vigiles 40.1.0 → 41.1.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.
Files changed (54) hide show
  1. package/dist/adapter.d.ts +1 -1
  2. package/dist/adapters/claude-code/skill-listing.d.ts +27 -5
  3. package/dist/adapters/claude-code/skill-listing.js +29 -1
  4. package/dist/adapters/codex/skill-listing.d.ts +22 -4
  5. package/dist/adapters/codex/skill-listing.js +30 -1
  6. package/dist/cli-main.d.ts +4 -3
  7. package/dist/cli-main.js +121 -25
  8. package/dist/context-creep-lint.d.ts +123 -0
  9. package/dist/context-creep-lint.js +397 -0
  10. package/dist/core/always-loaded-limits.d.ts +118 -0
  11. package/dist/core/always-loaded-limits.js +175 -0
  12. package/dist/core/always-loaded.d.ts +15 -1
  13. package/dist/core/always-loaded.js +9 -0
  14. package/dist/core/baseline-store.d.ts +183 -0
  15. package/dist/core/baseline-store.js +392 -0
  16. package/dist/core/instruction-weight.d.ts +3 -3
  17. package/dist/core/instruction-weight.js +3 -3
  18. package/dist/core/legacy-baseline.d.ts +70 -0
  19. package/dist/core/legacy-baseline.js +117 -0
  20. package/dist/core/rule-proof/kits/eslint.d.ts +30 -0
  21. package/dist/core/rule-proof/kits/eslint.js +130 -0
  22. package/dist/core/rule-proof/kits/index.d.ts +7 -0
  23. package/dist/core/rule-proof/kits/index.js +12 -0
  24. package/dist/core/rule-proof/kits/ruff.d.ts +28 -0
  25. package/dist/core/rule-proof/kits/ruff.js +178 -0
  26. package/dist/core/rule-proof/node-install.d.ts +32 -0
  27. package/dist/core/rule-proof/node-install.js +117 -0
  28. package/dist/core/rule-proof/pair.d.ts +11 -0
  29. package/dist/core/rule-proof/pair.js +61 -0
  30. package/dist/core/rule-proof/port.d.ts +77 -0
  31. package/dist/core/rule-proof/port.js +3 -0
  32. package/dist/core/rule-proof/report.d.ts +11 -0
  33. package/dist/core/rule-proof/report.js +36 -0
  34. package/dist/core/rule-proof/run.d.ts +58 -0
  35. package/dist/core/rule-proof/run.js +260 -0
  36. package/dist/core/rule-proof/types.d.ts +119 -0
  37. package/dist/core/rule-proof/types.js +13 -0
  38. package/dist/core/skill-listing.d.ts +24 -0
  39. package/dist/core/types.d.ts +14 -6
  40. package/dist/entries/rule-proof.d.ts +18 -0
  41. package/dist/entries/rule-proof.js +23 -0
  42. package/dist/host/rule-proof.io.d.ts +4 -0
  43. package/dist/host/rule-proof.io.js +64 -0
  44. package/dist/local-files.js +2 -2
  45. package/dist/rules/index.d.ts +25 -2
  46. package/dist/rules/index.js +22 -9
  47. package/dist/scan.js +27 -1
  48. package/dist/vigilesrc.schema.json +32 -0
  49. package/hooks/session-start.sh +4 -3
  50. package/package.json +2 -1
  51. package/dist/context-creep-ratchet.d.ts +0 -88
  52. package/dist/context-creep-ratchet.js +0 -270
  53. package/dist/core/instruction-baseline.d.ts +0 -333
  54. package/dist/core/instruction-baseline.js +0 -570
@@ -0,0 +1,397 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readBaselineStore = readBaselineStore;
4
+ exports.legacyFilesPresent = legacyFilesPresent;
5
+ exports.contextCreepRun = contextCreepRun;
6
+ exports.updateRefusals = updateRefusals;
7
+ exports.legacyLine = legacyLine;
8
+ exports.checkContextCreep = checkContextCreep;
9
+ exports.recordIfMissing = recordIfMissing;
10
+ exports.compileWeightLine = compileWeightLine;
11
+ /**
12
+ * `lint`'s side of the always-loaded check: measure each scored bundle, let
13
+ * the detector (`core/always-loaded-limits.ts`) say which parts are over the
14
+ * harness's limits, then apply the baseline store (`core/baseline-store.ts`)
15
+ * to those findings — and, only under the explicit `--update-baseline`, write
16
+ * the store.
17
+ *
18
+ * This module decides what is read, written and deleted — the store, and the
19
+ * file earlier releases wrote — and turns lines into lint counters and
20
+ * annotations. The bytes go through {@link BaselineFiles}, a port the
21
+ * composition root fills with the file system, so this module does no I/O of
22
+ * its own.
23
+ *
24
+ * WHY THE STORE IS COMMITTED, unlike `.vigiles/coverage.json`. Coverage records
25
+ * what tests ran on THIS machine. The store records a property of the COMMIT:
26
+ * every number in it is built from `committedTotal` and committed settings,
27
+ * which leave out per-machine files, so two clones of one commit compute
28
+ * byte-identical files. That is what lets CI compare against it.
29
+ *
30
+ * WHO WRITES. `lint` never does on its own — every default lint path is a read.
31
+ * `--update-baseline` writes the store while some bundle is over a limit and
32
+ * deletes it once nothing is; `init` writes it once on a repository that is
33
+ * over a limit and has none (`recordIfMissing`).
34
+ */
35
+ const baseline_store_js_1 = require("./core/baseline-store.js");
36
+ const always_loaded_limits_js_1 = require("./core/always-loaded-limits.js");
37
+ const legacy_baseline_js_1 = require("./core/legacy-baseline.js");
38
+ const instruction_remedies_js_1 = require("./core/instruction-remedies.js");
39
+ function readBaselineStore(files) {
40
+ const text = files.read(baseline_store_js_1.BASELINE_FILE);
41
+ return text === undefined ? { kind: "absent" } : (0, baseline_store_js_1.parseBaselineStore)(text);
42
+ }
43
+ /** Write the store, or delete the file when there is nothing left in it. */
44
+ function writeBaselineStore(files, store) {
45
+ if (store === undefined)
46
+ files.remove(baseline_store_js_1.BASELINE_FILE);
47
+ else
48
+ files.write(baseline_store_js_1.BASELINE_FILE, (0, baseline_store_js_1.serializeBaselineStore)(store));
49
+ }
50
+ /** The old baseline files present in this repository, newest name first. */
51
+ function legacyFilesPresent(files, ruleId) {
52
+ return (0, legacy_baseline_js_1.legacyBaselineFiles)(ruleId).filter((f) => files.read(f) !== undefined);
53
+ }
54
+ /** One bundle's check against its limits, or nothing to weigh. */
55
+ function limitCheck(m, limits) {
56
+ return m[1] === null
57
+ ? undefined
58
+ : (0, always_loaded_limits_js_1.checkAlwaysLoadedLimits)(m[1], m[2], limits.limits);
59
+ }
60
+ /**
61
+ * An import named and not read is weight this number lacks. Said on the
62
+ * finding itself, because the comparison is only as true as the sum.
63
+ */
64
+ function unfollowedNote(weight) {
65
+ return weight.unreadImports.length > 0
66
+ ? ` (${String(weight.unreadImports.length)} import(s) not followed: ${weight.unreadImports.join(", ")} — their size is not in this number)`
67
+ : "";
68
+ }
69
+ /** The over-limit finding for a bundle, carrying what the store records. */
70
+ function overLimitFinding(at, weight, loaded, check) {
71
+ return check.over.length === 0
72
+ ? []
73
+ : [
74
+ {
75
+ subject: at,
76
+ text: `${(0, always_loaded_limits_js_1.formatOverLimit)(check, at)}${unfollowedNote(weight)}`,
77
+ measurement: (0, always_loaded_limits_js_1.alwaysLoadedMeasurement)(weight, loaded),
78
+ },
79
+ ];
80
+ }
81
+ /** The findings one bundle produces: over a limit (acceptable), over the ceiling (never). */
82
+ function bundleFindings(m, limits) {
83
+ if (m[1] === null)
84
+ return [];
85
+ const [at, weight, loaded] = m;
86
+ const check = (0, always_loaded_limits_js_1.checkAlwaysLoadedLimits)(weight, loaded, limits.limits);
87
+ const ceiling = (0, always_loaded_limits_js_1.checkCeiling)(weight, limits.max);
88
+ return [
89
+ ...overLimitFinding(at, weight, loaded, check),
90
+ ...(ceiling === undefined
91
+ ? []
92
+ : [
93
+ {
94
+ subject: at,
95
+ text: (0, always_loaded_limits_js_1.formatCeiling)(ceiling, at, instruction_remedies_js_1.MOVE_OUT_OF_ALWAYS_LOADED),
96
+ },
97
+ ]),
98
+ ];
99
+ }
100
+ /** What the stateless rule reports for the store to act on. */
101
+ function contextCreepRun(ruleId, measured, limits) {
102
+ return {
103
+ ruleId,
104
+ findings: measured.flatMap((m) => bundleFindings(m, limits)),
105
+ measured: measured.flatMap((m) => (m[1] === null ? [] : [m[0]])),
106
+ gone: measured.flatMap((m) => (m[1] === null ? [m[0]] : [])),
107
+ unmeasured: Object.fromEntries(measured.flatMap(unmeasuredParts)),
108
+ remedy: instruction_remedies_js_1.MOVE_OUT_OF_ALWAYS_LOADED,
109
+ };
110
+ }
111
+ /** A measured bundle's parts this run could not measure, when it has any. */
112
+ function unmeasuredParts(m) {
113
+ if (m[1] === null)
114
+ return [];
115
+ const parts = Object.entries((0, always_loaded_limits_js_1.alwaysLoadedMeasurement)(m[1], m[2]).parts ?? {})
116
+ .filter(([, p]) => p.value === null)
117
+ .map(([name]) => name);
118
+ return parts.length === 0 ? [] : [[m[0], parts]];
119
+ }
120
+ /** Whether a bundle path is the scanned one or inside it (`.` covers every bundle). */
121
+ const inScope = (subject, scope) => scope === "." || subject === scope || subject.startsWith(`${scope}/`);
122
+ /**
123
+ * The run with every recorded bundle inside the scan's scope whose directory
124
+ * no longer exists added as gone — the one way an entry the scan did not
125
+ * measure may be dropped. Outside the scope nothing is touched.
126
+ */
127
+ function withGoneBundles(run, onDisk, files, scope) {
128
+ const seen = new Set([...run.measured, ...(run.gone ?? [])]);
129
+ const vanished = Object.keys((0, baseline_store_js_1.entriesOf)(onDisk, run.ruleId) ?? {}).filter((s) => !seen.has(s) && inScope(s, scope) && !files.exists(s));
130
+ return vanished.length === 0
131
+ ? run
132
+ : { ...run, gone: [...(run.gone ?? []), ...vanished] };
133
+ }
134
+ /** The bundles `--update-baseline` must not record: each one over the ceiling. */
135
+ function updateRefusals(measured, max) {
136
+ const text = {
137
+ file: baseline_store_js_1.BASELINE_FILE,
138
+ command: baseline_store_js_1.UPDATE_BASELINE_COMMAND,
139
+ remedy: instruction_remedies_js_1.MOVE_OUT_OF_ALWAYS_LOADED,
140
+ };
141
+ return measured.flatMap(([at, weight]) => {
142
+ const over = weight === null ? undefined : (0, always_loaded_limits_js_1.checkCeiling)(weight, max);
143
+ return over === undefined ? [] : [(0, always_loaded_limits_js_1.formatRefusal)(over, at, text)];
144
+ });
145
+ }
146
+ /** The line a repository with an old baseline file gets: a finding, naming the command. */
147
+ function legacyLine(file) {
148
+ return {
149
+ subject: ".",
150
+ status: "finding",
151
+ text: `${file} is no longer read: the always-loaded baseline moved to ${baseline_store_js_1.BASELINE_FILE}. ` +
152
+ `Migrate it with \`${baseline_store_js_1.UPDATE_BASELINE_COMMAND}\` — it carries every recorded bundle over with its recorded numbers (dropping only a bundle the run finds under its limits or gone) and deletes ${file}.`,
153
+ };
154
+ }
155
+ /**
156
+ * The bundles one old file hands the store. A bundle this run measured follows
157
+ * the normal rule — kept only while still over a limit — and keeps its
158
+ * RECORDED numbers, never a re-measure. A bundle this run did not look at (a
159
+ * scoped run, another bundle), or whose old entry recorded a part this run
160
+ * could not measure, is converted as recorded. A bundle the run measured under
161
+ * its limits — every recorded part measured — or found gone, is not carried.
162
+ */
163
+ function legacyEntries(legacy, run) {
164
+ const looked = new Set([...run.measured, ...(run.gone ?? [])]);
165
+ const scanned = run.findings.flatMap((f) => f.measurement === undefined ? [] : [{ at: f.subject, now: f.measurement }]);
166
+ const asked = new Set(scanned.map(({ at }) => at));
167
+ const unproven = Object.keys(legacy.file.bundles)
168
+ .filter((at) => !asked.has(at))
169
+ .map((at) => ({ at, now: undefined }));
170
+ return Object.fromEntries([...scanned, ...unproven].flatMap(({ at, now }) => {
171
+ const entry = (0, legacy_baseline_js_1.convertLegacyEntry)(legacy, at, now);
172
+ const proven = now === undefined &&
173
+ looked.has(at) &&
174
+ (0, baseline_store_js_1.unmeasuredRecorded)(run, at, entry).length === 0;
175
+ return entry === undefined || proven ? [] : [[at, entry]];
176
+ }));
177
+ }
178
+ /**
179
+ * The rule's entries after recording, with every old file folded in: the
180
+ * run's own entries ({@link entriesFor}), then each old file's bundles the
181
+ * store does not already hold, the newest file winning a bundle two of them
182
+ * record. Every entry of every readable old file is therefore either in the
183
+ * result or deliberately dropped (measured under its limits, or gone), which
184
+ * is what lets the caller delete the old files after writing.
185
+ */
186
+ function migrate(files, legacy, run, onDisk) {
187
+ const parsed = legacy.map((f) => ({
188
+ file: f,
189
+ old: (0, legacy_baseline_js_1.parseLegacyBaseline)(files.read(f) ?? ""),
190
+ }));
191
+ const stored = (0, baseline_store_js_1.entriesOf)(onDisk, run.ruleId) ?? {};
192
+ const carried = parsed.reduceRight((acc, { old }) => old.kind === "ok" ? { ...acc, ...legacyEntries(old, run) } : acc, {});
193
+ const unstored = Object.entries(carried).filter(([s]) => !Object.hasOwn(stored, s));
194
+ return {
195
+ entries: { ...(0, baseline_store_js_1.entriesFor)(onDisk, run), ...Object.fromEntries(unstored) },
196
+ migrated: parsed.flatMap((p) => (p.old.kind === "ok" ? [p.file] : [])),
197
+ unreadable: parsed.flatMap((p) => (p.old.kind === "ok" ? [] : [p.file])),
198
+ };
199
+ }
200
+ /** What `record` says about the store it wrote or removed. */
201
+ function wroteLine(next, onDisk) {
202
+ if (next !== undefined)
203
+ return `✓ recorded ${baseline_store_js_1.BASELINE_FILE}`;
204
+ return onDisk.kind === "ok"
205
+ ? `✓ nothing is over a limit — removed ${baseline_store_js_1.BASELINE_FILE}`
206
+ : "✓ nothing is over a limit — no baseline to record";
207
+ }
208
+ /** What `record` says about each old file it folded in. */
209
+ function migratedLines(plan) {
210
+ const empty = Object.keys(plan.entries).length === 0;
211
+ return [
212
+ ...plan.migrated.map((file) => empty
213
+ ? `✓ nothing is over a limit, so nothing in ${file} needed carrying over`
214
+ : `✓ migrated ${file} into ${baseline_store_js_1.BASELINE_FILE}, keeping its recorded numbers — run \`${baseline_store_js_1.UPDATE_BASELINE_COMMAND}\` again to accept the current size`),
215
+ ...plan.unreadable.map((file) => `✓ ${file} could not be read, so the current size was recorded instead`),
216
+ ];
217
+ }
218
+ /**
219
+ * Record the run, folding in every old baseline file (the old numbers carry
220
+ * over for each bundle the store does not hold yet). The store is written
221
+ * first and the old files deleted after, so an old file goes only once each of
222
+ * its entries is in the store or was dropped by the normal rule. Returns what
223
+ * to print.
224
+ */
225
+ function record(files, run, onDisk) {
226
+ const legacy = legacyFilesPresent(files, run.ruleId);
227
+ const plan = migrate(files, legacy, run, onDisk);
228
+ const next = (0, baseline_store_js_1.withEntries)(onDisk, run.ruleId, plan.entries);
229
+ writeBaselineStore(files, next);
230
+ legacy.forEach((f) => {
231
+ files.remove(f);
232
+ });
233
+ return [
234
+ wroteLine(next, onDisk),
235
+ ...migratedLines(plan),
236
+ ...legacy.map((f) => `✓ deleted ${f}`),
237
+ ];
238
+ }
239
+ /** The `--summary` notes: what the agent working in the repository should run. */
240
+ function summaryNotes(run, onDisk, legacy) {
241
+ const unrecorded = !(0, baseline_store_js_1.hasEntries)(onDisk, run.ruleId) &&
242
+ legacy.length === 0 &&
243
+ run.findings.some((f) => f.measurement !== undefined);
244
+ return [
245
+ ...(unrecorded
246
+ ? [
247
+ `always-loaded context is over the harness's limit and no baseline is recorded — run \`${baseline_store_js_1.UPDATE_BASELINE_COMMAND}\` and commit ${baseline_store_js_1.BASELINE_FILE}`,
248
+ ]
249
+ : []),
250
+ ...legacy.map((f) => legacyLine(f).text),
251
+ ];
252
+ }
253
+ const MARKS = { ok: "✓", note: "ℹ" };
254
+ function printReport(lines, recorded, severity) {
255
+ console.log("\nContext creep (always-loaded context):\n");
256
+ recorded.forEach((r) => {
257
+ console.log(` ${r}`);
258
+ });
259
+ const finding = severity === "error" ? "✗" : "⚠";
260
+ lines.forEach((l) => {
261
+ const mark = l.status === "finding" ? finding : MARKS[l.status];
262
+ console.log(` ${mark} ${l.text}`);
263
+ });
264
+ }
265
+ /** `--update-baseline`: refuse over the ceiling, else record. Returns what it printed and refused. */
266
+ function update(opts, measured, run) {
267
+ if (!opts.update)
268
+ return { recorded: [], refusals: 0 };
269
+ const refusals = updateRefusals(measured, opts.max);
270
+ refusals.forEach((message) => {
271
+ console.error(`✗ ${message}`);
272
+ opts.annotate("error", message);
273
+ });
274
+ return refusals.length > 0
275
+ ? { recorded: [], refusals: refusals.length }
276
+ : {
277
+ recorded: record(opts.files, run, readBaselineStore(opts.files)),
278
+ refusals: 0,
279
+ };
280
+ }
281
+ /** Annotate every finding at the rule's level and every summary note as a notice. */
282
+ function annotateAll(opts, findings, notes) {
283
+ const level = opts.severity === "error" ? "error" : "warning";
284
+ findings.forEach((l) => {
285
+ opts.annotate(level, l.text);
286
+ });
287
+ notes.forEach((note) => {
288
+ opts.annotate("notice", note);
289
+ });
290
+ }
291
+ /** The rule's run over the measured bundles, with vanished in-scope bundles marked gone. */
292
+ const scopedRun = (opts, measured) => withGoneBundles(contextCreepRun(opts.ruleId, measured, opts), readBaselineStore(opts.files), opts.files, opts.scope);
293
+ /** Run the check for `lint`: record if asked, then print, annotate, count. */
294
+ function checkContextCreep(opts) {
295
+ const { severity, files, ruleId } = opts;
296
+ if (!severity && !opts.update)
297
+ return { issues: 0, errors: 0, notes: [] };
298
+ const measured = opts.measure();
299
+ const run = scopedRun(opts, measured);
300
+ const { recorded, refusals } = update(opts, measured, run);
301
+ const onDisk = readBaselineStore(files);
302
+ const legacy = legacyFilesPresent(files, ruleId);
303
+ const lines = severity
304
+ ? [...(0, baseline_store_js_1.applyBaseline)(run, onDisk), ...legacy.map(legacyLine)]
305
+ : [];
306
+ if (!opts.silent && (opts.update || lines.length > 0)) {
307
+ printReport(lines, recorded, severity);
308
+ }
309
+ const findings = lines.filter((l) => l.status === "finding");
310
+ const notes = severity ? summaryNotes(run, onDisk, legacy) : [];
311
+ annotateAll(opts, findings, notes);
312
+ const counted = severity === "error" ? findings.length : 0;
313
+ return {
314
+ issues: findings.length + refusals,
315
+ errors: counted + refusals,
316
+ notes,
317
+ };
318
+ }
319
+ /** "skill-listing is 7,530 chars, over the limit of 6,000", per over part. */
320
+ function overParts(measured, limits) {
321
+ const g = (x) => x.toLocaleString("en-US");
322
+ return measured.flatMap((m) => {
323
+ const check = limitCheck(m, limits);
324
+ const where = m[0] === "." ? "" : `${m[0]}: `;
325
+ return (check?.over ?? []).map((p) => `${where}${p.part} is ${g(p.size)} ${check?.unit ?? ""}, over the limit of ${g(p.limit)}`);
326
+ });
327
+ }
328
+ /** The entries a fresh run over `measured` would write that `existing` lacks. */
329
+ function missingEntries(ruleId, measured, limits, existing) {
330
+ const fresh = (0, baseline_store_js_1.entriesFor)({ kind: "absent" }, contextCreepRun(ruleId, measured, limits));
331
+ return Object.entries(fresh).filter(([s]) => !Object.hasOwn(existing, s));
332
+ }
333
+ /** `init`'s summary for the bundles it just added: each over-limit part of those only. */
334
+ function recordedOutcome(measured, limits, added) {
335
+ const subjects = new Set(added.map(([s]) => s));
336
+ return {
337
+ kind: "recorded",
338
+ file: baseline_store_js_1.BASELINE_FILE,
339
+ over: overParts(measured.filter((m) => subjects.has(m[0])), limits),
340
+ };
341
+ }
342
+ /**
343
+ * `init`'s step: record every bundle over a limit that has no entry yet, so
344
+ * the gate starts from today's size. An existing entry is never overwritten
345
+ * (a rerun adds only the bundles that are missing), and nothing is measured
346
+ * over an old file — that is what migrating is for, and re-measuring would
347
+ * accept unseen growth.
348
+ */
349
+ function recordIfMissing(files, ruleId, measured, limits) {
350
+ const onDisk = readBaselineStore(files);
351
+ if (onDisk.kind === "invalid")
352
+ return { kind: "kept", file: baseline_store_js_1.BASELINE_FILE };
353
+ const legacy = legacyFilesPresent(files, ruleId)[0];
354
+ if (legacy !== undefined) {
355
+ return { kind: "legacy", file: legacy, command: baseline_store_js_1.UPDATE_BASELINE_COMMAND };
356
+ }
357
+ const existing = (0, baseline_store_js_1.entriesOf)(onDisk, ruleId) ?? {};
358
+ const missing = missingEntries(ruleId, measured, limits, existing);
359
+ if (missing.length === 0) {
360
+ return Object.keys(existing).length > 0
361
+ ? { kind: "kept", file: baseline_store_js_1.BASELINE_FILE }
362
+ : { kind: "under-limits" };
363
+ }
364
+ writeBaselineStore(files, (0, baseline_store_js_1.withEntries)(onDisk, ruleId, {
365
+ ...existing,
366
+ ...Object.fromEntries(missing),
367
+ }));
368
+ return recordedOutcome(measured, limits, missing);
369
+ }
370
+ /** Where the size stands against the store, in a few words, for `compile`. */
371
+ function compileStatus(line) {
372
+ if (line?.status === "ok")
373
+ return "held at the baseline";
374
+ if (line?.status === "finding")
375
+ return "grew past the baseline — `vigiles lint` fails";
376
+ return "not a finding — `vigiles lint` says why";
377
+ }
378
+ /**
379
+ * The line `compile` prints after writing instruction files: the size now,
380
+ * against each limit, and against the baseline when over one. Report-only —
381
+ * `lint` stays the single gate. `null` when there is nothing to weigh.
382
+ */
383
+ function compileWeightLine(files, ruleId, measured, limits) {
384
+ const check = limitCheck(measured, limits);
385
+ if (check === undefined || measured[1] === null)
386
+ return null;
387
+ const g = (x) => x.toLocaleString("en-US");
388
+ const parts = check.parts
389
+ .map((p) => `${p.part} ${g(p.size)}/${g(p.limit)}`)
390
+ .join(" · ");
391
+ const head = `always-loaded context: ${g(measured[2].total)} ${check.unit} — ${parts}`;
392
+ if (check.over.length === 0)
393
+ return `${head} (under every limit)`;
394
+ const line = (0, baseline_store_js_1.applyBaseline)(contextCreepRun(ruleId, [measured], limits), readBaselineStore(files)).find((l) => l.subject === measured[0]);
395
+ return `${head} (over a limit; ${compileStatus(line)})`;
396
+ }
397
+ //# sourceMappingURL=context-creep-lint.js.map
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Is what the harness loads at session start over the HARNESS'S OWN limits?
3
+ * The one detector behind the `context-creep` rule and the audit's
4
+ * always-loaded block, so the two can never disagree about which part is over.
5
+ *
6
+ * WHY A FIXED LIMIT, AND WHICH. No threshold here is vigiles's invention: each
7
+ * adapter supplies the number its harness publishes or acts on, per part, read
8
+ * from the pinned release (each `capturedFrom` names the artifact):
9
+ *
10
+ * - instructions — the instruction budget (`InstructionBudget.limit`). The
11
+ * selected output style loads beside the instructions and has no limit of
12
+ * its own, so it is counted with them against this one;
13
+ * - skill listing — the listing budget (`SkillListingBudget`), past which the
14
+ * harness drops skill descriptions. A committed setting can move it.
15
+ *
16
+ * WHY THE LIMIT DOES NOT GATE ON ITS OWN. Real repositories sit several times
17
+ * over the instruction budget, and a rule that fails every one of them on day
18
+ * one is switched off on day one. So a part over its limit is a finding the
19
+ * rule PRODUCES, carrying the measured sizes, and the baseline store
20
+ * (`./baseline-store.ts`) decides afterwards whether the repository already
21
+ * accepted that size: green at any size it recorded, red the day it grows. A
22
+ * repository under every limit produces nothing, needs no file, and may grow
23
+ * freely up to the limit.
24
+ *
25
+ * WHY THE SUM IS WHAT IS RECORDED. The measurement handed to the store is the
26
+ * whole always-loaded context with its parts, not the part that is over: text
27
+ * moved from the instructions into a skill description or the selected style
28
+ * still loads on every request, and a per-part number would read that move as a
29
+ * shrink (`./always-loaded.ts`).
30
+ *
31
+ * Pure.
32
+ */
33
+ import type { AlwaysLoadedContext } from "./always-loaded.js";
34
+ import type { InstructionWeight } from "./instruction-weight.js";
35
+ import type { Measurement } from "./baseline-store.js";
36
+ /** The parts a limit applies to. The output style counts with the instructions. */
37
+ export type LimitedPart = "instructions" | "skill-listing";
38
+ /** Per-repository overrides, from the rule's options in `.vigilesrc.json`. */
39
+ export type LimitOverrides = Readonly<Partial<Record<LimitedPart, number>>>;
40
+ /** Where a limit came from — said in the message, so a reader can move it. */
41
+ export type LimitSource = {
42
+ readonly kind: "harness";
43
+ } | {
44
+ readonly kind: "setting";
45
+ readonly name: string;
46
+ } | {
47
+ readonly kind: "config";
48
+ };
49
+ /** One part against its limit. */
50
+ export interface PartLimit {
51
+ readonly part: LimitedPart;
52
+ readonly size: number;
53
+ readonly limit: number;
54
+ readonly source: LimitSource;
55
+ /** What the harness does past it — said as a consequence, not a cost. */
56
+ readonly onExceed: "warns" | "truncates" | "drops-descriptions";
57
+ }
58
+ /** Every part that has a limit, and which of them are over. */
59
+ export interface LimitCheck {
60
+ readonly unit: "chars" | "bytes";
61
+ /** Every limited part this harness and commit have, in print order. */
62
+ readonly parts: readonly PartLimit[];
63
+ /** The parts strictly over their limit. */
64
+ readonly over: readonly PartLimit[];
65
+ }
66
+ /** Check each limited part against its limit. */
67
+ export declare function checkAlwaysLoadedLimits(weight: InstructionWeight, loaded: AlwaysLoadedContext, overrides?: LimitOverrides): LimitCheck;
68
+ /**
69
+ * Which measurement produced a recorded context-creep number — bumped whenever
70
+ * a release changes what counts in ANY part (chain membership, how a listing
71
+ * entry is rendered), so consumers see one "re-record" verdict instead of
72
+ * growth attributed to their own files.
73
+ */
74
+ export declare const ALWAYS_LOADED_MEASURE = 1;
75
+ /**
76
+ * The always-loaded context as the store records it: the scored instruction
77
+ * files (never a per-machine one), the selected style and the listing.
78
+ */
79
+ export declare function alwaysLoadedMeasurement(weight: InstructionWeight, loaded: AlwaysLoadedContext): Measurement;
80
+ /** What happens past a limit, as a behaviour. */
81
+ export declare const CONSEQUENCE: Readonly<Record<PartLimit["onExceed"], string>>;
82
+ /** Where the limit came from, in words. */
83
+ export declare function describeSource(source: LimitSource): string;
84
+ /** One over-limit part, as a line. */
85
+ export declare function describeOver(p: PartLimit, unit: string): string;
86
+ /** The finding text for a bundle with at least one part over its limit. */
87
+ export declare function formatOverLimit(check: LimitCheck, at: string): string;
88
+ /** One file's size, for naming where the weight is. */
89
+ export interface FileWeight {
90
+ readonly path: string;
91
+ readonly size: number;
92
+ }
93
+ /**
94
+ * A total above the opt-in absolute ceiling (`["error", { max }]`) — unlike a
95
+ * limit, a ceiling no baseline lifts. Decided on the scored instructions
96
+ * (`committedTotal`) in the harness's unit, without looking at the store: that
97
+ * independence is what makes it a ceiling.
98
+ */
99
+ export interface CeilingVerdict {
100
+ readonly total: number;
101
+ readonly max: number;
102
+ readonly unit: "chars" | "bytes";
103
+ /** The scored files, heaviest first — where the cut has to come from. */
104
+ readonly largest: readonly FileWeight[];
105
+ }
106
+ /** `undefined` when the weight is at or under `max`, or when no ceiling is set. */
107
+ export declare function checkCeiling(weight: InstructionWeight, max: number | undefined): CeilingVerdict | undefined;
108
+ /** The message for a total over the ceiling, prefixed by its bundle. */
109
+ export declare function formatCeiling(verdict: CeilingVerdict, at: string, remedy: string): string;
110
+ /** What a refusal names: the file it did not write, the command to rerun, the cure. */
111
+ export interface RefusalText {
112
+ readonly file: string;
113
+ readonly command: string;
114
+ readonly remedy: string;
115
+ }
116
+ /** Why `--update-baseline` wrote nothing: a ceiling the baseline would have sat above. */
117
+ export declare function formatRefusal(verdict: CeilingVerdict, at: string, { file, command, remedy }: RefusalText): string;
118
+ //# sourceMappingURL=always-loaded-limits.d.ts.map