paperlint 19.0.2 → 19.0.3

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 (88) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CLAUDE.md +2 -2
  3. package/dist/CLAUDE.md.spec.d.ts.map +1 -1
  4. package/dist/CLAUDE.md.spec.js +7 -1
  5. package/dist/CLAUDE.md.spec.js.map +1 -1
  6. package/dist/cli.d.ts +2 -21
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +45 -93
  9. package/dist/cli.js.map +1 -1
  10. package/dist/doctor.d.ts +8 -10
  11. package/dist/doctor.d.ts.map +1 -1
  12. package/dist/doctor.js +27 -37
  13. package/dist/doctor.js.map +1 -1
  14. package/dist/hooks-notice.d.ts +8 -2
  15. package/dist/hooks-notice.d.ts.map +1 -1
  16. package/dist/hooks-notice.js +15 -20
  17. package/dist/hooks-notice.js.map +1 -1
  18. package/dist/hooks-settings.d.ts +1 -1
  19. package/dist/hooks-settings.js +1 -1
  20. package/dist/init.d.ts +1 -1
  21. package/dist/init.js +5 -5
  22. package/dist/lib/paper-config.d.ts +4 -9
  23. package/dist/lib/paper-config.d.ts.map +1 -1
  24. package/dist/lib/paper-config.js +4 -9
  25. package/dist/lib/paper-config.js.map +1 -1
  26. package/dist/papers-roots.d.ts +19 -0
  27. package/dist/papers-roots.d.ts.map +1 -0
  28. package/dist/papers-roots.js +42 -0
  29. package/dist/papers-roots.js.map +1 -0
  30. package/dist/retired-hooks.d.ts +6 -0
  31. package/dist/retired-hooks.d.ts.map +1 -0
  32. package/dist/retired-hooks.js +34 -0
  33. package/dist/retired-hooks.js.map +1 -0
  34. package/dist/skill-chunks/chunk-C2G5EK7S.js +579 -0
  35. package/dist/skill-chunks/{chunk-UL4INX2P.js → chunk-L3NJUJUP.js} +446 -446
  36. package/dist/skill-chunks/{chunk-EOVEVX67.js → chunk-X4VKG4KT.js} +1 -1
  37. package/dist/types.d.ts +1 -1
  38. package/docs/install.md +9 -11
  39. package/docs/layout.md +2 -4
  40. package/docs/rules/paper/allowed-files-only.md +1 -2
  41. package/docs/testing.md +1 -1
  42. package/eslint.config.mjs +1 -1
  43. package/lib/paper-config.harness.mjs +3 -6
  44. package/lib/paper-config.ts +4 -9
  45. package/package.json +2 -3
  46. package/plugin/hooks/hooks.json +0 -13
  47. package/scripts/coverage-config.test.ts +0 -1
  48. package/scripts/eslint-file-length.mjs +0 -1
  49. package/skills/argument-arc/scripts/headings.js +2 -2
  50. package/skills/build-label-page/scripts/label-page.js +125 -125
  51. package/skills/cold-read-diff/scripts/cold-read.js +11 -11
  52. package/skills/paper-pipeline/scripts/extract-ref-facts.js +3 -3
  53. package/skills/paper-status/SKILL.md +1 -2
  54. package/skills/paper-status/SKILL.md.spec.ts +0 -1
  55. package/skills/pc-panel-review/scripts/prior-reviews.js +1 -1
  56. package/skills/verify-citations/scripts/bib-authors.js +3 -3
  57. package/skills/verify-citations/scripts/verify-cites.js +3 -3
  58. package/src/CLAUDE.md +16 -1
  59. package/src/CLAUDE.md.spec.ts +12 -1
  60. package/src/cli.harness.mjs +14 -79
  61. package/src/cli.test.ts +4 -34
  62. package/src/cli.ts +47 -140
  63. package/src/doctor.harness.mjs +17 -59
  64. package/src/doctor.test.ts +1 -1
  65. package/src/doctor.ts +26 -41
  66. package/src/domain/paper-folder.test.ts +1 -1
  67. package/src/hooks-notice.test.ts +21 -74
  68. package/src/hooks-notice.ts +30 -20
  69. package/src/hooks-settings.harness.ts +25 -27
  70. package/src/hooks-settings.ts +1 -1
  71. package/src/in-process-hooks.test.ts +18 -0
  72. package/src/init.ts +5 -5
  73. package/src/lint-edited-site-example.test.ts +0 -3
  74. package/src/papers-roots.test.ts +56 -0
  75. package/src/papers-roots.ts +56 -0
  76. package/src/retired-hooks.test.ts +155 -0
  77. package/src/retired-hooks.ts +41 -0
  78. package/src/types.ts +1 -1
  79. package/dist/skill-chunks/chunk-GRSXIWYF.js +0 -352
  80. package/hooks/CLAUDE.md +0 -34
  81. package/hooks/CLAUDE.md.spec.ts +0 -30
  82. package/hooks/hooks.harness.ts +0 -566
  83. package/hooks/paper-edit-guard.hook.d.mts +0 -12
  84. package/hooks/paper-edit-guard.hook.mjs +0 -443
  85. package/hooks/paper-edit-guard.test.ts +0 -66
  86. package/hooks/paper-skills-nudge.hook.d.mts +0 -22
  87. package/hooks/paper-skills-nudge.hook.mjs +0 -193
  88. package/hooks/paper-skills-nudge.test.ts +0 -122
@@ -1,443 +0,0 @@
1
- /**
2
- * paper-edit-guard — a PreToolUse gate: a paper SOURCE must not be written from Bash, because a
3
- * Bash write skips every PostToolUse check that hangs on Edit/Write (readability thresholds, the
4
- * pipeline nudge, the unrun-gate surface).
5
- *
6
- * ── WHY THIS SHIPS AS `.mjs` AND NOT AS A `.hook.ts` SPEC ───────────────────
7
- * 🔴 MEASURED, both halves, four locations (2026-09-11). The same hook, byte for byte, placed
8
- * inside an installed package:
9
- *
10
- * <pkg>/hooks/probe.hook.mjs deny-input RC=2 + reason allow-input RC=0, silent ✅
11
- * <pkg>/hooks/probe.hook.ts deny-input RC=2 "cannot be loaded"
12
- * allow-input RC=2 "cannot be loaded" 🔴 DEAD
13
- *
14
- * A `.ts` reached through `node_modules` does not load, and a PreToolUse hook that does not load
15
- * refuses EVERY Bash command — including the one that would fix it. So the shipped artifact is
16
- * `.mjs`. The CLI transpiles TypeScript hooks with its own host; why that host does not serve a
17
- * path inside `node_modules` was not established, and does not need to be for this decision.
18
- *
19
- * ── WHY NOT A THIN SPEC IN THE CONSUMER THAT IMPORTS THIS LOGIC ─────────────
20
- * 🔴 ALSO MEASURED (2026-09-12), and it is the form that looks obviously right and is not. A
21
- * consumer-side `.hook.ts` that pulls this logic in from the installed package:
22
- *
23
- * runtime deny-input RC=2, allow-input RC=0 ✅ it runs
24
- * `vigiles compile` RC=1 — "hook program uses capabilities outside `vigiles/hook`" 🔴
25
- *
26
- * `checkHookImports` allows exactly one specifier, and that is not a bug to route around: the
27
- * import list IS the capability surface. The consequence is what kills the form: compile is also
28
- * what writes the tamper-evident stamp, so a hook it refuses can never be re-stamped, and the
29
- * runtime FAILS CLOSED on a stamp that no longer matches its source —
30
- *
31
- * vigiles: hook … does not match its compiled stamp (tampered).
32
- * … the way out is a FILE WRITE, not a command — this refusal blocks the recompile too.
33
- *
34
- * — i.e. editing that thin file wedges the repository, and the only steady state is running
35
- * permanently unstamped. Shipping the whole program instead keeps the stamp question from
36
- * arising (no sidecar ⇒ no check) and pins the source by lockfile integrity instead, which is
37
- * stronger than a local stamp: the consumer cannot hand-edit an installed tree without the next
38
- * install reverting it.
39
- *
40
- * The capability surface is therefore asserted HERE, on the artifact that actually executes:
41
- * `hooks.harness.ts` runs `checkHookImports` over every shipped `.hook.mjs`. That is a stricter
42
- * check than compiling a twin `.ts` source would be, because a twin can drift from its build and
43
- * this cannot — there is only one file.
44
- *
45
- * ── WHERE THE CONSUMER'S PAPERS ARE ─────────────────────────────────────────
46
- * One declaration, `{ "papersDir": "…" }` in the root `paperlint.json` (optional; default
47
- * `papers`), read the way a hook is able to read anything at all: a `provide` that cats the file.
48
- * The alternatives were measured and killed in `eslint-rules/papers.mjs` — an env var cannot be
49
- * read from a hook at all (no imports), and a symlinked root makes ESLint report zero files.
50
- *
51
- * 🔴 THE PATH IS ANCHORED, AND THAT IS NOT DECORATION. vigiles runs a provider "via execSync in
52
- * the hook's cwd", so a bare `cat paperlint.json` resolves against whatever directory the hook
53
- * PROCESS happens to have — which is set by the consumer's wiring, a string this hook cannot
54
- * see and does not control. With the wiring this package documents (`cd "$CLAUDE_PROJECT_DIR"
55
- * && node …`) the bare read is correct; without it, any tool cwd outside the project root makes
56
- * the read fail, and by the paragraph below that failure DENIES EVERY BASH COMMAND until
57
- * something external resets the cwd — `pwd` included, so the wedge cannot be escaped from the
58
- * shell. Reported 2026-09-16 by a session that hit exactly that after a `cd` into a subtree.
59
- *
60
- * ⚠️ The wiring is not hypothetical to lose: `vigiles compile` has REGENERATED it without the
61
- * `cd` prefix once already in this corpus. A gate whose blast radius is "all of Bash" must not
62
- * rest on a prefix a code generator can drop. `${CLAUDE_PROJECT_DIR:-.}` keeps the old behaviour
63
- * when the variable is absent, so this is strictly wider than what it replaces.
64
- *
65
- * 🔴 AN UNREADABLE DECLARATION DENIES, IT DOES NOT DEFAULT. Measured 2026-09-12: when the
66
- * provider's command fails — an unreadable file, or one with conflict markers in it — `e.ctx.config`
67
- * arrives as the EMPTY STRING (or text that is not JSON) and the runtime says nothing. A `try { JSON.parse } catch { use the
68
- * default }` therefore turns a broken declaration into a silently permissive gate: the prefix
69
- * quietly becomes `papers`, nothing under the real root matches, and every Bash write to a paper
70
- * is allowed by a gate that still looks installed and green. So parse failure is a `deny` that
71
- * names the cure.
72
- *
73
- * ⚠️ That deny does refuse every Bash command while the declaration is broken, which is a known
74
- * and accepted cost rather than an oversight: the recovery is a FILE WRITE (Edit/Write bypass
75
- * PreToolUse entirely), and the message below says so. A gate that fails open here would be
76
- * indistinguishable from a gate that is working.
77
- *
78
- * ── HONEST SCOPE — three holes, left open on purpose ────────────────────────
79
- * 1. INTERPRETER INDIRECTION. The gate reads the Bash command's AST; a path that never appears
80
- * in the command is invisible. A heredoc that writes a script naming the paper, then running
81
- * it, passes. Closing it means deciding what an arbitrary program will write, which is
82
- * undecidable, and every cheap approximation (deny `python3` with a file argument, scan
83
- * heredoc bodies) buys a little coverage for a lot of false denials. A guard that denies
84
- * legitimate commands gets muted, and a muted guard is worth less than none.
85
- * 2. A WRAPPER THAT CHANGES DIRECTORY. Measured: `sed -i s/a/b/ <root>/x/paper.tex` → blocked;
86
- * `env -C <root-parent> sed -i s/a/b/ …` → allowed. Both scans compare against a prefix
87
- * starting at the repository root and neither knows the command's working directory. Closing
88
- * it means a cwd model that `cd`, `env -C`, `pushd`, `git -C` and a subshell can each move —
89
- * that belongs in the vocabulary upstream, not in a guard reimplementing shell semantics.
90
- * 3. DELIVERY, from the product's own docs: a PreToolUse hook does not fire for a subagent's
91
- * tool calls. So this is a strong default, never an unbypassable wall — and hole 3 is wider
92
- * than 1 and 2 together, which is why patching them from inside the hook is not worth it.
93
- *
94
- * This gate is a SPEED BUMP against the idiom people reach for. The boundary is the convention
95
- * in the consumer's own instructions, and that is held by prose on purpose.
96
- */
97
- // 🔴 `tools`, PLURAL. The singular alias existed before vigiles 27.x and was REMOVED from
98
- // `vigiles/hook` in it. The failure is not local: a missing import means the hook does not load,
99
- // and a PreToolUse hook that does not load refuses EVERY Bash command — including the one that
100
- // would fix it. Observed in the first consumer on 2026-09-10 after a 25.1.0 → 27.1.4 bump; the
101
- // repository had to be recovered with a file write. Pin this package's vigiles to the consumer's.
102
- import {
103
- experimental_defineHook,
104
- tools,
105
- provide,
106
- allow,
107
- deny,
108
- } from "vigiles/hook";
109
-
110
- /** The tool's name — the package this hook resolves its scripts through. */
111
- export const CONFIG_KEY = "paperlint";
112
- /** The settings file at the project root. Optional: absent means every default. */
113
- export const CONFIG_FILE = "paperlint.json";
114
- /** The default. A consumer that declares nothing is assumed to keep papers in `papers/`. */
115
- export const DEFAULT_PAPERS_ROOT = "papers";
116
- /**
117
- * The field of the root `paperlint.json` that names the papers directory. These are copies of the
118
- * constants in `lib/paper-config.mjs` (a hook may import nothing but `vigiles/hook`);
119
- * `lib/paper-config.harness.mjs` checks that the copies match.
120
- */
121
- export const PAPERS_DIR_FIELD = "papersDir";
122
-
123
- /**
124
- * The provider: the root `paperlint.json`, or `{}` when the project has none — so an ABSENT file
125
- * (every default) and an UNREADABLE one (the empty string the runtime gives a failed provider)
126
- * stay two different inputs.
127
- *
128
- * 🔴 THE PATH IS ANCHORED TO THE PROJECT ROOT. vigiles runs a provider "via execSync in the hook's
129
- * cwd", which is the consumer's wiring — a string this hook cannot see. A bare relative path reads
130
- * from whatever directory the Bash tool last moved to.
131
- */
132
- const READ_CONFIG = `f="\${CLAUDE_PROJECT_DIR:-.}/${CONFIG_FILE}"; if [ -e "$f" ]; then cat "$f"; else echo '{}'; fi`;
133
-
134
- /**
135
- * The declared papers root, or a `deny` explaining why there is not one.
136
- *
137
- * Returns a string on success and a `Decision` on failure, so the caller cannot accidentally
138
- * continue with a bad root: there is no value to continue WITH.
139
- *
140
- * 🔴 `declared === undefined`, NOT `declared ?? DEFAULT` — the two differ on exactly one input,
141
- * `"papersDir": null`, and that difference is the point: `??` reads an explicit `null` as "nothing
142
- * was declared" and silently substitutes the default, i.e. treats a typed keystroke as an
143
- * absence. The same distinction is made by every other carrier in this package.
144
- */
145
- /**
146
- * EXPORTED ON PURPOSE — this is the only way to cross-check without a second copy of the logic.
147
- * `paperlint doctor` has to say which directory THIS hook will guard, not what a retelling of it
148
- * would guard. The compiled hook is forbidden to IMPORT anything but `vigiles/hook`
149
- * (that's what `checkHookImports` enforces), so a shared module is impossible — but that ban
150
- * doesn't restrict exporting outward, and the reverse direction, CLI → hook, is free.
151
- * Returns the root string, or a rejection object: the caller tells them apart by `typeof`.
152
- */
153
- export const papersRoot = (rawConfig) => {
154
- let config;
155
- try {
156
- config = JSON.parse(rawConfig);
157
- } catch {
158
- return deny(
159
- `${CONFIG_KEY}: this gate could not read the project's ${CONFIG_FILE}, so it does not know ` +
160
- `where papers live and is refusing rather than guessing.\n` +
161
- `The declaration it needs is:\n` +
162
- ` { "${PAPERS_DIR_FIELD}": "path/to/papers" }\n` +
163
- `(no file at all is fine too — the default is "${DEFAULT_PAPERS_ROOT}").\n` +
164
- `If ${CONFIG_FILE} is mid-merge or otherwise broken, fix it with Edit or Write: file ` +
165
- `tools do not pass through this gate, so that path out is always open.\n` +
166
- `This refuses rather than falling back on purpose. A gate whose prefix quietly became ` +
167
- `the default would allow every Bash write to the real papers root while still looking ` +
168
- `installed and green.`,
169
- );
170
- }
171
- const declared = config?.[PAPERS_DIR_FIELD];
172
- const root = declared === undefined ? DEFAULT_PAPERS_ROOT : declared;
173
- if (typeof root !== "string" || root.length === 0)
174
- return deny(
175
- `${CONFIG_KEY}: "${PAPERS_DIR_FIELD}" must be a non-empty string, got ${JSON.stringify(root)}.\n` +
176
- `Fix it in the project's ${CONFIG_FILE}. This gate refuses while the value is unusable: ` +
177
- `an empty prefix matches nothing, so the gate would pass every paper write in silence.`,
178
- );
179
- // One trailing slash at most, whatever the consumer typed: `"papersDir": "docs/papers/"` reaches
180
- // here with its own, and `prefix + "/"` would become `docs/papers//`, which matches NOTHING.
181
- // That exact defect (a trailing slash in the guarded prefix) made an earlier version of this
182
- // guard a no-op while its comment claimed otherwise.
183
- return root.replace(/\/+$/, "");
184
- };
185
-
186
- /**
187
- * Redirection targets (`> f`, `>> f`, `1> f`, `&> f`), which `touches` cannot see.
188
- *
189
- * MEASURED, not assumed: `leafCommandsNormalized("echo x > p/x/paper.tex")` returns
190
- * `[{head:"echo", argv:["echo","x"], args:["x"], …}]` — the redirection and its target are
191
- * DROPPED by the parser, so they appear in no field of any leaf. The closed vocabulary
192
- * (`runs` / `touches` / `pipesToShell` / `isSideEffecting`) has no way to ask what a command
193
- * WRITES. Filed upstream as a `writesTo(prefixes)` primitive; when that lands, this helper
194
- * deletes and the assertions stay.
195
- *
196
- * 🔴 THE SCAN IS QUOTE-AWARE, and the version before it was not. It stripped quoted spans
197
- * wholesale, so a quoted redirection target vanished with them. MEASURED on this guard:
198
- *
199
- * echo x > <root>/x/paper.tex → blocked
200
- * echo x > "<root>/x/paper.tex" → ALLOWED
201
- * echo x > '<root>/x/paper.tex' → ALLOWED
202
- *
203
- * Stripping was not merely careless: a `>` INSIDE quotes is not a redirection at all, so the
204
- * guard has to know about quoting or it fires on any command that merely QUOTES a paper write —
205
- * which it did, three times in a row, on the very commands testing it. Both facts are true at
206
- * once and a regex cannot hold them both: the operator must be found OUTSIDE quotes while the
207
- * target must be read THROUGH them. Hence a character scan that tracks quote state.
208
- */
209
- const redirectTargets = (raw) => {
210
- const src = raw.replace(/<<-?\s*'?(\w+)'?[\s\S]*?^\1$/gm, "<<HEREDOC");
211
- const out = [];
212
- let i = 0;
213
- let quote = null;
214
- while (i < src.length) {
215
- const c = src[i];
216
- if (quote) {
217
- if (c === "\\" && quote === '"') i += 1;
218
- else if (c === quote) quote = null;
219
- i += 1;
220
- continue;
221
- }
222
- if (c === "'" || c === '"') {
223
- quote = c;
224
- i += 1;
225
- continue;
226
- }
227
- if (c === "\\") {
228
- i += 2;
229
- continue;
230
- }
231
- if (c !== ">") {
232
- i += 1;
233
- continue;
234
- }
235
- i += 1;
236
- if (src[i] === ">") i += 1;
237
- while (i < src.length && (src[i] === " " || src[i] === "\t")) i += 1;
238
- // Read the target, unquoting as we go. `2>&1` and `2>/dev/null` fall out for free: `&` is a
239
- // delimiter, so the first yields an empty token, and the second simply names a path under no
240
- // guarded prefix.
241
- let tok = "";
242
- let tq = null;
243
- while (i < src.length) {
244
- const d = src[i];
245
- if (tq) {
246
- if (d === "\\" && tq === '"') {
247
- tok += src[i + 1] ?? "";
248
- i += 2;
249
- continue;
250
- }
251
- if (d === tq) {
252
- tq = null;
253
- i += 1;
254
- continue;
255
- }
256
- tok += d;
257
- i += 1;
258
- continue;
259
- }
260
- if (d === "'" || d === '"') {
261
- tq = d;
262
- i += 1;
263
- continue;
264
- }
265
- if (/[\s;|&()<>]/.test(d)) break;
266
- if (d === "\\") {
267
- tok += src[i + 1] ?? "";
268
- i += 2;
269
- continue;
270
- }
271
- tok += d;
272
- i += 1;
273
- }
274
- if (tok !== "") out.push(tok.replace(/^\.\//, ""));
275
- }
276
- return out;
277
- };
278
-
279
- /**
280
- * 🔴 UNQUOTES rather than DELETES — the argument scan used to strip quoted spans, and a quoted
281
- * path therefore vanished before it could be matched. MEASURED against this guard:
282
- *
283
- * sed -i s/a/b/ <root>/x/paper.tex → blocked
284
- * sed -i s/a/b/ "<root>/x/paper.tex" → ALLOWED
285
- *
286
- * Quoting a path is what anyone writes for a path with a space in it, so the gate was one quote
287
- * from open. Deleting quoted text was not wrong for its own job — it stopped the guard firing on
288
- * a command that merely QUOTES a paper write, which really happened — but that job now belongs
289
- * to `writesTo`, which answers "is this WRITTEN" instead of "is this mentioned". With the write
290
- * established there, the argument scan only has to say WHICH file, so it must see the path, not
291
- * lose it. Heredocs are still collapsed: their body is data, not argv.
292
- */
293
- const unquote = (s) =>
294
- s
295
- .replace(/<<-?\s*'?(\w+)'?[\s\S]*?^\1$/gm, "<<HEREDOC")
296
- .replace(/'([^']*)'/g, "$1")
297
- .replace(/"((?:[^"\\]|\\.)*)"/g, "$1");
298
-
299
- const redirectsInto = (raw, prefixes) =>
300
- redirectTargets(raw).some(
301
- (t) =>
302
- // ⚠️ This leg is WIDER than the argv leg: it claims any redirect target under the root,
303
- // whatever its extension, so the frozen-snapshot carve-out has to be repeated here. It
304
- // does not reach the argv leg's carve-outs either — noted, not widened, because loosening
305
- // a guard beyond the case at hand is how gates stop holding.
306
- !isFrozenSnapshot(t) &&
307
- prefixes.some(
308
- (p) => t === p || t.startsWith(p + "/") || t.includes("/" + p + "/"),
309
- ),
310
- );
311
-
312
- /**
313
- * Programs that WRITE a path given as an argument. The list is explicit because `touches`
314
- * answers "is this path MENTIONED", not "is it written".
315
- *
316
- * 🔴 An earlier version leaned on `isSideEffecting()` to tell a read from a write. That
317
- * classifies the WHOLE command line, so `grep -c '☐' <root>/x/STATUS.md 2>/dev/null` came back
318
- * side-effecting, touched a paper path, and was blocked — a plain read, refused. Coarse enough
319
- * to be useless as a discriminator, and it fired on real work twice within the hour.
320
- */
321
- const MUTATORS = [
322
- "sed -i",
323
- "cp",
324
- "mv",
325
- "tee",
326
- "dd",
327
- "truncate",
328
- "install",
329
- "shred",
330
- ];
331
-
332
- /**
333
- * Does the command RUN a mutator?
334
- *
335
- * 🔴 THE `runs()` CONJUNCT CANNOT BE DROPPED — it is what separates a write from a read. Without
336
- * it `cat <root>/x/paper.tex` touches a paper, names a paper source, and would be denied: a
337
- * plain read refused, which this guard has already done once and which cost real work.
338
- *
339
- * ⚠️ A RAW-TEXT CRUTCH USED TO SIT BESIDE IT, AND IT IS GONE BECAUSE ITS PREMISE EXPIRED. On
340
- * 2026-08-13, against vigiles 15.x, `runs()` read the RAW leaves while `writesTo`/`touches` read
341
- * the NORMALIZED ones, so the vocabulary contradicted itself on a wrapped command and
342
- * `env sed -i … <root>/x/paper.tex` was ALLOWED with a full, correct path. A second scan over the
343
- * unquoted raw text patched that, with a comment saying it "deletes on the day the vocabulary
344
- * stops disagreeing, not before".
345
- *
346
- * That day arrived. Re-measured on vigiles 27.1.4 (2026-09-12), and the old table is stale in
347
- * the row that motivated the crutch:
348
- *
349
- * command runs("sed -i") writesTo touches
350
- * sed -i … <root>/x/paper.tex true true true
351
- * env sed -i … <root>/x/paper.tex true ← was FALSE true true
352
- * env -C <parent> sed -i … <root>/… true ← was false true false
353
- * cd <parent> && sed -i … <root>/… true false false
354
- *
355
- * `runs()` now sees through `env`, `env -C`, `command`, `nice`, `xargs`, `sudo`, `time`, a
356
- * repeated space and a quoted head — every form tried. So the crutch defended nothing, which is
357
- * not a judgement but a measurement: removing it left all 78 harness assertions GREEN, and no
358
- * command form could be found that it alone catches. A line the harness can never fail on is a
359
- * line documenting a defence that does not exist, so it was deleted rather than kept for comfort.
360
- *
361
- * ⚠️ WHAT THIS DOES NOT FIX: rows 3 and 4 above. A wrapper that moves the working directory is
362
- * still invisible, because `touches`/`namesPaperSource` compare against a repo-root prefix and
363
- * neither knows the command's cwd — see hole 2 in the header. Only the `env`-without-`-C` row
364
- * closed.
365
- */
366
- const runsMutator = (cmd) => MUTATORS.some((m) => cmd.runs(m));
367
-
368
- /**
369
- * A PAPER SOURCE, not merely a path under the papers root.
370
- *
371
- * 🔴 An earlier version guarded the whole subtree, so copying a script into a paper's
372
- * reproduction bundle — ordinary work, touching no prose — was denied. The gate exists to stop a
373
- * paper's PROSE being edited past the PostToolUse checks; everything else under that directory
374
- * is data, code and bundles that no readability gate looks at. Observed while it was blocking
375
- * the artifact fix the pre-submission gate had just asked for.
376
- */
377
- const isPaperSource = (p) => !isFrozenSnapshot(p) && hasSourceExtension(p);
378
-
379
- const hasSourceExtension = (p) => p.endsWith(".tex");
380
-
381
- /**
382
- * A FROZEN SNAPSHOT — a file under a paper's `versions/`, which is the same carve-out as the
383
- * reproduction bundle above and was missed only because a snapshot keeps the `.tex` extension of
384
- * the live source it was copied from.
385
- *
386
- * 🔴 Why the gate must not claim it. Everything the guard protects is a PostToolUse check on the
387
- * paper being WRITTEN — readability thresholds, the pipeline nudge, the unrun-gate check. None of
388
- * them has anything to say about a snapshot: a frozen version is immutable by construction, it is
389
- * never the file an author edits, and `paper/stages` already gates it far more strictly than any
390
- * of those, by BYTES, in both directions.
391
- *
392
- * ⚠️ Observed: restoring `versions/2026-08-29-camera-ready.tex` from the one commit that still
393
- * resolved was denied, so the only recoverable source of four declared stages was unreachable by
394
- * the tool that could reach it. The guard was refusing the archival write while the live
395
- * `paper.tex` beside it — the file it actually exists to protect — stayed open.
396
- */
397
- const isFrozenSnapshot = (p) => /(^|\/)versions\/[^/]+$/.test(p);
398
-
399
- /** Paper-source paths named as arguments (as opposed to redirection targets). */
400
- const namesPaperSource = (raw, prefixes) =>
401
- unquote(raw)
402
- .split(/[\s;|&()<>]+/)
403
- .some(
404
- (tok) =>
405
- isPaperSource(tok) &&
406
- prefixes.some(
407
- (p) => tok.startsWith(p + "/") || tok.includes("/" + p + "/"),
408
- ),
409
- );
410
-
411
- export default experimental_defineHook({
412
- on: "PreToolUse",
413
- match: tools("Bash"),
414
- needs: [provide("config", READ_CONFIG)],
415
- decide: (e) => {
416
- const root = papersRoot(e.ctx.config);
417
- // A `deny` object rather than a string means the root could not be established. Returning it
418
- // unchanged is deliberate: there is no root to continue with, so there is nothing to decide.
419
- if (typeof root !== "string") return root;
420
- const PAPER_SOURCES = [root];
421
-
422
- // Reads are fine — the point is that WRITES must not bypass the gates that hang on
423
- // Edit/Write. A command that merely names a paper is not a bypass. `writesTo` establishes
424
- // that something under the papers root is WRITTEN — quote-safe, and it sees redirection
425
- // targets that `touches` cannot. The argument scan then only decides WHICH file, so the
426
- // extension filter still applies and an artifact/bundle write stays allowed.
427
- // ⚠️ That scan survives only because `writesTo` returns a boolean, not the targets it
428
- // matched; with `writeTargets()` upstream this helper deletes.
429
- const writesViaArgv =
430
- runsMutator(e.command) &&
431
- (e.command.writesTo(PAPER_SOURCES) || e.command.touches(PAPER_SOURCES)) &&
432
- namesPaperSource(e.command.raw, PAPER_SOURCES);
433
- const hits = writesViaArgv || redirectsInto(e.command.raw, PAPER_SOURCES);
434
- if (!hits) return allow();
435
-
436
- return deny(
437
- "Writing a paper source from Bash skips every PostToolUse gate " +
438
- "(the readability thresholds, the pipeline nudge, the unrun-gate check). " +
439
- "Use Edit or Write. For a machine-generated rewrite, emit to a temp file " +
440
- `outside ${root}/ and land it with Write.`,
441
- );
442
- },
443
- });
@@ -1,66 +0,0 @@
1
- /**
2
- * paper-edit-guard's Bash scan on the shapes the hooks harness does not carry: a `>` inside quotes
3
- * or escaped (not a redirection), a target spelled with backslashes (read through them), a target
4
- * ended by a delimiter, and a mutator that moves a paper source AWAY — a write `writesTo` does not
5
- * see, which the `touches` fallback catches. Each case runs the hook the way a consumer's settings
6
- * run it: `vigiles hook-runtime run-program`, from a throwaway project.
7
- */
8
- import assert from "node:assert/strict";
9
- import { test } from "vitest";
10
- import { hookConsumer, onBash, runShippedHook } from "../test/hook-consumer.ts";
11
- import { useTempDir } from "../test/support.ts";
12
-
13
- const dir = hookConsumer(useTempDir("paper-edit-guard-"), {
14
- "papers/alpha/PIPELINE-STATUS.md": "# S\n",
15
- });
16
- /** `>` built rather than typed: a literal one here would be a redirection to the guard's own scan. */
17
- const GT = String.fromCharCode(62);
18
- const P = "papers/alpha/paper.tex";
19
-
20
- /** The guard's exit code for one Bash command: 2 denies, 0 lets it through. */
21
- const guard = (command: string): number =>
22
- runShippedHook("paper-edit-guard", onBash(command), dir).exitCode;
23
-
24
- test("a `>` inside quotes, after an escaped quote, or escaped itself is not a redirection", () => {
25
- assert.deepEqual(
26
- [
27
- guard(`echo "a ${GT} ${P}"`),
28
- guard(`echo "a \\" ${GT} b"`),
29
- guard(`echo a\\${GT} ${P}`),
30
- ],
31
- [0, 0, 0],
32
- );
33
- });
34
-
35
- test("a redirection target is read through backslashes, quoted or not, and ends at a delimiter", () => {
36
- assert.deepEqual(
37
- [
38
- guard(`echo x ${GT} "papers/alpha/pa\\per.tex"`),
39
- guard(`echo x ${GT} papers/alpha/pa\\per.tex`),
40
- guard(`echo x ${GT}${P}; true`),
41
- ],
42
- [2, 2, 2],
43
- );
44
- });
45
-
46
- test("moving a paper source away is a write to it: denied", () => {
47
- assert.equal(guard(`mv ${P} /tmp/elsewhere.md`), 2);
48
- });
49
-
50
- test("a command cut off right after a backslash still names its target, quoted or not", () => {
51
- // The backslash escapes nothing — there is no next character — and the target read so far
52
- // is still a paper source.
53
- assert.deepEqual(
54
- [guard(`echo x ${GT} ${P}\\`), guard(`echo x ${GT} "${P}\\`)],
55
- [2, 2],
56
- );
57
- });
58
-
59
- test("only paper.tex is a paper source: copying over another file of the paper is let through", () => {
60
- // Guards: the extension filter of the argv leg. (A redirection is refused for ANY file under the
61
- // papers root, so the argv leg is the one that says which files are sources.)
62
- assert.deepEqual(
63
- [guard("cp /tmp/x papers/alpha/notes.txt"), guard(`cp /tmp/x ${P}`)],
64
- [0, 2],
65
- );
66
- });
@@ -1,22 +0,0 @@
1
- // Types for the exports `hooks/paper-skills-nudge.test.ts` imports from the hook. The hook ships as
2
- // plain .mjs (a compiled hook may import nothing but `vigiles/hook`), so without this file TypeScript
3
- // sees `any` and `tsc -p tsconfig.test.json` fails with TS7016 — the same reason
4
- // `paper-edit-guard.hook.d.mts` exists.
5
-
6
- /** One line per skill from the provider's tab-separated `name<TAB>description` output. */
7
- export declare const skillLines: (raw: string | undefined) => readonly string[];
8
-
9
- /** The paper a path belongs to, from every spelling of the path the event carries; null when none. */
10
- export declare const paperOf: (
11
- paths: readonly (string | undefined)[],
12
- root: string,
13
- ) => string | null;
14
-
15
- /** The notice text for one paper and its skill lines. */
16
- export declare const message: (
17
- paper: string,
18
- lines: readonly string[],
19
- ) => string;
20
-
21
- declare const hook: unknown;
22
- export default hook;