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
package/src/init.ts CHANGED
@@ -19,7 +19,7 @@
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 [Y/n] of a human, YES without one — the guard is what the package is
22
+ * asked of a human (Yes preselected), YES without one — the guard is what the package is
23
23
  * 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.
@@ -54,11 +54,17 @@ import {
54
54
  type ProgramProbe,
55
55
  } from "./doctor.ts";
56
56
  import { PAPER_MARKERS, papersIn } from "./build.ts";
57
- import { linkSkills, SKILLS_HOME, type LinkReport } from "./link-skills.ts";
57
+ import {
58
+ linkSkills,
59
+ SKILLS_HOME,
60
+ unlinkSkills,
61
+ type LinkReport,
62
+ } from "./link-skills.ts";
58
63
  import {
59
64
  FRESH_CLONE_NOTE,
60
65
  SETTINGS_PATH,
61
66
  shippedWiring,
67
+ unwireHooks,
62
68
  wireHooks,
63
69
  type Merge,
64
70
  type WireResult,
@@ -75,11 +81,51 @@ import {
75
81
  import { messageOf } from "./domain/text.ts";
76
82
  import { isRecord } from "./domain/record.ts";
77
83
  import type { NamedVenue } from "./domain/venue-name.ts";
84
+ import type { Answer, Prompts } from "./ports/prompts.ts";
85
+ import type { ClaudeCode } from "./ports/claude-code.ts";
86
+ import { absolutePath } from "./domain/paths.ts";
87
+ import {
88
+ offerPlugin,
89
+ pluginOn,
90
+ reportPlugin,
91
+ type PluginFlag,
92
+ } from "./plugin-offer.ts";
78
93
 
79
94
  /** How the papers directory was arrived at. Printed, because a guess must not read as a fact. */
80
95
  export type PapersHow =
81
96
  "detected" | "chosen" | "not-asked" | "no-answer" | "guessed";
82
97
 
98
+ /**
99
+ * 🔴 CTRL+C AT A QUESTION STOPS init THERE. Measured 2026-11-22 on a pseudo-terminal: the readline
100
+ * questions this replaced took Ctrl+C as "no answer", so each took its default and init went on — a
101
+ * Ctrl+C at "wire the hooks? [Y/n]" WIRED them, and the run exited 0. A cancel now writes nothing
102
+ * after the question and exits with the shell's code for an interrupt.
103
+ */
104
+ export const CANCELLED_CODE = 130;
105
+
106
+ /** The line a cancelled run ends with. */
107
+ export const CANCELLED_LINE = ` ✗ cancelled — init stopped at this question, and nothing after it was written. \`npx paperlint init\` starts again`;
108
+
109
+ /**
110
+ * One question, asked through the port. A prompt that FAILS (a stream that ended) is `null`, and
111
+ * its default is taken and said — the rule `askOrDefault` keeps for readline. A cancel passes through.
112
+ */
113
+ export async function askOrNull<T>(
114
+ ask: () => Promise<Answer<T>>,
115
+ ): Promise<Answer<T> | null> {
116
+ try {
117
+ return await ask();
118
+ } catch {
119
+ return null;
120
+ }
121
+ }
122
+
123
+ /** The value answered, or `fallback` when the prompt failed. */
124
+ const valueOr = <T>(a: Answer<T> | null, fallback: T): T =>
125
+ a?.kind === "answer" ? a.value : fallback;
126
+
127
+ const cancelled = (a: Answer<unknown> | null): boolean => a?.kind === "cancel";
128
+
83
129
  /**
84
130
  * 🔴 A QUESTION CAN FAIL, AND ITS FAILURE MUST NOT BE THE COMMAND'S. Measured 2026-09-18 on a
85
131
  * real pseudo-terminal: `readline`'s `question()` REJECTS with `AbortError: Aborted with Ctrl+D`
@@ -161,30 +207,30 @@ export interface PapersChoice {
161
207
  export async function choosePapers(
162
208
  root: string,
163
209
  {
164
- ask,
210
+ prompts,
165
211
  interactive,
166
- }: { ask?: (q: string) => Promise<string>; interactive: boolean },
167
- ): Promise<PapersChoice> {
212
+ }: { prompts?: Prompts | undefined; interactive: boolean },
213
+ ): Promise<PapersChoice | "cancelled"> {
168
214
  const candidates = detectPapers(root);
169
215
  const first = candidates[0];
170
216
  if (first === undefined)
171
217
  return { papers: DEFAULT_PAPERS_ROOT, how: "guessed", candidates };
172
218
  if (candidates.length === 1)
173
219
  return { papers: first, how: "detected", candidates };
174
- if (!interactive || !ask)
220
+ if (!interactive || !prompts)
175
221
  return { papers: first, how: "not-asked", candidates };
176
222
 
177
- const menu = candidates
178
- .map((c, i) => ` ${String(i + 1)}) ${c}`)
179
- .join("\n");
180
- const answer = await askOrDefault(
181
- ask,
182
- ` several directories look like papers roots:\n${menu}\n which one? [1] `,
223
+ const answer = await askOrNull(() =>
224
+ prompts.select({
225
+ message: "several directories look like papers roots — which one?",
226
+ options: candidates,
227
+ initial: first,
228
+ }),
183
229
  );
184
- const picked = candidates[Number((answer ?? "").trim()) - 1];
185
- return picked === undefined
230
+ if (cancelled(answer)) return "cancelled";
231
+ return answer === null
186
232
  ? { papers: first, how: "no-answer", candidates }
187
- : { papers: picked, how: "chosen", candidates };
233
+ : { papers: valueOr(answer, first), how: "chosen", candidates };
188
234
  }
189
235
 
190
236
  export type DeclarationResult =
@@ -212,7 +258,8 @@ export type DeclarationResult =
212
258
  readonly status: "unparsable";
213
259
  readonly path: string;
214
260
  readonly reason: string;
215
- };
261
+ }
262
+ | { readonly status: "cancelled"; readonly path: string };
216
263
 
217
264
  /**
218
265
  * Declares the papers directory in the root `paperlint.json` — the one file the hooks, the rules
@@ -225,7 +272,7 @@ export type DeclarationResult =
225
272
  */
226
273
  export async function declarePapers(
227
274
  root: string,
228
- choose: () => Promise<PapersChoice>,
275
+ choose: () => Promise<PapersChoice | "cancelled">,
229
276
  ): Promise<DeclarationResult> {
230
277
  const path = join(root, CONFIG_FILE);
231
278
  const raw = existsSync(path) ? readFileSync(path, "utf8") : null;
@@ -247,6 +294,7 @@ export async function declarePapers(
247
294
  // 🔴 ONLY NOW is the directory measured (or asked about). A declared one is the answer, and a
248
295
  // candidate measured beside it is a decision nobody takes.
249
296
  const choice = await choose();
297
+ if (choice === "cancelled") return { status: "cancelled", path };
250
298
  if (choice.papers === DEFAULT_PAPERS_ROOT)
251
299
  return { status: "default", path, papers: choice.papers, choice };
252
300
  // Two-space indent and the file's own trailing newline: a declaration is not a licence to
@@ -296,31 +344,28 @@ export function workflowYaml(): string {
296
344
  ].join("\n");
297
345
  }
298
346
 
299
- export type WorkflowResult = "written" | "kept" | "declined" | "not-asked";
347
+ export type WorkflowResult =
348
+ "written" | "kept" | "declined" | "not-asked" | "cancelled";
300
349
 
301
350
  export async function offerWorkflow(
302
351
  root: string,
303
352
  {
304
- ask,
353
+ prompts,
305
354
  interactive,
306
- }: {
307
- ask?: (q: string) => Promise<string>;
308
- interactive: boolean;
309
- },
355
+ }: { prompts?: Prompts | undefined; interactive: boolean },
310
356
  ): Promise<WorkflowResult> {
311
357
  const path = join(root, WORKFLOW_PATH);
312
358
  if (existsSync(path)) return "kept";
313
- if (!interactive || !ask) return "not-asked";
314
- const answer = (
315
- await askOrDefault(
316
- ask,
317
- ` add a GitHub Actions workflow that runs this in CI? [y/N] `,
318
- )
319
- )
320
- ?.trim()
321
- .toLowerCase();
322
- // No answer — an empty line, or a stream that ended — is the safe default, which is "no file".
323
- if (answer !== "y" && answer !== "yes") return "declined";
359
+ if (!interactive || !prompts) return "not-asked";
360
+ const answer = await askOrNull(() =>
361
+ prompts.confirm({
362
+ message: "add a GitHub Actions workflow that runs this in CI?",
363
+ initial: false,
364
+ }),
365
+ );
366
+ if (cancelled(answer)) return "cancelled";
367
+ // No answer — a stream that ended — is the safe default, which is "no file".
368
+ if (!valueOr(answer, false)) return "declined";
324
369
  mkdirSync(dirname(path), { recursive: true });
325
370
  writeFileSync(path, workflowYaml(), "utf8");
326
371
  return "written";
@@ -338,6 +383,7 @@ export function reportWorkflow(
338
383
  ` ✓ ${WORKFLOW_PATH} is already there — kept, nothing overwritten`,
339
384
  );
340
385
  else if (wf === "declined") out.push(` · declined — nothing written`);
386
+ else if (wf === "cancelled") return [CANCELLED_LINE];
341
387
  else
342
388
  out.push(
343
389
  ` · ${why}, so nothing was asked. Default taken: NO file written.`,
@@ -391,6 +437,7 @@ export type HooksOutcome =
391
437
  | WireResult
392
438
  | { readonly status: "skipped" }
393
439
  | { readonly status: "declined" }
440
+ | { readonly status: "cancelled" }
394
441
  | { readonly status: "failed"; readonly reason: string };
395
442
 
396
443
  /**
@@ -404,48 +451,132 @@ export async function offerHooks(
404
451
  {
405
452
  hooks,
406
453
  interactive,
407
- ask,
454
+ prompts,
408
455
  merge,
409
456
  }: {
410
457
  hooks: boolean;
411
458
  interactive: boolean;
412
- ask?: (q: string) => Promise<string>;
459
+ prompts?: Prompts | undefined;
413
460
  merge?: Merge | undefined;
414
461
  },
415
462
  ): Promise<HooksOutcome> {
416
463
  if (!hooks) return { status: "skipped" };
417
- if (interactive && ask) {
418
- const answer = (
419
- await askOrDefault(
420
- ask,
421
- ` wire the paper hooks into ${SETTINGS_PATH} (committed, shared with every clone)? [Y/n] `,
422
- )
423
- )
424
- ?.trim()
425
- .toLowerCase();
426
- // An empty line or a stream that ended is the stated default, which here is YES.
427
- if (answer === "n" || answer === "no") return { status: "declined" };
464
+ if (interactive && prompts) {
465
+ const answer = await askOrNull(() =>
466
+ prompts.confirm({
467
+ message: `wire the paper hooks into ${SETTINGS_PATH} (committed, shared with every clone)?`,
468
+ initial: true,
469
+ }),
470
+ );
471
+ if (cancelled(answer)) return { status: "cancelled" };
472
+ // A stream that ended is the stated default, which here is YES.
473
+ if (!valueOr(answer, true)) return { status: "declined" };
428
474
  }
429
475
  try {
430
- // Called THROUGH the protocol object rather than as a detached method: the port is an
431
- // object, and an implementation that one day reads `this` must not break here.
432
- let m = merge;
433
- if (!m) {
434
- // eslint-disable-next-line boundaries/dependencies -- legacy layer, moves behind a port in #76
435
- const { claudeCodeHookProtocol } = await import("vigiles/claude-code");
436
- m = (existing, compiled, managedBy) =>
437
- claudeCodeHookProtocol.mergeRegistrations(
438
- existing,
439
- compiled,
440
- managedBy,
441
- );
442
- }
443
- return wireHooks(root, m, shippedWiring());
476
+ return wireHooks(root, await loadMerge(merge), shippedWiring());
444
477
  } catch (e) {
445
478
  return { status: "failed", reason: messageOf(e) };
446
479
  }
447
480
  }
448
481
 
482
+ /** vigiles' merge: the injected one, or the real one, loaded only when init needs it. */
483
+ async function loadMerge(merge: Merge | undefined): Promise<Merge> {
484
+ if (merge) return merge;
485
+ // eslint-disable-next-line boundaries/dependencies -- legacy layer, moves behind a port in #76
486
+ const { claudeCodeHookProtocol } = await import("vigiles/claude-code");
487
+ // Called THROUGH the protocol object rather than as a detached method: the port is an
488
+ // object, and an implementation that one day reads `this` must not break here.
489
+ return (existing, compiled, managedBy) =>
490
+ claudeCodeHookProtocol.mergeRegistrations(existing, compiled, managedBy);
491
+ }
492
+
493
+ /** Without the plugin: each skill linked into `.claude/skills/`, the hooks wired into settings. */
494
+ async function linkAndWire(
495
+ root: string,
496
+ {
497
+ link,
498
+ asking,
499
+ here,
500
+ log,
501
+ }: {
502
+ readonly link: (root: string) => LinkReport;
503
+ readonly asking: Parameters<typeof offerHooks>[1] & {
504
+ readonly why: string;
505
+ };
506
+ readonly here: (p: string) => string;
507
+ readonly log: (line: string) => void;
508
+ },
509
+ ): Promise<"cancelled" | "done"> {
510
+ reportSkillLinks(link(root), here).forEach((line) => {
511
+ log(line);
512
+ });
513
+ log(``);
514
+ log(
515
+ `hooks (Claude Code runs them from ${SETTINGS_PATH} — committed, shared with every clone)`,
516
+ );
517
+ const hooked = await offerHooks(root, asking);
518
+ reportHooks(hooked, {
519
+ here,
520
+ how: asking.interactive
521
+ ? `you were asked; \`--no-hooks\` skips this next time`
522
+ : `default taken: YES — ${asking.why}, so nothing was asked. \`--no-hooks\` skips this`,
523
+ }).forEach((line) => {
524
+ log(line);
525
+ });
526
+ return hooked.status === "cancelled" ? "cancelled" : "done";
527
+ }
528
+
529
+ /**
530
+ * The plugin is on: the skill links and hook commands init made earlier go, so nothing is listed or
531
+ * run twice. What the project made itself stays, and doctor names it.
532
+ */
533
+ async function retireOld(
534
+ root: string,
535
+ {
536
+ unlink,
537
+ merge,
538
+ here,
539
+ log,
540
+ }: {
541
+ readonly unlink: (root: string) => ReturnType<typeof unlinkSkills>;
542
+ readonly merge?: Merge | undefined;
543
+ readonly here: (p: string) => string;
544
+ readonly log: (line: string) => void;
545
+ },
546
+ ): Promise<"done"> {
547
+ const skills = unlink(root);
548
+ const hooks = await loadMerge(merge)
549
+ .then((m) => unwireHooks(root, m))
550
+ .catch((e: unknown) => ({
551
+ status: "failed" as const,
552
+ reason: messageOf(e),
553
+ }));
554
+ const hookLine = {
555
+ removed: (h: {
556
+ readonly path: string;
557
+ readonly names: readonly string[];
558
+ }) =>
559
+ ` ✓ removed the hook commands init wrote into ${here(h.path)}: ${h.names.join(", ")}`,
560
+ none: () => ` ✓ no hook commands of init's to remove`,
561
+ other: (reason: string) => ` ⚠ hook commands not checked — ${reason}`,
562
+ };
563
+ [
564
+ ``,
565
+ `skills and hooks (the plugin carries them now)`,
566
+ skills.ok
567
+ ? ` ✓ ${skills.removed.length === 0 ? "no skill links of init's to remove" : `removed the skill links init made: ${skills.removed.join(", ")}`}`
568
+ : ` ⚠ skill links not checked — ${skills.error}`,
569
+ hooks.status === "removed"
570
+ ? hookLine.removed(hooks)
571
+ : hooks.status === "none"
572
+ ? hookLine.none()
573
+ : hookLine.other(hooks.reason),
574
+ ].forEach((line) => {
575
+ log(line);
576
+ });
577
+ return "done";
578
+ }
579
+
449
580
  /** The hooks section of init's report. Every default names the flag that changes it. */
450
581
  export function reportHooks(
451
582
  outcome: HooksOutcome,
@@ -456,6 +587,7 @@ export function reportHooks(
456
587
  out.push(` · --no-hooks — nothing written`);
457
588
  return out;
458
589
  }
590
+ if (outcome.status === "cancelled") return [CANCELLED_LINE];
459
591
  if (outcome.status === "declined") {
460
592
  out.push(
461
593
  ` · declined — nothing written. \`npx paperlint init\` again wires them later`,
@@ -552,8 +684,11 @@ export interface InitOptions {
552
684
  log?: typeof console.log;
553
685
  err?: typeof console.error;
554
686
  cwd?: string;
555
- /** Asks one question. Injected so the prompt is assertable without a pseudo-terminal. */
556
- ask?: (question: string) => Promise<string>;
687
+ /**
688
+ * The questions, drawn by the CLI's clack adapter (`src/adapters/clack/`). Injected so each one is
689
+ * assertable without a pseudo-terminal; without it nothing is asked.
690
+ */
691
+ prompts?: Prompts;
557
692
  /**
558
693
  * Whether a human is at the other end. Defaults to `interactivity()` over this process: stdin
559
694
  * AND stdout are terminals, `CI` is unset, and no `--yes`.
@@ -590,9 +725,15 @@ export interface InitOptions {
590
725
  * it (`paperlint toolchain`). Passed in by the CLI; without them the step only names the command.
591
726
  */
592
727
  tex?: { readonly installed: () => boolean; readonly install?: () => number };
728
+ /** Claude Code, for the plugin offer. Passed in by the CLI; without it nothing is offered. */
729
+ claude?: ClaudeCode;
730
+ /** `--plugin` or `--no-plugin`. */
731
+ pluginFlag?: PluginFlag;
732
+ /** Removes the skill links init made; injected only so a test can stand in for the package. */
733
+ unlink?: (root: string) => ReturnType<typeof unlinkSkills>;
593
734
  }
594
735
 
595
- /** Reads one line from a real terminal. Kept out of `init` so the command stays testable. */
736
+ /** Reads one line from a real terminal, for `paperlint new` and the build; init asks through `Prompts`. */
596
737
  export async function askOnTerminal(question: string): Promise<string> {
597
738
  // eslint-disable-next-line boundaries/dependencies -- legacy I/O, moves behind a port in #76
598
739
  const { createInterface } = await import("node:readline/promises");
@@ -609,7 +750,12 @@ export async function askOnTerminal(question: string): Promise<string> {
609
750
  export const TOOLCHAIN_COST = "~270 MB, ~3 min, once";
610
751
 
611
752
  export type TexOutcome =
612
- "installed" | "was-installed" | "failed" | "declined" | "not-asked";
753
+ | "installed"
754
+ | "was-installed"
755
+ | "failed"
756
+ | "declined"
757
+ | "not-asked"
758
+ | "cancelled";
613
759
 
614
760
  /**
615
761
  * TeX Live, for `paperlint build` — `paperlint lint` needs none. OFFERED to a human with its cost
@@ -619,21 +765,20 @@ export type TexOutcome =
619
765
  export async function offerTexLive(
620
766
  tex: InitOptions["tex"],
621
767
  {
622
- ask,
768
+ prompts,
623
769
  interactive,
624
- }: { ask?: (q: string) => Promise<string>; interactive: boolean },
770
+ }: { prompts?: Prompts | undefined; interactive: boolean },
625
771
  ): Promise<TexOutcome> {
626
772
  if (tex?.installed()) return "was-installed";
627
- if (!interactive || !ask || !tex?.install) return "not-asked";
628
- const answer = (
629
- await askOrDefault(
630
- ask,
631
- ` install TeX Live now, for \`paperlint build\`? (${TOOLCHAIN_COST}) [y/N] `,
632
- )
633
- )
634
- ?.trim()
635
- .toLowerCase();
636
- if (answer !== "y" && answer !== "yes") return "declined";
773
+ if (!interactive || !prompts || !tex?.install) return "not-asked";
774
+ const answer = await askOrNull(() =>
775
+ prompts.confirm({
776
+ message: `install TeX Live now, for \`paperlint build\`? (${TOOLCHAIN_COST})`,
777
+ initial: false,
778
+ }),
779
+ );
780
+ if (cancelled(answer)) return "cancelled";
781
+ if (!valueOr(answer, false)) return "declined";
637
782
  return tex.install() === 0 ? "installed" : "failed";
638
783
  }
639
784
 
@@ -642,6 +787,7 @@ export function reportTexLive(t: TexOutcome, why: string): string[] {
642
787
  const cmd = `npx paperlint toolchain # ${TOOLCHAIN_COST}`;
643
788
  if (t === "was-installed") return [` ✓ paperlint's TeX Live is installed`];
644
789
  if (t === "installed") return [` ✓ installed`];
790
+ if (t === "cancelled") return [CANCELLED_LINE];
645
791
  if (t === "failed")
646
792
  return [
647
793
  ` ✗ the install failed — see above. Run it again:`,
@@ -691,6 +837,76 @@ function papersLines(decl: DeclarationResult, why: string): string[] {
691
837
  ];
692
838
  }
693
839
 
840
+ /** The name of the first paper: `--paper`, else asked of a human when there is none yet. */
841
+ async function wantedPaper(
842
+ hasPaper: boolean,
843
+ {
844
+ paper,
845
+ asking: { prompts, interactive },
846
+ createPaper,
847
+ }: Readonly<FirstPaperDeps>,
848
+ ): Promise<Answer<string | null>> {
849
+ if (paper !== null || hasPaper || !interactive || !prompts || !createPaper)
850
+ return { kind: "answer", value: paper };
851
+ const answer = await askOrNull(() =>
852
+ prompts.text({
853
+ message: "create a first paper? its name (an empty line skips):",
854
+ placeholder: "skip",
855
+ }),
856
+ );
857
+ if (cancelled(answer)) return { kind: "cancel" };
858
+ return { kind: "answer", value: valueOr(answer, "").trim() || null };
859
+ }
860
+
861
+ interface FirstPaperDeps {
862
+ readonly papersDir: string;
863
+ readonly paper: string | null;
864
+ readonly asking: {
865
+ readonly prompts?: Prompts | undefined;
866
+ readonly interactive: boolean;
867
+ readonly why: string;
868
+ };
869
+ readonly createPaper?:
870
+ ((papersRoot: string, name: string) => Promise<number>) | undefined;
871
+ readonly venues: readonly NamedVenue[];
872
+ readonly log: (line: string) => void;
873
+ }
874
+
875
+ /** Step 6, a first paper: the exit code it owes (0 when none was asked for), or a cancel. */
876
+ async function firstPaper(
877
+ papersAbs: string,
878
+ deps: Readonly<FirstPaperDeps>,
879
+ ): Promise<number | "cancelled"> {
880
+ const { papersDir, asking, createPaper, venues, log } = deps;
881
+ const hasPaper = papersIn(papersAbs).length > 0;
882
+ const asked = await wantedPaper(hasPaper, deps);
883
+ if (asked.kind === "cancel") return "cancelled";
884
+ const wanted = asked.value;
885
+ if (wanted === null || !createPaper) {
886
+ log(
887
+ hasPaper
888
+ ? ` ✓ ${papersDir} already holds a paper`
889
+ : ` · none yet${asking.interactive ? "" : ` — ${asking.why}, so nothing was asked`}. \`npx paperlint new <name>\` or \`--paper <name>\` creates one`,
890
+ );
891
+ return 0;
892
+ }
893
+ const problem = nameProblem(wanted, venues);
894
+ if (problem) {
895
+ log(` ✗ no paper created — ${problem}`);
896
+ return 2;
897
+ }
898
+ const code = await createPaper(papersAbs, wanted);
899
+ if (code !== 0)
900
+ log(` ⚠ the new paper's lint exited ${String(code)} — see above`);
901
+ return code;
902
+ }
903
+
904
+ /** A question was cancelled: say so, and stop. */
905
+ const stop = (log: typeof console.log): number => (
906
+ log(CANCELLED_LINE),
907
+ CANCELLED_CODE
908
+ );
909
+
694
910
  // Documented in README.md#-getting-started and docs/install.md — update them when this changes.
695
911
  export async function init(
696
912
  dir: string,
@@ -701,7 +917,7 @@ export async function init(
701
917
  err = console.error,
702
918
  // eslint-disable-next-line no-restricted-globals -- legacy I/O, moves behind a port in #76
703
919
  cwd = process.cwd(),
704
- ask = askOnTerminal,
920
+ prompts,
705
921
  yes = false,
706
922
  hooks = true,
707
923
  merge,
@@ -711,6 +927,7 @@ export async function init(
711
927
  run = spawnSync,
712
928
  resolveCliPapers,
713
929
  link = (r: string) => linkSkills(r),
930
+ unlink = (r: string) => unlinkSkills(r),
714
931
  } = opts;
715
932
  // An injected `interactive` is a test standing in for a terminal; its reason is the classic one.
716
933
  const { interactive, why } =
@@ -731,8 +948,9 @@ export async function init(
731
948
  // ── 1. where the papers are, and 2. the declaration, in paperlint.json when not the default ─
732
949
  // The declaration is read FIRST: the directory is measured only when none is declared.
733
950
  const decl = await declarePapers(root, () =>
734
- choosePapers(root, { ask, interactive }),
951
+ choosePapers(root, { prompts, interactive }),
735
952
  );
953
+ if (decl.status === "cancelled") return stop(log);
736
954
  for (const line of papersLines(decl, why)) log(line);
737
955
  log(``);
738
956
  log(`settings`);
@@ -772,67 +990,57 @@ export async function init(
772
990
  return 2;
773
991
  }
774
992
 
775
- // ── 3. the skills, linked where Claude Code looks for them ─────────────────────────────
776
- for (const line of reportSkillLinks(link(root), here)) log(line);
777
-
778
- // ── 4. the hooks, wired where Claude Code reads them ───────────────────────────────────
779
- log(``);
780
- log(
781
- `hooks (Claude Code runs them from ${SETTINGS_PATH} — committed, shared with every clone)`,
782
- );
783
- const hooked = await offerHooks(root, { hooks, interactive, ask, merge });
784
- for (const line of reportHooks(hooked, {
785
- here,
786
- how: interactive
787
- ? `you were asked; \`--no-hooks\` skips this next time`
788
- : `default taken: YES — ${why}, so nothing was asked. \`--no-hooks\` skips this`,
789
- }))
993
+ // ── 3. the Claude Code plugin, which carries the skills and the hooks ──────────────────
994
+ const plugin = await offerPlugin(absolutePath(root), opts.claude, {
995
+ flag: opts.pluginFlag ?? null,
996
+ interactive,
997
+ why,
998
+ prompts,
999
+ });
1000
+ if (plugin.kind === "cancelled") return stop(log);
1001
+ reportPlugin(plugin).forEach((line) => {
790
1002
  log(line);
1003
+ });
1004
+
1005
+ // ── 4. without the plugin: the skills linked, the hooks wired; with it, init's old ones gone ─
1006
+ const wired = pluginOn(plugin)
1007
+ ? await retireOld(root, { unlink, merge, here, log })
1008
+ : await linkAndWire(root, {
1009
+ link,
1010
+ asking: { hooks, interactive, prompts, merge, why },
1011
+ here,
1012
+ log,
1013
+ });
1014
+ if (wired === "cancelled") return CANCELLED_CODE;
791
1015
 
792
1016
  // ── 5. the one expensive, unguessable thing ───────────────────────────────────────────
793
1017
  log(``);
794
1018
  log(`CI`);
795
- const wf = await offerWorkflow(root, { ask, interactive });
1019
+ const wf = await offerWorkflow(root, { prompts, interactive });
796
1020
  for (const line of reportWorkflow(wf, { why })) log(line);
1021
+ if (wf === "cancelled") return CANCELLED_CODE;
797
1022
 
798
1023
  // ── 6. a first paper — offered only where there is none, and only to a human ──────────
799
1024
  log(``);
800
1025
  log(`first paper`);
801
- const papersAbs = resolve(root, papersDir);
802
- const hasPaper = papersIn(papersAbs).length > 0;
803
- let wanted: string | null = paper;
804
1026
  // A paper that was asked for and not delivered decides the exit code (below): the doctor's
805
1027
  // code can be 0, and automation would read an unfulfilled `--paper` as done.
806
- let paperCode = 0;
807
- if (wanted === null && !hasPaper && interactive && createPaper) {
808
- const answer = (
809
- await askOrDefault(ask, ` create a first paper? name: [skip] `)
810
- )?.trim();
811
- wanted = answer ? answer : null;
812
- }
813
- if (wanted !== null && createPaper) {
814
- const problem = nameProblem(wanted, venues);
815
- if (problem) {
816
- log(` ✗ no paper created — ${problem}`);
817
- paperCode = 2;
818
- } else {
819
- const code = await createPaper(papersAbs, wanted);
820
- if (code !== 0) {
821
- log(` ⚠ the new paper's lint exited ${String(code)} — see above`);
822
- paperCode = code;
823
- }
824
- }
825
- } else if (hasPaper) log(` ✓ ${papersDir} already holds a paper`);
826
- else
827
- log(
828
- ` · none yet${interactive ? "" : ` — ${why}, so nothing was asked`}. \`npx paperlint new <name>\` or \`--paper <name>\` creates one`,
829
- );
1028
+ const paperCode = await firstPaper(resolve(root, papersDir), {
1029
+ papersDir,
1030
+ paper,
1031
+ asking: { prompts, interactive, why },
1032
+ createPaper,
1033
+ venues,
1034
+ log,
1035
+ });
1036
+ if (paperCode === "cancelled") return stop(log);
830
1037
 
831
1038
  // ── 7. TeX Live — offered to a human with its cost, never installed unasked ─────────────
832
1039
  log(``);
833
1040
  log(`TeX Live (for \`paperlint build\`; \`paperlint lint\` needs none)`);
834
- const texOutcome = await offerTexLive(opts.tex, { ask, interactive });
1041
+ const texOutcome = await offerTexLive(opts.tex, { prompts, interactive });
835
1042
  for (const line of reportTexLive(texOutcome, why)) log(line);
1043
+ if (texOutcome === "cancelled") return CANCELLED_CODE;
836
1044
 
837
1045
  // ── 8. the other programs are reported, never installed ────────────────────────────────
838
1046
  log(``);
@@ -871,7 +1079,16 @@ export async function init(
871
1079
  // ── 9. the install states its own condition ───────────────────────────────────────────
872
1080
  log(`── paperlint doctor ${"─".repeat(56)}`);
873
1081
  const cliPapers = resolveCliPapers ? resolveCliPapers(root) : papersDir;
874
- const code = doctor({ log, cwd: root, projectDir: root, run, cliPapers });
1082
+ // Read after step 3, as `paperlint doctor` reads it: the plugin carries the skills and hooks now.
1083
+ const at = absolutePath(root);
1084
+ const code = doctor({
1085
+ log,
1086
+ cwd: root,
1087
+ projectDir: root,
1088
+ run,
1089
+ cliPapers,
1090
+ plugin: opts.claude?.present(at) ? opts.claude.plugin(at) : null,
1091
+ });
875
1092
  if (code !== 0)
876
1093
  log(
877
1094
  `doctor exits ${String(code)} — the install is NOT finished. The lines marked ✗ above say what is\n` +