@polymorphism-tech/morph-spec 11.2.0 → 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 +7 -7
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +1 -1
- package/framework/MORPH.md +2 -2
- package/framework/agents.json +4 -4
- package/framework/docs/CLI.md +19 -11
- package/framework/evals/review-checklist.md +26 -2
- package/framework/hooks/README.md +3 -2
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
- package/framework/mcp/registry.json +15 -15
- package/framework/rules/ai-agents-standards.md +9 -1
- package/framework/rules/gsap-standards.md +8 -0
- package/framework/rules/mcp-standards.md +10 -0
- package/framework/schemas/config.schema.json +7 -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 +4 -3
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +1 -1
- 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 +124 -266
- package/framework/templates/README.md +52 -82
- package/framework/templates/REGISTRY.json +0 -206
- 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 +1 -1
- 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 +2 -4
- package/framework/templates/frontend/nextjs/gsap-scroll-section.tsx.hbs +13 -17
- package/framework/templates/infrastructure/github/README.md +10 -13
- package/package.json +2 -2
- package/src/commands/mcp/manual-setup.js +95 -0
- package/src/commands/mcp/mcp-setup.js +23 -191
- package/src/commands/project/doctor.js +6 -16
- package/src/commands/project/init-contract.js +2 -2
- package/src/commands/project/init.js +15 -133
- package/src/commands/project/stack-scan.js +6 -14
- package/src/commands/project/stack-set.js +1 -1
- package/src/commands/project/standards.js +1 -2
- package/src/commands/project/update.js +52 -66
- package/src/commands/scaffold/scaffold.js +28 -7
- package/src/lib/ai/ai-project-scan.js +1 -4
- package/src/lib/ai/code-audit.js +1 -6
- package/src/lib/ai/registry-audit.js +2 -1
- package/src/lib/config/project-config.js +3 -2
- package/src/lib/contract/apply.js +2 -1
- package/src/lib/contract/merge.js +1 -0
- package/src/lib/contract/scan.js +5 -5
- package/src/lib/detectors/claude-config-detector.js +45 -47
- package/src/lib/detectors/mcp-config.js +2 -1
- package/src/lib/diff/diff-lines.js +2 -7
- package/src/lib/graph/graph-loader.js +2 -1
- package/src/lib/graph/graphifyignore.js +2 -1
- package/src/lib/installers/install-manifest.js +56 -0
- package/src/lib/installers/mcp-installer.js +14 -5
- package/src/lib/installers/rules-installer.js +9 -15
- package/src/lib/installers/stack-assets.js +42 -21
- package/src/lib/installers/stack-sync.js +12 -12
- 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 +3 -2
- package/src/lib/plan/media.js +3 -3
- package/src/lib/plan/plan-parser.js +5 -10
- package/src/lib/review-reports.js +5 -4
- package/src/lib/stack/stack-scan.js +1 -1
- package/src/lib/standards/verified-against.js +1 -1
- package/src/lib/tests-audit/audit.js +1 -1
- package/src/lib/text.js +5 -0
- package/src/scripts/setup-infra.js +22 -33
- package/src/utils/agents-installer.js +13 -30
- package/src/utils/claude-md-injector.js +16 -50
- package/src/utils/claude-settings-manager.js +2 -2
- package/src/utils/file-copier.js +3 -4
- package/src/utils/hooks-installer.js +55 -20
- package/src/utils/skills-installer.js +18 -78
- 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/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/lib/detectors/index.js +0 -153
- package/src/lib/installers/templates-reconcile.js +0 -26
|
@@ -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 = [
|
|
@@ -77,7 +78,7 @@ export function buildGraphifyignore(projectTags = []) {
|
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
const normalize = (text) => String(text)
|
|
81
|
+
const normalize = (text) => stripBom(String(text)).replace(/\r\n/g, '\n');
|
|
81
82
|
|
|
82
83
|
// Ausente → escreve. Idêntico ao que a geração anterior escrevia → migra, só se as regras mudam.
|
|
83
84
|
// Qualquer outra coisa é do usuário: não toca, e em .NET devolve em `outdated` a troca a fazer.
|
|
@@ -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
|
+
}
|
|
@@ -83,11 +83,20 @@ export function isRemoteMcp(config) {
|
|
|
83
83
|
return config.type === 'http' || config.url != null;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
const WINDOWS_SHIMS = new Set(['npx', 'npm', 'pnpm', 'yarn']);
|
|
87
|
+
|
|
88
|
+
// These are `.cmd` shims on Windows, which Claude Code cannot spawn without a shell. `.mcp.json` therefore
|
|
89
|
+
// carries the form of the OS that ran the install: there is no single form both sides can start.
|
|
90
|
+
export function platformConfig(config, platform = process.platform) {
|
|
91
|
+
if (platform !== 'win32' || !WINDOWS_SHIMS.has(config.command)) return { ...config };
|
|
92
|
+
return { ...config, command: 'cmd', args: ['/c', config.command, ...(config.args ?? [])] };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function installAutoMcps(targetPath, mcpsToInstall, platform = process.platform) {
|
|
87
96
|
const servers = {};
|
|
88
97
|
|
|
89
98
|
for (const [name, entry] of Object.entries(mcpsToInstall)) {
|
|
90
|
-
let config =
|
|
99
|
+
let config = platformConfig(entry.install.config, platform);
|
|
91
100
|
if (!isRemoteMcp(config)) {
|
|
92
101
|
if (config.env && Object.values(config.env).every(v => !v)) {
|
|
93
102
|
delete config.env;
|
|
@@ -118,7 +127,7 @@ export function installCompanionSkills(mcpsInstalled, exec = execSync, cwd = pro
|
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
export async function installMcpWithCredentials(targetPath, name, mcpEntry, credentialValues) {
|
|
121
|
-
const config =
|
|
130
|
+
const config = platformConfig(mcpEntry.install.config);
|
|
122
131
|
config.env = { ...config.env, ...credentialValues };
|
|
123
132
|
return installMcpServers(targetPath, { [name]: config });
|
|
124
133
|
}
|
|
@@ -138,12 +147,12 @@ export function generateSetupInstructions(name, mcpEntry) {
|
|
|
138
147
|
return {
|
|
139
148
|
configSnippet,
|
|
140
149
|
credentialUrls,
|
|
141
|
-
cliCommand: setupGuide || `claude mcp add --transport http ${name} ${config.url}`,
|
|
150
|
+
cliCommand: setupGuide || `claude mcp add --transport http --scope project ${name} ${config.url}`,
|
|
142
151
|
isRemote: true
|
|
143
152
|
};
|
|
144
153
|
}
|
|
145
154
|
|
|
146
|
-
const snippetConfig =
|
|
155
|
+
const snippetConfig = platformConfig(config);
|
|
147
156
|
if (credentials.length > 0) {
|
|
148
157
|
snippetConfig.env = {};
|
|
149
158
|
for (const cred of credentials) {
|
|
@@ -2,6 +2,7 @@ import { readFileSync, readdirSync } from 'fs';
|
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { parseStacks, shouldInstall } from '../stack-filter.js';
|
|
4
4
|
import { realEffects } from './effects.js';
|
|
5
|
+
import { pruneOwned } from './install-manifest.js';
|
|
5
6
|
|
|
6
7
|
export const MAF_TAG = 'maf';
|
|
7
8
|
export const MAF_RULE = 'ai-agents-standards.md';
|
|
@@ -31,27 +32,20 @@ export function installRuleFile(rulesSrc, rulesDest, file, projectTags, fx = rea
|
|
|
31
32
|
else fx.writeFile(to, desired);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
export function installRulesForStack(rulesSrc, rulesDest, projectTags, fx = realEffects()) {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
/** `previous`: the rules the manifest records. `prune: false` when the caller already emptied `rulesDest`. */
|
|
36
|
+
export function installRulesForStack(rulesSrc, rulesDest, projectTags, fx = realEffects(), { previous = [], prune = true } = {}) {
|
|
37
|
+
const shipped = readdirSync(rulesSrc).filter(f => f.endsWith('.md'));
|
|
38
|
+
const names = [];
|
|
38
39
|
|
|
39
|
-
for (const file of
|
|
40
|
+
for (const file of shipped) {
|
|
40
41
|
const content = readFileSync(join(rulesSrc, file), 'utf-8');
|
|
41
42
|
if (shouldInstall(parseStacks(content), projectTags)) {
|
|
42
43
|
installRuleFile(rulesSrc, rulesDest, file, projectTags, fx);
|
|
43
|
-
|
|
44
|
+
names.push(file);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
if (!fx.dryRun) {
|
|
49
|
-
for (const file of readdirSync(rulesDest).filter(f => f.endsWith('.md'))) {
|
|
50
|
-
if (!installed.has(file)) {
|
|
51
|
-
fx.remove(join(rulesDest, file));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
48
|
+
if (prune) pruneOwned(rulesDest, { previous, shipped, installed: names, fx });
|
|
55
49
|
|
|
56
|
-
return { installed:
|
|
50
|
+
return { installed: names.length, names };
|
|
57
51
|
}
|
|
@@ -1,43 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readdirSync, readFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { installRulesForStack } from './rules-installer.js';
|
|
4
4
|
import { realEffects } from './effects.js';
|
|
5
|
+
import { ASSET_DIRS, pruneOwned, readManifest, writeManifest } from './install-manifest.js';
|
|
5
6
|
import { parseStacks, shouldInstall } from '../stack-filter.js';
|
|
6
7
|
import { installSkills } from '../../utils/skills-installer.js';
|
|
7
8
|
import { installAgents } from '../../utils/agents-installer.js';
|
|
9
|
+
import { syncAssetDeny } from '../../utils/hooks-installer.js';
|
|
8
10
|
|
|
9
11
|
const FRAMEWORK_SRC = join(import.meta.dirname, '..', '..', '..', 'framework');
|
|
10
12
|
|
|
11
|
-
/**
|
|
12
|
-
export function installCommandsForStack(commandsSrc, commandsDest, projectTags, fx = realEffects()) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
for (const file of
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
installed++;
|
|
20
|
-
} else if (!fx.dryRun && existsSync(dest)) {
|
|
21
|
-
fx.remove(dest);
|
|
22
|
-
}
|
|
13
|
+
/** `previous`: the commands the manifest records. `prune: false` when the caller already emptied `commandsDest`. */
|
|
14
|
+
export function installCommandsForStack(commandsSrc, commandsDest, projectTags, fx = realEffects(), { previous = [], prune = true } = {}) {
|
|
15
|
+
const shipped = readdirSync(commandsSrc).filter(f => f.endsWith('.md'));
|
|
16
|
+
const names = [];
|
|
17
|
+
for (const file of shipped) {
|
|
18
|
+
if (!shouldInstall(parseStacks(readFileSync(join(commandsSrc, file), 'utf-8')), projectTags)) continue;
|
|
19
|
+
fx.copyFile(join(commandsSrc, file), join(commandsDest, file));
|
|
20
|
+
names.push(file);
|
|
23
21
|
}
|
|
24
|
-
|
|
22
|
+
if (prune) pruneOwned(commandsDest, { previous, shipped, installed: names, fx });
|
|
23
|
+
return { installed: names.length, names };
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Rules, commands, skills and agents filtered by `stacks:`; an empty tag list installs the universal ones.
|
|
28
|
+
* Removes only what morph-spec owns (`pruneOwned`), then the manifest becomes what this run installed.
|
|
29
|
+
* `manifest`: the one read before anything was deleted. `createManifest`: a full install or `update`.
|
|
30
|
+
*/
|
|
31
|
+
export async function installAssetsForTags(targetPath, tags, {
|
|
32
|
+
frameworkSrc = FRAMEWORK_SRC, fx = realEffects(), manifest = readManifest(targetPath), prune = true, createManifest = false,
|
|
33
|
+
} = {}) {
|
|
29
34
|
const claudeDir = join(targetPath, '.claude');
|
|
35
|
+
const owned = (dir) => ({ previous: manifest?.[dir] ?? [], prune });
|
|
36
|
+
const results = {};
|
|
30
37
|
for (const [dir, install] of [['rules', installRulesForStack], ['commands', installCommandsForStack]]) {
|
|
31
|
-
|
|
32
|
-
install(join(frameworkSrc, dir), join(claudeDir, dir), tags);
|
|
38
|
+
fx.ensureDir(join(claudeDir, dir));
|
|
39
|
+
results[dir] = install(join(frameworkSrc, dir), join(claudeDir, dir), tags, fx, owned(dir));
|
|
33
40
|
}
|
|
34
|
-
await installSkills(targetPath, { projectTags: tags });
|
|
35
|
-
|
|
41
|
+
results.skills = await installSkills(targetPath, { projectTags: tags, fx, ...owned('skills') });
|
|
42
|
+
results.agents = await installAgents(targetPath, frameworkSrc, { projectTags: tags, fx, ...owned('agents') });
|
|
43
|
+
|
|
44
|
+
// An install with no manifest stays without one here: `update` still owes it the last whole-folder
|
|
45
|
+
// clean, and a manifest born from a partial reinstall would turn what is left over into the user's.
|
|
46
|
+
const written = manifest || createManifest
|
|
47
|
+
? writeManifest(targetPath, Object.fromEntries(ASSET_DIRS.map((dir) => [dir, results[dir].names])), fx)
|
|
48
|
+
: null;
|
|
49
|
+
return { ...results, manifest: written };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** For the paths that reinstall the assets and not the hooks: the per-asset deny follows the new manifest. */
|
|
53
|
+
export async function refreshAssetsForTags(targetPath, tags, options = {}) {
|
|
54
|
+
const result = await installAssetsForTags(targetPath, tags, options);
|
|
55
|
+
if (result.manifest) syncAssetDeny(targetPath, { manifest: result.manifest, fx: options.fx });
|
|
56
|
+
return result;
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
/** The one path init and stack-set share; a project with no tag keeps what setup-infra installed. */
|
|
39
60
|
export async function installStackAssets(targetPath, stackTags, options) {
|
|
40
61
|
if (stackTags.length === 0) return false;
|
|
41
|
-
await
|
|
62
|
+
await refreshAssetsForTags(targetPath, stackTags, options);
|
|
42
63
|
return true;
|
|
43
64
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
-
import { detectProject } from '../detectors/index.js';
|
|
4
3
|
import { scanRepo } from '../contract/scan.js';
|
|
5
4
|
import { getProjectTags, parseStacks, shouldInstall } from '../stack-filter.js';
|
|
6
5
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
6
|
+
import { readJsonFile } from '../json-file.js';
|
|
7
7
|
import { createEffects } from './effects.js';
|
|
8
|
+
import { addToManifest } from './install-manifest.js';
|
|
9
|
+
import { syncAssetDeny } from '../../utils/hooks-installer.js';
|
|
8
10
|
import { MAF_RULE, MAF_TAG, installRuleFile, ruleContentFor } from './rules-installer.js';
|
|
9
11
|
|
|
10
12
|
const COMPOSE_CANDIDATES = ['compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml'];
|
|
@@ -60,10 +62,8 @@ function walk(root, visit) {
|
|
|
60
62
|
*/
|
|
61
63
|
export function detectStackTags(projectDir, { config = null, rulesSrc = RULES_SRC } = {}) {
|
|
62
64
|
const found = new Set();
|
|
63
|
-
const
|
|
64
|
-
for (const t of
|
|
65
|
-
for (const t of structure.integrations) found.add(t);
|
|
66
|
-
for (const t of scanRepo(projectDir).tags) found.add(t);
|
|
65
|
+
const scan = scanRepo(projectDir);
|
|
66
|
+
for (const t of [...(scan.stack ?? '').split('+'), ...scan.tags]) found.add(t);
|
|
67
67
|
|
|
68
68
|
walk(projectDir, (name, path) => {
|
|
69
69
|
if (name.endsWith('.csproj') || name.endsWith('.sln') || name.endsWith('.slnx')) found.add('dotnet');
|
|
@@ -101,10 +101,6 @@ export function mergeDetectedTags(config, tags) {
|
|
|
101
101
|
|
|
102
102
|
const configPathOf = (projectDir) => join(projectDir, '.morph', 'config', 'config.json');
|
|
103
103
|
|
|
104
|
-
function readConfig(path) {
|
|
105
|
-
return JSON.parse(readFileSync(path, 'utf-8').replace(/^/, ''));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
104
|
function missingRules(projectDir, tags, rulesSrc) {
|
|
109
105
|
const rulesDest = join(projectDir, '.claude', 'rules');
|
|
110
106
|
const missing = [];
|
|
@@ -140,7 +136,7 @@ export function syncStackRules(projectDir, {
|
|
|
140
136
|
const configPath = configPathOf(projectDir);
|
|
141
137
|
if (!existsSync(configPath)) return { ...NOOP };
|
|
142
138
|
let config;
|
|
143
|
-
try { config =
|
|
139
|
+
try { config = readJsonFile(configPath); } catch {
|
|
144
140
|
warnOnce(log, `${configPath} ilegível — regras de stack não sincronizadas`);
|
|
145
141
|
return { ...NOOP };
|
|
146
142
|
}
|
|
@@ -159,6 +155,10 @@ export function syncStackRules(projectDir, {
|
|
|
159
155
|
installRuleFile(rulesSrc, rulesDest, file, tags, fx);
|
|
160
156
|
log(` + .claude/rules/${file} (stack: ${tags.join('+')})`);
|
|
161
157
|
}
|
|
158
|
+
if (missing.length) {
|
|
159
|
+
const manifest = addToManifest(projectDir, 'rules', missing, fx);
|
|
160
|
+
if (manifest) syncAssetDeny(projectDir, { manifest, fx });
|
|
161
|
+
}
|
|
162
162
|
return { added: missing, updated: stale, tags, configChanged: merged.changed };
|
|
163
163
|
} catch (err) {
|
|
164
164
|
warnOnce(log, err?.message ?? String(err));
|
|
@@ -191,7 +191,7 @@ export function setProjectStack(projectDir, stack, {
|
|
|
191
191
|
return { error: `tag desconhecida: ${unknown.join(', ') || '(stack vazia)'}. Stack: ${known.stacks.join(' | ')} (unidas por +); --with: ${known.integrations.join(', ')}` };
|
|
192
192
|
}
|
|
193
193
|
let config;
|
|
194
|
-
try { config =
|
|
194
|
+
try { config = readJsonFile(configPath); } catch { return { error: `${configPath} ilegível` }; }
|
|
195
195
|
if (integrations.includes('docker') && !resolveComposeFile(projectDir, config)) {
|
|
196
196
|
return { error: 'docker sem compose não sobe as dependências dos testes: crie o compose primeiro (o plan-check e o update declaram docker quando ele existir)' };
|
|
197
197
|
}
|
|
@@ -209,7 +209,7 @@ export function stackRuleGaps(projectDir, { rulesSrc = RULES_SRC } = {}) {
|
|
|
209
209
|
try {
|
|
210
210
|
const configPath = configPathOf(projectDir);
|
|
211
211
|
if (!existsSync(configPath)) return null;
|
|
212
|
-
const config =
|
|
212
|
+
const config = readJsonFile(configPath);
|
|
213
213
|
const stack = config?.project?.stack;
|
|
214
214
|
const detected = detectStackTags(projectDir, { config, rulesSrc });
|
|
215
215
|
const tags = [...new Set([...getProjectTags(config), ...detected.tags])];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process';
|
|
2
|
-
import { existsSync
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { readJsonFile } from '../json-file.js';
|
|
4
5
|
import { PACKAGE_LOCATIONS } from '../../../framework/hooks/shared/frontend-locations.js';
|
|
5
6
|
import { filterByStack, installAutoMcps, installCompanionSkills, orchestrateMcpSetup } from './mcp-installer.js';
|
|
6
7
|
|
|
@@ -11,7 +12,7 @@ function componentsJsonFiles(targetPath, frontendPath) {
|
|
|
11
12
|
|
|
12
13
|
function missingRegistries(file, wanted) {
|
|
13
14
|
let json;
|
|
14
|
-
try { json =
|
|
15
|
+
try { json = readJsonFile(file); } catch { return null; }
|
|
15
16
|
const current = json.registries ?? {};
|
|
16
17
|
const missing = Object.entries(wanted).filter(([name]) => !(name in current));
|
|
17
18
|
return missing.length > 0 ? { json, missing } : null;
|
|
@@ -24,7 +25,7 @@ function missingRegistries(file, wanted) {
|
|
|
24
25
|
export async function syncStackTooling(targetPath, options) {
|
|
25
26
|
const { config, existingMcps = [], enabledPlugins = [], fx, exec = execSync } = options;
|
|
26
27
|
const stack = config?.project?.stack ?? '';
|
|
27
|
-
const integrations = config?.project?.integrations ?? [];
|
|
28
|
+
const integrations = [...new Set([...(config?.project?.integrations ?? []), ...(config?.project?.tags ?? [])])];
|
|
28
29
|
const result = { mcps: [], skills: [], skillsFailed: [], registries: [] };
|
|
29
30
|
|
|
30
31
|
const { registry, autoInstallable } = orchestrateMcpSetup(targetPath, stack, existingMcps, { autoOnly: true, integrations, enabledPlugins });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
|
|
3
|
+
// PowerShell 5.1's `Out-File -Encoding utf8` writes a BOM that JSON.parse rejects.
|
|
4
|
+
export const stripBom = (text) => text.replace(/^/, '');
|
|
5
|
+
|
|
6
|
+
/** Throws on a missing file or invalid JSON: the caller decides what an unreadable file means. */
|
|
7
|
+
export function readJsonFile(path) {
|
|
8
|
+
return JSON.parse(stripBom(readFileSync(path, 'utf8')));
|
|
9
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** The inline justification that lets a criterion talk about an artifact on purpose. */
|
|
2
2
|
export const ARTIFACT_MARKER_RE = /por\s+que\s+artefato\s*:/i;
|
|
3
3
|
|
|
4
|
-
// Node
|
|
4
|
+
// Node 22 has no inline `(?i:…)` modifier, and the rest of the regex must stay case-sensitive.
|
|
5
5
|
const anyCase = (word) => [...word].map((c) => {
|
|
6
6
|
const lo = c.toLowerCase();
|
|
7
7
|
const up = c.toUpperCase();
|
package/src/lib/plan/checks.js
CHANGED
|
@@ -3,6 +3,7 @@ import { frozenBody } from '../../../framework/hooks/shared/errata.js';
|
|
|
3
3
|
import { findArtifactTerms } from './artifact-vocabulary.js';
|
|
4
4
|
import { mediaCitationError } from './media.js';
|
|
5
5
|
import { scenarioLabel, WORK_NAME } from '../../../framework/hooks/shared/owner-words.js';
|
|
6
|
+
import { foldAccents } from '../text.js';
|
|
6
7
|
import { PROOF_KINDS, RISK_KINDS, REWORK_RUNGS, REUSE_VERDICTS, ADR_SCOPES, SECTIONS, CONFLICTS_HEADING } from './plan-parser.js';
|
|
7
8
|
|
|
8
9
|
const CHECKS_VERSION = 1;
|
|
@@ -12,7 +13,7 @@ export function planHash(text) {
|
|
|
12
13
|
return createHash('sha256').update(frozenBody(text), 'utf8').digest('hex');
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
const foldRisk = (s) => s.
|
|
16
|
+
const foldRisk = (s) => foldAccents(s.replace(/`/g, '')).trim();
|
|
16
17
|
const RISK_BY_FOLD = new Map(RISK_KINDS.map((r) => [foldRisk(r), r]));
|
|
17
18
|
const RUNG_BY_FOLD = new Map(REWORK_RUNGS.map((r) => [foldRisk(r), r]));
|
|
18
19
|
const canonicalRung = (rung) => (rung === null ? null : RUNG_BY_FOLD.get(foldRisk(rung)) ?? false);
|
|
@@ -162,4 +163,4 @@ export function buildChecks(feature, text, plan) {
|
|
|
162
163
|
|
|
163
164
|
// The scenarios came from the issue, or the agent proposed them because the issue had none: then someone approves first.
|
|
164
165
|
const sourceOf = (text) => (/^propost/i.test(String(text ?? '').trim()) ? 'proposta' : text ? 'issue' : null);
|
|
165
|
-
const summaryOf = (plan) => ({ name: plan.summary?.name ?? null, after: plan.summary?.after ?? null, source: sourceOf(plan.summary?.source) });
|
|
166
|
+
const summaryOf = (plan) => ({ name: plan.summary?.name ?? null, after: plan.summary?.after ?? null, watch: plan.summary?.watch ?? [], source: sourceOf(plan.summary?.source) });
|
package/src/lib/plan/media.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { foldAccents } from '../text.js';
|
|
2
|
+
|
|
1
3
|
const MEDIA_STANDARD_IDS = [
|
|
2
4
|
'ai-agents-modalities-image-gen',
|
|
3
5
|
'ai-agents-media-video',
|
|
@@ -18,8 +20,6 @@ function featureGeneratesMedia(planText) {
|
|
|
18
20
|
return MEDIA_STANDARD_IDS.some((id) => tokens.has(id));
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
const fold = (s) => s.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase();
|
|
22
|
-
|
|
23
23
|
// Vocabulário estreito de propósito: "imagem" sozinha (upload, avatar) não é mídia gerada.
|
|
24
24
|
const GENERATED_MEDIA_RE = new RegExp([
|
|
25
25
|
String.raw`\b(gera[rd]?[ao]?s?|geracao|generat\w*)\b[^.\n]{0,40}\b(imagem|imagens|images?|videos?|ilustrac\w*|thumbnails?)\b`,
|
|
@@ -33,7 +33,7 @@ const NO_MEDIA_RE = /^\s*[-*]?\s*\**midia gerada:?\**:?\s*nao\b/m;
|
|
|
33
33
|
/** Plano que fala em gerar imagem ou vídeo e não cita o standard deixaria o guardrail desarmado em silêncio. */
|
|
34
34
|
export function mediaCitationError(planText) {
|
|
35
35
|
if (typeof planText !== 'string' || featureGeneratesMedia(planText)) return null;
|
|
36
|
-
const text =
|
|
36
|
+
const text = foldAccents(planText);
|
|
37
37
|
if (NO_MEDIA_RE.test(text)) return null;
|
|
38
38
|
const hit = GENERATED_MEDIA_RE.exec(text);
|
|
39
39
|
if (!hit) return null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tableCells, isTableLine, SEPARATOR_ROW_RE } from '../specs/gfm-table.js';
|
|
2
|
+
import { foldAccents } from '../text.js';
|
|
2
3
|
import { ARTIFACT_MARKER_RE } from './artifact-vocabulary.js';
|
|
3
4
|
import { markdownLines } from '../../../framework/hooks/shared/errata.js';
|
|
4
5
|
|
|
@@ -44,7 +45,7 @@ const ADR_PLAIN = {
|
|
|
44
45
|
const WHY_RE =new RegExp(String.raw`^\s*>\s*` + ARTIFACT_MARKER_RE.source + String.raw`\s*(.*?)\s*$`, 'i');
|
|
45
46
|
const SCOPE_RE = /^\s*\*\*Alcance:\*\*\s*(.*?)\s*$/i;
|
|
46
47
|
|
|
47
|
-
const fold = (s) => s
|
|
48
|
+
const fold = (s) => foldAccents(s).trim();
|
|
48
49
|
|
|
49
50
|
function splitSections(lines) {
|
|
50
51
|
const sections = [];
|
|
@@ -150,12 +151,11 @@ function parseReuse(lines) {
|
|
|
150
151
|
line: line.n,
|
|
151
152
|
});
|
|
152
153
|
}
|
|
153
|
-
return
|
|
154
|
+
return rows;
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
function parseSummary(lines) {
|
|
157
158
|
const found = { name: null, kind: null, today: null, after: null, source: null, watch: [] };
|
|
158
|
-
const rest = [];
|
|
159
159
|
let open = null;
|
|
160
160
|
for (const line of lines) {
|
|
161
161
|
const m = !line.fenced && SUMMARY_RE.exec(line.raw);
|
|
@@ -168,9 +168,8 @@ function parseSummary(lines) {
|
|
|
168
168
|
}
|
|
169
169
|
if (open && /^\s+\S/.test(line.raw)) { open.text += ` ${line.raw.trim()}`; continue; }
|
|
170
170
|
open = null;
|
|
171
|
-
rest.push(line.raw);
|
|
172
171
|
}
|
|
173
|
-
return { name: found.name?.text ?? null, kind: found.kind?.text.trim().toLowerCase() ?? null, today: found.today?.text ?? null, after: found.after?.text ?? null, source: found.source?.text ?? null, watch: found.watch.map((w) => w.text)
|
|
172
|
+
return { name: found.name?.text ?? null, kind: found.kind?.text.trim().toLowerCase() ?? null, today: found.today?.text ?? null, after: found.after?.text ?? null, source: found.source?.text ?? null, watch: found.watch.map((w) => w.text) };
|
|
174
173
|
}
|
|
175
174
|
|
|
176
175
|
function parseDefaults(lines) {
|
|
@@ -215,7 +214,6 @@ export function parsePlan(text) {
|
|
|
215
214
|
}
|
|
216
215
|
const body = (key) => byName.get(key)?.lines ?? [];
|
|
217
216
|
const decisions = parseDecisions(body('decisions'));
|
|
218
|
-
const reuse = parseReuse(body('reuse'));
|
|
219
217
|
const errata = byName.get('errata');
|
|
220
218
|
|
|
221
219
|
return {
|
|
@@ -224,14 +222,11 @@ export function parsePlan(text) {
|
|
|
224
222
|
scenarios: parseScenarios(body('scenarios')),
|
|
225
223
|
adrs: decisions.adrs,
|
|
226
224
|
conflicts: decisions.conflicts,
|
|
227
|
-
reuse: reuse
|
|
228
|
-
reuseHeader: reuse.header,
|
|
225
|
+
reuse: parseReuse(body('reuse')),
|
|
229
226
|
summary: parseSummary(body('summary')),
|
|
230
227
|
defaults: parseDefaults(body('defaults')),
|
|
231
228
|
states: parseStates(body('states')),
|
|
232
229
|
flow: parseStates(body('flow')),
|
|
233
|
-
text: Object.fromEntries(Object.keys(SECTIONS).map((k) => [k, body(k).map((l) => l.raw).join('\n').trim()])),
|
|
234
|
-
errata: errata ? errata.lines.map((l) => l.raw).join('\n').trim() : null,
|
|
235
230
|
sectionsAfterErrata: errata ? sections.filter((s) => s.line > errata.line).map((s) => s.name) : [],
|
|
236
231
|
};
|
|
237
232
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { OUTPUT_SCHEMA } from '../core/paths/output-schema.js';
|
|
4
|
+
import { tableCells } from './specs/gfm-table.js';
|
|
5
|
+
import { foldAccents } from './text.js';
|
|
4
6
|
import { PARTIAL_MARKER } from '../../framework/hooks/shared/report-progress.js';
|
|
5
7
|
|
|
6
8
|
export const VERDICT_TOKEN = '**Verdict:**';
|
|
@@ -39,7 +41,7 @@ function lastSectionBody(text, re) {
|
|
|
39
41
|
return bodies.length ? bodies[bodies.length - 1] : null;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
const normalize = (s) => String(s ?? '')
|
|
44
|
+
const normalize = (s) => foldAccents(String(s ?? '')).replace(/\s+/g, ' ').trim();
|
|
43
45
|
const cleanId = (s) => String(s ?? '').replace(/[*`_]/g, '').trim().toUpperCase();
|
|
44
46
|
|
|
45
47
|
const isSeparator = (cells) => cells.every((c) => /^:?-{2,}:?$/.test(c) || c === '');
|
|
@@ -54,10 +56,9 @@ function tableRows(body, keepHeader = () => true) {
|
|
|
54
56
|
const lines = body.split(/\r?\n/);
|
|
55
57
|
for (const [i, line] of lines.entries()) {
|
|
56
58
|
if (!/^\s*\|/.test(line)) { skipping = false; continue; }
|
|
57
|
-
const cells = line
|
|
59
|
+
const cells = tableCells(line);
|
|
58
60
|
if (isSeparator(cells)) continue;
|
|
59
|
-
|
|
60
|
-
if (next && /^\s*\|/.test(lines[i + 1]) && isSeparator(next) && !skipping) {
|
|
61
|
+
if (/^\s*\|/.test(lines[i + 1] ?? '') && isSeparator(tableCells(lines[i + 1])) && !skipping) {
|
|
61
62
|
skipping = !keepHeader(cells);
|
|
62
63
|
continue;
|
|
63
64
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
2
2
|
import { join, relative } from 'path';
|
|
3
3
|
import { getProjectTags } from '../stack-filter.js';
|
|
4
|
-
import { PACKAGE_LOCATIONS } from '
|
|
4
|
+
import { PACKAGE_LOCATIONS } from '../../../framework/hooks/shared/frontend-locations.js';
|
|
5
5
|
import { isTestPath } from '../diff/diff-lines.js';
|
|
6
6
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ const AI_PIN_RELATIVE = join('framework', 'ai-pin.json');
|
|
|
11
11
|
|
|
12
12
|
// Group 1 = subject, group 2 = ISO date. `[^\n]*?` keeps it on one line: a
|
|
13
13
|
// `Last-verified:` further down belongs to another claim.
|
|
14
|
-
|
|
14
|
+
const LAST_VERIFIED_RE = /\*\*Verified against:\*\*([^\n]*?)Last-verified:\s*(\d{4}-\d{2}-\d{2})/;
|
|
15
15
|
|
|
16
16
|
// Real markers are end-of-line and often lack a colon (`x; // VERIFY namespace`),
|
|
17
17
|
// so no line-start/colon anchor. The fence rule lives in countVerifyMarkers.
|
|
@@ -2,6 +2,7 @@ import { execFileSync } from 'child_process';
|
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
3
|
import { basename, join } from 'path';
|
|
4
4
|
import { isTestPath } from '../diff/diff-lines.js';
|
|
5
|
+
import { lineOf } from '../text.js';
|
|
5
6
|
|
|
6
7
|
const PROSE_MIN_HITS = 3;
|
|
7
8
|
const FAMILY_MIN_SIZE = 4;
|
|
@@ -24,7 +25,6 @@ function trackedTestFiles(root) {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const lineOf = (text, index) => text.slice(0, index).split('\n').length;
|
|
28
28
|
const countOf = (text, re) => (text.match(re) ?? []).length;
|
|
29
29
|
|
|
30
30
|
function factFamilies(text) {
|
package/src/lib/text.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Lowercase without diacritics: `Regressão` and `regressao` compare equal. */
|
|
2
|
+
export const foldAccents = (s) => s.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase();
|
|
3
|
+
|
|
4
|
+
/** 1-based line of a character offset. */
|
|
5
|
+
export const lineOf = (text, index) => text.slice(0, index).split('\n').length;
|