paperlint 19.0.2 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CLAUDE.md +2 -2
- package/dist/CLAUDE.md.spec.d.ts.map +1 -1
- package/dist/CLAUDE.md.spec.js +7 -1
- package/dist/CLAUDE.md.spec.js.map +1 -1
- package/dist/cli.d.ts +2 -21
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +45 -93
- package/dist/cli.js.map +1 -1
- package/dist/doctor.d.ts +8 -10
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +27 -37
- package/dist/doctor.js.map +1 -1
- package/dist/hooks-notice.d.ts +8 -2
- package/dist/hooks-notice.d.ts.map +1 -1
- package/dist/hooks-notice.js +15 -20
- package/dist/hooks-notice.js.map +1 -1
- package/dist/hooks-settings.d.ts +1 -1
- package/dist/hooks-settings.js +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.js +5 -5
- package/dist/lib/paper-config.d.ts +4 -9
- package/dist/lib/paper-config.d.ts.map +1 -1
- package/dist/lib/paper-config.js +4 -9
- package/dist/lib/paper-config.js.map +1 -1
- package/dist/papers-roots.d.ts +19 -0
- package/dist/papers-roots.d.ts.map +1 -0
- package/dist/papers-roots.js +42 -0
- package/dist/papers-roots.js.map +1 -0
- package/dist/retired-hooks.d.ts +6 -0
- package/dist/retired-hooks.d.ts.map +1 -0
- package/dist/retired-hooks.js +34 -0
- package/dist/retired-hooks.js.map +1 -0
- package/dist/skill-chunks/chunk-C2G5EK7S.js +579 -0
- package/dist/skill-chunks/{chunk-UL4INX2P.js → chunk-L3NJUJUP.js} +446 -446
- package/dist/skill-chunks/{chunk-EOVEVX67.js → chunk-X4VKG4KT.js} +1 -1
- package/dist/types.d.ts +1 -1
- package/docs/install.md +9 -11
- package/docs/layout.md +2 -4
- package/docs/rules/paper/allowed-files-only.md +1 -2
- package/docs/testing.md +1 -1
- package/eslint.config.mjs +1 -1
- package/lib/paper-config.harness.mjs +3 -6
- package/lib/paper-config.ts +4 -9
- package/lib/skill-eval-kit.mjs +0 -14
- package/package.json +2 -4
- package/plugin/hooks/hooks.json +0 -13
- package/scripts/coverage-config.test.ts +0 -2
- package/scripts/eslint-file-length.mjs +0 -1
- package/skills/argument-arc/scripts/headings.js +2 -2
- package/skills/build-label-page/scripts/label-page.js +125 -125
- package/skills/cold-read-diff/scripts/cold-read.js +11 -11
- package/skills/paper-pipeline/scripts/extract-ref-facts.js +3 -3
- package/skills/paper-status/SKILL.md +1 -2
- package/skills/paper-status/SKILL.md.spec.ts +0 -1
- package/skills/pc-panel-review/scripts/prior-reviews.js +1 -1
- package/skills/verify-citations/scripts/bib-authors.js +3 -3
- package/skills/verify-citations/scripts/verify-cites.js +3 -3
- package/src/CLAUDE.md +16 -1
- package/src/CLAUDE.md.spec.ts +12 -1
- package/src/cli.harness.mjs +14 -79
- package/src/cli.test.ts +4 -34
- package/src/cli.ts +47 -140
- package/src/doctor.harness.mjs +17 -59
- package/src/doctor.test.ts +1 -1
- package/src/doctor.ts +26 -41
- package/src/domain/paper-folder.test.ts +1 -1
- package/src/hooks-notice.test.ts +21 -74
- package/src/hooks-notice.ts +30 -20
- package/src/hooks-settings.harness.ts +25 -27
- package/src/hooks-settings.ts +1 -1
- package/src/in-process-hooks.test.ts +18 -0
- package/src/init.ts +5 -5
- package/src/lint-edited-site-example.test.ts +0 -3
- package/src/papers-roots.test.ts +56 -0
- package/src/papers-roots.ts +56 -0
- package/src/retired-hooks.test.ts +155 -0
- package/src/retired-hooks.ts +41 -0
- package/src/types.ts +1 -1
- package/dist/skill-chunks/chunk-GRSXIWYF.js +0 -352
- package/hooks/CLAUDE.md +0 -34
- package/hooks/CLAUDE.md.spec.ts +0 -30
- package/hooks/hooks.harness.ts +0 -566
- package/hooks/paper-edit-guard.hook.d.mts +0 -12
- package/hooks/paper-edit-guard.hook.mjs +0 -443
- package/hooks/paper-edit-guard.test.ts +0 -66
- package/hooks/paper-skills-nudge.hook.d.mts +0 -22
- package/hooks/paper-skills-nudge.hook.mjs +0 -193
- package/hooks/paper-skills-nudge.test.ts +0 -122
- package/lib/trigger-ledger.mjs +0 -215
package/src/hooks-notice.test.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { join } from "node:path";
|
|
|
12
12
|
import { test } from "vitest";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
import { useTempDir, writeTree } from "../test/support.ts";
|
|
15
|
-
import { run, runHook
|
|
15
|
+
import { run, runHook } from "./cli.ts";
|
|
16
16
|
import type { LinkReport } from "./link-skills.ts";
|
|
17
17
|
import {
|
|
18
18
|
NOTICE_STATE,
|
|
@@ -144,6 +144,19 @@ test("noticeText names the version and the hooks, as an instruction; mergeNotice
|
|
|
144
144
|
});
|
|
145
145
|
assert.equal(mergeNotice("not json", "N"), null);
|
|
146
146
|
assert.equal(mergeNotice("[1]", "N"), null);
|
|
147
|
+
const context = (said: unknown): unknown =>
|
|
148
|
+
Notice.parse(JSON.parse(mergeNotice(JSON.stringify(said), "N") ?? ""))
|
|
149
|
+
.hookSpecificOutput;
|
|
150
|
+
assert.deepEqual(
|
|
151
|
+
[
|
|
152
|
+
context({ hookSpecificOutput: { additionalContext: "A" } }),
|
|
153
|
+
context({ hookSpecificOutput: { additionalContext: "" } }),
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
{ hookEventName: "PostToolUse", additionalContext: "A\n\nN" },
|
|
157
|
+
{ hookEventName: "PostToolUse", additionalContext: "N" },
|
|
158
|
+
],
|
|
159
|
+
);
|
|
147
160
|
});
|
|
148
161
|
|
|
149
162
|
test("a wired hook on a paper file: missing hook → one notice, the same version again → silent, a new version → one more", async () => {
|
|
@@ -171,7 +184,7 @@ test("a wired hook on a paper file: missing hook → one notice, the same versio
|
|
|
171
184
|
});
|
|
172
185
|
|
|
173
186
|
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-
|
|
187
|
+
const dir = project("block", wiringWithout(["paper-folder-layout"]), true);
|
|
175
188
|
const said = await hook(
|
|
176
189
|
"lint-edited",
|
|
177
190
|
dir,
|
|
@@ -186,7 +199,7 @@ test("the notice rides on what the hook said: a block stays a block, and the exi
|
|
|
186
199
|
assert.match(parsed.reason, /tex\/max-sentence-words/);
|
|
187
200
|
assert.match(
|
|
188
201
|
Notice.parse(parsed).hookSpecificOutput.additionalContext,
|
|
189
|
-
/paper-
|
|
202
|
+
/paper-folder-layout/,
|
|
190
203
|
);
|
|
191
204
|
});
|
|
192
205
|
|
|
@@ -268,56 +281,6 @@ test("paperlint lint: one stderr line naming the missing hooks when partly wired
|
|
|
268
281
|
assert.equal(partly.code, wired.code);
|
|
269
282
|
});
|
|
270
283
|
|
|
271
|
-
test("a spawned PostToolUse hook: its stdout is captured and merged, its payload fed on stdin; outside a paper it is fed and left alone; a failing hook's output is passed through", () => {
|
|
272
|
-
const dir = project("spawned", wiringWithout(["lint-edited"]));
|
|
273
|
-
const payload = (file: string) =>
|
|
274
|
-
JSON.stringify({ tool_input: { file_path: file } });
|
|
275
|
-
const spawn = (file: string, status = 0, stdout = "") => {
|
|
276
|
-
const seen: unknown[] = [];
|
|
277
|
-
const out: string[] = [];
|
|
278
|
-
const code = runHook("paper-skills-nudge", {
|
|
279
|
-
stdin: () => payload(file),
|
|
280
|
-
out: (t) => {
|
|
281
|
-
out.push(t);
|
|
282
|
-
},
|
|
283
|
-
projectDir: dir,
|
|
284
|
-
claude: PLUGIN_OFF,
|
|
285
|
-
version: "9.9.9",
|
|
286
|
-
run: (_f, _a, o) => {
|
|
287
|
-
seen.push(o);
|
|
288
|
-
return { status, stdout };
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
return { code, seen, out: out.join("") };
|
|
292
|
-
};
|
|
293
|
-
const nudge = JSON.stringify({
|
|
294
|
-
hookSpecificOutput: {
|
|
295
|
-
hookEventName: "PostToolUse",
|
|
296
|
-
additionalContext: "nudge",
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
const outside = spawn(join(dir, "notes.txt"), 0, "");
|
|
300
|
-
assert.deepEqual(outside.seen, [
|
|
301
|
-
{
|
|
302
|
-
stdio: ["pipe", "inherit", "inherit"],
|
|
303
|
-
input: payload(join(dir, "notes.txt")),
|
|
304
|
-
encoding: "utf8",
|
|
305
|
-
},
|
|
306
|
-
]);
|
|
307
|
-
assert.equal(outside.out, "");
|
|
308
|
-
const failed = spawn(
|
|
309
|
-
join(dir, "papers/p/paper.tex"),
|
|
310
|
-
2,
|
|
311
|
-
"stdout of a refusal",
|
|
312
|
-
);
|
|
313
|
-
assert.deepEqual([failed.code, failed.out], [2, "stdout of a refusal"]);
|
|
314
|
-
const merged = spawn(join(dir, "papers/p/paper.tex"), 0, nudge);
|
|
315
|
-
const context = Notice.parse(JSON.parse(merged.out)).hookSpecificOutput
|
|
316
|
-
.additionalContext;
|
|
317
|
-
assert.match(context, /^nudge\n\n⚠ paperlint 9\.9\.9 .*lint-edited/s);
|
|
318
|
-
assert.equal(merged.code, 0);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
284
|
test("the notice machinery never fails a hook: an unwritable state file is one stderr line, no notice, the hook's own output intact", async () => {
|
|
322
285
|
const dir = project("state-blocked", wiringWithout(["lint-edited"]));
|
|
323
286
|
// `node_modules/.cache` as a FILE: the state cannot be written under it.
|
|
@@ -389,22 +352,6 @@ test("the check that cannot run, and a payload that cannot be read, leave the ho
|
|
|
389
352
|
assert.match(thrown.join("\n"), /did not run: EAGAIN/);
|
|
390
353
|
});
|
|
391
354
|
|
|
392
|
-
test("spawnHook: the real spawner, once with the terminal's streams and once piped with an input", () => {
|
|
393
|
-
const print = ["-e", "process.stdin.pipe(process.stdout)"];
|
|
394
|
-
assert.deepEqual(
|
|
395
|
-
spawnHook(process.execPath, ["-e", "0"], { stdio: "inherit" }),
|
|
396
|
-
{ status: 0, stdout: null },
|
|
397
|
-
);
|
|
398
|
-
assert.deepEqual(
|
|
399
|
-
spawnHook(process.execPath, print, {
|
|
400
|
-
stdio: ["pipe", "pipe", "inherit"],
|
|
401
|
-
input: "payload",
|
|
402
|
-
encoding: "utf8",
|
|
403
|
-
}),
|
|
404
|
-
{ status: 0, stdout: "payload" },
|
|
405
|
-
);
|
|
406
|
-
});
|
|
407
|
-
|
|
408
355
|
test("a state file that is garbage, or not an object, counts as not told: the notice speaks and rewrites it", async () => {
|
|
409
356
|
const state = (dir: string) => join(dir, NOTICE_STATE);
|
|
410
357
|
const told = (dir: string) =>
|
|
@@ -495,9 +442,9 @@ test("an upgrade that ships a skill the project never linked: the notice names i
|
|
|
495
442
|
});
|
|
496
443
|
|
|
497
444
|
test("a project missing a hook and a skill hears both in one notice; every skill linked, or no package to read, says nothing about skills", async () => {
|
|
498
|
-
const both = project("both", wiringWithout(["
|
|
445
|
+
const both = project("both", wiringWithout(["paper-folder-layout"]));
|
|
499
446
|
const said = await hook(
|
|
500
|
-
"
|
|
447
|
+
"lint-edited",
|
|
501
448
|
both,
|
|
502
449
|
join(both, "papers/p/paper.tex"),
|
|
503
450
|
"Fine.",
|
|
@@ -506,7 +453,7 @@ test("a project missing a hook and a skill hears both in one notice; every skill
|
|
|
506
453
|
);
|
|
507
454
|
const text = Notice.parse(JSON.parse(said.out)).hookSpecificOutput
|
|
508
455
|
.additionalContext;
|
|
509
|
-
assert.match(text, /
|
|
456
|
+
assert.match(text, /paper-folder-layout/);
|
|
510
457
|
assert.match(text, /rewrite-unclear/);
|
|
511
458
|
const whole = project("skills-whole", wiringWithout([]));
|
|
512
459
|
const file = join(whole, "papers/p/paper.tex");
|
|
@@ -567,11 +514,11 @@ test("lintLine and noticeText word skills beside hooks", () => {
|
|
|
567
514
|
/hook lint-edited is not wired; skills a, b are not linked/,
|
|
568
515
|
);
|
|
569
516
|
assert.match(
|
|
570
|
-
noticeText("9.9.9", ["lint-edited"], true, ["a"]),
|
|
517
|
+
noticeText("9.9.9", ["lint-edited"], true, { skills: ["a"] }),
|
|
571
518
|
/by hand.*\(init does link the skills\)/,
|
|
572
519
|
);
|
|
573
520
|
assert.match(
|
|
574
|
-
noticeText("9.9.9", [], false, ["a"]),
|
|
521
|
+
noticeText("9.9.9", [], false, { skills: ["a"] }),
|
|
575
522
|
/skills that are not linked into \.claude\/skills\/: a\./,
|
|
576
523
|
);
|
|
577
524
|
});
|
package/src/hooks-notice.ts
CHANGED
|
@@ -27,20 +27,16 @@ import { SKILLS_HOME } from "./link-skills.ts";
|
|
|
27
27
|
import type { Files } from "./ports/files.ts";
|
|
28
28
|
|
|
29
29
|
/** The hooks that may carry the notice: PostToolUse ones. A PreToolUse hook never does. */
|
|
30
|
-
export const NOTICE_HOOKS: readonly string[] = [
|
|
31
|
-
"lint-edited",
|
|
32
|
-
"paper-skills-nudge",
|
|
33
|
-
];
|
|
30
|
+
export const NOTICE_HOOKS: readonly string[] = ["lint-edited"];
|
|
34
31
|
|
|
35
32
|
/** 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
33
|
export const hookNotRunningText = (
|
|
37
34
|
name: string | undefined,
|
|
38
|
-
program: string,
|
|
39
35
|
version: string,
|
|
40
36
|
): string =>
|
|
41
37
|
name === undefined || name === ""
|
|
42
|
-
? "paperlint: `hook` needs a name, e.g. `paperlint hook
|
|
43
|
-
: `paperlint: unknown hook \`${name}\` — no such
|
|
38
|
+
? "paperlint: `hook` needs a name, e.g. `paperlint hook lint-edited`; no hook is running."
|
|
39
|
+
: `paperlint: unknown hook \`${name}\` — this paperlint has no such hook; it is NOT running (installed: paperlint ${version}). Run \`npm install\`, or remove \`paperlint hook ${name}\` from .claude/settings.json.`;
|
|
44
40
|
|
|
45
41
|
/** Where the version last told is kept, relative to the project root. */
|
|
46
42
|
export const NOTICE_STATE = join(
|
|
@@ -52,25 +48,39 @@ export const NOTICE_STATE = join(
|
|
|
52
48
|
|
|
53
49
|
const SKILLS_HOME_SHOWN = `${SKILLS_HOME}/`;
|
|
54
50
|
|
|
51
|
+
/** One clause of the notice: the names after their sentence, or nothing when there are none. */
|
|
52
|
+
const clause = (names: readonly string[], says: string): readonly string[] =>
|
|
53
|
+
names.length === 0 ? [] : [`${says}: ${names.join(", ")}`];
|
|
54
|
+
|
|
55
|
+
/** What the project owes besides the missing hooks; the notice names each that is not empty. */
|
|
56
|
+
interface Owed {
|
|
57
|
+
readonly skills?: readonly string[];
|
|
58
|
+
readonly retired?: readonly string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The clauses the notice joins: missing hooks, unlinked skills, retired hooks still wired. */
|
|
62
|
+
const owedClauses = (missing: readonly string[], owed: Owed): string =>
|
|
63
|
+
[
|
|
64
|
+
...clause(missing, "expects hooks that this project has not wired"),
|
|
65
|
+
...clause(
|
|
66
|
+
owed.skills ?? [],
|
|
67
|
+
`ships skills that are not linked into ${SKILLS_HOME_SHOWN}`,
|
|
68
|
+
),
|
|
69
|
+
...clause(
|
|
70
|
+
owed.retired ?? [],
|
|
71
|
+
"no longer ships hooks this project still wires, which now run nothing",
|
|
72
|
+
),
|
|
73
|
+
].join(", and ");
|
|
74
|
+
|
|
55
75
|
/** The instruction the agent reads. `byHand`: `init` writes no hooks then, so the remedy differs. */
|
|
56
76
|
export const noticeText = (
|
|
57
77
|
version: string,
|
|
58
78
|
missing: readonly string[],
|
|
59
79
|
byHand: boolean,
|
|
60
|
-
|
|
80
|
+
owed: Owed = {},
|
|
61
81
|
): string => {
|
|
62
|
-
const what =
|
|
63
|
-
|
|
64
|
-
? []
|
|
65
|
-
: [
|
|
66
|
-
`expects hooks that this project has not wired: ${missing.join(", ")}`,
|
|
67
|
-
]),
|
|
68
|
-
...(skills.length === 0
|
|
69
|
-
? []
|
|
70
|
-
: [
|
|
71
|
-
`ships skills that are not linked into ${SKILLS_HOME_SHOWN}: ${skills.join(", ")}`,
|
|
72
|
-
]),
|
|
73
|
-
].join(", and ");
|
|
82
|
+
const what = owedClauses(missing, owed);
|
|
83
|
+
const skills = owed.skills ?? [];
|
|
74
84
|
const handHooks = byHand && missing.length > 0;
|
|
75
85
|
return (
|
|
76
86
|
`⚠ paperlint ${version} ${what}. ` +
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* What each block defends against, in real life:
|
|
9
9
|
* - a SECOND copy of a hook wired by hand under another spelling: Claude Code dedupes only
|
|
10
|
-
* identical handlers, so the
|
|
10
|
+
* identical handlers, so the hook would run twice and nothing would say so;
|
|
11
11
|
* - a rewrite on every `init`: the settings file is committed, so churn is a diff someone reviews
|
|
12
12
|
* for nothing — and a reformat of the user's own file is a change they did not ask for;
|
|
13
13
|
* - a doctor that says "wired" over nothing, or offers a remedy `init` then refuses to apply.
|
|
@@ -65,9 +65,8 @@ 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 —
|
|
69
|
-
wiring.names.join() ===
|
|
70
|
-
"paper-edit-guard,submission-confirm,paper-folder-layout,paper-skills-nudge,lint-edited",
|
|
68
|
+
"the hook names are DERIVED from hooks.json — three, in its order",
|
|
69
|
+
wiring.names.join() === "submission-confirm,paper-folder-layout,lint-edited",
|
|
71
70
|
);
|
|
72
71
|
// ── settings written by hand: shapes Claude Code would ignore are skipped, not crashed on ──
|
|
73
72
|
check(
|
|
@@ -76,7 +75,7 @@ check(
|
|
|
76
75
|
wiredCounts(
|
|
77
76
|
{
|
|
78
77
|
hooks: {
|
|
79
|
-
PreToolUse: "npx paperlint hook
|
|
78
|
+
PreToolUse: "npx paperlint hook submission-confirm",
|
|
80
79
|
PostToolUse: [{ matcher: "Edit" }, null, { hooks: "x" }],
|
|
81
80
|
Stop: [{ hooks: [{ type: "command" }, null] }],
|
|
82
81
|
},
|
|
@@ -136,28 +135,28 @@ try {
|
|
|
136
135
|
);
|
|
137
136
|
|
|
138
137
|
// ── which spelling runs which hook ─────────────────────────────────────────────────────
|
|
139
|
-
const ours = `node "\${CLAUDE_PROJECT_DIR}/${MANAGED_BY}" hook
|
|
138
|
+
const ours = `node "\${CLAUDE_PROJECT_DIR}/${MANAGED_BY}" hook submission-confirm`;
|
|
140
139
|
const cases: [string, { name: string; ours: boolean } | null][] = [
|
|
141
|
-
[ours, { name: "
|
|
140
|
+
[ours, { name: "submission-confirm", ours: true }],
|
|
142
141
|
[
|
|
143
142
|
`node "$CLAUDE_PROJECT_DIR/${MANAGED_BY}" hook lint-edited`,
|
|
144
143
|
{ name: "lint-edited", ours: true },
|
|
145
144
|
],
|
|
146
145
|
[
|
|
147
|
-
`node "$CLAUDE_PROJECT_DIR/node_modules/vigiles/dist/cli.js" hook-runtime run-program "$CLAUDE_PROJECT_DIR/node_modules/paperlint/hooks/
|
|
148
|
-
{ name: "
|
|
146
|
+
`node "$CLAUDE_PROJECT_DIR/node_modules/vigiles/dist/cli.js" hook-runtime run-program "$CLAUDE_PROJECT_DIR/node_modules/paperlint/hooks/submission-confirm.hook.mjs"`,
|
|
147
|
+
{ name: "submission-confirm", ours: false },
|
|
149
148
|
],
|
|
150
149
|
[
|
|
151
|
-
`npx paperlint hook paper-
|
|
152
|
-
{ name: "paper-
|
|
150
|
+
`npx paperlint hook paper-folder-layout`,
|
|
151
|
+
{ name: "paper-folder-layout", ours: false },
|
|
153
152
|
],
|
|
154
153
|
[
|
|
155
|
-
`npx paperlint hook paper-
|
|
156
|
-
{ name: "paper-
|
|
154
|
+
`npx paperlint hook paper-folder-layout`,
|
|
155
|
+
{ name: "paper-folder-layout", ours: false },
|
|
157
156
|
],
|
|
158
157
|
[
|
|
159
|
-
`node /abs/proj/node_modules/paperlint/bin/paperlint.mjs hook
|
|
160
|
-
{ name: "
|
|
158
|
+
`node /abs/proj/node_modules/paperlint/bin/paperlint.mjs hook submission-confirm`,
|
|
159
|
+
{ name: "submission-confirm", ours: false },
|
|
161
160
|
],
|
|
162
161
|
[`node my-own-lint.mjs`, null],
|
|
163
162
|
[`node node_modules/paperlint/bin/paperlint.mjs lint`, null],
|
|
@@ -260,7 +259,7 @@ try {
|
|
|
260
259
|
{
|
|
261
260
|
type: "command",
|
|
262
261
|
command:
|
|
263
|
-
'node "$CLAUDE_PROJECT_DIR/node_modules/vigiles/dist/cli.js" hook-runtime run-program "$CLAUDE_PROJECT_DIR/node_modules/paperlint/hooks/
|
|
262
|
+
'node "$CLAUDE_PROJECT_DIR/node_modules/vigiles/dist/cli.js" hook-runtime run-program "$CLAUDE_PROJECT_DIR/node_modules/paperlint/hooks/submission-confirm.hook.mjs"',
|
|
264
263
|
},
|
|
265
264
|
],
|
|
266
265
|
},
|
|
@@ -278,22 +277,21 @@ try {
|
|
|
278
277
|
"the report names the hook and the command it found",
|
|
279
278
|
r.status === "foreign" &&
|
|
280
279
|
r.found.length === 1 &&
|
|
281
|
-
r.found[0]?.name === "
|
|
280
|
+
r.found[0]?.name === "submission-confirm",
|
|
282
281
|
);
|
|
283
282
|
check(
|
|
284
283
|
"and names the hooks that are not wired in ANY form",
|
|
285
284
|
r.status === "foreign" &&
|
|
286
|
-
r.missing.join() ===
|
|
287
|
-
"submission-confirm,paper-folder-layout,paper-skills-nudge,lint-edited",
|
|
285
|
+
r.missing.join() === "paper-folder-layout,lint-edited",
|
|
288
286
|
);
|
|
289
287
|
// The control: without the check, vigiles' merge WOULD add a second copy. This is the
|
|
290
288
|
// reason the check exists, measured rather than asserted.
|
|
291
289
|
const merged = merge(handWired, wiring.compiled, MANAGED_BY);
|
|
292
290
|
const c = wiredCounts(merged, wiring.names).find(
|
|
293
|
-
(c) => c.name === "
|
|
291
|
+
(c) => c.name === "submission-confirm",
|
|
294
292
|
);
|
|
295
293
|
check(
|
|
296
|
-
"(control) vigiles' merge alone would wire
|
|
294
|
+
"(control) vigiles' merge alone would wire submission-confirm TWICE here",
|
|
297
295
|
c?.ours === 1 && c.other === 1,
|
|
298
296
|
);
|
|
299
297
|
}
|
|
@@ -320,24 +318,24 @@ try {
|
|
|
320
318
|
const wiredOnce = merge({}, wiring.compiled, MANAGED_BY);
|
|
321
319
|
check(
|
|
322
320
|
"wired once each → ✓ wired, with the fresh-clone consequence",
|
|
323
|
-
/✓ wired —
|
|
321
|
+
/✓ wired — submission-confirm, paper-folder-layout, lint-edited, once each/.test(
|
|
324
322
|
doc(wiredOnce),
|
|
325
323
|
) && /cannot run until `npm install`/.test(doc(wiredOnce)),
|
|
326
324
|
);
|
|
327
325
|
check(
|
|
328
326
|
"nothing wired → ⚠ not wired, with the remedy",
|
|
329
|
-
/⚠ not wired — none of the
|
|
327
|
+
/⚠ not wired — none of the 3 hooks/.test(doc({})),
|
|
330
328
|
);
|
|
331
329
|
const twice = PreToolUseSettings.parse(structuredClone(wiredOnce));
|
|
332
330
|
twice.hooks.PreToolUse[0]?.hooks.push({
|
|
333
331
|
type: "command",
|
|
334
|
-
command: "npx paperlint hook
|
|
332
|
+
command: "npx paperlint hook submission-confirm",
|
|
335
333
|
});
|
|
336
334
|
const twiceText = doc(twice);
|
|
337
335
|
check(
|
|
338
336
|
"🔴 the same hook under two spellings → ⚠ wired TWICE, naming it with its count",
|
|
339
337
|
/wired TWICE/.test(twiceText) &&
|
|
340
|
-
/
|
|
338
|
+
/submission-confirm ×2/.test(twiceText) &&
|
|
341
339
|
!/✓ wired/.test(twiceText),
|
|
342
340
|
);
|
|
343
341
|
const handPartial = doc({
|
|
@@ -346,7 +344,7 @@ try {
|
|
|
346
344
|
{
|
|
347
345
|
matcher: "Bash",
|
|
348
346
|
hooks: [
|
|
349
|
-
{ type: "command", command: "npx paperlint hook
|
|
347
|
+
{ type: "command", command: "npx paperlint hook lint-edited" },
|
|
350
348
|
],
|
|
351
349
|
},
|
|
352
350
|
],
|
|
@@ -354,7 +352,7 @@ try {
|
|
|
354
352
|
});
|
|
355
353
|
check(
|
|
356
354
|
"🔴 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
|
|
355
|
+
/partly wired — missing: submission-confirm, paper-folder-layout/.test(
|
|
358
356
|
handPartial,
|
|
359
357
|
) && /writes nothing then/.test(handPartial),
|
|
360
358
|
);
|
package/src/hooks-settings.ts
CHANGED
|
@@ -289,7 +289,7 @@ export type WireResult =
|
|
|
289
289
|
* 🔴 ANOTHER SPELLING OF THE SAME HOOK STOPS THE WRITE. vigiles' merge owns only commands whose
|
|
290
290
|
* path token is MANAGED_BY; a hook wired by hand through `vigiles … run-program …/hooks/x.hook.mjs`
|
|
291
291
|
* is not recognised as ours, so a merge would ADD a second copy — and Claude Code dedupes only
|
|
292
|
-
* identical handlers, so the
|
|
292
|
+
* identical handlers, so the hook would run twice. Writing nothing and saying so is the only
|
|
293
293
|
* answer that cannot make it worse.
|
|
294
294
|
*/
|
|
295
295
|
export function wireHooks(
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-process hook table may only shrink. It is a workaround for zernie/vigiles#472 (a hook
|
|
3
|
+
* program cannot use its own package's code); the way out is zernie/paperlint#650, not one more
|
|
4
|
+
* entry. A hook that needs this package's code waits for vigiles#472 instead.
|
|
5
|
+
*/
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { test } from "vitest";
|
|
8
|
+
import { IN_PROCESS_HOOK_NAMES } from "./cli.ts";
|
|
9
|
+
|
|
10
|
+
/** The entries that existed when the table was frozen (2026-11-23). Remove a name; never add one. */
|
|
11
|
+
const FROZEN = ["lint-edited", "paper-folder-layout", "submission-confirm"];
|
|
12
|
+
|
|
13
|
+
test("no hook is added to IN_PROCESS_HOOKS: fix zernie/vigiles#472 and extract (#650) instead", () => {
|
|
14
|
+
assert.deepEqual(
|
|
15
|
+
IN_PROCESS_HOOK_NAMES.filter((name) => !FROZEN.includes(name)),
|
|
16
|
+
[],
|
|
17
|
+
);
|
|
18
|
+
});
|
package/src/init.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 🔴 THE HOOKS, THE RULES AND THE CLI READ THE PAPERS DIRECTORY FROM ONE PLACE — the root
|
|
5
5
|
* `paperlint.json`, or its default `papers` when the file is absent. An install that wrote it
|
|
6
|
-
* anywhere else would give
|
|
7
|
-
*
|
|
6
|
+
* anywhere else would give hooks watching a directory that does not exist — and a
|
|
7
|
+
* hook watching nothing is byte-identical, from outside, to a hook that is working (issue #33).
|
|
8
8
|
*
|
|
9
9
|
* The yardstick is how many actions happen between "I want this" and "it works": two, `npm i` and
|
|
10
10
|
* this command (`docs/install.md`). Nothing is left to edit by hand.
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* only place Claude Code looks for project skills (`link-skills.ts`). An
|
|
20
20
|
* entry of the same name that paperlint did not make is reported, never replaced.
|
|
21
21
|
* hooks WRITTEN into `.claude/settings.json` by vigiles' merge (`hooks-settings.ts`);
|
|
22
|
-
* asked of a human (Yes preselected), YES without one —
|
|
23
|
-
* for, and the edit is idempotent and visible in `git diff`. `--no-hooks` skips.
|
|
22
|
+
* asked of a human (Yes preselected), YES without one — checking an agent's edits is what the package
|
|
23
|
+
* is for, and the edit is idempotent and visible in `git diff`. `--no-hooks` skips.
|
|
24
24
|
* CI workflow ASKED, because writing a file into `.github/` is not guessable and not
|
|
25
25
|
* cheap to undo. Prior art: Playwright's initializer asks exactly this.
|
|
26
26
|
* Without a human: NO.
|
|
@@ -442,7 +442,7 @@ export type HooksOutcome =
|
|
|
442
442
|
|
|
443
443
|
/**
|
|
444
444
|
* The hooks step: decide, then wire. `hooks: false` is `--no-hooks`. The default without a human
|
|
445
|
-
* is YES — installing a package whose purpose includes an
|
|
445
|
+
* is YES — installing a package whose purpose includes checking an agent's edits makes "yes" guessable, and
|
|
446
446
|
* the edit is idempotent and shows up in `git diff` (the rule `docs/install.md` took from
|
|
447
447
|
* Playwright: ask only about what cannot be guessed or is expensive).
|
|
448
448
|
*/
|
|
@@ -66,9 +66,6 @@ async function hookOn(file: string, newString: string): Promise<string> {
|
|
|
66
66
|
err: (m: string) => {
|
|
67
67
|
throw new Error(`the hook complained: ${m}`);
|
|
68
68
|
},
|
|
69
|
-
run: () => {
|
|
70
|
-
throw new Error("an in-process hook spawns nothing");
|
|
71
|
-
},
|
|
72
69
|
});
|
|
73
70
|
assert.equal(code, 0);
|
|
74
71
|
return out.join("");
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one reader of `papersDir`: every spelling a project root resolves the same way is the same
|
|
3
|
+
* directory, a list is several, and a path is placed among them by segments, not by its spelling.
|
|
4
|
+
*/
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { test } from "vitest";
|
|
7
|
+
import { papersRoots, segmentsUnder, toPaths } from "./papers-roots.ts";
|
|
8
|
+
|
|
9
|
+
test("a papers directory given as a string or as a list normalises to a list; anything else to none", () => {
|
|
10
|
+
assert.deepEqual(
|
|
11
|
+
[
|
|
12
|
+
toPaths(" papers "),
|
|
13
|
+
toPaths(["a", "", 3, "b"]),
|
|
14
|
+
toPaths(undefined),
|
|
15
|
+
toPaths(" "),
|
|
16
|
+
toPaths(null),
|
|
17
|
+
],
|
|
18
|
+
[["papers"], ["a", "b"], [], [], []],
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("every spelling that resolves to the same directory is the same absolute directory; none means the default", () => {
|
|
23
|
+
const roots = (papersDir?: unknown) =>
|
|
24
|
+
papersRoots({ opts: { papersDir }, root: "/p" });
|
|
25
|
+
assert.deepEqual(
|
|
26
|
+
[
|
|
27
|
+
roots("./papers"),
|
|
28
|
+
roots(".//papers//"),
|
|
29
|
+
roots("x/../papers"),
|
|
30
|
+
roots(),
|
|
31
|
+
roots(["a", "/abs"]),
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
["/p/papers"],
|
|
35
|
+
["/p/papers"],
|
|
36
|
+
["/p/papers"],
|
|
37
|
+
["/p/papers"],
|
|
38
|
+
["/p/a", "/abs"],
|
|
39
|
+
],
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a path is placed under the first directory that holds it, by its segments", () => {
|
|
44
|
+
const roots = ["/p/a", "/p/papers"];
|
|
45
|
+
assert.deepEqual(
|
|
46
|
+
[
|
|
47
|
+
segmentsUnder("/p/papers/x/paper.tex", roots),
|
|
48
|
+
segmentsUnder("/p/a/y", roots),
|
|
49
|
+
segmentsUnder("/p/papers", roots),
|
|
50
|
+
segmentsUnder("/p/papers-old/x", roots),
|
|
51
|
+
segmentsUnder("/elsewhere/papers/x", roots),
|
|
52
|
+
segmentsUnder("/p/papers/..draft/paper.tex", roots),
|
|
53
|
+
],
|
|
54
|
+
[["x", "paper.tex"], ["y"], null, null, null, ["..draft", "paper.tex"]],
|
|
55
|
+
);
|
|
56
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the project's papers are, and where a path sits among them: the one reader of the
|
|
3
|
+
* `papersDir` setting, for `paperlint lint` and for the hooks that ask which paper a write lands in.
|
|
4
|
+
*
|
|
5
|
+
* ── WHY ONE MODULE ───────────────────────────────────────────────────────────────
|
|
6
|
+
* The hooks shipped as standalone programs could import nothing but `vigiles/hook`, so each read the
|
|
7
|
+
* setting again and tidied its spelling with regular expressions; `"./papers"`, `"x/../papers"` and a
|
|
8
|
+
* list of directories each slipped past a different copy (#326). Here the setting is read once, every
|
|
9
|
+
* directory is made absolute with `path.resolve`, and a path is placed by `path.relative`, so every
|
|
10
|
+
* spelling the project root resolves the same way is the same directory, by construction.
|
|
11
|
+
*/
|
|
12
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
13
|
+
import { DEFAULT_PAPERS_ROOT } from "#lib/paper-config";
|
|
14
|
+
|
|
15
|
+
/** The papers directory field of the settings, read by its one declared name; the default when absent. */
|
|
16
|
+
export function papersDirOf(opts: { readonly papersDir?: unknown }): unknown {
|
|
17
|
+
const declared = opts.papersDir;
|
|
18
|
+
return declared === undefined ? DEFAULT_PAPERS_ROOT : declared;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The papers directory may be one directory or several; both spellings normalise to a list. */
|
|
22
|
+
export function toPaths(papers: unknown): readonly string[] {
|
|
23
|
+
if (typeof papers === "string") return papers.trim() ? [papers.trim()] : [];
|
|
24
|
+
if (Array.isArray(papers))
|
|
25
|
+
return papers.filter(
|
|
26
|
+
(x): x is string => typeof x === "string" && x.trim() !== "",
|
|
27
|
+
);
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The papers directories of a read config, absolute: each relative to the project root. */
|
|
32
|
+
export const papersRoots = (cfg: {
|
|
33
|
+
readonly opts: { readonly papersDir?: unknown };
|
|
34
|
+
readonly root: string;
|
|
35
|
+
}): readonly string[] =>
|
|
36
|
+
toPaths(papersDirOf(cfg.opts)).map((rel) => resolve(cfg.root, rel));
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The segments of `file` below the first of `roots` that holds it, the paper's folder first; null
|
|
40
|
+
* when it is under none of them. `file` must be absolute; so must the roots (`papersRoots`).
|
|
41
|
+
*/
|
|
42
|
+
export function segmentsUnder(
|
|
43
|
+
file: string,
|
|
44
|
+
roots: readonly string[],
|
|
45
|
+
): readonly string[] | null {
|
|
46
|
+
const below = roots
|
|
47
|
+
.map((root) => relative(root, file))
|
|
48
|
+
.find(
|
|
49
|
+
(rel) =>
|
|
50
|
+
rel !== "" &&
|
|
51
|
+
rel !== ".." &&
|
|
52
|
+
!rel.startsWith(`..${sep}`) &&
|
|
53
|
+
!isAbsolute(rel),
|
|
54
|
+
);
|
|
55
|
+
return below === undefined ? null : below.split(sep);
|
|
56
|
+
}
|