maxsimcli 4.1.0 → 4.2.1

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 (80) hide show
  1. package/README.md +14 -5
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/assets/CHANGELOG.md +32 -0
  4. package/dist/assets/dashboard/client/assets/index-C199D4Eb.css +32 -0
  5. package/dist/assets/dashboard/client/assets/{index-C_eAetZJ.js → index-nAXJLp0_.js} +61 -59
  6. package/dist/assets/dashboard/client/index.html +2 -2
  7. package/dist/assets/dashboard/server.js +26 -11
  8. package/dist/assets/templates/agents/AGENTS.md +18 -69
  9. package/dist/assets/templates/agents/maxsim-code-reviewer.md +17 -92
  10. package/dist/assets/templates/agents/maxsim-codebase-mapper.md +57 -694
  11. package/dist/assets/templates/agents/maxsim-debugger.md +80 -925
  12. package/dist/assets/templates/agents/maxsim-executor.md +94 -431
  13. package/dist/assets/templates/agents/maxsim-integration-checker.md +51 -319
  14. package/dist/assets/templates/agents/maxsim-phase-researcher.md +63 -429
  15. package/dist/assets/templates/agents/maxsim-plan-checker.md +79 -568
  16. package/dist/assets/templates/agents/maxsim-planner.md +125 -855
  17. package/dist/assets/templates/agents/maxsim-project-researcher.md +32 -472
  18. package/dist/assets/templates/agents/maxsim-research-synthesizer.md +25 -134
  19. package/dist/assets/templates/agents/maxsim-roadmapper.md +66 -480
  20. package/dist/assets/templates/agents/maxsim-spec-reviewer.md +13 -55
  21. package/dist/assets/templates/agents/maxsim-verifier.md +95 -450
  22. package/dist/assets/templates/commands/maxsim/artefakte.md +122 -0
  23. package/dist/assets/templates/commands/maxsim/batch.md +42 -0
  24. package/dist/assets/templates/commands/maxsim/check-todos.md +1 -0
  25. package/dist/assets/templates/commands/maxsim/sdd.md +39 -0
  26. package/dist/assets/templates/references/thinking-partner.md +33 -0
  27. package/dist/assets/templates/workflows/batch.md +420 -0
  28. package/dist/assets/templates/workflows/check-todos.md +85 -1
  29. package/dist/assets/templates/workflows/discuss-phase.md +31 -0
  30. package/dist/assets/templates/workflows/execute-plan.md +96 -27
  31. package/dist/assets/templates/workflows/help.md +47 -0
  32. package/dist/assets/templates/workflows/sdd.md +426 -0
  33. package/dist/backend-server.cjs +174 -51
  34. package/dist/backend-server.cjs.map +1 -1
  35. package/dist/cli.cjs +310 -146
  36. package/dist/cli.cjs.map +1 -1
  37. package/dist/cli.js +5 -5
  38. package/dist/cli.js.map +1 -1
  39. package/dist/core/artefakte.d.ts.map +1 -1
  40. package/dist/core/artefakte.js +16 -0
  41. package/dist/core/artefakte.js.map +1 -1
  42. package/dist/core/context-loader.d.ts +1 -0
  43. package/dist/core/context-loader.d.ts.map +1 -1
  44. package/dist/core/context-loader.js +58 -0
  45. package/dist/core/context-loader.js.map +1 -1
  46. package/dist/core/core.d.ts +6 -0
  47. package/dist/core/core.d.ts.map +1 -1
  48. package/dist/core/core.js +238 -0
  49. package/dist/core/core.js.map +1 -1
  50. package/dist/core/index.d.ts +1 -1
  51. package/dist/core/index.d.ts.map +1 -1
  52. package/dist/core/index.js +5 -3
  53. package/dist/core/index.js.map +1 -1
  54. package/dist/core/phase.d.ts +11 -11
  55. package/dist/core/phase.d.ts.map +1 -1
  56. package/dist/core/phase.js +88 -73
  57. package/dist/core/phase.js.map +1 -1
  58. package/dist/core/roadmap.d.ts +2 -2
  59. package/dist/core/roadmap.d.ts.map +1 -1
  60. package/dist/core/roadmap.js +11 -10
  61. package/dist/core/roadmap.js.map +1 -1
  62. package/dist/core/state.d.ts +11 -11
  63. package/dist/core/state.d.ts.map +1 -1
  64. package/dist/core/state.js +60 -54
  65. package/dist/core/state.js.map +1 -1
  66. package/dist/core-RRjCSt0G.cjs.map +1 -1
  67. package/dist/{lifecycle-D4E9yP6E.cjs → lifecycle-0M4VqOMm.cjs} +2 -2
  68. package/dist/{lifecycle-D4E9yP6E.cjs.map → lifecycle-0M4VqOMm.cjs.map} +1 -1
  69. package/dist/mcp/context-tools.d.ts.map +1 -1
  70. package/dist/mcp/context-tools.js +7 -3
  71. package/dist/mcp/context-tools.js.map +1 -1
  72. package/dist/mcp/phase-tools.js +3 -3
  73. package/dist/mcp/phase-tools.js.map +1 -1
  74. package/dist/mcp-server.cjs +163 -40
  75. package/dist/mcp-server.cjs.map +1 -1
  76. package/dist/{server-pvY2WbKj.cjs → server-G1MIg_Oe.cjs} +7 -7
  77. package/dist/server-G1MIg_Oe.cjs.map +1 -0
  78. package/package.json +1 -1
  79. package/dist/assets/dashboard/client/assets/index-CmiJKqOU.css +0 -32
  80. package/dist/server-pvY2WbKj.cjs.map +0 -1
@@ -0,0 +1,122 @@
1
+ ---
2
+ name: maxsim:artefakte
3
+ description: View and manage project artefakte (decisions, acceptance criteria, no-gos)
4
+ argument-hint: "[decisions|acceptance-criteria|no-gos] [--phase <N>]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Bash
9
+ - AskUserQuestion
10
+ ---
11
+
12
+ <objective>
13
+ View and manage the three artefakte documents that capture project-level and phase-level decisions:
14
+
15
+ - **DECISIONS.md** — Architectural and design decisions with rationale
16
+ - **ACCEPTANCE-CRITERIA.md** — Measurable criteria that define "done"
17
+ - **NO-GOS.md** — Explicitly excluded scope items
18
+
19
+ Supports listing all artefakte, reading a specific type, and appending new entries. When `--phase N` is provided, operations are scoped to that phase's artefakte directory.
20
+
21
+ **CRITICAL — AskUserQuestion tool mandate:**
22
+ Every single question to the user MUST use the `AskUserQuestion` tool. NEVER ask questions as plain text in your response. This includes menu selection, entry input, continuation prompts, and any other user interaction. If you need the user's input, use `AskUserQuestion`. No exceptions.
23
+ </objective>
24
+
25
+ <context>
26
+ Arguments: $ARGUMENTS
27
+
28
+ Parse from arguments:
29
+ - **type**: first positional argument — one of `decisions`, `acceptance-criteria`, `no-gos` (optional)
30
+ - **--phase N**: scope to phase N artefakte (optional)
31
+ </context>
32
+
33
+ <process>
34
+ <step name="parse-arguments">
35
+ Parse `$ARGUMENTS` to extract:
36
+ - `type` — the first positional word if it matches `decisions`, `acceptance-criteria`, or `no-gos`
37
+ - `phase` — the value after `--phase` if present
38
+
39
+ Build the base command: `node ~/.claude/maxsim/bin/maxsim-tools.cjs`
40
+ If `--phase` is set, append `--phase <N>` to all CLI calls below.
41
+ </step>
42
+
43
+ <step name="route-by-arguments">
44
+ **If no type argument is provided**, go to Step 3 (overview).
45
+ **If a type argument is provided**, go to Step 4 (read specific).
46
+ </step>
47
+
48
+ <step name="overview">
49
+ Run via Bash:
50
+ ```
51
+ node ~/.claude/maxsim/bin/maxsim-tools.cjs artefakte-list [--phase <N>]
52
+ ```
53
+
54
+ Display the result as a formatted summary showing each artefakte file's existence status and entry count.
55
+
56
+ Then use `AskUserQuestion` to offer the user a choice:
57
+ - "View decisions"
58
+ - "View acceptance criteria"
59
+ - "View no-gos"
60
+ - "Add new entry"
61
+ - "Done"
62
+
63
+ Route based on selection:
64
+ - View → go to Step 4 with the selected type
65
+ - Add → go to Step 5
66
+ - Done → end
67
+ </step>
68
+
69
+ <step name="read-specific">
70
+ Run via Bash:
71
+ ```
72
+ node ~/.claude/maxsim/bin/maxsim-tools.cjs artefakte-read <type> [--phase <N>]
73
+ ```
74
+
75
+ Display the content in a clean, readable format. If the file doesn't exist yet, say so and offer to create the first entry.
76
+
77
+ Then use `AskUserQuestion` to offer:
78
+ - "Add entry to this artefakte"
79
+ - "View another artefakte"
80
+ - "Done"
81
+
82
+ Route based on selection:
83
+ - Add → go to Step 5 with the current type
84
+ - View another → use `AskUserQuestion` to pick which type, then repeat Step 4
85
+ - Done → end
86
+ </step>
87
+
88
+ <step name="add-entry">
89
+ If the artefakte type isn't known yet, use `AskUserQuestion` to ask:
90
+ - "Which artefakte? (decisions / acceptance-criteria / no-gos)"
91
+
92
+ Then use `AskUserQuestion` to get the entry text from the user:
93
+ - For **decisions**: "What decision should be recorded? (include rationale)"
94
+ - For **acceptance-criteria**: "What acceptance criterion should be added?"
95
+ - For **no-gos**: "What should be explicitly excluded from scope? (include reason)"
96
+
97
+ Run via Bash:
98
+ ```
99
+ node ~/.claude/maxsim/bin/maxsim-tools.cjs artefakte-append <type> --entry "<text>" [--phase <N>]
100
+ ```
101
+
102
+ Confirm the entry was added. Then commit the change:
103
+ ```
104
+ node ~/.claude/maxsim/bin/maxsim-tools.cjs commit "docs: add <type> artefakte entry" --files .planning/
105
+ ```
106
+
107
+ Use `AskUserQuestion` to offer:
108
+ - "Add another entry"
109
+ - "View artefakte"
110
+ - "Done"
111
+
112
+ Route accordingly — Add another loops back to the top of Step 5, View goes to Step 3, Done ends.
113
+ </step>
114
+ </process>
115
+
116
+ <success_criteria>
117
+ - Artefakte overview accurately shows file existence and entry counts
118
+ - Individual artefakte content is displayed clearly
119
+ - New entries are appended and committed
120
+ - Phase scoping works when --phase flag is provided
121
+ - User can navigate between view/add/done without confusion
122
+ </success_criteria>
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: maxsim:batch
3
+ description: Decompose a large task into independent units and execute each in an isolated git worktree with its own PR
4
+ argument-hint: "<task description>"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Edit
9
+ - Glob
10
+ - Grep
11
+ - Bash
12
+ - Task
13
+ - AskUserQuestion
14
+ ---
15
+ <objective>
16
+ Decompose a large task into independent units, execute each in an isolated git worktree, and produce one PR per unit.
17
+
18
+ Batch mode uses the full MAXSIM system with worktree isolation:
19
+ - Spawns maxsim-planner (batch mode) to decompose the task into independent units
20
+ - Validates file independence across all units (no overlap allowed)
21
+ - Spawns one worktree agent per unit, each with its own branch and PR
22
+ - Tracks progress and handles failures with automatic retries
23
+ - Records batch metadata in `.planning/batch/`
24
+
25
+ **Use when:** Task has 3+ independent units that can be implemented in parallel.
26
+ **Do not use when:** Fewer than 3 units (use `/maxsim:quick` instead) or units have sequential dependencies.
27
+ </objective>
28
+
29
+ <execution_context>
30
+ @./workflows/batch.md
31
+ </execution_context>
32
+
33
+ <context>
34
+ $ARGUMENTS
35
+
36
+ Context files are resolved inside the workflow (`init quick`) and delegated via `<files_to_read>` blocks.
37
+ </context>
38
+
39
+ <process>
40
+ Execute the batch workflow from @./workflows/batch.md end-to-end.
41
+ Preserve all workflow gates (validation, decomposition, independence check, agent spawning, tracking, state updates).
42
+ </process>
@@ -22,6 +22,7 @@ Routes to the check-todos workflow which handles:
22
22
 
23
23
  <execution_context>
24
24
  @./workflows/check-todos.md
25
+ @./references/thinking-partner.md
25
26
  </execution_context>
26
27
 
27
28
  <context>
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: maxsim:sdd
3
+ description: Execute a phase using Spec-Driven Dispatch — fresh agent per task with 2-stage review
4
+ argument-hint: "<phase-number>"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Edit
9
+ - Glob
10
+ - Grep
11
+ - Bash
12
+ - Task
13
+ - AskUserQuestion
14
+ ---
15
+ <objective>
16
+ Execute phase plans using the Spec-Driven Dispatch (SDD) pattern. Each task is dispatched to a fresh-context subagent with minimal context. Two-stage review (spec compliance + code quality) runs between every task. No task starts until the previous task passes both review stages.
17
+
18
+ SDD differs from standard execute-phase:
19
+ - **Standard:** Single agent or segmented execution per plan
20
+ - **SDD:** Fresh agent per task with mandatory inter-task review gates
21
+
22
+ Context budget: ~10% orchestrator. 100% fresh per task agent. Zero context bleeding between tasks.
23
+ </objective>
24
+
25
+ <execution_context>
26
+ @./workflows/sdd.md
27
+ @./references/ui-brand.md
28
+ </execution_context>
29
+
30
+ <context>
31
+ Phase: $ARGUMENTS
32
+
33
+ Context files are resolved inside the workflow via `maxsim-tools init execute-phase` and per-task `<files_to_read>` blocks.
34
+ </context>
35
+
36
+ <process>
37
+ Execute the SDD workflow from @./workflows/sdd.md end-to-end.
38
+ Preserve all workflow gates (task dispatch, 2-stage review, fix iteration cap, state updates, routing).
39
+ </process>
@@ -38,4 +38,37 @@ You are a thinking partner, not a task executor. Your role is to help the user a
38
38
 
39
39
  </anti_patterns>
40
40
 
41
+ <context_modes>
42
+
43
+ **Project initialization** (new-project, init-existing): Focus on vision clarity, scope boundaries, surfacing hidden requirements. Push hard on "what problem are you solving?" and "who is this for?" Accept vague tech stack preferences early — they'll solidify during research.
44
+
45
+ **Phase discussion** (discuss-phase): Focus on implementation decisions, gray area resolution, downstream impact. Challenge hand-wavy integration plans. Push for concrete acceptance criteria per deliverable.
46
+
47
+ **Todo/bug triage** (add-todo --discuss, check-todos brainstorm): Focus on problem definition, scope containment, approach selection. Shorter rounds — 2-3 questions vs 4. Time-boxed to 20-30 min. Don't over-explore — capture enough to unblock, not to solve.
48
+
49
+ **General discussion**: Default behaviors from core_behaviors apply. Read the energy — if the user is exploring, explore with them. If they want a quick answer, give it.
50
+
51
+ </context_modes>
52
+
53
+ <escalation_patterns>
54
+
55
+ **Push harder on:**
56
+ - Vague acceptance criteria — "it should work well" is not a criterion
57
+ - Undefined error handling — "we'll handle errors" is not a plan
58
+ - "Figure it out later" on decisions that block downstream work
59
+ - Scope that keeps expanding without acknowledgment
60
+
61
+ **Accept quickly:**
62
+ - Aesthetic preferences (colors, fonts, naming)
63
+ - Minor UX details that can be changed later
64
+ - Tool/library choices when alternatives are roughly equivalent
65
+ - Formatting preferences
66
+
67
+ **Flag and move on:**
68
+ - Decisions that need external input (API docs, stakeholder approval)
69
+ - Blocked by unknowns outside the project scope
70
+ - Performance targets without measurement baseline — "make it fast" needs a benchmark first, then move on
71
+
72
+ </escalation_patterns>
73
+
41
74
  </thinking_partner>
@@ -0,0 +1,420 @@
1
+ <sanity_check>
2
+ Before executing any step in this workflow, verify:
3
+ 1. The current directory contains a `.planning/` folder — if not, stop and tell the user to run `/maxsim:new-project` first.
4
+ 2. Git is initialized (`git rev-parse --git-dir` succeeds) — worktrees require a git repository.
5
+ 3. `.planning/ROADMAP.md` exists — if not, stop and tell the user to initialize the project.
6
+ </sanity_check>
7
+
8
+ <purpose>
9
+ Decompose a large task into independent units, execute each in an isolated git worktree, and produce one PR per unit. Each unit gets its own branch, worktree, and PR — enabling parallel implementation with zero merge conflicts.
10
+
11
+ Follows the batch-worktree skill process: Research (decompose) -> Plan (validate independence) -> Spawn (worktree agents) -> Track (progress and failures).
12
+ </purpose>
13
+
14
+ <required_reading>
15
+ Read all files referenced by the invoking prompt's execution_context before starting.
16
+ @./references/dashboard-bridge.md
17
+ </required_reading>
18
+
19
+ <process>
20
+
21
+ <step name="initialize" priority="first">
22
+ Load context in one call:
23
+
24
+ ```bash
25
+ INIT=$(node ~/.claude/maxsim/bin/maxsim-tools.cjs init quick "$DESCRIPTION")
26
+ ```
27
+
28
+ Parse JSON for: `planner_model`, `executor_model`, `slug`, `date`, `timestamp`, `roadmap_exists`, `planning_exists`.
29
+
30
+ **If `roadmap_exists` is false:** Error — Batch mode requires an active project with ROADMAP.md. Run `/maxsim:new-project` first.
31
+
32
+ Verify git is available:
33
+ ```bash
34
+ git rev-parse --git-dir > /dev/null 2>&1 || echo "ERROR: Not a git repository"
35
+ ```
36
+
37
+ Store `BASE_BRANCH`:
38
+ ```bash
39
+ BASE_BRANCH=$(git rev-parse --abbrev-ref HEAD)
40
+ ```
41
+ </step>
42
+
43
+ <step name="gather_task">
44
+ Parse `$ARGUMENTS` for the task description.
45
+
46
+ If `$ARGUMENTS` is empty, prompt user interactively:
47
+
48
+ ```
49
+ AskUserQuestion(
50
+ header: "Batch Task",
51
+ question: "Describe the large task to decompose into independent worktree units.",
52
+ followUp: null
53
+ )
54
+ ```
55
+
56
+ Store response as `$DESCRIPTION`.
57
+
58
+ If still empty, re-prompt: "Please provide a task description."
59
+
60
+ Display banner:
61
+ ```
62
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
63
+ MAXSIM > BATCH WORKTREE EXECUTION
64
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
65
+
66
+ Task: ${DESCRIPTION}
67
+ Base branch: ${BASE_BRANCH}
68
+ ```
69
+ </step>
70
+
71
+ <step name="decompose">
72
+ Spawn maxsim-planner with batch-specific prompt to produce a decomposition:
73
+
74
+ ```
75
+ Task(
76
+ prompt="
77
+ <planning_context>
78
+
79
+ **Mode:** batch
80
+ **Description:** ${DESCRIPTION}
81
+ **Base branch:** ${BASE_BRANCH}
82
+
83
+ <files_to_read>
84
+ - .planning/STATE.md (Project State)
85
+ - .planning/ROADMAP.md (Phase structure)
86
+ - ./CLAUDE.md (if exists — follow project-specific guidelines)
87
+ - .skills/batch-worktree/SKILL.md (if exists — batch-worktree constraints)
88
+ </files_to_read>
89
+
90
+ **Project skills:** Check .skills/ directory (if exists) — read SKILL.md files, plans should account for project skill rules
91
+
92
+ </planning_context>
93
+
94
+ <constraints>
95
+ - Decompose into 3-30 independent units
96
+ - Each unit MUST be independently mergeable (hard gate from batch-worktree skill)
97
+ - If fewer than 3 units are identified, STOP and recommend /maxsim:quick instead
98
+ - No file may appear in more than one unit
99
+ - No runtime dependency between units (unit A output must not be unit B input)
100
+ - Each unit must have: title, description, files owned, acceptance criteria
101
+ </constraints>
102
+
103
+ <output>
104
+ Write decomposition to: .planning/batch/${slug}/DECOMPOSITION.md
105
+
106
+ Format:
107
+ ---
108
+ task: ${DESCRIPTION}
109
+ date: ${date}
110
+ base_branch: ${BASE_BRANCH}
111
+ unit_count: N
112
+ status: pending
113
+ ---
114
+
115
+ ## Units
116
+
117
+ ### Unit 1: [Title]
118
+ **Description:** ...
119
+ **Files owned:**
120
+ - path/to/file1.ts
121
+ - path/to/file2.ts
122
+ **Acceptance criteria:**
123
+ - [ ] Criterion 1
124
+ - [ ] Criterion 2
125
+
126
+ ### Unit 2: [Title]
127
+ ...
128
+
129
+ ## Independence Matrix
130
+ [For each pair of units, confirm no file overlap and no runtime dependency]
131
+
132
+ Return: ## PLANNING COMPLETE with unit count and decomposition path
133
+ </output>
134
+ ",
135
+ subagent_type="maxsim-planner",
136
+ model="{planner_model}",
137
+ description="Batch decomposition: ${DESCRIPTION}"
138
+ )
139
+ ```
140
+
141
+ After planner returns:
142
+ 1. Verify decomposition exists at `.planning/batch/${slug}/DECOMPOSITION.md`
143
+ 2. Extract unit count
144
+ 3. If unit count < 3: warn user and suggest `/maxsim:quick` instead. Ask: "Continue with batch (${unit_count} units) or switch to quick mode?"
145
+ 4. Report: "Decomposition complete: ${unit_count} units identified"
146
+
147
+ If decomposition not found, error: "Planner failed to create DECOMPOSITION.md"
148
+ </step>
149
+
150
+ <step name="validate_independence">
151
+ Read the DECOMPOSITION.md and validate file independence across all units.
152
+
153
+ For each pair of units:
154
+ 1. Extract the files owned by each unit
155
+ 2. Compute the intersection
156
+ 3. If any file appears in more than one unit, the validation fails
157
+
158
+ **If validation fails:**
159
+
160
+ Report the overlapping files and which units conflict:
161
+ ```
162
+ ## Independence Validation Failed
163
+
164
+ | File | Unit A | Unit B |
165
+ |------|--------|--------|
166
+ | path/to/file.ts | Unit 1: Title | Unit 3: Title |
167
+ ```
168
+
169
+ Return to planner with revision prompt:
170
+ ```
171
+ Task(
172
+ prompt="
173
+ <revision_context>
174
+
175
+ <files_to_read>
176
+ - .planning/batch/${slug}/DECOMPOSITION.md (Existing decomposition)
177
+ </files_to_read>
178
+
179
+ **Independence validation failed.** The following files appear in multiple units:
180
+ ${overlap_table}
181
+
182
+ Options:
183
+ 1. Merge overlapping units into one
184
+ 2. Extract shared files into a prerequisite unit that runs first
185
+ 3. Redesign the split so each file belongs to exactly one unit
186
+
187
+ Revise DECOMPOSITION.md to resolve all overlaps.
188
+ </revision_context>
189
+ ",
190
+ subagent_type="maxsim-planner",
191
+ model="{planner_model}",
192
+ description="Revise batch decomposition: fix overlaps"
193
+ )
194
+ ```
195
+
196
+ Re-validate after revision. If validation fails a second time, stop and escalate to user.
197
+
198
+ **If validation passes:**
199
+
200
+ ```
201
+ Independence validated: ${unit_count} units, no file overlap
202
+ ```
203
+ </step>
204
+
205
+ <step name="record_decision">
206
+ Record the decomposition decision in STATE.md:
207
+
208
+ ```bash
209
+ node ~/.claude/maxsim/bin/maxsim-tools.cjs state add-decision --phase "batch" --summary "Batch decomposition: ${unit_count} units, no file overlap confirmed"
210
+ ```
211
+ </step>
212
+
213
+ <step name="spawn_worktree_agents">
214
+ For each unit in the decomposition, spawn a worktree agent.
215
+
216
+ Display progress table header:
217
+ ```
218
+ ## Spawning Worktree Agents
219
+
220
+ | # | Unit | Status | PR |
221
+ |---|------|--------|----|
222
+ ```
223
+
224
+ For each unit (spawn all with `run_in_background: true` for parallel execution):
225
+
226
+ ```
227
+ Task(
228
+ subagent_type="general-purpose",
229
+ model="{executor_model}",
230
+ isolation="worktree",
231
+ run_in_background=true,
232
+ prompt="
233
+ You are implementing Unit ${unit_number} of a batch worktree execution.
234
+
235
+ <unit_spec>
236
+ **Title:** ${unit_title}
237
+ **Description:** ${unit_description}
238
+ **Base branch:** ${BASE_BRANCH}
239
+ **Branch name:** batch/${slug}/unit-${unit_number}
240
+ **Files owned (ONLY touch these files):**
241
+ ${unit_files}
242
+ **Acceptance criteria:**
243
+ ${unit_criteria}
244
+ </unit_spec>
245
+
246
+ <files_to_read>
247
+ - ./CLAUDE.md (if exists — follow project-specific guidelines)
248
+ - .planning/STATE.md (Project state)
249
+ - .skills/ (if exists — list skills, read SKILL.md for each, follow relevant rules)
250
+ </files_to_read>
251
+
252
+ <instructions>
253
+ 1. Create branch: git checkout -b batch/${slug}/unit-${unit_number}
254
+ 2. Implement the changes described in the unit spec
255
+ 3. ONLY modify files listed in 'Files owned' — do not touch any other files
256
+ 4. Run tests relevant to your changes
257
+ 5. Commit atomically with message: feat(batch): ${unit_title}
258
+ 6. Push branch: git push -u origin batch/${slug}/unit-${unit_number}
259
+ 7. Create PR: gh pr create --title 'batch(${slug}): ${unit_title}' --body '## Unit ${unit_number}: ${unit_title}\n\n${unit_description}\n\nPart of batch: ${DESCRIPTION}'
260
+ 8. Return the PR URL
261
+
262
+ If tests fail, fix and retry. If you cannot fix after 2 attempts, report failure with error details.
263
+ </instructions>
264
+
265
+ <output>
266
+ Return one of:
267
+ - ## UNIT COMPLETE\nPR: <url>
268
+ - ## UNIT FAILED\nError: <details>
269
+ </output>
270
+ ",
271
+ description="Batch unit ${unit_number}: ${unit_title}"
272
+ )
273
+ ```
274
+ </step>
275
+
276
+ <step name="track_progress">
277
+ As agents complete, update the status table:
278
+
279
+ | # | Unit | Status | PR |
280
+ |---|------|--------|----|
281
+ | 1 | title | done | #123 |
282
+ | 2 | title | in-progress | -- |
283
+ | 3 | title | failed | -- |
284
+
285
+ Statuses: `pending`, `in-progress`, `done`, `failed`
286
+
287
+ After each agent returns:
288
+ 1. Parse output for `## UNIT COMPLETE` or `## UNIT FAILED`
289
+ 2. Extract PR URL if complete
290
+ 3. Update status table
291
+ 4. Report progress: "${completed}/${unit_count} units complete"
292
+
293
+ Wait for all agents to finish before proceeding.
294
+ </step>
295
+
296
+ <step name="handle_failures">
297
+ For each failed unit:
298
+
299
+ **Attempt 1 — spawn fix agent:**
300
+ ```
301
+ Task(
302
+ subagent_type="general-purpose",
303
+ model="{executor_model}",
304
+ isolation="worktree",
305
+ prompt="
306
+ Unit ${unit_number} failed with error:
307
+ ${error_details}
308
+
309
+ <unit_spec>
310
+ ${original_unit_spec}
311
+ </unit_spec>
312
+
313
+ Fix the failing unit. The worktree and branch already exist.
314
+ Check out the existing branch, diagnose the failure, fix it, test, commit, push, create PR.
315
+ ",
316
+ description="Fix batch unit ${unit_number}: ${unit_title}"
317
+ )
318
+ ```
319
+
320
+ **Merge conflict detected:** Flag to user — decomposition had hidden overlap.
321
+ ```
322
+ AskUserQuestion(
323
+ header: "Merge Conflict in Unit ${unit_number}",
324
+ question: "Unit ${unit_number} (${unit_title}) has a merge conflict. This suggests the decomposition missed a dependency. Options:\n1. Fix manually\n2. Skip this unit\n3. Abort remaining units",
325
+ followUp: null
326
+ )
327
+ ```
328
+
329
+ **3+ failures on same unit:** Stop retrying and escalate:
330
+ ```
331
+ ## Unit ${unit_number} Escalated
332
+
333
+ Unit "${unit_title}" failed 3+ times. Manual intervention required.
334
+ Error history: ${error_summaries}
335
+ Branch: batch/${slug}/unit-${unit_number}
336
+ ```
337
+ </step>
338
+
339
+ <step name="report">
340
+ After all units are resolved (complete or escalated):
341
+
342
+ ```
343
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
344
+ MAXSIM > BATCH EXECUTION COMPLETE
345
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
346
+
347
+ Task: ${DESCRIPTION}
348
+ Units: ${completed_count}/${unit_count} complete
349
+
350
+ | # | Unit | Status | PR |
351
+ |---|------|--------|----|
352
+ ${final_status_table}
353
+
354
+ ${failed_count > 0 ? "Failed units require manual attention." : "All units completed successfully."}
355
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
356
+ ```
357
+
358
+ Update STATE.md with batch completion:
359
+ ```bash
360
+ node ~/.claude/maxsim/bin/maxsim-tools.cjs state add-decision --phase "batch" --summary "Batch complete: ${completed_count}/${unit_count} units done. PRs: ${pr_list}"
361
+ ```
362
+ </step>
363
+
364
+ <step name="commit_metadata">
365
+ Store batch record in `.planning/batch/` directory.
366
+
367
+ Update DECOMPOSITION.md frontmatter status:
368
+ - All units done: `status: complete`
369
+ - Some failed: `status: partial`
370
+
371
+ Create `.planning/batch/${slug}/RESULTS.md`:
372
+ ```markdown
373
+ ---
374
+ task: ${DESCRIPTION}
375
+ date: ${date}
376
+ status: ${all_done ? "complete" : "partial"}
377
+ units_total: ${unit_count}
378
+ units_complete: ${completed_count}
379
+ units_failed: ${failed_count}
380
+ ---
381
+
382
+ ## Results
383
+
384
+ | # | Unit | Status | PR | Branch |
385
+ |---|------|--------|----|--------|
386
+ ${results_table}
387
+
388
+ ## Failed Units
389
+ ${failed_summaries or "None"}
390
+ ```
391
+
392
+ Commit metadata:
393
+ ```bash
394
+ node ~/.claude/maxsim/bin/maxsim-tools.cjs commit "docs(batch): ${DESCRIPTION}" --files .planning/batch/${slug}/DECOMPOSITION.md .planning/batch/${slug}/RESULTS.md .planning/STATE.md
395
+ ```
396
+ </step>
397
+
398
+ </process>
399
+
400
+ <success_criteria>
401
+ - [ ] `.planning/` and git repository verified
402
+ - [ ] User provides task description
403
+ - [ ] Decomposition produces 3+ independent units
404
+ - [ ] File independence validated across all unit pairs
405
+ - [ ] Decision recorded in STATE.md
406
+ - [ ] One worktree agent spawned per unit
407
+ - [ ] Each agent creates its own branch and PR
408
+ - [ ] Progress tracked with status table
409
+ - [ ] Failed units retried once before escalation
410
+ - [ ] Final report lists all PRs and flags failures
411
+ - [ ] Batch metadata committed to `.planning/batch/`
412
+ </success_criteria>
413
+
414
+ <failure_handling>
415
+ - **classifyHandoffIfNeeded false failure:** Agent reports "failed" with `classifyHandoffIfNeeded is not defined` error — Claude Code bug, not MAXSIM. Check if branch exists and has commits. If so, treat as success.
416
+ - **Independence validation fails twice:** Stop, present overlaps to user, ask for manual decomposition guidance.
417
+ - **Agent fails to create PR:** Check if `gh` CLI is authenticated. If not, report branch name for manual PR creation.
418
+ - **All agents fail:** Likely systemic issue (git config, permissions). Stop and report for investigation.
419
+ - **Fewer than 3 units identified:** Suggest `/maxsim:quick` instead. Do not force worktree overhead for small tasks.
420
+ </failure_handling>