@sabaiway/agent-workflow-kit 20.2.0 → 22.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/CHANGELOG.md +85 -0
- package/README.md +7 -5
- package/SKILL.md +1 -1
- package/bin/install.mjs +10 -11
- package/capability.json +1 -1
- package/launchers/windsurf-workflow.md +3 -1
- package/migrations/3.0.0-hardened-core-loop.md +7 -6
- package/package.json +5 -2
- package/references/advisor-writers.md +1 -1
- package/references/contracts.md +11 -10
- package/references/modes/bootstrap.md +3 -3
- package/references/modes/commit-guard.md +1 -1
- package/references/modes/gates.md +2 -2
- package/references/modes/recommendations.md +3 -3
- package/references/modes/upgrade.md +6 -6
- package/references/scripts/{archive-caps.mjs → archives/archive-caps.mjs} +1 -1
- package/references/scripts/{archive-changelog.mjs → archives/archive-changelog.mjs} +7 -9
- package/references/scripts/{archive-decisions.mjs → archives/archive-decisions.mjs} +13 -10
- package/references/scripts/{archive-issues.mjs → archives/archive-issues.mjs} +7 -8
- package/references/scripts/{check-docs-size.mjs → docs-size/check-docs-size.mjs} +3 -4
- package/references/scripts/docs-size/index.mjs +2 -0
- package/references/scripts/family.json +45 -0
- package/references/scripts/family.mjs +90 -0
- package/references/scripts/gates/kit-command-gates.mjs +117 -0
- package/references/scripts/{migrate-gates.mjs → gates/migrate-gates.mjs} +263 -182
- package/references/scripts/{install-git-hooks.mjs → git-hooks/install-git-hooks.mjs} +50 -38
- package/references/scripts/run.mjs +90 -0
- package/references/scripts/shared/index.mjs +3 -0
- package/references/scripts/shared/project-root.mjs +11 -0
- package/references/scripts/spec-schema/index.mjs +2 -0
- package/references/scripts/test-reporter/reporter.mjs +130 -0
- package/references/shared/composition-handoff.md +1 -1
- package/references/shared/deploy-tail.md +2 -2
- package/references/templates/SPEC_TEMPLATE.md +1 -1
- package/references/templates/adr-record.md +3 -3
- package/tools/apply-danger-check.mjs +9 -5
- package/tools/atomic-write.mjs +3 -1
- package/tools/coverage-producer.mjs +76 -41
- package/tools/direct-run.mjs +2 -0
- package/tools/distribution-files/retired.mjs +99 -0
- package/tools/distribution-files/scripts.mjs +68 -52
- package/tools/ensure-configs.mjs +21 -21
- package/tools/ensure-ops.mjs +60 -18
- package/tools/ensure-specs.mjs +85 -47
- package/tools/ensure-vocabulary.mjs +4 -4
- package/tools/epic-shape-cli.mjs +1 -1
- package/tools/epic-shape-ledger.mjs +1 -1
- package/tools/epic-shape.mjs +1 -1
- package/tools/family-registry.mjs +3 -1
- package/tools/feedback-record-cli.mjs +1 -1
- package/tools/fold-scope.mjs +2 -2
- package/tools/gates-declaration.mjs +22 -14
- package/tools/gates-init.mjs +33 -17
- package/tools/git-hooks.mjs +90 -65
- package/tools/jev-connect.mjs +1 -1
- package/tools/jev-guide.mjs +1 -1
- package/tools/jev-skill.mjs +1 -1
- package/tools/known-footprint.mjs +7 -29
- package/tools/node-evidence.mjs +29 -15
- package/tools/now-cli.mjs +1 -1
- package/tools/payload-prune.mjs +53 -58
- package/tools/plan-shape-cli.mjs +1 -1
- package/tools/plan-shape.mjs +1 -1
- package/tools/project-rules/rules-record.mjs +1 -1
- package/tools/queue-audit-cli.mjs +1 -1
- package/tools/queue-audit.mjs +2 -2
- package/tools/queue-purge-archive.mjs +1 -1
- package/tools/queue-purge-cli.mjs +1 -1
- package/tools/queue-purge.mjs +1 -1
- package/tools/recommendations.mjs +37 -25
- package/tools/script-priors.mjs +31 -3
- package/tools/source-size/piles.mjs +1 -1
- package/tools/spec-adoption.mjs +1 -1
- package/tools/spec-check-ops.mjs +2 -2
- package/tools/spec-check.mjs +2 -2
- package/tools/spec-coverage.mjs +1 -1
- package/tools/tier-guide.mjs +1 -1
- package/tools/transition/index.mjs +1 -1
- package/tools/upgrade-runlist.mjs +3 -3
- package/tools/write-lanes.mjs +2 -2
- package/references/scripts/_expect-shim.mjs +0 -41
- package/references/scripts/archive-caps.test.mjs +0 -321
- package/references/scripts/archive-changelog.test.mjs +0 -560
- package/references/scripts/archive-conservation.test.mjs +0 -466
- package/references/scripts/archive-decisions.test.mjs +0 -1503
- package/references/scripts/archive-issues.test.mjs +0 -825
- package/references/scripts/archiver-structure.test.mjs +0 -84
- package/references/scripts/check-docs-size-cli.test.mjs +0 -325
- package/references/scripts/check-docs-size-ensure.test.mjs +0 -360
- package/references/scripts/check-docs-size.test.mjs +0 -395
- package/references/scripts/install-git-hooks-repo-exec.test.mjs +0 -185
- package/references/scripts/install-git-hooks.test.mjs +0 -241
- package/references/scripts/markdown-blocks.test.mjs +0 -310
- package/references/scripts/migrate-gates-branches.test.mjs +0 -302
- package/references/scripts/migrate-gates.test.mjs +0 -517
- package/references/scripts/spec-schema.test.mjs +0 -352
- /package/references/scripts/{markdown-blocks.mjs → shared/markdown-blocks.mjs} +0 -0
- /package/references/scripts/{spec-schema.mjs → spec-schema/spec-schema.mjs} +0 -0
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// migrate-gates.mjs — the
|
|
3
|
-
// that predates the hardened core declares gates the stripped kit no longer ships (the
|
|
4
|
-
// review-ledger / fold-completeness checks);
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// declaration that PRODUCES the lcov it reads
|
|
10
|
-
//
|
|
2
|
+
// migrate-gates.mjs — the LEGACY gates.json migration (strip-the-kit D8), the kit's MANDATORY move. A
|
|
3
|
+
// deployment that predates the hardened core declares gates the stripped kit no longer ships (the
|
|
4
|
+
// review-ledger / fold-completeness checks); `--apply` migrates the declaration ATOMICALLY, with no
|
|
5
|
+
// question: it REMOVES a canonical legacy entry whose target is proven absent, EXTENDS the canonical
|
|
6
|
+
// `unit-tests` cmd, and SWITCHES every producer form an earlier kit wrote, onto the stable kit
|
|
7
|
+
// command's unit-tests name (the D3(d) coverage source), and moves a declared coverage-check gate LAST.
|
|
8
|
+
// The coverage check stays OPTIONAL: the checker is ADDED only with `--add-checker`, which the agent
|
|
9
|
+
// runs on the user's explicit yes, and only over a declaration that PRODUCES the lcov it reads — over
|
|
10
|
+
// none it is withheld, with the fact and the remedy (spec coverage-producer).
|
|
11
11
|
//
|
|
12
12
|
// Matching is by the DOCUMENTED cmd forms ONLY (hand-wired history included — never by seed
|
|
13
13
|
// provenance): a legacy entry is `node <path>/review-ledger.mjs --check` or
|
|
14
14
|
// `node <path>/fold-completeness.mjs --check` (quoted or bare path, ONE plain invocation); the
|
|
15
|
-
// canonical unit-tests entry is id `unit-tests` with a cmd
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
15
|
+
// canonical unit-tests entry is id `unit-tests` with a cmd `node --test` and a path-shaped rest; an
|
|
16
|
+
// earlier kit's producer form is matched under any id (spec coverage-producer). ANYTHING
|
|
17
|
+
// else, but a kit-check gate the switch below rewrites, is a CUSTOMIZED entry — never auto-touched: the
|
|
18
|
+
// preview reports it loudly and prints the paste-ready recovery so the maintainer applies the intent by
|
|
19
|
+
// hand; the commit guard is NOT to be installed until the declaration is final-run-capable.
|
|
19
20
|
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
21
|
+
// A kit-check gate over a current kit folder that the rules above do not hold customized is SWITCHED to the stable kit command (spec kit-command, read by
|
|
22
|
+
// ./kit-command-gates.mjs); any other form is named.
|
|
23
|
+
//
|
|
24
|
+
// Write discipline (the family's writer contract): preview (dry-run) is the DEFAULT and writes
|
|
25
|
+
// NOTHING, `--add-checker` included; `--apply` rewrites docs/ai/gates.json via exclusive tmp+rename in the same
|
|
22
26
|
// directory; a symlinked gates.json (or docs/ai parent) is a STOP; a malformed declaration is
|
|
23
27
|
// never written over. `--kit-tools <dir>` names the installed kit's tools directory — the
|
|
24
28
|
// migration writes RESOLVED, QUOTED paths for the coverage-check gate (no runtime guessing).
|
|
@@ -27,10 +31,11 @@
|
|
|
27
31
|
// Dependency-free. No side effects on import.
|
|
28
32
|
|
|
29
33
|
import { existsSync, lstatSync, readFileSync, writeFileSync, renameSync, unlinkSync, realpathSync } from 'node:fs';
|
|
30
|
-
import { join, resolve, isAbsolute } from 'node:path';
|
|
34
|
+
import { dirname, join, resolve, isAbsolute } from 'node:path';
|
|
31
35
|
import { fileURLToPath } from 'node:url';
|
|
32
36
|
import { randomBytes } from 'node:crypto';
|
|
33
37
|
import { spawnSync } from 'node:child_process';
|
|
38
|
+
import { planKitCommandGates, repointsOf } from './kit-command-gates.mjs';
|
|
34
39
|
|
|
35
40
|
export const MIGRATE_GATES_STOP = 'MIGRATE_GATES_STOP';
|
|
36
41
|
const stop = (message) =>
|
|
@@ -41,7 +46,7 @@ export const GATES_REL = join('docs', 'ai', 'gates.json');
|
|
|
41
46
|
|
|
42
47
|
// The documented canonical forms — ONE plain invocation, quoted or bare path, `--check` at END
|
|
43
48
|
// (the run-gates strict-matcher shape; a masked/compound form is a CUSTOMIZED entry).
|
|
44
|
-
const legacyRe = (basename) => new RegExp(`^node\\s+(?:"(?:[^"]*[/\\\\])?${basename}"|(?:[^\\s"]*[/\\\\])?${basename})\\s+--check$`);
|
|
49
|
+
const legacyRe = (basename) => new RegExp(`^node\\s+(?:"((?:[^"]*[/\\\\])?${basename})"|((?:[^\\s"]*[/\\\\])?${basename}))\\s+--check$`);
|
|
45
50
|
export const LEGACY_FORMS = Object.freeze([
|
|
46
51
|
{ name: 'review-ledger', re: legacyRe('review-ledger\\.mjs') },
|
|
47
52
|
{ name: 'fold-completeness', re: legacyRe('fold-completeness\\.mjs') },
|
|
@@ -54,31 +59,17 @@ export const LEGACY_FORMS = Object.freeze([
|
|
|
54
59
|
// bytes — so a TEXT drift guard beside the root's copy holds them equal. Edit BOTH, then re-run the
|
|
55
60
|
// mirror sync.
|
|
56
61
|
//
|
|
57
|
-
// The
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// TAP/spec output.
|
|
66
|
-
export const UNIT_TESTS_COVERAGE_FLAGS =
|
|
67
|
-
'--experimental-test-coverage --test-reporter=lcov --test-reporter-destination="${AW_GIT_DIR:?exported by run-gates}/agent-workflow-lcov.info" --test-reporter=spec --test-reporter-destination=stdout';
|
|
68
|
-
|
|
69
|
-
// Every flag set the kit has EVER emitted — APPEND-ONLY, newest first. Emission uses the head; the
|
|
70
|
-
// tail exists so a declaration written by an EARLIER kit and living on disk in a deployed project
|
|
71
|
-
// keeps reading as the producer it is. De-recognizing a prior form would silently reclassify a
|
|
72
|
-
// working suite gate as customized and withhold the checker over it.
|
|
73
|
-
export const KNOWN_COVERAGE_FLAG_SETS = Object.freeze([
|
|
74
|
-
UNIT_TESTS_COVERAGE_FLAGS,
|
|
62
|
+
// The ONE producer form the kit writes: the stable kit command's unit-tests name (spec kit-command) —
|
|
63
|
+
// the Node test runner with the lcov reporter under AW_GIT_DIR and the kit test reporter on stdout.
|
|
64
|
+
export const COVERAGE_PRODUCER_BODY = 'node scripts/agent-workflow/run.mjs unit-tests';
|
|
65
|
+
|
|
66
|
+
// The reporter flag sets earlier kits wrote after `node --test`, newest first, byte for byte: a MOVE
|
|
67
|
+
// LIST the gate migration switches onto the body above, never read as a producer.
|
|
68
|
+
export const RETIRED_COVERAGE_FLAG_SETS = Object.freeze([
|
|
69
|
+
'--experimental-test-coverage --test-reporter=lcov --test-reporter-destination="${AW_GIT_DIR:?exported by run-gates}/agent-workflow-lcov.info" --test-reporter=spec --test-reporter-destination=stdout',
|
|
75
70
|
'--experimental-test-coverage --test-reporter=lcov --test-reporter-destination="$AW_GIT_DIR/agent-workflow-lcov.info" --test-reporter=spec --test-reporter-destination=stdout',
|
|
76
71
|
]);
|
|
77
|
-
|
|
78
|
-
// The ONE suite body that produces that lcov with no extra dependency (the EMITTED form), beside
|
|
79
|
-
// the closed set of bodies recognition accepts.
|
|
80
|
-
export const COVERAGE_PRODUCER_BODY = `node --test ${UNIT_TESTS_COVERAGE_FLAGS}`;
|
|
81
|
-
const KNOWN_PRODUCER_BODIES = Object.freeze(KNOWN_COVERAGE_FLAG_SETS.map((flags) => `node --test ${flags}`));
|
|
72
|
+
const RETIRED_BODIES = Object.freeze(RETIRED_COVERAGE_FLAG_SETS.map((flags) => `node --test ${flags}`));
|
|
82
73
|
|
|
83
74
|
// The per-PM exec wrappers a fill offer puts that body behind. Recognition must cover every form
|
|
84
75
|
// the kit has EMITTED, so the prefixes are matched literally; gates-init's execCmdFor stays the one
|
|
@@ -91,11 +82,11 @@ const PRODUCER_EXEC_PREFIXES = Object.freeze([
|
|
|
91
82
|
|
|
92
83
|
// A trailing suffix is the project's own test paths; a leading one would mean the body is not what
|
|
93
84
|
// this cmd runs. The tail passes a POSITIVE closed grammar — every whitespace-separated token must
|
|
94
|
-
// be path-shaped — never an operator blocklist:
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
85
|
+
// be path-shaped — never an operator blocklist: `<body> && rm -f <lcov>` runs the suite and then
|
|
86
|
+
// DELETES the file, so an open-ended tail would certify a producer that leaves nothing behind, and
|
|
87
|
+
// scanning for operator BYTES would put the incomplete-scan failure on the unsafe side (a missed
|
|
88
|
+
// operator is a dead pair) instead of the mild one (an unrecognised legitimate tail merely
|
|
89
|
+
// withholds the offer — add the gate by hand). No flag either: the command hands it to the runner.
|
|
99
90
|
// The token set is everything that appears in a PATH or a glob and can never sequence, redirect or
|
|
100
91
|
// substitute a command — quoting and `~` included, `( ) $ ` ; & | < > # \` excluded. SCOPE, stated
|
|
101
92
|
// exactly: the screen judges each token's SOURCE bytes. Quote removal adds none, but brace SEQUENCE
|
|
@@ -110,22 +101,65 @@ const PRODUCER_EXEC_PREFIXES = Object.freeze([
|
|
|
110
101
|
// `skipped-no-lcov`.
|
|
111
102
|
const PRODUCER_PATH_TOKEN = /^(?!-)[A-Za-z0-9_./*{},:@+=~?[\]!'"-]+$/;
|
|
112
103
|
const pathShapedTail = (tail) => tail === '' || tail.split(/[ \t]+/).every((token) => PRODUCER_PATH_TOKEN.test(token));
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
104
|
+
|
|
105
|
+
// The exec prefix the trimmed text opens with ('' for none), and the rest after it.
|
|
106
|
+
const splitExecPrefix = (text) => {
|
|
107
|
+
const prefix = PRODUCER_EXEC_PREFIXES.find((p) => text.startsWith(p)) ?? '';
|
|
108
|
+
return [prefix, text.slice(prefix.length)];
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// The rest after `body` (trimmed; '' when nothing follows), or null unless the text is the body, then nothing or one space.
|
|
112
|
+
const bodyRest = (text, body) => {
|
|
113
|
+
if (text === body) return '';
|
|
114
|
+
return text.startsWith(`${body} `) ? text.slice(body.length).trim() : null;
|
|
115
|
+
};
|
|
117
116
|
|
|
118
117
|
// matchesCoverageProducer(cmd) → CLOSED-WORLD over the full command forms the kit emits, never a
|
|
119
|
-
// substring probe: `echo
|
|
120
|
-
//
|
|
121
|
-
// declared over a gate that writes nothing and then PASSES while certifying nothing.
|
|
118
|
+
// substring probe: `echo <body>`, the quoted body or a retired flag set is NOT a producer — else the
|
|
119
|
+
// checker is declared over a gate that writes nothing and then PASSES while certifying nothing.
|
|
122
120
|
export const matchesCoverageProducer = (cmd) => {
|
|
123
121
|
if (typeof cmd !== 'string') return false;
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
return
|
|
122
|
+
const [, text] = splitExecPrefix(cmd.trim());
|
|
123
|
+
const rest = bodyRest(text, COVERAGE_PRODUCER_BODY);
|
|
124
|
+
return rest !== null && pathShapedTail(rest);
|
|
127
125
|
};
|
|
128
126
|
|
|
127
|
+
// retiredProducerFormOf(cmd) → { prefix (as written, or ''), tail (trimmed), pathShaped } when the
|
|
128
|
+
// trimmed cmd is no or one exec prefix, `node --test`, a retired flag set and nothing or one space and
|
|
129
|
+
// a rest; null for every other value. The switch carries only a path-shaped tail onto the body.
|
|
130
|
+
export const retiredProducerFormOf = (cmd) => {
|
|
131
|
+
if (typeof cmd !== 'string') return null;
|
|
132
|
+
const [prefix, text] = splitExecPrefix(cmd.trim());
|
|
133
|
+
for (const body of RETIRED_BODIES) {
|
|
134
|
+
const tail = bodyRest(text, body);
|
|
135
|
+
if (tail !== null) return { prefix, tail, pathShaped: pathShapedTail(tail) };
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// unitTestsGuardFailure → the guard on every write of the body: run.mjs a regular file equal to `ownRun`, then the reporter
|
|
141
|
+
// a regular file, every folder on the way a directory (lstat: a link fails); null, or the first failing path and kind,
|
|
142
|
+
// worded by guardRemedy with the caller's upgrade.
|
|
143
|
+
const GUARD_PATHS = Object.freeze(['scripts/agent-workflow/run.mjs', 'scripts/agent-workflow/test-reporter/reporter.mjs']);
|
|
144
|
+
export const unitTestsGuardFailure = (projectDir, ownRun, { lstatSync, readFileSync }) => {
|
|
145
|
+
for (const rel of GUARD_PATHS) {
|
|
146
|
+
const parts = rel.split('/');
|
|
147
|
+
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
148
|
+
const at = parts.slice(0, depth).join('/');
|
|
149
|
+
const st = lstatSync(`${projectDir}/${at}`, { throwIfNoEntry: false });
|
|
150
|
+
if (st === undefined) return { path: rel, kind: 'absent' };
|
|
151
|
+
if (depth < parts.length ? !st.isDirectory() : !st.isFile()) return { path: at, kind: 'wrong-kind' };
|
|
152
|
+
}
|
|
153
|
+
if (rel === GUARD_PATHS[0] && !readFileSync(`${projectDir}/${rel}`).equals(readFileSync(ownRun))) return { path: rel, kind: 'earlier' };
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
};
|
|
157
|
+
export const guardRemedy = (kind, upgrade) => ({
|
|
158
|
+
absent: `is absent — the kit's upgrade places the kit folder only where Node evidence stands (a root package.json, or a kit script): add one if this project runs Node, then run ${upgrade}.`,
|
|
159
|
+
earlier: `differs from this kit's — run ${upgrade}, whose configs step writes the current one`,
|
|
160
|
+
'wrong-kind': `is not what the kit writes there — a directory, a link, or a file where a folder belongs — beside which the specs op writes nothing: clear it by hand first, then run ${upgrade}`,
|
|
161
|
+
})[kind];
|
|
162
|
+
|
|
129
163
|
// isCoverageProducerGate(gate) → the GATE-level producer question, and the ONE predicate every
|
|
130
164
|
// consumer asks it through: does THIS declared entry write the lcov the canonical checker reads?
|
|
131
165
|
// Exactly two ways to be one — the cmd passes the closed world above, or the declaration CLAIMS
|
|
@@ -145,6 +179,11 @@ export const isCoverageProducerGate = (gate) => {
|
|
|
145
179
|
if (gate.cmd.trim() === '' || /[\r\n]/.test(gate.cmd)) return false;
|
|
146
180
|
return matchesCoverageProducer(gate.cmd) || gate.lcovProducer === true;
|
|
147
181
|
};
|
|
182
|
+
// readsAsCoverageProducer(gate, claim) → the ONE producer question of a declared row, asked by both hosts: `claim` is
|
|
183
|
+
// the row's claim on the coverage-check tool through the checker-claim canon, and only a row that is not the tool
|
|
184
|
+
// (`'not-the-tool'`, equal by test to CHECKER_CLAIM.NOT_THE_TOOL) can produce — a checker, canonical or vendored,
|
|
185
|
+
// consumes the lcov it reads, so its marker claims nothing.
|
|
186
|
+
export const readsAsCoverageProducer = (gate, claim) => claim === 'not-the-tool' && isCoverageProducerGate(gate);
|
|
148
187
|
// coverage-producer canon <<< END drift-guarded region
|
|
149
188
|
|
|
150
189
|
// checker-claim canon >>> BEGIN drift-guarded region
|
|
@@ -242,7 +281,7 @@ export const classifyCheckerClaim = (tool, cmd, projectDir) => {
|
|
|
242
281
|
// checker-claim canon <<< END drift-guarded region
|
|
243
282
|
|
|
244
283
|
// The RETIRED kit-owned git-dir stores the deleted machinery wrote — dead data a consumer's
|
|
245
|
-
// upgrade would otherwise strand forever. The migration cleans them (
|
|
284
|
+
// upgrade would otherwise strand forever. The migration cleans them on apply (named by the preview;
|
|
246
285
|
// ENOENT is a silent no-op; any other unlink error is reported loudly but never fails the
|
|
247
286
|
// migration — the stores are not a gate input).
|
|
248
287
|
export const RETIRED_STORE_BASENAMES = Object.freeze([
|
|
@@ -263,7 +302,31 @@ export const findRetiredStores = (cwd) => {
|
|
|
263
302
|
return RETIRED_STORE_BASENAMES.map((name) => join(gitDir, name)).filter((p) => existsSync(p));
|
|
264
303
|
};
|
|
265
304
|
|
|
266
|
-
const
|
|
305
|
+
const SUITE_LINE = `${COVERAGE_PRODUCER_BODY} <your test paths>`;
|
|
306
|
+
// Every checker line: one positional fact and one remedy; why a gate was kept rides that gate's own line.
|
|
307
|
+
const [WITHHELD_FACT, POSITIONAL_FACT] = ['no declared gate is a producer this kit reads', 'no gate before it is a producer this kit reads'];
|
|
308
|
+
const CHECKER_REMEDY = `declare or move one before it: ${SUITE_LINE}, or mark your own suite gate "lcovProducer": true`;
|
|
309
|
+
|
|
310
|
+
// The guard reads the project's kit folder against this migration's own ../run.mjs; the memory substrate names no sibling skill.
|
|
311
|
+
const OWN_RUN = join(dirname(fileURLToPath(import.meta.url)), '..', 'run.mjs');
|
|
312
|
+
const UPGRADE = "the kit's upgrade";
|
|
313
|
+
const guardLine = ({ id, path, kind }) =>
|
|
314
|
+
` KEPT ${id}: ${path} ${guardRemedy(kind, UPGRADE)} — once that is resolved, ${UPGRADE} moves this gate with no question.`;
|
|
315
|
+
|
|
316
|
+
// legacyTargetAbsent(re, cmd, projectDir) → whether a legacy check's invocation target, resolved from the project root as
|
|
317
|
+
// run-gates resolves a declared token, is PROVEN absent: the checker-claim quoting screens admit the token and its lstat
|
|
318
|
+
// answers ENOENT. A file, a directory or a link there, or a token the screens refuse (`~`, `$`), is no proof.
|
|
319
|
+
const legacyTargetAbsent = (re, cmd, projectDir) => {
|
|
320
|
+
const [, quoted, bare] = re.exec(cmd.trim());
|
|
321
|
+
const token = quoted ?? bare;
|
|
322
|
+
if (!(quoted !== undefined ? !dqUnsafePath(token) : bareTokenSafe(token)) || token.startsWith('-')) return false;
|
|
323
|
+
try {
|
|
324
|
+
lstatSync(isAbsolute(token) ? token : join(projectDir, token));
|
|
325
|
+
return false;
|
|
326
|
+
} catch (err) {
|
|
327
|
+
return err.code === 'ENOENT';
|
|
328
|
+
}
|
|
329
|
+
};
|
|
267
330
|
|
|
268
331
|
// The core checks the stripped core anchors on, asked through the checker-claim canon above — the
|
|
269
332
|
// SAME three outcomes, so a declared cmd is read as what it is: this copy of the tool, a DIFFERENT
|
|
@@ -274,16 +337,22 @@ const CORE_CHECK_NAMES = Object.freeze(['coverage-check', 'review-state']);
|
|
|
274
337
|
const coreCheckTools = (kitToolsDir) =>
|
|
275
338
|
Object.fromEntries(CORE_CHECK_NAMES.map((name) => [name, checkerClaimTool(`${name}.mjs`, join(kitToolsDir, `${name}.mjs`))]));
|
|
276
339
|
|
|
277
|
-
// buildMigrationPlan(gates, kitToolsDir, projectDir) → the
|
|
278
|
-
// plan rows: { action: 'keep' | 'remove' | 'extend' | 'move' | 'add', entry, reason }.
|
|
340
|
+
// buildMigrationPlan(gates, kitToolsDir, projectDir, { addChecker }) → the migration plan.
|
|
341
|
+
// plan rows: { action: 'keep' | 'remove' | 'extend' | 'switch' | 'move' | 'add', entry, reason, claim }.
|
|
279
342
|
// finalCapable mirrors the run-gates --final acceptance shape: the canonical review-state check
|
|
280
343
|
// must be PRESENT (the checker itself is guaranteed last by the plan) — missing means the result
|
|
281
344
|
// is NOT final-run-capable and the preview says so loudly with the paste-ready candidate. An
|
|
282
345
|
// EXTERNAL-COPY core check withholds that claim too: the runner anchors on the installed copy.
|
|
283
|
-
|
|
346
|
+
// Every row but the checker add is a mechanical move; the add joins the plan only with `addChecker`
|
|
347
|
+
// (the user's yes), else `checkerOffered` says it would.
|
|
348
|
+
export const buildMigrationPlan = (gates, kitToolsDir, projectDir, { addChecker = false } = {}) => {
|
|
284
349
|
if (typeof projectDir !== 'string') {
|
|
285
350
|
throw stop('buildMigrationPlan needs the project root — a declared cmd may name a core check by a RELATIVE path, and only the project root resolves it the way the runner does');
|
|
286
351
|
}
|
|
352
|
+
const kit = planKitCommandGates(gates, projectDir);
|
|
353
|
+
let guard;
|
|
354
|
+
const guardFailure = () => (guard === undefined ? (guard = unitTestsGuardFailure(projectDir, OWN_RUN, { lstatSync, readFileSync })) : guard);
|
|
355
|
+
const guardKept = [];
|
|
287
356
|
const tools = coreCheckTools(kitToolsDir);
|
|
288
357
|
const claimOf = (name, cmd) => classifyCheckerClaim(tools[name], cmd, projectDir);
|
|
289
358
|
const plan = [];
|
|
@@ -296,28 +365,34 @@ export const buildMigrationPlan = (gates, kitToolsDir, projectDir) => {
|
|
|
296
365
|
let unitTestsExtended = false;
|
|
297
366
|
let hasReviewState = false;
|
|
298
367
|
const coverageCmd = `node "${join(kitToolsDir, 'coverage-check.mjs')}" --check`;
|
|
299
|
-
for (const gate of gates) {
|
|
368
|
+
for (const [at, gate] of gates.entries()) {
|
|
300
369
|
const legacy = LEGACY_FORMS.find((f) => f.re.test(gate.cmd.trim()));
|
|
301
370
|
if (legacy) {
|
|
302
|
-
|
|
371
|
+
// Removed only over a target proven absent: anything standing there may be the project's own, so it is CUSTOMIZED.
|
|
372
|
+
if (legacyTargetAbsent(legacy.re, gate.cmd, projectDir)) {
|
|
373
|
+
plan.push({ action: 'remove', entry: gate, reason: `was: ${gate.cmd} — the ${legacy.name} check died with its tool (strip-the-kit), its target absent` });
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
customized.push(gate);
|
|
377
|
+
plan.push({ action: 'keep', entry: gate, reason: null, claim: CHECKER_CLAIM.NOT_THE_TOOL });
|
|
303
378
|
continue;
|
|
304
379
|
}
|
|
305
380
|
const coverageClaim = claimOf('coverage-check', gate.cmd);
|
|
381
|
+
const keep = { action: 'keep', entry: gate, reason: null, claim: coverageClaim };
|
|
306
382
|
if (coverageClaim === CHECKER_CLAIM.CANONICAL) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
plan.push(row);
|
|
383
|
+
checkerRows.push(keep);
|
|
384
|
+
plan.push(keep);
|
|
310
385
|
continue;
|
|
311
386
|
}
|
|
312
387
|
const reviewClaim = claimOf('review-state', gate.cmd);
|
|
313
388
|
if (reviewClaim === CHECKER_CLAIM.CANONICAL) {
|
|
314
389
|
hasReviewState = true;
|
|
315
|
-
plan.push(
|
|
390
|
+
plan.push(keep);
|
|
316
391
|
continue;
|
|
317
392
|
}
|
|
318
393
|
// The third outcome: this IS the tool, from a copy the caller did not name. A vendored
|
|
319
394
|
// deployment declared it deliberately, so it is PRESERVED as written — a plain keep row, never
|
|
320
|
-
// a new action kind (resultingGates carries only keep|extend|move|add and would silently drop
|
|
395
|
+
// a new action kind (resultingGates carries only keep|extend|switch|move|add and would silently drop
|
|
321
396
|
// one) — and it counts as DECLARED, which is what stops the checker being added on top of it
|
|
322
397
|
// and stops its id reading as a squatter. What it does not buy is the final-capability claim:
|
|
323
398
|
// run-gates --final anchors on the installed copy by realpath and would refuse this cmd.
|
|
@@ -325,100 +400,99 @@ export const buildMigrationPlan = (gates, kitToolsDir, projectDir) => {
|
|
|
325
400
|
? 'coverage-check'
|
|
326
401
|
: reviewClaim === CHECKER_CLAIM.ELSEWHERE ? 'review-state' : null;
|
|
327
402
|
if (elsewhereName !== null) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
plan.push(row);
|
|
403
|
+
externalCoreChecks.push({ name: elsewhereName, entry: gate, installed: join(kitToolsDir, `${elsewhereName}.mjs`), row: keep });
|
|
404
|
+
plan.push(keep);
|
|
331
405
|
continue;
|
|
332
406
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
unitTestsExtended
|
|
407
|
+
// An earlier kit's producer form (any id, marked or not, read BEFORE the marker keep) is SWITCHED,
|
|
408
|
+
// and the unit-tests gate's `node --test` EXTENDED, onto the command body: only over a path-shaped
|
|
409
|
+
// tail (a flag there is CUSTOMIZED, never rewritten) and while the guard holds, else kept with the
|
|
410
|
+
// guard's line. So no form is written that the next run reports CUSTOMIZED.
|
|
411
|
+
const retired = retiredProducerFormOf(gate.cmd);
|
|
412
|
+
const unitRest = retired === null && gate.id === 'unit-tests' && !isCoverageProducerGate(gate) ? bodyRest(gate.cmd.trim(), 'node --test') : null;
|
|
413
|
+
const move = retired ?? (unitRest === null ? null : { prefix: '', tail: unitRest, pathShaped: pathShapedTail(unitRest) });
|
|
414
|
+
if (move !== null) {
|
|
415
|
+
if (!move.pathShaped) customized.push(gate);
|
|
416
|
+
else if (guardFailure() !== null) guardKept.push({ id: gate.id, ...guardFailure() });
|
|
417
|
+
else {
|
|
418
|
+
const entry = { ...gate, cmd: `${move.prefix}${COVERAGE_PRODUCER_BODY}${move.tail ? ` ${move.tail}` : ''}` };
|
|
419
|
+
plan.push(retired !== null
|
|
420
|
+
? { action: 'switch', entry, reason: `was: ${gate.cmd} — the unit tests run through the stable kit command`, claim: coverageClaim }
|
|
421
|
+
: { action: 'extend', entry, reason: `was: ${gate.cmd} — the unit-tests cmd runs through the stable kit command, which adds the lcov reporter (the D3(d) coverage source)`, claim: coverageClaim });
|
|
422
|
+
unitTestsExtended ||= retired === null;
|
|
349
423
|
continue;
|
|
350
424
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
425
|
+
plan.push(keep);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (gate.id === 'unit-tests') {
|
|
429
|
+
// Already configured — decided by the CLOSED predicate, never a substring probe — or a declared
|
|
430
|
+
// `lcovProducer` marker: keep. `echo <body>`, a `&& rm -f <lcov>` tail, `npm test` or a wrapper
|
|
431
|
+
// cannot be VERIFIED as a producer: CUSTOMIZED with its recovery, never a silent keep.
|
|
432
|
+
if (!isCoverageProducerGate(gate)) customized.push(gate);
|
|
433
|
+
plan.push(keep);
|
|
355
434
|
continue;
|
|
356
435
|
}
|
|
357
436
|
// A dead-tool reference or a core-check LOOKALIKE in a non-canonical form — reported, never touched.
|
|
358
|
-
|
|
359
|
-
|
|
437
|
+
const deadTool = /review-ledger|fold-completeness|verification-profile|seed-gates|sarif|coverage-check\.mjs|review-state\.mjs/.test(gate.cmd);
|
|
438
|
+
if (deadTool) customized.push(gate);
|
|
439
|
+
if (kit.gates[at] !== gate && !deadTool) {
|
|
440
|
+
plan.push({ action: 'switch', entry: kit.gates[at], reason: `was: ${gate.cmd} — the kit check runs through the stable kit command`, claim: coverageClaim });
|
|
441
|
+
continue;
|
|
360
442
|
}
|
|
361
|
-
plan.push(
|
|
443
|
+
plan.push(keep);
|
|
362
444
|
}
|
|
363
|
-
|
|
445
|
+
// A gate the kit reading would switch but the rules above keep untouched is named with its repoint instead.
|
|
446
|
+
const switchedEntries = new Set(plan.filter((r) => r.action === 'switch').map((r) => r.entry));
|
|
447
|
+
const repoints = [...kit.repoints, ...gates.flatMap((gate, at) => (kit.gates[at] !== gate && !switchedEntries.has(kit.gates[at]) ? repointsOf(gate) : []))];
|
|
448
|
+
const kept = plan.filter((r) => r.action === 'keep' || r.action === 'extend' || r.action === 'switch');
|
|
364
449
|
const checkerRow = checkerRows[checkerRows.length - 1] ?? null;
|
|
365
450
|
const externalCoverageChecks = externalCoreChecks.filter((c) => c.name === 'coverage-check');
|
|
366
451
|
// The checker READS an lcov; something has to WRITE it FIRST. Adding the checker over a
|
|
367
|
-
// declaration with no producer creates the dead pair
|
|
368
|
-
//
|
|
369
|
-
//
|
|
370
|
-
//
|
|
371
|
-
|
|
372
|
-
// the lcov it reads, so a marker on a DUPLICATE checker must not read as the producer for the
|
|
373
|
-
// other one; that pair would claim final-capability while nothing wrote the file. A VENDORED
|
|
374
|
-
// checker is excluded for the identical reason: which copy runs changes nothing about the fact
|
|
375
|
-
// that a checker consumes the lcov rather than writing it.
|
|
376
|
-
const consumerRows = new Set([...checkerRows, ...externalCoverageChecks.map((c) => c.row)]);
|
|
377
|
-
const isProducerRow = (row) => !consumerRows.has(row) && isCoverageProducerGate(row.entry);
|
|
452
|
+
// declaration with no producer creates the dead pair, so the migration withholds it and says why.
|
|
453
|
+
// A row is a producer through the ONE question both hosts ask (readsAsCoverageProducer): a row
|
|
454
|
+
// claiming the coverage checker, the canonical copy or a vendored one, consumes the lcov rather
|
|
455
|
+
// than writing it, so its marker never pairs it with itself or with a duplicate.
|
|
456
|
+
const isProducerRow = (row) => readsAsCoverageProducer(row.entry, row.claim);
|
|
378
457
|
const hasProducer = kept.some(isProducerRow);
|
|
379
458
|
let collision = null;
|
|
380
459
|
let checkerWithheld = false;
|
|
460
|
+
let checkerOffered = false;
|
|
381
461
|
if (checkerRow !== null) {
|
|
382
462
|
if (kept[kept.length - 1] !== checkerRow) {
|
|
383
463
|
checkerRow.action = 'move';
|
|
384
|
-
checkerRow.reason = 'the canonical checker must be the LAST declared gate (nothing may run after it consumed the lcov)
|
|
464
|
+
checkerRow.reason = `was: before ${kept.slice(kept.indexOf(checkerRow) + 1).map((r) => r.entry.id).join(', ')} — the canonical checker must be the LAST declared gate (nothing may run after it consumed the lcov)`;
|
|
385
465
|
}
|
|
386
466
|
} else if (externalCoverageChecks.length > 0) {
|
|
387
467
|
// The checker IS declared, from another copy. Adding the canonical one beside it would create
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
// collides; the verify warning below carries what the maintainer has to decide.
|
|
468
|
+
// a duplicate — and rewriting the row the deployment chose is not this tool's call. Nothing is
|
|
469
|
+
// added, nothing is moved; the verify lines below carry what the maintainer has to decide.
|
|
391
470
|
} else if (kept.some((r) => r.entry.id === 'coverage-check')) {
|
|
392
|
-
// A surviving
|
|
393
|
-
// `coverage-check` rows would be ambiguous
|
|
394
|
-
// FIRST (the caller turns this into a loud STOP on preview and apply alike).
|
|
471
|
+
// A surviving row other than a checker holding the checker's id withholds only the add — two
|
|
472
|
+
// `coverage-check` rows would be ambiguous — and stops no mechanical row.
|
|
395
473
|
collision = 'coverage-check';
|
|
396
474
|
} else if (!hasProducer) {
|
|
397
475
|
checkerWithheld = true;
|
|
398
|
-
} else {
|
|
476
|
+
} else if (addChecker) {
|
|
399
477
|
plan.push({
|
|
400
478
|
action: 'add',
|
|
401
479
|
entry: { id: 'coverage-check', title: 'Changed-line coverage + red-proof verification (the final-run checker)', cmd: coverageCmd },
|
|
402
480
|
reason: 'run-gates --final requires the canonical checker as the LAST declared gate',
|
|
403
481
|
});
|
|
482
|
+
} else {
|
|
483
|
+
checkerOffered = true;
|
|
404
484
|
}
|
|
405
485
|
// An ALREADY-declared checker over no producer is the same dead pair the withhold prevents — an
|
|
406
486
|
// earlier deployment could have created it. The migration removes no declared gate, so it reports
|
|
407
|
-
// the
|
|
487
|
+
// the fact and refuses to call the result final-run-capable.
|
|
408
488
|
//
|
|
409
|
-
// The
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
// producer declared AFTER it writes the lcov the checker has already read past, and counting it
|
|
414
|
-
// would report a live pair over one that certifies nothing.
|
|
415
|
-
// Tracked PER ROW, not as one flag: the renderer has to name the edit for the row it is talking
|
|
416
|
-
// about, and a single boolean is what let one preview demand a removal and a reorder at once.
|
|
489
|
+
// The question is POSITIONAL for both checker kinds: a canonical checker always ENDS UP LAST here
|
|
490
|
+
// (moved last), so its producers are every kept row; a VENDORED checker is left where the
|
|
491
|
+
// deployment put it, so a producer declared AFTER it writes the lcov it has already read past.
|
|
492
|
+
// Tracked PER ROW: the renderer names the edit for the row it is talking about.
|
|
417
493
|
const inertExternalRows = new Set(
|
|
418
494
|
externalCoverageChecks.filter(({ row }) => !kept.slice(0, kept.indexOf(row)).some(isProducerRow)).map(({ row }) => row),
|
|
419
495
|
);
|
|
420
|
-
// The canonical checker's ONLY inert cause is that nothing produces at all — it always ends up
|
|
421
|
-
// last — so its sentence never has to speak about order.
|
|
422
496
|
const canonicalCheckerInert = checkerRow !== null && !hasProducer;
|
|
423
497
|
const checkerInert = canonicalCheckerInert || inertExternalRows.size > 0;
|
|
424
498
|
// `--final` accepts EXACTLY ONE canonical checker, so a declaration carrying two is not
|
|
@@ -426,15 +500,17 @@ export const buildMigrationPlan = (gates, kitToolsDir, projectDir) => {
|
|
|
426
500
|
// so it names the duplication and withholds the claim instead of over-promising a green.
|
|
427
501
|
const duplicateCheckers = checkerRows.length;
|
|
428
502
|
const reviewStateCandidate = `{ "id": "review-state", "title": "Review receipts converged (D3(b))", "cmd": "node \\"${join(kitToolsDir, 'review-state.mjs')}\\" --check" }`;
|
|
503
|
+
// finalCapable judges the result with the offered add landed: the offer line carries the one step left.
|
|
429
504
|
return {
|
|
430
505
|
plan,
|
|
431
506
|
customized,
|
|
432
507
|
unitTestsExtended,
|
|
433
508
|
finalCapable:
|
|
434
|
-
hasReviewState && !checkerWithheld && !checkerInert && duplicateCheckers <= 1 && externalCoreChecks.length === 0,
|
|
509
|
+
hasReviewState && !checkerWithheld && collision === null && !checkerInert && duplicateCheckers <= 1 && externalCoreChecks.length === 0,
|
|
435
510
|
hasProducer,
|
|
436
511
|
hasReviewState,
|
|
437
512
|
checkerWithheld,
|
|
513
|
+
checkerOffered,
|
|
438
514
|
checkerInert,
|
|
439
515
|
duplicateCheckers,
|
|
440
516
|
// The plan ROW is an internal handle (the move arm mutates it) — consumers get the facts only.
|
|
@@ -449,13 +525,17 @@ export const buildMigrationPlan = (gates, kitToolsDir, projectDir) => {
|
|
|
449
525
|
inert: inertExternalRows.has(row),
|
|
450
526
|
})),
|
|
451
527
|
canonicalCheckerInert,
|
|
528
|
+
canonicalCheckerId: checkerRow?.entry.id ?? null,
|
|
452
529
|
reviewStateCandidate,
|
|
453
530
|
collision,
|
|
531
|
+
repoints,
|
|
532
|
+
withheld: kit.withheld,
|
|
533
|
+
guardKept,
|
|
454
534
|
};
|
|
455
535
|
};
|
|
456
536
|
|
|
457
537
|
export const resultingGates = (plan) => {
|
|
458
|
-
const kept = plan.filter((r) => r.action === 'keep' || r.action === 'extend').map((r) => r.entry);
|
|
538
|
+
const kept = plan.filter((r) => r.action === 'keep' || r.action === 'extend' || r.action === 'switch').map((r) => r.entry);
|
|
459
539
|
const moved = plan.filter((r) => r.action === 'move').map((r) => r.entry);
|
|
460
540
|
const added = plan.filter((r) => r.action === 'add').map((r) => r.entry);
|
|
461
541
|
return [...kept, ...moved, ...added]; // move/add go LAST — the checker ends up the last declared gate
|
|
@@ -463,16 +543,24 @@ export const resultingGates = (plan) => {
|
|
|
463
543
|
|
|
464
544
|
const MARKER_LANE = 'or, if your suite cmd already writes that lcov in a form this check cannot recognise, add "lcovProducer": true to that gate in docs/ai/gates.json';
|
|
465
545
|
|
|
466
|
-
// The per-entry customized recovery: a unit-tests-class entry
|
|
467
|
-
//
|
|
468
|
-
// dead-tool recovery.
|
|
469
|
-
const customizedRecovery = (gate) =>
|
|
470
|
-
gate.id === 'unit-tests'
|
|
471
|
-
|
|
546
|
+
// The per-entry customized recovery: a unit-tests-class entry — the unit-tests id, or an earlier
|
|
547
|
+
// kit's producer form under any id — gets the command's suite line (the intent is known — the cmd
|
|
548
|
+
// shape just cannot be verified); a legacy check whose target stands gets the hand decision; anything else the dead-tool recovery.
|
|
549
|
+
const customizedRecovery = (gate) => {
|
|
550
|
+
if (gate.id === 'unit-tests' || retiredProducerFormOf(gate.cmd) !== null) {
|
|
551
|
+
return `declare the canonical suite gate by hand so the coverage contract is verifiable: ${SUITE_LINE} — ${MARKER_LANE}`;
|
|
552
|
+
}
|
|
553
|
+
const legacy = LEGACY_FORMS.find((f) => f.re.test(gate.cmd.trim()));
|
|
554
|
+
return legacy
|
|
555
|
+
? `the ${legacy.name} check is retired, but its target is not proven absent (something stands at that path, or its token is one the kit does not resolve) — remove the entry by hand if it runs the retired tool; if it is your own check, move its file to a path that does not contain ${legacy.name} and point the gate at it.`
|
|
472
556
|
: 'remove the entry, or repoint it at a living check — the review-ledger / fold-completeness tools no longer exist.';
|
|
557
|
+
};
|
|
473
558
|
|
|
474
|
-
const warningLines = ({ customized, finalCapable, hasReviewState = finalCapable,
|
|
559
|
+
const warningLines = ({ customized, finalCapable, hasReviewState = finalCapable, checkerWithheld = false, checkerOffered = false, canonicalCheckerInert = false, canonicalCheckerId = 'coverage-check', duplicateCheckers = 0, externalCoreChecks = [], reviewStateCandidate, repoints = [], withheld = [], guardKept = [], collision = null, addCheckerHint = 'this migration with --apply --add-checker' }) => {
|
|
475
560
|
const lines = [];
|
|
561
|
+
for (const kept of guardKept) lines.push(guardLine(kept));
|
|
562
|
+
for (const { id, path } of withheld) lines.push(` WARNING: ${id} runs a kit check, but the kit folder is not current (${path}) — kept as declared; refresh the kit's scripts, then re-run this migration.`);
|
|
563
|
+
for (const { id, repoint } of repoints) lines.push(` REPOINT (untouched): ${id}: run ${repoint} in place of its invocation of that check, its arguments kept.`);
|
|
476
564
|
for (const gate of customized) {
|
|
477
565
|
lines.push(` CUSTOMIZED (untouched): ${gate.id}: ${gate.cmd}`);
|
|
478
566
|
lines.push(` recovery (apply by hand if the intent still stands): ${customizedRecovery(gate)}`);
|
|
@@ -490,33 +578,22 @@ const warningLines = ({ customized, finalCapable, hasReviewState = finalCapable,
|
|
|
490
578
|
? ` the INSTALLED ${name} check is declared here too, so repointing this cmd would leave TWO — run-gates --final accepts exactly ONE canonical check. Remove THIS entry by hand and keep the canonical one.`
|
|
491
579
|
: ` run-gates --final anchors on the installed copy by realpath, so the result is NOT final-run-capable while this entry stands: either repoint the cmd at ${installed}, or upgrade through the kit that owns the copy it names.`,
|
|
492
580
|
);
|
|
493
|
-
// The
|
|
494
|
-
|
|
495
|
-
if (inert && canonicalTwin) {
|
|
496
|
-
lines.push(' it is also INERT as declared — nothing produces the lcov before it — and removing it, as above, is the ONE edit that resolves both.');
|
|
497
|
-
} else if (inert && hasProducer) {
|
|
498
|
-
lines.push(' it is also INERT as declared: a gate DOES produce the lcov, but it runs AFTER this entry, so this checker reads nothing (or stale bytes) and passes while verifying nothing — a checker belongs LAST, after its producer.');
|
|
499
|
-
} else if (inert) {
|
|
500
|
-
lines.push(` it is also INERT as declared: no declared gate PRODUCES the lcov it reads, so it passes while verifying nothing — declare the suite gate: node --test ${UNIT_TESTS_COVERAGE_FLAGS} <your test paths> — ${MARKER_LANE}`);
|
|
501
|
-
}
|
|
581
|
+
// The fact of THIS row, said on THIS row, with its one remedy — the removal above when a canonical twin stands.
|
|
582
|
+
if (inert) lines.push(` it also reads as inert: ${POSITIONAL_FACT} — ${canonicalTwin ? 'removing it, as above, is the one edit' : CHECKER_REMEDY}`);
|
|
502
583
|
}
|
|
503
584
|
if (externalCoreChecks.length) {
|
|
504
585
|
// The same consequence the customized block carries, for the same reason: a declaration --final
|
|
505
586
|
// refuses mints no receipt, and the commit guard then refuses every commit.
|
|
506
587
|
lines.push(' IMPORTANT: do NOT install the commit guard while the entr(ies) above stand — a declaration that cannot pass run-gates --final would block every commit.');
|
|
507
588
|
}
|
|
508
|
-
if (
|
|
509
|
-
lines.push(
|
|
510
|
-
lines.push(` node --test ${UNIT_TESTS_COVERAGE_FLAGS} <your test paths>`);
|
|
511
|
-
lines.push(` ${MARKER_LANE}, then re-run this migration`);
|
|
512
|
-
}
|
|
513
|
-
// The CANONICAL checker's inertness only. An external row's is said on the row itself above, with
|
|
514
|
-
// the edit that fits that row — this block would otherwise add a second, contradictory one.
|
|
515
|
-
if (canonicalCheckerInert) {
|
|
516
|
-
lines.push(' WARNING: the DECLARED coverage-check gate is INERT — no declared gate PRODUCES the lcov it reads, so it passes while verifying nothing. Nothing is removed for you; declare the suite gate:');
|
|
517
|
-
lines.push(` node --test ${UNIT_TESTS_COVERAGE_FLAGS} <your test paths>`);
|
|
518
|
-
lines.push(` ${MARKER_LANE}`);
|
|
589
|
+
if (collision !== null) {
|
|
590
|
+
lines.push(` WARNING: the canonical coverage-check gate was not added — a row that is not the checker already holds the id ${collision}: rename that row by hand.`);
|
|
519
591
|
}
|
|
592
|
+
if (checkerWithheld) lines.push(` WARNING: the canonical coverage-check gate was not added — ${WITHHELD_FACT}; ${CHECKER_REMEDY}`);
|
|
593
|
+
// The coverage check is optional: its add is the one step that waits for the user's explicit yes.
|
|
594
|
+
if (checkerOffered) lines.push(` OFFER coverage-check: a declared gate is a producer this kit reads and no checker is declared — on the user's explicit yes, add the canonical checker last: ${addCheckerHint}`);
|
|
595
|
+
// The CANONICAL checker's fact only; an external row's is said on the row itself above.
|
|
596
|
+
if (canonicalCheckerInert) lines.push(` WARNING: the declared coverage checker (${canonicalCheckerId}): ${POSITIONAL_FACT} — ${CHECKER_REMEDY}`);
|
|
520
597
|
if (duplicateCheckers > 1) {
|
|
521
598
|
lines.push(` WARNING: ${duplicateCheckers} declared gates are the canonical coverage checker — run-gates --final accepts EXACTLY ONE, so the result is NOT final-run-capable. Nothing is removed for you; keep a single checker and delete the rest by hand.`);
|
|
522
599
|
}
|
|
@@ -530,27 +607,28 @@ const warningLines = ({ customized, finalCapable, hasReviewState = finalCapable,
|
|
|
530
607
|
return lines;
|
|
531
608
|
};
|
|
532
609
|
|
|
610
|
+
// Each acted row, printed alike by the preview and the apply: its action, id, cmd and its reason (a moved or removed gate's `was:`).
|
|
611
|
+
const actedLines = (plan) => plan.filter((r) => r.action !== 'keep').map((r) => ` ${r.action.toUpperCase()} ${r.entry.id}: ${r.entry.cmd} (${r.reason})`);
|
|
612
|
+
|
|
533
613
|
export const formatPreview = (analysis, applyHint) => {
|
|
534
|
-
const { plan, unitTestsExtended, finalCapable, hasProducer = unitTestsExtended, retiredStores = [] } = analysis;
|
|
614
|
+
const { plan, unitTestsExtended, finalCapable, checkerOffered = false, hasProducer = unitTestsExtended, retiredStores = [] } = analysis;
|
|
535
615
|
const lines = ['[agent-workflow] legacy gates.json migration preview (dry-run — nothing was written):'];
|
|
536
|
-
const acted = plan
|
|
537
|
-
|
|
538
|
-
lines.push(` ${r.action.toUpperCase()} ${r.entry.id}: ${r.entry.cmd} (${r.reason})`);
|
|
539
|
-
}
|
|
616
|
+
const acted = actedLines(plan);
|
|
617
|
+
lines.push(...acted);
|
|
540
618
|
for (const p of retiredStores) {
|
|
541
619
|
lines.push(` CLEAN ${p} (a retired kit-owned store the deleted machinery wrote — dead data, unlinked on apply)`);
|
|
542
620
|
}
|
|
543
621
|
if (!acted.length && !retiredStores.length) {
|
|
544
622
|
lines.push(
|
|
545
|
-
finalCapable
|
|
623
|
+
finalCapable && !checkerOffered
|
|
546
624
|
? ' nothing to migrate — no canonical legacy entries, no retired stores, and the declaration is already final-run-capable.'
|
|
547
|
-
: ' nothing to migrate mechanically — no canonical legacy entries and no retired stores; the
|
|
625
|
+
: ' nothing to migrate mechanically — no canonical legacy entries and no retired stores; the lines below still need a hand.',
|
|
548
626
|
);
|
|
549
627
|
}
|
|
550
628
|
// Keyed on the ID, but a PRODUCER is recognized under any id — repeating this advice over a
|
|
551
629
|
// working producer sends the user to fix nothing.
|
|
552
630
|
if (!hasProducer && !unitTestsExtended && !plan.some((r) => r.entry.id === 'unit-tests')) {
|
|
553
|
-
lines.push(
|
|
631
|
+
lines.push(` note: no canonical \`unit-tests\` entry found — declare your suite gate by hand as ${SUITE_LINE} (the coverage-check gate reads the lcov it produces).`);
|
|
554
632
|
}
|
|
555
633
|
lines.push(...warningLines(analysis));
|
|
556
634
|
if (acted.length || retiredStores.length) {
|
|
@@ -622,11 +700,12 @@ const writeAtomic = (cwd, body, lstatFn) => {
|
|
|
622
700
|
};
|
|
623
701
|
|
|
624
702
|
export const parseArgs = (argv) => {
|
|
625
|
-
const args = { cwd: process.cwd(), apply: false, kitTools: null, help: false };
|
|
703
|
+
const args = { cwd: process.cwd(), apply: false, addChecker: false, kitTools: null, help: false };
|
|
626
704
|
for (let i = 0; i < argv.length; i += 1) {
|
|
627
705
|
const a = argv[i];
|
|
628
706
|
if (a === '--help' || a === '-h') args.help = true;
|
|
629
707
|
else if (a === '--apply') args.apply = true;
|
|
708
|
+
else if (a === '--add-checker') args.addChecker = true;
|
|
630
709
|
else if (a === '--dry-run') args.apply = false;
|
|
631
710
|
else if (a === '--cwd') {
|
|
632
711
|
i += 1;
|
|
@@ -641,18 +720,23 @@ export const parseArgs = (argv) => {
|
|
|
641
720
|
return args;
|
|
642
721
|
};
|
|
643
722
|
|
|
644
|
-
const HELP = `migrate-gates — the
|
|
723
|
+
const HELP = `migrate-gates — the legacy gates.json migration (strip-the-kit D8), the kit's mandatory move.
|
|
645
724
|
|
|
646
725
|
Usage:
|
|
647
|
-
node migrate-gates.mjs --kit-tools <installed-kit-tools-dir> [--cwd <project>] [--apply]
|
|
648
|
-
|
|
649
|
-
Default is a dry-run PREVIEW (writes nothing). --apply rewrites ${GATES_REL}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
726
|
+
node migrate-gates.mjs --kit-tools <installed-kit-tools-dir> [--cwd <project>] [--apply [--add-checker]]
|
|
727
|
+
|
|
728
|
+
Default is a dry-run PREVIEW (writes nothing, --add-checker included). --apply rewrites ${GATES_REL}
|
|
729
|
+
atomically with every mechanical row, the upgrade's gates-migration step running it with no question:
|
|
730
|
+
a canonical legacy entry (review-ledger / fold-completeness --check, matched by its documented
|
|
731
|
+
single-invocation form) is REMOVED when its target is proven absent; the canonical unit-tests cmd and
|
|
732
|
+
every earlier kit's producer form run through ${COVERAGE_PRODUCER_BODY} (while the kit folder holds this
|
|
733
|
+
kit's command and reporter); a kit-check gate over a current kit folder is SWITCHED in place to
|
|
734
|
+
node scripts/agent-workflow/run.mjs <name>, unless it is a customized entry below, a flat scripts/<file>
|
|
735
|
+
only when nothing stands at that path; any other form naming a kit check is kept, named with its repoint;
|
|
736
|
+
a declared coverage-check gate is moved last. The coverage-check gate is ADDED last (resolved, QUOTED path)
|
|
737
|
+
only with --add-checker, on the user's explicit yes, and only when a declared gate produces the lcov it
|
|
738
|
+
reads. Customized entries are NEVER auto-touched — each is named with a paste-ready recovery, and the
|
|
739
|
+
commit guard must not be installed until they are resolved.`;
|
|
656
740
|
|
|
657
741
|
export const main = (argv = process.argv.slice(2), io = {}) => {
|
|
658
742
|
const out = io.log ?? console.log;
|
|
@@ -682,14 +766,10 @@ export const main = (argv = process.argv.slice(2), io = {}) => {
|
|
|
682
766
|
return 0;
|
|
683
767
|
}
|
|
684
768
|
const parsed = declaration.outcome === 'loaded' ? declaration.parsed : { gates: [] };
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
'(two rows under the checker id would be ambiguous — the canonical checker is never added alongside a customized twin)',
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
const applyHint = `node "${fileURLToPath(import.meta.url)}" --kit-tools "${kitTools}" --cwd "${args.cwd}" --apply`;
|
|
769
|
+
const command = `node "${fileURLToPath(import.meta.url)}" --kit-tools "${kitTools}" --cwd "${args.cwd}"`;
|
|
770
|
+
const addCheckerHint = `${command} --apply --add-checker`;
|
|
771
|
+
const analysis = { ...buildMigrationPlan(parsed.gates, kitTools, resolve(args.cwd), { addChecker: args.addChecker }), retiredStores, addCheckerHint };
|
|
772
|
+
const applyHint = args.addChecker ? addCheckerHint : `${command} --apply`;
|
|
693
773
|
if (!args.apply) {
|
|
694
774
|
out(formatPreview(analysis, applyHint));
|
|
695
775
|
return 0;
|
|
@@ -698,6 +778,7 @@ export const main = (argv = process.argv.slice(2), io = {}) => {
|
|
|
698
778
|
if (acted.length && declaration.outcome === 'loaded') {
|
|
699
779
|
const merged = { ...parsed, gates: resultingGates(analysis.plan) };
|
|
700
780
|
const writtenPath = writeAtomic(args.cwd, `${JSON.stringify(merged, null, 2)}\n`, lstatFn);
|
|
781
|
+
for (const line of actedLines(analysis.plan)) out(line);
|
|
701
782
|
out(`[agent-workflow] migrated ${writtenPath}: ${acted.map((r) => `${r.action} ${r.entry.id}`).join(', ')}`);
|
|
702
783
|
}
|
|
703
784
|
for (const p of retiredStores) {
|
|
@@ -712,9 +793,9 @@ export const main = (argv = process.argv.slice(2), io = {}) => {
|
|
|
712
793
|
for (const line of warningLines(analysis)) out(line);
|
|
713
794
|
if (!acted.length && !retiredStores.length) {
|
|
714
795
|
out(
|
|
715
|
-
analysis.finalCapable
|
|
796
|
+
analysis.finalCapable && !analysis.checkerOffered
|
|
716
797
|
? '[agent-workflow] nothing to migrate — the declaration is already final-run-capable and no retired stores remain.'
|
|
717
|
-
: '[agent-workflow] nothing to migrate mechanically — no canonical legacy entries and no retired stores remain; the
|
|
798
|
+
: '[agent-workflow] nothing to migrate mechanically — no canonical legacy entries and no retired stores remain; the lines above still need a hand.',
|
|
718
799
|
);
|
|
719
800
|
}
|
|
720
801
|
return 0;
|