paperlint 20.1.1 → 20.2.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 (126) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.github/workflows/ci.yml +7 -0
  3. package/CLAUDE.md +6 -2
  4. package/CONTRIBUTING.md +2 -2
  5. package/{action.harness.mjs → action.test.mjs} +147 -138
  6. package/dist/adapters/venue-corpus/index.d.ts +345 -0
  7. package/dist/adapters/venue-corpus/index.d.ts.map +1 -0
  8. package/dist/adapters/venue-corpus/index.js +205 -0
  9. package/dist/adapters/venue-corpus/index.js.map +1 -0
  10. package/dist/domain/licence.d.ts +51 -0
  11. package/dist/domain/licence.d.ts.map +1 -0
  12. package/dist/domain/licence.js +61 -0
  13. package/dist/domain/licence.js.map +1 -0
  14. package/dist/domain/venue-corpus.d.ts +120 -0
  15. package/dist/domain/venue-corpus.d.ts.map +1 -0
  16. package/dist/domain/venue-corpus.js +13 -0
  17. package/dist/domain/venue-corpus.js.map +1 -0
  18. package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  19. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  20. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  21. package/dist/eslint-rules/papers.js +1 -1
  22. package/dist/latex-log.d.ts +1 -1
  23. package/dist/latex-log.js +1 -1
  24. package/dist/latex-loop.d.ts +1 -1
  25. package/dist/latex-loop.js +1 -1
  26. package/dist/lib/paper-config.d.ts +3 -3
  27. package/dist/lib/paper-config.js +3 -3
  28. package/dist/ports/venue-corpus-codec.d.ts +11 -0
  29. package/dist/ports/venue-corpus-codec.d.ts.map +1 -0
  30. package/dist/ports/venue-corpus-codec.js +2 -0
  31. package/dist/ports/venue-corpus-codec.js.map +1 -0
  32. package/dist/skill-chunks/chunk-5KCU4WTN.js +108 -0
  33. package/dist/skill-chunks/{chunk-X4VKG4KT.js → chunk-6YEM4VDI.js} +11 -9
  34. package/dist/skill-chunks/{chunk-L3NJUJUP.js → chunk-CXAGKT44.js} +5 -3
  35. package/dist/skill-chunks/{chunk-6NU6CXUS.js → chunk-J5XYPERO.js} +12 -72
  36. package/dist/skill-chunks/{chunk-IREAROCV.js → chunk-Z5YMDZYW.js} +4 -0
  37. package/dist/skills/study-accepted-papers/scripts/corpus-licences-core.d.ts +54 -0
  38. package/dist/skills/study-accepted-papers/scripts/corpus-licences.d.ts +2 -0
  39. package/docs/design/venue-corpus.md +250 -0
  40. package/docs/e2e.md +9 -9
  41. package/docs/testing.md +3 -4
  42. package/docs/venues.md +144 -21
  43. package/eslint-rules/CLAUDE.md +5 -1
  44. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  45. package/eslint-rules/{install-path-literals.harness.mjs → install-path-literals.test.mjs} +14 -13
  46. package/eslint-rules/{latex-language.harness.mjs → latex-language-rules.test.mjs} +61 -51
  47. package/eslint-rules/{paper-stages.harness.mjs → paper-stages-rule.test.mjs} +66 -69
  48. package/eslint-rules/{papers.harness.mjs → papers.test.mjs} +41 -30
  49. package/eslint-rules/papers.ts +1 -1
  50. package/eslint-rules/{pdf-last-page-balance.harness.mjs → pdf-last-page-balance.test.mjs} +27 -15
  51. package/eslint-rules/{temp-root-realpath.harness.mjs → temp-root-realpath.test.mjs} +24 -24
  52. package/eslint-rules/{tex-build.harness.mjs → tex-build.test.mjs} +292 -271
  53. package/eslint.config.mjs +15 -2
  54. package/fixtures/pdf-facts/README.md +1 -1
  55. package/fixtures/render-paper/build-clean.sh +1 -1
  56. package/fixtures/toolchain-mirror/install-tl +1 -1
  57. package/lib/{agent-cli-version.harness.mjs → agent-cli-version.test.mjs} +17 -18
  58. package/lib/{paper-config.harness.mjs → paper-config.test.mjs} +21 -20
  59. package/lib/paper-config.ts +3 -3
  60. package/lib/{skill-trigger-cases.harness.mjs → skill-trigger-cases-carrier.test.mjs} +78 -115
  61. package/package.json +4 -3
  62. package/presets/acm-acmsmall.jsonc +1 -1
  63. package/scripts/bundle-skills.ts +1 -0
  64. package/scripts/check-workflow.test.ts +368 -0
  65. package/scripts/check.ts +2 -2
  66. package/scripts/eslint-file-length.mjs +9 -9
  67. package/scripts/eslint-report-guard.mjs +1 -1
  68. package/scripts/eslint-report-guard.test.mjs +1 -1
  69. package/scripts/harness-api.test.ts +7 -46
  70. package/scripts/{rules-see-files.harness.mjs → rules-see-files-rule.test.mjs} +10 -6
  71. package/scripts/rules-see-files.mjs +1 -1
  72. package/scripts/venue-corpus-schema.test.ts +39 -0
  73. package/scripts/venue-corpus-schema.ts +17 -0
  74. package/skills/argument-arc/scripts/headings.js +6 -4
  75. package/skills/cold-read-diff/scripts/cold-read.js +6 -4
  76. package/skills/paper-pipeline/{paper-pipeline.harness.mjs → paper-pipeline.test.mjs} +45 -46
  77. package/skills/paper-pipeline/scripts/{consumer.harness.mjs → consumer-paths.test.mjs} +66 -59
  78. package/skills/paper-pipeline/scripts/consumer.mjs +3 -3
  79. package/skills/paper-pipeline/scripts/{extract-ref-facts.harness.mjs → extract-ref-facts-cli.test.mjs} +29 -31
  80. package/skills/paper-pipeline/scripts/extract-ref-facts.js +6 -5
  81. package/skills/paper-pipeline/scripts/fixtures/real-bib/refs.bib +1 -1
  82. package/skills/paper-pipeline/scripts/{generated-code.harness.mjs → generated-code-fixtures.test.mjs} +39 -46
  83. package/skills/pc-panel-review/scripts/prior-reviews.js +7 -5
  84. package/skills/render-paper/{extract-pdf-facts.harness.ts → extract-pdf-facts.test.ts} +20 -13
  85. package/skills/render-paper/{render-paper.harness.mjs → render-paper.test.mjs} +41 -40
  86. package/skills/study-accepted-papers/SKILL.md +28 -2
  87. package/skills/study-accepted-papers/SKILL.md.spec.ts +27 -1
  88. package/skills/study-accepted-papers/papers.schema.json +427 -0
  89. package/skills/study-accepted-papers/scripts/corpus-licences-core.js +180 -0
  90. package/skills/study-accepted-papers/scripts/corpus-licences-core.ts +302 -0
  91. package/skills/study-accepted-papers/scripts/corpus-licences.js +383 -0
  92. package/skills/study-accepted-papers/scripts/corpus-licences.test.ts +485 -0
  93. package/skills/study-accepted-papers/scripts/corpus-licences.ts +27 -0
  94. package/skills/verify-citations/scripts/bib-authors.js +6 -5
  95. package/skills/verify-citations/scripts/verify-cites.js +6 -5
  96. package/src/adapters/pdfjs/fill.test.ts +1 -1
  97. package/src/adapters/venue-corpus/index.test.ts +279 -0
  98. package/src/adapters/venue-corpus/index.ts +286 -0
  99. package/src/{build-engine.harness.mjs → build-engine-prepare.test.mjs} +98 -81
  100. package/src/{build.harness.mjs → build-fake-tex.test.mjs} +61 -28
  101. package/src/{cli.harness.mjs → cli-e2e.test.mjs} +108 -102
  102. package/src/cli.test.ts +1 -1
  103. package/src/{doctor.harness.mjs → doctor-install.test.mjs} +28 -29
  104. package/src/domain/licence.test.ts +122 -0
  105. package/src/domain/licence.ts +95 -0
  106. package/src/domain/venue-corpus.ts +130 -0
  107. package/src/{engine.harness.mjs → engine.test.mjs} +120 -106
  108. package/src/facts-file.test.ts +1 -1
  109. package/src/{hooks-settings.harness.ts → hooks-settings.test.ts} +161 -146
  110. package/src/latex-log.test.ts +395 -0
  111. package/src/latex-log.ts +1 -1
  112. package/src/latex-loop.test.ts +553 -0
  113. package/src/latex-loop.ts +1 -1
  114. package/src/{link-skills.harness.ts → link-skills-fs.test.ts} +26 -26
  115. package/src/{new-paper.harness.mjs → new-paper-scaffold.test.mjs} +31 -19
  116. package/src/{pdf-facts.harness.ts → pdf-facts-tables.test.ts} +28 -22
  117. package/src/{pdf-geometry.harness.ts → pdf-geometry.test.ts} +93 -75
  118. package/src/ports/venue-corpus-codec.ts +11 -0
  119. package/src/{rules-config.harness.ts → rules-config.test.ts} +41 -31
  120. package/src/{structure.harness.ts → structure.test.ts} +12 -10
  121. package/src/{tex-requirements.harness.ts → tex-requirements-tables.test.ts} +106 -85
  122. package/src/{toolchain.harness.mjs → toolchain-mirror.test.mjs} +204 -186
  123. package/scripts/check.harness.ts +0 -343
  124. package/scripts/harness-api.frozen.json +0 -41
  125. package/src/latex-log.harness.ts +0 -382
  126. package/src/latex-loop.harness.ts +0 -515
@@ -0,0 +1,302 @@
1
+ /**
2
+ * corpus-licences-core — for each paper of a venue corpus's `papers.json` and each kind a corpus
3
+ * stores (its extracted text, its PDF), the copy whose licence permits keeping it, or each copy's
4
+ * reason it may not be kept. study-accepted-papers reads it before it downloads a PDF or extracts a
5
+ * text (docs/venues.md, "Licences"; docs/design/venue-corpus.md, decisions 2 and 3).
6
+ *
7
+ * The record is parsed by `VenueCorpusCodec`; what a licence permits is `src/domain/licence.ts`'s
8
+ * table, never restated here. The project's non-commercial setting arrives with `corpus/licence`;
9
+ * until then the runner judges as for a project that has not declared itself non-commercial.
10
+ * No model, no network.
11
+ *
12
+ * Usage: node corpus-licences.js <venue>
13
+ * The record is `<papers-root>/venues/<venue>/papers.json`: the project root is the git top level of
14
+ * the folder the command runs in, the papers roots are the project's `papersDir` (src/papers-roots.ts).
15
+ * Exit: 0 — one line per paper and kind · 1 — not in a git repository, no papers.json in any papers
16
+ * root or one in several, or it does not parse · 2 — no venue named, or not a folder name.
17
+ */
18
+ import { dirname, join } from "node:path";
19
+ import { CONFIG_FILE, PAPERS_DIR_FIELD } from "#lib/paper-config";
20
+ import { callerPath } from "#src/caller-path";
21
+ import {
22
+ permits,
23
+ STORED_KINDS,
24
+ type LicenceSettings,
25
+ type Permission,
26
+ type StoredKind,
27
+ } from "#src/domain/licence";
28
+ import {
29
+ CORPUS_RECORD,
30
+ type Copy,
31
+ type KnownVersion,
32
+ type Paper,
33
+ type VenueCorpus,
34
+ } from "#src/domain/venue-corpus";
35
+ import { papersRoots } from "#src/papers-roots";
36
+ import type { Files } from "#src/ports/files";
37
+ import type { RunProcess } from "#src/ports/process";
38
+ import type { VenueCorpusCodec } from "#src/ports/venue-corpus-codec";
39
+
40
+ /** Why one copy may not be kept as one kind. */
41
+ export type Refused = Exclude<Permission, { readonly kind: "permitted" }>;
42
+
43
+ /** One copy's refusal: its version, its licence id, and why. */
44
+ export interface Refusal {
45
+ readonly version: Copy["version"];
46
+ readonly licence: string;
47
+ readonly permission: Refused;
48
+ }
49
+
50
+ /** For one paper and one kind: the copy to keep, or every copy's refusal (none when it has no copy). */
51
+ export type Verdict =
52
+ | {
53
+ readonly key: string;
54
+ readonly stored: StoredKind;
55
+ readonly outcome: "keep";
56
+ readonly version: KnownVersion;
57
+ readonly licence: string;
58
+ readonly url: string;
59
+ }
60
+ | {
61
+ readonly key: string;
62
+ readonly stored: StoredKind;
63
+ readonly outcome: "none";
64
+ readonly refusals: readonly Refusal[];
65
+ };
66
+
67
+ /** One copy judged for one kind. */
68
+ interface Judged {
69
+ readonly copy: Copy;
70
+ readonly permission: Permission;
71
+ }
72
+
73
+ const isRefused = (j: Judged): j is Judged & { readonly permission: Refused } =>
74
+ j.permission.kind !== "permitted";
75
+
76
+ /** A copy whose version is known: only such a copy can be kept (an `unknown` one is `NOASSERTION`). */
77
+ type KnownCopy = Extract<Copy, { readonly version: KnownVersion }>;
78
+
79
+ /** The first copy, in the record's order, whose licence permits the kind. */
80
+ const keptOf = (judged: readonly Judged[]): KnownCopy | undefined =>
81
+ judged
82
+ .map((j) => j.copy)
83
+ .find(
84
+ (c, i): c is KnownCopy =>
85
+ judged[i]?.permission.kind === "permitted" && c.version !== "unknown",
86
+ );
87
+
88
+ /** Every copy that may not be kept as the kind, with why. */
89
+ const refusalsOf = (judged: readonly Judged[]): readonly Refusal[] =>
90
+ judged.filter(isRefused).map((j) => ({
91
+ version: j.copy.version,
92
+ licence: j.copy.licence.id,
93
+ permission: j.permission,
94
+ }));
95
+
96
+ /** The verdict for one paper and one kind: the copy to keep, or every copy's refusal. */
97
+ function verdictOf(
98
+ paper: Paper,
99
+ stored: StoredKind,
100
+ settings: Readonly<LicenceSettings>,
101
+ ): Verdict {
102
+ const judged: readonly Judged[] = paper.copies.map((copy) => ({
103
+ copy,
104
+ permission: permits(copy.licence.id, stored, settings),
105
+ }));
106
+ const kept = keptOf(judged);
107
+ const { key } = paper;
108
+ return kept === undefined
109
+ ? {
110
+ key,
111
+ stored,
112
+ outcome: "none",
113
+ refusals: refusalsOf(judged),
114
+ }
115
+ : {
116
+ key,
117
+ stored,
118
+ outcome: "keep",
119
+ version: kept.version,
120
+ licence: kept.licence.id,
121
+ url: kept.url,
122
+ };
123
+ }
124
+
125
+ /** Every paper's verdict for each kind, in the record's order. */
126
+ export const verdicts = (
127
+ corpus: VenueCorpus,
128
+ settings: Readonly<LicenceSettings>,
129
+ ): readonly Verdict[] =>
130
+ corpus.papers.flatMap((p) =>
131
+ STORED_KINDS.map((kind) => verdictOf(p, kind, settings)),
132
+ );
133
+
134
+ /** Why a copy may not be kept, in words. */
135
+ function reason(r: Refusal): string {
136
+ switch (r.permission.kind) {
137
+ case "forbidden":
138
+ return `${r.licence}: ${r.permission.why}`;
139
+ case "non-commercial-only":
140
+ return `${r.licence} permits it only in a project declared non-commercial`;
141
+ case "not-read":
142
+ return "its licence was not read (NOASSERTION)";
143
+ case "unlisted":
144
+ return `${r.permission.id} is not in the licence table, so it permits nothing`;
145
+ }
146
+ }
147
+
148
+ /** One verdict as the line the command prints. */
149
+ function line(v: Verdict): string {
150
+ const what =
151
+ v.outcome === "keep"
152
+ ? `keep the ${v.version} copy (${v.licence}), ${v.url}`
153
+ : v.refusals.length === 0
154
+ ? "none: no copy recorded"
155
+ : `none: ${v.refusals.map((r) => `${r.version}: ${reason(r)}`).join("; ")}`;
156
+ return `${v.key} ${v.stored}: ${what}`;
157
+ }
158
+
159
+ /** What the command prints for `all`. */
160
+ export const listing = (all: readonly Verdict[]): string =>
161
+ all.length === 0
162
+ ? `${CORPUS_RECORD} holds no paper\n`
163
+ : `${all.map(line).join("\n")}\n`;
164
+
165
+ /** What the command reads with: the disk, the record's codec, and where the project is. */
166
+ export interface Deps {
167
+ readonly files: Files;
168
+ readonly codec: VenueCorpusCodec;
169
+ /** The top of the git working tree holding `cwd`, or null when `cwd` is in none. */
170
+ readonly projectRoot: (cwd: string) => string | null;
171
+ /** The folder the command was started in. */
172
+ readonly cwd: string;
173
+ }
174
+
175
+ /**
176
+ * `git rev-parse --show-toplevel` in `cwd`: the project's root, or null outside a repository (or
177
+ * when git did not run). `path` is the caller's PATH, the only variable git is given.
178
+ */
179
+ export function gitTopLevel(
180
+ git: RunProcess,
181
+ path: string | undefined,
182
+ cwd: string,
183
+ ): string | null {
184
+ const r = git.run({
185
+ file: "git",
186
+ args: ["rev-parse", "--show-toplevel"],
187
+ env: { PATH: path ?? "" },
188
+ timeoutMs: 10_000,
189
+ cwd: callerPath(cwd),
190
+ });
191
+ const top = r.kind === "exited" && r.status === 0 ? r.stdout.trim() : "";
192
+ return top === "" ? null : top;
193
+ }
194
+
195
+ /** Where the command writes: the listing, and what stops it. */
196
+ export interface Output {
197
+ readonly out: (s: string) => void;
198
+ readonly err: (s: string) => void;
199
+ }
200
+
201
+ /** The project's setting the table reads, until `corpus/licence` ships it: not declared. */
202
+ const UNDECLARED: LicenceSettings = { nonCommercial: false };
203
+
204
+ /** A venue is one folder name: no separator, and not a way up. */
205
+ const VENUE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
206
+
207
+ const USAGE = "usage: node corpus-licences.js <venue>\n";
208
+
209
+ /** The project's `papersDir` setting, read through the disk port; absent file, default setting. */
210
+ function settingsOf(
211
+ files: Files,
212
+ root: string,
213
+ ):
214
+ | { readonly ok: true; readonly opts: { readonly papersDir?: unknown } }
215
+ | {
216
+ readonly ok: false;
217
+ readonly why: string;
218
+ } {
219
+ const file = join(root, CONFIG_FILE);
220
+ const bytes = files.readBytes(callerPath(file));
221
+ if (bytes === null) return { ok: true, opts: {} };
222
+ const parsed = jsonOf(new TextDecoder().decode(bytes));
223
+ if (parsed === undefined) return { ok: false, why: `${file} is not JSON` };
224
+ return {
225
+ ok: true,
226
+ opts: isObject(parsed)
227
+ ? { [PAPERS_DIR_FIELD]: parsed[PAPERS_DIR_FIELD] }
228
+ : {},
229
+ };
230
+ }
231
+
232
+ const isObject = (v: unknown): v is Readonly<Record<string, unknown>> =>
233
+ v !== null && typeof v === "object" && !Array.isArray(v);
234
+
235
+ /** The JSON `text` holds, or undefined when it is not JSON. */
236
+ function jsonOf(text: string): unknown {
237
+ try {
238
+ return JSON.parse(text);
239
+ } catch {
240
+ return undefined;
241
+ }
242
+ }
243
+
244
+ /** The one `papers.json` of `venue` among the project's papers roots, or why there is not exactly one. */
245
+ function recordOf(
246
+ deps: Deps,
247
+ venue: string,
248
+ ):
249
+ | { readonly ok: true; readonly file: string }
250
+ | { readonly ok: false; readonly why: string } {
251
+ const root = deps.projectRoot(deps.cwd);
252
+ if (root === null)
253
+ return {
254
+ ok: false,
255
+ why: `${deps.cwd} is not inside a git repository: run it in the project`,
256
+ };
257
+ const settings = settingsOf(deps.files, root);
258
+ if (!settings.ok) return settings;
259
+ const looked = papersRoots({ opts: settings.opts, root }).map((papers) =>
260
+ join(papers, "venues", venue, CORPUS_RECORD),
261
+ );
262
+ const found = looked.filter((f) => deps.files.isFile(callerPath(f)));
263
+ const [only] = found;
264
+ if (only !== undefined && found.length === 1) return { ok: true, file: only };
265
+ return {
266
+ ok: false,
267
+ why:
268
+ found.length === 0
269
+ ? `no ${CORPUS_RECORD} for venue "${venue}": looked in ${looked.map((f) => dirname(f)).join(", ")}; write the record first`
270
+ : `venue "${venue}" is in more than one papers folder: ${found.map((f) => dirname(f)).join(", ")}`,
271
+ };
272
+ }
273
+
274
+ /** Run the command on `argv`; the exit code. */
275
+ export function main(
276
+ argv: readonly string[],
277
+ deps: Deps,
278
+ { out, err }: Output,
279
+ ): number {
280
+ const [venue, ...rest] = argv;
281
+ if (venue === undefined || rest.length > 0 || !VENUE.test(venue)) {
282
+ err(USAGE);
283
+ return 2;
284
+ }
285
+ const at = recordOf(deps, venue);
286
+ if (!at.ok) {
287
+ err(`corpus-licences: ${at.why}\n`);
288
+ return 1;
289
+ }
290
+ const bytes = deps.files.readBytes(callerPath(at.file));
291
+ if (bytes === null) {
292
+ err(`corpus-licences: ${at.file} could not be read\n`);
293
+ return 1;
294
+ }
295
+ const parsed = deps.codec.parse(new TextDecoder().decode(bytes));
296
+ if (!parsed.ok) {
297
+ err(`corpus-licences: ${parsed.why}\n`);
298
+ return 1;
299
+ }
300
+ out(listing(verdicts(parsed.corpus, UNDECLARED)));
301
+ return 0;
302
+ }
@@ -0,0 +1,383 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __plCreateRequire } from "node:module";
3
+ import { fileURLToPath as __plFileURLToPath } from "node:url";
4
+ import { dirname as __plDirname } from "node:path";
5
+ const require = __plCreateRequire(import.meta.url);
6
+ const __filename = __plFileURLToPath(import.meta.url);
7
+ const __dirname = __plDirname(__filename);
8
+ import {
9
+ CONFIG_FILE,
10
+ DEFAULT_PAPERS_ROOT,
11
+ PAPERS_DIR_FIELD
12
+ } from "../../../dist/skill-chunks/chunk-Z5YMDZYW.js";
13
+ import {
14
+ callerPath,
15
+ nodeFiles,
16
+ spawnProcess
17
+ } from "../../../dist/skill-chunks/chunk-5KCU4WTN.js";
18
+ import {
19
+ external_exports
20
+ } from "../../../dist/skill-chunks/chunk-4MHEJ6FR.js";
21
+ import "../../../dist/skill-chunks/chunk-PJ4KNV4J.js";
22
+
23
+ // src/domain/licence.ts
24
+ var STORED_KINDS = ["text", "pdf"];
25
+ var NOASSERTION = "NOASSERTION";
26
+ var ND = {
27
+ no: "ND permits reproduction in unmodified form; whether an extracted text is an adaptation is unsettled"
28
+ };
29
+ var ARXIV = {
30
+ no: 'it grants arXiv alone the right to distribute: "We are thus unable to grant others the right to distribute arXiv articles"'
31
+ };
32
+ var PUBLISHER = {
33
+ no: "the publisher grants no right to third parties"
34
+ };
35
+ var TABLE = /* @__PURE__ */ new Map([
36
+ ["CC0-1.0", { text: "yes", pdf: "yes" }],
37
+ ["CC-BY-4.0", { text: "yes", pdf: "yes" }],
38
+ ["CC-BY-SA-4.0", { text: "yes", pdf: "yes" }],
39
+ ["CC-BY-NC-4.0", { text: "non-commercial", pdf: "non-commercial" }],
40
+ ["CC-BY-NC-SA-4.0", { text: "non-commercial", pdf: "non-commercial" }],
41
+ ["CC-BY-ND-4.0", { text: ND, pdf: "yes" }],
42
+ ["CC-BY-NC-ND-4.0", { text: ND, pdf: "non-commercial" }],
43
+ ["LicenseRef-arxiv-nonexclusive-1.0", { text: ARXIV, pdf: ARXIV }],
44
+ ["LicenseRef-publisher", { text: PUBLISHER, pdf: PUBLISHER }]
45
+ ]);
46
+ var isLicenceId = (id) => /^(?:LicenseRef-[A-Za-z0-9.-]+|[A-Za-z0-9][A-Za-z0-9.-]*\+?)$/u.test(id);
47
+ function permits(id, kind, settings) {
48
+ if (id === NOASSERTION) return { kind: "not-read" };
49
+ const row = TABLE.get(id);
50
+ if (row === void 0) return { kind: "unlisted", id };
51
+ const grant = row[kind];
52
+ if (grant === "yes") return { kind: "permitted" };
53
+ if (grant === "non-commercial")
54
+ return settings.nonCommercial ? { kind: "permitted" } : { kind: "non-commercial-only" };
55
+ return { kind: "forbidden", why: grant.no };
56
+ }
57
+
58
+ // src/domain/venue-corpus.ts
59
+ var CORPUS_RECORD = "papers.json";
60
+ var KNOWN_VERSIONS = ["published", "accepted", "preprint"];
61
+ var PAPER_ID_KINDS = ["doi", "arxiv", "dblp", "s2", "url"];
62
+ var KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/u;
63
+
64
+ // src/adapters/venue-corpus/index.ts
65
+ var words = external_exports.string().min(1);
66
+ var date = external_exports.iso.date();
67
+ var webUrl = external_exports.url({
68
+ protocol: /^https?$/u,
69
+ error: "an http or https address"
70
+ });
71
+ var repeats = (values) => values.flatMap((v, i) => {
72
+ const first = values.indexOf(v);
73
+ return first === i ? [] : [[i, first]];
74
+ });
75
+ var licenceId = external_exports.string().refine(isLicenceId, "an SPDX license id or a LicenseRef-");
76
+ var notRead = external_exports.strictObject({ id: external_exports.literal(NOASSERTION) });
77
+ var licence = external_exports.strictObject({
78
+ id: licenceId,
79
+ read_from: webUrl.optional(),
80
+ read_on: date.optional()
81
+ }).transform((l, ctx) => {
82
+ const fields = ["read_from", "read_on"];
83
+ const noneRead = l.id === NOASSERTION;
84
+ const wrong = fields.filter((f) => l[f] === void 0 !== noneRead);
85
+ wrong.forEach((f) => {
86
+ ctx.addIssue({
87
+ code: "custom",
88
+ path: [f],
89
+ message: noneRead ? "NOASSERTION means the licence was not read" : `a licence other than NOASSERTION names ${f === "read_from" ? "where" : "when"} it was read`
90
+ });
91
+ });
92
+ return l.read_from === void 0 || l.read_on === void 0 ? { id: NOASSERTION } : { id: l.id, read_from: l.read_from, read_on: l.read_on };
93
+ });
94
+ var storage = {
95
+ stored: external_exports.array(external_exports.enum(STORED_KINDS)),
96
+ fetched_from: webUrl.optional()
97
+ };
98
+ var stores = (c, ctx) => {
99
+ repeats(c.stored).forEach(([i]) => {
100
+ ctx.addIssue({
101
+ code: "custom",
102
+ path: ["stored"],
103
+ message: `"${String(c.stored[i])}" is listed twice`
104
+ });
105
+ });
106
+ if (c.stored.length > 0 && c.fetched_from === void 0)
107
+ ctx.addIssue({
108
+ code: "custom",
109
+ path: ["fetched_from"],
110
+ message: "a copy that stores a file names where it was fetched from"
111
+ });
112
+ };
113
+ var copy = external_exports.discriminatedUnion("version", [
114
+ external_exports.strictObject({
115
+ version: external_exports.enum(KNOWN_VERSIONS),
116
+ url: webUrl,
117
+ licence,
118
+ ...storage
119
+ }).superRefine(stores),
120
+ external_exports.strictObject({
121
+ version: external_exports.literal("unknown"),
122
+ licence: notRead,
123
+ ...storage
124
+ }).superRefine(stores)
125
+ ]);
126
+ var ids = external_exports.strictObject({
127
+ doi: words.optional(),
128
+ arxiv: words.optional(),
129
+ dblp: words.optional(),
130
+ s2: words.optional(),
131
+ url: webUrl.optional()
132
+ }).refine(
133
+ (i) => Object.values(i).some((v) => v !== void 0),
134
+ `at least one of ${PAPER_ID_KINDS.join(", ")}`
135
+ );
136
+ var paperFields = {
137
+ key: external_exports.string().regex(KEY_PATTERN, "a letter or digit, then letters, digits, '_' or '-'"),
138
+ title: words,
139
+ authors: external_exports.array(words).optional(),
140
+ abstract: external_exports.string().nullable().optional(),
141
+ ids,
142
+ copies: external_exports.array(copy)
143
+ };
144
+ var year = external_exports.number().int().positive();
145
+ var paper = external_exports.discriminatedUnion("group", [
146
+ external_exports.looseObject({
147
+ ...paperFields,
148
+ group: external_exports.enum(["accepted", "award"]),
149
+ edition: year
150
+ }),
151
+ external_exports.looseObject({
152
+ ...paperFields,
153
+ group: external_exports.literal("sister"),
154
+ venue: words,
155
+ year,
156
+ listed_from: webUrl
157
+ })
158
+ ]);
159
+ var edition = external_exports.strictObject({
160
+ edition: year,
161
+ listed_from: webUrl,
162
+ read_on: date,
163
+ accepted: external_exports.number().int().nonnegative().optional()
164
+ });
165
+ var consistent = (r, ctx) => {
166
+ const years = r.editions.map((e) => e.edition);
167
+ repeats(years).forEach(([i]) => {
168
+ ctx.addIssue({
169
+ code: "custom",
170
+ path: ["editions", i, "edition"],
171
+ message: `${String(years[i])} is listed twice`
172
+ });
173
+ });
174
+ const keys = r.papers.map((p) => p.key);
175
+ repeats(keys).forEach(([i, first]) => {
176
+ ctx.addIssue({
177
+ code: "custom",
178
+ path: ["papers", i, "key"],
179
+ message: `"${String(keys[i])}" is the key of papers.${String(first)} too`
180
+ });
181
+ });
182
+ r.papers.forEach((p, i) => {
183
+ if (p.group !== "sister" && !years.includes(p.edition))
184
+ ctx.addIssue({
185
+ code: "custom",
186
+ path: ["papers", i, "edition"],
187
+ message: `${String(p.edition)} is not one of editions[].edition (${years.join(", ")})`
188
+ });
189
+ });
190
+ };
191
+ var record = external_exports.strictObject({
192
+ venue: words,
193
+ editions: external_exports.array(edition),
194
+ papers: external_exports.array(paper)
195
+ }).superRefine(consistent);
196
+ function jsonOf(text) {
197
+ try {
198
+ return JSON.parse(text);
199
+ } catch {
200
+ return void 0;
201
+ }
202
+ }
203
+ function parseVenueCorpus(text) {
204
+ const json = jsonOf(text);
205
+ if (json === void 0)
206
+ return { ok: false, why: `${CORPUS_RECORD} is not JSON` };
207
+ const parsed = record.safeParse(json);
208
+ if (parsed.success) return { ok: true, corpus: parsed.data };
209
+ const reasons = parsed.error.issues.map(
210
+ (i) => `${i.path.length === 0 ? "(top)" : i.path.join(".")}: ${i.message}`
211
+ );
212
+ return { ok: false, why: `${CORPUS_RECORD}: ${reasons.join("; ")}` };
213
+ }
214
+ var venueCorpusCodec = { parse: parseVenueCorpus };
215
+
216
+ // skills/study-accepted-papers/scripts/corpus-licences-core.ts
217
+ import { dirname, join } from "node:path";
218
+
219
+ // src/papers-roots.ts
220
+ import { isAbsolute, relative, resolve, sep } from "node:path";
221
+ function papersDirOf(opts) {
222
+ const declared = opts.papersDir;
223
+ return declared === void 0 ? DEFAULT_PAPERS_ROOT : declared;
224
+ }
225
+ function toPaths(papers) {
226
+ if (typeof papers === "string") return papers.trim() ? [papers.trim()] : [];
227
+ if (Array.isArray(papers))
228
+ return papers.filter(
229
+ (x) => typeof x === "string" && x.trim() !== ""
230
+ );
231
+ return [];
232
+ }
233
+ var papersRoots = (cfg) => toPaths(papersDirOf(cfg.opts)).map((rel) => resolve(cfg.root, rel));
234
+
235
+ // skills/study-accepted-papers/scripts/corpus-licences-core.ts
236
+ var isRefused = (j) => j.permission.kind !== "permitted";
237
+ var keptOf = (judged) => judged.map((j) => j.copy).find(
238
+ (c, i) => judged[i]?.permission.kind === "permitted" && c.version !== "unknown"
239
+ );
240
+ var refusalsOf = (judged) => judged.filter(isRefused).map((j) => ({
241
+ version: j.copy.version,
242
+ licence: j.copy.licence.id,
243
+ permission: j.permission
244
+ }));
245
+ function verdictOf(paper2, stored, settings) {
246
+ const judged = paper2.copies.map((copy2) => ({
247
+ copy: copy2,
248
+ permission: permits(copy2.licence.id, stored, settings)
249
+ }));
250
+ const kept = keptOf(judged);
251
+ const { key } = paper2;
252
+ return kept === void 0 ? {
253
+ key,
254
+ stored,
255
+ outcome: "none",
256
+ refusals: refusalsOf(judged)
257
+ } : {
258
+ key,
259
+ stored,
260
+ outcome: "keep",
261
+ version: kept.version,
262
+ licence: kept.licence.id,
263
+ url: kept.url
264
+ };
265
+ }
266
+ var verdicts = (corpus, settings) => corpus.papers.flatMap(
267
+ (p) => STORED_KINDS.map((kind) => verdictOf(p, kind, settings))
268
+ );
269
+ function reason(r) {
270
+ switch (r.permission.kind) {
271
+ case "forbidden":
272
+ return `${r.licence}: ${r.permission.why}`;
273
+ case "non-commercial-only":
274
+ return `${r.licence} permits it only in a project declared non-commercial`;
275
+ case "not-read":
276
+ return "its licence was not read (NOASSERTION)";
277
+ case "unlisted":
278
+ return `${r.permission.id} is not in the licence table, so it permits nothing`;
279
+ }
280
+ }
281
+ function line(v) {
282
+ const what = v.outcome === "keep" ? `keep the ${v.version} copy (${v.licence}), ${v.url}` : v.refusals.length === 0 ? "none: no copy recorded" : `none: ${v.refusals.map((r) => `${r.version}: ${reason(r)}`).join("; ")}`;
283
+ return `${v.key} ${v.stored}: ${what}`;
284
+ }
285
+ var listing = (all) => all.length === 0 ? `${CORPUS_RECORD} holds no paper
286
+ ` : `${all.map(line).join("\n")}
287
+ `;
288
+ function gitTopLevel(git2, path, cwd) {
289
+ const r = git2.run({
290
+ file: "git",
291
+ args: ["rev-parse", "--show-toplevel"],
292
+ env: { PATH: path ?? "" },
293
+ timeoutMs: 1e4,
294
+ cwd: callerPath(cwd)
295
+ });
296
+ const top = r.kind === "exited" && r.status === 0 ? r.stdout.trim() : "";
297
+ return top === "" ? null : top;
298
+ }
299
+ var UNDECLARED = { nonCommercial: false };
300
+ var VENUE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
301
+ var USAGE = "usage: node corpus-licences.js <venue>\n";
302
+ function settingsOf(files, root) {
303
+ const file = join(root, CONFIG_FILE);
304
+ const bytes = files.readBytes(callerPath(file));
305
+ if (bytes === null) return { ok: true, opts: {} };
306
+ const parsed = jsonOf2(new TextDecoder().decode(bytes));
307
+ if (parsed === void 0) return { ok: false, why: `${file} is not JSON` };
308
+ return {
309
+ ok: true,
310
+ opts: isObject(parsed) ? { [PAPERS_DIR_FIELD]: parsed[PAPERS_DIR_FIELD] } : {}
311
+ };
312
+ }
313
+ var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
314
+ function jsonOf2(text) {
315
+ try {
316
+ return JSON.parse(text);
317
+ } catch {
318
+ return void 0;
319
+ }
320
+ }
321
+ function recordOf(deps, venue) {
322
+ const root = deps.projectRoot(deps.cwd);
323
+ if (root === null)
324
+ return {
325
+ ok: false,
326
+ why: `${deps.cwd} is not inside a git repository: run it in the project`
327
+ };
328
+ const settings = settingsOf(deps.files, root);
329
+ if (!settings.ok) return settings;
330
+ const looked = papersRoots({ opts: settings.opts, root }).map(
331
+ (papers) => join(papers, "venues", venue, CORPUS_RECORD)
332
+ );
333
+ const found = looked.filter((f) => deps.files.isFile(callerPath(f)));
334
+ const [only] = found;
335
+ if (only !== void 0 && found.length === 1) return { ok: true, file: only };
336
+ return {
337
+ ok: false,
338
+ why: found.length === 0 ? `no ${CORPUS_RECORD} for venue "${venue}": looked in ${looked.map((f) => dirname(f)).join(", ")}; write the record first` : `venue "${venue}" is in more than one papers folder: ${found.map((f) => dirname(f)).join(", ")}`
339
+ };
340
+ }
341
+ function main(argv, deps, { out, err }) {
342
+ const [venue, ...rest] = argv;
343
+ if (venue === void 0 || rest.length > 0 || !VENUE.test(venue)) {
344
+ err(USAGE);
345
+ return 2;
346
+ }
347
+ const at = recordOf(deps, venue);
348
+ if (!at.ok) {
349
+ err(`corpus-licences: ${at.why}
350
+ `);
351
+ return 1;
352
+ }
353
+ const bytes = deps.files.readBytes(callerPath(at.file));
354
+ if (bytes === null) {
355
+ err(`corpus-licences: ${at.file} could not be read
356
+ `);
357
+ return 1;
358
+ }
359
+ const parsed = deps.codec.parse(new TextDecoder().decode(bytes));
360
+ if (!parsed.ok) {
361
+ err(`corpus-licences: ${parsed.why}
362
+ `);
363
+ return 1;
364
+ }
365
+ out(listing(verdicts(parsed.corpus, UNDECLARED)));
366
+ return 0;
367
+ }
368
+
369
+ // skills/study-accepted-papers/scripts/corpus-licences.ts
370
+ var git = spawnProcess();
371
+ process.exitCode = main(
372
+ process.argv.slice(2),
373
+ {
374
+ files: nodeFiles,
375
+ codec: venueCorpusCodec,
376
+ projectRoot: (cwd) => gitTopLevel(git, process.env["PATH"], cwd),
377
+ cwd: process.cwd()
378
+ },
379
+ {
380
+ out: (s) => process.stdout.write(s),
381
+ err: (s) => process.stderr.write(s)
382
+ }
383
+ );