paperlint 18.6.0 → 18.8.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/marketplace.json +11 -0
- package/.claude-plugin/plugin.json +7 -0
- package/CLAUDE.md +3 -3
- package/CONTRIBUTING.md +5 -2
- package/README.md +6 -6
- package/dist/adapters/clack/index.d.ts +3 -0
- package/dist/adapters/clack/index.d.ts.map +1 -0
- package/dist/adapters/clack/index.js +3 -0
- package/dist/adapters/clack/index.js.map +1 -0
- package/dist/adapters/clack/prompts.io.d.ts +8 -0
- package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
- package/dist/adapters/clack/prompts.io.js +20 -0
- package/dist/adapters/clack/prompts.io.js.map +1 -0
- package/dist/adapters/claude-code/claude.io.d.ts +13 -0
- package/dist/adapters/claude-code/claude.io.d.ts.map +1 -0
- package/dist/adapters/claude-code/claude.io.js +68 -0
- package/dist/adapters/claude-code/claude.io.js.map +1 -0
- package/dist/adapters/claude-code/index.d.ts +4 -0
- package/dist/adapters/claude-code/index.d.ts.map +1 -0
- package/dist/adapters/claude-code/index.js +4 -0
- package/dist/adapters/claude-code/index.js.map +1 -0
- package/dist/adapters/claude-code/plugin.d.ts +19 -0
- package/dist/adapters/claude-code/plugin.d.ts.map +1 -0
- package/dist/adapters/claude-code/plugin.js +66 -0
- package/dist/adapters/claude-code/plugin.js.map +1 -0
- package/dist/adapters/package-manager/index.d.ts +4 -0
- package/dist/adapters/package-manager/index.d.ts.map +1 -0
- package/dist/adapters/package-manager/index.js +4 -0
- package/dist/adapters/package-manager/index.js.map +1 -0
- package/dist/adapters/package-manager/install.io.d.ts +3 -0
- package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
- package/dist/adapters/package-manager/install.io.js +23 -0
- package/dist/adapters/package-manager/install.io.js.map +1 -0
- package/dist/adapters/package-manager/manager.d.ts +13 -0
- package/dist/adapters/package-manager/manager.d.ts.map +1 -0
- package/dist/adapters/package-manager/manager.js +22 -0
- package/dist/adapters/package-manager/manager.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/cli.d.ts +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +73 -13
- package/dist/cli.js.map +1 -1
- package/dist/doctor-plugin.d.ts +23 -0
- package/dist/doctor-plugin.d.ts.map +1 -0
- package/dist/doctor-plugin.js +56 -0
- package/dist/doctor-plugin.js.map +1 -0
- package/dist/doctor.d.ts +6 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +69 -26
- package/dist/doctor.js.map +1 -1
- package/dist/hooks-settings.d.ts +18 -0
- package/dist/hooks-settings.d.ts.map +1 -1
- package/dist/hooks-settings.js +25 -0
- package/dist/hooks-settings.js.map +1 -1
- package/dist/init.d.ts +47 -16
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +231 -86
- package/dist/init.js.map +1 -1
- package/dist/link-skills.d.ts +15 -0
- package/dist/link-skills.d.ts.map +1 -1
- package/dist/link-skills.js +18 -1
- package/dist/link-skills.js.map +1 -1
- package/dist/plugin-offer.d.ts +73 -0
- package/dist/plugin-offer.d.ts.map +1 -0
- package/dist/plugin-offer.js +96 -0
- package/dist/plugin-offer.js.map +1 -0
- package/dist/ports/claude-code.d.ts +31 -0
- package/dist/ports/claude-code.d.ts.map +1 -0
- package/dist/ports/claude-code.js +2 -0
- package/dist/ports/claude-code.js.map +1 -0
- package/dist/ports/project-install.d.ts +19 -0
- package/dist/ports/project-install.d.ts.map +1 -0
- package/dist/ports/project-install.js +2 -0
- package/dist/ports/project-install.js.map +1 -0
- package/dist/ports/prompts.d.ts +31 -0
- package/dist/ports/prompts.d.ts.map +1 -0
- package/dist/ports/prompts.js +2 -0
- package/dist/ports/prompts.js.map +1 -0
- package/dist/self-install.d.ts +65 -0
- package/dist/self-install.d.ts.map +1 -0
- package/dist/self-install.js +145 -0
- package/dist/self-install.js.map +1 -0
- package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
- package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
- package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
- package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
- package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
- package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
- package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
- package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
- package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/e2e.md +10 -0
- package/docs/install.md +88 -29
- package/docs/prior-art/README.md +2 -0
- package/docs/prior-art/one-command-install.md +33 -0
- package/docs/prior-art/prompt-libraries.md +32 -0
- package/eslint.config.mjs +1 -0
- package/hooks/CLAUDE.md +2 -2
- package/hooks/CLAUDE.md.spec.ts +1 -1
- package/lib/skill-checks.mjs +13 -6
- package/lib/skill-checks.test.mjs +28 -15
- package/lib/skill-corpus.mjs +5 -2
- package/package.json +8 -3
- package/plugin/CLAUDE.md +22 -14
- package/plugin/CLAUDE.md.spec.ts +20 -12
- package/scripts/bundle-skills.test.ts +226 -0
- package/scripts/bundle-skills.ts +304 -0
- package/scripts/plugin-version.test.ts +80 -0
- package/scripts/plugin-version.ts +58 -0
- package/skills/CLAUDE.md +2 -2
- package/skills/CLAUDE.md.spec.ts +1 -1
- package/skills/argument-arc/SKILL.md +2 -2
- package/skills/argument-arc/SKILL.md.spec.ts +1 -1
- package/skills/argument-arc/scripts/headings.js +57 -13
- package/skills/build-label-page/scripts/label-page.js +2005 -93
- package/skills/cold-read-diff/scripts/cold-read.js +221 -14
- package/skills/label-agent-runs/scripts/labels.js +272 -348
- package/skills/paper-pipeline/references/anonymization.md +4 -3
- package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
- package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
- package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
- package/skills/submit-paper/SKILL.md +5 -4
- package/skills/submit-paper/SKILL.md.spec.ts +4 -3
- package/skills/submit-paper/check-deanon.sh +17 -2
- package/skills/submit-paper/check-deanon.test.ts +141 -0
- package/skills/verify-citations/SKILL.md +9 -9
- package/skills/verify-citations/SKILL.md.spec.ts +8 -8
- package/skills/verify-citations/scripts/bib-authors.js +228 -0
- package/skills/verify-citations/scripts/verify-cites.js +816 -0
- package/src/adapters/clack/index.ts +2 -0
- package/src/adapters/clack/prompts.io.ts +35 -0
- package/src/adapters/clack/prompts.test.ts +58 -0
- package/src/adapters/claude-code/claude.io.ts +103 -0
- package/src/adapters/claude-code/index.test.ts +233 -0
- package/src/adapters/claude-code/index.ts +11 -0
- package/src/adapters/claude-code/plugin.ts +82 -0
- package/src/adapters/package-manager/index.test.ts +67 -0
- package/src/adapters/package-manager/index.ts +3 -0
- package/src/adapters/package-manager/install.io.ts +27 -0
- package/src/adapters/package-manager/manager.ts +33 -0
- package/src/cli.harness.mjs +47 -26
- package/src/cli.test.ts +179 -2
- package/src/cli.ts +130 -10
- package/src/doctor-plugin.test.ts +103 -0
- package/src/doctor-plugin.ts +83 -0
- package/src/doctor.test.ts +111 -2
- package/src/doctor.ts +83 -32
- package/src/hooks-notice.test.ts +82 -0
- package/src/hooks-settings.ts +49 -0
- package/src/init-plugin.test.ts +178 -0
- package/src/init.test.ts +138 -27
- package/src/init.ts +341 -124
- package/src/link-skills.test.ts +34 -1
- package/src/link-skills.ts +34 -0
- package/src/parse-args.test.ts +2 -0
- package/src/plugin-offer.test.ts +276 -0
- package/src/plugin-offer.ts +160 -0
- package/src/ports/claude-code.ts +30 -0
- package/src/ports/project-install.ts +18 -0
- package/src/ports/prompts.ts +27 -0
- package/src/self-install.test.ts +267 -0
- package/src/self-install.ts +224 -0
- package/src/types.ts +4 -0
|
@@ -0,0 +1,816 @@
|
|
|
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
|
+
bibReader,
|
|
10
|
+
bibliographyAt,
|
|
11
|
+
bibliographyUnreadWhy,
|
|
12
|
+
consumerContactEmail,
|
|
13
|
+
isMain
|
|
14
|
+
} from "../../../dist/skill-chunks/chunk-KWK6RT4T.js";
|
|
15
|
+
import {
|
|
16
|
+
latexReader,
|
|
17
|
+
sourcesCodec
|
|
18
|
+
} from "../../../dist/skill-chunks/chunk-65X5HVIJ.js";
|
|
19
|
+
import "../../../dist/skill-chunks/chunk-IREAROCV.js";
|
|
20
|
+
import {
|
|
21
|
+
absolutePath,
|
|
22
|
+
nodeFiles
|
|
23
|
+
} from "../../../dist/skill-chunks/chunk-6NU6CXUS.js";
|
|
24
|
+
import "../../../dist/skill-chunks/chunk-GRSXIWYF.js";
|
|
25
|
+
import "../../../dist/skill-chunks/chunk-NPQVDEE4.js";
|
|
26
|
+
import "../../../dist/skill-chunks/chunk-PJ4KNV4J.js";
|
|
27
|
+
|
|
28
|
+
// skills/verify-citations/scripts/verify-cites.mjs
|
|
29
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
30
|
+
import { homedir } from "node:os";
|
|
31
|
+
import { dirname, join, extname, resolve } from "node:path";
|
|
32
|
+
import { createHash } from "node:crypto";
|
|
33
|
+
var CACHE_PATH = process.env.VERIFY_CITES_CACHE || join(homedir(), ".cache", "paperlint", "cite-cache.json");
|
|
34
|
+
var CONTACT = consumerContactEmail();
|
|
35
|
+
var USER_AGENT = `verify-cites/1.0 (citation gate${CONTACT ? `; mailto:${CONTACT}` : ""})`;
|
|
36
|
+
var TIMEOUT_MS = 15e3;
|
|
37
|
+
var TITLE_THRESHOLD = 0.7;
|
|
38
|
+
var YEAR_TOLERANCE = 1;
|
|
39
|
+
function levenshtein(a, b) {
|
|
40
|
+
a = a ?? "";
|
|
41
|
+
b = b ?? "";
|
|
42
|
+
if (a === b) return 0;
|
|
43
|
+
if (a.length === 0) return b.length;
|
|
44
|
+
if (b.length === 0) return a.length;
|
|
45
|
+
let prev = new Array(b.length + 1);
|
|
46
|
+
let cur = new Array(b.length + 1);
|
|
47
|
+
for (let j = 0; j <= b.length; j++) prev[j] = j;
|
|
48
|
+
for (let i = 1; i <= a.length; i++) {
|
|
49
|
+
cur[0] = i;
|
|
50
|
+
const ca = a.charCodeAt(i - 1);
|
|
51
|
+
for (let j = 1; j <= b.length; j++) {
|
|
52
|
+
const cost = ca === b.charCodeAt(j - 1) ? 0 : 1;
|
|
53
|
+
cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost);
|
|
54
|
+
}
|
|
55
|
+
[prev, cur] = [cur, prev];
|
|
56
|
+
}
|
|
57
|
+
return prev[b.length];
|
|
58
|
+
}
|
|
59
|
+
function normalizeTitle(t) {
|
|
60
|
+
return (t ?? "").toLowerCase().normalize("NFKD").replace(new RegExp("\\p{M}+", "gu"), "").replace(/[^\p{L}\p{N}\s]/gu, " ").replace(/\s+/g, " ").trim();
|
|
61
|
+
}
|
|
62
|
+
function titleSimilarity(a, b) {
|
|
63
|
+
const na = normalizeTitle(a);
|
|
64
|
+
const nb = normalizeTitle(b);
|
|
65
|
+
if (!na || !nb) return 0;
|
|
66
|
+
const maxLen = Math.max(na.length, nb.length);
|
|
67
|
+
return 1 - levenshtein(na, nb) / maxLen;
|
|
68
|
+
}
|
|
69
|
+
function normalizeDoi(doi) {
|
|
70
|
+
if (!doi) return doi;
|
|
71
|
+
return String(doi).trim().replace(/^doi:\s*/i, "").replace(/^https?:\/\/(dx\.)?doi\.org\//i, "").replace(/[.,;:]+$/, "").trim();
|
|
72
|
+
}
|
|
73
|
+
function normalizeArxiv(arxiv) {
|
|
74
|
+
if (!arxiv) return arxiv;
|
|
75
|
+
return String(arxiv).trim().replace(/^arxiv:\s*/i, "").replace(/[.,;:]+$/, "").trim();
|
|
76
|
+
}
|
|
77
|
+
var ARXIV_DOI = /^10\.48550\/arxiv\.(.+)$/i;
|
|
78
|
+
function identifierAuthority(citation, query) {
|
|
79
|
+
if (query === "arxiv") return "arxiv";
|
|
80
|
+
return citation.doi && ARXIV_DOI.test(citation.doi) ? "arxiv" : "crossref";
|
|
81
|
+
}
|
|
82
|
+
function normalizeIdentifiers(citation) {
|
|
83
|
+
const c = { ...citation };
|
|
84
|
+
if (c.doi) c.doi = normalizeDoi(c.doi);
|
|
85
|
+
if (c.arxiv) c.arxiv = normalizeArxiv(c.arxiv);
|
|
86
|
+
const fromDoi = c.doi ? ARXIV_DOI.exec(c.doi)?.[1] : void 0;
|
|
87
|
+
if (!c.arxiv && fromDoi) c.arxiv = fromDoi;
|
|
88
|
+
return c;
|
|
89
|
+
}
|
|
90
|
+
var STOP_TOKENS = /* @__PURE__ */ new Set([
|
|
91
|
+
"the",
|
|
92
|
+
"a",
|
|
93
|
+
"an",
|
|
94
|
+
"of",
|
|
95
|
+
"and",
|
|
96
|
+
"for",
|
|
97
|
+
"to",
|
|
98
|
+
"in",
|
|
99
|
+
"on",
|
|
100
|
+
"is",
|
|
101
|
+
"are",
|
|
102
|
+
"with",
|
|
103
|
+
"via",
|
|
104
|
+
"using",
|
|
105
|
+
"from",
|
|
106
|
+
"by",
|
|
107
|
+
"at",
|
|
108
|
+
"as",
|
|
109
|
+
"or",
|
|
110
|
+
"be",
|
|
111
|
+
"we",
|
|
112
|
+
"our"
|
|
113
|
+
]);
|
|
114
|
+
function contentTokens(norm) {
|
|
115
|
+
return norm.split(" ").filter((w) => w.length >= 2 && !STOP_TOKENS.has(w));
|
|
116
|
+
}
|
|
117
|
+
function isAcronymOf(base, words) {
|
|
118
|
+
if (base.length < 2) return false;
|
|
119
|
+
for (let i = 0; i < words.length; i++) {
|
|
120
|
+
let acr = "";
|
|
121
|
+
for (let j = i; j < words.length && acr.length < base.length; j++) {
|
|
122
|
+
acr += words[j].charAt(0);
|
|
123
|
+
}
|
|
124
|
+
if (acr === base) return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
function tokenOverlap(small, large) {
|
|
129
|
+
const setL = new Set(large);
|
|
130
|
+
let count = 0;
|
|
131
|
+
for (const t of small) {
|
|
132
|
+
const base = t.replace(/s$/, "");
|
|
133
|
+
if (setL.has(t) || setL.has(base) || isAcronymOf(base, large)) count++;
|
|
134
|
+
}
|
|
135
|
+
return count;
|
|
136
|
+
}
|
|
137
|
+
function scriptsOf(s) {
|
|
138
|
+
const set = /* @__PURE__ */ new Set();
|
|
139
|
+
if (/[a-z]/.test(s)) set.add("latin");
|
|
140
|
+
if (/[Ѐ-ӿ]/.test(s)) set.add("cyrillic");
|
|
141
|
+
if (/[-ヿ㐀-鿿가-]/.test(s)) set.add("cjk");
|
|
142
|
+
if (/[Ͱ-Ͽ]/.test(s)) set.add("greek");
|
|
143
|
+
if (/[-ۿ]/.test(s)) set.add("arabic");
|
|
144
|
+
return set;
|
|
145
|
+
}
|
|
146
|
+
function titleRelation(a, b) {
|
|
147
|
+
const na = normalizeTitle(a);
|
|
148
|
+
const nb = normalizeTitle(b);
|
|
149
|
+
if (!na || !nb) return "incomparable";
|
|
150
|
+
const sa = scriptsOf(na);
|
|
151
|
+
const sb = scriptsOf(nb);
|
|
152
|
+
if (sa.size && sb.size && ![...sa].some((x) => sb.has(x)))
|
|
153
|
+
return "incomparable";
|
|
154
|
+
if (titleSimilarity(a, b) >= TITLE_THRESHOLD) return "match";
|
|
155
|
+
const A = contentTokens(na);
|
|
156
|
+
const B = contentTokens(nb);
|
|
157
|
+
if (A.length && B.length) {
|
|
158
|
+
const [small, large] = A.length <= B.length ? [A, B] : [B, A];
|
|
159
|
+
const contain = tokenOverlap(small, large) / small.length;
|
|
160
|
+
if (contain >= 0.6) return "match";
|
|
161
|
+
}
|
|
162
|
+
return "different";
|
|
163
|
+
}
|
|
164
|
+
function candidateTitles(record) {
|
|
165
|
+
const t = (record.title || "").trim();
|
|
166
|
+
const out = [t];
|
|
167
|
+
if (record.subtitle) {
|
|
168
|
+
const sub = String(record.subtitle).trim();
|
|
169
|
+
out.push(`${t} ${sub}`.trim(), `${t}: ${sub}`.trim());
|
|
170
|
+
}
|
|
171
|
+
return out.filter(Boolean);
|
|
172
|
+
}
|
|
173
|
+
function bestTitleRelation(claimed, candidates) {
|
|
174
|
+
let sawComparable = false;
|
|
175
|
+
for (const cand of candidates) {
|
|
176
|
+
const rel = titleRelation(claimed, cand);
|
|
177
|
+
if (rel === "match") return "match";
|
|
178
|
+
if (rel !== "incomparable") sawComparable = true;
|
|
179
|
+
}
|
|
180
|
+
return sawComparable ? "different" : "incomparable";
|
|
181
|
+
}
|
|
182
|
+
function yearMatch(claimed, found, tolerance = YEAR_TOLERANCE) {
|
|
183
|
+
const c = toYear(claimed);
|
|
184
|
+
const f = toYear(found);
|
|
185
|
+
if (c == null || f == null) return true;
|
|
186
|
+
return Math.abs(c - f) <= tolerance;
|
|
187
|
+
}
|
|
188
|
+
function toYear(y) {
|
|
189
|
+
if (y == null) return null;
|
|
190
|
+
const n = typeof y === "number" ? y : parseInt(String(y).slice(0, 4), 10);
|
|
191
|
+
return Number.isFinite(n) ? n : null;
|
|
192
|
+
}
|
|
193
|
+
function classifyResolver(citation, response) {
|
|
194
|
+
const db = response.db;
|
|
195
|
+
if (response.transport === "error") return { db, status: "unreachable" };
|
|
196
|
+
if (response.query === "doi" || response.query === "arxiv") {
|
|
197
|
+
if (response.record == null) {
|
|
198
|
+
return {
|
|
199
|
+
db,
|
|
200
|
+
status: "id_unmatched",
|
|
201
|
+
query: response.query,
|
|
202
|
+
authoritative: response.query === "arxiv" ? db === "arxiv" : false
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (citation.title) {
|
|
206
|
+
const rel = bestTitleRelation(
|
|
207
|
+
citation.title,
|
|
208
|
+
candidateTitles(response.record)
|
|
209
|
+
);
|
|
210
|
+
if (rel === "different") {
|
|
211
|
+
return {
|
|
212
|
+
db,
|
|
213
|
+
status: "doi_mismatch",
|
|
214
|
+
foundTitle: response.record.title,
|
|
215
|
+
authoritative: identifierAuthority(citation, response.query) === db
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
db,
|
|
221
|
+
status: "matched",
|
|
222
|
+
matchedTitle: response.record.title,
|
|
223
|
+
matchedYear: response.record.year
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const hits = response.records || [];
|
|
227
|
+
for (const rec of hits) {
|
|
228
|
+
if (titleRelation(citation.title, rec.title) === "match" && yearMatch(citation.year, rec.year)) {
|
|
229
|
+
return {
|
|
230
|
+
db,
|
|
231
|
+
status: "matched",
|
|
232
|
+
matchedTitle: rec.title,
|
|
233
|
+
matchedYear: rec.year
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { db, status: "title_miss" };
|
|
238
|
+
}
|
|
239
|
+
function classifyDoiAuthority(response) {
|
|
240
|
+
const db = "doi_authority";
|
|
241
|
+
if (!response || response.transport === "error")
|
|
242
|
+
return { db, status: "unreachable" };
|
|
243
|
+
if (response.responseCode === 1) return { db, status: "authority_present" };
|
|
244
|
+
if (response.responseCode === 100) return { db, status: "authority_absent" };
|
|
245
|
+
return { db, status: "unreachable" };
|
|
246
|
+
}
|
|
247
|
+
function checkNvd(citation, nvd) {
|
|
248
|
+
const db = "nvd";
|
|
249
|
+
if (!citation.cve) return null;
|
|
250
|
+
if (!nvd || nvd.transport === "error") return { db, status: "unreachable" };
|
|
251
|
+
if (nvd.found) {
|
|
252
|
+
return { db, status: "matched", matchedTitle: citation.cve };
|
|
253
|
+
}
|
|
254
|
+
return { db, status: "id_unmatched", query: "cve" };
|
|
255
|
+
}
|
|
256
|
+
function isValidCveId(cve) {
|
|
257
|
+
return /^CVE-\d{4}-\d{4,}$/i.test((cve ?? "").trim());
|
|
258
|
+
}
|
|
259
|
+
function checkCommit(citation) {
|
|
260
|
+
const flags = [];
|
|
261
|
+
if (citation.commit == null) return flags;
|
|
262
|
+
const sha = String(citation.commit).trim();
|
|
263
|
+
if (!/^[0-9a-f]+$/i.test(sha)) {
|
|
264
|
+
flags.push(`commit "${sha}" is not a hex git SHA \u2014 pin a full 40-char SHA`);
|
|
265
|
+
} else if (sha.length < 40) {
|
|
266
|
+
flags.push(
|
|
267
|
+
`commit "${sha}" is a short SHA (${sha.length}/40) \u2014 pin the full 40-char SHA (short hashes collide / are ambiguous)`
|
|
268
|
+
);
|
|
269
|
+
} else if (sha.length > 40) {
|
|
270
|
+
flags.push(
|
|
271
|
+
`commit "${sha}" is ${sha.length} hex chars (>40) \u2014 not a valid git SHA; pin the exact full 40-char SHA`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
return flags;
|
|
275
|
+
}
|
|
276
|
+
function reduceVerdict(citation, evidence, commitFlags = []) {
|
|
277
|
+
const ev = evidence.filter(Boolean);
|
|
278
|
+
const flags = [...commitFlags];
|
|
279
|
+
const out = (verdict, reason2, matched_db = null, extra = {}) => ({
|
|
280
|
+
id: citation.id,
|
|
281
|
+
verdict,
|
|
282
|
+
reason: reason2,
|
|
283
|
+
matched_db,
|
|
284
|
+
...extra,
|
|
285
|
+
...flags.length ? { flags } : {}
|
|
286
|
+
});
|
|
287
|
+
const matched = ev.find((e) => e.status === "matched");
|
|
288
|
+
if (matched) {
|
|
289
|
+
return out(
|
|
290
|
+
"true",
|
|
291
|
+
`confirmed by ${matched.db}${matched.matchedTitle ? ` \u2014 "${matched.matchedTitle}"` : ""}`,
|
|
292
|
+
matched.db,
|
|
293
|
+
{ matched_title: matched.matchedTitle }
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
const mismatch = ev.find(
|
|
297
|
+
(e) => e.status === "doi_mismatch" && e.authoritative
|
|
298
|
+
);
|
|
299
|
+
const aggregatorMismatch = ev.find(
|
|
300
|
+
(e) => e.status === "doi_mismatch" && !e.authoritative
|
|
301
|
+
);
|
|
302
|
+
if (mismatch) {
|
|
303
|
+
return out(
|
|
304
|
+
"false",
|
|
305
|
+
`DOI_MISMATCH: identifier resolves via ${mismatch.db} to an UNRELATED paper "${mismatch.foundTitle}" (claimed "${citation.title}") \u2014 DOI misdirection`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const authorityAbsent = ev.find((e) => e.status === "authority_absent");
|
|
309
|
+
const authorityPresent = ev.find((e) => e.status === "authority_present");
|
|
310
|
+
const doiIdMiss = ev.find(
|
|
311
|
+
(e) => e.status === "id_unmatched" && e.query === "doi"
|
|
312
|
+
);
|
|
313
|
+
const arxivAuthMiss = ev.find(
|
|
314
|
+
(e) => e.status === "id_unmatched" && e.query === "arxiv" && e.authoritative
|
|
315
|
+
);
|
|
316
|
+
const arxivAnyMiss = ev.find(
|
|
317
|
+
(e) => e.status === "id_unmatched" && e.query === "arxiv"
|
|
318
|
+
);
|
|
319
|
+
const cveMiss = ev.find(
|
|
320
|
+
(e) => e.status === "id_unmatched" && e.query === "cve"
|
|
321
|
+
);
|
|
322
|
+
if (authorityAbsent) {
|
|
323
|
+
return out(
|
|
324
|
+
"false",
|
|
325
|
+
`RESOLVED_TO_NOTHING: DOI ${citation.doi} does not resolve at the DOI authority (doi.org handle responseCode 100 = not found) \u2014 fabrication evidence`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
if (arxivAuthMiss) {
|
|
329
|
+
return out(
|
|
330
|
+
"false",
|
|
331
|
+
`RESOLVED_TO_NOTHING: arXiv id ${citation.arxiv} returns a definitive not-found from the reachable arXiv API \u2014 fabrication evidence`
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
if (cveMiss) {
|
|
335
|
+
return out(
|
|
336
|
+
"false",
|
|
337
|
+
`RESOLVED_TO_NOTHING: the provided CVE ${citation.cve} resolves to no record (checked ${cveMiss.db}) \u2014 fabrication evidence`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
const reachable = ev.some((e) => e.status !== "unreachable");
|
|
341
|
+
let reason;
|
|
342
|
+
if (aggregatorMismatch) {
|
|
343
|
+
reason = `DOI_MISMATCH unconfirmed: ${aggregatorMismatch.db} maps the identifier to "${aggregatorMismatch.foundTitle}" (claimed "${citation.title}"), but ${aggregatorMismatch.db} only aggregates metadata and the identifier's own registry did not confirm it \u2014 eyeball the entry \u2192 unresolvable, not false`;
|
|
344
|
+
} else if (doiIdMiss && authorityPresent) {
|
|
345
|
+
reason = `DOI ${citation.doi} resolves at doi.org but no content registry (Crossref/OpenAlex/Semantic Scholar) has metadata for it \u2014 common for DataCite/Zenodo and freshly-minted DOIs; the work EXISTS, its metadata is just unindexed \u2192 unresolvable, NOT fabrication`;
|
|
346
|
+
} else if (doiIdMiss) {
|
|
347
|
+
reason = `DOI ${citation.doi} not found in any content registry, and the DOI authority (doi.org) was not reachable to confirm non-existence \u2014 cannot assert fabrication \u2192 unresolvable, never false`;
|
|
348
|
+
} else if (arxivAnyMiss) {
|
|
349
|
+
reason = `arXiv id ${citation.arxiv} missed only by non-authoritative sources (the reachable arXiv API did not definitively reject it) \u2014 cannot assert fabrication \u2192 unresolvable`;
|
|
350
|
+
} else if (reachable) {
|
|
351
|
+
reason = "not found by title in any database (no resolvable id to disprove) \u2014 could be a legit unindexed/regional/pre-digital work, NOT fabrication";
|
|
352
|
+
} else {
|
|
353
|
+
reason = "all databases unreachable (network/rate-limit) \u2014 degraded to unresolvable, never to false";
|
|
354
|
+
}
|
|
355
|
+
return out("unresolvable", reason);
|
|
356
|
+
}
|
|
357
|
+
var writtenName = (n) => n.name ?? [n.firstName, n.prefix, n.lastName, n.suffix].filter(Boolean).join(" ");
|
|
358
|
+
function citationsOf(entries) {
|
|
359
|
+
return entries.map((e) => {
|
|
360
|
+
const f = e.fields;
|
|
361
|
+
const c = { id: e.key };
|
|
362
|
+
if (f.doi) c.doi = normalizeDoi(f.doi);
|
|
363
|
+
if (f.title) c.title = f.title.replace(/\s+/g, " ").trim();
|
|
364
|
+
if (f.year) c.year = f.year;
|
|
365
|
+
const authors = (e.names.author ?? []).map(writtenName).join(" and ");
|
|
366
|
+
if (authors) c.authors = authors;
|
|
367
|
+
const archive = f.archiveprefix || f.eprinttype;
|
|
368
|
+
if (f.eprint && (!archive || /arxiv/i.test(archive)))
|
|
369
|
+
c.arxiv = normalizeArxiv(f.eprint);
|
|
370
|
+
return c;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
function loadCache() {
|
|
374
|
+
try {
|
|
375
|
+
if (existsSync(CACHE_PATH))
|
|
376
|
+
return JSON.parse(readFileSync(CACHE_PATH, "utf8"));
|
|
377
|
+
} catch {
|
|
378
|
+
}
|
|
379
|
+
return {};
|
|
380
|
+
}
|
|
381
|
+
function saveCache(cache) {
|
|
382
|
+
try {
|
|
383
|
+
mkdirSync(dirname(CACHE_PATH), { recursive: true });
|
|
384
|
+
writeFileSync(CACHE_PATH, JSON.stringify(cache, null, 2));
|
|
385
|
+
} catch {
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function titleIdentity(t) {
|
|
389
|
+
return (t ?? "").toLowerCase().normalize("NFKD").replace(new RegExp("\\p{M}+", "gu"), "").replace(/[{}]/g, "").replace(/\s+/g, " ").trim();
|
|
390
|
+
}
|
|
391
|
+
function titleHash(t) {
|
|
392
|
+
return createHash("sha1").update(titleIdentity(t)).digest("hex").slice(0, 16);
|
|
393
|
+
}
|
|
394
|
+
function cacheKey(kind, val) {
|
|
395
|
+
return `${kind}:${val}`;
|
|
396
|
+
}
|
|
397
|
+
async function request(url, json, signal) {
|
|
398
|
+
const res = await fetch(url, {
|
|
399
|
+
headers: {
|
|
400
|
+
"User-Agent": USER_AGENT,
|
|
401
|
+
Accept: json ? "application/json" : "*/*"
|
|
402
|
+
},
|
|
403
|
+
signal
|
|
404
|
+
});
|
|
405
|
+
if (res.status === 429 || res.status >= 500) {
|
|
406
|
+
return { ok: false, reason: `http ${res.status}` };
|
|
407
|
+
}
|
|
408
|
+
if (res.status === 404) return { ok: true, notFound: true };
|
|
409
|
+
if (!res.ok) return { ok: false, reason: `http ${res.status}` };
|
|
410
|
+
const text = await res.text();
|
|
411
|
+
if (!json) return { ok: true, data: text };
|
|
412
|
+
try {
|
|
413
|
+
return { ok: true, data: JSON.parse(text) };
|
|
414
|
+
} catch {
|
|
415
|
+
return {
|
|
416
|
+
ok: false,
|
|
417
|
+
reason: text.trimStart().startsWith("<") ? "answered HTML, not JSON" : "answered something that is not JSON"
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
async function httpGet(url, { json = true } = {}) {
|
|
422
|
+
const ctrl = new AbortController();
|
|
423
|
+
const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
|
|
424
|
+
const result = await request(url, json, ctrl.signal).catch((e) => ({
|
|
425
|
+
ok: false,
|
|
426
|
+
reason: e.name === "AbortError" ? "timeout" : String(e)
|
|
427
|
+
}));
|
|
428
|
+
clearTimeout(timer);
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
async function crossrefResolve(citation) {
|
|
432
|
+
const db = "crossref";
|
|
433
|
+
if (citation.doi) {
|
|
434
|
+
const r2 = await httpGet(
|
|
435
|
+
`https://api.crossref.org/works/${encodeURIComponent(citation.doi)}`
|
|
436
|
+
);
|
|
437
|
+
if (!r2.ok) return { db, transport: "error", reason: r2.reason };
|
|
438
|
+
if (r2.notFound) return { db, transport: "ok", query: "doi", record: null };
|
|
439
|
+
const w = r2.data?.message;
|
|
440
|
+
return {
|
|
441
|
+
db,
|
|
442
|
+
transport: "ok",
|
|
443
|
+
query: "doi",
|
|
444
|
+
// Crossref splits a subtitle into its own field — carry it so the title
|
|
445
|
+
// comparison can try title AND title+subtitle (M2).
|
|
446
|
+
record: w ? {
|
|
447
|
+
title: (w.title || [])[0] || "",
|
|
448
|
+
subtitle: (w.subtitle || [])[0] || "",
|
|
449
|
+
year: crYear(w)
|
|
450
|
+
} : null
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
const url = `https://api.crossref.org/works?query.bibliographic=${encodeURIComponent(
|
|
454
|
+
citation.title
|
|
455
|
+
)}&rows=5`;
|
|
456
|
+
const r = await httpGet(url);
|
|
457
|
+
if (!r.ok) return { db, transport: "error", reason: r.reason };
|
|
458
|
+
const items = r.data?.message?.items || [];
|
|
459
|
+
return {
|
|
460
|
+
db,
|
|
461
|
+
transport: "ok",
|
|
462
|
+
query: "title",
|
|
463
|
+
records: items.map((w) => ({
|
|
464
|
+
title: (w.title || [])[0] || "",
|
|
465
|
+
year: crYear(w)
|
|
466
|
+
}))
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function crYear(w) {
|
|
470
|
+
return w?.issued?.["date-parts"]?.[0]?.[0] ?? w?.published?.["date-parts"]?.[0]?.[0] ?? null;
|
|
471
|
+
}
|
|
472
|
+
async function openalexResolve(citation) {
|
|
473
|
+
const db = "openalex";
|
|
474
|
+
if (citation.doi) {
|
|
475
|
+
const r2 = await httpGet(
|
|
476
|
+
`https://api.openalex.org/works/doi:${encodeURIComponent(citation.doi)}`
|
|
477
|
+
);
|
|
478
|
+
if (!r2.ok) return { db, transport: "error", reason: r2.reason };
|
|
479
|
+
if (r2.notFound) return { db, transport: "ok", query: "doi", record: null };
|
|
480
|
+
const w = r2.data;
|
|
481
|
+
return {
|
|
482
|
+
db,
|
|
483
|
+
transport: "ok",
|
|
484
|
+
query: "doi",
|
|
485
|
+
record: w?.id ? { title: w.display_name || "", year: w.publication_year } : null
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
const r = await httpGet(
|
|
489
|
+
`https://api.openalex.org/works?search=${encodeURIComponent(citation.title)}&per-page=5`
|
|
490
|
+
);
|
|
491
|
+
if (!r.ok) return { db, transport: "error", reason: r.reason };
|
|
492
|
+
const items = r.data?.results || [];
|
|
493
|
+
return {
|
|
494
|
+
db,
|
|
495
|
+
transport: "ok",
|
|
496
|
+
query: "title",
|
|
497
|
+
records: items.map((w) => ({
|
|
498
|
+
title: w.display_name || "",
|
|
499
|
+
year: w.publication_year
|
|
500
|
+
}))
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
var S2 = "https://api.semanticscholar.org/graph/v1/paper";
|
|
504
|
+
var semanticScholarResolve = (citation) => citation.doi || citation.arxiv ? semanticScholarById(citation) : semanticScholarByTitle(citation.title);
|
|
505
|
+
async function semanticScholarById(citation) {
|
|
506
|
+
const db = "semantic_scholar";
|
|
507
|
+
const query = citation.doi ? "doi" : "arxiv";
|
|
508
|
+
const id = citation.doi ? `DOI:${citation.doi}` : `arXiv:${citation.arxiv}`;
|
|
509
|
+
const r = await httpGet(`${S2}/${encodeURIComponent(id)}?fields=title,year`);
|
|
510
|
+
if (!r.ok) return { db, transport: "error", reason: r.reason };
|
|
511
|
+
if (r.notFound) return { db, transport: "ok", query, record: null };
|
|
512
|
+
const w = r.data;
|
|
513
|
+
return {
|
|
514
|
+
db,
|
|
515
|
+
transport: "ok",
|
|
516
|
+
query,
|
|
517
|
+
record: w?.title != null ? { title: w.title || "", year: w.year } : null
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
async function semanticScholarByTitle(title) {
|
|
521
|
+
const db = "semantic_scholar";
|
|
522
|
+
const r = await httpGet(
|
|
523
|
+
`${S2}/search?query=${encodeURIComponent(title)}&fields=title,year&limit=5`
|
|
524
|
+
);
|
|
525
|
+
if (!r.ok) return { db, transport: "error", reason: r.reason };
|
|
526
|
+
const items = r.data?.data || [];
|
|
527
|
+
return {
|
|
528
|
+
db,
|
|
529
|
+
transport: "ok",
|
|
530
|
+
query: "title",
|
|
531
|
+
records: items.map((w) => ({ title: w.title || "", year: w.year }))
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
async function arxivResolve(citation) {
|
|
535
|
+
const db = "arxiv";
|
|
536
|
+
if (citation.arxiv) {
|
|
537
|
+
const r2 = await httpGet(
|
|
538
|
+
`https://export.arxiv.org/api/query?id_list=${encodeURIComponent(citation.arxiv)}&max_results=1`,
|
|
539
|
+
{ json: false }
|
|
540
|
+
);
|
|
541
|
+
if (!r2.ok) return { db, transport: "error", reason: r2.reason };
|
|
542
|
+
const entry = parseArxivFeed(r2.data);
|
|
543
|
+
return { db, transport: "ok", query: "arxiv", record: entry[0] ?? null };
|
|
544
|
+
}
|
|
545
|
+
const r = await httpGet(
|
|
546
|
+
`https://export.arxiv.org/api/query?search_query=ti:${encodeURIComponent(
|
|
547
|
+
'"' + citation.title + '"'
|
|
548
|
+
)}&max_results=5`,
|
|
549
|
+
{ json: false }
|
|
550
|
+
);
|
|
551
|
+
if (!r.ok) return { db, transport: "error", reason: r.reason };
|
|
552
|
+
return {
|
|
553
|
+
db,
|
|
554
|
+
transport: "ok",
|
|
555
|
+
query: "title",
|
|
556
|
+
records: parseArxivFeed(r.data)
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
function parseArxivFeed(xml) {
|
|
560
|
+
const out = [];
|
|
561
|
+
if (!xml) return out;
|
|
562
|
+
const entries = xml.split(/<entry>/).slice(1);
|
|
563
|
+
for (const e of entries) {
|
|
564
|
+
const tM = e.match(/<title>([\s\S]*?)<\/title>/);
|
|
565
|
+
const pM = e.match(/<published>(\d{4})/);
|
|
566
|
+
const idM = e.match(/<id>([\s\S]*?)<\/id>/);
|
|
567
|
+
if (!tM) continue;
|
|
568
|
+
const title = tM[1].replace(/\s+/g, " ").trim();
|
|
569
|
+
const isErrorSentinel = title === "Error" && /arxiv\.org\/api\/errors/i.test(idM ? idM[1] : "");
|
|
570
|
+
if (isErrorSentinel) continue;
|
|
571
|
+
out.push({ title, year: pM ? +pM[1] : null });
|
|
572
|
+
}
|
|
573
|
+
return out;
|
|
574
|
+
}
|
|
575
|
+
async function doiAuthorityCheck(doi) {
|
|
576
|
+
const path = encodeURIComponent(doi.trim()).replace(/%2F/gi, "/");
|
|
577
|
+
const r = await httpGet(`https://doi.org/api/handles/${path}`);
|
|
578
|
+
if (r.notFound) return { transport: "ok", responseCode: 100 };
|
|
579
|
+
if (!r.ok) return { transport: "error", reason: r.reason };
|
|
580
|
+
const code = r.data?.responseCode;
|
|
581
|
+
return {
|
|
582
|
+
transport: "ok",
|
|
583
|
+
responseCode: typeof code === "number" ? code : void 0
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
async function nvdCheck(cve) {
|
|
587
|
+
if (!isValidCveId(cve)) {
|
|
588
|
+
return { transport: "ok", found: false };
|
|
589
|
+
}
|
|
590
|
+
const r = await httpGet(
|
|
591
|
+
`https://services.nvd.nist.gov/rest/json/cves/2.0?cveId=${encodeURIComponent(
|
|
592
|
+
cve.toUpperCase()
|
|
593
|
+
)}`
|
|
594
|
+
);
|
|
595
|
+
if (!r.ok) return { transport: "error", reason: r.reason };
|
|
596
|
+
if (r.notFound) return { transport: "ok", found: false };
|
|
597
|
+
const total = r.data?.totalResults ?? (r.data?.vulnerabilities || []).length;
|
|
598
|
+
return { transport: "ok", found: total > 0 };
|
|
599
|
+
}
|
|
600
|
+
var PAPER_RESOLVERS = [
|
|
601
|
+
{
|
|
602
|
+
name: "crossref",
|
|
603
|
+
fn: crossrefResolve,
|
|
604
|
+
ask: (c) => c.doi ? { doi: c.doi } : c.title ? { title: c.title } : null
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
name: "openalex",
|
|
608
|
+
fn: openalexResolve,
|
|
609
|
+
ask: (c) => c.doi ? { doi: c.doi } : c.title ? { title: c.title } : null
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
name: "semantic_scholar",
|
|
613
|
+
fn: semanticScholarResolve,
|
|
614
|
+
ask: (c) => c.doi ? { doi: c.doi } : c.arxiv ? { arxiv: c.arxiv } : { title: c.title }
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
name: "arxiv",
|
|
618
|
+
fn: arxivResolve,
|
|
619
|
+
// No DOI endpoint: by arXiv id, else a title search — but not for a DOI-only entry.
|
|
620
|
+
ask: (c) => c.arxiv ? { arxiv: c.arxiv } : c.title && !c.doi ? { title: c.title } : null
|
|
621
|
+
}
|
|
622
|
+
];
|
|
623
|
+
var paperKey = (name, q) => cacheKey(
|
|
624
|
+
name,
|
|
625
|
+
q.doi ? `doi:${q.doi}` : q.arxiv ? `arxiv:${q.arxiv}` : `title:${titleHash(q.title)}`
|
|
626
|
+
);
|
|
627
|
+
async function consult(citation, lookup) {
|
|
628
|
+
const evidence = [];
|
|
629
|
+
const matched = () => evidence.at(-1)?.status === "matched";
|
|
630
|
+
if (citation.doi || citation.arxiv || citation.title) {
|
|
631
|
+
for (const { name, fn, ask } of PAPER_RESOLVERS) {
|
|
632
|
+
const question = ask(citation);
|
|
633
|
+
if (question === null) continue;
|
|
634
|
+
const resp = await lookup(
|
|
635
|
+
paperKey(name, question),
|
|
636
|
+
name,
|
|
637
|
+
() => fn(question),
|
|
638
|
+
() => true
|
|
639
|
+
);
|
|
640
|
+
evidence.push(classifyResolver(citation, resp));
|
|
641
|
+
if (matched()) return evidence;
|
|
642
|
+
}
|
|
643
|
+
if (citation.doi) {
|
|
644
|
+
const auth = await lookup(
|
|
645
|
+
cacheKey("doi_authority", citation.doi),
|
|
646
|
+
"doi_authority",
|
|
647
|
+
() => doiAuthorityCheck(citation.doi),
|
|
648
|
+
// Cache only POSITIVE existence; never authority-absent (100), so a freshly-minted DOI
|
|
649
|
+
// checked pre-propagation isn't pinned to `false` on re-run.
|
|
650
|
+
(a) => a.responseCode !== 100
|
|
651
|
+
);
|
|
652
|
+
evidence.push(classifyDoiAuthority(auth));
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
if (citation.cve) {
|
|
656
|
+
const nvd = await lookup(
|
|
657
|
+
cacheKey("nvd", citation.cve.toUpperCase()),
|
|
658
|
+
"nvd",
|
|
659
|
+
() => nvdCheck(citation.cve),
|
|
660
|
+
// Cache only POSITIVE existence, as for doi.org: a CVE cited before NVD indexes it must not
|
|
661
|
+
// be pinned to "not found" in the committed cache. A missing CVE is asked again each build.
|
|
662
|
+
(a) => a.found
|
|
663
|
+
);
|
|
664
|
+
const e = checkNvd(citation, nvd);
|
|
665
|
+
if (e) evidence.push(e);
|
|
666
|
+
}
|
|
667
|
+
return evidence;
|
|
668
|
+
}
|
|
669
|
+
async function wouldAsk(citation, cache) {
|
|
670
|
+
let missed = false;
|
|
671
|
+
await consult(normalizeIdentifiers(citation), async (key) => {
|
|
672
|
+
if (cache[key]) return cache[key];
|
|
673
|
+
missed = true;
|
|
674
|
+
return { transport: "error" };
|
|
675
|
+
});
|
|
676
|
+
return missed;
|
|
677
|
+
}
|
|
678
|
+
function createBreaker() {
|
|
679
|
+
const state = /* @__PURE__ */ new Map();
|
|
680
|
+
const call = async (service, attempt) => {
|
|
681
|
+
const s = state.get(service);
|
|
682
|
+
if (s?.refused)
|
|
683
|
+
return {
|
|
684
|
+
ok: false,
|
|
685
|
+
reason: `${service} refused earlier in this run (${s.refused})`
|
|
686
|
+
};
|
|
687
|
+
if (s?.first) {
|
|
688
|
+
await s.first;
|
|
689
|
+
return call(service, attempt);
|
|
690
|
+
}
|
|
691
|
+
const pending = attempt();
|
|
692
|
+
if (!s) state.set(service, { first: pending });
|
|
693
|
+
const r = await pending;
|
|
694
|
+
if (!r.ok) state.set(service, { refused: r.reason });
|
|
695
|
+
else if (!s) state.set(service, { answered: true });
|
|
696
|
+
return r;
|
|
697
|
+
};
|
|
698
|
+
return { call };
|
|
699
|
+
}
|
|
700
|
+
async function verifyCitationLive(citation, { cache = {}, offline = false, breaker = createBreaker() } = {}) {
|
|
701
|
+
citation = normalizeIdentifiers(citation);
|
|
702
|
+
const commitFlags = checkCommit(citation);
|
|
703
|
+
if (offline) {
|
|
704
|
+
return reduceVerdict(citation, [], commitFlags);
|
|
705
|
+
}
|
|
706
|
+
const refused = [];
|
|
707
|
+
const evidence = await consult(
|
|
708
|
+
citation,
|
|
709
|
+
async (key, service, fetch2, keep) => {
|
|
710
|
+
if (cache[key]) return cache[key];
|
|
711
|
+
const r = await breaker.call(service, async () => {
|
|
712
|
+
const resp = await fetch2();
|
|
713
|
+
return resp.transport === "ok" ? { ok: true, value: resp } : { ok: false, reason: resp.reason };
|
|
714
|
+
});
|
|
715
|
+
if (!r.ok) {
|
|
716
|
+
refused.push(`${service}: ${r.reason}`);
|
|
717
|
+
return { db: service, transport: "error" };
|
|
718
|
+
}
|
|
719
|
+
if (keep(r.value)) cache[key] = r.value;
|
|
720
|
+
return r.value;
|
|
721
|
+
}
|
|
722
|
+
);
|
|
723
|
+
const verdict = reduceVerdict(citation, evidence, commitFlags);
|
|
724
|
+
return refused.length ? { ...verdict, refused } : verdict;
|
|
725
|
+
}
|
|
726
|
+
var DEPS = {
|
|
727
|
+
files: nodeFiles,
|
|
728
|
+
codec: sourcesCodec,
|
|
729
|
+
latex: latexReader,
|
|
730
|
+
bib: bibReader
|
|
731
|
+
};
|
|
732
|
+
function loadInput(argv) {
|
|
733
|
+
const path = argv.find((a) => !a.startsWith("-"));
|
|
734
|
+
if (path && extname(path).toLowerCase() === ".bib") {
|
|
735
|
+
const r = bibliographyAt(absolutePath(resolve(path)), DEPS);
|
|
736
|
+
if (!r.ok) throw new Error(bibliographyUnreadWhy(r.error));
|
|
737
|
+
return citationsOf(r.value.texts.flatMap((t) => t.entries));
|
|
738
|
+
}
|
|
739
|
+
const raw = path && path !== "-" ? readFileSync(path, "utf8") : readFileSync(0, "utf8");
|
|
740
|
+
const parsed = JSON.parse(raw);
|
|
741
|
+
return Array.isArray(parsed) ? parsed : [parsed];
|
|
742
|
+
}
|
|
743
|
+
async function main() {
|
|
744
|
+
const argv = process.argv.slice(2);
|
|
745
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
746
|
+
process.stderr.write(
|
|
747
|
+
"usage: verify-cites.mjs <cites.json | refs.bib | -> [--offline]\n"
|
|
748
|
+
);
|
|
749
|
+
process.exit(0);
|
|
750
|
+
}
|
|
751
|
+
const offline = argv.includes("--offline");
|
|
752
|
+
let cites;
|
|
753
|
+
try {
|
|
754
|
+
cites = loadInput(argv);
|
|
755
|
+
} catch (e) {
|
|
756
|
+
process.stderr.write(`error: could not read input \u2014 ${e.message}
|
|
757
|
+
`);
|
|
758
|
+
process.exit(2);
|
|
759
|
+
}
|
|
760
|
+
const cache = loadCache();
|
|
761
|
+
const breaker = createBreaker();
|
|
762
|
+
const results = [];
|
|
763
|
+
for (const c of cites) {
|
|
764
|
+
if (!c || !c.id) {
|
|
765
|
+
results.push({
|
|
766
|
+
id: c?.id ?? null,
|
|
767
|
+
verdict: "unresolvable",
|
|
768
|
+
reason: "citation has no id",
|
|
769
|
+
matched_db: null
|
|
770
|
+
});
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
results.push(await verifyCitationLive(c, { cache, offline, breaker }));
|
|
774
|
+
}
|
|
775
|
+
saveCache(cache);
|
|
776
|
+
process.stdout.write(JSON.stringify(results, null, 2) + "\n");
|
|
777
|
+
const n = results.length;
|
|
778
|
+
const f = results.filter((r) => r.verdict === "false").length;
|
|
779
|
+
const u = results.filter((r) => r.verdict === "unresolvable").length;
|
|
780
|
+
const t = results.filter((r) => r.verdict === "true").length;
|
|
781
|
+
const flagged = results.filter((r) => r.flags && r.flags.length).length;
|
|
782
|
+
process.stderr.write(
|
|
783
|
+
`
|
|
784
|
+
verify-cites: ${n} citation(s) \u2014 ${t} true, ${f} false (fabrication), ${u} unresolvable` + (flagged ? `, ${flagged} with hygiene flag(s)` : "") + `
|
|
785
|
+
${f > 0 ? "FAIL \u2014 fabrication(s) found (exit 1)" : "PASS \u2014 no fabrication (unresolvable is advisory)"}
|
|
786
|
+
`
|
|
787
|
+
);
|
|
788
|
+
process.exit(f > 0 ? 1 : 0);
|
|
789
|
+
}
|
|
790
|
+
if (isMain(import.meta.url)) {
|
|
791
|
+
main();
|
|
792
|
+
}
|
|
793
|
+
export {
|
|
794
|
+
bestTitleRelation,
|
|
795
|
+
candidateTitles,
|
|
796
|
+
checkCommit,
|
|
797
|
+
checkNvd,
|
|
798
|
+
citationsOf,
|
|
799
|
+
classifyDoiAuthority,
|
|
800
|
+
classifyResolver,
|
|
801
|
+
createBreaker,
|
|
802
|
+
isValidCveId,
|
|
803
|
+
levenshtein,
|
|
804
|
+
normalizeArxiv,
|
|
805
|
+
normalizeDoi,
|
|
806
|
+
normalizeIdentifiers,
|
|
807
|
+
normalizeTitle,
|
|
808
|
+
parseArxivFeed,
|
|
809
|
+
reduceVerdict,
|
|
810
|
+
titleIdentity,
|
|
811
|
+
titleRelation,
|
|
812
|
+
titleSimilarity,
|
|
813
|
+
verifyCitationLive,
|
|
814
|
+
wouldAsk,
|
|
815
|
+
yearMatch
|
|
816
|
+
};
|