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
|
@@ -1,396 +1,320 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* Wilson interval, Cohen's kappa, and every disagreement. Use it for the automatic pre-sort
|
|
15
|
-
* against the hand labels, and for one rater against another.
|
|
16
|
-
*
|
|
17
|
-
* A label file is TSV with exactly this header: agent, model, cell, label. `cell` is
|
|
18
|
-
* `<unit>/<arm>/<seed>`, the cell of the run-agent-grid ledger.
|
|
19
|
-
*
|
|
20
|
-
* TypeScript, compiled beside itself to `labels.js` by `npm run build`: a consumer runs the skill
|
|
21
|
-
* from `node_modules`, where Node does not strip types. The skill names the `.js`.
|
|
22
|
-
*
|
|
23
|
-
* EXIT CODES: 0 valid / reported · 1 a finding · 2 usage.
|
|
24
|
-
*/
|
|
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
|
+
external_exports
|
|
10
|
+
} from "../../../dist/skill-chunks/chunk-NPQVDEE4.js";
|
|
11
|
+
import "../../../dist/skill-chunks/chunk-PJ4KNV4J.js";
|
|
12
|
+
|
|
13
|
+
// skills/label-agent-runs/scripts/labels.ts
|
|
25
14
|
import { spawnSync } from "node:child_process";
|
|
26
15
|
import { readFileSync } from "node:fs";
|
|
27
16
|
import { dirname, relative, resolve, sep } from "node:path";
|
|
28
17
|
import { parseArgs } from "node:util";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
18
|
+
|
|
19
|
+
// skills/label-agent-runs/scripts/labels-commands.ts
|
|
20
|
+
var COMMANDS = {
|
|
21
|
+
validate: "validate",
|
|
22
|
+
agree: "agree"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// skills/label-agent-runs/scripts/labels.ts
|
|
26
|
+
var Refusal = class extends Error {
|
|
27
|
+
exitCode;
|
|
28
|
+
constructor(exitCode, message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.exitCode = exitCode;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var refuse = (exitCode, message) => {
|
|
34
|
+
throw new Refusal(exitCode, message);
|
|
40
35
|
};
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
var say = (line) => {
|
|
37
|
+
process.stdout.write(`${line}
|
|
38
|
+
`);
|
|
43
39
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
]
|
|
61
|
-
: [];
|
|
40
|
+
var prop = (e, key) => Reflect.get(Object(e), key);
|
|
41
|
+
var HEADER = ["agent", "model", "cell", "label"];
|
|
42
|
+
var keyOf = (r) => `${r.agent} ${r.model} ${r.cell}`;
|
|
43
|
+
var show = (r) => `${r.agent} ${r.model} ${r.cell}`;
|
|
44
|
+
var asRow = ({ fields, n }) => {
|
|
45
|
+
const [agent, model, cell, label] = fields;
|
|
46
|
+
return fields.length === 4 ? [
|
|
47
|
+
{
|
|
48
|
+
agent: String(agent),
|
|
49
|
+
model: String(model),
|
|
50
|
+
cell: String(cell),
|
|
51
|
+
label: String(label),
|
|
52
|
+
n
|
|
53
|
+
}
|
|
54
|
+
] : [];
|
|
62
55
|
};
|
|
63
|
-
/** Rows of a label file, and the problems that stop a line being one. */
|
|
64
56
|
function readLabels(file) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
: [`${file}:1: the header must be "${HEADER.join("\\t")}"`]),
|
|
76
|
-
...lines
|
|
77
|
-
.filter(({ fields }) => fields.length !== 4)
|
|
78
|
-
.map(({ n }) => `${file}:${String(n)}: not four tab-separated fields`),
|
|
79
|
-
],
|
|
80
|
-
};
|
|
57
|
+
const [first, ...body] = readFileSync(file, "utf8").split("\n");
|
|
58
|
+
const lines = body.map((line, i) => ({ line, fields: line.split(" "), n: i + 2 })).filter(({ line }) => line.trim() !== "");
|
|
59
|
+
const headerOk = String(first).replace(/\r$/, "") === HEADER.join(" ");
|
|
60
|
+
return {
|
|
61
|
+
rows: lines.flatMap(asRow),
|
|
62
|
+
problems: [
|
|
63
|
+
...headerOk ? [] : [`${file}:1: the header must be "${HEADER.join("\\t")}"`],
|
|
64
|
+
...lines.filter(({ fields }) => fields.length !== 4).map(({ n }) => `${file}:${String(n)}: not four tab-separated fields`)
|
|
65
|
+
]
|
|
66
|
+
};
|
|
81
67
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
rel: relative(top.stdout.trim(), abs).split(sep).join("/"),
|
|
90
|
-
}
|
|
91
|
-
: null;
|
|
68
|
+
var git = (cwd, ...args) => spawnSync("git", ["-C", cwd, ...args], { encoding: "utf8" });
|
|
69
|
+
var repoPath = (abs) => {
|
|
70
|
+
const top = git(dirname(abs), "rev-parse", "--show-toplevel");
|
|
71
|
+
return top.status === 0 ? {
|
|
72
|
+
top: top.stdout.trim(),
|
|
73
|
+
rel: relative(top.stdout.trim(), abs).split(sep).join("/")
|
|
74
|
+
} : null;
|
|
92
75
|
};
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return at
|
|
98
|
-
? git(at.top, "log", ...filter, "--format=%ct", "--", at.rel)
|
|
99
|
-
.stdout.trim()
|
|
100
|
-
.split("\n")
|
|
101
|
-
.filter(Boolean)
|
|
102
|
-
.map(Number)
|
|
103
|
-
: [];
|
|
76
|
+
var commitTimes = (abs, added) => {
|
|
77
|
+
const at = repoPath(abs);
|
|
78
|
+
const filter = added ? ["--diff-filter=A"] : [];
|
|
79
|
+
return at ? git(at.top, "log", ...filter, "--format=%ct", "--", at.rel).stdout.trim().split("\n").filter(Boolean).map(Number) : [];
|
|
104
80
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
})
|
|
112
|
-
|
|
81
|
+
var Codebook = external_exports.looseObject({
|
|
82
|
+
labels: external_exports.array(
|
|
83
|
+
external_exports.looseObject({
|
|
84
|
+
id: external_exports.unknown().optional(),
|
|
85
|
+
definition: external_exports.unknown().optional(),
|
|
86
|
+
borderline: external_exports.unknown().optional()
|
|
87
|
+
})
|
|
88
|
+
).default([])
|
|
113
89
|
});
|
|
114
|
-
|
|
115
|
-
/** Is the committed copy of `abs` the one on disk? A message when it is not. */
|
|
90
|
+
var filled = (v) => typeof v === "string" && v.trim() !== "";
|
|
116
91
|
function committedProblem(file, abs, text) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
`${file} differs from its committed version: the codebook is fixed before labelling`,
|
|
127
|
-
];
|
|
92
|
+
const at = repoPath(abs);
|
|
93
|
+
const head = at ? git(at.top, "show", `HEAD:${at.rel}`) : null;
|
|
94
|
+
if (!head || head.status !== 0)
|
|
95
|
+
return [
|
|
96
|
+
`${file} is not committed: commit the codebook before the first label`
|
|
97
|
+
];
|
|
98
|
+
return head.stdout === text ? [] : [
|
|
99
|
+
`${file} differs from its committed version: the codebook is fixed before labelling`
|
|
100
|
+
];
|
|
128
101
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
102
|
+
var incomplete = (file, labels) => labels.filter(
|
|
103
|
+
(l) => !(filled(l.id) && filled(l.definition) && filled(l.borderline))
|
|
104
|
+
).map(
|
|
105
|
+
(l) => `${file}: label "${String(l.id)}" needs an id, a definition and a borderline example`
|
|
106
|
+
);
|
|
133
107
|
function codebookProblems(file, labelsFile) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
};
|
|
108
|
+
const abs = resolve(file);
|
|
109
|
+
const text = readFileSync(abs, "utf8");
|
|
110
|
+
const { labels } = Codebook.parse(JSON.parse(text));
|
|
111
|
+
const bookLast = Math.max(-Infinity, ...commitTimes(abs, false));
|
|
112
|
+
const labelsFirst = Math.min(
|
|
113
|
+
Infinity,
|
|
114
|
+
...commitTimes(resolve(labelsFile), true)
|
|
115
|
+
);
|
|
116
|
+
const late = bookLast > labelsFirst;
|
|
117
|
+
return {
|
|
118
|
+
known: new Set(labels.map((l) => l.id)),
|
|
119
|
+
problems: [
|
|
120
|
+
...committedProblem(file, abs, text),
|
|
121
|
+
...labels.length ? [] : [`${file} defines no labels`],
|
|
122
|
+
...incomplete(file, labels),
|
|
123
|
+
...late ? [
|
|
124
|
+
`${file} was committed after ${labelsFile} was first committed: the codebook is fixed before labelling; a changed codebook needs a new label file`
|
|
125
|
+
] : []
|
|
126
|
+
]
|
|
127
|
+
};
|
|
155
128
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
129
|
+
var Attempt = external_exports.looseObject({
|
|
130
|
+
attempt: external_exports.string(),
|
|
131
|
+
agent: external_exports.string().optional(),
|
|
132
|
+
model: external_exports.string().optional(),
|
|
133
|
+
unit: external_exports.string().optional(),
|
|
134
|
+
arm: external_exports.string().optional(),
|
|
135
|
+
seed: external_exports.union([external_exports.string(), external_exports.number()]).optional(),
|
|
136
|
+
status: external_exports.string().optional()
|
|
164
137
|
});
|
|
165
|
-
/** The cells of the completed attempts in a run-agent-grid ledger. */
|
|
166
138
|
function ledgerCells(file) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
.filter((r) => r.status === "complete")
|
|
177
|
-
.map((r) => ({
|
|
178
|
-
agent: String(r.agent),
|
|
179
|
-
model: String(r.model),
|
|
180
|
-
cell: `${String(r.unit)}/${String(r.arm)}/${String(r.seed)}`,
|
|
181
|
-
}));
|
|
139
|
+
const byId = /* @__PURE__ */ new Map();
|
|
140
|
+
readFileSync(file, "utf8").split("\n").filter((l) => l.trim()).map((l) => Attempt.parse(JSON.parse(l))).forEach((r) => {
|
|
141
|
+
byId.set(r.attempt, { ...byId.get(r.attempt), ...r });
|
|
142
|
+
});
|
|
143
|
+
return [...byId.values()].filter((r) => r.status === "complete").map((r) => ({
|
|
144
|
+
agent: String(r.agent),
|
|
145
|
+
model: String(r.model),
|
|
146
|
+
cell: `${String(r.unit)}/${String(r.arm)}/${String(r.seed)}`
|
|
147
|
+
}));
|
|
182
148
|
}
|
|
183
|
-
/** The labels a revision of the label file held, by cell; null when it did not exist there. */
|
|
184
149
|
function labelsAt(labelsFile, rev) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
cell: String(cell),
|
|
199
|
-
}),
|
|
200
|
-
String(label),
|
|
201
|
-
]));
|
|
150
|
+
const at = repoPath(resolve(labelsFile));
|
|
151
|
+
const then = at ? git(at.top, "show", `${rev}:${at.rel}`) : null;
|
|
152
|
+
if (!then || then.status !== 0) return null;
|
|
153
|
+
return new Map(
|
|
154
|
+
then.stdout.split("\n").slice(1).filter((l) => l.trim()).map((l) => l.split(" ")).map(([agent, model, cell, label]) => [
|
|
155
|
+
keyOf({
|
|
156
|
+
agent: String(agent),
|
|
157
|
+
model: String(model),
|
|
158
|
+
cell: String(cell)
|
|
159
|
+
}),
|
|
160
|
+
String(label)
|
|
161
|
+
])
|
|
162
|
+
);
|
|
202
163
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
/** A cell key back as the three fields `show` prints. */
|
|
208
|
-
const fromKey = (key) => {
|
|
209
|
-
const [agent, model, cell] = key.split("\t");
|
|
210
|
-
return { agent: String(agent), model: String(model), cell: String(cell) };
|
|
164
|
+
var datedSections = (notesFile) => readFileSync(notesFile, "utf8").split(/^(?=## )/m).filter((s) => /^## \d{4}-\d{2}-\d{2}\b/.test(s));
|
|
165
|
+
var fromKey = (key) => {
|
|
166
|
+
const [agent, model, cell] = key.split(" ");
|
|
167
|
+
return { agent: String(agent), model: String(model), cell: String(cell) };
|
|
211
168
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
.map((r) => {
|
|
217
|
-
const was = before.get(keyOf(r));
|
|
218
|
-
return was === undefined
|
|
219
|
-
? `${show(r)}: added after the analysis (${r.label}),${WHY}`
|
|
220
|
-
: `${show(r)}: relabelled ${was} → ${r.label} after the analysis,${WHY}`;
|
|
169
|
+
var WHY = " with no dated note quoting the run";
|
|
170
|
+
var touchedSince = (rows, before, noted) => rows.filter((r) => before.get(keyOf(r)) !== r.label && !noted(r.cell)).map((r) => {
|
|
171
|
+
const was = before.get(keyOf(r));
|
|
172
|
+
return was === void 0 ? `${show(r)}: added after the analysis (${r.label}),${WHY}` : `${show(r)}: relabelled ${was} \u2192 ${r.label} after the analysis,${WHY}`;
|
|
221
173
|
});
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
.map(([key, was]) => `${show(fromKey(key))}: removed after the analysis (was ${was}),${WHY}`);
|
|
174
|
+
var removedSince = (rows, before, noted) => {
|
|
175
|
+
const now = new Set(rows.map(keyOf));
|
|
176
|
+
return [...before].filter(([key]) => !now.has(key) && !noted(fromKey(key).cell)).map(
|
|
177
|
+
([key, was]) => `${show(fromKey(key))}: removed after the analysis (was ${was}),${WHY}`
|
|
178
|
+
);
|
|
228
179
|
};
|
|
229
|
-
/**
|
|
230
|
-
* Every cell whose label differs from what the analysis read at `rev` — changed, ADDED after it,
|
|
231
|
-
* or REMOVED since — and is not explained in a dated, quoted note naming the cell.
|
|
232
|
-
*/
|
|
233
180
|
function relabelProblems(labelsFile, rev, notesFile, rows) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return [
|
|
237
|
-
`${labelsFile} does not exist at ${rev}: name the revision the analysis read`,
|
|
238
|
-
];
|
|
239
|
-
const sections = datedSections(notesFile);
|
|
240
|
-
const noted = (cell) => sections.some((s) => s.includes(cell) && /^> \S/m.test(s));
|
|
181
|
+
const before = labelsAt(labelsFile, rev);
|
|
182
|
+
if (!before)
|
|
241
183
|
return [
|
|
242
|
-
|
|
243
|
-
...removedSince(rows, before, noted),
|
|
184
|
+
`${labelsFile} does not exist at ${rev}: name the revision the analysis read`
|
|
244
185
|
];
|
|
186
|
+
const sections = datedSections(notesFile);
|
|
187
|
+
const noted = (cell) => sections.some((s) => s.includes(cell) && /^> \S/m.test(s));
|
|
188
|
+
return [
|
|
189
|
+
...touchedSince(rows, before, noted),
|
|
190
|
+
...removedSince(rows, before, noted)
|
|
191
|
+
];
|
|
245
192
|
}
|
|
246
|
-
/** Cells a file labels more than once, with the lines. */
|
|
247
193
|
function duplicates(file, rows) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
194
|
+
const seen = /* @__PURE__ */ new Map();
|
|
195
|
+
rows.forEach((r) => seen.set(keyOf(r), [...seen.get(keyOf(r)) ?? [], r.n]));
|
|
196
|
+
return [...seen].filter(([, ns]) => ns.length > 1).map(
|
|
197
|
+
([k, ns]) => `${file}: ${show(fromKey(k))} is labelled ${String(ns.length)} times (lines ${ns.join(", ")})`
|
|
198
|
+
);
|
|
253
199
|
}
|
|
254
|
-
/** Rows naming a cell twice, and coverage against the ledger. */
|
|
255
200
|
function rowProblems(file, rows, ledger) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
.map((r) => `${show(r)}: a completed run with no label`),
|
|
269
|
-
]
|
|
270
|
-
: []),
|
|
271
|
-
];
|
|
201
|
+
const runs = ledger === void 0 ? null : ledgerCells(ledger);
|
|
202
|
+
const ran = new Set((runs ?? []).map(keyOf));
|
|
203
|
+
const labelled = new Set(rows.map(keyOf));
|
|
204
|
+
return [
|
|
205
|
+
...duplicates(file, rows),
|
|
206
|
+
...runs ? [
|
|
207
|
+
...rows.filter((r) => !ran.has(keyOf(r))).map(
|
|
208
|
+
(r) => `${file}:${String(r.n)}: ${show(r)} has no completed run in the ledger`
|
|
209
|
+
),
|
|
210
|
+
...runs.filter((r) => !labelled.has(keyOf(r))).map((r) => `${show(r)}: a completed run with no label`)
|
|
211
|
+
] : []
|
|
212
|
+
];
|
|
272
213
|
}
|
|
273
214
|
function validate(file, o) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (all.length)
|
|
288
|
-
refuse(1, all.join("\n"));
|
|
289
|
-
say(`${file}: ${String(rows.length)} labels, valid`);
|
|
215
|
+
const { rows, problems } = readLabels(file);
|
|
216
|
+
const book = codebookProblems(String(o.codebook), file);
|
|
217
|
+
const all = [
|
|
218
|
+
...problems,
|
|
219
|
+
...book.problems,
|
|
220
|
+
...rows.filter((r) => !book.known.has(r.label)).map(
|
|
221
|
+
(r) => `${file}:${String(r.n)}: "${r.label}" is not a codebook label`
|
|
222
|
+
),
|
|
223
|
+
...rowProblems(file, rows, o.ledger),
|
|
224
|
+
...o["analysed-at"] === void 0 ? [] : relabelProblems(file, o["analysed-at"], String(o.notes), rows)
|
|
225
|
+
];
|
|
226
|
+
if (all.length) refuse(1, all.join("\n"));
|
|
227
|
+
say(`${file}: ${String(rows.length)} labels, valid`);
|
|
290
228
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const half = (Z * Math.sqrt((p * (1 - p)) / n + (Z * Z) / (4 * n * n))) / denom;
|
|
299
|
-
return [centre - half, centre + half];
|
|
229
|
+
var Z = 1.959963984540054;
|
|
230
|
+
var wilson = (k, n) => {
|
|
231
|
+
const p = k / n;
|
|
232
|
+
const denom = 1 + Z * Z / n;
|
|
233
|
+
const centre = (p + Z * Z / (2 * n)) / denom;
|
|
234
|
+
const half = Z * Math.sqrt(p * (1 - p) / n + Z * Z / (4 * n * n)) / denom;
|
|
235
|
+
return [centre - half, centre + half];
|
|
300
236
|
};
|
|
301
|
-
/** Cohen's kappa over paired labels; null when chance agreement is 1 (one label only). */
|
|
302
237
|
function cohenKappa(pairs) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
238
|
+
const n = pairs.length;
|
|
239
|
+
const po = pairs.filter(([a, b]) => a === b).length / n;
|
|
240
|
+
const labels = [...new Set(pairs.flat())];
|
|
241
|
+
const share = (i, l) => pairs.filter((p) => p[i] === l).length / n;
|
|
242
|
+
const pe = labels.reduce((s, l) => s + share(0, l) * share(1, l), 0);
|
|
243
|
+
return pe === 1 ? null : (po - pe) / (1 - pe);
|
|
309
244
|
}
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
.map((r) => `${show(r)}: only in ${fileA}`),
|
|
318
|
-
...b
|
|
319
|
-
.filter((r) => !inA.has(keyOf(r)))
|
|
320
|
-
.map((r) => `${show(r)}: only in ${fileB}`),
|
|
321
|
-
];
|
|
245
|
+
var onlyIn = (fileA, a, b, fileB) => {
|
|
246
|
+
const inA = new Set(a.map(keyOf));
|
|
247
|
+
const inB = new Set(b.map(keyOf));
|
|
248
|
+
return [
|
|
249
|
+
...a.filter((r) => !inB.has(keyOf(r))).map((r) => `${show(r)}: only in ${fileA}`),
|
|
250
|
+
...b.filter((r) => !inA.has(keyOf(r))).map((r) => `${show(r)}: only in ${fileB}`)
|
|
251
|
+
];
|
|
322
252
|
};
|
|
323
|
-
/** The second file's label for each cell of the first; a refusal when the cells differ. */
|
|
324
253
|
function matched(fileA, fileB) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
254
|
+
const a = readLabels(fileA);
|
|
255
|
+
const b = readLabels(fileB);
|
|
256
|
+
const bad = [
|
|
257
|
+
...a.problems,
|
|
258
|
+
...b.problems,
|
|
259
|
+
...duplicates(fileA, a.rows),
|
|
260
|
+
...duplicates(fileB, b.rows)
|
|
261
|
+
];
|
|
262
|
+
if (bad.length) refuse(1, bad.join("\n"));
|
|
263
|
+
const inB = new Map(b.rows.map((r) => [keyOf(r), r.label]));
|
|
264
|
+
const unmatched = onlyIn(fileA, a.rows, b.rows, fileB);
|
|
265
|
+
if (unmatched.length)
|
|
266
|
+
refuse(
|
|
267
|
+
1,
|
|
268
|
+
`the two files label different cells \u2014 rate the same runs:
|
|
269
|
+
${unmatched.join("\n")}`
|
|
270
|
+
);
|
|
271
|
+
if (a.rows.length === 0) refuse(1, "no labels to compare");
|
|
272
|
+
return a.rows.map((r) => [r, String(inB.get(keyOf(r)))]);
|
|
343
273
|
}
|
|
344
274
|
function agree(fileA, fileB) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
275
|
+
const rows = matched(fileA, fileB);
|
|
276
|
+
const pairs = rows.map(([r, other]) => [r.label, other]);
|
|
277
|
+
const n = pairs.length;
|
|
278
|
+
const k = pairs.filter(([x, y]) => x === y).length;
|
|
279
|
+
const [lo, hi] = wilson(k, n);
|
|
280
|
+
const kappa = cohenKappa(pairs);
|
|
281
|
+
const f = (x) => x.toFixed(3);
|
|
282
|
+
say(
|
|
283
|
+
[
|
|
284
|
+
`n ${String(n)}`,
|
|
285
|
+
`agreement ${String(k)}/${String(n)} = ${f(k / n)} (95% Wilson ${f(lo)}\u2013${f(hi)})`,
|
|
286
|
+
`cohen kappa ${kappa === null ? "undefined (one label only)" : f(kappa)}`,
|
|
287
|
+
...rows.filter(([r, other]) => r.label !== other).map(([r, other]) => `disagree ${show(r)}: ${r.label} | ${other}`)
|
|
288
|
+
].join("\n")
|
|
289
|
+
);
|
|
360
290
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
notes: { type: "string" },
|
|
291
|
+
var OPTIONS = {
|
|
292
|
+
codebook: { type: "string" },
|
|
293
|
+
ledger: { type: "string" },
|
|
294
|
+
"analysed-at": { type: "string" },
|
|
295
|
+
notes: { type: "string" }
|
|
367
296
|
};
|
|
368
|
-
|
|
297
|
+
var USAGE = "usage: labels.js validate <labels.tsv> --codebook <f> [--ledger <f>] [--analysed-at <rev> --notes <f>] | agree <a.tsv> <b.tsv>";
|
|
369
298
|
function main() {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
validate(String(paths[0]), values);
|
|
385
|
-
else if (cmd === COMMANDS.agree && paths.length === 2)
|
|
386
|
-
agree(String(paths[0]), String(paths[1]));
|
|
387
|
-
else
|
|
388
|
-
refuse(2, USAGE);
|
|
299
|
+
const { values, positionals } = (() => {
|
|
300
|
+
try {
|
|
301
|
+
return parseArgs({ options: OPTIONS, allowPositionals: true });
|
|
302
|
+
} catch (e) {
|
|
303
|
+
return refuse(2, `${String(prop(e, "message"))}
|
|
304
|
+
${USAGE}`);
|
|
305
|
+
}
|
|
306
|
+
})();
|
|
307
|
+
const [cmd, ...paths] = positionals;
|
|
308
|
+
const validateOk = cmd === COMMANDS.validate && paths.length === 1 && values.codebook !== void 0 && (values["analysed-at"] === void 0 || values.notes !== void 0);
|
|
309
|
+
if (validateOk) validate(String(paths[0]), values);
|
|
310
|
+
else if (cmd === COMMANDS.agree && paths.length === 2)
|
|
311
|
+
agree(String(paths[0]), String(paths[1]));
|
|
312
|
+
else refuse(2, USAGE);
|
|
389
313
|
}
|
|
390
314
|
try {
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
315
|
+
main();
|
|
316
|
+
} catch (e) {
|
|
317
|
+
process.stderr.write(`labels: ${String(prop(e, "message"))}
|
|
318
|
+
`);
|
|
319
|
+
process.exitCode = e instanceof Refusal ? e.exitCode : 1;
|
|
396
320
|
}
|