paperlint 18.6.0 → 18.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/.claude-plugin/marketplace.json +11 -0
  2. package/.claude-plugin/plugin.json +7 -0
  3. package/CLAUDE.md +3 -3
  4. package/CONTRIBUTING.md +5 -2
  5. package/README.md +6 -6
  6. package/dist/adapters/clack/index.d.ts +3 -0
  7. package/dist/adapters/clack/index.d.ts.map +1 -0
  8. package/dist/adapters/clack/index.js +3 -0
  9. package/dist/adapters/clack/index.js.map +1 -0
  10. package/dist/adapters/clack/prompts.io.d.ts +8 -0
  11. package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
  12. package/dist/adapters/clack/prompts.io.js +20 -0
  13. package/dist/adapters/clack/prompts.io.js.map +1 -0
  14. package/dist/adapters/claude-code/claude.io.d.ts +13 -0
  15. package/dist/adapters/claude-code/claude.io.d.ts.map +1 -0
  16. package/dist/adapters/claude-code/claude.io.js +68 -0
  17. package/dist/adapters/claude-code/claude.io.js.map +1 -0
  18. package/dist/adapters/claude-code/index.d.ts +4 -0
  19. package/dist/adapters/claude-code/index.d.ts.map +1 -0
  20. package/dist/adapters/claude-code/index.js +4 -0
  21. package/dist/adapters/claude-code/index.js.map +1 -0
  22. package/dist/adapters/claude-code/plugin.d.ts +19 -0
  23. package/dist/adapters/claude-code/plugin.d.ts.map +1 -0
  24. package/dist/adapters/claude-code/plugin.js +66 -0
  25. package/dist/adapters/claude-code/plugin.js.map +1 -0
  26. package/dist/adapters/package-manager/index.d.ts +4 -0
  27. package/dist/adapters/package-manager/index.d.ts.map +1 -0
  28. package/dist/adapters/package-manager/index.js +4 -0
  29. package/dist/adapters/package-manager/index.js.map +1 -0
  30. package/dist/adapters/package-manager/install.io.d.ts +3 -0
  31. package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
  32. package/dist/adapters/package-manager/install.io.js +23 -0
  33. package/dist/adapters/package-manager/install.io.js.map +1 -0
  34. package/dist/adapters/package-manager/manager.d.ts +13 -0
  35. package/dist/adapters/package-manager/manager.d.ts.map +1 -0
  36. package/dist/adapters/package-manager/manager.js +22 -0
  37. package/dist/adapters/package-manager/manager.js.map +1 -0
  38. package/dist/adapters/study-registry/index.d.ts +2 -2
  39. package/dist/cli.d.ts +9 -1
  40. package/dist/cli.d.ts.map +1 -1
  41. package/dist/cli.js +73 -13
  42. package/dist/cli.js.map +1 -1
  43. package/dist/doctor-plugin.d.ts +23 -0
  44. package/dist/doctor-plugin.d.ts.map +1 -0
  45. package/dist/doctor-plugin.js +56 -0
  46. package/dist/doctor-plugin.js.map +1 -0
  47. package/dist/doctor.d.ts +6 -1
  48. package/dist/doctor.d.ts.map +1 -1
  49. package/dist/doctor.js +69 -26
  50. package/dist/doctor.js.map +1 -1
  51. package/dist/hooks-settings.d.ts +18 -0
  52. package/dist/hooks-settings.d.ts.map +1 -1
  53. package/dist/hooks-settings.js +25 -0
  54. package/dist/hooks-settings.js.map +1 -1
  55. package/dist/init.d.ts +47 -16
  56. package/dist/init.d.ts.map +1 -1
  57. package/dist/init.js +231 -86
  58. package/dist/init.js.map +1 -1
  59. package/dist/link-skills.d.ts +15 -0
  60. package/dist/link-skills.d.ts.map +1 -1
  61. package/dist/link-skills.js +18 -1
  62. package/dist/link-skills.js.map +1 -1
  63. package/dist/plugin-offer.d.ts +73 -0
  64. package/dist/plugin-offer.d.ts.map +1 -0
  65. package/dist/plugin-offer.js +96 -0
  66. package/dist/plugin-offer.js.map +1 -0
  67. package/dist/ports/claude-code.d.ts +31 -0
  68. package/dist/ports/claude-code.d.ts.map +1 -0
  69. package/dist/ports/claude-code.js +2 -0
  70. package/dist/ports/claude-code.js.map +1 -0
  71. package/dist/ports/project-install.d.ts +19 -0
  72. package/dist/ports/project-install.d.ts.map +1 -0
  73. package/dist/ports/project-install.js +2 -0
  74. package/dist/ports/project-install.js.map +1 -0
  75. package/dist/ports/prompts.d.ts +31 -0
  76. package/dist/ports/prompts.d.ts.map +1 -0
  77. package/dist/ports/prompts.js +2 -0
  78. package/dist/ports/prompts.js.map +1 -0
  79. package/dist/self-install.d.ts +65 -0
  80. package/dist/self-install.d.ts.map +1 -0
  81. package/dist/self-install.js +145 -0
  82. package/dist/self-install.js.map +1 -0
  83. package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
  84. package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
  85. package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
  86. package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
  87. package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
  88. package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
  89. package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
  90. package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
  91. package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
  92. package/dist/types.d.ts +4 -0
  93. package/dist/types.d.ts.map +1 -1
  94. package/docs/e2e.md +10 -0
  95. package/docs/install.md +88 -29
  96. package/docs/prior-art/README.md +2 -0
  97. package/docs/prior-art/one-command-install.md +33 -0
  98. package/docs/prior-art/prompt-libraries.md +32 -0
  99. package/eslint.config.mjs +1 -0
  100. package/hooks/CLAUDE.md +2 -2
  101. package/hooks/CLAUDE.md.spec.ts +1 -1
  102. package/lib/skill-checks.mjs +13 -6
  103. package/lib/skill-checks.test.mjs +28 -15
  104. package/lib/skill-corpus.mjs +5 -2
  105. package/package.json +8 -3
  106. package/plugin/CLAUDE.md +22 -14
  107. package/plugin/CLAUDE.md.spec.ts +20 -12
  108. package/scripts/bundle-skills.test.ts +226 -0
  109. package/scripts/bundle-skills.ts +304 -0
  110. package/scripts/plugin-version.test.ts +80 -0
  111. package/scripts/plugin-version.ts +58 -0
  112. package/skills/CLAUDE.md +2 -2
  113. package/skills/CLAUDE.md.spec.ts +1 -1
  114. package/skills/argument-arc/SKILL.md +2 -2
  115. package/skills/argument-arc/SKILL.md.spec.ts +1 -1
  116. package/skills/argument-arc/scripts/headings.js +57 -13
  117. package/skills/build-label-page/scripts/label-page.js +2005 -93
  118. package/skills/cold-read-diff/scripts/cold-read.js +221 -14
  119. package/skills/label-agent-runs/scripts/labels.js +272 -348
  120. package/skills/paper-pipeline/references/anonymization.md +4 -3
  121. package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
  122. package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
  123. package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
  124. package/skills/submit-paper/SKILL.md +5 -4
  125. package/skills/submit-paper/SKILL.md.spec.ts +4 -3
  126. package/skills/submit-paper/check-deanon.sh +17 -2
  127. package/skills/submit-paper/check-deanon.test.ts +141 -0
  128. package/skills/verify-citations/SKILL.md +9 -9
  129. package/skills/verify-citations/SKILL.md.spec.ts +8 -8
  130. package/skills/verify-citations/scripts/bib-authors.js +228 -0
  131. package/skills/verify-citations/scripts/verify-cites.js +816 -0
  132. package/src/adapters/clack/index.ts +2 -0
  133. package/src/adapters/clack/prompts.io.ts +35 -0
  134. package/src/adapters/clack/prompts.test.ts +58 -0
  135. package/src/adapters/claude-code/claude.io.ts +103 -0
  136. package/src/adapters/claude-code/index.test.ts +233 -0
  137. package/src/adapters/claude-code/index.ts +11 -0
  138. package/src/adapters/claude-code/plugin.ts +82 -0
  139. package/src/adapters/package-manager/index.test.ts +67 -0
  140. package/src/adapters/package-manager/index.ts +3 -0
  141. package/src/adapters/package-manager/install.io.ts +27 -0
  142. package/src/adapters/package-manager/manager.ts +33 -0
  143. package/src/cli.harness.mjs +47 -26
  144. package/src/cli.test.ts +179 -2
  145. package/src/cli.ts +130 -10
  146. package/src/doctor-plugin.test.ts +103 -0
  147. package/src/doctor-plugin.ts +83 -0
  148. package/src/doctor.test.ts +111 -2
  149. package/src/doctor.ts +83 -32
  150. package/src/hooks-notice.test.ts +82 -0
  151. package/src/hooks-settings.ts +49 -0
  152. package/src/init-plugin.test.ts +178 -0
  153. package/src/init.test.ts +138 -27
  154. package/src/init.ts +341 -124
  155. package/src/link-skills.test.ts +34 -1
  156. package/src/link-skills.ts +34 -0
  157. package/src/parse-args.test.ts +2 -0
  158. package/src/plugin-offer.test.ts +276 -0
  159. package/src/plugin-offer.ts +160 -0
  160. package/src/ports/claude-code.ts +30 -0
  161. package/src/ports/project-install.ts +18 -0
  162. package/src/ports/prompts.ts +27 -0
  163. package/src/self-install.test.ts +267 -0
  164. package/src/self-install.ts +224 -0
  165. package/src/types.ts +4 -0
@@ -0,0 +1,103 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ compareVersions,
4
+ PLUGIN_UPDATE,
5
+ pluginLines,
6
+ type PluginFacts,
7
+ } from "./doctor-plugin.ts";
8
+
9
+ const HEAD = "Claude Code plugin (carries the skills and the hooks)";
10
+ const facts = (over: Partial<PluginFacts> = {}): PluginFacts => ({
11
+ state: { enabled: true, version: "1.2.0" },
12
+ installed: "1.2.0",
13
+ oldLinks: [],
14
+ oldHooks: [],
15
+ ...over,
16
+ });
17
+
18
+ describe("compareVersions", () => {
19
+ it("orders by the dotted numbers, missing parts as 0, a pre-release tag ignored", () => {
20
+ expect([
21
+ compareVersions("1.2.0", "1.2.0"),
22
+ compareVersions("1.2.0", "1.10.0"),
23
+ compareVersions("2.0", "1.9.9"),
24
+ compareVersions("1.2.0-beta.1", "1.2"),
25
+ compareVersions("x", "0.0.0"),
26
+ ]).toEqual([0, -1, 1, 0, 0]);
27
+ });
28
+ });
29
+
30
+ describe("pluginLines — declared, not installed", () => {
31
+ it("declared but not installed: one line, and init's links are not called doubled — nothing loads the plugin", () => {
32
+ expect(
33
+ pluginLines(
34
+ facts({
35
+ state: { enabled: true, version: null },
36
+ oldLinks: ["a"],
37
+ oldHooks: ["h"],
38
+ }),
39
+ ),
40
+ ).toEqual([
41
+ HEAD,
42
+ " · declared in the settings, not installed — the skills and hooks below are init's links and commands until `npx paperlint init --plugin` runs where `claude` is on PATH",
43
+ ]);
44
+ });
45
+ });
46
+
47
+ describe("pluginLines", () => {
48
+ it("on and matching, with nothing of init's left: one line", () => {
49
+ expect(pluginLines(facts())).toEqual([
50
+ HEAD,
51
+ " ✓ on for this project, version 1.2.0",
52
+ ]);
53
+ });
54
+
55
+ it("off: one line naming --plugin", () => {
56
+ expect(
57
+ pluginLines(
58
+ facts({ state: { enabled: false, version: null }, oldLinks: ["a"] }),
59
+ ),
60
+ ).toEqual([
61
+ HEAD,
62
+ " · not on for this project — the skills and hooks below are init's links and commands. `npx paperlint init --plugin` turns it on",
63
+ ]);
64
+ });
65
+
66
+ it("init's links or hooks beside it: named, with the one command that removes them", () => {
67
+ const remedy =
68
+ " `npx paperlint init --plugin` removes the old ones and keeps the plugin";
69
+ expect([
70
+ pluginLines(facts({ oldLinks: ["a", "b"] })).slice(2),
71
+ pluginLines(facts({ oldHooks: ["h"] })).slice(2),
72
+ ]).toEqual([
73
+ [
74
+ " ⚠ init's own skill links (a, b) are still here beside the plugin — each such skill is listed twice, each such hook runs twice",
75
+ remedy,
76
+ ],
77
+ [
78
+ " ⚠ init's own hook commands (h) are still here beside the plugin — each such skill is listed twice, each such hook runs twice",
79
+ remedy,
80
+ ],
81
+ ]);
82
+ });
83
+
84
+ it("a version that is not the installed one: which side is behind, and its command; unknown, nothing", () => {
85
+ const behind = pluginLines(facts({ installed: "1.3.0" })).slice(2);
86
+ const ahead = pluginLines(facts({ installed: "1.1.0" })).slice(2);
87
+ expect([
88
+ behind,
89
+ ahead,
90
+ pluginLines(facts({ installed: null })).slice(2),
91
+ ]).toEqual([
92
+ [
93
+ " ⚠ the plugin is 1.2.0, the installed paperlint is 1.3.0 — its skills and hooks describe another version",
94
+ ` \`${PLUGIN_UPDATE}\` brings the plugin to the newest release`,
95
+ ],
96
+ [
97
+ " ⚠ the plugin is 1.2.0, the installed paperlint is 1.1.0 — its skills and hooks describe another version",
98
+ " the package is behind: install paperlint@1.2.0 in this project",
99
+ ],
100
+ [],
101
+ ]);
102
+ });
103
+ });
@@ -0,0 +1,83 @@
1
+ /**
2
+ * `paperlint doctor`'s plugin section. Once the Claude Code plugin is on it carries the skills and the
3
+ * hooks, so a project without init's links and hook commands is complete — and one that has BOTH lists
4
+ * every skill twice and runs every hook twice, which is the first thing this section warns about. The
5
+ * second is a plugin whose version is not the installed package's: the plugin's skills and hooks then
6
+ * describe a different paperlint than the one `npx paperlint` runs.
7
+ */
8
+ import type { PluginState } from "./ports/claude-code.ts";
9
+
10
+ export const PLUGIN_UPDATE =
11
+ "claude plugin update paperlint@paperlint --scope project";
12
+
13
+ /** -1, 0 or 1 by the dotted numbers of two versions; a pre-release tag is ignored. */
14
+ export function compareVersions(a: string, b: string): number {
15
+ // A missing part reads as "undefined", which parses to NaN, which counts as 0.
16
+ const part = (v: string, k: number): number =>
17
+ Number.parseInt(String(v.split("-", 1).join("").split(".")[k]), 10) || 0;
18
+ return (
19
+ [0, 1, 2]
20
+ .map((k) => Math.sign(part(a, k) - part(b, k)))
21
+ .find((d) => d !== 0) ?? 0
22
+ );
23
+ }
24
+
25
+ export interface PluginFacts {
26
+ readonly state: PluginState;
27
+ /** The paperlint this doctor is, as installed in the project; null when unknown. */
28
+ readonly installed: string | null;
29
+ /** init's skill links still in `.claude/skills/`. */
30
+ readonly oldLinks: readonly string[];
31
+ /** The hooks init's own commands still run from `.claude/settings.json`. */
32
+ readonly oldHooks: readonly string[];
33
+ }
34
+
35
+ const versionLine = (
36
+ plugin: string,
37
+ installed: string | null,
38
+ ): readonly string[] => {
39
+ if (installed === null) return [];
40
+ const order = compareVersions(plugin, installed);
41
+ if (order === 0) return [];
42
+ return [
43
+ ` ⚠ the plugin is ${plugin}, the installed paperlint is ${installed} — its skills and hooks describe another version`,
44
+ order < 0
45
+ ? ` \`${PLUGIN_UPDATE}\` brings the plugin to the newest release`
46
+ : ` the package is behind: install paperlint@${plugin} in this project`,
47
+ ];
48
+ };
49
+
50
+ const doubled = (f: PluginFacts): readonly string[] => {
51
+ const what = [
52
+ f.oldLinks.length > 0 ? `skill links (${f.oldLinks.join(", ")})` : null,
53
+ f.oldHooks.length > 0 ? `hook commands (${f.oldHooks.join(", ")})` : null,
54
+ ].filter((w): w is string => w !== null);
55
+ return what.length === 0
56
+ ? []
57
+ : [
58
+ ` ⚠ init's own ${what.join(" and ")} are still here beside the plugin — each such skill is listed twice, each such hook runs twice`,
59
+ ` \`npx paperlint init --plugin\` removes the old ones and keeps the plugin`,
60
+ ];
61
+ };
62
+
63
+ /** The section: a header and its lines. */
64
+ export function pluginLines(f: PluginFacts): readonly string[] {
65
+ const head = "Claude Code plugin (carries the skills and the hooks)";
66
+ if (!f.state.enabled)
67
+ return [
68
+ head,
69
+ " · not on for this project — the skills and hooks below are init's links and commands. `npx paperlint init --plugin` turns it on",
70
+ ];
71
+ // Declared but not installed: the keys alone load nothing, so init's links are not doubled.
72
+ if (f.state.version === null)
73
+ return [
74
+ head,
75
+ " · declared in the settings, not installed — the skills and hooks below are init's links and commands until `npx paperlint init --plugin` runs where `claude` is on PATH",
76
+ ];
77
+ return [
78
+ head,
79
+ ` ✓ on for this project, version ${f.state.version}`,
80
+ ...doubled(f),
81
+ ...versionLine(f.state.version, f.installed),
82
+ ];
83
+ }
@@ -14,8 +14,8 @@ import {
14
14
  import { tmpdir } from "node:os";
15
15
  import { join } from "node:path";
16
16
  import { test } from "vitest";
17
- import { detectPapers, doctor } from "./doctor.ts";
18
- import { shippedWiring } from "./hooks-settings.ts";
17
+ import { detectPapers, doctor, type DoctorOptions } from "./doctor.ts";
18
+ import { MANAGED_BY, shippedWiring } from "./hooks-settings.ts";
19
19
 
20
20
  const project = (): string =>
21
21
  realpathSync(mkdtempSync(join(tmpdir(), "doctor-")));
@@ -104,6 +104,115 @@ test("doctor exits non-zero when the hooks are only partly wired", () => {
104
104
  assert.equal(exitWithHooks([hookCommand("paper-edit-guard")]), 2);
105
105
  });
106
106
 
107
+ /** Doctor's output for a project with one of init's hook commands and one present skill link. */
108
+ const withPlugin = (plugin: NonNullable<DoctorOptions["plugin"]> | null) => {
109
+ const root = project();
110
+ writeFileSync(join(root, "paperlint.json"), "{}\n");
111
+ mkdirSync(join(root, ".claude"), { recursive: true });
112
+ const ours = `node ${MANAGED_BY} hook ${allHooks[0] ?? ""}`;
113
+ writeFileSync(
114
+ join(root, ".claude", "settings.json"),
115
+ JSON.stringify({
116
+ hooks: {
117
+ PreToolUse: [
118
+ { matcher: "Bash", hooks: [{ type: "command", command: ours }] },
119
+ ],
120
+ },
121
+ }),
122
+ );
123
+ const lines: string[] = [];
124
+ const code = doctor({
125
+ cwd: root,
126
+ log: (s: string) => lines.push(s),
127
+ run: () => ({ status: 0 }),
128
+ cliPapers: join(root, "papers"),
129
+ plugin,
130
+ installed: "1.0.0",
131
+ skillLinks: () => ({
132
+ ok: true,
133
+ home: join(root, ".claude", "skills"),
134
+ example: null,
135
+ links: [{ name: "paper-pipeline", status: "present" }],
136
+ }),
137
+ });
138
+ return { code, out: lines.join("\n").split("\n") };
139
+ };
140
+
141
+ test("doctor and the plugin: on, it carries the skills and hooks and names init's leftovers; off, it says so; no Claude Code, no section", () => {
142
+ const on = withPlugin({ enabled: true, version: "1.0.0" });
143
+ const off = withPlugin({ enabled: false, version: null });
144
+ const none = withPlugin(null);
145
+ const head = "Claude Code plugin (carries the skills and the hooks)";
146
+ // A partly wired set fails the run without the plugin, and not with it: the plugin carries the hooks.
147
+ assert.deepEqual([on.code, off.code, none.code], [0, 2, 2]);
148
+ assert.deepEqual(
149
+ on.out.slice(on.out.indexOf(head), on.out.indexOf(head) + 4),
150
+ [
151
+ head,
152
+ " ✓ on for this project, version 1.0.0",
153
+ ` ⚠ init's own skill links (paper-pipeline) and hook commands (${allHooks[0] ?? ""}) are still here beside the plugin — each such skill is listed twice, each such hook runs twice`,
154
+ " `npx paperlint init --plugin` removes the old ones and keeps the plugin",
155
+ ],
156
+ );
157
+ assert.equal(
158
+ on.out.filter((l) => l === " ✓ carried by the plugin").length,
159
+ 2,
160
+ );
161
+ assert.deepEqual(
162
+ [off.out.includes(head), none.out.includes(head)],
163
+ [true, false],
164
+ );
165
+ });
166
+
167
+ test("doctor with the plugin declared but not installed: the hooks are checked as without it", () => {
168
+ const declared = withPlugin({ enabled: true, version: null });
169
+ const off = withPlugin({ enabled: false, version: null });
170
+ // The keys alone load nothing: a partly wired set fails the run, and nothing is "carried".
171
+ assert.deepEqual(
172
+ [
173
+ declared.code,
174
+ declared.out.filter((l) => l === " ✓ carried by the plugin").length,
175
+ ],
176
+ [off.code, 0],
177
+ );
178
+ });
179
+
180
+ test("doctor with the plugin on and settings that do not parse, or cannot be read: no leftovers named, the run not failed", () => {
181
+ const onWith = (settings: (root: string) => void) => {
182
+ const root = project();
183
+ writeFileSync(join(root, "paperlint.json"), "{}\n");
184
+ mkdirSync(join(root, ".claude"), { recursive: true });
185
+ settings(root);
186
+ const lines: string[] = [];
187
+ const code = doctor({
188
+ cwd: root,
189
+ log: (s: string) => lines.push(s),
190
+ run: () => ({ status: 0 }),
191
+ cliPapers: join(root, "papers"),
192
+ plugin: { enabled: true, version: "1.0.0" },
193
+ skillLinks: () => ({ ok: false, error: "not resolved" }),
194
+ });
195
+ const out = lines.join("\n").split("\n");
196
+ const at = out.indexOf(
197
+ "Claude Code plugin (carries the skills and the hooks)",
198
+ );
199
+ return [code, out.slice(at + 1, at + 3)];
200
+ };
201
+ const quiet = [0, [" ✓ on for this project, version 1.0.0", ""]];
202
+ assert.deepEqual(
203
+ [
204
+ onWith((root) => {
205
+ writeFileSync(join(root, ".claude", "settings.json"), "{ nope");
206
+ }),
207
+ // A DIRECTORY where the file should be: reading it throws EISDIR.
208
+ onWith((root) => {
209
+ mkdirSync(join(root, ".claude", "settings.json"));
210
+ }),
211
+ ],
212
+ [quiet, quiet],
213
+ );
214
+ });
215
+
107
216
  test("doctor exits non-zero when a hook is wired twice", () => {
108
217
  const commands = [
109
218
  ...allHooks.map(hookCommand),
package/src/doctor.ts CHANGED
@@ -35,7 +35,10 @@ import {
35
35
  } from "../hooks/paper-edit-guard.hook.mjs";
36
36
  import { PAPER_MARKERS } from "./build.ts";
37
37
  import { linkSkills, SKILLS_HOME, type LinkReport } from "./link-skills.ts";
38
- import { doctorHooks } from "./hooks-settings.ts";
38
+ import { doctorHooks, initWiredHooks } from "./hooks-settings.ts";
39
+ import { pluginLines } from "./doctor-plugin.ts";
40
+ import { installedPluginVersion } from "./plugin-offer.ts";
41
+ import type { PluginState } from "./ports/claude-code.ts";
39
42
  import { messageOf } from "./domain/text.ts";
40
43
  import { fieldOf } from "./domain/record.ts";
41
44
 
@@ -240,6 +243,61 @@ function papersVerdict(
240
243
  return { lines: out, bad };
241
244
  }
242
245
 
246
+ /** The hooks init's own commands run; none when they cannot be read (the plugin carries them anyway). */
247
+ function oldHooksOf(root: string): readonly string[] {
248
+ try {
249
+ return initWiredHooks(root);
250
+ } catch {
251
+ return [];
252
+ }
253
+ }
254
+
255
+ /** init's skill links that lead to the shipped skill. */
256
+ const presentLinks = (links: LinkReport): readonly string[] =>
257
+ links.ok
258
+ ? links.links.filter((l) => l.status === "present").map((l) => l.name)
259
+ : [];
260
+
261
+ /** The skills section; the plugin, when it is on, carries them. */
262
+ function skillsLines(links: LinkReport, on: boolean): readonly string[] {
263
+ const head = `skills (Claude Code finds project skills only in ${SKILLS_HOME}/)`;
264
+ if (on) return [head, ` ✓ carried by the plugin`];
265
+ if (!links.ok) return [head, ` ⚠ not checked — ${links.error}`];
266
+ const gaps = links.links.filter((l) => l.status !== "present");
267
+ const total = String(links.links.length);
268
+ const as = join(SKILLS_HOME, "<name>");
269
+ return gaps.length === 0
270
+ ? [head, ` ✓ all ${total} shipped skills are reachable as ${as}`]
271
+ : [
272
+ head,
273
+ ` ⚠ ${String(gaps.length)} of ${total} shipped skills are NOT reachable as ${as}:`,
274
+ ...gaps.map(
275
+ (g) =>
276
+ ` ${g.name} — ${g.status === "missing" ? "not linked" : `${g.reason ?? "occupied"}, not the shipped skill`}`,
277
+ ),
278
+ ` \`npx paperlint init\` links the missing ones; it never replaces an entry it did not make`,
279
+ ];
280
+ }
281
+
282
+ /**
283
+ * 🔴 THE HOOKS ARE READ FROM THE FILE THAT CARRIES THEM. Until `init` wrote them into
284
+ * `.claude/settings.json`, the only carrier was a plugin and this section said "cannot be checked
285
+ * from a terminal". Hooks wired NOT AT ALL are advisory, like the skills: `--no-hooks` is a choice,
286
+ * not a fault. Partly wired, or wired twice, is a fault and fails the run — unless the plugin is on,
287
+ * which carries them.
288
+ */
289
+ function hooksSection(
290
+ root: string,
291
+ on: boolean,
292
+ ): { readonly lines: readonly string[]; readonly bad: number } {
293
+ if (on) return { lines: [`hooks`, ` ✓ carried by the plugin`], bad: 0 };
294
+ try {
295
+ return doctorHooks(root);
296
+ } catch (e) {
297
+ return { lines: [`hooks`, ` ⚠ not checked — ${messageOf(e)}`], bad: 0 };
298
+ }
299
+ }
300
+
243
301
  export interface DoctorOptions {
244
302
  log?: typeof console.log;
245
303
  cwd?: string;
@@ -250,6 +308,10 @@ export interface DoctorOptions {
250
308
  cliPapers?: string | null;
251
309
  /** Reads the skill links without writing any. Injected only so a test can fake the install. */
252
310
  skillLinks?: (root: string) => LinkReport;
311
+ /** The Claude Code plugin in this project, as the CLI read it; null where Claude Code is not. */
312
+ plugin?: PluginState | null;
313
+ /** The installed paperlint's version, compared with the plugin's; null skips the comparison. */
314
+ installed?: string | null;
253
315
  }
254
316
 
255
317
  /**
@@ -267,6 +329,8 @@ export function doctor({
267
329
  run = spawnSync,
268
330
  cliPapers = null,
269
331
  skillLinks = (r: string) => linkSkills(r, { write: false }),
332
+ plugin = null,
333
+ installed = null,
270
334
  }: DoctorOptions = {}): number {
271
335
  const root = projectDir ?? cwd;
272
336
  const configPath = join(root, CONFIG_FILE);
@@ -301,32 +365,24 @@ export function doctor({
301
365
  // work without it, and an entry of the same name that `init` refused to replace is the
302
366
  // consumer's own decision. What this section removes is the silence — before it, a consumer
303
367
  // without links had no `/paper-pipeline` and nothing anywhere said so.
368
+ const links = skillLinks(root);
369
+ // Without Claude Code there is no plugin to speak of, so no section at all.
370
+ const on = installedPluginVersion(plugin ?? null) !== null;
304
371
  out.push(
372
+ ...(plugin
373
+ ? [
374
+ "",
375
+ ...pluginLines({
376
+ state: plugin,
377
+ installed,
378
+ oldLinks: presentLinks(links),
379
+ oldHooks: on ? oldHooksOf(root) : [],
380
+ }),
381
+ ]
382
+ : []),
305
383
  "",
306
- `skills (Claude Code finds project skills only in ${SKILLS_HOME}/)`,
384
+ ...skillsLines(links, on),
307
385
  );
308
- const links = skillLinks(root);
309
- if (!links.ok) out.push(` ⚠ not checked — ${links.error}`);
310
- else {
311
- const gaps = links.links.filter((l) => l.status !== "present");
312
- const total = String(links.links.length);
313
- if (gaps.length === 0)
314
- out.push(
315
- ` ✓ all ${total} shipped skills are reachable as ${join(SKILLS_HOME, "<name>")}`,
316
- );
317
- else {
318
- out.push(
319
- ` ⚠ ${String(gaps.length)} of ${total} shipped skills are NOT reachable as ${join(SKILLS_HOME, "<name>")}:`,
320
- );
321
- for (const g of gaps)
322
- out.push(
323
- ` ${g.name} — ${g.status === "missing" ? "not linked" : `${g.reason ?? "occupied"}, not the shipped skill`}`,
324
- );
325
- out.push(
326
- ` \`npx paperlint init\` links the missing ones; it never replaces an entry it did not make`,
327
- );
328
- }
329
- }
330
386
 
331
387
  out.push(
332
388
  "",
@@ -344,14 +400,9 @@ export function doctor({
344
400
  // `.claude/settings.json`, the only carrier was a plugin and this section said "cannot be
345
401
  // checked from a terminal". Hooks wired NOT AT ALL are advisory, like the skills: `--no-hooks`
346
402
  // is a choice, not a fault. Partly wired, or wired twice, is a fault and fails the run.
347
- out.push("");
348
- try {
349
- const hooks = doctorHooks(root);
350
- out.push(...hooks.lines);
351
- bad += hooks.bad;
352
- } catch (e) {
353
- out.push(`hooks`, ` ⚠ not checked — ${messageOf(e)}`);
354
- }
403
+ const hooks = hooksSection(root, on);
404
+ out.push("", ...hooks.lines);
405
+ bad += hooks.bad;
355
406
  out.push("");
356
407
  log(out.join("\n"));
357
408
  return bad > 0 ? 2 : 0;
@@ -21,6 +21,7 @@ import {
21
21
  noticeText,
22
22
  } from "./hooks-notice.ts";
23
23
  import { WIRING_FILE } from "./hooks-settings.ts";
24
+ import type { ClaudeCode } from "./ports/claude-code.ts";
24
25
 
25
26
  const root = useTempDir("hooks-notice-");
26
27
 
@@ -65,6 +66,25 @@ function project(name: string, settings: string | null, long = false): string {
65
66
  return dir;
66
67
  }
67
68
 
69
+ /**
70
+ * Claude Code with the plugin off, whatever the machine running the tests has: the default reads the
71
+ * user's own settings, and a developer with the plugin on would see every notice go quiet.
72
+ */
73
+ const PLUGIN_OFF: ClaudeCode = {
74
+ present: () => true,
75
+ plugin: () => ({ enabled: false, version: null }),
76
+ enable: () => ({ ok: false, reason: "not in this test" }),
77
+ };
78
+ const PLUGIN_ON: ClaudeCode = {
79
+ ...PLUGIN_OFF,
80
+ plugin: () => ({ enabled: true, version: "9.9.9" }),
81
+ };
82
+ /** Declared in the settings, never installed: the keys alone load nothing. */
83
+ const PLUGIN_DECLARED: ClaudeCode = {
84
+ ...PLUGIN_OFF,
85
+ plugin: () => ({ enabled: true, version: null }),
86
+ };
87
+
68
88
  /** `paperlint hook <name>` in-process on an Edit of `file`. */
69
89
  // eslint-disable-next-line max-params -- a test helper: the hook, the project, the edit and the version
70
90
  async function hook(
@@ -90,6 +110,7 @@ async function hook(
90
110
  err.push(m);
91
111
  },
92
112
  projectDir: dir,
113
+ claude: PLUGIN_OFF,
93
114
  version,
94
115
  ...(skillLinks === undefined ? {} : { skillLinks }),
95
116
  });
@@ -229,6 +250,7 @@ test("paperlint lint: one stderr line naming the missing hooks when partly wired
229
250
  log: () => undefined,
230
251
  err: (...a: unknown[]) => err.push(a.join(" ")),
231
252
  cwd: dir,
253
+ claude: PLUGIN_OFF,
232
254
  });
233
255
  return { code, err: err.filter((l) => /not wired|unwired/.test(l)) };
234
256
  };
@@ -259,6 +281,7 @@ test("a spawned PostToolUse hook: its stdout is captured and merged, its payload
259
281
  out.push(t);
260
282
  },
261
283
  projectDir: dir,
284
+ claude: PLUGIN_OFF,
262
285
  version: "9.9.9",
263
286
  run: (_f, _a, o) => {
264
287
  seen.push(o);
@@ -342,6 +365,7 @@ test("the check that cannot run, and a payload that cannot be read, leave the ho
342
365
  out: () => undefined,
343
366
  err: (m: string) => void said.push(m),
344
367
  projectDir: dir,
368
+ claude: PLUGIN_OFF,
345
369
  version: "9.9.9",
346
370
  });
347
371
  assert.equal(garbled, 0);
@@ -358,6 +382,7 @@ test("the check that cannot run, and a payload that cannot be read, leave the ho
358
382
  out: () => undefined,
359
383
  err: (m: string) => void thrown.push(m),
360
384
  projectDir: dir,
385
+ claude: PLUGIN_OFF,
361
386
  version: "9.9.9",
362
387
  });
363
388
  assert.equal(unread, 0);
@@ -411,11 +436,13 @@ test("paperlint lint: a settings file it cannot read is no second finding — th
411
436
  log: () => undefined,
412
437
  err: (...a: unknown[]) => void err.push(a.join(" ")),
413
438
  cwd: dir,
439
+ claude: PLUGIN_OFF,
414
440
  });
415
441
  const clean = await run(["lint"], {
416
442
  log: () => undefined,
417
443
  err: () => undefined,
418
444
  cwd: project("lint-unreadable-control", null),
445
+ claude: PLUGIN_OFF,
419
446
  });
420
447
  assert.equal(code, clean);
421
448
  assert.deepEqual(
@@ -511,6 +538,7 @@ test("paperlint lint: one stderr line names the unlinked skills, and none when t
511
538
  log: () => undefined,
512
539
  err: (...a: unknown[]) => err.push(a.join(" ")),
513
540
  cwd: dir,
541
+ claude: PLUGIN_OFF,
514
542
  skillLinks,
515
543
  });
516
544
  return { code, err: err.filter((l) => /not linked|not wired/.test(l)) };
@@ -547,3 +575,57 @@ test("lintLine and noticeText word skills beside hooks", () => {
547
575
  /skills that are not linked into \.claude\/skills\/: a\./,
548
576
  );
549
577
  });
578
+
579
+ test("the plugin on: a partly wired project with unlinked skills hears nothing, from the hook or from lint", async () => {
580
+ const dir = project("plugin-on", wiringWithout(["lint-edited"]));
581
+ const unlinked = linked(["rewrite-unclear", "missing"]);
582
+ // The hook speaks once per version, so the declared plugin gets a project of its own.
583
+ const declaredDir = project(
584
+ "plugin-declared",
585
+ wiringWithout(["lint-edited"]),
586
+ );
587
+ const hooked = async (claude: ClaudeCode, at = dir) => {
588
+ const out: string[] = [];
589
+ await runHook("lint-edited", {
590
+ stdin: () =>
591
+ JSON.stringify({
592
+ tool_name: "Edit",
593
+ tool_input: {
594
+ file_path: join(at, "papers/p/paper.tex"),
595
+ new_string: "Fine.",
596
+ },
597
+ }),
598
+ out: (t) => void out.push(t),
599
+ err: () => undefined,
600
+ projectDir: at,
601
+ version: "7.7.7",
602
+ skillLinks: unlinked,
603
+ claude,
604
+ });
605
+ return out.join("").includes("additionalContext");
606
+ };
607
+ const linted = async (claude: ClaudeCode) => {
608
+ const err: string[] = [];
609
+ await run(["lint"], {
610
+ log: () => undefined,
611
+ err: (...a: unknown[]) => err.push(a.join(" ")),
612
+ cwd: dir,
613
+ skillLinks: unlinked,
614
+ claude,
615
+ });
616
+ return err.filter((l) => l.includes("npx paperlint init"));
617
+ };
618
+ // Both halves: the same project with the plugin off speaks, so the silence is the plugin's.
619
+ // A plugin only declared carries nothing, so it speaks as off does.
620
+ assert.deepEqual(
621
+ [
622
+ await hooked(PLUGIN_ON),
623
+ await linted(PLUGIN_ON),
624
+ await hooked(PLUGIN_OFF),
625
+ (await linted(PLUGIN_OFF)).length,
626
+ await hooked(PLUGIN_DECLARED, declaredDir),
627
+ (await linted(PLUGIN_DECLARED)).length,
628
+ ],
629
+ [false, [], true, 1, true, 1],
630
+ );
631
+ });
@@ -321,6 +321,55 @@ export function wireHooks(
321
321
  return { status: "written", path, names: wiring.names };
322
322
  }
323
323
 
324
+ /**
325
+ * Removes the hook commands `init` wrote (the MANAGED_BY spelling) once the Claude Code plugin carries
326
+ * the hooks; the project's own commands stay. vigiles' merge does it: measured 2026-11-22, a merge
327
+ * whose map names each event with no entries drops exactly the managed commands of those events.
328
+ */
329
+ export function unwireHooks(
330
+ root: string,
331
+ merge: Merge,
332
+ wiring: Wiring = shippedWiring(),
333
+ ):
334
+ | {
335
+ readonly status: "removed";
336
+ readonly path: string;
337
+ readonly names: readonly string[];
338
+ }
339
+ | { readonly status: "none" }
340
+ | {
341
+ readonly status: "unparsable";
342
+ readonly path: string;
343
+ readonly reason: string;
344
+ } {
345
+ const read = readSettings(root);
346
+ if (read.status === "unparsable") return read;
347
+ const names = initWiredHooks(root, wiring);
348
+ if (names.length === 0) return { status: "none" };
349
+ const none = Object.fromEntries(
350
+ Object.keys(wiring.compiled).map((event) => [event, []]),
351
+ );
352
+ writeFileSync(
353
+ read.path,
354
+ `${JSON.stringify(merge(read.settings, none, MANAGED_BY), null, 2)}\n`,
355
+ "utf8",
356
+ );
357
+ return { status: "removed", path: read.path, names };
358
+ }
359
+
360
+ /** The hooks a command of init's own spelling runs; none when the settings file cannot be read. */
361
+ export function initWiredHooks(
362
+ root: string,
363
+ wiring: Wiring = shippedWiring(),
364
+ ): readonly string[] {
365
+ const read = readSettings(root);
366
+ return read.status === "unparsable"
367
+ ? []
368
+ : wiredCounts(read.settings, wiring.names)
369
+ .filter((c) => c.ours > 0)
370
+ .map((c) => c.name);
371
+ }
372
+
324
373
  /** The consequence every report of a written hook must carry, in one place. */
325
374
  export const FRESH_CLONE_NOTE = `the commands point into node_modules/${PACKAGE_NAME}/ — in a fresh clone they cannot run until \`npm install\` has run there`;
326
375