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,337 @@
1
+ /**
2
+ * The schema of a venue corpus's `papers.json` (docs/design/venue-corpus.md, decision 1): a record
3
+ * parses to itself with a paper row's extra fields kept, and every way a file can fail to be one is
4
+ * refused with the zod path of each problem.
5
+ */
6
+ import { readFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import { describe, expect, it } from "vitest";
10
+ import { z } from "zod";
11
+ import {
12
+ problemsText,
13
+ type Paper,
14
+ type VenueCorpus,
15
+ } from "../../domain/venue-corpus.ts";
16
+ import {
17
+ SCHEMA_FILE,
18
+ venueCorpusCodec,
19
+ venueCorpusJsonSchema,
20
+ venueCorpusSchemaText,
21
+ } from "./index.ts";
22
+
23
+ const parse = venueCorpusCodec.parse;
24
+
25
+ const LICENCE = {
26
+ id: "CC-BY-4.0",
27
+ read_from: "https://api.crossref.org/works/10.1145/3786167.3788430",
28
+ read_on: "2026-11-03",
29
+ } as const;
30
+
31
+ const COPY = {
32
+ version: "published",
33
+ url: "https://doi.org/10.1145/3786167.3788430",
34
+ licence: LICENCE,
35
+ fetched_from: "https://dl.acm.org/doi/pdf/10.1145/3786167.3788430",
36
+ stored: ["text", "pdf"],
37
+ } as const;
38
+
39
+ const PAPER = {
40
+ key: "2026-01",
41
+ edition: 2026,
42
+ group: "accepted",
43
+ title: "A Catalogue of Evaluation Metrics",
44
+ authors: ["Ingrid Lima", "Paulo Maia"],
45
+ abstract: "LLM-based Multi-Agent frameworks …",
46
+ ids: { doi: "10.1145/3786167.3788430" },
47
+ copies: [COPY],
48
+ } as const;
49
+
50
+ const EDITION = {
51
+ edition: 2026,
52
+ listed_from: "https://conf.researchr.org/home/icse-2026/agent-2026",
53
+ read_on: "2026-11-03",
54
+ accepted: 27,
55
+ capped: null,
56
+ proxy: { what: "distinguished-paper award", papers: 4 },
57
+ } as const;
58
+
59
+ const RECORD = {
60
+ venue: "agent",
61
+ editions: [EDITION],
62
+ papers: [PAPER],
63
+ rebuild: ["node scripts/list-accepted.mjs agent 2026"],
64
+ };
65
+
66
+ const text = (v: unknown): string => JSON.stringify(v);
67
+ /** The record with its one paper replaced by `paper`. */
68
+ const withPaper = (paper: Readonly<Record<string, unknown>>): string =>
69
+ text({ ...RECORD, papers: [paper] });
70
+ /** The record with its one paper's one copy replaced by `copy`. */
71
+ const withCopy = (copy: Readonly<Record<string, unknown>>): string =>
72
+ withPaper({ ...PAPER, copies: [copy] });
73
+
74
+ describe("parsing a papers.json", () => {
75
+ it("🔴 the design note's record parses to itself", () => {
76
+ // Guards: a valid record comes back whole, nothing dropped or added.
77
+ expect(parse(text(RECORD))).toEqual({ ok: true, corpus: RECORD });
78
+ });
79
+
80
+ it("🔴 a paper row's extra fields are kept, whatever they hold", () => {
81
+ const row = { ...PAPER, award: "distinguished", pages: 8, found_at: null };
82
+ // Guards: a row is loose — the consumer's own fields survive the parse.
83
+ expect(parse(withPaper(row))).toEqual({
84
+ ok: true,
85
+ corpus: { ...RECORD, papers: [row] },
86
+ });
87
+ });
88
+
89
+ it("🔴 an abstract a listing left null parses as null", () => {
90
+ const row = { ...PAPER, abstract: null };
91
+ // Guards: scraped listings leave the abstract null (8 of 16 rows of one real corpus); null is not refused.
92
+ expect(parse(withPaper(row))).toEqual({
93
+ ok: true,
94
+ corpus: { ...RECORD, papers: [row] },
95
+ });
96
+ });
97
+
98
+ it("a sister paper names its venue, year and where it was found; an unknown copy stores under NOASSERTION", () => {
99
+ const { edition, ...rest } = PAPER;
100
+ const sister: Paper = {
101
+ ...rest,
102
+ group: "sister",
103
+ venue: "nlbse",
104
+ year: 2025,
105
+ listed_from: "https://nlbse.github.io/2025/",
106
+ ids: { url: "https://nlbse.github.io/2025/papers/7" },
107
+ copies: [
108
+ {
109
+ version: "unknown",
110
+ licence: { id: "NOASSERTION" },
111
+ fetched_from: "https://example.org/7.pdf",
112
+ stored: ["pdf"],
113
+ },
114
+ ],
115
+ };
116
+ const record: VenueCorpus = { ...RECORD, papers: [sister] };
117
+ // Guards: the sister shape and the unknown-origin copy are both representable.
118
+ expect([edition, parse(text(record))]).toEqual([
119
+ 2026,
120
+ { ok: true, corpus: record },
121
+ ]);
122
+ });
123
+
124
+ it("an unlisted licence id parses: the table, not the parser, judges it", () => {
125
+ const copy = { ...COPY, licence: { ...LICENCE, id: "CC-BY-3.0" } };
126
+ // Guards: one unlisted id does not make the whole record unreadable.
127
+ expect(parse(withCopy(copy))).toEqual({
128
+ ok: true,
129
+ corpus: { ...RECORD, papers: [{ ...PAPER, copies: [copy] }] },
130
+ });
131
+ });
132
+ });
133
+
134
+ describe("a copy whose licence was never read", () => {
135
+ it("🔴 a known copy under NOASSERTION, storing nothing, parses: the record is not the licence check", () => {
136
+ const copy = {
137
+ version: "preprint",
138
+ url: "https://arxiv.org/abs/2601.00001",
139
+ licence: { id: "NOASSERTION" },
140
+ stored: [],
141
+ };
142
+ // Guards: a corpus migrated before its licences were read still validates.
143
+ expect(parse(withCopy(copy))).toEqual({
144
+ ok: true,
145
+ corpus: { ...RECORD, papers: [{ ...PAPER, copies: [copy] }] },
146
+ });
147
+ });
148
+
149
+ it("🔴 the collection facts parse: what was capped, no proxy, no rebuild command", () => {
150
+ const facts = {
151
+ ...RECORD,
152
+ editions: [
153
+ { ...EDITION, capped: "the research track only, 100 of 312" },
154
+ { ...EDITION, edition: 2025, proxy: null },
155
+ ],
156
+ rebuild: [],
157
+ };
158
+ // Guards: each fact is a field, and "none" is null or an empty list.
159
+ expect(parse(text(facts))).toEqual({ ok: true, corpus: facts });
160
+ });
161
+ });
162
+
163
+ /** A file that is no record, and the reasons it is refused with. */
164
+ const REFUSED: readonly (readonly [string, string, string])[] = [
165
+ [
166
+ "🔴 a misspelt key in a copy, at the key",
167
+ withCopy({ ...COPY, licence: undefined, lisence: LICENCE }),
168
+ 'papers.0.copies.0.licence: Invalid input: expected object, received undefined; papers.0.copies.0.lisence: Unrecognized key: "lisence"',
169
+ ],
170
+ [
171
+ "🔴 a copy without its licence object",
172
+ withCopy({ ...COPY, licence: undefined }),
173
+ "papers.0.copies.0.licence: Invalid input: expected object, received undefined",
174
+ ],
175
+ [
176
+ "🔴 a key two papers share",
177
+ text({ ...RECORD, papers: [PAPER, { ...PAPER, title: "Other" }] }),
178
+ 'papers.1.key: "2026-01" is the key of papers.0 too',
179
+ ],
180
+ [
181
+ "a misspelt key at the top level",
182
+ text({ ...RECORD, edtions: [] }),
183
+ 'edtions: Unrecognized key: "edtions"',
184
+ ],
185
+ [
186
+ "a misspelt key in a licence",
187
+ withCopy({ ...COPY, licence: { ...LICENCE, read_form: "x" } }),
188
+ 'papers.0.copies.0.licence.read_form: Unrecognized key: "read_form"',
189
+ ],
190
+ [
191
+ "a licence read from nowhere",
192
+ withCopy({ ...COPY, licence: { id: "CC-BY-4.0" } }),
193
+ "papers.0.copies.0.licence.read_from: a licence other than NOASSERTION names where it was read; papers.0.copies.0.licence.read_on: a licence other than NOASSERTION names when it was read",
194
+ ],
195
+ [
196
+ "NOASSERTION with a source: a licence read is not NOASSERTION",
197
+ withCopy({ ...COPY, licence: { ...LICENCE, id: "NOASSERTION" } }),
198
+ "papers.0.copies.0.licence.read_from: NOASSERTION means the licence was not read; papers.0.copies.0.licence.read_on: NOASSERTION means the licence was not read",
199
+ ],
200
+ [
201
+ "a licence id that is no SPDX id",
202
+ withCopy({ ...COPY, licence: { ...LICENCE, id: "CC BY 4.0" } }),
203
+ "papers.0.copies.0.licence.id: an SPDX license id or a LicenseRef-",
204
+ ],
205
+ [
206
+ "a copy of unknown origin under a licence",
207
+ withCopy({ ...COPY, version: "unknown" }),
208
+ 'papers.0.copies.0.licence.id: Invalid input: expected "NOASSERTION"; papers.0.copies.0.licence.read_from: Unrecognized keys: "read_from", "read_on"; papers.0.copies.0.url: Unrecognized key: "url"',
209
+ ],
210
+ [
211
+ "a stored copy that does not say where its bytes came from",
212
+ withCopy({ ...COPY, fetched_from: undefined }),
213
+ "papers.0.copies.0.fetched_from: a copy that stores a file names where it was fetched from",
214
+ ],
215
+ [
216
+ "a copy fetched from somewhere that is not a web address",
217
+ withCopy({ ...COPY, fetched_from: "file:///home/me/x.pdf" }),
218
+ "papers.0.copies.0.fetched_from: an http or https address",
219
+ ],
220
+ [
221
+ "a kind stored twice by one copy",
222
+ withCopy({ ...COPY, stored: ["pdf", "pdf"] }),
223
+ 'papers.0.copies.0.stored: "pdf" is listed twice',
224
+ ],
225
+ [
226
+ "a paper of an edition the record does not list",
227
+ withPaper({ ...PAPER, edition: 2025 }),
228
+ "papers.0.edition: 2025 is not one of editions[].edition (2026)",
229
+ ],
230
+ [
231
+ "an edition listed twice",
232
+ text({ ...RECORD, editions: [EDITION, EDITION] }),
233
+ "editions.1.edition: 2026 is listed twice",
234
+ ],
235
+ [
236
+ "a paper with no id",
237
+ withPaper({ ...PAPER, ids: {} }),
238
+ "papers.0.ids: at least one of doi, arxiv, dblp, s2, url",
239
+ ],
240
+ [
241
+ "a misspelt id",
242
+ withPaper({ ...PAPER, ids: { dio: "10.1/x" } }),
243
+ 'papers.0.ids.dio: Unrecognized key: "dio"; papers.0.ids: at least one of doi, arxiv, dblp, s2, url',
244
+ ],
245
+ [
246
+ "a key that cannot name a file",
247
+ withPaper({ ...PAPER, key: "../x" }),
248
+ "papers.0.key: a letter or digit, then letters, digits, '_' or '-'",
249
+ ],
250
+ [
251
+ // Guards: text/<key>.<variant>.txt splits at the first dot, so a dotted key would read as a variant.
252
+ "a key with a dot",
253
+ withPaper({ ...PAPER, key: "2501.15919" }),
254
+ "papers.0.key: a letter or digit, then letters, digits, '_' or '-'",
255
+ ],
256
+ [
257
+ "🔴 an edition that leaves out what was capped, and a proxy marking -1 papers",
258
+ text({
259
+ ...RECORD,
260
+ editions: [
261
+ { ...EDITION, capped: undefined, proxy: { what: "award", papers: -1 } },
262
+ ],
263
+ }),
264
+ "editions.0.capped: Invalid input: expected string, received undefined; editions.0.proxy.papers: Too small: expected number to be >=0",
265
+ ],
266
+ [
267
+ "🔴 a record without its rebuild commands",
268
+ text({ ...RECORD, rebuild: undefined }),
269
+ "rebuild: Invalid input: expected array, received undefined",
270
+ ],
271
+ ];
272
+
273
+ describe("refusing what is not a papers.json", () => {
274
+ it("text that is not JSON", () => {
275
+ // Guards: a broken file is named as such, not parsed as an empty record.
276
+ expect(parse("{ venue: agent")).toEqual({
277
+ ok: false,
278
+ problems: [{ path: [], message: "not JSON" }],
279
+ });
280
+ });
281
+
282
+ it("🔴 each problem carries its path, a misspelt key's ending at the key", () => {
283
+ // Guards: `corpus/record` walks the path to the field it reports on.
284
+ expect(
285
+ parse(withPaper({ ...PAPER, ids: { doi: "10.1/x", dio: "10.1/x" } })),
286
+ ).toEqual({
287
+ ok: false,
288
+ problems: [
289
+ {
290
+ path: ["papers", 0, "ids", "dio"],
291
+ message: 'Unrecognized key: "dio"',
292
+ },
293
+ ],
294
+ });
295
+ });
296
+
297
+ it.each(REFUSED)("%s", (_name, file, why) => {
298
+ // Guards: the record is refused, and the reason names the path of every problem.
299
+ const parsed = parse(file);
300
+ expect(parsed.ok ? "parsed" : problemsText(parsed.problems)).toBe(
301
+ `papers.json: ${why}`,
302
+ );
303
+ });
304
+ });
305
+
306
+ describe("venueCorpusJsonSchema — the shipped schema file", () => {
307
+ const SHIPPED = join(
308
+ dirname(fileURLToPath(import.meta.url)),
309
+ "../../../",
310
+ SCHEMA_FILE,
311
+ );
312
+
313
+ it("🔴 is the generated schema, byte for byte", () => {
314
+ // Guards: the schema the skill points at never drifts from the parser that judges the record.
315
+ expect(
316
+ readFileSync(SHIPPED, "utf8"),
317
+ `${SCHEMA_FILE} is stale: regenerate it with \`npm run schema:venue-corpus\``,
318
+ ).toBe(venueCorpusSchemaText());
319
+ });
320
+
321
+ it("🔴 says the parser checks what a schema cannot, and names the record's fields", () => {
322
+ const schema = z
323
+ .looseObject({
324
+ description: z.string(),
325
+ properties: z.looseObject({}),
326
+ })
327
+ .parse(venueCorpusJsonSchema());
328
+ expect(schema.description).toContain("papers.json");
329
+ expect(schema.description).toContain("corpus-licences.js");
330
+ expect(Object.keys(schema.properties)).toEqual([
331
+ "venue",
332
+ "editions",
333
+ "papers",
334
+ "rebuild",
335
+ ]);
336
+ });
337
+ });
@@ -0,0 +1,306 @@
1
+ /**
2
+ * The schema of a venue corpus's `papers.json` — the one place its shape is checked
3
+ * (docs/design/venue-corpus.md, decision 1). The text is parsed once, here, into the domain's
4
+ * `VenueCorpus`; whatever reads a record after it never re-validates. The study registry's pattern
5
+ * (`src/adapters/study-registry/`).
6
+ *
7
+ * The top level, an edition, a copy, a licence and a paper's ids are strict, so a misspelt key is an
8
+ * error. A paper row is loose: a consumer's scripts read their own fields from it. A licence id is
9
+ * checked for its shape only: whether the id permits anything is `src/domain/licence.ts`'s table, so
10
+ * one unlisted id does not make the record unreadable.
11
+ */
12
+ import { z } from "zod";
13
+ import {
14
+ isLicenceId,
15
+ NOASSERTION,
16
+ STORED_KINDS,
17
+ } from "../../domain/licence.ts";
18
+ import {
19
+ KEY_PATTERN,
20
+ KNOWN_VERSIONS,
21
+ PAPER_ID_KINDS,
22
+ type Copy,
23
+ type Edition,
24
+ type Licence,
25
+ type ParsedCorpus,
26
+ type Paper,
27
+ type PaperIds,
28
+ type CorpusProblem,
29
+ type StrongAcceptProxy,
30
+ type VenueCorpus,
31
+ } from "../../domain/venue-corpus.ts";
32
+ import type { VenueCorpusCodec } from "../../ports/venue-corpus-codec.ts";
33
+
34
+ const words = z.string().min(1);
35
+ const date = z.iso.date();
36
+ /** Where a page or a file was read: a web address, never a local path or another scheme. */
37
+ const webUrl = z.url({
38
+ protocol: /^https?$/u,
39
+ error: "an http or https address",
40
+ });
41
+
42
+ /** The index of each value that occurs earlier in `values`, with the index of its first. */
43
+ const repeats = (
44
+ values: readonly unknown[],
45
+ ): readonly (readonly [number, number])[] =>
46
+ values.flatMap((v, i) => {
47
+ const first = values.indexOf(v);
48
+ return first === i ? [] : [[i, first] as const];
49
+ });
50
+
51
+ const licenceId = z
52
+ .string()
53
+ .refine(isLicenceId, "an SPDX license id or a LicenseRef-");
54
+
55
+ const notRead = z.strictObject({ id: z.literal(NOASSERTION) });
56
+
57
+ /** A licence: NOASSERTION alone, or any other id with where and when it was read. */
58
+ const licence = z
59
+ .strictObject({
60
+ id: licenceId,
61
+ read_from: webUrl.optional(),
62
+ read_on: date.optional(),
63
+ })
64
+ .transform((l, ctx): Licence => {
65
+ const fields = ["read_from", "read_on"] as const;
66
+ const noneRead = l.id === NOASSERTION;
67
+ const wrong = fields.filter((f) => (l[f] === undefined) !== noneRead);
68
+ wrong.forEach((f) => {
69
+ ctx.addIssue({
70
+ code: "custom",
71
+ path: [f],
72
+ message: noneRead
73
+ ? "NOASSERTION means the licence was not read"
74
+ : `a licence other than NOASSERTION names ${f === "read_from" ? "where" : "when"} it was read`,
75
+ });
76
+ });
77
+ return l.read_from === undefined || l.read_on === undefined
78
+ ? { id: NOASSERTION }
79
+ : { id: l.id, read_from: l.read_from, read_on: l.read_on };
80
+ });
81
+
82
+ const storage = {
83
+ stored: z.array(z.enum(STORED_KINDS)),
84
+ fetched_from: webUrl.optional(),
85
+ };
86
+
87
+ /** Each kind at most once, and a stored copy names where its bytes came from. */
88
+ const stores = (
89
+ c: Readonly<{ stored: readonly string[]; fetched_from?: string | undefined }>,
90
+ ctx: Readonly<z.core.$RefinementCtx>,
91
+ ): void => {
92
+ repeats(c.stored).forEach(([i]) => {
93
+ ctx.addIssue({
94
+ code: "custom",
95
+ path: ["stored"],
96
+ message: `"${String(c.stored[i])}" is listed twice`,
97
+ });
98
+ });
99
+ if (c.stored.length > 0 && c.fetched_from === undefined)
100
+ ctx.addIssue({
101
+ code: "custom",
102
+ path: ["fetched_from"],
103
+ message: "a copy that stores a file names where it was fetched from",
104
+ });
105
+ };
106
+
107
+ const copy = z.discriminatedUnion("version", [
108
+ z
109
+ .strictObject({
110
+ version: z.enum(KNOWN_VERSIONS),
111
+ url: webUrl,
112
+ licence,
113
+ ...storage,
114
+ })
115
+ .superRefine(stores),
116
+ z
117
+ .strictObject({
118
+ version: z.literal("unknown"),
119
+ licence: notRead,
120
+ ...storage,
121
+ })
122
+ .superRefine(stores),
123
+ ]);
124
+
125
+ const ids = z
126
+ .strictObject({
127
+ doi: words.optional(),
128
+ arxiv: words.optional(),
129
+ dblp: words.optional(),
130
+ s2: words.optional(),
131
+ url: webUrl.optional(),
132
+ })
133
+ .refine(
134
+ (i) => Object.values(i).some((v) => v !== undefined),
135
+ `at least one of ${PAPER_ID_KINDS.join(", ")}`,
136
+ );
137
+
138
+ const paperFields = {
139
+ key: z
140
+ .string()
141
+ .regex(KEY_PATTERN, "a letter or digit, then letters, digits, '_' or '-'"),
142
+ title: words,
143
+ authors: z.array(words).optional(),
144
+ abstract: z.string().nullable().optional(),
145
+ ids,
146
+ copies: z.array(copy),
147
+ };
148
+
149
+ const year = z.number().int().positive();
150
+
151
+ const paper = z.discriminatedUnion("group", [
152
+ z.looseObject({
153
+ ...paperFields,
154
+ group: z.enum(["accepted", "award"]),
155
+ edition: year,
156
+ }),
157
+ z.looseObject({
158
+ ...paperFields,
159
+ group: z.literal("sister"),
160
+ venue: words,
161
+ year,
162
+ listed_from: webUrl,
163
+ }),
164
+ ]);
165
+
166
+ const count = z.number().int().nonnegative();
167
+
168
+ const proxy = z.strictObject({ what: words, papers: count });
169
+
170
+ // `capped` and `proxy` are required, and "none" is null: a fact left out is not a fact recorded.
171
+ const edition = z.strictObject({
172
+ edition: year,
173
+ listed_from: webUrl,
174
+ read_on: date,
175
+ accepted: count.optional(),
176
+ capped: words.nullable(),
177
+ proxy: proxy.nullable(),
178
+ });
179
+
180
+ /** Keys unique, editions unique, and every paper of this venue of a listed edition. */
181
+ const consistent = (
182
+ r: Readonly<{ editions: readonly Edition[]; papers: readonly Paper[] }>,
183
+ ctx: Readonly<z.core.$RefinementCtx>,
184
+ ): void => {
185
+ const years = r.editions.map((e) => e.edition);
186
+ repeats(years).forEach(([i]) => {
187
+ ctx.addIssue({
188
+ code: "custom",
189
+ path: ["editions", i, "edition"],
190
+ message: `${String(years[i])} is listed twice`,
191
+ });
192
+ });
193
+ const keys = r.papers.map((p) => p.key);
194
+ repeats(keys).forEach(([i, first]) => {
195
+ ctx.addIssue({
196
+ code: "custom",
197
+ path: ["papers", i, "key"],
198
+ message: `"${String(keys[i])}" is the key of papers.${String(first)} too`,
199
+ });
200
+ });
201
+ r.papers.forEach((p, i) => {
202
+ if (p.group !== "sister" && !years.includes(p.edition))
203
+ ctx.addIssue({
204
+ code: "custom",
205
+ path: ["papers", i, "edition"],
206
+ message: `${String(p.edition)} is not one of editions[].edition (${years.join(", ")})`,
207
+ });
208
+ });
209
+ };
210
+
211
+ const record = z
212
+ .strictObject({
213
+ venue: words,
214
+ editions: z.array(edition),
215
+ papers: z.array(paper),
216
+ rebuild: z.array(words),
217
+ })
218
+ .superRefine(consistent);
219
+
220
+ // ── the schemas ARE the domain's types (as in the study registry's adapter) ──────────────────
221
+
222
+ /** `T`, readonly all the way down: zod's outputs are mutable, the domain's are not. */
223
+ type Frozen<T> = T extends readonly (infer U)[]
224
+ ? readonly Frozen<U>[]
225
+ : T extends object
226
+ ? { readonly [K in keyof T]: Frozen<T[K]> }
227
+ : T;
228
+
229
+ /** True when `A` and `B`, both made readonly all the way down, are one type. */
230
+ type Same<A, B> =
231
+ (<T>() => T extends Frozen<A> ? readonly [T] : 2) extends <
232
+ T,
233
+ >() => T extends Frozen<B> ? readonly [T] : 2
234
+ ? true
235
+ : false;
236
+
237
+ /** Compiles only when every schema's output is its domain type. */
238
+ export type SchemasAreTheDomain = [
239
+ Same<z.output<typeof record>, VenueCorpus>,
240
+ Same<z.output<typeof edition>, Edition>,
241
+ Same<z.output<typeof proxy>, StrongAcceptProxy>,
242
+ Same<z.output<typeof paper>, Paper>,
243
+ Same<z.output<typeof copy>, Copy>,
244
+ Same<z.output<typeof licence>, Licence>,
245
+ Same<z.output<typeof ids>, PaperIds>,
246
+ ] extends true[]
247
+ ? true
248
+ : never;
249
+
250
+ /** The proof is used, so the build checks it. */
251
+ export const SCHEMAS_ARE_THE_DOMAIN: SchemasAreTheDomain = true;
252
+
253
+ /** The JSON `text` holds, or undefined when it is not JSON. */
254
+ function jsonOf(text: string): unknown {
255
+ try {
256
+ return JSON.parse(text);
257
+ } catch {
258
+ return undefined;
259
+ }
260
+ }
261
+
262
+ /**
263
+ * One zod issue as a problem. A misspelt key's path ends at the key (the first, when there are
264
+ * several), so a reader of the file lands on it rather than on the object holding it.
265
+ */
266
+ const problemOf = (i: z.core.$ZodIssue): CorpusProblem => ({
267
+ path: [
268
+ ...i.path.filter((s) => typeof s !== "symbol"),
269
+ ...(i.code === "unrecognized_keys" ? i.keys.slice(0, 1) : []),
270
+ ],
271
+ message: i.message,
272
+ });
273
+
274
+ /** A `papers.json`'s text, parsed once at the boundary: the record, or every reason it is not one. */
275
+ export function parseVenueCorpus(text: string): ParsedCorpus {
276
+ const json = jsonOf(text);
277
+ if (json === undefined)
278
+ return { ok: false, problems: [{ path: [], message: "not JSON" }] };
279
+ const parsed = record.safeParse(json);
280
+ return parsed.success
281
+ ? { ok: true, corpus: parsed.data }
282
+ : { ok: false, problems: parsed.error.issues.map(problemOf) };
283
+ }
284
+
285
+ export const venueCorpusCodec: VenueCorpusCodec = { parse: parseVenueCorpus };
286
+
287
+ /** Where the shipped JSON Schema of the record sits, below the package root: in the skill that writes it. */
288
+ export const SCHEMA_FILE = "skills/study-accepted-papers/papers.schema.json";
289
+
290
+ /**
291
+ * The JSON Schema of a `papers.json`, generated from the parser's own shape: the fields a skill (or
292
+ * an editor) reads instead of a hand-written table. Shipped as `SCHEMA_FILE`; a test holds the file
293
+ * to this. A schema cannot say that a key is unique, that a paper's edition is a listed one, or that
294
+ * a stored copy names where it was fetched from: `corpus-licences.js` checks those and names the
295
+ * field's path.
296
+ */
297
+ export const venueCorpusJsonSchema = (): unknown => ({
298
+ ...z.toJSONSchema(record, { io: "input", unrepresentable: "any" }),
299
+ title: "A venue corpus's papers.json",
300
+ description:
301
+ "The record of a venue corpus, papers.json: one row per paper, every copy with its licence. This schema lists the fields; it cannot express that a key is unique, that a paper's edition is one of editions[].edition, or that a copy that stores a file names where it was fetched from. `node ${CLAUDE_SKILL_DIR}/scripts/corpus-licences.js <venue>` checks those and refuses a wrong record with the path of the field.",
302
+ });
303
+
304
+ /** The shipped file's text: the schema, indented, with a closing newline. */
305
+ export const venueCorpusSchemaText = (): string =>
306
+ `${JSON.stringify(venueCorpusJsonSchema(), null, 2)}\n`;
@@ -180,11 +180,11 @@ it("config is assembled, and consumer data gets through", async () => {
180
180
  const ruleBlocks = (c) => c.filter((b) => Array.isArray(b.files));
181
181
  check(
182
182
  "without a LaTeX language the config still gets built — a corpus with no .tex is not a reason to refuse",
183
- Array.isArray(cfg) && ruleBlocks(cfg).length === 3,
183
+ Array.isArray(cfg) && ruleBlocks(cfg).length === 4,
184
184
  );
185
185
  check(
186
186
  "with a LaTeX language two blocks are added: paper.tex, and the files it includes",
187
- ruleBlocks(buildConfig({}, {})).length === 5,
187
+ ruleBlocks(buildConfig({}, {})).length === 6,
188
188
  );
189
189
  check(
190
190
  "🔴 the project's paper TEMPLATE directory is ignored — flat config does not skip dot-directories",
package/src/cli.test.ts CHANGED
@@ -682,7 +682,7 @@ test("a paper's paperlint.json that does not parse stops the lint with its path"
682
682
  "p/paper.tex": "% P\n",
683
683
  "p/paperlint.json": "{ nope",
684
684
  });
685
- const r = paperRuleBlocks([join(dir, "p")]);
685
+ const r = paperRuleBlocks([join(dir, "p")], []);
686
686
  assert.equal(r.ok, false);
687
687
  assert.match(r.error, /^.*rules-broken\/p\/paperlint\.json: /);
688
688
  });