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.
@@ -87,9 +87,10 @@ interface LintReport {
87
87
  contextCreepIssues: number;
88
88
  contextCreepErrors: number;
89
89
  /**
90
- * Notes the context-creep ratchet raises that never count: today the one
91
- * naming the old baseline file and the command that moves it. `--summary`
92
- * prints them, because the session-start hook injects that output.
90
+ * Notes the always-loaded check raises that never count: over a limit with
91
+ * no baseline recorded, and an old baseline file to migrate — each with its
92
+ * command. `--summary` prints them, because the session-start hook injects
93
+ * that output.
93
94
  */
94
95
  contextCreepNotes: readonly string[];
95
96
  deprecatedKeyFilesIssues: number;
package/dist/cli-main.js CHANGED
@@ -49,7 +49,8 @@ const setup_plan_js_1 = require("./setup-plan.js");
49
49
  const types_js_1 = require("./core/types.js");
50
50
  const test_coverage_js_1 = require("./test-coverage.js");
51
51
  const scan_js_1 = require("./scan.js");
52
- const context_creep_ratchet_js_1 = require("./context-creep-ratchet.js");
52
+ const context_creep_lint_js_1 = require("./context-creep-lint.js");
53
+ const always_loaded_limits_js_1 = require("./core/always-loaded-limits.js");
53
54
  const frame_js_1 = require("./core/frame.js");
54
55
  const surface_discovery_js_1 = require("./core/surface-discovery.js");
55
56
  const scan_trigger_suggest_js_1 = require("./scan-trigger-suggest.js");
@@ -117,6 +118,47 @@ const CONFIG = (0, config_schema_js_1.configFor)(index_js_1.RULES, index_js_1.RU
117
118
  const INIT_POLICY = (0, rule_js_1.initPolicyOf)(index_js_1.RULES, index_js_1.RULE_GROUPS);
118
119
  /** Every rule at its shipped default — what a missing `.vigilesrc.json` loads as. */
119
120
  const DEFAULT_CONFIG = (0, validate_js_1.configDefaults)(CONFIG);
121
+ /**
122
+ * The always-loaded rule, asked of the set by its detector rather than by
123
+ * name: `lint`, `compile` and `init` read its severity and options, and the
124
+ * baseline store keys its entries by its id.
125
+ */
126
+ const ALWAYS_LOADED_RULE = (() => {
127
+ const rule = index_js_1.RULES.find((r) => r.detector === always_loaded_limits_js_1.checkAlwaysLoadedLimits.name);
128
+ if (rule === undefined)
129
+ throw new Error("no rule reports checkAlwaysLoadedLimits");
130
+ return rule.id;
131
+ })();
132
+ /**
133
+ * The repository's files under `root`, for the baseline store — the file
134
+ * system I/O the context-creep module takes as a port.
135
+ */
136
+ function repoFiles(root) {
137
+ return {
138
+ read: (path) => {
139
+ const abs = (0, node_path_1.join)(root, path);
140
+ return (0, node_fs_1.existsSync)(abs) ? (0, node_fs_1.readFileSync)(abs, "utf-8") : undefined;
141
+ },
142
+ write: (path, text) => {
143
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)((0, node_path_1.join)(root, path)), { recursive: true });
144
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, path), text);
145
+ },
146
+ remove: (path) => {
147
+ (0, node_fs_1.rmSync)((0, node_path_1.join)(root, path), { force: true });
148
+ },
149
+ exists: (path) => (0, node_fs_1.existsSync)((0, node_path_1.join)(root, path)),
150
+ };
151
+ }
152
+ /** The always-loaded rule's limit options, as `.vigilesrc.json` sets them. */
153
+ function alwaysLoadedLimits(config) {
154
+ const value = config?.rules?.[ALWAYS_LOADED_RULE];
155
+ const parsed = index_js_1.contextCreepOptions.safeParse(Array.isArray(value) ? value[1] : {});
156
+ const opts = parsed.success ? parsed.data : undefined;
157
+ return {
158
+ ...(opts?.limits === undefined ? {} : { limits: opts.limits }),
159
+ ...(opts?.max === undefined ? {} : { max: opts.max }),
160
+ };
161
+ }
120
162
  /** `.vigilesrc.json` for this rule set; see `core/validate.ts` `loadConfig`. */
121
163
  function loadConfig(searchFrom, opts) {
122
164
  return (0, validate_js_1.loadConfig)(CONFIG, searchFrom, opts);
@@ -1870,13 +1912,15 @@ async function runLint(restArgs, flags, excludes, config) {
1870
1912
  // typo, an uncompilable or unreachable MCP pattern, one too narrow for real
1871
1913
  // server naming, or an undeclared MCP server).
1872
1914
  const hookMatcher = overBundles(checkHookMatcher, run, lintRoots);
1873
- // 7v. Context-creep ratchet — the always-loaded instruction weight may
1874
- // not move off the committed baseline. One file for the whole run (bundles
1875
- // are keys inside it), so it runs ONCE over `lintRoots`, not per bundle.
1876
- const contextCreep = (0, context_creep_ratchet_js_1.checkContextCreepRatchet)({
1877
- root: frame.root,
1878
- severity: (0, types_js_1.ruleSeverity)(config?.rules?.["context-creep"]),
1879
- max: (0, types_js_1.ruleOptions)(config?.rules?.["context-creep"])?.max,
1915
+ // 7v. Context creep — the always-loaded context against the harness's own
1916
+ // limits, then the baseline store over those findings. One store for the
1917
+ // whole run (bundles are keys inside it), so it runs ONCE over `lintRoots`.
1918
+ const contextCreep = (0, context_creep_lint_js_1.checkContextCreep)({
1919
+ ruleId: ALWAYS_LOADED_RULE,
1920
+ files: repoFiles(frame.root),
1921
+ scope: frame.bundle(scanRoot).at,
1922
+ severity: (0, types_js_1.ruleSeverity)(config?.rules?.[ALWAYS_LOADED_RULE]),
1923
+ ...alwaysLoadedLimits(config),
1880
1924
  update: flags.includes("--update-baseline"),
1881
1925
  silent,
1882
1926
  measure: () => lintRoots.map((abs) => measuredBundle(frame.bundle(abs).at, abs, adapter)),
@@ -2126,8 +2170,8 @@ function printLintSummary(report) {
2126
2170
  else {
2127
2171
  console.log(`vigiles: ${parts.join(" / ")}`);
2128
2172
  }
2129
- // One extra line per note, only when there is one: the old baseline file's
2130
- // rename command reaches the agent through the session-start hook.
2173
+ // One extra line per note, only when there is one: the command to record or
2174
+ // migrate the baseline reaches the agent through the session-start hook.
2131
2175
  report.contextCreepNotes.forEach((note) => {
2132
2176
  console.log(`vigiles: note — ${note}`);
2133
2177
  });
@@ -3973,13 +4017,17 @@ async function setup(args) {
3973
4017
  specs: plan.scaffoldSpecs,
3974
4018
  written,
3975
4019
  });
4020
+ // The always-loaded baseline, on a repository already over a limit: the
4021
+ // gate starts from today's size instead of waiting for someone to find the
4022
+ // flag. Read after the config is written, so the harness it records is used.
4023
+ const baseline = plan.lint ? initBaseline() : [];
3976
4024
  printSetupSummary({
3977
4025
  plan,
3978
4026
  strict,
3979
4027
  targets,
3980
4028
  adopted,
3981
4029
  // The skill links the plugin step created, so the commit hint names them.
3982
- written: [...written, ...linkedSkills],
4030
+ written: [...written, ...linkedSkills, ...baseline],
3983
4031
  });
3984
4032
  // Surface the OTHER mode so both directions are discoverable — the two branches
3985
4033
  // are mutually exclusive (a run is either gate-only or full):
@@ -4013,7 +4061,10 @@ function minimalRerun(parsed, state) {
4013
4061
  printDetection(detected, harnesses);
4014
4062
  const links = plan.plugin ? linkSkillsOnly(harnesses) : [];
4015
4063
  const devDep = plan.lint || plan.test ? addMissingVigilesDevDep() : [];
4016
- const written = [...links, ...devDep];
4064
+ // A missing always-loaded baseline is missing AND local: recorded only on a
4065
+ // repository over a limit, never over an existing one.
4066
+ const baseline = plan.lint ? initBaseline() : [];
4067
+ const written = [...links, ...devDep, ...baseline];
4017
4068
  if (written.length === 0)
4018
4069
  console.log("\nNothing was missing.");
4019
4070
  const followUps = (0, setup_plan_js_1.fullSetupFollowUps)(fullSetupGap(plan, detected, harnesses), INIT_POLICY.preset);
@@ -4022,6 +4073,60 @@ function minimalRerun(parsed, state) {
4022
4073
  if (written.length > 0)
4023
4074
  console.log(`\n Commit:\n git add ${written.join(" ")} && git commit -m "Update vigiles"`);
4024
4075
  }
4076
+ /**
4077
+ * `compile`'s always-loaded line: the size now against each limit, and against
4078
+ * the baseline when over one. Report-only — `lint` is the gate.
4079
+ */
4080
+ function printCompileWeight(projectRoot, harnessFlag, config) {
4081
+ const adapter = (0, adapter_registry_js_1.resolveHarnessSelection)({
4082
+ root: projectRoot,
4083
+ flag: harnessFlag,
4084
+ configHarness: (0, adapter_registry_js_1.declaredHarnessNames)(config.harnesses),
4085
+ }).adapter;
4086
+ const line = (0, context_creep_lint_js_1.compileWeightLine)(repoFiles(projectRoot), ALWAYS_LOADED_RULE, measuredBundle(".", projectRoot, adapter), alwaysLoadedLimits(config));
4087
+ if (line !== null)
4088
+ console.log(`\n${line}`);
4089
+ }
4090
+ /** What `init` prints about the always-loaded baseline. */
4091
+ function initBaselineLine(outcome) {
4092
+ switch (outcome.kind) {
4093
+ case "under-limits":
4094
+ return undefined;
4095
+ case "kept":
4096
+ return `✓ ${outcome.file} already holds the always-loaded baseline — left as it is`;
4097
+ case "legacy":
4098
+ return `ℹ ${outcome.file} is the old always-loaded baseline — migrate it with \`${outcome.command}\` (it keeps the recorded numbers)`;
4099
+ case "recorded":
4100
+ return (`✓ always-loaded context: ${outcome.over.join("; ")}. Recorded ${outcome.file} — commit it. ` +
4101
+ "CI now fails only if it grows past that size.");
4102
+ }
4103
+ }
4104
+ /**
4105
+ * `init`'s baseline step over the repository root: record the always-loaded
4106
+ * baseline when the repository is over a harness limit and has none. Off when
4107
+ * the rule is off. Returns the file written, for the commit hint.
4108
+ */
4109
+ function initBaseline() {
4110
+ const root = process.cwd();
4111
+ const config = loadConfig();
4112
+ if (!(0, types_js_1.ruleSeverity)(config.rules?.[ALWAYS_LOADED_RULE]))
4113
+ return [];
4114
+ const adapter = (0, adapter_registry_js_1.resolveHarnessSelection)({
4115
+ root,
4116
+ flag: undefined,
4117
+ configHarness: (0, adapter_registry_js_1.declaredHarnessNames)(config.harnesses),
4118
+ }).adapter;
4119
+ // The bundles `lint` scores, so the next `lint` finds an entry for each.
4120
+ const frame = (0, frame_js_1.frameFor)(root, root);
4121
+ const bundles = config.bundles === "all"
4122
+ ? [root, ...discoverNestedBundles(root, (0, exclude_js_1.excludeSet)(root, config.exclude))]
4123
+ : [root];
4124
+ const outcome = (0, context_creep_lint_js_1.recordIfMissing)(repoFiles(root), ALWAYS_LOADED_RULE, bundles.map((abs) => measuredBundle(frame.bundle(abs).at, abs, adapter)), alwaysLoadedLimits(config));
4125
+ const line = initBaselineLine(outcome);
4126
+ if (line !== undefined)
4127
+ console.log(`\n${line}`);
4128
+ return outcome.kind === "recorded" ? [outcome.file] : [];
4129
+ }
4025
4130
  /**
4026
4131
  * Link the shipped skills for each harness that links them — the safe, local
4027
4132
  * half of `installPlugins`, without the global install or config wiring.
@@ -7491,19 +7596,10 @@ async function main() {
7491
7596
  if (specs.length > 0)
7492
7597
  valid =
7493
7598
  (await compile(specs, config, excludes, { harnessFlag })) && valid;
7494
- // The always-loaded weight the author just produced, against the
7495
- // committed baseline — shown at the moment of change. Report-only:
7496
- // `lint` is the gate (rule `context-creep`).
7497
- if (specs.length > 0) {
7498
- const measured = measuredBundle(".", projectRoot, (0, adapter_registry_js_1.resolveHarnessSelection)({
7499
- root: projectRoot,
7500
- flag: harnessFlag,
7501
- configHarness: (0, adapter_registry_js_1.declaredHarnessNames)(config.harnesses),
7502
- }).adapter);
7503
- const weightLine = (0, context_creep_ratchet_js_1.compileWeightLine)(projectRoot, measured);
7504
- if (weightLine !== null)
7505
- console.log(`\n${weightLine}`);
7506
- }
7599
+ // The always-loaded size the author just produced, against the
7600
+ // harness's limits — shown at the moment of change. Report-only.
7601
+ if (specs.length > 0)
7602
+ printCompileWeight(projectRoot, harnessFlag, config);
7507
7603
  valid =
7508
7604
  (await installHooks(hooks, harnessFlag, (0, adapter_registry_js_1.declaredHarnessNames)(config.harnesses),
7509
7605
  // A hook-side compile is under way even when every hook was refused:
@@ -0,0 +1,123 @@
1
+ /**
2
+ * `lint`'s side of the always-loaded check: measure each scored bundle, let
3
+ * the detector (`core/always-loaded-limits.ts`) say which parts are over the
4
+ * harness's limits, then apply the baseline store (`core/baseline-store.ts`)
5
+ * to those findings — and, only under the explicit `--update-baseline`, write
6
+ * the store.
7
+ *
8
+ * This module decides what is read, written and deleted — the store, and the
9
+ * file earlier releases wrote — and turns lines into lint counters and
10
+ * annotations. The bytes go through {@link BaselineFiles}, a port the
11
+ * composition root fills with the file system, so this module does no I/O of
12
+ * its own.
13
+ *
14
+ * WHY THE STORE IS COMMITTED, unlike `.vigiles/coverage.json`. Coverage records
15
+ * what tests ran on THIS machine. The store records a property of the COMMIT:
16
+ * every number in it is built from `committedTotal` and committed settings,
17
+ * which leave out per-machine files, so two clones of one commit compute
18
+ * byte-identical files. That is what lets CI compare against it.
19
+ *
20
+ * WHO WRITES. `lint` never does on its own — every default lint path is a read.
21
+ * `--update-baseline` writes the store while some bundle is over a limit and
22
+ * deletes it once nothing is; `init` writes it once on a repository that is
23
+ * over a limit and has none (`recordIfMissing`).
24
+ */
25
+ import { type RuleRun, type StoreLine, type StoreOnDisk } from "./core/baseline-store.js";
26
+ import { type LimitOverrides } from "./core/always-loaded-limits.js";
27
+ import type { AlwaysLoadedContext } from "./core/always-loaded.js";
28
+ import type { InstructionWeight } from "./core/instruction-weight.js";
29
+ import type { RuleSeverity } from "./core/types.js";
30
+ /**
31
+ * The repository's files, by path relative to the config root. The root fills
32
+ * it with the file system; a test can fill it with a map.
33
+ */
34
+ export interface BaselineFiles {
35
+ /** The file's text, or `undefined` when it does not exist. */
36
+ readonly read: (path: string) => string | undefined;
37
+ /** Write the file, creating its folder. */
38
+ readonly write: (path: string, text: string) => void;
39
+ /** Delete the file; nothing when it does not exist. */
40
+ readonly remove: (path: string) => void;
41
+ /** Whether a directory (a bundle) exists. */
42
+ readonly exists: (path: string) => boolean;
43
+ }
44
+ /**
45
+ * One bundle's measurement: where it is, and either nothing to weigh or its
46
+ * weight WITH the always-loaded context around it.
47
+ */
48
+ export type MeasuredBundle = readonly [at: string, weight: null] | readonly [
49
+ at: string,
50
+ weight: InstructionWeight,
51
+ loaded: AlwaysLoadedContext
52
+ ];
53
+ /** The rule's options that change what is measured against. */
54
+ export interface ContextCreepLimits {
55
+ /** Per-part limits from `.vigilesrc.json`; each one missing keeps the harness's. */
56
+ readonly limits?: LimitOverrides;
57
+ /** The opt-in absolute ceiling on the scored instructions; no baseline lifts it. */
58
+ readonly max?: number;
59
+ }
60
+ export declare function readBaselineStore(files: BaselineFiles): StoreOnDisk;
61
+ /** The old baseline files present in this repository, newest name first. */
62
+ export declare function legacyFilesPresent(files: BaselineFiles, ruleId: string): readonly string[];
63
+ /** What the stateless rule reports for the store to act on. */
64
+ export declare function contextCreepRun(ruleId: string, measured: readonly MeasuredBundle[], limits: ContextCreepLimits): RuleRun;
65
+ /** The bundles `--update-baseline` must not record: each one over the ceiling. */
66
+ export declare function updateRefusals(measured: readonly MeasuredBundle[], max: number | undefined): readonly string[];
67
+ /** The line a repository with an old baseline file gets: a finding, naming the command. */
68
+ export declare function legacyLine(file: string): StoreLine;
69
+ /** The options {@link checkContextCreep} takes. */
70
+ export interface ContextCreepOptions extends ContextCreepLimits {
71
+ readonly ruleId: string;
72
+ readonly files: BaselineFiles;
73
+ /** The scanned bundle (`.` = the whole repository); entries outside it are never touched. */
74
+ readonly scope: string;
75
+ readonly severity: RuleSeverity;
76
+ readonly update: boolean;
77
+ readonly silent: boolean;
78
+ /** Called only when the rule is on or an update was asked for. */
79
+ readonly measure: () => readonly MeasuredBundle[];
80
+ readonly annotate: (level: "error" | "warning" | "notice", message: string) => void;
81
+ }
82
+ /** What {@link checkContextCreep} hands back to `lint`. */
83
+ export interface ContextCreepResult {
84
+ readonly issues: number;
85
+ readonly errors: number;
86
+ /**
87
+ * One-line notes `--summary` prints (the session-start hook injects them):
88
+ * over a limit with no baseline, and an old baseline file to migrate.
89
+ */
90
+ readonly notes: readonly string[];
91
+ }
92
+ /** Run the check for `lint`: record if asked, then print, annotate, count. */
93
+ export declare function checkContextCreep(opts: ContextCreepOptions): ContextCreepResult;
94
+ /** What `init` did about the baseline, for its summary. */
95
+ export type InitBaseline = {
96
+ readonly kind: "under-limits";
97
+ } | {
98
+ readonly kind: "kept";
99
+ readonly file: string;
100
+ } | {
101
+ readonly kind: "legacy";
102
+ readonly file: string;
103
+ readonly command: string;
104
+ } | {
105
+ readonly kind: "recorded";
106
+ readonly file: string;
107
+ readonly over: readonly string[];
108
+ };
109
+ /**
110
+ * `init`'s step: record every bundle over a limit that has no entry yet, so
111
+ * the gate starts from today's size. An existing entry is never overwritten
112
+ * (a rerun adds only the bundles that are missing), and nothing is measured
113
+ * over an old file — that is what migrating is for, and re-measuring would
114
+ * accept unseen growth.
115
+ */
116
+ export declare function recordIfMissing(files: BaselineFiles, ruleId: string, measured: readonly MeasuredBundle[], limits: ContextCreepLimits): InitBaseline;
117
+ /**
118
+ * The line `compile` prints after writing instruction files: the size now,
119
+ * against each limit, and against the baseline when over one. Report-only —
120
+ * `lint` stays the single gate. `null` when there is nothing to weigh.
121
+ */
122
+ export declare function compileWeightLine(files: BaselineFiles, ruleId: string, measured: MeasuredBundle, limits: ContextCreepLimits): string | null;
123
+ //# sourceMappingURL=context-creep-lint.d.ts.map