@hanzlaa/rcode 3.4.4 → 3.4.5

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 +5 -5
  5. package/cli/index.js +0 -0
  6. package/cli/install.js +112 -3
  7. package/cli/lib/manifest.cjs +1 -1
  8. package/cli/uninstall.js +8 -0
  9. package/dist/rcode.js +19 -1
  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
@@ -44,12 +44,14 @@ End with Next Up routing to /rihal-execute.
44
44
  @.rihal/references/output-format.md
45
45
  Read all files referenced by the invoking prompt's execution_context before starting.
46
46
 
47
- @.rihal/references/ui-brand.md
47
+ <!-- ui-brand.md (254 lines): only load when phase goal/CONTEXT.md contains UI signals (frontend|ui|component|design|style|brand) -->
48
+ ${PHASE_GOAL_HAS_UI ? '@.rihal/references/ui-brand.md' : ''}
48
49
  @.rihal/references/revision-loop.md
49
50
  @.rihal/references/gate-prompts.md
50
51
  @.rihal/references/agent-contracts.md
51
52
  @.rihal/references/gates.md
52
53
  @.rihal/references/karpathy-guidelines.md
54
+ @.rihal/references/thinking-models-planning.md
53
55
  </required_reading>
54
56
 
55
57
  <available_agent_types>
@@ -68,15 +70,20 @@ Load all context in one call (paths only to minimize orchestrator context):
68
70
  ```bash
69
71
  INIT=$(node ".rihal/bin/rihal-tools.cjs" init sprint-plan "$PHASE")
70
72
  if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
71
- AGENT_SKILLS_RESEARCHER=$(node ".rihal/bin/rihal-tools.cjs" agent-skills rihal-researcher 2>/dev/null)
73
+ AGENT_SKILLS_RESEARCHER=$(node ".rihal/bin/rihal-tools.cjs" agent-skills rihal-phase-researcher 2>/dev/null)
72
74
  AGENT_SKILLS_PLANNER=$(node ".rihal/bin/rihal-tools.cjs" agent-skills rihal-planner 2>/dev/null)
73
- AGENT_SKILLS_CHECKER=$(node ".rihal/bin/rihal-tools.cjs" agent-skills rihal-checker 2>/dev/null)
75
+ AGENT_SKILLS_CHECKER=$(node ".rihal/bin/rihal-tools.cjs" agent-skills rihal-sprint-checker 2>/dev/null)
74
76
  CONTEXT_WINDOW=$(node ".rihal/bin/rihal-tools.cjs" config-get context_window 2>/dev/null || echo "200000")
77
+
78
+ # Detect UI signals in phase goal + CONTEXT.md to decide whether to load ui-brand.md (254 lines)
79
+ PHASE_GOAL_HAS_UI=$(grep -iEl "frontend|ui|component|design|style|brand" \
80
+ .planning/phases/*${PHASE_NUMBER}*/*-CONTEXT.md \
81
+ .planning/ROADMAP.md 2>/dev/null | head -1)
75
82
  ```
76
83
 
77
84
  When `CONTEXT_WINDOW >= 500000`, the planner prompt includes prior phase CONTEXT.md files so cross-phase decisions are consistent (e.g., "use library X for all data fetching" from Phase 2 is visible to Phase 5's planner).
78
85
 
79
- Parse JSON for: `researcher_model`, `planner_model`, `checker_model`, `research_enabled`, `plan_checker_enabled`, `nyquist_validation_enabled`, `commit_docs`, `text_mode`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `padded_phase`, `has_research`, `has_context`, `has_reviews`, `has_plans`, `plan_count`, `planning_exists`, `roadmap_exists`, `phase_req_ids`, `response_language`.
86
+ Parse JSON for: `researcher_model`, `planner_model`, `checker_model`, `research_enabled`, `plan_checker_enabled`, `nyquist_validation_enabled`, `commit_docs`, `text_mode`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `padded_phase`, `has_research`, `has_context`, `has_reviews`, `has_plans`, `plan_count`, `phase_status`, `planning_exists`, `roadmap_exists`, `phase_req_ids`, `response_language`.
80
87
 
81
88
  **If `response_language` is set:** Include `response_language: {value}` in all spawned subagent prompts so any user-facing output stays in the configured language.
82
89
 
@@ -101,7 +108,7 @@ else
101
108
  fi
102
109
  ```
103
110
 
104
- When `GAPS_MODE=true`, the workflow switches to **gap-closure planning**: read the phase's VERIFICATION.md, extract verification gaps classified `gap_found` or `partial`, and produce a single new numbered plan file (`NNN-NN-PLAN.md`) that closes them. Research, CONTEXT.md gating, and VALIDATION.md creation are skipped — gaps are grounded in already-shipped code, not new design work.
111
+ When `GAPS_MODE=true`, the workflow switches to **gap-closure planning**: read the phase's VERIFICATION.md, extract verification gaps classified `gap_found` or `partial`, and produce a single new numbered plan file (`NNN-NN-SPRINT.md`) that closes them. Research, CONTEXT.md gating, and VALIDATION.md creation are skipped — gaps are grounded in already-shipped code, not new design work.
105
112
 
106
113
  **If no phase number:** Detect next unplanned phase from roadmap.
107
114
 
@@ -150,109 +157,9 @@ PHASE_INFO=$(node ".rihal/bin/rihal-tools.cjs" roadmap get-phase "${PHASE}")
150
157
 
151
158
  **If `found` is false:** Error with available phases. **If `found` is true:** Extract `phase_number`, `phase_name`, `goal` from JSON.
152
159
 
153
- ## 3.5. Handle PRD Express Path
154
-
155
- **Skip if:** No `--prd` flag in arguments.
156
-
157
- **If `--prd <filepath>` provided:**
158
-
159
- 1. Read the PRD file:
160
- ```bash
161
- PRD_CONTENT=$(cat "$PRD_FILE" 2>/dev/null)
162
- if [ -z "$PRD_CONTENT" ]; then
163
- echo "Error: PRD file not found: $PRD_FILE"
164
- exit 1
165
- fi
166
- ```
167
-
168
- 2. Display banner:
169
- ```
170
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
171
- Rihal ► PRD EXPRESS PATH
172
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
173
-
174
- Using PRD: {PRD_FILE}
175
- Generating CONTEXT.md from requirements...
176
- ```
177
-
178
- 3. Parse the PRD content and generate CONTEXT.md. The orchestrator should:
179
- - Extract all requirements, user stories, acceptance criteria, and constraints from the PRD
180
- - Map each to a locked decision (everything in the PRD is treated as a locked decision)
181
- - Identify any areas the PRD doesn't cover and mark as "Claude's Discretion"
182
- - **Extract canonical refs** from ROADMAP.md for this phase, plus any specs/ADRs referenced in the PRD — expand to full file paths (MANDATORY)
183
- - Create CONTEXT.md in the phase directory
184
-
185
- 4. Write CONTEXT.md:
186
- ```markdown
187
- # Phase [X]: [Name] - Context
188
-
189
- **Gathered:** [date]
190
- **Status:** Ready for planning
191
- **Source:** PRD Express Path ({PRD_FILE})
192
-
193
- <domain>
194
- ## Phase Boundary
195
-
196
- [Extracted from PRD — what this phase delivers]
197
-
198
- </domain>
199
-
200
- <decisions>
201
- ## Implementation Decisions
202
-
203
- {For each requirement/story/criterion in the PRD:}
204
- ### [Category derived from content]
205
- - [Requirement as locked decision]
206
-
207
- ### Claude's Discretion
208
- [Areas not covered by PRD — implementation details, technical choices]
209
-
210
- </decisions>
211
-
212
- <canonical_refs>
213
- ## Canonical References
214
-
215
- **Downstream agents MUST read these before planning or implementing.**
216
-
217
- [MANDATORY. Extract from ROADMAP.md and any docs referenced in the PRD.
218
- Use full relative paths. Group by topic area.]
219
160
 
220
- ### [Topic area]
221
- - `path/to/spec-or-adr.md` — [What it decides/defines]
161
+ @rihal/workflows/plan-prd-express.md
222
162
 
223
- [If no external specs: "No external specs — requirements fully captured in decisions above"]
224
-
225
- </canonical_refs>
226
-
227
- <specifics>
228
- ## Specific Ideas
229
-
230
- [Any specific references, examples, or concrete requirements from PRD]
231
-
232
- </specifics>
233
-
234
- <deferred>
235
- ## Deferred Ideas
236
-
237
- [Items in PRD explicitly marked as future/v2/out-of-scope]
238
- [If none: "None — PRD covers phase scope"]
239
-
240
- </deferred>
241
-
242
- ---
243
-
244
- *Phase: XX-name*
245
- *Context gathered: [date] via PRD Express Path*
246
- ```
247
-
248
- 5. Commit:
249
- ```bash
250
- node ".rihal/bin/rihal-tools.cjs" commit "docs(${padded_phase}): generate context from PRD" --files "${phase_dir}/${padded_phase}-CONTEXT.md"
251
- ```
252
-
253
- 6. Set `context_content` to the generated CONTEXT.md content and continue to step 5 (Handle Research).
254
-
255
- **Effect:** This completely bypasses step 4 (Load CONTEXT.md) since we just created it. The rest of the workflow (research, planning, verification) proceeds normally with the PRD-derived context.
256
163
 
257
164
  ## 3.6. Handle `--gaps` Mode
258
165
 
@@ -300,10 +207,10 @@ Exit workflow.
300
207
  **Step 3: Determine next plan number**
301
208
 
302
209
  ```bash
303
- EXISTING_PLAN_COUNT=$(ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null | wc -l | tr -d ' ')
210
+ EXISTING_PLAN_COUNT=$(ls "${PHASE_DIR}"/*-SPRINT.md 2>/dev/null | wc -l | tr -d ' ')
304
211
  NEXT_PLAN_NUMBER=$(printf "%02d" $((EXISTING_PLAN_COUNT + 1)))
305
212
  PADDED_PHASE=$(printf "%02d" "${PHASE}")
306
- GAP_PLAN_FILENAME="${PADDED_PHASE}-${NEXT_PLAN_NUMBER}-PLAN.md"
213
+ GAP_PLAN_FILENAME="${PADDED_PHASE}-${NEXT_PLAN_NUMBER}-SPRINT.md"
307
214
  GAP_PLAN_PATH="${PHASE_DIR}/${GAP_PLAN_FILENAME}"
308
215
  ```
309
216
 
@@ -312,7 +219,7 @@ If `EXISTING_PLAN_COUNT == 0`, there is no prior execution to reference. Display
312
219
  **Step 4: Gather prior plans for planner context**
313
220
 
314
221
  ```bash
315
- EXISTING_PLAN_FILES=$(ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null | tr '\n' ' ')
222
+ EXISTING_PLAN_FILES=$(ls "${PHASE_DIR}"/*-SPRINT.md 2>/dev/null | tr '\n' ' ')
316
223
  EXISTING_SUMMARY_FILES=$(ls "${PHASE_DIR}"/*-SUMMARY.md 2>/dev/null | tr '\n' ' ')
317
224
  ```
318
225
 
@@ -391,302 +298,64 @@ If "Run discuss-phase first":
391
298
  ```
392
299
  **Exit the sprint-plan workflow. Do not continue.**
393
300
 
394
- ## 5. Handle Research
395
-
396
- **Skip if:** `--gaps` flag or `--skip-research` flag or `--reviews` flag.
397
-
398
- **If `has_research` is true (from init) AND no `--research` flag:** Use existing, skip to step 6.
399
-
400
- **If RESEARCH.md missing OR `--research` flag:**
401
-
402
- **If no explicit flag (`--research` or `--skip-research`) and not `--auto`:**
403
- Ask the user whether to research, with a contextual recommendation based on the phase:
404
-
405
- If `TEXT_MODE` is true, present as a plain-text numbered list:
406
- ```
407
- Research before planning Phase {X}: {phase_name}?
408
-
409
- 1. Research first (Recommended) — Investigate domain, patterns, and dependencies before planning. Best for new features, unfamiliar integrations, or architectural changes.
410
- 2. Skip research — Plan directly from context and requirements. Best for bug fixes, simple refactors, or well-understood tasks.
411
-
412
- Enter number:
413
- ```
414
-
415
- Otherwise use AskUserQuestion:
416
- ```
417
- AskUserQuestion([
418
- {
419
- question: "Research before planning Phase {X}: {phase_name}?",
420
- header: "Research",
421
- multiSelect: false,
422
- options: [
423
- { label: "Research first (Recommended)", description: "Investigate domain, patterns, and dependencies before planning. Best for new features, unfamiliar integrations, or architectural changes." },
424
- { label: "Skip research", description: "Plan directly from context and requirements. Best for bug fixes, simple refactors, or well-understood tasks." }
425
- ]
426
- }
427
- ])
428
- ```
429
-
430
- If user selects "Skip research": skip to step 6.
431
-
432
- **If `--auto` and `research_enabled` is false:** Skip research silently (preserves automated behavior).
433
-
434
- Display banner:
435
- ```
436
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
437
- Rihal ► RESEARCHING PHASE {X}
438
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
439
-
440
- ◆ Spawning researcher...
441
- ```
442
-
443
- ### Spawn rihal-phase-researcher
444
-
445
- ```bash
446
- PHASE_DESC=$(node ".rihal/bin/rihal-tools.cjs" roadmap get-phase "${PHASE}" --pick section)
447
- ```
448
-
449
- Research prompt:
450
-
451
- ```markdown
452
- <objective>
453
- Research how to implement Phase {phase_number}: {phase_name}
454
- Answer: "What do I need to know to PLAN this phase well?"
455
- </objective>
456
-
457
- <files_to_read>
458
- - {context_path} (USER DECISIONS from /rihal-discuss-phase)
459
- - {requirements_path} (Project requirements)
460
- - {state_path} (Project decisions and history)
461
- </files_to_read>
462
-
463
- ${AGENT_SKILLS_RESEARCHER}
464
-
465
- <additional_context>
466
- **Phase description:** {phase_description}
467
- **Phase requirement IDs (MUST address):** {phase_req_ids}
468
-
469
- **Project instructions:** Read ./CLAUDE.md if exists — follow project-specific guidelines
470
- **Project skills:** Check .claude/skills/ or .agents/skills/ directory (if either exists) — read SKILL.md files, research should account for project skill patterns
471
- </additional_context>
472
-
473
- <output>
474
- Write to: {phase_dir}/{phase_num}-RESEARCH.md
475
- </output>
476
- ```
477
-
478
- ```
479
- Task(
480
- prompt=research_prompt,
481
- subagent_type="rihal-phase-researcher",
482
- model="{researcher_model}",
483
- description="Research Phase {phase}"
484
- )
485
- ```
486
-
487
- ### Handle Researcher Return
488
301
 
489
- - **`## RESEARCH COMPLETE`:** Display confirmation, continue to step 6
490
- - **`## RESEARCH BLOCKED`:** Display blocker, offer: 1) Provide context, 2) Skip research, 3) Abort
302
+ @rihal/workflows/plan-research-validation.md
491
303
 
492
- ## 5.5. Create Validation Strategy
493
-
494
- Skip if `nyquist_validation_enabled` is false OR `research_enabled` is false.
495
-
496
- If `research_enabled` is false and `nyquist_validation_enabled` is true: warn "Nyquist validation enabled but research disabled — VALIDATION.md cannot be created without RESEARCH.md. Plans will lack validation requirements (Dimension 8)." Continue to step 6.
497
-
498
- **But Nyquist is not applicable for this run** when all of the following are true:
499
- - `research_enabled` is false
500
- - `has_research` is false
501
- - no `--research` flag was provided
502
-
503
- In that case: **skip validation-strategy creation entirely**. Do **not** expect `RESEARCH.md` or `VALIDATION.md` for this run, and continue to Step 6.
504
-
505
- ```bash
506
- grep -l "## Validation Architecture" "${PHASE_DIR}"/*-RESEARCH.md 2>/dev/null || true
507
- ```
508
-
509
- **If found:**
510
- 1. Read template: `.rihal/templates/VALIDATION.md`
511
- 2. Write to `${PHASE_DIR}/${PADDED_PHASE}-VALIDATION.md` (use Write tool)
512
- 3. Fill frontmatter: `{N}` → phase number, `{phase-slug}` → slug, `{date}` → current date
513
- 4. Verify:
514
- ```bash
515
- test -f "${PHASE_DIR}/${PADDED_PHASE}-VALIDATION.md" && echo "VALIDATION_CREATED=true" || echo "VALIDATION_CREATED=false"
516
- ```
517
- 5. If `VALIDATION_CREATED=false`: STOP — do not proceed to Step 6
518
- 6. If `commit_docs`: `commit "docs(phase-${PHASE}): add validation strategy"`
519
-
520
- **If not found:** Warn and continue — plans may fail Dimension 8.
521
-
522
- ## 5.55. Security Threat Model Gate
523
-
524
- > Skip if `workflow.security_enforcement` is explicitly `false`. Absent = enabled.
525
-
526
- ```bash
527
- SECURITY_CFG=$(node ".rihal/bin/rihal-tools.cjs" config-get workflow.security_enforcement --raw 2>/dev/null || echo "true")
528
- SECURITY_ASVS=$(node ".rihal/bin/rihal-tools.cjs" config-get workflow.security_asvs_level --raw 2>/dev/null || echo "1")
529
- SECURITY_BLOCK=$(node ".rihal/bin/rihal-tools.cjs" config-get workflow.security_block_on --raw 2>/dev/null || echo "high")
530
- ```
531
304
 
532
- **If `SECURITY_CFG` is `false`:** Skip to step 5.6.
533
-
534
- **If `SECURITY_CFG` is `true`:** Display banner:
535
-
536
- ```
537
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
538
- Rihal ► SECURITY THREAT MODEL REQUIRED (ASVS L{SECURITY_ASVS})
539
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
540
-
541
- Each SPRINT.md must include a <threat_model> block.
542
- Block on: {SECURITY_BLOCK} severity threats.
543
- Opt out: set security_enforcement: false in .planning/config.json
544
- ```
545
-
546
- Continue to step 5.6. Security config is passed to the planner in step 8.
547
-
548
- ## 5.6. UI Design Contract Gate
549
-
550
- > Skip if `workflow.ui_phase` is explicitly `false` AND `workflow.ui_safety_gate` is explicitly `false` in `.planning/config.json`. If keys are absent, treat as enabled.
551
-
552
- ```bash
553
- UI_PHASE_CFG=$(node ".rihal/bin/rihal-tools.cjs" config-get workflow.ui_phase 2>/dev/null || echo "true")
554
- UI_GATE_CFG=$(node ".rihal/bin/rihal-tools.cjs" config-get workflow.ui_safety_gate 2>/dev/null || echo "true")
555
- ```
556
-
557
- **If both are `false`:** Skip to step 6.
558
-
559
- Check if phase has frontend indicators:
560
-
561
- ```bash
562
- PHASE_SECTION=$(node ".rihal/bin/rihal-tools.cjs" roadmap get-phase "${PHASE}" 2>/dev/null)
563
- echo "$PHASE_SECTION" | grep -iE "UI|interface|frontend|component|layout|page|screen|view|form|dashboard|widget" > /dev/null 2>&1
564
- HAS_UI=$?
565
- ```
566
-
567
- **If `HAS_UI` is 0 (frontend indicators found):**
568
-
569
- Check for existing UI-SPEC:
570
- ```bash
571
- UI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-UI-SPEC.md 2>/dev/null | head -1)
572
- ```
573
-
574
- **If UI-SPEC.md found:** Set `UI_SPEC_PATH=$UI_SPEC_FILE`. Display: `Using UI design contract: ${UI_SPEC_PATH}`
575
-
576
- **If UI-SPEC.md missing AND `UI_GATE_CFG` is `true`:**
305
+ ## 6. Check Existing Plans
577
306
 
578
- Read auto-chain state:
579
307
  ```bash
580
- AUTO_CHAIN=$(node ".rihal/bin/rihal-tools.cjs" config-get workflow._auto_chain_active 2>/dev/null || echo "false")
308
+ ls "${PHASE_DIR}"/*-SPRINT.md 2>/dev/null || true
581
309
  ```
582
310
 
583
- **If `AUTO_CHAIN` is `true` (running inside a `--chain` or `--auto` pipeline):**
311
+ **If exists AND `--reviews` flag:** Skip prompt — go straight to replanning (the purpose of `--reviews` is to replan with review feedback).
584
312
 
585
- Auto-generate UI-SPEC without prompting:
586
- ```
587
- Skill(skill="rihal-ui-phase", args="${PHASE} --auto ${Rihal_WS}")
588
- ```
589
- After `rihal-ui-phase` returns, re-read:
590
- ```bash
591
- UI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-UI-SPEC.md 2>/dev/null | head -1)
592
- UI_SPEC_PATH="${UI_SPEC_FILE}"
593
- ```
594
- Continue to step 6.
313
+ **If exists AND no `--reviews` flag:** Ask the user what they'd like to do. Tailor the message to context — do NOT say "as per the workflow" or expose implementation details. Examples:
595
314
 
596
- **If `AUTO_CHAIN` is `false` (manual invocation):**
315
+ - If `phase_status` is `complete` or `executed`:
316
+ > "Phase {N} ({name}) already shipped {plan_count} plans and is marked {status}. Do you want to review those plans, add more, or replan from scratch?"
597
317
 
598
- If `TEXT_MODE` is true, present as a plain-text numbered list:
599
- ```
600
- Phase {N} has frontend indicators but no UI-SPEC.md. Generate a design contract before planning?
318
+ - If `phase_status` is `in_progress` or `planned` (or null):
319
+ > "Phase {N} ({name}) already has {plan_count} plan(s). Want to add more, review what's there, or start fresh?"
601
320
 
602
- 1. Generate UI-SPEC first Run /rihal-ui-phase {N} then re-run /rihal-sprint-plan {N}
603
- 2. Continue without UI-SPEC
604
- 3. Not a frontend phase
321
+ Always offer exactly three numbered options:
322
+ 1. Add more plans
323
+ 2. View existing plans
324
+ 3. Replan from scratch
605
325
 
606
- Enter number:
607
- ```
326
+ Wait for the user's choice before proceeding. Do not auto-select.
608
327
 
609
- Otherwise use AskUserQuestion:
610
- - header: "UI Design Contract"
611
- - question: "Phase {N} has frontend indicators but no UI-SPEC.md. Generate a design contract before planning?"
612
- - options:
613
- - "Generate UI-SPEC first" → Display: "Run `/rihal-ui-phase {N} ${Rihal_WS}` then re-run `/rihal-sprint-plan {N} ${Rihal_WS}`". Exit workflow.
614
- - "Continue without UI-SPEC" → Continue to step 6.
615
- - "Not a frontend phase" → Continue to step 6.
328
+ **If user picks option 2 (View existing plans):**
616
329
 
617
- **If `HAS_UI` is 1 (no frontend indicators):** Skip silently to step 5.7.
330
+ Display a sprint summary table (sprint id one-line goal).
618
331
 
619
- ## 5.7. Schema Push Detection Gate
332
+ Then run a **best-effort codebase overlap check** before showing the execute prompt — Closes #596.
620
333
 
621
- > Detects schema-relevant files in the phase scope and injects a mandatory `[BLOCKING]` schema push task into the plan. Prevents false-positive verification where build/types pass because TypeScript types come from config, not the live database.
334
+ **This check is always informational. It never blocks, never errors, never fails the workflow.** If any step below cannot complete for any reason, skip it silently and proceed straight to the execute prompt.
622
335
 
623
- Check if any files in the phase scope match schema patterns:
336
+ 1. Read the SPRINT.md files for this phase (they are already on disk — no tool calls needed beyond `Read`).
337
+ 2. From each sprint's `files_modified:` frontmatter list, note which paths already exist on disk vs. which are new.
338
+ 3. Separately, look at the sprint *goals* and compare against modules/components the codebase already has. Use your knowledge from any files already read this session; do NOT spawn new reads just for this check.
339
+ 4. Report what you found — one compact block:
624
340
 
625
- ```bash
626
- PHASE_SECTION=$(node ".rihal/bin/rihal-tools.cjs" roadmap get-phase "${PHASE}" --pick section 2>/dev/null)
627
341
  ```
628
-
629
- Scan `PHASE_SECTION`, `CONTEXT.md` (if loaded), and `RESEARCH.md` (if exists) for file paths matching these ORM patterns:
630
-
631
- | ORM | File Patterns |
632
- |-----|--------------|
633
- | Payload CMS | `src/collections/**/*.ts`, `src/globals/**/*.ts` |
634
- | Prisma | `prisma/schema.prisma`, `prisma/schema/*.prisma` |
635
- | Drizzle | `drizzle/schema.ts`, `src/db/schema.ts`, `drizzle/*.ts` |
636
- | Supabase | `supabase/migrations/*.sql` |
637
- | TypeORM | `src/entities/**/*.ts`, `src/migrations/**/*.ts` |
638
-
639
- Also check if any existing SPRINT.md files for this phase already reference these file patterns in `files_modified`.
640
-
641
- **If schema-relevant files detected:**
642
-
643
- Set `SCHEMA_PUSH_REQUIRED=true` and `SCHEMA_ORM={detected_orm}`.
644
-
645
- Determine the push command for the detected ORM:
646
-
647
- | ORM | Push Command | Non-TTY Workaround |
648
- |-----|-------------|-------------------|
649
- | Payload CMS | `npx payload migrate` | `CI=true PAYLOAD_MIGRATING=true npx payload migrate` |
650
- | Prisma | `npx prisma db push` | `npx prisma db push --accept-data-loss` (if destructive) |
651
- | Drizzle | `npx drizzle-kit push` | `npx drizzle-kit push` |
652
- | Supabase | `supabase db push` | Set `SUPABASE_ACCESS_TOKEN` env var |
653
- | TypeORM | `npx typeorm migration:run` | `npx typeorm migration:run -d src/data-source.ts` |
654
-
655
- Inject the following into the planner prompt (step 8) as an additional constraint:
656
-
657
- ```markdown
658
- <schema_push_requirement>
659
- **[BLOCKING] Schema Push Required**
660
-
661
- This phase modifies schema-relevant files ({detected_files}). The planner MUST include
662
- a `[BLOCKING]` task that runs the database schema push command AFTER all schema file
663
- modifications are complete but BEFORE verification.
664
-
665
- - ORM detected: {SCHEMA_ORM}
666
- - Push command: {push_command}
667
- - Non-TTY workaround: {env_hint}
668
- - If push requires interactive prompts that cannot be suppressed, flag the task for
669
- manual intervention with `autonomous: false`
670
-
671
- This task is mandatory — the phase CANNOT pass verification without it. Build and
672
- type checks will pass without the push (types come from config, not the live database),
673
- creating a false-positive verification state.
674
- </schema_push_requirement>
342
+ Codebase overlap check (best-effort):
343
+ N files already exist plans will extend them
344
+ + M files are new — will be created
345
+ Possible overlap: [file A] in the codebase may already cover [sprint X goal] — worth checking before executing
675
346
  ```
676
347
 
677
- Display: `Schema files detected ({SCHEMA_ORM})[BLOCKING] push task will be injected into plans`
348
+ If nothing notable: one line`No obvious conflicts detected.`
678
349
 
679
- **If no schema-relevant files detected:** Skip silently to step 6.
350
+ **Hard rules (dead-ends nothing here can cause failure):**
351
+ - If a SPRINT.md can't be read → skip it, don't error
352
+ - If files_modified is empty or absent → skip the file check, move on
353
+ - If you're uncertain whether an overlap is real → don't mention it (false positives are noise)
354
+ - If the whole check produces nothing → omit the block entirely, go straight to execute prompt
355
+ - **Never ask a follow-up question about the overlap** — state it and move on
356
+ - **Never refuse to show the execute prompt** because of an overlap finding
680
357
 
681
- ## 6. Check Existing Plans
682
-
683
- ```bash
684
- ls "${PHASE_DIR}"/*-SPRINT.md 2>/dev/null || true
685
- ```
686
-
687
- **If exists AND `--reviews` flag:** Skip prompt — go straight to replanning (the purpose of `--reviews` is to replan with review feedback).
688
-
689
- **If exists AND no `--reviews` flag:** Offer: 1) Add more plans, 2) View existing, 3) Replan from scratch.
358
+ Only after showing overlap results (or skipping them), show the execute prompt.
690
359
 
691
360
  ## 7. Use Context Paths from INIT
692
361
 
@@ -727,165 +396,43 @@ If missing and Nyquist is still enabled/applicable — ask user:
727
396
 
728
397
  Proceed to Step 8 only if user selects 2 or 3.
729
398
 
730
- ## 8. Spawn rihal-planner Agent
731
-
732
- Display banner:
733
- ```
734
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
735
- Rihal ► PLANNING PHASE {X}
736
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
737
-
738
- ◆ Spawning planner...
739
- ```
740
399
 
741
- **Gap-closure planner prompt (when `GAPS_MODE=true`):**
400
+ @rihal/workflows/plan-spawn-planner.md
742
401
 
743
- When `GAPS_MODE=true`, use the prompt below in place of the standard planner prompt. The planner must emit **exactly one** new plan file at `${GAP_PLAN_PATH}` that closes the listed gaps. Do not create CONTEXT.md or RESEARCH.md references — gaps are grounded in already-shipped code.
402
+ ## 9. Handle Planner Return
744
403
 
745
- ```markdown
746
- <planning_context>
747
- **Phase:** {phase_number}
748
- **Mode:** gap_closure
749
- **Phase goal:** {goal from ROADMAP.md}
404
+ - **`## PLANNING COMPLETE`:** Display plan count. If `--skip-verify` or `plan_checker_enabled` is false (from init): skip to step 13. Otherwise: step 10.
405
+ - **`## PHASE SPLIT RECOMMENDED`:** The planner determined the phase is too complex to implement all user decisions without simplifying them. Handle in step 9b.
406
+ - **`## CHECKPOINT REACHED`:** Present to user, get response, spawn continuation (step 12)
407
+ - **`## PLANNING INCONCLUSIVE`:** Show attempts, offer: Add context / Retry / Manual
750
408
 
751
- <files_to_read>
752
- - {VERIFICATION_FILE} (Authoritative verification report — source of truth for gaps)
753
- - {state_path} (Project State)
754
- - {roadmap_path} (Roadmap)
755
- - {requirements_path} (Requirements)
756
- - Existing plan files in this phase: {EXISTING_PLAN_FILES}
757
- - Existing summary files in this phase: {EXISTING_SUMMARY_FILES}
758
- </files_to_read>
409
+ **Sprint count guard (token cost protection — closes #584):**
759
410
 
760
- ${AGENT_SKILLS_PLANNER}
411
+ After planner returns `## PLANNING COMPLETE`, immediately count sprint files:
761
412
 
762
- <gap_list>
763
- {Serialized GAP_LIST for each gap include id, title, expected behavior, actual behavior, status (gap_found|partial), and source section.}
764
- </gap_list>
765
-
766
- <output>
767
- Write a single new plan file to: {GAP_PLAN_PATH}
768
-
769
- Frontmatter MUST include:
770
- ---
771
- phase: {phase_number}
772
- plan_number: {NEXT_PLAN_NUMBER}
773
- gap_closure: true
774
- wave: 1
775
- depends_on: []
776
- files_modified: [...]
777
- autonomous: true|false
778
- ---
779
-
780
- Each gap in the list MUST be addressed by at least one task. Use the anti-shallow execution rules below.
781
- </output>
782
- </planning_context>
413
+ ```bash
414
+ MAX_SPRINTS=$($TOOL config-get workflow.max_sprints_per_phase 2>/dev/null || echo "4")
415
+ SPRINT_COUNT=$(find "${PHASE_DIR}" -maxdepth 1 -name "*-SPRINT.md" | wc -l | tr -d ' ')
783
416
  ```
784
417
 
785
- Proceed to the standard planner Task invocation below, but pass the gap-closure prompt above. After the planner returns, the normal plan-checker / revision loop (step 10+) runs unchanged.
786
-
787
- ---
788
-
789
- **Standard planner prompt (when `GAPS_MODE=false`):**
418
+ If `SPRINT_COUNT > MAX_SPRINTS`:
790
419
 
791
- Planner prompt:
792
-
793
- ```markdown
794
- <planning_context>
795
- **Phase:** {phase_number}
796
- **Mode:** {standard | gap_closure | reviews}
797
-
798
- <files_to_read>
799
- - {state_path} (Project State)
800
- - {roadmap_path} (Roadmap)
801
- - {requirements_path} (Requirements)
802
- - {context_path} (USER DECISIONS from /rihal-discuss-phase)
803
- - {research_path} (Technical Research)
804
- - {verification_path} (Verification Gaps - if --gaps)
805
- - {uat_path} (UAT Gaps - if --gaps)
806
- - {reviews_path} (Cross-AI Review Feedback - if --reviews)
807
- - {UI_SPEC_PATH} (UI Design Contract — visual/interaction specs, if exists)
808
- ${CONTEXT_WINDOW >= 500000 ? `
809
- **Cross-phase context (1M model enrichment):**
810
- - Prior phase CONTEXT.md files (locked decisions from earlier phases — maintain consistency)
811
- - Prior phase SUMMARY.md files (what was actually built — reuse patterns, avoid duplication)
812
- ` : ''}
813
- </files_to_read>
814
-
815
- ${AGENT_SKILLS_PLANNER}
816
-
817
- **Phase requirement IDs (every ID MUST appear in a plan's `requirements` field):** {phase_req_ids}
818
-
819
- **Project instructions:** Read ./CLAUDE.md if exists — follow project-specific guidelines
820
- **Project skills:** Check .claude/skills/ or .agents/skills/ directory (if either exists) — read SKILL.md files, plans should account for project skill rules
821
-
822
- </planning_context>
823
-
824
- <downstream_consumer>
825
- Output consumed by /rihal-execute-phase. Plans need:
826
- - Frontmatter (wave, depends_on, files_modified, autonomous)
827
- - Tasks in XML format with read_first and acceptance_criteria fields (MANDATORY on every task)
828
- - Verification criteria
829
- - must_haves for goal-backward verification
830
- </downstream_consumer>
831
-
832
- <deep_work_rules>
833
- ## Anti-Shallow Execution Rules (MANDATORY)
834
-
835
- Every task MUST include these fields — they are NOT optional:
836
-
837
- 1. **`<read_first>`** — Files the executor MUST read before touching anything. Always include:
838
- - The file being modified (so executor sees current state, not assumptions)
839
- - Any "source of truth" file referenced in CONTEXT.md (reference implementations, existing patterns, config files, schemas)
840
- - Any file whose patterns, signatures, types, or conventions must be replicated or respected
841
-
842
- 2. **`<acceptance_criteria>`** — Verifiable conditions that prove the task was done correctly. Rules:
843
- - Every criterion must be checkable with grep, file read, test command, or CLI output
844
- - NEVER use subjective language ("looks correct", "properly configured", "consistent with")
845
- - ALWAYS include exact strings, patterns, values, or command outputs that must be present
846
- - Examples:
847
- - Code: `auth.py contains def verify_token(` / `test_auth.py exits 0`
848
- - Config: `.env.example contains DATABASE_URL=` / `Dockerfile contains HEALTHCHECK`
849
- - Docs: `README.md contains '## Installation'` / `API.md lists all endpoints`
850
- - Infra: `deploy.yml has rollback step` / `docker-compose.yml has healthcheck for db`
851
-
852
- 3. **`<action>`** — Must include CONCRETE values, not references. Rules:
853
- - NEVER say "align X with Y", "match X to Y", "update to be consistent" without specifying the exact target state
854
- - ALWAYS include the actual values: config keys, function signatures, SQL statements, class names, import paths, env vars, etc.
855
- - If CONTEXT.md has a comparison table or expected values, copy them into the action verbatim
856
- - The executor should be able to complete the task from the action text alone, without needing to read CONTEXT.md or reference files (read_first is for verification, not discovery)
857
-
858
- **Why this matters:** Executor agents work from the plan text. Vague instructions like "update the config to match production" produce shallow one-line changes. Concrete instructions like "add DATABASE_URL=postgresql://... , set POOL_SIZE=20, add REDIS_URL=redis://..." produce complete work. The cost of verbose plans is far less than the cost of re-doing shallow execution.
859
- </deep_work_rules>
860
-
861
- <quality_gate>
862
- - [ ] SPRINT.md files created in phase directory
863
- - [ ] Each plan has valid frontmatter
864
- - [ ] Tasks are specific and actionable
865
- - [ ] Every task has `<read_first>` with at least the file being modified
866
- - [ ] Every task has `<acceptance_criteria>` with grep-verifiable conditions
867
- - [ ] Every `<action>` contains concrete values (no "align X with Y" without specifying what)
868
- - [ ] Dependencies correctly identified
869
- - [ ] Waves assigned for parallel execution
870
- - [ ] must_haves derived from phase goal
871
- </quality_gate>
872
420
  ```
421
+ ⚠ Phase {N}: Planner created {SPRINT_COUNT} sprint files (limit: {MAX_SPRINTS}).
422
+ This phase is too large — the sprint-checker will be expensive and revision
423
+ loops will multiply the cost.
873
424
 
874
- ```
875
- Task(
876
- prompt=filled_prompt,
877
- subagent_type="rihal-planner",
878
- model="{planner_model}",
879
- description="Plan Phase {phase}"
880
- )
425
+ Recommended: split this phase into two using /rihal-plan --split {N}
426
+
427
+ Options:
428
+ 1. Split phase now (recommended)
429
+ 2. Continue anyway (accept higher token cost)
430
+ 3. Re-plan with explicit 4-sprint limit
881
431
  ```
882
432
 
883
- ## 9. Handle Planner Return
433
+ In `mode: yolo` / autonomous: auto-select option 3 (re-plan with limit). Do not halt or ask.
884
434
 
885
- - **`## PLANNING COMPLETE`:** Display plan count. If `--skip-verify` or `plan_checker_enabled` is false (from init): skip to step 13. Otherwise: step 10.
886
- - **`## PHASE SPLIT RECOMMENDED`:** The planner determined the phase is too complex to implement all user decisions without simplifying them. Handle in step 9b.
887
- - **`## CHECKPOINT REACHED`:** Present to user, get response, spawn continuation (step 12)
888
- - **`## PLANNING INCONCLUSIVE`:** Show attempts, offer: Add context / Retry / Manual
435
+ Re-plan prompt appended: `"IMPORTANT: Create at most {MAX_SPRINTS} SPRINT.md files. Merge smaller tasks into the nearest related sprint instead of creating new ones."`
889
436
 
890
437
  ## 9b. Handle Phase Split Recommendation
891
438
 
@@ -963,6 +510,7 @@ ${AGENT_SKILLS_CHECKER}
963
510
  Task(
964
511
  prompt=checker_prompt,
965
512
  subagent_type="rihal-sprint-checker",
513
+ model="sonnet",
966
514
  model="{checker_model}",
967
515
  description="Verify Phase {phase} plans"
968
516
  )
@@ -992,13 +540,23 @@ Apply this to the revision? [Yes] / [No, I'll decide]
992
540
  If yes: include the recommendation in the revision prompt. If no: proceed to revision loop as normal.
993
541
  If thinking_partner disabled: skip this block entirely.
994
542
 
995
- ## 12. Revision Loop (Max 3 Iterations)
543
+ ## 12. Revision Loop (Max 3 Iterations, 1 in autonomous/yolo mode)
544
+
545
+ **Mode-based iteration cap (token cost protection — closes #585):**
546
+
547
+ ```bash
548
+ MAX_ITERATIONS=$($TOOL config-get workflow.max_checker_iterations 2>/dev/null || echo "")
549
+ if [ -z "$MAX_ITERATIONS" ]; then
550
+ # Default: 1 in yolo/autonomous, 3 in guided
551
+ [ "$MODE" = "yolo" ] || [ -n "$AUTONOMOUS" ] && MAX_ITERATIONS=1 || MAX_ITERATIONS=3
552
+ fi
553
+ ```
996
554
 
997
555
  Track `iteration_count` (starts at 1 after initial plan + check).
998
556
  Track `prev_issue_count` (initialized to `Infinity` before the loop begins).
999
557
  Track `stall_reentry_count` (starts at 0; incremented each time "Adjust approach" re-enters step 8).
1000
558
 
1001
- **If iteration_count < 3:**
559
+ **If iteration_count < MAX_ITERATIONS:**
1002
560
 
1003
561
  **Sprint-checker malfunction guard (BLOCKER-class — added in v3.1.0 after #440):**
1004
562
 
@@ -1072,6 +630,7 @@ Return what changed.
1072
630
  Task(
1073
631
  prompt=revision_prompt,
1074
632
  subagent_type="rihal-planner",
633
+ model="sonnet",
1075
634
  model="{planner_model}",
1076
635
  description="Revise Phase {phase} plans"
1077
636
  )
@@ -1232,7 +791,7 @@ Plans ready. Launching execute-phase...
1232
791
 
1233
792
  Launch execute-phase using the Skill tool to avoid nested Task sessions (which cause runtime freezes due to deep agent nesting):
1234
793
  ```
1235
- Skill(skill="rihal-execute-phase", args="${PHASE} --auto --no-transition ${Rihal_WS}")
794
+ Skill(skill="rihal-execute", args="${PHASE} --auto --no-transition ${Rihal_WS}")
1236
795
  ```
1237
796
 
1238
797
  The `--no-transition` flag tells execute-phase to return status after verification instead of chaining further. This keeps the auto-advance chain flat — each phase runs at the same nesting level rather than spawning deeper Task agents.
@@ -1253,7 +812,7 @@ The `--no-transition` flag tells execute-phase to return status after verificati
1253
812
  Auto-advance stopped: Execution needs review.
1254
813
 
1255
814
  Review the output above and continue manually:
1256
- /rihal-execute-phase ${PHASE} ${Rihal_WS}
815
+ /rihal-execute ${PHASE} ${Rihal_WS}
1257
816
  ```
1258
817
 
1259
818
  **If neither `--auto` nor config enabled:**
@@ -1286,7 +845,7 @@ Verification: {Passed | Passed with override | Skipped}
1286
845
 
1287
846
  /clear then:
1288
847
 
1289
- /rihal-execute-phase {X} ${Rihal_WS}
848
+ /rihal-execute {X} ${Rihal_WS}
1290
849
 
1291
850
  ───────────────────────────────────────────────────────────────
1292
851