maestro-flow 0.4.2 → 0.4.3

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 (80) hide show
  1. package/.claude/commands/maestro-analyze.md +1 -1
  2. package/.claude/commands/maestro-brainstorm.md +1 -1
  3. package/.claude/commands/maestro-collab.md +1 -1
  4. package/.claude/commands/maestro-execute.md +10 -1
  5. package/.claude/commands/maestro-guard.md +101 -0
  6. package/.claude/commands/maestro-impeccable.md +1 -1
  7. package/.claude/commands/maestro-plan.md +15 -2
  8. package/.claude/commands/maestro-ralph-execute.md +9 -2
  9. package/.claude/commands/maestro-ralph.md +8 -1
  10. package/.claude/commands/maestro-verify.md +15 -1
  11. package/.claude/commands/quality-auto-test.md +1 -1
  12. package/.claude/commands/quality-debug.md +1 -1
  13. package/.claude/commands/quality-refactor.md +1 -1
  14. package/.claude/commands/quality-retrospective.md +1 -1
  15. package/.claude/commands/quality-review.md +15 -1
  16. package/.claude/commands/quality-test.md +1 -1
  17. package/.claude/commands/security-audit.md +154 -0
  18. package/.claude/skills/maestro-help/index/catalog.json +2 -0
  19. package/.codex/skills/maestro-analyze/SKILL.md +18 -1
  20. package/.codex/skills/maestro-brainstorm/SKILL.md +17 -4
  21. package/.codex/skills/maestro-collab/SKILL.md +7 -1
  22. package/.codex/skills/maestro-execute/SKILL.md +365 -348
  23. package/.codex/skills/maestro-guard/SKILL.md +97 -0
  24. package/.codex/skills/maestro-impeccable/SKILL.md +1 -1
  25. package/.codex/skills/maestro-plan/SKILL.md +66 -7
  26. package/.codex/skills/maestro-ralph/SKILL.md +1 -1
  27. package/.codex/skills/maestro-verify/SKILL.md +18 -1
  28. package/.codex/skills/quality-auto-test/SKILL.md +13 -3
  29. package/.codex/skills/quality-debug/SKILL.md +362 -346
  30. package/.codex/skills/quality-refactor/SKILL.md +1 -1
  31. package/.codex/skills/quality-retrospective/SKILL.md +292 -292
  32. package/.codex/skills/quality-review/SKILL.md +374 -365
  33. package/.codex/skills/quality-test/SKILL.md +1 -1
  34. package/.codex/skills/security-audit/SKILL.md +154 -0
  35. package/bin/maestro-hook-runner.js +21 -1
  36. package/dashboard/dist-server/src/coordinator/output-parser.js +27 -0
  37. package/dashboard/dist-server/src/coordinator/output-parser.js.map +1 -1
  38. package/dist/src/commands/coordinate.d.ts.map +1 -1
  39. package/dist/src/commands/coordinate.js +2 -0
  40. package/dist/src/commands/coordinate.js.map +1 -1
  41. package/dist/src/commands/hooks.d.ts.map +1 -1
  42. package/dist/src/commands/hooks.js +39 -3
  43. package/dist/src/commands/hooks.js.map +1 -1
  44. package/dist/src/coordinator/output-parser.d.ts.map +1 -1
  45. package/dist/src/coordinator/output-parser.js +27 -0
  46. package/dist/src/coordinator/output-parser.js.map +1 -1
  47. package/dist/src/hooks/delegate-monitor.d.ts +1 -0
  48. package/dist/src/hooks/delegate-monitor.d.ts.map +1 -1
  49. package/dist/src/hooks/delegate-monitor.js +1 -1
  50. package/dist/src/hooks/delegate-monitor.js.map +1 -1
  51. package/dist/src/hooks/guards/workflow-guard.d.ts +15 -0
  52. package/dist/src/hooks/guards/workflow-guard.d.ts.map +1 -1
  53. package/dist/src/hooks/guards/workflow-guard.js +61 -1
  54. package/dist/src/hooks/guards/workflow-guard.js.map +1 -1
  55. package/dist/src/hooks/plugins/decision-log-plugin.d.ts +19 -0
  56. package/dist/src/hooks/plugins/decision-log-plugin.d.ts.map +1 -0
  57. package/dist/src/hooks/plugins/decision-log-plugin.js +28 -0
  58. package/dist/src/hooks/plugins/decision-log-plugin.js.map +1 -0
  59. package/dist/src/hooks/plugins/index.d.ts +2 -0
  60. package/dist/src/hooks/plugins/index.d.ts.map +1 -1
  61. package/dist/src/hooks/plugins/index.js +1 -0
  62. package/dist/src/hooks/plugins/index.js.map +1 -1
  63. package/dist/src/hooks/session-context.d.ts +1 -0
  64. package/dist/src/hooks/session-context.d.ts.map +1 -1
  65. package/dist/src/hooks/session-context.js +1 -1
  66. package/dist/src/hooks/session-context.js.map +1 -1
  67. package/dist/src/hooks/skill-context.d.ts +1 -0
  68. package/dist/src/hooks/skill-context.d.ts.map +1 -1
  69. package/dist/src/hooks/skill-context.js +1 -1
  70. package/dist/src/hooks/skill-context.js.map +1 -1
  71. package/dist/src/hooks/spec-injector.d.ts.map +1 -1
  72. package/dist/src/hooks/spec-injector.js +2 -0
  73. package/dist/src/hooks/spec-injector.js.map +1 -1
  74. package/package.json +1 -1
  75. package/workflows/debug.md +73 -0
  76. package/workflows/execute.md +27 -0
  77. package/workflows/plan.md +11 -0
  78. package/workflows/review.md +33 -1
  79. package/workflows/tdd.md +257 -0
  80. package/workflows/verify.md +57 -0
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: quality-refactor
3
- description: Reduce tech debt with reflection-driven iteration
3
+ description: Use when accumulated tech debt needs systematic identification and safe reduction
4
4
  argument-hint: "<phase|--dir path> [--max-iterations N]"
5
5
  allowed-tools: spawn_agents_on_csv, Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
6
6
  ---
@@ -1,292 +1,292 @@
1
- ---
2
- name: quality-retrospective
3
- description: Phase retrospective with insight routing to specs and lessons
4
- argument-hint: "[phase|N..M] [--lens technical|process|quality|decision] [--all] [--no-route] [--compare N] [-y]"
5
- allowed-tools: Read, Write, Edit, Bash, Glob, Grep
6
- ---
7
-
8
- <purpose>
9
- Multi-lens retrospective for completed phases. Context-Agent Fork loads phase artifacts once;
10
- four parallel lens agents (technical, process, quality, decision) analyze independently;
11
- synthesizer distills insights; outputs are routed to spec stubs, knowhow tips, issues, and specs/learnings.md.
12
-
13
- ```
14
- +------------------------------------------------------------------+
15
- | quality-retrospective -- Context-Agent Fork + Parallel Fan-out |
16
- +------------------------------------------------------------------+
17
-
18
- Stage 1-3: Read-only resolution (no writes)
19
- +---------------------------------------------+
20
- | Parse mode -> Validate artifacts |
21
- | -> [scan] Find unreviewed phases |
22
- +----------------------+-----------------------+
23
- |
24
- Stage 4: Context-Agent Fork (Pattern 2.10)
25
- +----------------------------------------------------------------+
26
- | spawn ctx (fork_turns: "none") |
27
- | wait ctx |
28
- | +----------+ +----------+ +----------+ +----------+ |
29
- | |lens-tech | |lens-proc | |lens-qual | |lens-dec | |
30
- | |fork=true | |fork=true | |fork=true | |fork=true | |
31
- | +----------+ +----------+ +----------+ +----------+ |
32
- | wait_agent([lens-tech, lens-proc, lens-qual, lens-dec]) |
33
- | close lenses -> close ctx LAST |
34
- +----------------------+-----------------------------------------+
35
- | lens results
36
- Stage 5: Synthesizer
37
- +------------------------------------------+
38
- | spawn synthesizer (fork_turns: "none") |
39
- | -> wait -> close |
40
- +----------------------+-------------------+
41
- | distilled_insights
42
- Stage 6-8: Route -> Write -> Report
43
- ```
44
- </purpose>
45
-
46
- <context>
47
- ```bash
48
- $quality-retrospective
49
- $quality-retrospective "3"
50
- $quality-retrospective "2..4"
51
- $quality-retrospective "--all"
52
- $quality-retrospective "3 --lens technical --no-route"
53
- $quality-retrospective "3 --compare 2 -y"
54
- ```
55
-
56
- **Flags**:
57
- - No phase argument -> `scan` mode: report unreviewed completed phases, prompt selection
58
- - `<N>` -> `single` mode: retrospect phase N
59
- - `<N>..<M>` -> `range` mode: retrospect phases N through M (inclusive)
60
- - `--all` -> batch mode: re-run for every completed phase
61
- - `--lens <name>` -- restrict to one lens (repeatable): `technical|process|quality|decision`
62
- - `--no-route` -- produce retrospective.{md,json} only; skip auto-creation of spec/note/issue
63
- - `--compare <M>` -- emit a delta section vs phase M's prior retrospective
64
- - `-y` -- accept all routing recommendations without prompting
65
-
66
- When `-y`: Accept all routing recommendations without prompting. Route all insights automatically.
67
-
68
- **Storage written**:
69
- - `{target_dir}/retrospective.md` -- human-readable record (target_dir resolved via state.json artifact registry to `.workflow/scratch/{YYYYMMDD}-{type}-{slug}/`)
70
- - `{target_dir}/retrospective.json` -- structured record
71
- - `.workflow/specs/{category-file}.md` -- `<spec-entry>` entries appended to matching category files (one per spec-routed insight)
72
- - `.workflow/issues/issues.jsonl` -- appended issue rows (`source: "retrospective"`)
73
- - `.workflow/knowhow/TIP-*.md` -- knowhow tips (via `manage-knowhow-capture` skill)
74
- - `.workflow/specs/learnings.md` -- append-only insight log
75
- - Index auto-maintained by WikiIndexer
76
-
77
- **Storage read (never modified)** — all resolved via `state.json.artifacts[]`:
78
- ```
79
- related = artifacts.filter(a =>
80
- a.phase === target_phase && a.milestone === current_milestone
81
- ).sort_by(completed_at asc)
82
- ```
83
- Each artifact's type determines its outputs at `.workflow/{a.path}/`:
84
- - **execute** → index.json, plan.json, .task/TASK-*.json, .summaries/TASK-*-summary.md
85
- - **verify** → verification.json
86
- - **review** → review.json (findings, verdict, severity distribution)
87
- - **debug** → understanding.md, evidence.ndjson (root causes, fix directions)
88
- - **test** → uat.md, .tests/ (UAT results, gaps, coverage)
89
- - Also reads: `.workflow/issues/issues.jsonl`, `.workflow/state.json`
90
-
91
- ### Agent Registry
92
-
93
- | Agent | task_name | fork_turns | Responsibility |
94
- |-------|-----------|------------|----------------|
95
- | Context Agent | `ctx` | "none" | Load all phase artifacts: index.json, plan.json, verification.json, review.json, uat.md, issues.jsonl, task summaries |
96
- | Technical Lens | `lens-tech` | "all" | Technical debt, architecture decisions, code quality gaps, performance issues |
97
- | Process Lens | `lens-proc` | "all" | Workflow efficiency, collaboration patterns, planning accuracy, bottlenecks |
98
- | Quality Lens | `lens-qual` | "all" | Test coverage gaps, verification failures, UAT issues, quality gate outcomes |
99
- | Decision Lens | `lens-dec` | "all" | Key decisions made, tradeoffs accepted, ADR candidates, reversibility |
100
- | Synthesizer | `synthesizer` | "none" | Merge lens results, deduplicate insights, classify routing targets |
101
-
102
- ### Fork Turns Strategy
103
-
104
- | Agent | task_name | fork_turns | fork_from | Rationale |
105
- |-------|-----------|------------|-----------|-----------|
106
- | Context Agent | `ctx` | "none" | -- | Independent artifact loader; clean start |
107
- | Technical Lens | `lens-tech` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
108
- | Process Lens | `lens-proc` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
109
- | Quality Lens | `lens-qual` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
110
- | Decision Lens | `lens-dec` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
111
- | Synthesizer | `synthesizer` | "none" | -- | Clean context; receives lens results via message |
112
-
113
- **Context-Agent Lifecycle**: Spawn `ctx` first -> `wait_agent` -> spawn all lens agents (`fork_turns: "all"`) -> `wait_agent` batch for lenses -> `close_agent` lenses -> `close_agent ctx` LAST.
114
-
115
- > **fork_turns semantics**: `fork_turns: "all"` means the spawned agent inherits the *orchestrator's* current conversation context -- not the ctx agent's own context. When `wait_agent` for ctx returns, the ctx agent's completed artifact summaries are visible in the orchestrator's context. Lens agents forked after that point therefore inherit those summaries. Lens agents do **not** fork directly from `ctx`; the `fork_from: ctx` column above is conceptual shorthand for this sequencing.
116
- </context>
117
-
118
- <invariants>
119
- 1. **Read-only until Stage 6**: Stages 1-5 must not write any files -- only read and analyze
120
- 2. **Context-agent spawns first**: `ctx` must complete before any lens agent is spawned
121
- 3. **Parallel lens dispatch**: All active lens agents spawned in a single batch, then `wait_agent` for all together -- never sequentially
122
- 4. **Context-agent closes last**: Close all lens agents before closing `ctx`
123
- 5. **Synthesizer is isolated**: `fork_turns: "none"` -- receives lens results only via message, not full conversation history
124
- 6. **Stable INS-ids**: `INS-{8hex}` from `hash(phase_num + lens + title)` -- re-runs do not create duplicates
125
- 7. **Archive before overwrite**: Move existing retrospective.{md,json} to `.history/` with timestamp before writing new ones
126
- 8. **Spec learnings.md backward-compat**: Append to it only if it already exists -- never create it
127
- 9. **Route confirmation**: Unless `-y`, present routing table and ask per-group before writing spec/issue/knowhow
128
- 10. **Lessons always written**: Append to `specs/learnings.md` regardless of `--no-route` -- routing only controls spec/issue/knowhow creation
129
- </invariants>
130
-
131
- <execution>
132
-
133
- ### Session Initialization
134
-
135
- Update plan: Stages 1-3 → in_progress; Stages 4-8 → pending.
136
-
137
- ### Stages 1-3: Parse Mode and Validate Artifacts
138
-
139
- **Stage 1: Parse mode** from `$ARGUMENTS`:
140
-
141
- | First non-flag token | Mode |
142
- |---------------------|------|
143
- | (empty) | scan |
144
- | `<N>` (single digit/number) | single |
145
- | `<N>..<M>` | range |
146
- | `--all` flag present | all |
147
-
148
- Validate `--lens` values. If `--compare <M>` present, require single mode.
149
-
150
- **Stage 2: Validate phase artifacts**. For each target phase:
151
- - Phase directory must exist (resolved via state.json artifact registry to `.workflow/scratch/{YYYYMMDD}-{type}-{slug}/`)
152
- - `index.json` must show `status: "completed"`
153
- - `.task/` directory must exist with at least one `TASK-*.json`
154
- - If existing `retrospective.json` found and not `--all`: emit W002, prompt overwrite
155
-
156
- **Stage 3: Scan mode** -- list all completed phases without retrospective.json. Prompt user to select.
157
-
158
- Update plan: Stages 1-3 → completed; Stage 4 → in_progress.
159
-
160
- ### Stage 4: Context-Agent Fork + Parallel Lens Analysis
161
-
162
- **Archive if overwriting**:
163
- If existing `retrospective.{md,json}` present, move to `{artifact_dir}/.history/` with timestamp suffix before spawning.
164
-
165
- **Step 4a: Spawn context agent**
166
- ```javascript
167
- spawn_agent({
168
- task_name: "ctx",
169
- fork_turns: "none",
170
- message: `Load and summarize all phase ${targetPhase} artifacts for retrospective.
171
- 1. Query state.json artifacts[] for phase === ${targetPhase} && milestone === current_milestone
172
- 2. Load per-artifact outputs (execute→index/plan/tasks/summaries, verify→verification.json, review→review.json, debug→understanding/evidence, test→uat/tests)
173
- 3. Filter issues.jsonl for this phase; read state.json for project context
174
- EXPECTED: Goals vs outcomes, completion rates, verification/review/UAT results, issue counts, key metrics`
175
- })
176
- wait_agent({ timeout_ms: 1800000 })
177
- ```
178
-
179
- **Step 4b: Fork 4 lens agents** (only active lenses based on `--lens` flag; default: all 4)
180
-
181
- All lenses use `fork_turns: "all"` and return the same JSON array schema:
182
- ```json
183
- [{ "title": "<80 chars>", "summary": "...", "category": "pattern|antipattern|decision|tool|gotcha|technique",
184
- "routing": "spec|issue|knowhow|none", "severity": "critical|high|medium|low", "evidence": "<file:line>" }]
185
- ```
186
-
187
- | Agent | task_name | Focus |
188
- |-------|-----------|-------|
189
- | Technical | `lens-tech` | Tech debt, architecture decisions, code quality, performance, security, dependencies |
190
- | Process | `lens-proc` | Planning accuracy, collaboration, workflow efficiency, communication, process improvements |
191
- | Quality | `lens-qual` | Test coverage gaps, quality gates, UAT failures, review blockers, missing scenarios |
192
- | Decision | `lens-dec` | Key decisions, tradeoffs, ADR candidates, reversibility, retrospective judgment |
193
-
194
- ```javascript
195
- // Spawn all 4 lenses in parallel
196
- ["lens-tech", "lens-proc", "lens-qual", "lens-dec"].forEach(name =>
197
- spawn_agent({ task_name: name, fork_turns: "all", message: `<lens-specific prompt>` })
198
- )
199
- const lensResults = wait_agent({ timeout_ms: 1800000 })
200
-
201
- // Close lenses first, then context agent LAST
202
- ["lens-tech", "lens-proc", "lens-qual", "lens-dec"].forEach(n => close_agent({ target: n }))
203
- close_agent({ target: "ctx" })
204
- ```
205
-
206
- If `lensResults.timed_out` for any agent: emit W001, continue with partial coverage.
207
-
208
- ### Stage 5: Synthesize Insights
209
-
210
- ```javascript
211
- spawn_agent({
212
- task_name: "synthesizer",
213
- fork_turns: "none",
214
- message: `Merge and distill insights from 4 lens analyses.
215
- Input: ${JSON.stringify(lensResults.status)}
216
- 1. Merge all insights, deduplicate (same issue across lenses → keep higher severity, combine evidence)
217
- 2. Generate stable INS-{8hex} id: hash(phase_num + lens + title)
218
- 3. Classify routing: spec | issue | knowhow | none
219
- 4. Produce phase-level metrics summary
220
- EXPECTED JSON: { insights: [{id,title,summary,category,lens,routing,severity,evidence}],
221
- metrics: {tasks_completed,tasks_failed,test_pass_rate,review_issues_count,uat_scenarios_passed},
222
- routing_summary: {spec:N, issue:N, knowhow:N, none:N} }`
223
- })
224
- const synthResult = wait_agent({ timeout_ms: 1800000 })
225
- close_agent({ target: "synthesizer" })
226
- ```
227
-
228
- Update plan: Stages 1-5 → completed; Stage 6 → in_progress.
229
-
230
- ### Stage 6: Route Outputs
231
-
232
- If `--no-route`: skip this stage.
233
-
234
- For each insight in `synthResult.insights`, route based on `routing` field:
235
-
236
- **Spec routing** (`routing: "spec"`):
237
- Map category (pattern/convention → `coding`, architecture → `arch`, quality → `quality`). Append `<spec-entry>` with category, auto-extracted keywords, date, source="retrospective", title, summary, evidence, phase/lens/INS-id.
238
-
239
- **Issue routing** (`routing: "issue"`, severity critical/high):
240
- Append to `.workflow/issues/issues.jsonl` with `ISS-<date>-<seq>` id, source="retrospective", phase/INS-id context, and history entry.
241
-
242
- **Memory routing** (`routing: "knowhow"`):
243
- Invoke `manage-knowhow-capture` skill with tip content and `--tag retrospective,phase-{N}`.
244
-
245
- If `!AUTO_YES`: present routing table and ask confirmation before routing each group.
246
-
247
- ### Stage 7: Write Artifacts
248
-
249
- Write two files to `{target_dir}/`:
250
- - **retrospective.json**: phase, slug, timestamp, lenses_run, metrics, findings_by_lens, distilled_insights, routing_summary
251
- - **retrospective.md**: Header with phase/slug/timestamp, metrics table (tasks completed, test pass rate, review issues, UAT scenarios), findings by lens, distilled insights, routing summary
252
-
253
- Append each insight to `.workflow/specs/learnings.md`.
254
-
255
- If `.workflow/specs/learnings.md` already exists, append each insight as `<spec-entry>` (category=`learning`, auto-extract keywords, date=today, source=`retrospective`). Never create the file -- only append if it exists.
256
-
257
- Update plan: Stages 1-7 → completed; Stage 8 → in_progress.
258
-
259
- ### Stage 8: Report
260
-
261
- Display summary: phase, lenses run, insight counts (new vs merged duplicates), routing breakdown (spec/issue/knowhow/lesson counts with target paths), key metrics (task completion, test pass rate, review issues).
262
-
263
- Next steps: `$manage-status`, `$manage-issue "list --source retrospective"`, `$manage-learn "list --phase <N>"`, `$manage-wiki health`, `$wiki-digest "<phase-topic>"`.
264
- </execution>
265
-
266
- <error_codes>
267
-
268
- | Code | Severity | Description | Stage |
269
- |------|----------|-------------|-------|
270
- | E001 | error | `.workflow/` not initialized | parse_input |
271
- | E002 | error | Unknown `--lens` name | parse_input |
272
- | E003 | error | `--compare` requires single phase mode | parse_input |
273
- | E004 | error | Phase has no execution artifacts (no .task/) | load_artifacts |
274
- | E005 | error | Phase directory not found or phase not completed | scan_unreviewed |
275
- | W001 | warning | One or more lens agents timed out -- partial coverage | multi_lens_analysis |
276
- | W002 | warning | Existing retrospective.json found -- prompted to overwrite | scan_unreviewed |
277
- | W003 | warning | `manage-knowhow-capture` did not return parseable TIP id; fell back to direct write | route_outputs |
278
- | W004 | warning | `--compare` target phase has no retrospective.json; delta omitted | load_artifacts |
279
- </error_codes>
280
-
281
- <success_criteria>
282
- - [ ] Mode correctly parsed from arguments (scan/single/range/all)
283
- - [ ] Phase artifacts validated before analysis begins
284
- - [ ] Context agent loads all artifacts before lens agents spawn
285
- - [ ] All active lens agents spawned in parallel, waited as batch
286
- - [ ] Context agent closed last (after all lens agents)
287
- - [ ] Synthesizer produces deduplicated insights with stable INS-ids
288
- - [ ] Routing applied per insight (spec/issue/knowhow/none) with confirmation
289
- - [ ] retrospective.{md,json} written to phase directory
290
- - [ ] Lessons appended to specs/learnings.md regardless of --no-route flag
291
- - [ ] Existing retrospective archived before overwrite
292
- </success_criteria>
1
+ ---
2
+ name: quality-retrospective
3
+ description: Use after completing a phase to extract lessons, patterns, and improvement opportunities
4
+ argument-hint: "[phase|N..M] [--lens technical|process|quality|decision] [--all] [--no-route] [--compare N] [-y]"
5
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep
6
+ ---
7
+
8
+ <purpose>
9
+ Multi-lens retrospective for completed phases. Context-Agent Fork loads phase artifacts once;
10
+ four parallel lens agents (technical, process, quality, decision) analyze independently;
11
+ synthesizer distills insights; outputs are routed to spec stubs, knowhow tips, issues, and specs/learnings.md.
12
+
13
+ ```
14
+ +------------------------------------------------------------------+
15
+ | quality-retrospective -- Context-Agent Fork + Parallel Fan-out |
16
+ +------------------------------------------------------------------+
17
+
18
+ Stage 1-3: Read-only resolution (no writes)
19
+ +---------------------------------------------+
20
+ | Parse mode -> Validate artifacts |
21
+ | -> [scan] Find unreviewed phases |
22
+ +----------------------+-----------------------+
23
+ |
24
+ Stage 4: Context-Agent Fork (Pattern 2.10)
25
+ +----------------------------------------------------------------+
26
+ | spawn ctx (fork_turns: "none") |
27
+ | wait ctx |
28
+ | +----------+ +----------+ +----------+ +----------+ |
29
+ | |lens-tech | |lens-proc | |lens-qual | |lens-dec | |
30
+ | |fork=true | |fork=true | |fork=true | |fork=true | |
31
+ | +----------+ +----------+ +----------+ +----------+ |
32
+ | wait_agent([lens-tech, lens-proc, lens-qual, lens-dec]) |
33
+ | close lenses -> close ctx LAST |
34
+ +----------------------+-----------------------------------------+
35
+ | lens results
36
+ Stage 5: Synthesizer
37
+ +------------------------------------------+
38
+ | spawn synthesizer (fork_turns: "none") |
39
+ | -> wait -> close |
40
+ +----------------------+-------------------+
41
+ | distilled_insights
42
+ Stage 6-8: Route -> Write -> Report
43
+ ```
44
+ </purpose>
45
+
46
+ <context>
47
+ ```bash
48
+ $quality-retrospective
49
+ $quality-retrospective "3"
50
+ $quality-retrospective "2..4"
51
+ $quality-retrospective "--all"
52
+ $quality-retrospective "3 --lens technical --no-route"
53
+ $quality-retrospective "3 --compare 2 -y"
54
+ ```
55
+
56
+ **Flags**:
57
+ - No phase argument -> `scan` mode: report unreviewed completed phases, prompt selection
58
+ - `<N>` -> `single` mode: retrospect phase N
59
+ - `<N>..<M>` -> `range` mode: retrospect phases N through M (inclusive)
60
+ - `--all` -> batch mode: re-run for every completed phase
61
+ - `--lens <name>` -- restrict to one lens (repeatable): `technical|process|quality|decision`
62
+ - `--no-route` -- produce retrospective.{md,json} only; skip auto-creation of spec/note/issue
63
+ - `--compare <M>` -- emit a delta section vs phase M's prior retrospective
64
+ - `-y` -- accept all routing recommendations without prompting
65
+
66
+ When `-y`: Accept all routing recommendations without prompting. Route all insights automatically.
67
+
68
+ **Storage written**:
69
+ - `{target_dir}/retrospective.md` -- human-readable record (target_dir resolved via state.json artifact registry to `.workflow/scratch/{YYYYMMDD}-{type}-{slug}/`)
70
+ - `{target_dir}/retrospective.json` -- structured record
71
+ - `.workflow/specs/{category-file}.md` -- `<spec-entry>` entries appended to matching category files (one per spec-routed insight)
72
+ - `.workflow/issues/issues.jsonl` -- appended issue rows (`source: "retrospective"`)
73
+ - `.workflow/knowhow/TIP-*.md` -- knowhow tips (via `manage-knowhow-capture` skill)
74
+ - `.workflow/specs/learnings.md` -- append-only insight log
75
+ - Index auto-maintained by WikiIndexer
76
+
77
+ **Storage read (never modified)** — all resolved via `state.json.artifacts[]`:
78
+ ```
79
+ related = artifacts.filter(a =>
80
+ a.phase === target_phase && a.milestone === current_milestone
81
+ ).sort_by(completed_at asc)
82
+ ```
83
+ Each artifact's type determines its outputs at `.workflow/{a.path}/`:
84
+ - **execute** → index.json, plan.json, .task/TASK-*.json, .summaries/TASK-*-summary.md
85
+ - **verify** → verification.json
86
+ - **review** → review.json (findings, verdict, severity distribution)
87
+ - **debug** → understanding.md, evidence.ndjson (root causes, fix directions)
88
+ - **test** → uat.md, .tests/ (UAT results, gaps, coverage)
89
+ - Also reads: `.workflow/issues/issues.jsonl`, `.workflow/state.json`
90
+
91
+ ### Agent Registry
92
+
93
+ | Agent | task_name | fork_turns | Responsibility |
94
+ |-------|-----------|------------|----------------|
95
+ | Context Agent | `ctx` | "none" | Load all phase artifacts: index.json, plan.json, verification.json, review.json, uat.md, issues.jsonl, task summaries |
96
+ | Technical Lens | `lens-tech` | "all" | Technical debt, architecture decisions, code quality gaps, performance issues |
97
+ | Process Lens | `lens-proc` | "all" | Workflow efficiency, collaboration patterns, planning accuracy, bottlenecks |
98
+ | Quality Lens | `lens-qual` | "all" | Test coverage gaps, verification failures, UAT issues, quality gate outcomes |
99
+ | Decision Lens | `lens-dec` | "all" | Key decisions made, tradeoffs accepted, ADR candidates, reversibility |
100
+ | Synthesizer | `synthesizer` | "none" | Merge lens results, deduplicate insights, classify routing targets |
101
+
102
+ ### Fork Turns Strategy
103
+
104
+ | Agent | task_name | fork_turns | fork_from | Rationale |
105
+ |-------|-----------|------------|-----------|-----------|
106
+ | Context Agent | `ctx` | "none" | -- | Independent artifact loader; clean start |
107
+ | Technical Lens | `lens-tech` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
108
+ | Process Lens | `lens-proc` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
109
+ | Quality Lens | `lens-qual` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
110
+ | Decision Lens | `lens-dec` | "all" | `ctx` | Inherits loaded artifacts -- no redundant file reads |
111
+ | Synthesizer | `synthesizer` | "none" | -- | Clean context; receives lens results via message |
112
+
113
+ **Context-Agent Lifecycle**: Spawn `ctx` first -> `wait_agent` -> spawn all lens agents (`fork_turns: "all"`) -> `wait_agent` batch for lenses -> `close_agent` lenses -> `close_agent ctx` LAST.
114
+
115
+ > **fork_turns semantics**: `fork_turns: "all"` means the spawned agent inherits the *orchestrator's* current conversation context -- not the ctx agent's own context. When `wait_agent` for ctx returns, the ctx agent's completed artifact summaries are visible in the orchestrator's context. Lens agents forked after that point therefore inherit those summaries. Lens agents do **not** fork directly from `ctx`; the `fork_from: ctx` column above is conceptual shorthand for this sequencing.
116
+ </context>
117
+
118
+ <invariants>
119
+ 1. **Read-only until Stage 6**: Stages 1-5 must not write any files -- only read and analyze
120
+ 2. **Context-agent spawns first**: `ctx` must complete before any lens agent is spawned
121
+ 3. **Parallel lens dispatch**: All active lens agents spawned in a single batch, then `wait_agent` for all together -- never sequentially
122
+ 4. **Context-agent closes last**: Close all lens agents before closing `ctx`
123
+ 5. **Synthesizer is isolated**: `fork_turns: "none"` -- receives lens results only via message, not full conversation history
124
+ 6. **Stable INS-ids**: `INS-{8hex}` from `hash(phase_num + lens + title)` -- re-runs do not create duplicates
125
+ 7. **Archive before overwrite**: Move existing retrospective.{md,json} to `.history/` with timestamp before writing new ones
126
+ 8. **Spec learnings.md backward-compat**: Append to it only if it already exists -- never create it
127
+ 9. **Route confirmation**: Unless `-y`, present routing table and ask per-group before writing spec/issue/knowhow
128
+ 10. **Lessons always written**: Append to `specs/learnings.md` regardless of `--no-route` -- routing only controls spec/issue/knowhow creation
129
+ </invariants>
130
+
131
+ <execution>
132
+
133
+ ### Session Initialization
134
+
135
+ Update plan: Stages 1-3 → in_progress; Stages 4-8 → pending.
136
+
137
+ ### Stages 1-3: Parse Mode and Validate Artifacts
138
+
139
+ **Stage 1: Parse mode** from `$ARGUMENTS`:
140
+
141
+ | First non-flag token | Mode |
142
+ |---------------------|------|
143
+ | (empty) | scan |
144
+ | `<N>` (single digit/number) | single |
145
+ | `<N>..<M>` | range |
146
+ | `--all` flag present | all |
147
+
148
+ Validate `--lens` values. If `--compare <M>` present, require single mode.
149
+
150
+ **Stage 2: Validate phase artifacts**. For each target phase:
151
+ - Phase directory must exist (resolved via state.json artifact registry to `.workflow/scratch/{YYYYMMDD}-{type}-{slug}/`)
152
+ - `index.json` must show `status: "completed"`
153
+ - `.task/` directory must exist with at least one `TASK-*.json`
154
+ - If existing `retrospective.json` found and not `--all`: emit W002, prompt overwrite
155
+
156
+ **Stage 3: Scan mode** -- list all completed phases without retrospective.json. Prompt user to select.
157
+
158
+ Update plan: Stages 1-3 → completed; Stage 4 → in_progress.
159
+
160
+ ### Stage 4: Context-Agent Fork + Parallel Lens Analysis
161
+
162
+ **Archive if overwriting**:
163
+ If existing `retrospective.{md,json}` present, move to `{artifact_dir}/.history/` with timestamp suffix before spawning.
164
+
165
+ **Step 4a: Spawn context agent**
166
+ ```javascript
167
+ spawn_agent({
168
+ task_name: "ctx",
169
+ fork_turns: "none",
170
+ message: `Load and summarize all phase ${targetPhase} artifacts for retrospective.
171
+ 1. Query state.json artifacts[] for phase === ${targetPhase} && milestone === current_milestone
172
+ 2. Load per-artifact outputs (execute→index/plan/tasks/summaries, verify→verification.json, review→review.json, debug→understanding/evidence, test→uat/tests)
173
+ 3. Filter issues.jsonl for this phase; read state.json for project context
174
+ EXPECTED: Goals vs outcomes, completion rates, verification/review/UAT results, issue counts, key metrics`
175
+ })
176
+ wait_agent({ timeout_ms: 1800000 })
177
+ ```
178
+
179
+ **Step 4b: Fork 4 lens agents** (only active lenses based on `--lens` flag; default: all 4)
180
+
181
+ All lenses use `fork_turns: "all"` and return the same JSON array schema:
182
+ ```json
183
+ [{ "title": "<80 chars>", "summary": "...", "category": "pattern|antipattern|decision|tool|gotcha|technique",
184
+ "routing": "spec|issue|knowhow|none", "severity": "critical|high|medium|low", "evidence": "<file:line>" }]
185
+ ```
186
+
187
+ | Agent | task_name | Focus |
188
+ |-------|-----------|-------|
189
+ | Technical | `lens-tech` | Tech debt, architecture decisions, code quality, performance, security, dependencies |
190
+ | Process | `lens-proc` | Planning accuracy, collaboration, workflow efficiency, communication, process improvements |
191
+ | Quality | `lens-qual` | Test coverage gaps, quality gates, UAT failures, review blockers, missing scenarios |
192
+ | Decision | `lens-dec` | Key decisions, tradeoffs, ADR candidates, reversibility, retrospective judgment |
193
+
194
+ ```javascript
195
+ // Spawn all 4 lenses in parallel
196
+ ["lens-tech", "lens-proc", "lens-qual", "lens-dec"].forEach(name =>
197
+ spawn_agent({ task_name: name, fork_turns: "all", message: `<lens-specific prompt>` })
198
+ )
199
+ const lensResults = wait_agent({ timeout_ms: 1800000 })
200
+
201
+ // Close lenses first, then context agent LAST
202
+ ["lens-tech", "lens-proc", "lens-qual", "lens-dec"].forEach(n => close_agent({ target: n }))
203
+ close_agent({ target: "ctx" })
204
+ ```
205
+
206
+ If `lensResults.timed_out` for any agent: emit W001, continue with partial coverage.
207
+
208
+ ### Stage 5: Synthesize Insights
209
+
210
+ ```javascript
211
+ spawn_agent({
212
+ task_name: "synthesizer",
213
+ fork_turns: "none",
214
+ message: `Merge and distill insights from 4 lens analyses.
215
+ Input: ${JSON.stringify(lensResults.status)}
216
+ 1. Merge all insights, deduplicate (same issue across lenses → keep higher severity, combine evidence)
217
+ 2. Generate stable INS-{8hex} id: hash(phase_num + lens + title)
218
+ 3. Classify routing: spec | issue | knowhow | none
219
+ 4. Produce phase-level metrics summary
220
+ EXPECTED JSON: { insights: [{id,title,summary,category,lens,routing,severity,evidence}],
221
+ metrics: {tasks_completed,tasks_failed,test_pass_rate,review_issues_count,uat_scenarios_passed},
222
+ routing_summary: {spec:N, issue:N, knowhow:N, none:N} }`
223
+ })
224
+ const synthResult = wait_agent({ timeout_ms: 1800000 })
225
+ close_agent({ target: "synthesizer" })
226
+ ```
227
+
228
+ Update plan: Stages 1-5 → completed; Stage 6 → in_progress.
229
+
230
+ ### Stage 6: Route Outputs
231
+
232
+ If `--no-route`: skip this stage.
233
+
234
+ For each insight in `synthResult.insights`, route based on `routing` field:
235
+
236
+ **Spec routing** (`routing: "spec"`):
237
+ Map category (pattern/convention → `coding`, architecture → `arch`, quality → `quality`). Append `<spec-entry>` with category, auto-extracted keywords, date, source="retrospective", title, summary, evidence, phase/lens/INS-id.
238
+
239
+ **Issue routing** (`routing: "issue"`, severity critical/high):
240
+ Append to `.workflow/issues/issues.jsonl` with `ISS-<date>-<seq>` id, source="retrospective", phase/INS-id context, and history entry.
241
+
242
+ **Memory routing** (`routing: "knowhow"`):
243
+ Invoke `manage-knowhow-capture` skill with tip content and `--tag retrospective,phase-{N}`.
244
+
245
+ If `!AUTO_YES`: present routing table and ask confirmation before routing each group.
246
+
247
+ ### Stage 7: Write Artifacts
248
+
249
+ Write two files to `{target_dir}/`:
250
+ - **retrospective.json**: phase, slug, timestamp, lenses_run, metrics, findings_by_lens, distilled_insights, routing_summary
251
+ - **retrospective.md**: Header with phase/slug/timestamp, metrics table (tasks completed, test pass rate, review issues, UAT scenarios), findings by lens, distilled insights, routing summary
252
+
253
+ Append each insight to `.workflow/specs/learnings.md`.
254
+
255
+ If `.workflow/specs/learnings.md` already exists, append each insight as `<spec-entry>` (category=`learning`, auto-extract keywords, date=today, source=`retrospective`). Never create the file -- only append if it exists.
256
+
257
+ Update plan: Stages 1-7 → completed; Stage 8 → in_progress.
258
+
259
+ ### Stage 8: Report
260
+
261
+ Display summary: phase, lenses run, insight counts (new vs merged duplicates), routing breakdown (spec/issue/knowhow/lesson counts with target paths), key metrics (task completion, test pass rate, review issues).
262
+
263
+ Next steps: `$manage-status`, `$manage-issue "list --source retrospective"`, `$manage-learn "list --phase <N>"`, `$manage-wiki health`, `$wiki-digest "<phase-topic>"`.
264
+ </execution>
265
+
266
+ <error_codes>
267
+
268
+ | Code | Severity | Description | Stage |
269
+ |------|----------|-------------|-------|
270
+ | E001 | error | `.workflow/` not initialized | parse_input |
271
+ | E002 | error | Unknown `--lens` name | parse_input |
272
+ | E003 | error | `--compare` requires single phase mode | parse_input |
273
+ | E004 | error | Phase has no execution artifacts (no .task/) | load_artifacts |
274
+ | E005 | error | Phase directory not found or phase not completed | scan_unreviewed |
275
+ | W001 | warning | One or more lens agents timed out -- partial coverage | multi_lens_analysis |
276
+ | W002 | warning | Existing retrospective.json found -- prompted to overwrite | scan_unreviewed |
277
+ | W003 | warning | `manage-knowhow-capture` did not return parseable TIP id; fell back to direct write | route_outputs |
278
+ | W004 | warning | `--compare` target phase has no retrospective.json; delta omitted | load_artifacts |
279
+ </error_codes>
280
+
281
+ <success_criteria>
282
+ - [ ] Mode correctly parsed from arguments (scan/single/range/all)
283
+ - [ ] Phase artifacts validated before analysis begins
284
+ - [ ] Context agent loads all artifacts before lens agents spawn
285
+ - [ ] All active lens agents spawned in parallel, waited as batch
286
+ - [ ] Context agent closed last (after all lens agents)
287
+ - [ ] Synthesizer produces deduplicated insights with stable INS-ids
288
+ - [ ] Routing applied per insight (spec/issue/knowhow/none) with confirmation
289
+ - [ ] retrospective.{md,json} written to phase directory
290
+ - [ ] Lessons appended to specs/learnings.md regardless of --no-route flag
291
+ - [ ] Existing retrospective archived before overwrite
292
+ </success_criteria>