@sabaiway/agent-workflow-kit 10.0.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/SKILL.md +1 -1
- package/bridges/antigravity-cli-bridge/SKILL.md +4 -2
- package/bridges/antigravity-cli-bridge/bin/agy-review-harness.test.mjs +288 -0
- package/bridges/antigravity-cli-bridge/bin/agy-review-verdict.test.mjs +109 -0
- package/bridges/antigravity-cli-bridge/bin/agy-review.sh +19 -1
- package/bridges/antigravity-cli-bridge/bin/agy-review.test.mjs +5 -336
- package/bridges/antigravity-cli-bridge/capability.json +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/tools/fold-scope.mjs +34 -7
- package/tools/queue-audit-cli.mjs +135 -0
- package/tools/queue-audit-rows.mjs +310 -0
- package/tools/queue-audit.mjs +164 -0
- package/tools/spec-check.mjs +11 -1
- package/tools/spec-coverage-cli.mjs +211 -0
- package/tools/spec-coverage.mjs +88 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The CLI half of the coverage requirement: argv, fs and the debt record. No rule lives here (the
|
|
3
|
+
// rule is spec-coverage.mjs), and the ratchet is enforced HERE because it is the only write.
|
|
4
|
+
//
|
|
5
|
+
// Exit codes: 0 accept; 1 refuse (an uncovered tool, or a settled debt entry still recorded); 2
|
|
6
|
+
// usage — an unknown flag, a flag with no value, an unreadable scope or store, a reasonless write.
|
|
7
|
+
|
|
8
|
+
import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { join, relative, sep } from 'node:path';
|
|
10
|
+
import { isDirectRun } from './direct-run.mjs';
|
|
11
|
+
import { claimsOf, formatFindings, judgeCoverage, settleAfter } from './spec-coverage.mjs';
|
|
12
|
+
|
|
13
|
+
export const SCOPE_PATH = join('docs', 'ai', 'spec-coverage.json');
|
|
14
|
+
export const STORE_ROOT = join('docs', 'ai', 'specs');
|
|
15
|
+
const REASON_MAX_BYTES = 300;
|
|
16
|
+
|
|
17
|
+
const HELP = `spec-coverage — every shipped tool is governed by a contract, or the debt names it.
|
|
18
|
+
|
|
19
|
+
Usage:
|
|
20
|
+
node spec-coverage-cli.mjs --report [--root <dir>]
|
|
21
|
+
node spec-coverage-cli.mjs --check [--root <dir>]
|
|
22
|
+
node spec-coverage-cli.mjs --write-debt --reason "<what was paid, and by which contract>" [--root <dir>]
|
|
23
|
+
|
|
24
|
+
--report one line per in-scope tool: the contract that covers it, or that none does.
|
|
25
|
+
--check refuses an in-scope tool no contract claims and is not recorded as debt, and a
|
|
26
|
+
recorded entry that is already settled — the record must not overstate the debt.
|
|
27
|
+
--write-debt records what was PAID: every adopted path whose contract now exists moves into the
|
|
28
|
+
settled set, and nothing else changes. It never touches the adoption baseline, so a
|
|
29
|
+
path outside it cannot be invented — it is refused by name. Write the contract first.
|
|
30
|
+
|
|
31
|
+
Scope and debt: ${SCOPE_PATH}. Contracts: ${STORE_ROOT}. Exit codes: 0 accept; 1 refuse; 2 usage.`;
|
|
32
|
+
|
|
33
|
+
const fail = (exitCode, message) => Object.assign(new Error(message), { exitCode });
|
|
34
|
+
const posix = (p) => p.split(sep).join('/');
|
|
35
|
+
|
|
36
|
+
// A scope this tool cannot trust is worse than no scope: `{}`, an empty `roots`, or an `exclude`
|
|
37
|
+
// carrying an empty string all yield a census of ZERO tools and a cheerful PASS — a gate answering
|
|
38
|
+
// about a domain it never looked at, which is the exact failure this whole rung exists to end.
|
|
39
|
+
const validateScope = (scope, path) => {
|
|
40
|
+
const bad = (why) => { throw fail(2, `the coverage scope ${path} is unusable: ${why}`); };
|
|
41
|
+
if (scope === null || typeof scope !== 'object' || Array.isArray(scope)) bad('it is not an object');
|
|
42
|
+
if (scope.schema !== 1) bad(`schema must be 1, got ${JSON.stringify(scope.schema)}`);
|
|
43
|
+
const list = (key, required) => {
|
|
44
|
+
const value = scope[key];
|
|
45
|
+
if (value === undefined && !required) return [];
|
|
46
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== 'string' || v === '')) bad(`${key} must be an array of non-empty strings`);
|
|
47
|
+
if (required && value.length === 0) bad(`${key} is empty, so nothing would ever be judged`);
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
list('roots', true);
|
|
51
|
+
const extensions = list('extensions', true);
|
|
52
|
+
if (extensions.some((ext) => !ext.startsWith('.'))) bad('every extension starts with a dot');
|
|
53
|
+
list('exclude', false);
|
|
54
|
+
// Both recorded sets are PATHS. `Array.isArray` alone let `[42]` through, and a scope the tool
|
|
55
|
+
// cannot trust is the thing this validator exists to catch.
|
|
56
|
+
if (!Array.isArray(scope.adopted)) bad('adopted is the frozen set measured at adoption, and it must be an array');
|
|
57
|
+
list('adopted', false);
|
|
58
|
+
list('settled', false);
|
|
59
|
+
return scope;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const readJson = (path, what) => {
|
|
63
|
+
let raw;
|
|
64
|
+
try {
|
|
65
|
+
raw = readFileSync(path, 'utf8');
|
|
66
|
+
} catch (err) {
|
|
67
|
+
throw fail(2, `cannot read ${what} ${path}: ${err.message}`);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(raw);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
throw fail(2, `${what} ${path} is not valid JSON: ${err.message}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Deterministic order in both walks: a report a human compares between runs must not depend on the
|
|
77
|
+
// order a directory happens to be read in.
|
|
78
|
+
const sorted = (entries) => [...entries].sort((a, b) => (a.name < b.name ? -1 : 1));
|
|
79
|
+
|
|
80
|
+
export const specDocuments = (root, io = { readdirSync, readFileSync }) => {
|
|
81
|
+
const out = [];
|
|
82
|
+
const walk = (dir) => {
|
|
83
|
+
for (const entry of sorted(io.readdirSync(dir, { withFileTypes: true }))) {
|
|
84
|
+
const full = join(dir, entry.name);
|
|
85
|
+
if (entry.isDirectory()) walk(full);
|
|
86
|
+
else if (entry.name.endsWith('.md')) out.push({ rel: posix(relative(root, full)), text: io.readFileSync(full, 'utf8') });
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
walk(join(root, STORE_ROOT));
|
|
90
|
+
return out;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// A test file is never in scope: a contract governs the module, and its tests are the evidence FOR
|
|
94
|
+
// that contract, not a second thing to write one for. A `<name>.test/` directory is the same answer.
|
|
95
|
+
export const toolsIn = (root, scope, io = { readdirSync }) => {
|
|
96
|
+
const extensions = scope.extensions ?? ['.mjs'];
|
|
97
|
+
// A textual prefix is not a path. `.../fixtures` would also hide `.../fixtures-escape.mjs`, so a
|
|
98
|
+
// new tool could leave the scope by being named next to an excluded directory. The boundary is a
|
|
99
|
+
// path COMPONENT: the entry itself, or something under it.
|
|
100
|
+
const excluded = (rel) => (scope.exclude ?? []).some((prefix) => rel === prefix || rel.startsWith(`${prefix}/`));
|
|
101
|
+
const isTest = (name) => extensions.some((ext) => name.endsWith(`.test${ext}`));
|
|
102
|
+
const out = [];
|
|
103
|
+
const walk = (dir) => {
|
|
104
|
+
for (const entry of sorted(io.readdirSync(dir, { withFileTypes: true }))) {
|
|
105
|
+
const full = join(dir, entry.name);
|
|
106
|
+
const rel = posix(relative(root, full));
|
|
107
|
+
if (excluded(rel)) continue;
|
|
108
|
+
if (entry.isDirectory()) {
|
|
109
|
+
if (!entry.name.endsWith('.test')) walk(full);
|
|
110
|
+
} else if (extensions.some((ext) => entry.name.endsWith(ext)) && !isTest(entry.name)) out.push(rel);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
for (const scopeRoot of scope.roots ?? []) walk(join(root, scopeRoot));
|
|
114
|
+
return out;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const parseArgv = (argv) => {
|
|
118
|
+
if (argv.length === 1 && (argv[0] === '--help' || argv[0] === '-h')) return { mode: 'help' };
|
|
119
|
+
const options = { mode: null, root: process.cwd(), reason: null };
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
const valueOf = (index, flag) => {
|
|
122
|
+
const value = argv[index + 1];
|
|
123
|
+
if (value === undefined || value === '' || value.startsWith('--')) throw fail(2, `${flag} takes a value`);
|
|
124
|
+
return value;
|
|
125
|
+
};
|
|
126
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
127
|
+
const arg = argv[index];
|
|
128
|
+
if (arg === '--report' || arg === '--check' || arg === '--write-debt') {
|
|
129
|
+
if (options.mode) throw fail(2, `--${options.mode} was already given — name exactly one mode`);
|
|
130
|
+
options.mode = arg.slice(2);
|
|
131
|
+
} else if (arg === '--root' || arg === '--reason') {
|
|
132
|
+
if (seen.has(arg)) throw fail(2, `${arg} was given twice — each option is named exactly once`);
|
|
133
|
+
seen.add(arg);
|
|
134
|
+
options[arg === '--root' ? 'root' : 'reason'] = valueOf(index, arg);
|
|
135
|
+
index += 1;
|
|
136
|
+
} else throw fail(2, `unknown argument "${arg}" — run with --help`);
|
|
137
|
+
}
|
|
138
|
+
if (!options.mode) throw fail(2, 'one of --report, --check or --write-debt is required — run with --help');
|
|
139
|
+
// A repayment with no stated reason is how a ratchet becomes a rubber stamp: the reason is recorded
|
|
140
|
+
// in the file it changes and is what the commit message and the changelog restate.
|
|
141
|
+
if (options.mode === 'write-debt' && !options.reason) throw fail(2, '--write-debt requires --reason "<what was paid, and by which contract>"');
|
|
142
|
+
if (options.reason && Buffer.byteLength(options.reason, 'utf8') > REASON_MAX_BYTES) {
|
|
143
|
+
throw fail(2, `a reason must be at most ${REASON_MAX_BYTES} UTF-8 bytes, got ${Buffer.byteLength(options.reason, 'utf8')}`);
|
|
144
|
+
}
|
|
145
|
+
return options;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const main = (argv, { log = console.log, error = console.error, io } = {}) => {
|
|
149
|
+
let options;
|
|
150
|
+
try {
|
|
151
|
+
options = parseArgv(argv);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
error(err.message);
|
|
154
|
+
return err.exitCode ?? 2;
|
|
155
|
+
}
|
|
156
|
+
if (options.mode === 'help') {
|
|
157
|
+
log(HELP);
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let scope;
|
|
162
|
+
let judged;
|
|
163
|
+
let unreadable;
|
|
164
|
+
try {
|
|
165
|
+
scope = validateScope(readJson(join(options.root, SCOPE_PATH), 'the coverage scope'), join(options.root, SCOPE_PATH));
|
|
166
|
+
const documents = specDocuments(options.root, io);
|
|
167
|
+
const found = claimsOf(documents);
|
|
168
|
+
unreadable = found.unreadable;
|
|
169
|
+
const tools = toolsIn(options.root, scope, io);
|
|
170
|
+
// A census of nothing is not a pass. Either the roots are wrong or the tree is not what the
|
|
171
|
+
// scope describes; both are refusals, never a green.
|
|
172
|
+
if (tools.length === 0) throw fail(2, `the declared roots (${(scope.roots ?? []).join(', ')}) hold no file this scope would judge — a census of zero is not a pass`);
|
|
173
|
+
judged = judgeCoverage({ tools, claims: found.claims, adopted: scope.adopted, settled: scope.settled ?? [] });
|
|
174
|
+
} catch (err) {
|
|
175
|
+
error(err.message);
|
|
176
|
+
return err.exitCode ?? 2;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (options.mode === 'report') {
|
|
180
|
+
for (const { path, by } of judged.covered) log(`${path}\tcovered\t${by}`);
|
|
181
|
+
for (const path of judged.uncovered) log(`${path}\tuncovered\t-`);
|
|
182
|
+
for (const path of judged.debt) log(`${path}\tdebt\t-`);
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (options.mode === 'write-debt') {
|
|
187
|
+
// What is PAYABLE is a subset of what was ADOPTED by construction — it is the owed set filtered,
|
|
188
|
+
// and the owed set is the baseline minus what is already settled. So this write cannot invent a
|
|
189
|
+
// path even in principle; `settleAfter` states that as a rule and refuses one directly, which is
|
|
190
|
+
// where it is asserted. A branch here would be unreachable, and an unreachable guard is not a
|
|
191
|
+
// guard: it is a claim nobody can check.
|
|
192
|
+
const next = settleAfter(scope.adopted, scope.settled ?? [], judged.payable);
|
|
193
|
+
// `adopted` is never rewritten here: it is the state this write is judged against.
|
|
194
|
+
writeFileSync(join(options.root, SCOPE_PATH), `${JSON.stringify({ ...scope, reason: options.reason, settled: next.settled }, null, 2)}\n`);
|
|
195
|
+
log(`spec-coverage: debt ${judged.debt.length} → ${judged.debt.length - next.added.length} (${next.added.length} paid and recorded)`);
|
|
196
|
+
log(`reason: ${options.reason}`);
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const findings = formatFindings({ ...judged, unreadable });
|
|
201
|
+
if (findings.length === 0) {
|
|
202
|
+
log(`spec-coverage: PASS — ${judged.covered.length} tool(s) governed by a contract, ${judged.debt.length} still owed`);
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
error(`spec-coverage: FAIL — ${findings.length} finding(s) against ${join(options.root, SCOPE_PATH)}:`);
|
|
206
|
+
for (const line of findings) error(line);
|
|
207
|
+
error('spec-coverage: WHY — no work is done without a specification; a tool no contract governs promises nothing anyone can check.');
|
|
208
|
+
return 1;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (isDirectRun(import.meta.url)) process.exitCode = main(process.argv.slice(2));
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// NO WORK IS DONE WITHOUT A SPECIFICATION — the half prose cannot do.
|
|
3
|
+
//
|
|
4
|
+
// The spec store answers "what does this module promise?" only for the modules somebody chose to
|
|
5
|
+
// write a contract for, so a contract has been a suggestion: measured when this module was written,
|
|
6
|
+
// 122 tool modules under `agent-workflow-kit/tools/` and 14 of them covered. This module makes the
|
|
7
|
+
// contract a REQUIREMENT with a ratchet — a shipped tool no contract governs is a REFUSAL, and the
|
|
8
|
+
// debt of today's uncovered tools may only shrink.
|
|
9
|
+
//
|
|
10
|
+
// The contract this module is built to is `docs/ai/specs/kit/spec-coverage.md`, and it was written
|
|
11
|
+
// BEFORE this file. That order is the point: a contract amended after the code describes whatever
|
|
12
|
+
// the last review happened to find, which makes review an open question with no bounded answer.
|
|
13
|
+
//
|
|
14
|
+
// Pure functions. No filesystem, no argv, no side effects on import — the CLI half owns all of that.
|
|
15
|
+
// Dependency-free, Node >= 22.
|
|
16
|
+
|
|
17
|
+
import { readSpecDocument } from '../references/scripts/spec-schema.mjs';
|
|
18
|
+
|
|
19
|
+
// One `## Module` bullet, carried with the document that made the claim so a refusal can name the
|
|
20
|
+
// owner. The two forms are the ones the spec schema already validates and there is no third here:
|
|
21
|
+
// a `dir/` root covers by PREFIX, a file claim by EQUALITY. The trailing slash is what makes the
|
|
22
|
+
// prefix test safe — `tools/manifest/` can never swallow `tools/manifest-validate.mjs`.
|
|
23
|
+
// Only a LIVE contract claims shipped code. A `draft` is a proposal — it may name a module nobody
|
|
24
|
+
// has built and bind a scenario to nothing — and a `retired` one has stopped promising anything. If
|
|
25
|
+
// either counted, a tool could ship covered by a contract that was never in force.
|
|
26
|
+
const CLAIMING_KINDS = new Set(['spec']);
|
|
27
|
+
const CLAIMING_STATUS = 'live';
|
|
28
|
+
|
|
29
|
+
export const claimsOf = (documents) => {
|
|
30
|
+
const claims = [];
|
|
31
|
+
const unreadable = [];
|
|
32
|
+
for (const { rel, text } of documents) {
|
|
33
|
+
const verdict = readSpecDocument(String(text ?? ''), rel);
|
|
34
|
+
// Only a CONTRACT claims code. A navigator (`kind: index`) lists children and a part belongs to
|
|
35
|
+
// the module its parent already claims, so neither is asked for a `## Module` — skipping them by
|
|
36
|
+
// KIND, never by the absence of the section, is what keeps the next line honest.
|
|
37
|
+
if (!CLAIMING_KINDS.has(verdict.kind) || verdict.status !== CLAIMING_STATUS) continue;
|
|
38
|
+
const module = verdict.structure?.module;
|
|
39
|
+
// A CONTRACT whose module cannot be read is its OWN finding, never a silent skip: the tools it
|
|
40
|
+
// would have covered would look uncovered and the refusal would name the wrong defect.
|
|
41
|
+
if (!module) unreadable.push({ rel, why: verdict.errors?.[0]?.message ?? 'no readable ## Module declaration' });
|
|
42
|
+
else for (const path of module.paths) claims.push({ path, form: module.form, by: rel });
|
|
43
|
+
}
|
|
44
|
+
return { claims, unreadable };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const coveredBy = (claims, path) =>
|
|
48
|
+
claims.find((claim) => (claim.path.endsWith('/') ? path.startsWith(claim.path) : claim.path === path)) ?? null;
|
|
49
|
+
|
|
50
|
+
// The verdict over one census. The debt is DERIVED — `adopted` minus `settled` — so there is no
|
|
51
|
+
// stored list a hand can edit into a lie. Three findings:
|
|
52
|
+
// uncovered a tool no contract covers and the derived debt does not owe — the refusal
|
|
53
|
+
// falselySettled a path recorded as PAID whose contract is not there — the record claims what the
|
|
54
|
+
// contracts do not say, and it is checked against them every run
|
|
55
|
+
// payable a path still owed whose contract now EXISTS — the debt shrank and the record did
|
|
56
|
+
// not, so run --write-debt; until then the record overstates what is owed
|
|
57
|
+
export const judgeCoverage = ({ tools, claims, adopted = [], settled = [] }) => {
|
|
58
|
+
const paid = new Set(settled);
|
|
59
|
+
const owed = adopted.filter((path) => !paid.has(path));
|
|
60
|
+
const stillOwed = new Set(owed);
|
|
61
|
+
const present = new Set(tools);
|
|
62
|
+
const covered = [];
|
|
63
|
+
const uncovered = [];
|
|
64
|
+
for (const path of tools) {
|
|
65
|
+
const claim = coveredBy(claims, path);
|
|
66
|
+
if (claim) covered.push({ path, by: claim.by });
|
|
67
|
+
else if (!stillOwed.has(path)) uncovered.push(path);
|
|
68
|
+
}
|
|
69
|
+
const falselySettled = settled.filter((path) => present.has(path) && coveredBy(claims, path) === null);
|
|
70
|
+
const payable = owed.filter((path) => !present.has(path) || coveredBy(claims, path) !== null);
|
|
71
|
+
return { covered, uncovered, falselySettled, payable, debt: owed };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// What a `--write-debt` run may record: every path whose contract now exists moves into `settled`,
|
|
75
|
+
// and nothing else changes. `adopted` is never touched, so a path that is not in it cannot be
|
|
76
|
+
// invented — the run names it and says to write the contract.
|
|
77
|
+
export const settleAfter = (adopted, settled, payable) => {
|
|
78
|
+
const unknown = payable.filter((path) => !adopted.includes(path));
|
|
79
|
+
if (unknown.length) return { ok: false, unknown };
|
|
80
|
+
return { ok: true, settled: [...new Set([...settled, ...payable])].sort(), added: payable };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const formatFindings = ({ uncovered, falselySettled = [], payable = [], unreadable = [] }) => [
|
|
84
|
+
...unreadable.map((u) => ` ${u.rel}: its ## Module cannot be read (${u.why}) — the tools it claims are unknown`),
|
|
85
|
+
...uncovered.map((p) => ` ${p}: no contract under docs/ai/specs/ claims this module — write one, or it cannot ship`),
|
|
86
|
+
...falselySettled.map((p) => ` ${p}: recorded as SETTLED, but no live contract claims it — the record asserts a contract that is not there`),
|
|
87
|
+
...payable.map((p) => ` ${p}: still recorded as owed although it is covered now (or gone) — run --write-debt to record what was paid`),
|
|
88
|
+
];
|