vigiles 39.2.0 → 40.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.
Files changed (52) hide show
  1. package/dist/adapter.d.ts +3 -2
  2. package/dist/adapters/claude-code/dialect.js +4 -0
  3. package/dist/adapters/claude-code/output-style.js +15 -0
  4. package/dist/adapters/claude-code/skill-listing.d.ts +48 -0
  5. package/dist/adapters/claude-code/skill-listing.js +54 -0
  6. package/dist/adapters/codex/dialect.js +4 -0
  7. package/dist/adapters/codex/layout.js +5 -0
  8. package/dist/adapters/codex/mock-model.d.ts +7 -0
  9. package/dist/adapters/codex/mock-model.js +1 -0
  10. package/dist/adapters/codex/skill-listing.d.ts +42 -0
  11. package/dist/adapters/codex/skill-listing.js +40 -0
  12. package/dist/audit-html.js +7 -2
  13. package/dist/audit-report.d.ts +51 -0
  14. package/dist/audit-report.js +54 -8
  15. package/dist/audit-report.template.html +38 -33
  16. package/dist/cli-main.d.ts +9 -3
  17. package/dist/cli-main.js +32 -17
  18. package/dist/{instruction-weight-ratchet.d.ts → context-creep-ratchet.d.ts} +34 -12
  19. package/dist/context-creep-ratchet.js +270 -0
  20. package/dist/core/always-loaded.d.ts +128 -0
  21. package/dist/core/always-loaded.js +134 -0
  22. package/dist/core/compile.js +1 -1
  23. package/dist/core/dialect.d.ts +9 -0
  24. package/dist/core/harness-unit.d.ts +20 -0
  25. package/dist/core/harness-unit.js +24 -0
  26. package/dist/core/instruction-baseline.d.ts +179 -11
  27. package/dist/core/instruction-baseline.js +349 -47
  28. package/dist/core/instruction-weight.d.ts +2 -11
  29. package/dist/core/instruction-weight.js +6 -16
  30. package/dist/core/layout.d.ts +40 -0
  31. package/dist/core/layout.js +25 -1
  32. package/dist/core/output-style.d.ts +20 -0
  33. package/dist/core/skill-listing.d.ts +49 -0
  34. package/dist/core/skill-listing.js +23 -0
  35. package/dist/core/types.d.ts +2 -2
  36. package/dist/deprecated-key-files.d.ts +1 -1
  37. package/dist/deprecated-key-files.js +1 -1
  38. package/dist/fs-walk.d.ts +31 -0
  39. package/dist/fs-walk.js +49 -0
  40. package/dist/local-files.js +2 -1
  41. package/dist/plugin-loader.js +40 -19
  42. package/dist/rules/index.d.ts +4 -4
  43. package/dist/rules/index.js +7 -7
  44. package/dist/scan-files.js +24 -3
  45. package/dist/scan.d.ts +30 -1
  46. package/dist/scan.js +69 -3
  47. package/dist/surface-discovery-fs.d.ts +15 -0
  48. package/dist/surface-discovery-fs.js +55 -0
  49. package/dist/vigilesrc.schema.json +2 -2
  50. package/hooks/session-start.sh +3 -1
  51. package/package.json +1 -1
  52. package/dist/instruction-weight-ratchet.js +0 -181
package/dist/scan.js CHANGED
@@ -28,6 +28,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.measureInstructionWeight = measureInstructionWeight;
31
+ exports.measureAlwaysLoaded = measureAlwaysLoaded;
31
32
  exports.scanPlugin = scanPlugin;
32
33
  exports.verifyLiveMcpTools = verifyLiveMcpTools;
33
34
  exports.formatMcpContractReport = formatMcpContractReport;
@@ -75,6 +76,7 @@ const test_coverage_js_1 = require("./test-coverage.js");
75
76
  const coverage_evidence_js_1 = require("./coverage-evidence.js");
76
77
  const scan_core_js_1 = require("./scan-core.js");
77
78
  const instruction_weight_js_1 = require("./core/instruction-weight.js");
79
+ const always_loaded_js_1 = require("./core/always-loaded.js");
78
80
  const event_capability_js_1 = require("./core/event-capability.js");
79
81
  const hook_command_js_1 = require("./core/hook-command.js");
80
82
  const hook_paths_js_1 = require("./core/hook-paths.js");
@@ -162,7 +164,7 @@ function ownTestSignalOnDisk(dir) {
162
164
  * The always-loaded instruction weight of ONE directory under ONE harness —
163
165
  * the bounded read, the harness's chain, and the sum, in one place.
164
166
  *
165
- * `scanPlugin` reports it, `lint`'s instruction-weight ratchet gates on it and
167
+ * `scanPlugin` reports it, `lint`'s context-creep ratchet gates on it and
166
168
  * `compile` prints it, so all three must arrive at the same number by the same
167
169
  * route; this function is that route. `null` when the harness publishes no
168
170
  * budget (there is no unit to count in).
@@ -171,6 +173,32 @@ function measureInstructionWeight(dir, harness) {
171
173
  // No `exclude` parameter, on purpose — see the note in `scanPlugin`.
172
174
  return weighBoundedInstructions(harness, (0, surface_discovery_fs_js_1.boundedInstructionFiles)((0, node_path_1.resolve)(dir), harness.layout));
173
175
  }
176
+ /**
177
+ * The always-loaded context of ONE directory under ONE harness — the same route as
178
+ * {@link measureInstructionWeight}, plus the style and skill files. `lint`'s
179
+ * ratchet gates on it, `compile` prints it and `scanPlugin` reports it.
180
+ */
181
+ function measureAlwaysLoaded(dir, harness) {
182
+ return alwaysLoadedOf(dir, harness, (0, surface_discovery_fs_js_1.boundedInstructionFiles)((0, node_path_1.resolve)(dir), harness.layout));
183
+ }
184
+ function alwaysLoadedOf(dir, harness, instructionFiles) {
185
+ const instructionWeight = weighBoundedInstructions(harness, instructionFiles);
186
+ if (instructionWeight === null)
187
+ return { instructionWeight };
188
+ const files = {
189
+ ...instructionFiles,
190
+ ...(0, surface_discovery_fs_js_1.alwaysLoadedFiles)((0, node_path_1.resolve)(dir), harness.layout),
191
+ };
192
+ return {
193
+ instructionWeight,
194
+ alwaysLoaded: (0, always_loaded_js_1.weighAlwaysLoaded)({
195
+ weight: instructionWeight,
196
+ files,
197
+ layout: harness.layout,
198
+ dialect: harness.dialect,
199
+ }),
200
+ };
201
+ }
174
202
  function weighBoundedInstructions(harness, instructionFiles) {
175
203
  const budget = harness.dialect.instructionBudget;
176
204
  return budget
@@ -369,7 +397,7 @@ function scanPlugin(dir, layout, dialect, opts = {}) {
369
397
  // unit (Claude Code counts 40 000 chars, Codex 32 768 bytes), so there is no
370
398
  // meaningful sum across two; reporting the one that owns the file that
371
399
  // exists is the only reading that is true of something.
372
- instructionWeight: weighBoundedInstructions(instructionHarness, instructionFiles),
400
+ ...alwaysLoadedOf(dir, instructionHarness, instructionFiles),
373
401
  untested: coverage.untested.length,
374
402
  untestedHarness: coverage.harness.untested.length,
375
403
  unevaluated: coverage.evals.untested.length,
@@ -695,10 +723,48 @@ function deprecatedKeyFilesLines(r) {
695
723
  ` ${keyfiles_js_1.KEYFILES_DOCS_URL} [deprecated-key-files]`,
696
724
  ], found.length);
697
725
  }
726
+ /** One always-loaded row's value: a size, or why there is none. */
727
+ function loadedPartValue(part, unit, what) {
728
+ const g = (n) => n.toLocaleString("en-US");
729
+ switch (part.kind) {
730
+ case "counted": {
731
+ const where = what === "output style"
732
+ ? part.files.map((f) => f.path).join(", ")
733
+ : `${String(part.files.length)} skill(s) listed`;
734
+ return `${g(part.total)} ${unit} ${where}`;
735
+ }
736
+ case "none":
737
+ return what === "output style" ? "none selected" : "no skill listed";
738
+ case "not-supported":
739
+ return `n/a — this harness has no ${what}s`;
740
+ case "not-modelled":
741
+ return `not measured — the ${what} is not modelled for this harness`;
742
+ case "unresolved":
743
+ return `"${part.name}" is selected and no repository style declares that name (a built-in style, or a name that loads the default) — not counted`;
744
+ }
745
+ }
746
+ /**
747
+ * The two rows the always-loaded context adds under the instruction weight, and the
748
+ * total of all three. Said as "at session start, before any decision" because
749
+ * that is what the number is — not the size of a request: the harness's own
750
+ * prompt, user and plugin skills and the conversation come on top.
751
+ */
752
+ function alwaysLoadedLines(f) {
753
+ const g = (n) => n.toLocaleString("en-US");
754
+ return [
755
+ ` + output style: ${loadedPartValue(f.outputStyle, f.unit, "output style")}`,
756
+ ` + skill listing: ${loadedPartValue(f.skillListing, f.unit, "skill listing")}`,
757
+ ` = always loaded: ${g(f.total)} ${f.unit} loaded at session start before any decision (instructions + output style + skill listing)`,
758
+ ];
759
+ }
698
760
  /** What the instruction file costs: its always-loaded weight, then any deprecated `keyFiles` inflating it. */
699
761
  function instructionCostLines(r) {
700
762
  const weight = r.instructionWeight
701
- ? [...instructionWeightLines(r.instructionWeight), ""]
763
+ ? [
764
+ ...instructionWeightLines(r.instructionWeight),
765
+ ...(r.alwaysLoaded ? alwaysLoadedLines(r.alwaysLoaded) : []),
766
+ "",
767
+ ]
702
768
  : [];
703
769
  return [...weight, ...deprecatedKeyFilesLines(r)];
704
770
  }
@@ -11,4 +11,19 @@ export declare function boundedSurfacePaths(root: string, excludes?: ExcludeSet)
11
11
  /** Every surface the bounded walk finds on disk under `root`, by shape. */
12
12
  export declare function discoverSurfacesOnDisk(root: string, excludes?: ExcludeSet): readonly DiscoveredSurface[];
13
13
  export declare function boundedInstructionFiles(root: string, layout: PluginLayout, excludes?: ExcludeSet): Record<string, string>;
14
+ /**
15
+ * The files the ALWAYS-LOADED CONTEXT reads beyond the instruction candidates: the
16
+ * style files in the folder a session at the root reads styles from, and each
17
+ * `SKILL.md` under the session's skills folder at a depth the harness reads —
18
+ * the two inputs `core/always-loaded.ts` filters, by the same paths, out of the
19
+ * browser engine's fetched tree.
20
+ *
21
+ * Two NAMED directories, not a walk of the repository: the layout says where
22
+ * both are and how deep the harness looks under each, and nothing else is
23
+ * read. `exclude` does not apply, for the reason it does not apply to the
24
+ * instruction weight: the harness loads these whatever vigiles lints, and the
25
+ * number is a committed baseline that one more `exclude` line would otherwise
26
+ * lower.
27
+ */
28
+ export declare function alwaysLoadedFiles(root: string, layout: PluginLayout): Readonly<Record<string, string>>;
14
29
  //# sourceMappingURL=surface-discovery-fs.d.ts.map
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.boundedSurfacePaths = boundedSurfacePaths;
4
4
  exports.discoverSurfacesOnDisk = discoverSurfacesOnDisk;
5
5
  exports.boundedInstructionFiles = boundedInstructionFiles;
6
+ exports.alwaysLoadedFiles = alwaysLoadedFiles;
6
7
  /**
7
8
  * The DISK half of BOUNDED DISCOVERY: enumerate the repo-relative paths inside
8
9
  * the bounded root set, so the pure classifiers in `src/core/surface-discovery.ts`
@@ -40,6 +41,7 @@ const node_fs_1 = require("node:fs");
40
41
  const node_path_1 = require("node:path");
41
42
  const instruction_chain_js_1 = require("./core/instruction-chain.js");
42
43
  const layout_js_1 = require("./core/layout.js");
44
+ const output_style_js_1 = require("./core/output-style.js");
43
45
  const surface_discovery_js_1 = require("./core/surface-discovery.js");
44
46
  const exclude_js_1 = require("./exclude.js");
45
47
  const fs_walk_js_1 = require("./fs-walk.js");
@@ -207,4 +209,57 @@ function boundedInstructionFiles(root, layout, excludes) {
207
209
  // would under-report the one number this report exists to give.
208
210
  return (0, instruction_chain_js_1.resolveImports)(layout, candidateFiles, (rel) => readIfFile(root, rel));
209
211
  }
212
+ /**
213
+ * The `SKILL.md` paths under the session's skills folder, at the depths the
214
+ * layout's {@link SkillDiscovery} names: directories are entered only while a
215
+ * deeper `SKILL.md` could still be read, and the same {@link sessionSkillDirs}
216
+ * the pure filter asks decides which file counts.
217
+ */
218
+ function sessionSkillFiles(root, home, discovery) {
219
+ // A linked skill folder is entered — `vigiles init` links shipped skills in
220
+ // as directories, and the harness lists them — through the SAME classifier
221
+ // the loader's skills walk uses (`skillTreeEntryOf`), so the audit's skill
222
+ // count and this listing cannot disagree about which folders exist. One
223
+ // directory link per path; a link back over the tree is refused.
224
+ const walk = (rel, depth, mayFollow) => namesIn((0, node_path_1.join)(root, home, rel)).flatMap((name) => {
225
+ const childRel = rel === "" ? name : `${rel}/${name}`;
226
+ const entry = (0, fs_walk_js_1.skillTreeEntryOf)((0, node_path_1.join)(root, home, childRel), root, mayFollow);
227
+ if (entry.kind === "file") {
228
+ return (0, layout_js_1.sessionSkillDirs)(childRel, discovery) === null
229
+ ? []
230
+ : [`${home}/${childRel}`];
231
+ }
232
+ const enter = entry.kind === "dir" &&
233
+ depth < discovery.maxDepth &&
234
+ !(discovery.skipHidden && name.startsWith("."));
235
+ return enter ? walk(childRel, depth + 1, entry.mayFollowBelow) : [];
236
+ });
237
+ return walk("", 0, true);
238
+ }
239
+ /**
240
+ * The files the ALWAYS-LOADED CONTEXT reads beyond the instruction candidates: the
241
+ * style files in the folder a session at the root reads styles from, and each
242
+ * `SKILL.md` under the session's skills folder at a depth the harness reads —
243
+ * the two inputs `core/always-loaded.ts` filters, by the same paths, out of the
244
+ * browser engine's fetched tree.
245
+ *
246
+ * Two NAMED directories, not a walk of the repository: the layout says where
247
+ * both are and how deep the harness looks under each, and nothing else is
248
+ * read. `exclude` does not apply, for the reason it does not apply to the
249
+ * instruction weight: the harness loads these whatever vigiles lints, and the
250
+ * number is a committed baseline that one more `exclude` line would otherwise
251
+ * lower.
252
+ */
253
+ function alwaysLoadedFiles(root, layout) {
254
+ const styleHome = (0, output_style_js_1.outputStyleHomes)(layout).at(-1);
255
+ const skillHome = (0, layout_js_1.skillsHome)(layout);
256
+ const styles = styleHome === undefined ? [] : filesDirectlyIn(root, styleHome);
257
+ const skills = skillHome === null
258
+ ? []
259
+ : sessionSkillFiles(root, skillHome, (0, layout_js_1.skillDiscoveryOf)(layout));
260
+ return Object.fromEntries([...styles, ...skills].flatMap((rel) => {
261
+ const text = readIfFile(root, rel);
262
+ return text === undefined ? [] : [[rel, text]];
263
+ }));
264
+ }
210
265
  //# sourceMappingURL=surface-discovery-fs.js.map
@@ -1644,7 +1644,7 @@
1644
1644
  }
1645
1645
  ]
1646
1646
  },
1647
- "instruction-weight": {
1647
+ "context-creep": {
1648
1648
  "anyOf": [
1649
1649
  {
1650
1650
  "anyOf": [
@@ -3099,7 +3099,7 @@
3099
3099
  }
3100
3100
  ]
3101
3101
  },
3102
- "instruction-weight": {
3102
+ "context-creep": {
3103
3103
  "anyOf": [
3104
3104
  {
3105
3105
  "type": "string",
@@ -5,7 +5,9 @@
5
5
  # Uses `vigiles lint --summary` which is designed for this: it
6
6
  # silences all per-stage output and prints a single line like
7
7
  # vigiles: 3 stale / 2 validation errors / 1 duplicate
8
- # (or "vigiles: clean") so the injection costs a handful of tokens.
8
+ # (or "vigiles: clean") so the injection costs a handful of tokens. While a
9
+ # repo still has the old baseline file it adds one `vigiles: note — … git mv …`
10
+ # line, so the agent renames it.
9
11
  #
10
12
  # Hook runs on the `startup` and `compact` matchers — the latter is
11
13
  # effectively free on token budget because it fires every time
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vigiles",
3
- "version": "39.2.0",
3
+ "version": "40.0.0",
4
4
  "description": "Audit, test and measure the harness your AI agent runs on — grade your CLAUDE.md / AGENTS.md, skills, subagents and hooks, run them against a scripted model, and measure whether they actually fire.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -1,181 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readInstructionBaseline = readInstructionBaseline;
4
- exports.writeInstructionBaseline = writeInstructionBaseline;
5
- exports.ratchetLines = ratchetLines;
6
- exports.updateRefusals = updateRefusals;
7
- exports.checkInstructionWeightRatchet = checkInstructionWeightRatchet;
8
- exports.compileWeightLine = compileWeightLine;
9
- /**
10
- * `lint`'s side of the instruction-weight ratchet: measure each scored bundle,
11
- * compare it with `.vigiles/instruction-weight.json`, and — only under the
12
- * explicit `--update-baseline` — write that file.
13
- *
14
- * The decisions (what a verdict is, what it says) live in
15
- * `core/instruction-baseline.ts`; this module owns the two effects the core
16
- * must not have, reading and writing the committed file, plus turning verdicts
17
- * into lint counters.
18
- *
19
- * WHY THE FILE IS COMMITTED, unlike `.vigiles/coverage.json`. Coverage records
20
- * what tests ran on THIS machine, so a committed copy would credit a checkout
21
- * where nothing ran. The baseline records a property of the COMMIT: it is built
22
- * from `committedTotal`, which already leaves out every per-machine file
23
- * (`CLAUDE.local.md`, a gitignored settings sibling), so two clones of one
24
- * commit compute byte-identical files. That is what lets CI compare against it.
25
- */
26
- const node_fs_1 = require("node:fs");
27
- const node_path_1 = require("node:path");
28
- const instruction_baseline_js_1 = require("./core/instruction-baseline.js");
29
- function readInstructionBaseline(root) {
30
- const path = (0, node_path_1.join)(root, instruction_baseline_js_1.INSTRUCTION_BASELINE_FILE);
31
- return (0, node_fs_1.existsSync)(path)
32
- ? (0, instruction_baseline_js_1.parseInstructionBaseline)((0, node_fs_1.readFileSync)(path, "utf-8"))
33
- : { kind: "absent" };
34
- }
35
- /** Write the baseline for every measured bundle; returns what was written. */
36
- function writeInstructionBaseline(root, onDisk, measured) {
37
- const next = (0, instruction_baseline_js_1.recordEntries)(onDisk.kind === "ok" ? onDisk.baseline : undefined, measured.map(([at, w]) => [at, w === null ? null : (0, instruction_baseline_js_1.entryFor)(w)]));
38
- const path = (0, node_path_1.join)(root, instruction_baseline_js_1.INSTRUCTION_BASELINE_FILE);
39
- (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(path), { recursive: true });
40
- (0, node_fs_1.writeFileSync)(path, (0, instruction_baseline_js_1.serializeBaseline)(next));
41
- return next;
42
- }
43
- /**
44
- * Pure: the lines a run prints, given what was measured and what is on disk.
45
- * `max` is the opt-in absolute ceiling; a bundle over it adds a finding of its
46
- * own, whatever the baseline says (including when there is none, or it is
47
- * unreadable).
48
- *
49
- * A bundle with no entry is a nudge while the repo has NO baseline file (it has
50
- * not opted in, and a fresh repo must not fail on day one) — but a FINDING once
51
- * the file exists: a bundle that appeared after the baseline was recorded is
52
- * weight nobody signed off on.
53
- */
54
- function ratchetLines(onDisk, measured, max) {
55
- return [
56
- ...baselineLines(onDisk, measured),
57
- ...measured.flatMap(([at, weight]) => ceilingLine(at, weight, max)),
58
- ];
59
- }
60
- /** One bundle's ceiling finding, or nothing when it is at or under `max`. */
61
- function ceilingLine(at, weight, max) {
62
- const over = weight === null ? undefined : (0, instruction_baseline_js_1.checkCeiling)(weight, max);
63
- return over === undefined
64
- ? []
65
- : [{ at, status: "finding", text: (0, instruction_baseline_js_1.formatCeiling)(over, at) }];
66
- }
67
- function baselineLines(onDisk, measured) {
68
- if (onDisk.kind === "invalid") {
69
- return [
70
- {
71
- at: ".",
72
- status: "finding",
73
- text: `${instruction_baseline_js_1.INSTRUCTION_BASELINE_FILE} cannot be read (${onDisk.message}) — ` +
74
- `re-record it with \`${instruction_baseline_js_1.UPDATE_BASELINE_COMMAND}\``,
75
- },
76
- ];
77
- }
78
- const recorded = onDisk.kind === "ok" ? onDisk.baseline.bundles : {};
79
- return measured.flatMap(([at, weight]) => {
80
- if (weight === null)
81
- return [];
82
- const verdict = (0, instruction_baseline_js_1.compareToBaseline)(weight, Object.hasOwn(recorded, at) ? recorded[at] : undefined);
83
- const status = verdict.kind === "held"
84
- ? "ok"
85
- : verdict.kind === "unrecorded" && onDisk.kind !== "ok"
86
- ? "note"
87
- : "finding";
88
- // An import named and not read is weight this number lacks — a second
89
- // hop, or a path that does not resolve. Said on the line itself, because
90
- // the gate holding is only as true as the sum it holds.
91
- const unfollowed = weight.unreadImports.length > 0
92
- ? ` (${String(weight.unreadImports.length)} import(s) not followed: ${weight.unreadImports.join(", ")} — their size is not in this number)`
93
- : "";
94
- return [{ at, status, text: `${(0, instruction_baseline_js_1.formatVerdict)(verdict, at)}${unfollowed}` }];
95
- });
96
- }
97
- /**
98
- * The bundles `--update-baseline` must not record: each one over the ceiling,
99
- * as the refusal text. Empty when there is no ceiling or nothing exceeds it.
100
- */
101
- function updateRefusals(measured, max) {
102
- return measured.flatMap(([at, weight]) => {
103
- const over = weight === null ? undefined : (0, instruction_baseline_js_1.checkCeiling)(weight, max);
104
- return over === undefined ? [] : [(0, instruction_baseline_js_1.formatRefusal)(over, at)];
105
- });
106
- }
107
- /**
108
- * What `lint` compares against: the file as it is, or — under `--update-baseline`
109
- * and when nothing is over the ceiling — the file just written. A baseline above
110
- * the ceiling would bypass it (re-recording is how a ratchet gets loosened), so
111
- * then nothing is written and the refusals are returned for the caller to fail on.
112
- */
113
- function recordOrRead(opts, measured) {
114
- const before = readInstructionBaseline(opts.root);
115
- const refusals = opts.update ? updateRefusals(measured, opts.max) : [];
116
- const record = opts.update && refusals.length === 0;
117
- return {
118
- refusals,
119
- onDisk: record
120
- ? {
121
- kind: "ok",
122
- baseline: writeInstructionBaseline(opts.root, before, measured),
123
- }
124
- : before,
125
- };
126
- }
127
- /** The human-readable report: what was recorded, then one line per bundle. */
128
- function printReport(lines, severity, recorded) {
129
- console.log("\nInstruction-weight ratchet:\n");
130
- if (recorded)
131
- console.log(` ✓ recorded ${instruction_baseline_js_1.INSTRUCTION_BASELINE_FILE}`);
132
- const marks = {
133
- finding: severity === "error" ? "✗" : "⚠",
134
- ok: "✓",
135
- note: "ℹ",
136
- };
137
- lines.forEach((l) => {
138
- console.log(` ${marks[l.status]} ${l.text}`);
139
- });
140
- }
141
- /** Run the ratchet for `lint`: print, annotate, count. */
142
- function checkInstructionWeightRatchet(opts) {
143
- const { severity, update, silent } = opts;
144
- if (!severity && !update)
145
- return { issues: 0, errors: 0 };
146
- const measured = opts.measure();
147
- const { onDisk, refusals } = recordOrRead(opts, measured);
148
- refusals.forEach((message) => {
149
- console.error(`✗ ${message}`);
150
- opts.annotate("error", message);
151
- });
152
- const lines = severity ? ratchetLines(onDisk, measured, opts.max) : [];
153
- const findings = lines.filter((l) => l.status === "finding");
154
- if (!silent && (update || lines.length > 0)) {
155
- printReport(lines, severity, update && refusals.length === 0);
156
- }
157
- const level = severity === "error" ? "error" : "warning";
158
- findings.forEach((l) => {
159
- opts.annotate(level, l.text);
160
- });
161
- return {
162
- issues: findings.length + refusals.length,
163
- errors: (severity === "error" ? findings.length : 0) + refusals.length,
164
- };
165
- }
166
- /**
167
- * The line `compile` prints after writing instruction files: the weight NOW,
168
- * against the baseline, at the moment the author changed it. Report-only —
169
- * `lint` stays the single gate. `null` when there is nothing to weigh.
170
- */
171
- function compileWeightLine(root, weight) {
172
- if (weight === null)
173
- return null;
174
- const onDisk = readInstructionBaseline(root);
175
- if (onDisk.kind === "invalid") {
176
- return `always-loaded: ${instruction_baseline_js_1.INSTRUCTION_BASELINE_FILE} cannot be read (${onDisk.message})`;
177
- }
178
- const recorded = onDisk.kind === "ok" ? onDisk.baseline.bundles : {};
179
- return (0, instruction_baseline_js_1.formatWeightLine)((0, instruction_baseline_js_1.compareToBaseline)(weight, Object.hasOwn(recorded, ".") ? recorded["."] : undefined));
180
- }
181
- //# sourceMappingURL=instruction-weight-ratchet.js.map