specweave 1.0.418 → 1.0.419

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 (53) hide show
  1. package/dist/src/cli/commands/init.d.ts +4 -11
  2. package/dist/src/cli/commands/init.d.ts.map +1 -1
  3. package/dist/src/cli/commands/init.js +126 -732
  4. package/dist/src/cli/commands/init.js.map +1 -1
  5. package/dist/src/cli/commands/resolve-structure.d.ts +4 -2
  6. package/dist/src/cli/commands/resolve-structure.d.ts.map +1 -1
  7. package/dist/src/cli/commands/resolve-structure.js +4 -2
  8. package/dist/src/cli/commands/resolve-structure.js.map +1 -1
  9. package/dist/src/cli/helpers/init/ado-repo-cloning.d.ts.map +1 -1
  10. package/dist/src/cli/helpers/init/ado-repo-cloning.js +14 -12
  11. package/dist/src/cli/helpers/init/ado-repo-cloning.js.map +1 -1
  12. package/dist/src/cli/helpers/init/bitbucket-repo-cloning.d.ts.map +1 -1
  13. package/dist/src/cli/helpers/init/bitbucket-repo-cloning.js +14 -12
  14. package/dist/src/cli/helpers/init/bitbucket-repo-cloning.js.map +1 -1
  15. package/dist/src/cli/helpers/init/directory-structure.d.ts +2 -2
  16. package/dist/src/cli/helpers/init/directory-structure.d.ts.map +1 -1
  17. package/dist/src/cli/helpers/init/directory-structure.js +5 -23
  18. package/dist/src/cli/helpers/init/directory-structure.js.map +1 -1
  19. package/dist/src/cli/helpers/init/github-repo-cloning.d.ts.map +1 -1
  20. package/dist/src/cli/helpers/init/github-repo-cloning.js +14 -12
  21. package/dist/src/cli/helpers/init/github-repo-cloning.js.map +1 -1
  22. package/dist/src/cli/helpers/init/index.d.ts +5 -7
  23. package/dist/src/cli/helpers/init/index.d.ts.map +1 -1
  24. package/dist/src/cli/helpers/init/index.js +6 -17
  25. package/dist/src/cli/helpers/init/index.js.map +1 -1
  26. package/dist/src/cli/helpers/init/next-steps.d.ts +6 -6
  27. package/dist/src/cli/helpers/init/next-steps.d.ts.map +1 -1
  28. package/dist/src/cli/helpers/init/next-steps.js +49 -52
  29. package/dist/src/cli/helpers/init/next-steps.js.map +1 -1
  30. package/dist/src/cli/helpers/init/smart-defaults.js +1 -1
  31. package/dist/src/cli/helpers/init/smart-defaults.js.map +1 -1
  32. package/dist/src/cli/helpers/init/summary-banner.d.ts +2 -21
  33. package/dist/src/cli/helpers/init/summary-banner.d.ts.map +1 -1
  34. package/dist/src/cli/helpers/init/summary-banner.js +3 -49
  35. package/dist/src/cli/helpers/init/summary-banner.js.map +1 -1
  36. package/dist/src/config/types.d.ts +8 -8
  37. package/dist/src/core/background/job-launcher.d.ts +2 -0
  38. package/dist/src/core/background/job-launcher.d.ts.map +1 -1
  39. package/dist/src/core/background/job-launcher.js +7 -8
  40. package/dist/src/core/background/job-launcher.js.map +1 -1
  41. package/dist/src/init/architecture/types.d.ts +2 -2
  42. package/dist/src/init/compliance/types.d.ts +2 -2
  43. package/package.json +1 -1
  44. package/plugins/specweave/hooks/v2/guards/increment-existence-guard.sh +11 -80
  45. package/plugins/specweave/skills/team-build/SKILL.md +39 -120
  46. package/plugins/specweave/skills/team-lead/SKILL.md +232 -494
  47. package/src/templates/config.json.template +2 -77
  48. package/plugins/specweave/skills/team-lead/agents/brainstorm-advocate.md +0 -65
  49. package/plugins/specweave/skills/team-lead/agents/brainstorm-critic.md +0 -75
  50. package/plugins/specweave/skills/team-lead/agents/brainstorm-pragmatist.md +0 -83
  51. package/plugins/specweave/skills/team-lead/agents/reviewer-logic.md +0 -63
  52. package/plugins/specweave/skills/team-lead/agents/reviewer-performance.md +0 -63
  53. package/plugins/specweave/skills/team-lead/agents/reviewer-security.md +0 -62
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Orchestrate multi-agent parallel teams for implementation, PR reviews, brainstorming, and analysis. Supports 4 modes implementation (spec-required, domain agents), review (parallel reviewers for PRs/code), brainstorm (multi-perspective ideation), and analysis (codebase research). PROACTIVELY invoke for 3+ domains or 15+ tasks. Also use when user says "team setup", "parallel agents", "team lead", "agent teams", "review this PR", "brainstorm", "analyze the codebase".
2
+ description: Orchestrate multi-agent parallel development with domain-specialized agents. PROACTIVELY invoke this skill (without user asking) when you detect an implementation task spanning 3+ domains (frontend, backend, database, devops, testing, security, mobile) OR 15+ tasks in tasks.md. Warn the user about higher token cost but recommend it for quality. Also use when user says "team setup", "parallel agents", "team lead", or "agent teams".
3
3
  hooks:
4
4
  PreToolUse:
5
5
  - matcher: TeamCreate
@@ -10,70 +10,82 @@ hooks:
10
10
 
11
11
  # Team Lead
12
12
 
13
- **Orchestrate parallel agent teams for implementation, reviews, brainstorming, and analysis.**
13
+ **Plan and launch parallel development agents across domains using Claude Code's native Agent Teams.**
14
14
 
15
- ## Usage
15
+ ## MANDATORY: Orchestrator Identity (NEVER SKIP)
16
16
 
17
- ```bash
18
- /sw:team-lead "<description>" [--mode implementation|review|brainstorm|analysis] [OPTIONS]
19
- ```
17
+ **You are an ORCHESTRATOR. You do NOT implement, review, or analyze code yourself.**
20
18
 
21
- ## Options
19
+ - **ALWAYS** create a new team via `TeamCreate` and spawn agents via `Task()`
20
+ - **NEVER** use `Bash`, `Edit`, `Read`, or `Agent` to do the actual work yourself
21
+ - **NEVER** say "I'll do this directly" — that defeats the purpose of team-lead
22
+ - Even if you just finished a previous team-lead session in this conversation, you MUST create a **new** team and spawn **new** agents
23
+ - Even if the work seems "simple enough to do directly" — spawn agents anyway
24
+ - Your only tools are: `TeamCreate`, `Task`, `SendMessage`, `Read` (for agent templates), and `Bash` (only for team state inspection)
22
25
 
23
- | Option | Description | Default |
24
- |--------|-------------|---------|
25
- | `--mode` | Team mode: `implementation`, `review`, `brainstorm`, `analysis` | auto-detect |
26
- | `--dry-run` | Show proposed agent plan without launching | false |
27
- | `--domains` | Override domain detection (implementation mode) | auto-detect |
28
- | `--max-agents` | Maximum number of concurrent agents | 6 |
26
+ **The test**: If you're about to call `Edit()` or write code, STOP — you're violating this rule.
29
27
 
30
28
  ---
31
29
 
32
- ## 0. Mode Detection (FIRST STEP)
30
+ ## -1. Pre-Flight Cleanup (ALWAYS FIRST)
33
31
 
34
- **Before anything else, determine which mode this team operates in.** The mode dictates the entire workflow different modes have fundamentally different agent structures, naming conventions, and requirements.
32
+ **Before mode detection or any other step**, clean up stale teams from previous runs in this session.
35
33
 
36
- ### Auto-Detection Rules
34
+ ### Why This Matters
37
35
 
38
- | Signal | Mode | Examples |
39
- |--------|------|---------|
40
- | Explicit `--mode` flag | As specified | `--mode review` |
41
- | PR/review keywords | **review** | "review PR #63", "code review", "audit the auth module", "review this pull request" |
42
- | Brainstorm keywords | **brainstorm** | "brainstorm approaches", "explore ideas", "pros and cons", "ideate on", "what are our options" |
43
- | Analysis keywords | **analysis** | "analyze the codebase", "research how X works", "explore the architecture", "investigate performance" |
44
- | Implementation signals | **implementation** | "build X", "implement Y", "add feature Z", 3+ domains detected, 15+ tasks in tasks.md |
36
+ Teams persist at `~/.claude/teams/` and `~/.claude/tasks/` after completion. If not cleaned up, they pollute the session and may prevent `TeamCreate` from working.
45
37
 
46
- ### Keyword Priority
38
+ ### Cleanup Steps
47
39
 
48
- If multiple signals conflict, explicit `--mode` flag wins. Otherwise: review > brainstorm > analysis > implementation.
40
+ ```bash
41
+ # 1. List existing teams
42
+ ls ~/.claude/teams/ 2>/dev/null
43
+
44
+ # 2. List existing task directories
45
+ ls ~/.claude/tasks/ 2>/dev/null
46
+ ```
49
47
 
50
- ### Team Naming Convention (CRITICAL for Guard)
48
+ **If stale teams exist from a previous run in this session:**
51
49
 
52
- The PreToolUse guard uses team_name prefix to determine mode. **You MUST use these prefixes:**
50
+ 1. Call `TeamDelete()` for each stale team that is no longer active
51
+ 2. If `TeamDelete` fails (agents still active), send `shutdown_request` to all agents first:
52
+ ```typescript
53
+ SendMessage({ type: "shutdown_request", recipient: "<agent-name>" });
54
+ ```
55
+ 3. Then retry `TeamDelete()`
53
56
 
54
- | Mode | team_name pattern | Example |
55
- |------|------------------|---------|
56
- | Implementation | `impl-*` or any non-prefixed name | `impl-checkout`, `feature-auth` |
57
- | Review | `review-*` | `review-pr-63`, `review-auth-module` |
58
- | Brainstorm | `brainstorm-*` | `brainstorm-architecture`, `brainstorm-pricing` |
59
- | Analysis | `analysis-*` | `analysis-performance`, `analysis-codebase` |
57
+ **If no stale teams or all cleaned up:** Proceed to Mode Detection (Section 0).
60
58
 
61
- **WHY**: The guard only enforces spec-first for implementation teams. Using the correct prefix lets review/brainstorm/analysis teams proceed without an increment.
59
+ **CRITICAL**: Use a **unique team name** for each invocation to avoid collisions. Append a timestamp or sequence number:
60
+ - `review-pr-1533-1`, `review-pr-1533-2`
61
+ - `impl-feature-{timestamp}`
62
62
 
63
63
  ---
64
64
 
65
- ## Mode 1: Implementation (Spec-Required)
65
+ ## Usage
66
+
67
+ ```bash
68
+ /sw:team-lead "<feature description>" [OPTIONS]
69
+ ```
70
+
71
+ ## Options
66
72
 
67
- **When to use**: Building features, fixing bugs, any work that produces code changes requiring spec-driven coordination.
73
+ | Option | Description | Default |
74
+ |--------|-------------|---------|
75
+ | `--dry-run` | Show proposed agent plan without launching | false |
76
+ | `--domains` | Override domain detection (e.g., `--domains frontend,backend,testing`) | auto-detect |
77
+ | `--max-agents` | Maximum number of concurrent agents | 6 |
68
78
 
69
- **Requires**: An existing increment with substantive spec.md (enforced by guard).
79
+ ---
70
80
 
71
- ### 0a. Increment Pre-Flight (BLOCKING)
81
+ ## 0. Increment Pre-Flight (BLOCKING)
72
82
 
73
- **CRITICAL: Implementation mode REQUIRES an existing increment with a substantive spec.md.**
83
+ **CRITICAL: /sw:team-lead REQUIRES an existing increment with a substantive spec.md.**
74
84
  A PreToolUse guard on TeamCreate will BLOCK team creation if no increment exists.
75
85
 
76
- **You MUST verify an increment exists BEFORE proceeding.**
86
+ **You MUST verify an increment exists BEFORE proceeding to Step 1.**
87
+
88
+ ### Check for Existing Increment
77
89
 
78
90
  ```bash
79
91
  # Single-repo
@@ -83,7 +95,7 @@ find .specweave/increments -maxdepth 2 -name "spec.md" 2>/dev/null | head -5
83
95
  find repositories -path "*/.specweave/increments/*/spec.md" -maxdepth 6 2>/dev/null | head -5
84
96
  ```
85
97
 
86
- #### If NO increment exists → Auto-invoke /sw:increment
98
+ ### If NO increment exists → Auto-invoke /sw:increment
87
99
 
88
100
  Do NOT ask permission. Invoke the increment skill with the user's feature description:
89
101
 
@@ -92,280 +104,42 @@ Skill({ skill: "sw:increment", args: "the user's feature description" })
92
104
  ```
93
105
 
94
106
  Wait for /sw:increment to complete (spec.md, plan.md, tasks.md created and approved).
95
- Then continue. If /sw:increment fails: **STOP. Do NOT proceed.**
107
+ Then continue to Step 1.
96
108
 
97
- #### If increment exists Read the master spec
109
+ If /sw:increment fails (user rejects plan, skill errors, etc.): **STOP. Do NOT proceed.**
110
+ Report the failure to the user and ask them to run `/sw:increment` manually.
111
+
112
+ ### If increment exists → Read the master spec
98
113
 
99
114
  Read the increment's spec.md. This is the **source of truth** for all agent work:
100
115
  - Scope and boundaries
101
116
  - User stories and acceptance criteria
102
117
  - Task breakdown and dependencies
103
118
 
104
- Store the increment path as `MASTER_INCREMENT_PATH`.
119
+ Store the increment path as `MASTER_INCREMENT_PATH` — you will reference it in agent prompts.
120
+
121
+ **WHY THIS MATTERS**: Without a spec, agents infer scope from natural language alone.
122
+ This leads to uncoordinated implementation, scope creep, and missing acceptance criteria.
123
+ The spec-first principle exists because specs are the contract between user intent and agent execution.
105
124
 
106
- #### Activate the Master Increment (MANDATORY)
125
+ ### Activate the Master Increment (MANDATORY)
107
126
 
108
- **Before spawning ANY agents**, transition the master increment to `"active"` status.
127
+ **Before spawning ANY agents**, transition the master increment to `"active"` status. The `specweave complete` command silently exits on increments with `"planned"` or `"backlog"` status — if you skip this step, closure will fail.
109
128
 
110
129
  ```bash
130
+ # Read current status
111
131
  STATUS=$(jq -r '.status' [MASTER_INCREMENT_PATH]/metadata.json)
132
+
133
+ # If not already active, activate it
112
134
  if [ "$STATUS" != "active" ] && [ "$STATUS" != "ready_for_review" ]; then
113
- Edit metadata.json: "status": "planned" "status": "active"
135
+ # Edit metadata.json: set status to "active" and update lastActivity
136
+ Edit metadata.json:
137
+ "status": "planned" → "status": "active"
138
+ "lastActivity": "<current ISO timestamp>"
114
139
  fi
115
140
  ```
116
141
 
117
- ### Implementation Workflow
118
-
119
- Follow Sections 1-11 below (the full implementation protocol).
120
-
121
- ---
122
-
123
- ## Mode 2: Review (No Increment Required)
124
-
125
- **When to use**: PR reviews, code audits, architecture reviews, security audits, pre-release quality checks.
126
-
127
- **Does NOT require**: An increment or spec.md. Reviews examine existing code.
128
-
129
- ### Review Workflow
130
-
131
- #### Step 1: Determine Review Scope
132
-
133
- Identify what's being reviewed:
134
- - **PR review**: Extract PR number, fetch diff with `gh pr diff <number>`
135
- - **Code audit**: Identify target files/modules
136
- - **Architecture review**: Identify system boundaries and components
137
-
138
- #### Step 2: Create Review Team
139
-
140
- ```typescript
141
- TeamCreate({
142
- team_name: "review-pr-63", // MUST use review-* prefix
143
- description: "Review PR #63 for security, logic, and performance"
144
- });
145
- ```
146
-
147
- #### Step 3: Spawn Review Agents (All Parallel)
148
-
149
- Review agents run in parallel — they examine code independently from different perspectives. **Read the agent definition files** from `agents/` directory, replace placeholders, and spawn.
150
-
151
- | Agent | File | Focus |
152
- |-------|------|-------|
153
- | Security Reviewer | `agents/reviewer-security.md` | Vulnerabilities, injection, auth flaws, secrets exposure, OWASP |
154
- | Logic Reviewer | `agents/reviewer-logic.md` | Correctness, edge cases, error handling, race conditions, logic bugs |
155
- | Performance Reviewer | `agents/reviewer-performance.md` | N+1 queries, memory leaks, unnecessary allocations, algorithmic complexity |
156
-
157
- ```typescript
158
- // Spawn ALL reviewers in parallel — no dependencies between them
159
- Task({
160
- team_name: "review-pr-63",
161
- name: "security-reviewer",
162
- subagent_type: "general-purpose",
163
- mode: "bypassPermissions",
164
- prompt: <content of agents/reviewer-security.md with placeholders replaced>
165
- });
166
-
167
- Task({
168
- team_name: "review-pr-63",
169
- name: "logic-reviewer",
170
- subagent_type: "general-purpose",
171
- mode: "bypassPermissions",
172
- prompt: <content of agents/reviewer-logic.md with placeholders replaced>
173
- });
174
-
175
- Task({
176
- team_name: "review-pr-63",
177
- name: "performance-reviewer",
178
- subagent_type: "general-purpose",
179
- mode: "bypassPermissions",
180
- prompt: <content of agents/reviewer-performance.md with placeholders replaced>
181
- });
182
- ```
183
-
184
- #### Step 4: Collect and Merge Reviews
185
-
186
- Wait for all agents to signal REVIEW_COMPLETE. Each agent produces a structured findings report. The team-lead:
187
-
188
- 1. Collects all REVIEW_COMPLETE messages
189
- 2. Deduplicates overlapping findings
190
- 3. Prioritizes by severity (CRITICAL > HIGH > MEDIUM > LOW)
191
- 4. Produces a unified review summary with:
192
- - **Must Fix** (blocking): Security vulnerabilities, logic bugs, data loss risks
193
- - **Should Fix** (non-blocking): Performance issues, code quality, missing error handling
194
- - **Consider** (optional): Style improvements, documentation gaps, refactoring opportunities
195
-
196
- #### Step 5: Deliver Review
197
-
198
- Present the merged review to the user. If reviewing a PR, optionally post the review as a PR comment via `gh pr review`.
199
-
200
- ### Review Agent Communication Protocol
201
-
202
- | Prefix | Purpose | Sender | Receiver |
203
- |--------|---------|--------|----------|
204
- | `REVIEW_COMPLETE:` | Agent finished reviewing | Review agent | team-lead |
205
- | `REVIEW_QUESTION:` | Agent needs clarification | Review agent | team-lead |
206
-
207
- ---
208
-
209
- ## Mode 3: Brainstorm (No Increment Required)
210
-
211
- **When to use**: Exploring ideas, evaluating approaches, multi-perspective ideation, architecture decision exploration, trade-off analysis.
212
-
213
- **Does NOT require**: An increment or spec.md. Brainstorming is pre-spec exploration.
214
-
215
- ### Brainstorm Workflow
216
-
217
- #### Step 1: Frame the Question
218
-
219
- Extract the core question or decision to brainstorm:
220
- - "How should we architect the payment system?"
221
- - "What approach for real-time notifications?"
222
- - "Should we use microservices or monolith?"
223
-
224
- #### Step 2: Create Brainstorm Team
225
-
226
- ```typescript
227
- TeamCreate({
228
- team_name: "brainstorm-payment-arch", // MUST use brainstorm-* prefix
229
- description: "Brainstorm payment system architecture approaches"
230
- });
231
- ```
232
-
233
- #### Step 3: Spawn Perspective Agents (All Parallel)
234
-
235
- Brainstorm agents represent different thinking perspectives. **Read the agent definition files** from `agents/` directory, replace placeholders, and spawn.
236
-
237
- | Agent | File | Perspective |
238
- |-------|------|------------|
239
- | Advocate | `agents/brainstorm-advocate.md` | Champions the most ambitious/innovative approach. Pushes boundaries. |
240
- | Critic | `agents/brainstorm-critic.md` | Devil's advocate. Finds risks, edge cases, failure modes. Questions assumptions. |
241
- | Pragmatist | `agents/brainstorm-pragmatist.md` | Practical realist. Considers timelines, team skills, maintenance burden. |
242
-
243
- ```typescript
244
- // Spawn ALL perspective agents in parallel
245
- Task({
246
- team_name: "brainstorm-payment-arch",
247
- name: "advocate",
248
- subagent_type: "general-purpose",
249
- mode: "bypassPermissions",
250
- prompt: <content of agents/brainstorm-advocate.md with placeholders replaced>
251
- });
252
-
253
- Task({
254
- team_name: "brainstorm-payment-arch",
255
- name: "critic",
256
- subagent_type: "general-purpose",
257
- mode: "bypassPermissions",
258
- prompt: <content of agents/brainstorm-critic.md with placeholders replaced>
259
- });
260
-
261
- Task({
262
- team_name: "brainstorm-payment-arch",
263
- name: "pragmatist",
264
- subagent_type: "general-purpose",
265
- mode: "bypassPermissions",
266
- prompt: <content of agents/brainstorm-pragmatist.md with placeholders replaced>
267
- });
268
- ```
269
-
270
- #### Step 4: Synthesize Perspectives
271
-
272
- Wait for all agents to signal PERSPECTIVE_COMPLETE. The team-lead:
273
-
274
- 1. Collects all perspectives
275
- 2. Identifies areas of agreement (strong signals)
276
- 3. Maps areas of disagreement (decision points)
277
- 4. Produces a **Decision Matrix**:
278
-
279
- ```
280
- | Approach | Advocate View | Critic Concerns | Pragmatist Assessment | Score |
281
- |----------|--------------|-----------------|----------------------|-------|
282
- | Option A | Pro: X, Y | Risk: Z | Feasible, 2 weeks | 7/10 |
283
- | Option B | Pro: A, B | Risk: C, D | Complex, 4 weeks | 5/10 |
284
- ```
285
-
286
- 5. Recommends a path forward with clear rationale
287
- 6. If the user wants to proceed → suggest `/sw:increment` to formalize the chosen approach
288
-
289
- ### Brainstorm Agent Communication Protocol
290
-
291
- | Prefix | Purpose | Sender | Receiver |
292
- |--------|---------|--------|----------|
293
- | `PERSPECTIVE_COMPLETE:` | Agent finished their analysis | Perspective agent | team-lead |
294
- | `INSIGHT:` | Important finding during analysis | Perspective agent | team-lead |
295
-
296
- ---
297
-
298
- ## Mode 4: Analysis (No Increment Required)
299
-
300
- **When to use**: Codebase research, dependency analysis, architecture mapping, performance profiling, tech debt assessment, migration feasibility studies.
301
-
302
- **Does NOT require**: An increment or spec.md. Analysis is exploratory.
303
-
304
- ### Analysis Workflow
305
-
306
- #### Step 1: Define Analysis Scope
307
-
308
- Identify what needs to be analyzed and what questions need answers:
309
- - "How are API endpoints structured?"
310
- - "What's the dependency graph for the auth module?"
311
- - "Where are the performance bottlenecks?"
312
-
313
- #### Step 2: Create Analysis Team
314
-
315
- ```typescript
316
- TeamCreate({
317
- team_name: "analysis-auth-deps", // MUST use analysis-* prefix
318
- description: "Analyze authentication module dependencies and architecture"
319
- });
320
- ```
321
-
322
- #### Step 3: Spawn Analysis Agents
323
-
324
- Unlike fixed-role review/brainstorm agents, analysis agents are **dynamically composed** based on the analysis scope. Common patterns:
325
-
326
- | Pattern | Agents | Use Case |
327
- |---------|--------|----------|
328
- | **Architecture mapping** | structure-agent, dependency-agent, pattern-agent | Understanding system design |
329
- | **Performance analysis** | profiler-agent, bottleneck-agent, optimization-agent | Finding performance issues |
330
- | **Tech debt assessment** | complexity-agent, coverage-agent, freshness-agent | Evaluating maintenance burden |
331
- | **Migration feasibility** | source-agent, target-agent, risk-agent | Planning technology migrations |
332
-
333
- Agents are spawned with focused prompts tailored to the specific analysis question. There are no fixed agent templates — the team-lead crafts prompts from the analysis scope.
334
-
335
- ```typescript
336
- // Example: Architecture mapping
337
- Task({
338
- team_name: "analysis-auth-deps",
339
- name: "structure-agent",
340
- subagent_type: "general-purpose",
341
- mode: "bypassPermissions",
342
- prompt: "Analyze the directory structure and module organization of the auth system. Map all files in src/auth/, src/middleware/auth*, and related test files. Report: file count, module boundaries, export/import graph, and any circular dependencies. Signal completion with ANALYSIS_COMPLETE: prefix."
343
- });
344
-
345
- Task({
346
- team_name: "analysis-auth-deps",
347
- name: "dependency-agent",
348
- subagent_type: "general-purpose",
349
- mode: "bypassPermissions",
350
- prompt: "Analyze external dependencies used by the auth module. Check package.json for auth-related packages, trace their usage, check for CVEs, and assess upgrade paths. Signal completion with ANALYSIS_COMPLETE: prefix."
351
- });
352
- ```
353
-
354
- #### Step 4: Synthesize Findings
355
-
356
- Wait for all ANALYSIS_COMPLETE signals. Produce a structured analysis report:
357
-
358
- 1. **Findings Summary**: Key discoveries from each agent
359
- 2. **Diagrams**: ASCII architecture diagrams, dependency graphs
360
- 3. **Recommendations**: Prioritized list of actions
361
- 4. **Next Steps**: Suggest `/sw:increment` if actionable improvements are identified
362
-
363
- ### Analysis Agent Communication Protocol
364
-
365
- | Prefix | Purpose | Sender | Receiver |
366
- |--------|---------|--------|----------|
367
- | `ANALYSIS_COMPLETE:` | Agent finished analysis | Analysis agent | team-lead |
368
- | `FINDING:` | Significant discovery during analysis | Analysis agent | team-lead |
142
+ **Why**: Agents implement tasks but don't manage the increment lifecycle. The team-lead owns status transitions — activate before work begins, close after work completes.
369
143
 
370
144
  ---
371
145
 
@@ -380,7 +154,7 @@ Wait for all ANALYSIS_COMPLETE signals. Produce a structured analysis report:
380
154
 
381
155
  ---
382
156
 
383
- ## 2. Domain-to-Skill Mapping (Implementation Mode)
157
+ ## 2. Domain-to-Skill Mapping
384
158
 
385
159
  Analyze the feature request and map affected domains to SpecWeave skills.
386
160
 
@@ -402,7 +176,7 @@ The orchestrator infers domains from the feature description and codebase struct
402
176
 
403
177
  ---
404
178
 
405
- ## 3. Contract-First Spawning Protocol (Implementation Mode)
179
+ ## 3. Contract-First Spawning Protocol
406
180
 
407
181
  Agents are NOT all spawned simultaneously. The orchestrator follows a two-phase dependency protocol to prevent integration conflicts.
408
182
 
@@ -468,6 +242,10 @@ umbrella-project/
468
242
  │ │ └── .specweave/increments/0001-shared-types/
469
243
  │ └── {ORG}/sw-ecom-api/
470
244
  │ └── .specweave/increments/0001-api-endpoints/
245
+
246
+ # WRONG: All agents dumping into umbrella root
247
+ umbrella-project/
248
+ ├── .specweave/increments/0001-everything/ # WRONG!
471
249
  ```
472
250
 
473
251
  **Rules:**
@@ -534,7 +312,7 @@ Analyze domains
534
312
 
535
313
  ---
536
314
 
537
- ## 3b. Plan Review Workflow (Implementation Mode)
315
+ ## 3b. Plan Review Workflow
538
316
 
539
317
  The team lead acts as **architectural reviewer** for all sub-agent plans. Do NOT auto-accept plans.
540
318
 
@@ -548,7 +326,7 @@ Without review, agents may duplicate work across domains, misinterpret scope, ma
548
326
  - Agents run as separate processes that encounter folder trust prompts
549
327
  - Trust prompts require interactive input that agents CANNOT provide
550
328
  - Without `bypassPermissions`, agents get STUCK waiting for trust confirmation and never execute
551
- - This applies to ALL agent spawns — upstream and downstream, ALL MODES
329
+ - This applies to ALL agent spawns — upstream and downstream
552
330
 
553
331
  **NEVER use `mode: "plan"` for agent spawns** — it causes agents to block on the trust-folder prompt.
554
332
 
@@ -603,6 +381,10 @@ SendMessage({
603
381
 
604
382
  Plan review MUST NOT block other agents. Review plans as they arrive — agents waiting for approval are idle, but other agents continue working normally.
605
383
 
384
+ ### Multi-Increment Consideration
385
+
386
+ For very large features, the team lead MAY split work into multiple increments per domain for better tracking and independent closure. Decide this during initial analysis (Step 1), before spawning agents.
387
+
606
388
  ### Task Cap Per Agent (CRITICAL — Context Overflow Prevention)
607
389
 
608
390
  **Maximum 15 tasks per agent.** Agents with more tasks accumulate too much context in auto-mode, leading to extended thinking loops and stuck agents.
@@ -612,15 +394,22 @@ When distributing tasks from the master spec:
612
394
  2. If a domain has >15 tasks: **split into 2 agents** (e.g., `jira-agent-a`, `jira-agent-b`) with non-overlapping task ranges
613
395
  3. If splitting isn't natural, group tasks into phases and create 2 increments per domain
614
396
 
397
+ ```
398
+ Domain tasks analysis:
399
+ Frontend: 12 tasks -> 1 agent (OK)
400
+ Backend: 8 tasks -> 1 agent (OK)
401
+ JIRA: 23 tasks -> SPLIT into 2 agents (tasks 1-12, tasks 13-23)
402
+ ```
403
+
615
404
  **Why**: Each auto-mode iteration adds context (spec reads, edits, test outputs). At 20+ tasks, accumulated context causes the model to enter extended thinking (30+ min) and effectively hang. The 15-task cap keeps agents within a safe context budget.
616
405
 
617
406
  ---
618
407
 
619
408
  ## 4. Agent Spawn Prompt Templates
620
409
 
621
- Agent definitions live as reusable `.md` files in the `agents/` subdirectory. When spawning an agent, **Read the agent file and use its full content as the Task() prompt**, with placeholders replaced.
410
+ Agent definitions live as reusable `.md` files in the `agents/` subdirectory. When spawning a domain agent, **Read the agent file and use its full content as the Task() prompt**, with placeholders replaced.
622
411
 
623
- ### Implementation Agent Reference
412
+ ### Agent Reference Table
624
413
 
625
414
  | Agent | File | Domain | Phase | Primary Skills |
626
415
  |-------|------|--------|-------|---------------|
@@ -630,41 +419,32 @@ Agent definitions live as reusable `.md` files in the `agents/` subdirectory. Wh
630
419
  | Testing | `agents/testing.md` | Unit, integration, E2E | 2 (downstream) | `testing:qa`, `testing:e2e` |
631
420
  | Security | `agents/security.md` | Auth, validation, audit | 2 (downstream) | `sw:security` |
632
421
 
633
- ### Review Agent Reference
634
-
635
- | Agent | File | Focus |
636
- |-------|------|-------|
637
- | Security Reviewer | `agents/reviewer-security.md` | Vulnerabilities, injection, auth, secrets, OWASP |
638
- | Logic Reviewer | `agents/reviewer-logic.md` | Correctness, edge cases, error handling, race conditions |
639
- | Performance Reviewer | `agents/reviewer-performance.md` | N+1 queries, memory leaks, algorithmic complexity |
640
-
641
- ### Brainstorm Agent Reference
642
-
643
- | Agent | File | Perspective |
644
- |-------|------|------------|
645
- | Advocate | `agents/brainstorm-advocate.md` | Champions innovative/ambitious approaches |
646
- | Critic | `agents/brainstorm-critic.md` | Devil's advocate — finds risks and failure modes |
647
- | Pragmatist | `agents/brainstorm-pragmatist.md` | Practical realist — timelines, skills, maintenance |
648
-
649
422
  ### How to Use Agent Files
650
423
 
651
- For each agent to spawn:
424
+ For each domain agent to spawn:
652
425
 
653
- 1. **Read** the agent definition: `Read("agents/{name}.md")`
426
+ 1. **Read** the agent definition: `Read("agents/{domain}.md")`
654
427
  2. **Replace placeholders** in the content:
655
- - `[REVIEW_TARGET]` → PR number, file paths, or module name being reviewed
656
- - `[BRAINSTORM_QUESTION]` → the core question being explored
657
- - `[INCREMENT_ID]` → the increment ID (implementation mode)
658
- - `[MASTER_INCREMENT_PATH]` → full path to the master increment directory (implementation mode)
428
+ - `[INCREMENT_ID]` → the increment ID (e.g., `0042-checkout-flow`)
429
+ - `[MASTER_INCREMENT_PATH]` → full path to the master increment directory
659
430
  - `{ORG}` → the discovered organization name
660
431
  - `{repo-name}` → the assigned repository name
661
- 3. **Spawn** via Task() with the replaced content as the prompt
432
+ 3. **Spawn** via Task() with the replaced content as the prompt:
433
+ ```
434
+ Task({
435
+ team_name: "<team-name>",
436
+ name: "<domain>-agent",
437
+ subagent_type: "general-purpose",
438
+ mode: "bypassPermissions",
439
+ prompt: <replaced agent content>
440
+ })
441
+ ```
662
442
 
663
443
  **CRITICAL**: Always use `mode: "bypassPermissions"` — agents cannot handle interactive trust-folder prompts.
664
444
 
665
445
  ---
666
446
 
667
- ## 5. File Ownership (Implementation Mode)
447
+ ## 5. File Ownership
668
448
 
669
449
  Each agent has exclusive WRITE access to specific file patterns. This prevents merge conflicts.
670
450
 
@@ -691,49 +471,51 @@ Each agent has exclusive WRITE access to specific file patterns. This prevents m
691
471
  5. **Conflict detection** -- the orchestrator checks for ownership overlap before spawning and resolves ambiguity upfront
692
472
  6. **Repository directory structure** -- for multi-repo setups, ALL repository cloning and creation MUST use the `repositories/{ORG}/` directory convention
693
473
 
694
- **Note**: Review, brainstorm, and analysis mode agents have READ-ONLY access to all files. They do not write code (unless explicitly asked to produce fixes in review mode).
695
-
696
474
  ---
697
475
 
698
476
  ## 6. Communication Protocol
699
477
 
700
- Agents communicate using `SendMessage`. The message prefix convention varies by mode.
478
+ Agents communicate contract readiness, blocking issues, and completion status using `SendMessage`.
701
479
 
702
- ### Implementation Mode Messages
480
+ ### Message Types
703
481
 
704
482
  | Prefix | Purpose | Sender | Receiver |
705
483
  |--------|---------|--------|----------|
706
- | `CONTRACT_READY:` | Upstream contract is published | Upstream agent | team-lead |
484
+ | `CONTRACT_READY:` | Upstream contract is published | Upstream agent | team-lead (broadcasts to downstream) |
707
485
  | `BLOCKING_ISSUE:` | Agent is stuck, needs help | Any agent | team-lead |
708
486
  | `COMPLETION:` | Agent finished all tasks | Any agent | team-lead |
709
- | `PLAN_READY:` | Agent's plan is ready for review | Any agent | team-lead |
710
- | `PLAN_APPROVED:` | Plan approved, proceed | team-lead | Agent |
711
- | `PLAN_REJECTED:` | Plan needs revision | team-lead | Agent |
712
-
713
- ### Review Mode Messages
714
487
 
715
- | Prefix | Purpose | Sender | Receiver |
716
- |--------|---------|--------|----------|
717
- | `REVIEW_COMPLETE:` | Review findings ready | Review agent | team-lead |
718
- | `REVIEW_QUESTION:` | Needs clarification about code | Review agent | team-lead |
488
+ ### Message Examples
719
489
 
720
- ### Brainstorm Mode Messages
721
-
722
- | Prefix | Purpose | Sender | Receiver |
723
- |--------|---------|--------|----------|
724
- | `PERSPECTIVE_COMPLETE:` | Perspective analysis done | Brainstorm agent | team-lead |
725
- | `INSIGHT:` | Important finding during analysis | Brainstorm agent | team-lead |
490
+ ```typescript
491
+ // Upstream agent signals contract is ready
492
+ SendMessage({
493
+ type: "message",
494
+ recipient: "team-lead",
495
+ content: "CONTRACT_READY: TypeScript interfaces written to src/types/checkout.ts. Exports: CheckoutItem, CartSummary, PaymentIntent.",
496
+ summary: "Shared types contract ready"
497
+ });
726
498
 
727
- ### Analysis Mode Messages
499
+ // Agent reports a blocking issue
500
+ SendMessage({
501
+ type: "message",
502
+ recipient: "team-lead",
503
+ content: "BLOCKING_ISSUE: Cannot implement payment webhook -- Stripe webhook secret not found in .env. Need STRIPE_WEBHOOK_SECRET to proceed.",
504
+ summary: "Blocked on missing Stripe secret"
505
+ });
728
506
 
729
- | Prefix | Purpose | Sender | Receiver |
730
- |--------|---------|--------|----------|
731
- | `ANALYSIS_COMPLETE:` | Analysis findings ready | Analysis agent | team-lead |
732
- | `FINDING:` | Significant discovery | Analysis agent | team-lead |
507
+ // Agent signals completion
508
+ SendMessage({
509
+ type: "message",
510
+ recipient: "team-lead",
511
+ content: "COMPLETION: All 8 tasks done. Tests passing (24/24). Ready for team-lead closure.",
512
+ summary: "Frontend agent completed all tasks"
513
+ });
514
+ ```
733
515
 
734
516
  ---
735
517
 
736
- ## 7. Spawning Agents (Implementation Mode)
518
+ ## 7. Spawning Agents
737
519
 
738
520
  ### Step 1: Create the Team
739
521
 
@@ -748,9 +530,10 @@ TeamCreate({
748
530
 
749
531
  All agents are spawned with `mode: "bypassPermissions"` to prevent blocking on trust-folder prompts. Plan review is enforced via the SendMessage PLAN_READY/PLAN_APPROVED protocol (see Section 3b).
750
532
 
751
- For each agent: **Read the agent definition file** (see Section 4 reference table), replace placeholders, and use the full content as the Task() prompt.
533
+ For each agent: **Read the agent definition file** (see Section 4 reference table), replace placeholders (`[INCREMENT_ID]`, `[MASTER_INCREMENT_PATH]`, `{ORG}`, `{repo-name}`), and use the full content as the Task() prompt.
752
534
 
753
535
  ```typescript
536
+ // Read agents/database.md, replace placeholders, then:
754
537
  Task({
755
538
  team_name: "feature-checkout",
756
539
  name: "database-agent",
@@ -767,6 +550,8 @@ Messages are delivered automatically via SendMessage from upstream agents.
767
550
  ### Step 4: Spawn Downstream Agents (Phase 2)
768
551
 
769
552
  ```typescript
553
+ // Read agents/backend.md, agents/frontend.md, agents/testing.md
554
+ // Replace placeholders, then spawn each:
770
555
  Task({
771
556
  team_name: "feature-checkout",
772
557
  name: "backend-agent",
@@ -794,7 +579,7 @@ Task({
794
579
 
795
580
  ---
796
581
 
797
- ## 8. Quality Gates (Implementation Mode)
582
+ ## 8. Quality Gates
798
583
 
799
584
  Quality gates are split: agents handle tests, team-lead handles closure (grill, done, judge-llm). This prevents context overflow in agents from loading 4+ additional skill definitions during closure.
800
585
 
@@ -811,6 +596,8 @@ Agent Workflow:
811
596
  7. Do NOT run /sw:grill or /sw:done — team-lead handles closure centrally
812
597
  ```
813
598
 
599
+ **Why agents don't run /sw:done**: The /sw:done skill invokes 4 sub-skills (grill, judge-llm, sync-docs, qa), each loading a full SKILL.md. After 15+ tasks of auto-mode context, this pushes agents into extended thinking (30+ min hangs). Centralizing closure on the team-lead (which has a cleaner context) avoids this.
600
+
814
601
  ### Orchestrator Quality Gate (Centralized Closure)
815
602
 
816
603
  After all agents complete, the team-lead runs closure **centrally** for each increment.
@@ -825,7 +612,7 @@ Orchestrator Final Check:
825
612
  4. For EACH increment in dependency order (shared → database → backend → frontend → testing → security):
826
613
  a. PRE-CLOSURE STATUS CHECK:
827
614
  - Read metadata.json status
828
- - If status is "planned" or "backlog" → Edit to "active"
615
+ - If status is "planned" or "backlog" → Edit to "active" (agents may not have activated)
829
616
  - If status is "completed" → Skip (already closed)
830
617
  b. Run /sw:grill on the increment
831
618
  c. If grill finds CRITICAL/BLOCKER issues:
@@ -833,7 +620,7 @@ Orchestrator Final Check:
833
620
  → Re-run /sw:grill (max 2 retries)
834
621
  → If still failing after 2 retries → log failure, move to next increment
835
622
  d. Run /sw:done --auto <id>
836
- e. If /sw:done fails:
623
+ e. If /sw:done fails (quality gate, desync, missing reports):
837
624
  → Read the error output carefully
838
625
  → Fix the root cause (sync ACs, update task counts, write missing reports)
839
626
  → Re-run /sw:done --auto <id> (max 2 retries)
@@ -841,6 +628,7 @@ Orchestrator Final Check:
841
628
  5. After all increments attempted:
842
629
  - If ALL closed → /sw:team-merge
843
630
  - If SOME failed → report which increments are still open with failure reasons
631
+ - Do NOT leave increments in limbo — either close them or clearly report why they can't close
844
632
  ```
845
633
 
846
634
  **Common closure failures and fixes:**
@@ -854,6 +642,17 @@ Orchestrator Final Check:
854
642
  | Task count mismatch | tasks.md frontmatter != actual checked tasks | Update `completed_tasks` in tasks.md frontmatter |
855
643
  | ACs not all checked | Some ACs still `[ ]` in spec.md | Verify implementation, then check them `[x]` |
856
644
 
645
+ ### Grill Checklist per Domain
646
+
647
+ | Domain | Grill Checks |
648
+ |--------|-------------|
649
+ | Frontend | Components render, no console errors, accessibility, responsive |
650
+ | Backend | API endpoints return correct status codes, validation works, error handling |
651
+ | Database | Migrations apply cleanly, seed data loads, rollback works |
652
+ | Testing | All tests pass, coverage threshold met, no flaky tests |
653
+ | Security | No exposed secrets, input validation, auth working |
654
+ | DevOps | Docker builds, CI passes, deployment config valid |
655
+
857
656
  ---
858
657
 
859
658
  ## 8b. Agent Timeout and Stuck Detection
@@ -862,102 +661,96 @@ Agents can get stuck in extended thinking if their context overflows. The team-l
862
661
 
863
662
  ### Stuck Detection Rules
864
663
 
865
- **Note**: Claude Code has no built-in timers. These are best-effort heuristics applied when the team-lead regains control.
664
+ **Note**: Claude Code has no built-in timers. These are best-effort heuristics applied when the team-lead regains control (e.g., after processing other agent messages).
866
665
 
867
666
  | Condition | Action |
868
667
  |-----------|--------|
869
668
  | Agent has not messaged since team-lead's last turn | Send `STATUS_CHECK` message to agent |
870
669
  | Agent does not respond to STATUS_CHECK on next team-lead turn | Declare agent stuck |
871
- | Agent stuck | Log warning, proceed with other agents, handle stuck agent's work manually |
670
+ | Agent stuck | Log warning, proceed with other agents, handle stuck agent's increment manually in team-merge |
872
671
  | All agents stuck | STOP team, report to user |
873
672
 
874
673
  ### Stuck Agent Recovery
875
674
 
876
- 1. Do NOT wait for it — proceed with closure of other agents' work
877
- 2. Note the stuck agent's last known progress
878
- 3. Send shutdown_request to the stuck agent to free resources
879
- 4. For implementation mode: leave stuck agent's increment open for manual completion
675
+ When an agent is declared stuck:
676
+ 1. Do NOT wait for it proceed with closure of other agents' increments
677
+ 2. Note the stuck agent's increment ID and last known task progress
678
+ 3. During /sw:team-merge, the stuck agent's increment is left open for manual completion
679
+ 4. Send shutdown_request to the stuck agent to free resources
880
680
 
881
681
  ### Preventing Stuck Agents
882
682
 
883
- - Enforce the 15-task cap (implementation mode)
884
- - Agents use `--simple` flag in auto-mode
683
+ - Enforce the 15-task cap (Section 3b)
684
+ - Agents use `--simple` flag in auto-mode (reduces context per iteration)
885
685
  - Agents do NOT run /sw:done (team-lead handles closure centrally)
886
- - Review/brainstorm/analysis agents have inherently bounded scope
686
+ - If an agent's task count exceeds 15 despite the cap, the team-lead should split it before spawning
887
687
 
888
688
  ---
889
689
 
890
690
  ## 9. Workflow Summary
891
691
 
892
- ### Implementation Mode
893
-
894
692
  ```
895
693
  /sw:team-lead "Build checkout flow"
896
694
 
897
- ├── Step 0: MODE DETECTION implementation (default)
898
- ├── Step 0a: VERIFY INCREMENT EXISTS (BLOCKING)
695
+ ├── Step 0: VERIFY INCREMENT EXISTS (BLOCKING)
899
696
  │ ├── Found? → Read master spec.md as source of truth
900
697
  │ └── Missing? → Auto-invoke /sw:increment, wait for completion
901
- ├── Step 0b: ACTIVATE MASTER INCREMENT
902
- │ └── Edit metadata.json: set status to "active"
903
- ├── Step 1: Analyze feature identify domains decide increment split
904
- ├── Step 2: Create team via TeamCreate (team_name: "impl-*" or any)
905
- ├── Step 3: Create per-domain increments
698
+ ├── Step 0b: ACTIVATE MASTER INCREMENT (MANDATORY)
699
+ │ └── Edit metadata.json: set status to "active" BEFORE spawning agents
700
+ ├── Step 1: Analyze feature (from master spec) -> identify domains -> decide increment split
701
+ ├── Step 2: Create team via TeamCreate
702
+ ├── Step 3: Create per-domain increments (derived from master spec)
906
703
  ├── Step 4: Contract-first spawning (all agents with mode: "bypassPermissions")
907
- │ ├── Phase 1: Spawn shared + database → wait for CONTRACT_READY
704
+ │ ├── Phase 1: Spawn shared + database
705
+ │ │ └── Receive PLAN_READY, review & approve via SendMessage (Section 3b)
706
+ │ │ └── Wait for CONTRACT_READY after approval
908
707
  │ └── Phase 2: Spawn backend + frontend + testing
909
- ├── Step 5: Monitor progress via SendMessage
910
- ├── Step 6: Agents signal COMPLETION
911
- ├── Step 7: Team-lead runs centralized closure per increment
708
+ │ └── Receive PLAN_READY, review & approve via SendMessage
709
+ ├── Step 5: Monitor progress via SendMessage (timeout: 20min idle → STATUS_CHECK)
710
+ ├── Step 6: Agents signal COMPLETION (tests pass, no /sw:grill or /sw:done on agents)
711
+ ├── Step 7: Team-lead runs centralized closure per increment:
712
+ │ ├── Pre-closure: verify/fix metadata.json status → must be "active"
713
+ │ ├── /sw:grill → fix findings → retry if needed (max 2)
714
+ │ └── /sw:done --auto → fix gate failures → retry if needed (max 2)
912
715
  └── Step 8: Merge and close (/sw:team-merge)
913
716
  ```
914
717
 
915
- ### Review Mode
718
+ **IMPORTANT**: The intended entry point is: `/sw:increment` → `/sw:do` (detects 3+ domains) → `/sw:team-lead`.
719
+ Direct invocation of `/sw:team-lead` without an existing increment will trigger the guard and auto-invoke `/sw:increment`.
916
720
 
917
- ```
918
- /sw:team-lead "Review PR #63" --mode review
919
-
920
- ├── Step 0: MODE DETECTION → review
921
- ├── Step 1: Determine review scope (PR diff, target files)
922
- ├── Step 2: Create team (team_name: "review-pr-63")
923
- ├── Step 3: Spawn all reviewers in parallel
924
- │ ├── Security Reviewer
925
- │ ├── Logic Reviewer
926
- │ └── Performance Reviewer
927
- ├── Step 4: Collect REVIEW_COMPLETE from all agents
928
- ├── Step 5: Merge, deduplicate, prioritize findings
929
- └── Step 6: Deliver unified review to user
930
- ```
721
+ ### Step 9: Post-Completion Cleanup (MANDATORY)
931
722
 
932
- ### Brainstorm Mode
723
+ **After delivering results OR after /sw:team-merge, ALWAYS clean up the team.**
933
724
 
934
- ```
935
- /sw:team-lead "Brainstorm payment architecture" --mode brainstorm
936
-
937
- ├── Step 0: MODE DETECTION → brainstorm
938
- ├── Step 1: Frame the core question
939
- ├── Step 2: Create team (team_name: "brainstorm-payment-arch")
940
- ├── Step 3: Spawn all perspective agents in parallel
941
- │ ├── Advocate (champions innovative approaches)
942
- │ ├── Critic (finds risks and failure modes)
943
- │ └── Pragmatist (practical feasibility)
944
- ├── Step 4: Collect PERSPECTIVE_COMPLETE from all agents
945
- ├── Step 5: Synthesize into decision matrix
946
- └── Step 6: Recommend path forward → suggest /sw:increment if proceeding
725
+ ```typescript
726
+ // Clean up the team session so the next invocation starts fresh
727
+ TeamDelete();
947
728
  ```
948
729
 
949
- ### Analysis Mode
730
+ This removes `~/.claude/teams/{team-name}/` and `~/.claude/tasks/{team-name}/`, ensuring subsequent `/sw:team-lead` invocations can create new teams without conflicts.
731
+
732
+ **If you skip this step**, the next `/sw:team-lead` run in the same session will likely fail to spawn agents.
733
+
734
+ ### --dry-run Output
735
+
736
+ When `--dry-run` is specified, display the proposed plan without executing.
737
+ **Do NOT call TeamCreate in dry-run mode** — just show the formatted plan text.
950
738
 
951
739
  ```
952
- /sw:team-lead "Analyze auth module architecture" --mode analysis
953
-
954
- ├── Step 0: MODE DETECTION analysis
955
- ├── Step 1: Define analysis scope and questions
956
- ├── Step 2: Create team (team_name: "analysis-auth-deps")
957
- ├── Step 3: Spawn analysis agents (dynamically composed)
958
- ├── Step 4: Collect ANALYSIS_COMPLETE from all agents
959
- ├── Step 5: Synthesize findings into structured report
960
- └── Step 6: Deliver report → suggest /sw:increment if actionable
740
+ Team Orchestration Plan (DRY RUN)
741
+ ==================================================
742
+ Feature: Build checkout flow | Domains: 4
743
+
744
+ Phase 1 (upstream):
745
+ 1. shared-types -> sw:architect, sw:code-simplifier | Increment: 0200-checkout-shared
746
+ 2. database -> sw:architect | Increment: 0201-checkout-database
747
+
748
+ Phase 2 (downstream, parallel):
749
+ 3. backend -> sw:architect, infra:devops | Increment: 0202-checkout-backend
750
+ 4. frontend -> frontend:architect | Increment: 0203-checkout-frontend
751
+
752
+ Max agents: 4 (2 sequential + 2 parallel)
753
+ To execute, run without --dry-run.
961
754
  ```
962
755
 
963
756
  ---
@@ -966,27 +759,29 @@ Agents can get stuck in extended thinking if their context overflows. The team-l
966
759
 
967
760
  | Issue | Cause | Fix |
968
761
  |-------|-------|-----|
969
- | **TeamCreate blocked by guard** | No increment exists AND team_name doesn't have a non-impl prefix | For implementation: run `/sw:increment` first. For review/brainstorm/analysis: use the correct team_name prefix (review-*, brainstorm-*, analysis-*) |
970
- | **Agent stuck on trust folder** | Agent spawned without `bypassPermissions` | ALWAYS use `mode: "bypassPermissions"` — NEVER `mode: "plan"` |
971
- | **Agents editing same files** | Overlapping file ownership (implementation mode) | Review ownership map; reassign conflicting files |
972
- | **Token cost too high** | Too many agents | Reduce `--max-agents`; use `--domains` to limit scope |
973
- | **Agent stuck in extended thinking** | Too many tasks (>15) | Enforce 15-task cap; split large domains |
974
- | **Review agents missing context** | PR diff not provided in prompt | Ensure PR number or file paths are in [REVIEW_TARGET] placeholder |
975
- | **Brainstorm too shallow** | Agents not exploring deeply enough | Add more specific context to [BRAINSTORM_QUESTION] placeholder |
976
- | **Wrong mode detected** | Ambiguous description | Use explicit `--mode` flag or correct team_name prefix |
977
- | **`specweave complete` exits silently** | metadata.json status is "planned" | Edit metadata.json: set status to "active" before closure |
762
+ | **TeamCreate blocked by guard** | No increment with spec.md exists | Run `/sw:increment "feature"` first, then retry `/sw:team-lead`. The guard requires a substantive spec.md (>200 bytes, not a template) |
763
+ | **Agent stuck on trust folder** | Agent spawned without `bypassPermissions` | ALWAYS use `mode: "bypassPermissions"` — NEVER `mode: "plan"`. Trust prompts require interactive input agents cannot provide |
764
+ | **Agents editing same files** | Overlapping file ownership patterns | Review ownership map; reassign conflicting files to a single owner; use `--dry-run` to validate before launch |
765
+ | **Token cost too high** | Too many agents or overly large prompts | Reduce `--max-agents`; use `--domains` to limit scope; split feature into smaller increments |
766
+ | **Agent stuck in extended thinking** | Too many tasks (>15) causing context overflow | Enforce 15-task cap per agent; split large domains into 2 agents; agents use `--simple` mode |
767
+ | **Agent hung on /sw:done** | Closure loads 4+ skill definitions into already-full context | Agents should NOT run /sw:done team-lead handles closure centrally |
768
+ | **Contract agent takes too long** | Large schema or complex type system | Set a timeout in the agent prompt; if stuck >15 min, check agent output and consider splitting the contract work |
769
+ | **Phase 2 starts before Phase 1 finishes** | CONTRACT_READY not received yet | Ensure upstream agents send CONTRACT_READY via SendMessage before team-lead spawns downstream |
770
+ | **Agent fails mid-task** | Build error, test failure, or dependency issue | Send message to agent to fix; restart the agent with `/sw:auto` on its increment |
771
+ | **`specweave complete` exits silently** | metadata.json status is "planned" (not "active") | Agents don't manage lifecycle status. Team-lead MUST activate the increment before spawning agents (see Step 0). Fix: edit metadata.json to set `"status": "active"` before running `specweave complete` |
772
+ | **Closure fails on multiple increments** | Quality gates fail (grill, desync, missing reports) | Fix each issue and retry `/sw:done --auto` (max 2 retries per increment). See Section 8 closure failure table |
978
773
 
979
774
  ---
980
775
 
981
776
  ## 11. Examples
982
777
 
983
- ### Example 1: Full-Stack Feature (Implementation Mode)
778
+ ### Example 1: Full-Stack Feature
984
779
 
985
780
  ```
986
781
  User: /sw:team-lead "Build user authentication with login, signup, password reset, and OAuth"
987
782
 
988
- Mode: implementation (auto-detected)
989
- Domains: shared/types, database, backend, frontend, testing, security
783
+ Orchestrator detects domains: shared/types, database, backend, frontend, testing, security
784
+ Creates 6 increments.
990
785
 
991
786
  Phase 1:
992
787
  - shared-types agent: Auth types (User, Session, AuthToken interfaces)
@@ -999,73 +794,18 @@ Phase 2 (after contracts ready):
999
794
  - security agent: Password hashing, JWT validation, rate limiting, CSRF
1000
795
  ```
1001
796
 
1002
- ### Example 2: PR Review (Review Mode)
797
+ ### Example 2: Frontend-Only (No Dependencies)
1003
798
 
1004
799
  ```
1005
- User: /sw:team-lead "Review PR #63"
1006
-
1007
- Mode: review (auto-detected from "PR #63")
1008
- Team: review-pr-63
1009
-
1010
- Spawns 3 parallel reviewers:
1011
- - Security: Checks for injection, auth bypass, secrets in diff
1012
- - Logic: Verifies correctness, edge cases, error handling in changed code
1013
- - Performance: Identifies N+1 queries, unnecessary allocations in diff
1014
-
1015
- Output: Unified review with Must Fix / Should Fix / Consider categories
800
+ User: /sw:team-lead "Redesign dashboard" --domains frontend,testing
801
+ -> No upstream dependencies. Both agents spawn in parallel immediately.
1016
802
  ```
1017
803
 
1018
- ### Example 3: Architecture Brainstorm (Brainstorm Mode)
1019
-
1020
- ```
1021
- User: /sw:team-lead "Brainstorm: microservices vs monolith for our growing app"
1022
-
1023
- Mode: brainstorm (auto-detected from "brainstorm")
1024
- Team: brainstorm-arch-decision
1025
-
1026
- Spawns 3 parallel perspective agents:
1027
- - Advocate: Champions microservices — independent scaling, team autonomy, polyglot
1028
- - Critic: Warns about distributed complexity, network latency, operational overhead
1029
- - Pragmatist: Evaluates team size, current traffic, migration cost, timeline
1030
-
1031
- Output: Decision matrix with scored options and recommended path
1032
- ```
1033
-
1034
- ### Example 4: Codebase Analysis (Analysis Mode)
1035
-
1036
- ```
1037
- User: /sw:team-lead "Analyze our dependency tree for security risks" --mode analysis
1038
-
1039
- Mode: analysis (explicit flag)
1040
- Team: analysis-dep-security
1041
-
1042
- Spawns dynamically composed agents:
1043
- - npm-audit-agent: Runs npm audit, maps CVEs to severity
1044
- - license-agent: Checks license compliance across all deps
1045
- - freshness-agent: Identifies outdated packages and upgrade paths
1046
-
1047
- Output: Structured report with findings, risk assessment, prioritized action items
1048
- ```
1049
-
1050
- ### Example 5: Dry Run
804
+ ### Example 3: Dry Run
1051
805
 
1052
806
  ```
1053
807
  User: /sw:team-lead "Add payment processing" --dry-run
1054
-
1055
- Team Orchestration Plan (DRY RUN)
1056
- ==================================================
1057
- Feature: Add payment processing | Mode: implementation | Domains: 4
1058
-
1059
- Phase 1 (upstream):
1060
- 1. shared-types -> sw:architect | Increment: 0200-payment-shared
1061
- 2. database -> sw:architect | Increment: 0201-payment-database
1062
-
1063
- Phase 2 (downstream, parallel):
1064
- 3. backend -> sw:architect | Increment: 0202-payment-backend
1065
- 4. frontend -> frontend:architect | Increment: 0203-payment-frontend
1066
-
1067
- Max agents: 4 (2 sequential + 2 parallel)
1068
- To execute, run without --dry-run.
808
+ -> Shows plan with domains, phases, file ownership. No agents spawned.
1069
809
  ```
1070
810
 
1071
811
  ---
@@ -1076,8 +816,6 @@ To execute, run without --dry-run.
1076
816
  |-------|---------|
1077
817
  | `/sw:team-status` | Show progress of all agents in the current team session |
1078
818
  | `/sw:team-merge` | Merge completed agent work in dependency order |
1079
- | `/sw:team-build` | Preset-driven team spawning (full-stack, review, testing, tdd, migration) |
1080
819
  | `/sw:auto` | Autonomous execution (single-agent mode) |
1081
820
  | `/sw:architect` | System architecture and ADRs |
1082
821
  | `/sw:grill` | Quality validation gate |
1083
- | `/sw:brainstorm` | Single-agent brainstorming (for simpler ideation without teams) |