maestro-flow-one 0.2.0 → 0.2.2

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 (97) hide show
  1. package/.ace-tool/index.json +108 -0
  2. package/bin/maestro-flow.js +30 -0
  3. package/claude/maestro-flow/agents/cli-explore-agent.md +187 -0
  4. package/claude/maestro-flow/agents/conceptual-planning-agent.md +245 -0
  5. package/claude/maestro-flow/agents/team-supervisor.md +143 -0
  6. package/claude/maestro-flow/agents/team-worker.md +237 -0
  7. package/claude/maestro-flow/agents/ui-design-agent.md +286 -0
  8. package/claude/maestro-flow/agents/workflow-analyzer.md +115 -0
  9. package/claude/maestro-flow/agents/workflow-codebase-mapper.md +77 -0
  10. package/claude/maestro-flow/agents/workflow-collab-planner.md +143 -0
  11. package/claude/maestro-flow/agents/workflow-debugger.md +103 -0
  12. package/claude/maestro-flow/agents/workflow-executor.md +129 -0
  13. package/claude/maestro-flow/agents/workflow-external-researcher.md +86 -0
  14. package/claude/maestro-flow/agents/workflow-integration-checker.md +83 -0
  15. package/claude/maestro-flow/agents/workflow-nyquist-auditor.md +85 -0
  16. package/claude/maestro-flow/agents/workflow-phase-researcher.md +85 -0
  17. package/claude/maestro-flow/agents/workflow-plan-checker.md +90 -0
  18. package/claude/maestro-flow/agents/workflow-planner.md +195 -0
  19. package/claude/maestro-flow/agents/workflow-project-researcher.md +74 -0
  20. package/claude/maestro-flow/agents/workflow-research-synthesizer.md +70 -0
  21. package/claude/maestro-flow/agents/workflow-reviewer.md +82 -0
  22. package/claude/maestro-flow/agents/workflow-roadmapper.md +81 -0
  23. package/claude/maestro-flow/agents/workflow-verifier.md +120 -0
  24. package/codex/maestro-flow/agents/team-supervisor.toml +40 -0
  25. package/codex/maestro-flow/agents/team-worker.toml +63 -0
  26. package/maestro-flow/agents/cli-explore-agent.md +187 -0
  27. package/maestro-flow/agents/conceptual-planning-agent.md +245 -0
  28. package/maestro-flow/agents/team-supervisor.md +143 -0
  29. package/maestro-flow/agents/team-worker.md +237 -0
  30. package/maestro-flow/agents/ui-design-agent.md +286 -0
  31. package/maestro-flow/agents/workflow-analyzer.md +115 -0
  32. package/maestro-flow/agents/workflow-codebase-mapper.md +77 -0
  33. package/maestro-flow/agents/workflow-collab-planner.md +143 -0
  34. package/maestro-flow/agents/workflow-debugger.md +103 -0
  35. package/maestro-flow/agents/workflow-executor.md +129 -0
  36. package/maestro-flow/agents/workflow-external-researcher.md +86 -0
  37. package/maestro-flow/agents/workflow-integration-checker.md +83 -0
  38. package/maestro-flow/agents/workflow-nyquist-auditor.md +85 -0
  39. package/maestro-flow/agents/workflow-phase-researcher.md +85 -0
  40. package/maestro-flow/agents/workflow-plan-checker.md +90 -0
  41. package/maestro-flow/agents/workflow-planner.md +195 -0
  42. package/maestro-flow/agents/workflow-project-researcher.md +74 -0
  43. package/maestro-flow/agents/workflow-research-synthesizer.md +70 -0
  44. package/maestro-flow/agents/workflow-reviewer.md +82 -0
  45. package/maestro-flow/agents/workflow-roadmapper.md +81 -0
  46. package/maestro-flow/agents/workflow-verifier.md +120 -0
  47. package/maestro-flow/commands/learn/decompose.md +176 -0
  48. package/maestro-flow/commands/learn/follow.md +167 -0
  49. package/maestro-flow/commands/learn/investigate.md +221 -0
  50. package/maestro-flow/commands/learn/retro.md +303 -0
  51. package/maestro-flow/commands/learn/second-opinion.md +167 -0
  52. package/maestro-flow/commands/lifecycle/amend.md +300 -0
  53. package/maestro-flow/commands/lifecycle/analyze.md +130 -0
  54. package/maestro-flow/commands/lifecycle/brainstorm.md +104 -0
  55. package/maestro-flow/commands/lifecycle/collab.md +333 -0
  56. package/maestro-flow/commands/lifecycle/composer.md +354 -0
  57. package/maestro-flow/commands/lifecycle/execute.md +120 -0
  58. package/maestro-flow/commands/lifecycle/fork.md +86 -0
  59. package/maestro-flow/commands/lifecycle/init.md +78 -0
  60. package/maestro-flow/commands/lifecycle/learn.md +140 -0
  61. package/maestro-flow/commands/lifecycle/link-coordinate.md +71 -0
  62. package/maestro-flow/commands/lifecycle/merge.md +61 -0
  63. package/maestro-flow/commands/lifecycle/overlay.md +178 -0
  64. package/maestro-flow/commands/lifecycle/plan.md +154 -0
  65. package/maestro-flow/commands/lifecycle/player.md +404 -0
  66. package/maestro-flow/commands/lifecycle/quick.md +56 -0
  67. package/maestro-flow/commands/lifecycle/roadmap.md +164 -0
  68. package/maestro-flow/commands/lifecycle/ui-design.md +93 -0
  69. package/maestro-flow/commands/lifecycle/update.md +176 -0
  70. package/maestro-flow/commands/lifecycle/verify.md +96 -0
  71. package/maestro-flow/commands/manage/codebase-rebuild.md +75 -0
  72. package/maestro-flow/commands/manage/codebase-refresh.md +57 -0
  73. package/maestro-flow/commands/manage/harvest.md +94 -0
  74. package/maestro-flow/commands/manage/issue-discover.md +77 -0
  75. package/maestro-flow/commands/manage/issue.md +73 -0
  76. package/maestro-flow/commands/manage/knowhow-capture.md +193 -0
  77. package/maestro-flow/commands/manage/knowhow.md +77 -0
  78. package/maestro-flow/commands/manage/learn.md +67 -0
  79. package/maestro-flow/commands/manage/status.md +51 -0
  80. package/maestro-flow/commands/manage/wiki.md +62 -0
  81. package/maestro-flow/commands/milestone/audit.md +68 -0
  82. package/maestro-flow/commands/milestone/complete.md +75 -0
  83. package/maestro-flow/commands/milestone/release.md +96 -0
  84. package/maestro-flow/commands/quality/auto-test.md +128 -0
  85. package/maestro-flow/commands/quality/debug.md +125 -0
  86. package/maestro-flow/commands/quality/refactor.md +55 -0
  87. package/maestro-flow/commands/quality/retrospective.md +78 -0
  88. package/maestro-flow/commands/quality/review.md +114 -0
  89. package/maestro-flow/commands/quality/sync.md +51 -0
  90. package/maestro-flow/commands/quality/test.md +107 -0
  91. package/maestro-flow/commands/spec/add.md +49 -0
  92. package/maestro-flow/commands/spec/load.md +51 -0
  93. package/maestro-flow/commands/spec/remove.md +51 -0
  94. package/maestro-flow/commands/spec/setup.md +51 -0
  95. package/maestro-flow/commands/wiki/connect.md +62 -0
  96. package/maestro-flow/commands/wiki/digest.md +69 -0
  97. package/package.json +1 -1
@@ -0,0 +1,176 @@
1
+ ---
2
+ name: learn-decompose
3
+ description: Extract design patterns from code into specs and wiki
4
+ argument-hint: "<path|module> [--patterns <list>] [--save-spec] [--save-wiki]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Bash
9
+ - Glob
10
+ - Grep
11
+ - Agent
12
+ - AskUserQuestion
13
+ ---
14
+ <purpose>
15
+ Systematic pattern extraction from code. Analyzes a module or directory across 4 dimensions (structural, behavioral, data, error) using parallel agents, then catalogs findings with code anchors. Discovered patterns can be persisted to specs (via `spec-add`) and wiki (via `maestro wiki create`).
16
+
17
+ Unlike `learn-follow` which reads code with forcing questions, this command is purpose-built for pattern identification and cataloging. It produces a reusable pattern catalog that feeds into the spec system.
18
+ </purpose>
19
+
20
+ <context>
21
+ Arguments: $ARGUMENTS
22
+
23
+ **Target resolution:**
24
+ - File path → analyze that file
25
+ - Directory path → analyze all source files in it
26
+ - Module name → Glob for matching directory under `src/`
27
+
28
+ **Flags:**
29
+ - `--patterns <list>` — Comma-separated pattern names to look for (e.g., "observer,factory,middleware"). If omitted, detect all.
30
+ - `--save-spec` — Invoke `Skill({ skill: "spec-add" })` for each newly discovered pattern
31
+ - `--save-wiki` — Create wiki note entries per pattern group via `maestro wiki create --type note`
32
+
33
+ **Storage written:**
34
+ - `.workflow/learning/decompose-{slug}-{YYYY-MM-DD}.md` — Pattern decomposition report
35
+ - `.workflow/learning/lessons.jsonl` — One insight per discovered pattern (source: "decompose")
36
+ - `.workflow/learning/learning-index.json` — Updated index
37
+ - If `--save-spec`: entries appended to `.workflow/specs/coding-conventions.md`
38
+ - If `--save-wiki`: new wiki note entries
39
+
40
+ **Storage read:**
41
+ - Source files at target path
42
+ - `.workflow/specs/coding-conventions.md` — Existing documented patterns (for dedup)
43
+ - `.workflow/learning/lessons.jsonl` — Previously identified patterns (for dedup)
44
+ </context>
45
+
46
+ <execution>
47
+
48
+ ### Stage 1: Resolve Target
49
+ - If argument is a file: verify exists, use as single-file target
50
+ - If argument is a directory: list all `.ts`, `.tsx`, `.js`, `.jsx` files (exclude `node_modules`, `dist`, `.test.`)
51
+ - If argument is a module name: Glob `src/**/{module}*` to find matching directory
52
+ - If target unresolvable, AskUserQuestion with suggestions
53
+
54
+ ### Stage 2: Load Existing Patterns
55
+ - Read `.workflow/specs/coding-conventions.md` — extract documented patterns
56
+ - Search `lessons.jsonl` for entries with `category: "pattern"` — previously discovered
57
+ - Build dedup set: pattern names already known
58
+
59
+ ### Stage 3: Parallel Agent Analysis (4 dimensions)
60
+ Spawn 4 Agents in a single message, each analyzing the target from one dimension:
61
+
62
+ **Agent 1 — Structural Patterns:**
63
+ - Class hierarchy and composition relationships
64
+ - Module boundaries and encapsulation
65
+ - Dependency injection / inversion of control
66
+ - Builder, Factory, Singleton patterns
67
+ - Export structure (barrel files, re-exports)
68
+
69
+ **Agent 2 — Behavioral Patterns:**
70
+ - Event flow (EventEmitter, pub/sub, callbacks)
71
+ - Middleware chains and interceptors
72
+ - Observer/subscriber patterns
73
+ - Command/strategy patterns
74
+ - State machines
75
+
76
+ **Agent 3 — Data Patterns:**
77
+ - Repository / data access patterns
78
+ - DTO / transformation pipelines
79
+ - Caching strategies (memoization, LRU, TTL)
80
+ - Serialization / deserialization
81
+ - Schema validation approaches
82
+
83
+ **Agent 4 — Error Patterns:**
84
+ - Error boundary and propagation
85
+ - Retry / backoff / circuit breaker
86
+ - Fallback chains
87
+ - Validation and guard clauses
88
+ - Logging and observability patterns
89
+
90
+ Each agent returns findings as structured list:
91
+ ```json
92
+ [{
93
+ "name": "pattern name",
94
+ "dimension": "structural|behavioral|data|error",
95
+ "confidence": "high|medium|low",
96
+ "anchors": ["file:line", "file:line"],
97
+ "description": "what it does",
98
+ "rationale": "why this approach",
99
+ "tradeoffs": "what was given up"
100
+ }]
101
+ ```
102
+
103
+ If `--patterns` specified, instruct agents to focus only on named patterns.
104
+
105
+ ### Stage 4: Cross-Reference & Dedup
106
+ - Match agent findings against existing pattern set from Stage 2
107
+ - Mark each finding: `documented` (already in specs), `known` (in lessons), or `new`
108
+ - Flag contradictions: finding conflicts with documented convention
109
+ - Merge duplicate findings across agents (same pattern found by multiple dimensions)
110
+
111
+ ### Stage 5: Produce Pattern Catalog
112
+ Build the decomposition report grouped by dimension:
113
+
114
+ ```markdown
115
+ # Pattern Decomposition: {target}
116
+
117
+ ## Summary
118
+ - Patterns found: N (M new, K documented, J known)
119
+ - Dimensions analyzed: structural, behavioral, data, error
120
+ - Contradictions: N
121
+
122
+ ## Structural Patterns
123
+ | Pattern | Confidence | Location | Status |
124
+ |---------|-----------|----------|--------|
125
+ | {name} | high | {file:line} | new / documented / known |
126
+
127
+ ### {Pattern Name}
128
+ **Description:** ...
129
+ **Code example:** (inline snippet from anchor)
130
+ **Trade-offs:** ...
131
+
132
+ ## Behavioral Patterns
133
+ ...
134
+ ```
135
+
136
+ ### Stage 6: Persist
137
+ 1. Write `.workflow/learning/decompose-{slug}-{date}.md`
138
+ 2. Append each **new** pattern to `lessons.jsonl`:
139
+ - `source: "decompose"`, `category: "pattern"`, `confidence: <level>`
140
+ - Tags: `["decompose", "{dimension}", "{target-slug}"]`
141
+ - Stable INS-id from `hash("decompose" + target + pattern_name)`
142
+ 3. Update `learning-index.json`
143
+ 4. If `--save-spec`: for each new pattern, invoke `Skill({ skill: "spec-add", args: "pattern {description}" })`
144
+ 5. If `--save-wiki`: create wiki note per dimension group via `maestro wiki create --type note --slug decompose-{dimension}-{slug}`
145
+ 6. Display summary with counts and next steps
146
+
147
+ **Next-step routing:**
148
+ - Follow-along on a specific pattern → `/learn-follow <anchor-file>`
149
+ - Get second opinion on findings → `/learn-second-opinion <target>`
150
+ - Add all new patterns to specs → `/spec-add coding ...` per pattern
151
+ </execution>
152
+
153
+ <error_codes>
154
+ | Code | Severity | Condition | Recovery |
155
+ |------|----------|-----------|----------|
156
+ | E001 | error | Target path not found | Check path exists, or use a module name |
157
+ | E002 | error | No source files found in target directory | Check target has .ts/.js files, exclude filters may be too aggressive |
158
+ | W001 | warning | One or more dimension agents failed — partial results | Proceed with available dimensions, retry failed ones |
159
+ | W002 | warning | coding-conventions.md not found — skipping dedup against specs | All patterns marked as "new" |
160
+ | W003 | warning | Large target (>50 files) — analysis may be slow | Consider narrowing scope with --patterns filter |
161
+ </error_codes>
162
+
163
+ <success_criteria>
164
+ - [ ] Target resolved to concrete file list
165
+ - [ ] Existing patterns loaded for dedup
166
+ - [ ] All 4 dimension agents spawned in parallel
167
+ - [ ] Each finding has: name, dimension, confidence, anchors, description, tradeoffs
168
+ - [ ] Cross-reference performed (documented / known / new status assigned)
169
+ - [ ] Pattern catalog written to `decompose-{slug}-{date}.md`
170
+ - [ ] New patterns appended to `lessons.jsonl` with stable INS-ids
171
+ - [ ] `learning-index.json` updated
172
+ - [ ] If --save-spec: spec entries created for new patterns
173
+ - [ ] If --save-wiki: wiki notes created per dimension group
174
+ - [ ] No files modified outside `.workflow/learning/` (and optionally specs/wiki)
175
+ - [ ] Summary displayed with pattern counts and next-step routing
176
+ </success_criteria>
@@ -0,0 +1,167 @@
1
+ ---
2
+ name: learn-follow
3
+ description: Guided reading of code or wiki to extract patterns
4
+ argument-hint: "<path|wiki-id|topic> [--depth shallow|deep] [--save-wiki]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Bash
9
+ - Glob
10
+ - Grep
11
+ - Agent
12
+ - AskUserQuestion
13
+ ---
14
+ <purpose>
15
+ Guided reading experience for code files, wiki entries, or topics. Instead of just reading code, this command walks through content section by section using forcing questions (inspired by gstack `/office-hours` brainstorming) to extract patterns, identify assumptions, and build a structured understanding map.
16
+
17
+ Outputs reading notes with extracted patterns, open questions, and connection points. Insights persist to `lessons.jsonl` and optionally become wiki note entries for the knowledge graph.
18
+ </purpose>
19
+
20
+ <context>
21
+ Arguments: $ARGUMENTS
22
+
23
+ **Target resolution (auto-detected from first argument):**
24
+ - File path (e.g., `src/commands/wiki.ts`) → Read source file
25
+ - Wiki ID (e.g., `spec-auth`, `phase-planning`) → Fetch via `maestro wiki get`
26
+ - Topic string (e.g., `"authentication flow"`) → Search via `maestro wiki search`, use top result
27
+
28
+ **Flags:**
29
+ - `--depth shallow` — Quick pass: key patterns and structure only (default)
30
+ - `--depth deep` — Thorough: every function, every branch, every assumption
31
+ - `--save-wiki` — Create a wiki note entry with the reading notes via `maestro wiki create --type note`
32
+
33
+ **Storage written:**
34
+ - `.workflow/learning/follow-{slug}-{YYYY-MM-DD}.md` — Reading notes with understanding map
35
+ - `.workflow/learning/lessons.jsonl` — Appended pattern/technique insights
36
+ - `.workflow/learning/learning-index.json` — Updated index
37
+ - If `--save-wiki`: new wiki note entry
38
+
39
+ **Storage read:**
40
+ - Target source file or wiki entry
41
+ - `maestro wiki backlinks <id>` / `maestro wiki forward <id>` — Relationship context
42
+ - `.workflow/specs/coding-conventions.md` — Convention reference for pattern matching
43
+ - `.workflow/learning/lessons.jsonl` — Prior insights for dedup and cross-reference
44
+ </context>
45
+
46
+ <execution>
47
+
48
+ ### Stage 1: Resolve Target
49
+ - If argument looks like a file path (contains `/` or `\`, or matches a glob): verify file exists via Read
50
+ - If argument matches wiki ID pattern (`<type>-<slug>`): fetch via `maestro wiki get <id>` (offline mode)
51
+ - Otherwise: treat as topic string, run `maestro wiki search "<topic>"`, take the top result. If no result, fall back to Grep across `src/` for the topic.
52
+ - If target cannot be resolved, AskUserQuestion with suggestions.
53
+
54
+ ### Stage 2: Load Context Web
55
+ For the resolved target, build a 1-hop context neighborhood:
56
+
57
+ **If wiki entry:**
58
+ - `maestro wiki forward <id>` — What this entry references
59
+ - `maestro wiki backlinks <id>` — What references this entry
60
+ - Read the body of top 3 related entries for context
61
+
62
+ **If code file:**
63
+ - Parse imports/requires to identify dependency files
64
+ - Grep for exports used by other files (reverse dependencies)
65
+ - Read the first 50 lines of top 3 dependent files for context
66
+
67
+ **If directory:**
68
+ - List files, identify entry points (index.ts, main.ts, cli.ts)
69
+ - Build reading order: entry point → core modules → utilities → tests
70
+
71
+ ### Stage 3: Build Reading Order
72
+ - For a single file: split into logical sections (function boundaries, class boundaries, export groups)
73
+ - For a wiki entry: split by markdown headings
74
+ - For a directory: order files by dependency (entry points first, leaf modules last)
75
+ - For `--depth shallow`: limit to top-level structure (function signatures, section headers)
76
+ - For `--depth deep`: include every function body, every branch
77
+
78
+ ### Stage 4: Guided Reading with Forcing Questions
79
+ Walk through each section in reading order. For each section, apply 4 forcing questions:
80
+
81
+ 1. **"What pattern is being used here?"** — Identify design patterns, idioms, conventions. Compare against `coding-conventions.md`.
82
+ 2. **"Why this approach instead of alternatives?"** — What trade-offs were made? What was the simpler approach not chosen?
83
+ 3. **"What assumption does this depend on?"** — What must be true for this code/content to be correct? External state? Input shape? Ordering?
84
+ 4. **"What would break if this changed?"** — Fragility analysis. What downstream effects would a change have?
85
+
86
+ Record answers as structured annotations per section.
87
+
88
+ ### Stage 5: Extract Patterns
89
+ From the forcing question answers, extract:
90
+ - **Design patterns**: named patterns with code anchors (file:line)
91
+ - **Naming conventions**: how things are named and why
92
+ - **Error handling approach**: how errors flow through this code/content
93
+ - **Data flow**: how data enters, transforms, and exits
94
+ - **Assumptions**: explicit and implicit assumptions identified
95
+
96
+ Cross-reference each pattern against existing `coding-conventions.md` entries:
97
+ - Already documented → note as "confirmed convention"
98
+ - Not documented → flag as "undocumented pattern" (candidate for `spec-add`)
99
+
100
+ ### Stage 6: Produce Understanding Map
101
+ Build a structured summary document:
102
+
103
+ ```markdown
104
+ # Follow-Along: {target name}
105
+
106
+ ## Key Concepts
107
+ - {concept}: {one-line explanation}
108
+
109
+ ## Patterns Identified
110
+ | Pattern | Location | Convention Status |
111
+ |---------|----------|-------------------|
112
+ | {name} | {file:line} | documented / undocumented |
113
+
114
+ ## Assumptions
115
+ - {assumption}: {what depends on it}
116
+
117
+ ## Open Questions
118
+ - {question}: {why it matters}
119
+
120
+ ## Connections
121
+ - Links to: {forward link entries}
122
+ - Referenced by: {backlink entries}
123
+ - Related lessons: {matching lessons.jsonl entries}
124
+ ```
125
+
126
+ ### Stage 7: Persist
127
+ 1. Write `.workflow/learning/follow-{slug}-{date}.md` with the understanding map
128
+ 2. Append each new pattern/technique as an insight to `lessons.jsonl`:
129
+ - `source: "follow"`, `category: "pattern"` or `"technique"`
130
+ - Tags: `["follow", "{target-slug}"]`
131
+ - Stable INS-id from `hash("follow" + target + pattern_name)`
132
+ 3. Update `learning-index.json`
133
+ 4. If `--save-wiki`: run `maestro wiki create --type note --slug follow-{slug} --title "Follow-Along: {target}" --body-file .workflow/learning/follow-{slug}-{date}.md`
134
+ 5. Display summary with key findings and next steps
135
+
136
+ **Next-step routing:**
137
+ - Deep dive into a discovered pattern → `/learn-decompose <path>`
138
+ - Add undocumented pattern to specs → `/spec-add coding <description>`
139
+ - Get second opinion on a finding → `/learn-second-opinion <file>`
140
+ - Browse related wiki entries → `/wiki-digest <topic>`
141
+ </execution>
142
+
143
+ <error_codes>
144
+ | Code | Severity | Condition | Recovery |
145
+ |------|----------|-----------|----------|
146
+ | E001 | error | Target not resolvable (file not found, wiki ID not found, search returned 0) | Check path/ID, or rephrase topic for search |
147
+ | E002 | error | `.workflow/` not initialized | Run `/maestro-init` first |
148
+ | W001 | warning | Wiki graph unavailable (no .workflow/ wiki entries) — skipping context web | Proceed with code-only context (imports/exports) |
149
+ | W002 | warning | coding-conventions.md not found — skipping convention comparison | Patterns flagged as "unknown convention status" |
150
+ | W003 | warning | Target is very large (>1000 lines) — auto-switching to shallow depth | Use --depth deep to override |
151
+ </error_codes>
152
+
153
+ <success_criteria>
154
+ - [ ] Target resolved to concrete content (file, wiki entry, or search result)
155
+ - [ ] Context web loaded (forward/backlinks for wiki, imports/exports for code)
156
+ - [ ] Reading order established (sections/files ordered logically)
157
+ - [ ] All 4 forcing questions applied per section
158
+ - [ ] Patterns extracted with file:line anchors
159
+ - [ ] Convention comparison performed against coding-conventions.md
160
+ - [ ] Understanding map produced with: concepts, patterns, assumptions, questions, connections
161
+ - [ ] `follow-{slug}-{date}.md` written
162
+ - [ ] `lessons.jsonl` appended with discovered patterns (stable INS-ids)
163
+ - [ ] `learning-index.json` updated
164
+ - [ ] If --save-wiki: wiki note entry created
165
+ - [ ] No files modified outside `.workflow/learning/` (and optionally wiki)
166
+ - [ ] Summary displayed with next-step routing
167
+ </success_criteria>
@@ -0,0 +1,221 @@
1
+ ---
2
+ name: learn-investigate
3
+ description: Investigate questions with hypothesis testing and evidence logging
4
+ argument-hint: "<question> [--scope <path>] [--max-hypotheses N]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Bash
9
+ - Glob
10
+ - Grep
11
+ - Agent
12
+ - AskUserQuestion
13
+ ---
14
+ <purpose>
15
+ Systematic investigation workflow for understanding questions (not bug-fixing). Inspired by gstack `/investigate` with its 4-phase approach, scope lock, and 3-strike escalation rule.
16
+
17
+ Unlike `quality-debug` which is designed for fixing bugs during execution phases, this command is for answering "how does X work?", "why does Y happen?", "what would happen if Z?" questions. It produces structured evidence trails and understanding documents that persist to the learning system.
18
+ </purpose>
19
+
20
+ <context>
21
+ Arguments: $ARGUMENTS
22
+
23
+ **Target:** First argument is the question or topic to investigate (quoted string or keywords).
24
+
25
+ **Flags:**
26
+ - `--scope <path>` — Restrict investigation to files under this directory (default: entire project)
27
+ - `--max-hypotheses N` — Maximum hypotheses to test before escalating (default: 3)
28
+
29
+ **Storage written:**
30
+ - `.workflow/learning/investigate-{slug}/evidence.ndjson` — Structured evidence log (one JSON line per evidence)
31
+ - `.workflow/learning/investigate-{slug}/understanding.md` — Evolving understanding document
32
+ - `.workflow/learning/investigate-{slug}/report.md` — Final investigation report
33
+ - `.workflow/learning/lessons.jsonl` — Investigation findings as insights (source: "investigate")
34
+ - `.workflow/learning/learning-index.json` — Updated index
35
+
36
+ **Storage read:**
37
+ - Source files within scope
38
+ - `maestro wiki search "<question>"` — Prior knowledge about the topic
39
+ - `.workflow/learning/lessons.jsonl` — Prior related investigations
40
+ - `.workflow/specs/debug-notes.md` — Known gotchas and patterns
41
+ - `.workflow/codebase/architecture.md` — Structural context (if exists)
42
+ </context>
43
+
44
+ <execution>
45
+
46
+ ### Stage 1: Frame the Question
47
+ - Parse question from arguments
48
+ - Determine scope (--scope or full project)
49
+ - Generate investigation slug from question keywords
50
+ - Create `.workflow/learning/investigate-{slug}/` directory
51
+ - Search prior knowledge:
52
+ - `maestro wiki search "<question>"` for related entries
53
+ - Grep `lessons.jsonl` for related insights
54
+ - Read `debug-notes.md` for known gotchas
55
+
56
+ Write initial `understanding.md`:
57
+ ```markdown
58
+ # Investigation: {question}
59
+ ## Initial Understanding
60
+ - Prior knowledge: {summary of wiki/lessons findings}
61
+ - Scope: {path or "full project"}
62
+ - Started: {timestamp}
63
+ ```
64
+
65
+ ### Stage 2: Evidence Collection
66
+ Systematically gather evidence related to the question:
67
+
68
+ 1. **Code search**: Grep for keywords from the question across the scoped files
69
+ 2. **File inspection**: Read the most relevant files identified by search
70
+ 3. **Import/dependency tracing**: Follow imports to understand the dependency chain
71
+ 4. **Git history**: `git log --oneline -10 -- <relevant-files>` for recent changes
72
+
73
+ For each piece of evidence, append to `evidence.ndjson`:
74
+ ```json
75
+ {"ts": "ISO", "type": "code|git|search|doc", "source": "file:line", "relevance": "high|medium|low", "content": "...", "note": "why this matters"}
76
+ ```
77
+
78
+ ### Stage 3: Pattern Matching
79
+ Compare collected evidence against known patterns:
80
+ - Check `debug-notes.md` entries for matching situations
81
+ - Check `lessons.jsonl` for related technique/pattern/gotcha entries
82
+ - Identify: does this match a documented pattern, or is it novel?
83
+
84
+ Update `understanding.md` with pattern analysis section.
85
+
86
+ ### Stage 4: Hypothesis Formation
87
+ From evidence and patterns, generate ranked hypotheses:
88
+ - Each hypothesis: a specific, testable claim about "how/why"
89
+ - Rank by plausibility (evidence strength)
90
+ - Write hypotheses to `understanding.md`
91
+
92
+ ```markdown
93
+ ## Hypotheses
94
+ 1. **[HIGH]** {hypothesis 1} — Evidence: {refs}
95
+ 2. **[MEDIUM]** {hypothesis 2} — Evidence: {refs}
96
+ 3. **[LOW]** {hypothesis 3} — Evidence: {refs}
97
+ ```
98
+
99
+ ### Stage 4.5: CLI Supplementary Exploration (optional)
100
+
101
+ **Skip if** no enabled CLI tools or hypotheses are trivially testable.
102
+
103
+ ```
104
+ IF no CLI tools enabled: skip to Stage 5
105
+
106
+ hypothesis_summary = hypotheses.map(h => "${h.rank}: ${h.claim}").join("\n")
107
+
108
+ Bash({
109
+ command: 'maestro delegate "PURPOSE: Gather evidence for investigation hypotheses
110
+ TASK: For each hypothesis, trace relevant call chains and data flows | Find corroborating or contradicting code patterns
111
+ MODE: analysis
112
+ CONTEXT: @${scope_path}/**/*
113
+ EXPECTED: JSON array of { hypothesis_rank, evidence: [{ file, line, supports: bool, explanation }] }
114
+ CONSTRAINTS: Focus on code-level evidence only | Max 5 evidence items per hypothesis
115
+
116
+ Hypotheses:
117
+ ${hypothesis_summary}
118
+ " --role explore --mode analysis',
119
+ run_in_background: true
120
+ })
121
+ ```
122
+
123
+ **On callback:** Parse result, append each evidence item to `evidence.ndjson` with `type: "cli-exploration"`. Pass as supplementary context to Stage 5 testing.
124
+
125
+ ### Stage 5: Hypothesis Testing
126
+ For each hypothesis (in rank order):
127
+
128
+ 1. **Design test**: What specific evidence would confirm or disprove this?
129
+ 2. **Execute test**: Code trace, targeted search, data inspection, or experiment
130
+ 3. **Record result**: Append to `evidence.ndjson` with `type: "test"`
131
+ 4. **Update understanding**: Mark hypothesis as confirmed / disproved / inconclusive
132
+
133
+ ```markdown
134
+ ## Test Results
135
+ ### Hypothesis 1: {claim}
136
+ - Test: {what was done}
137
+ - Result: CONFIRMED / DISPROVED / INCONCLUSIVE
138
+ - Evidence: {file:line references}
139
+ ```
140
+
141
+ ### Stage 6: 3-Strike Escalation
142
+ If `--max-hypotheses` hypotheses all fail:
143
+
144
+ 1. **Broaden scope**: If scope was restricted, suggest expanding. AskUserQuestion:
145
+ ```
146
+ {N} hypotheses tested, none confirmed.
147
+ A) Broaden scope to full project
148
+ B) I have a new hypothesis: [user provides]
149
+ C) Escalate — this needs deeper investigation
150
+ ```
151
+ 2. **Search wiki for clues**: `maestro wiki search` with alternative keywords
152
+ 3. **If still stuck**: Mark as INCONCLUSIVE with what was learned and what remains unknown
153
+
154
+ ### Stage 7: Synthesize & Report
155
+ Write final `report.md`:
156
+
157
+ ```markdown
158
+ # Investigation Report: {question}
159
+
160
+ ## Answer
161
+ {confirmed understanding or "INCONCLUSIVE: ..."}
162
+
163
+ ## Evidence Trail
164
+ | # | Type | Source | Relevance | Finding |
165
+ |---|------|--------|-----------|---------|
166
+ | 1 | code | file:line | high | ... |
167
+
168
+ ## Hypotheses Tested
169
+ | Hypothesis | Result | Key Evidence |
170
+ |-----------|--------|-------------|
171
+ | ... | confirmed/disproved | file:line |
172
+
173
+ ## Key Learnings
174
+ - {learning 1}
175
+ - {learning 2}
176
+
177
+ ## Open Questions
178
+ - {what remains unknown}
179
+ ```
180
+
181
+ ### Stage 8: Persist
182
+ 1. Append findings to `lessons.jsonl`:
183
+ - Confirmed hypotheses → `category: "technique"` or `"pattern"`
184
+ - Disproved hypotheses → `category: "gotcha"` (what looked true but wasn't)
185
+ - `source: "investigate"`, tags: `["investigate", "{question-slug}"]`
186
+ - Stable INS-id from `hash("investigate" + question + finding_title)`
187
+ 2. Update `learning-index.json`
188
+ 3. Display summary with answer and next steps
189
+
190
+ **Next-step routing:**
191
+ - Save finding to specs → `/spec-add debug <finding>`
192
+ - Follow-along on discovered code → `/learn-follow <path>`
193
+ - Decompose patterns found → `/learn-decompose <module>`
194
+ - Create wiki entry for understanding → `maestro wiki create --type note`
195
+ </execution>
196
+
197
+ <error_codes>
198
+ | Code | Severity | Condition | Recovery |
199
+ |------|----------|-----------|----------|
200
+ | E001 | error | No question provided | Provide a question as the first argument |
201
+ | E002 | error | Scope path does not exist | Check --scope path is valid |
202
+ | W001 | warning | No prior knowledge found in wiki/lessons | Proceed with fresh investigation |
203
+ | W002 | warning | Evidence collection found very few matches (<3) | Broaden search terms or expand scope |
204
+ | W003 | warning | All hypotheses inconclusive — escalating | Investigation marked INCONCLUSIVE |
205
+ </error_codes>
206
+
207
+ <success_criteria>
208
+ - [ ] Question parsed and investigation slug generated
209
+ - [ ] Investigation directory created under `.workflow/learning/`
210
+ - [ ] Prior knowledge loaded from wiki and lessons
211
+ - [ ] Evidence collected and logged to `evidence.ndjson` (structured NDJSON)
212
+ - [ ] Pattern matching performed against debug-notes and lessons
213
+ - [ ] At least 1 hypothesis formed and tested
214
+ - [ ] `understanding.md` tracks evolving understanding with timestamps
215
+ - [ ] `report.md` written with answer, evidence trail, hypothesis results
216
+ - [ ] Findings appended to `lessons.jsonl` with stable INS-ids
217
+ - [ ] `learning-index.json` updated
218
+ - [ ] 3-strike escalation triggered if all hypotheses fail
219
+ - [ ] No files modified outside `.workflow/learning/`
220
+ - [ ] Summary displayed with answer and next-step routing
221
+ </success_criteria>