vigiles 40.1.0 → 41.1.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 (54) hide show
  1. package/dist/adapter.d.ts +1 -1
  2. package/dist/adapters/claude-code/skill-listing.d.ts +27 -5
  3. package/dist/adapters/claude-code/skill-listing.js +29 -1
  4. package/dist/adapters/codex/skill-listing.d.ts +22 -4
  5. package/dist/adapters/codex/skill-listing.js +30 -1
  6. package/dist/cli-main.d.ts +4 -3
  7. package/dist/cli-main.js +121 -25
  8. package/dist/context-creep-lint.d.ts +123 -0
  9. package/dist/context-creep-lint.js +397 -0
  10. package/dist/core/always-loaded-limits.d.ts +118 -0
  11. package/dist/core/always-loaded-limits.js +175 -0
  12. package/dist/core/always-loaded.d.ts +15 -1
  13. package/dist/core/always-loaded.js +9 -0
  14. package/dist/core/baseline-store.d.ts +183 -0
  15. package/dist/core/baseline-store.js +392 -0
  16. package/dist/core/instruction-weight.d.ts +3 -3
  17. package/dist/core/instruction-weight.js +3 -3
  18. package/dist/core/legacy-baseline.d.ts +70 -0
  19. package/dist/core/legacy-baseline.js +117 -0
  20. package/dist/core/rule-proof/kits/eslint.d.ts +30 -0
  21. package/dist/core/rule-proof/kits/eslint.js +130 -0
  22. package/dist/core/rule-proof/kits/index.d.ts +7 -0
  23. package/dist/core/rule-proof/kits/index.js +12 -0
  24. package/dist/core/rule-proof/kits/ruff.d.ts +28 -0
  25. package/dist/core/rule-proof/kits/ruff.js +178 -0
  26. package/dist/core/rule-proof/node-install.d.ts +32 -0
  27. package/dist/core/rule-proof/node-install.js +117 -0
  28. package/dist/core/rule-proof/pair.d.ts +11 -0
  29. package/dist/core/rule-proof/pair.js +61 -0
  30. package/dist/core/rule-proof/port.d.ts +77 -0
  31. package/dist/core/rule-proof/port.js +3 -0
  32. package/dist/core/rule-proof/report.d.ts +11 -0
  33. package/dist/core/rule-proof/report.js +36 -0
  34. package/dist/core/rule-proof/run.d.ts +58 -0
  35. package/dist/core/rule-proof/run.js +260 -0
  36. package/dist/core/rule-proof/types.d.ts +119 -0
  37. package/dist/core/rule-proof/types.js +13 -0
  38. package/dist/core/skill-listing.d.ts +24 -0
  39. package/dist/core/types.d.ts +14 -6
  40. package/dist/entries/rule-proof.d.ts +18 -0
  41. package/dist/entries/rule-proof.js +23 -0
  42. package/dist/host/rule-proof.io.d.ts +4 -0
  43. package/dist/host/rule-proof.io.js +64 -0
  44. package/dist/local-files.js +2 -2
  45. package/dist/rules/index.d.ts +25 -2
  46. package/dist/rules/index.js +22 -9
  47. package/dist/scan.js +27 -1
  48. package/dist/vigilesrc.schema.json +32 -0
  49. package/hooks/session-start.sh +4 -3
  50. package/package.json +2 -1
  51. package/dist/context-creep-ratchet.d.ts +0 -88
  52. package/dist/context-creep-ratchet.js +0 -270
  53. package/dist/core/instruction-baseline.d.ts +0 -333
  54. package/dist/core/instruction-baseline.js +0 -570
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eslintKit = void 0;
4
+ exports.pluginOf = pluginOf;
5
+ exports.eslintConfigModule = eslintConfigModule;
6
+ exports.parseEslintReport = parseEslintReport;
7
+ /**
8
+ * The ESLint kit: install through the repository's Node lockfile, one flat
9
+ * config per reading, and `--format json` read back as per-file reports.
10
+ */
11
+ const node_path_1 = require("node:path");
12
+ const zod_1 = require("zod");
13
+ const report_js_1 = require("../report.js");
14
+ const node_install_js_1 = require("../node-install.js");
15
+ /** The plugin package a rule id needs, by ESLint's naming convention. */
16
+ function pluginOf(rule) {
17
+ const parts = rule.split("/");
18
+ if (parts.length === 1)
19
+ return null;
20
+ const prefix = parts.slice(0, -1).join("/");
21
+ if (!prefix.startsWith("@"))
22
+ return { prefix, pkg: `eslint-plugin-${prefix}` };
23
+ const [scope, name] = prefix.split("/");
24
+ return {
25
+ prefix,
26
+ pkg: name === undefined
27
+ ? `${scope}/eslint-plugin`
28
+ : `${scope}/eslint-plugin-${name}`,
29
+ };
30
+ }
31
+ const json = (value) => JSON.stringify(value);
32
+ /**
33
+ * The flat-config module for one reading. The scope's `ignores` stand in a
34
+ * block of their own, which ESLint reads as GLOBAL ignores: a file there is
35
+ * reported as ignored. In the rule's block they would only make that block skip
36
+ * the file, and the file would still be linted — with no rule on, so it would
37
+ * read clean (measured on ESLint 10.1.0).
38
+ */
39
+ function eslintConfigModule(reading) {
40
+ const plugin = pluginOf(reading.rule);
41
+ const imports = [
42
+ ...(plugin === null ? [] : [`import plugin from ${json(plugin.pkg)};`]),
43
+ ...(reading.parser === undefined
44
+ ? []
45
+ : [`import parser from ${json(reading.parser)};`]),
46
+ ];
47
+ const block = [
48
+ `files: ${json(reading.scope.files)}`,
49
+ 'linterOptions: { reportUnusedDisableDirectives: "off" }',
50
+ ...(plugin === null ? [] : [`plugins: { ${json(plugin.prefix)}: plugin }`]),
51
+ ...(reading.parser === undefined ? [] : ["languageOptions: { parser }"]),
52
+ `rules: { ${json(reading.rule)}: ${json(["error", ...reading.options])} }`,
53
+ ];
54
+ return [
55
+ ...imports,
56
+ "export default [",
57
+ ` { ignores: ${json(reading.scope.ignores)} },`,
58
+ ` { ${block.join(", ")} },`,
59
+ "];",
60
+ "",
61
+ ].join("\n");
62
+ }
63
+ const reportSchema = zod_1.z.array(zod_1.z.object({
64
+ filePath: zod_1.z.string(),
65
+ messages: zod_1.z.array(zod_1.z.object({
66
+ ruleId: zod_1.z.string().nullable(),
67
+ fatal: zod_1.z.boolean().optional(),
68
+ message: zod_1.z.string(),
69
+ })),
70
+ }));
71
+ function fileReport(path, messages, rule) {
72
+ const fatal = messages.find((m) => m.fatal === true);
73
+ if (fatal !== undefined)
74
+ return { path, kind: "parse-error", message: fatal.message };
75
+ const ignored = messages.some((m) => m.ruleId === null && m.message.startsWith("File ignored"));
76
+ if (ignored)
77
+ return { path, kind: "ignored" };
78
+ return {
79
+ path,
80
+ kind: "linted",
81
+ hits: messages.filter((m) => m.ruleId === rule).length,
82
+ };
83
+ }
84
+ /** ESLint's `--format json` as per-file reports. */
85
+ function parseEslintReport(stdout, dir, rule) {
86
+ const parsed = reportSchema.safeParse((0, report_js_1.jsonArray)(stdout));
87
+ if (!parsed.success)
88
+ return (0, report_js_1.unreadable)(stdout);
89
+ return {
90
+ kind: "parsed",
91
+ files: parsed.data.map((f) => fileReport((0, report_js_1.toRelative)(dir, f.filePath), f.messages, rule)),
92
+ };
93
+ }
94
+ const CONFIG = ".vigiles-rule-proof.config.mjs";
95
+ exports.eslintKit = {
96
+ linter: "eslint",
97
+ plan(root) {
98
+ const plan = (0, node_install_js_1.nodeInstallPlan)({
99
+ lockfiles: root.names,
100
+ packageManager: (0, node_install_js_1.packageManagerIn)(root.read("package.json")),
101
+ });
102
+ if (plan.kind === "none")
103
+ return { kind: "none", stage: "no-lockfile", reason: plan.reason };
104
+ return {
105
+ kind: "plan",
106
+ install: plan.install,
107
+ command: (dir) => [(0, node_path_1.join)(dir, "node_modules/.bin/eslint")],
108
+ version: (read) => (0, node_install_js_1.versionIn)(read("node_modules/eslint/package.json")),
109
+ missing: "the install left no node_modules/eslint: the repository does not depend on it",
110
+ };
111
+ },
112
+ // ESLint 8 reads a flat config only when this is set; --config alone keeps
113
+ // it in legacy mode, and the generated config would not load. ESLint 9+
114
+ // ignores it.
115
+ env: (cacheDir) => ({
116
+ ...(0, node_install_js_1.nodeCacheEnv)(cacheDir),
117
+ ESLINT_USE_FLAT_CONFIG: "true",
118
+ }),
119
+ // The config sits in the repository, so its plugin imports resolve from the
120
+ // repository's own node_modules.
121
+ invocation: (reading, files, { dir }) => ({
122
+ configPath: (0, node_path_1.join)(dir, CONFIG),
123
+ configText: eslintConfigModule(reading),
124
+ args: ["--config", (0, node_path_1.join)(dir, CONFIG), "--format", "json", ...files],
125
+ }),
126
+ // 1 is "lint errors found"; 2 is a crash or a config that did not load.
127
+ reportCodes: [0, 1],
128
+ parse: (stdout, _files, reading, dir) => parseEslintReport(stdout, dir, reading.rule),
129
+ };
130
+ //# sourceMappingURL=eslint.js.map
@@ -0,0 +1,7 @@
1
+ export declare const PROOF_KITS: {
2
+ readonly eslint: import("../port.js").ProofKit<import("./eslint.js").EslintReading>;
3
+ readonly ruff: import("../port.js").ProofKit<import("./ruff.js").RuffReading>;
4
+ };
5
+ export type { EslintReading } from "./eslint.js";
6
+ export type { RuffReading } from "./ruff.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROOF_KITS = void 0;
4
+ /**
5
+ * The kit set: the ONLY place that lists the linters rule-proof supports. A new
6
+ * linter is a module beside this one and a line here; nothing generic changes
7
+ * (`local/no-kit-names` refuses a generic rule-proof file that spells a kit).
8
+ */
9
+ const eslint_js_1 = require("./eslint.js");
10
+ const ruff_js_1 = require("./ruff.js");
11
+ exports.PROOF_KITS = { eslint: eslint_js_1.eslintKit, ruff: ruff_js_1.ruffKit };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,28 @@
1
+ import type { ProofKit } from "../port.js";
2
+ import type { LintParse, ReadingScope } from "../types.js";
3
+ /** One Ruff configuration of one rule. */
4
+ export interface RuffReading {
5
+ readonly linter: "ruff";
6
+ /** The rule code: `E501`. */
7
+ readonly rule: string;
8
+ /** Ruff settings in the pinned version's own dialect, e.g. `{ "line-length": 100 }`. */
9
+ readonly settings: Readonly<Record<string, unknown>>;
10
+ readonly scope: ReadingScope;
11
+ }
12
+ /**
13
+ * The Ruff version a repository pins, from the files it would come from, most
14
+ * exact first: a lockfile, then `ruff==` in a requirements file or
15
+ * `pyproject.toml`, then the pre-commit hook's `rev`. A ranged requirement is no
16
+ * pin. Keys are file names at the repository root, values their text.
17
+ */
18
+ export declare function ruffPin(files: Readonly<Record<string, string>>): string | null;
19
+ /** A reading's settings as the TOML file `--config` reads. */
20
+ export declare function ruffConfigToml(settings: RuffReading["settings"]): string;
21
+ /**
22
+ * Ruff's `--output-format json` as per-file reports. Ruff lists diagnostics,
23
+ * not files, so the files passed in are the denominator: one with no
24
+ * diagnostic was linted and is clean.
25
+ */
26
+ export declare function parseRuffReport(stdout: string, dir: string, files: readonly string[], rule: string): LintParse;
27
+ export declare const ruffKit: ProofKit<RuffReading>;
28
+ //# sourceMappingURL=ruff.d.ts.map
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ruffKit = void 0;
4
+ exports.ruffPin = ruffPin;
5
+ exports.ruffConfigToml = ruffConfigToml;
6
+ exports.parseRuffReport = parseRuffReport;
7
+ /**
8
+ * The Ruff kit: the version the repository pins, run through `uvx`, the
9
+ * reading's settings as the TOML Ruff reads, and `--output-format json` read
10
+ * back as per-file reports.
11
+ */
12
+ const toml_1 = require("@iarna/toml");
13
+ const js_yaml_1 = require("js-yaml");
14
+ const node_path_1 = require("node:path");
15
+ const zod_1 = require("zod");
16
+ const report_js_1 = require("../report.js");
17
+ const lockSchema = zod_1.z.object({
18
+ package: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), version: zod_1.z.string() })),
19
+ });
20
+ function fromLock(text) {
21
+ try {
22
+ const lock = lockSchema.safeParse((0, toml_1.parse)(text));
23
+ return lock.success
24
+ ? (lock.data.package.find((p) => p.name === "ruff")?.version ?? null)
25
+ : null;
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
31
+ const EXACT = /^\s*ruff\s*==\s*([\w.]+)\s*$/m;
32
+ const exact = (text) => EXACT.exec(text)?.[1] ?? null;
33
+ /** Every string anywhere in a parsed document. */
34
+ function strings(value) {
35
+ if (typeof value === "string")
36
+ return [value];
37
+ if (typeof value !== "object" || value === null)
38
+ return [];
39
+ return Object.values(value).flatMap(strings);
40
+ }
41
+ function fromPyproject(text) {
42
+ try {
43
+ return (strings((0, toml_1.parse)(text))
44
+ .map(exact)
45
+ .find((v) => v !== null) ?? null);
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ }
51
+ const preCommitSchema = zod_1.z.object({
52
+ repos: zod_1.z.array(zod_1.z.object({ repo: zod_1.z.string(), rev: zod_1.z.string().optional() })),
53
+ });
54
+ function fromPreCommit(text) {
55
+ try {
56
+ const config = preCommitSchema.safeParse((0, js_yaml_1.load)(text));
57
+ const rev = config.success
58
+ ? config.data.repos.find((r) => r.repo.endsWith("/ruff-pre-commit"))?.rev
59
+ : undefined;
60
+ return rev === undefined ? null : rev.replace(/^v/, "");
61
+ }
62
+ catch {
63
+ return null;
64
+ }
65
+ }
66
+ const LOCKS = ["uv.lock", "poetry.lock", "pdm.lock"];
67
+ const REQUIREMENTS = /^requirements.*\.txt$/;
68
+ const PYPROJECT = "pyproject.toml";
69
+ const PRE_COMMIT = ".pre-commit-config.yaml";
70
+ /**
71
+ * The Ruff version a repository pins, from the files it would come from, most
72
+ * exact first: a lockfile, then `ruff==` in a requirements file or
73
+ * `pyproject.toml`, then the pre-commit hook's `rev`. A ranged requirement is no
74
+ * pin. Keys are file names at the repository root, values their text.
75
+ */
76
+ function ruffPin(files) {
77
+ const named = (keep) => Object.entries(files)
78
+ .filter(([name]) => keep(name))
79
+ .map(([, text]) => text);
80
+ const candidates = [
81
+ ...LOCKS.flatMap((lock) => named((n) => n === lock)).map((t) => () => fromLock(t)),
82
+ ...named((n) => REQUIREMENTS.test(n)).map((t) => () => exact(t)),
83
+ ...named((n) => n === PYPROJECT).map((t) => () => fromPyproject(t)),
84
+ ...named((n) => n === PRE_COMMIT).map((t) => () => fromPreCommit(t)),
85
+ ];
86
+ return candidates.reduce((found, next) => found ?? next(), null);
87
+ }
88
+ const isPinFile = (name) => LOCKS.some((lock) => lock === name) ||
89
+ REQUIREMENTS.test(name) ||
90
+ name === PYPROJECT ||
91
+ name === PRE_COMMIT;
92
+ const settingsSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any());
93
+ /** A reading's settings as the TOML file `--config` reads. */
94
+ function ruffConfigToml(settings) {
95
+ return (0, toml_1.stringify)(settingsSchema.parse(settings));
96
+ }
97
+ const reportSchema = zod_1.z.array(zod_1.z.object({
98
+ code: zod_1.z.string().nullable(),
99
+ filename: zod_1.z.string(),
100
+ message: zod_1.z.string(),
101
+ }));
102
+ /** How each Ruff version spells "this file did not parse". */
103
+ const PARSE_CODES = new Set([
104
+ null,
105
+ "E999",
106
+ "invalid-syntax",
107
+ "syntax-error",
108
+ ]);
109
+ /**
110
+ * Ruff's `--output-format json` as per-file reports. Ruff lists diagnostics,
111
+ * not files, so the files passed in are the denominator: one with no
112
+ * diagnostic was linted and is clean.
113
+ */
114
+ function parseRuffReport(stdout, dir, files, rule) {
115
+ const parsed = reportSchema.safeParse((0, report_js_1.jsonArray)(stdout));
116
+ if (!parsed.success)
117
+ return (0, report_js_1.unreadable)(stdout);
118
+ const diags = parsed.data.map((d) => ({
119
+ ...d,
120
+ path: (0, report_js_1.toRelative)(dir, d.filename),
121
+ }));
122
+ return {
123
+ kind: "parsed",
124
+ files: files.map((path) => {
125
+ const own = diags.filter((d) => d.path === path);
126
+ const broken = own.find((d) => PARSE_CODES.has(d.code));
127
+ if (broken !== undefined)
128
+ return { path, kind: "parse-error", message: broken.message };
129
+ return {
130
+ path,
131
+ kind: "linted",
132
+ hits: own.filter((d) => d.code === rule).length,
133
+ };
134
+ }),
135
+ };
136
+ }
137
+ exports.ruffKit = {
138
+ linter: "ruff",
139
+ plan(root) {
140
+ const pins = root.names.filter(isPinFile);
141
+ const version = ruffPin(Object.fromEntries(pins.map((n) => [n, root.read(n) ?? ""])));
142
+ if (version === null)
143
+ return {
144
+ kind: "none",
145
+ stage: "no-pin",
146
+ reason: "no exact Ruff pin in a lockfile, requirements, pyproject.toml or pre-commit",
147
+ };
148
+ const tool = `ruff@${version}`;
149
+ return {
150
+ kind: "plan",
151
+ install: ["uvx", tool, "--version"],
152
+ command: () => ["uvx", tool],
153
+ version: () => version,
154
+ missing: "",
155
+ };
156
+ },
157
+ env: (cacheDir) => ({ UV_CACHE_DIR: node_path_1.posix.join(cacheDir, "uv") }),
158
+ // The config sits in the repository, so a relative `extend` in the settings
159
+ // resolves against the repository as it would in the repository's own file.
160
+ invocation: (reading, files, { dir }) => {
161
+ const configPath = (0, node_path_1.join)(dir, ".vigiles-rule-proof.ruff.toml");
162
+ return {
163
+ configPath,
164
+ configText: ruffConfigToml(reading.settings),
165
+ args: [
166
+ ...["check", "--no-cache", "--output-format", "json", "--exit-zero"],
167
+ // A reading's own settings may not change WHAT is measured: with
168
+ // `force-exclude` an excluded twin vanishes from the report and would
169
+ // read clean, and with `fix` the planted violation is rewritten away.
170
+ ...["--no-force-exclude", "--no-fix"],
171
+ ...["--select", reading.rule, "--config", configPath, ...files],
172
+ ],
173
+ };
174
+ },
175
+ reportCodes: [0],
176
+ parse: (stdout, files, reading, dir) => parseRuffReport(stdout, dir, files, reading.rule),
177
+ };
178
+ //# sourceMappingURL=ruff.js.map
@@ -0,0 +1,32 @@
1
+ /** What a repository says about its Node package manager. */
2
+ export interface NodeInstallFacts {
3
+ /** Entry names at the repository root (lockfiles among them). */
4
+ readonly lockfiles: readonly string[];
5
+ /** The `packageManager` field of the root `package.json`, if any. */
6
+ readonly packageManager?: string;
7
+ }
8
+ /** The install command, or why there is none. */
9
+ export type NodeInstallPlan = {
10
+ readonly kind: "plan";
11
+ readonly install: readonly [string, ...string[]];
12
+ } | {
13
+ readonly kind: "none";
14
+ readonly reason: string;
15
+ };
16
+ /**
17
+ * The install for a Node repository. No lockfile is no plan: an install without
18
+ * one would not reproduce the repository's linter version, which is the point
19
+ * of installing at all.
20
+ */
21
+ export declare function nodeInstallPlan(facts: NodeInstallFacts): NodeInstallPlan;
22
+ /** The `packageManager` field of a `package.json` text, if it has one. */
23
+ export declare function packageManagerIn(text: string | null): string | undefined;
24
+ /** The `version` of a package's `package.json` text, or null. */
25
+ export declare function versionIn(text: string | null): string | null;
26
+ /**
27
+ * Every Node package manager's cache under `cacheDir`: one hand-written copy of
28
+ * this filled the root disk with a 6.8 GB yarn cache, and Yarn Berry and bun
29
+ * ignore `npm_config_cache`.
30
+ */
31
+ export declare function nodeCacheEnv(cacheDir: string): Readonly<Record<string, string>>;
32
+ //# sourceMappingURL=node-install.d.ts.map
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeInstallPlan = nodeInstallPlan;
4
+ exports.packageManagerIn = packageManagerIn;
5
+ exports.versionIn = versionIn;
6
+ exports.nodeCacheEnv = nodeCacheEnv;
7
+ /**
8
+ * How a Node repository installs its pinned dependencies: the lockfile says
9
+ * which tool, `packageManager` decides between two and pins the tool's version.
10
+ * Shared by every kit whose linter ships through npm.
11
+ */
12
+ const node_path_1 = require("node:path");
13
+ const zod_1 = require("zod");
14
+ const LOCKFILE_TOOL = {
15
+ "package-lock.json": "npm",
16
+ "npm-shrinkwrap.json": "npm",
17
+ "pnpm-lock.yaml": "pnpm",
18
+ "yarn.lock": "yarn",
19
+ "bun.lock": "bun",
20
+ "bun.lockb": "bun",
21
+ };
22
+ const NO_SCRIPTS = "--ignore-scripts";
23
+ const FROZEN = "--frozen-lockfile";
24
+ /** The install arguments per tool; `as` is the tool spelled with its pin. */
25
+ const INSTALL_ARGS = {
26
+ npm: () => ["ci", NO_SCRIPTS, "--no-audit", "--no-fund"],
27
+ pnpm: (as) => [as, "install", FROZEN, NO_SCRIPTS],
28
+ yarn: (as, berry) => berry
29
+ ? [as, "install", "--immutable", "--mode=skip-build"]
30
+ : [as, "install", FROZEN, NO_SCRIPTS, "--non-interactive"],
31
+ bun: (as) => ["--yes", as, "install", FROZEN, NO_SCRIPTS],
32
+ };
33
+ const INSTALL_COMMAND = {
34
+ npm: "npm",
35
+ pnpm: "corepack",
36
+ yarn: "corepack",
37
+ bun: "npx",
38
+ };
39
+ /** Yarn 1 when unpinned: corepack would otherwise pick the newest (Berry). */
40
+ const UNPINNED = {
41
+ npm: "npm",
42
+ pnpm: "pnpm",
43
+ yarn: "yarn@1",
44
+ bun: "bun",
45
+ };
46
+ function planFor(tool, version) {
47
+ const as = version === undefined ? UNPINNED[tool] : `${tool}@${version}`;
48
+ const berry = version !== undefined && !version.startsWith("1.");
49
+ return {
50
+ kind: "plan",
51
+ install: [INSTALL_COMMAND[tool], ...INSTALL_ARGS[tool](as, berry)],
52
+ };
53
+ }
54
+ /**
55
+ * The install for a Node repository. No lockfile is no plan: an install without
56
+ * one would not reproduce the repository's linter version, which is the point
57
+ * of installing at all.
58
+ */
59
+ function nodeInstallPlan(facts) {
60
+ const tools = facts.lockfiles.flatMap((f) => {
61
+ const tool = LOCKFILE_TOOL[f];
62
+ return tool === undefined ? [] : [tool];
63
+ });
64
+ const pm = /^([^@]+)@([^+]+)/.exec(facts.packageManager ?? "");
65
+ const declared = tools.find((t) => t === pm?.[1]);
66
+ const tool = declared ?? tools[0];
67
+ if (tool === undefined)
68
+ return {
69
+ kind: "none",
70
+ reason: "no lockfile: the linter version would not be the repository's",
71
+ };
72
+ return planFor(tool, declared === undefined ? undefined : pm?.[2]);
73
+ }
74
+ const packageJsonSchema = zod_1.z.object({ packageManager: zod_1.z.string().optional() });
75
+ /** The `packageManager` field of a `package.json` text, if it has one. */
76
+ function packageManagerIn(text) {
77
+ try {
78
+ const parsed = packageJsonSchema.safeParse(JSON.parse(text ?? "{}"));
79
+ return parsed.success ? parsed.data.packageManager : undefined;
80
+ }
81
+ catch {
82
+ return undefined;
83
+ }
84
+ }
85
+ const versionSchema = zod_1.z.object({ version: zod_1.z.string() });
86
+ /** The `version` of a package's `package.json` text, or null. */
87
+ function versionIn(text) {
88
+ try {
89
+ const parsed = versionSchema.safeParse(JSON.parse(text ?? "null"));
90
+ return parsed.success ? parsed.data.version : null;
91
+ }
92
+ catch {
93
+ return null;
94
+ }
95
+ }
96
+ /**
97
+ * Every Node package manager's cache under `cacheDir`: one hand-written copy of
98
+ * this filled the root disk with a 6.8 GB yarn cache, and Yarn Berry and bun
99
+ * ignore `npm_config_cache`.
100
+ */
101
+ function nodeCacheEnv(cacheDir) {
102
+ const at = (name) => node_path_1.posix.join(cacheDir, name);
103
+ return {
104
+ npm_config_cache: at("npm"),
105
+ npm_config_store_dir: at("pnpm"),
106
+ YARN_CACHE_FOLDER: at("yarn"),
107
+ YARN_GLOBAL_FOLDER: at("yarn-global"),
108
+ COREPACK_HOME: at("corepack"),
109
+ COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
110
+ BUN_INSTALL_CACHE_DIR: at("bun"),
111
+ // Yarn Berry's default Plug'n'Play leaves no node_modules, so the linter
112
+ // and its version could not be found where every other tool puts them.
113
+ // The lockfile, not the linker, pins the versions.
114
+ YARN_NODE_LINKER: "node-modules",
115
+ };
116
+ }
117
+ //# sourceMappingURL=node-install.js.map
@@ -0,0 +1,11 @@
1
+ import type { FileReport, Flagged, PairVerdict, ReadingScope } from "./types.js";
2
+ /**
3
+ * Is `path` (relative, `/`-separated) in the scope? Dot files match, as they do
4
+ * in a linter's own `files` patterns.
5
+ */
6
+ export declare function inScope(path: string, scope: ReadingScope): boolean;
7
+ /** Proved only when the bad file is flagged AND its twin is not. */
8
+ export declare function judgePair(bad: FileReport, good: FileReport): PairVerdict;
9
+ /** Split per-file reports into the three lists, each sorted. */
10
+ export declare function summarize(files: readonly FileReport[]): Flagged;
11
+ //# sourceMappingURL=pair.d.ts.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inScope = inScope;
4
+ exports.judgePair = judgePair;
5
+ exports.summarize = summarize;
6
+ /**
7
+ * What every linter's proof shares: the scope test, the verdict on a planted
8
+ * pair, and the split of per-file reports into the lists a run returns.
9
+ */
10
+ const minimatch_1 = require("minimatch");
11
+ const MATCH = { dot: true };
12
+ /**
13
+ * Is `path` (relative, `/`-separated) in the scope? Dot files match, as they do
14
+ * in a linter's own `files` patterns.
15
+ */
16
+ function inScope(path, scope) {
17
+ const matches = (p) => (0, minimatch_1.minimatch)(path, p, MATCH);
18
+ return scope.files.some(matches) && !scope.ignores.some(matches);
19
+ }
20
+ /** A planted file's hits, or why it gives no verdict. */
21
+ function hitsOf(file) {
22
+ if (file.kind === "parse-error")
23
+ return {
24
+ kind: "not-run",
25
+ stage: "parse",
26
+ reason: `${file.path}: ${file.message}`,
27
+ };
28
+ if (file.kind === "ignored")
29
+ return {
30
+ kind: "not-run",
31
+ stage: "pair-ignored",
32
+ reason: `${file.path}: the linter ignored the planted file`,
33
+ };
34
+ return file.hits;
35
+ }
36
+ /** Proved only when the bad file is flagged AND its twin is not. */
37
+ function judgePair(bad, good) {
38
+ const badHits = hitsOf(bad);
39
+ if (typeof badHits !== "number")
40
+ return badHits;
41
+ const goodHits = hitsOf(good);
42
+ if (typeof goodHits !== "number")
43
+ return goodHits;
44
+ return badHits > 0 && goodHits === 0
45
+ ? { kind: "proved" }
46
+ : { kind: "not-proved", badHits, goodHits };
47
+ }
48
+ /** Split per-file reports into the three lists, each sorted. */
49
+ function summarize(files) {
50
+ const paths = (keep) => files
51
+ .filter(keep)
52
+ .map((f) => f.path)
53
+ .sort((a, b) => a.localeCompare(b));
54
+ return {
55
+ linted: files.filter((f) => f.kind === "linted").length,
56
+ flagged: paths((f) => f.kind === "linted" && f.hits > 0),
57
+ parseErrors: paths((f) => f.kind === "parse-error"),
58
+ ignored: paths((f) => f.kind === "ignored"),
59
+ };
60
+ }
61
+ //# sourceMappingURL=pair.js.map
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The two ports of `experimental_ruleProof`.
3
+ *
4
+ * {@link RuleProofHost} is every effect the steps need from the machine; the
5
+ * host adapter (`src/host/rule-proof.io.ts`) implements it. {@link ProofKit} is
6
+ * everything the steps need to know about ONE linter; each kit is a module in
7
+ * `./kits/`, and the set is assembled there and handed in by the entry root. The
8
+ * steps (`./run.ts`) know neither a machine nor a linter by name.
9
+ */
10
+ import type { BaseReading, ExecOptions, ExecResult, LintParse } from "./types.js";
11
+ /** Every effect rule-proof needs. Paths are absolute unless a member says otherwise. */
12
+ export interface RuleProofHost {
13
+ readonly exec: (command: string, args: readonly string[], options: ExecOptions) => ExecResult;
14
+ /** A file's text, or null when it is absent or unreadable. */
15
+ readonly read: (path: string) => string | null;
16
+ readonly exists: (path: string) => boolean;
17
+ /** Entry names directly in `dir`. */
18
+ readonly list: (dir: string) => readonly string[];
19
+ /** Write a file, making its parent directories. */
20
+ readonly write: (path: string, text: string) => void;
21
+ /** Remove a file or a directory tree; absent is fine. */
22
+ readonly remove: (path: string) => void;
23
+ /**
24
+ * Files under `dir` matching `patterns`: relative, `/`-separated, never
25
+ * inside node_modules or .git.
26
+ */
27
+ readonly files: (dir: string, patterns: readonly string[]) => readonly string[];
28
+ }
29
+ /** What a kit may look at in a repository's root before installing. */
30
+ export interface RootView {
31
+ /** Entry names at the root. */
32
+ readonly names: readonly string[];
33
+ /** A root file's text by name, or null. */
34
+ readonly read: (name: string) => string | null;
35
+ }
36
+ /** How to install a linter at the repository's pinned version, or why that is impossible. */
37
+ export type KitPlan = {
38
+ readonly kind: "plan";
39
+ /** The install command and its arguments, run in the repository. */
40
+ readonly install: readonly [string, ...string[]];
41
+ /** The argv prefix that runs the linter once installed. */
42
+ readonly command: (dir: string) => readonly string[];
43
+ /** The installed version, given a reader of repository-relative files; null when absent. */
44
+ readonly version: (read: (path: string) => string | null) => string | null;
45
+ /** What to say when `version` finds nothing after the install. */
46
+ readonly missing: string;
47
+ } | {
48
+ readonly kind: "none";
49
+ readonly stage: "no-lockfile" | "no-pin";
50
+ readonly reason: string;
51
+ };
52
+ /** One lint call: the config file to write, and the arguments after the command. */
53
+ export interface Invocation {
54
+ readonly configPath: string;
55
+ readonly configText: string;
56
+ readonly args: readonly string[];
57
+ }
58
+ /** Where a lint call runs and where its scratch files go. */
59
+ export interface Places {
60
+ readonly dir: string;
61
+ readonly cacheDir: string;
62
+ }
63
+ /**
64
+ * Everything the steps need to know about one linter. Methods, not function
65
+ * properties: a kit of a narrower reading is still a kit.
66
+ */
67
+ export interface ProofKit<R extends BaseReading> {
68
+ readonly linter: R["linter"];
69
+ plan(root: RootView): KitPlan;
70
+ /** Environment that keeps this linter's tools' caches under `cacheDir`. */
71
+ env(cacheDir: string): Readonly<Record<string, string>>;
72
+ invocation(reading: R, files: readonly string[], places: Places): Invocation;
73
+ /** Exit codes after which stdout holds a report. Any other is `config-load`. */
74
+ readonly reportCodes: readonly number[];
75
+ parse(stdout: string, files: readonly string[], reading: R, dir: string): LintParse;
76
+ }
77
+ //# sourceMappingURL=port.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=port.js.map
@@ -0,0 +1,11 @@
1
+ import type { LintParse } from "./types.js";
2
+ /** `file` relative to `dir`, `/`-separated. */
3
+ export declare const toRelative: (dir: string, file: string) => string;
4
+ /**
5
+ * The JSON array in a linter's stdout. A plugin may print banner lines first,
6
+ * so the array starts at the first line that opens one.
7
+ */
8
+ export declare function jsonArray(stdout: string): unknown;
9
+ /** Output that is not the report: never an empty list. */
10
+ export declare const unreadable: (stdout: string) => LintParse;
11
+ //# sourceMappingURL=report.d.ts.map