clearotron 0.5.0 → 0.5.1-beta.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/CONTRIBUTING.md +2 -2
- package/INSTALL.md +334 -302
- package/QUICKSTART.md +12 -4
- package/README.md +12 -7
- package/THIRD-PARTY-NOTICES.md +4 -4
- package/bin/README.md +14 -11
- package/bin/clearotron.mjs +1 -1
- package/bin/connect.mjs +73 -25
- package/bin/example.mjs +4 -2
- package/bin/onboard.mjs +562 -336
- package/bin/start.mjs +184 -36
- package/bin/update.mjs +26 -13
- package/build-info.json +2 -2
- package/docs/PORTAL.md +2 -2
- package/docs/architecture/02-architecture.md +3 -3
- package/docs/architecture/04-configuration-reference.md +1 -2
- package/docs/architecture/05-config-governance.md +1 -1
- package/docs/architecture/06-operations-runbook.md +1 -1
- package/driver/CHANGELOG.md +77 -0
- package/driver/README.md +2 -2
- package/driver/config-inventory.mjs +20 -11
- package/driver/contract-e3-backlog.mjs +27 -27
- package/driver/contract-e3-baseline.json +2 -2
- package/driver/contract-vocabulary.mjs +1 -1
- package/driver/degraded-parts.mjs +67 -3
- package/driver/dev-portal.mjs +1 -1
- package/driver/digest-queue.mjs +5 -5
- package/driver/driver.config.mjs +9 -9
- package/driver/engine/CONTRACT.md +1 -1
- package/driver/engine/anthropic-agent.mjs +4 -2
- package/driver/engine/mcp/band-server.mjs +1 -21
- package/driver/engine/mcp/clarivate-propose-tool.mjs +26 -0
- package/driver/engine/mcp/clarivate-server.mjs +2 -18
- package/driver/engine/mcp/fixture-register-server.mjs +33 -0
- package/driver/engine/mcp/gather-config.mjs +48 -7
- package/driver/engine/mcp/recording-server.mjs +206 -14
- package/driver/engine/mcp/supplemental.mjs +4 -2
- package/driver/engine/openai-agent.mjs +3 -1
- package/driver/engine/probe.mjs +10 -0
- package/driver/filing-goods.mjs +95 -0
- package/driver/findings-model.mjs +3 -0
- package/driver/gateway.mjs +42 -40
- package/driver/knockout-assess-record.mjs +54 -4
- package/driver/knockout-correction-record.mjs +342 -0
- package/driver/knockout-frame-record.mjs +4 -2
- package/driver/knockout-register-read.mjs +705 -0
- package/driver/knockout-register-record.mjs +222 -0
- package/driver/knockout-review-record.mjs +96 -25
- package/driver/narrative-refutation-record.mjs +87 -1
- package/driver/order-tables.mjs +23 -0
- package/driver/owner-use-check.mjs +5 -2
- package/driver/package.json +1 -1
- package/driver/partial-payload-baseline.json +8 -0
- package/driver/pipeline-knockout.mjs +506 -313
- package/driver/pipeline.mjs +179 -86
- package/driver/portal-local-auth.mjs +7 -1
- package/driver/portal-service.mjs +62 -6
- package/driver/progress.mjs +2 -2
- package/driver/publish/index.mjs +18 -21
- package/driver/publish/knockout.mjs +40 -18
- package/driver/publish/render-knockout.mjs +40 -27
- package/driver/publish/report-dates.mjs +43 -0
- package/driver/recall-reconciliation.mjs +2 -2
- package/driver/record-goods.mjs +50 -9
- package/driver/register-count.mjs +12 -59
- package/driver/register-fixture-marker.mjs +22 -0
- package/driver/register-plan.mjs +48 -0
- package/driver/register-records.mjs +84 -266
- package/driver/register-taint.mjs +2 -2
- package/driver/repair-composers.mjs +15 -8
- package/driver/result-noun-fields.mjs +6 -2
- package/driver/run-requirements.mjs +54 -4
- package/driver/runner.mjs +4 -13
- package/driver/skills/clearance-register/providers/clarivate.md +2 -2
- package/driver/skills/knockout-assess/SKILL.md +101 -100
- package/driver/skills/knockout-frame/SKILL.md +3 -1
- package/driver/skills/knockout-register-read/SKILL.md +77 -0
- package/driver/stages-knockout.mjs +159 -98
- package/driver/stages.mjs +4 -2
- package/driver/suite-census.json +389 -71
- package/driver/systemd/README.md +2 -2
- package/driver/verify-knockout.mjs +175 -39
- package/driver/verify.mjs +10 -9
- package/mcp-server/CHANGELOG.md +4 -0
- package/mcp-server/CONNECT.md +4 -0
- package/mcp-server/demo-mode.mjs +6 -0
- package/mcp-server/lib/demo-texts.mjs +38 -0
- package/mcp-server/lib/http-handler.mjs +7 -1
- package/mcp-server/lib/knockout.mjs +3 -2
- package/mcp-server/lib/options.mjs +3 -1
- package/mcp-server/lib/plan.mjs +6 -1
- package/mcp-server/mint-token.mjs +1 -1
- package/mcp-server/package.json +1 -1
- package/mcp-server/serve.mjs +11 -0
- package/mcp-server/server.mjs +13 -5
- package/package.json +1 -1
- package/portal-ui/dist/assets/{index-D2wrw9cH.css → index-AtB9ZpDH.css} +29 -0
- package/portal-ui/dist/assets/{index-DcLbvFmQ.js → index-C1oE78Wk.js} +161 -195
- package/portal-ui/dist/index.html +2 -2
- package/portal-ui/package.json +4 -4
- package/providers/README.md +4 -4
- package/providers/_shared/execute-plan.mjs +45 -1
- package/providers/_shared/term-shape.mjs +1 -1
- package/providers/clarivate/src/capabilities.js +7 -6
- package/providers/clarivate/src/core.js +11 -7
- package/providers/clarivate/src/wider-list.js +104 -0
- package/providers/oauth-mcp-bridge/CHANGELOG.md +4 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/providers/signa/src/capabilities.js +0 -9
- package/scripts/e2e-first-time.mjs +8 -7
- package/scripts/freeze-example-run.mjs +2 -2
- package/scripts/settings-render-check.mjs +5 -3
- package/scripts/test-run.mjs +8 -2
- package/shared/client-door.mjs +11 -8
- package/shared/connect-clients.mjs +10 -4
- package/shared/demo-connection.mjs +43 -0
- package/shared/demo-start-args.mjs +7 -2
- package/shared/invocation.mjs +18 -3
- package/shared/permanent-install.mjs +14 -0
- package/shared/scope.mjs +8 -1
- package/shared/stdio-connect.mjs +43 -21
- package/shared/trigger-lane.mjs +7 -0
- package/shared/tty-style.mjs +21 -5
|
@@ -0,0 +1,222 @@
|
|
|
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-register-record.mjs — record_knockout_register_read: the knockout's reading step, as a typed return path.
|
|
5
|
+
//
|
|
6
|
+
// The step asks its questions through the register's own tool, which writes every answer to the band itself. What
|
|
7
|
+
// comes back here is the part only judgment can say, per name: the filings it carries forward, what it set aside and
|
|
8
|
+
// why, and the questions it chose not to ask. The driver joins each to the band, so a record id is one the register
|
|
9
|
+
// returned, and refuses a record that leaves a read list, a crowd or a count unaccounted for: nothing set aside goes
|
|
10
|
+
// without its reason. A row that stands is kept when another is refused, so a repair sends only what it corrects, and a
|
|
11
|
+
// turn that ends early leaves what it had settled.
|
|
12
|
+
//
|
|
13
|
+
// THE ARTIFACT IS AT THE RUN ROOT, the rule the rest of this lane follows: `_driver/` holds the driver's own
|
|
14
|
+
// measurements, and this is a model's output.
|
|
15
|
+
|
|
16
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { basename, dirname, join } from "node:path";
|
|
18
|
+
|
|
19
|
+
import { captureCall, stampVerdict } from "./call-capture.mjs";
|
|
20
|
+
import { DRIVER_DIR, driverDir } from "../shared/driver-dir.mjs";
|
|
21
|
+
import { refuseUndeclared, lastAccepted, acceptedEnvelope } from "./preserve-merge.mjs";
|
|
22
|
+
import { addedClassQuestions, carriedIds, formQid, formsOfName, knockoutBandBlocks, knockoutProposals, namesAddedClass, openingQid, questionsOwed } from "./knockout-register-read.mjs";
|
|
23
|
+
|
|
24
|
+
const TOKEN = "knockoutregisterread";
|
|
25
|
+
const SCHEMA_VERSION = 1;
|
|
26
|
+
|
|
27
|
+
const DECLARED = {
|
|
28
|
+
"": ["schema_version", "marks"],
|
|
29
|
+
marks: ["name", "carried", "set_aside", "not_asked", "open_questions"],
|
|
30
|
+
"marks.carried": ["records", "why", "check_owner"],
|
|
31
|
+
"marks.set_aside": ["question", "records", "why"],
|
|
32
|
+
"marks.not_asked": ["question", "why"],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** The artifact this transport writes, at the run root. */
|
|
36
|
+
export const knockoutRegisterFile = (runDir) => join(String(runDir ?? ""), "knockout-register.json");
|
|
37
|
+
|
|
38
|
+
/** One file per call, refusals included, beside the other transports' capture directories. */
|
|
39
|
+
export function knockoutRegisterCallPaths(runDir) {
|
|
40
|
+
const dir = driverDir(runDir, "knockout-register-calls");
|
|
41
|
+
return { dir, accepted: join(dir, "accepted.json"), refusals: join(dir, "refusals.jsonl") };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const nameKey = (s) => String(s ?? "").trim().toLowerCase();
|
|
45
|
+
const text = (v) => (typeof v === "string" ? v.trim() : "");
|
|
46
|
+
|
|
47
|
+
/** A repair call merges by name onto what was accepted: a name it omits keeps its row, one it sends is replaced whole. PURE. */
|
|
48
|
+
export function mergeKnockoutRegisterCall(prior, received) {
|
|
49
|
+
if (!prior) return received;
|
|
50
|
+
const byName = new Map((Array.isArray(prior.marks) ? prior.marks : []).map((m) => [nameKey(m?.name), m]));
|
|
51
|
+
for (const m of Array.isArray(received?.marks) ? received.marks : []) byName.set(nameKey(m?.name), m);
|
|
52
|
+
return { ...prior, ...received, marks: [...byName.values()] };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The call's own shape, before anything on disk is read. PURE. */
|
|
56
|
+
export function acceptKnockoutRegister(call) {
|
|
57
|
+
const refuse = (what) => ({ ok: false, reason: `${TOKEN}_${what}` });
|
|
58
|
+
if (!Array.isArray(call?.marks) || !call.marks.length) return refuse("marks: send one row per instructed name.");
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
const marks = [];
|
|
61
|
+
for (const m of call.marks) {
|
|
62
|
+
const name = text(m?.name);
|
|
63
|
+
if (!name) return refuse("name: every row names the instructed name it answers for, verbatim.");
|
|
64
|
+
if (seen.has(nameKey(name))) return refuse(`duplicate:${name}: one row per name.`);
|
|
65
|
+
seen.add(nameKey(name));
|
|
66
|
+
for (const key of ["carried", "set_aside", "not_asked"]) {
|
|
67
|
+
if (!Array.isArray(m?.[key])) return refuse(`${key}:${name}: send a list; an empty one says there is none.`);
|
|
68
|
+
}
|
|
69
|
+
for (const g of m.carried) {
|
|
70
|
+
if (!Array.isArray(g?.records) || !g.records.length) return refuse(`carried_records:${name}: each carried group names its record ids.`);
|
|
71
|
+
if (!text(g?.why)) return refuse(`carried_why:${name}: a carried group says why, in one reason for the group.`);
|
|
72
|
+
}
|
|
73
|
+
for (const key of ["set_aside", "not_asked"]) {
|
|
74
|
+
for (const row of m[key]) {
|
|
75
|
+
if (!text(row?.question)) return refuse(`${key}_question:${name}: each row names the question it is about.`);
|
|
76
|
+
if (!text(row?.why)) return refuse(`${key}_why:${name}: ${text(row?.question)} carries no reason. Write down why.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
marks.push({ name,
|
|
80
|
+
carried: m.carried.map((g) => ({ records: [...new Set(g.records.map((r) => String(r)))], why: text(g.why), ...(g.check_owner === true ? { check_owner: true } : {}) })),
|
|
81
|
+
set_aside: m.set_aside.map((r) => ({ question: text(r.question), ...(Array.isArray(r.records) && r.records.length ? { records: r.records.map(String) } : {}), why: text(r.why) })),
|
|
82
|
+
not_asked: m.not_asked.map((r) => ({ question: text(r.question), why: text(r.why) })),
|
|
83
|
+
open_questions: (Array.isArray(m.open_questions) ? m.open_questions : []).map(text).filter(Boolean) });
|
|
84
|
+
}
|
|
85
|
+
return { ok: true, model: { schema_version: SCHEMA_VERSION, marks } };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const readJson = (path) => { try { return JSON.parse(readFileSync(path, "utf8")); } catch { return null; } };
|
|
89
|
+
|
|
90
|
+
/** Why one name's row cannot stand against what this run holds, or null. The record says what the step decided; this checks only that it adds up. */
|
|
91
|
+
function rowDefect(row, n, { counts, plan, runDir }) {
|
|
92
|
+
const countsEntry = (counts?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(n)) ?? null;
|
|
93
|
+
const framed = (plan?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(n)) ?? null;
|
|
94
|
+
const blocks = knockoutBandBlocks(runDir, n);
|
|
95
|
+
const rowsUnder = (qid) => { const b = blocks.get(qid); return (Array.isArray(b?.records) ? b.records : []).map((r) => String(r?.record_id ?? "")); };
|
|
96
|
+
const held = new Set([...blocks.keys()].flatMap(rowsUnder));
|
|
97
|
+
const carried = carriedIds(row);
|
|
98
|
+
const stranger = [...carried].find((id) => !held.has(id));
|
|
99
|
+
if (stranger) return `${TOKEN}_carried:${n}: "${stranger}" is not a record this name's questions returned. Copy record_id from the list you read.`;
|
|
100
|
+
const { entries } = knockoutProposals(runDir, n);
|
|
101
|
+
const addedQuestions = addedClassQuestions(runDir, n);
|
|
102
|
+
const asked = new Set([...blocks.keys(), ...entries.map((e) => String(e?.qid)), ...["identical", "containing", "close"].map((k) => openingQid(n, k)),
|
|
103
|
+
...formsOfName(n, framed).map((_, i) => formQid(n, i)), ...addedQuestions.map((q) => q.qid)]);
|
|
104
|
+
const unknown = row.set_aside.find((r) => !asked.has(r.question));
|
|
105
|
+
if (unknown) return `${TOKEN}_set_aside:${n}: "${unknown.question}" is not a question on this name. Name the question by its qid.`;
|
|
106
|
+
for (const r of row.set_aside) {
|
|
107
|
+
const under = new Set(rowsUnder(r.question));
|
|
108
|
+
const outsider = (r.records ?? []).find((id) => !under.has(id));
|
|
109
|
+
if (outsider) return `${TOKEN}_set_aside_records:${n}: "${outsider}" is not a filing of ${r.question}. Copy record_id from that question's list.`;
|
|
110
|
+
const both = (r.records ?? []).find((id) => carried.has(id));
|
|
111
|
+
if (both) return `${TOKEN}_set_aside_records:${n}: "${both}" is both carried and set aside. Keep it in one.`;
|
|
112
|
+
}
|
|
113
|
+
const owed = questionsOwed({ name: n, countsEntry, blocks, proposals: entries, carried, framed, addedQuestions });
|
|
114
|
+
const notAsked = owed.find((o) => o.mustAsk);
|
|
115
|
+
if (notAsked) return `${TOKEN}_identical:${n}: the register counts ${notAsked.count} under this name and no question was asked on it. Ask it: read the list if you can read it in full, or narrow it. A reason does not stand in for the name's own question.`;
|
|
116
|
+
const silent = owed.find((o) => o.addedClass != null && ![...row.not_asked, ...row.set_aside].some((r) => namesAddedClass(r.question, o)));
|
|
117
|
+
if (silent) return `${TOKEN}_added_class:${n}: Class ${silent.addedClass} was added for this name, but its identical-name question has no outcome. Ask that question, reuse its held answer for the same scope, or record why it remains unresolved. Keep the original instructed classes unchanged.`;
|
|
118
|
+
// A FILING IS ACCOUNTED FOR ONCE, wherever it is said. A row naming filings holds only those, so it excuses no other.
|
|
119
|
+
const accounted = new Set([...carried, ...row.set_aside.flatMap((r) => r.records ?? rowsUnder(r.question))]);
|
|
120
|
+
const said = new Set(row.set_aside.map((r) => r.question));
|
|
121
|
+
const unsaid = owed.flatMap((o) => {
|
|
122
|
+
if (o.addedClass != null) return [];
|
|
123
|
+
if (o.records) { const left = o.records.filter((id) => !accounted.has(id)); return left.length ? [`${o.question} (${left.length} of its ${o.count} uncarried filings, ${o.kind})`] : []; }
|
|
124
|
+
return said.has(o.question) ? [] : [`${o.question} (${o.count ?? "count unknown"}, ${o.kind}${o.unread ? `: ${o.unread.join(", ")} not read` : ""})`];
|
|
125
|
+
});
|
|
126
|
+
return unsaid.length ? `${TOKEN}_set_aside:${n}: nothing says what became of ${unsaid.join("; ")}. Read it, narrow it, or add a set_aside row naming that question with your reason.` : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The accepted record against this run: one row per instructed name, ids the register returned, nothing unaccounted for.
|
|
131
|
+
* `standing` is the rows that hold whatever the verdict on the others.
|
|
132
|
+
*/
|
|
133
|
+
export function checkKnockoutRegisterAgainstRun(model, runDir) {
|
|
134
|
+
const scope = readJson(driverDir(runDir, "instructed-scope.json"));
|
|
135
|
+
const instructed = (Array.isArray(scope?.marks) ? scope.marks : []).map((n) => String(n));
|
|
136
|
+
if (!instructed.length) return { ok: false, standing: [], reason: `${TOKEN}_scope: the run's instructed scope could not be read, so the names cannot be checked.` };
|
|
137
|
+
const byName = new Map(model.marks.map((m) => [nameKey(m.name), m]));
|
|
138
|
+
const known = new Set(instructed.map(nameKey));
|
|
139
|
+
const context = { counts: readJson(driverDir(runDir, "register-counts.json")), plan: readJson(join(runDir, "knockout-plan.json")), runDir };
|
|
140
|
+
const defects = model.marks.filter((m) => !known.has(nameKey(m.name))).map((m) => `${TOKEN}_names: "${m.name}" is not an instructed name. Names verbatim from the instructed scope.`);
|
|
141
|
+
const missing = instructed.filter((n) => !byName.has(nameKey(n)));
|
|
142
|
+
if (missing.length) defects.push(`${TOKEN}_names: no row for ${missing.map((n) => `"${n}"`).join(", ")}. Send one row per instructed name.`);
|
|
143
|
+
const standing = [];
|
|
144
|
+
for (const n of instructed) {
|
|
145
|
+
const row = byName.get(nameKey(n));
|
|
146
|
+
if (!row) continue;
|
|
147
|
+
const defect = rowDefect(row, n, context);
|
|
148
|
+
if (defect) defects.push(defect); else standing.push(row);
|
|
149
|
+
}
|
|
150
|
+
if (!defects.length) return { ok: true, standing };
|
|
151
|
+
return { ok: false, standing, reason: `${defects.join(" ")}${standing.length ? " Every other name stands: send only the names above." : ""}` };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** What the step had settled when its turn ended: every row that still stands, or null where none does. */
|
|
155
|
+
export function settledKnockoutReading(runDir) {
|
|
156
|
+
const paths = knockoutRegisterCallPaths(runDir);
|
|
157
|
+
const shape = acceptKnockoutRegister(lastAccepted(paths.accepted, readFileSync));
|
|
158
|
+
if (!shape.ok) return null;
|
|
159
|
+
const { standing } = checkKnockoutRegisterAgainstRun(shape.model, runDir);
|
|
160
|
+
return standing.length ? { schema_version: SCHEMA_VERSION, marks: standing } : null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Does the file on disk hold an accepted reading record for this run? koStage's skip-if-valid read. */
|
|
164
|
+
export function validateKnockoutRegisterFile(file, content) {
|
|
165
|
+
let doc;
|
|
166
|
+
try { doc = JSON.parse(content); } catch (e) { return { ok: false, reason: `not valid JSON: ${e.message}` }; }
|
|
167
|
+
const shape = acceptKnockoutRegister(doc);
|
|
168
|
+
if (!shape.ok) return shape;
|
|
169
|
+
const dir = dirname(file);
|
|
170
|
+
const runDir = basename(dir) === DRIVER_DIR ? dirname(dir) : dir;
|
|
171
|
+
if (!existsSync(driverDir(runDir, "instructed-scope.json"))) return { ok: false, reason: "the run's instructed scope is not on disk, so this record cannot be checked." };
|
|
172
|
+
return checkKnockoutRegisterAgainstRun(shape.model, runDir);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function recordKnockoutRegisterRead(runDir, received, { now = () => new Date().toISOString() } = {}) {
|
|
176
|
+
const dir = String(runDir ?? "");
|
|
177
|
+
const paths = knockoutRegisterCallPaths(dir);
|
|
178
|
+
const nameFor = (seq) => join(paths.dir, `call-${String(seq).padStart(3, "0")}.json`);
|
|
179
|
+
const cap = captureCall({ nameFor, params: received, now });
|
|
180
|
+
const closeCapture = (v) => { stampVerdict(cap.path, v); return cap.path; };
|
|
181
|
+
const journal = (reason) => {
|
|
182
|
+
try { writeFileSync(paths.refusals, JSON.stringify({ at: now(), reason }) + "\n", { flag: "a" }); }
|
|
183
|
+
catch { /* the refusal still stands and is still returned */ }
|
|
184
|
+
};
|
|
185
|
+
const refused = (reason) => {
|
|
186
|
+
journal(reason);
|
|
187
|
+
return { written: null, refused: reason, captured: closeCapture({ ok: false, refused: reason }), capture_failed: cap.failed };
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const undeclared = refuseUndeclared(received, DECLARED, TOKEN);
|
|
191
|
+
if (undeclared) return refused(undeclared);
|
|
192
|
+
|
|
193
|
+
const call = mergeKnockoutRegisterCall(lastAccepted(paths.accepted, readFileSync), received);
|
|
194
|
+
const verdict = acceptKnockoutRegister(call);
|
|
195
|
+
if (!verdict.ok) return refused(verdict.reason);
|
|
196
|
+
const joined = checkKnockoutRegisterAgainstRun(verdict.model, dir);
|
|
197
|
+
if (!joined.ok) {
|
|
198
|
+
if (joined.standing.length) {
|
|
199
|
+
try { writeFileSync(paths.accepted, acceptedEnvelope({ marks: joined.standing }, now())); }
|
|
200
|
+
catch { /* the refusal still stands; the repair then sends the whole record */ }
|
|
201
|
+
}
|
|
202
|
+
return refused(joined.reason);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const file = knockoutRegisterFile(dir);
|
|
206
|
+
try {
|
|
207
|
+
writeFileSync(file, JSON.stringify(verdict.model, null, 2) + "\n");
|
|
208
|
+
writeFileSync(paths.accepted, acceptedEnvelope(call, now()));
|
|
209
|
+
} catch (e) {
|
|
210
|
+
return { written: null, refused: null, write_failed: String(e?.message ?? e).slice(0, 200),
|
|
211
|
+
captured: closeCapture({ ok: false, write_failed: true }), capture_failed: cap.failed };
|
|
212
|
+
}
|
|
213
|
+
return { written: file, refused: null, names: verdict.model.marks.length, captured: closeCapture({ ok: true }), capture_failed: cap.failed };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The refusals journalled for this run, newest last. The accessor a TOOL_WRITTEN_ARTIFACTS row carries. */
|
|
217
|
+
export function knockoutRegisterRefusalsFor(runDir) {
|
|
218
|
+
try {
|
|
219
|
+
return readFileSync(knockoutRegisterCallPaths(String(runDir ?? "")).refusals, "utf8")
|
|
220
|
+
.split("\n").filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return { reason: l }; } });
|
|
221
|
+
} catch { return []; }
|
|
222
|
+
}
|
|
@@ -26,16 +26,21 @@
|
|
|
26
26
|
// re-send the other twenty, and a partial payload that DELETED the rest is the failure that rule exists
|
|
27
27
|
// to stop.
|
|
28
28
|
//
|
|
29
|
-
// `declined[]` — merged the same way, by address. A
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
29
|
+
// `declined[]` — merged the same way, by address. A clean read is recorded here once: one row saying the
|
|
30
|
+
// lines stand. A seat may also say why it left a flagged line alone, and is not asked to: a line it leaves
|
|
31
|
+
// alone owes no row. "I looked and it is fine" and "I did not look" stay different states in the
|
|
32
|
+
// artifact because an empty call is refused below, not because every line carries a row.
|
|
33
33
|
//
|
|
34
|
-
//
|
|
34
|
+
// `material[]` — REPLACED when present, KEPT when absent. It is the pass's whole answer to whether the
|
|
35
|
+
// client is being told the right thing, so half of one is not a thing.
|
|
35
36
|
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
37
|
+
// AND THE PASS CHANGES NO RATING. A material defect is named by mark and finding, with what it rests on, and
|
|
38
|
+
// goes to the step that can reason a band (knockout-correction-record.mjs). The only thing a rewrite may
|
|
39
|
+
// change is the prose of a default-visible line. The acceptor enforces that by construction: the address
|
|
40
|
+
// grammar cannot express a band, an ordinal reassignment or a new finding, so no rewrite reaches them.
|
|
41
|
+
//
|
|
42
|
+
// A SECOND PASS READS THE CORRECTED RECORD. Dispatched fresh after a correction, it has its own artifact and
|
|
43
|
+
// its own accepted call, bound by the ordinal in its label, so nothing the first pass sent carries into it.
|
|
39
44
|
import { writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
40
45
|
import { join, dirname, basename } from "node:path";
|
|
41
46
|
import { driverDir, DRIVER_DIR } from "../shared/driver-dir.mjs";
|
|
@@ -46,6 +51,7 @@ import { plainRegisterFlags } from "./plain-register.mjs"; // the pinned
|
|
|
46
51
|
// THE HINT'S fold, and it is imported rather than rebuilt — see nearestAddress. It is a comparison key
|
|
47
52
|
// for saying WHICH line was probably meant; it never decides whether an address resolves.
|
|
48
53
|
import { queryKey } from "./connotation-search.mjs";
|
|
54
|
+
import { PERMITTED_SOURCES, registerRecordIdsHeld, urlHeldFor } from "./verify-knockout.mjs";
|
|
49
55
|
|
|
50
56
|
const SCHEMA_VERSION = 1;
|
|
51
57
|
|
|
@@ -58,7 +64,8 @@ const SCHEMA_VERSION = 1;
|
|
|
58
64
|
* and the artifact would say the seat rewrote a line it did not.
|
|
59
65
|
*/
|
|
60
66
|
const DECLARED = {
|
|
61
|
-
"": ["schema_version", "first_question", "rewrites", "declined"],
|
|
67
|
+
"": ["schema_version", "first_question", "material", "rewrites", "declined"],
|
|
68
|
+
material: ["kind", "mark", "finding", "problem", "rests_on"],
|
|
62
69
|
rewrites: ["at", "text", "why"],
|
|
63
70
|
"rewrites.at": ["field", "mark", "index", "ordinal"],
|
|
64
71
|
declined: ["at", "why"],
|
|
@@ -103,9 +110,12 @@ export const ADDRESSABLE = Object.freeze({
|
|
|
103
110
|
"findings.net": Object.freeze(["mark", "ordinal"]),
|
|
104
111
|
});
|
|
105
112
|
|
|
106
|
-
/**
|
|
107
|
-
export
|
|
108
|
-
|
|
113
|
+
/** What a material defect can be, and whether it has to name the evidence it rests on. */
|
|
114
|
+
export const MATERIAL_KINDS = Object.freeze({ band: false, missing: true, exclusion: true, scope: false, contradiction: false });
|
|
115
|
+
|
|
116
|
+
/** One file per call, refusals included, beside the other transports' capture directories. A later pass keeps its own. */
|
|
117
|
+
export function knockoutReviewCallPaths(runDir, pass = 0) {
|
|
118
|
+
const dir = pass ? driverDir(runDir, join("knockout-review-calls", `pass-${Number(pass)}`)) : driverDir(runDir, "knockout-review-calls");
|
|
109
119
|
return { dir, accepted: join(dir, "accepted.json"), refusals: join(dir, "refusals.jsonl") };
|
|
110
120
|
}
|
|
111
121
|
|
|
@@ -122,9 +132,10 @@ export function knockoutReviewCallPaths(runDir) {
|
|
|
122
132
|
* The CALL captures stay under `_driver/`: those are the driver's record of what arrived, not a seat's
|
|
123
133
|
* output, and nothing dispatches against them.
|
|
124
134
|
*/
|
|
125
|
-
export function knockoutReviewFile(runDir) {
|
|
126
|
-
return join(String(runDir ?? ""), "knockout-review.json");
|
|
135
|
+
export function knockoutReviewFile(runDir, pass = 0) {
|
|
136
|
+
return join(String(runDir ?? ""), pass ? `knockout-review-${Number(pass)}.json` : "knockout-review.json");
|
|
127
137
|
}
|
|
138
|
+
export const KNOCKOUT_RECHECK_RE = /^knockout-review-\d+\.json$/;
|
|
128
139
|
|
|
129
140
|
/**
|
|
130
141
|
* The address as one string, for joining and for saying which address was refused.
|
|
@@ -209,6 +220,17 @@ export function acceptKnockoutReview(call) {
|
|
|
209
220
|
const firstQuestion = typeof call?.first_question === "string" && call.first_question.trim() ? call.first_question : undefined;
|
|
210
221
|
if (rewrites !== undefined && !Array.isArray(rewrites)) return { ok: false, reason: "rewrites must be an array" };
|
|
211
222
|
if (declined !== undefined && !Array.isArray(declined)) return { ok: false, reason: "declined must be an array" };
|
|
223
|
+
const material = call?.material;
|
|
224
|
+
if (material !== undefined && !Array.isArray(material)) return { ok: false, reason: "material must be an array" };
|
|
225
|
+
for (const m of material ?? []) {
|
|
226
|
+
if (!Object.hasOwn(MATERIAL_KINDS, m?.kind)) return { ok: false, reason: `a material row's kind is one of ${Object.keys(MATERIAL_KINDS).join(", ")}` };
|
|
227
|
+
if (typeof m?.mark !== "string" || !m.mark.trim()) return { ok: false, reason: "a material row names the mark it is about, verbatim" };
|
|
228
|
+
if (m.finding !== undefined && !Number.isInteger(m.finding)) return { ok: false, reason: `the material row on "${m.mark}": finding is the finding's ordinal` };
|
|
229
|
+
if (typeof m?.problem !== "string" || !m.problem.trim()) return { ok: false, reason: `the material row on "${m.mark}" says nothing about what is wrong` };
|
|
230
|
+
const rests = m.rests_on;
|
|
231
|
+
if (rests !== undefined && (!Array.isArray(rests) || rests.some((r) => typeof r !== "string" || !r.trim()))) return { ok: false, reason: `the material row on "${m.mark}": rests_on is a list of held recordIds, question qids, and URLs` };
|
|
232
|
+
if (MATERIAL_KINDS[m.kind] && !rests?.length) return { ok: false, reason: `the ${m.kind} row on "${m.mark}" names no evidence: send the recordIds, question qids, or URLs it rests on in rests_on` };
|
|
233
|
+
}
|
|
212
234
|
const seen = new Set();
|
|
213
235
|
for (const r of rewrites ?? []) {
|
|
214
236
|
const fault = addressFault(r?.at);
|
|
@@ -228,10 +250,10 @@ export function acceptKnockoutReview(call) {
|
|
|
228
250
|
}
|
|
229
251
|
// An empty call and a stage that never ran leave the same artifact behind, and they are different
|
|
230
252
|
// findings: one says the seat read the lines and had nothing to change, the other says nothing looked.
|
|
231
|
-
if (!(rewrites ?? []).length && !(declined ?? []).length)
|
|
232
|
-
return { ok: false, reason: "send at least one rewrite or
|
|
253
|
+
if (!(rewrites ?? []).length && !(declined ?? []).length && !(material ?? []).length)
|
|
254
|
+
return { ok: false, reason: "send at least one material, rewrite or declined row — an empty call cannot be told from a stage that never ran" };
|
|
233
255
|
return { ok: true, model: { schema_version: SCHEMA_VERSION, ...(firstQuestion !== undefined ? { first_question: firstQuestion } : {}),
|
|
234
|
-
rewrites: rewrites ?? [], declined: declined ?? [] } };
|
|
256
|
+
material: material ?? [], rewrites: rewrites ?? [], declined: declined ?? [] } };
|
|
235
257
|
}
|
|
236
258
|
|
|
237
259
|
/** Merge a repair turn onto what was already accepted, BY ADDRESS. See the header for the per-key rule. */
|
|
@@ -243,7 +265,7 @@ export function mergeKnockoutReviewCall(was, now) {
|
|
|
243
265
|
return [...byAddr.values()];
|
|
244
266
|
};
|
|
245
267
|
if (!was) return { ...now };
|
|
246
|
-
return { ...was, ...now, rewrites: merge("rewrites"), declined: merge("declined") };
|
|
268
|
+
return { ...was, ...now, material: now?.material ?? was.material, rewrites: merge("rewrites"), declined: merge("declined") };
|
|
247
269
|
}
|
|
248
270
|
|
|
249
271
|
/**
|
|
@@ -393,7 +415,16 @@ export function validateKnockoutReviewFile(file, text) {
|
|
|
393
415
|
let merged;
|
|
394
416
|
try { merged = JSON.parse(readFileSync(findingsFile, "utf8")); }
|
|
395
417
|
catch (e) { return { ok: false, reason: `the merged record will not parse, so no address could be checked: ${e.message}` }; }
|
|
418
|
+
const fault = joinFault(doc, merged, runDir);
|
|
419
|
+
return fault ? { ok: false, reason: fault } : { ok: true };
|
|
420
|
+
}
|
|
396
421
|
|
|
422
|
+
/**
|
|
423
|
+
* THE JOIN AGAINST THE RUN'S RECORD: why this answer cannot stand, or null. It runs at the recording call as well as at the stage's end,
|
|
424
|
+
* so a bad address or reference is refused while the seat can still repair it in its turn. Heard only at the end, it cost a whole
|
|
425
|
+
* attempt each time: on a saved batch, 2026-11-05, two refusals of one reference spent 430 s and 50,000 generated tokens on one stage.
|
|
426
|
+
*/
|
|
427
|
+
function joinFault(doc, merged, runDir) {
|
|
397
428
|
const knownAts = knockoutVisibleProse(merged).map((v) => v.at);
|
|
398
429
|
const known = new Set(knownAts.map((a) => addressKey(a)));
|
|
399
430
|
const owned = new Set(knockoutVisibleProse(merged).filter((v) => v.at?.engineOwned).map((v) => addressKey(v.at)));
|
|
@@ -404,13 +435,43 @@ export function validateKnockoutReviewFile(file, text) {
|
|
|
404
435
|
};
|
|
405
436
|
for (const r of doc.rewrites ?? []) {
|
|
406
437
|
const key = addressKey(r.at);
|
|
407
|
-
if (owned.has(key)) return
|
|
408
|
-
if (!known.has(key)) return
|
|
438
|
+
if (owned.has(key)) return `the rewrite for ${r.at.field} names a caveat the engine wrote, not a seat — it is not offered and cannot be changed`;
|
|
439
|
+
if (!known.has(key)) return `the rewrite for ${r.at.field}${r.at.mark ? ` on "${r.at.mark}"` : ""} names no line on this record${hint(r.at)}`;
|
|
409
440
|
}
|
|
410
441
|
for (const d of doc.declined ?? []) {
|
|
411
|
-
if (!known.has(addressKey(d.at))) return
|
|
442
|
+
if (!known.has(addressKey(d.at))) return `the declined row for ${d.at.field}${d.at.mark ? ` on "${d.at.mark}"` : ""} names no line on this record${hint(d.at)}`;
|
|
412
443
|
}
|
|
413
|
-
|
|
444
|
+
for (const m of doc.material ?? []) {
|
|
445
|
+
const fault = materialFault(m, merged, runDir);
|
|
446
|
+
if (fault) return fault;
|
|
447
|
+
}
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** Why a material row cannot be joined to what this run holds, or null. Whether the defect is real is the reader's judgment. */
|
|
452
|
+
function materialFault(m, merged, runDir) {
|
|
453
|
+
const mark = (merged?.marks ?? []).find((r) => String(r?.name ?? "") === m.mark);
|
|
454
|
+
if (!mark) return `the material row names "${m.mark}", which is not a name on this record. Copy it verbatim.`;
|
|
455
|
+
if (m.finding !== undefined && !(mark.findings ?? []).some((f) => f?.ordinal === m.finding)) return `the material row on "${m.mark}" names finding ${m.finding}, which it does not hold.`;
|
|
456
|
+
// WHAT THE RUN HOLDS, not what it holds under this name: a filing, a recorded research payload or an owner check may bear on more than
|
|
457
|
+
// one name. A question the run asked is held too, by its qid. Anything else is refused, in words about those sources and not the run.
|
|
458
|
+
const records = registerRecordIdsHeld(runDir);
|
|
459
|
+
let questions = new Set();
|
|
460
|
+
try { questions = new Set((JSON.parse(readFileSync(driverDir(runDir, "register-records.json"), "utf8")).marks ?? []).flatMap((e) => (e?.terms ?? []).map((t) => String(t?.qid ?? "")))); } catch { questions = new Set(); }
|
|
461
|
+
const urlHeld = urlHeldFor(runDir);
|
|
462
|
+
const stranger = (m.rests_on ?? []).find((r) => !records.has(r) && !questions.has(r) && !urlHeld(r));
|
|
463
|
+
return stranger ? `the material row on "${m.mark}" rests on "${stranger}", which is not traceable to ${PERMITTED_SOURCES}, or a question this run asked. Copy a recordId, question qid, or URL from what this run holds.` : null;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* The rewrites of a first pass that still have a line to land on after a correction: those on a name no defect named, and the
|
|
468
|
+
* standing caveats. A corrected name is renumbered and reworded, and the batch summary with it, so the second pass reads those
|
|
469
|
+
* afresh. PURE.
|
|
470
|
+
*/
|
|
471
|
+
export function rewritesThatSurvive(review, correctedNames) {
|
|
472
|
+
const corrected = new Set([...correctedNames].map((n) => String(n ?? "").trim().toLowerCase()));
|
|
473
|
+
const stands = (r) => r?.at?.field === "batch.standardCaveats" || (r?.at?.mark != null && !corrected.has(String(r.at.mark).trim().toLowerCase()));
|
|
474
|
+
return { ...review, rewrites: (review?.rewrites ?? []).filter(stands) };
|
|
414
475
|
}
|
|
415
476
|
|
|
416
477
|
/**
|
|
@@ -489,9 +550,10 @@ export function applyKnockoutReview(merged, review) {
|
|
|
489
550
|
return { doc, receipt: { applied: applied.length, unresolved, refused, declined: (review?.declined ?? []).length } };
|
|
490
551
|
}
|
|
491
552
|
|
|
492
|
-
export function recordKnockoutReview(runDir, received, { now = () => new Date().toISOString() } = {}) {
|
|
553
|
+
export function recordKnockoutReview(runDir, received, { boundOrdinal = null, now = () => new Date().toISOString() } = {}) {
|
|
493
554
|
const dir = String(runDir ?? "");
|
|
494
|
-
const
|
|
555
|
+
const pass = Number(boundOrdinal) || 0;
|
|
556
|
+
const paths = knockoutReviewCallPaths(dir, pass);
|
|
495
557
|
const nameFor = (seq) => join(paths.dir, `call-${String(seq).padStart(3, "0")}.json`);
|
|
496
558
|
const cap = captureCall({ nameFor, params: received, now });
|
|
497
559
|
const captureFailed = cap.failed;
|
|
@@ -518,7 +580,15 @@ export function recordKnockoutReview(runDir, received, { now = () => new Date().
|
|
|
518
580
|
return { written: null, refused: verdict.reason, captured: closeCapture({ ok: false, refused: verdict.reason }), capture_failed: captureFailed };
|
|
519
581
|
}
|
|
520
582
|
|
|
521
|
-
|
|
583
|
+
// Where the record is on disk the seat hears the join now, in its turn. Where it is not, the stage's own check says it could not look.
|
|
584
|
+
const held = (() => { try { return JSON.parse(readFileSync(join(dir, "knockout-findings.json"), "utf8")); } catch { return null; } })();
|
|
585
|
+
const fault = held ? joinFault(verdict.model, held, dir) : null;
|
|
586
|
+
if (fault) {
|
|
587
|
+
journal(fault);
|
|
588
|
+
return { written: null, refused: fault, captured: closeCapture({ ok: false, refused: fault }), capture_failed: captureFailed };
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const file = knockoutReviewFile(dir, pass);
|
|
522
592
|
try {
|
|
523
593
|
writeFileSync(file, JSON.stringify(verdict.model, null, 2) + "\n");
|
|
524
594
|
writeFileSync(paths.accepted, acceptedEnvelope(call, now()));
|
|
@@ -530,6 +600,7 @@ export function recordKnockoutReview(runDir, received, { now = () => new Date().
|
|
|
530
600
|
return {
|
|
531
601
|
written: file,
|
|
532
602
|
refused: null,
|
|
603
|
+
material: verdict.model.material.length,
|
|
533
604
|
rewrites: verdict.model.rewrites.length,
|
|
534
605
|
declined: verdict.model.declined.length,
|
|
535
606
|
captured: closeCapture({ ok: true }),
|
|
@@ -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, SECTION_HEADING_RE } from "./verify.mjs";
|
|
42
|
+
import { parseVerdict, countCitedDefects, parseCorrections, parseCorrectionKinds, correctionFlagContent, CORRECTION_KINDS, SECTION_HEADING_RE } from "./verify.mjs";
|
|
43
43
|
|
|
44
44
|
export const REVIEW_FILE = "senior-eye-review.md";
|
|
45
45
|
|
|
@@ -361,6 +361,92 @@ export function readAcceptedReviewSince(runDir, seq0) {
|
|
|
361
361
|
return null;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
// ── A REVIEW SAVED BY REWRITING THE FILE MEETS THE RULES THE TYPED ROUTE KEEPS ─────────────────────────────────────────
|
|
365
|
+
//
|
|
366
|
+
// A seat may save a review through the tool or by rewriting the file, and the recheck's message orders the rewrite. The
|
|
367
|
+
// file's validator asks for a verdict line and, on a receipt run, the audit's words somewhere in the file, so a review
|
|
368
|
+
// the tool refuses could be written into the file instead and read as the review of the corrected record: a BLOCKING
|
|
369
|
+
// that names nothing, or a flag on a position the writer's list does not give. Changed bytes show a review is fresh. They
|
|
370
|
+
// do not show it can be accepted.
|
|
371
|
+
//
|
|
372
|
+
// SO THE FILE IS READ BACK INTO THE VALUES THE TOOL TAKES, through the shipped parsers, and refused with the tool's own
|
|
373
|
+
// tokens. FORMATTING IS NOT WHAT IS REFUSED: a legacy line with no kind token still reads as `fact` (the validator's
|
|
374
|
+
// contract), and a flag with no `[on:]` stays undeclared. A BLOCKING is counted by the permissive walk the verdict gate
|
|
375
|
+
// uses, because refusing here discards a review. The check is one read of the file and sends nothing back to the seat.
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The plan audit's lines in a review file. It opens at a line naming the check that is not itself a flag, because a flag
|
|
379
|
+
* that mentions the check audits nothing, and runs to the next heading at its own level or above that names the flags or
|
|
380
|
+
* the corrections. Any other heading stays in: saved reviews write their audits under headings of their own, and refusing
|
|
381
|
+
* a real audit over one is the worse mistake. Words after the name on its own line count: "PLAN-EXECUTION CHECK: every
|
|
382
|
+
* slice ran" is an audit. PURE.
|
|
383
|
+
*/
|
|
384
|
+
export function planAuditLines(reviewMd) {
|
|
385
|
+
const lines = String(reviewMd ?? "").split("\n").slice(1).map((l) => l.trim());
|
|
386
|
+
const at = lines.findIndex((l) => /PLAN-EXECUTION CHECK/i.test(l) && correctionFlagContent(l) == null);
|
|
387
|
+
if (at < 0) return [];
|
|
388
|
+
const own = lines[at].replace(/^.*?PLAN-EXECUTION CHECK/i, "").replace(/^[^\p{L}\p{N}]+/u, "");
|
|
389
|
+
const levelOf = (l) => /^(#{1,6})\s/.exec(l)?.[1].length ?? 6; // a line of capitals has no level of its own
|
|
390
|
+
const end = lines.findIndex((l, i) => i > at && SECTION_HEADING_RE.test(l) && /\b(?:flags?|flagged|corrections?)\b/i.test(l) && levelOf(l) <= levelOf(lines[at]));
|
|
391
|
+
return [own, ...lines.slice(at + 1, end < 0 ? undefined : end)].filter((l) => l && !/^(?:#{1,6}\s+)?\W*PLAN-EXECUTION CHECK\W*$/i.test(l));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The typed values of a review saved as a file, as `{ok: true, verdict, flags, planAudit}`, or `{ok: false, reason}` with
|
|
396
|
+
* the token the tool refuses the same review with. `receiptPresent` and `positionsListed` are the driver's reads, as for
|
|
397
|
+
* acceptRefutation. PURE.
|
|
398
|
+
*/
|
|
399
|
+
export function acceptReviewFile(content, { receiptPresent = false, positionsListed = null } = {}) {
|
|
400
|
+
const text = String(content ?? "");
|
|
401
|
+
const verdict = parseVerdict(text);
|
|
402
|
+
if (!REVIEW_VERDICTS.includes(verdict)) return { ok: false, reason: `refutation_verdict_invalid:${String(verdict).slice(0, 40)}` };
|
|
403
|
+
if (verdict === "BLOCKING" && countCitedDefects(text) === 0) return { ok: false, reason: "refutation_blocking_without_flags" };
|
|
404
|
+
const flags = parseCorrections(text);
|
|
405
|
+
for (let i = 0; i < flags.length; i++) {
|
|
406
|
+
if (!String(flags[i].text ?? "").trim()) return { ok: false, reason: `refutation_flag_text_empty:${i}` };
|
|
407
|
+
if ((flags[i].ordinals ?? []).some((n) => n < 1)) return { ok: false, reason: `refutation_flag_on_invalid:${i}` };
|
|
408
|
+
const unknown = (flags[i].positions ?? []).find((p) => !positionsListed?.get(String(normalizeRecordUri(p) ?? "")));
|
|
409
|
+
if (unknown != null) return { ok: false, reason: `refutation_flag_position_unlisted:${i}:${String(unknown).slice(0, 80)}` };
|
|
410
|
+
}
|
|
411
|
+
const planAudit = planAuditLines(text);
|
|
412
|
+
if (receiptPresent && !planAudit.length) return { ok: false, reason: "refutation_plan_audit_missing" };
|
|
413
|
+
return { ok: true, verdict, flags, planAudit };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* WHAT A RECHECK'S DISPATCH SAVED, whichever way it saved it, and what must stand in the file afterwards. `before` is the
|
|
418
|
+
* review's text when the dispatch began, and `seq0` its first call number. Returns `{read, fail, refused, restore}`:
|
|
419
|
+
* read `{by, seq}` when a review was saved that can be accepted, otherwise null
|
|
420
|
+
* fail why nothing was read, on a stage that ended ok: `no-accepted-call`, or `file-save-refused:<token>`
|
|
421
|
+
* refused the token of a direct save that was refused, whether or not a typed save stands in its place
|
|
422
|
+
* restore the text the caller writes to the file, or null to leave it
|
|
423
|
+
*
|
|
424
|
+
* ONE DECISION, ONE READ OF THE FILE, AND NO RETRY. A refused direct save gives way to the dispatch's last accepted typed
|
|
425
|
+
* call if there is one, and otherwise to the earlier review, so a verdict is never read from refused bytes and those bytes
|
|
426
|
+
* do not stay in place of an accepted review. A stage that failed reads nothing, and whatever it left gives way to the
|
|
427
|
+
* earlier review, whose verdict stands. Never throws on a file it cannot read: an absent review gives way the same way.
|
|
428
|
+
*/
|
|
429
|
+
export function settleRecheckSave(runDir, { before = null, stageOk = false, seq0 = 0 } = {}) {
|
|
430
|
+
const dir0 = String(runDir ?? "");
|
|
431
|
+
let now = null;
|
|
432
|
+
try { now = readFileSync(join(dir0, REVIEW_FILE), "utf8"); } catch { now = null; }
|
|
433
|
+
const earlierBack = before != null && now !== before ? before : null;
|
|
434
|
+
if (!stageOk) return { read: null, fail: null, refused: null, restore: earlierBack };
|
|
435
|
+
const rules = { receiptPresent: planReceiptPresent(dir0), positionsListed: listedExclusionPositions(dir0) };
|
|
436
|
+
const call = readAcceptedReviewSince(dir0, seq0);
|
|
437
|
+
const typed = call ? acceptRefutation({ verdict: call.verdict, flags: call.flags, plan_audit: call.planAudit }, rules) : null;
|
|
438
|
+
const saved = typed?.ok ? typed.content : null;
|
|
439
|
+
const byTool = saved != null ? { by: "tool", seq: call.seq } : null;
|
|
440
|
+
if (saved != null && now === saved) return { read: byTool, fail: null, refused: null, restore: null };
|
|
441
|
+
if (now == null || now === before) {
|
|
442
|
+
return byTool ? { read: byTool, fail: null, refused: null, restore: saved } : { read: null, fail: "no-accepted-call", refused: null, restore: earlierBack };
|
|
443
|
+
}
|
|
444
|
+
const file = acceptReviewFile(now, rules);
|
|
445
|
+
if (file.ok) return { read: { by: "file", seq: null }, fail: null, refused: null, restore: null };
|
|
446
|
+
if (byTool) return { read: byTool, fail: null, refused: file.reason, restore: saved };
|
|
447
|
+
return { read: null, fail: `file-save-refused:${file.reason}`, refused: file.reason, restore: earlierBack };
|
|
448
|
+
}
|
|
449
|
+
|
|
364
450
|
/** Read back what was written — the verdict view of the stored file, through the one parse. */
|
|
365
451
|
export function readRecordedVerdict(runDir) {
|
|
366
452
|
try { return parseVerdict(readFileSync(join(String(runDir ?? ""), REVIEW_FILE), "utf8")); }
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
// order-tables.mjs — the tables an order is checked against, loaded once, for every door that asks.
|
|
5
|
+
//
|
|
6
|
+
// `orderTimeRefusal` (run-requirements.mjs) is the one test for "can this install run a search", and it is
|
|
7
|
+
// pure: the register and engine tables arrive from the caller. The runner's intake wall and the portal's order
|
|
8
|
+
// door both take them from HERE, so the two ask one question of one set of tables and cannot disagree. The
|
|
9
|
+
// portal used to ask nothing: it said "queued", and the runner then refused the order with no one watching.
|
|
10
|
+
//
|
|
11
|
+
// AT CALL TIME, never a static import. The register SELECTION table lives in `bin/onboard.mjs`, a CLI entry
|
|
12
|
+
// point, and a static import from `driver/` would point the driver at `bin/` — the cycle that makes
|
|
13
|
+
// `clearotron doctor` exit 13 after printing most of a report. This module sits outside run-requirements.mjs
|
|
14
|
+
// so that module stays pure and reaches nothing in `bin/`.
|
|
15
|
+
let tables = null;
|
|
16
|
+
export async function runTables() {
|
|
17
|
+
if (!tables) {
|
|
18
|
+
const { PROVIDERS } = await import("../bin/onboard.mjs");
|
|
19
|
+
const { ENGINE_BINARIES, DEFAULT_ENGINE_ID, resolveEngineProgram } = await import("./driver.config.mjs");
|
|
20
|
+
tables = { registers: PROVIDERS, engines: ENGINE_BINARIES, defaultEngine: DEFAULT_ENGINE_ID, resolveEngine: resolveEngineProgram };
|
|
21
|
+
}
|
|
22
|
+
return tables;
|
|
23
|
+
}
|
|
@@ -83,7 +83,10 @@ export function ownersOwedACheck(recordsDoc, { cap = OWNER_CHECK_CAP } = {}) {
|
|
|
83
83
|
// stage. The scope therefore comes from `entry.classes`, which register-records.mjs sets to the
|
|
84
84
|
// classes it actually searched. Passing the entry's own classes as the mark's keeps the predicate
|
|
85
85
|
// reading the same scope it reads at publish time instead of silently widening to every record.
|
|
86
|
-
|
|
86
|
+
// THE READING STEP NAMES THE FILINGS WHOSE OWNER MERITS A SEARCH, where it finished: judgment, not the first few owners
|
|
87
|
+
// of what would be promoted. A run whose step did not finish keeps the bounded rule below.
|
|
88
|
+
const named = Array.isArray(entry?.reading?.ownerChecks) ? new Set(entry.reading.ownerChecks.map(String)) : null;
|
|
89
|
+
const promoted = named ? (entry?.records ?? []).filter((r) => named.has(String(r?.recordId ?? ""))) : promotableRecords(entry, { classesSearched: entry?.classes ?? [] });
|
|
87
90
|
const byOwner = new Map();
|
|
88
91
|
for (const r of promoted) {
|
|
89
92
|
const owner = String(r?.owner ?? "").trim();
|
|
@@ -97,7 +100,7 @@ export function ownersOwedACheck(recordsDoc, { cap = OWNER_CHECK_CAP } = {}) {
|
|
|
97
100
|
for (const c of (Array.isArray(r.classes) ? r.classes : [])) if (Number.isFinite(Number(c))) g.classes.add(Number(c));
|
|
98
101
|
byOwner.set(key, g);
|
|
99
102
|
}
|
|
100
|
-
for (const g of [...byOwner.values()].slice(0, cap)) {
|
|
103
|
+
for (const g of named ? [...byOwner.values()] : [...byOwner.values()].slice(0, cap)) {
|
|
101
104
|
out.push({ mark: g.mark, owner: g.owner, recordIds: g.recordIds.filter(Boolean), classes: [...g.classes].sort((a, b) => a - b) });
|
|
102
105
|
}
|
|
103
106
|
}
|
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.1-beta.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": {
|
|
@@ -58,6 +58,14 @@
|
|
|
58
58
|
{
|
|
59
59
|
"tool": "record_synthesis",
|
|
60
60
|
"why": "CLOSED by mergeSynthesisPatch plus synthesis_patch_without_base — pinned by the-repair-order-and-the-tool-schema-agree.test.mjs, not re-planted here"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"tool": "record_knockout_register_read",
|
|
64
|
+
"why": "merges by name, pinned in a-knockout-reads-the-register-by-judgment.test.mjs; a row it omits keeps what was accepted, and a run with no instructed scope refuses it, so the census's bare fixture cannot reach it"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"tool": "record_knockout_correction",
|
|
68
|
+
"why": "a partial is its whole design: a field or a finding it omits keeps the chunk's own, pinned in a-knockout-defect-reaches-the-step-that-can-repair-it.test.mjs; a run with no correction under way refuses it, so the census's bare fixture cannot reach it"
|
|
61
69
|
}
|
|
62
70
|
],
|
|
63
71
|
"known_open": [
|