paperlint 18.4.0 → 18.5.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 (104) hide show
  1. package/CLAUDE.md +5 -1
  2. package/dist/adapters/latex/abstract.d.ts +11 -0
  3. package/dist/adapters/latex/abstract.d.ts.map +1 -1
  4. package/dist/adapters/latex/abstract.js +1 -1
  5. package/dist/adapters/latex/abstract.js.map +1 -1
  6. package/dist/adapters/latex/index.d.ts.map +1 -1
  7. package/dist/adapters/latex/index.js +3 -0
  8. package/dist/adapters/latex/index.js.map +1 -1
  9. package/dist/adapters/latex/macros.d.ts +6 -0
  10. package/dist/adapters/latex/macros.d.ts.map +1 -0
  11. package/dist/adapters/latex/macros.js +27 -0
  12. package/dist/adapters/latex/macros.js.map +1 -0
  13. package/dist/adapters/osf/host.io.d.ts +12 -0
  14. package/dist/adapters/osf/host.io.d.ts.map +1 -0
  15. package/dist/adapters/osf/host.io.js +119 -0
  16. package/dist/adapters/osf/host.io.js.map +1 -0
  17. package/dist/adapters/osf/index.d.ts +10 -0
  18. package/dist/adapters/osf/index.d.ts.map +1 -0
  19. package/dist/adapters/osf/index.js +10 -0
  20. package/dist/adapters/osf/index.js.map +1 -0
  21. package/dist/adapters/osf/response.d.ts +11 -0
  22. package/dist/adapters/osf/response.d.ts.map +1 -0
  23. package/dist/adapters/osf/response.js +87 -0
  24. package/dist/adapters/osf/response.js.map +1 -0
  25. package/dist/artifact-upload-rule.d.ts +66 -0
  26. package/dist/artifact-upload-rule.d.ts.map +1 -0
  27. package/dist/artifact-upload-rule.js +151 -0
  28. package/dist/artifact-upload-rule.js.map +1 -0
  29. package/dist/artifact.d.ts +35 -0
  30. package/dist/artifact.d.ts.map +1 -0
  31. package/dist/artifact.js +251 -0
  32. package/dist/artifact.js.map +1 -0
  33. package/dist/cli.d.ts +9 -1
  34. package/dist/cli.d.ts.map +1 -1
  35. package/dist/cli.js +136 -23
  36. package/dist/cli.js.map +1 -1
  37. package/dist/domain/artifact-upload.d.ts +44 -0
  38. package/dist/domain/artifact-upload.d.ts.map +1 -0
  39. package/dist/domain/artifact-upload.js +80 -0
  40. package/dist/domain/artifact-upload.js.map +1 -0
  41. package/dist/domain/paper-dirs.d.ts +16 -0
  42. package/dist/domain/paper-dirs.d.ts.map +1 -0
  43. package/dist/domain/paper-dirs.js +42 -0
  44. package/dist/domain/paper-dirs.js.map +1 -0
  45. package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  46. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  47. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  48. package/dist/paper-files.d.ts +25 -42
  49. package/dist/paper-files.d.ts.map +1 -1
  50. package/dist/paper-files.js +101 -9
  51. package/dist/paper-files.js.map +1 -1
  52. package/dist/ports/artifact-host.d.ts +54 -0
  53. package/dist/ports/artifact-host.d.ts.map +1 -0
  54. package/dist/ports/artifact-host.js +2 -0
  55. package/dist/ports/artifact-host.js.map +1 -0
  56. package/dist/ports/latex.d.ts +9 -0
  57. package/dist/ports/latex.d.ts.map +1 -1
  58. package/dist/submission-confirm-hook.d.ts +11 -1
  59. package/dist/submission-confirm-hook.d.ts.map +1 -1
  60. package/dist/submission-confirm-hook.js +83 -21
  61. package/dist/submission-confirm-hook.js.map +1 -1
  62. package/dist/types.d.ts +6 -0
  63. package/dist/types.d.ts.map +1 -1
  64. package/docs/artifact-upload.md +124 -0
  65. package/docs/optional-rules.md +1 -0
  66. package/docs/osf-artifact.md +4 -1
  67. package/docs/rules/artifact/upload-current.md +85 -0
  68. package/docs/rules.md +1 -0
  69. package/eslint-rules/CLAUDE.md +5 -1
  70. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  71. package/package.json +1 -1
  72. package/src/adapters/latex/abstract.ts +3 -1
  73. package/src/adapters/latex/index.ts +3 -0
  74. package/src/adapters/latex/macros.test.ts +31 -0
  75. package/src/adapters/latex/macros.ts +43 -0
  76. package/src/adapters/osf/cassette/README.md +20 -0
  77. package/src/adapters/osf/cassette/get-file.json +108 -0
  78. package/src/adapters/osf/cassette/get-listing.json +111 -0
  79. package/src/adapters/osf/cassette/get-missing.json +1 -0
  80. package/src/adapters/osf/cassette/put-new.json +31 -0
  81. package/src/adapters/osf/host.io.ts +156 -0
  82. package/src/adapters/osf/host.test.ts +274 -0
  83. package/src/adapters/osf/index.ts +14 -0
  84. package/src/adapters/osf/response.ts +105 -0
  85. package/src/artifact-upload-rule.test.ts +213 -0
  86. package/src/artifact-upload-rule.ts +213 -0
  87. package/src/artifact.test.ts +504 -0
  88. package/src/artifact.ts +402 -0
  89. package/src/cli.test.ts +271 -1
  90. package/src/cli.ts +168 -23
  91. package/src/domain/artifact-upload.test.ts +80 -0
  92. package/src/domain/artifact-upload.ts +111 -0
  93. package/src/domain/paper-dirs.test.ts +91 -0
  94. package/src/domain/paper-dirs.ts +62 -0
  95. package/src/new-paper.test.ts +8 -2
  96. package/src/paper-files.test.ts +88 -0
  97. package/src/paper-files.ts +98 -9
  98. package/src/paper-settings-commands.test.ts +18 -0
  99. package/src/ports/artifact-host.ts +65 -0
  100. package/src/ports/latex.ts +10 -0
  101. package/src/rule-cases.test.ts +44 -0
  102. package/src/submission-confirm-hook.test.ts +113 -1
  103. package/src/submission-confirm-hook.ts +120 -27
  104. package/src/types.ts +6 -0
@@ -3,7 +3,8 @@
3
3
  * PreToolUse on `Bash` (`plugin/hooks/hooks.json`): a command that sends a submission — `paperlint
4
4
  * submission new|update` with `--save` or `--submit` — runs only when the person has said yes, in an
5
5
  * `AskUserQuestion` asked since the last send, to a question naming the paper folder (its full path)
6
- * and the sha256 of the PDF it sends.
6
+ * and the sha256 of the PDF it sends. An upload of the artifact, `paperlint artifact upload … --save`,
7
+ * is a send too: the question names the paper folder and the sha256 of the file it uploads.
7
8
  * A command that names a portal's host runs only after a yes to a question naming that host and the
8
9
  * command's first 60 characters. Without the yes the command is refused (`"permissionDecision":
9
10
  * "deny"`), and the reason tells the agent exactly what to ask. Anything else: no output.
@@ -90,6 +91,8 @@ export type ConfirmDeps = PresetDeps & {
90
91
  * `--pdf` the send names (null for the defaults), or null when they do not parse cleanly.
91
92
  */
92
93
  readonly readSend: (words: readonly string[]) => Send | null;
94
+ /** The words after `artifact`, read the same way: the paper and the file an upload names, or null. */
95
+ readonly readUpload: (words: readonly string[]) => Upload | null;
93
96
  };
94
97
 
95
98
  /** What Claude Code reads from a PreToolUse hook's stdout to refuse the command; the agent sees the reason. */
@@ -129,22 +132,45 @@ function allLeaves(
129
132
  ];
130
133
  }
131
134
 
132
- /** A `paperlint submission new|update` with `--save` or `--submit`, in the words of one command. */
135
+ /**
136
+ * Where a `paperlint artifact … upload … --save` stands in one command's words; -1 for none. The CLI
137
+ * reads the subcommand wherever the flags leave it (`artifact --to osf upload …`), so any `upload`
138
+ * after `artifact` counts here; `readUpload`, the CLI's own parser, then reads the words, and words
139
+ * it cannot read cleanly are refused rather than let through.
140
+ */
141
+ const uploadAt = (l: ShellLeaf): number =>
142
+ l.hasFlag("save")
143
+ ? l.args.findIndex(
144
+ (x, i) => x === "artifact" && l.args.slice(i + 1).includes("upload"),
145
+ )
146
+ : -1;
147
+
148
+ /** A `paperlint submission new|update` with `--save` or `--submit`, or an upload that saves, in the words of one command. */
133
149
  function isSend(l: ShellLeaf): boolean {
134
150
  const at = l.args.indexOf("submission");
135
151
  return (
136
- at >= 0 &&
137
- l.args.slice(at + 1).some((w) => w === "new" || w === "update") &&
138
- l.hasFlag("save", "submit")
152
+ (at >= 0 &&
153
+ l.args.slice(at + 1).some((w) => w === "new" || w === "update") &&
154
+ l.hasFlag("save", "submit")) ||
155
+ uploadAt(l) >= 0
139
156
  );
140
157
  }
141
158
 
142
- /** One `paperlint submission new|update` send: the paper folder and `--pdf` it names; null for the default. */
159
+ /** One send: the paper folder and the `--pdf` a `submission new|update` names (null for the default). */
143
160
  export interface Send {
144
161
  readonly paper: string | null;
145
162
  readonly pdf: string | null;
146
163
  }
147
164
 
165
+ /** One `artifact upload --save`: the paper (null for the current folder), the file, and where it goes. */
166
+ export interface Upload {
167
+ readonly paper: string | null;
168
+ readonly artifact: string;
169
+ /** The host's name (`--to`) and the project on it (`--node`). */
170
+ readonly host: string;
171
+ readonly project: string;
172
+ }
173
+
148
174
  /** Programs that change the directory the rest of the command line runs in. */
149
175
  const MOVES: ReadonlySet<string> = new Set(["cd", "pushd", "popd"]);
150
176
 
@@ -155,18 +181,25 @@ const MOVES: ReadonlySet<string> = new Set(["cd", "pushd", "popd"]);
155
181
  */
156
182
  function sendsIn(
157
183
  leaves: readonly ShellLeaf[],
158
- readSend: ConfirmDeps["readSend"],
159
- ): readonly (Send | null)[] {
184
+ deps: Pick<ConfirmDeps, "readSend" | "readUpload">,
185
+ ): readonly (Send | Upload | null)[] {
160
186
  return leaves.flatMap((l, n) => {
161
187
  const at = l.args.findIndex(
162
188
  (x, i) =>
163
189
  x === "submission" && /^(?:new|update)$/u.test(l.args[i + 1] ?? ""),
164
190
  );
165
- if (at < 0 || !l.hasFlag("save", "submit")) return [];
191
+ const sends = at >= 0 && l.hasFlag("save", "submit");
192
+ const up = uploadAt(l);
193
+ if (!sends && up < 0) return [];
166
194
  const moved = leaves
167
195
  .slice(0, n + 1)
168
196
  .some((x) => MOVES.has(x.head) || x.chdir !== null);
169
- return [moved ? null : readSend(l.args.slice(at + 1))];
197
+ if (moved) return [null];
198
+ return [
199
+ sends
200
+ ? deps.readSend(l.args.slice(at + 1))
201
+ : deps.readUpload(l.args.slice(up + 1)),
202
+ ];
170
203
  });
171
204
  }
172
205
 
@@ -234,20 +267,47 @@ function factsLines(
234
267
  return [...stale, bodyPages(f.value)];
235
268
  }
236
269
 
237
- /** What a yes to one send must name: the paper folder as the hook resolves it, and the PDF's sha256 prefix. */
270
+ /**
271
+ * What a yes to one send must name: the paper folder as the hook resolves it, the file's sha256
272
+ * prefix, and, for an upload, the project it goes to.
273
+ */
238
274
  interface Named {
239
275
  readonly folder: string;
240
276
  readonly sha: string;
277
+ readonly project?: string;
241
278
  }
242
279
 
243
280
  /** One send, described: what a yes must name (null when the PDF is not found), and the lines for the person. */
244
281
  interface Described {
245
282
  readonly named: Named | null;
246
283
  readonly lines: readonly string[];
284
+ /** An artifact upload, not a submission. */
285
+ readonly upload?: true;
286
+ }
287
+
288
+ /** One upload, described: the paper, the file it uploads and its sha256, and where it goes. */
289
+ function describeUpload(u: Upload, cwd: string, files: Files): Described {
290
+ const paperDir = resolve(cwd, u.paper ?? ".");
291
+ const bytes = files.readBytes(callerPath(resolve(cwd, u.artifact)));
292
+ const sha = bytes === null ? null : sha256Hex(bytes).slice(0, SHA_SHOWN);
293
+ return {
294
+ upload: true,
295
+ named: sha === null ? null : { folder: paperDir, sha, project: u.project },
296
+ lines: [
297
+ `paper folder: ${paperDir}`,
298
+ `artifact: ${u.artifact}${sha === null ? " — NOT FOUND" : `, sha256 ${sha}`}`,
299
+ `to: ${u.host} project ${u.project}`,
300
+ ],
301
+ };
247
302
  }
248
303
 
249
304
  /** One send, described: the paper, the PDF as the command resolves it, what the build saw. */
250
- function describe(send: Send, cwd: string, deps: PresetDeps): Described {
305
+ function describe(
306
+ send: Send | Upload,
307
+ cwd: string,
308
+ deps: PresetDeps,
309
+ ): Described {
310
+ if ("artifact" in send) return describeUpload(send, cwd, deps.files);
251
311
  const paperDir = resolve(cwd, send.paper ?? ".");
252
312
  const p = paperPreset(paperDir, deps);
253
313
  const own = paperPdf(
@@ -277,6 +337,17 @@ const UNRESOLVED =
277
337
 
278
338
  const NOT_SENT = "Not run: this sends the paper to the venue's portal";
279
339
  const NAMES_PORTAL = "Not run: this command names a venue's submission portal";
340
+ const NOT_UPLOADED = "Not run: this uploads the paper's artifact to its host";
341
+
342
+ /** What to ask before an artifact upload. */
343
+ const HOW_TO_ASK_UPLOAD = [
344
+ "Ask the person with AskUserQuestion first, then run this command again. In the question, give the paper folder (the full path), the artifact's file and sha256, and the project, as written above.",
345
+ 'Options: "Yes, upload it" and "No". One yes lets one upload through.',
346
+ ].join("\n");
347
+
348
+ /** Whether every send of a command is an artifact upload: then it is asked about as one. */
349
+ const onlyUploads = (described: readonly Described[]): boolean =>
350
+ described.every((d) => d.upload === true);
280
351
 
281
352
  /** What to ask, once every send's PDF is known. */
282
353
  const HOW_TO_ASK = [
@@ -412,11 +483,11 @@ const literal = (text: string): string =>
412
483
  text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
413
484
 
414
485
  /**
415
- * Whether a question names the folder `folder` and not a longer path that starts with it
416
- * (`/w/paper` is not `/w/paper2` or `/w/paper.old`), nor one it ends: the whole path, case-sensitive.
486
+ * Whether a question names `word` (a folder, a project id) and not a longer one that starts with it
487
+ * (`/w/paper` is not `/w/paper2` or `/w/paper.old`), nor one it ends: the whole word, case-sensitive.
417
488
  */
418
- const namesFolder = (question: string, folder: string): boolean =>
419
- new RegExp(`(?<![\\w.-])${literal(folder)}(?![\\w.-])`, "u").test(question);
489
+ const namesWhole = (question: string, word: string): boolean =>
490
+ new RegExp(`(?<![\\w.-])${literal(word)}(?![\\w.-])`, "u").test(question);
420
491
 
421
492
  /** A question a yes must have been given to: what a send or a portal command needs it to name. */
422
493
  type Needs = (question: string) => boolean;
@@ -441,11 +512,13 @@ function takeYes(
441
512
  return found !== undefined && isYes(found) ? new Set([...taken, at]) : null;
442
513
  }
443
514
 
444
- /** What a yes to one send must name: its sha256 (any case) and its folder (the whole path, as written). */
515
+ /** What a yes to one send must name: its sha256 (any case), its folder (the whole path, as written) and its project. */
445
516
  const namesSend =
446
517
  (s: Named): Needs =>
447
518
  (question) =>
448
- hasAll(question, [s.sha]) && namesFolder(question, s.folder);
519
+ hasAll(question, [s.sha]) &&
520
+ namesWhole(question, s.folder) &&
521
+ (s.project === undefined || namesWhole(question, s.project));
449
522
 
450
523
  /** What a yes to a command that names a portal must name: the host (any case) and the command's start, literally. */
451
524
  const namesPortal =
@@ -478,18 +551,25 @@ function describedSends(
478
551
  ): readonly Described[] {
479
552
  const sends = /[`$]/u.test(command)
480
553
  ? []
481
- : sendsIn(deps.shellLeaves(command), deps.readSend);
554
+ : sendsIn(deps.shellLeaves(command), deps);
482
555
  return (sends.length === 0 ? [null] : sends).map((x): Described =>
483
556
  x === null ? { named: null, lines: [UNRESOLVED] } : describe(x, cwd, deps),
484
557
  );
485
558
  }
486
559
 
487
560
  /** The refusal of a send whose PDF is not known or not there: there is no sha256 to ask about. */
488
- const noPdf = (described: readonly Described[]): readonly string[] => [
489
- `${NOT_SENT}, and paperlint cannot find the PDF it uploads, so there is no sha256 to ask the person about.`,
490
- ...blocks(described),
491
- "Name the paper folder and the PDF plainly (no cd, no $…), build the PDF, run the dry run, and ask then.",
492
- ];
561
+ const noPdf = (described: readonly Described[]): readonly string[] =>
562
+ onlyUploads(described)
563
+ ? [
564
+ `${NOT_UPLOADED}, and paperlint cannot find the file it uploads, so there is no sha256 to ask the person about.`,
565
+ ...blocks(described),
566
+ "Name the paper folder and the file plainly (no cd, no $…), run the dry run, and ask then.",
567
+ ]
568
+ : [
569
+ `${NOT_SENT}, and paperlint cannot find the PDF it uploads, so there is no sha256 to ask the person about.`,
570
+ ...blocks(described),
571
+ "Name the paper folder and the PDF plainly (no cd, no $…), build the PDF, run the dry run, and ask then.",
572
+ ];
493
573
 
494
574
  /** The portal hosts the venue presets declare, or — when they cannot be read — none, and why. */
495
575
  interface Hosts {
@@ -523,6 +603,17 @@ const fallbackLines = (h: Hosts): readonly string[] =>
523
603
  `The venue presets could not be read (${h.failed}), so only HotCRP-hosted sites and paperlint sends are recognised until they are fixed.`,
524
604
  ];
525
605
 
606
+ /** How a refusal opens, and what it says to ask: a portal named, a paperlint send, or only uploads. */
607
+ function wordsFor(
608
+ paperlint: boolean,
609
+ described: readonly Described[],
610
+ ): { readonly base: string; readonly ask: readonly string[] } {
611
+ if (!paperlint) return { base: NAMES_PORTAL, ask: [] };
612
+ return onlyUploads(described)
613
+ ? { base: NOT_UPLOADED, ask: [HOW_TO_ASK_UPLOAD] }
614
+ : { base: NOT_SENT, ask: [HOW_TO_ASK] };
615
+ }
616
+
526
617
  /**
527
618
  * A command that sends: let through (null) when the person said yes to it since the last send —
528
619
  * each paperlint send by its paper folder and its PDF's sha256, a yes of its own for each, a portal
@@ -537,7 +628,7 @@ function decide(
537
628
  const described = c.paperlint ? describedSends(c.text, c.cwd, deps) : [];
538
629
  const named = described.flatMap((d) => (d.named === null ? [] : [d.named]));
539
630
  if (named.length < described.length) return noPdf(described);
540
- const base = c.paperlint ? NOT_SENT : NAMES_PORTAL;
631
+ const { base, ask } = wordsFor(c.paperlint, described);
541
632
  const read = transcriptOf(payload, deps.files);
542
633
  if (typeof read !== "string")
543
634
  return [
@@ -550,7 +641,7 @@ function decide(
550
641
  return [
551
642
  `${base}, and the person has not said yes to it since the last send.`,
552
643
  ...blocks(described),
553
- ...(c.paperlint ? [HOW_TO_ASK] : []),
644
+ ...ask,
554
645
  ...portalLines(c.host, start),
555
646
  ];
556
647
  }
@@ -573,7 +664,9 @@ function earlierSend(
573
664
  mayHold: (text) => {
574
665
  const plain = text.replace(/["'\\]/gu, "").toLowerCase();
575
666
  return (
576
- plain.includes("submission") || known.some((h) => plain.includes(h))
667
+ plain.includes("submission") ||
668
+ plain.includes("artifact") ||
669
+ known.some((h) => plain.includes(h))
577
670
  );
578
671
  },
579
672
  sends: (command) => {
package/src/types.ts CHANGED
@@ -74,6 +74,12 @@ export interface Args {
74
74
  submit: boolean;
75
75
  /** `--save` for `submission update`: really change the submission; without it, a dry run. */
76
76
  save: boolean;
77
+ /** `--url`, `--host`, `--to`, `--node`, `--numbers` for `artifact`: where the upload is, and what it holds. */
78
+ url: string | null;
79
+ host: string | null;
80
+ to: string | null;
81
+ node: string | null;
82
+ numbers: string | null;
77
83
  /**
78
84
  * `--allow-venue-name` for `new`: create the folder even though its name names a venue. Skips
79
85
  * that one refusal and no other.