@atlashub/smartstack-cli 4.18.0 → 4.19.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 (160) hide show
  1. package/package.json +1 -1
  2. package/templates/agents/ba-reader.md +86 -80
  3. package/templates/agents/ba-writer.md +318 -415
  4. package/templates/agents/docs-context-reader.md +3 -3
  5. package/templates/mcp-scaffolding/frontend/nav-routes.ts.hbs +133 -0
  6. package/templates/mcp-scaffolding/frontend/routes.tsx.hbs +126 -0
  7. package/templates/skills/apex/SKILL.md +29 -16
  8. package/templates/skills/apex/_shared.md +62 -9
  9. package/templates/skills/apex/references/analysis-methods.md +8 -6
  10. package/templates/skills/apex/references/challenge-questions.md +5 -5
  11. package/templates/skills/apex/references/core-seed-data.md +68 -45
  12. package/templates/skills/apex/references/frontend-route-wiring-app-tsx.md +26 -21
  13. package/templates/skills/apex/references/parallel-execution.md +156 -0
  14. package/templates/skills/apex/references/person-extension-pattern.md +12 -12
  15. package/templates/skills/apex/references/post-checks.md +1748 -1726
  16. package/templates/skills/apex/references/smartstack-api.md +63 -57
  17. package/templates/skills/apex/references/smartstack-frontend-compliance.md +594 -0
  18. package/templates/skills/apex/references/smartstack-frontend.md +1246 -1842
  19. package/templates/skills/apex/references/smartstack-layers.md +98 -145
  20. package/templates/skills/apex/steps/step-00-init.md +30 -6
  21. package/templates/skills/apex/steps/step-01-analyze.md +27 -23
  22. package/templates/skills/apex/steps/step-02-plan.md +12 -12
  23. package/templates/skills/apex/steps/step-03-execute.md +198 -143
  24. package/templates/skills/apex/steps/step-04-examine.md +24 -93
  25. package/templates/skills/apex/steps/step-05-deep-review.md +16 -16
  26. package/templates/skills/apex/steps/step-06-resolve.md +9 -9
  27. package/templates/skills/apex/steps/step-07-tests.md +3 -1
  28. package/templates/skills/apex/steps/step-08-run-tests.md +1 -1
  29. package/templates/skills/business-analyse/SKILL.md +182 -301
  30. package/templates/skills/business-analyse/_shared.md +119 -336
  31. package/templates/skills/business-analyse/html/ba-interactive.html +703 -82
  32. package/templates/skills/business-analyse/html/build-html.js +41 -3
  33. package/templates/skills/business-analyse/html/src/partials/cadrage-context.html +34 -0
  34. package/templates/skills/business-analyse/html/src/partials/cadrage-risks.html +48 -0
  35. package/templates/skills/business-analyse/html/src/partials/cadrage-scope.html +49 -0
  36. package/templates/skills/business-analyse/html/src/partials/cadrage-stakeholders.html +55 -0
  37. package/templates/skills/business-analyse/html/src/partials/cadrage-success.html +34 -0
  38. package/templates/skills/business-analyse/html/src/partials/consol-datamodel.html +8 -0
  39. package/templates/skills/business-analyse/html/src/partials/consol-flows.html +29 -0
  40. package/templates/skills/business-analyse/html/src/partials/consol-interactions.html +8 -0
  41. package/templates/skills/business-analyse/html/src/partials/consol-permissions.html +8 -0
  42. package/templates/skills/business-analyse/html/src/partials/decomp-dependencies.html +38 -0
  43. package/templates/skills/business-analyse/html/src/partials/decomp-modules.html +51 -0
  44. package/templates/skills/business-analyse/html/src/partials/handoff-summary.html +24 -0
  45. package/templates/skills/business-analyse/html/src/partials/module-spec-container.html +4 -0
  46. package/templates/skills/business-analyse/html/src/scripts/01-data-init.js +17 -1
  47. package/templates/skills/business-analyse/html/src/scripts/02-navigation.js +31 -5
  48. package/templates/skills/business-analyse/html/src/scripts/05-render-specs.js +100 -63
  49. package/templates/skills/business-analyse/html/src/scripts/06-render-mockups.js +372 -0
  50. package/templates/skills/business-analyse/html/src/scripts/10-comments.js +41 -13
  51. package/templates/skills/business-analyse/html/src/styles/09-mockups-html.css +136 -0
  52. package/templates/skills/business-analyse/patterns/suggestion-catalog.md +7 -5
  53. package/templates/skills/business-analyse/questionnaire/02-stakeholders-scope.md +142 -0
  54. package/templates/skills/business-analyse/questionnaire/03-data-ui.md +94 -0
  55. package/templates/skills/business-analyse/questionnaire/04-risks-metrics.md +150 -0
  56. package/templates/skills/business-analyse/questionnaire/05-cross-module.md +69 -0
  57. package/templates/skills/business-analyse/questionnaire.md +23 -280
  58. package/templates/skills/business-analyse/react/application-viewer.md +2 -2
  59. package/templates/skills/business-analyse/react/components.md +4 -4
  60. package/templates/skills/business-analyse/react/i18n-template.md +1 -1
  61. package/templates/skills/business-analyse/react/schema.md +14 -14
  62. package/templates/skills/business-analyse/references/acceptance-criteria.md +21 -21
  63. package/templates/skills/business-analyse/references/analysis-semantic-checks.md +3 -3
  64. package/templates/skills/business-analyse/references/compilation-structure-cards.md +1 -1
  65. package/templates/skills/business-analyse/references/consolidation-structural-checks.md +5 -5
  66. package/templates/skills/business-analyse/references/deploy-data-build.md +12 -11
  67. package/templates/skills/business-analyse/references/deploy-modes.md +10 -10
  68. package/templates/skills/business-analyse/references/detection-strategies.md +6 -6
  69. package/templates/skills/business-analyse/references/html-data-mapping.md +15 -15
  70. package/templates/skills/business-analyse/references/naming-conventions.md +4 -4
  71. package/templates/skills/business-analyse/references/review-data-mapping.md +29 -29
  72. package/templates/skills/business-analyse/references/robustness-checks.md +36 -36
  73. package/templates/skills/business-analyse/references/spec-auto-inference.md +2 -2
  74. package/templates/skills/business-analyse/references/ui-dashboard-spec.md +1 -1
  75. package/templates/skills/business-analyse/references/ui-resource-cards.md +1 -1
  76. package/templates/skills/business-analyse/references/validation-checklist.md +3 -3
  77. package/templates/skills/business-analyse/references/wireframe-svg-style-guide.md +2 -2
  78. package/templates/skills/business-analyse/schemas/application-schema.json +8 -8
  79. package/templates/skills/business-analyse/schemas/feature-schema.json +3 -3
  80. package/templates/skills/business-analyse/schemas/index-schema.json +47 -0
  81. package/templates/skills/business-analyse/schemas/project-schema.json +6 -6
  82. package/templates/skills/business-analyse/schemas/sections/analysis-schema.json +1 -1
  83. package/templates/skills/business-analyse/schemas/sections/handoff-schema.json +5 -3
  84. package/templates/skills/business-analyse/schemas/sections/metadata-schema.json +4 -4
  85. package/templates/skills/business-analyse/schemas/sections/specification-schema.json +1 -1
  86. package/templates/skills/business-analyse/schemas/shared/common-defs.json +4 -4
  87. package/templates/skills/business-analyse/steps/step-00-init.md +68 -77
  88. package/templates/skills/business-analyse/steps/step-01-cadrage.md +54 -180
  89. package/templates/skills/business-analyse/steps/step-02-structure.md +175 -0
  90. package/templates/skills/business-analyse/steps/step-03-specify.md +198 -0
  91. package/templates/skills/business-analyse/steps/step-04-consolidate.md +478 -0
  92. package/templates/skills/business-analyse/steps/step-05-deploy.md +220 -0
  93. package/templates/skills/business-analyse/steps/step-06-review.md +51 -69
  94. package/templates/skills/business-analyse/templates/tpl-frd.md +1 -1
  95. package/templates/skills/business-analyse/templates/tpl-handoff.md +20 -17
  96. package/templates/skills/business-analyse/templates/tpl-launch-displays.md +2 -2
  97. package/templates/skills/business-analyse/templates-react.md +2 -2
  98. package/templates/skills/derive-prd/SKILL.md +92 -0
  99. package/templates/skills/derive-prd/references/acceptance-criteria.md +169 -0
  100. package/templates/skills/derive-prd/references/entity-domain-mapping.md +115 -0
  101. package/templates/skills/{business-analyse → derive-prd}/references/handoff-file-templates.md +131 -120
  102. package/templates/skills/{business-analyse → derive-prd}/references/handoff-mappings.md +95 -95
  103. package/templates/skills/{business-analyse → derive-prd}/references/handoff-seeddata-generation.md +312 -312
  104. package/templates/skills/{business-analyse → derive-prd}/references/prd-generation.md +262 -263
  105. package/templates/skills/derive-prd/references/readiness-scoring.md +104 -0
  106. package/templates/skills/derive-prd/schemas/handoff-schema.json +95 -0
  107. package/templates/skills/derive-prd/steps/step-00-validate.md +130 -0
  108. package/templates/skills/derive-prd/steps/step-01-transform.md +206 -0
  109. package/templates/skills/derive-prd/steps/step-02-export.md +181 -0
  110. package/templates/skills/{business-analyse → derive-prd}/templates/tpl-progress.md +172 -172
  111. package/templates/skills/ralph-loop/SKILL.md +2 -1
  112. package/templates/skills/ralph-loop/references/init-resume-recovery.md +1 -1
  113. package/templates/skills/ralph-loop/steps/step-01-task.md +2 -2
  114. package/templates/skills/apex/references/agent-teams-protocol.md +0 -203
  115. package/templates/skills/business-analyse/_architecture.md +0 -124
  116. package/templates/skills/business-analyse/_elicitation.md +0 -206
  117. package/templates/skills/business-analyse/_module-loop.md +0 -115
  118. package/templates/skills/business-analyse/_rules.md +0 -142
  119. package/templates/skills/business-analyse/_suggestions.md +0 -34
  120. package/templates/skills/business-analyse/questionnaire/00-application.md +0 -160
  121. package/templates/skills/business-analyse/questionnaire/00b-project.md +0 -85
  122. package/templates/skills/business-analyse/questionnaire/02-stakeholders.md +0 -189
  123. package/templates/skills/business-analyse/questionnaire/03-scope.md +0 -164
  124. package/templates/skills/business-analyse/questionnaire/04-data.md +0 -88
  125. package/templates/skills/business-analyse/questionnaire/05-integrations.md +0 -58
  126. package/templates/skills/business-analyse/questionnaire/06-security.md +0 -68
  127. package/templates/skills/business-analyse/questionnaire/07-ui.md +0 -76
  128. package/templates/skills/business-analyse/questionnaire/08-performance.md +0 -42
  129. package/templates/skills/business-analyse/questionnaire/09-constraints.md +0 -45
  130. package/templates/skills/business-analyse/questionnaire/10-documentation.md +0 -58
  131. package/templates/skills/business-analyse/questionnaire/11-data-lifecycle.md +0 -59
  132. package/templates/skills/business-analyse/questionnaire/12-migration.md +0 -58
  133. package/templates/skills/business-analyse/questionnaire/13-cross-module.md +0 -69
  134. package/templates/skills/business-analyse/questionnaire/14-risk-assumptions.md +0 -135
  135. package/templates/skills/business-analyse/questionnaire/15-success-metrics.md +0 -136
  136. package/templates/skills/business-analyse/references/agent-module-prompt.md +0 -366
  137. package/templates/skills/business-analyse/references/agent-pooling-best-practices.md +0 -557
  138. package/templates/skills/business-analyse/references/cache-warming-strategy.md +0 -566
  139. package/templates/skills/business-analyse/references/cadrage-challenge-patterns.md +0 -41
  140. package/templates/skills/business-analyse/references/cadrage-coverage-matrix.md +0 -74
  141. package/templates/skills/business-analyse/references/cadrage-pre-analysis.md +0 -115
  142. package/templates/skills/business-analyse/references/cadrage-shared-modules.md +0 -68
  143. package/templates/skills/business-analyse/references/cadrage-structure-cards.md +0 -85
  144. package/templates/skills/business-analyse/references/team-orchestration.md +0 -1093
  145. package/templates/skills/business-analyse/references/validate-incremental-html.md +0 -121
  146. package/templates/skills/business-analyse/steps/step-01b-applications.md +0 -419
  147. package/templates/skills/business-analyse/steps/step-02-decomposition.md +0 -387
  148. package/templates/skills/business-analyse/steps/step-03a-data.md +0 -16
  149. package/templates/skills/business-analyse/steps/step-03a1-setup.md +0 -486
  150. package/templates/skills/business-analyse/steps/step-03a2-analysis.md +0 -300
  151. package/templates/skills/business-analyse/steps/step-03b-ui.md +0 -405
  152. package/templates/skills/business-analyse/steps/step-03c-compile.md +0 -516
  153. package/templates/skills/business-analyse/steps/step-03d-validate.md +0 -691
  154. package/templates/skills/business-analyse/steps/step-04-consolidation.md +0 -17
  155. package/templates/skills/business-analyse/steps/step-04a-collect.md +0 -415
  156. package/templates/skills/business-analyse/steps/step-04b-analyze.md +0 -163
  157. package/templates/skills/business-analyse/steps/step-04c-decide.md +0 -186
  158. package/templates/skills/business-analyse/steps/step-05a-handoff.md +0 -937
  159. package/templates/skills/business-analyse/steps/step-05b-deploy.md +0 -522
  160. package/templates/skills/business-analyse/steps/step-05c-ralph-readiness.md +0 -703
@@ -1,1093 +0,0 @@
1
- # Team Orchestration — Business-Analyse Propose & Review
2
-
3
- > **Loaded by:** step-02 when multi-module detected (`moduleOrder.length >= 2`)
4
- > **Purpose:** Delegate module specification to autonomous agents with user review.
5
- > **Rule:** Single module = NO team. Only create team for 2+ modules.
6
- > **Execution:** Parallel by dependency layer — all modules in the same layer run simultaneously.
7
-
8
- ---
9
-
10
- ## Multi-Application Team Structure (Project Mode)
11
-
12
- > **Only applies when `workflow.mode === "project"`** (multiple applications in a single BA session).
13
- > In single-application mode, skip this section entirely.
14
-
15
- When the project contains multiple applications, the team structure adds an **application-level outer loop** around the existing module-level inner loop:
16
-
17
- ```
18
- Team Lead (project level)
19
- ├── Application 1 (in topological order)
20
- │ ├── mod-{app1-module1} (parallel per dependency layer)
21
- │ ├── mod-{app1-module2}
22
- │ └── consolidation-{app1}
23
- ├── Application 2
24
- │ ├── mod-{app2-module1}
25
- │ ├── mod-{app2-module2}
26
- │ └── consolidation-{app2}
27
- ├── Cross-Application Consolidation Agent
28
- └── Handoff Agent (all applications)
29
- ```
30
-
31
- **Application Loop Protocol:**
32
-
33
- ```
34
- FOR each application in projectFeature.applicationDependencyGraph.topologicalOrder:
35
- 1. Load application feature.json
36
- 2. Read module decomposition for this application
37
- 3. Execute §1-§4 (team setup → module specification → review → layer completion)
38
- - Team name: "ba-{projectName}-{appCode}"
39
- - Agent names: "mod-{appCode}-{moduleCode}"
40
- - Context passed to agents includes application-specific: context, tablePrefix, applicationRoles
41
- 4. After all modules in this application are specified:
42
- - Run per-application consolidation (§5 — scoped to this application's modules)
43
- - Mark application as "specified" in project feature.json
44
- - Clean up application team
45
-
46
- AFTER all applications specified:
47
- 5. Run cross-application consolidation (§5-bis)
48
- 6. Run unified handoff (§6 — all applications at once)
49
- 7. Cleanup (§7)
50
- ```
51
-
52
- **Key differences from single-application mode:**
53
- - Team names include application code to avoid collisions
54
- - Agent prompts include application context (not just module context)
55
- - Cross-application consolidation runs AFTER all per-application consolidations
56
- - Handoff generates one PRD per module + one cross-application PRD
57
- - The team lead tracks both `completedApplications[]` and `completedModules[]`
58
-
59
- ---
60
-
61
- ## 1. Team Setup
62
-
63
- After step-02 decomposition is complete and client has approved the module structure:
64
-
65
- ### 1a. Clean Up Old Team Data (MANDATORY)
66
-
67
- Before creating the team, clean up any leftover data from previous sessions to prevent stale task collisions:
68
-
69
- ```bash
70
- # Remove leftover task files from previous runs
71
- rm -f ~/.claude/tasks/ba-{appName}/*.json 2>/dev/null
72
- # Remove leftover team directory (TeamDelete may leave remnants)
73
- rm -rf ~/.claude/teams/ba-{appName} 2>/dev/null
74
- ```
75
-
76
- > **Why:** If a previous session used the same team name and crashed or was interrupted,
77
- > leftover task files will be picked up by new agents, causing them to receive stale
78
- > task_assignment notifications for wrong modules.
79
-
80
- ### 1b. Create Team and Capture Actual Name
81
-
82
- ```javascript
83
- const result = TeamCreate({ team_name: "ba-{appName}", description: "BA module analysis for {appName}" });
84
- // CRITICAL: TeamCreate may return a DIFFERENT name than requested!
85
- // Always use the RETURNED team_name, not the requested one.
86
- const actualTeamName = result.team_name;
87
- ```
88
-
89
- Store team context for the session:
90
- ```javascript
91
- const teamContext = {
92
- teamName: actualTeamName, // ← RETURNED name, NOT "ba-{appName}"
93
- moduleOrder: metadata.workflow.moduleOrder,
94
- dependencyLayers: dependencyGraph.layers, // ← from step-02 topological sort
95
- completedModules: [],
96
- completedLayers: [],
97
- mode: "propose-review"
98
- };
99
- ```
100
-
101
- > **WARNING:** NEVER hardcode `"ba-{appName}"` in subsequent calls.
102
- > Always use `teamContext.teamName` (the actual name returned by TeamCreate).
103
-
104
- ---
105
-
106
- ## 2. Module Agent Spawn — Parallel by Dependency Layer
107
-
108
- Process modules **layer by layer**. Within each layer, spawn ALL agents **simultaneously**.
109
-
110
- ```
111
- FOR each layer in dependencyGraph.layers:
112
- Execute §2a → §2b → §2c → §2d → §2e → §3 → §4
113
- ```
114
-
115
- ### 2a. Pre-Spawn Cross-Module Analysis
116
-
117
- **ALWAYS executed for layers with 2+ modules.** Analyze the module definitions within this layer to identify cross-module touchpoints BEFORE spawning agents.
118
-
119
- ```
120
- IF layer.modules.length >= 2:
121
-
122
- ULTRATHINK: Analyze module definitions for same-layer interactions:
123
-
124
- 1. Shared entity names
125
- → Do any modules reference the same entity? (e.g., both "Products" and "Inventory"
126
- might reference a "Category" entity)
127
-
128
- 2. Potential FK overlaps
129
- → Do any modules anticipate creating entities that others might reference?
130
- → E.g., Products creates "Product" entity, Orders references "Product" via FK
131
-
132
- 3. Naming conventions
133
- → Will both modules use similar attribute names? (e.g., "Code", "Name", "Status")
134
- → Agree on a consistent naming pattern
135
-
136
- 4. Shared lookup data
137
- → Do any modules reference common reference tables?
138
- → E.g., both use a "Status" enum, a "Country" lookup, a "Currency" type
139
-
140
- 5. Permission path consistency
141
- → Verify permission paths won't collide:
142
- {app}.{module1}.{entity}.{action}
143
- {app}.{module2}.{entity}.{action}
144
-
145
- Build coordinationNotes for EACH module in the layer:
146
- ```
147
-
148
- **coordinationNotes template** (injected into each agent's prompt):
149
-
150
- ```
151
- ## Same-Layer Coordination Notes
152
-
153
- You are running IN PARALLEL with: {otherModuleCodes.join(", ")}
154
-
155
- ### Known Touchpoints
156
- - {otherModule} will define entity "{EntityName}" — if you need to reference it,
157
- use CROSS_MODULE_QUERY to get the exact attribute structure
158
- - Naming convention: use {convention} for shared concepts (e.g., "Status" enum values)
159
- - Shared lookups: {list any common reference data both modules might create}
160
-
161
- ### Your Responsibilities vs Theirs
162
- - You own: {your entities — list}
163
- - They own: {their entities — list}
164
- - Contested/shared: {entities both might create — QUERY before defining}
165
-
166
- ### Cross-Module FK Convention
167
- When referencing an entity owned by a same-layer module:
168
- 1. Send CROSS_MODULE_QUERY to team lead asking for the entity's attribute structure
169
- 2. WAIT for the answer before defining your FK field
170
- 3. Use the exact entity name and primary key type from the answer
171
- ```
172
-
173
- > **IF layer has only 1 module:** Skip §2a entirely. No coordination notes needed.
174
-
175
- ### 2b. Prepare Agent Context (per module)
176
-
177
- For EACH module in the layer, gather the context the agent needs:
178
-
179
- ```
180
- 1. ba-reader.readApplicationContext({feature_id})
181
- → Extract: appName, featureId, context, language
182
-
183
- 2. Read module decomposition data from master feature.json:
184
- → modules[moduleCode]: code, name, description, featureType, entities,
185
- anticipatedSections, dependencies, detailTabs, estimatedComplexity, priority
186
-
187
- 3. ba-reader.getCompletedModulesSummary({feature_id})
188
- → Compact summary of already-specified modules from COMPLETED LAYERS (max 100 lines)
189
- → Includes: entity names, FK relationships, permission paths, shared types
190
- ```
191
-
192
- ### 2c. Spawn ALL Layer Agents Simultaneously
193
-
194
- **For layers with 1 module** — single spawn (same as standard):
195
-
196
- ```javascript
197
- Task({
198
- subagent_type: "general-purpose",
199
- team_name: teamContext.teamName,
200
- name: "mod-{moduleCode}",
201
- model: "opus",
202
- mode: "bypassPermissions",
203
- prompt: BUILD_PROMPT(references/agent-module-prompt.md, {
204
- appName,
205
- featureId,
206
- moduleCode,
207
- moduleDescription: module.description,
208
- featureType: module.featureType,
209
- entities: module.entities,
210
- anticipatedSections: module.anticipatedSections,
211
- dependencies: module.dependencies,
212
- detailTabs: module.detailTabs,
213
- estimatedComplexity: module.estimatedComplexity,
214
- priority: module.priority,
215
- completedModulesSummary,
216
- coordinationNotes: "", // empty for single-module layer
217
- language: metadata.language,
218
- docsDir: "docs/{appName}/{moduleCode}/business-analyse/v{version}/"
219
- }),
220
- description: "Specify {moduleCode}"
221
- });
222
- ```
223
-
224
- **For layers with 2+ modules** — spawn ALL in a **single message** (parallel):
225
-
226
- ```javascript
227
- // CRITICAL: All Task() calls MUST be in ONE message for parallel execution.
228
- // Do NOT await between them — they MUST be sent together.
229
-
230
- // Agent 1:
231
- Task({
232
- subagent_type: "general-purpose",
233
- team_name: teamContext.teamName,
234
- name: "mod-{moduleCode1}",
235
- model: "opus",
236
- mode: "bypassPermissions",
237
- prompt: BUILD_PROMPT(references/agent-module-prompt.md, {
238
- ...moduleContext1,
239
- coordinationNotes: coordinationNotesForModule1, // ← NEW
240
- }),
241
- description: "Specify {moduleCode1}"
242
- });
243
-
244
- // Agent 2 (IN SAME MESSAGE):
245
- Task({
246
- subagent_type: "general-purpose",
247
- team_name: teamContext.teamName,
248
- name: "mod-{moduleCode2}",
249
- model: "opus",
250
- mode: "bypassPermissions",
251
- prompt: BUILD_PROMPT(references/agent-module-prompt.md, {
252
- ...moduleContext2,
253
- coordinationNotes: coordinationNotesForModule2, // ← NEW
254
- }),
255
- description: "Specify {moduleCode2}"
256
- });
257
-
258
- // ... repeat for all modules in this layer
259
- ```
260
-
261
- **BUILD_PROMPT**: Read `references/agent-module-prompt.md`, replace all `{placeholders}` with actual values (including the new `{coordinationNotes}`), and pass as the `prompt` parameter.
262
-
263
- ### 2d. Track Layer State
264
-
265
- After spawning, initialize layer tracking:
266
-
267
- ```javascript
268
- const layerState = {
269
- layerIndex: L,
270
- modules: layer.modules, // ["Customers", "Products"]
271
- pendingProposals: [...layer.modules], // agents not yet PROPOSAL_READY
272
- receivedProposals: {}, // { moduleCode: proposalSummary }
273
- approvedModules: [], // modules approved by user
274
- crossModuleQueries: [], // log of queries handled
275
- };
276
- ```
277
-
278
- ### 2e. Wait for Layer Completion — Message Handling Loop
279
-
280
- After spawning all agents in the layer, the team lead enters a **message handling loop**.
281
- Messages from teammates are delivered automatically — do NOT poll or re-spawn.
282
-
283
- ```
284
- WHILE layerState.pendingProposals.length > 0:
285
-
286
- Wait for next message from any agent in this layer.
287
-
288
- CASE message matches "PROPOSAL_READY:{moduleCode}":
289
- → Remove moduleCode from pendingProposals
290
- → Store proposal in receivedProposals[moduleCode]
291
- → Display: "✓ Module {moduleCode} proposal received ({received}/{total})"
292
- → IF pendingProposals is now empty:
293
- → All agents in this layer have proposed
294
- → Proceed to §3 (Layer Review)
295
-
296
- CASE message matches "CROSS_MODULE_QUERY:{targetModule}":
297
- → Handle per §2-bis (Cross-Module Coordination Protocol)
298
-
299
- CASE message matches "CROSS_MODULE_ANSWER_RELAY:{requestingModule}":
300
- → Forward to requesting agent per §2-bis
301
-
302
- CASE message matches "ERROR:{moduleCode}:{description}":
303
- → Handle per §8 (Error Recovery)
304
- → Remove from pendingProposals if module is skipped
305
- → IF pendingProposals is now empty → proceed to §3
306
- ```
307
-
308
- > **This loop may take several minutes** as agents work autonomously.
309
- > The team lead does nothing except handle cross-module queries during this time.
310
-
311
- ---
312
-
313
- ## 2-bis. Cross-Module Coordination Protocol (Runtime Relay)
314
-
315
- When an agent sends `CROSS_MODULE_QUERY:{targetModule}`, the team lead routes the query based on the target module's state:
316
-
317
- ### Case 1: Target is in a COMPLETED layer
318
-
319
- The target module's specification is already written to feature.json.
320
-
321
- ```
322
- → Read target module's entities/attributes from completedModulesSummary
323
- → Send answer directly to requesting agent:
324
-
325
- SendMessage({
326
- type: "message",
327
- recipient: "mod-{requestingModule}",
328
- content: "CROSS_MODULE_ANSWER:{requestingModule}\nAnswer: {entity structure from completed module data}",
329
- summary: "Answer from completed {targetModule}"
330
- })
331
- ```
332
-
333
- ### Case 2: Target is in CURRENT layer AND has sent PROPOSAL_READY
334
-
335
- The target agent has finished its proposal — we have its specification data.
336
-
337
- ```
338
- → Extract relevant entity/attribute info from receivedProposals[targetModule]
339
- → Send answer directly to requesting agent:
340
-
341
- SendMessage({
342
- type: "message",
343
- recipient: "mod-{requestingModule}",
344
- content: "CROSS_MODULE_ANSWER:{requestingModule}\nAnswer: {entity structure from proposal data}",
345
- summary: "Answer from {targetModule} proposal"
346
- })
347
- ```
348
-
349
- ### Case 3: Target is in CURRENT layer AND still working (no PROPOSAL_READY yet)
350
-
351
- The target agent is still specifying — relay the question.
352
-
353
- ```
354
- → Forward question to target agent:
355
-
356
- SendMessage({
357
- type: "message",
358
- recipient: "mod-{targetModule}",
359
- content: "CROSS_MODULE_QUERY_RELAY:{requestingModule}\nQuestion: {original question}",
360
- summary: "Relay query from {requestingModule}"
361
- })
362
-
363
- → Wait for target agent to respond with CROSS_MODULE_ANSWER_RELAY
364
- → Forward answer to requesting agent:
365
-
366
- SendMessage({
367
- type: "message",
368
- recipient: "mod-{requestingModule}",
369
- content: "CROSS_MODULE_ANSWER:{requestingModule}\nAnswer: {answer from target agent}",
370
- summary: "Answer from {targetModule}"
371
- })
372
- ```
373
-
374
- ### Case 4: Circular query (A asks about B, B asks about A simultaneously)
375
-
376
- Both agents are blocked waiting for each other. The team lead MUST resolve this autonomously.
377
-
378
- ```
379
- → ULTRATHINK: Based on SmartStack conventions and module descriptions,
380
- make a consistent design decision for BOTH modules.
381
- → Send CROSS_MODULE_ANSWER to BOTH agents with compatible entity structures.
382
- → Log resolution in layerState.crossModuleQueries[] for later review.
383
- ```
384
-
385
- > **Every cross-module query is logged** in `layerState.crossModuleQueries[]` for display during §3 review.
386
-
387
- ---
388
-
389
- ## 3. Layer Review — Quality-First Protocol
390
-
391
- When ALL agents in a layer have sent PROPOSAL_READY, the team lead presents the results to the user.
392
-
393
- ### 3a. Cross-Module Interaction Analysis (layers with 2+ modules)
394
-
395
- **ALWAYS displayed FIRST** for multi-module layers. This gives the user a bird's-eye view of how modules in this layer interact.
396
-
397
- ```
398
- ═══════════════════════════════════════════════════════════
399
- Layer {L} — {N} modules terminés — Analyse croisée
400
- ═══════════════════════════════════════════════════════════
401
-
402
- ### Interactions cross-module détectées
403
-
404
- | Module A | Module B | Type | Détail |
405
- |----------|----------|------|--------|
406
- | {mod1} | {mod2} | FK | {mod1}.{entity}.{field} → {mod2}.{entity} |
407
- | {mod1} | {mod2} | Concept partagé | Les deux définissent "{concept}" |
408
- | {mod1} | {mod2} | Lookup | {mod1} référence {mod2}.{entity} comme donnée de ref |
409
-
410
- ### Requêtes cross-module résolues pendant la spécification ({count})
411
- {FOR each query in layerState.crossModuleQueries:}
412
- - {requestingModule} → {targetModule}: {question summary} → {answer summary}
413
-
414
- ### Points d'attention
415
- - {naming inconsistencies detected between module proposals}
416
- - {potential permission path conflicts}
417
- - {shared entity definition differences}
418
-
419
- ─────────────────────────────────────────────────────────
420
- ```
421
-
422
- > **For single-module layers:** Skip §3a entirely — no cross-module analysis needed.
423
-
424
- ### 3b. Individual Module Review (ALWAYS — for quality)
425
-
426
- Review each module's proposal individually. For multi-module layers, the user has already seen the cross-module context from §3a.
427
-
428
- ```
429
- FOR each module in layer (respecting topologicalOrder within layer):
430
- ```
431
-
432
- **Step 1:** Format and display the proposal:
433
-
434
- ```
435
- ═══════════════════════════════════════════════════════════
436
- Proposition pour le module {moduleCode}
437
- (Layer {L} — module {idx+1}/{layerTotal} — global {globalIdx+1}/{totalModules})
438
- ═══════════════════════════════════════════════════════════
439
-
440
- {structured summary from agent — displayed as-is}
441
-
442
- ─────────────────────────────────────────────────────────
443
- ```
444
-
445
- **Step 2:** Ask the user via AskUserQuestion:
446
-
447
- ```
448
- Validez-vous cette spécification ?
449
- Options:
450
- 1. "Valider" → approve as-is
451
- 2. "Modifier" → provide feedback for revision
452
- 3. "Voir détail" → team lead reads module feature.json and displays full content
453
- ```
454
-
455
- **Step 3 — IMMEDIATELY after AskUserQuestion returns, handle the response:**
456
-
457
- **IF user selected "Valider" (approve):**
458
- ```
459
- SendMessage({
460
- type: "message",
461
- recipient: "mod-{moduleCode}",
462
- content: "APPROVED:{moduleCode}",
463
- summary: "{moduleCode} approved by user"
464
- })
465
- ```
466
- → CRITICAL: You MUST send this message. Do NOT skip this step.
467
- → Then WAIT for the agent to send `MODULE_COMPLETE:{moduleCode}`.
468
- → Add moduleCode to `layerState.approvedModules`.
469
- → Continue to next module in this layer.
470
-
471
- **IF user selected "Modifier" (revision):**
472
- → Ask user for specific feedback via AskUserQuestion
473
- → Then send:
474
- ```
475
- SendMessage({
476
- type: "message",
477
- recipient: "mod-{moduleCode}",
478
- content: "REVISION:{moduleCode}\n{user_feedback}",
479
- summary: "{moduleCode} revision requested"
480
- })
481
- ```
482
- → Then WAIT for the agent to send a new `PROPOSAL_READY` → re-display this module's proposal.
483
- → Other modules in the layer are NOT blocked — their proposals remain in receivedProposals.
484
-
485
- **IF user selected "Voir détail":**
486
- → Read module feature.json via ba-reader.readSection({feature_id, section})
487
- → Display relevant sections in detail
488
- → Go back to Step 2 (re-ask the validation question)
489
-
490
- ### 3c. Revision Limits
491
-
492
- - Max **3 revision cycles** per module
493
- - After 3 rejections: team lead asks user if they want to switch to **inline interactive mode** for this module
494
- - If yes: shutdown agent, team lead loads step-03a1-setup.md and executes interactively
495
- - If no: mark module as "needs-review" and continue to next module
496
-
497
- ### 3d. Layer Consistency Check (layers with 2+ modules)
498
-
499
- After ALL modules in a layer are approved, perform a final cross-module consistency verification:
500
-
501
- ```
502
- IF layer.modules.length >= 2 AND all modules approved:
503
-
504
- ULTRATHINK: Verify cross-module consistency:
505
-
506
- 1. FK references: Do FK field names match actual entity names across modules?
507
- → e.g., if Products.CategoryId references Categories.Category, names must match
508
-
509
- 2. Permission paths: Are paths consistent and non-colliding?
510
- → {app}.{module1}.{entity}.read vs {app}.{module2}.{entity}.read
511
-
512
- 3. i18n keys: Do keys follow consistent patterns? No collisions?
513
- → {module1}.labels.name vs {module2}.labels.name (OK — namespaced)
514
-
515
- 4. Seed data IDs: All GUIDs use Guid.NewGuid() (no deterministic/fixed values)
516
- → Verify no hardcoded or deterministic GUID patterns
517
-
518
- 5. Entity attribute types: Are shared concepts typed consistently?
519
- → If both modules define "Status", is it the same enum type?
520
-
521
- IF inconsistency found:
522
- Display warning with specific issue:
523
- "⚠ Incohérence détectée entre {mod1} et {mod2}: {description}"
524
-
525
- AskUserQuestion:
526
- question: "Corriger automatiquement cette incohérence ?"
527
- options:
528
- 1. "Corriger" → send REVISION to affected agent(s) with fix instructions
529
- 2. "Ignorer" → proceed (will be caught in consolidation)
530
-
531
- IF "Corriger":
532
- → Send REVISION:{moduleCode}\n{auto-fix instructions} to affected agent
533
- → Wait for new PROPOSAL_READY
534
- → Re-approve (no full re-review needed — only the fix)
535
-
536
- IF no inconsistency found:
537
- Display: "✓ Cohérence cross-module vérifiée pour le layer {L}"
538
- ```
539
-
540
- ---
541
-
542
- ## 4. Layer Completion & Agent Shutdown
543
-
544
- After ALL modules in a layer are approved AND consistency check passed:
545
-
546
- ### 4a. Shutdown ALL Layer Agents (MANDATORY — do NOT skip)
547
-
548
- **IMMEDIATELY** after layer is fully approved, send shutdown_request to ALL agents in this layer:
549
-
550
- ```javascript
551
- // Send shutdown to ALL layer agents
552
- FOR each moduleCode in layer.modules:
553
- SendMessage({
554
- type: "shutdown_request",
555
- recipient: "mod-{moduleCode}",
556
- content: "Layer complete, shutting down"
557
- })
558
- ```
559
-
560
- Wait for ALL agents to confirm shutdown (`shutdown_response approve: true`).
561
-
562
- > **WARNING:** If you skip this step, agents will remain running indefinitely.
563
- > Agents CANNOT self-terminate — they NEED shutdown_request from you.
564
-
565
- ### 4b. Update Layer Tracking
566
-
567
- ```javascript
568
- FOR each moduleCode in layer.modules:
569
- teamContext.completedModules.push(moduleCode);
570
- ba-writer.updateModuleStatus({feature_id, moduleCode, status: "specified"});
571
-
572
- teamContext.completedLayers.push(layerState.layerIndex);
573
-
574
- Display:
575
- "═══ Layer {L} complete — {layer.modules.length} modules specified ═══"
576
- "═══ Progress: {completedModules.length}/{moduleOrder.length} modules ═══"
577
- ```
578
-
579
- ### 4b-bis. Deploy Incremental Interactive HTML (MANDATORY)
580
-
581
- > **Module agents do NOT generate the HTML** — this responsibility belongs to the team lead.
582
- > After each layer is approved, the team lead generates/updates the interactive HTML with all completed modules.
583
- > This gives clients early access to review completed modules while the next layer is being specified.
584
-
585
- **Execute the incremental HTML deployment:**
586
-
587
- 1. **Read** the HTML template: `html/ba-interactive.html` (relative to skill root `~/.claude/skills/business-analyse/html/`)
588
- 2. **Read** `references/html-data-mapping.md` for the complete FEATURE_DATA and EMBEDDED_ARTIFACTS mapping specification
589
- 3. **Read** the master feature.json (application level)
590
- 4. **Read** EACH completed module's feature.json (all modules in `teamContext.completedModules`)
591
- 5. **Build FEATURE_DATA** following `references/validate-incremental-html.md`:
592
- - `metadata`, `cadrage`, `modules[]`, `dependencies[]` → from master feature.json
593
- - `moduleSpecs[moduleCode]` → only for modules with status "specified" (completed so far)
594
- - `consolidation` → empty `{ interactions: [], e2eFlows: [] }` (not yet consolidated)
595
- - `handoff` → empty `{}` (not yet handed off)
596
- - `cadrage.scope` MUST use HTML keys (`vital`/`important`/`optional`/`excluded`), NOT feature.json keys
597
- 6. **Build EMBEDDED_ARTIFACTS** with wireframes for completed modules:
598
- - Rename fields: `mockupFormat` → `format`, `mockup` → `content`
599
- - Safety net: check BOTH key names (`uiWireframes` / `wireframes`, `mockup` / `ascii` / `content`)
600
- - Include dependency graph from master
601
- 7. **Replace placeholders** in template: `{{FEATURE_DATA}}`, `{{EMBEDDED_ARTIFACTS}}`, `{{APPLICATION_NAME}}`, `{{VERSION}}`, etc.
602
- 8. **Write** to `docs/{app}/business-analyse/v{version}/ba-interactive.html`
603
-
604
- **Display confirmation:**
605
- ```
606
- ✓ Interactive HTML updated (incremental):
607
- Path: docs/{app}/business-analyse/v{version}/ba-interactive.html
608
- Modules included: {completedModules.length}/{totalModules} specified
609
- → Client can open in browser to review completed modules now.
610
- ```
611
-
612
- > **Reference:** See [references/validate-incremental-html.md](validate-incremental-html.md) for the complete deployment process and field mapping details.
613
-
614
- ### 4c. Build Updated Context for Next Layer
615
-
616
- Before spawning the next layer's agents, rebuild the `completedModulesSummary`:
617
-
618
- ```
619
- ba-reader.getCompletedModulesSummary({feature_id})
620
- → Now includes ALL modules from completed layers
621
- → This summary is injected into next layer's agent prompts
622
- → Agents in the next layer will have full context of everything specified so far
623
- ```
624
-
625
- ### 4d. Next Layer or Consolidation
626
-
627
- ```
628
- IF more layers remain in dependencyGraph.layers:
629
- → Go back to §2 for the next layer
630
-
631
- IF all layers complete (all modules specified):
632
- → Proceed to §5 (Consolidation)
633
- ```
634
-
635
- ---
636
-
637
- ## 5. Consolidation Phase
638
-
639
- After ALL modules are specified (all layers complete):
640
-
641
- ```
642
- Display: "═══ All {moduleOrder.length} modules specified — Starting consolidation ═══"
643
- ```
644
-
645
- ### 5a. Spawn Consolidation Agent
646
-
647
- ```javascript
648
- Task({
649
- subagent_type: "general-purpose",
650
- team_name: teamContext.teamName, // ← ACTUAL name from TeamCreate result
651
- name: "consolidation",
652
- model: "opus",
653
- mode: "bypassPermissions",
654
- prompt: `
655
- You are a consolidation agent for business-analyse application "{appName}".
656
-
657
- ## Your Mission
658
- Execute cross-module consolidation (steps 04a + 04b):
659
- 1. Load steps/step-04a-collect.md and execute
660
- 2. Load steps/step-04b-analyze.md and execute
661
-
662
- ## Context
663
- - Feature ID: {featureId}
664
- - Modules: {moduleOrder.join(", ")}
665
- - Dependency layers: {JSON.stringify(dependencyGraph.layers)}
666
- - All modules have status "specified"
667
-
668
- ## Output
669
- Send CONSOLIDATION_READY with a structured report:
670
- - Cross-module interactions (FK references, shared entities, event flows)
671
- - Permission coherence (conflicts, overlaps, gaps)
672
- - E2E user flows validated
673
- - Global risks identified
674
-
675
- ## Communication
676
- - CONSOLIDATION_READY:{appName}\n{report} → when analysis complete
677
- - ERROR:{appName}:{description} → on blocking issue
678
- `,
679
- description: "Cross-module consolidation"
680
- });
681
- ```
682
-
683
- ### 5b. Present Consolidation to User (04c Decision)
684
-
685
- When CONSOLIDATION_READY received:
686
-
687
- ```
688
- ═══════════════════════════════════════════════════════════
689
- Consolidation cross-module — {appName}
690
- ═══════════════════════════════════════════════════════════
691
-
692
- {consolidation report from agent}
693
-
694
- ─────────────────────────────────────────────────────────
695
- ```
696
-
697
- AskUserQuestion: "Approuvez-vous la consolidation ?"
698
- - "Approuver" → send APPROVED to agent → agent writes consolidation to master feature.json
699
- - "Réviser" → send feedback → agent adjusts
700
-
701
- After approval → shutdown consolidation agent.
702
-
703
- **IF `workflow.mode === "project"`:** proceed to §5-bis (cross-application consolidation).
704
- **ELSE:** proceed to §6 (handoff).
705
-
706
- ---
707
-
708
- ## 5-bis. Cross-Application Consolidation (Project Mode Only)
709
-
710
- > **Only runs when `workflow.mode === "project"` AND all applications have been consolidated.**
711
- > This step validates interactions BETWEEN applications, not just between modules within one application.
712
-
713
- ```javascript
714
- Task({
715
- subagent_type: "general-purpose",
716
- team_name: teamContext.teamName,
717
- name: "cross-app-consolidation",
718
- model: "opus",
719
- mode: "bypassPermissions",
720
- prompt: `
721
- You are a cross-application consolidation agent for project "{projectName}".
722
-
723
- ## Your Mission
724
- Validate interactions between ALL applications in the project:
725
-
726
- 1. Cross-application shared entities
727
- → Entity defined in App A, referenced by App B via data dependency
728
- 2. Cross-application permission path consistency
729
- → Each app uses its own context prefix (e.g., hr.* vs selfservice.*)
730
- 3. Cross-application role consistency
731
- → Same role names have compatible permission levels across apps
732
- 4. Cross-application navigation coherence
733
- → Applications appear in correct contexts with non-colliding routes
734
- 5. Cross-application seed data ordering
735
- → Foundation applications must seed first (NavigationApplication order)
736
-
737
- ## Context
738
- - Project ID: {projectId}
739
- - Applications: ${JSON.stringify(projectFeature.applications.map(a => ({
740
- code: a.code, modules: a.modules.map(m => m.code)
741
- })))}
742
- - Application dependency graph: ${JSON.stringify(projectFeature.applicationDependencyGraph)}
743
-
744
- ## Output
745
- Send CROSS_APP_CONSOLIDATION_READY with:
746
- - Cross-application interactions found
747
- - Permission path conflicts (if any)
748
- - Role inconsistencies (if any)
749
- - Recommended seed data order
750
- `,
751
- description: "Cross-app consolidation"
752
- });
753
- ```
754
-
755
- When CROSS_APP_CONSOLIDATION_READY received:
756
-
757
- ```
758
- ═══════════════════════════════════════════════════════════
759
- Cross-Application Consolidation — {projectName}
760
- ═══════════════════════════════════════════════════════════
761
-
762
- {cross-application consolidation report}
763
-
764
- ─────────────────────────────────────────────────────────
765
- ```
766
-
767
- AskUserQuestion: "Approuvez-vous la consolidation inter-applications ?"
768
- - "Approuver" → write cross-application interactions to project feature.json → proceed to §6
769
- - "Réviser" → send feedback → agent adjusts
770
-
771
- After approval → shutdown agent → proceed to §6.
772
-
773
- ---
774
-
775
- ## 6. Handoff Phase
776
-
777
- ```javascript
778
- // Project mode: handoff agent processes ALL applications at once
779
- // Single-app mode: handoff agent processes one application
780
- const handoffContext = workflow.mode === "project"
781
- ? {
782
- scope: "project",
783
- projectId: projectId,
784
- applications: projectFeature.applications.map(a => ({
785
- code: a.code, featureId: a.featureJsonPath,
786
- modules: a.modules.map(m => m.code)
787
- })),
788
- totalModules: projectFeature.applications.reduce((sum, a) => sum + a.modules.length, 0)
789
- }
790
- : {
791
- scope: "application",
792
- featureId: featureId,
793
- modules: moduleOrder
794
- };
795
-
796
- Task({
797
- subagent_type: "general-purpose",
798
- team_name: teamContext.teamName, // ← ACTUAL name from TeamCreate result
799
- name: "handoff",
800
- model: "sonnet",
801
- mode: "bypassPermissions",
802
- prompt: `
803
- You are a handoff agent for business-analyse ${workflow.mode === "project" ? `project "${projectName}"` : `application "${appName}"`}.
804
-
805
- ## Your Mission
806
- Execute the handoff sequence (steps 05a + 05b + 05c). ALL THREE STEPS ARE MANDATORY.
807
-
808
- ### Step 1: Handoff (step-05a-handoff.md)
809
- Load steps/step-05a-handoff.md and execute:
810
- - File mapping (7 categories: domain, application, infrastructure, api, frontend, seedData, tests)
811
- - BR-to-code mapping
812
- - API endpoint summary
813
-
814
- ### Step 2: Deploy Artifacts (step-05b-deploy.md)
815
- Load steps/step-05b-deploy.md and execute ALL sections:
816
-
817
- a. **Generate prd.json** for each module via \`ss derive-prd\` (section 1)
818
- b. **Initialize progress tracker** (section 2)
819
- c. **Update BA manifest** docs/index.json (section 3)
820
- d. **CRITICAL — Deploy ba-interactive.html** (sections 4-8):
821
- - Read HTML template from \`html/ba-interactive.html\` (relative to skill root \`~/.claude/skills/business-analyse/html/\`)
822
- - Read \`references/html-data-mapping.md\` for the EXACT FEATURE_DATA and EMBEDDED_ARTIFACTS field mapping
823
- - Read the master feature.json (application level)
824
- - Read EACH module feature.json (module level)
825
- - Build FEATURE_DATA object (metadata, cadrage, modules, moduleSpecs, consolidation, handoff)
826
- - FEATURE_DATA.moduleSpecs MUST have ONE entry per module (empty = BUG)
827
- - FEATURE_DATA.cadrage.scope MUST use HTML keys (vital/important/optional/excluded)
828
- - FEATURE_DATA.metadata.analysisMode MUST be set (always "interactive")
829
- - Build EMBEDDED_ARTIFACTS object (wireframes with field renames, e2eFlows, dependencyGraph)
830
- - Rename: mockupFormat → format, mockup → content
831
- - Replace placeholders: {{FEATURE_DATA}}, {{EMBEDDED_ARTIFACTS}}, {{APPLICATION_NAME}}, {{VERSION}}, etc.
832
- - Write to docs/{app}/business-analyse/v{version}/ba-interactive.html
833
- - Run POST-CHECK: file size > 100KB, moduleSpecs non-empty for ALL modules, cadrage.scope uses HTML keys
834
-
835
- > **WARNING:** The ba-interactive.html is the PRIMARY deliverable of the BA.
836
- > Generating PRD files WITHOUT generating the HTML is a BLOCKING BUG.
837
- > The HTML MUST be pre-populated with ALL analysis data (not an empty template).
838
-
839
- ### Step 3: Quality Gate (step-05c-ralph-readiness.md)
840
- Load steps/step-05c-ralph-readiness.md and execute:
841
- - ULTRATHINK quality review
842
- - Validate all handoffs are complete
843
- - Verify PRD structural integrity
844
- - Verify ba-interactive.html exists and is > 100KB
845
-
846
- ## Context
847
- ${workflow.mode === "project" ? `
848
- - Project ID: ${projectId}
849
- - Applications: ${JSON.stringify(handoffContext.applications)}
850
- - Total modules: ${handoffContext.totalModules}
851
- - Workflow mode: project
852
- - All applications and modules consolidated
853
- ` : `
854
- - Feature ID: ${featureId}
855
- - Modules: ${moduleOrder.join(", ")}
856
- - All modules consolidated
857
- `}
858
-
859
- ## Output
860
- Send HANDOFF_READY with:
861
- - PRD files generated (list with file paths)
862
- - ba-interactive.html deployed (path + file size — MUST be > 100KB)
863
- - BA manifest updated (docs/index.json entry count)
864
- - Quality gate result (PASS/FAIL with details)
865
-
866
- ## Communication
867
- - HANDOFF_READY:${workflow.mode === "project" ? projectName : appName}\n{report} → when all artifacts deployed
868
- - ERROR:${workflow.mode === "project" ? projectName : appName}:{description} → on blocking issue
869
- `,
870
- description: "Handoff & deploy"
871
- });
872
- ```
873
-
874
- When HANDOFF_READY received:
875
-
876
- ```
877
- ═══════════════════════════════════════════════════════════
878
- Handoff complete — {appName}
879
- ═══════════════════════════════════════════════════════════
880
-
881
- {handoff report}
882
-
883
- ─────────────────────────────────────────────────────────
884
- ```
885
-
886
- Display final status to user. If quality gate PASS → ready for /ralph-loop.
887
-
888
- ---
889
-
890
- ## 7. Cleanup
891
-
892
- After handoff complete:
893
-
894
- ```javascript
895
- // Safety net: shutdown ALL remaining agents (module agents + consolidation + handoff)
896
- // Module agents should already be shut down in §4a, but this catches any missed ones.
897
- const allAgents = [
898
- ...teamContext.moduleOrder.map(m => `mod-${m}`),
899
- "consolidation",
900
- "handoff"
901
- ];
902
-
903
- for (const agentName of allAgents) {
904
- SendMessage({
905
- type: "shutdown_request",
906
- recipient: agentName,
907
- content: "Workflow complete"
908
- });
909
- // Ignore errors for already-terminated agents
910
- }
911
-
912
- // Delete team
913
- TeamDelete();
914
-
915
- Display: "═══ Business-analyse complete — Team cleaned up ═══"
916
- ```
917
-
918
- > **Note:** Sending shutdown_request to an already-terminated agent is harmless.
919
- > This safety net ensures no orphan agents remain running.
920
-
921
- ---
922
-
923
- ## 8. Error Recovery
924
-
925
- ### Agent Crash in Parallel Layer
926
-
927
- If an agent stops responding or sends ERROR while other agents in the same layer are still working:
928
-
929
- ```javascript
930
- // 1. Do NOT disrupt other agents in the layer — they continue working
931
- // 2. Check module status in feature.json
932
- const moduleStatus = ba-reader.getModuleStatus({feature_id});
933
-
934
- // 3. If module has partial data (status = "in-progress"):
935
- // → Spawn new agent for same module (joins existing layer)
936
- // → New agent detects partial state and continues
937
- // → Include in prompt: "Resume specification — partial data exists in feature.json"
938
-
939
- // 4. Track retry count per module
940
- if (retryCount[moduleCode] >= 3) {
941
- Display: "Agent failed 3 times for module {moduleCode}."
942
- AskUserQuestion: "Fallback to inline interactive mode for this module?"
943
- // If yes: remove from pendingProposals, will handle inline after layer completes
944
- // If no: skip module, mark as "needs-review"
945
- }
946
- ```
947
-
948
- > **Key difference from sequential mode:** Other agents in the layer keep running.
949
- > The crashed module is retried independently without blocking the layer.
950
-
951
- ### Context Exhaustion on Team Lead
952
-
953
- The team lead should stay under 30% context usage. If approaching limits:
954
-
955
- 1. **Minimize presentation**: Show only entity/section counts, not full details
956
- 2. **Auto-approve**: If user has approved 3+ modules without changes, suggest auto-approve mode
957
- 3. **Skip detail view**: Don't read full feature.json into team lead context
958
-
959
- ### Resume After Session Crash
960
-
961
- If the entire session crashes:
962
-
963
- 1. User restarts `/business-analyse`
964
- 2. Step-00 detects existing feature.json with `status: "decomposed"` or partial modules
965
- 3. Reads `metadata.workflow.completedModules` to know which modules are done
966
- 4. Determines which layer to resume from:
967
- - Find the first layer where not all modules are in `completedModules`
968
- - Modules already completed in that layer are skipped
969
- 5. **Cleans up old team/task data** (§1a cleanup step) before creating new team
970
- 6. Creates new team (§1b — captures actual team name)
971
- 7. Spawns agents ONLY for incomplete modules in the current layer
972
- 8. Continues normally (parallel within layer, sequential between layers)
973
-
974
- ---
975
-
976
- ## Task List Coordination (T10)
977
-
978
- Create tasks for each module analysis before spawning teammates:
979
-
980
- ```javascript
981
- // Create tasks for each module before spawning agents
982
- for (const mod of moduleOrder) {
983
- TaskCreate({
984
- subject: `Specify ${mod} module`,
985
- description: `Propose business specification including entities, attributes, permissions, and workflows for ${mod}`,
986
- activeForm: `Analyzing ${mod}`
987
- });
988
- }
989
-
990
- // Teammates update task status when done
991
- TaskUpdate({ taskId: currentTaskId, status: 'completed' });
992
-
993
- // Team lead checks progress
994
- TaskList(); // View all tasks and their status
995
- ```
996
-
997
- ---
998
-
999
- ## Idle State Handling (T13)
1000
-
1001
- > **IMPORTANT:** Teammates go idle after every turn — this is completely normal.
1002
- > Idle simply means the teammate is waiting for input. An idle notification immediately
1003
- > after a message does NOT mean the teammate is done or has errors.
1004
- > Send a message to an idle teammate to wake it up.
1005
-
1006
- ---
1007
-
1008
- ## Team Config Discovery (T14)
1009
-
1010
- ```javascript
1011
- // Teammates can discover each other via team config:
1012
- // ~/.claude/teams/{team-name}/config.json
1013
- // Contains: members[] with name, agentId, agentType
1014
- // Always refer to teammates by NAME, not by UUID.
1015
- ```
1016
-
1017
- ---
1018
-
1019
- ## Decision Matrix
1020
-
1021
- | Condition | Action |
1022
- |-----------|--------|
1023
- | 1 module | NO team, classic inline execution |
1024
- | 2+ modules (single app) | Team mode (Propose & Review) |
1025
- | 2+ applications (project mode) | Application loop + per-app team mode |
1026
- | Modules in same dependency layer | Spawn ALL in parallel (single message) |
1027
- | Modules in different layers | Sequential — complete layer N before spawning layer N+1 |
1028
- | Layer with 1 module | Standard single-agent propose-review |
1029
- | Layer with 2+ modules | Pre-inject coordination notes + parallel spawn + batch review |
1030
- | Cross-module query (completed layer) | Answer from completedModulesSummary |
1031
- | Cross-module query (same layer, proposed) | Answer from receivedProposals |
1032
- | Cross-module query (same layer, working) | Relay to target agent |
1033
- | Circular cross-query (A↔B) | Team lead resolves autonomously |
1034
- | Agent error in parallel layer | Other agents continue; retry crashed module |
1035
- | User rejects 3 times | Offer fallback to inline interactive |
1036
- | Layer consistency check fails | Auto-fix via targeted REVISION |
1037
- | Context > 50% on team lead | Minimize presentation, suggest auto-approve |
1038
- | Session crash | Resume from feature.json + completedModules state |
1039
- | Project mode + all app modules done | Run per-app consolidation → advance to next app |
1040
- | Project mode + all apps done | Run cross-app consolidation (§5-bis) → unified handoff |
1041
- | Project mode + app has 1 module | Inline mode for that app (no team) |
1042
-
1043
- ---
1044
-
1045
- ## Message Protocol Summary
1046
-
1047
- ### Standard Messages (unchanged)
1048
-
1049
- | Message | Direction | Purpose |
1050
- |---------|-----------|---------|
1051
- | `PROPOSAL_READY:{moduleCode}\n{summary}` | agent → lead | Specification complete |
1052
- | `APPROVED:{moduleCode}` | lead → agent | User approved |
1053
- | `REVISION:{moduleCode}\n{feedback}` | lead → agent | User wants changes |
1054
- | `MODULE_COMPLETE:{moduleCode}` | agent → lead | After approval confirmed |
1055
- | `CONSOLIDATION_READY:{appName}\n{report}` | agent → lead | Consolidation done |
1056
- | `HANDOFF_READY:{appName}\n{report}` | agent → lead | Handoff done |
1057
- | `ERROR:{moduleCode}:{description}` | agent → lead | Blocking error |
1058
- | `shutdown_request` / `shutdown_response` | lead ↔ agent | Termination |
1059
-
1060
- ### Cross-Module Messages (NEW — for parallel execution)
1061
-
1062
- | Message | Direction | Purpose |
1063
- |---------|-----------|---------|
1064
- | `CROSS_MODULE_QUERY:{targetModule}\nQuestion:{q}\nContext:{ctx}` | agent → lead | Ask about same-layer module |
1065
- | `CROSS_MODULE_ANSWER:{requestingModule}\nAnswer:{a}` | lead → agent | Response to query |
1066
- | `CROSS_MODULE_QUERY_RELAY:{requestingModule}\nQuestion:{q}` | lead → target agent | Relay query to working agent |
1067
- | `CROSS_MODULE_ANSWER_RELAY:{requestingModule}\nAnswer:{a}` | target agent → lead | Response to relayed query |
1068
-
1069
- ---
1070
-
1071
- ## Token Budget Estimates
1072
-
1073
- | Phase | Agent | Est. Context % | Notes |
1074
- |-------|-------|---------------|-------|
1075
- | Init + Cadrage + Decomposition | Team lead (inline) | 20-30% | Sequential, interactive |
1076
- | Pre-spawn analysis (per layer) | Team lead | +1-3% per layer | Cross-module touchpoint detection |
1077
- | Module specification (per module) | mod-{code} agent | 40-60% | Parallel within layer, fresh context |
1078
- | Cross-module relay (per query) | Team lead | +1-2% per query | Lightweight relay |
1079
- | Layer review (per layer) | Team lead | +3-5% per layer | Proposals + consistency check |
1080
- | Consolidation | consolidation agent | 30-40% | Cross-module validation |
1081
- | Handoff | handoff agent | 40-50% | Artifact generation |
1082
- | **Total team lead** | — | **30-50%** | Same budget, more throughput |
1083
- | **Total per module agent** | — | **40-60%** | Independent contexts |
1084
-
1085
- **Key insight:** Team lead never exceeds 50% even with 10+ modules, because:
1086
- - Module specifications happen in separate parallel contexts
1087
- - Cross-module relay is lightweight (forward message, not re-analyze)
1088
- - Layer reviews are incremental (only current layer proposals)
1089
-
1090
- **Wall-clock time improvement:**
1091
- - Layer with 3 independent modules: 1x (parallel) vs 3x (sequential) = **66% reduction**
1092
- - Typical 4-module app (2 layers of 2): ~50% wall-clock reduction
1093
- - Full benefit: apps with many independent foundation modules (layer 0)