clearotron 0.7.0-beta.2 → 0.7.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +5 -5
- package/QUICKSTART.md +4 -4
- package/README.md +2 -2
- package/bin/README.md +3 -4
- package/bin/clearotron.mjs +1 -1
- package/bin/onboard.mjs +28 -40
- package/bin/status.mjs +11 -0
- package/build-info.json +2 -2
- package/docs/DELIVERY.md +30 -6
- package/docs/architecture/04-configuration-reference.md +1 -0
- package/driver/CHANGELOG.md +21 -0
- package/driver/compose-read.mjs +4 -3
- package/driver/contract-arm2-baseline.json +1 -2
- package/driver/contract-dictation-registry.mjs +7 -48
- package/driver/contract-e3-backlog.mjs +55 -52
- package/driver/contract-e3-baseline.json +22 -7
- package/driver/contract-vocabulary.mjs +4 -2
- package/driver/coverage-form.mjs +4 -0
- package/driver/coverage-rows-run.mjs +68 -4
- package/driver/engine/anthropic-agent.mjs +10 -13
- package/driver/engine/common.mjs +34 -22
- package/driver/engine/health.mjs +251 -0
- package/driver/engine/jx-turn.mjs +2 -1
- package/driver/engine/mcp/codex-config.mjs +16 -1
- package/driver/engine/mcp/crowd-note.mjs +1 -1
- package/driver/engine/mcp/gather-config.mjs +34 -9
- package/driver/engine/mcp/perplexity-server.mjs +33 -23
- package/driver/engine/mcp/recording-server.mjs +67 -58
- package/driver/engine/mcp/unit-note-server.mjs +2 -0
- package/driver/engine/openai-agent.mjs +9 -24
- package/driver/engine/probe.mjs +24 -7
- package/driver/findings-model.mjs +54 -0
- package/driver/jx-units.mjs +139 -30
- package/driver/knockout-assess-record.mjs +2 -2
- package/driver/knockout-correction-check.mjs +119 -0
- package/driver/knockout-correction-record.mjs +1 -1
- package/driver/knockout-frame-record.mjs +24 -10
- package/driver/knockout-review-record.mjs +35 -430
- package/driver/ladder/dispatch.mjs +4 -2
- package/driver/ladder/form-repair.mjs +5 -5
- package/driver/ladder/form-sync.mjs +4 -6
- package/driver/ladder/next-rung.mjs +10 -0
- package/driver/ladder/repair-messages.mjs +37 -65
- package/driver/ladder/stage.mjs +3 -3
- package/driver/ladder/turn-signals.mjs +4 -14
- package/driver/manual-paragraphs.mjs +22 -2
- package/driver/mark-logos.mjs +20 -5
- package/driver/package.json +1 -1
- package/driver/pipeline-knockout.mjs +2 -2
- package/driver/predelivery-lint.mjs +39 -7
- package/driver/product-fault.mjs +53 -0
- package/driver/publish/knockout.mjs +2 -1
- package/driver/publish/render.mjs +13 -7
- package/driver/recording-agreement.mjs +6 -4
- package/driver/register-band-run.mjs +2 -2
- package/driver/register-digest-record.mjs +31 -9
- package/driver/register-unit-record.mjs +10 -1
- package/driver/repair-composers.mjs +12 -11
- package/driver/repair-contract.mjs +6 -6
- package/driver/repair-targets.mjs +7 -6
- package/driver/run-outcome.mjs +8 -0
- package/driver/runner.mjs +42 -3
- package/driver/skills/README.md +5 -4
- package/driver/skills/blind-frame/SKILL.md +1 -1
- package/driver/skills/case-law-citation/SKILL.md +1 -1
- package/driver/skills/clearance-common-law/SKILL.md +6 -423
- package/driver/skills/clearance-common-law/grid.md +272 -0
- package/driver/skills/clearance-common-law/meaning.md +142 -0
- package/driver/skills/clearance-common-law/perplexity-prompts.md +4 -2
- package/driver/skills/clearance-register/SKILL.md +7 -174
- package/driver/skills/clearance-register/digest.md +89 -25
- package/driver/skills/clearance-register/providers/clarivate-questions.md +154 -0
- package/driver/skills/clearance-register/providers/clarivate.md +5 -149
- package/driver/skills/clearance-register/providers/signa-questions.md +120 -0
- package/driver/skills/clearance-register/providers/signa.md +3 -114
- package/driver/skills/clearance-register/providers/uspto-local.md +3 -3
- package/driver/skills/clearance-register/register-recipes.md +10 -10
- package/driver/skills/clearance-register/status-rules.md +2 -2
- package/driver/skills/clearance-register/unit.md +96 -54
- package/driver/skills/clearance-search/delivery-contract.md +11 -49
- package/driver/skills/clearance-search/firm-wide-reasoning.md +10 -13
- package/driver/skills/clearance-search/look-at-what-you-have.md +7 -0
- package/driver/skills/clearance-search/phase2-execution.md +12 -117
- package/driver/skills/clearance-search/report-card-rules.md +2 -2
- package/driver/skills/clearance-search/report-prose.md +30 -23
- package/driver/skills/clearance-search/synthesis-rules.md +27 -69
- package/driver/skills/clearance-search/worked-examples.md +11 -16
- package/driver/skills/clearance-variants/SKILL.md +7 -7
- package/driver/skills/clearance-variants/transliteration-scripts.md +2 -2
- package/driver/skills/frame-diff/SKILL.md +1 -1
- package/driver/skills/knockout-assess/SKILL.md +54 -41
- package/driver/skills/knockout-frame/SKILL.md +13 -12
- package/driver/skills/knockout-register-read/SKILL.md +2 -10
- package/driver/skills/matter-frame/SKILL.md +2 -2
- package/driver/skills/narrative-refutation/SKILL.md +7 -6
- package/driver/skills/placement-inquiry/SKILL.md +3 -3
- package/driver/skills/skeptic/SKILL.md +111 -0
- package/driver/skills/whatif-memo/SKILL.md +5 -2
- package/driver/stage-declarations.mjs +6 -0
- package/driver/stages-knockout.mjs +36 -38
- package/driver/stages.mjs +69 -64
- package/driver/steps/delivery.mjs +6 -4
- package/driver/steps/open-run.mjs +2 -0
- package/driver/steps/overview-and-cards.mjs +2 -2
- package/driver/steps/register-sweep.mjs +20 -1
- package/driver/steps/synthesis.mjs +28 -11
- package/driver/suite-census.json +213 -57
- package/driver/synthesis-record.mjs +24 -2
- package/driver/verify-knockout.mjs +23 -3
- package/driver/whatif-memo-run.mjs +39 -10
- package/driver/whatif-queue.mjs +53 -7
- package/mcp-server/CHANGELOG.md +4 -0
- package/mcp-server/lib/ops.mjs +19 -10
- package/mcp-server/lib/whatif.mjs +7 -6
- package/mcp-server/package.json +1 -1
- package/mcp-server/server.mjs +55 -19
- package/package.json +1 -1
- package/portal-ui/package.json +1 -1
- package/providers/clarivate/src/adapter.js +3 -0
- package/providers/jx/src/nativeread.js +5 -3
- package/providers/oauth-mcp-bridge/CHANGELOG.md +4 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/providers/perplexity/src/core.js +7 -2
- package/providers/signa/src/adapter.js +3 -0
- package/scripts/e2e-first-time.mjs +2 -2
- package/shared/connector-signin-probe.mjs +1 -1
- package/shared/names-in-force.mjs +1 -0
- package/skills/clearotron-account/SKILL.md +21 -11
- package/skills/clearotron-client/SKILL.md +15 -15
- package/skills/clearotron-ops/COURIER.md +5 -1
- package/skills/clearotron-ops/SKILL.md +21 -14
|
@@ -3,53 +3,21 @@
|
|
|
3
3
|
//
|
|
4
4
|
// record_knockout_review — the knockout lane's REVIEWING pass, as a typed return path.
|
|
5
5
|
//
|
|
6
|
-
// The
|
|
7
|
-
//
|
|
8
|
-
// equivalent rides `narrative-refutation`; this is the same rule reaching the same reader on the other
|
|
9
|
-
// product, through the smallest stage that can carry it.
|
|
6
|
+
// The review checks what the client is told against the request, the framework and the evidence the run holds. The clearance
|
|
7
|
+
// product's equivalent rides `narrative-refutation`.
|
|
10
8
|
//
|
|
11
|
-
// WHAT THE SEAT SENDS
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
// {field, mark?, index?, ordinal?} — and carries the replacement prose. It does not quote the sentence
|
|
15
|
-
// it is replacing. A quote has to be matched back against the record, and the matcher is then the thing
|
|
16
|
-
// that decides where a rewrite lands: on the clearance lane a correction the cycle cannot bind to an
|
|
17
|
-
// entity is declined whatever its merit, and prose-matching is how a rewrite comes to land on the wrong
|
|
18
|
-
// mark when two names differ only in case. The address is the join key, and it is refused by name when
|
|
19
|
-
// it does not resolve.
|
|
20
|
-
//
|
|
21
|
-
// EVERY KEY'S MERGE RULE, STATED BEFORE THE CODE.
|
|
22
|
-
//
|
|
23
|
-
// `rewrites[]` — merged onto the stored call BY ADDRESS. A repair turn that re-sends one address
|
|
24
|
-
// replaces that rewrite whole; addresses it omits survive. This is the same rule the frame and assess
|
|
25
|
-
// transports state for a mark row, for the same reason: a seat correcting one line should not have to
|
|
26
|
-
// re-send the other twenty, and a partial payload that DELETED the rest is the failure that rule exists
|
|
27
|
-
// to stop.
|
|
28
|
-
//
|
|
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
|
-
//
|
|
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.
|
|
9
|
+
// WHAT THE SEAT SENDS: its answer to the client's question (`first_question`) and the material defects (`material`). It rewords
|
|
10
|
+
// nothing; a supported line stands. `material` is REPLACED when present and KEPT when absent: it is the pass's whole answer to
|
|
11
|
+
// whether the client is being told the right thing, so half of one is not a thing.
|
|
36
12
|
//
|
|
37
13
|
// 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).
|
|
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.
|
|
14
|
+
// goes to the step that can reason a band (knockout-correction-record.mjs).
|
|
41
15
|
//
|
|
42
|
-
//
|
|
43
|
-
// its own accepted call, bound by the ordinal in its label, so nothing the first pass sent carries into it.
|
|
16
|
+
// ONE REVIEW: a correction is not read again. A label that still carries a pass ordinal is kept apart by that ordinal.
|
|
44
17
|
import { writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
45
18
|
import { join, dirname, basename } from "node:path";
|
|
46
19
|
import { captureCall, stampVerdict } from "./call-capture.mjs";
|
|
47
20
|
import { refuseUndeclared as refuseUndeclaredShared, lastAccepted, acceptedEnvelope } from "./preserve-merge.mjs";
|
|
48
|
-
import { knockoutVisibleProse } from "./predelivery-lint.mjs"; // the walk is the authority on what a reader sees
|
|
49
|
-
import { plainRegisterFlags } from "./plain-register.mjs"; // the pinned rule, one copy
|
|
50
|
-
// THE HINT'S fold, and it is imported rather than rebuilt — see nearestAddress. It is a comparison key
|
|
51
|
-
// for saying WHICH line was probably meant; it never decides whether an address resolves.
|
|
52
|
-
import { queryKey } from "./connotation-search.mjs";
|
|
53
21
|
import { PERMITTED_SOURCES, registerRecordIdsHeld, urlHeldFor } from "./verify-knockout.mjs";
|
|
54
22
|
import { DRIVER_DIR, driverDir, paths as runPaths, readJson } from "./run-record.mjs";
|
|
55
23
|
|
|
@@ -59,56 +27,17 @@ const SCHEMA_VERSION = 1;
|
|
|
59
27
|
* Path → the keys that path declares, in `refuseUndeclared`'s own shape.
|
|
60
28
|
*
|
|
61
29
|
* The top level ("") is deliberately permissive by that helper's rule — an envelope field nobody reads
|
|
62
|
-
* must never kill a stage. The care is inside the typed sub-
|
|
63
|
-
*
|
|
64
|
-
* and the artifact would say the seat rewrote a line it did not.
|
|
30
|
+
* must never kill a stage. The care is inside the typed sub-object: a material row's field under a key this tool does not
|
|
31
|
+
* declare would be accepted and then dropped, and the artifact would say the seat named what it did not.
|
|
65
32
|
*/
|
|
66
33
|
const DECLARED = {
|
|
67
34
|
"": ["schema_version", "first_question", "material"],
|
|
68
35
|
material: ["kind", "mark", "finding", "problem", "rests_on"],
|
|
69
|
-
rewrites: ["at", "text", "why"],
|
|
70
|
-
"rewrites.at": ["field", "mark", "index", "ordinal"],
|
|
71
|
-
declined: ["at", "why"],
|
|
72
|
-
"declined.at": ["field", "mark", "index", "ordinal"],
|
|
73
36
|
};
|
|
74
37
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* THE SET IS WHAT A CLIENT SEES FIRST, WHICH IS NARROWER THAN THE WALK — in two different directions,
|
|
79
|
-
* and each has to be said or the next reader repairs the wrong one.
|
|
80
|
-
*
|
|
81
|
-
* NARROWER BY WHO WROTE IT. The engine appends two of the standing caveats itself. They are in the walk
|
|
82
|
-
* because an over-long engine caveat is a real defect for whoever edits the code that emits it, and they
|
|
83
|
-
* are not addressable because a rewrite there breaks a delivery-time match or appends a second copy of
|
|
84
|
-
* the note, silently either way.
|
|
85
|
-
*
|
|
86
|
-
* NARROWER BY WHAT A READER MEETS. `marks[].registerReads[].read` is in the walk and is NOT in
|
|
87
|
-
* `DEFAULT_VISIBLE_FIELDS.knockout`. The walk is the authority on what the internal lint should READ;
|
|
88
|
-
* that list is the authority on what a client meets before opening anything, and this pass is scoped to
|
|
89
|
-
* the second — its own instruction to the seat says "a line a reader meets before opening anything", and
|
|
90
|
-
* the ruling that authorised it says the lines a client reads. So a field that is visible to the lint and
|
|
91
|
-
* not on that list is outside the pass, and the pass reaches eight.
|
|
92
|
-
*
|
|
93
|
-
* THAT THE TWO LISTS DISAGREE AT ALL IS A SEPARATE DEFECT, and it is filed as one rather than repaired
|
|
94
|
-
* here. Reconciling them is a change to what the product calls default-visible; making the pass ACT on
|
|
95
|
-
* the disagreement — which is what including `registerReads` did — would settle that question as a side
|
|
96
|
-
* effect of a rewrite pass, on delivered prose, with nothing recording that it had been decided.
|
|
97
|
-
*
|
|
98
|
-
* An arm compares the SETS rather than the counts, and names each difference. Both lists happened to
|
|
99
|
-
* hold nine entries while being different nines, which is exactly how a reconciliation reads as correct
|
|
100
|
-
* when it is not.
|
|
101
|
-
*/
|
|
102
|
-
export const ADDRESSABLE = Object.freeze({
|
|
103
|
-
"batch.executiveSummary": Object.freeze([]),
|
|
104
|
-
"batch.standardCaveats": Object.freeze(["index"]),
|
|
105
|
-
basis: Object.freeze(["mark"]),
|
|
106
|
-
mitigation: Object.freeze(["mark"]),
|
|
107
|
-
factors: Object.freeze(["mark", "index"]),
|
|
108
|
-
counterFactors: Object.freeze(["mark", "index"]),
|
|
109
|
-
purpleNotes: Object.freeze(["mark", "index"]),
|
|
110
|
-
"findings.net": Object.freeze(["mark", "ordinal"]),
|
|
111
|
-
});
|
|
38
|
+
// THE KEYS AN EARLIER REVIEW SENT, when it reworded the lines a reader meets first. It rewords nothing now.
|
|
39
|
+
const RETIRED_KEYS = Object.freeze(["rewrites", "declined"]);
|
|
40
|
+
const RETIRED_REASON = (k) => `this review rewords nothing, so it takes no \`${k}\`: send \`first_question\` and \`material\` only`;
|
|
112
41
|
|
|
113
42
|
/** What a material defect can be, and whether it has to name the evidence it rests on. */
|
|
114
43
|
export const MATERIAL_KINDS = Object.freeze({ band: false, missing: true, exclusion: true, scope: false, contradiction: false });
|
|
@@ -126,7 +55,7 @@ export function knockoutReviewCallPaths(runDir, pass = 0) {
|
|
|
126
55
|
* measurements and is behind a deny hook; a stage whose `out` lands there has a seat that will be
|
|
127
56
|
* refused on Write and on Bash, and a corrective ladder that exhausts against a dispatch ordering a
|
|
128
57
|
* write nothing permits. The assess chunk was relocated out of it for exactly that reason. This file is
|
|
129
|
-
* a MODEL output — the seat's
|
|
58
|
+
* a MODEL output — the seat's answer — so the run root is where it belongs by the same rule, and an
|
|
130
59
|
* arm sweeps both stage tables to keep it there.
|
|
131
60
|
*
|
|
132
61
|
* The CALL captures stay under `_driver/`: those are the driver's record of what arrived, not a seat's
|
|
@@ -136,89 +65,16 @@ export function knockoutReviewFile(runDir, pass = 0) {
|
|
|
136
65
|
return join(String(runDir ?? ""), pass ? `knockout-review-${Number(pass)}.json` : "knockout-review.json");
|
|
137
66
|
}
|
|
138
67
|
|
|
139
|
-
/**
|
|
140
|
-
* The address as one string, for joining and for saying which address was refused.
|
|
141
|
-
*
|
|
142
|
-
* ONE SPELLING. The merge joins on it, the refusal names it and the applier looks it up, so a second
|
|
143
|
-
* way of writing the same address is a rewrite that merges against itself and applies to nothing.
|
|
144
|
-
*
|
|
145
|
-
* THE SEPARATOR IS A NUL, not a space, and it is named rather than inlined. A mark name may contain a
|
|
146
|
-
* space — "OPEN COUNTRY" is an ordinary mark — so a space-joined key lets two different addresses
|
|
147
|
-
* collide into one string, and the second rewrite would silently replace the first in the merge. A NUL
|
|
148
|
-
* cannot appear in a field name or a mark name. It is also invisible in a diff, which is why it is a
|
|
149
|
-
* named constant: the property is in the name, where a reader can see it.
|
|
150
|
-
*/
|
|
151
|
-
const ADDRESS_SEP = "\u0000"; // named: a literal control character in the source is invisible
|
|
152
|
-
|
|
153
|
-
export function addressKey(at) {
|
|
154
|
-
const a = at ?? {};
|
|
155
|
-
return [a.field, a.mark ?? "", a.index ?? "", a.ordinal ?? ""].join(ADDRESS_SEP);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* THE ADDRESS A SEAT PROBABLY MEANT, FOR THE REFUSAL TO NAME — and for nothing else.
|
|
160
|
-
*
|
|
161
|
-
* The lookup above stays EXACT and that is a ruling, not an oversight (owner, 2026-09-16). Punctuation
|
|
162
|
-
* can be part of a mark's identity, so two marks differing by an apostrophe form are not assumed to be
|
|
163
|
-
* one mark and a rewrite is never applied by analogy. What was wrong was the refusal, not the matching:
|
|
164
|
-
* a seat that re-typed a name with a right single quotation mark where the record has an apostrophe was
|
|
165
|
-
* told its rewrite "names no line on this record", which describes the record rather than the difference,
|
|
166
|
-
* and the rewrite was dropped with nobody able to see why. One character, invisible in most fonts.
|
|
167
|
-
*
|
|
168
|
-
* So this names the nearest and changes nothing. It folds ONLY typographic form — `queryKey`, the same
|
|
169
|
-
* key the meaning gate was folded onto after a production clearance stopped on exactly this character —
|
|
170
|
-
* and it is imported rather than copied, because two private folds are how the two gates drift apart.
|
|
171
|
-
* That key deliberately does not fold accents, so it cannot quietly propose that Café and Cafe are the
|
|
172
|
-
* same mark.
|
|
173
|
-
*
|
|
174
|
-
* It requires an EXACT match on every other part of the address — field, index, ordinal — so the hint is
|
|
175
|
-
* always the same line of the same record, differing only in how the mark's name was typed. A candidate
|
|
176
|
-
* whose mark is byte-identical is not a hint: the caller only asks when the exact lookup already failed,
|
|
177
|
-
* and pointing at the address that was just refused would say nothing.
|
|
178
|
-
*
|
|
179
|
-
* @returns {object|null} the address on this record, or null when nothing differs by form alone
|
|
180
|
-
*/
|
|
181
|
-
export function nearestAddress(at, knownAts) {
|
|
182
|
-
const want = at ?? {};
|
|
183
|
-
if (want.mark == null) return null; // no name to have mistyped
|
|
184
|
-
const same = (a, b) => (a ?? "") === (b ?? "");
|
|
185
|
-
for (const k of knownAts ?? []) {
|
|
186
|
-
if (!k || k.field !== want.field) continue;
|
|
187
|
-
if (!same(k.index, want.index) || !same(k.ordinal, want.ordinal)) continue;
|
|
188
|
-
const kn = String(k.mark ?? ""), wn = String(want.mark ?? "");
|
|
189
|
-
if (kn !== wn && queryKey(kn) === queryKey(wn)) return k;
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** Is this a well-formed address for a field the pass may reach? The reason, or null. */
|
|
195
|
-
export function addressFault(at) {
|
|
196
|
-
if (!at || typeof at !== "object" || Array.isArray(at)) return "an address must be an object";
|
|
197
|
-
const field = at.field;
|
|
198
|
-
if (typeof field !== "string" || !Object.hasOwn(ADDRESSABLE, field))
|
|
199
|
-
return `"${String(field)}" is not an addressable field — one of ${Object.keys(ADDRESSABLE).join(", ")}`;
|
|
200
|
-
const need = ADDRESSABLE[field];
|
|
201
|
-
for (const k of need) {
|
|
202
|
-
if (at[k] === undefined || at[k] === null) return `address for "${field}" needs ${k}`;
|
|
203
|
-
if (k === "mark" && (typeof at.mark !== "string" || !at.mark.trim())) return `address for "${field}": mark must be a name`;
|
|
204
|
-
if ((k === "index" || k === "ordinal") && !Number.isInteger(at[k])) return `address for "${field}": ${k} must be an integer`;
|
|
205
|
-
}
|
|
206
|
-
for (const k of Object.keys(at)) {
|
|
207
|
-
if (k === "field" || need.includes(k)) continue;
|
|
208
|
-
return `address for "${field}" does not take "${k}"`;
|
|
209
|
-
}
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** SHAPE ONLY. Whether an address resolves against THIS run's record is the validator's join, not this. */
|
|
68
|
+
/** SHAPE ONLY. Whether a material row joins this run's record is the validator's join, not this. */
|
|
214
69
|
export function acceptKnockoutReview(call) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
70
|
+
// THE REVIEW REWORDS NOTHING: a call that still sends a rewrite or a declined line is refused, never quietly dropped.
|
|
71
|
+
for (const k of RETIRED_KEYS) {
|
|
72
|
+
const v = call?.[k];
|
|
73
|
+
if (v !== undefined && !(Array.isArray(v) && !v.length)) return { ok: false, reason: RETIRED_REASON(k) };
|
|
74
|
+
}
|
|
75
|
+
// THE ANSWER TO THE QUESTION THE PASS OPENS ON is recorded when the seat sends it. Only words are kept; anything else is left out
|
|
76
|
+
// rather than refused.
|
|
219
77
|
const firstQuestion = typeof call?.first_question === "string" && call.first_question.trim() ? call.first_question : undefined;
|
|
220
|
-
if (rewrites !== undefined && !Array.isArray(rewrites)) return { ok: false, reason: "rewrites must be an array" };
|
|
221
|
-
if (declined !== undefined && !Array.isArray(declined)) return { ok: false, reason: "declined must be an array" };
|
|
222
78
|
const material = call?.material;
|
|
223
79
|
if (material !== undefined && !Array.isArray(material)) return { ok: false, reason: "material must be an array" };
|
|
224
80
|
for (const m of material ?? []) {
|
|
@@ -230,177 +86,33 @@ export function acceptKnockoutReview(call) {
|
|
|
230
86
|
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` };
|
|
231
87
|
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` };
|
|
232
88
|
}
|
|
233
|
-
const seen = new Set();
|
|
234
|
-
for (const r of rewrites ?? []) {
|
|
235
|
-
const fault = addressFault(r?.at);
|
|
236
|
-
if (fault) return { ok: false, reason: `a rewrite's ${fault}` };
|
|
237
|
-
if (typeof r?.text !== "string" || !r.text.trim())
|
|
238
|
-
return { ok: false, reason: `the rewrite for "${r?.at?.field}" carries no replacement text` };
|
|
239
|
-
for (const k of Object.keys(r)) if (!["at", "text", "why"].includes(k)) return { ok: false, reason: `a rewrite does not take "${k}"` };
|
|
240
|
-
const key = addressKey(r.at);
|
|
241
|
-
if (seen.has(key)) return { ok: false, reason: `two rewrites address the same line ("${r.at.field}") — send one` };
|
|
242
|
-
seen.add(key);
|
|
243
|
-
}
|
|
244
|
-
for (const d of declined ?? []) {
|
|
245
|
-
const fault = addressFault(d?.at);
|
|
246
|
-
if (fault) return { ok: false, reason: `a declined row's ${fault}` };
|
|
247
|
-
if (typeof d?.why !== "string" || !d.why.trim()) return { ok: false, reason: "a declined row must say why the line stands" };
|
|
248
|
-
for (const k of Object.keys(d)) if (!["at", "why"].includes(k)) return { ok: false, reason: `a declined row does not take "${k}"` };
|
|
249
|
-
}
|
|
250
|
-
// An empty call and a stage that never ran leave the same artifact behind, and they are different
|
|
251
|
-
// findings: one says the seat read the lines and had nothing to change, the other says nothing looked.
|
|
252
89
|
// A CLEAN READ IS AN ANSWER: the question answered and an empty list of defects sent. A call with neither cannot be told from a
|
|
253
90
|
// stage that never ran.
|
|
254
|
-
if (!(
|
|
91
|
+
if (!(material ?? []).length && !(Array.isArray(material) && firstQuestion !== undefined))
|
|
255
92
|
return { ok: false, reason: "send `first_question` and `material`, an empty list where you found no defect — an empty call cannot be told from a stage that never ran" };
|
|
256
|
-
return { ok: true, model: { schema_version: SCHEMA_VERSION, ...(firstQuestion !== undefined ? { first_question: firstQuestion } : {}),
|
|
257
|
-
material: material ?? [], rewrites: rewrites ?? [], declined: declined ?? [] } };
|
|
93
|
+
return { ok: true, model: { schema_version: SCHEMA_VERSION, ...(firstQuestion !== undefined ? { first_question: firstQuestion } : {}), material: material ?? [] } };
|
|
258
94
|
}
|
|
259
95
|
|
|
260
|
-
/** Merge a repair turn onto what was already accepted
|
|
96
|
+
/** Merge a repair turn onto what was already accepted: `material` replaced when present and kept when absent, the answer likewise. */
|
|
261
97
|
export function mergeKnockoutReviewCall(was, now) {
|
|
262
|
-
const merge = (key) => {
|
|
263
|
-
const byAddr = new Map();
|
|
264
|
-
for (const row of was?.[key] ?? []) byAddr.set(addressKey(row?.at), row);
|
|
265
|
-
for (const row of now?.[key] ?? []) byAddr.set(addressKey(row?.at), row);
|
|
266
|
-
return [...byAddr.values()];
|
|
267
|
-
};
|
|
268
98
|
if (!was) return { ...now };
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* What the driver MEASURED, as the evidence this stage is dispatched with.
|
|
274
|
-
*
|
|
275
|
-
* THE DRIVER MEASURES, THE SEAT JUDGES — the same split the clearance block states. `plainRegisterFlags`
|
|
276
|
-
* is deterministic and says which line carries a word of the profession's and how long a sentence ran.
|
|
277
|
-
* Whether the sentence is actually wrong, and what replaces it, is the seat's call. The ruling behind
|
|
278
|
-
* this rejects a word list AS THE MECHANISM, so the seat is handed evidence and never a verdict: half
|
|
279
|
-
* these words are ordinary English and several are plausible marks.
|
|
280
|
-
*
|
|
281
|
-
* BLIND TO THE RUN'S OWN NOUNS, and the empty case SAYS SO. `about` blanks every mark and owner before
|
|
282
|
-
* the text is read, because a check that flagged the mark being cleared would put its noise on the one
|
|
283
|
-
* report where it matters most. When the run named no mark to exclude, the seat is told that outright —
|
|
284
|
-
* an absolute reassurance is false in exactly the state where a flag IS the mark, and telling a seat
|
|
285
|
-
* nothing is worse than telling it the truth about what was not done.
|
|
286
|
-
*
|
|
287
|
-
* ENGINE-OWNED LINES ARE NOT OFFERED. They are in the walk and out of the pass's reach; see the applier.
|
|
288
|
-
*/
|
|
289
|
-
export function reviewEvidence(merged, about = {}) {
|
|
290
|
-
const rows = [];
|
|
291
|
-
for (const { where, text, at } of knockoutVisibleProse(merged)) {
|
|
292
|
-
// OFFERED ONLY WHAT CAN BE REWRITTEN. The walk is wider than this pass in both directions — see
|
|
293
|
-
// ADDRESSABLE — and handing a seat a line it cannot address wastes the turn and teaches it that a
|
|
294
|
-
// refused address is normal.
|
|
295
|
-
if (at?.engineOwned || !Object.hasOwn(ADDRESSABLE, at?.field)) continue;
|
|
296
|
-
const flags = plainRegisterFlags(text, about);
|
|
297
|
-
if (!flags.length) continue;
|
|
298
|
-
rows.push({ at: offeredAddress(at), where, says: flags.map((f) => f.say) });
|
|
299
|
-
}
|
|
300
|
-
const marks = (about.marks ?? []).filter(Boolean), owners = (about.owners ?? []).filter(Boolean);
|
|
301
|
-
const ownerNote = owners.length ? ` The ${owners.length} owner name(s) from the record were also removed.` : "";
|
|
302
|
-
const exclusionNote = marks.length
|
|
303
|
-
? `The ${marks.length} mark(s) this run is about were removed before reading, so none of these is a hit inside a name being screened.${ownerNote}`
|
|
304
|
-
: `THIS RUN NAMED NO MARK TO EXCLUDE, so the names being screened were NOT removed before reading — a flag below may BE one of them. Check each against the batch before rewriting it.${ownerNote}`;
|
|
305
|
-
return { rows, exclusionNote };
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/** The addresses the driver offered this run, for the seat to quote back. One line each. */
|
|
309
|
-
export function reviewEvidenceLines({ rows }) {
|
|
310
|
-
return rows.map(({ at, where, says }) => `- ${where} — address ${JSON.stringify(at)} — ${says.join(" ")}`);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* The lines a reader meets first, each one the pass may write, with the address that names it.
|
|
315
|
-
*
|
|
316
|
-
* Handed to the reviewer on a record the driver's read flagged nowhere (owner ruling 2026-10-10). Its
|
|
317
|
-
* first question is the client's, and it can rewrite toward that answer, or decline, only at an address
|
|
318
|
-
* it was given: the tool refuses a composed one. The set is the one the flagged table is drawn from,
|
|
319
|
-
* without the flag, so the engine's own caveats and any field the applier cannot write stay out here too.
|
|
320
|
-
*/
|
|
321
|
-
export function reviewFirstReadRows(merged) {
|
|
322
|
-
return knockoutVisibleProse(merged)
|
|
323
|
-
.filter(({ at }) => !at?.engineOwned && Object.hasOwn(ADDRESSABLE, at?.field))
|
|
324
|
-
.map(({ at, where }) => ({ at: offeredAddress(at), where }));
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* An address as the seat is told to copy it: the field and the keys that field takes, nothing else.
|
|
329
|
-
*
|
|
330
|
-
* The walk marks a standing caveat with `engineOwned`, true or false, to decide what is offered at all.
|
|
331
|
-
* The grammar refuses any key a field does not take, so an offered address that carried the mark would
|
|
332
|
-
* be refused when copied verbatim, as the tool tells the seat to copy it.
|
|
333
|
-
*/
|
|
334
|
-
export function offeredAddress(at) {
|
|
335
|
-
const out = { field: at.field };
|
|
336
|
-
for (const k of ADDRESSABLE[at.field] ?? []) if (at[k] !== undefined) out[k] = at[k];
|
|
337
|
-
return out;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/** One line each, the address quoted for the seat to copy back. */
|
|
341
|
-
export function reviewFirstReadLines(rows) {
|
|
342
|
-
return rows.map(({ at, where }) => `- ${where} — address ${JSON.stringify(at)}`);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* What the reviewing pass hands the reviewer, decided before any turn is spent. PURE.
|
|
347
|
-
*
|
|
348
|
-
* EVERY KNOCKOUT IS REVIEWED. Flagged lines go as the measured table. A record flagged nowhere hands
|
|
349
|
-
* over its first-read lines instead, so the client's question is put on every record. Only a record with
|
|
350
|
-
* no such line at all is not dispatched, because there would be nothing to read and no address to answer.
|
|
351
|
-
*/
|
|
352
|
-
export function reviewDispatch(merged, plan) {
|
|
353
|
-
const about = reviewAbout(merged, plan);
|
|
354
|
-
const evidence = reviewEvidence(merged, about);
|
|
355
|
-
const firstRead = evidence.rows.length ? [] : reviewFirstReadRows(merged);
|
|
356
|
-
return {
|
|
357
|
-
about, evidence, flagged: evidence.rows.length, listed: firstRead.length,
|
|
358
|
-
dispatch: evidence.rows.length > 0 || firstRead.length > 0,
|
|
359
|
-
msgCtx: {
|
|
360
|
-
evidenceLines: reviewEvidenceLines(evidence),
|
|
361
|
-
firstReadLines: reviewFirstReadLines(firstRead),
|
|
362
|
-
exclusionNote: evidence.exclusionNote,
|
|
363
|
-
},
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* The `about` a knockout run is blind to: every name in the batch, and every owner on the record.
|
|
369
|
-
*
|
|
370
|
-
* TWO SOURCES, AND ONLY ONE OF THEM PROTECTS THE NAME BEING SCREENED. Owners come from the RECORD and
|
|
371
|
-
* marks from the PLAN, so keying the reassurance on the union lets a record carrying thirteen owners
|
|
372
|
-
* fire it over a batch that named no mark — telling the seat no flag is a screened name, over a flag
|
|
373
|
-
* that is exactly that. The clearance side measured this; the two are counted separately here for it.
|
|
374
|
-
*/
|
|
375
|
-
export function reviewAbout(merged, plan) {
|
|
376
|
-
const marks = [
|
|
377
|
-
...(plan?.marks ?? []).map((m) => (typeof m === "string" ? m : m?.name)),
|
|
378
|
-
...(merged?.marks ?? []).map((m) => m?.name),
|
|
379
|
-
].filter((x) => typeof x === "string" && x.trim());
|
|
380
|
-
const owners = (merged?.marks ?? [])
|
|
381
|
-
.flatMap((m) => [...(m?.findings ?? []).map((f) => f?.owner), ...(m?.registerReads ?? []).map((r) => r?.owner)])
|
|
382
|
-
.filter((x) => typeof x === "string" && x.trim());
|
|
383
|
-
return { marks: [...new Set(marks)], owners: [...new Set(owners)] };
|
|
99
|
+
// A call accepted by an earlier build may carry the retired keys; only this turn's own can be refused.
|
|
100
|
+
const { rewrites: _rewrites, declined: _declined, ...base } = was;
|
|
101
|
+
return { ...base, ...now, material: now?.material ?? base.material };
|
|
384
102
|
}
|
|
385
103
|
|
|
386
104
|
/**
|
|
387
105
|
* The stage's `validate` — shape, and the JOIN against the record this run actually holds.
|
|
388
106
|
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* from `predelivery-lint.mjs`, which reads `isEngineAppendedCaveat` from `verify-knockout.mjs`. ESM
|
|
392
|
-
* would survive it and the hazard would be a const read during module init, years from now, by someone
|
|
393
|
-
* who did not know the cycle was there. The stage def imports its validator from here instead.
|
|
394
|
-
*
|
|
395
|
-
* THE JOIN IS THE HALF THAT MATTERS. Shape alone accepts a rewrite aimed at a mark this run does not
|
|
396
|
-
* carry, and the applier would then report it unresolved AFTER the stage had been declared good — a
|
|
397
|
-
* seat's whole turn wasted with nothing telling it why. Refusing here puts the reason in front of the
|
|
398
|
-
* seat while it can still send a repair turn.
|
|
107
|
+
* THE JOIN IS THE HALF THAT MATTERS. Shape alone accepts a material row aimed at a mark this run does not carry, or resting on a
|
|
108
|
+
* source it does not hold. Refusing here puts the reason in front of the seat while it can still send a repair turn.
|
|
399
109
|
*/
|
|
400
110
|
export function validateKnockoutReviewFile(file, text) {
|
|
401
111
|
let doc;
|
|
402
112
|
try { doc = JSON.parse(text); } catch (e) { return { ok: false, reason: `not valid JSON: ${e.message}` }; }
|
|
403
|
-
|
|
113
|
+
// A SAVED FILE IS NOT A FRESH CALL. One an earlier build accepted may still carry the retired lists; they are read past and never
|
|
114
|
+
// applied, so a resumed run keeps its review without summoning a reviewer to drop them. A fresh call carrying one is still refused.
|
|
115
|
+
const shape = acceptKnockoutReview(Object.fromEntries(Object.entries(doc ?? {}).filter(([k]) => !RETIRED_KEYS.includes(k))));
|
|
404
116
|
if (!shape.ok) return shape;
|
|
405
117
|
|
|
406
118
|
// The run dir, from the artifact's own path rather than a fixed depth — the assumption that bit the
|
|
@@ -409,8 +121,7 @@ export function validateKnockoutReviewFile(file, text) {
|
|
|
409
121
|
const runDir = basename(dir) === DRIVER_DIR ? dirname(dir) : dir;
|
|
410
122
|
const findingsFile = join(runDir, "knockout-findings.json");
|
|
411
123
|
if (!existsSync(findingsFile)) {
|
|
412
|
-
// A COULD-NOT-LOOK, SAID AS ONE. Passing here would let every
|
|
413
|
-
// the receipt exactly like a run whose addresses all resolved.
|
|
124
|
+
// A COULD-NOT-LOOK, SAID AS ONE. Passing here would let every material row through unchecked.
|
|
414
125
|
return { ok: false, reason: `the merged record is not on disk at ${findingsFile}, so no address could be checked` };
|
|
415
126
|
}
|
|
416
127
|
let merged;
|
|
@@ -422,26 +133,10 @@ export function validateKnockoutReviewFile(file, text) {
|
|
|
422
133
|
|
|
423
134
|
/**
|
|
424
135
|
* 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,
|
|
425
|
-
* so a bad
|
|
426
|
-
*
|
|
136
|
+
* so a bad reference is refused while the seat can still repair it in its turn. Heard only at the end, it cost a whole attempt each
|
|
137
|
+
* time: on a saved batch, 2026-11-05, two refusals of one reference spent 430 s and 50,000 generated tokens on one stage.
|
|
427
138
|
*/
|
|
428
139
|
function joinFault(doc, merged, runDir) {
|
|
429
|
-
const knownAts = knockoutVisibleProse(merged).map((v) => v.at);
|
|
430
|
-
const known = new Set(knownAts.map((a) => addressKey(a)));
|
|
431
|
-
const owned = new Set(knockoutVisibleProse(merged).filter((v) => v.at?.engineOwned).map((v) => addressKey(v.at)));
|
|
432
|
-
// Appended to a refusal, never consulted before one: the address still has to match exactly.
|
|
433
|
-
const hint = (at) => {
|
|
434
|
-
const n = nearestAddress(at, knownAts);
|
|
435
|
-
return n ? ` — this record carries "${n.mark}" at that line, which differs from "${at.mark}" only in how it is typed; the two are not assumed to be the same mark, so re-send the rewrite naming the record's spelling` : "";
|
|
436
|
-
};
|
|
437
|
-
for (const r of doc.rewrites ?? []) {
|
|
438
|
-
const key = addressKey(r.at);
|
|
439
|
-
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`;
|
|
440
|
-
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)}`;
|
|
441
|
-
}
|
|
442
|
-
for (const d of doc.declined ?? []) {
|
|
443
|
-
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)}`;
|
|
444
|
-
}
|
|
445
140
|
for (const m of doc.material ?? []) {
|
|
446
141
|
const fault = materialFault(m, merged, runDir);
|
|
447
142
|
if (fault) return fault;
|
|
@@ -464,94 +159,6 @@ function materialFault(m, merged, runDir) {
|
|
|
464
159
|
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;
|
|
465
160
|
}
|
|
466
161
|
|
|
467
|
-
/**
|
|
468
|
-
* The rewrites of a first pass that still have a line to land on after a correction: those on a name the correction did not
|
|
469
|
-
* change, and the standing caveats. A changed name, whether a defect named it or the correction reached it, is renumbered and
|
|
470
|
-
* reworded, and the batch summary with it, so the second pass reads those afresh. `changedNames` null means the correction's
|
|
471
|
-
* reach could not be compared: no rewrite on a name is taken to be independent of it, and only the caveats stand. PURE.
|
|
472
|
-
*/
|
|
473
|
-
export function rewritesThatSurvive(review, changedNames) {
|
|
474
|
-
const corrected = changedNames == null ? null : new Set([...changedNames].map((n) => String(n ?? "").trim().toLowerCase()));
|
|
475
|
-
const stands = (r) => r?.at?.field === "batch.standardCaveats" || (corrected != null && r?.at?.mark != null && !corrected.has(String(r.at.mark).trim().toLowerCase()));
|
|
476
|
-
return { ...review, rewrites: (review?.rewrites ?? []).filter(stands) };
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Apply accepted rewrites to the merged record, and say exactly what happened to each one.
|
|
481
|
-
*
|
|
482
|
-
* WHAT THIS MAY CHANGE, AND WHAT IT MAY NOT. Prose on a default-visible line, and nothing else. It
|
|
483
|
-
* never adds or removes a mark, a finding or a caveat, never touches a band, an ordinal, evidence or a
|
|
484
|
-
* count, and never lengthens or shortens an array. An address that does not resolve against THIS record
|
|
485
|
-
* is reported as unresolved and changes nothing — a rewrite aimed at a mark the run does not carry is a
|
|
486
|
-
* defect in the pass, and applying it by nearest match is how it would become a defect in the report.
|
|
487
|
-
*
|
|
488
|
-
* A CLONE, NOT AN IN-PLACE EDIT. The caller keeps the original to fall back to, and the failure path
|
|
489
|
-
* below depends on there being one: this pass is the last thing that should be able to cost a client a
|
|
490
|
-
* report, so anything it cannot do cleanly it does not do at all.
|
|
491
|
-
*
|
|
492
|
-
* `engineOwned` IS REFUSED HERE TOO, not only left out of the dispatch. A caveat the engine appended is
|
|
493
|
-
* matched at delivery by `SURVIVOR_BOUNDARY_RE`; a rewrite that landed on it would either break that
|
|
494
|
-
* match or append a second copy of the note, and both are silent. The dispatch never offers those
|
|
495
|
-
* lines, so a rewrite naming one did not come from the evidence it was handed.
|
|
496
|
-
*/
|
|
497
|
-
export function applyKnockoutReview(merged, review) {
|
|
498
|
-
const doc = JSON.parse(JSON.stringify(merged ?? {}));
|
|
499
|
-
// THE WALK IS RE-DERIVED FROM THIS RECORD, never passed in. An index is only in range for the record
|
|
500
|
-
// it was measured on, and a caller holding a walk from before the merge would write into a slot that
|
|
501
|
-
// has moved — silently, because the address still resolves. Deriving it here makes the two the same
|
|
502
|
-
// record by construction.
|
|
503
|
-
const byKey = new Map();
|
|
504
|
-
for (const v of knockoutVisibleProse(doc)) byKey.set(addressKey(v.at), v);
|
|
505
|
-
|
|
506
|
-
const applied = [], unresolved = [], refused = [];
|
|
507
|
-
for (const r of review?.rewrites ?? []) {
|
|
508
|
-
const key = addressKey(r.at);
|
|
509
|
-
const seen = byKey.get(key);
|
|
510
|
-
if (!seen) {
|
|
511
|
-
// Same hint as the validator's, for the same reason: the apply path is reached on a record this
|
|
512
|
-
// pass did not validate, and an unresolved row that cannot say WHY is the state that cost a
|
|
513
|
-
// rewrite silently. It still changes nothing — `unresolved` is a report.
|
|
514
|
-
const near = nearestAddress(r.at, [...byKey.values()].map((v) => v.at));
|
|
515
|
-
unresolved.push({ at: r.at, why: near ? `no such line on this record — it carries "${near.mark}" there, differing from "${r.at.mark}" only in how it is typed` : "no such line on this record" });
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
if (seen.at?.engineOwned) { refused.push({ at: r.at, why: "the engine wrote this caveat, not a seat" }); continue; }
|
|
519
|
-
const at = r.at, text = String(r.text);
|
|
520
|
-
// THE WALK IS THE BOUNDS CHECK. `seen` came from this same record, so a resolved address names a
|
|
521
|
-
// field that exists and an index that is in range. The two lookups below cannot fail while that
|
|
522
|
-
// holds — they are here because if they ever DO fire, the walk and the record disagree about the
|
|
523
|
-
// shape of the same document, and writing through that disagreement is how a rewrite lands on the
|
|
524
|
-
// wrong mark. They report; they never guess a nearest match.
|
|
525
|
-
const mark = at.mark == null ? null : (doc.marks ?? []).find((m) => String(m?.name ?? "") === at.mark);
|
|
526
|
-
if (at.mark != null && !mark) { unresolved.push({ at, why: "the walk and the record disagree: no such mark" }); continue; }
|
|
527
|
-
switch (at.field) {
|
|
528
|
-
case "batch.executiveSummary": doc.batch.executiveSummary = text; break;
|
|
529
|
-
case "batch.standardCaveats": doc.batch.standardCaveats[at.index] = text; break;
|
|
530
|
-
case "basis": mark.basis = text; break;
|
|
531
|
-
case "mitigation": mark.mitigation = text; break;
|
|
532
|
-
case "factors": mark.factors[at.index] = text; break;
|
|
533
|
-
case "counterFactors": mark.counterFactors[at.index] = text; break;
|
|
534
|
-
case "purpleNotes": {
|
|
535
|
-
const note = mark.purpleNotes[at.index];
|
|
536
|
-
if (note && typeof note === "object") note.text = text; else mark.purpleNotes[at.index] = text;
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
case "registerReads": mark.registerReads[at.index].read = text; break;
|
|
540
|
-
case "findings.net": {
|
|
541
|
-
// JOINED ON THE ORDINAL, never on position — the merged gate re-ranks and renumbers on the band,
|
|
542
|
-
// so the index that addressed this row upstream addresses a different row after normalisation.
|
|
543
|
-
const f = (mark.findings ?? []).find((x) => x?.ordinal === at.ordinal);
|
|
544
|
-
if (!f) { unresolved.push({ at, why: "the walk and the record disagree: no finding with that ordinal" }); continue; }
|
|
545
|
-
f.net = text;
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
548
|
-
default: refused.push({ at, why: "not an addressable field" }); continue;
|
|
549
|
-
}
|
|
550
|
-
applied.push({ at, chars: text.length });
|
|
551
|
-
}
|
|
552
|
-
return { doc, receipt: { applied: applied.length, unresolved, refused, declined: (review?.declined ?? []).length } };
|
|
553
|
-
}
|
|
554
|
-
|
|
555
162
|
export function recordKnockoutReview(runDir, received, { boundOrdinal = null, now = () => new Date().toISOString() } = {}) {
|
|
556
163
|
const dir = String(runDir ?? "");
|
|
557
164
|
const pass = Number(boundOrdinal) || 0;
|
|
@@ -603,8 +210,6 @@ export function recordKnockoutReview(runDir, received, { boundOrdinal = null, no
|
|
|
603
210
|
written: file,
|
|
604
211
|
refused: null,
|
|
605
212
|
material: verdict.model.material.length,
|
|
606
|
-
rewrites: verdict.model.rewrites.length,
|
|
607
|
-
declined: verdict.model.declined.length,
|
|
608
213
|
captured: closeCapture({ ok: true }),
|
|
609
214
|
capture_failed: captureFailed,
|
|
610
215
|
};
|
|
@@ -17,6 +17,7 @@ import { witnessStageMethodology, describeMethodologyDrift } from "../methodolog
|
|
|
17
17
|
import { inlineManuals } from "../manuals-inline.mjs";
|
|
18
18
|
import { builtinToolsFor } from "../engine/mcp/gather-config.mjs";
|
|
19
19
|
import { statOf } from "./judge.mjs";
|
|
20
|
+
import { recordEngineAnswered, turnAnswered } from "../engine/health.mjs"; // a completed turn moves the engine check's clock
|
|
20
21
|
import { correctiveMessage, warmPatchMessage, warmTimeoutMessage } from "./repair-messages.mjs";
|
|
21
22
|
import { retryBackoffMs, sleep, vetoResumeRuledNone, warmEligible } from "./turn-signals.mjs";
|
|
22
23
|
|
|
@@ -59,7 +60,7 @@ export async function retryMode({ name }, { attempt, lastFail, lastJson, lastKil
|
|
|
59
60
|
|
|
60
61
|
export async function dispatchTurn(stage, { attempt, warm, timeoutWarm, vetoedResume, lastFail, lastKey, lastSessionRef, warmEscalatedAt, effTimeout }) {
|
|
61
62
|
const { name, engine, stageHome, agent, message, refreshMessage, model, thinking, sessionKey, stallSec, files, maxRetries, runDir, followup, adds,
|
|
62
|
-
supplementalLane, gatherAllowedTools, gatherSeatWrites, engineSkillsDir, engineSkillsGrantRoots, engineResolveSkill, turnConfig } = stage;
|
|
63
|
+
supplementalLane, gatherAllowedTools, gatherSeatWrites, turnOutput, engineSkillsDir, engineSkillsGrantRoots, engineResolveSkill, turnConfig } = stage;
|
|
63
64
|
// Snapshot each expected artifact at THIS attempt's start. TWO readers, one base — so they can never
|
|
64
65
|
// disagree about what this dispatch emitted:
|
|
65
66
|
// · AD-4 emitted-vs-landed telemetry — `wrote` says whether this dispatch WROTE its artifact, as
|
|
@@ -134,12 +135,13 @@ export async function dispatchTurn(stage, { attempt, warm, timeoutWarm, vetoedRe
|
|
|
134
135
|
// already holds them, and its message names none. The dispatch record and the witness above keep the composed text.
|
|
135
136
|
const wire = warm || timeoutWarm ? { text: effMessage, inlined: [], missing: [] }
|
|
136
137
|
: inlineManuals(effMessage, { resolve: engineResolveSkill, skillsDir: engineSkillsDir });
|
|
137
|
-
const turn = await engine.runTurn({ agent, sessionKey: key, message: wire.text, grantDispatch: base, model, thinking, timeoutSec: effTimeout, resumeRef: warm ? lastSessionRef : undefined, stageHome, mcpConfig, allowedTools: gatherAllowedTools, builtinTools: builtinToolsFor(name), seatWrites: gatherSeatWrites, skillsDir: engineSkillsDir, skillsGrantRoots: engineSkillsGrantRoots, profilesDir: profilesStoreDir, resolveSkill: engineResolveSkill, runDir, stallSec,
|
|
138
|
+
const turn = await engine.runTurn({ agent, sessionKey: key, message: wire.text, grantDispatch: base, model, thinking, timeoutSec: effTimeout, resumeRef: warm ? lastSessionRef : undefined, stageHome, mcpConfig, allowedTools: gatherAllowedTools, builtinTools: builtinToolsFor(name), output: turnOutput, seatWrites: gatherSeatWrites, skillsDir: engineSkillsDir, skillsGrantRoots: engineSkillsGrantRoots, profilesDir: profilesStoreDir, resolveSkill: engineResolveSkill, runDir, stallSec,
|
|
138
139
|
progressFiles: files, // the no-progress watchdog's artifact-advance signal (anthropic-agent; other adapters ignore it)
|
|
139
140
|
// The raw stream of this session, beside its dispatch record (engine/session-record.mjs). The engines
|
|
140
141
|
// keep it while the disk has room and say on the tuple's `stream` what landed.
|
|
141
142
|
streamFile: streamFilePath(runDir, name, attempt) });
|
|
142
143
|
const settledAt = Date.now(); //: zero point of the wall-rescue quiescence clock, read before anything else
|
|
144
|
+
if (turnAnswered(turn)) recordEngineAnswered(engine.name);
|
|
143
145
|
// LOG-ONLY. Nothing here can fail a turn: the claim that the frozen set does not change across a seat
|
|
144
146
|
// turn is READ from the writers' call sites and not yet MEASURED on a running system, and arming an
|
|
145
147
|
// unmeasured guard is the defect class this exists to catch. One run supplies the number; the row's
|
|
@@ -24,7 +24,7 @@ import { builtinToolsFor } from "../engine/mcp/gather-config.mjs";
|
|
|
24
24
|
export async function repairFormInDispatch(stage, { judgeArtifacts }, { attempt, key, turn, effTimeout, fail, stampedQuantity, failingFile,
|
|
25
25
|
formRepairsUsed, killSeen, lastGraded, lastModelUsed }) {
|
|
26
26
|
const { name, engine, stageHome, agent, model, thinking, files, runDir, stallSec, adds, supplementalLane, auth, gatherAllowedTools,
|
|
27
|
-
|
|
27
|
+
turnOutput, engineSkillsDir, engineSkillsGrantRoots, engineResolveSkill, turnConfig } = stage;
|
|
28
28
|
const { json } = turn;
|
|
29
29
|
// ── — WRITE-TIME FORM REJECTION, INSIDE THE DISPATCH ────────────────────────────────────
|
|
30
30
|
// In the 08-02 round, 5 of 12 non-clean dispatches were PURE FORM: a bad enum, a closed-vocabulary
|
|
@@ -90,10 +90,10 @@ export async function repairFormInDispatch(stage, { judgeArtifacts }, { attempt,
|
|
|
90
90
|
// this turn wants. Passing `gatherSeatWrites` would lean on the dispatch naming an ABSOLUTE path
|
|
91
91
|
// under the run dir to win the grant back, and warmPatchMessage renders the target through rel();
|
|
92
92
|
// a relative path there would silently strip the write root off the one turn that needs it most.
|
|
93
|
-
// — AND THE OUTPUT RULE IS THE STAGE'S,
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
const rt = await engine.runTurn({ agent, sessionKey: key, message: repairMessage, model, thinking,
|
|
93
|
+
// — AND THE OUTPUT RULE IS THE STAGE'S, on both engines. A recording stage's form repair is a record call, so the turn
|
|
94
|
+
// keeps that stage's rule (engine/common.mjs, outputRule). It is read from the declaration, so the grant decided above
|
|
95
|
+
// is not touched.
|
|
96
|
+
const rt = await engine.runTurn({ agent, sessionKey: key, message: repairMessage, model, thinking, output: turnOutput,
|
|
97
97
|
timeoutSec: effTimeout, resumeRef: repairRef, stageHome, mcpConfig: turnConfig(effTimeout), allowedTools: gatherAllowedTools, builtinTools: builtinToolsFor(name),
|
|
98
98
|
skillsDir: engineSkillsDir, skillsGrantRoots: engineSkillsGrantRoots, profilesDir: profilesStoreDir, resolveSkill: engineResolveSkill, runDir, stallSec,
|
|
99
99
|
progressFiles: files, streamFile: streamFilePath(runDir, name, attempt, formRepairsUsed + 1) });
|