@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
@@ -8,682 +8,199 @@ next_step: steps/step-05-report.md OR steps/step-01-task.md
8
8
 
9
9
  ## YOUR TASK:
10
10
 
11
- Check if all tasks are complete and decide whether to output completion promise or continue to next task.
11
+ Check if all tasks are complete and decide: output completion promise, advance module, or continue loop.
12
12
 
13
13
  ---
14
14
 
15
- ## EXECUTION SEQUENCE:
16
-
17
- ### 1. Read Current State
18
-
19
- **Load prd.json:**
15
+ ## 1. Read Current State
20
16
 
21
17
  ```javascript
22
18
  const prd = readJSON('.ralph/prd.json');
23
-
24
19
  const tasksCompleted = prd.tasks.filter(t => t.status === 'completed').length;
25
- const tasksSkipped = prd.tasks.filter(t => t.status === 'skipped').length;
26
- const tasksFailed = prd.tasks.filter(t => t.status === 'failed').length;
27
- const tasksBlocked = prd.tasks.filter(t => t.status === 'blocked').length;
28
- const tasksPending = prd.tasks.filter(t => t.status === 'pending').length;
29
- const tasksTotal = prd.tasks.length;
30
-
31
- const allDone = (tasksCompleted + tasksSkipped) === tasksTotal;
32
- const hasFailures = tasksFailed > 0;
33
- const hasBlocked = tasksBlocked > 0;
34
- const hasPending = tasksPending > 0;
20
+ const tasksSkipped = prd.tasks.filter(t => t.status === 'skipped').length;
21
+ const tasksFailed = prd.tasks.filter(t => t.status === 'failed').length;
22
+ const tasksBlocked = prd.tasks.filter(t => t.status === 'blocked').length;
23
+ const tasksPending = prd.tasks.filter(t => t.status === 'pending').length;
24
+ const tasksTotal = prd.tasks.length;
25
+ const allDone = (tasksCompleted + tasksSkipped) === tasksTotal;
35
26
  ```
36
27
 
37
- ### 1.5. REGRESSION CHECK (MANDATORY AFTER EACH ITERATION)
38
-
39
- **CRITICAL: After EVERY task completion, run full test suite to detect regressions.**
28
+ ### 1.5. Regression Check (BLOCKING)
40
29
 
30
+ **Backend — build + tests:**
41
31
  ```bash
42
- PROJECT_NAME=$(basename $(pwd))
43
- TEST_PROJECT="tests/${PROJECT_NAME}.Tests.Unit"
32
+ dotnet build --no-restore
33
+ if [ $? -ne 0 ]; then
34
+ echo "BUILD REGRESSION — creating fix task"
35
+ # Inject fix task, category: validation, acceptance: "dotnet build passes"
36
+ fi
44
37
 
38
+ TEST_PROJECT="tests/$(basename $(pwd)).Tests.Unit"
45
39
  if [ -d "$TEST_PROJECT" ]; then
46
- echo "🔍 Running regression check (full test suite)..."
47
-
48
- # Run ALL tests to ensure nothing broke
49
- dotnet test "$TEST_PROJECT" --no-build --verbosity minimal --logger "console;verbosity=minimal"
50
-
51
- REGRESSION_EXIT_CODE=$?
52
-
53
- if [ $REGRESSION_EXIT_CODE -ne 0 ]; then
54
- echo "╔════════════════════════════════════════════════════════════╗"
55
- echo "║ ⚠️ REGRESSION DETECTED ║"
56
- echo "╠════════════════════════════════════════════════════════════╣"
57
- echo "║ A previously passing test is now failing. ║"
58
- echo "║ This indicates the last change broke existing code. ║"
59
- echo "╠════════════════════════════════════════════════════════════╣"
60
- echo "║ CORRECTIVE ACTION: ║"
61
- echo "║ 1. Identify which test(s) started failing ║"
62
- echo "║ 2. Analyze what changed in last commit ║"
63
- echo "║ 3. Fix the regression ║"
64
- echo "║ 4. Commit the fix ║"
65
- echo "║ 5. Ralph will continue automatically ║"
66
- echo "╚════════════════════════════════════════════════════════════╝"
67
-
68
- // Parse test output to identify which tests failed
69
- const regressionTests = parseFailedTests(testOutput);
70
-
71
- // Log regression details to progress.txt
72
- const progressEntry = `
73
- [REGRESSION DETECTED - Iteration ${prd.config.current_iteration}]
74
- Failed tests: ${regressionTests.join(', ')}
75
- Last completed task: ${prd.tasks.find(t => t.id === lastCompletedTaskId).description}
76
- Commit: ${lastCommitHash}
77
-
78
- ACTION REQUIRED: Fix regression before continuing.
79
- `;
80
- appendToFile('.ralph/progress.txt', progressEntry);
81
-
82
- // Mark current state as having regression
83
- prd.regression_detected = {
84
- iteration: prd.config.current_iteration,
85
- failed_tests: regressionTests,
86
- last_task: lastCompletedTaskId,
87
- commit_hash: lastCommitHash
88
- };
40
+ dotnet test "$TEST_PROJECT" --no-build --verbosity normal
41
+ if [ $? -ne 0 ]; then
42
+ echo "TEST REGRESSION creating fix task"
43
+ # Inject fix task into prd.json:
44
+ prd.tasks.push({ id: maxId+1, description: "Fix test regression — all tests must pass",
45
+ status: "pending", category: "validation", dependencies: [],
46
+ acceptance_criteria: "dotnet test exits 0, all tests pass" });
89
47
  writeJSON('.ralph/prd.json', prd);
48
+ fi
49
+ fi
50
+ ```
90
51
 
91
- // Create a new task to fix the regression
92
- const fixTask = {
93
- id: prd.tasks.length + 1,
94
- description: `Fix regression: ${regressionTests.length} test(s) failing`,
95
- status: 'pending',
96
- category: 'validation',
97
- dependencies: [],
98
- acceptance_criteria: `All tests pass: ${regressionTests.join(', ')}`,
99
- started_at: null,
100
- completed_at: null,
101
- iteration: null,
102
- commit_hash: null,
103
- files_changed: { created: [], modified: [] },
104
- validation: null,
105
- error: null
106
- };
107
- prd.tasks.push(fixTask);
108
- prd.updated_at = new Date().toISOString();
52
+ **Frontend typecheck + lint:**
53
+ ```bash
54
+ if [ -f "web/package.json" ] || [ -f "package.json" ]; then
55
+ npm run typecheck
56
+ if [ $? -ne 0 ]; then
57
+ echo "FRONTEND REGRESSION — creating fix task"
58
+ prd.tasks.push({ id: maxId+1, description: "Fix frontend typecheck errors",
59
+ status: "pending", category: "frontend", dependencies: [],
60
+ acceptance_criteria: "npm run typecheck exits 0" });
109
61
  writeJSON('.ralph/prd.json', prd);
110
-
111
- // DO NOT STOP - continue to next task (which is the fix task)
112
- echo "📋 Created task ${fixTask.id}: Fix regression";
113
- } else {
114
- echo "✅ Regression check passed. No tests broken.";
115
-
116
- // Update test metrics in progress.txt
117
- const testStats = parseTestStats(testOutput);
118
- const metricsEntry = `
119
- [Test Metrics - Iteration ${prd.config.current_iteration}]
120
- Total: ${testStats.total} | Passed: ${testStats.passed} | Failed: ${testStats.failed} | Skipped: ${testStats.skipped}
121
- Duration: ${testStats.duration}
122
- `;
123
- appendToFile('.ralph/progress.txt', metricsEntry);
124
- }
62
+ fi
125
63
  fi
126
64
  ```
127
65
 
128
- ### 2. Check Iteration Limit
129
-
130
- **If `prd.config.current_iteration` > `prd.config.max_iterations`:**
66
+ ## 2. Check Iteration Limit
131
67
 
68
+ If `current_iteration > max_iterations`:
132
69
  ```
133
- ╔══════════════════════════════════════════════════════════════════╗
134
- ║ ⚠️ MAX ITERATIONS REACHED ║
135
- ╠══════════════════════════════════════════════════════════════════╣
136
- ║ Iterations: {current_iteration} / {max_iterations} ║
137
- ║ Tasks: {tasksCompleted} / {tasksTotal} complete ║
138
- ║ Failed: {tasksFailed} | Blocked: {tasksBlocked} ║
139
- ╠══════════════════════════════════════════════════════════════════╣
140
- ║ Ralph loop stopped due to iteration limit. ║
141
- ║ Remaining tasks: ║
142
- ║ {list of tasks with status != completed and != skipped} ║
143
- ╚══════════════════════════════════════════════════════════════════╝
144
-
70
+ MAX ITERATIONS REACHED: {iteration}/{max} | {completed}/{total} done
145
71
  -> Generating partial report...
146
72
  ```
73
+ Set `prd.status = 'partial'` → step-05.
147
74
 
148
- **Update prd.json:**
149
- ```javascript
150
- prd.status = 'partial';
151
- prd.updated_at = new Date().toISOString();
152
- writeJSON('.ralph/prd.json', prd);
153
- ```
75
+ ## 3. Check All Tasks Complete
154
76
 
155
- **Proceed to step-05-report.md**
77
+ If `allDone`:
156
78
 
157
- ### 3. Check All Tasks Complete
79
+ ### 3a. Team Mode (multi-module with Agent Teams)
158
80
 
159
- **If allDone = true:**
81
+ ```javascript
82
+ if ({team_active}) {
83
+ // Signal team lead that this module is done
84
+ SendMessage({
85
+ type: "message", recipient: "team-lead",
86
+ content: `MODULE_COMPLETE:${current_module}`,
87
+ summary: `${current_module} complete`
88
+ });
89
+ // STOP — team lead manages next module
90
+ return;
91
+ }
92
+ ```
160
93
 
161
- **First, check for multi-module queue:**
94
+ ### 3b. Sequential Multi-Module (modules-queue.json)
162
95
 
163
96
  ```javascript
164
97
  const queuePath = '.ralph/modules-queue.json';
165
- const hasQueue = fileExists(queuePath);
166
-
167
- if (hasQueue) {
98
+ if (fileExists(queuePath)) {
168
99
  const queue = readJSON(queuePath);
169
100
  const currentModule = queue.modules[queue.currentIndex];
170
101
 
171
- // ✅ FIX #4: MODULE COMPLETENESS CHECK (MANDATORY before advancing)
172
- // A module is NOT complete unless all expected layers have at least one completed task.
173
- // This prevents marking a module as "done" when only backend was implemented.
174
- const completedCategories = new Set(
175
- prd.tasks.filter(t => t.status === 'completed').map(t => t.category)
176
- );
177
- const expectedCategories = ['domain', 'infrastructure', 'application', 'api', 'frontend', 'test'];
178
- const missingCategories = expectedCategories.filter(c => !completedCategories.has(c));
179
-
180
- if (missingCategories.length > 0) {
181
- console.log(`
182
- ╔══════════════════════════════════════════════════════════════════╗
183
- ║ ⚠️ MODULE INCOMPLETE: Missing layers ║
184
- ╠══════════════════════════════════════════════════════════════════╣
185
- ║ Module: ${currentModule.code} ║
186
- ║ Missing: ${missingCategories.join(', ')} ║
187
- ╠══════════════════════════════════════════════════════════════════╣
188
- ║ Injecting guardrail tasks for missing layers... ║
189
- ╚══════════════════════════════════════════════════════════════════╝
190
- `);
191
-
192
- // Inject guardrail tasks for each missing category
193
- let maxId = Math.max(...prd.tasks.map(t => t.id));
194
- const lastCompletedByCategory = {};
195
- for (const task of prd.tasks) {
196
- if (task.status === 'completed') lastCompletedByCategory[task.category] = task.id;
197
- }
102
+ // MODULE COMPLETENESS CHECK: verify all expected layers
103
+ const completedCats = new Set(prd.tasks.filter(t => t.status === 'completed').map(t => t.category));
104
+ const expected = ['domain', 'infrastructure', 'application', 'api', 'frontend', 'test'];
105
+ const missing = expected.filter(c => !completedCats.has(c));
198
106
 
199
- for (const cat of missingCategories) {
107
+ if (missing.length > 0) {
108
+ // Inject guardrail tasks for missing layers
109
+ let maxId = Math.max(...prd.tasks.map(t => t.id));
110
+ for (const cat of missing) {
200
111
  maxId++;
201
- const depId = cat === 'frontend'
202
- ? (lastCompletedByCategory['api'] || lastCompletedByCategory['application'])
203
- : cat === 'test'
204
- ? (lastCompletedByCategory['api'] || lastCompletedByCategory['frontend'])
205
- : (lastCompletedByCategory['domain'] || lastCompletedByCategory['infrastructure']);
206
-
207
112
  prd.tasks.push({
208
- id: maxId,
209
- description: `[${cat}] GUARDRAIL: Generate missing ${cat} layer for module ${currentModule.code}`,
210
- status: 'pending',
211
- category: cat,
212
- dependencies: depId ? [depId] : [],
213
- acceptance_criteria: `${cat} layer fully implemented for module ${currentModule.code}`,
214
- started_at: null, completed_at: null, iteration: null, commit_hash: null,
215
- files_changed: { created: [], modified: [] },
113
+ id: maxId, description: `[${cat}] GUARDRAIL: Generate missing ${cat} for ${currentModule.code}`,
114
+ status: 'pending', category: cat, dependencies: [],
115
+ acceptance_criteria: `${cat} layer fully implemented`, started_at: null, completed_at: null,
116
+ iteration: null, commit_hash: null, files_changed: { created: [], modified: [] },
216
117
  validation: null, error: null, module: currentModule.code
217
118
  });
218
- console.log(` → Injected task ${maxId}: [${cat}] guardrail for ${currentModule.code}`);
219
119
  }
220
-
221
- prd.updated_at = new Date().toISOString();
222
120
  writeJSON('.ralph/prd.json', prd);
223
-
224
- // DO NOT mark module as complete — continue the COMPACT LOOP with new tasks
225
- // Fall through to section 5 (COMPACT LOOP)
121
+ // Fall through to section 5 (compact loop)
226
122
  } else {
123
+ // Module complete — advance
124
+ currentModule.status = 'completed';
125
+ queue.completedModules++;
126
+ const nextIndex = queue.currentIndex + 1;
127
+
128
+ if (nextIndex < queue.totalModules) {
129
+ queue.currentIndex = nextIndex;
130
+ queue.modules[nextIndex].status = 'in-progress';
131
+ writeJSON(queuePath, queue);
132
+
133
+ // Create transition marker
134
+ writeJSON('.ralph/module-changed.json', {
135
+ fromModule: currentModule.code, toModule: queue.modules[nextIndex].code,
136
+ timestamp: new Date().toISOString()
137
+ });
227
138
 
228
- // Mark current module as completed (only when ALL layers verified)
229
- currentModule.status = 'completed';
230
- queue.completedModules++;
231
-
232
- // Check if more modules remain
233
- const nextIndex = queue.currentIndex + 1;
139
+ // Load next module PRD
140
+ prd.status = 'completed';
141
+ writeJSON('.ralph/prd.json', prd);
142
+ const nextPrd = readJSON(queue.modules[nextIndex].prdFile);
143
+ nextPrd.config.current_iteration = 1;
144
+ nextPrd.config.max_iterations = prd.config.max_iterations;
145
+ writeJSON('.ralph/prd.json', nextPrd);
146
+
147
+ console.log(`MODULE COMPLETE: ${currentModule.code} → NEXT: ${queue.modules[nextIndex].code}`);
148
+ // → step-01 (module transition)
149
+ return;
150
+ }
234
151
 
235
- if (nextIndex < queue.totalModules) {
236
- // ADVANCE TO NEXT MODULE
237
- queue.currentIndex = nextIndex;
238
- queue.modules[nextIndex].status = 'in-progress';
152
+ // ALL MODULES COMPLETE
239
153
  writeJSON(queuePath, queue);
240
-
241
- // ✅ FIX #1: Create module transition marker
242
- // This signals to step-01 that it MUST reload even on iteration > 1
243
- writeJSON('.ralph/module-changed.json', {
244
- fromModule: currentModule.code,
245
- toModule: queue.modules[nextIndex].code,
246
- timestamp: new Date().toISOString()
247
- });
248
-
249
- // Mark current prd.json as completed
250
- prd.status = 'completed';
251
- prd.updated_at = new Date().toISOString();
252
- writeJSON('.ralph/prd.json', prd);
253
-
254
- // ✅ FIX #2: Load next module's PRD NOW and reset iteration counter
255
- const nextModulePrd = readJSON(queue.modules[nextIndex].prdFile);
256
- nextModulePrd.config.current_iteration = 1;
257
- nextModulePrd.config.max_iterations = prd.config.max_iterations; // Preserve
258
- nextModulePrd.updated_at = new Date().toISOString();
259
- writeJSON('.ralph/prd.json', nextModulePrd);
260
-
261
- console.log(`
262
- ╔══════════════════════════════════════════════════════════════════╗
263
- ║ ✅ MODULE COMPLETE: ${currentModule.code} ║
264
- ╠══════════════════════════════════════════════════════════════════╣
265
- ║ Tasks: ${tasksCompleted} completed, ${tasksSkipped} skipped ║
266
- ║ Modules: ${queue.completedModules} / ${queue.totalModules} ║
267
- ╠══════════════════════════════════════════════════════════════════╣
268
- ║ ADVANCING TO NEXT MODULE: ${queue.modules[nextIndex].code} ║
269
- ║ Next module PRD loaded: ${queue.modules[nextIndex].prdFile} ║
270
- ║ Iteration counter reset: 1 ║
271
- ╚══════════════════════════════════════════════════════════════════╝
272
- `);
273
-
274
- // Loop back to step-01 which will detect module-changed.json
275
- // and skip the "Only Read Once" rule for this transition
276
- // -> Proceed to step-01-task.md
277
- return;
154
+ console.log(`ALL ${queue.totalModules} MODULES COMPLETE`);
278
155
  }
279
-
280
- // ALL MODULES COMPLETE - fall through to completion below
281
- writeJSON(queuePath, queue);
282
-
283
- console.log(`
284
- ╔══════════════════════════════════════════════════════════════════╗
285
- ║ ✅ ALL MODULES COMPLETE ║
286
- ╠══════════════════════════════════════════════════════════════════╣
287
- ║ Modules: ${queue.completedModules} / ${queue.totalModules} ║
288
- ║ ${queue.modules.map(m => m.code + ": " + m.status).join("\n║ ")} ║
289
- ╚══════════════════════════════════════════════════════════════════╝
290
- `);
291
- } // end else (module completeness check passed)
292
156
  }
293
157
  ```
294
158
 
295
- **Then output completion (single module or all modules done):**
296
-
297
- ```
298
- ╔══════════════════════════════════════════════════════════════════╗
299
- ║ ✅ ALL TASKS COMPLETE ║
300
- ╠══════════════════════════════════════════════════════════════════╣
301
- ║ Iterations: {current_iteration - 1} ║
302
- ║ Tasks: {tasksCompleted} completed, {tasksSkipped} skipped ║
303
- ╠══════════════════════════════════════════════════════════════════╣
304
- ║ Output completion promise: ║
305
- ║ <promise>{completion_promise}</promise> ║
306
- ╚══════════════════════════════════════════════════════════════════╝
307
-
308
- <promise>{completion_promise}</promise>
309
- ```
310
-
311
- **Update prd.json:**
312
- ```javascript
313
- prd.status = 'completed';
314
- prd.updated_at = new Date().toISOString();
315
- writeJSON('.ralph/prd.json', prd);
316
- ```
159
+ ### 3c. Completion Output
317
160
 
318
- **CRITICAL: Output the promise tag exactly as shown:**
319
161
  ```
162
+ ALL TASKS COMPLETE | Iterations: {n} | Tasks: {completed}/{total}
320
163
  <promise>{completion_promise}</promise>
321
164
  ```
322
165
 
323
- **Proceed to step-05-report.md**
166
+ Set `prd.status = 'completed'` → step-05.
324
167
 
325
- ### 4. Check for Dead-End (all remaining are blocked/failed)
326
-
327
- **If !hasPending AND !allDone:**
328
-
329
- All remaining tasks are blocked or failed. No progress is possible.
168
+ ## 4. Dead-End Check
330
169
 
170
+ If `!hasPending && !allDone`: all remaining blocked/failed, no progress possible.
331
171
  ```
332
- ╔══════════════════════════════════════════════════════════════════╗
333
- ║ ⚠️ DEAD-END DETECTED ║
334
- ╠══════════════════════════════════════════════════════════════════╣
335
- ║ Tasks: {tasksCompleted} completed, {tasksFailed} failed, ║
336
- ║ {tasksBlocked} blocked ║
337
- ╠══════════════════════════════════════════════════════════════════╣
338
- ║ No more tasks can be executed. ║
339
- ║ Failed tasks: ║
340
- ║ {list of failed tasks with error messages} ║
341
- ║ ║
342
- ║ Blocked tasks (downstream): ║
343
- ║ {list of blocked tasks with dependency info} ║
344
- ╚══════════════════════════════════════════════════════════════════╝
345
-
346
- -> Generating partial report...
347
- ```
348
-
349
- **Update prd.json:**
350
- ```javascript
351
- prd.status = 'failed';
352
- prd.updated_at = new Date().toISOString();
353
- writeJSON('.ralph/prd.json', prd);
172
+ DEAD-END: {completed} done, {failed} failed, {blocked} blocked
354
173
  ```
174
+ Set `prd.status = 'failed'` → step-05.
355
175
 
356
- **Proceed to step-05-report.md**
357
-
358
- ### 5. More Tasks Remaining — COMPACT LOOP (CRITICAL)
359
-
360
- > **MANDATORY RULE: DO NOT STOP. DO NOT WAIT FOR USER INPUT. DO NOT RE-READ STEP FILES.**
361
- > After the first full iteration (step-01 → step-02 → step-03 → step-04), all subsequent iterations
362
- > MUST use this COMPACT LOOP inline. Re-reading step files wastes context and causes the loop to stall.
363
- > **STOPPING THE LOOP = BUG.** Only completion, max iterations, or dead-end stop the loop.
364
-
365
- **If hasPending AND iteration < max_iterations:**
366
-
367
- Display compact progress (ONE line):
368
- ```
369
- [{current_iteration}/{max_iterations}] {tasksCompleted}/{tasksTotal} done | Next: finding eligible task...
370
- ```
176
+ ## 5. Compact Loop (CRITICAL)
371
177
 
372
- **IMMEDIATELY execute the following inline loop DO NOT re-read step files:**
178
+ > **MANDATORY:** After first full iteration, ALL subsequent iterations use this inline loop.
179
+ > DO NOT stop. DO NOT wait for user. DO NOT re-read step files.
180
+ > **Read `references/compact-loop.md` and execute inline.**
373
181
 
374
- #### 5a. Find Next Eligible Task (inline step-01)
182
+ If `hasPending && iteration < max`:
375
183
 
376
- ```javascript
377
- const prd = readJSON('.ralph/prd.json');
378
-
379
- // Block tasks whose dependencies failed
380
- for (const task of prd.tasks) {
381
- if (task.status !== 'pending') continue;
382
- const depsBlocked = task.dependencies.some(depId => {
383
- const dep = prd.tasks.find(t => t.id === depId);
384
- return dep && (dep.status === 'failed' || dep.status === 'blocked');
385
- });
386
- if (depsBlocked) { task.status = 'blocked'; task.error = 'Blocked by failed dependency'; }
387
- }
388
-
389
- // Find ALL eligible tasks (dependencies met)
390
- const eligible = prd.tasks.filter(task => {
391
- if (task.status !== 'pending') return false;
392
- return task.dependencies.every(depId => {
393
- const dep = prd.tasks.find(t => t.id === depId);
394
- return dep && dep.status === 'completed';
395
- });
396
- });
397
-
398
- if (eligible.length === 0) {
399
- // Dead-end or all done — re-run sections 2-4 above
400
- goto CHECK_COMPLETION;
401
- }
402
-
403
- // BATCH MODE: group eligible tasks by category, take the first group
404
- const firstCategory = eligible[0].category;
405
- const batch = eligible.filter(t => t.category === firstCategory);
406
- // Cap batch at 5 tasks max to keep atomic
407
- const tasksToExecute = batch.slice(0, 5);
408
- ```
409
-
410
- Display:
411
- ```
412
- Batch: {tasksToExecute.length} task(s) [{firstCategory}]
413
- {tasksToExecute.map(t => `[${t.id}] ${t.description}`).join('\n ')}
414
- ```
415
-
416
- #### 5b. Execute Batch (inline step-02)
417
-
418
- **For EACH task in tasksToExecute:**
419
-
420
- 1. Mark `task.status = 'in_progress'`, `task.started_at = now`
421
- 2. ULTRA THINK: implement the task following SmartStack conventions
422
- - Track files_created and files_modified per task
423
- 3. **MANDATORY TEST-DRIVEN CYCLE (per task):**
424
- ```
425
- ┌─────────────────────────────────────────────────────────┐
426
- │ TASK EXECUTION CYCLE (100% tests pass required) │
427
- ├─────────────────────────────────────────────────────────┤
428
- │ │
429
- │ 1. GENERATE CODE │
430
- │ ├─ Backend: Entity, Service, Repository, Controller│
431
- │ ├─ Frontend: Page, Component, Hook │
432
- │ ├─ Tests: Unit tests + Integration tests │
433
- │ └─ Docs: Inline comments + tooltips + i18n │
434
- │ │
435
- │ 2. COMPILE CODE │
436
- │ ├─ Backend: dotnet build --no-restore │
437
- │ └─ Frontend: npm run typecheck │
438
- │ │
439
- │ 3. RUN TESTS (MANDATORY) │
440
- │ ├─ Backend: dotnet test {TestProject} │
441
- │ ├─ Frontend: npm test (if applicable) │
442
- │ └─ Security: tenant isolation + RBAC checks │
443
- │ │
444
- │ 4. CHECK RESULT │
445
- │ ├─ IF 100% PASS → Mark task completed, next task │
446
- │ └─ IF ANY FAIL → Go to step 5 │
447
- │ │
448
- │ 5. FIX ERRORS (loop until pass) │
449
- │ ├─ Parse test output → identify failing tests │
450
- │ ├─ Analyze root cause (stack trace, logs) │
451
- │ ├─ Fix code (NOT test - fix implementation) │
452
- │ ├─ Re-compile (step 2) │
453
- │ └─ Re-run tests (step 3) → loop until 100% pass │
454
- │ │
455
- │ 🎯 Goal: ZERO test failures before next task │
456
- │ 📊 Coverage: 95-100% (tests auto-generated per task) │
457
- │ │
458
- └─────────────────────────────────────────────────────────┘
459
- ```
460
-
461
- **Implementation per task:**
462
- a. Generate code + tests
463
- b. Compile: `dotnet build` or `npm run typecheck`
464
- c. Run tests: `dotnet test {TestProject}` or `npm test`
465
- d. Parse test output → count passed/failed/skipped
466
- e. IF failed > 0:
467
- - Log failure details to progress.txt
468
- - Analyze error (stack trace, assertion message)
469
- - Fix code (modify implementation, NOT test)
470
- - Re-compile
471
- - Re-run tests
472
- - Repeat until passed = total (100%)
473
- f. IF passed = total → task.status = 'completed'
474
-
475
- 4. Verify acceptance criteria
476
- 5. If task execution failed (not tests, but code generation): set `task.status = 'failed'`, `task.error = reason`, continue to next task in batch
477
-
478
- **CATEGORY-SPECIFIC EXECUTION RULES:**
479
-
480
- **IF category = "frontend":** Follow MCP-FIRST protocol (MANDATORY):
481
- 1. Call `mcp__smartstack__scaffold_api_client` → generates API client + types
482
- 2. Call `mcp__smartstack__scaffold_routes` → updates routes inside Layout wrapper
483
- 3. Create pages using SmartStack components (SmartTable, EntityCard, SmartForm, SmartFilter)
484
- 4. CSS variables ONLY (NO `bg-blue-600`, use `bg-[var(--color-accent-600)]`)
485
- 5. `EntityCard` for grids, `SmartTable` for lists (NO HTML `<table>` or custom `<div>` cards)
486
- 6. All pages MUST have loading/error/empty states
487
- 7. API client uses `@/services/api/apiClient` (NOT axios)
488
- 8. Generate 4-language i18n (fr, en, it, de)
489
- 9. `npm run typecheck` MUST pass
490
-
491
- **IF category = "domain":** Entities in `Domain/Entities/{ContextPascal}/{App}/{Module}/`, Enums in `Domain/Enums/{ContextPascal}/{App}/{Module}/`
492
-
493
- **IF category = "application":** Services in `Application/Services/{ContextPascal}/{App}/{Module}/`, DTOs in `Application/DTOs/{ContextPascal}/{App}/{Module}/`
494
-
495
- **IF category = "infrastructure":**
496
- - EF configs in `Infrastructure/Persistence/Configurations/{ContextPascal}/{App}/{Module}/`
497
- - Seed data in `Infrastructure/Persistence/Seeding/Data/{Module}/`
498
- - **IF task description contains "seed data", "SeedData", or "IClientSeedDataProvider":**
499
- Read `references/core-seed-data.md` for COMPLETE execution guidance (parameter extraction,
500
- MCP `generate_permissions` call, code templates, IClientSeedDataProvider, verification checklist).
501
- **Do NOT improvise core seed data generation.**
502
-
503
- **IF category = "api":** Controllers in `Api/Controllers/{ContextShort}/{App}/{Entity}Controller.cs`
504
-
505
- After ALL tasks in batch executed:
506
- - Run `mcp__smartstack__validate_conventions` ONCE for the whole batch
507
- - Quick build check: `dotnet build --no-restore` (backend) or `npm run typecheck` (frontend)
508
-
509
- #### 5c. Commit Batch (inline step-03)
510
-
511
- ```bash
512
- # Stage all changed files
513
- git add {all files from batch}
514
- git add .ralph/prd.json
515
-
516
- # Single commit for the batch
517
- git commit -m "$(cat <<'EOF'
518
- feat({scope}): [{firstCategory}] {tasksToExecute.length} tasks — {short summary}
519
-
520
- Tasks: {tasksToExecute.map(t => t.id).join(', ')} / {tasks_total}
521
- Iteration: {current_iteration}
522
- {current_module ? "Module: " + current_module : ""}
523
-
524
- Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
525
- EOF
526
- )"
527
-
528
- COMMIT_HASH=$(git rev-parse --short HEAD)
529
- ```
530
-
531
- **Finalize each task in prd.json:**
532
- ```javascript
533
- for (const task of tasksToExecute) {
534
- if (task.status !== 'failed') task.status = 'completed';
535
- task.completed_at = now;
536
- task.iteration = prd.config.current_iteration;
537
- task.commit_hash = COMMIT_HASH;
538
- }
539
- prd.history.push({
540
- iteration: prd.config.current_iteration,
541
- task_ids: tasksToExecute.map(t => t.id),
542
- action: 'batch-completed',
543
- timestamp: now,
544
- commit_hash: COMMIT_HASH,
545
- notes: "{What was accomplished}"
546
- });
547
- prd.config.current_iteration++;
548
- prd.updated_at = now;
549
- writeJSON('.ralph/prd.json', prd);
550
- ```
551
-
552
- ```bash
553
- git add .ralph/prd.json .ralph/progress.txt
554
- [ -f .ralph/modules-queue.json ] && git add .ralph/modules-queue.json
555
- git commit -m "chore(ralph): progress — iteration {current_iteration}"
556
- ```
557
-
558
- #### 5d. Re-check Completion (loop back to section 1)
559
-
560
- **IMMEDIATELY go back to section 1 (Read Current State) of THIS step.**
561
- **DO NOT stop. DO NOT wait for user. DO NOT re-read step files.**
562
-
563
- ---
564
-
565
- ## DECISION TREE:
566
-
567
- ```
568
- ┌─────────────────────┐
569
- │ Check Completion │
570
- └──────────┬──────────┘
571
-
572
- ┌────────────────────┼────────────────────┐
573
- │ │ │
574
- ▼ ▼ ▼
575
- ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
576
- │ Max Iters │ │ All Tasks │ │ Tasks │
577
- │ Reached │ │ Done │ │ Remaining │
578
- └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
579
- │ │ │
580
- │ ┌────────┴────────┐ ┌───────┴────────┐
581
- │ │ │ │ │
582
- ▼ ▼ ▼ ▼ ▼
583
- ┌────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
584
- │ Partial │ │ More modules│ │ No more │ │ Dead-End / │
585
- │ Report │ │ in queue? │ │ modules │ │ Loop to │
586
- │ step-05 │ │ → step-01 │ │ → Promise │ │ step-01 │
587
- │ status: │ │ (next mod) │ │ → step-05 │ │ │
588
- │ "partial" │ └─────────────┘ └─────────────┘ └─────────────┘
589
- └────────────┘
590
- ```
591
-
592
- ---
593
-
594
- ## OUTPUT FORMAT:
595
-
596
- **If continuing:**
597
- ```
598
- Completion Check:
599
-
600
- | Field | Value |
601
- |-------|-------|
602
- | Iteration | {current_iteration} / {max_iterations} |
603
- | Completed | {tasksCompleted} / {tasksTotal} |
604
- | Failed | {tasksFailed} |
605
- | Blocked | {tasksBlocked} |
606
- | Pending | {tasksPending} |
607
- | Status | Continuing |
608
-
609
- -> Loading next task...
610
- ```
611
-
612
- **If complete:**
613
- ```
614
- Completion Check:
615
-
616
- | Field | Value |
617
- |-------|-------|
618
- | Iterations Used | {current_iteration - 1} |
619
- | Completed | {tasksCompleted} / {tasksTotal} |
620
- | Skipped | {tasksSkipped} |
621
- | Status | COMPLETE |
622
-
623
- <promise>{completion_promise}</promise>
624
-
625
- -> Generating report...
626
- ```
627
-
628
- **If partial/failed:**
629
- ```
630
- Completion Check:
631
-
632
- | Field | Value |
633
- |-------|-------|
634
- | Iterations Used | {current_iteration - 1} |
635
- | Completed | {tasksCompleted} / {tasksTotal} |
636
- | Failed | {tasksFailed} |
637
- | Blocked | {tasksBlocked} |
638
- | Status | {PARTIAL or FAILED} |
639
- | Reason | {max iterations / dead-end} |
640
-
641
- -> Generating report...
642
- ```
184
+ 1. Read `references/compact-loop.md`
185
+ 2. Execute sections A → B → C → D inline
186
+ 3. Return to section 1 of THIS step
643
187
 
644
188
  ---
645
189
 
646
190
  ## CRITICAL RULES:
647
191
 
648
- **NEVER output the completion promise unless:**
649
- 1. ALL tasks have `status: "completed"` or `status: "skipped"`
650
- 2. Zero tasks with `status: "blocked"` or `status: "failed"`
651
- 3. The statement is genuinely true
652
- 4. **Multi-module:** ALL modules in `modules-queue.json` have `status: "completed"`
653
-
654
- **False promises to escape the loop are FORBIDDEN.**
655
-
656
- **Always update `prd.status` and `prd.updated_at` before proceeding.**
657
-
658
- **NEVER DELEGATE THE LOOP:**
659
- - NEVER use the Task tool to spawn a sub-agent for Ralph loop execution.
660
- - Sub-agents lose ALL skill context and WILL stop prematurely.
661
- - The ONLY acceptable Task usage: isolated read-only research (e.g., Context7 docs lookup).
662
-
663
- **MODULE COMPLETENESS (multi-module):**
664
- - Before advancing to the next module, verify ALL expected layers have completed tasks.
665
- - Expected layers: domain, infrastructure, application, api, frontend, test.
666
- - If any layer is missing, inject guardrail tasks and continue the COMPACT LOOP.
667
- - A module with only backend tasks is NOT complete.
668
-
669
- **LOOP CONTINUATION IS MANDATORY:**
670
- - After the first full iteration (step-01→02→03→04), ALL subsequent iterations use the COMPACT LOOP in section 5.
671
- - DO NOT re-read step-01, step-02, step-03 files. You already know the instructions.
672
- - DO NOT stop and wait for user input between iterations.
673
- - DO NOT output a summary and pause. The loop is AUTONOMOUS.
674
- - DO NOT decide to stop because "quality over quantity" or "this is enough for now".
675
- - DO NOT stop after completing one module when others remain in the queue.
676
- - DO NOT reduce scope autonomously ("I'll skip frontend/tests to save time").
677
- - The ONLY reasons to stop: ALL tasks complete (all modules), max iterations, dead-end, or user Ctrl+C.
678
- - Stopping for any other reason is a **BUG** that wastes user time and context.
679
- - **BATCH tasks of the same category** to reduce iterations (max 5 per batch).
680
- - Prefer compact output (1-2 lines per task) over verbose output during the loop.
192
+ - **NEVER** output completion promise unless ALL tasks done (all modules if multi)
193
+ - **NEVER** delegate the loop to sub-agents (except team mode for multi-module)
194
+ - **NEVER** stop between iterations
195
+ - **BATCH** same-category tasks (max 5)
196
+ - **MODULE COMPLETENESS:** All layers must have completed tasks before advancing
197
+ - Only valid stop: all complete, max iterations, dead-end, or user Ctrl+C
681
198
 
682
199
  ---
683
200
 
684
201
  ## NEXT STEP:
685
202
 
686
- - If all tasks complete AND more modules in queue: `./step-01-task.md` (next module)
687
- - If all tasks complete AND no more modules (or no queue): `./step-05-report.md`
688
- - If max iterations or dead-end: `./step-05-report.md`
689
- - If tasks remaining in current module: `./step-01-task.md`
203
+ - All done + more modules in queue `./step-01-task.md`
204
+ - All done (no more modules) `./step-05-report.md`
205
+ - Max iterations or dead-end `./step-05-report.md`
206
+ - Tasks remaining compact loop (section 5)