clearotron 0.7.0-beta.2 → 0.7.0-beta.3

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 (131) hide show
  1. package/INSTALL.md +5 -5
  2. package/QUICKSTART.md +4 -4
  3. package/README.md +2 -2
  4. package/bin/README.md +3 -4
  5. package/bin/clearotron.mjs +1 -1
  6. package/bin/onboard.mjs +28 -40
  7. package/bin/status.mjs +11 -0
  8. package/build-info.json +2 -2
  9. package/docs/DELIVERY.md +30 -6
  10. package/docs/architecture/04-configuration-reference.md +1 -0
  11. package/driver/CHANGELOG.md +21 -0
  12. package/driver/compose-read.mjs +4 -3
  13. package/driver/contract-arm2-baseline.json +1 -2
  14. package/driver/contract-dictation-registry.mjs +7 -48
  15. package/driver/contract-e3-backlog.mjs +55 -52
  16. package/driver/contract-e3-baseline.json +22 -7
  17. package/driver/contract-vocabulary.mjs +4 -2
  18. package/driver/coverage-form.mjs +4 -0
  19. package/driver/coverage-rows-run.mjs +68 -4
  20. package/driver/engine/anthropic-agent.mjs +10 -13
  21. package/driver/engine/common.mjs +34 -22
  22. package/driver/engine/health.mjs +251 -0
  23. package/driver/engine/jx-turn.mjs +2 -1
  24. package/driver/engine/mcp/codex-config.mjs +16 -1
  25. package/driver/engine/mcp/crowd-note.mjs +1 -1
  26. package/driver/engine/mcp/gather-config.mjs +34 -9
  27. package/driver/engine/mcp/perplexity-server.mjs +33 -23
  28. package/driver/engine/mcp/recording-server.mjs +67 -58
  29. package/driver/engine/mcp/unit-note-server.mjs +2 -0
  30. package/driver/engine/openai-agent.mjs +9 -24
  31. package/driver/engine/probe.mjs +24 -7
  32. package/driver/findings-model.mjs +54 -0
  33. package/driver/jx-units.mjs +139 -30
  34. package/driver/knockout-assess-record.mjs +2 -2
  35. package/driver/knockout-correction-check.mjs +119 -0
  36. package/driver/knockout-correction-record.mjs +1 -1
  37. package/driver/knockout-frame-record.mjs +24 -10
  38. package/driver/knockout-review-record.mjs +35 -430
  39. package/driver/ladder/dispatch.mjs +4 -2
  40. package/driver/ladder/form-repair.mjs +5 -5
  41. package/driver/ladder/form-sync.mjs +4 -6
  42. package/driver/ladder/next-rung.mjs +10 -0
  43. package/driver/ladder/repair-messages.mjs +37 -65
  44. package/driver/ladder/stage.mjs +3 -3
  45. package/driver/ladder/turn-signals.mjs +4 -14
  46. package/driver/manual-paragraphs.mjs +22 -2
  47. package/driver/mark-logos.mjs +20 -5
  48. package/driver/package.json +1 -1
  49. package/driver/pipeline-knockout.mjs +2 -2
  50. package/driver/predelivery-lint.mjs +39 -7
  51. package/driver/product-fault.mjs +53 -0
  52. package/driver/publish/knockout.mjs +2 -1
  53. package/driver/publish/render.mjs +13 -7
  54. package/driver/recording-agreement.mjs +6 -4
  55. package/driver/register-band-run.mjs +2 -2
  56. package/driver/register-digest-record.mjs +31 -9
  57. package/driver/register-unit-record.mjs +10 -1
  58. package/driver/repair-composers.mjs +12 -11
  59. package/driver/repair-contract.mjs +6 -6
  60. package/driver/repair-targets.mjs +7 -6
  61. package/driver/run-outcome.mjs +8 -0
  62. package/driver/runner.mjs +42 -3
  63. package/driver/skills/README.md +5 -4
  64. package/driver/skills/blind-frame/SKILL.md +1 -1
  65. package/driver/skills/case-law-citation/SKILL.md +1 -1
  66. package/driver/skills/clearance-common-law/SKILL.md +6 -423
  67. package/driver/skills/clearance-common-law/grid.md +272 -0
  68. package/driver/skills/clearance-common-law/meaning.md +142 -0
  69. package/driver/skills/clearance-common-law/perplexity-prompts.md +4 -2
  70. package/driver/skills/clearance-register/SKILL.md +7 -174
  71. package/driver/skills/clearance-register/digest.md +89 -25
  72. package/driver/skills/clearance-register/providers/clarivate-questions.md +154 -0
  73. package/driver/skills/clearance-register/providers/clarivate.md +5 -149
  74. package/driver/skills/clearance-register/providers/signa-questions.md +120 -0
  75. package/driver/skills/clearance-register/providers/signa.md +3 -114
  76. package/driver/skills/clearance-register/providers/uspto-local.md +3 -3
  77. package/driver/skills/clearance-register/register-recipes.md +10 -10
  78. package/driver/skills/clearance-register/status-rules.md +2 -2
  79. package/driver/skills/clearance-register/unit.md +96 -54
  80. package/driver/skills/clearance-search/delivery-contract.md +11 -49
  81. package/driver/skills/clearance-search/firm-wide-reasoning.md +10 -13
  82. package/driver/skills/clearance-search/look-at-what-you-have.md +7 -0
  83. package/driver/skills/clearance-search/phase2-execution.md +12 -117
  84. package/driver/skills/clearance-search/report-card-rules.md +2 -2
  85. package/driver/skills/clearance-search/report-prose.md +30 -23
  86. package/driver/skills/clearance-search/synthesis-rules.md +27 -69
  87. package/driver/skills/clearance-search/worked-examples.md +11 -16
  88. package/driver/skills/clearance-variants/SKILL.md +7 -7
  89. package/driver/skills/clearance-variants/transliteration-scripts.md +2 -2
  90. package/driver/skills/frame-diff/SKILL.md +1 -1
  91. package/driver/skills/knockout-assess/SKILL.md +54 -41
  92. package/driver/skills/knockout-frame/SKILL.md +13 -12
  93. package/driver/skills/knockout-register-read/SKILL.md +2 -10
  94. package/driver/skills/matter-frame/SKILL.md +2 -2
  95. package/driver/skills/narrative-refutation/SKILL.md +7 -6
  96. package/driver/skills/placement-inquiry/SKILL.md +3 -3
  97. package/driver/skills/skeptic/SKILL.md +111 -0
  98. package/driver/skills/whatif-memo/SKILL.md +5 -2
  99. package/driver/stage-declarations.mjs +6 -0
  100. package/driver/stages-knockout.mjs +36 -38
  101. package/driver/stages.mjs +69 -64
  102. package/driver/steps/delivery.mjs +6 -4
  103. package/driver/steps/open-run.mjs +2 -0
  104. package/driver/steps/overview-and-cards.mjs +2 -2
  105. package/driver/steps/register-sweep.mjs +20 -1
  106. package/driver/steps/synthesis.mjs +28 -11
  107. package/driver/suite-census.json +213 -57
  108. package/driver/synthesis-record.mjs +24 -2
  109. package/driver/verify-knockout.mjs +23 -3
  110. package/driver/whatif-memo-run.mjs +39 -10
  111. package/driver/whatif-queue.mjs +53 -7
  112. package/mcp-server/CHANGELOG.md +4 -0
  113. package/mcp-server/lib/ops.mjs +19 -10
  114. package/mcp-server/lib/whatif.mjs +7 -6
  115. package/mcp-server/package.json +1 -1
  116. package/mcp-server/server.mjs +55 -19
  117. package/package.json +1 -1
  118. package/portal-ui/package.json +1 -1
  119. package/providers/clarivate/src/adapter.js +3 -0
  120. package/providers/jx/src/nativeread.js +5 -3
  121. package/providers/oauth-mcp-bridge/CHANGELOG.md +4 -0
  122. package/providers/oauth-mcp-bridge/package.json +1 -1
  123. package/providers/perplexity/src/core.js +7 -2
  124. package/providers/signa/src/adapter.js +3 -0
  125. package/scripts/e2e-first-time.mjs +2 -2
  126. package/shared/connector-signin-probe.mjs +1 -1
  127. package/shared/names-in-force.mjs +1 -0
  128. package/skills/clearotron-account/SKILL.md +21 -11
  129. package/skills/clearotron-client/SKILL.md +15 -15
  130. package/skills/clearotron-ops/COURIER.md +5 -1
  131. package/skills/clearotron-ops/SKILL.md +21 -14
@@ -42,7 +42,7 @@
42
42
  // IT REUSES EACH ADAPTER'S OWN SPAWN PATH AND HAND-ROLLS NOTHING
43
43
  //
44
44
  // The turn goes through `engine.runTurn()`. On anthropic that is `buildClaudeArgs` (prompt on STDIN, `-p`
45
- // as a bare flag, `--effort`, the WRITE_DISCIPLINE system prompt) plus `spawnEnv`; on codex it is
45
+ // as a bare flag, `--effort`, the output rule as its system prompt) plus `spawnEnv`; on codex it is
46
46
  // `buildCodexArgs` plus `spawnEnv` plus the per-run `CODEX_HOME` with its rendered config.toml and its
47
47
  // seeded auth.json — including that adapter's own auth.json refusal, which is a cheaper check than a
48
48
  // turn and runs before one. Both bring their stall watchdog, their detached group-kill and their result
@@ -69,6 +69,7 @@
69
69
 
70
70
  import { ENGINE_BINARIES, DEFAULT_ENGINE_ID, engineAdapterSpecifier, resolveEngineProgram } from "../driver.config.mjs";
71
71
  import { resolveAuthMode, CLOUD_SETTINGS, CLOUD_CREDENTIAL_CHECK } from "./auth.mjs";
72
+ import { billingRefusalWords } from "../run-requirements.mjs"; // the one refusal that quotes a value, said by name
72
73
  import { everyToolCallRefused } from "./tool-refusal.mjs";
73
74
  import { randomBytes } from "node:crypto";
74
75
  import { fileURLToPath } from "node:url";
@@ -128,6 +129,8 @@ export function probeToolConfig(words) {
128
129
  };
129
130
  }
130
131
 
132
+ /** How the probe returns its result: its reply, which carries the words its tools gave. */
133
+ export const PROBE_OUTPUT = Object.freeze({ kind: "reply" });
131
134
  /** A word no model would produce unprompted, fresh per turn. */
132
135
  export const mintProbeSentinel = () => `probe-${randomBytes(4).toString("hex")}`;
133
136
  /** The CHEAP rung of the driver's tier vocabulary on BOTH adapters (engine/CONTRACT.md §3). */
@@ -266,9 +269,11 @@ export function classifyProbe({ engine, tuple = null, error = null, timeoutSec =
266
269
  // rewrites the bare word for that copy and leaves every other copy's text as it was thrown.
267
270
  if (error) {
268
271
  const msg = String(error?.message ?? error);
272
+ // THE BILLING WORD IS NAMED, NEVER QUOTED: a key pasted into it would otherwise be printed by `doctor`, which
273
+ // makes this turn every time, and carried in the engine check's alert.
269
274
  if (error?.billingRefusal === true || /=api-key but/i.test(msg)) // auth.mjs marks every billing refusal
270
275
  return v("auth-misconfigured", "config",
271
- `${id} cannot start: ${/=api-key but/i.test(msg) ? "the billing mode this box declares has no key" : "the billing setting this box declares is refused"}`, msg, { detail: null });
276
+ `${id} cannot start: ${/=api-key but/i.test(msg) ? "the billing mode this box declares has no key" : "the billing setting this box declares is refused"}`, billingRefusalWords(msg), { detail: null });
272
277
  if (SIGNED_OUT_RE.test(msg))
273
278
  return v("signed-out", "config", `${id} is not signed in`, ENGINE_BINARIES[id] ? namingProgram(msg, ENGINE_BINARIES[id], program) : msg);
274
279
  if (TIER_RE.test(msg))
@@ -682,7 +687,9 @@ export async function probeEngineTurn({
682
687
  commandFile = join(runDir, PROBE_COMMAND_FILE);
683
688
  writeFileSync(commandFile, `${command}\n`);
684
689
  }
685
- const tuple = await turn({ message: probePrompt(file, commandFile), model: PROBE_MODEL, thinking: PROBE_THINKING, timeoutSec, stallSec, runDir, ...probeToolConfig(words) });
690
+ // ITS DUTIES ARE ITS PROMPT'S. The probe is judged on the words in its reply, so it carries no output rule: a file
691
+ // stage's rule says to reply with just the path, which would contradict the reply it is checked on.
692
+ const tuple = await turn({ message: probePrompt(file, commandFile), model: PROBE_MODEL, thinking: PROBE_THINKING, timeoutSec, stallSec, runDir, output: PROBE_OUTPUT, ...probeToolConfig(words) });
686
693
  let written = null;
687
694
  try { written = readFileSync(file, "utf8"); } catch { /* not written: classifyProbe says what that means */ }
688
695
  return classifyProbe({ engine: id, tuple, timeoutSec, auth, program, expect: { words, written, ...(command ? { command, commandFile } : {}) } });
@@ -732,6 +739,19 @@ export async function probeEngineTurn({
732
739
  * provider's sign-in, which a minute's wait may outlast.
733
740
  */
734
741
  export async function preflightEngineTurn(opts = {}) {
742
+ const verdict = await judgeEngineTurn(opts);
743
+ if (verdict.ok) return verdict;
744
+ if (probeVerdictLane(verdict) !== "configuration") return { ...verdict, warning: probeWeatherWarning(verdict) };
745
+ const detail = verdict.detail ? `\n engine said: ${verdict.detail}` : "";
746
+ throw new Error(`[preflight] ${probeFailureText(verdict)}${detail}`);
747
+ }
748
+
749
+ /**
750
+ * The door's verdict without the door's refusal: one probe, and the second check after a sign-in renewal that
751
+ * could not happen just now. The engine check between jobs (engine/health.mjs) judges a turn exactly as the door
752
+ * does and reads the lane itself, because it reports rather than refuses.
753
+ */
754
+ export async function judgeEngineTurn(opts = {}) {
735
755
  let verdict = await doorProbe(opts);
736
756
  if (RECHECKED_MODES.has(verdict.mode)) {
737
757
  const first = verdict;
@@ -741,10 +761,7 @@ export async function preflightEngineTurn(opts = {}) {
741
761
  verdict = { ...await doorProbe(opts),
742
762
  recheckedAfter: { mode: first.mode, basis: first.basis, detail: first.detail, waitedMs: REFRESH_LOCK_WAIT_MS } };
743
763
  }
744
- if (verdict.ok) return verdict;
745
- if (probeVerdictLane(verdict) !== "configuration") return { ...verdict, warning: probeWeatherWarning(verdict) };
746
- const detail = verdict.detail ? `\n engine said: ${verdict.detail}` : "";
747
- throw new Error(`[preflight] ${probeFailureText(verdict)}${detail}`);
764
+ return verdict;
748
765
  }
749
766
 
750
767
  /**
@@ -836,6 +836,60 @@ const findingKeysFor = (mode) => (mode.v7 ? FINDING_KEYS_V7 : mode.v6 ? FINDING_
836
836
  * the first time this ladder gains a key. It is derived, so they cannot.
837
837
  */
838
838
  export const FINDING_KEYS_CURRENT = Object.freeze([...FINDING_KEYS_V7]);
839
+
840
+ /**
841
+ * EACH KEY OF THE CURRENT FINDING: when it is required, its shape and the values it takes, as the record_synthesis
842
+ * schema serves them (recording-server.mjs) and the dispatch's checklist names the keys every new finding carries
843
+ * (`always`). The values are this file's own lists, so the text says what the parser accepts. A key is required where
844
+ * the parser, the record's own check (verify.mjs `checkFindingsSibling`) or the dispatch requires it; `manageable` and
845
+ * `bears_on` are required by the dispatch and flagged before delivery, and the parser leaves them optional so archived
846
+ * records still read. The judgments a field needs stay in the dispatch, and so do the framework's band words, its
847
+ * material band and its inputs. A test holds the keys to FINDING_KEYS_CURRENT.
848
+ */
849
+ const quoted = (list) => list.map((k) => `"${k}"`);
850
+ const andList = (list) => (list.length > 1 ? `${list.slice(0, -1).join(", ")} and ${list.at(-1)}` : list.join(""));
851
+ const REQUIRED_ON_READ = "REQUIRED on every finding except a withdrawn or ruled-out one";
852
+ export const FINDING_FIELDS = Object.freeze({
853
+ ordinal: { type: "integer", always: true, about: 'REQUIRED. A whole number from 1, unique in the record: this finding\'s number in your "Finding N" order.' },
854
+ mark: { type: "string", always: true, about: "REQUIRED. The conflicting mark text, verbatim as it appears in the narrative." },
855
+ owner: { type: "object", always: true, about: `REQUIRED. {"name"}, non-empty, with optional ${andList(quoted(OWNER_KEYS.filter((k) => k !== "name")))}. `
856
+ + "Name each registration relied on for this finding by its held URI. Use an empty list for a finding with no registration. "
857
+ + `Each registration is {"uri"}, with optional ${andList(quoted(REGISTRATION_KEYS.filter((k) => k !== "uri")))}; "classes" is a list of strings.` },
858
+ band: { type: "string", about: `REQUIRED on ${andList(BAND_REQUIRED_DISPOSITIONS)} findings, FORBIDDEN on off-field, allowed on withdrawn. `
859
+ + "The framework's band word, exactly as the framework writes it: never a number or code." },
860
+ borderline_between: { type: "array", about: "OPTIONAL, on a finding with a band only: exactly two different band words, one of them this finding's band, "
861
+ + "the two the framework's criteria do not decide between. Omit it where they decide." },
862
+ inputs: { type: "object", about: "Only on a run whose framework states a method: there REQUIRED on every finding with a band except a withdrawn one, "
863
+ + "and FORBIDDEN on one without. An object naming each of the framework's inputs and its value. A withdrawn finding keeps the inputs it had; "
864
+ + "every other finding follows this run's method. FORBIDDEN on every other run." },
865
+ net: { type: "string", about: `${REQUIRED_ON_READ}: the finding sentence.` },
866
+ disposition: { type: "string", always: true, about: `REQUIRED. Exactly one of: ${DISPOSITIONS.join(" / ")}. withdrawn is a correction to an existing finding, never the disposition of a new one.` },
867
+ meters: { type: "object", always: true, about: `REQUIRED. All four of ${andList(METERS)}, each {"token", "basis"} with an optional "source". `
868
+ + `token: ${METERS.map((m) => `${m} is ${METER_TOKENS[m].join(" / ")}`).join("; ")}. basis: ${BASIS_VALUES.join(" / ")}. `
869
+ + "source is the record URI or URL behind the meter, and a verified-from-record meter must name one." },
870
+ quadrant: { type: "object", always: true, about: 'REQUIRED. {"x", "y"}, numbers from 0 to 1. x = goods/services proximity (0 = distant, 1 = identical). y = mark similarity (0 = distinct, 1 = identical).' },
871
+ source: { type: "object", always: true, about: `REQUIRED. {"source_type", "resolved_link"}. source_type is exactly one of: ${SOURCE_TYPES.join(" / ")}. `
872
+ + 'resolved_link is the record URL actually fetched or cited for this finding. Where the provider publishes no page for the record, it is "", and the office register is cited in the text.' },
873
+ use_check: { type: "object", about: `REQUIRED where your instructions' USE-CHECK rule asks for one, OPTIONAL otherwise. {"source"}, with optional "quality" (${USE_SOURCE_QUALITY.join(" / ")}) and "question". `
874
+ + `source is a result URL or "${USE_CHECK_NO_RESULT}". A no-result needs "question": the completed research question it rests on, copied exactly.` },
875
+ own_rights: { type: "object", about: 'REQUIRED whenever this finding relies on the applicant\'s own rights, OPTIONAL otherwise. {"source"}: the applicant\'s own record URI(s), or "no applicant-owned registrations in the searched register material".' },
876
+ bears_on: { type: "string", about: "REQUIRED whenever the enforcer meter is high, OPTIONAL otherwise. One line on what the evidence proves about this conflict." },
877
+ impact: { type: "string", about: "OPTIONAL. One line on the consequences if the rights-holder enforced, for the client to weigh. It never moves the band." },
878
+ deadline: { type: "object", about: 'OPTIONAL. {"date"}, with an optional "kind": a date by which the client must act because of this conflict. date is the ISO date; kind names it, such as opposition, statement-of-use or renewal.' },
879
+ withdrawn_reason: { type: "string", about: "REQUIRED on a withdrawn finding, FORBIDDEN on every other: the review flag that withdrew it." },
880
+ ruled_out: { type: "boolean", about: "OPTIONAL. true for a name that surfaced but shares no word or sound with the mark. It is listed as considered and ruled out, not as a conflict." },
881
+ ruled_out_reason: { type: "string", about: "REQUIRED when ruled_out is true: the specific point that settled it." },
882
+ legal_position: { type: "string", about: `${REQUIRED_ON_READ}: the legal read alone.` },
883
+ practical_position: { type: "string", about: `${REQUIRED_ON_READ}: the enforcement reality, stated beside the legal read and never averaged into the band.` },
884
+ manageable: { type: "object", about: `REQUIRED on ${andList(MANAGEABLE_DISPOSITIONS)} findings, FORBIDDEN on adversarial and off-field. `
885
+ + `{"category", "reason"}: category is exactly one of ${MANAGEABLE_CATEGORIES.join(" / ")}; reason says why this finding is manageable for this client.` },
886
+ off_field_ground: { type: "string", about: `REQUIRED on an off-field finding that is not ruled out, FORBIDDEN on every other disposition. Exactly one of: ${OFF_FIELD_GROUNDS.join(" / ")}. `
887
+ + 'different-field needs a goods_proximity of "low".' },
888
+ rating_withdrawn_ground: { type: "string", about: `OPTIONAL on a withdrawn finding, FORBIDDEN on every other. Exactly: ${RATING_WITHDRAWN_GROUNDS.join(" / ")}. `
889
+ + "Send it where the right stands and only its rating is withdrawn." },
890
+ });
891
+ /** The keys every newly written finding carries: the dispatch's checklist. The tool's schema explains the rest. */
892
+ export const FINDING_KEYS_ALWAYS = Object.freeze(Object.keys(FINDING_FIELDS).filter((k) => FINDING_FIELDS[k].always));
839
893
  const isPlainObject = (v) => v && typeof v === "object" && !Array.isArray(v);
840
894
  const onlyKeys = (obj, allowed, tokenFor) => {
841
895
  for (const k of Object.keys(obj)) if (!allowed.includes(k)) throw new Error(`${tokenFor(k)} (keys are EXACTLY: ${allowed.join(", ")})`);
@@ -30,7 +30,7 @@
30
30
  // enforces record_uri ∈ the inlined slice (else the item demotes to a lead); severity_hint is a
31
31
  // triage hint and NEVER sets a band — Claude stays the sole rating authority.
32
32
 
33
- import { readFileSync, writeFileSync, renameSync, appendFileSync, mkdirSync } from "node:fs";
33
+ import { existsSync, readFileSync, writeFileSync, renameSync, appendFileSync, mkdirSync } from "node:fs";
34
34
  import { join } from "node:path";
35
35
  import { LANGUAGE_LANES, SERP_LANES, isMirrorHost, canonicalTerm, jxBillingStamp, jxModelFields } from "./jx-lanes.mjs";
36
36
  import { jxKey, MAX_LANE_ATTEMPTS } from "./jx.mjs";
@@ -40,6 +40,9 @@ import { SERP_PROVIDERS } from "./driver.config.mjs";
40
40
  import { JX_PROVIDERS } from "./jx-providers.mjs";
41
41
  import { findGridLedgerViolations, findPlatformIdentityViolations } from "./common-law-receipts.mjs";
42
42
  import { paths, readJson } from "./run-record.mjs";
43
+ import { isLiveRecord } from "./band-shape.mjs";
44
+ import { bandGoodsIndex, goodsFor, rowGoods } from "./record-goods.mjs";
45
+ import { recordGoodsEvidence, goodsFromLabel, heldRecordProvenance } from "./goods-evidence.mjs";
43
46
  import { stopsWithTheRun } from "./cancel.mjs";
44
47
 
45
48
  export const MAX_UNIT_ATTEMPTS = 3; // degraded-unit retries across resumes (repairable, never terminal)
@@ -50,7 +53,8 @@ export const SERP_CONCURRENCY = 3; // parallel SERP calls (the knockout sw
50
53
  export const SERP_GRID_DEADLINE_MS = 5 * 60_000; // whole-grid wall clock (CLEAROTRON_JX_SERP_DEADLINE_MS overrides);
51
54
  // past it, unattempted cells gap honestly — never a stalled run
52
55
  export const NATIVEREAD_GRID_ROWS_CAP = 60; // grid-findings rows inlined into the read payload (receipted cap)
53
- export const NATIVEREAD_SLICE_CAP = 12000; // chars of register-unit output inlined into the read payload
56
+ export const NATIVEREAD_RECORDS_CAP = 60; // Chinese register records inlined into the read payload
57
+ export const NATIVEREAD_GOODS_CHARS = 300; // goods text shown per record
54
58
  const GAP_DEGRADE_FLOOR = 0.5; // >50% gapped cells ⇒ the grid attempt DEGRADES (the GRID_COVERAGE_FLOOR idiom)
55
59
 
56
60
  const jxDir = (runDir) => paths(runDir).jx;
@@ -432,7 +436,6 @@ export async function runJxSerpGrid(ctx, job, opts = {}, { runLog = () => {}, no
432
436
  }
433
437
 
434
438
  // ── Slice 3 — jx-nativeread:zh ──────────────────────────────────────────────────────────────────────
435
- const URI_RE = /https?:\/\/[^\s|)\]"'<>]+/g;
436
439
  const normUri = (u) => String(u).replace(/[.,;:!?]+$/, "");
437
440
 
438
441
  // The rows the cap keeps. The grid is in cell order, which says nothing about relevance, so use a reader could flag sat
@@ -442,34 +445,141 @@ const GRID_ROW_RANK = new Map([["use-evidence", 0], ["listing-candidate", 1], ["
442
445
  const gridRowRank = (f) => GRID_ROW_RANK.get(f?.classification) ?? 3;
443
446
 
444
447
  /** Assemble the code-inlined zh evidence slice + the fetched-URI set it carries (pure over inputs). */
445
- export function buildNativereadPayload({ registerSliceText = "", candidates = [], cnipaSubgroups = [], gridFindings = [] }) {
448
+ // THE OFFICE A BAND ROW BELONGS TO: the registry the screen names, else the office its identifier carries
449
+ // (`/mark/cn/…`). Empty when neither says.
450
+ const officeOf = (r) => {
451
+ const reg = String(r?.screen?.registry ?? (Array.isArray(r?.jurisdictions) ? r.jurisdictions[0] : r?.jurisdictions) ?? r?.jurisdiction ?? "").trim();
452
+ if (reg) return reg.toUpperCase();
453
+ return (/^\/mark\/([a-z]+)\//i.exec(String(r?.record_id ?? r?.uri ?? ""))?.[1] ?? "").toUpperCase();
454
+ };
455
+ const recordIdOf = (r) => String(r?.record_id ?? r?.uri ?? "").trim();
456
+
457
+ /**
458
+ * THE CHINESE REGISTER RECORDS THE READER IS GIVEN, from the transliteration and numeric search's own band: every row
459
+ * whose office is CN, once per identifier. Live records come first and then by identifier, so a capped list is the
460
+ * same list on every read. `state` keeps what the record establishes apart: "read" (the band was read, with or
461
+ * without a Chinese record), "missing" (no band) and "unreadable". The unit's note is not read: it is a count.
462
+ *
463
+ * A record's goods are its held body's, and where the run holds none, the statements its search row carries
464
+ * (record-goods.mjs `rowGoods`). `goodsFrom` says what they rest on and how complete they are, in the words the band
465
+ * lookup serves (goods-evidence.mjs `goodsFromLabel`): an empty held body, a body with no goods field and nothing held
466
+ * stay three different things. A class whose wording the merged band set aside is said in `goodsFrom`, never as text.
467
+ */
468
+ export function chineseRegisterRecords(runDir) {
469
+ const at = paths(runDir).registerBand("transliteration-numeric");
470
+ if (!existsSync(at)) return { state: "missing", records: [] };
471
+ let blocks;
472
+ try { blocks = JSON.parse(readFileSync(at, "utf8")); } catch { return { state: "unreadable", records: [] }; }
473
+ if (!Array.isArray(blocks)) return { state: "unreadable", records: [] };
474
+ const seen = new Map();
475
+ for (const b of blocks) {
476
+ for (const r of [...(Array.isArray(b?.records) ? b.records : []), ...(Array.isArray(b?.sample) ? b.sample : [])]) {
477
+ const id = recordIdOf(r);
478
+ if (!id || officeOf(r) !== "CN" || seen.has(id)) continue;
479
+ seen.set(id, r);
480
+ }
481
+ }
482
+ let index = null, bodies = null;
483
+ try { index = bandGoodsIndex(runDir); } catch { index = null; }
484
+ try { bodies = heldRecordProvenance(runDir); } catch { bodies = null; }
485
+ const held = (r) => goodsFor(index, { record_id: recordIdOf(r) });
486
+ const reader = { of: (r) => held(r) ?? rowGoods(r), held: (r) => held(r) != null };
487
+ const records = [...seen.values()]
488
+ .sort((a, b) => (Number(isLiveRecord(b)) - Number(isLiveRecord(a))) || recordIdOf(a).localeCompare(recordIdOf(b)))
489
+ .map((r) => {
490
+ const evidence = recordGoodsEvidence({ ...r, record_id: recordIdOf(r) }, { goods: reader, held: bodies });
491
+ const statements = (reader.of(r) ?? []).filter((g) => g?.setAside !== true && String(g?.text ?? "").trim());
492
+ return { id: recordIdOf(r), mark: r?.mark_text ?? null, owner: r?.owner_name ?? null, status: r?.status ?? r?.screen?.status ?? null,
493
+ classes: Array.isArray(r?.classes) ? r.classes : [], goods: statements.length ? statements : null, goodsFrom: goodsFromLabel(evidence) };
494
+ });
495
+ return { state: "read", records };
496
+ }
497
+
498
+ /**
499
+ * A RECORD'S GOODS AS THE READER IS SHOWN THEM: what they rest on, then the statements, class by class. A statement the
500
+ * register gave with a translation shows the original first and the translation beside it, labelled, so it never reads
501
+ * as more goods; neither carries a language label, which the record does not establish for the original. Past
502
+ * NATIVEREAD_GOODS_CHARS the text is cut here, and the line says so, apart from any cut the register made: how many
503
+ * characters it shows of how many, each class none of whose wording appears, each class whose further wording does
504
+ * not, and which version of a statement the cut shortened or left out. PURE.
505
+ */
506
+ const goodsShown = (goods, from) => {
507
+ const label = from ?? "nothing held";
508
+ if (!goods?.length) return `goods: ${label}`;
509
+ const statements = goods.map((g) => {
510
+ const head = [...(g.classes?.length ? `class ${g.classes.join("/")}: ` : "")];
511
+ const original = [...String(g.alt ?? g.text)];
512
+ const opening = g.alt ? [..." (translation: "] : [];
513
+ const translation = g.alt ? [...String(g.text)] : [];
514
+ return { name: g.classes?.length ? g.classes.join("/") : null, head, original, opening, translation, close: g.alt ? [...")"] : [] };
515
+ });
516
+ const whole = statements.flatMap((t, i) => [...(i ? [..."; "] : []), ...t.head, ...t.original, ...t.opening, ...t.translation, ...t.close]);
517
+ if (whole.length <= NATIVEREAD_GOODS_CHARS) return `goods (${label}): ${whole.join("")}`;
518
+ const cut = NATIVEREAD_GOODS_CHARS;
519
+ const seen = new Set(), none = [], further = [], versions = [];
520
+ let at = 0;
521
+ for (const t of statements) {
522
+ const words = at + t.head.length, originalEnd = words + t.original.length;
523
+ const translationStart = originalEnd + t.opening.length, translationEnd = translationStart + t.translation.length;
524
+ const end = translationEnd + t.close.length;
525
+ if (cut <= words) { if (t.name) (seen.has(t.name) ? further : none).push(t.name); }
526
+ else {
527
+ if (t.name) seen.add(t.name);
528
+ // Only the words count: a translation shown whole with its closing bracket cut is not a shortened translation,
529
+ // and the line's own count already says the cut fell there.
530
+ if (t.translation.length && cut < translationEnd && t.name) {
531
+ versions.push(cut < originalEnd ? `the original wording for class ${t.name} is shortened, and its translation is not shown`
532
+ : cut <= translationStart ? `the translation for class ${t.name} is not shown` : `the translation for class ${t.name} is shortened`);
533
+ }
534
+ }
535
+ at = end + 2;
536
+ }
537
+ const classes = (list) => `class${list.length > 1 ? "es" : ""} ${[...new Set(list)].join(", ")}`;
538
+ // The cut only moves forward, so a class first left out is never shown later: the two lists never share a class.
539
+ const notes = [...(none.length ? [`the text of ${classes(none)} is not shown`] : []),
540
+ ...(further.length ? [`further wording for ${classes(further)} is not shown`] : []), ...versions];
541
+ return `goods (${label}; first ${cut} of ${whole.length} characters shown${notes.map((n) => `; ${n}`).join("")}): ${whole.slice(0, cut).join("")}`;
542
+ };
543
+
544
+ /**
545
+ * The read's evidence, assembled by the driver: the sections the reader is shown, and the identifiers and URLs it
546
+ * may cite. Only what it was shown can ground a reading: a record or a platform row left out by a cap is not
547
+ * citable. A register section with no record does not count as evidence to read.
548
+ */
549
+ export function buildNativereadPayload({ registerRecords = { state: "missing", records: [] }, candidates = [], cnipaSubgroups = [], gridFindings = [] }) {
446
550
  const sections = [];
447
- if (candidates.length) sections.push("## Native-script candidates (generated for this run)\n"
448
- + candidates.map((c) => `- ${c.term} (${c.kind}) — ${String(c.rationale ?? "").slice(0, 200)}`).join("\n"));
449
- if (cnipaSubgroups.length) sections.push("## CNIPA sub-class notes (seed table — informational)\n"
450
- + cnipaSubgroups.map((g) => `- class ${g.class}: ${g.groups ? g.groups.join(", ") : (g.note ?? "no entry")}`).join("\n"));
451
- if (registerSliceText.trim()) {
452
- const truncated = registerSliceText.length > NATIVEREAD_SLICE_CAP;
453
- sections.push("## CN register slice (transliteration-numeric unit output" + (truncated ? ", truncated" : "") + ")\n"
454
- + registerSliceText.slice(0, NATIVEREAD_SLICE_CAP));
551
+ let evidence = 0;
552
+ if (candidates.length) { evidence++; sections.push("## Native-script candidates (generated for this run)\n"
553
+ + candidates.map((c) => `- ${c.term} (${c.kind}) — ${String(c.rationale ?? "").slice(0, 200)}`).join("\n")); }
554
+ if (cnipaSubgroups.length) { evidence++; sections.push("## CNIPA sub-class notes (informational)\n"
555
+ + cnipaSubgroups.map((g) => `- class ${g.class}: ${g.groups ? g.groups.join(", ") : (g.note ?? "no entry")}`).join("\n")); }
556
+ const eligible = registerRecords?.records ?? [];
557
+ const shownRecords = eligible.slice(0, NATIVEREAD_RECORDS_CAP);
558
+ if (shownRecords.length) {
559
+ evidence++;
560
+ sections.push(`## Chinese register records supplied (${shownRecords.length} of ${eligible.length})\n`
561
+ + shownRecords.map((r) => `- ${r.id} | ${r.mark ?? "mark not shown"} | owner: ${r.owner ?? "not shown"} | ${r.status ?? "status not shown"}`
562
+ + ` | classes ${r.classes.length ? r.classes.join(", ") : "not shown"} | ${goodsShown(r.goods, r.goodsFrom)}`).join("\n"));
563
+ } else {
564
+ sections.push("## No Chinese register records were supplied for this reading");
455
565
  }
456
566
  let gridRowsDropped = 0;
567
+ let shownRows = [];
457
568
  if (gridFindings.length) {
458
- const rows = [...gridFindings].sort((a, b) => gridRowRank(a) - gridRowRank(b)).slice(0, NATIVEREAD_GRID_ROWS_CAP);
459
- gridRowsDropped = gridFindings.length - rows.length;
569
+ evidence++;
570
+ shownRows = [...gridFindings].sort((a, b) => gridRowRank(a) - gridRowRank(b)).slice(0, NATIVEREAD_GRID_ROWS_CAP);
571
+ gridRowsDropped = gridFindings.length - shownRows.length;
460
572
  sections.push("## Platform grid findings (judged)\n"
461
- + rows.map((f) => `- [${f.classification}] "${f.title}" — ${f.url} (term ${f.term} on ${f.platform})${f.note ? ` — ${f.note}` : ""}`).join("\n")
462
- + (gridRowsDropped ? `\n- … ${gridRowsDropped} more rows omitted (payload cap — full set in zh-grid-findings.json)` : ""));
573
+ + shownRows.map((f) => `- [${f.classification}] "${f.title}" — ${f.url} (term ${f.term} on ${f.platform})${f.note ? ` — ${f.note}` : ""}`).join("\n")
574
+ + (gridRowsDropped ? `\n- … ${gridRowsDropped} more rows not shown` : ""));
463
575
  }
464
576
  const payload = sections.join("\n\n");
465
- // The grounding set is STRUCTURAL, never a regex over the rendered payload: a URL an attacker
466
- // plants inside a hit TITLE/snippet (or the model echoes in its own output) must not mint a
467
- // grounding URI (review 2026-07-18). Sources: the grid findings' url FIELDS (every one was
468
- // actually fetched and receipted, capped or not) + URIs in the register unit's own output (our
469
- // register machinery's text, the design's fetched set).
470
- const uris = new Set(gridFindings.map((f) => f?.url).filter(Boolean).map((u) => normUri(String(u))));
471
- for (const m of String(registerSliceText).slice(0, NATIVEREAD_SLICE_CAP).match(URI_RE) ?? []) uris.add(normUri(m));
472
- return { payload, uris, sections: sections.length, gridRowsDropped };
577
+ // The grounding set is STRUCTURAL, never a regex over the rendered payload: a URL planted inside a hit title or
578
+ // echoed by the model must not mint a grounding identifier (review 2026-07-18). It holds the identifiers of the
579
+ // register records shown and the URL fields of the platform rows shown, and nothing a cap left out.
580
+ const uris = new Set([...shownRecords.map((r) => r.id), ...shownRows.map((f) => f?.url).filter(Boolean)].map((u) => normUri(String(u))));
581
+ return { payload, uris, sections: evidence, gridRowsDropped,
582
+ register: { state: registerRecords?.state ?? "missing", eligible: eligible.length, shown: shownRecords.length } };
473
583
  }
474
584
 
475
585
  /** Grounding enforcement (pure): record_uri must come from the inlined slice; conflict-read and
@@ -512,14 +622,13 @@ export async function runJxNativeread(ctx, job, opts = {}, { runLog = () => {},
512
622
  }
513
623
 
514
624
  const markName = String(job.markName ?? job.name ?? "").trim();
515
- let registerSliceText = "";
516
- try { registerSliceText = readFileSync(join(run.runDir, "register-units", "transliteration-numeric.md"), "utf8"); } catch { /* unit may not exist */ }
625
+ const registerRecords = chineseRegisterRecords(run.runDir);
517
626
  const fold = ctx.jxLanes?.fold?.lanes?.[lane] ?? {};
518
627
  let gridFindings = [];
519
628
  try { gridFindings = readJson(join(jxDir(run.runDir), `${lane}-grid-findings.json`))?.findings ?? []; } catch { /* grid unit may be off */ }
520
- const { payload, uris, sections, gridRowsDropped } = buildNativereadPayload({
521
- registerSliceText, candidates: fold.accepted ?? [], cnipaSubgroups: fold.cnipaSubgroups ?? [], gridFindings });
522
- if (!sections) return { ran: false, cause: "no zh evidence to read (no register slice, candidates or grid findings)" };
629
+ const { payload, uris, sections, gridRowsDropped, register } = buildNativereadPayload({
630
+ registerRecords, candidates: fold.accepted ?? [], cnipaSubgroups: fold.cnipaSubgroups ?? [], gridFindings });
631
+ if (!sections) return { ran: false, cause: `no zh evidence to read (register records ${register.state === "read" ? "none held" : register.state}, no candidates or grid findings)` };
523
632
 
524
633
  const { exec, source } = resolveNativeread(opts, { mark: markName, lane, runDir: run.runDir });
525
634
  const started = Date.now();
@@ -540,7 +649,7 @@ export async function runJxNativeread(ctx, job, opts = {}, { runLog = () => {},
540
649
  const items = groundReadItems(r.items ?? [], uris);
541
650
  const grounded = items.filter((i) => i.grounded).length;
542
651
  mkdirSync(jxDir(run.runDir), { recursive: true });
543
- atomic(join(jxDir(run.runDir), "nativeread.json"), { schema: 1, lane, mark: markName, items, sections,
652
+ atomic(join(jxDir(run.runDir), "nativeread.json"), { schema: 1, lane, mark: markName, items, sections, register,
544
653
  ...(gridRowsDropped ? { gridRowsDropped } : {}), readAt: new Date().toISOString() });
545
654
  // the aim-attention artifact — the ONLY thing the Phase-5 consume flag will ever surface to
546
655
  // synthesis; the header restates the authority rule so the artifact is self-describing
@@ -210,8 +210,8 @@ const nameKey = (s) => String(s ?? "").trim().toLowerCase();
210
210
  * happy-path test passes on a merge that deletes everything it was not handed.
211
211
  * chunkSummary REPLACED when present, KEPT when absent. It narrates the whole chunk, so a partial
212
212
  * summary is not a thing — either the seat restated it or it did not.
213
- * batch MERGED PER KEY. Chunk 0 only, and its two keys are independent: a correction to
214
- * productContext must not drop standardCaveats.
213
+ * batch MERGED PER KEY. Optional from any group, and its two keys are independent: a correction to
214
+ * productContext must not drop standardCaveats. The driver takes the product context from the plan.
215
215
  * framework REPLACED when present. It is one object naming the deck and its ladder; half a
216
216
  * ladder is not a ladder.
217
217
  * schema_version THE DRIVER'S. Never taken from the payload — a stored document's version is a fact
@@ -0,0 +1,119 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
3
+ //
4
+ // knockout-correction-check.mjs — does a corrected Knockout deliver its correction?
5
+ //
6
+ // A Knockout is reviewed once, and each defect the review raises goes back to the rating step once. The record that
7
+ // publishes is composed again from the corrected groups, and the order's summary is joined from each group's own summary,
8
+ // which the rating step is asked to update when its correction changes it. Nothing compared the two afterwards: a summary
9
+ // left in its earlier form, or a record composed from the groups as they were rated, delivered with no flag, because the
10
+ // pre-delivery check listed corrections as absent by design on this lane.
11
+ //
12
+ // So this compares what publishes with what the round accepted, from the round's own record: the names as rated
13
+ // (`knockout-correction-work.json`), the outcome of each defect (`knockout-corrections.json`) and the review's answer.
14
+ // For each defect whose correction was accepted, the delivered name must not hold the earlier form: a removed finding is
15
+ // gone, a changed finding or line is not as it was rated, and the name's block in the summary heads it with the band
16
+ // the record now gives it. A clean review, and a round that accepted nothing, are checked too, and say so.
17
+ //
18
+ // FLAGS, NEVER A REFUSAL, as every Knockout pre-delivery check: the caller hands these to the lint, which projects a
19
+ // failure on the report to the reviewing lawyer through the existing correction-consistency sentence. It reads the run
20
+ // directory here and nowhere else, so the comparison itself stays pure.
21
+ import { paths } from "./run-record.mjs";
22
+ import { knockoutReviewFile } from "./knockout-review-record.mjs";
23
+ import { readCorrectionWork, sameFinding, summaryBlock, withoutOrdinal } from "./knockout-correction-record.mjs";
24
+ import { readFileSync } from "node:fs";
25
+
26
+ const ID = "correction-consistency";
27
+ const FAMILY = "corrections";
28
+ // The outcomes in which a correction changed what a name delivers (knockout-correction-record.mjs correctionOutcomes).
29
+ const ACCEPTED = new Set(["findings-changed", "findings-removed", "line-changed"]);
30
+
31
+ const nameKey = (s) => String(s ?? "").trim().toLowerCase();
32
+ const readJson = (p) => { try { return JSON.parse(readFileSync(p, "utf8")); } catch { return null; } };
33
+ const row = (id, surface, pass, detail) => ({ id, family: FAMILY, surface, pass: Boolean(pass), detail });
34
+ const markOf = (doc, name) => (doc?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(name)) ?? null;
35
+ const shape = (m) => (m ? JSON.stringify({ ...m, findings: (m.findings ?? []).map(withoutOrdinal) }) : null);
36
+
37
+ /** The round as the run holds it: the review's answer, the corrections record and the names as rated. Each null where absent. */
38
+ export function readCorrectionRound(runDir) {
39
+ return { review: readJson(knockoutReviewFile(runDir)), corrections: readJson(paths(runDir).knockoutCorrections), work: readCorrectionWork(runDir) };
40
+ }
41
+
42
+ /** The band word a summary block's heading gives its name, from the framework's ladder, or null where it names none. PURE. */
43
+ export function headedBand(block, name, ladder) {
44
+ const head = String(block ?? "").split("\n")[0] ?? "";
45
+ const rest = head.toLowerCase().split(nameKey(name)).join(" ");
46
+ const words = [...(ladder ?? [])].map(String).filter(Boolean).sort((a, b) => b.length - a.length);
47
+ const esc = (w) => w.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
48
+ return words.find((w) => new RegExp(`(^|[^a-z])${esc(w)}([^a-z]|$)`).test(rest)) ?? null;
49
+ }
50
+
51
+ /**
52
+ * The checks, over the delivered record and the round. `notApplicable` where the run holds no review at all: a run rated
53
+ * before every Knockout was reviewed, republished. PURE.
54
+ */
55
+ export function knockoutCorrectionChecks({ findings, round }) {
56
+ const { review = null, corrections = null, work = null } = round ?? {};
57
+ if (!review && !corrections) {
58
+ return { checks: [], notApplicable: { id: ID, family: FAMILY, reason: "this run holds no review record, so no correction was made after rating to compare" } };
59
+ }
60
+ if (!corrections) {
61
+ const raised = review?.material?.length ?? 0;
62
+ return { checks: [raised
63
+ ? row(`${ID}:round`, "findings", false, `the review raised ${raised} defect(s) and the run holds no corrections record, so what was delivered cannot be compared with a correction`)
64
+ : row(ID, "report", true, "the review raised no defect, so nothing was corrected after rating")], notApplicable: null };
65
+ }
66
+ const accepted = (corrections.outcomes ?? []).filter((o) => ACCEPTED.has(o?.outcome));
67
+ if (!accepted.length) {
68
+ const why = corrections.failure ? `the correction stood down (${corrections.failure}) and the rated record shipped` : "no correction changed a name";
69
+ return { checks: [row(ID, "report", true, `${why}; nothing delivered differs from the record as rated`)], notApplicable: null };
70
+ }
71
+ if (!Array.isArray(work?.rated?.marks) || !Array.isArray(work?.defects)) {
72
+ return { checks: [row(`${ID}:round`, "findings", false, `${accepted.length} correction(s) were accepted and the run no longer holds the names as rated, so what was delivered cannot be compared with them`)], notApplicable: null };
73
+ }
74
+
75
+ const checks = [];
76
+ const ladder = findings?.framework?.ladder ?? [];
77
+ const summaryNow = findings?.batch?.executiveSummary, summaryWas = work.rated?.batch?.executiveSummary;
78
+ const names = new Map();
79
+ for (const o of accepted) {
80
+ const d = work.defects.find((x) => x?.n === o.n);
81
+ if (!d) { checks.push(row(`${ID}:record:${o.n}`, "findings", false, `correction ${o.n} was accepted and the round's work holds no defect ${o.n}`)); continue; }
82
+ const was = markOf(work.rated, d.mark), now = markOf(findings, d.mark);
83
+ if (!now) { checks.push(row(`${ID}:record:${o.n}`, "findings", false, `correction ${o.n} changed "${d.mark}", which the delivered record does not hold`)); continue; }
84
+ names.set(nameKey(d.mark), { name: d.mark, was, now, removed: [...(names.get(nameKey(d.mark))?.removed ?? []), ...(o.outcome === "findings-removed" && d.names ? [d.names] : [])] });
85
+ let stale = null;
86
+ if (o.outcome === "findings-removed" && d.names) {
87
+ if ((now.findings ?? []).some((f) => sameFinding(f, d.names))) stale = `the finding "${d.names.name}" the correction removed is still delivered on "${d.mark}"`;
88
+ } else if (o.outcome === "findings-changed" && d.names) {
89
+ const before = (was?.findings ?? []).find((f) => sameFinding(f, d.names)), current = (now.findings ?? []).find((f) => sameFinding(f, d.names));
90
+ if (before && current && withoutOrdinal(before) === withoutOrdinal(current)) stale = `the finding "${d.names.name}" on "${d.mark}" is delivered as it was rated, before its correction`;
91
+ } else if (o.outcome === "line-changed") {
92
+ if (shape(was) === shape(now)) stale = `"${d.mark}" is delivered as it was rated, before its correction`;
93
+ }
94
+ checks.push(row(`${ID}:record:${o.n}`, "report", !stale, stale ?? `correction ${o.n} (${o.outcome}) on "${d.mark}" is the form delivered`));
95
+ }
96
+
97
+ // THE SUMMARY, once per corrected name: its heading gives the band the record now gives the name, a moved band is not left in
98
+ // the block as it was rated, and a finding the correction removed is not still named there.
99
+ let i = 0;
100
+ for (const { name, was, now, removed } of names.values()) {
101
+ i += 1;
102
+ const block = summaryBlock(summaryNow, name);
103
+ const faults = [];
104
+ const headed = headedBand(block, name, ladder);
105
+ if (headed && nameKey(headed) !== nameKey(now.rating)) faults.push(`the summary heads "${name}" ${headed} and the delivered record rates it ${now.rating}`);
106
+ if (block != null && nameKey(was?.rating) !== nameKey(now.rating) && block === summaryBlock(summaryWas, name))
107
+ faults.push(`"${name}" moved from ${was?.rating} to ${now.rating} and its summary block is as it was rated`);
108
+ for (const r of removed) {
109
+ const stillCarried = (now.findings ?? []).some((f) => nameKey(f?.name) === nameKey(r.name));
110
+ if (block && !stillCarried && String(r.name ?? "").trim() && block.toLowerCase().includes(nameKey(r.name)))
111
+ faults.push(`the summary block for "${name}" still names "${r.name}", which the correction removed`);
112
+ }
113
+ // A corrected name the summary gives no block cannot be compared there. That is recorded, not passed, and not put to the
114
+ // reader as a stale correction.
115
+ if (block == null) checks.push(row(`${ID}:summary:${i}`, "findings", false, `the summary holds no block headed "${name}", so it could not be compared with the correction`));
116
+ else checks.push(row(`${ID}:summary:${i}`, "report", !faults.length, faults.join("; ") || `the summary block for "${name}" agrees with its corrected record`));
117
+ }
118
+ return { checks, notApplicable: null };
119
+ }
@@ -45,7 +45,7 @@ const correctionCallDir = (runDir, chunkNo) => driverDir(runDir, join("knockout-
45
45
  const nameKey = (s) => String(s ?? "").trim().toLowerCase();
46
46
  /** A finding's identity across a renumbering: the gate re-ranks on the band, so an ordinal does not survive a move. */
47
47
  export const sameFinding = (a, b) => nameKey(a?.name) === nameKey(b?.name) && nameKey(a?.owner) === nameKey(b?.owner);
48
- const withoutOrdinal = (f) => { const { ordinal: _ordinal, ...rest } = f ?? {}; return JSON.stringify(rest); };
48
+ export const withoutOrdinal = (f) => { const { ordinal: _ordinal, ...rest } = f ?? {}; return JSON.stringify(rest); };
49
49
 
50
50
  /**
51
51
  * The round's work, from the record the check read and the defects it raised: each numbered, on its chunk, with the finding