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,342 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
|
|
3
|
+
//
|
|
4
|
+
// knockout-correction-record.mjs — record_knockout_correction: a material defect reaches the step that can repair it.
|
|
5
|
+
//
|
|
6
|
+
// The knockout's independent check names a defect by mark and finding, with what it rests on. It changes nothing itself,
|
|
7
|
+
// because a band and a finding are the rating step's to reason. So a defect goes back to that step, for one correction and
|
|
8
|
+
// one recheck, as an address and never as prose to match. Nothing else about the batch is reopened.
|
|
9
|
+
//
|
|
10
|
+
// WHAT STANDS, STANDS BY CONSTRUCTION. A call may touch only the names a defect concerns, and a name no defect concerns cannot
|
|
11
|
+
// drift, nor its block in the summary, because no field reaches them. Inside an affected name the repair reaches what it needs,
|
|
12
|
+
// and says which defect each moved finding serves. A call sends only what changes, and its rows merge onto the chunk the run holds.
|
|
13
|
+
//
|
|
14
|
+
// THE CHUNK IS THE RECORD, so a corrected batch composes as a rated one does, through the same steps and the same gate, and
|
|
15
|
+
// a resumed run reads the correction back rather than losing it. An accepted repair stands when later work fails: only a change
|
|
16
|
+
// the record cannot stand with goes back, name by name, from the chunk as first rated, which is kept beside the run's work.
|
|
17
|
+
//
|
|
18
|
+
// A DEPENDENT ANSWER MOVES WITH WHAT IT DEPENDS ON. A rating that moves brings its basis, its opening read and the batch
|
|
19
|
+
// summary with it, and the summary's block for the name has to carry the band the name now has. Whether the prose is right
|
|
20
|
+
// is the recheck's to read; these checks only stop an answer being left behind on the old band.
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { copyFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { basename, dirname, join } from "node:path";
|
|
24
|
+
|
|
25
|
+
import { captureCall, stampVerdict } from "./call-capture.mjs";
|
|
26
|
+
import { DRIVER_DIR, driverDir } from "../shared/driver-dir.mjs";
|
|
27
|
+
import { acceptedEnvelope } from "./preserve-merge.mjs";
|
|
28
|
+
import { acceptKnockoutAssess, knockoutAssessCallPaths, knockoutAssessChunkFile, refuseUndeclared } from "./knockout-assess-record.mjs";
|
|
29
|
+
import { validators as koValidators } from "./verify-knockout.mjs";
|
|
30
|
+
|
|
31
|
+
const TOKEN = "knockoutcorrection";
|
|
32
|
+
const SCHEMA_VERSION = 1;
|
|
33
|
+
|
|
34
|
+
/** The artifact one correction leaves: the answer to each defect in its chunk, at the run root as a model's output is. */
|
|
35
|
+
export const knockoutCorrectionFile = (runDir, chunkNo) => join(String(runDir ?? ""), `knockout-correction-${Number(chunkNo)}.json`);
|
|
36
|
+
export const KNOCKOUT_CORRECTION_RE = /^knockout-correction-\d+\.json$/;
|
|
37
|
+
|
|
38
|
+
/** The driver's own account of the round: the record the check read, and each defect with its address. */
|
|
39
|
+
export const correctionWorkPath = (runDir) => driverDir(runDir, "knockout-correction-work.json");
|
|
40
|
+
const chunkBasePath = (runDir, chunkNo) => driverDir(runDir, `knockout-correction-base-${Number(chunkNo)}.json`);
|
|
41
|
+
const correctionCallDir = (runDir, chunkNo) => driverDir(runDir, join("knockout-correction-calls", `chunk-${Number(chunkNo)}`));
|
|
42
|
+
|
|
43
|
+
const nameKey = (s) => String(s ?? "").trim().toLowerCase();
|
|
44
|
+
const readJson = (path) => { try { return JSON.parse(readFileSync(path, "utf8")); } catch { return null; } };
|
|
45
|
+
/** A finding's identity across a renumbering: the gate re-ranks on the band, so an ordinal does not survive a move. */
|
|
46
|
+
export const sameFinding = (a, b) => nameKey(a?.name) === nameKey(b?.name) && nameKey(a?.owner) === nameKey(b?.owner);
|
|
47
|
+
const withoutOrdinal = (f) => { const { ordinal: _ordinal, ...rest } = f ?? {}; return JSON.stringify(rest); };
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The round's work, from the record the check read and the defects it raised: each numbered, on its chunk, with the finding
|
|
51
|
+
* it names held by identity. A defect on a name no chunk holds cannot have passed the review's own gate. PURE.
|
|
52
|
+
*/
|
|
53
|
+
export function correctionWork({ rated, material, chunks }) {
|
|
54
|
+
const chunkOf = new Map((chunks ?? []).flatMap((names, c) => names.map((n) => [nameKey(n?.name ?? n), c])));
|
|
55
|
+
const defects = (material ?? []).map((m, i) => {
|
|
56
|
+
const mark = (rated?.marks ?? []).find((r) => nameKey(r?.name) === nameKey(m.mark));
|
|
57
|
+
const finding = m.finding == null ? null : (mark?.findings ?? []).find((f) => f?.ordinal === m.finding) ?? null;
|
|
58
|
+
return { n: i + 1, kind: m.kind, mark: m.mark, ...(m.finding != null ? { finding: m.finding } : {}), problem: m.problem, rests_on: m.rests_on ?? [],
|
|
59
|
+
chunk: chunkOf.get(nameKey(m.mark)) ?? null,
|
|
60
|
+
...(finding ? { names: { name: finding.name, owner: finding.owner } } : {}) };
|
|
61
|
+
});
|
|
62
|
+
return { schema_version: SCHEMA_VERSION, rated, defects };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const readCorrectionWork = (runDir) => readJson(correctionWorkPath(runDir));
|
|
66
|
+
|
|
67
|
+
/** Keep each chunk a defect touches as it was rated. Written once: a resumed round must not take a corrected chunk for the base. */
|
|
68
|
+
export function keepChunkBases(runDir, chunkNos) {
|
|
69
|
+
for (const c of chunkNos) {
|
|
70
|
+
if (!existsSync(chunkBasePath(runDir, c))) copyFileSync(knockoutAssessChunkFile(runDir, c), chunkBasePath(runDir, c));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Put the chunks back as they were rated, where the record could stand with none of the round's repairs. */
|
|
75
|
+
export function restoreChunkBases(runDir, chunkNos) {
|
|
76
|
+
for (const c of chunkNos) {
|
|
77
|
+
if (existsSync(chunkBasePath(runDir, c))) copyFileSync(chunkBasePath(runDir, c), knockoutAssessChunkFile(runDir, c));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Which names of one chunk the round concerns, read against the chunk as rated, with the findings a defect names. PURE. */
|
|
82
|
+
export function chunkScope(work, chunkNo, base) {
|
|
83
|
+
const byMark = new Map();
|
|
84
|
+
const defects = (work?.defects ?? []).filter((d) => d.chunk === Number(chunkNo));
|
|
85
|
+
for (const d of defects) {
|
|
86
|
+
const key = nameKey(d.mark);
|
|
87
|
+
const row = byMark.get(key) ?? { named: new Set() };
|
|
88
|
+
if (d.names) {
|
|
89
|
+
const mark = (base?.marks ?? []).find((m) => nameKey(m?.name) === key);
|
|
90
|
+
for (const f of mark?.findings ?? []) if (sameFinding(f, d.names)) row.named.add(f.ordinal);
|
|
91
|
+
}
|
|
92
|
+
byMark.set(key, row);
|
|
93
|
+
}
|
|
94
|
+
return { defects, byMark };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** One name's block in a chunk summary: its `## NAME` sub-header to the next. Null where it has none. PURE. */
|
|
98
|
+
export function summaryBlock(summary, name) {
|
|
99
|
+
const want = nameKey(name);
|
|
100
|
+
const lines = String(summary ?? "").split("\n");
|
|
101
|
+
const at = lines.findIndex((l) => /^##\s/.test(l) && l.toLowerCase().includes(want));
|
|
102
|
+
if (at < 0) return null;
|
|
103
|
+
const end = lines.findIndex((l, i) => i > at && /^##\s/.test(l));
|
|
104
|
+
return lines.slice(at, end < 0 ? lines.length : end).join("\n");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function patchedFindings(mark, row, stop) {
|
|
108
|
+
const out = new Map((mark?.findings ?? []).map((f) => [f?.ordinal, f]));
|
|
109
|
+
for (const f of row.findings ?? []) {
|
|
110
|
+
if (!Number.isInteger(f?.ordinal)) return stop(`finding_ordinal:${row.name}: each finding names its ordinal: an existing one to replace it, or the next one for a new finding.`);
|
|
111
|
+
out.set(f.ordinal, f);
|
|
112
|
+
}
|
|
113
|
+
for (const o of row.remove_findings ?? []) out.delete(o);
|
|
114
|
+
return [...out.values()].sort((a, b) => a.ordinal - b.ordinal);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The chunk with one call applied, or why it cannot be. PURE. \`held\` is the chunk as it now stands. A name no defect concerns,
|
|
119
|
+
* and its block in the summary, stay as they are; a defect's repair may reach whatever findings of its own name it needs, and
|
|
120
|
+
* says which (\`mergedAnswers\`), so the check that follows can read the connection.
|
|
121
|
+
*/
|
|
122
|
+
export function applyCorrectionCall({ held, call, scope }) {
|
|
123
|
+
const refuse = (what) => ({ ok: false, reason: `${TOKEN}_${what}` });
|
|
124
|
+
let failure = null;
|
|
125
|
+
const stop = (what) => { failure = refuse(what); return null; };
|
|
126
|
+
const marks = (held?.marks ?? []).map((m) => m);
|
|
127
|
+
const moved = [];
|
|
128
|
+
for (const row of Array.isArray(call?.marks) ? call.marks : []) {
|
|
129
|
+
const name = String(row?.name ?? "");
|
|
130
|
+
if (!scope.byMark.has(nameKey(name))) return refuse(`scope:${name}: no material defect concerns this name. Leave it as it stands.`);
|
|
131
|
+
const i = marks.findIndex((m) => nameKey(m?.name) === nameKey(name));
|
|
132
|
+
if (i < 0) return refuse(`scope:${name}: this name is not in the chunk you were handed.`);
|
|
133
|
+
const { findings: _findings, remove_findings: _removed, ...fields } = row;
|
|
134
|
+
const next = { ...marks[i], ...fields };
|
|
135
|
+
if (row.findings !== undefined || row.remove_findings !== undefined) {
|
|
136
|
+
next.findings = patchedFindings(marks[i], row, stop);
|
|
137
|
+
if (failure) return failure;
|
|
138
|
+
}
|
|
139
|
+
const was = `${marks[i].rating}|${marks[i].ratingQualifier ?? ""}`, now = `${next.rating}|${next.ratingQualifier ?? ""}`;
|
|
140
|
+
if (was !== now) {
|
|
141
|
+
for (const key of ["basis", "assessment"]) {
|
|
142
|
+
if (row[key] === undefined) return refuse(`dependent:${name}: the rating moved from ${marks[i].rating} to ${next.rating}, and ${key} still reads for the old band. Send it as it now reads.`);
|
|
143
|
+
}
|
|
144
|
+
if (call.chunkSummary === undefined) return refuse(`dependent:${name}: the rating moved from ${marks[i].rating} to ${next.rating}, and chunkSummary still reads for the old band. Send it as it now reads.`);
|
|
145
|
+
}
|
|
146
|
+
marks[i] = next;
|
|
147
|
+
moved.push(name);
|
|
148
|
+
}
|
|
149
|
+
const chunkSummary = call?.chunkSummary ?? held?.chunkSummary;
|
|
150
|
+
for (const m of marks) {
|
|
151
|
+
if (scope.byMark.has(nameKey(m?.name))) continue;
|
|
152
|
+
if (summaryBlock(chunkSummary, m.name) !== summaryBlock(held?.chunkSummary, m.name)) return refuse(`summary:${m.name}: no defect concerns this name, so its block in chunkSummary stays as it was.`);
|
|
153
|
+
}
|
|
154
|
+
for (const name of moved) {
|
|
155
|
+
const m = marks.find((x) => nameKey(x?.name) === nameKey(name));
|
|
156
|
+
const block = summaryBlock(chunkSummary, name);
|
|
157
|
+
if (block && !block.toLowerCase().includes(String(m.rating ?? "").toLowerCase())) return refuse(`summary:${name}: its block in chunkSummary does not carry its band, ${m.rating}. Send chunkSummary as it now reads.`);
|
|
158
|
+
}
|
|
159
|
+
return { ok: true, chunk: { ...held, marks, chunkSummary } };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The ordinals of a name's findings that differ from the chunk as rated: changed, added or removed. PURE. */
|
|
163
|
+
function findingsMoved(baseMark, mark) {
|
|
164
|
+
const was = new Map((baseMark?.findings ?? []).map((f) => [f?.ordinal, f]));
|
|
165
|
+
const now = new Map((mark?.findings ?? []).map((f) => [f?.ordinal, f]));
|
|
166
|
+
return [...new Set([...was.keys(), ...now.keys()])].filter((o) => JSON.stringify(was.get(o)) !== JSON.stringify(now.get(o)));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The answers so far with this call's merged on by defect, or why they cannot stand. PURE. A defect not yet answered is left open,
|
|
171
|
+
* not refused: what the call did repair is kept. Every finding the repair moved is one a defect names or an answer claims, so a
|
|
172
|
+
* change never goes unexplained to the check that reads it.
|
|
173
|
+
*/
|
|
174
|
+
export function mergedAnswers(stored, received, scope, { base, chunk }) {
|
|
175
|
+
const refuse = (what) => ({ ok: false, reason: `${TOKEN}_${what}` });
|
|
176
|
+
const known = new Map(scope.defects.map((d) => [d.n, d]));
|
|
177
|
+
const byDefect = new Map((stored ?? []).map((a) => [a.defect, a]));
|
|
178
|
+
for (const a of Array.isArray(received) ? received : []) {
|
|
179
|
+
if (!known.has(a?.defect)) return refuse(`answers: there is no defect ${a?.defect} on this chunk.`);
|
|
180
|
+
if (!["changed", "stands"].includes(a?.outcome)) return refuse(`answers: defect ${a.defect} takes outcome "changed" or "stands".`);
|
|
181
|
+
if (typeof a?.why !== "string" || !a.why.trim()) return refuse(`answers: defect ${a.defect} carries no reason. Write down what you changed, or why the record stands.`);
|
|
182
|
+
byDefect.set(a.defect, { defect: a.defect, outcome: a.outcome, why: a.why.trim(), ...(Array.isArray(a.findings) && a.findings.length ? { findings: a.findings } : {}) });
|
|
183
|
+
}
|
|
184
|
+
const of = (doc, name) => (doc?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(name));
|
|
185
|
+
for (const a of byDefect.values()) {
|
|
186
|
+
if (a.outcome !== "changed") continue;
|
|
187
|
+
const d = known.get(a.defect);
|
|
188
|
+
if (JSON.stringify(of(base, d.mark)) === JSON.stringify(of(chunk, d.mark))) return refuse(`answers: defect ${a.defect} says changed, and nothing on ${d.mark} differs from the rated record. Send the change, or answer stands with your reason.`);
|
|
189
|
+
}
|
|
190
|
+
for (const [key, row] of scope.byMark) {
|
|
191
|
+
const mark = of(chunk, key);
|
|
192
|
+
const claimed = new Set([...row.named, ...[...byDefect.values()].filter((a) => nameKey(known.get(a.defect)?.mark) === key).flatMap((a) => a.findings ?? [])]);
|
|
193
|
+
const silent = findingsMoved(of(base, key), mark).find((o) => !claimed.has(o));
|
|
194
|
+
if (silent !== undefined) return refuse(`answers: finding ${silent} on ${mark?.name ?? key} changed, and no answer says which defect it serves. Name it in that answer's findings, or leave it as it was.`);
|
|
195
|
+
}
|
|
196
|
+
return { ok: true, answers: [...byDefect.values()].sort((x, y) => x.defect - y.defect), open: scope.defects.filter((d) => !byDefect.has(d.n)).map((d) => d.n) };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const chunkSha = (text) => createHash("sha256").update(text).digest("hex");
|
|
200
|
+
|
|
201
|
+
export function recordKnockoutCorrection(runDir, received, { boundOrdinal = null, now = () => new Date().toISOString() } = {}) {
|
|
202
|
+
const dir = String(runDir ?? "");
|
|
203
|
+
if (boundOrdinal === null || boundOrdinal === "") return { written: null, refused: `${TOKEN}_unbound: no chunk was bound for this turn. The driver sets it from the label it dispatched.` };
|
|
204
|
+
const chunkNo = Number(boundOrdinal);
|
|
205
|
+
const callDir = correctionCallDir(dir, chunkNo);
|
|
206
|
+
const cap = captureCall({ nameFor: (seq) => join(callDir, `call-${String(seq).padStart(3, "0")}.json`), params: received, extra: { boundOrdinal: String(boundOrdinal) }, now });
|
|
207
|
+
const closeCapture = (v) => { stampVerdict(cap.path, v); return cap.path; };
|
|
208
|
+
const refused = (reason) => {
|
|
209
|
+
try { writeFileSync(join(callDir, "refusals.jsonl"), JSON.stringify({ at: now(), reason }) + "\n", { flag: "a" }); }
|
|
210
|
+
catch { /* the refusal still stands and is still returned */ }
|
|
211
|
+
return { written: null, refused: reason, captured: closeCapture({ ok: false, refused: reason }), capture_failed: cap.failed };
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const { answers: receivedAnswers, ...rest } = received ?? {};
|
|
215
|
+
const undeclared = refuseUndeclared({ ...rest, marks: (Array.isArray(rest.marks) ? rest.marks : []).map(({ remove_findings: _r, ...m }) => m) });
|
|
216
|
+
if (undeclared) return refused(undeclared.replace(/^knockoutassess/, TOKEN));
|
|
217
|
+
|
|
218
|
+
const work = readCorrectionWork(dir);
|
|
219
|
+
const file = knockoutAssessChunkFile(dir, chunkNo);
|
|
220
|
+
const held = readJson(file), base = readJson(chunkBasePath(dir, chunkNo));
|
|
221
|
+
if (!work || !held || !base) return refused(`${TOKEN}_state: this run holds no correction for chunk ${chunkNo}.`);
|
|
222
|
+
const scope = chunkScope(work, chunkNo, base);
|
|
223
|
+
|
|
224
|
+
const applied = applyCorrectionCall({ held, call: rest, scope });
|
|
225
|
+
if (!applied.ok) return refused(applied.reason);
|
|
226
|
+
const receipt = knockoutCorrectionFile(dir, chunkNo);
|
|
227
|
+
const answers = mergedAnswers(readJson(receipt)?.answers, receivedAnswers, scope, { base, chunk: applied.chunk });
|
|
228
|
+
if (!answers.ok) return refused(answers.reason);
|
|
229
|
+
|
|
230
|
+
// THE SAME GATES A RATED CHUNK PASSED, at the call, while the seat can still repair what they name.
|
|
231
|
+
const shape = acceptKnockoutAssess(applied.chunk, { boundOrdinal });
|
|
232
|
+
if (!shape.ok) return refused(shape.reason);
|
|
233
|
+
const text = JSON.stringify(shape.model, null, 2) + "\n";
|
|
234
|
+
const gate = koValidators.knockoutAssessChunk(file, text);
|
|
235
|
+
if (!gate.ok) return refused(`${TOKEN}_gate: ${gate.reason}`);
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
writeFileSync(file, text);
|
|
239
|
+
writeFileSync(receipt, JSON.stringify({ schema_version: SCHEMA_VERSION, chunk: chunkNo, chunkSha: chunkSha(text), answers: answers.answers }, null, 2) + "\n");
|
|
240
|
+
} catch (e) {
|
|
241
|
+
return { written: null, refused: null, write_failed: String(e?.message ?? e).slice(0, 200), captured: closeCapture({ ok: false, write_failed: true }), capture_failed: cap.failed };
|
|
242
|
+
}
|
|
243
|
+
try { writeFileSync(knockoutAssessCallPaths(dir, chunkNo).accepted, acceptedEnvelope(shape.model, now())); }
|
|
244
|
+
catch { /* the chunk is the record; this is only the base a later rating call would merge onto */ }
|
|
245
|
+
return { written: receipt, refused: null, chunk: chunkNo, answers: answers.answers.length, ...(answers.open.length ? { still_open: answers.open } : {}), captured: closeCapture({ ok: true }), capture_failed: cap.failed };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Is this correction's answer whole, and of the chunk as it stands? koStage's skip-if-valid read, and the stage's own check. */
|
|
249
|
+
export function validateKnockoutCorrectionFile(file, content) {
|
|
250
|
+
let doc;
|
|
251
|
+
try { doc = JSON.parse(content); } catch (e) { return { ok: false, reason: `not valid JSON: ${e.message}` }; }
|
|
252
|
+
const dir = dirname(file);
|
|
253
|
+
const runDir = basename(dir) === DRIVER_DIR ? dirname(dir) : dir;
|
|
254
|
+
const chunkNo = Number(basename(file).match(/(\d+)\.json$/)?.[1]);
|
|
255
|
+
if (doc?.chunk !== chunkNo) return { ok: false, reason: `this answer is not chunk ${chunkNo}'s.` };
|
|
256
|
+
const work = readCorrectionWork(runDir);
|
|
257
|
+
if (!work) return { ok: false, reason: "this run holds no correction, so this answer cannot be checked." };
|
|
258
|
+
const owed = (work.defects ?? []).filter((d) => d.chunk === chunkNo);
|
|
259
|
+
if (!owed.length) return { ok: false, reason: `no defect is on chunk ${chunkNo}.` };
|
|
260
|
+
let held = null;
|
|
261
|
+
try { held = readFileSync(knockoutAssessChunkFile(runDir, chunkNo), "utf8"); } catch { held = null; }
|
|
262
|
+
if (held == null || doc.chunkSha !== chunkSha(held)) return { ok: false, reason: "this answer is not of the chunk as it now stands." };
|
|
263
|
+
const said = new Set([...(Array.isArray(doc.answers) ? doc.answers : []).map((a) => a?.defect), ...(doc.rolledBack ?? [])]);
|
|
264
|
+
const open = owed.filter((d) => !said.has(d.n)).map((d) => d.n);
|
|
265
|
+
return open.length ? { ok: false, reason: `defect ${open.join(", ")} has no answer.` } : { ok: true };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Take one name's repair back out of its chunk, because the record cannot stand with it: its row and its summary block return as
|
|
270
|
+
* rated, and its defects leave the answers as rolled back, so they stay open and a resumed run does not ask again.
|
|
271
|
+
*/
|
|
272
|
+
export function rollBackName(runDir, work, name) {
|
|
273
|
+
const defects = (work?.defects ?? []).filter((d) => nameKey(d.mark) === nameKey(name));
|
|
274
|
+
const chunkNo = defects[0]?.chunk;
|
|
275
|
+
if (chunkNo == null) return;
|
|
276
|
+
const base = readJson(chunkBasePath(runDir, chunkNo)), held = readJson(knockoutAssessChunkFile(runDir, chunkNo));
|
|
277
|
+
const rated = (base?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(name));
|
|
278
|
+
if (!base || !held || !rated) return;
|
|
279
|
+
const was = summaryBlock(base.chunkSummary, name), now = summaryBlock(held.chunkSummary, name);
|
|
280
|
+
const chunkSummary = was != null && now != null ? held.chunkSummary.replace(now, () => was) : held.chunkSummary;
|
|
281
|
+
const text = JSON.stringify({ ...held, chunkSummary, marks: held.marks.map((m) => (nameKey(m?.name) === nameKey(name) ? rated : m)) }, null, 2) + "\n";
|
|
282
|
+
writeFileSync(knockoutAssessChunkFile(runDir, chunkNo), text);
|
|
283
|
+
const receipt = readJson(knockoutCorrectionFile(runDir, chunkNo));
|
|
284
|
+
const ns = new Set(defects.map((d) => d.n));
|
|
285
|
+
if (receipt) writeFileSync(knockoutCorrectionFile(runDir, chunkNo), JSON.stringify({ ...receipt, chunkSha: chunkSha(text),
|
|
286
|
+
answers: (receipt.answers ?? []).filter((a) => !ns.has(a.defect)), rolledBack: [...new Set([...(receipt.rolledBack ?? []), ...ns])] }, null, 2) + "\n");
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** The refusals journalled for this chunk, newest last. The accessor a tool-written row carries. */
|
|
290
|
+
export function knockoutCorrectionRefusalsFor(runDir, chunkNo = 0) {
|
|
291
|
+
try {
|
|
292
|
+
return readFileSync(join(correctionCallDir(String(runDir ?? ""), chunkNo), "refusals.jsonl"), "utf8")
|
|
293
|
+
.split("\n").filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return { reason: l }; } });
|
|
294
|
+
} catch { return []; }
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** The answers every chunk of the round has given, by defect. */
|
|
298
|
+
export function correctionAnswers(runDir, chunkNos) {
|
|
299
|
+
const out = new Map();
|
|
300
|
+
for (const c of chunkNos) for (const a of readJson(knockoutCorrectionFile(runDir, c))?.answers ?? []) out.set(a.defect, a);
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* What the driver saw of each defect, comparing the record the check read with the current one: in the shape and the words the full
|
|
306
|
+
* engine's table and its resolved set read (corrections-feedforward.mjs). Findings are joined by identity, because the gate
|
|
307
|
+
* renumbers on the band. A correction's own account rides as its reason and never decides, and a defect no one answered says so. PURE.
|
|
308
|
+
*/
|
|
309
|
+
export function correctionOutcomes(work, after, answers = new Map()) {
|
|
310
|
+
const of = (doc, name) => (doc?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(name)) ?? null;
|
|
311
|
+
return (work?.defects ?? []).map((d) => {
|
|
312
|
+
const was = of(work.rated, d.mark), now = of(after, d.mark);
|
|
313
|
+
const answer = answers.get(d.n);
|
|
314
|
+
const common = { n: d.n, kind: d.kind, typed: true, text: d.problem, ordinals: d.finding != null ? [d.finding] : null, ...(answer ? { reason: answer.why } : {}) };
|
|
315
|
+
const moved = JSON.stringify(was) !== JSON.stringify(now);
|
|
316
|
+
if (!answer && !moved) return { ...common, targets: [d.names?.name ?? d.mark], outcome: "not-answered", removed: [] };
|
|
317
|
+
if (d.names) {
|
|
318
|
+
const label = d.names.name ?? `finding ${d.finding}`;
|
|
319
|
+
const before = (was?.findings ?? []).find((f) => sameFinding(f, d.names));
|
|
320
|
+
const current = (now?.findings ?? []).find((f) => sameFinding(f, d.names));
|
|
321
|
+
if (!current) return { ...common, targets: [label], outcome: "findings-removed", removed: [label] };
|
|
322
|
+
return { ...common, targets: [label], outcome: withoutOrdinal(before) !== withoutOrdinal(current) ? "findings-changed" : "findings-unchanged", removed: [] };
|
|
323
|
+
}
|
|
324
|
+
return { ...common, targets: [d.mark], outcome: moved ? "line-changed" : "line-unchanged", removed: [] };
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* What moved under a name no defect concerns, or an empty answer: its record, or its block in the batch summary. A call cannot reach
|
|
330
|
+
* these, so a row here is a fault between the chunk and the record, and the caller keeps the rated record. PURE.
|
|
331
|
+
*/
|
|
332
|
+
export function movedOutsideScope(work, after) {
|
|
333
|
+
const concerned = new Set((work?.defects ?? []).map((d) => nameKey(d.mark)));
|
|
334
|
+
const marks = [], blocks = [];
|
|
335
|
+
for (const was of work?.rated?.marks ?? []) {
|
|
336
|
+
if (concerned.has(nameKey(was?.name))) continue;
|
|
337
|
+
const now = (after?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(was?.name)) ?? null;
|
|
338
|
+
if (JSON.stringify(was) !== JSON.stringify(now)) marks.push(was.name);
|
|
339
|
+
if (summaryBlock(work.rated?.batch?.executiveSummary, was.name) !== summaryBlock(after?.batch?.executiveSummary, was.name)) blocks.push(was.name);
|
|
340
|
+
}
|
|
341
|
+
return { marks, blocks };
|
|
342
|
+
}
|
|
@@ -51,7 +51,7 @@ import { refuseUndeclared as refuseUndeclaredShared, keepIfAbsent, lastAccepted,
|
|
|
51
51
|
import { kebabCollisions } from "./search-policy.mjs";
|
|
52
52
|
// The plan's own checks for the web search's lists, one definition: the call is refused with the plan's
|
|
53
53
|
// sentence, so the seat hears the rule once, in the same words, whichever door it reaches first.
|
|
54
|
-
import { placesDefect, spellingsDefect, useKindDefect } from "./verify-knockout.mjs";
|
|
54
|
+
import { placesDefect, spellingsDefect, useKindDefect, alternativesDefect } from "./verify-knockout.mjs";
|
|
55
55
|
|
|
56
56
|
const SCHEMA_VERSION = 1;
|
|
57
57
|
|
|
@@ -86,7 +86,7 @@ export function knockoutFrameCallPaths(runDir) {
|
|
|
86
86
|
const DECLARED = Object.freeze({
|
|
87
87
|
"": ["schema", "batch", "marks", "scope_note"],
|
|
88
88
|
batch: ["productContext", "inUseAs", "places", "umbrellaBrandNote", "executionOrder"],
|
|
89
|
-
marks: ["ref", "name", "classes", "beltAndBraces", "classesPlain", "contextFraming", "useKind", "places", "spellings", "priorKnowledge", "priority"],
|
|
89
|
+
marks: ["ref", "name", "classes", "beltAndBraces", "classesPlain", "contextFraming", "useKind", "places", "spellings", "alternatives", "priorKnowledge", "priority"],
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
/** Refuse an undeclared key by path, through the shared implementation every transport now uses. */
|
|
@@ -201,6 +201,8 @@ export function acceptKnockoutFrame(params) {
|
|
|
201
201
|
}
|
|
202
202
|
const spellingsRefused = spellingsDefect(name, m?.spellings);
|
|
203
203
|
if (spellingsRefused) defects.push(`knockoutframe_spellings:${name} — ${spellingsRefused}`);
|
|
204
|
+
const alternativesRefused = alternativesDefect(name, m?.alternatives);
|
|
205
|
+
if (alternativesRefused) defects.push(`knockoutframe_alternatives:${name} — ${alternativesRefused}`);
|
|
204
206
|
for (const ck of ["classes", "beltAndBraces"]) {
|
|
205
207
|
if (m?.[ck] != null && !isClassArray(m[ck]))
|
|
206
208
|
defects.push(`knockoutframe_classes:${name}.${ck} must be Nice-class integers 1–45 — these interpolate into report and email HTML, so a free string is both a contract break and an injection surface`);
|