@polymorphism-tech/morph-spec 11.5.0 → 12.0.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 -4
- package/bin/morph-spec.js +10 -1
- package/docs/CHEATSHEET.md +3 -3
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +1 -1
- package/framework/MORPH.md +5 -6
- package/framework/agents.json +4 -4
- package/framework/docs/CLI.md +7 -11
- package/framework/evals/review-checklist.md +28 -42
- package/framework/hooks/README.md +1 -1
- package/framework/hooks/claude-code/core/masked-exit.js +16 -5
- package/framework/hooks/claude-code/core/protect-spec-files.js +4 -27
- package/framework/hooks/shared/command-tokens.js +12 -0
- package/framework/rules/implement-report.md +2 -2
- package/framework/rules/plan-grammar.md +9 -25
- package/framework/schemas/config.schema.json +0 -4
- 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 +19 -11
- package/framework/skills/core/morph-plan/SKILL.md +13 -13
- package/framework/skills/core/morph-uiux/SKILL.md +1 -1
- package/framework/standards/STANDARDS.json +1 -1
- package/framework/standards/architecture/engineering-lens.md +1 -1
- package/framework/standards/architecture/stack-baseline.md +2 -2
- package/framework/standards/integration/mcp/mcp-tools.md +1 -1
- package/framework/templates/REGISTRY.json +1 -1
- package/framework/templates/docs/plan.md +7 -75
- package/package.json +1 -1
- package/src/commands/project/init-contract.js +1 -1
- package/src/commands/validation/check.js +10 -8
- package/src/commands/validation/plan-check.js +6 -13
- package/src/lib/check/signals.js +16 -27
- package/src/lib/contract/defaults.js +1 -1
- package/src/lib/installers/memory-installer.js +0 -1
- package/src/lib/plan/checks.js +11 -93
- package/src/lib/plan/plan-parser.js +28 -137
- package/src/lib/review-reports.js +4 -1
- package/src/lib/specs/gfm-table.js +0 -6
- package/src/utils/agents-installer.js +2 -2
- package/src/utils/version-checker.js +9 -0
- package/framework/hooks/shared/errata.js +0 -59
- package/src/lib/specs/adr-index.js +0 -122
- package/src/lib/specs/frontmatter.js +0 -31
- package/src/lib/specs/revocations.js +0 -85
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// One file per ADR under `.morph/specs/adrs/`, so parallel features that index different ADRs merge cleanly.
|
|
2
|
-
|
|
3
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
4
|
-
import { basename, join } from 'path';
|
|
5
|
-
import { readFrontmatterField, setFrontmatterField } from './frontmatter.js';
|
|
6
|
-
import { parseRevocations } from './revocations.js';
|
|
7
|
-
import { parsePlan } from '../plan/plan-parser.js';
|
|
8
|
-
import { OUTPUT_SCHEMA } from '../../core/paths/output-schema.js';
|
|
9
|
-
|
|
10
|
-
/** Project-relative path of the index folder (git pathspec-ready). */
|
|
11
|
-
export const ADR_INDEX_PATHSPEC = join('.morph', 'specs', 'adrs');
|
|
12
|
-
|
|
13
|
-
const PLAN = OUTPUT_SCHEMA.plan;
|
|
14
|
-
const INDEX_LABEL = '.morph/specs/adrs/';
|
|
15
|
-
const INDEX_FILE_RE = /^([a-z0-9][a-z0-9-]*)--(ADR-\d+)\.md$/;
|
|
16
|
-
|
|
17
|
-
/** `admin/ADR-001` ↔ `admin--ADR-001.md`. */
|
|
18
|
-
const adrFileName = (ref) => `${ref.replace('/', '--')}.md`;
|
|
19
|
-
const refOf = (name) => {
|
|
20
|
-
const m = INDEX_FILE_RE.exec(name);
|
|
21
|
-
return m ? `${m[1]}/${m[2]}` : null;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function renderAdrFile({ ref, title, body }, feature) {
|
|
25
|
-
const source = `.morph/features/${feature}/${PLAN.phaseDir}/${PLAN.filename}`;
|
|
26
|
-
return [
|
|
27
|
-
'---',
|
|
28
|
-
`adr: ${ref}`,
|
|
29
|
-
`title: ${JSON.stringify(title)}`,
|
|
30
|
-
`source: ${source}`,
|
|
31
|
-
'---',
|
|
32
|
-
'',
|
|
33
|
-
`# ${ref}: ${title}`,
|
|
34
|
-
'',
|
|
35
|
-
'> Mantido pelo `morph-spec plan-check` — não edite à mão. Vale no projeto até que o `plan.md` de uma',
|
|
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
|
-
'',
|
|
38
|
-
body,
|
|
39
|
-
'',
|
|
40
|
-
].join('\n');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** `[]` when there is no index or it cannot be read. */
|
|
44
|
-
export function readAdrIndex(cwd) {
|
|
45
|
-
const dir = join(cwd, ADR_INDEX_PATHSPEC);
|
|
46
|
-
try {
|
|
47
|
-
if (!existsSync(dir)) return [];
|
|
48
|
-
return readdirSync(dir).sort().flatMap((file) => {
|
|
49
|
-
const ref = refOf(file);
|
|
50
|
-
if (!ref) return [];
|
|
51
|
-
let content = '';
|
|
52
|
-
try { content = readFileSync(join(dir, file), 'utf8'); } catch {}
|
|
53
|
-
return [{ ref, file, title: readFrontmatterField(content, 'title'), scope: readFrontmatterField(content, 'scope') }];
|
|
54
|
-
});
|
|
55
|
-
} catch {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** An unreadable or absent plan touches nothing. */
|
|
61
|
-
export function updateAdrIndex(cwd, featureDir) {
|
|
62
|
-
const result = { changed: false, added: [], revoked: [], narrowed: [], problems: [] };
|
|
63
|
-
const feature = basename(featureDir);
|
|
64
|
-
const dir = join(cwd, ADR_INDEX_PATHSPEC);
|
|
65
|
-
|
|
66
|
-
let plan = null;
|
|
67
|
-
try {
|
|
68
|
-
const planPath = join(featureDir, PLAN.phaseDir, PLAN.filename);
|
|
69
|
-
if (existsSync(planPath)) plan = parsePlan(readFileSync(planPath, 'utf8'));
|
|
70
|
-
} catch {}
|
|
71
|
-
if (!plan) return result;
|
|
72
|
-
|
|
73
|
-
for (const { id, title, body } of plan.adrs.filter((a) => a.scope === 'projeto')) {
|
|
74
|
-
const ref = `${feature}/${id}`;
|
|
75
|
-
const path = join(dir, adrFileName(ref));
|
|
76
|
-
const next = renderAdrFile({ ref, title, body }, feature);
|
|
77
|
-
const existed = existsSync(path);
|
|
78
|
-
if (existed && readFileSync(path, 'utf8') === next) continue;
|
|
79
|
-
mkdirSync(dir, { recursive: true });
|
|
80
|
-
writeFileSync(path, next, 'utf8');
|
|
81
|
-
result.changed = true;
|
|
82
|
-
if (!existed) result.added.push(ref);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const { entries: revocations, problems } = parseRevocations(plan.conflicts?.text);
|
|
86
|
-
result.problems.push(...problems);
|
|
87
|
-
for (const rev of revocations) {
|
|
88
|
-
const path = join(dir, adrFileName(rev.id));
|
|
89
|
-
if (!existsSync(path)) {
|
|
90
|
-
result.problems.push({
|
|
91
|
-
id: rev.id,
|
|
92
|
-
reason: 'adr-not-indexed',
|
|
93
|
-
message: `${rev.id} não está no índice de ADRs ativos (${INDEX_LABEL}) — nada a retirar; o plan.md segue como história`,
|
|
94
|
-
});
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (rev.change === 'total') {
|
|
98
|
-
rmSync(path, { force: true });
|
|
99
|
-
result.revoked.push(rev.id);
|
|
100
|
-
} else {
|
|
101
|
-
writeFileSync(path, setFrontmatterField(readFileSync(path, 'utf8'), 'scope', JSON.stringify(rev.scope)), 'utf8');
|
|
102
|
-
result.narrowed.push(rev.id);
|
|
103
|
-
}
|
|
104
|
-
result.changed = true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** What updateAdrIndex would fail to apply from the revocation table, reported before the plan freezes. */
|
|
111
|
-
export function revocationWarnings(cwd, plan) {
|
|
112
|
-
const { entries, problems } = parseRevocations(plan.conflicts?.text);
|
|
113
|
-
const warnings = problems.map((p) => `### Conflitos com o acervo: ${p.message}`);
|
|
114
|
-
if (entries.length === 0) return warnings;
|
|
115
|
-
const indexed = new Set(readAdrIndex(cwd).map((a) => a.ref));
|
|
116
|
-
for (const e of entries) {
|
|
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}) — não há o que retirar`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return warnings;
|
|
122
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const FRONTMATTER_RE = /^(?---\r?\n)([\s\S]*?)(\r?\n---(?:\r?\n|$))/;
|
|
2
|
-
|
|
3
|
-
/** Preserves every other line, the EOL style and the body; no frontmatter block → unchanged. `value` is written as-is. */
|
|
4
|
-
export function setFrontmatterField(content, key, value) {
|
|
5
|
-
const m = FRONTMATTER_RE.exec(content);
|
|
6
|
-
if (!m || m.index !== 0) return content;
|
|
7
|
-
|
|
8
|
-
const [full, open, body, close] = m;
|
|
9
|
-
const eol = full.includes('\r\n') ? '\r\n' : '\n';
|
|
10
|
-
const fieldLine = new RegExp(`^${key}:[ \\t]*.*$`, 'm');
|
|
11
|
-
// Function replacer: a value carrying `$&` or `$1` is text, not a pattern.
|
|
12
|
-
const next = fieldLine.test(body)
|
|
13
|
-
? body.replace(fieldLine, () => `${key}: ${value}`)
|
|
14
|
-
: `${body}${eol}${key}: ${value}`;
|
|
15
|
-
|
|
16
|
-
return open + next + close + content.slice(full.length);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** `null` when absent; double-quoted values read as JSON strings, single-quoted as YAML (`''` is a quote). */
|
|
20
|
-
export function readFrontmatterField(content, key) {
|
|
21
|
-
const m = FRONTMATTER_RE.exec(content);
|
|
22
|
-
if (!m || m.index !== 0) return null;
|
|
23
|
-
const line = new RegExp(`^${key}:[ \\t]*(.+?)[ \\t]*$`, 'm').exec(m[2]);
|
|
24
|
-
if (!line) return null;
|
|
25
|
-
const raw = line[1].trim();
|
|
26
|
-
if (raw.length >= 2 && raw.startsWith('"') && raw.endsWith('"')) {
|
|
27
|
-
try { return JSON.parse(raw); } catch { return raw; }
|
|
28
|
-
}
|
|
29
|
-
if (raw.length >= 2 && raw.startsWith("'") && raw.endsWith("'")) return raw.slice(1, -1).replace(/''/g, "'");
|
|
30
|
-
return raw;
|
|
31
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// plan-check reports the problems while the plan can still change, so nothing ambiguous reaches the ADR index.
|
|
2
|
-
|
|
3
|
-
import { SEPARATOR_ROW_RE, isTableLine, tableCells } from './gfm-table.js';
|
|
4
|
-
|
|
5
|
-
/** ADR numbers restart in every feature, so only `{feature}/ADR-{nnn}` is unambiguous. */
|
|
6
|
-
const ADR_REF_RE = /^[a-z0-9][a-z0-9-]*\/ADR-\d+$/;
|
|
7
|
-
|
|
8
|
-
const FENCE_RE = /^\s*(```|~~~)/;
|
|
9
|
-
const REF_TOKEN_RE = /\b[a-z0-9][a-z0-9-]*\/ADR-\d+\b/;
|
|
10
|
-
const LIST_ITEM_RE = /^\s*(?:[-*+]|\d+[.)])\s/;
|
|
11
|
-
const CHANGES = new Map([['total', 'total'], ['parcial', 'parcial'], ['partial', 'parcial']]);
|
|
12
|
-
|
|
13
|
-
const isNone = (cell) => /^(?:—|–|-)?$/.test(cell);
|
|
14
|
-
const bare = (cell) => cell.replace(/^[`*]+|[`*]+$/g, '').trim();
|
|
15
|
-
|
|
16
|
-
function readRow(line) {
|
|
17
|
-
const problems = [];
|
|
18
|
-
const problem = (id, reason, message) => problems.push({ id, reason, message });
|
|
19
|
-
|
|
20
|
-
const row = tableCells(line);
|
|
21
|
-
if (row.length < 3) {
|
|
22
|
-
problem(null, 'malformed-row', `linha com ${row.length} coluna(s), esperado 3 (ADR | Mudança | Escopo): ${line.trim()}`);
|
|
23
|
-
return { entry: null, problems };
|
|
24
|
-
}
|
|
25
|
-
const id = bare(row[0]);
|
|
26
|
-
const change = CHANGES.get(bare(row[1]).toLowerCase());
|
|
27
|
-
const scope = isNone(row[2]) ? null : row[2];
|
|
28
|
-
|
|
29
|
-
if (!ADR_REF_RE.test(id)) {
|
|
30
|
-
problem(id || null, 'malformed-id', `"${id}" não é um {feature}/ADR-{nnn}`);
|
|
31
|
-
return { entry: null, problems };
|
|
32
|
-
}
|
|
33
|
-
if (!change) problem(id, 'malformed-change', `${id}: mudança "${bare(row[1])}" — use total ou parcial`);
|
|
34
|
-
if (change === 'parcial' && !scope) {
|
|
35
|
-
problem(id, 'missing-scope', `${id}: revogação parcial precisa dizer onde o antigo ainda vale (coluna Escopo)`);
|
|
36
|
-
} else if (change === 'total' && scope) {
|
|
37
|
-
problem(id, 'scope-on-total', `${id}: revogação total com escopo "${scope}" — se o antigo ainda vale em algum lugar, a mudança é parcial`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return { entry: problems.length ? { id } : { id, change, scope }, problems };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function parseRevocations(conflicts) {
|
|
44
|
-
const problems = [];
|
|
45
|
-
const rows = [];
|
|
46
|
-
let fenced = false;
|
|
47
|
-
let table = null;
|
|
48
|
-
|
|
49
|
-
for (const line of String(conflicts ?? '').split(/\r?\n/)) {
|
|
50
|
-
if (FENCE_RE.test(line)) { fenced = !fenced; table = null; continue; }
|
|
51
|
-
if (fenced) continue;
|
|
52
|
-
|
|
53
|
-
if (!isTableLine(line)) {
|
|
54
|
-
table = null;
|
|
55
|
-
const stray = LIST_ITEM_RE.test(line) ? REF_TOKEN_RE.exec(line) : null;
|
|
56
|
-
if (stray) {
|
|
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` });
|
|
59
|
-
}
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (!table) {
|
|
63
|
-
table = { revocations: bare(tableCells(line)[0] ?? '').toLowerCase() === 'adr', separatorSeen: false };
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (!table.revocations) continue;
|
|
67
|
-
if (!table.separatorSeen) {
|
|
68
|
-
if (SEPARATOR_ROW_RE.test(line)) { table.separatorSeen = true; continue; }
|
|
69
|
-
problems.push({ id: null, reason: 'unreadable-table',
|
|
70
|
-
message: 'tabela de revogação ilegível — falta a linha separadora (|---|---|---|) depois do cabeçalho; nenhuma linha foi lida' });
|
|
71
|
-
table.revocations = false;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const { entry, problems: rowProblems } = readRow(line);
|
|
75
|
-
problems.push(...rowProblems);
|
|
76
|
-
if (entry) rows.push(entry);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const count = new Map();
|
|
80
|
-
for (const r of rows) count.set(r.id, (count.get(r.id) ?? 0) + 1);
|
|
81
|
-
for (const [id, n] of count) {
|
|
82
|
-
if (n > 1) problems.push({ id, reason: 'duplicate-id', message: `${id} aparece em ${n} linhas — nenhuma foi aplicada; deixe uma só` });
|
|
83
|
-
}
|
|
84
|
-
return { entries: rows.filter((r) => r.change && count.get(r.id) === 1), problems };
|
|
85
|
-
}
|