clearotron 0.6.0 → 0.7.0-beta.1
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 +7 -4
- package/QUICKSTART.md +1 -0
- package/README.md +5 -2
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/bin/clearotron.mjs +4 -2
- package/bin/onboard.mjs +158 -29
- package/build-info.json +2 -2
- package/docs/CLIENT-MCP.md +3 -1
- package/docs/DELIVERY.md +6 -3
- package/docs/architecture/02-architecture.md +1 -1
- package/docs/architecture/04-configuration-reference.md +105 -8
- package/docs/branding.md +4 -4
- package/docs/report-data/clearance-1.schema.json +320 -0
- package/docs/report-data/knockout-1.schema.json +268 -0
- package/driver/CHANGELOG.md +77 -0
- package/driver/cancel.mjs +19 -0
- package/driver/connotation-search.mjs +1 -1
- package/driver/contract-e3-backlog.mjs +41 -41
- package/driver/contract-vocabulary.mjs +1 -1
- package/driver/coverage-ledger.mjs +18 -2
- package/driver/deferral-row.mjs +1 -1
- package/driver/degraded-parts.mjs +1 -0
- package/driver/driver.config.mjs +5 -5
- package/driver/effective-scope.mjs +3 -1
- package/driver/engagement-receipt.mjs +3 -3
- package/driver/engine/anthropic-agent.mjs +15 -1
- package/driver/engine/common.mjs +7 -0
- package/driver/engine/mcp/band-server.mjs +7 -16
- package/driver/engine/mcp/codex-config.mjs +3 -0
- package/driver/engine/mcp/recording-server.mjs +45 -34
- package/driver/engine/openai-agent.mjs +74 -7
- package/driver/engine/session-record.mjs +44 -2
- package/driver/findings-model.mjs +14 -2
- package/driver/follow-up-twins.mjs +86 -0
- package/driver/gateway.mjs +77 -12
- package/driver/jx-units.mjs +3 -1
- package/driver/jx.mjs +13 -5
- package/driver/manuals-inline.mjs +98 -0
- package/driver/manuals-seen.mjs +134 -0
- package/driver/mark-logos.mjs +174 -0
- package/driver/methodology-witness.mjs +2 -1
- package/driver/owner-use-check.mjs +8 -4
- package/driver/package.json +1 -1
- package/driver/pipeline-knockout.mjs +23 -4
- package/driver/pipeline.mjs +128 -15
- package/driver/portal-local-auth.mjs +6 -2
- package/driver/portal-report.mjs +45 -14
- package/driver/portal-routes/me.mjs +4 -1
- package/driver/portal-runs.mjs +19 -16
- package/driver/predelivery-lint.mjs +7 -5
- package/driver/profiles.mjs +4 -4
- package/driver/publish/README.md +9 -7
- package/driver/publish/email-conditions.mjs +22 -5
- package/driver/publish/evidence-words.mjs +21 -0
- package/driver/publish/index.mjs +304 -211
- package/driver/publish/knockout.mjs +297 -247
- package/driver/publish/office-record-links.mjs +11 -9
- package/driver/publish/page-shell.mjs +98 -0
- package/driver/publish/pool-admin.mjs +2 -2
- package/driver/publish/publish-inputs.mjs +4 -0
- package/driver/publish/regions.mjs +28 -3
- package/driver/publish/register-record-html.mjs +105 -0
- package/driver/publish/register-record.mjs +165 -0
- package/driver/publish/render-knockout.mjs +299 -671
- package/driver/publish/render.mjs +561 -492
- package/driver/publish/report-data.mjs +226 -13
- package/driver/publish/report-document.mjs +353 -0
- package/driver/publish/search-depth.mjs +88 -7
- package/driver/publish/shell.mjs +41 -1
- package/driver/publish/strings.mjs +810 -0
- package/driver/publish/templates/clearance-print.css +23 -0
- package/driver/publish/templates/knockout.css +224 -0
- package/driver/publish/templates/report.css +112 -53
- package/driver/publish/xlsx.mjs +158 -139
- package/driver/record-goods.mjs +42 -0
- package/driver/reference-score.mjs +4 -1
- package/driver/register-count.mjs +5 -1
- package/driver/register-reach.mjs +39 -0
- package/driver/registry-fidelity.mjs +155 -37
- package/driver/repair-composers.mjs +7 -3
- package/driver/repair-targets.mjs +4 -1
- package/driver/replay-archive.mjs +4 -3
- package/driver/run-delivered.mjs +14 -8
- package/driver/run-record.mjs +1 -0
- package/driver/runner.mjs +73 -29
- package/driver/scope-facts.mjs +27 -6
- package/driver/search-policy.mjs +9 -4
- package/driver/skills/clearance-search/report-prose.md +3 -0
- package/driver/skills/knockout-assess/SKILL.md +8 -0
- package/driver/stage-freshness.mjs +8 -5
- package/driver/stages.mjs +69 -43
- package/driver/steps/delivery.mjs +9 -5
- package/driver/steps/overview-and-cards.mjs +54 -15
- package/driver/steps/register-sweep.mjs +5 -4
- package/driver/steps/skeptic-and-follow-up.mjs +3 -2
- package/driver/steps/verdict-gate.mjs +35 -14
- package/driver/suite-census.json +579 -87
- package/driver/synthesis-record.mjs +4 -3
- package/driver/terminal-clamp.mjs +6 -1
- package/driver/withdrawn-rating.mjs +72 -0
- package/mcp-server/CHANGELOG.md +8 -0
- package/mcp-server/lib/audit-view.mjs +5 -2
- package/mcp-server/lib/brief.mjs +6 -2
- package/mcp-server/lib/evidence.mjs +94 -23
- package/mcp-server/lib/findings.mjs +19 -2
- package/mcp-server/lib/knockout.mjs +13 -4
- package/mcp-server/lib/scrub.mjs +1 -1
- package/mcp-server/package.json +1 -1
- package/mcp-server/server.mjs +22 -3
- package/package.json +4 -1
- package/portal-ui/dist/assets/{index-CYaO2ygd.js → index-BBlN4CYq.js} +238 -80
- package/portal-ui/dist/assets/{index-izLa9apq.css → index-CxAkJXIT.css} +25 -5
- package/portal-ui/dist/index.html +2 -2
- package/portal-ui/package.json +3 -3
- package/providers/_shared/ledger.mjs +30 -2
- package/providers/_shared/record-uri.mjs +15 -0
- package/providers/clarivate/src/adapter.js +11 -0
- package/providers/clarivate/src/core.js +17 -1
- package/providers/jx/src/core.js +4 -4
- package/providers/jx/src/judge.js +1 -3
- package/providers/jx/src/nativeread.js +1 -3
- package/providers/oauth-mcp-bridge/CHANGELOG.md +8 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/scripts/README.md +147 -3
- package/scripts/added-reference-check.mjs +35 -7
- package/scripts/e2e-first-time.mjs +4 -4
- package/scripts/env-audit.mjs +16 -9
- package/scripts/freeze-example-run.mjs +3 -3
- package/scripts/mint-public-residue.mjs +3 -3
- package/scripts/mint-search-level-tags.mjs +61 -0
- package/scripts/mint-source-pin-census.mjs +89 -0
- package/scripts/release-note-required.mjs +65 -6
- package/scripts/test-durations-reporter.mjs +25 -0
- package/scripts/test-full.mjs +72 -18
- package/scripts/test-run.mjs +18 -1
- package/shared/brand.mjs +93 -6
- package/shared/inline-markdown.mjs +53 -0
- package/shared/names-in-force.mjs +0 -1
- package/shared/portal-tokens.mjs +2 -1
- package/shared/reference-guard-classes.mjs +43 -2
- package/shared/register-selection.mjs +8 -3
- package/shared/search-level-tags.json +25 -0
- package/shared/source-spans.mjs +91 -0
- package/shared/tools/derive-band-pairs.mjs +10 -0
- package/driver/own-rights.mjs +0 -83
- package/driver/use-check.mjs +0 -85
|
@@ -39,7 +39,7 @@ import { serve } from "./stdio-server.mjs";
|
|
|
39
39
|
import { recordSynthesis } from "../../synthesis-record.mjs"; // the writer
|
|
40
40
|
import { correctionPositionsFrom } from "./correction-positions.mjs"; // the positions a correction's dispatch hands its save
|
|
41
41
|
import { recordRegisterDigest } from "../../register-digest-record.mjs"; // conversion 11 — the findings document
|
|
42
|
-
import { FINDING_KEYS_CURRENT, COVERAGE_AREA_STATES } from "../../findings-model.mjs";
|
|
42
|
+
import { FINDING_KEYS_CURRENT, COVERAGE_AREA_STATES, KNOCKOUT_FINDING_KEYS } from "../../findings-model.mjs";
|
|
43
43
|
import { recordBlindFrame } from "../../blind-frame-record.mjs";
|
|
44
44
|
import { VARIANT_DIRECTIONS, RANKING_BASES } from "../../blind-frame-model.mjs";
|
|
45
45
|
import { recordSkeptic } from "../../skeptic-record.mjs";
|
|
@@ -275,6 +275,46 @@ async function search_run_artifacts(params) {
|
|
|
275
275
|
return searchRunArtifacts(runDir, params);
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
// ── THE KNOCKOUT FINDING, DECLARED FROM ITS KEY LIST ─────────────────────────────────────────────────────
|
|
279
|
+
//
|
|
280
|
+
// The two tools that carry a Knockout finding list its keys from `KNOCKOUT_FINDING_KEYS`, the list the
|
|
281
|
+
// recorder enforces, as `record_synthesis` lists the clearance's from its own ladder. Each tool keeps its own
|
|
282
|
+
// schema for a key, because the model reads each one's words and they are not the same words. A key on the
|
|
283
|
+
// list with no schema here is left out of what the tool lists, and the test that lists both tools names it.
|
|
284
|
+
const KNOCKOUT_ASSESS_FINDING_FIELDS = {
|
|
285
|
+
ordinal: { type: "integer", minimum: 1, description: "Unique within the mark, most blocking first. The code renumbers contiguously; yours breaks ties inside a band. Never cite a finding by number in prose." },
|
|
286
|
+
name: { type: "string", description: "The CONFLICTING name, verbatim." },
|
|
287
|
+
owner: { type: "string" },
|
|
288
|
+
band: { type: "string" },
|
|
289
|
+
// The framework's inputs behind the band, when the framework states a method: required on every finding
|
|
290
|
+
// then, refused otherwise (findings-model.mjs validateKnockoutFinding).
|
|
291
|
+
inputs: { type: "object", additionalProperties: { type: "string" }, description: "The framework's own inputs for this finding, keyed by its labels, each one of the values it lists." },
|
|
292
|
+
net: { type: "string", description: "One conclusion sentence." },
|
|
293
|
+
type: { type: "string" },
|
|
294
|
+
evidence: { type: "array", items: { type: "string" } },
|
|
295
|
+
basis: { type: "string", description: "The ground THIS FINDING's band rests on — not the mark's `basis`, which is a different field one level up." },
|
|
296
|
+
// The ninth key. This schema once said "all eight, no others" and forbade it while the recorder enforced
|
|
297
|
+
// nine, two closed sets that disagreed; listing the keys from the recorder's own list ends that.
|
|
298
|
+
weighedFilings: {
|
|
299
|
+
type: "array", items: { type: "string" },
|
|
300
|
+
description: "The register record ids whose evidence THIS finding's reasoning actually used, copied verbatim from the filings you were given. The report derives this finding's source labelling from it, and the driver joins every id against the run's own record store — so a Register label can never appear on a finding with no register evidence. Optional; omit it rather than guessing.",
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
const KNOCKOUT_CORRECTION_FINDING_FIELDS = {
|
|
304
|
+
ordinal: { type: "integer", description: "An existing finding's ordinal, or the next one for a new finding." },
|
|
305
|
+
name: { type: "string", description: "The conflicting name, verbatim." },
|
|
306
|
+
owner: { type: "string", description: "The party behind it, or \"not established on the searched material\"." },
|
|
307
|
+
band: { type: "string", description: "A word from the framework's ladder." },
|
|
308
|
+
inputs: { type: "object", description: "The framework's own inputs for this finding, where it states a method." },
|
|
309
|
+
net: { type: "string", description: "One conclusion sentence." },
|
|
310
|
+
type: { type: "string", description: "Famous Brand, Active Business, Cultural Reference, Domain, Descriptive Use, Negative Association or Competitor Intelligence." },
|
|
311
|
+
evidence: { type: "array", items: { type: "string" }, description: "URLs held for this name." },
|
|
312
|
+
basis: { type: "string", description: "The ground the band rests on." },
|
|
313
|
+
weighedFilings: { type: "array", items: { type: "string" }, description: "The register record ids this finding's reasoning used." },
|
|
314
|
+
};
|
|
315
|
+
const knockoutFindingProperties = (fields) =>
|
|
316
|
+
Object.fromEntries(KNOCKOUT_FINDING_KEYS.filter((k) => k in fields).map((k) => [k, fields[k]]));
|
|
317
|
+
|
|
278
318
|
serve({
|
|
279
319
|
name: "recording",
|
|
280
320
|
tools: [{
|
|
@@ -1332,27 +1372,7 @@ serve({
|
|
|
1332
1372
|
items: {
|
|
1333
1373
|
type: "object", additionalProperties: false,
|
|
1334
1374
|
required: ["ordinal", "name"],
|
|
1335
|
-
properties:
|
|
1336
|
-
ordinal: { type: "integer", minimum: 1, description: "Unique within the mark, most blocking first. The code renumbers contiguously; yours breaks ties inside a band. Never cite a finding by number in prose." },
|
|
1337
|
-
name: { type: "string", description: "The CONFLICTING name, verbatim." },
|
|
1338
|
-
owner: { type: "string" },
|
|
1339
|
-
band: { type: "string" },
|
|
1340
|
-
// The framework's inputs behind the band, when the framework states a method: required on
|
|
1341
|
-
// every finding then, refused otherwise (findings-model.mjs validateKnockoutFinding).
|
|
1342
|
-
inputs: { type: "object", additionalProperties: { type: "string" }, description: "The framework's own inputs for this finding, keyed by its labels, each one of the values it lists." },
|
|
1343
|
-
net: { type: "string", description: "One conclusion sentence." },
|
|
1344
|
-
type: { type: "string" },
|
|
1345
|
-
evidence: { type: "array", items: { type: "string" } },
|
|
1346
|
-
basis: { type: "string", description: "The ground THIS FINDING's band rests on — not the mark's `basis`, which is a different field one level up." },
|
|
1347
|
-
// — the ninth key, and the count above moved with it. The
|
|
1348
|
-
// recorder's own DECLARED list has carried this field since
|
|
1349
|
-
// while this object said eight and forbade it, so "all eight, no others" was a
|
|
1350
|
-
// closed set that disagreed with the closed set actually enforced.
|
|
1351
|
-
weighedFilings: {
|
|
1352
|
-
type: "array", items: { type: "string" },
|
|
1353
|
-
description: "The register record ids whose evidence THIS finding's reasoning actually used, copied verbatim from the filings you were given. The report derives this finding's source labelling from it, and the driver joins every id against the run's own record store — so a Register label can never appear on a finding with no register evidence. Optional; omit it rather than guessing.",
|
|
1354
|
-
},
|
|
1355
|
-
},
|
|
1375
|
+
properties: knockoutFindingProperties(KNOCKOUT_ASSESS_FINDING_FIELDS),
|
|
1356
1376
|
},
|
|
1357
1377
|
},
|
|
1358
1378
|
},
|
|
@@ -1493,18 +1513,9 @@ serve({
|
|
|
1493
1513
|
findings: {
|
|
1494
1514
|
type: "array",
|
|
1495
1515
|
description: "Only the findings you change or add, each whole.",
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
owner: { type: "string", description: "The party behind it, or \"not established on the searched material\"." },
|
|
1500
|
-
band: { type: "string", description: "A word from the framework's ladder." },
|
|
1501
|
-
inputs: { type: "object", description: "The framework's own inputs for this finding, where it states a method." },
|
|
1502
|
-
net: { type: "string", description: "One conclusion sentence." },
|
|
1503
|
-
type: { type: "string", description: "Famous Brand, Active Business, Cultural Reference, Domain, Descriptive Use, Negative Association or Competitor Intelligence." },
|
|
1504
|
-
evidence: { type: "array", items: { type: "string" }, description: "URLs held for this name." },
|
|
1505
|
-
basis: { type: "string", description: "The ground the band rests on." },
|
|
1506
|
-
weighedFilings: { type: "array", items: { type: "string" }, description: "The register record ids this finding's reasoning used." },
|
|
1507
|
-
} },
|
|
1516
|
+
// The `required` list is kept as data: `inputs` and `weighedFilings` stay optional here, and no
|
|
1517
|
+
// `additionalProperties: false`, because either change would alter what the model may send.
|
|
1518
|
+
items: { type: "object", required: ["ordinal", "name", "owner", "band", "net", "type", "evidence", "basis"], properties: knockoutFindingProperties(KNOCKOUT_CORRECTION_FINDING_FIELDS) },
|
|
1508
1519
|
},
|
|
1509
1520
|
remove_findings: { type: "array", items: { type: "integer" }, description: "Ordinals the evidence shows should not be there." },
|
|
1510
1521
|
},
|
|
@@ -28,7 +28,7 @@ import { newSessionRecord, noteCodexEvent, sessionSummary, countTool, streamSink
|
|
|
28
28
|
import { writeSecretFile } from "../../shared/secret-file.mjs"; // the rotated login goes back the way every credential is written
|
|
29
29
|
import { tmpdir, homedir } from "node:os";
|
|
30
30
|
import { join, dirname, sep } from "node:path";
|
|
31
|
-
import { runStreamingChild, absolutizeSkillRefs, WRITE_DISCIPLINE, buildEnvelope, resolveSpawnCwd } from "./common.mjs";
|
|
31
|
+
import { runStreamingChild, absolutizeSkillRefs, WRITE_DISCIPLINE, buildEnvelope, resolveSpawnCwd, isRecordTool } from "./common.mjs";
|
|
32
32
|
import { renderCodexConfigToml } from "./mcp/codex-config.mjs";
|
|
33
33
|
import { resolveAuthMode } from "./auth.mjs";
|
|
34
34
|
import { engineEnv, codexCommandWithheld } from "./engine-env.mjs";
|
|
@@ -438,8 +438,10 @@ export function buildCodexArgs({ model, thinking, resumeRef, runDir } = {}) {
|
|
|
438
438
|
return { args: [...base, "-"] };
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
// Fold ONE codex --json line into the running event accumulator.
|
|
442
|
-
|
|
441
|
+
// Fold ONE codex --json line into the running event accumulator. `atMs` is when the line arrived, in ms from the
|
|
442
|
+
// spawn; given, it times the turn (see codexTiming), and a line that is not JSON still counts as the child speaking.
|
|
443
|
+
export function parseCodexEvent(line, ev, atMs = null) {
|
|
444
|
+
if (Number.isFinite(atMs)) ev.firstLineAtMs ??= atMs;
|
|
443
445
|
let e; try { e = JSON.parse(line); } catch { return; }
|
|
444
446
|
// MODEL GAUGE ( corruption 3) — OPPORTUNISTIC on the stream, and its answer here is "nothing".
|
|
445
447
|
//
|
|
@@ -475,6 +477,7 @@ export function parseCodexEvent(line, ev) {
|
|
|
475
477
|
}
|
|
476
478
|
noteMcpToolCall(e.item, ev);
|
|
477
479
|
noteToolItem(e.item, ev);
|
|
480
|
+
noteToolTiming(e.type, e.item, ev, atMs);
|
|
478
481
|
break;
|
|
479
482
|
// ── — AN MCP CALL THAT WAS REFUSED IS NOT A CALL NOBODY MADE ──────────
|
|
480
483
|
//
|
|
@@ -498,6 +501,7 @@ export function parseCodexEvent(line, ev) {
|
|
|
498
501
|
case "item.started":
|
|
499
502
|
noteMcpToolCall(e.item, ev);
|
|
500
503
|
noteToolItem(e.item, ev);
|
|
504
|
+
noteToolTiming(e.type, e.item, ev, atMs);
|
|
501
505
|
break;
|
|
502
506
|
default: break;
|
|
503
507
|
}
|
|
@@ -533,12 +537,72 @@ const TOOL_ITEM_KINDS = new Set(["command_execution", "file_change", "web_search
|
|
|
533
537
|
*/
|
|
534
538
|
export function noteToolItem(item, ev) {
|
|
535
539
|
if (!item?.id) return;
|
|
536
|
-
const name = item
|
|
537
|
-
: TOOL_ITEM_KINDS.has(item.type) ? item.type : null;
|
|
540
|
+
const name = toolItemName(item);
|
|
538
541
|
if (!name) return;
|
|
539
542
|
(ev.toolItems ??= new Map()).set(item.id, name);
|
|
540
543
|
}
|
|
541
544
|
|
|
545
|
+
/** A tool-shaped item's name, as the per-name count and the wait split key it; null for anything else. */
|
|
546
|
+
const toolItemName = (item) => (item?.type === "mcp_tool_call" ? `mcp__${item.server ?? "?"}__${item.tool ?? "?"}`
|
|
547
|
+
: TOOL_ITEM_KINDS.has(item?.type) ? item.type : null);
|
|
548
|
+
|
|
549
|
+
// ── WHERE A CODEX TURN'S TIME WENT, ON THE ANTHROPIC ENGINE'S TERMS ─────────────────────────────────────────
|
|
550
|
+
//
|
|
551
|
+
// Codex attempts carried no start-up, tool-wait or active time, so a Codex turn's time could not be split between
|
|
552
|
+
// the engine starting, the model working and its tools running, and its stall window could not be set from any
|
|
553
|
+
// record. Its stream already says when each tool item opens (`item.started`) and closes (`item.completed`); what it
|
|
554
|
+
// lacked was the time each line arrived. Every line is now read with its arrival in ms from the spawn, and the
|
|
555
|
+
// fields mean what they mean on the Anthropic engine (anthropic-agent.mjs, the settled timing):
|
|
556
|
+
// - `firstByteMs`: spawn to the child's first line, null when it never spoke;
|
|
557
|
+
// - `toolWaitMs`: time with at least one tool item open, so two concurrent items count their overlap once, and an
|
|
558
|
+
// item still open when the turn ended counts up to the end;
|
|
559
|
+
// - `toolWaitByTool`: each resolved item's own open time under its name, which can sum past `toolWaitMs` for the
|
|
560
|
+
// same reason as on the Anthropic engine (concurrent items), and leaves out an item that never resolved;
|
|
561
|
+
// - `activeMs`: the wall less `toolWaitMs`, so the two tile the wall.
|
|
562
|
+
// The items counted as tool wait are the kinds this file counts as tool calls: MCP calls, shell commands, file
|
|
563
|
+
// changes and web searches; the Anthropic engine counts every tool it asks for, which covers the same kinds.
|
|
564
|
+
// RECORDING ONLY: nothing in the kill clocks, walls or retries reads these.
|
|
565
|
+
export function noteToolTiming(type, item, ev, atMs) {
|
|
566
|
+
if (!Number.isFinite(atMs) || !item?.id) return;
|
|
567
|
+
const name = toolItemName(item);
|
|
568
|
+
if (!name) return;
|
|
569
|
+
const t = (ev.toolTiming ??= { open: new Map(), since: null, waitMs: 0, byTool: Object.create(null) });
|
|
570
|
+
if (type === "item.started") {
|
|
571
|
+
if (t.open.has(item.id)) return;
|
|
572
|
+
// The last tool asked for, apart from the stage's own record write, and the last record write (see codexTiming).
|
|
573
|
+
if (isRecordTool(name)) ev.lastRecordAskMs = atMs; else ev.lastWorkAskMs = atMs;
|
|
574
|
+
if (t.open.size === 0) t.since = atMs;
|
|
575
|
+
t.open.set(item.id, atMs);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
if (type !== "item.completed") return;
|
|
579
|
+
const opened = t.open.get(item.id);
|
|
580
|
+
// An item that arrives already complete was never seen open: it is a call, with no wait anybody could time.
|
|
581
|
+
t.byTool[name] = (t.byTool[name] ?? 0) + (opened == null ? 0 : Math.max(0, atMs - opened));
|
|
582
|
+
if (opened == null) return;
|
|
583
|
+
t.open.delete(item.id);
|
|
584
|
+
if (t.open.size === 0) { t.waitMs += Math.max(0, atMs - t.since); t.since = null; }
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* The settled timing of a turn `wallMs` long (see above). An accumulator that was never timed reports null for each
|
|
589
|
+
* field: this engine could not measure, which is not "no wait". PURE.
|
|
590
|
+
*/
|
|
591
|
+
export function codexTiming(ev, wallMs) {
|
|
592
|
+
if (!ev?.timed || !Number.isFinite(wallMs)) return { firstByteMs: null, toolWaitMs: null, activeMs: null, toolWaitByTool: null, lastToolAsk: null };
|
|
593
|
+
const t = ev.toolTiming;
|
|
594
|
+
const open = t?.open.size ? Math.max(0, wallMs - t.since) : 0;
|
|
595
|
+
const toolWaitMs = Math.min(Math.round(wallMs), Math.round((t?.waitMs ?? 0) + open));
|
|
596
|
+
return {
|
|
597
|
+
firstByteMs: Number.isFinite(ev.firstLineAtMs) ? Math.round(ev.firstLineAtMs) : null,
|
|
598
|
+
toolWaitMs, activeMs: Math.max(0, Math.round(wallMs) - toolWaitMs),
|
|
599
|
+
toolWaitByTool: Object.fromEntries(Object.entries(t?.byTool ?? {}).map(([k, v]) => [k, Math.round(v)])),
|
|
600
|
+
// ms from spawn to the last tool item opened that was not the stage's own record write, and to the last that was, as the
|
|
601
|
+
// Anthropic engine reports them; the gateway reads them to choose how a hard-wall kill is retried.
|
|
602
|
+
lastToolAsk: { workMs: Number.isFinite(ev.lastWorkAskMs) ? Math.round(ev.lastWorkAskMs) : null, recordMs: Number.isFinite(ev.lastRecordAskMs) ? Math.round(ev.lastRecordAskMs) : null },
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
542
606
|
/**
|
|
543
607
|
* The turn's tool calls by name, in the shape anthropic-agent records: an MCP call under
|
|
544
608
|
* `mcp__<server>__<tool>`, and codex's own tool items under its own word for them. Counted once per item
|
|
@@ -863,6 +927,8 @@ function settleTuple({ r, ev, resumeRef }) {
|
|
|
863
927
|
// through (session-record.mjs: every turn ending and stream error, in order), and the raw stream.
|
|
864
928
|
toolCallsByName: codexToolCallsByName(ev), toolCallsErroredByName: codexToolServerErrors(ev),
|
|
865
929
|
session: sessionSummary(ev.session), stream: ev.stream ?? null,
|
|
930
|
+
// Start-up, tool wait and active time, as the Anthropic engine reports them (codexTiming).
|
|
931
|
+
...codexTiming(ev, r.wall * 1000),
|
|
866
932
|
writesFailed: ev.writesFailed ?? 0,
|
|
867
933
|
commandsFailed: ev.commandsFailed ?? 0,
|
|
868
934
|
commandFailures: ev.commandFailures ?? [],
|
|
@@ -992,8 +1058,9 @@ export const openaiAgentEngine = {
|
|
|
992
1058
|
// Stamped HERE, not at function entry: everything above is file writes that can take a moment, and
|
|
993
1059
|
// a floor set too early would let a previous turn's rollout back in on a shared home.
|
|
994
1060
|
const spawnedAtMs = Date.now();
|
|
1061
|
+
// `timed`: this turn's lines are read with their arrival times, so its timing fields are measurements.
|
|
995
1062
|
const ev = { threadId: null, usage: null, agentText: "", turnCompleted: false, turnFailed: null, streamError: null, model: null, mcpCalls: new Map(),
|
|
996
|
-
session: newSessionRecord() };
|
|
1063
|
+
session: newSessionRecord(), timed: true };
|
|
997
1064
|
// The raw stream, one file per session beside its dispatch; every line codex wrote on stdout.
|
|
998
1065
|
const sink = streamSink(streamFile);
|
|
999
1066
|
const r = await runStreamingChild({
|
|
@@ -1004,7 +1071,7 @@ export const openaiAgentEngine = {
|
|
|
1004
1071
|
env, stallSec, timeoutSec,
|
|
1005
1072
|
onStdoutLine: (line) => {
|
|
1006
1073
|
sink.write(`${line}\n`);
|
|
1007
|
-
parseCodexEvent(line, ev);
|
|
1074
|
+
parseCodexEvent(line, ev, Date.now() - spawnedAtMs);
|
|
1008
1075
|
let e; try { e = JSON.parse(line); } catch { return; }
|
|
1009
1076
|
noteCodexEvent(ev.session, e, Date.now() - t0);
|
|
1010
1077
|
},
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
// said in plain words that the session had expired. On a healthy ending that field is the model's answer
|
|
40
40
|
// and stays off the row.
|
|
41
41
|
|
|
42
|
-
import { mkdirSync, openSync, writeSync, closeSync, statfsSync } from "node:fs";
|
|
42
|
+
import { mkdirSync, openSync, writeSync, closeSync, readSync, statfsSync, existsSync, readFileSync, writeFileSync, unlinkSync, statSync } from "node:fs";
|
|
43
43
|
import { dirname } from "node:path";
|
|
44
|
+
import { gzipSync, gunzipSync } from "node:zlib";
|
|
44
45
|
|
|
45
46
|
/** The program's words for a classifier cut, as it writes them into the session. Matched, never quoted. */
|
|
46
47
|
export const CLASSIFIER_CUT_RE = /stopped by a safety classifier/i;
|
|
@@ -203,6 +204,32 @@ export function countTool(byName, name) {
|
|
|
203
204
|
// name it took, so every row names the bytes of its own session.
|
|
204
205
|
export const STREAM_FLOOR_BYTES = 5 * 1024 ** 3;
|
|
205
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Each line of a saved stream, as bytes, whether it was kept gzipped (a session that closed) or plain (one that never
|
|
209
|
+
* did). The one reader of the format, beside the one writer. A plain stream is read a megabyte at a time, so a long one is
|
|
210
|
+
* never held whole; a gzipped one is held whole once decompressed, at most the size the session wrote.
|
|
211
|
+
*/
|
|
212
|
+
export function* streamLines(file) {
|
|
213
|
+
if (String(file).endsWith(".gz")) {
|
|
214
|
+
const text = gunzipSync(readFileSync(file));
|
|
215
|
+
let at = 0;
|
|
216
|
+
for (let nl; (nl = text.indexOf(10, at)) >= 0; at = nl + 1) yield text.subarray(at, nl);
|
|
217
|
+
if (at < text.length) yield text.subarray(at);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const fd = openSync(file, "r");
|
|
221
|
+
try {
|
|
222
|
+
const chunk = Buffer.alloc(1 << 20);
|
|
223
|
+
let rest = Buffer.alloc(0);
|
|
224
|
+
for (let n; (n = readSync(fd, chunk, 0, chunk.length, null)) > 0;) {
|
|
225
|
+
let buf = Buffer.concat([rest, chunk.subarray(0, n)]), at;
|
|
226
|
+
while ((at = buf.indexOf(10)) >= 0) { yield buf.subarray(0, at); buf = buf.subarray(at + 1); }
|
|
227
|
+
rest = Buffer.from(buf);
|
|
228
|
+
}
|
|
229
|
+
if (rest.length) yield rest;
|
|
230
|
+
} finally { closeSync(fd); }
|
|
231
|
+
}
|
|
232
|
+
|
|
206
233
|
/** `<stem>.jsonl` for the first session under a name, `<stem>.session<n>.jsonl` for each later one. */
|
|
207
234
|
const nthStreamName = (file, n) => (n === 1 ? file : file.replace(/(\.jsonl)?$/, (ext) => `.session${n}${ext}`));
|
|
208
235
|
|
|
@@ -222,6 +249,9 @@ export function streamSink(file, { floorBytes = STREAM_FLOOR_BYTES, freeBytes =
|
|
|
222
249
|
// "wx" creates or refuses, in one step, so two sessions can never both take one name.
|
|
223
250
|
for (let n = 1; fd === null; n += 1) {
|
|
224
251
|
const name = nthStreamName(file, n);
|
|
252
|
+
// A closed session's stream is kept gzipped under `<name>.gz`, so the plain name is free again once it closes: a
|
|
253
|
+
// name is taken when either is there.
|
|
254
|
+
if (existsSync(`${name}.gz`)) continue;
|
|
225
255
|
try { fd = openSync(name, "wx", 0o600); file = name; }
|
|
226
256
|
catch (e) { if (e?.code !== "EEXIST" || n >= 999) throw e; }
|
|
227
257
|
}
|
|
@@ -235,7 +265,19 @@ export function streamSink(file, { floorBytes = STREAM_FLOOR_BYTES, freeBytes =
|
|
|
235
265
|
},
|
|
236
266
|
close() {
|
|
237
267
|
if (fd !== null) { try { closeSync(fd); } catch { /* the bytes are on disk or they are not; bytes says which */ } fd = null; }
|
|
238
|
-
|
|
268
|
+
if (reason) return { file, present: bytes > 0, bytes, reason };
|
|
269
|
+
// A SESSION THAT CLOSED IS KEPT GZIPPED. One long session wrote 28 to 41 MB as plain lines, and the archive keeps every
|
|
270
|
+
// run's streams. Compressed here, once the session has closed: a session that is killed never reaches this, so its
|
|
271
|
+
// stream stays plain and readable to its last line, which is the stream someone most wants to read. A compression that
|
|
272
|
+
// fails keeps the plain file and says so; it never fails the turn.
|
|
273
|
+
try {
|
|
274
|
+
const gz = `${file}.gz`;
|
|
275
|
+
writeFileSync(gz, gzipSync(readFileSync(file)), { mode: 0o600, flag: "wx" });
|
|
276
|
+
unlinkSync(file);
|
|
277
|
+
return { file: gz, present: true, bytes, storedBytes: statSync(gz).size };
|
|
278
|
+
} catch (e) {
|
|
279
|
+
return { file, present: true, bytes, notCompressed: String(e?.message ?? e).slice(0, 120) };
|
|
280
|
+
}
|
|
239
281
|
},
|
|
240
282
|
};
|
|
241
283
|
}
|
|
@@ -115,6 +115,12 @@ export const FINDINGS_SCHEMA_VERSION = 7;
|
|
|
115
115
|
// and re-saves, the file is re-validated, and the model would have to author a legal read for a card it
|
|
116
116
|
// is deleting. See issue comment 2026-08-03.
|
|
117
117
|
export const POSITION_REQUIRED_DISPOSITIONS = ["adversarial", "coexistence-partner", "distinguished", "off-field"];
|
|
118
|
+
// A WITHDRAWN RATING IS NOT A REJECTED FINDING. The review can withdraw a finding whose right still stands, because the
|
|
119
|
+
// rating it carried cannot be supported: its goods wording could not be used. `withdrawn` alone took that right off the
|
|
120
|
+
// page with the rejected ones. `rating_withdrawn_ground` says which case it is and why: present, the right stands
|
|
121
|
+
// unrated for that reason and the report lists it as left open; absent, the review rejected the finding, as before.
|
|
122
|
+
// Valid only beside `disposition: "withdrawn"`, so every card, total and summary keeps leaving it out.
|
|
123
|
+
export const RATING_WITHDRAWN_GROUNDS = ["goods-wording-unavailable"];
|
|
118
124
|
// requirement 2 — off-field's TWO sanctioned grounds, made to declare themselves.
|
|
119
125
|
//
|
|
120
126
|
// `off-field` had been carrying two different claims under one token: "the same token in a different
|
|
@@ -702,8 +708,9 @@ const FINDING_KEYS_V4 = ["ordinal", "mark", "owner", "band", "borderline_between
|
|
|
702
708
|
// this negative rests on (see OFF_FIELD_GROUNDS). Required on off-field, forbidden everywhere else — a
|
|
703
709
|
// field ground on a rated conflict is a mis-typed disposition, not extra colour.
|
|
704
710
|
const FINDING_KEYS_V6 = [...FINDING_KEYS_V4, "off_field_ground"];
|
|
705
|
-
// (v7) —
|
|
706
|
-
|
|
711
|
+
// (v7) — the change is to `net`'s permitted CONTENT, not the shape. One OPTIONAL key joined it later, back-compatible
|
|
712
|
+
// like `ruled_out` before it: `rating_withdrawn_ground` (see RATING_WITHDRAWN_GROUNDS). No archived document carries it.
|
|
713
|
+
const FINDING_KEYS_V7 = [...FINDING_KEYS_V6, "rating_withdrawn_ground"];
|
|
707
714
|
// which dispositions carry a band on v4: a rated conflict needs one; off-field IS the unrated
|
|
708
715
|
// commercial-awareness home ("a conflict the entity clearly wins with no material risk is not a rated
|
|
709
716
|
// conflict" — doc 50); withdrawn tolerates a stale band (forensic record, renders nowhere).
|
|
@@ -855,6 +862,7 @@ const onlyKeys = (obj, allowed, tokenFor) => {
|
|
|
855
862
|
* | finding_deadline_invalid:<ordinal> | finding_deadline_key_unknown:<key> | finding_deadline_date_missing:<ordinal>
|
|
856
863
|
* | findings_context_note_invalid | findings_context_note_key_unknown:<key> | findings_context_note_type_invalid:<v>
|
|
857
864
|
* | findings_net_chained:<ordinal> (v7 only — PLURAL on purpose; see validateNetShape)
|
|
865
|
+
* | finding_rating_withdrawn_ground_invalid:<v> | finding_rating_withdrawn_ground_orphan:<ordinal>
|
|
858
866
|
* (the composite>=3 NON-EMPTY-source gate for use_check/own_rights is raised by the caller in verify.mjs —
|
|
859
867
|
* this parser only enforces SHAPE: object / key-allowlist / source-is-a-string. Both fields are OPTIONAL.)
|
|
860
868
|
*
|
|
@@ -1415,6 +1423,10 @@ function validateFinding(f, idx, seenOrdinals, mode = { v4: false, manifest: nul
|
|
|
1415
1423
|
throw new Error(`finding_withdrawn_reason_missing:${ord} (a withdrawn finding must carry withdrawn_reason — the review flag that killed it)`);
|
|
1416
1424
|
if (f.withdrawn_reason != null && f.disposition !== "withdrawn")
|
|
1417
1425
|
throw new Error(`finding_withdrawn_reason_orphan:${ord} (withdrawn_reason is only valid when disposition is "withdrawn")`);
|
|
1426
|
+
if (f.rating_withdrawn_ground != null && !RATING_WITHDRAWN_GROUNDS.includes(f.rating_withdrawn_ground))
|
|
1427
|
+
throw new Error(`finding_rating_withdrawn_ground_invalid:${short(f.rating_withdrawn_ground)} (rating_withdrawn_ground, when present, must be one of: ${RATING_WITHDRAWN_GROUNDS.join(", ")})`);
|
|
1428
|
+
if (f.rating_withdrawn_ground != null && f.disposition !== "withdrawn")
|
|
1429
|
+
throw new Error(`finding_rating_withdrawn_ground_orphan:${ord} (rating_withdrawn_ground is only valid when disposition is "withdrawn")`);
|
|
1418
1430
|
|
|
1419
1431
|
validateOwner(f.owner, ord, mode?.recordOrigins ?? null, mode?.foreignLinks ?? null);
|
|
1420
1432
|
validateMeters(f.meters);
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
// follow-up-twins.mjs — when a written coverage row with an axis label stands in for the driver's Follow-up row.
|
|
4
|
+
//
|
|
5
|
+
// "Left open" listed one unfinished search twice: once as the writer's row ("Register / …") and once as the row the
|
|
6
|
+
// driver composes for a deferred directive ("Follow-up / …"). An axis-labelled row was never allowed to stand in,
|
|
7
|
+
// because word containment alone had erased two genuinely different open searches on a delivered page. The rule
|
|
8
|
+
// now rests on the search the run RECORDED for the deferred directive (design, 2026-11-19): the frame receipt
|
|
9
|
+
// (`_driver/frame-reopen.json`) keeps, per directive, the plan questions minted for it, and each question's id names
|
|
10
|
+
// its search kind (`supp:primary-sweep:exact:…`).
|
|
11
|
+
//
|
|
12
|
+
// A WRITTEN ROW STANDS IN ONLY WHEN ALL OF THIS HOLDS, and the Follow-up stays otherwise:
|
|
13
|
+
// - the directive's recorded questions name exactly one kind of search; none recorded, as on every older run and
|
|
14
|
+
// on every common-law directive, or several kinds, keeps the Follow-up;
|
|
15
|
+
// - the written row is open, carries an axis label whose head is that kind's spelling (its own key, its reader
|
|
16
|
+
// label, and "register" for the main register search), and carries every significant word of the directive;
|
|
17
|
+
// - no other open row fits equally well.
|
|
18
|
+
// A completed row never stands in. The driver composing the rows, the lint reading the page and the page itself all
|
|
19
|
+
// ask this one function, so the three cannot disagree. The free-text arm each of them already has is unchanged.
|
|
20
|
+
import { readFileSync } from "node:fs";
|
|
21
|
+
import { AXIS_READER_LABEL } from "./coverage-ledger.mjs";
|
|
22
|
+
import { plainDirective } from "./deferral-row.mjs";
|
|
23
|
+
import { paths } from "./run-record.mjs";
|
|
24
|
+
|
|
25
|
+
const STOPWORDS = new Set(["the", "a", "an", "as", "for", "of", "in", "on", "and", "or", "to", "is",
|
|
26
|
+
"was", "it", "its", "this", "that", "with", "by", "at", "be", "been", "run", "search", "searched"]);
|
|
27
|
+
/** The significant words of a text, as the page's Follow-up test reads them. PURE. */
|
|
28
|
+
export const significantWords = (t) => new Set(String(t || "").toLowerCase().match(/[a-z0-9]+/g)?.filter((w) => !STOPWORDS.has(w)) ?? []);
|
|
29
|
+
|
|
30
|
+
const keyOf = (directive) => plainDirective(directive).toLowerCase().replace(/\s+/g, " ").trim();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The search kinds the run recorded for each deferred directive, keyed by the directive as a Follow-up row prints it
|
|
34
|
+
* (its plain form, lower case). A kind is a question id's second segment. A directive with no recorded question has
|
|
35
|
+
* no entry. PURE.
|
|
36
|
+
*/
|
|
37
|
+
export function followUpKinds(receipt) {
|
|
38
|
+
const out = new Map();
|
|
39
|
+
const qids = receipt?.directive_qids && typeof receipt.directive_qids === "object" ? receipt.directive_qids : {};
|
|
40
|
+
for (const d of Array.isArray(receipt?.deferrals) ? receipt.deferrals : []) {
|
|
41
|
+
const directive = typeof d?.directive === "string" ? d.directive : "";
|
|
42
|
+
const ids = Array.isArray(qids[directive]) ? qids[directive].filter((q) => typeof q === "string") : [];
|
|
43
|
+
const segments = ids.map((q) => q.split(":")[1]);
|
|
44
|
+
// Every recorded question must name its kind: one that does not leaves the record incomplete, and nothing folds.
|
|
45
|
+
if (directive && ids.length && segments.every(Boolean)) out.set(keyOf(directive), new Set(segments));
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The kinds recorded for the directive a Follow-up row prints, or null. The directive is its note's opening clause. PURE. */
|
|
51
|
+
export function kindsForFollowUp(row, kinds) {
|
|
52
|
+
if (!(kinds instanceof Map) || !kinds.size) return null;
|
|
53
|
+
return kinds.get(keyOf(String(row?.note ?? "").split("—")[0])) ?? null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const headOf = (area) => {
|
|
57
|
+
const a = String(area ?? "");
|
|
58
|
+
const cut = a.indexOf(" / ");
|
|
59
|
+
return cut < 0 ? null : a.slice(0, cut).trim().toLowerCase();
|
|
60
|
+
};
|
|
61
|
+
const spells = (head, kind) => head === kind || head === AXIS_READER_LABEL[kind] || (kind === "primary-sweep" && head === "register");
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The one written row that stands in for a Follow-up row whose directive is `directive` and whose recorded kinds are
|
|
65
|
+
* `kinds`, or null when none does. `written` is every row that is not a Follow-up row. PURE.
|
|
66
|
+
*/
|
|
67
|
+
export function axisTwin(directive, kinds, written) {
|
|
68
|
+
if (!(kinds instanceof Set) || kinds.size !== 1) return null;
|
|
69
|
+
const [kind] = kinds;
|
|
70
|
+
const want = significantWords(directive);
|
|
71
|
+
if (!want.size) return null;
|
|
72
|
+
const fits = (Array.isArray(written) ? written : []).filter((w) => {
|
|
73
|
+
if (!w || w.state === "confirmed-clean") return false;
|
|
74
|
+
const head = headOf(w.area);
|
|
75
|
+
if (!head || !spells(head, kind)) return false;
|
|
76
|
+
const theirs = significantWords(w.area);
|
|
77
|
+
return [...want].every((word) => theirs.has(word));
|
|
78
|
+
});
|
|
79
|
+
return fits.length === 1 ? fits[0] : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The recorded kinds of a run's deferred directives, read from its frame receipt; empty when the run has none. IMPURE. */
|
|
83
|
+
export function followUpKindsOf(runDir) {
|
|
84
|
+
if (!runDir) return new Map();
|
|
85
|
+
try { return followUpKinds(JSON.parse(readFileSync(paths(runDir).frameReopenReceipt, "utf8"))); } catch { return new Map(); }
|
|
86
|
+
}
|