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/adapter.d.ts CHANGED
@@ -17,8 +17,9 @@
17
17
  */
18
18
  export type { HarnessAdapter, AdapterCapabilities } from "./core/adapter.js";
19
19
  export type { HarnessDialect } from "./core/dialect.js";
20
- export type { PluginLayout, SurfaceDirs, SurfaceKind } from "./core/layout.js";
21
- export type { OutputStyle, OutputStyleRules } from "./core/output-style.js";
20
+ export type { PluginLayout, SkillDiscovery, SurfaceDirs, SurfaceKind, } from "./core/layout.js";
21
+ export type { OutputStyle, OutputStyleRules, StyleSelection, } from "./core/output-style.js";
22
+ export type { ListedSkill, SkillListingRules } from "./core/skill-listing.js";
22
23
  export type { ModelRequest } from "./core/harness-driver.js";
23
24
  export { executableSourceDirs, materializePrefix, surfaceDirs, } from "./core/layout.js";
24
25
  /**
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.claudeCodeDialect = exports.claudeCodeSideEffectingTools = exports.claudeCodeBuiltinAgentTools = void 0;
4
4
  const event_capability_js_1 = require("./event-capability.js");
5
+ const skill_listing_js_1 = require("./skill-listing.js");
5
6
  const vocabulary_js_1 = require("./vocabulary.js");
6
7
  /**
7
8
  * The Claude Code built-in subagent tool catalog as a `const` tuple, so a typed
@@ -92,6 +93,9 @@ exports.claudeCodeDialect = {
92
93
  // re-read on every request whatever the window. Read from the 2.1.296 binary.
93
94
  capturedFrom: "claude-code 2.1.296 large-file warning, floor of max(40000, window*0.05*charsPerToken); the rules dir measured 2026-09-16 in a consumer repo",
94
95
  },
96
+ // The session-start skill listing — part of the always-loaded context; see
97
+ // ./skill-listing.ts for each rule and its source.
98
+ skillListing: skill_listing_js_1.claudeCodeSkillListing,
95
99
  // The capability table — what each event CARRIES and HONOURS. Nine of the 31
96
100
  // events, each with its basis; see ./event-capability.ts. The three flat lists
97
101
  // above are kept for now and are ASSERTED against this table in
@@ -68,6 +68,20 @@ const reached = (style, request) => {
68
68
  const probe = squash(`${HEADER}${style.name}\n${style.body}`);
69
69
  return [request.system, ...request.messages.map((m) => m.text)].some((text) => squash(text).includes(probe));
70
70
  };
71
+ /**
72
+ * `outputStyle` in one settings file. `default` (any case) is Claude Code's own
73
+ * style, which adds no text; anything else is a name, matched by the harness
74
+ * against each style's `name` in exact case — a wrong case silently loads the
75
+ * default, which is why the resolution against files stays exact.
76
+ */
77
+ const selected = (settings) => {
78
+ const value = settings["outputStyle"];
79
+ if (typeof value !== "string" || value === "")
80
+ return { kind: "unset" };
81
+ return value.toLowerCase() === "default"
82
+ ? { kind: "default" }
83
+ : { kind: "named", name: value };
84
+ };
71
85
  exports.claudeCodeOutputStyles = {
72
86
  dir: "output-styles",
73
87
  isStyleFile: (pathInDir) => pathInDir.endsWith(".md"),
@@ -77,5 +91,6 @@ exports.claudeCodeOutputStyles = {
77
91
  // project; the project's own `default` wins over it (measured on 2.1.292).
78
92
  selectNone: { outputStyle: "default" },
79
93
  reached,
94
+ selected,
80
95
  };
81
96
  //# sourceMappingURL=output-style.js.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * How Claude Code renders a skill into the listing it loads at session start.
3
+ *
4
+ * MODELLED ON THE PINNED VERSION, `VALIDATED_CC_VERSION` in `dialect-drift.ts`
5
+ * (2.1.187) — the version the dialect is validated against and the one CI
6
+ * installs, so `skill-listing-delivery.test.ts` proves these rules against the
7
+ * binary on every run. Read from https://code.claude.com/docs/en/skills
8
+ * (fetched 2026-10-31) and measured against the mock model:
9
+ *
10
+ * - the LABEL is the skill's directory name, whatever the frontmatter `name`;
11
+ * - the text is the `description`, else the first non-empty line of the
12
+ * body, else the word `Skill`, trimmed; `when_to_use` "is appended to
13
+ * `description` … and counts toward the 1,536-character cap", joined by
14
+ * ` - `;
15
+ * - nothing else is rewritten: `<`, `>`, `&` and control characters reach
16
+ * the model as written;
17
+ * - the CAP applies to the combined text: over 1,536 UTF-16 units (or
18
+ * `skillListingMaxDescChars`), the first cap−1 units are kept and `…`
19
+ * appended — a cut that can split a surrogate pair, as Claude Code's does;
20
+ * - `disable-model-invocation: true` "removes the skill from Claude's context
21
+ * entirely";
22
+ * - `skillOverrides` is keyed by the DIRECTORY name (a key equal to the
23
+ * frontmatter name does nothing): `"name-only"` lists `- dir` alone,
24
+ * `"off"` and `"user-invocable-only"` do not list it.
25
+ *
26
+ * ⚠️ NEWER RELEASES RENDER MORE, so on them this is an UNDER-count. Measured on
27
+ * 2.1.316, against the same fixture:
28
+ *
29
+ * - `<` and `>` become `&lt;` and `&gt;` BEFORE the cap — +3 characters
30
+ * each (`- alpha: Run <cmd> now & then - When the user says <go>`, 55
31
+ * characters on 2.1.187, is 67 on 2.1.316);
32
+ * - a frontmatter `name` that differs from the directory follows it in
33
+ * parentheses, `- dir (name): …` — +3 plus the name's length;
34
+ * - each control, format, private-use or separator code point becomes one
35
+ * space — the same length, a different text.
36
+ *
37
+ * Moving to those rules is a bump of `VALIDATED_CC_VERSION`, which moves CI's
38
+ * binary with it; modelling them while CI runs the pinned release would leave
39
+ * the delivery test proving nothing.
40
+ *
41
+ * The listing as a WHOLE also has a budget (1% of the model's context window),
42
+ * past which descriptions are dropped by least use. That budget depends on the
43
+ * model and on this machine's usage, so it is not a property of a commit and
44
+ * is not modelled here; every entry is counted at its full capped size.
45
+ */
46
+ import type { SkillListingRules } from "../../core/skill-listing.js";
47
+ export declare const claudeCodeSkillListing: SkillListingRules;
48
+ //# sourceMappingURL=skill-listing.d.ts.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.claudeCodeSkillListing = void 0;
4
+ /** The documented per-entry cap, in characters (UTF-16 units, as measured). */
5
+ const ENTRY_CAP = 1536;
6
+ /** What replaces the cut tail; the cap includes it. */
7
+ const ELLIPSIS = "…";
8
+ /** The text an entry carries when the skill gives none. */
9
+ const NO_DESCRIPTION = "Skill";
10
+ /** The trimmed text, or `undefined` when nothing is left. */
11
+ function trimmed(v) {
12
+ if (typeof v !== "string")
13
+ return undefined;
14
+ const text = v.trim();
15
+ return text === "" ? undefined : text;
16
+ }
17
+ const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
18
+ /** The configured cap when it is a positive integer, else the documented one. */
19
+ const capFrom = (settings) => {
20
+ const v = settings["skillListingMaxDescChars"];
21
+ return typeof v === "number" && Number.isInteger(v) && v > 0 ? v : ENTRY_CAP;
22
+ };
23
+ const capped = (text, cap) => text.length <= cap ? text : text.slice(0, cap - 1) + ELLIPSIS;
24
+ const firstLine = (body) => body
25
+ .split("\n")
26
+ .map(trimmed)
27
+ .find((l) => l !== undefined);
28
+ /** `skillOverrides[dir]`, when the settings carry one for this skill. */
29
+ const overrideFor = (settings, dirName) => {
30
+ const overrides = settings["skillOverrides"];
31
+ return isRecord(overrides) ? overrides[dirName] : undefined;
32
+ };
33
+ const entry = (skill, settings) => {
34
+ const fm = skill.frontmatter;
35
+ // A skill whose frontmatter is not valid YAML is not registered by the
36
+ // harness (observed in a dogfood session: fixing the YAML made the skill
37
+ // appear in the listing it had been missing from).
38
+ if (fm === null || fm["disable-model-invocation"] === true)
39
+ return null;
40
+ const override = overrideFor(settings, skill.dirName);
41
+ if (override === "off" || override === "user-invocable-only")
42
+ return null;
43
+ if (override === "name-only")
44
+ return `- ${skill.dirName}`;
45
+ const description = trimmed(fm["description"]) ?? firstLine(skill.body) ?? NO_DESCRIPTION;
46
+ const whenToUse = trimmed(fm["when_to_use"]);
47
+ const combined = whenToUse === undefined ? description : `${description} - ${whenToUse}`;
48
+ return `- ${skill.dirName}: ${capped(combined, capFrom(settings))}`;
49
+ };
50
+ exports.claudeCodeSkillListing = {
51
+ entry,
52
+ capturedFrom: "code.claude.com/docs/en/skills (fetched 2026-10-31); measured on Claude Code 2.1.187 (VALIDATED_CC_VERSION)",
53
+ };
54
+ //# sourceMappingURL=skill-listing.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.codexDialect = void 0;
4
+ const skill_listing_js_1 = require("./skill-listing.js");
4
5
  exports.codexDialect = {
5
6
  name: "codex",
6
7
  // Codex model-facing tools (shell/exec, file edits, plan, web), + MCP tools.
@@ -44,6 +45,9 @@ exports.codexDialect = {
44
45
  // DIRECTORY along root→cwd, so at the root it is one file. A monorepo with
45
46
  // twelve package-level AGENTS.md files was told it was 12x over a budget no
46
47
  // session approaches. Which files load is now `codexLayout.instructionChain`.
48
+ // The session-start skill listing — part of the always-loaded context, counted in
49
+ // the same bytes as the instructions; see ./skill-listing.ts.
50
+ skillListing: skill_listing_js_1.codexSkillListing,
47
51
  instructionTargets: ["AGENTS.md"],
48
52
  pluginRootToken: "${PLUGIN_ROOT}",
49
53
  // Codex SKILL.md frontmatter is name + description ONLY — the richer keys
@@ -16,6 +16,11 @@ exports.codexLayout = {
16
16
  // NOT share a parent (`.agents/` vs `.codex/`), so no single root can name
17
17
  // both; spelling each dir in full is the only shape that keeps the reported key
18
18
  // equal to the real on-disk path.
19
+ // Repository skill roots are walked recursively: a SKILL.md directly in the
20
+ // folder up to six directories down, `.`-directories pruned
21
+ // (`codex-rs/ext/skills/src/loader/discovery.rs`; measured on 0.153.0 — see
22
+ // `SkillDiscovery`).
23
+ skillDiscovery: { minDepth: 0, maxDepth: 6, skipHidden: true },
19
24
  surfaces: {
20
25
  skill: ".agents/skills",
21
26
  // No `agent` key: Codex `[agents]` is a TOML concurrency table, not a
@@ -49,5 +49,12 @@ export declare function parseResponsesRequest(body: string): {
49
49
  */
50
50
  export declare function startCodexMock(script: readonly CodexTurn[], opts?: {
51
51
  onRequest?: (req: CodexRequest) => void;
52
+ /**
53
+ * The raw `/v1/responses` body, before {@link parseResponsesRequest}
54
+ * narrows it to the prompt. For a test that must see what the parse drops
55
+ * — the instructions and developer messages, where Codex puts its skill
56
+ * listing.
57
+ */
58
+ onBody?: (body: string) => void;
52
59
  }): Promise<CodexMockHandle>;
53
60
  //# sourceMappingURL=mock-model.d.ts.map
@@ -203,6 +203,7 @@ function startCodexMock(script, opts = {}) {
203
203
  res.end("{}");
204
204
  return;
205
205
  }
206
+ opts.onBody?.(body);
206
207
  const parsed = parseResponsesRequest(body);
207
208
  requests.push(parsed);
208
209
  opts.onRequest?.(parsed);
@@ -0,0 +1,42 @@
1
+ /**
2
+ * How Codex renders a skill into the listing it loads at session start.
3
+ *
4
+ * Read from the Codex source (`openai/codex`, main, fetched 2026-10-31) and
5
+ * measured on codex-cli 0.153.0 against the mock model
6
+ * (`skill-listing-delivery.test.ts` pins it):
7
+ *
8
+ * - WHICH SKILLS ARE LISTED (`codex-rs/skills/src/parser.rs`,
9
+ * `parse_skill_frontmatter_metadata`). A SKILL.md with no frontmatter
10
+ * block, with a block that is not valid YAML, with an empty description,
11
+ * or with a name over 64 characters fails to parse, is pushed to the
12
+ * loader's errors, and is not listed at all.
13
+ * - THE TEXT. Name and description each pass through `sanitize_single_line`
14
+ * (`split_whitespace().join(" ")`), so a multi-line description is one
15
+ * line. A missing name falls back to the skill's directory name.
16
+ * - THE ENTRY (`codex-rs/ext/skills/src/render.rs`): one line,
17
+ * `- {name}: {description} ({locator_kind}: {locator})`, where a skill on
18
+ * disk prints `file`.
19
+ * - THE CAP (`truncate_catalog_skill_description`): a description longer
20
+ * than 1,024 characters keeps its first 1,021 and gains `...`. Characters
21
+ * are Unicode scalar values, so an emoji is one character, not two.
22
+ *
23
+ * ⚠️ NOT MIRRORED, each an UNDER-count:
24
+ *
25
+ * - Codex repairs one kind of invalid YAML before giving up: an unquoted
26
+ * scalar holding `: `, as in `description: Build for AWS: ECS`, is quoted
27
+ * line by line and parsed again. vigiles reads such a block as malformed
28
+ * and does not list the skill, where Codex does.
29
+ * - THE LOCATOR is per machine. Codex prints either the absolute path or a
30
+ * short alias (`r1/<path under the skills folder>`, beside a table that
31
+ * maps `r1` to the absolute folder), whichever renders cheaper. Neither can
32
+ * be committed and compared in CI, so this module writes the repo-relative
33
+ * path; the size is reproducible from a commit, and each entry is off by
34
+ * the difference between that path and the one Codex printed.
35
+ *
36
+ * The listing as a whole has a budget (2% of the model's context window, or a
37
+ * configured token count), past which descriptions are dropped. It depends on
38
+ * the model, so it is not a property of a commit and is not modelled here.
39
+ */
40
+ import type { SkillListingRules } from "../../core/skill-listing.js";
41
+ export declare const codexSkillListing: SkillListingRules;
42
+ //# sourceMappingURL=skill-listing.d.ts.map
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codexSkillListing = void 0;
4
+ /** Longer descriptions are cut, in Unicode scalar values. */
5
+ const DESCRIPTION_CAP = 1024;
6
+ /** What replaces the cut tail; the cap includes it. */
7
+ const TRUNCATION_SUFFIX = "...";
8
+ /** A longer name fails to parse, in Unicode scalar values. */
9
+ const NAME_CAP = 64;
10
+ /** `sanitize_single_line`: every run of whitespace becomes one space. */
11
+ const singleLine = (v) => v.split(/\s+/u).filter(Boolean).join(" ");
12
+ /** A frontmatter value as Codex reads it, or `""` when it is not text. */
13
+ const field = (v) => typeof v === "string" ? singleLine(v) : "";
14
+ /** `truncate_catalog_skill_description`, counted in code points. */
15
+ function capped(description) {
16
+ // Code points, as Rust's `chars()` counts — not UTF-16 units, not graphemes.
17
+ const chars = Array.from(description);
18
+ return chars.length <= DESCRIPTION_CAP
19
+ ? description
20
+ : chars.slice(0, DESCRIPTION_CAP - TRUNCATION_SUFFIX.length).join("") +
21
+ TRUNCATION_SUFFIX;
22
+ }
23
+ const entry = (skill) => {
24
+ const fm = skill.frontmatter;
25
+ // `{}` is a file with no block, `null` a block that is not valid YAML; both
26
+ // are parse errors to Codex, and an empty description is one too.
27
+ if (fm === null)
28
+ return null;
29
+ const name = field(fm["name"]) || singleLine(skill.dirName);
30
+ const description = field(fm["description"]);
31
+ if (description === "" || name === "" || Array.from(name).length > NAME_CAP) {
32
+ return null;
33
+ }
34
+ return `- ${name}: ${capped(description)} (file: ${skill.path})`;
35
+ };
36
+ exports.codexSkillListing = {
37
+ entry,
38
+ capturedFrom: "openai/codex codex-rs/skills/src/parser.rs + codex-rs/ext/skills/src/render.rs (main, fetched 2026-10-31); measured on codex-cli 0.153.0",
39
+ };
40
+ //# sourceMappingURL=skill-listing.js.map
@@ -46,11 +46,16 @@ function injectReportData(template, report, serve) {
46
46
  if (!re.test(template)) {
47
47
  throw new Error("audit report template is missing the data placeholder");
48
48
  }
49
- let out = template.replace(re, escapeForScript(JSON.stringify(report)));
49
+ // Every replacement goes through a function: a replacement STRING reads `$1`,
50
+ // `$&`, `$'` and the like as patterns, and report text quotes files that say
51
+ // "$120/h". A function's return value is used verbatim.
52
+ const data = escapeForScript(JSON.stringify(report));
53
+ let out = template.replace(re, () => data);
50
54
  if (serve) {
51
55
  // Prepend the serve global onto the same statement that carries the data, so
52
56
  // it's set before the app bundle reads it. The token is hex, but escape anyway.
53
- out = out.replace("window.__VIGILES_DATA__", `window.__VIGILES_SERVE__=${escapeForScript(JSON.stringify(serve))};window.__VIGILES_DATA__`);
57
+ const prefix = `window.__VIGILES_SERVE__=${escapeForScript(JSON.stringify(serve))};`;
58
+ out = out.replace("window.__VIGILES_DATA__", () => `${prefix}window.__VIGILES_DATA__`);
54
59
  }
55
60
  return out;
56
61
  }
@@ -22,6 +22,7 @@ import type { RuleInventoryItem } from "./rule-inventory.js";
22
22
  import type { RuleRouting } from "./rule-routing.js";
23
23
  import type { EvidenceCounts } from "./coverage-evidence.js";
24
24
  import type { DeprecatedKeyFilesFinding } from "./deprecated-key-files.js";
25
+ import type { LoadedPartName } from "./core/always-loaded.js";
25
26
  import { type FilteredScan, type UngradedGroup } from "./core/apply-rules.js";
26
27
  /**
27
28
  * The current schema version. Bump only on a BREAKING change to the shape.
@@ -107,6 +108,49 @@ export interface Adoptable {
107
108
  /** The one command that adopts every surface at once. */
108
109
  readonly createAllCommand: string;
109
110
  }
111
+ /** One file's share of an always-loaded part, in the report's unit. */
112
+ export interface AlwaysLoadedFile {
113
+ readonly path: string;
114
+ readonly size: number;
115
+ }
116
+ /**
117
+ * One part of the always-loaded context. Only a `counted` part has a size: every other
118
+ * state is a reason there is none, kept apart because each reads differently
119
+ * (nothing selected · the harness has no such thing · vigiles does not model
120
+ * it · a style selected by a name no repository file declares).
121
+ */
122
+ export type AlwaysLoadedPart = {
123
+ readonly part: "instructions" | LoadedPartName;
124
+ readonly kind: "counted";
125
+ readonly total: number;
126
+ readonly files: readonly AlwaysLoadedFile[];
127
+ } | {
128
+ readonly part: LoadedPartName;
129
+ readonly kind: "none" | "not-supported" | "not-modelled";
130
+ } | {
131
+ readonly part: "output-style";
132
+ readonly kind: "unresolved";
133
+ /** The name the committed settings select. */
134
+ readonly name: string;
135
+ };
136
+ /**
137
+ * What the harness loads at session start before any decision: the
138
+ * instructions, the output style the committed settings select and the skill
139
+ * listing, in the harness's own unit (characters or bytes, never tokens). The
140
+ * part of every request the REPOSITORY decides — the harness's own prompt,
141
+ * user and plugin skills and the conversation come on top.
142
+ */
143
+ export interface AlwaysLoadedReport {
144
+ readonly unit: "chars" | "bytes";
145
+ /** The instructions plus every counted part. */
146
+ readonly total: number;
147
+ /** Always `instructions`, `output-style`, `skill-listing`, in that order. */
148
+ readonly parts: readonly AlwaysLoadedPart[];
149
+ }
150
+ /** How much context the harness carries before the conversation starts. */
151
+ export interface ContextCostReport {
152
+ readonly alwaysLoaded: AlwaysLoadedReport;
153
+ }
110
154
  /**
111
155
  * The full audit, as the dashboard / CI / HTML all consume it. Self-describing
112
156
  * and versioned; additive-only within a `schemaVersion`.
@@ -190,6 +234,13 @@ export interface AuditReport {
190
234
  * Present only when at least one atomic rule was segmented. Additive/optional.
191
235
  */
192
236
  readonly ruleRouting?: RuleRouting;
237
+ /**
238
+ * The context the harness carries before any decision, per part
239
+ * ({@link ContextCostReport}). Present whenever the harness publishes an
240
+ * instruction budget — the same condition as the terminal's weight block.
241
+ * Additive/optional — schema version unchanged.
242
+ */
243
+ readonly contextCost?: ContextCostReport;
193
244
  }
194
245
  export interface BuildAuditReportOptions extends AuditScoreOptions {
195
246
  readonly harness: string;
@@ -75,6 +75,47 @@ function inventoryOf(report) {
75
75
  function outputStylesField(n) {
76
76
  return n === undefined || n === 0 ? {} : { outputStyles: n };
77
77
  }
78
+ /** One scan-side part as the report carries it. */
79
+ function loadedPartReport(part, value) {
80
+ switch (value.kind) {
81
+ case "counted":
82
+ return { part, kind: "counted", total: value.total, files: value.files };
83
+ case "unresolved":
84
+ return { part: "output-style", kind: "unresolved", name: value.name };
85
+ case "none":
86
+ case "not-supported":
87
+ case "not-modelled":
88
+ return { part, kind: value.kind };
89
+ }
90
+ }
91
+ /** The report's `contextCost`, or nothing when the scan weighed no instructions. */
92
+ function contextCostField(report) {
93
+ const weight = report.instructionWeight;
94
+ const loaded = report.alwaysLoaded;
95
+ if (weight === null || loaded === undefined)
96
+ return {};
97
+ const files = weight.files
98
+ .filter((f) => f.scope === "repo")
99
+ .map((f) => ({ path: f.path, size: f.size }));
100
+ return {
101
+ contextCost: {
102
+ alwaysLoaded: {
103
+ unit: loaded.unit,
104
+ total: loaded.total,
105
+ parts: [
106
+ {
107
+ part: "instructions",
108
+ kind: "counted",
109
+ total: loaded.instructions,
110
+ files,
111
+ },
112
+ loadedPartReport("output-style", loaded.outputStyle),
113
+ loadedPartReport("skill-listing", loaded.skillListing),
114
+ ],
115
+ },
116
+ },
117
+ };
118
+ }
78
119
  /**
79
120
  * The scan's concrete finding lists, each present only when non-empty — and the
80
121
  * ungraded groups' blocks, present only when some rule of one is on.
@@ -101,6 +142,17 @@ function gradedPart(report, opts) {
101
142
  const verdict = (0, audit_verdict_js_1.computeVerdict)({ report: graded, score, recommendations });
102
143
  return { score, verdict, recommendations };
103
144
  }
145
+ /** The report's self-description; `generatedAt` is the CLI's, never set here. */
146
+ function auditMeta(dir, opts) {
147
+ return {
148
+ schemaVersion: exports.AUDIT_SCHEMA_VERSION,
149
+ tool: "vigiles",
150
+ kind: "audit",
151
+ vigilesVersion: opts.vigilesVersion,
152
+ harness: opts.harness,
153
+ dir,
154
+ };
155
+ }
104
156
  /**
105
157
  * Assemble the versioned {@link AuditReport} from a scan report — pure, no clock.
106
158
  * The CLI attaches `meta.generatedAt` when it writes the JSON artifact; the
@@ -112,19 +164,13 @@ report, opts) {
112
164
  const adoptable = buildAdoptable(opts.adoptableSurfaces);
113
165
  const { score, verdict, recommendations } = gradedPart(report, opts);
114
166
  return {
115
- meta: {
116
- schemaVersion: exports.AUDIT_SCHEMA_VERSION,
117
- tool: "vigiles",
118
- kind: "audit",
119
- vigilesVersion: opts.vigilesVersion,
120
- harness: opts.harness,
121
- dir: report.dir,
122
- },
167
+ meta: auditMeta(report.dir, opts),
123
168
  score,
124
169
  verdict,
125
170
  recommendations,
126
171
  inventory: inventoryOf(report),
127
172
  ...scanFindingLists(report),
173
+ ...contextCostField(report),
128
174
  ...(adoptable ? { adoptable } : {}),
129
175
  ...(opts.observations ? { observations: opts.observations } : {}),
130
176
  ...(opts.rulesInventory && opts.rulesInventory.length