@hanzlaa/rcode 3.4.4 → 3.4.6

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 (213) hide show
  1. package/AGENTS.md +1 -1
  2. package/CONTRIBUTING.md +63 -1
  3. package/README.md +9 -4
  4. package/cli/generate-command-skills.cjs +21 -9
  5. package/cli/index.js +0 -0
  6. package/cli/install.js +126 -7
  7. package/cli/lib/manifest.cjs +1 -1
  8. package/cli/uninstall.js +8 -0
  9. package/dist/rcode.js +1279 -2004
  10. package/package.json +16 -17
  11. package/rihal/agents/rihal-ahmed.md +2 -1
  12. package/rihal/agents/rihal-code-fixer.md +46 -0
  13. package/rihal/agents/rihal-code-reviewer.md +46 -1
  14. package/rihal/agents/rihal-deviation-analyzer.md +1 -0
  15. package/rihal/agents/rihal-docs-auditor.md +106 -1
  16. package/rihal/agents/rihal-edge-case-hunter.md +47 -1
  17. package/rihal/agents/rihal-executor.md +1 -1
  18. package/rihal/agents/rihal-khalid.md +40 -1
  19. package/rihal/agents/rihal-layla.md +2 -1
  20. package/rihal/agents/rihal-nasser.md +2 -1
  21. package/rihal/agents/rihal-noor.md +3 -2
  22. package/rihal/agents/rihal-nyquist-auditor.md +1 -1
  23. package/rihal/agents/rihal-phase-researcher.md +46 -1
  24. package/rihal/agents/rihal-planner.md +1 -1
  25. package/rihal/agents/rihal-profiler.md +45 -2
  26. package/rihal/agents/rihal-project-researcher.md +47 -0
  27. package/rihal/agents/rihal-remediation-planner.md +45 -0
  28. package/rihal/agents/rihal-roadmapper.md +46 -0
  29. package/rihal/agents/rihal-security-adversary.md +46 -1
  30. package/rihal/agents/rihal-security-auditor.md +45 -1
  31. package/rihal/agents/rihal-ui-auditor.md +44 -1
  32. package/rihal/agents/rihal-ux-designer.md +41 -1
  33. package/rihal/agents/rihal-zahra.md +2 -1
  34. package/rihal/agents/rihal-zayd.md +2 -1
  35. package/rihal/bin/lib/config.cjs +13 -1
  36. package/rihal/bin/lib/council-panel.cjs +185 -23
  37. package/rihal/bin/lib/roadmap.cjs +27 -2
  38. package/rihal/bin/rihal-tools.cjs +1837 -99
  39. package/rihal/commands/audit.md +2 -2
  40. package/rihal/commands/capture.md +12 -0
  41. package/rihal/commands/diagnose-issues.md +18 -0
  42. package/rihal/commands/discuss-phase-power.md +18 -0
  43. package/rihal/commands/feature-drift.md +18 -0
  44. package/rihal/commands/karpathy-audit.md +18 -0
  45. package/rihal/commands/lens-audit.md +70 -0
  46. package/rihal/commands/new-project-research.md +18 -0
  47. package/rihal/commands/new-project-roadmap.md +18 -0
  48. package/rihal/commands/phase.md +11 -0
  49. package/rihal/references/continuation-format.md +3 -3
  50. package/rihal/references/output-format.md +79 -0
  51. package/rihal/references/revision-loop.md +1 -1
  52. package/rihal/references/verb-dictionary.md +85 -28
  53. package/rihal/skills/actions/1-analysis/rihal-prfaq/SKILL.md +1 -1
  54. package/rihal/skills/actions/2-plan/rihal-create-epics-and-stories/SKILL.md +12 -2
  55. package/rihal/skills/actions/2-plan/rihal-create-epics-and-stories/steps/step-04-final-validation.md +12 -0
  56. package/rihal/skills/actions/2-plan/rihal-create-prd/SKILL.md +12 -2
  57. package/rihal/skills/actions/2-plan/rihal-create-story/SKILL.md +12 -2
  58. package/rihal/skills/actions/4-implementation/rihal-browser-verify/SKILL.md +1 -1
  59. package/rihal/skills/actions/4-implementation/rihal-checkpoint-preview/SKILL.md +1 -1
  60. package/rihal/skills/actions/4-implementation/rihal-ci/SKILL.md +1 -1
  61. package/rihal/skills/actions/4-implementation/rihal-code-review/SKILL.md +16 -4
  62. package/rihal/skills/actions/4-implementation/rihal-debug/SKILL.md +14 -1
  63. package/rihal/skills/actions/4-implementation/rihal-git-flow/SKILL.md +1 -1
  64. package/rihal/skills/actions/4-implementation/rihal-harden/SKILL.md +1 -1
  65. package/rihal/skills/actions/4-implementation/rihal-incremental/SKILL.md +1 -1
  66. package/rihal/skills/actions/4-implementation/rihal-migrate/SKILL.md +1 -1
  67. package/rihal/skills/actions/4-implementation/rihal-perf/SKILL.md +1 -1
  68. package/rihal/skills/actions/4-implementation/rihal-prove-it/SKILL.md +1 -1
  69. package/rihal/skills/actions/4-implementation/rihal-scaffold-project/steps/step-01-target.md +6 -0
  70. package/rihal/skills/actions/4-implementation/rihal-source-truth/SKILL.md +1 -1
  71. package/rihal/skills/actions/4-implementation/rihal-sprint-planning/SKILL.md +14 -3
  72. package/rihal/skills/actions/4-implementation/rihal-trim/SKILL.md +1 -1
  73. package/rihal/skills/agents/ahmed-hassani-director/SKILL.md +15 -1
  74. package/rihal/skills/agents/dalil-scout/SKILL.md +14 -2
  75. package/rihal/skills/agents/fatima-qa/SKILL.md +16 -1
  76. package/rihal/skills/agents/haitham-frontend/SKILL.md +13 -1
  77. package/rihal/skills/agents/hanzla-engineer/SKILL.md +13 -1
  78. package/rihal/skills/agents/hussain-pm/SKILL.md +16 -1
  79. package/rihal/skills/agents/hussain-sm/SKILL.md +14 -1
  80. package/rihal/skills/agents/layla-designer/SKILL.md +13 -1
  81. package/rihal/skills/agents/majlis-council/SKILL.md +16 -1
  82. package/rihal/skills/agents/mariam-marketing/SKILL.md +14 -1
  83. package/rihal/skills/agents/nasser-eng-manager/SKILL.md +16 -1
  84. package/rihal/skills/agents/noor-writer/SKILL.md +15 -1
  85. package/rihal/skills/agents/raees-orchestrator/SKILL.md +15 -1
  86. package/rihal/skills/agents/rihal-cross-platform-auditor/SKILL.md +162 -0
  87. package/rihal/skills/agents/rihal-dep-auditor/SKILL.md +151 -0
  88. package/rihal/skills/agents/rihal-deviation-analyzer/SKILL.md +78 -0
  89. package/rihal/skills/agents/rihal-i18n-auditor/SKILL.md +152 -0
  90. package/rihal/skills/agents/rihal-observability-auditor/SKILL.md +156 -0
  91. package/rihal/skills/agents/sadiq-analyst/SKILL.md +12 -2
  92. package/rihal/skills/agents/waleed-architect/SKILL.md +12 -2
  93. package/rihal/skills/agents/yousef-backend/SKILL.md +12 -2
  94. package/rihal/skills/agents/zahra-branding/SKILL.md +15 -1
  95. package/rihal/skills/agents/zayd-ml/SKILL.md +13 -1
  96. package/rihal/skills/core/rihal-advanced-elicitation/SKILL.md +2 -2
  97. package/rihal/skills/core/rihal-auth-audit/SKILL.md +1 -1
  98. package/rihal/skills/core/rihal-brainstorming/SKILL.md +13 -2
  99. package/rihal/skills/core/rihal-client-gate/SKILL.md +1 -1
  100. package/rihal/skills/core/rihal-clone-website/SKILL.md +11 -1
  101. package/rihal/skills/core/rihal-deploy-unify/SKILL.md +1 -1
  102. package/rihal/skills/core/rihal-distillator/SKILL.md +2 -2
  103. package/rihal/skills/core/rihal-editorial-review-prose/SKILL.md +1 -1
  104. package/rihal/skills/core/rihal-editorial-review-structure/SKILL.md +2 -2
  105. package/rihal/skills/core/rihal-help/SKILL.md +18 -1
  106. package/rihal/skills/core/rihal-incident-record/SKILL.md +1 -1
  107. package/rihal/skills/core/rihal-index-docs/SKILL.md +1 -1
  108. package/rihal/skills/core/rihal-memory-audit/SKILL.md +18 -1
  109. package/rihal/skills/core/rihal-memory-init/SKILL.md +13 -1
  110. package/rihal/skills/core/rihal-memory-update/SKILL.md +13 -1
  111. package/rihal/skills/core/rihal-mvp-graduate/SKILL.md +1 -1
  112. package/rihal/skills/core/rihal-ocr-consistency/SKILL.md +1 -1
  113. package/rihal/skills/core/rihal-rebrand/SKILL.md +1 -1
  114. package/rihal/skills/core/rihal-review-adversarial-general/SKILL.md +1 -1
  115. package/rihal/skills/core/rihal-review-edge-case-hunter/SKILL.md +17 -1
  116. package/rihal/skills/core/rihal-shard-doc/SKILL.md +1 -1
  117. package/rihal/skills/core/rihal-theme-system/SKILL.md +1 -1
  118. package/rihal/team.yaml +0 -7
  119. package/rihal/templates/RESEARCH.md +84 -0
  120. package/rihal/templates/VALIDATION.md +45 -0
  121. package/rihal/templates/memory/INDEX.md +1 -0
  122. package/rihal/templates/memory/project/design-system.md +128 -0
  123. package/rihal/templates/summary.md +33 -3
  124. package/rihal/workflows/add-tests.md +1 -1
  125. package/rihal/workflows/add-todo.md +6 -0
  126. package/rihal/workflows/analyze-dependencies.md +6 -0
  127. package/rihal/workflows/audit-fix.md +12 -0
  128. package/rihal/workflows/audit-milestone.md +2 -2
  129. package/rihal/workflows/audit.md +23 -14
  130. package/rihal/workflows/autonomous-smart-discuss.md +247 -0
  131. package/rihal/workflows/autonomous.md +54 -267
  132. package/rihal/workflows/capture.md +60 -0
  133. package/rihal/workflows/chain.md +1 -1
  134. package/rihal/workflows/code-review-fix.md +6 -3
  135. package/rihal/workflows/code-review.md +34 -10
  136. package/rihal/workflows/complete-milestone.md +17 -8
  137. package/rihal/workflows/correct-course.md +6 -0
  138. package/rihal/workflows/council.md +37 -23
  139. package/rihal/workflows/create-architecture.md +31 -0
  140. package/rihal/workflows/create-epics-and-stories.md +7 -1
  141. package/rihal/workflows/create-prd.md +25 -0
  142. package/rihal/workflows/dashboard.md +1 -1
  143. package/rihal/workflows/debug.md +8 -0
  144. package/rihal/workflows/decisions.md +1 -1
  145. package/rihal/workflows/diff.md +6 -0
  146. package/rihal/workflows/discuss-phase-discuss-areas.md +271 -0
  147. package/rihal/workflows/discuss-phase.md +27 -266
  148. package/rihal/workflows/do.md +51 -12
  149. package/rihal/workflows/docs-update.md +3 -0
  150. package/rihal/workflows/document-project.md +7 -1
  151. package/rihal/workflows/edit-prd.md +31 -0
  152. package/rihal/workflows/enable-hooks.md +1 -1
  153. package/rihal/workflows/execute-regression-gates.md +131 -0
  154. package/rihal/workflows/execute-sprint.md +31 -2
  155. package/rihal/workflows/execute-verify-phase-goal.md +136 -0
  156. package/rihal/workflows/execute-waves.md +404 -0
  157. package/rihal/workflows/execute.md +101 -642
  158. package/rihal/workflows/feature-drift.md +243 -0
  159. package/rihal/workflows/forensics.md +10 -2
  160. package/rihal/workflows/health.md +65 -16
  161. package/rihal/workflows/help.md +36 -9
  162. package/rihal/workflows/import.md +17 -3
  163. package/rihal/workflows/init.md +20 -10
  164. package/rihal/workflows/install.md +2 -10
  165. package/rihal/workflows/lens-audit.md +689 -0
  166. package/rihal/workflows/map-codebase.md +7 -1
  167. package/rihal/workflows/memory-audit.md +67 -5
  168. package/rihal/workflows/memory-distill.md +10 -0
  169. package/rihal/workflows/memory-init.md +4 -0
  170. package/rihal/workflows/memory-update.md +4 -0
  171. package/rihal/workflows/new-milestone.md +7 -1
  172. package/rihal/workflows/new-project-create-roadmap.md +176 -0
  173. package/rihal/workflows/new-project-define-requirements.md +160 -0
  174. package/rihal/workflows/new-project-research-decision.md +247 -0
  175. package/rihal/workflows/new-project.md +3 -557
  176. package/rihal/workflows/note.md +1 -1
  177. package/rihal/workflows/phase.md +54 -0
  178. package/rihal/workflows/plan-milestone-gaps.md +1 -1
  179. package/rihal/workflows/plan-prd-express.md +108 -0
  180. package/rihal/workflows/plan-research-validation.md +313 -0
  181. package/rihal/workflows/plan-spawn-planner.md +204 -0
  182. package/rihal/workflows/plan.md +91 -532
  183. package/rihal/workflows/plant-seed.md +1 -1
  184. package/rihal/workflows/pr-branch.md +1 -1
  185. package/rihal/workflows/profile-user.md +1 -1
  186. package/rihal/workflows/quick.md +3 -3
  187. package/rihal/workflows/remove-phase.md +6 -1
  188. package/rihal/workflows/remove-workspace.md +6 -0
  189. package/rihal/workflows/rerun.md +1 -1
  190. package/rihal/workflows/research-phase.md +4 -2
  191. package/rihal/workflows/resume-work.md +8 -3
  192. package/rihal/workflows/retrospective.md +31 -0
  193. package/rihal/workflows/review-adversarial.md +12 -0
  194. package/rihal/workflows/review.md +6 -0
  195. package/rihal/workflows/scaffold-project.md +31 -0
  196. package/rihal/workflows/scan.md +10 -0
  197. package/rihal/workflows/secure-phase.md +15 -2
  198. package/rihal/workflows/session-report.md +32 -7
  199. package/rihal/workflows/ship.md +7 -2
  200. package/rihal/workflows/show.md +6 -0
  201. package/rihal/workflows/sprint-status.md +4 -4
  202. package/rihal/workflows/status.md +2 -2
  203. package/rihal/workflows/ui-phase.md +1 -1
  204. package/rihal/workflows/undo.md +2 -3
  205. package/rihal/workflows/update.md +2 -2
  206. package/rihal/workflows/validate-phase.md +1 -1
  207. package/rihal/workflows/validate-prd.md +31 -0
  208. package/rihal/workflows/verify-phase.md +38 -5
  209. package/rihal/workflows/verify-work.md +25 -11
  210. package/rihal/workflows/workstream.md +20 -8
  211. package/server/lib/html/client.js +13 -63
  212. package/server/lib/html/shell.js +0 -1
  213. package/server/lib/scanner.js +33 -2
@@ -0,0 +1,404 @@
1
+ <purpose>
2
+ Sub-step of execute.md — execute_waves. Executes each wave of plans in sequence, handles file-overlap detection, parallel vs sequential spawning, and checkpoint plans between waves.
3
+ </purpose>
4
+
5
+ <step name="execute_waves">
6
+ Execute each selected wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`, sequential if `false`.
7
+
8
+ **For each wave:**
9
+
10
+ 1. **Intra-wave files_modified overlap check (BEFORE spawning):**
11
+
12
+ Before spawning any agents for this wave, inspect the `files_modified` list of all plans
13
+ in the wave. Check every pair of plans in the wave — if any two plans share even one file
14
+ in their `files_modified` lists, those plans have an implicit dependency and MUST NOT run
15
+ in parallel.
16
+
17
+ **Detection algorithm (pseudocode):**
18
+ ```
19
+ seen_files = {}
20
+ overlapping_plans = []
21
+ for each plan in wave_plans:
22
+ for each file in plan.files_modified:
23
+ if file in seen_files:
24
+ overlapping_plans.add(plan, seen_files[file]) # both plans overlap on this file
25
+ else:
26
+ seen_files[file] = plan
27
+ ```
28
+
29
+ **If overlap is detected:**
30
+ - Warn the user:
31
+ ```
32
+ ⚠ Intra-wave files_modified overlap detected in Wave {N}:
33
+ Plan {A} and Plan {B} both modify {file}
34
+ Running these plans sequentially to avoid parallel worktree conflicts.
35
+ ```
36
+ - Override `PARALLELIZATION` to `false` for this wave only — run all plans in the wave
37
+ sequentially regardless of the global parallelization setting.
38
+ - This is a safety net for plans that were incorrectly assigned to the same wave.
39
+ The planner should have caught this; flag it as a planning defect so the user can
40
+ replan the phase if desired.
41
+
42
+ **If no overlap:** proceed normally (parallel if `PARALLELIZATION=true`).
43
+
44
+ 2. **Describe what's being built (BEFORE spawning):**
45
+
46
+ Read each plan's `<objective>`. Extract what's being built and why.
47
+
48
+ ```
49
+ ---
50
+ ## Wave {N}
51
+
52
+ **{Plan ID}: {Plan Name}**
53
+ {2-3 sentences: what this builds, technical approach, why it matters}
54
+
55
+ Spawning {count} agent(s)...
56
+ ---
57
+ ```
58
+
59
+ - Bad: "Executing terrain generation plan"
60
+ - Good: "Procedural terrain generator using Perlin noise — creates height maps, biome zones, and collision meshes. Required before vehicle physics can interact with ground."
61
+
62
+ 3. **Spawn executor agents:**
63
+
64
+ Pass paths only — executors read files themselves with their fresh context window.
65
+ For 200k models, this keeps orchestrator context lean (~10-15%).
66
+ For 1M+ models (Opus 4.6, Sonnet 4.6), richer context can be passed directly.
67
+
68
+ **Worktree mode** (`USE_WORKTREES` is not `false`):
69
+
70
+ Before spawning, capture the current HEAD:
71
+ ```bash
72
+ EXPECTED_BASE=$(git rev-parse HEAD)
73
+ ```
74
+
75
+ **Sequential dispatch for parallel execution (waves with 2+ agents):**
76
+ When spawning multiple agents in a wave, dispatch each `Task()` call **one at a time
77
+ with `run_in_background: true`** — do NOT send all Task calls in a single message.
78
+ `git worktree add` acquires an exclusive lock on `.git/config.lock`, so simultaneous
79
+ calls race for this lock and fail. Sequential dispatch ensures each worktree finishes
80
+ creation before the next begins (the round-trip latency of each tool call provides
81
+ natural spacing), while all agents still **run in parallel** once created.
82
+
83
+ ```
84
+ # CORRECT: dispatch one Task() per message, each with run_in_background: true
85
+ # → worktrees created sequentially, agents execute in parallel
86
+ #
87
+ # WRONG: multiple Task() calls in a single message
88
+ # → simultaneous git worktree add → .git/config.lock contention → failures
89
+ ```
90
+
91
+ ```
92
+ Task(
93
+ subagent_type="rihal-executor",
94
+ model="sonnet",
95
+ description="Execute plan {plan_number} of phase {phase_number}",
96
+ model="{executor_model}",
97
+ isolation="worktree",
98
+ prompt="
99
+ <objective>
100
+ Execute plan {plan_number} of phase {phase_number}-{phase_name}.
101
+ Commit each task atomically. Create SUMMARY.md.
102
+ Do NOT update STATE.md or ROADMAP.md — the orchestrator owns those writes after all worktree agents in the wave complete.
103
+ </objective>
104
+
105
+ <worktree_branch_check>
106
+ FIRST ACTION before any other work: verify this worktree's branch is based on the correct commit.
107
+
108
+ Run:
109
+ ```bash
110
+ ACTUAL_BASE=$(git merge-base HEAD {EXPECTED_BASE})
111
+ CURRENT_HEAD=$(git rev-parse HEAD)
112
+ ```
113
+
114
+ If `ACTUAL_BASE` != `{EXPECTED_BASE}` (i.e. the worktree branch was created from an older
115
+ base such as `main` instead of the feature branch HEAD), rebase onto the correct base:
116
+ ```bash
117
+ git rebase --onto {EXPECTED_BASE} $(git rev-parse --abbrev-ref HEAD~1 2>/dev/null || git rev-parse HEAD^) HEAD 2>/dev/null || true
118
+ # If rebase fails or is a no-op, reset the branch to start from the correct base:
119
+ git reset --soft {EXPECTED_BASE}
120
+ ```
121
+
122
+ If `ACTUAL_BASE` == `{EXPECTED_BASE}`: the branch base is correct, proceed immediately.
123
+
124
+ This check fixes a known issue on Windows where `EnterWorktree` creates branches from
125
+ `main` instead of the current feature branch HEAD.
126
+ </worktree_branch_check>
127
+
128
+ <parallel_execution>
129
+ You are running as a PARALLEL executor agent. To avoid pre-commit hook
130
+ contention with other agents, acquire a file-based lock before each
131
+ commit and release it immediately after:
132
+
133
+ while ! mkdir .rihal/.commit-lock 2>/dev/null; do sleep 0.5; done
134
+ git commit -m "..." # hooks run normally
135
+ rmdir .rihal/.commit-lock
136
+
137
+ Hooks run as designed for every commit. AGENTS.md forbids --no-verify;
138
+ hook failures must be fixed at the source, not bypassed. The orchestrator
139
+ still validates state once after all agents complete.
140
+ </parallel_execution>
141
+
142
+ <execution_context>
143
+ @.rihal/workflows/execute-sprint.md
144
+ @.rihal/templates/summary.md
145
+ @.rihal/references/tdd.md
146
+ <!-- checkpoints.md (778 lines) loaded only when a task contains "checkpoint" or a prior wave failed -->
147
+ ${SPRINT_HAS_CHECKPOINT || PRIOR_WAVE_FAILED ? '@.rihal/references/checkpoints.md' : ''}
148
+ </execution_context>
149
+
150
+ <files_to_read>
151
+ Read these files at execution start using the Read tool:
152
+ - {phase_dir}/{plan_file} (Plan)
153
+ - .planning/PROJECT.md (Project context — core value, requirements, evolution rules)
154
+ - .planning/STATE.md (State)
155
+ - .planning/config.json (Config, if exists)
156
+ ${CONTEXT_WINDOW >= 500000 ? `
157
+ - ${phase_dir}/*-CONTEXT.md (User decisions from discuss-phase — honors locked choices)
158
+ - ${phase_dir}/*-RESEARCH.md (Technical research — pitfalls and patterns to follow)
159
+ - ${prior_wave_summaries} (SUMMARY.md files from earlier waves in this phase — what was already built)
160
+ ` : ''}
161
+ - ./CLAUDE.md (Project instructions, if exists — follow project-specific guidelines and coding conventions)
162
+ - .claude/skills/ or .agents/skills/ (Project skills, if either exists — list skills, read SKILL.md for each, follow relevant rules during implementation)
163
+ </files_to_read>
164
+
165
+ ${AGENT_SKILLS}
166
+
167
+ <mcp_tools>
168
+ If CLAUDE.md or project instructions reference MCP tools (e.g. jCodeMunch, context7,
169
+ or other MCP servers), prefer those tools over Grep/Glob for code navigation when available.
170
+ MCP tools often save significant tokens by providing structured code indexes.
171
+ Check tool availability first — if MCP tools are not accessible, fall back to Grep/Glob.
172
+ </mcp_tools>
173
+
174
+ <done_field_protocol>
175
+ For every task that contains a `<done>` field: treat it as the acceptance
176
+ criterion for that task. Before committing, verify every condition in `<done>`
177
+ is met (use grep, file reads, or CLI commands). If any condition fails, fix
178
+ the implementation before committing. Do NOT skip or defer `<done>` checks.
179
+ </done_field_protocol>
180
+
181
+ <success_criteria>
182
+ - [ ] All tasks executed
183
+ - [ ] Each task's <done> criteria verified before commit
184
+ - [ ] Each task committed individually
185
+ - [ ] SUMMARY.md created in plan directory
186
+ </success_criteria>
187
+ "
188
+ )
189
+ ```
190
+
191
+ **Sequential mode** (`USE_WORKTREES` is `false`):
192
+
193
+ Omit `isolation="worktree"` from the Task call. Replace the `<parallel_execution>` block with:
194
+
195
+ ```
196
+ <sequential_execution>
197
+ You are running as a SEQUENTIAL executor agent on the main working tree.
198
+ Use normal git commits (with hooks). Do NOT use --no-verify.
199
+ </sequential_execution>
200
+ ```
201
+
202
+ The sequential mode Task prompt uses the same structure as worktree mode but with these differences in success_criteria — since there is only one agent writing at a time, there are no shared-file conflicts:
203
+
204
+ ```
205
+ <success_criteria>
206
+ - [ ] All tasks executed
207
+ - [ ] Each task committed individually
208
+ - [ ] SUMMARY.md created in plan directory
209
+ - [ ] STATE.md updated with position and decisions
210
+ - [ ] ROADMAP.md updated with plan progress (via `roadmap update-plan-progress`)
211
+ </success_criteria>
212
+ ```
213
+
214
+ When worktrees are disabled, execute plans **one at a time within each wave** (sequential) regardless of the `PARALLELIZATION` setting — multiple agents writing to the same working tree concurrently would cause conflicts.
215
+
216
+ 4. **Wait for all agents in wave to complete.**
217
+
218
+ **Completion signal fallback (Copilot and runtimes where Task() may not return):**
219
+
220
+ If a spawned agent does not return a completion signal but appears to have finished
221
+ its work, do NOT block indefinitely. Instead, verify completion via spot-checks:
222
+
223
+ ```bash
224
+ # For each plan in this wave, check if the executor finished:
225
+ SUMMARY_EXISTS=$(test -f "{phase_dir}/{plan_number}-{plan_padded}-SUMMARY.md" && echo "true" || echo "false")
226
+ COMMITS_FOUND=$(git log --oneline --all --grep="{phase_number}-{plan_padded}" --since="1 hour ago" | head -1)
227
+ ```
228
+
229
+ **If SUMMARY.md exists AND commits are found:** The agent completed successfully —
230
+ treat as done and proceed to step 5. Log: `"✓ {Plan ID} completed (verified via spot-check — completion signal not received)"`
231
+
232
+ **If SUMMARY.md does NOT exist after a reasonable wait:** The agent may still be
233
+ running or may have failed silently. Check `git log --oneline -5` for recent
234
+ activity. If commits are still appearing, wait longer. If no activity, report
235
+ the plan as failed and route to the failure handler in step 6.
236
+
237
+ **This fallback applies automatically to all runtimes.** Claude Code's Task() normally
238
+ returns synchronously, but the fallback ensures resilience if it doesn't.
239
+
240
+ 5. **Post-wave hook validation (parallel mode only):**
241
+
242
+ When agents committed with `--no-verify`, run pre-commit hooks once after the wave:
243
+ ```bash
244
+ # Run project's pre-commit hooks on the current state
245
+ git diff --cached --quiet || git stash # stash any unstaged changes
246
+ git hook run pre-commit 2>&1 || echo "⚠ Pre-commit hooks failed — review before continuing"
247
+ ```
248
+ If hooks fail: report the failure and ask "Fix hook issues now?" or "Continue to next wave?"
249
+
250
+ 5.5. **Worktree cleanup (when `isolation="worktree"` was used):**
251
+
252
+ When executor agents ran in worktree isolation, their commits land on temporary branches in separate working trees. After the wave completes, merge these changes back and clean up:
253
+
254
+ ```bash
255
+ # List worktrees created by this wave's agents
256
+ WORKTREES=$(git worktree list --porcelain | grep "^worktree " | grep -v "$(pwd)$" | sed 's/^worktree //')
257
+
258
+ for WT in $WORKTREES; do
259
+ # Get the branch name for this worktree
260
+ WT_BRANCH=$(git -C "$WT" rev-parse --abbrev-ref HEAD 2>/dev/null)
261
+ if [ -n "$WT_BRANCH" ] && [ "$WT_BRANCH" != "HEAD" ]; then
262
+ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
263
+
264
+ # --- Orchestrator file protection (#1756) ---
265
+ # Snapshot orchestrator-owned files BEFORE merge. If the worktree
266
+ # branch outlived a milestone transition, its versions of STATE.md
267
+ # and ROADMAP.md are stale. Main always wins for these files.
268
+ STATE_BACKUP=$(mktemp)
269
+ ROADMAP_BACKUP=$(mktemp)
270
+ git show HEAD:.planning/STATE.md > "$STATE_BACKUP" 2>/dev/null || true
271
+ git show HEAD:.planning/ROADMAP.md > "$ROADMAP_BACKUP" 2>/dev/null || true
272
+
273
+ # Snapshot list of files on main BEFORE merge to detect resurrections
274
+ PRE_MERGE_FILES=$(git ls-files .planning/)
275
+
276
+ # Merge the worktree branch into the current branch
277
+ git merge "$WT_BRANCH" --no-edit -m "chore: merge executor worktree ($WT_BRANCH)" 2>&1 || {
278
+ echo "⚠ Merge conflict from worktree $WT_BRANCH — resolve manually"
279
+ rm -f "$STATE_BACKUP" "$ROADMAP_BACKUP"
280
+ continue
281
+ }
282
+
283
+ # Restore orchestrator-owned files (main always wins)
284
+ if [ -s "$STATE_BACKUP" ]; then
285
+ cp "$STATE_BACKUP" .planning/STATE.md
286
+ fi
287
+ if [ -s "$ROADMAP_BACKUP" ]; then
288
+ cp "$ROADMAP_BACKUP" .planning/ROADMAP.md
289
+ fi
290
+ rm -f "$STATE_BACKUP" "$ROADMAP_BACKUP"
291
+
292
+ # Detect files deleted on main but re-added by worktree merge
293
+ # (e.g., archived phase directories that were intentionally removed)
294
+ # IMPORTANT: skip executor-created planning artifacts (SUMMARY, SPRINT, RESEARCH,
295
+ # CONTEXT) — these are brand-new files, not resurrections of previously-deleted ones.
296
+ # Deleting them here would cause phases to stay stuck in "executing". (#604)
297
+ DELETED_FILES=$(git diff --diff-filter=A --name-only HEAD~1 -- .planning/ 2>/dev/null || true)
298
+ for RESURRECTED in $DELETED_FILES; do
299
+ # Never remove executor-created planning artifacts
300
+ case "$RESURRECTED" in
301
+ *-SUMMARY.md|*-SPRINT.md|*-RESEARCH.md|*-CONTEXT.md|*-PLAN.md) continue ;;
302
+ esac
303
+ # Check if this file was NOT in main's pre-merge tree
304
+ if ! echo "$PRE_MERGE_FILES" | grep -qxF "$RESURRECTED"; then
305
+ git rm -f "$RESURRECTED" 2>/dev/null || true
306
+ fi
307
+ done
308
+
309
+ # Amend merge commit with restored files if any changed
310
+ if ! git diff --quiet .planning/STATE.md .planning/ROADMAP.md 2>/dev/null || \
311
+ [ -n "$DELETED_FILES" ]; then
312
+ # Only amend the commit with .planning/ files if commit_docs is enabled (#1783)
313
+ COMMIT_DOCS=$(node ".rihal/bin/rihal-tools.cjs" config-get commit_docs 2>/dev/null || echo "true")
314
+ if [ "$COMMIT_DOCS" != "false" ]; then
315
+ git add .planning/STATE.md .planning/ROADMAP.md 2>/dev/null || true
316
+ git commit --amend --no-edit 2>/dev/null || true
317
+ fi
318
+ fi
319
+
320
+ # Remove the worktree
321
+ git worktree remove "$WT" --force 2>/dev/null || true
322
+
323
+ # Delete the temporary branch
324
+ git branch -D "$WT_BRANCH" 2>/dev/null || true
325
+ fi
326
+ done
327
+ ```
328
+
329
+ **If `workflow.use_worktrees` is `false`:** Agents ran on the main working tree — skip this step entirely.
330
+
331
+ **If no worktrees found:** Skip silently — agents may have been spawned without worktree isolation.
332
+
333
+ 5.6. **Post-wave shared artifact update (worktree mode only):**
334
+
335
+ When executor agents ran with `isolation="worktree"`, they skipped STATE.md and ROADMAP.md updates to avoid last-merge-wins overwrites. The orchestrator is the single writer for these files. After worktrees are merged back, update shared artifacts once:
336
+
337
+ ```bash
338
+ # Update ROADMAP.md for each completed plan in this wave
339
+ for PLAN_ID in ${WAVE_PLAN_IDS}; do
340
+ node ".rihal/bin/rihal-tools.cjs" roadmap update-plan-progress "${PHASE_NUMBER}" "${PLAN_ID}" completed
341
+ done
342
+
343
+ ```
344
+
345
+ Where `WAVE_PLAN_IDS` is the space-separated list of plan IDs that completed in this wave.
346
+
347
+ **If `workflow.use_worktrees` is `false`:** Sequential agents already updated STATE.md and ROADMAP.md themselves — skip this step.
348
+
349
+ 6. **Report completion — spot-check claims first:**
350
+
351
+ For each SUMMARY.md:
352
+ - Verify first 2 files from `key-files.created` exist on disk
353
+ - Check `git log --oneline --all --grep="{phase}-{plan}"` returns ≥1 commit
354
+ - Check for `## Self-Check: FAILED` marker
355
+
356
+ If ANY spot-check fails: report which plan failed, route to failure handler — ask "Retry plan?" or "Continue with remaining waves?"
357
+
358
+ If pass:
359
+ ```
360
+ ---
361
+ ## Wave {N} Complete
362
+
363
+ **{Plan ID}: {Plan Name}**
364
+ {What was built — from SUMMARY.md}
365
+ {Notable deviations, if any}
366
+
367
+ {If more waves: what this enables for next wave}
368
+ ---
369
+ ```
370
+
371
+ - Bad: "Wave 2 complete. Proceeding to Wave 3."
372
+ - Good: "Terrain system complete — 3 biome types, height-based texturing, physics collision meshes. Vehicle physics (Wave 3) can now reference ground surfaces."
373
+
374
+ 7. **Handle failures:**
375
+
376
+ **Known Claude Code bug (classifyHandoffIfNeeded):** If an agent reports "failed" with error containing `classifyHandoffIfNeeded is not defined`, this is a Claude Code runtime bug — not a Rihal or agent issue. The error fires in the completion handler AFTER all tool calls finish. In this case: run the same spot-checks as step 5 (SUMMARY.md exists, git commits present, no Self-Check: FAILED). If spot-checks PASS → treat as **successful**. If spot-checks FAIL → treat as real failure below.
377
+
378
+ For real failures: report which plan failed → ask "Continue?" or "Stop?" → if continue, dependent plans may also fail. If stop, partial completion report.
379
+
380
+ 7b. **Pre-wave dependency check (waves 2+ only):**
381
+
382
+ Before spawning wave N+1, for each plan in the upcoming wave:
383
+ ```bash
384
+ node ".rihal/bin/rihal-tools.cjs" verify key-links {phase_dir}/{plan}-SPRINT.md
385
+ ```
386
+
387
+ If any key-link from a PRIOR wave's artifact fails verification:
388
+
389
+ ## Cross-Plan Wiring Gap
390
+
391
+ | Plan | Link | From | Expected Pattern | Status |
392
+ |------|------|------|-----------------|--------|
393
+ | {plan} | {via} | {from} | {pattern} | NOT FOUND |
394
+
395
+ Wave {N} artifacts may not be properly wired. Options:
396
+ 1. Investigate and fix before continuing
397
+ 2. Continue (may cause cascading failures in wave {N+1})
398
+
399
+ Key-links referencing files in the CURRENT (upcoming) wave are skipped.
400
+
401
+ 8. **Execute checkpoint plans between waves** — see `<checkpoint_handling>`.
402
+
403
+ 9. **Proceed to next wave.**
404
+ </step>