From 33371b069ecd2fbc369b25d96772d2914b69b8cb Mon Sep 17 00:00:00 2001 From: LegGasai Date: Mon, 16 Nov 2026 13:32:27 +0800 Subject: [PATCH] feat(worktree)!: merge create_worktree into enter_worktree The model has one tool for entering a worktree, as Claude Code's EnterWorktree: `enter_worktree({ name?, from? })`. When the pool of the checkout the Session is in holds a registered worktree of that name, the call enters it and changes neither Git state nor files. Otherwise it creates a new branch and checkout from `from`, HEAD by default, and enters it. `from` asks for a new worktree, so it fails with `WORKTREE_ALREADY_EXISTS` when the name is taken; a call without a name always creates one. The result adds `created`. `create_worktree` is removed. `ctx.worktrees.create` and `enter` keep their behavior: the tool calls `enter` first and `create` only on `WORKTREE_NOT_FOUND`, so Host callers such as the forge panel still create. The upgrade guide `create-worktree-tool-merged` covers the removed tool name. --- ...026-11-03-session-workspace-root.i18n.yaml | 12 +-- .../2026-11-03-session-workspace-root.md | 8 +- .../2026-11-03-session-workspace-root.zh.md | 8 +- ...09-13-explicit-worktree-creation.i18n.yaml | 4 +- .../2026-09-13-explicit-worktree-creation.md | 2 +- ...026-09-13-explicit-worktree-creation.zh.md | 2 +- apps/web/tests/forge-panel.e2e.ts | 2 +- apps/web/tests/worktree-opt-in.e2e.ts | 11 +-- docs/subsystems/worktrees.i18n.yaml | 8 +- docs/subsystems/worktrees.md | 4 +- docs/subsystems/worktrees.zh.md | 4 +- docs/tool-catalog.i18n.yaml | 15 ++- docs/tool-catalog.md | 33 ++----- docs/tool-catalog.zh.md | 33 ++----- .../guide.i18n.yaml | 16 +++ .../create-worktree-tool-merged/guide.md | 28 ++++++ .../create-worktree-tool-merged/guide.zh.md | 28 ++++++ .../guide.i18n.yaml | 8 +- .../working-directory-tool-removed/guide.md | 4 +- .../guide.zh.md | 4 +- .../core/tools/tests/gen-tool-catalog.spec.ts | 6 +- .../client-ui-forge/README.i18n.yaml | 4 +- .../experimental/client-ui-forge/README.md | 2 +- .../experimental/client-ui-forge/README.zh.md | 2 +- .../forge-bundle/README.i18n.yaml | 4 +- packages/experimental/forge-bundle/README.md | 2 +- .../experimental/forge-bundle/README.zh.md | 2 +- .../tool-worktree/README.i18n.yaml | 36 +++---- packages/experimental/tool-worktree/README.md | 16 +-- .../experimental/tool-worktree/README.zh.md | 16 +-- .../experimental/tool-worktree/docs/DETAIL.md | 2 +- .../tool-worktree/docs/DETAIL.zh.md | 2 +- .../experimental/tool-worktree/src/index.ts | 56 ++++------- .../tests/loader-composition.spec.ts | 97 +++++++++++-------- scripts/gen-tool-catalog.ts | 2 +- snapshots/session/worktree/session.v4.jsonl | 14 +-- .../worktree/tool-schemas.expected.json | 30 ++---- 37 files changed, 267 insertions(+), 260 deletions(-) create mode 100644 docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.i18n.yaml create mode 100644 docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.md create mode 100644 docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.zh.md diff --git a/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.i18n.yaml b/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.i18n.yaml index 99bf37fe39..8202aa1acb 100644 --- a/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.i18n.yaml @@ -9,14 +9,14 @@ en: 6938aa715106bb99 zh: ea1497b337712f33 /agent-note-session-workspace-root/decision: - en: 35b00c73a8898442 - zh: a45b349487491c8c + en: 83e5ff57c2e11e93 + zh: 2ca4f64333ef2ad5 /agent-note-session-workspace-root/deferred: en: d8167590081dfa4e zh: a030f78230192206 /agent-note-session-workspace-root/alternatives-considered: - en: 1f06a00497effec7 - zh: ac97aa5f9f98047d + en: 056a06b3f8758c1c + zh: 78256ec4c1d6cede /agent-note-session-workspace-root/consequences: - en: 8e7b91f65af92657 - zh: 7a140c796d395c6a + en: fbc61f5a561061db + zh: 0c36539cfb645aa4 diff --git a/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.md b/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.md index 8c1ec063de..59694fa089 100644 --- a/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.md +++ b/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.md @@ -14,7 +14,7 @@ A Session works in one directory, and only Host operations move it. The model-fa `workspace-root/change` is a new ordinary event type, recorded as a same-version persistence change in the [acknowledgement](../../../../docs/persistence-changes/2026-11-13-workspace-root-change.md). `working-directory/change` stays in the event vocabulary, deprecated and without a writer. A stored one, written while the model could move the directory, moves only the current directory, so a stored Session keeps the root it had. An older build refuses a log that holds `workspace-root/change`; a Session that never moves its workspace holds none. -Worktree creation enters the checkout through `set`. `ctx.worktrees.enter`, exposed to the model as `enter_worktree`, moves the Session into an existing worktree that a name selects inside the pool of the checkout it works in; the name cannot leave that pool, so the model still cannot choose an arbitrary directory. `ctx.worktrees.exit`, exposed as `exit_worktree`, returns the Session from the recorded worktree that contains its directory to the checkout it created or entered that worktree from. A child subagent keeps the parent's original project in its header and starts, through `set`, in the parent's workspace root or a Host-chosen directory. +Worktree creation enters the checkout through `set`. The model has one tool for entering a checkout, `enter_worktree`: a name selects a worktree inside the pool of the checkout the Session works in. An existing one is entered through `ctx.worktrees.enter`, and a new one is created through `ctx.worktrees.create` when none has that name. The name cannot leave that pool, so the model still cannot choose an arbitrary directory. `ctx.worktrees.exit`, exposed as `exit_worktree`, returns the Session from the recorded worktree that contains its directory to the checkout it created or entered that worktree from. A child subagent keeps the parent's original project in its header and starts, through `set`, in the parent's workspace root or a Host-chosen directory. ## Deferred @@ -32,7 +32,9 @@ The sandbox write boundary, the workspace file service, desktop file drag, the c **Retire `working-directory/change` through a format migration.** The stored event carries no origin, so a migration would classify each one by its neighbouring events, and a stored model `cd` still needs a record that moves only the directory. The [compatibility rules](../../../../docs/persistence-changes/README.md#compatibility-rules) reserve a version bump for changes that an existing discriminator cannot make safe. -**Enter a worktree by path, or fold creation and entry into one tool.** A model-supplied path would move the write boundary to any registered worktree without the user's approval, which removing the directory tool ruled out, and the harness has no approval step for a directory move. One tool with a creation mode would rename `create_worktree`, which stored Sessions and recorded scenarios call. A name inside the pool keeps the boundary inside the checkout and adds one tool. +**Enter a worktree by path.** A model-supplied path would move the write boundary to any registered worktree, which removing the directory tool ruled out unless the user approves each move. A `tools/pre-execute` listener can ask for that approval through the approval service; this decision leaves the path form, and with it entry of a sibling from inside a worktree, to a later change. A name inside the pool keeps the boundary inside the checkout. + +**Separate tools for creation and entry.** `create_worktree` beside `enter_worktree` gave the model two tools for one action, entering a worktree, and made it choose by whether the worktree exists. One tool follows Claude Code's `EnterWorktree`, which creates a worktree or opens the one of that name. In the 79 recorded Sessions of one developer that offered `create_worktree`, the model called it once in 6,599 tool calls, so removing the name affects few stored Sessions. **Persist the shell's `cd` between calls.** That is an implicit cursor. In that developer's Sessions, 68% of `cd` prefixes named a directory outside the Session directory and 30% the Session directory itself, so a persisted directory confined to the workspace would apply to about 2%. @@ -40,4 +42,4 @@ The sandbox write boundary, the workspace file service, desktop file drag, the c ## Consequences -Consumers read one directory: `get` for relative paths and `rootOf` for everything that belongs to the workspace. The two differ only in a Session that holds `working-directory/change` events, and the next Host move brings them together. Readers keep folding that event as a directory-only change, so a later cursor needs no format change. The model enters a checkout only through the worktree tools: a new one with `create_worktree`, a registered one in the pool with `enter_worktree`. A checkout elsewhere needs a Host operation. The ACP, SDK, and Web producers record the original project by its canonical spelling, so a Host move back to it records no change. The worktree snapshot fixture covers entering, leaving, and losing a worktree. Moving the consumers listed under Deferred is a separate change. +Consumers read one directory: `get` for relative paths and `rootOf` for everything that belongs to the workspace. The two differ only in a Session that holds `working-directory/change` events, and the next Host move brings them together. Readers keep folding that event as a directory-only change, so a later cursor needs no format change. The model enters a checkout only through `enter_worktree`: a new one, or a registered one in the pool. A checkout elsewhere needs a Host operation. The ACP, SDK, and Web producers record the original project by its canonical spelling, so a Host move back to it records no change. The worktree snapshot fixture covers entering, leaving, and losing a worktree. Moving the consumers listed under Deferred is a separate change. diff --git a/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.zh.md b/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.zh.md index 24f5f75c0b..215872af2a 100644 --- a/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.zh.md +++ b/.agents/notes/implemented/architecture/2026-11-03-session-workspace-root.zh.md @@ -14,7 +14,7 @@ Status: implemented `workspace-root/change` 是新增的普通事件类型,作为同版本持久化变更记录在[确认记录](../../../../docs/persistence-changes/2026-11-13-workspace-root-change.zh.md)中。`working-directory/change` 保留在事件词汇表中,已标为 deprecated,没有写入方。已存储的这类事件写于模型还能移动目录的时期,它只移动当前目录,因此已存储的 Session 保持原有的根。旧版本拒绝含有 `workspace-root/change` 的日志;从未移动工作区的 Session 不含该事件。 -工作树创建通过 `set` 进入检出目录。`ctx.worktrees.enter` 以 `enter_worktree` 的形式提供给模型,它把 Session 移入名称在所在检出的池中选中的已有工作树;名称无法离开该池,因此模型仍然不能选择任意目录。`ctx.worktrees.exit` 以 `exit_worktree` 的形式提供,它找到包含 Session 目录的已记录工作树,把 Session 送回创建或进入该工作树时所在的检出。子代理的 header 保留父级的原始项目,并通过 `set` 从父级的工作区根或 Host 选定的目录启动。 +工作树创建通过 `set` 进入检出目录。模型只有一个进入检出的工具 `enter_worktree`:名称在 Session 所在检出的池中选中一个工作树。已有的工作树通过 `ctx.worktrees.enter` 进入,没有同名工作树时通过 `ctx.worktrees.create` 新建。名称无法离开该池,因此模型仍然不能选择任意目录。`ctx.worktrees.exit` 以 `exit_worktree` 的形式提供,它找到包含 Session 目录的已记录工作树,把 Session 送回创建或进入该工作树时所在的检出。子代理的 header 保留父级的原始项目,并通过 `set` 从父级的工作区根或 Host 选定的目录启动。 ## Deferred @@ -32,7 +32,9 @@ Status: implemented **通过格式迁移退役 `working-directory/change`。** 已存储的事件不带来源,迁移只能依据相邻事件逐条分类,而已存储的模型 `cd` 仍需要一种只移动目录的记录。[兼容性规则](../../../../docs/persistence-changes/README.zh.md#compatibility-rules)只在现有判别符无法保证安全时才要求升版本。 -**按路径进入工作树,或把创建与进入合并为一个工具。** 模型提供的路径可以不经用户批准就把写边界移到任意已登记的工作树,这正是移除目录工具所排除的;harness 也没有针对目录移动的审批步骤。带创建模式的单一工具需要给 `create_worktree` 改名,而已存储的 Session 和录制场景都在调用它。池内的名称把边界留在检出之内,只新增一个工具。 +**按路径进入工作树。** 模型提供的路径会把写边界移到任意已登记的工作树,除非用户逐次批准,否则这正是移除目录工具所排除的。`tools/pre-execute` 监听器可以通过审批服务请求这一批准;本决定把路径形式,以及随之而来的“从工作树内进入同级工作树”,留给之后的变更。池内的名称把边界留在检出之内。 + +**创建与进入各用一个工具。** `create_worktree` 与 `enter_worktree` 并存时,模型为“进入工作树”这一个动作面对两个工具,还要按工作树是否存在来选择。单一工具与 Claude Code 的 `EnterWorktree` 一致,后者创建工作树,或打开同名的已有工作树。在一位开发者提供过 `create_worktree` 的 79 个已记录 Session 中,模型在 6,599 次工具调用里只调用过它一次,因此移除这个名称影响的已存储 Session 很少。 **在调用之间保留 shell 的 `cd`。** 这是一个隐式的光标。在该开发者的 Session 中,68% 的 `cd` 前缀指向 Session 目录之外,30% 指向 Session 目录本身,限制在工作区内的保留只对约 2% 生效。 @@ -40,4 +42,4 @@ Status: implemented ## Consequences -消费方读取一个目录:相对路径用 `get`,属于工作区的一切用 `rootOf`。两者只在含有 `working-directory/change` 事件的 Session 中不同,下一次 Host 移动会让它们重新一致。读者继续把该事件折叠为只移动目录的变更,因此以后增加光标不需要改格式。模型只能通过工作树工具进入检出:用 `create_worktree` 进入新建的检出,用 `enter_worktree` 进入池中已登记的检出。其他位置的检出需要 Host 操作。ACP、SDK 与 Web 的生产方以规范拼写记录原始项目,因此 Host 移回原始项目时不记录变更。工作树快照夹具覆盖进入、离开和失去工作树。迁移 Deferred 中列出的消费方是另一项变更。 +消费方读取一个目录:相对路径用 `get`,属于工作区的一切用 `rootOf`。两者只在含有 `working-directory/change` 事件的 Session 中不同,下一次 Host 移动会让它们重新一致。读者继续把该事件折叠为只移动目录的变更,因此以后增加光标不需要改格式。模型只能通过 `enter_worktree` 进入检出:新建的检出,或池中已登记的检出。其他位置的检出需要 Host 操作。ACP、SDK 与 Web 的生产方以规范拼写记录原始项目,因此 Host 移回原始项目时不记录变更。工作树快照夹具覆盖进入、离开和失去工作树。迁移 Deferred 中列出的消费方是另一项变更。 diff --git a/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.i18n.yaml b/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.i18n.yaml index 201593ebbe..6a8511eee5 100644 --- a/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.i18n.yaml @@ -9,8 +9,8 @@ en: 12ab239ab0c58e31 zh: c32874442ce66041 /agent-note-explicit-worktree-creation/decision: - en: 571a2d4c5352170b - zh: aeb12b849c5f8d31 + en: 98289c9b859516cd + zh: ac45d0997966840b /agent-note-explicit-worktree-creation/alternatives-considered: en: 72d42e892a37b94c zh: 92a14a51c6a89c53 diff --git a/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.md b/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.md index 9facc68061..6fe421dab8 100644 --- a/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.md +++ b/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.md @@ -10,7 +10,7 @@ A Session that needs an isolated checkout otherwise has to coordinate Git comman ## Decision -The experimental [worktree runtime](../../../../packages/experimental/worktree/README.md) creates a new named branch and checkout from a pinned local commit, then enters its canonical directory through the shared working-directory service. The [tool](../../../../packages/experimental/tool-worktree/README.md) exposes `create_worktree({ name?, from? })`. These packages use ordinary explicit composition, with no additional runtime feature flag. +The experimental [worktree runtime](../../../../packages/experimental/worktree/README.md) creates a new named branch and checkout from a pinned local commit, then enters its canonical directory through the shared working-directory service. The [tool](../../../../packages/experimental/tool-worktree/README.md) exposes it as `enter_worktree({ name?, from? })`, which also enters an existing worktree of that name. These packages use ordinary explicit composition, with no additional runtime feature flag. The source repository comes from the calling Session's current directory. Creation does not fetch or copy uncommitted files. The default pool is `.agents/worktrees` under the current checkout’s top-level directory, including when the caller is in a linked checkout. The process that creates a pool writes its self-ignoring `.gitignore`; existing directories and ignore files are preserved. Names must be new branches and unused checkout paths. diff --git a/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.zh.md b/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.zh.md index bc9fc0670c..2baafd7af8 100644 --- a/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.zh.md +++ b/.agents/notes/implemented/feature/2026-09-13-explicit-worktree-creation.zh.md @@ -10,7 +10,7 @@ Status: implemented ## Decision -实验性[工作树运行时](../../../../packages/experimental/worktree/README.zh.md)从固定的本地提交创建新的具名分支与检出目录,然后通过共享工作目录服务进入其规范路径。[工具](../../../../packages/experimental/tool-worktree/README.zh.md)公开 `create_worktree({ name?, from? })`。这些包使用普通的显式组合,不添加额外运行时功能开关。 +实验性[工作树运行时](../../../../packages/experimental/worktree/README.zh.md)从固定的本地提交创建新的具名分支与检出目录,然后通过共享工作目录服务进入其规范路径。[工具](../../../../packages/experimental/tool-worktree/README.zh.md)以 `enter_worktree({ name?, from? })` 公开它,同名工作树已存在时进入该工作树。这些包使用普通的显式组合,不添加额外运行时功能开关。 源仓库由调用 Session 的当前目录决定。创建操作不会获取远端提交或复制未提交文件。默认父目录是当前检出目录顶层路径下的 `.agents/worktrees`,调用方位于链接检出目录中时也一样。创建该目录的进程写入忽略自身的 `.gitignore`;已有目录与忽略文件保持不变。名称必须对应新分支与尚未使用的检出路径。 diff --git a/apps/web/tests/forge-panel.e2e.ts b/apps/web/tests/forge-panel.e2e.ts index f84c79925a..4a7125a29f 100644 --- a/apps/web/tests/forge-panel.e2e.ts +++ b/apps/web/tests/forge-panel.e2e.ts @@ -744,7 +744,7 @@ it.skipIf(MODE === 'record')('automatically shows a numbered PR when gh JSON omi const sessionId = await settled const events = await readPersistedEvents(launch.scaffold, sessionId) const request = events.find(event => event.type === 'request/header') - expect(request?.data.header.tools?.filter(tool => tool.name === 'create_worktree')).toHaveLength(1) + expect(request?.data.header.tools?.filter(tool => tool.name === 'enter_worktree')).toHaveLength(1) const toolOutput = events.flatMap(event => event.type === 'tool/result' ? event.data.message.content.flatMap(block => block.type === 'text' ? [block.text] : []) : []).join('\n') expect(toolOutput).toContain('Add the pull request panel') diff --git a/apps/web/tests/worktree-opt-in.e2e.ts b/apps/web/tests/worktree-opt-in.e2e.ts index d5a51d83d2..6192fcf5a9 100644 --- a/apps/web/tests/worktree-opt-in.e2e.ts +++ b/apps/web/tests/worktree-opt-in.e2e.ts @@ -83,7 +83,6 @@ it('persists the unified review and worktree switch and retains checkouts after expect(rows()).toEqual([]) expect(scaffold.ctx.get('worktrees')).toBeUndefined() expect(scaffold.ctx.get('forgePanel')).toBeUndefined() - expect(tools()).not.toContain('create_worktree') expect(tools()).not.toContain('enter_worktree') expect(tools()).not.toContain('exit_worktree') @@ -91,17 +90,16 @@ it('persists the unified review and worktree switch and retains checkouts after await expect.poll(() => rows().length, { timeout: PLUGIN_TOGGLE_SETTLE_MS }).toBe(2) await expect.poll(() => toggle.getAttribute('aria-checked'), { timeout: PLUGIN_TOGGLE_SETTLE_MS }).toBe('true') expect(await selectedBundles()).toContain(BUNDLE) - expect(tools()).toContain('create_worktree') expect(tools()).toContain('enter_worktree') expect(tools()).toContain('exit_worktree') expect(scaffold.ctx.get('forgePanel')).toBeDefined() const created = { path: join(repository, '.agents/worktrees/gui-opt-in'), baseCommit: (await git('rev-parse', 'HEAD')).stdout.trim() } const result = await scaffold.ctx.tools.execute({ agent, signal: new AbortController().signal, - calls: [{ type: 'tool-call', id: brandString('gui-opt-in'), name: 'create_worktree', arguments: JSON.stringify({ name: 'gui-opt-in' }) }], + calls: [{ type: 'tool-call', id: brandString('gui-opt-in'), name: 'enter_worktree', arguments: JSON.stringify({ name: 'gui-opt-in' }) }], }) expect(result.results[0]?.result.isError).not.toBe(true) - expect(result.results[0]?.result.value).toEqual({ ...created, branch: 'gui-opt-in', repositoryRoot: repository }) + expect(result.results[0]?.result.value).toEqual({ ...created, branch: 'gui-opt-in', repositoryRoot: repository, created: true }) expect(await readFile(join(created.path, 'retained.txt'), 'utf8')).toBe('retained checkout\n') expect(scaffold.ctx.workingDirectory.get(agent.session)).toBe(created.path) @@ -110,14 +108,13 @@ it('persists the unified review and worktree switch and retains checkouts after card = panel.locator(`[data-plugin-group="more"] [data-plugin-package="${BUNDLE}"]`) toggle = card.getByRole('switch', { name: 'Enable Change requests & worktrees', exact: true }) await expect.poll(() => toggle.getAttribute('aria-checked')).toBe('true') - expect(tools()).toContain('create_worktree') + expect(tools()).toContain('enter_worktree') await toggle.click() await expect.poll(() => rows().length, { timeout: PLUGIN_TOGGLE_SETTLE_MS }).toBe(0) await expect.poll(() => toggle.getAttribute('aria-checked'), { timeout: PLUGIN_TOGGLE_SETTLE_MS }).toBe('false') expect(await selectedBundles()).not.toContain(BUNDLE) expect(scaffold.ctx.get('worktrees')).toBeUndefined() expect(scaffold.ctx.get('forgePanel')).toBeUndefined() - expect(tools()).not.toContain('create_worktree') expect(tools()).not.toContain('enter_worktree') expect(tools()).not.toContain('exit_worktree') expect(await readFile(join(created.path, 'retained.txt'), 'utf8')).toBe('retained checkout\n') @@ -128,7 +125,7 @@ it('persists the unified review and worktree switch and retains checkouts after panel = await openPlugins() await expect.poll(() => panel.getByRole('switch', { name: 'Enable Change requests & worktrees', exact: true }) .getAttribute('aria-checked')).toBe('false') - expect(tools()).not.toContain('create_worktree') + expect(tools()).not.toContain('enter_worktree') expect(await selectedBundles()).not.toContain(BUNDLE) expect(tripwire.pageErrors).toEqual([]) }) diff --git a/docs/subsystems/worktrees.i18n.yaml b/docs/subsystems/worktrees.i18n.yaml index 845b35867b..7a7a207dec 100644 --- a/docs/subsystems/worktrees.i18n.yaml +++ b/docs/subsystems/worktrees.i18n.yaml @@ -3,11 +3,11 @@ # After editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write docs/subsystems/worktrees.md /git-worktrees: - en: 2b8bd1769282a1b6 - zh: 3da9c6b3459fbb2e + en: a0def5edd90e9189 + zh: 96c3f6fa48eb850d /git-worktrees/creation-and-retention: - en: 86c9fe64306517b7 - zh: e2d087afe24d2ef5 + en: 1cce2f01306c7804 + zh: fe196380757b81d0 /git-worktrees/request-and-result: en: 5801c5909e1873a0 zh: 5c36a4c4ea97ecad diff --git a/docs/subsystems/worktrees.md b/docs/subsystems/worktrees.md index c387ead94a..661996ec2c 100644 --- a/docs/subsystems/worktrees.md +++ b/docs/subsystems/worktrees.md @@ -2,7 +2,7 @@ English | [中文](worktrees.zh.md) -The experimental [`dsh-experimental-worktree`](../../packages/experimental/worktree/README.md) service provides `ctx.worktrees`. Its [`create_worktree`](../../packages/experimental/tool-worktree/README.md) consumer creates a new Git branch and checkout, then selects it through the [working-directory service](working-directory.md); `enter_worktree` selects an existing checkout of the pool, and `exit_worktree` returns to the checkout the Session came from. The [Change requests & worktrees bundle](../../packages/experimental/forge-bundle/README.md#use-this-package) loads both packages through the GUI plugin manager and ships switched off. Other profiles can select the [standalone worktree bundle](../../packages/experimental/tool-worktree/README.md#use-this-package) or mount the two packages explicitly. +The experimental [`dsh-experimental-worktree`](../../packages/experimental/worktree/README.md) service provides `ctx.worktrees`. Its [`enter_worktree`](../../packages/experimental/tool-worktree/README.md) consumer selects a checkout of the pool through the [working-directory service](working-directory.md), creating a new Git branch and checkout when none has the requested name, and `exit_worktree` returns to the checkout the Session came from. The [Change requests & worktrees bundle](../../packages/experimental/forge-bundle/README.md#use-this-package) loads both packages through the GUI plugin manager and ships switched off. Other profiles can select the [standalone worktree bundle](../../packages/experimental/tool-worktree/README.md#use-this-package) or mount the two packages explicitly. ## Creation and retention @@ -10,7 +10,7 @@ The calling Session's current directory selects the source repository. Creation The default destination is `/.agents/worktrees/`. `repositoryRoot` is the top-level directory of the caller’s current checkout; a linked checkout therefore contains its own pool. The service writes a `.gitignore` containing `*` and a trailing newline only when its allocation creates the configured pool directory. Existing files and ignore rules are preserved. The calling Session’s existing sandbox policy must permit writes to the destination and shared Git administration directory. Successful Git setup precedes the working-directory change. -`ctx.worktrees.enter(agent, { name })`, which the `enter_worktree` tool calls, moves the Session into an existing worktree in the pool of the checkout it works in. The directory must lie inside that pool and be a registered worktree of the repository: a missing name, an unregistered directory, and a link that leaves the pool fail with `WORKTREE_NOT_FOUND`. Entry changes neither Git state nor files and records itself in the Session log. +`ctx.worktrees.enter(agent, { name })` moves the Session into an existing worktree in the pool of the checkout it works in. The `enter_worktree` tool calls it first for a named request without a start revision, and calls `create` only when it reports `WORKTREE_NOT_FOUND`. The directory must lie inside that pool and be a registered worktree of the repository: a missing name, an unregistered directory, and a link that leaves the pool fail with `WORKTREE_NOT_FOUND`. Entry changes neither Git state nor files and records itself in the Session log. `ctx.worktrees.exit(agent)`, which the `exit_worktree` tool calls, returns the Session from the recorded worktree that contains its current directory to the checkout it created or entered that worktree from; the checkout and branch remain. Nested worktrees exit one level at a time. Cancellation or failure can also retain partial artifacts; the error identifies their location. Worktree failures throw `WorktreeError` with a `WORKTREE_*` code; a failure after allocation keeps the wrapped error's `name` and `code`, and caller cancellation stays an `AbortError`. The service aborts and drains pending operations on disposal. The [package README](../../packages/experimental/worktree/README.md) owns configuration and Git requirements. diff --git a/docs/subsystems/worktrees.zh.md b/docs/subsystems/worktrees.zh.md index 59495fca74..6c7ae7d4cf 100644 --- a/docs/subsystems/worktrees.zh.md +++ b/docs/subsystems/worktrees.zh.md @@ -2,7 +2,7 @@ [English](worktrees.md) | 中文 -实验性的 [`dsh-experimental-worktree`](../../packages/experimental/worktree/README.zh.md) 服务提供 `ctx.worktrees`。其消费方 [`create_worktree`](../../packages/experimental/tool-worktree/README.zh.md) 创建新的 Git 分支与检出目录,再通过[工作目录服务](working-directory.zh.md)选中它;`enter_worktree` 选中池中已有的检出目录,`exit_worktree` 回到 Session 来自的检出目录。[变更请求与工作树组合包](../../packages/experimental/forge-bundle/README.zh.md#use-this-package)通过 GUI 插件管理器一起加载这两个包,随安装提供但默认关闭。其他 profile 可以选择[独立工作树组合包](../../packages/experimental/tool-worktree/README.zh.md#use-this-package),或显式挂载这两个包。 +实验性的 [`dsh-experimental-worktree`](../../packages/experimental/worktree/README.zh.md) 服务提供 `ctx.worktrees`。其消费方 [`enter_worktree`](../../packages/experimental/tool-worktree/README.zh.md) 通过[工作目录服务](working-directory.zh.md)选中池中的检出目录,没有同名检出目录时创建新的 Git 分支与检出目录;`exit_worktree` 回到 Session 来自的检出目录。[变更请求与工作树组合包](../../packages/experimental/forge-bundle/README.zh.md#use-this-package)通过 GUI 插件管理器一起加载这两个包,随安装提供但默认关闭。其他 profile 可以选择[独立工作树组合包](../../packages/experimental/tool-worktree/README.zh.md#use-this-package),或显式挂载这两个包。 ## 创建与保留 @@ -10,7 +10,7 @@ 默认目标为 `/.agents/worktrees/`。`repositoryRoot` 是调用方当前检出目录的顶层目录;因此,链接检出目录会在自身内部保存工作树父目录。仅当服务的分配操作创建了配置指定的父目录时,服务才会写入内容为 `*` 加换行符的 `.gitignore`。已有文件与忽略规则保持不变。调用方 Session 的现有沙箱策略必须允许写入目标目录与共享 Git 管理目录。Git 初始化成功后才改变工作目录。 -`enter_worktree` 工具调用的 `ctx.worktrees.enter(agent, { name })` 把 Session 移入它所在检出的池中已有的工作树。该目录必须位于池内,并且是仓库已登记的工作树:名称不存在、目录未登记、链接指向池外都以 `WORKTREE_NOT_FOUND` 失败。进入不改变 Git 状态和文件,并在 Session 日志中记录这次进入。 +`ctx.worktrees.enter(agent, { name })` 把 Session 移入它所在检出的池中已有的工作树。`enter_worktree` 工具对带名称且不带起始修订的请求先调用它,只有它报告 `WORKTREE_NOT_FOUND` 时才调用 `create`。该目录必须位于池内,并且是仓库已登记的工作树:名称不存在、目录未登记、链接指向池外都以 `WORKTREE_NOT_FOUND` 失败。进入不改变 Git 状态和文件,并在 Session 日志中记录这次进入。 `exit_worktree` 工具调用的 `ctx.worktrees.exit(agent)` 找到包含 Session 当前目录的已记录工作树,把 Session 送回创建或进入该工作树时所在的检出;检出目录与分支保留。嵌套的工作树每次退出一层。取消或失败也可能留下部分产物;错误会指出它们的位置。worktree 失败抛出带 `WORKTREE_*` code 的 `WorktreeError`;分配开始后的失败保留被包装错误的 `name` 与 `code`,调用方取消仍为 `AbortError`。服务销毁时会中止待完成操作并等待它们结束。[包 README](../../packages/experimental/worktree/README.zh.md)拥有配置与 Git 要求。 diff --git a/docs/tool-catalog.i18n.yaml b/docs/tool-catalog.i18n.yaml index 71996d28ed..1c33f41d51 100644 --- a/docs/tool-catalog.i18n.yaml +++ b/docs/tool-catalog.i18n.yaml @@ -9,8 +9,8 @@ en: 6cc2cd9ced70bb09 zh: 1c0e6cb4ba2ed637 /tool-schema-catalog/tool-package-map: - en: 42e89edca7bae115 - zh: 735c6af26e8df6a5 + en: 886cd189bdaa2d0e + zh: 814f0e9f94ef3487 /tool-schema-catalog/deepseek-ai-dsh-plugin-manager: en: e0143916bb634762 zh: e0143916bb634762 @@ -320,15 +320,12 @@ /tool-schema-catalog/deepseek-ai-dsh-experimental-tool-worktree: en: d5f5679abe86e316 zh: d5f5679abe86e316 -/tool-schema-catalog/deepseek-ai-dsh-experimental-tool-worktree/create-worktree: - en: 5c3d354aa18e8d19 - zh: 275bff3958cf465a /tool-schema-catalog/deepseek-ai-dsh-experimental-tool-worktree/enter-worktree: - en: 644de5ca0bc1d312 - zh: 7a2f4860089bfcb8 + en: fb9a393b6fe3523f + zh: 02de205e99537ef2 /tool-schema-catalog/deepseek-ai-dsh-experimental-tool-worktree/exit-worktree: - en: 834d21fd914b7211 - zh: ea1501ee1fc8a754 + en: d0e4d70d5b5f607e + zh: 17000fe015d8d76a /tool-schema-catalog/deepseek-ai-dsh-tool-workflow: en: bb38a9d29f46563c zh: bb38a9d29f46563c diff --git a/docs/tool-catalog.md b/docs/tool-catalog.md index 6d8eaeac2c..f44fd34f4f 100644 --- a/docs/tool-catalog.md +++ b/docs/tool-catalog.md @@ -47,7 +47,7 @@ This table connects model-visible tool names to the plugin package and service s | `@deepseek-ai/dsh-tool-jobs` | `job_kill`, `job_list`, `job_output` | `ctx.tools`, `ctx.jobs`, `ctx.systemPrompt` | `tool/call`, `tool/result`, `user/message via agent.inject() for background completion notices` | - | The kind-agnostic background-job controller: background bash commands and PTY sends are read, listed, and killed through the same three tools. Loading the plugin attaches the controller that arms producers' `ctx.jobs.start()`. | | `@deepseek-ai/dsh-tool-agent-team` | `team_task_create`, `team_task_get`, `team_task_list`, `team_task_update` | `ctx.tools`, `ctx.systemPrompt`, `ctx.agentTeams`, `ctx.subagents`, `an exact live Team member Agent` | `tool/call`, `team/task`, `tool/result` | - | Four task-board tools share the subagent tree’s root Session. Enabling Team mode on the root Session adds task-board guidance alongside standard subagent delegation and control tools. Standard subagent controls provide required identity independently of Team mode. | | `@deepseek-ai/dsh-tool-todo` | `todo_write` | `ctx.tools`, `owning Agent session` | `tool/call`, `todo/write`, `tool/result` | - | todo_write is session-owned state; UIs render the latest todo/write event as a checklist. `allowParallelInProgress` is required with no default, so the catalog states its choice: `true`, whose description invites several `in_progress` items. A deployment choosing `false` receives the same tool with a description asking for exactly one active task. | -| `@deepseek-ai/dsh-experimental-tool-worktree` | `create_worktree`, `enter_worktree`, `exit_worktree` | `ctx.tools`, `ctx.worktrees`, `a calling Agent` | `tool/call`, `Git branch and checkout`, `workspace-root/change`, `tool/result` | - | Enabled through the Change requests & worktrees bundle on Web and Desktop; other profiles can select the standalone bundle. Creates a new branch and checkout from a pinned local commit under existing write permissions, then changes the Session directory. `enter_worktree` moves the Session into an existing worktree in the pool of the checkout it works in; `exit_worktree` returns the Session to the checkout it came from; the branch and checkout remain. | +| `@deepseek-ai/dsh-experimental-tool-worktree` | `enter_worktree`, `exit_worktree` | `ctx.tools`, `ctx.worktrees`, `a calling Agent` | `tool/call`, `Git branch and checkout`, `workspace-root/change`, `tool/result` | - | Enabled through the Change requests & worktrees bundle on Web and Desktop; other profiles can select the standalone bundle. `enter_worktree` moves the Session into the worktree a name selects in the pool of the checkout it works in, creating a new branch and checkout from a pinned local commit under existing write permissions when none has that name. `exit_worktree` returns the Session to the checkout it came from; the branch and checkout remain. | | `@deepseek-ai/dsh-tool-workflow` | `workflow` | `ctx.tools`, `ctx.workflowEngine`, `ctx.systemPrompt`, `a calling Agent (exec.agent parents the script children)` | `tool/call`, `tool/result` | - | - | | `@deepseek-ai/dsh-tool-workspace-dependencies` | `load_workspace_dependencies` | `ctx.tools` | `tool/call`, `tool/result` | - | - | | `@deepseek-ai/dsh-tool-web` | `web_fetch`, `web_search` | `ctx.tools`, `ctx.web`, `ctx.systemPrompt` | `tool/call`, `tool/result` | - | web_search and web_fetch keep provider selection behind ctx.web so model-visible schemas stay stable across backend swaps. | @@ -2634,9 +2634,9 @@ todo_write is session-owned state; UIs render the latest todo/write event as a c ## `@deepseek-ai/dsh-experimental-tool-worktree` -### `create_worktree` +### `enter_worktree` -Create a new Git branch and worktree from a local commit, branch, or tag, then change this session's working directory to it. Uncommitted files stay in the source checkout. Existing names fail; enter_worktree enters an existing worktree. exit_worktree returns to the source checkout. +Change this session's working directory to a Git worktree of the checkout it is in. An existing worktree named name is entered as it is. Otherwise a new branch and worktree are created from a local commit, branch, or tag, and uncommitted files stay in the source checkout. exit_worktree returns to the source checkout. ```json { @@ -2644,11 +2644,11 @@ Create a new Git branch and worktree from a local commit, branch, or tag, then c "properties": { "name": { "type": "string", - "description": "New branch name, also used as the checkout directory: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to generate a unique name." + "description": "Worktree to enter, also the branch name and checkout directory of a new one: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to create a worktree with a generated name." }, "from": { "type": "string", - "description": "Local commit, branch, or tag to start from. Defaults to HEAD; no fetch is performed." + "description": "Local commit, branch, or tag a new worktree starts from. Defaults to HEAD; no fetch is performed. Fails when the worktree already exists." } } } @@ -2656,27 +2656,6 @@ Create a new Git branch and worktree from a local commit, branch, or tag, then c Source: [`packages/experimental/tool-worktree/src/index.ts`](../packages/experimental/tool-worktree/src/index.ts) -### `enter_worktree` - -Change this session's working directory to an existing worktree that was created from the checkout this session is in. Branches and files stay as they are. exit_worktree returns to that checkout. - -```json -{ - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "Name the worktree was created with." - } - }, - "required": [ - "name" - ] -} -``` - -Source: [`packages/experimental/tool-worktree/src/index.ts`](../packages/experimental/tool-worktree/src/index.ts) - ### `exit_worktree` Change this session's working directory from the worktree it is in back to the checkout it entered that worktree from, and report the worktree left. The worktree and its branch remain. @@ -2690,7 +2669,7 @@ Change this session's working directory from the worktree it is in back to the c Source: [`packages/experimental/tool-worktree/src/index.ts`](../packages/experimental/tool-worktree/src/index.ts) -Enabled through the Change requests & worktrees bundle on Web and Desktop; other profiles can select the standalone bundle. Creates a new branch and checkout from a pinned local commit under existing write permissions, then changes the Session directory. `enter_worktree` moves the Session into an existing worktree in the pool of the checkout it works in; `exit_worktree` returns the Session to the checkout it came from; the branch and checkout remain. +Enabled through the Change requests & worktrees bundle on Web and Desktop; other profiles can select the standalone bundle. `enter_worktree` moves the Session into the worktree a name selects in the pool of the checkout it works in, creating a new branch and checkout from a pinned local commit under existing write permissions when none has that name. `exit_worktree` returns the Session to the checkout it came from; the branch and checkout remain. diff --git a/docs/tool-catalog.zh.md b/docs/tool-catalog.zh.md index a6eed7234a..00294c390d 100644 --- a/docs/tool-catalog.zh.md +++ b/docs/tool-catalog.zh.md @@ -51,7 +51,7 @@ | `@deepseek-ai/dsh-tool-jobs` | `job_kill`、`job_list`、`job_output` | `ctx.tools`、`ctx.jobs`、`ctx.systemPrompt` | `tool/call`、`tool/result`、`user/message via agent.inject() for background completion notices` | - | 与任务种类无关的后台任务控制器:后台 bash 命令与 PTY 发送 都通过相同的 3 个工具读取、列出和终止。加载该插件会挂接控制器,从而启用生产方的 `ctx.jobs.start()`。 | | `@deepseek-ai/dsh-tool-agent-team` | `team_task_create`, `team_task_get`, `team_task_list`, `team_task_update` | `ctx.tools`, `ctx.systemPrompt`, `ctx.agentTeams`, `ctx.subagents`, `an exact live Team member Agent` | `tool/call`, `team/task`, `tool/result` | - | 四个任务板工具共享 subagent 树的根 Session。在根 Session 开启 Team 模式,会在标准 subagent 委派和控制工具之外增加任务板指导。标准 subagent 控制工具提供必需身份,不受 Team 模式影响。 | | `@deepseek-ai/dsh-tool-todo` | `todo_write` | `ctx.tools`、`owning Agent session` | `tool/call`、`todo/write`、`tool/result` | - | todo_write 是会话所有的状态;UI 将最新的 todo/write 事件渲染为检查清单。`allowParallelInProgress` 是没有默认值的必填项,因此本目录明确选择 `true`,对应描述允许同时存在多个 `in_progress` 项。选择 `false` 的部署会获得同一工具,但描述会要求只能有 1 个活动任务。 | -| `@deepseek-ai/dsh-experimental-tool-worktree` | `create_worktree`, `enter_worktree`, `exit_worktree` | `ctx.tools`, `ctx.worktrees`, `a calling Agent` | `tool/call`, `Git branch and checkout`, `workspace-root/change`, `tool/result` | - | 在 Web 和 Desktop 上通过变更请求与工作树组合包启用;其他 profile 可以选择独立组合包。在现有写权限下从固定的本地提交创建新分支与检出目录,再改变 Session 工作目录。`enter_worktree` 把 Session 移入它所在检出的池中已有的工作树;`exit_worktree` 把 Session 送回它来自的检出目录;分支与检出目录保留。 | +| `@deepseek-ai/dsh-experimental-tool-worktree` | `enter_worktree`, `exit_worktree` | `ctx.tools`, `ctx.worktrees`, `a calling Agent` | `tool/call`, `Git branch and checkout`, `workspace-root/change`, `tool/result` | - | 在 Web 和 Desktop 上通过变更请求与工作树组合包启用;其他 profile 可以选择独立组合包。`enter_worktree` 把 Session 移入名称在它所在检出的池中选中的工作树,没有同名工作树时在现有写权限下从固定的本地提交创建新分支与检出目录。`exit_worktree` 把 Session 送回它来自的检出目录;分支与检出目录保留。 | | `@deepseek-ai/dsh-tool-workflow` | `workflow` | `ctx.tools`、`ctx.workflowEngine`、`ctx.systemPrompt`、`a calling Agent (exec.agent parents the script children)` | `tool/call`、`tool/result` | - | - | | `@deepseek-ai/dsh-tool-workspace-dependencies` | `load_workspace_dependencies` | `ctx.tools` | `tool/call`, `tool/result` | - | - | | `@deepseek-ai/dsh-tool-web` | `web_fetch`、`web_search` | `ctx.tools`、`ctx.web`、`ctx.systemPrompt` | `tool/call`、`tool/result` | - | web_search 和 web_fetch 将提供方选择置于 ctx.web 之后,使模型可见 schema 在更换后端时保持稳定。 | @@ -2640,9 +2640,9 @@ todo_write 是会话所有的状态;UI 将最新的 todo/write 事件渲染为 ## `@deepseek-ai/dsh-experimental-tool-worktree` -### `create_worktree` +### `enter_worktree` -从本地提交、分支或标签创建新的 Git 分支与工作树,再将本 Session 的工作目录切换到该位置。未提交文件保留在源检出目录中。名称已存在时失败;enter_worktree 进入已有的工作树。exit_worktree 返回源检出目录。 +把本 Session 的工作目录切换到它所在检出目录的一个 Git 工作树。名为 name 的工作树已存在时原样进入。否则从本地提交、分支或标签创建新的分支与工作树,未提交文件保留在源检出目录中。exit_worktree 返回源检出目录。 ```json { @@ -2650,11 +2650,11 @@ todo_write 是会话所有的状态;UI 将最新的 todo/write 事件渲染为 "properties": { "name": { "type": "string", - "description": "New branch name, also used as the checkout directory: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to generate a unique name." + "description": "Worktree to enter, also the branch name and checkout directory of a new one: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to create a worktree with a generated name." }, "from": { "type": "string", - "description": "Local commit, branch, or tag to start from. Defaults to HEAD; no fetch is performed." + "description": "Local commit, branch, or tag a new worktree starts from. Defaults to HEAD; no fetch is performed. Fails when the worktree already exists." } } } @@ -2662,27 +2662,6 @@ todo_write 是会话所有的状态;UI 将最新的 todo/write 事件渲染为 来源:[`packages/experimental/tool-worktree/src/index.ts`](../packages/experimental/tool-worktree/src/index.ts) -### `enter_worktree` - -把本 Session 的工作目录切换到一个已有的工作树,该工作树须是从本 Session 所在的检出目录创建的。分支与文件保持原样。exit_worktree 返回该检出目录。 - -```json -{ - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "Name the worktree was created with." - } - }, - "required": [ - "name" - ] -} -``` - -来源:[`packages/experimental/tool-worktree/src/index.ts`](../packages/experimental/tool-worktree/src/index.ts) - ### `exit_worktree` 把本 Session 的工作目录从所在的工作树切换回进入该工作树时所在的检出目录,并报告所离开的工作树。工作树及其分支保留。 @@ -2696,7 +2675,7 @@ todo_write 是会话所有的状态;UI 将最新的 todo/write 事件渲染为 来源:[`packages/experimental/tool-worktree/src/index.ts`](../packages/experimental/tool-worktree/src/index.ts) -在 Web 和 Desktop 上通过变更请求与工作树组合包启用;其他 profile 可以选择独立组合包。在现有写权限下从固定的本地提交创建新分支与检出目录,再改变 Session 工作目录。`enter_worktree` 把 Session 移入它所在检出的池中已有的工作树;`exit_worktree` 把 Session 送回它来自的检出目录;分支与检出目录保留。 +在 Web 和 Desktop 上通过变更请求与工作树组合包启用;其他 profile 可以选择独立组合包。`enter_worktree` 把 Session 移入名称在它所在检出的池中选中的工作树,没有同名工作树时在现有写权限下从固定的本地提交创建新分支与检出目录。`exit_worktree` 把 Session 送回它来自的检出目录;分支与检出目录保留。 diff --git a/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.i18n.yaml new file mode 100644 index 0000000000..e90150a66a --- /dev/null +++ b/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.i18n.yaml @@ -0,0 +1,16 @@ +# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading +# section, a hash of its English and Chinese blocks outside code blocks and generated regions. +# After editing either side, bring the other along and re-record with: +# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.md +/: + en: d994abee8ad3650f + zh: 0857a7d70b9d395e +/enter-worktree-replaces-create-worktree: + en: bdeb4b6e382fe6ba + zh: ac7389ae7a3e2a43 +/enter-worktree-replaces-create-worktree/change: + en: 844309112e229e12 + zh: e018fbfe34ae4fd3 +/enter-worktree-replaces-create-worktree/migration: + en: 5a1bd8b061f43a37 + zh: 2191774792218cfb diff --git a/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.md b/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.md new file mode 100644 index 0000000000..2203cbb371 --- /dev/null +++ b/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.md @@ -0,0 +1,28 @@ +--- +kind: upgrade-guide +description: "The `create_worktree` model tool is removed; `enter_worktree` creates a worktree or enters an existing one of the same name." +--- +# `enter_worktree` replaces `create_worktree` + +English | [中文](guide.zh.md) + +## Change + +The experimental package `@deepseek-ai/dsh-experimental-tool-worktree` no longer registers the model tool `create_worktree`. Its replacement `enter_worktree({ name?, from? })` moves the Session into a worktree in the pool of the checkout it is in, `.agents/worktrees/` by default: + +- When the pool holds a registered worktree named `name`, the call enters it and changes neither Git state nor files. `create_worktree` failed for an existing name. +- Otherwise the call creates a new branch and checkout from `from`, HEAD by default, and enters it, as `create_worktree` did. Omitting `name` creates one with a generated name. +- `from` asks for a new worktree: with a name that is taken, the call fails with `WORKTREE_ALREADY_EXISTS`. + +The result adds `created`, true for a new worktree. A result for an existing worktree has no `baseCommit`, and no `branch` when its HEAD is detached. `exit_worktree` leaves either kind and returns the Session to the checkout it came from. + +`ctx.worktrees.create` keeps its behavior; the new `ctx.worktrees.enter(agent, { name })` enters an existing worktree. + +Who observes it: prompts, skills, and evaluation sets that name `create_worktree`; PTC programs that call `tools.create_worktree`; Host code that reads the tool result. A stored Session keeps its recorded `create_worktree` calls as history, and a new call returns `unknown tool "create_worktree"`. + +## Migration + +1. Replace `create_worktree` with `enter_worktree` in prompts, skills, scripted model turns, and PTC programs. The parameters `name` and `from` keep their meaning. +2. Where a task needs a fresh worktree and the name may be taken, pass `from` or omit `name`, so an existing worktree is not entered silently. Otherwise read `created` in the result. +3. Where code reads the tool result, treat `baseCommit` and `branch` as optional. +4. Confirm: with the worktree bundle enabled, the tool list of a first request contains `enter_worktree` and `exit_worktree` and no `create_worktree`. diff --git a/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.zh.md new file mode 100644 index 0000000000..9dbd0b7384 --- /dev/null +++ b/docs/upgrade-guide/v0.2.2-rc.3/create-worktree-tool-merged/guide.zh.md @@ -0,0 +1,28 @@ +--- +kind: upgrade-guide +description: "模型工具 `create_worktree` 被移除;`enter_worktree` 创建工作树,或进入同名的已有工作树。" +--- +# `enter_worktree` 取代 `create_worktree` + +[English](guide.md) | 中文 + +## 变更 + +实验性包 `@deepseek-ai/dsh-experimental-tool-worktree` 不再注册模型工具 `create_worktree`。取代它的 `enter_worktree({ name?, from? })` 把 Session 移入它所在检出的工作树池(默认 `.agents/worktrees/`)中的工作树: + +- 池中已有名为 `name` 的已登记工作树时,调用进入该工作树,不改变 Git 状态和文件。`create_worktree` 在名称已存在时失败。 +- 否则调用从 `from`(默认 HEAD)创建新的分支与检出目录并进入,与 `create_worktree` 相同。省略 `name` 时用生成的名称新建。 +- `from` 表示要新建工作树:名称已被占用时,调用以 `WORKTREE_ALREADY_EXISTS` 失败。 + +结果新增 `created`,新建工作树时为 true。进入已有工作树的结果没有 `baseCommit`,其 HEAD 分离时也没有 `branch`。`exit_worktree` 可以离开这两种工作树,把 Session 送回它来自的检出。 + +`ctx.worktrees.create` 的行为不变;新增的 `ctx.worktrees.enter(agent, { name })` 进入已有的工作树。 + +受影响的对象:提到 `create_worktree` 的提示词、技能与评测集;调用 `tools.create_worktree` 的 PTC 程序;读取工具结果的 Host 代码。已存储的 Session 中记录的 `create_worktree` 调用仍是历史,新的调用返回 `unknown tool "create_worktree"`。 + +## 迁移 + +1. 在提示词、技能、脚本化的模型轮次和 PTC 程序中,把 `create_worktree` 替换为 `enter_worktree`。参数 `name` 与 `from` 的含义不变。 +2. 任务需要全新的工作树而名称可能已被占用时,传入 `from` 或省略 `name`,避免无提示地进入已有的工作树。其他情况读取结果中的 `created`。 +3. 读取工具结果的代码要把 `baseCommit` 与 `branch` 当作可选。 +4. 确认:启用工作树组合包后,首个请求的工具列表中有 `enter_worktree` 与 `exit_worktree`,没有 `create_worktree`。 diff --git a/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.i18n.yaml index bd65e7e8f5..1acbaf18d7 100644 --- a/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.i18n.yaml +++ b/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.i18n.yaml @@ -9,8 +9,8 @@ en: 9f20155a3198221f zh: 4e8fbfcc6e819ac6 /the-working-directory-tool-and-the-subagent-cwd-parameter-are-removed/change: - en: 1a4d05e4e678a400 - zh: 41dd47d57aaea5dc + en: 2b33930e4c1bc6cb + zh: e76289da3cdc060f /the-working-directory-tool-and-the-subagent-cwd-parameter-are-removed/migration: - en: 7be13e241868a3c2 - zh: 78fbf7a8ca905597 + en: 1a6d1219aa571f48 + zh: 7a442a027dc74c28 diff --git a/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.md b/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.md index 52bad8d881..79e0dc17a5 100644 --- a/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.md +++ b/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.md @@ -10,7 +10,7 @@ English | [中文](guide.zh.md) The model tool `working_directory` and its package `@deepseek-ai/dsh-tool-working-directory` no longer exist; the `dsh-base` and `dsh-sdk-minimal` bundles no longer mount the `tool-working-directory` entry. The delegation tools registered by `@deepseek-ai/dsh-tool-subagent`, and `subagent_oar`, no longer accept `cwd`: a child starts in the caller's workspace directory. -A Session's directory now changes only through Host operations: `create_worktree`, the new `enter_worktree` and `exit_worktree`, the forge panel, SDK `setWorkingDirectory` (`set_working_directory` in Python), and recovery when the directory disappears. Each change is recorded as `workspace-root/change`; the [persistence record](../../../persistence-changes/2026-11-13-workspace-root-change.md) covers stored logs and readers of earlier releases. A stored Session whose model changed the directory resumes in that directory. Its recorded `working_directory` calls remain history, and a new call returns `unknown tool "working_directory"`. +A Session's directory now changes only through Host operations: `enter_worktree`, the new `exit_worktree`, the forge panel, SDK `setWorkingDirectory` (`set_working_directory` in Python), and recovery when the directory disappears. Each change is recorded as `workspace-root/change`; the [persistence record](../../../persistence-changes/2026-11-13-workspace-root-change.md) covers stored logs and readers of earlier releases. A stored Session whose model changed the directory resumes in that directory. Its recorded `working_directory` calls remain history, and a new call returns `unknown tool "working_directory"`. Who observes it: prompts, skills, and evaluation sets that expect the tool or the parameter in the tool list; profiles and patches that name the `tool-working-directory` entry or the package; Host plugins that pass a model-supplied path to `ctx.subagents.start({ cwd })` or `ctx.workingDirectory.set`, which now also moves the Session's workspace root. @@ -18,6 +18,6 @@ Who observes it: prompts, skills, and evaluation sets that expect the tool or th 1. Remove `tool-working-directory` rows and `@deepseek-ai/dsh-tool-working-directory` dependencies from profiles, patches, and package manifests. A patch that still names the entry reports `patch: entry "tool-working-directory" not found` at load. 2. In prompts, skills, and scripted model turns, replace `working_directory({ cd })` with paths relative to the Session directory or absolute paths, and with the `workdir` argument of `bash` or `pwsh` for commands. The `Current working directory:` line of the user context replaces `working_directory()` as the way to read the directory. -3. To leave a worktree, call `exit_worktree()`. It returns the Session to the checkout the worktree was created or entered from. To return to an existing worktree, call `enter_worktree({ name })` from the checkout it was created from. +3. To leave a worktree, call `exit_worktree()`. It returns the Session to the checkout the worktree was created or entered from. To return to an existing worktree, call `enter_worktree({ name })` from the checkout it was created from; the [worktree tool guide](../create-worktree-tool-merged/guide.md) covers that tool. 4. Remove `cwd` from `subagent` and `subagent_oar` calls and name the subdirectory in the task. A Host that needs another start directory passes a path it chose itself to `ctx.subagents.start({ cwd })`. 5. Confirm: `dsh --profile headless --dump-config` lists no `tool-working-directory` entry, and the tool list of a first request contains neither `working_directory` nor a `cwd` property on `subagent`. diff --git a/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.zh.md index 3ae338c5dd..1aed1ea689 100644 --- a/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.zh.md +++ b/docs/upgrade-guide/v0.2.2-rc.3/working-directory-tool-removed/guide.zh.md @@ -10,7 +10,7 @@ description: "模型工具 `working_directory`、它的包以及子代理工具 模型工具 `working_directory` 及其包 `@deepseek-ai/dsh-tool-working-directory` 不再存在;`dsh-base` 与 `dsh-sdk-minimal` 组合包不再挂载 `tool-working-directory` 条目。`@deepseek-ai/dsh-tool-subagent` 注册的委派工具以及 `subagent_oar` 不再接受 `cwd`:子代理从调用方的工作区目录启动。 -Session 的目录现在只通过 Host 操作改变:`create_worktree`、新增的 `enter_worktree` 与 `exit_worktree`、forge 面板、SDK 的 `setWorkingDirectory`(Python 中为 `set_working_directory`),以及目录消失时的恢复。每次变更都记录为 `workspace-root/change`;[持久化记录](../../../persistence-changes/2026-11-13-workspace-root-change.zh.md)说明已存储日志的读法和早期版本读者的行为。模型曾改变过目录的已存储 Session 会在该目录恢复。其中记录的 `working_directory` 调用仍是历史,新的调用返回 `unknown tool "working_directory"`。 +Session 的目录现在只通过 Host 操作改变:`enter_worktree`、新增的 `exit_worktree`、forge 面板、SDK 的 `setWorkingDirectory`(Python 中为 `set_working_directory`),以及目录消失时的恢复。每次变更都记录为 `workspace-root/change`;[持久化记录](../../../persistence-changes/2026-11-13-workspace-root-change.zh.md)说明已存储日志的读法和早期版本读者的行为。模型曾改变过目录的已存储 Session 会在该目录恢复。其中记录的 `working_directory` 调用仍是历史,新的调用返回 `unknown tool "working_directory"`。 受影响的对象:期望工具列表中有该工具或该参数的提示词、技能与评测集;引用 `tool-working-directory` 条目或该包的 profile 与 patch;把模型提供的路径传给 `ctx.subagents.start({ cwd })` 或 `ctx.workingDirectory.set` 的 Host 插件,后者现在同时移动 Session 的工作区根。 @@ -18,6 +18,6 @@ Session 的目录现在只通过 Host 操作改变:`create_worktree`、新增 1. 从 profile、patch 和包清单中移除 `tool-working-directory` 行与 `@deepseek-ai/dsh-tool-working-directory` 依赖。仍然引用该条目的 patch 在加载时报告 `patch: entry "tool-working-directory" not found`。 2. 在提示词、技能和脚本化的模型轮次中,把 `working_directory({ cd })` 替换为相对 Session 目录的路径或绝对路径,命令使用 `bash` 或 `pwsh` 的 `workdir` 参数。读取目录改用用户上下文中的 `Current working directory:` 一行,不再调用 `working_directory()`。 -3. 离开工作树时调用 `exit_worktree()`。它把 Session 送回创建或进入该工作树时所在的检出目录。要回到已有的工作树,在创建它的检出目录中调用 `enter_worktree({ name })`。 +3. 离开工作树时调用 `exit_worktree()`。它把 Session 送回创建或进入该工作树时所在的检出目录。要回到已有的工作树,在创建它的检出目录中调用 `enter_worktree({ name })`;[工作树工具指南](../create-worktree-tool-merged/guide.zh.md)说明该工具。 4. 从 `subagent` 与 `subagent_oar` 调用中移除 `cwd`,把子目录写进任务。需要其他起始目录的 Host 把自己选定的路径传给 `ctx.subagents.start({ cwd })`。 5. 确认:`dsh --profile headless --dump-config` 不再列出 `tool-working-directory` 条目,首个请求的工具列表中既没有 `working_directory`,`subagent` 也没有 `cwd` 属性。 diff --git a/packages/core/tools/tests/gen-tool-catalog.spec.ts b/packages/core/tools/tests/gen-tool-catalog.spec.ts index 9931b5e20f..1887c32058 100644 --- a/packages/core/tools/tests/gen-tool-catalog.spec.ts +++ b/packages/core/tools/tests/gen-tool-catalog.spec.ts @@ -28,7 +28,7 @@ describe('gen-tool-catalog collectToolCatalog', () => { const names = catalog.flatMap(entry => entry.schemas.map(s => s.name)).sort() expect(names).toEqual([ 'apply_patch', 'ask_user_question', 'bash', 'bash', 'cordis_inspect', - 'create_goal', 'create_worktree', 'edit', 'enter_worktree', 'exit_plan_mode', 'exit_worktree', 'get_goal', 'glob', 'grep', + 'create_goal', 'edit', 'enter_worktree', 'exit_plan_mode', 'exit_worktree', 'get_goal', 'glob', 'grep', 'interrupt_agent', 'job_kill', 'job_list', 'job_output', 'list_agents', 'list_mcp_resource_templates', 'list_mcp_resources', 'list_subagent_models', 'load_workspace_dependencies', 'lsp', 'office_convert', 'office_recalculate', 'office_render', 'plugin_manager', 'plugin_market', 'present', 'propose_action', 'pwsh', 'pwsh', 'ralph', @@ -49,8 +49,8 @@ describe('gen-tool-catalog collectToolCatalog', () => { } } const worktree = catalog.find(entry => entry.pkg === '@deepseek-ai/dsh-experimental-tool-worktree') - expect(worktree?.sources.create_worktree).toBe('packages/experimental/tool-worktree/src/index.ts') - const parameters = worktree?.schemas.find(schema => schema.name === 'create_worktree')?.parameters + expect(worktree?.sources.enter_worktree).toBe('packages/experimental/tool-worktree/src/index.ts') + const parameters = worktree?.schemas.find(schema => schema.name === 'enter_worktree')?.parameters expect(parameters).toHaveProperty('properties.name.type', 'string') expect(parameters?.required ?? []).not.toContain('name') }) diff --git a/packages/experimental/client-ui-forge/README.i18n.yaml b/packages/experimental/client-ui-forge/README.i18n.yaml index fd5661abe2..59562c5db0 100644 --- a/packages/experimental/client-ui-forge/README.i18n.yaml +++ b/packages/experimental/client-ui-forge/README.i18n.yaml @@ -15,8 +15,8 @@ en: d152484eb41ac6b4 zh: 2f8a621b991260a1 /deepseek-ai-dsh-experimental-client-ui-forge/use-this-package: - en: 240a0267069304b5 - zh: 1e28533a1706a37d + en: df5fb14ddbd349c1 + zh: 569ef0ef6b745c91 /deepseek-ai-dsh-experimental-client-ui-forge/understand-the-implementation: en: 217bfca4fd738be4 zh: ce735665eb698408 diff --git a/packages/experimental/client-ui-forge/README.md b/packages/experimental/client-ui-forge/README.md index 5b7314809c..b7a6f0e7da 100644 --- a/packages/experimental/client-ui-forge/README.md +++ b/packages/experimental/client-ui-forge/README.md @@ -30,7 +30,7 @@ Enable the [forge bundle](../forge-bundle/README.md) on the Plugins page; it com Panel text follows the application language: Chinese, English, Japanese, Spanish, French, German, Russian, or Portuguese. - **Worktree option** — on the New Session screen, New worktree sits beside the current branch at the right end of the row with the workspace and mode pickers. Both stay hidden outside a Git checkout. The branch is read-only until New worktree is checked, when it becomes the base branch selector; the menu lists recent local branches. If permissions block an existing request, its selected base stays visible without a selector and the request can still be withdrawn. Hovering, focusing, or tapping the read-only branch or base shows its full description. The option is disabled, with the reason in its tooltip, in a read-only Session and when the checkout or its Git directory lies outside the Session's writable root, as for a project that is itself a linked worktree. Sending the first message hands it to the Session at once, and it waits there while the branch `dsh--<4 random hexadecimal digits>` is created from the base under the repository's `.agents/worktrees/` and its checkout becomes the Session's working directory; the message's turn starts once the worktree exists. -- **Archive cleanup** — archiving a Session lets the [worktree service](../worktree/README.md) reclaim the clean, unreferenced worktree it created, whether through the New Session option or the model's `create_worktree` tool, while retaining the branch and its commits. A scheduled cleanup uses the archive notice “Archived; the worktree will be cleaned up”; one that ends retained returns to the ordinary notice, and one that fails replaces it with a warning while the Session stays archived. Undo cancels deletion before admission or waits for an admitted deletion; a removed checkout uses the existing Restore worktree flow. The bundle's worktree row on the Plugins page offers Keep worktrees when archiving: once saved, archiving keeps every worktree and shows the ordinary archive notice; the switch is read at each archive, so it does not affect a cleanup already scheduled. +- **Archive cleanup** — archiving a Session lets the [worktree service](../worktree/README.md) reclaim the clean, unreferenced worktree it created, whether through the New Session option or the model's `enter_worktree` tool, while retaining the branch and its commits. A scheduled cleanup uses the archive notice “Archived; the worktree will be cleaned up”; one that ends retained returns to the ordinary notice, and one that fails replaces it with a warning while the Session stays archived. Undo cancels deletion before admission or waits for an admitted deletion; a removed checkout uses the existing Restore worktree flow. The bundle's worktree row on the Plugins page offers Keep worktrees when archiving: once saved, archiving keeps every worktree and shows the ordinary archive notice; the switch is read at each archive, so it does not affect a cleanup already scheduled. - **Creation card** — while the worktree is created, a card above the composer shows the new branch and its two steps, creating the branch and checking out files; More details adds the branch and base. Cancel stops the attempt. After a stopped or failed attempt the message keeps waiting, and the card shows the reason of a failure: Retry tries again with a new branch name, and Continue without a worktree withdraws the request so the message goes on in the current checkout. - **Removed worktree** — when the worktree the Session works in has been removed outside the Session, a card above the composer says so, and a message sent meanwhile waits without starting its turn until the worktree is restored or left; the card then says that the message goes on afterwards. Restore worktree, also offered as Restore in the tab, checks the branch out again at the same directory, or creates the branch again at the commit it started from when the branch is gone too; while it runs, the card follows its two steps, preparing the worktree and checking out files, and the tab's Restore turns into a spinner. Continue in the project moves the Session to the source checkout. Meanwhile the tab's first row shows a warning glyph. - **Code review and changes** — on the right-sidebar start page, opens the same change request tab as the Session header button. diff --git a/packages/experimental/client-ui-forge/README.zh.md b/packages/experimental/client-ui-forge/README.zh.md index 7c2eb2b3ba..b7a02a4fe6 100644 --- a/packages/experimental/client-ui-forge/README.zh.md +++ b/packages/experimental/client-ui-forge/README.zh.md @@ -30,7 +30,7 @@ kind: "package-reference" 面板文案跟随应用语言,支持中文、英文、日语、西班牙语、法语、德语、俄语和葡萄牙语。 - **工作树选项**——在新会话页面上,“新建工作树”与当前分支一起位于工作区与模式选择器那一行的右端。不在 Git 检出中时,两者均隐藏。分支默认为只读展示;勾选“新建工作树”后,它变为基准分支选择器,菜单列出最近的本地分支。权限阻止已有请求时,仍只读显示已选基准,并允许取消请求。悬停、聚焦或轻点只读分支或基准会显示完整说明。Session 为只读,或检出及其 Git 目录不在 Session 的可写根内(例如项目本身就是链接 worktree)时,该选项不可用,提示中说明原因。发送第一条消息后,消息立即交给 Session 并在那里等待,同时从基准分支在仓库的 `.agents/worktrees/` 下创建分支 `dsh--<4 位随机十六进制数>`,并把它的检出设为 Session 的工作目录;worktree 建好后这条消息的这一轮才开始。 -- **归档清理**——归档一个会话后,由[工作树服务](../worktree/README.zh.md)回收它创建的干净且无人引用的工作树,无论来自新会话选项还是模型的 `create_worktree` 工具,分支及其提交保留。清理排队后,归档提示为“已归档,工作树将被清理”;最终保留时恢复为普通归档提示,失败时替换为警告而会话仍保持归档。撤销归档会取消尚未获准的删除,或等待已获准的删除结束;已移除的工作树使用现有的“恢复工作树”流程。插件页上该套件的 worktree 行提供“归档时不删除工作树”开关:保存后,归档会保留所有工作树并显示普通归档提示;开关在每次归档时读取,不影响已排队的清理。 +- **归档清理**——归档一个会话后,由[工作树服务](../worktree/README.zh.md)回收它创建的干净且无人引用的工作树,无论来自新会话选项还是模型的 `enter_worktree` 工具,分支及其提交保留。清理排队后,归档提示为“已归档,工作树将被清理”;最终保留时恢复为普通归档提示,失败时替换为警告而会话仍保持归档。撤销归档会取消尚未获准的删除,或等待已获准的删除结束;已移除的工作树使用现有的“恢复工作树”流程。插件页上该套件的 worktree 行提供“归档时不删除工作树”开关:保存后,归档会保留所有工作树并显示普通归档提示;开关在每次归档时读取,不影响已排队的清理。 - **创建卡片**——创建 worktree 期间,输入框上方的卡片显示新分支以及“创建分支”“检出文件”两个步骤;“更多详情”会列出分支与基准。“取消”停止这次尝试。尝试被停止或失败后,消息继续等待,失败时卡片显示原因:“重试”换一个新分支名再试;“不使用工作树”撤回请求,消息在当前检出中继续发送。 - **工作树已被删除**——Session 所在的 worktree 在 Session 之外被删除后,输入框上方的卡片会说明这一点;此期间发送的消息会等待、不开始这一轮,直到该 worktree 被恢复或离开,卡片也会说明消息之后会接着发送。“恢复工作树”(标签页中的“恢复”与之相同)在原目录重新检出该分支;分支也已删除时,从它开始时的提交重新创建分支;恢复期间卡片显示“准备工作树”“检出文件”两个步骤,标签页中的“恢复”变为加载状态。“在项目目录继续”把 Session 移回源检出。此期间标签页顶部一行显示警示图标。 - **代码审查和变更**——右侧栏起始页中的入口,与会话标题栏按钮打开同一个变更请求标签页。 diff --git a/packages/experimental/forge-bundle/README.i18n.yaml b/packages/experimental/forge-bundle/README.i18n.yaml index 016b4ca42c..5a7de3b78f 100644 --- a/packages/experimental/forge-bundle/README.i18n.yaml +++ b/packages/experimental/forge-bundle/README.i18n.yaml @@ -15,8 +15,8 @@ en: d152484eb41ac6b4 zh: 2f8a621b991260a1 /deepseek-ai-dsh-experimental-forge-bundle/use-this-package: - en: e5299486a672bc02 - zh: d43b01e6f30564cd + en: 887cd00cceadc228 + zh: ca33a4ce807379d6 /deepseek-ai-dsh-experimental-forge-bundle/understand-the-implementation: en: 3afaeb5efc183949 zh: c916499192d320f3 diff --git a/packages/experimental/forge-bundle/README.md b/packages/experimental/forge-bundle/README.md index 4e7a5ffbd1..d8dc69c723 100644 --- a/packages/experimental/forge-bundle/README.md +++ b/packages/experimental/forge-bundle/README.md @@ -27,7 +27,7 @@ Review each Session's change requests, checks, and diffs, start a new Session in Open Plugins and enable Change requests & worktrees in the Official group. In a Git workspace, check Worktree in the composer before the first message to start the Session in a new worktree. In a Session whose directory is inside a Git checkout, the header button opens the panel. GitHub pull requests that the Session creates with `gh pr create`, opens with `gh pr view`, `gh pr edit`, or `gh pr checkout`, or works on as its branch or updates with a later `git push`, appear as change requests without further steps. Run `gh auth login --hostname ` in a terminal to sign in; the panel shows the command when sign-in is missing. The [panel package](../client-ui-forge/README.md#use-this-package) describes each control. -The same switch enables the model's [worktree tools](../tool-worktree/README.md): `create_worktree`, `enter_worktree`, and `exit_worktree`. Turning it off removes both the panel and the tools while retaining existing checkouts and branches. For profiles that already selected the standalone worktree bundle, follow the [upgrade guide](../../../docs/upgrade-guide/v0.2.2-alpha.2/forge-worktree-entry/guide.md) before enabling this bundle. +The same switch enables the model's [worktree tools](../tool-worktree/README.md): `enter_worktree` and `exit_worktree`. Turning it off removes both the panel and the tools while retaining existing checkouts and branches. For profiles that already selected the standalone worktree bundle, follow the [upgrade guide](../../../docs/upgrade-guide/v0.2.2-alpha.2/forge-worktree-entry/guide.md) before enabling this bundle. ----- diff --git a/packages/experimental/forge-bundle/README.zh.md b/packages/experimental/forge-bundle/README.zh.md index b8838efbc4..9f85e594e7 100644 --- a/packages/experimental/forge-bundle/README.zh.md +++ b/packages/experimental/forge-bundle/README.zh.md @@ -27,7 +27,7 @@ kind: "package-bundle" 打开插件页面,在官方分组中启用“变更请求与工作树”。在 Git 工作区中,发出第一条消息之前在输入框中勾选“工作树”,Session 就会在新的 worktree 中开始。Session 的目录位于 Git 检出中时,标题栏按钮会打开面板。Session 用 `gh pr create` 创建、用 `gh pr view`、`gh pr edit` 或 `gh pr checkout` 打开的 GitHub pull request,以及 Session 所在分支上或之后 `git push` 更新的 pull request,无需额外操作即会作为变更请求出现。在终端运行 `gh auth login --hostname ` 登录;缺少登录时,面板会显示这条命令。[面板包](../client-ui-forge/README.zh.md#use-this-package)说明了每个控件。 -同一个开关也启用模型的[工作树工具](../tool-worktree/README.zh.md):`create_worktree`、`enter_worktree` 与 `exit_worktree`。关闭后面板和工具一起移除,已有检出目录与分支仍然保留。已选中独立工作树组合包的 profile,请在启用本组合包前按[升级指南](../../../docs/upgrade-guide/v0.2.2-alpha.2/forge-worktree-entry/guide.zh.md)调整配置。 +同一个开关也启用模型的[工作树工具](../tool-worktree/README.zh.md):`enter_worktree` 与 `exit_worktree`。关闭后面板和工具一起移除,已有检出目录与分支仍然保留。已选中独立工作树组合包的 profile,请在启用本组合包前按[升级指南](../../../docs/upgrade-guide/v0.2.2-alpha.2/forge-worktree-entry/guide.zh.md)调整配置。 ----- diff --git a/packages/experimental/tool-worktree/README.i18n.yaml b/packages/experimental/tool-worktree/README.i18n.yaml index 1a4f3bcff7..8b3ba68de6 100644 --- a/packages/experimental/tool-worktree/README.i18n.yaml +++ b/packages/experimental/tool-worktree/README.i18n.yaml @@ -3,44 +3,44 @@ # After editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/experimental/tool-worktree/README.md /: - en: 09a4b4d95b664d1c - zh: c229106b16e9ecd9 + en: be8ddda9a016791f + zh: 0bad4fc0c3ce0988 /deepseek-ai-dsh-experimental-tool-worktree: en: db61f6b6ad671f45 zh: 9f3083d7f5605cbb /deepseek-ai-dsh-experimental-tool-worktree/summary: - en: c978e8e0be90d5f8 - zh: 75c20376f2e9d45f + en: ad053750132f42c3 + zh: 14e72801140ff7ac /deepseek-ai-dsh-experimental-tool-worktree/table-of-contents: en: d152484eb41ac6b4 zh: 2f8a621b991260a1 /deepseek-ai-dsh-experimental-tool-worktree/use-this-package: - en: 59068f72c326c780 - zh: 0c0f3687d971063c + en: a5d25494fde4f73d + zh: e99a6f7a485d56f5 /deepseek-ai-dsh-experimental-tool-worktree/understand-the-implementation: - en: 20d2b29ce103e6f0 - zh: 4e705758734ddb97 + en: 01d5f02b2b840cf0 + zh: db3c4f57ce636b34 /deepseek-ai-dsh-experimental-tool-worktree/further-exploration: en: 6ec5bb0f5bfbbaa4 zh: 45009dd139621d0e /deepseek-ai-dsh-experimental-tool-worktree/model-experience: en: 215e7ba838619b7b zh: a311da3843709f90 -/deepseek-ai-dsh-experimental-tool-worktree/model-experience/creation-tool: - en: 4062fcaa4794bed7 - zh: b56d35fc675fc430 -/deepseek-ai-dsh-experimental-tool-worktree/model-experience/creation-tool/what-the-model-sees: - en: 6e1fdb5ed5494542 - zh: 2ed8dcf7777f9ee9 -/deepseek-ai-dsh-experimental-tool-worktree/model-experience/creation-tool/token-effect: +/deepseek-ai-dsh-experimental-tool-worktree/model-experience/worktree-tools: + en: 079a9a4d389cc1e4 + zh: c61df4be4bc259e5 +/deepseek-ai-dsh-experimental-tool-worktree/model-experience/worktree-tools/what-the-model-sees: + en: a93746dd90abe4b6 + zh: 77a218bd6f9eec1b +/deepseek-ai-dsh-experimental-tool-worktree/model-experience/worktree-tools/token-effect: en: 6c3f73ba01233a36 zh: d64d87a425db4fbd -/deepseek-ai-dsh-experimental-tool-worktree/model-experience/creation-tool/kv-cache-effect: +/deepseek-ai-dsh-experimental-tool-worktree/model-experience/worktree-tools/kv-cache-effect: en: 365f8ccedfa61bbb zh: aa328044ba2528b8 /deepseek-ai-dsh-experimental-tool-worktree/known-limitations-and-deferred-work: - en: f0e0c0f36b6252a2 - zh: b2cd1fdcad570ce9 + en: 34a1eea5a4fb5cd0 + zh: ab445f8a2d43b22f /deepseek-ai-dsh-experimental-tool-worktree/known-limitations-and-deferred-work/dev-note: en: e67f633dc6fe7773 zh: 3bb0c20c93f16f98 diff --git a/packages/experimental/tool-worktree/README.md b/packages/experimental/tool-worktree/README.md index 51dce1e83a..d7873ab2d5 100644 --- a/packages/experimental/tool-worktree/README.md +++ b/packages/experimental/tool-worktree/README.md @@ -1,5 +1,5 @@ --- -description: "Model tools that create a local Git worktree, enter an existing one, and return to the source checkout." +description: "Model tools that enter a local Git worktree, creating it when it is new, and return to the source checkout." kind: "package-bundle" --- @@ -9,7 +9,7 @@ English | [中文](README.zh.md) ## Summary -Let a model create and enter a new Git worktree with one call, enter an existing one by name, and return to the checkout it came from. Web and Desktop expose these tools through Change requests & worktrees; other profiles can select this standalone bundle. Native tool calls and PTC programs receive the same typed result, and the existing file policy governs creation. +Let a model enter a Git worktree with one call, which creates the worktree when no worktree has the name, and return to the checkout it came from. Web and Desktop expose these tools through Change requests & worktrees; other profiles can select this standalone bundle. Native tool calls and PTC programs receive the same typed result, and the existing file policy governs creation. ## Table of Contents @@ -25,7 +25,7 @@ Let a model create and enter a new Git worktree with one call, enter an existing ## Use this package -In the GUI, enable [Change requests & worktrees](../forge-bundle/README.md). The standalone bundle has no Plugins page card. Profiles without the Web application may select it in `dsh.profile.bundles`; it loads the [worktree runtime](../worktree/README.md) and this tool together. Turning it off removes `create_worktree`, `enter_worktree`, and `exit_worktree` without deleting existing checkouts or branches; a Session inside a worktree stays there until a Host operation moves it. +In the GUI, enable [Change requests & worktrees](../forge-bundle/README.md). The standalone bundle has no Plugins page card. Profiles without the Web application may select it in `dsh.profile.bundles`; it loads the [worktree runtime](../worktree/README.md) and this tool together. Turning it off removes `enter_worktree` and `exit_worktree` without deleting existing checkouts or branches; a Session inside a worktree stays there until a Host operation moves it. For an explicit composition, mount this function plugin after the worktree runtime and tool registry. @@ -34,7 +34,7 @@ For an explicit composition, mount this function plugin after the worktree runti - name: '@deepseek-ai/dsh-experimental-tool-worktree' ``` -Call `create_worktree({ name?: string, from?: string })`. Success returns the canonical checkout `path`, new `branch`, pinned `baseCommit`, and source `repositoryRoot`, and changes the calling Session's current working directory. `enter_worktree({ name: string })` moves the Session into an existing worktree that was created from the checkout it is in, and returns the worktree's `path`, its `branch` when one is checked out, and the `repositoryRoot` the Session came from. To leave, call `exit_worktree()`: it returns the Session to the checkout it created or entered the worktree from and reports that worktree's record; the checkout and branch remain. The [generated tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-experimental-tool-worktree) owns the exact schema and model-facing description. +Call `enter_worktree({ name?: string, from?: string })`. When the worktree pool of the checkout the Session is in holds a registered worktree of that name, the call moves the Session into it, leaves branches and files as they are, and returns its `path`, its `branch` when one is checked out, the `repositoryRoot` the Session came from, and `created: false`. Otherwise it creates a new branch and checkout from `from`, HEAD by default, enters it, and returns `path`, `branch`, the pinned `baseCommit`, `repositoryRoot`, and `created: true`. Omitting `name` always creates one with a generated name. `from` asks for a new worktree, so it fails with `WORKTREE_ALREADY_EXISTS` when the name is taken. To leave, call `exit_worktree()`: it returns the Session to the checkout it created or entered the worktree from and reports that worktree's record; the checkout and branch remain. The [generated tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-experimental-tool-worktree) owns the exact schema and model-facing description. ----- @@ -44,7 +44,7 @@ Call `create_worktree({ name?: string, from?: string })`. Success returns the ca
Implementation internals — click to expand -[`cordis.patch.yml`](cordis.patch.yml) inserts the `worktree` runtime row and the `tool-worktree` consumer row. [`src/index.ts`](src/index.ts) registers three typed tools. The runtime owns Git behavior, cancellation, and the working-directory change. Each tool returns the runtime record as its canonical value and renders that record as JSON; its Host presentation uses the generic card. Disposal unregisters the tools. +[`cordis.patch.yml`](cordis.patch.yml) inserts the `worktree` runtime row and the `tool-worktree` consumer row. [`src/index.ts`](src/index.ts) registers two typed tools. `enter_worktree` asks the runtime to enter the named worktree and, only when the runtime reports `WORKTREE_NOT_FOUND`, to create it. The runtime owns Git behavior, cancellation, and the working-directory change. Each tool returns the runtime record as its canonical value and renders that record as JSON; its Host presentation uses the generic card. Disposal unregisters the tools. No runtime invariant companion is published because the tool retains no state independently of the worktree runtime. @@ -64,11 +64,11 @@ No runtime invariant companion is published because the tool retains no state in ## Model Experience -### Creation tool +### Worktree tools #### What the model sees -The [tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-experimental-tool-worktree) defines `create_worktree`, `enter_worktree`, and `exit_worktree`. Each successful result contains the canonical path and branch of the worktree created, entered, or left, and the top-level directory of the checkout the Session came from; a creation, and the exit of a created worktree, add the base commit. Failed calls report the operation error. +The [tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-experimental-tool-worktree) defines `enter_worktree` and `exit_worktree`. Each successful result contains the canonical path and branch of the worktree entered or left, and the top-level directory of the checkout the Session came from; a creation, and the exit of a created worktree, add the base commit. `created` tells the model whether `enter_worktree` made a new worktree. Failed calls report the operation error. #### Token effect @@ -83,7 +83,7 @@ Unchanged tool schemas retain their existing prefix. Calls append after prior hi - **Calling Agent required** — the tool changes a Session directory and rejects calls without an Agent. -- **Creation and entry only** — listing, inspection, merging, and checkout or branch removal are outside these tools, and `enter_worktree` reaches only worktrees in the pool of the checkout the Session is in; the [runtime limitations](../worktree/README.md#known-limitations-and-deferred-work) also apply. +- **Creation and entry only** — listing, inspection, merging, and checkout or branch removal are outside these tools. `enter_worktree` reaches only worktrees in the pool of the checkout the Session is in: a worktree elsewhere, or a sibling while the Session is inside another worktree, is not reachable by name; the [runtime limitations](../worktree/README.md#known-limitations-and-deferred-work) also apply. ### Dev Note diff --git a/packages/experimental/tool-worktree/README.zh.md b/packages/experimental/tool-worktree/README.zh.md index 2fd828b254..fc8c8ef16c 100644 --- a/packages/experimental/tool-worktree/README.zh.md +++ b/packages/experimental/tool-worktree/README.zh.md @@ -1,5 +1,5 @@ --- -description: "创建本地 Git 工作树、进入已有工作树并返回源检出的模型工具。" +description: "进入本地 Git 工作树(不存在时新建)并返回源检出的模型工具。" kind: "package-bundle" --- @@ -9,7 +9,7 @@ kind: "package-bundle" ## 概述 -让模型通过一次调用创建并进入新的 Git 工作树,按名称进入已有的工作树,并回到它来自的检出。Web 与 Desktop 通过“变更请求与工作树”提供这些工具;其他 profile 可以选择本独立组合包。原生工具调用与 PTC 程序获得相同的带类型结果,创建操作沿用现有文件策略。 +让模型通过一次调用进入 Git 工作树(没有同名工作树时新建),并回到它来自的检出。Web 与 Desktop 通过“变更请求与工作树”提供这些工具;其他 profile 可以选择本独立组合包。原生工具调用与 PTC 程序获得相同的带类型结果,创建操作沿用现有文件策略。 ## 目录 @@ -25,7 +25,7 @@ kind: "package-bundle" ## 使用本包 -在 GUI 中启用[变更请求与工作树](../forge-bundle/README.zh.md)。独立组合包在插件页没有卡片。未组合 Web 应用的 profile 可以在 `dsh.profile.bundles` 中选择它;它一起加载[工作树运行时](../worktree/README.zh.md)与本工具。关闭后会移除 `create_worktree`、`enter_worktree` 与 `exit_worktree`,已有检出目录与分支会保留;已在工作树中的 Session 会留在原处,直到 Host 操作移动它。 +在 GUI 中启用[变更请求与工作树](../forge-bundle/README.zh.md)。独立组合包在插件页没有卡片。未组合 Web 应用的 profile 可以在 `dsh.profile.bundles` 中选择它;它一起加载[工作树运行时](../worktree/README.zh.md)与本工具。关闭后会移除 `enter_worktree` 与 `exit_worktree`,已有检出目录与分支会保留;已在工作树中的 Session 会留在原处,直到 Host 操作移动它。 在显式组合中,将此函数插件挂载到工作树运行时和工具注册表之后。 @@ -34,7 +34,7 @@ kind: "package-bundle" - name: '@deepseek-ai/dsh-experimental-tool-worktree' ``` -调用 `create_worktree({ name?: string, from?: string })`。成功会返回规范化检出路径 `path`、新分支 `branch`、固定提交 `baseCommit` 和源仓库根目录 `repositoryRoot`,并改变调用 Session 的当前工作目录。`enter_worktree({ name: string })` 把 Session 移入从它所在检出创建的已有工作树,返回该工作树的 `path`、检出了分支时的 `branch`,以及 Session 进入前所在的 `repositoryRoot`。离开时调用 `exit_worktree()`:它把 Session 送回创建或进入该工作树时所在的检出,并返回该工作树的记录;检出目录与分支会保留。[生成的工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-experimental-tool-worktree)拥有准确的 schema 与面向模型的描述。 +调用 `enter_worktree({ name?: string, from?: string })`。Session 所在检出的工作树池中已有同名的已登记工作树时,调用把 Session 移入其中,分支与文件保持原样,返回它的 `path`、检出了分支时的 `branch`、Session 进入前所在的 `repositoryRoot`,以及 `created: false`。否则从 `from`(默认 HEAD)创建新的分支与检出目录并进入,返回 `path`、`branch`、固定提交 `baseCommit`、`repositoryRoot`,以及 `created: true`。省略 `name` 时总是用生成的名称新建。`from` 表示要新建工作树,所以名称已被占用时以 `WORKTREE_ALREADY_EXISTS` 失败。离开时调用 `exit_worktree()`:它把 Session 送回创建或进入该工作树时所在的检出,并返回该工作树的记录;检出目录与分支会保留。[生成的工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-experimental-tool-worktree)拥有准确的 schema 与面向模型的描述。 ----- @@ -44,7 +44,7 @@ kind: "package-bundle"
实现细节——点击展开 -[`cordis.patch.yml`](cordis.patch.yml) 插入 `worktree` 运行时行与 `tool-worktree` 消费方行。[`src/index.ts`](src/index.ts) 注册三个带类型的工具。运行时拥有 Git 行为、取消处理与工作目录切换。每个工具将运行时记录作为规范返回值,并渲染为 JSON;Host 展示使用通用卡片。销毁插件会注销这些工具。 +[`cordis.patch.yml`](cordis.patch.yml) 插入 `worktree` 运行时行与 `tool-worktree` 消费方行。[`src/index.ts`](src/index.ts) 注册两个带类型的工具。`enter_worktree` 请运行时进入指定名称的工作树,只有运行时报告 `WORKTREE_NOT_FOUND` 时才请它新建。运行时拥有 Git 行为、取消处理与工作目录切换。每个工具将运行时记录作为规范返回值,并渲染为 JSON;Host 展示使用通用卡片。销毁插件会注销这些工具。 本包不发布运行时不变量伴随入口,因为工具不保留独立于工作树运行时的状态。 @@ -64,11 +64,11 @@ kind: "package-bundle" ## 模型体验 -### 创建工具 +### 工作树工具 #### 模型看到什么 -[工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-experimental-tool-worktree)定义 `create_worktree`、`enter_worktree` 与 `exit_worktree`。每个成功结果包含所创建、所进入或所离开工作树的规范路径与分支,以及 Session 来自的检出的顶层目录;创建以及离开自己创建的工作树时还包含基准提交。失败调用报告操作错误。 +[工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-experimental-tool-worktree)定义 `enter_worktree` 与 `exit_worktree`。每个成功结果包含所进入或所离开工作树的规范路径与分支,以及 Session 来自的检出的顶层目录;创建以及离开自己创建的工作树时还包含基准提交。`created` 告诉模型 `enter_worktree` 是否新建了工作树。失败调用报告操作错误。 #### Token 影响 @@ -83,7 +83,7 @@ kind: "package-bundle" - **必须有调用 Agent**——工具改变 Session 目录,没有 Agent 的调用会被拒绝。 -- **仅负责创建与进入**——列出、检查、合并、移除检出目录或删除分支不属于这些工具,`enter_worktree` 只能到达 Session 所在检出的池中的工作树;[运行时限制](../worktree/README.zh.md#known-limitations-and-deferred-work)同样适用。 +- **仅负责创建与进入**——列出、检查、合并、移除检出目录或删除分支不属于这些工具。`enter_worktree` 只能到达 Session 所在检出的池中的工作树:其他位置的工作树,或 Session 已在某个工作树内时的同级工作树,都无法按名称到达;[运行时限制](../worktree/README.zh.md#known-limitations-and-deferred-work)同样适用。 ### 开发备注 diff --git a/packages/experimental/tool-worktree/docs/DETAIL.md b/packages/experimental/tool-worktree/docs/DETAIL.md index 6645c8233e..3764f467ba 100644 --- a/packages/experimental/tool-worktree/docs/DETAIL.md +++ b/packages/experimental/tool-worktree/docs/DETAIL.md @@ -1 +1 @@ -![A request for a new branch, the create_worktree call, and the new checkout beside the unchanged main checkout](preview.svg) +![A request for a new branch, the enter_worktree call, and the new checkout beside the unchanged main checkout](preview.svg) diff --git a/packages/experimental/tool-worktree/docs/DETAIL.zh.md b/packages/experimental/tool-worktree/docs/DETAIL.zh.md index dcde7fa4c8..cfb44a3666 100644 --- a/packages/experimental/tool-worktree/docs/DETAIL.zh.md +++ b/packages/experimental/tool-worktree/docs/DETAIL.zh.md @@ -1 +1 @@ -![请求在新分支上工作、create_worktree 调用,以及与保持不变的主工作树并列的新工作树](preview.zh.svg) +![请求在新分支上工作、enter_worktree 调用,以及与保持不变的主工作树并列的新工作树](preview.zh.svg) diff --git a/packages/experimental/tool-worktree/src/index.ts b/packages/experimental/tool-worktree/src/index.ts index f182226993..84f457268d 100644 --- a/packages/experimental/tool-worktree/src/index.ts +++ b/packages/experimental/tool-worktree/src/index.ts @@ -1,10 +1,10 @@ /** - * Model tools for creating and entering a new Git worktree, entering an existing one, and returning to the - * source checkout, through the shared runtime. + * Model tools for entering a Git worktree, which is created when no worktree has the requested name, and for + * returning to the source checkout, through the shared runtime. */ import type { Context } from '@deepseek-ai/cordis' -import type {} from '@deepseek-ai/dsh-experimental-worktree' +import { WorktreeError } from '@deepseek-ai/dsh-experimental-worktree' import { defineTool, ToolContextUnavailableError } from '@deepseek-ai/dsh-tools' /** Cordis plugin name. */ @@ -12,26 +12,16 @@ export const name = 'tool-worktree' /** Services required to register and execute the worktree tools. */ export const inject = ['tools', 'worktrees'] -/** Result fields of a created worktree. */ -const CREATED_SCHEMA = { - type: 'object', - additionalProperties: false, - properties: { - path: { type: 'string', required: true }, - branch: { type: 'string', required: true }, - baseCommit: { type: 'string', required: true }, - repositoryRoot: { type: 'string', required: true }, - }, -} as const - -/** Result fields of an entered worktree; `branch` is absent on a detached HEAD. */ +/** Result fields of the worktree a Session entered; a created one adds `baseCommit`, and `branch` is absent on a detached HEAD. */ const ENTERED_SCHEMA = { type: 'object', additionalProperties: false, properties: { path: { type: 'string', required: true }, branch: { type: 'string' }, + baseCommit: { type: 'string' }, repositoryRoot: { type: 'string', required: true }, + created: { type: 'boolean', required: true }, }, } as const @@ -48,32 +38,16 @@ const EXITED_SCHEMA = { } as const /** - * Register create_worktree, enter_worktree, and exit_worktree for model and PTC callers. + * Register enter_worktree and exit_worktree for model and PTC callers. * @param ctx - tool registry and worktree runtime. */ export function apply(ctx: Context): void { - ctx.tools.register(defineTool({ - name: 'create_worktree', - description: 'Create a new Git branch and worktree from a local commit, branch, or tag, then change this session\'s working directory to it. Uncommitted files stay in the source checkout. Existing names fail; enter_worktree enters an existing worktree. exit_worktree returns to the source checkout.', - parameters: { - name: { type: 'string', description: 'New branch name, also used as the checkout directory: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to generate a unique name.' }, - from: { type: 'string', description: 'Local commit, branch, or tag to start from. Defaults to HEAD; no fetch is performed.' }, - }, - output: { - schema: CREATED_SCHEMA, - render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }], - }, - async execute(args, exec) { - if (exec.agent === undefined) throw new ToolContextUnavailableError('create_worktree requires a calling agent') - return ctx.worktrees.create(exec.agent, args, exec.signal) - }, - presentCall: args => ({ card: 'generic', title: 'create_worktree', rawInput: args }), - })) ctx.tools.register(defineTool({ name: 'enter_worktree', - description: 'Change this session\'s working directory to an existing worktree that was created from the checkout this session is in. Branches and files stay as they are. exit_worktree returns to that checkout.', + description: 'Change this session\'s working directory to a Git worktree of the checkout it is in. An existing worktree named name is entered as it is. Otherwise a new branch and worktree are created from a local commit, branch, or tag, and uncommitted files stay in the source checkout. exit_worktree returns to the source checkout.', parameters: { - name: { type: 'string', required: true, description: 'Name the worktree was created with.' }, + name: { type: 'string', description: 'Worktree to enter, also the branch name and checkout directory of a new one: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to create a worktree with a generated name.' }, + from: { type: 'string', description: 'Local commit, branch, or tag a new worktree starts from. Defaults to HEAD; no fetch is performed. Fails when the worktree already exists.' }, }, output: { schema: ENTERED_SCHEMA, @@ -81,7 +55,15 @@ export function apply(ctx: Context): void { }, async execute(args, exec) { if (exec.agent === undefined) throw new ToolContextUnavailableError('enter_worktree requires a calling agent') - return ctx.worktrees.enter(exec.agent, args, exec.signal) + // A start revision asks for a new worktree, as does a call without a name. + if (args.name !== undefined && args.from === undefined) { + try { + return { ...await ctx.worktrees.enter(exec.agent, { name: args.name }, exec.signal), created: false } + } catch (error) { + if (!(error instanceof WorktreeError && error.code === 'WORKTREE_NOT_FOUND')) throw error + } + } + return { ...await ctx.worktrees.create(exec.agent, args, exec.signal), created: true } }, presentCall: args => ({ card: 'generic', title: 'enter_worktree', rawInput: args }), })) diff --git a/packages/experimental/tool-worktree/tests/loader-composition.spec.ts b/packages/experimental/tool-worktree/tests/loader-composition.spec.ts index 28e4618bb0..26080e4197 100644 --- a/packages/experimental/tool-worktree/tests/loader-composition.spec.ts +++ b/packages/experimental/tool-worktree/tests/loader-composition.spec.ts @@ -6,7 +6,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { pathToFileURL } from 'node:url' import { promisify } from 'node:util' -import { afterEach, describe, expect, it } from 'vitest' +import { afterEach, describe, expect, it, vi } from 'vitest' import { Context } from '@deepseek-ai/cordis' import Loader from '@deepseek-ai/cordis-plugin-loader' import Include from '@deepseek-ai/cordis-plugin-include' @@ -38,7 +38,7 @@ afterEach(async () => { }) describe('worktree tool through real Loader composition', () => { - it('creates and enters a new checkout, exits it to the source checkout, enters it again by name, reports canonical fields, and unregisters on disposal', async () => { + it('creates a checkout for a new name and enters an existing one, exits to the source checkout, reports canonical fields, and unregisters on disposal', async () => { root = await realpath(await mkdtemp(join(tmpdir(), 'dsh-worktree-loader-'))) const repository = join(root, 'repo') await mkdir(repository) @@ -87,64 +87,77 @@ describe('worktree tool through real Loader composition', () => { await context.loader.await() const agent = await context.agentLoop.create(brandString('worktree-loader'), {}, { cwd: repository }) - const invoke = (name: string, agentValue = agent) => executeToolFixture(context!, { - name: 'create_worktree', callId: brandString(name), arguments: { name }, agent: agentValue, signal: new AbortController().signal, + const enter = (args: { name?: string; from?: string }, agentValue?: typeof agent) => executeToolFixture(context!, { + name: 'enter_worktree', callId: brandString(`enter-${args.name ?? 'generated'}`), arguments: args, + signal: new AbortController().signal, + ...agentValue === undefined ? {} : { agent: agentValue }, }) - const result = await invoke('new-checkout') - const path = join(repository, '.agents/worktrees/new-checkout') - expect(result.isError).not.toBe(true) - expect(result.value).toEqual({ path, branch: 'new-checkout', baseCommit, repositoryRoot: repository }) - expect(result.content).toEqual([{ type: 'text', text: JSON.stringify(result.value) }]) - expect(context.workingDirectory.get(agent.session)).toBe(path) - expect(await readFile(join(path, 'file.txt'), 'utf8')).toBe('committed\n') - - const failure = await executeToolFixture(context, { - name: 'create_worktree', callId: brandString('no-agent'), arguments: {}, signal: new AbortController().signal, - }) - expect(failure.isError).toBe(true) - expect(failure.content.flatMap(block => block.type === 'text' ? [block.text] : []).join('\n')).toContain('requires a calling agent') - expect(failure.isError && failure.error.info).toEqual({ name: 'ToolContextUnavailableError', code: 'TOOL_CONTEXT_UNAVAILABLE' }) - const existing = await invoke('new-checkout') - expect(existing.isError && existing.error.info).toEqual({ name: 'WorktreeError', code: 'WORKTREE_ALREADY_EXISTS' }) - expect(context.tools.get('create_worktree')!.presentCall!({ name: 'named' })).toEqual({ - card: 'generic', title: 'create_worktree', rawInput: { name: 'named' }, - }) - const exit = (agentValue?: typeof agent) => executeToolFixture(context!, { name: 'exit_worktree', callId: brandString('exit'), arguments: {}, signal: new AbortController().signal, ...agentValue === undefined ? {} : { agent: agentValue }, }) + const text = (result: Awaited>) => result.content.flatMap(block => block.type === 'text' ? [block.text] : []).join('\n') + const path = join(repository, '.agents/worktrees/new-checkout') + const creation = { path, branch: 'new-checkout', baseCommit, repositoryRoot: repository } + + // No worktree has the name, so the call creates one. + const result = await enter({ name: 'new-checkout' }, agent) + expect(result.isError).not.toBe(true) + expect(result.value).toEqual({ ...creation, created: true }) + expect(result.content).toEqual([{ type: 'text', text: JSON.stringify(result.value) }]) + expect(context.workingDirectory.get(agent.session)).toBe(path) + expect(await readFile(join(path, 'file.txt'), 'utf8')).toBe('committed\n') + + const failure = await enter({}) + expect(failure.isError).toBe(true) + expect(text(failure)).toContain('requires a calling agent') + expect(failure.isError && failure.error.info).toEqual({ name: 'ToolContextUnavailableError', code: 'TOOL_CONTEXT_UNAVAILABLE' }) + // Inside the new worktree the name selects its own empty pool, and the branch of a nested worktree already exists. + const nested = await enter({ name: 'new-checkout' }, agent) + expect(nested.isError && nested.error.info).toEqual({ name: 'WorktreeError', code: 'WORKTREE_ALREADY_EXISTS' }) + expect(context.tools.get('enter_worktree')!.presentCall!({ name: 'named' })).toEqual({ + card: 'generic', title: 'enter_worktree', rawInput: { name: 'named' }, + }) + const left = await exit(agent) expect(left.isError).not.toBe(true) - expect(left.value).toEqual(result.value) - expect(left.content).toEqual([{ type: 'text', text: JSON.stringify(result.value) }]) + expect(left.value).toEqual(creation) + expect(left.content).toEqual([{ type: 'text', text: JSON.stringify(creation) }]) expect(context.workingDirectory.get(agent.session)).toBe(repository) const outside = await exit(agent) expect(outside.isError && outside.error.info).toEqual({ name: 'WorktreeError', code: 'WORKTREE_NOT_ENTERED' }) - expect(outside.content.flatMap(block => block.type === 'text' ? [block.text] : []).join('\n')).toContain('no recorded worktree contains the working directory') + expect(text(outside)).toContain('no recorded worktree contains the working directory') const agentless = await exit() expect(agentless.isError && agentless.error.info).toEqual({ name: 'ToolContextUnavailableError', code: 'TOOL_CONTEXT_UNAVAILABLE' }) expect(context.tools.get('exit_worktree')!.presentCall!({})).toEqual({ card: 'generic', title: 'exit_worktree', rawInput: {} }) - const enter = (name: string, agentValue?: typeof agent) => executeToolFixture(context!, { - name: 'enter_worktree', callId: brandString(`enter-${name}`), arguments: { name }, signal: new AbortController().signal, - ...agentValue === undefined ? {} : { agent: agentValue }, - }) - const entered = await enter('new-checkout', agent) + // The worktree now exists, so the same name enters it and creates nothing. + const branches = (await git('branch', '--list')).stdout + const entered = await enter({ name: 'new-checkout' }, agent) expect(entered.isError).not.toBe(true) - expect(entered.value).toEqual({ path, branch: 'new-checkout', repositoryRoot: repository }) + expect(entered.value).toEqual({ path, branch: 'new-checkout', repositoryRoot: repository, created: false }) expect(entered.content).toEqual([{ type: 'text', text: JSON.stringify(entered.value) }]) expect(context.workingDirectory.get(agent.session)).toBe(path) - expect((await exit(agent)).value).toEqual(result.value) - const missing = await enter('absent', agent) - expect(missing.isError && missing.error.info).toEqual({ name: 'WorktreeError', code: 'WORKTREE_NOT_FOUND' }) - expect(missing.content.flatMap(block => block.type === 'text' ? [block.text] : []).join('\n')).toContain('holds no registered worktree of that name') + expect((await git('branch', '--list')).stdout).toBe(branches) + expect((await exit(agent)).value).toEqual(creation) + + // A start revision asks for a new worktree, which an existing name refuses. + const refused = await enter({ name: 'new-checkout', from: 'HEAD' }, agent) + expect(refused.isError && refused.error.info).toEqual({ name: 'WorktreeError', code: 'WORKTREE_ALREADY_EXISTS' }) + // Only a missing worktree leads to creation: other lookup failures are reported as they are. + const create = vi.spyOn(context.worktrees, 'create') + const invalid = await enter({ name: '../outside' }, agent) + expect(invalid.isError && invalid.error.info).toEqual({ name: 'WorktreeError', code: 'WORKTREE_INVALID_ARGUMENT' }) + vi.spyOn(context.worktrees, 'enter').mockRejectedValueOnce(new Error('lookup failed')) + expect(text(await enter({ name: 'new-checkout' }, agent))).toContain('lookup failed') + expect(create).not.toHaveBeenCalled() expect(context.workingDirectory.get(agent.session)).toBe(repository) - const unowned = await enter('new-checkout') - expect(unowned.isError && unowned.error.info).toEqual({ name: 'ToolContextUnavailableError', code: 'TOOL_CONTEXT_UNAVAILABLE' }) - expect(context.tools.get('enter_worktree')!.presentCall!({ name: 'named' })).toEqual({ - card: 'generic', title: 'enter_worktree', rawInput: { name: 'named' }, - }) + + // Without a name the call creates a worktree with a generated name. + const generated = await enter({}, agent) + expect(generated.isError).not.toBe(true) + expect(generated.value).toMatchObject({ baseCommit, repositoryRoot: repository, created: true }) + expect(create).toHaveBeenCalledOnce() const entry = [...context.loader.entries()].find(candidate => candidate.options.name === 'cordis:@deepseek-ai/dsh-experimental-tool-worktree') await entry!.fiber!.dispose() diff --git a/scripts/gen-tool-catalog.ts b/scripts/gen-tool-catalog.ts index 19c127b570..e245b1f849 100644 --- a/scripts/gen-tool-catalog.ts +++ b/scripts/gen-tool-catalog.ts @@ -710,7 +710,7 @@ const TOOL_PACKAGES: ToolPackage[] = [ }) await ctx.plugin(ToolWorktree) }, - note: 'Enabled through the Change requests & worktrees bundle on Web and Desktop; other profiles can select the standalone bundle. Creates a new branch and checkout from a pinned local commit under existing write permissions, then changes the Session directory. `enter_worktree` moves the Session into an existing worktree in the pool of the checkout it works in; `exit_worktree` returns the Session to the checkout it came from; the branch and checkout remain.', + note: 'Enabled through the Change requests & worktrees bundle on Web and Desktop; other profiles can select the standalone bundle. `enter_worktree` moves the Session into the worktree a name selects in the pool of the checkout it works in, creating a new branch and checkout from a pinned local commit under existing write permissions when none has that name. `exit_worktree` returns the Session to the checkout it came from; the branch and checkout remain.', }, { pkg: '@deepseek-ai/dsh-tool-workflow', diff --git a/snapshots/session/worktree/session.v4.jsonl b/snapshots/session/worktree/session.v4.jsonl index 67c95b6df9..b6d573679c 100644 --- a/snapshots/session/worktree/session.v4.jsonl +++ b/snapshots/session/worktree/session.v4.jsonl @@ -12,12 +12,12 @@ {"type":"request/header","data":{"header":{"config":{"provider":"deepseek-official","model":"deepseek-v4-flash","maxTokens":256000,"reasoningEffort":"max"},"adapterDefaults":{"reasoningEffort":true,"maxTokens":true},"tools":"{{tools}}"},"reason":"initial"}} {"type":"request/context","data":{"provider":"deepseek-official","model":"deepseek-v4-flash","contextWindow":1000000}} {"type":"session/title","data":{"title":"Create a worktree named isolated","messageSeqs":[8],"source":{"kind":"fallback"}}} -{"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"tool-call","id":"worktree-1","name":"create_worktree","arguments":"{\"name\":\"isolated\",\"from\":\"HEAD\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:4}}"},"usage":{"inputTokens":10,"outputTokens":5},"stream":[{"type":"chunk","time":1794389455414,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794389455414,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"worktree-1","name":"create_worktree","arguments":"{\"name\":\"isolated\",\"from\":\"HEAD\"}"}}},{"type":"chunk","time":1794389455414,"chunk":{"type":"usage","usage":{"inputTokens":10,"outputTokens":5}}},{"type":"chunk","time":1794389455414,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"} -{"type":"tool/call","data":{"turn":1,"step":1,"callId":"worktree-1","name":"create_worktree","arguments":"{\"name\":\"isolated\",\"from\":\"HEAD\"}"}} +{"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"tool-call","id":"worktree-1","name":"enter_worktree","arguments":"{\"name\":\"isolated\",\"from\":\"HEAD\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:4}}"},"usage":{"inputTokens":10,"outputTokens":5},"stream":[{"type":"chunk","time":1794389455414,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794389455414,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"worktree-1","name":"enter_worktree","arguments":"{\"name\":\"isolated\",\"from\":\"HEAD\"}"}}},{"type":"chunk","time":1794389455414,"chunk":{"type":"usage","usage":{"inputTokens":10,"outputTokens":5}}},{"type":"chunk","time":1794389455414,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"} +{"type":"tool/call","data":{"turn":1,"step":1,"callId":"worktree-1","name":"enter_worktree","arguments":"{\"name\":\"isolated\",\"from\":\"HEAD\"}"}} {"type":"workspace-root/change","data":{"cwd":"{{cwd}}/.agents/worktrees/isolated"}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"The working directory changed from \"{{cwd}}\" to \"{{cwd}}/.agents/worktrees/isolated\"."}],"source":{"kind":"working-directory"},"role":"user","id":"{{message:5}}"}]}} {"type":"plugin:worktree/created","data":{"path":"{{cwd}}/.agents/worktrees/isolated","branch":"isolated","baseCommit":"86e2ed339bd583c54e29aaf0698fb8fb176ddcbb","repositoryRoot":"{{cwd}}"},"ignorable":true} -{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"worktree-1"},"toolCallId":"worktree-1","content":[{"type":"text","text":"{\"path\":\"{{cwd}}/.agents/worktrees/isolated\",\"branch\":\"isolated\",\"baseCommit\":\"86e2ed339bd583c54e29aaf0698fb8fb176ddcbb\",\"repositoryRoot\":\"{{cwd}}\"}"}],"isError":false,"id":"{{message:6}}"}},"sourceEventSeqs":[14],"surfaceOp":"append"} +{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"worktree-1"},"toolCallId":"worktree-1","content":[{"type":"text","text":"{\"path\":\"{{cwd}}/.agents/worktrees/isolated\",\"branch\":\"isolated\",\"baseCommit\":\"86e2ed339bd583c54e29aaf0698fb8fb176ddcbb\",\"repositoryRoot\":\"{{cwd}}\",\"created\":true}"}],"isError":false,"id":"{{message:6}}"}},"sourceEventSeqs":[14],"surfaceOp":"append"} {"type":"step/end","data":{"turn":1,"step":1}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"removedCount":1,"inserted":[]}} {"type":"step/start","data":{"turn":1,"step":2}} @@ -67,7 +67,7 @@ {"type":"workspace-root/change","data":{"cwd":"{{cwd}}/.agents/worktrees/isolated"}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"The working directory changed from \"{{cwd}}\" to \"{{cwd}}/.agents/worktrees/isolated\"."}],"source":{"kind":"working-directory"},"role":"user","id":"{{message:23}}"}]}} {"type":"plugin:worktree/entered","data":{"path":"{{cwd}}/.agents/worktrees/isolated","branch":"isolated","repositoryRoot":"{{cwd}}"},"ignorable":true} -{"type":"tool/result","data":{"turn":1,"step":8,"message":{"role":"tool","source":{"kind":"tool","callId":"worktree-8"},"toolCallId":"worktree-8","content":[{"type":"text","text":"{\"path\":\"{{cwd}}/.agents/worktrees/isolated\",\"branch\":\"isolated\",\"repositoryRoot\":\"{{cwd}}\"}"}],"isError":false,"id":"{{message:24}}"}},"sourceEventSeqs":[64],"surfaceOp":"append"} +{"type":"tool/result","data":{"turn":1,"step":8,"message":{"role":"tool","source":{"kind":"tool","callId":"worktree-8"},"toolCallId":"worktree-8","content":[{"type":"text","text":"{\"path\":\"{{cwd}}/.agents/worktrees/isolated\",\"branch\":\"isolated\",\"repositoryRoot\":\"{{cwd}}\",\"created\":false}"}],"isError":false,"id":"{{message:24}}"}},"sourceEventSeqs":[64],"surfaceOp":"append"} {"type":"step/end","data":{"turn":1,"step":8}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"removedCount":1,"inserted":[]}} {"type":"step/start","data":{"turn":1,"step":9}} @@ -88,12 +88,12 @@ {"type":"step/start","data":{"turn":1,"step":11}} {"type":"user/message","data":{"content":[{"type":"text","text":"The working directory changed from \"{{cwd}}/.agents/worktrees/isolated\" to \"{{cwd}}\"."}],"source":{"kind":"working-directory"},"role":"user","id":"{{message:29}}"},"surfaceOp":"append"} {"type":"user/message","data":{"content":[{"type":"text","text":"\nThe following information describes your current session. It replaces earlier versions of this context, including any retained in conversation summaries.\n\nCurrent working directory: \"{{cwd}}\".\n\nCurrent DSH file policy: danger-full-access. The DSH file sandbox does not restrict file modifications by available operations.\n\nApproval prompts are disabled in this session: actions that require approval are rejected automatically — do not request sandbox escalation (do not set `sandbox_permissions`).\n\nYou are the root agent. Your name is \"lead\".\n\nTo message other agents, use send_message({ agent: \"\", message: \"...\" }).\nUse list_agents({}) to find your collaborator agents and their names.\n"}],"source":{"kind":"runtime-context","form":"snapshot","sections":[{"name":"working-directory:current","text":"Current working directory: \"{{cwd}}\"."},{"name":"sandbox:policy","text":"Current DSH file policy: danger-full-access. The DSH file sandbox does not restrict file modifications by available operations."},{"name":"approval:policy","text":"Approval prompts are disabled in this session: actions that require approval are rejected automatically — do not request sandbox escalation (do not set `sandbox_permissions`)."},{"name":"subagent:identity","text":"You are the root agent. Your name is \"lead\".\n\nTo message other agents, use send_message({ agent: \"\", message: \"...\" }).\nUse list_agents({}) to find your collaborator agents and their names."}]},"role":"user","id":"{{message:31}}"},"surfaceOp":"append"} -{"type":"assistant/message","data":{"turn":1,"step":11,"message":{"role":"assistant","content":[{"type":"tool-call","id":"worktree-11","name":"create_worktree","arguments":"{\"name\":\"doomed\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:32}}"},"usage":{"inputTokens":10,"outputTokens":5},"stream":[{"type":"chunk","time":1794564229610,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794564229610,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"worktree-11","name":"create_worktree","arguments":"{\"name\":\"doomed\"}"}}},{"type":"chunk","time":1794564229610,"chunk":{"type":"usage","usage":{"inputTokens":10,"outputTokens":5}}},{"type":"chunk","time":1794564229610,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"} -{"type":"tool/call","data":{"turn":1,"step":11,"callId":"worktree-11","name":"create_worktree","arguments":"{\"name\":\"doomed\"}"}} +{"type":"assistant/message","data":{"turn":1,"step":11,"message":{"role":"assistant","content":[{"type":"tool-call","id":"worktree-11","name":"enter_worktree","arguments":"{\"name\":\"doomed\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:32}}"},"usage":{"inputTokens":10,"outputTokens":5},"stream":[{"type":"chunk","time":1794564229610,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794564229610,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"worktree-11","name":"enter_worktree","arguments":"{\"name\":\"doomed\"}"}}},{"type":"chunk","time":1794564229610,"chunk":{"type":"usage","usage":{"inputTokens":10,"outputTokens":5}}},{"type":"chunk","time":1794564229610,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"} +{"type":"tool/call","data":{"turn":1,"step":11,"callId":"worktree-11","name":"enter_worktree","arguments":"{\"name\":\"doomed\"}"}} {"type":"workspace-root/change","data":{"cwd":"{{cwd}}/.agents/worktrees/doomed"}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"The working directory changed from \"{{cwd}}\" to \"{{cwd}}/.agents/worktrees/doomed\"."}],"source":{"kind":"working-directory"},"role":"user","id":"{{message:33}}"}]}} {"type":"plugin:worktree/created","data":{"path":"{{cwd}}/.agents/worktrees/doomed","branch":"doomed","baseCommit":"86e2ed339bd583c54e29aaf0698fb8fb176ddcbb","repositoryRoot":"{{cwd}}"},"ignorable":true} -{"type":"tool/result","data":{"turn":1,"step":11,"message":{"role":"tool","source":{"kind":"tool","callId":"worktree-11"},"toolCallId":"worktree-11","content":[{"type":"text","text":"{\"path\":\"{{cwd}}/.agents/worktrees/doomed\",\"branch\":\"doomed\",\"baseCommit\":\"86e2ed339bd583c54e29aaf0698fb8fb176ddcbb\",\"repositoryRoot\":\"{{cwd}}\"}"}],"isError":false,"id":"{{message:34}}"}},"sourceEventSeqs":[90],"surfaceOp":"append"} +{"type":"tool/result","data":{"turn":1,"step":11,"message":{"role":"tool","source":{"kind":"tool","callId":"worktree-11"},"toolCallId":"worktree-11","content":[{"type":"text","text":"{\"path\":\"{{cwd}}/.agents/worktrees/doomed\",\"branch\":\"doomed\",\"baseCommit\":\"86e2ed339bd583c54e29aaf0698fb8fb176ddcbb\",\"repositoryRoot\":\"{{cwd}}\",\"created\":true}"}],"isError":false,"id":"{{message:34}}"}},"sourceEventSeqs":[90],"surfaceOp":"append"} {"type":"step/end","data":{"turn":1,"step":11}} {"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"removedCount":1,"inserted":[]}} {"type":"step/start","data":{"turn":1,"step":12}} diff --git a/snapshots/session/worktree/tool-schemas.expected.json b/snapshots/session/worktree/tool-schemas.expected.json index 77defbcf50..a98620c92d 100644 --- a/snapshots/session/worktree/tool-schemas.expected.json +++ b/snapshots/session/worktree/tool-schemas.expected.json @@ -93,23 +93,6 @@ ] } }, - { - "name": "create_worktree", - "description": "Create a new Git branch and worktree from a local commit, branch, or tag, then change this session's working directory to it. Uncommitted files stay in the source checkout. Existing names fail; enter_worktree enters an existing worktree. exit_worktree returns to the source checkout.", - "parameters": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "New branch name, also used as the checkout directory: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to generate a unique name." - }, - "from": { - "type": "string", - "description": "Local commit, branch, or tag to start from. Defaults to HEAD; no fetch is performed." - } - } - } - }, { "name": "edit", "description": "Edit an existing UTF-8 text file by replacing literal text.", @@ -154,18 +137,19 @@ }, { "name": "enter_worktree", - "description": "Change this session's working directory to an existing worktree that was created from the checkout this session is in. Branches and files stay as they are. exit_worktree returns to that checkout.", + "description": "Change this session's working directory to a Git worktree of the checkout it is in. An existing worktree named name is entered as it is. Otherwise a new branch and worktree are created from a local commit, branch, or tag, and uncommitted files stay in the source checkout. exit_worktree returns to the source checkout.", "parameters": { "type": "object", "properties": { "name": { "type": "string", - "description": "Name the worktree was created with." + "description": "Worktree to enter, also the branch name and checkout directory of a new one: a few lowercase words joined by hyphens that describe the task, such as fix-login-retry. Omit to create a worktree with a generated name." + }, + "from": { + "type": "string", + "description": "Local commit, branch, or tag a new worktree starts from. Defaults to HEAD; no fetch is performed. Fails when the worktree already exists." } - }, - "required": [ - "name" - ] + } } }, {