@sabaiway/agent-workflow-kit 21.0.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 +46 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/migrations/3.0.0-hardened-core-loop.md +7 -6
- package/package.json +1 -1
- package/references/advisor-writers.md +1 -1
- package/references/contracts.md +2 -1
- package/references/modes/gates.md +2 -2
- package/references/modes/recommendations.md +1 -1
- package/references/modes/upgrade.md +5 -5
- package/references/scripts/family.json +2 -0
- package/references/scripts/family.mjs +2 -2
- package/references/scripts/gates/migrate-gates.mjs +240 -176
- package/references/scripts/run.mjs +26 -10
- package/references/scripts/test-reporter/reporter.mjs +130 -0
- package/tools/coverage-producer.mjs +76 -41
- package/tools/distribution-files/scripts.mjs +5 -4
- package/tools/ensure-configs.mjs +2 -2
- package/tools/ensure-specs.mjs +11 -8
- package/tools/gates-declaration.mjs +22 -14
- package/tools/gates-init.mjs +33 -17
- package/tools/recommendations.mjs +15 -6
- package/tools/upgrade-runlist.mjs +3 -3
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// run.mjs — the stable kit command (spec kit-command): `node scripts/agent-workflow/run.mjs <name> [arguments...]`
|
|
3
|
-
// runs the named kit check with every argument unchanged
|
|
3
|
+
// runs the named kit check with every argument unchanged, and `unit-tests` runs the Node test runner with the lcov
|
|
4
|
+
// reporter and the kit test reporter. The names are frozen; the files behind them are the kit's.
|
|
4
5
|
// Dependency-free, Node >= 22. No side effects on import.
|
|
5
6
|
|
|
6
7
|
import { realpathSync, statSync } from 'node:fs';
|
|
7
8
|
import { dirname, join } from 'node:path';
|
|
8
|
-
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
9
10
|
import { spawnSync } from 'node:child_process';
|
|
10
11
|
|
|
11
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -19,17 +20,25 @@ export const KIT_COMMANDS = Object.freeze({
|
|
|
19
20
|
'archive-decisions': 'archives/archive-decisions.mjs',
|
|
20
21
|
'install-git-hooks': 'git-hooks/install-git-hooks.mjs',
|
|
21
22
|
});
|
|
23
|
+
export const UNIT_TESTS_NAME = 'unit-tests';
|
|
24
|
+
export const UNIT_TESTS_REPORTER = 'test-reporter/reporter.mjs';
|
|
22
25
|
|
|
23
|
-
const NAMES = Object.keys(KIT_COMMANDS);
|
|
26
|
+
const NAMES = [...Object.keys(KIT_COMMANDS), UNIT_TESTS_NAME];
|
|
24
27
|
const PREFIX = '[run]';
|
|
25
28
|
const USAGE = `Usage: node ${KIT_COMMAND_PATH} <name> [arguments...]
|
|
26
|
-
Runs the named kit check with every argument after the name, unchanged
|
|
29
|
+
Runs the named kit check with every argument after the name, unchanged; ${UNIT_TESTS_NAME} runs the Node test runner
|
|
30
|
+
with the lcov reporter and the kit test reporter over the arguments. Names: ${NAMES.join(', ')}.
|
|
27
31
|
`;
|
|
28
32
|
|
|
29
33
|
const isRegularFile = (path) => statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
30
34
|
|
|
35
|
+
// The runner's flags for unit-tests: the lcov under the git dir run-gates exports, the kit reporter on stdout.
|
|
36
|
+
const unitTestsFlags = (gitDir, reporter) => ['--test', '--experimental-test-coverage', '--test-reporter=lcov',
|
|
37
|
+
`--test-reporter-destination=${gitDir}/agent-workflow-lcov.info`, `--test-reporter=${pathToFileURL(reporter).href}`,
|
|
38
|
+
'--test-reporter-destination=stdout'];
|
|
39
|
+
|
|
31
40
|
export const main = (argv = process.argv.slice(2), deps = {}) => {
|
|
32
|
-
const { spawn = spawnSync, isFile = isRegularFile, stdout = process.stdout, stderr = process.stderr } = deps;
|
|
41
|
+
const { spawn = spawnSync, isFile = isRegularFile, stdout = process.stdout, stderr = process.stderr, env = process.env } = deps;
|
|
33
42
|
const [name, ...args] = argv;
|
|
34
43
|
if (name === undefined) {
|
|
35
44
|
stderr.write(USAGE);
|
|
@@ -39,23 +48,30 @@ export const main = (argv = process.argv.slice(2), deps = {}) => {
|
|
|
39
48
|
stdout.write(USAGE);
|
|
40
49
|
return 0;
|
|
41
50
|
}
|
|
42
|
-
|
|
51
|
+
const unitTests = name === UNIT_TESTS_NAME;
|
|
52
|
+
if (!unitTests && !Object.hasOwn(KIT_COMMANDS, name)) {
|
|
43
53
|
stderr.write(`${PREFIX} unknown name ${JSON.stringify(name)} — the known names are ${NAMES.join(', ')}\n`);
|
|
44
54
|
return 2;
|
|
45
55
|
}
|
|
46
|
-
const target = KIT_COMMANDS[name];
|
|
56
|
+
const target = unitTests ? UNIT_TESTS_REPORTER : KIT_COMMANDS[name];
|
|
47
57
|
const file = join(HERE, ...target.split('/'));
|
|
48
58
|
if (!isFile(file)) {
|
|
49
59
|
stderr.write(`${PREFIX} ${name}: scripts/agent-workflow/${target} is not a file of this deployment\n`);
|
|
50
60
|
return 1;
|
|
51
61
|
}
|
|
52
|
-
|
|
62
|
+
if (unitTests && !env.AW_GIT_DIR) {
|
|
63
|
+
stderr.write(`${PREFIX} ${name}: AW_GIT_DIR is unset or empty — run-gates exports it; the lcov has no destination\n`);
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
const runArgs = unitTests ? [...unitTestsFlags(env.AW_GIT_DIR, file), ...args] : [file, ...args];
|
|
67
|
+
const result = spawn(process.execPath, runArgs, { stdio: 'inherit' });
|
|
68
|
+
const what = unitTests ? 'the test runner' : 'the check';
|
|
53
69
|
if (result.error) {
|
|
54
|
-
stderr.write(`${PREFIX} ${name}: cannot run
|
|
70
|
+
stderr.write(`${PREFIX} ${name}: cannot run ${what} (${result.error.message})\n`);
|
|
55
71
|
return 1;
|
|
56
72
|
}
|
|
57
73
|
if (result.signal) {
|
|
58
|
-
stderr.write(`${PREFIX} ${name}:
|
|
74
|
+
stderr.write(`${PREFIX} ${name}: ${what} was killed by ${result.signal}\n`);
|
|
59
75
|
return 1;
|
|
60
76
|
}
|
|
61
77
|
return result.status ?? 1;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// reporter.mjs — the kit test reporter (spec test-reporter): a `node --test --test-reporter=<this file>`
|
|
2
|
+
// run prints each failing test's block and one totals line, read from the runner's own events, never its text.
|
|
3
|
+
//
|
|
4
|
+
// The default export alone: an async generator over the runner's event stream that yields text. Each event is
|
|
5
|
+
// rendered under its own guard and the totals line always closes the output, so the reporter never throws and
|
|
6
|
+
// never ends the run; it sets no exit code. Dependency-free, Node >= 22. No side effects on import.
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { inspect } from 'node:util';
|
|
12
|
+
|
|
13
|
+
const QUIET_FAILURES = new Set(['subtestsFailed', 'cancelledByParent']);
|
|
14
|
+
const TOTAL_KEYS = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo'];
|
|
15
|
+
const CLOSING_KEYS = new Set([...TOTAL_KEYS, 'suites', 'duration_ms']);
|
|
16
|
+
const ERROR_HEAD = /^[A-Za-z_$][\w$]*(?: \[[\w$]+\])?: /;
|
|
17
|
+
const FRAME = /^\s*at (?:.*?\()?(.+?):(\d+):(\d+)\)?$/;
|
|
18
|
+
const VALUE_CAP = 500;
|
|
19
|
+
|
|
20
|
+
const isObject = (value) => typeof value === 'object' && value !== null;
|
|
21
|
+
const firstLine = (value) => String(value ?? '').split('\n')[0];
|
|
22
|
+
const toPath = (file) => (String(file).startsWith('file:') ? fileURLToPath(String(file)) : String(file));
|
|
23
|
+
const absolute = (file) => resolve(toPath(file ?? ''));
|
|
24
|
+
const shown = (file) => (file === undefined || file === null ? '?' : relative(process.cwd(), absolute(file)));
|
|
25
|
+
|
|
26
|
+
// An error's first line, or its fallback when the error's own cannot be read.
|
|
27
|
+
const errorLine = (error) => {
|
|
28
|
+
try {
|
|
29
|
+
return firstLine(isObject(error) ? error.message ?? String(error) : error);
|
|
30
|
+
} catch {
|
|
31
|
+
return 'an unreadable error';
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// One line by util.inspect, cut at the cap with an ellipsis.
|
|
36
|
+
const show = (value) => {
|
|
37
|
+
const text = inspect(value, { breakLength: Infinity }).replace(/\n\s*/g, ' ');
|
|
38
|
+
return text.length > VALUE_CAP ? `${text.slice(0, VALUE_CAP)}…` : text;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// The first frame inside the working directory and under no node_modules, with its source text when readable.
|
|
42
|
+
const codeLine = (stack) => {
|
|
43
|
+
for (const frame of String(stack ?? '').split('\n')) {
|
|
44
|
+
const match = FRAME.exec(frame);
|
|
45
|
+
if (!match || !(match[1].startsWith('file:') || isAbsolute(match[1]))) continue;
|
|
46
|
+
const file = absolute(match[1]);
|
|
47
|
+
const inside = relative(process.cwd(), file);
|
|
48
|
+
if (!inside || isAbsolute(inside) || inside.split(sep).some((part) => part === '..' || part === 'node_modules')) continue;
|
|
49
|
+
let text = '';
|
|
50
|
+
try {
|
|
51
|
+
text = readFileSync(file, 'utf8').split(/\r?\n/)[Number(match[2]) - 1]?.trim() ?? '';
|
|
52
|
+
} catch { /* the location alone */ }
|
|
53
|
+
return ` at ${inside}:${match[2]}:${match[3]}${text ? ` ${text}` : ''}`;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// The error-head line of a file's standard error, else its first non-blank line.
|
|
59
|
+
const stderrLine = (chunks) => {
|
|
60
|
+
const lines = chunks.join('').split('\n').map((line) => line.trim()).filter(Boolean);
|
|
61
|
+
return lines.find((line) => ERROR_HEAD.test(line) && !line.startsWith('at ')) ?? lines[0];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const renderFailure = (data, names, stderr) => {
|
|
65
|
+
const error = data.details?.error;
|
|
66
|
+
const cause = error?.cause ?? error;
|
|
67
|
+
const path = [...Array.from({ length: data.nesting ?? 0 }, (_, at) => names[at] ?? '?'), data.name].join(' > ');
|
|
68
|
+
const klass = isObject(cause) && typeof cause.name === 'string' && cause.name ? `${cause.name}: ` : '';
|
|
69
|
+
const lines = [`FAIL ${shown(data.file)}:${data.line ?? '?'} ${path}`, ` ${error?.failureType ?? '?'}: ${klass}${firstLine(isObject(cause) ? cause.message : cause)}`];
|
|
70
|
+
if (isObject(cause) && Object.hasOwn(cause, 'expected') && Object.hasOwn(cause, 'actual')) {
|
|
71
|
+
lines.push(` expected: ${show(cause.expected)}`, ` actual: ${show(cause.actual)}`);
|
|
72
|
+
}
|
|
73
|
+
const at = isObject(cause) ? codeLine(cause.stack) : null;
|
|
74
|
+
if (at) lines.push(at);
|
|
75
|
+
const fileLevel = (data.nesting ?? 0) === 0 && typeof data.name === 'string' && absolute(data.name) === absolute(data.file);
|
|
76
|
+
const line = fileLevel && stderr ? stderrLine(stderr) : undefined;
|
|
77
|
+
if (line) lines.push(` stderr: ${line}`);
|
|
78
|
+
return `${lines.join('\n')}\n`;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default async function* testReporter(source) {
|
|
82
|
+
const names = new Map();
|
|
83
|
+
const stderr = new Map();
|
|
84
|
+
const totals = {};
|
|
85
|
+
const kept = [];
|
|
86
|
+
let green = null;
|
|
87
|
+
let failed = false;
|
|
88
|
+
const read = (event) => {
|
|
89
|
+
const { type, data } = event ?? {};
|
|
90
|
+
if (type === 'test:start') {
|
|
91
|
+
const key = absolute(data.file);
|
|
92
|
+
names.set(key, names.get(key) ?? []).get(key)[data.nesting] = data.name;
|
|
93
|
+
} else if (type === 'test:stderr') {
|
|
94
|
+
const key = absolute(data.file);
|
|
95
|
+
stderr.set(key, stderr.get(key) ?? []).get(key).push(String(data.message ?? ''));
|
|
96
|
+
} else if (type === 'test:summary') {
|
|
97
|
+
if (data.file === undefined) green = data.success === true;
|
|
98
|
+
} else if (type === 'test:diagnostic') {
|
|
99
|
+
const [key, value] = String(data.message ?? '').split(' ');
|
|
100
|
+
if (data.file === undefined && CLOSING_KEYS.has(key)) {
|
|
101
|
+
if (TOTAL_KEYS.includes(key)) totals[key] = value;
|
|
102
|
+
} else {
|
|
103
|
+
kept.push(`diagnostic: ${firstLine(data.message)}\n`);
|
|
104
|
+
}
|
|
105
|
+
} else if (type === 'test:fail' && !data.todo && !data.skip && !QUIET_FAILURES.has(data.details?.error?.failureType)) {
|
|
106
|
+
failed = true;
|
|
107
|
+
return renderFailure(data, names.get(absolute(data.file)) ?? [], stderr.get(absolute(data.file)));
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
};
|
|
111
|
+
try {
|
|
112
|
+
for await (const event of source) {
|
|
113
|
+
let text;
|
|
114
|
+
try {
|
|
115
|
+
text = read(event);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
text = `reporter: an event could not be rendered (${errorLine(error)})\n`;
|
|
118
|
+
}
|
|
119
|
+
if (text) yield text;
|
|
120
|
+
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
yield `reporter: the event stream ended with an error (${errorLine(error)})\n`;
|
|
123
|
+
}
|
|
124
|
+
const red = green === null ? Number(totals.fail) > 0 || Number(totals.cancelled) > 0 : !green;
|
|
125
|
+
if (red) {
|
|
126
|
+
yield* kept;
|
|
127
|
+
if (!failed && kept.length === 0) yield 'reporter: the run failed and no test reported a failure\n';
|
|
128
|
+
}
|
|
129
|
+
yield `${TOTAL_KEYS.map((key) => `${key} ${totals[key] ?? '?'}`).join(' · ')}\n`;
|
|
130
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// coverage-producer.mjs — the kit's half of the shared coverage-producer vocabulary
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// coverage-producer.mjs — the kit's half of the shared coverage-producer vocabulary (spec
|
|
2
|
+
// coverage-producer): the one command body the suite gate runs, the move list of the flag sets
|
|
3
|
+
// earlier kits wrote, and the CLOSED predicate deciding whether a declared gate cmd actually WRITES
|
|
4
|
+
// the lcov the canonical checker reads. A LEAF — imports nothing, so every consumer (gates-init,
|
|
5
|
+
// gates-declaration, the advisor) decides through ONE predicate.
|
|
5
6
|
// Dependency-free, Node >= 22. No side effects on import.
|
|
6
7
|
|
|
7
8
|
// coverage-producer canon >>> BEGIN drift-guarded region
|
|
@@ -11,31 +12,17 @@
|
|
|
11
12
|
// bytes — so a TEXT drift guard beside the root's copy holds them equal. Edit BOTH, then re-run the
|
|
12
13
|
// mirror sync.
|
|
13
14
|
//
|
|
14
|
-
// The
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
// PASTE-READY, and the required-parameter form makes bash refuse BY NAME when AW_GIT_DIR is unset
|
|
18
|
-
// or EMPTY, where a bare `$AW_GIT_DIR` expanded to empty and wrote the lcov to the filesystem ROOT.
|
|
19
|
-
// Residual, stated: `:?` says nothing about the value's ORIGIN — a STALE exported AW_GIT_DIR
|
|
20
|
-
// expands fine and the lcov lands under it; only the runner's own injection makes it the right dir.
|
|
21
|
-
// The explicit stdout reporter keeps the human stream: without it the lcov reporter swallows the
|
|
22
|
-
// TAP/spec output.
|
|
23
|
-
export const UNIT_TESTS_COVERAGE_FLAGS =
|
|
24
|
-
'--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';
|
|
15
|
+
// The ONE producer form the kit writes: the stable kit command's unit-tests name (spec kit-command) —
|
|
16
|
+
// the Node test runner with the lcov reporter under AW_GIT_DIR and the kit test reporter on stdout.
|
|
17
|
+
export const COVERAGE_PRODUCER_BODY = 'node scripts/agent-workflow/run.mjs unit-tests';
|
|
25
18
|
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const KNOWN_COVERAGE_FLAG_SETS = Object.freeze([
|
|
31
|
-
UNIT_TESTS_COVERAGE_FLAGS,
|
|
19
|
+
// The reporter flag sets earlier kits wrote after `node --test`, newest first, byte for byte: a MOVE
|
|
20
|
+
// LIST the gate migration switches onto the body above, never read as a producer.
|
|
21
|
+
export const RETIRED_COVERAGE_FLAG_SETS = Object.freeze([
|
|
22
|
+
'--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',
|
|
32
23
|
'--experimental-test-coverage --test-reporter=lcov --test-reporter-destination="$AW_GIT_DIR/agent-workflow-lcov.info" --test-reporter=spec --test-reporter-destination=stdout',
|
|
33
24
|
]);
|
|
34
|
-
|
|
35
|
-
// The ONE suite body that produces that lcov with no extra dependency (the EMITTED form), beside
|
|
36
|
-
// the closed set of bodies recognition accepts.
|
|
37
|
-
export const COVERAGE_PRODUCER_BODY = `node --test ${UNIT_TESTS_COVERAGE_FLAGS}`;
|
|
38
|
-
const KNOWN_PRODUCER_BODIES = Object.freeze(KNOWN_COVERAGE_FLAG_SETS.map((flags) => `node --test ${flags}`));
|
|
25
|
+
const RETIRED_BODIES = Object.freeze(RETIRED_COVERAGE_FLAG_SETS.map((flags) => `node --test ${flags}`));
|
|
39
26
|
|
|
40
27
|
// The per-PM exec wrappers a fill offer puts that body behind. Recognition must cover every form
|
|
41
28
|
// the kit has EMITTED, so the prefixes are matched literally; gates-init's execCmdFor stays the one
|
|
@@ -48,11 +35,11 @@ const PRODUCER_EXEC_PREFIXES = Object.freeze([
|
|
|
48
35
|
|
|
49
36
|
// A trailing suffix is the project's own test paths; a leading one would mean the body is not what
|
|
50
37
|
// this cmd runs. The tail passes a POSITIVE closed grammar — every whitespace-separated token must
|
|
51
|
-
// be path-shaped — never an operator blocklist:
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
38
|
+
// be path-shaped — never an operator blocklist: `<body> && rm -f <lcov>` runs the suite and then
|
|
39
|
+
// DELETES the file, so an open-ended tail would certify a producer that leaves nothing behind, and
|
|
40
|
+
// scanning for operator BYTES would put the incomplete-scan failure on the unsafe side (a missed
|
|
41
|
+
// operator is a dead pair) instead of the mild one (an unrecognised legitimate tail merely
|
|
42
|
+
// withholds the offer — add the gate by hand). No flag either: the command hands it to the runner.
|
|
56
43
|
// The token set is everything that appears in a PATH or a glob and can never sequence, redirect or
|
|
57
44
|
// substitute a command — quoting and `~` included, `( ) $ ` ; & | < > # \` excluded. SCOPE, stated
|
|
58
45
|
// exactly: the screen judges each token's SOURCE bytes. Quote removal adds none, but brace SEQUENCE
|
|
@@ -67,21 +54,64 @@ const PRODUCER_EXEC_PREFIXES = Object.freeze([
|
|
|
67
54
|
// `skipped-no-lcov`.
|
|
68
55
|
const PRODUCER_PATH_TOKEN = /^(?!-)[A-Za-z0-9_./*{},:@+=~?[\]!'"-]+$/;
|
|
69
56
|
const pathShapedTail = (tail) => tail === '' || tail.split(/[ \t]+/).every((token) => PRODUCER_PATH_TOKEN.test(token));
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
);
|
|
57
|
+
|
|
58
|
+
// The exec prefix the trimmed text opens with ('' for none), and the rest after it.
|
|
59
|
+
const splitExecPrefix = (text) => {
|
|
60
|
+
const prefix = PRODUCER_EXEC_PREFIXES.find((p) => text.startsWith(p)) ?? '';
|
|
61
|
+
return [prefix, text.slice(prefix.length)];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// The rest after `body` (trimmed; '' when nothing follows), or null unless the text is the body, then nothing or one space.
|
|
65
|
+
const bodyRest = (text, body) => {
|
|
66
|
+
if (text === body) return '';
|
|
67
|
+
return text.startsWith(`${body} `) ? text.slice(body.length).trim() : null;
|
|
68
|
+
};
|
|
74
69
|
|
|
75
70
|
// matchesCoverageProducer(cmd) → CLOSED-WORLD over the full command forms the kit emits, never a
|
|
76
|
-
// substring probe: `echo
|
|
77
|
-
//
|
|
78
|
-
// declared over a gate that writes nothing and then PASSES while certifying nothing.
|
|
71
|
+
// substring probe: `echo <body>`, the quoted body or a retired flag set is NOT a producer — else the
|
|
72
|
+
// checker is declared over a gate that writes nothing and then PASSES while certifying nothing.
|
|
79
73
|
export const matchesCoverageProducer = (cmd) => {
|
|
80
74
|
if (typeof cmd !== 'string') return false;
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
return
|
|
75
|
+
const [, text] = splitExecPrefix(cmd.trim());
|
|
76
|
+
const rest = bodyRest(text, COVERAGE_PRODUCER_BODY);
|
|
77
|
+
return rest !== null && pathShapedTail(rest);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// retiredProducerFormOf(cmd) → { prefix (as written, or ''), tail (trimmed), pathShaped } when the
|
|
81
|
+
// trimmed cmd is no or one exec prefix, `node --test`, a retired flag set and nothing or one space and
|
|
82
|
+
// a rest; null for every other value. The switch carries only a path-shaped tail onto the body.
|
|
83
|
+
export const retiredProducerFormOf = (cmd) => {
|
|
84
|
+
if (typeof cmd !== 'string') return null;
|
|
85
|
+
const [prefix, text] = splitExecPrefix(cmd.trim());
|
|
86
|
+
for (const body of RETIRED_BODIES) {
|
|
87
|
+
const tail = bodyRest(text, body);
|
|
88
|
+
if (tail !== null) return { prefix, tail, pathShaped: pathShapedTail(tail) };
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// unitTestsGuardFailure → the guard on every write of the body: run.mjs a regular file equal to `ownRun`, then the reporter
|
|
94
|
+
// a regular file, every folder on the way a directory (lstat: a link fails); null, or the first failing path and kind,
|
|
95
|
+
// worded by guardRemedy with the caller's upgrade.
|
|
96
|
+
const GUARD_PATHS = Object.freeze(['scripts/agent-workflow/run.mjs', 'scripts/agent-workflow/test-reporter/reporter.mjs']);
|
|
97
|
+
export const unitTestsGuardFailure = (projectDir, ownRun, { lstatSync, readFileSync }) => {
|
|
98
|
+
for (const rel of GUARD_PATHS) {
|
|
99
|
+
const parts = rel.split('/');
|
|
100
|
+
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
101
|
+
const at = parts.slice(0, depth).join('/');
|
|
102
|
+
const st = lstatSync(`${projectDir}/${at}`, { throwIfNoEntry: false });
|
|
103
|
+
if (st === undefined) return { path: rel, kind: 'absent' };
|
|
104
|
+
if (depth < parts.length ? !st.isDirectory() : !st.isFile()) return { path: at, kind: 'wrong-kind' };
|
|
105
|
+
}
|
|
106
|
+
if (rel === GUARD_PATHS[0] && !readFileSync(`${projectDir}/${rel}`).equals(readFileSync(ownRun))) return { path: rel, kind: 'earlier' };
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
84
109
|
};
|
|
110
|
+
export const guardRemedy = (kind, upgrade) => ({
|
|
111
|
+
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}.`,
|
|
112
|
+
earlier: `differs from this kit's — run ${upgrade}, whose configs step writes the current one`,
|
|
113
|
+
'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}`,
|
|
114
|
+
})[kind];
|
|
85
115
|
|
|
86
116
|
// isCoverageProducerGate(gate) → the GATE-level producer question, and the ONE predicate every
|
|
87
117
|
// consumer asks it through: does THIS declared entry write the lcov the canonical checker reads?
|
|
@@ -102,4 +132,9 @@ export const isCoverageProducerGate = (gate) => {
|
|
|
102
132
|
if (gate.cmd.trim() === '' || /[\r\n]/.test(gate.cmd)) return false;
|
|
103
133
|
return matchesCoverageProducer(gate.cmd) || gate.lcovProducer === true;
|
|
104
134
|
};
|
|
135
|
+
// readsAsCoverageProducer(gate, claim) → the ONE producer question of a declared row, asked by both hosts: `claim` is
|
|
136
|
+
// the row's claim on the coverage-check tool through the checker-claim canon, and only a row that is not the tool
|
|
137
|
+
// (`'not-the-tool'`, equal by test to CHECKER_CLAIM.NOT_THE_TOOL) can produce — a checker, canonical or vendored,
|
|
138
|
+
// consumes the lcov it reads, so its marker claims nothing.
|
|
139
|
+
export const readsAsCoverageProducer = (gate, claim) => claim === 'not-the-tool' && isCoverageProducerGate(gate);
|
|
105
140
|
// coverage-producer canon <<< END drift-guarded region
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// scripts.mjs — the upgrade's `scripts` op: every kit script of a deployment, the hook installer
|
|
2
2
|
// included, kept current by the one rule in the kit folder scripts/agent-workflow/. The family is the
|
|
3
|
-
// manifest's deployed entries (node-evidence.mjs) less the spec layer's modules and the
|
|
4
|
-
// which the specs op places. Each family file is
|
|
3
|
+
// manifest's deployed entries (node-evidence.mjs) less the spec layer's modules, the test reporter's and the
|
|
4
|
+
// command run.mjs, which the specs op places. Each family file is
|
|
5
5
|
// surveyed by proof before any write: absent, current, prior (a body the catalog lists for its manifest
|
|
6
6
|
// path) or edited. On every plain run a prior is refreshed, an edited one replaced in place and an
|
|
7
7
|
// absent one placed create-only, with no question and no copy kept; a current one is left. A project
|
|
@@ -32,8 +32,9 @@ export const VEHICLE_CHANNEL = VEHICLES_REL;
|
|
|
32
32
|
export const AGENT_CHANNEL = '.claude/agents/<name>.local.md with a name: of its own';
|
|
33
33
|
export const HOOK_CHANNEL = '.claude/hooks/<name>.local.mjs';
|
|
34
34
|
const ROTATOR = 'archives/archive-decisions.mjs';
|
|
35
|
-
// The family: every deployed entry outside the specs op's files (its
|
|
36
|
-
const
|
|
35
|
+
// The family: every deployed entry outside the specs op's files (its three modules and the command), in manifest order.
|
|
36
|
+
const SPECS_MODULES = ['spec-schema', 'docs-size', 'test-reporter'];
|
|
37
|
+
const FAMILY = DEPLOYED_SCRIPTS.filter((e) => e.module && !SPECS_MODULES.includes(e.module));
|
|
37
38
|
// The manifest paths a run of a component that is not accepted judges: the rotator and what it loads.
|
|
38
39
|
export const SEED_NAMES = Object.freeze(FAMILY.filter((e) => e.seed).map((e) => e.path));
|
|
39
40
|
const FOLDERS = [...new Set([SCRIPTS_DIR, KIT_SCRIPTS_DIR, ...FAMILY.map((e) => posix.dirname(e.deployed))])];
|
package/tools/ensure-configs.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// autonomy docs/ai/autonomy.json seed-if-missing (same)
|
|
7
7
|
// vehicles docs/ai/vehicles.json seed-if-missing (same)
|
|
8
8
|
// executor .claude/agents/executor.md judged against docs/ai/vehicles.json, never written: a differing body is pending
|
|
9
|
-
// specs scripts/<spec layer> reader + checker pairs and run.mjs, with no question and no copy kept:
|
|
9
|
+
// specs scripts/<spec layer> reader + checker pairs, the test reporter and run.mjs, with no question and no copy kept:
|
|
10
10
|
// + docs/ai/specs/index.md a shipped prior refreshed, an edited one replaced, an absent
|
|
11
11
|
// one placed; then the store root seeded create-only
|
|
12
12
|
// scripts scripts/<every kit script> once a kit script outside the seed names, or the old flat installer, stands there, every file not current
|
|
@@ -76,7 +76,7 @@ refreshed in place. Four ops refresh instead: the orchestration onboarding note,
|
|
|
76
76
|
note with no question and no copy kept, every recipe kept (a differing note's line names where a note of your
|
|
77
77
|
own goes); the spec-layer reader and checker pairs, with no question and no copy kept: a body a release shipped
|
|
78
78
|
is refreshed, an edited one replaced (its line names where an edit meant to last goes) and an absent one placed,
|
|
79
|
-
the reader pair, then the checker pair, then run.mjs, then the spec store root seeded create-only; the project rules
|
|
79
|
+
the reader pair, then the checker pair, then the test reporter, then run.mjs, then the spec store root seeded create-only; the project rules
|
|
80
80
|
kit file, refreshed while its bytes are a body a release shipped and any other body replaced by the template,
|
|
81
81
|
with no question and no copy kept, the effective file rebuilt as its copy and recorded where no local file
|
|
82
82
|
exists; and the navigator index — a GENERATED artifact, regenerated
|
package/tools/ensure-specs.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
// ensure-specs.mjs — the SIXTH upgrade ensure: the spec layer (memory 4.6.0, AD-112) kept current on an
|
|
2
2
|
// EXISTING deployment. Its scripts are the reader pair (the deployed entries of the spec-schema module)
|
|
3
|
-
// and the checker pair (the docs-size module's), plus the command, each at its deployed
|
|
4
|
-
// scripts/agent-workflow/, with the bundled files they import; every other kit script is
|
|
5
|
-
// ensure's. They and one store root follow the scripts op's rule (distribution-files/): every file is
|
|
3
|
+
// and the checker pair (the docs-size module's), plus the test reporter and the command, each at its deployed
|
|
4
|
+
// path in the kit folder scripts/agent-workflow/, with the bundled files they import; every other kit script is
|
|
5
|
+
// the scripts ensure's. They and one store root follow the scripts op's rule (distribution-files/): every file is
|
|
6
6
|
// surveyed by proof first, then on every plain run a prior body is refreshed and an edited one replaced
|
|
7
7
|
// in place, an absent one placed create-only and an absent store root seeded create-only, with no
|
|
8
8
|
// question and no copy kept; a current file is left. The writes run in a FIXED order:
|
|
9
9
|
// 1. the files the pairs import scripts/agent-workflow/shared/... (dependencies first)
|
|
10
10
|
// 2. the reader pair scripts/agent-workflow/spec-schema/...
|
|
11
11
|
// 3. the checker pair scripts/agent-workflow/docs-size/check-docs-size.mjs
|
|
12
|
-
// 4. the
|
|
13
|
-
// 5. the
|
|
12
|
+
// 4. the test reporter scripts/agent-workflow/test-reporter/reporter.mjs
|
|
13
|
+
// 5. the command scripts/agent-workflow/run.mjs, which runs the reporter
|
|
14
|
+
// 6. the store root docs/ai/specs/index.md (placeholders rendered)
|
|
14
15
|
// Why the order: every file is written after the files it imports, so each pair file it leaves loads;
|
|
15
16
|
// the kit's bundled navigator generator collapses `specs/` into one row, while the project's pre-commit
|
|
16
17
|
// hook runs ITS deployed checker — an older one renders the store row by row and reds `--check-index`.
|
|
@@ -31,6 +32,7 @@ import { fileLine, hookLine } from './distribution-files/index.mjs';
|
|
|
31
32
|
const OP = 'specs';
|
|
32
33
|
const READER = DEPLOYED_SCRIPTS.filter((e) => e.module === 'spec-schema');
|
|
33
34
|
const CHECKER = DEPLOYED_SCRIPTS.filter((e) => e.module === 'docs-size');
|
|
35
|
+
const REPORTER = DEPLOYED_SCRIPTS.filter((e) => e.module === 'test-reporter');
|
|
34
36
|
const COMMAND = DEPLOYED_SCRIPTS.find((e) => !e.module);
|
|
35
37
|
const STORE_ROOT_REL = 'docs/ai/specs/index.md';
|
|
36
38
|
const STORE_ROOT_TEMPLATE = ['references', 'templates', 'specs', 'index.md'];
|
|
@@ -43,10 +45,10 @@ const wrongKind = (rel, kind) => composeFailure(OP, 'wrong-node-kind', `${rel}:
|
|
|
43
45
|
|
|
44
46
|
// ── the survey: the pairs, the files they import and the store root classified, nothing written ───
|
|
45
47
|
|
|
46
|
-
// The bundled side: the pairs and their whole import closure in write order → { files } | { refusal }.
|
|
48
|
+
// The bundled side: the pairs, the reporter, the command and their whole import closure in write order → { files } | { refusal }.
|
|
47
49
|
const readBundles = (kitRoot, read) => {
|
|
48
50
|
const byPath = new Map();
|
|
49
|
-
const queue = [...READER, ...CHECKER, COMMAND];
|
|
51
|
+
const queue = [...READER, ...CHECKER, ...REPORTER, COMMAND];
|
|
50
52
|
for (const entry of queue) {
|
|
51
53
|
if (byPath.has(entry.path)) continue;
|
|
52
54
|
let bundle;
|
|
@@ -61,7 +63,8 @@ const readBundles = (kitRoot, read) => {
|
|
|
61
63
|
}
|
|
62
64
|
const of = (entries) => (path) => entries.some((e) => e.path === path);
|
|
63
65
|
const group = (keep) => dependenciesFirst([...byPath.values()].filter((f) => keep(f.path)));
|
|
64
|
-
|
|
66
|
+
const own = [READER, CHECKER, REPORTER].map(of);
|
|
67
|
+
return { files: [...group((p) => !own.some((is) => is(p)) && p !== COMMAND.path), ...own.flatMap(group), ...group((p) => p === COMMAND.path)] };
|
|
65
68
|
};
|
|
66
69
|
|
|
67
70
|
// Each folder on the way to a pair file or a file it imports, lstat-ed without following a link → a refusal or null.
|
|
@@ -11,7 +11,7 @@ import { join, isAbsolute } from 'node:path';
|
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
import { CHECKER_CLAIM, checkerClaimTool, classifyCheckerClaim } from './checker-claim.mjs';
|
|
13
13
|
import { fail, loadConfig, CONFIG_REL } from './orchestration-config.mjs';
|
|
14
|
-
import {
|
|
14
|
+
import { readsAsCoverageProducer, retiredProducerFormOf } from './coverage-producer.mjs';
|
|
15
15
|
import { matchesSourceSizeGate } from './source-size-core.mjs';
|
|
16
16
|
|
|
17
17
|
// The per-project declaration (strict JSON, hand-editable). cwd-relative — errors show a path the
|
|
@@ -158,11 +158,21 @@ export const isFinalCapableDeclaration = (gates, projectDir) => {
|
|
|
158
158
|
// so the checker reads nothing — or, worse, stale bytes an earlier run left behind — and still
|
|
159
159
|
// passes. ONE home for the rule: the written-declaration defects below and the advisor's
|
|
160
160
|
// inert-declaration item both decide through it, so they cannot drift apart. Producer-ness itself is
|
|
161
|
-
// the canon's
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
export const coverageProducerPrecedes = (gates, checkerIndex) =>
|
|
165
|
-
gates.slice(0, checkerIndex).some((gate) =>
|
|
161
|
+
// the canon's one row question (readsAsCoverageProducer: the gate-level predicate, asked only of a
|
|
162
|
+
// row that does not claim the coverage checker), so the slice is the only thing this function owns.
|
|
163
|
+
const COVERAGE_CHECK_TOOL = checkerClaimTool('coverage-check.mjs', fileURLToPath(new URL('./coverage-check.mjs', import.meta.url)));
|
|
164
|
+
export const coverageProducerPrecedes = (gates, checkerIndex, projectDir) =>
|
|
165
|
+
gates.slice(0, checkerIndex).some((gate) => readsAsCoverageProducer(gate, classifyCheckerClaim(COVERAGE_CHECK_TOOL, gate?.cmd, projectDir)));
|
|
166
|
+
|
|
167
|
+
// movableEarlierForm(gates) → whether a gate an earlier kit wrote, which the upgrade's gates-migration
|
|
168
|
+
// step moves (a retired form with a path-shaped tail), stands anywhere in the declaration (spec
|
|
169
|
+
// coverage-producer, the remedy route). A flagged tail is not movable: its remedy is its CUSTOMIZED line.
|
|
170
|
+
export const movableEarlierForm = (gates) => gates.some((gate) => retiredProducerFormOf(gate?.cmd)?.pathShaped === true);
|
|
171
|
+
|
|
172
|
+
// The checker lines' one fact and one remedy, and the upgrade's words, which predict nothing about the run.
|
|
173
|
+
export const NO_PRODUCER_FACT = 'no gate before it is a producer this kit reads';
|
|
174
|
+
export const NO_PRODUCER_REMEDY = 'declare or move one before it: node scripts/agent-workflow/run.mjs unit-tests <your test paths>, or mark your own suite gate "lcovProducer": true';
|
|
175
|
+
export const UPGRADE_MOVES = "it moves an earlier kit's gate with no question, or a line of its report names what stops it";
|
|
166
176
|
|
|
167
177
|
// coverageDeclarationDefects(gates, projectDir) → the WRITTEN-declaration coverage rule, as a list
|
|
168
178
|
// of named defects (empty = satisfied): at most ONE canonical coverage checker; if one is present
|
|
@@ -193,14 +203,12 @@ export const coverageDeclarationDefects = (gates, projectDir) => {
|
|
|
193
203
|
'places a new entry before a trailing checker, but it never reorders what it did not write)',
|
|
194
204
|
}];
|
|
195
205
|
}
|
|
196
|
-
if (!coverageProducerPrecedes(gates, index)) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
'(references/modes/gates.md names the exact form), or drop the checker',
|
|
203
|
-
}];
|
|
206
|
+
if (!coverageProducerPrecedes(gates, index, projectDir)) {
|
|
207
|
+
// One fact; the remedy is the upgrade's gates-migration step while a gate it moves stands anywhere.
|
|
208
|
+
const remedy = movableEarlierForm(gates)
|
|
209
|
+
? `run the gates-migration step of /agent-workflow-kit upgrade: ${UPGRADE_MOVES}`
|
|
210
|
+
: NO_PRODUCER_REMEDY;
|
|
211
|
+
return [{ kind: 'no-producer', message: `${GATES_REL}: the canonical coverage checker (${checkers[0].id}): ${NO_PRODUCER_FACT} — ${remedy}` }];
|
|
204
212
|
}
|
|
205
213
|
return [];
|
|
206
214
|
};
|