@polymorphism-tech/morph-spec 11.1.1 → 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 +49 -153
- 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 -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 +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 -13
- 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,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'], {
|
|
@@ -41,10 +41,9 @@ const PREVIOUS = {
|
|
|
41
41
|
dotnet: ['**/*.Tests/', '**/*Tests/', '**/*.Test/', ...DOTNET_BUILD_OUTPUT],
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
const DOTNET_TAGS = new Set(['dotnet'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
]);
|
|
44
|
+
const DOTNET_TAGS = new Set(['dotnet']);
|
|
45
|
+
// `nodejs`: what the detector wrote into config.json before it said `node`.
|
|
46
|
+
const WEB_TAGS = new Set(['nextjs', 'react', 'vue', 'node', 'nodejs']);
|
|
48
47
|
|
|
49
48
|
const hasDotnetTag = (tags) => [...new Set(tags)].some((t) => DOTNET_TAGS.has(t));
|
|
50
49
|
|
|
@@ -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 });
|
|
@@ -58,7 +58,7 @@ export function getInstalledMcps(existingServers, registry, enabledPlugins = [])
|
|
|
58
58
|
return installed;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
function checkPrerequisites(mcpEntry) {
|
|
62
62
|
const prereqs = mcpEntry.install?.prerequisites || [];
|
|
63
63
|
const results = [];
|
|
64
64
|
|
|
@@ -83,18 +83,6 @@ export function isRemoteMcp(config) {
|
|
|
83
83
|
return config.type === 'http' || config.url != null;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
// On Windows npx must run via `cmd /c` (ENOENT otherwise); the registry already stores that form,
|
|
87
|
-
// this covers legacy configs.
|
|
88
|
-
export function patchConfigForPlatform(config) {
|
|
89
|
-
if (isRemoteMcp(config)) return config;
|
|
90
|
-
if (config.command !== 'npx') return config;
|
|
91
|
-
return {
|
|
92
|
-
...config,
|
|
93
|
-
command: 'cmd',
|
|
94
|
-
args: ['/c', 'npx', ...(config.args || [])]
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
86
|
export async function installAutoMcps(targetPath, mcpsToInstall) {
|
|
99
87
|
const servers = {};
|
|
100
88
|
|
|
@@ -105,7 +93,7 @@ export async function installAutoMcps(targetPath, mcpsToInstall) {
|
|
|
105
93
|
delete config.env;
|
|
106
94
|
}
|
|
107
95
|
}
|
|
108
|
-
servers[name] =
|
|
96
|
+
servers[name] = config;
|
|
109
97
|
}
|
|
110
98
|
|
|
111
99
|
return installMcpServers(targetPath, servers);
|
|
@@ -130,7 +118,7 @@ export function installCompanionSkills(mcpsInstalled, exec = execSync, cwd = pro
|
|
|
130
118
|
}
|
|
131
119
|
|
|
132
120
|
export async function installMcpWithCredentials(targetPath, name, mcpEntry, credentialValues) {
|
|
133
|
-
const config =
|
|
121
|
+
const config = { ...mcpEntry.install.config };
|
|
134
122
|
config.env = { ...config.env, ...credentialValues };
|
|
135
123
|
return installMcpServers(targetPath, { [name]: config });
|
|
136
124
|
}
|
|
@@ -231,7 +219,7 @@ export function formatMcpStatusTable(orchestration, justInstalled = {}) {
|
|
|
231
219
|
|
|
232
220
|
const { autoInstallable, alreadyInstalled, needsManualSetup, notRelevant, prerequisitesMissing, registry } = orchestration;
|
|
233
221
|
|
|
234
|
-
for (const
|
|
222
|
+
for (const name of Object.keys(justInstalled)) {
|
|
235
223
|
const mcpEntry = registry.mcps[name];
|
|
236
224
|
rows.push({
|
|
237
225
|
name,
|
|
@@ -240,7 +228,7 @@ export function formatMcpStatusTable(orchestration, justInstalled = {}) {
|
|
|
240
228
|
});
|
|
241
229
|
}
|
|
242
230
|
|
|
243
|
-
for (const
|
|
231
|
+
for (const name of Object.keys(autoInstallable)) {
|
|
244
232
|
if (justInstalled[name]) continue;
|
|
245
233
|
rows.push({
|
|
246
234
|
name,
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
// The path encoding mirrors Claude Code's scheme (slashes and colons become dashes);
|
|
2
|
-
// MORPH_MEMORY_ROOT overrides the root in tests.
|
|
3
|
-
|
|
4
1
|
import fs from 'fs-extra';
|
|
5
2
|
import { join } from 'path';
|
|
6
3
|
import { homedir } from 'os';
|
|
7
4
|
|
|
5
|
+
// Claude Code names the project folder by turning every non-alphanumeric character into a dash.
|
|
6
|
+
export const encodeProjectPath = (projectPath) => projectPath.replace(/[^A-Za-z0-9]/g, '-');
|
|
7
|
+
|
|
8
8
|
function getMemoryRoot(projectPath) {
|
|
9
9
|
if (process.env.MORPH_MEMORY_ROOT) return process.env.MORPH_MEMORY_ROOT;
|
|
10
|
-
|
|
11
|
-
const encoded = projectPath.replace(/[:\\/]/g, '-').replace(/^-+/, '');
|
|
12
|
-
return join(homedir(), '.claude', 'projects', encoded, 'memory');
|
|
10
|
+
return join(homedir(), '.claude', 'projects', encodeProjectPath(projectPath), 'memory');
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
function projectMemoryContent(info) {
|
|
@@ -54,8 +52,7 @@ metadata:
|
|
|
54
52
|
|
|
55
53
|
# morph-spec context locations
|
|
56
54
|
|
|
57
|
-
- \`.morph/context/
|
|
58
|
-
- \`.morph/context/design-system.md\` — design tokens and components (source of truth)
|
|
55
|
+
- \`.morph/context/design-system.md\` — design tokens and components, when the project has a UI
|
|
59
56
|
- \`.morph/specs/adrs/\` — project-scope decisions, written by plan-check
|
|
60
57
|
- \`.morph/framework/CLI.md\` — the CLI reference, one section per command
|
|
61
58
|
- \`.morph/framework/evals/review-checklist.md\` — what the review personas check (SHIP/FIX + evidence-typed blockers)
|
|
@@ -1,17 +1,43 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'fs';
|
|
1
2
|
import { join } from 'path';
|
|
2
3
|
import { installRulesForStack } from './rules-installer.js';
|
|
3
|
-
import {
|
|
4
|
+
import { realEffects } from './effects.js';
|
|
5
|
+
import { parseStacks, shouldInstall } from '../stack-filter.js';
|
|
4
6
|
import { installSkills } from '../../utils/skills-installer.js';
|
|
5
7
|
import { installAgents } from '../../utils/agents-installer.js';
|
|
6
8
|
|
|
7
9
|
const FRAMEWORK_SRC = join(import.meta.dirname, '..', '..', '..', 'framework');
|
|
8
10
|
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
11
|
+
/** Clean-slate: removes only a framework command the stack filtered out, never one the user wrote. */
|
|
12
|
+
export function installCommandsForStack(commandsSrc, commandsDest, projectTags, fx = realEffects()) {
|
|
13
|
+
const sourceFiles = readdirSync(commandsSrc).filter(f => f.endsWith('.md'));
|
|
14
|
+
let installed = 0;
|
|
15
|
+
for (const file of sourceFiles) {
|
|
16
|
+
const dest = join(commandsDest, file);
|
|
17
|
+
if (shouldInstall(parseStacks(readFileSync(join(commandsSrc, file), 'utf-8')), projectTags)) {
|
|
18
|
+
fx.copyFile(join(commandsSrc, file), dest);
|
|
19
|
+
installed++;
|
|
20
|
+
} else if (!fx.dryRun && existsSync(dest)) {
|
|
21
|
+
fx.remove(dest);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { installed };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Rules, commands, skills and agents filtered by `stacks:`; an empty tag list installs the universal ones. Returns the agents result. */
|
|
28
|
+
export async function installAssetsForTags(targetPath, tags, { frameworkSrc = FRAMEWORK_SRC } = {}) {
|
|
29
|
+
const claudeDir = join(targetPath, '.claude');
|
|
30
|
+
for (const [dir, install] of [['rules', installRulesForStack], ['commands', installCommandsForStack]]) {
|
|
31
|
+
mkdirSync(join(claudeDir, dir), { recursive: true });
|
|
32
|
+
install(join(frameworkSrc, dir), join(claudeDir, dir), tags);
|
|
33
|
+
}
|
|
34
|
+
await installSkills(targetPath, { projectTags: tags });
|
|
35
|
+
return installAgents(targetPath, frameworkSrc, { projectTags: tags });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The one path init and stack-set share; a project with no tag keeps what setup-infra installed. */
|
|
39
|
+
export async function installStackAssets(targetPath, stackTags, options) {
|
|
11
40
|
if (stackTags.length === 0) return false;
|
|
12
|
-
|
|
13
|
-
installCommandsForStack(join(frameworkSrc, 'commands'), join(targetPath, '.claude', 'commands'), stackTags);
|
|
14
|
-
await installSkills(targetPath, { projectTags: stackTags });
|
|
15
|
-
await installAgents(targetPath, frameworkSrc, { projectTags: stackTags });
|
|
41
|
+
await installAssetsForTags(targetPath, stackTags, options);
|
|
16
42
|
return true;
|
|
17
43
|
}
|
|
@@ -10,7 +10,7 @@ import { MAF_RULE, MAF_TAG, installRuleFile, ruleContentFor } from './rules-inst
|
|
|
10
10
|
const COMPOSE_CANDIDATES = ['compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml'];
|
|
11
11
|
|
|
12
12
|
function resolveComposeFile(cwd, config) {
|
|
13
|
-
const configured = config?.e2e?.composeFile;
|
|
13
|
+
const configured = config?.project?.deps?.compose ?? config?.e2e?.composeFile;
|
|
14
14
|
if (configured) return existsSync(join(cwd, configured)) ? configured : null;
|
|
15
15
|
return COMPOSE_CANDIDATES.find((name) => existsSync(join(cwd, name))) ?? null;
|
|
16
16
|
}
|
|
@@ -32,7 +32,7 @@ function ruleFiles(rulesSrc) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** The tags some rule's `stacks:` names: the only detected tags worth persisting. */
|
|
35
|
-
|
|
35
|
+
function ruleTags(rulesSrc = RULES_SRC) {
|
|
36
36
|
return new Set(ruleFiles(rulesSrc).flatMap(({ stacks }) => stacks).filter((s) => s !== '*'));
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -56,7 +56,7 @@ function walk(root, visit) {
|
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* `tags`: what the files show, for picking rules. `persist`: the subset safe to write into config.json —
|
|
59
|
-
* `docker` only with a compose file
|
|
59
|
+
* `docker` only with a compose file: a declared `docker` without one has no dependencies to bring up.
|
|
60
60
|
*/
|
|
61
61
|
export function detectStackTags(projectDir, { config = null, rulesSrc = RULES_SRC } = {}) {
|
|
62
62
|
const found = new Set();
|
|
@@ -193,7 +193,7 @@ export function setProjectStack(projectDir, stack, {
|
|
|
193
193
|
let config;
|
|
194
194
|
try { config = readConfig(configPath); } catch { return { error: `${configPath} ilegível` }; }
|
|
195
195
|
if (integrations.includes('docker') && !resolveComposeFile(projectDir, config)) {
|
|
196
|
-
return { error: 'docker sem compose
|
|
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
|
}
|
|
198
198
|
|
|
199
199
|
const project = { ...(config.project ?? {}), stack: stackTags.join('+') };
|
package/src/lib/plan/checks.js
CHANGED
|
@@ -5,7 +5,7 @@ import { mediaCitationError } from './media.js';
|
|
|
5
5
|
import { scenarioLabel, WORK_NAME } from '../../../framework/hooks/shared/owner-words.js';
|
|
6
6
|
import { PROOF_KINDS, RISK_KINDS, REWORK_RUNGS, REUSE_VERDICTS, ADR_SCOPES, SECTIONS, CONFLICTS_HEADING } from './plan-parser.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const CHECKS_VERSION = 1;
|
|
9
9
|
|
|
10
10
|
/** sha256 of the plan without its errata: appending a correction never invalidates the extracted checks. */
|
|
11
11
|
export function planHash(text) {
|
package/src/lib/plan/media.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
const MEDIA_STANDARD_IDS = [
|
|
2
2
|
'ai-agents-modalities-image-gen',
|
|
3
3
|
'ai-agents-media-video',
|
|
4
4
|
'ai-agents-media-pipeline',
|
|
5
5
|
];
|
|
6
6
|
|
|
7
7
|
// O plano escreve o standard pelo id ou pelo caminho (com ou sem `framework/`/`standards/`).
|
|
8
|
-
|
|
8
|
+
function standardIdOf(value) {
|
|
9
9
|
return String(value ?? '').trim().replace(/\\/g, '/')
|
|
10
10
|
.replace(/^(\.morph\/)?(framework\/)?(standards\/)?/, '')
|
|
11
11
|
.replace(/\.md$/, '')
|
|
12
12
|
.replace(/\//g, '-');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
function featureGeneratesMedia(planText) {
|
|
16
16
|
if (typeof planText !== 'string') return false;
|
|
17
17
|
const tokens = new Set(planText.split(/[\s`'",;:()[\]|]+/).map((t) => standardIdOf(t.replace(/[.!?]+$/, ''))));
|
|
18
18
|
return MEDIA_STANDARD_IDS.some((id) => tokens.has(id));
|
|
@@ -36,7 +36,7 @@ const TITLE_RE = /^\s*t[ií]tulo\s*:\s*(.*?)\s*$/i;
|
|
|
36
36
|
const SUMMARY_RE = /^\s*[-*]\s+\**\s*(nome|tipo|hoje|depois|origem|aten[çc][ãa]o)\s*\**\s*:\s*\**\s*(.+?)\s*$/i;
|
|
37
37
|
const SUMMARY_KEYS = { nome: 'name', tipo: 'kind', hoje: 'today', depois: 'after', origem: 'source' };
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const ADR_PLAIN = {
|
|
40
40
|
decided: /^\s*\*\*Decidimos:\*\*\s*(.+?)\s*$/im,
|
|
41
41
|
why: /^\s*\*\*Por qu[eê]:\*\*\s*(.+?)\s*$/im,
|
|
42
42
|
cost: /^\s*\*\*O que custa:\*\*\s*(.+?)\s*$/im,
|
|
@@ -7,7 +7,7 @@ export const VERDICT_TOKEN = '**Verdict:**';
|
|
|
7
7
|
export const REVIEWED_SHA_TOKEN = '**Reviewed-SHA:**';
|
|
8
8
|
export const VERDICTS = ['SHIP', 'FIX'];
|
|
9
9
|
export const BLOCKER_TYPES = ['check', 'teste', 'regressao', 'seguranca', 'escopo', 'arquitetura', 'performance', 'irreversivel'];
|
|
10
|
-
|
|
10
|
+
const CHECK_STATUSES = ['PROVADO', 'NÃO PROVADO', 'FALHA'];
|
|
11
11
|
|
|
12
12
|
export const REVIEW_ROLES = {
|
|
13
13
|
verifier: { output: 'verifierReport', persona: 'morph-verifier' },
|
|
@@ -16,7 +16,7 @@ export const REVIEW_ROLES = {
|
|
|
16
16
|
};
|
|
17
17
|
const ROLE_ORDER = Object.keys(REVIEW_ROLES);
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const reviewFileName = (role) => OUTPUT_SCHEMA[REVIEW_ROLES[role].output].filename;
|
|
20
20
|
|
|
21
21
|
// Append-only: uma reavaliação acrescenta ao fim, e vale o ÚLTIMO token/seção.
|
|
22
22
|
const VERDICT_RE = /\*\*Verdict:\*\*\s*([A-Za-z]+)/g;
|
|
@@ -45,7 +45,7 @@ const cleanId = (s) => String(s ?? '').replace(/[*`_]/g, '').trim().toUpperCase(
|
|
|
45
45
|
const isSeparator = (cells) => cells.every((c) => /^:?-{2,}:?$/.test(c) || c === '');
|
|
46
46
|
|
|
47
47
|
// A status table a confirmation lists under "Nenhum." is skipped; any other header off the
|
|
48
|
-
// contract still counts, so its rows land in `untyped` and
|
|
48
|
+
// contract still counts, so its rows land in `untyped` and `reviewSignals` reads them as `revisao-fix`.
|
|
49
49
|
const isStatusHeader = (header) => /^(situacao|status)$/.test(normalize(header[1]));
|
|
50
50
|
|
|
51
51
|
function tableRows(body, keepHeader = () => true) {
|
|
@@ -105,19 +105,14 @@ function splitRounds(text) {
|
|
|
105
105
|
return starts.map((s, i) => text.slice(i === 0 ? 0 : s, starts[i + 1] ?? text.length));
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/**
|
|
109
|
-
* Um relatório de review lido do texto. `checks` é `null` sem a seção `## Checks`.
|
|
110
|
-
* `rounds`: uma entrada por veredito, na ordem do arquivo, com o que aquela rodada escreveu.
|
|
111
|
-
*/
|
|
108
|
+
/** Um relatório de review lido do texto. `checks` é `null` sem a seção `## Checks`. */
|
|
112
109
|
export function parseReviewReport(text) {
|
|
113
110
|
if (typeof text !== 'string') {
|
|
114
|
-
return { partial: false, verdict: undefined, blockers: [], untyped: [],
|
|
111
|
+
return { partial: false, verdict: undefined, blockers: [], untyped: [], checks: null, reviewedSha: null };
|
|
115
112
|
}
|
|
116
|
-
|
|
117
|
-
const last =
|
|
118
|
-
|
|
119
|
-
// Blockers belong to the round that wrote them: a confirmation without `## Bloqueadores` closes the earlier ones.
|
|
120
|
-
return { ...parseRound(text), blockers: last.blockers, untyped: last.untyped, rounds };
|
|
113
|
+
// Blockers belong to the last verdict: one written without `## Bloqueadores` closes the earlier ones.
|
|
114
|
+
const last = parseRound(splitRounds(text).at(-1));
|
|
115
|
+
return { ...parseRound(text), blockers: last.blockers, untyped: last.untyped };
|
|
121
116
|
}
|
|
122
117
|
|
|
123
118
|
function parseRound(text) {
|
|
@@ -130,7 +125,6 @@ function parseRound(text) {
|
|
|
130
125
|
partial: PARTIAL_MARKER.test(firstLine),
|
|
131
126
|
verdict: verdicts.length ? verdicts[verdicts.length - 1] : undefined,
|
|
132
127
|
...(blockersBody === null ? { blockers: [], untyped: [] } : parseBlockers(blockersBody)),
|
|
133
|
-
superseded: verdicts.slice(0, -1),
|
|
134
128
|
checks: checksBodies.length === 0 ? null : parseChecks(checksBodies),
|
|
135
129
|
reviewedSha: shas.length ? shas[shas.length - 1] : null,
|
|
136
130
|
};
|
|
@@ -15,14 +15,14 @@ const INDEX_LABEL = '.morph/specs/adrs/';
|
|
|
15
15
|
const INDEX_FILE_RE = /^([a-z0-9][a-z0-9-]*)--(ADR-\d+)\.md$/;
|
|
16
16
|
|
|
17
17
|
/** `admin/ADR-001` ↔ `admin--ADR-001.md`. */
|
|
18
|
-
|
|
18
|
+
const adrFileName = (ref) => `${ref.replace('/', '--')}.md`;
|
|
19
19
|
const refOf = (name) => {
|
|
20
20
|
const m = INDEX_FILE_RE.exec(name);
|
|
21
21
|
return m ? `${m[1]}/${m[2]}` : null;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
function renderAdrFile({ ref, title, body }, feature) {
|
|
25
|
-
const source = `.morph/
|
|
25
|
+
const source = `.morph/features/${feature}/${PLAN.phaseDir}/${PLAN.filename}`;
|
|
26
26
|
return [
|
|
27
27
|
'---',
|
|
28
28
|
`adr: ${ref}`,
|
|
@@ -32,7 +32,7 @@ function renderAdrFile({ ref, title, body }, feature) {
|
|
|
32
32
|
'',
|
|
33
33
|
`# ${ref}: ${title}`,
|
|
34
34
|
'',
|
|
35
|
-
'> Mantido pelo `morph-spec
|
|
35
|
+
'> Mantido pelo `morph-spec plan-check` — não edite à mão. Vale no projeto até que o `plan.md` de uma',
|
|
36
36
|
'> feature o revogue em `### Conflitos com o acervo`: por inteiro, e este arquivo sai; em parte, e `scope:` diz onde ele ainda vale.',
|
|
37
37
|
'',
|
|
38
38
|
body,
|
|
@@ -115,7 +115,7 @@ export function revocationWarnings(cwd, plan) {
|
|
|
115
115
|
const indexed = new Set(readAdrIndex(cwd).map((a) => a.ref));
|
|
116
116
|
for (const e of entries) {
|
|
117
117
|
if (!indexed.has(e.id)) {
|
|
118
|
-
warnings.push(`### Conflitos com o acervo: ${e.id} não está no índice de ADRs ativos (${INDEX_LABEL}) —
|
|
118
|
+
warnings.push(`### Conflitos com o acervo: ${e.id} não está no índice de ADRs ativos (${INDEX_LABEL}) — não há o que retirar`);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
return warnings;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// plan-check reports the problems while the plan can still change, so nothing ambiguous reaches the
|
|
1
|
+
// plan-check reports the problems while the plan can still change, so nothing ambiguous reaches the ADR index.
|
|
2
2
|
|
|
3
3
|
import { SEPARATOR_ROW_RE, isTableLine, tableCells } from './gfm-table.js';
|
|
4
4
|
|
|
5
5
|
/** ADR numbers restart in every feature, so only `{feature}/ADR-{nnn}` is unambiguous. */
|
|
6
|
-
|
|
6
|
+
const ADR_REF_RE = /^[a-z0-9][a-z0-9-]*\/ADR-\d+$/;
|
|
7
7
|
|
|
8
8
|
const FENCE_RE = /^\s*(```|~~~)/;
|
|
9
9
|
const REF_TOKEN_RE = /\b[a-z0-9][a-z0-9-]*\/ADR-\d+\b/;
|
|
@@ -55,7 +55,7 @@ export function parseRevocations(conflicts) {
|
|
|
55
55
|
const stray = LIST_ITEM_RE.test(line) ? REF_TOKEN_RE.exec(line) : null;
|
|
56
56
|
if (stray) {
|
|
57
57
|
problems.push({ id: stray[0], reason: 'outside-table',
|
|
58
|
-
message: `${stray[0]} aparece fora da tabela ADR | Mudança | Escopo — só as linhas da tabela são aplicadas
|
|
58
|
+
message: `${stray[0]} aparece fora da tabela ADR | Mudança | Escopo — só as linhas da tabela são aplicadas` });
|
|
59
59
|
}
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
@@ -6,7 +6,7 @@ import { isTestPath } from '../diff/diff-lines.js';
|
|
|
6
6
|
import { WORKTREE_DIR_NAMES } from '../scan/worktree-dirs.js';
|
|
7
7
|
|
|
8
8
|
export const SEVERITIES = ['Bloqueante', 'Alto', 'Médio', 'Baixo'];
|
|
9
|
-
|
|
9
|
+
const MAX_FILES = 20000;
|
|
10
10
|
|
|
11
11
|
const SKIP_DIRS = new Set([
|
|
12
12
|
'node_modules', '.git', 'bin', 'obj', 'dist', 'build', 'out', 'coverage', '.next', '.morph', '.claude', '.vs', '.idea',
|
|
@@ -192,7 +192,7 @@ function auditNextjs(root, read) {
|
|
|
192
192
|
add('Médio', 'ESLint do stack ausente (o lint não barra import proibido nem fetch em `useEffect`)', eslintConfig ? [eslintConfig] : [],
|
|
193
193
|
'`eslint.config.mjs` na raiz do app: `morph-spec standards --show frontend-nextjs-lint#files`');
|
|
194
194
|
} else if (shadcn && !/forbid-elements/.test(read(eslintConfig) ?? '')) {
|
|
195
|
-
add('Baixo', 'ESLint sem `react/forbid-elements` (
|
|
195
|
+
add('Baixo', 'ESLint sem `react/forbid-elements` (elemento cru passa sem aviso no editor)', [eslintConfig],
|
|
196
196
|
'copiar `RAW_ELEMENTS` e o bloco da regra: `morph-spec standards --show frontend-nextjs-lint#files`');
|
|
197
197
|
}
|
|
198
198
|
if (shadcn) {
|
|
@@ -251,7 +251,7 @@ function whereText(where) {
|
|
|
251
251
|
return ` — onde: ${shown}${unique.length > WHERE_LIMIT ? ` (+${unique.length - WHERE_LIMIT})` : ''} (${unique.length} arquivo(s))`;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
function notAuditedReason(result) {
|
|
255
255
|
return result.stack
|
|
256
256
|
? `não auditado: nenhuma regra de varredura para \`${result.stack}\``
|
|
257
257
|
: 'não auditado: project.stack ausente em .morph/config/config.json';
|
|
@@ -5,7 +5,7 @@ export const STANDARDS_FILE = 'STANDARDS.json';
|
|
|
5
5
|
export const STANDARDS_META_FILE = 'STANDARDS.meta.json';
|
|
6
6
|
|
|
7
7
|
/** Per-standard fields that live in the sidecar, keyed by id: no runtime reader needs them to pick a standard. */
|
|
8
|
-
|
|
8
|
+
const META_FIELDS = ['aliases', 'verifiedAgainst', 'provedBy'];
|
|
9
9
|
|
|
10
10
|
export function metaPathFor(standardsJsonPath) {
|
|
11
11
|
return join(dirname(standardsJsonPath), STANDARDS_META_FILE);
|
|
@@ -33,11 +33,11 @@ export function parseVerifiedAgainst(text) {
|
|
|
33
33
|
|
|
34
34
|
// Three real typesettings: backtick before the clause, after it, or the clause in
|
|
35
35
|
// bold mid-sentence. The non-letter prefix keeps `aprovado por` out.
|
|
36
|
-
|
|
36
|
+
const PROVED_BY_TRIGGER_RE = /(?:^|[^a-zA-Z])provado por/gi;
|
|
37
37
|
|
|
38
38
|
// A path needs a `/` and a closing backtick, so denials ("sem cláusula `provado por`")
|
|
39
39
|
// derive nothing. `*`/`_` are separators for the bold form. Anchored: prose ends the scan.
|
|
40
|
-
|
|
40
|
+
const PROVED_BY_PATH_RE =
|
|
41
41
|
/^[\s`,;*_]*(?:\be\b[\s`,;*_]*)?([A-Za-z0-9_.][A-Za-z0-9_.\-]*(?:\/[A-Za-z0-9_.\-]*)+)`/;
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -3,8 +3,8 @@ import { readFileSync } from 'fs';
|
|
|
3
3
|
import { basename, join } from 'path';
|
|
4
4
|
import { isTestPath } from '../diff/diff-lines.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const PROSE_MIN_HITS = 3;
|
|
7
|
+
const FAMILY_MIN_SIZE = 4;
|
|
8
8
|
|
|
9
9
|
const TEST_FILE = /\.(cs|[cm]?[jt]sx?)$/i;
|
|
10
10
|
const CS_CASE = /\[\s*\w*(Fact|Theory)\b/g;
|
|
@@ -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'));
|