maestro-flow-one 0.1.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 (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +173 -0
  3. package/bin/maestro-flow.js +730 -0
  4. package/claude/maestro-flow/SKILL.md +239 -0
  5. package/claude/maestro-flow/chains/templates.json +256 -0
  6. package/claude/maestro-flow/commands/learn/decompose.md +176 -0
  7. package/claude/maestro-flow/commands/learn/follow.md +167 -0
  8. package/claude/maestro-flow/commands/learn/investigate.md +221 -0
  9. package/claude/maestro-flow/commands/learn/retro.md +303 -0
  10. package/claude/maestro-flow/commands/learn/second-opinion.md +167 -0
  11. package/claude/maestro-flow/commands/lifecycle/amend.md +300 -0
  12. package/claude/maestro-flow/commands/lifecycle/analyze.md +126 -0
  13. package/claude/maestro-flow/commands/lifecycle/brainstorm.md +100 -0
  14. package/claude/maestro-flow/commands/lifecycle/composer.md +354 -0
  15. package/claude/maestro-flow/commands/lifecycle/execute.md +114 -0
  16. package/claude/maestro-flow/commands/lifecycle/fork.md +86 -0
  17. package/claude/maestro-flow/commands/lifecycle/init.md +78 -0
  18. package/claude/maestro-flow/commands/lifecycle/learn.md +140 -0
  19. package/claude/maestro-flow/commands/lifecycle/link-coordinate.md +71 -0
  20. package/claude/maestro-flow/commands/lifecycle/merge.md +61 -0
  21. package/claude/maestro-flow/commands/lifecycle/overlay.md +178 -0
  22. package/claude/maestro-flow/commands/lifecycle/plan.md +138 -0
  23. package/claude/maestro-flow/commands/lifecycle/player.md +404 -0
  24. package/claude/maestro-flow/commands/lifecycle/quick.md +56 -0
  25. package/claude/maestro-flow/commands/lifecycle/roadmap.md +164 -0
  26. package/claude/maestro-flow/commands/lifecycle/ui-design.md +93 -0
  27. package/claude/maestro-flow/commands/lifecycle/update.md +176 -0
  28. package/claude/maestro-flow/commands/lifecycle/verify.md +90 -0
  29. package/claude/maestro-flow/commands/manage/codebase-rebuild.md +75 -0
  30. package/claude/maestro-flow/commands/manage/codebase-refresh.md +57 -0
  31. package/claude/maestro-flow/commands/manage/harvest.md +94 -0
  32. package/claude/maestro-flow/commands/manage/issue-discover.md +77 -0
  33. package/claude/maestro-flow/commands/manage/issue.md +73 -0
  34. package/claude/maestro-flow/commands/manage/knowhow-capture.md +193 -0
  35. package/claude/maestro-flow/commands/manage/knowhow.md +77 -0
  36. package/claude/maestro-flow/commands/manage/learn.md +67 -0
  37. package/claude/maestro-flow/commands/manage/status.md +51 -0
  38. package/claude/maestro-flow/commands/manage/wiki.md +62 -0
  39. package/claude/maestro-flow/commands/milestone/audit.md +68 -0
  40. package/claude/maestro-flow/commands/milestone/complete.md +75 -0
  41. package/claude/maestro-flow/commands/milestone/release.md +96 -0
  42. package/claude/maestro-flow/commands/quality/auto-test.md +124 -0
  43. package/claude/maestro-flow/commands/quality/debug.md +115 -0
  44. package/claude/maestro-flow/commands/quality/refactor.md +55 -0
  45. package/claude/maestro-flow/commands/quality/retrospective.md +78 -0
  46. package/claude/maestro-flow/commands/quality/review.md +108 -0
  47. package/claude/maestro-flow/commands/quality/sync.md +51 -0
  48. package/claude/maestro-flow/commands/quality/test.md +103 -0
  49. package/claude/maestro-flow/commands/spec/add.md +49 -0
  50. package/claude/maestro-flow/commands/spec/load.md +51 -0
  51. package/claude/maestro-flow/commands/spec/remove.md +51 -0
  52. package/claude/maestro-flow/commands/spec/setup.md +51 -0
  53. package/claude/maestro-flow/commands/wiki/connect.md +62 -0
  54. package/claude/maestro-flow/commands/wiki/digest.md +69 -0
  55. package/codex/maestro-flow/SKILL.md +505 -0
  56. package/codex/maestro-flow/chains/templates.json +256 -0
  57. package/codex/maestro-flow/commands/learn/decompose.md +113 -0
  58. package/codex/maestro-flow/commands/learn/follow.md +83 -0
  59. package/codex/maestro-flow/commands/learn/investigate.md +83 -0
  60. package/codex/maestro-flow/commands/learn/retro.md +83 -0
  61. package/codex/maestro-flow/commands/learn/second-opinion.md +86 -0
  62. package/codex/maestro-flow/commands/lifecycle/amend.md +300 -0
  63. package/codex/maestro-flow/commands/lifecycle/analyze.md +483 -0
  64. package/codex/maestro-flow/commands/lifecycle/brainstorm.md +397 -0
  65. package/codex/maestro-flow/commands/lifecycle/composer.md +213 -0
  66. package/codex/maestro-flow/commands/lifecycle/execute.md +318 -0
  67. package/codex/maestro-flow/commands/lifecycle/fork.md +98 -0
  68. package/codex/maestro-flow/commands/lifecycle/init.md +134 -0
  69. package/codex/maestro-flow/commands/lifecycle/learn.md +80 -0
  70. package/codex/maestro-flow/commands/lifecycle/link-coordinate.md +257 -0
  71. package/codex/maestro-flow/commands/lifecycle/merge.md +69 -0
  72. package/codex/maestro-flow/commands/lifecycle/overlay.md +119 -0
  73. package/codex/maestro-flow/commands/lifecycle/plan.md +460 -0
  74. package/codex/maestro-flow/commands/lifecycle/player.md +323 -0
  75. package/codex/maestro-flow/commands/lifecycle/quick.md +124 -0
  76. package/codex/maestro-flow/commands/lifecycle/roadmap.md +468 -0
  77. package/codex/maestro-flow/commands/lifecycle/ui-design.md +135 -0
  78. package/codex/maestro-flow/commands/lifecycle/update.md +176 -0
  79. package/codex/maestro-flow/commands/lifecycle/verify.md +468 -0
  80. package/codex/maestro-flow/commands/manage/codebase-rebuild.md +347 -0
  81. package/codex/maestro-flow/commands/manage/codebase-refresh.md +66 -0
  82. package/codex/maestro-flow/commands/manage/harvest.md +91 -0
  83. package/codex/maestro-flow/commands/manage/issue-discover.md +431 -0
  84. package/codex/maestro-flow/commands/manage/issue.md +75 -0
  85. package/codex/maestro-flow/commands/manage/knowhow-capture.md +110 -0
  86. package/codex/maestro-flow/commands/manage/knowhow.md +95 -0
  87. package/codex/maestro-flow/commands/manage/learn.md +137 -0
  88. package/codex/maestro-flow/commands/manage/status.md +76 -0
  89. package/codex/maestro-flow/commands/manage/wiki.md +55 -0
  90. package/codex/maestro-flow/commands/milestone/audit.md +87 -0
  91. package/codex/maestro-flow/commands/milestone/complete.md +91 -0
  92. package/codex/maestro-flow/commands/milestone/release.md +70 -0
  93. package/codex/maestro-flow/commands/quality/auto-test.md +547 -0
  94. package/codex/maestro-flow/commands/quality/debug.md +334 -0
  95. package/codex/maestro-flow/commands/quality/refactor.md +151 -0
  96. package/codex/maestro-flow/commands/quality/retrospective.md +292 -0
  97. package/codex/maestro-flow/commands/quality/review.md +364 -0
  98. package/codex/maestro-flow/commands/quality/sync.md +111 -0
  99. package/codex/maestro-flow/commands/quality/test.md +498 -0
  100. package/codex/maestro-flow/commands/spec/add.md +101 -0
  101. package/codex/maestro-flow/commands/spec/load.md +77 -0
  102. package/codex/maestro-flow/commands/spec/remove.md +69 -0
  103. package/codex/maestro-flow/commands/spec/setup.md +75 -0
  104. package/codex/maestro-flow/commands/wiki/connect.md +73 -0
  105. package/codex/maestro-flow/commands/wiki/digest.md +87 -0
  106. package/package.json +24 -0
@@ -0,0 +1,257 @@
1
+ ---
2
+ name: maestro-link-coordinate
3
+ description: Chain-graph walker with in-process flow control. Loads chain JSON, walks nodes in main process, dispatches command nodes via spawn_agents_on_csv. Decision nodes resolved in-process between waves.
4
+ argument-hint: "\"intent text\" [--list] [-c [sessionId]] [--chain <name>] [-y]"
5
+ allowed-tools: spawn_agents_on_csv, Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
6
+ ---
7
+
8
+ <purpose>
9
+ In-process chain-graph coordinator. Unlike the CLI-delegated version (maestro coordinate start/next),
10
+ this coordinator loads chain graph JSON directly and drives flow in the main process:
11
+
12
+ - Command nodes → spawn via `spawn_agents_on_csv` (one command = one wave, always solo)
13
+ - Decision nodes → resolve in-process using expression evaluation against accumulated context
14
+ - Gate/terminal nodes → handle in-process
15
+
16
+ Coordinator responsibilities: load graph → walk nodes → build skill_call → spawn → read result →
17
+ evaluate decision → advance → persist state → repeat until terminal.
18
+
19
+ ```
20
+ +-------------------------------------------------------------------+
21
+ | maestro-link-coordinate (in-process walker) |
22
+ +-------------------------------------------------------------------+
23
+ | |
24
+ | Phase 1: Load Chain Graph |
25
+ | +-- Parse flags (--chain, -y, -c, --list) |
26
+ | +-- Load chain JSON from chains/ directory |
27
+ | +-- Initialize session state |
28
+ | |
29
+ | Phase 2: Walk Loop |
30
+ | +-- while (current_node != terminal): |
31
+ | | +-- command → build skill_call → spawn_agents_on_csv |
32
+ | | | → read result → update context → follow next|
33
+ | | +-- decision → evaluate expr against ctx.result |
34
+ | | | → match edge → follow target |
35
+ | | +-- gate → evaluate condition → on_pass / on_fail |
36
+ | | +-- terminal → exit loop |
37
+ | +-- Persist state after each node |
38
+ | |
39
+ | Phase 3: Completion Report |
40
+ | +-- Per-node results with outcomes |
41
+ | +-- Final status and resume hint |
42
+ +-------------------------------------------------------------------+
43
+ ```
44
+ </purpose>
45
+
46
+ <context>
47
+ $ARGUMENTS — user intent text, or flags.
48
+
49
+ **Flags**:
50
+ - `--list` — List all available chain graphs (scan chains/ directory)
51
+ - `-c / --continue [sessionId]` — Resume from last completed node
52
+ - `--chain <name>` — Force a specific chain graph
53
+ - `-y / --yes` — Auto mode: no confirmations between nodes
54
+
55
+ **Session state**: `.workflow/.maestro/{session-id}/`
56
+ **Chain graphs**: `chains/` and `chains/singles/` directories (JSON files)
57
+ </context>
58
+
59
+ <invariants>
60
+ 1. **ALL command-node execution via spawn_agents_on_csv**: Coordinator NEVER executes skills directly. Every command node dispatches through `spawn_agents_on_csv`.
61
+ 2. **Coordinator = graph walker + prompt assembler**: Load graph → walk → build skill_call → spawn → read result → evaluate decisions → persist. Nothing else.
62
+ 3. **One command per wave**: Each command node runs as a solo wave (result needed for subsequent decisions).
63
+ 4. **Decision nodes are in-process**: Coordinator evaluates `node.eval` against `ctx.result` directly. No sub-agent or CLI delegation.
64
+ 5. **Context flows forward**: Each command result is captured and available to subsequent decision expressions and command args.
65
+ 6. **max_visits enforced**: Track visit count per node; bail with failure if exceeded.
66
+ 7. **Resume from node**: `-c` loads saved state and continues from last incomplete node.
67
+ </invariants>
68
+
69
+ <execution>
70
+
71
+ ### Phase 1: Load Chain Graph
72
+
73
+ Parse `$ARGUMENTS` to extract: `listMode` (`--list`), `autoYes` (`-y`/`--yes`), `resumeMode` (`-c`/`--continue`), `resumeId`, `forcedChain` (`--chain <name>`), `intent` (remaining text).
74
+
75
+ **`--list`**: Scan `chains/*.json` and `chains/singles/*.json`, display names + descriptions, stop.
76
+
77
+ **`-c` (resume)**: Glob `.workflow/.maestro/MLC-*/state.json`, pick most recent (or by `resumeId`). Load state → find first incomplete node → jump to Phase 2.
78
+
79
+ **Fresh session**:
80
+ 1. Resolve chain: `--chain` direct or classify from intent using `chains/_intent-map.json`
81
+ 2. Load chain JSON: try `chains/{name}.json` then `chains/singles/{name}.json`
82
+ 3. Read `.workflow/state.json` for project context (phase, milestone)
83
+ 4. Initialize session state:
84
+
85
+ ```json
86
+ {
87
+ "id": "MLC-{YYYYMMDD}-{HHmmss}",
88
+ "intent": "<intent>", "chain": "<graph.id>", "auto_mode": false,
89
+ "status": "in_progress", "started_at": "<ISO>",
90
+ "current_node": "<graph.entry>",
91
+ "context": { "phase": null, "description": "<intent>", "result": null },
92
+ "visit_counts": {},
93
+ "history": []
94
+ }
95
+ ```
96
+
97
+ Session dir: `.workflow/.maestro/{sessionId}/`
98
+
99
+ **`--dry-run`**: Display node walk order with types, stop.
100
+ **Confirm** (skip if `autoYes`): Display chain summary, prompt `Proceed?`.
101
+
102
+ ### Phase 2: Walk Loop
103
+
104
+ Loop while `state.status === 'in_progress'`:
105
+ 1. Resolve `current_node` from graph — fail if not found
106
+ 2. Increment `visit_counts[nodeId]` — fail if exceeds `node.max_visits`
107
+ 3. Dispatch by `node.type`: command → handleCommand, decision → handleDecision, gate → handleGate, terminal → handleTerminal
108
+ 4. Persist `state.json` after every node
109
+
110
+ #### handleCommand — spawn via CSV
111
+
112
+ 1. Build `skill_call` from node config + context + auto_mode
113
+ 2. Write single-row CSV: `wave-{nodeId}.csv` with columns `id,skill_call,topic`
114
+ 3. Spawn:
115
+
116
+ ```javascript
117
+ spawn_agents_on_csv({
118
+ csv_path: csvPath,
119
+ id_column: "id",
120
+ instruction: AGENT_INSTRUCTION,
121
+ max_workers: 1,
122
+ max_runtime_seconds: 3600,
123
+ output_csv_path: `${sessionDir}/wave-${nodeId}-results.csv`,
124
+ output_schema: RESULT_SCHEMA
125
+ })
126
+ ```
127
+
128
+ 4. Read result → parse findings into `state.context.result` (for downstream decision eval)
129
+ 5. Record history entry with outcome
130
+ 6. Advance: success → `node.next`, failure → `node.on_failure` or fail state
131
+
132
+ #### handleDecision — in-process expr evaluation
133
+
134
+ 1. Evaluate `node.eval` expression (e.g. `ctx.result.verification_status`) against `state.context` via dot-path resolution
135
+ 2. Match against `node.edges[]`: first by exact `edge.value`, then by regex `edge.match`, finally `edge.default`
136
+ 3. Record history: `evalKey = "value" → matchedLabel`
137
+ 4. Advance to matched `edge.target` — fail if no match found
138
+
139
+ #### handleGate — condition check
140
+
141
+ Evaluate `node.condition` against context. Route to `node.on_pass` or `node.on_fail`. Record history with passed/blocked outcome.
142
+
143
+ #### handleTerminal
144
+
145
+ Set `state.status` to completed/failed based on `node.status`. Record final history entry.
146
+
147
+ ### Shared Utilities
148
+
149
+ **AUTO_FLAG_MAP** (skill → auto-confirm flag):
150
+
151
+ | Skill | Flag |
152
+ |-------|------|
153
+ | `maestro-init`, `maestro-analyze`, `maestro-brainstorm`, `maestro-ui-design`, `maestro-roadmap` | `-y` |
154
+ | `maestro-plan`, `maestro-execute`, `maestro-milestone-complete` | `-y` |
155
+ | `quality-auto-test`, `quality-retrospective` | `-y` |
156
+ | `quality-test` | `-y --auto-fix` |
157
+
158
+ **buildSkillCall(node, ctx, autoMode)**: Substitute `{phase}`, `{description}`, `{issue_id}`, `{milestone_num}` from context into `node.args`. If autoMode, append auto flag from `node.auto_flag` or AUTO_FLAG_MAP. Return `$${node.cmd} ${resolvedArgs}`.
159
+
160
+ **resolveExpr(expr, ctx)**: Navigate dot-path (e.g. `ctx.result.verification_status`) from context root. Strip `ctx.` prefix, walk path segments, return leaf value or undefined.
161
+
162
+ **parseResultContext(result)**: Parse `result.findings` as JSON if string, merge with `_raw_summary` and `_status`. Fallback to raw summary on parse failure.
163
+
164
+ ### Sub-Agent Instruction Template
165
+
166
+ ```
167
+ 你是 CSV job 子 agent。
168
+
169
+ 先原样执行这一段技能调用:
170
+ {skill_call}
171
+
172
+ 然后基于结果完成这一行任务说明:
173
+ {topic}
174
+
175
+ 限制:
176
+ - 不要修改 .workflow/.maestro/ 下的 state 文件
177
+ - skill 内部有自己的 session 管理,按 skill SKILL.md 执行即可
178
+
179
+ 最后必须调用 `report_agent_job_result`,返回 JSON:
180
+ {"status":"completed|failed","skill_call":"{skill_call}","summary":"一句话结果","findings":"JSON 结构化结果(含 decision 所需字段)","artifacts":"产物路径或空字符串","error":"失败原因或空字符串"}
181
+ ```
182
+
183
+ **findings 字段规约**:sub-agent 必须在 findings 中返回 decision node 需要的字段。例如:
184
+ - `maestro-verify` → `{"verification_status": "passed|failed", ...}`
185
+ - `quality-review` → `{"review_verdict": "PASS|BLOCK", ...}`
186
+ - `quality-test` → `{"uat_status": "passed|failed", ...}`
187
+ - `maestro-milestone-audit` → `{"audit_verdict": "PASS|BLOCK", ...}`
188
+
189
+ Coordinator 将 `findings` 解析后写入 `ctx.result`,供后续 decision node 的 `eval` 表达式读取。
190
+
191
+ ### Result Schema
192
+
193
+ ```javascript
194
+ const RESULT_SCHEMA = {
195
+ type: "object",
196
+ properties: {
197
+ status: { type: "string", enum: ["completed", "failed"] },
198
+ skill_call: { type: "string" },
199
+ summary: { type: "string" },
200
+ findings: { type: "string" },
201
+ artifacts: { type: "string" },
202
+ error: { type: "string" }
203
+ },
204
+ required: ["status", "skill_call", "summary", "findings", "artifacts", "error"]
205
+ };
206
+ ```
207
+
208
+ ### Phase 3: Completion Report
209
+
210
+ Set `state.completed_at`, persist final `state.json`. Display:
211
+ ```
212
+ === LINK-COORDINATE COMPLETE ===
213
+ Session: {sessionId}
214
+ Chain: {chain.name} ({chain.id})
215
+ Status: {completed|failed}
216
+
217
+ NODE WALK:
218
+ [✓] plan (command) — success — Plan generated
219
+ [→] check_verify (decision) — ctx.result.verification_status = "passed" → review
220
+ [✓] review (command) — success — No blockers
221
+ [→] check_review (decision) — ctx.result.review_verdict = "PASS" → test
222
+ [✓] test (command) — success — All tests passing
223
+
224
+ Nodes: {completed}/{total} | Visits: {total_visits}
225
+ State: .workflow/.maestro/{sessionId}/state.json
226
+ Resume: $maestro-link-coordinate -c {sessionId}
227
+ ```
228
+
229
+ </execution>
230
+
231
+ <error_codes>
232
+ | Code | Severity | Description | Recovery |
233
+ |------|----------|-------------|----------|
234
+ | E001 | error | No intent and no --list/--chain | Suggest --list |
235
+ | E002 | error | Chain graph JSON not found | List available chains |
236
+ | E003 | error | Command node spawn failed | Check wave result CSV, resume with -c |
237
+ | E004 | error | Decision node: no matching edge | Show eval value and available edges |
238
+ | E005 | error | max_visits exceeded on node | Show loop path, suggest --chain with simpler graph |
239
+ | E006 | error | Resume session not found | List available sessions |
240
+ | W001 | warning | Decision eval returned undefined | Fall through to default edge |
241
+ </error_codes>
242
+
243
+ <success_criteria>
244
+ - [ ] Chain graph loaded from chains/ directory (multi-path resolution)
245
+ - [ ] Session state initialized with graph entry node
246
+ - [ ] Every command node dispatched via spawn_agents_on_csv — coordinator never executes skills
247
+ - [ ] Decision nodes resolved in-process via expr evaluation against ctx.result
248
+ - [ ] Gate nodes evaluated in-process with pass/fail routing
249
+ - [ ] max_visits tracked per node, exceeded → failure
250
+ - [ ] Context flows forward: command result → ctx.result → decision eval → next command args
251
+ - [ ] State persisted after every node for resumability
252
+ - [ ] -c resumes from last incomplete node
253
+ - [ ] --list displays available chains without starting a session
254
+ - [ ] -y propagates auto_flag to command skill_calls
255
+ - [ ] Completion report shows per-node walk with outcomes
256
+ - [ ] findings from sub-agent parsed into ctx.result for decision routing
257
+ </success_criteria>
@@ -0,0 +1,69 @@
1
+ ---
2
+ name: maestro-merge
3
+ description: Two-phase merge of milestone worktree branch back — git merge first, scratch artifact sync and registry reconciliation only on success.
4
+ argument-hint: "-m <milestone-number> [--force] [--dry-run] [--no-cleanup] [--continue]"
5
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
6
+ ---
7
+
8
+ <purpose>
9
+ Merge a completed milestone worktree branch back into main, sync scratch artifacts,
10
+ and reconcile artifact registry. Two-phase approach: git merge first (source code),
11
+ artifact sync second (only after git succeeds). Prevents partial state corruption
12
+ when merge conflicts occur.
13
+ </purpose>
14
+
15
+ <required_reading>
16
+ @~/.maestro/workflows/merge.md
17
+ </required_reading>
18
+
19
+ <context>
20
+ $ARGUMENTS — milestone number and optional flags.
21
+
22
+ **Flags:**
23
+ - `-m <N>` or bare `<N>`: Milestone number
24
+ - `--force`: Merge even if milestone has incomplete artifacts
25
+ - `--dry-run`: Show what would be merged
26
+ - `--no-cleanup`: Keep worktree and branch after merge
27
+ - `--continue`: Resume merge paused due to git conflict
28
+
29
+ **Merge sequence:**
30
+ 1. Registry health check → 2. Milestone artifact completeness validation →
31
+ 3. Pre-merge rebase → 4. Git merge (source) → 5. Scratch artifact sync →
32
+ 6. Artifact registry reconciliation → 7. Cleanup
33
+
34
+ **Phase 2 detail:**
35
+ - Copy worktree `scratch/*` to main `.workflow/scratch/`
36
+ - Merge `state.json.artifacts[]` entries (worktree wins for same id)
37
+ - Remove milestone `"forked"` flag in main state.json
38
+ </context>
39
+
40
+ <execution>
41
+ Follow '~/.maestro/workflows/merge.md' completely.
42
+
43
+ **Next steps:**
44
+ - View dashboard → `$manage-status`
45
+ - Audit milestone → `$maestro-milestone-audit`
46
+ </execution>
47
+
48
+ <error_codes>
49
+ | Code | Severity | Condition | Recovery |
50
+ |------|----------|-----------|----------|
51
+ | E001 | error | Running inside a worktree | Run from main worktree |
52
+ | E002 | error | No worktree registry found | Nothing to merge |
53
+ | E003 | error | --continue but no merge state | Start fresh merge |
54
+ | E004 | error | No milestone number | Provide `-m <N>` |
55
+ | W001 | warning | Stale registry entries | Auto-cleaned |
56
+ | W002 | warning | Incomplete artifacts without --force | Confirm or use --force |
57
+ | W003 | warning | Conflict pulling main into worktree | Resolve first |
58
+ </error_codes>
59
+
60
+ <success_criteria>
61
+ - [ ] Registry health check passed
62
+ - [ ] Pre-merge rebase successful
63
+ - [ ] Git merge completed (or conflicts resolved via --continue)
64
+ - [ ] Scratch artifacts synced to main `.workflow/scratch/`
65
+ - [ ] `state.json.artifacts[]` reconciled (worktree entries merged)
66
+ - [ ] Milestone `"forked"` flag removed
67
+ - [ ] Worktree removed and branch deleted (unless --no-cleanup)
68
+ - [ ] Registry updated
69
+ </success_criteria>
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: maestro-overlay
3
+ description: Create or edit a non-invasive command overlay from natural-language intent. Writes a JSON patch file to ~/.maestro/overlays/, applies it via maestro overlay add, and confirms installation with idempotent re-apply support.
4
+ argument-hint: "<intent> | --list | --remove <name>"
5
+ allowed-tools: Read, Write, Bash, Glob, Grep
6
+ ---
7
+
8
+ <purpose>
9
+ 4-step pipeline: parse intent → identify targets + injection points → draft overlay JSON → install via CLI and report. Overlays are JSON patch files that augment `.claude/commands/*.md` non-invasively. They survive reinstalls because `maestro install` auto-reapplies them. Each overlay is idempotent: the patcher wraps content in hashed HTML-comment markers, so re-running `maestro overlay apply` produces no file changes.
10
+
11
+ ```
12
+ Parse Intent → Identify Targets → Draft JSON → Install + Report
13
+ (or --list / (read command (apply_patch (exec_command +
14
+ --remove) XML sections) to overlays/) banner)
15
+ ```
16
+
17
+ **Available injection sections**: `purpose`, `required_reading`, `deferred_reading`, `context`, `execution`, `error_codes`, `success_criteria`
18
+
19
+ **Patch modes**: `append`, `prepend`, `replace`, `new-section`
20
+ </purpose>
21
+
22
+ <context>
23
+
24
+ ```bash
25
+ $maestro-overlay "always run CLI verification after maestro-execute"
26
+ $maestro-overlay "require reading doc X before maestro-plan"
27
+ $maestro-overlay "--list"
28
+ $maestro-overlay "--remove cli-verify-after-execute"
29
+ ```
30
+
31
+ **Flags**:
32
+ - `<intent>` — Natural-language description of what to inject and where
33
+ - `--list` — Show installed overlays and their applied state
34
+ - `--remove <name>` — Strip overlay from targets and delete its file
35
+
36
+ **Overlay storage**:
37
+ - User overlays: `~/.maestro/overlays/*.json`
38
+ - Shared docs: `~/.maestro/overlays/docs/*.md`
39
+ - Shipped examples: `~/.maestro/overlays/_shipped/` (read-only)
40
+
41
+ </context>
42
+
43
+ <invariants>
44
+ 1. **Quick-exit first**: `--list` and `--remove` skip all intent parsing
45
+ 2. **Pristine source preferred**: Always read `.claude/commands/<name>.md` for the untouched command spec before deciding injection point
46
+ 3. **Idempotent content**: Injected blocks use hashed comment markers — re-runs produce no changes
47
+ 4. **Heading required**: Every injected block must start with a `## <Title> (overlay)` heading
48
+ 5. **Validate before report**: Run `maestro overlay add` successfully before displaying the report banner
49
+ 6. **Max 2 clarification questions**: If intent is ambiguous, ask at most 2 focused questions then proceed with best guess
50
+ </invariants>
51
+
52
+ <execution>
53
+
54
+ ### Step 1: Parse User Intent
55
+
56
+ **Quick-exit paths**:
57
+ - `--list` → run `maestro overlay list`, then stop
58
+ - `--remove <name>` → run `maestro overlay remove <name>`, then stop
59
+
60
+ **Ambiguous intent**: If target command or injection point unclear, ask up to 2 focused questions.
61
+
62
+ ### Step 2: Identify Targets and Injection Points
63
+
64
+ Read pristine command source from `$PKG_ROOT/.claude/commands/<name>.md` (fallback: `~/.claude/commands/<name>.md`). Select injection point:
65
+
66
+ | Intent type | Section | Mode |
67
+ |-------------|---------|------|
68
+ | New step after execution | `execution` | `append` |
69
+ | Required reading / prerequisite | `required_reading` | `append` |
70
+ | Preconditions / gating | `context` | `append` |
71
+ | Output quality gate | `success_criteria` | `append` |
72
+ | Brand-new section | `execution` | `new-section` (with `afterSection`) |
73
+
74
+ ### Step 3: Draft Overlay JSON
75
+
76
+ Build slug from intent (kebab-case, lowercase, max 40 chars). Write overlay to `~/.maestro/overlays/<slug>.json`:
77
+
78
+ ```json
79
+ {
80
+ "name": "<slug>",
81
+ "description": "<short summary>",
82
+ "targets": ["<command-name>"],
83
+ "priority": 50,
84
+ "enabled": true,
85
+ "patches": [{
86
+ "section": "<section>",
87
+ "mode": "<append|prepend|replace|new-section>",
88
+ "content": "<injected markdown with (overlay) heading>"
89
+ }]
90
+ }
91
+ ```
92
+
93
+ **Content guidelines**: Lead with `## Title (overlay)` heading. Use `@~/.maestro/...` references. Keep concise.
94
+
95
+ ### Step 4: Install via CLI and Report
96
+
97
+ Run `maestro overlay add ~/.maestro/overlays/<slug>.json`. On validation failure, fix JSON and retry (max 2).
98
+
99
+ Display report with name, path, targets (applied/skipped), and commands for re-apply/remove/inspect.
100
+
101
+ </execution>
102
+
103
+ <error_codes>
104
+
105
+ | Code | Severity | Description | Recovery |
106
+ |------|----------|-------------|----------|
107
+ | E001 | error | `maestro overlay add` validation failed | Fix JSON syntax or section name, retry |
108
+ | E002 | error | No targets found (all commands missing) | Check command name spelling |
109
+ | E003 | error | `--remove` target not found in overlay store | Run `--list` to see installed overlays |
110
+ | W001 | warning | One or more targets skipped (command missing from install) | Overlay still installed; applies when command is added |
111
+
112
+ </error_codes>
113
+
114
+ <success_criteria>
115
+ - [ ] Intent parsed and targets identified
116
+ - [ ] Overlay JSON drafted with correct section and mode
117
+ - [ ] `maestro overlay add` executed successfully
118
+ - [ ] Report displayed with apply/remove/inspect commands
119
+ </success_criteria>