@polymorphism-tech/morph-spec 7.8.0 → 7.8.1

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 (166) hide show
  1. package/README.md +2 -2
  2. package/bin/validate.js +379 -379
  3. package/claude-plugin.json +1 -1
  4. package/docs/CHEATSHEET.md +1 -1
  5. package/docs/QUICKSTART.md +1 -1
  6. package/framework/commands/commit.md +166 -166
  7. package/framework/commands/morph-infra.md +215 -215
  8. package/framework/commands/morph-preflight.md +205 -205
  9. package/framework/commands/morph-troubleshoot.md +124 -124
  10. package/framework/hooks/claude-code/statusline.py +679 -679
  11. package/framework/hooks/claude-code/statusline.sh +11 -11
  12. package/framework/hooks/git/commit-msg/conventional-commits.sh +33 -33
  13. package/framework/hooks/git/pre-commit/agents.sh +25 -25
  14. package/framework/hooks/git/pre-commit/orchestrator.sh +64 -64
  15. package/framework/hooks/git/pre-commit/specs.sh +50 -50
  16. package/framework/hooks/git/pre-push/run-tests.sh +44 -44
  17. package/framework/hooks/shared/activity-logger.js +160 -160
  18. package/framework/hooks/shared/hook-response.js +45 -45
  19. package/framework/hooks/shared/payload-utils.js +78 -78
  20. package/framework/hooks/shared/stdin-reader.js +26 -26
  21. package/framework/rubrics/backend.json +41 -41
  22. package/framework/rules/ai-agents-standards.md +45 -45
  23. package/framework/rules/dotnet-templates.md +86 -86
  24. package/framework/rules/frontend-standards.md +13 -13
  25. package/framework/rules/infrastructure-standards.md +27 -27
  26. package/framework/rules/neon-standards.md +25 -25
  27. package/framework/rules/nextjs-standards.md +20 -20
  28. package/framework/rules/nextjs-templates.md +40 -40
  29. package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
  30. package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
  31. package/framework/skills/core/morph-brainstorming/SKILL.md +8 -4
  32. package/framework/skills/core/morph-eval/SKILL.md +1 -1
  33. package/framework/skills/core/morph-plan/SKILL.md +8 -4
  34. package/framework/skills/core/morph-proposal/SKILL.md +1 -1
  35. package/framework/skills/core/morph-review/SKILL.md +13 -7
  36. package/framework/skills/core/morph-stack-scan/SKILL.md +1 -1
  37. package/framework/skills/core/morph-standards/SKILL.md +1 -1
  38. package/framework/standards/ai-agents/agent-session.md +160 -160
  39. package/framework/standards/ai-agents/batching.md +193 -193
  40. package/framework/standards/ai-agents/context-providers.md +188 -188
  41. package/framework/standards/ai-agents/mcp-server.md +250 -250
  42. package/framework/standards/ai-agents/mcp-tools.md +197 -197
  43. package/framework/standards/ai-agents/middleware-patterns.md +207 -207
  44. package/framework/standards/ai-agents/modalities-image-gen.md +173 -173
  45. package/framework/standards/ai-agents/modalities-speech-to-text.md +171 -171
  46. package/framework/standards/ai-agents/modalities-text-to-speech.md +181 -181
  47. package/framework/standards/ai-agents/modalities-vision.md +201 -201
  48. package/framework/standards/ai-agents/multi-agent-patterns.md +155 -155
  49. package/framework/standards/ai-agents/production.md +275 -275
  50. package/framework/standards/ai-agents/prompts-in-db.md +214 -214
  51. package/framework/standards/ai-agents/providers/model-registry.md +158 -158
  52. package/framework/standards/ai-agents/service-tier-flex.md +135 -135
  53. package/framework/standards/ai-agents/structured-output.md +249 -249
  54. package/framework/standards/ai-agents/sweet-spot.md +109 -109
  55. package/framework/templates/IDE-SNIPPETS.md +262 -262
  56. package/framework/templates/code/dotnet/abstractions/api-endpoint.cs +7 -7
  57. package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +39 -39
  58. package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +68 -68
  59. package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +117 -117
  60. package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +95 -95
  61. package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +61 -61
  62. package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +107 -107
  63. package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +58 -58
  64. package/framework/templates/code/dotnet/contracts/contracts-vsa.cs +281 -281
  65. package/framework/templates/code/dotnet/database/migration.cs +83 -83
  66. package/framework/templates/code/dotnet/feature/endpoint.cs.hbs +21 -21
  67. package/framework/templates/code/dotnet/feature/request.cs.hbs +4 -4
  68. package/framework/templates/code/dotnet/feature/response.cs.hbs +4 -4
  69. package/framework/templates/code/dotnet/feature/validator.cs.hbs +15 -15
  70. package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +58 -58
  71. package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +91 -91
  72. package/framework/templates/code/typescript/contracts.ts +167 -167
  73. package/framework/templates/docs/clarifications.md +253 -253
  74. package/framework/templates/docs/schema-analysis.md +119 -119
  75. package/framework/templates/docs/ui-components.md +52 -52
  76. package/framework/templates/docs/ui-design-system.md +76 -76
  77. package/framework/templates/docs/ui-flows.md +167 -167
  78. package/framework/templates/docs/ui-mockups.md +98 -98
  79. package/framework/templates/feature/decisions.md +122 -122
  80. package/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +43 -43
  81. package/framework/templates/frontend/nextjs/client-component.tsx.hbs +26 -26
  82. package/framework/templates/frontend/nextjs/env.mjs.hbs +32 -32
  83. package/framework/templates/frontend/nextjs/feature-form.tsx.hbs +56 -56
  84. package/framework/templates/frontend/nextjs/page.tsx.hbs +22 -22
  85. package/framework/templates/frontend/nextjs/tsconfig.json.hbs +26 -26
  86. package/framework/templates/frontend/nextjs/use-feature.ts.hbs +54 -54
  87. package/framework/templates/infrastructure/docker/Dockerfile.template +58 -58
  88. package/framework/templates/infrastructure/docker/docker-compose.template.yml +50 -50
  89. package/framework/templates/infrastructure/docker/dockerfile-api.dockerfile +38 -38
  90. package/framework/templates/infrastructure/docker/dockerfile-web.dockerfile +48 -48
  91. package/framework/templates/infrastructure/github/README.md +56 -56
  92. package/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +45 -45
  93. package/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +27 -27
  94. package/framework/templates/infrastructure/github/workflows/docker-build-push.yml.hbs +59 -59
  95. package/framework/templates/infrastructure/github/workflows/dotnet-build.yml.hbs +39 -39
  96. package/framework/templates/integrations/asaas-client.cs +387 -387
  97. package/framework/templates/integrations/asaas-webhook.cs +351 -351
  98. package/framework/templates/meta-prompts/fusion/fusion-agent.md +76 -76
  99. package/framework/templates/meta-prompts/fusion/fusion-aggregator.md +100 -100
  100. package/framework/templates/meta-prompts/parallel-workers/parallel-coordinator.md +113 -113
  101. package/framework/templates/meta-prompts/validators/pre-commit-validator.md +95 -95
  102. package/framework/templates/project/validate.js +120 -120
  103. package/framework/templates/state.template.json +17 -17
  104. package/framework/templates/ui/design-system.css +226 -226
  105. package/package.json +1 -1
  106. package/src/commands/dashboard/dashboard.js +53 -53
  107. package/src/commands/index.js +13 -13
  108. package/src/commands/mcp/mcp-setup.js +519 -519
  109. package/src/commands/project/checkpoint.js +209 -209
  110. package/src/commands/project/update.js +7 -4
  111. package/src/core/state/phase-state-machine.js +197 -197
  112. package/src/core/templates/template-renderer.js +477 -477
  113. package/src/dashboard/app/components/DetailPanel.jsx +11 -11
  114. package/src/dashboard/app/components/FlowGraph.jsx +17 -17
  115. package/src/dashboard/app/components/SearchFilter.jsx +22 -22
  116. package/src/dashboard/app/hooks/useDetailPanel.js +15 -15
  117. package/src/dashboard/app/main.jsx +13 -13
  118. package/src/dashboard/app/pages/AgentMap.jsx +370 -370
  119. package/src/dashboard/app/pages/HookInspector.jsx +418 -418
  120. package/src/dashboard/app/pages/LiveState.jsx +239 -239
  121. package/src/dashboard/app/pages/PhasePipeline.jsx +408 -408
  122. package/src/dashboard/app/pages/RulesMap.jsx +273 -273
  123. package/src/dashboard/app/pages/SkillsLibrary.jsx +366 -366
  124. package/src/dashboard/app/pages/Standards.jsx +332 -332
  125. package/src/dashboard/app/styles/index.css +47 -47
  126. package/src/dashboard/index.html +12 -12
  127. package/src/dashboard/package.json +24 -24
  128. package/src/dashboard/scanner/hooks-scanner.js +41 -41
  129. package/src/dashboard/scanner/phases-scanner.js +15 -15
  130. package/src/dashboard/scanner/rubrics-scanner.js +12 -12
  131. package/src/dashboard/scanner/rules-scanner.js +37 -37
  132. package/src/dashboard/scanner/skills-scanner.js +43 -43
  133. package/src/dashboard/scanner/squads-scanner.js +13 -13
  134. package/src/dashboard/scanner/standards-scanner.js +26 -26
  135. package/src/dashboard/vite-plugin-morph-data.js +17 -17
  136. package/src/dashboard/vite.config.js +24 -24
  137. package/src/lib/agents/metrics-aggregator.js +56 -56
  138. package/src/lib/agents/metrics-calculator.js +125 -125
  139. package/src/lib/agents/output-collector.js +73 -73
  140. package/src/lib/detectors/claude-config-detector.js +152 -152
  141. package/src/lib/detectors/design-system-detector.js +231 -231
  142. package/src/lib/detectors/index.js +217 -217
  143. package/src/lib/generators/architecture-scanner.js +639 -639
  144. package/src/lib/generators/design-system-generator.js +508 -508
  145. package/src/lib/generators/index.js +13 -13
  146. package/src/lib/generators/settings-generator.js +209 -209
  147. package/src/lib/hooks/hook-executor.js +167 -167
  148. package/src/lib/installers/mcp-installer.js +719 -719
  149. package/src/lib/tasks/task-classifier.js +30 -30
  150. package/src/lib/tasks/task-parser.js +209 -209
  151. package/src/lib/tasks/test-runner.js +81 -81
  152. package/src/lib/validators/architecture/architecture-validator.js +259 -259
  153. package/src/lib/validators/checkpoint-persistence.js +39 -39
  154. package/src/lib/validators/contracts/contract-compliance-validator.js +274 -274
  155. package/src/lib/validators/css/css-validator.js +340 -340
  156. package/src/lib/validators/packages/package-validator.js +347 -347
  157. package/src/lib/validators/shared/emit-validator-dispatch.js +14 -14
  158. package/src/lib/validators/shared/issue-counter.js +14 -14
  159. package/src/lib/validators/validation-runner.js +349 -349
  160. package/src/scripts/setup-infra.js +383 -383
  161. package/src/utils/agent-id-mapper.js +11 -11
  162. package/src/utils/banner.js +1 -2
  163. package/src/utils/claude-settings-manager.js +300 -300
  164. package/src/utils/skills-installer.js +172 -172
  165. package/framework/templates/.idea/morph-templates.xml +0 -92
  166. package/framework/templates/.vscode/morph-templates.code-snippets +0 -186
@@ -1,383 +1,383 @@
1
- /**
2
- * setup-infra.js
3
- *
4
- * Headless infrastructure setup for MORPH-SPEC.
5
- * Extracted from init.js (steps 1-10) so it can be called by the
6
- * /morph-init Claude Code skill via `morph-spec setup-infra` without
7
- * interactive prompts or stack detection.
8
- *
9
- * Usage:
10
- * import { setupInfra } from './setup-infra.js';
11
- * await setupInfra('/path/to/project');
12
- */
13
-
14
- import { join, dirname } from 'path';
15
- import { fileURLToPath } from 'url';
16
- import { execSync } from 'child_process';
17
- import { readFileSync, readdirSync, copyFileSync, unlinkSync } from 'fs';
18
- import {
19
- copyDirectory,
20
- copyFile,
21
- pathExists,
22
- writeJson,
23
- ensureDir,
24
- writeFile,
25
- updateGitignore
26
- } from '../utils/file-copier.js';
27
- import { parseStacks, getProjectTags, shouldInstall } from '../lib/stack-filter.js';
28
- import { injectMorphImport } from '../utils/claude-md-injector.js';
29
- import { saveProjectMorphVersion, getInstalledCLIVersion } from '../utils/version-checker.js';
30
- import { installClaudeHooks, installGlobalStatusline } from '../utils/claude-settings-manager.js';
31
- import { installSkills } from '../utils/skills-installer.js';
32
- import { installAgents, installDomainAgents } from '../utils/agents-installer.js';
33
-
34
- const FRAMEWORK_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'framework');
35
-
36
- const REQUIRED_PLUGINS = [
37
- 'superpowers@claude-plugins-official',
38
- 'context7@claude-plugins-official',
39
- ];
40
-
41
- async function installRequiredPlugins(log, exec) {
42
- log('Step 0: Installing required Claude Code plugins...');
43
- for (const plugin of REQUIRED_PLUGINS) {
44
- try {
45
- exec(`claude plugin install ${plugin}`, { stdio: 'inherit' });
46
- log(` ✓ ${plugin}`);
47
- } catch {
48
- log(` ⚠ Failed to install ${plugin} — install manually: claude plugin install ${plugin}`);
49
- }
50
- }
51
- }
52
-
53
- /**
54
- * Install only stack-matching rules from rulesSrc to rulesDest.
55
- * Also removes orphan rules in rulesDest that are no longer in the install set.
56
- *
57
- * @param {string} rulesSrc - Source rules directory (framework/rules/)
58
- * @param {string} rulesDest - Destination rules directory (.claude/rules/)
59
- * @param {string[]} projectTags - Stack tags from config (e.g., ['dotnet', 'blazor'])
60
- */
61
- export function installRulesForStack(rulesSrc, rulesDest, projectTags) {
62
- const sourceFiles = readdirSync(rulesSrc).filter(f => f.endsWith('.md'));
63
- const installed = new Set();
64
-
65
- for (const file of sourceFiles) {
66
- const content = readFileSync(join(rulesSrc, file), 'utf-8');
67
- const stacks = parseStacks(content);
68
- if (shouldInstall(stacks, projectTags)) {
69
- copyFileSync(join(rulesSrc, file), join(rulesDest, file));
70
- installed.add(file);
71
- }
72
- }
73
-
74
- // Cleanup orphans
75
- for (const file of readdirSync(rulesDest).filter(f => f.endsWith('.md'))) {
76
- if (!installed.has(file)) {
77
- unlinkSync(join(rulesDest, file));
78
- }
79
- }
80
- }
81
-
82
- /**
83
- * Re-install only stack-aware assets (rules, skills, agents) using current config.json.
84
- * Skips infrastructure steps (dirs, framework copy, hooks).
85
- *
86
- * @param {string} targetPath - Absolute path to the target project directory
87
- * @param {Function} log - Logging function
88
- * @returns {{ agentCounts: object, domainCounts: object, projectTags: string[] }}
89
- */
90
- async function installStackAwareAssets(targetPath, log) {
91
- const configPath = join(targetPath, '.morph', 'config', 'config.json');
92
- let projectTags = [];
93
- if (await pathExists(configPath)) {
94
- try {
95
- // BOM-tolerant: a config.json hand-edited on Windows (PS 5.1 Out-File)
96
- // carries a UTF-8 BOM; without stripping it this parse fails silently
97
- // and only universal personas get installed.
98
- const config = JSON.parse(readFileSync(configPath, 'utf-8').replace(/^/, ''));
99
- projectTags = getProjectTags(config);
100
- } catch { /* ignore malformed config */ }
101
- }
102
-
103
- log('Installing stack-filtered rules...');
104
- const claudeDest = join(targetPath, '.claude');
105
- const rulesSrc = join(FRAMEWORK_DIR, 'rules');
106
- const rulesDest = join(claudeDest, 'rules');
107
- if (await pathExists(rulesSrc)) {
108
- await ensureDir(rulesDest);
109
- installRulesForStack(rulesSrc, rulesDest, projectTags);
110
- }
111
-
112
- log('Installing skills...');
113
- await installSkills(targetPath, { projectTags });
114
-
115
- log('Installing agents...');
116
- const agentCounts = await installAgents(targetPath, FRAMEWORK_DIR, { projectTags });
117
-
118
- log('Installing domain agents...');
119
- const domainCounts = await installDomainAgents(targetPath, FRAMEWORK_DIR, { projectTags });
120
-
121
- return { agentCounts, domainCounts, projectTags };
122
- }
123
-
124
- /**
125
- * Rewrite the managed personas block in .claude/CLAUDE.md with the agents
126
- * ACTUALLY installed (derived list — never a hand-written promise).
127
- * No markers / no file → no-op (fail-open).
128
- * Exported so `morph-spec update` derives the same block on upgrades.
129
- *
130
- * @param {string} claudeMdPath - Absolute path to the installed .claude/CLAUDE.md
131
- * @param {Array<{ name: string, title: string, domains: string[] }>} agents
132
- */
133
- export async function updateClaudeMdAgentsBlock(claudeMdPath, agents = []) {
134
- if (!(await pathExists(claudeMdPath))) return;
135
- const START = '<!-- morph-agents:start -->';
136
- const END = '<!-- morph-agents:end -->';
137
- const content = readFileSync(claudeMdPath, 'utf-8');
138
- if (!content.includes(START) || !content.includes(END)) return;
139
-
140
- const list = agents.length > 0
141
- ? agents.map(a => `- \`${a.name}\` — ${a.title}${a.domains?.length ? ` (${a.domains.join(', ')})` : ''}`).join('\n')
142
- : '_Nenhuma persona instalada — configure `project.stack` em `.morph/config/config.json` e rode `morph-spec setup-infra --reinstall`._';
143
-
144
- const block = `${START}\n**Personas instaladas neste projeto** (derivado de agents.json na última instalação):\n\n${list}\n${END}`;
145
- const updated = content.replace(
146
- new RegExp(`${START}[\\s\\S]*?${END}`),
147
- block
148
- );
149
- await writeFile(claudeMdPath, updated);
150
- }
151
-
152
- /**
153
- * Installs MORPH-SPEC infrastructure into the target project directory.
154
- * Headless — no prompts, no spinner (suppressed when MORPH_QUIET=1), no stack detection.
155
- *
156
- * @param {string} targetPath - Absolute path to the target project directory
157
- * @param {object} options
158
- * @param {Function} options._exec - exec function (for testing)
159
- * @param {boolean} options.reinstall - If true, only re-install stack-aware assets (rules, skills, agents)
160
- */
161
- export async function setupInfra(targetPath, { _exec = execSync, reinstall = false } = {}) {
162
- const quiet = process.env.MORPH_QUIET === '1';
163
-
164
- function log(msg) {
165
- if (!quiet) process.stdout.write(msg + '\n');
166
- }
167
-
168
- // --- Reinstall mode: only re-install stack-aware assets ---
169
- if (reinstall) {
170
- log('setup-infra (reinstall): re-installing stack-aware assets...');
171
- const { agentCounts, domainCounts } = await installStackAwareAssets(targetPath, log);
172
- // Keep the derived personas list in .claude/CLAUDE.md in sync with what
173
- // was actually (re)installed.
174
- await updateClaudeMdAgentsBlock(join(targetPath, '.claude', 'CLAUDE.md'), agentCounts?.agents ?? []);
175
- log('setup-infra (reinstall): complete.');
176
- return {
177
- agents: {
178
- tier1: agentCounts?.tier1 ?? 0,
179
- tier2: agentCounts?.tier2 ?? 0,
180
- specialists: domainCounts?.specialists ?? 0,
181
- },
182
- };
183
- }
184
-
185
- // --- 0. Install required Claude Code plugins ---
186
- await installRequiredPlugins(log, _exec);
187
-
188
- // --- 1. Inject @import into root CLAUDE.md (preserves user content) ---
189
- log('Step 1: Setting up CLAUDE.md...');
190
- const claudeMdSrc = join(FRAMEWORK_DIR, 'CLAUDE.md');
191
- const claudeMdDest = join(targetPath, 'CLAUDE.md');
192
- const importResult = await injectMorphImport(claudeMdDest);
193
- log(` ✓ Root CLAUDE.md: ${importResult}`);
194
-
195
- // --- 2. Create .morph directory structure ---
196
- log('Step 2: Creating .morph structure...');
197
- const morphPath = join(targetPath, '.morph');
198
- const configDir = join(morphPath, 'config');
199
- const frameworkDestDir = join(morphPath, 'framework');
200
- const contextDir = join(morphPath, 'context');
201
- const featuresDir = join(morphPath, 'features');
202
- const checkpointsDir = join(morphPath, 'checkpoints');
203
- const memoryDir = join(morphPath, 'memory');
204
- const archiveDir = join(morphPath, 'archive');
205
-
206
- await ensureDir(configDir);
207
- await ensureDir(frameworkDestDir);
208
- await ensureDir(contextDir);
209
- await ensureDir(featuresDir);
210
- await ensureDir(checkpointsDir);
211
- await ensureDir(memoryDir);
212
- await ensureDir(archiveDir);
213
-
214
- // --- 3. Write minimal config.json (only if not exists) ---
215
- log('Step 3: Writing config.json...');
216
- const configPath = join(configDir, 'config.json');
217
- if (!(await pathExists(configPath))) {
218
- const dirName = targetPath.split(/[\/]/).pop();
219
- const config = {
220
- framework: 'global',
221
- frameworkVersion: getInstalledCLIVersion(),
222
- trust: 'auto',
223
- project: {
224
- name: dirName
225
- }
226
- };
227
- await writeJson(configPath, config);
228
- }
229
-
230
- // --- 4. Write placeholder context/README.md (only if not exists) ---
231
- log('Step 4: Writing context/README.md...');
232
- const contextReadmePath = join(contextDir, 'README.md');
233
- if (!(await pathExists(contextReadmePath))) {
234
- const dirName = targetPath.split(/[\/]/).pop();
235
- const readmeContent = `# ${dirName} — Project Context\n\nRun \`morph-spec context refresh\` to generate architecture context.\n`;
236
- await writeFile(contextReadmePath, readmeContent);
237
- }
238
-
239
- // --- 5. Copy framework/templates → .morph/framework/templates ---
240
- log('Step 5: Copying framework templates...');
241
- const frameworkTemplatesSrc = join(FRAMEWORK_DIR, 'templates');
242
- const templatesDest = join(frameworkDestDir, 'templates');
243
- if (await pathExists(frameworkTemplatesSrc)) {
244
- await copyDirectory(frameworkTemplatesSrc, templatesDest);
245
- } else {
246
- await ensureDir(templatesDest);
247
- }
248
-
249
- // --- 6. Copy framework/standards → .morph/framework/standards ---
250
- log('Step 6: Copying framework standards...');
251
- const frameworkStandardsSrc = join(FRAMEWORK_DIR, 'standards');
252
- const frameworkStandardsDest = join(frameworkDestDir, 'standards');
253
- if (await pathExists(frameworkStandardsSrc)) {
254
- await copyDirectory(frameworkStandardsSrc, frameworkStandardsDest);
255
- }
256
-
257
- // --- 7. Copy framework/hooks → .morph/framework/hooks ---
258
- log('Step 7: Copying hooks...');
259
- const hooksSrc = join(FRAMEWORK_DIR, 'hooks');
260
- const hooksDest = join(frameworkDestDir, 'hooks');
261
- if (await pathExists(hooksSrc)) {
262
- await copyDirectory(hooksSrc, hooksDest);
263
- }
264
-
265
- // --- 7b. Copy framework/rubrics → .morph/framework/rubrics ---
266
- log('Step 7b: Copying rubrics...');
267
- const rubricsSrc = join(FRAMEWORK_DIR, 'rubrics');
268
- const rubricsDest = join(frameworkDestDir, 'rubrics');
269
- if (await pathExists(rubricsSrc)) {
270
- await copyDirectory(rubricsSrc, rubricsDest);
271
- }
272
-
273
- // --- 7c. Copy framework/evals → .morph/framework/evals ---
274
- // Rubricas .md (bandas 0-10) + trace-schema.md — referenciadas por
275
- // morph-eval/morph-review/agents.json via .morph/framework/evals/.
276
- log('Step 7c: Copying evals (rubrics .md + trace schema)...');
277
- const evalsSrc = join(FRAMEWORK_DIR, 'evals');
278
- const evalsDest = join(frameworkDestDir, 'evals');
279
- if (await pathExists(evalsSrc)) {
280
- await copyDirectory(evalsSrc, evalsDest);
281
- }
282
-
283
- // --- 8. Copy framework/agents.json → .morph/framework/agents.json ---
284
- log('Step 8: Copying agents.json...');
285
- const agentsSrc = join(FRAMEWORK_DIR, 'agents.json');
286
- const agentsDest = join(frameworkDestDir, 'agents.json');
287
- if (await pathExists(agentsSrc)) {
288
- await copyFile(agentsSrc, agentsDest);
289
- }
290
-
291
- // --- 8b. Copy framework/MORPH.md → .morph/framework/MORPH.md ---
292
- log('Step 8b: Copying MORPH.md (NLH charter)...');
293
- const morphMdSrc = join(FRAMEWORK_DIR, 'MORPH.md');
294
- const morphMdDest = join(frameworkDestDir, 'MORPH.md');
295
- if (await pathExists(morphMdSrc)) {
296
- await copyFile(morphMdSrc, morphMdDest);
297
- }
298
-
299
- // --- 8c. Copy framework/phases.json → .morph/framework/phases.json ---
300
- log('Step 8c: Copying phases.json...');
301
- const phasesSrc = join(FRAMEWORK_DIR, 'phases.json');
302
- const phasesDest = join(frameworkDestDir, 'phases.json');
303
- if (await pathExists(phasesSrc)) {
304
- await copyFile(phasesSrc, phasesDest);
305
- }
306
-
307
- // --- 8d. Copy framework/schemas → .morph/framework/schemas (JSON schemas) ---
308
- log('Step 8d: Copying schemas...');
309
- const schemasSrc = join(FRAMEWORK_DIR, 'schemas');
310
- const schemasDest = join(frameworkDestDir, 'schemas');
311
- if (await pathExists(schemasSrc)) {
312
- await copyDirectory(schemasSrc, schemasDest);
313
- }
314
-
315
- // --- 9. Copy framework/commands → .claude/commands ---
316
- log('Step 9: Setting up Claude Code integration...');
317
- const claudeDest = join(targetPath, '.claude');
318
- const commandsSrc = join(FRAMEWORK_DIR, 'commands');
319
- const commandsDest = join(claudeDest, 'commands');
320
- if (await pathExists(commandsSrc)) {
321
- await copyDirectory(commandsSrc, commandsDest);
322
- }
323
-
324
- // --- 10-13. Install stack-aware assets (rules, skills, agents) ---
325
- log('Steps 10-13: Installing stack-aware assets...');
326
- const { agentCounts, domainCounts } = await installStackAwareAssets(targetPath, log);
327
-
328
- // --- 14. Copy framework/CLAUDE.md → .claude/CLAUDE.md (morph-owned, gitignored) ---
329
- log('Step 14: Installing .claude/CLAUDE.md...');
330
- const runtimeClaudeMdDest = join(claudeDest, 'CLAUDE.md');
331
- if (await pathExists(claudeMdSrc)) {
332
- await copyFile(claudeMdSrc, runtimeClaudeMdDest);
333
- // Derive the personas section from what step 10-13 actually installed.
334
- await updateClaudeMdAgentsBlock(runtimeClaudeMdDest, agentCounts?.agents ?? []);
335
- }
336
-
337
- // --- 15. installGlobalStatusline (non-critical) ---
338
- log('Step 15: Installing global statusline...');
339
- const HOOKS_SRC = join(FRAMEWORK_DIR, 'hooks', 'claude-code');
340
- try {
341
- await installGlobalStatusline(HOOKS_SRC);
342
- } catch {
343
- // Non-critical — global ~/.claude may not be writable
344
- }
345
-
346
- // --- 16. installClaudeHooks ---
347
- log('Step 16: Installing Claude Code hooks...');
348
- await installClaudeHooks(targetPath);
349
-
350
- // --- 17. saveProjectMorphVersion ---
351
- log('Step 17: Saving version info...');
352
- const cliVersion = getInstalledCLIVersion();
353
- await saveProjectMorphVersion(targetPath, cliVersion);
354
-
355
- // --- 18. updateGitignore ---
356
- log('Step 18: Updating .gitignore...');
357
- await updateGitignore(targetPath);
358
-
359
- // --- 19. Initialize state.json (only if not exists) ---
360
- log('Step 19: Initializing state.json...');
361
- const statePath = join(morphPath, 'state.json');
362
- if (!(await pathExists(statePath))) {
363
- const dirName = targetPath.split(/[\/\\]/).pop();
364
- const now = new Date().toISOString();
365
- await writeJson(statePath, {
366
- version: '5.0.0',
367
- project: { name: dirName, type: 'unknown', createdAt: now, updatedAt: now },
368
- features: {},
369
- threads: {},
370
- metadata: { totalFeatures: 0, completedFeatures: 0, totalTimeSpent: 0, lastUpdated: now }
371
- });
372
- }
373
-
374
- log('setup-infra: complete.');
375
-
376
- return {
377
- agents: {
378
- tier1: agentCounts?.tier1 ?? 0,
379
- tier2: agentCounts?.tier2 ?? 0,
380
- specialists: domainCounts?.specialists ?? 0,
381
- },
382
- };
383
- }
1
+ /**
2
+ * setup-infra.js
3
+ *
4
+ * Headless infrastructure setup for MORPH-SPEC.
5
+ * Extracted from init.js (steps 1-10) so it can be called by the
6
+ * /morph-init Claude Code skill via `morph-spec setup-infra` without
7
+ * interactive prompts or stack detection.
8
+ *
9
+ * Usage:
10
+ * import { setupInfra } from './setup-infra.js';
11
+ * await setupInfra('/path/to/project');
12
+ */
13
+
14
+ import { join, dirname } from 'path';
15
+ import { fileURLToPath } from 'url';
16
+ import { execSync } from 'child_process';
17
+ import { readFileSync, readdirSync, copyFileSync, unlinkSync } from 'fs';
18
+ import {
19
+ copyDirectory,
20
+ copyFile,
21
+ pathExists,
22
+ writeJson,
23
+ ensureDir,
24
+ writeFile,
25
+ updateGitignore
26
+ } from '../utils/file-copier.js';
27
+ import { parseStacks, getProjectTags, shouldInstall } from '../lib/stack-filter.js';
28
+ import { injectMorphImport } from '../utils/claude-md-injector.js';
29
+ import { saveProjectMorphVersion, getInstalledCLIVersion } from '../utils/version-checker.js';
30
+ import { installClaudeHooks, installGlobalStatusline } from '../utils/claude-settings-manager.js';
31
+ import { installSkills } from '../utils/skills-installer.js';
32
+ import { installAgents, installDomainAgents } from '../utils/agents-installer.js';
33
+
34
+ const FRAMEWORK_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'framework');
35
+
36
+ const REQUIRED_PLUGINS = [
37
+ 'superpowers@claude-plugins-official',
38
+ 'context7@claude-plugins-official',
39
+ ];
40
+
41
+ async function installRequiredPlugins(log, exec) {
42
+ log('Step 0: Installing required Claude Code plugins...');
43
+ for (const plugin of REQUIRED_PLUGINS) {
44
+ try {
45
+ exec(`claude plugin install ${plugin}`, { stdio: 'inherit' });
46
+ log(` ✓ ${plugin}`);
47
+ } catch {
48
+ log(` ⚠ Failed to install ${plugin} — install manually: claude plugin install ${plugin}`);
49
+ }
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Install only stack-matching rules from rulesSrc to rulesDest.
55
+ * Also removes orphan rules in rulesDest that are no longer in the install set.
56
+ *
57
+ * @param {string} rulesSrc - Source rules directory (framework/rules/)
58
+ * @param {string} rulesDest - Destination rules directory (.claude/rules/)
59
+ * @param {string[]} projectTags - Stack tags from config (e.g., ['dotnet', 'blazor'])
60
+ */
61
+ export function installRulesForStack(rulesSrc, rulesDest, projectTags) {
62
+ const sourceFiles = readdirSync(rulesSrc).filter(f => f.endsWith('.md'));
63
+ const installed = new Set();
64
+
65
+ for (const file of sourceFiles) {
66
+ const content = readFileSync(join(rulesSrc, file), 'utf-8');
67
+ const stacks = parseStacks(content);
68
+ if (shouldInstall(stacks, projectTags)) {
69
+ copyFileSync(join(rulesSrc, file), join(rulesDest, file));
70
+ installed.add(file);
71
+ }
72
+ }
73
+
74
+ // Cleanup orphans
75
+ for (const file of readdirSync(rulesDest).filter(f => f.endsWith('.md'))) {
76
+ if (!installed.has(file)) {
77
+ unlinkSync(join(rulesDest, file));
78
+ }
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Re-install only stack-aware assets (rules, skills, agents) using current config.json.
84
+ * Skips infrastructure steps (dirs, framework copy, hooks).
85
+ *
86
+ * @param {string} targetPath - Absolute path to the target project directory
87
+ * @param {Function} log - Logging function
88
+ * @returns {{ agentCounts: object, domainCounts: object, projectTags: string[] }}
89
+ */
90
+ async function installStackAwareAssets(targetPath, log) {
91
+ const configPath = join(targetPath, '.morph', 'config', 'config.json');
92
+ let projectTags = [];
93
+ if (await pathExists(configPath)) {
94
+ try {
95
+ // BOM-tolerant: a config.json hand-edited on Windows (PS 5.1 Out-File)
96
+ // carries a UTF-8 BOM; without stripping it this parse fails silently
97
+ // and only universal personas get installed.
98
+ const config = JSON.parse(readFileSync(configPath, 'utf-8').replace(/^/, ''));
99
+ projectTags = getProjectTags(config);
100
+ } catch { /* ignore malformed config */ }
101
+ }
102
+
103
+ log('Installing stack-filtered rules...');
104
+ const claudeDest = join(targetPath, '.claude');
105
+ const rulesSrc = join(FRAMEWORK_DIR, 'rules');
106
+ const rulesDest = join(claudeDest, 'rules');
107
+ if (await pathExists(rulesSrc)) {
108
+ await ensureDir(rulesDest);
109
+ installRulesForStack(rulesSrc, rulesDest, projectTags);
110
+ }
111
+
112
+ log('Installing skills...');
113
+ await installSkills(targetPath, { projectTags });
114
+
115
+ log('Installing agents...');
116
+ const agentCounts = await installAgents(targetPath, FRAMEWORK_DIR, { projectTags });
117
+
118
+ log('Installing domain agents...');
119
+ const domainCounts = await installDomainAgents(targetPath, FRAMEWORK_DIR, { projectTags });
120
+
121
+ return { agentCounts, domainCounts, projectTags };
122
+ }
123
+
124
+ /**
125
+ * Rewrite the managed personas block in .claude/CLAUDE.md with the agents
126
+ * ACTUALLY installed (derived list — never a hand-written promise).
127
+ * No markers / no file → no-op (fail-open).
128
+ * Exported so `morph-spec update` derives the same block on upgrades.
129
+ *
130
+ * @param {string} claudeMdPath - Absolute path to the installed .claude/CLAUDE.md
131
+ * @param {Array<{ name: string, title: string, domains: string[] }>} agents
132
+ */
133
+ export async function updateClaudeMdAgentsBlock(claudeMdPath, agents = []) {
134
+ if (!(await pathExists(claudeMdPath))) return;
135
+ const START = '<!-- morph-agents:start -->';
136
+ const END = '<!-- morph-agents:end -->';
137
+ const content = readFileSync(claudeMdPath, 'utf-8');
138
+ if (!content.includes(START) || !content.includes(END)) return;
139
+
140
+ const list = agents.length > 0
141
+ ? agents.map(a => `- \`${a.name}\` — ${a.title}${a.domains?.length ? ` (${a.domains.join(', ')})` : ''}`).join('\n')
142
+ : '_Nenhuma persona instalada — configure `project.stack` em `.morph/config/config.json` e rode `morph-spec setup-infra --reinstall`._';
143
+
144
+ const block = `${START}\n**Personas instaladas neste projeto** (derivado de agents.json na última instalação):\n\n${list}\n${END}`;
145
+ const updated = content.replace(
146
+ new RegExp(`${START}[\\s\\S]*?${END}`),
147
+ block
148
+ );
149
+ await writeFile(claudeMdPath, updated);
150
+ }
151
+
152
+ /**
153
+ * Installs MORPH-SPEC infrastructure into the target project directory.
154
+ * Headless — no prompts, no spinner (suppressed when MORPH_QUIET=1), no stack detection.
155
+ *
156
+ * @param {string} targetPath - Absolute path to the target project directory
157
+ * @param {object} options
158
+ * @param {Function} options._exec - exec function (for testing)
159
+ * @param {boolean} options.reinstall - If true, only re-install stack-aware assets (rules, skills, agents)
160
+ */
161
+ export async function setupInfra(targetPath, { _exec = execSync, reinstall = false } = {}) {
162
+ const quiet = process.env.MORPH_QUIET === '1';
163
+
164
+ function log(msg) {
165
+ if (!quiet) process.stdout.write(msg + '\n');
166
+ }
167
+
168
+ // --- Reinstall mode: only re-install stack-aware assets ---
169
+ if (reinstall) {
170
+ log('setup-infra (reinstall): re-installing stack-aware assets...');
171
+ const { agentCounts, domainCounts } = await installStackAwareAssets(targetPath, log);
172
+ // Keep the derived personas list in .claude/CLAUDE.md in sync with what
173
+ // was actually (re)installed.
174
+ await updateClaudeMdAgentsBlock(join(targetPath, '.claude', 'CLAUDE.md'), agentCounts?.agents ?? []);
175
+ log('setup-infra (reinstall): complete.');
176
+ return {
177
+ agents: {
178
+ tier1: agentCounts?.tier1 ?? 0,
179
+ tier2: agentCounts?.tier2 ?? 0,
180
+ specialists: domainCounts?.specialists ?? 0,
181
+ },
182
+ };
183
+ }
184
+
185
+ // --- 0. Install required Claude Code plugins ---
186
+ await installRequiredPlugins(log, _exec);
187
+
188
+ // --- 1. Inject @import into root CLAUDE.md (preserves user content) ---
189
+ log('Step 1: Setting up CLAUDE.md...');
190
+ const claudeMdSrc = join(FRAMEWORK_DIR, 'CLAUDE.md');
191
+ const claudeMdDest = join(targetPath, 'CLAUDE.md');
192
+ const importResult = await injectMorphImport(claudeMdDest);
193
+ log(` ✓ Root CLAUDE.md: ${importResult}`);
194
+
195
+ // --- 2. Create .morph directory structure ---
196
+ log('Step 2: Creating .morph structure...');
197
+ const morphPath = join(targetPath, '.morph');
198
+ const configDir = join(morphPath, 'config');
199
+ const frameworkDestDir = join(morphPath, 'framework');
200
+ const contextDir = join(morphPath, 'context');
201
+ const featuresDir = join(morphPath, 'features');
202
+ const checkpointsDir = join(morphPath, 'checkpoints');
203
+ const memoryDir = join(morphPath, 'memory');
204
+ const archiveDir = join(morphPath, 'archive');
205
+
206
+ await ensureDir(configDir);
207
+ await ensureDir(frameworkDestDir);
208
+ await ensureDir(contextDir);
209
+ await ensureDir(featuresDir);
210
+ await ensureDir(checkpointsDir);
211
+ await ensureDir(memoryDir);
212
+ await ensureDir(archiveDir);
213
+
214
+ // --- 3. Write minimal config.json (only if not exists) ---
215
+ log('Step 3: Writing config.json...');
216
+ const configPath = join(configDir, 'config.json');
217
+ if (!(await pathExists(configPath))) {
218
+ const dirName = targetPath.split(/[\/]/).pop();
219
+ const config = {
220
+ framework: 'global',
221
+ frameworkVersion: getInstalledCLIVersion(),
222
+ trust: 'auto',
223
+ project: {
224
+ name: dirName
225
+ }
226
+ };
227
+ await writeJson(configPath, config);
228
+ }
229
+
230
+ // --- 4. Write placeholder context/README.md (only if not exists) ---
231
+ log('Step 4: Writing context/README.md...');
232
+ const contextReadmePath = join(contextDir, 'README.md');
233
+ if (!(await pathExists(contextReadmePath))) {
234
+ const dirName = targetPath.split(/[\/]/).pop();
235
+ const readmeContent = `# ${dirName} — Project Context\n\nRun \`morph-spec context refresh\` to generate architecture context.\n`;
236
+ await writeFile(contextReadmePath, readmeContent);
237
+ }
238
+
239
+ // --- 5. Copy framework/templates → .morph/framework/templates ---
240
+ log('Step 5: Copying framework templates...');
241
+ const frameworkTemplatesSrc = join(FRAMEWORK_DIR, 'templates');
242
+ const templatesDest = join(frameworkDestDir, 'templates');
243
+ if (await pathExists(frameworkTemplatesSrc)) {
244
+ await copyDirectory(frameworkTemplatesSrc, templatesDest);
245
+ } else {
246
+ await ensureDir(templatesDest);
247
+ }
248
+
249
+ // --- 6. Copy framework/standards → .morph/framework/standards ---
250
+ log('Step 6: Copying framework standards...');
251
+ const frameworkStandardsSrc = join(FRAMEWORK_DIR, 'standards');
252
+ const frameworkStandardsDest = join(frameworkDestDir, 'standards');
253
+ if (await pathExists(frameworkStandardsSrc)) {
254
+ await copyDirectory(frameworkStandardsSrc, frameworkStandardsDest);
255
+ }
256
+
257
+ // --- 7. Copy framework/hooks → .morph/framework/hooks ---
258
+ log('Step 7: Copying hooks...');
259
+ const hooksSrc = join(FRAMEWORK_DIR, 'hooks');
260
+ const hooksDest = join(frameworkDestDir, 'hooks');
261
+ if (await pathExists(hooksSrc)) {
262
+ await copyDirectory(hooksSrc, hooksDest);
263
+ }
264
+
265
+ // --- 7b. Copy framework/rubrics → .morph/framework/rubrics ---
266
+ log('Step 7b: Copying rubrics...');
267
+ const rubricsSrc = join(FRAMEWORK_DIR, 'rubrics');
268
+ const rubricsDest = join(frameworkDestDir, 'rubrics');
269
+ if (await pathExists(rubricsSrc)) {
270
+ await copyDirectory(rubricsSrc, rubricsDest);
271
+ }
272
+
273
+ // --- 7c. Copy framework/evals → .morph/framework/evals ---
274
+ // Rubricas .md (bandas 0-10) + trace-schema.md — referenciadas por
275
+ // morph-eval/morph-review/agents.json via .morph/framework/evals/.
276
+ log('Step 7c: Copying evals (rubrics .md + trace schema)...');
277
+ const evalsSrc = join(FRAMEWORK_DIR, 'evals');
278
+ const evalsDest = join(frameworkDestDir, 'evals');
279
+ if (await pathExists(evalsSrc)) {
280
+ await copyDirectory(evalsSrc, evalsDest);
281
+ }
282
+
283
+ // --- 8. Copy framework/agents.json → .morph/framework/agents.json ---
284
+ log('Step 8: Copying agents.json...');
285
+ const agentsSrc = join(FRAMEWORK_DIR, 'agents.json');
286
+ const agentsDest = join(frameworkDestDir, 'agents.json');
287
+ if (await pathExists(agentsSrc)) {
288
+ await copyFile(agentsSrc, agentsDest);
289
+ }
290
+
291
+ // --- 8b. Copy framework/MORPH.md → .morph/framework/MORPH.md ---
292
+ log('Step 8b: Copying MORPH.md (NLH charter)...');
293
+ const morphMdSrc = join(FRAMEWORK_DIR, 'MORPH.md');
294
+ const morphMdDest = join(frameworkDestDir, 'MORPH.md');
295
+ if (await pathExists(morphMdSrc)) {
296
+ await copyFile(morphMdSrc, morphMdDest);
297
+ }
298
+
299
+ // --- 8c. Copy framework/phases.json → .morph/framework/phases.json ---
300
+ log('Step 8c: Copying phases.json...');
301
+ const phasesSrc = join(FRAMEWORK_DIR, 'phases.json');
302
+ const phasesDest = join(frameworkDestDir, 'phases.json');
303
+ if (await pathExists(phasesSrc)) {
304
+ await copyFile(phasesSrc, phasesDest);
305
+ }
306
+
307
+ // --- 8d. Copy framework/schemas → .morph/framework/schemas (JSON schemas) ---
308
+ log('Step 8d: Copying schemas...');
309
+ const schemasSrc = join(FRAMEWORK_DIR, 'schemas');
310
+ const schemasDest = join(frameworkDestDir, 'schemas');
311
+ if (await pathExists(schemasSrc)) {
312
+ await copyDirectory(schemasSrc, schemasDest);
313
+ }
314
+
315
+ // --- 9. Copy framework/commands → .claude/commands ---
316
+ log('Step 9: Setting up Claude Code integration...');
317
+ const claudeDest = join(targetPath, '.claude');
318
+ const commandsSrc = join(FRAMEWORK_DIR, 'commands');
319
+ const commandsDest = join(claudeDest, 'commands');
320
+ if (await pathExists(commandsSrc)) {
321
+ await copyDirectory(commandsSrc, commandsDest);
322
+ }
323
+
324
+ // --- 10-13. Install stack-aware assets (rules, skills, agents) ---
325
+ log('Steps 10-13: Installing stack-aware assets...');
326
+ const { agentCounts, domainCounts } = await installStackAwareAssets(targetPath, log);
327
+
328
+ // --- 14. Copy framework/CLAUDE.md → .claude/CLAUDE.md (morph-owned, gitignored) ---
329
+ log('Step 14: Installing .claude/CLAUDE.md...');
330
+ const runtimeClaudeMdDest = join(claudeDest, 'CLAUDE.md');
331
+ if (await pathExists(claudeMdSrc)) {
332
+ await copyFile(claudeMdSrc, runtimeClaudeMdDest);
333
+ // Derive the personas section from what step 10-13 actually installed.
334
+ await updateClaudeMdAgentsBlock(runtimeClaudeMdDest, agentCounts?.agents ?? []);
335
+ }
336
+
337
+ // --- 15. installGlobalStatusline (non-critical) ---
338
+ log('Step 15: Installing global statusline...');
339
+ const HOOKS_SRC = join(FRAMEWORK_DIR, 'hooks', 'claude-code');
340
+ try {
341
+ await installGlobalStatusline(HOOKS_SRC);
342
+ } catch {
343
+ // Non-critical — global ~/.claude may not be writable
344
+ }
345
+
346
+ // --- 16. installClaudeHooks ---
347
+ log('Step 16: Installing Claude Code hooks...');
348
+ await installClaudeHooks(targetPath);
349
+
350
+ // --- 17. saveProjectMorphVersion ---
351
+ log('Step 17: Saving version info...');
352
+ const cliVersion = getInstalledCLIVersion();
353
+ await saveProjectMorphVersion(targetPath, cliVersion);
354
+
355
+ // --- 18. updateGitignore ---
356
+ log('Step 18: Updating .gitignore...');
357
+ await updateGitignore(targetPath);
358
+
359
+ // --- 19. Initialize state.json (only if not exists) ---
360
+ log('Step 19: Initializing state.json...');
361
+ const statePath = join(morphPath, 'state.json');
362
+ if (!(await pathExists(statePath))) {
363
+ const dirName = targetPath.split(/[\/\\]/).pop();
364
+ const now = new Date().toISOString();
365
+ await writeJson(statePath, {
366
+ version: '5.0.0',
367
+ project: { name: dirName, type: 'unknown', createdAt: now, updatedAt: now },
368
+ features: {},
369
+ threads: {},
370
+ metadata: { totalFeatures: 0, completedFeatures: 0, totalTimeSpent: 0, lastUpdated: now }
371
+ });
372
+ }
373
+
374
+ log('setup-infra: complete.');
375
+
376
+ return {
377
+ agents: {
378
+ tier1: agentCounts?.tier1 ?? 0,
379
+ tier2: agentCounts?.tier2 ?? 0,
380
+ specialists: domainCounts?.specialists ?? 0,
381
+ },
382
+ };
383
+ }