paperlint 20.1.2 → 20.3.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 (96) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CLAUDE.md +5 -1
  3. package/dist/adapters/venue-corpus/index.d.ts +361 -0
  4. package/dist/adapters/venue-corpus/index.d.ts.map +1 -0
  5. package/dist/adapters/venue-corpus/index.js +221 -0
  6. package/dist/adapters/venue-corpus/index.js.map +1 -0
  7. package/dist/cli.d.ts +4 -3
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +42 -13
  10. package/dist/cli.js.map +1 -1
  11. package/dist/corpus-record-rule.d.ts +65 -0
  12. package/dist/corpus-record-rule.d.ts.map +1 -0
  13. package/dist/corpus-record-rule.js +85 -0
  14. package/dist/corpus-record-rule.js.map +1 -0
  15. package/dist/domain/corpus-record.d.ts +51 -0
  16. package/dist/domain/corpus-record.d.ts.map +1 -0
  17. package/dist/domain/corpus-record.js +119 -0
  18. package/dist/domain/corpus-record.js.map +1 -0
  19. package/dist/domain/licence.d.ts +51 -0
  20. package/dist/domain/licence.d.ts.map +1 -0
  21. package/dist/domain/licence.js +61 -0
  22. package/dist/domain/licence.js.map +1 -0
  23. package/dist/domain/venue-corpus.d.ts +142 -0
  24. package/dist/domain/venue-corpus.d.ts.map +1 -0
  25. package/dist/domain/venue-corpus.js +17 -0
  26. package/dist/domain/venue-corpus.js.map +1 -0
  27. package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  28. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  29. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  30. package/dist/paper-files.d.ts +10 -3
  31. package/dist/paper-files.d.ts.map +1 -1
  32. package/dist/paper-files.js +17 -2
  33. package/dist/paper-files.js.map +1 -1
  34. package/dist/papers-roots.d.ts +6 -0
  35. package/dist/papers-roots.d.ts.map +1 -1
  36. package/dist/papers-roots.js +14 -0
  37. package/dist/papers-roots.js.map +1 -1
  38. package/dist/ports/venue-corpus-codec.d.ts +11 -0
  39. package/dist/ports/venue-corpus-codec.d.ts.map +1 -0
  40. package/dist/ports/venue-corpus-codec.js +2 -0
  41. package/dist/ports/venue-corpus-codec.js.map +1 -0
  42. package/dist/skill-chunks/chunk-5KCU4WTN.js +108 -0
  43. package/dist/skill-chunks/{chunk-X4VKG4KT.js → chunk-6YEM4VDI.js} +11 -9
  44. package/dist/skill-chunks/{chunk-L3NJUJUP.js → chunk-CXAGKT44.js} +5 -3
  45. package/dist/skill-chunks/{chunk-6NU6CXUS.js → chunk-J5XYPERO.js} +12 -72
  46. package/dist/skill-chunks/{chunk-IREAROCV.js → chunk-Z5YMDZYW.js} +4 -0
  47. package/dist/skills/study-accepted-papers/scripts/corpus-licences-core.d.ts +54 -0
  48. package/dist/skills/study-accepted-papers/scripts/corpus-licences.d.ts +2 -0
  49. package/docs/design/venue-corpus.md +271 -0
  50. package/docs/layout.md +2 -2
  51. package/docs/rules/corpus/record.md +119 -0
  52. package/docs/rules.md +1 -0
  53. package/docs/venues.md +158 -24
  54. package/eslint-rules/CLAUDE.md +5 -1
  55. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  56. package/eslint.config.mjs +1 -0
  57. package/package.json +3 -1
  58. package/scripts/bundle-skills.ts +1 -0
  59. package/scripts/eslint-file-length.mjs +3 -3
  60. package/scripts/venue-corpus-schema.test.ts +39 -0
  61. package/scripts/venue-corpus-schema.ts +17 -0
  62. package/skills/argument-arc/scripts/headings.js +6 -4
  63. package/skills/cold-read-diff/scripts/cold-read.js +6 -4
  64. package/skills/paper-pipeline/scripts/extract-ref-facts.js +6 -5
  65. package/skills/pc-panel-review/scripts/prior-reviews.js +7 -5
  66. package/skills/study-accepted-papers/SKILL.md +34 -2
  67. package/skills/study-accepted-papers/SKILL.md.spec.ts +33 -1
  68. package/skills/study-accepted-papers/papers.schema.json +474 -0
  69. package/skills/study-accepted-papers/scripts/corpus-licences-core.js +180 -0
  70. package/skills/study-accepted-papers/scripts/corpus-licences-core.ts +303 -0
  71. package/skills/study-accepted-papers/scripts/corpus-licences.js +393 -0
  72. package/skills/study-accepted-papers/scripts/corpus-licences.test.ts +488 -0
  73. package/skills/study-accepted-papers/scripts/corpus-licences.ts +27 -0
  74. package/skills/verify-citations/scripts/bib-authors.js +6 -5
  75. package/skills/verify-citations/scripts/verify-cites.js +6 -5
  76. package/src/adapters/venue-corpus/index.test.ts +337 -0
  77. package/src/adapters/venue-corpus/index.ts +306 -0
  78. package/src/cli-e2e.test.mjs +2 -2
  79. package/src/cli.test.ts +1 -1
  80. package/src/cli.ts +57 -13
  81. package/src/corpus-record-rule.test.ts +228 -0
  82. package/src/corpus-record-rule.ts +175 -0
  83. package/src/domain/corpus-record.test.ts +163 -0
  84. package/src/domain/corpus-record.ts +210 -0
  85. package/src/domain/licence.test.ts +122 -0
  86. package/src/domain/licence.ts +95 -0
  87. package/src/domain/venue-corpus.ts +159 -0
  88. package/src/paper-files.test.ts +13 -4
  89. package/src/paper-files.ts +23 -2
  90. package/src/paper-settings-commands.test.ts +2 -2
  91. package/src/papers-roots.test.ts +34 -1
  92. package/src/papers-roots.ts +15 -0
  93. package/src/ports/venue-corpus-codec.ts +11 -0
  94. package/src/rule-cases.test.ts +15 -0
  95. package/src/settled-paper.test.ts +1 -1
  96. package/src/unowned-file.test.ts +1 -1
@@ -0,0 +1,163 @@
1
+ /** The corpus record's judge: each finding of `corpus/record`, and silence on a corpus that keeps its record. */
2
+ import { describe, expect, it } from "vitest";
3
+ import {
4
+ corpusMessage,
5
+ judgeCorpus,
6
+ storedKey,
7
+ type CorpusFinding,
8
+ type CorpusFolder,
9
+ } from "./corpus-record.ts";
10
+ import type { Copy, Paper, VenueCorpus } from "./venue-corpus.ts";
11
+
12
+ const copy = (stored: Copy["stored"]): Copy => ({
13
+ version: "published",
14
+ url: "https://doi.org/10.1/x",
15
+ licence: { id: "NOASSERTION" },
16
+ stored,
17
+ ...(stored.length > 0 ? { fetched_from: "https://doi.org/10.1/x" } : {}),
18
+ });
19
+
20
+ const paper = (key: string, copies: readonly Copy[]): Paper => ({
21
+ key,
22
+ title: "A title",
23
+ group: "accepted",
24
+ edition: 2026,
25
+ ids: { doi: "10.1/x" },
26
+ copies,
27
+ });
28
+
29
+ const corpus = (papers: readonly Paper[]): VenueCorpus => ({
30
+ venue: "agent",
31
+ editions: [],
32
+ papers,
33
+ rebuild: [],
34
+ });
35
+
36
+ const folder = (
37
+ record: CorpusFolder["record"],
38
+ pdf: readonly string[] = [],
39
+ text: readonly string[] = [],
40
+ ): CorpusFolder => ({ record, stored: { pdf, text } });
41
+
42
+ const read = (papers: readonly Paper[]): CorpusFolder["record"] => ({
43
+ ok: true,
44
+ corpus: corpus(papers),
45
+ });
46
+
47
+ describe("storedKey: the paper a stored file's name belongs to", () => {
48
+ it.each([
49
+ ["pdf", "2026-01.pdf", "2026-01"],
50
+ ["text", "2026-01.txt", "2026-01"],
51
+ ["text", "2026-01.pdfminer.txt", "2026-01"],
52
+ ["pdf", "2026-01.txt", null],
53
+ ["pdf", "a.b.pdf", null],
54
+ ["text", "2026-01.pdf", null],
55
+ ["text", "2026-01..txt", null],
56
+ ["text", ".txt", null],
57
+ ] as const)("%s/%s → %s", (kind, name, key) => {
58
+ // Guards: a name outside `<key>.pdf` / `<key>[.<variant>].txt` belongs to no paper.
59
+ expect(storedKey(kind, name)).toBe(key);
60
+ });
61
+ });
62
+
63
+ describe("judgeCorpus", () => {
64
+ it("is silent when every stored file is claimed by exactly one copy and exists", () => {
65
+ expect(
66
+ judgeCorpus(
67
+ folder(
68
+ read([paper("a", [copy(["pdf", "text"]), copy([])])]),
69
+ ["a.pdf"],
70
+ ["a.txt", "a.pdfminer.txt"],
71
+ ),
72
+ ),
73
+ ).toEqual([]);
74
+ });
75
+
76
+ it("reports a record that does not parse: each of the codec's problems at its path", () => {
77
+ expect(
78
+ judgeCorpus(
79
+ folder({
80
+ ok: false,
81
+ problems: [
82
+ { path: ["papers", 0, "key"], message: "x" },
83
+ { path: [], message: "not JSON" },
84
+ ],
85
+ }),
86
+ ),
87
+ ).toEqual([
88
+ { kind: "unparsed", at: ["papers", 0, "key"], message: "x" },
89
+ { kind: "unparsed", at: [], message: "not JSON" },
90
+ ]);
91
+ });
92
+ });
93
+
94
+ describe("judgeCorpus: a record that does not account for the folder", () => {
95
+ it("reports a claimed PDF that is not there at the stored of the copy that claims it", () => {
96
+ expect(
97
+ judgeCorpus(folder(read([paper("a", [copy([]), copy(["pdf"])])]))),
98
+ ).toEqual([
99
+ {
100
+ kind: "missing",
101
+ at: ["papers", 0, "copies", 1, "stored"],
102
+ key: "a",
103
+ stored: "pdf",
104
+ file: "pdf/a.pdf",
105
+ },
106
+ ]);
107
+ });
108
+
109
+ it("reports an unclaimed file, a missing file and two copies storing one kind", () => {
110
+ expect(
111
+ judgeCorpus(
112
+ folder(
113
+ read([
114
+ paper("a", [copy(["pdf"]), copy(["pdf"])]),
115
+ paper("b", [copy(["text"])]),
116
+ ]),
117
+ ["a.pdf", "b.pdf", "c.pdf", "notes.docx"],
118
+ [],
119
+ ),
120
+ ),
121
+ ).toEqual([
122
+ {
123
+ kind: "twice",
124
+ at: ["papers", 0, "copies", 1, "stored"],
125
+ key: "a",
126
+ stored: "pdf",
127
+ copies: [0, 1],
128
+ },
129
+ // A file of a listed paper is reported at that paper's copies; any other, on the record.
130
+ {
131
+ kind: "unclaimed",
132
+ at: ["papers", 1, "copies"],
133
+ file: "pdf/b.pdf",
134
+ key: "b",
135
+ },
136
+ { kind: "unclaimed", at: [], file: "pdf/c.pdf", key: "c" },
137
+ { kind: "unclaimed", at: [], file: "pdf/notes.docx", key: null },
138
+ {
139
+ kind: "missing",
140
+ at: ["papers", 1, "copies", 0, "stored"],
141
+ key: "b",
142
+ stored: "text",
143
+ file: "text/b.txt",
144
+ },
145
+ ]);
146
+ });
147
+ });
148
+
149
+ describe("corpusMessage: every finding names its cure", () => {
150
+ const at = ["papers", 0, "copies", 0, "stored"];
151
+ const findings: readonly CorpusFinding[] = [
152
+ { kind: "unparsed", at: ["papers", 0, "key"], message: "x" },
153
+ { kind: "unparsed", at: [], message: "not JSON" },
154
+ { kind: "unclaimed", at: [], file: "pdf/b.pdf", key: "b" },
155
+ { kind: "unclaimed", at: [], file: "pdf/x.docx", key: null },
156
+ { kind: "missing", at, key: "b", stored: "text", file: "text/b.txt" },
157
+ { kind: "twice", at, key: "a", stored: "pdf", copies: [0, 1] },
158
+ ];
159
+ it.each(findings)("$kind", (f) => {
160
+ // Guards: each message says what to do, after the finding itself.
161
+ expect(corpusMessage(f)).toMatch(/What to do: \S/u);
162
+ });
163
+ });
@@ -0,0 +1,210 @@
1
+ /**
2
+ * `corpus/record`'s judgement of one venue corpus (docs/design/venue-corpus.md, decisions 4–6;
3
+ * docs/rules/corpus/record.md): whether every copy stored in `pdf/` and `text/` is accounted for by
4
+ * `papers.json`. Pure: the folder's listing and the record, already parsed by the codec, in; the
5
+ * findings out. What the record's fields mean is `venue-corpus.ts`; this file never re-checks them.
6
+ *
7
+ * A stored file's path follows from its paper's `key` (decision 5): `pdf/<key>.pdf`,
8
+ * `text/<key>.txt` and `text/<key>.<variant>.txt`. The folder is named after the kind it holds.
9
+ */
10
+ import { STORED_KINDS, type StoredKind } from "./licence.ts";
11
+ import {
12
+ CORPUS_RECORD,
13
+ KEY_PATTERN,
14
+ pathText,
15
+ type Paper,
16
+ type ParsedCorpus,
17
+ type RecordPath,
18
+ type VenueCorpus,
19
+ } from "./venue-corpus.ts";
20
+
21
+ /** The folder in a papers root that holds one corpus per venue. */
22
+ export const CORPORA_DIR = "venues";
23
+
24
+ /** What the rule reads of one corpus folder. */
25
+ export interface CorpusFolder {
26
+ /** `papers.json`, as the codec parsed it. */
27
+ readonly record: ParsedCorpus;
28
+ /** The names in `pdf/` and in `text/`, hidden ones left out; none when the folder is absent. */
29
+ readonly stored: Readonly<Record<StoredKind, readonly string[]>>;
30
+ }
31
+
32
+ /**
33
+ * One finding, with `at`, the path in `papers.json` it is reported at (empty: the whole file);
34
+ * `file` is relative to the corpus folder.
35
+ */
36
+ export type CorpusFinding = { readonly at: RecordPath } & (
37
+ | { readonly kind: "unparsed"; readonly message: string }
38
+ | {
39
+ readonly kind: "unclaimed";
40
+ readonly file: string;
41
+ readonly key: string | null;
42
+ }
43
+ | {
44
+ readonly kind: "missing";
45
+ readonly key: string;
46
+ readonly stored: StoredKind;
47
+ readonly file: string;
48
+ }
49
+ | {
50
+ readonly kind: "twice";
51
+ readonly key: string;
52
+ readonly stored: StoredKind;
53
+ readonly copies: readonly number[];
54
+ }
55
+ );
56
+
57
+ const keyOrNull = (key: string): string | null =>
58
+ KEY_PATTERN.test(key) ? key : null;
59
+
60
+ /** The key a stored file's name belongs to, or null when the name is not one a copy can store. */
61
+ export function storedKey(kind: StoredKind, name: string): string | null {
62
+ switch (kind) {
63
+ case "pdf":
64
+ return name.endsWith(".pdf") ? keyOrNull(name.slice(0, -4)) : null;
65
+ case "text": {
66
+ if (!name.endsWith(".txt")) return null;
67
+ const [key = "", ...variant] = name.slice(0, -4).split(".");
68
+ return variant.length > 0 && variant.join(".") === ""
69
+ ? null
70
+ : keyOrNull(key);
71
+ }
72
+ }
73
+ }
74
+
75
+ /** The extension of a stored kind's file. */
76
+ const EXTENSION: Readonly<Record<StoredKind, string>> = {
77
+ pdf: "pdf",
78
+ text: "txt",
79
+ };
80
+
81
+ /** The name the record expects a paper's stored kind under, for a message. */
82
+ const expectedFile = (kind: StoredKind, key: string): string =>
83
+ `${kind}/${key}.${EXTENSION[kind]}`;
84
+
85
+ /** The indexes of `p`'s copies that store `kind`. */
86
+ const storing = (p: Paper, kind: StoredKind): readonly number[] =>
87
+ p.copies.flatMap((c, i) => (c.stored.includes(kind) ? [i] : []));
88
+
89
+ /** Which copies of one paper (the `paper`-th of the record) store one kind. */
90
+ interface Claim {
91
+ readonly kind: StoredKind;
92
+ readonly key: string;
93
+ readonly paper: number;
94
+ readonly copies: readonly number[];
95
+ }
96
+
97
+ /** The `stored` of a paper's copy (`copy` holds its index), as a path. */
98
+ const storedAt = (paper: number, copy: readonly number[]): RecordPath => [
99
+ "papers",
100
+ paper,
101
+ "copies",
102
+ ...copy,
103
+ "stored",
104
+ ];
105
+
106
+ /** A paper's kind stored by more than one of its copies, reported at the second one. */
107
+ const twice = (claims: readonly Claim[]): readonly CorpusFinding[] =>
108
+ claims
109
+ .filter((c) => c.copies.length > 1)
110
+ .map((c) => ({
111
+ kind: "twice",
112
+ at: storedAt(c.paper, c.copies.slice(1, 2)),
113
+ key: c.key,
114
+ stored: c.kind,
115
+ copies: c.copies,
116
+ }));
117
+
118
+ /** A stored file no copy claims: at its paper's copies when the record lists the paper, else on the file. */
119
+ const unclaimed = (
120
+ claims: readonly Claim[],
121
+ stored: CorpusFolder["stored"],
122
+ ): readonly CorpusFinding[] =>
123
+ STORED_KINDS.flatMap((kind) =>
124
+ stored[kind]
125
+ .map((name) => ({ name, key: storedKey(kind, name) }))
126
+ .filter(
127
+ (f) =>
128
+ !claims.some(
129
+ (c) => c.kind === kind && c.key === f.key && c.copies.length > 0,
130
+ ),
131
+ )
132
+ .map((f) => ({
133
+ kind: "unclaimed",
134
+ at: atPaper(claims, f.key),
135
+ file: `${kind}/${f.name}`,
136
+ key: f.key,
137
+ })),
138
+ );
139
+
140
+ /** The copies of the paper `key` names, as a path; the whole file when no paper has that key. */
141
+ const atPaper = (claims: readonly Claim[], key: string | null): RecordPath => {
142
+ const claim = claims.find((c) => c.key === key);
143
+ return claim === undefined ? [] : ["papers", claim.paper, "copies"];
144
+ };
145
+
146
+ /** A claimed kind with no file of its paper's key. */
147
+ const missing = (
148
+ claims: readonly Claim[],
149
+ stored: CorpusFolder["stored"],
150
+ ): readonly CorpusFinding[] =>
151
+ claims
152
+ .filter(
153
+ (c) =>
154
+ c.copies.length > 0 &&
155
+ !stored[c.kind].some((name) => storedKey(c.kind, name) === c.key),
156
+ )
157
+ .map((c) => ({
158
+ kind: "missing",
159
+ at: storedAt(c.paper, c.copies.slice(0, 1)),
160
+ key: c.key,
161
+ stored: c.kind,
162
+ file: expectedFile(c.kind, c.key),
163
+ }));
164
+
165
+ /** What a read record says about the folder. */
166
+ function judgeRecord(
167
+ corpus: VenueCorpus,
168
+ stored: CorpusFolder["stored"],
169
+ ): readonly CorpusFinding[] {
170
+ const claims = STORED_KINDS.flatMap((kind) =>
171
+ corpus.papers.map((p, paper) => ({
172
+ kind,
173
+ key: p.key,
174
+ paper,
175
+ copies: storing(p, kind),
176
+ })),
177
+ );
178
+ return [
179
+ ...twice(claims),
180
+ ...unclaimed(claims, stored),
181
+ ...missing(claims, stored),
182
+ ];
183
+ }
184
+
185
+ /** Every finding about one corpus folder; none for a corpus whose record accounts for each copy. */
186
+ export const judgeCorpus = (folder: CorpusFolder): readonly CorpusFinding[] =>
187
+ folder.record.ok
188
+ ? judgeRecord(folder.record.corpus, folder.stored)
189
+ : folder.record.problems.map((p) => ({
190
+ kind: "unparsed",
191
+ at: p.path,
192
+ message: p.message,
193
+ }));
194
+
195
+ const KEEP_IDS =
196
+ "or remove the file and keep the paper's ids in `papers.json`, which is all a corpus needs to measure against it";
197
+
198
+ /** The text of a finding: what is wrong, then what to do. */
199
+ export function corpusMessage(f: CorpusFinding): string {
200
+ switch (f.kind) {
201
+ case "unparsed":
202
+ return `\`${pathText(f.at)}\`: ${f.message}. What to do: correct the field; the fields are in the JSON Schema \`papers.schema.json\` that \`study-accepted-papers\` ships`;
203
+ case "unclaimed":
204
+ return `\`${f.file}\` is stored, and no copy in \`${CORPUS_RECORD}\` claims it${f.key === null ? `: its name is not \`pdf/<key>.pdf\`, \`text/<key>.txt\` or \`text/<key>.<variant>.txt\`` : ` (no copy of the paper \`${f.key}\` lists it in \`stored\`)`}. What to do: record it under the copy it was fetched from, with \`fetched_from\`, its licence and where the licence was read; ${KEEP_IDS}`;
205
+ case "missing":
206
+ return `a copy of \`${f.key}\` stores \`${f.stored}\` in \`${CORPUS_RECORD}\`, and \`${f.file}\` is not there. What to do: put the file back, or remove \`"${f.stored}"\` from that copy's \`stored\``;
207
+ case "twice":
208
+ return `copies ${f.copies.join(" and ")} of \`${f.key}\` both store \`${f.stored}\`, and one stored file is a copy of one version. What to do: keep \`"${f.stored}"\` in the \`stored\` of the copy the file was fetched from, and remove it from the other`;
209
+ }
210
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The licence table (docs/design/venue-corpus.md, decision 3): what a copy's licence permits the
3
+ * corpus to store, for each kind, with and without the project's non-commercial setting.
4
+ */
5
+ import { describe, expect, it } from "vitest";
6
+ import {
7
+ isLicenceId,
8
+ permits,
9
+ type LicenceSettings,
10
+ type StoredKind,
11
+ } from "./licence.ts";
12
+
13
+ const COMMERCIAL: LicenceSettings = { nonCommercial: false };
14
+ const NON_COMMERCIAL: LicenceSettings = { nonCommercial: true };
15
+
16
+ /** What `id` permits for text and for the PDF, under `settings`. */
17
+ const both = (id: string, settings = COMMERCIAL) =>
18
+ Object.fromEntries(
19
+ (["text", "pdf"] as const satisfies readonly StoredKind[]).map((k) => [
20
+ k,
21
+ permits(id, k, settings),
22
+ ]),
23
+ );
24
+
25
+ const PERMITTED = { kind: "permitted" } as const;
26
+ const NC_ONLY = { kind: "non-commercial-only" } as const;
27
+ const ARXIV_WHY =
28
+ 'it grants arXiv alone the right to distribute: "We are thus unable to grant others the right to distribute arXiv articles"';
29
+ const ND_WHY =
30
+ "ND permits reproduction in unmodified form; whether an extracted text is an adaptation is unsettled";
31
+
32
+ describe("permits — what a copy's licence lets the corpus store", () => {
33
+ it.each(["CC0-1.0", "CC-BY-4.0", "CC-BY-SA-4.0"])(
34
+ "%s permits text and the PDF, whatever the setting",
35
+ (id) => {
36
+ // Guards: the open licences permit both kinds, commercial or not.
37
+ expect([both(id), both(id, NON_COMMERCIAL)]).toEqual([
38
+ { text: PERMITTED, pdf: PERMITTED },
39
+ { text: PERMITTED, pdf: PERMITTED },
40
+ ]);
41
+ },
42
+ );
43
+
44
+ it("🔴 CC-BY-NC-4.0 permits both only when the project is declared non-commercial", () => {
45
+ // Guards: NC is never assumed; the setting turns it on.
46
+ expect([
47
+ both("CC-BY-NC-4.0"),
48
+ both("CC-BY-NC-4.0", NON_COMMERCIAL),
49
+ ]).toEqual([
50
+ { text: NC_ONLY, pdf: NC_ONLY },
51
+ { text: PERMITTED, pdf: PERMITTED },
52
+ ]);
53
+ });
54
+
55
+ it("CC-BY-ND-4.0 permits the PDF and no extracted text; NC-ND adds the setting to the PDF", () => {
56
+ const noText = { kind: "forbidden", why: ND_WHY };
57
+ // Guards: ND never permits text, even under the setting; its PDF follows the NC rule.
58
+ expect([
59
+ both("CC-BY-ND-4.0"),
60
+ both("CC-BY-NC-ND-4.0"),
61
+ both("CC-BY-NC-ND-4.0", NON_COMMERCIAL),
62
+ ]).toEqual([
63
+ { text: noText, pdf: PERMITTED },
64
+ { text: noText, pdf: NC_ONLY },
65
+ { text: noText, pdf: PERMITTED },
66
+ ]);
67
+ });
68
+
69
+ it("🔴 arXiv's non-exclusive licence permits nothing, even under the setting", () => {
70
+ const no = { kind: "forbidden", why: ARXIV_WHY };
71
+ // Guards: the arXiv default grants nothing to a third party.
72
+ expect(both("LicenseRef-arxiv-nonexclusive-1.0", NON_COMMERCIAL)).toEqual({
73
+ text: no,
74
+ pdf: no,
75
+ });
76
+ });
77
+
78
+ it("NOASSERTION permits nothing, as its own result: the licence was not read", () => {
79
+ // Guards: an unread licence is not confused with a forbidding one.
80
+ expect(both("NOASSERTION", NON_COMMERCIAL)).toEqual({
81
+ text: { kind: "not-read" },
82
+ pdf: { kind: "not-read" },
83
+ });
84
+ });
85
+
86
+ it.each(["CC-BY-3.0", "CC-BY-4.O", "LicenseRef-mine", "constructor"])(
87
+ "🔴 an id outside the table (%s) permits nothing and is named",
88
+ (id) => {
89
+ // Guards: an unlisted id is its own result naming the id, never a permission.
90
+ expect(both(id, NON_COMMERCIAL)).toEqual({
91
+ text: { kind: "unlisted", id },
92
+ pdf: { kind: "unlisted", id },
93
+ });
94
+ },
95
+ );
96
+ });
97
+
98
+ describe("isLicenceId — the shape of an SPDX id or a LicenseRef", () => {
99
+ it("any SPDX-shaped id or LicenseRef- parses, listed or not", () => {
100
+ const ids = [
101
+ "CC-BY-4.0",
102
+ "CC-BY-3.0",
103
+ "GPL-2.0+",
104
+ "NOASSERTION",
105
+ "LicenseRef-arxiv-nonexclusive-1.0",
106
+ ];
107
+ // Guards: the parser accepts what the table may not list; the table judges it.
108
+ expect(ids.filter(isLicenceId)).toEqual(ids);
109
+ });
110
+
111
+ it("text that is no id does not", () => {
112
+ const notIds = [
113
+ "",
114
+ "CC BY 4.0",
115
+ "MIT OR Apache-2.0",
116
+ "-x",
117
+ "https://x.org",
118
+ ];
119
+ // Guards: a phrase, an expression or a URL is refused where it is read.
120
+ expect(notIds.filter(isLicenceId)).toEqual([]);
121
+ });
122
+ });
@@ -0,0 +1,95 @@
1
+ /**
2
+ * THE LICENCE TABLE — what a copy's licence permits a venue corpus to store (docs/design/venue-corpus.md,
3
+ * decision 3). A corpus keeps third-party papers; each stored file is a copy of one version, judged by
4
+ * that copy's licence (`papers.json`, `src/domain/venue-corpus.ts`).
5
+ *
6
+ * Any SPDX id or `LicenseRef-…` is a licence id where the record is parsed; this table decides what
7
+ * one permits. An id it does not list permits nothing and is its own result, naming the id, so one
8
+ * `CC-BY-3.0` does not hide the rest of a record and a typo is still loud. `NOASSERTION` (the licence
9
+ * was not read) permits nothing, as its own result. A non-commercial licence permits storing only in a
10
+ * project that declares itself non-commercial: paperlint does not assume it.
11
+ *
12
+ * A version of a CC licence other than 4.0 gets its row when a corpus meets it.
13
+ */
14
+
15
+ /** What a corpus stores of a copy: its extracted text (every variant), or the PDF. */
16
+ export const STORED_KINDS = ["text", "pdf"] as const;
17
+ export type StoredKind = (typeof STORED_KINDS)[number];
18
+
19
+ /** SPDX's own id for "no licence information was given": here, the licence was not read. */
20
+ export const NOASSERTION = "NOASSERTION";
21
+
22
+ /** The project's one setting the table reads: it declares itself non-commercial. */
23
+ export interface LicenceSettings {
24
+ readonly nonCommercial: boolean;
25
+ }
26
+
27
+ /** What a licence permits for one kind: storing it, or the one reason it may not be stored. */
28
+ export type Permission =
29
+ | { readonly kind: "permitted" }
30
+ | { readonly kind: "forbidden"; readonly why: string }
31
+ /** A non-commercial licence, in a project that has not declared itself non-commercial. */
32
+ | { readonly kind: "non-commercial-only" }
33
+ /** `NOASSERTION`: no licence was read for the copy. */
34
+ | { readonly kind: "not-read" }
35
+ /** An id the table does not list. */
36
+ | { readonly kind: "unlisted"; readonly id: string };
37
+
38
+ /** One kind's grant: always, never (with why), or only in a non-commercial project. */
39
+ type Grant = "yes" | { readonly no: string } | "non-commercial";
40
+
41
+ interface Row {
42
+ readonly text: Grant;
43
+ readonly pdf: Grant;
44
+ }
45
+
46
+ const ND = {
47
+ no: "ND permits reproduction in unmodified form; whether an extracted text is an adaptation is unsettled",
48
+ } as const;
49
+
50
+ const ARXIV = {
51
+ no: 'it grants arXiv alone the right to distribute: "We are thus unable to grant others the right to distribute arXiv articles"',
52
+ } as const;
53
+
54
+ const PUBLISHER = {
55
+ no: "the publisher grants no right to third parties",
56
+ } as const;
57
+
58
+ /** The table: an id → what it grants for text and for the PDF. */
59
+ const TABLE: ReadonlyMap<string, Row> = new Map<string, Row>([
60
+ ["CC0-1.0", { text: "yes", pdf: "yes" }],
61
+ ["CC-BY-4.0", { text: "yes", pdf: "yes" }],
62
+ ["CC-BY-SA-4.0", { text: "yes", pdf: "yes" }],
63
+ ["CC-BY-NC-4.0", { text: "non-commercial", pdf: "non-commercial" }],
64
+ ["CC-BY-NC-SA-4.0", { text: "non-commercial", pdf: "non-commercial" }],
65
+ ["CC-BY-ND-4.0", { text: ND, pdf: "yes" }],
66
+ ["CC-BY-NC-ND-4.0", { text: ND, pdf: "non-commercial" }],
67
+ ["LicenseRef-arxiv-nonexclusive-1.0", { text: ARXIV, pdf: ARXIV }],
68
+ ["LicenseRef-publisher", { text: PUBLISHER, pdf: PUBLISHER }],
69
+ ]);
70
+
71
+ /**
72
+ * True for an SPDX license id's shape (letters, digits, `-` and `.`, and the deprecated `+` suffix)
73
+ * or a `LicenseRef-` of SPDX and REUSE; listed or not. An expression (`MIT OR Apache-2.0`), a phrase
74
+ * or a URL is not an id.
75
+ */
76
+ export const isLicenceId = (id: string): boolean =>
77
+ /^(?:LicenseRef-[A-Za-z0-9.-]+|[A-Za-z0-9][A-Za-z0-9.-]*\+?)$/u.test(id);
78
+
79
+ /** Whether a copy under licence `id` may be stored as `kind`, in a project of `settings`. */
80
+ export function permits(
81
+ id: string,
82
+ kind: StoredKind,
83
+ settings: Readonly<LicenceSettings>,
84
+ ): Permission {
85
+ if (id === NOASSERTION) return { kind: "not-read" };
86
+ const row = TABLE.get(id);
87
+ if (row === undefined) return { kind: "unlisted", id };
88
+ const grant = row[kind];
89
+ if (grant === "yes") return { kind: "permitted" };
90
+ if (grant === "non-commercial")
91
+ return settings.nonCommercial
92
+ ? { kind: "permitted" }
93
+ : { kind: "non-commercial-only" };
94
+ return { kind: "forbidden", why: grant.no };
95
+ }