clearotron 0.5.0-beta.8 → 0.5.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/.env.example +2 -1
- package/INSTALL.md +4 -3
- package/QUICKSTART.md +78 -0
- package/bin/onboard.mjs +9 -4
- package/build-info.json +2 -2
- package/docs/releases/0.5.0.md +77 -0
- package/driver/CHANGELOG.md +103 -0
- package/driver/contract-vocabulary.mjs +3 -3
- package/driver/corrections-delivered.mjs +7 -5
- package/driver/corrections-feedforward.mjs +89 -3
- package/driver/coverage-form.mjs +61 -2
- package/driver/degraded-parts.mjs +4 -0
- package/driver/engine/mcp/band-server.mjs +16 -6
- package/driver/engine/openai-agent.mjs +24 -1
- package/driver/engine/probe.mjs +64 -9
- package/driver/goods-evidence.mjs +33 -6
- package/driver/narrative-refutation-record.mjs +17 -2
- package/driver/package.json +1 -1
- package/driver/pipeline.mjs +373 -38
- package/driver/predelivery-lint.mjs +160 -10
- package/driver/publish/index.mjs +2 -2
- package/driver/record-fold.mjs +17 -0
- package/driver/record-goods.mjs +24 -8
- package/driver/register-plan.mjs +8 -3
- package/driver/repair-composers.mjs +61 -7
- package/driver/saved-register-pages.mjs +144 -0
- package/driver/stage-context.mjs +4 -0
- package/driver/suite-census.json +122 -14
- package/driver/terminal-clamp.mjs +21 -0
- package/driver/verify.mjs +6 -3
- package/mcp-server/CHANGELOG.md +12 -0
- package/mcp-server/package.json +1 -1
- package/package.json +2 -1
- package/portal-ui/package.json +1 -1
- package/providers/oauth-mcp-bridge/CHANGELOG.md +12 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/providers/signa/src/core.js +18 -4
- package/scripts/e2e-first-time.mjs +10 -6
- package/scripts/release-duplicate-notes.mjs +5 -0
|
@@ -25,7 +25,8 @@ import { classifyRecord, prepareTargets, SHAPE_TIERS, isLiveRecord, niceClassKey
|
|
|
25
25
|
import { recordQids } from "../../named-band.mjs";
|
|
26
26
|
import { normalizeRecordUri } from "../../registry-fidelity.mjs";
|
|
27
27
|
import { bandGoodsIndex, goodsFor, goodsWordCounter, goodsWordsMatched, rawGoodsCarried, untaggedIsEnglish, rowGoods } from "../../record-goods.mjs";
|
|
28
|
-
import { recordGoodsEvidence, heldRecordProvenance, recordFetchOutcomes, readRunCallRows, goodsFromLabel } from "../../goods-evidence.mjs";
|
|
28
|
+
import { recordGoodsEvidence, heldRecordProvenance, recordFetchOutcomes, readRunCallRows, goodsFromLabel, registerPageLabel } from "../../goods-evidence.mjs";
|
|
29
|
+
import { savedStatusPages } from "../../saved-register-pages.mjs";
|
|
29
30
|
import { DEFAULT_LEDGER_PATH } from "../../provider-usage.mjs";
|
|
30
31
|
|
|
31
32
|
const RUN_DIR = process.env.CLEAROTRON_BAND_RUN_DIR || "";
|
|
@@ -301,9 +302,15 @@ const shapeGoodsTest = () => {
|
|
|
301
302
|
testCache = { words, matched: goodsWordsMatched(words, { stems: true }) };
|
|
302
303
|
return testCache;
|
|
303
304
|
};
|
|
305
|
+
// THE REGISTER'S OWN PAGES THE RUN'S RESEARCH SAVED (saved-register-pages.mjs), read again at the start of each lookup
|
|
306
|
+
// and each record call, never once per server as the held bodies are: a stage's own research question can save a
|
|
307
|
+
// record's page after the stage's first lookup, and the stage reads it from its next one.
|
|
308
|
+
const statusPages = savedStatusPages(RUN_DIR);
|
|
309
|
+
let pagesNow = new Map();
|
|
304
310
|
// The record's body first; where the run holds none, the statements the row carries, as the shape reads them
|
|
305
|
-
// (`rowGoods`, a statement the register cut marked so); a row that carries its goods as
|
|
306
|
-
|
|
311
|
+
// (`rowGoods`, a statement the register cut marked so, or continued from a saved page); a row that carries its goods as
|
|
312
|
+
// one string stands in last.
|
|
313
|
+
const goodsOfRow = (r) => goodsFor(goodsIndex(), r) ?? rowGoods(r, pagesNow)
|
|
307
314
|
?? (typeof r?.goods === "string" && r.goods.trim() ? [{ classes: [], text: r.goods.trim(), ...(untaggedIsEnglish(r?.record_id) ? {} : { en: false }) }] : null);
|
|
308
315
|
// WHAT A RECORD'S GOODS REST ON, from the run's own files and its fetches, by the shared reader's one rule
|
|
309
316
|
// (goods-evidence.mjs `recordGoodsEvidence`): the supporting evidence the record holds, never the last call made
|
|
@@ -386,6 +393,7 @@ function bandLookup(params = {}) {
|
|
|
386
393
|
}
|
|
387
394
|
|
|
388
395
|
const all = Array.isArray(band?.enumerated) ? band.enumerated : [];
|
|
396
|
+
pagesNow = statusPages();
|
|
389
397
|
const hits = [];
|
|
390
398
|
let matched = 0;
|
|
391
399
|
for (const r of all) {
|
|
@@ -557,7 +565,8 @@ function bandRecord(params = {}) {
|
|
|
557
565
|
const parsed = hit.miss !== "unparsable-uri";
|
|
558
566
|
const key = normalizeRecordUri(uri) || normalizeRecordUri(`/${String(uri ?? "").trim().replace(/^\/+/, "")}`);
|
|
559
567
|
const bandRow = parsed && key ? bandRowFor(key) : null;
|
|
560
|
-
|
|
568
|
+
if (bandRow) pagesNow = statusPages();
|
|
569
|
+
const statements = bandRow ? rowGoods(bandRow, pagesNow) : null;
|
|
561
570
|
const fetched = parsed ? runEvidence().fetches : null;
|
|
562
571
|
const fetch = fetched && key ? (fetched.get(key) ?? fetched.get(key.split("/").pop())) : null;
|
|
563
572
|
const failed = Boolean(fetch?.failed && !fetch.ok);
|
|
@@ -572,7 +581,8 @@ function bandRecord(params = {}) {
|
|
|
572
581
|
return { isError: true, text: `${why} ${rest}` };
|
|
573
582
|
}
|
|
574
583
|
const goodsLines = statements.map((g) => JSON.stringify({ class: g.classes.join(",") || null, text: g.text,
|
|
575
|
-
goods_from: g.cut ? "search answer, cut by the register" : g.unknown ? "search answer, completeness not established"
|
|
584
|
+
goods_from: g.cut ? "search answer, cut by the register" : g.unknown ? "search answer, completeness not established"
|
|
585
|
+
: g.page ? registerPageLabel(g.page.question) : "search answer" }));
|
|
576
586
|
const text = [why, ...goodsLines, rest].join("\n");
|
|
577
587
|
const parts = splitAtLines(text, RESPONSE_CHARS);
|
|
578
588
|
const wanted = Number(params.part ?? 1);
|
|
@@ -610,7 +620,7 @@ const GROUP_PAGES = process.env.CLEAROTRON_BAND_GROUPS === "1";
|
|
|
610
620
|
// served the shape without them (the owner's ruling, 2026-10-14). Each is removed with the space before it, inside
|
|
611
621
|
// its line, so no line moves and the line each listed mark is printed on, which `linesByPart` reads, still holds.
|
|
612
622
|
// (band-shape.mjs `withoutPlacementOrders` removes them, with the shape's other placement-only orders and its group-page commands.)
|
|
613
|
-
const LOOKUP_DESCRIPTION = "Look up enumerated records in this run's frozen register band (read-only; logged to the reading audit). Filters AND together: record_id (exact uri), owner (substring), nice_class, tier (identical|near-identical|same-family|other|unclassifiable — classified against the shape's frozen targets), qid (exact plan-entry id — the plan-execution ledger join; a record surfaced by several slices matches under EVERY one of them), query (the _query slice that surfaced the record), text (substring of mark_text), status (substring), live_only, goods (words: records whose goods contain any of them, as whole words, singular or plural; a record with no goods on file matches too), group (a, b, c, d, rest or no_goods: that list's lines in the shape's order, one per mark of an owner), limit (default 20, max 100), offset (default 0: where in the matching records or lines to start — a capped answer names the offset where the next page starts). On each record served, `goods_words` gives the client's goods words its goods hold, as the shape tests them (k of N: the words), or null where its goods cannot be read; `goods_from` says what those goods rest on: official record; official record, cut by the register; official record, completeness not established; official record, no goods listed; search answer; search answer, cut by the register; search answer, completeness not established; fetch failed; or nothing held. The goods text is in band_record. Matching un-enumerated crowd descriptors ride along so a lookup can never mistake a counted-only zone for a clean.";
|
|
623
|
+
const LOOKUP_DESCRIPTION = "Look up enumerated records in this run's frozen register band (read-only; logged to the reading audit). Filters AND together: record_id (exact uri), owner (substring), nice_class, tier (identical|near-identical|same-family|other|unclassifiable — classified against the shape's frozen targets), qid (exact plan-entry id — the plan-execution ledger join; a record surfaced by several slices matches under EVERY one of them), query (the _query slice that surfaced the record), text (substring of mark_text), status (substring), live_only, goods (words: records whose goods contain any of them, as whole words, singular or plural; a record with no goods on file matches too), group (a, b, c, d, rest or no_goods: that list's lines in the shape's order, one per mark of an owner), limit (default 20, max 100), offset (default 0: where in the matching records or lines to start — a capped answer names the offset where the next page starts). On each record served, `goods_words` gives the client's goods words its goods hold, as the shape tests them (k of N: the words), or null where its goods cannot be read; `goods_from` says what those goods rest on: official record; official record, cut by the register; official record, completeness not established; official record, no goods listed; search answer; search answer, cut by the register; search answer, completeness not established; the register's own page, saved by research question <N>; fetch failed; or nothing held. The goods text is in band_record. Matching un-enumerated crowd descriptors ride along so a lookup can never mistake a counted-only zone for a clean.";
|
|
614
624
|
const LOOKUP_GROUP_CLAUSE = "group (a, b, c, d, rest or no_goods: that list's lines in the shape's order, one per mark of an owner), ";
|
|
615
625
|
const LOOKUP_OFFSET_GROUPS = "offset (default 0: where in the matching records or lines to start — a capped answer names the offset where the next page starts)";
|
|
616
626
|
const LOOKUP_OFFSET_BAND = "offset (default 0: where in the matching records to start — a capped answer names the offset where the next page starts)";
|
|
@@ -726,7 +726,26 @@ const RATE_LIMIT_RE = /\b429\b|rate.?limit|usage limit|quota|too many requests|i
|
|
|
726
726
|
// A SIGN-IN THAT CAN NO LONGER BE REFRESHED, in codex's own words (measured on a live install, 2026-09-11).
|
|
727
727
|
// Narrow on purpose: a register provider's 401 or 403 can land in a stage's stderr too, and reading that as
|
|
728
728
|
// the operator's codex login having expired would send them to sign in again for nothing.
|
|
729
|
-
|
|
729
|
+
//
|
|
730
|
+
// A REFUSED RENEWAL ONLY: a 401 at renewal, or codex's words for a token spent, expired or revoked. 0.162.0
|
|
731
|
+
// says "Failed to refresh token status=401 …" and "Your access token could not be refreshed because …"; the
|
|
732
|
+
// live capture of 2026-09-11 said "Failed to refresh token: 401 Unauthorized: …already been used…". A bare
|
|
733
|
+
// "failed to refresh token" also matched every renewal that failed for a passing reason, because 0.162.0
|
|
734
|
+
// writes that line for each one: a 503, a dropped connection, and an outage the renewal recovered from
|
|
735
|
+
// within the same turn (measured offline, 2026-11-03). Read as a sign-out, each of those ended the stage's
|
|
736
|
+
// retries on its first attempt.
|
|
737
|
+
const REFRESH_FAILED_RE = /refresh token (?:has|was) already been used|access token could not be refreshed|failed to refresh token(?::| status=) ?401\b/i;
|
|
738
|
+
// …AND A RENEWAL THAT FAILED WITHOUT BEING REFUSED, which is not a sign-out: the line codex writes for any
|
|
739
|
+
// renewal attempt that did not succeed. Its own signal, read only where the refusal above is absent, so the
|
|
740
|
+
// run door can check again after a wait (engine/probe.mjs) while a stage retries as on any failed turn.
|
|
741
|
+
//
|
|
742
|
+
// READ ON A KILLED TURN TOO. On a dropped connection codex does not end the turn: it retries the renewal, 44
|
|
743
|
+
// times in the door's 60 s probe on one measured run, until the watchdog stops it. The stopped turn's text
|
|
744
|
+
// still names the renewal address, ".../oauth/token", and the door's sign-in pattern reads that `oauth` as a
|
|
745
|
+
// sign-out, so a signal kept off killed turns let the door refuse the job (measured offline on 0.162.0,
|
|
746
|
+
// 2026-11-03). The signal stays off wherever the refusal above appears, whatever ended the turn, so a 401
|
|
747
|
+
// stays a sign-out.
|
|
748
|
+
const REFRESH_ATTEMPT_FAILED_RE = /failed to refresh token/i;
|
|
730
749
|
|
|
731
750
|
// A retry hint, WHEN THE MESSAGE HAPPENS TO CARRY ONE. Two anchored shapes and nothing clever: an
|
|
732
751
|
// explicit timestamp, or a relative delay with a unit. Anything else yields undefined and the driver
|
|
@@ -805,6 +824,7 @@ function settleTuple({ r, ev, resumeRef }) {
|
|
|
805
824
|
const rateLimitText = `${ev.turnFailed || ""}\n${ev.streamError || ""}\n${r.stderr || ""}`;
|
|
806
825
|
const rateLimited = !killed && RATE_LIMIT_RE.test(rateLimitText);
|
|
807
826
|
const signedOut = !killed && REFRESH_FAILED_RE.test(rateLimitText);
|
|
827
|
+
const refreshFailed = !REFRESH_FAILED_RE.test(rateLimitText) && REFRESH_ATTEMPT_FAILED_RE.test(rateLimitText);
|
|
808
828
|
const resetsAt = rateLimited ? parseResetHint(rateLimitText) : undefined;
|
|
809
829
|
return {
|
|
810
830
|
code: killed ? 137 : (failed ? (r.rawCode || 1) : 0),
|
|
@@ -859,6 +879,9 @@ function settleTuple({ r, ev, resumeRef }) {
|
|
|
859
879
|
// The engine's sign-in could not be refreshed: what the operator runs to fix it. The gateway names the
|
|
860
880
|
// stage's failure with it.
|
|
861
881
|
signedOut: signedOut ? "codex sign-in expired — run `codex login`, then start the search again" : undefined,
|
|
882
|
+
// A renewal attempt failed and was not refused, on a turn that ended or one the watchdog stopped. Read by the
|
|
883
|
+
// run door only; a stage's ladder treats the turn as any failed turn.
|
|
884
|
+
refreshFailed: refreshFailed || undefined,
|
|
862
885
|
// Every tool call refused and none completed: codex's own sandbox on this host, and what fixes it. The
|
|
863
886
|
// turn is still `ok` here; when the stage then fails, the gateway names its failure with this, as it
|
|
864
887
|
// names a sign-in, instead of the missing file the refusal left behind.
|
package/driver/engine/probe.mjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
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
|
+
}
|
|
@@ -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),
|
|
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
|
|
@@ -39,6 +41,11 @@ import { runPrefixSpellings } from "../shared/pre-rename-spellings.mjs";
|
|
|
39
41
|
|
|
40
42
|
export const GOODS_EVIDENCE_SCHEMA_VERSION = 1;
|
|
41
43
|
export const GOODS_EVIDENCE_FILE = "goods-evidence.json";
|
|
44
|
+
// THE EVIDENCE AS THE WRITER HAD IT. The record above is derived again with every band merge, the first merge of a
|
|
45
|
+
// resumed pass among them, from the bodies the run holds by then, so a record the writer had as a cut search answer can
|
|
46
|
+
// read later as an official record held whole. The driver keeps the record a cold dispatch of the writer was given
|
|
47
|
+
// (pipeline.mjs, around `stage`), and the delivery check compares the findings with that copy: what they were written on.
|
|
48
|
+
export const GOODS_EVIDENCE_AS_WRITTEN_FILE = "goods-evidence.as-written.json";
|
|
42
49
|
export const GOODS_STATES = Object.freeze(["complete", "cut", "unknown", "absent", "unavailable", "not-held"]);
|
|
43
50
|
|
|
44
51
|
const uriKey = (u) => normalizeRecordUri(u);
|
|
@@ -191,7 +198,8 @@ export function recordGoodsEvidence(record, { goods = null, held = null, fetches
|
|
|
191
198
|
const readable = statements?.length ? statements.some((g) => g?.en !== false) : null;
|
|
192
199
|
const cut = (statements ?? []).some((g) => g?.cut === true);
|
|
193
200
|
const unknown = (statements ?? []).some((g) => g?.unknown === true);
|
|
194
|
-
const
|
|
201
|
+
const page = (statements ?? []).find((g) => g?.page)?.page ?? null;
|
|
202
|
+
const row = (state, source, basis, extra = null) => ({ uri, state, source, basis, ...extra, readable, held: body, fetch });
|
|
195
203
|
// The statements are a held body's where the reader says so; a reader that cannot tell reads bodies only.
|
|
196
204
|
if (statements?.length && fromBody) {
|
|
197
205
|
const op = body?.goods?.operation ?? "undocumented";
|
|
@@ -199,6 +207,10 @@ export function recordGoodsEvidence(record, { goods = null, held = null, fetches
|
|
|
199
207
|
cut ? "register-flag" : unknown ? (op === "retrieve" ? "retrieved-record-without-flag" : "full-record-operation-undocumented")
|
|
200
208
|
: op === "retrieve" ? "register-flag" : op === "bulk-register" ? "bulk-register-statement" : "full-record");
|
|
201
209
|
}
|
|
210
|
+
// A search answer's statements that a register page the run's research saved continues whole (record-goods.mjs
|
|
211
|
+
// `rowGoods`). The record rests on that page once none is left cut or not established whole; where its classes were
|
|
212
|
+
// continued from pages two questions saved, the question named is its first such class's.
|
|
213
|
+
if (statements?.length && page && !cut && !unknown) return row("complete", "register-page", "register-page-statement", { question: page.question });
|
|
202
214
|
if (statements?.length) return row(cut ? "cut" : unknown ? "unknown" : "complete", "search-row",
|
|
203
215
|
cut ? "register-flag" : unknown ? "default-answer-at-or-over-its-cut" : "default-answer-under-its-cut");
|
|
204
216
|
if (body) {
|
|
@@ -216,10 +228,13 @@ export function recordGoodsEvidence(record, { goods = null, held = null, fetches
|
|
|
216
228
|
* 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
229
|
* the supporting evidence the record holds and its completeness, never the last call made for it. "No goods listed"
|
|
218
230
|
* 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".
|
|
231
|
+
* field is missing is "completeness not established". Goods continued whole from a register page the run's research
|
|
232
|
+
* saved name the question that saved it (`question`, which a caller passing the row on carries with it). null where
|
|
233
|
+
* there is no evidence row. PURE.
|
|
220
234
|
*/
|
|
221
235
|
export function goodsFromLabel(e) {
|
|
222
236
|
if (!e) return null;
|
|
237
|
+
if (e.source === "register-page") return registerPageLabel(e.question);
|
|
223
238
|
if (e.source === "record-body") return e.state === "absent" ? "official record, no goods listed"
|
|
224
239
|
: e.state === "cut" ? "official record, cut by the register"
|
|
225
240
|
: e.state === "unknown" ? "official record, completeness not established" : "official record";
|
|
@@ -228,6 +243,9 @@ export function goodsFromLabel(e) {
|
|
|
228
243
|
return e.state === "unavailable" ? "fetch failed" : "nothing held";
|
|
229
244
|
}
|
|
230
245
|
|
|
246
|
+
/** What the stages read for goods taken whole from a register page the run's research saved, naming the question. PURE. */
|
|
247
|
+
export const registerPageLabel = (question) => `the register's own page, saved by research question ${question}`;
|
|
248
|
+
|
|
231
249
|
/** Records counted by state, by source and by basis; `unreadable` counts goods held in no language the engine reads. PURE. */
|
|
232
250
|
export function goodsEvidenceTotals(rows) {
|
|
233
251
|
const list = Array.isArray(rows) ? rows : [];
|
|
@@ -250,11 +268,20 @@ export function deriveGoodsEvidence({ records = [], goods = null, held = null, f
|
|
|
250
268
|
return { schema_version: GOODS_EVIDENCE_SCHEMA_VERSION, totals: goodsEvidenceTotals(rows), records: rows };
|
|
251
269
|
}
|
|
252
270
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const p = driverDir(runDir, GOODS_EVIDENCE_FILE);
|
|
271
|
+
const readDriverJson = (runDir, name) => {
|
|
272
|
+
const p = driverDir(runDir, name);
|
|
256
273
|
if (!existsSync(p)) return null;
|
|
257
274
|
try { return JSON.parse(readFileSync(p, "utf8")); } catch { return null; }
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/** The record the run wrote, or null when there is none or it will not parse. IMPURE. */
|
|
278
|
+
export function readGoodsEvidence(runDir) {
|
|
279
|
+
return readDriverJson(runDir, GOODS_EVIDENCE_FILE);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The record the writer's last cold dispatch was given, or null when the run kept none or it will not parse. IMPURE. */
|
|
283
|
+
export function readGoodsEvidenceAsWritten(runDir) {
|
|
284
|
+
return readDriverJson(runDir, GOODS_EVIDENCE_AS_WRITTEN_FILE);
|
|
258
285
|
}
|
|
259
286
|
|
|
260
287
|
/**
|
|
@@ -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(
|
|
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";
|
package/driver/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "clearotron-driver",
|
|
3
3
|
"private": true,
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.5.0
|
|
5
|
+
"version": "0.5.0",
|
|
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": {
|