Skip to content

refactor(worktree): remove worktree-setup.sh support and align print-mode trust - #5528

Merged
Grapedge merged 2 commits into
mainfrom
remove-worktree-setup
Nov 26, 2026
Merged

Grapedge merged 2 commits into
mainfrom
remove-worktree-setup

Conversation

@Grapedge

Copy link
Copy Markdown
Collaborator

Requirement or Bug

实验性 Git worktree 功能中的 .kimi-code/worktree-setup.sh 初始化脚本能力设计尚未收敛,本 PR 在正式发布前先移除该能力,只保留 .worktreeinclude 忽略文件复制及其他 worktree 管理功能。同时移除 print 模式 -w 单独的未受信任项目阻断检查,使其与普通 kimi -p 的信任模型保持一致。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路

新建 worktree 的流程现在在完成 .worktreeinclude 文件复制后直接结束并进入新工作树,不再发现、提示或执行 .kimi-code/worktree-setup.sh。由于 print 模式不再自动执行仓库内的 shell 脚本,kimi -p -w 移除单独的未受信任项目阻断检查,沿用普通 kimi -p 的项目级 MCP 跳过警告与引擎门控。

flowchart LR
  Create["WorktreeService.create"] --> Add["git worktree add"]
  Add --> Include[".worktreeinclude 复制"]
  Include --> Print["CLI print 模式直接启动会话"]
  Include --> Tui["CLI TUI 直接进入工作树"]
Loading

去掉脚本执行阶段后,print 模式 preparePrintWorktree 不再存在「工作树已创建但脚本失败未就绪」的中间态,TUI 也不再需要脚本确认弹窗、流式输出截尾与失败删树分支,引擎层进程执行逻辑也随之收简。

关键决策

决策 选择 没选 理由
kimi -p -w 的项目信任检查 移除单独阻断,与普通 kimi -p 对齐 仅为 -w 保留硬阻断 worktree 不应偏离 print 模式既有信任边界,如需调整应统一处理
未发布的 worktree SDK 接口 直接移除 runWorktreeSetupScript 与相关类型 保留废弃空壳 worktree 能力尚未进入正式版本,直接删除可避免引入无效公开接口

阅读指南

  • packages/agent-core-v2/src/app/worktree/worktree.ts 与 worktreeService.ts:移除 CreatedWorktree.setupScript、runSetupScript、脚本路径解析,以及仅由其使用的 runWithLease 包装与 RunOptions 字段。
  • apps/kimi-code/src/cli/v2/run-v2-print.ts:移除 isProjectTrusted 与脚本执行段,将 preparePrintWorktree 返回值收紧为 Promise<CreatedWorktree | undefined>。
  • apps/kimi-code/src/tui/controllers/worktree-creation.ts:移除脚本询问/重试/失败删树逻辑、OutputTail,并收紧 WorktreeCreationHost 依赖。
  • 可略读:packages/node-sdk/src/* 透传导出清理、apps/kimi-code/src/tui/components/{dialogs/worktree-choices,messages/worktree-progress}.ts 弹窗与进度行分支清理、测试更新、.changeset/worktree-core.md 措辞同步,以及 docs/{zh,en}/guides/worktrees.md 文档更新。

Behavior Changes and Affected Users

行为变化 改动前 改动后 依赖旧行为的人群 退路
新建 worktree 时处理 .kimi-code/worktree-setup.sh TUI 弹窗询问是否运行;print 模式自动运行并注入 KIMI_CODE_WORKTREE_SOURCE_DIR 与 KIMI_CODE_WORKTREE_DIR 忽略该文件且绝不执行;.worktreeinclude 照常复制忽略文件 使用 canary 版本并启用实验性 worktree 开关、且在仓库配置了 .kimi-code/worktree-setup.sh 的 TUI 与 print 模式用户 无(该能力尚未进入正式版;进入新工作树后可手动执行环境准备命令)
在未受信任项目运行 kimi -p -w 报错退出(退出码 1)并拒绝创建 worktree 正常创建 worktree 并启动会话,跳过项目级 MCP 并在 stderr 输出警告,与普通 kimi -p 一致 依赖 kimi -p -w 在未受信任项目下自动中止的脚本或外部自动化流程 无(与普通 kimi -p 信任模型保持一致)
@moonshot-ai/kimi-code-sdk 与 @moonshot-ai/agent-core-v2 worktree 接口 导出 RunSetupScriptInput、RunSetupScriptOptions、runWorktreeSetupScript / runSetupScript 与 CreatedWorktree.setupScript 在首个正式版本发布前移除,并同步清理未发布的 .changeset/worktree-core.md 依赖 canary 版本实验接口的 SDK 调用方 无(尚未随正式版发布)

受影响模块与验证

  • 受影响模块:packages/agent-core-v2、packages/node-sdk、apps/kimi-code、docs/{zh,en}/guides/worktrees.md、.changeset/worktree-core.md。
  • 已验证(macOS 实测):
    • agent-core-v2、node-sdk、apps/kimi-code 三包类型检查全部通过。
    • 单元测试覆盖仓库存在已提交或未提交 .kimi-code/worktree-setup.sh 时不执行且保留 .worktreeinclude、未受信任项目下 kimi -p -w 放行并输出 MCP 跳过警告、createWorktree 失败退出码 1,以及 TUI 创建与进度渲染。
    • 真实 CLI 端到端验证了 kimi -p ... -w(未受信任仓库含 .worktreeinclude、可执行 .kimi-code/worktree-setup.sh 与 .kimi-code/mcp.json)与 PTY 交互式 kimi -w,均正确复制 .env、跳过脚本且无弹窗。
    • pnpm lint 与 pnpm run check:duplication 全部通过。
  • 未验证:本机为 macOS,未在 Windows 实机验证(新增的 worktreeService.test.ts 回归用例未跳过 Windows,将随 CI 校验)。
验证命令与结果
  • pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit(退出码 0)
  • pnpm exec tsc -p packages/node-sdk/tsconfig.json --noEmit(退出码 0)
  • pnpm exec tsc -p apps/kimi-code/tsconfig.json --noEmit(退出码 0)
  • pnpm exec vitest run --reporter=agent 运行 9 个 worktree/CLI/TUI 测试文件(596 项通过;补齐 createWorktree 失败用例后复跑 apps/kimi-code/test/cli/v2-run-print.test.ts 51/51 通过)
  • pnpm lint(退出码 0,0 warnings / 0 errors)
  • pnpm run check:duplication FETCH_HEAD(退出码 0,无新增重复)

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T11:32:47.071423Z a3c6eb3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a3c6eb3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 7 packages
Name Type
@moonshot-ai/agent-core-v2 Minor
@moonshot-ai/acp-server Patch
@moonshot-ai/kap-server Patch
@moonshot-ai/klient Patch
@moonshot-ai/migration-legacy Patch
@moonshot-ai/kimi-code-product Patch
@moonshot-ai/remote-control Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@a3c6eb3
npx https://pkg.pr.new/@moonshot-ai/kimi-code@a3c6eb3

commit: a3c6eb3

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a3c6eb3891

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Grapedge
Grapedge merged commit 48ee2f2 into main Nov 26, 2026
22 checks passed
@Grapedge
Grapedge deleted the remove-worktree-setup branch November 26, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants