mcpField
W
workspace-isolation

workspace-isolation

github.com/qodex-ai开发47129 次安装42 周前更新
代码仓库

关于 workspace-isolation

面向开发者和编码 Agent 的 Git worktree 技能,可为并行分支工作建立隔离工作区,并指导目录选择、安全检查、项目配置和基线测试。

主要功能

  1. 01按优先级选择 worktree 目录
  2. 02检查本地目录的 .gitignore
  3. 03检测项目配置命令
  4. 04运行测试验证干净基线
  5. 05继续前报告测试失败

适用场景

  1. 01同时处理多个分支
  2. 02为实现任务准备隔离工作区
  3. 03修改前检查基线测试

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/qodex-ai/ai-agent-skills --skill workspace-isolation

安装后在 Claude Code 中输入/workspace-isolation确认已加载。

详细介绍

使用 Git Worktrees

概述

Git worktrees 可创建共享同一仓库的隔离工作区,让你无需切换分支即可同时处理多个分支。

核心原则: 系统化选择目录 + 安全验证 = 可靠隔离。

开始时宣布:“我正在使用 using-git-worktrees 技能来设置隔离工作区。”

目录选择流程

按以下优先顺序操作:

1. 检查现有目录
# Check in priority order
ls -d .worktrees 2>/dev/null     # Preferred (hidden)
ls -d worktrees 2>/dev/null      # Alternative

**如果找到:**使用该目录。如果两者都存在,则优先使用 .worktrees。

2. 检查 CLAUDE.md
grep -i "worktree.*director" CLAUDE.md 2>/dev/null

**如果指定了首选项:**直接使用,无需询问。

3. 询问用户

如果不存在目录,且 CLAUDE.md 中也没有首选项:

No worktree directory found. Where should I create worktrees?

1. .worktrees/ (project-local, hidden)
2. ~/.config/superpowers/worktrees/<project-name>/ (global location)

Which would you prefer?

安全验证

对于项目本地目录(.worktrees 或 worktrees)

创建 worktree 前必须验证 .gitignore:

# Check if directory pattern in .gitignore
grep -q "^\.worktrees/$" .gitignore || grep -q "^worktrees/$" .gitignore

如果未列入 .gitignore:

按照 Jesse 的规则“立即修复问题”:

  1. 在 .gitignore 中添加合适的条目
  2. 提交此更改
  3. 继续创建 worktree

**为何至关重要:**防止意外将 worktree 内容提交到仓库。

对于全局目录(~/.config/superpowers/worktrees)

无需验证 .gitignore,因为此目录完全位于项目之外。

创建步骤

1. 检测项目名称
project=$(basename "$(git rev-parse --show-toplevel)")
2. 创建 Worktree
# Determine full path
case $LOCATION in
  .worktrees|worktrees)
    path="$LOCATION/$BRANCH_NAME"
    ;;
  ~/.config/superpowers/worktrees/*)
    path="~/.config/superpowers/worktrees/$project/$BRANCH_NAME"
    ;;
esac

# Create worktree with new branch
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
3. 运行项目设置

自动检测并运行相应的设置:

# Node.js
if [ -f package.json ]; then npm install; fi

# Rust
if [ -f Cargo.toml ]; then cargo build; fi

# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi

# Go
if [ -f go.mod ]; then go mod download; fi
4. 验证干净的基线

运行测试,确保 worktree 初始状态干净:

# Examples - use project-appropriate command
npm test
cargo test
pytest
go test ./...

**如果测试失败:**报告失败情况,并询问是继续还是调查问题。

**如果测试通过:**报告已就绪。

5. 报告位置
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>

快速参考

情况操作
.worktrees/ 存在使用该目录(验证 .gitignore)
worktrees/ 存在使用该目录(验证 .gitignore)
两者都存在使用 .worktrees/
两者都不存在检查 CLAUDE.md → 询问用户
目录未列入 .gitignore立即添加并提交
基线测试失败报告失败情况并询问
没有 package.json/Cargo.toml跳过依赖安装

常见错误

跳过 .gitignore 验证

  • **问题:**worktree 内容会被跟踪,污染 git status
  • **修复:**创建项目本地 worktree 前,务必先 grep .gitignore

臆测目录位置

  • **问题:**导致不一致,违反项目约定
  • **修复:**遵循优先顺序:现有目录 > CLAUDE.md > 询问

测试失败仍继续

  • **问题:**无法区分新出现的错误和既有问题
  • **修复:**报告失败情况,获得明确许可后再继续

硬编码设置命令

  • **问题:**在使用不同工具的项目中会失效
  • **修复:**根据项目文件(package.json 等)自动检测

工作流示例

You: I'm using the using-git-worktrees skill to set up an isolated workspace.

[Check .worktrees/ - exists]
[Verify .gitignore - contains .worktrees/]
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
[Run npm install]
[Run npm test - 47 passing]

Worktree ready at /Users/jesse/myproject/.worktrees/auth
Tests passing (47 tests, 0 failures)
Ready to implement auth feature

危险信号

绝不:

  • 未验证 .gitignore 就创建 worktree(项目本地)
  • 跳过基线测试验证
  • 未经询问就在测试失败时继续
  • 在目录位置不明确时自行假定
  • 跳过检查 CLAUDE.md

始终:

  • 遵循目录优先顺序:现有目录 > CLAUDE.md > 询问
  • 验证项目本地目录的 .gitignore
  • 自动检测并运行项目设置
  • 验证测试基线干净

集成

由以下项目调用:

  • brainstorming(阶段 4)- 设计获批并进入实施阶段时必须使用
  • 任何需要隔离工作区的技能

配合使用:

  • finishing-a-development-branch - 工作完成后必须用于清理
  • executing-plans 或 subagent-driven-development - 在此 worktree 中开展工作

评论

支持 Markdown