maestro-flow 0.5.46 → 0.5.47

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 (237) hide show
  1. package/.agents/skills/domain-add/SKILL.md +9 -0
  2. package/.agents/skills/learn-decompose/SKILL.md +12 -0
  3. package/.agents/skills/learn-follow/SKILL.md +41 -0
  4. package/.agents/skills/learn-investigate/SKILL.md +14 -0
  5. package/.agents/skills/learn-second-opinion/SKILL.md +14 -0
  6. package/.agents/skills/maestro-amend/SKILL.md +11 -0
  7. package/.agents/skills/maestro-companion/SKILL.md +11 -0
  8. package/.agents/skills/maestro-composer/SKILL.md +11 -0
  9. package/.agents/skills/maestro-guard/SKILL.md +25 -0
  10. package/.agents/skills/maestro-init/SKILL.md +28 -0
  11. package/.agents/skills/maestro-overlay/SKILL.md +11 -0
  12. package/.agents/skills/maestro-player/SKILL.md +11 -0
  13. package/.agents/skills/maestro-quick/SKILL.md +29 -0
  14. package/.agents/skills/maestro-swarm-workflow/SKILL.md +25 -0
  15. package/.agents/skills/maestro-tools-execute/SKILL.md +29 -0
  16. package/.agents/skills/maestro-tools-register/SKILL.md +29 -0
  17. package/.agents/skills/maestro-ui-codify/SKILL.md +11 -0
  18. package/.agents/skills/maestro-universal-workflow/SKILL.md +59 -0
  19. package/.agents/skills/maestro-update/SKILL.md +38 -0
  20. package/.agents/skills/manage-codebase-rebuild/SKILL.md +29 -0
  21. package/.agents/skills/manage-drift-realign/SKILL.md +12 -0
  22. package/.agents/skills/manage-harvest/SKILL.md +30 -6
  23. package/.agents/skills/manage-issue/SKILL.md +23 -0
  24. package/.agents/skills/manage-issue-discover/SKILL.md +28 -0
  25. package/.agents/skills/manage-kg-extractors/SKILL.md +27 -1
  26. package/.agents/skills/manage-knowhow/SKILL.md +26 -0
  27. package/.agents/skills/manage-knowhow-capture/SKILL.md +24 -0
  28. package/.agents/skills/manage-knowledge-audit/SKILL.md +13 -0
  29. package/.agents/skills/manage-status/SKILL.md +22 -0
  30. package/.agents/skills/manage-wiki/SKILL.md +28 -0
  31. package/.agents/skills/odyssey-improve/SKILL.md +50 -0
  32. package/.agents/skills/odyssey-planex/SKILL.md +46 -0
  33. package/.agents/skills/odyssey-review-test-fix/SKILL.md +50 -0
  34. package/.agents/skills/odyssey-ui/SKILL.md +50 -0
  35. package/.agents/skills/quality-auto-test/SKILL.md +12 -0
  36. package/.agents/skills/quality-debug/SKILL.md +11 -0
  37. package/.agents/skills/quality-refactor/SKILL.md +11 -0
  38. package/.agents/skills/quality-retrospective/SKILL.md +11 -0
  39. package/.agents/skills/quality-review/SKILL.md +11 -0
  40. package/.agents/skills/quality-sync/SKILL.md +10 -0
  41. package/.agents/skills/quality-test/SKILL.md +12 -0
  42. package/.agents/skills/security-audit/SKILL.md +11 -0
  43. package/.agents/skills/spec-add/SKILL.md +27 -0
  44. package/.agents/skills/spec-load/SKILL.md +25 -0
  45. package/.agents/skills/spec-remove/SKILL.md +26 -0
  46. package/.agents/skills/spec-setup/SKILL.md +30 -0
  47. package/.agy/skills/domain-add/SKILL.md +9 -0
  48. package/.agy/skills/learn-decompose/SKILL.md +12 -0
  49. package/.agy/skills/learn-follow/SKILL.md +41 -0
  50. package/.agy/skills/learn-investigate/SKILL.md +14 -0
  51. package/.agy/skills/learn-second-opinion/SKILL.md +14 -0
  52. package/.agy/skills/maestro-amend/SKILL.md +11 -0
  53. package/.agy/skills/maestro-companion/SKILL.md +11 -0
  54. package/.agy/skills/maestro-composer/SKILL.md +11 -0
  55. package/.agy/skills/maestro-guard/SKILL.md +25 -0
  56. package/.agy/skills/maestro-init/SKILL.md +28 -0
  57. package/.agy/skills/maestro-overlay/SKILL.md +11 -0
  58. package/.agy/skills/maestro-player/SKILL.md +11 -0
  59. package/.agy/skills/maestro-quick/SKILL.md +29 -0
  60. package/.agy/skills/maestro-swarm-workflow/SKILL.md +25 -0
  61. package/.agy/skills/maestro-tools-execute/SKILL.md +29 -0
  62. package/.agy/skills/maestro-tools-register/SKILL.md +29 -0
  63. package/.agy/skills/maestro-ui-codify/SKILL.md +11 -0
  64. package/.agy/skills/maestro-universal-workflow/SKILL.md +59 -0
  65. package/.agy/skills/maestro-update/SKILL.md +38 -0
  66. package/.agy/skills/manage-codebase-rebuild/SKILL.md +29 -0
  67. package/.agy/skills/manage-drift-realign/SKILL.md +12 -0
  68. package/.agy/skills/manage-harvest/SKILL.md +30 -6
  69. package/.agy/skills/manage-issue/SKILL.md +23 -0
  70. package/.agy/skills/manage-issue-discover/SKILL.md +28 -0
  71. package/.agy/skills/manage-kg-extractors/SKILL.md +27 -1
  72. package/.agy/skills/manage-knowhow/SKILL.md +26 -0
  73. package/.agy/skills/manage-knowhow-capture/SKILL.md +24 -0
  74. package/.agy/skills/manage-knowledge-audit/SKILL.md +13 -0
  75. package/.agy/skills/manage-status/SKILL.md +22 -0
  76. package/.agy/skills/manage-wiki/SKILL.md +28 -0
  77. package/.agy/skills/odyssey-improve/SKILL.md +50 -0
  78. package/.agy/skills/odyssey-planex/SKILL.md +46 -0
  79. package/.agy/skills/odyssey-review-test-fix/SKILL.md +50 -0
  80. package/.agy/skills/odyssey-ui/SKILL.md +50 -0
  81. package/.agy/skills/quality-auto-test/SKILL.md +12 -0
  82. package/.agy/skills/quality-debug/SKILL.md +11 -0
  83. package/.agy/skills/quality-refactor/SKILL.md +11 -0
  84. package/.agy/skills/quality-retrospective/SKILL.md +11 -0
  85. package/.agy/skills/quality-review/SKILL.md +11 -0
  86. package/.agy/skills/quality-sync/SKILL.md +10 -0
  87. package/.agy/skills/quality-test/SKILL.md +12 -0
  88. package/.agy/skills/security-audit/SKILL.md +11 -0
  89. package/.agy/skills/spec-add/SKILL.md +27 -0
  90. package/.agy/skills/spec-load/SKILL.md +25 -0
  91. package/.agy/skills/spec-remove/SKILL.md +26 -0
  92. package/.agy/skills/spec-setup/SKILL.md +30 -0
  93. package/.claude/commands/domain-add.md +9 -0
  94. package/.claude/commands/learn-decompose.md +12 -0
  95. package/.claude/commands/learn-follow.md +41 -0
  96. package/.claude/commands/learn-investigate.md +14 -0
  97. package/.claude/commands/learn-second-opinion.md +14 -0
  98. package/.claude/commands/maestro-amend.md +11 -0
  99. package/.claude/commands/maestro-companion.md +11 -0
  100. package/.claude/commands/maestro-composer.md +11 -0
  101. package/.claude/commands/maestro-guard.md +25 -0
  102. package/.claude/commands/maestro-init.md +28 -0
  103. package/.claude/commands/maestro-overlay.md +11 -0
  104. package/.claude/commands/maestro-player.md +11 -0
  105. package/.claude/commands/maestro-quick.md +29 -0
  106. package/.claude/commands/maestro-swarm-workflow.md +25 -0
  107. package/.claude/commands/maestro-tools-execute.md +29 -0
  108. package/.claude/commands/maestro-tools-register.md +29 -0
  109. package/.claude/commands/maestro-ui-codify.md +11 -0
  110. package/.claude/commands/maestro-universal-workflow.md +59 -0
  111. package/.claude/commands/maestro-update.md +38 -0
  112. package/.claude/commands/manage-codebase-rebuild.md +29 -0
  113. package/.claude/commands/manage-drift-realign.md +12 -0
  114. package/.claude/commands/manage-harvest.md +30 -6
  115. package/.claude/commands/manage-issue-discover.md +28 -0
  116. package/.claude/commands/manage-issue.md +23 -0
  117. package/.claude/commands/manage-kg-extractors.md +27 -1
  118. package/.claude/commands/manage-knowhow-capture.md +24 -0
  119. package/.claude/commands/manage-knowhow.md +26 -0
  120. package/.claude/commands/manage-knowledge-audit.md +13 -0
  121. package/.claude/commands/manage-status.md +22 -0
  122. package/.claude/commands/manage-wiki.md +28 -0
  123. package/.claude/commands/odyssey-improve.md +50 -0
  124. package/.claude/commands/odyssey-planex.md +46 -0
  125. package/.claude/commands/odyssey-review-test-fix.md +50 -0
  126. package/.claude/commands/odyssey-ui.md +50 -0
  127. package/.claude/commands/quality-auto-test.md +12 -0
  128. package/.claude/commands/quality-debug.md +11 -0
  129. package/.claude/commands/quality-refactor.md +11 -0
  130. package/.claude/commands/quality-retrospective.md +11 -0
  131. package/.claude/commands/quality-review.md +11 -0
  132. package/.claude/commands/quality-sync.md +10 -0
  133. package/.claude/commands/quality-test.md +12 -0
  134. package/.claude/commands/security-audit.md +11 -0
  135. package/.claude/commands/spec-add.md +27 -0
  136. package/.claude/commands/spec-load.md +25 -0
  137. package/.claude/commands/spec-remove.md +26 -0
  138. package/.claude/commands/spec-setup.md +30 -0
  139. package/.codex/skills/codify-to-knowhow/SKILL.md +2 -0
  140. package/.codex/skills/domain-add/SKILL.md +26 -0
  141. package/.codex/skills/domain-discover/SKILL.md +46 -0
  142. package/.codex/skills/domain-list/SKILL.md +29 -0
  143. package/.codex/skills/learn-decompose/SKILL.md +2 -0
  144. package/.codex/skills/learn-follow/SKILL.md +34 -0
  145. package/.codex/skills/learn-investigate/SKILL.md +33 -0
  146. package/.codex/skills/learn-retro/SKILL.md +33 -0
  147. package/.codex/skills/learn-second-opinion/SKILL.md +30 -0
  148. package/.codex/skills/maestro-amend/SKILL.md +11 -0
  149. package/.codex/skills/maestro-companion/SKILL.md +11 -0
  150. package/.codex/skills/maestro-composer/SKILL.md +11 -0
  151. package/.codex/skills/maestro-guard/SKILL.md +25 -0
  152. package/.codex/skills/maestro-help/SKILL.md +2 -0
  153. package/.codex/skills/maestro-init/SKILL.md +16 -0
  154. package/.codex/skills/maestro-learn/SKILL.md +2 -0
  155. package/.codex/skills/maestro-overlay/SKILL.md +1 -0
  156. package/.codex/skills/maestro-player/SKILL.md +2 -0
  157. package/.codex/skills/maestro-quick/SKILL.md +17 -0
  158. package/.codex/skills/maestro-tools-execute/SKILL.md +31 -0
  159. package/.codex/skills/maestro-tools-register/SKILL.md +29 -0
  160. package/.codex/skills/maestro-ui-codify/SKILL.md +2 -0
  161. package/.codex/skills/maestro-update/SKILL.md +38 -0
  162. package/.codex/skills/manage-codebase-rebuild/SKILL.md +2 -0
  163. package/.codex/skills/manage-codebase-refresh/SKILL.md +11 -0
  164. package/.codex/skills/manage-drift-realign/SKILL.md +2 -0
  165. package/.codex/skills/manage-harvest/SKILL.md +30 -8
  166. package/.codex/skills/manage-issue/SKILL.md +24 -0
  167. package/.codex/skills/manage-issue-discover/SKILL.md +2 -0
  168. package/.codex/skills/manage-knowhow/SKILL.md +26 -0
  169. package/.codex/skills/manage-knowhow-capture/SKILL.md +23 -0
  170. package/.codex/skills/manage-learn/SKILL.md +2 -0
  171. package/.codex/skills/manage-status/SKILL.md +22 -0
  172. package/.codex/skills/manage-wiki/SKILL.md +28 -0
  173. package/.codex/skills/odyssey-debug/SKILL.md +44 -0
  174. package/.codex/skills/odyssey-improve/SKILL.md +49 -0
  175. package/.codex/skills/odyssey-planex/SKILL.md +44 -0
  176. package/.codex/skills/odyssey-review-test-fix/SKILL.md +48 -0
  177. package/.codex/skills/odyssey-ui/SKILL.md +49 -0
  178. package/.codex/skills/quality-auto-test/SKILL.md +2 -0
  179. package/.codex/skills/quality-debug/SKILL.md +2 -0
  180. package/.codex/skills/quality-refactor/SKILL.md +2 -0
  181. package/.codex/skills/quality-retrospective/SKILL.md +2 -0
  182. package/.codex/skills/quality-review/SKILL.md +2 -0
  183. package/.codex/skills/quality-sync/SKILL.md +24 -0
  184. package/.codex/skills/quality-test/SKILL.md +2 -0
  185. package/.codex/skills/security-audit/SKILL.md +30 -0
  186. package/.codex/skills/spec-add/SKILL.md +28 -0
  187. package/.codex/skills/spec-load/SKILL.md +26 -0
  188. package/.codex/skills/spec-map/SKILL.md +1 -0
  189. package/.codex/skills/spec-remove/SKILL.md +28 -0
  190. package/.codex/skills/spec-setup/SKILL.md +28 -0
  191. package/.codex/skills/wiki-connect/SKILL.md +11 -0
  192. package/.codex/skills/wiki-digest/SKILL.md +11 -0
  193. package/dashboard/dist-server/dashboard/src/server/agents/api-explore-adapter.js +3 -1
  194. package/dashboard/dist-server/dashboard/src/server/agents/api-explore-adapter.js.map +1 -1
  195. package/dashboard/dist-server/dashboard/src/server/wiki/embedding.d.ts +5 -0
  196. package/dashboard/dist-server/dashboard/src/server/wiki/embedding.js +25 -1
  197. package/dashboard/dist-server/dashboard/src/server/wiki/embedding.js.map +1 -1
  198. package/dashboard/dist-server/src/graph/kg/db/queries.d.ts +4 -0
  199. package/dashboard/dist-server/src/graph/kg/db/queries.js +35 -19
  200. package/dashboard/dist-server/src/graph/kg/db/queries.js.map +1 -1
  201. package/dashboard/dist-server/src/graph/kg/extraction/orchestrator.js +19 -11
  202. package/dashboard/dist-server/src/graph/kg/extraction/orchestrator.js.map +1 -1
  203. package/dist/src/agents/api-explore/config.d.ts +11 -1
  204. package/dist/src/agents/api-explore/config.d.ts.map +1 -1
  205. package/dist/src/agents/api-explore/config.js +17 -16
  206. package/dist/src/agents/api-explore/config.js.map +1 -1
  207. package/dist/src/agents/api-explore/index.js +4 -4
  208. package/dist/src/agents/api-explore/index.js.map +1 -1
  209. package/dist/src/agents/api-explore/llm.d.ts +2 -0
  210. package/dist/src/agents/api-explore/llm.d.ts.map +1 -1
  211. package/dist/src/agents/api-explore/llm.js +16 -4
  212. package/dist/src/agents/api-explore/llm.js.map +1 -1
  213. package/dist/src/agents/api-explore/runner.d.ts.map +1 -1
  214. package/dist/src/agents/api-explore/runner.js +16 -12
  215. package/dist/src/agents/api-explore/runner.js.map +1 -1
  216. package/dist/src/commands/explore.d.ts.map +1 -1
  217. package/dist/src/commands/explore.js +19 -2
  218. package/dist/src/commands/explore.js.map +1 -1
  219. package/dist/src/commands/install.js +7 -28
  220. package/dist/src/commands/install.js.map +1 -1
  221. package/dist/src/commands/moa.d.ts.map +1 -1
  222. package/dist/src/commands/moa.js +17 -2
  223. package/dist/src/commands/moa.js.map +1 -1
  224. package/dist/src/commands/search.d.ts.map +1 -1
  225. package/dist/src/commands/search.js +2 -0
  226. package/dist/src/commands/search.js.map +1 -1
  227. package/dist/src/graph/kg/db/queries.d.ts +4 -0
  228. package/dist/src/graph/kg/db/queries.d.ts.map +1 -1
  229. package/dist/src/graph/kg/db/queries.js +35 -19
  230. package/dist/src/graph/kg/db/queries.js.map +1 -1
  231. package/dist/src/graph/kg/extraction/orchestrator.d.ts.map +1 -1
  232. package/dist/src/graph/kg/extraction/orchestrator.js +19 -11
  233. package/dist/src/graph/kg/extraction/orchestrator.js.map +1 -1
  234. package/dist/src/hooks/plugins/explore-plugin.d.ts.map +1 -1
  235. package/dist/src/hooks/plugins/explore-plugin.js +3 -2
  236. package/dist/src/hooks/plugins/explore-plugin.js.map +1 -1
  237. package/package.json +1 -1
@@ -43,6 +43,8 @@ Remaining → intent
43
43
  | `wf-plan` | `{ context_dir?, from?, phase?, scope?, specs?, gaps?, quick? }` |
44
44
  | `wf-execute` | `{ plan_dir, specs?, codebase_context?, wiki_context?, auto_commit? }` |
45
45
  | `wf-milestone-audit` | `{ milestone?, is_adhoc? }` |
46
+
47
+ **Output boundary**: ALL file writes MUST target `.workflow/scratch/{YYYYMMDD}-swarm-{script}-{slug}/` (results, ralph-compatible artifacts). When inside a ralph session, writes target the corresponding step's scratch directory. NEVER modify source code, workflow scripts (`~/.maestro/workflows/swarm/`), or `.claude/commands/` files.
46
48
  </context>
47
49
 
48
50
  <state_machine>
@@ -196,6 +198,29 @@ Workflow 返回 JSON 后:
196
198
  6. **结果必须展示** — Workflow 返回后必须向用户展示格式化摘要,不得静默完成
197
199
  </invariants>
198
200
 
201
+ <execution>
202
+
203
+ ### Phase Gates (MANDATORY, BLOCKING)
204
+
205
+ **GATE 1: Parse → Route**
206
+ - REQUIRED: Intent text or `--script` flag parsed successfully.
207
+ - BLOCKED if: no intent and no `--script` (E001).
208
+
209
+ **GATE 2: Route → Context Assembly**
210
+ - REQUIRED: Target script resolved unambiguously (single match or user-selected from candidates).
211
+ - BLOCKED if: ambiguous routing without user resolution (E002).
212
+
213
+ **GATE 3: Context → Dispatch**
214
+ - REQUIRED: Args payload assembled with all required fields for target script.
215
+ - REQUIRED: Script file exists at `~/.maestro/workflows/swarm/{script}.js`.
216
+ - BLOCKED if: script file not found (E003) or required args missing.
217
+
218
+ **GATE 4: Dispatch → Ingest**
219
+ - REQUIRED: Workflow execution completed (success or partial results available).
220
+ - BLOCKED if: Workflow execution failed entirely (E004) — offer `--resume`.
221
+
222
+ </execution>
223
+
199
224
  <appendix>
200
225
 
201
226
  ### 与 Ralph 集成
@@ -35,8 +35,37 @@ $ARGUMENTS — Tool name, keyword, or --category filter
35
35
  Empty arguments enters interactive mode: list all tools for user selection.
36
36
  </context>
37
37
 
38
+ <invariants>
39
+ 1. **Confirmation before execution** — MUST AskUserQuestion before executing tool steps; NEVER auto-execute without user consent
40
+ 2. **Sequential step execution** — steps MUST be executed in defined order; NEVER skip or reorder steps unless user explicitly requests skip
41
+ 3. **Blocker escalation** — step failure MUST be reported to user with retry/skip/abort options; NEVER silently skip failed steps
42
+ 4. **Read-only tool definition** — tool execution MUST NOT modify the tool's knowhow document or spec entry; only the target codebase is modified per tool steps
43
+ 5. **Progress feedback** — each completed step MUST report `[Step N/M] done — <step_name>`; NEVER execute silently
44
+ 6. **Output boundary** — file writes are governed by the individual tool's step definitions. This command itself writes NO files beyond what the loaded tool prescribes
45
+ </invariants>
46
+
38
47
  <execution>
39
48
 
49
+ ### Phase Gates (MANDATORY, BLOCKING)
50
+
51
+ **GATE 1: Parse → Load**
52
+ - REQUIRED: Tool name, keyword, or --category parsed from arguments (or empty for interactive mode).
53
+ - BLOCKED if: invalid category value.
54
+
55
+ **GATE 2: Load → Confirm**
56
+ - REQUIRED: Exactly one tool resolved (direct match or user selection from candidates).
57
+ - REQUIRED: Tool document loaded and steps extracted (ref entries expanded via `maestro load --type knowhow`).
58
+ - BLOCKED if: E001 (no match found), E002 unresolved (multiple matches without user selection).
59
+
60
+ **GATE 3: Confirm → Execute**
61
+ - REQUIRED: User confirmed execution mode via AskUserQuestion (execute as-is / adjust / view only).
62
+ - BLOCKED if: user selects "View only" — display steps and END without execution.
63
+
64
+ **GATE 4: Execute → Report**
65
+ - REQUIRED: All steps attempted (completed, skipped with user approval, or aborted by user).
66
+ - REQUIRED: Results collected for each step (success/skip/fail).
67
+ - BLOCKED if: user chose abort mid-execution — report partial results and END.
68
+
40
69
  ### Step 1: Load Tool
41
70
 
42
71
  **By name**:
@@ -35,8 +35,37 @@ $ARGUMENTS — Intent description
35
35
  ```
36
36
  </context>
37
37
 
38
+ <invariants>
39
+ 1. **Schema validation** — tool knowhow document MUST include `tool: true`, `category`, `keywords`, and `summary` in YAML frontmatter; missing fields → reject write
40
+ 2. **No duplicate names** — tool title MUST be unique within its category; duplicate detection → E002 warning with overwrite/optimize confirmation
41
+ 3. **Category required** — every tool MUST declare exactly one category from: coding, test, review, arch, debug; empty category → E003
42
+ 4. **Confirmation gate** — MUST AskUserQuestion before writing knowhow document and spec ref entry; NEVER persist without user confirmation
43
+ 5. **Promote is in-place** — promote mode MUST update existing knowhow frontmatter via `maestro wiki update`; NEVER recreate the document
44
+ 6. **Output boundary** — ALL file writes MUST target .workflow/knowhow/ (tool documents) and .workflow/specs/ (ref entries via maestro spec add) only. NEVER modify source code or files outside these paths
45
+ 7. **Description format** — first line after `### Title` MUST state "Use when ..." (usage timing); this is critical for ref entry summary visibility in spec-load
46
+ </invariants>
47
+
38
48
  <execution>
39
49
 
50
+ ### Phase Gates (MANDATORY, BLOCKING)
51
+
52
+ **GATE 1: Parse → Gather**
53
+ - REQUIRED: Mode determined (extract/generate/optimize/promote) from argument parsing.
54
+ - REQUIRED: For optimize/promote modes, target tool/document exists and is loadable.
55
+ - BLOCKED if: empty args without user response to AskUserQuestion.
56
+
57
+ **GATE 2: Gather → Write**
58
+ - REQUIRED: Tool name, category, and usage timing confirmed.
59
+ - REQUIRED: Steps extracted or generated (extract: ≥1 step, generate: user-confirmed scope).
60
+ - REQUIRED: Inline vs ref mode decided based on step count.
61
+ - REQUIRED: User confirmed via AskUserQuestion (title, category, keywords, summary, step count).
62
+ - BLOCKED if: E001 (.workflow/specs/ not initialized), E003 (no category), user cancels.
63
+
64
+ **GATE 3: Write → Verify**
65
+ - REQUIRED: Knowhow document written with `tool: true` frontmatter (or updated in-place for promote).
66
+ - REQUIRED: Spec ref entry registered (if user confirmed).
67
+ - BLOCKED if: write failed or spec add returned error.
68
+
40
69
  ### Step 1: Intent Detection
41
70
 
42
71
  Parse $ARGUMENTS to determine mode:
@@ -33,8 +33,19 @@ Flags:
33
33
  - `--package-name <name>`: Package name for reference output (default: auto-generated from source directory)
34
34
  - `--output-dir <path>`: Output directory for reference package (default: `.workflow/reference_style`)
35
35
  - `--overwrite`: Allow overwriting existing package directory
36
+
37
+ **Output boundary**: ALL file writes MUST target the `--output-dir` path (default: `.workflow/reference_style/`) for reference packages, and `.workflow/knowhow/` for knowledge assets (via `codify-to-knowhow`). NEVER modify the source directory being analyzed.
36
38
  </context>
37
39
 
40
+ <invariants>
41
+ 1. **Source read-only** — the source path being analyzed MUST NOT be modified; extraction is purely read-only
42
+ 2. **Phase-sequential loading** — workflow files (ui-codify-extract, ui-codify-package, ui-codify-knowhow) MUST be read only when their phase starts; NEVER load all phases eagerly
43
+ 3. **User confirmation before knowhow** — Phase 3→4 gate MUST present AskUserQuestion before generating knowledge assets; NEVER auto-proceed to knowhow generation
44
+ 4. **Overwrite protection** — existing package directory MUST NOT be overwritten without `--overwrite` flag (E003)
45
+ 5. **Artifact completeness** — all 5 required artifacts MUST exist before reporting completion; NEVER skip artifact verification
46
+ 6. **Token-first extraction** — design-tokens.json MUST be generated before layout-templates.json; layout extraction depends on token foundation
47
+ </invariants>
48
+
38
49
  <execution>
39
50
  ## 1. Load UI Specs
40
51
 
@@ -33,6 +33,8 @@ Remaining → intent
33
33
  **Library locations:**
34
34
  - Fixed scripts: `~/.maestro/workflows/swarm/wf-*.js`
35
35
  - Dynamic scripts: `~/.maestro/workflows/dynamic/uwf-*.js`
36
+
37
+ **Output boundary**: ALL file writes MUST target `~/.maestro/workflows/dynamic/` (generated scripts) and `.workflow/scratch/{YYYYMMDD}-uwf-*/` (execution results). Fixed scripts at `~/.maestro/workflows/swarm/` are read-only. NEVER modify source code or `.claude/commands/` files.
36
38
  </context>
37
39
 
38
40
  <state_machine>
@@ -509,6 +511,36 @@ Findings: ${digest}
509
511
  12. **无反斜杠路径** — 字符串中路径用正斜杠(`\u`、`\a` 等会被解析为转义序列)
510
512
  </invariants>
511
513
 
514
+ <execution>
515
+
516
+ ### Phase Gates (MANDATORY, BLOCKING)
517
+
518
+ **GATE 1: Parse → Scan**
519
+ - REQUIRED: Intent text or `--from`/`--resume` flag parsed.
520
+ - BLOCKED if: no intent and no flags (E001).
521
+
522
+ **GATE 2: Scan → Design/Execute**
523
+ - REQUIRED: Library scan completed (both `swarm/` and `dynamic/` directories).
524
+ - REQUIRED: User decision if matches found (reuse existing vs generate new).
525
+ - BLOCKED if: scan fails to read script directories.
526
+
527
+ **GATE 3: Design → Generate**
528
+ - REQUIRED: Task decomposition completed with work_items, decision_points, data_flow.
529
+ - REQUIRED: Phase orchestration and adversarial pattern selection determined by depth.
530
+ - BLOCKED if: task cannot be decomposed (E002).
531
+
532
+ **GATE 4: Generate → Execute**
533
+ - REQUIRED: Script written to `~/.maestro/workflows/dynamic/uwf-{slug}.js`.
534
+ - REQUIRED: `node --check` syntax validation passed.
535
+ - REQUIRED: User confirmation via AskUserQuestion (unless resuming).
536
+ - BLOCKED if: syntax validation fails after 2 retries (E003).
537
+
538
+ **GATE 5: Execute → Persist**
539
+ - REQUIRED: Workflow execution completed via `scriptPath` invocation.
540
+ - BLOCKED if: Workflow execution failed (E004) — offer `--resume`.
541
+
542
+ </execution>
543
+
512
544
  <appendix>
513
545
 
514
546
  ### 使用示例
@@ -569,3 +601,30 @@ universal-workflow 扫描时会同时检查 swarm/ 和 dynamic/ 目录,
569
601
  | E005 | 持久化失败 | 展示脚本内容,让用户手动保存 |
570
602
 
571
603
  </appendix>
604
+
605
+ <error_codes>
606
+ | Code | Severity | Condition | Recovery |
607
+ |------|----------|-----------|----------|
608
+ | E001 | error | No intent and no --from/--resume flag | Prompt user for intent text |
609
+ | E002 | error | Task decomposition failed — cannot identify work_items | Require more specific intent description |
610
+ | E003 | error | Generated script syntax error after 2 retries | Show script content + error for manual fix |
611
+ | E004 | error | Workflow execution failed | Show error, offer --resume with runId |
612
+ | E005 | error | Script persistence failed (filesystem write error) | Show script content for manual save |
613
+ | W001 | warning | No matching scripts found in library scan | Proceed directly to S_DESIGN |
614
+ | W002 | warning | Adversarial gate confidence < 50% | Flag low-confidence decision, suggest --depth deep |
615
+ </error_codes>
616
+
617
+ <success_criteria>
618
+ - [ ] Intent parsed and flags extracted (--name, --depth, --dry-run, --from, --resume)
619
+ - [ ] Library scan completed across both swarm/ and dynamic/ directories
620
+ - [ ] User decision captured if matching scripts found (reuse vs generate)
621
+ - [ ] Task decomposition produced: work_items, decision_points, data_flow
622
+ - [ ] Adversarial pattern selected per decision_point according to depth level
623
+ - [ ] Blueprint presented to user with estimated agent count
624
+ - [ ] Script generated as pure JavaScript with all 12 generation rules enforced
625
+ - [ ] `node --check` syntax validation passed
626
+ - [ ] User confirmation obtained before execution (unless --resume)
627
+ - [ ] Workflow executed via scriptPath (not inline script string)
628
+ - [ ] Script persisted to `~/.maestro/workflows/dynamic/uwf-{slug}.js`
629
+ - [ ] Completion summary displayed with reuse/resume commands
630
+ </success_criteria>
@@ -30,10 +30,38 @@ $ARGUMENTS — optional flags.
30
30
  - `update-v{TO}-setup.md` — post-migration setup for version {TO}
31
31
 
32
32
  **Schema registry:** `src/migrations/` — handles all intermediate version bumps automatically
33
+
34
+ **Output boundary**: ALL file writes MUST target `.workflow/state.json` (version bump), `.workflow/state.json.backup-*` (backup), and `.workflow/` config files touched by version-specific setup. NEVER modify source code or `src/migrations/` files.
33
35
  </context>
34
36
 
37
+ <invariants>
38
+ 1. **Backup before migration** — a timestamped backup of `.workflow/state.json` MUST be created before any schema migration runs; NEVER execute migration without backup
39
+ 2. **Idempotent** — running update when already on latest version MUST be a no-op (display "up to date"); NEVER re-apply migrations
40
+ 3. **Confirmation before execute** — migration diff MUST be displayed and user MUST confirm via AskUserQuestion before execution (unless `--force`); NEVER silently apply schema changes
41
+ 4. **Migration diff always visible** — even with `--force`, the migration diff MUST be displayed for audit visibility; NEVER skip diff display
42
+ 5. **Restore path on failure** — if migration fails, the backup restore command MUST be displayed; NEVER leave user without recovery instructions
43
+ 6. **Sequential migration** — all intermediate version steps MUST be applied in order by the schema registry; NEVER skip intermediate versions
44
+ </invariants>
45
+
35
46
  <execution>
36
47
 
48
+ ### Phase Gates (MANDATORY, BLOCKING)
49
+
50
+ **GATE 1: Detect → Check**
51
+ - REQUIRED: Current version read from `.workflow/state.json`.
52
+ - BLOCKED if: state.json missing or unreadable (E001).
53
+
54
+ **GATE 2: Check → Execute**
55
+ - REQUIRED: Dry-run migration check completed; target version identified.
56
+ - REQUIRED: User confirmation via AskUserQuestion (unless `--force`).
57
+ - BLOCKED if: already up to date (display message and exit) or user cancels.
58
+
59
+ **GATE 3: Execute → Summary**
60
+ - REQUIRED: Backup created at `.workflow/state.json.backup-v{current}-{timestamp}`.
61
+ - REQUIRED: Schema migration completed successfully.
62
+ - REQUIRED: Version-specific setup doc followed (if exists).
63
+ - BLOCKED if: migration failed — display restore command and exit.
64
+
37
65
  ### Step 1: Detect Version
38
66
 
39
67
  ```
@@ -106,6 +134,16 @@ Next steps:
106
134
 
107
135
  </execution>
108
136
 
137
+ <error_codes>
138
+ | Code | Severity | Condition | Recovery |
139
+ |------|----------|-----------|----------|
140
+ | E001 | error | `.workflow/state.json` not found or unreadable | Run `/maestro-init` first |
141
+ | E002 | error | Schema migration failed (npx tsx returned error) | Display backup restore command: `cp .workflow/state.json.backup-* .workflow/state.json` |
142
+ | E003 | error | Version-specific setup doc failed to execute | Manual setup: read `~/.maestro/workflows/updates/update-v{target}-setup.md` |
143
+ | W001 | warning | No version-specific setup doc found for target version | Proceed without setup; schema migration alone is sufficient |
144
+ | W002 | warning | `--setup-only` but no setup script exists for current version | Display message and exit |
145
+ </error_codes>
146
+
109
147
  <success_criteria>
110
148
  - [ ] Current version detected from state.json
111
149
  - [ ] Schema migrations run automatically (no manual intermediate steps)
@@ -44,13 +44,42 @@ $ARGUMENTS -- optional flags.
44
44
  - `.workflow/codebase/` -- target directory (will be cleared and rebuilt)
45
45
  - `.workflow/codebase/doc-index.json` -- generated documentation index
46
46
  - `.workflow/codebase/knowledge-graph.json` -- Knowledge Graph with nodes, edges, layers, and tour (generated by `maestro kg index`)
47
+
48
+ **Output boundary**: ALL file writes MUST target `.workflow/codebase/`, `.workflow/state.json`, or `.workflow/project.md` (Tech Stack section only). NEVER modify source code or files outside these paths.
47
49
  </context>
48
50
 
51
+ <invariants>
52
+ 1. **Destructive with confirmation** — rebuild clears `.workflow/codebase/` entirely; MUST confirm with user unless `--force` is set
53
+ 2. **Commit confirmation** — git commit MUST be confirmed by user unless `--force` is set; `--skip-commit` bypasses commit entirely
54
+ 3. **Partial failure tolerance** — if 1-3 mapper agents fail, proceed with partial results (W001); only abort if all 4 fail (E002)
55
+ 4. **Focus scoping** — when `--focus <area>` is set, MUST only regenerate docs relevant to that scope; leave unrelated docs untouched
56
+ 5. **State update** — MUST update state.json with rebuild timestamp on completion
57
+ 6. **KG pipeline mandatory** — MUST run `maestro kg index` after doc regeneration; KG validation failure is non-fatal (W003)
58
+ </invariants>
59
+
49
60
  <execution>
50
61
  Follow '~/.maestro/workflows/codebase-rebuild.md' completely.
51
62
 
52
63
  **When `--focus <area>` is set:** pass the area string to each mapper agent as scoping context; only regenerate the docs relevant to that scope (leave others untouched unless missing).
53
64
 
65
+ ### Phase Gates (MANDATORY, BLOCKING)
66
+
67
+ **GATE 1: Confirmation → Mapping** (Pre-flight → Agent spawn)
68
+ - REQUIRED: `.workflow/` initialized (E001 if missing).
69
+ - REQUIRED: User confirmed rebuild (or `--force` set). W002 if existing docs found.
70
+ - BLOCKED if user declines confirmation.
71
+
72
+ **GATE 2: Mapping → KG Pipeline** (Agent results → Knowledge Graph)
73
+ - REQUIRED: At least 1 of 4 mapper agents returned valid results.
74
+ - REQUIRED: All output files written to `.workflow/codebase/`.
75
+ - REQUIRED: doc-index.json generated and valid.
76
+ - BLOCKED if all 4 mapper agents failed (E002).
77
+
78
+ **GATE 3: KG Pipeline → Commit** (Knowledge Graph → Git)
79
+ - REQUIRED: `maestro kg index` executed (W003 if validation fails — non-blocking).
80
+ - REQUIRED: state.json updated with rebuild timestamp.
81
+ - REQUIRED: If not `--skip-commit`: user confirmed git commit (or `--force` set).
82
+ - BLOCKED if state.json update fails.
54
83
  </execution>
55
84
 
56
85
  <completion>
@@ -58,8 +58,20 @@ Arguments: $ARGUMENTS
58
58
  - `.workflow/project.md`
59
59
 
60
60
  使用 `maestro timeline` CLI 构建统一的 git+session 时间线。
61
+
62
+ **Output boundary**: ALL file writes MUST target `.workflow/` metadata files (specs, codebase docs, roadmap.md, state.json, issues.jsonl) or `.workflow/.trash/drift-realign-{timestamp}/` (backups) or `.workflow/.drift-realign/` (session details). NEVER modify source code files.
61
63
  </context>
62
64
 
65
+ <invariants>
66
+ 1. **Code-as-Truth** — 代码是唯一真理源;当文档说 X 但代码做 Y 时,文档漂移,NEVER 反向修改代码来匹配文档
67
+ 2. **Backup before mutate** — MUST create backup tarball in `.workflow/.trash/` before any file modification (E005 if backup fails)
68
+ 3. **Never modify source code** — drift-realign only updates `.workflow/` metadata; source code files are read-only
69
+ 4. **Mutual exclusion** — `--report` 与 `--auto-archive` 互斥;同时传入 MUST trigger E006
70
+ 5. **Auto-depth escalation** — `drift_window` > 180 天 MUST auto-upgrade to `--depth deep` with W002 warning
71
+ 6. **Audit trail** — every triage decision MUST be logged in `drift-log.jsonl` with finding ID, action, and timestamp
72
+ 7. **Rebuild trigger** — codebase scope 的 3+ P0 finding MUST auto-trigger `/quality-sync --full` after triage
73
+ </invariants>
74
+
63
75
  <execution>
64
76
  Follow `~/.maestro/workflows/drift-realign.md` Stages 1-9 in order.
65
77
 
@@ -37,17 +37,41 @@ Arguments: $ARGUMENTS
37
37
  - `-y` / `--yes` — Skip confirmation prompts for all write operations (artifact selection, routing decisions, store writes). Useful for CI or batch harvesting.
38
38
 
39
39
  Additional flags, source registry (scan paths), and storage locations defined in workflow harvest.md.
40
+
41
+ **Output boundary**: ALL file writes MUST target `.workflow/knowhow/`, `.workflow/specs/`, `.workflow/issues/`, `.workflow/wiki/`, `.workflow/harvest/`, or `.workflow/state.json` only. NEVER modify source code, source artifacts, or files outside these paths.
40
42
  </context>
41
43
 
44
+ <invariants>
45
+ 1. **Read-only until routing** — extraction and classification happen in-memory; no files written until Stage 6
46
+ 2. **Never modify source artifacts** — harvest is purely extractive; source files remain untouched
47
+ 3. **Dedup before write** — MUST check harvest-log.jsonl and existing stores before each write to prevent duplicates
48
+ 4. **Source tagging** — MUST set `source: "harvest"` on every issues.jsonl row so concurrent writers can be distinguished
49
+ 5. **Conflict pre-check on spec routing** — when routing to spec, MUST compare against existing specs with same keywords/category; set `confidence="low"` and log conflict note if semantic conflict detected
50
+ 6. **Provenance tracking** — every routed item MUST be logged in harvest-log.jsonl with fragment ID, target store, and timestamp
51
+ 7. **Dry-run safety** — `--dry-run` MUST NOT write any files; preview only
52
+ </invariants>
53
+
42
54
  <execution>
43
55
  Follow '~/.maestro/workflows/harvest.md' Stages 1-8 in order.
44
56
 
45
- **Key invariants:**
46
- 1. **Read-only until Stage 6** — extraction and classification happen in-memory.
47
- 2. **Dedup before write** check harvest-log.jsonl and existing stores before each write.
48
- 3. **Never modify source artifacts** harvest is purely extractive.
49
- 4. **Dedup contract with parallel writers** — when appending to `issues.jsonl`, set `source: "harvest"` on each row so concurrent writers (e.g. `manage-issue-discover` with `source: "discover"`) can be distinguished and deduplicated.
50
- 5. **Conflict pre-check on spec routing** when routing to spec (Stage 6b), compare new entry against existing specs with same keywords/category. If semantic conflict detected, set `confidence="low"` on the new entry and log conflict note. Use `maestro spec conflict mark` if contradiction is clear.
57
+ ### Phase Gates (MANDATORY, BLOCKING)
58
+
59
+ **GATE 1: Discovery → Extraction** (Stages 1-3 Stage 4)
60
+ - REQUIRED: Source artifacts discovered and mode resolved (scan/session/path).
61
+ - REQUIRED: User selected artifact(s) to harvest (or auto-selected via session/path mode, or `-y`).
62
+ - BLOCKED if no harvestable artifacts found (W001) or invalid source (E004/E005).
63
+
64
+ **GATE 2: Extraction → Routing** (Stage 4 → Stage 5-6)
65
+ - REQUIRED: All files in selected artifacts loaded and parsed.
66
+ - REQUIRED: Knowledge fragments extracted with category, confidence, and tags.
67
+ - REQUIRED: Fragments filtered by `--min-confidence`.
68
+ - BLOCKED if extraction produces zero fragments.
69
+
70
+ **GATE 3: Routing → Write** (Stage 6 → Stage 7-8)
71
+ - REQUIRED: Routing classification applied (auto or forced by `--to`).
72
+ - REQUIRED: Dedup check passed against harvest-log.jsonl and existing stores.
73
+ - REQUIRED: If `--dry-run`: preview displayed, no files written — GATE blocks further writes.
74
+ - BLOCKED if dedup check fails or store paths unresolvable.
51
75
 
52
76
  Extraction patterns, classification rules, routing infrastructure, and fragment ID scheme defined in workflow harvest.md.
53
77
 
@@ -45,8 +45,19 @@ $ARGUMENTS -- optional. Parse first token to determine mode.
45
45
  ### Pre-load specs
46
46
  1. **Debug specs**: Run `maestro load --type spec --category debug` to load known antipatterns, root causes, and gotchas. Informs discovery perspectives with prior findings.
47
47
  2. Optional — proceed without if unavailable.
48
+
49
+ **Output boundary**: ALL file writes MUST target `.workflow/issues/issues.jsonl` or `.workflow/issues/discoveries/{SESSION_ID}/` only. NEVER modify source code or files outside these paths.
48
50
  </context>
49
51
 
52
+ <invariants>
53
+ 1. **Read-only analysis** — discovery agents MUST NOT modify source code; only `.workflow/issues/` is writable
54
+ 2. **Source tagging** — MUST set `source: "discover"` on every issues.jsonl row so concurrent writers (e.g. `manage-harvest`) can be distinguished and deduplicated
55
+ 3. **Dedup before write** — MUST check existing issues.jsonl for duplicates before appending new findings
56
+ 4. **Session traceability** — every discovery run MUST produce a session directory under `.workflow/issues/discoveries/` with full agent outputs
57
+ 5. **Schema compliance** — every issue row MUST conform to the canonical issue.json template schema
58
+ 6. **Idempotent re-run** — repeated execution with same scope and prompt MUST NOT create duplicate issues
59
+ </invariants>
60
+
50
61
  <execution>
51
62
  Determine mode from $ARGUMENTS:
52
63
  - No arguments or empty → interactive selection via AskUserQuestion
@@ -54,6 +65,23 @@ Determine mode from $ARGUMENTS:
54
65
  - First token is `by-prompt` → prompt-driven mode, remaining tokens are the user prompt
55
66
 
56
67
  Follow '~/.maestro/workflows/issue-discover.md' completely.
68
+
69
+ ### Phase Gates (MANDATORY, BLOCKING)
70
+
71
+ **GATE 1: Mode Selection → Analysis** (Steps 1-2 → Steps 3-8)
72
+ - REQUIRED: Mode correctly determined from arguments (multi-perspective or by-prompt).
73
+ - REQUIRED: `.workflow/issues/` directory exists (auto-create if missing).
74
+ - BLOCKED if E_NO_PROJECT (`.workflow/` missing) or E_EMPTY_PROMPT (by-prompt without text).
75
+
76
+ **GATE 2: Analysis → Issue Creation** (Steps 8-9 → Steps 10-11)
77
+ - REQUIRED: All perspectives analyzed (multi-perspective) or dimensions explored (by-prompt).
78
+ - REQUIRED: Findings deduplicated against existing issues.jsonl.
79
+ - BLOCKED if E_DISCOVERY_FAILED (all agents returned no results).
80
+
81
+ **GATE 3: Issue Creation → Completion** (Steps 11-12)
82
+ - REQUIRED: Issues appended to issues.jsonl with correct schema and `source: "discover"`.
83
+ - REQUIRED: Discovery session directory created with full agent outputs.
84
+ - BLOCKED if schema validation fails on any issue record.
57
85
  </execution>
58
86
 
59
87
  <error_codes>
@@ -37,12 +37,35 @@ $ARGUMENTS -- subcommand + options. Parse first token as subcommand.
37
37
  **State files:**
38
38
  - `.workflow/issues/issues.jsonl` -- active issues (one JSON per line)
39
39
  - `.workflow/issues/issue-history.jsonl` -- archived/closed issues
40
+
41
+ **Output boundary**: ALL file writes MUST target `.workflow/issues/issues.jsonl`, `.workflow/issues/issue-history.jsonl`, or `.workflow/issues/` directory only. NEVER modify source code or files outside these paths.
40
42
  </context>
41
43
 
44
+ <invariants>
45
+ 1. **Schema compliance** — every issue record MUST conform to the canonical issue.json template schema
46
+ 2. **ID uniqueness** — issue IDs (ISS-XXXXXXXX-NNN) MUST be unique across issues.jsonl and issue-history.jsonl
47
+ 3. **Close moves to history** — `close` subcommand MUST move the record from issues.jsonl to issue-history.jsonl, NEVER delete without archiving
48
+ 4. **Bidirectional links** — `link` subcommand MUST create references in both the issue and the linked task
49
+ 5. **Confirmation on destructive ops** — `close` and bulk `update` MUST require user confirmation unless `-y` flag is set
50
+ 6. **Append-only audit** — NEVER overwrite existing issue records; updates MUST preserve all prior fields and add `updated_at` timestamp
51
+ </invariants>
52
+
42
53
  <execution>
43
54
  Parse subcommand from first token of $ARGUMENTS.
44
55
  Follow '~/.maestro/workflows/issue.md' completely.
45
56
 
57
+ ### Phase Gates (MANDATORY, BLOCKING)
58
+
59
+ **GATE 1: Parse → Execute** (Subcommand routing)
60
+ - REQUIRED: Subcommand parsed and validated against valid set (create/list/status/update/close/link).
61
+ - REQUIRED: `.workflow/issues/` directory exists (auto-create with empty issues.jsonl if missing).
62
+ - BLOCKED if E_NO_SUBCOMMAND or E_INVALID_SUBCOMMAND.
63
+
64
+ **GATE 2: Execute → Write** (For mutating subcommands: create/update/close/link)
65
+ - REQUIRED: Issue data validated against issue.json template schema.
66
+ - REQUIRED: For `close`: resolution text provided.
67
+ - REQUIRED: For `link`: target task ID resolved and exists.
68
+ - BLOCKED if schema validation fails or target references unresolvable.
46
69
  </execution>
47
70
 
48
71
  <completion>
@@ -38,6 +38,8 @@ $ARGUMENTS -- optional flags.
38
38
 
39
39
  **Output:** `.workflow/kg/extractors.yaml` — declarative rules for PluginEngine.
40
40
 
41
+ **Output boundary**: ALL file writes MUST target `.workflow/kg/extractors.yaml` only. NEVER modify source code or files outside this path. `--scan-only` MUST NOT write any files.
42
+
41
43
  **Rule format:**
42
44
  ```yaml
43
45
  version: 1
@@ -66,6 +68,16 @@ plugins:
66
68
 
67
69
  <execution>
68
70
 
71
+ <invariants>
72
+ 1. **Read-only source code** — agents MUST only read source files for pattern discovery; NEVER modify source code
73
+ 2. **Scan-only safety** — `--scan-only` MUST stop after Phase 2 summary; NEVER write extractors.yaml
74
+ 3. **Append preservation** — `--append` MUST preserve existing rules in extractors.yaml; default (overwrite) MUST warn (W003) if file exists
75
+ 4. **Min-count threshold** — patterns with fewer occurrences than `--min-count` MUST be excluded unless explicitly overridden
76
+ 5. **User confirmation** — each pattern group MUST be confirmed/edited/skipped by user before writing (Phase 3, Step 2)
77
+ 6. **Schema compliance** — generated extractors.yaml MUST conform to version 1 PluginEngine schema with required fields (id, languages, mode, rules)
78
+ 7. **Validation mandatory** — MUST run `maestro kg index` after writing to verify new symbols are extractable
79
+ </invariants>
80
+
69
81
  ### Phase 1: Discover patterns
70
82
 
71
83
  Spawn **3 parallel agents** to scan the codebase:
@@ -78,7 +90,21 @@ Spawn **3 parallel agents** to scan the codebase:
78
90
 
79
91
  Each agent returns: `[{pattern_type, regex_evidence, file_count, sample_matches: [{file, line, code}]}]`
80
92
 
81
- **Gate:** If all 3 agents return empty results → E002 (abort). If at least 1 agent succeeds, proceed with partial results (log W001 for failed agents).
93
+ ### Phase Gates (MANDATORY, BLOCKING)
94
+
95
+ **GATE 1: Discovery → Generation** (Phase 1 → Phase 2)
96
+ - REQUIRED: At least 1 of 3 agents returned valid pattern results.
97
+ - BLOCKED if all 3 agents return empty results (E002).
98
+
99
+ **GATE 2: Generation → Write** (Phase 2 → Phase 3)
100
+ - REQUIRED: At least 1 pattern meets `--min-count` threshold.
101
+ - REQUIRED: User confirmed pattern groups via AskUserQuestion.
102
+ - BLOCKED if `--scan-only` is set — stop after summary.
103
+
104
+ **GATE 3: Write → Validation** (Phase 3 → KG Index)
105
+ - REQUIRED: extractors.yaml written with valid schema.
106
+ - REQUIRED: `maestro kg index` executed to verify extraction.
107
+ - BLOCKED if schema validation fails on generated YAML.
82
108
 
83
109
  ### Phase 2: Generate rules
84
110
 
@@ -44,11 +44,35 @@ $ARGUMENTS — type token + description + optional flags.
44
44
  | No args | — | — | AskUserQuestion (10 options) |
45
45
 
46
46
  **Output**: `.workflow/knowhow/{PREFIX}-{YYYYMMDD}-{slug}.md` with YAML frontmatter (title, description, type, category, created, tags, source, lang, status)
47
+
48
+ **Output boundary**: ALL file writes MUST target `.workflow/knowhow/` only. NEVER modify source code or files outside this path.
47
49
  </context>
48
50
 
51
+ <invariants>
52
+ 1. **Description required** — every entry MUST have a `description` field in frontmatter (under 120 chars) for search indexing
53
+ 2. **Tags language match** — tags MUST match content language (Chinese content → Chinese tags, English → English)
54
+ 3. **ID uniqueness** — generated file names ({PREFIX}-{YYYYMMDD}-{slug}.md) MUST be unique; NEVER overwrite existing entries
55
+ 4. **Frontmatter completeness** — YAML frontmatter MUST include: title, description, type, category, created, tags, status
56
+ 5. **Type-specific validation** — each type MUST populate all its required fields before writing (template needs code block, recipe needs steps, etc.)
57
+ 6. **Idempotent naming** — same content captured twice MUST produce same slug, enabling dedup detection
58
+ </invariants>
59
+
49
60
  <execution>
50
61
  Follow '~/.maestro/workflows/knowhow.md' completely.
51
62
 
63
+ ### Phase Gates (MANDATORY, BLOCKING)
64
+
65
+ **GATE 1: Type Detection → Content Collection** (Type routing → Content extraction)
66
+ - REQUIRED: Type detected from first token or selected via AskUserQuestion.
67
+ - REQUIRED: Type maps to a valid prefix (KNW-/TPL-/RCP-/REF-/DCS-/TIP-/AST-/BLP-/DOC-/INS-).
68
+ - BLOCKED if type unresolvable after interactive prompt.
69
+
70
+ **GATE 2: Content Collection → Write** (Content extraction → File write)
71
+ - REQUIRED: All type-specific required fields populated (e.g., template needs code block, recipe needs steps).
72
+ - REQUIRED: `description` field generated or provided (under 120 chars).
73
+ - REQUIRED: Tags generated in correct language matching content.
74
+ - BLOCKED if required fields missing after user prompt (E002/E003).
75
+
52
76
  **Description rule**: Every entry MUST have a `description` field in frontmatter — a one-line summary (under 120 chars) for search results. WikiIndexer uses priority chain: `description > content[:240]`. Use `--description` flag value if provided; otherwise auto-generate from content.
53
77
 
54
78
  **Tags language rule**: Tags must match content language. Chinese content → Chinese tags (如 `认证,令牌,刷新`). English content → English tags. Mixed → bilingual.
@@ -24,6 +24,8 @@ Arguments: $ARGUMENTS
24
24
 
25
25
  Dual store architecture (paths, formats, index) defined in workflow knowhow.md.
26
26
 
27
+ **Output boundary**: Workflow store writes MUST target `.workflow/knowhow/` only. System store writes MUST target `~/.claude/projects/*/memory/` only. NEVER modify source code or files outside these paths.
28
+
27
29
  **Subcommands:**
28
30
  - `list` — List entries from both stores (default if no arguments)
29
31
  - `search <query>` — Full-text search across both stores
@@ -44,8 +46,32 @@ Dual store architecture (paths, formats, index) defined in workflow knowhow.md.
44
46
 
45
47
  <execution>
46
48
  Follow '~/.maestro/workflows/knowhow.md' Part A (KnowHow Management) completely.
49
+
50
+ ### Phase Gates (MANDATORY, BLOCKING)
51
+
52
+ **GATE 1: Parse → Execute** (Subcommand routing)
53
+ - REQUIRED: Subcommand parsed from first token (list/search/view/edit/delete/prune).
54
+ - REQUIRED: Both store paths resolved (workflow + system).
55
+ - BLOCKED if E001 (no memory stores found) or invalid subcommand.
56
+
57
+ **GATE 2: Execute → Mutate** (For destructive subcommands: delete/prune/edit)
58
+ - REQUIRED: Target entry/file resolved and exists (E002 if not found).
59
+ - REQUIRED: MEMORY.md protected from deletion (E004 — use `edit` instead).
60
+ - REQUIRED: For `prune`: at least one filter provided (E003).
61
+ - REQUIRED: User confirmation before delete/prune unless `--confirm` flag set.
62
+ - BLOCKED if target unresolvable or confirmation denied.
47
63
  </execution>
48
64
 
65
+ <invariants>
66
+ 1. **MEMORY.md protected** — NEVER delete MEMORY.md; only editable via `edit` subcommand
67
+ 2. **MEMORY.md line limit** — MUST warn (W003) when MEMORY.md exceeds 200 lines; content beyond 200 lines will be truncated at load
68
+ 3. **Confirmation on destructive ops** — `delete` and `prune` MUST require user confirmation unless `--confirm` flag is set
69
+ 4. **Store isolation** — `prune` operates on workflow store only; NEVER prune system memory files
70
+ 5. **Reference integrity** — `delete` MUST check for references from other entries before removing; warn if orphaned references would result
71
+ 6. **Dry-run safety** — `--dry-run` MUST NOT write any files; preview destructive operations only
72
+ 7. **Index consistency** — after delete/prune, workflow index MUST be updated to reflect removals
73
+ </invariants>
74
+
49
75
  <error_codes>
50
76
  | Code | Severity | Description | Stage |
51
77
  |------|----------|-------------|-------|
@@ -35,8 +35,21 @@ Arguments: $ARGUMENTS
35
35
  **互斥规则:** `--interactive`、`--mark`、`--delete`、`--purge` 四选一,同时传入多个 → E006。
36
36
 
37
37
  Flag 全集、scope 对应的扫描路径、Stage 步骤、检测算法定义在 workflow knowledge-audit.md。
38
+
39
+ **Output boundary**: ALL file writes MUST target `.workflow/specs/`, `.workflow/knowhow/`, `.workflow/.trash/knowledge-audit-{timestamp}/`, `.workflow/issues/`, or audit report files (`audit-report-*.md`, `audit-log.jsonl`). NEVER modify source code files.
38
40
  </context>
39
41
 
42
+ <invariants>
43
+ 1. **Code-as-Truth** — 代码是唯一真理源;spec/knowhow 声明 MUST 与代码实际行为一致;每个 finding 的 evidence MUST 包含代码引用(文件:行号)
44
+ 2. **Backup before mutate** — MUST create backup tarball in `.workflow/.trash/` before any file modification (E005 if backup fails)
45
+ 3. **Deprecate over delete** — 文本存储首选 `status="deprecated"` 保留历史;NEVER 物理删除 spec/knowhow 文件
46
+ 4. **Purge 仅 artifact** — `--purge` MUST NOT 作用于 spec/knowhow scope (E004)
47
+ 5. **Rescue before delete** — 未 harvest 的 artifact 删除前 MUST 强制提示先跑 `/manage-harvest` (W002)
48
+ 6. **Conflict marker sync** — deprecate/delete 执行时如果目标条目有 conflict-marker,MUST 同步调用 `maestro spec conflict clear` 清除标记
49
+ 7. **Mutual exclusion** — `--interactive`/`--mark`/`--delete`/`--purge` 四选一;同时传入多个 MUST trigger E006
50
+ 8. **Dry-run safety** — `--dry-run` MUST NOT write any files; `--purge` 与 `--dry-run` 互斥 (E003)
51
+ </invariants>
52
+
40
53
  <execution>
41
54
  Follow `~/.maestro/workflows/knowledge-audit.md` Stages 1-8 in order.
42
55