maestro-flow 0.3.10 → 0.3.11

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 (184) hide show
  1. package/.claude/agents/workflow-collab-planner.md +1 -1
  2. package/.claude/agents/workflow-executor.md +1 -1
  3. package/.claude/agents/workflow-plan-checker.md +1 -1
  4. package/.claude/agents/workflow-planner.md +1 -1
  5. package/.claude/commands/learn-decompose.md +176 -176
  6. package/.claude/commands/learn-follow.md +167 -167
  7. package/.claude/commands/learn-retro.md +1 -1
  8. package/.claude/commands/maestro-coordinate.md +1 -3
  9. package/.claude/commands/manage-harvest.md +131 -131
  10. package/.claude/commands/manage-issue.md +2 -2
  11. package/.claude/commands/spec-add.md +67 -56
  12. package/.claude/commands/spec-load.md +66 -64
  13. package/.claude/commands/spec-setup.md +5 -9
  14. package/.codex/skills/learn-decompose/SKILL.md +119 -0
  15. package/.codex/skills/learn-follow/SKILL.md +83 -0
  16. package/.codex/skills/learn-investigate/SKILL.md +83 -0
  17. package/.codex/skills/learn-retro/SKILL.md +83 -0
  18. package/.codex/skills/learn-second-opinion/SKILL.md +86 -0
  19. package/.codex/skills/maestro/SKILL.md +151 -279
  20. package/.codex/skills/maestro-analyze/SKILL.md +59 -71
  21. package/.codex/skills/maestro-brainstorm/SKILL.md +452 -463
  22. package/.codex/skills/maestro-chain/SKILL.md +95 -110
  23. package/.codex/skills/maestro-coordinate/SKILL.md +68 -234
  24. package/.codex/skills/maestro-execute/SKILL.md +435 -446
  25. package/.codex/skills/maestro-fork/SKILL.md +68 -0
  26. package/.codex/skills/maestro-init/SKILL.md +171 -167
  27. package/.codex/skills/maestro-learn/SKILL.md +80 -0
  28. package/.codex/skills/maestro-link-coordinate/SKILL.md +224 -220
  29. package/.codex/skills/maestro-merge/SKILL.md +62 -0
  30. package/.codex/skills/maestro-milestone-audit/SKILL.md +108 -103
  31. package/.codex/skills/maestro-milestone-complete/SKILL.md +155 -149
  32. package/.codex/skills/maestro-milestone-release/SKILL.md +70 -0
  33. package/.codex/skills/maestro-overlay/SKILL.md +188 -185
  34. package/.codex/skills/maestro-plan/SKILL.md +58 -69
  35. package/.codex/skills/maestro-quick/SKILL.md +26 -23
  36. package/.codex/skills/maestro-roadmap/SKILL.md +65 -73
  37. package/.codex/skills/maestro-spec-generate/SKILL.md +66 -74
  38. package/.codex/skills/maestro-ui-design/SKILL.md +34 -31
  39. package/.codex/skills/maestro-verify/SKILL.md +556 -566
  40. package/.codex/skills/manage-codebase-rebuild/SKILL.md +397 -405
  41. package/.codex/skills/manage-codebase-refresh/SKILL.md +93 -82
  42. package/.codex/skills/manage-harvest/SKILL.md +82 -0
  43. package/.codex/skills/manage-issue/SKILL.md +80 -65
  44. package/.codex/skills/manage-issue-discover/SKILL.md +491 -503
  45. package/.codex/skills/manage-learn/SKILL.md +190 -186
  46. package/.codex/skills/manage-memory/SKILL.md +95 -72
  47. package/.codex/skills/manage-memory-capture/SKILL.md +99 -86
  48. package/.codex/skills/manage-status/SKILL.md +102 -89
  49. package/.codex/skills/quality-business-test/SKILL.md +228 -223
  50. package/.codex/skills/quality-debug/SKILL.md +54 -66
  51. package/.codex/skills/quality-integration-test/SKILL.md +532 -544
  52. package/.codex/skills/quality-refactor/SKILL.md +197 -191
  53. package/.codex/skills/quality-retrospective/SKILL.md +512 -505
  54. package/.codex/skills/quality-review/SKILL.md +93 -105
  55. package/.codex/skills/quality-sync/SKILL.md +101 -89
  56. package/.codex/skills/quality-test/SKILL.md +202 -198
  57. package/.codex/skills/quality-test-gen/SKILL.md +93 -104
  58. package/.codex/skills/spec-add/SKILL.md +58 -39
  59. package/.codex/skills/spec-load/SKILL.md +45 -40
  60. package/.codex/skills/spec-map/SKILL.md +180 -182
  61. package/.codex/skills/spec-setup/SKILL.md +94 -76
  62. package/.codex/skills/team-coordinate/SKILL.md +346 -357
  63. package/.codex/skills/team-executor/SKILL.md +70 -112
  64. package/.codex/skills/team-lifecycle-v4/SKILL.md +311 -299
  65. package/.codex/skills/team-quality-assurance/SKILL.md +234 -227
  66. package/.codex/skills/team-review/SKILL.md +232 -225
  67. package/.codex/skills/team-tech-debt/SKILL.md +78 -100
  68. package/.codex/skills/team-testing/SKILL.md +242 -235
  69. package/.codex/skills/wiki-connect/SKILL.md +75 -0
  70. package/.codex/skills/wiki-digest/SKILL.md +87 -0
  71. package/README.md +7 -4
  72. package/README.zh-CN.md +7 -4
  73. package/dashboard/dist-server/dashboard/src/server/routes/specs.d.ts +1 -1
  74. package/dashboard/dist-server/dashboard/src/server/routes/specs.js +75 -30
  75. package/dashboard/dist-server/dashboard/src/server/routes/specs.js.map +1 -1
  76. package/dashboard/dist-server/dashboard/src/server/state/event-bus.d.ts +5 -0
  77. package/dashboard/dist-server/dashboard/src/server/state/event-bus.js +5 -0
  78. package/dashboard/dist-server/dashboard/src/server/state/event-bus.js.map +1 -1
  79. package/dashboard/dist-server/dashboard/src/shared/constants.js +5 -0
  80. package/dashboard/dist-server/dashboard/src/shared/constants.js.map +1 -1
  81. package/dashboard/dist-server/dashboard/src/shared/team-types.d.ts +21 -0
  82. package/dashboard/dist-server/dashboard/src/shared/team-types.js.map +1 -1
  83. package/dashboard/dist-server/dashboard/src/shared/types.d.ts +3 -2
  84. package/dashboard/dist-server/dashboard/src/shared/ws-protocol.d.ts +1 -1
  85. package/dashboard/dist-server/dashboard/src/shared/ws-protocol.js.map +1 -1
  86. package/dashboard/dist-server/src/hooks/constants.d.ts +2 -0
  87. package/dashboard/dist-server/src/hooks/constants.js +2 -0
  88. package/dashboard/dist-server/src/hooks/constants.js.map +1 -1
  89. package/dist/src/commands/collab.js +4 -4
  90. package/dist/src/commands/collab.js.map +1 -1
  91. package/dist/src/commands/hooks.d.ts.map +1 -1
  92. package/dist/src/commands/hooks.js +66 -1
  93. package/dist/src/commands/hooks.js.map +1 -1
  94. package/dist/src/commands/spec.d.ts.map +1 -1
  95. package/dist/src/commands/spec.js +7 -2
  96. package/dist/src/commands/spec.js.map +1 -1
  97. package/dist/src/hooks/constants.d.ts +2 -0
  98. package/dist/src/hooks/constants.d.ts.map +1 -1
  99. package/dist/src/hooks/constants.js +2 -0
  100. package/dist/src/hooks/constants.js.map +1 -1
  101. package/dist/src/hooks/guards/index.d.ts +1 -0
  102. package/dist/src/hooks/guards/index.d.ts.map +1 -1
  103. package/dist/src/hooks/guards/index.js +1 -0
  104. package/dist/src/hooks/guards/index.js.map +1 -1
  105. package/dist/src/hooks/guards/spec-validator.d.ts +25 -0
  106. package/dist/src/hooks/guards/spec-validator.d.ts.map +1 -0
  107. package/dist/src/hooks/guards/spec-validator.js +66 -0
  108. package/dist/src/hooks/guards/spec-validator.js.map +1 -0
  109. package/dist/src/hooks/keyword-spec-injector.d.ts +21 -0
  110. package/dist/src/hooks/keyword-spec-injector.d.ts.map +1 -0
  111. package/dist/src/hooks/keyword-spec-injector.js +96 -0
  112. package/dist/src/hooks/keyword-spec-injector.js.map +1 -0
  113. package/dist/src/hooks/plugins/spec-injection-plugin.d.ts +2 -1
  114. package/dist/src/hooks/plugins/spec-injection-plugin.d.ts.map +1 -1
  115. package/dist/src/hooks/plugins/spec-injection-plugin.js +21 -12
  116. package/dist/src/hooks/plugins/spec-injection-plugin.js.map +1 -1
  117. package/dist/src/hooks/spec-bridge.d.ts +40 -0
  118. package/dist/src/hooks/spec-bridge.d.ts.map +1 -0
  119. package/dist/src/hooks/spec-bridge.js +97 -0
  120. package/dist/src/hooks/spec-bridge.js.map +1 -0
  121. package/dist/src/hooks/spec-injector.d.ts.map +1 -1
  122. package/dist/src/hooks/spec-injector.js +18 -12
  123. package/dist/src/hooks/spec-injector.js.map +1 -1
  124. package/dist/src/team/phase-orchestrator.d.ts +52 -0
  125. package/dist/src/team/phase-orchestrator.d.ts.map +1 -0
  126. package/dist/src/team/phase-orchestrator.js +165 -0
  127. package/dist/src/team/phase-orchestrator.js.map +1 -0
  128. package/dist/src/team/phase-types.d.ts +51 -0
  129. package/dist/src/team/phase-types.d.ts.map +1 -0
  130. package/dist/src/team/phase-types.js +41 -0
  131. package/dist/src/team/phase-types.js.map +1 -0
  132. package/dist/src/tools/index.d.ts.map +1 -1
  133. package/dist/src/tools/index.js +6 -0
  134. package/dist/src/tools/index.js.map +1 -1
  135. package/dist/src/tools/spec-entry-parser.d.ts +56 -0
  136. package/dist/src/tools/spec-entry-parser.d.ts.map +1 -0
  137. package/dist/src/tools/spec-entry-parser.js +196 -0
  138. package/dist/src/tools/spec-entry-parser.js.map +1 -0
  139. package/dist/src/tools/spec-init.d.ts.map +1 -1
  140. package/dist/src/tools/spec-init.js +66 -92
  141. package/dist/src/tools/spec-init.js.map +1 -1
  142. package/dist/src/tools/spec-keyword-index.d.ts +30 -0
  143. package/dist/src/tools/spec-keyword-index.d.ts.map +1 -0
  144. package/dist/src/tools/spec-keyword-index.js +101 -0
  145. package/dist/src/tools/spec-keyword-index.js.map +1 -0
  146. package/dist/src/tools/spec-loader.d.ts +3 -3
  147. package/dist/src/tools/spec-loader.d.ts.map +1 -1
  148. package/dist/src/tools/spec-loader.js +49 -23
  149. package/dist/src/tools/spec-loader.js.map +1 -1
  150. package/dist/src/tools/team-agents.d.ts +27 -0
  151. package/dist/src/tools/team-agents.d.ts.map +1 -0
  152. package/dist/src/tools/team-agents.js +362 -0
  153. package/dist/src/tools/team-agents.js.map +1 -0
  154. package/dist/src/tools/team-mailbox.d.ts +40 -0
  155. package/dist/src/tools/team-mailbox.d.ts.map +1 -0
  156. package/dist/src/tools/team-mailbox.js +384 -0
  157. package/dist/src/tools/team-mailbox.js.map +1 -0
  158. package/dist/src/tools/team-msg.d.ts +17 -8
  159. package/dist/src/tools/team-msg.d.ts.map +1 -1
  160. package/dist/src/tools/team-msg.js +110 -13
  161. package/dist/src/tools/team-msg.js.map +1 -1
  162. package/dist/src/tools/team-tasks-mcp.d.ts +27 -0
  163. package/dist/src/tools/team-tasks-mcp.d.ts.map +1 -0
  164. package/dist/src/tools/team-tasks-mcp.js +408 -0
  165. package/dist/src/tools/team-tasks-mcp.js.map +1 -0
  166. package/package.json +2 -1
  167. package/workflows/analyze.md +816 -816
  168. package/workflows/brainstorm.md +471 -471
  169. package/workflows/codebase-rebuild.md +332 -332
  170. package/workflows/codebase-refresh.md +240 -240
  171. package/workflows/execute.md +1 -1
  172. package/workflows/harvest.md +420 -420
  173. package/workflows/integration-test.md +343 -343
  174. package/workflows/issue-discover.md +414 -414
  175. package/workflows/map.md +111 -111
  176. package/workflows/milestone-complete.md +176 -176
  177. package/workflows/plan.md +1 -1
  178. package/workflows/quick.md +497 -497
  179. package/workflows/refactor.md +300 -300
  180. package/workflows/roadmap.md +335 -335
  181. package/workflows/spec-generate.md +640 -640
  182. package/workflows/specs-add.md +46 -81
  183. package/workflows/specs-load.md +15 -17
  184. package/workflows/specs-setup.md +40 -161
@@ -1,300 +1,300 @@
1
- # Refactor Workflow
2
-
3
- Systematically reduce tech debt through scope analysis, task planning, and reflection-driven execution. Each refactoring round records strategy, outcome, and adjustments. Existing tests must pass after every change.
4
-
5
- Output: scratch/refactor-{slug}-{date}/ with index.json + reflection-log.md + .task/ + .summaries/
6
-
7
- ---
8
-
9
- ## Prerequisites
10
-
11
- - `.workflow/` directory initialized
12
- - Test suite available for affected scope (E002 if missing)
13
-
14
- ---
15
-
16
- ### Step 1: Parse Scope
17
-
18
- **Parse scope from $ARGUMENTS:**
19
-
20
- - Module path (e.g., "src/auth") -> scan that directory
21
- - Feature area (e.g., "authentication") -> search for related files
22
- - "all" -> full codebase scan
23
- - Empty -> prompt user:
24
-
25
- ```
26
- AskUserQuestion(
27
- header: "Refactoring Scope",
28
- question: "What scope should be refactored?",
29
- options: [
30
- { label: "Module path", description: "e.g., src/auth -- specific directory" },
31
- { label: "Feature area", description: "e.g., authentication -- conceptual scope" },
32
- { label: "Full codebase", description: "Scan everything for tech debt" }
33
- ]
34
- )
35
- ```
36
-
37
- Generate slug from scope (lowercase, hyphens, max 40 chars).
38
- Set date to current date (YYYY-MM-DD).
39
-
40
- ---
41
-
42
- ### Step 2: Create Scratch Directory
43
-
44
- **Create scratch directory and index.json:**
45
-
46
- ```bash
47
- REFACTOR_DIR=".workflow/scratch/refactor-${slug}-${date}"
48
- mkdir -p "$REFACTOR_DIR/.task"
49
- mkdir -p "$REFACTOR_DIR/.summaries"
50
- ```
51
-
52
- Write index.json:
53
- ```json
54
- {
55
- "id": "refactor-{slug}-{date}",
56
- "type": "refactor",
57
- "title": "Refactor: {scope description}",
58
- "status": "active",
59
- "created_at": "{ISO timestamp}",
60
- "updated_at": "{ISO timestamp}",
61
- "scope": "{original scope argument}",
62
- "plan": {
63
- "task_ids": [],
64
- "task_count": 0
65
- },
66
- "execution": {
67
- "method": "agent",
68
- "tasks_completed": 0,
69
- "tasks_total": 0
70
- },
71
- "reflection": {
72
- "rounds": 0,
73
- "strategy_adjustments": []
74
- }
75
- }
76
- ```
77
-
78
- ---
79
-
80
- ### Step 2.5: Load Project Specs
81
-
82
- ```
83
- specs_content = maestro spec load --category execution
84
- ```
85
-
86
- Used in Step 3 to detect pattern violations against project conventions.
87
-
88
- ---
89
-
90
- ### Step 3: Scope Analysis
91
-
92
- **Analyze scope for tech debt:**
93
-
94
- Read all files in scope. Use specs_content (if loaded) to detect convention violations. Identify and categorize issues:
95
-
96
- 1. **Duplication** - Repeated code blocks, copy-paste patterns
97
- 2. **Complexity hotspots** - Functions too long, deep nesting, high cyclomatic complexity
98
- 3. **Naming issues** - Inconsistent naming, unclear variable/function names
99
- 4. **Dependency tangles** - Circular deps, tight coupling, god objects
100
- 5. **Dead code** - Unused functions, unreachable branches
101
- 6. **Pattern violations** - Inconsistent with project conventions (from specs/)
102
-
103
- Present analysis summary:
104
- ```
105
- ## Scope Analysis: {scope}
106
-
107
- | Category | Count | Severity |
108
- |----------|-------|----------|
109
- | Duplication | 3 | medium |
110
- | Complexity | 5 | high |
111
- | Naming | 8 | low |
112
- | Dependencies | 2 | high |
113
- | Dead code | 4 | low |
114
-
115
- Total issues: 22
116
- Recommended priority: Complexity > Dependencies > Duplication > Naming > Dead code
117
- ```
118
-
119
- Confirm with user before proceeding to planning.
120
-
121
- ---
122
-
123
- ### Step 4: Plan Refactoring
124
-
125
- **Generate refactoring plan:**
126
-
127
- Write plan.json:
128
- ```json
129
- {
130
- "scope": "{scope}",
131
- "total_tasks": N,
132
- "strategy": "incremental -- each task is independently safe",
133
- "tasks": ["TASK-001", "TASK-002", ...]
134
- }
135
- ```
136
-
137
- For each identified issue, create .task/TASK-{NNN}.json:
138
- ```json
139
- {
140
- "id": "TASK-{NNN}",
141
- "title": "{specific refactoring}",
142
- "status": "pending",
143
- "type": "refactor",
144
- "category": "duplication|complexity|naming|dependency|dead_code|pattern",
145
- "description": "{what to change and why}",
146
- "read_first": ["path/to/file.ts", "path/to/related.ts"],
147
- "files": [
148
- { "path": "path/to/file.ts", "action": "modify", "target": "{function_or_class}", "change": "{concrete_change}" }
149
- ],
150
- "action": "{detailed steps with concrete values}",
151
- "convergence": {
152
- "criteria": ["{grep-verifiable completion criterion}"],
153
- "verification": "Run existing tests to confirm no regressions"
154
- },
155
- "implementation": ["{step 1 with concrete values}"],
156
- "risk": "low|medium|high"
157
- }
158
- ```
159
-
160
- Order tasks by: high risk last, dependencies respected, quick wins first.
161
-
162
- Update index.json plan fields.
163
-
164
- **Present plan to user via AskUserQuestion:**
165
- - Show affected files with proposed changes
166
- - Highlight risk areas and dependency impacts
167
- - Ask for approval, modifications, or rejection
168
- - Capture any additional constraints or priorities
169
-
170
- ---
171
-
172
- ### Step 5: Execute with Reflection
173
-
174
- **Execute each task with reflection tracking:**
175
-
176
- Initialize reflection-log.md:
177
- ```markdown
178
- # Refactoring Reflection Log
179
-
180
- Scope: {scope}
181
- Started: {ISO timestamp}
182
-
183
- ---
184
- ```
185
-
186
- For each task in order:
187
-
188
- **5a. Execute the refactoring:**
189
- Implement the change as described in the task.
190
-
191
- **5b. Run existing tests:**
192
- ```bash
193
- # Detect and run test suite
194
- npm test 2>&1 || pytest 2>&1 || go test ./... 2>&1 || echo "No test runner detected"
195
- ```
196
-
197
- **5c. Record in reflection-log.md:**
198
- ```markdown
199
- ## Round {N}: {task title}
200
-
201
- - **Strategy:** {approach taken}
202
- - **Result:** {pass|fail} -- {brief outcome}
203
- - **Tests:** {all pass | N failures}
204
- - **Adjustment:** {what to change in approach for next round, or "none needed"}
205
- - **Files changed:** {list}
206
-
207
- ---
208
- ```
209
-
210
- **5d. Handle test failures:**
211
- If tests fail after a refactoring:
212
- 1. Revert the change
213
- 2. Record failure in reflection-log.md with strategy adjustment
214
- 3. Attempt with adjusted strategy (max 2 retries per task)
215
- 4. If still failing, mark task as "blocked" and continue to next
216
-
217
- **5e. Update task status:**
218
- Update .task/TASK-{NNN}.json status to "completed" or "blocked".
219
- Write .summaries/TASK-{NNN}-summary.md.
220
- Update index.json execution fields.
221
- Update reflection.rounds and strategy_adjustments in index.json.
222
-
223
- ---
224
-
225
- ### Step 6: Final Verification
226
-
227
- **Run full test suite after all tasks:**
228
-
229
- ```bash
230
- npm test 2>&1 || pytest 2>&1 || go test ./... 2>&1
231
- ```
232
-
233
- Record final state in reflection-log.md:
234
- ```markdown
235
- ## Final Verification
236
-
237
- - **Tests:** {all pass | N failures}
238
- - **Tasks completed:** {N}/{total}
239
- - **Tasks blocked:** {N}
240
- - **Key learnings:** {patterns discovered during refactoring}
241
- ```
242
-
243
- ---
244
-
245
- ### Step 7: Complete
246
-
247
- **Update index.json and present summary:**
248
-
249
- Update index.json:
250
- ```json
251
- {
252
- "status": "completed",
253
- "updated_at": "{ISO timestamp}",
254
- "execution": {
255
- "tasks_completed": N,
256
- "tasks_total": M
257
- },
258
- "reflection": {
259
- "rounds": N,
260
- "strategy_adjustments": ["list of adjustments made"]
261
- }
262
- }
263
- ```
264
-
265
- Present completion summary:
266
- ```
267
- ## Refactoring Complete: {scope}
268
-
269
- | Metric | Value |
270
- |--------|-------|
271
- | Tasks completed | {N}/{total} |
272
- | Tasks blocked | {N} |
273
- | Reflection rounds | {N} |
274
- | Strategy adjustments | {N} |
275
- | Tests passing | {yes/no} |
276
-
277
- Key learnings:
278
- {from reflection-log.md}
279
-
280
- Artifacts:
281
- - Reflection log: {REFACTOR_DIR}/reflection-log.md
282
- - Task results: {REFACTOR_DIR}/.summaries/
283
- ```
284
-
285
- If regressions found: list affected tests and suggest Skill({ skill: "quality-debug" }).
286
-
287
- ---
288
-
289
- ## Success Criteria
290
-
291
- - [ ] Scope parsed and validated
292
- - [ ] Scratch directory created with index.json
293
- - [ ] Scope analysis identifies tech debt categories
294
- - [ ] plan.json + .task/TASK-*.json created for each refactoring
295
- - [ ] Each task executed with test verification (no regressions)
296
- - [ ] reflection-log.md tracks strategy per round with adjustments
297
- - [ ] Test failures trigger revert + retry with adjusted strategy
298
- - [ ] Full test suite passes at end
299
- - [ ] index.json updated with final status
300
- - [ ] .summaries/ written for completed tasks
1
+ # Refactor Workflow
2
+
3
+ Systematically reduce tech debt through scope analysis, task planning, and reflection-driven execution. Each refactoring round records strategy, outcome, and adjustments. Existing tests must pass after every change.
4
+
5
+ Output: scratch/refactor-{slug}-{date}/ with index.json + reflection-log.md + .task/ + .summaries/
6
+
7
+ ---
8
+
9
+ ## Prerequisites
10
+
11
+ - `.workflow/` directory initialized
12
+ - Test suite available for affected scope (E002 if missing)
13
+
14
+ ---
15
+
16
+ ### Step 1: Parse Scope
17
+
18
+ **Parse scope from $ARGUMENTS:**
19
+
20
+ - Module path (e.g., "src/auth") -> scan that directory
21
+ - Feature area (e.g., "authentication") -> search for related files
22
+ - "all" -> full codebase scan
23
+ - Empty -> prompt user:
24
+
25
+ ```
26
+ AskUserQuestion(
27
+ header: "Refactoring Scope",
28
+ question: "What scope should be refactored?",
29
+ options: [
30
+ { label: "Module path", description: "e.g., src/auth -- specific directory" },
31
+ { label: "Feature area", description: "e.g., authentication -- conceptual scope" },
32
+ { label: "Full codebase", description: "Scan everything for tech debt" }
33
+ ]
34
+ )
35
+ ```
36
+
37
+ Generate slug from scope (lowercase, hyphens, max 40 chars).
38
+ Set date to current date (YYYY-MM-DD).
39
+
40
+ ---
41
+
42
+ ### Step 2: Create Scratch Directory
43
+
44
+ **Create scratch directory and index.json:**
45
+
46
+ ```bash
47
+ REFACTOR_DIR=".workflow/scratch/refactor-${slug}-${date}"
48
+ mkdir -p "$REFACTOR_DIR/.task"
49
+ mkdir -p "$REFACTOR_DIR/.summaries"
50
+ ```
51
+
52
+ Write index.json:
53
+ ```json
54
+ {
55
+ "id": "refactor-{slug}-{date}",
56
+ "type": "refactor",
57
+ "title": "Refactor: {scope description}",
58
+ "status": "active",
59
+ "created_at": "{ISO timestamp}",
60
+ "updated_at": "{ISO timestamp}",
61
+ "scope": "{original scope argument}",
62
+ "plan": {
63
+ "task_ids": [],
64
+ "task_count": 0
65
+ },
66
+ "execution": {
67
+ "method": "agent",
68
+ "tasks_completed": 0,
69
+ "tasks_total": 0
70
+ },
71
+ "reflection": {
72
+ "rounds": 0,
73
+ "strategy_adjustments": []
74
+ }
75
+ }
76
+ ```
77
+
78
+ ---
79
+
80
+ ### Step 2.5: Load Project Specs
81
+
82
+ ```
83
+ specs_content = maestro spec load --category coding
84
+ ```
85
+
86
+ Used in Step 3 to detect pattern violations against project conventions.
87
+
88
+ ---
89
+
90
+ ### Step 3: Scope Analysis
91
+
92
+ **Analyze scope for tech debt:**
93
+
94
+ Read all files in scope. Use specs_content (if loaded) to detect convention violations. Identify and categorize issues:
95
+
96
+ 1. **Duplication** - Repeated code blocks, copy-paste patterns
97
+ 2. **Complexity hotspots** - Functions too long, deep nesting, high cyclomatic complexity
98
+ 3. **Naming issues** - Inconsistent naming, unclear variable/function names
99
+ 4. **Dependency tangles** - Circular deps, tight coupling, god objects
100
+ 5. **Dead code** - Unused functions, unreachable branches
101
+ 6. **Pattern violations** - Inconsistent with project conventions (from specs/)
102
+
103
+ Present analysis summary:
104
+ ```
105
+ ## Scope Analysis: {scope}
106
+
107
+ | Category | Count | Severity |
108
+ |----------|-------|----------|
109
+ | Duplication | 3 | medium |
110
+ | Complexity | 5 | high |
111
+ | Naming | 8 | low |
112
+ | Dependencies | 2 | high |
113
+ | Dead code | 4 | low |
114
+
115
+ Total issues: 22
116
+ Recommended priority: Complexity > Dependencies > Duplication > Naming > Dead code
117
+ ```
118
+
119
+ Confirm with user before proceeding to planning.
120
+
121
+ ---
122
+
123
+ ### Step 4: Plan Refactoring
124
+
125
+ **Generate refactoring plan:**
126
+
127
+ Write plan.json:
128
+ ```json
129
+ {
130
+ "scope": "{scope}",
131
+ "total_tasks": N,
132
+ "strategy": "incremental -- each task is independently safe",
133
+ "tasks": ["TASK-001", "TASK-002", ...]
134
+ }
135
+ ```
136
+
137
+ For each identified issue, create .task/TASK-{NNN}.json:
138
+ ```json
139
+ {
140
+ "id": "TASK-{NNN}",
141
+ "title": "{specific refactoring}",
142
+ "status": "pending",
143
+ "type": "refactor",
144
+ "category": "duplication|complexity|naming|dependency|dead_code|pattern",
145
+ "description": "{what to change and why}",
146
+ "read_first": ["path/to/file.ts", "path/to/related.ts"],
147
+ "files": [
148
+ { "path": "path/to/file.ts", "action": "modify", "target": "{function_or_class}", "change": "{concrete_change}" }
149
+ ],
150
+ "action": "{detailed steps with concrete values}",
151
+ "convergence": {
152
+ "criteria": ["{grep-verifiable completion criterion}"],
153
+ "verification": "Run existing tests to confirm no regressions"
154
+ },
155
+ "implementation": ["{step 1 with concrete values}"],
156
+ "risk": "low|medium|high"
157
+ }
158
+ ```
159
+
160
+ Order tasks by: high risk last, dependencies respected, quick wins first.
161
+
162
+ Update index.json plan fields.
163
+
164
+ **Present plan to user via AskUserQuestion:**
165
+ - Show affected files with proposed changes
166
+ - Highlight risk areas and dependency impacts
167
+ - Ask for approval, modifications, or rejection
168
+ - Capture any additional constraints or priorities
169
+
170
+ ---
171
+
172
+ ### Step 5: Execute with Reflection
173
+
174
+ **Execute each task with reflection tracking:**
175
+
176
+ Initialize reflection-log.md:
177
+ ```markdown
178
+ # Refactoring Reflection Log
179
+
180
+ Scope: {scope}
181
+ Started: {ISO timestamp}
182
+
183
+ ---
184
+ ```
185
+
186
+ For each task in order:
187
+
188
+ **5a. Execute the refactoring:**
189
+ Implement the change as described in the task.
190
+
191
+ **5b. Run existing tests:**
192
+ ```bash
193
+ # Detect and run test suite
194
+ npm test 2>&1 || pytest 2>&1 || go test ./... 2>&1 || echo "No test runner detected"
195
+ ```
196
+
197
+ **5c. Record in reflection-log.md:**
198
+ ```markdown
199
+ ## Round {N}: {task title}
200
+
201
+ - **Strategy:** {approach taken}
202
+ - **Result:** {pass|fail} -- {brief outcome}
203
+ - **Tests:** {all pass | N failures}
204
+ - **Adjustment:** {what to change in approach for next round, or "none needed"}
205
+ - **Files changed:** {list}
206
+
207
+ ---
208
+ ```
209
+
210
+ **5d. Handle test failures:**
211
+ If tests fail after a refactoring:
212
+ 1. Revert the change
213
+ 2. Record failure in reflection-log.md with strategy adjustment
214
+ 3. Attempt with adjusted strategy (max 2 retries per task)
215
+ 4. If still failing, mark task as "blocked" and continue to next
216
+
217
+ **5e. Update task status:**
218
+ Update .task/TASK-{NNN}.json status to "completed" or "blocked".
219
+ Write .summaries/TASK-{NNN}-summary.md.
220
+ Update index.json execution fields.
221
+ Update reflection.rounds and strategy_adjustments in index.json.
222
+
223
+ ---
224
+
225
+ ### Step 6: Final Verification
226
+
227
+ **Run full test suite after all tasks:**
228
+
229
+ ```bash
230
+ npm test 2>&1 || pytest 2>&1 || go test ./... 2>&1
231
+ ```
232
+
233
+ Record final state in reflection-log.md:
234
+ ```markdown
235
+ ## Final Verification
236
+
237
+ - **Tests:** {all pass | N failures}
238
+ - **Tasks completed:** {N}/{total}
239
+ - **Tasks blocked:** {N}
240
+ - **Key learnings:** {patterns discovered during refactoring}
241
+ ```
242
+
243
+ ---
244
+
245
+ ### Step 7: Complete
246
+
247
+ **Update index.json and present summary:**
248
+
249
+ Update index.json:
250
+ ```json
251
+ {
252
+ "status": "completed",
253
+ "updated_at": "{ISO timestamp}",
254
+ "execution": {
255
+ "tasks_completed": N,
256
+ "tasks_total": M
257
+ },
258
+ "reflection": {
259
+ "rounds": N,
260
+ "strategy_adjustments": ["list of adjustments made"]
261
+ }
262
+ }
263
+ ```
264
+
265
+ Present completion summary:
266
+ ```
267
+ ## Refactoring Complete: {scope}
268
+
269
+ | Metric | Value |
270
+ |--------|-------|
271
+ | Tasks completed | {N}/{total} |
272
+ | Tasks blocked | {N} |
273
+ | Reflection rounds | {N} |
274
+ | Strategy adjustments | {N} |
275
+ | Tests passing | {yes/no} |
276
+
277
+ Key learnings:
278
+ {from reflection-log.md}
279
+
280
+ Artifacts:
281
+ - Reflection log: {REFACTOR_DIR}/reflection-log.md
282
+ - Task results: {REFACTOR_DIR}/.summaries/
283
+ ```
284
+
285
+ If regressions found: list affected tests and suggest Skill({ skill: "quality-debug" }).
286
+
287
+ ---
288
+
289
+ ## Success Criteria
290
+
291
+ - [ ] Scope parsed and validated
292
+ - [ ] Scratch directory created with index.json
293
+ - [ ] Scope analysis identifies tech debt categories
294
+ - [ ] plan.json + .task/TASK-*.json created for each refactoring
295
+ - [ ] Each task executed with test verification (no regressions)
296
+ - [ ] reflection-log.md tracks strategy per round with adjustments
297
+ - [ ] Test failures trigger revert + retry with adjusted strategy
298
+ - [ ] Full test suite passes at end
299
+ - [ ] index.json updated with final status
300
+ - [ ] .summaries/ written for completed tasks