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.
Files changed (165) hide show
  1. package/.claude-plugin/marketplace.json +11 -0
  2. package/.claude-plugin/plugin.json +7 -0
  3. package/CLAUDE.md +3 -3
  4. package/CONTRIBUTING.md +5 -2
  5. package/README.md +6 -6
  6. package/dist/adapters/clack/index.d.ts +3 -0
  7. package/dist/adapters/clack/index.d.ts.map +1 -0
  8. package/dist/adapters/clack/index.js +3 -0
  9. package/dist/adapters/clack/index.js.map +1 -0
  10. package/dist/adapters/clack/prompts.io.d.ts +8 -0
  11. package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
  12. package/dist/adapters/clack/prompts.io.js +20 -0
  13. package/dist/adapters/clack/prompts.io.js.map +1 -0
  14. package/dist/adapters/claude-code/claude.io.d.ts +13 -0
  15. package/dist/adapters/claude-code/claude.io.d.ts.map +1 -0
  16. package/dist/adapters/claude-code/claude.io.js +68 -0
  17. package/dist/adapters/claude-code/claude.io.js.map +1 -0
  18. package/dist/adapters/claude-code/index.d.ts +4 -0
  19. package/dist/adapters/claude-code/index.d.ts.map +1 -0
  20. package/dist/adapters/claude-code/index.js +4 -0
  21. package/dist/adapters/claude-code/index.js.map +1 -0
  22. package/dist/adapters/claude-code/plugin.d.ts +19 -0
  23. package/dist/adapters/claude-code/plugin.d.ts.map +1 -0
  24. package/dist/adapters/claude-code/plugin.js +66 -0
  25. package/dist/adapters/claude-code/plugin.js.map +1 -0
  26. package/dist/adapters/package-manager/index.d.ts +4 -0
  27. package/dist/adapters/package-manager/index.d.ts.map +1 -0
  28. package/dist/adapters/package-manager/index.js +4 -0
  29. package/dist/adapters/package-manager/index.js.map +1 -0
  30. package/dist/adapters/package-manager/install.io.d.ts +3 -0
  31. package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
  32. package/dist/adapters/package-manager/install.io.js +23 -0
  33. package/dist/adapters/package-manager/install.io.js.map +1 -0
  34. package/dist/adapters/package-manager/manager.d.ts +13 -0
  35. package/dist/adapters/package-manager/manager.d.ts.map +1 -0
  36. package/dist/adapters/package-manager/manager.js +22 -0
  37. package/dist/adapters/package-manager/manager.js.map +1 -0
  38. package/dist/adapters/study-registry/index.d.ts +2 -2
  39. package/dist/cli.d.ts +9 -1
  40. package/dist/cli.d.ts.map +1 -1
  41. package/dist/cli.js +73 -13
  42. package/dist/cli.js.map +1 -1
  43. package/dist/doctor-plugin.d.ts +23 -0
  44. package/dist/doctor-plugin.d.ts.map +1 -0
  45. package/dist/doctor-plugin.js +56 -0
  46. package/dist/doctor-plugin.js.map +1 -0
  47. package/dist/doctor.d.ts +6 -1
  48. package/dist/doctor.d.ts.map +1 -1
  49. package/dist/doctor.js +69 -26
  50. package/dist/doctor.js.map +1 -1
  51. package/dist/hooks-settings.d.ts +18 -0
  52. package/dist/hooks-settings.d.ts.map +1 -1
  53. package/dist/hooks-settings.js +25 -0
  54. package/dist/hooks-settings.js.map +1 -1
  55. package/dist/init.d.ts +47 -16
  56. package/dist/init.d.ts.map +1 -1
  57. package/dist/init.js +231 -86
  58. package/dist/init.js.map +1 -1
  59. package/dist/link-skills.d.ts +15 -0
  60. package/dist/link-skills.d.ts.map +1 -1
  61. package/dist/link-skills.js +18 -1
  62. package/dist/link-skills.js.map +1 -1
  63. package/dist/plugin-offer.d.ts +73 -0
  64. package/dist/plugin-offer.d.ts.map +1 -0
  65. package/dist/plugin-offer.js +96 -0
  66. package/dist/plugin-offer.js.map +1 -0
  67. package/dist/ports/claude-code.d.ts +31 -0
  68. package/dist/ports/claude-code.d.ts.map +1 -0
  69. package/dist/ports/claude-code.js +2 -0
  70. package/dist/ports/claude-code.js.map +1 -0
  71. package/dist/ports/project-install.d.ts +19 -0
  72. package/dist/ports/project-install.d.ts.map +1 -0
  73. package/dist/ports/project-install.js +2 -0
  74. package/dist/ports/project-install.js.map +1 -0
  75. package/dist/ports/prompts.d.ts +31 -0
  76. package/dist/ports/prompts.d.ts.map +1 -0
  77. package/dist/ports/prompts.js +2 -0
  78. package/dist/ports/prompts.js.map +1 -0
  79. package/dist/self-install.d.ts +65 -0
  80. package/dist/self-install.d.ts.map +1 -0
  81. package/dist/self-install.js +145 -0
  82. package/dist/self-install.js.map +1 -0
  83. package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
  84. package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
  85. package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
  86. package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
  87. package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
  88. package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
  89. package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
  90. package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
  91. package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
  92. package/dist/types.d.ts +4 -0
  93. package/dist/types.d.ts.map +1 -1
  94. package/docs/e2e.md +10 -0
  95. package/docs/install.md +88 -29
  96. package/docs/prior-art/README.md +2 -0
  97. package/docs/prior-art/one-command-install.md +33 -0
  98. package/docs/prior-art/prompt-libraries.md +32 -0
  99. package/eslint.config.mjs +1 -0
  100. package/hooks/CLAUDE.md +2 -2
  101. package/hooks/CLAUDE.md.spec.ts +1 -1
  102. package/lib/skill-checks.mjs +13 -6
  103. package/lib/skill-checks.test.mjs +28 -15
  104. package/lib/skill-corpus.mjs +5 -2
  105. package/package.json +8 -3
  106. package/plugin/CLAUDE.md +22 -14
  107. package/plugin/CLAUDE.md.spec.ts +20 -12
  108. package/scripts/bundle-skills.test.ts +226 -0
  109. package/scripts/bundle-skills.ts +304 -0
  110. package/scripts/plugin-version.test.ts +80 -0
  111. package/scripts/plugin-version.ts +58 -0
  112. package/skills/CLAUDE.md +2 -2
  113. package/skills/CLAUDE.md.spec.ts +1 -1
  114. package/skills/argument-arc/SKILL.md +2 -2
  115. package/skills/argument-arc/SKILL.md.spec.ts +1 -1
  116. package/skills/argument-arc/scripts/headings.js +57 -13
  117. package/skills/build-label-page/scripts/label-page.js +2005 -93
  118. package/skills/cold-read-diff/scripts/cold-read.js +221 -14
  119. package/skills/label-agent-runs/scripts/labels.js +272 -348
  120. package/skills/paper-pipeline/references/anonymization.md +4 -3
  121. package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
  122. package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
  123. package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
  124. package/skills/submit-paper/SKILL.md +5 -4
  125. package/skills/submit-paper/SKILL.md.spec.ts +4 -3
  126. package/skills/submit-paper/check-deanon.sh +17 -2
  127. package/skills/submit-paper/check-deanon.test.ts +141 -0
  128. package/skills/verify-citations/SKILL.md +9 -9
  129. package/skills/verify-citations/SKILL.md.spec.ts +8 -8
  130. package/skills/verify-citations/scripts/bib-authors.js +228 -0
  131. package/skills/verify-citations/scripts/verify-cites.js +816 -0
  132. package/src/adapters/clack/index.ts +2 -0
  133. package/src/adapters/clack/prompts.io.ts +35 -0
  134. package/src/adapters/clack/prompts.test.ts +58 -0
  135. package/src/adapters/claude-code/claude.io.ts +103 -0
  136. package/src/adapters/claude-code/index.test.ts +233 -0
  137. package/src/adapters/claude-code/index.ts +11 -0
  138. package/src/adapters/claude-code/plugin.ts +82 -0
  139. package/src/adapters/package-manager/index.test.ts +67 -0
  140. package/src/adapters/package-manager/index.ts +3 -0
  141. package/src/adapters/package-manager/install.io.ts +27 -0
  142. package/src/adapters/package-manager/manager.ts +33 -0
  143. package/src/cli.harness.mjs +47 -26
  144. package/src/cli.test.ts +179 -2
  145. package/src/cli.ts +130 -10
  146. package/src/doctor-plugin.test.ts +103 -0
  147. package/src/doctor-plugin.ts +83 -0
  148. package/src/doctor.test.ts +111 -2
  149. package/src/doctor.ts +83 -32
  150. package/src/hooks-notice.test.ts +82 -0
  151. package/src/hooks-settings.ts +49 -0
  152. package/src/init-plugin.test.ts +178 -0
  153. package/src/init.test.ts +138 -27
  154. package/src/init.ts +341 -124
  155. package/src/link-skills.test.ts +34 -1
  156. package/src/link-skills.ts +34 -0
  157. package/src/parse-args.test.ts +2 -0
  158. package/src/plugin-offer.test.ts +276 -0
  159. package/src/plugin-offer.ts +160 -0
  160. package/src/ports/claude-code.ts +30 -0
  161. package/src/ports/project-install.ts +18 -0
  162. package/src/ports/prompts.ts +27 -0
  163. package/src/self-install.test.ts +267 -0
  164. package/src/self-install.ts +224 -0
  165. package/src/types.ts +4 -0
@@ -1,396 +1,320 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * labels — the checks of the label-agent-runs skill.
4
- *
5
- * validate <labels.tsv> --codebook <codebook.json> [--ledger <attempts.jsonl>]
6
- * [--analysed-at <git rev> --notes <notes.md>]
7
- * The label file is well formed, uses only codebook labels, names each cell once, and —
8
- * with a ledger — covers exactly the completed runs. The codebook is committed, unchanged,
9
- * and was committed no later than the label file. With --analysed-at: every cell whose
10
- * label differs from that revision is explained in a dated section of the notes, with a
11
- * verbatim quote.
12
- * agree <a.tsv> <b.tsv>
13
- * Agreement between two label files over the same cells: n, percent agreement with a 95%
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
- import { z } from "zod";
30
- import { COMMANDS } from "./labels-commands.js";
31
- class Refusal extends Error {
32
- exitCode;
33
- constructor(exitCode, message) {
34
- super(message);
35
- this.exitCode = exitCode;
36
- }
37
- }
38
- const refuse = (exitCode, message) => {
39
- throw new Refusal(exitCode, message);
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
- const say = (line) => {
42
- process.stdout.write(`${line}\n`);
36
+ var say = (line) => {
37
+ process.stdout.write(`${line}
38
+ `);
43
39
  };
44
- const prop = (e, key) => Reflect.get(Object(e), key);
45
- const HEADER = ["agent", "model", "cell", "label"];
46
- const keyOf = (r) => `${r.agent}\t${r.model}\t${r.cell}`;
47
- const show = (r) => `${r.agent} ${r.model} ${r.cell}`;
48
- /** A line with exactly four fields as a row; anything else is not one. */
49
- const asRow = ({ fields, n }) => {
50
- const [agent, model, cell, label] = fields;
51
- return fields.length === 4
52
- ? [
53
- {
54
- agent: String(agent),
55
- model: String(model),
56
- cell: String(cell),
57
- label: String(label),
58
- n,
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
- const [first, ...body] = readFileSync(file, "utf8").split("\n");
66
- const lines = body
67
- .map((line, i) => ({ line, fields: line.split("\t"), n: i + 2 }))
68
- .filter(({ line }) => line.trim() !== "");
69
- const headerOk = String(first).replace(/\r$/, "") === HEADER.join("\t");
70
- return {
71
- rows: lines.flatMap(asRow),
72
- problems: [
73
- ...(headerOk
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
- const git = (cwd, ...args) => spawnSync("git", ["-C", cwd, ...args], { encoding: "utf8" });
83
- /** Where `abs` sits in its git repository, or null outside one. */
84
- const repoPath = (abs) => {
85
- const top = git(dirname(abs), "rev-parse", "--show-toplevel");
86
- return top.status === 0
87
- ? {
88
- top: top.stdout.trim(),
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
- /** Unix times of the commits that touched `abs` — only the ones that ADDED it, with `added`. */
94
- const commitTimes = (abs, added) => {
95
- const at = repoPath(abs);
96
- const filter = added ? ["--diff-filter=A"] : [];
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
- const Codebook = z.looseObject({
106
- labels: z
107
- .array(z.looseObject({
108
- id: z.unknown().optional(),
109
- definition: z.unknown().optional(),
110
- borderline: z.unknown().optional(),
111
- }))
112
- .default([]),
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
- const filled = (v) => typeof v === "string" && v.trim() !== "";
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
- const at = repoPath(abs);
118
- const head = at ? git(at.top, "show", `HEAD:${at.rel}`) : null;
119
- if (!head || head.status !== 0)
120
- return [
121
- `${file} is not committed: commit the codebook before the first label`,
122
- ];
123
- return head.stdout === text
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
- /** Labels that lack an id, a definition or a borderline example. */
130
- const incomplete = (file, labels) => labels
131
- .filter((l) => !(filled(l.id) && filled(l.definition) && filled(l.borderline)))
132
- .map((l) => `${file}: label "${String(l.id)}" needs an id, a definition and a borderline example`);
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
- const abs = resolve(file);
135
- const text = readFileSync(abs, "utf8");
136
- const { labels } = Codebook.parse(JSON.parse(text));
137
- // EVERY commit of the codebook, not only the one that added it: an edit after labelling began
138
- // changes what the labels already given mean.
139
- const bookLast = Math.max(-Infinity, ...commitTimes(abs, false));
140
- const labelsFirst = Math.min(Infinity, ...commitTimes(resolve(labelsFile), true));
141
- const late = bookLast > labelsFirst;
142
- return {
143
- known: new Set(labels.map((l) => l.id)),
144
- problems: [
145
- ...committedProblem(file, abs, text),
146
- ...(labels.length ? [] : [`${file} defines no labels`]),
147
- ...incomplete(file, labels),
148
- ...(late
149
- ? [
150
- `${file} was committed after ${labelsFile} was first committed: the codebook is fixed before labelling; a changed codebook needs a new label file`,
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
- const Attempt = z.looseObject({
157
- attempt: z.string(),
158
- agent: z.string().optional(),
159
- model: z.string().optional(),
160
- unit: z.string().optional(),
161
- arm: z.string().optional(),
162
- seed: z.union([z.string(), z.number()]).optional(),
163
- status: z.string().optional(),
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
- const byId = new Map();
168
- readFileSync(file, "utf8")
169
- .split("\n")
170
- .filter((l) => l.trim())
171
- .map((l) => Attempt.parse(JSON.parse(l)))
172
- .forEach((r) => {
173
- byId.set(r.attempt, { ...byId.get(r.attempt), ...r });
174
- });
175
- return [...byId.values()]
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
- const at = repoPath(resolve(labelsFile));
186
- const then = at ? git(at.top, "show", `${rev}:${at.rel}`) : null;
187
- if (!then || then.status !== 0)
188
- return null;
189
- return new Map(then.stdout
190
- .split("\n")
191
- .slice(1)
192
- .filter((l) => l.trim())
193
- .map((l) => l.split("\t"))
194
- .map(([agent, model, cell, label]) => [
195
- keyOf({
196
- agent: String(agent),
197
- model: String(model),
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
- /** The sections of the notes under a "## YYYY-MM-DD" heading, each up to the next "## ". */
204
- const datedSections = (notesFile) => readFileSync(notesFile, "utf8")
205
- .split(/^(?=## )/m)
206
- .filter((s) => /^## \d{4}-\d{2}-\d{2}\b/.test(s));
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
- const WHY = " with no dated note quoting the run";
213
- /** Rows whose label is new or different since the analysis, and not explained. */
214
- const touchedSince = (rows, before, noted) => rows
215
- .filter((r) => before.get(keyOf(r)) !== r.label && !noted(r.cell))
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
- /** Cells the analysis read that are gone now, and not explained. */
223
- const removedSince = (rows, before, noted) => {
224
- const now = new Set(rows.map(keyOf));
225
- return [...before]
226
- .filter(([key]) => !now.has(key) && !noted(fromKey(key).cell))
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
- const before = labelsAt(labelsFile, rev);
235
- if (!before)
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
- ...touchedSince(rows, before, noted),
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
- const seen = new Map();
249
- rows.forEach((r) => seen.set(keyOf(r), [...(seen.get(keyOf(r)) ?? []), r.n]));
250
- return [...seen]
251
- .filter(([, ns]) => ns.length > 1)
252
- .map(([k, ns]) => `${file}: ${show(fromKey(k))} is labelled ${String(ns.length)} times (lines ${ns.join(", ")})`);
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
- const runs = ledger === undefined ? null : ledgerCells(ledger);
257
- const ran = new Set((runs ?? []).map(keyOf));
258
- const labelled = new Set(rows.map(keyOf));
259
- return [
260
- ...duplicates(file, rows),
261
- ...(runs
262
- ? [
263
- ...rows
264
- .filter((r) => !ran.has(keyOf(r)))
265
- .map((r) => `${file}:${String(r.n)}: ${show(r)} has no completed run in the ledger`),
266
- ...runs
267
- .filter((r) => !labelled.has(keyOf(r)))
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
- const { rows, problems } = readLabels(file);
275
- const book = codebookProblems(String(o.codebook), file);
276
- const all = [
277
- ...problems,
278
- ...book.problems,
279
- ...rows
280
- .filter((r) => !book.known.has(r.label))
281
- .map((r) => `${file}:${String(r.n)}: "${r.label}" is not a codebook label`),
282
- ...rowProblems(file, rows, o.ledger),
283
- ...(o["analysed-at"] === undefined
284
- ? []
285
- : relabelProblems(file, o["analysed-at"], String(o.notes), rows)),
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
- // ── agreement ───────────────────────────────────────────────────────────────────────────────
292
- const Z = 1.959963984540054;
293
- /** 95% Wilson score interval for k successes in n. */
294
- const wilson = (k, n) => {
295
- const p = k / n;
296
- const denom = 1 + (Z * Z) / n;
297
- const centre = (p + (Z * Z) / (2 * n)) / denom;
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
- const n = pairs.length;
304
- const po = pairs.filter(([a, b]) => a === b).length / n;
305
- const labels = [...new Set(pairs.flat())];
306
- const share = (i, l) => pairs.filter((p) => p[i] === l).length / n;
307
- const pe = labels.reduce((s, l) => s + share(0, l) * share(1, l), 0);
308
- return pe === 1 ? null : (po - pe) / (1 - pe);
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
- /** Cells of either file that the other does not label. */
311
- const onlyIn = (fileA, a, b, fileB) => {
312
- const inA = new Set(a.map(keyOf));
313
- const inB = new Set(b.map(keyOf));
314
- return [
315
- ...a
316
- .filter((r) => !inB.has(keyOf(r)))
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
- const a = readLabels(fileA);
326
- const b = readLabels(fileB);
327
- // A cell labelled twice has no single label to compare: refused before any statistic.
328
- const bad = [
329
- ...a.problems,
330
- ...b.problems,
331
- ...duplicates(fileA, a.rows),
332
- ...duplicates(fileB, b.rows),
333
- ];
334
- if (bad.length)
335
- refuse(1, bad.join("\n"));
336
- const inB = new Map(b.rows.map((r) => [keyOf(r), r.label]));
337
- const unmatched = onlyIn(fileA, a.rows, b.rows, fileB);
338
- if (unmatched.length)
339
- refuse(1, `the two files label different cells — rate the same runs:\n${unmatched.join("\n")}`);
340
- if (a.rows.length === 0)
341
- refuse(1, "no labels to compare");
342
- return a.rows.map((r) => [r, String(inB.get(keyOf(r)))]);
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
- const rows = matched(fileA, fileB);
346
- const pairs = rows.map(([r, other]) => [r.label, other]);
347
- const n = pairs.length;
348
- const k = pairs.filter(([x, y]) => x === y).length;
349
- const [lo, hi] = wilson(k, n);
350
- const kappa = cohenKappa(pairs);
351
- const f = (x) => x.toFixed(3);
352
- say([
353
- `n ${String(n)}`,
354
- `agreement ${String(k)}/${String(n)} = ${f(k / n)} (95% Wilson ${f(lo)}–${f(hi)})`,
355
- `cohen kappa ${kappa === null ? "undefined (one label only)" : f(kappa)}`,
356
- ...rows
357
- .filter(([r, other]) => r.label !== other)
358
- .map(([r, other]) => `disagree ${show(r)}: ${r.label} | ${other}`),
359
- ].join("\n"));
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
- // ── command line ────────────────────────────────────────────────────────────────────────────
362
- const OPTIONS = {
363
- codebook: { type: "string" },
364
- ledger: { type: "string" },
365
- "analysed-at": { type: "string" },
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
- const USAGE = "usage: labels.js validate <labels.tsv> --codebook <f> [--ledger <f>] [--analysed-at <rev> --notes <f>] | agree <a.tsv> <b.tsv>";
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
- const { values, positionals } = (() => {
371
- try {
372
- return parseArgs({ options: OPTIONS, allowPositionals: true });
373
- }
374
- catch (e) {
375
- return refuse(2, `${String(prop(e, "message"))}\n${USAGE}`);
376
- }
377
- })();
378
- const [cmd, ...paths] = positionals;
379
- const validateOk = cmd === COMMANDS.validate &&
380
- paths.length === 1 &&
381
- values.codebook !== undefined &&
382
- (values["analysed-at"] === undefined || values.notes !== undefined);
383
- if (validateOk)
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
- main();
392
- }
393
- catch (e) {
394
- process.stderr.write(`labels: ${String(prop(e, "message"))}\n`);
395
- process.exitCode = e instanceof Refusal ? e.exitCode : 1;
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
  }