@sabaiway/agent-workflow-kit 23.6.0 → 23.8.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.
@@ -1,284 +1,20 @@
1
1
  #!/usr/bin/env node
2
- // source-size-check.mjs — the source-size practice's CLI and its writer half. The pure read core
3
- // (config, scope, counting, the canonical gate-cmd matcher) lives in source-size-core.mjs, the
4
- // verdict in source-size-judge.mjs and its wording in source-size-report.mjs; all three are imported
5
- // here. NOTHING in the read graph imports THIS module, so the advisor surfaces can ask about the
6
- // practice without ever reaching a writer (D-18).
2
+ // source-size-check.mjs — the size check's command line: it parses the arguments, runs the one mode
3
+ // they name from source-size-runs.mjs (what each mode does is told there) and composes what that run
4
+ // returned.
7
5
  //
8
- // What --check judges: every in-scope file against the resolved limits with their bands, layout
9
- // where it is recorded or the config is absent, and every RECORDED size against the ratchet — a
10
- // record may not grow, and one above the tree or gone warns until the regeneration lowers or removes
11
- // it. Each declared root carries the same exact ratchet over its summed lines, so splitting one big
12
- // file into six buys no headroom. An absent config is judged under the kit's values.
13
- //
14
- // What --write-baseline does: regenerates the machine keys from the tree, and ONLY the machine keys.
15
- // The authored half is copied through with its VALUES and their ORDER preserved exactly; the file
16
- // itself is canonically serialized, so its formatting becomes the writer's (that is what makes a
17
- // regeneration of an unchanged tree reproduce the same bytes). A regeneration that RAISES any value takes
18
- // --reason "<text>" — the checker cannot invent the human's reason — and that string lands verbatim
19
- // in the entry it raises. A pure tighten needs none: shrinking is progress. The printed old→new
20
- // delta is the durable record where docs/ai is git-hidden; it is what the commit message carries.
21
- //
22
- // What --adopt does: mints the record and declares the gate — the whole adoption as ONE consented
23
- // line, because the alternative is a two-step ceremony whose halves can be left half-done. It
24
- // composes the two writers it already has (this module's mint, the fill's consented apply restricted
25
- // to this one id) and owns no write of its own, but for the schema-1 move of a minted config, which
26
- // carries both records verbatim.
27
- //
28
- // What --override does: once a regeneration under the current limits would raise nothing, writes or
29
- // removes one reasoned override of a kit limit and regenerates the machine keys under the new limits
30
- // in the same write. Every write here moves a schema-1 config to schema 2; --check stops on one.
31
- //
32
- // Exit codes: 0 green / 1 violation or refusal / 2 usage, config or enumeration error.
6
+ // Exit codes: 0 green / 1 violation or refusal / 2 usage, config or enumeration error, or an unexpected error.
33
7
  // Dependency-free, Node >= 22. No side effects on import.
34
8
 
35
9
  import { resolve } from 'node:path';
36
- import { assertDocsAiDeployment, writeDocsAiFileAtomic } from './atomic-write.mjs';
10
+ import { composeRedBlock, composeUsageRefusal, guardChecker } from '../references/scripts/shared/index.mjs';
37
11
  import { isDirectRun, sameFile } from './direct-run.mjs';
38
- import {
39
- KIT_LIMITS,
40
- SOURCE_SIZE_CONFIG_REL,
41
- SOURCE_SIZE_GATE_ID,
42
- SOURCE_SIZE_SCHEMA,
43
- applyOverride,
44
- assertNoStoreRoot,
45
- checkTargetOf,
46
- isRaise,
47
- loadSourceSizeConfig,
48
- matchesSourceSizeGate,
49
- materialize,
50
- migrateSchema1,
51
- planRecord,
52
- reasonDefect,
53
- scopeFail,
54
- serialize,
55
- validateSourceSizeConfig,
56
- } from './source-size-core.mjs';
57
- import { bandWarningsOf, judgeTree, standingWarningsOf, stopsOf } from './source-size-judge.mjs';
58
- import { GATES_REL, loadDeclaration } from './gates-declaration.mjs';
59
- import { applyFill } from './gates-init.mjs';
60
- import {
61
- HELP,
62
- TEMPLATE_README,
63
- TEMPLATE_READMES,
64
- absentRefusalLines,
65
- adoptAbsentRefusalLines,
66
- checkReportLines,
67
- gateAlreadyDeclaredLines,
68
- gateDeclaredLines,
69
- gateRefusedLines,
70
- notJudgedLines,
71
- overrideOutgrownLines,
72
- overrideUnchangedLines,
73
- overrideWrittenLines,
74
- reasonRequiredLines,
75
- recordNoLongerHoldsLines,
76
- recordRecognizedLines,
77
- schema1MovedLines,
78
- schema1StopLines,
79
- statedLimitLines,
80
- unmintedRefusalLines,
81
- warningLines,
82
- writtenLines,
83
- } from './source-size-report.mjs';
84
-
85
- const usageFail = (message) => Object.assign(new Error(`[agent-workflow-kit] ${message}`), { exitCode: 2 });
86
- const RECORD_NOUN = 'the source-size record';
87
- 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
-
89
- // What an absent config is judged as: schema 2 under the kit's values, layout over "." and the store.
90
- const ABSENT = Object.freeze({ _README: TEMPLATE_README, schema: SOURCE_SIZE_SCHEMA });
91
-
92
- // Every run returns the config it resolved, so the CLI states the limits that run judged, and the
93
- // scope it judged, so the CLI says once what it did not.
94
- export const runCheck = ({ cwd, deps = {} }) => {
95
- const target = checkTargetOf({ loaded: loadSourceSizeConfig(cwd, deps), absentConfig: validateSourceSizeConfig(ABSENT) });
96
- const { config, judged } = target;
97
- if (target.stop === 'schema-1') return { code: 1, lines: schema1StopLines(cwd), config };
98
- if (target.stop === 'unminted') return { code: 1, lines: unmintedRefusalLines(cwd, { state: target.state, missing: target.missing }), config };
99
- const verdict = judgeTree(cwd, config, deps, judged);
100
- return { code: stopsOf(verdict.findings).length === 0 ? 0 : 1, lines: checkReportLines({ cwd, config, verdict, absent: judged.absent }), config, judged };
101
- };
102
-
103
- // ── the writer ────────────────────────────────────────────────────────────────────────────────────
104
-
105
- // A schema-1 config is moved by the one transform, the kit's old template `_README` replaced by the
106
- // new one; every write of this module goes through it, so no writer ever writes schema 1 back.
107
- const schema2Of = (parsed) => (parsed.schema === 1 ? migrateSchema1(parsed, TEMPLATE_READMES) : parsed);
108
-
109
- // What a move says it did, read off the moved config itself.
110
- const movedLines = (cwd, parsed) => (parsed.schema === 1 ? schema1MovedLines(cwd) : []);
111
-
112
- const writeRecord = (cwd, body, deps) =>
113
- writeDocsAiFileAtomic(cwd, SOURCE_SIZE_CONFIG_REL, body, deps, { stop: scopeFail, noun: RECORD_NOUN });
114
-
115
- // A run that writes prints every warning its write leaves standing; a refused write prints only
116
- // those standing today.
117
- const judgeForWrite = (cwd, config, deps, judged) => {
118
- const verdict = judgeTree(cwd, config, deps, judged);
119
- const { findings } = verdict;
120
- return { verdict, plan: planRecord({ config, verdict }), bandWarnings: warningLines(bandWarningsOf(findings)), warnings: warningLines(standingWarningsOf(findings)) };
121
- };
122
-
123
- // Layout is regenerated wherever it is judged; --layout starts it on a present config with none, and
124
- // changes nothing on one that records layout or is absent.
125
- export const runWriteBaseline = ({ cwd, reason, layout = false, deps = {} }) => {
126
- // Checked BEFORE the config is read, so a project that was never deployed hears about the
127
- // deployment rather than about a file it has no place to put.
128
- assertDocsAiDeployment(cwd, deps, { stop: scopeFail, rel: SOURCE_SIZE_CONFIG_REL, noun: RECORD_NOUN });
129
- const loaded = loadSourceSizeConfig(cwd, deps);
130
- const absent = loaded.state === 'absent';
131
- const parsed = absent ? ABSENT : loaded.parsed;
132
- const config = absent ? validateSourceSizeConfig(parsed) : loaded.config;
133
- if (layout && !absent && config.layout === null) assertNoStoreRoot(config.roots);
134
- const judged = { absent, layout: absent || layout || config.layout !== null };
135
- const { plan, bandWarnings, warnings } = judgeForWrite(cwd, config, deps, judged);
136
- const starts = layout && !absent && config.layout === null;
137
- // Starting layout on a minted record raises the layout record alone: growth takes the plain write first.
138
- const plain = starts && loaded.state === 'minted' ? plan.deltas.filter((delta) => !plan.layout.deltas.includes(delta)) : [];
139
- if (plain.some(isRaise)) return { code: 1, lines: [...bandWarnings, LAYOUT_GROWTH_LEAD, ...reasonRequiredLines(cwd, plain)], config, judged };
140
- if (plan.raises.length > 0 && reason === undefined) return { code: 1, lines: [...bandWarnings, ...reasonRequiredLines(cwd, plan.deltas, { layout: starts })], config, judged };
141
- const body = serialize(schema2Of(parsed), materialize(plan, reason));
142
- // Whether anything was written is decided by the BYTES, not by the delta count: completing a
143
- // hand-edited half record changes the file while raising nothing at all.
144
- const changed = body !== loaded.text;
145
- if (changed) writeRecord(cwd, body, deps);
146
- const written = writtenLines({ cwd, deltas: plan.deltas, reason: plan.raises.length > 0 ? reason : undefined, changed });
147
- return { code: 0, lines: [...warnings, ...movedLines(cwd, parsed), ...written], config, judged };
148
- };
149
-
150
- // --override: the projection under the CURRENT limits comes first, so an override's reason never
151
- // lands on drift it did not cause; only then is the override applied and the record regenerated
152
- // under the new limits, in the same atomic write.
153
- export const runOverride = ({ cwd, id, value, tolerance, kitDefault, reason, deps = {} }) => {
154
- assertDocsAiDeployment(cwd, deps, { stop: scopeFail, rel: SOURCE_SIZE_CONFIG_REL, noun: RECORD_NOUN });
155
- const { state, config, parsed, text, missingMachineKeys } = loadSourceSizeConfig(cwd, deps);
156
- if (state === 'absent') return { code: 1, lines: absentRefusalLines(cwd) };
157
- if (state !== 'minted') return { code: 1, lines: unmintedRefusalLines(cwd, { state, missing: missingMachineKeys }), config };
158
- const judged = { absent: false, layout: config.layout !== null };
159
- const current = planRecord({ config, verdict: judgeTree(cwd, config, deps, judged) });
160
- if (current.raises.length > 0) return { code: 1, lines: overrideOutgrownLines(cwd, current.deltas), config, judged };
161
- const resolved = config.limits[id];
162
- const filled = kitDefault ? null : { value: value ?? resolved.value, tolerance: tolerance ?? resolved.tolerance, reason };
163
- const kit = KIT_LIMITS[id];
164
- if (filled !== null && filled.tolerance === kit.tolerance && (kit.value === null || filled.value === kit.value)) {
165
- throw usageFail(`--override ${id} equals the kit's own numbers — pass --kit-default to return to them; the writer never writes an override equal to the kit's`);
166
- }
167
- const next = applyOverride(schema2Of(parsed), id, filled);
168
- const nextConfig = validateSourceSizeConfig(next);
169
- const { plan, warnings } = judgeForWrite(cwd, nextConfig, deps, judged);
170
- const body = serialize(next, materialize(plan, reason));
171
- if (body === text) return { code: 0, lines: [...warnings, ...overrideUnchangedLines(cwd, id)], config: nextConfig, judged };
172
- writeRecord(cwd, body, deps);
173
- return {
174
- code: 0,
175
- judged,
176
- lines: [
177
- ...warnings,
178
- ...overrideWrittenLines({ cwd, id, removed: kitDefault, reason }),
179
- ...movedLines(cwd, parsed),
180
- ...(plan.deltas.length === 0 ? [] : writtenLines({ cwd, deltas: plan.deltas, reason: plan.raises.length > 0 ? reason : undefined, changed: true })),
181
- ],
182
- config: nextConfig,
183
- };
184
- };
185
-
186
- // ── the adoption verb (D-16) ──────────────────────────────────────────────────────────────────────
187
-
188
- // Declaring the gate is delegated to the FILL's own consented apply, restricted to this one id: the
189
- // fill owns every rule about what a written declaration may look like (placement, id collisions, the
190
- // coverage invariant, the atomic write), and a second writer here would be a second set of those
191
- // rules — the one that drifts. `--adopt` is therefore a composition, never a re-implementation.
192
- //
193
- // The already-declared arm is checked FIRST and through the practice's own matcher: an earlier
194
- // partial run leaves a minted record and a declared gate, and re-running must converge rather than
195
- // collide. A gate that merely CARRIES the id without being this checker does not count — it reaches
196
- // the fill and collides there, loudly, which is the honest answer to a squatter.
197
- // The READ is inside the try with the write, deliberately: by the time this runs the record is
198
- // already minted, so ANY failure here — a malformed declaration the reader throws on, just as much
199
- // as a collision the fill refuses — must still report both halves. Letting the read escape would
200
- // surface a bare error carrying neither the mint that succeeded nor the exit contract this tool
201
- // documents.
202
- const declareGate = (cwd, deps) => {
203
- try {
204
- applyFill({ cwd, onlyIds: [SOURCE_SIZE_GATE_ID] }, deps);
205
- return { code: 0, lines: gateDeclaredLines(GATES_REL, SOURCE_SIZE_GATE_ID) };
206
- } catch (err) {
207
- return { code: 1, lines: gateRefusedLines(GATES_REL, err?.message ?? String(err)) };
208
- }
209
- };
210
-
211
- // Is the canonical gate ALREADY there? Asked through the practice's own matcher, so a gate that
212
- // merely carries the id — running something else entirely — never reads as adopted; it reaches the
213
- // fill and collides there, loudly, which is the honest answer to a squatter.
214
- //
215
- // An unreadable declaration is NOT a verdict here. This read is a shortcut, and aborting on it would
216
- // report an outcome before the record was settled; the fill re-reads the same file and refuses
217
- // authoritatively AFTER, so the partial report names both halves truthfully.
218
- const gateIsDeclared = (cwd, deps) => {
219
- try {
220
- const declaration = loadDeclaration(cwd, deps);
221
- return (declaration.outcome === 'loaded' ? declaration.gates : []).some((gate) => matchesSourceSizeGate(gate.cmd, cwd));
222
- } catch {
223
- return false;
224
- }
225
- };
12
+ import { KIT_LIMITS, commandReasonDefect, escapeForLine, reasonDefect } from './source-size-core.mjs';
13
+ import { HELP, escapeLeadingSpace, notJudgedLines, statedLimitLines } from './source-size-report.mjs';
14
+ import { CHECKER_NAME, ERROR_PREFIX, USAGE_REFUSAL, runAdopt, runCheck, runOverride, runWriteBaseline, usageFail } from './source-size-runs.mjs';
226
15
 
227
- // A MINTED record is RECOGNIZED, never regenerated. Adoption carries a PINNED reason — the advisor
228
- // renders it as a fixed string, and its item keeps firing while the gate is undeclared — so a
229
- // re-run after a partial adoption would let that one sentence raise whatever the tree grew in the
230
- // meantime. That is exactly the laundering the reason requirement exists to prevent, so the verb
231
- // asks the checker instead: a record that no longer holds is a ratchet question with its own
232
- // reasoned lane, and it must be answered BEFORE a gate is declared over it — declaring one that is
233
- // certain to red the matrix is what the offer rules refuse everywhere else.
234
- const recognizeRecord = ({ cwd, deps }) => {
235
- const verdict = runCheck({ cwd, deps });
236
- if (verdict.code !== 0) return { code: verdict.code, lines: [...verdict.lines, ...recordNoLongerHoldsLines(GATES_REL)] };
237
- return { code: 0, lines: recordRecognizedLines(cwd) };
238
- };
239
-
240
- // A MINTED schema-1 config is moved in its own write before adoption reads it as schema 2: the
241
- // authored half transformed, both machine records carried verbatim, nothing regenerated — so the
242
- // adoption reason can never ride a raise. An authored or incomplete one is moved by the mint itself.
243
- const moveMinted = (cwd, parsed, deps) => {
244
- writeRecord(cwd, serialize(schema2Of(parsed), { baseline: parsed.baseline, aggregate: parsed.aggregate }), deps);
245
- return movedLines(cwd, parsed);
246
- };
247
-
248
- // A stop after the move still prints the move: the write happened, and no stop may hide it.
249
- const reportingMove = (moved, run) => {
250
- try {
251
- return run();
252
- } catch (err) {
253
- throw Object.assign(err, { lines: [...moved, ...(err.lines ?? [])] });
254
- }
255
- };
256
-
257
- // --adopt = settle the record, then declare the gate. The order is not a preference: the fill offers
258
- // the gate ONLY over a minted config (declaring it earlier would declare a gate that refuses), so
259
- // the record is what makes the declaration offerable at all.
260
- export const runAdopt = ({ cwd, reason, deps = {} }) => {
261
- const { state, config, parsed } = loadSourceSizeConfig(cwd, deps);
262
- if (state === 'absent') return { code: 1, lines: adoptAbsentRefusalLines(cwd) };
263
- const moved = state === 'minted' && config.schema === 1 ? moveMinted(cwd, parsed, deps) : [];
264
- // ADOPTED is asked FIRST, and it is a question about the GATE alone. Idempotence cannot be made
265
- // conditional on the record still holding: a declared gate reports its own staleness on every run,
266
- // with the reasoned lane, and stopping here would tell a reader the gate was not declared while it
267
- // plainly is — which is exactly what re-running the advisor's one-liner on a drifted tree does.
268
- // Once the gate is there and the record is minted, nothing is left to adopt.
269
- const declared = gateIsDeclared(cwd, deps);
270
- if (declared && state === 'minted') return { code: 0, lines: [...moved, ...gateAlreadyDeclaredLines(GATES_REL)] };
271
- // Either half carries its OWN self-servable refusals (a raise with no reason, a project with no
272
- // docs/ai, a record the tree outgrew). They are returned unchanged: re-wording them here would be
273
- // the second practice this module exists to avoid, and each already names the step that clears it.
274
- const record = state === 'minted' ? reportingMove(moved, () => recognizeRecord({ cwd, deps })) : runWriteBaseline({ cwd, reason, deps });
275
- if (record.code !== 0) return { code: record.code, lines: [...moved, ...record.lines] };
276
- if (declared) return { code: 0, lines: [...moved, ...record.lines, ...gateAlreadyDeclaredLines(GATES_REL)] };
277
- const gate = declareGate(cwd, deps);
278
- return { code: gate.code, lines: [...moved, ...record.lines, ...gate.lines] };
279
- };
280
-
281
- // ── CLI ───────────────────────────────────────────────────────────────────────────────────────────
16
+ const HELP_LINES = HELP.split('\n');
17
+ const USAGE = HELP_LINES.slice(HELP_LINES.indexOf('Usage:')).slice(0, 6).join('\n');
282
18
 
283
19
  const MODES = Object.freeze(['--check', '--write-baseline', '--adopt', '--override']);
284
20
  const RUNS = Object.freeze({ '--check': runCheck, '--write-baseline': runWriteBaseline, '--adopt': runAdopt, '--override': runOverride });
@@ -348,7 +84,7 @@ export const main = (argv, ctx = {}) => {
348
84
  if (layout && mode !== '--write-baseline') throw usageFail(`${LAYOUT} belongs to --write-baseline — it starts the layout record`);
349
85
  if (reasonOption.value !== undefined) {
350
86
  if (mode === '--check') throw usageFail('--reason belongs to --write-baseline, --adopt and --override — a check records nothing');
351
- const defect = reasonDefect(reasonOption.value);
87
+ const defect = reasonDefect(reasonOption.value) ?? commandReasonDefect(reasonOption.value, { override: mode === '--override' });
352
88
  if (defect) throw usageFail(defect);
353
89
  } else if (mode === '--override') {
354
90
  throw usageFail('--override needs --reason "<text>" — an override is a reasoned change of a kit number');
@@ -357,22 +93,37 @@ export const main = (argv, ctx = {}) => {
357
93
  ? overrideOptions({ id: idOption.value, value: valueOption.value, tolerance: toleranceOption.value, kitDefault })
358
94
  : {};
359
95
  const deps = ctx.deps ?? {};
360
- const { code, lines, config, judged } = RUNS[mode]({ cwd, reason: reasonOption.value, layout, deps, ...override });
96
+ const { code, lines, block, config, judged, scope } = RUNS[mode]({ cwd, reason: reasonOption.value, layout, deps, ...override });
361
97
  const states = STATES_LIMITS.includes(mode) && config;
362
98
  const limits = states ? statedLimitLines(config) : [];
363
- const notJudged = states && judged ? notJudgedLines(cwd, { ...judged, config }) : [];
364
- return { code, stdout: [...limits, ...notJudged, ...lines].join('\n'), stderr: '' };
99
+ const notJudged = states && judged ? notJudgedLines(cwd, { ...judged, config, excluded: scope?.excluded }) : [];
100
+ const output = block ? composeRedBlock({ name: CHECKER_NAME, ...block, after: [...limits, ...notJudged, ...block.after] }) : [...limits, ...notJudged, ...lines];
101
+ return { code, stdout: output.join('\n'), stderr: '' };
365
102
  } catch (err) {
366
- return { code: err.exitCode ?? 1, stdout: (err.lines ?? []).join('\n'), stderr: `source-size-check: ${err.message}` };
103
+ if (err?.exitCode === undefined) throw err;
104
+ const message = err.message.startsWith(ERROR_PREFIX) ? err.message.slice(ERROR_PREFIX.length) : err.message;
105
+ const failed = escapeLeadingSpace(err[USAGE_REFUSAL] ? escapeForLine(message) : message);
106
+ const output = err[USAGE_REFUSAL] ? composeUsageRefusal({ name: CHECKER_NAME, failed, usage: USAGE })
107
+ : 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 ?? [] });
108
+ return { code: err.exitCode, stdout: output.join('\n'), stderr: '' };
367
109
  }
368
110
  };
369
111
 
112
+ export const guardedMain = (argv, ctx = {}) => {
113
+ const carried = [];
114
+ const result = guardChecker({ name: CHECKER_NAME, exitCode: 2, remedy: 'fix the cause the stack below names, then re-run' }, () => {
115
+ try { return main(argv, ctx); }
116
+ catch (err) { carried.push(...(err?.lines ?? [])); throw err; }
117
+ });
118
+ return result.lines ? { code: result.exitCode, stdout: [...result.lines, ...carried].join('\n'), stderr: '' } : result;
119
+ };
120
+
370
121
  // The realpath-compare direct-run predicate now lives in tools/direct-run.mjs (the fix this file
371
122
  // carried first, extracted so every module shares one implementation); `sameFile` stays exported here
372
123
  // because this module's tests bind it as a seam.
373
124
  export { sameFile };
374
125
  if (isDirectRun(import.meta.url)) {
375
- const result = main(process.argv.slice(2));
126
+ const result = guardedMain(process.argv.slice(2));
376
127
  if (result.stdout) process.stdout.write(result.stdout.endsWith('\n') ? result.stdout : `${result.stdout}\n`);
377
128
  if (result.stderr) process.stderr.write(result.stderr.endsWith('\n') ? result.stderr : `${result.stderr}\n`);
378
129
  process.exitCode = result.code;
@@ -26,9 +26,7 @@ export const SOURCE_SIZE_DEFAULTS = Object.freeze({
26
26
  maxLineBytes: KIT_LIMITS['bytes-per-line'].value,
27
27
  });
28
28
  export const REASON_MAX_BYTES = 300;
29
- // The reason a FIRST mint records: every value is new, so every value is a raise, and "this is what
30
- // the tree already carried when the practice arrived" is the honest sentence for all of them.
31
- export const INITIAL_ADOPTION_REASON = 'initial adoption';
29
+ export { INITIAL_ADOPTION_REASON } from './source-size/index.mjs';
32
30
  // The root an absent `roots` declares: every tracked path. Admitted only as the sole root.
33
31
  export const WHOLE_TREE_ROOT = '.';
34
32
  // The kit's own folder: taken away from every judgment by this fixed path, with no config key.
@@ -92,6 +92,13 @@ export {
92
92
  pilesOf,
93
93
  queueChecksOf,
94
94
  spliceLater,
95
+ helpText,
96
+ GROWTH_REASON_PLACEHOLDER,
97
+ halfOf,
98
+ presentHalves,
99
+ refusedRaises,
100
+ mintReasonOf,
101
+ commandReasonDefect,
95
102
  } from './source-size/index.mjs';
96
103
 
97
104
  export {
@@ -10,7 +10,7 @@
10
10
  //
11
11
  // Dependency-free, Node >= 22. No writes, no side effects on import.
12
12
 
13
- import { measureFile, resolveScope, specStoreEntries } from './source-size-scope.mjs';
13
+ import { measureFile, resolveScope, specStoreEntries, workTreeOf } from './source-size-scope.mjs';
14
14
  import { scopeFail } from './source-size-refusal.mjs';
15
15
  import { SPEC_STORE_ROOT, bandOf, changesFor, isRaise, layoutCounts, ownEntry, projectLayout } from './source-size/index.mjs';
16
16
 
@@ -32,17 +32,19 @@ export const recordFor = (measured, limits) => Object.fromEntries(
32
32
  );
33
33
 
34
34
  const BAND_KINDS = new Set(['within-band', 'root-band', 'dir-band']);
35
+ const WORK_TREE_KINDS = Object.freeze({ untracked: 'untracked', differing: 'unstaged' });
36
+ const STANDING_KINDS = new Set([...BAND_KINDS, ...Object.values(WORK_TREE_KINDS)]);
35
37
  // D-9: the unmechanizable question — real decomposition, or the same coupling spread thinner? — is
36
38
  // asked exactly where a record went DOWN or disappeared, and the checker itself raises it there.
37
39
  const LOWERED_KINDS = new Set(['stale', 'record-obsolete', 'entry-gone', 'root-stale', 'root-gone', 'dir-stale', 'dir-obsolete', 'dir-gone']);
38
40
 
39
41
  export const stopsOf = (findings) => findings.filter((f) => f.severity === STOP);
40
42
  export const warningsOf = (findings) => findings.filter((f) => f.severity === WARNING);
41
- export const bandWarningsOf = (findings) => findings.filter((f) => BAND_KINDS.has(f.kind));
43
+ export const bandWarningsOf = (findings) => findings.filter((f) => STANDING_KINDS.has(f.kind));
42
44
  // The warnings a write leaves standing: a value within its band, one whose obsolete record it drops included.
43
45
  const BAND_OF_OBSOLETE = Object.freeze({ 'record-obsolete': 'within-band', 'dir-obsolete': 'dir-band' });
44
46
  export const standingWarningsOf = (findings) => findings.flatMap((f) => {
45
- if (BAND_KINDS.has(f.kind)) return [f];
47
+ if (STANDING_KINDS.has(f.kind)) return [f];
46
48
  const kind = BAND_OF_OBSOLETE[f.kind];
47
49
  return kind && f.dimension !== 'depth' && f.actual > f.allowed && f.actual <= f.ceiling ? [{ ...f, kind }] : [];
48
50
  });
@@ -165,7 +167,8 @@ const judgeLayout = (cwd, config, scope, deps, { absent }) => {
165
167
  // refuses even when its size is recorded debt. An absent config's aggregate is no finding.
166
168
  export const judgeTree = (cwd, config, deps = {}, { layout = false, absent = false } = {}) => {
167
169
  const scope = resolveScope(cwd, config, deps);
168
- const measured = new Map(scope.files.map((rel) => [rel, measureFile(cwd, rel, deps)]));
170
+ const bytes = new Map();
171
+ const measured = new Map(scope.files.map((rel) => [rel, measureFile(cwd, rel, deps, (content) => bytes.set(rel, content))]));
169
172
  const projected = new Map(scope.files.map((rel) => [rel, recordFor(measured.get(rel), config.limits)]));
170
173
  const baseline = config.baseline ?? {};
171
174
  const findings = scope.files.flatMap((rel) => fileFindings(rel, measured.get(rel), projected.get(rel), ownEntry(baseline, rel), config.limits));
@@ -178,5 +181,8 @@ export const judgeTree = (cwd, config, deps = {}, { layout = false, absent = fal
178
181
  if (!absent) findings.push(...judgeAggregate(rootLines, config.aggregate ?? {}));
179
182
  const judged = layout ? judgeLayout(cwd, config, scope, deps, { absent }) : null;
180
183
  if (judged) findings.push(...judged.findings);
184
+ const tree = workTreeOf(cwd, config, { scope, bytes, layout }, deps);
185
+ findings.push(...Object.entries(WORK_TREE_KINDS).filter(([part]) => tree[part].length > 0)
186
+ .map(([part, kind]) => ({ kind, severity: WARNING, paths: tree[part] })));
181
187
  return { scope, measured, projected, rootLines, layout: judged, findings };
182
188
  };