@polymorphism-tech/morph-spec 11.1.1 → 11.3.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 +3 -2
- package/bin/morph-spec.js +13 -23
- package/docs/CHEATSHEET.md +3 -3
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +3 -1
- package/framework/MORPH.md +8 -3
- package/framework/agents.json +4 -4
- package/framework/docs/CLI.md +28 -18
- package/framework/evals/review-checklist.md +35 -18
- package/framework/hooks/README.md +18 -11
- 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 +6 -6
- 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 +16 -32
- package/framework/rules/ai-agents-standards.md +9 -1
- package/framework/rules/dotnet-templates.md +32 -33
- package/framework/rules/gsap-standards.md +8 -0
- package/framework/rules/infrastructure-standards.md +9 -9
- package/framework/rules/mcp-standards.md +10 -0
- 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 +11 -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 +6 -4
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +5 -5
- package/framework/standards/STANDARDS.json +8 -4
- package/framework/standards/STANDARDS.meta.json +1 -1
- package/framework/standards/ai-agents/agent-archetypes.md +1 -1
- package/framework/standards/ai-agents/middleware-patterns.md +0 -2
- package/framework/standards/ai-agents/prompt-sources.md +2 -2
- package/framework/standards/ai-agents/providers/model-registry.md +9 -12
- package/framework/standards/ai-agents/rag-custom-pgvector.md +2 -9
- package/framework/standards/frontend/design-system/ai-image-generation.md +1 -1
- package/framework/standards/infrastructure/docker/local-compose-isolation.md +2 -2
- package/framework/standards/integration/mcp/mcp-tools.md +125 -267
- package/framework/templates/README.md +52 -82
- package/framework/templates/REGISTRY.json +1 -281
- package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +3 -4
- package/framework/templates/context/design-system.md +1 -1
- package/framework/templates/docs/plan.md +2 -2
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/model-registry.v2.json +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Morph.AiKit.Tests.csproj +3 -5
- package/framework/templates/frontend/nextjs/gsap-scroll-section.tsx.hbs +13 -17
- package/framework/templates/infrastructure/docker/docker-compose.template.yml +15 -16
- package/framework/templates/infrastructure/github/README.md +10 -13
- package/package.json +7 -16
- package/src/commands/graph/build.js +2 -2
- package/src/commands/mcp/manual-setup.js +95 -0
- package/src/commands/mcp/mcp-setup.js +26 -192
- package/src/commands/project/doctor.js +48 -142
- package/src/commands/project/env.js +2 -1
- package/src/commands/project/init-contract.js +2 -2
- package/src/commands/project/init.js +34 -294
- package/src/commands/project/stack-scan.js +6 -14
- package/src/commands/project/stack-set.js +3 -1
- package/src/commands/project/standards.js +1 -2
- package/src/commands/project/update.js +87 -205
- package/src/commands/scaffold/scaffold.js +43 -5
- 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 -27
- 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 +2 -5
- package/src/lib/ai/code-audit.js +3 -8
- package/src/lib/ai/registry-audit.js +2 -1
- package/src/lib/check/signals.js +25 -7
- package/src/lib/config/project-config.js +3 -2
- package/src/lib/contract/apply.js +2 -1
- package/src/lib/contract/defaults.js +2 -2
- package/src/lib/contract/merge.js +1 -0
- package/src/lib/contract/scan.js +5 -5
- package/src/lib/detectors/claude-config-detector.js +44 -98
- package/src/lib/detectors/mcp-config.js +2 -1
- package/src/lib/diff/diff-lines.js +4 -9
- package/src/lib/generators/scaffold-generator.js +5 -17
- package/src/lib/git/default-branch.js +5 -13
- package/src/lib/graph/graph-health.js +1 -1
- package/src/lib/graph/graph-loader.js +2 -1
- package/src/lib/graph/graphifyignore.js +5 -5
- package/src/lib/graph/sanitize.js +2 -2
- package/src/lib/installers/effects.js +0 -13
- package/src/lib/installers/install-manifest.js +56 -0
- package/src/lib/installers/mcp-installer.js +16 -19
- package/src/lib/installers/memory-installer.js +5 -8
- package/src/lib/installers/rules-installer.js +9 -15
- package/src/lib/installers/stack-assets.js +54 -7
- package/src/lib/installers/stack-sync.js +16 -16
- package/src/lib/installers/stack-tooling.js +4 -3
- package/src/lib/json-file.js +9 -0
- package/src/lib/plan/artifact-vocabulary.js +1 -1
- package/src/lib/plan/checks.js +4 -3
- package/src/lib/plan/media.js +6 -6
- package/src/lib/plan/plan-parser.js +6 -11
- package/src/lib/review-reports.js +13 -18
- 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 +4 -4
- package/src/lib/standards/registry.js +1 -1
- package/src/lib/standards/verified-against.js +3 -3
- package/src/lib/tests-audit/audit.js +3 -3
- package/src/lib/text.js +5 -0
- package/src/scripts/global-install.js +41 -19
- package/src/scripts/setup-infra.js +68 -187
- package/src/utils/agents-installer.js +21 -60
- package/src/utils/claude-md-injector.js +16 -50
- package/src/utils/claude-settings-manager.js +29 -27
- package/src/utils/file-copier.js +3 -4
- package/src/utils/hooks-installer.js +83 -62
- package/src/utils/skills-installer.js +18 -78
- 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/IDE-SNIPPETS.md +0 -262
- package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +0 -26
- package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +0 -28
- package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +0 -99
- package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +0 -40
- package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +0 -54
- package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +0 -53
- package/framework/templates/code/dotnet/contracts/README.md +0 -74
- package/framework/templates/code/dotnet/database/vector-entity.cs +0 -49
- package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +0 -91
- package/framework/templates/code/sql/postgresql-migration.template.sql +0 -108
- package/framework/templates/code/typescript/contracts.ts +0 -140
- package/framework/templates/context/ARCHITECTURE.md +0 -106
- package/framework/templates/examples/design-system-examples.md +0 -354
- package/framework/templates/infrastructure/docker/Dockerfile.template +0 -58
- package/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +0 -45
- package/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +0 -27
- package/framework/templates/integrations/asaas-client.cs +0 -332
- package/framework/templates/integrations/asaas-webhook.cs +0 -290
- package/framework/templates/integrations/neon-auth-config.cs +0 -170
- package/framework/templates/ui/design-system.css +0 -226
- package/src/commands/context/context-refresh.js +0 -63
- package/src/lib/detectors/index.js +0 -178
- 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
- package/src/lib/installers/templates-reconcile.js +0 -26
|
@@ -3,6 +3,7 @@ import { dirname, join } from 'path';
|
|
|
3
3
|
import { atomicWriteJson } from '../../utils/atomic-json.js';
|
|
4
4
|
import { CONTRACT_FILE } from '../../../framework/hooks/shared/contract.js';
|
|
5
5
|
import { readMorphConfig } from '../config/project-config.js';
|
|
6
|
+
import { readJsonFile } from '../json-file.js';
|
|
6
7
|
import { getProjectTags, parseStacks, shouldInstall } from '../stack-filter.js';
|
|
7
8
|
import { scanRepo } from './scan.js';
|
|
8
9
|
import { contractFromScan } from './defaults.js';
|
|
@@ -12,7 +13,7 @@ const FRAMEWORK_SRC = join(import.meta.dirname, '..', '..', '..', 'framework');
|
|
|
12
13
|
// Inside config.json, not beside it: `update` wipes .morph/config/ and restores only that file.
|
|
13
14
|
export const PRINTS_KEY = '_generated';
|
|
14
15
|
|
|
15
|
-
const readJson = (path) => { try { return
|
|
16
|
+
const readJson = (path) => { try { return readJsonFile(path); } catch { return null; } };
|
|
16
17
|
|
|
17
18
|
/** What `init` would write, without writing: the dry run and the real run share it. */
|
|
18
19
|
export function planContract(root) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const CONTRACT_VERSION = 1;
|
|
5
5
|
|
|
6
6
|
export const DEFAULT_LIMITS = Object.freeze({ maxScenarios: 6, maxFiles: 20, maxIterations: 8, sameErrorStop: 3 });
|
|
7
7
|
|
|
8
|
-
// Globs over repo-relative paths;
|
|
8
|
+
// Globs over repo-relative paths; `LINE_CATEGORY` in check/signals.js catches what a path cannot name.
|
|
9
9
|
export const DEFAULT_RISK = Object.freeze({
|
|
10
10
|
dados: ['**/Migrations/**', '**/migrations/**', '**/*.sql', '**/prisma/schema.prisma', '**/alembic/versions/**', '**/drizzle/**'],
|
|
11
11
|
pessoas: ['**/*{WhatsApp,Whatsapp,whatsapp,Kapso,kapso}*{,/**}', '**/*{Email,email,Mailer,mailer}*{,/**}', '**/*{Sms,sms,Twilio,twilio}*{,/**}'],
|
|
@@ -63,6 +63,7 @@ export function mergeContract(config, contract, previousPrints = {}) {
|
|
|
63
63
|
out.project ??= {};
|
|
64
64
|
const p = out.project;
|
|
65
65
|
|
|
66
|
+
out.$schema ??= '../framework/schemas/config.schema.json';
|
|
66
67
|
out.contractVersion = contract.contractVersion;
|
|
67
68
|
p.stack = mergeValue('project.stack', p.stack, contract.stack, prints, report);
|
|
68
69
|
p.tags = mergeValue('project.tags', p.tags, contract.tags, prints, report);
|
package/src/lib/contract/scan.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'fs';
|
|
2
2
|
import { join, relative } from 'path';
|
|
3
3
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
4
|
+
import { stripBom } from '../json-file.js';
|
|
4
5
|
|
|
5
6
|
const SKIP_DIRS = new Set([
|
|
6
7
|
'node_modules', '.git', 'bin', 'obj', 'dist', 'build', 'out', 'coverage', '.next', '.nuxt', '.morph', '.claude',
|
|
@@ -9,7 +10,7 @@ const SKIP_DIRS = new Set([
|
|
|
9
10
|
]);
|
|
10
11
|
const MAX_DEPTH = 4;
|
|
11
12
|
|
|
12
|
-
const MANIFEST = /^(package\.json|pyproject\.toml|requirements(-[\w-]+)?\.txt|components\.json|
|
|
13
|
+
const MANIFEST = /^(package\.json|pyproject\.toml|requirements(-[\w-]+)?\.txt|components\.json|(docker-)?compose(\.[\w-]+)?\.ya?ml|Dockerfile)$|\.(csproj|slnx?)$/i;
|
|
13
14
|
|
|
14
15
|
const fwd = (p) => p.replace(/\\/g, '/');
|
|
15
16
|
|
|
@@ -31,7 +32,7 @@ function walk(root) {
|
|
|
31
32
|
return found.sort();
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
const readText = (root, rel) => { try { return readFileSync(join(root, rel), 'utf8')
|
|
35
|
+
const readText = (root, rel) => { try { return stripBom(readFileSync(join(root, rel), 'utf8')); } catch { return ''; } };
|
|
35
36
|
const readJson = (root, rel) => { try { return JSON.parse(readText(root, rel)); } catch { return null; } };
|
|
36
37
|
const dirOf = (rel) => (rel.includes('/') ? rel.slice(0, rel.lastIndexOf('/')) : '.');
|
|
37
38
|
|
|
@@ -51,7 +52,7 @@ function nodePackage(root, rel) {
|
|
|
51
52
|
if (!pkg) return null;
|
|
52
53
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
53
54
|
const scripts = Object.fromEntries(Object.entries(pkg.scripts || {}).filter(([, v]) => typeof v === 'string'));
|
|
54
|
-
return { dir: dirOf(rel),
|
|
55
|
+
return { dir: dirOf(rel), deps: Object.keys(deps), scripts };
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
function dotnetProject(root, rel) {
|
|
@@ -76,7 +77,6 @@ export function scanRepo(root) {
|
|
|
76
77
|
const solutions = files.filter((f) => /\.slnx?$/i.test(f));
|
|
77
78
|
const python = files.filter((f) => /(^|\/)(pyproject\.toml|requirements(-[\w-]+)?\.txt)$/i.test(f)).map((f) => pythonProject(root, f));
|
|
78
79
|
const compose = files.filter((f) => /(^|\/)(docker-)?compose(\.[\w-]+)?\.ya?ml$/i.test(f));
|
|
79
|
-
const playwright = files.filter((f) => /(^|\/)playwright\.config\./.test(f));
|
|
80
80
|
|
|
81
81
|
for (const p of node) for (const [dep, tag] of NODE_TAGS) if (p.deps.includes(dep)) tags.add(tag);
|
|
82
82
|
for (const p of dotnet) for (const pkg of p.packages) for (const [re, tag] of DOTNET_TAGS) if (re.test(pkg)) tags.add(tag);
|
|
@@ -97,6 +97,6 @@ export function scanRepo(root) {
|
|
|
97
97
|
return {
|
|
98
98
|
stack: stacks.length ? stacks.join('+') : null,
|
|
99
99
|
tags: [...tags].sort(),
|
|
100
|
-
node, dotnet, solutions, python, compose,
|
|
100
|
+
node, dotnet, solutions, python, compose,
|
|
101
101
|
};
|
|
102
102
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
|
+
import { readJsonFile } from '../json-file.js';
|
|
4
5
|
import { readMcpConfig } from './mcp-config.js';
|
|
5
6
|
|
|
6
7
|
// User settings first, then the project's: a later file overrides, and `false` turns a plugin off.
|
|
@@ -14,7 +15,7 @@ export function readEnabledPlugins(targetPath, home = homedir()) {
|
|
|
14
15
|
for (const file of files) {
|
|
15
16
|
if (!existsSync(file)) continue;
|
|
16
17
|
try {
|
|
17
|
-
const map =
|
|
18
|
+
const map = readJsonFile(file).enabledPlugins;
|
|
18
19
|
if (!map || typeof map !== 'object') continue;
|
|
19
20
|
for (const [id, on] of Object.entries(map)) merged.set(id, on === true);
|
|
20
21
|
} catch {}
|
|
@@ -27,121 +28,66 @@ export function detectClaudeConfig(targetPath) {
|
|
|
27
28
|
plugins: [],
|
|
28
29
|
enabledPlugins: [],
|
|
29
30
|
mcpServers: [],
|
|
30
|
-
customSkills: [],
|
|
31
|
-
customCommands: [],
|
|
32
|
-
hooks: [],
|
|
33
31
|
};
|
|
34
32
|
|
|
35
33
|
result.enabledPlugins = readEnabledPlugins(targetPath);
|
|
36
34
|
|
|
37
35
|
const mcpJsonNames = new Set();
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
mcpJsonNames.add(name);
|
|
48
|
-
}
|
|
49
|
-
} catch {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const settingsPaths = [
|
|
53
|
-
join(targetPath, '.claude', 'settings.json'),
|
|
54
|
-
join(targetPath, '.claude', 'settings.local.json'),
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
for (const sp of settingsPaths) {
|
|
58
|
-
if (existsSync(sp)) {
|
|
59
|
-
try {
|
|
60
|
-
const settings = JSON.parse(readFileSync(sp, 'utf8'));
|
|
61
|
-
// Legacy entries: .mcp.json wins; among settings files, the later one wins.
|
|
62
|
-
const mcps = settings.mcpServers || {};
|
|
63
|
-
for (const [name, config] of Object.entries(mcps)) {
|
|
64
|
-
if (mcpJsonNames.has(name)) continue;
|
|
65
|
-
const idx = result.mcpServers.findIndex(m => m.name === name);
|
|
66
|
-
if (idx >= 0) {
|
|
67
|
-
result.mcpServers[idx] = { name, config };
|
|
68
|
-
} else {
|
|
69
|
-
result.mcpServers.push({ name, config });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (settings.hooks) {
|
|
74
|
-
for (const [event, eventHooks] of Object.entries(settings.hooks)) {
|
|
75
|
-
for (const group of (Array.isArray(eventHooks) ? eventHooks : [])) {
|
|
76
|
-
for (const h of (group.hooks || [])) {
|
|
77
|
-
result.hooks.push(`${event}:${h.type || 'unknown'}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} catch {}
|
|
37
|
+
const mcpJsonPath = join(targetPath, '.mcp.json');
|
|
38
|
+
if (existsSync(mcpJsonPath)) {
|
|
39
|
+
try {
|
|
40
|
+
const mcpJson = readJsonFile(mcpJsonPath);
|
|
41
|
+
const mcps = mcpJson.mcpServers || {};
|
|
42
|
+
for (const [name, config] of Object.entries(mcps)) {
|
|
43
|
+
result.mcpServers.push({ name, config });
|
|
44
|
+
mcpJsonNames.add(name);
|
|
83
45
|
}
|
|
84
|
-
}
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
85
48
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
49
|
+
const settingsPaths = [
|
|
50
|
+
join(targetPath, '.claude', 'settings.json'),
|
|
51
|
+
join(targetPath, '.claude', 'settings.local.json'),
|
|
52
|
+
];
|
|
91
53
|
|
|
92
|
-
|
|
93
|
-
if (existsSync(
|
|
54
|
+
for (const sp of settingsPaths) {
|
|
55
|
+
if (existsSync(sp)) {
|
|
94
56
|
try {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
57
|
+
const settings = readJsonFile(sp);
|
|
58
|
+
// Legacy entries: .mcp.json wins; among settings files, the later one wins.
|
|
59
|
+
const mcps = settings.mcpServers || {};
|
|
60
|
+
for (const [name, config] of Object.entries(mcps)) {
|
|
61
|
+
if (mcpJsonNames.has(name)) continue;
|
|
62
|
+
const idx = result.mcpServers.findIndex(m => m.name === name);
|
|
63
|
+
if (idx >= 0) {
|
|
64
|
+
result.mcpServers[idx] = { name, config };
|
|
65
|
+
} else {
|
|
66
|
+
result.mcpServers.push({ name, config });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
98
69
|
} catch {}
|
|
99
70
|
}
|
|
71
|
+
}
|
|
100
72
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
73
|
+
// User and local scopes live in ~/.claude.json: missing them rewrites a server the user already has into .mcp.json.
|
|
74
|
+
for (const s of readMcpConfig({ projectDir: targetPath }).servers) {
|
|
75
|
+
if (s.scope === 'project' || result.mcpServers.some(m => m.name === s.name)) continue;
|
|
76
|
+
result.mcpServers.push({ name: s.name, config: { command: s.command, args: s.args, url: s.url }, source: s.scope });
|
|
77
|
+
}
|
|
107
78
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
79
|
+
const pluginsPath = join(homedir(), '.claude', 'plugins', 'installed_plugins.json');
|
|
80
|
+
if (existsSync(pluginsPath)) {
|
|
81
|
+
try {
|
|
82
|
+
const pluginsData = readJsonFile(pluginsPath);
|
|
83
|
+
const plugins = pluginsData.plugins || {};
|
|
84
|
+
result.plugins = Object.keys(plugins);
|
|
85
|
+
} catch {}
|
|
115
86
|
}
|
|
116
87
|
|
|
117
88
|
return result;
|
|
118
89
|
}
|
|
119
90
|
|
|
120
|
-
// `phaseMatrix`/`currentPhase` default: `init` passes only `mcpServers`, and a throw here was
|
|
121
|
-
// swallowed by its outer catch, skipping the steps after it.
|
|
122
|
-
export function mapMcpsToPhases(mcpServers, phaseMatrix = {}, currentPhase = null) {
|
|
123
|
-
const configuredNames = new Set((mcpServers || []).map(m => m.name.toLowerCase()));
|
|
124
|
-
// No phase asked for → the union across every phase, deduped.
|
|
125
|
-
const recommended = currentPhase
|
|
126
|
-
? (phaseMatrix[currentPhase] || [])
|
|
127
|
-
: [...new Set(Object.values(phaseMatrix).flat())];
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
available: recommended.filter(name => configuredNames.has(name)),
|
|
131
|
-
recommended,
|
|
132
|
-
missing: recommended.filter(name => !configuredNames.has(name)),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function mcpAvailabilityByPhase(mcpServers, phaseMatrix = {}) {
|
|
137
|
-
return Object.keys(phaseMatrix)
|
|
138
|
-
.map(phase => ({
|
|
139
|
-
phase,
|
|
140
|
-
available: mapMcpsToPhases(mcpServers, phaseMatrix, phase).available,
|
|
141
|
-
}))
|
|
142
|
-
.filter(({ available }) => available.length > 0);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
91
|
export function formatConfigSummary(config) {
|
|
146
92
|
const parts = [];
|
|
147
93
|
if (config.mcpServers.length > 0) {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join, resolve } from 'node:path';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
+
import { stripBom } from '../json-file.js';
|
|
4
5
|
import { jsoncToJson } from '../../../framework/hooks/shared/comment-stripper.js';
|
|
5
6
|
import { readEnabledPlugins } from './claude-config-detector.js';
|
|
6
7
|
|
|
7
8
|
function readJsonc(file, unreadable) {
|
|
8
9
|
if (!existsSync(file)) return null;
|
|
9
10
|
try {
|
|
10
|
-
return JSON.parse(jsoncToJson(readFileSync(file, 'utf8')
|
|
11
|
+
return JSON.parse(jsoncToJson(stripBom(readFileSync(file, 'utf8'))));
|
|
11
12
|
} catch {
|
|
12
13
|
unreadable.push(file);
|
|
13
14
|
return null;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'child_process';
|
|
2
|
-
import { minimatch } from 'minimatch';
|
|
3
2
|
|
|
4
|
-
// O predicado único de teste
|
|
3
|
+
// O predicado único de "é teste" (grafo, stack-scan, prove-red). Só três formas de pasta, porque
|
|
5
4
|
// `[^/]*[Tt]ests?/` genérico também casaria `latest/` e `contests/`.
|
|
6
5
|
const TEST_PATH = /(^|\/)__tests__\/|\.(test|spec)\.[jt]sx?$|(^|\/)(?:[Tt]ests?|[^/]*\.[Tt]ests?|[^/]*[a-z0-9_]Tests?)\//;
|
|
7
6
|
|
|
@@ -12,7 +11,7 @@ export function isTestPath(sourceFile) {
|
|
|
12
11
|
const DOC_PATH = /(^|\/)docs\/|\.(md|mdx|txt|rst|adoc|png|jpe?g|gif|svg|webp|ico)$/i;
|
|
13
12
|
const CONFIG_PATH = /\.(json|jsonc|ya?ml|toml|ini|xml|editorconfig|env\.example)$|(^|\/)\.(gitignore|gitattributes|npmrc|nvmrc|prettierrc|eslintignore)$|(^|\/)\.env(\.[^/]+)?$/i;
|
|
14
13
|
// Resolves or compiles everything: a change here reaches code the diff does not name.
|
|
15
|
-
|
|
14
|
+
const WIDE_PATH = /(^|\/)(package(-lock)?\.json|pnpm-lock\.yaml|yarn\.lock|global\.json|Directory\.(Build|Packages)\.(props|targets)|tsconfig[^/]*\.json|[^/]+\.(csproj|sln|slnx|props|targets))$/i;
|
|
16
15
|
|
|
17
16
|
export function git(cwd, args) {
|
|
18
17
|
return execFileSync('git', args, { cwd, stdio: 'pipe', maxBuffer: 256 * 1024 * 1024 }).toString();
|
|
@@ -21,13 +20,9 @@ export function git(cwd, args) {
|
|
|
21
20
|
// An agent reads these as instructions: a changed sentence is changed behaviour, whatever the extension.
|
|
22
21
|
const PROMPT_PATH = /(^|\/)(prompts?|agents?|skills?|playbooks?|personas?|instructions?|\.claude)\/|(^|\/)(CLAUDE|AGENTS|GEMINI|MORPH|SKILL|copilot-instructions)\.md$|prompt[^/]*$/i;
|
|
23
22
|
|
|
24
|
-
export function
|
|
25
|
-
return PROMPT_PATH.test(path) || promptGlobs.some((g) => minimatch(path, g));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function fileClass(path, promptGlobs = []) {
|
|
23
|
+
export function fileClass(path) {
|
|
29
24
|
if (path.startsWith('.morph/')) return 'state';
|
|
30
|
-
if (
|
|
25
|
+
if (PROMPT_PATH.test(path)) return 'code';
|
|
31
26
|
if (DOC_PATH.test(path)) return 'doc';
|
|
32
27
|
if (CONFIG_PATH.test(path) && !WIDE_PATH.test(path)) return 'config';
|
|
33
28
|
return isTestPath(path) || /(^|\/)e2e\//.test(path) ? 'test' : 'code';
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'fs';
|
|
2
2
|
import { join, dirname, basename } from 'path';
|
|
3
|
-
import { renderTemplate } from '../../core/templates/template-renderer.js';
|
|
3
|
+
import { renderTemplate, Handlebars } from '../../core/templates/template-renderer.js';
|
|
4
4
|
import { resolveFrameworkTemplatePath } from '../../core/templates/template-registry.js';
|
|
5
|
+
import { readMorphConfig } from '../config/project-config.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
return str
|
|
8
|
-
.split('-')
|
|
9
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
10
|
-
.join('');
|
|
11
|
-
}
|
|
7
|
+
export const toPascalCase = (str) => Handlebars.helpers.pascalCase(str);
|
|
12
8
|
|
|
13
9
|
/** Kebab-case so Handlebars {{pascalCase}} reconstructs it: "MyBookStore" → "my-book-store", "My.App" → "my-app". */
|
|
14
10
|
export function normalizeNamespaceToKebab(ns) {
|
|
@@ -156,7 +152,7 @@ export function scaffoldNextjsFeature(options) {
|
|
|
156
152
|
return { files };
|
|
157
153
|
}
|
|
158
154
|
|
|
159
|
-
/** <RootNamespace> or the name of a .csproj here or one level deep, else
|
|
155
|
+
/** <RootNamespace> or the name of a .csproj here or one level deep, else the contract's `project.name`. */
|
|
160
156
|
export function detectNamespace(dir) {
|
|
161
157
|
const csprojInDir = findCsproj(dir);
|
|
162
158
|
if (csprojInDir) {
|
|
@@ -179,15 +175,7 @@ export function detectNamespace(dir) {
|
|
|
179
175
|
}
|
|
180
176
|
} catch {}
|
|
181
177
|
|
|
182
|
-
|
|
183
|
-
if (existsSync(configPath)) {
|
|
184
|
-
try {
|
|
185
|
-
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
186
|
-
if (config.project?.name) return config.project.name;
|
|
187
|
-
} catch {}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return null;
|
|
178
|
+
return readMorphConfig(dir)?.project?.name || null;
|
|
191
179
|
}
|
|
192
180
|
|
|
193
181
|
function findCsproj(dir) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from 'child_process';
|
|
2
|
-
import {
|
|
3
|
-
import { join } from 'path';
|
|
2
|
+
import { readMorphConfig } from '../config/project-config.js';
|
|
4
3
|
|
|
5
4
|
function localBranchExists(branch, cwd) {
|
|
6
5
|
try {
|
|
@@ -11,19 +10,13 @@ function localBranchExists(branch, cwd) {
|
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
* from it, measure against it and close back into it. `MORPH_BASE_BRANCH` first (the root
|
|
17
|
-
* checkout stays on the old default, so `create` run there needs it), then `project.baseBranch`
|
|
18
|
-
* in the `.morph/config/config.json` of the repo `cwd` is in (a worktree reads its own copy).
|
|
19
|
-
* @returns {string|null} null when nothing is declared.
|
|
20
|
-
*/
|
|
21
|
-
export function configuredBaseBranch(cwd = process.cwd()) {
|
|
13
|
+
/** `MORPH_BASE_BRANCH`, then `project.baseBranch` of the contract in the repo `cwd` is in; null when neither is set. */
|
|
14
|
+
function configuredBaseBranch(cwd = process.cwd()) {
|
|
22
15
|
const env = process.env.MORPH_BASE_BRANCH?.trim();
|
|
23
16
|
if (env) return env;
|
|
24
17
|
try {
|
|
25
18
|
const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, stdio: 'pipe' }).toString().trim();
|
|
26
|
-
const branch =
|
|
19
|
+
const branch = readMorphConfig(root)?.project?.baseBranch;
|
|
27
20
|
return typeof branch === 'string' && branch.trim() ? branch.trim() : null;
|
|
28
21
|
} catch {
|
|
29
22
|
return null;
|
|
@@ -31,8 +24,7 @@ export function configuredBaseBranch(cwd = process.cwd()) {
|
|
|
31
24
|
}
|
|
32
25
|
|
|
33
26
|
/**
|
|
34
|
-
* The declared base branch
|
|
35
|
-
* `main`, then `master`.
|
|
27
|
+
* The declared base branch first, then `origin/HEAD`, then a local `main`, then `master`.
|
|
36
28
|
* @returns {string|null} null when none resolves; the caller decides.
|
|
37
29
|
*/
|
|
38
30
|
export function detectDefaultBranch(cwd = process.cwd()) {
|
|
@@ -11,7 +11,7 @@ const GRAPHIFY_HOOK_MARKER = /# graphify-(?:checkout-)?hook-start/;
|
|
|
11
11
|
|
|
12
12
|
// O hook git do próprio graphify é danoso: depois de um fast-forward carimba o HEAD num grafo sem os
|
|
13
13
|
// arquivos do merge ("fresh" falso) e disputa o graph.json com o refresh. Respeita `core.hooksPath`.
|
|
14
|
-
|
|
14
|
+
function graphifyGitHookInstalled(projectPath) {
|
|
15
15
|
let dir;
|
|
16
16
|
try {
|
|
17
17
|
const rel = execFileSync('git', ['rev-parse', '--git-path', 'hooks'], {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '../../../framework/hooks/shared/graph-refresh.js';
|
|
10
10
|
import { isSecondaryWorktree, workTreeTop } from '../../../framework/hooks/shared/git-paths.js';
|
|
11
11
|
import { GRAPHIFY_PACKAGE, GRAPHIFY_VERSION } from './graphify-runtime.js';
|
|
12
|
+
import { stripBom } from '../json-file.js';
|
|
12
13
|
|
|
13
14
|
export function resolveGraphPath(projectPath) {
|
|
14
15
|
return join(projectPath, 'graphify-out', 'graph.json');
|
|
@@ -26,7 +27,7 @@ export function loadGraph(projectPath) {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
try {
|
|
29
|
-
const graph = JSON.parse(raw
|
|
30
|
+
const graph = JSON.parse(stripBom(raw));
|
|
30
31
|
// A chave das arestas é `links`, não `edges`. Um JSON válido sem uma das
|
|
31
32
|
// duas listas não é um grafo utilizável.
|
|
32
33
|
if (!graph || !Array.isArray(graph.nodes) || !Array.isArray(graph.links)) {
|
|
@@ -5,6 +5,7 @@ import { writeFileSync, existsSync, readFileSync } from 'node:fs';
|
|
|
5
5
|
import { execFileSync } from 'node:child_process';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
8
|
+
import { stripBom } from '../json-file.js';
|
|
8
9
|
import { ignoreRules } from '../../../framework/hooks/shared/graph-freshness.js';
|
|
9
10
|
|
|
10
11
|
export const ALWAYS_IGNORED = [
|
|
@@ -41,10 +42,9 @@ const PREVIOUS = {
|
|
|
41
42
|
dotnet: ['**/*.Tests/', '**/*Tests/', '**/*.Test/', ...DOTNET_BUILD_OUTPUT],
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
const DOTNET_TAGS = new Set(['dotnet'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
]);
|
|
45
|
+
const DOTNET_TAGS = new Set(['dotnet']);
|
|
46
|
+
// `nodejs`: what the detector wrote into config.json before it said `node`.
|
|
47
|
+
const WEB_TAGS = new Set(['nextjs', 'react', 'vue', 'node', 'nodejs']);
|
|
48
48
|
|
|
49
49
|
const hasDotnetTag = (tags) => [...new Set(tags)].some((t) => DOTNET_TAGS.has(t));
|
|
50
50
|
|
|
@@ -78,7 +78,7 @@ export function buildGraphifyignore(projectTags = []) {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const normalize = (text) => String(text)
|
|
81
|
+
const normalize = (text) => stripBom(String(text)).replace(/\r\n/g, '\n');
|
|
82
82
|
|
|
83
83
|
// Ausente → escreve. Idêntico ao que a geração anterior escrevia → migra, só se as regras mudam.
|
|
84
84
|
// Qualquer outra coisa é do usuário: não toca, e em .NET devolve em `outdated` a troca a fazer.
|
|
@@ -5,13 +5,13 @@ import { isTestPath } from '../diff/diff-lines.js';
|
|
|
5
5
|
// externo é `real.length === 0`, nunca "o que sobrou".
|
|
6
6
|
|
|
7
7
|
/** Arestas que contam como dependência para blast radius. */
|
|
8
|
-
|
|
8
|
+
const USE_RELATIONS = new Set([
|
|
9
9
|
'calls', 'references', 'uses', 'imports', 'imports_from',
|
|
10
10
|
'inherits', 'implements', 'extends', 'dispatches_to', 'indirect_call',
|
|
11
11
|
]);
|
|
12
12
|
|
|
13
13
|
/** Herança não é uso: uma interface muito implementada tem poucos usos reais. */
|
|
14
|
-
|
|
14
|
+
const INHERITANCE_RELATIONS = new Set(['inherits', 'implements', 'extends']);
|
|
15
15
|
|
|
16
16
|
const LANG_BY_EXT = {
|
|
17
17
|
cs: 'dotnet', csproj: 'dotnet', razor: 'dotnet', cshtml: 'dotnet',
|
|
@@ -13,7 +13,6 @@ export function createEffects({ dryRun = false } = {}) {
|
|
|
13
13
|
const effect = { verb, target };
|
|
14
14
|
if (extra.from !== undefined) effect.from = extra.from;
|
|
15
15
|
if (extra.detail !== undefined) effect.detail = extra.detail;
|
|
16
|
-
if (extra.args !== undefined) effect.args = extra.args;
|
|
17
16
|
effects.push(effect);
|
|
18
17
|
return effect;
|
|
19
18
|
};
|
|
@@ -74,18 +73,6 @@ export function createEffects({ dryRun = false } = {}) {
|
|
|
74
73
|
fs.writeJsonSync(path, { ...current, ...patch }, { spaces: 2 });
|
|
75
74
|
},
|
|
76
75
|
|
|
77
|
-
// `dryRunArgs`: variante só-leitura do comando, executada no lugar em dry; o registro é o comando real.
|
|
78
|
-
spawn(cmd, args = [], options = {}) {
|
|
79
|
-
// `args` viaja além do `detail`: quebrar o `detail` por espaço erra caminhos com espaço.
|
|
80
|
-
record('spawn', cmd, { detail: args.join(' '), args: [...args] });
|
|
81
|
-
const { cwd, dryRunArgs } = options;
|
|
82
|
-
if (dryRun) {
|
|
83
|
-
if (!dryRunArgs) return null;
|
|
84
|
-
return spawnSync(cmd, dryRunArgs, { cwd, encoding: 'utf8' });
|
|
85
|
-
}
|
|
86
|
-
return spawnSync(cmd, args, { cwd, encoding: 'utf8' });
|
|
87
|
-
},
|
|
88
|
-
|
|
89
76
|
// A sonda que decide se há o que fazer fica fora daqui: sondar é ler, e ler acontece nos dois modos.
|
|
90
77
|
gitIndex(op, path, options = {}) {
|
|
91
78
|
record('gitIndex', path, { detail: op });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { readJsonFile } from '../json-file.js';
|
|
4
|
+
import { realEffects } from './effects.js';
|
|
5
|
+
|
|
6
|
+
export const ASSET_DIRS = ['commands', 'rules', 'skills', 'agents'];
|
|
7
|
+
|
|
8
|
+
export const manifestPath = (projectDir) => join(projectDir, '.morph', 'framework', 'installed.json');
|
|
9
|
+
|
|
10
|
+
const emptyManifest = () => Object.fromEntries(ASSET_DIRS.map((dir) => [dir, []]));
|
|
11
|
+
|
|
12
|
+
function normalize(raw) {
|
|
13
|
+
const manifest = emptyManifest();
|
|
14
|
+
for (const dir of ASSET_DIRS) {
|
|
15
|
+
if (!Array.isArray(raw?.[dir])) continue;
|
|
16
|
+
manifest[dir] = [...new Set(raw[dir].filter((name) => typeof name === 'string'))].sort();
|
|
17
|
+
}
|
|
18
|
+
return manifest;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* What morph-spec installed in each of `.claude/{commands,rules,skills,agents}`, by entry name
|
|
23
|
+
* (a skill is its directory). `null` when the project has no manifest.
|
|
24
|
+
*/
|
|
25
|
+
export function readManifest(projectDir) {
|
|
26
|
+
const path = manifestPath(projectDir);
|
|
27
|
+
if (!existsSync(path)) return null;
|
|
28
|
+
// An unreadable manifest claims nothing: what the package ships stays removable, a file of the user's does not.
|
|
29
|
+
try { return normalize(readJsonFile(path)); } catch { return emptyManifest(); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function writeManifest(projectDir, manifest, fx = realEffects()) {
|
|
33
|
+
const normalized = normalize(manifest);
|
|
34
|
+
fx.writeJson(manifestPath(projectDir), normalized);
|
|
35
|
+
return normalized;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** For a path that only adds assets. Returns `null`, writing nothing, when the project has no manifest. */
|
|
39
|
+
export function addToManifest(projectDir, dir, names, fx = realEffects()) {
|
|
40
|
+
const manifest = readManifest(projectDir);
|
|
41
|
+
if (!manifest) return null;
|
|
42
|
+
return writeManifest(projectDir, { ...manifest, [dir]: [...manifest[dir], ...names] }, fx);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The one removal rule: in `dir`, morph-spec deletes only what it owns and did not install now —
|
|
47
|
+
* the names the manifest records plus the names the package ships, whatever the stack filter says.
|
|
48
|
+
*/
|
|
49
|
+
export function pruneOwned(dir, { previous = [], shipped = [], installed = [], fx = realEffects() }) {
|
|
50
|
+
if (!existsSync(dir)) return [];
|
|
51
|
+
const owned = new Set([...previous, ...shipped]);
|
|
52
|
+
const kept = new Set(installed);
|
|
53
|
+
const removed = readdirSync(dir).filter((name) => owned.has(name) && !kept.has(name)).sort();
|
|
54
|
+
for (const name of removed) fx.remove(join(dir, name));
|
|
55
|
+
return removed;
|
|
56
|
+
}
|