cc-devflow 4.1.4 → 4.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.claude/CLAUDE.md +87 -1183
  2. package/.claude/commands/core/architecture.md +2 -2
  3. package/.claude/commands/core/guidelines.md +2 -2
  4. package/.claude/commands/core/roadmap.md +4 -4
  5. package/.claude/commands/core/style.md +40 -268
  6. package/.claude/commands/flow/CLAUDE.md +28 -0
  7. package/.claude/commands/flow/archive.md +2 -2
  8. package/.claude/commands/flow/checklist.md +9 -251
  9. package/.claude/commands/flow/clarify.md +9 -127
  10. package/.claude/commands/flow/constitution.md +1 -1
  11. package/.claude/commands/flow/context.md +1 -1
  12. package/.claude/commands/flow/dev.md +19 -395
  13. package/.claude/commands/flow/fix.md +1 -6
  14. package/.claude/commands/flow/ideate.md +13 -13
  15. package/.claude/commands/flow/init.md +19 -41
  16. package/.claude/commands/flow/new.md +12 -268
  17. package/.claude/commands/flow/quality.md +10 -153
  18. package/.claude/commands/flow/release.md +18 -131
  19. package/.claude/commands/flow/restart.md +15 -16
  20. package/.claude/commands/flow/spec.md +14 -164
  21. package/.claude/commands/flow/status.md +12 -12
  22. package/.claude/commands/flow/update.md +4 -4
  23. package/.claude/commands/flow/upgrade.md +6 -6
  24. package/.claude/commands/flow/verify.md +19 -78
  25. package/.claude/commands/flow/workspace.md +3 -20
  26. package/.claude/docs/guides/INIT_TROUBLESHOOTING.md +7 -7
  27. package/.claude/docs/guides/NEW_TROUBLESHOOTING.md +44 -96
  28. package/.claude/docs/guides/ROADMAP_TROUBLESHOOTING.md +1 -1
  29. package/.claude/docs/guides/TASK_COMPLETION_MARKING.md +5 -5
  30. package/.claude/docs/guides/TEAM_MODE_GUIDE.md +0 -1
  31. package/.claude/docs/templates/ATTEMPT_TEMPLATE.md +1 -1
  32. package/.claude/docs/templates/BACKLOG_TEMPLATE.md +3 -3
  33. package/.claude/docs/templates/CLARIFICATION_REPORT_TEMPLATE.md +5 -5
  34. package/.claude/docs/templates/ERROR_LOG_TEMPLATE.md +2 -2
  35. package/.claude/docs/templates/INIT_FLOW_TEMPLATE.md +3 -3
  36. package/.claude/docs/templates/NEW_ORCHESTRATION_TEMPLATE.md +33 -64
  37. package/.claude/docs/templates/RESEARCH_TEMPLATE.md +3 -3
  38. package/.claude/docs/templates/ROADMAP_DIALOGUE_TEMPLATE.md +2 -2
  39. package/.claude/docs/templates/ROADMAP_TEMPLATE.md +2 -2
  40. package/.claude/docs/templates/STYLE_TEMPLATE.md +3 -3
  41. package/.claude/docs/templates/UI_PROTOTYPE_TEMPLATE.md +8 -9
  42. package/.claude/guides/workflow-guides/flow-orchestrator.md +31 -265
  43. package/.claude/hooks/CLAUDE.md +1 -1
  44. package/.claude/hooks/checklist-gate.js +4 -4
  45. package/.claude/hooks/inject-agent-context.ts +2 -2
  46. package/.claude/hooks/teammate-idle-hook.ts +1 -1
  47. package/.claude/rules/devflow-conventions.md +2 -93
  48. package/.claude/scripts/CLAUDE.md +1 -4
  49. package/.claude/scripts/calculate-checklist-completion.sh +2 -2
  50. package/.claude/scripts/check-prerequisites.sh +2 -2
  51. package/.claude/scripts/checklist-errors.sh +4 -4
  52. package/.claude/scripts/common.sh +12 -147
  53. package/.claude/scripts/flow-quality-full.sh +5 -5
  54. package/.claude/scripts/flow-quality-quick.sh +4 -4
  55. package/.claude/scripts/flow-workspace-init.sh +2 -2
  56. package/.claude/scripts/generate-clarification-report.sh +4 -4
  57. package/.claude/scripts/recover-workflow.sh +70 -73
  58. package/.claude/scripts/run-quality-gates.sh +1 -1
  59. package/.claude/scripts/setup-epic.sh +2 -2
  60. package/.claude/scripts/setup-ralph-loop.sh +2 -2
  61. package/.claude/scripts/validate-research.sh +1 -1
  62. package/.claude/scripts/verify-setup.sh +1 -1
  63. package/.claude/skills/cc-devflow-orchestrator/SKILL.md +88 -108
  64. package/.claude/skills/workflow/CLAUDE.md +24 -0
  65. package/.claude/skills/workflow/flow-dev/CLAUDE.md +14 -76
  66. package/.claude/skills/workflow/flow-dev/SKILL.md +29 -67
  67. package/.claude/skills/workflow/flow-dev/context.jsonl +4 -8
  68. package/.claude/skills/workflow/flow-init/SKILL.md +23 -186
  69. package/.claude/skills/workflow/flow-init/assets/RESEARCH_TEMPLATE.md +1 -1
  70. package/.claude/skills/workflow/flow-init/context.jsonl +3 -3
  71. package/.claude/skills/workflow/flow-init/scripts/check-prerequisites.sh +1 -1
  72. package/.claude/skills/workflow/flow-init/scripts/create-requirement.sh +15 -134
  73. package/.claude/skills/workflow/flow-init/scripts/validate-research.sh +1 -1
  74. package/.claude/skills/workflow/flow-release/SKILL.md +20 -110
  75. package/.claude/skills/workflow/flow-release/context.jsonl +5 -7
  76. package/.claude/skills/workflow/flow-spec/CLAUDE.md +15 -101
  77. package/.claude/skills/workflow/flow-spec/SKILL.md +15 -518
  78. package/.claude/skills/workflow/flow-spec/context.jsonl +5 -7
  79. package/.claude/skills/workflow/flow-verify/CLAUDE.md +10 -0
  80. package/.claude/skills/workflow/flow-verify/SKILL.md +53 -0
  81. package/.claude/skills/workflow/flow-verify/context.jsonl +5 -0
  82. package/.claude/skills/workflow.yaml +72 -270
  83. package/CHANGELOG.md +72 -0
  84. package/README.md +91 -69
  85. package/README.zh-CN.md +90 -67
  86. package/bin/harness.js +22 -0
  87. package/docs/commands/README.md +34 -38
  88. package/docs/commands/README.zh-CN.md +34 -36
  89. package/docs/commands/core-roadmap.md +2 -2
  90. package/docs/commands/core-roadmap.zh-CN.md +2 -2
  91. package/docs/commands/core-style.md +29 -381
  92. package/docs/commands/core-style.zh-CN.md +29 -381
  93. package/docs/commands/flow-init.md +10 -10
  94. package/docs/commands/flow-init.zh-CN.md +11 -11
  95. package/docs/commands/flow-new.md +25 -260
  96. package/docs/commands/flow-new.zh-CN.md +26 -257
  97. package/docs/guides/getting-started.md +16 -15
  98. package/docs/guides/getting-started.zh-CN.md +10 -12
  99. package/lib/compiler/__tests__/manifest.test.js +156 -0
  100. package/lib/compiler/__tests__/parser.test.js +21 -0
  101. package/lib/compiler/index.js +17 -1
  102. package/lib/compiler/manifest.js +68 -6
  103. package/lib/compiler/parser.js +5 -0
  104. package/lib/harness/CLAUDE.md +21 -0
  105. package/lib/harness/cli.js +208 -0
  106. package/lib/harness/index.js +16 -0
  107. package/lib/harness/operations/dispatch.js +285 -0
  108. package/lib/harness/operations/init.js +48 -0
  109. package/lib/harness/operations/janitor.js +74 -0
  110. package/lib/harness/operations/pack.js +100 -0
  111. package/lib/harness/operations/plan.js +29 -0
  112. package/lib/harness/operations/release.js +83 -0
  113. package/lib/harness/operations/resume.js +44 -0
  114. package/lib/harness/operations/verify.js +163 -0
  115. package/lib/harness/planner.js +141 -0
  116. package/lib/harness/schemas.js +108 -0
  117. package/lib/harness/store.js +240 -0
  118. package/package.json +9 -1
  119. package/.claude/scripts/flow-workspace-start.sh +0 -217
  120. package/.claude/scripts/flow-workspace-switch.sh +0 -234
  121. package/.claude/skills/domain/using-git-worktrees/SKILL.md +0 -252
  122. package/.claude/skills/domain/using-git-worktrees/assets/SHELL_ALIASES.md +0 -133
  123. package/.claude/skills/domain/using-git-worktrees/context.jsonl +0 -4
  124. package/.claude/skills/domain/using-git-worktrees/scripts/worktree-cleanup.sh +0 -218
  125. package/.claude/skills/domain/using-git-worktrees/scripts/worktree-create.sh +0 -232
  126. package/.claude/skills/domain/using-git-worktrees/scripts/worktree-list.sh +0 -130
  127. package/.claude/skills/domain/using-git-worktrees/scripts/worktree-status.sh +0 -140
  128. package/.claude/skills/domain/using-git-worktrees/scripts/worktree-switch.sh +0 -70
@@ -1,217 +0,0 @@
1
- #!/bin/bash
2
- # [INPUT]: 依赖 .current-req 和 journal-*.md
3
- # [OUTPUT]: 显示上下文恢复信息
4
- # [POS]: scripts 的 workspace 启动脚本,被 /flow-workspace start 调用
5
- # [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
-
7
- set -e
8
-
9
- # ============================================================================
10
- # Configuration
11
- # ============================================================================
12
-
13
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
15
- WORKSPACE_DIR="$PROJECT_ROOT/devflow/workspace"
16
- COMMON_SH="$SCRIPT_DIR/common.sh"
17
-
18
- if [[ -f "$COMMON_SH" ]]; then
19
- source "$COMMON_SH"
20
- fi
21
-
22
- # ============================================================================
23
- # Parse Arguments
24
- # ============================================================================
25
-
26
- usage() {
27
- cat << 'EOF'
28
- Usage: flow-workspace-start.sh [REQ_ID|DEVELOPER] [OPTIONS]
29
-
30
- Start a workspace session and recover context.
31
-
32
- Arguments:
33
- REQ_ID Optional requirement ID to activate (REQ-XXX / BUG-XXX)
34
- DEVELOPER Optional developer name (legacy positional style)
35
-
36
- Options:
37
- --developer NAME Explicit developer name
38
- --req REQ_ID Activate a specific requirement before recovery
39
- --switch Show switch recommendation to the target worktree
40
- --cd Try to execute cd (effective only when script is sourced)
41
- --help, -h Show help
42
-
43
- Examples:
44
- flow-workspace-start.sh
45
- flow-workspace-start.sh REQ-123 --switch
46
- source flow-workspace-start.sh REQ-123 --switch --cd
47
- EOF
48
- }
49
-
50
- DEVELOPER="${DEVFLOW_DEVELOPER:-$(whoami)}"
51
- REQ_OVERRIDE=""
52
- SHOW_SWITCH=false
53
- DO_CD=false
54
- POSITIONAL=()
55
-
56
- while [[ $# -gt 0 ]]; do
57
- case "$1" in
58
- --developer)
59
- DEVELOPER="$2"
60
- shift 2
61
- ;;
62
- --req)
63
- REQ_OVERRIDE="$2"
64
- shift 2
65
- ;;
66
- --switch)
67
- SHOW_SWITCH=true
68
- shift
69
- ;;
70
- --cd)
71
- DO_CD=true
72
- shift
73
- ;;
74
- --help|-h)
75
- usage
76
- exit 0
77
- ;;
78
- -*)
79
- echo "ERROR: Unknown option '$1'. Use --help for usage." >&2
80
- exit 1
81
- ;;
82
- *)
83
- POSITIONAL+=("$1")
84
- shift
85
- ;;
86
- esac
87
- done
88
-
89
- # Backward compatible positional parsing:
90
- # - if token looks like REQ/BUG -> requirement override
91
- # - else treat as developer
92
- for token in "${POSITIONAL[@]}"; do
93
- if [[ "$token" =~ ^(REQ|BUG)-[0-9]+(-[0-9]+)?$ ]]; then
94
- REQ_OVERRIDE=$(echo "$token" | tr '[:lower:]' '[:upper:]')
95
- else
96
- DEVELOPER="$token"
97
- fi
98
- done
99
-
100
- DEV_WORKSPACE="$WORKSPACE_DIR/$DEVELOPER"
101
-
102
- if [[ ! -d "$DEV_WORKSPACE" ]]; then
103
- echo "Workspace not found for $DEVELOPER"
104
- echo "Run '/flow-workspace init $DEVELOPER' first."
105
- exit 1
106
- fi
107
-
108
- # ============================================================================
109
- # Main Logic
110
- # ============================================================================
111
-
112
- echo "🔄 Session Recovery for $DEVELOPER"
113
- echo "=================================="
114
- echo ""
115
-
116
- if [[ -n "$REQ_OVERRIDE" ]]; then
117
- if declare -f validate_req_id >/dev/null 2>&1; then
118
- validate_req_id "$REQ_OVERRIDE" || exit 1
119
- fi
120
- echo "$REQ_OVERRIDE" > "$DEV_WORKSPACE/.current-req"
121
- echo "📌 Requirement override: $REQ_OVERRIDE"
122
- fi
123
-
124
- # Read current requirement
125
- if [[ -f "$DEV_WORKSPACE/.current-req" ]]; then
126
- CURRENT_REQ=$(cat "$DEV_WORKSPACE/.current-req")
127
- echo "📋 Current Requirement: $CURRENT_REQ"
128
-
129
- # Resolve requirement/bug directory by ID prefix
130
- if [[ "$CURRENT_REQ" =~ ^BUG- ]]; then
131
- REQ_DIR="$PROJECT_ROOT/devflow/bugs/$CURRENT_REQ"
132
- STATUS_BASENAME="status.json"
133
- else
134
- REQ_DIR="$PROJECT_ROOT/devflow/requirements/$CURRENT_REQ"
135
- STATUS_BASENAME="orchestration_status.json"
136
- fi
137
-
138
- if [[ -d "$REQ_DIR" ]]; then
139
- # Read orchestration status
140
- STATUS_FILE="$REQ_DIR/$STATUS_BASENAME"
141
- if [[ -f "$STATUS_FILE" ]]; then
142
- STATUS=$(jq -r '.status' "$STATUS_FILE" 2>/dev/null || echo "unknown")
143
- echo " Status: $STATUS"
144
- fi
145
-
146
- # Check TASKS.md for progress
147
- TASKS_FILE="$REQ_DIR/TASKS.md"
148
- if [[ -f "$TASKS_FILE" ]]; then
149
- TOTAL=$(grep -c '^\- \[' "$TASKS_FILE" 2>/dev/null || echo "0")
150
- DONE=$(grep -c '^\- \[x\]' "$TASKS_FILE" 2>/dev/null || echo "0")
151
- echo " Tasks: $DONE/$TOTAL completed"
152
- fi
153
-
154
- # Show expected worktree path and whether current session matches.
155
- if declare -f get_worktree_dir_for_req >/dev/null 2>&1; then
156
- EXPECTED_WORKTREE=$(get_worktree_dir_for_req "$CURRENT_REQ" 2>/dev/null || echo "")
157
- CURRENT_GIT_ROOT=$(git -C "$PROJECT_ROOT" rev-parse --show-toplevel 2>/dev/null || echo "")
158
-
159
- if [[ -n "$EXPECTED_WORKTREE" ]]; then
160
- echo " Expected Worktree: $EXPECTED_WORKTREE"
161
- if [[ -d "$EXPECTED_WORKTREE" ]]; then
162
- if [[ "$CURRENT_GIT_ROOT" == "$EXPECTED_WORKTREE" ]]; then
163
- echo " Worktree Match: yes"
164
- else
165
- echo " Worktree Match: no"
166
- echo " Action: cd $EXPECTED_WORKTREE"
167
- fi
168
- else
169
- echo " Worktree Match: missing"
170
- fi
171
-
172
- if $SHOW_SWITCH; then
173
- if [[ -d "$EXPECTED_WORKTREE" ]]; then
174
- if $DO_CD; then
175
- if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
176
- cd "$EXPECTED_WORKTREE"
177
- echo " Auto Switched: yes ($PWD)"
178
- else
179
- echo " Auto Switched: no (requires sourced execution)"
180
- echo " Run: source .claude/scripts/flow-workspace-start.sh $CURRENT_REQ --switch --cd"
181
- fi
182
- else
183
- echo " Switch Command: cd \"$EXPECTED_WORKTREE\""
184
- fi
185
- fi
186
- fi
187
- fi
188
- fi
189
- else
190
- echo " ⚠️ Requirement directory not found"
191
- fi
192
- else
193
- echo "📋 Current Requirement: None"
194
- fi
195
-
196
- echo ""
197
-
198
- # Read latest journal entries
199
- LATEST_JOURNAL=$(ls -1 "$DEV_WORKSPACE"/journal-*.md 2>/dev/null | sort -V | tail -1)
200
-
201
- if [[ -n "$LATEST_JOURNAL" && -f "$LATEST_JOURNAL" ]]; then
202
- echo "📓 Latest Journal: $(basename "$LATEST_JOURNAL")"
203
- echo ""
204
- echo "Recent entries:"
205
- echo "---------------"
206
-
207
- # Show last 20 lines of journal (excluding frontmatter)
208
- tail -30 "$LATEST_JOURNAL" | head -20
209
-
210
- echo ""
211
- echo "---------------"
212
- fi
213
-
214
- echo ""
215
- echo "Ready to continue. Use:"
216
- echo " /flow-workspace record \"message\" - Record progress"
217
- echo " /flow-workspace switch REQ-XXX|BUG-XXX - Switch requirement"
@@ -1,234 +0,0 @@
1
- #!/bin/bash
2
- # [INPUT]: 依赖 common.sh、workspace/.current-req、journal-*.md
3
- # [OUTPUT]: 更新当前开发者的 REQ 指针,并输出/执行 worktree 切换动作
4
- # [POS]: scripts 的 workspace 切换脚本,被 /flow-workspace switch 与 start --switch 调用
5
- # [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
-
7
- set -e
8
-
9
- # ============================================================================
10
- # Configuration
11
- # ============================================================================
12
-
13
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
15
- WORKSPACE_DIR="$PROJECT_ROOT/devflow/workspace"
16
- COMMON_SH="$SCRIPT_DIR/common.sh"
17
-
18
- if [[ -f "$COMMON_SH" ]]; then
19
- source "$COMMON_SH"
20
- fi
21
-
22
- # ============================================================================
23
- # Usage
24
- # ============================================================================
25
-
26
- usage() {
27
- cat << 'EOF'
28
- Usage: flow-workspace-switch.sh REQ_ID [OPTIONS]
29
-
30
- Switch workspace context to a target requirement.
31
-
32
- Arguments:
33
- REQ_ID Requirement ID (REQ-XXX or BUG-XXX)
34
-
35
- Options:
36
- --developer NAME Developer name (default: DEVFLOW_DEVELOPER or current user)
37
- --print-cd Print `cd "<worktree>"` for eval-style switching
38
- --cd Try to execute cd (effective only when script is sourced)
39
- --json Output in JSON format
40
- --help, -h Show help
41
-
42
- Examples:
43
- flow-workspace-switch.sh REQ-123
44
- flow-workspace-switch.sh REQ-123 --print-cd
45
- eval "$(flow-workspace-switch.sh REQ-123 --print-cd)"
46
- source flow-workspace-switch.sh REQ-123 --cd
47
- EOF
48
- }
49
-
50
- # ============================================================================
51
- # Parse Arguments
52
- # ============================================================================
53
-
54
- REQ_ID=""
55
- DEVELOPER="${DEVFLOW_DEVELOPER:-$(whoami)}"
56
- PRINT_CD=false
57
- DO_CD=false
58
- JSON_MODE=false
59
-
60
- while [[ $# -gt 0 ]]; do
61
- case "$1" in
62
- --developer)
63
- DEVELOPER="$2"
64
- shift 2
65
- ;;
66
- --print-cd)
67
- PRINT_CD=true
68
- shift
69
- ;;
70
- --cd)
71
- DO_CD=true
72
- shift
73
- ;;
74
- --json)
75
- JSON_MODE=true
76
- shift
77
- ;;
78
- --help|-h)
79
- usage
80
- exit 0
81
- ;;
82
- -*)
83
- echo "ERROR: Unknown option '$1'. Use --help for usage." >&2
84
- exit 1
85
- ;;
86
- *)
87
- if [[ -z "$REQ_ID" ]]; then
88
- REQ_ID="$1"
89
- else
90
- echo "ERROR: Too many arguments. Use --help for usage." >&2
91
- exit 1
92
- fi
93
- shift
94
- ;;
95
- esac
96
- done
97
-
98
- if [[ -z "$REQ_ID" ]]; then
99
- echo "ERROR: REQ_ID is required. Use --help for usage." >&2
100
- exit 1
101
- fi
102
-
103
- # Normalize and validate REQ_ID
104
- REQ_ID=$(echo "$REQ_ID" | tr '[:lower:]' '[:upper:]')
105
- if declare -f validate_req_id >/dev/null 2>&1; then
106
- validate_req_id "$REQ_ID" || exit 1
107
- fi
108
-
109
- # ============================================================================
110
- # Resolve Workspace
111
- # ============================================================================
112
-
113
- DEV_WORKSPACE="$WORKSPACE_DIR/$DEVELOPER"
114
- if [[ ! -d "$DEV_WORKSPACE" ]]; then
115
- echo "ERROR: Workspace not found for '$DEVELOPER': $DEV_WORKSPACE" >&2
116
- echo "Run '/flow-workspace init $DEVELOPER' first." >&2
117
- exit 1
118
- fi
119
-
120
- # Update current requirement pointer
121
- echo "$REQ_ID" > "$DEV_WORKSPACE/.current-req"
122
-
123
- # Append a lightweight journal entry
124
- LATEST_JOURNAL=$(ls -1 "$DEV_WORKSPACE"/journal-*.md 2>/dev/null | sort -V | tail -1)
125
- if [[ -z "$LATEST_JOURNAL" ]]; then
126
- LATEST_JOURNAL="$DEV_WORKSPACE/journal-1.md"
127
- cat > "$LATEST_JOURNAL" << EOF
128
- ---
129
- developer: "$DEVELOPER"
130
- journal_number: 1
131
- created_at: "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
132
- ---
133
-
134
- # Developer Journal: $DEVELOPER
135
-
136
- > **[PROTOCOL]**: 变更时更新此头部,然后检查 CLAUDE.md
137
-
138
- ---
139
- EOF
140
- fi
141
-
142
- TIMESTAMP=$(date +"%Y-%m-%d %H:%M")
143
- cat >> "$LATEST_JOURNAL" << EOF
144
- ## [$TIMESTAMP] Requirement Switch
145
-
146
- **REQ**: $REQ_ID
147
-
148
- Switched workspace pointer to \`$REQ_ID\`.
149
-
150
- ---
151
- EOF
152
-
153
- # Resolve worktree path
154
- WORKTREE_DIR=""
155
- WORKTREE_EXISTS=false
156
- if declare -f get_worktree_dir_for_req >/dev/null 2>&1; then
157
- WORKTREE_DIR=$(get_worktree_dir_for_req "$REQ_ID" 2>/dev/null || echo "")
158
- fi
159
- if [[ -n "$WORKTREE_DIR" && -d "$WORKTREE_DIR" ]]; then
160
- WORKTREE_EXISTS=true
161
- fi
162
-
163
- # Source detection: cd can only affect caller shell when sourced
164
- IS_SOURCED=false
165
- if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
166
- IS_SOURCED=true
167
- fi
168
-
169
- CD_EXECUTED=false
170
- if $DO_CD; then
171
- if ! $WORKTREE_EXISTS; then
172
- echo "ERROR: Worktree not found for $REQ_ID: $WORKTREE_DIR" >&2
173
- exit 1
174
- fi
175
-
176
- if $IS_SOURCED; then
177
- cd "$WORKTREE_DIR"
178
- CD_EXECUTED=true
179
- fi
180
- fi
181
-
182
- # ============================================================================
183
- # Output
184
- # ============================================================================
185
-
186
- if $JSON_MODE; then
187
- printf '{"developer":"%s","req_id":"%s","workspace":"%s","worktree_dir":"%s","worktree_exists":%s,"cd_executed":%s}\n' \
188
- "$DEVELOPER" \
189
- "$REQ_ID" \
190
- "$DEV_WORKSPACE" \
191
- "$WORKTREE_DIR" \
192
- "$WORKTREE_EXISTS" \
193
- "$CD_EXECUTED"
194
- return 0 2>/dev/null || exit 0
195
- fi
196
-
197
- if $PRINT_CD; then
198
- if $WORKTREE_EXISTS; then
199
- printf 'cd "%s"\n' "$WORKTREE_DIR"
200
- return 0 2>/dev/null || exit 0
201
- fi
202
- echo "ERROR: Worktree not found for $REQ_ID: $WORKTREE_DIR" >&2
203
- exit 1
204
- fi
205
-
206
- echo "✅ Workspace switched"
207
- echo "Developer: $DEVELOPER"
208
- echo "Current REQ: $REQ_ID"
209
- echo "Workspace: $DEV_WORKSPACE"
210
- if [[ -n "$WORKTREE_DIR" ]]; then
211
- echo "Expected Worktree: $WORKTREE_DIR"
212
- fi
213
- echo "Worktree Exists: $WORKTREE_EXISTS"
214
-
215
- if $DO_CD; then
216
- if $CD_EXECUTED; then
217
- echo "Directory switched to: $PWD"
218
- else
219
- echo ""
220
- echo "⚠️ --cd 未生效(脚本以子进程运行,无法修改父 Shell 目录)"
221
- echo "Use one of:"
222
- echo " source .claude/scripts/flow-workspace-switch.sh $REQ_ID --cd"
223
- echo " eval \"\$(.claude/scripts/flow-workspace-switch.sh $REQ_ID --print-cd)\""
224
- fi
225
- elif $WORKTREE_EXISTS; then
226
- echo ""
227
- echo "Next:"
228
- echo " cd \"$WORKTREE_DIR\""
229
- else
230
- echo ""
231
- echo "Worktree is missing. Create it with flow-init (default mode) or worktree-create script."
232
- fi
233
-
234
- return 0 2>/dev/null || exit 0
@@ -1,252 +0,0 @@
1
- ---
2
- name: using-git-worktrees
3
- description: 'Git Worktree management for parallel development. Enables multiple Claude Code sessions working on different requirements simultaneously.'
4
- ---
5
-
6
- # Using Git Worktrees Skill
7
-
8
- > [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
9
-
10
- ## Purpose
11
-
12
- 支持多需求并行开发,每个 worktree 独立的 Claude 会话,互不干扰。
13
-
14
- ## When to Use
15
-
16
- - 多需求并行开发
17
- - 代码审查时需要隔离环境
18
- - 紧急修复时不丢失当前工作
19
- - 需要在不同分支间快速切换
20
-
21
- ## Core Concepts
22
-
23
- ### Worktree vs Branch
24
-
25
- | 传统分支 | Git Worktree |
26
- |---------|--------------|
27
- | `git checkout` 切换 | `cd` 切换目录 |
28
- | 需要 stash 当前工作 | 工作区完全隔离 |
29
- | 单一 Claude 会话 | 每个 worktree 独立会话 |
30
- | 切换耗时 ~30s | 切换耗时 ~1s |
31
-
32
- ### Directory Layout
33
-
34
- ```
35
- ~/projects/
36
- ├── cc-devflow/ # 主仓库 (main 分支)
37
- ├── cc-devflow-REQ-001/ # REQ-001 worktree
38
- ├── cc-devflow-REQ-002/ # REQ-002 worktree
39
- ├── cc-devflow-analysis/ # 只读分析 worktree (可选)
40
- └── cc-devflow-hotfix/ # 紧急修复 worktree (可选)
41
- ```
42
-
43
- ### Naming Convention
44
-
45
- ```
46
- Worktree 目录: {repo-name}-{REQ_ID}
47
- 对应分支: feature/{REQ_ID}-{slug}
48
- ```
49
-
50
- ## Commands
51
-
52
- ### Create Worktree
53
-
54
- ```bash
55
- # 创建新 worktree + 分支
56
- bash scripts/worktree-create.sh "REQ-123" "Feature Title"
57
-
58
- # 仅创建 worktree (分支已存在)
59
- bash scripts/worktree-create.sh "REQ-123" --existing-branch
60
- ```
61
-
62
- ### List Worktrees
63
-
64
- ```bash
65
- # 列出所有 worktree
66
- bash scripts/worktree-list.sh
67
-
68
- # JSON 格式输出
69
- bash scripts/worktree-list.sh --json
70
- ```
71
-
72
- ### Switch Worktree
73
-
74
- ```bash
75
- # 切换到指定 worktree
76
- bash scripts/worktree-switch.sh "REQ-123"
77
-
78
- # 或直接 cd
79
- cd ../cc-devflow-REQ-123
80
- ```
81
-
82
- ### Cleanup Worktree
83
-
84
- ```bash
85
- # 清理单个 worktree
86
- bash scripts/worktree-cleanup.sh "REQ-123"
87
-
88
- # 清理所有已合并的 worktree
89
- bash scripts/worktree-cleanup.sh --merged
90
- ```
91
-
92
- ### Status Check
93
-
94
- ```bash
95
- # 检查当前 worktree 状态
96
- bash scripts/worktree-status.sh
97
- ```
98
-
99
- ## Shell Aliases (Recommended)
100
-
101
- 将以下内容添加到 `~/.zshrc` 或 `~/.bashrc`:
102
-
103
- ```bash
104
- # 快速导航
105
- alias za='cd $(git rev-parse --show-toplevel 2>/dev/null || echo .)' # 当前 worktree 根目录
106
- alias zl='git worktree list' # 列出所有 worktree
107
- alias zm='cd ~/projects/cc-devflow' # 主仓库
108
-
109
- # 快速切换函数
110
- zw() {
111
- local req_id="${1:-}"
112
- if [[ -z "$req_id" ]]; then
113
- echo "Usage: zw REQ-123"
114
- return 1
115
- fi
116
- local repo_name=$(basename $(git -C ~/projects/cc-devflow rev-parse --show-toplevel 2>/dev/null))
117
- local target_dir=~/projects/${repo_name}-${req_id}
118
- if [[ -d "$target_dir" ]]; then
119
- cd "$target_dir"
120
- else
121
- echo "Worktree not found: $target_dir"
122
- return 1
123
- fi
124
- }
125
- ```
126
-
127
- ## Integration with CC-DevFlow
128
-
129
- ### flow-init
130
-
131
- 默认使用 worktree 模式:
132
-
133
- ```bash
134
- /flow-init "REQ-123|Feature Title"
135
- # 创建: ../cc-devflow-REQ-123/
136
- # 分支: feature/REQ-123-feature-title
137
- ```
138
-
139
- 兼容模式 (传统分支):
140
-
141
- ```bash
142
- /flow-init "REQ-123|Feature Title" --branch-only
143
- ```
144
-
145
- ### flow-release
146
-
147
- 自动清理 worktree:
148
-
149
- ```bash
150
- /flow-release "REQ-123"
151
- # 1. 合并分支
152
- # 2. 删除 worktree
153
- # 3. 删除分支
154
- ```
155
-
156
- ### flow-restart
157
-
158
- 切换到已有 worktree:
159
-
160
- ```bash
161
- /flow-restart "REQ-123"
162
- # cd ../cc-devflow-REQ-123
163
- ```
164
-
165
- ## Session Management
166
-
167
- 每个 worktree 可以运行独立的 Claude Code 会话:
168
-
169
- ```bash
170
- # 终端 1: REQ-001
171
- cd ~/projects/cc-devflow-REQ-001
172
- claude
173
-
174
- # 终端 2: REQ-002
175
- cd ~/projects/cc-devflow-REQ-002
176
- claude
177
-
178
- # 终端 3: 主仓库 (代码审查)
179
- cd ~/projects/cc-devflow
180
- claude
181
- ```
182
-
183
- ## Best Practices
184
-
185
- ### 1. 保持主仓库干净
186
-
187
- 主仓库 (`cc-devflow/`) 应始终在 `main` 分支,用于:
188
- - 创建新 worktree
189
- - 代码审查
190
- - 合并操作
191
-
192
- ### 2. 定期清理
193
-
194
- ```bash
195
- # 清理已合并的 worktree
196
- bash scripts/worktree-cleanup.sh --merged
197
- ```
198
-
199
- ### 3. 命名一致性
200
-
201
- - Worktree 目录: `{repo}-{REQ_ID}`
202
- - 分支名: `feature/{REQ_ID}-{slug}`
203
-
204
- ### 4. 紧急修复流程
205
-
206
- ```bash
207
- # 1. 在主仓库创建 hotfix worktree
208
- cd ~/projects/cc-devflow
209
- git worktree add ../cc-devflow-hotfix -b hotfix/critical-fix
210
-
211
- # 2. 修复并合并
212
- cd ../cc-devflow-hotfix
213
- # ... 修复代码 ...
214
- git push origin hotfix/critical-fix
215
-
216
- # 3. 清理
217
- cd ~/projects/cc-devflow
218
- git worktree remove ../cc-devflow-hotfix
219
- git branch -d hotfix/critical-fix
220
- ```
221
-
222
- ## Error Handling
223
-
224
- | 错误 | 解决方案 |
225
- |------|----------|
226
- | Worktree 目录已存在 | 使用 `--force` 或手动删除 |
227
- | 分支已被其他 worktree 使用 | 先删除旧 worktree |
228
- | 主仓库不在 main 分支 | `git checkout main` |
229
- | 磁盘空间不足 | 清理已合并的 worktree |
230
-
231
- ## Scripts Reference
232
-
233
- | Script | Purpose |
234
- |--------|---------|
235
- | `scripts/worktree-create.sh` | 创建 worktree |
236
- | `scripts/worktree-list.sh` | 列出 worktree |
237
- | `scripts/worktree-switch.sh` | 切换 worktree |
238
- | `scripts/worktree-cleanup.sh` | 清理 worktree |
239
- | `scripts/worktree-status.sh` | 状态检查 |
240
-
241
- ## Assets Reference
242
-
243
- | Asset | Purpose |
244
- |-------|---------|
245
- | `assets/SHELL_ALIASES.md` | Shell 别名模板 |
246
-
247
- ---
248
-
249
- **Related Skills**:
250
- - `flow-init` - 需求初始化 (worktree 创建)
251
- - `flow-release` - 发布管理 (worktree 清理)
252
- - `finishing-branch` - 分支完成决策