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