@polymorphism-tech/morph-spec 11.1.0 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/morph-spec.js +9 -19
- package/docs/CHEATSHEET.md +3 -3
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +2 -0
- package/framework/MORPH.md +7 -2
- package/framework/agents.json +3 -3
- package/framework/docs/CLI.md +14 -12
- package/framework/evals/review-checklist.md +9 -16
- package/framework/hooks/README.md +15 -9
- package/framework/hooks/claude-code/core/README.md +2 -2
- package/framework/hooks/claude-code/core/chain.js +9 -25
- package/framework/hooks/claude-code/core/comment-guard.js +3 -9
- package/framework/hooks/claude-code/core/conventional-commit.js +3 -3
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +4 -4
- package/framework/hooks/claude-code/core/masked-exit.js +4 -3
- package/framework/hooks/claude-code/core/pre-bash-denylist.js +2 -2
- package/framework/hooks/claude-code/core/protect-spec-files.js +2 -4
- package/framework/hooks/claude-code/core/stack-changed.js +5 -4
- package/framework/hooks/claude-code/core/validate-completion.js +15 -12
- package/framework/hooks/shared/contract.js +22 -1
- package/framework/hooks/shared/git-paths.js +6 -0
- package/framework/hooks/shared/graph-freshness.js +3 -3
- package/framework/hooks/shared/graph-refresh.js +5 -10
- package/framework/hooks/shared/hook-response.js +1 -18
- package/framework/hooks/shared/payload-utils.js +12 -1
- package/framework/hooks/shared/phase-utils.js +4 -52
- package/framework/hooks/shared/report-progress.js +1 -1
- package/framework/mcp/registry.json +1 -17
- package/framework/rules/dotnet-templates.md +32 -33
- package/framework/rules/infrastructure-standards.md +9 -9
- package/framework/rules/neon-standards.md +4 -4
- package/framework/rules/nextjs-templates.md +10 -11
- package/framework/rules/ui-design.md +2 -2
- package/framework/schemas/config.schema.json +4 -0
- 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 +5 -4
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +5 -5
- package/framework/standards/integration/mcp/mcp-tools.md +2 -2
- package/framework/templates/REGISTRY.json +1 -75
- package/framework/templates/docs/plan.md +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Morph.AiKit.Tests.csproj +1 -1
- package/framework/templates/infrastructure/docker/docker-compose.template.yml +15 -16
- package/package.json +6 -15
- package/src/commands/graph/build.js +2 -2
- package/src/commands/mcp/mcp-setup.js +6 -4
- package/src/commands/project/doctor.js +42 -126
- package/src/commands/project/env.js +2 -1
- package/src/commands/project/init.js +28 -170
- package/src/commands/project/stack-set.js +3 -1
- package/src/commands/project/update.js +50 -154
- package/src/commands/scaffold/scaffold.js +21 -4
- package/src/commands/validation/check.js +12 -10
- package/src/commands/validation/prove-red.js +61 -22
- package/src/core/paths/output-schema.js +8 -37
- package/src/core/templates/template-registry.js +8 -43
- package/src/core/templates/template-renderer.js +3 -200
- package/src/lib/ai/ai-checks.js +1 -1
- package/src/lib/ai/ai-project-scan.js +1 -1
- package/src/lib/ai/code-audit.js +2 -2
- package/src/lib/check/signals.js +25 -7
- package/src/lib/contract/defaults.js +2 -2
- package/src/lib/detectors/claude-config-detector.js +0 -52
- package/src/lib/detectors/index.js +5 -30
- package/src/lib/diff/diff-lines.js +3 -3
- package/src/lib/generators/scaffold-generator.js +5 -17
- package/src/lib/git/default-branch.js +5 -48
- package/src/lib/graph/graph-health.js +1 -1
- package/src/lib/graph/graphifyignore.js +3 -4
- package/src/lib/graph/sanitize.js +2 -2
- package/src/lib/installers/effects.js +0 -13
- package/src/lib/installers/mcp-installer.js +5 -17
- package/src/lib/installers/memory-installer.js +5 -8
- package/src/lib/installers/stack-assets.js +33 -7
- package/src/lib/installers/stack-sync.js +4 -4
- package/src/lib/plan/checks.js +1 -1
- package/src/lib/plan/media.js +3 -3
- package/src/lib/plan/plan-parser.js +1 -1
- package/src/lib/review-reports.js +8 -14
- package/src/lib/scan/worktree-dirs.js +1 -3
- package/src/lib/specs/adr-index.js +4 -4
- package/src/lib/specs/revocations.js +3 -3
- package/src/lib/stack/stack-scan.js +3 -3
- package/src/lib/standards/registry.js +1 -1
- package/src/lib/standards/verified-against.js +2 -2
- package/src/lib/tests-audit/audit.js +2 -2
- package/src/scripts/global-install.js +41 -19
- package/src/scripts/setup-infra.js +57 -165
- package/src/utils/agents-installer.js +8 -30
- package/src/utils/claude-settings-manager.js +29 -27
- package/src/utils/hooks-installer.js +30 -44
- package/src/utils/version-checker.js +2 -31
- package/CLAUDE.md +0 -118
- package/framework/commands/create-umbraco-lp.md +0 -37
- package/framework/commands/migrate-lp-to-umbraco.md +0 -35
- package/framework/commands/morph-apply.md +0 -14
- package/framework/hooks/shared/spawn-command.js +0 -23
- package/framework/templates/CLAUDE.md.core.guide.md +0 -29
- package/framework/templates/CLAUDE.md.core.template +0 -22
- package/framework/templates/context/ARCHITECTURE.md +0 -106
- package/src/commands/context/context-refresh.js +0 -63
- package/src/lib/generators/architecture-scanner.js +0 -543
- package/src/lib/generators/settings-generator.js +0 -97
- package/src/lib/graph/god-nodes.js +0 -65
|
@@ -1,16 +1,46 @@
|
|
|
1
|
-
import { join, dirname } from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
1
|
+
import { join, dirname, resolve } from 'path';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
3
|
import { homedir, platform } from 'os';
|
|
4
|
-
import {
|
|
4
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
5
5
|
import { existsSync } from 'fs';
|
|
6
6
|
import { execSync } from 'child_process';
|
|
7
7
|
import { installGlobalStatusline } from '../utils/hooks-installer.js';
|
|
8
8
|
|
|
9
9
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const
|
|
10
|
+
const PACKAGE_ROOT = join(__dirname, '..', '..');
|
|
11
|
+
const FRAMEWORK_DIR = join(PACKAGE_ROOT, 'framework');
|
|
12
|
+
const PATH_MARKER = '# morph-spec: ensure npm global in PATH';
|
|
13
|
+
const PATH_END = '# end morph-spec PATH';
|
|
14
|
+
|
|
15
|
+
// `npm install` inside this repo (INIT_CWD is the package itself) or on CI is not a user install.
|
|
16
|
+
export function isDevOrCiInstall(env = process.env, packageRoot = PACKAGE_ROOT) {
|
|
17
|
+
if (env.CI) return true;
|
|
18
|
+
if (!env.INIT_CWD) return false;
|
|
19
|
+
const same = (a, b) => (platform() === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
20
|
+
return same(resolve(env.INIT_CWD), resolve(packageRoot));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function pathSnippet(npmGlobalDir) {
|
|
24
|
+
return [
|
|
25
|
+
PATH_MARKER,
|
|
26
|
+
`if ($env:PATH -notlike "*${npmGlobalDir}*") {`,
|
|
27
|
+
` $env:PATH += ";${npmGlobalDir}"`,
|
|
28
|
+
'}',
|
|
29
|
+
PATH_END,
|
|
30
|
+
].join('\n');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A block from an older install is replaced in place: its guard never matched and it grew PATH on every shell.
|
|
34
|
+
export function withPathSnippet(content, snippet) {
|
|
35
|
+
const start = content.indexOf(PATH_MARKER);
|
|
36
|
+
if (start < 0) return content ? `${content}\n\n${snippet}\n` : `${snippet}\n`;
|
|
37
|
+
const end = content.indexOf(PATH_END, start);
|
|
38
|
+
if (end < 0) return content;
|
|
39
|
+
return content.slice(0, start) + snippet + content.slice(end + PATH_END.length);
|
|
40
|
+
}
|
|
11
41
|
|
|
12
42
|
/** Windows only: adds the npm global bin to the PowerShell $PROFILE so new terminals find `morph-spec`. */
|
|
13
|
-
|
|
43
|
+
async function ensureNpmGlobalInPath() {
|
|
14
44
|
if (platform() !== 'win32') return;
|
|
15
45
|
|
|
16
46
|
let npmGlobalDir;
|
|
@@ -25,33 +55,25 @@ export async function ensureNpmGlobalInPath() {
|
|
|
25
55
|
const psProfile = join(homedir(), 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
26
56
|
const psProfileLegacy = join(homedir(), 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
27
57
|
|
|
28
|
-
const
|
|
29
|
-
const snippet = [
|
|
30
|
-
marker,
|
|
31
|
-
`if ($env:PATH -notlike "*${npmGlobalDir.replace(/\\/g, '\\\\')}*") {`,
|
|
32
|
-
` $env:PATH += ";${npmGlobalDir}"`,
|
|
33
|
-
'}',
|
|
34
|
-
'# end morph-spec PATH',
|
|
35
|
-
].join('\n');
|
|
58
|
+
const snippet = pathSnippet(npmGlobalDir);
|
|
36
59
|
|
|
37
60
|
for (const profilePath of [psProfile, psProfileLegacy]) {
|
|
38
61
|
try {
|
|
39
62
|
let content = '';
|
|
40
63
|
if (existsSync(profilePath)) {
|
|
41
64
|
content = await readFile(profilePath, 'utf8');
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
await mkdir(dirname(profilePath), { recursive: true });
|
|
65
|
+
} else if (!existsSync(dirname(profilePath))) {
|
|
66
|
+
continue;
|
|
45
67
|
}
|
|
46
|
-
const
|
|
47
|
-
await writeFile(profilePath,
|
|
68
|
+
const next = withPathSnippet(content, snippet);
|
|
69
|
+
if (next !== content) await writeFile(profilePath, next, 'utf8');
|
|
48
70
|
} catch {
|
|
49
71
|
// non-critical — skip silently
|
|
50
72
|
}
|
|
51
73
|
}
|
|
52
74
|
}
|
|
53
75
|
|
|
54
|
-
if (process.argv[1]
|
|
76
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href && !isDevOrCiInstall()) {
|
|
55
77
|
const HOOKS_SRC = join(FRAMEWORK_DIR, 'hooks', 'claude-code');
|
|
56
78
|
const { readFileSync } = await import('fs');
|
|
57
79
|
const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
|
|
@@ -1,35 +1,38 @@
|
|
|
1
|
-
import { basename, join,
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
1
|
+
import { basename, join, resolve } from 'path';
|
|
3
2
|
import { execSync } from 'child_process';
|
|
4
|
-
import { readFileSync
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
5
4
|
import {
|
|
6
5
|
copyDirectory,
|
|
7
6
|
copyFile,
|
|
8
7
|
pathExists,
|
|
9
8
|
writeJson,
|
|
10
9
|
ensureDir,
|
|
11
|
-
writeFile,
|
|
12
10
|
updateGitignore,
|
|
13
11
|
ensureGitattributes
|
|
14
12
|
} from '../utils/file-copier.js';
|
|
15
|
-
import {
|
|
13
|
+
import { getProjectTags } from '../lib/stack-filter.js';
|
|
14
|
+
import { readMorphConfig } from '../lib/config/project-config.js';
|
|
16
15
|
import { injectMorphImport } from '../utils/claude-md-injector.js';
|
|
17
16
|
import { saveProjectMorphVersion, getInstalledCLIVersion, getProjectMorphVersion } from '../utils/version-checker.js';
|
|
18
17
|
import { installClaudeHooks, installGlobalStatusline } from '../utils/claude-settings-manager.js';
|
|
19
|
-
import { installSkills } from '../utils/skills-installer.js';
|
|
20
|
-
import { installAgents } from '../utils/agents-installer.js';
|
|
21
18
|
import { reconcileLegacyTemplatesCopy } from '../lib/installers/templates-reconcile.js';
|
|
22
19
|
import { realEffects } from '../lib/installers/effects.js';
|
|
23
|
-
import {
|
|
20
|
+
import { installAssetsForTags } from '../lib/installers/stack-assets.js';
|
|
24
21
|
|
|
25
|
-
const FRAMEWORK_DIR = join(
|
|
22
|
+
const FRAMEWORK_DIR = join(import.meta.dirname, '..', '..', 'framework');
|
|
26
23
|
|
|
27
24
|
const REQUIRED_PLUGINS = [
|
|
28
25
|
'context7@claude-plugins-official',
|
|
29
26
|
];
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const toolInstallOff = () => process.env.MORPH_NO_TOOL_INSTALL === '1';
|
|
29
|
+
|
|
30
|
+
function installRequiredPlugins(log, exec) {
|
|
31
|
+
if (toolInstallOff()) {
|
|
32
|
+
log(`Plugins do Claude Code não instalados (MORPH_NO_TOOL_INSTALL=1): ${REQUIRED_PLUGINS.join(', ')}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
log('Installing required Claude Code plugins...');
|
|
33
36
|
for (const plugin of REQUIRED_PLUGINS) {
|
|
34
37
|
try {
|
|
35
38
|
exec(`claude plugin install ${plugin}`, { stdio: 'inherit' });
|
|
@@ -40,59 +43,10 @@ async function installRequiredPlugins(log, exec) {
|
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
export { installRulesForStack };
|
|
44
|
-
|
|
45
|
-
/** Clean-slate: removes only a framework command the stack filtered out, never one the user wrote. */
|
|
46
|
-
export function installCommandsForStack(commandsSrc, commandsDest, projectTags, fx = realEffects()) {
|
|
47
|
-
const sourceFiles = readdirSync(commandsSrc).filter(f => f.endsWith('.md'));
|
|
48
|
-
let installed = 0;
|
|
49
|
-
for (const file of sourceFiles) {
|
|
50
|
-
const dest = join(commandsDest, file);
|
|
51
|
-
if (shouldInstall(parseStacks(readFileSync(join(commandsSrc, file), 'utf-8')), projectTags)) {
|
|
52
|
-
fx.copyFile(join(commandsSrc, file), dest);
|
|
53
|
-
installed++;
|
|
54
|
-
} else if (!fx.dryRun && existsSync(dest)) {
|
|
55
|
-
fx.remove(dest);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return { installed };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
46
|
async function installStackAwareAssets(targetPath, log) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
// BOM-tolerant: a config.json written by PS 5.1 Out-File carries a BOM, and a failed parse
|
|
67
|
-
// here silently installs only the universal personas.
|
|
68
|
-
const config = JSON.parse(readFileSync(configPath, 'utf-8').replace(/^/, ''));
|
|
69
|
-
projectTags = getProjectTags(config);
|
|
70
|
-
} catch { /* ignore malformed config */ }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const claudeDest = join(targetPath, '.claude');
|
|
74
|
-
log('Installing stack-filtered commands...');
|
|
75
|
-
const commandsSrc = join(FRAMEWORK_DIR, 'commands');
|
|
76
|
-
const commandsDest = join(claudeDest, 'commands');
|
|
77
|
-
if (await pathExists(commandsSrc)) {
|
|
78
|
-
await ensureDir(commandsDest);
|
|
79
|
-
installCommandsForStack(commandsSrc, commandsDest, projectTags);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
log('Installing stack-filtered rules...');
|
|
83
|
-
const rulesSrc = join(FRAMEWORK_DIR, 'rules');
|
|
84
|
-
const rulesDest = join(claudeDest, 'rules');
|
|
85
|
-
if (await pathExists(rulesSrc)) {
|
|
86
|
-
await ensureDir(rulesDest);
|
|
87
|
-
installRulesForStack(rulesSrc, rulesDest, projectTags);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
log('Installing skills...');
|
|
91
|
-
await installSkills(targetPath, { projectTags });
|
|
92
|
-
|
|
93
|
-
log('Installing agents...');
|
|
94
|
-
const agentCounts = await installAgents(targetPath, FRAMEWORK_DIR, { projectTags });
|
|
95
|
-
|
|
47
|
+
const projectTags = getProjectTags(readMorphConfig(targetPath));
|
|
48
|
+
log('Installing stack-filtered rules, commands, skills and agents...');
|
|
49
|
+
const agentCounts = await installAssetsForTags(targetPath, projectTags, { frameworkSrc: FRAMEWORK_DIR });
|
|
96
50
|
return { agentCounts, projectTags };
|
|
97
51
|
}
|
|
98
52
|
|
|
@@ -115,7 +69,7 @@ export async function updateClaudeMdAgentsBlock(claudeMdPath, agents = [], optio
|
|
|
115
69
|
const block = `${START}\n**Personas de revisão** (derivado de agents.json na última instalação):\n\n${list}\n${END}`;
|
|
116
70
|
const updated = content.replace(
|
|
117
71
|
new RegExp(`${START}[\\s\\S]*?${END}`),
|
|
118
|
-
block
|
|
72
|
+
() => block
|
|
119
73
|
);
|
|
120
74
|
fx.writeFile(claudeMdPath, updated);
|
|
121
75
|
}
|
|
@@ -141,46 +95,31 @@ export async function setupInfra(targetPath, {
|
|
|
141
95
|
return { agents: { installed: agentCounts?.installed ?? 0 } };
|
|
142
96
|
}
|
|
143
97
|
|
|
144
|
-
|
|
98
|
+
installRequiredPlugins(log, _exec);
|
|
145
99
|
|
|
146
|
-
log('
|
|
100
|
+
log('Setting up CLAUDE.md...');
|
|
147
101
|
const claudeMdSrc = join(FRAMEWORK_DIR, 'CLAUDE.md');
|
|
148
|
-
const
|
|
149
|
-
const importResult = await injectMorphImport(claudeMdDest);
|
|
102
|
+
const importResult = await injectMorphImport(join(targetPath, 'CLAUDE.md'));
|
|
150
103
|
log(` ✓ Root CLAUDE.md: ${importResult}`);
|
|
151
104
|
|
|
152
|
-
log('
|
|
105
|
+
log('Creating .morph structure...');
|
|
153
106
|
const morphPath = join(targetPath, '.morph');
|
|
154
107
|
const configDir = join(morphPath, 'config');
|
|
155
108
|
const frameworkDestDir = join(morphPath, 'framework');
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
await ensureDir(configDir);
|
|
160
|
-
await ensureDir(frameworkDestDir);
|
|
161
|
-
await ensureDir(contextDir);
|
|
162
|
-
await ensureDir(featuresDir);
|
|
109
|
+
for (const dir of [configDir, frameworkDestDir, join(morphPath, 'context'), join(morphPath, 'features')]) {
|
|
110
|
+
await ensureDir(dir);
|
|
111
|
+
}
|
|
163
112
|
|
|
164
|
-
log('Step 3: Writing config.json...');
|
|
165
113
|
const configPath = join(configDir, 'config.json');
|
|
166
114
|
if (!(await pathExists(configPath))) {
|
|
167
|
-
|
|
115
|
+
await writeJson(configPath, {
|
|
168
116
|
frameworkVersion: getInstalledCLIVersion(),
|
|
169
117
|
project: { name: basename(resolve(targetPath)) },
|
|
170
|
-
};
|
|
171
|
-
await writeJson(configPath, config);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
log('Step 4: Writing context/README.md...');
|
|
175
|
-
const contextReadmePath = join(contextDir, 'README.md');
|
|
176
|
-
if (!(await pathExists(contextReadmePath))) {
|
|
177
|
-
const readmeContent = `# ${basename(resolve(targetPath))} — Project Context\n\nRun \`morph-spec context refresh\` to generate architecture context.\n`;
|
|
178
|
-
await writeFile(contextReadmePath, readmeContent);
|
|
118
|
+
});
|
|
179
119
|
}
|
|
180
120
|
|
|
181
|
-
|
|
182
|
-
//
|
|
183
|
-
// aqui, antes de o passo 17 regravar .morph/.morphversion; sem ela, não há fonte segura e só avisa.
|
|
121
|
+
// A legacy copy shadows the package templates (override-first); the prior version is read here,
|
|
122
|
+
// before `.morph/.morphversion` is rewritten below.
|
|
184
123
|
const legacyTemplatesDir = join(frameworkDestDir, 'templates');
|
|
185
124
|
if (await pathExists(legacyTemplatesDir)) {
|
|
186
125
|
const priorVersionInfo = await getProjectMorphVersion(targetPath);
|
|
@@ -189,95 +128,48 @@ export async function setupInfra(targetPath, {
|
|
|
189
128
|
if (result === 'removed-legacy') {
|
|
190
129
|
log(' ✓ .morph/framework/templates/ (cópia legada de instalação antiga removida — resolvida do pacote)');
|
|
191
130
|
} else {
|
|
192
|
-
log(' ⚠ .morph/framework/templates/ (override local presente
|
|
131
|
+
log(' ⚠ .morph/framework/templates/ (override local presente — preservado, não reconciliado)');
|
|
193
132
|
}
|
|
194
133
|
} else {
|
|
195
134
|
log(' ⚠ .morph/framework/templates/ existe (instalação antiga) e tem precedência sobre os templates do pacote — sem versão anterior registrada em .morph/.morphversion para decidir com segurança; rode `morph-spec update` para reconciliar, ou apague se não for customização sua.');
|
|
196
135
|
}
|
|
197
136
|
}
|
|
198
137
|
|
|
199
|
-
log('
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
if (await pathExists(frameworkStandardsSrc)) {
|
|
203
|
-
await copyDirectory(frameworkStandardsSrc, frameworkStandardsDest);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
log('Step 7: Copying hooks...');
|
|
207
|
-
const hooksSrc = join(FRAMEWORK_DIR, 'hooks');
|
|
208
|
-
const hooksDest = join(frameworkDestDir, 'hooks');
|
|
209
|
-
if (await pathExists(hooksSrc)) {
|
|
210
|
-
await copyDirectory(hooksSrc, hooksDest);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
log('Step 7c: Copying evals (review checklist + trace schema)...');
|
|
214
|
-
const evalsSrc = join(FRAMEWORK_DIR, 'evals');
|
|
215
|
-
const evalsDest = join(frameworkDestDir, 'evals');
|
|
216
|
-
if (await pathExists(evalsSrc)) {
|
|
217
|
-
await copyDirectory(evalsSrc, evalsDest);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
log('Step 8: Copying agents.json...');
|
|
221
|
-
const agentsSrc = join(FRAMEWORK_DIR, 'agents.json');
|
|
222
|
-
const agentsDest = join(frameworkDestDir, 'agents.json');
|
|
223
|
-
if (await pathExists(agentsSrc)) {
|
|
224
|
-
await copyFile(agentsSrc, agentsDest);
|
|
138
|
+
log('Copying standards, hooks, review checklist, schemas, agents.json, MORPH.md and CLI.md...');
|
|
139
|
+
for (const dir of ['standards', 'hooks', 'evals', 'schemas']) {
|
|
140
|
+
await copyDirectory(join(FRAMEWORK_DIR, dir), join(frameworkDestDir, dir));
|
|
225
141
|
}
|
|
142
|
+
await copyFile(join(FRAMEWORK_DIR, 'agents.json'), join(frameworkDestDir, 'agents.json'));
|
|
143
|
+
await copyFile(join(FRAMEWORK_DIR, 'MORPH.md'), join(frameworkDestDir, 'MORPH.md'));
|
|
144
|
+
await copyFile(join(FRAMEWORK_DIR, 'docs', 'CLI.md'), join(frameworkDestDir, 'CLI.md'));
|
|
226
145
|
|
|
227
|
-
log('Step 8b: Copying MORPH.md (NLH charter)...');
|
|
228
|
-
const morphMdSrc = join(FRAMEWORK_DIR, 'MORPH.md');
|
|
229
|
-
const morphMdDest = join(frameworkDestDir, 'MORPH.md');
|
|
230
|
-
if (await pathExists(morphMdSrc)) {
|
|
231
|
-
await copyFile(morphMdSrc, morphMdDest);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
log('Step 8b2: Copying CLI.md (command reference)...');
|
|
235
|
-
const cliMdSrc = join(FRAMEWORK_DIR, 'docs', 'CLI.md');
|
|
236
|
-
const cliMdDest = join(frameworkDestDir, 'CLI.md');
|
|
237
|
-
if (await pathExists(cliMdSrc)) {
|
|
238
|
-
await copyFile(cliMdSrc, cliMdDest);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
log('Step 8d: Copying schemas...');
|
|
242
|
-
const schemasSrc = join(FRAMEWORK_DIR, 'schemas');
|
|
243
|
-
const schemasDest = join(frameworkDestDir, 'schemas');
|
|
244
|
-
if (await pathExists(schemasSrc)) {
|
|
245
|
-
await copyDirectory(schemasSrc, schemasDest);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const claudeDest = join(targetPath, '.claude');
|
|
249
|
-
|
|
250
|
-
log('Steps 10-13: Installing stack-aware assets...');
|
|
251
146
|
const { agentCounts, projectTags } = await installStackAwareAssets(targetPath, log);
|
|
252
147
|
|
|
253
|
-
log('
|
|
254
|
-
const runtimeClaudeMdDest = join(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
await updateClaudeMdAgentsBlock(runtimeClaudeMdDest, agentCounts?.agents ?? []);
|
|
258
|
-
}
|
|
148
|
+
log('Installing .claude/CLAUDE.md...');
|
|
149
|
+
const runtimeClaudeMdDest = join(targetPath, '.claude', 'CLAUDE.md');
|
|
150
|
+
await copyFile(claudeMdSrc, runtimeClaudeMdDest);
|
|
151
|
+
await updateClaudeMdAgentsBlock(runtimeClaudeMdDest, agentCounts?.agents ?? []);
|
|
259
152
|
|
|
260
|
-
log('
|
|
261
|
-
|
|
153
|
+
log('Installing global statusline...');
|
|
154
|
+
let statusline = true;
|
|
262
155
|
try {
|
|
263
|
-
await installGlobalStatusline(
|
|
156
|
+
await installGlobalStatusline(join(FRAMEWORK_DIR, 'hooks', 'claude-code'));
|
|
264
157
|
} catch {
|
|
265
|
-
|
|
158
|
+
statusline = false;
|
|
159
|
+
log(' ⚠ ~/.claude não gravável: statusline global não instalado');
|
|
266
160
|
}
|
|
267
161
|
|
|
268
|
-
log('
|
|
269
|
-
await installClaudeHooks(targetPath);
|
|
162
|
+
log('Installing Claude Code hooks...');
|
|
163
|
+
const hooks = await installClaudeHooks(targetPath);
|
|
270
164
|
|
|
271
|
-
|
|
272
|
-
const cliVersion = getInstalledCLIVersion();
|
|
273
|
-
await saveProjectMorphVersion(targetPath, cliVersion);
|
|
165
|
+
await saveProjectMorphVersion(targetPath, getInstalledCLIVersion());
|
|
274
166
|
|
|
275
|
-
log('
|
|
167
|
+
log('Updating .gitignore + .gitattributes...');
|
|
276
168
|
await updateGitignore(targetPath);
|
|
277
169
|
await ensureGitattributes(targetPath);
|
|
278
170
|
|
|
279
171
|
// Fail-open por inteiro: o wrapper de CLI mata o processo em qualquer throw.
|
|
280
|
-
log('
|
|
172
|
+
log('Codebase graph (graphify)...');
|
|
281
173
|
try {
|
|
282
174
|
const { writeGraphifyignore, describeOutdatedIgnore } = await import('../lib/graph/graphifyignore.js');
|
|
283
175
|
const {
|
|
@@ -285,7 +177,7 @@ export async function setupInfra(targetPath, {
|
|
|
285
177
|
GRAPHIFY_VERSION, GRAPHIFY_PACKAGE,
|
|
286
178
|
} = await import('../lib/graph/graphify-runtime.js');
|
|
287
179
|
const { ensureClaudeignore } = await import('../utils/file-copier.js');
|
|
288
|
-
const {
|
|
180
|
+
const { collectProjectFiles } = await import('../lib/ai/ai-project-scan.js');
|
|
289
181
|
|
|
290
182
|
const ignore = writeGraphifyignore(targetPath, projectTags ?? []);
|
|
291
183
|
if (ignore.migrated) log(' ✓ .graphifyignore atualizado (dublês, fixtures e helpers de teste no grafo)');
|
|
@@ -303,13 +195,13 @@ export async function setupInfra(targetPath, {
|
|
|
303
195
|
log(` ✓ graphify ${installed} já instalado`);
|
|
304
196
|
} else {
|
|
305
197
|
const { kind } = detectInstaller();
|
|
306
|
-
if (
|
|
198
|
+
if (toolInstallOff()) {
|
|
307
199
|
log(` ○ graphify não instalado (MORPH_NO_TOOL_INSTALL=1). Depois: uv tool install ${GRAPHIFY_PACKAGE}==${GRAPHIFY_VERSION}`);
|
|
308
200
|
} else if (!kind) {
|
|
309
201
|
log(` ⚠ Sem uv/pipx/python — grafo indisponível. Depois: uv tool install ${GRAPHIFY_PACKAGE}==${GRAPHIFY_VERSION}`);
|
|
310
202
|
} else {
|
|
311
203
|
// Sem o extra [sql] os arquivos .sql são ignorados em silêncio.
|
|
312
|
-
const withSql = (
|
|
204
|
+
const withSql = collectProjectFiles(targetPath, (name) => name.endsWith('.sql')).length > 0;
|
|
313
205
|
const { cmd, args } = installArgs(kind, { withSql });
|
|
314
206
|
try {
|
|
315
207
|
_exec(`${cmd} ${args.join(' ')}`, { stdio: 'ignore' });
|
|
@@ -321,16 +213,16 @@ export async function setupInfra(targetPath, {
|
|
|
321
213
|
}
|
|
322
214
|
}
|
|
323
215
|
|
|
324
|
-
// Sem hook git do graphify: o refresh mora nos hooks do Claude
|
|
216
|
+
// Sem hook git do graphify: o refresh mora nos hooks do Claude. O `graphify hook install`
|
|
325
217
|
// 0.9.50 não roda em worktree vinculada, não tem post-merge e carimba HEAD num grafo sem o merge.
|
|
326
218
|
if (probe()) {
|
|
327
|
-
log(' ✓ refresh automático do grafo da raiz: depois dos comandos git/gh/morph-spec do agente
|
|
219
|
+
log(' ✓ refresh automático do grafo da raiz: depois dos comandos git/gh/morph-spec do agente');
|
|
328
220
|
}
|
|
329
221
|
} catch (err) {
|
|
330
|
-
log(` ⚠
|
|
222
|
+
log(` ⚠ Grafo pulado: ${err.message}`);
|
|
331
223
|
}
|
|
332
224
|
|
|
333
225
|
log('setup-infra: complete.');
|
|
334
226
|
|
|
335
|
-
return { agents: { installed: agentCounts?.installed ?? 0 } };
|
|
227
|
+
return { agents: { installed: agentCounts?.installed ?? 0 }, hooks: hooks.installed, statusline };
|
|
336
228
|
}
|
|
@@ -4,7 +4,7 @@ import { shouldInstall } from '../lib/stack-filter.js';
|
|
|
4
4
|
import { realEffects } from '../lib/installers/effects.js';
|
|
5
5
|
import { REVIEW_ROLES, VERDICT_TOKEN, REVIEWED_SHA_TOKEN, VERDICTS } from '../lib/review-reports.js';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const DEFAULT_AGENT_TOOLS = 'Read, Glob, Grep, Bash';
|
|
8
8
|
|
|
9
9
|
export const DEFAULT_MAX_TURNS = 20;
|
|
10
10
|
|
|
@@ -31,7 +31,7 @@ export function maxTurnsError(id, value) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Claude Code's subagent `effort` field; an unknown value is ignored there, so it is refused here.
|
|
34
|
-
|
|
34
|
+
const EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
35
35
|
|
|
36
36
|
export function effortError(id, value) {
|
|
37
37
|
if (value === undefined || EFFORT_LEVELS.includes(value)) return null;
|
|
@@ -53,7 +53,7 @@ function personaError(agent) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// `tools:` is a strict allowlist: without Skill no skill runs, without ToolSearch no deferred MCP tool loads.
|
|
56
|
-
|
|
56
|
+
const PLATFORM_TOOLS = ['Skill', 'ToolSearch'];
|
|
57
57
|
|
|
58
58
|
// A grant matches only its own spelling (`mcp__context7` vs `mcp__plugin_context7_context7`),
|
|
59
59
|
// so every spelling becomes a grant; one the project does not configure is inert.
|
|
@@ -71,7 +71,7 @@ export function serverNamesProblem(id, value) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/** @returns {Map<string, string[]>|null} id → server names; null = no registry (grant nothing) */
|
|
74
|
-
|
|
74
|
+
function loadKnownMcpIds(frameworkDir) {
|
|
75
75
|
try {
|
|
76
76
|
const registryPath = join(frameworkDir, 'mcp', 'registry.json');
|
|
77
77
|
if (!existsSync(registryPath)) return null;
|
|
@@ -84,15 +84,15 @@ export function loadKnownMcpIds(frameworkDir) {
|
|
|
84
84
|
|
|
85
85
|
// With no known stack tags every persona is generated: a dispatch of `morph-{id}` must find
|
|
86
86
|
// its subagent. Deliberately differs from rules/skills filtering.
|
|
87
|
-
|
|
87
|
+
function agentEligible(agent, projectTags = []) {
|
|
88
88
|
if (projectTags.length === 0) return true;
|
|
89
89
|
return shouldInstall(agent.stack ?? ['*'], projectTags);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const MANAGED_HEADER =
|
|
93
|
-
'<!-- MANAGED BY morph-spec — generated from
|
|
93
|
+
'<!-- MANAGED BY morph-spec — generated from the agents.json of the morph-spec package.\n' +
|
|
94
94
|
' Do NOT edit by hand: changes are overwritten on `morph-spec update` / `setup-infra --reinstall`.\n' +
|
|
95
|
-
'
|
|
95
|
+
' Drift is flagged by `morph-spec doctor`. -->';
|
|
96
96
|
|
|
97
97
|
const MANAGED_HEADER_MARKER = MANAGED_HEADER.split('\n')[0];
|
|
98
98
|
|
|
@@ -216,13 +216,6 @@ export const REVIEW_REPORT_CONTRACT = [
|
|
|
216
216
|
`Primeira linha \`${VERDICT_TOKEN} ${VERDICTS.join('|')}\`, depois \`${REVIEWED_SHA_TOKEN} {sha}\`, ` +
|
|
217
217
|
'tabela `## Bloqueadores` (`| id | tipo | onde | evidência |`; vazia = `Nenhum.`) e `## Notas`. ' +
|
|
218
218
|
'Bloqueador só com evidência e tipo; o resto é nota, e nota nunca pede rodada nova.',
|
|
219
|
-
'',
|
|
220
|
-
'Numa confirmação (um dispatch novo te traz depois da correção, com o `sha` novo) acrescente ao fim uma seção nova com ' +
|
|
221
|
-
`\`${VERDICT_TOKEN}\` e \`${REVIEWED_SHA_TOKEN} {sha novo}\`: se você abriu bloqueadores, julgue só eles; ` +
|
|
222
|
-
'se não abriu, julgue só o delta `{sha anterior}..{sha novo}` — o que a correção abriu. ' +
|
|
223
|
-
'O relatório é append-only: vale o último veredito e, na `## Checks`, a última linha de cada Cn.',
|
|
224
|
-
'',
|
|
225
|
-
'Um comando por chamada de Bash, sem encadear (`;`, `&&`, pipe): o composto é negado e custa a rodada.',
|
|
226
219
|
];
|
|
227
220
|
|
|
228
221
|
function buildBody(agent, maxTurns) {
|
|
@@ -249,8 +242,7 @@ function buildBody(agent, maxTurns) {
|
|
|
249
242
|
if (Object.hasOwn(REVIEW_ROLES, agent.id)) lines.push(...REVIEW_REPORT_CONTRACT, '');
|
|
250
243
|
|
|
251
244
|
lines.push(
|
|
252
|
-
// `PARCIAL` on line 1 is what
|
|
253
|
-
// review from carrying a Verdict the gate would read as final.
|
|
245
|
+
// `PARCIAL` on line 1 is what `parseRound` (review-reports.js) reads as an incomplete report.
|
|
254
246
|
'## Turn budget',
|
|
255
247
|
'',
|
|
256
248
|
`You have ${maxTurns} turns (\`maxTurns\`); at the ceiling you are cut off mid-work, without warning. ` +
|
|
@@ -382,17 +374,3 @@ function diffAgentMd(onDisk, rendered) {
|
|
|
382
374
|
// Bytes differ but no key/value does (a stray blank line between the fences).
|
|
383
375
|
return fields.length > 0 ? fields : ['frontmatter'];
|
|
384
376
|
}
|
|
385
|
-
|
|
386
|
-
export function collectSkillFiles(dir) {
|
|
387
|
-
const results = [];
|
|
388
|
-
if (!existsSync(dir)) return results;
|
|
389
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
390
|
-
const fullPath = join(dir, entry.name);
|
|
391
|
-
if (entry.isDirectory()) {
|
|
392
|
-
results.push(...collectSkillFiles(fullPath));
|
|
393
|
-
} else if (entry.name.endsWith('.md') && entry.name !== 'README.md') {
|
|
394
|
-
results.push(fullPath);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return results;
|
|
398
|
-
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
-
import { readFile, writeFile, mkdir, copyFile } from 'fs/promises';
|
|
2
|
+
import { readFile, writeFile, mkdir, copyFile, unlink } from 'fs/promises';
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
|
+
import { MORPH_ALLOW, MORPH_DENY } from './hooks-installer.js';
|
|
4
5
|
|
|
5
6
|
const MORPH_MANAGED_KEY = '_morph_managed';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// The installer writes no env var today; these are what older versions left behind.
|
|
9
|
+
const LEGACY_ENV_KEYS = ['MORPH_SPEC_ACTIVE', 'CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS'];
|
|
10
|
+
|
|
11
|
+
export { installClaudeHooks, installGlobalStatusline } from './hooks-installer.js';
|
|
9
12
|
|
|
10
13
|
export async function resetMorphSettings(targetPath) {
|
|
11
14
|
const claudeDir = join(targetPath, '.claude');
|
|
@@ -25,18 +28,30 @@ export async function resetMorphSettings(targetPath) {
|
|
|
25
28
|
const backupPath = settingsPath + '.backup';
|
|
26
29
|
await copyFile(settingsPath, backupPath);
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const footprint = { deny: MORPH_DENY, allow: MORPH_ALLOW, envKeys: LEGACY_ENV_KEYS };
|
|
32
|
+
const permissionsRemoved = [];
|
|
33
|
+
const envRemoved = [];
|
|
34
|
+
|
|
35
|
+
if (settings.permissions && typeof settings.permissions === 'object') {
|
|
36
|
+
for (const kind of ['deny', 'allow']) {
|
|
37
|
+
const entries = settings.permissions[kind];
|
|
38
|
+
if (!Array.isArray(entries)) continue;
|
|
39
|
+
const kept = entries.filter(p => !footprint[kind].includes(p));
|
|
40
|
+
permissionsRemoved.push(...entries.filter(p => footprint[kind].includes(p)));
|
|
41
|
+
if (kept.length > 0) settings.permissions[kind] = kept;
|
|
42
|
+
else delete settings.permissions[kind];
|
|
43
|
+
}
|
|
44
|
+
if (Object.keys(settings.permissions).length === 0) {
|
|
33
45
|
delete settings.permissions;
|
|
34
46
|
}
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
if (
|
|
38
|
-
for (const key of
|
|
39
|
-
|
|
49
|
+
if (settings.env) {
|
|
50
|
+
for (const key of footprint.envKeys) {
|
|
51
|
+
if (key in settings.env) {
|
|
52
|
+
delete settings.env[key];
|
|
53
|
+
envRemoved.push(key);
|
|
54
|
+
}
|
|
40
55
|
}
|
|
41
56
|
if (Object.keys(settings.env).length === 0) {
|
|
42
57
|
delete settings.env;
|
|
@@ -45,18 +60,14 @@ export async function resetMorphSettings(targetPath) {
|
|
|
45
60
|
|
|
46
61
|
if (settings.hooks) {
|
|
47
62
|
const morphPattern = /framework\/hooks\/claude-code\//;
|
|
48
|
-
const oldPattern = /agent-teams\/dispatch\.js/;
|
|
49
63
|
|
|
50
64
|
for (const [event, entries] of Object.entries(settings.hooks)) {
|
|
51
65
|
if (!Array.isArray(entries)) continue;
|
|
52
66
|
|
|
53
67
|
settings.hooks[event] = entries.filter(entry => {
|
|
68
|
+
if (entry._morph === true) return false;
|
|
54
69
|
if (!Array.isArray(entry.hooks)) return true;
|
|
55
|
-
|
|
56
|
-
typeof h.command !== 'string' ||
|
|
57
|
-
(!morphPattern.test(h.command) && !oldPattern.test(h.command))
|
|
58
|
-
);
|
|
59
|
-
return nonMorphHooks.length > 0;
|
|
70
|
+
return entry.hooks.some(h => typeof h.command !== 'string' || !morphPattern.test(h.command));
|
|
60
71
|
});
|
|
61
72
|
|
|
62
73
|
if (settings.hooks[event].length === 0) {
|
|
@@ -80,7 +91,6 @@ export async function resetMorphSettings(targetPath) {
|
|
|
80
91
|
if (Object.keys(mcpJson).length === 0) {
|
|
81
92
|
const mcpJsonPath = join(targetPath, '.mcp.json');
|
|
82
93
|
if (existsSync(mcpJsonPath)) {
|
|
83
|
-
const { unlink } = await import('fs/promises');
|
|
84
94
|
await unlink(mcpJsonPath);
|
|
85
95
|
}
|
|
86
96
|
} else {
|
|
@@ -102,15 +112,7 @@ export async function resetMorphSettings(targetPath) {
|
|
|
102
112
|
|
|
103
113
|
await saveSettings(targetPath, settings);
|
|
104
114
|
|
|
105
|
-
return {
|
|
106
|
-
removed: true,
|
|
107
|
-
backupPath,
|
|
108
|
-
permissionsRemoved: managed.permissions_added || [],
|
|
109
|
-
envRemoved: managed.env_added || [],
|
|
110
|
-
hooksRemoved: managed.hooks_added || [],
|
|
111
|
-
mcpsRemoved: managed.mcps_installed || [],
|
|
112
|
-
previouslyGenerated: managed.generated_at
|
|
113
|
-
};
|
|
115
|
+
return { removed: true, backupPath, permissionsRemoved, envRemoved };
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
// Claude Code reads MCP servers from .mcp.json, not settings.local.json.
|