@chrono-meta/fh-gate 3.10.0 → 3.12.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/regression/probes_live.yaml +13 -5
- package/.claude-plugin/marketplace.json +4 -4
- package/AGENTS.md +1 -1
- package/CHEATSHEET.md +1 -1
- package/CLAUDE.md +8 -4
- package/bin/fh-codex-doctor.js +223 -25
- package/docs/codex-compat.md +1 -1
- package/knowledge/shared/harness-core/claude_md_gate_details.md +8 -4
- package/knowledge/shared/harness-core/governance_engineering_definition.md +403 -7
- package/knowledge/shared/harness-core/harness_terminal_correlation_and_recommendations.md +22 -6
- package/knowledge/shared/learnings/subagent_invocations_log.yaml +107 -0
- package/package.json +11 -2
- package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-commons/README.md +1 -1
- package/plugins/fh-commons/skills/ko-tech-writer/SKILL.md +269 -26
- package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/CHANGELOG.md +44 -0
- package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
- package/scripts/citation_key_check.py +357 -0
- package/scripts/claim_propagation_scan.py +499 -0
- package/scripts/ko_tech_writer_calibrate.py +13 -4
- package/scripts/numeric_token_diff.py +389 -0
- package/scripts/probe_live_eval_lib.py +19 -1
- package/scripts/section_ref_check.py +591 -0
- package/scripts/selfcheck.sh +72 -0
- package/scripts/session_checklist.py +704 -0
- package/scripts/test_claim_propagation_lanes.sh +573 -0
- package/scripts/test_codex_doctor_root_lanes.sh +384 -0
- package/scripts/test_ko_tech_writer_lanes.sh +5 -1
- package/scripts/test_paper_integrity_lanes.sh +1473 -0
- package/scripts/test_probe_live_eval_lanes.sh +25 -4
- package/scripts/test_session_checklist_lanes.sh +746 -0
- package/templates/predelete_check.sh +28 -4
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""citation_key_check.py — every citation key a paper USES is DEFINED, and every DEFINED key is USED.
|
|
3
|
+
|
|
4
|
+
WHAT IT CLOSES (measured 2026-09-17, paper-2 draft, the night the sister paper had been rejected by
|
|
5
|
+
arXiv for 11/17 reference mismatches)
|
|
6
|
+
The governor had to check citation-key integrity BY HAND with ad-hoc python. Two live defects that
|
|
7
|
+
night: `[EBP18]` was cited in §9.4 and had NO row in the references table (a PHANTOM), and `[MF24]`
|
|
8
|
+
was cited where the table's row read `[MF22]` — the arXiv-posting year had been used as the key
|
|
9
|
+
while the journal year is 2022 (a NEAR-MISS: same letters, different year). A plain used-vs-defined
|
|
10
|
+
diff reports that second case as one phantom PLUS one orphan and never says they are the same key,
|
|
11
|
+
so a renumbering can silently orphan the row and phantom the citation at once. This tool pairs them.
|
|
12
|
+
|
|
13
|
+
WHAT IT DOES NOT DO — read before trusting a 0
|
|
14
|
+
🟥 It checks KEY integrity, not bibliographic truth. A key that is used and defined can still point
|
|
15
|
+
at a row whose title, year, venue or DOI is wrong — that is `phantom-quench` / the refs table's
|
|
16
|
+
own «확인» column, not this tool.
|
|
17
|
+
🟥 Keys inside code spans (`[K26]`, fenced blocks) are MENTIONS, not citations — a paper's own
|
|
18
|
+
«citation verification» table names keys that way. They are counted separately and printed, never
|
|
19
|
+
silently dropped; `--count-code` turns them into usages if a body really cites in code style.
|
|
20
|
+
🟥 A definition row is recognised ONLY by the house table shape: the row's FIRST cell is `[KEY]`
|
|
21
|
+
(`| [C70] | Chow … |`, bold allowed). A bibliography written as a list is invisible → rc=10, not
|
|
22
|
+
«all phantom». The whole definition row is excluded from usage counting, so a paper that carries
|
|
23
|
+
its own table in the body still works (the row's note column is not scanned for usages).
|
|
24
|
+
🟥 Grouped citations `[C70, EW10, T24]` are split on `,` / `;`; every element that fully matches the
|
|
25
|
+
key grammar counts. An element that does not (`[C70, p. 41]` → `p. 41`) is ignored, not reported.
|
|
26
|
+
🟥 Keys in a --refs file OUTSIDE its definition rows are NOT usages unless that file is also passed
|
|
27
|
+
as --body (the drop-in prior-art section is both a body and the table — pass it as both).
|
|
28
|
+
|
|
29
|
+
KEY GRAMMAR (house style) [A-Z][A-Za-z]{0,6}\\d{2}[a-z]? e.g. [C70] [EBP18] [BES26a] [OCR26]
|
|
30
|
+
NEAR-MISS two DIFFERENT keys with the same letter prefix (case-insensitive), where at
|
|
31
|
+
least one side is PHANTOM or ORPHAN — [MF24]↔[MF22], [BES26]↔[BES26a].
|
|
32
|
+
Two keys both used and both defined are two papers, not a near-miss.
|
|
33
|
+
`--no-near-miss` disables the pairing (ablation / revert probe).
|
|
34
|
+
|
|
35
|
+
EXIT CODES
|
|
36
|
+
0 scanned, every used key defined, every defined key used (orphans listed but not counted)
|
|
37
|
+
1 PHANTOM (used, undefined) or DUP-DEF (one key defined twice)
|
|
38
|
+
2 no phantom, but ORPHAN keys present and --strict-orphans was given
|
|
39
|
+
4 DEAD CONTROL: the body yields ZERO citation usages — a paper with no citations is not
|
|
40
|
+
«clean», it is unscanned (mentions-only counts as zero). Distinct from 0 on purpose.
|
|
41
|
+
10 input error (file missing / unreadable · 0 definition rows parsed from the references table)
|
|
42
|
+
|
|
43
|
+
USAGE
|
|
44
|
+
python3 scripts/citation_key_check.py --body <md...> [--refs <md...>] [--strict-orphans]
|
|
45
|
+
[--count-code] [--no-near-miss] [--json]
|
|
46
|
+
bash scripts/test_paper_integrity_lanes.sh # known pairs + revert probe
|
|
47
|
+
Python ≥ 3.9, stdlib only.
|
|
48
|
+
"""
|
|
49
|
+
import argparse
|
|
50
|
+
import json
|
|
51
|
+
import os
|
|
52
|
+
import re
|
|
53
|
+
import sys
|
|
54
|
+
import unicodedata
|
|
55
|
+
|
|
56
|
+
KEY = r"[A-Z][A-Za-z]{0,6}\d{2}[a-z]?"
|
|
57
|
+
KEY_RE = re.compile(r"^" + KEY + r"$")
|
|
58
|
+
# 🟥 v3 (codex round 2, 2026-09-18): `[BAD–26]` — letters, a Unicode dash, digits — is a citation the
|
|
59
|
+
# reader SEES and the table cannot match, and v2 skipped it silently because it failed KEY_RE. A key
|
|
60
|
+
# with any dash/underscore between letters and year is MALFORMED: reported and counted, never
|
|
61
|
+
# normalized away (a typo the reader sees is a defect even when a human would guess the row).
|
|
62
|
+
MALFORMED_RE = re.compile(r"^[A-Z][A-Za-z]{0,6}[\-‐‑‒–—−_]\d{2}[a-z]?$")
|
|
63
|
+
# v10 (codex round 9): `[mf22]` — key-shaped but case-mismatched — cannot match the house table either
|
|
64
|
+
CASE_RE = re.compile(r"^[A-Za-z]{1,7}[\-‐‑‒–—−_]?\d{2}[A-Za-z]?$") # v11: `[BES26A]` too
|
|
65
|
+
BRACKET_RE = re.compile(r"\[([^\[\]\n]{1,160})\]")
|
|
66
|
+
# v7 (codex round 6): a definitions table inside a blockquote (`> | [KEY] | … |`) is still the visible table
|
|
67
|
+
DEF_ROW_RE = re.compile(r"^\s*(?:>\s*)*\|\s*(?:\*\*)?\[(" + KEY + r")\](?:\*\*)?\s*\|")
|
|
68
|
+
CODE_SPAN_RE = re.compile(r"`[^`\n]*`")
|
|
69
|
+
LETTERS_RE = re.compile(r"^([A-Za-z]+)\d{2}[a-z]?$")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def letters(key):
|
|
73
|
+
m = LETTERS_RE.match(key)
|
|
74
|
+
return m.group(1).lower() if m else key.lower()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _elements(text):
|
|
78
|
+
"""Bracket elements, NFKC-normalized (`[MF22]`-style full-width forms read as ASCII)."""
|
|
79
|
+
for m in BRACKET_RE.finditer(unicodedata.normalize("NFKC", text)):
|
|
80
|
+
for el in re.split(r"[,;&、·]|\s+and\s+", m.group(1)): # v14: `[AB24 & ZZ99]` · `[AB24 and ZZ99]` · v17: `[AB24、ZZ99]` · v18: `[AB24 · ZZ99]`
|
|
81
|
+
yield el.strip()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def keys_in(text):
|
|
85
|
+
"""Every key cited in `text`: single `[K26]` and grouped `[C70, EW10]` brackets."""
|
|
86
|
+
return [el for el in _elements(text) if KEY_RE.match(el)]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def malformed_in(text):
|
|
90
|
+
"""Citation-shaped bracket elements that are NOT keys (`[BAD–26]`, `[MF-22]`, `[GE_17]`, `[mf22]`)."""
|
|
91
|
+
return [el for el in _elements(text) if not KEY_RE.match(el) and (MALFORMED_RE.match(el) or CASE_RE.match(el))]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
CODE_SPAN_MASK_RE = re.compile(r"`[^`\n]*`")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
FENCE_RE = re.compile(r"^(?:>\s*)*(`{3,}|~{3,})(.*)$")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _fence_step(line, fence):
|
|
101
|
+
"""→ (fence_after, on_fence_line). `fence` = (char, opener length) while inside a fenced block, else
|
|
102
|
+
None. v9 (codex round 8) — CommonMark: a closer uses the same char, is at least as long as the
|
|
103
|
+
opener and carries nothing but spaces after it (a 3-tick line does not close a 4-tick fence); a
|
|
104
|
+
`> ` prefix is allowed (a fence inside a blockquote). Kept byte-identical across the three tools."""
|
|
105
|
+
m = FENCE_RE.match(line.lstrip())
|
|
106
|
+
if fence is None:
|
|
107
|
+
return ((m.group(1)[0], len(m.group(1))), True) if m else (None, False)
|
|
108
|
+
if m and m.group(1)[0] == fence[0] and len(m.group(1)) >= fence[1] and not m.group(2).strip():
|
|
109
|
+
return None, True
|
|
110
|
+
return fence, False
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def strip_html_comments(text):
|
|
114
|
+
"""v6 (codex round 5): text inside `<!-- … -->` is invisible to the reader, so it is neither a defect
|
|
115
|
+
nor an anchor. 🟥 v7 (codex round 6): the v6 regex strip ERASED PROSE between a `<!--` and a `-->`
|
|
116
|
+
that sat inside code spans or fenced blocks — a delimiter inside code is a literal. 🟥 v8 (codex
|
|
117
|
+
round 7): the same for `~~~` fences and 4-space / tab INDENTED code blocks (a block starts after a
|
|
118
|
+
blank line and runs while lines stay indented). v9: fences go through _fence_step (opener length ·
|
|
119
|
+
blockquote prefix). Fences and indented code are left untouched, code spans are masked before a
|
|
120
|
+
delimiter is looked for. Line numbers are preserved; comment text becomes spaces. Kept
|
|
121
|
+
byte-identical in the three tools (lanes L11l / L11o / L11q pin all three)."""
|
|
122
|
+
out, fence, in_comment, prev_blank, prev_code = [], None, False, True, False
|
|
123
|
+
for line in text.split("\n"):
|
|
124
|
+
if in_comment:
|
|
125
|
+
j = line.find("-->")
|
|
126
|
+
if j < 0:
|
|
127
|
+
out.append(" " * len(line))
|
|
128
|
+
continue
|
|
129
|
+
line, in_comment = " " * (j + 3) + line[j + 3:], False
|
|
130
|
+
s = line.strip()
|
|
131
|
+
fence, on_fence = _fence_step(line, fence)
|
|
132
|
+
if on_fence or fence is not None:
|
|
133
|
+
out.append(line)
|
|
134
|
+
prev_blank, prev_code = False, False
|
|
135
|
+
continue
|
|
136
|
+
indented = (line.startswith(" ") or line.startswith("\t")) and (prev_blank or prev_code)
|
|
137
|
+
if indented:
|
|
138
|
+
out.append(line)
|
|
139
|
+
prev_blank, prev_code = False, True
|
|
140
|
+
continue
|
|
141
|
+
prev_blank, prev_code = (s == ""), False
|
|
142
|
+
masked = CODE_SPAN_MASK_RE.sub(lambda m: " " * len(m.group(0)), line)
|
|
143
|
+
res, pos = [], 0
|
|
144
|
+
while True:
|
|
145
|
+
i = masked.find("<!--", pos)
|
|
146
|
+
if i < 0:
|
|
147
|
+
res.append(line[pos:])
|
|
148
|
+
break
|
|
149
|
+
res.append(line[pos:i])
|
|
150
|
+
j = line.find("-->", i + 4)
|
|
151
|
+
if j < 0:
|
|
152
|
+
res.append(" " * (len(line) - i))
|
|
153
|
+
in_comment = True
|
|
154
|
+
break
|
|
155
|
+
res.append(" " * (j + 3 - i))
|
|
156
|
+
pos = j + 3
|
|
157
|
+
out.append("".join(res))
|
|
158
|
+
return "\n".join(out)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def load(path):
|
|
162
|
+
try:
|
|
163
|
+
with open(path, encoding="utf-8", errors="replace") as fh:
|
|
164
|
+
return strip_html_comments(fh.read()).split("\n"), None
|
|
165
|
+
except OSError as e:
|
|
166
|
+
return None, str(e)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def scan_body(path, lines, count_code, used, mentions, malformed):
|
|
170
|
+
"""Fill used[key] / mentions[key] / malformed[element] with (file, line, snippet) sites. Definition
|
|
171
|
+
rows are skipped. MALFORMED elements are collected from prose only — inside a fence or a code span
|
|
172
|
+
they are text, like every other key there."""
|
|
173
|
+
fence = None # v8/v9: ``` and ~~~ fences via _fence_step (opener length · `> ` prefix)
|
|
174
|
+
for i, line in enumerate(lines, 1):
|
|
175
|
+
s = line.strip()
|
|
176
|
+
fence, on_fence = _fence_step(line, fence)
|
|
177
|
+
if on_fence:
|
|
178
|
+
continue
|
|
179
|
+
in_fence = fence is not None
|
|
180
|
+
if not in_fence and DEF_ROW_RE.match(line):
|
|
181
|
+
continue # a definition row is not a citation of itself
|
|
182
|
+
snippet = s[:110]
|
|
183
|
+
if in_fence and not count_code:
|
|
184
|
+
for k in keys_in(line):
|
|
185
|
+
mentions.setdefault(k, []).append((path, i, snippet))
|
|
186
|
+
continue
|
|
187
|
+
if count_code:
|
|
188
|
+
prose, code = line, ""
|
|
189
|
+
else:
|
|
190
|
+
prose = CODE_SPAN_RE.sub(" ", line)
|
|
191
|
+
code = " ".join(CODE_SPAN_RE.findall(line))
|
|
192
|
+
for k in keys_in(prose):
|
|
193
|
+
used.setdefault(k, []).append((path, i, snippet))
|
|
194
|
+
for k in malformed_in(prose):
|
|
195
|
+
malformed.setdefault(k, []).append((path, i, snippet))
|
|
196
|
+
for k in keys_in(code):
|
|
197
|
+
mentions.setdefault(k, []).append((path, i, snippet))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def scan_defs(path, lines, defined):
|
|
201
|
+
"""🟥 v8 (codex round 7): a `| [KEY] |` row INSIDE a code fence is code, not a definition — v7 counted
|
|
202
|
+
it, so a key whose only «definition» was a quoted table read as defined."""
|
|
203
|
+
fence = None
|
|
204
|
+
for i, line in enumerate(lines, 1):
|
|
205
|
+
fence, on_fence = _fence_step(line, fence)
|
|
206
|
+
if on_fence or fence is not None:
|
|
207
|
+
continue
|
|
208
|
+
m = DEF_ROW_RE.match(line)
|
|
209
|
+
if m:
|
|
210
|
+
defined.setdefault(m.group(1), []).append((path, i))
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def near_miss_pairs(phantom, orphan, used, defined):
|
|
214
|
+
problematic = set(phantom) | set(orphan)
|
|
215
|
+
pool = set(used) | set(defined)
|
|
216
|
+
pairs = {}
|
|
217
|
+
for x in sorted(problematic):
|
|
218
|
+
for y in sorted(pool):
|
|
219
|
+
if y == x or letters(x) != letters(y):
|
|
220
|
+
continue
|
|
221
|
+
a, b = sorted((x, y))
|
|
222
|
+
pairs[(a, b)] = True
|
|
223
|
+
return sorted(pairs)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def role(k, phantom, orphan, used, defined):
|
|
227
|
+
tags = []
|
|
228
|
+
if k in phantom:
|
|
229
|
+
tags.append("PHANTOM")
|
|
230
|
+
if k in orphan:
|
|
231
|
+
tags.append("ORPHAN")
|
|
232
|
+
if not tags:
|
|
233
|
+
tags.append("ok")
|
|
234
|
+
if k in used:
|
|
235
|
+
tags.append("used ×%d" % len(used[k]))
|
|
236
|
+
if k in defined:
|
|
237
|
+
tags.append("defined %s" % ", ".join("%s:%d" % (os.path.basename(f), n) for f, n in defined[k]))
|
|
238
|
+
return " · ".join(tags)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def main():
|
|
242
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
243
|
+
ap.add_argument("--body", nargs="+", required=True, metavar="MD", help="body file(s) whose citations are checked")
|
|
244
|
+
ap.add_argument("--refs", nargs="*", default=[], metavar="MD",
|
|
245
|
+
help="file(s) carrying the references table (`| [KEY] | … |`); definition rows found in --body files count too")
|
|
246
|
+
ap.add_argument("--strict-orphans", action="store_true", help="a defined-but-unused key fails (rc=2)")
|
|
247
|
+
ap.add_argument("--count-code", action="store_true", help="keys inside code spans / fences count as usages, not mentions")
|
|
248
|
+
ap.add_argument("--no-near-miss", action="store_true", help="disable NEAR-MISS pairing (ablation / revert probe)")
|
|
249
|
+
ap.add_argument("--no-malformed", action="store_true",
|
|
250
|
+
help="ABLATION ONLY: skip MALFORMED keys (`[BAD–26]`) — the v2 arm, where they read as clean")
|
|
251
|
+
ap.add_argument("--max-sites", type=int, default=6, help="usage sites printed per phantom key (0 = all)")
|
|
252
|
+
ap.add_argument("--json", action="store_true")
|
|
253
|
+
args = ap.parse_args()
|
|
254
|
+
|
|
255
|
+
files = {}
|
|
256
|
+
for p in list(args.body) + list(args.refs):
|
|
257
|
+
if p in files:
|
|
258
|
+
continue
|
|
259
|
+
lines, err = load(p)
|
|
260
|
+
if lines is None:
|
|
261
|
+
print("🟥 cannot read %s: %s" % (p, err), file=sys.stderr)
|
|
262
|
+
return 10
|
|
263
|
+
files[p] = lines
|
|
264
|
+
|
|
265
|
+
used, mentions, defined, malformed = {}, {}, {}, {}
|
|
266
|
+
for p in args.body:
|
|
267
|
+
scan_body(p, files[p], args.count_code, used, mentions, malformed)
|
|
268
|
+
if args.no_malformed:
|
|
269
|
+
malformed = {}
|
|
270
|
+
for p in dict.fromkeys(list(args.refs) + list(args.body)):
|
|
271
|
+
scan_defs(p, files[p], defined)
|
|
272
|
+
|
|
273
|
+
if not defined:
|
|
274
|
+
print("🟥 0 definition rows parsed from %s — wrong file or wrong shape (expected a table row whose FIRST "
|
|
275
|
+
"cell is `[KEY]`). %d usage(s) of %d key(s) were seen and are NOT reported as phantom. rc=10"
|
|
276
|
+
% (", ".join(args.refs) if args.refs else "the body (no --refs given)",
|
|
277
|
+
sum(len(v) for v in used.values()), len(used)))
|
|
278
|
+
return 10
|
|
279
|
+
n_usages = sum(len(v) for v in used.values())
|
|
280
|
+
n_ment = sum(len(v) for v in mentions.values())
|
|
281
|
+
if n_usages == 0 and not malformed:
|
|
282
|
+
print("⬜ DEAD CONTROL — 0 citation usages in %d body file(s) (%d line(s) read; %d mention(s) in code spans "
|
|
283
|
+
"not counted); %d definition(s) present but NOTHING was checked. rc=4 (not a clean check)."
|
|
284
|
+
% (len(args.body), sum(len(files[p]) for p in args.body), n_ment, len(defined)))
|
|
285
|
+
return 4
|
|
286
|
+
|
|
287
|
+
phantom = sorted(k for k in used if k not in defined)
|
|
288
|
+
orphan = sorted(k for k in defined if k not in used)
|
|
289
|
+
dup = sorted(k for k, sites in defined.items() if len(sites) > 1)
|
|
290
|
+
mention_only = sorted(k for k in mentions if k not in used and k not in defined)
|
|
291
|
+
bad = sorted(malformed)
|
|
292
|
+
pairs = [] if args.no_near_miss else near_miss_pairs(phantom, orphan, used, defined)
|
|
293
|
+
rc = 1 if (phantom or dup or bad) else (2 if (orphan and args.strict_orphans) else 0)
|
|
294
|
+
|
|
295
|
+
if args.json:
|
|
296
|
+
print(json.dumps({
|
|
297
|
+
"body": args.body, "refs": args.refs,
|
|
298
|
+
"count_code": args.count_code, "near_miss_enabled": not args.no_near_miss,
|
|
299
|
+
"used": {k: [{"file": f, "line": n, "snippet": s} for f, n, s in v] for k, v in sorted(used.items())},
|
|
300
|
+
"mentions": {k: [{"file": f, "line": n} for f, n, _ in v] for k, v in sorted(mentions.items())},
|
|
301
|
+
"defined": {k: [{"file": f, "line": n} for f, n in v] for k, v in sorted(defined.items())},
|
|
302
|
+
"phantom": phantom, "orphan": orphan, "dup_def": dup, "mention_only": mention_only,
|
|
303
|
+
"malformed": {k: [{"file": f, "line": n, "snippet": s} for f, n, s in v] for k, v in sorted(malformed.items())},
|
|
304
|
+
"near_miss": [{"a": a, "b": b, "a_role": role(a, phantom, orphan, used, defined),
|
|
305
|
+
"b_role": role(b, phantom, orphan, used, defined)} for a, b in pairs],
|
|
306
|
+
"summary": {"usages": n_usages, "used_distinct": len(used), "defined": len(defined),
|
|
307
|
+
"mentions": n_ment, "phantom": len(phantom), "orphan": len(orphan),
|
|
308
|
+
"near_miss": len(pairs), "dup_def": len(dup), "mention_only": len(mention_only),
|
|
309
|
+
"malformed": len(bad), "rc": rc},
|
|
310
|
+
}, ensure_ascii=False, indent=1))
|
|
311
|
+
return rc
|
|
312
|
+
|
|
313
|
+
print("citation-key check · body=%d file%s (%d usages · %d distinct keys) · refs=%s (%d definitions) · mentions in code=%d%s"
|
|
314
|
+
% (len(args.body), "" if len(args.body) == 1 else "s", n_usages, len(used),
|
|
315
|
+
", ".join(args.refs) if args.refs else "(body rows)", len(defined), n_ment,
|
|
316
|
+
" (counted as usages: --count-code)" if args.count_code else ""))
|
|
317
|
+
print(" mechanisms: near-miss=%s · code-spans=%s · strict-orphans=%s · malformed=%s"
|
|
318
|
+
% ("off" if args.no_near_miss else "on", "usage" if args.count_code else "mention",
|
|
319
|
+
"on" if args.strict_orphans else "off", "off (ABLATION)" if args.no_malformed else "on"))
|
|
320
|
+
for k in bad:
|
|
321
|
+
sites = malformed[k]
|
|
322
|
+
print(" 🟥 MALFORMED [%s] cited ×%d — %s — citation-shaped but not a key (dash/underscore between letters and year); no row can match it"
|
|
323
|
+
% (k, len(sites), " · ".join("%s:%d" % (os.path.basename(f), n) for f, n, _ in sites[:args.max_sites or None])))
|
|
324
|
+
print(" …%s…" % sites[0][2])
|
|
325
|
+
for k in phantom:
|
|
326
|
+
sites = used[k]
|
|
327
|
+
shown = sites if args.max_sites == 0 else sites[:args.max_sites]
|
|
328
|
+
where = " · ".join("%s:%d" % (os.path.basename(f), n) for f, n, _ in shown)
|
|
329
|
+
more = "" if len(shown) == len(sites) else " (+%d more)" % (len(sites) - len(shown))
|
|
330
|
+
print(" 🟥 PHANTOM [%s] used ×%d — %s%s" % (k, len(sites), where, more))
|
|
331
|
+
print(" …%s…" % sites[0][2])
|
|
332
|
+
for k in dup:
|
|
333
|
+
print(" 🟥 DUP-DEF [%s] defined ×%d — %s" % (k, len(defined[k]),
|
|
334
|
+
" · ".join("%s:%d" % (os.path.basename(f), n) for f, n in defined[k])))
|
|
335
|
+
for k in orphan:
|
|
336
|
+
ment = mentions.get(k, [])
|
|
337
|
+
print(" 🟨 ORPHAN [%s] defined %s, used ×0%s" % (
|
|
338
|
+
k, " · ".join("%s:%d" % (os.path.basename(f), n) for f, n in defined[k]),
|
|
339
|
+
(" (mentioned ×%d in code: %s)" % (len(ment), " · ".join("%s:%d" % (os.path.basename(f), n) for f, n, _ in ment[:3]))) if ment else ""))
|
|
340
|
+
for a, b in pairs:
|
|
341
|
+
print(" 🟧 NEAR-MISS [%s] (%s) ↔ [%s] (%s) — same letters, different key"
|
|
342
|
+
% (a, role(a, phantom, orphan, used, defined), b, role(b, phantom, orphan, used, defined)))
|
|
343
|
+
for k in mention_only:
|
|
344
|
+
ment = mentions[k]
|
|
345
|
+
print(" ⬜ MENTION-ONLY [%s] undefined, appears only in code spans ×%d — %s (not a citation; --count-code to count it)"
|
|
346
|
+
% (k, len(ment), " · ".join("%s:%d" % (os.path.basename(f), n) for f, n, _ in ment[:3])))
|
|
347
|
+
if phantom:
|
|
348
|
+
print("ⓘ a PHANTOM key has no row a reader can resolve — this is the class that got the sister paper rejected.")
|
|
349
|
+
if orphan and not args.strict_orphans:
|
|
350
|
+
print("ⓘ ORPHAN keys are listed, not counted (rc unaffected) — --strict-orphans to count them.")
|
|
351
|
+
print("citation-key verdict: PHANTOM=%d ORPHAN=%d NEAR-MISS=%d DUP-DEF=%d MENTION-ONLY=%d MALFORMED=%d rc=%d"
|
|
352
|
+
% (len(phantom), len(orphan), len(pairs), len(dup), len(mention_only), len(bad), rc))
|
|
353
|
+
return rc
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
if __name__ == "__main__":
|
|
357
|
+
sys.exit(main())
|