CSY656/dsh-worktree1

dsh-worktree

DSH Git worktree 文件系统隔离插件:通过 Git worktree 实现分支级的文件系统隔离,支持动态创建、列出和删除工作树。

AI 分析

核心用途是为 Agent 提供干净、隔离的代码运行环境,防止并发任务冲突。适合进行多分支并行开发或自动化测试的任务。需 DSH >= 0.1.0-rc.6。

包名
dsh-worktree
版本
0.1.0
许可证
MIT
最近更新
2026年8月14日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:CSY656/dsh-worktree

Usage

/worktree create feature/demo    → creates .dsh/worktrees/feature+demo, branch worktree-feature+demo
/worktree list                   → name/path/branch rows
/worktree remove feature/demo    → refuses while dirty; --discard forces

Service API (for plugin authors):

const lease = await ctx.worktree.acquire('agent-abc1234', cwd)  // create/restore at HEAD
// ...run an isolated child with its session header.cwd = lease.entry.path...
const { kept, path, branch } = await lease.release()            // clean → removed; dirty → kept + reported
  • Worktrees live at /.dsh/worktrees//; nested slugs flatten / to + (team/aliceteam+alice), branch worktree-team+alice.
  • validateSlug enforces [a-zA-Z0-9._-] per segment, length ≤ 64, rejecting ., .., //, and leading/trailing separators.
  • Post-creation setup is best-effort: copies project .dsh config, inherits core.hooksPath, symlinks node_modules/.venv/vendor (Windows symlink failures degrade to a warning), copies .worktreeinclude-listed ignored files.
  • Change detection is fail-closed: any git failure counts as "has changes", so a broken worktree is kept rather than deleted.
  • Per-repository mutations serialize; concurrent acquires of the same slug are idempotent (fast restore, no git subprocess).

Configuration

interface Config {
  sweepIntervalMs?: number  // default 3_600_000 (1h)
  sweepMaxAgeMs?: number    // default 86_400_000 (24h); only agent-* temp worktrees are swept
}