SuperAPI AI 工具集

using-git-worktrees

编程与开发

查看项目

更新于 10-16 09:44

技能介绍

用途:在开始需要隔离的 feature work 或执行 implementation plans 前,确保工作发生在隔离 workspace 中。核心原则是先检测现有隔离,再使用原生工具,最后才 fallback 到 git,绝不对抗 harness。

主要流程:Step 0 检测现有隔离,通过 git rev-parse --git-dir 与 --git-common-dir 判断是否已在 linked worktree,并用 git rev-parse --show-superproject-working-tree 排除 submodule 误判;若已在隔离 workspace 则跳过创建。若为普通 repo 且用户未表明偏好,需先征得同意。

Step 1 创建隔离:优先使用原生 worktree 工具(如 EnterWorktree、WorktreeCreate、/worktree 或 --worktree flag),有原生工具时使用 git worktree add 会产生 harness 无法管理的 phantom state。仅无原生工具时用 fallback:按现有偏好、项目本地 .worktrees/ 或 worktrees/、全局 ~/.config/superpowers/worktrees/$project、默认 .worktrees/ 的顺序选择目录,项目本地目录须用 git check-ignore 验证已 ignored,未 ignored 则加入 .gitignore 并提交,然后 git worktree add "$path" -b "$BRANCH_NAME" 并 cd。若因 sandbox 权限失败,则在当前目录工作。

Step 3 自动检测并运行项目 setup(package.json→npm install、Cargo.toml→cargo build、requirements.txt→pip install、pyproject.toml→poetry install、go.mod→go mod download)。Step 4 运行测试验证干净 baseline,失败则报告并询问是否继续,通过则报告就绪。

限制与常见错误:不得在已有隔离时创建 worktree,不得在有原生工具时使用 git worktree add,不得跳过 ignore 验证或 baseline 测试,不得假设目录位置,测试失败时不得未经许可继续。