claude-code-orchestrator-kit 1.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 (130) hide show
  1. package/.claude/agents/database/workers/api-builder.md +155 -0
  2. package/.claude/agents/database/workers/database-architect.md +193 -0
  3. package/.claude/agents/database/workers/supabase-auditor.md +1070 -0
  4. package/.claude/agents/development/workers/code-reviewer.md +968 -0
  5. package/.claude/agents/development/workers/cost-calculator-specialist.md +683 -0
  6. package/.claude/agents/development/workers/llm-service-specialist.md +999 -0
  7. package/.claude/agents/development/workers/skill-builder-v2.md +480 -0
  8. package/.claude/agents/development/workers/typescript-types-specialist.md +649 -0
  9. package/.claude/agents/development/workers/utility-builder.md +582 -0
  10. package/.claude/agents/documentation/workers/technical-writer.md +152 -0
  11. package/.claude/agents/frontend/workers/fullstack-nextjs-specialist.md +206 -0
  12. package/.claude/agents/frontend/workers/visual-effects-creator.md +159 -0
  13. package/.claude/agents/health/orchestrators/bug-orchestrator.md +1045 -0
  14. package/.claude/agents/health/orchestrators/dead-code-orchestrator.md +1045 -0
  15. package/.claude/agents/health/orchestrators/dependency-orchestrator.md +1045 -0
  16. package/.claude/agents/health/orchestrators/security-orchestrator.md +1045 -0
  17. package/.claude/agents/health/workers/bug-fixer.md +525 -0
  18. package/.claude/agents/health/workers/bug-hunter.md +649 -0
  19. package/.claude/agents/health/workers/dead-code-hunter.md +446 -0
  20. package/.claude/agents/health/workers/dead-code-remover.md +437 -0
  21. package/.claude/agents/health/workers/dependency-auditor.md +379 -0
  22. package/.claude/agents/health/workers/dependency-updater.md +436 -0
  23. package/.claude/agents/health/workers/security-scanner.md +700 -0
  24. package/.claude/agents/health/workers/vulnerability-fixer.md +524 -0
  25. package/.claude/agents/infrastructure/workers/infrastructure-specialist.md +156 -0
  26. package/.claude/agents/infrastructure/workers/orchestration-logic-specialist.md +1260 -0
  27. package/.claude/agents/infrastructure/workers/qdrant-specialist.md +503 -0
  28. package/.claude/agents/infrastructure/workers/quality-validator-specialist.md +984 -0
  29. package/.claude/agents/meta/workers/meta-agent-v3.md +503 -0
  30. package/.claude/agents/research/workers/problem-investigator.md +507 -0
  31. package/.claude/agents/research/workers/research-specialist.md +423 -0
  32. package/.claude/agents/testing/workers/accessibility-tester.md +813 -0
  33. package/.claude/agents/testing/workers/integration-tester.md +188 -0
  34. package/.claude/agents/testing/workers/mobile-fixes-implementer.md +252 -0
  35. package/.claude/agents/testing/workers/mobile-responsiveness-tester.md +180 -0
  36. package/.claude/agents/testing/workers/performance-optimizer.md +262 -0
  37. package/.claude/agents/testing/workers/test-writer.md +800 -0
  38. package/.claude/commands/health-bugs.md +297 -0
  39. package/.claude/commands/health-cleanup.md +297 -0
  40. package/.claude/commands/health-deps.md +297 -0
  41. package/.claude/commands/health-metrics.md +747 -0
  42. package/.claude/commands/health-security.md +297 -0
  43. package/.claude/commands/push.md +21 -0
  44. package/.claude/commands/speckit.analyze.md +184 -0
  45. package/.claude/commands/speckit.checklist.md +294 -0
  46. package/.claude/commands/speckit.clarify.md +178 -0
  47. package/.claude/commands/speckit.constitution.md +78 -0
  48. package/.claude/commands/speckit.implement.md +182 -0
  49. package/.claude/commands/speckit.plan.md +87 -0
  50. package/.claude/commands/speckit.specify.md +250 -0
  51. package/.claude/commands/speckit.tasks.md +137 -0
  52. package/.claude/commands/translate-doc.md +95 -0
  53. package/.claude/commands/worktree-cleanup.md +382 -0
  54. package/.claude/commands/worktree-create.md +287 -0
  55. package/.claude/commands/worktree-list.md +239 -0
  56. package/.claude/commands/worktree-remove.md +339 -0
  57. package/.claude/schemas/base-plan.schema.json +82 -0
  58. package/.claude/schemas/bug-plan.schema.json +71 -0
  59. package/.claude/schemas/dead-code-plan.schema.json +71 -0
  60. package/.claude/schemas/dependency-plan.schema.json +74 -0
  61. package/.claude/schemas/security-plan.schema.json +71 -0
  62. package/.claude/scripts/gates/check-bundle-size.sh +47 -0
  63. package/.claude/scripts/gates/check-coverage.sh +67 -0
  64. package/.claude/scripts/gates/check-security.sh +46 -0
  65. package/.claude/scripts/release.sh +740 -0
  66. package/.claude/settings.local.json +21 -0
  67. package/.claude/settings.local.json.example +20 -0
  68. package/.claude/skills/calculate-priority-score/SKILL.md +229 -0
  69. package/.claude/skills/calculate-priority-score/scoring-matrix.json +83 -0
  70. package/.claude/skills/extract-version/SKILL.md +228 -0
  71. package/.claude/skills/format-commit-message/SKILL.md +189 -0
  72. package/.claude/skills/format-commit-message/template.md +64 -0
  73. package/.claude/skills/format-markdown-table/SKILL.md +202 -0
  74. package/.claude/skills/format-markdown-table/examples.md +84 -0
  75. package/.claude/skills/format-todo-list/SKILL.md +222 -0
  76. package/.claude/skills/format-todo-list/template.json +30 -0
  77. package/.claude/skills/generate-changelog/SKILL.md +258 -0
  78. package/.claude/skills/generate-changelog/commit-mapping.json +47 -0
  79. package/.claude/skills/generate-report-header/SKILL.md +228 -0
  80. package/.claude/skills/generate-report-header/template.md +66 -0
  81. package/.claude/skills/parse-error-logs/SKILL.md +286 -0
  82. package/.claude/skills/parse-error-logs/patterns.json +26 -0
  83. package/.claude/skills/parse-git-status/SKILL.md +164 -0
  84. package/.claude/skills/parse-package-json/SKILL.md +151 -0
  85. package/.claude/skills/parse-package-json/schema.json +43 -0
  86. package/.claude/skills/render-template/SKILL.md +245 -0
  87. package/.claude/skills/rollback-changes/SKILL.md +582 -0
  88. package/.claude/skills/rollback-changes/changes-log-schema.json +101 -0
  89. package/.claude/skills/run-quality-gate/SKILL.md +404 -0
  90. package/.claude/skills/run-quality-gate/gate-mappings.json +97 -0
  91. package/.claude/skills/validate-plan-file/SKILL.md +327 -0
  92. package/.claude/skills/validate-plan-file/schema.json +35 -0
  93. package/.claude/skills/validate-report-file/SKILL.md +256 -0
  94. package/.claude/skills/validate-report-file/schema.json +67 -0
  95. package/.env.example +49 -0
  96. package/.github/BRANCH_PROTECTION.md +137 -0
  97. package/.github/workflows/build.yml +70 -0
  98. package/.github/workflows/claude-code-review.yml +255 -0
  99. package/.github/workflows/claude.yml +79 -0
  100. package/.github/workflows/deploy-staging.yml +90 -0
  101. package/.github/workflows/test.yml +104 -0
  102. package/.gitignore +116 -0
  103. package/CLAUDE.md +137 -0
  104. package/LICENSE +72 -0
  105. package/README.md +1098 -0
  106. package/docs/ARCHITECTURE.md +746 -0
  107. package/docs/Agents Ecosystem/AGENT-ORCHESTRATION.md +568 -0
  108. package/docs/Agents Ecosystem/AI-AGENT-ECOSYSTEM-README.md +658 -0
  109. package/docs/Agents Ecosystem/ARCHITECTURE.md +606 -0
  110. package/docs/Agents Ecosystem/QUALITY-GATES-SPECIFICATION.md +1315 -0
  111. package/docs/Agents Ecosystem/REPORT-TEMPLATE-STANDARD.md +1324 -0
  112. package/docs/Agents Ecosystem/spec-kit-comprehensive-updates.md +478 -0
  113. package/docs/FAQ.md +572 -0
  114. package/docs/MIGRATION-GUIDE.md +542 -0
  115. package/docs/PERFORMANCE-OPTIMIZATION.md +494 -0
  116. package/docs/ROADMAP.md +439 -0
  117. package/docs/TUTORIAL-CUSTOM-AGENTS.md +2041 -0
  118. package/docs/USE-CASES.md +706 -0
  119. package/index.js +96 -0
  120. package/mcp/.mcp.base.json +21 -0
  121. package/mcp/.mcp.frontend.json +29 -0
  122. package/mcp/.mcp.full.json +67 -0
  123. package/mcp/.mcp.local.example.json +7 -0
  124. package/mcp/.mcp.local.json +7 -0
  125. package/mcp/.mcp.n8n.json +45 -0
  126. package/mcp/.mcp.supabase-full.json +35 -0
  127. package/mcp/.mcp.supabase-only.json +28 -0
  128. package/package.json +78 -0
  129. package/postinstall.js +71 -0
  130. package/switch-mcp.sh +101 -0
@@ -0,0 +1,606 @@
1
+ # AI Agents Architecture - Canonical Reference
2
+
3
+ **Version**: 2.0
4
+ **Last Updated**: 2025-10-18
5
+ **Status**: Canonical Reference for AI Agents
6
+ **Language**: English (for AI agents)
7
+ **Audience**: Claude Code and custom agents
8
+
9
+ ---
10
+
11
+ ## Executive Summary
12
+
13
+ This document defines the **canonical 2-level architecture** for AI agents in MegaCampus2. After Phase 2 refactoring, we use a simplified hierarchy:
14
+
15
+ ```
16
+ User → /health {domain} → Domain Orchestrator (L1)
17
+ → Hunter/Scanner → detection report
18
+ → Fixer/Updater (staged by priority) → fixes
19
+ → Hunter/Scanner (verification) → verification report
20
+ → (iterate if issues remain)
21
+ ```
22
+
23
+ ### Key Principles
24
+
25
+ 1. **Orchestrators coordinate, don't invoke** - Use Return Control pattern
26
+ 2. **2-level hierarchy** - Domain orchestrators are L1, workers are L2
27
+ 3. **Hunter+Fixer separation** - Context window preservation via staged execution
28
+ 4. **Iterative cycles** - Detection → Fixing → Verification → Repeat
29
+ 5. **Quality gates** - Validation checkpoints between phases
30
+ 6. **Plan files** - Structured communication (`.{domain}-{phase}-plan.json`)
31
+
32
+ ---
33
+
34
+ ## Core Concepts
35
+
36
+ ### What is an Agent?
37
+
38
+ An **agent** is a specialized AI assistant with:
39
+ - **Isolated context window** (prevents context pollution)
40
+ - **Specific domain expertise** (bugs, security, dead code, dependencies)
41
+ - **Defined inputs/outputs** (plan files → work → reports)
42
+ - **Independent tool access** (Bash, Read, Write, Edit, etc.)
43
+
44
+ **Location**: `.claude/agents/{domain}/{orchestrators|workers}/`
45
+
46
+ ### Agent Types
47
+
48
+ #### 1. Orchestrators (Level 1)
49
+
50
+ **Purpose**: Coordinate multi-phase workflows
51
+
52
+ **Responsibilities**:
53
+ - Create plan files for each phase
54
+ - Signal readiness to user (Return Control)
55
+ - Validate worker outputs at quality gates
56
+ - Track progress via TodoWrite
57
+ - Handle errors with rollback instructions
58
+ - Generate final summary reports
59
+
60
+ **CRITICAL RULES**:
61
+ - ❌ **NO Task tool** to invoke subagents
62
+ - ❌ **NO implementation work** (delegate to workers)
63
+ - ❌ **NO skip quality gate validations**
64
+ - ✅ **DO create plan files** before signaling
65
+ - ✅ **DO validate worker outputs** at quality gates
66
+ - ✅ **DO report status** to user
67
+
68
+ **Location**: `.claude/agents/health/orchestrators/`
69
+
70
+ **Examples**:
71
+ - `bug-orchestrator.md`
72
+ - `security-orchestrator.md`
73
+ - `dead-code-orchestrator.md`
74
+ - `dependency-orchestrator.md`
75
+
76
+ #### 2. Workers (Level 2)
77
+
78
+ **Purpose**: Execute domain-specific work
79
+
80
+ **Responsibilities**:
81
+ - Read plan file first
82
+ - Execute domain work (detection, fixing, verification)
83
+ - Validate work internally
84
+ - Generate structured report
85
+ - Return to main session
86
+
87
+ **CRITICAL RULES**:
88
+ - ❌ **NO invoke other agents**
89
+ - ❌ **NO skip report generation**
90
+ - ❌ **NO report success without validation**
91
+ - ✅ **DO read plan file** first
92
+ - ✅ **DO generate changes logs** (for rollback)
93
+ - ✅ **DO self-validate** work
94
+
95
+ **Location**: `.claude/agents/health/workers/`
96
+
97
+ **Examples**:
98
+ - `bug-hunter.md`, `bug-fixer.md`
99
+ - `security-scanner.md`, `vulnerability-fixer.md`
100
+ - `dead-code-hunter.md`, `dead-code-remover.md`
101
+ - `dependency-auditor.md`, `dependency-updater.md`
102
+
103
+ #### 3. Skills (Utilities)
104
+
105
+ **Purpose**: Reusable utility functions
106
+
107
+ **Characteristics**:
108
+ - Stateless (no context needed)
109
+ - <100 lines logic
110
+ - Single responsibility
111
+ - No agent invocation
112
+
113
+ **Location**: `.claude/skills/{skill-name}/SKILL.md`
114
+
115
+ **Examples**:
116
+ - `validate-plan-file`
117
+ - `run-quality-gate`
118
+ - `rollback-changes`
119
+ - `generate-report-header`
120
+
121
+ ---
122
+
123
+ ## Return Control Pattern
124
+
125
+ ### How It Works
126
+
127
+ ```mermaid
128
+ sequenceDiagram
129
+ participant User
130
+ participant Main as Main Claude Session
131
+ participant Orch as Orchestrator
132
+ participant Worker as Worker Agent
133
+
134
+ User->>Main: /health bugs
135
+ Main->>Orch: Invoke orchestrator via Task tool
136
+ Orch->>Orch: Create .bug-detection-plan.json
137
+ Orch->>Orch: Validate plan file
138
+ Orch->>Orch: Update TodoWrite (in_progress)
139
+ Orch->>User: Signal readiness, return control
140
+ Orch-->>Main: Exit orchestrator
141
+ Main->>Main: Read .bug-detection-plan.json
142
+ Main->>Worker: Invoke bug-hunter via Task tool
143
+ Worker->>Worker: Read plan file
144
+ Worker->>Worker: Execute detection
145
+ Worker->>Worker: Generate report
146
+ Worker-->>Main: Return control
147
+ Main->>Orch: Resume orchestrator via Task tool
148
+ Orch->>Orch: Validate report (quality gate)
149
+ Orch->>Orch: Create .bug-fixing-plan.json
150
+ Orch->>User: Signal readiness, return control
151
+ Orch-->>Main: Exit orchestrator
152
+ Main->>Main: Read .bug-fixing-plan.json
153
+ Main->>Worker: Invoke bug-fixer via Task tool
154
+ Note: Cycle continues...
155
+ ```
156
+
157
+ ### Signal Readiness Protocol
158
+
159
+ Orchestrators must:
160
+
161
+ 1. **Create plan file**:
162
+ ```json
163
+ {
164
+ "workflow": "bug-management",
165
+ "phase": "detection",
166
+ "config": { "priority": "all" },
167
+ "validation": {
168
+ "required": ["report-exists", "type-check"]
169
+ },
170
+ "nextAgent": "bug-hunter"
171
+ }
172
+ ```
173
+
174
+ 2. **Validate plan file** using `validate-plan-file` Skill
175
+
176
+ 3. **Update TodoWrite**:
177
+ ```json
178
+ {
179
+ "content": "Phase 1: Bug detection",
180
+ "status": "in_progress",
181
+ "activeForm": "Detecting bugs"
182
+ }
183
+ ```
184
+
185
+ 4. **Signal to user and return control**:
186
+ ```
187
+ ✅ Phase preparation complete!
188
+
189
+ Plan: .bug-detection-plan.json
190
+ Next Agent: bug-hunter
191
+
192
+ Returning control to main session.
193
+
194
+ Main session should:
195
+ 1. Read .bug-detection-plan.json
196
+ 2. Invoke bug-hunter via Task tool
197
+ 3. Resume orchestrator after worker completes
198
+ ```
199
+
200
+ 5. **Exit orchestrator** - Return control to main session (do NOT invoke workers)
201
+
202
+ ### Manual Worker Invocation Pattern
203
+
204
+ **IMPORTANT**: Claude Code does NOT have automatic agent invocation. The main session must explicitly invoke workers using the Task tool.
205
+
206
+ **Correct Pattern**:
207
+
208
+ 1. **Orchestrator** creates plan file (e.g., `.bug-detection-plan.json`) with `nextAgent` field
209
+ 2. **Orchestrator** reports readiness and exits, returning control to main session
210
+ 3. **Main session** (slash command or user) reads the plan file
211
+ 4. **Main session** explicitly invokes worker using Task tool:
212
+ ```
213
+ Use Task tool with:
214
+ - subagent_type: "{worker-name}" (from plan.nextAgent)
215
+ - prompt: "Execute work based on plan file: {plan-file-path}"
216
+ ```
217
+ 5. **Worker** reads plan file, executes work, generates report, returns control
218
+ 6. **Main session** resumes orchestrator for validation
219
+
220
+ **Worker Description Pattern** (unchanged):
221
+ ```markdown
222
+ description: Use proactively for {task}. Reads plan files with nextAgent='worker-name'.
223
+ ```
224
+
225
+ **NOTE**: "Use proactively" helps Claude understand when to use the agent, but does NOT trigger automatic invocation.
226
+
227
+ ---
228
+
229
+ ## Workflow Patterns
230
+
231
+ ### Pattern 1: Iterative Cycle (Bug, Security, Dead Code)
232
+
233
+ ```
234
+ Phase 1: Detection
235
+ ├─ Orchestrator creates detection plan
236
+ ├─ Hunter/Scanner executes → generates categorized report
237
+ └─ Orchestrator validates report
238
+
239
+ Phase 2: Fixing (Staged by Priority)
240
+ ├─ Orchestrator creates fixing plan (priority=critical)
241
+ ├─ Fixer executes critical fixes
242
+ ├─ Orchestrator validates (quality gate: type-check, build)
243
+ ├─ If issues remain at this priority, repeat
244
+ └─ Move to next priority (high → medium → low)
245
+
246
+ Phase 3: Verification
247
+ ├─ Orchestrator creates verification plan
248
+ ├─ Hunter/Scanner re-scans to verify fixes
249
+ └─ Orchestrator validates verification
250
+
251
+ Phase 4: Iteration Decision
252
+ ├─ If new issues found → back to Phase 2
253
+ ├─ If max iterations reached → stop
254
+ └─ If no issues → final summary
255
+
256
+ Phase 5: Final Summary
257
+ └─ Orchestrator generates comprehensive report
258
+ ```
259
+
260
+ ### Pattern 2: Sequential Update (Dependencies)
261
+
262
+ ```
263
+ Phase 1: Audit
264
+ ├─ Orchestrator creates audit plan
265
+ ├─ Auditor scans and categorizes
266
+ └─ Orchestrator validates report
267
+
268
+ Phase 2: Update (One-at-a-Time)
269
+ ├─ Orchestrator creates update plan (category=security, severity=critical)
270
+ ├─ Updater updates ONE dependency
271
+ ├─ Orchestrator validates (quality gate: lockfile-valid, build, tests)
272
+ ├─ If validation passes → update next dependency
273
+ └─ If validation fails → rollback, mark as problematic, continue
274
+
275
+ Phase 3: Verification
276
+ ├─ Orchestrator creates verification plan
277
+ ├─ Auditor re-scans
278
+ └─ Orchestrator generates final report
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Quality Gates
284
+
285
+ ### Gate Execution
286
+
287
+ Use `run-quality-gate` Skill:
288
+
289
+ ```markdown
290
+ ## Quality Gate: Type Check
291
+
292
+ Use run-quality-gate Skill:
293
+ - gate: "type-check"
294
+ - blocking: true
295
+
296
+ If action="stop":
297
+ ⛔ HALT workflow
298
+ Report errors to user
299
+ Suggest rollback or fix
300
+ Ask user: "Fix issues or skip validation? (fix/skip)"
301
+
302
+ If action="warn":
303
+ ⚠️ WARN user but continue
304
+ Log warnings in report
305
+
306
+ If action="continue":
307
+ ✅ PASSED - proceed to next phase
308
+ ```
309
+
310
+ ### Standard Gates
311
+
312
+ **Blocking** (must pass):
313
+ - `type-check`: pnpm type-check
314
+ - `build`: pnpm build
315
+ - `tests`: pnpm test (for critical changes)
316
+ - `lockfile-valid`: Ensure package-lock.json consistent
317
+ - `no-critical-vulns`: No critical security vulnerabilities
318
+
319
+ **Non-Blocking** (warnings only):
320
+ - `lint`: pnpm lint
321
+ - `bundle-size`: Check bundle size increase
322
+ - `performance`: Lighthouse CI scores
323
+
324
+ ### Custom Gates
325
+
326
+ ```markdown
327
+ Use run-quality-gate Skill:
328
+ - gate: "custom"
329
+ - blocking: false
330
+ - custom_command: "npm run lighthouse-ci"
331
+ ```
332
+
333
+ ---
334
+
335
+ ## Plan Files
336
+
337
+ ### Naming Convention
338
+
339
+ Pattern: `.{domain}-{phase}-plan.json`
340
+
341
+ **Examples**:
342
+ - `.bug-detection-plan.json`
343
+ - `.bug-fixing-plan.json`
344
+ - `.security-scan-plan.json`
345
+ - `.security-remediation-plan.json`
346
+ - `.dead-code-detection-plan.json`
347
+ - `.dependency-audit-plan.json`
348
+
349
+ ### Schema Validation
350
+
351
+ All plan files must conform to JSON schemas in `.claude/schemas/`:
352
+
353
+ - `base-plan.schema.json` - Base schema (all plans)
354
+ - `bug-plan.schema.json` - Bug management
355
+ - `security-plan.schema.json` - Security audit
356
+ - `dead-code-plan.schema.json` - Dead code cleanup
357
+ - `dependency-plan.schema.json` - Dependency management
358
+
359
+ **Validation**: Use `validate-plan-file` Skill after creating plan
360
+
361
+ ---
362
+
363
+ ## Changes Logging & Rollback
364
+
365
+ ### Changes Log Format
366
+
367
+ Location: `.{domain}-changes.json`
368
+
369
+ ```json
370
+ {
371
+ "phase": "bug-fixing",
372
+ "timestamp": "2025-10-18T14:30:00Z",
373
+ "files_modified": [
374
+ {
375
+ "path": "src/components/Button.tsx",
376
+ "backup": ".rollback/src-components-Button.tsx.backup"
377
+ }
378
+ ],
379
+ "files_created": ["src/utils/newHelper.ts"],
380
+ "commands_executed": ["pnpm install"]
381
+ }
382
+ ```
383
+
384
+ ### Rollback Procedure
385
+
386
+ Use `rollback-changes` Skill:
387
+
388
+ ```markdown
389
+ ## On Validation Failure
390
+
391
+ Use rollback-changes Skill:
392
+ - changes_log_path: ".bug-changes.json"
393
+ - phase: "bug-fixing"
394
+ - confirmation_required: true
395
+
396
+ Actions:
397
+ 1. Restore modified files from backups
398
+ 2. Delete created files
399
+ 3. Revert commands (git checkout, pnpm install)
400
+ 4. Remove artifacts (.plan.json, .lock files)
401
+ 5. Generate rollback report
402
+ ```
403
+
404
+ ---
405
+
406
+ ## Report Files
407
+
408
+ ### Standard Format
409
+
410
+ Follow `REPORT-TEMPLATE-STANDARD.md`:
411
+
412
+ **Sections**:
413
+ 1. Header: Report type, timestamp, status
414
+ 2. Executive Summary: Key metrics, validation status
415
+ 3. Detailed Findings: Changes, issues, actions
416
+ 4. Validation Results: ✅/⛔/⚠️ for each gate
417
+ 5. Next Steps: Recommendations
418
+
419
+ ### File Organization
420
+
421
+ #### Temporary Files
422
+
423
+ All orchestration state files stored in `.tmp/`:
424
+
425
+ **Why `.tmp/`?**
426
+ - ✅ Centralized location for all temporary files
427
+ - ✅ Easy to add to .gitignore
428
+ - ✅ Clear separation from source code
429
+ - ✅ Follows Unix conventions (tmp/ for temporary data)
430
+ - ✅ Easy cleanup: `rm -rf .tmp/*`
431
+
432
+ **Structure**:
433
+ ```
434
+ .tmp/
435
+ ├── current/ # Active run (read/write)
436
+ │ ├── plans/ # Plan files for workers
437
+ │ ├── changes/ # Changes logs for rollback
438
+ │ ├── backups/ # File backups (.rollback/)
439
+ │ └── locks/ # Lock files for conflict prevention
440
+ └── archive/ # Historical runs (read-only, auto-cleanup)
441
+ └── YYYY-MM-DD-HHMMSS/
442
+ ├── plans/
443
+ ├── changes/
444
+ └── reports/
445
+ ```
446
+
447
+ **Lifecycle**:
448
+ 1. Pre-flight creates `current/` directories
449
+ 2. Workers read/write to `current/`
450
+ 3. Final summary archives `current/` → `archive/{timestamp}/`
451
+ 4. Auto-cleanup removes `archive/` entries > 7 days
452
+
453
+ #### Permanent Files
454
+
455
+ Reports archived to `docs/reports/{domain}/{YYYY-MM}/`:
456
+ - Timestamped for versioning
457
+ - Git committed for history
458
+ - Organized by domain and month
459
+
460
+ **Examples**:
461
+ - `docs/reports/bugs/2025-10/2025-10-19-bug-hunting-report.md`
462
+ - `docs/reports/security/2025-10/2025-10-19-security-audit.md`
463
+ - `docs/reports/summaries/2025-10-19-health-summary.md`
464
+
465
+ ---
466
+
467
+ ## Conflict Avoidance
468
+
469
+ ### Sequential Phases Locking
470
+
471
+ **Strategy**: Hunter phases can run in parallel (read-only), fixer phases must run sequentially (write operations).
472
+
473
+ **Implementation**:
474
+
475
+ ```markdown
476
+ ## Before Starting Fixer Phase
477
+
478
+ 1. Check for `.active-fixer.lock` file
479
+ 2. If lock exists:
480
+ - Read lock file
481
+ - Check if expired (>30 minutes old)
482
+ - If not expired: wait or fail
483
+ 3. If no lock or expired:
484
+ - Create lock file:
485
+ {
486
+ "domain": "bugs",
487
+ "started": "2025-10-18T14:30:00Z",
488
+ "pid": "bug-orchestrator-instance-abc123"
489
+ }
490
+ 4. Execute fixer phase
491
+ 5. Remove lock file on completion or failure
492
+ ```
493
+
494
+ **Lock Location**: `.tmp/current/locks/` (auto-cleanup on expiry)
495
+
496
+ ---
497
+
498
+ ## Best Practices
499
+
500
+ ### For Orchestrators
501
+
502
+ 1. **Always validate plan files** after creation
503
+ 2. **Track progress** with TodoWrite (mark phases in_progress → completed immediately)
504
+ 3. **Enforce quality gates** - don't skip validations
505
+ 4. **Limit iterations** - max 3 cycles to prevent infinite loops
506
+ 5. **Generate comprehensive reports** with all phases summarized
507
+ 6. **Handle errors gracefully** with rollback instructions
508
+
509
+ ### For Workers
510
+
511
+ 1. **Always read plan file first** - don't assume config
512
+ 2. **Log all changes** for rollback capability
513
+ 3. **Self-validate** before reporting success
514
+ 4. **Generate structured reports** following standard format
515
+ 5. **Use MCP servers** when specified in policy
516
+ 6. **Return control** after completing work
517
+
518
+ ### For Skills
519
+
520
+ 1. **Keep stateless** - no context dependencies
521
+ 2. **Single responsibility** - one clear purpose
522
+ 3. **Document thoroughly** - include examples
523
+ 4. **Handle errors** - return structured error info
524
+ 5. **Version schemas** - use JSON Schema for inputs/outputs
525
+
526
+ ---
527
+
528
+ ## Common Pitfalls
529
+
530
+ ### ❌ Orchestrator Using Task Tool
531
+
532
+ **Problem**: Orchestrator tries to invoke subagents directly
533
+ **Solution**: Remove Task tool usage, use Return Control pattern
534
+
535
+ ### ❌ Skipping Plan Validation
536
+
537
+ **Problem**: Invalid plan causes worker failure
538
+ **Solution**: Always use `validate-plan-file` Skill after creating plan
539
+
540
+ ### ❌ Missing Changes Logging
541
+
542
+ **Problem**: Can't rollback on validation failure
543
+ **Solution**: Workers must log all file modifications to changes log
544
+
545
+ ### ❌ Infinite Iteration Loops
546
+
547
+ **Problem**: Orchestrator keeps retrying without termination
548
+ **Solution**: Set max iterations (typically 3) and track progress
549
+
550
+ ### ❌ Blocking Without User Prompt
551
+
552
+ **Problem**: Orchestrator blocks on failure without user interaction
553
+ **Solution**: Report failure, provide options (fix/skip), wait for user decision
554
+
555
+ ---
556
+
557
+ ## MCP Server Usage Policy
558
+
559
+ ### Two-Tier Configuration
560
+
561
+ **Minimal (`.mcp.json`)**: context7, server-sequential-thinking
562
+ **Full (`.mcp.full.json`)**: Above + playwright, supabase, n8n-mcp, shadcn
563
+
564
+ **Token savings**: ~600-3000 tokens/conversation with minimal config
565
+
566
+ ### Worker Requirements
567
+
568
+ **bug-hunter**:
569
+ - MUST use Context7 (validate patterns before flagging bugs)
570
+ - Use `gh` CLI via Bash (not MCP)
571
+
572
+ **security-scanner**:
573
+ - MUST use Context7 (security best practices)
574
+ - Supabase MCP: only if `.mcp.full.json` active
575
+
576
+ **dependency-auditor**:
577
+ - Use npm audit (standard tool)
578
+ - Use `gh` CLI via Bash
579
+
580
+ ### Fallback Strategy
581
+
582
+ If MCP unavailable:
583
+ 1. Log warning in report
584
+ 2. Continue with reduced functionality
585
+ 3. Mark findings as "requires MCP verification"
586
+
587
+ ### Design Rationale
588
+
589
+ Architecture follows Anthropic multi-agent research patterns:
590
+ - Lead-subagent hierarchy → Orchestrator-Worker (L1-L2)
591
+ - Parallel execution → Hunters run concurrently
592
+ - Iterative refinement → Max 3 cycles with verification
593
+ - Structured communication → Plan files + Reports
594
+
595
+ **Key adaptation**: Return Control Pattern vs direct spawning (CLI constraints)
596
+
597
+ **Source**: https://www.anthropic.com/engineering/multi-agent-research-system
598
+
599
+ ---
600
+
601
+ ## References
602
+
603
+ - **Skills Guide**: `SKILLS-GUIDE.md`
604
+ - **Quality Gates**: `QUALITY-GATES-SPEC.md`
605
+ - **Report Template**: `REPORT-TEMPLATE-STANDARD.md`
606
+ - **CLAUDE.md**: Project-wide orchestration rules