@atlashub/smartstack-cli 3.7.0 → 3.9.0

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 (133) hide show
  1. package/dist/index.js +365 -2
  2. package/dist/index.js.map +1 -1
  3. package/package.json +4 -2
  4. package/templates/agents/action.md +1 -0
  5. package/templates/agents/ba-writer.md +33 -0
  6. package/templates/agents/explore-codebase.md +1 -0
  7. package/templates/agents/explore-docs.md +1 -0
  8. package/templates/agents/fix-grammar.md +1 -0
  9. package/templates/agents/snipper.md +1 -0
  10. package/templates/skills/admin/SKILL.md +6 -0
  11. package/templates/skills/ai-prompt/SKILL.md +32 -136
  12. package/templates/skills/ai-prompt/steps/step-01-implementation.md +122 -0
  13. package/templates/skills/apex/SKILL.md +120 -0
  14. package/templates/skills/apex/_shared.md +86 -0
  15. package/templates/skills/apex/references/agent-teams-protocol.md +164 -0
  16. package/templates/skills/apex/references/smartstack-layers.md +173 -0
  17. package/templates/skills/apex/steps/step-00-init.md +156 -0
  18. package/templates/skills/apex/steps/step-01-analyze.md +169 -0
  19. package/templates/skills/apex/steps/step-02-plan.md +160 -0
  20. package/templates/skills/apex/steps/step-03-execute.md +166 -0
  21. package/templates/skills/apex/steps/step-04-validate.md +138 -0
  22. package/templates/skills/apex/steps/step-05-examine.md +124 -0
  23. package/templates/skills/apex/steps/step-06-resolve.md +105 -0
  24. package/templates/skills/apex/steps/step-07-tests.md +130 -0
  25. package/templates/skills/apex/steps/step-08-run-tests.md +115 -0
  26. package/templates/skills/application/SKILL.md +10 -0
  27. package/templates/skills/application/references/backend-controller-hierarchy.md +58 -0
  28. package/templates/skills/application/references/backend-entity-seeding.md +72 -0
  29. package/templates/skills/application/references/backend-verification.md +88 -0
  30. package/templates/skills/application/references/frontend-verification.md +111 -0
  31. package/templates/skills/application/references/nav-fallback-procedure.md +200 -0
  32. package/templates/skills/application/references/provider-template.md +134 -0
  33. package/templates/skills/application/references/test-frontend.md +73 -0
  34. package/templates/skills/application/references/test-prerequisites.md +72 -0
  35. package/templates/skills/application/steps/step-01-navigation.md +7 -198
  36. package/templates/skills/application/steps/step-03b-provider.md +4 -128
  37. package/templates/skills/application/steps/step-04-backend.md +20 -350
  38. package/templates/skills/application/steps/step-05-frontend.md +12 -101
  39. package/templates/skills/application/steps/step-07-tests.md +12 -132
  40. package/templates/skills/business-analyse/SKILL.md +11 -2
  41. package/templates/skills/business-analyse/html/ba-interactive.html +3214 -2246
  42. package/templates/skills/business-analyse/html/build-html.js +77 -0
  43. package/templates/skills/business-analyse/html/src/scripts/01-data-init.js +130 -0
  44. package/templates/skills/business-analyse/html/src/scripts/02-navigation.js +22 -0
  45. package/templates/skills/business-analyse/html/src/scripts/03-render-cadrage.js +208 -0
  46. package/templates/skills/business-analyse/html/src/scripts/04-render-modules.js +211 -0
  47. package/templates/skills/business-analyse/html/src/scripts/05-render-specs.js +554 -0
  48. package/templates/skills/business-analyse/html/src/scripts/06-render-consolidation.js +110 -0
  49. package/templates/skills/business-analyse/html/src/scripts/07-render-handoff.js +90 -0
  50. package/templates/skills/business-analyse/html/src/scripts/08-editing.js +45 -0
  51. package/templates/skills/business-analyse/html/src/scripts/09-export.js +168 -0
  52. package/templates/skills/business-analyse/html/src/scripts/10-comments.js +171 -0
  53. package/templates/skills/business-analyse/html/src/scripts/11-review-panel.js +161 -0
  54. package/templates/skills/business-analyse/html/src/styles/01-variables.css +38 -0
  55. package/templates/skills/business-analyse/html/src/styles/02-layout.css +101 -0
  56. package/templates/skills/business-analyse/html/src/styles/03-navigation.css +62 -0
  57. package/templates/skills/business-analyse/html/src/styles/04-cards.css +196 -0
  58. package/templates/skills/business-analyse/html/src/styles/05-modules.css +325 -0
  59. package/templates/skills/business-analyse/html/src/styles/06-wireframes.css +230 -0
  60. package/templates/skills/business-analyse/html/src/styles/07-comments.css +184 -0
  61. package/templates/skills/business-analyse/html/src/styles/08-review-panel.css +241 -0
  62. package/templates/skills/business-analyse/html/src/template.html +623 -0
  63. package/templates/skills/business-analyse/references/cadrage-structure-cards.md +78 -0
  64. package/templates/skills/business-analyse/references/cadrage-vibe-coding.md +97 -0
  65. package/templates/skills/business-analyse/references/consolidation-structural-checks.md +92 -0
  66. package/templates/skills/business-analyse/references/deploy-data-build.md +121 -0
  67. package/templates/skills/business-analyse/references/deploy-modes.md +49 -0
  68. package/templates/skills/business-analyse/references/handoff-file-templates.md +119 -0
  69. package/templates/skills/business-analyse/references/handoff-mappings.md +81 -0
  70. package/templates/skills/business-analyse/references/html-data-mapping.md +10 -2
  71. package/templates/skills/business-analyse/references/init-schema-deployment.md +65 -0
  72. package/templates/skills/business-analyse/references/review-data-mapping.md +363 -0
  73. package/templates/skills/business-analyse/references/spec-auto-inference.md +57 -0
  74. package/templates/skills/business-analyse/references/ui-dashboard-spec.md +85 -0
  75. package/templates/skills/business-analyse/references/ui-resource-cards.md +110 -0
  76. package/templates/skills/business-analyse/references/validate-incremental-html.md +55 -0
  77. package/templates/skills/business-analyse/steps/step-00-init.md +35 -68
  78. package/templates/skills/business-analyse/steps/step-01-cadrage.md +5 -194
  79. package/templates/skills/business-analyse/steps/step-03a-data.md +6 -49
  80. package/templates/skills/business-analyse/steps/step-03b-ui.md +12 -178
  81. package/templates/skills/business-analyse/steps/step-03d-validate.md +3 -48
  82. package/templates/skills/business-analyse/steps/step-04-consolidation.md +9 -104
  83. package/templates/skills/business-analyse/steps/step-05a-handoff.md +25 -441
  84. package/templates/skills/business-analyse/steps/step-05b-deploy.md +19 -187
  85. package/templates/skills/business-analyse/steps/step-06-review.md +277 -0
  86. package/templates/skills/cc-agent/references/agent-behavior-patterns.md +95 -0
  87. package/templates/skills/cc-agent/steps/step-02-generate.md +5 -78
  88. package/templates/skills/check-version/SKILL.md +7 -0
  89. package/templates/skills/controller/references/controller-code-templates.md +159 -0
  90. package/templates/skills/controller/references/permission-sync-templates.md +152 -0
  91. package/templates/skills/controller/steps/step-03-generate.md +6 -158
  92. package/templates/skills/controller/steps/step-04-perms.md +5 -144
  93. package/templates/skills/debug/SKILL.md +7 -0
  94. package/templates/skills/explore/SKILL.md +6 -0
  95. package/templates/skills/feature-full/SKILL.md +39 -142
  96. package/templates/skills/feature-full/steps/step-01-implementation.md +120 -0
  97. package/templates/skills/gitflow/references/init-config-template.md +135 -0
  98. package/templates/skills/gitflow/references/init-name-normalization.md +103 -0
  99. package/templates/skills/gitflow/references/plan-template.md +69 -0
  100. package/templates/skills/gitflow/references/start-efcore-preflight.md +70 -0
  101. package/templates/skills/gitflow/references/start-local-config.md +110 -0
  102. package/templates/skills/gitflow/steps/step-init.md +18 -289
  103. package/templates/skills/gitflow/steps/step-plan.md +6 -63
  104. package/templates/skills/gitflow/steps/step-start.md +16 -126
  105. package/templates/skills/mcp/SKILL.md +9 -213
  106. package/templates/skills/mcp/steps/step-01-healthcheck.md +108 -0
  107. package/templates/skills/mcp/steps/step-02-tools.md +73 -0
  108. package/templates/skills/notification/SKILL.md +7 -0
  109. package/templates/skills/quick-search/SKILL.md +5 -0
  110. package/templates/skills/ralph-loop/SKILL.md +99 -381
  111. package/templates/skills/ralph-loop/references/category-rules.md +259 -0
  112. package/templates/skills/ralph-loop/references/compact-loop.md +182 -0
  113. package/templates/skills/ralph-loop/references/task-transform-legacy.md +259 -0
  114. package/templates/skills/ralph-loop/references/team-orchestration.md +189 -0
  115. package/templates/skills/ralph-loop/steps/step-00-init.md +111 -383
  116. package/templates/skills/ralph-loop/steps/step-01-task.md +79 -896
  117. package/templates/skills/ralph-loop/steps/step-02-execute.md +68 -680
  118. package/templates/skills/ralph-loop/steps/step-03-commit.md +47 -277
  119. package/templates/skills/ralph-loop/steps/step-04-check.md +124 -607
  120. package/templates/skills/ralph-loop/steps/step-05-report.md +68 -367
  121. package/templates/skills/refactor/SKILL.md +12 -176
  122. package/templates/skills/refactor/steps/step-01-discover.md +60 -0
  123. package/templates/skills/refactor/steps/step-02-execute.md +67 -0
  124. package/templates/skills/review-code/SKILL.md +19 -257
  125. package/templates/skills/review-code/steps/step-01-smartstack.md +96 -0
  126. package/templates/skills/review-code/steps/step-02-detailed-review.md +80 -0
  127. package/templates/skills/review-code/steps/step-03-react.md +44 -0
  128. package/templates/skills/ui-components/SKILL.md +7 -0
  129. package/templates/skills/utils/SKILL.md +6 -0
  130. package/templates/skills/validate/SKILL.md +6 -0
  131. package/templates/skills/validate-feature/SKILL.md +8 -0
  132. package/templates/skills/workflow/SKILL.md +40 -118
  133. package/templates/skills/workflow/steps/step-01-implementation.md +84 -0
@@ -6,373 +6,155 @@ next_step: steps/step-01-task.md
6
6
 
7
7
  # Step 0: Initialization
8
8
 
9
- ## MANDATORY EXECUTION RULES:
9
+ ## MANDATORY RULES:
10
10
 
11
11
  - NEVER skip MCP verification
12
- - ALWAYS parse ALL flags before any other action
13
- - ONLY check for resume if -r flag is set
14
- - YOU ARE AN INITIALIZER, not an executor
15
- - FORBIDDEN to load step-01 until init is complete
16
- - ALWAYS check prd.json version is v2
17
- - **CONTEXT BUDGET**: Keep init output COMPACT. Do NOT dump verbose MCP responses or long file listings. Every token saved here = more tokens for actual code generation in the COMPACT LOOP.
18
- - **NEVER DELEGATE**: Do NOT use the Task tool to delegate the Ralph loop to a sub-agent. The loop MUST run in the main agent context. Sub-agents lose skill context and stop prematurely.
12
+ - ALWAYS parse ALL flags before any action
13
+ - ONLY check resume if -r flag is set
14
+ - CONTEXT BUDGET: Keep output COMPACT
15
+ - **NEVER DELEGATE** the main Ralph loop to a sub-agent (single module)
16
+ - **Multi-module (2+ modules):** Use Agent Teams for parallel execution
19
17
 
20
18
  ## YOUR TASK:
21
19
 
22
- Initialize the Ralph loop by parsing flags, verifying MCP availability, setting up the execution environment, and validating integrity on resume.
20
+ Initialize the Ralph loop: parse flags, verify MCP, setup environment, detect multi-module.
23
21
 
24
22
  ---
25
23
 
26
- <defaults>
27
- ## Default Configuration
24
+ ## 1. Parse Flags
28
25
 
29
26
  ```yaml
30
- max_iterations: 50
31
- completion_promise: null
32
- verbose_mode: false
33
- resume_mode: false
34
- current_iteration: 1
35
- ```
36
- </defaults>
37
-
38
- ---
39
-
40
- ## EXECUTION SEQUENCE:
27
+ Defaults:
28
+ max_iterations: 50
29
+ completion_promise: null
30
+ verbose_mode: false
31
+ resume_mode: false
32
+ current_iteration: 1
41
33
 
42
- ### 1. Parse Flags and Input
43
-
44
- **Step 1: Load defaults from config above**
45
-
46
- ```
47
- {max_iterations} = 50
48
- {completion_promise} = null
49
- {verbose_mode} = false
50
- {resume_mode} = false
51
- {current_iteration} = 1
52
- ```
53
-
54
- **Step 2: Parse user input and override defaults:**
55
-
56
- ```
57
34
  Flags:
58
- -m N or --max-iterations N -> {max_iterations} = N
59
- -c TEXT or --completion-promise TEXT -> {completion_promise} = TEXT
60
- -v or --verbose -> {verbose_mode} = true
61
- -r or --resume -> {resume_mode} = true
62
-
63
- Remainder -> {task_description}
35
+ -m N / --max-iterations N {max_iterations} = N
36
+ -c TEXT / --completion-promise TEXT {completion_promise} = TEXT
37
+ -v / --verbose {verbose_mode} = true
38
+ -r / --resume {resume_mode} = true
39
+ Remainder → {task_description}
64
40
  ```
65
41
 
66
- ### 2. Verify MCP Servers (MANDATORY)
67
-
68
- **CRITICAL: Do NOT proceed without MCP verification!**
42
+ ## 2. Verify MCP (MANDATORY)
69
43
 
70
- **Check SmartStack MCP:**
71
44
  ```
72
- mcp__smartstack__validate_conventions:
73
- checks: ["all"]
74
- (just to verify connectivity)
45
+ mcp__smartstack__validate_conventions: checks: ["all"] → {mcp_smartstack} = true/false
46
+ mcp__context7__resolve-library-id: libraryName: "test" → {mcp_context7} = true/false
75
47
  ```
76
48
 
77
- **Check Context7 MCP:**
78
- ```
79
- mcp__context7__resolve-library-id:
80
- libraryName: "test"
81
- query: "connectivity check"
82
- (just to verify connectivity)
83
- ```
84
-
85
- **Record MCP status for metadata:**
86
- ```
87
- {mcp_smartstack} = true/false
88
- {mcp_context7} = true/false
89
- ```
90
-
91
- **If ANY MCP fails:**
92
- ```
93
- ╔══════════════════════════════════════════════════════════════════╗
94
- ║ ❌ MCP SERVER UNAVAILABLE ║
95
- ╠══════════════════════════════════════════════════════════════════╣
96
- ║ Server: {failed_server} ║
97
- ║ Status: Connection failed ║
98
- ╠══════════════════════════════════════════════════════════════════╣
99
- ║ RALPH CANNOT PROCEED WITHOUT MCP ║
100
- ║ ║
101
- ║ Troubleshooting: ║
102
- ║ 1. Run: smartstack check-mcp ║
103
- ║ 2. Restart Claude Code ║
104
- ║ 3. Check MCP server configuration ║
105
- ╚══════════════════════════════════════════════════════════════════╝
106
-
107
- STOP - Do not proceed.
108
- ```
109
-
110
- ### 3. Check Resume Mode
49
+ If ANY fails: show error, suggest `smartstack check-mcp`, STOP.
111
50
 
112
- **If {resume_mode} = true:**
51
+ ## 3. Resume Mode
113
52
 
114
- 1. Check for existing `.ralph/prd.json`
115
- 2. If not found:
116
- - Error: "No active Ralph loop to resume"
117
- - Ask user to start new loop
118
- - STOP
53
+ If `{resume_mode} = true`:
119
54
 
120
- 3. If found, **validate schema version:**
55
+ 1. Check `.ralph/prd.json` exists error if not
56
+ 2. Detect format:
57
+ - `$version === "3.0.0"` → **v3 unified** (native, preferred)
58
+ - `$version === "2.0.0"` → **v2 legacy** (OK, continue)
59
+ - `.project && .requirements && !.$version` → **FORMAT A (DEPRECATED)** — warn and transform via step-01
60
+ - Other → error
61
+ 3. Check branch consistency: current branch vs `prd.metadata.branch`
62
+ 4. Restore state: `current_iteration`, `completion_promise`, `max_iterations`
63
+ 5. If `modules-queue.json` exists: restore multi-module state
64
+ 6. Continue to step-01
121
65
 
122
- ```javascript
123
- const prd = readJSON('.ralph/prd.json');
124
-
125
- if (prd.$version !== "2.0.0") {
126
- echo "❌ prd.json schema version unsupported: ${prd.$version || 'missing'}";
127
- echo " Expected: 2.0.0";
128
- echo " Re-run /business-analyse to generate a fresh prd.json";
129
- STOP;
130
- }
131
- ```
132
-
133
- 4. **Validate integrity (v2 resume):**
134
-
135
- ```bash
136
- # Check branch consistency
137
- CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
138
- PRD_BRANCH={prd.metadata.branch}
139
-
140
- if [ "$CURRENT_BRANCH" != "$PRD_BRANCH" ]; then
141
- echo "⚠️ Branch mismatch: prd.json was created on '$PRD_BRANCH', now on '$CURRENT_BRANCH'"
142
- # Ask user: continue on current branch or switch
143
- AskUserQuestion:
144
- header: "Branch"
145
- question: "prd.json was created on '$PRD_BRANCH' but you're on '$CURRENT_BRANCH'. Continue?"
146
- options:
147
- - label: "Continue on $CURRENT_BRANCH"
148
- description: "Update metadata and continue"
149
- - label: "Cancel"
150
- description: "Switch branch manually first"
151
- fi
152
-
153
- # Check for external commits since last update
154
- LAST_UPDATED={prd.updated_at}
155
- EXTERNAL_COMMITS=$(git log --since="$LAST_UPDATED" --oneline --not --author="Co-Authored-By: Claude" | wc -l)
156
-
157
- if [ "$EXTERNAL_COMMITS" -gt 0 ]; then
158
- echo "⚠️ $EXTERNAL_COMMITS external commits detected since last Ralph iteration"
159
- echo " prd.json state may not reflect current code state"
160
- fi
161
- ```
162
-
163
- 5. **Restore state from prd.json:**
164
- - Read `prd.config.current_iteration` → `{current_iteration}`
165
- - Read `prd.config.completion_promise` → `{completion_promise}`
166
- - Read `prd.config.max_iterations` → `{max_iterations}`
167
- - Read progress.txt for context
168
-
169
- 6. **Restore multi-module state (if applicable):**
170
- ```javascript
171
- if (fileExists('.ralph/modules-queue.json')) {
172
- const queue = readJSON('.ralph/modules-queue.json');
173
- const currentModule = queue.modules[queue.currentIndex];
174
-
175
- // Restore module state
176
- {modules_queue} = queue;
177
- {current_module} = currentModule.code;
178
-
179
- console.log(`Resuming multi-module: ${currentModule.code} (${queue.currentIndex + 1}/${queue.totalModules})`);
180
- console.log(`Modules completed: ${queue.completedModules}/${queue.totalModules}`);
181
- }
182
- ```
183
-
184
- - Continue to step-01
185
-
186
- ### 4. Initialize .ralph/ Structure (new loop)
187
-
188
- **Create directory structure:**
189
-
190
- ```
191
- .ralph/
192
- ├── prd.json # Will be created in step-01
193
- ├── progress.txt # Will be created in step-01
194
- ├── logs/
195
- └── reports/
196
- ```
197
-
198
- **Commands:**
199
- ```bash
200
- mkdir -p .ralph/logs
201
- mkdir -p .ralph/reports
202
- ```
203
-
204
- ### 4a. Auto-Recovery: Detect BA Artifacts Without PRD (NEW)
205
-
206
- > **Scenario:** Business-analyse completed (feature.json with status="handed-off") but step-05b
207
- > didn't generate PRD files (context exhaustion). Ralph-loop auto-recovers by running `ss derive-prd`.
208
-
209
- **Check for BA artifacts when no PRD files exist:**
66
+ ## 4. Initialize .ralph/ (new loop)
210
67
 
211
68
  ```bash
212
- PRD_EXISTS=$(ls .ralph/prd-*.json 2>/dev/null | head -1)
213
- SINGLE_PRD_EXISTS=$(test -f .ralph/prd.json && echo "yes" || echo "no")
69
+ mkdir -p .ralph/logs .ralph/reports
214
70
  ```
215
71
 
216
- **IF no PRD files found (neither prd-*.json nor prd.json):**
217
-
218
- ```bash
219
- # Search for handed-off master feature.json
220
- MASTER_FEATURE=$(find docs/business -maxdepth 4 -name "feature.json" -path "*/business-analyse/*" 2>/dev/null | head -1)
221
- ```
72
+ ### 4a. Auto-Recovery: BA Artifacts Without PRD
222
73
 
223
- **IF master feature.json found:**
74
+ If no PRD files exist (neither `prd-*.json` nor `prd.json`):
224
75
 
225
76
  ```javascript
226
- const master = readJSON(MASTER_FEATURE);
227
-
228
- if (master.status === "handed-off" || master.handoff?.status === "handed-off") {
229
- // BA completed but PRD files are missing — auto-recover
230
- console.log("BA artifacts detected without PRD files — auto-recovering...");
231
-
232
- // Display validation table
233
- console.log(`
234
- ╔══════════════════════════════════════════════════════════════════╗
235
- ║ BA ARTIFACT VALIDATION ║
236
- ╠══════════════════════════════════════════════════════════════════╣
237
- ║ Master feature.json: ✅ Found (status: ${master.status}) ║
238
- ║ Application: ${master.metadata?.application || 'unknown'} ║
239
- ║ Modules: ${master.modules?.length || 0} ║
240
- ║ PRD files: ❌ Missing — will auto-generate ║
241
- ╠══════════════════════════════════════════════════════════════════╣
242
- ║ Running: ss derive-prd --application ${MASTER_FEATURE} ║
243
- ╚══════════════════════════════════════════════════════════════════╝
244
- `);
245
-
246
- // Execute ss derive-prd to generate missing PRD files
247
- // This is a deterministic CLI command (no LLM), safe to auto-run
248
- exec(`ss derive-prd --application ${MASTER_FEATURE}`);
249
-
250
- // Verify PRD files were generated
251
- const newPrdFiles = glob('.ralph/prd-*.json');
252
- if (newPrdFiles.length === 0) {
253
- console.log("❌ ss derive-prd failed to generate PRD files");
254
- console.log(" Verify: ss derive-prd is installed (npm list -g @atlashub/smartstack-cli)");
255
- console.log(" Manual: ss derive-prd --application " + MASTER_FEATURE);
256
- STOP;
77
+ const masterFeature = findFile('docs/business/**/business-analyse/**/feature.json');
78
+ if (masterFeature) {
79
+ const master = readJSON(masterFeature);
80
+ if (master.status === 'handed-off' || master.handoff?.status === 'handed-off') {
81
+ console.log('BA artifacts detected without PRD — auto-recovering...');
82
+ exec(`ss derive-prd --application ${masterFeature}`);
83
+ const newPrds = glob('.ralph/prd-*.json');
84
+ if (newPrds.length === 0) { console.log('ss derive-prd failed'); STOP; }
85
+ console.log(`Auto-recovered ${newPrds.length} PRD files`);
257
86
  }
258
-
259
- console.log(`✅ Auto-recovered ${newPrdFiles.length} PRD files`);
260
- // Continue to section 4b which will detect and queue them
261
87
  }
262
88
  ```
263
89
 
264
- **IF master feature.json NOT found OR status ≠ "handed-off":**
265
- - No BA artifacts → proceed normally (step-01 will create prd.json from task description)
266
-
267
- **IF PRD files already exist:**
268
- - Skip auto-recovery entirely → proceed to section 4b
269
-
270
- ### 4b. Detect Multi-Module PRDs (from BA Handoff or Auto-Recovery)
90
+ ### 4b. Detect Multi-Module PRDs
271
91
 
272
- **After creating `.ralph/` directory, check for per-module PRD files:**
273
-
274
- ```bash
275
- # Count prd-*.json files (generated by BA handoff via ss derive-prd)
276
- PRD_FILES=$(ls .ralph/prd-*.json 2>/dev/null)
277
- PRD_COUNT=$(echo "$PRD_FILES" | grep -c "prd-" 2>/dev/null || echo "0")
278
- ```
279
-
280
- **If multiple prd-*.json files found (PRD_COUNT > 0):**
281
-
282
- 1. **Read module order from master feature.json (if available):**
283
- ```bash
284
- # Look for master feature.json that references modules
285
- MASTER_FEATURE=$(find docs/business -maxdepth 4 -name "feature.json" -path "*/business-analyse/*" | head -1)
286
- ```
287
-
288
- 2. **Build module queue:**
289
92
  ```javascript
290
- const modules = [];
291
-
292
- if (MASTER_FEATURE && masterJson.metadata?.workflow?.moduleOrder) {
293
- // Use order from BA master feature.json
294
- for (const mod of masterJson.metadata.workflow.moduleOrder) {
295
- const prdFile = `.ralph/prd-${mod.code}.json`;
296
- if (fileExists(prdFile)) {
297
- modules.push({ code: mod.code, prdFile, status: "pending" });
93
+ const prdFiles = glob('.ralph/prd-*.json');
94
+ const PRD_COUNT = prdFiles.length;
95
+
96
+ if (PRD_COUNT > 0) {
97
+ // Build module queue (from master feature.json order or alphabetical)
98
+ const modules = [];
99
+ const masterFeature = findFile('docs/business/**/business-analyse/**/feature.json');
100
+ if (masterFeature) {
101
+ const master = readJSON(masterFeature);
102
+ const moduleOrder = master.metadata?.workflow?.moduleOrder || [];
103
+ for (const mod of moduleOrder) {
104
+ if (fileExists(`.ralph/prd-${mod.code}.json`)) {
105
+ modules.push({ code: mod.code, prdFile: `.ralph/prd-${mod.code}.json`, status: 'pending' });
106
+ }
298
107
  }
299
108
  }
300
- } else {
301
- // Fallback: alphabetical order from prd-*.json filenames
302
- for (const file of prdFiles) {
303
- const code = file.match(/prd-(.+)\.json$/)[1];
304
- modules.push({ code, prdFile: `.ralph/${file}`, status: "pending" });
109
+ // Fallback: alphabetical
110
+ if (modules.length === 0) {
111
+ for (const file of prdFiles) {
112
+ const code = file.match(/prd-(.+)\.json$/)[1];
113
+ modules.push({ code, prdFile: `.ralph/${file}`, status: 'pending' });
114
+ }
305
115
  }
306
- }
307
- ```
308
-
309
- 3. **Create modules-queue.json:**
310
- ```json
311
- {
312
- "modules": [
313
- { "code": "mod1", "prdFile": ".ralph/prd-mod1.json", "status": "pending" },
314
- { "code": "mod2", "prdFile": ".ralph/prd-mod2.json", "status": "pending" }
315
- ],
316
- "currentIndex": 0,
317
- "totalModules": 2,
318
- "completedModules": 0
319
- }
320
- ```
321
-
322
- 4. **Set first module as active:**
323
- ```javascript
324
- modules[0].status = "in-progress";
325
- ```
326
116
 
327
- 5. **Log detection:**
328
- ```
329
- Multi-module detected: {PRD_COUNT} modules
330
- Queue: {module codes joined by " → "}
331
- Starting with: {modules[0].code}
332
- ```
117
+ // Create modules-queue.json
118
+ modules[0].status = 'in-progress';
119
+ const queue = { modules, currentIndex: 0, totalModules: modules.length, completedModules: 0 };
120
+ writeJSON('.ralph/modules-queue.json', queue);
121
+ console.log(`Multi-module: ${modules.length} modules → ${modules.map(m => m.code).join(' → ')}`);
333
122
 
334
- 6. **Display BA artifact validation (if from BA handoff):**
335
- ```
336
- [CHECK] BA Artifact Validation:
337
- ✓ Master feature.json: {MASTER_FEATURE} (status: handed-off)
338
- ✓ Module feature.json: {module_count} modules (all handed-off)
339
- ✓ PRD files: {PRD_COUNT} modules (.ralph/prd-*.json)
340
- ✓ progress.txt: {exists ? "present" : "will be created"}
341
- [PASS] All BA artifacts valid. Multi-module development ready.
123
+ {modules_queue} = queue;
124
+ {current_module} = modules[0].code;
125
+ }
342
126
  ```
343
127
 
344
- **If only `.ralph/prd.json` exists (single module):**
345
- - Skip queue creation (backward compatible)
346
- - Proceed normally
128
+ ### 4c. Team Orchestration (multi-module, 2+ modules)
347
129
 
348
- **Store:**
349
- ```
350
- {modules_queue} = queue object or null
351
- {current_module} = first module code or null
130
+ ```javascript
131
+ if (PRD_COUNT > 1) {
132
+ // Read references/team-orchestration.md for full protocol
133
+ // Detect dependency layers from master feature.json
134
+ const layers = master.metadata?.workflow?.dependencyGraph?.layers;
135
+
136
+ if (layers) {
137
+ // PARALLEL MODE: Use Agent Teams
138
+ TeamCreate({ team_name: `ralph-${appName}` });
139
+
140
+ // For each layer, spawn teammates in parallel
141
+ // Layer 0: foundation modules (spawn, wait for LAYER_READY)
142
+ // Layer 1+: dependent modules (spawn after previous layer completes)
143
+ // See references/team-orchestration.md for teammate prompt template
144
+
145
+ // After all layers: cross-module verify → step-05 → TeamDelete
146
+ // STOP here — team orchestration takes over
147
+ return;
148
+ }
149
+ // If no layers: fall through to sequential mode (classic compact loop)
150
+ }
352
151
  ```
353
152
 
354
- ### 5. Validate Completion Promise
355
-
356
- **If {completion_promise} is null:**
357
-
358
- ```yaml
359
- AskUserQuestion:
360
- header: "Promise"
361
- question: "What text should signal completion?"
362
- options:
363
- - label: "COMPLETE"
364
- description: "Standard completion signal"
365
- - label: "ALL TESTS PASS"
366
- description: "For test-focused tasks"
367
- - label: "DONE"
368
- description: "Simple completion"
369
- - label: "Custom..."
370
- description: "Specify custom text"
371
- ```
153
+ ## 5. Completion Promise
372
154
 
373
- ### 6. Collect Metadata
155
+ If `{completion_promise}` is null: ask user to choose (COMPLETE, ALL TESTS PASS, DONE, or custom).
374
156
 
375
- **Gather execution context:**
157
+ ## 6. Collect Metadata
376
158
 
377
159
  ```bash
378
160
  CLI_VERSION=$(node -e "console.log(require('package.json').version)" 2>/dev/null || echo "unknown")
@@ -380,73 +162,19 @@ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
380
162
  PROJECT_PATH=$(pwd)
381
163
  ```
382
164
 
383
- **Store metadata for prd.json creation (step-01):**
384
- ```
385
- {metadata} = {
386
- cli_version: CLI_VERSION,
387
- branch: CURRENT_BRANCH,
388
- project_path: PROJECT_PATH,
389
- mcp_servers: { smartstack: {mcp_smartstack}, context7: {mcp_context7} }
390
- }
391
- ```
392
-
393
- ### 7. Log Initialization
394
-
395
- **If {verbose_mode} = true:**
396
-
397
- Write to `.ralph/logs/{timestamp}.log`:
398
- ```
399
- [{timestamp}] RALPH LOOP INITIALIZED
400
- Task: {task_description}
401
- Max iterations: {max_iterations}
402
- Completion promise: {completion_promise}
403
- MCP Status: SmartStack {mcp_smartstack ? "✅" : "❌"}, Context7 {mcp_context7 ? "✅" : "❌"}
404
- Schema: v2.0.0
405
- Branch: {CURRENT_BRANCH}
165
+ ```javascript
166
+ {metadata} = { cli_version: CLI_VERSION, branch: CURRENT_BRANCH, project_path: PROJECT_PATH,
167
+ mcp_servers: { smartstack: {mcp_smartstack}, context7: {mcp_context7} } }
406
168
  ```
407
169
 
408
- ### 8. Show Summary and Proceed
409
-
410
- **Always show COMPACT summary:**
170
+ ## 7. Show Summary
411
171
 
412
172
  ```
413
- ╔══════════════════════════════════════════════════════════════════╗
414
- ║ RALPH LOOP INITIALIZED ║
415
- ╠══════════════════════════════════════════════════════════════════╣
416
- ║ Task: {task_description}
417
- ║ Max iterations: {max_iterations} ║
418
- ║ Completion: <promise>{completion_promise}</promise> ║
419
- ║ MCP: ✅ Ready ║
420
- ║ Schema: v2.0.0 ║
421
- ║ Branch: {CURRENT_BRANCH} ║
422
- ║ {modules_queue ? "Modules: " + totalModules + " (" + module_codes.join(" → ") + ")" : "Mode: single module"} ║
423
- ╠══════════════════════════════════════════════════════════════════╣
424
- ║ Files: ║
425
- ║ - .ralph/prd.json (tasks) ║
426
- ║ - .ralph/progress.txt (memory) ║
427
- ║ {modules_queue ? "- .ralph/modules-queue.json (module tracking)" : ""} ║
428
- ╚══════════════════════════════════════════════════════════════════╝
429
-
173
+ RALPH LOOP INITIALIZED
174
+ Task: {task_description} | Max: {max_iterations} | Promise: {completion_promise}
175
+ MCP: Ready | Branch: {branch} | Schema: v3.0.0
176
+ {modules_queue ? `Modules: ${totalModules} (${module_codes.join(' → ')})` : 'Mode: single module'}
430
177
  -> Loading tasks...
431
178
  ```
432
179
 
433
- **Then proceed directly to step-01-task.md**
434
-
435
- ---
436
-
437
- ## SUCCESS METRICS:
438
-
439
- - All flags correctly parsed
440
- - MCP servers verified and available
441
- - .ralph/ directory structure created
442
- - Completion promise defined
443
- - Metadata collected (branch, version, MCP status)
444
- - prd.json v2 schema validated (if resume)
445
- - Branch integrity validated (if resume)
446
- - Multi-module prd files detected and modules-queue.json created (if applicable)
447
- - Output is COMPACT
448
- - Proceeded to step-01 immediately after summary
449
-
450
- ## NEXT STEP:
451
-
452
- After showing initialization summary, always proceed directly to `./step-01-task.md`
180
+ **Proceed directly to step-01-task.md**