pi-maestro-flow 0.2.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 (179) hide show
  1. package/README.md +124 -0
  2. package/agents/aggregator.md +27 -0
  3. package/agents/cli-explore-agent.md +188 -0
  4. package/agents/cross-role-reviewer.md +171 -0
  5. package/agents/delegate.md +19 -0
  6. package/agents/explorer.md +23 -0
  7. package/agents/impeccable-agent.md +99 -0
  8. package/agents/ralph-executor.md +81 -0
  9. package/agents/reference.md +24 -0
  10. package/agents/role-design-author.md +220 -0
  11. package/agents/team-supervisor.md +143 -0
  12. package/agents/team-worker.md +237 -0
  13. package/agents/ui-design-agent.md +270 -0
  14. package/agents/workflow-analyzer.md +116 -0
  15. package/agents/workflow-codebase-mapper.md +77 -0
  16. package/agents/workflow-collab-planner.md +147 -0
  17. package/agents/workflow-debugger.md +104 -0
  18. package/agents/workflow-executor.md +133 -0
  19. package/agents/workflow-external-researcher.md +86 -0
  20. package/agents/workflow-integration-checker.md +83 -0
  21. package/agents/workflow-nyquist-auditor.md +85 -0
  22. package/agents/workflow-phase-researcher.md +85 -0
  23. package/agents/workflow-plan-checker.md +100 -0
  24. package/agents/workflow-planner.md +200 -0
  25. package/agents/workflow-project-researcher.md +74 -0
  26. package/agents/workflow-research-synthesizer.md +70 -0
  27. package/agents/workflow-reviewer.md +82 -0
  28. package/agents/workflow-roadmapper.md +81 -0
  29. package/agents/workflow-verifier.md +120 -0
  30. package/package.json +58 -0
  31. package/skills/codify-to-knowhow/SKILL.md +167 -0
  32. package/skills/delegation-check/SKILL.md +297 -0
  33. package/skills/domain-add/SKILL.md +75 -0
  34. package/skills/insight-challenge/SKILL.md +226 -0
  35. package/skills/learn-decompose/SKILL.md +124 -0
  36. package/skills/learn-follow/SKILL.md +163 -0
  37. package/skills/learn-investigate/SKILL.md +160 -0
  38. package/skills/learn-second-opinion/SKILL.md +128 -0
  39. package/skills/maestro/SKILL.md +239 -0
  40. package/skills/maestro-amend/SKILL.md +169 -0
  41. package/skills/maestro-analyze/SKILL.md +173 -0
  42. package/skills/maestro-blueprint/SKILL.md +159 -0
  43. package/skills/maestro-brainstorm/SKILL.md +193 -0
  44. package/skills/maestro-collab/SKILL.md +181 -0
  45. package/skills/maestro-companion/SKILL.md +536 -0
  46. package/skills/maestro-composer/SKILL.md +192 -0
  47. package/skills/maestro-execute/SKILL.md +193 -0
  48. package/skills/maestro-fork/SKILL.md +104 -0
  49. package/skills/maestro-grill/SKILL.md +151 -0
  50. package/skills/maestro-guard/SKILL.md +124 -0
  51. package/skills/maestro-help/SKILL.md +328 -0
  52. package/skills/maestro-impeccable/SKILL.md +302 -0
  53. package/skills/maestro-init/SKILL.md +151 -0
  54. package/skills/maestro-merge/SKILL.md +90 -0
  55. package/skills/maestro-milestone-audit/SKILL.md +117 -0
  56. package/skills/maestro-milestone-complete/SKILL.md +133 -0
  57. package/skills/maestro-milestone-release/SKILL.md +131 -0
  58. package/skills/maestro-next/SKILL.md +269 -0
  59. package/skills/maestro-overlay/SKILL.md +203 -0
  60. package/skills/maestro-plan/SKILL.md +194 -0
  61. package/skills/maestro-player/SKILL.md +184 -0
  62. package/skills/maestro-quick/SKILL.md +117 -0
  63. package/skills/maestro-ralph/SKILL.md +905 -0
  64. package/skills/maestro-ralph-cli/SKILL.md +976 -0
  65. package/skills/maestro-ralph-cli-execute/SKILL.md +229 -0
  66. package/skills/maestro-ralph-execute/SKILL.md +409 -0
  67. package/skills/maestro-ralph-v2/SKILL.md +1198 -0
  68. package/skills/maestro-roadmap/SKILL.md +157 -0
  69. package/skills/maestro-swarm-workflow/SKILL.md +272 -0
  70. package/skills/maestro-tools-execute/SKILL.md +143 -0
  71. package/skills/maestro-tools-register/SKILL.md +192 -0
  72. package/skills/maestro-ui-codify/SKILL.md +127 -0
  73. package/skills/maestro-universal-workflow/SKILL.md +622 -0
  74. package/skills/maestro-update/SKILL.md +156 -0
  75. package/skills/manage-codebase-rebuild/SKILL.md +111 -0
  76. package/skills/manage-drift-realign/SKILL.md +159 -0
  77. package/skills/manage-harvest/SKILL.md +121 -0
  78. package/skills/manage-issue/SKILL.md +88 -0
  79. package/skills/manage-issue-discover/SKILL.md +104 -0
  80. package/skills/manage-kg-extractors/SKILL.md +147 -0
  81. package/skills/manage-knowhow/SKILL.md +102 -0
  82. package/skills/manage-knowhow-capture/SKILL.md +109 -0
  83. package/skills/manage-knowledge-audit/SKILL.md +147 -0
  84. package/skills/manage-status/SKILL.md +80 -0
  85. package/skills/manage-wiki/SKILL.md +104 -0
  86. package/skills/odyssey-debug/SKILL.md +344 -0
  87. package/skills/odyssey-improve/SKILL.md +423 -0
  88. package/skills/odyssey-planex/SKILL.md +542 -0
  89. package/skills/odyssey-review-test-fix/SKILL.md +392 -0
  90. package/skills/odyssey-ui/SKILL.md +388 -0
  91. package/skills/prompt-generator/SKILL.md +470 -0
  92. package/skills/quality-auto-test/SKILL.md +168 -0
  93. package/skills/quality-debug/SKILL.md +176 -0
  94. package/skills/quality-refactor/SKILL.md +108 -0
  95. package/skills/quality-retrospective/SKILL.md +134 -0
  96. package/skills/quality-review/SKILL.md +169 -0
  97. package/skills/quality-sync/SKILL.md +90 -0
  98. package/skills/quality-test/SKILL.md +183 -0
  99. package/skills/scholar-anti-ai-writing/SKILL.md +173 -0
  100. package/skills/scholar-anti-ai-writing/references/patterns-chinese.md +242 -0
  101. package/skills/scholar-anti-ai-writing/references/patterns-english.md +242 -0
  102. package/skills/scholar-citation-verify/SKILL.md +166 -0
  103. package/skills/scholar-citation-verify/references/api-usage.md +372 -0
  104. package/skills/scholar-citation-verify/references/common-errors.md +384 -0
  105. package/skills/scholar-citation-verify/references/verification-rules.md +399 -0
  106. package/skills/scholar-experiment/SKILL.md +321 -0
  107. package/skills/scholar-ideation/SKILL.md +288 -0
  108. package/skills/scholar-latex-organizer/SKILL.md +186 -0
  109. package/skills/scholar-publish/SKILL.md +220 -0
  110. package/skills/scholar-rebuttal-pro/README.md +313 -0
  111. package/skills/scholar-rebuttal-pro/SKILL.md +511 -0
  112. package/skills/scholar-review/SKILL.md +227 -0
  113. package/skills/scholar-thesis-docx/README.md +111 -0
  114. package/skills/scholar-thesis-docx/README_EN.md +108 -0
  115. package/skills/scholar-thesis-docx/SKILL.md +212 -0
  116. package/skills/scholar-thesis-docx/references/failure-patterns-and-quality-gates.md +178 -0
  117. package/skills/scholar-thesis-docx/references/figure-and-code-rules.md +33 -0
  118. package/skills/scholar-thesis-docx/references/paper-format-workflow.md +68 -0
  119. package/skills/scholar-thesis-docx/references/script-usage.md +157 -0
  120. package/skills/scholar-thesis-docx/scripts/audit_docx_ooxml.py +429 -0
  121. package/skills/scholar-thesis-docx/scripts/check_word_com.ps1 +50 -0
  122. package/skills/scholar-thesis-docx/scripts/export_word_pdf.ps1 +62 -0
  123. package/skills/scholar-thesis-docx/scripts/normalize_word_styles.ps1 +498 -0
  124. package/skills/scholar-thesis-docx/scripts/render_mermaid_figure.ps1 +148 -0
  125. package/skills/scholar-writing/SKILL.md +296 -0
  126. package/skills/security-audit/SKILL.md +244 -0
  127. package/skills/skill-generator/SKILL.md +472 -0
  128. package/skills/skill-iter-tune/SKILL.md +382 -0
  129. package/skills/skill-simplify/SKILL.md +63 -0
  130. package/skills/skill-tuning/SKILL.md +174 -0
  131. package/skills/spec-add/SKILL.md +105 -0
  132. package/skills/spec-load/SKILL.md +98 -0
  133. package/skills/spec-remove/SKILL.md +74 -0
  134. package/skills/spec-setup/SKILL.md +75 -0
  135. package/skills/team-adversarial-swarm/SKILL.md +233 -0
  136. package/skills/team-adversarial-swarm/scripts/__pycache__/pheromone.cpython-313.pyc +0 -0
  137. package/skills/team-adversarial-swarm/scripts/__pycache__/scoring.cpython-313.pyc +0 -0
  138. package/skills/team-adversarial-swarm/scripts/aco.py +473 -0
  139. package/skills/team-adversarial-swarm/scripts/pheromone.py +144 -0
  140. package/skills/team-adversarial-swarm/scripts/scoring.py +92 -0
  141. package/skills/team-adversarial-swarm/scripts/test_aco.py +475 -0
  142. package/skills/team-arch-opt/SKILL.md +158 -0
  143. package/skills/team-brainstorm/SKILL.md +171 -0
  144. package/skills/team-coordinate/SKILL.md +266 -0
  145. package/skills/team-designer/SKILL.md +160 -0
  146. package/skills/team-executor/SKILL.md +189 -0
  147. package/skills/team-frontend/SKILL.md +136 -0
  148. package/skills/team-frontend-debug/SKILL.md +198 -0
  149. package/skills/team-interactive-craft/SKILL.md +141 -0
  150. package/skills/team-issue/SKILL.md +171 -0
  151. package/skills/team-lifecycle-v4/SKILL.md +209 -0
  152. package/skills/team-motion-design/SKILL.md +142 -0
  153. package/skills/team-perf-opt/SKILL.md +175 -0
  154. package/skills/team-planex/SKILL.md +137 -0
  155. package/skills/team-quality-assurance/SKILL.md +147 -0
  156. package/skills/team-review/SKILL.md +147 -0
  157. package/skills/team-roadmap-dev/SKILL.md +169 -0
  158. package/skills/team-swarm/SKILL.md +178 -0
  159. package/skills/team-swarm/scripts/aco.py +473 -0
  160. package/skills/team-swarm/scripts/pheromone.py +144 -0
  161. package/skills/team-swarm/scripts/scoring.py +92 -0
  162. package/skills/team-swarm/scripts/test_aco.py +475 -0
  163. package/skills/team-tech-debt/SKILL.md +128 -0
  164. package/skills/team-testing/SKILL.md +143 -0
  165. package/skills/team-ui-polish/SKILL.md +141 -0
  166. package/skills/team-uidesign/SKILL.md +144 -0
  167. package/skills/team-ultra-analyze/SKILL.md +173 -0
  168. package/skills/team-ux-improve/SKILL.md +151 -0
  169. package/skills/team-visual-a11y/SKILL.md +156 -0
  170. package/skills/workflow-skill-designer/SKILL.md +496 -0
  171. package/src/extension/index.ts +222 -0
  172. package/src/extension/schemas.ts +131 -0
  173. package/src/providers/cli-tools-loader.ts +74 -0
  174. package/src/providers/provider-registry.ts +130 -0
  175. package/src/tools/delegate.ts +85 -0
  176. package/src/tools/explore.ts +134 -0
  177. package/src/tools/moa.ts +213 -0
  178. package/src/tools/status.ts +99 -0
  179. package/src/tools/wait.ts +166 -0
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: manage-status
3
+ description: "Show project dashboard with progress and next steps Arguments: "
4
+ allowed-tools: Read Bash Glob Grep
5
+ ---
6
+
7
+ <purpose>
8
+ Project dashboard: artifact progress, task counts, active work, next-step suggestions.
9
+ </purpose>
10
+
11
+ <required_reading>
12
+ @~/.maestro/workflows/status.md
13
+ </required_reading>
14
+
15
+ <context>
16
+ $ARGUMENTS (no arguments required)
17
+
18
+ **State files read:**
19
+ - `.workflow/state.json` -- project-level state machine + artifact registry
20
+ - `.workflow/roadmap.md` -- milestone and phase structure
21
+ - `.workflow/scratch/*/plan.json` -- plan metadata (via artifact registry paths)
22
+ - `.workflow/scratch/*/.task/TASK-*.json` -- individual task statuses
23
+
24
+ **Output boundary**: Read-only command. MUST NOT write any files. All output is displayed to the user via text.
25
+ </context>
26
+
27
+ <invariants>
28
+ 1. **Read-only** — MUST NOT write or modify any files; this is a pure display command
29
+ 2. **Graceful degradation** — missing roadmap.md, plan.json, or task files MUST NOT cause failure; display available data and note missing sections
30
+ 3. **State accuracy** — progress percentages MUST be calculated from actual task statuses, NEVER estimated or inferred
31
+ 4. **Wiki health optional** — wiki health score display MUST degrade gracefully if wiki is unavailable
32
+ 5. **Complete dashboard** — MUST include: milestone progress, phase status, task counts, active work, and next-step suggestions
33
+ </invariants>
34
+
35
+ <execution>
36
+ Follow '~/.maestro/workflows/status.md' completely.
37
+
38
+ Next-step decision table defined in workflow status.md Step 5.
39
+
40
+ ### Phase Gates (MANDATORY, BLOCKING)
41
+
42
+ **GATE 1: Load → Render** (State loading → Dashboard display)
43
+ - REQUIRED: `.workflow/` exists and `state.json` is readable (E001/E002 if not).
44
+ - REQUIRED: Project state loaded with milestone and artifact registry.
45
+ - BLOCKED if state.json missing or corrupt (E002).
46
+
47
+ **GATE 2: Render → Route** (Dashboard → Next-step suggestions)
48
+ - REQUIRED: Per-phase progress calculated from actual task statuses.
49
+ - REQUIRED: Dashboard rendered with progress bars and status table.
50
+ - BLOCKED if state parsing fails entirely.
51
+ </execution>
52
+
53
+ <error_codes>
54
+ | Code | Severity | Description | Stage |
55
+ |------|----------|-------------|-------|
56
+ | E001 | fatal | `.workflow/` not initialized -- run `/maestro-init` first | parse_input |
57
+ | E002 | fatal | `state.json` missing or corrupt -- project state unrecoverable | parse_input |
58
+ </error_codes>
59
+
60
+ <success_criteria>
61
+ - [ ] Project state loaded from `state.json`
62
+ - [ ] Roadmap parsed with milestone/phase structure
63
+ - [ ] Per-phase progress calculated (task counts, completion %)
64
+ - [ ] Dashboard rendered with progress bars and status table
65
+ - [ ] Active work section shows current phase details
66
+ - [ ] Next steps suggested based on current state analysis
67
+ - [ ] Wiki health score displayed (or graceful unavailable message)
68
+ </success_criteria>
69
+
70
+ <completion>
71
+ ### Next-step routing
72
+
73
+ | Condition | Suggestion |
74
+ |-----------|-----------|
75
+ | Phase needs analysis | `/maestro-analyze {phase}` |
76
+ | Phase needs planning | `/maestro-plan {phase}` |
77
+ | Phase needs execution | `/maestro-execute {phase}` |
78
+ | Milestone ready for audit | `/maestro-milestone-audit` |
79
+ | Issues need triage | `/manage-issue list` |
80
+ </completion>
@@ -0,0 +1,104 @@
1
+ ---
2
+ name: manage-wiki
3
+ description: "Manage wiki graph — health, cleanup, search, stats Arguments: <subcommand: health|search|cleanup|stats|connect|digest> [query] [--fix] [--dry-run]"
4
+ allowed-tools: Read Write Edit Bash Glob Grep AskUserQuestion
5
+ ---
6
+
7
+ <purpose>
8
+ Wiki graph management: health, search, cleanup, stats, connect, digest.
9
+ </purpose>
10
+
11
+ <required_reading>
12
+ @~/.maestro/workflows/wiki-manage.md
13
+ </required_reading>
14
+
15
+ <context>
16
+ $ARGUMENTS — subcommand and optional flags.
17
+
18
+ **Subcommands:**
19
+ | Subcommand | Description |
20
+ |-----------|-------------|
21
+ | `health` | Health dashboard — score, broken links, orphans, hubs (default) |
22
+ | `search <query>` | Interactive BM25 search with follow-up actions |
23
+ | `cleanup` | Find and resolve orphans, broken links, stale entries |
24
+ | `stats` | Graph statistics — type distribution, tag frequency, growth trends |
25
+ | `connect` | Find and link hidden connections — orphan rescue, missing links, transitive gaps |
26
+ | `digest [topic]` | Generate knowledge digest with theme clustering and gap analysis |
27
+ | No args | Same as `health` |
28
+
29
+ **Flags:**
30
+ - `--type <type>` — Filter by wiki type: spec, knowhow, note, issue
31
+ - `--fix` — Auto-fix issues found during cleanup/connect (remove broken links, apply connections)
32
+ - `--dry-run` — Preview mode, no writes. **Overrides `--fix`**: when both are passed, `--dry-run` takes precedence (preview only, no fixes applied).
33
+ - `--json` — Output in JSON format
34
+ - `--min-similarity N` — (connect) Minimum similarity threshold for link candidates
35
+ - `--max N` — (connect) Maximum number of suggestions
36
+ - `--format brief|full` — (digest) Output format
37
+ - `--recent N` — (digest) Scope to N most recent entries
38
+ - `--create-issues` — (digest) Create issues for identified knowledge gaps
39
+
40
+ **Output boundary**: File writes MUST target `.workflow/wiki/`, `.workflow/knowhow/`, or `.workflow/issues/issues.jsonl` (when `--create-issues`) only. NEVER modify source code or files outside these paths. `--dry-run` overrides `--fix` — no writes when both are set.
41
+ </context>
42
+
43
+ <invariants>
44
+ 1. **Dry-run precedence** — `--dry-run` MUST override `--fix` when both are passed; preview only, no writes
45
+ 2. **Read-only by default** — without `--fix` or `--create-issues`, all subcommands MUST be read-only
46
+ 3. **Confirmation on fixes** — `--fix` MUST show preview of changes before applying; auto-apply only when explicitly set
47
+ 4. **Graph integrity** — `connect` MUST NOT create circular link chains; validate graph acyclicity for parent-child relationships
48
+ 5. **Threshold enforcement** — `--min-similarity` MUST be respected; NEVER suggest connections below the threshold
49
+ 6. **Subcommand isolation** — each subcommand routes to its own workflow file; NEVER cross-execute subcommand logic
50
+ </invariants>
51
+
52
+ <execution>
53
+ **Subcommand routing:**
54
+ - `health|search|cleanup|stats` → Follow `~/.maestro/workflows/wiki-manage.md` completely.
55
+ - `connect` → Follow `~/.maestro/workflows/wiki-connect.md` completely (Stages 1-6).
56
+ - `digest` → Follow `~/.maestro/workflows/wiki-digest.md` completely (Stages 1-8).
57
+
58
+ ### Phase Gates (MANDATORY, BLOCKING)
59
+
60
+ **GATE 1: Parse → Load** (Subcommand routing → Wiki data loading)
61
+ - REQUIRED: Subcommand parsed and validated (health/search/cleanup/stats/connect/digest).
62
+ - REQUIRED: `.workflow/` initialized (E001 if missing).
63
+ - BLOCKED if E003 (invalid subcommand) or E001.
64
+
65
+ **GATE 2: Load → Execute** (Wiki data → Subcommand execution)
66
+ - REQUIRED: Wiki data loaded via `maestro wiki` CLI.
67
+ - REQUIRED: At least one wiki entry exists (E002 if none).
68
+ - BLOCKED if wiki data loading fails entirely.
69
+
70
+ **GATE 3: Execute → Write** (For mutating operations: cleanup --fix, connect --fix, digest --create-issues)
71
+ - REQUIRED: Preview of changes shown to user.
72
+ - REQUIRED: `--dry-run` NOT set (overrides `--fix`).
73
+ - BLOCKED if preview generation fails or user declines.
74
+ </execution>
75
+
76
+ <error_codes>
77
+ | Code | Severity | Description | Stage |
78
+ |------|----------|-------------|-------|
79
+ | E001 | fatal | `.workflow/` not initialized — run `/maestro-init` first | validate |
80
+ | E002 | fatal | No wiki entries found — create content first | load |
81
+ | E003 | error | Invalid subcommand | parse_input |
82
+ | W001 | warning | Health score below 50 — graph needs attention | health |
83
+ | W002 | warning | Orphan cleanup had partial failures | cleanup |
84
+ </error_codes>
85
+
86
+ <success_criteria>
87
+ - [ ] Subcommand parsed (health/search/cleanup/stats/connect/digest)
88
+ - [ ] Wiki data loaded via `maestro wiki` CLI
89
+ - [ ] Results displayed in formatted output
90
+ - [ ] If cleanup/connect --fix: issues resolved and delta reported
91
+ - [ ] If digest: themes clustered, gaps identified, coverage heatmap generated
92
+ - [ ] Next-step suggestions provided
93
+ </success_criteria>
94
+
95
+ <completion>
96
+ ### Next-step routing
97
+
98
+ | Condition | Suggestion |
99
+ |-----------|-----------|
100
+ | Health score < 50 | `/manage-wiki cleanup --fix` |
101
+ | Orphan entries found | `/manage-wiki connect --fix` |
102
+ | Knowledge gaps identified | `/manage-knowhow-capture` |
103
+ | Want knowledge synthesis | `/manage-wiki digest` |
104
+ </completion>
@@ -0,0 +1,344 @@
1
+ ---
2
+ name: odyssey-debug
3
+ description: "Long-running debug cycle — archaeology, diagnosis, fix, confirmation, generalization, discovery, and knowledge persistence Arguments: <issue> [--template <name>] [--skip-fix] [--skip-generalize] [--auto] [-y] [-c] [--heartbeat]"
4
+ allowed-tools: Read Write Edit Bash Glob Grep Agent AskUserQuestion
5
+ ---
6
+
7
+ <base>@~/.maestro/workflows/odyssey-base.md</base>
8
+
9
+ <purpose>
10
+ archaeology → explore → diagnose → fix & confirm → generalize → discover siblings → persist.
11
+ Exhaustive iteration until root cause confirmed or INCONCLUSIVE.
12
+ </purpose>
13
+
14
+ <boundary>
15
+ **In scope:** Single bug/issue full loop.
16
+ **Out of scope:** Features → `/odyssey-planex` | Quality review → `/odyssey-review-test-fix` | UI → `/odyssey-ui` | Architecture → `/maestro-plan`
17
+
18
+ **`--template <name>`:**
19
+
20
+ | Template | Strategy | Use case |
21
+ |----------|----------|----------|
22
+ | `performance` | profiling → hot path → allocation → cache | Performance degradation |
23
+ | `memory-leak` | heap snapshot → retention chain → lifecycle | Memory leaks |
24
+ | `race-condition` | timeline → concurrent access → lock analysis | Race conditions |
25
+ | `regression` | git bisect → diff analysis → boundary check | Regressions |
26
+ | `crash` | stack trace → null chain → error propagation | Crashes / exceptions |
27
+ </boundary>
28
+
29
+ <context>
30
+ $ARGUMENTS
31
+
32
+ **Flags:** `--skip-fix` analysis-only | `--skip-generalize` quick fix | `--template <name>` | `--auto` no delegate confirmation | `-y` auto-confirm | `-c` resume | `--heartbeat` /loop heartbeat
33
+
34
+ **Session**: `.workflow/scratch/{YYYYMMDD}-debug-odyssey-{slug}/`
35
+ **Output**: `session.json` | `evidence.ndjson` | `explore.json` | `understanding.md`
36
+
37
+ **session.json — debug-specific fields:**
38
+ ```json
39
+ { "issue": "", "diagnosis_retries": 0, "root_cause": null, "confirmation": null,
40
+ "patterns": [], "generalization_stats": null }
41
+ ```
42
+
43
+ **evidence.ndjson phases:** `archaeology|explore|diagnosis|discovery|decision|self-iteration`
44
+ - `archaeology`: `sha`, `author`, `date`, `message`, `relevance`
45
+ - `explore`: `category` (call_chain|recent_change|error_gap|similar_pattern), `detail`
46
+ - `diagnosis`: `hypothesis`, `result` (confirmed|disproved|inconclusive)
47
+ - `discovery`: `file`, `line`, `classification` (safe|risk|bug), `action` (fix|issue|decision|skip)
48
+ - `decision`: `question`, `options`, `context`, `status`, `resolution`
49
+ - `self-iteration`: `stage`, `round`, `assessment`, `expansion`
50
+
51
+ **explore.json**: `{call_chains, recent_changes, error_gaps, similar_patterns, cli_tool, timestamp}`
52
+
53
+ **phase_goals[]:**
54
+
55
+ | ID | Goal | done_when | phase | skip_when |
56
+ |----|------|-----------|-------|-----------|
57
+ | G1 | Root cause identified | phase=diagnosis result=confirmed | S_DIAGNOSE | — |
58
+ | G2 | Explore context gathered | explore.json ≥1 category | S_EXPLORE | — |
59
+ | G3 | Fix applied and confirmed | confirmation.overall == confirmed | S_CONFIRM | skip_fix |
60
+ | G4 | Pattern generalized | patterns[] ≥1 entry | S_GENERALIZE | skip_generalize |
61
+ | G5 | Discoveries triaged | all scan hits classified | S_DISCOVER | skip_generalize |
62
+ | G6 | Learnings persisted | spec entries created OR none actionable | S_RECORD | — |
63
+
64
+ **understanding.md — 9 sections:**
65
+ 1. Issue & Scope ← S_INTAKE | 2. Archaeology ← S_ARCHAEOLOGY | 3. Exploration ← S_EXPLORE
66
+ 4. Hypotheses ← S_DIAGNOSE | 5. Root Cause ← S_DIAGNOSE | 6. Fix & Confirmation ← S_FIX+S_CONFIRM
67
+ 7. Generalization ← S_GENERALIZE | 8. Discoveries ← S_DISCOVER | 9. Learnings ← S_RECORD
68
+
69
+ **Knowledge Persistence categories (§9):**
70
+
71
+ | Category | Content | Follow-up |
72
+ |----------|---------|-----------|
73
+ | Recurring root cause pattern | Type + triggers + fix + detection | `/spec-add debug` |
74
+ | Non-obvious workaround | Problem + steps + why obvious fix fails | `/spec-add learning` |
75
+ | Architecture boundary violation | Violation + correct boundary + verification | `/spec-add arch` |
76
+ | Reusable generalization pattern | Signature + risk + fix template + scope | `/spec-add coding` |
77
+ </context>
78
+
79
+ <invariants>
80
+ 1. **Evidence append-only** — never delete or overwrite evidence.ndjson entries
81
+ 2. **Phase goal tracking** — mark goal done/failed before transition; no silent skips
82
+ 3. **Generalize is mandatory** — S_GENERALIZE and S_DISCOVER execute unless `skip_generalize == true`. "No findings" from prior phases, convergence signals, or context pressure are NOT valid reasons to skip. The phase itself determines whether patterns exist.
83
+ </invariants>
84
+
85
+ <self_iteration>
86
+ Applies to: **S_ARCHAEOLOGY, S_EXPLORE, S_DIAGNOSE, S_GENERALIZE**. Logic in base.
87
+ </self_iteration>
88
+
89
+ <state_machine>
90
+
91
+ <states>
92
+ S_INTAKE → S_ARCHAEOLOGY → S_EXPLORE → S_DIAGNOSE → S_FIX → S_CONFIRM → S_GENERALIZE → S_DISCOVER → S_RECORD → END
93
+ </states>
94
+
95
+ <transitions>
96
+ S_INTAKE → S_INTAKE : -c + session found → A_RESUME_SESSION
97
+ S_INTAKE → S_ARCHAEOLOGY : issue parsed → A_INTAKE
98
+ S_INTAKE → S_INTAKE : no issue, no session → AskUserQuestion
99
+
100
+ S_ARCHAEOLOGY → S_EXPLORE : complete
101
+ S_EXPLORE → S_DIAGNOSE : complete
102
+
103
+ S_DIAGNOSE → S_FIX : confirmed, !skip_fix
104
+ S_DIAGNOSE → S_GENERALIZE : confirmed, skip_fix, !skip_generalize
105
+ S_DIAGNOSE → S_RECORD : confirmed, skip_fix, skip_generalize
106
+ S_DIAGNOSE → S_DIAGNOSE : all hypotheses failed, retries < 3 → A_ESCALATE_DIAGNOSIS
107
+ S_DIAGNOSE → S_RECORD : retries >= 3 → INCONCLUSIVE
108
+
109
+ S_FIX → S_CONFIRM : fix implemented
110
+ S_CONFIRM → S_GENERALIZE : confirmed, !skip_generalize
111
+ S_CONFIRM → S_RECORD : confirmed, skip_generalize
112
+ S_CONFIRM → S_FIX : needs_rework
113
+
114
+ S_GENERALIZE → S_DISCOVER : similar code found
115
+ S_GENERALIZE → S_RECORD : all 3 layers scanned with evidence, total_hits == 0
116
+
117
+ S_DISCOVER → S_DIAGNOSE : new bug → cross_phase_loops++
118
+ S_DISCOVER → S_FIX : same-pattern bug + fix_template, !skip_fix → cross_phase_loops++
119
+ S_DISCOVER → S_RECORD : remaining_actionable == 0
120
+ S_DISCOVER → S_RECORD : loops >= max_loops → log per-item reasons
121
+
122
+ S_RECORD → END : complete
123
+ </transitions>
124
+
125
+ <actions>
126
+
127
+ ### A_INTAKE
128
+ 1. Parse arguments, generate slug, create SESSION_DIR
129
+ 2. `maestro search "<keywords>"` + Glob prior sessions + ARCHITECTURE.md + Grep keywords
130
+ 3. Derive `phase_goals[]` from flags
131
+ 4. Write `session.json` + `understanding.md` §1, emit Goal Prompt
132
+
133
+ Commit: `"odyssey-debug({slug}): INTAKE — parse target and load context"`
134
+
135
+ ### A_RESUME_SESSION
136
+ Glob latest session → read `session.json` → jump to `current_state`.
137
+
138
+ ### A_ARCHAEOLOGY
139
+ 2 parallel Agents: Timeline (`git log --oneline -20 -- {files}`) + Blame (top 3 files `git blame -L {region}`). Evidence phase=archaeology.
140
+
141
+ `maestro delegate --role analyze --mode analysis` (`run_in_background: true`):
142
+ - PURPOSE: Review recent modifications related to {issue}
143
+ - EXPECTED: JSON [{commit_sha, risk_level, analysis, could_cause_issue, explanation}]
144
+
145
+ Update §2. Commit: `"odyssey-debug({slug}): ARCHAEOLOGY — git history analysis"`
146
+
147
+ ### A_EXPLORE
148
+ Skip if no CLI tools (W006).
149
+
150
+ `maestro delegate --role explore --mode analysis` (`run_in_background: true`):
151
+ - PURPOSE: Call chains, recent changes, error gaps, similar patterns
152
+ - EXPECTED: JSON {call_chains, recent_changes, error_gaps, similar_patterns}
153
+
154
+ Write `explore.json` + evidence phase=explore. Update §3. Mark G2. Commit: `"odyssey-debug({slug}): EXPLORE — codebase exploration"`
155
+
156
+ ### A_DIAGNOSE
157
+ 1. Hypotheses from evidence, ranked [HIGH]/[MEDIUM]/[LOW] → §4
158
+ 2. Test each → evidence phase=diagnosis
159
+ 3. Ambiguity → evidence phase=decision; Normal: AskUserQuestion | `-y`: defer
160
+ 4. Confirmed → `session.json.root_cause` + §5. Mark G1.
161
+
162
+ Commit: `"odyssey-debug({slug}): DIAGNOSE — root cause confirmed"`
163
+
164
+ ### A_ESCALATE_DIAGNOSIS
165
+ `diagnosis_retries++`. < 3: `maestro delegate --role analyze`, new hypotheses, → S_DIAGNOSE. >= 3: Normal → AskUserQuestion | `-y` → INCONCLUSIVE → S_RECORD.
166
+
167
+ ### A_FIX
168
+ 1. Present root cause + proposed fix. Normal: AskUserQuestion | `-y`: auto proceed
169
+ 2. Implement fix, evidence phase=decision
170
+
171
+ Commit: `"odyssey-debug({slug}): FIX — {summary}"`
172
+
173
+ ### A_CONFIRM
174
+ 1. Run covering tests
175
+ 2. `maestro delegate --role review --mode analysis` (`run_in_background: true`):
176
+ - EXPECTED: JSON {verdict, findings [{severity, description, suggestion}], regression_risk}
177
+ 3. `session.json.confirmation`: `{test_result, cli_review, overall: "confirmed|needs_rework"}`
178
+ 4. Update §6. `needs_rework` → S_FIX. `confirmed` → mark G3.
179
+
180
+ Commit: `"odyssey-debug({slug}): CONFIRM — fix verified"`
181
+
182
+ ### A_GENERALIZE
183
+
184
+ **MANDATORY — executes unless `skip_generalize == true`. Prior-phase convergence, "no findings," or context pressure are NOT valid skip reasons.**
185
+
186
+ Pattern source: confirmed root cause + applied fix.
187
+
188
+ **Step 1 — 3-layer pattern extraction:**
189
+
190
+ | Layer | Method | Targets |
191
+ |-------|--------|---------|
192
+ | Syntax | Build regex from fix diff → Grep | Missing `await`, unchecked null, wrong comparison, identical error-handling gap |
193
+ | Semantic | Understand anti-pattern that caused the bug → Agent scan | Same async-without-catch, same boundary assumption, race on shared state |
194
+ | Structural | Find files with same module shape / import graph | Sibling handlers, parallel service implementations, same-shape error handlers |
195
+
196
+ Write `session.json.patterns[]`: `[{id, source, layer, signature, description, risk, fix_template, confidence}]`
197
+
198
+ **Thoroughness floor:** ALL 3 layers must be attempted and logged. Each layer records search method, scope, hit count in evidence phase=generalization. "No hits" requires all 3 layers to return 0 with logged evidence — a single-layer quick grep does NOT satisfy.
199
+
200
+ **Step 2 — 4-agent concurrent scan** (single message, 4 Agents):
201
+
202
+ | Agent | Strategy | Scope |
203
+ |-------|----------|-------|
204
+ | Syntax grep | Grep regex from pattern signatures | Full project |
205
+ | Semantic scan | Anti-pattern understanding → scan same bug class | Related modules |
206
+ | Structural match | Find structurally similar files to buggy file | Full project |
207
+ | Historical grep | `git log -S` for pattern signatures | Git history |
208
+
209
+ **Step 3 — Cross-layer dedup:** multi-layer hit → boost | single-layer → `needs_review` | historically fixed → `regression_risk`
210
+
211
+ **Step 4 — Iterative deepening:** Module with ≥3 hits → targeted deep scan (max 1 round).
212
+
213
+ **Step 5 — Persist:** Update understanding.md §7 + write `session.json.generalization_stats`:
214
+ ```json
215
+ {"patterns_extracted": 0, "total_hits": 0, "cross_layer_confirmed": 0, "regression_risks": 0, "by_layer": {"syntax": 0, "semantic": 0, "structural": 0}, "deepening_triggered": false}
216
+ ```
217
+
218
+ **Transition guard:** `S_GENERALIZE → S_RECORD` requires `by_layer` has entries for all 3 layers with search evidence logged. Mark G4 done.
219
+
220
+ Commit: `"odyssey-debug({slug}): GENERALIZE — pattern scan complete"`
221
+
222
+ ### A_DISCOVER
223
+
224
+ **Executes whenever `total_hits > 0`. Cannot be skipped without `skip_generalize == true`.**
225
+
226
+ 1. **Triage** each hit with ±10 lines context → classify:
227
+ - `bug` — same defect pattern confirmed
228
+ - `risk` — potential issue needing guard
229
+ - `safe` — false positive (must log individual reason — blanket "pre-existing" forbidden)
230
+
231
+ 2. **Route:**
232
+
233
+ | Classification | Action |
234
+ |---------------|--------|
235
+ | bug + fix_template applicable | Immediate fix → back to S_FIX |
236
+ | bug + cross-module or no template | Create issue (fix suggestion + impact) |
237
+ | risk + guard addable directly | Fix directly |
238
+ | risk + complex | Create issue |
239
+ | safe | Skip with logged per-item reason |
240
+
241
+ Normal: AskUserQuestion per hit | `-y`: auto-fix bugs with fix_template, create issue for rest
242
+
243
+ 3. **Cross-phase loops:** `cross_phase_loops++` on fix/diagnose return. `loops >= max_loops` → must log per-item reasons.
244
+
245
+ 4. Append evidence phase=discovery. Update understanding.md §8. Mark G5 done.
246
+
247
+ Commit: `"odyssey-debug({slug}): DISCOVER — sibling triage complete"`
248
+
249
+ ### A_RECORD
250
+
251
+ 1. Finalize understanding.md §9 — learnings by Knowledge Persistence categories:
252
+ - Recurring root cause pattern → `/spec-add debug`
253
+ - Non-obvious workaround → `/spec-add learning`
254
+ - Architecture boundary violation → `/spec-add arch`
255
+ - Reusable generalization pattern → `/spec-add coding`
256
+
257
+ 2. Mark G6 done. Pending decisions: Normal → AskUserQuestion | `-y` → skip (show deferred count).
258
+
259
+ 3. **Goal audit (hardened):**
260
+ - `done` → confirmed
261
+ - `skipped` → confirmed ONLY if corresponding `skip_when` flag is true
262
+ - **Hard rule:** G4 and G5 CANNOT be `skipped` unless `skip_generalize == true`. Pending without flag → `failed` (Normal: AskUserQuestion | `-y`: record `failed`)
263
+ - `phase_goals_all_done = true` only when all goals pass this audit
264
+
265
+ 4. `current_state = "COMPLETED"`, emit completion summary.
266
+
267
+ **Completion summary:**
268
+ ```
269
+ --- DEBUG ODYSSEY COMPLETE ---
270
+ Issue: {issue}
271
+ Root cause: {root_cause.hypothesis}
272
+ Fix: {applied|skipped|inconclusive}
273
+ Patterns: {patterns_extracted} ({by_layer})
274
+ Scan hits: {total_hits} ({cross_layer_confirmed} confirmed)
275
+ Issues: {N} created
276
+ Decisions: {N} resolved, {M} pending, {K} deferred
277
+ Learnings: {N} persisted
278
+ Self-iter: {N} rounds across {M} stages
279
+ Goals: {done}/{total} ({skipped} skipped)
280
+ ---
281
+ ```
282
+
283
+ Commit: `"odyssey-debug({slug}): RECORD — summary and knowledge persistence"`
284
+
285
+ </actions>
286
+
287
+ <appendix>
288
+
289
+ ### `-y` debug-specific points
290
+
291
+ | Decision Point | Normal | `-y` |
292
+ |---------------|--------|------|
293
+ | A_DIAGNOSE ambiguity | AskUserQuestion | deferred |
294
+ | A_ESCALATE 3-strike | AskUserQuestion | INCONCLUSIVE |
295
+ | A_FIX direction | AskUserQuestion | auto proceed |
296
+ | A_DISCOVER hit routing | AskUserQuestion | auto-fix bugs with template, create issue for rest |
297
+
298
+ ### Goal Prompt convergence rules
299
+
300
+ ```
301
+ Stop when root cause confirmed (or INCONCLUSIVE), fix verified,
302
+ generalization exhausted, phase_goals_all_done=true.
303
+ All sibling bugs fixed or issued — no leftovers.
304
+ ```
305
+
306
+ </appendix>
307
+
308
+ </state_machine>
309
+
310
+ <error_codes>
311
+ | Code | Severity | Condition | Recovery |
312
+ |------|----------|-----------|----------|
313
+ | E001 | error | No issue, no session | Provide issue or -c |
314
+ | W001 | warning | No relevant git history | Proceed |
315
+ | W002 | warning | 3 retries exhausted | INCONCLUSIVE |
316
+ | W003 | warning | Partial archaeology agent failure (Timeline or Blame) | Proceed with available results, log failed agent |
317
+ | W005 | warning | Pending decisions | Filter evidence phase=decision |
318
+ | W006 | warning | No CLI tools | Skip explore |
319
+ | W007 | warning | Generalization 0 hits after full 3-layer scan | Advance to S_RECORD (requires all 3 layers attempted with evidence) |
320
+ </error_codes>
321
+
322
+ <success_criteria>
323
+ - [ ] Session + 4 output files + prior knowledge searched
324
+ - [ ] Archaeology + CLI review → evidence phase=archaeology
325
+ - [ ] CLI exploration → explore.json + evidence phase=explore
326
+ - [ ] Hypotheses tested, root cause with evidence refs
327
+ - [ ] understanding.md 9 sections progressive
328
+ - [ ] Fix + confirmed (unless --skip-fix)
329
+ - [ ] Generalization + scan (unless --skip-generalize)
330
+ - [ ] Discoveries classified; unfixed findings individually justified
331
+ - [ ] phase_goals + goal audit + resumable via -c
332
+ - [ ] Completion summary
333
+ </success_criteria>
334
+
335
+ <next_step_routing>
336
+ | Condition | Next |
337
+ |-----------|------|
338
+ | Discovery issues | `/manage-issue list --source debug-odyssey` |
339
+ | Document pattern | `/learn-decompose <module>` |
340
+ | Formal review | `/quality-review <phase>` |
341
+ | Second opinion | `/learn-second-opinion <understanding.md>` |
342
+ | Related question | `/learn-investigate "<question>"` |
343
+ | Pending decisions | Filter evidence phase=decision status=pending |
344
+ </next_step_routing>