@sabaiway/agent-workflow-kit 23.6.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 +22 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- 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/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,28 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
|
|
|
4
4
|
is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
|
|
5
5
|
every `migrations/<version>-<slug>.md` newer than it, in semver order.
|
|
6
6
|
|
|
7
|
+
## 23.7.0 — a failed size check shows what failed and the fix first (AD-235)
|
|
8
|
+
|
|
9
|
+
**After `/agent-workflow-kit upgrade`, a red `source-size-check.mjs --check` run opens with its failure, and so do, in
|
|
10
|
+
every mode, a tree the check cannot judge, a config error, a usage refusal and an unexpected error.** Before, a `--check`
|
|
11
|
+
that stopped printed the five limit lines, the notes and the warnings first, and the findings came last, indented under
|
|
12
|
+
a FAIL line; a refusal of the tree, the config or the command line went to standard error, apart from everything else.
|
|
13
|
+
|
|
14
|
+
- **A stop leads with three parts:** `source-size: FAIL — <what failed>`, each finding at column one starting with its
|
|
15
|
+
file or folder, and `source-size: REMEDY — <the command that fixes it>` (where the command cannot be printed safely,
|
|
16
|
+
the way to run it by hand). The limits, the not-judged notes, the warnings and the hand-record lines follow, in
|
|
17
|
+
their old order.
|
|
18
|
+
- **Every red output goes to standard output**, standard error stays empty: a file past its cap, a schema-1 or
|
|
19
|
+
unminted config, a tree the check cannot judge, a config error and a usage refusal of any mode.
|
|
20
|
+
- **The refusals the writing modes print themselves keep their lines**, as before — among them `--write-baseline`
|
|
21
|
+
raising a record without `--reason`, `--override` on a record the tree outgrew, and `--adopt` or `--override` on an
|
|
22
|
+
absent config. `--adopt` on a record the tree outgrew prints the check's new block, after any schema-1 move it wrote,
|
|
23
|
+
then that the gate was not declared.
|
|
24
|
+
- **An unexpected error exits 2** (it exited 1) and prints `source-size: FAIL — unexpected error: <its message>`, a
|
|
25
|
+
REMEDY line and the stack.
|
|
26
|
+
- **`--help`** states the new order and the new exit code. Every other run that exits 0 prints what it printed
|
|
27
|
+
before, and every other exit code is unchanged.
|
|
28
|
+
|
|
7
29
|
## 23.6.0 — a changed file that a test runs elsewhere can be committed through the final run (AD-234)
|
|
8
30
|
|
|
9
31
|
**After `/agent-workflow-kit upgrade`, a project can list in `docs/ai/coverage-declared.json` the changed files that
|
package/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: agent-workflow-kit
|
|
|
3
3
|
description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow". New to the epic, story and task tier? Run `/agent-workflow-kit tier`. A typed decision with a confidence from Jev? Run `/agent-workflow-kit jev`.
|
|
4
4
|
disable-model-invocation: true
|
|
5
5
|
metadata:
|
|
6
|
-
version: '23.
|
|
6
|
+
version: '23.7.0'
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# agent-workflow-kit
|
package/capability.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sabaiway/agent-workflow-kit",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.7.0",
|
|
4
4
|
"description": "Portable, cross-agent memory & workflow for AI coding agents — Claude Code, Codex, Cursor, Devin Desktop. One command deploys an AGENTS.md entry point + docs/ai context with cap/archive/index enforcement into any repo.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export const helpText = ({ SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_SCHEMA, KIT_FOLDER_ROOT }) => `source-size-check — the declared source-size practice (agent-workflow family).
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
node source-size-check.mjs --check [--cwd <project-root>]
|
|
5
|
+
node source-size-check.mjs --write-baseline [--layout] [--reason "<text>"] [--cwd <project-root>]
|
|
6
|
+
node source-size-check.mjs --adopt [--reason "<text>"] [--cwd <project-root>]
|
|
7
|
+
node source-size-check.mjs --override <id> [--value <n>] [--tolerance <p>] --reason "<text>" [--cwd <project-root>]
|
|
8
|
+
node source-size-check.mjs --override <id> --kit-default --reason "<text>" [--cwd <project-root>]
|
|
9
|
+
|
|
10
|
+
Judges every in-scope file against ${SOURCE_SIZE_CONFIG_REL} (schema ${SOURCE_SIZE_SCHEMA}): git-tracked files
|
|
11
|
+
under a declared root carrying a declared extension, minus the excluded path-segment prefixes and
|
|
12
|
+
the kit's own folder ${KIT_FOLDER_ROOT}, which nothing here judges and no root may declare. An
|
|
13
|
+
absent "roots" is the one root ".", every tracked path; a config declaring no extension judges no
|
|
14
|
+
file, and every check says so. With the config absent the check judges layout alone under the
|
|
15
|
+
kit's values. Symlinks and submodule gitlinks are skipped by kind; an unmerged index, a non-UTF-8
|
|
16
|
+
in-scope path, an unverifiable in-scope file and an empty declared scope are refusals.
|
|
17
|
+
|
|
18
|
+
Limits: the kit's own five, kept in its code, each with a tolerance; the config holds only a
|
|
19
|
+
project's reasoned overrides under "limits". A value at or under its limit is clean, above it within
|
|
20
|
+
the band ceil(value x tolerance / 100) a WARNING printed on every run (exit 0), and beyond the band a
|
|
21
|
+
stop unless a record holds it. Every --check, --write-baseline and --override run that resolves the
|
|
22
|
+
config and ends in no usage, config, enumeration or scope error states all five limits with value,
|
|
23
|
+
tolerance and source, then what it does not judge, then its warnings, then its stops; a --check that
|
|
24
|
+
stops opens instead with its verdict line, its findings and its remedy, its limits, notes and warnings
|
|
25
|
+
after them.
|
|
26
|
+
|
|
27
|
+
Counting: lines, and the longest line in BYTES. A terminator never counts (the CR of a CRLF
|
|
28
|
+
included); a last line with no final newline still counts; an empty file is 0 lines. Layout: the
|
|
29
|
+
entries of each directory and its depth below its root, over every tracked entry under a declared
|
|
30
|
+
root outside the kit's own folder ${KIT_FOLDER_ROOT} plus the spec store docs/ai/specs walked from
|
|
31
|
+
disk, and the files of each declared root.
|
|
32
|
+
|
|
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. Each declared root carries
|
|
35
|
+
the same exact ratchet over its summed lines.
|
|
36
|
+
|
|
37
|
+
--write-baseline regenerates the machine keys (baseline, aggregate, and layout where it is judged)
|
|
38
|
+
from the tree; on an absent config it writes a schema-2 one. --layout starts the layout record on a
|
|
39
|
+
present config that has none. The authored keys keep their values and their order; the file is
|
|
40
|
+
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 schema-1 config is moved to schema 2 in
|
|
42
|
+
the same write; --check stops on one until it is.
|
|
43
|
+
|
|
44
|
+
--adopt is the ONE-line adoption: it mints the record and declares the source-size gate (and NOTHING
|
|
45
|
+
else) in docs/ai/gates.json. It is idempotent on an already-adopted project. With the config absent
|
|
46
|
+
it refuses with the exact file to author. A refused declaration exits nonzero and reports both
|
|
47
|
+
halves: what was minted and what was not declared.
|
|
48
|
+
|
|
49
|
+
--override writes one override of a kit limit (lines-per-file, bytes-per-line, entries-per-directory,
|
|
50
|
+
depth: --value and/or --tolerance; files-per-root: --tolerance only), or with --kit-default removes
|
|
51
|
+
it; an option left out keeps the limit's current value or tolerance, and --reason is mandatory. It
|
|
52
|
+
runs only once regenerating the record under the current limits would raise nothing, and
|
|
53
|
+
regenerates the record in the same write.
|
|
54
|
+
|
|
55
|
+
Exit codes: 0 green, warnings included; 1 a stop or a refusal; 2 usage, config or enumeration error, or an unexpected error.`;
|
|
@@ -29,10 +29,11 @@
|
|
|
29
29
|
// removes one reasoned override of a kit limit and regenerates the machine keys under the new limits
|
|
30
30
|
// in the same write. Every write here moves a schema-1 config to schema 2; --check stops on one.
|
|
31
31
|
//
|
|
32
|
-
// Exit codes: 0 green / 1 violation or refusal / 2 usage, config or enumeration error.
|
|
32
|
+
// Exit codes: 0 green / 1 violation or refusal / 2 usage, config or enumeration error, or an unexpected error.
|
|
33
33
|
// Dependency-free, Node >= 22. No side effects on import.
|
|
34
34
|
|
|
35
35
|
import { resolve } from 'node:path';
|
|
36
|
+
import { composeRedBlock, composeUsageRefusal, guardChecker } from '../references/scripts/shared/index.mjs';
|
|
36
37
|
import { assertDocsAiDeployment, writeDocsAiFileAtomic } from './atomic-write.mjs';
|
|
37
38
|
import { isDirectRun, sameFile } from './direct-run.mjs';
|
|
38
39
|
import {
|
|
@@ -42,7 +43,7 @@ import {
|
|
|
42
43
|
SOURCE_SIZE_SCHEMA,
|
|
43
44
|
applyOverride,
|
|
44
45
|
assertNoStoreRoot,
|
|
45
|
-
checkTargetOf,
|
|
46
|
+
checkTargetOf, escapeForLine,
|
|
46
47
|
isRaise,
|
|
47
48
|
loadSourceSizeConfig,
|
|
48
49
|
matchesSourceSizeGate,
|
|
@@ -63,7 +64,7 @@ import {
|
|
|
63
64
|
TEMPLATE_READMES,
|
|
64
65
|
absentRefusalLines,
|
|
65
66
|
adoptAbsentRefusalLines,
|
|
66
|
-
checkReportLines,
|
|
67
|
+
checkReportLines, checkStopBlock, escapeLeadingSpace,
|
|
67
68
|
gateAlreadyDeclaredLines,
|
|
68
69
|
gateDeclaredLines,
|
|
69
70
|
gateRefusedLines,
|
|
@@ -74,15 +75,18 @@ import {
|
|
|
74
75
|
reasonRequiredLines,
|
|
75
76
|
recordNoLongerHoldsLines,
|
|
76
77
|
recordRecognizedLines,
|
|
77
|
-
schema1MovedLines,
|
|
78
|
-
|
|
79
|
-
statedLimitLines,
|
|
80
|
-
unmintedRefusalLines,
|
|
78
|
+
schema1MovedLines, schema1StopBlock,
|
|
79
|
+
statedLimitLines, unmintedRefusalLines, unmintedStopBlock,
|
|
81
80
|
warningLines,
|
|
82
81
|
writtenLines,
|
|
83
82
|
} from './source-size-report.mjs';
|
|
84
83
|
|
|
85
|
-
const
|
|
84
|
+
const ERROR_PREFIX = '[agent-workflow-kit] ';
|
|
85
|
+
const CHECKER_NAME = 'source-size';
|
|
86
|
+
const USAGE_REFUSAL = Symbol('usage refusal');
|
|
87
|
+
const HELP_LINES = HELP.split('\n');
|
|
88
|
+
const USAGE = HELP_LINES.slice(HELP_LINES.indexOf('Usage:')).slice(0, 6).join('\n');
|
|
89
|
+
const usageFail = (message) => Object.assign(new Error(`${ERROR_PREFIX}${message}`), { exitCode: 2, [USAGE_REFUSAL]: true });
|
|
86
90
|
const RECORD_NOUN = 'the source-size record';
|
|
87
91
|
const LAYOUT_GROWTH_LEAD = 'source-size: --layout REFUSED — it starts the layout record and raises nothing else, but the record no longer holds for this tree, so that growth takes --write-baseline --reason first; nothing was written.';
|
|
88
92
|
|
|
@@ -94,10 +98,12 @@ const ABSENT = Object.freeze({ _README: TEMPLATE_README, schema: SOURCE_SIZE_SCH
|
|
|
94
98
|
export const runCheck = ({ cwd, deps = {} }) => {
|
|
95
99
|
const target = checkTargetOf({ loaded: loadSourceSizeConfig(cwd, deps), absentConfig: validateSourceSizeConfig(ABSENT) });
|
|
96
100
|
const { config, judged } = target;
|
|
97
|
-
if (target.stop === 'schema-1') return { code: 1,
|
|
98
|
-
if (target.stop === 'unminted') return { code: 1,
|
|
101
|
+
if (target.stop === 'schema-1') return { code: 1, block: schema1StopBlock(cwd), config };
|
|
102
|
+
if (target.stop === 'unminted') return { code: 1, block: unmintedStopBlock(cwd, { state: target.state, missing: target.missing }), config };
|
|
99
103
|
const verdict = judgeTree(cwd, config, deps, judged);
|
|
100
|
-
|
|
104
|
+
const report = { cwd, config, verdict, absent: judged.absent };
|
|
105
|
+
return stopsOf(verdict.findings).length > 0 ? { code: 1, block: checkStopBlock(report), config, judged }
|
|
106
|
+
: { code: 0, lines: checkReportLines(report), config, judged };
|
|
101
107
|
};
|
|
102
108
|
|
|
103
109
|
// ── the writer ────────────────────────────────────────────────────────────────────────────────────
|
|
@@ -233,7 +239,7 @@ const gateIsDeclared = (cwd, deps) => {
|
|
|
233
239
|
// certain to red the matrix is what the offer rules refuse everywhere else.
|
|
234
240
|
const recognizeRecord = ({ cwd, deps }) => {
|
|
235
241
|
const verdict = runCheck({ cwd, deps });
|
|
236
|
-
if (verdict.code !== 0) return { code: verdict.code, lines: [...verdict.
|
|
242
|
+
if (verdict.code !== 0) return { code: verdict.code, lines: [...composeRedBlock({ name: CHECKER_NAME, ...verdict.block }), ...recordNoLongerHoldsLines(GATES_REL)] };
|
|
237
243
|
return { code: 0, lines: recordRecognizedLines(cwd) };
|
|
238
244
|
};
|
|
239
245
|
|
|
@@ -357,22 +363,37 @@ export const main = (argv, ctx = {}) => {
|
|
|
357
363
|
? overrideOptions({ id: idOption.value, value: valueOption.value, tolerance: toleranceOption.value, kitDefault })
|
|
358
364
|
: {};
|
|
359
365
|
const deps = ctx.deps ?? {};
|
|
360
|
-
const { code, lines, config, judged } = RUNS[mode]({ cwd, reason: reasonOption.value, layout, deps, ...override });
|
|
366
|
+
const { code, lines, block, config, judged } = RUNS[mode]({ cwd, reason: reasonOption.value, layout, deps, ...override });
|
|
361
367
|
const states = STATES_LIMITS.includes(mode) && config;
|
|
362
368
|
const limits = states ? statedLimitLines(config) : [];
|
|
363
369
|
const notJudged = states && judged ? notJudgedLines(cwd, { ...judged, config }) : [];
|
|
364
|
-
|
|
370
|
+
const output = block ? composeRedBlock({ name: CHECKER_NAME, ...block, after: [...limits, ...notJudged, ...block.after] }) : [...limits, ...notJudged, ...lines];
|
|
371
|
+
return { code, stdout: output.join('\n'), stderr: '' };
|
|
365
372
|
} catch (err) {
|
|
366
|
-
|
|
373
|
+
if (err?.exitCode === undefined) throw err;
|
|
374
|
+
const message = err.message.startsWith(ERROR_PREFIX) ? err.message.slice(ERROR_PREFIX.length) : err.message;
|
|
375
|
+
const failed = escapeLeadingSpace(err[USAGE_REFUSAL] ? escapeForLine(message) : message);
|
|
376
|
+
const output = err[USAGE_REFUSAL] ? composeUsageRefusal({ name: CHECKER_NAME, failed, usage: USAGE })
|
|
377
|
+
: composeRedBlock({ name: CHECKER_NAME, failed, remedies: [err.exitCode === 2 ? 'fix the size config or the git index error the verdict line names, then re-run' : 'fix the tree condition the verdict line names, then re-run'], after: err.lines ?? [] });
|
|
378
|
+
return { code: err.exitCode, stdout: output.join('\n'), stderr: '' };
|
|
367
379
|
}
|
|
368
380
|
};
|
|
369
381
|
|
|
382
|
+
export const guardedMain = (argv, ctx = {}) => {
|
|
383
|
+
const carried = [];
|
|
384
|
+
const result = guardChecker({ name: CHECKER_NAME, exitCode: 2, remedy: 'fix the cause the stack below names, then re-run' }, () => {
|
|
385
|
+
try { return main(argv, ctx); }
|
|
386
|
+
catch (err) { carried.push(...(err?.lines ?? [])); throw err; }
|
|
387
|
+
});
|
|
388
|
+
return result.lines ? { code: result.exitCode, stdout: [...result.lines, ...carried].join('\n'), stderr: '' } : result;
|
|
389
|
+
};
|
|
390
|
+
|
|
370
391
|
// The realpath-compare direct-run predicate now lives in tools/direct-run.mjs (the fix this file
|
|
371
392
|
// carried first, extracted so every module shares one implementation); `sameFile` stays exported here
|
|
372
393
|
// because this module's tests bind it as a seam.
|
|
373
394
|
export { sameFile };
|
|
374
395
|
if (isDirectRun(import.meta.url)) {
|
|
375
|
-
const result =
|
|
396
|
+
const result = guardedMain(process.argv.slice(2));
|
|
376
397
|
if (result.stdout) process.stdout.write(result.stdout.endsWith('\n') ? result.stdout : `${result.stdout}\n`);
|
|
377
398
|
if (result.stderr) process.stderr.write(result.stderr.endsWith('\n') ? result.stderr : `${result.stderr}\n`);
|
|
378
399
|
process.exitCode = result.code;
|
|
@@ -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 });
|