maestro-flow 0.4.21 → 0.4.23

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 (63) hide show
  1. package/.agents/skills/maestro-analyze/SKILL.md +78 -34
  2. package/.agents/skills/maestro-blueprint/SKILL.md +57 -24
  3. package/.agents/skills/maestro-brainstorm/SKILL.md +69 -34
  4. package/.agents/skills/maestro-execute/SKILL.md +45 -15
  5. package/.agents/skills/maestro-grill/SKILL.md +63 -38
  6. package/.agents/skills/maestro-init/SKILL.md +59 -17
  7. package/.agents/skills/maestro-milestone-audit/SKILL.md +48 -5
  8. package/.agents/skills/maestro-milestone-complete/SKILL.md +48 -6
  9. package/.agents/skills/maestro-milestone-release/SKILL.md +42 -11
  10. package/.agents/skills/maestro-plan/SKILL.md +19 -13
  11. package/.agents/skills/maestro-roadmap/SKILL.md +59 -29
  12. package/.agents/skills/maestro-verify/SKILL.md +46 -11
  13. package/.agents/skills/team-adversarial-swarm/scripts/__pycache__/pheromone.cpython-313.pyc +0 -0
  14. package/.agents/skills/team-adversarial-swarm/scripts/__pycache__/scoring.cpython-313.pyc +0 -0
  15. package/.agents/skills/team-adversarial-swarm/scripts/aco.py +15 -15
  16. package/.agents/skills/team-adversarial-swarm/scripts/pheromone.py +2 -2
  17. package/.agents/skills/team-adversarial-swarm/scripts/scoring.py +1 -1
  18. package/.agents/skills/team-swarm/scripts/aco.py +15 -15
  19. package/.agents/skills/team-swarm/scripts/pheromone.py +2 -2
  20. package/.agents/skills/team-swarm/scripts/scoring.py +1 -1
  21. package/.agy/skills/maestro-analyze/SKILL.md +78 -34
  22. package/.agy/skills/maestro-blueprint/SKILL.md +57 -24
  23. package/.agy/skills/maestro-brainstorm/SKILL.md +69 -34
  24. package/.agy/skills/maestro-execute/SKILL.md +45 -15
  25. package/.agy/skills/maestro-grill/SKILL.md +63 -38
  26. package/.agy/skills/maestro-init/SKILL.md +59 -17
  27. package/.agy/skills/maestro-milestone-audit/SKILL.md +48 -5
  28. package/.agy/skills/maestro-milestone-complete/SKILL.md +48 -6
  29. package/.agy/skills/maestro-milestone-release/SKILL.md +42 -11
  30. package/.agy/skills/maestro-plan/SKILL.md +19 -13
  31. package/.agy/skills/maestro-roadmap/SKILL.md +59 -29
  32. package/.agy/skills/maestro-verify/SKILL.md +46 -11
  33. package/.agy/skills/team-adversarial-swarm/scripts/__pycache__/pheromone.cpython-313.pyc +0 -0
  34. package/.agy/skills/team-adversarial-swarm/scripts/__pycache__/scoring.cpython-313.pyc +0 -0
  35. package/.agy/skills/team-adversarial-swarm/scripts/aco.py +15 -15
  36. package/.agy/skills/team-adversarial-swarm/scripts/pheromone.py +2 -2
  37. package/.agy/skills/team-adversarial-swarm/scripts/scoring.py +1 -1
  38. package/.agy/skills/team-swarm/scripts/aco.py +15 -15
  39. package/.agy/skills/team-swarm/scripts/pheromone.py +2 -2
  40. package/.agy/skills/team-swarm/scripts/scoring.py +1 -1
  41. package/.claude/commands/maestro-analyze.md +78 -34
  42. package/.claude/commands/maestro-blueprint.md +57 -24
  43. package/.claude/commands/maestro-brainstorm.md +69 -34
  44. package/.claude/commands/maestro-execute.md +45 -15
  45. package/.claude/commands/maestro-grill.md +63 -38
  46. package/.claude/commands/maestro-init.md +59 -17
  47. package/.claude/commands/maestro-milestone-audit.md +48 -5
  48. package/.claude/commands/maestro-milestone-complete.md +48 -6
  49. package/.claude/commands/maestro-milestone-release.md +42 -11
  50. package/.claude/commands/maestro-plan.md +19 -13
  51. package/.claude/commands/maestro-roadmap.md +59 -29
  52. package/.claude/commands/maestro-verify.md +46 -11
  53. package/.claude/skills/team-adversarial-swarm/scripts/__pycache__/pheromone.cpython-313.pyc +0 -0
  54. package/.claude/skills/team-adversarial-swarm/scripts/__pycache__/scoring.cpython-313.pyc +0 -0
  55. package/.claude/skills/team-adversarial-swarm/scripts/aco.py +15 -15
  56. package/.claude/skills/team-adversarial-swarm/scripts/pheromone.py +2 -2
  57. package/.claude/skills/team-adversarial-swarm/scripts/scoring.py +1 -1
  58. package/.claude/skills/team-swarm/scripts/aco.py +15 -15
  59. package/.claude/skills/team-swarm/scripts/pheromone.py +2 -2
  60. package/.claude/skills/team-swarm/scripts/scoring.py +1 -1
  61. package/package.json +1 -1
  62. package/workflows/command-authoring.md +823 -0
  63. package/workflows/interview-mechanics.md +7 -0
@@ -0,0 +1,823 @@
1
+ # Pipeline Command Authoring Standard
2
+
3
+ <purpose>
4
+ Authoring standard for pipeline commands (.claude/commands/*.md). Complements skill-authoring.md (FSM style) — Pipeline suits linear staged pipelines; FSM suits orchestrators and decision engines.
5
+
6
+ Selection criteria: control flow complexity. Use FSM when ≥3 conditions are met (non-linear branching, runtime chain reshaping, precise re-entry, multi-component handoff, 20+ persisted fields); otherwise use Pipeline. See knowhow DCS-20260531-1048.
7
+ </purpose>
8
+
9
+ ---
10
+
11
+ ## 1. Architecture: Staged Pipeline
12
+
13
+ Pipeline commands are **staged linear pipelines**: entry routing → sequential phases → produce artifact → report completion.
14
+
15
+ Core characteristics:
16
+ - Mode is fixed at entry (create/revise/check), no runtime reshaping
17
+ - Each phase has explicit input/output contracts
18
+ - Implementation details delegated to workflow files (`Follow 'workflow/X.md' completely`)
19
+ - Self-contained — unaware of orchestrators (ralph, etc.)
20
+
21
+ ### File Structure
22
+
23
+ ```
24
+ ---
25
+ frontmatter (name, description, argument-hint, allowed-tools)
26
+ ---
27
+
28
+ <purpose> <!-- Required -->
29
+ <required_reading> <!-- Conditionally required: when command delegates to a workflow file -->
30
+ <deferred_reading> <!-- Conditionally required: when command has lazily loaded templates -->
31
+ <context> <!-- Required -->
32
+ ### Pre-load <!-- Standard subsection -->
33
+ ### Role Knowledge <!-- Standard subsection -->
34
+ <interview_protocol> <!-- Conditionally required: when command has multi-round interactive decisions -->
35
+ <execution> <!-- Required -->
36
+ <completion> <!-- Required -->
37
+ <error_codes> <!-- Required -->
38
+ <success_criteria> <!-- Required -->
39
+ </output> <!-- Closing tag -->
40
+ ```
41
+
42
+ ### Section Requirement Classification
43
+
44
+ | Level | Sections | Rule |
45
+ |-------|----------|------|
46
+ | **Required** | purpose, context, execution, completion, error_codes, success_criteria | Every pipeline command must have these |
47
+ | **Conditionally Required** | required_reading, deferred_reading, interview_protocol | Include when the trigger condition is met; omit when not applicable |
48
+
49
+ **Trigger conditions for conditionally required sections:**
50
+
51
+ | Section | Include when | Omit when |
52
+ |---------|-------------|-----------|
53
+ | `<required_reading>` | Command delegates to a workflow file (`Follow 'workflow/X.md'`) | Command is self-contained with all logic inline |
54
+ | `<deferred_reading>` | Command loads templates or references on-demand during execution | No lazy-loaded dependencies exist |
55
+ | `<interview_protocol>` | Command has **multi-round interactive decision trees** (scope → depth → dimensions, etc.) | Command only uses AskUserQuestion for simple one-shot confirmations (proceed/cancel, yes/no) |
56
+
57
+ **Interview protocol classification guide:**
58
+
59
+ | Usage pattern | Needs interview_protocol? | Example |
60
+ |---------------|--------------------------|---------|
61
+ | Multi-round decision tree with traversal order | **Yes** — full protocol with 6 strategy elements | analyze, brainstorm, grill, roadmap, blueprint, init |
62
+ | Version/option selection (1-2 questions, no tree) | **Lightweight** — declare decision points only, no traversal rules | milestone-release |
63
+ | Simple confirmation (proceed/cancel) | **No** — handled inline in `<execution>` | plan, execute, verify, milestone-audit, milestone-complete |
64
+
65
+ Section authoring rules are defined in § 2 below.
66
+
67
+ ---
68
+
69
+ ## 2. Section Specifications
70
+
71
+ ### `<purpose>` — Goal and Positioning
72
+
73
+ State three things: **what it does**, **what it produces**, **where it sits in the pipeline**.
74
+
75
+ ```markdown
76
+ <purpose>
77
+ Create, revise, or verify an execution plan through a 5-stage pipeline:
78
+ Exploration, Clarification, Planning, Plan Checking, and Confirmation.
79
+ Produces plan.json with waves, task definitions, and user-confirmed execution strategy.
80
+
81
+ Supports three modes:
82
+ - **Create** (default): Build plan from analysis context
83
+ - **Revise** (`--revise`): Incrementally modify existing plan
84
+ - **Check** (`--check`): Standalone plan verification
85
+
86
+ All output goes to `.workflow/scratch/{YYYYMMDD}-plan-[P{N}-|M{N}-]{slug}/`.
87
+ </purpose>
88
+ ```
89
+
90
+ **Rules**:
91
+ - First paragraph: one-sentence summary + pipeline phase names
92
+ - Mode list: one line per mode, include trigger flag
93
+ - Output path: describe directory pattern
94
+ - Pipeline position: what is upstream, what is downstream (ASCII diagram or one sentence)
95
+ - No more than 15 lines
96
+
97
+ ### `<required_reading>` — Startup Dependencies (Conditionally Required)
98
+
99
+ Include when the command delegates execution to a workflow file. Omit when the command is self-contained with all logic inline in `<execution>`.
100
+
101
+ Workflow files loaded immediately when the command starts. Use `@` prefix for absolute paths.
102
+
103
+ ```markdown
104
+ <required_reading>
105
+ @~/.maestro/workflows/plan.md
106
+ </required_reading>
107
+ ```
108
+
109
+ **Rules**:
110
+ - Only list files that must be read before command execution begins
111
+ - Keep to 1-3 files
112
+ - Use `@~/.maestro/workflows/` prefix for paths
113
+ - Omit this section entirely if the command has no external workflow dependency
114
+
115
+ ### `<deferred_reading>` — Lazy Loading (Conditionally Required)
116
+
117
+ Include when the command loads templates or references on-demand during execution. Omit when no lazy-loaded dependencies exist.
118
+
119
+ ```markdown
120
+ <deferred_reading>
121
+ - [plan.json](~/.maestro/templates/plan.json) — read when generating plan output
122
+ - [task.json](~/.maestro/templates/task.json) — read when generating task files
123
+ - [state.json](~/.maestro/templates/state.json) — read when registering artifact
124
+ </deferred_reading>
125
+ ```
126
+
127
+ **Rules**:
128
+ - Each entry annotates when it is triggered (`read when ...`)
129
+ - Link format: `[display name](path) — trigger condition`
130
+ - Omit this section entirely when there is nothing to defer
131
+
132
+ ### `<context>` — Arguments and Environment
133
+
134
+ Input arguments, flags, and scope routing logic.
135
+
136
+ ```markdown
137
+ <context>
138
+ $ARGUMENTS — phase number, or no args for milestone-wide, with optional flags.
139
+
140
+ **Flags:**
141
+ | Flag | Effect | Default |
142
+ |------|--------|---------|
143
+ | `-y` / `--yes` | Auto mode — skip interactive questions | false |
144
+ | `--from <source>` | Load upstream context (analyze:ANL-xxx, blueprint:BLP-xxx) | — |
145
+ | `--gaps` | Plan from verification gaps | — |
146
+
147
+ **Scope routing:**
148
+ | Input | Scope | Resolution |
149
+ |-------|-------|------------|
150
+ | numeric arg | phase | Resolve from roadmap |
151
+ | `--from analyze:ANL-xxx` | standalone | Direct artifact path |
152
+ | no args + roadmap | milestone | Current milestone |
153
+
154
+ ### Pre-load
155
+
156
+ 1. **Codebase docs**: IF `.workflow/codebase/doc-index.json` exists → Read ARCHITECTURE.md, FEATURES.md
157
+ 2. **Specs**: `maestro spec load --category {category}` — load coding/arch/review constraints
158
+ 3. **Wiki search**: `maestro wiki search "{phase keywords}" --json` → top 5-10 entries as context
159
+ 4. All optional — proceed without if unavailable (log warning)
160
+
161
+ ### Role Knowledge
162
+
163
+ 1. Browse: `maestro wiki list --category {category}`
164
+ 2. Select task-relevant entries from index
165
+ 3. Load: `maestro wiki load <id1> [id2...]`
166
+ </context>
167
+ ```
168
+
169
+ **Rules**:
170
+ - `$ARGUMENTS` on the first line describes positional arguments
171
+ - Flags use tables, not prose
172
+ - Scope routing uses tables or pseudocode with explicit priority order
173
+ - `### Pre-load` subsection: numbered steps, each with condition check + command + degradation handling
174
+ - `### Role Knowledge` subsection: standard three steps (browse → select → load)
175
+ - Pre-load category selection by command domain:
176
+ | Command domain | spec category | wiki category |
177
+ |----------------|---------------|---------------|
178
+ | Analysis | arch | debug |
179
+ | Planning | arch, coding | arch |
180
+ | Execution | coding, ui (conditional) | coding |
181
+ | Verification | review | review |
182
+ | Brainstorming | arch | arch |
183
+
184
+ ### `<interview_protocol>` — Interactive Decisions (Conditionally Required)
185
+
186
+ **When required**: Include when the command has **multi-round interactive decision trees** (e.g., scope → depth → dimensions). Omit when the command only uses AskUserQuestion for simple one-shot confirmations (proceed/cancel).
187
+
188
+ | Usage pattern | Section needed? | Format |
189
+ |---------------|-----------------|--------|
190
+ | Multi-round decision tree | **Full protocol** — 6 strategy elements | Reference standard + all elements |
191
+ | 1-2 option selections, no traversal | **Lightweight** — decision points only | Decision points + scope guard |
192
+ | Simple confirmation (yes/no) | **Not needed** — handle inline in `<execution>` | — |
193
+
194
+ Interview protocol has two layers: **interaction mechanics** (shared across commands) and **decision strategy** (unique per command).
195
+
196
+ #### Interaction Mechanics (Shared Standard)
197
+
198
+ The following rules apply to all commands with an interview_protocol. Commands reference this standard directly — no need to rewrite each rule inline:
199
+
200
+ **Format**: One decision per turn via AskUserQuestion, 2-4 options, first option marked `(Recommended)`. User can terminate or redirect at any time via `Other`.
201
+
202
+ **Search-first**: Before asking, attempt self-resolution (priority high to low):
203
+ 1. Project state files: state.json, roadmap.md, project.md
204
+ 2. Current session artifacts already produced
205
+ 3. Knowledge base: `maestro spec load` / `maestro wiki search`
206
+ 4. Codebase: Glob / Grep / Read
207
+ 5. Open-ended exploration: `Agent(subagent_type: Explore)` / `maestro delegate --role explore`
208
+
209
+ Principle: **never ask what code or memory can answer**; never bounce your own ambiguity back to the user.
210
+
211
+ **Writeback cadence**: After each decision settles, **write to disk immediately** (target file specified by the command). Do not batch. Partial decisions must be on disk before the next question.
212
+
213
+ **Skip conditions**: Skip the entire interview in auto mode (`-y`/`--yes`), resume mode (`-c`/`--continue`), or when input is already unambiguous. Commands may append additional skip conditions.
214
+
215
+ **Decision table schema**: `| # | Decision | Choice | Source (user / code / default) |`
216
+
217
+ #### Decision Strategy (Command-Specific)
218
+
219
+ Each command only needs to declare the following elements in its `<interview_protocol>`:
220
+
221
+ | Element | Description | Example |
222
+ |---------|-------------|---------|
223
+ | **Interaction mode** | Convergent menu / adversarial Socratic / hybrid | `convergent menu-driven` |
224
+ | **Decision tree** | Decision points and traversal order | `scope → depth → dimensions → threshold` |
225
+ | **Traversal rules** | Strict order / allow jumps | `strict: do not open next branch until current settles` |
226
+ | **Scope guard** | What to decide, what NOT to prejudge | `only analyze; do not prejudge plan/execute` |
227
+ | **Writeback target** | Which file and section to write decisions to | `discussion.md top table + context.md` |
228
+ | **Additional search sources** | Data sources beyond the shared list | `issues.jsonl (for --gaps mode)` |
229
+ | **Additional skip conditions** | Skip conditions beyond the shared list | `--revise, --review` |
230
+ | **Exit condition** | When to end the interview | `all decision points settled` |
231
+
232
+ **Example usage in a command (convergent menu)**:
233
+
234
+ ```markdown
235
+ <interview_protocol>
236
+ Follows @~/.maestro/workflows/interview-mechanics.md standard.
237
+
238
+ **Interaction mode**: convergent menu-driven
239
+ **Decision tree** (strict order): scope → depth → dimensions → Go/No-Go threshold
240
+ **Scope guard**: only analyze decisions; do not prejudge plan/execute concerns
241
+ **Writeback target**: discussion.md (top table) + context.md "Interview Decisions"
242
+ **Additional search sources**: issues.jsonl (--gaps mode), roadmap.md
243
+ **Additional skip conditions**: input is already specific (explicit phase number or unambiguous topic)
244
+ **Exit condition**: all decision points settled → finalize session metadata
245
+ </interview_protocol>
246
+ ```
247
+
248
+ **Example usage in a command (adversarial mode, grill-specific)**:
249
+
250
+ ```markdown
251
+ <interview_protocol>
252
+ Follows @~/.maestro/workflows/interview-mechanics.md standard,
253
+ but **overrides interaction mode to adversarial Socratic**.
254
+
255
+ **Interaction mode**: adversarial Socratic — NOT menu-driven
256
+ **Question style**:
257
+ - Reference specific code: "The codebase uses `{symbol}` at `{file:line}` — your proposal calls it `{term}`. Which wins?"
258
+ - Concrete scenarios: "What happens when {action} while {condition}?"
259
+ - Challenge contradictions: immediately surface conflicts with code evidence or prior answers
260
+ - Escalating depth: per branch basic → specific → adversarial
261
+ **Branch traversal** (depth-gated): Scope → Data Model → Edge Cases → Integration → Scale → Security → Observability → Migration
262
+ **Writeback target**: grill-report.md (Q&A append) + terminology.md (term crystallization)
263
+ **Exit condition**: all depth-selected branches fully walked → finalize report + context-package.json
264
+ </interview_protocol>
265
+ ```
266
+
267
+ ### `<execution>` — Execution Logic
268
+
269
+ Core structure: workflow reference + command-specific extensions.
270
+
271
+ ```markdown
272
+ <execution>
273
+ ### Pre-flight
274
+ {Checks before entering the pipeline}
275
+
276
+ Follow '~/.maestro/workflows/{name}.md' completely.
277
+
278
+ ### {Command-specific extension 1}
279
+ {Only write logic not covered by the workflow file}
280
+
281
+ ### {Command-specific extension 2}
282
+ {Same}
283
+ </execution>
284
+ ```
285
+
286
+ **Rules**:
287
+ - `Follow 'workflow/X.md' completely` is the core delegation — the workflow file contains phase details
288
+ - Only write command-layer logic that the workflow file does not cover
289
+ - Extensions use `###` subsections with clear titles
290
+ - Do not repeat content already in the workflow file
291
+ - Pre-flight checks (e.g., `maestro collab preflight`) go before the workflow reference
292
+
293
+ **Typical extension types**:
294
+
295
+ | Type | Description | Example |
296
+ |------|-------------|---------|
297
+ | Agent constraint | Specific phases must/must not use Agent | P3 planning MUST spawn planner agent |
298
+ | Post-task inquiry | Knowledge capture after task completion | "Record as arch constraint?" |
299
+ | Issue sync | Bidirectional sync with issues.jsonl | task completion → issue status update |
300
+ | Mode routing | Entry points for special modes | `--gaps` → follow alternative workflow |
301
+
302
+ ### `<completion>` — Completion Report
303
+
304
+ Separate from `<execution>`. Defines the command's output protocol after completion.
305
+
306
+ ```markdown
307
+ <completion>
308
+ ### Standalone report
309
+
310
+ ```
311
+ === {COMMAND_NAME} READY ===
312
+ {Key}: {value}
313
+ {Key}: {value}
314
+
315
+ Output:
316
+ {artifact paths}
317
+
318
+ Next steps:
319
+ /{next-command} -- {description}
320
+ /{alt-command} -- {description}
321
+ ```
322
+
323
+ ### Ralph-invoked completion
324
+
325
+ Report completion via CLI (do not output text blocks):
326
+ ```
327
+ maestro ralph complete <idx> --status {STATUS} [--evidence {path}] [--concerns "..."]
328
+ ```
329
+
330
+ Status verdicts:
331
+ - **DONE** — Normal completion
332
+ - **DONE_WITH_CONCERNS** — Completed with caveats; pass `--concerns`
333
+ - **NEEDS_RETRY** — Tooling error / transient issue; ralph will retry
334
+ - **BLOCKED** — External hard blocker; pass `--reason`
335
+
336
+ ### Next-step routing
337
+
338
+ | Condition | Suggestion |
339
+ |-----------|-----------|
340
+ | {condition_1} | `/{command_1}` |
341
+ | {condition_2} | `/{command_2}` |
342
+ </completion>
343
+ ```
344
+
345
+ **Rules**:
346
+ - Standalone reports are wrapped with `=== X READY ===` or `=== X COMPLETE ===`
347
+ - Report template must include: artifact paths + next-step suggestions
348
+ - Ralph-invoked completion uses CLI calls only, no `--- COMPLETION STATUS ---` text blocks
349
+ - Next-step routing uses condition tables, covering all terminal states (success/partial/failure)
350
+ - Do not mix completion logic into `<execution>`
351
+
352
+ ### `<error_codes>` — Error Code Table
353
+
354
+ Enumerate all foreseeable errors and warnings.
355
+
356
+ ```markdown
357
+ <error_codes>
358
+ | Code | Severity | Condition | Recovery |
359
+ |------|----------|-----------|----------|
360
+ | E001 | error | No args and no roadmap | Provide phase number or create roadmap |
361
+ | E002 | error | Upstream artifact not found | Check artifact ID, verify state.json |
362
+ | W001 | warning | Wiki search unavailable | Continue without prior knowledge |
363
+ | W002 | warning | Collision detected with existing plan | Review and confirm scope |
364
+ </error_codes>
365
+ ```
366
+
367
+ **Rules**:
368
+ - At least 2 errors + 1 warning
369
+ - Every error must have a Recovery (resolution advice)
370
+ - Error codes use `E0xx`, warning codes use `W0xx`
371
+ - Severity has only two levels: `error` and `warning`
372
+ - Cover the following scenarios:
373
+ | Scenario | Example |
374
+ |----------|---------|
375
+ | Missing prerequisite | No roadmap, no plan, no artifacts |
376
+ | Invalid input | Invalid phase number, unknown flag |
377
+ | External dependency failure | CLI tool unavailable, delegate failed |
378
+ | Quality gate failure | Checker found issues, coverage below threshold |
379
+ | Degraded operation | Wiki/spec unavailable, partial context |
380
+
381
+ ### `<success_criteria>` — Acceptance Checklist
382
+
383
+ Line-by-line verifiable completion standards.
384
+
385
+ ```markdown
386
+ <success_criteria>
387
+ - [ ] plan.json written to scratch directory with summary, approach, task_ids, waves
388
+ - [ ] .task/TASK-*.json files created for each task
389
+ - [ ] Every task has `read_first[]` with at least the file being modified
390
+ - [ ] Every task has `convergence.criteria[]` with grep-verifiable conditions
391
+ - [ ] Plan-checker passed (or minor issues acknowledged)
392
+ - [ ] User confirmation captured (execute/modify/cancel)
393
+ - [ ] Artifact registered in state.json with correct scope/milestone/phase
394
+ </success_criteria>
395
+ ```
396
+
397
+ **Rules**:
398
+ - At least 5 items
399
+ - Each item must be **objectively verifiable** — determinable via file existence check, field non-empty check, or command exit code
400
+ - No subjective descriptions ("good code quality", "user is satisfied")
401
+ - Cover three categories:
402
+ | Category | Verification method | Example |
403
+ |----------|-------------------|---------|
404
+ | Artifact existence | Glob / Read | plan.json, TASK-*.json exist |
405
+ | Artifact quality | Field check | Every task has convergence.criteria[] |
406
+ | State update | state.json check | Artifact registered |
407
+
408
+ ---
409
+
410
+ ## 3. Pre-load Context Pattern
411
+
412
+ Plan, Execute, and Verify share a similar pre-load pattern. Unified standard below:
413
+
414
+ ### Standard Pre-load Steps
415
+
416
+ ```
417
+ 1. Codebase docs (structural context):
418
+ IF .workflow/codebase/doc-index.json exists:
419
+ Read ARCHITECTURE.md → module boundaries, integration points
420
+ Read FEATURES.md → component mapping (if relevant)
421
+ ELSE: log "W0xx: Codebase docs unavailable, continuing with code exploration only"
422
+
423
+ 2. Knowledge specs (conventions + constraints):
424
+ Bash("maestro spec load --category {category}")
425
+ Category mapping: analyze→arch, plan→arch, execute→coding, verify→review
426
+ Pass as constraints context to downstream agents
427
+
428
+ 3. Wiki search (prior knowledge):
429
+ keywords = extract 2-5 key terms from phase goal/title
430
+ Bash("maestro wiki search '{keywords}' --json 2>/dev/null")
431
+ IF exit code != 0 OR empty: log "W0xx: Wiki search unavailable"
432
+ ELSE: extract top 5-10 entries as prior knowledge context
433
+
434
+ 4. UI specs (conditional — only when task involves frontend):
435
+ IF task scope contains UI keywords (component, page, style, layout, CSS, frontend):
436
+ Bash("maestro spec load --category ui")
437
+ ELSE: skip
438
+ ```
439
+
440
+ ### Per-command Tailoring
441
+
442
+ | Command | Step 1 | Step 2 | Step 3 | Step 4 |
443
+ |---------|--------|--------|--------|--------|
444
+ | analyze | ARCHITECTURE.md | arch | debug keywords | — |
445
+ | plan | ARCHITECTURE.md + FEATURES.md | arch, coding | phase goal | UI conditional |
446
+ | execute | ARCHITECTURE.md | coding | phase keywords | UI conditional |
447
+ | verify | ARCHITECTURE.md + FEATURES.md | review | "architecture constraint" | — |
448
+ | brainstorm | — | arch | topic keywords | — |
449
+ | roadmap | — | arch | requirement keywords | — |
450
+
451
+ Commands reference this standard in `<context> ### Pre-load` and annotate their tailoring — no need to rewrite the full procedure.
452
+
453
+ ---
454
+
455
+ ## 4. Depth Standard
456
+
457
+ Using `maestro-plan.md` (188 lines) as the depth benchmark. Every pipeline command should meet the following minimum depth:
458
+
459
+ ### Minimum Requirements
460
+
461
+ **Required sections** (every pipeline command):
462
+
463
+ | Section | Min lines | Min entries | Must cover |
464
+ |---------|-----------|-------------|------------|
465
+ | `<purpose>` | 5 | — | Goal + modes + output path |
466
+ | `<context>` | 15 | Flags table + scope routing | Arguments, flags, Pre-load, Role Knowledge |
467
+ | `<execution>` | 5 | Workflow ref or inline logic + ≥1 extension | Core logic + command-specific extensions |
468
+ | `<completion>` | 10 | 2 modes | Standalone report + ralph CLI + next-step routing |
469
+ | `<error_codes>` | 4 | ≥2 error + ≥1 warning | Prerequisite + degradation |
470
+ | `<success_criteria>` | 5 | ≥5 items | Artifact existence + quality + state update |
471
+
472
+ **Conditionally required sections** (when trigger condition is met):
473
+
474
+ | Section | Min lines | Min entries | Must cover |
475
+ |---------|-----------|-------------|------------|
476
+ | `<required_reading>` | 1 | 1 file | Primary workflow file |
477
+ | `<deferred_reading>` | 2 | 1 entry with trigger | Template/reference + "read when ..." |
478
+ | `<interview_protocol>` (full) | 8 | 6 strategy elements | Interaction mode + decision tree + scope guard + writeback target + exit condition |
479
+ | `<interview_protocol>` (lightweight) | 4 | Decision points list | Decision points + scope guard |
480
+
481
+ ### Signs of Insufficient Depth
482
+
483
+ | Signal | Problem | Fix |
484
+ |--------|---------|-----|
485
+ | `<execution>` only has "Follow workflow X" | Missing command-specific constraints | Add Pre-flight / Agent constraints / Post-task |
486
+ | No `<error_codes>` | Error scenarios not enumerated | Cover at least missing prerequisites + dependency failures |
487
+ | No `<success_criteria>` | Ralph cannot judge completion quality | List grep/file-check verifiable acceptance items |
488
+ | No `<completion>` | Completion protocol unclear | Add standalone report + ralph CLI |
489
+ | `<context>` has no Pre-load | Missing knowledge context | Follow § 3 standard |
490
+
491
+ ---
492
+
493
+ ## 5. Anti-Patterns
494
+
495
+ | Anti-Pattern | Correct |
496
+ |---|---|
497
+ | `<execution>` only says "Follow workflow X" with nothing else | Add at least Pre-flight + command-specific extensions + separate completion |
498
+ | interview_protocol copies 50-line boilerplate | Reference this standard, write only 6 strategy elements (or lightweight variant) |
499
+ | Adding interview_protocol for simple yes/no confirmations | Only add for multi-round decision trees; simple confirmations go inline in `<execution>` |
500
+ | Adding required_reading when command has no external workflow | Only add when command delegates to a workflow file; self-contained commands omit it |
501
+ | Pre-load rewritten step-by-step in every command | Reference § 3 standard, annotate tailoring |
502
+ | Completion logic mixed into `<execution>` | Separate into `<completion>` section |
503
+ | error_codes / success_criteria missing | Every command must have them, even at minimum |
504
+ | `<purpose>` is a single sentence | Cover at least goal + modes + output path |
505
+ | Command repeats workflow file phase details | Command only writes extensions not in the workflow |
506
+ | Scope routing described in prose with implicit priority | Use tables or pseudocode with explicit priority order |
507
+ | Interview decision tree buried in prose | List decision points independently, state traversal order |
508
+ | success_criteria contains subjective descriptions | Every item must be objectively verifiable |
509
+
510
+ ---
511
+
512
+ ## 6. Pipeline vs FSM Decision Guide
513
+
514
+ | Choose Pipeline | Choose FSM |
515
+ |-----------------|------------|
516
+ | Linear phases (N phases executed sequentially) | 10+ states with multi-path branching |
517
+ | 1-3 modes, routed at entry then each runs independently | Runtime decisions reshape subsequent path |
518
+ | Self-contained, no cross-command handoff | Bidirectional handoff (A ↔ B loop) |
519
+ | Artifact written once | Per-step precise PERSIST, 20+ fields with cross-references |
520
+ | Simple re-entry (`-c` resume session) | Arbitrary step resumption, steps[] grow/shrink at runtime |
521
+
522
+ The two styles are complementary: FSM orchestrators invoke pipeline commands; pipeline commands are unaware of orchestrators.
523
+
524
+ ### Current Command Classification
525
+
526
+ | Style | Commands |
527
+ |-------|----------|
528
+ | **Pipeline** | init, analyze, plan, execute, verify, brainstorm, grill, blueprint, roadmap, milestone-audit, milestone-complete, milestone-release |
529
+ | **FSM** | ralph, ralph-execute, ralph-beta |
530
+ | **Needs evaluation** | coordinate (multi-role handoff may need FSM) |
531
+
532
+ ---
533
+
534
+ ## 7. Workflow File Authoring
535
+
536
+ Workflow files (`workflows/*.md`) are the **implementation** behind pipeline commands. A command file says `Follow 'workflow/X.md' completely` — the workflow file contains the actual phase-by-phase procedure, pseudocode, agent prompts, and internal logic.
537
+
538
+ ### Content Boundary: Command vs Workflow
539
+
540
+ | Content | Owned by | Rationale |
541
+ |---------|----------|-----------|
542
+ | Error code registry (`<error_codes>`) | **Command** | Command is the contract surface |
543
+ | Success criteria checklist | **Command** | Completion validation owned by caller |
544
+ | Completion report format | **Command** | `<completion>` section owns output protocol |
545
+ | Interview decision strategy | **Command** | `<interview_protocol>` owns the decision tree |
546
+ | Pre-load context pattern | **Command** | `<context> ### Pre-load` references § 3 |
547
+ | Phase-by-phase procedures | **Workflow** | Detailed execution steps with pseudocode |
548
+ | Agent spawn prompts | **Workflow** | Full prompt templates for sub-agents |
549
+ | Scope resolution logic | **Workflow** | Pseudocode priority cascade |
550
+ | Behavioral guards (Iron Law, Red Flags) | **Workflow** | Runtime constraints for agents |
551
+ | Output schemas (JSON) | **Workflow** | jsonc blocks for artifact formats |
552
+ | Internal quality gates | **Workflow** | Execution-time checks beyond success_criteria |
553
+ | State field writes | **Workflow** | Detailed index.json/state.json updates |
554
+ | Flag definitions | **Both** | Command = table; Workflow = implementation |
555
+ | Next-step routing | **Both** | Command = condition table; Workflow = implementation |
556
+ | Pipeline position diagram | **Both** | Command = brief in `<purpose>`; Workflow = full ASCII diagram |
557
+
558
+ **Principle**: The command file is the **contract** (what, when, error codes, success criteria); the workflow file is the **implementation** (how, step-by-step, pseudocode, agent prompts).
559
+
560
+ ### File Structure
561
+
562
+ ```
563
+ # Workflow: {Name}
564
+ {1-3 line summary: purpose + output + key constraint}
565
+
566
+ ---
567
+
568
+ ## Behavioral Guards ← Iron Law, Red Flags, Forbidden Wording (if applicable)
569
+ ## Prerequisites ← Required upstream artifacts (if applicable)
570
+ ## Architecture ← ASCII pipeline diagram (if multi-mode)
571
+ ## Parameters ← Flags/arguments table
572
+ ## Scope Resolution ← Input routing pseudocode
573
+ ## Output Artifacts ← Directory tree / file list (if 3+ output files)
574
+
575
+ ---
576
+
577
+ ## {Phase 1}: {Title} ← Core pipeline phases (sequential)
578
+ ## {Phase 2}: {Title}
579
+ ## ...
580
+ ## {Phase N}: {Title}
581
+
582
+ ---
583
+
584
+ ## Mode: {Name} ({--flag}) ← Alternate modes as trailing sections (if applicable)
585
+ ## ...
586
+
587
+ ---
588
+
589
+ ## Quality Gates ← Internal quality checks (if applicable)
590
+ ## Error Handling ← Error table OR reference to command file
591
+ ## State Updates ← State field writes (if applicable)
592
+ ```
593
+
594
+ ### Section Rules
595
+
596
+ #### H1 Title + Opening Summary
597
+
598
+ ```markdown
599
+ # Workflow: {Name}
600
+
601
+ 5-phase pipeline: Context Collection → Clarification → Planning → Plan Checking → Confirmation.
602
+ Produces plan.json + .task/TASK-{NNN}.json in .workflow/scratch/{YYYYMMDD}-plan-{slug}/.
603
+ ```
604
+
605
+ - H1 format: `# Workflow: {Name}` (standardized across all workflow files)
606
+ - Opening summary: exactly 1-3 lines — purpose, output, key constraint
607
+ - `---` horizontal rule after summary, and between every H2 section
608
+
609
+ #### Behavioral Guards (conditionally required)
610
+
611
+ For high-stakes workflows (execute, verify) that need anti-hallucination or anti-shortcut enforcement:
612
+
613
+ ```markdown
614
+ ## Iron Law
615
+ Never mark a task as complete unless the convergence criteria are met.
616
+
617
+ ## Red Flags
618
+ - Empty catch blocks, @ts-ignore, `as any` → stop, fix the root cause
619
+ - Test file has 0 assertions → invalid, rewrite
620
+ - "Aligned X with Y" without concrete change → reject
621
+ ```
622
+
623
+ Required when: workflow agents can hallucinate success, skip verification, or hide errors.
624
+
625
+ #### Prerequisites
626
+
627
+ ```markdown
628
+ ## Prerequisites
629
+ - None for standalone operation (state.json auto-bootstraps)
630
+ - For milestone/phase scope: init + roadmap required
631
+ ```
632
+
633
+ Required when: workflow depends on upstream artifacts or commands.
634
+
635
+ #### Parameters
636
+
637
+ Always use table format. Title: `## Parameters` (not "Flag Processing", "Arguments", or "Input").
638
+
639
+ ```markdown
640
+ ## Parameters
641
+
642
+ | Flag | Effect | Default |
643
+ |------|--------|---------|
644
+ | `--collab` | Use collaborative multi-planner mode in P3 | false |
645
+ | `--gaps` | Plan from verification gaps, skip P1 exploration | false |
646
+ | `--tdd` | Generate RED-GREEN-REFACTOR triplet tasks | false |
647
+ ```
648
+
649
+ #### Scope Resolution
650
+
651
+ Always use pseudocode in fenced code blocks with explicit priority numbering:
652
+
653
+ ```markdown
654
+ ## Scope Resolution
655
+
656
+ ```
657
+ Resolution priority (highest to lowest):
658
+ 1. --from analyze:ANL-xxx → CONTEXT_DIR = artifact path, scope = "standalone"
659
+ 2. --dir <path> → CONTEXT_DIR = path, scope from state.json
660
+ 3. numeric arg → scope = "phase", resolve from roadmap
661
+ 4. no args + roadmap → scope = "milestone"
662
+ 5. no args + no roadmap → ERROR E001
663
+ ```
664
+ ```
665
+
666
+ Never use prose paragraphs for scope resolution — pseudocode makes priority order unambiguous.
667
+
668
+ #### Output Artifacts (conditionally required)
669
+
670
+ When the workflow produces 3+ output files, document the directory structure:
671
+
672
+ ```markdown
673
+ ## Output Artifacts
674
+
675
+ ```
676
+ .workflow/scratch/{YYYYMMDD}-plan-P{N}-{slug}/
677
+ plan.json ← Plan overview with task_ids[], waves[]
678
+ .task/
679
+ TASK-001.json ← Individual task definition
680
+ TASK-002.json
681
+ .process/
682
+ exploration-arch.json ← Agent exploration results
683
+ context-package.json ← Aggregated context
684
+ ```
685
+ ```
686
+
687
+ #### Phase Sections (core content)
688
+
689
+ **Phase naming convention**:
690
+
691
+ | Pattern | When to use | Example |
692
+ |---------|-------------|---------|
693
+ | `{Letter}{N}: {Title}` | Core pipeline trio (plan/execute/verify) — they cross-reference each other | `P1: Context Collection`, `E2: Wave Parallel Execution`, `V1: Goal-Backward Verification` |
694
+ | `Step {N}: {Title}` | All other workflows | `Step 1: Parse & Route`, `Step 4: Branch Walking` |
695
+ | Fractional numbering | Interstitial phases in any workflow | `P4.5: Collision Detection`, `Step 2.5: Terminology Alignment` |
696
+
697
+ **Phase internal structure**:
698
+ - Use numbered steps within each phase
699
+ - Sub-steps use decimal notation: `4.1`, `4.2`, `5b`
700
+ - Pseudocode in fenced code blocks for conditional logic and loops
701
+ - Agent spawn blocks use `Agent()` pseudocode with full prompt templates
702
+ - Data mappings use tables, not prose
703
+
704
+ #### Alternate Modes (conditionally required)
705
+
706
+ When a workflow supports `--revise`, `--review`, `--check`, or similar alternate modes:
707
+
708
+ ```markdown
709
+ ## Mode: Revise (--revise)
710
+
711
+ ### Plan Discovery
712
+ Resolve which existing plan to revise via --dir or latest artifact lookup.
713
+
714
+ ### Execution Flow
715
+ 1. Load existing plan.json
716
+ 2. Obtain revision instructions (user or --revise arg)
717
+ 3. Spawn planner agent with existing plan + instructions
718
+ 4. Re-run P4 checker
719
+ 5. Update artifact in state.json
720
+ ```
721
+
722
+ - Place alternate modes as trailing H2 sections **after** the main pipeline phases
723
+ - Heading format: `## Mode: {Name} ({--flag})`
724
+ - Do not embed alternate mode logic inline within main pipeline phases
725
+
726
+ #### Error Handling
727
+
728
+ ```markdown
729
+ ## Error Handling
730
+
731
+ | Error | Condition | Recovery |
732
+ |-------|-----------|----------|
733
+ | E001 | No roadmap and no --dir | Provide phase number or create roadmap |
734
+ | E004 | Planner agent returned empty plan | Retry with expanded context |
735
+ | Runtime | Agent timeout | Retry once, then mark task failed |
736
+ ```
737
+
738
+ - Use table format matching the command file's `<error_codes>` schema
739
+ - At minimum, reference the command file's error codes
740
+ - Add workflow-specific runtime errors not covered by the command
741
+
742
+ #### Quality Gates (conditionally required)
743
+
744
+ Workflow-internal quality checks that run during execution (distinct from command's `<success_criteria>` which validates after completion):
745
+
746
+ ```markdown
747
+ ## Quality Gates
748
+
749
+ - [ ] Every task has `convergence.criteria[]` with grep-verifiable conditions
750
+ - [ ] No task `action` contains vague language ("align", "ensure", "improve")
751
+ - [ ] Plan confidence score ≥ 70 before proceeding to confirmation
752
+ ```
753
+
754
+ Use "Quality Gates" naming to avoid confusion with command's "success_criteria".
755
+
756
+ #### State Updates (conditionally required)
757
+
758
+ When the workflow writes to index.json or state.json:
759
+
760
+ ```markdown
761
+ ## State Updates
762
+
763
+ | When | Field | Value |
764
+ |------|-------|-------|
765
+ | P5 completion | state.json.artifacts[] | New PLN artifact entry |
766
+ | P5 completion | index.json.status | "confirmed" |
767
+ | Collision detected | index.json.collisions[] | Colliding file paths |
768
+ ```
769
+
770
+ ### Formatting Rules
771
+
772
+ | Element | Format | Example |
773
+ |---------|--------|---------|
774
+ | Section separators | `---` between every H2 section | Universal |
775
+ | Flags/parameters | Table with Flag / Effect / Default columns | `## Parameters` |
776
+ | Scope resolution | Pseudocode in fenced code block | Numbered priority cascade |
777
+ | Agent spawn prompts | `Agent()` pseudocode with structured prompt | Full template inline |
778
+ | Output schemas | `jsonc` code blocks with annotation comments | verification.json, context-package.json |
779
+ | Report templates | Plain code blocks with `{placeholder}` variables | Completion report format |
780
+ | Anti-patterns / traps | Bullet list | Red Flags section |
781
+ | Next-step routing | Condition → suggestion table | Post-pipeline routing |
782
+
783
+ ### Depth Calibration
784
+
785
+ Workflow depth correlates with interactivity, multi-agent orchestration, and mode count:
786
+
787
+ | Workflow type | Expected lines | Characteristics |
788
+ |---------------|---------------|-----------------|
789
+ | Interactive (discussion loops, feedback rounds) | 400-800 | analyze, brainstorm, grill |
790
+ | Multi-agent (parallel spawning, cross-agent synthesis) | 400-700 | execute, brainstorm |
791
+ | Multi-mode (3+ execution paths) | 400-600 | plan (create/revise/check/tdd) |
792
+ | Standard (single linear pipeline) | 200-400 | blueprint, roadmap |
793
+ | Procedural/operational (archive, audit, release) | 100-200 | milestone-audit, milestone-complete |
794
+
795
+ A workflow under 100 lines likely belongs inline in the command file rather than as a separate file.
796
+
797
+ ### Shared Logic Extraction
798
+
799
+ When 2+ workflow files share procedural logic, extract to a `{name}-common.md` companion:
800
+
801
+ ```
802
+ roadmap.md → imports shared logic from roadmap-common.md
803
+ roadmap-common.md → shared scope routing, milestone resolution, state updates
804
+ ```
805
+
806
+ - Primary workflow delegates with `Follow '{name}-common.md' § {Section}` pattern
807
+ - Common file uses the same H2 section structure as regular workflows
808
+ - Only extract when duplication is ≥30 lines across 2+ files
809
+
810
+ ### Workflow Anti-Patterns
811
+
812
+ | Anti-Pattern | Correct |
813
+ |---|---|
814
+ | Duplicating command's error_codes or success_criteria | Workflow adds runtime errors only; command owns the registry |
815
+ | Embedding completion report format | Completion format belongs in command's `<completion>` |
816
+ | Defining interview decision strategy | Decision tree belongs in command's `<interview_protocol>` |
817
+ | Omitting Parameters / Scope Resolution sections | Always include — readers should not need the command file for basic routing |
818
+ | Prose paragraphs for scope resolution | Use pseudocode with numbered priority levels |
819
+ | Inline alternate modes within main pipeline phases | Place as trailing `## Mode: {Name}` sections |
820
+ | "Quality Criteria" naming | Use "Quality Gates" to avoid collision with command's success_criteria |
821
+ | No `---` separators between H2 sections | Always separate for visual parsing |
822
+ | H1 title inconsistency ("X Workflow" vs "Workflow: X") | Standardize on `# Workflow: {Name}` |
823
+ | Workflow under 100 lines as separate file | Inline into the command file instead |