DSH / Atlas
2026-09-13implementedfeature

Explicit worktree creation

显式创建工作树

A Session that needs an isolated checkout otherwise has to coordinate Git commands with its own working directory. Changing a shell process directory does not update the Session's later tools or recorded context, and a linked worktree's Git administration directory can lie outside the Session's existing write grant.

English

Problem

A Session that needs an isolated checkout otherwise has to coordinate Git commands with its own working directory. Changing a shell process directory does not update the Session's later tools or recorded context, and a linked worktree's Git administration directory can lie outside the Session's existing write grant.

Decision

The experimental worktree runtime 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 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.

Git and directory creation use the mounted subprocess and sandbox providers without widening the calling Session's policy. Both destination and shared Git metadata writes must already be permitted. Successful creation changes only the current working directory; the Session identity and original sandbox root remain owned by their existing services.

Leaving uses the shared working-directory operation and retains the checkout and branch. Failed setup can retain partial artifacts and reports their location. The service does not own a branch merge policy or a task association database.

The service records each creation as a plugin:worktree/created record and owns archive-triggered cleanup of those checkouts, as the job and Agent registries own their archive-admission families. A Session's inherited prefix decides whether it created a checkout or merely refers to one; cwd alone never grants cleanup ownership. Admission registers the attempt inside the Workspace write queue and returns; inspection reads cold Sessions through the projection cache or their log, without starting an Agent, and runs afterwards. Only a clean, unreferenced checkout is removed, without force and without deleting its branch; tracked changes and untracked files retain it, ignored files do not, matching Git's own non-force refusal. Inspection trusts git status alone, as peer agent products do: edits to skip-worktree or assume-unchanged files are discarded with the checkout, because sparse checkout sets skip-worktree on every file outside its cone and inspecting those bits would retain every sparse checkout. A checkout whose administrative directory holds submodule repositories is retained; a committed embedded repository is not inspected, and Git's refusal of that removal settles the attempt as failed. Processes and terminals are not consulted. A volatile retainOnArchive setting, read at admission, turns the cleanup off without unmounting the service; the Forge client edits it on the bundle's worktree row of the Plugins page because the service package has no Client half. Unarchiving cancels an unadmitted removal and waits for an admitted one, and directory entry into a checkout being removed waits for that removal. No startup sweep deletes previously archived worktrees.

Alternatives considered

A separate worktree-exit tool. Leaving is the existing working-directory operation; another exit operation would needlessly couple directory changes to Git ownership or deletion.

Copy the dirty checkout into each new worktree. A pinned local commit gives the caller an explicit baseline without mixing staged, unstaged, untracked, and ignored state or inventing conflict rules.

Automatic subagent isolation. Agent Teams keeps its existing explicit coordination model. Creating a checkout is available as an operation rather than an implicit consequence of delegation.

Expand write grants during creation. A convenience operation cannot acquire authority over a shared Git administration directory merely because the destination is writable.

Consequences

The caller can continue one Session in a new checkout with a reconstructable directory change. Retention avoids deleting work on exit or a failed final publication, while archiving reclaims a clean checkout without touching branch lifetime. Git and Node must be available in the filesystem provider's execution world. Submodule setup and dependency installation remain separate operations.

中文

Problem

需要隔离检出目录的 Session 原本必须自行协调 Git 命令与工作目录。改变 shell 进程目录不会更新 Session 后续工具或已记录的上下文,而且链接工作树的 Git 管理目录可能位于 Session 既有写权限范围之外。

Decision

实验性工作树运行时从固定的本地提交创建新的具名分支与检出目录,然后通过共享工作目录服务进入其规范路径。工具以 enter_worktree({ name?, from? }) 公开它,同名工作树已存在时进入该工作树。这些包使用普通的显式组合,不添加额外运行时功能开关。

源仓库由调用 Session 的当前目录决定。创建操作不会获取远端提交或复制未提交文件。默认父目录是当前检出目录顶层路径下的 .agents/worktrees,调用方位于链接检出目录中时也一样。创建该目录的进程写入忽略自身的 .gitignore;已有目录与忽略文件保持不变。名称必须对应新分支与尚未使用的检出路径。

Git 与目录创建使用挂载的子进程及沙箱提供方,不扩大调用 Session 的策略。目标目录与共享 Git 元数据必须均已允许写入。成功创建只改变当前工作目录;Session 身份与原始沙箱根目录仍由已有服务拥有。

离开使用共享工作目录操作,保留检出目录与分支。初始化失败可能留下部分产物,并报告其位置。该服务不拥有分支合并策略或任务关联数据库。

服务把每次创建记录为 plugin:worktree/created Session 事件,并像 job 与 Agent 注册表各自拥有归档准入家族那样,拥有这些检出目录的归档触发清理。Session 的继承前缀决定它创建了某个检出目录还是仅引用它;当前工作目录本身不授予清理所有权。准入在 Workspace 写队列内登记尝试并返回;检查通过投影缓存或日志读取冷 Session,不启动 Agent,并在之后执行。只删除干净且无人引用的检出目录,不带 force 也不删除分支;跟踪文件改动与未跟踪文件保留目录,被忽略的文件不保留,与 Git 自身不带 force 时的拒绝条件一致。检查与同类 Agent 产品一样只依据 git status:skip-worktree 或 assume-unchanged 文件的改动随检出目录一起丢弃,因为 sparse checkout 会给稀疏范围之外的每个文件设置 skip-worktree,检查这些标记会保留每个稀疏检出目录。管理目录中含子模块仓库的检出目录会保留;已提交的内嵌仓库不在检查范围内,Git 拒绝这类删除,本次尝试以失败结束。不咨询进程与终端。volatile 的 retainOnArchive 设置在准入时读取,无需卸载服务即可关闭清理;由于服务包没有 Client 半部,Forge 客户端在插件页该套件的 worktree 行上编辑它。取消归档会取消尚未获准的删除并等待已获准的删除,进入正在删除的检出目录会等待该删除结束。不在启动时扫描删除此前已归档的工作树。

Alternatives considered

单独提供工作树退出工具。 离开就是已有工作目录操作;另一个退出操作会无谓地将目录切换与 Git 所有权或删除耦合。

将未提交状态复制到每个新工作树。 固定本地提交为调用方提供显式基准,无需混合暂存、未暂存、未跟踪和被忽略的状态,也无需制定冲突规则。

自动隔离子代理。 Agent Teams保留已有的显式协调模型。创建检出目录是一项可调用操作,而不是委派的隐含结果。

创建时扩大写权限。 便捷操作不能仅因目标目录可写,就获得共享 Git 管理目录的权限。

Consequences

调用方可以在新的检出目录继续同一个 Session,且目录切换可重建。保留策略避免在离开或最后发布失败时删除工作,而归档会回收干净的检出目录,不触及分支生命周期。Git 与 Node 必须存在于文件系统提供方的执行环境中。子模块配置与依赖安装仍是独立操作。