vigiles 40.0.0 → 41.0.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/README.md +9 -8
- package/dist/adapter.d.ts +1 -1
- package/dist/adapters/claude-code/skill-listing.d.ts +27 -5
- package/dist/adapters/claude-code/skill-listing.js +29 -1
- package/dist/adapters/codex/skill-listing.d.ts +22 -4
- package/dist/adapters/codex/skill-listing.js +30 -1
- package/dist/audit-report.template.html +33 -43
- package/dist/cli-main.d.ts +4 -3
- package/dist/cli-main.js +121 -25
- package/dist/context-creep-lint.d.ts +123 -0
- package/dist/context-creep-lint.js +397 -0
- package/dist/core/always-loaded-limits.d.ts +118 -0
- package/dist/core/always-loaded-limits.js +175 -0
- package/dist/core/always-loaded.d.ts +15 -1
- package/dist/core/always-loaded.js +9 -0
- package/dist/core/baseline-store.d.ts +183 -0
- package/dist/core/baseline-store.js +392 -0
- package/dist/core/instruction-weight.d.ts +3 -3
- package/dist/core/instruction-weight.js +3 -3
- package/dist/core/legacy-baseline.d.ts +70 -0
- package/dist/core/legacy-baseline.js +117 -0
- package/dist/core/skill-listing.d.ts +24 -0
- package/dist/core/types.d.ts +14 -6
- package/dist/local-files.js +2 -2
- package/dist/rules/index.d.ts +25 -2
- package/dist/rules/index.js +22 -9
- package/dist/scan.js +27 -1
- package/dist/vigilesrc.schema.json +32 -0
- package/hooks/session-start.sh +4 -3
- package/package.json +1 -1
- package/dist/context-creep-ratchet.d.ts +0 -88
- package/dist/context-creep-ratchet.js +0 -270
- package/dist/core/instruction-baseline.d.ts +0 -333
- package/dist/core/instruction-baseline.js +0 -570
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.INSTRUCTION_WEIGHT_MEASURE = exports.LOADED_PART_NAMES = exports.LOADED_PART_MEASURE = exports.INSTRUCTION_BASELINE_VERSION = exports.UPDATE_BASELINE_COMMAND = exports.REMOVE_LEGACY_BASELINE_COMMAND = exports.RENAME_BASELINE_COMMAND = exports.LEGACY_INSTRUCTION_BASELINE_FILE = exports.INSTRUCTION_BASELINE_FILE = void 0;
|
|
4
|
-
exports.legacyBaselineNote = legacyBaselineNote;
|
|
5
|
-
exports.parseInstructionBaseline = parseInstructionBaseline;
|
|
6
|
-
exports.entryFor = entryFor;
|
|
7
|
-
exports.compareToBaseline = compareToBaseline;
|
|
8
|
-
exports.carryUnmeasured = carryUnmeasured;
|
|
9
|
-
exports.compareAlwaysLoadedToBaseline = compareAlwaysLoadedToBaseline;
|
|
10
|
-
exports.checkCeiling = checkCeiling;
|
|
11
|
-
exports.recordEntries = recordEntries;
|
|
12
|
-
exports.serializeBaseline = serializeBaseline;
|
|
13
|
-
exports.formatVerdict = formatVerdict;
|
|
14
|
-
exports.formatBaselineVerdict = formatBaselineVerdict;
|
|
15
|
-
exports.describeUnmeasured = describeUnmeasured;
|
|
16
|
-
exports.formatUnrecordedParts = formatUnrecordedParts;
|
|
17
|
-
exports.formatCeiling = formatCeiling;
|
|
18
|
-
exports.formatRefusal = formatRefusal;
|
|
19
|
-
exports.formatWeightLine = formatWeightLine;
|
|
20
|
-
/**
|
|
21
|
-
* The context-creep RATCHET: the always-loaded weight may not grow past
|
|
22
|
-
* what the repository itself last recorded.
|
|
23
|
-
*
|
|
24
|
-
* WHY A RATCHET AND NOT THE BUDGET. `./instruction-weight.ts` explains why the
|
|
25
|
-
* harness's own threshold cannot gate: real repositories sit several times over
|
|
26
|
-
* it, and a rule that fails every repo on day one is switched off on day one.
|
|
27
|
-
* What CAN gate is the repository's own past. The baseline is whatever the repo
|
|
28
|
-
* weighed when it was last recorded, so a repo four times over budget starts
|
|
29
|
-
* green — and stays green only while it does not get heavier. The measured case
|
|
30
|
-
* this exists for: a root instruction file cut from ~4 100 lines to ~1 900, then
|
|
31
|
-
* regrown by ~1 000 lines over ten ordinary commits, with nothing in CI to say so.
|
|
32
|
-
*
|
|
33
|
-
* WHY THE SUM, AGAIN. The baseline records `committedTotal`, the same number the
|
|
34
|
-
* audit report scores: everything the harness loads without being asked that a
|
|
35
|
-
* teammate on the same commit also loads. A per-file baseline would read text
|
|
36
|
-
* moved into an always-loaded sibling as a shrink — the evasion the weight
|
|
37
|
-
* module was built to see through. The per-file sizes are recorded too, but only
|
|
38
|
-
* so a message can say WHICH file moved; the verdict is decided on the total.
|
|
39
|
-
*
|
|
40
|
-
* WHY A SHRINK IS A FINDING TOO. A baseline left above the tree is headroom, and
|
|
41
|
-
* headroom is exactly where the regrowth above landed: every character up to the
|
|
42
|
-
* old number would pass. So, like ESLint's unpruned suppressions and `betterer
|
|
43
|
-
* ci`, a tree LIGHTER than its baseline asks for the baseline to be lowered —
|
|
44
|
-
* one command, in the same change that made the cut. The baseline then always
|
|
45
|
-
* equals the tree on the default branch, and any growth at all is a diff a
|
|
46
|
-
* reviewer sees.
|
|
47
|
-
*
|
|
48
|
-
* WHO WRITES IT. Never `lint` on its own: a read never writes. The file is
|
|
49
|
-
* written only by the explicit `vigiles lint --update-baseline`, the same shape
|
|
50
|
-
* as `eslint --suppress-all` / `--prune-suppressions` and `jest -u`. Raising the
|
|
51
|
-
* baseline is allowed and is the point: growth is not forbidden, it is made
|
|
52
|
-
* visible as a reviewed diff of a committed file.
|
|
53
|
-
*
|
|
54
|
-
* VERSION 2 — THE ALWAYS-LOADED CONTEXT. The output style the committed settings select
|
|
55
|
-
* and the skill listing load at session start exactly as the instructions do
|
|
56
|
-
* (`./always-loaded.ts`), so a section moved from `CLAUDE.md` into either is
|
|
57
|
-
* the same relocation the sum above exists to see. A version-2 entry carries
|
|
58
|
-
* them as `parts`, each with its own `measure`, and the verdict is decided on
|
|
59
|
-
* the SUM of the instructions and every recorded part. Per part, so a change
|
|
60
|
-
* to how one part is measured asks to re-record that part by name.
|
|
61
|
-
*
|
|
62
|
-
* ⚠️ THE TRADE-OFF OF A STRICT FILE, stated rather than hidden. Version 1 was
|
|
63
|
-
* read with `.strict()` and `z.literal(1)`, so there is no extension of it an
|
|
64
|
-
* OLDER vigiles accepts: it reads a version-2 file as "cannot be read", which
|
|
65
|
-
* is a finding at the rule's severity — red CI wherever lint still runs the old
|
|
66
|
-
* release, the moment one teammate re-records. Loud, never silent, but red. The
|
|
67
|
-
* alternative, a sibling file old readers ignore, would split one gated sum
|
|
68
|
-
* across two files, so that a move from one to the other read as a shrink in
|
|
69
|
-
* each. What keeps the cost small:
|
|
70
|
-
*
|
|
71
|
-
* - a repo still on version 1 is read as before — the instructions gate as
|
|
72
|
-
* they did, and each new part that is not zero is a NOTE, never a finding,
|
|
73
|
-
* so upgrading vigiles never turns CI red;
|
|
74
|
-
* - `--update-baseline` writes version 2 only when some part is not zero, so
|
|
75
|
-
* a repo with no output style and no listed skill keeps a version-1 file
|
|
76
|
-
* every release reads — and, once a file is version 2, keeps it there even
|
|
77
|
-
* when every part drops to zero, so re-adding a part is growth, not a note;
|
|
78
|
-
* - the note and the rule doc say to upgrade vigiles wherever lint runs
|
|
79
|
-
* BEFORE re-recording.
|
|
80
|
-
*
|
|
81
|
-
* Pure: parsing, comparison and formatting only. Reading and writing the file
|
|
82
|
-
* is the caller's (`src/context-creep-ratchet.ts`).
|
|
83
|
-
*/
|
|
84
|
-
const zod_1 = require("zod");
|
|
85
|
-
const instruction_remedies_js_1 = require("./instruction-remedies.js");
|
|
86
|
-
/** Where the baseline lives, relative to the directory `.vigilesrc.json` is read from. */
|
|
87
|
-
exports.INSTRUCTION_BASELINE_FILE = ".vigiles/context-creep.json";
|
|
88
|
-
/**
|
|
89
|
-
* The name this baseline had before the rule became `context-creep`. Still
|
|
90
|
-
* READ when the new file is absent (a repo upgrading keeps its ratchet), never
|
|
91
|
-
* written; {@link legacyBaselineNote} tells the author how to move it.
|
|
92
|
-
*/
|
|
93
|
-
exports.LEGACY_INSTRUCTION_BASELINE_FILE = ".vigiles/instruction-weight.json";
|
|
94
|
-
/** The command that renames the old baseline — quoted verbatim by the note. */
|
|
95
|
-
exports.RENAME_BASELINE_COMMAND = `git mv ${exports.LEGACY_INSTRUCTION_BASELINE_FILE} ${exports.INSTRUCTION_BASELINE_FILE}`;
|
|
96
|
-
/** The command that drops a stale old baseline once the new one exists. */
|
|
97
|
-
exports.REMOVE_LEGACY_BASELINE_COMMAND = `git rm ${exports.LEGACY_INSTRUCTION_BASELINE_FILE}`;
|
|
98
|
-
/**
|
|
99
|
-
* The one-sentence NOTE (never a finding) for a repo that still has the old
|
|
100
|
-
* file, or `undefined` when it has not. The exact command is in the text: the
|
|
101
|
-
* session-start hook injects `lint --summary` into the agent, and the agent
|
|
102
|
-
* runs the command.
|
|
103
|
-
*/
|
|
104
|
-
function legacyBaselineNote(legacy) {
|
|
105
|
-
switch (legacy) {
|
|
106
|
-
case "none":
|
|
107
|
-
return undefined;
|
|
108
|
-
case "only":
|
|
109
|
-
return `${exports.LEGACY_INSTRUCTION_BASELINE_FILE} is the old name of the context-creep baseline (still read) — rename it with \`${exports.RENAME_BASELINE_COMMAND}\``;
|
|
110
|
-
case "both":
|
|
111
|
-
return `${exports.LEGACY_INSTRUCTION_BASELINE_FILE} is stale: ${exports.INSTRUCTION_BASELINE_FILE} is read instead — delete it with \`${exports.REMOVE_LEGACY_BASELINE_COMMAND}\``;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/** The command that writes the baseline — named once, quoted by every message. */
|
|
115
|
-
exports.UPDATE_BASELINE_COMMAND = "vigiles lint --update-baseline";
|
|
116
|
-
/**
|
|
117
|
-
* The newest on-disk shape this release reads and writes. Bumped only on an
|
|
118
|
-
* incompatible change. Version 1 is still read, and still WRITTEN when no
|
|
119
|
-
* always-loaded part has anything in it — see the header for why.
|
|
120
|
-
*/
|
|
121
|
-
exports.INSTRUCTION_BASELINE_VERSION = 2;
|
|
122
|
-
/**
|
|
123
|
-
* Which measurement produced a recorded PART — the same job as
|
|
124
|
-
* {@link INSTRUCTION_WEIGHT_MEASURE}, per part, so a change to how the skill
|
|
125
|
-
* listing is rendered re-records the listing and names it.
|
|
126
|
-
*/
|
|
127
|
-
exports.LOADED_PART_MEASURE = 1;
|
|
128
|
-
/** The parts a version-2 entry may carry, in the order they are printed. */
|
|
129
|
-
exports.LOADED_PART_NAMES = [
|
|
130
|
-
"output-style",
|
|
131
|
-
"skill-listing",
|
|
132
|
-
];
|
|
133
|
-
/**
|
|
134
|
-
* Which MEASUREMENT produced a recorded number — bumped whenever a release
|
|
135
|
-
* changes what counts (chain membership in any adapter, how a file is sized),
|
|
136
|
-
* even when the file shape stays the same.
|
|
137
|
-
*
|
|
138
|
-
* Without it, a vigiles fix that moves a file into or out of the chain moves
|
|
139
|
-
* `committedTotal` on every consumer with a committed baseline, and they see
|
|
140
|
-
* `grew`/`shrank` attributed to their own content. With it, they see one
|
|
141
|
-
* "re-record" verdict that names the cause. `version` cannot do this job: it
|
|
142
|
-
* describes the file, not the number in it.
|
|
143
|
-
*/
|
|
144
|
-
exports.INSTRUCTION_WEIGHT_MEASURE = 1;
|
|
145
|
-
const SUM_MESSAGE = "`total` is not the sum of `files` — the file was edited by hand; re-record it";
|
|
146
|
-
const sumsUp = (e) => Object.values(e.files).reduce((a, b) => a + b, 0) === e.total;
|
|
147
|
-
const partSchema = zod_1.z
|
|
148
|
-
.object({
|
|
149
|
-
measure: zod_1.z.number().int().nonnegative(),
|
|
150
|
-
total: zod_1.z.number().int().nonnegative(),
|
|
151
|
-
files: zod_1.z.record(zod_1.z.string(), zod_1.z.number().int().nonnegative()),
|
|
152
|
-
})
|
|
153
|
-
.strict()
|
|
154
|
-
.refine(sumsUp, { message: SUM_MESSAGE });
|
|
155
|
-
const entrySchema = zod_1.z
|
|
156
|
-
.object({
|
|
157
|
-
unit: zod_1.z.enum(["chars", "bytes"]),
|
|
158
|
-
measure: zod_1.z.number().int().nonnegative(),
|
|
159
|
-
total: zod_1.z.number().int().nonnegative(),
|
|
160
|
-
files: zod_1.z.record(zod_1.z.string(), zod_1.z.number().int().nonnegative()),
|
|
161
|
-
/** Version 2 only: the always-loaded parts beside the instructions. */
|
|
162
|
-
parts: zod_1.z
|
|
163
|
-
.object({
|
|
164
|
-
"output-style": partSchema.optional(),
|
|
165
|
-
"skill-listing": partSchema.optional(),
|
|
166
|
-
})
|
|
167
|
-
.strict()
|
|
168
|
-
.optional(),
|
|
169
|
-
})
|
|
170
|
-
.strict()
|
|
171
|
-
.refine(sumsUp, { message: SUM_MESSAGE });
|
|
172
|
-
const baselineSchema = zod_1.z
|
|
173
|
-
.object({
|
|
174
|
-
version: zod_1.z.union([zod_1.z.literal(1), zod_1.z.literal(exports.INSTRUCTION_BASELINE_VERSION)]),
|
|
175
|
-
/** Keyed by bundle location from the config root; `.` is the root itself. */
|
|
176
|
-
bundles: zod_1.z.record(zod_1.z.string(), entrySchema),
|
|
177
|
-
})
|
|
178
|
-
.strict()
|
|
179
|
-
.refine((b) => b.version !== 1 ||
|
|
180
|
-
Object.values(b.bundles).every((e) => e.parts === undefined), { message: "`parts` needs `version: 2` — re-record the file" });
|
|
181
|
-
function parseInstructionBaseline(text) {
|
|
182
|
-
const json = (() => {
|
|
183
|
-
try {
|
|
184
|
-
return { ok: true, value: JSON.parse(text) };
|
|
185
|
-
}
|
|
186
|
-
catch {
|
|
187
|
-
return { ok: false };
|
|
188
|
-
}
|
|
189
|
-
})();
|
|
190
|
-
if (!json.ok)
|
|
191
|
-
return { kind: "invalid", message: "not valid JSON" };
|
|
192
|
-
const parsed = baselineSchema.safeParse(json.value);
|
|
193
|
-
return parsed.success
|
|
194
|
-
? { kind: "ok", baseline: parsed.data }
|
|
195
|
-
: {
|
|
196
|
-
kind: "invalid",
|
|
197
|
-
message: parsed.error.issues
|
|
198
|
-
.map((i) => `${i.path.join(".") || "(top level)"}: ${i.message}`)
|
|
199
|
-
.join("; "),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
const sortedFiles = (files) => Object.fromEntries([...files]
|
|
203
|
-
.sort((a, b) => a.path.localeCompare(b.path))
|
|
204
|
-
.map((f) => [f.path, f.size]));
|
|
205
|
-
/** A part as it would be recorded, or nothing when it adds nothing. */
|
|
206
|
-
function partEntry(part) {
|
|
207
|
-
return part.kind === "counted" && part.total > 0
|
|
208
|
-
? {
|
|
209
|
-
measure: exports.LOADED_PART_MEASURE,
|
|
210
|
-
total: part.total,
|
|
211
|
-
files: sortedFiles(part.files),
|
|
212
|
-
}
|
|
213
|
-
: undefined;
|
|
214
|
-
}
|
|
215
|
-
/** The parts of an always-loaded that would be recorded, by name. */
|
|
216
|
-
function partEntries(loaded) {
|
|
217
|
-
if (loaded === undefined)
|
|
218
|
-
return undefined;
|
|
219
|
-
const byName = {
|
|
220
|
-
"output-style": partEntry(loaded.outputStyle),
|
|
221
|
-
"skill-listing": partEntry(loaded.skillListing),
|
|
222
|
-
};
|
|
223
|
-
const kept = Object.entries(byName).filter(([, p]) => p !== undefined);
|
|
224
|
-
return kept.length === 0 ? undefined : Object.fromEntries(kept);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* What a measured weight would be recorded as: the SCORED files only, plus
|
|
228
|
-
* every always-loaded part that is not zero when one is handed in.
|
|
229
|
-
*/
|
|
230
|
-
function entryFor(weight, loaded) {
|
|
231
|
-
const scored = weight.files.filter((f) => f.scope === "repo");
|
|
232
|
-
const parts = partEntries(loaded);
|
|
233
|
-
return {
|
|
234
|
-
unit: weight.unit,
|
|
235
|
-
measure: exports.INSTRUCTION_WEIGHT_MEASURE,
|
|
236
|
-
total: weight.committedTotal,
|
|
237
|
-
files: sortedFiles(scored),
|
|
238
|
-
...(parts === undefined ? {} : { parts }),
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function changesBetween(before, after) {
|
|
242
|
-
const paths = [...new Set([...Object.keys(before), ...Object.keys(after)])];
|
|
243
|
-
const size = (m, p) => Object.hasOwn(m, p) ? m[p] : null;
|
|
244
|
-
return paths
|
|
245
|
-
.map((path) => ({ path, from: size(before, path), to: size(after, path) }))
|
|
246
|
-
.filter((c) => c.from !== c.to)
|
|
247
|
-
.sort((a, b) => Math.abs((b.to ?? 0) - (b.from ?? 0)) -
|
|
248
|
-
Math.abs((a.to ?? 0) - (a.from ?? 0)) || a.path.localeCompare(b.path));
|
|
249
|
-
}
|
|
250
|
-
function compareToBaseline(weight, recorded) {
|
|
251
|
-
return compareEntries(entryFor(weight), recorded);
|
|
252
|
-
}
|
|
253
|
-
/** A recorded number some other measurement produced — of a part, when named. */
|
|
254
|
-
function measureChanged(recorded, current, part) {
|
|
255
|
-
return {
|
|
256
|
-
kind: "measure-changed",
|
|
257
|
-
recorded,
|
|
258
|
-
current,
|
|
259
|
-
...(part === undefined ? {} : { part }),
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
/** The verdict between two entries, decided on `total`. */
|
|
263
|
-
function compareEntries(current, recorded) {
|
|
264
|
-
if (recorded === undefined)
|
|
265
|
-
return { kind: "unrecorded", current };
|
|
266
|
-
if (recorded.unit !== current.unit) {
|
|
267
|
-
return {
|
|
268
|
-
kind: "unit-changed",
|
|
269
|
-
recorded: recorded.unit,
|
|
270
|
-
current: current.unit,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
if (recorded.measure !== current.measure) {
|
|
274
|
-
return measureChanged(recorded.measure, current.measure);
|
|
275
|
-
}
|
|
276
|
-
if (current.total === recorded.total) {
|
|
277
|
-
return { kind: "held", total: current.total, unit: current.unit };
|
|
278
|
-
}
|
|
279
|
-
return {
|
|
280
|
-
kind: current.total > recorded.total ? "grew" : "shrank",
|
|
281
|
-
from: recorded.total,
|
|
282
|
-
to: current.total,
|
|
283
|
-
unit: current.unit,
|
|
284
|
-
changes: changesBetween(recorded.files, current.files),
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
const PART_LABEL = {
|
|
288
|
-
"output-style": "output style",
|
|
289
|
-
"skill-listing": "skill listing",
|
|
290
|
-
};
|
|
291
|
-
/**
|
|
292
|
-
* One entry with its parts folded in: the total is the always-loaded sum, and each
|
|
293
|
-
* part's files are named with the part, so a `grew` message says which part a
|
|
294
|
-
* file moved in. In memory only — never written.
|
|
295
|
-
*/
|
|
296
|
-
function folded(entry) {
|
|
297
|
-
const parts = exports.LOADED_PART_NAMES.flatMap((name) => {
|
|
298
|
-
const part = entry.parts?.[name];
|
|
299
|
-
return part === undefined ? [] : [{ name, part }];
|
|
300
|
-
});
|
|
301
|
-
return {
|
|
302
|
-
unit: entry.unit,
|
|
303
|
-
measure: entry.measure,
|
|
304
|
-
total: parts.reduce((sum, p) => sum + p.part.total, entry.total),
|
|
305
|
-
files: Object.fromEntries([
|
|
306
|
-
...Object.entries(entry.files),
|
|
307
|
-
...parts.flatMap(({ name, part }) => Object.entries(part.files).map(([path, size]) => [
|
|
308
|
-
`${path} (${PART_LABEL[name]})`,
|
|
309
|
-
size,
|
|
310
|
-
])),
|
|
311
|
-
]),
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
/** Each part's size on both sides; a part recorded on neither side is left out. */
|
|
315
|
-
function movesBetween(current, recorded) {
|
|
316
|
-
const parts = exports.LOADED_PART_NAMES.flatMap((part) => {
|
|
317
|
-
const from = recorded.parts?.[part]?.total;
|
|
318
|
-
const to = current.parts?.[part]?.total;
|
|
319
|
-
return from === undefined && to === undefined
|
|
320
|
-
? []
|
|
321
|
-
: [{ part, from: from ?? 0, to: to ?? 0 }];
|
|
322
|
-
});
|
|
323
|
-
return [
|
|
324
|
-
{ part: "instructions", from: recorded.total, to: current.total },
|
|
325
|
-
...parts,
|
|
326
|
-
];
|
|
327
|
-
}
|
|
328
|
-
/** The first part whose recorded measurement is not this release's. */
|
|
329
|
-
function partMeasureChanged(current, recorded) {
|
|
330
|
-
const changed = exports.LOADED_PART_NAMES.find((name) => {
|
|
331
|
-
const was = recorded.parts?.[name]?.measure;
|
|
332
|
-
const now = current.parts?.[name]?.measure;
|
|
333
|
-
return was !== undefined && now !== undefined && was !== now;
|
|
334
|
-
});
|
|
335
|
-
if (changed === undefined)
|
|
336
|
-
return undefined;
|
|
337
|
-
return measureChanged(recorded.parts?.[changed]?.measure ?? 0, exports.LOADED_PART_MEASURE, changed);
|
|
338
|
-
}
|
|
339
|
-
const partOf = (loaded, name) => name === "output-style" ? loaded.outputStyle : loaded.skillListing;
|
|
340
|
-
/**
|
|
341
|
-
* `current` with every recorded part this run cannot measure carried over from
|
|
342
|
-
* `recorded`, and the list of those parts. `counted` and `none` are measured —
|
|
343
|
-
* `none` is a real zero — so they are never carried.
|
|
344
|
-
*/
|
|
345
|
-
function carryUnmeasured(current, loaded, recorded) {
|
|
346
|
-
const carried = exports.LOADED_PART_NAMES.flatMap((name) => {
|
|
347
|
-
const was = recorded?.parts?.[name];
|
|
348
|
-
const now = partOf(loaded, name);
|
|
349
|
-
return was === undefined || now.kind === "counted" || now.kind === "none"
|
|
350
|
-
? []
|
|
351
|
-
: [{ name, was, kind: now.kind }];
|
|
352
|
-
});
|
|
353
|
-
if (carried.length === 0)
|
|
354
|
-
return { entry: current, unmeasured: [] };
|
|
355
|
-
const parts = Object.fromEntries([
|
|
356
|
-
...Object.entries(current.parts ?? {}),
|
|
357
|
-
...carried.map(({ name, was }) => [name, was]),
|
|
358
|
-
]);
|
|
359
|
-
return {
|
|
360
|
-
entry: { ...current, parts },
|
|
361
|
-
unmeasured: carried.map(({ name, was, kind }) => ({
|
|
362
|
-
part: name,
|
|
363
|
-
kind,
|
|
364
|
-
recorded: was.total,
|
|
365
|
-
})),
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function compareAlwaysLoadedToBaseline(weight, loaded, recorded, file) {
|
|
369
|
-
const measuredNow = entryFor(weight, loaded);
|
|
370
|
-
const sumGated = file === exports.INSTRUCTION_BASELINE_VERSION ||
|
|
371
|
-
(file === "absent" && measuredNow.parts !== undefined);
|
|
372
|
-
if (!sumGated) {
|
|
373
|
-
return {
|
|
374
|
-
kind: "instructions-only",
|
|
375
|
-
verdict: compareToBaseline(weight, recorded),
|
|
376
|
-
unrecordedParts: exports.LOADED_PART_NAMES.flatMap((part) => {
|
|
377
|
-
const total = measuredNow.parts?.[part]?.total;
|
|
378
|
-
return total === undefined ? [] : [{ part, total }];
|
|
379
|
-
}),
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
return compareSum(measuredNow, loaded, recorded);
|
|
383
|
-
}
|
|
384
|
-
/** The `always-loaded` verdict: the sum, with unmeasurable recorded parts carried. */
|
|
385
|
-
function compareSum(measuredNow, loaded, recorded) {
|
|
386
|
-
if (recorded === undefined) {
|
|
387
|
-
return {
|
|
388
|
-
kind: "always-loaded",
|
|
389
|
-
verdict: { kind: "unrecorded", current: folded(measuredNow) },
|
|
390
|
-
byPart: [],
|
|
391
|
-
unmeasured: [],
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
const { entry: current, unmeasured } = carryUnmeasured(measuredNow, loaded, recorded);
|
|
395
|
-
return {
|
|
396
|
-
kind: "always-loaded",
|
|
397
|
-
verdict: partMeasureChanged(current, recorded) ??
|
|
398
|
-
compareEntries(folded(current), folded(recorded)),
|
|
399
|
-
byPart: movesBetween(current, recorded),
|
|
400
|
-
unmeasured,
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
/** How many of the heaviest files a ceiling message names. */
|
|
404
|
-
const CEILING_NAMED_FILES = 5;
|
|
405
|
-
/** `undefined` when the weight is at or under `max`, or when no ceiling is set. */
|
|
406
|
-
function checkCeiling(weight, max) {
|
|
407
|
-
if (max === undefined)
|
|
408
|
-
return undefined;
|
|
409
|
-
const { total, unit, files } = entryFor(weight);
|
|
410
|
-
if (total <= max)
|
|
411
|
-
return undefined;
|
|
412
|
-
return {
|
|
413
|
-
total,
|
|
414
|
-
max,
|
|
415
|
-
unit,
|
|
416
|
-
largest: Object.entries(files)
|
|
417
|
-
.map(([path, size]) => ({ path, size }))
|
|
418
|
-
.sort((a, b) => b.size - a.size || a.path.localeCompare(b.path))
|
|
419
|
-
.slice(0, CEILING_NAMED_FILES),
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
/** Replace the measured bundles' entries; `null` removes one. Others are kept. */
|
|
423
|
-
function recordEntries(previous, measured) {
|
|
424
|
-
const removed = new Set(measured.filter(([, e]) => e === null).map(([at]) => at));
|
|
425
|
-
const kept = Object.entries(previous?.bundles ?? {}).filter(([at]) => !removed.has(at));
|
|
426
|
-
const fresh = measured.flatMap(([at, e]) => e === null ? [] : [[at, e]]);
|
|
427
|
-
const bundles = Object.fromEntries([...new Map([...kept, ...fresh]).entries()].sort(([a], [b]) => a.localeCompare(b)));
|
|
428
|
-
// Version 2 when some entry carries a part — see the header: a repo with
|
|
429
|
-
// nothing to add keeps a file every release can read — OR when the file was
|
|
430
|
-
// already version 2. A version is a one-way door: writing version 1 after a
|
|
431
|
-
// repo dropped its last skill or its style would turn a re-added part from
|
|
432
|
-
// growth of the gated sum into a note, so a legitimate cut, recorded,
|
|
433
|
-
// would silently switch off the gate the repo opted into.
|
|
434
|
-
const withParts = Object.values(bundles).some((e) => e.parts !== undefined);
|
|
435
|
-
const wasSumGated = previous?.version === exports.INSTRUCTION_BASELINE_VERSION;
|
|
436
|
-
return {
|
|
437
|
-
version: withParts || wasSumGated ? exports.INSTRUCTION_BASELINE_VERSION : 1,
|
|
438
|
-
bundles,
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
/** Stable text: sorted keys, two-space indent, trailing newline, no timestamp. */
|
|
442
|
-
function serializeBaseline(baseline) {
|
|
443
|
-
return `${JSON.stringify(baseline, null, 2)}\n`;
|
|
444
|
-
}
|
|
445
|
-
const n = (x) => x.toLocaleString("en-US");
|
|
446
|
-
const signed = (x) => (x > 0 ? `+${n(x)}` : n(x));
|
|
447
|
-
function describeChange(c) {
|
|
448
|
-
if (c.from === null)
|
|
449
|
-
return `${c.path} +${n(c.to ?? 0)} (new)`;
|
|
450
|
-
if (c.to === null)
|
|
451
|
-
return `${c.path} -${n(c.from)} (gone)`;
|
|
452
|
-
return `${c.path} ${signed(c.to - c.from)}`;
|
|
453
|
-
}
|
|
454
|
-
/** A re-record request: what counts changed in vigiles, not in the files. */
|
|
455
|
-
function measureChangedText(verdict, where) {
|
|
456
|
-
const whose = verdict.part === undefined ? "" : `'s ${PART_LABEL[verdict.part]}`;
|
|
457
|
-
return (`${where}the context-creep baseline${whose} was recorded by measurement ${String(verdict.recorded)}, this vigiles uses ${String(verdict.current)} — ` +
|
|
458
|
-
`what counts changed in vigiles, not in your files. Re-record it with \`${exports.UPDATE_BASELINE_COMMAND}\``);
|
|
459
|
-
}
|
|
460
|
-
/** The one-paragraph message a verdict prints as, prefixed by its bundle. */
|
|
461
|
-
function formatVerdict(verdict, at, subject = "always-loaded instructions") {
|
|
462
|
-
const where = at === "." ? "" : `${at}: `;
|
|
463
|
-
switch (verdict.kind) {
|
|
464
|
-
case "unrecorded":
|
|
465
|
-
return (`${where}no context-creep baseline recorded (${n(verdict.current.total)} ${verdict.current.unit} always loaded) — ` +
|
|
466
|
-
`run \`${exports.UPDATE_BASELINE_COMMAND}\` and commit ${exports.INSTRUCTION_BASELINE_FILE} to stop it growing unnoticed`);
|
|
467
|
-
case "unit-changed":
|
|
468
|
-
return (`${where}the context-creep baseline is in ${verdict.recorded} but this harness counts ${verdict.current} — ` +
|
|
469
|
-
`re-record it with \`${exports.UPDATE_BASELINE_COMMAND}\``);
|
|
470
|
-
case "measure-changed":
|
|
471
|
-
return measureChangedText(verdict, where);
|
|
472
|
-
case "held":
|
|
473
|
-
return `${where}${subject} held at ${n(verdict.total)} ${verdict.unit} (baseline)`;
|
|
474
|
-
case "grew":
|
|
475
|
-
case "shrank":
|
|
476
|
-
return movedText(verdict, `${where}${subject}`);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
/** A grew/shrank message: the delta, every file that moved, and what to do. */
|
|
480
|
-
function movedText(verdict, who) {
|
|
481
|
-
const head = `${n(verdict.from)} → ${n(verdict.to)} ${verdict.unit} (${signed(verdict.to - verdict.from)})`;
|
|
482
|
-
const moved = verdict.changes.length > 0
|
|
483
|
-
? ` Changed: ${verdict.changes.map(describeChange).join(", ")}.`
|
|
484
|
-
: "";
|
|
485
|
-
return verdict.kind === "grew"
|
|
486
|
-
? `${who} grew ${head} over the recorded baseline.${moved} ` +
|
|
487
|
-
`If the growth is intended, record it with \`${exports.UPDATE_BASELINE_COMMAND}\` — the diff of ${exports.INSTRUCTION_BASELINE_FILE} is the review. If it is not:\n${instruction_remedies_js_1.MOVE_OUT_OF_ALWAYS_LOADED}`
|
|
488
|
-
: `${who} shrank ${head}; the baseline still allows the old weight.${moved} ` +
|
|
489
|
-
`Lock the cut in with \`${exports.UPDATE_BASELINE_COMMAND}\`, or the headroom can be regrown without a finding.`;
|
|
490
|
-
}
|
|
491
|
-
/** "instructions 24,665 · output style 8,616 (+200) · skill listing 31,210". */
|
|
492
|
-
function describeMoves(moves) {
|
|
493
|
-
return moves
|
|
494
|
-
.map((m) => {
|
|
495
|
-
const label = m.part === "instructions" ? "instructions" : PART_LABEL[m.part];
|
|
496
|
-
const delta = m.to === m.from ? "" : ` (${signed(m.to - m.from)})`;
|
|
497
|
-
return `${label} ${n(m.to)}${delta}`;
|
|
498
|
-
})
|
|
499
|
-
.join(" · ");
|
|
500
|
-
}
|
|
501
|
-
/** The message for one bundle's {@link BaselineVerdict}, prefixed by its bundle. */
|
|
502
|
-
function formatBaselineVerdict(verdict, at) {
|
|
503
|
-
if (verdict.kind === "instructions-only") {
|
|
504
|
-
return formatVerdict(verdict.verdict, at);
|
|
505
|
-
}
|
|
506
|
-
const text = formatVerdict(verdict.verdict, at, "always-loaded context");
|
|
507
|
-
const lines = [
|
|
508
|
-
text,
|
|
509
|
-
...(verdict.byPart.length === 0 ? [] : [describeMoves(verdict.byPart)]),
|
|
510
|
-
...verdict.unmeasured.map(describeUnmeasured),
|
|
511
|
-
];
|
|
512
|
-
return lines.join("\n ");
|
|
513
|
-
}
|
|
514
|
-
/** Why a recorded part was carried: the run could not measure it, not a cut. */
|
|
515
|
-
function describeUnmeasured(u) {
|
|
516
|
-
return (`${PART_LABEL[u.part]}: recorded ${n(u.recorded)}, not measured in this run (${u.kind}) — ` +
|
|
517
|
-
`carried at its recorded size, not compared and not dropped by \`${exports.UPDATE_BASELINE_COMMAND}\``);
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* The NOTE a version-1 file gets for each part that is not zero: always
|
|
521
|
-
* loaded, not yet in the baseline, and what recording it does — including the
|
|
522
|
-
* one cost of recording, an older vigiles reading the new file as unreadable.
|
|
523
|
-
*/
|
|
524
|
-
function formatUnrecordedParts(parts, unit, at) {
|
|
525
|
-
const where = at === "." ? "" : `${at}: `;
|
|
526
|
-
const what = parts
|
|
527
|
-
.map((p) => `${PART_LABEL[p.part]} (${n(p.total)} ${unit})`)
|
|
528
|
-
.join(" and ");
|
|
529
|
-
return (`${where}${what} load at session start but are not in the baseline — ` +
|
|
530
|
-
`\`${exports.UPDATE_BASELINE_COMMAND}\` adds them (the file becomes version 2) and the gate becomes their sum with the instructions. ` +
|
|
531
|
-
`Upgrade vigiles wherever lint runs first: an older release cannot read version 2 and reports the file as unreadable.`);
|
|
532
|
-
}
|
|
533
|
-
/** The message for a total over the ceiling, prefixed by its bundle. */
|
|
534
|
-
function formatCeiling(verdict, at) {
|
|
535
|
-
const where = at === "." ? "" : `${at}: `;
|
|
536
|
-
const biggest = verdict.largest
|
|
537
|
-
.map((f) => `${f.path} ${n(f.size)}`)
|
|
538
|
-
.join(", ");
|
|
539
|
-
return (`${where}always-loaded instructions are ${n(verdict.total)} ${verdict.unit}, ` +
|
|
540
|
-
`max ${n(verdict.max)} — ${n(verdict.total - verdict.max)} over. ` +
|
|
541
|
-
`Largest: ${biggest}.\n` +
|
|
542
|
-
`${instruction_remedies_js_1.MOVE_OUT_OF_ALWAYS_LOADED}\n` +
|
|
543
|
-
`Moving text to another always-loaded file does not help, ` +
|
|
544
|
-
`and re-recording the baseline does not lift the ceiling.`);
|
|
545
|
-
}
|
|
546
|
-
/** Why `--update-baseline` wrote nothing: the ceiling it would have been recorded above. */
|
|
547
|
-
function formatRefusal(verdict, at) {
|
|
548
|
-
const where = at === "." ? "" : `${at}: `;
|
|
549
|
-
return (`${where}refusing to record ${exports.INSTRUCTION_BASELINE_FILE}: ` +
|
|
550
|
-
`${n(verdict.total)} ${verdict.unit} is over the configured max ${n(verdict.max)} ` +
|
|
551
|
-
`(${n(verdict.total - verdict.max)} over). A baseline above the ceiling would bypass it — ` +
|
|
552
|
-
`get under it first, then run \`${exports.UPDATE_BASELINE_COMMAND}\` again.\n${instruction_remedies_js_1.MOVE_OUT_OF_ALWAYS_LOADED}`);
|
|
553
|
-
}
|
|
554
|
-
/** The compile-time one-liner: weight now, against the baseline when there is one. */
|
|
555
|
-
function formatWeightLine(verdict, label = "always-loaded") {
|
|
556
|
-
switch (verdict.kind) {
|
|
557
|
-
case "unrecorded":
|
|
558
|
-
return `${label}: ${n(verdict.current.total)} ${verdict.current.unit} (no baseline — \`${exports.UPDATE_BASELINE_COMMAND}\`)`;
|
|
559
|
-
case "unit-changed":
|
|
560
|
-
return `${label}: baseline is in ${verdict.recorded}, this harness counts ${verdict.current}`;
|
|
561
|
-
case "measure-changed":
|
|
562
|
-
return `${label}: baseline recorded by measurement ${String(verdict.recorded)}, this vigiles uses ${String(verdict.current)} — re-record`;
|
|
563
|
-
case "held":
|
|
564
|
-
return `${label}: ${n(verdict.total)} ${verdict.unit} (baseline ${n(verdict.total)}, ±0)`;
|
|
565
|
-
case "grew":
|
|
566
|
-
case "shrank":
|
|
567
|
-
return `${label}: ${n(verdict.to)} ${verdict.unit} (baseline ${n(verdict.from)}, ${signed(verdict.to - verdict.from)})`;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
//# sourceMappingURL=instruction-baseline.js.map
|