vigiles 40.1.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/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/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
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasEntries = exports.recordRun = exports.entriesOf = exports.BASELINE_STORE_VERSION = exports.UPDATE_BASELINE_COMMAND = exports.BASELINE_FILE = void 0;
|
|
4
|
+
exports.readJson = readJson;
|
|
5
|
+
exports.parseBaselineStore = parseBaselineStore;
|
|
6
|
+
exports.serializeBaselineStore = serializeBaselineStore;
|
|
7
|
+
exports.toEntry = toEntry;
|
|
8
|
+
exports.unmeasuredRecorded = unmeasuredRecorded;
|
|
9
|
+
exports.applyBaseline = applyBaseline;
|
|
10
|
+
exports.withEntries = withEntries;
|
|
11
|
+
exports.entriesFor = entriesFor;
|
|
12
|
+
/**
|
|
13
|
+
* The BASELINE STORE: one committed file, `.vigiles/baseline.json`, holding the
|
|
14
|
+
* size each rule last ACCEPTED for each thing it measures. A rule stays
|
|
15
|
+
* stateless — it measures, compares against a fixed limit and reports what is
|
|
16
|
+
* over — and this module, applied AFTER the rule has produced its findings,
|
|
17
|
+
* decides which of those findings the repository already accepted. The shape
|
|
18
|
+
* of ESLint's bulk suppressions ("suppressions are applied after cache
|
|
19
|
+
* retrieval"), betterer's results file and the `--update-baseline` flag of
|
|
20
|
+
* several static analysers: the rule never reads the store, the store never
|
|
21
|
+
* knows how a rule measures.
|
|
22
|
+
*
|
|
23
|
+
* WHY ONE FILE FOR EVERY RULE. A second rule that ratchets (a file length, a
|
|
24
|
+
* per-file count) needs the same four things: a number per subject, a
|
|
25
|
+
* direction, a measurement version and a reviewed diff when the number moves.
|
|
26
|
+
* Keyed by rule id and then by subject, every such rule shares the reader, the
|
|
27
|
+
* writer, the schema and the messages, and a re-record of one rule never
|
|
28
|
+
* touches another's entries.
|
|
29
|
+
*
|
|
30
|
+
* WHAT AN ENTRY SAYS. `value` in `unit`, recorded by `measure` (bumped when a
|
|
31
|
+
* release changes what counts, so a vigiles change reads as "re-record", not
|
|
32
|
+
* as growth the author made), and `direction`: `shrink-only` is the one
|
|
33
|
+
* direction today — the number may hold or fall, never rise. `parts` is an
|
|
34
|
+
* optional breakdown that sums to `value`, so a message can say which part
|
|
35
|
+
* moved; each part may name its files for the same reason.
|
|
36
|
+
*
|
|
37
|
+
* THE VERDICT, per finding that carries a measurement:
|
|
38
|
+
*
|
|
39
|
+
* - no entry for the rule at all → a NOTE naming the command: a repository
|
|
40
|
+
* over a limit starts green and is told how to accept its current size;
|
|
41
|
+
* - entries for the rule, none for this subject → a finding: weight that
|
|
42
|
+
* appeared after the baseline was recorded is weight nobody signed off on;
|
|
43
|
+
* - another unit or measure → a finding asking to re-record;
|
|
44
|
+
* - at the stored value → held; below it → a finding asking to record the
|
|
45
|
+
* lower number, because a baseline above the tree is headroom that can be
|
|
46
|
+
* regrown unseen (the stale-entry rule of PHPStan, Psalm, ESLint's unpruned
|
|
47
|
+
* suppressions and `betterer ci`);
|
|
48
|
+
* above it → a finding, with what moved.
|
|
49
|
+
*
|
|
50
|
+
* And per stored entry whose subject produced no such finding: a NOTE that the
|
|
51
|
+
* entry can go (`--update-baseline` drops it), because the subject is now
|
|
52
|
+
* under its limit or is no longer measured.
|
|
53
|
+
*
|
|
54
|
+
* Pure: parsing, comparison, recording and formatting. Reading and writing the
|
|
55
|
+
* file is the caller's.
|
|
56
|
+
*/
|
|
57
|
+
const zod_1 = require("zod");
|
|
58
|
+
/** Where the store lives, relative to the directory `.vigilesrc.json` is read from. */
|
|
59
|
+
exports.BASELINE_FILE = ".vigiles/baseline.json";
|
|
60
|
+
/** The command that writes the store — named once, quoted by every message. */
|
|
61
|
+
exports.UPDATE_BASELINE_COMMAND = "vigiles lint --update-baseline";
|
|
62
|
+
/** The on-disk shape this release reads and writes. */
|
|
63
|
+
exports.BASELINE_STORE_VERSION = 1;
|
|
64
|
+
const size = zod_1.z.number().int().nonnegative();
|
|
65
|
+
const sumOf = (xs) => xs.reduce((a, b) => a + b, 0);
|
|
66
|
+
const partSchema = zod_1.z
|
|
67
|
+
.object({
|
|
68
|
+
value: size,
|
|
69
|
+
files: zod_1.z.record(zod_1.z.string(), size).optional(),
|
|
70
|
+
})
|
|
71
|
+
.strict()
|
|
72
|
+
.refine((p) => p.files === undefined || sumOf(Object.values(p.files)) === p.value, {
|
|
73
|
+
message: "`value` is not the sum of `files` — edited by hand; re-record it",
|
|
74
|
+
});
|
|
75
|
+
const entrySchema = zod_1.z
|
|
76
|
+
.object({
|
|
77
|
+
direction: zod_1.z.literal("shrink-only"),
|
|
78
|
+
unit: zod_1.z.string().min(1),
|
|
79
|
+
measure: zod_1.z.number().int().nonnegative(),
|
|
80
|
+
value: size,
|
|
81
|
+
parts: zod_1.z.record(zod_1.z.string(), partSchema).optional(),
|
|
82
|
+
})
|
|
83
|
+
.strict()
|
|
84
|
+
.refine((e) => e.parts === undefined ||
|
|
85
|
+
sumOf(Object.values(e.parts).map((p) => p.value)) === e.value, {
|
|
86
|
+
message: "`value` is not the sum of `parts` — edited by hand; re-record it",
|
|
87
|
+
});
|
|
88
|
+
const storeSchema = zod_1.z
|
|
89
|
+
.object({
|
|
90
|
+
version: zod_1.z.literal(exports.BASELINE_STORE_VERSION),
|
|
91
|
+
/** Rule id → subject → entry. */
|
|
92
|
+
rules: zod_1.z.record(zod_1.z.string(), zod_1.z.record(zod_1.z.string(), entrySchema)),
|
|
93
|
+
})
|
|
94
|
+
.strict();
|
|
95
|
+
/** JSON text as a value, or `invalid` — never throws. */
|
|
96
|
+
function readJson(text) {
|
|
97
|
+
try {
|
|
98
|
+
const value = JSON.parse(text);
|
|
99
|
+
return { ok: true, value };
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return { ok: false };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Parse the file's text; never throws. */
|
|
106
|
+
function parseBaselineStore(text) {
|
|
107
|
+
const json = readJson(text);
|
|
108
|
+
if (!json.ok)
|
|
109
|
+
return { kind: "invalid", message: "not valid JSON" };
|
|
110
|
+
const parsed = storeSchema.safeParse(json.value);
|
|
111
|
+
return parsed.success
|
|
112
|
+
? { kind: "ok", store: parsed.data }
|
|
113
|
+
: {
|
|
114
|
+
kind: "invalid",
|
|
115
|
+
message: parsed.error.issues
|
|
116
|
+
.map((i) => `${i.path.join(".") || "(top level)"}: ${i.message}`)
|
|
117
|
+
.join("; "),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Stable text: two-space indent, trailing newline, no timestamp. */
|
|
121
|
+
function serializeBaselineStore(store) {
|
|
122
|
+
return `${JSON.stringify(store, null, 2)}\n`;
|
|
123
|
+
}
|
|
124
|
+
/** The rule's entries, or none. */
|
|
125
|
+
const entriesOf = (store, ruleId) => store.kind === "ok" && Object.hasOwn(store.store.rules, ruleId)
|
|
126
|
+
? store.store.rules[ruleId]
|
|
127
|
+
: undefined;
|
|
128
|
+
exports.entriesOf = entriesOf;
|
|
129
|
+
const entryAt = (entries, subject) => entries !== undefined && Object.hasOwn(entries, subject)
|
|
130
|
+
? entries[subject]
|
|
131
|
+
: undefined;
|
|
132
|
+
/** One measured part as recorded: carried when unmeasured, dropped when zero. */
|
|
133
|
+
function recordedPart(name, p, stored) {
|
|
134
|
+
const carried = p.value === null ? stored?.parts?.[name] : undefined;
|
|
135
|
+
if (carried !== undefined)
|
|
136
|
+
return [[name, carried]];
|
|
137
|
+
if (p.value === null || p.value === 0)
|
|
138
|
+
return [];
|
|
139
|
+
return [
|
|
140
|
+
[
|
|
141
|
+
name,
|
|
142
|
+
p.files === undefined
|
|
143
|
+
? { value: p.value }
|
|
144
|
+
: { value: p.value, files: { ...p.files } },
|
|
145
|
+
],
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
function toEntry(m, stored) {
|
|
149
|
+
const head = {
|
|
150
|
+
direction: "shrink-only",
|
|
151
|
+
unit: m.unit,
|
|
152
|
+
measure: m.measure,
|
|
153
|
+
};
|
|
154
|
+
if (m.parts === undefined)
|
|
155
|
+
return { ...head, value: m.value };
|
|
156
|
+
const parts = Object.entries(m.parts)
|
|
157
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
158
|
+
.flatMap(([name, p]) => recordedPart(name, p, stored));
|
|
159
|
+
return {
|
|
160
|
+
...head,
|
|
161
|
+
value: sumOf(parts.map(([, p]) => p.value)),
|
|
162
|
+
parts: Object.fromEntries(parts),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const n = (x) => x.toLocaleString("en-US");
|
|
166
|
+
const signed = (x) => (x > 0 ? `+${n(x)}` : n(x));
|
|
167
|
+
/** Each part's stored and current value, where either side has one. */
|
|
168
|
+
function partMoves(current, stored) {
|
|
169
|
+
const names = [
|
|
170
|
+
...new Set([
|
|
171
|
+
...Object.keys(stored.parts ?? {}),
|
|
172
|
+
...Object.keys(current.parts ?? {}),
|
|
173
|
+
]),
|
|
174
|
+
].sort();
|
|
175
|
+
return names
|
|
176
|
+
.map((name) => {
|
|
177
|
+
const from = stored.parts?.[name]?.value ?? 0;
|
|
178
|
+
const to = current.parts?.[name]?.value ?? 0;
|
|
179
|
+
return `${name} ${n(to)}${from === to ? "" : ` (${signed(to - from)})`}`;
|
|
180
|
+
})
|
|
181
|
+
.join(" · ");
|
|
182
|
+
}
|
|
183
|
+
/** Every file of every part, named with its part. */
|
|
184
|
+
const flatFiles = (e) => Object.fromEntries(Object.entries(e.parts ?? {}).flatMap(([name, p]) => Object.entries(p.files ?? {}).map(([file, s]) => [`${file} (${name})`, s])));
|
|
185
|
+
/** Every file whose size moved, largest movement first. */
|
|
186
|
+
function fileMoves(current, stored) {
|
|
187
|
+
const before = flatFiles(stored);
|
|
188
|
+
const after = flatFiles(current);
|
|
189
|
+
const moves = [...new Set([...Object.keys(before), ...Object.keys(after)])]
|
|
190
|
+
.map((file) => ({
|
|
191
|
+
file,
|
|
192
|
+
from: before[file] ?? 0,
|
|
193
|
+
to: after[file] ?? 0,
|
|
194
|
+
had: Object.hasOwn(before, file),
|
|
195
|
+
has: Object.hasOwn(after, file),
|
|
196
|
+
}))
|
|
197
|
+
.filter((c) => c.from !== c.to || c.had !== c.has)
|
|
198
|
+
.sort((a, b) => Math.abs(b.to - b.from) - Math.abs(a.to - a.from) ||
|
|
199
|
+
a.file.localeCompare(b.file));
|
|
200
|
+
return moves
|
|
201
|
+
.map((c) => {
|
|
202
|
+
if (!c.had)
|
|
203
|
+
return `${c.file} +${n(c.to)} (new)`;
|
|
204
|
+
if (!c.has)
|
|
205
|
+
return `${c.file} -${n(c.from)} (gone)`;
|
|
206
|
+
return `${c.file} ${signed(c.to - c.from)}`;
|
|
207
|
+
})
|
|
208
|
+
.join(", ");
|
|
209
|
+
}
|
|
210
|
+
/** A finding with the store's verdict appended. */
|
|
211
|
+
const withVerdict = (f) => (status, text) => ({
|
|
212
|
+
subject: f.subject,
|
|
213
|
+
status,
|
|
214
|
+
text: `${f.text}\n ${text}`,
|
|
215
|
+
});
|
|
216
|
+
/** Why an entry cannot be compared: another unit or measurement, or nothing. */
|
|
217
|
+
function incomparable(stored, m) {
|
|
218
|
+
if (stored.unit !== m.unit) {
|
|
219
|
+
return `The baseline is in ${stored.unit}, this harness counts ${m.unit}. Re-record it with \`${exports.UPDATE_BASELINE_COMMAND}\`.`;
|
|
220
|
+
}
|
|
221
|
+
if (stored.measure !== m.measure) {
|
|
222
|
+
return `The baseline was recorded by measurement ${String(stored.measure)}, this vigiles uses ${String(m.measure)} — what counts changed in vigiles, not in your files. Re-record it with \`${exports.UPDATE_BASELINE_COMMAND}\`.`;
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
/** "15 → 17 chars (+2)", and each part's size with its move. */
|
|
227
|
+
function movement(unit, current, stored) {
|
|
228
|
+
const delta = current.value - stored.value;
|
|
229
|
+
return {
|
|
230
|
+
head: `${n(stored.value)} → ${n(current.value)} ${unit} (${signed(delta)})`,
|
|
231
|
+
parts: current.parts === undefined ? "" : `\n ${partMoves(current, stored)}`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/** Growth: by how much, which files and parts moved, and both ways out. */
|
|
235
|
+
function grewText(unit, current, stored, remedy) {
|
|
236
|
+
const { head, parts } = movement(unit, current, stored);
|
|
237
|
+
const files = fileMoves(current, stored);
|
|
238
|
+
const changed = files === "" ? "" : ` Changed: ${files}.`;
|
|
239
|
+
const cure = remedy === undefined ? "" : ` If it is not:\n${remedy}`;
|
|
240
|
+
return (`Grew ${head} over the recorded baseline.${changed}${parts}\n ` +
|
|
241
|
+
`If the growth is intended, record it with \`${exports.UPDATE_BASELINE_COMMAND}\` — the diff of ${exports.BASELINE_FILE} is the review.${cure}`);
|
|
242
|
+
}
|
|
243
|
+
/** The comparison of a measurement with its comparable stored entry. */
|
|
244
|
+
function compared(f, m, stored, remedy) {
|
|
245
|
+
const at = withVerdict(f);
|
|
246
|
+
const current = toEntry(m, stored);
|
|
247
|
+
if (current.value === stored.value) {
|
|
248
|
+
return at("ok", `Held at the recorded baseline (${n(stored.value)} ${m.unit}).`);
|
|
249
|
+
}
|
|
250
|
+
if (current.value > stored.value) {
|
|
251
|
+
return at("finding", grewText(m.unit, current, stored, remedy));
|
|
252
|
+
}
|
|
253
|
+
const { head, parts } = movement(m.unit, current, stored);
|
|
254
|
+
return at("finding", `The size went down: ${head}, below the recorded baseline, which still allows the old size — headroom that can be regrown without a finding. ` +
|
|
255
|
+
`Record the new, lower number with \`${exports.UPDATE_BASELINE_COMMAND}\`.${parts}`);
|
|
256
|
+
}
|
|
257
|
+
/** The verdict for one finding that carries a measurement. */
|
|
258
|
+
function verdictFor(f, m, entries, remedy) {
|
|
259
|
+
const at = withVerdict(f);
|
|
260
|
+
if (entries === undefined) {
|
|
261
|
+
return at("note", `No baseline is recorded, so this is not a finding. To fail CI only if it grows, run \`${exports.UPDATE_BASELINE_COMMAND}\` and commit ${exports.BASELINE_FILE}.`);
|
|
262
|
+
}
|
|
263
|
+
const stored = entryAt(entries, f.subject);
|
|
264
|
+
if (stored === undefined) {
|
|
265
|
+
return at("finding", `${exports.BASELINE_FILE} has no entry for this, so nobody accepted this size. Record it with \`${exports.UPDATE_BASELINE_COMMAND}\` (the diff is the review), or get under the limit.`);
|
|
266
|
+
}
|
|
267
|
+
const why = incomparable(stored, m);
|
|
268
|
+
return why === undefined
|
|
269
|
+
? compared(f, m, stored, remedy)
|
|
270
|
+
: at("finding", why);
|
|
271
|
+
}
|
|
272
|
+
/** The parts a subject's entry recorded that this run could not measure, sorted. */
|
|
273
|
+
function unmeasuredRecorded(run, subject, entry) {
|
|
274
|
+
const missing = new Set(run.unmeasured !== undefined && Object.hasOwn(run.unmeasured, subject)
|
|
275
|
+
? run.unmeasured[subject]
|
|
276
|
+
: []);
|
|
277
|
+
return Object.keys(entry?.parts ?? {})
|
|
278
|
+
.filter((part) => missing.has(part))
|
|
279
|
+
.sort();
|
|
280
|
+
}
|
|
281
|
+
/** "output style not measured this run; recorded 20 chars kept", per such part. */
|
|
282
|
+
function unmeasuredLine(subject, entry, parts) {
|
|
283
|
+
const where = subject === "." ? "" : `${subject}: `;
|
|
284
|
+
const said = parts
|
|
285
|
+
.map((p) => `${p.replaceAll("-", " ")} not measured this run; recorded ${n(entry.parts?.[p]?.value ?? 0)} ${entry.unit} kept`)
|
|
286
|
+
.join("; ");
|
|
287
|
+
return {
|
|
288
|
+
subject,
|
|
289
|
+
status: "note",
|
|
290
|
+
text: `${where}${said} — ${exports.BASELINE_FILE} keeps the entry until a run measures every part it recorded.`,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/** A stored entry no finding asked for: the subject is under its limit, or gone. */
|
|
294
|
+
function staleLine(subject, measured) {
|
|
295
|
+
const where = subject === "." ? "" : `${subject}: `;
|
|
296
|
+
return {
|
|
297
|
+
subject,
|
|
298
|
+
status: "note",
|
|
299
|
+
text: measured
|
|
300
|
+
? `${where}under the limit, so ${exports.BASELINE_FILE} no longer needs its entry — \`${exports.UPDATE_BASELINE_COMMAND}\` drops it (and deletes the file once it is empty).`
|
|
301
|
+
: `${where}nothing to measure any more, so its entry in ${exports.BASELINE_FILE} is stale — \`${exports.UPDATE_BASELINE_COMMAND}\` drops it.`,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/** A finding the store does not touch. */
|
|
305
|
+
const asIs = (f) => ({
|
|
306
|
+
subject: f.subject,
|
|
307
|
+
status: "finding",
|
|
308
|
+
text: f.text,
|
|
309
|
+
});
|
|
310
|
+
/** An unreadable store: one finding for it, and every finding stays a finding. */
|
|
311
|
+
const unreadable = (run, message) => [
|
|
312
|
+
{
|
|
313
|
+
subject: ".",
|
|
314
|
+
status: "finding",
|
|
315
|
+
text: `${exports.BASELINE_FILE} cannot be read (${message}) — re-record it with \`${exports.UPDATE_BASELINE_COMMAND}\``,
|
|
316
|
+
},
|
|
317
|
+
...run.findings.map(asIs),
|
|
318
|
+
];
|
|
319
|
+
/** Apply the store to one rule's run: the lines lint prints, in subject order. */
|
|
320
|
+
function applyBaseline(run, store) {
|
|
321
|
+
if (store.kind === "invalid")
|
|
322
|
+
return unreadable(run, store.message);
|
|
323
|
+
const entries = (0, exports.entriesOf)(store, run.ruleId);
|
|
324
|
+
const lines = run.findings.map((f) => f.measurement === undefined
|
|
325
|
+
? asIs(f)
|
|
326
|
+
: verdictFor(f, f.measurement, entries, run.remedy));
|
|
327
|
+
const asked = new Set(run.findings
|
|
328
|
+
.filter((f) => f.measurement !== undefined)
|
|
329
|
+
.map((f) => f.subject));
|
|
330
|
+
return [...lines, ...storeNotes(run, entries ?? {}, asked)];
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* The notes for stored entries: a recorded part this run could not measure
|
|
334
|
+
* (the entry is kept), else — when no finding asked for the subject — under
|
|
335
|
+
* its limit or gone. Entries the run did not look at are silent.
|
|
336
|
+
*/
|
|
337
|
+
function storeNotes(run, entries, asked) {
|
|
338
|
+
const gone = new Set(run.gone ?? []);
|
|
339
|
+
const measured = new Set(run.measured);
|
|
340
|
+
return Object.entries(entries)
|
|
341
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
342
|
+
.flatMap(([s, e]) => {
|
|
343
|
+
const unmeasured = measured.has(s) ? unmeasuredRecorded(run, s, e) : [];
|
|
344
|
+
if (unmeasured.length > 0)
|
|
345
|
+
return [unmeasuredLine(s, e, unmeasured)];
|
|
346
|
+
return !asked.has(s) && (measured.has(s) || gone.has(s))
|
|
347
|
+
? [staleLine(s, measured.has(s))]
|
|
348
|
+
: [];
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* The store with one rule's entries replaced by `entries` — every other rule's
|
|
353
|
+
* are kept. `undefined` when nothing is left to store, so the caller deletes
|
|
354
|
+
* the file rather than committing an empty one.
|
|
355
|
+
*/
|
|
356
|
+
function withEntries(previous, ruleId, entries) {
|
|
357
|
+
const before = previous.kind === "ok" ? previous.store.rules : {};
|
|
358
|
+
const fresh = Object.entries(entries).sort(([a], [b]) => a.localeCompare(b));
|
|
359
|
+
const others = Object.entries(before).filter(([id]) => id !== ruleId);
|
|
360
|
+
const mine = fresh.length === 0 ? [] : [[ruleId, Object.fromEntries(fresh)]];
|
|
361
|
+
const rules = Object.fromEntries([...others, ...mine].sort(([a], [b]) => a.localeCompare(b)));
|
|
362
|
+
return Object.keys(rules).length === 0
|
|
363
|
+
? undefined
|
|
364
|
+
: { version: exports.BASELINE_STORE_VERSION, rules };
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The rule's entries after recording one run: every subject the run measured
|
|
368
|
+
* or found gone becomes exactly its finding's measurement (or nothing, when it
|
|
369
|
+
* is under its limit or gone), with any part this run could not measure
|
|
370
|
+
* carried over. Every subject the run did not look at keeps its entry as is,
|
|
371
|
+
* so a scoped run never deletes another bundle's baseline — and so does one
|
|
372
|
+
* whose entry recorded a part this run could not measure, since no finding
|
|
373
|
+
* there proves nothing about that part.
|
|
374
|
+
*/
|
|
375
|
+
function entriesFor(previous, run) {
|
|
376
|
+
const old = (0, exports.entriesOf)(previous, run.ruleId);
|
|
377
|
+
const looked = new Set([...run.measured, ...(run.gone ?? [])]);
|
|
378
|
+
const asked = new Set(run.findings.flatMap((f) => f.measurement === undefined ? [] : [f.subject]));
|
|
379
|
+
const kept = Object.entries(old ?? {}).filter(([s, e]) => !looked.has(s) ||
|
|
380
|
+
(!asked.has(s) && unmeasuredRecorded(run, s, e).length > 0));
|
|
381
|
+
const fresh = run.findings.flatMap((f) => f.measurement === undefined
|
|
382
|
+
? []
|
|
383
|
+
: [[f.subject, toEntry(f.measurement, entryAt(old, f.subject))]]);
|
|
384
|
+
return Object.fromEntries([...kept, ...fresh]);
|
|
385
|
+
}
|
|
386
|
+
/** The store after recording one rule's run ({@link withEntries} of {@link entriesFor}). */
|
|
387
|
+
const recordRun = (previous, run) => withEntries(previous, run.ruleId, entriesFor(previous, run));
|
|
388
|
+
exports.recordRun = recordRun;
|
|
389
|
+
/** Whether the store already holds entries for a rule — `init` never overwrites them. */
|
|
390
|
+
const hasEntries = (store, ruleId) => Object.keys((0, exports.entriesOf)(store, ruleId) ?? {}).length > 0;
|
|
391
|
+
exports.hasEntries = hasEntries;
|
|
392
|
+
//# sourceMappingURL=baseline-store.js.map
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
* against sit at roughly four times the Claude Code threshold. A rule that
|
|
33
33
|
* fails every real repo on day one is switched off on day one
|
|
34
34
|
* (`lint-rule-calibration`: severity tracks confidence, and a check nobody
|
|
35
|
-
* leaves on catches nothing). So
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* leaves on catches nothing). So going over it is a finding the baseline store
|
|
36
|
+
* can accept (`./always-loaded-limits.ts`, `./baseline-store.ts`): green on
|
|
37
|
+
* day one at any size the repository recorded, red the day it grows.
|
|
38
38
|
*/
|
|
39
39
|
import type { InstructionChain, InstructionRole, InstructionScope } from "./instruction-chain.js";
|
|
40
40
|
/** What the harness counts, and what it does when the count is exceeded. */
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
* against sit at roughly four times the Claude Code threshold. A rule that
|
|
34
34
|
* fails every real repo on day one is switched off on day one
|
|
35
35
|
* (`lint-rule-calibration`: severity tracks confidence, and a check nobody
|
|
36
|
-
* leaves on catches nothing). So
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* leaves on catches nothing). So going over it is a finding the baseline store
|
|
37
|
+
* can accept (`./always-loaded-limits.ts`, `./baseline-store.ts`): green on
|
|
38
|
+
* day one at any size the repository recorded, red the day it grows.
|
|
39
39
|
*/
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.sizeIn = void 0;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The always-loaded baseline as earlier releases wrote it, in its own file —
|
|
3
|
+
* read ONLY to migrate it into the baseline store (`./baseline-store.ts`).
|
|
4
|
+
* Nothing compares against it: a file `lint` no longer reads must say so, not
|
|
5
|
+
* keep gating under an old name. The file is named after the rule
|
|
6
|
+
* (`.vigiles/<rule-id>.json`), or `.vigiles/instruction-weight.json` from
|
|
7
|
+
* before the rule's rename.
|
|
8
|
+
*
|
|
9
|
+
* WHAT MIGRATING KEEPS. The recorded numbers, not the tree's current size:
|
|
10
|
+
* re-measuring while migrating would accept, unseen, whatever growth landed
|
|
11
|
+
* since the old file was last recorded. So each old entry becomes a store
|
|
12
|
+
* entry with the same instructions total and the same parts. A version-1
|
|
13
|
+
* file never recorded the output style or the skill listing (it printed a
|
|
14
|
+
* note for them instead), so those parts are taken at their current size —
|
|
15
|
+
* they were never gated, and recording them is what the note asked for.
|
|
16
|
+
*
|
|
17
|
+
* Pure: parsing and conversion. Finding and deleting the files is the caller's.
|
|
18
|
+
*/
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
import { type BaselineEntry, type Measurement } from "./baseline-store.js";
|
|
21
|
+
/** The file this baseline had before the rule was renamed. */
|
|
22
|
+
export declare const PRE_RENAME_BASELINE_FILE = ".vigiles/instruction-weight.json";
|
|
23
|
+
/** Every old file name, newest first: the rule's own name, then the pre-rename one. */
|
|
24
|
+
export declare const legacyBaselineFiles: (ruleId: string) => readonly string[];
|
|
25
|
+
declare const legacyFile: z.ZodObject<{
|
|
26
|
+
version: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>;
|
|
27
|
+
bundles: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
28
|
+
unit: z.ZodEnum<{
|
|
29
|
+
chars: "chars";
|
|
30
|
+
bytes: "bytes";
|
|
31
|
+
}>;
|
|
32
|
+
measure: z.ZodNumber;
|
|
33
|
+
total: z.ZodNumber;
|
|
34
|
+
files: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
35
|
+
parts: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
"output-style": z.ZodOptional<z.ZodObject<{
|
|
37
|
+
measure: z.ZodNumber;
|
|
38
|
+
total: z.ZodNumber;
|
|
39
|
+
files: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
40
|
+
}, z.core.$strict>>;
|
|
41
|
+
"skill-listing": z.ZodOptional<z.ZodObject<{
|
|
42
|
+
measure: z.ZodNumber;
|
|
43
|
+
total: z.ZodNumber;
|
|
44
|
+
files: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
45
|
+
}, z.core.$strict>>;
|
|
46
|
+
}, z.core.$strict>>;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
/** The old file, parsed: its bundles, or why it cannot be converted. */
|
|
50
|
+
export type LegacyBaseline = {
|
|
51
|
+
readonly kind: "ok";
|
|
52
|
+
readonly file: z.infer<typeof legacyFile>;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: "invalid";
|
|
55
|
+
readonly message: string;
|
|
56
|
+
};
|
|
57
|
+
export declare function parseLegacyBaseline(text: string): LegacyBaseline;
|
|
58
|
+
/**
|
|
59
|
+
* One old entry as a store entry, or `undefined` when the old file has no
|
|
60
|
+
* entry for this bundle. `current` fills the parts a version-1 file never
|
|
61
|
+
* recorded; for a bundle this run did not measure it is `undefined`, and
|
|
62
|
+
* those parts stay unrecorded, exactly as the old file left them. A
|
|
63
|
+
* measurement version other than the one earlier releases wrote becomes
|
|
64
|
+
* measure 0, which the store reads as "re-record".
|
|
65
|
+
*/
|
|
66
|
+
export declare function convertLegacyEntry(legacy: Extract<LegacyBaseline, {
|
|
67
|
+
kind: "ok";
|
|
68
|
+
}>, at: string, current: Measurement | undefined): BaselineEntry | undefined;
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=legacy-baseline.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.legacyBaselineFiles = exports.PRE_RENAME_BASELINE_FILE = void 0;
|
|
4
|
+
exports.parseLegacyBaseline = parseLegacyBaseline;
|
|
5
|
+
exports.convertLegacyEntry = convertLegacyEntry;
|
|
6
|
+
/**
|
|
7
|
+
* The always-loaded baseline as earlier releases wrote it, in its own file —
|
|
8
|
+
* read ONLY to migrate it into the baseline store (`./baseline-store.ts`).
|
|
9
|
+
* Nothing compares against it: a file `lint` no longer reads must say so, not
|
|
10
|
+
* keep gating under an old name. The file is named after the rule
|
|
11
|
+
* (`.vigiles/<rule-id>.json`), or `.vigiles/instruction-weight.json` from
|
|
12
|
+
* before the rule's rename.
|
|
13
|
+
*
|
|
14
|
+
* WHAT MIGRATING KEEPS. The recorded numbers, not the tree's current size:
|
|
15
|
+
* re-measuring while migrating would accept, unseen, whatever growth landed
|
|
16
|
+
* since the old file was last recorded. So each old entry becomes a store
|
|
17
|
+
* entry with the same instructions total and the same parts. A version-1
|
|
18
|
+
* file never recorded the output style or the skill listing (it printed a
|
|
19
|
+
* note for them instead), so those parts are taken at their current size —
|
|
20
|
+
* they were never gated, and recording them is what the note asked for.
|
|
21
|
+
*
|
|
22
|
+
* Pure: parsing and conversion. Finding and deleting the files is the caller's.
|
|
23
|
+
*/
|
|
24
|
+
const zod_1 = require("zod");
|
|
25
|
+
const baseline_store_js_1 = require("./baseline-store.js");
|
|
26
|
+
const always_loaded_limits_js_1 = require("./always-loaded-limits.js");
|
|
27
|
+
/** The file this baseline had before the rule was renamed. */
|
|
28
|
+
exports.PRE_RENAME_BASELINE_FILE = ".vigiles/instruction-weight.json";
|
|
29
|
+
/** Every old file name, newest first: the rule's own name, then the pre-rename one. */
|
|
30
|
+
const legacyBaselineFiles = (ruleId) => [
|
|
31
|
+
`.vigiles/${ruleId}.json`,
|
|
32
|
+
exports.PRE_RENAME_BASELINE_FILE,
|
|
33
|
+
];
|
|
34
|
+
exports.legacyBaselineFiles = legacyBaselineFiles;
|
|
35
|
+
/** The one measurement version earlier releases recorded, for the file and every part. */
|
|
36
|
+
const LEGACY_MEASURE = 1;
|
|
37
|
+
const size = zod_1.z.number().int().nonnegative();
|
|
38
|
+
const files = zod_1.z.record(zod_1.z.string(), size);
|
|
39
|
+
const legacyPartSchema = zod_1.z
|
|
40
|
+
.object({ measure: size, total: size, files })
|
|
41
|
+
.strict();
|
|
42
|
+
const legacyEntry = zod_1.z
|
|
43
|
+
.object({
|
|
44
|
+
unit: zod_1.z.enum(["chars", "bytes"]),
|
|
45
|
+
measure: size,
|
|
46
|
+
total: size,
|
|
47
|
+
files,
|
|
48
|
+
parts: zod_1.z
|
|
49
|
+
.object({
|
|
50
|
+
"output-style": legacyPartSchema.optional(),
|
|
51
|
+
"skill-listing": legacyPartSchema.optional(),
|
|
52
|
+
})
|
|
53
|
+
.strict()
|
|
54
|
+
.optional(),
|
|
55
|
+
})
|
|
56
|
+
.strict();
|
|
57
|
+
const legacyFile = zod_1.z
|
|
58
|
+
.object({
|
|
59
|
+
version: zod_1.z.union([zod_1.z.literal(1), zod_1.z.literal(2)]),
|
|
60
|
+
bundles: zod_1.z.record(zod_1.z.string(), legacyEntry),
|
|
61
|
+
})
|
|
62
|
+
.strict();
|
|
63
|
+
function parseLegacyBaseline(text) {
|
|
64
|
+
const json = (0, baseline_store_js_1.readJson)(text);
|
|
65
|
+
if (!json.ok)
|
|
66
|
+
return { kind: "invalid", message: "not valid JSON" };
|
|
67
|
+
const parsed = legacyFile.safeParse(json.value);
|
|
68
|
+
return parsed.success
|
|
69
|
+
? { kind: "ok", file: parsed.data }
|
|
70
|
+
: {
|
|
71
|
+
kind: "invalid",
|
|
72
|
+
message: parsed.error.issues.map((i) => i.message).join("; "),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* One part of an old entry as a measured part: as recorded; zero when a
|
|
77
|
+
* version-2 file left it out (it wrote only parts that were not zero); today's
|
|
78
|
+
* size when a version-1 file never recorded it.
|
|
79
|
+
*/
|
|
80
|
+
function legacyPart(old, version, name, current) {
|
|
81
|
+
const p = old.parts?.[name];
|
|
82
|
+
if (p !== undefined)
|
|
83
|
+
return { [name]: { value: p.total, files: p.files } };
|
|
84
|
+
if (version === 2)
|
|
85
|
+
return { [name]: { value: 0 } };
|
|
86
|
+
const now = current?.parts?.[name];
|
|
87
|
+
return now === undefined ? {} : { [name]: now };
|
|
88
|
+
}
|
|
89
|
+
/** Whether every number in the old entry was taken by the one measurement earlier releases had. */
|
|
90
|
+
const sameMeasure = (old) => old.measure === LEGACY_MEASURE &&
|
|
91
|
+
Object.values(old.parts ?? {}).every((p) => p.measure === LEGACY_MEASURE);
|
|
92
|
+
/**
|
|
93
|
+
* One old entry as a store entry, or `undefined` when the old file has no
|
|
94
|
+
* entry for this bundle. `current` fills the parts a version-1 file never
|
|
95
|
+
* recorded; for a bundle this run did not measure it is `undefined`, and
|
|
96
|
+
* those parts stay unrecorded, exactly as the old file left them. A
|
|
97
|
+
* measurement version other than the one earlier releases wrote becomes
|
|
98
|
+
* measure 0, which the store reads as "re-record".
|
|
99
|
+
*/
|
|
100
|
+
function convertLegacyEntry(legacy, at, current) {
|
|
101
|
+
const { bundles, version } = legacy.file;
|
|
102
|
+
if (!Object.hasOwn(bundles, at))
|
|
103
|
+
return undefined;
|
|
104
|
+
const old = bundles[at];
|
|
105
|
+
const parts = {
|
|
106
|
+
instructions: { value: old.total, files: old.files },
|
|
107
|
+
...legacyPart(old, version, "output-style", current),
|
|
108
|
+
...legacyPart(old, version, "skill-listing", current),
|
|
109
|
+
};
|
|
110
|
+
return (0, baseline_store_js_1.toEntry)({
|
|
111
|
+
unit: old.unit,
|
|
112
|
+
measure: sameMeasure(old) ? always_loaded_limits_js_1.ALWAYS_LOADED_MEASURE : 0,
|
|
113
|
+
parts,
|
|
114
|
+
value: 0,
|
|
115
|
+
}, undefined);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=legacy-baseline.js.map
|
|
@@ -45,5 +45,29 @@ export interface SkillListingRules {
|
|
|
45
45
|
readonly entry: (skill: ListedSkill, settings: Readonly<Record<string, unknown>>) => string | null;
|
|
46
46
|
/** The vendor artifact this was read from, version included. */
|
|
47
47
|
readonly capturedFrom: string;
|
|
48
|
+
/**
|
|
49
|
+
* The size of the listing as a WHOLE past which the harness drops skill
|
|
50
|
+
* descriptions, so some skills lose the text they trigger on. Absent when
|
|
51
|
+
* the adapter does not model one — a different fact from "no limit".
|
|
52
|
+
*/
|
|
53
|
+
readonly budget?: SkillListingBudget;
|
|
54
|
+
}
|
|
55
|
+
/** The listing's budget for one commit: the harness default, or a committed setting. */
|
|
56
|
+
export interface ListingLimit {
|
|
57
|
+
/** In the harness's unit (the instruction budget's `unit`). */
|
|
58
|
+
readonly limit: number;
|
|
59
|
+
/** The committed setting that moved it off the default, when one did. */
|
|
60
|
+
readonly setBy?: string;
|
|
61
|
+
}
|
|
62
|
+
/** How a harness sizes its whole skill listing. */
|
|
63
|
+
export interface SkillListingBudget {
|
|
64
|
+
/**
|
|
65
|
+
* The limit a session on this commit gets, from the COMMITTED settings
|
|
66
|
+
* (`{}` when there are none). Per-machine environment variables that move
|
|
67
|
+
* it are not a property of the commit and are not read.
|
|
68
|
+
*/
|
|
69
|
+
readonly limit: (settings: Readonly<Record<string, unknown>>) => ListingLimit;
|
|
70
|
+
/** The vendor artifact this was read from, version included. */
|
|
71
|
+
readonly capturedFrom: string;
|
|
48
72
|
}
|
|
49
73
|
//# sourceMappingURL=skill-listing.d.ts.map
|
package/dist/core/types.d.ts
CHANGED
|
@@ -63,15 +63,23 @@ export interface CoverageThresholds {
|
|
|
63
63
|
scripts?: number;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Options for the `context-creep` rule:
|
|
66
|
+
* Options for the `context-creep` rule:
|
|
67
|
+
* `["error", { limits: { "skill-listing": 9000 }, max: 60000 }]`.
|
|
67
68
|
*/
|
|
68
69
|
export interface ContextCreepConfig {
|
|
69
70
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
* Per-part limits in the harness's own unit (characters for Claude Code,
|
|
72
|
+
* bytes for Codex). A part left out keeps the harness's number. Going over
|
|
73
|
+
* one is a finding the baseline store can accept. Positive integers.
|
|
74
|
+
*/
|
|
75
|
+
limits?: {
|
|
76
|
+
instructions?: number;
|
|
77
|
+
"skill-listing"?: number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* An opt-in ABSOLUTE ceiling on the scored instruction weight. A total above
|
|
81
|
+
* it is a finding no baseline lifts, and `vigiles lint --update-baseline`
|
|
82
|
+
* refuses to record above it. A positive integer.
|
|
75
83
|
*/
|
|
76
84
|
max?: number;
|
|
77
85
|
}
|