@atlashub/smartstack-cli 3.37.0 → 3.38.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 (216) hide show
  1. package/dist/index.js +16 -24
  2. package/dist/index.js.map +1 -1
  3. package/dist/mcp-entry.mjs +201 -256
  4. package/dist/mcp-entry.mjs.map +1 -1
  5. package/package.json +1 -1
  6. package/scripts/extract-api-endpoints.ts +5 -5
  7. package/scripts/generate-doc-with-mock-ui.ts +10 -17
  8. package/templates/agents/ba-reader.md +9 -9
  9. package/templates/agents/ba-writer.md +12 -15
  10. package/templates/agents/code-reviewer.md +1 -1
  11. package/templates/agents/docs-context-reader.md +1 -1
  12. package/templates/agents/gitflow/merge.md +0 -4
  13. package/templates/agents/gitflow/pr.md +0 -4
  14. package/templates/agents/gitflow/start.md +30 -5
  15. package/templates/mcp-scaffolding/frontend/nav-routes.ts.hbs +20 -20
  16. package/templates/mcp-scaffolding/frontend/routes.tsx.hbs +16 -24
  17. package/templates/mcp-scaffolding/migrations/seed-roles.cs.hbs +2 -2
  18. package/templates/skills/_resources/mcp-validate-documentation-spec.md +3 -3
  19. package/templates/skills/_shared.md +15 -17
  20. package/templates/skills/ai-prompt/SKILL.md +1 -1
  21. package/templates/skills/ai-prompt/steps/step-00-init.md +47 -0
  22. package/templates/skills/apex/SKILL.md +3 -4
  23. package/templates/skills/apex/_shared.md +10 -20
  24. package/templates/skills/apex/references/analysis-methods.md +141 -0
  25. package/templates/skills/apex/references/challenge-questions.md +1 -21
  26. package/templates/skills/apex/references/core-seed-data.md +35 -57
  27. package/templates/skills/apex/references/examine-build-validation.md +87 -0
  28. package/templates/skills/apex/references/execution-frontend-gates.md +177 -0
  29. package/templates/skills/apex/references/execution-frontend-patterns.md +105 -0
  30. package/templates/skills/apex/references/execution-layer1-rules.md +96 -0
  31. package/templates/skills/apex/references/initialization-challenge-flow.md +110 -0
  32. package/templates/skills/apex/references/planning-layer-mapping.md +151 -0
  33. package/templates/skills/apex/references/post-checks.md +145 -40
  34. package/templates/skills/apex/references/smartstack-api.md +35 -51
  35. package/templates/skills/apex/references/smartstack-frontend.md +17 -17
  36. package/templates/skills/apex/references/smartstack-layers.md +38 -62
  37. package/templates/skills/apex/steps/step-00-init.md +14 -26
  38. package/templates/skills/apex/steps/step-01-analyze.md +10 -143
  39. package/templates/skills/apex/steps/step-02-plan.md +10 -92
  40. package/templates/skills/apex/steps/step-03-execute.md +47 -249
  41. package/templates/skills/apex/steps/step-04-examine.md +14 -78
  42. package/templates/skills/apex/steps/step-05-deep-review.md +2 -2
  43. package/templates/skills/apex/steps/step-08-run-tests.md +2 -0
  44. package/templates/skills/application/SKILL.md +6 -7
  45. package/templates/skills/application/references/backend-controller-hierarchy.md +16 -16
  46. package/templates/skills/application/references/backend-seeding-and-dto-output.md +83 -0
  47. package/templates/skills/application/references/backend-table-prefix-mapping.md +79 -0
  48. package/templates/skills/application/references/backend-verification.md +1 -1
  49. package/templates/skills/application/references/frontend-i18n-and-output.md +67 -0
  50. package/templates/skills/application/references/frontend-route-naming.md +117 -0
  51. package/templates/skills/application/references/frontend-route-wiring-app-tsx.md +107 -0
  52. package/templates/skills/application/references/frontend-verification.md +12 -12
  53. package/templates/skills/application/references/init-parameter-detection.md +120 -0
  54. package/templates/skills/application/references/migration-checklist-troubleshooting.md +100 -0
  55. package/templates/skills/application/references/nav-fallback-procedure.md +5 -6
  56. package/templates/skills/application/references/provider-template.md +2 -6
  57. package/templates/skills/application/references/roles-client-project-handling.md +55 -0
  58. package/templates/skills/application/references/roles-fallback-procedure.md +149 -0
  59. package/templates/skills/application/references/test-coverage-requirements.md +213 -0
  60. package/templates/skills/application/references/test-frontend.md +3 -3
  61. package/templates/skills/application/steps/step-00-init.md +11 -141
  62. package/templates/skills/application/steps/step-01-navigation.md +3 -3
  63. package/templates/skills/application/steps/step-02-permissions.md +4 -4
  64. package/templates/skills/application/steps/step-03-roles.md +18 -175
  65. package/templates/skills/application/steps/step-03b-provider.md +1 -2
  66. package/templates/skills/application/steps/step-04-backend.md +19 -110
  67. package/templates/skills/application/steps/step-05-frontend.md +17 -143
  68. package/templates/skills/application/steps/step-06-migration.md +12 -60
  69. package/templates/skills/application/steps/step-07-tests.md +9 -76
  70. package/templates/skills/application/templates-backend.md +29 -27
  71. package/templates/skills/application/templates-frontend.md +48 -48
  72. package/templates/skills/application/templates-seed.md +57 -131
  73. package/templates/skills/business-analyse/SKILL.md +27 -30
  74. package/templates/skills/business-analyse/_architecture.md +6 -6
  75. package/templates/skills/business-analyse/_shared.md +60 -88
  76. package/templates/skills/business-analyse/questionnaire/04-data.md +3 -3
  77. package/templates/skills/business-analyse/questionnaire/06-security.md +1 -1
  78. package/templates/skills/business-analyse/questionnaire/13-cross-module.md +1 -1
  79. package/templates/skills/business-analyse/react/application-viewer.md +12 -12
  80. package/templates/skills/business-analyse/react/components.md +8 -12
  81. package/templates/skills/business-analyse/react/schema.md +11 -11
  82. package/templates/skills/business-analyse/references/agent-module-prompt.md +2 -3
  83. package/templates/skills/business-analyse/references/analysis-semantic-checks.md +190 -0
  84. package/templates/skills/business-analyse/references/cache-warming-strategy.md +2 -2
  85. package/templates/skills/business-analyse/references/cadrage-challenge-patterns.md +41 -0
  86. package/templates/skills/business-analyse/references/cadrage-coverage-matrix.md +74 -0
  87. package/templates/skills/business-analyse/references/cadrage-shared-modules.md +69 -0
  88. package/templates/skills/business-analyse/references/cadrage-structure-cards.md +1 -1
  89. package/templates/skills/business-analyse/references/compilation-structure-cards.md +297 -0
  90. package/templates/skills/business-analyse/references/consolidation-structural-checks.md +2 -2
  91. package/templates/skills/business-analyse/references/deploy-modes.md +5 -5
  92. package/templates/skills/business-analyse/references/detection-strategies.md +7 -7
  93. package/templates/skills/business-analyse/references/handoff-file-templates.md +14 -22
  94. package/templates/skills/business-analyse/references/handoff-mappings.md +4 -4
  95. package/templates/skills/business-analyse/references/handoff-seeddata-generation.md +312 -0
  96. package/templates/skills/business-analyse/references/init-schema-deployment.md +3 -3
  97. package/templates/skills/business-analyse/references/naming-conventions.md +22 -24
  98. package/templates/skills/business-analyse/references/prd-generation.md +2 -2
  99. package/templates/skills/business-analyse/references/review-data-mapping.md +2 -2
  100. package/templates/skills/business-analyse/references/robustness-checks.md +1 -1
  101. package/templates/skills/business-analyse/references/spec-auto-inference.md +3 -3
  102. package/templates/skills/business-analyse/references/team-orchestration.md +49 -6
  103. package/templates/skills/business-analyse/references/ui-dashboard-spec.md +1 -1
  104. package/templates/skills/business-analyse/references/ui-resource-cards.md +18 -18
  105. package/templates/skills/business-analyse/references/validate-incremental-html.md +2 -2
  106. package/templates/skills/business-analyse/references/validation-checklist.md +2 -2
  107. package/templates/skills/business-analyse/schemas/application-schema.json +4 -5
  108. package/templates/skills/business-analyse/schemas/project-schema.json +1 -6
  109. package/templates/skills/business-analyse/schemas/sections/metadata-schema.json +2 -3
  110. package/templates/skills/business-analyse/schemas/sections/specification-schema.json +4 -4
  111. package/templates/skills/business-analyse/steps/step-00-init.md +8 -17
  112. package/templates/skills/business-analyse/steps/step-01-cadrage.md +35 -198
  113. package/templates/skills/business-analyse/steps/step-01b-applications.md +16 -20
  114. package/templates/skills/business-analyse/steps/step-02-decomposition.md +1 -1
  115. package/templates/skills/business-analyse/steps/step-03a1-setup.md +4 -4
  116. package/templates/skills/business-analyse/steps/step-03a2-analysis.md +1 -1
  117. package/templates/skills/business-analyse/steps/step-03b-ui.md +4 -4
  118. package/templates/skills/business-analyse/steps/step-03c-compile.md +66 -140
  119. package/templates/skills/business-analyse/steps/step-03d-validate.md +2 -2
  120. package/templates/skills/business-analyse/steps/step-04a-collect.md +2 -2
  121. package/templates/skills/business-analyse/steps/step-04b-analyze.md +42 -160
  122. package/templates/skills/business-analyse/steps/step-04c-decide.md +1 -1
  123. package/templates/skills/business-analyse/steps/step-05a-handoff.md +74 -104
  124. package/templates/skills/business-analyse/steps/step-05b-deploy.md +13 -11
  125. package/templates/skills/business-analyse/steps/step-06-review.md +3 -3
  126. package/templates/skills/business-analyse/templates/tpl-frd.md +13 -13
  127. package/templates/skills/business-analyse/templates/tpl-handoff.md +12 -12
  128. package/templates/skills/business-analyse/templates-frd.md +25 -25
  129. package/templates/skills/business-analyse/templates-react.md +15 -21
  130. package/templates/skills/controller/SKILL.md +1 -1
  131. package/templates/skills/controller/postman-templates.md +1 -1
  132. package/templates/skills/controller/references/controller-code-templates.md +2 -2
  133. package/templates/skills/controller/references/mcp-scaffold-workflow.md +209 -0
  134. package/templates/skills/controller/references/permission-sync-templates.md +13 -16
  135. package/templates/skills/controller/steps/step-00-init.md +11 -11
  136. package/templates/skills/controller/steps/step-03-generate.md +64 -103
  137. package/templates/skills/controller/templates.md +67 -71
  138. package/templates/skills/debug/SKILL.md +13 -218
  139. package/templates/skills/debug/steps/step-00-init.md +57 -0
  140. package/templates/skills/debug/steps/step-01-analyze.md +219 -0
  141. package/templates/skills/debug/steps/step-02-resolve.md +85 -0
  142. package/templates/skills/documentation/SKILL.md +49 -345
  143. package/templates/skills/documentation/data-schema.md +11 -8
  144. package/templates/skills/documentation/steps/step-00-init.md +70 -0
  145. package/templates/skills/documentation/steps/step-01-scan.md +113 -0
  146. package/templates/skills/documentation/steps/step-02-generate.md +231 -0
  147. package/templates/skills/documentation/steps/step-03-validate.md +238 -0
  148. package/templates/skills/documentation/templates.md +480 -322
  149. package/templates/skills/efcore/references/both-contexts.md +32 -0
  150. package/templates/skills/efcore/references/database-operations.md +67 -0
  151. package/templates/skills/efcore/references/destructive-operations.md +38 -0
  152. package/templates/skills/efcore/references/reset-operations.md +81 -0
  153. package/templates/skills/efcore/references/seed-methods.md +86 -0
  154. package/templates/skills/efcore/references/shared-init-functions.md +250 -0
  155. package/templates/skills/efcore/references/sql-objects-injection.md +61 -0
  156. package/templates/skills/efcore/references/troubleshooting.md +81 -0
  157. package/templates/skills/efcore/steps/db/step-deploy.md +1 -32
  158. package/templates/skills/efcore/steps/db/step-reset.md +7 -103
  159. package/templates/skills/efcore/steps/db/step-seed.md +10 -132
  160. package/templates/skills/efcore/steps/db/step-status.md +5 -44
  161. package/templates/skills/efcore/steps/migration/step-03-validate.md +8 -62
  162. package/templates/skills/efcore/steps/rebase-snapshot/step-03-create.md +1 -57
  163. package/templates/skills/efcore/steps/shared/step-00-init.md +11 -254
  164. package/templates/skills/efcore/steps/squash/step-03-create.md +1 -58
  165. package/templates/skills/feature-full/SKILL.md +1 -1
  166. package/templates/skills/feature-full/steps/step-00-init.md +57 -0
  167. package/templates/skills/feature-full/steps/step-01-implementation.md +1 -1
  168. package/templates/skills/gitflow/SKILL.md +1 -1
  169. package/templates/skills/gitflow/_shared.md +23 -0
  170. package/templates/skills/gitflow/references/commit-message-generation.md +58 -0
  171. package/templates/skills/gitflow/references/commit-migration-validation.md +49 -0
  172. package/templates/skills/gitflow/references/finish-cleanup.md +51 -0
  173. package/templates/skills/gitflow/references/finish-version-bumping.md +45 -0
  174. package/templates/skills/gitflow/references/init-environment-detection.md +41 -0
  175. package/templates/skills/gitflow/references/init-questions.md +185 -0
  176. package/templates/skills/gitflow/references/init-structure-creation.md +71 -0
  177. package/templates/skills/gitflow/references/init-version-detection.md +21 -0
  178. package/templates/skills/gitflow/references/init-workspace-detection.md +43 -0
  179. package/templates/skills/gitflow/references/merge-ci-status.md +36 -0
  180. package/templates/skills/gitflow/references/merge-execution.md +62 -0
  181. package/templates/skills/gitflow/references/merge-pr-context.md +76 -0
  182. package/templates/skills/gitflow/references/pr-build-checks.md +60 -0
  183. package/templates/skills/gitflow/references/pr-generation.md +58 -0
  184. package/templates/skills/gitflow/references/start-branch-normalization.md +28 -0
  185. package/templates/skills/gitflow/references/start-worktree-creation.md +50 -0
  186. package/templates/skills/gitflow/references/sync-push-verify.md +44 -0
  187. package/templates/skills/gitflow/references/sync-rebase-conflicts.md +38 -0
  188. package/templates/skills/gitflow/steps/step-commit.md +12 -91
  189. package/templates/skills/gitflow/steps/step-finish.md +15 -159
  190. package/templates/skills/gitflow/steps/step-init.md +24 -326
  191. package/templates/skills/gitflow/steps/step-merge.md +17 -176
  192. package/templates/skills/gitflow/steps/step-pr.md +10 -116
  193. package/templates/skills/gitflow/steps/step-start.md +16 -109
  194. package/templates/skills/gitflow/steps/step-sync.md +6 -69
  195. package/templates/skills/ralph-loop/SKILL.md +6 -0
  196. package/templates/skills/ralph-loop/references/category-completeness.md +185 -0
  197. package/templates/skills/ralph-loop/references/compact-loop.md +1 -1
  198. package/templates/skills/ralph-loop/references/init-resume-recovery.md +127 -0
  199. package/templates/skills/ralph-loop/references/module-transition.md +151 -0
  200. package/templates/skills/ralph-loop/references/multi-module-queue.md +171 -0
  201. package/templates/skills/ralph-loop/references/parallel-execution.md +246 -0
  202. package/templates/skills/ralph-loop/references/task-transform-legacy.md +6 -9
  203. package/templates/skills/ralph-loop/references/team-orchestration.md +45 -3
  204. package/templates/skills/ralph-loop/steps/step-00-init.md +36 -109
  205. package/templates/skills/ralph-loop/steps/step-01-task.md +15 -163
  206. package/templates/skills/ralph-loop/steps/step-02-execute.md +8 -154
  207. package/templates/skills/ralph-loop/steps/step-04-check.md +21 -73
  208. package/templates/skills/review-code/references/owasp-api-top10.md +5 -5
  209. package/templates/skills/review-code/references/smartstack-conventions.md +11 -11
  210. package/templates/skills/validate-feature/references/api-smoke-tests.md +140 -0
  211. package/templates/skills/validate-feature/references/db-validation-checks.md +180 -0
  212. package/templates/skills/validate-feature/steps/step-01-compile.md +5 -2
  213. package/templates/skills/validate-feature/steps/step-04-api-smoke.md +34 -145
  214. package/templates/skills/validate-feature/steps/step-05-db-validation.md +74 -260
  215. package/templates/skills/workflow/SKILL.md +1 -1
  216. package/templates/skills/workflow/steps/step-00-init.md +57 -0
@@ -0,0 +1,127 @@
1
+ # Resume and Recovery Logic
2
+
3
+ > **Reference for:** step-00-init.md sections 4 (Resume Mode) and 4a (Auto-Recovery)
4
+ > **Purpose:** Handle resumption of interrupted loops and auto-recovery from BA artifacts
5
+
6
+ ---
7
+
8
+ ## Resume Mode
9
+
10
+ If `{resume_mode} = true` (user passed `-r` flag):
11
+
12
+ ```javascript
13
+ // Check PRD exists
14
+ if (!fileExists('.ralph/prd.json')) {
15
+ console.error('ERROR: -r flag set but .ralph/prd.json not found');
16
+ STOP;
17
+ }
18
+
19
+ const prd = readJSON('.ralph/prd.json');
20
+
21
+ // Detect format
22
+ let resumeValid = false;
23
+ if (prd.$version === '3.0.0') {
24
+ // v3 unified — native format
25
+ resumeValid = true;
26
+ console.log('Resume: v3.0.0 unified PRD');
27
+ } else if (prd.$version === '2.0.0') {
28
+ // v2 legacy — OK to resume
29
+ resumeValid = true;
30
+ console.log('Resume: v2.0.0 legacy PRD');
31
+ } else if (prd.project && prd.requirements && !prd.$version) {
32
+ // FORMAT A deprecated — warn but transform
33
+ console.warn('⚠ DEPRECATED: FORMAT A prd.json detected during resume');
34
+ console.warn('Re-run `ss derive-prd` to generate v3 format');
35
+ // NOTE: Transformation happens in step-01, not here
36
+ resumeValid = true;
37
+ } else {
38
+ console.error('ERROR: .ralph/prd.json format not recognized');
39
+ STOP;
40
+ }
41
+
42
+ if (resumeValid) {
43
+ // Check branch consistency
44
+ const branch = prd.metadata?.branch || 'unknown';
45
+ const currentBranch = getCurrentBranch();
46
+ if (branch !== currentBranch) {
47
+ console.warn(`⚠ Branch mismatch: PRD from ${branch}, currently on ${currentBranch}`);
48
+ console.warn('Continuing anyway — verify this is intentional');
49
+ }
50
+
51
+ // Restore state
52
+ {current_iteration} = prd.config?.current_iteration || 1;
53
+ {completion_promise} = prd.config?.completion_promise || null;
54
+ {max_iterations} = prd.config?.max_iterations || 50;
55
+
56
+ // Restore multi-module state if present
57
+ if (fileExists('.ralph/modules-queue.json')) {
58
+ {modules_queue} = readJSON('.ralph/modules-queue.json');
59
+ {current_module} = {modules_queue}.modules[{modules_queue}.currentIndex]?.code;
60
+ console.log(`Multi-module resume: ${{current_module}} (${{modules_queue}.currentIndex + 1}/${{modules_queue}.totalModules})`);
61
+ }
62
+
63
+ console.log(`Resuming from iteration ${{current_iteration}}`);
64
+ // Continue to step-01
65
+ }
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Auto-Recovery: BA Artifacts Without PRD
71
+
72
+ If no PRD files exist (neither `.ralph/prd-*.json` nor `.ralph/prd.json`):
73
+
74
+ ```javascript
75
+ const masterFeature = findFile('docs/business/**/business-analyse/**/feature.json');
76
+
77
+ if (!masterFeature) {
78
+ // No BA artifacts found — start fresh
79
+ console.log('No existing PRD or BA artifacts — starting new loop');
80
+ return;
81
+ }
82
+
83
+ const master = readJSON(masterFeature);
84
+ const handoffStatus = master.status || master.handoff?.status || null;
85
+
86
+ if (handoffStatus === 'handed-off') {
87
+ // BA handoff completed — auto-derive PRDs
88
+ console.log('BA artifacts detected without PRD — auto-recovering...');
89
+
90
+ // Call ss derive-prd to generate PRD files
91
+ const result = exec(`ss derive-prd --application ${masterFeature}`);
92
+
93
+ if (result.exitCode !== 0) {
94
+ console.error('ss derive-prd failed — cannot auto-recover');
95
+ STOP;
96
+ }
97
+
98
+ const newPrds = glob('.ralph/prd-*.json');
99
+ if (newPrds.length === 0) {
100
+ console.error('ss derive-prd did not create any PRD files');
101
+ STOP;
102
+ }
103
+
104
+ console.log(`Auto-recovered ${newPrds.length} PRD file(s): ${newPrds.map(f => f.split('/').pop()).join(', ')}`);
105
+ // Continue to detect multi-module (section 4b)
106
+ } else {
107
+ // BA handoff NOT complete
108
+ console.warn(`⚠ BA handoff status: "${handoffStatus}" (expected "handed-off")`);
109
+ console.warn('Cannot auto-recover PRD files without complete handoff');
110
+ console.warn('Run /business-analyse to complete the handoff, then retry /ralph-loop');
111
+ STOP;
112
+ }
113
+ ```
114
+
115
+ ---
116
+
117
+ ## State After Recovery
118
+
119
+ After resume or auto-recovery:
120
+
121
+ ```javascript
122
+ // If PRD now exists (either resumed or recovered):
123
+ // - Continue to section 4b (Detect Multi-Module)
124
+ // - Initialize modules-queue.json if 2+ PRD files found
125
+ // - Set {modules_queue} and {current_module} appropriately
126
+ // - Proceed to step-01 to load tasks
127
+ ```
@@ -0,0 +1,151 @@
1
+ # Module Transition Logic
2
+
3
+ > **Reference for:** step-04-check.md section 3b
4
+ > **Trigger:** Multi-module mode + current module complete
5
+ > **Purpose:** Advance to next module in queue OR finish if all done
6
+
7
+ ---
8
+
9
+ ## When Module Transition Occurs
10
+
11
+ ```javascript
12
+ const queuePath = '.ralph/modules-queue.json';
13
+ if (fileExists(queuePath)) {
14
+ const queue = readJSON(queuePath);
15
+ const currentModule = queue.modules[queue.currentIndex];
16
+
17
+ // MODULE COMPLETENESS CHECK
18
+ const completedCats = new Set(prd.tasks.filter(t => t.status === 'completed').map(t => t.category));
19
+ const expected = ['domain', 'infrastructure', 'application', 'api', 'seedData', 'frontend', 'test'];
20
+ const missing = expected.filter(c => !completedCats.has(c));
21
+
22
+ if (missing.length > 0) {
23
+ console.log(`Module ${currentModule.code}: missing categories ${missing.join(', ')} — continuing loop`);
24
+ // Fall through to compact loop (section 5)
25
+ return;
26
+ }
27
+
28
+ // All categories present — module is complete
29
+ // Continue below...
30
+ }
31
+ ```
32
+
33
+ ---
34
+
35
+ ## Advance to Next Module
36
+
37
+ ```javascript
38
+ if (missing.length === 0) {
39
+ // Mark current module done
40
+ currentModule.status = 'completed';
41
+ queue.completedModules++;
42
+ const nextIndex = queue.currentIndex + 1;
43
+
44
+ if (nextIndex < queue.totalModules) {
45
+ // More modules to process
46
+ queue.currentIndex = nextIndex;
47
+ queue.modules[nextIndex].status = 'in-progress';
48
+ writeJSON(queuePath, queue);
49
+
50
+ // Signal module transition to step-01
51
+ writeJSON('.ralph/module-changed.json', {
52
+ fromModule: currentModule.code,
53
+ toModule: queue.modules[nextIndex].code,
54
+ timestamp: new Date().toISOString()
55
+ });
56
+
57
+ // Mark current PRD as complete
58
+ prd.status = 'completed';
59
+ writeJSON('.ralph/prd.json', prd);
60
+
61
+ // Load next module's PRD
62
+ const nextPrd = readJSON(queue.modules[nextIndex].prdFile);
63
+ nextPrd.config.current_iteration = 1;
64
+ nextPrd.config.max_iterations = prd.config.max_iterations;
65
+ writeJSON('.ralph/prd.json', nextPrd);
66
+
67
+ console.log(`MODULE COMPLETE: ${currentModule.code} → NEXT: ${queue.modules[nextIndex].code}`);
68
+
69
+ // Return to step-01 to load next module's tasks
70
+ // (step-01 will detect module-changed.json and load next PRD)
71
+ return GO_TO_STEP_01;
72
+ }
73
+
74
+ // ALL MODULES COMPLETE
75
+ // Continue to section 3c (completion output) → step-05
76
+ }
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Check: All Modules Complete
82
+
83
+ ```javascript
84
+ if (nextIndex >= queue.totalModules) {
85
+ // No more modules
86
+ writeJSON(queuePath, queue);
87
+ console.log(`ALL ${queue.totalModules} MODULES COMPLETE`);
88
+
89
+ // Fall through to step 3c (completion output) → step-05
90
+ }
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Step-01 Module Detection
96
+
97
+ When returning to step-01 after module transition:
98
+
99
+ ```javascript
100
+ // In step-01, section 0:
101
+ const moduleChangePath = '.ralph/module-changed.json';
102
+ if (fileExists(moduleChangePath)) {
103
+ const transition = readJSON(moduleChangePath);
104
+ console.log(`Module transition: ${transition.fromModule} → ${transition.toModule}`);
105
+ deleteFile(moduleChangePath);
106
+
107
+ // This is an exception to "Read Once" rule — PRD has changed
108
+ // PROCEED with loading the new module's tasks
109
+ }
110
+ ```
111
+
112
+ ---
113
+
114
+ ## State Transitions
115
+
116
+ ```
117
+ [Phase A: Module 1]
118
+ ├─ step-01: Load tasks from prd-module1.json
119
+ ├─ step-02: Delegate to /apex
120
+ ├─ step-03: Commit PRD state
121
+ ├─ step-04: Check completion
122
+ │ └─ If all categories complete:
123
+ │ ├─ Write module-changed.json
124
+ │ ├─ Write next PRD to .ralph/prd.json
125
+ │ └─ Return to step-01 ✓
126
+
127
+ └─ [Phase B: Module 2]
128
+ ├─ step-01: Detect module-changed.json, load next PRD
129
+ ├─ step-02: Delegate to /apex
130
+ ├─ ... (repeat for module 2)
131
+
132
+ └─ [Module 2 complete]
133
+ ├─ Mark module 2 done in modules-queue.json
134
+ ├─ Check if more modules
135
+ │ ├─ If yes: Transition to module 3 (goto Phase C)
136
+ │ └─ If no: Fall through to step-05 ✓
137
+
138
+ └─ [Phase N: Final Module]
139
+ ├─ ... (repeat)
140
+ └─ ALL MODULES COMPLETE → step-05
141
+ ```
142
+
143
+ ---
144
+
145
+ ## Rules
146
+
147
+ - **Module completeness check runs EVERY iteration:** Not just once
148
+ - **Exception to "Read Once":** When transitioning modules, step-01 re-reads the new PRD
149
+ - **Atomic module advancement:** Only transition when all required categories are complete
150
+ - **Max iterations applies globally:** Not per-module
151
+ - **State persistence:** modules-queue.json tracks progress across modules
@@ -0,0 +1,171 @@
1
+ # Multi-Module Queue Initialization
2
+
3
+ > **Reference for:** step-01-task.md section 0
4
+ > **Purpose:** Initialize multi-module state when 2+ PRD files detected
5
+ > **Output:** modules-queue.json with module list and current index
6
+
7
+ ---
8
+
9
+ ## Detection
10
+
11
+ ```javascript
12
+ const prdFiles = glob('.ralph/prd-*.json');
13
+ const PRD_COUNT = prdFiles.length;
14
+
15
+ if (PRD_COUNT === 0) {
16
+ {modules_queue} = null;
17
+ {current_module} = null;
18
+ return; // Single module mode or no PRDs
19
+ }
20
+
21
+ if (PRD_COUNT === 1) {
22
+ // Single module
23
+ {modules_queue} = null;
24
+ {current_module} = null;
25
+ return; // Use standard mode
26
+ }
27
+
28
+ // PRD_COUNT > 1 → Multi-module detected
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Module Queue Construction
34
+
35
+ ```javascript
36
+ const modules = [];
37
+
38
+ // Step 1: Get module order from master feature.json
39
+ const masterFeature = findFile('docs/business/**/business-analyse/**/feature.json');
40
+ let moduleOrder = [];
41
+
42
+ if (masterFeature) {
43
+ const master = readJSON(masterFeature);
44
+ moduleOrder = master.metadata?.workflow?.moduleOrder || [];
45
+ }
46
+
47
+ // Step 2: Build queue in order
48
+ for (const mod of moduleOrder) {
49
+ const prdFile = `.ralph/prd-${mod.code}.json`;
50
+ if (fileExists(prdFile)) {
51
+ modules.push({
52
+ code: mod.code,
53
+ prdFile: prdFile,
54
+ status: 'pending'
55
+ });
56
+ }
57
+ }
58
+
59
+ // Step 3: Fallback to alphabetical if no order from feature.json
60
+ if (modules.length === 0) {
61
+ for (const file of prdFiles) {
62
+ const code = file.match(/prd-(.+)\.json$/)[1];
63
+ modules.push({
64
+ code: code,
65
+ prdFile: `.ralph/${file}`,
66
+ status: 'pending'
67
+ });
68
+ }
69
+ modules.sort((a, b) => a.code.localeCompare(b.code));
70
+ }
71
+
72
+ // Step 4: Initialize first module as in-progress
73
+ if (modules.length > 0) {
74
+ modules[0].status = 'in-progress';
75
+ }
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Queue State Structure
81
+
82
+ ```javascript
83
+ const queue = {
84
+ modules: modules, // Array of {code, prdFile, status}
85
+ currentIndex: 0, // Index of currently executing module
86
+ totalModules: modules.length, // Total count
87
+ completedModules: 0 // Count of completed modules
88
+ };
89
+
90
+ writeJSON('.ralph/modules-queue.json', queue);
91
+
92
+ {modules_queue} = queue;
93
+ {current_module} = modules[0].code;
94
+
95
+ console.log(`Multi-module: ${modules.length} modules → ${modules.map(m => m.code).join(' → ')}`);
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Module Transition (Next Iteration)
101
+
102
+ When calling step-01 after a module completes:
103
+
104
+ ```javascript
105
+ // Check for module transition marker
106
+ if (fileExists('.ralph/module-changed.json')) {
107
+ const transition = readJSON('.ralph/module-changed.json');
108
+ console.log(`Module transition: ${transition.fromModule} → ${transition.toModule}`);
109
+ deleteFile('.ralph/module-changed.json');
110
+
111
+ // PROCEED — this is an exception to the "Read Once" rule
112
+ // Continue to load the new module's PRD
113
+ }
114
+ ```
115
+
116
+ ---
117
+
118
+ ## PRD Loading for Current Module
119
+
120
+ ```javascript
121
+ const queuePath = '.ralph/modules-queue.json';
122
+ if (fileExists(queuePath)) {
123
+ const queue = readJSON(queuePath);
124
+ const currentModule = queue.modules[queue.currentIndex];
125
+
126
+ const currentPrd = readJSON('.ralph/prd.json');
127
+ if (currentPrd.metadata?.moduleCode !== currentModule.code) {
128
+ // Module has changed — load new PRD
129
+ const modulePrd = readJSON(currentModule.prdFile);
130
+
131
+ // v3 FAST PATH
132
+ if (modulePrd.$version === '3.0.0') {
133
+ modulePrd.status = 'in_progress';
134
+ modulePrd.feature = `${modulePrd.project?.module || currentModule.code} (${modulePrd.project?.application || 'app'})`;
135
+ modulePrd.created = modulePrd.created || new Date().toISOString();
136
+ modulePrd.updated_at = new Date().toISOString();
137
+ modulePrd.config = modulePrd.config || {
138
+ max_iterations: {max_iterations},
139
+ completion_promise: "{completion_promise}",
140
+ current_iteration: 1
141
+ };
142
+ modulePrd.metadata.branch = modulePrd.metadata.branch || getCurrentBranch();
143
+ modulePrd.metadata.project_path = modulePrd.metadata.project_path || process.cwd();
144
+ modulePrd.metadata.mcp_servers = modulePrd.metadata.mcp_servers || { smartstack: true, context7: true };
145
+ modulePrd.history = modulePrd.history || [];
146
+ writeJSON('.ralph/prd.json', modulePrd);
147
+ }
148
+ // LEGACY: FORMAT A
149
+ else if (modulePrd.project && modulePrd.requirements && !modulePrd.$version) {
150
+ console.warn('⚠ DEPRECATED: FORMAT A prd.json detected. Re-run `ss derive-prd` to generate v3 format.');
151
+ writeJSON('.ralph/prd.json', transformPrdJsonToRalphV2(modulePrd, currentModule.code));
152
+ }
153
+ // v2 legacy
154
+ else {
155
+ writeJSON('.ralph/prd.json', modulePrd);
156
+ }
157
+ }
158
+
159
+ {current_module} = currentModule.code;
160
+ }
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Single Module Mode
166
+
167
+ If PRD_COUNT === 0 or 1:
168
+ - {modules_queue} = null
169
+ - {current_module} = null
170
+ - Skip multi-module logic
171
+ - Use standard single-module compact loop
@@ -0,0 +1,246 @@
1
+ # Parallel Execution Mode (Agent Teams)
2
+
3
+ > **Reference for:** step-02-execute.md section 3a
4
+ > **Trigger:** `-p` flag OR `{parallel_mode} == true`
5
+ > **Applicability:** Multi-module only (2+ modules)
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ When Ralph detects 2+ modules with `-p` flag:
12
+
13
+ 1. **Phase 0 (Ralph sequential):** Generate ALL entities from ALL modules + ONE migration
14
+ 2. **Phase 1-N (Teams parallel):** Spawn teammates per application/module for services/controllers/frontend/tests
15
+ 3. **Cleanup:** Collect results, validate, TeamDelete
16
+
17
+ ---
18
+
19
+ ## Phase 0: Foundation (Sequential)
20
+
21
+ ### 1. Collect All Entities
22
+
23
+ ```javascript
24
+ const allEntities = [];
25
+ const allModules = [];
26
+ for (const prdFile of glob('.ralph/prd-*.json')) {
27
+ const modulePrd = readJSON(prdFile);
28
+ const moduleEntities = modulePrd.tasks
29
+ .filter(t => t.category === 'domain')
30
+ .map(t => extractEntityName(t.description));
31
+ allEntities.push(...moduleEntities);
32
+ allModules.push({
33
+ code: modulePrd.project.module,
34
+ application: modulePrd.project.application,
35
+ prdFile: prdFile,
36
+ entityCount: moduleEntities.length
37
+ });
38
+ }
39
+
40
+ console.log(`PARALLEL MODE: Phase 0 — Foundation`);
41
+ console.log(` Generating ${allEntities.length} entities from ${allModules.length} modules`);
42
+ console.log(` Entities: ${allEntities.join(', ')}`);
43
+ ```
44
+
45
+ ### 2. Invoke /apex --foundation
46
+
47
+ Ralph invokes `/apex --foundation -d .ralph/prd.json` which:
48
+ - Generates ALL entity classes
49
+ - Generates ALL EF configurations
50
+ - Registers ALL DbSets in DbContext
51
+ - Creates ONE migration with all entities
52
+ - **SKIPS** services/controllers/frontend/tests
53
+
54
+ ```bash
55
+ /apex --foundation -d .ralph/prd.json
56
+ ```
57
+
58
+ ### 3. Commit Foundation
59
+
60
+ ```bash
61
+ git add .
62
+ git commit -m "chore(foundation): entities for all modules
63
+
64
+ $(allModules.map(m => m.code).join(' + ')) — ${allEntities.length} entities
65
+
66
+ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"
67
+ ```
68
+
69
+ Result: ModelSnapshot contains all entities. Database ready for application layers.
70
+
71
+ ---
72
+
73
+ ## Phase 1-N: Parallel Teams
74
+
75
+ ### 1. Determine Teammate Granularity
76
+
77
+ Applications can have 1-N modules. Teammate strategy:
78
+
79
+ ```javascript
80
+ const teammates = [];
81
+ const applicationsMap = {}; // { appName: [module1, module2, ...] }
82
+
83
+ for (const mod of allModules) {
84
+ if (!applicationsMap[mod.application]) {
85
+ applicationsMap[mod.application] = [];
86
+ }
87
+ applicationsMap[mod.application].push(mod);
88
+ }
89
+
90
+ for (const [appName, modules] of Object.entries(applicationsMap)) {
91
+ if (modules.length <= 3) {
92
+ // 1 teammate per APPLICATION
93
+ teammates.push({
94
+ name: `apex-${kebabCase(appName)}`,
95
+ application: appName,
96
+ modules: modules.map(m => m.code),
97
+ prdFiles: modules.map(m => m.prdFile)
98
+ });
99
+ } else {
100
+ // Application has >3 modules → 1 teammate per MODULE
101
+ for (const mod of modules) {
102
+ teammates.push({
103
+ name: `apex-${kebabCase(appName)}-${kebabCase(mod.code)}`,
104
+ application: appName,
105
+ modules: [mod.code],
106
+ prdFiles: [mod.prdFile]
107
+ });
108
+ }
109
+ }
110
+ }
111
+
112
+ console.log(`Spawning ${teammates.length} teammates:`);
113
+ for (const t of teammates) {
114
+ console.log(` - ${t.name}: ${t.modules.join(', ')}`);
115
+ }
116
+ ```
117
+
118
+ ### 2. Create Team
119
+
120
+ ```javascript
121
+ TeamCreate({
122
+ team_name: `smartstack-${kebabCase(prd.project.name || 'project')}`,
123
+ description: `Parallel development for ${teammates.length} modules`
124
+ });
125
+ ```
126
+
127
+ ### 3. Spawn Teammates
128
+
129
+ ```javascript
130
+ for (const teammate of teammates) {
131
+ Task({
132
+ subagent_type: "apex",
133
+ name: teammate.name,
134
+ team_name: `smartstack-${kebabCase(prd.project.name || 'project')}`,
135
+ prompt: `
136
+ You are teammate ${teammate.name}.
137
+
138
+ CONTEXT:
139
+ - Application: ${teammate.application}
140
+ - Modules: ${teammate.modules.join(', ')}
141
+ - PRD files: ${teammate.prdFiles.join(', ')}
142
+
143
+ ENTITIES ALREADY EXIST (Phase 0 completed):
144
+ All entity classes, EF configurations, and migrations are complete.
145
+ The ModelSnapshot is complete and the database is ready.
146
+ DO NOT attempt to create entities or migrations.
147
+
148
+ YOUR TASK:
149
+ For each module in ${teammate.modules}, generate:
150
+ - Services (Application layer)
151
+ - Controllers (API layer)
152
+ - Seed data (Navigation + Permissions + Business data)
153
+ - Frontend (Pages + Routes + i18n for all 4 languages)
154
+ - Tests (Unit + Integration)
155
+
156
+ DO NOT:
157
+ - Create new entities (already done in Phase 0)
158
+ - Create migrations (ModelSnapshot already complete)
159
+ - Modify DbContext (already done in Phase 0)
160
+
161
+ EXECUTE:
162
+ For each PRD file: invoke /apex -d {prdFile}
163
+ Apex will detect existing entities and skip domain/infrastructure layers.
164
+
165
+ When done, send a message to team lead with results:
166
+ {
167
+ "type": "completion",
168
+ "teammate": "${teammate.name}",
169
+ "status": "complete" | "failed",
170
+ "modules": ${JSON.stringify(teammate.modules)},
171
+ "summary": "Brief summary of what was generated"
172
+ }
173
+ `
174
+ });
175
+ }
176
+ ```
177
+
178
+ ### 4. Wait for Teammates
179
+
180
+ Ralph waits for all teammates to send completion messages:
181
+
182
+ ```javascript
183
+ const MAX_WAIT = 3600; // 1 hour timeout
184
+ const POLL_INTERVAL = 5; // 5 seconds
185
+
186
+ const teamMateResults = [];
187
+ const deadline = Date.now() + MAX_WAIT * 1000;
188
+
189
+ while (teamMateResults.length < teammates.length && Date.now() < deadline) {
190
+ // Check for new messages from teammates
191
+ const messages = getTeamMessages();
192
+ for (const msg of messages) {
193
+ if (msg.type === 'completion') {
194
+ teamMateResults.push(msg);
195
+ console.log(` ✅ ${msg.teammate}: ${msg.status}`);
196
+ }
197
+ }
198
+ if (teamMateResults.length < teammates.length) {
199
+ sleep(POLL_INTERVAL * 1000);
200
+ }
201
+ }
202
+
203
+ if (teamMateResults.length < teammates.length) {
204
+ console.error(`TIMEOUT: ${teammates.length - teamMateResults.length} teammates did not complete`);
205
+ // Set status to 'partial'
206
+ }
207
+ ```
208
+
209
+ ### 5. Collect & Validate Results
210
+
211
+ ```javascript
212
+ const completedTeammates = teamMateResults.filter(r => r.status === 'complete').length;
213
+ const failedTeammates = teamMateResults.filter(r => r.status === 'failed').length;
214
+
215
+ console.log(`Phase 1-N completed:`);
216
+ console.log(` ✅ ${completedTeammates} teammates succeeded`);
217
+ console.log(` ❌ ${failedTeammates} teammates failed`);
218
+ console.log(` ⏱ ${teammates.length - teamMateResults.length} teammates did not respond`);
219
+ ```
220
+
221
+ ### 6. Cleanup Team
222
+
223
+ ```javascript
224
+ TeamDelete();
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Fallback (Non-Parallel)
230
+
231
+ If `-p` flag NOT set OR only 1 module detected:
232
+
233
+ - **Single module:** Ralph executes compact loop normally (no teams)
234
+ - **Multi-module (no -p):** Check for dependency graph in feature.json
235
+ - If graph exists → Classic Agent Teams (layered approach)
236
+ - If no graph → Sequential compact loop per module
237
+
238
+ ---
239
+
240
+ ## Rules
241
+
242
+ - **Phase 0 is sequential:** Ralph must complete foundation first
243
+ - **Phase 1-N is parallel:** Teammates execute in parallel
244
+ - **No entity duplication:** Phase 1 teammates skip domain/infrastructure
245
+ - **Timeout:** 1 hour per phase (configurable)
246
+ - **Partial success OK:** If some teammates fail, continue validation