@atlashub/smartstack-cli 3.1.0 → 3.2.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.
@@ -10,27 +10,38 @@ Execute the Ralph Weegund technique - an iterative development methodology where
10
10
  </objective>
11
11
 
12
12
  <quick_start>
13
- **Basic usage:**
14
-
15
- ```bash
16
- /ralph-loop implement user authentication
17
- ```
18
-
19
- **With completion promise:**
13
+ **Three ways to start Ralph Loop:**
14
+
15
+ 1. **From Business Analysis (RECOMMENDED - NEW v6.1):**
16
+ ```bash
17
+ /business-analyse MyFeature
18
+ # At the end, choose "Ralph Loop" → automatic launch
19
+ # No arguments needed - prd.json already generated
20
+ ```
21
+
22
+ 2. **Manual start with existing prd.json:**
23
+ ```bash
24
+ /ralph-loop
25
+ # Ralph detects .ralph/prd.json and resumes automatically
26
+ # Works after BA handoff or previous Ralph session
27
+ ```
28
+
29
+ 3. **Direct task (no BA):**
30
+ ```bash
31
+ /ralph-loop implement user authentication
32
+ # Ralph creates prd.json on the fly
33
+ ```
34
+
35
+ **With options:**
20
36
 
21
37
  ```bash
38
+ # Completion promise
22
39
  /ralph-loop -c "COMPLETE" refactor the cache layer
23
- ```
24
40
 
25
- **With max iterations:**
26
-
27
- ```bash
41
+ # Max iterations
28
42
  /ralph-loop -m 20 -c "TESTS PASS" add comprehensive tests
29
- ```
30
43
 
31
- **Verbose mode:**
32
-
33
- ```bash
44
+ # Verbose mode
34
45
  /ralph-loop -v -c "DONE" fix all linting errors
35
46
  ```
36
47
 
@@ -39,6 +50,7 @@ Execute the Ralph Weegund technique - an iterative development methodology where
39
50
  - `-m N` (max): Maximum iterations before auto-stop
40
51
  - `-c TEXT` (complete): Completion promise text
41
52
  - `-v` (verbose): Detailed logging
53
+ - `-r` (resume): Resume from previous state
42
54
 
43
55
  See `<parameters>` for complete flag list.
44
56
  </quick_start>
@@ -99,12 +111,75 @@ The same prompt is fed to Claude repeatedly. The "self-referential" aspect comes
99
111
  5. Claude sees previous work in the files
100
112
  6. Iteratively improves until completion promise is output
101
113
 
114
+ **Iterative Development Cycle (per task):**
115
+ ```
116
+ ┌─────────────────────────────────────────────────────────────┐
117
+ │ RALPH LOOP - CYCLE │
118
+ ├─────────────────────────────────────────────────────────────┤
119
+ │ │
120
+ │ 1. ANALYSE → Load next task from prd.json │
121
+ │ (UC, FR, BR, wireframes, acceptance) │
122
+ │ │
123
+ │ 2. DÉVELOPPEMENT → Generate code for task │
124
+ │ ├─ Backend: Entity, Service, Repository, Controller │
125
+ │ ├─ Tests: Unit tests (xUnit) + non-regression │
126
+ │ ├─ Frontend: Page, Component, Hook (match wireframe) │
127
+ │ ├─ Tests: Frontend tests (React Testing Library) │
128
+ │ ├─ SeedData: CORE RBAC (5 entries) + business data │
129
+ │ └─ Docs: Inline comments + tooltips + i18n keys │
130
+ │ │
131
+ │ 3. VALIDATION → Commit changes + MCP conventions check │
132
+ │ (validate_conventions, check_migrations) │
133
+ │ │
134
+ │ 4. TEST → Run tests (dotnet test + npm test) │
135
+ │ ├─ Unit tests │
136
+ │ ├─ Integration tests │
137
+ │ ├─ Security tests (tenant isolation) │
138
+ │ └─ E2E tests (critical flows) │
139
+ │ │
140
+ │ 5. CORRECTION → If tests fail: │
141
+ │ ├─ Analyze error logs │
142
+ │ ├─ Fix root cause │
143
+ │ ├─ Commit fix │
144
+ │ └─ Return to step 4 │
145
+ │ │
146
+ │ 6. NEXT TASK → Mark task as completed, loop to step 1 │
147
+ │ │
148
+ │ 🎯 Goal: 100% tests pass before moving to next task │
149
+ │ 📊 Coverage: 95-100% (tests auto-generated) │
150
+ │ │
151
+ └─────────────────────────────────────────────────────────────┘
152
+ ```
153
+
102
154
  **Completion signal:**
103
155
  ```
104
156
  <promise>{completion_promise}</promise>
105
157
  ```
106
158
 
107
159
  The loop only stops when this exact tag is output or max iterations reached.
160
+
161
+ **What Ralph generates per task:**
162
+ - **Backend code**: Entities (Domain), Services (Application), Repositories (Infrastructure), Controllers (API)
163
+ - **Unit tests**: xUnit tests for domain logic, services, repositories
164
+ - **Integration tests**: Controller tests with WebApplicationFactory
165
+ - **Frontend code**: React pages, components, custom hooks (matching BA wireframes)
166
+ - **Frontend tests**: React Testing Library for components and pages
167
+ - **SeedData**: 5 CORE entries (Navigation, Permissions, Roles, Tenants, Users) + business reference data
168
+ - **Documentation**: Inline code comments, user-facing tooltips, i18n translation keys
169
+ - **Security tests**: Tenant isolation, permission checks, OWASP validations
170
+
171
+ **prd.json structure (input from BA):**
172
+ The prd.json is generated by `/business-analyse` via `ss derive-prd` command. It contains:
173
+ - **feature**: Feature description (from BA)
174
+ - **tasks[]**: Task breakdown by category (domain, application, infrastructure, api, frontend, i18n, test, validation)
175
+ - Each task has: id, description, category, dependencies, acceptance_criteria, linkedFRs, linkedUCs, linkedBRs
176
+ - Frontend tasks include: linkedWireframes (screen IDs from BA mockups), wireframeAcceptanceCriteria
177
+ - SeedData tasks specify: category (core|business), source (specification.seedDataCore or seedDataBusiness)
178
+ - **source**: Traceability to feature.json path (source of truth)
179
+ - **metadata**: Project context (branch, namespace, module order)
180
+ - **config**: max_iterations, completion_promise, current_iteration
181
+
182
+ Ralph reads prd.json to know WHAT to generate, then generates it, tests it, fixes it, and moves to the next task.
108
183
  </ralph_concept>
109
184
 
110
185
  <workflow>
@@ -118,19 +193,62 @@ The loop only stops when this exact tag is output or max iterations reached.
118
193
  7. Check completion → enter COMPACT LOOP (step-04)
119
194
  8. **COMPACT LOOP** (step-04 section 5, NO re-reading step files):
120
195
  - Find eligible tasks → batch by category (max 5)
121
- - Execute batch inline
122
- - Commit batch
196
+ - Execute batch inline (generate code)
197
+ - Run tests (dotnet test + npm test)
198
+ - If tests fail: analyze → fix → re-test (loop until 100% pass)
199
+ - Commit batch (only when tests pass)
123
200
  - Re-check completion → loop or finish
124
201
  9. When complete: generate final report (step-05)
125
202
 
126
- **Multi-module flow (from BA handoff):**
127
- 1-3. Same as standard flow
203
+ **Multi-module flow (from BA handoff - NEW v6.1: automatic launch):**
204
+ 1-3. Same as standard flow (or launched automatically from `/business-analyse`)
128
205
  4. Detect `prd-*.json` files → create `modules-queue.json`
129
206
  5. Copy current module's prd to `prd.json`
130
- 6. Execute all tasks for current module via COMPACT LOOP
207
+ 6. Execute all tasks for current module via COMPACT LOOP:
208
+ - Process tasks by category (domain → seeddata → application → infrastructure → api → frontend → i18n → tests)
209
+ - For each task: generate → test → fix (if needed) → re-test → commit (when pass)
210
+ - Each task generates: backend code + tests + frontend code + tests + seeddata + docs
211
+ - Each frontend task respects wireframes from BA (specification.uiWireframes[])
212
+ - Continue until ALL tasks of module = completed
131
213
  7. When module complete: advance to next module in queue (step-04 section 3)
132
214
  8. Repeat steps 5-7 for each module (step-01 is re-read ONLY for module transitions)
133
215
  9. When all modules done: generate cross-module report
216
+
217
+ **Note:** When launched from `/business-analyse` (v6.1+), Ralph Loop receives:
218
+ - `.ralph/prd-{module}.json` for each module (generated by `ss derive-prd`)
219
+ - Each prd contains: tasks breakdown with UC/FR/BR/wireframes/acceptance criteria
220
+ - Task categories: domain, application, infrastructure, api, frontend, i18n, test, validation
221
+ - Each task linked to: functional requirements (FR), use cases (UC), business rules (BR)
222
+ - Frontend tasks include: linkedWireframes[] (screen IDs from BA mockups)
223
+ - SeedData tasks specify: category (core 5 entries MANDATORY + business data)
224
+ - `.ralph/progress.txt` with comprehensive task tracker (hierarchical: module → layer → tasks)
225
+ - Module order from BA's topological dependency graph (dependencies first)
226
+ - No arguments needed - fully configured by BA handoff
227
+
228
+ **Task execution cycle (per task):**
229
+ ```
230
+ LOAD TASK → GENERATE CODE → COMMIT → RUN TESTS → [FAIL?] → ANALYZE ERROR → FIX → RE-TEST → [PASS!] → NEXT TASK
231
+ ↑___________________________________________|
232
+ (loop until 100% tests pass)
233
+ ```
234
+
235
+ **What gets generated per module:**
236
+ 1. **Domain layer**: Entities, Value Objects, Enums, Domain Exceptions
237
+ 2. **SeedData layer**: 5 CORE entries (Navigation, Permissions, Roles, Tenants, Users) + business reference data
238
+ 3. **Application layer**: Services, DTOs, Validators, Query Handlers
239
+ 4. **Infrastructure layer**: Repositories, DbContext, Specifications
240
+ 5. **API layer**: Controllers, Error Handlers, Validation Responses
241
+ 6. **Frontend layer**: Pages (matching wireframes), Components, Custom Hooks, Forms
242
+ 7. **I18n layer**: Translation keys (fr, en, it, de) for UI labels
243
+ 8. **Tests layer**: Unit tests (Domain, Application), Integration tests (API), Security tests (tenant isolation), E2E tests (critical flows)
244
+
245
+ **Acceptance criteria per task:**
246
+ - Code compiles (dotnet build + npm build)
247
+ - Tests pass (dotnet test + npm test)
248
+ - MCP conventions validated (validate_conventions)
249
+ - Wireframes respected (frontend pages match BA mockups from specification.uiWireframes[])
250
+ - Business rules implemented (BR-to-code mapping from BA)
251
+ - Security enforced (tenant isolation, RBAC permissions)
134
252
  </workflow>
135
253
 
136
254
  <state_variables>
@@ -6,11 +6,35 @@ next_step: steps/step-02-execute.md
6
6
 
7
7
  # Step 1: Load Task
8
8
 
9
- > **CONTEXT OPTIMIZATION:** This file is only read ONCE (first iteration).
9
+ > **MODULE TRANSITION CHECK (MANDATORY):**
10
+ > Before applying the "Only Read Once" rule, check for module transition marker:
11
+
12
+ ```javascript
13
+ const moduleChangedPath = '.ralph/module-changed.json';
14
+ const moduleTransition = fileExists(moduleChangedPath);
15
+
16
+ if (moduleTransition) {
17
+ const transitionData = readJSON(moduleChangedPath);
18
+ console.log(`🔄 Module transition detected: ${transitionData.fromModule} → ${transitionData.toModule}`);
19
+ console.log(` Reloading step-01 to initialize new module...`);
20
+
21
+ // Delete flag (consume it)
22
+ deleteFile(moduleChangedPath);
23
+
24
+ // PROCEED with step-01 execution (skip "Only Read Once" rule below)
25
+ // This is the EXCEPTION case for multi-module workflows
26
+ }
27
+ ```
28
+
29
+ > **CONTEXT OPTIMIZATION:** This file is normally read ONCE per module (first iteration).
10
30
  > After the first full iteration (step-01 → step-02 → step-03 → step-04),
11
- > ALL subsequent iterations MUST use the COMPACT LOOP in step-04-check.md section 5.
12
- > **DO NOT re-read this file for iterations > 1.**
13
- > If you are re-reading this file on iteration > 1, STOP and go to step-04 section 5 instead.
31
+ > ALL subsequent iterations within the SAME module MUST use the COMPACT LOOP in step-04-check.md section 5.
32
+ > **DO NOT re-read this file for iterations > 1 of the same module.**
33
+ >
34
+ > **EXCEPTION:** When transitioning between modules (multi-module workflows), step-01 MUST be re-read
35
+ > to load the next module's PRD. This is signaled by `.ralph/module-changed.json` file (checked above).
36
+ >
37
+ > If you are re-reading this file on iteration > 1 AND no module transition detected, STOP and go to step-04 section 5 instead.
14
38
 
15
39
  ## YOUR TASK:
16
40
 
@@ -24,7 +48,10 @@ Load the current task from prd.json or create initial task breakdown with catego
24
48
 
25
49
  ### 0. Multi-Module Queue Check
26
50
 
27
- **Before any other logic, check for modules-queue.json:**
51
+ **✅ ALWAYS check for modules-queue.json, even on iteration > 1:**
52
+
53
+ > **CRITICAL:** This section MUST execute even when step-01 is re-read for module transitions.
54
+ > The module-changed.json flag (checked above) ensures this section runs when needed.
28
55
 
29
56
  ```javascript
30
57
  const queuePath = '.ralph/modules-queue.json';
@@ -34,22 +61,52 @@ if (hasQueue) {
34
61
  const queue = readJSON(queuePath);
35
62
  const currentModule = queue.modules[queue.currentIndex];
36
63
 
37
- console.log(`Module ${queue.currentIndex + 1}/${queue.totalModules}: ${currentModule.code}`);
38
-
39
- // Copy current module's prd file to prd.json (overwrite)
40
- const modulePrd = readJSON(currentModule.prdFile);
41
-
42
- // Transform PrdJson format to Ralph v2 if needed
43
- if (modulePrd.project && modulePrd.requirements && !modulePrd.$version) {
44
- // This is a PrdJson format from ss derive-prd → transform to Ralph v2
45
- const transformedPrd = transformPrdJsonToRalphV2(modulePrd, currentModule.code);
46
- writeJSON('.ralph/prd.json', transformedPrd);
64
+ console.log(`
65
+ ╔══════════════════════════════════════════════════════════════════╗
66
+ Multi-Module Workflow Detected ║
67
+ ╠══════════════════════════════════════════════════════════════════╣
68
+ ║ Current Module: ${currentModule.code} (${queue.currentIndex + 1}/${queue.totalModules}) ║
69
+ Status: ${currentModule.status} ║
70
+ PRD File: ${currentModule.prdFile} ║
71
+ ╚══════════════════════════════════════════════════════════════════╝
72
+ `);
73
+
74
+ // ✅ FIX #3: RESTORE multi-module state variables
75
+ // These variables persist across step files and are critical for multi-module coordination
76
+ {modules_queue} = queue;
77
+ {current_module} = currentModule.code;
78
+
79
+ // ✅ Load or verify current module's PRD is in .ralph/prd.json
80
+ // On module transition, step-04 already loaded it, but we verify here
81
+ const currentPrd = readJSON('.ralph/prd.json');
82
+
83
+ // Verify PRD matches current module (sanity check)
84
+ if (currentPrd.metadata && currentPrd.metadata.moduleCode !== currentModule.code) {
85
+ console.log(`⚠️ PRD mismatch detected. Loading correct PRD for module ${currentModule.code}...`);
86
+
87
+ // Load current module's PRD
88
+ const modulePrd = readJSON(currentModule.prdFile);
89
+
90
+ // Transform PrdJson format to Ralph v2 if needed
91
+ if (modulePrd.project && modulePrd.requirements && !modulePrd.$version) {
92
+ // This is a PrdJson format from ss derive-prd → transform to Ralph v2
93
+ const transformedPrd = transformPrdJsonToRalphV2(modulePrd, currentModule.code);
94
+ writeJSON('.ralph/prd.json', transformedPrd);
95
+ console.log(`✅ Transformed and loaded PRD for module: ${currentModule.code}`);
96
+ } else {
97
+ // Already Ralph v2 format
98
+ writeJSON('.ralph/prd.json', modulePrd);
99
+ console.log(`✅ Loaded PRD for module: ${currentModule.code}`);
100
+ }
47
101
  } else {
48
- // Already Ralph v2 format
49
- writeJSON('.ralph/prd.json', modulePrd);
102
+ console.log(`✅ PRD already loaded for module: ${currentModule.code}`);
50
103
  }
51
104
 
52
- console.log(`Loaded PRD for module: ${currentModule.code}`);
105
+ console.log(`State restored: modules_queue and current_module set`);
106
+ } else {
107
+ // Single-module workflow
108
+ {modules_queue} = null;
109
+ {current_module} = null;
53
110
  }
54
111
  ```
55
112
 
@@ -181,13 +181,25 @@ if (hasQueue) {
181
181
  queue.modules[nextIndex].status = 'in-progress';
182
182
  writeJSON(queuePath, queue);
183
183
 
184
+ // ✅ FIX #1: Create module transition marker
185
+ // This signals to step-01 that it MUST reload even on iteration > 1
186
+ writeJSON('.ralph/module-changed.json', {
187
+ fromModule: currentModule.code,
188
+ toModule: queue.modules[nextIndex].code,
189
+ timestamp: new Date().toISOString()
190
+ });
191
+
184
192
  // Mark current prd.json as completed
185
193
  prd.status = 'completed';
186
194
  prd.updated_at = new Date().toISOString();
187
195
  writeJSON('.ralph/prd.json', prd);
188
196
 
189
- // Reset iteration counter for next module
190
- // (preserve max_iterations from config)
197
+ // FIX #2: Load next module's PRD NOW and reset iteration counter
198
+ const nextModulePrd = readJSON(queue.modules[nextIndex].prdFile);
199
+ nextModulePrd.config.current_iteration = 1;
200
+ nextModulePrd.config.max_iterations = prd.config.max_iterations; // Preserve
201
+ nextModulePrd.updated_at = new Date().toISOString();
202
+ writeJSON('.ralph/prd.json', nextModulePrd);
191
203
 
192
204
  console.log(`
193
205
  ╔══════════════════════════════════════════════════════════════════╗
@@ -197,10 +209,13 @@ if (hasQueue) {
197
209
  ║ Modules: ${queue.completedModules} / ${queue.totalModules} ║
198
210
  ╠══════════════════════════════════════════════════════════════════╣
199
211
  ║ ADVANCING TO NEXT MODULE: ${queue.modules[nextIndex].code} ║
212
+ ║ Next module PRD loaded: ${queue.modules[nextIndex].prdFile} ║
213
+ ║ Iteration counter reset: 1 ║
200
214
  ╚══════════════════════════════════════════════════════════════════╝
201
215
  `);
202
216
 
203
- // Loop back to step-01 which will load next module's prd
217
+ // Loop back to step-01 which will detect module-changed.json
218
+ // and skip the "Only Read Once" rule for this transition
204
219
  // -> Proceed to step-01-task.md
205
220
  return;
206
221
  }
@@ -347,8 +362,60 @@ Batch: {tasksToExecute.length} task(s) [{firstCategory}]
347
362
  1. Mark `task.status = 'in_progress'`, `task.started_at = now`
348
363
  2. ULTRA THINK: implement the task following SmartStack conventions
349
364
  - Track files_created and files_modified per task
350
- 3. Verify acceptance criteria
351
- 4. If failed: set `task.status = 'failed'`, `task.error = reason`, continue to next task in batch
365
+ 3. **MANDATORY TEST-DRIVEN CYCLE (per task):**
366
+ ```
367
+ ┌─────────────────────────────────────────────────────────┐
368
+ │ TASK EXECUTION CYCLE (100% tests pass required) │
369
+ ├─────────────────────────────────────────────────────────┤
370
+ │ │
371
+ │ 1. GENERATE CODE │
372
+ │ ├─ Backend: Entity, Service, Repository, Controller│
373
+ │ ├─ Frontend: Page, Component, Hook │
374
+ │ ├─ Tests: Unit tests + Integration tests │
375
+ │ └─ Docs: Inline comments + tooltips + i18n │
376
+ │ │
377
+ │ 2. COMPILE CODE │
378
+ │ ├─ Backend: dotnet build --no-restore │
379
+ │ └─ Frontend: npm run typecheck │
380
+ │ │
381
+ │ 3. RUN TESTS (MANDATORY) │
382
+ │ ├─ Backend: dotnet test {TestProject} │
383
+ │ ├─ Frontend: npm test (if applicable) │
384
+ │ └─ Security: tenant isolation + RBAC checks │
385
+ │ │
386
+ │ 4. CHECK RESULT │
387
+ │ ├─ IF 100% PASS → Mark task completed, next task │
388
+ │ └─ IF ANY FAIL → Go to step 5 │
389
+ │ │
390
+ │ 5. FIX ERRORS (loop until pass) │
391
+ │ ├─ Parse test output → identify failing tests │
392
+ │ ├─ Analyze root cause (stack trace, logs) │
393
+ │ ├─ Fix code (NOT test - fix implementation) │
394
+ │ ├─ Re-compile (step 2) │
395
+ │ └─ Re-run tests (step 3) → loop until 100% pass │
396
+ │ │
397
+ │ 🎯 Goal: ZERO test failures before next task │
398
+ │ 📊 Coverage: 95-100% (tests auto-generated per task) │
399
+ │ │
400
+ └─────────────────────────────────────────────────────────┘
401
+ ```
402
+
403
+ **Implementation per task:**
404
+ a. Generate code + tests
405
+ b. Compile: `dotnet build` or `npm run typecheck`
406
+ c. Run tests: `dotnet test {TestProject}` or `npm test`
407
+ d. Parse test output → count passed/failed/skipped
408
+ e. IF failed > 0:
409
+ - Log failure details to progress.txt
410
+ - Analyze error (stack trace, assertion message)
411
+ - Fix code (modify implementation, NOT test)
412
+ - Re-compile
413
+ - Re-run tests
414
+ - Repeat until passed = total (100%)
415
+ f. IF passed = total → task.status = 'completed'
416
+
417
+ 4. Verify acceptance criteria
418
+ 5. If task execution failed (not tests, but code generation): set `task.status = 'failed'`, `task.error = reason`, continue to next task in batch
352
419
 
353
420
  **CATEGORY-SPECIFIC EXECUTION RULES:**
354
421