@sabaiway/agent-workflow-kit 23.5.0 → 23.7.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 +43 -0
- package/README.md +2 -2
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/modes/commit-guard.md +1 -1
- package/references/modes/coverage-check.md +1 -1
- package/references/modes/gates.md +3 -3
- package/tools/commands.mjs +1 -1
- package/tools/commit-guard.mjs +10 -4
- package/tools/core-evidence-store-read.mjs +4 -0
- package/tools/coverage-check.mjs +40 -26
- package/tools/coverage-declared/config.mjs +186 -0
- package/tools/coverage-declared/index.mjs +2 -0
- package/tools/coverage-declared/judge.mjs +88 -0
- package/tools/doc-parity.mjs +8 -1
- package/tools/run-gates.mjs +33 -13
- package/tools/source-size/help.mjs +55 -0
- package/tools/source-size/index.mjs +4 -0
- package/tools/source-size-check.mjs +37 -16
- package/tools/source-size-core.mjs +1 -0
- package/tools/source-size-report.mjs +65 -93
- package/tools/tracked-tree-census.mjs +8 -4
|
@@ -19,7 +19,7 @@ import { SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_WARNING_PREFIX, SOURCE_SIZE_WHY, co
|
|
|
19
19
|
import { INITIAL_ADOPTION_REASON, KIT_FOLDER_ROOT, SOURCE_SIZE_SCHEMA, practiceFacts } from './source-size-config.mjs';
|
|
20
20
|
import { SOURCE_SIZE_TOOL_PATH, dqUnsafePath } from './source-size-gate-cmd.mjs';
|
|
21
21
|
import { hasLoweredRecord, hasStoreRecord, stopsOf, warningsOf } from './source-size-judge.mjs';
|
|
22
|
-
import { isRaise, limitLines } from './source-size/index.mjs';
|
|
22
|
+
import { helpText, isRaise, limitLines } from './source-size/index.mjs';
|
|
23
23
|
|
|
24
24
|
// The project directory is project-controlled too, so the path every refusal names enters its line
|
|
25
25
|
// escaped like any other such value. configPathFor itself stays literal — it also builds the real
|
|
@@ -87,11 +87,8 @@ const regenerator = (cwd, reason, layout = false) => rendered(cwd, layout ? '--w
|
|
|
87
87
|
|
|
88
88
|
const SPLIT_QUALITY_FOCUS = 'source-size: REVIEW FOCUS — a recorded size went DOWN or disappeared: check that this is real decomposition and not the same coupling spread across more files (paste this line into the review dispatch focus).';
|
|
89
89
|
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
// unmerged index, an empty declared scope) and the exit-2 config, usage and enumeration errors: both
|
|
93
|
-
// are about a tree the practice could not judge at all, where a sentence about module size explains
|
|
94
|
-
// nothing.
|
|
90
|
+
// Rendered refusals close with WHY. Thrown stops and usage refusals carry no WHY line; the command
|
|
91
|
+
// line composes them, each with the remedy of its exit class (usage carries only its help lines).
|
|
95
92
|
const WHY_LINE = `source-size: WHY — ${SOURCE_SIZE_WHY}`;
|
|
96
93
|
const refusal = (lines) => [...lines, WHY_LINE];
|
|
97
94
|
|
|
@@ -112,17 +109,31 @@ export const absentRefusalLines = (cwd) => refusal([
|
|
|
112
109
|
// Both not-yet-MINTED states route to the same lane — the regenerator writes the machine half — so
|
|
113
110
|
// they differ only in what they say happened: AUTHORED is the state a human creates, INCOMPLETE is a
|
|
114
111
|
// machine half no regenerator produces, which means the file was hand-edited into it.
|
|
112
|
+
const unmintedSentence = (cwd, { state, missing }) => state === 'incomplete'
|
|
113
|
+
? `${namedConfig(cwd)} is INCOMPLETE: it carries a machine half no regenerator produces (missing ${missing.map((key) => `"${key}"`).join(', ')}), so the ratchet holds only part of this tree.`
|
|
114
|
+
: `${namedConfig(cwd)} is AUTHORED but not yet MINTED (it records no size yet), so there is nothing for the ratchet to hold.`;
|
|
115
|
+
const MINT_LINE = 'Mint it — the regenerator records what this tree already carries; recording a value for the first time is a raise, so it takes a reason';
|
|
116
|
+
const UNMINTED_LANE = `Run source-size-check.mjs --write-baseline --reason "${INITIAL_ADOPTION_REASON}" with the working directory set to this project.`;
|
|
117
|
+
|
|
115
118
|
export const unmintedRefusalLines = (cwd, { state, missing }) => {
|
|
116
119
|
const { command, withheld } = regenerator(cwd, INITIAL_ADOPTION_REASON);
|
|
117
120
|
return refusal([
|
|
118
|
-
state
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
'Mint it — the regenerator records what this tree already carries; recording a value for the first time is a raise, so it takes a reason:',
|
|
122
|
-
command === null ? `${withheld} Run source-size-check.mjs --write-baseline --reason "${INITIAL_ADOPTION_REASON}" with the working directory set to this project.` : ` ${command}`,
|
|
121
|
+
`source-size: REFUSED — ${unmintedSentence(cwd, { state, missing })}`,
|
|
122
|
+
`${MINT_LINE}:`,
|
|
123
|
+
command === null ? `${withheld} ${UNMINTED_LANE}` : ` ${command}`,
|
|
123
124
|
]);
|
|
124
125
|
};
|
|
125
126
|
|
|
127
|
+
export const unmintedStopBlock = (cwd, { state, missing }) => {
|
|
128
|
+
const { command, withheld } = regenerator(cwd, INITIAL_ADOPTION_REASON);
|
|
129
|
+
return {
|
|
130
|
+
failed: escapeLeadingSpace(unmintedSentence(cwd, { state, missing }).slice(0, -1)),
|
|
131
|
+
findings: [{ place: SOURCE_SIZE_CONFIG_REL, text: MINT_LINE }],
|
|
132
|
+
remedies: [command ?? UNMINTED_LANE],
|
|
133
|
+
after: refusal(command === null ? [withheld] : []),
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
126
137
|
// Every finding names a path or a root the PROJECT chose, and each one crosses the line-safety
|
|
127
138
|
// boundary ONCE — in lineSafeFinding, before any branch sees it. Nine branches each remembering to
|
|
128
139
|
// escape would be nine chances to forget, and the tenth branch nobody has written yet would start
|
|
@@ -183,17 +194,36 @@ const suggestedEntryLines = (verdict) => {
|
|
|
183
194
|
});
|
|
184
195
|
};
|
|
185
196
|
|
|
186
|
-
|
|
187
|
-
|
|
197
|
+
export const escapeLeadingSpace = (text) => text.replace(/^ /, '\\u0020');
|
|
198
|
+
|
|
199
|
+
const findingPart = (finding) => {
|
|
200
|
+
const safe = lineSafeFinding(finding);
|
|
201
|
+
const place = safe.rel ?? safe.root ?? safe.dir;
|
|
202
|
+
const line = FINDING_LINE[finding.kind](safe);
|
|
203
|
+
const ownPlace = place === '.' || (place !== 'source-size' && !place.startsWith(' ')
|
|
204
|
+
&& !/[\\:]/.test(place) && place.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..'));
|
|
205
|
+
return { place: ownPlace ? place : '.', text: escapeLeadingSpace(ownPlace ? line.slice(place.length + 2) : line) };
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const emptyRootLines = (verdict) => verdict.scope.emptyRoots.map((rel) =>
|
|
209
|
+
`source-size: NOTE — the declared root "${escapeForLine(rel)}" matches no tracked file with a declared extension${verdict.scope.kitFolderRoots.includes(rel) ? ` outside the kit's own folder ${KIT_FOLDER_ROOT}` : ''}`);
|
|
210
|
+
|
|
211
|
+
export const checkStopBlock = ({ cwd, verdict, absent = false }) => {
|
|
212
|
+
const stops = stopsOf(verdict.findings);
|
|
213
|
+
const warnings = warningsOf(verdict.findings);
|
|
188
214
|
const entries = suggestedEntryLines(verdict);
|
|
189
215
|
const { command, withheld } = regenerator(cwd, GROWTH_REASON_PLACEHOLDER);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
216
|
+
return {
|
|
217
|
+
failed: escapeLeadingSpace(`${stops.length} finding(s) ${absent ? `under the kit's values (${namedConfig(cwd)} is absent)` : `against ${namedConfig(cwd)}`}`),
|
|
218
|
+
findings: stops.map(findingPart),
|
|
219
|
+
remedies: [command ?? WITHHELD_LANE],
|
|
220
|
+
after: refusal([
|
|
221
|
+
...emptyRootLines(verdict), ...warningLines(warnings),
|
|
222
|
+
...(command === null ? [withheld] : ['This regeneration RAISES a recorded value, so the reason is REQUIRED — it is recorded in the entry it raises, and it is what the commit message and the CHANGELOG restate.']),
|
|
223
|
+
...(command !== null && entries.length > 0 ? ['Or record each size by hand under "baseline" — the validator accepts exactly these bytes:'] : []),
|
|
224
|
+
...entries, ...(hasLoweredRecord(warnings) ? [SPLIT_QUALITY_FOCUS] : []),
|
|
225
|
+
]),
|
|
226
|
+
};
|
|
197
227
|
};
|
|
198
228
|
|
|
199
229
|
// A lowered or removed record warns with the paste-ready regeneration, which needs no reason.
|
|
@@ -202,27 +232,18 @@ const tightenLine = (cwd) => {
|
|
|
202
232
|
return `${SOURCE_SIZE_WARNING_PREFIX}a record above is lower or gone, so regenerating lowers or removes it with no reason: ${command ?? `${withheld} ${WITHHELD_LANE}`}`;
|
|
203
233
|
};
|
|
204
234
|
|
|
205
|
-
//
|
|
235
|
+
// A passing check keeps its notes, warnings and green line in that order.
|
|
206
236
|
export const checkReportLines = ({ cwd, config, verdict, absent = false }) => {
|
|
207
|
-
const lines = verdict
|
|
208
|
-
`source-size: NOTE — the declared root "${escapeForLine(rel)}" matches no tracked file with a declared extension${verdict.scope.kitFolderRoots.includes(rel) ? ` outside the kit's own folder ${KIT_FOLDER_ROOT}` : ''}`);
|
|
209
|
-
const stops = stopsOf(verdict.findings);
|
|
237
|
+
const lines = emptyRootLines(verdict);
|
|
210
238
|
const warnings = warningsOf(verdict.findings);
|
|
211
239
|
lines.push(...warningLines(warnings));
|
|
212
240
|
const lowered = hasLoweredRecord(warnings);
|
|
213
|
-
if (
|
|
214
|
-
if (lowered || hasStoreRecord(warnings)) lines.push(tightenLine(cwd));
|
|
215
|
-
if (lowered) lines.push(SPLIT_QUALITY_FOCUS);
|
|
216
|
-
lines.push(warnings.length === 0
|
|
217
|
-
? `source-size: PASS — ${verdict.scope.files.length} in-scope file(s) within the declared caps`
|
|
218
|
-
: `source-size: PASS with ${warnings.length} warning(s) — ${verdict.scope.files.length} in-scope file(s) judged and nothing beyond a band or a record; each warning above repeats on every run until it is settled`);
|
|
219
|
-
return absent ? lines : [...lines, practiceLine(config)];
|
|
220
|
-
}
|
|
221
|
-
lines.push(`source-size: FAIL — ${stops.length} finding(s) ${absent ? `under the kit's values (${namedConfig(cwd)} is absent)` : `against ${namedConfig(cwd)}`}:`);
|
|
222
|
-
for (const finding of stops) lines.push(` ${FINDING_LINE[finding.kind](lineSafeFinding(finding))}`);
|
|
223
|
-
lines.push(...servableStep(cwd, verdict));
|
|
241
|
+
if (lowered || hasStoreRecord(warnings)) lines.push(tightenLine(cwd));
|
|
224
242
|
if (lowered) lines.push(SPLIT_QUALITY_FOCUS);
|
|
225
|
-
|
|
243
|
+
lines.push(warnings.length === 0
|
|
244
|
+
? `source-size: PASS — ${verdict.scope.files.length} in-scope file(s) within the declared caps`
|
|
245
|
+
: `source-size: PASS with ${warnings.length} warning(s) — ${verdict.scope.files.length} in-scope file(s) judged and nothing beyond a band or a record; each warning above repeats on every run until it is settled`);
|
|
246
|
+
return absent ? lines : [...lines, practiceLine(config)];
|
|
226
247
|
};
|
|
227
248
|
|
|
228
249
|
// The delta is the DURABLE RECORD on a deployment whose docs/ai is git-hidden: it is what the commit
|
|
@@ -247,11 +268,14 @@ export const reasonRequiredLines = (cwd, deltas, { layout = false } = {}) => {
|
|
|
247
268
|
// ── schema 1 and --override ───────────────────────────────────────────────────────────────────────
|
|
248
269
|
|
|
249
270
|
// The check no longer judges schema 1: it names the one move, which the writer makes in its one write.
|
|
250
|
-
export const
|
|
271
|
+
export const schema1StopBlock = (cwd) => {
|
|
251
272
|
const { command, withheld } = regenerator(cwd);
|
|
252
|
-
return
|
|
253
|
-
|
|
254
|
-
|
|
273
|
+
return {
|
|
274
|
+
failed: escapeLeadingSpace(`${namedConfig(cwd)} is schema 1, which the check no longer judges`),
|
|
275
|
+
findings: [{ place: SOURCE_SIZE_CONFIG_REL, text: '--write-baseline moves it to schema 2 in its one write (a raise riding it still takes --reason)' }],
|
|
276
|
+
remedies: [command ?? 'Run source-size-check.mjs --write-baseline with the working directory set to this project.'],
|
|
277
|
+
after: refusal(command === null ? [withheld] : []),
|
|
278
|
+
};
|
|
255
279
|
};
|
|
256
280
|
|
|
257
281
|
// Claims only what holds of every written file.
|
|
@@ -343,56 +367,4 @@ export const writtenLines = ({ cwd, deltas, reason, changed }) => {
|
|
|
343
367
|
|
|
344
368
|
// ── --help ────────────────────────────────────────────────────────────────────────────────────────
|
|
345
369
|
|
|
346
|
-
export const HELP =
|
|
347
|
-
|
|
348
|
-
Usage:
|
|
349
|
-
node source-size-check.mjs --check [--cwd <project-root>]
|
|
350
|
-
node source-size-check.mjs --write-baseline [--layout] [--reason "<text>"] [--cwd <project-root>]
|
|
351
|
-
node source-size-check.mjs --adopt [--reason "<text>"] [--cwd <project-root>]
|
|
352
|
-
node source-size-check.mjs --override <id> [--value <n>] [--tolerance <p>] --reason "<text>" [--cwd <project-root>]
|
|
353
|
-
node source-size-check.mjs --override <id> --kit-default --reason "<text>" [--cwd <project-root>]
|
|
354
|
-
|
|
355
|
-
Judges every in-scope file against ${SOURCE_SIZE_CONFIG_REL} (schema ${SOURCE_SIZE_SCHEMA}): git-tracked files
|
|
356
|
-
under a declared root carrying a declared extension, minus the excluded path-segment prefixes and
|
|
357
|
-
the kit's own folder ${KIT_FOLDER_ROOT}, which nothing here judges and no root may declare. An
|
|
358
|
-
absent "roots" is the one root ".", every tracked path; a config declaring no extension judges no
|
|
359
|
-
file, and every check says so. With the config absent the check judges layout alone under the
|
|
360
|
-
kit's values. Symlinks and submodule gitlinks are skipped by kind; an unmerged index, a non-UTF-8
|
|
361
|
-
in-scope path, an unverifiable in-scope file and an empty declared scope are refusals.
|
|
362
|
-
|
|
363
|
-
Limits: the kit's own five, kept in its code, each with a tolerance; the config holds only a
|
|
364
|
-
project's reasoned overrides under "limits". A value at or under its limit is clean, above it within
|
|
365
|
-
the band ceil(value x tolerance / 100) a WARNING printed on every run (exit 0), and beyond the band a
|
|
366
|
-
stop unless a record holds it. Every --check, --write-baseline and --override run that resolves the
|
|
367
|
-
config and ends in no usage, config, enumeration or scope error states all five limits with value,
|
|
368
|
-
tolerance and source, then what it does not judge, then its warnings, then its stops.
|
|
369
|
-
|
|
370
|
-
Counting: lines, and the longest line in BYTES. A terminator never counts (the CR of a CRLF
|
|
371
|
-
included); a last line with no final newline still counts; an empty file is 0 lines. Layout: the
|
|
372
|
-
entries of each directory and its depth below its root, over every tracked entry under a declared
|
|
373
|
-
root outside the kit's own folder ${KIT_FOLDER_ROOT} plus the spec store docs/ai/specs walked from
|
|
374
|
-
disk, and the files of each declared root.
|
|
375
|
-
|
|
376
|
-
A recorded entry is DEBT: a finding stops exactly when the regeneration would raise it, and a record
|
|
377
|
-
above the tree or gone warns until the regeneration lowers or removes it. Each declared root carries
|
|
378
|
-
the same exact ratchet over its summed lines.
|
|
379
|
-
|
|
380
|
-
--write-baseline regenerates the machine keys (baseline, aggregate, and layout where it is judged)
|
|
381
|
-
from the tree; on an absent config it writes a schema-2 one. --layout starts the layout record on a
|
|
382
|
-
present config that has none. The authored keys keep their values and their order; the file is
|
|
383
|
-
canonically serialized. A regeneration that RAISES any recorded value needs --reason; the string is
|
|
384
|
-
recorded in the entry it raised. A pure tighten needs none. A schema-1 config is moved to schema 2 in
|
|
385
|
-
the same write; --check stops on one until it is.
|
|
386
|
-
|
|
387
|
-
--adopt is the ONE-line adoption: it mints the record and declares the source-size gate (and NOTHING
|
|
388
|
-
else) in docs/ai/gates.json. It is idempotent on an already-adopted project. With the config absent
|
|
389
|
-
it refuses with the exact file to author. A refused declaration exits nonzero and reports both
|
|
390
|
-
halves: what was minted and what was not declared.
|
|
391
|
-
|
|
392
|
-
--override writes one override of a kit limit (lines-per-file, bytes-per-line, entries-per-directory,
|
|
393
|
-
depth: --value and/or --tolerance; files-per-root: --tolerance only), or with --kit-default removes
|
|
394
|
-
it; an option left out keeps the limit's current value or tolerance, and --reason is mandatory. It
|
|
395
|
-
runs only once regenerating the record under the current limits would raise nothing, and
|
|
396
|
-
regenerates the record in the same write.
|
|
397
|
-
|
|
398
|
-
Exit codes: 0 green, warnings included; 1 a stop or a refusal; 2 usage, config or enumeration error.`;
|
|
370
|
+
export const HELP = helpText({ SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_SCHEMA, KIT_FOLDER_ROOT });
|
|
@@ -43,8 +43,11 @@ const splitOnNul = (buffer) => {
|
|
|
43
43
|
return parts;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const
|
|
47
|
-
|
|
46
|
+
const TRACKED_PATH_ARGS = ['ls-files', '-z'];
|
|
47
|
+
const ALL_NAMED_PATH_ARGS = ['ls-files', '-z', '--cached', '--others', '--exclude-standard'];
|
|
48
|
+
export const listGitNamedPaths = (root, { untracked = false, spawn = spawnSync } = {}) => {
|
|
49
|
+
const args = untracked ? ALL_NAMED_PATH_ARGS : TRACKED_PATH_ARGS;
|
|
50
|
+
const result = spawn('git', args, { cwd: root, maxBuffer: GIT_MAX_BUFFER, windowsHide: true });
|
|
48
51
|
if (result.error || result.status !== 0) {
|
|
49
52
|
const reason = result.error ? (result.error.code ?? result.error.message) : `git exited ${result.status}`;
|
|
50
53
|
throw Object.assign(new Error(`tracked-tree census unavailable: ${reason}`), { code: 'CENSUS_UNAVAILABLE' });
|
|
@@ -57,7 +60,7 @@ const listTrackedPaths = (root, spawn) => {
|
|
|
57
60
|
const identity = part.toString('latin1'); // byte-exact key: one char per byte, never lossy
|
|
58
61
|
if (seenBytes.has(identity)) continue;
|
|
59
62
|
seenBytes.add(identity);
|
|
60
|
-
paths.push(part
|
|
63
|
+
paths.push(part);
|
|
61
64
|
}
|
|
62
65
|
return paths;
|
|
63
66
|
};
|
|
@@ -76,7 +79,8 @@ const listTrackedPaths = (root, spawn) => {
|
|
|
76
79
|
export const takeCensus = (root, { spawn = spawnSync } = {}) => {
|
|
77
80
|
const counts = { assessable: 0, unsupported: 0, 'out-of-domain': 0, 'excluded-test': 0 };
|
|
78
81
|
const unsupportedExtensions = new Set();
|
|
79
|
-
for (const
|
|
82
|
+
for (const name of listGitNamedPaths(root, { spawn })) {
|
|
83
|
+
const path = name.toString('utf8');
|
|
80
84
|
const kind = classifyChangedPath(path);
|
|
81
85
|
counts[kind] += 1;
|
|
82
86
|
if (kind === 'unsupported') {
|