paperlint 19.0.1 → 19.0.2
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.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +7 -11
- package/dist/cli.js.map +1 -1
- package/dist/folder-layout-hook.js +1 -1
- package/dist/hooks-notice.d.ts +2 -0
- package/dist/hooks-notice.d.ts.map +1 -1
- package/dist/hooks-notice.js +4 -1
- package/dist/hooks-notice.js.map +1 -1
- package/docs/install.md +4 -4
- package/docs/layout.md +0 -1
- package/hooks/hooks.harness.ts +2 -140
- package/hooks/paper-skills-nudge.hook.mjs +0 -6
- package/lib/paper-config.harness.mjs +1 -2
- package/package.json +1 -1
- package/plugin/hooks/hooks.json +0 -9
- package/scripts/eslint-file-length.mjs +1 -1
- package/src/cli.harness.mjs +9 -8
- package/src/cli.test.ts +4 -4
- package/src/cli.ts +7 -10
- package/src/folder-layout-hook.ts +1 -1
- package/src/hooks-notice.test.ts +2 -2
- package/src/hooks-notice.ts +10 -1
- package/src/hooks-settings.harness.ts +8 -8
- package/hooks/paper-status-gates.hook.mjs +0 -158
- package/hooks/paper-status-gates.sh +0 -93
- package/hooks/paper-status-gates.test.ts +0 -101
package/hooks/hooks.harness.ts
CHANGED
|
@@ -174,7 +174,7 @@ try {
|
|
|
174
174
|
// future `vigiles compile`/`lint` pass would apply to the shipped artifact. It is to describe
|
|
175
175
|
// a forbidden import in prose WITHOUT writing one. Anyone extending these headers: do not
|
|
176
176
|
// quote an import statement in a comment here; name it in words.
|
|
177
|
-
check("there are shipped hooks to check at all", SHIPPED.length
|
|
177
|
+
check("there are shipped hooks to check at all", SHIPPED.length > 0);
|
|
178
178
|
for (const f of SHIPPED) {
|
|
179
179
|
const offenders = checkHookImports(readFileSync(join(HOOKS, f), "utf8"));
|
|
180
180
|
check(
|
|
@@ -329,22 +329,13 @@ try {
|
|
|
329
329
|
guarded.exitCode === 2,
|
|
330
330
|
);
|
|
331
331
|
|
|
332
|
-
// The
|
|
332
|
+
// The PostToolUse hook: still SPEAKS from a foreign cwd.
|
|
333
333
|
const nudge = adrift(
|
|
334
334
|
dir,
|
|
335
335
|
"paper-skills-nudge",
|
|
336
336
|
onEdit(`${dir}/writing/drafts/alpha/paper.tex`),
|
|
337
337
|
);
|
|
338
338
|
check("drift · the skills nudge still fires", injected(nudge).length > 0);
|
|
339
|
-
const gates = adrift(
|
|
340
|
-
dir,
|
|
341
|
-
"paper-status-gates",
|
|
342
|
-
onEdit(`${dir}/writing/drafts/alpha/PIPELINE-STATUS.md`),
|
|
343
|
-
);
|
|
344
|
-
check(
|
|
345
|
-
`drift · the status-gates hook still runs (rc=${String(gates.exitCode)})`,
|
|
346
|
-
gates.exitCode === 0,
|
|
347
|
-
);
|
|
348
339
|
}
|
|
349
340
|
|
|
350
341
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -555,80 +546,6 @@ try {
|
|
|
555
546
|
}
|
|
556
547
|
}
|
|
557
548
|
|
|
558
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
559
|
-
// VI. paper-status-gates — the tool runs, and only for a validated directory
|
|
560
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
561
|
-
{
|
|
562
|
-
const dir = fixture({ [PAPERS_DIR_FIELD]: "docs/papers" });
|
|
563
|
-
const fires = (label: string, p: string) => {
|
|
564
|
-
const r = at(dir, "paper-status-gates", onEdit(p));
|
|
565
|
-
check(
|
|
566
|
-
`gates FIRES on ${label} (${String(r.stderr.length)}b stderr)`,
|
|
567
|
-
/fixture verdict line/.test(r.stderr),
|
|
568
|
-
);
|
|
569
|
-
check(`gates on ${label} exits 0`, r.exitCode === 0);
|
|
570
|
-
};
|
|
571
|
-
const silent = (label: string, p: string) => {
|
|
572
|
-
const r = at(dir, "paper-status-gates", onEdit(p));
|
|
573
|
-
check(
|
|
574
|
-
`gates SILENT on ${label}`,
|
|
575
|
-
r.stdout.length === 0 && r.stderr.length === 0 && r.exitCode === 0,
|
|
576
|
-
);
|
|
577
|
-
};
|
|
578
|
-
fires("a relative paper.tex", "docs/papers/alpha/paper.tex");
|
|
579
|
-
fires("an ABSOLUTE paper.tex", join(dir, "docs/papers/alpha/paper.tex"));
|
|
580
|
-
silent("a README under the papers root", "docs/papers/README.md");
|
|
581
|
-
silent("a file outside the papers root", "README.md");
|
|
582
|
-
// 🔴 THE BOUNDARY IN `(?:^|/)`: a directory merely ENDING in the root's last segment must
|
|
583
|
-
// not smuggle a match. Without the boundary this is a hit.
|
|
584
|
-
silent(
|
|
585
|
-
"a look-alike root (`notdocs/papers/…`)",
|
|
586
|
-
"notdocs/papers/alpha/paper.tex",
|
|
587
|
-
);
|
|
588
|
-
// A `.tex` whose directory name carries a shell metacharacter cannot reach a command.
|
|
589
|
-
silent(
|
|
590
|
-
"a directory name with a shell metacharacter",
|
|
591
|
-
"docs/papers/al;pha/paper.tex",
|
|
592
|
-
);
|
|
593
|
-
// 🔴 The `??` discriminator again, for this hook's own copy of the carrier.
|
|
594
|
-
{
|
|
595
|
-
const broken = fixture(
|
|
596
|
-
{ [PAPERS_DIR_FIELD]: null },
|
|
597
|
-
{ papers: "papers" },
|
|
598
|
-
);
|
|
599
|
-
check(
|
|
600
|
-
"gates: an explicit null is NOT read as an absence (no fallback to the default root)",
|
|
601
|
-
at(broken, "paper-status-gates", onEdit("papers/alpha/paper.tex"))
|
|
602
|
-
.stderr.length === 0,
|
|
603
|
-
);
|
|
604
|
-
}
|
|
605
|
-
// The declared root is regex-ESCAPED: `.` in a root must not act as a wildcard.
|
|
606
|
-
{
|
|
607
|
-
const dotted = fixture(
|
|
608
|
-
{ [PAPERS_DIR_FIELD]: "docs.v2/papers" },
|
|
609
|
-
{ papers: "docs.v2/papers" },
|
|
610
|
-
);
|
|
611
|
-
check(
|
|
612
|
-
"gates: a root with a dot matches ITSELF",
|
|
613
|
-
/fixture verdict line/.test(
|
|
614
|
-
at(
|
|
615
|
-
dotted,
|
|
616
|
-
"paper-status-gates",
|
|
617
|
-
onEdit("docs.v2/papers/alpha/paper.tex"),
|
|
618
|
-
).stderr,
|
|
619
|
-
),
|
|
620
|
-
);
|
|
621
|
-
check(
|
|
622
|
-
"gates: …and the dot is NOT a wildcard",
|
|
623
|
-
at(
|
|
624
|
-
dotted,
|
|
625
|
-
"paper-status-gates",
|
|
626
|
-
onEdit("docsXv2/papers/alpha/paper.tex"),
|
|
627
|
-
).stderr.length === 0,
|
|
628
|
-
);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
549
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
633
550
|
// VII. THE FORCED DUPLICATION — moved out, and why
|
|
634
551
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -643,61 +560,6 @@ try {
|
|
|
643
560
|
// comparison. They could have drifted in silence. A check named after one part of a set
|
|
644
561
|
// cannot notice the rest of the set.
|
|
645
562
|
|
|
646
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
647
|
-
// VIII. paper-status-gates.sh — a TOOL, and it must refuse to be a hook
|
|
648
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
649
|
-
{
|
|
650
|
-
const dir = fixture({ [PAPERS_DIR_FIELD]: "docs/papers" });
|
|
651
|
-
const sh = (args: string) =>
|
|
652
|
-
runHook(
|
|
653
|
-
`bash ${JSON.stringify(join(HOOKS, "paper-status-gates.sh"))} ${args}`,
|
|
654
|
-
STOP,
|
|
655
|
-
{
|
|
656
|
-
cwd: dir,
|
|
657
|
-
env: { CLAUDE_PROJECT_DIR: dir },
|
|
658
|
-
},
|
|
659
|
-
);
|
|
660
|
-
const usage = sh("");
|
|
661
|
-
check(
|
|
662
|
-
"the .sh called with no --surface says it is a tool",
|
|
663
|
-
/a tool, not a hook/.test(usage.stderr),
|
|
664
|
-
);
|
|
665
|
-
check("…and still exits 0 (it must never block)", usage.exitCode === 0);
|
|
666
|
-
const good = sh("--surface alpha");
|
|
667
|
-
check(
|
|
668
|
-
"the .sh surfaces the verdict for a real paper",
|
|
669
|
-
/fixture verdict line/.test(good.stderr),
|
|
670
|
-
);
|
|
671
|
-
check(
|
|
672
|
-
"…and reads the papers root from the DECLARATION",
|
|
673
|
-
good.exitCode === 0,
|
|
674
|
-
);
|
|
675
|
-
const missing = sh("--surface nosuchpaper");
|
|
676
|
-
check(
|
|
677
|
-
"the .sh is silent for a directory with no status file",
|
|
678
|
-
missing.stderr.length === 0,
|
|
679
|
-
);
|
|
680
|
-
// 🔴 THE NASTY NAME NEEDS A REAL DIRECTORY BEHIND IT, or the assertion cannot fail. First
|
|
681
|
-
// draft just passed `a;b` and checked for silence — but a name that names nothing is silent
|
|
682
|
-
// anyway, for want of a status file, so deleting the name check would leave this harness
|
|
683
|
-
// green regardless. The fixture now contains a paper literally called `a;b` with a status file in it:
|
|
684
|
-
// with the check, silence; without it, the verdict comes out. Measured 2026-09-12.
|
|
685
|
-
mkdirSync(join(dir, "docs/papers/a;b"), { recursive: true });
|
|
686
|
-
writeFileSync(
|
|
687
|
-
join(dir, "docs/papers/a;b/PIPELINE-STATUS.md"),
|
|
688
|
-
"**Readiness verdict:** ✅ fixture verdict line\n",
|
|
689
|
-
);
|
|
690
|
-
check(
|
|
691
|
-
"the .sh's positive control: a plain name with a status file DOES surface",
|
|
692
|
-
/fixture verdict line/.test(sh("--surface alpha").stderr),
|
|
693
|
-
);
|
|
694
|
-
const nasty = sh("--surface 'a;b'");
|
|
695
|
-
check(
|
|
696
|
-
"the .sh re-rejects a name with a metacharacter EVEN THOUGH that paper exists",
|
|
697
|
-
nasty.stderr.length === 0 && nasty.exitCode === 0,
|
|
698
|
-
);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
563
|
console.log(`hooks.harness: ${String(check.count)} assertions passed`);
|
|
702
564
|
} finally {
|
|
703
565
|
for (const d of tmps) rmSync(d, { recursive: true, force: true });
|
|
@@ -10,12 +10,6 @@
|
|
|
10
10
|
* the payload: the runtime decodes the event and hands in `e.path`, so the whole family of "read
|
|
11
11
|
* the wrong input / wrote the wrong field / exited the wrong code" is unrepresentable here.
|
|
12
12
|
*
|
|
13
|
-
* ── SPLIT FROM `paper-status-gates`, DELIBERATELY ───────────────────────────
|
|
14
|
-
* This carries the STATIC checklist. The part that reads `<paper-dir>/PIPELINE-STATUS.md` and
|
|
15
|
-
* surfaces unrun gates lives in `paper-status-gates.hook.mjs`, because it needs a tool run and
|
|
16
|
-
* this one does not. Two hooks on one event is the honest line between a constant and an I/O,
|
|
17
|
-
* not an accident of porting.
|
|
18
|
-
*
|
|
19
13
|
* ── DELIVERY, MEASURED (2026-09-12, vigiles 27.1.4) ─────────────────────────
|
|
20
14
|
* `PostToolUse` is in the adapter's `injectableEvents`, so a `notice` on this event reaches the
|
|
21
15
|
* model as `hookSpecificOutput.additionalContext` on STDOUT — 1 346 bytes on a paper edit, 0 on
|
|
@@ -44,7 +44,6 @@ const CARRIERS = [
|
|
|
44
44
|
"lib/paper-config.ts",
|
|
45
45
|
"hooks/paper-edit-guard.hook.mjs",
|
|
46
46
|
"hooks/paper-skills-nudge.hook.mjs",
|
|
47
|
-
"hooks/paper-status-gates.hook.mjs",
|
|
48
47
|
"eslint-rules/papers.ts",
|
|
49
48
|
"skills/paper-pipeline/scripts/consumer.mjs",
|
|
50
49
|
];
|
|
@@ -191,7 +190,7 @@ const loaded = await Promise.all(
|
|
|
191
190
|
);
|
|
192
191
|
check(
|
|
193
192
|
"and the search itself is not empty — otherwise it is searching the wrong place, and its zero reads as all-clear",
|
|
194
|
-
found.length
|
|
193
|
+
found.length > 0,
|
|
195
194
|
);
|
|
196
195
|
}
|
|
197
196
|
|
package/package.json
CHANGED
package/plugin/hooks/hooks.json
CHANGED
|
@@ -34,15 +34,6 @@
|
|
|
34
34
|
}
|
|
35
35
|
]
|
|
36
36
|
},
|
|
37
|
-
{
|
|
38
|
-
"matcher": "Edit|Write|MultiEdit",
|
|
39
|
-
"hooks": [
|
|
40
|
-
{
|
|
41
|
-
"type": "command",
|
|
42
|
-
"command": "node \"${CLAUDE_PROJECT_DIR}/node_modules/paperlint/bin/paperlint.mjs\" hook paper-status-gates"
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
},
|
|
46
37
|
{
|
|
47
38
|
"matcher": "Edit|Write|MultiEdit",
|
|
48
39
|
"hooks": [
|
|
@@ -13,7 +13,7 @@ const legacyCeilings = {
|
|
|
13
13
|
"eslint-rules/prereg-coverage.ts": 320,
|
|
14
14
|
"eslint-rules/tex-build.harness.mjs": 535,
|
|
15
15
|
"eslint.config.mjs": 622,
|
|
16
|
-
"hooks/hooks.harness.ts":
|
|
16
|
+
"hooks/hooks.harness.ts": 382,
|
|
17
17
|
"scripts/coverage-config.test.ts": 376,
|
|
18
18
|
"scripts/pipeline.ts": 380,
|
|
19
19
|
"src/adapters/git/history.test.ts": 327,
|
package/src/cli.harness.mjs
CHANGED
|
@@ -1185,17 +1185,18 @@ check(
|
|
|
1185
1185
|
|
|
1186
1186
|
said = "";
|
|
1187
1187
|
check(
|
|
1188
|
-
"no name —
|
|
1189
|
-
runHook(undefined, { err }) ===
|
|
1188
|
+
"no name — the right invocation is suggested, and it does not deny",
|
|
1189
|
+
runHook(undefined, { err }) === 1 &&
|
|
1190
1190
|
/paperlint hook paper-edit-guard/.test(said),
|
|
1191
1191
|
);
|
|
1192
1192
|
|
|
1193
|
+
// An unknown name cannot run, the same failure as a missing runtime below, so it must not deny (#324).
|
|
1193
1194
|
said = "";
|
|
1195
|
+
const named =
|
|
1196
|
+
/unknown hook `no-such-hook`.*no-such-hook\.hook\.mjs.*paperlint \d+\.\d+\.\d+.*npm install/s;
|
|
1194
1197
|
check(
|
|
1195
|
-
"an unknown hook is NAMED
|
|
1196
|
-
runHook("no-such-hook", { err }) ===
|
|
1197
|
-
/unknown hook `no-such-hook`/.test(said) &&
|
|
1198
|
-
/no-such-hook\.hook\.mjs/.test(said),
|
|
1198
|
+
"an unknown hook is NAMED with its path, the installed version and the remedy, and does not deny",
|
|
1199
|
+
runHook("no-such-hook", { err }) === 1 && named.test(said),
|
|
1199
1200
|
);
|
|
1200
1201
|
|
|
1201
1202
|
// 🔴 THE MAIN ASSERTION. A runtime that cannot be found HAS NO RIGHT to return 2: on
|
|
@@ -1213,8 +1214,8 @@ check(
|
|
|
1213
1214
|
resolve: brokenResolve,
|
|
1214
1215
|
});
|
|
1215
1216
|
check(
|
|
1216
|
-
"the runtime does not resolve — work is NOT blocked (code
|
|
1217
|
-
code ===
|
|
1217
|
+
"the runtime does not resolve — work is NOT blocked (code 1: shown to the person, not 2)",
|
|
1218
|
+
code === 1,
|
|
1218
1219
|
);
|
|
1219
1220
|
check(
|
|
1220
1221
|
"and the complaint is LOUD: the hook is named, the effect is named, the remedy is named",
|
package/src/cli.test.ts
CHANGED
|
@@ -224,7 +224,7 @@ test("runHook: a runtime with no cli.js beside it, and a hook killed by a signal
|
|
|
224
224
|
assert.deepEqual(
|
|
225
225
|
{ noCli, killed, messages: messages.map((m) => m.split(" from ")[0]) },
|
|
226
226
|
{
|
|
227
|
-
noCli:
|
|
227
|
+
noCli: 1,
|
|
228
228
|
killed: 0,
|
|
229
229
|
messages: ["paperlint: the hook runtime (vigiles) is not resolvable"],
|
|
230
230
|
},
|
|
@@ -1219,11 +1219,11 @@ test("lint with its LaTeX language missing from the install still lints the scor
|
|
|
1219
1219
|
assert.match(whole.out, /missing all of `paper\.tex`/);
|
|
1220
1220
|
});
|
|
1221
1221
|
|
|
1222
|
-
test("`paperlint hook` with no name: exit
|
|
1222
|
+
test("`paperlint hook` with no name: exit 1, so it cannot deny and is shown, and the usage names an example", async () => {
|
|
1223
1223
|
assert.deepEqual(await cli(["hook"], root), {
|
|
1224
|
-
code:
|
|
1224
|
+
code: 1,
|
|
1225
1225
|
out: "",
|
|
1226
|
-
err: "`hook` needs a name, e.g. `paperlint hook paper-edit-guard
|
|
1226
|
+
err: "paperlint: `hook` needs a name, e.g. `paperlint hook paper-edit-guard`; no hook is running.",
|
|
1227
1227
|
});
|
|
1228
1228
|
});
|
|
1229
1229
|
|
package/src/cli.ts
CHANGED
|
@@ -250,6 +250,7 @@ import {
|
|
|
250
250
|
noticeText,
|
|
251
251
|
notYetTold,
|
|
252
252
|
recordTold,
|
|
253
|
+
hookNotRunningText,
|
|
253
254
|
} from "./hooks-notice.ts";
|
|
254
255
|
import { unwiredHooks } from "./hooks-settings.ts";
|
|
255
256
|
import {
|
|
@@ -1856,18 +1857,14 @@ function runHookPlain(
|
|
|
1856
1857
|
readonly capture?: boolean;
|
|
1857
1858
|
} = {},
|
|
1858
1859
|
): number | Promise<number> {
|
|
1859
|
-
|
|
1860
|
-
err(`\`hook\` needs a name, e.g. \`paperlint hook paper-edit-guard\``);
|
|
1861
|
-
return 2;
|
|
1862
|
-
}
|
|
1863
|
-
const inProcess = IN_PROCESS_HOOKS[name];
|
|
1860
|
+
const inProcess = IN_PROCESS_HOOKS[name ?? ""];
|
|
1864
1861
|
if (inProcess !== undefined) return inProcess({ err, stdin, out });
|
|
1865
1862
|
const program = fileURLToPath(
|
|
1866
|
-
new URL(`../hooks/${name}.hook.mjs`, import.meta.url),
|
|
1863
|
+
new URL(`../hooks/${name ?? ""}.hook.mjs`, import.meta.url),
|
|
1867
1864
|
);
|
|
1868
|
-
if (!existsSync(program)) {
|
|
1869
|
-
err(
|
|
1870
|
-
return 2;
|
|
1865
|
+
if (!name || !existsSync(program)) {
|
|
1866
|
+
err(hookNotRunningText(name, program, packageVersion()));
|
|
1867
|
+
return 1; // not 2: that denies every Bash command, the fix included (#324); not 0: nobody sees it
|
|
1871
1868
|
}
|
|
1872
1869
|
let runtime;
|
|
1873
1870
|
try {
|
|
@@ -1880,7 +1877,7 @@ function runHookPlain(
|
|
|
1880
1877
|
`The \`${name}\` hook is NOT running. Everything else — \`paperlint lint\`, CI — is unaffected.\n` +
|
|
1881
1878
|
`Reinstall this package so its dependencies are present.`,
|
|
1882
1879
|
);
|
|
1883
|
-
return 0
|
|
1880
|
+
return 1; // not 2: that would deny every Bash command; not 0: nobody would see this
|
|
1884
1881
|
}
|
|
1885
1882
|
const args = [runtime, "hook-runtime", "run-program", program];
|
|
1886
1883
|
const r =
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* ── WHY IT IS NOT A VIGILES PROGRAM LIKE ITS NEIGHBOURS (measured 2026-10-12, vigiles 38) ──────
|
|
29
29
|
* A shipped `.hook.mjs` may import nothing but `vigiles/hook` (`checkHookImports`), so it cannot call
|
|
30
30
|
* this package's function; its only way to a tool is `run()`, whose output reaches stderr and never
|
|
31
|
-
* the hook's answer (
|
|
31
|
+
* the hook's answer (measured 2026-09-12, vigiles 27); and a `provide()` command runs
|
|
32
32
|
* before the reaction without the event, so it cannot know which file is written. Each of the three
|
|
33
33
|
* would mean a second copy of the layout. So `paperlint hook paper-folder-layout` runs this module
|
|
34
34
|
* in-process (`runHook`, src/cli.ts), behind the same wiring command as the other hooks, which is
|
package/src/hooks-notice.test.ts
CHANGED
|
@@ -171,7 +171,7 @@ test("a wired hook on a paper file: missing hook → one notice, the same versio
|
|
|
171
171
|
});
|
|
172
172
|
|
|
173
173
|
test("the notice rides on what the hook said: a block stays a block, and the exit stays 0", async () => {
|
|
174
|
-
const dir = project("block", wiringWithout(["paper-
|
|
174
|
+
const dir = project("block", wiringWithout(["paper-skills-nudge"]), true);
|
|
175
175
|
const said = await hook(
|
|
176
176
|
"lint-edited",
|
|
177
177
|
dir,
|
|
@@ -186,7 +186,7 @@ test("the notice rides on what the hook said: a block stays a block, and the exi
|
|
|
186
186
|
assert.match(parsed.reason, /tex\/max-sentence-words/);
|
|
187
187
|
assert.match(
|
|
188
188
|
Notice.parse(parsed).hookSpecificOutput.additionalContext,
|
|
189
|
-
/paper-
|
|
189
|
+
/paper-skills-nudge/,
|
|
190
190
|
);
|
|
191
191
|
});
|
|
192
192
|
|
package/src/hooks-notice.ts
CHANGED
|
@@ -30,9 +30,18 @@ import type { Files } from "./ports/files.ts";
|
|
|
30
30
|
export const NOTICE_HOOKS: readonly string[] = [
|
|
31
31
|
"lint-edited",
|
|
32
32
|
"paper-skills-nudge",
|
|
33
|
-
"paper-status-gates",
|
|
34
33
|
];
|
|
35
34
|
|
|
35
|
+
/** What `paperlint hook [name]` says when it cannot run a hook: no name, or no such hook shipped. It names the remedy; the caller does not deny (#324). */
|
|
36
|
+
export const hookNotRunningText = (
|
|
37
|
+
name: string | undefined,
|
|
38
|
+
program: string,
|
|
39
|
+
version: string,
|
|
40
|
+
): string =>
|
|
41
|
+
name === undefined || name === ""
|
|
42
|
+
? "paperlint: `hook` needs a name, e.g. `paperlint hook paper-edit-guard`; no hook is running."
|
|
43
|
+
: `paperlint: unknown hook \`${name}\` — no such program at ${program}; it is NOT running (installed: paperlint ${version}). Run \`npm install\`, or remove \`paperlint hook ${name}\` from .claude/settings.json.`;
|
|
44
|
+
|
|
36
45
|
/** Where the version last told is kept, relative to the project root. */
|
|
37
46
|
export const NOTICE_STATE = join(
|
|
38
47
|
"node_modules",
|
|
@@ -65,9 +65,9 @@ check(
|
|
|
65
65
|
// ── the one source: plugin/hooks/hooks.json ─────────────────────────────────────────────
|
|
66
66
|
const wiring = shippedWiring();
|
|
67
67
|
check(
|
|
68
|
-
"the hook names are DERIVED from hooks.json —
|
|
68
|
+
"the hook names are DERIVED from hooks.json — five, in its order",
|
|
69
69
|
wiring.names.join() ===
|
|
70
|
-
"paper-edit-guard,submission-confirm,paper-folder-layout,paper-skills-nudge,
|
|
70
|
+
"paper-edit-guard,submission-confirm,paper-folder-layout,paper-skills-nudge,lint-edited",
|
|
71
71
|
);
|
|
72
72
|
// ── settings written by hand: shapes Claude Code would ignore are skipped, not crashed on ──
|
|
73
73
|
check(
|
|
@@ -140,8 +140,8 @@ try {
|
|
|
140
140
|
const cases: [string, { name: string; ours: boolean } | null][] = [
|
|
141
141
|
[ours, { name: "paper-edit-guard", ours: true }],
|
|
142
142
|
[
|
|
143
|
-
`node "$CLAUDE_PROJECT_DIR/${MANAGED_BY}" hook
|
|
144
|
-
{ name: "
|
|
143
|
+
`node "$CLAUDE_PROJECT_DIR/${MANAGED_BY}" hook lint-edited`,
|
|
144
|
+
{ name: "lint-edited", ours: true },
|
|
145
145
|
],
|
|
146
146
|
[
|
|
147
147
|
`node "$CLAUDE_PROJECT_DIR/node_modules/vigiles/dist/cli.js" hook-runtime run-program "$CLAUDE_PROJECT_DIR/node_modules/paperlint/hooks/paper-edit-guard.hook.mjs"`,
|
|
@@ -284,7 +284,7 @@ try {
|
|
|
284
284
|
"and names the hooks that are not wired in ANY form",
|
|
285
285
|
r.status === "foreign" &&
|
|
286
286
|
r.missing.join() ===
|
|
287
|
-
"submission-confirm,paper-folder-layout,paper-skills-nudge,
|
|
287
|
+
"submission-confirm,paper-folder-layout,paper-skills-nudge,lint-edited",
|
|
288
288
|
);
|
|
289
289
|
// The control: without the check, vigiles' merge WOULD add a second copy. This is the
|
|
290
290
|
// reason the check exists, measured rather than asserted.
|
|
@@ -320,13 +320,13 @@ try {
|
|
|
320
320
|
const wiredOnce = merge({}, wiring.compiled, MANAGED_BY);
|
|
321
321
|
check(
|
|
322
322
|
"wired once each → ✓ wired, with the fresh-clone consequence",
|
|
323
|
-
/✓ wired — paper-edit-guard, submission-confirm, paper-folder-layout, paper-skills-nudge,
|
|
323
|
+
/✓ wired — paper-edit-guard, submission-confirm, paper-folder-layout, paper-skills-nudge, lint-edited, once each/.test(
|
|
324
324
|
doc(wiredOnce),
|
|
325
325
|
) && /cannot run until `npm install`/.test(doc(wiredOnce)),
|
|
326
326
|
);
|
|
327
327
|
check(
|
|
328
328
|
"nothing wired → ⚠ not wired, with the remedy",
|
|
329
|
-
/⚠ not wired — none of the
|
|
329
|
+
/⚠ not wired — none of the 5 hooks/.test(doc({})),
|
|
330
330
|
);
|
|
331
331
|
const twice = PreToolUseSettings.parse(structuredClone(wiredOnce));
|
|
332
332
|
twice.hooks.PreToolUse[0]?.hooks.push({
|
|
@@ -354,7 +354,7 @@ try {
|
|
|
354
354
|
});
|
|
355
355
|
check(
|
|
356
356
|
"🔴 partly wired BY HAND → the remedy is NOT `npx paperlint init`, which would refuse to write",
|
|
357
|
-
/partly wired — missing: submission-confirm, paper-folder-layout, paper-skills-nudge,
|
|
357
|
+
/partly wired — missing: submission-confirm, paper-folder-layout, paper-skills-nudge, lint-edited/.test(
|
|
358
358
|
handPartial,
|
|
359
359
|
) && /writes nothing then/.test(handPartial),
|
|
360
360
|
);
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* paper-status-gates — a PostToolUse react: editing a paper's source surfaces that paper's
|
|
3
|
-
* readiness verdict and its UNRUN GATES, unprompted.
|
|
4
|
-
*
|
|
5
|
-
* A ☐ against study-accepted / pc-panel / harden / verify-citations is a HOLE, not an
|
|
6
|
-
* "anti-churn" skip: a session that skipped three of them had the panel come back with real
|
|
7
|
-
* must-fixes. Advisory, never blocks, always exits 0 — a `react`'s type has no `deny`.
|
|
8
|
-
*
|
|
9
|
-
* ── WHY IT WAS WORTH SURFACING AT ALL ───────────────────────────────────────
|
|
10
|
-
* The checker PARSED the verdict line (to test it was not a bare percentage) and never PRINTED
|
|
11
|
-
* it, so the one fact its author kept asking for by hand was the one thing the tooling reliably
|
|
12
|
-
* withheld. A status file nobody is shown is a status file nobody reads.
|
|
13
|
-
*
|
|
14
|
-
* ── THE PURE / IMPURE LINE, AND WHERE IT REALLY FALLS ───────────────────────
|
|
15
|
-
* An earlier header claimed this half "READS A FILE and interpolates its contents, and a vigiles
|
|
16
|
-
* `react` is a pure function — it cannot", and called that the honest boundary of the closed
|
|
17
|
-
* vocabulary. That reading was one step too pessimistic. The boundary is real, but it falls
|
|
18
|
-
* between DECIDING and DOING, not between "hook" and "shell": deciding whether this edit
|
|
19
|
-
* concerns a paper, and WHICH one, is pure and belongs here; reading that paper's status file
|
|
20
|
-
* and running the checker is a tool, and `run()` is how a react invokes one.
|
|
21
|
-
*
|
|
22
|
-
* ── WHY THE DIRECTORY NAME IS VALIDATED BEFORE IT REACHES A COMMAND ─────────
|
|
23
|
-
* `run()` takes a string AND IT GOES THROUGH A SHELL — measured 2026-09-12: a `$(…)` inside a
|
|
24
|
-
* `run()` command substitutes. This one embeds a path taken from the event, so the name is
|
|
25
|
-
* extracted by an anchored pattern and accepted only if it is `[A-Za-z0-9._-]+` — no slash, no
|
|
26
|
-
* space, no shell metacharacter can survive. The shell predecessor got this incidentally, via a
|
|
27
|
-
* `grep -oE`; here it is explicit, because "incidentally safe" is how it stops being safe.
|
|
28
|
-
*
|
|
29
|
-
* 🔴 THE `(?:^|\/)` IS NOT DECORATION, AND LEAVING IT OUT KILLED THIS HOOK ONCE. The first
|
|
30
|
-
* version anchored the papers root at `^`, which passed every test in the harness — because the
|
|
31
|
-
* harness's own edit helper builds a RELATIVE path. The live harness sends an ABSOLUTE one.
|
|
32
|
-
* Measured against the real runtime:
|
|
33
|
-
*
|
|
34
|
-
* file_path "<root>/<paper>/paper.tex" → fires
|
|
35
|
-
* file_path "/abs/path/to/repo/<root>/<paper>/…" → SILENT
|
|
36
|
-
*
|
|
37
|
-
* So the hook would have been dead in production and green in the tests: precisely the
|
|
38
|
-
* false-confidence class this whole exercise is about, reintroduced while converting a hook away
|
|
39
|
-
* from it. The shell version was accidentally immune — it grepped the raw payload with no anchor
|
|
40
|
-
* at all. The harness now sends BOTH spellings for every case.
|
|
41
|
-
*
|
|
42
|
-
* The boundary is still required (`^` or `/`), so a directory merely ENDING in the root's last
|
|
43
|
-
* segment cannot smuggle a match.
|
|
44
|
-
*
|
|
45
|
-
* ── WHAT THIS HOOK'S OUTPUT DOES *NOT* DO, measured and named ───────────────
|
|
46
|
-
* ⚠️ A `run()` reaction's output is passed through RAW — 0 bytes of `hookSpecificOutput` on
|
|
47
|
-
* stdout, the tool's own text on stderr (measured 2026-09-12: 1 184 bytes of stderr, 0 of
|
|
48
|
-
* stdout). Only a `notice` on an injectable event becomes `additionalContext`. So this hook's
|
|
49
|
-
* findings reach a HUMAN reading the transcript's debug output, not the model's context. That is
|
|
50
|
-
* a property of the reaction KIND, not a bug here, and it is the reason the static half lives in
|
|
51
|
-
* `paper-skills-nudge` as a `notice` instead: that one does land.
|
|
52
|
-
*
|
|
53
|
-
* ── WHY `.mjs` AND NOT A `.hook.ts` SPEC ────────────────────────────────────
|
|
54
|
-
* See `paper-edit-guard.hook.mjs`: a `.ts` hook reached through `node_modules` does not load,
|
|
55
|
-
* and a consumer-side thin spec importing this logic is refused by `vigiles compile` and can
|
|
56
|
-
* never be re-stamped. Both halves measured there.
|
|
57
|
-
*/
|
|
58
|
-
import {
|
|
59
|
-
experimental_defineReact,
|
|
60
|
-
tools,
|
|
61
|
-
provide,
|
|
62
|
-
run,
|
|
63
|
-
nothing,
|
|
64
|
-
} from "vigiles/hook";
|
|
65
|
-
|
|
66
|
-
/** The tool's name — the package this hook resolves its scripts through. */
|
|
67
|
-
export const CONFIG_KEY = "paperlint";
|
|
68
|
-
/** The settings file at the project root. Optional: absent means every default. */
|
|
69
|
-
export const CONFIG_FILE = "paperlint.json";
|
|
70
|
-
/** The default. A consumer that declares nothing is assumed to keep papers in `papers/`. */
|
|
71
|
-
export const DEFAULT_PAPERS_ROOT = "papers";
|
|
72
|
-
/**
|
|
73
|
-
* The field of the root `paperlint.json` that names the papers directory. These are copies of the
|
|
74
|
-
* constants in `lib/paper-config.mjs` (a hook may import nothing but `vigiles/hook`);
|
|
75
|
-
* `lib/paper-config.harness.mjs` checks that the copies match.
|
|
76
|
-
*/
|
|
77
|
-
export const PAPERS_DIR_FIELD = "papersDir";
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The provider: the root `paperlint.json`, or `{}` when the project has none — so an ABSENT file
|
|
81
|
-
* (every default) and an UNREADABLE one (the empty string the runtime gives a failed provider)
|
|
82
|
-
* stay two different inputs.
|
|
83
|
-
*
|
|
84
|
-
* 🔴 THE PATH IS ANCHORED TO THE PROJECT ROOT. vigiles runs a provider "via execSync in the hook's
|
|
85
|
-
* cwd", which is the consumer's wiring — a string this hook cannot see. A bare relative path reads
|
|
86
|
-
* from whatever directory the Bash tool last moved to.
|
|
87
|
-
*/
|
|
88
|
-
const READ_CONFIG = `f="\${CLAUDE_PROJECT_DIR:-.}/${CONFIG_FILE}"; if [ -e "$f" ]; then cat "$f"; else echo '{}'; fi`;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The declared papers root, or `null` when it is unusable.
|
|
92
|
-
*
|
|
93
|
-
* ⚠️ `null` means SILENCE, not refusal — same asymmetry as `paper-skills-nudge` and for the same
|
|
94
|
-
* reason: this is advisory, and a `react` cannot deny anyway. The gate (`paper-edit-guard`) is
|
|
95
|
-
* the one that must refuse on an unreadable declaration, because there a silent default would
|
|
96
|
-
* pass the very writes it exists to stop.
|
|
97
|
-
*
|
|
98
|
-
* 🔴 `declared === undefined`, NOT `declared ?? DEFAULT` — `"papersDir": null` is a keystroke, not
|
|
99
|
-
* an absence.
|
|
100
|
-
*/
|
|
101
|
-
const papersRoot = (rawConfig) => {
|
|
102
|
-
let declared;
|
|
103
|
-
try {
|
|
104
|
-
declared = JSON.parse(rawConfig)?.[PAPERS_DIR_FIELD];
|
|
105
|
-
} catch {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
const root = declared === undefined ? DEFAULT_PAPERS_ROOT : declared;
|
|
109
|
-
if (typeof root !== "string" || root.length === 0) return null;
|
|
110
|
-
return root.replace(/\/+$/, "");
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* A paper SOURCE under `<root>/<dir>/`, with `<dir>` captured.
|
|
115
|
-
*
|
|
116
|
-
* 🔴 THE ROOT IS REGEX-ESCAPED. It is a path from a config file, and `.` is both a legal
|
|
117
|
-
* directory character and a regex wildcard: an unescaped root like `docs.v2/papers` would match
|
|
118
|
-
* `docsXv2/papers` too. Cheap to get right, and the failure it prevents is a hook firing about
|
|
119
|
-
* the wrong tree.
|
|
120
|
-
*/
|
|
121
|
-
const paperSourceRe = (root) =>
|
|
122
|
-
new RegExp(
|
|
123
|
-
`(?:^|/)${root.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/([A-Za-z0-9._-]+)/[^/]*\\.tex$`,
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* The tool invocation, with the script located rather than assumed.
|
|
128
|
-
*
|
|
129
|
-
* 🔴 `require.resolve` INSTEAD OF A HARD-CODED `node_modules/<pkg>/…` PATH. This package must
|
|
130
|
-
* not spell its own install location: a consumer may install it under an alias, and a
|
|
131
|
-
* pnpm/yarn-berry layout is not `node_modules/<name>` at all. `require.resolve` asks the
|
|
132
|
-
* resolver the same question Node itself answers, and it works for a non-JS extension —
|
|
133
|
-
* measured 2026-09-12 against a `.md` and a `.sh` in an installed copy. It runs in a `$(…)`
|
|
134
|
-
* because `run()` goes through a shell (also measured).
|
|
135
|
-
*/
|
|
136
|
-
const surface = (dir) =>
|
|
137
|
-
`bash "$(node -p "require.resolve('${CONFIG_KEY}/hooks/paper-status-gates.sh')")" --surface ${dir}`;
|
|
138
|
-
|
|
139
|
-
export default experimental_defineReact({
|
|
140
|
-
on: "PostToolUse",
|
|
141
|
-
match: tools("Edit", "Write", "MultiEdit"),
|
|
142
|
-
// The provider is anchored to the project root (`READ_CONFIG`, above).
|
|
143
|
-
//
|
|
144
|
-
// ⚠️ THE FAILURE HERE IS SILENT, which makes it more dangerous than its neighbor's.
|
|
145
|
-
// `paper-edit-guard` on PreToolUse DENIES loudly and visibly when the declaration is
|
|
146
|
-
// unreadable. This hook on PostToolUse just returns `nothing()`, i.e. simply stops firing:
|
|
147
|
-
// the `cat` fails → empty string → `JSON.parse("")` throws → `papersRoot` returns null
|
|
148
|
-
// → silence. And silence is exactly what a nudge's success state looks like, so a dead hook
|
|
149
|
-
// is indistinguishable from a working one.
|
|
150
|
-
needs: [provide("config", READ_CONFIG)],
|
|
151
|
-
react: (e) => {
|
|
152
|
-
const root = papersRoot(e.ctx.config);
|
|
153
|
-
if (root === null) return nothing();
|
|
154
|
-
const m = paperSourceRe(root).exec(e.path.raw.replace(/^\.\//, ""));
|
|
155
|
-
if (m === null) return nothing();
|
|
156
|
-
return run(surface(m[1]));
|
|
157
|
-
},
|
|
158
|
-
});
|