paperlint 19.0.0 → 19.0.2

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 (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CLAUDE.md +2 -2
  3. package/dist/adapters/eslint/index.d.ts +13 -0
  4. package/dist/adapters/eslint/index.d.ts.map +1 -0
  5. package/dist/adapters/eslint/index.js +44 -0
  6. package/dist/adapters/eslint/index.js.map +1 -0
  7. package/dist/adapters/eslint/report.io.d.ts +15 -0
  8. package/dist/adapters/eslint/report.io.d.ts.map +1 -0
  9. package/dist/adapters/eslint/report.io.js +48 -0
  10. package/dist/adapters/eslint/report.io.js.map +1 -0
  11. package/dist/cli.d.ts +7 -12
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +80 -121
  14. package/dist/cli.js.map +1 -1
  15. package/dist/domain/submission-lint.d.ts +29 -0
  16. package/dist/domain/submission-lint.d.ts.map +1 -0
  17. package/dist/domain/submission-lint.js +84 -0
  18. package/dist/domain/submission-lint.js.map +1 -0
  19. package/dist/folder-layout-hook.js +1 -1
  20. package/dist/hooks-notice.d.ts +2 -0
  21. package/dist/hooks-notice.d.ts.map +1 -1
  22. package/dist/hooks-notice.js +4 -1
  23. package/dist/hooks-notice.js.map +1 -1
  24. package/dist/ports/submission-lint.d.ts +6 -0
  25. package/dist/ports/submission-lint.d.ts.map +1 -0
  26. package/dist/ports/submission-lint.js +2 -0
  27. package/dist/ports/submission-lint.js.map +1 -0
  28. package/dist/structure.d.ts +17 -1
  29. package/dist/structure.d.ts.map +1 -1
  30. package/dist/structure.js.map +1 -1
  31. package/dist/submission-confirm-hook.d.ts +8 -1
  32. package/dist/submission-confirm-hook.d.ts.map +1 -1
  33. package/dist/submission-confirm-hook.js +75 -20
  34. package/dist/submission-confirm-hook.js.map +1 -1
  35. package/dist/submission.d.ts +5 -0
  36. package/dist/submission.d.ts.map +1 -1
  37. package/dist/submission.js +46 -7
  38. package/dist/submission.js.map +1 -1
  39. package/dist/types.d.ts +2 -0
  40. package/dist/types.d.ts.map +1 -1
  41. package/docs/install.md +4 -4
  42. package/docs/layout.md +0 -1
  43. package/docs/submission.md +19 -8
  44. package/eslint.config.mjs +2 -0
  45. package/hooks/hooks.harness.ts +2 -140
  46. package/hooks/paper-skills-nudge.hook.mjs +0 -6
  47. package/lib/paper-config.harness.mjs +1 -2
  48. package/package.json +1 -1
  49. package/plugin/hooks/hooks.json +0 -9
  50. package/scripts/eslint-file-length.mjs +117 -0
  51. package/src/adapters/eslint/index.test.ts +152 -0
  52. package/src/adapters/eslint/index.ts +89 -0
  53. package/src/adapters/eslint/report.io.ts +82 -0
  54. package/src/cli.harness.mjs +9 -8
  55. package/src/cli.test.ts +4 -4
  56. package/src/cli.ts +110 -144
  57. package/src/domain/submission-lint.test.ts +211 -0
  58. package/src/domain/submission-lint.ts +166 -0
  59. package/src/folder-layout-hook.ts +1 -1
  60. package/src/hooks-notice.test.ts +2 -2
  61. package/src/hooks-notice.ts +10 -1
  62. package/src/hooks-settings.harness.ts +8 -8
  63. package/src/ports/submission-lint.ts +10 -0
  64. package/src/structure.ts +2 -4
  65. package/src/submission-confirm-hook-lint.test.ts +47 -0
  66. package/src/submission-confirm-hook.test.ts +73 -6
  67. package/src/submission-confirm-hook.ts +133 -28
  68. package/src/submission-fields-run.test.ts +1 -1
  69. package/src/submission-new.test.ts +4 -2
  70. package/src/submission-update.test.ts +16 -11
  71. package/src/submission.ts +62 -8
  72. package/src/types.ts +2 -0
  73. package/hooks/paper-status-gates.hook.mjs +0 -158
  74. package/hooks/paper-status-gates.sh +0 -93
  75. package/hooks/paper-status-gates.test.ts +0 -101
@@ -63,10 +63,13 @@ import { bodyEnd } from "./domain/body-pages.ts";
63
63
  import { fieldOf, isRecord } from "./domain/record.ts";
64
64
  import { sha256Hex } from "./domain/sha256.ts";
65
65
  import { messageOf } from "./domain/text.ts";
66
+ import { partition } from "remeda";
66
67
  import { factsPath, parseFactsText, type ReadFacts } from "./facts-file.ts";
67
68
  import type { Files } from "./ports/files.ts";
68
69
  import { paperPreset, type PresetDeps } from "./presets.ts";
69
70
  import { paperPdf } from "./submission.ts";
71
+ import { lintExceptionLines, lintSummary } from "./domain/submission-lint.ts";
72
+ import type { SubmissionLintResult } from "./ports/submission-lint.ts";
70
73
 
71
74
  /** One simple command of a command line, as a shell parser reads it (vigiles' `leafCommandsNormalized`). */
72
75
  interface ShellLeaf {
@@ -81,7 +84,7 @@ interface ShellLeaf {
81
84
  }
82
85
 
83
86
  /** What the hook reads: files, the shipped presets, and the portal hosts the project's venues declare. */
84
- export type ConfirmDeps = PresetDeps & {
87
+ export type ConfirmDeps<T = SubmissionLintResult> = PresetDeps & {
85
88
  /** The hosts of every venue portal paperlint knows of from `cwd`: shipped and the project's own. */
86
89
  readonly portalHosts: (cwd: string) => readonly string[];
87
90
  /** Every simple command of a command line, across `&&`, `;`, `|`; none when it does not parse. */
@@ -93,8 +96,12 @@ export type ConfirmDeps = PresetDeps & {
93
96
  readonly readSend: (words: readonly string[]) => Send | null;
94
97
  /** The words after `artifact`, read the same way: the paper and the file an upload names, or null. */
95
98
  readonly readUpload: (words: readonly string[]) => Upload | null;
99
+ readonly lintPaper: (paperDir: string, cwd: string) => T;
96
100
  };
97
101
 
102
+ type MaybePromise<T> = T | Promise<T>;
103
+ type HookDeps = ConfirmDeps<MaybePromise<SubmissionLintResult>>;
104
+
98
105
  /** What Claude Code reads from a PreToolUse hook's stdout to refuse the command; the agent sees the reason. */
99
106
  export interface DenyOutput {
100
107
  readonly hookSpecificOutput: {
@@ -160,6 +167,8 @@ function isSend(l: ShellLeaf): boolean {
160
167
  export interface Send {
161
168
  readonly paper: string | null;
162
169
  readonly pdf: string | null;
170
+ readonly action: "create" | "update" | "submit";
171
+ readonly allowLintErrors?: string | undefined;
163
172
  }
164
173
 
165
174
  /** One `artifact upload --save`: the paper (null for the current folder), the file, and where it goes. */
@@ -275,6 +284,7 @@ interface Named {
275
284
  readonly folder: string;
276
285
  readonly sha: string;
277
286
  readonly project?: string;
287
+ readonly lintException?: readonly string[];
278
288
  }
279
289
 
280
290
  /** One send, described: what a yes must name (null when the PDF is not found), and the lines for the person. */
@@ -283,6 +293,7 @@ interface Described {
283
293
  readonly lines: readonly string[];
284
294
  /** An artifact upload, not a submission. */
285
295
  readonly upload?: true;
296
+ readonly blocked?: true;
286
297
  }
287
298
 
288
299
  /** One upload, described: the paper, the file it uploads and its sha256, and where it goes. */
@@ -302,13 +313,23 @@ function describeUpload(u: Upload, cwd: string, files: Files): Described {
302
313
  }
303
314
 
304
315
  /** One send, described: the paper, the PDF as the command resolves it, what the build saw. */
305
- function describe(
306
- send: Send | Upload,
316
+ const actions = {
317
+ create: "Create submission",
318
+ update: "Save changes to submission",
319
+ submit: "Mark submission ready for review",
320
+ } as const;
321
+
322
+ const actionAt = (send: Send, p: ReturnType<typeof paperPreset>): string => {
323
+ const to = p.kind === "resolved" ? p.preset.portal?.url : undefined;
324
+ return `${actions[send.action]}${to === undefined ? "" : ` at ${to}`}`;
325
+ };
326
+
327
+ function describePaper(
328
+ send: Send,
307
329
  cwd: string,
330
+ paperDir: string,
308
331
  deps: PresetDeps,
309
- ): Described {
310
- if ("artifact" in send) return describeUpload(send, cwd, deps.files);
311
- const paperDir = resolve(cwd, send.paper ?? ".");
332
+ ): Described & { readonly action: string } {
312
333
  const p = paperPreset(paperDir, deps);
313
334
  const own = paperPdf(
314
335
  paperDir,
@@ -317,17 +338,71 @@ function describe(
317
338
  const pdf = send.pdf === null ? own : resolve(cwd, send.pdf);
318
339
  const bytes = deps.files.readBytes(callerPath(pdf));
319
340
  const sha = bytes === null ? null : sha256Hex(bytes);
341
+ const action = actionAt(send, p);
320
342
  return {
343
+ action,
321
344
  named:
322
345
  sha === null ? null : { folder: paperDir, sha: sha.slice(0, SHA_SHOWN) },
323
346
  lines: [
324
347
  `paper folder: ${paperDir}`,
325
348
  `PDF: ${send.pdf ?? join(send.paper ?? ".", relative(paperDir, own))}${sha === null ? " — NOT FOUND" : `, sha256 ${sha.slice(0, SHA_SHOWN)}`}`,
326
349
  ...factsLines(paperDir, sha, deps.files),
350
+ `Action: ${action}`,
327
351
  ],
328
352
  };
329
353
  }
330
354
 
355
+ function describe(
356
+ send: Send | Upload,
357
+ cwd: string,
358
+ deps: HookDeps,
359
+ ): MaybePromise<Described> {
360
+ if ("artifact" in send) return describeUpload(send, cwd, deps.files);
361
+ const paperDir = resolve(cwd, send.paper ?? ".");
362
+ const described = describePaper(send, cwd, paperDir, deps);
363
+ const reason = send.allowLintErrors;
364
+ const { named } = described;
365
+ if (named === null || reason === undefined) return described;
366
+ const lint = deps.lintPaper(paperDir, cwd);
367
+ const paperSend = { described, named, action: described.action };
368
+ return lint instanceof Promise
369
+ ? lint.then((r) => describeException(paperSend, r, reason))
370
+ : describeException(paperSend, lint, reason);
371
+ }
372
+
373
+ function describeException(
374
+ paper: {
375
+ readonly described: Described;
376
+ readonly named: Named;
377
+ readonly action: string;
378
+ },
379
+ lint: SubmissionLintResult,
380
+ reason: string,
381
+ ): Described {
382
+ const { described, named, action } = paper;
383
+ if (!lint.ok)
384
+ return {
385
+ ...described,
386
+ blocked: true,
387
+ lines: [
388
+ ...described.lines,
389
+ `Cannot approve a lint exception: ${lint.error}`,
390
+ ],
391
+ };
392
+ const exception = lintExceptionLines(lint.value, reason);
393
+ const details = [
394
+ `Lint exception: ${exceptionDigest(exception)}`,
395
+ ...exception,
396
+ ];
397
+ return {
398
+ named: { ...named, lintException: [`Action: ${action}`, ...details] },
399
+ lines: [...described.lines, lintSummary(lint.value), ...details],
400
+ };
401
+ }
402
+
403
+ const exceptionDigest = (lines: readonly string[]): string =>
404
+ sha256Hex(new TextEncoder().encode(lines.join("\n"))).slice(0, SHA_SHOWN);
405
+
331
406
  /** How much of the sha256 the reason shows, and the question must contain. */
332
407
  const SHA_SHOWN = 12;
333
408
 
@@ -351,11 +426,9 @@ const onlyUploads = (described: readonly Described[]): boolean =>
351
426
 
352
427
  /** What to ask, once every send's PDF is known. */
353
428
  const HOW_TO_ASK = [
354
- "Ask the person with AskUserQuestion first, then run this command again. In the question, give:",
355
- "- the paper folder (the full path, as written above), the PDF and its sha256 as written above (the folder path and the sha256 must both be in the question text),",
356
- "- what the lines above say about the build (the body pages, or that it is stale or missing),",
357
- "- the dry run's venue check, quoted word for word (its `venue rules at their default options` line and every error under it).",
358
- 'Options: "Yes, send it" and "No". One yes lets one send through: ask one question per send, each naming its own folder and sha256.',
429
+ "Ask with AskUserQuestion. Show the action, one lint summary line from the dry run, and the full paper folder, PDF and sha256 above.",
430
+ "For an exception, copy the Action, Lint exception, reason and blocking errors above. Mention stale or missing build facts.",
431
+ 'Options: "Yes, proceed" and "No". One yes covers one command.',
359
432
  ].join("\n");
360
433
 
361
434
  /** How much of a command naming a portal the question must quote. */
@@ -518,7 +591,8 @@ const namesSend =
518
591
  (question) =>
519
592
  hasAll(question, [s.sha]) &&
520
593
  namesWhole(question, s.folder) &&
521
- (s.project === undefined || namesWhole(question, s.project));
594
+ (s.project === undefined || namesWhole(question, s.project)) &&
595
+ (s.lintException?.every((line) => question.includes(line.trim())) ?? true);
522
596
 
523
597
  /** What a yes to a command that names a portal must name: the host (any case) and the command's start, literally. */
524
598
  const namesPortal =
@@ -547,12 +621,12 @@ const everyNeedHasItsYes = (
547
621
  function describedSends(
548
622
  command: string,
549
623
  cwd: string,
550
- deps: ConfirmDeps,
551
- ): readonly Described[] {
624
+ deps: HookDeps,
625
+ ): readonly MaybePromise<Described>[] {
552
626
  const sends = /[`$]/u.test(command)
553
627
  ? []
554
628
  : sendsIn(deps.shellLeaves(command), deps);
555
- return (sends.length === 0 ? [null] : sends).map((x): Described =>
629
+ return (sends.length === 0 ? [null] : sends).map((x) =>
556
630
  x === null ? { named: null, lines: [UNRESOLVED] } : describe(x, cwd, deps),
557
631
  );
558
632
  }
@@ -578,7 +652,7 @@ interface Hosts {
578
652
  }
579
653
 
580
654
  /** The presets' hosts; when they cannot be read, none, and why. */
581
- function readHosts(cwd: string, deps: ConfirmDeps): Hosts {
655
+ function readHosts(cwd: string, deps: HookDeps): Hosts {
582
656
  try {
583
657
  return { hosts: deps.portalHosts(cwd), failed: null };
584
658
  } catch (e) {
@@ -623,9 +697,10 @@ function wordsFor(
623
697
  function decide(
624
698
  c: Command,
625
699
  payload: unknown,
626
- deps: ConfirmDeps,
700
+ deps: HookDeps,
701
+ described: readonly Described[],
627
702
  ): readonly string[] | null {
628
- const described = c.paperlint ? describedSends(c.text, c.cwd, deps) : [];
703
+ if (described.some((d) => d.blocked)) return [NOT_SENT, ...blocks(described)];
629
704
  const named = described.flatMap((d) => (d.named === null ? [] : [d.named]));
630
705
  if (named.length < described.length) return noPdf(described);
631
706
  const { base, ask } = wordsFor(c.paperlint, described);
@@ -656,7 +731,7 @@ const portalLines = (host: string | null, start: string): readonly string[] =>
656
731
  function earlierSend(
657
732
  c: Command,
658
733
  payload: unknown,
659
- deps: ConfirmDeps,
734
+ deps: Pick<ConfirmDeps, "shellLeaves">,
660
735
  ): EarlierSend {
661
736
  const known = knownHosts(c.hosts.hosts);
662
737
  return {
@@ -715,8 +790,8 @@ function judge(
715
790
  text: string,
716
791
  cwd: string,
717
792
  payload: unknown,
718
- deps: ConfirmDeps,
719
- ): DenyOutput | null {
793
+ deps: HookDeps,
794
+ ): MaybePromise<DenyOutput | null> {
720
795
  const leaves = allLeaves(text, deps.shellLeaves);
721
796
  const paperlint = leaves.some(isSend);
722
797
  // The presets are read only for a command that may send: anything else pays nothing.
@@ -724,10 +799,29 @@ function judge(
724
799
  const hosts = readHosts(cwd, deps);
725
800
  const host = portalHost(leaves, hosts.hosts);
726
801
  if (!paperlint && host === null) return null;
727
- const lines = decide({ text, cwd, paperlint, host, hosts }, payload, deps);
802
+ const described = paperlint ? describedSends(text, cwd, deps) : [];
803
+ const command = { text, cwd, paperlint, host, hosts };
804
+ const finish = (sends: readonly Described[]) =>
805
+ decisionOutput(command, payload, deps, sends);
806
+ const [ready, pending] = partition(
807
+ described,
808
+ (send): send is Described => !(send instanceof Promise),
809
+ );
810
+ return pending.length === 0
811
+ ? finish(ready)
812
+ : Promise.all(described.map((send) => Promise.resolve(send))).then(finish);
813
+ }
814
+
815
+ function decisionOutput(
816
+ command: Command,
817
+ payload: unknown,
818
+ deps: HookDeps,
819
+ sends: readonly Described[],
820
+ ): DenyOutput | null {
821
+ const lines = decide(command, payload, deps, sends);
728
822
  return lines === null
729
823
  ? null
730
- : deny([...lines, ...fallbackLines(hosts)].join("\n"));
824
+ : deny([...lines, ...fallbackLines(command.hosts)].join("\n"));
731
825
  }
732
826
 
733
827
  /**
@@ -737,7 +831,15 @@ function judge(
737
831
  export function submissionConfirm(
738
832
  stdin: string,
739
833
  deps: ConfirmDeps,
740
- ): DenyOutput | null {
834
+ ): DenyOutput | null;
835
+ export function submissionConfirm(
836
+ stdin: string,
837
+ deps: HookDeps,
838
+ ): MaybePromise<DenyOutput | null>;
839
+ export function submissionConfirm(
840
+ stdin: string,
841
+ deps: HookDeps,
842
+ ): MaybePromise<DenyOutput | null> {
741
843
  const payload = parsed(stdin);
742
844
  if (payload === null) return UNREADABLE_INPUT;
743
845
  const raw = fieldOf(fieldOf(payload, "tool_input"), "command");
@@ -745,11 +847,14 @@ export function submissionConfirm(
745
847
  const given = fieldOf(payload, "cwd");
746
848
  const cwd =
747
849
  typeof given === "string" && isAbsolute(given) ? given : resolve(".");
748
- try {
749
- return judge(text, cwd, payload, deps);
750
- } catch (e) {
751
- return deny(
850
+ const failed = (e: unknown) =>
851
+ deny(
752
852
  `Not run: paperlint could not check whether this command sends a paper: ${messageOf(e)}.`,
753
853
  );
854
+ try {
855
+ const verdict = judge(text, cwd, payload, deps);
856
+ return verdict instanceof Promise ? verdict.catch(failed) : verdict;
857
+ } catch (e) {
858
+ return failed(e);
754
859
  }
755
860
  }
@@ -50,7 +50,7 @@ test("update: the paper's fields are checked and sent with the change, and print
50
50
  { save: false },
51
51
  ],
52
52
  ]);
53
- expect(r.out.slice(2, 5)).toStrictEqual([
53
+ expect(r.out.slice(3, 6)).toStrictEqual([
54
54
  'field topics: ["Group: Topic A"]',
55
55
  'field pc_conflicts: {"pc@example.org":"collaborator"}',
56
56
  'field ACMCorAut: "ada@example.org"',
@@ -24,6 +24,7 @@ import {
24
24
  DRAFT_WARNING,
25
25
  ON_THE_SITE,
26
26
  NO_ERRORS,
27
+ CLEAN_LINT,
27
28
  } from "../test/submission-fixtures.ts";
28
29
 
29
30
  test("new: a dry run by default — title from \\title, abstract from \\begin{abstract} with the author's macro expanded, the declared authors, the PDF", async () => {
@@ -35,6 +36,7 @@ test("new: a dry run by default — title from \\title, abstract from \\begin{ab
35
36
  expect(r.out).toStrictEqual([
36
37
  CHECK("papers/p/paper.pdf", "the call for papers, https://example.org/cfp"),
37
38
  NO_ERRORS,
39
+ CLEAN_LINT,
38
40
  "title Agents That Lie",
39
41
  "author 1 Ada Lovelace <ada@example.org>, Analytical",
40
42
  "author 2 Bob Bobson <bob@example.org>",
@@ -65,7 +67,7 @@ test("new --save: the id the portal chose is written into paperlint.json, and `s
65
67
  const r = await run({ sub: "new", save: true }, { files: fs });
66
68
  expect(r.code, r.errs.join("\n")).toBe(0);
67
69
  expect(r.seen[0]?.calls).toStrictEqual([["create", WANT, { save: true }]]);
68
- expect(r.out.slice(7, 8)).toStrictEqual(["created submission 42"]);
70
+ expect(r.out).toContain("created submission 42");
69
71
  expect(r.out.slice(-2)).toStrictEqual([
70
72
  `recorded "submission": { "id": 42 } in papers/p/paperlint.json`,
71
73
  `next npx paperlint submission show papers/p — it should say "match yes"`,
@@ -514,7 +516,7 @@ test("new: no paper.tex — the PDF's Title stands in; without one either, the f
514
516
  },
515
517
  );
516
518
  expect(titled.code, titled.errs.join("\n")).toBe(0);
517
- expect(titled.out[2]).toBe("title From The PDF");
519
+ expect(titled.out).toContain("title From The PDF");
518
520
  const noAbstract = await run(
519
521
  { sub: "new" },
520
522
  { files: newFiles({ tex: null, facts: facts({ title: "From The PDF" }) }) },
@@ -17,6 +17,7 @@ import {
17
17
  CHECK,
18
18
  run,
19
19
  NO_ERRORS,
20
+ CLEAN_LINT,
20
21
  facts,
21
22
  DEFAULT_TEX,
22
23
  ABSTRACT_TEX,
@@ -44,6 +45,7 @@ test("update: a dry run by default — the paper's PDF sent, nothing saved, exit
44
45
  expect(r.out).toStrictEqual([
45
46
  CHECK("papers/p/paper.pdf", "the call for papers, https://example.org/cfp"),
46
47
  NO_ERRORS,
48
+ CLEAN_LINT,
47
49
  NOT_CHECKED,
48
50
  NO_ABSTRACT,
49
51
  "dry run — the portal checked the change and kept nothing; --save sends it for real",
@@ -84,9 +86,10 @@ test("update --save --submit --abstract --pdf: all of it sent, and said to be sa
84
86
  ],
85
87
  ]);
86
88
  // Guards: the PDF that is sent is the one named, and --save is told to check it too.
87
- expect(r.out.slice(0, 5)).toStrictEqual([
89
+ expect(r.out.slice(0, 6)).toStrictEqual([
88
90
  CHECK("other.pdf", "the call for papers, https://example.org/cfp"),
89
91
  NO_ERRORS,
92
+ CLEAN_LINT,
90
93
  NOT_CHECKED,
91
94
  "abstract sends abs.txt (2 words), from --abstract",
92
95
  "saved",
@@ -127,7 +130,7 @@ test("update: valid:false, or a non-2xx status, exits 1 with the portal's messag
127
130
  { portal: fakePortal({ update: invalid }) },
128
131
  );
129
132
  expect(r1.code).toBe(1);
130
- expect(r1.out.slice(6)).toStrictEqual([
133
+ expect(r1.out.slice(-4)).toStrictEqual([
131
134
  "valid NO",
132
135
  "changes —",
133
136
  `local PDF papers/p/paper.pdf sha2-${HEX}`,
@@ -168,7 +171,7 @@ test("update --save that the portal withheld says so", async () => {
168
171
  { sub: "update", save: true },
169
172
  { portal: fakePortal({ update: withheld }) },
170
173
  );
171
- expect(r.out[4]).toBe("SAVE WITHHELD by the portal — nothing changed");
174
+ expect(r.out).toContain("SAVE WITHHELD by the portal — nothing changed");
172
175
  });
173
176
 
174
177
  test("update: no PDF to send, or no abstract file, is refused before the portal is asked", async () => {
@@ -219,11 +222,12 @@ const LINT_BLOCK = (level: "error" | "warning", text: string): string[] => [
219
222
  test("update over the page limit: the venue rules' findings on that PDF, as lint prints them, before the portal is asked; a dry run still runs", async () => {
220
223
  const r = await run({ sub: "update" }, { files: OVER });
221
224
  expect(r.code).toBe(0);
222
- expect(r.out.slice(1, 9)).toStrictEqual([
225
+ expect(r.out.slice(1, 10)).toStrictEqual([
223
226
  ...LINT_BLOCK(
224
227
  "error",
225
228
  "body pages (up to the references on page 9): 8, over the limit 6 for venue/short — a desk reject; cut the text format/page-limit",
226
229
  ),
230
+ CLEAN_LINT,
227
231
  NOT_CHECKED,
228
232
  NO_ABSTRACT,
229
233
  "dry run — the portal checked the change and kept nothing; --save sends it for real",
@@ -233,7 +237,7 @@ test("update over the page limit: the venue rules' findings on that PDF, as lint
233
237
 
234
238
  test("update --save over the limit: the same findings, and the send goes ahead — the person decides on them, not the command", async () => {
235
239
  const r = await run({ sub: "update", save: true }, { files: OVER });
236
- expect([r.code, r.errs, r.out[2], r.out[8]]).toStrictEqual([
240
+ expect([r.code, r.errs, r.out[2], r.out[9]]).toStrictEqual([
237
241
  0,
238
242
  [],
239
243
  `${PAPER}/paper.tex`,
@@ -374,9 +378,10 @@ test("🔴 update: a \\title and an abstract that differ from the portal's are s
374
378
  ["show", 7],
375
379
  SENT({ title: "Agents That Lie", abstract: WANT.abstract }),
376
380
  ]);
377
- expect(r.out.slice(0, 5)).toStrictEqual([
381
+ expect(r.out.slice(0, 6)).toStrictEqual([
378
382
  CHECK("papers/p/paper.pdf", "the call for papers, https://example.org/cfp"),
379
383
  NO_ERRORS,
384
+ CLEAN_LINT,
380
385
  "title sends «Agents That Lie» — the portal has «A Fake Title»",
381
386
  "abstract sends the paper's (17 words) — the portal has another (4 words)",
382
387
  "dry run — the portal checked the change and kept nothing; --save sends it for real",
@@ -392,7 +397,7 @@ test("update: a \\title and an abstract the portal already holds are not sent",
392
397
  expect(r.seen[0]?.calls[1]).toStrictEqual(
393
398
  SENT({ title: null, abstract: null }),
394
399
  );
395
- expect(r.out.slice(2, 4)).toStrictEqual([
400
+ expect(r.out.slice(3, 5)).toStrictEqual([
396
401
  "title unchanged — the portal holds «Agents That Lie»",
397
402
  "abstract unchanged — the portal holds the paper's (17 words)",
398
403
  ]);
@@ -401,7 +406,7 @@ test("update: a \\title and an abstract the portal already holds are not sent",
401
406
  test("update: a portal with no title and no abstract gets the paper's, said as none", async () => {
402
407
  const none = holding({ title: null, abstract: null });
403
408
  const r = await run({ sub: "update" }, { files: titled(), portal: none });
404
- expect(r.out.slice(2, 4)).toStrictEqual([
409
+ expect(r.out.slice(3, 5)).toStrictEqual([
405
410
  "title sends «Agents That Lie» — the portal has none",
406
411
  "abstract sends the paper's (17 words) — the portal has none",
407
412
  ]);
@@ -413,7 +418,7 @@ test("update: neither readable — both said, nothing asked of the portal for th
413
418
  expect(r.seen[0]?.calls).toStrictEqual([
414
419
  SENT({ title: null, abstract: null }),
415
420
  ]);
416
- expect(r.out.slice(2, 4)).toStrictEqual([NOT_CHECKED, NO_ABSTRACT]);
421
+ expect(r.out.slice(3, 5)).toStrictEqual([NOT_CHECKED, NO_ABSTRACT]);
417
422
  });
418
423
 
419
424
  test("update: one of the two readable is enough to ask the portal — an abstract with no \\title, a \\title with no abstract", async () => {
@@ -436,7 +441,7 @@ test("update: one of the two readable is enough to ask the portal — an abstrac
436
441
  ["show", 7],
437
442
  SENT({ title: null, abstract: null }),
438
443
  ]);
439
- expect(r2.out[3]).toBe(
444
+ expect(r2.out[4]).toBe(
440
445
  "abstract not checked — paper.tex has no \\begin{abstract}…\\end{abstract} — give the abstract with --abstract <file>, a plain-text file",
441
446
  );
442
447
  });
@@ -455,7 +460,7 @@ test("update --abstract: the file is sent whatever the portal holds, and said",
455
460
  expect(r.seen[0]?.calls[1]).toStrictEqual(
456
461
  SENT({ title: null, abstract: "Two words." }),
457
462
  );
458
- expect(r.out[3]).toBe(
463
+ expect(r.out[4]).toBe(
459
464
  "abstract sends abs.txt (2 words), from --abstract",
460
465
  );
461
466
  });
package/src/submission.ts CHANGED
@@ -20,10 +20,8 @@
20
20
  * sent (`src/domain/submission-fields.ts`). A checkbox field the portal did not take is said, and
21
21
  * fails the command: HotCRP keeps an option it does not know as nothing, without an error.
22
22
  *
23
- * Before the portal is asked, `new` and `update` print what the venue rules find in the exact PDF
24
- * they send, as `paperlint lint` prints it — or "venue rules: no errors" (paperlint#264). The verdict
25
- * is the author's to act on; the one thing the command refuses is a `--save` whose build facts are
26
- * missing or about other bytes, because then nothing was checked (exit 2).
23
+ * Before the portal is asked, `new` and `update` check the exact PDF and run the full paper lint.
24
+ * A save stops on lint errors (exit 2). A reasoned `--allow-lint-errors` permits those findings.
27
25
  *
28
26
  * 🔴 THE TOKEN IS AN INPUT, AND ONLY AN INPUT. It comes from the environment (the root reads it), is
29
27
  * handed to the adapter, and never appears in anything printed here.
@@ -34,6 +32,12 @@ import { basename, join, resolve } from "node:path";
34
32
  import { absolutePath } from "./domain/paths.ts";
35
33
  import { messageOf } from "./domain/text.ts";
36
34
  import { err, ok, type Result } from "./domain/result.ts";
35
+ import {
36
+ lintExceptionReason,
37
+ lintReportLines,
38
+ type PaperSections,
39
+ } from "./domain/submission-lint.ts";
40
+ import type { SubmissionLinter } from "./ports/submission-lint.ts";
37
41
  import { sha256Hex, type Sha256 } from "./domain/sha256.ts";
38
42
  import {
39
43
  supportedPortal,
@@ -173,6 +177,7 @@ export interface SubmissionArgs {
173
177
  readonly abstract: string | null;
174
178
  readonly submit: boolean;
175
179
  readonly save: boolean;
180
+ readonly allowLintErrors?: string | undefined;
176
181
  }
177
182
 
178
183
  export interface SubmissionDeps {
@@ -192,6 +197,7 @@ export interface SubmissionDeps {
192
197
  file: string,
193
198
  messages: readonly VenueMessage[],
194
199
  ) => Promise<string>;
200
+ readonly lintPaper: SubmissionLinter;
195
201
  /** Parses the reviewers' points file a reviewed rejection names (`--save` stops while one is unanswered). */
196
202
  readonly yaml: ParseYaml;
197
203
  /** The instant a frozen version's lock entry records (`versions/lock.json`), ISO 8601. */
@@ -676,6 +682,29 @@ const VENUE_RULES = "venue rules at their default options";
676
682
  const REBUILD_REFUSAL =
677
683
  "refused: no build facts describe this PDF (none, unreadable, or of other bytes), so the venue rules did not see it — rebuild (`paperlint build`), run the dry run again, and read its venue check; nothing was sent";
678
684
 
685
+ /** A dry run reports every finding. A save stops before the portal sees a request. */
686
+ async function submissionCheck(
687
+ t: SubmissionTarget,
688
+ bytes: Uint8Array,
689
+ a: SubmissionArgs,
690
+ deps: RunDeps,
691
+ ): Promise<boolean> {
692
+ const venueRefused = await venueCheck(t, bytes, a.save, deps);
693
+ const lint = await deps.lintPaper(t.paperDir, deps.cwd);
694
+ if (!lint.ok) {
695
+ deps.err(`lint could not finish: ${lint.error}`);
696
+ return a.save || venueRefused;
697
+ }
698
+ logAll(lintReportLines(lint.value), deps);
699
+ if (lint.value.errors.length === 0) return venueRefused;
700
+ if (a.allowLintErrors !== undefined) {
701
+ deps.log(lintExceptionReason(a.allowLintErrors));
702
+ return venueRefused;
703
+ }
704
+ if (a.save) deps.err("refused: the paper has lint errors; nothing was sent");
705
+ return a.save || venueRefused;
706
+ }
707
+
679
708
  /** `update`: send the PDF, a changed title and abstract, and "submitted" when asked; a dry run unless saving. */
680
709
  async function runUpdate(
681
710
  t: SubmissionTarget & { readonly id: number },
@@ -693,7 +722,7 @@ async function runUpdate(
693
722
  const abstract = abstractOf(a, deps);
694
723
  if (!abstract.ok) return (deps.err(abstract.error), 2);
695
724
  deps.log(checkPdfLine(shown, t.call));
696
- const refused = await venueCheck(t, bytes, a.save, deps);
725
+ const refused = await submissionCheck(t, bytes, a, deps);
697
726
  logAll(fieldLines(t.fields), deps);
698
727
  if (refused) return 2;
699
728
  const plan = planFor(t, a.save, deps);
@@ -1111,7 +1140,7 @@ function readyForNew(t: SubmissionTarget): Result<readonly Author[], string> {
1111
1140
  /** The paper as the build read it: paper.tex with the files it includes spliced in; null without one. */
1112
1141
  function assembledPaper(
1113
1142
  paperDir: string,
1114
- deps: SubmissionDeps,
1143
+ deps: Pick<SubmissionDeps, "files" | "latex" | "codec">,
1115
1144
  ): PaperSource | null {
1116
1145
  const bytes = bytesAt(deps.files, join(paperDir, MAIN));
1117
1146
  return bytes === null
@@ -1119,6 +1148,20 @@ function assembledPaper(
1119
1148
  : readPaper(join(paperDir, MAIN), new TextDecoder().decode(bytes), deps);
1120
1149
  }
1121
1150
 
1151
+ export function submissionSections(
1152
+ paperDir: string,
1153
+ deps: Pick<SubmissionDeps, "files" | "latex" | "codec">,
1154
+ ): PaperSections | null {
1155
+ const paper = assembledPaper(paperDir, deps);
1156
+ return paper === null
1157
+ ? null
1158
+ : {
1159
+ paper,
1160
+ abstract: deps.latex.abstractSpan(paper.text),
1161
+ outline: deps.latex.outline(paper.text),
1162
+ };
1163
+ }
1164
+
1122
1165
  /**
1123
1166
  * The paper's title (`titleOf`, falling back on the build's facts about `pdf`, none without one)
1124
1167
  * and its abstract (`sourceAbstract`): what `new` sends, and what `update` and `show` compare.
@@ -1233,7 +1276,7 @@ async function runNew(
1233
1276
  if (!n.ok) return (deps.err(n.error), 2);
1234
1277
  const { paper, shown } = n.value;
1235
1278
  deps.log(checkPdfLine(shown, t.call));
1236
- const refused = await venueCheck(t, paper.pdf.bytes, a.save, deps);
1279
+ const refused = await submissionCheck(t, paper.pdf.bytes, a, deps);
1237
1280
  logAll(newLines(paper), deps);
1238
1281
  if (refused) return 2;
1239
1282
  const plan = planFor(t, a.save, deps);
@@ -1325,6 +1368,17 @@ const writingFlags = (a: SubmissionArgs): readonly string[] =>
1325
1368
  a.save ? "--save" : null,
1326
1369
  ].filter((f) => f !== null);
1327
1370
 
1371
+ function lintExceptionProblem(a: SubmissionArgs): string | null {
1372
+ const reason = a.allowLintErrors?.trim();
1373
+ if (reason === undefined) return null;
1374
+ return a.save &&
1375
+ (a.sub === "new" || a.sub === "update") &&
1376
+ reason !== "" &&
1377
+ !reason.startsWith("--")
1378
+ ? null
1379
+ : "--allow-lint-errors needs a nonempty reason and --save on submission new or update";
1380
+ }
1381
+
1328
1382
  /** Why the command line cannot be run as asked; null when it can. Pure. */
1329
1383
  export function usageProblem(a: SubmissionArgs): string | null {
1330
1384
  if (!isSubcommand(a.sub))
@@ -1336,7 +1390,7 @@ export function usageProblem(a: SubmissionArgs): string | null {
1336
1390
  return `${writing.join(", ")}: only \`submission new\` and \`submission update\` change anything; \`${a.sub}\` reads`;
1337
1391
  return a.sub === "new" && a.submit
1338
1392
  ? "--submit: `submission new` creates the submission; mark it submitted with `submission update --submit` once `show` says the portal holds this build"
1339
- : null;
1393
+ : lintExceptionProblem(a);
1340
1394
  }
1341
1395
 
1342
1396
  /** The variables a site's token lookup reads. */
package/src/types.ts CHANGED
@@ -78,6 +78,8 @@ export interface Args {
78
78
  submit: boolean;
79
79
  /** `--save` for `submission update`: really change the submission; without it, a dry run. */
80
80
  save: boolean;
81
+ /** `--allow-lint-errors <reason>` for a submission save. */
82
+ allowLintErrors?: string | null;
81
83
  /** `--url`, `--host`, `--to`, `--node`, `--numbers` for `artifact`: where the upload is, and what it holds. */
82
84
  url: string | null;
83
85
  host: string | null;