@sabaiway/agent-workflow-kit 14.38.0 → 14.40.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 +61 -0
- package/README.md +2 -1
- package/SKILL.md +5 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/advisor-writers.md +1 -0
- package/references/modes/gates.md +1 -1
- package/references/modes/procedures.md +1 -1
- package/references/modes/recommendations.md +1 -1
- package/references/modes/rules.md +24 -0
- package/references/modes/upgrade.md +7 -7
- package/references/shared/composition-handoff.md +2 -2
- package/references/templates/architecture.md +5 -20
- package/tools/commands.mjs +7 -0
- package/tools/gates-init.mjs +17 -8
- package/tools/inject-methodology.mjs +16 -16
- package/tools/procedures.mjs +9 -2
- package/tools/project-rules/index.mjs +1 -0
- package/tools/project-rules/memory-map-row.mjs +62 -0
- package/tools/recommendations.mjs +25 -11
- package/tools/run-gates.mjs +13 -3
- package/tools/source-size/index.mjs +30 -0
- package/tools/source-size/layout.mjs +136 -0
- package/tools/source-size/limits.mjs +110 -0
- package/tools/source-size/record.mjs +143 -0
- package/tools/source-size-check.mjs +192 -127
- package/tools/source-size-config.mjs +92 -27
- package/tools/source-size-core.mjs +27 -0
- package/tools/source-size-judge.mjs +143 -77
- package/tools/source-size-refusal.mjs +8 -3
- package/tools/source-size-report.mjs +182 -46
- package/tools/source-size-scope.mjs +31 -6
- package/tools/write-lanes.mjs +1 -0
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
// must name the file, the actual value, the allowed value AND a step the reader can perform against
|
|
3
3
|
// THIS build — never a bare "too big" and never a command that does not exist yet.
|
|
4
4
|
//
|
|
5
|
-
// Two render contracts, honestly separated (D-3a):
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// The exception both share: on a project path that does not survive double-quoting, NO command is
|
|
12
|
-
// rendered (a rendered one could run somewhere else) — the parameters, the reason requirement and
|
|
13
|
-
// the manual lane are stated instead.
|
|
5
|
+
// Two render contracts, honestly separated (D-3a): a TIGHTEN warns, the tree shrank below its
|
|
6
|
+
// record, and prints the regenerator EXACTLY as it should be pasted, no reason asked; a GROWTH stops,
|
|
7
|
+
// the regeneration would RAISE a value, and prints the command as a TEMPLATE carrying the reason
|
|
8
|
+
// placeholder, the requirement stated. The exception both share: on a project path that does not
|
|
9
|
+
// survive double-quoting, NO command is rendered (a rendered one could run somewhere else) — the
|
|
10
|
+
// parameters, the reason requirement and the manual lane are stated instead.
|
|
14
11
|
//
|
|
15
12
|
// The standing echo (D-17 U4) rides the same two renders: a PASS states the practice in one line, so
|
|
16
13
|
// the enforced path itself keeps the caps in front of the reader, and every refusal CLOSES with the
|
|
@@ -18,10 +15,11 @@
|
|
|
18
15
|
//
|
|
19
16
|
// Dependency-free, Node >= 22. No writes, no side effects on import.
|
|
20
17
|
|
|
21
|
-
import { SOURCE_SIZE_WHY, configPathFor, escapeForLine, isLineUnsafe, jsonForLine } from './source-size-refusal.mjs';
|
|
22
|
-
import { INITIAL_ADOPTION_REASON,
|
|
18
|
+
import { SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_WARNING_PREFIX, SOURCE_SIZE_WHY, configPathFor, escapeForLine, isLineUnsafe, jsonForLine } from './source-size-refusal.mjs';
|
|
19
|
+
import { INITIAL_ADOPTION_REASON, SOURCE_SIZE_SCHEMA, practiceFacts } from './source-size-config.mjs';
|
|
23
20
|
import { SOURCE_SIZE_TOOL_PATH, dqUnsafePath } from './source-size-gate-cmd.mjs';
|
|
24
|
-
import {
|
|
21
|
+
import { hasLoweredRecord, stopsOf, warningsOf } from './source-size-judge.mjs';
|
|
22
|
+
import { isRaise, limitLines } from './source-size/index.mjs';
|
|
25
23
|
|
|
26
24
|
// The project directory is project-controlled too, so the path every refusal names enters its line
|
|
27
25
|
// escaped like any other such value. configPathFor itself stays literal — it also builds the real
|
|
@@ -30,17 +28,35 @@ const namedConfig = (cwd) => escapeForLine(configPathFor(cwd));
|
|
|
30
28
|
|
|
31
29
|
export const GROWTH_REASON_PLACEHOLDER = '<why this size is accepted>';
|
|
32
30
|
|
|
31
|
+
// The `_README` the kit's schema-1 template carried, frozen: the move replaces a `_README` byte-equal
|
|
32
|
+
// to it with the schema-2 text and carries any other verbatim.
|
|
33
|
+
export const SCHEMA1_TEMPLATE_README = 'Source-size practice: declared scope + thresholds + the recorded ratchet. Authored keys: schema, defaults, roots, exclude, extensions. Machine keys: baseline, aggregate — each recorded entry carries a reason, and a recorded size is debt, not permission. Strict JSON — unknown keys refused.';
|
|
34
|
+
export const TEMPLATE_README = 'Source-size practice: declared scope + the recorded ratchet; the limits are the kit\'s, kept in its code. Authored keys: schema, roots, exclude, extensions, limits (a project\'s reasoned overrides of a kit limit). Machine keys: baseline, aggregate, layout — each recorded entry carries a reason, and a recorded size is debt, not permission. Strict JSON — unknown keys refused.';
|
|
35
|
+
export const TEMPLATE_READMES = Object.freeze({ schema1: SCHEMA1_TEMPLATE_README, schema2: TEMPLATE_README });
|
|
36
|
+
|
|
33
37
|
// The authoring template (D-5): GENERIC, and INERT by construction — its roots/extensions carry
|
|
34
38
|
// placeholders the validator refuses, so it can never be pasted into an empty-green scope.
|
|
35
39
|
export const authoringTemplate = () => JSON.stringify({
|
|
36
|
-
_README:
|
|
40
|
+
_README: TEMPLATE_README,
|
|
37
41
|
schema: SOURCE_SIZE_SCHEMA,
|
|
38
|
-
defaults: { ...SOURCE_SIZE_DEFAULTS },
|
|
39
42
|
roots: ['<a directory this practice covers>'],
|
|
40
43
|
exclude: [],
|
|
41
44
|
extensions: ['<.an-extension-this-practice-covers>'],
|
|
42
45
|
}, null, 2);
|
|
43
46
|
|
|
47
|
+
// The five limits every run that reaches a resolved config states, from the module's one function.
|
|
48
|
+
export const statedLimitLines = (config) =>
|
|
49
|
+
limitLines(config.limits, { escape: escapeForLine, recorded: config.layout !== null }).map((line) => `source-size: ${line}`);
|
|
50
|
+
|
|
51
|
+
// What a run does not judge is said once, before its warnings: no extension, no config, no layout.
|
|
52
|
+
export const notJudgedLines = (cwd, { absent, config, layout }) => {
|
|
53
|
+
if (absent) return [`source-size: NOTE — ${namedConfig(cwd)} is absent, so the kit's values judge layout alone and no file is judged on lines or bytes`];
|
|
54
|
+
return [
|
|
55
|
+
...(config.extensions.length === 0 ? [`source-size: NOTE — ${namedConfig(cwd)} declares no extension, so no file is judged on lines or bytes`] : []),
|
|
56
|
+
...(layout ? [] : [`source-size: NOTE — ${namedConfig(cwd)} records no "layout", so entries per directory, depth and files per root are not judged; --write-baseline --layout --reason "<text>" starts it`]),
|
|
57
|
+
];
|
|
58
|
+
};
|
|
59
|
+
|
|
44
60
|
// A rendered command carries the RESOLVED tool path and an explicit quoted --cwd, so it means the
|
|
45
61
|
// same thing from any directory. It is WITHHELD on either of two grounds, and the render says WHICH
|
|
46
62
|
// one fired: a reader told their path "does not survive double-quoting" when it quotes perfectly
|
|
@@ -63,7 +79,7 @@ const rendered = (cwd, mode, reason) => {
|
|
|
63
79
|
if (paths.some(dqUnsafePath)) return { command: null, withheld: WITHHELD_SHELL };
|
|
64
80
|
return { command: `node "${SOURCE_SIZE_TOOL_PATH}" ${mode} --cwd "${cwd}"${reason === undefined ? '' : ` --reason "${reason}"`}`, withheld: null };
|
|
65
81
|
};
|
|
66
|
-
const regenerator = (cwd, reason) => rendered(cwd, '--write-baseline', reason);
|
|
82
|
+
const regenerator = (cwd, reason, layout = false) => rendered(cwd, layout ? '--write-baseline --layout' : '--write-baseline', reason);
|
|
67
83
|
|
|
68
84
|
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).';
|
|
69
85
|
|
|
@@ -75,18 +91,16 @@ const SPLIT_QUALITY_FOCUS = 'source-size: REVIEW FOCUS — a recorded size went
|
|
|
75
91
|
const WHY_LINE = `source-size: WHY — ${SOURCE_SIZE_WHY}`;
|
|
76
92
|
const refusal = (lines) => [...lines, WHY_LINE];
|
|
77
93
|
|
|
78
|
-
// The standing summary (D-17 U4) — one line, from the CONFIG alone
|
|
79
|
-
//
|
|
80
|
-
// by construction, and saying that is the honest form of "how much room is left". Reached only on a
|
|
81
|
-
// MINTED config (a check refuses every other state before it renders anything).
|
|
94
|
+
// The standing summary (D-17 U4) — one line, from the CONFIG alone, on a MINTED config only: an
|
|
95
|
+
// absent one records nothing to summarize.
|
|
82
96
|
const practiceLine = (config) => {
|
|
83
97
|
const facts = practiceFacts(config);
|
|
84
|
-
return `source-size: practice — caps ${facts.maxLines} lines · ${facts.maxLineBytes} bytes per line over ${facts.roots} declared root(s) · ${facts.recordedFiles} file(s) carry a recorded size (debt, not permission) · aggregate ${facts.aggregateLines} line(s)
|
|
98
|
+
return `source-size: practice — caps ${facts.maxLines} lines · ${facts.maxLineBytes} bytes per line over ${facts.roots} declared root(s) · ${facts.recordedFiles} file(s) carry a recorded size (debt, not permission) · aggregate ${facts.aggregateLines} line(s): growth past a record takes a reasoned bump, and a record above the tree or gone warns until the regeneration lowers or removes it.`;
|
|
85
99
|
};
|
|
86
100
|
|
|
87
101
|
export const absentRefusalLines = (cwd) => refusal([
|
|
88
102
|
`source-size: REFUSED — ${namedConfig(cwd)} is absent, so the scope of this practice is undeclared.`,
|
|
89
|
-
'Scope is DECLARED, never guessed: the kit ships no default
|
|
103
|
+
'Scope is DECLARED, never guessed: the kit ships no default file-type list, because a fixed one would silently exempt every unlisted language.',
|
|
90
104
|
'Create it with this content, replacing every placeholder value:',
|
|
91
105
|
authoringTemplate(),
|
|
92
106
|
]);
|
|
@@ -115,24 +129,47 @@ const lineSafeFinding = (finding) => ({
|
|
|
115
129
|
...finding,
|
|
116
130
|
...(finding.rel === undefined ? {} : { rel: escapeForLine(finding.rel) }),
|
|
117
131
|
...(finding.root === undefined ? {} : { root: escapeForLine(finding.root) }),
|
|
132
|
+
...(finding.dir === undefined ? {} : { dir: escapeForLine(finding.dir) }),
|
|
118
133
|
});
|
|
119
134
|
|
|
135
|
+
const BAND = (f) => `over the limit ${f.allowed} but within its band (up to ${f.ceiling})`;
|
|
136
|
+
|
|
137
|
+
// A stop: the regeneration would raise.
|
|
120
138
|
const FINDING_LINE = Object.freeze({
|
|
121
|
-
'over-default': (f) => `${f.rel}: ${f.dimension} ${f.actual} exceeds the declared default ${f.allowed}`,
|
|
139
|
+
'over-default': (f) => `${f.rel}: ${f.dimension} ${f.actual} exceeds the declared default ${f.allowed} beyond its band (up to ${f.ceiling})`,
|
|
122
140
|
grew: (f) => `${f.rel}: ${f.dimension} ${f.actual} exceeds its recorded baseline ${f.recorded} — recorded debt is not permission to grow`,
|
|
123
|
-
stale: (f) => `${f.rel}: ${f.dimension} ${f.actual} is under the recorded ${f.recorded} — the baseline is STALE, tighten it`,
|
|
124
|
-
'record-obsolete': (f) => `${f.rel}: ${f.dimension} ${f.actual} no longer exceeds the declared default ${f.allowed} — the record must go`,
|
|
125
|
-
'entry-gone': (f) => `${f.rel}: recorded in "baseline" but no longer in scope — split, renamed or deleted; the record must go`,
|
|
126
141
|
'aggregate-grew': (f) => `${f.root}: aggregate lines ${f.actual} exceeds the recorded budget ${f.recorded} — splitting a file buys no aggregate headroom`,
|
|
127
|
-
'aggregate-stale': (f) => `${f.root}: aggregate lines ${f.actual} is under the recorded budget ${f.recorded} — the budget is STALE, tighten it`,
|
|
128
142
|
'aggregate-unrecorded': (f) => `${f.root}: declared root carries NO recorded aggregate budget (${f.actual} lines measured) — the record must mirror the declared roots exactly`,
|
|
129
|
-
'
|
|
143
|
+
'root-unrecorded': (f) => `${f.root}: judged root carries NO recorded files count (${f.actual} files measured) — the layout record must mirror the judged roots exactly`,
|
|
144
|
+
'root-grew': (f) => `${f.root}: files ${f.actual} exceeds its recorded ${f.recorded} beyond its band (up to ${f.ceiling})`,
|
|
145
|
+
'dir-over': (f) => `${f.dir}: ${f.dimension} ${f.actual} exceeds the limit ${f.allowed} beyond its band (up to ${f.ceiling})`,
|
|
146
|
+
'dir-grew': (f) => `${f.dir}: ${f.dimension} ${f.actual} exceeds its recorded ${f.recorded} — recorded debt is not permission to grow`,
|
|
130
147
|
});
|
|
131
148
|
|
|
149
|
+
// A warning: printed on every run, exit 0, until the value or its record comes back within its limit.
|
|
150
|
+
const WARNING_LINE = Object.freeze({
|
|
151
|
+
'within-band': (f) => `${f.rel}: ${f.dimension} ${f.actual} is ${BAND(f)} — no record is kept; past ${f.ceiling} it stops`,
|
|
152
|
+
stale: (f) => `${f.rel}: ${f.dimension} ${f.actual} is under the recorded ${f.recorded} — the regeneration lowers it`,
|
|
153
|
+
'record-obsolete': (f) => `${f.rel}: ${f.dimension} ${f.actual} is within its band (up to ${f.ceiling}), so its record is obsolete — the regeneration removes it`,
|
|
154
|
+
'entry-gone': (f) => `${f.rel}: recorded in "baseline" but no longer in scope — split, renamed or deleted; the regeneration removes it`,
|
|
155
|
+
'aggregate-stale': (f) => `${f.root}: aggregate lines ${f.actual} is under the recorded budget ${f.recorded} — the regeneration lowers it`,
|
|
156
|
+
'aggregate-root-gone': (f) => `${f.root}: recorded in "aggregate" but no longer a declared root — the regeneration removes it`,
|
|
157
|
+
'root-band': (f) => `${f.root}: files ${f.actual} is over its recorded ${f.recorded} but within its band (up to ${f.ceiling}) — past ${f.ceiling} it stops`,
|
|
158
|
+
'root-stale': (f) => `${f.root}: files ${f.actual} is under the recorded ${f.recorded} — the regeneration lowers it`,
|
|
159
|
+
'root-gone': (f) => `${f.root}: recorded in "layout"."roots" but no longer a judged root — the regeneration removes it`,
|
|
160
|
+
'dir-band': (f) => `${f.dir}: ${f.dimension} ${f.actual} is ${BAND(f)} — past ${f.ceiling} it stops`,
|
|
161
|
+
'dir-stale': (f) => `${f.dir}: ${f.dimension} ${f.actual} is under the recorded ${f.recorded} — the regeneration lowers it`,
|
|
162
|
+
'dir-obsolete': (f) => (f.actual > f.ceiling ? `${f.dir}: its depth record ${f.recorded} no longer sits on the shallowest directory beyond the depth band — the regeneration removes it` : `${f.dir}: ${f.dimension} ${f.actual} is within its band (up to ${f.ceiling}), so its record is obsolete — the regeneration removes it`),
|
|
163
|
+
'dir-gone': (f) => `${f.dir}: recorded in "layout"."directories" but no directory the run judges — the regeneration removes it`,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export const warningLines = (findings) =>
|
|
167
|
+
findings.map((finding) => `${SOURCE_SIZE_WARNING_PREFIX}${WARNING_LINE[finding.kind](lineSafeFinding(finding))}`);
|
|
168
|
+
|
|
132
169
|
// The suggested entry is the WHOLE projected record, not the dimensions that happen to have changed:
|
|
133
170
|
// an entry printed from the findings alone would drop a recorded dimension that stayed put, and
|
|
134
171
|
// pasting it would fail the very next check. The projection already carries exactly the dimensions
|
|
135
|
-
//
|
|
172
|
+
// beyond their band and nothing else.
|
|
136
173
|
const suggestedEntryLines = (verdict) => {
|
|
137
174
|
const rels = [...new Set(verdict.findings.filter((f) => f.kind === 'over-default' || f.kind === 'grew').map((f) => f.rel))];
|
|
138
175
|
return rels.map((rel) => {
|
|
@@ -141,32 +178,44 @@ const suggestedEntryLines = (verdict) => {
|
|
|
141
178
|
});
|
|
142
179
|
};
|
|
143
180
|
|
|
181
|
+
// A stop is a raise, so its regeneration always takes the reason.
|
|
144
182
|
const servableStep = (cwd, verdict) => {
|
|
145
|
-
const growth = hasGrowth(verdict.findings);
|
|
146
183
|
const entries = suggestedEntryLines(verdict);
|
|
147
|
-
const { command, withheld } = regenerator(cwd,
|
|
184
|
+
const { command, withheld } = regenerator(cwd, GROWTH_REASON_PLACEHOLDER);
|
|
148
185
|
const byHand = entries.length === 0 ? [] : ['Or record each size by hand under "baseline" — the validator accepts exactly these bytes:', ...entries];
|
|
149
186
|
if (command === null) return [withheld, WITHHELD_LANE, ...entries];
|
|
150
187
|
return [
|
|
151
|
-
|
|
152
|
-
? '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:'
|
|
153
|
-
: 'Nothing here grows — regenerate the record (no reason needed; shrinking is progress):',
|
|
188
|
+
'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:',
|
|
154
189
|
` ${command}`,
|
|
155
190
|
...byHand,
|
|
156
191
|
];
|
|
157
192
|
};
|
|
158
193
|
|
|
159
|
-
|
|
194
|
+
// A lowered or removed record warns with the paste-ready regeneration, which needs no reason.
|
|
195
|
+
const tightenLine = (cwd) => {
|
|
196
|
+
const { command, withheld } = regenerator(cwd);
|
|
197
|
+
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}`}`;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// The order every check prints: its notes, its warnings, then the green line or its stops.
|
|
201
|
+
export const checkReportLines = ({ cwd, config, verdict, absent = false }) => {
|
|
160
202
|
const lines = verdict.scope.emptyRoots.map(
|
|
161
203
|
(rel) => `source-size: NOTE — the declared root "${escapeForLine(rel)}" matches no tracked file with a declared extension`);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
204
|
+
const stops = stopsOf(verdict.findings);
|
|
205
|
+
const warnings = warningsOf(verdict.findings);
|
|
206
|
+
lines.push(...warningLines(warnings));
|
|
207
|
+
const lowered = hasLoweredRecord(warnings);
|
|
208
|
+
if (stops.length === 0) {
|
|
209
|
+
if (lowered) lines.push(tightenLine(cwd), SPLIT_QUALITY_FOCUS);
|
|
210
|
+
lines.push(warnings.length === 0
|
|
211
|
+
? `source-size: PASS — ${verdict.scope.files.length} in-scope file(s) within the declared caps`
|
|
212
|
+
: `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`);
|
|
213
|
+
return absent ? lines : [...lines, practiceLine(config)];
|
|
165
214
|
}
|
|
166
|
-
lines.push(`source-size: FAIL — ${
|
|
167
|
-
for (const finding of
|
|
215
|
+
lines.push(`source-size: FAIL — ${stops.length} finding(s) ${absent ? `under the kit's values (${namedConfig(cwd)} is absent)` : `against ${namedConfig(cwd)}`}:`);
|
|
216
|
+
for (const finding of stops) lines.push(` ${FINDING_LINE[finding.kind](lineSafeFinding(finding))}`);
|
|
168
217
|
lines.push(...servableStep(cwd, verdict));
|
|
169
|
-
if (
|
|
218
|
+
if (lowered) lines.push(SPLIT_QUALITY_FOCUS);
|
|
170
219
|
return refusal(lines);
|
|
171
220
|
};
|
|
172
221
|
|
|
@@ -178,8 +227,9 @@ export const deltaLines = (deltas) => deltas.map(
|
|
|
178
227
|
({ target, dimension, from, to }) =>
|
|
179
228
|
` ${escapeForLine(target)}: ${dimension} ${from ?? 'none'} → ${to ?? 'none'}${isRaise({ from, to }) ? ' (raise)' : ''}`);
|
|
180
229
|
|
|
181
|
-
|
|
182
|
-
|
|
230
|
+
// A run that starts the layout record says so in the command it prints, or pasting it would not.
|
|
231
|
+
export const reasonRequiredLines = (cwd, deltas, { layout = false } = {}) => {
|
|
232
|
+
const { command, withheld } = regenerator(cwd, GROWTH_REASON_PLACEHOLDER, layout);
|
|
183
233
|
const raises = deltas.filter(isRaise).length;
|
|
184
234
|
return refusal([
|
|
185
235
|
`source-size: REFUSED — this regeneration RAISES ${raises} recorded value(s), and a raise takes a reason (it lands verbatim in the entry it raises, in the commit message and in the CHANGELOG). The whole old→new it would write:`,
|
|
@@ -188,20 +238,52 @@ export const reasonRequiredLines = (cwd, deltas) => {
|
|
|
188
238
|
]);
|
|
189
239
|
};
|
|
190
240
|
|
|
241
|
+
// ── schema 1 and --override ───────────────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
// The check no longer judges schema 1: it names the one move, which the writer makes in its one write.
|
|
244
|
+
export const schema1StopLines = (cwd) => {
|
|
245
|
+
const { command, withheld } = regenerator(cwd);
|
|
246
|
+
return refusal([
|
|
247
|
+
`source-size: STOPPED — ${namedConfig(cwd)} is schema 1, which the check no longer judges; --write-baseline moves it to schema 2 in its one write (a raise riding it still takes --reason): ${command ?? `${withheld} Run source-size-check.mjs --write-baseline with the working directory set to this project.`}`,
|
|
248
|
+
]);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Claims only what holds of every written file.
|
|
252
|
+
export const schema1MovedLines = (cwd) => [
|
|
253
|
+
`source-size: ${namedConfig(cwd)} moved from schema 1 to schema 2 in this write.`,
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
// The record must hold before an override is written, so its reason never lands on drift it did not
|
|
257
|
+
// cause: the lead line says so, and the reason-required refusal names that drift's own lane.
|
|
258
|
+
export const overrideOutgrownLines = (cwd, deltas) => [
|
|
259
|
+
`source-size: --override REFUSED — the record in ${namedConfig(cwd)} no longer holds for this tree before this change, so that drift takes --write-baseline --reason first; nothing was written.`,
|
|
260
|
+
...reasonRequiredLines(cwd, deltas),
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
// Names the id and the reason, never a value or tolerance: the limit lines state what is judged.
|
|
264
|
+
export const overrideWrittenLines = ({ cwd, id, removed, reason }) => [
|
|
265
|
+
removed
|
|
266
|
+
? `source-size: ${id} follows the kit's numbers in ${namedConfig(cwd)} — reason: ${escapeForLine(reason)}`
|
|
267
|
+
: `source-size: override of ${id} written in ${namedConfig(cwd)} — reason: ${escapeForLine(reason)}`,
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
export const overrideUnchangedLines = (cwd, id) => [
|
|
271
|
+
`source-size: ${id} — ${namedConfig(cwd)} already holds this, so nothing was written`,
|
|
272
|
+
];
|
|
273
|
+
|
|
191
274
|
// ── --adopt (D-16) ────────────────────────────────────────────────────────────────────────────────
|
|
192
275
|
// The verb touches TWO files, so it reports the two halves separately, ALWAYS. A failure in the
|
|
193
276
|
// second must never read as a failure of the first: a reader told only "adopt failed" would re-run a
|
|
194
277
|
// mint that already succeeded, or hand-write a record that is already on disk. Every line below
|
|
195
278
|
// therefore names what WAS done before what was not.
|
|
196
279
|
|
|
197
|
-
// ABSENT config
|
|
198
|
-
//
|
|
199
|
-
// check prints, because a second wording of the same refusal would be a second practice.
|
|
280
|
+
// ABSENT config: authoring the scope is the EXPECTED first step of adoption, not a failure — the
|
|
281
|
+
// template and the WHY are the ones the --override refusal prints, never a second wording.
|
|
200
282
|
export const adoptAbsentRefusalLines = (cwd) => {
|
|
201
283
|
const { command, withheld } = rendered(cwd, '--adopt', INITIAL_ADOPTION_REASON);
|
|
202
284
|
return refusal([
|
|
203
285
|
`source-size: --adopt REFUSED — ${namedConfig(cwd)} is absent, so this practice has no declared scope yet.`,
|
|
204
|
-
'
|
|
286
|
+
'Reaching it here is EXPECTED, not a failure: adoption needs a declared scope, and the kit ships no default file-type list, because a fixed one would silently exempt every unlisted language.',
|
|
205
287
|
'Create it with this content, replacing every placeholder value:',
|
|
206
288
|
authoringTemplate(),
|
|
207
289
|
'Then re-run this same verb — it mints the record and declares the gate in one step:',
|
|
@@ -252,3 +334,57 @@ export const writtenLines = ({ cwd, deltas, reason, changed }) => {
|
|
|
252
334
|
...(reason === undefined ? [] : [`reason: ${reason}`]),
|
|
253
335
|
];
|
|
254
336
|
};
|
|
337
|
+
|
|
338
|
+
// ── --help ────────────────────────────────────────────────────────────────────────────────────────
|
|
339
|
+
|
|
340
|
+
export const HELP = `source-size-check — the declared source-size practice (agent-workflow family).
|
|
341
|
+
|
|
342
|
+
Usage:
|
|
343
|
+
node source-size-check.mjs --check [--cwd <project-root>]
|
|
344
|
+
node source-size-check.mjs --write-baseline [--layout] [--reason "<text>"] [--cwd <project-root>]
|
|
345
|
+
node source-size-check.mjs --adopt [--reason "<text>"] [--cwd <project-root>]
|
|
346
|
+
node source-size-check.mjs --override <id> [--value <n>] [--tolerance <p>] --reason "<text>" [--cwd <project-root>]
|
|
347
|
+
node source-size-check.mjs --override <id> --kit-default --reason "<text>" [--cwd <project-root>]
|
|
348
|
+
|
|
349
|
+
Judges every in-scope file against ${SOURCE_SIZE_CONFIG_REL} (schema ${SOURCE_SIZE_SCHEMA}): git-tracked files
|
|
350
|
+
under a declared root carrying a declared extension, minus the excluded path-segment prefixes. An
|
|
351
|
+
absent "roots" is the one root ".", every tracked path; a config declaring no extension judges no
|
|
352
|
+
file, and every check says so. With the config absent the check judges layout alone under the
|
|
353
|
+
kit's values. Symlinks and submodule gitlinks are skipped by kind; an unmerged index, a non-UTF-8
|
|
354
|
+
in-scope path, an unverifiable in-scope file and an empty declared scope are refusals.
|
|
355
|
+
|
|
356
|
+
Limits: the kit's own five, kept in its code, each with a tolerance; the config holds only a
|
|
357
|
+
project's reasoned overrides under "limits". A value at or under its limit is clean, above it within
|
|
358
|
+
the band ceil(value x tolerance / 100) a WARNING printed on every run (exit 0), and beyond the band a
|
|
359
|
+
stop unless a record holds it. Every --check, --write-baseline and --override run that resolves the
|
|
360
|
+
config and ends in no usage, config, enumeration or scope error states all five limits with value,
|
|
361
|
+
tolerance and source, then what it does not judge, then its warnings, then its stops.
|
|
362
|
+
|
|
363
|
+
Counting: lines, and the longest line in BYTES. A terminator never counts (the CR of a CRLF
|
|
364
|
+
included); a last line with no final newline still counts; an empty file is 0 lines. Layout: the
|
|
365
|
+
entries of each directory, its depth below its root, and the files of each root — every tracked
|
|
366
|
+
entry under a declared root, plus the spec store docs/ai/specs walked from disk.
|
|
367
|
+
|
|
368
|
+
A recorded entry is DEBT: a finding stops exactly when the regeneration would raise it, and a record
|
|
369
|
+
above the tree or gone warns until the regeneration lowers or removes it. Each declared root carries
|
|
370
|
+
the same exact ratchet over its summed lines.
|
|
371
|
+
|
|
372
|
+
--write-baseline regenerates the machine keys (baseline, aggregate, and layout where it is judged)
|
|
373
|
+
from the tree; on an absent config it writes a schema-2 one. --layout starts the layout record on a
|
|
374
|
+
present config that has none. The authored keys keep their values and their order; the file is
|
|
375
|
+
canonically serialized. A regeneration that RAISES any recorded value needs --reason; the string is
|
|
376
|
+
recorded in the entry it raised. A pure tighten needs none. A schema-1 config is moved to schema 2 in
|
|
377
|
+
the same write; --check stops on one until it is.
|
|
378
|
+
|
|
379
|
+
--adopt is the ONE-line adoption: it mints the record and declares the source-size gate (and NOTHING
|
|
380
|
+
else) in docs/ai/gates.json. It is idempotent on an already-adopted project. With the config absent
|
|
381
|
+
it refuses with the exact file to author. A refused declaration exits nonzero and reports both
|
|
382
|
+
halves: what was minted and what was not declared.
|
|
383
|
+
|
|
384
|
+
--override writes one override of a kit limit (lines-per-file, bytes-per-line, entries-per-directory,
|
|
385
|
+
depth: --value and/or --tolerance; files-per-root: --tolerance only), or with --kit-default removes
|
|
386
|
+
it; an option left out keeps the limit's current value or tolerance, and --reason is mandatory. It
|
|
387
|
+
runs only once regenerating the record under the current limits would raise nothing, and
|
|
388
|
+
regenerates the record in the same write.
|
|
389
|
+
|
|
390
|
+
Exit codes: 0 green, warnings included; 1 a stop or a refusal; 2 usage, config or enumeration error.`;
|
|
@@ -14,16 +14,19 @@
|
|
|
14
14
|
// Dependency-free, Node >= 22. No side effects on import; the only child process is a read-only git
|
|
15
15
|
// query, so the read-graph purity suite stays true.
|
|
16
16
|
|
|
17
|
-
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { lstatSync, readdirSync, readFileSync } from 'node:fs';
|
|
18
18
|
import { join } from 'node:path';
|
|
19
19
|
import { spawnSync } from 'node:child_process';
|
|
20
20
|
import { configFail, configPathFor, scopeFail } from './source-size-refusal.mjs';
|
|
21
|
+
import { WHOLE_TREE_ROOT } from './source-size-config.mjs';
|
|
22
|
+
import { SPEC_STORE_ROOT, walkSpecStore } from './source-size/index.mjs';
|
|
21
23
|
import { GIT_MAX_BUFFER, parseIndexEntries, resolveGitLocation, withGitPath } from './git-env.mjs';
|
|
22
24
|
|
|
23
25
|
const LF = 0x0a;
|
|
24
26
|
const CR = 0x0d;
|
|
25
27
|
const SLASH = 0x2f;
|
|
26
28
|
|
|
29
|
+
const SPEC_STORE = Buffer.from(SPEC_STORE_ROOT, 'utf8');
|
|
27
30
|
const SYMLINK_MODE = '120000';
|
|
28
31
|
const GITLINK_MODE = '160000';
|
|
29
32
|
|
|
@@ -69,9 +72,12 @@ export const enumerateIndex = (cwd, deps = {}) => {
|
|
|
69
72
|
return parseIndexEntries(result.stdout);
|
|
70
73
|
};
|
|
71
74
|
|
|
72
|
-
// resolveScope(cwd, config) → { files: [rel…] sorted, perRoot: Map<root, [rel…]>,
|
|
75
|
+
// resolveScope(cwd, config) → { files: [rel…] sorted, perRoot: Map<root, [rel…]>, layout: Map<root,
|
|
76
|
+
// [{ path, dir }…]>, emptyRoots: [root…] }; `layout` holds every entry under a root, of any mode, as
|
|
77
|
+
// a binary string below the root.
|
|
73
78
|
// Every exclusion is BY RULE (root / extension / exclude prefix) or BY KIND (symlink, gitlink); an
|
|
74
|
-
// in-scope path that cannot be addressed losslessly is a refusal, never a quiet skip.
|
|
79
|
+
// in-scope path that cannot be addressed losslessly is a refusal, never a quiet skip. The root "."
|
|
80
|
+
// covers every tracked path.
|
|
75
81
|
export const resolveScope = (cwd, config, deps = {}) => {
|
|
76
82
|
const entries = enumerateIndex(cwd, deps);
|
|
77
83
|
const unmerged = entries.filter((e) => e.stage !== 0);
|
|
@@ -82,12 +88,18 @@ export const resolveScope = (cwd, config, deps = {}) => {
|
|
|
82
88
|
const excludes = config.exclude.map((rel) => Buffer.from(rel, 'utf8'));
|
|
83
89
|
const extensions = config.extensions.map((ext) => Buffer.from(ext, 'utf8'));
|
|
84
90
|
const perRoot = new Map(config.roots.map((rel) => [rel, []]));
|
|
91
|
+
const layout = new Map(config.roots.map((rel) => [rel, []]));
|
|
85
92
|
const files = [];
|
|
86
93
|
for (const entry of entries) {
|
|
87
|
-
const root = roots.find((r) => bufSegmentPrefix(entry.path, r.buf));
|
|
94
|
+
const root = roots.find((r) => r.rel === WHOLE_TREE_ROOT || bufSegmentPrefix(entry.path, r.buf));
|
|
88
95
|
if (!root) continue;
|
|
89
|
-
if (!extensions.some((ext) => bufEndsWith(entry.path, ext))) continue;
|
|
90
96
|
if (excludes.some((ex) => bufSegmentPrefix(entry.path, ex))) continue;
|
|
97
|
+
// Layout counts every entry of any mode, the spec store's aside: the store is a root of its own.
|
|
98
|
+
if (!bufSegmentPrefix(entry.path, SPEC_STORE)) {
|
|
99
|
+
const below = root.rel === WHOLE_TREE_ROOT ? entry.path : entry.path.subarray(root.buf.length + 1);
|
|
100
|
+
if (below.length > 0) layout.get(root.rel).push({ path: below.toString('latin1'), dir: false });
|
|
101
|
+
}
|
|
102
|
+
if (!extensions.some((ext) => bufEndsWith(entry.path, ext))) continue;
|
|
91
103
|
if (entry.mode === SYMLINK_MODE || entry.mode === GITLINK_MODE) continue;
|
|
92
104
|
const rel = decodeStrict(entry.path);
|
|
93
105
|
if (rel === null) {
|
|
@@ -96,12 +108,25 @@ export const resolveScope = (cwd, config, deps = {}) => {
|
|
|
96
108
|
files.push(rel);
|
|
97
109
|
perRoot.get(root.rel).push(rel);
|
|
98
110
|
}
|
|
111
|
+
// A config declaring no extension judges no file, and the check says so instead of refusing.
|
|
112
|
+
if (extensions.length === 0) return { files, perRoot, layout, emptyRoots: [] };
|
|
99
113
|
if (files.length === 0) {
|
|
100
114
|
throw scopeFail(`the declared scope matches ZERO tracked files (roots: ${config.roots.join(', ')}; extensions: ${config.extensions.join(', ')}) — an empty scope is a misdeclaration, never an empty green; either widen "roots" / "extensions" in ${configPathFor(cwd)}, or track a file the declared scope covers`);
|
|
101
115
|
}
|
|
102
116
|
files.sort();
|
|
103
117
|
for (const list of perRoot.values()) list.sort();
|
|
104
|
-
return { files, perRoot, emptyRoots: [...perRoot].filter(([, list]) => list.length === 0).map(([rel]) => rel) };
|
|
118
|
+
return { files, perRoot, layout, emptyRoots: [...perRoot].filter(([, list]) => list.length === 0).map(([rel]) => rel) };
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// specStoreEntries(cwd) → the spec store's entries walked from disk, or null where it is absent. A
|
|
122
|
+
// store that is present but no directory, or that cannot be read, is a scope refusal naming the path.
|
|
123
|
+
export const specStoreEntries = (cwd, deps = {}) => {
|
|
124
|
+
const walked = walkSpecStore(cwd, { readdir: deps.readdir ?? readdirSync, lstat: deps.lstat ?? lstatSync });
|
|
125
|
+
if (walked.state === 'absent') return null;
|
|
126
|
+
if (walked.state === 'refused') {
|
|
127
|
+
throw scopeFail(`${walked.path}: the spec store ${SPEC_STORE_ROOT} could not be walked (${walked.cause}) — layout counts it from disk, so nothing is judged; make it a readable directory, or remove it`);
|
|
128
|
+
}
|
|
129
|
+
return walked.entries;
|
|
105
130
|
};
|
|
106
131
|
|
|
107
132
|
// countBytes(buf) → { lines, maxLineBytes }. A terminator never counts (the CR of a CRLF included);
|
package/tools/write-lanes.mjs
CHANGED
|
@@ -31,6 +31,7 @@ export const VARIANT_LANES = Object.freeze({
|
|
|
31
31
|
'source-size.unminted': LANE_CHAT,
|
|
32
32
|
'source-size.adopted-elsewhere': LANE_CHAT,
|
|
33
33
|
'source-size.id-squatter': LANE_USER,
|
|
34
|
+
'source-size.schema-1': LANE_CHAT,
|
|
34
35
|
'gate-hook': LANE_HARNESS,
|
|
35
36
|
'gate-hook.marker-stale': LANE_HARNESS,
|
|
36
37
|
'commit-guard': LANE_HARNESS,
|