clearotron 0.5.1 → 0.6.0-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/.env.example +7 -7
- package/INSTALL.md +10 -10
- package/QUICKSTART.md +6 -6
- package/README.md +2 -2
- package/THIRD-PARTY-NOTICES.md +4 -4
- package/bin/README.md +2 -2
- package/bin/clearotron.mjs +1 -1
- package/bin/connect.mjs +1 -1
- package/bin/disconnect.mjs +1 -1
- package/bin/example.mjs +2 -2
- package/bin/grant.mjs +1 -1
- package/bin/onboard.mjs +78 -23
- package/bin/start.mjs +49 -18
- package/bin/update.mjs +13 -3
- package/build-info.json +2 -2
- package/docs/DELIVERY.md +1 -1
- package/docs/PORTAL.md +1 -1
- package/docs/RELEASES.md +1 -1
- package/docs/architecture/02-architecture.md +10 -2
- package/docs/architecture/03-run-lifecycle.md +6 -2
- package/docs/architecture/04-configuration-reference.md +3 -3
- package/docs/architecture/05-config-governance.md +5 -4
- package/docs/architecture/08-development-guide.md +4 -4
- package/docs/architecture/09-security-and-data.md +1 -1
- package/{driver/skills/clearance-search/SKILL.md → docs/architecture/retired-manuals/clearance-search-spine.md} +17 -30
- package/{driver/skills/clearance-search/templates/email/generic.md → docs/architecture/retired-manuals/email-generic.md} +1 -1
- package/{driver/skills/clearance-search → docs/architecture/retired-manuals}/template-formatting.md +3 -4
- package/docs/configuration.md +1 -1
- package/docs/decisions/0002-no-dark-functionality.md +5 -0
- package/driver/CHANGELOG.md +60 -0
- package/driver/README.md +11 -1
- package/driver/accepted-order.mjs +13 -5
- package/driver/attempt-rows.mjs +64 -0
- package/driver/attributed-span.mjs +1 -1
- package/driver/authority-trees.mjs +1 -1
- package/driver/best-draft.mjs +3 -3
- package/driver/blind-frame-record.mjs +2 -2
- package/driver/cancel.mjs +3 -2
- package/driver/carry-through.mjs +2 -2
- package/driver/citation-census.json +3 -3
- package/driver/clearance-variants-record.mjs +4 -10
- package/driver/common-law-coverage-status.mjs +3 -3
- package/driver/common-law-receipts.mjs +2 -2
- package/driver/compare.mjs +1 -1
- package/driver/config-inventory.mjs +6 -79
- package/driver/consumption-ledger.mjs +2 -1
- package/driver/contract-dictation-registry.mjs +5 -0
- package/driver/contract-e3-backlog.mjs +45 -66
- package/driver/contract-e3-baseline.json +16 -16
- package/driver/contract-vocabulary.mjs +8 -6
- package/driver/corrections-feedforward.mjs +3 -1
- package/driver/coverage-form-io.mjs +7 -8
- package/driver/coverage-tool.mjs +1 -1
- package/driver/declination-tool.mjs +2 -2
- package/driver/degraded-parts.mjs +9 -9
- package/driver/demo-container.mjs +5 -4
- package/driver/deploy-live-run-guard.mjs +19 -7
- package/driver/derived-state.mjs +2 -2
- package/driver/dev-portal.mjs +2 -1
- package/driver/dispatch-record.mjs +1 -1
- package/driver/disposition-tool.mjs +2 -1
- package/driver/doubt-closure-tool.mjs +2 -2
- package/driver/driver.config.mjs +35 -724
- package/driver/e2e-rounds.mjs +3 -4
- package/driver/engine/CONTRACT.md +3 -0
- package/driver/engine/README.md +2 -0
- package/driver/engine/anthropic-agent.mjs +8 -37
- package/driver/engine/auth.mjs +74 -0
- package/driver/engine/child-record.mjs +1 -1
- package/driver/engine/deny-authority-write.mjs +2 -2
- package/driver/engine/jx-turn.mjs +10 -2
- package/driver/engine/mcp/README.md +1 -1
- package/driver/engine/mcp/band-server.mjs +6 -6
- package/driver/engine/mcp/codex-config.mjs +1 -1
- package/driver/engine/mcp/declination-server.mjs +2 -3
- package/driver/engine/mcp/dispositions-server.mjs +3 -3
- package/driver/engine/mcp/gather-config.mjs +24 -19
- package/driver/engine/mcp/grid-provenance.mjs +1 -1
- package/driver/engine/mcp/held-answers.mjs +5 -5
- package/driver/engine/mcp/perplexity-server.mjs +16 -7
- package/driver/engine/mcp/recording-server.mjs +7 -6
- package/driver/engine/mcp/register-server.mjs +29 -0
- package/driver/engine/mcp/stdio-server.mjs +5 -5
- package/driver/engine/mcp/supplemental.mjs +9 -9
- package/driver/engine/openai-agent.mjs +5 -2
- package/driver/engine/registry.mjs +103 -0
- package/driver/engine/run-choices.mjs +162 -0
- package/driver/engine/stamps.mjs +35 -0
- package/driver/enqueue-schema.mjs +4 -4
- package/driver/envelope-settle.mjs +3 -2
- package/driver/feedback-issues.mjs +1 -1
- package/driver/feedback-mint.mjs +3 -2
- package/driver/feedback-store.mjs +3 -2
- package/driver/findings-model.mjs +1 -1
- package/driver/flag-snapshot.mjs +5 -4
- package/driver/floor-duty.mjs +3 -3
- package/driver/foreign-record-links.mjs +1 -1
- package/driver/frame-diff-record.mjs +2 -8
- package/driver/framework.mjs +1 -1
- package/driver/gate-metrics.mjs +10 -11
- package/driver/gateway.mjs +220 -839
- package/driver/goods-evidence.mjs +10 -6
- package/driver/jx-lanes.mjs +3 -3
- package/driver/jx-units.mjs +31 -37
- package/driver/jx.mjs +44 -59
- package/driver/knockout-assess-record.mjs +3 -3
- package/driver/knockout-caveats.mjs +21 -0
- package/driver/knockout-correction-record.mjs +58 -28
- package/driver/knockout-frame-record.mjs +2 -2
- package/driver/knockout-register-read.mjs +38 -21
- package/driver/knockout-register-record.mjs +5 -6
- package/driver/knockout-review-record.mjs +12 -11
- package/driver/ladder/model-gauge.mjs +88 -0
- package/driver/ladder/next-rung.mjs +296 -0
- package/driver/ladder/rescue.mjs +146 -0
- package/driver/ladder/stage-tools.mjs +57 -0
- package/driver/ladder/turn-failure.mjs +166 -0
- package/driver/log.mjs +2 -2
- package/driver/matter-frame-record.mjs +4 -4
- package/driver/methodology-witness.mjs +2 -2
- package/driver/narrative-refutation-record.mjs +145 -42
- package/driver/one-build-per-run.mjs +62 -0
- package/driver/outbox-backoff.mjs +4 -4
- package/driver/owner-screen.mjs +0 -10
- package/driver/owner-use-check.mjs +2 -28
- package/driver/package.json +1 -1
- package/driver/partial-payload-baseline.json +1 -1
- package/driver/parts-not-completed.mjs +1 -1
- package/driver/pipeline-knockout.mjs +1015 -1001
- package/driver/pipeline.mjs +511 -9265
- package/driver/placement-decisions.mjs +2 -2
- package/driver/placement-form-io.mjs +7 -9
- package/driver/placement-union.mjs +0 -6
- package/driver/plan-stability.mjs +7 -10
- package/driver/portal-acks.mjs +3 -2
- package/driver/portal-confirmation.mjs +48 -0
- package/driver/portal-families.mjs +3 -2
- package/driver/portal-local-auth.mjs +1 -2
- package/driver/portal-routes/README.md +24 -0
- package/driver/portal-routes/admin.mjs +425 -0
- package/driver/portal-routes/compose.mjs +66 -0
- package/driver/portal-routes/config.mjs +118 -0
- package/driver/portal-routes/connect.mjs +283 -0
- package/driver/portal-routes/feedback.mjs +178 -0
- package/driver/portal-routes/me.mjs +165 -0
- package/driver/portal-routes/queue.mjs +64 -0
- package/driver/portal-routes/report.mjs +106 -0
- package/driver/portal-routes/run.mjs +508 -0
- package/driver/portal-routes/runs.mjs +127 -0
- package/driver/portal-routes/usage.mjs +82 -0
- package/driver/portal-runs.mjs +588 -0
- package/driver/portal-service.mjs +78 -2592
- package/driver/portal-static.mjs +3 -1
- package/driver/predelivery-lint.mjs +92 -9
- package/driver/production-pool-guard.mjs +1 -1
- package/driver/profiles.mjs +5 -4
- package/driver/progress.mjs +29 -24
- package/driver/publish/README.md +10 -5
- package/driver/publish/archive-tags.mjs +3 -2
- package/driver/publish/demo-marking.mjs +2 -2
- package/driver/publish/index.mjs +215 -140
- package/driver/publish/knockout.mjs +153 -107
- package/driver/publish/office-record-links.mjs +22 -0
- package/driver/publish/parse.mjs +20 -5
- package/driver/publish/pool-admin.mjs +9 -3
- package/driver/publish/render.mjs +11 -3
- package/driver/publish/report-dates.mjs +3 -4
- package/driver/publish/report-registry.mjs +7 -10
- package/driver/publish/seed-pool.mjs +3 -2
- package/driver/publish/shell.mjs +106 -0
- package/driver/publish/templates/report.css +3 -1
- package/driver/queue-order.mjs +4 -3
- package/driver/record-carry.mjs +0 -9
- package/driver/record-discard.mjs +1 -4
- package/driver/record-fold.mjs +3 -3
- package/driver/record-goods.mjs +5 -5
- package/driver/reference-score.mjs +2 -3
- package/driver/register-capabilities.mjs +0 -6
- package/driver/register-count.mjs +3 -2
- package/driver/register-digest-record.mjs +7 -7
- package/driver/register-fixture-marker.mjs +3 -3
- package/driver/register-plan.mjs +2 -2
- package/driver/register-records.mjs +2 -2
- package/driver/register-taint.mjs +3 -3
- package/driver/register-unit-record.mjs +48 -9
- package/driver/register-unreachable.mjs +4 -3
- package/driver/registry-fidelity.mjs +79 -34
- package/driver/repair-composers.mjs +14 -9
- package/driver/repair-digest.mjs +4 -6
- package/driver/repair-scope.mjs +3 -3
- package/driver/repair-targets.mjs +24 -9
- package/driver/repairs.mjs +44 -58
- package/driver/replay-archive.mjs +7 -7
- package/driver/report-card-record.mjs +3 -3
- package/driver/report-overview-record.mjs +4 -4
- package/driver/research-answers.mjs +38 -6
- package/driver/research-checks.mjs +4 -4
- package/driver/result-noun-fields.mjs +28 -11
- package/driver/review-addresses.mjs +163 -0
- package/driver/rule-shape.mjs +1 -1
- package/driver/run-delivered.mjs +340 -0
- package/driver/run-economics.mjs +8 -26
- package/driver/run-failed.mjs +545 -0
- package/driver/run-integrity.mjs +1 -1
- package/driver/run-outcome.mjs +314 -0
- package/driver/run-park.mjs +23 -0
- package/driver/run-quote.mjs +32 -0
- package/driver/run-record.mjs +352 -0
- package/driver/run-requirements.mjs +22 -0
- package/driver/run-shell.mjs +55 -0
- package/driver/runner.mjs +71 -33
- package/driver/saved-register-pages.mjs +4 -4
- package/driver/score-redaction.mjs +2 -2
- package/driver/search-policy.mjs +12 -13
- package/driver/settle-stamp.mjs +4 -3
- package/driver/skeptic-record.mjs +2 -2
- package/driver/skeptic-search.mjs +1 -1
- package/driver/skills/README.md +7 -7
- package/driver/skills/blind-frame/SKILL.md +1 -2
- package/driver/skills/case-law-citation/SKILL.md +9 -37
- package/driver/skills/case-law-citation/sources/courtlistener.md +1 -3
- package/driver/skills/case-law-citation/sources/eurlex.md +8 -11
- package/driver/skills/case-law-citation/sources/legaldatahunter.md +1 -1
- package/driver/skills/clearance-common-law/SKILL.md +45 -111
- package/driver/skills/clearance-common-law/perplexity-prompts.md +7 -79
- package/driver/skills/clearance-register/SKILL.md +15 -33
- package/driver/skills/clearance-register/digest.md +31 -92
- package/driver/skills/clearance-register/providers/clarivate.md +2 -2
- package/driver/skills/clearance-register/providers/corsearch.md +5 -5
- package/driver/skills/clearance-register/providers/euipo.md +1 -2
- package/driver/skills/clearance-register/providers/free-tier.md +0 -19
- package/driver/skills/clearance-register/providers/signa.md +6 -25
- package/driver/skills/clearance-register/providers/uspto-local.md +0 -24
- package/driver/skills/clearance-register/register-recipes.md +8 -15
- package/driver/skills/clearance-register/status-rules.md +6 -24
- package/driver/skills/clearance-register/unit.md +11 -20
- package/driver/skills/clearance-search/delivery-contract.md +24 -120
- package/driver/skills/clearance-search/field-doctrine-pharma.md +1 -5
- package/driver/skills/clearance-search/firm-wide-reasoning.md +24 -43
- package/driver/skills/clearance-search/phase2-execution.md +29 -77
- package/driver/skills/clearance-search/report-prose.md +3 -4
- package/driver/skills/clearance-search/risk-framework-demo.md +1 -1
- package/driver/skills/clearance-search/risk-framework-triage.manifest.json +3 -3
- package/driver/skills/clearance-search/risk-framework-triage.md +7 -9
- package/driver/skills/clearance-search/risk-framework.manifest.json +1 -1
- package/driver/skills/clearance-search/risk-framework.md +1 -1
- package/driver/skills/clearance-search/synthesis-rules.md +30 -107
- package/driver/skills/clearance-search/worked-examples.md +5 -5
- package/driver/skills/clearance-variants/SKILL.md +46 -45
- package/driver/skills/clearance-variants/transliteration-scripts.md +4 -4
- package/driver/skills/frame-diff/SKILL.md +1 -1
- package/driver/skills/knockout-assess/SKILL.md +6 -14
- package/driver/skills/knockout-frame/SKILL.md +1 -1
- package/driver/skills/matter-frame/SKILL.md +7 -12
- package/driver/skills/matter-frame/watchlist-reference.md +1 -4
- package/driver/skills/narrative-refutation/SKILL.md +20 -30
- package/driver/skills/placement-inquiry/SKILL.md +8 -18
- package/driver/skills-store-provenance.mjs +1 -1
- package/driver/stage-context.mjs +32 -35
- package/driver/stage-freshness.mjs +127 -11
- package/driver/stages-knockout.mjs +49 -22
- package/driver/stages.mjs +88 -283
- package/driver/status-snapshot.mjs +2 -1
- package/driver/steps/correction-cycle.mjs +311 -0
- package/driver/steps/corrections.mjs +644 -0
- package/driver/steps/delivery.mjs +1287 -0
- package/driver/steps/frame-comparison.mjs +922 -0
- package/driver/steps/intake.mjs +84 -0
- package/driver/steps/open-run.mjs +419 -0
- package/driver/steps/overview-and-cards.mjs +899 -0
- package/driver/steps/placement-and-digest.mjs +23 -0
- package/driver/steps/register-sweep.mjs +1563 -0
- package/driver/steps/skeptic-and-follow-up.mjs +831 -0
- package/driver/steps/synthesis.mjs +261 -0
- package/driver/steps/verdict-gate.mjs +968 -0
- package/driver/suite-census.json +403 -91
- package/driver/surface-exit-verdict.mjs +0 -8
- package/driver/synthesis-record.mjs +72 -6
- package/driver/terminal-clamp.mjs +10 -0
- package/driver/tokens.mjs +8 -62
- package/driver/tool-calls.mjs +2 -2
- package/driver/unit-state-verdict.mjs +1 -1
- package/driver/usage-ledger.mjs +2 -1
- package/driver/verify-knockout.mjs +20 -35
- package/driver/verify.mjs +47 -36
- package/driver/web-grid.mjs +3 -4
- package/driver/whatif-memo-run.mjs +2 -2
- package/driver/whatif-queue.mjs +4 -3
- package/driver/withheld-families.mjs +14 -15
- package/driver/worker-heartbeat.mjs +3 -2
- package/driver/write-up-form.mjs +0 -3
- package/mcp-server/CHANGELOG.md +4 -0
- package/mcp-server/http-server.mjs +1 -1
- package/mcp-server/lib/brief.mjs +22 -4
- package/mcp-server/lib/events.mjs +2 -2
- package/mcp-server/lib/evidence.mjs +3 -2
- package/mcp-server/lib/findings.mjs +2 -1
- package/mcp-server/lib/knockout.mjs +9 -10
- package/mcp-server/lib/ops.mjs +9 -9
- package/mcp-server/lib/runs.mjs +9 -10
- package/mcp-server/lib/trace.mjs +1 -1
- package/mcp-server/lib/whatif.mjs +2 -3
- package/mcp-server/package.json +1 -1
- package/mcp-server/server.mjs +5 -5
- package/package.json +2 -1
- package/portal-ui/dist/assets/{index-fPqAU0sx.js → index-D5rkCjDc.js} +26 -14
- package/portal-ui/dist/index.html +1 -1
- package/portal-ui/package.json +3 -3
- package/providers/README.md +1 -1
- package/providers/_shared/answer-memory.mjs +4 -5
- package/providers/_shared/execute-plan.mjs +48 -1
- package/providers/_shared/records-from-search.mjs +46 -0
- package/providers/clarivate/README.md +2 -2
- package/providers/clarivate/src/adapter.js +147 -0
- package/providers/clarivate/src/core.js +1 -14
- package/{driver/engine/mcp/clarivate-server.mjs → providers/clarivate/src/mount.js} +5 -10
- package/providers/corsearch/README.md +3 -3
- package/providers/corsearch/src/adapter.js +80 -0
- package/providers/corsearch/src/core.js +14 -11
- package/{driver/engine/mcp/corsearch-server.mjs → providers/corsearch/src/mount.js} +5 -10
- package/providers/euipo/README.md +2 -2
- package/providers/euipo/src/adapter.js +85 -0
- package/providers/euipo/src/core.js +1 -1
- package/providers/euipo/src/euipo-client.js +1 -2
- package/{driver/engine/mcp/euipo-server.mjs → providers/euipo/src/mount.js} +5 -10
- package/providers/free-tier/README.md +2 -2
- package/providers/free-tier/src/adapter.js +127 -0
- package/{driver/engine/mcp/free-tier-server.mjs → providers/free-tier/src/mount.js} +5 -10
- package/providers/jx-subclass/coverage.mjs +1 -6
- package/providers/jx-subclass/score-truth.mjs +2 -1
- package/providers/oauth-mcp-bridge/CHANGELOG.md +4 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/providers/perplexity/src/core.js +2 -2
- package/providers/signa/README.md +2 -2
- package/providers/signa/src/adapter.js +157 -0
- package/providers/signa/src/capabilities.js +0 -3
- package/providers/signa/src/core.js +2 -2
- package/{driver/engine/mcp/signa-server.mjs → providers/signa/src/mount.js} +7 -12
- package/providers/signa/src/offices.generated.js +17 -15
- package/providers/uspto-local/README.md +1 -1
- package/providers/uspto-local/bin/verify-index.mjs +1 -1
- package/providers/uspto-local/src/adapter.js +75 -0
- package/{driver/engine/mcp/uspto-local-server.mjs → providers/uspto-local/src/mount.js} +5 -10
- package/scripts/band-shape-probe.mjs +2 -2
- package/scripts/citation-line-check.mjs +7 -7
- package/scripts/compare.mjs +1 -1
- package/scripts/dead-names.mjs +2 -2
- package/scripts/e2e-first-time.mjs +19 -7
- package/scripts/e2e.mjs +13 -13
- package/scripts/engine-probe.mjs +1 -1
- package/scripts/env-audit.mjs +7 -4
- package/scripts/env-classify.mjs +5 -1
- package/scripts/feedback-mint.mjs +1 -1
- package/scripts/freeze-example-run.mjs +7 -7
- package/scripts/mint-suite-census.mjs +2 -2
- package/scripts/nightly-notice.mjs +1 -1
- package/scripts/release-cut-decision.mjs +7 -2
- package/scripts/release-note-required.mjs +26 -9
- package/scripts/release-notes-lint.mjs +3 -2
- package/scripts/release-version-pr-checks.mjs +1 -1
- package/scripts/settings-render-check.mjs +23 -3
- package/scripts/test-run.mjs +5 -5
- package/scripts/travelling-predicates.mjs +1 -1
- package/scripts/undeclared-field-census.mjs +1 -1
- package/scripts/unexecuted-asserts.mjs +1 -1
- package/scripts/verify-publishable.mjs +1 -1
- package/shared/client-door.mjs +1 -1
- package/shared/connect-clients.mjs +1 -1
- package/shared/connector-signin-probe.mjs +1 -1
- package/shared/env-aliases.mjs +1 -1
- package/shared/invocation.mjs +14 -2
- package/shared/names-in-force.mjs +2 -0
- package/shared/register-selection.mjs +2 -2
- package/shared/store-in-repo.mjs +3 -3
- package/shared/summary-blocks.mjs +0 -3
- package/shared/trigger-lane.mjs +1 -1
- package/shared/vacuous-pass.mjs +2 -2
- package/shared/verb-shim.mjs +4 -2
- package/node_modules/exceljs/README.md +0 -3023
|
@@ -0,0 +1,831 @@
|
|
|
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
|
+
// steps/skeptic-and-follow-up.mjs — the skeptic, and the searches and rechecks its flags and the floors raise.
|
|
5
|
+
//
|
|
6
|
+
// One phase of a run, moved out of pipelineInner unchanged. `helpers` are functions still held in pipeline.mjs, handed in
|
|
7
|
+
// because this module must not import that one back; each moves here when the other phases that share it have moved.
|
|
8
|
+
import { runRecordLogPath } from "../../providers/_shared/ledger-path.mjs";
|
|
9
|
+
import { heldForNothingToSend, splitDeferredByCloseability } from "../coverage-ledger.mjs";
|
|
10
|
+
import { CROWD_CONTEXT_AXIS, buildCrowdContext } from "../crowd-context.mjs";
|
|
11
|
+
import { pendingItems, runPostFlushGateRepair } from "../digest-queue.mjs";
|
|
12
|
+
import { config } from "../driver.config.mjs";
|
|
13
|
+
import { note, outputMeta, runLog } from "../log.mjs";
|
|
14
|
+
import { atomicWrite, readJson } from "../run-record.mjs";
|
|
15
|
+
import { fullyDeferredAxes, undoneSearchesNote } from "../register-plan.mjs";
|
|
16
|
+
import { registerCapabilities } from "../register-unreachable.mjs";
|
|
17
|
+
import { assembleRunRecords, recordBodyHasContent } from "../registry-fidelity.mjs";
|
|
18
|
+
import { repairFollowup } from "../repair-composers.mjs";
|
|
19
|
+
import { findScreenGateParseGaps, findScreenGateViolations, screenGateZeroCause } from "../screen-gate.mjs";
|
|
20
|
+
import { escalatedAxes } from "../skeptic-record.mjs";
|
|
21
|
+
import { STAGES, lines } from "../stages.mjs";
|
|
22
|
+
import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
23
|
+
|
|
24
|
+
export async function runSkepticAndFollowUp({ P, agent, axes, ctx, dispatchPlanQids, flushDigestQueue, job, mintDigestWork, opts, planExec, run, unitKey }, helpers) {
|
|
25
|
+
const { askableOf, bandBytesOf, capabilityGapAxes, defaultRecordFetcher, deriveBandShape, deriveNamedBand, envelopeDecision, envelopeHeldNote, escalationHeldNote, findFloorBreaches, forceFromActive, isInactiveAxisRow, lateRecordIds, loadCoverageLedger, officeGapOf, readFloorAxes, readPlanExecution, recordPlacementPass, recordScreenGateEvidence, refreshSupplementalExecution, remergeIfBandsMoved, runBatched, screenGateSnapshot, settleOneShotStamp, skepticDeferralExtra, stage, stickyGapUnits } = helpers;
|
|
26
|
+
// Step 2.6 skeptic → code-decided escalation. The skeptic poses its flags as a QUESTION back to each
|
|
27
|
+
// flagged unit, which RESUMES its own session (warm cache, same model) and defends-or-adjusts in place —
|
|
28
|
+
// it does NOT redo the search from scratch on a fresh opus session. This is both cheaper (a follow-up turn
|
|
29
|
+
// on the cached thread vs. a cold full opus re-run — the old path's dominant cost) and better (the unit
|
|
30
|
+
// argues from the evidence it already gathered). Opus judgment still happens once, at the re-digest.
|
|
31
|
+
// B1: the skeptic is a fresh-eyes audit that can only ADD escalations — its absence == the (common)
|
|
32
|
+
// clean-skeptic path. A gemini-flash outage must NOT bin the completed gather+digest, so it is NON-FATAL:
|
|
33
|
+
// on failure we proceed with no escalation. (Coverage/judgment stages stay fatal; this is the one exception.)
|
|
34
|
+
const skepticData = skepticDeferralExtra(ctx);
|
|
35
|
+
const sk = await stage("skeptic", ctx, skepticData ? { extra: skepticData } : {});
|
|
36
|
+
let flags = "";
|
|
37
|
+
if (sk.ok) {
|
|
38
|
+
flags = readFileSync(P.skepticFlags, "utf8");
|
|
39
|
+
} else {
|
|
40
|
+
note(`skeptic failed (non-fatal — proceeding with no escalation): ${sk.fail}`);
|
|
41
|
+
runLog(run.runDir, { event: "skeptic-skipped", reason: sk.fail });
|
|
42
|
+
}
|
|
43
|
+
// Which axes to re-run is decided by STRUCTURED tokens the skeptic emits — one `ESCALATE: <axis>` line per
|
|
44
|
+
// axis with a material unresolved gap — NOT by substring-matching its prose (which both false-triggered on
|
|
45
|
+
// incidental mentions and missed gaps phrased without the axis name). `flags` (the full prose) is still
|
|
46
|
+
// passed into the follow-ups as context. No flags (clean OR skipped) ⇒ no escalation.
|
|
47
|
+
//
|
|
48
|
+
// The parse itself MOVED to skeptic-record.mjs (same regex, one function): the record_skeptic
|
|
49
|
+
// transport renders the ESCALATE lines and re-reads them through the same `escalatedAxes` this
|
|
50
|
+
// dispatch runs, so the rendered shape and this read cannot drift — the dictated-shape-with-a-
|
|
51
|
+
// forgotten-reparser seam, closed by having exactly one parser.
|
|
52
|
+
const escalate = escalatedAxes(flags, axes);
|
|
53
|
+
// D3 — the escalation-risk SHADOW loop (risk-tag parse + would-skip telemetry for the
|
|
54
|
+
// never-enabled CLEAROTRON_ESCALATION_FILTER) is DELETED; every ESCALATE line still re-runs its axis.
|
|
55
|
+
// Audit-trail-aware escalation skip (Lever 4). A skeptic flag against an axis whose coverage-ledger
|
|
56
|
+
// row(s) are ALL `coverage-limited` is a DOCUMENTED/ACCEPTED structural limit (a crowd recorded with its
|
|
57
|
+
// count) — a warm re-run cannot close it; it
|
|
58
|
+
// would only re-spend the fat gather context (the ~343K cold-write) + a 2nd Opus re-digest for no recall
|
|
59
|
+
// gain, so we skip it. CONSERVATIVE predicate: skip ONLY when the axis owns ≥1 ledger row AND every owned
|
|
60
|
+
// row is `coverage-limited` (a `deferred` row = real outstanding work → re-run closes it; a `confirmed-clean`
|
|
61
|
+
// row still flagged = a fresh-eyes catch the ledger calls clean → escalate). An axis with no parseable
|
|
62
|
+
// ledger row is never skipped. Escalating needlessly only wastes money; skipping a real gap loses recall —
|
|
63
|
+
// when in doubt, escalate. (Ungated build; A/B to ship — assert only documented-accepted gaps are skipped.)
|
|
64
|
+
const ledger = loadCoverageLedger(run.runDir).rows; // WS-A: machine ledger when present, else prose
|
|
65
|
+
// A2 — the capability-gap inputs the skip below decides on, read once (same authority-then-prose
|
|
66
|
+
// ordering as the envelope: the receipt indicts an axis, the row reason splits inside it).
|
|
67
|
+
const escalationReceipt = readPlanExecution(ctx);
|
|
68
|
+
const escalationGapAxes = capabilityGapAxes(ctx.registerPlan, escalationReceipt);
|
|
69
|
+
// — the floor axes this mark designated, and the axes whose floor work was excused rather than
|
|
70
|
+
// executed. Read once, beside the other inputs the skip decides on, in the same authority ordering.
|
|
71
|
+
const floorBreachAxes = new Set(findFloorBreaches(ledger, readFloorAxes(P)).map((b) => b.axis));
|
|
72
|
+
const escalationFullyDeferred = new Set((ctx.registerPlan ? fullyDeferredAxes(ctx.registerPlan) : []).map((a) => String(a.axis).toLowerCase()));
|
|
73
|
+
const codeSideEscalations = []; // A6 — code-side axes a skeptic flag landed on; they get a deterministic recheck below, never a silent skip
|
|
74
|
+
const escalateGated = escalate.filter((a) => {
|
|
75
|
+
// a code-side / resumed-past unit has NO session to warm-resume (unitKey null) — and for
|
|
76
|
+
// saturation-probe there is nothing to defend anyway: the band is a code-executed count table.
|
|
77
|
+
if (a === "saturation-probe" && !unitKey[a]) {
|
|
78
|
+
note(`escalation skipped ${a} — code-executed axis, no unit session to resume (counts are mechanical) — deterministic recheck follows`);
|
|
79
|
+
runLog(run.runDir, { event: "escalation-skipped", axis: a, reason: "code-side unit (no session)" });
|
|
80
|
+
codeSideEscalations.push(a);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const owned = ledger.filter((r) => r.axis === a.toLowerCase());
|
|
84
|
+
// — THE FLOOR TERM IS ON BOTH SKIP BRANCHES, AND ON THIS ONE THAT IS AN EXTENSION rather than
|
|
85
|
+
// a restoration. Stated plainly because it is the one place this PR goes past what removed:
|
|
86
|
+
// the retired `!floorBreachAxes.has(a)` sat on the capability-gap branch below and only there.
|
|
87
|
+
//
|
|
88
|
+
// Leaving this branch unheld would be internally incoherent. An axis whose rows are ALL
|
|
89
|
+
// `coverage-limited` is the PUREST case of the loophole — everything excused, nothing executed — and
|
|
90
|
+
// `computeOpenFloors` already discloses it as an unmet floor. So the run would state an open floor on
|
|
91
|
+
// the delivered report and, in the same breath, have decided not to pursue it: flagged and not
|
|
92
|
+
// pursued, which is half the ruling and the confusing half.
|
|
93
|
+
//
|
|
94
|
+
// It also follows this gate's own doctrine, written above: "Escalating needlessly only wastes money;
|
|
95
|
+
// skipping a real gap loses recall — when in doubt, escalate."
|
|
96
|
+
if (owned.length > 0 && owned.every((r) => r.status === "coverage-limited") && !floorBreachAxes.has(a.toLowerCase())) {
|
|
97
|
+
note(`escalation skipped ${a} — coverage ledger documents an accepted limit (no closeable gap)`);
|
|
98
|
+
runLog(run.runDir, { event: "escalation-skipped", axis: a, reason: "documented coverage-limit" });
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
// A2 — the code gate behind the prompt line: an axis whose ONLY outstanding work is a
|
|
102
|
+
// capability-gap deferral has nothing a warm re-run can reach. The skeptic escalated exactly
|
|
103
|
+
// this on the evidence run (it re-derived the ledger out of a 103 KB prose document and got it
|
|
104
|
+
// wrong), and the re-run then re-derived the provider's deterministic refusal at full price.
|
|
105
|
+
// Same conservative shape as the coverage-limited skip: the receipt must indict the axis AND
|
|
106
|
+
// every outstanding row must state the gap.
|
|
107
|
+
//
|
|
108
|
+
// ⚠ THE HOLD, and this is the one site where the search floor changes what the pipeline DOES rather
|
|
109
|
+
// than what it reports. retired the ⭐ mechanism and this condition WIDENED as a consequence —
|
|
110
|
+
// the old `&& !floorBreachAxes.has(a)` term PREVENTED the skip, so dropping it made an axis whose
|
|
111
|
+
// only outstanding work is a capability-gap deferral skippable even where floor work had been
|
|
112
|
+
// excused rather than executed. restores the term against the typed designation.
|
|
113
|
+
//
|
|
114
|
+
// The direction is the point: a floor breach does not force a re-run, it withholds a SKIP. An axis
|
|
115
|
+
// that could not be fully checked is never quietly closed — it stays flagged and pursued. And with
|
|
116
|
+
// no designation `floorBreachAxes` is empty, so this reads exactly as it does today on every run
|
|
117
|
+
// that designates no floor.
|
|
118
|
+
if (owned.length > 0 && !floorBreachAxes.has(a.toLowerCase())) {
|
|
119
|
+
const split = splitDeferredByCloseability(ledger, a, escalationGapAxes,
|
|
120
|
+
{ fullyDeferred: escalationFullyDeferred.has(a.toLowerCase()), heldUnits: stickyGapUnits(P), uncovered: officeGapOf(ctx.registerPlan), askable: askableOf(escalationReceipt) });
|
|
121
|
+
const openNonDeferred = owned.some((r) => r.status !== "deferred" && r.status !== "coverage-limited");
|
|
122
|
+
if (split.held.length > 0 && split.closeable.length === 0 && !openNonDeferred) {
|
|
123
|
+
// Held only because none of its rows has a question left to send is not a capability gap, and says so.
|
|
124
|
+
const nothingToSend = heldForNothingToSend(split);
|
|
125
|
+
note(nothingToSend
|
|
126
|
+
? `escalation skipped ${a} — no question is left to send, so a re-run cannot close it (the gap stays open and disclosed)`
|
|
127
|
+
: `escalation skipped ${a} — capability-gap deferral: the active register provider cannot express those slices, so a re-run re-derives the same refusal (the gap stays open and disclosed)`);
|
|
128
|
+
runLog(run.runDir, { event: "escalation-skipped", axis: a,
|
|
129
|
+
reason: nothingToSend ? "no question left to send (nothing a re-run can close)" : "capability-gap deferral (nothing a re-run can close)" });
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
});
|
|
135
|
+
// Escalation is a PRE-synthesis digest refinement (re-run the flagged axis → re-digest). Once synthesis has
|
|
136
|
+
// produced narrative.md, the digest it consumed is locked in — so on a RESUME past synthesis we must NOT
|
|
137
|
+
// re-fire it: a cold-session re-run would re-spend Corsearch and could rewrite register-findings.md, which
|
|
138
|
+
// would corrupt the audit spine the deliverable is built from. V4-1: the lock is "will synthesis run for
|
|
139
|
+
// THIS delivery" — an inherited narrative.md that --from synthesis is about to force-re-run does NOT lock
|
|
140
|
+
// (the stale-proxy bug: forks never closed closable digest work).
|
|
141
|
+
const digestLocked = existsSync(P.narrative) && !forceFromActive(ctx, "synthesis");
|
|
142
|
+
// ── A6 (hardening 8, 2026-07-28 postmortem): a skeptic flag on a CODE-SIDE axis used to END at the skip
|
|
143
|
+
// event — no deterministic re-run, no recorded ending (it fired 2× on the 2026-07-28 postmortem run, silently). The
|
|
144
|
+
// axis is fully dictated, so the honest cheap answer IS code: re-dispatch its frozen plan qids ONCE
|
|
145
|
+
// through the deterministic executor (count probes — seconds, no session, no agent turn). A band
|
|
146
|
+
// that comes back changed makes the digest stale w.r.t. its declared inputs, so stage-staleness
|
|
147
|
+
// forces the re-digest deterministically — no new trigger is invented here. With no dispatch lane
|
|
148
|
+
// (no executor adapter / no frozen plan / repair budget spent) the skip is recorded
|
|
149
|
+
// judged-immaterial WITH its reason, so the escalation has an ending either way. Runs under the
|
|
150
|
+
// same digest lock as the warm escalation arm: past synthesis, a band mutation belongs to the
|
|
151
|
+
// frame-reopen/digest-queue lanes, not here.
|
|
152
|
+
for (const a of codeSideEscalations) {
|
|
153
|
+
if (digestLocked) {
|
|
154
|
+
runLog(run.runDir, { event: "escalation-recheck", axis: a, dispatched: false, reason: "digest-locked (post-synthesis) — a band mutation here would bypass the digest lock" });
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (!planExec || !ctx.registerPlan) {
|
|
158
|
+
runLog(run.runDir, { event: "escalation-recheck", axis: a, dispatched: false, reason: "judged-immaterial: no deterministic dispatch lane (no executor/frozen plan) — the gathered counts stand" });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const bandBefore = (() => { try { return readFileSync(P.registerBand(a), "utf8"); } catch { return null; } })();
|
|
162
|
+
const outcome = await dispatchPlanQids(a, null, "escalation-recheck", 1);
|
|
163
|
+
const bandAfter = (() => { try { return readFileSync(P.registerBand(a), "utf8"); } catch { return null; } })();
|
|
164
|
+
const bandChanged = outcome === "ok" && bandAfter != null && bandBefore !== bandAfter;
|
|
165
|
+
runLog(run.runDir, { event: "escalation-recheck", axis: a, dispatched: outcome != null, outcome: outcome ?? "repair-budget-exhausted", bandChanged });
|
|
166
|
+
if (bandChanged) {
|
|
167
|
+
try { deriveNamedBand(ctx); } catch (err) { note(`escalation-recheck ${a}: band re-merge failed (${String(err?.message ?? err).slice(0, 100)}) — the digest will re-merge on its own pass`); }
|
|
168
|
+
// The changed counts must REACH the digest THIS pass, not by ambush at delivery: minting digest
|
|
169
|
+
// work rides the same pre-synthesis settlement flush as the warm escalation lane above. Leaving
|
|
170
|
+
// it to the delivery-freshness gate alone (register-digest is on staleOnPath) means synthesis
|
|
171
|
+
// and the cards get built from the PRE-recheck digest, delivery blocks as stale, and the run
|
|
172
|
+
// pays a park + a full back-half recompute — the exact re-drive cascade the funnel
|
|
173
|
+
// exists to prevent — for what one flush section reconciles in-pass.
|
|
174
|
+
mintDigestWork("escalation-recheck", [a], lines(
|
|
175
|
+
`A skeptic flag on the code-executed ${a} axis triggered a deterministic recheck: its frozen plan queries were re-dispatched and the fresh counts CHANGED the crowd band. Re-read that axis's updated unit file and count band, reconcile your prior findings against the fresh counts, and revise only what the changed band requires.`,
|
|
176
|
+
));
|
|
177
|
+
note(`escalation-recheck ${a}: fresh dispatch changed the band — re-digest queued for the settlement flush`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (escalateGated.length && !digestLocked) {
|
|
181
|
+
// Fix 3: re-run flagged axes CONCURRENTLY (was a sequential await-per-axis loop, ~19 min → ~6 min),
|
|
182
|
+
// reusing the gather pass's runBatched fan-out at config.gatherConcurrency (≤ gateway maxConcurrent —
|
|
183
|
+
// proven by the first gather pass). Each axis is independent: it resumes its OWN session key
|
|
184
|
+
// (unitKey[a]) and writes its OWN unit file, so there is no shared mutable state — the only join is the
|
|
185
|
+
// escalated[] collection, which stays deterministic because runBatched writes results by index.
|
|
186
|
+
const escResults = await runBatched(escalateGated, config.gatherConcurrency, async (a) => {
|
|
187
|
+
// WS4: snapshot the unit file BEFORE the escalated re-run. A warm "defend-in-place" that re-emits a
|
|
188
|
+
// byte-identical file leaves the digest's inputs unchanged, so re-firing the Opus re-digest for it is
|
|
189
|
+
// provably wasted spend (the re-digest's own followup says "re-read only those updated unit files").
|
|
190
|
+
// Only axes whose unit file MATERIALLY changed stay in escalated[]; content-compare is conservative —
|
|
191
|
+
// any byte difference re-fires, so a genuine recall fix is never skipped. Floor-neutral.
|
|
192
|
+
const beforeUnit = existsSync(P.registerUnit(a)) ? readFileSync(P.registerUnit(a), "utf8") : null;
|
|
193
|
+
const beforeBand = bandBytesOf(P, a); // a narrow sub-query adds blocks to the band, whatever it does to the notes
|
|
194
|
+
note(`skeptic escalated ${a} → resuming its session to defend/adjust (warm, same tier)`);
|
|
195
|
+
let followup = repairFollowup("register-unit:escalation", { paths: P, axis: a, flags,
|
|
196
|
+
supplementalLane: !!ctx.registerPlan?.contract?.supplemental_lane, job: ctx.job, profile: ctx.profile });
|
|
197
|
+
// A2, per-row: the skip above only catches an axis whose ENTIRE outstanding work is held (a
|
|
198
|
+
// capability gap, or nothing left to send). An axis is often escalated for a good reason (a flagged confirmed-clean row)
|
|
199
|
+
// while ALSO carrying held rows — and the resumed unit must not be left to think those are
|
|
200
|
+
// work it failed to do. Name them, exactly as the envelope's close followup does.
|
|
201
|
+
const escHeld = splitDeferredByCloseability(ledger, a, escalationGapAxes,
|
|
202
|
+
{ fullyDeferred: escalationFullyDeferred.has(a.toLowerCase()), heldUnits: stickyGapUnits(P), uncovered: officeGapOf(ctx.registerPlan), askable: askableOf(escalationReceipt) }).held;
|
|
203
|
+
followup += escalationHeldNote(escHeld);
|
|
204
|
+
// No opts.model → stays on this axis's original tier (axisTier: sonnet/haiku); the followup is a fresh
|
|
205
|
+
// session, so no cache rides on it. sessionKey: unitKey[a] names the EXACT key the unit won on. force bypasses idempotency.
|
|
206
|
+
const r = await stage("register-unit", { ...ctx, axis: a }, { force: true, followup, sessionKey: unitKey[a], trigger: "escalation" });
|
|
207
|
+
if (!r.ok) return { axis: a, changed: false, ok: false };
|
|
208
|
+
const afterUnit = readFileSync(P.registerUnit(a), "utf8");
|
|
209
|
+
const changed = afterUnit !== beforeUnit || bandBytesOf(P, a) !== beforeBand;
|
|
210
|
+
if (!changed) {
|
|
211
|
+
note(`escalation ${a}: unit defended in place (unchanged) — Opus re-digest not needed`);
|
|
212
|
+
runLog(run.runDir, { event: "escalation-noop", axis: a });
|
|
213
|
+
}
|
|
214
|
+
return { axis: a, changed, ok: true };
|
|
215
|
+
});
|
|
216
|
+
const escalated = escResults.filter((e) => e.changed).map((e) => e.axis);
|
|
217
|
+
remergeIfBandsMoved(ctx, "escalation");
|
|
218
|
+
// W-3 input (D1): persist the escalation outcome so the client-export gate can WITHHOLD when a
|
|
219
|
+
// load-bearing escalation the system ITSELF raised did not complete. requested = axes attempted this
|
|
220
|
+
// session; failed = those whose register-unit stage returned !r.ok (never ran to a result). The
|
|
221
|
+
// documented-coverage-limit skips (escalate − escalateGated) are accepted limits, never "failed".
|
|
222
|
+
try {
|
|
223
|
+
atomicWrite(P.escalationState, JSON.stringify({ // B5 — the client-gate reads this: never truncated
|
|
224
|
+
ts: new Date().toISOString(),
|
|
225
|
+
requested: escalateGated,
|
|
226
|
+
completed: escResults.filter((e) => e.ok).map((e) => e.axis),
|
|
227
|
+
failed: escResults.filter((e) => !e.ok).map((e) => e.axis),
|
|
228
|
+
}, null, 2) + "\n");
|
|
229
|
+
} catch (e) { note(`escalation-state write failed (non-fatal): ${e.message}`); }
|
|
230
|
+
refreshSupplementalExecution(ctx); // escalation followups may have PROPOSED supplementals — account for them
|
|
231
|
+
if (escalated.length) {
|
|
232
|
+
runLog(run.runDir, { event: "skeptic-escalation", escalated });
|
|
233
|
+
const escalationSegment = lines(
|
|
234
|
+
`The Step-2.6 skeptic flagged the issues below, and these register units have just defended/revised in place: ${escalated.join(", ")}. Re-read only those updated unit files, reconcile your prior findings against them, and revise only what these flags and the new coverage require.`,
|
|
235
|
+
``,
|
|
236
|
+
flags,
|
|
237
|
+
);
|
|
238
|
+
//: the unit defend/adjust work above is KEPT; only the opus re-digest is deferred to
|
|
239
|
+
// the pre-synthesis settlement flush. Keyed on the escalated axis set — a resume re-entering
|
|
240
|
+
// this block with the same set no-ops (the receipt survives the resume).
|
|
241
|
+
mintDigestWork("escalation", escalated, escalationSegment);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ── Spec A3: deadline-envelope — close unmet must-search floor obligations IN-LOOP when time allows ──
|
|
246
|
+
// Floor obligations = `deferred` Coverage-ledger rows (planned but never run — incl. material
|
|
247
|
+
// jurisdictions the digest reconciliation found unsearched). `coverage-limited` rows are documented
|
|
248
|
+
// accepted limits (Lever 4) — a re-run cannot close them, so they are not floors here. Close mechanics
|
|
249
|
+
// mirror the skeptic-escalation block above: a followup on the owning unit's winning key,
|
|
250
|
+
// byte-diff guard, ONE re-digest for materially-changed axes. Same audit-spine lock: never re-fire
|
|
251
|
+
// past synthesis. The decision (envelope arithmetic + choice) is always logged; whatever remains
|
|
252
|
+
// unclosed at delivery is stated in the report with its MECHANICAL cause (front-matter, code-built).
|
|
253
|
+
//
|
|
254
|
+
// funnel trade (owner-accepted): with escalation+envelope COALESCED into one settlement
|
|
255
|
+
// flush, this decision reads the FRESH digest's ledger (exactly as on runs with no escalation) —
|
|
256
|
+
// the escalation re-digest no longer runs first, so a NEW `deferred` row that escalation-changed
|
|
257
|
+
// units would have surfaced via that re-digest is not visible to THIS envelope pass. That miss is
|
|
258
|
+
// NOT silent: the flushed digest re-emits the Coverage ledger, and any still-open deferred row
|
|
259
|
+
// surfaces at delivery via computeOpenFloors → envelope_note (front-matter) and the U1 floor.
|
|
260
|
+
ctx.envelopeNote = null;
|
|
261
|
+
{
|
|
262
|
+
const ledgerNow = loadCoverageLedger(run.runDir).rows; // WS-A: machine ledger when present, else prose
|
|
263
|
+
const axesLc = axes.map((x) => x.toLowerCase());
|
|
264
|
+
// Floors = `deferred` rows. The ⭐-breach union is retired — see the note where
|
|
265
|
+
// `findFloorBreaches` used to live.
|
|
266
|
+
const deferredAxes = [...new Set(ledgerNow.filter((r) => r.status === "deferred").map((r) => r.axis))]
|
|
267
|
+
.filter((a) => axesLc.includes(a))
|
|
268
|
+
// a code-side saturation-probe has no unit session to warm-resume, and its dictated entries were
|
|
269
|
+
// executor-run to completion — a "deferred" sat-probe row can only be ledger prose; skip the arm.
|
|
270
|
+
.filter((a) => a !== "saturation-probe" || unitKey[a]);
|
|
271
|
+
// A2 — split each axis's floor obligations into what a re-run can close and what it never can.
|
|
272
|
+
// The plan-execution receipt is the authority (capabilityGapAxes); the row reason only splits
|
|
273
|
+
// INSIDE an indicted axis. An axis with nothing closeable is HELD: never re-run, never closed by
|
|
274
|
+
// time, still deferred, still an open floor, still disclosed.
|
|
275
|
+
const envelopeReceipt = readPlanExecution(ctx);
|
|
276
|
+
const gapAxes = capabilityGapAxes(ctx.registerPlan, envelopeReceipt);
|
|
277
|
+
const fullyDeferred = new Set((ctx.registerPlan ? fullyDeferredAxes(ctx.registerPlan) : []).map((a) => String(a.axis).toLowerCase()));
|
|
278
|
+
const stickyUnitsNow = stickyGapUnits(P); // a gap this run already accepted is held whatever its row's reason says
|
|
279
|
+
const closeabilityByAxis = new Map(deferredAxes.map((a) => [a,
|
|
280
|
+
splitDeferredByCloseability(ledgerNow, a, gapAxes, { fullyDeferred: fullyDeferred.has(String(a).toLowerCase()), heldUnits: stickyUnitsNow,
|
|
281
|
+
uncovered: officeGapOf(ctx.registerPlan), askable: askableOf(envelopeReceipt) })]));
|
|
282
|
+
const heldAxes = deferredAxes.filter((a) => {
|
|
283
|
+
const s = closeabilityByAxis.get(a);
|
|
284
|
+
// The `!hasBreach &&` term is retired with the ⭐ floor: it kept an axis carrying a
|
|
285
|
+
// mislabelled floor row out of the HELD set, because such a row is work a re-run can do rather
|
|
286
|
+
// than a capability refusal. With no breaches to find, the split alone decides.
|
|
287
|
+
return s.held.length > 0 && s.closeable.length === 0;
|
|
288
|
+
});
|
|
289
|
+
const closeableAxes = deferredAxes.filter((a) => !heldAxes.includes(a));
|
|
290
|
+
const estCloseSec = closeableAxes.length
|
|
291
|
+
? closeableAxes.length * (STAGES["register-unit"].timeoutSec / 2) + STAGES["register-digest"].timeoutSec / 2
|
|
292
|
+
: 0;
|
|
293
|
+
const decision = envelopeDecision({ deferredAxes, deadline: job.deadline ?? null, now: Date.now(), estCloseSec, heldAxes });
|
|
294
|
+
// unconditional telemetry (AD-4): held/held_rows are written on every run, empty included, so
|
|
295
|
+
// "nothing was held" is a recorded answer and not an absent field.
|
|
296
|
+
// `floorBreaches` is GONE from this event. Its only consumer was pipeline.mock.test.mjs's
|
|
297
|
+
// C-2 arm, which retires in the same diff; ask-ledger.mjs reads `reason`/`axes`/`unverified` here and
|
|
298
|
+
// is untouched.
|
|
299
|
+
runLog(run.runDir, { event: "envelope-decision", deferredAxes, estCloseSec, deadline: job.deadline ?? null,
|
|
300
|
+
held_rows: heldAxes.map((a) => ({ axis: a, rows: (closeabilityByAxis.get(a)?.held ?? []).map((r) => ({ unit: r.unit, reason: String(r.reason ?? "").slice(0, 200) })) })),
|
|
301
|
+
...decision });
|
|
302
|
+
// An axis held only because none of its rows has a question left to send is not a capability gap: the client's
|
|
303
|
+
// note below names the capability-held axes alone, and the open-floor line discloses the rest.
|
|
304
|
+
const nothingToSendOnly = (a) => heldForNothingToSend(closeabilityByAxis.get(a));
|
|
305
|
+
for (const a of heldAxes) {
|
|
306
|
+
note(nothingToSendOnly(a)
|
|
307
|
+
? `envelope: ${a} HELD — no question is left to send, so a re-run cannot close it; the floor stays open and ships disclosed`
|
|
308
|
+
: `envelope: ${a} HELD — a capability-gap deferral is never closeable by time; the floor stays open and ships disclosed`);
|
|
309
|
+
}
|
|
310
|
+
// V4-1: same digest-lock semantics as the escalation block — a --from synthesis fork's inherited
|
|
311
|
+
// narrative does not lock the digest (synthesis is about to re-run over it).
|
|
312
|
+
const digestLockedEnv = existsSync(P.narrative) && !forceFromActive(ctx, "synthesis");
|
|
313
|
+
if (closeableAxes.length && decision.close && !digestLockedEnv) {
|
|
314
|
+
const closeResults = await runBatched(closeableAxes, config.gatherConcurrency, async (a) => {
|
|
315
|
+
const beforeUnit = existsSync(P.registerUnit(a)) ? readFileSync(P.registerUnit(a), "utf8") : null;
|
|
316
|
+
const beforeBand = bandBytesOf(P, a); // a close that runs the deferred slices adds blocks to the band
|
|
317
|
+
// quote the axis's own deferred ledger rows + ⭐-floor breach rows verbatim so the unit closes
|
|
318
|
+
// exactly what was deferred (or mislabelled away). WS-A: the quoted rows come from the SAME
|
|
319
|
+
// loadCoverageLedger read the gate decided on — never a separate prose grep that could diverge.
|
|
320
|
+
// A2: a HELD row (capability gap) is excluded from the quoted work and named separately — the
|
|
321
|
+
// unit must not be asked to close what the provider cannot express, and must not delete the row.
|
|
322
|
+
const split = closeabilityByAxis.get(a) ?? { closeable: [], held: [] };
|
|
323
|
+
const rows = split.closeable
|
|
324
|
+
.map((r) => `| ${r.unit} | deferred | ${r.reason} |`).join("\n");
|
|
325
|
+
const heldRows = envelopeHeldNote(split.held);
|
|
326
|
+
note(`envelope: closing deferred coverage on ${a} (deadline permits — ${decision.reason})`);
|
|
327
|
+
// What the re-opened unit is asked to close, and what it is told to leave: the record of the split
|
|
328
|
+
// this close acted on, so a gap handed back as work is visible in the run's own log.
|
|
329
|
+
runLog(run.runDir, { event: "envelope-close-rows", axis: a,
|
|
330
|
+
closeable: split.closeable.map((r) => String(r.unit ?? "")), held: split.held.map((r) => String(r.unit ?? "")) });
|
|
331
|
+
const followup = repairFollowup("register-unit:envelope-close", { paths: P, axis: a, rows: rows + heldRows,
|
|
332
|
+
supplementalLane: !!ctx.registerPlan?.contract?.supplemental_lane, job: ctx.job, profile: ctx.profile });
|
|
333
|
+
const r = await stage("register-unit", { ...ctx, axis: a }, { force: true, followup, sessionKey: unitKey[a], trigger: "envelope" });
|
|
334
|
+
if (!r.ok) return { axis: a, changed: false, fail: r.fail };
|
|
335
|
+
const afterUnit = readFileSync(P.registerUnit(a), "utf8");
|
|
336
|
+
return { axis: a, changed: afterUnit !== beforeUnit || bandBytesOf(P, a) !== beforeBand, fail: null };
|
|
337
|
+
});
|
|
338
|
+
remergeIfBandsMoved(ctx, "envelope");
|
|
339
|
+
const closedChanged = closeResults.filter((e) => e.changed).map((e) => e.axis);
|
|
340
|
+
const closeFails = closeResults.filter((e) => e.fail);
|
|
341
|
+
if (closedChanged.length) {
|
|
342
|
+
// The reconcile segment — shared verbatim between the legacy immediate re-digest (funnel OFF)
|
|
343
|
+
// and the queued settlement-flush section (funnel ON).
|
|
344
|
+
const envelopeSegment = `These register units just CLOSED their deferred Coverage-ledger work (deadline-envelope rule): ${closedChanged.join(", ")}. Re-read only those updated unit files, reconcile your prior findings and the Coverage ledger against them, and revise only what the new coverage requires.`;
|
|
345
|
+
// Post-re-digest bookkeeping, shared by both paths (funnel ON runs it after the settlement
|
|
346
|
+
// flush lands — the detectors are meaningless before the re-emitted ledger exists):
|
|
347
|
+
// (1) Timeout-taint resolution: an envelope close that CHANGED the axis is the sanctioned closer for
|
|
348
|
+
// its deferred rows — judgment engaged with the honest taint reason and re-emitted. Mark the
|
|
349
|
+
// receipt resolved FIRST (before the verify read below), else loadCoverageLedger would re-relabel
|
|
350
|
+
// the freshly-closed rows and the verify would read them as still-open.
|
|
351
|
+
// (2) Fix 2 (close-the-loop, #7) — the envelope quoted the EXACT deferred rows + ⭐-floor breaches to
|
|
352
|
+
// close, then logged `envelope-closed` on a byte-diff, telling the audit trail those floors closed
|
|
353
|
+
// even when the search re-emitted without actually resolving them (RUN1: the incumbent-class /
|
|
354
|
+
// opposition floors "closed" then shipped still-open). Re-run the SAME detectors on the RE-DIGESTED
|
|
355
|
+
// ledger and log as closed ONLY the axes whose specific breach/deferral is gone; the rest are
|
|
356
|
+
// recorded `unverified`. The still-open floors are DISCLOSED by the existing computeOpenFloors →
|
|
357
|
+
// envelope_note path at delivery (deliver-always; disclose > false-clean), so this arm never
|
|
358
|
+
// withholds and never mutates that disclosure — it only stops the audit trail claiming a false close.
|
|
359
|
+
// No re-attempt here: a second paid envelope pass is thrash, and (unlike the register arm) there is
|
|
360
|
+
// no structured remedy to correct the query with — an honest disclosure is the close.
|
|
361
|
+
const verifyEnvelopeClosure = () => {
|
|
362
|
+
try {
|
|
363
|
+
const tp = P.registerTaint;
|
|
364
|
+
if (existsSync(tp)) {
|
|
365
|
+
const rec = readJson(tp);
|
|
366
|
+
let touched = false;
|
|
367
|
+
for (const a of closedChanged) {
|
|
368
|
+
if (rec?.axes?.[a]?.status === "active") {
|
|
369
|
+
rec.axes[a] = { ...rec.axes[a], status: "resolved", resolvedBy: "envelope", resolvedAt: new Date().toISOString() };
|
|
370
|
+
touched = true;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (touched) { writeFileSync(`${tp}.tmp`, JSON.stringify(rec, null, 2) + "\n"); renameSync(`${tp}.tmp`, tp); }
|
|
374
|
+
}
|
|
375
|
+
} catch (e) { note(`register-taint receipt update failed (non-fatal): ${String(e.message).slice(0, 80)}`); }
|
|
376
|
+
const ledgerAfter = loadCoverageLedger(run.runDir).rows;
|
|
377
|
+
const deferredAfter = new Set(ledgerAfter.filter((r) => r.status === "deferred" && !isInactiveAxisRow(r) && axesLc.includes(r.axis)).map((r) => r.axis));
|
|
378
|
+
// The breach half is retired: an axis is unverified when a deferral survives the
|
|
379
|
+
// re-digest. `envelope-closed`'s `unverified` list keeps its meaning for ask-ledger.mjs.
|
|
380
|
+
const envUnverified = closedChanged.filter((a) => deferredAfter.has(a));
|
|
381
|
+
const envVerified = closedChanged.filter((a) => !envUnverified.includes(a));
|
|
382
|
+
runLog(run.runDir, { event: "envelope-closed", axes: envVerified, ...(envUnverified.length ? { unverified: envUnverified } : {}) });
|
|
383
|
+
if (envUnverified.length) note(`envelope: ${envUnverified.join(", ")} re-emitted but the floor is NOT closed (breach/deferral still present after the re-digest) — will ship disclosed, not marked closed`);
|
|
384
|
+
};
|
|
385
|
+
//: the unit closes above are KEPT; the opus re-digest coalesces into the settlement
|
|
386
|
+
// flush. Keyed on the deferred-row set this decision fired over (a resume re-entering with
|
|
387
|
+
// the same open rows no-ops); the closure verification runs after the flush lands.
|
|
388
|
+
mintDigestWork("envelope",
|
|
389
|
+
ledgerNow.filter((r) => r.status === "deferred").map((r) => `${r.axis}/${r.unit}`),
|
|
390
|
+
envelopeSegment);
|
|
391
|
+
ctx.envelopeFlushVerify = verifyEnvelopeClosure;
|
|
392
|
+
}
|
|
393
|
+
if (closeFails.length) {
|
|
394
|
+
ctx.envelopeNote = closeFails.map((e) =>
|
|
395
|
+
`deferred coverage on ${e.axis} not closed — close attempt failed mechanically (${e.fail})`).join("; ");
|
|
396
|
+
// T3 (H3): a MECHANICAL close-fail of a system-raised envelope close is the same
|
|
397
|
+
// class as a failed escalation — "the main search didn't finish". It lands in the SAME sink
|
|
398
|
+
// the client-gate preflight reads (additive; a prose note alone let it ship finished-looking).
|
|
399
|
+
try {
|
|
400
|
+
const p = P.escalationState;
|
|
401
|
+
const cur = existsSync(p) ? readJson(p) : { requested: [], completed: [] };
|
|
402
|
+
const failed = [...new Set([...(cur.failed ?? []), ...closeFails.map((e) => `envelope:${e.axis}`)])];
|
|
403
|
+
atomicWrite(p, JSON.stringify({ ...cur, ts: new Date().toISOString(), failed }, null, 2) + "\n"); // B5 — the client-gate reads this: never truncated
|
|
404
|
+
} catch (e) { note(`escalation-state append failed (non-fatal): ${e.message}`); }
|
|
405
|
+
}
|
|
406
|
+
} else if (closeableAxes.length) {
|
|
407
|
+
ctx.envelopeNote = digestLockedEnv
|
|
408
|
+
? `deferred coverage (${closeableAxes.join(", ")}) not closed — resume past synthesis locks the digest (re-running would corrupt the audit spine)`
|
|
409
|
+
: `deferred coverage (${closeableAxes.join(", ")}) not closed — ${decision.reason}`;
|
|
410
|
+
}
|
|
411
|
+
// A2 — held axes are DISCLOSED, never silently absent: the note is what the report's front matter
|
|
412
|
+
// renders, and a gap nothing can close is precisely the gap the lawyer must be told about. It
|
|
413
|
+
// rides beside any close note rather than replacing it.
|
|
414
|
+
// The account is the owner's sentences (approved 2026-10-30): the searches the register refused during the run apart
|
|
415
|
+
// from the ones it does not support, each refused one with the register's recorded answer, read from the receipt.
|
|
416
|
+
const capabilityHeldAxes = heldAxes.filter((a) => !nothingToSendOnly(a));
|
|
417
|
+
if (capabilityHeldAxes.length) {
|
|
418
|
+
const heldNote = undoneSearchesNote(ctx.registerPlan, envelopeReceipt, capabilityHeldAxes);
|
|
419
|
+
ctx.envelopeNote = ctx.envelopeNote ? `${ctx.envelopeNote}; ${heldNote}` : heldNote;
|
|
420
|
+
}
|
|
421
|
+
refreshSupplementalExecution(ctx); // envelope closes may have PROPOSED supplementals — account for them
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Fix 1b — Finding-1 acceptance gate. An in-scope-live mark may NOT be goods/field-dropped on the batch
|
|
425
|
+
// row alone; such a drop must rest on a record_fetch of the real goods. We parse the FINAL
|
|
426
|
+
// register-findings negative-results drops (after any escalation re-digest above rewrote the file) and
|
|
427
|
+
// cross-check each in-scope-live goods/field drop's URI against the run's record_fetch ledger. A violation
|
|
428
|
+
// is the exact CN-pair failure mode. On a resume past synthesis the findings are already final, so
|
|
429
|
+
// re-checking them here is still correct.
|
|
430
|
+
//
|
|
431
|
+
// RECOVER-THEN-DISCLOSE (completes the Fix-3 escalation): the gate is correct and must never be silenced,
|
|
432
|
+
// but the flagged marks are FETCHABLE — a high-conflict run (KINETIC) where the digest took the
|
|
433
|
+
// name-inferred shortcut on a few marks should SELF-HEAL, not die. So on the first violation we do ONE
|
|
434
|
+
// followup re-digest that forces the worker to record_fetch the flagged URIs and re-decide on their
|
|
435
|
+
// REAL goods (mirrors the coverage-ledger recoverCoverageLedger / candidate-self followup pattern, on the
|
|
436
|
+
// WINNING digest key; a fresh session, so the message names the findings it re-decides). Whatever is STILL
|
|
437
|
+
// violating after that one recovery pass is disclosed as unexamined + clamps the verdict (owner
|
|
438
|
+
// decision 2026-07-22 — the terminal branch below); the gate never silently passes a drop.
|
|
439
|
+
{
|
|
440
|
+
const runPrefix = `clearance-${run.slug}-${run.codename}-`;
|
|
441
|
+
// Re-read the findings + recompute the fetched universe on EACH check (the recovery re-digest rewrites
|
|
442
|
+
// the findings AND may record_fetch the flagged URIs — both must be picked up on the post-recovery
|
|
443
|
+
// check). V4-1: the fetched universe is the DELIVERED ARTIFACT SET's records (run-dir _records/ ∪ this
|
|
444
|
+
// session's ledger rows) — not the session-prefixed ledger alone. A failed fetch is not a retrieval, and a
|
|
445
|
+
// body that carries no record is not one either (ruled 2026-10-18): neither answers the gate, so such a drop
|
|
446
|
+
// gets the gate's own recovery fetch and, failing that, its disclosure. A valid copy the run already holds
|
|
447
|
+
// still answers it, whatever a later attempt did. A call the register answered `ok` is no record on its own:
|
|
448
|
+
// every register files the body it fetched, and a 200 carrying an empty record files an empty one, so the
|
|
449
|
+
// body is what is read, never the call's status.
|
|
450
|
+
const fetchedUniverse = () => new Set(
|
|
451
|
+
[...assembleRunRecords(run.runDir, runPrefix).records].filter(([, body]) => recordBodyHasContent(body)).map(([uri]) => uri));
|
|
452
|
+
const checkScreenGate = () => {
|
|
453
|
+
const findings = existsSync(P.registerFindings) ? readFileSync(P.registerFindings, "utf8") : "";
|
|
454
|
+
return findScreenGateViolations(findings, fetchedUniverse());
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// PARSE-GAP LEDGER (2026-07-21): records the gate is blind to because URI_RE's `[a-z]{2}` cannot read
|
|
458
|
+
// their jurisdiction segment (/mark/int/ Madrid, /mark/uss/ US state). NEVER fatal and never a
|
|
459
|
+
// violation — they would be unclearable, since no re-digest can satisfy a parser that cannot read the
|
|
460
|
+
// answer. Logged so the exposure is measurable before and after the coordinated URI-grammar fix.
|
|
461
|
+
{
|
|
462
|
+
const gaps = findScreenGateParseGaps(existsSync(P.registerFindings) ? readFileSync(P.registerFindings, "utf8") : "");
|
|
463
|
+
if (gaps.length) {
|
|
464
|
+
runLog(run.runDir, { event: "screen-gate-parse-gap", count: gaps.length, refs: gaps.map((g) => g.ref) });
|
|
465
|
+
note(`screen-gate: ${gaps.length} goods-drop record reference(s) our URI grammar cannot parse (${[...new Set(gaps.map((g) => g.ref.split("/")[2]))].join(", ")}) — not policed this run; see the URI-grammar fix`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// UNNAMED-DROP ARM — OBSERVE MODE (2026-07-21, approved gating). A goods/field drop naming no record
|
|
470
|
+
// anywhere is the same disease as the NR10 batch, but the measured population is large (19 of 35
|
|
471
|
+
// goods-drop rows in the delivered archive), so arming it terminal blind would fail most runs on a
|
|
472
|
+
// repair path whose model compliance is untested. It runs observe-only through the fresh-mark
|
|
473
|
+
// validation run and the replays, and the observation answers the question that decides the
|
|
474
|
+
// semantics — TRACEABILITY, not row shape:
|
|
475
|
+
// (a) the row dismisses records named NOWHERE in the run's artifacts → NR10's disease → terminal
|
|
476
|
+
// the day this arms;
|
|
477
|
+
// (b) the row is a slice-level screen over a band whose members ARE enumerated with URIs elsewhere
|
|
478
|
+
// in the run (the "204 NODE + 5 OWED + 50 OED scanned" field-screen shape) → auditable
|
|
479
|
+
// record-by-record, just not in the drop row. Forcing 470 rows for a crowd screen the band
|
|
480
|
+
// already enumerates would be the rule outstripping what judgment needs.
|
|
481
|
+
// So we record, per unnamed row, whether the run enumerated anything under that row's search term.
|
|
482
|
+
// Never fatal, and deliberately NOT deciding the semantics here — this collects the evidence the
|
|
483
|
+
// proposal is built from. Set CLEAROTRON_SCREEN_GATE_UNNAMED=enforce to arm it terminal.
|
|
484
|
+
const unnamedArmed = String(process.env.CLEAROTRON_SCREEN_GATE_UNNAMED ?? "").toLowerCase() === "enforce";
|
|
485
|
+
{
|
|
486
|
+
const unnamed = checkScreenGate().filter((v) => !v.uri);
|
|
487
|
+
if (unnamed.length) {
|
|
488
|
+
// The run's enumerated material: which slices (`_query`) produced records, and how many.
|
|
489
|
+
let byQuery = new Map(), totalEnumerated = 0;
|
|
490
|
+
try {
|
|
491
|
+
const band = readJson(P.registerNamedBand);
|
|
492
|
+
for (const r of (band?.enumerated ?? [])) {
|
|
493
|
+
const q = String(r?._query ?? "").toLowerCase();
|
|
494
|
+
byQuery.set(q, (byQuery.get(q) ?? 0) + 1);
|
|
495
|
+
totalEnumerated++;
|
|
496
|
+
}
|
|
497
|
+
} catch { /* no band on this path — the rows still log, with no traceability evidence */ }
|
|
498
|
+
const words = (s) => String(s ?? "").toLowerCase().match(/[a-z0-9]{3,}/g) ?? [];
|
|
499
|
+
const rows = unnamed.map((v) => {
|
|
500
|
+
const terms = words(v.notes.split(";")[0]).concat(words(v.mark));
|
|
501
|
+
let traceable = 0;
|
|
502
|
+
for (const [q, n] of byQuery) if (terms.some((t) => q.includes(t))) traceable += n;
|
|
503
|
+
return { mark: v.mark.slice(0, 40), result: v.result.slice(0, 40),
|
|
504
|
+
notes: v.notes.replace(/\s+/g, " ").slice(0, 160),
|
|
505
|
+
enumeratedUnderTerm: traceable, class: traceable > 0 ? "b:slice-over-enumerated-band" : "a:named-nowhere" };
|
|
506
|
+
});
|
|
507
|
+
runLog(run.runDir, { event: "screen-gate-unnamed-observed", mode: unnamedArmed ? "enforce" : "observe",
|
|
508
|
+
count: rows.length, totalEnumerated,
|
|
509
|
+
classA: rows.filter((r) => r.class.startsWith("a")).length,
|
|
510
|
+
classB: rows.filter((r) => r.class.startsWith("b")).length, rows });
|
|
511
|
+
note(`screen-gate: ${rows.length} goods-drop row(s) name no record (${rows.filter((r) => r.class.startsWith("a")).length} traceable nowhere, ${rows.filter((r) => r.class.startsWith("b")).length} over an enumerated band) — ${unnamedArmed ? "ENFORCING" : "observe-only this run"}`);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// Observe mode: the unnamed rows are logged above and dropped from the ENFORCED set, so only NAMED
|
|
516
|
+
// records (the multi-URI policing that ships terminal now) can fail a run.
|
|
517
|
+
//
|
|
518
|
+
// ION/copper-foundry 2026-07-22: this filter used to be applied inline to the FIRST check only, and
|
|
519
|
+
// the post-repair re-check below called checkScreenGate() raw — so an unnamed row that observe mode
|
|
520
|
+
// had just excluded came back and killed the run in the terminal branch. The run log for that run
|
|
521
|
+
// says `mode:"observe"` and the failure detail says "drop row names no record URI", which is the
|
|
522
|
+
// unnamed branch: it died on a rule the same function had declared non-enforcing four lines earlier.
|
|
523
|
+
//
|
|
524
|
+
// Worse, an unnamed row is UNFIXABLE on that path by construction — the repair loop below skips it
|
|
525
|
+
// (`if (!v.uri) continue` — the driver cannot fetch what nobody named), so once it reaches the
|
|
526
|
+
// re-check it fails every time. Observe mode was the only thing holding it, and it was dropped at
|
|
527
|
+
// exactly the point where it was load-bearing. Any run with one unnamed goods-drop row plus at least
|
|
528
|
+
// one named violation (ION had eleven) dies here.
|
|
529
|
+
//
|
|
530
|
+
// One filter, one helper, both call sites. The mode is a property of the RUN, not of a call site.
|
|
531
|
+
const enforcedViolations = () => {
|
|
532
|
+
const v = checkScreenGate();
|
|
533
|
+
return unnamedArmed ? v : v.filter((x) => x.uri);
|
|
534
|
+
};
|
|
535
|
+
//: AFTER any settlement/late flush lands a digest, re-run this gate in code over the
|
|
536
|
+
// flushed findings (cheap — the re-emitted file may carry a NEW drop row without a fetch
|
|
537
|
+
// receipt) with at most ONE bounded code-fetch repair round; survivors are FLAGGED, never
|
|
538
|
+
// looped on and never a delivery gate (the disclose-clamp arm below already ran, immediately, at
|
|
539
|
+
// the mechanism). Registered here so the flush (which runs later, at the frame-reopen seam)
|
|
540
|
+
// reuses the exact same check + fetched-universe closure as the gate itself.
|
|
541
|
+
ctx.screenGateRecheck = async (pass) => {
|
|
542
|
+
const fetcher = opts.recordFetcher ?? defaultRecordFetcher;
|
|
543
|
+
const { violations: leftover, failures: postFlushFailures } = await runPostFlushGateRepair({
|
|
544
|
+
check: enforcedViolations,
|
|
545
|
+
fetcher: (uri) => fetcher(uri, { agentId: agent, sessionKey: `${runPrefix}screen-gate-refetch`, recordLog: runRecordLogPath(run.runDir) }),
|
|
546
|
+
log: (row) => runLog(run.runDir, { pass, ...row }),
|
|
547
|
+
});
|
|
548
|
+
const sidecar = P.screenGateUnresolved;
|
|
549
|
+
if (leftover.length) {
|
|
550
|
+
note(`screen-gate (post-flush): ${leftover.length} drop row(s) still lack a fetch receipt after one code-fetch repair round — flagged (bounded; never a loop)`);
|
|
551
|
+
// Re-stamp the disclosure to the CURRENT leftover set — the flush may have corrected some
|
|
552
|
+
// rows while new ones appeared; the floor and the sidecar must describe what is true now.
|
|
553
|
+
// A row already disclosed keeps its original (more specific) fetch-failure cause.
|
|
554
|
+
const priorCause = new Map((ctx.screenGateUnresolved ?? []).map((u) => [u.uri ?? u.mark, u]));
|
|
555
|
+
// — the PROVIDER's own words first. `runPostFlushGateRepair` now returns what each fetch
|
|
556
|
+
// said instead of discarding it, so a row disclosed on this path names the register's error
|
|
557
|
+
// rather than the driver's generic string. `cause_source` says which of the three it is,
|
|
558
|
+
// because "the provider refused" and "the fetch reported ok and the gate still cannot see the
|
|
559
|
+
// record" have completely different fixes and used to print identically.
|
|
560
|
+
ctx.screenGateUnresolved = leftover.map((v) => {
|
|
561
|
+
const key = v.uri ?? v.mark;
|
|
562
|
+
const fresh = v.uri ? postFlushFailures?.get(v.uri) : null;
|
|
563
|
+
const prior = priorCause.get(key);
|
|
564
|
+
if (fresh) return { mark: v.mark, uri: v.uri ?? null, cause: fresh, cause_source: "provider" };
|
|
565
|
+
// An earlier pass's cause keeps the source it was given: a refusal is the provider's on that earlier
|
|
566
|
+
// pass, and a fetch that reported success, or a row naming no record, stays what it was.
|
|
567
|
+
if (prior?.cause) return { mark: v.mark, uri: v.uri ?? null, cause: prior.cause,
|
|
568
|
+
cause_source: !prior.cause_source || prior.cause_source === "provider" ? "provider-earlier-pass" : prior.cause_source };
|
|
569
|
+
return {
|
|
570
|
+
mark: v.mark, uri: v.uri ?? null,
|
|
571
|
+
cause: v.uri
|
|
572
|
+
// The fetch did NOT fail. That is the 641-mark class — a case-fold, a granularity or a
|
|
573
|
+
// record-log write loss — and calling it "not retrievable" sent a whole run chasing the
|
|
574
|
+
// provider while the records sat in _records/ the entire time.
|
|
575
|
+
? "the record_fetch reported success and the gate still cannot see this record — NOT a provider failure; look at the run's own record set before raising it with the vendor"
|
|
576
|
+
: "drop row names no record URI — the dismissal cannot be examined or audited",
|
|
577
|
+
cause_source: v.uri ? "driver-fetch-reported-ok" : "no-uri",
|
|
578
|
+
};
|
|
579
|
+
});
|
|
580
|
+
atomicWrite(sidecar, JSON.stringify({ ts: new Date().toISOString(), unresolved: ctx.screenGateUnresolved }, null, 2) + "\n");
|
|
581
|
+
} else {
|
|
582
|
+
// HEALED AT THE FLUSH: the settled digest re-justified (or the repair fetch grounded) every
|
|
583
|
+
// formerly-unexamined drop. A healed gap must not keep clamping — clear the in-process floor
|
|
584
|
+
// input AND the durable sidecar, exactly like the mechanism's own recovered branch.
|
|
585
|
+
if (Array.isArray(ctx.screenGateUnresolved) && ctx.screenGateUnresolved.length) {
|
|
586
|
+
ctx.screenGateUnresolved = null;
|
|
587
|
+
rmSync(sidecar, { force: true });
|
|
588
|
+
runLog(run.runDir, { event: "screen-gate-clean", recovered: true, pass });
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
let violations = enforcedViolations();
|
|
593
|
+
// What the gate's answer stood on before it fetched anything, and each fetch it makes: the evidence below.
|
|
594
|
+
const heldBeforeGate = fetchedUniverse();
|
|
595
|
+
const gateBefore = screenGateSnapshot(ctx, runPrefix);
|
|
596
|
+
const gateFetched = new Map();
|
|
597
|
+
if (violations.length) {
|
|
598
|
+
// REPAIR-OR-DISCLOSE, NEVER BLOCK (2026-06-18). The digest intermittently drops an in-scope-live mark on
|
|
599
|
+
// goods WITHOUT record_fetching it, and a generic re-digest re-runs identically (the model skips the same
|
|
600
|
+
// fetch) — so the old warm-re-fetch could not repair it and the run HARD-HALTED (no report). A production
|
|
601
|
+
// report must ALWAYS ship. So: (1) the DRIVER fetches the flagged URIs in CODE (the V4-2 record-closure
|
|
602
|
+
// pattern — deterministic, no agent turn, no model-compliance dependency); the plugin chokepoint writes
|
|
603
|
+
// them to the ledger+records so the gate's fetched-universe picks them up. (2) Best-effort, re-decide those
|
|
604
|
+
// rows on the now-fetched goods via the digest session. (3) Whatever STILL cannot be retrieved is an
|
|
605
|
+
// irreducible examination gap (dead/404 record, provider error) → DISCLOSE it + CLAMP the verdict (the
|
|
606
|
+
// coverage-honesty floor below) and DELIVER. The gate's intent (no SILENT drop of an in-scope mark) is
|
|
607
|
+
// preserved by loud disclosure, never by withholding the report.
|
|
608
|
+
// uris self-describe (2026-07-29): an unnamed drop row used to ride as a bare `null`, forcing
|
|
609
|
+
// every event consumer to null-guard. Stamp `unnamed:<mark>` — the digest-queue keyParts shape.
|
|
610
|
+
runLog(run.runDir, { event: "screen-gate-violation", count: violations.length, uris: violations.map((v) => v.uri ?? `unnamed:${v.mark}`), action: "driver-refetch" });
|
|
611
|
+
note(`screen-gate: ${violations.length} in-scope-live goods/field drop(s) not record_fetched — DRIVER code-fetch + re-decide (no hard-halt)`);
|
|
612
|
+
const fetcher = opts.recordFetcher ?? defaultRecordFetcher;
|
|
613
|
+
const fetchFailures = new Map();
|
|
614
|
+
for (const v of violations) {
|
|
615
|
+
if (!v.uri) continue; // an unnamed drop — the driver cannot fetch what nobody named; the re-digest below must name it
|
|
616
|
+
try {
|
|
617
|
+
const r = await fetcher(v.uri, { agentId: agent, sessionKey: `${runPrefix}screen-gate-refetch`, recordLog: runRecordLogPath(run.runDir) });
|
|
618
|
+
if (!r?.ok) fetchFailures.set(v.uri, r?.cause ?? "record_fetch returned not-ok");
|
|
619
|
+
gateFetched.set(v.uri, { ok: r?.ok === true, cause: r?.ok ? null : (r?.cause ?? "record_fetch returned not-ok") });
|
|
620
|
+
} catch (e) { fetchFailures.set(v.uri, String(e?.message ?? e).slice(0, 120)); gateFetched.set(v.uri, { ok: false, cause: String(e?.message ?? e).slice(0, 120) }); }
|
|
621
|
+
}
|
|
622
|
+
// The re-decide text — shared verbatim between the legacy immediate re-digest (funnel OFF) and
|
|
623
|
+
// the queued settlement-flush section (funnel ON).
|
|
624
|
+
const redecideLines = [
|
|
625
|
+
`RE-DECIDE EACH on its fetched goods: keep it as a conflict/finding if in-field; otherwise record the drop with a fetched-goods justification (never a name/owner-inferred guess).`,
|
|
626
|
+
...violations.map((v) => v.uri
|
|
627
|
+
? `- ${v.uri} (${v.mark})${fetchFailures.has(v.uri) ? " [record UNRETRIEVABLE — note it as an unverified drop]" : ""}`
|
|
628
|
+
: `- (${v.mark}) [this drop row names NO record URI — name the record you dropped, one row per record, or restore the candidate]`),
|
|
629
|
+
// ONE RECORD PER ROW: a shared rationale over several records is not a decision about any of them.
|
|
630
|
+
`ONE ROW PER RECORD: if any row above covers several records, split it — each record gets its own row, its own fetched goods, and its own reason. A rationale shared across a batch is not a decision about any of its members.`,
|
|
631
|
+
];
|
|
632
|
+
//: the driver code-fetch above is KEPT (and is what actually clears the gate — the
|
|
633
|
+
// comment below); the re-decide re-digest exists only to re-justify drop rows on real goods,
|
|
634
|
+
// so it queues for the settlement flush instead of firing its own opus pass. Keyed on the
|
|
635
|
+
// violating URI set (a resume re-seeing the same rows no-ops). Deliberately NOT a tailed
|
|
636
|
+
// "ONLY those rows corrected" wording — the flush ends with the standard FULL
|
|
637
|
+
// re-emission contract (the falcon tripwire).
|
|
638
|
+
mintDigestWork("screen-gate", violations.map((v) => v.uri ?? `unnamed:${v.mark}`), lines(
|
|
639
|
+
`The driver has record_fetched the marks below — their REAL goods/services are in the run's record set.`,
|
|
640
|
+
...redecideLines,
|
|
641
|
+
));
|
|
642
|
+
|
|
643
|
+
violations = enforcedViolations();
|
|
644
|
+
if (violations.length) {
|
|
645
|
+
// Irreducible: an in-scope-LIVE mark was dropped on goods and its official record could not be
|
|
646
|
+
// retrieved (the code-fetch failed too) — so the drop cannot be examined. This reverses the
|
|
647
|
+
// fail-loud arm that stood here ("it should just mark it as
|
|
648
|
+
// unexamined — couldn't fetch or something. NOT failed"): an unexamined drop ships as a LOUD
|
|
649
|
+
// unexamined disclosure — a per-mark coverage row on the report plus the coverage-honesty
|
|
650
|
+
// floor's CONDITIONAL clamp — never a dead run. The fail was costing whole reports over
|
|
651
|
+
// provider 404s the machinery can do nothing about; the
|
|
652
|
+
// disclosure+clamp keeps the gate's real intent (nobody relies on that mark as clean) while the
|
|
653
|
+
// report still ships. ctx feeds the floor in-process; the sidecar is the durable copy so a
|
|
654
|
+
// crash between here and delivery cannot lose the disclosure (the floor re-reads it on resume).
|
|
655
|
+
// — same three-way split as the post-flush writer. On THIS path the provider's cause was
|
|
656
|
+
// already available in `fetchFailures`; what was missing is that the generic fallback fired
|
|
657
|
+
// silently when the fetch had reported ok, which is a completely different defect and used to
|
|
658
|
+
// read identically. 62 rows on R1 carried one string across six jurisdictions.
|
|
659
|
+
ctx.screenGateUnresolved = violations.map((v) => {
|
|
660
|
+
const cause = v.uri ? fetchFailures.get(v.uri) : null;
|
|
661
|
+
if (cause) return { mark: v.mark, uri: v.uri, cause, cause_source: "provider" };
|
|
662
|
+
return {
|
|
663
|
+
mark: v.mark, uri: v.uri ?? null,
|
|
664
|
+
cause: v.uri
|
|
665
|
+
? "the record_fetch reported success and the gate still cannot see this record — NOT a provider failure; look at the run's own record set before raising it with the vendor"
|
|
666
|
+
: "drop row names no record URI — the dismissal cannot be examined or audited",
|
|
667
|
+
cause_source: v.uri ? "driver-fetch-reported-ok" : "no-uri",
|
|
668
|
+
};
|
|
669
|
+
});
|
|
670
|
+
atomicWrite(P.screenGateUnresolved,
|
|
671
|
+
JSON.stringify({ ts: new Date().toISOString(), unresolved: ctx.screenGateUnresolved }, null, 2) + "\n");
|
|
672
|
+
runLog(run.runDir, { event: "screen-gate-unresolved", count: violations.length, uris: violations.map((v) => v.uri),
|
|
673
|
+
action: "disclose-clamp", failures: [...fetchFailures.entries()].map(([uri, cause]) => ({ uri, cause })) });
|
|
674
|
+
note(`screen-gate: ${violations.length} in-scope-live mark(s) could not be record_fetched after the driver fetch — the run CONTINUES with each disclosed as unexamined (coverage row + CONDITIONAL clamp; owner decision 2026-07-22, never a dead run).`);
|
|
675
|
+
} else {
|
|
676
|
+
// Recovered — and a PRIOR pass's disclosure sidecar (a crash-resume where the record now
|
|
677
|
+
// fetches or the re-decide landed) must go with it: a healed gap must not keep clamping.
|
|
678
|
+
rmSync(P.screenGateUnresolved, { force: true });
|
|
679
|
+
runLog(run.runDir, { event: "screen-gate-clean", recovered: true });
|
|
680
|
+
}
|
|
681
|
+
} else {
|
|
682
|
+
rmSync(P.screenGateUnresolved, { force: true }); // same healed-gap cleanup as the recovered branch
|
|
683
|
+
// — THE ZERO NAMES ITS OWN CAUSE. This branch fired on the CI red where screen-gate minted
|
|
684
|
+
// no digest work: the gate found no violations, logged that it was clean, and said nothing about
|
|
685
|
+
// WHY — so "the findings file was not there" and "the findings are fine" left identical records.
|
|
686
|
+
// Nothing about the gate's behaviour changes here; the next occurrence just arrives diagnosed.
|
|
687
|
+
const fPresent = existsSync(P.registerFindings);
|
|
688
|
+
runLog(run.runDir, { event: "screen-gate-clean",
|
|
689
|
+
...screenGateZeroCause({ findingsPresent: fPresent,
|
|
690
|
+
findingsContent: fPresent ? readFileSync(P.registerFindings, "utf8") : "", unnamedArmed }) });
|
|
691
|
+
}
|
|
692
|
+
recordScreenGateEvidence(ctx, { runPrefix, before: gateBefore, heldBeforeGate, heldAfterGate: fetchedUniverse(), gateFetched });
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// ──: STANDALONE SETTLEMENT / LATE FLUSH ───────────────────────────────────────────────────
|
|
696
|
+
// When the frame-reopen block fired nothing (clean diff, no blind model, receipt-skipped, disabled)
|
|
697
|
+
// but the queue is non-empty, the settlement flush still runs HERE — the same seam, before synthesis.
|
|
698
|
+
// Empty queue + no reopen ⇒ zero digest passes at this point.
|
|
699
|
+
//
|
|
700
|
+
// DIGEST-LOCKED (a resume past synthesis): escalation/envelope never ran (their digestLocked guards
|
|
701
|
+
// stay exactly as today), so any pending item here is a POST-SYNTHESIS trigger — today that is the
|
|
702
|
+
// screen-gate on a resumed run (whose legacy re-digest at the gate ALSO ran past synthesis), plus
|
|
703
|
+
// anything a failed pre-synthesis flush left pending. Those get AT MOST ONE bounded LATE flush per
|
|
704
|
+
// pass, at this same seam — deliberately BEFORE the back half's skip evaluation, so the
|
|
705
|
+
// stage-freshness staleness recompute of skeptic/synthesis/cards happens once, in-pass, instead of
|
|
706
|
+
// stale-blocking delivery into another park/resume cycle. Receipts still hold: a flushed item can
|
|
707
|
+
// never re-fire on any later resume.
|
|
708
|
+
if (!ctx.digestSettled) {
|
|
709
|
+
const digestLockedFlush = existsSync(P.narrative) && !forceFromActive(ctx, "synthesis");
|
|
710
|
+
// ── LATE EVIDENCE IS ASSESSED BEFORE THE READING STEP'S LAST PASS AND THE WRITER (owner's ruling, 2026-10-19) ──
|
|
711
|
+
// A record the band gained after placement's pass (a unit's re-run, the code-side recheck) is placed or set aside
|
|
712
|
+
// by placement itself, through its own stage, before the flush below hands the reading step the placements and
|
|
713
|
+
// before the writer reads them. The form is a union, so every row placement accepted stands. Only ids placement
|
|
714
|
+
// never read run it again: a band whose counts alone moved costs nothing. Every path that grows the band after
|
|
715
|
+
// placement queues the reading step's re-run, so the flush below follows; one that did not is recorded.
|
|
716
|
+
if (!digestLockedFlush) {
|
|
717
|
+
const late = lateRecordIds(P);
|
|
718
|
+
if (late.length) {
|
|
719
|
+
runLog(run.runDir, { event: "late-evidence", records: late.length });
|
|
720
|
+
note(`late evidence: ${late.length} record(s) reached the band after placement's pass — placement assesses them before the reading step's next pass and the writer`);
|
|
721
|
+
// A PASS THAT FAILS, OR IS REFUSED BEFORE IT STARTS, DOES NOT END THE RUN HERE. A run is never held for a recovery
|
|
722
|
+
// that could not run (the owner's ruling of 2026-10-19): placement's earlier account stands, and the floor and the
|
|
723
|
+
// recall gate state what it leaves open. The stage can throw before it dispatches, as it does for a band past the
|
|
724
|
+
// size ceiling, so the throw is caught and recorded as the failure it is.
|
|
725
|
+
let pass;
|
|
726
|
+
try { pass = recordPlacementPass(ctx, await stage("placement-inquiry", ctx, { force: true, trigger: "late-evidence" }), "late-evidence"); }
|
|
727
|
+
catch (e) { pass = { ok: false, fail: String(e?.message ?? e) }; }
|
|
728
|
+
if (!pass?.ok) {
|
|
729
|
+
runLog(run.runDir, { event: "late-evidence-failed", records: late.length, fail: String(pass?.fail ?? "failed").slice(0, 200) });
|
|
730
|
+
ctx.latePassFailed = { records: late.length, fail: String(pass?.fail ?? "failed").slice(0, 200) }; // the attempt, for the delivery record
|
|
731
|
+
note(`late evidence: placement's pass did not complete (${String(pass?.fail ?? "").slice(0, 100)}) — its earlier account stands, and the floor and the recall gate state what it leaves open`);
|
|
732
|
+
}
|
|
733
|
+
if (!pendingItems(ctx.digestQueue).length) runLog(run.runDir, { event: "late-evidence-no-digest-work", records: late.length });
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (!digestLockedFlush) await flushDigestQueue("pre-synthesis");
|
|
737
|
+
else if (pendingItems(ctx.digestQueue).length) await flushDigestQueue("late");
|
|
738
|
+
ctx.digestSettled = true;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// ── follow-up (2026-08-04): SETTLE THE ONE-SHOT FRAME STAMP ──────────────────────────────────
|
|
742
|
+
// THE LAST SEAM AT WHICH THE BAND AND THE UNITS CAN STILL MOVE. Three arms between frame-diff's seam
|
|
743
|
+
// and here rewrite artifacts it declares, and none of them could account for it: the escalation
|
|
744
|
+
// recheck's deriveNamedBand re-merge (register-named-band.json), the skeptic escalation's forced
|
|
745
|
+
// register-unit re-runs and the envelope close's forced register-unit re-runs (register-units/*.md).
|
|
746
|
+
// re-aimed stageInputs["frame-diff"] at exactly those artifacts and re-aimed nothing else, so on
|
|
747
|
+
// a RESUME that re-enters with frame-diff fresh and narrative.md absent — a recovery park or a
|
|
748
|
+
// rate-limit postpone anywhere between the frame seam and synthesis — frame-diff SKIPPED (⇒ on the
|
|
749
|
+
// delivery path via ctx.skippedStages), one of those arms moved its inputs, the delivery precondition
|
|
750
|
+
// read it stale, and with no UPSTREAM_STALE_REPAIR entry the run PARKED. A fresh run never saw it:
|
|
751
|
+
// frame-diff RUNS there, so it is never on the delivery path.
|
|
752
|
+
//
|
|
753
|
+
// Restamp rather than repair, because a re-diff cannot be the remedy: the stage is one-shot by
|
|
754
|
+
// contract, and every consumer of its output ran before this line. The rewrites are also the SAFE
|
|
755
|
+
// direction — the arms close coverage, so a diff taken over the earlier band can only over-report
|
|
756
|
+
// omissions, never miss one.
|
|
757
|
+
//
|
|
758
|
+
// NOT gated on ctx.digestSettled: settling the stamp is idempotent and must happen on every pass that
|
|
759
|
+
// reaches this seam, including one whose queue was already drained by an earlier pass.
|
|
760
|
+
settleOneShotStamp(run.runDir, "frame-diff",
|
|
761
|
+
[P.registerNamedBand, ...(axes ?? []).map((a) => P.registerUnit(a))], "pre-synthesis-register-arms");
|
|
762
|
+
|
|
763
|
+
// ── crowd-context (2026-07-22): the counts a lawyer closes a crowd doubt with ─────────────────────
|
|
764
|
+
// Runs at ONE seam — after the frame-reopen block (so the ledger read reflects any reopen re-digest)
|
|
765
|
+
// and before synthesis (its only consumer). When the coverage ledger holds a MATERIAL slice the
|
|
766
|
+
// funnel could not enumerate to has_more:false (the exact shape the COVERAGE JUDGMENT dictation
|
|
767
|
+
// routes to sufficient:false), the driver gathers the affirmative crowded-field evidence a lawyer
|
|
768
|
+
// closes that doubt with: per-term live counts, the same counts restricted to the in-scope classes,
|
|
769
|
+
// and the exact/near-identical subset FULLY enumerated when it is small enough — the dangerous
|
|
770
|
+
// category actually seen. The artifact is EVIDENCE to judgment, never a gate: no count decides
|
|
771
|
+
// anything here, the digest/ledger/band are never touched (the queries round-trip a STANDALONE
|
|
772
|
+
// plan/band pair under _driver/), and every failure is non-fatal by contract — log
|
|
773
|
+
// `crowd-context-failed` and continue; an absent artifact leaves synthesis's material-slice ⇒
|
|
774
|
+
// sufficient:false path exactly as it was. The executor is the SAME provider executePlan lane the
|
|
775
|
+
// code-side saturation-probe and the fan-in repair kit dispatch through (planExec, resolved once
|
|
776
|
+
// above the gather) — injected, so the module tests against a stub and no new provider surface exists.
|
|
777
|
+
try {
|
|
778
|
+
// crash-resume idempotency (mirrors stageOnce's skip): a prior pass's artifact is reused, never
|
|
779
|
+
// re-bought — re-running would re-spend provider calls and churn synthesis's input fingerprint.
|
|
780
|
+
if (existsSync(P.crowdContext)) {
|
|
781
|
+
try {
|
|
782
|
+
const prior = readJson(P.crowdContext);
|
|
783
|
+
ctx.crowdContext = { slices: (prior.slices ?? []).length };
|
|
784
|
+
runLog(run.runDir, { event: "crowd-context", reused: true, slices: ctx.crowdContext.slices, output: outputMeta(P.crowdContext) });
|
|
785
|
+
} catch { /* unreadable prior artifact — rebuild below */ }
|
|
786
|
+
}
|
|
787
|
+
if (!ctx.crowdContext && planExec && ctx.registerPlan) {
|
|
788
|
+
// the planExec-lane adapter: entries → standalone plan file → provider executePlan → band blocks.
|
|
789
|
+
// Own files under _driver/ (crowd-context-plan/-band.json) so the frozen register plan and the
|
|
790
|
+
// axis bands are never written; blocks come back qid-stamped exactly like every executor band.
|
|
791
|
+
const ccExecutor = async (entries) => {
|
|
792
|
+
const ccPlanPath = P.crowdContextPlan;
|
|
793
|
+
const ccBandPath = P.crowdContextBand;
|
|
794
|
+
atomicWrite(ccPlanPath, JSON.stringify({
|
|
795
|
+
schema_version: 1,
|
|
796
|
+
purpose: "crowd-context evidence queries — driver-minted, standalone; never part of the frozen register plan",
|
|
797
|
+
regions: ctx.registerPlan?.regions ?? [], entries,
|
|
798
|
+
}, null, 2) + "\n");
|
|
799
|
+
const r = await planExec({ planPath: ccPlanPath, axis: CROWD_CONTEXT_AXIS, outputPath: ccBandPath },
|
|
800
|
+
{ agentId: ctx.agent, sessionKey: `clearance-${run.slug}-${run.codename}-crowd-context`, recordLog: runRecordLogPath(run.runDir) });
|
|
801
|
+
if (!r?.ok) throw new Error(String(r?.cause ?? "crowd-context plan execution failed").slice(0, 200));
|
|
802
|
+
const blocks = readJson(ccBandPath);
|
|
803
|
+
return Array.isArray(blocks) ? blocks : [];
|
|
804
|
+
};
|
|
805
|
+
const cc = await buildCrowdContext({
|
|
806
|
+
ledger: loadCoverageLedger(run.runDir).rows, // fresh read — post-reopen/re-digest, same source as every gate
|
|
807
|
+
planContext: { entries: ctx.registerPlan.entries ?? [], niceClasses: ctx.registerPlan.nice_classes ?? [], regions: ctx.registerPlan.regions ?? [] },
|
|
808
|
+
executor: ccExecutor,
|
|
809
|
+
capabilities: registerCapabilities(ctx.register), // the contains floor, read the way the plan compile reads it
|
|
810
|
+
note: (m) => note(m),
|
|
811
|
+
log: (row) => runLog(run.runDir, row), // the orchestrator's own crowd-context-failed row lands in run.jsonl
|
|
812
|
+
});
|
|
813
|
+
if (cc) {
|
|
814
|
+
atomicWrite(P.crowdContext, JSON.stringify(cc.json, null, 2) + "\n");
|
|
815
|
+
atomicWrite(P.crowdContextMd, cc.md);
|
|
816
|
+
ctx.crowdContext = { slices: cc.stats.slices };
|
|
817
|
+
runLog(run.runDir, { event: "crowd-context", ...cc.stats, output: outputMeta(P.crowdContext) });
|
|
818
|
+
note(`crowd-context: gathered ${cc.stats.terms} per-term count(s) over ${cc.stats.slices} material slice(s); ${cc.stats.enumerated_subsets} exact/near-identical subset(s) fully enumerated (${cc.stats.enumerated_records} record(s) seen)`);
|
|
819
|
+
// PR-8 — re-derive the band shape now that crowd-context exists: its crowds[] rows carry the
|
|
820
|
+
// crowd_context_slice join (compose with the artifact, never change it), and synthesis reads
|
|
821
|
+
// the shape. The band itself is unchanged — this only re-projects it with the new evidence.
|
|
822
|
+
try { deriveBandShape(ctx, readJson(P.registerNamedBand)); }
|
|
823
|
+
catch { /* no merged band on this path (legacy/register-gap) — the pre-existing shape stands */ }
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
} catch (e) {
|
|
827
|
+
// never-kill: absence of crowd context must never block or degrade a run — disclose and continue.
|
|
828
|
+
note(`crowd-context failed (non-fatal — synthesis proceeds without it): ${String(e?.message ?? e).slice(0, 120)}`);
|
|
829
|
+
runLog(run.runDir, { event: "crowd-context-failed", fail: String(e?.message ?? e).slice(0, 200) });
|
|
830
|
+
}
|
|
831
|
+
}
|