@atlashub/smartstack-cli 3.6.0 → 3.8.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 (40) hide show
  1. package/package.json +3 -2
  2. package/templates/skills/business-analyse/SKILL.md +6 -12
  3. package/templates/skills/business-analyse/_architecture.md +1 -1
  4. package/templates/skills/business-analyse/html/ba-interactive.html +3058 -2252
  5. package/templates/skills/business-analyse/html/build-html.js +77 -0
  6. package/templates/skills/business-analyse/html/src/scripts/01-data-init.js +129 -0
  7. package/templates/skills/business-analyse/html/src/scripts/02-navigation.js +22 -0
  8. package/templates/skills/business-analyse/html/src/scripts/03-render-cadrage.js +208 -0
  9. package/templates/skills/business-analyse/html/src/scripts/04-render-modules.js +211 -0
  10. package/templates/skills/business-analyse/html/src/scripts/05-render-specs.js +542 -0
  11. package/templates/skills/business-analyse/html/src/scripts/06-render-consolidation.js +105 -0
  12. package/templates/skills/business-analyse/html/src/scripts/07-render-handoff.js +90 -0
  13. package/templates/skills/business-analyse/html/src/scripts/08-editing.js +45 -0
  14. package/templates/skills/business-analyse/html/src/scripts/09-export.js +65 -0
  15. package/templates/skills/business-analyse/html/src/scripts/10-comments.js +165 -0
  16. package/templates/skills/business-analyse/html/src/scripts/11-review-panel.js +139 -0
  17. package/templates/skills/business-analyse/html/src/styles/01-variables.css +38 -0
  18. package/templates/skills/business-analyse/html/src/styles/02-layout.css +101 -0
  19. package/templates/skills/business-analyse/html/src/styles/03-navigation.css +62 -0
  20. package/templates/skills/business-analyse/html/src/styles/04-cards.css +196 -0
  21. package/templates/skills/business-analyse/html/src/styles/05-modules.css +325 -0
  22. package/templates/skills/business-analyse/html/src/styles/06-wireframes.css +230 -0
  23. package/templates/skills/business-analyse/html/src/styles/07-comments.css +184 -0
  24. package/templates/skills/business-analyse/html/src/styles/08-review-panel.css +229 -0
  25. package/templates/skills/business-analyse/html/src/template.html +622 -0
  26. package/templates/skills/business-analyse/react/components.md +1 -1
  27. package/templates/skills/business-analyse/react/schema.md +1 -1
  28. package/templates/skills/business-analyse/references/html-data-mapping.md +2 -2
  29. package/templates/skills/business-analyse/schemas/feature-schema.json +1 -1
  30. package/templates/skills/business-analyse/steps/step-00-init.md +8 -1
  31. package/templates/skills/business-analyse/steps/step-03d-validate.md +1 -1
  32. package/templates/skills/business-analyse/steps/step-04-consolidation.md +21 -0
  33. package/templates/skills/business-analyse/steps/step-05a-handoff.md +273 -10
  34. package/templates/skills/business-analyse/steps/{step-05d-html.md → step-05b-deploy.md} +262 -63
  35. package/templates/skills/business-analyse/templates/tpl-launch-displays.md +1 -1
  36. package/templates/skills/business-analyse/templates/tpl-progress.md +1 -1
  37. package/templates/skills/ralph-loop/SKILL.md +3 -3
  38. package/templates/skills/ralph-loop/steps/step-00-init.md +77 -1
  39. package/templates/skills/business-analyse/steps/step-05b-mapping.md +0 -302
  40. package/templates/skills/business-analyse/steps/step-05c-deploy.md +0 -296
@@ -1,16 +1,20 @@
1
1
  ---
2
- name: step-05d-html
3
- description: Deploy ba-interactive.html pre-populated with all analysis data
2
+ name: step-05b-deploy
3
+ description: Generate prd.json, deploy artifacts, interactive HTML
4
4
  model: sonnet
5
5
  next_step: null
6
6
  ---
7
7
 
8
- > **Context files:** `_shared.md`
8
+ > **Context files:** _shared.md
9
9
 
10
- # Step 5d: Deploy Interactive HTML
10
+ # Step 5b: Deploy Artifacts & Interactive HTML
11
11
 
12
12
  ## MANDATORY EXECUTION RULES
13
13
 
14
+ - **ALWAYS** verify all module handoffs are complete before generating artifacts
15
+ - **ALWAYS** derive prd.json from feature.json (NEVER independently)
16
+ - **NEVER** invent entities/FRs/BRs not in feature.json
17
+ - **ALWAYS** update BA manifest at docs/business/index.json
14
18
  - **ALWAYS** deploy ba-interactive.html PRE-POPULATED with all data
15
19
  - **ALWAYS** follow references/html-data-mapping.md EXACTLY for FEATURE_DATA and EMBEDDED_ARTIFACTS mapping
16
20
  - **FEATURE_DATA.moduleSpecs MUST be populated for EACH module** — empty moduleSpecs = BROKEN specification tabs
@@ -20,13 +24,185 @@ next_step: null
20
24
 
21
25
  ## YOUR TASK
22
26
 
23
- Deploy the interactive HTML document pre-populated with ALL analysis data. This is the final step of the business analysis workflow. The HTML is the client-facing deliverable for review and can be edited, enriched, and re-imported.
27
+ Generate deployment artifacts (prd.json, progress.txt, BA manifest) and deploy the interactive HTML document pre-populated with all analysis data.
24
28
 
25
29
  ---
26
30
 
27
31
  ## EXECUTION SEQUENCE
28
32
 
29
- ### 1. Read Source Data
33
+ ### 0. Pre-flight Verification
34
+
35
+ Before generating ANY artifact, verify step-05a completed successfully:
36
+
37
+ ```
38
+ FOR each module in modules[]:
39
+ Read module feature.json
40
+ IF module.handoff === {} OR module.status !== "handed-off":
41
+ → BLOCKING ERROR: Module {module.code} has no handoff data
42
+ → Return to step-05a-handoff.md
43
+ ```
44
+
45
+ IF all modules have valid handoff → proceed.
46
+
47
+ ---
48
+
49
+ ### 1. Generate prd.json (PROGRAMMATIC)
50
+
51
+ > **RULE:** prd.json is extracted by CLI code, **NEVER** generated by LLM.
52
+ > The `ss derive-prd` command performs a deterministic data transformation from feature.json.
53
+
54
+ **For each module:**
55
+
56
+ ```
57
+ Execute: ss derive-prd --feature {moduleFeaturePath} --output .ralph/prd-{moduleCode}.json
58
+ ```
59
+
60
+ **For consolidated view (multi-module, optional):**
61
+
62
+ ```
63
+ Execute: ss derive-prd --application {masterFeaturePath}
64
+ → Generates .ralph/prd-{moduleCode}.json for each module
65
+ ```
66
+
67
+ **Verification:** After execution, read the generated prd.json and display summary:
68
+
69
+ ```
70
+ prd.json generated for module {moduleCode}:
71
+ - Use cases: {count}
72
+ - Functional requirements: {count}
73
+ - Business rules: {count}
74
+ - API endpoints: {count}
75
+ - Sections: {count}
76
+ - Files to create: {count}
77
+ - BR-to-code mappings: {count}
78
+ ```
79
+
80
+ **Key guarantees:**
81
+ - Source MUST reference feature.json path (traceability)
82
+ - All data is EXACT COPY from feature.json (no transformation, no invention)
83
+ - prd.json version: "2.0.0"
84
+ - source.type: "ba-handoff-programmatic"
85
+
86
+ **POST-CHECK (BLOCKING — DO NOT SKIP):**
87
+
88
+ After `ss derive-prd` execution, read the generated prd-{moduleCode}.json and verify structural integrity:
89
+
90
+ ```javascript
91
+ const prd = readJSON(`.ralph/prd-${moduleCode}.json`);
92
+ const featureHandoff = moduleFeature.handoff.filesToCreate;
93
+
94
+ // 1. Verify structure: filesToCreate MUST be under implementation (NOT root level)
95
+ if (prd.filesToCreate && !prd.implementation?.filesToCreate) {
96
+ BLOCKING_ERROR("prd.json has filesToCreate at ROOT level — this is NOT from ss derive-prd");
97
+ BLOCKING_ERROR("Re-run: ss derive-prd --feature {path} --output .ralph/prd-{moduleCode}.json");
98
+ STOP;
99
+ }
100
+
101
+ // 2. Verify ALL 7 categories present and match feature.json
102
+ const categories = ['domain', 'application', 'infrastructure', 'api', 'frontend', 'seedData', 'tests'];
103
+ for (const cat of categories) {
104
+ const prdCount = prd.implementation.filesToCreate[cat]?.length ?? 0;
105
+ const featureCount = featureHandoff[cat]?.length ?? 0;
106
+ if (prdCount !== featureCount) {
107
+ BLOCKING_ERROR(`${cat}: prd has ${prdCount} files but feature.json has ${featureCount}`);
108
+ }
109
+ }
110
+ ```
111
+
112
+ Display verification table:
113
+
114
+ ```
115
+ POST-CHECK: prd-{moduleCode}.json integrity
116
+ | Category | feature.json | prd.json | Match |
117
+ |----------------|-------------|----------|-------|
118
+ | domain | {n} | {n} | OK/FAIL |
119
+ | application | {n} | {n} | OK/FAIL |
120
+ | infrastructure | {n} | {n} | OK/FAIL |
121
+ | api | {n} | {n} | OK/FAIL |
122
+ | frontend | {n} | {n} | OK/FAIL |
123
+ | seedData | {n} | {n} | OK/FAIL |
124
+ | tests | {n} | {n} | OK/FAIL |
125
+ ```
126
+
127
+ IF ANY category shows FAIL → **STOP AND RE-RUN `ss derive-prd`**. DO NOT proceed with incomplete PRD.
128
+
129
+ ---
130
+
131
+ ### 2. Initialize Progress Tracker
132
+
133
+ > **Template:** Read `templates/tpl-progress.md` for the complete progress tracker template structure.
134
+ > Populate the template with module-specific data from feature.json handoff sections.
135
+
136
+ **Progress Tracker Rules:**
137
+ - One section per module, in topological order (dependencies first)
138
+ - CORE SeedData ALWAYS 5 entries (mandatory)
139
+ - Business SeedData varies by module
140
+ - Hierarchical task structure (module -> layer -> tasks)
141
+ - Each task is independent, assignable checkbox
142
+ - Effort estimate per module (simple/medium/complex)
143
+ - Summary with totals across all modules
144
+ - Cross-module tasks only if multi-module
145
+
146
+ ---
147
+
148
+ ### 3. Update BA Manifest (MANDATORY)
149
+
150
+ > **The BA manifest enables the SmartStack web app to discover and display all available business analyses.**
151
+ > It is a JSON index file at `docs/business/index.json` that lists all feature.json files.
152
+
153
+ **Path:** `docs/business/index.json` (project root relative)
154
+
155
+ **Schema:**
156
+ ```json
157
+ {
158
+ "version": "1.0",
159
+ "updatedAt": "{ISO timestamp}",
160
+ "analyses": [
161
+ {
162
+ "appCode": "{app_code}",
163
+ "appName": "{application_name}",
164
+ "moduleCode": null | "{module_code}",
165
+ "moduleName": "{module_name}",
166
+ "version": "{version}",
167
+ "status": "handed-off",
168
+ "featureDescription": "{feature_description}",
169
+ "path": "{app_code}/business-analyse/v{version}/feature.json",
170
+ "updatedAt": "{ISO timestamp}"
171
+ }
172
+ ]
173
+ }
174
+ ```
175
+
176
+ **Update logic:**
177
+
178
+ 1. Read existing manifest at `docs/business/index.json` (or create empty `{ "version": "1.0", "updatedAt": "", "analyses": [] }`)
179
+ 2. For the APPLICATION-level feature.json:
180
+ - Find existing entry where `appCode == {app_code}` AND `moduleCode == null` AND `version == {version}`
181
+ - If found: update `status`, `updatedAt`, `featureDescription`
182
+ - If not found: append new entry with `moduleCode: null` and `path: "{app_code}/business-analyse/v{version}/feature.json"`
183
+ 3. For EACH MODULE-level feature.json:
184
+ - Find existing entry where `appCode == {app_code}` AND `moduleCode == {module_code}` AND `version == {version}`
185
+ - If found: update `status`, `updatedAt`, `featureDescription`
186
+ - If not found: append new entry with `moduleCode: "{module_code}"` and `path: "{app_code}/{module_code}/business-analyse/v{version}/feature.json"`
187
+ 4. Update root `updatedAt` to current timestamp
188
+ 5. Write manifest back to `docs/business/index.json`
189
+
190
+ **Display confirmation:**
191
+ ```
192
+ ✓ BA manifest updated: docs/business/index.json
193
+ Entries: {total_count} ({app_count} applications, {module_count} modules)
194
+ Web viewer: /system/docs/ba
195
+ ```
196
+
197
+ **Why a manifest?**
198
+ - The web app needs to discover available BAs without scanning the filesystem
199
+ - Static file serving (no backend API needed)
200
+ - Incremental updates: each handoff adds/updates only its entries
201
+ - Consumed by the SmartStack web app BA viewer at `/system/docs/ba`
202
+
203
+ ---
204
+
205
+ ### 4. Read Source Data for HTML
30
206
 
31
207
  1. Read the HTML template from skill directory: `html/ba-interactive.html` (relative to `~/.claude/skills/business-analyse/`)
32
208
  2. Read the master feature.json (application level)
@@ -45,7 +221,7 @@ Deploy the interactive HTML document pre-populated with ALL analysis data. This
45
221
 
46
222
  ---
47
223
 
48
- ### 2. Build FEATURE_DATA Object
224
+ ### 5. Build FEATURE_DATA Object
49
225
 
50
226
  Reference `references/html-data-mapping.md` EXACTLY. The FEATURE_DATA object must contain:
51
227
 
@@ -131,7 +307,7 @@ const FEATURE_DATA = {
131
307
 
132
308
  ---
133
309
 
134
- ### 3. Build EMBEDDED_ARTIFACTS Object
310
+ ### 6. Build EMBEDDED_ARTIFACTS Object
135
311
 
136
312
  Extract visual artifacts and diagrams from the analysis:
137
313
 
@@ -172,7 +348,7 @@ const EMBEDDED_ARTIFACTS = {
172
348
 
173
349
  ---
174
350
 
175
- ### 4. Replace Placeholders in Template
351
+ ### 7. Replace Placeholders in Template
176
352
 
177
353
  1. Serialize the FEATURE_DATA object as JSON (with 2-space indentation)
178
354
  2. Serialize the EMBEDDED_ARTIFACTS object as JSON (with 2-space indentation)
@@ -190,7 +366,7 @@ const EMBEDDED_ARTIFACTS = {
190
366
 
191
367
  ---
192
368
 
193
- ### 5. Write and Verify
369
+ ### 8. Write and Verify
194
370
 
195
371
  1. Write the populated HTML to the output directory: `docs/business/{app}/business-analyse/v{version}/ba-interactive.html`
196
372
  2. Display deployment confirmation:
@@ -207,6 +383,21 @@ const EMBEDDED_ARTIFACTS = {
207
383
 
208
384
  ---
209
385
 
386
+ ## SELF-VERIFICATION (BEFORE COMPLETION)
387
+
388
+ Before displaying completion, VERIFY:
389
+
390
+ 1. **`.ralph/prd-{module}.json`** exists for ALL modules (file size > 100 bytes each)
391
+ 2. **`.ralph/progress.txt`** exists (file size > 500 bytes)
392
+ 3. **`docs/business/index.json`** exists with correct entry count
393
+ 4. **ba-interactive.html** exists and file size > 100KB
394
+ 5. **FEATURE_DATA contains moduleSpecs** with entries for ALL modules
395
+ 6. **cadrage.scope uses HTML keys** (vital/important/optional/excluded)
396
+
397
+ **IF any check fails → GENERATE the missing artifact before proceeding to completion.**
398
+
399
+ ---
400
+
210
401
  ## POST-CHECK (BLOCKING)
211
402
 
212
403
  After writing the HTML file, verify:
@@ -246,43 +437,73 @@ After writing the HTML file, verify:
246
437
 
247
438
  ---
248
439
 
249
- ## SELF-VERIFICATION (FINAL)
440
+ ## COMPLETION
250
441
 
251
- Before completion, verify:
442
+ > **IMPORTANT:** La BA ne lance JAMAIS /ralph-loop automatiquement.
443
+ > Il peut y avoir une phase de revue/modification de la documentation entre les deux étapes.
444
+ > L'utilisateur lance `/ralph-loop` manuellement quand il est prêt.
252
445
 
253
- 1. **ba-interactive.html exists** at `docs/business/{app}/business-analyse/v{version}/` and file size > 100KB
254
- 2. **FEATURE_DATA contains moduleSpecs** with entries for ALL modules (grep for `"moduleSpecs"` — if absent, the specification tabs will be broken)
255
- 3. **cadrage.scope uses HTML keys** (vital/important/optional/excluded) — NOT feature.json keys
256
- 4. **EMBEDDED_ARTIFACTS contains wireframes** for all modules with screen names and descriptions
257
- 5. **All 5 metadata fields populated:** applicationName, applicationId, version, createdAt, vibeCoding
446
+ Display completion using the template from `templates/tpl-launch-displays.md`:
258
447
 
259
- **IF any check fails → REGENERATE the HTML immediately.**
448
+ ```
449
+ ═══════════════════════════════════════════════════════════════
450
+ [OK] BUSINESS ANALYSE TERMINEE - {application_name}
451
+ ═══════════════════════════════════════════════════════════════
260
452
 
261
- ---
453
+ Modules: {count} ({names})
454
+ Strategy: {strategy}
455
+ Files: {total files across all modules}
456
+ Tasks: {total tasks} ({core_count} CORE + {biz_count} business + {dev_count} development)
457
+ Complexity: {complexity}
458
+ Effort: {total_days} days ({total_hours} hours)
262
459
 
263
- ## WHY A FINAL HTML DEPLOYMENT AT HANDOFF?
460
+ [DIR] Artefacts générés:
461
+ ✓ feature.json (master + per-module) - spécification complète
462
+ ✓ .ralph/prd-{module}.json - task breakdown per module
463
+ ✓ .ralph/progress.txt - tracker de progression
464
+ ✓ ba-interactive.html - document de revue interactif
264
465
 
265
- - Step 03 already deploys the HTML incrementally after each module (partial data)
266
- - This final deployment adds the COMPLETE data: all modules + consolidation + handoff info
267
- - The client sees the FULL analysis pre-populated — including cross-module interactions and E2E flows
268
- - The client can review, edit, and enrich directly in the browser
269
- - Any client modifications can be re-imported via `-x` extraction mode
270
- - The HTML is standalone (no server required) with localStorage persistence
271
- - On first open: pre-populated data displays. After client edits: localStorage overrides
272
- - **NOTE:** This overwrites the incremental HTML from step-03 with the complete version
466
+ [TARGET] Prochaines étapes:
467
+ 1. Ouvrir ba-interactive.html dans le navigateur
468
+ 2. Partager avec les stakeholders pour validation
469
+ 3. Si retours --> relancer /business-analyse pour une nouvelle itération
470
+ 4. Une fois validé, lancer le développement:
471
+
472
+ /ralph-loop -r
473
+
474
+ ═══════════════════════════════════════════════════════════════
475
+ ```
273
476
 
274
477
  ---
275
478
 
276
- ## OUTPUT
479
+ ## MODE SUPPORT
480
+
481
+ ### Standard Mode
482
+
483
+ Full handoff with all implementation details:
484
+ - All 7 file categories
485
+ - Complete BR-to-code mapping
486
+ - Full API endpoint summary
487
+ - Detailed prd.json
488
+ - Comprehensive progress tracker
277
489
 
278
- The final deliverable:
490
+ ### Micro Mode (use_case = micro)
279
491
 
280
- - **ba-interactive.html** (deployed to docs/business/{app}/business-analyse/v{version}/)
281
- - Standalone interactive HTML document for client review
282
- - Pre-populated with ALL analysis data (metadata, cadrage, modules, wireframes, E2E flows)
283
- - FEATURE_DATA and EMBEDDED_ARTIFACTS fully serialized as JSON variables
284
- - Client can edit, add use cases, modify scope, and export JSON
285
- - Re-importable via `/business-analyse -x <exported-json-path>`
492
+ Simplified handoff with minimal scope:
493
+ - Only essential CRUD entity + controller
494
+ - 3 core SeedData entries (omit some optional ones)
495
+ - Basic prd.json with simplified sections
496
+ - Lightweight progress.txt
497
+ - Display `/ralph-loop -r` command for later use
498
+
499
+ ### Delta Mode (use_case = refactoring)
500
+
501
+ Focused handoff for changes:
502
+ - Only affected modules listed
503
+ - Reuse existing implementation patterns
504
+ - Highlight what changed vs baseline
505
+ - Update only affected prd.json sections
506
+ - Progress tracker shows only delta tasks
286
507
 
287
508
  ---
288
509
 
@@ -290,6 +511,11 @@ The final deliverable:
290
511
 
291
512
  | Issue | Resolution |
292
513
  |-------|-----------|
514
+ | All modules missing handoff data | Return to step-05a-handoff.md. Handoff MUST be written to each module feature.json. |
515
+ | prd.json generation failed | Verify ss derive-prd command is installed and feature.json path is correct. |
516
+ | progress.txt incomplete | Ensure all 5 CORE SeedData entries are present per module. Check topological order. |
517
+ | BA manifest not found | Create docs/business/index.json if missing. Use schema provided in section 3. |
518
+ | Manifest entries incorrect | Verify appCode, moduleCode, and version match feature.json metadata exactly. |
293
519
  | ba-interactive.html is too small (< 100KB) | FEATURE_DATA not serialized correctly. Verify JSON structure. Re-run FEATURE_DATA build. |
294
520
  | moduleSpecs missing from HTML | FEATURE_DATA.moduleSpecs is empty or not included in JSON. Verify each module is iterated and populated. |
295
521
  | Scope keys still show "mustHave" instead of "vital" | Conversion from feature.json keys to HTML keys failed. Check cadrage.scope conversion logic. |
@@ -297,30 +523,3 @@ The final deliverable:
297
523
  | dependencyGraph missing | Verify master feature.json has consolidation.dependencyGraph. If missing, create empty nodes/edges arrays. |
298
524
  | HTML opens but data blank (localStorage issue) | Clear browser localStorage. HTML will load pre-populated FEATURE_DATA on first load. |
299
525
  | Export/re-import fails | Verify exported JSON matches original feature.json schema. Validate with `/business-analyse -x --validate`. |
300
-
301
- ---
302
-
303
- ## FINAL COMPLETION
304
-
305
- ```
306
- ═══════════════════════════════════════════════════════════════
307
- BUSINESS ANALYSE COMPLETE
308
- ═══════════════════════════════════════════════════════════════
309
-
310
- All artifacts deployed:
311
- ✓ feature.json (master + per-module)
312
- ✓ prd.json (module-level task breakdown)
313
- ✓ progress.txt (development tracker)
314
- ✓ ba-interactive.html (client-facing review document)
315
-
316
- Next steps:
317
- 1. Share ba-interactive.html with stakeholders
318
- 2. Gather feedback and edits
319
- 3. Export modified JSON from HTML
320
- 4. Re-import with: /business-analyse -x <exported-json-path>
321
- 5. Launch development: /ralph-loop -r
322
-
323
- ═══════════════════════════════════════════════════════════════
324
- ```
325
-
326
- **Business analysis is now complete. The HTML document is ready for client review.**
@@ -1,6 +1,6 @@
1
1
  # Skill Launch Display Templates (templates/tpl-launch-displays.md)
2
2
 
3
- > **Used by:** step-05c-deploy (section 5: Completion Summary)
3
+ > **Used by:** step-05b-deploy (Completion Summary)
4
4
  > **Purpose:** User-facing display templates for BA completion
5
5
  > **Note:** No emojis - uses text markers per Claude Code conventions
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Progress Tracker Template (templates/tpl-progress.md)
2
2
 
3
- > **Used by:** step-05c-deploy (section 2: Initialize Progress Tracker)
3
+ > **Used by:** step-05b-deploy (section 2: Initialize Progress Tracker)
4
4
  > **Purpose:** Template structure for .ralph/progress.txt - populate with module-specific data
5
5
 
6
6
  ## Template
@@ -12,11 +12,11 @@ Execute the Ralph Weegund technique - an iterative development methodology where
12
12
  <quick_start>
13
13
  **Three ways to start Ralph Loop:**
14
14
 
15
- 1. **From Business Analysis (RECOMMENDED - NEW v6.1):**
15
+ 1. **From Business Analysis (RECOMMENDED):**
16
16
  ```bash
17
17
  /business-analyse MyFeature
18
- # At the end, choose "Ralph Loop" automatic launch
19
- # No arguments needed - prd.json already generated
18
+ # At the end, BA offers to launch ralph-loop automatically
19
+ # If PRD files are missing, ralph-loop auto-recovers via ss derive-prd
20
20
  ```
21
21
 
22
22
  2. **Manual start with existing prd.json:**
@@ -201,7 +201,73 @@ mkdir -p .ralph/logs
201
201
  mkdir -p .ralph/reports
202
202
  ```
203
203
 
204
- ### 4b. Detect Multi-Module PRDs (from BA Handoff)
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:**
210
+
211
+ ```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")
214
+ ```
215
+
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
+ ```
222
+
223
+ **IF master feature.json found:**
224
+
225
+ ```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;
257
+ }
258
+
259
+ console.log(`✅ Auto-recovered ${newPrdFiles.length} PRD files`);
260
+ // Continue to section 4b which will detect and queue them
261
+ }
262
+ ```
263
+
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)
205
271
 
206
272
  **After creating `.ralph/` directory, check for per-module PRD files:**
207
273
 
@@ -265,6 +331,16 @@ Queue: {module codes joined by " → "}
265
331
  Starting with: {modules[0].code}
266
332
  ```
267
333
 
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.
342
+ ```
343
+
268
344
  **If only `.ralph/prd.json` exists (single module):**
269
345
  - Skip queue creation (backward compatible)
270
346
  - Proceed normally