claude-capsule-kit 3.0.0

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 (107) hide show
  1. package/README.md +281 -0
  2. package/agents/agent-developer.md +206 -0
  3. package/agents/architecture-explorer.md +90 -0
  4. package/agents/brainstorm-coordinator.md +120 -0
  5. package/agents/code-reviewer.md +135 -0
  6. package/agents/context-librarian.md +227 -0
  7. package/agents/context-manager.md +151 -0
  8. package/agents/database-architect.md +107 -0
  9. package/agents/database-navigator.md +136 -0
  10. package/agents/debugger.md +121 -0
  11. package/agents/devops-sre.md +102 -0
  12. package/agents/error-detective.md +128 -0
  13. package/agents/git-workflow-manager.md +212 -0
  14. package/agents/github-issue-tracker.md +252 -0
  15. package/agents/product-dx-specialist.md +99 -0
  16. package/agents/refactoring-specialist.md +159 -0
  17. package/agents/security-engineer.md +102 -0
  18. package/agents/session-summarizer.md +126 -0
  19. package/agents/system-architect.md +103 -0
  20. package/bin/cck.js +1624 -0
  21. package/commands/crew-setup.md +75 -0
  22. package/commands/load-session.md +68 -0
  23. package/commands/sessions.md +55 -0
  24. package/commands/statusline.md +51 -0
  25. package/commands/sync-disable.md +35 -0
  26. package/commands/sync-enable.md +32 -0
  27. package/commands/sync.md +31 -0
  28. package/crew/lib/activity-monitor.js +128 -0
  29. package/crew/lib/crew-config-reader.js +255 -0
  30. package/crew/lib/health-monitor.js +171 -0
  31. package/crew/lib/merge-pilot.js +340 -0
  32. package/crew/lib/prompt-generator.js +268 -0
  33. package/crew/lib/role-presets.js +63 -0
  34. package/crew/lib/task-decomposer.js +382 -0
  35. package/crew/lib/team-spawner.sh +557 -0
  36. package/crew/lib/team-state-manager.js +155 -0
  37. package/crew/lib/worktree-gc.js +357 -0
  38. package/crew/lib/worktree-manager.sh +700 -0
  39. package/docs/AGENT_ROUTING_GUIDE.md +655 -0
  40. package/docs/AGENT_TEAMS_WORKTREE_MODE.md +681 -0
  41. package/docs/BEST_PRACTICES.md +194 -0
  42. package/docs/CAPSULE_DEGRADATION_RCA.md +577 -0
  43. package/docs/SKILLS_ORCHESTRATION_ARCHITECTURE.md +455 -0
  44. package/docs/SUPER_CLAUDE_SYSTEM_ARCHITECTURE.md +1647 -0
  45. package/docs/TOOL_ENFORCEMENT_REFERENCE.md +418 -0
  46. package/hooks/check-refresh-needed.sh +77 -0
  47. package/hooks/detect-changes.sh +90 -0
  48. package/hooks/keyword-triggers.sh +66 -0
  49. package/hooks/lib/crew-detect.js +241 -0
  50. package/hooks/lib/handoff-generator.js +158 -0
  51. package/hooks/load-from-journal.sh +41 -0
  52. package/hooks/post-tool-use.js +212 -0
  53. package/hooks/pre-compact.js +77 -0
  54. package/hooks/pre-edit-analysis.sh +68 -0
  55. package/hooks/pre-tool-use.sh +212 -0
  56. package/hooks/prompt-submit-memory.sh +87 -0
  57. package/hooks/quality-check.sh +48 -0
  58. package/hooks/session-end.js +133 -0
  59. package/hooks/session-start.js +439 -0
  60. package/hooks/stop.sh +66 -0
  61. package/hooks/suggest-discoveries.sh +84 -0
  62. package/hooks/summarize-session.sh +122 -0
  63. package/hooks/sync-to-journal.sh +77 -0
  64. package/hooks/sync-todowrite.sh +37 -0
  65. package/hooks/tool-auto-suggest.sh +77 -0
  66. package/hooks/user-prompt-submit.sh +71 -0
  67. package/lib/audit-logger.sh +120 -0
  68. package/lib/sandbox-validator.sh +194 -0
  69. package/lib/tool-runner.sh +274 -0
  70. package/package.json +67 -0
  71. package/scripts/postinstall.js +4 -0
  72. package/scripts/show-capsule-visual.sh +103 -0
  73. package/scripts/show-capsule.sh +113 -0
  74. package/scripts/show-deps-tree.sh +66 -0
  75. package/scripts/show-stats-dashboard.sh +52 -0
  76. package/scripts/show-stats.sh +79 -0
  77. package/skills/code-review/SKILL.md +520 -0
  78. package/skills/crew/SKILL.md +395 -0
  79. package/skills/debug/SKILL.md +473 -0
  80. package/skills/deep-context/SKILL.md +446 -0
  81. package/skills/task-router/SKILL.md +390 -0
  82. package/skills/workflow/SKILL.md +370 -0
  83. package/templates/CLAUDE.md +124 -0
  84. package/templates/crew-config.json +21 -0
  85. package/templates/settings-hooks.json +74 -0
  86. package/templates/statusline-command.sh +208 -0
  87. package/tools/context-query/context-query.js +312 -0
  88. package/tools/context-query/context-query.sh +5 -0
  89. package/tools/context-query/tool.json +42 -0
  90. package/tools/dependency-scanner/dependency-scanner.sh +53 -0
  91. package/tools/dependency-scanner/tool.json +8 -0
  92. package/tools/find-circular/find-circular.sh +41 -0
  93. package/tools/find-circular/tool.json +36 -0
  94. package/tools/find-dead-code/find-dead-code.sh +41 -0
  95. package/tools/find-dead-code/tool.json +36 -0
  96. package/tools/impact-analysis/impact-analysis.sh +99 -0
  97. package/tools/impact-analysis/tool.json +38 -0
  98. package/tools/progressive-reader/progressive-reader.sh +14 -0
  99. package/tools/progressive-reader/tool.json +69 -0
  100. package/tools/query-deps/query-deps.sh +69 -0
  101. package/tools/query-deps/tool.json +34 -0
  102. package/tools/stats/stats.js +299 -0
  103. package/tools/stats/stats.sh +5 -0
  104. package/tools/stats/tool.json +34 -0
  105. package/tools/token-counter/README.md +73 -0
  106. package/tools/token-counter/token-counter.py +202 -0
  107. package/tools/token-counter/tool.json +40 -0
@@ -0,0 +1,655 @@
1
+ # Agent Routing Guide
2
+
3
+ Complete guide for selecting and orchestrating Claude Capsule Kit's 17 specialized agents.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ Claude Capsule Kit provides **17 specialized agents**. Use the RIGHT agent for each task.
10
+
11
+ **Key Principle**: Agents run in fresh context with focused expertise—they're MORE EFFECTIVE than doing everything yourself.
12
+
13
+ ---
14
+
15
+ ## When to Use Agents
16
+
17
+ ### Core Principles
18
+
19
+ 1. **Use agents when task requires DEEP expertise or PARALLEL investigation**
20
+ - Complex debugging → error-detective
21
+ - Architectural understanding → architecture-explorer
22
+ - Multi-perspective analysis → brainstorm-coordinator
23
+
24
+ 2. **Don't use agents for simple, quick tasks you can do directly**
25
+ - Single file edit → Direct work
26
+ - Known bug fix → Direct work
27
+ - Simple config change → Direct work
28
+
29
+ 3. **Prefer parallel agent spawning when tasks are independent**
30
+ - Bug investigation → error-detective + architecture-explorer (parallel)
31
+ - Pre-refactor analysis → refactoring-specialist + code-reviewer (parallel)
32
+
33
+ ---
34
+
35
+ ## Agent Categories
36
+
37
+ ### 1. Debugging (error-detective, debugger)
38
+
39
+ **Triggers**: Error, bug, stack trace, "why is this failing", test failure
40
+
41
+ **Agents**:
42
+
43
+ **error-detective** (Opus)
44
+ - **Use for**: Root cause analysis - returns structured RCA report
45
+ - **Output**: What Failed, Root Cause, Evidence, Chain of Events, Suggested Fix, Confidence
46
+ - **When**: Always use FIRST for errors/bugs
47
+
48
+ **debugger** (Opus)
49
+ - **Use for**: Systematic debugging, code tracing, isolating issues
50
+ - **Output**: Symptom, Hypotheses, Investigation Path, Root Cause, Recommended Fix
51
+ - **When**: RCA confidence < 80% or complex code tracing needed
52
+
53
+ **Pattern**:
54
+ 1. Start with `error-detective` for RCA
55
+ 2. Use `debugger` if issue is complex or needs code tracing
56
+ 3. Run in PARALLEL if investigating multiple potential causes
57
+
58
+ **Example**:
59
+ ```
60
+ User: "Tests are failing with TypeError"
61
+
62
+ Task(subagent_type="error-detective", description="RCA for TypeError")
63
+ # If RCA confidence low:
64
+ Task(subagent_type="debugger", description="Trace code execution for TypeError")
65
+ ```
66
+
67
+ ---
68
+
69
+ ### 2. Code Quality (code-reviewer, refactoring-specialist)
70
+
71
+ **Triggers**: Review code, check for bugs, before commit, PR review
72
+
73
+ **Agents**:
74
+
75
+ **code-reviewer** (Sonnet)
76
+ - **Use for**: Code review with structured feedback
77
+ - **Output**: Issues by category (BUG/SECURITY/PERF/QUALITY), Verdict (APPROVE/REQUEST_CHANGES)
78
+ - **When**: BEFORE commits/PRs
79
+
80
+ **refactoring-specialist** (Opus)
81
+ - **Use for**: Safe refactoring plans
82
+ - **Output**: Code Smells, Refactoring Steps, Risk Assessment, Rollback Plan
83
+ - **When**: Improving structure without changing behavior
84
+
85
+ **Pattern**:
86
+ 1. Use `code-reviewer` BEFORE commits/PRs
87
+ 2. Use `refactoring-specialist` when improving structure without changing behavior
88
+
89
+ **Example**:
90
+ ```
91
+ User: "Review my changes before commit"
92
+
93
+ Task(subagent_type="code-reviewer", description="Pre-commit review")
94
+ # Wait for verdict
95
+ # If APPROVE → commit
96
+ # If REQUEST_CHANGES → fix issues, re-review
97
+ ```
98
+
99
+ ---
100
+
101
+ ### 3. Architecture (architecture-explorer, system-architect)
102
+
103
+ **Triggers**: How does X work, architecture question, system design, integration
104
+
105
+ **Agents**:
106
+
107
+ **architecture-explorer** (Sonnet) - PROACTIVE
108
+ - **Use for**: Understanding codebase architecture, data flows
109
+ - **When**: "How does X work?", exploring systems, understanding integration
110
+ - **Proactive**: Use without being explicitly asked
111
+
112
+ **system-architect** (Sonnet)
113
+ - **Use for**: Technical architecture, algorithms, scalability
114
+ - **Output**: Architecture Analysis, Design Recommendations, Trade-offs
115
+ - **When**: Designing new systems, evaluating algorithms
116
+
117
+ **Pattern**: Use `architecture-explorer` for "how does X work?" questions
118
+
119
+ **Example**:
120
+ ```
121
+ User: "How does the authentication flow work?"
122
+
123
+ Task(subagent_type="architecture-explorer", description="Understand auth flow")
124
+ # Agent explores: login endpoint → middleware → JWT validation → protected routes
125
+ ```
126
+
127
+ ---
128
+
129
+ ### 4. Database (database-navigator, database-architect)
130
+
131
+ **Triggers**: Schema, query, database, SQL, migration, data model
132
+
133
+ **Agents**:
134
+
135
+ **database-navigator** (Sonnet) - PROACTIVE
136
+ - **Use for**: Exploring schemas, understanding data models
137
+ - **When**: Schema questions, migration analysis, understanding relationships
138
+ - **Proactive**: Use without being explicitly asked
139
+
140
+ **database-architect** (Opus)
141
+ - **Use for**: Schema design, query optimization, data modeling
142
+ - **Output**: Schema Analysis, Query Optimization, Index Recommendations
143
+ - **When**: Designing new schemas, optimizing queries
144
+
145
+ **Example**:
146
+ ```
147
+ User: "What's the database structure?"
148
+
149
+ Task(subagent_type="database-navigator", description="Explore database schema")
150
+ # Agent maps: tables, relationships, foreign keys, migrations
151
+ ```
152
+
153
+ ---
154
+
155
+ ### 5. Security (security-engineer)
156
+
157
+ **Triggers**: Security, vulnerability, auth, encryption, compliance
158
+
159
+ **Agents**:
160
+
161
+ **security-engineer** (Opus)
162
+ - **Use for**: Security analysis, threat modeling, compliance
163
+ - **Output**: Threat Model, Vulnerabilities, Security Recommendations
164
+ - **When**: Auth implementation, data handling, compliance requirements
165
+
166
+ **Example**:
167
+ ```
168
+ User: "Review this authentication code for security"
169
+
170
+ Task(subagent_type="security-engineer", description="Security review of auth implementation")
171
+ # Agent checks: password handling, token security, injection risks, session management
172
+ ```
173
+
174
+ ---
175
+
176
+ ### 6. Git Operations (git-workflow-manager)
177
+
178
+ **Triggers**: Git conflict, branching strategy, git history, merge issues
179
+
180
+ **Agents**:
181
+
182
+ **git-workflow-manager** (Sonnet)
183
+ - **Use for**: Git workflows, conflict resolution, history management
184
+ - **Output**: Workflow Recommendation, Step-by-Step Commands, Rollback Plan
185
+ - **When**: Merge conflicts, complex git operations, branching decisions
186
+
187
+ **Example**:
188
+ ```
189
+ User: "I have merge conflicts in 5 files"
190
+
191
+ Task(subagent_type="git-workflow-manager", description="Resolve merge conflicts")
192
+ # Agent provides: conflict resolution strategy, step-by-step git commands, verification steps
193
+ ```
194
+
195
+ ---
196
+
197
+ ### 7. DevOps (devops-sre)
198
+
199
+ **Triggers**: Deployment, monitoring, production, incident, CI/CD
200
+
201
+ **Agents**:
202
+
203
+ **devops-sre** (Sonnet)
204
+ - **Use for**: Operational concerns, production readiness
205
+ - **Output**: Operational Analysis, Monitoring Recommendations, Incident Response
206
+ - **When**: Deployment issues, production bugs, monitoring setup, incident response
207
+
208
+ **Example**:
209
+ ```
210
+ User: "App is slow in production"
211
+
212
+ Task(subagent_type="devops-sre", description="Analyze production performance issue")
213
+ # Agent checks: metrics, logs, resource usage, scaling, database performance
214
+ ```
215
+
216
+ ---
217
+
218
+ ### 8. Complex Tasks (brainstorm-coordinator)
219
+
220
+ **Triggers**: Multiple perspectives needed, brainstorming, complex decision
221
+
222
+ **Agents**:
223
+
224
+ **brainstorm-coordinator** (Sonnet)
225
+ - **Use for**: Coordinating multiple specialists
226
+ - **Output**: Synthesized recommendations from multiple agents
227
+ - **Special**: Can spawn other agents in parallel (meta-agent)
228
+ - **When**: Design decisions, trade-off analysis, multi-perspective needed
229
+
230
+ **Example**:
231
+ ```
232
+ User: "Should we use microservices or monolith?"
233
+
234
+ Task(subagent_type="brainstorm-coordinator", description="Analyze architecture decision: microservices vs monolith")
235
+
236
+ # brainstorm-coordinator spawns:
237
+ - system-architect (technical perspective)
238
+ - devops-sre (operational perspective)
239
+ - product-dx-specialist (developer experience)
240
+
241
+ # Then synthesizes all perspectives into recommendation
242
+ ```
243
+
244
+ ---
245
+
246
+ ### 9. Context Management (context-manager, session-summarizer)
247
+
248
+ **Triggers**: Session handoff, context optimization, memory management
249
+
250
+ **Agents**:
251
+
252
+ **context-manager** (Sonnet)
253
+ - **Use for**: Context optimization, handoff summaries
254
+ - **Output**: Optimized context, Session summary for continuation
255
+ - **When**: Session getting long, preparing for handoff, context cleanup
256
+
257
+ **session-summarizer** (Haiku)
258
+ - **Use for**: Quick session summaries for sync
259
+ - **Output**: Concise summary optimized for Claude Web/Desktop/Mobile
260
+ - **When**: End of session, sync to other devices
261
+
262
+ **Example**:
263
+ ```
264
+ User: "Summarize this session for continuation tomorrow"
265
+
266
+ Task(subagent_type="context-manager", description="Create session handoff summary")
267
+ # Agent extracts: key decisions, progress made, next steps
268
+ ```
269
+
270
+ ---
271
+
272
+ ## Parallel Spawning Strategies
273
+
274
+ ### When to Spawn Multiple Agents
275
+
276
+ **Principle**: When investigating complex issues, spawn multiple agents in PARALLEL (not sequential)
277
+
278
+ **How**: Single message with multiple Task tool calls
279
+
280
+ ```
281
+ # CORRECT - Parallel (single message, 3 Task calls)
282
+ Task(subagent_type="error-detective", prompt="RCA for error X")
283
+ Task(subagent_type="code-reviewer", prompt="Review related code")
284
+ Task(subagent_type="architecture-explorer", prompt="Understand system Y")
285
+
286
+ # WRONG - Sequential (3 separate messages)
287
+ Message 1: Task(subagent_type="error-detective", ...)
288
+ [wait for result]
289
+ Message 2: Task(subagent_type="code-reviewer", ...)
290
+ [wait for result]
291
+ Message 3: Task(subagent_type="architecture-explorer", ...)
292
+ ```
293
+
294
+ ### Example Scenarios
295
+
296
+ **Bug Investigation**:
297
+ ```
298
+ Spawn simultaneously:
299
+ - error-detective (find root cause)
300
+ - code-reviewer (check related code quality)
301
+ - architecture-explorer (understand affected systems)
302
+ ```
303
+
304
+ **Pre-Refactor Analysis**:
305
+ ```
306
+ Spawn simultaneously:
307
+ - refactoring-specialist (plan the refactor)
308
+ - code-reviewer (identify issues to fix)
309
+ - database-navigator (if DB schema affected)
310
+ ```
311
+
312
+ **New Feature Design**:
313
+ ```
314
+ Spawn simultaneously:
315
+ - architecture-explorer (understand existing patterns)
316
+ - security-engineer (security considerations)
317
+ - database-navigator (schema requirements)
318
+ ```
319
+
320
+ ---
321
+
322
+ ## Complete Agent Index
323
+
324
+ | Agent | Model | Category | Use For |
325
+ |-------|-------|----------|---------|
326
+ | **error-detective** | Opus | Debugging | Root cause analysis (RCA) |
327
+ | **debugger** | Opus | Debugging | Systematic debugging, code tracing |
328
+ | **code-reviewer** | Sonnet | Code Quality | Pre-commit review, bug detection |
329
+ | **refactoring-specialist** | Opus | Code Quality | Safe refactoring plans |
330
+ | **architecture-explorer** | Sonnet | Architecture | Understanding systems, data flows |
331
+ | **system-architect** | Sonnet | Architecture | Technical design, algorithms |
332
+ | **database-navigator** | Sonnet | Database | Schema exploration, data models |
333
+ | **database-architect** | Opus | Database | Schema design, query optimization |
334
+ | **security-engineer** | Opus | Security | Threat modeling, vulnerabilities |
335
+ | **git-workflow-manager** | Sonnet | Git | Conflict resolution, git workflows |
336
+ | **devops-sre** | Sonnet | DevOps | Production readiness, incidents |
337
+ | **brainstorm-coordinator** | Sonnet | Complex | Multi-perspective coordination |
338
+ | **context-manager** | Sonnet | Context | Session optimization, handoffs |
339
+ | **session-summarizer** | Haiku | Context | Quick session summaries |
340
+ | **github-issue-tracker** | Sonnet | Tools | GitHub issue management |
341
+ | **product-dx-specialist** | Sonnet | Product | Developer experience, API design |
342
+ | **agent-developer** | Haiku | Development | Mini-agent development |
343
+
344
+ ---
345
+
346
+ ## Model Selection Guide
347
+
348
+ **Opus (Deep Reasoning)**:
349
+ - Use for: Complex analysis, design decisions, security
350
+ - Agents: error-detective, debugger, refactoring-specialist, database-architect, security-engineer, system-architect
351
+ - Cost: Higher, use for critical thinking
352
+
353
+ **Sonnet (Balanced)**:
354
+ - Use for: Exploration, review, coordination, operational tasks
355
+ - Agents: code-reviewer, architecture-explorer, database-navigator, git-workflow-manager, devops-sre, brainstorm-coordinator, context-manager
356
+ - Cost: Moderate, good for frequent use
357
+
358
+ **Haiku (Quick)**:
359
+ - Use for: Fast tasks, summaries, lightweight operations
360
+ - Agents: session-summarizer, agent-developer
361
+ - Cost: Low, use for simple tasks
362
+
363
+ ---
364
+
365
+ ## Anti-Patterns
366
+
367
+ ### Don't Do This:
368
+
369
+ ❌ **Use Task/Explore agent for dependency queries**
370
+ - **Problem**: Slow, incomplete, can't detect circular dependencies
371
+ - **Instead**: Use `query-deps` tool
372
+
373
+ ❌ **Work on complex bugs without error-detective**
374
+ - **Problem**: Guessing causes, wasting time, treating symptoms
375
+ - **Instead**: Get RCA first, then fix root cause
376
+
377
+ ❌ **Refactor without refactoring-specialist**
378
+ - **Problem**: Break things, introduce bugs, unsafe changes
379
+ - **Instead**: Get plan, ensure safe incremental changes
380
+
381
+ ❌ **Commit without code-reviewer**
382
+ - **Problem**: Bugs ship to production
383
+ - **Instead**: Catch bugs before they're committed
384
+
385
+ ❌ **Spawn agents sequentially when they can run in parallel**
386
+ - **Problem**: Wastes time, inefficient
387
+ - **Instead**: Single message, multiple Task calls
388
+
389
+ ---
390
+
391
+ ## Decision Matrix
392
+
393
+ | Task Type | Direct Work | Single Agent | Multiple Agents (Parallel) |
394
+ |-----------|-------------|--------------|----------------------------|
395
+ | Simple edit (<3 files) | ✅ | ❌ | ❌ |
396
+ | Bug with clear cause | ✅ | ❌ | ❌ |
397
+ | Bug with unclear cause | ❌ | ✅ error-detective | ❌ |
398
+ | Complex bug (multiple theories) | ❌ | ❌ | ✅ error-detective + debugger + architecture-explorer |
399
+ | Code review | ❌ | ✅ code-reviewer | ❌ |
400
+ | Architecture question | ❌ | ✅ architecture-explorer | ❌ |
401
+ | Multi-file refactoring | ❌ | ❌ | ✅ refactoring-specialist + code-reviewer + impact-analysis |
402
+ | Design decision | ❌ | ❌ | ✅ brainstorm-coordinator (spawns specialists) |
403
+
404
+ ---
405
+
406
+ ## Usage Examples
407
+
408
+ ### Example 1: Simple Debugging (Single Agent)
409
+
410
+ ```
411
+ User: "Getting TypeError: Cannot read property 'name' of undefined"
412
+
413
+ # Clear error, likely simple null check issue
414
+ Task(
415
+ subagent_type="error-detective",
416
+ description="RCA for TypeError",
417
+ prompt="Analyze TypeError in user.name access - likely null/undefined user object"
418
+ )
419
+
420
+ # error-detective returns:
421
+ # Root Cause: Missing null check
422
+ # Fix: Add validation before property access
423
+ # Confidence: 90%
424
+
425
+ # Apply fix directly (no need for debugger)
426
+ ```
427
+
428
+ ---
429
+
430
+ ### Example 2: Complex Debugging (Parallel Agents)
431
+
432
+ ```
433
+ User: "Application crashes on startup, no error message"
434
+
435
+ # Complex, multiple potential causes
436
+ # Spawn 3 agents in PARALLEL (single message):
437
+
438
+ Task(
439
+ subagent_type="error-detective",
440
+ description="RCA for startup crash",
441
+ prompt="Application exits on startup with no error. Investigate dependency issues, env vars, database connection"
442
+ )
443
+
444
+ Task(
445
+ subagent_type="devops-sre",
446
+ description="Check production environment",
447
+ prompt="Verify environment variables, service health, resource availability"
448
+ )
449
+
450
+ Task(
451
+ subagent_type="database-navigator",
452
+ description="Check database connectivity",
453
+ prompt="Verify database connection, migrations, schema state"
454
+ )
455
+
456
+ # All 3 run simultaneously
457
+ # Synthesize findings: Database connection timeout (env var missing)
458
+ ```
459
+
460
+ ---
461
+
462
+ ### Example 3: Pre-Refactor Analysis (Parallel Agents)
463
+
464
+ ```
465
+ User: "Refactor the authentication module"
466
+
467
+ # Spawn 3 agents in PARALLEL:
468
+
469
+ Task(
470
+ subagent_type="refactoring-specialist",
471
+ description="Plan auth module refactor",
472
+ prompt="Create safe refactoring plan for authentication module"
473
+ )
474
+
475
+ Task(
476
+ subagent_type="code-reviewer",
477
+ description="Identify code smells",
478
+ prompt="Review auth module for code quality issues"
479
+ )
480
+
481
+ Task(
482
+ subagent_type="security-engineer",
483
+ description="Security review",
484
+ prompt="Review auth module for security vulnerabilities"
485
+ )
486
+
487
+ # Synthesize:
488
+ # - Refactoring plan (step-by-step)
489
+ # - Known issues to fix during refactor
490
+ # - Security considerations to maintain
491
+ ```
492
+
493
+ ---
494
+
495
+ ### Example 4: Architecture Understanding (Single Agent)
496
+
497
+ ```
498
+ User: "How does the SSE streaming work?"
499
+
500
+ Task(
501
+ subagent_type="architecture-explorer",
502
+ description="Understand SSE streaming architecture",
503
+ prompt="Explore and explain how Server-Sent Events streaming is implemented"
504
+ )
505
+
506
+ # architecture-explorer investigates:
507
+ # - SSE endpoint setup
508
+ # - Event emitter pattern
509
+ # - Client connection management
510
+ # - Data flow from backend to frontend
511
+ ```
512
+
513
+ ---
514
+
515
+ ### Example 5: Design Decision (Meta-Agent)
516
+
517
+ ```
518
+ User: "Should we use REST or GraphQL for the new API?"
519
+
520
+ Task(
521
+ subagent_type="brainstorm-coordinator",
522
+ description="Analyze API design decision",
523
+ prompt="""
524
+ Analyze trade-offs between REST and GraphQL for new API.
525
+
526
+ Context:
527
+ - Mobile app + web frontend
528
+ - Complex data relationships
529
+ - Team has REST experience
530
+
531
+ Perspectives needed:
532
+ - Technical architecture
533
+ - Developer experience
534
+ - Operational complexity
535
+ """
536
+ )
537
+
538
+ # brainstorm-coordinator spawns specialists:
539
+ # - system-architect (technical trade-offs)
540
+ # - product-dx-specialist (developer experience)
541
+ # - devops-sre (operational concerns)
542
+
543
+ # Then synthesizes unified recommendation
544
+ ```
545
+
546
+ ---
547
+
548
+ ## Agent Coordination Patterns
549
+
550
+ ### Pattern 1: Sequential (Dependent Tasks)
551
+
552
+ ```
553
+ # Phase 1: Get RCA
554
+ Task(subagent_type="error-detective", prompt="RCA for error")
555
+
556
+ # Wait for result
557
+
558
+ # Phase 2: Apply fix based on RCA
559
+ [Apply fix]
560
+
561
+ # Phase 3: Verify fix
562
+ Task(subagent_type="code-reviewer", prompt="Review fix")
563
+ ```
564
+
565
+ **Use when**: Later steps depend on earlier results
566
+
567
+ ---
568
+
569
+ ### Pattern 2: Parallel (Independent Tasks)
570
+
571
+ ```
572
+ # Single message with 3 Task calls:
573
+ Task(subagent_type="architecture-explorer", prompt="Understand module A")
574
+ Task(subagent_type="database-navigator", prompt="Understand schema B")
575
+ Task(subagent_type="code-reviewer", prompt="Review patterns C")
576
+
577
+ # All run simultaneously
578
+ # Synthesize findings after all complete
579
+ ```
580
+
581
+ **Use when**: Tasks are independent, no shared dependencies
582
+
583
+ ---
584
+
585
+ ### Pattern 3: Breadth-First (Comprehensive Coverage)
586
+
587
+ ```
588
+ # Spawn many agents to cover all aspects:
589
+ Task(subagent_type="architecture-explorer", ...)
590
+ Task(subagent_type="database-navigator", ...)
591
+ Task(subagent_type="security-engineer", ...)
592
+ Task(subagent_type="code-reviewer", ...)
593
+ Task(subagent_type="devops-sre", ...)
594
+
595
+ # Use for: New codebase exploration, comprehensive audits
596
+ ```
597
+
598
+ **Use when**: Need complete understanding from all angles
599
+
600
+ ---
601
+
602
+ ### Pattern 4: Meta-Coordination
603
+
604
+ ```
605
+ # Delegate to brainstorm-coordinator
606
+ Task(
607
+ subagent_type="brainstorm-coordinator",
608
+ prompt="Coordinate analysis of [complex decision]"
609
+ )
610
+
611
+ # brainstorm-coordinator handles:
612
+ # - Selecting relevant specialists
613
+ # - Spawning them in parallel
614
+ # - Synthesizing perspectives
615
+ ```
616
+
617
+ **Use when**: Multiple perspectives needed, you're not sure which specialists
618
+
619
+ ---
620
+
621
+ ## Proactive Agent Markers
622
+
623
+ Some agents should be used PROACTIVELY (without explicit user request):
624
+
625
+ | Agent | Proactive? | When to Use Proactively |
626
+ |-------|------------|-------------------------|
627
+ | architecture-explorer | ✅ YES | User asks "how does X work?" |
628
+ | database-navigator | ✅ YES | User mentions database/schema |
629
+ | agent-developer | NO | Only when explicitly developing agents |
630
+ | code-reviewer | NO | User must request review |
631
+
632
+ **Proactive = Use without being asked** (when context matches)
633
+
634
+ ---
635
+
636
+ ## Success Criteria
637
+
638
+ ### Correct Agent Usage
639
+
640
+ ✅ Right agent for task category (debugging → error-detective)
641
+ ✅ Parallel spawning used when appropriate (independent tasks)
642
+ ✅ Proactive agents used without explicit request (architecture-explorer)
643
+ ✅ Results synthesized (don't just pass agent output to user)
644
+ ✅ Findings persisted (captured automatically by Capsule hooks)
645
+
646
+ ### Quality Signals
647
+
648
+ - **Efficiency**: Agents used for deep work, not simple tasks
649
+ - **Coverage**: Multiple perspectives for complex decisions
650
+ - **Speed**: Parallel execution, not sequential
651
+ - **Persistence**: Agent findings captured automatically by Capsule
652
+
653
+ ---
654
+
655
+ **Remember**: Agents have FRESH context. Delegate deep work to them, keep your own context for coordination and synthesis.