cc-workspace 4.7.1 → 5.2.1

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 (35) hide show
  1. package/CHANGELOG.md +291 -0
  2. package/README.md +123 -41
  3. package/bin/cli.js +313 -134
  4. package/global-skills/agents/e2e-validator.md +151 -32
  5. package/global-skills/agents/implementer.md +77 -71
  6. package/global-skills/agents/reviewer.md +192 -0
  7. package/global-skills/agents/security-auditor.md +345 -0
  8. package/global-skills/agents/team-lead.md +93 -101
  9. package/global-skills/agents/workspace-init.md +16 -5
  10. package/global-skills/bootstrap-repo/SKILL.md +1 -0
  11. package/global-skills/cleanup/SKILL.md +35 -25
  12. package/global-skills/cross-service-check/SKILL.md +1 -0
  13. package/global-skills/cycle-retrospective/SKILL.md +6 -4
  14. package/global-skills/dispatch-feature/SKILL.md +225 -173
  15. package/global-skills/dispatch-feature/references/anti-patterns.md +52 -35
  16. package/global-skills/dispatch-feature/references/spawn-templates.md +140 -97
  17. package/global-skills/doctor/SKILL.md +124 -25
  18. package/global-skills/e2e-validator/references/container-strategies.md +55 -23
  19. package/global-skills/hooks/orphan-cleanup.sh +60 -0
  20. package/global-skills/hooks/permission-auto-approve.sh +61 -4
  21. package/global-skills/hooks/session-start-context.sh +10 -47
  22. package/global-skills/hooks/test_hooks.sh +242 -0
  23. package/global-skills/hooks/user-prompt-guard.sh +6 -6
  24. package/global-skills/hooks/validate-spawn-prompt.sh +40 -30
  25. package/global-skills/incident-debug/SKILL.md +1 -0
  26. package/global-skills/merge-prep/SKILL.md +1 -0
  27. package/global-skills/metrics/SKILL.md +139 -0
  28. package/global-skills/plan-review/SKILL.md +2 -1
  29. package/global-skills/qa-ruthless/SKILL.md +2 -0
  30. package/global-skills/refresh-profiles/SKILL.md +1 -0
  31. package/global-skills/rules/context-hygiene.md +4 -19
  32. package/global-skills/rules/model-routing.md +31 -18
  33. package/global-skills/session/SKILL.md +41 -20
  34. package/global-skills/templates/workspace.template.md +1 -1
  35. package/package.json +4 -3
@@ -1,9 +1,10 @@
1
1
  ---
2
2
  name: cleanup
3
+ prompt_version: 5.2.1
3
4
  description: >
4
5
  Clean orphan worktrees, stale sessions, and temporary files left by
5
- crashed implementers. Safe to run anytime — only removes /tmp/ worktrees
6
- and closed/stale sessions.
6
+ crashed implementers. Session-aware: never removes worktrees belonging
7
+ to active sessions. Safe to run anytime.
7
8
  Use: /cleanup
8
9
  argument-hint: ""
9
10
  context: fork
@@ -12,35 +13,48 @@ allowed-tools: Bash, Read, Glob, Grep
12
13
 
13
14
  # Cleanup — Orphan Worktree & Session Cleaner
14
15
 
15
- ## Step 1: Find orphan worktrees in /tmp/
16
+ ## CRITICAL: Session-aware worktree cleanup
17
+
18
+ **NEVER remove worktrees that belong to active sessions.**
19
+ Active session worktrees persist until `session close` — this is by design.
20
+ Only remove worktrees that have NO corresponding active session JSON entry.
21
+
22
+ ## Step 1: Identify session worktrees (do NOT touch these)
23
+
24
+ ```bash
25
+ # List all worktree paths referenced by active sessions
26
+ find ./.sessions -name "*.json" -exec jq -r 'select(.status=="active") | .repos[].worktree_path' {} \; 2>/dev/null
27
+ ```
28
+
29
+ Note these paths. Skip them in all subsequent cleanup steps.
30
+
31
+ ## Step 2: Find truly orphaned worktrees in /tmp/
16
32
 
17
33
  ```bash
18
- # List all potential orchestrator worktrees
19
34
  ls -d /tmp/*-session-* /tmp/e2e-* 2>/dev/null || echo "No worktrees found in /tmp/"
20
35
  ```
21
36
 
22
- For each found worktree:
37
+ For each found worktree that is NOT in the active session list:
23
38
  1. Check if it's still registered with a repo:
24
39
  ```bash
25
- # Find the parent repo by checking all sibling repos
26
40
  for repo in ../*/; do
27
41
  [ -d "$repo/.git" ] || continue
28
42
  git -C "$repo" worktree list 2>/dev/null | grep "/tmp/worktree-path"
29
43
  done
30
44
  ```
31
- 2. If registered but the directory is invalid → prune:
45
+ 2. If registered but invalid → prune:
32
46
  ```bash
33
- git -C ../[repo] worktree prune
47
+ git -C ../{repo} worktree prune
34
48
  ```
35
49
  3. If not registered → safe to remove:
36
50
  ```bash
37
- rm -rf /tmp/[worktree-path]
51
+ rm -rf /tmp/{worktree-path}
38
52
  ```
39
53
 
40
54
  Present what was found and ask the user before deleting:
41
- > "Found N orphan worktrees. Remove them? [y/N]"
55
+ > "Found N orphan worktrees (not linked to any active session). Remove them? [y/N]"
42
56
 
43
- ## Step 2: Find stale sessions
57
+ ## Step 3: Find stale sessions
44
58
 
45
59
  Read `.sessions/*.json`. A session is stale if:
46
60
  - Status is "closed"
@@ -48,29 +62,24 @@ Read `.sessions/*.json`. A session is stale if:
48
62
 
49
63
  For stale sessions, show:
50
64
  ```
51
- | Session | Status | Created | Repos | Action |
52
- |---------|--------|---------|-------|--------|
53
- | feature-old | closed | 2026-01-15 | api, front | Delete JSON? |
54
- | feature-stuck | active | 2026-01-20 | api | Stale (37 days) |
65
+ | Session | Status | Created | Repos | Worktrees | Action |
66
+ |---------|--------|---------|-------|-----------|--------|
67
+ | feature-old | closed | 2026-01-15 | api, front | /tmp/api-feature-old (missing) | Delete JSON? |
68
+ | feature-stuck | active | 2026-01-20 | api | /tmp/api-feature-stuck (exists!) | Stale (37d) |
55
69
  ```
56
70
 
57
- Ask before each deletion.
58
-
59
- For active stale sessions, also check if session branches exist:
60
- ```bash
61
- git -C ../[repo] branch --list session/[name] 2>/dev/null
62
- ```
71
+ For stale ACTIVE sessions with existing worktrees: warn strongly before suggesting removal.
72
+ These might be legitimate long-running sessions.
63
73
 
64
- ## Step 3: Clean modified-files.log
74
+ ## Step 4: Clean modified-files.log
65
75
 
66
76
  ```bash
67
- # Truncate if larger than 1000 lines
68
77
  wc -l .claude/modified-files.log 2>/dev/null
69
78
  ```
70
79
 
71
80
  If >1000 lines, ask to truncate to last 200 lines.
72
81
 
73
- ## Step 4: Docker cleanup (optional)
82
+ ## Step 5: Docker cleanup (optional)
74
83
 
75
84
  Check for dangling E2E containers:
76
85
  ```bash
@@ -87,7 +96,8 @@ docker compose -f ./e2e/docker-compose.e2e.yml down -v 2>/dev/null
87
96
  Summary of actions taken:
88
97
  ```
89
98
  Cleanup complete:
90
- - Removed N orphan worktrees
99
+ - Active session worktrees preserved: N (not touched)
100
+ - Removed N orphan worktrees (no active session)
91
101
  - Deleted N stale session files
92
102
  - Pruned modified-files.log (was X lines → 200)
93
103
  - Removed N dangling containers
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  name: cross-service-check
3
+ prompt_version: 5.2.1
3
4
  description: >
4
5
  Validate technical consistency BETWEEN services. Does not review code
5
6
  quality (that's qa-ruthless). Checks: API contracts match frontend types,
@@ -1,10 +1,12 @@
1
1
  ---
2
2
  name: cycle-retrospective
3
+ prompt_version: 5.2.1
3
4
  description: >
4
- Post-cycle learning and knowledge capture. Analyzes QA findings, teammate
5
- reports, and implementation patterns to improve repo CLAUDE.md files,
6
- service profiles, and project constitution. Run after a successful cycle
7
- (dispatch QA merge). Use when user says "retro", "rétrospective",
5
+ MANDATORY post-cycle learning and knowledge capture. Always runs as Phase 5
6
+ of dispatch-feature after qa-ruthless and merge-prep. Analyzes QA findings, teammate
7
+ session logs, and implementation patterns to improve repo CLAUDE.md files,
8
+ service profiles, and project constitution.
9
+ Also triggered manually when user says "retro", "rétrospective",
8
10
  "capitalize", "lessons learned", "what did we learn", "improve docs".
9
11
  argument-hint: "[feature-name]"
10
12
  context: fork
@@ -1,20 +1,24 @@
1
1
  ---
2
2
  name: dispatch-feature
3
+ prompt_version: 5.2.1
3
4
  description: >
4
- Orchestrate multi-service feature implementation. Clarifies ambiguities
5
- before planning, writes a persistent markdown plan, spawns teammates
6
- in dependency waves with full context including constitution and UX standards.
5
+ Orchestrate multi-service feature implementation. Clarifies ambiguities,
6
+ explores repos directly (no upfront Haiku scan), writes a persistent
7
+ markdown plan, sets up git branches and worktrees after plan validation,
8
+ spawns one teammate per repo with full context, runs micro-QA between
9
+ each commit, then runs cross-service-check, qa-ruthless, reviewer,
10
+ security-auditor (when needed), merge-prep, and cycle-retrospective.
7
11
  Use whenever the user describes a feature, says "implement", "new feature",
8
12
  "dispatch", "start dev", "launch teammates", or provides a spec.
9
13
  argument-hint: "[feature description]"
10
14
  context: fork
11
- allowed-tools: Read, Write, Glob, Grep, Task, Teammate, SendMessage
15
+ allowed-tools: Read, Write, Bash, Glob, Grep, Task, Teammate, SendMessage
12
16
  ---
13
17
 
14
- # Dispatch Feature — Clarify, Plan, Delegate, Track
18
+ # Dispatch Feature — Clarify, Plan, Git, Delegate, Track
15
19
 
16
- You produce ZERO code in repos. You clarify, plan, delegate, track.
17
- You CAN write in orchestrator/ (plans, workspace.md, constitution.md).
20
+ You produce ZERO code in repos. You clarify, plan, manage git, delegate, track.
21
+ You CAN write in orchestrator/ and run git/bash commands directly.
18
22
 
19
23
  ## Mode detection
20
24
 
@@ -22,13 +26,36 @@ Before any phase, check which mode was selected:
22
26
 
23
27
  | Mode | Behavior |
24
28
  |------|----------|
25
- | **A — Complet** | Run all phases 0-5 (default) |
26
- | **B — Plan rapide** | Skip Phase 0 (Clarify). Start at Phase 2 with specs as-is. |
29
+ | **A — Full** | All phases 0-5 (default) |
30
+ | **B — Quick plan** | Skip Phase 0 (Clarify). Start at Phase 1 exploration with specs as-is. |
27
31
  | **C — Go direct** | Skip Phases 0-2. Dispatch immediately from user specs. |
28
32
  | **D — Single-service** | Phases 0-2, then spawn ONE teammate. No waves. |
29
33
 
30
34
  If no mode specified, use Mode A.
31
35
 
36
+ ### Mode B — Quick plan details
37
+
38
+ User provides clear specs upfront (e.g. a Jira ticket, a detailed description).
39
+ 1. Skip Phase 0 entirely — do NOT ask clarification questions
40
+ 2. Run Phase 1 (targeted exploration) scoped to the user's specs
41
+ 3. Run Phase 2 (plan) — write the plan from specs + exploration
42
+ 4. Phases 2.5–5 proceed normally (git setup, dispatch, micro-QA, post-impl)
43
+ 5. If ambiguities emerge during exploration, ask then (max 3 focused questions)
44
+
45
+ ### Mode C — Go direct details
46
+
47
+ For hotfixes, quick patches, or when the user provides exact instructions.
48
+ 1. Skip Phases 0–2 — no clarification, no exploration, no written plan
49
+ 2. Run Phase 2.5 (git setup) — still create session branch + worktree
50
+ 3. Spawn ONE teammate per impacted repo with the user's specs as-is
51
+ 4. Micro-QA still runs after each commit (Phase 4 is NOT skipped)
52
+ 5. Post-impl: skip cross-service-check, run qa-ruthless (scoped), merge-prep, retro
53
+ 6. Write a minimal plan retroactively after dispatch for traceability
54
+
55
+ ### Mode D — Single-service details
56
+
57
+ See dedicated section below (## Mode D: Single-service).
58
+
32
59
  ## Phase 0: Clarify
33
60
 
34
61
  Run through this checklist SILENTLY. Only ask for items you cannot deduce:
@@ -42,42 +69,59 @@ Run through this checklist SILENTLY. Only ask for items you cannot deduce:
42
69
  **Should-know** (ask if ambiguous):
43
70
  - Error handling? Permissions? Trigger mechanism? Dependencies?
44
71
 
72
+ **Source branch override** — detect in the user's prompt:
73
+ - "fix on hotfix/payment" → source = hotfix/payment
74
+ - "refacto from develop" → source = develop
75
+ - (no mention) → use source_branch from workspace.md per repo
76
+
45
77
  **Rules**: max 5 questions at once, formulated as concrete choices.
46
78
  Skip clarify if: bug with log provided, or user says "go"/"autonome".
47
79
 
48
- ## Phase 1: Load context
80
+ **Example good vs bad clarification questions:**
49
81
 
50
- 1. Read `./workspace.md`
51
- 2. Read `./plans/service-profiles.md`
52
- 3. Read `./constitution.md` (project-specific rules)
53
- 4. Auto-discover repos: scan `../` for directories with `.git/` not in workspace.md
54
- → If new repos found: mention them, ask if relevant to this feature
82
+ Bad (vague, open-ended):
83
+ > "How should the feature handle errors?"
84
+ > "What permissions do you want?"
55
85
 
56
- > The constitution is defined in your workspace's constitution.md.
57
- > Teammates do NOT receive it automatically. You MUST include all rules
58
- > from constitution.md in every spawn prompt.
86
+ Good (concrete choices, actionable):
87
+ > "When invoice PDF generation fails: (a) retry then notify user, (b) queue for manual retry, or (c) fail silently with error log?"
88
+ > "Access control for this endpoint: (a) any authenticated user, (b) company admin only, or (c) role-based with a new permission?"
59
89
 
60
- ## Phase 2: Write the plan
90
+ ## Phase 1: Targeted exploration (Opus direct — no Haiku upfront)
61
91
 
62
- Create `./plans/{feature-name}.md` using `./plans/_TEMPLATE.md`.
63
- Include: context, clarification answers, services impacted, dependency waves,
64
- detailed tasks per service, API contract (exact shapes), and autonomous choices if applicable.
92
+ Read directly using available tools. Do NOT spawn a Haiku explorer at this phase.
65
93
 
66
- ### Commit planning (mandatory each commit unit = one implementer spawn)
94
+ **Constraint**: only read files directly related to the feature.
67
95
 
68
- **CRITICAL**: Each commit unit in the plan becomes a separate `Task(implementer)` spawn.
69
- The team-lead dispatches them sequentially per service. Size them accordingly:
70
- - **Too granular** (10+ per service) = excessive spawns, slow, expensive
71
- - **Too coarse** (1 giant unit) = defeats atomic commit purpose
72
- - **Sweet spot**: 2-5 units per service, ~100-300 lines each
96
+ ```bash
97
+ # Step 1: orientation
98
+ cat ./workspace.md
99
+ cat ./plans/service-profiles.md
100
+ cat ./constitution.md
73
101
 
74
- Typical split for a standard feature:
75
- - **Commit 1**: Data layer — models, migrations, DTOs, repositories
76
- - **Commit 2**: Business logic — use cases, services, validation
77
- - **Commit 3**: API/UI layer controllers, routes, components, pages
78
- - **Commit 4**: Tests for the above
102
+ # Step 2: read CLAUDE.md of potentially impacted repos
103
+ cat ../{repo}/CLAUDE.md
104
+
105
+ # Step 3: targeted grep/glob on the feature scope only
106
+ grep -r "EntityName\|routeName" ../{repo}/src/ --include="*.php" -l
107
+ find ../{repo}/src -name "*.ts" | xargs grep "InterfaceName" -l 2>/dev/null
108
+ ```
109
+
110
+ Auto-discover repos: scan ../ for directories with .git/ not in workspace.md.
111
+ If new repos found: mention them, ask if relevant to this feature.
112
+
113
+ Do NOT scan entire repos. Do NOT read files unrelated to the feature scope.
79
114
 
80
- For a small fix: **1 single commit unit** (no unnecessary splitting).
115
+ ## Phase 2: Write the plan
116
+
117
+ Create ./plans/{feature-name}.md using ./plans/_TEMPLATE.md.
118
+
119
+ Include: context, clarification answers, effective source branch per repo, dependency waves,
120
+ commit units per repo, API contract (exact shapes), progress tracker.
121
+
122
+ ### Commit unit sizing (CRITICAL — each unit = one teammate commit)
123
+
124
+ The teammate handles ALL commits sequentially. Size them for clarity, not spawning overhead:
81
125
 
82
126
  | Service complexity | Recommended commit units |
83
127
  |--------------------|--------------------------|
@@ -86,177 +130,185 @@ For a small fix: **1 single commit unit** (no unnecessary splitting).
86
130
  | Standard feature | 3-5 |
87
131
  | Complex feature | 4-6 (max) |
88
132
 
89
- Each commit unit in the plan must:
90
- - Have a descriptive title (becomes the commit message)
91
- - List the specific tasks it covers
92
- - Estimate ~N files, ~N lines
93
- - Be independently compilable and testable
94
- - Be **self-contained enough for a fresh implementer** — an implementer that only sees
95
- the previous commits and this unit's description must be able to deliver it
133
+ Sweet spot: 100-300 lines per unit. Each unit must be self-contained and independently compilable.
96
134
 
97
- The plan also includes a **progress tracker** table summarizing commits planned
98
- vs done per service, visible at a glance.
135
+ Typical split for a standard feature:
136
+ - **Commit 1**: Data layer models, migrations, DTOs
137
+ - **Commit 2**: Business logic — services, use cases, validation
138
+ - **Commit 3**: API/UI layer — controllers, routes, components, pages
139
+ - **Commit 4**: Tests
99
140
 
100
141
  ### Dependency waves
101
142
 
102
- - **Wave 1**: Producers — API backend, data/analytics, auth (define contracts)
143
+ - **Wave 1**: Producers — API backend, data, auth (define contracts)
103
144
  - **Wave 2**: Consumers — Frontend, integrations (depend on wave 1 contracts)
104
145
  - **Wave 3**: Infra/config — Gateway routes, deployment (after code exists)
105
146
 
106
- Independent services go in the same wave. Save. **Present plan, wait for approval.**
107
-
108
- ## Phase 2.5: Session setup (branch isolation)
109
-
110
- After plan approval and before dispatch:
111
-
112
- 1. Derive session name from feature name (slug: lowercase, hyphens, no spaces)
113
- 2. Read `./workspace.md` — extract the `Source Branch` column for each service
114
- 3. Identify repos impacted by the plan
115
- 4. Write `./.sessions/{session-name}.json`:
116
- ```json
117
- {
118
- "name": "{session-name}",
119
- "created": "{date}",
120
- "status": "active",
121
- "repos": {
122
- "{service}": {
123
- "path": "../{service}",
124
- "source_branch": "{from workspace.md}",
125
- "session_branch": "session/{session-name}",
126
- "branch_created": false
127
- }
128
- }
129
- }
130
- ```
131
- 5. Spawn a **Task subagent with Bash** to create branches in each impacted repo:
132
- ```
133
- git -C ../[repo] branch session/{name} {source_branch}
134
- ```
135
- - Use `git branch` — NOT `git checkout -b` (checkout disrupts other sessions)
136
- - If the branch already exists, verify it points to the right source and skip
137
- - The Task subagent reports success/failure per repo
138
- 6. Update the session JSON: set `branch_created: true` for each successful branch
139
-
140
- > **Why a Task subagent?** The team-lead has `disallowedTools: Bash`.
141
- > Branch creation requires shell access, so it must be delegated.
142
-
143
- ## Phase 3: Dispatch — one implementer per commit unit
144
-
145
- **CRITICAL**: You do NOT spawn one teammate per service. You spawn one
146
- `Task(implementer)` per **commit unit** in the plan. Each implementer handles
147
- exactly one commit, then dies. This guarantees every commit is made.
148
-
149
- ### Dispatch flow per service (sequential)
147
+ Save plan. **Present plan, wait for approval.**
148
+ Loop on Phases 1-2 if user requests changes.
150
149
 
151
- ```
152
- For each service in the current wave:
153
- For each commit unit (in order):
154
- 1. Spawn Task(implementer) with:
155
- - This commit unit's tasks ONLY
156
- - Constitution rules
157
- - API contract (if relevant)
158
- - Repo path + session branch
159
- - Context: "Commits 1..N-1 are already on the branch"
160
- 2. Wait for implementer to return
161
- 3. Verify commit on session branch (Task subagent with Bash)
162
- 4. Update plan: mark commit unit ✅ or ❌
163
- 5. If ❌: re-dispatch (max 2 retries), then escalate
164
- 6. If ✅: proceed to next commit unit
165
- ```
150
+ ## Phase 2.5: Git setup (after plan validation ONLY)
166
151
 
167
- **Cross-service parallelism**: Different services within the same wave can
168
- progress in parallel. Use parallel Task calls when possible.
152
+ Opus runs git directly via Bash. No subagents for git setup.
169
153
 
170
- ### Implementer spawn prompt — context tiering
154
+ For each impacted repo:
155
+ 1. `git -C ../{repo} branch session/{name} {source_branch}` — **git branch**, never checkout -b
156
+ 2. `git worktree add /tmp/{repo}-{session-name} session/{name}` — persists until session close
157
+ 3. Verify worktree appears in `git worktree list`
171
158
 
172
- The implementer agent already knows its git workflow, commit protocol, and cleanup
173
- procedure. Do NOT repeat these in spawn prompts. Only provide specific values and context.
159
+ Write `.sessions/{name}.json` with session metadata (name, created, status, per-repo: path, worktree_path, source_branch, session_branch, commits map).
174
160
 
175
- **Always include (Tier 1):**
176
- 1. Which commit unit: "Commit N of M for service X"
177
- 2. Tasks for this commit only (NOT the whole plan)
178
- 3. Constitution rules from constitution.md (translated to English)
179
- 4. Repo path + session branch: `session/{name}`
180
- 5. Previous context: "Commits 1..N-1 are on the branch. Do NOT redo."
161
+ PR target at session close = effective source branch.
181
162
 
182
- **Conditional (Tier 2):**
183
- - **Frontend commits with UI**: UX standards (from `references/frontend-ux-standards.md`)
184
- - **API commits**: API contract shapes (exact request/response)
185
- - **Frontend commits**: API contract as TypeScript interfaces
186
163
 
187
- **Never inject (Tier 3 already in repo CLAUDE.md or agent instructions):**
188
- - Anti-patterns list (implementer reads CLAUDE.md)
189
- - Git workflow procedure (implementer agent already knows)
190
- - Full workspace context (implementer doesn't need it)
164
+ ## Phase 2.9: Pre-dispatch check (before spawning any teammate)
165
+
166
+ Verify via Bash for each repo. Abort and fix before proceeding:
167
+
168
+ | Check | Fix if failed |
169
+ |-------|---------------|
170
+ | Session branch exists | `git -C ../{repo} branch session/{name} {source_branch}` |
171
+ | Worktree exists at /tmp/ path | `git worktree add /tmp/{repo}-{session-name} session/{name}` |
172
+ | Worktree on correct branch | Inspect — may need worktree remove + re-add |
173
+ | Worktree is clean (no uncommitted leftovers) | Inspect, commit useful changes or `git checkout -- .` |
174
+ | Repo is reachable | Escalate to user |
175
+
176
+ Only proceed to Phase 3 once all checks pass.
177
+
178
+ ## Phase 3: Dispatch — one teammate per repo
191
179
 
192
- See @references/spawn-templates.md for templates per service type.
180
+ **ONE teammate per repo.** Each teammate receives the complete repo plan and handles
181
+ all its commit units sequentially. It signals after each commit and waits for green light.
193
182
 
194
- > **Constitution in spawn prompts**: Implementers do NOT receive the constitution
195
- > automatically. You MUST include ALL rules from constitution.md in every spawn prompt.
183
+ This is fundamentally different from the old model (one subagent per commit unit).
184
+ The teammate has the full picture of its repo and can escalate intelligently at any point.
196
185
 
197
- ### Isolation
186
+ ### Teammate spawn prompt — context tiering
198
187
 
199
- Each `Task(implementer)` creates its own worktree in `/tmp/`. The worktree is
200
- removed after the commit. The next implementer creates a fresh worktree and sees
201
- all previous commits on the session branch.
188
+ See @references/spawn-templates.md for full templates.
202
189
 
203
- Never run two implementers on the same repo simultaneously — sequential only.
204
- Cross-service parallelism is fine.
190
+ **Always inject (Tier 1):**
191
+ 1. `worktree_path`: /tmp/{repo}-{session-name}/ ready, no git setup needed
192
+ 2. `session_branch`: session/{name}
193
+ 3. Complete repo plan (all commit units in order)
194
+ 4. Constitution rules (all from constitution.md, translated to English)
195
+ 5. SignalInstruction: "After each commit, SendMessage: 'commit N done — {hash} — {files} — tests: {pass/fail}'. Then WAIT for my green light."
196
+ 6. ScopeInstruction: "For each commit, read only files in scope for that commit unit."
197
+
198
+ **Conditional (Tier 2):**
199
+ - Frontend repo with UI → inject full frontend-ux-standards.md
200
+ - API commits → inject API contract (exact request/response shapes)
201
+ - Frontend commits → inject API contract as TypeScript interfaces
202
+
203
+ **Never inject (Tier 3 — already in CLAUDE.md or agent):**
204
+ - Git workflow (teammate has no git responsibility)
205
+ - Generic anti-patterns
206
+ - Full workspace context
207
+
208
+ > The constitution is in constitution.md. Teammates do NOT receive it automatically.
209
+ > Include ALL rules in every spawn prompt, translated to English.
210
+
211
+ ### Parallelism
212
+
213
+ - Different repos in same wave → spawn teammates in parallel ✅
214
+ - Same repo → ONE teammate handles everything sequentially ❌
205
215
 
206
216
  ### Wave execution
207
217
 
208
- 1. For each service in wave 1: dispatch commit units sequentially (parallel across services)
209
- 2. Wait for ALL services in wave 1 to complete ALL their commit units
210
- 3. Collect wave 1 results, update the API contract if needed
211
- 4. Dispatch wave 2 commit units with validated contracts from wave 1
212
- 5. Repeat for wave 3 if applicable
213
-
214
- ## Phase 4: Collect and update
215
-
216
- After EACH implementer returns:
217
- 1. **Verify the commit** — spawn a Task subagent (Bash):
218
- `git -C ../[repo] log session/{name} --oneline -3`
219
- → The new commit must appear. If not: re-dispatch this commit unit.
220
- 2. Update `./plans/{feature-name}.md` — mark this commit unit ✅ or ❌
221
- 3. Update the **progress tracker** table (commits done / planned)
222
- 4. Note dead code found
223
- 5. **Flag giant commits** — if >400 lines, note in session log
224
- 6. **Session log** entry: `[HH:MM] impl-[service]-commit-[N]: [status], [hash], [N] files, tests [pass/fail]`
225
- 7. If ❌ → analyze failure, correct the commit unit description, re-dispatch (max 2 retries)
226
- 8. If all commit units for a service are → service complete
227
- 9. If all services in current wave are complete → launch next wave
228
-
229
- ## Phase 5: Post-implementation
230
-
231
- 1. Run `cross-service-check`
232
- 2. Run `qa-ruthless`
233
- 3. Update plan with all results
234
- 4. Present final status to user
218
+ 1. Spawn all wave 1 repo teammates (parallel)
219
+ 2. Wait for ALL wave 1 teammates to complete ALL commits (all micro-QA validated)
220
+ 3. Collect validated API contracts from wave 1 results
221
+ 4. Spawn wave 2 teammates with validated contracts
222
+ 5. Repeat for wave 3
223
+
224
+ ## Phase 4: Micro-QA between commits
225
+
226
+ After each teammate SendMessage "commit N done — {hash}":
227
+
228
+ ### Step 1 Bash verification (Opus direct)
229
+
230
+ ```bash
231
+ # 1. Verify commit exists on session branch
232
+ git -C /tmp/{repo}-{session-name} log session/{name} --oneline -3
233
+
234
+ # 2. Run scoped tests adapt command to repo stack:
235
+ # PHP/Laravel:
236
+ cd /tmp/{repo}-{session-name} && php artisan test --filter={CommitScope} 2>&1 | tail -30
237
+ # Vue/Node:
238
+ cd /tmp/{repo}-{session-name} && npm run typecheck 2>&1 | tail -20
239
+ # Go:
240
+ cd /tmp/{repo}-{session-name} && go test ./... 2>&1 | tail -20
241
+ # Python:
242
+ cd /tmp/{repo}-{session-name} && pytest {scope_path} -v 2>&1 | tail -30
243
+
244
+ # 3. Check for debug artifacts
245
+ git -C /tmp/{repo}-{session-name} diff HEAD~1 HEAD \
246
+ | grep -E "(console\.log|dd\(|var_dump|\.only\(|TODO|FIXME|debugger|dump\()" \
247
+ | head -20
248
+ ```
249
+
250
+ ### Step 2 — Haiku diff review (Task subagent, read-only)
251
+
252
+ Use the Haiku micro-QA template from @references/spawn-templates.md (section "Haiku micro-QA subagent template").
253
+
254
+ Spawn Task(Explore, model: haiku) with that template, injecting the diff output from Step 1.
255
+
256
+ **Do NOT rephrase or shorten the template** — copy it verbatim from the reference file.
257
+ Haiku needs the exact structured prompt to return clean JSON.
258
+
259
+ ### Decision
260
+
261
+ | Bash | Haiku | Action |
262
+ |------|-------|--------|
263
+ | OK | OK | SendMessage to teammate: "green light, proceed to commit N+1" |
264
+ | FAIL | any | Opus analyzes failure, sends fix instruction to teammate OR escalates |
265
+ | OK | BLOCKER | Opus evaluates blocker severity, sends fix instruction or escalates |
266
+
267
+ Retry limit: max 2 per commit unit → escalate to user, stop the wave.
268
+
269
+ ### Update after each commit
270
+
271
+ ```bash
272
+ # Update plan progress tracker
273
+ # Mark commit N ✅ or ❌
274
+
275
+ # Update session.json commits tracking
276
+ # Add session log entry:
277
+ # [HH:MM] {repo}-commit-{N}: {status}, {hash}, {N} files, tests {pass/fail}
278
+ ```
279
+
280
+ ## Phase 5: Post-implementation (all mandatory)
281
+
282
+ 1. **cross-service-check** — inter-repo consistency (API shapes, env vars, gateway routes)
283
+ 2. **qa-ruthless** — adversarial QA, min 3 findings per service
284
+ 3. **reviewer** — evidence-based code review (scope check + architecture + constitution compliance). Run via `claude --agent reviewer` or inline.
285
+ 4. **security-auditor** (conditional) — run via `claude --agent security-auditor` when the plan involves: auth changes, new tenant-scoped models, file uploads, payment/sensitive data, new public endpoints, or dependency additions. Skip for pure UI or config-only changes.
286
+ 5. **merge-prep** — PR summaries, merge order, conflict detection, target = source branch
287
+ 6. **cycle-retrospective** — MANDATORY, not optional
288
+ - Analyzes QA findings + review comments + session log
289
+ - Suggests CLAUDE.md updates per repo
290
+ - Suggests constitution additions if gaps found
291
+ - Asks confirmation before applying any changes
235
292
 
236
293
  ## Mode D: Single-service
237
294
 
238
295
  For targeted fixes or single-repo work:
239
296
  1. Identify the ONE service to touch
240
- 2. Skip waves — dispatch commit units sequentially (often just 1)
297
+ 2. Skip waves — spawn ONE teammate (often 1-2 commit units)
241
298
  3. No cross-service-check (unless user requests it)
242
299
  4. QA scoped to that service only
243
300
  5. Merge prep for that service only
244
301
 
245
- For simple fixes with 1 commit unit: one Task(implementer) — no overhead.
246
-
247
- > **Context note**: This skill runs with `context: fork`. After it completes,
248
- > its internal context is discarded. The plan file on disk is the source of truth.
249
- > QA and cross-service-check will reload the plan from disk.
250
-
251
- ## Session recovery
302
+ ## Session recovery (after crash)
252
303
 
253
- If resuming after crash:
254
- 1. Read `./workspace.md` for project context
255
- 2. List `./plans/` for active plans
256
- 3. Read active plan — statuses and session log tell you where you are
257
- 4. Resume at last incomplete step
258
- 5. If no mode was selected before crash, default to Mode A
304
+ 1. Read ./workspace.md for project context
305
+ 2. List ./plans/ for active plans
306
+ 3. Check ./.sessions/ for active session JSON — worktrees should still exist in /tmp/
307
+ 4. Read active plan — statuses and session log tell you where you are
308
+ 5. Verify worktrees still exist: git worktree list for each repo
309
+ 6. Re-spawn missing teammates from their last incomplete commit unit
310
+ 7. Resume micro-QA loop
259
311
 
260
312
  ## Anti-patterns
261
313
 
262
- See @references/anti-patterns.md for the full list of anti-patterns and common mistakes.
314
+ See @references/anti-patterns.md for the full list.