@sema-agent/core 7.62.0 → 7.64.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/CHANGELOG.md +936 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.js +102 -54
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-queries.d.ts +50 -4
- package/dist/core/checkpoint-queries.js +42 -17
- package/dist/core/checkpoint-requirements.d.ts +3 -3
- package/dist/core/checkpoint-requirements.js +2 -1
- package/dist/core/checkpoint-row-verdict.d.ts +15 -4
- package/dist/core/checkpoint-row-verdict.js +22 -2
- package/dist/core/checkpoint-store.d.ts +28 -11
- package/dist/core/checkpoint-store.js +45 -4
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/context-settings.d.ts +40 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +27 -7
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +43 -5
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +28 -0
- package/dist/core/file-history-store.js +48 -5
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +2 -0
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +17 -3
- package/dist/core/leg-identity.d.ts +19 -1
- package/dist/core/leg-identity.js +12 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +74 -10
- package/dist/core/memory-engine/consolidation.js +183 -11
- package/dist/core/memory-engine/control-objects.d.ts +25 -0
- package/dist/core/memory-engine/control-objects.js +151 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
- package/dist/core/memory-engine/control-plane-adoption.js +159 -0
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +58 -40
- package/dist/core/memory-engine/delegation-settlement.js +270 -85
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +11 -7
- package/dist/core/memory-engine/engine.d.ts +136 -58
- package/dist/core/memory-engine/engine.js +491 -394
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +62 -60
- package/dist/core/memory-engine/file-backend.js +122 -198
- package/dist/core/memory-engine/index.d.ts +8 -7
- package/dist/core/memory-engine/index.js +7 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +127 -46
- package/dist/core/memory-engine/layout.js +264 -109
- package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
- package/dist/core/memory-engine/memory-backend-contract.js +476 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
- package/dist/core/memory-engine/memory-deployment.js +54 -15
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +68 -9
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +37 -2
- package/dist/core/memory-engine/session-write-home.js +38 -11
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +155 -19
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/stations.d.ts +20 -1
- package/dist/core/mods/stations.js +21 -2
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +26 -8
- package/dist/core/permission-rule-consent.js +76 -36
- package/dist/core/permission-rule-store.d.ts +72 -13
- package/dist/core/permission-rule-store.js +29 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/retention.d.ts +180 -10
- package/dist/core/retention.js +45 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/classifier-ladder.d.ts +7 -1
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +39 -11
- package/dist/core/runner/delegation-owner.d.ts +10 -3
- package/dist/core/runner/delegation-owner.js +4 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +13 -4
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
- package/dist/core/runner/memory-consolidation-driver.js +12 -9
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/person-path-rows.d.ts +8 -3
- package/dist/core/runner/person-path-rows.js +5 -1
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-ask-lane.js +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
- package/dist/core/runner/prepare-gate-stations.js +5 -5
- package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
- package/dist/core/runner/prepare-hands-readface.js +5 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
- package/dist/core/runner/prepare-inherited-gate.js +12 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +7 -2
- package/dist/core/runner/prepare-memory.js +41 -39
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-policy-chain.js +7 -7
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.js +26 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +9 -5
- package/dist/core/runner/run-notification-lane.js +22 -22
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +7 -3
- package/dist/core/secret-env.d.ts +1 -1
- package/dist/core/secret-env.js +4 -4
- package/dist/core/session-checkout.d.ts +168 -0
- package/dist/core/session-checkout.js +579 -0
- package/dist/core/session-store.d.ts +12 -4
- package/dist/core/session-store.js +23 -3
- package/dist/core/session.d.ts +16 -2
- package/dist/core/session.js +3 -0
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/store-contracts/session-store-contract.js +39 -0
- package/dist/core/task-event.d.ts +30 -5
- package/dist/core/task-notification.d.ts +119 -32
- package/dist/core/task-notification.js +186 -100
- package/dist/core/task-registry-agent.d.ts +25 -2
- package/dist/core/task-registry-agent.js +56 -22
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry.d.ts +33 -9
- package/dist/core/task-registry.js +36 -18
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +27 -2
- package/dist/core/tool-errors.d.ts +14 -6
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +32 -13
- package/dist/core/tool-policy.js +27 -17
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +67 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +30 -1
- package/dist/engine/session/session.js +48 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.js +12 -7
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +8 -1
- package/dist/orchestration/run-workflow-tool.js +8 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -2
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +11 -1
- package/dist/stores/file/index.js +7 -11
- package/dist/stores/file/permission-rule-store.d.ts +23 -0
- package/dist/stores/file/permission-rule-store.js +75 -7
- package/dist/stores/file/session-store.js +2 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/bash-program-position.js +3 -3
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +28 -3
- package/dist/tools/fs/read-deny.js +18 -2
- package/dist/tools/fs/removal-targets.js +3 -3
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +8 -1
- package/dist/tools/fs/shell-read-argv.js +34 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
- package/dist/tools/fs/shell-read-bindings.js +5 -1
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +16 -14
- package/dist/tools/fs/shell-read-establish.js +23 -16
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-plan.d.ts +10 -0
- package/dist/tools/fs/shell-read-plan.js +189 -93
- package/dist/tools/fs/shell-read-start.d.ts +19 -9
- package/dist/tools/fs/shell-read-start.js +20 -12
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
- package/dist/tools/fs/shell-read-workdir.js +73 -12
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +135 -11
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
|
@@ -8,10 +8,10 @@ import { inlineUntrusted } from "../untrusted-text.js";
|
|
|
8
8
|
import { ambiguousOriginRepresentation, committedDistilledOf, committedOriginOf, computeEntryRev, distilledEquals, entryFromFile, isValidEntryId, originEquals, parseEntryFile, serializeEntryFile } from "./frontmatter.js";
|
|
9
9
|
import { convertV1SidecarKeys } from "./delegation-settlement.js";
|
|
10
10
|
import { layerObservationLookup, observedDivergenceNotice } from "./layer-observations.js";
|
|
11
|
-
import { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, scanEntryFiles } from "./entry-scan.js";
|
|
12
|
-
import { ControlPlaneCorruptError, CURSORS_FILE, QUARANTINE_DIR,
|
|
11
|
+
import { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, carriesEntry, scanEntryFiles } from "./entry-scan.js";
|
|
12
|
+
import { ControlPlaneCorruptError, CURSORS_FILE, QUARANTINE_DIR, STRICT_CONTROL_PLANE_LEDGERS, fileGovernanceDocOf, IMPORT_RECEIPTS_DIR, SESSION_POLLUTION_DIR, appendChallengeEvents, atomicWriteFileSync, quarantineAndTombstone, captureAndClearLineageForEntries, adoptRootScopeLayout, anchorStoreRoot, effectiveControlRootOf, ensureDirExists, LEDGER_FILE, sayAnnounceFailure, enqueueMemoryAnnouncement, importLatchTxnId, importLineageCommitted, importSessionPollution, isContainedIn, lockedStrictUpdate, readStrictSidecar, permissionRemedyOf, withPermissionRemedy, lineageContributionsOfSession, listSessionPollution, readChallengeEvents, readLineageRecord, registerScope, registeredScopes, releaseImportLatch, layoutNeedsAdoption, scopeDirFor, scopeDirName, scopeRegistryShape, stageImportLatch, landsOutsideStore, storeActRefusal, storeRootMovedRefusal, writeAllSync, STORE_JOURNAL_FILE, ERASURE_SWEEP_RECORD_FILE, ERASURE_SWEEP_RECORD_WHAT, coerceErasureSweepRecord, erasureSweepOwedAt, erasureSweepRecordPathOf, STORE_TXN_LOCK_DIR, TXN_LOCK_STALE_MS, acquireStoreTxnLock, assertStoreTxnLockOwnership, renewStoreTxnLock, tryStoreTxnLock, } from "./layout.js";
|
|
13
13
|
import { screenInboundEntries } from "./data-plane.js";
|
|
14
|
-
import { CONSOLIDATION_DRIVER_PLANS_DIR, CONSOLIDATION_PLANS_DIR } from "./consolidation.js";
|
|
14
|
+
import { CONSOLIDATION_DRIVER_PLANS_DIR, CONSOLIDATION_PLANS_DIR, fileGovernanceStore } from "./consolidation.js";
|
|
15
15
|
import { canonicalExpectedScopes, expectedScopesInvalid, firstOutsideExpectedScopes } from "./export-bundle.js";
|
|
16
16
|
import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
|
|
17
17
|
import { admittingLandings, cutPerLanding, LandingsNeedAdmission, requireLandingsAdmitted } from "./landing-admission.js";
|
|
@@ -169,7 +169,6 @@ class AuditSnapshotContendedError extends Error {
|
|
|
169
169
|
class AuditObservationUnstableError extends Error {
|
|
170
170
|
}
|
|
171
171
|
const LEDGER_SCHEMA_VERSION = 2;
|
|
172
|
-
const LEDGER_V1_BACKUP_FILE = "revs.v1.json.bak";
|
|
173
172
|
const TRANSFERS_FILE = "transfers.jsonl";
|
|
174
173
|
const CHAIN_DEGRADED_FILE = "transfers.chain-degraded.json";
|
|
175
174
|
const SHADOW_DIR = "shadow";
|
|
@@ -281,33 +280,22 @@ function parseJournal(raw, jp) {
|
|
|
281
280
|
throw new ControlPlaneCorruptError(`transaction journal is unparseable: ${jp}`);
|
|
282
281
|
}
|
|
283
282
|
}
|
|
283
|
+
const V1_LEDGER_FORM_REFUSED = "the pre-binding v1 form (a bare id → rev map), which this engine does not read — open the store once with an engine at or below 7.63.0, whose locked migration upgrades it to the v2 envelope";
|
|
284
284
|
function journalLedgerSnapshot(journal, jp) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return { form: "v2", rows: validateLedgerRowsV2(env.rows, jp), extras };
|
|
300
|
-
}
|
|
301
|
-
const map = journal.ledger;
|
|
302
|
-
if (!map || typeof map !== "object" || Array.isArray(map))
|
|
303
|
-
throw new ControlPlaneCorruptError(`transaction journal ledger snapshot has the wrong shape: ${jp}`);
|
|
304
|
-
const rows = Object.create(null);
|
|
305
|
-
for (const [id, rev] of Object.entries(map)) {
|
|
306
|
-
if (typeof rev !== "string")
|
|
307
|
-
throw new ControlPlaneCorruptError(`transaction journal v1 ledger snapshot entry ${JSON.stringify(id)} is not a string: ${jp}`);
|
|
308
|
-
rows[id] = { rev };
|
|
309
|
-
}
|
|
310
|
-
return { form: "v1", rows };
|
|
285
|
+
if (journal.ledger !== undefined) {
|
|
286
|
+
throw new ControlPlaneCorruptError(`transaction journal carries its ledger snapshot in ${V1_LEDGER_FORM_REFUSED}: ${jp}`);
|
|
287
|
+
}
|
|
288
|
+
const env = journal.ledger2;
|
|
289
|
+
if (env === undefined)
|
|
290
|
+
throw new ControlPlaneCorruptError(`transaction journal has no ledger snapshot (wrong shape): ${jp}`);
|
|
291
|
+
if (!env || typeof env !== "object" || Array.isArray(env) || env.v !== LEDGER_SCHEMA_VERSION) {
|
|
292
|
+
throw new ControlPlaneCorruptError(`transaction journal ledger2 snapshot has the wrong shape: ${jp}`);
|
|
293
|
+
}
|
|
294
|
+
const extras = {};
|
|
295
|
+
for (const [k, val] of Object.entries(env))
|
|
296
|
+
if (k !== "v" && k !== "rows")
|
|
297
|
+
extras[k] = val;
|
|
298
|
+
return { rows: validateLedgerRowsV2(env.rows, jp), extras };
|
|
311
299
|
}
|
|
312
300
|
function parseLedgerText(raw, path) {
|
|
313
301
|
let parsed;
|
|
@@ -321,33 +309,47 @@ function parseLedgerText(raw, path) {
|
|
|
321
309
|
throw new ControlPlaneCorruptError(`committed-rev ledger has the wrong shape: ${path}`);
|
|
322
310
|
}
|
|
323
311
|
const rec = parsed;
|
|
324
|
-
if ("v" in rec) {
|
|
325
|
-
|
|
326
|
-
if (typeof v !== "number" || !Number.isInteger(v)) {
|
|
327
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger schema version is not an integer: ${path}`);
|
|
328
|
-
}
|
|
329
|
-
if (v > LEDGER_SCHEMA_VERSION) {
|
|
330
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger schema v${v} is newer than this engine supports (v${LEDGER_SCHEMA_VERSION}) — refusing to reinterpret it: ${path}`);
|
|
331
|
-
}
|
|
332
|
-
if (v !== LEDGER_SCHEMA_VERSION) {
|
|
333
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger has an unknown enveloped schema v${v}: ${path}`);
|
|
334
|
-
}
|
|
335
|
-
const rows = validateLedgerRowsV2(rec.rows, path);
|
|
336
|
-
const envelopeExtras = {};
|
|
337
|
-
for (const [k, val] of Object.entries(rec)) {
|
|
338
|
-
if (k !== "v" && k !== "rows")
|
|
339
|
-
envelopeExtras[k] = val;
|
|
340
|
-
}
|
|
341
|
-
return { form: "v2", rows, envelopeExtras };
|
|
312
|
+
if (!("v" in rec)) {
|
|
313
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger has no schema version: it is ${V1_LEDGER_FORM_REFUSED}: ${path}`);
|
|
342
314
|
}
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
315
|
+
const v = rec.v;
|
|
316
|
+
if (typeof v !== "number" || !Number.isInteger(v)) {
|
|
317
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger schema version is not an integer: ${path}`);
|
|
318
|
+
}
|
|
319
|
+
if (v > LEDGER_SCHEMA_VERSION) {
|
|
320
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger schema v${v} is newer than this engine supports (v${LEDGER_SCHEMA_VERSION}) — refusing to reinterpret it: ${path}`);
|
|
321
|
+
}
|
|
322
|
+
if (v !== LEDGER_SCHEMA_VERSION) {
|
|
323
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger has an unknown enveloped schema v${v}: ${path}`);
|
|
324
|
+
}
|
|
325
|
+
const rows = validateLedgerRowsV2(rec.rows, path);
|
|
326
|
+
const envelopeExtras = {};
|
|
327
|
+
for (const [k, val] of Object.entries(rec)) {
|
|
328
|
+
if (k !== "v" && k !== "rows")
|
|
329
|
+
envelopeExtras[k] = val;
|
|
349
330
|
}
|
|
350
|
-
return {
|
|
331
|
+
return { rows, envelopeExtras };
|
|
332
|
+
}
|
|
333
|
+
function ledgerFormOnDisk(controlDir) {
|
|
334
|
+
const path = join(controlDir, LEDGER_FILE);
|
|
335
|
+
const raw = readControlFileOrAbsent(path, "committed-rev ledger");
|
|
336
|
+
if (raw === undefined)
|
|
337
|
+
return "absent";
|
|
338
|
+
try {
|
|
339
|
+
parseLedgerText(raw, path);
|
|
340
|
+
return "v2";
|
|
341
|
+
}
|
|
342
|
+
catch (err) {
|
|
343
|
+
if (err instanceof ControlPlaneCorruptError)
|
|
344
|
+
return "malformed";
|
|
345
|
+
throw err;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
export async function readMemoryLedgerForm(controlDir) {
|
|
349
|
+
if (typeof controlDir !== "string" || controlDir === "") {
|
|
350
|
+
throw new TypeError(`readMemoryLedgerForm: controlDir is a non-empty directory path (got ${controlDir === "" ? "an empty string" : typeof controlDir})`);
|
|
351
|
+
}
|
|
352
|
+
return ledgerFormOnDisk(controlDir);
|
|
351
353
|
}
|
|
352
354
|
const KNOWN_TRANSFER_CHANNELS = new Set(["adopted-move", "applyPatches-move", "migration-bind", "migration", "delete", "erasure-anchor", "erasure-request"]);
|
|
353
355
|
function transferEventInvalid(raw) {
|
|
@@ -597,12 +599,11 @@ const FILE_MEMORY_ENGINE_BACKEND_OPTION_KEYS = optionKeys()({ controlDir: 0, now
|
|
|
597
599
|
export class FileMemoryEngineBackend {
|
|
598
600
|
directoryRoot;
|
|
599
601
|
controlPlaneRoot;
|
|
602
|
+
governance;
|
|
600
603
|
now;
|
|
601
604
|
onIncident;
|
|
602
605
|
ledger;
|
|
603
606
|
envelopeExtras;
|
|
604
|
-
persistedSchemaVersion;
|
|
605
|
-
announcedV1Compat = false;
|
|
606
607
|
unboundRowsKnown = false;
|
|
607
608
|
adoptionNoticeKeys = new Set();
|
|
608
609
|
transfersAppendFault;
|
|
@@ -619,6 +620,7 @@ export class FileMemoryEngineBackend {
|
|
|
619
620
|
this.onIncident = o.onIncident;
|
|
620
621
|
this.directoryRoot = dir;
|
|
621
622
|
this.controlPlaneRoot = effectiveControlRootOf(dir, { controlDir: o.controlDir, onIncident: o.onIncident });
|
|
623
|
+
this.governance = fileGovernanceStore(this.controlPlaneRoot);
|
|
622
624
|
this.assertRootAnchored();
|
|
623
625
|
ensureDirExists(dir);
|
|
624
626
|
ensureDirExists(this.controlPlaneRoot);
|
|
@@ -628,7 +630,7 @@ export class FileMemoryEngineBackend {
|
|
|
628
630
|
}
|
|
629
631
|
catch {
|
|
630
632
|
}
|
|
631
|
-
if (this.
|
|
633
|
+
if (this.ledger !== undefined && hasUnboundRows(this.ledger)) {
|
|
632
634
|
let layoutDerivesPaths = false;
|
|
633
635
|
try {
|
|
634
636
|
const shape = scopeRegistryShape(this.controlPlaneRoot);
|
|
@@ -683,10 +685,9 @@ export class FileMemoryEngineBackend {
|
|
|
683
685
|
this.ledger = undefined;
|
|
684
686
|
this.loadLedger();
|
|
685
687
|
registeredScopes(this.controlPlaneRoot);
|
|
686
|
-
if (
|
|
688
|
+
if (hasUnboundRows(this.loadLedger()))
|
|
687
689
|
this.tryOpportunisticMigrate();
|
|
688
|
-
|
|
689
|
-
this.announceUnboundRows(this.loadLedger());
|
|
690
|
+
this.announceUnboundRows(this.loadLedger());
|
|
690
691
|
}
|
|
691
692
|
drainInboundFindings() {
|
|
692
693
|
const out = this.inboundFindings;
|
|
@@ -706,37 +707,21 @@ export class FileMemoryEngineBackend {
|
|
|
706
707
|
const raw = readControlFileOrAbsent(path, "committed-rev ledger");
|
|
707
708
|
if (raw === undefined) {
|
|
708
709
|
this.ledger = Object.create(null);
|
|
709
|
-
this.persistedSchemaVersion = "v2";
|
|
710
710
|
this.unboundRowsKnown = false;
|
|
711
711
|
return this.ledger;
|
|
712
712
|
}
|
|
713
713
|
const parsed = parseLedgerText(raw, path);
|
|
714
714
|
this.ledger = parsed.rows;
|
|
715
715
|
this.envelopeExtras = parsed.envelopeExtras;
|
|
716
|
-
this.persistedSchemaVersion = parsed.form;
|
|
717
716
|
this.unboundRowsKnown = hasUnboundRows(parsed.rows);
|
|
718
|
-
if (parsed.form === "v1" && !this.announcedV1Compat) {
|
|
719
|
-
this.announcedV1Compat = true;
|
|
720
|
-
this.enqueueExternalItems("every-scope", ["memory ledger v1-compat active — v2 binding guarantees not yet in force (the migration runs at the next uncontended entry)"]);
|
|
721
|
-
}
|
|
722
717
|
return this.ledger;
|
|
723
718
|
}
|
|
724
719
|
saveLedger() {
|
|
725
720
|
if (!this.ledger)
|
|
726
721
|
return;
|
|
727
|
-
if (this.persistedSchemaVersion !== "v2") {
|
|
728
|
-
throw new ControlPlaneCorruptError("committed-rev ledger write refused: the on-disk ledger is still schema v1 and the migration has not run (mutations must migrate first)");
|
|
729
|
-
}
|
|
730
722
|
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(ledgerEnvelope(this.ledger, this.envelopeExtras), null, 2)}\n`);
|
|
731
723
|
this.unboundRowsKnown = hasUnboundRows(this.ledger);
|
|
732
724
|
}
|
|
733
|
-
persistLedgerV1(rows) {
|
|
734
|
-
const map = Object.create(null);
|
|
735
|
-
for (const [id, row] of rowsEntries(rows))
|
|
736
|
-
map[id] = row.rev;
|
|
737
|
-
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(map, null, 2)}\n`);
|
|
738
|
-
this.unboundRowsKnown = Object.keys(map).length > 0;
|
|
739
|
-
}
|
|
740
725
|
enqueueExternalItems(to, items, opts) {
|
|
741
726
|
if (items.length === 0 && opts?.supersedesPrefix === undefined)
|
|
742
727
|
return;
|
|
@@ -760,13 +745,8 @@ export class FileMemoryEngineBackend {
|
|
|
760
745
|
else {
|
|
761
746
|
scopes = [to.scope];
|
|
762
747
|
}
|
|
763
|
-
for (const scope of scopes)
|
|
764
|
-
|
|
765
|
-
enqueueMemoryAnnouncement(this.controlPlaneRoot, { kind: "external", scope, at: this.now(), items }, opts);
|
|
766
|
-
}
|
|
767
|
-
catch {
|
|
768
|
-
}
|
|
769
|
-
}
|
|
748
|
+
for (const scope of scopes)
|
|
749
|
+
void enqueueMemoryAnnouncement(this.governance, { kind: "external", scope, at: this.now(), items }, opts).catch((err) => sayAnnounceFailure(this.onIncident, "store-notice enqueue", err));
|
|
770
750
|
}
|
|
771
751
|
withholdNotice(items) {
|
|
772
752
|
if (items.length === 0)
|
|
@@ -872,28 +852,6 @@ export class FileMemoryEngineBackend {
|
|
|
872
852
|
}
|
|
873
853
|
return { complete, byId, distilledFrom };
|
|
874
854
|
}
|
|
875
|
-
writeV1BackupOnce() {
|
|
876
|
-
const raw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
877
|
-
if (raw === undefined)
|
|
878
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger vanished under the migration lock: ${join(this.controlPlaneRoot, LEDGER_FILE)}`);
|
|
879
|
-
const bak = join(this.controlPlaneRoot, LEDGER_V1_BACKUP_FILE);
|
|
880
|
-
let fd;
|
|
881
|
-
try {
|
|
882
|
-
fd = openSync(bak, "wx", 0o600);
|
|
883
|
-
}
|
|
884
|
-
catch (err) {
|
|
885
|
-
if (err.code === "EEXIST")
|
|
886
|
-
return;
|
|
887
|
-
throw err;
|
|
888
|
-
}
|
|
889
|
-
try {
|
|
890
|
-
writeAllSync(fd, raw);
|
|
891
|
-
fsyncSync(fd);
|
|
892
|
-
}
|
|
893
|
-
finally {
|
|
894
|
-
closeSync(fd);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
855
|
tryAcquireTxnLockSync() {
|
|
898
856
|
return tryStoreTxnLock(this.controlPlaneRoot, { now: this.now });
|
|
899
857
|
}
|
|
@@ -913,21 +871,19 @@ export class FileMemoryEngineBackend {
|
|
|
913
871
|
migrateLockedIfNeeded(lockToken) {
|
|
914
872
|
this.ledger = undefined;
|
|
915
873
|
const rows = this.loadLedger();
|
|
916
|
-
if (
|
|
874
|
+
if (!hasUnboundRows(rows))
|
|
917
875
|
return;
|
|
918
|
-
const fullMigration = this.persistedSchemaVersion === "v1";
|
|
919
876
|
const census = this.censusProjectionsLocked();
|
|
920
877
|
if (!census.complete) {
|
|
921
|
-
this.announceAdoptionNotice("migration-incomplete", "every-scope",
|
|
878
|
+
this.announceAdoptionNotice("migration-incomplete", "every-scope", "memory ledger unbound-row convergence abandoned this pass — the projection census could not read every scope (bindings derived from a partial view could be wrong); it retries at the next entry");
|
|
922
879
|
return;
|
|
923
880
|
}
|
|
924
881
|
const now = this.now();
|
|
925
882
|
const next = Object.create(null);
|
|
926
883
|
const bound = [];
|
|
927
|
-
const unbound = [];
|
|
928
884
|
const events = [];
|
|
929
885
|
for (const [id, row] of rowsEntries(rows)) {
|
|
930
|
-
if (
|
|
886
|
+
if (rowsBinding(rows, id) !== undefined) {
|
|
931
887
|
next[id] = { ...row };
|
|
932
888
|
continue;
|
|
933
889
|
}
|
|
@@ -936,35 +892,23 @@ export class FileMemoryEngineBackend {
|
|
|
936
892
|
if (projections.length === 1 && sole !== undefined) {
|
|
937
893
|
next[id] = { ...row, scope: sole.scope, slug: sole.slug };
|
|
938
894
|
bound.push(id);
|
|
939
|
-
|
|
940
|
-
events.push({ ev: randomUUID(), channel: "migration-bind", id, to: sole, at: now });
|
|
895
|
+
events.push({ ev: randomUUID(), channel: "migration-bind", id, to: sole, at: now });
|
|
941
896
|
}
|
|
942
897
|
else {
|
|
943
898
|
next[id] = { ...row };
|
|
944
|
-
unbound.push(`${id} (${projections.length} projection(s))`);
|
|
945
899
|
}
|
|
946
900
|
}
|
|
947
|
-
if (
|
|
948
|
-
this.writeV1BackupOnce();
|
|
949
|
-
events.push({ ev: randomUUID(), channel: "migration", boundRows: bound.length, unboundRows: unbound.length, at: now });
|
|
950
|
-
}
|
|
951
|
-
else if (bound.length === 0) {
|
|
901
|
+
if (bound.length === 0)
|
|
952
902
|
return;
|
|
953
|
-
}
|
|
954
903
|
this.assertTxnLockOwnership(lockToken);
|
|
955
904
|
this.precheckTransfersAppendable();
|
|
956
905
|
const journal = { txn: `${Date.now()}-migrate`, ops: [], ledger2: ledgerEnvelope(next, this.envelopeExtras), transfers: events };
|
|
957
906
|
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
958
907
|
this.ledger = next;
|
|
959
|
-
this.persistedSchemaVersion = "v2";
|
|
960
908
|
this.saveLedger();
|
|
961
909
|
this.appendTransfers(events);
|
|
962
910
|
rmSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), { force: true });
|
|
963
|
-
this.enqueueExternalItems("operator", [
|
|
964
|
-
fullMigration
|
|
965
|
-
? `memory ledger upgraded to v2 (${bound.length} row(s) bound, ${unbound.length} unbound${unbound.length > 0 ? `: ${unbound.slice(0, 8).join(", ")}${unbound.length > 8 ? ", …" : ""}` : ""})`
|
|
966
|
-
: `memory ledger unbound row(s) converged to bound: ${bound.slice(0, 8).join(", ")}${bound.length > 8 ? ", …" : ""}`,
|
|
967
|
-
]);
|
|
911
|
+
this.enqueueExternalItems("operator", [`memory ledger unbound row(s) converged to bound: ${bound.slice(0, 8).join(", ")}${bound.length > 8 ? ", …" : ""}`]);
|
|
968
912
|
}
|
|
969
913
|
chainDegradedMarkerPresent() {
|
|
970
914
|
return readControlFileOrAbsent(join(this.controlPlaneRoot, CHAIN_DEGRADED_FILE), "evidence-chain degradation marker") !== undefined;
|
|
@@ -1167,8 +1111,7 @@ export class FileMemoryEngineBackend {
|
|
|
1167
1111
|
const raw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
1168
1112
|
if (raw === undefined)
|
|
1169
1113
|
return Object.create(null);
|
|
1170
|
-
|
|
1171
|
-
return parsed.form === "v2" ? parsed.rows : Object.create(null);
|
|
1114
|
+
return parseLedgerText(raw, join(this.controlPlaneRoot, LEDGER_FILE)).rows;
|
|
1172
1115
|
}
|
|
1173
1116
|
catch (err) {
|
|
1174
1117
|
const code = err.code ?? (err instanceof ControlPlaneCorruptError ? "corrupt" : "io error");
|
|
@@ -1246,20 +1189,7 @@ export class FileMemoryEngineBackend {
|
|
|
1246
1189
|
const raw = readControlFileOrAbsent(jp, "transaction journal");
|
|
1247
1190
|
if (raw !== undefined) {
|
|
1248
1191
|
const journal = parseJournal(raw, jp);
|
|
1249
|
-
const { rows: snapshotRows, extras: snapshotExtras
|
|
1250
|
-
if (snapshotForm === "v1") {
|
|
1251
|
-
try {
|
|
1252
|
-
const diskRaw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
1253
|
-
const diskParsed = diskRaw !== undefined ? JSON.parse(diskRaw) : undefined;
|
|
1254
|
-
if (diskParsed !== null && typeof diskParsed === "object" && "v" in diskParsed && diskParsed.v === LEDGER_SCHEMA_VERSION) {
|
|
1255
|
-
this.enqueueExternalItems("every-scope", [
|
|
1256
|
-
"memory ledger: recovering a v1-format journal over a v2 ledger — a pre-v2 process wrote AFTER this store migrated (mixed-version deployment window). Retire old readers/writers before further writes; see the v2 rollback runbook.",
|
|
1257
|
-
]);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
catch {
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1192
|
+
const { rows: snapshotRows, extras: snapshotExtras } = journalLedgerSnapshot(journal, jp);
|
|
1263
1193
|
for (const op of journal.ops) {
|
|
1264
1194
|
const invalid = journalOpInvalid(op, this.directoryRoot);
|
|
1265
1195
|
if (invalid !== undefined) {
|
|
@@ -1286,8 +1216,6 @@ export class FileMemoryEngineBackend {
|
|
|
1286
1216
|
journalEvs.set(e.ev, canonical);
|
|
1287
1217
|
journalChainForms.set(e.ev, canonicalJsonStringify(chainFormOf(e)));
|
|
1288
1218
|
}
|
|
1289
|
-
if (snapshotForm === "v1")
|
|
1290
|
-
throw new ControlPlaneCorruptError(`transaction journal carries transfers with a v1 snapshot (impossible form): ${jp}`);
|
|
1291
1219
|
if (journalEvs.size > 0) {
|
|
1292
1220
|
for (const row of this.readTransferChain(fenceToken)) {
|
|
1293
1221
|
const j = journalEvs.get(row.ev);
|
|
@@ -1444,19 +1372,11 @@ export class FileMemoryEngineBackend {
|
|
|
1444
1372
|
}
|
|
1445
1373
|
this.recoveryCommitProbe?.();
|
|
1446
1374
|
this.assertTxnLockOwnership(fenceToken);
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
this.recordJournalSweep(journal);
|
|
1453
|
-
this.appendTransfers(journal.transfers ?? []);
|
|
1454
|
-
}
|
|
1455
|
-
else {
|
|
1456
|
-
this.ledger = snapshotRows;
|
|
1457
|
-
this.persistedSchemaVersion = "v1";
|
|
1458
|
-
this.persistLedgerV1(snapshotRows);
|
|
1459
|
-
}
|
|
1375
|
+
this.ledger = snapshotRows;
|
|
1376
|
+
this.envelopeExtras = snapshotExtras;
|
|
1377
|
+
this.saveLedger();
|
|
1378
|
+
this.recordJournalSweep(journal);
|
|
1379
|
+
this.appendTransfers(journal.transfers ?? []);
|
|
1460
1380
|
if (typeof journal.txn === "string") {
|
|
1461
1381
|
this.closeJournalIfOurs(journal.txn);
|
|
1462
1382
|
}
|
|
@@ -1570,7 +1490,7 @@ export class FileMemoryEngineBackend {
|
|
|
1570
1490
|
if (memo !== undefined)
|
|
1571
1491
|
return memo;
|
|
1572
1492
|
}
|
|
1573
|
-
if (this.
|
|
1493
|
+
if (this.unboundRowsKnown)
|
|
1574
1494
|
this.tryOpportunisticMigrate();
|
|
1575
1495
|
const dir = this.scopeDir(scope);
|
|
1576
1496
|
const files = scanEntryFiles(dir);
|
|
@@ -1595,6 +1515,8 @@ export class FileMemoryEngineBackend {
|
|
|
1595
1515
|
skippedUnreadable.push(relative(this.directoryRoot, f.path));
|
|
1596
1516
|
continue;
|
|
1597
1517
|
}
|
|
1518
|
+
if (!carriesEntry(text))
|
|
1519
|
+
continue;
|
|
1598
1520
|
const parsed = parseEntryFile(text);
|
|
1599
1521
|
if (parsed.id === undefined)
|
|
1600
1522
|
continue;
|
|
@@ -1920,7 +1842,7 @@ export class FileMemoryEngineBackend {
|
|
|
1920
1842
|
restrictedIdlessScope;
|
|
1921
1843
|
restrictedIdlessBaseline;
|
|
1922
1844
|
readScopeCommitted(scope, audit) {
|
|
1923
|
-
if (this.
|
|
1845
|
+
if (this.unboundRowsKnown)
|
|
1924
1846
|
this.tryOpportunisticMigrate();
|
|
1925
1847
|
const dir = this.scopeDir(scope);
|
|
1926
1848
|
const files = scanEntryFiles(dir, {
|
|
@@ -2115,11 +2037,10 @@ export class FileMemoryEngineBackend {
|
|
|
2115
2037
|
this.readScopeCommitted(scope, true);
|
|
2116
2038
|
const idlessBaseline = opts?.idlessWriteScope !== undefined && opts.idlessWriteScope === this.restrictedIdlessScope ? this.restrictedIdlessBaseline : undefined;
|
|
2117
2039
|
const idlessScope = idlessBaseline !== undefined ? opts?.idlessWriteScope : undefined;
|
|
2118
|
-
if (
|
|
2040
|
+
if (hasUnboundRows(this.loadLedger()))
|
|
2119
2041
|
this.tryOpportunisticMigrate();
|
|
2120
2042
|
const rows = { ...this.loadLedger() };
|
|
2121
|
-
|
|
2122
|
-
this.announceUnboundRows(rows);
|
|
2043
|
+
this.announceUnboundRows(rows);
|
|
2123
2044
|
const present = new Map();
|
|
2124
2045
|
let complete = true;
|
|
2125
2046
|
for (const scope of Object.keys(registeredScopes(this.controlPlaneRoot))) {
|
|
@@ -2472,10 +2393,10 @@ export class FileMemoryEngineBackend {
|
|
|
2472
2393
|
let slug = entry.slug;
|
|
2473
2394
|
let target = join(dir, `${slug}.md`);
|
|
2474
2395
|
for (let n = 2;; n++) {
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2396
|
+
if (!plannedTargets.has(target)) {
|
|
2397
|
+
const existing = readSafe(target);
|
|
2398
|
+
if (existing === undefined || !carriesEntry(existing))
|
|
2399
|
+
break;
|
|
2479
2400
|
const parsed = parseEntryFile(existing);
|
|
2480
2401
|
if (parsed.id === undefined || parsed.id === entry.id)
|
|
2481
2402
|
break;
|
|
@@ -2499,7 +2420,7 @@ export class FileMemoryEngineBackend {
|
|
|
2499
2420
|
report.applied.push({ op: "add", id: entry.id, slug });
|
|
2500
2421
|
return;
|
|
2501
2422
|
}
|
|
2502
|
-
const found = this.
|
|
2423
|
+
const found = this.locateForPatch(patch.id, rows, patch.op === "update" ? patch.entry?.scope : undefined);
|
|
2503
2424
|
if (!found) {
|
|
2504
2425
|
report.conflicts.push({ op: patch.op, id: patch.id, reason: "unknown id (entry not found in backend)" });
|
|
2505
2426
|
return;
|
|
@@ -2543,7 +2464,7 @@ export class FileMemoryEngineBackend {
|
|
|
2543
2464
|
if (patch.baseRev !== undefined && patch.baseRev !== currentRev) {
|
|
2544
2465
|
report.conflicts.push({ op: patch.op, id: patch.id, reason: "rev mismatch (concurrent change)", baseRev: patch.baseRev, currentRev });
|
|
2545
2466
|
const shadowText = this.readCommittedShadow(patch.id);
|
|
2546
|
-
if (shadowText !== undefined && shadowText !== serializeEntryFile(found.entry)) {
|
|
2467
|
+
if (shadowText !== undefined && (!found.onPlane || shadowText !== serializeEntryFile(found.entry))) {
|
|
2547
2468
|
ops.push({ kind: "write", target: found.path, content: shadowText });
|
|
2548
2469
|
landings.push({ id: patch.id, scope: found.entry.scope, slug: found.entry.slug });
|
|
2549
2470
|
}
|
|
@@ -2593,6 +2514,20 @@ export class FileMemoryEngineBackend {
|
|
|
2593
2514
|
bindRowTracked(rows, entry.id, { rev: computeEntryRev(entry), scope: entry.scope, slug: entry.slug, at: this.now() }, transfers, "applyPatches-move");
|
|
2594
2515
|
report.applied.push({ op: "update", id: entry.id, slug: entry.slug });
|
|
2595
2516
|
}
|
|
2517
|
+
locateForPatch(id, rows, preferScope) {
|
|
2518
|
+
const onPlane = this.locateById(id, preferScope);
|
|
2519
|
+
if (onPlane !== undefined)
|
|
2520
|
+
return { ...onPlane, onPlane: true };
|
|
2521
|
+
const binding = rowsBinding(rows, id);
|
|
2522
|
+
const shadowText = binding !== undefined ? this.readCommittedShadow(id) : undefined;
|
|
2523
|
+
if (binding === undefined || shadowText === undefined)
|
|
2524
|
+
return undefined;
|
|
2525
|
+
const path = this.bindingAbsPath(binding);
|
|
2526
|
+
const standing = readSafe(path);
|
|
2527
|
+
if (standing !== undefined && parseEntryFile(standing).id !== undefined)
|
|
2528
|
+
return undefined;
|
|
2529
|
+
return { entry: entryFromFile(shadowText, id, binding.slug, binding.scope), path, onPlane: false };
|
|
2530
|
+
}
|
|
2596
2531
|
locateById(id, preferScope) {
|
|
2597
2532
|
const scopes = Object.keys(registeredScopes(this.controlPlaneRoot));
|
|
2598
2533
|
const ordered = preferScope !== undefined ? [preferScope, ...scopes.filter((s) => s !== preferScope)] : scopes;
|
|
@@ -2738,7 +2673,7 @@ export class FileMemoryEngineBackend {
|
|
|
2738
2673
|
resolvedIds = [...new Set([...ledgerIds, ...ghostIds])].sort();
|
|
2739
2674
|
}
|
|
2740
2675
|
else {
|
|
2741
|
-
resolvedIds = lineageContributionsOfSession(this.
|
|
2676
|
+
resolvedIds = (await lineageContributionsOfSession(this.governance, select.sessionId))
|
|
2742
2677
|
.map((c) => c.entryId)
|
|
2743
2678
|
.sort();
|
|
2744
2679
|
}
|
|
@@ -2789,7 +2724,7 @@ export class FileMemoryEngineBackend {
|
|
|
2789
2724
|
transfers.push({ ev: randomUUID(), channel: "erasure-request", req: requestId, scope, selectHash, ids: byScope.get(scope) ?? [], at: now });
|
|
2790
2725
|
}
|
|
2791
2726
|
}
|
|
2792
|
-
const lineageCommitted = resolvedIds.length > 0 ? readLineageRecord(this.
|
|
2727
|
+
const lineageCommitted = resolvedIds.length > 0 ? (await readLineageRecord(this.governance)).committed : {};
|
|
2793
2728
|
const preSessionsOf = (id) => Object.prototype.hasOwnProperty.call(lineageCommitted, id) ? Object.keys(lineageCommitted[id] ?? {}).sort() : [];
|
|
2794
2729
|
for (const id of rowIds) {
|
|
2795
2730
|
const row = rows[id];
|
|
@@ -2888,7 +2823,7 @@ export class FileMemoryEngineBackend {
|
|
|
2888
2823
|
this.appendTransfers(transfers);
|
|
2889
2824
|
this.closeJournalIfOurs(txn);
|
|
2890
2825
|
}
|
|
2891
|
-
const late = captureAndClearLineageForEntries(this.
|
|
2826
|
+
const late = await captureAndClearLineageForEntries(this.governance, resolvedIds);
|
|
2892
2827
|
for (const e of erased) {
|
|
2893
2828
|
const lateSessions = late.get(e.id);
|
|
2894
2829
|
if (lateSessions !== undefined && lateSessions.length > 0)
|
|
@@ -2948,13 +2883,7 @@ export class FileMemoryEngineBackend {
|
|
|
2948
2883
|
const raw = readControlFileOrAbsent(path, "committed-rev ledger");
|
|
2949
2884
|
if (raw === undefined)
|
|
2950
2885
|
return { raw, rows: Object.create(null) };
|
|
2951
|
-
|
|
2952
|
-
if (parsed.form === "v1") {
|
|
2953
|
-
throw new Error(`memory audit read refused: the committed-rev ledger at ${path} is still schema v1 (pre-binding) — ` +
|
|
2954
|
-
`migrate first (the store migrates itself at its next uncontended write/read entry or checkControlPlane); ` +
|
|
2955
|
-
`an audit read never triggers the migration`);
|
|
2956
|
-
}
|
|
2957
|
-
return { raw, rows: parsed.rows };
|
|
2886
|
+
return { raw, rows: parseLedgerText(raw, path).rows };
|
|
2958
2887
|
}
|
|
2959
2888
|
async auditStable(read) {
|
|
2960
2889
|
for (let attempt = 0; attempt < FileMemoryEngineBackend.AUDIT_FENCE_ATTEMPTS; attempt++) {
|
|
@@ -3101,7 +3030,7 @@ export class FileMemoryEngineBackend {
|
|
|
3101
3030
|
const ledgerRaw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
3102
3031
|
if (ledgerRaw !== undefined) {
|
|
3103
3032
|
const parsed = parseLedgerText(ledgerRaw, join(this.controlPlaneRoot, LEDGER_FILE));
|
|
3104
|
-
if (
|
|
3033
|
+
if (Object.prototype.hasOwnProperty.call(parsed.rows, id) && parsed.rows[id]?.prev !== undefined) {
|
|
3105
3034
|
out.state = "damaged";
|
|
3106
3035
|
}
|
|
3107
3036
|
}
|
|
@@ -3215,7 +3144,7 @@ export class FileMemoryEngineBackend {
|
|
|
3215
3144
|
const feed = (label, text) => {
|
|
3216
3145
|
h.update(JSON.stringify([label, text]));
|
|
3217
3146
|
};
|
|
3218
|
-
for (const file of
|
|
3147
|
+
for (const file of STRICT_CONTROL_PLANE_LEDGERS.map((ledger) => fileGovernanceDocOf(ledger).file)) {
|
|
3219
3148
|
feed(file, readControlFileOrAbsent(join(this.controlPlaneRoot, file), `${file} (export fence)`) ?? "<absent>");
|
|
3220
3149
|
let journalRaw;
|
|
3221
3150
|
try {
|
|
@@ -3389,9 +3318,6 @@ export class FileMemoryEngineBackend {
|
|
|
3389
3318
|
this.recoverJournal({ token: lock.token });
|
|
3390
3319
|
this.adoptLayoutLocked(lock.token);
|
|
3391
3320
|
const rows = this.loadLedger();
|
|
3392
|
-
if (this.persistedSchemaVersion !== "v2") {
|
|
3393
|
-
throw erasureCodedError("memory export refused: the committed-rev ledger is still schema v1 (pre-binding) — the store migrates itself at its next write/read entry or checkControlPlane; an export never triggers the migration", FileMemoryEngineBackend.EXPORT_INCOMPLETE);
|
|
3394
|
-
}
|
|
3395
3321
|
if (this.chainDegradedMarkerPresent()) {
|
|
3396
3322
|
throw erasureCodedError("memory export refused: the custody chain carries the durable degradation marker (transfers.chain-degraded.json) — evidence rows were lost to an out-of-band tear and a bundle cannot testify to a complete deletion history; resolve the marker deliberately before exporting", FileMemoryEngineBackend.EXPORT_INCOMPLETE);
|
|
3397
3323
|
}
|
|
@@ -3400,11 +3326,11 @@ export class FileMemoryEngineBackend {
|
|
|
3400
3326
|
const fullStore = Object.keys(registered).every((s) => scopeSet.has(s));
|
|
3401
3327
|
for (let round = 0; round < 3; round++) {
|
|
3402
3328
|
const before = this.exportGovernanceFingerprint();
|
|
3403
|
-
const lineageRec = readLineageRecord(this.
|
|
3404
|
-
const challenges = readChallengeEvents(this.
|
|
3329
|
+
const lineageRec = await readLineageRecord(this.governance);
|
|
3330
|
+
const challenges = await readChallengeEvents(this.governance);
|
|
3405
3331
|
const polluted = listSessionPollution(this.controlPlaneRoot);
|
|
3406
3332
|
const chainRows = this.readExportChainRowsPure();
|
|
3407
|
-
this.exportFaceProbe?.(round);
|
|
3333
|
+
await this.exportFaceProbe?.(round);
|
|
3408
3334
|
const after = this.exportGovernanceFingerprint();
|
|
3409
3335
|
if (before !== after)
|
|
3410
3336
|
continue;
|
|
@@ -3473,8 +3399,6 @@ export class FileMemoryEngineBackend {
|
|
|
3473
3399
|
this.recoverJournal({ token: lock.token });
|
|
3474
3400
|
this.adoptLayoutLocked(lock.token);
|
|
3475
3401
|
const rows = this.loadLedger();
|
|
3476
|
-
if (this.persistedSchemaVersion !== "v2")
|
|
3477
|
-
return { custody: [], unbound: [], complete: false, unsliceableCustody: 0, reason: "the committed-rev ledger is still schema v1 (migrate first)" };
|
|
3478
3402
|
if (this.chainDegradedMarkerPresent()) {
|
|
3479
3403
|
return { custody: [], unbound: [], complete: false, unsliceableCustody: 0, reason: "the custody chain carries the durable degradation marker (transfers.chain-degraded.json) — evidence rows were lost to an out-of-band tear" };
|
|
3480
3404
|
}
|
|
@@ -3546,15 +3470,15 @@ export class FileMemoryEngineBackend {
|
|
|
3546
3470
|
this.appendTransfers(toAppend);
|
|
3547
3471
|
return { appended: toAppend.length, withheld };
|
|
3548
3472
|
}
|
|
3549
|
-
appendImportChallengesVerified(events) {
|
|
3473
|
+
async appendImportChallengesVerified(events) {
|
|
3550
3474
|
if (events.length === 0)
|
|
3551
3475
|
return;
|
|
3552
|
-
const { assignments } = appendChallengeEvents(this.
|
|
3476
|
+
const { assignments } = await appendChallengeEvents(this.governance, events, this.now);
|
|
3553
3477
|
const replayed = assignments.filter((a) => a.replayed);
|
|
3554
3478
|
if (replayed.length === 0)
|
|
3555
3479
|
return;
|
|
3556
3480
|
const byEventId = new Map();
|
|
3557
|
-
for (const e of readChallengeEvents(this.
|
|
3481
|
+
for (const e of await readChallengeEvents(this.governance))
|
|
3558
3482
|
if (!byEventId.has(e.eventId))
|
|
3559
3483
|
byEventId.set(e.eventId, e);
|
|
3560
3484
|
for (const a of replayed) {
|
|
@@ -3620,14 +3544,14 @@ export class FileMemoryEngineBackend {
|
|
|
3620
3544
|
catch {
|
|
3621
3545
|
throw new ControlPlaneCorruptError(`bundle import completion receipt is unreadable/malformed at ${receiptPath} — it cannot prove completion and cannot be re-minted; repair or remove it deliberately (fail-closed)`);
|
|
3622
3546
|
}
|
|
3623
|
-
releaseImportLatch(ctl, txnId);
|
|
3547
|
+
await releaseImportLatch(this.governance, ctl, txnId);
|
|
3624
3548
|
return report;
|
|
3625
3549
|
}
|
|
3626
3550
|
const digest = this.deletedIdsDigestLocked();
|
|
3627
3551
|
if (digest.state === "damaged" || this.chainDegradedMarkerPresent()) {
|
|
3628
3552
|
throw erasureCodedError("memory bundle import refused: the destination evidence chain is damaged or durably marked degraded — deletion history cannot be proven, so the anti-resurrection judgment cannot run; heal/rebuild the chain (locked mutation entry / explicit rebuild), then import again (nothing was landed, no latch was set)", "memory.import_rejected");
|
|
3629
3553
|
}
|
|
3630
|
-
stageImportLatch(
|
|
3554
|
+
await stageImportLatch(this.governance, bundleHash, plan.entries.map((e) => ({ entryId: e.id, rev: e.rev })), this.now);
|
|
3631
3555
|
const rows = this.loadLedger();
|
|
3632
3556
|
const rowPresent = (id) => Object.prototype.hasOwnProperty.call(rows, id);
|
|
3633
3557
|
const report = {
|
|
@@ -3729,16 +3653,16 @@ export class FileMemoryEngineBackend {
|
|
|
3729
3653
|
}
|
|
3730
3654
|
report.governanceWithheld = [...withheldIds].sort();
|
|
3731
3655
|
report.referentialOrphans = [...orphanIds].sort();
|
|
3732
|
-
report.lineageDivergence = importLineageCommitted(
|
|
3733
|
-
this.appendImportChallengesVerified(challengesToApply.map((c) => ({
|
|
3656
|
+
report.lineageDivergence = await importLineageCommitted(this.governance, lineageToApply);
|
|
3657
|
+
await this.appendImportChallengesVerified(challengesToApply.map((c) => ({
|
|
3734
3658
|
eventId: `imp:${bundleHash}:${c.eventId}`,
|
|
3735
3659
|
entryId: c.entryId,
|
|
3736
3660
|
reason: c.reason,
|
|
3737
3661
|
...(c.challengedRev !== undefined ? { challengedRev: c.challengedRev } : {}),
|
|
3738
3662
|
})));
|
|
3739
3663
|
for (const p of [...plan.pollutedSessions].sort((a, b) => (a.sessionId < b.sessionId ? -1 : 1))) {
|
|
3740
|
-
const contributions = lineageContributionsOfSession(
|
|
3741
|
-
this.appendImportChallengesVerified(contributions.map((c) => ({
|
|
3664
|
+
const contributions = (await lineageContributionsOfSession(this.governance, p.sessionId)).filter((c) => c.marked !== true);
|
|
3665
|
+
await this.appendImportChallengesVerified(contributions.map((c) => ({
|
|
3742
3666
|
eventId: `imp-sweep:${bundleHash}:pollution:${p.sessionId}:${p.at}:${c.entryId}`,
|
|
3743
3667
|
entryId: c.entryId,
|
|
3744
3668
|
reason: `challenged: the contributing session was marked polluted`,
|
|
@@ -3776,7 +3700,7 @@ export class FileMemoryEngineBackend {
|
|
|
3776
3700
|
}
|
|
3777
3701
|
throw err;
|
|
3778
3702
|
}
|
|
3779
|
-
releaseImportLatch(ctl, txnId);
|
|
3703
|
+
await releaseImportLatch(this.governance, ctl, txnId);
|
|
3780
3704
|
return report;
|
|
3781
3705
|
}
|
|
3782
3706
|
catch (err) {
|