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