clearotron 0.5.0-beta.7 → 0.5.0-beta.9

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 (46) hide show
  1. package/.env.example +9 -1
  2. package/INSTALL.md +1 -1
  3. package/bin/signa-sync.mjs +1 -1
  4. package/build-info.json +2 -2
  5. package/docs/architecture/04-configuration-reference.md +1 -0
  6. package/docs/configuration.md +1 -1
  7. package/driver/CHANGELOG.md +20 -0
  8. package/driver/contract-vocabulary.mjs +3 -3
  9. package/driver/corrections-delivered.mjs +7 -5
  10. package/driver/corrections-feedforward.mjs +89 -3
  11. package/driver/coverage-form.mjs +61 -2
  12. package/driver/engine/mcp/band-server.mjs +16 -6
  13. package/driver/engine/mcp/correction-positions.mjs +18 -0
  14. package/driver/engine/mcp/gather-config.mjs +7 -3
  15. package/driver/engine/mcp/recording-server.mjs +7 -4
  16. package/driver/engine/openai-agent.mjs +24 -1
  17. package/driver/engine/probe.mjs +64 -9
  18. package/driver/findings-model.mjs +4 -2
  19. package/driver/gateway.mjs +26 -16
  20. package/driver/goods-evidence.mjs +16 -3
  21. package/driver/narrative-refutation-record.mjs +17 -2
  22. package/driver/package.json +1 -1
  23. package/driver/pipeline.mjs +283 -41
  24. package/driver/predelivery-lint.mjs +91 -2
  25. package/driver/record-fold.mjs +16 -0
  26. package/driver/record-goods.mjs +24 -8
  27. package/driver/repair-composers.mjs +72 -12
  28. package/driver/saved-register-pages.mjs +144 -0
  29. package/driver/skills/clearance-register/providers/signa.md +6 -4
  30. package/driver/stage-context.mjs +7 -0
  31. package/driver/suite-census.json +96 -12
  32. package/driver/synthesis-record.mjs +165 -33
  33. package/driver/verify.mjs +6 -3
  34. package/mcp-server/CHANGELOG.md +8 -0
  35. package/mcp-server/package.json +1 -1
  36. package/package.json +1 -1
  37. package/portal-ui/package.json +1 -1
  38. package/providers/README.md +1 -1
  39. package/providers/oauth-mcp-bridge/CHANGELOG.md +8 -0
  40. package/providers/oauth-mcp-bridge/package.json +1 -1
  41. package/providers/signa/src/core.js +18 -4
  42. package/providers/signa/src/offices.generated.js +15 -13
  43. package/scripts/e2e-first-time.mjs +6 -4
  44. package/scripts/release-duplicate-notes.mjs +5 -0
  45. package/shared/names-in-force.mjs +1 -0
  46. package/shared/register-selection.mjs +2 -2
@@ -153,6 +153,15 @@ const DETAIL_CHARS = 400;
153
153
  // Please run /login"); bare "login" is deliberately NOT matched, because it appears in prose that is not
154
154
  // about being signed out.
155
155
  const SIGNED_OUT_RE = /not logged in|logged out|signed out|please log ?in|\/login\b|claude login|codex login|no auth\.json|credentials? (?:were )?not found|no .* credentials|unauthori[sz]ed|authentication[_ ]error|invalid[_ -]?api[_ -]?key|oauth|\b401\b|\b403\b/i;
156
+ // A SIGN-IN REFRESH ANOTHER COPY OF THE PROGRAM IS HOLDING, which is not a sign-out. The Claude program renews
157
+ // an expired sign-in under a lock that every copy on the same sign-in shares. When another copy holds it and
158
+ // does not renew it, the program gives up and says to retry in a minute, and files that as a server error,
159
+ // not an authentication failure. Claude Code 2.1.295 carries three wordings: the line a `-p` turn ends with,
160
+ // the one an interactive session shows, and the error's own message. Measured on the test machine,
161
+ // 2026-11-03: the first matched `oauth` above, and a job failed at the door as "not signed in" while the same
162
+ // sign-in renewed at the first try twelve minutes later. Read BEFORE that pattern, which keeps `oauth`: "OAuth
163
+ // session expired and could not be refreshed" is a real sign-out and matches through nothing else.
164
+ const REFRESH_LOCKED_RE = /another Claude Code process is (?:refreshing it|holding the refresh lock)/i;
156
165
  const TIER_RE = /model[_ -]?not[_ -]?found|unknown model|not a valid model|does not have access|no access to|model .{0,40}(?:not available|unavailable|not supported|unsupported)|unsupported model|no claude model mapped|no GPT tier mapped|permission[_ ]error/i;
157
166
 
158
167
  const tail = (s) => {
@@ -347,6 +356,22 @@ export function classifyProbe({ engine, tuple = null, error = null, timeoutSec =
347
356
  { resetsAt: s.resetsAt ?? null, detail });
348
357
  }
349
358
 
359
+ // A turn that ran and failed, in words that claim nothing they cannot see: the last answer below, and the
360
+ // locked refresh, whose explanation is the engine's own and rides in `detail`.
361
+ const ranAndFailed = (mode, basis) => v(mode, basis, `${id} ran but the turn failed (exit ${tuple.code})`,
362
+ "The engine's stderr below is the whole story; a turn that starts and fails is not a configuration this check can name.", { detail });
363
+
364
+ // A SIGN-IN REFRESH ANOTHER COPY IS HOLDING, before the pattern that would read it as a sign-out. It answers
365
+ // as a turn that ran and failed, with the program's "retry in a minute" beneath, under a mode of its own:
366
+ // outside the configuration lane, and the one the run door checks again once the lock has gone stale.
367
+ if (REFRESH_LOCKED_RE.test(text)) return ranAndFailed("refresh-locked", "text-match");
368
+
369
+ // A CODEX RENEWAL THAT FAILED WITHOUT BEING REFUSED (the adapter's signal, openai-agent.mjs), before the
370
+ // sign-in pattern too: a dropped connection's line names the renewal address, ".../oauth/token", and the
371
+ // pattern read that as a sign-out (measured offline on 0.162.0, 2026-11-03). The same answer as the locked
372
+ // refresh, and the same second check at the door.
373
+ if (s.refreshFailed) return ranAndFailed("refresh-failed", "text-match");
374
+
350
375
  // THE MODE STAYS `signed-out` UNDER EVERY WAY OF PAYING, because the run door refuses on the mode and a
351
376
  // refused credential is as much this machine's to fix as a signed-out program. Only the words follow how
352
377
  // the turn is paid for.
@@ -373,8 +398,7 @@ export function classifyProbe({ engine, tuple = null, error = null, timeoutSec =
373
398
  ? `That is what refused credentials look like, so start there: check ${refused.check}, then run this again. The engine's stderr below is the diagnosis if it is something else.`
374
399
  : `That is the signed-out shape, so start there: ${signInLine(id, program)}, then run this again. The engine's stderr below is the diagnosis if it is something else.`, { detail });
375
400
 
376
- return v("failed", "nonzero-exit", `${id} ran but the turn failed (exit ${tuple.code})`,
377
- "The engine's stderr below is the whole story; a turn that starts and fails is not a configuration this check can name.", { detail });
401
+ return ranAndFailed("failed", "nonzero-exit");
378
402
  }
379
403
 
380
404
  /** What fixes a host that refuses every tool call. On codex it is its own sandbox, and the setting is named. */
@@ -687,18 +711,49 @@ export async function probeEngineTurn({
687
711
  * or a missing `runTurn` export escapes as a raw error. That is a driver bug, and a driver bug must not
688
712
  * reach a client as a terminal refusal at the door — it fails open, loudly, and the run dies at stage one
689
713
  * with the engine's own message if it is real.
714
+ *
715
+ * A SIGN-IN REFRESH ANOTHER COPY IS HOLDING IS CHECKED ONCE MORE. The program says to retry in a minute, and
716
+ * its lock goes stale 60 s after its holder last renewed it, so the door waits `REFRESH_LOCK_WAIT_MS` and runs
717
+ * the probe again. The second verdict is the door's answer: a pass starts the run, a configuration fault
718
+ * refuses, and a lock still held is weather like any other. It carries the first as `recheckedAfter`, for the
719
+ * run record. `opts.wait` stands in for the wait, in tests.
720
+ *
721
+ * A CODEX RENEWAL THAT FAILED WITHOUT BEING REFUSED gets the same second check: a passing outage at the
722
+ * provider's sign-in, which a minute's wait may outlast.
690
723
  */
691
724
  export async function preflightEngineTurn(opts = {}) {
692
- let verdict;
693
- try {
694
- verdict = await probeEngineTurn(opts);
695
- } catch (e) {
696
- verdict = { ok: false, engine: String((opts?.env ?? process.env).CLEAROTRON_AI || DEFAULT_ENGINE_ID),
697
- mode: "probe-error", basis: "driver-bug", detail: null,
698
- headline: "the engine probe itself failed to run", fix: `This is a bug in the probe, not a fault on this box: ${String(e?.message ?? e)}` };
725
+ let verdict = await doorProbe(opts);
726
+ if (RECHECKED_MODES.has(verdict.mode)) {
727
+ const first = verdict;
728
+ console.error(`[preflight] ${probeFailureText(first)}${first.detail ? `\n engine said: ${first.detail}` : ""}\n`
729
+ + ` CHECKING AGAIN in ${REFRESH_LOCK_WAIT_MS / 1000}s (${first.mode}/${first.basis}): the engine could not renew its sign-in just now.`);
730
+ await (opts.wait ?? sleep)(REFRESH_LOCK_WAIT_MS);
731
+ verdict = { ...await doorProbe(opts),
732
+ recheckedAfter: { mode: first.mode, basis: first.basis, detail: first.detail, waitedMs: REFRESH_LOCK_WAIT_MS } };
699
733
  }
700
734
  if (verdict.ok) return verdict;
701
735
  if (probeVerdictLane(verdict) !== "configuration") return { ...verdict, warning: probeWeatherWarning(verdict) };
702
736
  const detail = verdict.detail ? `\n engine said: ${verdict.detail}` : "";
703
737
  throw new Error(`[preflight] ${probeFailureText(verdict)}${detail}`);
704
738
  }
739
+
740
+ /**
741
+ * How long the door waits before checking a locked refresh again: the lock goes stale 60 s after its holder last
742
+ * renewed it (Claude Code 2.1.295 renews it every 5 s while it holds it), so 65 s from the first answer is past
743
+ * that whenever the holder stopped.
744
+ */
745
+ export const REFRESH_LOCK_WAIT_MS = 65_000;
746
+ /** The verdicts the door checks once more after that wait: a sign-in renewal that could not happen just now. */
747
+ const RECHECKED_MODES = new Set(["refresh-locked", "refresh-failed"]);
748
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
749
+
750
+ /** One probe, as the door reads it: every throw from underneath is a verdict (see `preflightEngineTurn`). */
751
+ async function doorProbe(opts) {
752
+ try {
753
+ return await probeEngineTurn(opts);
754
+ } catch (e) {
755
+ return { ok: false, engine: String((opts?.env ?? process.env).CLEAROTRON_AI || DEFAULT_ENGINE_ID),
756
+ mode: "probe-error", basis: "driver-bug", detail: null,
757
+ headline: "the engine probe itself failed to run", fix: `This is a bug in the probe, not a fault on this box: ${String(e?.message ?? e)}` };
758
+ }
759
+ }
@@ -810,6 +810,8 @@ const OWN_RIGHTS_KEYS = ["source"];
810
810
  const DEADLINE_KEYS = ["kind", "date"]; // #6 — a CLIENT-facing time-critical date (opposition / SOU / renewal)
811
811
 
812
812
  const short = (v) => String(v ?? "").replace(/\s+/g, " ").trim().slice(0, 40);
813
+ /** The parser's words for an ordinal that is missing, not a whole number, or below 1. The save's transport uses them too. */
814
+ export const findingOrdinalInvalid = (ord) => `finding_ordinal_invalid:${short(ord)} (ordinal must be an integer >= 1)`;
813
815
  // The version-laddered key allowlists, in ONE place — both parsers (strict + lenient) read it, so a new
814
816
  // version can never tighten one path and leave the other on the old list.
815
817
  const topKeysFor = (mode) => (mode.v7 ? TOP_KEYS_V7 : mode.v6 ? TOP_KEYS_V6 : mode.v5 ? TOP_KEYS_V5 : mode.v4 ? TOP_KEYS_V4 : TOP_KEYS);
@@ -1379,7 +1381,7 @@ function validateFinding(f, idx, seenOrdinals, mode = { v4: false, manifest: nul
1379
1381
 
1380
1382
  // ordinal — 1-based, integer, unique (the F1/F2 drill-through id; markers and cards share it).
1381
1383
  const ord = f.ordinal;
1382
- if (!Number.isInteger(ord) || ord < 1) throw new Error(`finding_ordinal_invalid:${short(ord)} (ordinal must be an integer >= 1)`);
1384
+ if (!Number.isInteger(ord) || ord < 1) throw new Error(findingOrdinalInvalid(ord));
1383
1385
  if (seenOrdinals.has(ord)) throw new Error(`finding_ordinal_duplicate:${ord} (each finding's ordinal must be unique)`);
1384
1386
  seenOrdinals.add(ord);
1385
1387
 
@@ -1813,7 +1815,7 @@ function validateNet(f, ord, mode) {
1813
1815
  // `findings?_` and would aim the repair turn at register-coverage-ledger.json — forbidding the model
1814
1816
  // to rewrite the only file that could fix it.
1815
1817
  // It reaches the wire as a validator `reason` (verify.mjs checkFindingsSibling), which is the only shape
1816
- // gateway.mjs:1200 judgeArtifacts mints as `invalid_file:<path>:<token>`; a bespoke throw would match nothing.
1818
+ // gateway.mjs:1204 judgeArtifacts mints as `invalid_file:<path>:<token>`; a bespoke throw would match nothing.
1817
1819
  // The precedent is one line up the file: findings_mark_assessment_* was named plural for the same
1818
1820
  // routing reason.
1819
1821
  //
@@ -887,7 +887,11 @@ async function runStageLadder(name, opts, stageCodexHome = null) {
887
887
  // sweep) — a hard-wall timeout breaks after ONE attempt (a 1.5× extension can't fit
888
888
  // an already-over-budget resume; the caller records the coverage-limited deferral).
889
889
  excludeTools, bandSize, derivedLimit = null, // copper-lattice re-route: tool names dropped from this stage's allowedTools
890
+ // THE CORRECTION THIS DISPATCH IS, when it is one: `{positions}`, the excluded positions its flags name. Its save may
891
+ // add a finding for them, and its retries say so (`patchRows`); every other dispatch carries none.
892
+ correction = null,
890
893
  } = opts;
894
+ const adds = Boolean(correction);
891
895
  if (!message) throw new Error(`runStage(${name}): message is required`);
892
896
  if (!sessionKey) throw new Error(`runStage(${name}): sessionKey is required`);
893
897
  const files = (Array.isArray(expectFile) ? expectFile : [expectFile]).filter(Boolean);
@@ -930,7 +934,7 @@ async function runStageLadder(name, opts, stageCodexHome = null) {
930
934
  // The bound card index rides the same label the grant was resolved from — derived by the SAME
931
935
  // declared rule (`perAxis`), never by a second string-sniff that could disagree with it.
932
936
  const cfg = buildGatherMcpConfig(groups, { sessionKey, agent, runDir, recordAxis: recordAxisFor(name)?.axis,
933
- bandGroups: GROUP_READING_STAGES.has(name) });
937
+ bandGroups: GROUP_READING_STAGES.has(name), correctionPositions: correction?.positions ?? null });
934
938
  gatherMcpConfig = cfg ? JSON.stringify(cfg) : undefined;
935
939
  gatherAllowedTools = allowedToolsFor(groups);
936
940
  gatherSeatWrites = seatWritesForGroups(groups); // — the SAME derivation allowedToolsFor uses
@@ -1091,7 +1095,7 @@ async function runStageLadder(name, opts, stageCodexHome = null) {
1091
1095
  try { const fresh = refreshMessage(attempt); if (typeof fresh === "string" && fresh) base = fresh; }
1092
1096
  catch (e) { note(`[${name}] refreshMessage failed on attempt ${attempt}, dispatching the original text: ${String(e?.message ?? e).slice(0, 120)}`); }
1093
1097
  }
1094
- const effMessage = warm ? warmPatchMessage(lastFail, files, { supplementalLane }) : correctiveMessage(base, attempt, lastFail, files, { supplementalLane });
1098
+ const effMessage = warm ? warmPatchMessage(lastFail, files, { supplementalLane, adds }) : correctiveMessage(base, attempt, lastFail, files, { supplementalLane, adds });
1095
1099
  note(`[${name}] attempt ${attempt}/${maxRetries + 1}${warm ? " [warm patch]" : ""} (engine=${engine.name} agent=${agent} model=${model ?? "default"} key=${key} timeout=${effTimeout}s)`);
1096
1100
  // The engine runs ONE turn and returns the normalized tuple. Every adapter returns the same shape
1097
1101
  // (zero change); anthropic-agent = claude -p off-gateway with the stall-watchdog. A warm retry threads
@@ -1351,7 +1355,7 @@ async function runStageLadder(name, opts, stageCodexHome = null) {
1351
1355
  note(`[${name}] FORM defect at write time (${triggeredBy.slice(0, 140)}) — repairing INSIDE this dispatch (${formRepairsUsed}/${MAX_FORM_REPAIRS}) at ${rel(target)}; the retry ladder is not charged`);
1352
1356
  //: a form repair is a real model invocation, so it gets its own record rather than hiding
1353
1357
  // inside the attempt it belongs to. Hoisted only to be recordable — the message is unchanged.
1354
- const repairMessage = warmPatchMessage(triggeredBy, files, { supplementalLane });
1358
+ const repairMessage = warmPatchMessage(triggeredBy, files, { supplementalLane, adds });
1355
1359
  const repairDispatch = envGateOn("CLEAROTRON_DISPATCH_RECORD")
1356
1360
  ? recordDispatch(runDir, name, { attempt, repair: formRepairsUsed + 1, kind: "form-repair", message: repairMessage })
1357
1361
  : null;
@@ -2250,7 +2254,7 @@ function rel(p) {
2250
2254
  // missing_file) get corrective text — a timeout/transport failure is fixed by re-running, not by different content.
2251
2255
  // opts.supplementalLane (trailing + optional, so every positional caller is unchanged): the failing stage
2252
2256
  // ran without register_enumerate, so a hint that names it would contradict the prompt it is appended to.
2253
- export function correctiveMessage(baseMessage, attempt, lastFail, expectFile, { supplementalLane = false } = {}) {
2257
+ export function correctiveMessage(baseMessage, attempt, lastFail, expectFile, { supplementalLane = false, adds = false } = {}) {
2254
2258
  if (attempt <= 1 || !lastFail) return baseMessage;
2255
2259
  // A6 (addendum 2026-07-30): the max_tokens fault wraps the underlying content failure (or stands bare
2256
2260
  // on a transport-shaped turn). The retry must be told the CAUSE was the output ceiling — an unnamed
@@ -2287,7 +2291,7 @@ export function correctiveMessage(baseMessage, attempt, lastFail, expectFile, {
2287
2291
  `\n\nCORRECTION: ${budget}${requiredFileClause(inner, { names, toolWritten })}`;
2288
2292
  return baseMessage +
2289
2293
  `\n\nCORRECTION: your previous attempt failed file validation (${inner}). ${budget}Re-do the task and make sure ` +
2290
- `${correctionHint(inner, { gridLedgerName: gridLedgerNameFor(expectFile), supplementalLane, undispatchable: frameDiffUndispatchable(expectFile, inner), heldRecord: heldSynthesisRecord(files) })}. ` +
2294
+ `${correctionHint(inner, { gridLedgerName: gridLedgerNameFor(expectFile), supplementalLane, undispatchable: frameDiffUndispatchable(expectFile, inner), heldRecord: heldSynthesisRecord(files), adds })}. ` +
2291
2295
  requiredFileClause(inner, { names, toolWritten });
2292
2296
  }
2293
2297
 
@@ -2377,16 +2381,22 @@ const CLEARANCE_FINDINGS_TOKEN_RE = /(?<!knockout_|knockoutassess_)findings?_/;
2377
2381
  // patch the follow-ups above it ask for. A record nobody saved yet, or one whose version is being replaced, still
2378
2382
  // takes the complete save.
2379
2383
  // The patch a held record takes, in the tool's own words; the retry for most findings checks leaves the narrative as it is.
2380
- const HELD_RECORD_PATCH = "ONE `record_synthesis` PATCH call, sending only the change: `findings_patch` carrying the complete corrected finding object(s), each with the `ordinal` it replaces, and `findings` carrying any register you corrected, complete, and never a `findings[]` list";
2381
- const HELD_RECORD_RETRY = `Fix exactly that in ${HELD_RECORD_PATCH}; leave the narrative prose unchanged`;
2384
+ // On the correction answering a review's flags, and on its retries, the rows are described in the words ruled for that
2385
+ // correction (2026-11-02): it may add the finding for an excluded position its flags name (synthesis-record.mjs).
2386
+ export const REPLACED_ROWS = "the complete corrected finding object(s), each with the `ordinal` it replaces";
2387
+ export const CORRECTION_ROWS = "the complete finding objects you changed or added: keep each existing finding's `ordinal`; for a new finding answering a flag about an excluded position named in this correction, use the next unused ordinal after the highest in the current record and cite a record from that position";
2388
+ /** The rows a held record's patch carries: on a correction's dispatch (`adds`), the finding it may add among them. PURE. */
2389
+ export const patchRows = (adds = false) => (adds ? CORRECTION_ROWS : REPLACED_ROWS);
2390
+ const heldRecordPatch = (adds = false) => `ONE \`record_synthesis\` PATCH call, sending only the change: \`findings_patch\` carrying ${patchRows(adds)}, and \`findings\` carrying any register you corrected, complete, and never a \`findings[]\` list`;
2391
+ const heldRecordRetry = (adds = false) => `Fix exactly that in ${heldRecordPatch(adds)}; leave the narrative prose unchanged`;
2382
2392
  const VERSION_FAILURE_RE = /finding_legacy_scale_forbidden|schema_version/;
2383
2393
  // A USE CHECK'S CORRECTION corrects what depends on the finding too, so it never says to leave the narrative as it is
2384
2394
  // (design, 2026-10-28). A held record takes the patch, in the tool's own words, with the narrative sections it changes;
2385
2395
  // a record not yet accepted is completed by its first call, which the line after every hint names. The caller prints a
2386
2396
  // full stop after the hint, so the ruled sentences go without their last one.
2387
2397
  const USE_CHECK_TOKEN_RE = /finding_use_check_(missing|source_missing):/;
2388
- const useCheckCorrection = (heldRecord) => heldRecord
2389
- ? `${RESEARCH_CORRECTION} Send it in ${HELD_RECORD_PATCH}. In \`narrative\`, send only the sections you changed — the rest are held`
2398
+ const useCheckCorrection = (heldRecord, adds = false) => heldRecord
2399
+ ? `${RESEARCH_CORRECTION} Send it in ${heldRecordPatch(adds)}. In \`narrative\`, send only the sections you changed — the rest are held`
2390
2400
  : RESEARCH_CORRECTION.replace(/\.$/, "");
2391
2401
  /**
2392
2402
  * Does the driver hold an accepted synthesis record for the run these files belong to? Read from either of the files
@@ -2397,7 +2407,7 @@ export const heldSynthesisRecord = (files) => {
2397
2407
  return Boolean(f) && existsSync(synthesisCallPaths(dirname(f)).accepted);
2398
2408
  };
2399
2409
 
2400
- export function correctionHint(lastFail, { gridLedgerName = "common-law-grid.json", supplementalLane = false, undispatchable = [], toolWritten = null, heldRecord = false } = {}) {
2410
+ export function correctionHint(lastFail, { gridLedgerName = "common-law-grid.json", supplementalLane = false, undispatchable = [], toolWritten = null, heldRecord = false, adds = false } = {}) {
2401
2411
  // The repair act, for the hints that name one. Kept to a single sentence and a single decision so a
2402
2412
  // new hint has one thing to append rather than a branch to reproduce.
2403
2413
  const resaveClause = toolWritten
@@ -2497,8 +2507,8 @@ export function correctionHint(lastFail, { gridLedgerName = "common-law-grid.jso
2497
2507
  `registration — never overwrite or transpose another's facts; a finding with no fetched record → []), the four ` +
2498
2508
  `meters as {token, basis} (basis = verified-from-record | inferred-from-signal), quadrant {x,y} in [0,1], a ` +
2499
2509
  `typed source, a disposition, and a unique 1-based ordinal. The failed check was: ${tok}.${extra} ` +
2500
- (USE_CHECK_TOKEN_RE.test(lastFail) ? useCheckCorrection(heldRecord)
2501
- : heldRecord && !VERSION_FAILURE_RE.test(lastFail) ? HELD_RECORD_RETRY
2510
+ (USE_CHECK_TOKEN_RE.test(lastFail) ? useCheckCorrection(heldRecord, adds)
2511
+ : heldRecord && !VERSION_FAILURE_RE.test(lastFail) ? heldRecordRetry(adds)
2502
2512
  : `Fix exactly that, re-save the COMPLETE findings.json, and leave the narrative prose unchanged`);
2503
2513
  } else if (/coverage_status_offenum/.test(lastFail)) {
2504
2514
  // D1 — the off-enum PROSE Status cell (distinct from coverage_status_invalid, which is the JSON
@@ -3535,7 +3545,7 @@ function repairSiblingName(lastFail, expectFile) {
3535
3545
  : null;
3536
3546
  }
3537
3547
 
3538
- export function warmPatchMessage(lastFail, expectFile, { supplementalLane = false } = {}) {
3548
+ export function warmPatchMessage(lastFail, expectFile, { supplementalLane = false, adds = false } = {}) {
3539
3549
  const files = (Array.isArray(expectFile) ? expectFile : [expectFile]).filter(Boolean);
3540
3550
  const names = files.map(rel).join(", ");
3541
3551
  // named_band_missing (2026-07-14, copper-keystone): the band is ABSENT, not defective — the repair is a
@@ -3655,7 +3665,7 @@ export function warmPatchMessage(lastFail, expectFile, { supplementalLane = fals
3655
3665
  ? `Do NOT redo the work from scratch. This stage's own output is the driver's — it is rendered from your \`${outIsToolWritten.tool}\` call and you hold no tool that writes it, so there is nothing there for you to rewrite or protect.`
3656
3666
  : `Do NOT redo the work from scratch, and do NOT rewrite ${names || "the findings file"} (it already passed validation).`;
3657
3667
  return `You are RESUMING your own session for this stage — your prior work and inputs are already in your context. ${standsClause}\n` +
3658
- `Your saved ${sibling} failed validation (${lastFail}). Fix exactly this: ensure ${correctionHint(lastFail, { gridLedgerName: gridLedgerNameFor(files), supplementalLane, undispatchable: frameDiffUndispatchable(files, lastFail), heldRecord: heldSynthesisRecord(files) })}.\n` +
3668
+ `Your saved ${sibling} failed validation (${lastFail}). Fix exactly this: ensure ${correctionHint(lastFail, { gridLedgerName: gridLedgerNameFor(files), supplementalLane, undispatchable: frameDiffUndispatchable(files, lastFail), heldRecord: heldSynthesisRecord(files), adds })}.\n` +
3659
3669
  `Re-save the COMPLETE corrected JSON at ${sib}. Do not stop until it exists and is valid.`;
3660
3670
  }
3661
3671
  // — A BLIND-FRAME REPAIR IS A TOOL CALL, NOT A FILE WRITE, and this branch is what stops the two
@@ -3707,7 +3717,7 @@ export function warmPatchMessage(lastFail, expectFile, { supplementalLane = fals
3707
3717
  // DIRECTIVES again, which is the 2026-07-29 reopen loss. Caught by frame-diff-model.test.mjs's
3708
3718
  // cardinality pin, which asserts the warm path carries the full list without the caller passing
3709
3719
  // anything.
3710
- : `What you sent did not pass (${lastFail}). Fix exactly this: ensure ${correctionHint(lastFail, { supplementalLane, undispatchable: frameDiffUndispatchable(files, lastFail), toolWritten: toolWritten.tool, heldRecord: heldSynthesisRecord(files) })}.\n`) +
3720
+ : `What you sent did not pass (${lastFail}). Fix exactly this: ensure ${correctionHint(lastFail, { supplementalLane, undispatchable: frameDiffUndispatchable(files, lastFail), toolWritten: toolWritten.tool, heldRecord: heldSynthesisRecord(files), adds })}.\n`) +
3711
3721
  `Call \`${toolWritten.tool}\` with the values from the work already in your context — never by writing or editing any file. ` +
3712
3722
  `Do not stop until the tool accepts the call.`;
3713
3723
  }
@@ -3727,7 +3737,7 @@ export function warmPatchMessage(lastFail, expectFile, { supplementalLane = fals
3727
3737
  }
3728
3738
  const defective = failingTarget(lastFail, files) ?? files[0] ?? null;
3729
3739
  return `You are RESUMING your own session for this stage — your prior work and inputs are already in your context. Do NOT redo the work from scratch.\n` +
3730
- `Your saved ${defective ? rel(defective) : names || "output"} failed validation (${lastFail}). Fix exactly this: ensure ${correctionHint(lastFail, { gridLedgerName: gridLedgerNameFor(files), supplementalLane, undispatchable: frameDiffUndispatchable(files, lastFail), heldRecord: heldSynthesisRecord(files) })}.\n` +
3740
+ `Your saved ${defective ? rel(defective) : names || "output"} failed validation (${lastFail}). Fix exactly this: ensure ${correctionHint(lastFail, { gridLedgerName: gridLedgerNameFor(files), supplementalLane, undispatchable: frameDiffUndispatchable(files, lastFail), heldRecord: heldSynthesisRecord(files), adds })}.\n` +
3731
3741
  editRepairTail(defective || names || "the stage output");
3732
3742
  }
3733
3743
 
@@ -8,7 +8,9 @@
8
8
  //
9
9
  // complete the run holds the text whole, on a basis the record names: a full record from an operation
10
10
  // whose goods are whole (the record text, the register's own flag on a retrieved record, the
11
- // bulk register statement), or a search answer's statement shorter than its documented cut;
11
+ // bulk register statement), a search answer's statement shorter than its documented cut, or the
12
+ // register's own page, saved by the run's research, continuing a statement the search answer cut
13
+ // or did not establish whole;
12
14
  // cut the register marked the statement as cut: a missing word proves nothing;
13
15
  // unknown goods are held and their completeness is not established: a search answer's unflagged
14
16
  // statement at or over the default answer's documented cut, a retrieved record's statement with
@@ -191,7 +193,8 @@ export function recordGoodsEvidence(record, { goods = null, held = null, fetches
191
193
  const readable = statements?.length ? statements.some((g) => g?.en !== false) : null;
192
194
  const cut = (statements ?? []).some((g) => g?.cut === true);
193
195
  const unknown = (statements ?? []).some((g) => g?.unknown === true);
194
- const row = (state, source, basis) => ({ uri, state, source, basis, readable, held: body, fetch });
196
+ const page = (statements ?? []).find((g) => g?.page)?.page ?? null;
197
+ const row = (state, source, basis, extra = null) => ({ uri, state, source, basis, ...extra, readable, held: body, fetch });
195
198
  // The statements are a held body's where the reader says so; a reader that cannot tell reads bodies only.
196
199
  if (statements?.length && fromBody) {
197
200
  const op = body?.goods?.operation ?? "undocumented";
@@ -199,6 +202,10 @@ export function recordGoodsEvidence(record, { goods = null, held = null, fetches
199
202
  cut ? "register-flag" : unknown ? (op === "retrieve" ? "retrieved-record-without-flag" : "full-record-operation-undocumented")
200
203
  : op === "retrieve" ? "register-flag" : op === "bulk-register" ? "bulk-register-statement" : "full-record");
201
204
  }
205
+ // A search answer's statements that a register page the run's research saved continues whole (record-goods.mjs
206
+ // `rowGoods`). The record rests on that page once none is left cut or not established whole; where its classes were
207
+ // continued from pages two questions saved, the question named is its first such class's.
208
+ if (statements?.length && page && !cut && !unknown) return row("complete", "register-page", "register-page-statement", { question: page.question });
202
209
  if (statements?.length) return row(cut ? "cut" : unknown ? "unknown" : "complete", "search-row",
203
210
  cut ? "register-flag" : unknown ? "default-answer-at-or-over-its-cut" : "default-answer-under-its-cut");
204
211
  if (body) {
@@ -216,10 +223,13 @@ export function recordGoodsEvidence(record, { goods = null, held = null, fetches
216
223
  * WHAT A RECORD'S GOODS REST ON, IN THE WORDS THE STAGES READ (the band lookup's `goods_from`, the write-up's list):
217
224
  * the supporting evidence the record holds and its completeness, never the last call made for it. "No goods listed"
218
225
  * needs a full record from an operation whose goods are whole, with the field there and empty; a record whose goods
219
- * field is missing is "completeness not established". null where there is no evidence row. PURE.
226
+ * field is missing is "completeness not established". Goods continued whole from a register page the run's research
227
+ * saved name the question that saved it (`question`, which a caller passing the row on carries with it). null where
228
+ * there is no evidence row. PURE.
220
229
  */
221
230
  export function goodsFromLabel(e) {
222
231
  if (!e) return null;
232
+ if (e.source === "register-page") return registerPageLabel(e.question);
223
233
  if (e.source === "record-body") return e.state === "absent" ? "official record, no goods listed"
224
234
  : e.state === "cut" ? "official record, cut by the register"
225
235
  : e.state === "unknown" ? "official record, completeness not established" : "official record";
@@ -228,6 +238,9 @@ export function goodsFromLabel(e) {
228
238
  return e.state === "unavailable" ? "fetch failed" : "nothing held";
229
239
  }
230
240
 
241
+ /** What the stages read for goods taken whole from a register page the run's research saved, naming the question. PURE. */
242
+ export const registerPageLabel = (question) => `the register's own page, saved by research question ${question}`;
243
+
231
244
  /** Records counted by state, by source and by basis; `unreadable` counts goods held in no language the engine reads. PURE. */
232
245
  export function goodsEvidenceTotals(rows) {
233
246
  const list = Array.isArray(rows) ? rows : [];
@@ -39,7 +39,7 @@ import { captureCall, mergeCapture, nextSeq } from "./call-capture.mjs";
39
39
  import { join } from "node:path";
40
40
  import { driverDir } from "../shared/driver-dir.mjs";
41
41
  import { normalizeRecordUri } from "./registry-fidelity.mjs";
42
- import { parseVerdict, countCitedDefects, parseCorrectionKinds, correctionFlagContent, CORRECTION_KINDS } from "./verify.mjs";
42
+ import { parseVerdict, countCitedDefects, parseCorrectionKinds, correctionFlagContent, CORRECTION_KINDS, SECTION_HEADING_RE } from "./verify.mjs";
43
43
 
44
44
  export const REVIEW_FILE = "senior-eye-review.md";
45
45
 
@@ -107,12 +107,27 @@ export function renderRefutation(verdict, flags, planAudit) {
107
107
  }
108
108
  if (planAudit && planAudit.length) {
109
109
  out.push("## PLAN-EXECUTION CHECK", "");
110
- for (const l of planAudit) out.push(String(l));
110
+ for (const l of planAudit) out.push(planAuditLine(l));
111
111
  out.push("");
112
112
  }
113
113
  return out.join("\n").replace(/\n+$/, "\n");
114
114
  }
115
115
 
116
+ // ── A PLAN-AUDIT LINE CANNOT OPEN A SECTION ─────────────────────────────────────────────────────────
117
+ //
118
+ // The audit's lines are the reviewer's own, and the parsers read a markdown heading or a line of capitals as
119
+ // a section heading. One that names corrections ("CORRECTION REVIEW SCOPE", written by a recheck after a
120
+ // correction) became the document's corrections section: `parseCorrections` then read only what followed it,
121
+ // the flags above it counted none, and the round-trip refused both calls of a recheck as
122
+ // `refutation_roundtrip_kinds:fact` (measured on a saved recheck, 2026-11-03). Any heading-shaped line also
123
+ // ends the audit for `countCitedDefects`. Such a line renders in bold, its words unchanged: it still reads as
124
+ // a sub-heading, and no parser reads it as one. The heading test is the parsers' own (verify.mjs).
125
+ function planAuditLine(line) {
126
+ const s = String(line);
127
+ const t = s.trim();
128
+ return SECTION_HEADING_RE.test(t) ? `**${t.replace(/^#{1,6}\s+/, "")}**` : s;
129
+ }
130
+
116
131
  const HEADING_OR_LIST = /^\s*(?:#{1,6}\s|(?:\*{0,2})(?:[-*•]|\d+[.)]|[A-Za-z][.)])(?:\*{0,2})\s)/;
117
132
  const textDefect = (t) => {
118
133
  if (typeof t !== "string" || !t.trim()) return "empty";
@@ -2,7 +2,7 @@
2
2
  "name": "clearotron-driver",
3
3
  "private": true,
4
4
  "type": "module",
5
- "version": "0.5.0-beta.7",
5
+ "version": "0.5.0-beta.9",
6
6
  "license": "AGPL-3.0-only",
7
7
  "description": "Deterministic driver for the trademark clearance workflow: orchestration in code (fan-out, fan-in barrier, gating, retries); the model does judgment leaves only, through a reasoning CLI spawned per stage.",
8
8
  "engines": {