paperlint 18.9.1 → 19.0.1

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 (87) 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 +73 -110
  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/ports/submission-lint.d.ts +6 -0
  20. package/dist/ports/submission-lint.d.ts.map +1 -0
  21. package/dist/ports/submission-lint.js +2 -0
  22. package/dist/ports/submission-lint.js.map +1 -0
  23. package/dist/structure.d.ts +17 -1
  24. package/dist/structure.d.ts.map +1 -1
  25. package/dist/structure.js.map +1 -1
  26. package/dist/submission-confirm-hook.d.ts +8 -1
  27. package/dist/submission-confirm-hook.d.ts.map +1 -1
  28. package/dist/submission-confirm-hook.js +75 -20
  29. package/dist/submission-confirm-hook.js.map +1 -1
  30. package/dist/submission.d.ts +5 -0
  31. package/dist/submission.d.ts.map +1 -1
  32. package/dist/submission.js +46 -7
  33. package/dist/submission.js.map +1 -1
  34. package/dist/types.d.ts +2 -0
  35. package/dist/types.d.ts.map +1 -1
  36. package/docs/submission.md +19 -8
  37. package/eslint.config.mjs +2 -0
  38. package/lib/skill-corpus.mjs +2 -113
  39. package/lib/skill-corpus.test.mjs +10 -11
  40. package/package.json +1 -2
  41. package/scripts/eslint-file-length.mjs +117 -0
  42. package/scripts/harness-api.frozen.json +0 -18
  43. package/skills/build-label-page/build-label-page.test.ts +2 -7
  44. package/skills/harden-paper/check-numbers.test.ts +104 -0
  45. package/skills/harden-paper/check-release-claims.test.ts +126 -0
  46. package/skills/label-agent-runs/label-agent-runs.harness.ts +2 -6
  47. package/skills/render-paper/render-paper.harness.mjs +153 -0
  48. package/skills/rewrite-unclear/rewrite-unclear.harness.ts +0 -5
  49. package/skills/run-agent-grid/run-agent-grid.harness.ts +2 -6
  50. package/skills/submit-paper/check-deanon.test.ts +165 -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.ts +103 -134
  55. package/src/domain/submission-lint.test.ts +211 -0
  56. package/src/domain/submission-lint.ts +166 -0
  57. package/src/ports/submission-lint.ts +10 -0
  58. package/src/structure.ts +2 -4
  59. package/src/submission-confirm-hook-lint.test.ts +47 -0
  60. package/src/submission-confirm-hook.test.ts +73 -6
  61. package/src/submission-confirm-hook.ts +133 -28
  62. package/src/submission-fields-run.test.ts +1 -1
  63. package/src/submission-new.test.ts +4 -2
  64. package/src/submission-update.test.ts +16 -11
  65. package/src/submission.ts +62 -8
  66. package/src/types.ts +2 -0
  67. package/lib/skill-checks.d.mts +0 -10
  68. package/lib/skill-checks.mjs +0 -403
  69. package/lib/skill-checks.test.mjs +0 -288
  70. package/skills/analyze-sibling-paper/analyze-sibling-paper.harness.mjs +0 -23
  71. package/skills/argument-arc/argument-arc.harness.mjs +0 -23
  72. package/skills/build-benchmark/build-benchmark.harness.mjs +0 -23
  73. package/skills/camera-ready/camera-ready.harness.mjs +0 -23
  74. package/skills/cold-read-diff/cold-read-diff.harness.mjs +0 -21
  75. package/skills/draft-paper/draft-paper.harness.mjs +0 -23
  76. package/skills/extend-paper/extend-paper.harness.mjs +0 -23
  77. package/skills/find-venue/find-venue.harness.mjs +0 -23
  78. package/skills/harden-paper/harden-paper.harness.mjs +0 -23
  79. package/skills/map-prior-work/map-prior-work.harness.mjs +0 -23
  80. package/skills/paper-status/paper-status.harness.mjs +0 -25
  81. package/skills/pc-panel-review/pc-panel-review.harness.mjs +0 -24
  82. package/skills/plan-paper-timeline/plan-paper-timeline.harness.mjs +0 -23
  83. package/skills/research-ideate/research-ideate.harness.mjs +0 -23
  84. package/skills/study-accepted-papers/study-accepted-papers.harness.mjs +0 -23
  85. package/skills/submit-paper/submit-paper.harness.mjs +0 -23
  86. package/skills/tighten-paper/tighten-paper.harness.mjs +0 -23
  87. package/skills/verify-citations/verify-citations.harness.mjs +0 -23
@@ -0,0 +1,166 @@
1
+ import { partition } from "remeda";
2
+ import type { PaperSource, Segment } from "./paper-source.ts";
3
+ import type { Outline, Span } from "./tex-document.ts";
4
+
5
+ export interface LintFinding {
6
+ readonly file: string;
7
+ readonly severity: 1 | 2;
8
+ readonly line?: number | undefined;
9
+ readonly column?: number | undefined;
10
+ readonly ruleId: string | null;
11
+ readonly message: string;
12
+ readonly fatal?: boolean | undefined;
13
+ }
14
+
15
+ export interface SubmissionLint {
16
+ readonly errors: readonly LintFinding[];
17
+ readonly warnings: readonly LintFinding[];
18
+ readonly abstractWarnings: readonly LintFinding[];
19
+ readonly introductionWarnings: readonly LintFinding[];
20
+ }
21
+
22
+ export interface PaperSections {
23
+ readonly paper: PaperSource;
24
+ readonly abstract: Span | null;
25
+ readonly outline: Outline;
26
+ }
27
+
28
+ const introductionNames: ReadonlySet<string> = new Set([
29
+ "introduction",
30
+ "intro",
31
+ ]);
32
+
33
+ function introductionOf({ sections, backMatter, end }: Outline): Span | null {
34
+ const headings = sections.flatMap(({ place, title }) =>
35
+ place.kind === "at" ? [{ start: place.span.start, title }] : [],
36
+ );
37
+ const at = headings.findIndex(({ title }) =>
38
+ introductionNames.has(title.toLowerCase().split(" ", 1).join("")),
39
+ );
40
+ const heading = headings[at];
41
+ if (heading === undefined) return null;
42
+ return {
43
+ start: heading.start,
44
+ end: Math.min(
45
+ headings[at + 1]?.start ?? Infinity,
46
+ backMatter ?? end ?? Infinity,
47
+ ),
48
+ };
49
+ }
50
+
51
+ function offsetOf(
52
+ source: string,
53
+ { line, column }: LintFinding,
54
+ ): number | null {
55
+ if (line === undefined || line < 1) return null;
56
+ const lines = source.split("\n");
57
+ if (line > lines.length) return null;
58
+ return (
59
+ lines
60
+ .slice(0, line - 1)
61
+ .reduce((offset, text) => offset + text.length + 1, 0) +
62
+ (column ?? 1) -
63
+ 1
64
+ );
65
+ }
66
+
67
+ const contains = ({ start, end }: Span, offset: number): boolean =>
68
+ start <= offset && offset < end;
69
+
70
+ const onlySectionText = (text: string, section: Span, s: Segment): boolean =>
71
+ !text.slice(s.start, Math.min(s.end, section.start)).trim() &&
72
+ !text.slice(Math.max(s.start, section.end), s.end).trim();
73
+
74
+ /** Given ESLint's structured location, recover the assembled position or its outer include. */
75
+ function inSection(
76
+ paper: PaperSource,
77
+ finding: LintFinding,
78
+ section: Span,
79
+ ): boolean {
80
+ const source = paper.segments.find((s) => s.file === finding.file)?.source;
81
+ const offset = source === undefined ? null : offsetOf(source, finding);
82
+ if (offset === null) return false;
83
+ const included = paper.segments.filter(
84
+ (s) =>
85
+ finding.file === paper.main && s.via !== null && contains(s.via, offset),
86
+ );
87
+ // An include can hold more than one section. Its anchor alone cannot decide which warned.
88
+ if (included.length > 0)
89
+ return (
90
+ included.some((s) => s.start < section.end && s.end > section.start) &&
91
+ included.every((s) => onlySectionText(paper.text, section, s))
92
+ );
93
+ return paper.segments.some(
94
+ (s) =>
95
+ s.file === finding.file &&
96
+ offset >= s.from &&
97
+ offset < s.from + s.end - s.start &&
98
+ contains(section, s.start + offset - s.from),
99
+ );
100
+ }
101
+
102
+ export function submissionLint(
103
+ findings: readonly LintFinding[],
104
+ sections: PaperSections | null,
105
+ ): SubmissionLint {
106
+ const [warnings, errors] = partition(findings, (m) => m.severity === 1);
107
+ const inSpan = (span: Span | null) =>
108
+ sections === null || span === null
109
+ ? []
110
+ : warnings.filter((m) => inSection(sections.paper, m, span));
111
+ return {
112
+ errors,
113
+ warnings,
114
+ abstractWarnings: inSpan(sections?.abstract ?? null),
115
+ introductionWarnings: inSpan(
116
+ sections === null ? null : introductionOf(sections.outline),
117
+ ),
118
+ };
119
+ }
120
+
121
+ export const lintFindingLine = (m: LintFinding): string => {
122
+ const place = m.line
123
+ ? `${m.file}:${String(m.line)}:${String(m.column ?? 1)}`
124
+ : m.file;
125
+ return `${place}${m.ruleId === null ? "" : ` ${m.ruleId}`} — ${m.message.trim()}`;
126
+ };
127
+
128
+ const count = (n: number, noun: string): string =>
129
+ `${String(n)} ${noun}${n === 1 ? "" : "s"}`;
130
+
131
+ export const lintSummary = (lint: SubmissionLint): string =>
132
+ `lint: ${count(lint.errors.length, "error")}, ${count(lint.warnings.length, "warning")} (abstract: ${String(lint.abstractWarnings.length)}, introduction: ${String(lint.introductionWarnings.length)})`;
133
+
134
+ const block = (
135
+ title: string,
136
+ findings: readonly LintFinding[],
137
+ ): readonly string[] =>
138
+ findings.length === 0
139
+ ? []
140
+ : [title, ...findings.map((m) => ` ${lintFindingLine(m)}`)];
141
+
142
+ export const lintReportLines = (lint: SubmissionLint): readonly string[] => [
143
+ lintSummary(lint),
144
+ ...block("Abstract warnings", lint.abstractWarnings),
145
+ ...block("Introduction warnings", lint.introductionWarnings),
146
+ ...block("Lint errors", lint.errors),
147
+ ...block(
148
+ "Other lint warnings",
149
+ lint.warnings.filter(
150
+ (m) =>
151
+ !lint.abstractWarnings.includes(m) &&
152
+ !lint.introductionWarnings.includes(m),
153
+ ),
154
+ ),
155
+ ];
156
+
157
+ export const lintExceptionReason = (reason: string): string =>
158
+ `Allow lint errors: ${JSON.stringify(reason.trim())}`;
159
+
160
+ export const lintExceptionLines = (
161
+ lint: SubmissionLint,
162
+ reason: string,
163
+ ): readonly string[] => [
164
+ lintExceptionReason(reason),
165
+ ...lint.errors.map((m) => ` ${lintFindingLine(m)}`),
166
+ ];
@@ -0,0 +1,10 @@
1
+ import type { Result } from "../domain/result.ts";
2
+ import type { SubmissionLint } from "../domain/submission-lint.ts";
3
+
4
+ /** A completed paper lint, or the reason it could not make a decision. */
5
+ export type SubmissionLintResult = Result<SubmissionLint, string>;
6
+
7
+ export type SubmissionLinter = (
8
+ paperDir: string,
9
+ cwd: string,
10
+ ) => Promise<SubmissionLintResult>;
package/src/structure.ts CHANGED
@@ -142,9 +142,7 @@ export function formatStructure(findings: readonly StructureFinding[]): string {
142
142
  * consumer to write a second parser — and the first one who did not write it would read "there
143
143
  * are no structural findings" instead of "I do not parse them".
144
144
  */
145
- export function asEslintResults(
146
- findings: readonly StructureFinding[],
147
- ): unknown[] {
145
+ export function asEslintResults(findings: readonly StructureFinding[]) {
148
146
  const byDir = new Map<string, string[]>();
149
147
  for (const f of findings)
150
148
  byDir.set(f.file, [...(byDir.get(f.file) ?? []), f.message]);
@@ -152,7 +150,7 @@ export function asEslintResults(
152
150
  filePath,
153
151
  messages: msgs.map((message: string) => ({
154
152
  ruleId: "structure/required-file",
155
- severity: 2,
153
+ severity: 2 as const,
156
154
  message,
157
155
  line: 0,
158
156
  column: 0,
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The `submission-confirm` hook over a lint exception: when the paper's lint cannot be run, the
3
+ * exception cannot be approved, and the refusal says why.
4
+ */
5
+ import { expect, test } from "vitest";
6
+ import { leafCommandsNormalized as shellLeaves } from "vigiles/hook";
7
+ import { memoryFiles } from "./adapters/memory/index.ts";
8
+ import { err } from "./domain/result.ts";
9
+ import { submissionConfirm } from "./submission-confirm-hook.ts";
10
+ import { submissionSend, uploadSend } from "./cli.ts";
11
+ import { presetsDir } from "./package-dirs.ts";
12
+ import { PDF, facts, withPresets } from "../test/submission-fixtures.ts";
13
+
14
+ test("a lint exception is refused with the reason when the paper's lint could not be run", () => {
15
+ const command =
16
+ "npx paperlint submission update papers/p --submit --save --allow-lint-errors 'Known exception'";
17
+ const screen = submissionConfirm(
18
+ JSON.stringify({
19
+ tool_name: "Bash",
20
+ tool_input: { command },
21
+ cwd: "/w",
22
+ transcript_path: "/t/session.jsonl",
23
+ tool_use_id: "now",
24
+ }),
25
+ {
26
+ files: withPresets(
27
+ memoryFiles({
28
+ "/t/session.jsonl": "",
29
+ "/w/papers/p/paper.pdf": PDF,
30
+ "/w/papers/p/_build/paper.facts.json": facts(),
31
+ }),
32
+ ),
33
+ venuesDir: presetsDir(),
34
+ portalHosts: () => [],
35
+ shellLeaves,
36
+ readSend: submissionSend,
37
+ readUpload: uploadSend,
38
+ lintPaper: () => err("paperlint lint did not produce a report"),
39
+ },
40
+ );
41
+ expect(screen?.hookSpecificOutput.permissionDecision).toBe("deny");
42
+ const shown = screen?.hookSpecificOutput.permissionDecisionReason ?? "";
43
+ expect(shown).toContain(
44
+ "Cannot approve a lint exception: paperlint lint did not produce a report",
45
+ );
46
+ expect(shown).not.toContain("Allow lint errors:");
47
+ });
@@ -7,6 +7,8 @@ import { expect, test } from "vitest";
7
7
  import { memoryFiles } from "./adapters/memory/index.ts";
8
8
  import type { AbsolutePath } from "./domain/paths.ts";
9
9
  import { sha256Hex } from "./domain/sha256.ts";
10
+ import { ok } from "./domain/result.ts";
11
+ import { submissionLint } from "./domain/submission-lint.ts";
10
12
  import type { Files } from "./ports/files.ts";
11
13
  import { leafCommandsNormalized as shellLeaves } from "vigiles/hook";
12
14
  import { submissionSend, uploadSend } from "./cli.ts";
@@ -44,6 +46,7 @@ const submissionConfirm = (
44
46
  shellLeaves,
45
47
  readSend: submissionSend,
46
48
  readUpload: uploadSend,
49
+ lintPaper: () => ok(submissionLint([], null)),
47
50
  ...more,
48
51
  });
49
52
 
@@ -156,11 +159,9 @@ const NOT_SENT = "Not run: this sends the paper to the venue's portal";
156
159
  const HEAD = `${NOT_SENT}, and the person has not said yes to it since the last send.`;
157
160
  /** What the agent is told to ask: the last lines of that refusal. */
158
161
  const LAST = [
159
- "Ask the person with AskUserQuestion first, then run this command again. In the question, give:",
160
- "- 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),",
161
- "- what the lines above say about the build (the body pages, or that it is stale or missing),",
162
- "- the dry run's venue check, quoted word for word (its `venue rules at their default options` line and every error under it).",
163
- 'Options: "Yes, send it" and "No". One yes lets one send through: ask one question per send, each naming its own folder and sha256.',
162
+ "Ask with AskUserQuestion. Show the action, one lint summary line from the dry run, and the full paper folder, PDF and sha256 above.",
163
+ "For an exception, copy the Action, Lint exception, reason and blocking errors above. Mention stale or missing build facts.",
164
+ 'Options: "Yes, proceed" and "No". One yes covers one command.',
164
165
  ].join("\n");
165
166
 
166
167
  test("no yes: refused, telling the agent what to ask — the paper folder, the PDF and its sha256, the body pages, the venue check, yes or no", () => {
@@ -173,6 +174,7 @@ test("no yes: refused, telling the agent what to ask — the paper folder, the P
173
174
  "paper folder: /w/papers/p",
174
175
  `PDF: papers/p/paper.pdf, sha256 ${HEX.slice(0, 12)}`,
175
176
  "body pages: 4 (up to the references on page 5)",
177
+ "Action: Mark submission ready for review",
176
178
  LAST,
177
179
  ].join("\n"),
178
180
  },
@@ -187,6 +189,7 @@ test("a stale build is said loudly; no facts and broken facts are said too", ()
187
189
  `PDF: papers/p/paper.pdf, sha256 ${HEX.slice(0, 12)}`,
188
190
  "!! THE LAST BUILD IS NOT OF THIS PDF — the check did not see it. Rebuild (`paperlint build`) and run the dry run again.",
189
191
  "body pages: 4 (up to the references on page 5)",
192
+ "Action: Mark submission ready for review",
190
193
  LAST,
191
194
  ].join("\n"),
192
195
  );
@@ -221,6 +224,7 @@ test("a PDF that is not there: refused, whatever the transcript says — there i
221
224
  "PDF: gone.pdf — NOT FOUND",
222
225
  "!! THE LAST BUILD IS NOT OF THIS PDF — the check did not see it. Rebuild (`paperlint build`) and run the dry run again.",
223
226
  "body pages: 4 (up to the references on page 5)",
227
+ "Action: Save changes to submission",
224
228
  ),
225
229
  );
226
230
  });
@@ -523,7 +527,11 @@ const asksAbout = (folder: string, sha: string) =>
523
527
  const asks = (sha: string) => asksAbout("/w/papers/p", sha);
524
528
 
525
529
  /** The hook's answer to SEND, over the paper with this transcript. */
526
- const withTranscript = (lines: readonly string[], command = SEND) =>
530
+ const withTranscript = (
531
+ lines: readonly string[],
532
+ command = SEND,
533
+ more: Partial<ConfirmDeps> = {},
534
+ ) =>
527
535
  submissionConfirm(
528
536
  payload(command),
529
537
  memoryFiles({
@@ -531,8 +539,67 @@ const withTranscript = (lines: readonly string[], command = SEND) =>
531
539
  "/w/papers/p/paper.pdf": PDF,
532
540
  "/w/papers/p/_build/paper.facts.json": facts(),
533
541
  }),
542
+ more,
534
543
  );
535
544
 
545
+ test("the lint exception requires its current reason, action and blocking findings in the question", () => {
546
+ const command = `${SEND} --allow-lint-errors 'Known exception'`;
547
+ const lintPaper = (message: string) => () =>
548
+ ok(
549
+ submissionLint(
550
+ [
551
+ {
552
+ file: "paper.tex",
553
+ ruleId: "repro/example",
554
+ severity: 2,
555
+ line: 4,
556
+ column: 2,
557
+ message,
558
+ },
559
+ ],
560
+ null,
561
+ ),
562
+ );
563
+ const check = { lintPaper: lintPaper("Missing result") };
564
+ const screen = withTranscript(
565
+ question("q1", asks(SHA), "Yes"),
566
+ command,
567
+ check,
568
+ );
569
+ expect(screen?.hookSpecificOutput.permissionDecision).toBe("deny");
570
+ const shown = screen?.hookSpecificOutput.permissionDecisionReason ?? "";
571
+ expect(shown).toContain('Allow lint errors: "Known exception"');
572
+ expect(shown).toContain(" paper.tex:4:2 repro/example — Missing result");
573
+ const exception = shown
574
+ .split("\n")
575
+ .filter((line) =>
576
+ ["Action:", "Lint exception:", "Allow lint errors:", " paper.tex:"].some(
577
+ (start) => line.startsWith(start),
578
+ ),
579
+ );
580
+ const approved = question(
581
+ "q2",
582
+ [asks(SHA), ...exception].join("\n"),
583
+ "Yes, proceed",
584
+ );
585
+ expect(withTranscript(approved, command, check)).toBeNull();
586
+ expect(
587
+ withTranscript(approved, command, {
588
+ lintPaper: lintPaper("Another result is missing"),
589
+ }),
590
+ ).not.toBeNull();
591
+ expect(
592
+ withTranscript(
593
+ approved,
594
+ command.replace("Known exception", "New reason"),
595
+ check,
596
+ ),
597
+ ).not.toBeNull();
598
+ expect(
599
+ withTranscript(approved, command.replace(" --submit", ""), check),
600
+ ).not.toBeNull();
601
+ });
602
+
536
603
  test("a yes to a question naming the PDF's sha256: the send runs — the hook says nothing, so Claude Code's own permissions apply", () => {
537
604
  expect(withTranscript(question("q1", asks(SHA), "Yes, send it"))).toBe(null);
538
605
  // The answer is a yes by its first word, in any case, typed or chosen.