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,644 @@
|
|
|
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/corrections.mjs — the functions the correction steps share: how a review's flags name findings, the rollback
|
|
5
|
+
// and repair of a corrective pass, and the correction after a repair's review.
|
|
6
|
+
//
|
|
7
|
+
// Moved out of pipeline.mjs unchanged. The names below are still held there, and this module must not import that one
|
|
8
|
+
// back, so pipeline.mjs hands them in once, as it loads, through useThePipeline(); each moves here when the code that
|
|
9
|
+
// shares it has moved.
|
|
10
|
+
import { driverDir } from "../../shared/driver-dir.mjs";
|
|
11
|
+
import { correctionTargets } from "../corrections-delivered.mjs";
|
|
12
|
+
import { REPORT_LINE_KEY, REPORT_LINE_LABEL, answersLeftBehind, buildCorrectionsApplied, correctionScope, correctionsWorklist, flaggedPositions, linesOf, reportLines } from "../corrections-feedforward.mjs";
|
|
13
|
+
import { parseFindingsJsonLenient } from "../findings-model.mjs";
|
|
14
|
+
import { note, runLog } from "../log.mjs";
|
|
15
|
+
import { listedAddresses, listedExclusionPositions, readAcceptedFlags } from "../narrative-refutation-record.mjs";
|
|
16
|
+
import { properNameCandidates } from "../predelivery-lint.mjs";
|
|
17
|
+
import { atomicWrite } from "../run-record.mjs";
|
|
18
|
+
import { foldAfterSave, modelRecordPath, restoreFold } from "../record-fold.mjs";
|
|
19
|
+
import { normalizeRecordUri } from "../registry-fidelity.mjs";
|
|
20
|
+
import { repairFollowup } from "../repair-composers.mjs";
|
|
21
|
+
import { NARRATIVE_PROSE, anyRenumbered, sectionText } from "../repair-scope.mjs";
|
|
22
|
+
import { writeFindings } from "../stage-freshness.mjs";
|
|
23
|
+
import { paths } from "../stages.mjs";
|
|
24
|
+
import { lastAcceptedCall, rebaseSynthesis, restoreSynthesisBase, snapshotSynthesisBase } from "../synthesis-record.mjs";
|
|
25
|
+
import { parseCorrections } from "../verify.mjs";
|
|
26
|
+
import { createHash } from "node:crypto";
|
|
27
|
+
import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
28
|
+
|
|
29
|
+
let CORRECTIONS_DELIVERED_FILE, asPartNotCompleted, extractRulingsTail, must, postRepairCorrectionsPath, postRepairStatePath, prepareDeclinationSpec, recordFromTheSaves, recordSynthesisSeam, removalRepairedRow, reviewAfterRepairPath, reviewExclusionsPaths, safeReadJson, snapshotFindingsForCorrections, stage, stageCharter;
|
|
30
|
+
|
|
31
|
+
/** Called once by pipeline.mjs as it loads, with the names above. */
|
|
32
|
+
export function useThePipeline(held) {
|
|
33
|
+
({ CORRECTIONS_DELIVERED_FILE, asPartNotCompleted, extractRulingsTail, must, postRepairCorrectionsPath, postRepairStatePath, prepareDeclinationSpec, recordFromTheSaves, recordSynthesisSeam, removalRepairedRow, reviewAfterRepairPath, reviewExclusionsPaths, safeReadJson, snapshotFindingsForCorrections, stage, stageCharter } = held);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* — `depth` IS A PARAMETER because the corrective pass re-emits the WHOLE narrative and was the
|
|
38
|
+
* only synthesis dispatch that did not carry the depth rung. The fresh dispatch carried it once; this
|
|
39
|
+
* one carried it zero times, and the file that ships is the one this pass writes. The delivered
|
|
40
|
+
* narrative then did the thing the rung forbids — full prose accounts for conflicts the rung excludes.
|
|
41
|
+
*
|
|
42
|
+
* A re-emission that is not told the rung is not a repair of the rung's output. It is a fresh write
|
|
43
|
+
* under the default contract, wearing the corrective pass's name.
|
|
44
|
+
*/
|
|
45
|
+
/** A flag's position ids as the review's list keys them; null when it names none. PURE. */
|
|
46
|
+
const positionIdsOf = (ids, listed) => {
|
|
47
|
+
if (!Array.isArray(ids) || !ids.length) return null;
|
|
48
|
+
const out = [...new Set(ids.map((p) => listed?.get(String(normalizeRecordUri(p) ?? "")) ?? String(normalizeRecordUri(p) ?? p)))];
|
|
49
|
+
return out.length ? out : null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* WHAT A FLAG IS ABOUT, READ ONE WAY FOR THE CORRECTION AND ITS RECHECK (ruled 2026-10-30). A finding flag names its
|
|
54
|
+
* findings; a flag on a writer's exclusion names its positions; a flag about the document names the passage, section or
|
|
55
|
+
* coverage claim in its text, and carries no finding ordinal, which is normal for it. That is a declared target, `[]`,
|
|
56
|
+
* as the rendered review's `[on: -]` already reads, so a document flag no longer opens every finding for revision. A flag
|
|
57
|
+
* whose target cannot be read, one with no text, stays `null`, which leaves the pass open: an unidentified target is not
|
|
58
|
+
* a document one. PURE.
|
|
59
|
+
*/
|
|
60
|
+
export const flagOrdinals = (f) => (Array.isArray(f?.on) && f.on.length ? f.on : String(f?.text ?? "").trim() ? [] : null); // @internal
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The review's flags as the correction and its recheck read them: from the typed call the review recorded, or, for a
|
|
64
|
+
* review that has none (an archived run, a review the tool refused), parsed from its rendered document. Both read a flag's
|
|
65
|
+
* target the same way. IMPURE (reads the run's accepted call and its exclusions list).
|
|
66
|
+
*/
|
|
67
|
+
export function correctionRows(P, review, typed = readAcceptedFlags(P?.runDir)) { // @internal
|
|
68
|
+
if (!typed) return parseCorrections(review);
|
|
69
|
+
const listed = listedExclusionPositions(P.runDir);
|
|
70
|
+
return typed.map((f, i) => ({
|
|
71
|
+
n: i + 1, kind: f.kind, text: f.text, fix: f.fix ?? null,
|
|
72
|
+
ordinals: flagOrdinals(f),
|
|
73
|
+
// A writer's excluded position, as the review's list keys it, whichever of its record ids the flag named.
|
|
74
|
+
positions: positionIdsOf(f.positions, listed),
|
|
75
|
+
// The report's other parts the flag declared, by the addresses its review was handed.
|
|
76
|
+
...(Array.isArray(f.lines) && f.lines.length ? { lines: [...new Set(f.lines)] } : {}),
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The scope with each part its flags declared, by the label its review was shown, in declaration order. IMPURE (reads the run). */
|
|
81
|
+
function withLineLabels(scope, rows, P) {
|
|
82
|
+
const declared = [...new Set((rows ?? []).flatMap((r) => (Array.isArray(r?.lines) ? r.lines : [])))];
|
|
83
|
+
if (!declared.length) return scope;
|
|
84
|
+
const byAddress = new Map((listedAddresses(P.runDir)?.lines ?? []).map((l) => [l.address, l.label]));
|
|
85
|
+
return { ...scope, lineLabels: declared.map((a) => byAddress.get(a) ?? a) };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The scope with each named position's mark, owner and id, as the corrective pass is told them. IMPURE (reads the run). */
|
|
89
|
+
function withPositionLabels(scope, P) {
|
|
90
|
+
if (!scope?.positions?.length) return scope;
|
|
91
|
+
const shown = safeReadJson(reviewExclusionsPaths(P).shown);
|
|
92
|
+
const byUri = new Map((Array.isArray(shown?.positions) ? shown.positions : []).map((p) => [p.uri, p]));
|
|
93
|
+
// Its row in the list `record_declination` reads, prepared again before this pass, so keeping an exclusion names the row.
|
|
94
|
+
const spec = safeReadJson(paths(P.runDir).declinationSpec)?.rows;
|
|
95
|
+
const rowOf = (u) => (Array.isArray(spec) ? spec.findIndex((r) => r?.kind !== "page" && String(normalizeRecordUri(r?.uri) ?? "") === u) : -1);
|
|
96
|
+
const label = (u) => { const p = byUri.get(u); const i = rowOf(u); return `${p?.mark ?? "(unnamed)"}${p?.owner ? ` — ${p.owner}` : ""} (${u})${i >= 0 ? `, row ${i}` : ""}`; };
|
|
97
|
+
return { ...scope, positionLabels: scope.positions.map(label) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The review as the correction reads it, once: the pieces of its message, and the excluded positions its flags name,
|
|
102
|
+
* which its dispatch also hands the writer's save (synthesis-record.mjs, `correctionPositions`), so the positions the
|
|
103
|
+
* message names are the positions the save may add a finding for. IMPURE (reads the run).
|
|
104
|
+
*/
|
|
105
|
+
export function correctionReading(P) { // @internal
|
|
106
|
+
const review = existsSync(P.seniorEyeReview) ? readFileSync(P.seniorEyeReview, "utf8") : "";
|
|
107
|
+
const rulingsTail = extractRulingsTail(existsSync(P.placement) ? readFileSync(P.placement, "utf8") : "");
|
|
108
|
+
// — THE FLAGS ARRIVE AS A TYPED WORKLIST, not only as a wall of prose. The reviewer already
|
|
109
|
+
// declares each flag's kind and taught it all four; the first run after that deployed came back
|
|
110
|
+
// with four kinds populated across twelve lines. The raw review still rides below — this is a better
|
|
111
|
+
// index of the same evidence, and dropping the prose would lose the reasoning the flags rest on.
|
|
112
|
+
// ── T3b: THE TYPED FLAGS ARE THE WORKLIST'S SOURCE, NOT THE RENDERED PROSE ──────────────────────
|
|
113
|
+
//
|
|
114
|
+
//. The comment above says the flags "arrive as a typed worklist" — they did not.
|
|
115
|
+
// `parseCorrections` re-reads the DOCUMENT the driver had just rendered from those very values, so a
|
|
116
|
+
// flag the parse misses is a defect the reviewer named and the corrective pass never sees. That parse
|
|
117
|
+
// is what conversion 9 removed the need for: since the reviewer records typed values, the flags exist
|
|
118
|
+
// as data a few hundred milliseconds earlier, and reading them back out of markdown re-introduces the
|
|
119
|
+
// one failure the conversion closed.
|
|
120
|
+
//
|
|
121
|
+
// ✕ THE FALLBACK IS EXPLICIT AND RECORDED, NOT SILENT. `readAcceptedFlags` returns null for a run with
|
|
122
|
+
// no accepted call — an archived run, a resume across the conversion, or a review the tool REFUSED —
|
|
123
|
+
// and those runs still have a rendered document that the old parse reads correctly. So the parse stays
|
|
124
|
+
// as the second source rather than being deleted. What it must never be is invisible: a reader who
|
|
125
|
+
// cannot tell which source produced a worklist cannot tell a missed flag from an absent one, so the
|
|
126
|
+
// choice is written to the run log with the count each source yielded.
|
|
127
|
+
const typed = readAcceptedFlags(P.runDir);
|
|
128
|
+
const rows = correctionRows(P, review, typed);
|
|
129
|
+
if (P.runDir) {
|
|
130
|
+
try {
|
|
131
|
+
runLog(P.runDir, {
|
|
132
|
+
event: "corrective-worklist-source",
|
|
133
|
+
source: typed ? "typed-call" : "rendered-parse",
|
|
134
|
+
flags: rows.length,
|
|
135
|
+
// BOTH counts, always, so a divergence is visible in the record rather than inferable. If the
|
|
136
|
+
// typed source is in use and the parse would have found fewer, that difference IS the defect this
|
|
137
|
+
// change exists to close, and a reader should be able to see it without re-running anything.
|
|
138
|
+
parsedWouldFind: parseCorrections(review).length,
|
|
139
|
+
});
|
|
140
|
+
} catch { /* telemetry only — a log that cannot be written never blocks a repair */ }
|
|
141
|
+
}
|
|
142
|
+
const worklist = correctionsWorklist(rows);
|
|
143
|
+
// — THE SCOPE BLOCK, and it is the whole saving. The corrective pass costs 683 s on a delivered
|
|
144
|
+
// run because it re-emits the entire narrative and the entire findings.json; on that run exactly ONE
|
|
145
|
+
// finding moved. When every flag declares which finding it is about, the pass is told so, and told
|
|
146
|
+
// that nothing else may move. When any flag declares nothing, this is "" and the dispatch is
|
|
147
|
+
// byte-identical to the one before this existed — the narrowing is bought by the reviewer's own
|
|
148
|
+
// declaration, never assumed on its behalf. The positions the flags named ride either way, with their rows.
|
|
149
|
+
const named = flaggedPositions(rows);
|
|
150
|
+
const scope = withLineLabels(withPositionLabels({ ...correctionScope(rows), ...(named.length ? { positions: named } : {}) }, P), rows, P);
|
|
151
|
+
return { review, rulingsTail, worklist, scope, positions: named };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
*, T3b — THE CORRECTIVE PASS FAILED VALIDATION. RESTORE THE LAST GOOD STATE.
|
|
156
|
+
*
|
|
157
|
+
* Owner decision, 2026-08-26, put to him as a client outcome with options: a targeted fix that fails
|
|
158
|
+
* validation is DISCARDED — the report never ships text a repair degraded.
|
|
159
|
+
*
|
|
160
|
+
* ── WHAT HAPPENED BEFORE THIS, WHICH IS WORSE THAN SHIPPING DEGRADED TEXT ────────────────────────
|
|
161
|
+
*
|
|
162
|
+
* `must(correctivePass, …)` threw. Nothing between it and the run-level catch caught it, so a
|
|
163
|
+
* corrective synthesis that could not produce a document its validators accept KILLED THE RUN: the
|
|
164
|
+
* client received no report at all, on a matter where the only defect was that a repair of an
|
|
165
|
+
* already-delivered draft did not take. The pre-corrective findings were sitting on disk in full the
|
|
166
|
+
* whole time — `snapshotFindingsForCorrections` writes the TEXT, not just a sha, and has since PR-4.
|
|
167
|
+
*
|
|
168
|
+
* So the rollback is not only "don't ship the degraded version". It is the difference between a report
|
|
169
|
+
* and no report, which is the order of preference this product works to: avoid, then recover inside the
|
|
170
|
+
* run, then deliver always.
|
|
171
|
+
*
|
|
172
|
+
* ── WHAT IS ROLLED BACK TO, AND WHY IT IS A GOOD STATE ───────────────────────────────────────────
|
|
173
|
+
*
|
|
174
|
+
* The findings.json the reviewer read. It passed synthesis's own validators when it was written, and it
|
|
175
|
+
* is the document every earlier stage's output was checked against. It is not a guess at a good state;
|
|
176
|
+
* it is the last one this run demonstrated.
|
|
177
|
+
*
|
|
178
|
+
* The narrative beside it and the transport's merge base come back with it, whether or not findings.json
|
|
179
|
+
* moved: a pass can save a narrative change alone, and a base left at the failed pass's record is what the
|
|
180
|
+
* next patch would merge onto, which applies the discarded pass again. The snapshot holds both
|
|
181
|
+
* (`snapshotFindingsForCorrections`); a snapshot taken without them leaves both files as they are.
|
|
182
|
+
*
|
|
183
|
+
* ── TWO CASES THAT MUST STILL THROW, BECAUSE SWALLOWING THEM LOSES MORE THAN IT SAVES ────────────
|
|
184
|
+
*
|
|
185
|
+
* rate-limited The run is PARKED and auto-resumes after the cap resets, with every stage intact.
|
|
186
|
+
* Rolling back and delivering here would spend the client's report to avoid a wait,
|
|
187
|
+
* and the corrective pass would never be retried at all.
|
|
188
|
+
* no snapshot There is no last good state — the run had no findings.json before the pass. An
|
|
189
|
+
* absence is a finding, not a pass: with nothing to restore, delivering would ship
|
|
190
|
+
* whatever the failed pass left behind, which is exactly the text the owner ruled out.
|
|
191
|
+
*
|
|
192
|
+
* Returns the rollback record, or null to mean "this one still throws".
|
|
193
|
+
*/
|
|
194
|
+
export function rollbackCorrectivePass(P, runDir, pre, fail) { // @internal
|
|
195
|
+
if (fail?.fail === "rate_limited" || fail?.resetsAt) return null;
|
|
196
|
+
if (!pre?.raw) return null;
|
|
197
|
+
let now = null;
|
|
198
|
+
try { now = readFileSync(P.findings, "utf8"); } catch { /* the pass may have left nothing readable */ }
|
|
199
|
+
const nowSha = now == null ? null : createHash("sha256").update(now).digest("hex");
|
|
200
|
+
const changed = nowSha !== pre.sha;
|
|
201
|
+
if (changed) {
|
|
202
|
+
// Atomic, like every other write to this file: a half-restored findings.json is a worse state than
|
|
203
|
+
// either of the two this is choosing between.
|
|
204
|
+
writeFindings(runDir, pre.raw, { why: "corrective-pass-rolled-back", settles: [] });
|
|
205
|
+
if (pre.fold) restoreFold(runDir, pre.fold); // the record the model wrote and the map, as they stood
|
|
206
|
+
}
|
|
207
|
+
// `restored` keeps speaking for findings.json alone; what happened to the narrative and the base is its own field.
|
|
208
|
+
const base = restoreSynthesisBase(runDir, pre.base);
|
|
209
|
+
const record = { ts: new Date().toISOString(), reason: String(fail?.fail ?? "failed").slice(0, 200),
|
|
210
|
+
restored: changed, preSha: pre.sha, failedSha: nowSha, ...(base ? { base } : {}) };
|
|
211
|
+
try { atomicWrite(paths(runDir).correctiveRollback, JSON.stringify(record, null, 2) + "\n"); }
|
|
212
|
+
catch { /* sidecar is best-effort; the runLog event below is the record that decides */ }
|
|
213
|
+
return record;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* THE FLOOR UNDER A CORRECTIVE PASS: nothing leaves the findings record without
|
|
218
|
+
* somebody having said so.
|
|
219
|
+
*
|
|
220
|
+
* WHAT THIS IS A BACKSTOP FOR, and why it is not the fix. A corrective pass resent a whole document
|
|
221
|
+
* holding the four findings it was correcting; fifteen went, and the result validated, so every gate
|
|
222
|
+
* downstream read a clean run. The CAUSE was that the seat could not send a targeted edit at all — the
|
|
223
|
+
* tool schema required both halves of the call and declared no patch field, while the prompt demanded
|
|
224
|
+
* one. That is fixed at the schema, and a targeted edit cannot remove a finding: an ordinal names one to
|
|
225
|
+
* replace and there is no shape that deletes. This runs underneath, for the whole-document path that
|
|
226
|
+
* remains reachable.
|
|
227
|
+
*
|
|
228
|
+
* REPAIR AND DELIVER, decided under authority the owner delegated in session on 2026-08-27.
|
|
229
|
+
* The three alternatives were weighed and written down: rolling back gives the client every finding but
|
|
230
|
+
* none of the reviewer's corrections — one silent loss traded for another; printing the removals as open
|
|
231
|
+
* points tells the client about a hole instead of filling it; holding the report is against the standing
|
|
232
|
+
* deliver-always ruling. Repair keeps the corrections AND restores what vanished unexplained, so the
|
|
233
|
+
* client gets a complete corrected report and there is no hole to print.
|
|
234
|
+
*
|
|
235
|
+
* WHOLE FROM THE SNAPSHOT, NEVER RE-DERIVED — the owner's condition, and the reason this reads
|
|
236
|
+
* `JSON.parse(pre.raw)` rather than a normalized view. A restored finding is the exact object the
|
|
237
|
+
* reviewer read. Re-deriving one would be this function inventing evidence.
|
|
238
|
+
*
|
|
239
|
+
* NAMED MEANS NAMED BY A FLAG, and both spellings count: a flag that carries `on` names ordinals, and a
|
|
240
|
+
* flag that carries none is matched against the marks the review names. A removal the reviewer asked for
|
|
241
|
+
* stays removed — that is a judgment, and this function has no business reversing it. What it reverses
|
|
242
|
+
* is a removal NOBODY STATED, which is by construction one nobody reviewed.
|
|
243
|
+
*
|
|
244
|
+
* EVERY FIRING IS A DEFECT SIGNAL. After the schema fix this should be zero: the run log carries the
|
|
245
|
+
* event so e2e can assert exactly that, and a non-zero count is a report of the fix not holding rather
|
|
246
|
+
* than of this backstop working.
|
|
247
|
+
*
|
|
248
|
+
* @returns {null | {restoredFindings: {ordinal: *, mark: *}[], restoredKeys: string[], restoredRows: {register: string, key: string}[], leftRemoved: {ordinal: *, mark: *}[]}}
|
|
249
|
+
*/
|
|
250
|
+
export function repairUnnamedRemovals(P, runDir, pre, namedOrdinals, namedMarks, namedLines = []) { // @internal
|
|
251
|
+
if (!pre?.raw) return null; // nothing held — nothing to compare against
|
|
252
|
+
// In the model's numbering: the flags name its ordinals, and a folded record renumbers, so a finding
|
|
253
|
+
// removed from the folded record would shift every ordinal after it (record-fold.mjs).
|
|
254
|
+
let preDoc = null, postDoc = null, postRaw = null;
|
|
255
|
+
try { preDoc = JSON.parse(pre.model?.raw ?? pre.raw); } catch { return null; }
|
|
256
|
+
try { postRaw = readFileSync(modelRecordPath(runDir, P.findings), "utf8"); postDoc = JSON.parse(postRaw); } catch { return null; }
|
|
257
|
+
if (!preDoc || !postDoc || typeof postDoc !== "object") return null;
|
|
258
|
+
|
|
259
|
+
const norm = (s) => String(s ?? "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
260
|
+
const marks = new Set((namedMarks ?? []).map(norm).filter(Boolean));
|
|
261
|
+
const ordinals = new Set((namedOrdinals ?? []).map((o) => String(o)));
|
|
262
|
+
const wasNamed = (f) => ordinals.has(String(f?.ordinal))
|
|
263
|
+
|| [f?.mark, f?.owner?.name].some((n) => { const v = norm(n); return v && marks.has(v); });
|
|
264
|
+
|
|
265
|
+
const preList = Array.isArray(preDoc.findings) ? preDoc.findings : [];
|
|
266
|
+
const postList = Array.isArray(postDoc.findings) ? postDoc.findings : [];
|
|
267
|
+
const held = new Set(postList.map((f) => String(f?.ordinal)));
|
|
268
|
+
const restoredFindings = [], leftRemoved = [];
|
|
269
|
+
for (const f of preList) {
|
|
270
|
+
if (held.has(String(f?.ordinal))) continue;
|
|
271
|
+
(wasNamed(f) ? leftRemoved : restoredFindings).push(f);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// A KEY, NOT A TYPED LIST. Derived by comparing the two documents, so a register added next year is
|
|
275
|
+
// covered the day it exists — a list of key names here would be a second place to remember.
|
|
276
|
+
const restoredKeys = Object.keys(preDoc).filter((k) => !(k in postDoc));
|
|
277
|
+
|
|
278
|
+
// ROWS OF A REGISTER, NOT ONLY WHOLE REGISTERS. A pass rewriting a coverage note or an action sends the
|
|
279
|
+
// complete array in its PATCH, and a patch REPLACES the stored register — so a row the seat left out is
|
|
280
|
+
// a row deleted, and nothing downstream objects unless the slice was a limited one. A row no flag named
|
|
281
|
+
// is restored whole, keyed as `reportLines` keys it; a row the reviewer named stays out, as a named
|
|
282
|
+
// finding does.
|
|
283
|
+
const lineKeys = new Set(namedLines ?? []);
|
|
284
|
+
const restoredRows = [];
|
|
285
|
+
const rowsBack = {};
|
|
286
|
+
for (const [reg, keyOf] of Object.entries(REPORT_LINE_KEY)) {
|
|
287
|
+
if (!Array.isArray(preDoc[reg]) || !Array.isArray(postDoc[reg])) continue;
|
|
288
|
+
const have = new Set(postDoc[reg].map(keyOf));
|
|
289
|
+
const back = preDoc[reg].filter((r) => !have.has(keyOf(r)) && !lineKeys.has(keyOf(r)));
|
|
290
|
+
if (!back.length) continue;
|
|
291
|
+
rowsBack[reg] = back;
|
|
292
|
+
for (const r of back) restoredRows.push({ register: reg, key: keyOf(r), label: REPORT_LINE_LABEL[reg](r) });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (!restoredFindings.length && !restoredKeys.length && !restoredRows.length) return null;
|
|
296
|
+
|
|
297
|
+
// ONE RESTORATION, applied to a record in the model's numbering: the file's here, and the merge base's
|
|
298
|
+
// below. Whatever a record already holds stays as it holds it; only what came back is added.
|
|
299
|
+
const byOrdinal = new Map(preList.map((f, i) => [String(f?.ordinal), i]));
|
|
300
|
+
const restoreInto = (doc) => {
|
|
301
|
+
const merged = { ...doc };
|
|
302
|
+
for (const k of restoredKeys) if (!(k in merged)) merged[k] = preDoc[k];
|
|
303
|
+
for (const [reg, back] of Object.entries(rowsBack)) {
|
|
304
|
+
// In the snapshot's order, the post-pass version of every row it kept, then any row the pass added.
|
|
305
|
+
const keyOf = REPORT_LINE_KEY[reg];
|
|
306
|
+
const now = Array.isArray(doc[reg]) ? doc[reg] : [];
|
|
307
|
+
const post = new Map(now.map((r) => [keyOf(r), r]));
|
|
308
|
+
const restored = new Set(back);
|
|
309
|
+
const inPre = new Set(preDoc[reg].map(keyOf));
|
|
310
|
+
merged[reg] = [
|
|
311
|
+
...preDoc[reg].flatMap((r) => restored.has(r) ? [r] : post.has(keyOf(r)) ? [post.get(keyOf(r))] : []),
|
|
312
|
+
...now.filter((r) => !inPre.has(keyOf(r))),
|
|
313
|
+
];
|
|
314
|
+
}
|
|
315
|
+
if (restoredFindings.length) {
|
|
316
|
+
// Back in the order the reviewer read them, by ordinal — a restored finding appended to the end
|
|
317
|
+
// would be a different document from the one that was correct.
|
|
318
|
+
const list = Array.isArray(doc.findings) ? doc.findings : [];
|
|
319
|
+
const has = new Set(list.map((f) => String(f?.ordinal)));
|
|
320
|
+
merged.findings = [...list, ...restoredFindings.filter((f) => !has.has(String(f?.ordinal)))]
|
|
321
|
+
.sort((a, b) => (byOrdinal.get(String(a?.ordinal)) ?? 0) - (byOrdinal.get(String(b?.ordinal)) ?? 0));
|
|
322
|
+
}
|
|
323
|
+
return merged;
|
|
324
|
+
};
|
|
325
|
+
const merged = restoreInto(postDoc);
|
|
326
|
+
const brief = (f) => ({ ordinal: f?.ordinal ?? null, mark: f?.mark ?? null });
|
|
327
|
+
const record = {
|
|
328
|
+
ts: new Date().toISOString(),
|
|
329
|
+
restoredFindings: restoredFindings.map(brief),
|
|
330
|
+
restoredKeys,
|
|
331
|
+
restoredRows,
|
|
332
|
+
leftRemoved: leftRemoved.map(brief),
|
|
333
|
+
};
|
|
334
|
+
writeFindings(runDir, merged, { why: "unnamed-removals-restored", settles: [] });
|
|
335
|
+
foldAfterSave(runDir, P.findings); // after the seam the repaired record is folded again, as a save's is
|
|
336
|
+
// THE MERGE BASE TAKES THE SAME RESTORATION. The patch that follows (the corrections gate's re-emit) merges
|
|
337
|
+
// onto the base and re-renders the file from it, so a restore written to the file alone is dropped again.
|
|
338
|
+
// The edit is judged as a call is; a refusal leaves the base as it was, and the record says so.
|
|
339
|
+
record.base = rebaseSynthesis(runDir, restoreInto);
|
|
340
|
+
try { atomicWrite(paths(runDir).correctiveRepair, JSON.stringify(record, null, 2) + "\n"); }
|
|
341
|
+
catch { /* sidecar is best-effort; the runLog event is the record that decides */ }
|
|
342
|
+
return record;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function correctionNamedOrdinals(P) {
|
|
346
|
+
const out = [];
|
|
347
|
+
try {
|
|
348
|
+
// `P.reviewFlags`: the pass after a delivery-check repair applies a LATER review's flags, read from that review's own
|
|
349
|
+
// calls. Absent everywhere else, where `readAcceptedFlags` reads the newest accepted call of the review acted on.
|
|
350
|
+
const typed = Array.isArray(P.reviewFlags) ? P.reviewFlags : readAcceptedFlags(P.runDir);
|
|
351
|
+
if (typed) { for (const f of typed) if (Array.isArray(f?.on)) out.push(...f.on); return out; }
|
|
352
|
+
} catch { /* fall through to the rendered parse, exactly as the worklist does */ }
|
|
353
|
+
try {
|
|
354
|
+
const review = existsSync(P.seniorEyeReview) ? readFileSync(P.seniorEyeReview, "utf8") : "";
|
|
355
|
+
for (const r of parseCorrections(review)) if (Array.isArray(r?.ordinals)) out.push(...r.ordinals);
|
|
356
|
+
} catch { /* no ordinals — every removal is then judged by mark alone */ }
|
|
357
|
+
return out;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The non-finding lines the review's flags name or quote, as `reportLines` keys — matched against the
|
|
362
|
+
* PRE-corrective document, for the reason the names are: a removed row is absent from the post file.
|
|
363
|
+
*
|
|
364
|
+
* ── THIS JOIN DECIDES A RESTORATION, AND ITS TWO FAILURE DIRECTIONS ARE OPPOSITE ─────────────────────
|
|
365
|
+
*
|
|
366
|
+
* `linesOf` applies no correction anywhere — but these keys become `namedLines`, and `repairUnnamedRemovals`
|
|
367
|
+
* keeps a removed row OUT when its key is among them. So a prose match decides whether a row the pass
|
|
368
|
+
* deleted comes back:
|
|
369
|
+
*
|
|
370
|
+
* a MISS → the row is restored although the reviewer asked for it to go: the driver overrides a
|
|
371
|
+
* judgment that was made, and the reviewer sees it named as restored and can say so again.
|
|
372
|
+
* a FALSE HIT → an accidental deletion stays deleted: the row leaves the client's report and the
|
|
373
|
+
* restored-lines section says nothing, because the driver believed it was asked for.
|
|
374
|
+
*
|
|
375
|
+
* The second is the worse one and it is the same bet the backstop already makes by mark for findings.
|
|
376
|
+
* What keeps it bounded is that the reviewer is told: every restored row prints in the re-read section,
|
|
377
|
+
* so an override is visible, and a flag whose wording missed still leaves its own row in the observation
|
|
378
|
+
* table as unresolved. `namesLine` wants the label's shape — "the coverage line for <area>" — so a flag
|
|
379
|
+
* writing "the US coverage note" misses unless it also quoted eight running words of the line.
|
|
380
|
+
*/
|
|
381
|
+
export function correctionNamedLines(P, doc0) {
|
|
382
|
+
try {
|
|
383
|
+
const review = existsSync(P.seniorEyeReview) ? readFileSync(P.seniorEyeReview, "utf8") : "";
|
|
384
|
+
const lines = reportLines(doc0);
|
|
385
|
+
// A flag that declared its parts by address is bound to those; only a flag that declared none is matched by its prose.
|
|
386
|
+
return [...new Set(parseCorrections(review).flatMap((r) => (Array.isArray(r?.lines) && r.lines.length ? r.lines
|
|
387
|
+
: linesOf(r?.text, lines).map((l) => l.key))))];
|
|
388
|
+
} catch { return []; } // no review read — every row removal is then unnamed, and restored
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @param {*} doc0 the findings document to match the review's names against. DEFAULTS to the file on
|
|
393
|
+
* disk, which is right for the staleness check — but WRONG for judging a removal: a finding that was
|
|
394
|
+
* removed is not in the post-pass document, so its mark could never be found there and every named
|
|
395
|
+
* removal would read as unnamed. The repair path passes the PRE-corrective document for that reason.
|
|
396
|
+
*/
|
|
397
|
+
export function correctionNamedSet(P, doc0 = null) {
|
|
398
|
+
const review = existsSync(P.seniorEyeReview) ? readFileSync(P.seniorEyeReview, "utf8") : "";
|
|
399
|
+
let doc = doc0;
|
|
400
|
+
if (!doc) { try { doc = parseFindingsJsonLenient(readFileSync(P.findings, "utf8")); } catch { return []; } }
|
|
401
|
+
const norm = (s) => String(s ?? "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
402
|
+
const known = new Map();
|
|
403
|
+
for (const f of doc?.findings ?? []) {
|
|
404
|
+
for (const name of [f.mark, f.owner?.name]) { const n = norm(name); if (n) known.set(n, name); }
|
|
405
|
+
}
|
|
406
|
+
const named = new Set();
|
|
407
|
+
for (const tok of properNameCandidates(review)) {
|
|
408
|
+
const n = norm(tok);
|
|
409
|
+
for (const [k, orig] of known) if (n && (k === n || k.includes(n) || n.includes(k))) named.add(orig);
|
|
410
|
+
}
|
|
411
|
+
return [...named];
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* THE TRUSTED STATE BEFORE THE CORRECTION AFTER A POST-REPAIR REVIEW, for its rollback, from the first source that
|
|
416
|
+
* stands, in this order:
|
|
417
|
+
* 1. the findings record as it stands, with its fold, narrative and base (the usual snapshot);
|
|
418
|
+
* 2. the state kept whole before the review (`retainStateBeforeReview`), byte for byte;
|
|
419
|
+
* 3. the save the review read (`before`, read before the correction starts), rebuilt through the driver's own
|
|
420
|
+
* acceptance, never from a save the correction may write afterwards;
|
|
421
|
+
* 4. the save kept from before the delivery-check repair, rebuilt the same way.
|
|
422
|
+
* A save that the run's CURRENT duty refuses is not lost: it was accepted when it was made, and the records owed since
|
|
423
|
+
* are evidence added later. It is rebuilt with the duty set aside and marked so (`duty: "relaxed"`); once the correction
|
|
424
|
+
* settles, the writer's duty is judged again on the record that stands, and names what it leaves unaccounted in the
|
|
425
|
+
* approved sentence. A save that cannot be read, or that
|
|
426
|
+
* the acceptance refuses for anything else, is not a source. Null only when none of the four stands. Never throws.
|
|
427
|
+
*/
|
|
428
|
+
function trustedStateBeforeCorrection(Pv, runDir, before) {
|
|
429
|
+
const held = snapshotFindingsForCorrections(Pv, runDir);
|
|
430
|
+
if (held) return held;
|
|
431
|
+
const sha = (t) => createHash("sha256").update(t).digest("hex");
|
|
432
|
+
try {
|
|
433
|
+
const k = JSON.parse(readFileSync(postRepairStatePath(runDir), "utf8"));
|
|
434
|
+
if (typeof k?.findings === "string" && typeof k.narrative === "string" && typeof k.accepted === "string") {
|
|
435
|
+
const h = sha(k.findings);
|
|
436
|
+
return { raw: k.findings, sha: h, model: { raw: k.findings, sha: h }, fold: k.fold ?? null,
|
|
437
|
+
base: { accepted: k.accepted, narrative: k.narrative }, from: "state-before-the-review" };
|
|
438
|
+
}
|
|
439
|
+
} catch { /* no state kept, or it does not read: the saves below */ }
|
|
440
|
+
return recordFromTheSaves(Pv, runDir, before);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* A FAILED CORRECTION AFTER A POST-REPAIR REVIEW NEVER ENDS THE RUN (the owner's ruling of 2026-10-19: a run is never
|
|
445
|
+
* held). The trusted state comes back whole: the record, its narrative and the merge base, then the fold and the seam's
|
|
446
|
+
* writes made again over a record rebuilt from a save, as after any save, so the delivered verdict is derived from the
|
|
447
|
+
* record that stands. The correction's points stay in the run's open-questions record. A rate-limited correction is
|
|
448
|
+
* not waited for either: it is rolled back as a failed one is, since the report it would correct is already reviewed,
|
|
449
|
+
* and waiting for the reset would hold the run.
|
|
450
|
+
*
|
|
451
|
+
* WITH NO TRUSTED STATE, THIS PASS DOES NOT DELIVER THE ASSESSMENT. That is the precise limit: the record, the state
|
|
452
|
+
* kept whole before the review, the save the review read and the save kept from before the repair are all unreadable
|
|
453
|
+
* or refused, a storage failure. Nothing the failed pass wrote is adopted: the narrative and the base
|
|
454
|
+
* go back to what they were, and the failed pass's record is set aside under `_driver/` as evidence. A pass that went on from there delivered a
|
|
455
|
+
* report with no findings, labelled with the verdict as it stood (measured on the mock pipeline, 2026-10-19): a clear
|
|
456
|
+
* result over a record nobody can read. So the failure is the assessment not completed (parts-not-completed.mjs): once
|
|
457
|
+
* its recovery is spent, the run delivers what it holds without the assessment. Returns the rollback record, or null
|
|
458
|
+
* for this case.
|
|
459
|
+
*/
|
|
460
|
+
async function recoverFromFailedCorrection(ctx, Pv, runDir, pre, pass, { baseBefore, findingsBefore }) {
|
|
461
|
+
// A rate limit is a failure of this pass like any other here: the shared rollback would leave it to wait.
|
|
462
|
+
const failure = pass?.fail === "rate_limited" || pass?.resetsAt ? { fail: "rate_limited, not waited for" } : pass;
|
|
463
|
+
if (pre?.raw) {
|
|
464
|
+
const rollback = rollbackCorrectivePass(Pv, runDir, pre, failure);
|
|
465
|
+
if (rollback && pre.from) rollback.from = pre.from;
|
|
466
|
+
if (rollback && pre.duty) rollback.duty = pre.duty;
|
|
467
|
+
if (rollback && (pre.from === "accepted-save" || pre.from === "save-before-the-repair")) {
|
|
468
|
+
// A record rebuilt from a save is folded, and given the seam's writes, as the save itself was.
|
|
469
|
+
try { foldAfterSave(runDir, Pv.findings); } catch (e) { note(`[post-repair] the restored record could not be folded (${String(e?.message ?? e).slice(0, 100)})`); }
|
|
470
|
+
try { await ctx.afterSynthesisSave?.(); } catch (e) { note(`[post-repair] the seam's writes could not be made again over the restored record (${String(e?.message ?? e).slice(0, 100)})`); }
|
|
471
|
+
}
|
|
472
|
+
return rollback;
|
|
473
|
+
}
|
|
474
|
+
// NO TRUSTED STATE: nothing the failed pass wrote is adopted, and the pass ends as it always did.
|
|
475
|
+
const base = restoreSynthesisBase(runDir, baseBefore);
|
|
476
|
+
let findings = "unchanged";
|
|
477
|
+
if (!findingsBefore) {
|
|
478
|
+
let now = null;
|
|
479
|
+
try { now = readFileSync(Pv.findings, "utf8"); } catch { now = null; }
|
|
480
|
+
// Set aside, never deleted: the failed pass's record stays beside the run's record for whoever diagnoses the run.
|
|
481
|
+
if (now != null) {
|
|
482
|
+
try { renameSync(Pv.findings, paths(runDir).findingsFailedCorrection); findings = "set-aside"; }
|
|
483
|
+
catch { try { rmSync(Pv.findings, { force: true }); findings = "removed"; } catch { findings = "failed"; } }
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
runLog(runDir, { event: "post-repair-correction-unrecoverable", reason: String(failure?.fail ?? "failed").slice(0, 200), findings, ...(base ? { base } : {}) });
|
|
487
|
+
note(`[post-repair] the correction after the review of the repair failed with no trusted state to restore (the record and both saves unreadable) — nothing it wrote is kept, and this pass does not deliver a report without its record`);
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* The one correction after that review: every accepted point goes to it, whatever its class, and nothing
|
|
493
|
+
* reviews it again. It runs the first correction's own backstops — the rollback, the put-back of a removal no
|
|
494
|
+
* flag named, the follow-up when a correction missed the findings — on a view of the run's paths that points at
|
|
495
|
+
* the review after the repair, and records what each flag led to beside the first correction's record.
|
|
496
|
+
*/
|
|
497
|
+
export async function runPostRepairCorrection(ctx, P, run, { rec, items, points, grounds = false, whole = false, synthesisRef }) {
|
|
498
|
+
const runDir = run.runDir;
|
|
499
|
+
const Pv = { ...P, seniorEyeReview: reviewAfterRepairPath(runDir), correctionsApplied: postRepairCorrectionsPath(runDir), reviewFlags: rec.flags };
|
|
500
|
+
const named = [...new Set(points.filter((x) => x.target.kind !== "none").map((x) => x.target.label))];
|
|
501
|
+
const rows = rec.flags.map((f, i) => ({ n: i + 1, kind: f.kind, text: f.text, fix: f.fix ?? null, ordinals: flagOrdinals(f) }));
|
|
502
|
+
const review = readFileSync(Pv.seniorEyeReview, "utf8");
|
|
503
|
+
const rulingsTail = extractRulingsTail(existsSync(P.placement) ? readFileSync(P.placement, "utf8") : "");
|
|
504
|
+
// The writer's own record, in the numbering of the items and of the patch, while the delivery fold is in force.
|
|
505
|
+
const followup = repairFollowup("synthesis:post-repair-corrective", {
|
|
506
|
+
narrative: P.narrative, findings: modelRecordPath(runDir, P.findings), placement: P.placement, rulingsTail,
|
|
507
|
+
items: named, renumbered: anyRenumbered(items), worklist: correctionsWorklist(rows, { afterRepair: true }), review, whole,
|
|
508
|
+
});
|
|
509
|
+
const before = lastAcceptedCall(runDir);
|
|
510
|
+
// What stood before the correction, held before it can alter any of it: the files as they are, for a pass that
|
|
511
|
+
// fails with no trusted state to restore, and the trusted state itself.
|
|
512
|
+
const baseBefore = snapshotSynthesisBase(runDir);
|
|
513
|
+
const findingsBefore = (() => { try { readFileSync(Pv.findings); return true; } catch { return false; } })();
|
|
514
|
+
const pre = trustedStateBeforeCorrection(Pv, runDir, before);
|
|
515
|
+
prepareDeclinationSpec(ctx, P);
|
|
516
|
+
const pass = await stage("synthesis", ctx, { force: true, followup: followup + stageCharter("synthesis", ctx.depth, ctx.framework), sessionKey: synthesisRef.key,
|
|
517
|
+
model: synthesisRef.model, thinking: synthesisRef.thinking, trigger: "post-repair-corrective" });
|
|
518
|
+
recordSynthesisSeam(ctx, pass, "post-repair-corrective");
|
|
519
|
+
const rollback = pass.ok ? null : await recoverFromFailedCorrection(ctx, Pv, runDir, pre, pass, { baseBefore, findingsBefore });
|
|
520
|
+
if (rollback) {
|
|
521
|
+
runLog(runDir, { event: "corrective-rollback", reason: rollback.reason, restored: rollback.restored, pass: "post-repair", from: rollback.from ?? "record",
|
|
522
|
+
...(rollback.duty ? { duty: rollback.duty } : {}) });
|
|
523
|
+
note(`[post-repair] the correction after the review of the repair failed (${rollback.reason}) — the record it started from is back, and the run delivers with the points recorded`);
|
|
524
|
+
} else {
|
|
525
|
+
await asPartNotCompleted("assessment", async () => must(pass, "synthesis(post-repair)"));
|
|
526
|
+
let preDocForNames = null;
|
|
527
|
+
try { preDocForNames = pre ? parseFindingsJsonLenient(pre.raw) : null; } catch { /* fall back to the file */ }
|
|
528
|
+
const repaired = repairUnnamedRemovals(Pv, runDir, pre, correctionNamedOrdinals(Pv), correctionNamedSet(Pv, preDocForNames), correctionNamedLines(Pv, preDocForNames));
|
|
529
|
+
if (repaired) runLog(runDir, removalRepairedRow(repaired));
|
|
530
|
+
await enforceCorrectionsReachFindings(ctx, Pv, pre, { synthesisKey: synthesisRef.key, synthesisModel: synthesisRef.model, synthesisThinking: synthesisRef.thinking });
|
|
531
|
+
}
|
|
532
|
+
let applied = null;
|
|
533
|
+
try {
|
|
534
|
+
const preDoc = pre ? parseFindingsJsonLenient(pre.model?.raw ?? pre.raw) : null;
|
|
535
|
+
let postDoc = null;
|
|
536
|
+
try { postDoc = parseFindingsJsonLenient(readFileSync(modelRecordPath(runDir, P.findings), "utf8")); } catch { /* shape defects ride the normal ladder */ }
|
|
537
|
+
const after = lastAcceptedCall(runDir);
|
|
538
|
+
const sections = points.filter((x) => x.target.kind === "section").map((x) => {
|
|
539
|
+
const sec = NARRATIVE_PROSE.find((y) => y.key === x.target.key);
|
|
540
|
+
return { n: x.n, label: x.target.label, before: sectionText(sec?.read(before?.narrative)), after: sectionText(sec?.read(after?.narrative)) };
|
|
541
|
+
});
|
|
542
|
+
applied = buildCorrectionsApplied(rows, preDoc, postDoc, { sections });
|
|
543
|
+
// `grounds`: the review these rows answer hardened the run's verdict, so its points are that verdict's grounds.
|
|
544
|
+
atomicWrite(Pv.correctionsApplied, JSON.stringify({ ts: new Date().toISOString(), pass: "post-repair", ...(grounds ? { grounds: true } : {}),
|
|
545
|
+
rows: applied, classes: points.map((x) => ({ n: x.n, class: x.class, target: x.target.label })) }, null, 2) + "\n");
|
|
546
|
+
const outcomes = applied.reduce((a, x) => ((a[x.outcome] = (a[x.outcome] ?? 0) + 1), a), {});
|
|
547
|
+
runLog(runDir, { event: "post-repair-fix-pass", handed: rows.length, ok: Boolean(pass.ok), rolledBack: Boolean(rollback), outcomes });
|
|
548
|
+
} catch (e) {
|
|
549
|
+
note(`[post-repair] the observation of the correction could not be built (${String(e?.message ?? e).slice(0, 100)}) — its points print as not checked`);
|
|
550
|
+
runLog(runDir, { event: "post-repair-fix-pass", handed: rows.length, ok: Boolean(pass.ok), rolledBack: Boolean(rollback), observation: false });
|
|
551
|
+
}
|
|
552
|
+
return { ran: true, ok: Boolean(pass.ok), rollback, applied };
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// `resume.correction` is the first correction's (see its dispatch), handed on by that caller alone: the correction after
|
|
556
|
+
// the review of a repair shares this follow-up and is handed no positions.
|
|
557
|
+
/**
|
|
558
|
+
* The findings and other parts the review's flags declare, by the names a reader is given: a finding's mark or owner, or
|
|
559
|
+
* "finding N" when it has neither, and a part's label from the address list. IMPURE (reads the run).
|
|
560
|
+
*/
|
|
561
|
+
function correctionDeclaredNames(P, pre) {
|
|
562
|
+
try {
|
|
563
|
+
let doc = null;
|
|
564
|
+
try { doc = pre ? parseFindingsJsonLenient(pre.model?.raw ?? pre.raw) : null; } catch { doc = null; }
|
|
565
|
+
const review = existsSync(P.seniorEyeReview) ? readFileSync(P.seniorEyeReview, "utf8") : "";
|
|
566
|
+
const rows = correctionRows(P, review, Array.isArray(P.reviewFlags) ? P.reviewFlags : readAcceptedFlags(P.runDir));
|
|
567
|
+
const byOrd = new Map((doc?.findings ?? []).map((f) => [f?.ordinal, f]));
|
|
568
|
+
const labels = new Map((listedAddresses(P.runDir)?.lines ?? []).map((l) => [l.address, l.label]));
|
|
569
|
+
return rows.flatMap((r) => [
|
|
570
|
+
...(Array.isArray(r?.ordinals) ? r.ordinals : []).map((o) => { const f = byOrd.get(o); return f?.mark ?? f?.owner?.name ?? `finding ${o}`; }),
|
|
571
|
+
...(Array.isArray(r?.lines) ? r.lines : []).map((a) => labels.get(a) ?? a)]);
|
|
572
|
+
} catch { return []; } // nothing declared can be read — the prose names stand alone, as before
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export async function enforceCorrectionsReachFindings(ctx, P, pre, resume) {
|
|
576
|
+
if (!pre) return; // no findings.json before the pass — nothing to enforce
|
|
577
|
+
const { run } = ctx;
|
|
578
|
+
// What the review's prose names, and what its flags declare: a target either way counts, so the hold below never fires
|
|
579
|
+
// less often than it did on the prose alone.
|
|
580
|
+
const named = [...new Set([...correctionNamedSet(P), ...correctionDeclaredNames(P, pre)])];
|
|
581
|
+
const readState = () => {
|
|
582
|
+
let raw = null, corrections = null;
|
|
583
|
+
// the record the model wrote: a change the fold hides is still a change it made (record-fold.mjs)
|
|
584
|
+
try { raw = readFileSync(modelRecordPath(run.runDir, P.findings), "utf8"); } catch { return { stale: false }; }
|
|
585
|
+
try { corrections = parseFindingsJsonLenient(raw).corrections; } catch { /* shape defects ride the normal ladder */ }
|
|
586
|
+
const sha = createHash("sha256").update(raw).digest("hex");
|
|
587
|
+
return { stale: named.length > 0 && sha === (pre.model?.sha ?? pre.sha) && !(corrections && corrections.applied), sha };
|
|
588
|
+
};
|
|
589
|
+
if (!readState().stale) return answerFollowsCorrection(ctx, P, pre, resume);
|
|
590
|
+
note(`[corrections] findings.json unchanged after the corrective pass (review names: ${named.join(", ")}) — demanding the re-emit`);
|
|
591
|
+
await stage("synthesis", ctx, {
|
|
592
|
+
force: true, sessionKey: resume.synthesisKey, model: resume.synthesisModel, thinking: resume.synthesisThinking,
|
|
593
|
+
trigger: "corrective-findings",
|
|
594
|
+
...(resume.correction ? { correction: resume.correction } : {}),
|
|
595
|
+
// The writer's own record while a fold is in force, as the correction's own message names it (`correctionsExtra`).
|
|
596
|
+
followup: repairFollowup("synthesis:corrective-findings", { findings: modelRecordPath(run.runDir, P.findings), named, seniorEyeReview: P.seniorEyeReview, adds: Boolean(resume.correction) }) + stageCharter("synthesis", ctx.depth, ctx.framework),
|
|
597
|
+
});
|
|
598
|
+
if (readState().stale) {
|
|
599
|
+
runLog(run.runDir, { event: "corrective-findings-stale", named });
|
|
600
|
+
note(`[corrections] findings.json STILL stale — internal report ships; client export will hold (corrections-state)`);
|
|
601
|
+
try {
|
|
602
|
+
const tmp = paths(run.runDir).correctionsStateJson;
|
|
603
|
+
writeFileSync(tmp, JSON.stringify({ ts: new Date().toISOString(), stale: named }, null, 2));
|
|
604
|
+
renameSync(tmp, paths(run.runDir).correctionsState);
|
|
605
|
+
} catch { /* sidecar is best-effort; the runLog event stands */ }
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// THE ANSWERS FOLLOW THE FINDINGS THEY NAME, asked once, as the gate's one repair. A correction that moved findings an
|
|
610
|
+
// answer citing findings may depend on (`answersLeftBehind`) is handed those findings and the answers that may miss them.
|
|
611
|
+
// The writer updates the answers that depend on them or says why not in the corrections note; nothing is forced. Run
|
|
612
|
+
// only where the findings did reach the record: where they did not, the re-emit above is the one repair, and it may
|
|
613
|
+
// update the answers in the same PATCH. What remains afterwards is recorded, not judged; the recheck reads the answers.
|
|
614
|
+
async function answerFollowsCorrection(ctx, P, pre, resume) {
|
|
615
|
+
const { run } = ctx;
|
|
616
|
+
const leftBehind = () => {
|
|
617
|
+
try {
|
|
618
|
+
return answersLeftBehind(JSON.parse(pre.model?.raw ?? pre.raw), JSON.parse(readFileSync(modelRecordPath(run.runDir, P.findings), "utf8")),
|
|
619
|
+
ctx.framework?.bands);
|
|
620
|
+
} catch { return []; } // an unreadable record is the ladder's business, not this check's
|
|
621
|
+
};
|
|
622
|
+
const answers = leftBehind();
|
|
623
|
+
if (!answers.length) return;
|
|
624
|
+
runLog(run.runDir, { event: "corrective-answers-left-behind", answers });
|
|
625
|
+
note(`[corrections] ${answers.length} answer(s) in four_answers may miss findings the correction moved (${answers.map((a) => a.answer).join(", ")}) — asking once`);
|
|
626
|
+
await stage("synthesis", ctx, {
|
|
627
|
+
force: true, sessionKey: resume.synthesisKey, model: resume.synthesisModel, thinking: resume.synthesisThinking,
|
|
628
|
+
trigger: "corrective-answers",
|
|
629
|
+
followup: repairFollowup("synthesis:corrective-answers", { findings: modelRecordPath(run.runDir, P.findings), answers }) + stageCharter("synthesis", ctx.depth, ctx.framework),
|
|
630
|
+
});
|
|
631
|
+
const still = leftBehind();
|
|
632
|
+
runLog(run.runDir, { event: "corrective-answers-after", answers: still });
|
|
633
|
+
if (still.length) note(`[corrections] ${still.map((a) => a.answer).join(", ")} still name(s) the findings as before — recorded; any reason the writer gave is in the corrections note, and the recheck reads the answers`);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/** Keep the basis at the corrective pass, from the two records the applied table was built from. Throws on a write failure; the caller is never-kill. */
|
|
637
|
+
export function recordCorrectionsBasis(runDir, rows, preDoc, postDoc) { // @internal
|
|
638
|
+
const basis = correctionTargets(rows, preDoc, postDoc);
|
|
639
|
+
atomicWrite(driverDir(runDir, CORRECTIONS_DELIVERED_FILE), JSON.stringify({
|
|
640
|
+
_provenance: "whether each reviewer correction reached the record the report was built from: the basis is kept at the corrective pass, and every assembly reads it against the delivered record (corrections-delivered.mjs)",
|
|
641
|
+
basisAt: new Date().toISOString(), basis,
|
|
642
|
+
}, null, 2) + "\n");
|
|
643
|
+
return basis;
|
|
644
|
+
}
|