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
@@ -42,6 +42,24 @@ const { PROGRAMS } = await import(join(HERE, "doctor.ts"));
42
42
  // loads vigiles without recording a check is reported as having verified nothing.
43
43
  const check = createChecker();
44
44
 
45
+ /**
46
+ * init's `Prompts` port answered by `reply(message, options)`: a value, `undefined` (Enter: the
47
+ * initial value) or an Error (the stream ended). Every message asked lands in `asked`.
48
+ */
49
+ const answering = (reply, asked = []) => {
50
+ const one = async (message, initial, options) => {
51
+ asked.push(message);
52
+ const r = reply(message, options);
53
+ if (r instanceof Error) throw r;
54
+ return { kind: "answer", value: r === undefined ? initial : r };
55
+ };
56
+ return {
57
+ confirm: ({ message, initial }) => one(message, initial),
58
+ select: ({ message, initial, options }) => one(message, initial, options),
59
+ text: ({ message }) => one(message, ""),
60
+ };
61
+ };
62
+
45
63
  /** A paper.tex whose whole body is `body`. */
46
64
  const tex = (body) =>
47
65
  `\\documentclass{article}\n\\begin{document}\n${body}\n\\end{document}\n`;
@@ -71,6 +89,17 @@ async function cli(args, cwd) {
71
89
  const code = await run(args, {
72
90
  log: (...a) => stdout.push(a.join(" ")),
73
91
  err: (...a) => stderr.push(a.join(" ")),
92
+ // `init` never spawns a package manager here.
93
+ install: {
94
+ command: (_r, spec) => ["npm", spec],
95
+ run: () => ({ ok: true }),
96
+ },
97
+ // …nor finds Claude Code: the plugin offer has its own tests.
98
+ claude: {
99
+ present: () => false,
100
+ plugin: () => ({ enabled: false, version: null }),
101
+ enable: () => ({ ok: false, reason: "the harness turns nothing on" }),
102
+ },
74
103
  });
75
104
  return {
76
105
  code,
@@ -463,10 +492,7 @@ check(
463
492
  const asked = [];
464
493
  const wf = await offerWorkflow(dir, {
465
494
  interactive: true,
466
- ask: async (q) => {
467
- asked.push(q);
468
- return "y";
469
- },
495
+ prompts: answering(() => true, asked),
470
496
  });
471
497
  check(
472
498
  "saying yes WRITES the workflow",
@@ -489,7 +515,7 @@ check(
489
515
  check("the question is asked exactly once", asked.length === 1);
490
516
  const again = await offerWorkflow(dir, {
491
517
  interactive: true,
492
- ask: async () => "y",
518
+ prompts: answering(() => true),
493
519
  });
494
520
  check(
495
521
  "an existing workflow is neither overwritten nor asked about again",
@@ -500,7 +526,7 @@ check(
500
526
  const dir = project("ci-no", { papers: ["writing"] });
501
527
  const no = await offerWorkflow(dir, {
502
528
  interactive: true,
503
- ask: async () => "",
529
+ prompts: answering(() => undefined),
504
530
  });
505
531
  check(
506
532
  "an empty answer is a NO, and no file appears",
@@ -515,9 +541,7 @@ check(
515
541
  // i.e. the real defect would look like a hole in the test rather than a caught one.
516
542
  const aborted = await offerWorkflow(dir, {
517
543
  interactive: true,
518
- ask: async () => {
519
- throw new Error("Aborted with Ctrl+D");
520
- },
544
+ prompts: answering(() => new Error("Aborted with Ctrl+D")),
521
545
  }).catch((e) => `THREW: ${e?.message ?? e}`);
522
546
  check(
523
547
  "🔴 an interrupted question does NOT crash the command — it means the default",
@@ -530,7 +554,7 @@ check(
530
554
  const dir = project("many", { papers: ["alpha", "beta"] });
531
555
  const picked = await choosePapers(dir, {
532
556
  interactive: true,
533
- ask: async () => "2",
557
+ prompts: answering((_q, options) => options?.[1]),
534
558
  });
535
559
  check(
536
560
  "🔴 the human's answer DECIDES, it does not just decorate the output",
@@ -543,9 +567,7 @@ check(
543
567
  );
544
568
  const aborted = await choosePapers(dir, {
545
569
  interactive: true,
546
- ask: async () => {
547
- throw new Error("Aborted with Ctrl+D");
548
- },
570
+ prompts: answering(() => new Error("Aborted with Ctrl+D")),
549
571
  }).catch((e) => ({
550
572
  how: `THREW: ${e?.message ?? e}`,
551
573
  papers: null,
@@ -1510,14 +1532,14 @@ console.log(
1510
1532
  await init(dir, {
1511
1533
  ...quiet,
1512
1534
  interactive: true,
1513
- ask: async (q) => {
1514
- asked.push(q);
1515
- return /\[Y\/n\]/.test(q) ? "n" : "";
1516
- },
1535
+ prompts: answering(
1536
+ (q) => (/wire the paper hooks/.test(q) ? false : undefined),
1537
+ asked,
1538
+ ),
1517
1539
  });
1518
1540
  check(
1519
- "a human is asked [Y/n] for the hooks",
1520
- asked.some((q) => /wire the paper hooks .*\[Y\/n\]/.test(q)),
1541
+ "a human is asked about the hooks",
1542
+ asked.some((q) => /wire the paper hooks/.test(q)),
1521
1543
  );
1522
1544
  check("and a no is respected", !existsSync(settings(dir)));
1523
1545
  }
@@ -1526,7 +1548,7 @@ console.log(
1526
1548
  await init(dir, {
1527
1549
  ...quiet,
1528
1550
  interactive: true,
1529
- ask: async () => "",
1551
+ prompts: answering(() => undefined),
1530
1552
  });
1531
1553
  check(
1532
1554
  "an empty answer is the stated default, YES",
@@ -1562,11 +1584,10 @@ console.log(
1562
1584
  ...base,
1563
1585
  log: () => {},
1564
1586
  interactive: true,
1565
- ask: async (q) => {
1566
- asked.push(q);
1567
- if (/create a first paper/.test(q)) return "first";
1568
- return "";
1569
- },
1587
+ prompts: answering(
1588
+ (q) => (/create a first paper/.test(q) ? "first" : undefined),
1589
+ asked,
1590
+ ),
1570
1591
  createPaper: async (papersRoot, name) => {
1571
1592
  made.push({ papersRoot, name });
1572
1593
  return 0;
@@ -1619,7 +1640,7 @@ console.log(
1619
1640
  ...base,
1620
1641
  log: () => {},
1621
1642
  interactive: true,
1622
- ask: async (q) => (asked.push(q), ""),
1643
+ prompts: answering(() => undefined, asked),
1623
1644
  createPaper: async () => 0,
1624
1645
  });
1625
1646
  check(
package/src/cli.test.ts CHANGED
@@ -6,7 +6,13 @@
6
6
  */
7
7
  import assert from "node:assert/strict";
8
8
  import { spawn } from "node:child_process";
9
- import { existsSync, readdirSync, readFileSync } from "node:fs";
9
+ import {
10
+ existsSync,
11
+ mkdirSync,
12
+ readdirSync,
13
+ readFileSync,
14
+ symlinkSync,
15
+ } from "node:fs";
10
16
  import { createServer } from "node:http";
11
17
  import { dirname, join } from "node:path";
12
18
  import { test, vi } from "vitest";
@@ -32,9 +38,16 @@ import {
32
38
  toolchainTex,
33
39
  } from "./cli.ts";
34
40
  import { texInputsDir } from "./package-dirs.ts";
41
+ import type { ClaudeCode } from "./ports/claude-code.ts";
35
42
 
36
43
  const root = useTempDir("cli-test-");
37
44
 
45
+ const NO_CLAUDE: ClaudeCode = {
46
+ present: () => false,
47
+ plugin: () => ({ enabled: false, version: null }),
48
+ enable: () => assert.fail("no test here turns the plugin on for real"),
49
+ };
50
+
38
51
  /**
39
52
  * `run(argv)` from `cwd`, the output as one string per stream. Its clock stands still, so `lint`'s
40
53
  * «linted N file(s) in 0.0 s» is the same however long the run took: under a loaded
@@ -43,7 +56,10 @@ const root = useTempDir("cli-test-");
43
56
  async function cli(
44
57
  argv: string[],
45
58
  cwd: string,
46
- deps: Pick<NonNullable<Parameters<typeof run>[1]>, "loadTexLanguage"> = {},
59
+ deps: Pick<
60
+ NonNullable<Parameters<typeof run>[1]>,
61
+ "loadTexLanguage" | "claude" | "install"
62
+ > = {},
47
63
  ) {
48
64
  const out: string[] = [];
49
65
  const err: string[] = [];
@@ -52,6 +68,13 @@ async function cli(
52
68
  err: (...a: unknown[]) => err.push(a.join(" ")),
53
69
  cwd,
54
70
  now: () => 0,
71
+ // `init` never spawns a package manager here: adding paperlint is `src/self-install.test.ts`'s.
72
+ install: {
73
+ command: (_root, spec) => ["npm", spec],
74
+ run: () => ({ ok: true }),
75
+ },
76
+ // …nor finds Claude Code, unless a test hands one: the offer itself is `src/plugin-offer.test.ts`'s.
77
+ claude: NO_CLAUDE,
55
78
  ...deps,
56
79
  });
57
80
  return { code, out: out.join("\n"), err: err.join("\n") };
@@ -478,6 +501,28 @@ test("chooseVenue: a preset by path (inside and outside the paper), by prefixed
478
501
  );
479
502
  });
480
503
 
504
+ test("doctor reads the plugin where Claude Code is, and says nothing of it where it is not", async () => {
505
+ const dir = join(root, "doctor-plugin");
506
+ writeTree(dir, { "paperlint.json": "{}" });
507
+ const read: string[] = [];
508
+ const claude: ClaudeCode = {
509
+ ...NO_CLAUDE,
510
+ present: () => true,
511
+ plugin: (at) => (read.push(at), { enabled: true, version: "1.0.0" }),
512
+ };
513
+ const head = "Claude Code plugin (carries the skills and the hooks)";
514
+ const on = (await cli(["doctor"], dir, { claude })).out.split("\n");
515
+ const absent = (await cli(["doctor"], dir)).out.split("\n");
516
+ assert.deepEqual(
517
+ [
518
+ on.slice(on.indexOf(head), on.indexOf(head) + 2),
519
+ read,
520
+ absent.includes(head),
521
+ ],
522
+ [[head, " ✓ on for this project, version 1.0.0"], [dir], false],
523
+ );
524
+ });
525
+
481
526
  test("doctor reads a broken config as 'the CLI would lint nothing' instead of stopping", async () => {
482
527
  const dir = join(root, "doctor-broken");
483
528
  writeTree(dir, { "paperlint.json": "{ not json" });
@@ -739,6 +784,138 @@ test("init with no path sets up the current directory, and its first paper is pa
739
784
  assert.equal(made.includes("main.tex"), false);
740
785
  });
741
786
 
787
+ test("init --plugin turns the plugin on without a terminal; --no-plugin never asks; neither, one line", async () => {
788
+ const on: string[] = [];
789
+ const claude: ClaudeCode = {
790
+ present: () => true,
791
+ // Installed once both commands ran, as Claude Code then reads it.
792
+ plugin: (at) =>
793
+ on.includes(at)
794
+ ? { enabled: true, version: "1.0.0" }
795
+ : { enabled: false, version: null },
796
+ enable: (at) => (on.push(at), { ok: true, ran: ["claude x"] }),
797
+ };
798
+ const run = async (flag: string[]) => {
799
+ const dir = writeTree(join(root, `offer${flag.join("")}`), {
800
+ "package.json": "{}",
801
+ });
802
+ const out = (await cli(["init", "--yes", ...flag], dir, { claude })).out;
803
+ return out
804
+ .split("\n")
805
+ .filter(
806
+ (l) =>
807
+ l.startsWith("Claude Code plugin") ||
808
+ l.startsWith(" · --no-plugin") ||
809
+ l.startsWith("skills and hooks (") ||
810
+ l === " ✓ ran claude x",
811
+ );
812
+ };
813
+ // Each run ends with init's own doctor check, which reads the plugin as `paperlint doctor` does.
814
+ assert.deepEqual(
815
+ [
816
+ await run(["--plugin"]),
817
+ await run(["--no-plugin"]),
818
+ await run([]),
819
+ on.length,
820
+ ],
821
+ [
822
+ [
823
+ "Claude Code plugin (the skills and hooks, updated with paperlint)",
824
+ " ✓ ran claude x",
825
+ "skills and hooks (the plugin carries them now)",
826
+ "Claude Code plugin (carries the skills and the hooks)",
827
+ ],
828
+ [
829
+ "Claude Code plugin (the skills and hooks, updated with paperlint)",
830
+ " · --no-plugin — nothing asked, nothing turned on",
831
+ "Claude Code plugin (carries the skills and the hooks)",
832
+ ],
833
+ [
834
+ "Claude Code plugin: not turned on — --yes was given, so nothing was asked. To turn it on: npx paperlint init --plugin",
835
+ "Claude Code plugin (carries the skills and the hooks)",
836
+ ],
837
+ 1,
838
+ ],
839
+ );
840
+ });
841
+
842
+ test("init's step 0 that fails stops the run with 2: init itself never starts", async () => {
843
+ const dir = writeTree(join(root, "self-failed"), { "package.json": "{}" });
844
+ const r = await cli(["init", "--yes", "--no-hooks"], dir, {
845
+ install: {
846
+ command: (_root, spec) => ["npm", spec],
847
+ run: () => ({ ok: false, reason: "exit 1" }),
848
+ },
849
+ });
850
+ assert.deepEqual(
851
+ {
852
+ code: r.code,
853
+ out: r.out.split("\n"),
854
+ paperlintJson: existsSync(join(dir, "paperlint.json")),
855
+ },
856
+ {
857
+ code: 2,
858
+ out: [
859
+ "",
860
+ "paperlint in this project",
861
+ " → npm paperlint@0.0.0-semantically-released",
862
+ " ✗ npm paperlint@0.0.0-semantically-released failed (exit 1) — nothing else was done. Run it yourself, then `npx paperlint init` again",
863
+ ],
864
+ paperlintJson: false,
865
+ },
866
+ );
867
+ });
868
+
869
+ test("init's step 0 reads the project's own copy: this checkout is present, another version is said and kept", async () => {
870
+ const pkg = (dir: string) => join(dir, "node_modules", "paperlint");
871
+ const own = writeTree(join(root, "self-own"), { "package.json": "{}" });
872
+ mkdirSync(join(own, "node_modules"));
873
+ symlinkSync(dirname(import.meta.dirname), pkg(own));
874
+ const older = writeTree(join(root, "self-older"), {
875
+ "package.json": "{}",
876
+ "node_modules/paperlint/package.json":
877
+ '{"name":"paperlint","version":"0.0.1"}',
878
+ });
879
+ const unversioned = writeTree(join(root, "self-unversioned"), {
880
+ "package.json": "{}",
881
+ "node_modules/paperlint/package.json": '{"name":"paperlint"}',
882
+ });
883
+ const head = async (dir: string) =>
884
+ (await cli(["init", "--yes", "--no-hooks"], dir)).out
885
+ .split("\n")
886
+ .slice(0, 4);
887
+ assert.deepEqual(
888
+ [await head(own), await head(older), await head(unversioned)],
889
+ [
890
+ [
891
+ "",
892
+ "paperlint init — each decision below says HOW it was decided",
893
+ "",
894
+ "papers directory",
895
+ ],
896
+ [
897
+ "",
898
+ "paperlint in this project",
899
+ " ⚠ paperlint 0.0.1 is installed in this project, and this command is 0.0.0-semantically-released: kept 0.0.1, nothing up- or downgraded",
900
+ " to move the project to 0.0.0-semantically-released: npm paperlint@0.0.0-semantically-released",
901
+ ],
902
+ [
903
+ "",
904
+ "paperlint in this project",
905
+ " → npm paperlint@0.0.0-semantically-released",
906
+ " ✓ added paperlint to devDependencies",
907
+ ],
908
+ ],
909
+ );
910
+ // What is added can be named instead: the install e2e adds the packed tarball.
911
+ vi.stubEnv("PAPERLINT_INSTALL_SPEC", "/tmp/p.tgz");
912
+ try {
913
+ assert.equal((await head(unversioned))[2], " → npm /tmp/p.tgz");
914
+ } finally {
915
+ vi.unstubAllEnvs();
916
+ }
917
+ });
918
+
742
919
  test("init and doctor with a declaration that names no directory: nothing to compare", async () => {
743
920
  const dir = writeTree(join(root, "init-empty"), {
744
921
  "package.json": "{}",
package/src/cli.ts CHANGED
@@ -24,7 +24,14 @@
24
24
  * replaced it: silently breaking someone else's workflow is worse than asking them to fix a line.
25
25
  */
26
26
  import { ESLint, type Linter } from "eslint";
27
- import { readFileSync, readdirSync, existsSync, statSync } from "node:fs";
27
+ import {
28
+ readFileSync,
29
+ readdirSync,
30
+ existsSync,
31
+ realpathSync,
32
+ statSync,
33
+ } from "node:fs";
34
+ import { absolutePath } from "./domain/paths.ts";
28
35
  import { createRequire } from "node:module";
29
36
  import { stripVTControlCharacters } from "node:util";
30
37
  import { spawnSync } from "node:child_process";
@@ -152,9 +159,12 @@ import {
152
159
  type TexRequirements,
153
160
  } from "./tex-requirements.ts";
154
161
  import { doctor } from "./doctor.ts";
162
+ import { installedPluginVersion } from "./plugin-offer.ts";
155
163
  import {
156
164
  askOnTerminal,
157
165
  askOrDefault,
166
+ CANCELLED_CODE,
167
+ CANCELLED_LINE,
158
168
  init,
159
169
  processInteractivity,
160
170
  } from "./init.ts";
@@ -233,7 +243,21 @@ import {
233
243
  recordTold,
234
244
  } from "./hooks-notice.ts";
235
245
  import { unwiredHooks } from "./hooks-settings.ts";
236
- import { linkSkills, unlinkedSkills, type LinkReport } from "./link-skills.ts";
246
+ import {
247
+ linkSkills,
248
+ locatePackage,
249
+ unlinkedSkills,
250
+ type LinkReport,
251
+ } from "./link-skills.ts";
252
+ import { projectInstall } from "./adapters/package-manager/index.ts";
253
+ import type { ProjectInstall } from "./ports/project-install.ts";
254
+ import { claudeCode } from "./adapters/claude-code/index.ts";
255
+ import type { ClaudeCode } from "./ports/claude-code.ts";
256
+ import {
257
+ selfInstallStep,
258
+ versionOf,
259
+ type SelfInstallDeps,
260
+ } from "./self-install.ts";
237
261
  import {
238
262
  lintEditedHook,
239
263
  type LintResult,
@@ -360,6 +384,10 @@ init:
360
384
  --yes, -y ask nothing, take every default. Without a terminal on stdin AND stdout,
361
385
  or with CI set, nothing is asked either
362
386
  --no-hooks do not wire the hooks (the default without a human is to wire them)
387
+ --plugin turn on the Claude Code plugin (the skills and hooks) without asking, with
388
+ or without a terminal. Without a human and without this flag, init turns
389
+ nothing on and prints one line saying so
390
+ --no-plugin never ask about the plugin, never turn it on
363
391
  --paper <name> create this paper too (without a human, the only way init creates one)
364
392
 
365
393
  new:
@@ -1185,6 +1213,8 @@ export function parseArgs(argv: readonly string[]): Args {
1185
1213
  check: false,
1186
1214
  yes: false,
1187
1215
  noHooks: false,
1216
+ plugin: false,
1217
+ noPlugin: false,
1188
1218
  allowVenueName: false,
1189
1219
  paper: null,
1190
1220
  venue: null,
@@ -1270,6 +1300,8 @@ const SWITCHES: ReadonlyMap<
1270
1300
  | "check"
1271
1301
  | "yes"
1272
1302
  | "noHooks"
1303
+ | "plugin"
1304
+ | "noPlugin"
1273
1305
  | "allowVenueName"
1274
1306
  | "submit"
1275
1307
  | "save"
@@ -1282,6 +1314,8 @@ const SWITCHES: ReadonlyMap<
1282
1314
  ["--yes", "yes"],
1283
1315
  ["-y", "yes"],
1284
1316
  ["--no-hooks", "noHooks"],
1317
+ ["--plugin", "plugin"],
1318
+ ["--no-plugin", "noPlugin"],
1285
1319
  ["--allow-venue-name", "allowVenueName"],
1286
1320
  ["--submit", "submit"],
1287
1321
  ["--save", "save"],
@@ -1572,6 +1606,8 @@ interface HookOptions {
1572
1606
  readonly version?: string;
1573
1607
  /** What `paperlint doctor` reads to find unlinked skills; the disk by default. */
1574
1608
  readonly skillLinks?: (root: string) => LinkReport;
1609
+ /** Whether the Claude Code plugin is on; the disk by default. */
1610
+ readonly claude?: ClaudeCode;
1575
1611
  }
1576
1612
 
1577
1613
  const readSkillLinks = (root: string): LinkReport =>
@@ -1612,6 +1648,25 @@ const packageVersion = (): string =>
1612
1648
  ),
1613
1649
  ).version;
1614
1650
 
1651
+ /**
1652
+ * What the project still owes of the hooks and skills — nothing once the Claude Code plugin is on: the
1653
+ * plugin carries both, so a project without init's links and hook entries is complete.
1654
+ */
1655
+ function owed(
1656
+ root: string,
1657
+ skillLinks: (root: string) => LinkReport,
1658
+ claude: ClaudeCode,
1659
+ ): {
1660
+ readonly missing: readonly string[];
1661
+ readonly byHand: boolean;
1662
+ readonly skills: readonly string[];
1663
+ } {
1664
+ if (installedPluginVersion(claude.plugin(absolutePath(root))) !== null)
1665
+ return { missing: [], byHand: false, skills: [] };
1666
+ const { missing, byHand } = unwiredHooks(root);
1667
+ return { missing, byHand, skills: unlinkedSkills(skillLinks(root)) };
1668
+ }
1669
+
1615
1670
  interface Pending {
1616
1671
  readonly text: string;
1617
1672
  readonly root: string;
@@ -1625,8 +1680,11 @@ interface Pending {
1625
1680
  function pendingNotice(io: ResolvedHookOptions): Pending | null {
1626
1681
  try {
1627
1682
  const root = hookRoot(io);
1628
- const { missing, byHand } = unwiredHooks(root);
1629
- const skills = unlinkedSkills((io.skillLinks ?? readSkillLinks)(root));
1683
+ const { missing, byHand, skills } = owed(
1684
+ root,
1685
+ io.skillLinks ?? readSkillLinks,
1686
+ io.claude ?? claudeCode(),
1687
+ );
1630
1688
  const version = io.version ?? packageVersion();
1631
1689
  return (missing.length === 0 && skills.length === 0) ||
1632
1690
  !notYetTold(nodeFiles, root, version)
@@ -1655,10 +1713,10 @@ function hooksLine(
1655
1713
  root: string,
1656
1714
  err: typeof console.error,
1657
1715
  skillLinks: (root: string) => LinkReport,
1716
+ claude: ClaudeCode,
1658
1717
  ): void {
1659
1718
  try {
1660
- const { missing } = unwiredHooks(root);
1661
- const skills = unlinkedSkills(skillLinks(root));
1719
+ const { missing, skills } = owed(root, skillLinks, claude);
1662
1720
  if (missing.length > 0 || skills.length > 0)
1663
1721
  err(lintLine(packageVersion(), missing, skills));
1664
1722
  } catch {
@@ -2381,7 +2439,15 @@ async function runInit(
2381
2439
  log,
2382
2440
  err,
2383
2441
  cwd,
2384
- }: { log: typeof console.log; err: typeof console.error; cwd: string },
2442
+ install,
2443
+ claude,
2444
+ }: {
2445
+ log: typeof console.log;
2446
+ err: typeof console.error;
2447
+ cwd: string;
2448
+ install: ProjectInstall;
2449
+ claude: ClaudeCode;
2450
+ },
2385
2451
  ): Promise<number> {
2386
2452
  // Deferred, not implemented: named and refused, rather than read as the directory argument.
2387
2453
  if (a.hooksMode !== null) {
@@ -2391,12 +2457,26 @@ async function runInit(
2391
2457
  );
2392
2458
  return 2;
2393
2459
  }
2460
+ // Loaded here, not at the top: every hook runs through this file, and none of them asks anything.
2461
+ const { clackPrompts } = await import("./adapters/clack/index.ts");
2462
+ const prompts = clackPrompts();
2463
+ // Step 0, before init: paperlint itself, in the project's devDependencies (`self-install.ts`).
2464
+ const stop = await selfInstallStep(
2465
+ absolutePath(resolve(cwd, a.paths[0] ?? ".")),
2466
+ selfInstallDeps(install),
2467
+ { prompts, interactive: processInteractivity(a.yes).interactive, log },
2468
+ { code: CANCELLED_CODE, line: CANCELLED_LINE },
2469
+ );
2470
+ if (stop !== null) return stop;
2394
2471
  return await init(a.paths[0] ?? ".", {
2395
2472
  log,
2396
2473
  err,
2397
2474
  cwd,
2475
+ prompts,
2398
2476
  yes: a.yes,
2399
2477
  hooks: !a.noHooks,
2478
+ claude,
2479
+ pluginFlag: a.plugin ? "plugin" : a.noPlugin ? "no-plugin" : null,
2400
2480
  paper: a.paper,
2401
2481
  createPaper: (papersRoot, name) =>
2402
2482
  createPaperAt(papersRoot, name, { log, err, cwd }),
@@ -2407,6 +2487,35 @@ async function runInit(
2407
2487
  });
2408
2488
  }
2409
2489
 
2490
+ /** This copy of paperlint: its real directory and its version. */
2491
+ const runningCopy = (): { readonly dir: string; readonly version: string } => ({
2492
+ dir: realpathSync(fileURLToPath(new URL("..", import.meta.url))),
2493
+ version: packageVersion(),
2494
+ });
2495
+
2496
+ /**
2497
+ * What `init` needs to add paperlint to a project. `PAPERLINT_INSTALL_SPEC` replaces what is added
2498
+ * (a tarball, for the install e2e: an unreleased build's version is on no registry).
2499
+ */
2500
+ const selfInstallDeps = (install: ProjectInstall): SelfInstallDeps => {
2501
+ const running = runningCopy();
2502
+ return {
2503
+ running,
2504
+ installed: (root) => {
2505
+ const at = locatePackage(root);
2506
+ if ("error" in at) return null;
2507
+ const version = versionOf(
2508
+ nodeFiles.readBytes(absolutePath(join(at.dir, "package.json"))),
2509
+ );
2510
+ return version === null ? null : { dir: at.dir, version };
2511
+ },
2512
+ files: nodeFiles,
2513
+ install,
2514
+ spec:
2515
+ process.env["PAPERLINT_INSTALL_SPEC"] ?? `paperlint@${running.version}`,
2516
+ };
2517
+ };
2518
+
2410
2519
  /** The LaTeX language, loaded when a lint needs it: only `lint` and the `lint-edited` hook do. */
2411
2520
  const loadLatexLanguage = async (): Promise<unknown> =>
2412
2521
  (await import("#eslint-rules/latex-language")).texLanguage;
@@ -2421,10 +2530,16 @@ export async function run(
2421
2530
  checkReferences = onlineReferences,
2422
2531
  loadTexLanguage = loadLatexLanguage,
2423
2532
  skillLinks = readSkillLinks,
2533
+ install = projectInstall,
2534
+ claude = claudeCode(),
2424
2535
  }: {
2425
2536
  log?: typeof console.log;
2426
2537
  err?: typeof console.error;
2427
2538
  cwd?: string;
2539
+ /** How `init` adds paperlint to a project: the package manager by default; a test hands a fake. */
2540
+ install?: ProjectInstall;
2541
+ /** Claude Code as `init` and `doctor` see it: the disk and `claude` by default; a test hands a fake. */
2542
+ claude?: ClaudeCode;
2428
2543
  /** The clock `lint` times itself with, in milliseconds; a test hands one that answers fixed values. */
2429
2544
  now?: () => number;
2430
2545
  /**
@@ -2466,17 +2581,22 @@ export async function run(
2466
2581
  // `init` asks the CLI's OWN reader what it would lint, so the two sides `doctor` compares are
2467
2582
  // not two implementations of the same question. A second resolver here is the defect the
2468
2583
  // comparison exists to catch.
2469
- if (a.cmd === "init") return await runInit(a, { log, err, cwd });
2584
+ if (a.cmd === "init")
2585
+ return await runInit(a, { log, err, cwd, install, claude });
2470
2586
  // `doctor` reads the config but must NOT die on a broken one — reporting that the config is
2471
2587
  // broken is precisely its job. So a failed read becomes "the CLI would lint nothing", which is
2472
2588
  // what it prints, rather than an early exit that tells the reader nothing about the hooks.
2473
2589
  if (a.cmd === "doctor") {
2474
2590
  const papers = cliPapers(a, cwd);
2591
+ const projectDir = process.env["CLAUDE_PROJECT_DIR"] ?? cwd;
2592
+ const at = absolutePath(resolve(cwd, projectDir));
2475
2593
  return doctor({
2476
2594
  log,
2477
2595
  cwd,
2478
- projectDir: process.env["CLAUDE_PROJECT_DIR"] ?? cwd,
2596
+ projectDir,
2479
2597
  cliPapers: papers,
2598
+ plugin: claude.present(at) ? claude.plugin(at) : null,
2599
+ installed: packageVersion(),
2480
2600
  });
2481
2601
  }
2482
2602
  const simple = SIMPLE[a.cmd];
@@ -2594,7 +2714,7 @@ export async function run(
2594
2714
  .filter((f) => existsSync(f)),
2595
2715
  bodies,
2596
2716
  });
2597
- hooksLine(root, err, skillLinks);
2717
+ hooksLine(root, err, skillLinks, claude);
2598
2718
  // On stderr, so `--json` leaves stdout a clean array.
2599
2719
  timingLines({
2600
2720
  files: results.length,