@sabaiway/agent-workflow-kit 23.8.0 → 23.10.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 +51 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/modes/coverage-check.md +4 -2
- package/references/modes/gates.md +1 -1
- package/references/modes/now.md +1 -1
- package/references/modes/procedures.md +1 -1
- package/references/modes/recommendations.md +2 -2
- package/tools/checker-block/index.mjs +2 -0
- package/tools/checker-block/place.mjs +71 -0
- package/tools/checker-block/tail.mjs +16 -0
- package/tools/coverage-check/block.mjs +75 -0
- package/tools/coverage-check/help.mjs +47 -0
- package/tools/coverage-check/index.mjs +5 -0
- package/tools/coverage-check.mjs +62 -112
- package/tools/coverage-declared/judge.mjs +2 -3
- package/tools/gates-init.mjs +3 -3
- package/tools/now-render.mjs +1 -1
- package/tools/procedures.mjs +5 -11
- package/tools/recommendations.mjs +4 -4
- package/tools/source-size/help.mjs +8 -7
- package/tools/source-size/index.mjs +1 -0
- package/tools/source-size/limits.mjs +8 -2
- package/tools/source-size/piles.mjs +2 -2
- package/tools/source-size/reason.mjs +0 -1
- package/tools/source-size/record.mjs +6 -13
- package/tools/source-size/setup.mjs +2 -2
- package/tools/source-size-config.mjs +29 -41
- package/tools/source-size-core.mjs +3 -2
- package/tools/source-size-judge.mjs +11 -28
- package/tools/source-size-refusal.mjs +1 -1
- package/tools/source-size-report.mjs +24 -27
- package/tools/source-size-runs.mjs +31 -24
package/tools/coverage-check.mjs
CHANGED
|
@@ -22,13 +22,20 @@
|
|
|
22
22
|
|
|
23
23
|
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
24
24
|
import { createHash } from 'node:crypto';
|
|
25
|
-
import { join } from 'node:path';
|
|
25
|
+
import { join, resolve } from 'node:path';
|
|
26
26
|
import { spawnSync } from 'node:child_process';
|
|
27
27
|
import { GIT_MAX_BUFFER } from './git-env.mjs';
|
|
28
28
|
import { computeChangedSurface } from './changed-surface.mjs';
|
|
29
29
|
import { isDirectRun } from './direct-run.mjs';
|
|
30
30
|
import { lcovCoveredMap, uncoveredChangedFromLcov } from './lcov.mjs';
|
|
31
|
-
import {
|
|
31
|
+
import { resolveDeclaredListPath, readDeclaredList, judgeDeclaredList, compareDeclaredAttest, declaredPassLine } from './coverage-declared/index.mjs';
|
|
32
|
+
import { composeUsageRefusal } from '../references/scripts/shared/index.mjs';
|
|
33
|
+
import { runCheckerTail } from './checker-block/index.mjs';
|
|
34
|
+
import {
|
|
35
|
+
CHECKER_NAME, LCOV_BASENAME, composeCoverageBlock, isRed, composeHelp, composeUsage,
|
|
36
|
+
buildDeclaredFindings, buildLcovFindings, buildUncoveredFindings, buildRedProofFindings,
|
|
37
|
+
buildEvidenceFindings, buildAttestationFindings,
|
|
38
|
+
} from './coverage-check/index.mjs';
|
|
32
39
|
import {
|
|
33
40
|
computeTreeFingerprint,
|
|
34
41
|
resolveBase,
|
|
@@ -45,9 +52,12 @@ import {
|
|
|
45
52
|
} from './core-evidence.mjs';
|
|
46
53
|
|
|
47
54
|
export const COVERAGE_CHECK_STOP = 'COVERAGE_CHECK_STOP';
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
export { LCOV_BASENAME };
|
|
56
|
+
const USAGE_EXIT_CODE = 2;
|
|
57
|
+
const ERROR_EXIT_CODE = 1;
|
|
58
|
+
const NOT_FOUND = -1;
|
|
59
|
+
const LINE_FEED = '\n';
|
|
60
|
+
const ERROR_REMEDY = 'fix the cause the stack below names, then re-run';
|
|
51
61
|
|
|
52
62
|
const gitLine = (args, cwd) => {
|
|
53
63
|
const r = spawnSync('git', args, { cwd, maxBuffer: GIT_MAX_BUFFER, windowsHide: true });
|
|
@@ -70,19 +80,18 @@ export const resolveLcovPath = (cwd, env = process.env) => {
|
|
|
70
80
|
const checkCoverage = ({ rootTop, lcovPath, judgeDeclared }) => {
|
|
71
81
|
const notes = [];
|
|
72
82
|
const failures = [];
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return { failures, notes: [`skipped-no-lcov: no lcov file at ${lcovPath} — NO coverage check ran (produce it via the declared unit-tests gate cmd's lcov reporters)`], skipped: true, lcovSha256: null, declared: judgeDeclared(null) };
|
|
83
|
+
const status = (() => {
|
|
84
|
+
try {
|
|
85
|
+
return { file: lstatSync(lcovPath) };
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return { error };
|
|
79
88
|
}
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
})();
|
|
90
|
+
if (status.error?.code === 'ENOENT') {
|
|
91
|
+
return { failures, notes: [`skipped-no-lcov: no lcov file at ${lcovPath} — NO coverage check ran (produce it via the declared unit-tests gate cmd's lcov reporters)`], skipped: true, lcovSha256: null, declared: judgeDeclared(null) };
|
|
82
92
|
}
|
|
83
|
-
if (!
|
|
84
|
-
failures
|
|
85
|
-
return { failures, notes, skipped: false, lcovSha256: null, declared: judgeDeclared(null) };
|
|
93
|
+
if (status.error || !status.file.isFile()) {
|
|
94
|
+
return { failures, lcovFailure: { path: resolve(lcovPath), error: status.error }, notes, skipped: false, lcovSha256: null, declared: judgeDeclared(null) };
|
|
86
95
|
}
|
|
87
96
|
const surface = computeChangedSurface(rootTop);
|
|
88
97
|
const lcovBytes = readFileSync(lcovPath);
|
|
@@ -94,10 +103,10 @@ const checkCoverage = ({ rootTop, lcovPath, judgeDeclared }) => {
|
|
|
94
103
|
const key = keyFor(rootTop, rel);
|
|
95
104
|
const uncovered = uncoveredChangedFromLcov(covered, key, lines);
|
|
96
105
|
if (uncovered === null) {
|
|
97
|
-
failures.push(
|
|
106
|
+
failures.push({ path: rel });
|
|
98
107
|
continue;
|
|
99
108
|
}
|
|
100
|
-
for (const n of uncovered) failures.push(
|
|
109
|
+
for (const n of uncovered) failures.push({ path: rel, line: n });
|
|
101
110
|
}
|
|
102
111
|
if (surface.outOfDomain.length > 0) {
|
|
103
112
|
notes.push(`out-of-domain changed files (no Node-line coverage claim; covered by their own suites): ${surface.outOfDomain.join(', ')}`);
|
|
@@ -209,17 +218,17 @@ const verifyRedProofs = ({ rootTop, cwd, env }) => {
|
|
|
209
218
|
for (const record of bound) {
|
|
210
219
|
const id = record.testId;
|
|
211
220
|
if (record.fingerprint === fingerprint) {
|
|
212
|
-
failures.push(
|
|
221
|
+
failures.push({ file: record.file, testId: id, reason: "the record's pre-fix fingerprint EQUALS the current tree — nothing changed since the observed red (reuse/forgery); re-observe on the pre-fix tree" });
|
|
213
222
|
continue;
|
|
214
223
|
}
|
|
215
224
|
const resolved = resolveTestFile(rootTop, record.file);
|
|
216
225
|
if (!resolved.ok) {
|
|
217
|
-
failures.push(
|
|
226
|
+
failures.push({ file: record.file, testId: id, reason: `the bound test file ${resolved.reason.includes('does not exist') ? 'was deleted — ' : ''}${resolved.reason}` });
|
|
218
227
|
continue;
|
|
219
228
|
}
|
|
220
229
|
const currentHash = hashFileBytes(resolved.abs);
|
|
221
230
|
if (currentHash !== record.fileHash) {
|
|
222
|
-
failures.push(
|
|
231
|
+
failures.push({ file: record.file, testId: id, reason: "the bound test file's content changed since the observed red (hash mismatch) — re-observe red at the new expectations" });
|
|
223
232
|
continue;
|
|
224
233
|
}
|
|
225
234
|
let greens = 0;
|
|
@@ -232,11 +241,11 @@ const verifyRedProofs = ({ rootTop, cwd, env }) => {
|
|
|
232
241
|
if (p.resolvable && p.baselineGreen) greens += 1;
|
|
233
242
|
}
|
|
234
243
|
if (executed === 0) {
|
|
235
|
-
failures.push(
|
|
244
|
+
failures.push({ file: record.file, testId: id, reason: 'the pattern selects no test (zero-match) — the declared red→green pin is gone' });
|
|
236
245
|
continue;
|
|
237
246
|
}
|
|
238
247
|
if (greens !== reruns) {
|
|
239
|
-
failures.push(
|
|
248
|
+
failures.push({ file: record.file, testId: id, reason: `not green ${reruns}/${reruns} at the final run (${greens}/${reruns} green) — the declared fix is red` });
|
|
240
249
|
}
|
|
241
250
|
}
|
|
242
251
|
return { failures, verified: bound.length };
|
|
@@ -250,7 +259,6 @@ export const runCheck = ({ cwd = process.cwd(), env = process.env } = {}) => {
|
|
|
250
259
|
const read = readDeclaredList(resolveDeclaredListPath(rootTop));
|
|
251
260
|
const lcovPath = resolveLcovPath(cwd, env);
|
|
252
261
|
const lines = [];
|
|
253
|
-
let failed = false;
|
|
254
262
|
// The identity is read BEFORE the coverage arm and again AFTER it: a single up-front comparison
|
|
255
263
|
// leaves a window in which the tree moves between the surface walk and the verdict.
|
|
256
264
|
const identityBefore = { fingerprint: computeTreeFingerprint(cwd), base: resolveBase(cwd) };
|
|
@@ -264,29 +272,10 @@ export const runCheck = ({ cwd = process.cwd(), env = process.env } = {}) => {
|
|
|
264
272
|
lines.push(`coverage-check: lcov-sha256=${cov.lcovSha256 ?? 'none'}`);
|
|
265
273
|
for (const note of cov.notes) lines.push(`coverage-check: ${note}`);
|
|
266
274
|
lines.push(...declared.lines);
|
|
267
|
-
if (declared.configFailure) {
|
|
268
|
-
failed = true;
|
|
269
|
-
lines.push(declared.configFailure);
|
|
270
|
-
}
|
|
271
|
-
const failures = [...cov.failures, ...declared.failures];
|
|
272
|
-
if (failures.length > 0) {
|
|
273
|
-
failed = true;
|
|
274
|
-
lines.push('coverage-check: FAIL — uncovered/unattributed changed Node lines:');
|
|
275
|
-
for (const f of failures) lines.push(` ${f}`);
|
|
276
|
-
}
|
|
277
275
|
// The probes must never inherit a live attestation capability (a detached descendant could keep it).
|
|
278
276
|
const red = verifyRedProofs({ rootTop, cwd, env: withoutAttestEnv(env) });
|
|
279
|
-
if (red.storeFailure) {
|
|
280
|
-
|
|
281
|
-
lines.push(`coverage-check: FAIL — ${red.storeFailure}`);
|
|
282
|
-
} else {
|
|
283
|
-
if (red.failures.length > 0) {
|
|
284
|
-
failed = true;
|
|
285
|
-
lines.push('coverage-check: FAIL — red-proof obligations not satisfied:');
|
|
286
|
-
for (const f of red.failures) lines.push(` ${f}`);
|
|
287
|
-
} else if (red.verified > 0) {
|
|
288
|
-
lines.push(`coverage-check: ${red.verified} red-proof record(s) verified green N/N with custody intact`);
|
|
289
|
-
}
|
|
277
|
+
if (!red.storeFailure && red.failures.length === 0 && red.verified > 0) {
|
|
278
|
+
lines.push(`coverage-check: ${red.verified} red-proof record(s) verified green N/N with custody intact`);
|
|
290
279
|
}
|
|
291
280
|
// Re-read the identity AFTER the coverage arm and re-decide: the attestation must describe the
|
|
292
281
|
// tree the verdict was actually computed over, not the one it started over.
|
|
@@ -303,10 +292,16 @@ export const runCheck = ({ cwd = process.cwd(), env = process.env } = {}) => {
|
|
|
303
292
|
// EXACTLY ONE fully anchored machine line, the lcov-sha256 contract's sibling — the runner binds
|
|
304
293
|
// it, so a missing/duplicated/injected one is an integrity failure rather than a silent green.
|
|
305
294
|
lines.push(`coverage-check: attested=${attesting ? 'yes' : 'no'}`);
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
295
|
+
const classes = [
|
|
296
|
+
buildDeclaredFindings(declared),
|
|
297
|
+
buildLcovFindings(cov.lcovFailure),
|
|
298
|
+
buildUncoveredFindings(cov.failures),
|
|
299
|
+
buildRedProofFindings(red.failures ?? []),
|
|
300
|
+
buildEvidenceFindings(red.storeFailure ? resolve(storePath) : storePath, red.storeFailure),
|
|
301
|
+
buildAttestationFindings(rootTop, attestation.refusal),
|
|
302
|
+
];
|
|
303
|
+
const failed = isRed(classes);
|
|
304
|
+
if (!attestation.refusal && !attesting) {
|
|
310
305
|
lines.push(`coverage-check: NO VERDICT — ${contextValid ? NO_BYTES_NO_VERDICT : attestation.reason}`);
|
|
311
306
|
}
|
|
312
307
|
// The attestation gates ONLY the coverage claim. Every pre-existing fail-closed refusal above
|
|
@@ -314,71 +309,28 @@ export const runCheck = ({ cwd = process.cwd(), env = process.env } = {}) => {
|
|
|
314
309
|
if (attesting && !failed && cov.failures.length === 0) {
|
|
315
310
|
lines.push(declaredPassLine(declared.notJudged.length));
|
|
316
311
|
}
|
|
317
|
-
return { code: failed ? 1 : 0, lines };
|
|
312
|
+
return { code: failed ? 1 : 0, lines: composeCoverageBlock({ root: rootTop, classes, after: lines, withoutContext: !contextValid }) };
|
|
318
313
|
};
|
|
319
314
|
|
|
320
315
|
// ── CLI ───────────────────────────────────────────────────────────────────────────────────────────
|
|
321
316
|
|
|
322
|
-
const HELP = `coverage-check — the D3(c)+(d) final-run checker (agent-workflow family).
|
|
323
|
-
|
|
324
|
-
Usage:
|
|
325
|
-
node coverage-check.mjs --check [--cwd <dir>]
|
|
326
|
-
|
|
327
|
-
Reads the FIXED kit-owned lcov file (<git dir>/${LCOV_BASENAME}; AW_LCOV_FILE overrides —
|
|
328
|
-
produced by the declared unit-tests gate cmd's --experimental-test-coverage lcov reporters and
|
|
329
|
-
deleted fresh by run-gates --final), lists uncovered CHANGED executable Node lines file:line,
|
|
330
|
-
lists changed out-of-domain files (the coverage claim is narrowed to Node lines), and VERIFIES
|
|
331
|
-
every current-base red-proof record: bound test present, content hash unchanged, green N/N
|
|
332
|
-
(AW_CORE_EVIDENCE_RERUNS, default 3), pre-fix fingerprint differing from the current tree.
|
|
333
|
-
An absent lcov file (ENOENT) is a LOUD skipped-no-lcov (exit 0 — NO coverage check ran, stated).
|
|
334
|
-
Any other lcov status failure, a symlinked lcov path, an uncovered line, a broken red-proof
|
|
335
|
-
obligation, or a malformed evidence store fails (exit 1).
|
|
336
|
-
A changed file listed in ${COVERAGE_DECLARED_REL} (one { path, reason } entry per file nothing
|
|
337
|
-
runs at its repository path) with no executed line in the lcov read is not judged; it and every
|
|
338
|
-
other list line print on every run. An unreadable or malformed list fails (exit 1); with a context
|
|
339
|
-
the list must be the one the final run started with (AW_FINAL_ATTEST_DECLARED), else REFUSED.
|
|
340
|
-
|
|
341
|
-
A coverage VERDICT is issued ONLY inside the run that owns the artifact's lifetime: run-gates
|
|
342
|
-
--final deletes the lcov before any gate spawns and hands this checker an attestation context
|
|
343
|
-
(a nonce whose one-way commitment over {nonce, fingerprint, base} is the final-start attempt id).
|
|
344
|
-
One anchored machine line rides every run: coverage-check: attested=<yes|no>. It states whether a
|
|
345
|
-
coverage VERDICT was ISSUED — pass OR fail — never that coverage passed.
|
|
346
|
-
attested=yes → a verdict was issued over the lcov BYTES this run read (a failing one still
|
|
347
|
-
exits 1); the predicate is the consumed digest, never the skip flag.
|
|
348
|
-
attested=no → NO VERDICT: no handshake, or no lcov bytes were read at all (an absent file or a
|
|
349
|
-
refused path — nothing read, nothing certified). Withholding a verdict never
|
|
350
|
-
changes an exit code: an absent lcov stays exit 0, a refused non-regular path
|
|
351
|
-
keeps its own fail-closed exit 1, and uncovered lines still exit 1. Findings are
|
|
352
|
-
still printed; run-gates carries the withheld verdict as coverage=not-run.
|
|
353
|
-
REFUSED (exit 1) → the context describes another tree or another declared list, or matches no recorded attempt.
|
|
354
|
-
Residual, stated: ownership of the fixed path is CONVENTION, not enforcement — a concurrent writer
|
|
355
|
-
to it can still place foreign evidence (queued as LCOV-EXCLUSIVE-OWNERSHIP).
|
|
356
|
-
|
|
357
|
-
Sandbox-safe: no network; writes nothing; spawns read-only git queries and the bound-test
|
|
358
|
-
probes (node --test, shell-free) — the D4 sandbox lane. The attestation variables are consumed and
|
|
359
|
-
removed from this process's environment before anything spawns, so no child inherits the capability.
|
|
360
|
-
Read-only. Exit codes: 0 pass / no-verdict / skipped-loud; 1 fail or REFUSED; 2 usage.`;
|
|
361
|
-
|
|
362
317
|
export const main = (argv, ctx = {}) => {
|
|
318
|
+
if (argv.includes('--help') || argv.includes('-h')) return { code: 0, stdout: composeHelp(), stderr: '' };
|
|
363
319
|
const env = ctx.env ?? process.env;
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return { code, stdout: lines.join('\n'), stderr: '' };
|
|
379
|
-
} catch (err) {
|
|
380
|
-
return { code: err.exitCode ?? 1, stdout: '', stderr: `coverage-check: ${err.message}` };
|
|
381
|
-
}
|
|
320
|
+
const rest = [...argv];
|
|
321
|
+
const cwdAt = rest.indexOf('--cwd');
|
|
322
|
+
const refuseUsage = (failed) => ({
|
|
323
|
+
code: USAGE_EXIT_CODE,
|
|
324
|
+
stdout: composeUsageRefusal({ name: CHECKER_NAME, failed, usage: composeUsage() }).join(LINE_FEED),
|
|
325
|
+
stderr: '',
|
|
326
|
+
});
|
|
327
|
+
if (cwdAt !== NOT_FOUND && rest[cwdAt + 1] === undefined) return refuseUsage('--cwd needs a directory');
|
|
328
|
+
const cwd = cwdAt === NOT_FOUND ? ctx.cwd ?? process.cwd() : rest.splice(cwdAt, 2)[1];
|
|
329
|
+
const checkAt = rest.indexOf('--check');
|
|
330
|
+
if (checkAt !== NOT_FOUND) rest.splice(checkAt, 1);
|
|
331
|
+
if (rest.length > 0) return refuseUsage(`unknown argument: ${JSON.stringify(rest[0])}`);
|
|
332
|
+
const { code, lines } = runCheck({ cwd, env });
|
|
333
|
+
return { code, stdout: lines.join(LINE_FEED), stderr: '' };
|
|
382
334
|
};
|
|
383
335
|
|
|
384
336
|
if (isDirectRun(import.meta.url)) {
|
|
@@ -391,8 +343,6 @@ if (isDirectRun(import.meta.url)) {
|
|
|
391
343
|
.map((k) => [k, process.env[k]]),
|
|
392
344
|
);
|
|
393
345
|
for (const k of Object.keys(attest)) delete process.env[k];
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
if (r.stderr) process.stderr.write(r.stderr.endsWith('\n') ? r.stderr : `${r.stderr}\n`);
|
|
397
|
-
process.exitCode = r.code;
|
|
346
|
+
runCheckerTail({ name: CHECKER_NAME, exitCode: ERROR_EXIT_CODE, remedy: ERROR_REMEDY },
|
|
347
|
+
() => main(process.argv.slice(2), { env: { ...process.env, ...attest } }), process);
|
|
398
348
|
}
|
|
@@ -18,11 +18,10 @@ const HEX_RADIX = 16;
|
|
|
18
18
|
const ESCAPE_WIDTH = 4;
|
|
19
19
|
const ESCAPE_PADDING = '0';
|
|
20
20
|
const EMPTY_TEXT = '';
|
|
21
|
-
const CONFIG_FAILURE_PREFIX = `coverage-check: FAIL — ${COVERAGE_DECLARED_REL}: `;
|
|
22
21
|
const PASS_LINE = 'coverage-check: PASS — every changed Node line is covered';
|
|
23
22
|
|
|
24
23
|
const makeResult = (configFailure = null) => ({ configFailure, notJudged: [], lines: [], failures: [] });
|
|
25
|
-
const makeConfigFailure = (defect) => makeResult(
|
|
24
|
+
const makeConfigFailure = (defect) => makeResult(defect);
|
|
26
25
|
const renderAsciiLine = (value) => Array.from(String(value), (character) => {
|
|
27
26
|
const codePoint = character.codePointAt(ZERO);
|
|
28
27
|
return codePoint >= ASCII_FIRST && codePoint <= ASCII_LAST
|
|
@@ -55,7 +54,7 @@ export const judgeDeclaredList = ({ top, read, changed, spawn }) => {
|
|
|
55
54
|
continue;
|
|
56
55
|
}
|
|
57
56
|
if (probe.outcome === FOREIGN || probe.outcome === ERROR) {
|
|
58
|
-
result.failures.push(
|
|
57
|
+
result.failures.push({ path: entry.path, text: `listed in ${COVERAGE_DECLARED_REL} but not a regular file` });
|
|
59
58
|
continue;
|
|
60
59
|
}
|
|
61
60
|
if (changed === null) continue;
|
package/tools/gates-init.mjs
CHANGED
|
@@ -441,8 +441,8 @@ export const flowCheckCandidate = (cwd, deps = {}) => {
|
|
|
441
441
|
};
|
|
442
442
|
|
|
443
443
|
// The conditional SOURCE-SIZE candidate — keyed on the practice's own declaration rather than on a
|
|
444
|
-
// recipe: the gate is offered ONLY over a MINTED
|
|
445
|
-
//
|
|
444
|
+
// recipe: the gate is offered ONLY over a MINTED docs/ai/source-size.json past schema 1. Over an authored
|
|
445
|
+
// one the checker REFUSES by design, and a declared gate that refuses is a matrix
|
|
446
446
|
// this preview would have reddened on the user's behalf; a minted schema-1 one is withheld naming its
|
|
447
447
|
// --write-baseline move. A project that never declared the practice hears nothing here, while one
|
|
448
448
|
// that authored it and stopped short hears WHY the gate is not offered yet — the mint is the step it
|
|
@@ -468,7 +468,7 @@ export const sourceSizeCandidate = (cwd, deps = {}) => {
|
|
|
468
468
|
// The advice still follows the STATE: over an unminted record a hand-declared gate is red on
|
|
469
469
|
// every run, so pointing there would hand the reader their next failure as the way out.
|
|
470
470
|
const lane = state === 'minted'
|
|
471
|
-
? `${schema1 ? 'move the record
|
|
471
|
+
? `${schema1 ? 'move the record off schema 1 first — run source-size-check.mjs --write-baseline with the working directory set to this project, then ' : ''}declare the gate by hand`
|
|
472
472
|
: `mint the record first — run source-size-check.mjs --adopt --reason "${mintReasonOf(config)}" with the working directory set to this project, then declare the gate by hand`;
|
|
473
473
|
return {
|
|
474
474
|
candidate: null,
|
package/tools/now-render.mjs
CHANGED
|
@@ -133,7 +133,7 @@ const renderCampaignBlock = (block, color) => {
|
|
|
133
133
|
const lines = [getHeading(BLOCK_TITLE.campaign, color), ` state: ${block.state}`];
|
|
134
134
|
if (block.state !== 'absent') {
|
|
135
135
|
lines.push(` caps: ${block.maxLines} lines · ${block.maxLineBytes} bytes per line`);
|
|
136
|
-
lines.push(` roots: ${block.roots} · recorded files: ${getFigure(block.recordedFiles)}
|
|
136
|
+
lines.push(` roots: ${block.roots} · recorded files: ${getFigure(block.recordedFiles)}`);
|
|
137
137
|
}
|
|
138
138
|
return lines;
|
|
139
139
|
};
|
package/tools/procedures.mjs
CHANGED
|
@@ -536,9 +536,8 @@ const flowHalvesAdvice = (flow, probe) => {
|
|
|
536
536
|
// their reason ride EVERY named-activity render, so the plan's Module ledger is cut to them while the
|
|
537
537
|
// plan is being written. Composed from the project's live declaration, never from constants here.
|
|
538
538
|
// Each config state speaks as itself: ABSENT renders NOTHING (a project that declares no practice must
|
|
539
|
-
// not be handed invented limits); AUTHORED
|
|
540
|
-
//
|
|
541
|
-
// whole tree's debt); MINTED renders the recorded counts too.
|
|
539
|
+
// not be handed invented limits); AUTHORED renders the declared caps plus the honest "no file size is
|
|
540
|
+
// recorded yet" line; MINTED renders the recorded count too.
|
|
542
541
|
// A config that cannot be read renders ONE loud line carrying the reader's own message and the render
|
|
543
542
|
// still completes: the exit code for a broken source-size config belongs to the practice's own checker,
|
|
544
543
|
// while THIS tool's exit contract is about its own config and the engine.
|
|
@@ -554,14 +553,9 @@ const declaredPracticeAdvice = (cwd, readFile, lstat) => {
|
|
|
554
553
|
}
|
|
555
554
|
if (declaration.state === 'absent') return [];
|
|
556
555
|
const facts = practiceFacts(declaration.config);
|
|
557
|
-
// The two pre-mint states share a LANE (the ratchet holds nothing, the mint step is next) but not a
|
|
558
|
-
// FACT: an incomplete file carries half the machine record, so "no size is recorded" would be a
|
|
559
|
-
// plain untruth about it — it names the missing half instead. Neither ever prints minted counts.
|
|
560
556
|
// The mint step is named, not rendered: on a project path that does not survive double-quoting the
|
|
561
557
|
// checker deliberately withholds a paste-ready command, and this advisor never re-decides that.
|
|
562
|
-
const unmintedRecord =
|
|
563
|
-
? ` recorded: PARTIAL — the machine record is half-written (missing ${declaration.missingMachineKeys.map((key) => `"${key}"`).join(', ')}), so the ratchet holds nothing yet; run \`source-size-check.mjs --check\` for the mint step.`
|
|
564
|
-
: ' recorded: NOTHING YET — the caps are declared but no size is recorded, so the ratchet holds nothing; run `source-size-check.mjs --check` for the mint step.';
|
|
558
|
+
const unmintedRecord = ' recorded: NO FILE YET — the caps are declared but no file size is recorded, so the ratchet holds no file; run `source-size-check.mjs --check` for the mint step.';
|
|
565
559
|
// The five limits are the check's own lines, from the one function both renders read.
|
|
566
560
|
const { config } = declaration;
|
|
567
561
|
return [
|
|
@@ -571,9 +565,9 @@ const declaredPracticeAdvice = (cwd, readFile, lstat) => {
|
|
|
571
565
|
config.layout !== null
|
|
572
566
|
? ' layout: recorded — entries per directory, depth and files per root are judged by the size check.'
|
|
573
567
|
: ' layout: not recorded — `source-size-check.mjs --write-baseline --layout --reason "<text>"` starts it.',
|
|
574
|
-
...(config.schema === 1 ? [' schema 1: the check stops on it — `source-size-check.mjs --write-baseline` moves it
|
|
568
|
+
...(config.schema === 1 ? [' schema 1: the check stops on it — `source-size-check.mjs --write-baseline` moves it off schema 1.'] : []),
|
|
575
569
|
declaration.state === 'minted'
|
|
576
|
-
? ` recorded: ${facts.recordedFiles} file(s) carry a recorded size (debt, not permission)
|
|
570
|
+
? ` recorded: ${facts.recordedFiles} file(s) carry a recorded size (debt, not permission) — growth past a record takes a reasoned bump, and a record above the tree warns until the regeneration lowers it.`
|
|
577
571
|
: unmintedRecord,
|
|
578
572
|
` why: ${SOURCE_SIZE_WHY}`,
|
|
579
573
|
];
|
|
@@ -133,7 +133,7 @@ const HOOK_CHECKS_UNMANAGED_HOOK = 'an UNMANAGED pre-commit hook exists \u2014 t
|
|
|
133
133
|
const HOOK_CHECKS_WAIT = 'the layout line follows the source-size.layout record \u2014 apply that item first; this item\'s check line then arms the layout line too';
|
|
134
134
|
const HOOK_CHECKS_COMMAND = "the hook runs the kit's checks by flat paths this upgrade removes — once they are gone every commit stops until this item is applied";
|
|
135
135
|
const LAYOUT_RECORD_RECIPE = 'the hook is per clone and the config per branch: a branch or linked worktree with no size config is judged under the kit\'s values and stops on its piles until it takes the record (a hidden deployment\'s linked worktree carries none); one with an older config without layout is not judged on layout; one whose config is schema 1 or unminted stops every commit on that config\'s own stop until it takes the current config';
|
|
136
|
-
const REASON_AUTHOR_RECIPE = 'the reason is yours to write, with no question to the user: where you made the growth, say why this size is accepted; where an entry grew before this write (a
|
|
136
|
+
const REASON_AUTHOR_RECIPE = 'the reason is yours to write, with no question to the user: where you made the growth, say why this size is accepted; where an entry grew before this write (a raise after the schema move, a teammate\'s growth), write that it grew before this write and its cause was not recorded';
|
|
137
137
|
const SOURCE_SIZE_KEPT_WHAT = 'no source-size gate is declared — the size record is kept as it is; declaring the gate adds the size check to the gate matrix';
|
|
138
138
|
const LAYOUT_HELD = {
|
|
139
139
|
stops: () => 'the source-size check stops on this tree, so a layout record or layout line not yet in place waits \u2014 record that growth first with the reasoned --write-baseline its stop names, then re-run',
|
|
@@ -288,7 +288,7 @@ export const WHATS = Object.freeze({
|
|
|
288
288
|
'gates-inert.coverage-domain-narrow': 'certification covers the assessable minority only — {ext} dominate(s) the tracked tree, and the changed-line domain excludes them',
|
|
289
289
|
'source-size': 'no source-size gate is declared — the gate matrix runs no size check, so no gate run stops a file beyond its limits',
|
|
290
290
|
'source-size.unminted': 'the source-size gate is declared over an unminted record ({state}) — the check refuses it, or if absent judges layout alone, no line',
|
|
291
|
-
'source-size.schema-1': 'the source-size config is schema 1, which the check stops on — the writer moves it
|
|
291
|
+
'source-size.schema-1': 'the source-size config is schema 1, which the check stops on — the writer moves it off schema 1 in one write',
|
|
292
292
|
'source-size.layout': 'the layout record is not started — starting it records any directory already beyond the layout limits, so the commit hook can judge layout',
|
|
293
293
|
'source-size.piles': '{n} recorded pile(s) have no queue row planning their cleanup — one row each goes to the end of the queue\'s Later bucket',
|
|
294
294
|
'source-size.adopted-elsewhere': "the source-size gate runs a DIFFERENT copy of this checker ({n} declared) — adopted here, just not through this kit's own tool",
|
|
@@ -920,8 +920,8 @@ const probeSourceSize = ({ root, deps, add, skip, shared }) => {
|
|
|
920
920
|
const canonical = claims.filter((c) => c.claim === CHECKER_CLAIM.CANONICAL);
|
|
921
921
|
const elsewhere = claims.filter((c) => c.claim === CHECKER_CLAIM.ELSEWHERE);
|
|
922
922
|
if (canonical.length > 0 || elsewhere.length > 0) {
|
|
923
|
-
// A DECLARED gate is not the same fact as a working one: the checker refuses an authored
|
|
924
|
-
//
|
|
923
|
+
// A DECLARED gate is not the same fact as a working one: the checker refuses an authored
|
|
924
|
+
// record, so a gate declared over one reds the matrix on every run, and over an
|
|
925
925
|
// absent one it judges layout alone and no line. The declaration alone would report that deployment
|
|
926
926
|
// as adopted and say nothing about the one thing wrong with it. The split changes NOTHING here —
|
|
927
927
|
// the outcome, its attention class and its immunity to every ack are the same whichever copy runs.
|
|
@@ -31,16 +31,17 @@ root outside the kit's own folder ${KIT_FOLDER_ROOT} plus the spec store docs/ai
|
|
|
31
31
|
disk, and the files of each declared root.
|
|
32
32
|
|
|
33
33
|
A recorded entry is DEBT: a finding stops exactly when the regeneration would raise it, and a record
|
|
34
|
-
above the tree or gone warns until the regeneration lowers or removes it.
|
|
35
|
-
|
|
34
|
+
above the tree or gone warns until the regeneration lowers or removes it. No line sum over a root is
|
|
35
|
+
judged or recorded: an "aggregate" an earlier schema recorded warns on every check of a minted config and is dropped,
|
|
36
|
+
with no reason, by the next regeneration.
|
|
36
37
|
|
|
37
|
-
--write-baseline regenerates the machine keys (baseline,
|
|
38
|
-
|
|
38
|
+
--write-baseline regenerates the machine keys (baseline, and layout where it is judged) from the
|
|
39
|
+
tree and writes schema ${SOURCE_SIZE_SCHEMA}, on an absent config too. --layout starts the layout record on a
|
|
39
40
|
present config that has none. The authored keys keep their values and their order; the file is
|
|
40
41
|
canonically serialized. A regeneration that RAISES any recorded value needs --reason; the string is
|
|
41
|
-
recorded in the entry it raised. A pure tighten needs none. A
|
|
42
|
-
the same write
|
|
43
|
-
stops on
|
|
42
|
+
recorded in the entry it raised. A pure tighten needs none. A config of an earlier schema is moved in
|
|
43
|
+
the same write; a minted schema-1 one whose regeneration is refused is moved off schema 1 in a write
|
|
44
|
+
of its own, its records carried as they are; --check stops on schema 1 until it is moved.
|
|
44
45
|
|
|
45
46
|
--adopt is the ONE-line adoption: it mints the record and declares the source-size gate (and NOTHING
|
|
46
47
|
else) in docs/ai/gates.json. It is idempotent on an already-adopted project. With the config absent
|
|
@@ -80,8 +80,9 @@ export const limitLines = (limits, { escape = String, recorded = false } = {}) =
|
|
|
80
80
|
return `limit ${id} ${amount}, tolerance ${tolerance}% — ${source === 'kit' ? 'from kit' : `from override: ${escape(reason)}`}`;
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
// migrateSchema1(parsed, readmes) → the schema-2 config
|
|
84
|
-
// `_README` byte-equal to `readmes.schema1`
|
|
83
|
+
// migrateSchema1(parsed, readmes) → the schema-2 config, every key in its place; the writer writes it as
|
|
84
|
+
// it is only where the moved file holds the line sum. A `_README` byte-equal to `readmes.schema1`
|
|
85
|
+
// becomes `readmes.schema2`; any other is carried verbatim.
|
|
85
86
|
export const migrateSchema1 = (parsed, readmes = {}) => {
|
|
86
87
|
const overrides = Object.fromEntries(Object.entries(SCHEMA1_KEY)
|
|
87
88
|
.filter(([id, key]) => parsed.defaults[key] !== KIT_LIMITS[id].value)
|
|
@@ -94,6 +95,11 @@ export const migrateSchema1 = (parsed, readmes = {}) => {
|
|
|
94
95
|
}));
|
|
95
96
|
};
|
|
96
97
|
|
|
98
|
+
// atSchema(parsed, schema, { earlier, current }) → the config at `schema`, every key in its place: a
|
|
99
|
+
// `_README` byte-equal to one of the `earlier` template texts becomes `current`, any other is carried.
|
|
100
|
+
export const atSchema = (parsed, schema, { earlier = [], current } = {}) => Object.fromEntries(Object.entries(parsed)
|
|
101
|
+
.map(([key, value]) => [key, key === 'schema' ? schema : key === '_README' && earlier.includes(value) ? current : value]));
|
|
102
|
+
|
|
97
103
|
// applyOverride(parsed, id, override) → the config with one id's override set from { value,
|
|
98
104
|
// tolerance, reason } or, given null, removed; a `limits` left empty is dropped and a new one is
|
|
99
105
|
// appended. It judges nothing about the tree: the writer regenerates the record from the result.
|
|
@@ -29,11 +29,11 @@ const HELD_TEXT = {
|
|
|
29
29
|
};
|
|
30
30
|
const held = (reason, ...args) => ({ answer: 'held', reason, text: HELD_TEXT[reason](...args) });
|
|
31
31
|
|
|
32
|
-
// pilesOf(loaded) → [{ key, entries, value }]: each directory of a minted
|
|
32
|
+
// pilesOf(loaded) → [{ key, entries, value }]: each directory of a minted config's layout record whose
|
|
33
33
|
// recorded entries exceed the resolved entries-per-directory value plus its band, in the record's order.
|
|
34
34
|
export const pilesOf = (loaded) => {
|
|
35
35
|
const config = loaded?.state === 'minted' ? loaded.config : null;
|
|
36
|
-
if (config === null || config.schema
|
|
36
|
+
if (config === null || config.schema === 1 || config.layout === null) return [];
|
|
37
37
|
const { value, tolerance } = config.limits['entries-per-directory'];
|
|
38
38
|
return Object.entries(config.layout.directories)
|
|
39
39
|
.filter(([, record]) => Object.hasOwn(record, 'entries') && record.entries > value + bandOf(value, tolerance))
|
|
@@ -86,13 +86,11 @@ const layoutPlan = (recorded, projected) => {
|
|
|
86
86
|
// then two renderings of one computation.
|
|
87
87
|
export const planRecord = ({ config, verdict }) => {
|
|
88
88
|
const oldBaseline = config.baseline ?? {};
|
|
89
|
-
const oldAggregate = config.aggregate ?? {};
|
|
90
89
|
const files = verdict.scope.files.map((rel) => {
|
|
91
90
|
const next = verdict.projected.get(rel);
|
|
92
91
|
const recorded = ownEntry(oldBaseline, rel);
|
|
93
92
|
return { rel, next, recorded, changes: changesFor(rel, next, recorded) };
|
|
94
93
|
});
|
|
95
|
-
const roots = config.roots.map((root) => ({ root, lines: verdict.rootLines.get(root) ?? 0, recorded: ownEntry(oldAggregate, root) }));
|
|
96
94
|
const layout = verdict.layout ? layoutPlan(config.layout, verdict.layout.projected) : null;
|
|
97
95
|
const deltas = [
|
|
98
96
|
...files.flatMap(({ changes }) => changes),
|
|
@@ -101,30 +99,24 @@ export const planRecord = ({ config, verdict }) => {
|
|
|
101
99
|
...Object.entries(oldBaseline)
|
|
102
100
|
.filter(([rel]) => !verdict.measured.has(rel))
|
|
103
101
|
.flatMap(([rel, recorded]) => changesFor(rel, {}, recorded)),
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
.map(({ root, lines, recorded }) => ({ target: root, dimension: 'aggregate lines', from: recorded ? recorded.lines : null, to: lines })),
|
|
107
|
-
...Object.entries(oldAggregate)
|
|
108
|
-
.filter(([root]) => !config.roots.includes(root))
|
|
102
|
+
// A per-root line sum an earlier schema recorded is dropped whole, and the delta says so.
|
|
103
|
+
...Object.entries(config.aggregate ?? {})
|
|
109
104
|
.map(([root, recorded]) => ({ target: root, dimension: 'aggregate lines', from: recorded.lines, to: null })),
|
|
110
105
|
...(layout ? layout.deltas : []),
|
|
111
106
|
];
|
|
112
|
-
return { files,
|
|
107
|
+
return { files, layout, deltas, raises: deltas.filter(isRaise) };
|
|
113
108
|
};
|
|
114
109
|
|
|
115
110
|
const byKey = (entries) => Object.fromEntries(entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
116
111
|
|
|
117
112
|
// The reason of an entry the regeneration did NOT raise is the one already recorded — a tighten
|
|
118
113
|
// rewrites a number, never the human sentence that justified it.
|
|
119
|
-
export const materialize = ({ files,
|
|
114
|
+
export const materialize = ({ files, layout }, reason) => ({
|
|
120
115
|
baseline: Object.fromEntries(
|
|
121
116
|
files
|
|
122
117
|
.filter(({ next }) => Object.keys(next).length > 0)
|
|
123
118
|
.map(({ rel, next, recorded, changes }) => [rel, { ...next, reason: changes.some(isRaise) ? reason : recorded.reason }]),
|
|
124
119
|
),
|
|
125
|
-
aggregate: Object.fromEntries(
|
|
126
|
-
roots.map(({ root, lines, recorded }) => [root, { lines, reason: !recorded || lines > recorded.lines ? reason : recorded.reason }]),
|
|
127
|
-
),
|
|
128
120
|
...(layout === null ? {} : {
|
|
129
121
|
layout: {
|
|
130
122
|
roots: byKey(layout.roots.map(({ root, next, recorded }) => [root, { files: next, reason: !recorded || next > recorded.files ? reason : recorded.reason }])),
|
|
@@ -136,7 +128,8 @@ export const materialize = ({ files, roots, layout }, reason) => ({
|
|
|
136
128
|
// The file is CANONICALLY serialized: the authored VALUES and the ORDER the human wrote them in are
|
|
137
129
|
// preserved exactly, their formatting is not — this file is machine-maintained and the writer owns
|
|
138
130
|
// half of it, so one deterministic rendering is what makes "regenerate an unchanged tree and get the
|
|
139
|
-
// same bytes" true at all. The machine keys follow in their fixed order
|
|
131
|
+
// same bytes" true at all. The machine keys follow in their fixed order; `aggregate` is dropped
|
|
132
|
+
// with them and written back only by the schema-1 move, which carries it.
|
|
140
133
|
export const serialize = (parsed, machine) => {
|
|
141
134
|
const authored = Object.fromEntries(Object.entries(parsed).filter(([key]) => !MACHINE_KEYS.includes(key)));
|
|
142
135
|
return `${JSON.stringify({ ...authored, ...machine }, null, 2)}\n`;
|
|
@@ -10,12 +10,12 @@ import { SPEC_STORE_ROOT } from './layout.mjs';
|
|
|
10
10
|
export const SETUP_ANSWERS = Object.freeze(['armable', 'record', 'held']);
|
|
11
11
|
|
|
12
12
|
// checkTargetOf({ loaded, absentConfig }) → exactly one of: the schema-1 stop, the unminted stop (a
|
|
13
|
-
// present config
|
|
13
|
+
// present config with no file record), or the config to judge with the dimensions judged.
|
|
14
14
|
export const checkTargetOf = ({ loaded, absentConfig }) => {
|
|
15
15
|
const absent = loaded.state === 'absent';
|
|
16
16
|
const config = absent ? absentConfig : loaded.config;
|
|
17
17
|
if (config.schema === 1) return { stop: 'schema-1', config };
|
|
18
|
-
if (!absent && loaded.state !== 'minted') return { stop: 'unminted', config, state: loaded.state
|
|
18
|
+
if (!absent && loaded.state !== 'minted') return { stop: 'unminted', config, state: loaded.state };
|
|
19
19
|
return { stop: null, config, judged: { absent, layout: absent || config.layout !== null } };
|
|
20
20
|
};
|
|
21
21
|
|