@sema-agent/core 7.58.0 → 7.59.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 +776 -0
- package/README.md +6 -4
- package/dist/agents/cc-peer-directory.js +8 -8
- package/dist/agents/child-model-seat.d.ts +4 -2
- package/dist/agents/child-model-seat.js +5 -3
- package/dist/agents/peer-directory.d.ts +9 -0
- package/dist/agents/peer-directory.js +6 -2
- package/dist/agents/send-message-tool.js +21 -12
- package/dist/agents/subagent.js +33 -34
- package/dist/brain/anthropic.js +161 -45
- package/dist/brain/errors.d.ts +9 -3
- package/dist/brain/errors.js +7 -1
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +3 -3
- package/dist/brain/openai.js +103 -53
- package/dist/brain/provider-dialect.d.ts +11 -0
- package/dist/brain/provider-dialect.js +5 -2
- package/dist/brain/reasoning-request.js +5 -4
- package/dist/brain/reasoning.d.ts +19 -0
- package/dist/brain/reasoning.js +17 -2
- package/dist/brain/request-route.d.ts +4 -1
- package/dist/brain/request-route.js +4 -1
- package/dist/brain/route-adjudicator.d.ts +84 -18
- package/dist/brain/route-adjudicator.js +87 -21
- package/dist/brain/route-conformance.js +1 -1
- package/dist/brain/stream-engine.js +84 -49
- package/dist/brain/stream-shared.d.ts +30 -0
- package/dist/brain/stream-shared.js +34 -1
- package/dist/brain/timeout.d.ts +62 -5
- package/dist/brain/timeout.js +93 -6
- package/dist/core/account-row.d.ts +61 -0
- package/dist/core/account-row.js +51 -0
- package/dist/core/advisor-verdict.d.ts +2 -1
- package/dist/core/advisor-verdict.js +1 -1
- package/dist/core/allow-entry.d.ts +18 -6
- package/dist/core/allow-entry.js +16 -8
- package/dist/core/approval-object.d.ts +29 -15
- package/dist/core/approval-object.js +47 -19
- package/dist/core/auto-compaction.js +1 -1
- package/dist/core/background-agent-store.d.ts +16 -3
- package/dist/core/checkpoint-requirements.d.ts +13 -1
- package/dist/core/checkpoint-requirements.js +3 -1
- package/dist/core/checkpoint-store.d.ts +58 -12
- package/dist/core/checkpoint-store.js +18 -6
- package/dist/core/child-clamp-seats.d.ts +29 -0
- package/dist/core/child-clamp-seats.js +56 -1
- package/dist/core/compliance.d.ts +2 -2
- package/dist/core/compliance.js +1 -1
- package/dist/core/effective-path-target.d.ts +8 -2
- package/dist/core/effective-path-target.js +8 -3
- package/dist/core/engine-notice.d.ts +98 -8
- package/dist/core/engine-notice.js +19 -5
- package/dist/core/gate-fold.js +1 -1
- package/dist/core/gate-lanes.js +8 -4
- package/dist/core/gate-outcome.d.ts +32 -3
- package/dist/core/gate-outcome.js +19 -1
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +13 -0
- package/dist/core/hooks.d.ts +31 -3
- package/dist/core/hooks.js +5 -6
- package/dist/core/image-admission.d.ts +6 -5
- package/dist/core/image-admission.js +18 -14
- package/dist/core/locked-config.d.ts +5 -2
- package/dist/core/locked-config.js +2 -1
- package/dist/core/mailbox-store.d.ts +45 -1
- package/dist/core/mailbox-store.js +53 -9
- package/dist/core/mcp-failure.d.ts +114 -18
- package/dist/core/mcp-failure.js +63 -5
- package/dist/core/mcp-server-link.d.ts +22 -1
- package/dist/core/mcp-server-link.js +25 -1
- package/dist/core/mcp.d.ts +12 -8
- package/dist/core/mcp.js +42 -25
- package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
- package/dist/core/memory-engine/consolidation-driver.js +3 -3
- package/dist/core/memory-engine/consolidation.d.ts +4 -0
- package/dist/core/memory-engine/consolidation.js +1 -0
- package/dist/core/memory-engine/delegation-settlement.js +5 -12
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +50 -1
- package/dist/core/memory-engine/dual-root.js +44 -1
- package/dist/core/memory-engine/engine.d.ts +67 -14
- package/dist/core/memory-engine/engine.js +384 -212
- package/dist/core/memory-engine/export-bundle.d.ts +23 -0
- package/dist/core/memory-engine/export-bundle.js +23 -4
- package/dist/core/memory-engine/file-backend.d.ts +128 -55
- package/dist/core/memory-engine/file-backend.js +290 -117
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/layout.d.ts +59 -11
- package/dist/core/memory-engine/layout.js +190 -40
- package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
- package/dist/core/memory-engine/memory-backend-contract.js +39 -2
- package/dist/core/memory-engine/sync-client.d.ts +9 -1
- package/dist/core/memory-engine/sync-client.js +31 -8
- package/dist/core/memory-engine/sync.d.ts +5 -0
- package/dist/core/memory-engine/types.d.ts +6 -0
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/kernel/dispatch.js +2 -1
- package/dist/core/mods/kernel/events.d.ts +2 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/kernel/registration.d.ts +4 -0
- package/dist/core/mods/kernel/registration.js +3 -0
- package/dist/core/mods/stations.d.ts +31 -10
- package/dist/core/mods/stations.js +44 -10
- package/dist/core/mods/tool-call.js +1 -1
- package/dist/core/parent-spec-seat.d.ts +8 -3
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +6 -0
- package/dist/core/peer-seat.d.ts +70 -8
- package/dist/core/peer-seat.js +143 -11
- package/dist/core/permission-rule-consent.js +10 -4
- package/dist/core/permission-rule-model.d.ts +16 -0
- package/dist/core/permission-rule-model.js +1 -1
- package/dist/core/present-plan-tool.d.ts +11 -3
- package/dist/core/present-plan-tool.js +2 -2
- package/dist/core/resume-startup-cause.js +1 -0
- package/dist/core/rewrite-rejudge.d.ts +1 -0
- package/dist/core/rewrite-rejudge.js +2 -2
- package/dist/core/roles.d.ts +34 -2
- package/dist/core/roles.js +43 -4
- package/dist/core/runner/announce-once-ledger.d.ts +5 -4
- package/dist/core/runner/announce-once-ledger.js +4 -2
- package/dist/core/runner/call-hook-stations.js +2 -2
- package/dist/core/runner/contracts.d.ts +20 -16
- package/dist/core/runner/credential-origin-seat.js +4 -3
- package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
- package/dist/core/runner/cwd-alignment-probe.js +21 -0
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/gate-exit.d.ts +12 -4
- package/dist/core/runner/gate-exit.js +10 -7
- package/dist/core/runner/image-removed-seat.d.ts +12 -0
- package/dist/core/runner/image-removed-seat.js +19 -0
- package/dist/core/runner/inline-image.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.js +3 -3
- package/dist/core/runner/park-commit.d.ts +1 -1
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
- package/dist/core/runner/prepare-ask-lane.js +2 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -0
- package/dist/core/runner/prepare-config-doors.js +2 -0
- package/dist/core/runner/prepare-context-lane.js +2 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
- package/dist/core/runner/prepare-delegation-surface.js +1 -0
- package/dist/core/runner/prepare-hands-readface.d.ts +4 -0
- package/dist/core/runner/prepare-hands-readface.js +5 -0
- package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
- package/dist/core/runner/prepare-inherited-gate.js +14 -27
- package/dist/core/runner/prepare-memory.js +10 -17
- package/dist/core/runner/prepare-park-ask.d.ts +1 -1
- package/dist/core/runner/prepare-park-ask.js +2 -1
- package/dist/core/runner/prepare-policy-chain.d.ts +3 -3
- package/dist/core/runner/prepare-policy-chain.js +16 -13
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
- package/dist/core/runner/prepare-prompt-inputs.js +8 -19
- package/dist/core/runner/prepare-protocol-tools.js +9 -1
- package/dist/core/runner/prepare-run-refs.d.ts +2 -3
- package/dist/core/runner/prepare-run-refs.js +4 -1
- package/dist/core/runner/prepare-task.js +4 -2
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -1
- package/dist/core/runner/prepare-wiring-manifest.js +2 -1
- package/dist/core/runner/reply-pricing.d.ts +30 -0
- package/dist/core/runner/reply-pricing.js +19 -0
- package/dist/core/runner/resume-admission.js +4 -2
- package/dist/core/runner/resume-apply.js +6 -1
- package/dist/core/runner/resume-policy-outcome.js +5 -5
- package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
- package/dist/core/runner/role-seat-defaulted.js +40 -0
- package/dist/core/runner/run-brain-sinks.js +2 -0
- package/dist/core/runner/run-identity-wiring.d.ts +2 -5
- package/dist/core/runner/run-identity-wiring.js +5 -4
- package/dist/core/runner/run-leg.d.ts +2 -0
- package/dist/core/runner/run-leg.js +37 -28
- package/dist/core/runner/run-stop-and-final-verify.js +2 -2
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
- package/dist/core/runner/run-terminal-adoption.js +9 -3
- package/dist/core/runner/run-turn-boundary.js +77 -70
- package/dist/core/runner/runtask.d.ts +1 -1
- package/dist/core/runner/runtask.js +2 -2
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +3 -18
- package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
- package/dist/core/runner/sub-agent-deny-lists.js +10 -0
- package/dist/core/runner/tool-end-body.js +2 -2
- package/dist/core/runner/tool-occurrence.d.ts +1 -1
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner/turn-attachments.d.ts +26 -22
- package/dist/core/runner/turn-attachments.js +24 -26
- package/dist/core/runner-deps.d.ts +1 -1
- package/dist/core/secret-env.d.ts +32 -2
- package/dist/core/secret-env.js +65 -3
- package/dist/core/sensitive-path-policy.js +3 -3
- package/dist/core/session-policy-store.d.ts +3 -1
- package/dist/core/session-policy-store.js +13 -9
- package/dist/core/session-store.d.ts +2 -5
- package/dist/core/side-query.d.ts +11 -1
- package/dist/core/side-query.js +9 -0
- package/dist/core/skill-grant-binding.d.ts +31 -2
- package/dist/core/skill-grant-binding.js +31 -1
- package/dist/core/skill-grant.d.ts +8 -5
- package/dist/core/skill-grant.js +6 -6
- package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +3 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
- package/dist/core/synthetic-read-verdict.js +2 -1
- package/dist/core/task-event.d.ts +32 -8
- package/dist/core/task-notification.js +16 -10
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +5 -0
- package/dist/core/task-spec.d.ts +12 -1
- package/dist/core/terminal-cause.d.ts +10 -0
- package/dist/core/tool-check-reading.d.ts +1 -0
- package/dist/core/tool-check-reading.js +3 -3
- package/dist/core/tool-policy.d.ts +16 -0
- package/dist/core/tool-roster.d.ts +112 -5
- package/dist/core/tool-roster.js +42 -1
- package/dist/core/tool-spec.d.ts +3 -1
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -1
- package/dist/core/user-attachment.js +1 -1
- package/dist/core/wiring-manifest.d.ts +6 -3
- package/dist/engine/compaction/compaction.js +29 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
- package/dist/engine/execution-env/node-execution-env.js +9 -12
- package/dist/engine/harness/agent-harness.d.ts +25 -2
- package/dist/engine/harness/agent-harness.js +41 -12
- package/dist/engine/harness/messages.d.ts +3 -1
- package/dist/engine/harness/messages.js +3 -2
- package/dist/engine/harness/types.d.ts +8 -0
- package/dist/engine/llm/rejected-images.d.ts +46 -0
- package/dist/engine/llm/rejected-images.js +54 -0
- package/dist/engine/llm/tool-turns.d.ts +2 -1
- package/dist/engine/llm/types.d.ts +18 -7
- package/dist/engine/loop/agent-loop.d.ts +8 -0
- package/dist/engine/loop/agent-loop.js +52 -15
- package/dist/engine/loop/types.d.ts +3 -1
- package/dist/engine/session/path-to-root.d.ts +38 -0
- package/dist/engine/session/path-to-root.js +39 -0
- package/dist/engine/session/storage-base.js +4 -21
- package/dist/index.d.ts +16 -10
- package/dist/index.js +11 -7
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +1 -0
- package/dist/internal/llm.d.ts +1 -0
- package/dist/orchestration/workflow-observe.d.ts +17 -1
- package/dist/orchestration/workflow-observe.js +20 -0
- package/dist/orchestration/workflow-types.d.ts +32 -7
- package/dist/orchestration/workflow.js +739 -489
- package/dist/shell/counting-pass.d.ts +50 -0
- package/dist/shell/counting-pass.js +502 -0
- package/dist/shell/lex.d.ts +4 -2
- package/dist/shell/lex.js +93 -34
- package/dist/shell/shell-words.d.ts +1 -1
- package/dist/shell/shell-words.js +7 -6
- package/dist/stores/file/mailbox-store.js +6 -10
- package/dist/tools/fs/fs-bash.d.ts +6 -0
- package/dist/tools/fs/fs-bash.js +6 -3
- package/dist/tools/fs/index.js +6 -2
- package/dist/tools/fs/program-read-model.d.ts +13 -0
- package/dist/tools/fs/program-read-model.js +15 -0
- package/dist/tools/fs/program-read-model.rows.js +1 -1
- package/dist/tools/fs/read-deny.d.ts +13 -10
- package/dist/tools/fs/read-deny.js +25 -5
- package/dist/tools/fs/read-floor.d.ts +19 -0
- package/dist/tools/fs/read-floor.js +23 -0
- package/dist/tools/fs/shell-read-check.d.ts +1 -1
- package/dist/tools/fs/shell-read-check.js +2 -1
- package/dist/tools/fs/shell-read-judge.d.ts +16 -8
- package/dist/tools/fs/shell-read-judge.js +10 -6
- package/dist/tools/fs/shell-read-plan.d.ts +6 -1
- package/dist/tools/fs/shell-read-plan.js +22 -15
- package/dist/tools/fs/shell-read-start.js +1 -0
- package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
- package/dist/tools/fs/shell-reentry-text.js +25 -3
- package/dist/tools/monitor.d.ts +4 -0
- package/dist/tools/monitor.js +2 -0
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +87 -1
- package/wire-changes/core-stores-sql@7.59.0.json +29 -0
- package/wire-changes/core@7.59.0.json +2459 -0
- package/wire-changes/mods-kernel@7.59.0.json +29 -0
- package/wire-changes/primitives@7.59.0.json +29 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fstatSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, openSync, fsyncSync, closeSync, utimesSync } from "node:fs";
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import { canonicalJsonStringify } from "../canonical-json.js";
|
|
@@ -9,12 +9,72 @@ import { ambiguousOriginRepresentation, committedDistilledOf, committedOriginOf,
|
|
|
9
9
|
import { convertV1SidecarKeys } from "./delegation-settlement.js";
|
|
10
10
|
import { layerObservationLookup, observedDivergenceNotice } from "./layer-observations.js";
|
|
11
11
|
import { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, scanEntryFiles } from "./entry-scan.js";
|
|
12
|
-
import { ControlPlaneCorruptError, CURSORS_FILE, QUARANTINE_DIR, CHALLENGES_FILE, IMPORT_RECEIPTS_DIR, LINEAGE_FILE, SESSION_POLLUTION_DIR, appendChallengeEvents, atomicWriteFileSync, quarantineAndTombstone, captureAndClearLineageForEntries, adoptRootScopeLayout, anchorStoreRoot, effectiveControlRootOf, ensureDirExists, LEDGER_FILE, enqueueMemoryAnnouncement, importLatchTxnId, importLineageCommitted, importSessionPollution, isContainedIn, permissionRemedyOf, withPermissionRemedy, lineageContributionsOfSession, listSessionPollution, readChallengeEvents, readLineageRecord, registerScope, registeredScopes, releaseImportLatch, layoutNeedsAdoption, scopeDirFor, scopeDirName, scopeRegistryShape, stageImportLatch, landsOutsideStore, storeActRefusal, storeRootMovedRefusal, writeAllSync, STORE_JOURNAL_FILE, STORE_TXN_LOCK_DIR, TXN_LOCK_STALE_MS, acquireStoreTxnLock, assertStoreTxnLockOwnership, tryStoreTxnLock, } from "./layout.js";
|
|
12
|
+
import { ControlPlaneCorruptError, CURSORS_FILE, QUARANTINE_DIR, CHALLENGES_FILE, IMPORT_RECEIPTS_DIR, LINEAGE_FILE, SESSION_POLLUTION_DIR, appendChallengeEvents, atomicWriteFileSync, quarantineAndTombstone, captureAndClearLineageForEntries, adoptRootScopeLayout, anchorStoreRoot, effectiveControlRootOf, ensureDirExists, LEDGER_FILE, 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, tryStoreTxnLock, } from "./layout.js";
|
|
13
13
|
import { screenInboundEntries } from "./data-plane.js";
|
|
14
|
+
import { CONSOLIDATION_DRIVER_PLANS_DIR, CONSOLIDATION_PLANS_DIR } from "./consolidation.js";
|
|
15
|
+
import { canonicalExpectedScopes, expectedScopesInvalid, firstOutsideExpectedScopes } from "./export-bundle.js";
|
|
14
16
|
import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
|
|
15
17
|
import { admittingLandings, cutPerLanding, LandingsNeedAdmission, requireLandingsAdmitted } from "./landing-admission.js";
|
|
16
18
|
import { thrownText } from "../thrown-value.js";
|
|
17
19
|
export { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, scanEntryFiles } from "./entry-scan.js";
|
|
20
|
+
export const ERASURE_CARRIER_CLASSES = Object.freeze(["projection", "shadow", "indexLine", "quarantineCopy", "planArchive", "planWorkbook", "evidenceBinding", "backendDerived"]);
|
|
21
|
+
export function erasureStatusOf(att) {
|
|
22
|
+
if (att.conflicts.length > 0)
|
|
23
|
+
return "partial";
|
|
24
|
+
const claimed = new Set([...att.erased.map((e) => e.id), ...(att.erasedPreviously ?? []).map((e) => e.id)]);
|
|
25
|
+
const notFound = new Set(att.notFound.map((n) => n.id));
|
|
26
|
+
if (!att.resolvedIds.every((id) => claimed.has(id) || (att.custodyState === "complete" && notFound.has(id))))
|
|
27
|
+
return "partial";
|
|
28
|
+
for (const cls of ERASURE_CARRIER_CLASSES) {
|
|
29
|
+
const answer = att.residuals.carriers[cls];
|
|
30
|
+
if (answer === null || typeof answer !== "object" || answer.remaining !== 0)
|
|
31
|
+
return "partial";
|
|
32
|
+
}
|
|
33
|
+
return "complete";
|
|
34
|
+
}
|
|
35
|
+
function recordErasureSweep(controlDir, requestId, paths) {
|
|
36
|
+
if (paths.length === 0)
|
|
37
|
+
return;
|
|
38
|
+
lockedStrictUpdate(controlDir, ERASURE_SWEEP_RECORD_FILE, ERASURE_SWEEP_RECORD_WHAT, coerceErasureSweepRecord, (file) => {
|
|
39
|
+
const before = file.requests[requestId] ?? [];
|
|
40
|
+
const merged = [...new Set([...before, ...paths])].sort();
|
|
41
|
+
if (merged.length === before.length)
|
|
42
|
+
return { result: undefined };
|
|
43
|
+
file.requests[requestId] = merged;
|
|
44
|
+
return { next: file, result: undefined };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function readErasureSweep(controlDir, storeRoot, requestId) {
|
|
48
|
+
return erasureSweepOwedAt(coerceErasureSweepRecord(readStrictSidecar(controlDir, ERASURE_SWEEP_RECORD_FILE, ERASURE_SWEEP_RECORD_WHAT)), storeRoot, requestId);
|
|
49
|
+
}
|
|
50
|
+
export async function sweepUnderErasureRecord(controlDir, storeRoot, requestId, sweep) {
|
|
51
|
+
const txn = await acquireStoreTxnLock(controlDir, { now: Date.now });
|
|
52
|
+
try {
|
|
53
|
+
lockedStrictUpdate(controlDir, ERASURE_SWEEP_RECORD_FILE, ERASURE_SWEEP_RECORD_WHAT, coerceErasureSweepRecord, (file) => {
|
|
54
|
+
const owed = requestId === undefined ? [] : erasureSweepOwedAt(file, storeRoot, requestId);
|
|
55
|
+
assertStoreTxnLockOwnership(controlDir, txn.token);
|
|
56
|
+
if (!sweep(owed))
|
|
57
|
+
return { result: undefined };
|
|
58
|
+
assertStoreTxnLockOwnership(controlDir, txn.token);
|
|
59
|
+
if (requestId === undefined || file.requests[requestId] === undefined)
|
|
60
|
+
return { result: undefined };
|
|
61
|
+
delete file.requests[requestId];
|
|
62
|
+
return { next: file, result: undefined };
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
txn.release();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function spellsSlug(binding) {
|
|
70
|
+
return binding !== null && typeof binding === "object" && typeof binding.slug === "string";
|
|
71
|
+
}
|
|
72
|
+
function chainFormOf(e) {
|
|
73
|
+
if (e.channel !== "delete" || e.from === undefined)
|
|
74
|
+
return e;
|
|
75
|
+
const { from, ...rest } = e;
|
|
76
|
+
return { ...rest, scope: from.scope };
|
|
77
|
+
}
|
|
18
78
|
export function erasureSelectHash(select) {
|
|
19
79
|
return createHash("sha256").update(`${canonicalJsonStringify(select)}\n`, "utf8").digest("hex");
|
|
20
80
|
}
|
|
@@ -51,8 +111,16 @@ export function erasureRequestInvalid(input) {
|
|
|
51
111
|
}
|
|
52
112
|
if (input.allowUnevidenced !== undefined && typeof input.allowUnevidenced !== "boolean")
|
|
53
113
|
return "allowUnevidenced must be a boolean when present";
|
|
114
|
+
if (input.expectedScopes !== undefined) {
|
|
115
|
+
const grantBad = expectedScopesInvalid(input.expectedScopes);
|
|
116
|
+
if (grantBad !== undefined)
|
|
117
|
+
return grantBad;
|
|
118
|
+
}
|
|
54
119
|
return undefined;
|
|
55
120
|
}
|
|
121
|
+
export function erasureScopeRefusal(where) {
|
|
122
|
+
return erasureCodedError(`${where}: the request names or resolves to a scope outside its expectedScopes, or to an id whose scope this store cannot attribute — the whole request is refused (nothing was deleted, nothing was recorded; no count, id or scope is reported)`, "config.memory_erasure_scope");
|
|
123
|
+
}
|
|
56
124
|
function erasureCodedError(message, code) {
|
|
57
125
|
const e = new Error(message);
|
|
58
126
|
e.code = code;
|
|
@@ -70,6 +138,7 @@ export function captureErasureInput(input) {
|
|
|
70
138
|
return input;
|
|
71
139
|
const requestId = input.requestId;
|
|
72
140
|
const allowUnevidenced = input.allowUnevidenced;
|
|
141
|
+
const rawGrant = input.expectedScopes;
|
|
73
142
|
const rawSel = input.select;
|
|
74
143
|
let select;
|
|
75
144
|
if (rawSel && typeof rawSel === "object" && !Array.isArray(rawSel)) {
|
|
@@ -84,7 +153,8 @@ export function captureErasureInput(input) {
|
|
|
84
153
|
else {
|
|
85
154
|
select = rawSel;
|
|
86
155
|
}
|
|
87
|
-
|
|
156
|
+
const expectedScopes = (Array.isArray(rawGrant) ? [...rawGrant] : rawGrant);
|
|
157
|
+
return { requestId, select, ...(allowUnevidenced !== undefined ? { allowUnevidenced } : {}), ...(expectedScopes !== undefined ? { expectedScopes } : {}) };
|
|
88
158
|
}
|
|
89
159
|
class AuditSnapshotContendedError extends Error {
|
|
90
160
|
}
|
|
@@ -368,6 +438,12 @@ function transferEventInvalid(raw) {
|
|
|
368
438
|
return "delete event must not carry boundRows/unboundRows/to/select";
|
|
369
439
|
if (e.from !== undefined && bindingInvalid(e.from))
|
|
370
440
|
return "delete event has a malformed 'from'";
|
|
441
|
+
if (e.scope !== undefined) {
|
|
442
|
+
if (typeof e.scope !== "string" || e.scope.length === 0)
|
|
443
|
+
return "delete event has a non-string/empty 'scope'";
|
|
444
|
+
if (e.from !== undefined)
|
|
445
|
+
return "delete event carries both 'from' (journal form) and 'scope' (chain form)";
|
|
446
|
+
}
|
|
371
447
|
if (e.req !== undefined && (typeof e.req !== "string" || e.req.length === 0))
|
|
372
448
|
return "delete event has a non-string/empty 'req'";
|
|
373
449
|
if (e.sessions !== undefined) {
|
|
@@ -382,8 +458,8 @@ function transferEventInvalid(raw) {
|
|
|
382
458
|
}
|
|
383
459
|
if (e.legacyId !== undefined && e.legacyId !== true)
|
|
384
460
|
return "legacyId, when present, must be literal true";
|
|
385
|
-
if (e.legacyId !== undefined && e.from !== undefined)
|
|
386
|
-
return "legacyId and 'from' are mutually exclusive (a legacy row has no derivable projection)";
|
|
461
|
+
if (e.legacyId !== undefined && (e.from !== undefined || e.scope !== undefined))
|
|
462
|
+
return "legacyId and 'from'/'scope' are mutually exclusive (a legacy row has no derivable projection)";
|
|
387
463
|
return undefined;
|
|
388
464
|
}
|
|
389
465
|
if (e.channel === "erasure-anchor") {
|
|
@@ -426,6 +502,11 @@ function transferEventInvalid(raw) {
|
|
|
426
502
|
return "erasure anchor 'ids' does not equal the ids-selector's verbatim id list (a pinned set the selector never named)";
|
|
427
503
|
}
|
|
428
504
|
}
|
|
505
|
+
if (e.expectedScopes !== undefined) {
|
|
506
|
+
const grantBad = expectedScopesInvalid(e.expectedScopes);
|
|
507
|
+
if (grantBad !== undefined)
|
|
508
|
+
return `erasure anchor ${grantBad}`;
|
|
509
|
+
}
|
|
429
510
|
return undefined;
|
|
430
511
|
}
|
|
431
512
|
if (e.channel === "erasure-request") {
|
|
@@ -630,7 +711,7 @@ export class FileMemoryEngineBackend {
|
|
|
630
711
|
this.unboundRowsKnown = hasUnboundRows(parsed.rows);
|
|
631
712
|
if (parsed.form === "v1" && !this.announcedV1Compat) {
|
|
632
713
|
this.announcedV1Compat = true;
|
|
633
|
-
this.enqueueExternalItems(["memory ledger v1-compat active — v2 binding guarantees not yet in force (the migration runs at the next uncontended entry)"]);
|
|
714
|
+
this.enqueueExternalItems("every-scope", ["memory ledger v1-compat active — v2 binding guarantees not yet in force (the migration runs at the next uncontended entry)"]);
|
|
634
715
|
}
|
|
635
716
|
return this.ledger;
|
|
636
717
|
}
|
|
@@ -650,29 +731,70 @@ export class FileMemoryEngineBackend {
|
|
|
650
731
|
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(map, null, 2)}\n`);
|
|
651
732
|
this.unboundRowsKnown = Object.keys(map).length > 0;
|
|
652
733
|
}
|
|
653
|
-
enqueueExternalItems(items) {
|
|
734
|
+
enqueueExternalItems(to, items, opts) {
|
|
735
|
+
if (items.length === 0 && opts?.supersedesPrefix === undefined)
|
|
736
|
+
return;
|
|
737
|
+
let scopes = [];
|
|
738
|
+
if (to === "operator") {
|
|
739
|
+
this.withholdNotice(items);
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
if (to === "every-scope") {
|
|
743
|
+
try {
|
|
744
|
+
scopes = Object.keys(registeredScopes(this.controlPlaneRoot));
|
|
745
|
+
}
|
|
746
|
+
catch {
|
|
747
|
+
scopes = [];
|
|
748
|
+
}
|
|
749
|
+
if (scopes.length === 0) {
|
|
750
|
+
this.withholdNotice(items);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
scopes = [to.scope];
|
|
756
|
+
}
|
|
757
|
+
for (const scope of scopes) {
|
|
758
|
+
try {
|
|
759
|
+
enqueueMemoryAnnouncement(this.controlPlaneRoot, { kind: "external", scope, at: this.now(), items }, opts);
|
|
760
|
+
}
|
|
761
|
+
catch {
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
withholdNotice(items) {
|
|
654
766
|
if (items.length === 0)
|
|
655
767
|
return;
|
|
768
|
+
const text = `memory store notice names no single scope, so it was kept off every session's memory notices: ${items.join(" | ")}`;
|
|
769
|
+
const sink = this.onIncident;
|
|
770
|
+
if (sink === undefined) {
|
|
771
|
+
console.warn(`[sema] ${text}`);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
656
774
|
try {
|
|
657
|
-
|
|
775
|
+
const err = new Error(text);
|
|
776
|
+
err.code = "memory.announcement_withheld";
|
|
777
|
+
sink(err);
|
|
658
778
|
}
|
|
659
779
|
catch {
|
|
660
780
|
}
|
|
661
781
|
}
|
|
662
|
-
announceAdoptionNotice(key, item) {
|
|
782
|
+
announceAdoptionNotice(key, to, item) {
|
|
663
783
|
if (this.adoptionNoticeKeys.has(key))
|
|
664
784
|
return;
|
|
665
785
|
this.adoptionNoticeKeys.add(key);
|
|
666
|
-
this.enqueueExternalItems([item]);
|
|
786
|
+
this.enqueueExternalItems(to, [item]);
|
|
667
787
|
}
|
|
788
|
+
unboundReadingSaid;
|
|
668
789
|
announceUnboundRows(rows) {
|
|
669
790
|
const ids = unboundRowIds(rows);
|
|
670
791
|
const item = ids.length === 0 ? undefined : `${UNBOUND_DISCLOSURE_PREFIX}${ids.length} unbound row(s) (no derivable committed projection): ${ids.slice(0, 8).join(", ")}${ids.length > 8 ? ", …" : ""} — v2 binding guarantees do not cover them until they converge (duplicate projections need an unrestricted harvest or manual removal)`;
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
792
|
+
const reading = item ?? "";
|
|
793
|
+
if (reading === (this.unboundReadingSaid ?? ""))
|
|
794
|
+
return;
|
|
795
|
+
this.unboundReadingSaid = reading;
|
|
796
|
+
if (item !== undefined)
|
|
797
|
+
this.enqueueExternalItems("operator", [item]);
|
|
676
798
|
}
|
|
677
799
|
bindingAbsPath(binding) {
|
|
678
800
|
return join(scopeDirFor(this.directoryRoot, this.controlPlaneRoot, binding.scope), `${binding.slug}.md`);
|
|
@@ -683,6 +805,7 @@ export class FileMemoryEngineBackend {
|
|
|
683
805
|
censusProjectionsLocked() {
|
|
684
806
|
let complete = true;
|
|
685
807
|
const byId = new Map();
|
|
808
|
+
const distilledFrom = new Map();
|
|
686
809
|
for (const scope of Object.keys(registeredScopes(this.controlPlaneRoot))) {
|
|
687
810
|
const dir = this.scopeDir(scope);
|
|
688
811
|
const walk = (d, depth) => {
|
|
@@ -725,17 +848,23 @@ export class FileMemoryEngineBackend {
|
|
|
725
848
|
complete = false;
|
|
726
849
|
continue;
|
|
727
850
|
}
|
|
728
|
-
const
|
|
851
|
+
const parsed = parseEntryFile(text);
|
|
852
|
+
const id = parsed.id;
|
|
729
853
|
if (id === undefined)
|
|
730
854
|
continue;
|
|
731
855
|
const list = byId.get(id) ?? [];
|
|
732
856
|
list.push({ scope, slug: relative(dir, p).replace(/\.md$/, "") });
|
|
733
857
|
byId.set(id, list);
|
|
858
|
+
for (const input of parsed.frontmatter.distilled?.inputs ?? []) {
|
|
859
|
+
const products = distilledFrom.get(input.id) ?? new Set();
|
|
860
|
+
products.add(id);
|
|
861
|
+
distilledFrom.set(input.id, products);
|
|
862
|
+
}
|
|
734
863
|
}
|
|
735
864
|
};
|
|
736
865
|
walk(dir, 0);
|
|
737
866
|
}
|
|
738
|
-
return { complete, byId };
|
|
867
|
+
return { complete, byId, distilledFrom };
|
|
739
868
|
}
|
|
740
869
|
writeV1BackupOnce() {
|
|
741
870
|
const raw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
@@ -783,7 +912,7 @@ export class FileMemoryEngineBackend {
|
|
|
783
912
|
const fullMigration = this.persistedSchemaVersion === "v1";
|
|
784
913
|
const census = this.censusProjectionsLocked();
|
|
785
914
|
if (!census.complete) {
|
|
786
|
-
this.announceAdoptionNotice("migration-incomplete", `memory ledger ${fullMigration ? "v1→v2 migration" : "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`);
|
|
915
|
+
this.announceAdoptionNotice("migration-incomplete", "every-scope", `memory ledger ${fullMigration ? "v1→v2 migration" : "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`);
|
|
787
916
|
return;
|
|
788
917
|
}
|
|
789
918
|
const now = this.now();
|
|
@@ -825,7 +954,7 @@ export class FileMemoryEngineBackend {
|
|
|
825
954
|
this.saveLedger();
|
|
826
955
|
this.appendTransfers(events);
|
|
827
956
|
rmSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), { force: true });
|
|
828
|
-
this.enqueueExternalItems([
|
|
957
|
+
this.enqueueExternalItems("operator", [
|
|
829
958
|
fullMigration
|
|
830
959
|
? `memory ledger upgraded to v2 (${bound.length} row(s) bound, ${unbound.length} unbound${unbound.length > 0 ? `: ${unbound.slice(0, 8).join(", ")}${unbound.length > 8 ? ", …" : ""}` : ""})`
|
|
831
960
|
: `memory ledger unbound row(s) converged to bound: ${bound.slice(0, 8).join(", ")}${bound.length > 8 ? ", …" : ""}`,
|
|
@@ -934,7 +1063,7 @@ export class FileMemoryEngineBackend {
|
|
|
934
1063
|
catch {
|
|
935
1064
|
throw new ControlPlaneCorruptError(`transfer evidence log has a torn tail that could not be healed (truncation failed): ${path}`);
|
|
936
1065
|
}
|
|
937
|
-
this.enqueueExternalItems([
|
|
1066
|
+
this.enqueueExternalItems("every-scope", [
|
|
938
1067
|
outOfBand
|
|
939
1068
|
? `transfer evidence log had a torn tail with NO transaction journal beside it (out-of-band damage) — the fragment is quarantined, the sound prefix stands, and the chain is durably marked degraded: new id-bearing files are refused adoption until an explicit rebuild clears ${CHAIN_DEGRADED_FILE}`
|
|
940
1069
|
: `transfer evidence log had a torn tail (crash mid-append) — the fragment is quarantined and the sound prefix stands: ${TRANSFERS_FILE}`,
|
|
@@ -1037,7 +1166,7 @@ export class FileMemoryEngineBackend {
|
|
|
1037
1166
|
}
|
|
1038
1167
|
catch (err) {
|
|
1039
1168
|
const code = err.code ?? (err instanceof ControlPlaneCorruptError ? "corrupt" : "io error");
|
|
1040
|
-
this.announceAdoptionNotice(`retrieval-ledger-fault|${code}`, `memory retrieval guard: the committed-rev ledger could not be read on the lock-free retrieval face (${thrownText(err)}) — ` +
|
|
1169
|
+
this.announceAdoptionNotice(`retrieval-ledger-fault|${code}`, "operator", `memory retrieval guard: the committed-rev ledger could not be read on the lock-free retrieval face (${thrownText(err)}) — ` +
|
|
1041
1170
|
`ids carrying delete evidence are WITHHELD from retrieval (a legitimate re-add cannot be verified over an unreadable account) until the fault clears; ` +
|
|
1042
1171
|
`entries with no delete evidence serve normally`);
|
|
1043
1172
|
return Object.create(null);
|
|
@@ -1055,8 +1184,11 @@ export class FileMemoryEngineBackend {
|
|
|
1055
1184
|
const existing = this.readTransferEvents();
|
|
1056
1185
|
const batch = new Map();
|
|
1057
1186
|
const toWrite = [];
|
|
1058
|
-
for (const
|
|
1187
|
+
for (const minted of events) {
|
|
1188
|
+
const e = chainFormOf(minted);
|
|
1059
1189
|
const canonical = canonicalJsonStringify(e);
|
|
1190
|
+
if (existing.get(e.ev) === canonicalJsonStringify(minted))
|
|
1191
|
+
continue;
|
|
1060
1192
|
const inBatch = batch.get(e.ev);
|
|
1061
1193
|
if (inBatch !== undefined) {
|
|
1062
1194
|
if (inBatch !== canonical) {
|
|
@@ -1114,7 +1246,7 @@ export class FileMemoryEngineBackend {
|
|
|
1114
1246
|
const diskRaw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
1115
1247
|
const diskParsed = diskRaw !== undefined ? JSON.parse(diskRaw) : undefined;
|
|
1116
1248
|
if (diskParsed !== null && typeof diskParsed === "object" && "v" in diskParsed && diskParsed.v === LEDGER_SCHEMA_VERSION) {
|
|
1117
|
-
this.enqueueExternalItems([
|
|
1249
|
+
this.enqueueExternalItems("every-scope", [
|
|
1118
1250
|
"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.",
|
|
1119
1251
|
]);
|
|
1120
1252
|
}
|
|
@@ -1132,6 +1264,7 @@ export class FileMemoryEngineBackend {
|
|
|
1132
1264
|
if (!Array.isArray(journal.transfers))
|
|
1133
1265
|
throw new ControlPlaneCorruptError(`transaction journal transfers is not an array: ${jp}`);
|
|
1134
1266
|
const journalEvs = new Map();
|
|
1267
|
+
const journalChainForms = new Map();
|
|
1135
1268
|
for (const e of journal.transfers) {
|
|
1136
1269
|
const invalid = transferEventInvalid(e);
|
|
1137
1270
|
if (invalid !== undefined)
|
|
@@ -1145,13 +1278,14 @@ export class FileMemoryEngineBackend {
|
|
|
1145
1278
|
throw new ControlPlaneCorruptError(`transaction journal mints event id ${JSON.stringify(e.ev)} twice with DIFFERENT payloads (fail-closed before redo): ${jp}`);
|
|
1146
1279
|
}
|
|
1147
1280
|
journalEvs.set(e.ev, canonical);
|
|
1281
|
+
journalChainForms.set(e.ev, canonicalJsonStringify(chainFormOf(e)));
|
|
1148
1282
|
}
|
|
1149
1283
|
if (snapshotForm === "v1")
|
|
1150
1284
|
throw new ControlPlaneCorruptError(`transaction journal carries transfers with a v1 snapshot (impossible form): ${jp}`);
|
|
1151
1285
|
if (journalEvs.size > 0) {
|
|
1152
1286
|
for (const row of this.readTransferChain(fenceToken)) {
|
|
1153
1287
|
const j = journalEvs.get(row.ev);
|
|
1154
|
-
if (j !== undefined && j !== row.canonical) {
|
|
1288
|
+
if (j !== undefined && j !== row.canonical && journalChainForms.get(row.ev) !== row.canonical) {
|
|
1155
1289
|
throw new ControlPlaneCorruptError(`transaction journal event id ${JSON.stringify(row.ev)} collides with a DIFFERENT payload already on the evidence chain (fail-closed before redo): ${jp}`);
|
|
1156
1290
|
}
|
|
1157
1291
|
}
|
|
@@ -1309,6 +1443,7 @@ export class FileMemoryEngineBackend {
|
|
|
1309
1443
|
this.envelopeExtras = snapshotExtras;
|
|
1310
1444
|
this.persistedSchemaVersion = "v2";
|
|
1311
1445
|
this.saveLedger();
|
|
1446
|
+
this.recordJournalSweep(journal);
|
|
1312
1447
|
this.appendTransfers(journal.transfers ?? []);
|
|
1313
1448
|
}
|
|
1314
1449
|
else {
|
|
@@ -1473,11 +1608,11 @@ export class FileMemoryEngineBackend {
|
|
|
1473
1608
|
if (committed !== undefined && binding !== undefined && !(binding.scope === scope && binding.slug === f.slug)) {
|
|
1474
1609
|
const probe = probeProjection(this.bindingAbsPath(binding), entry.id);
|
|
1475
1610
|
if (probe === "present") {
|
|
1476
|
-
this.announceAdoptionNotice(`copy|${relPath}|${entry.rev}`, `duplicate projection of committed entry ${entry.id} at ${JSON.stringify(inlineUntrusted(relPath))} — the committed projection lives at ${JSON.stringify(inlineUntrusted(this.bindingRelPath(binding)))}; the copy is not served (a copy is not a scope credential) and stays on disk for an unrestricted harvest or manual removal to adjudicate`);
|
|
1611
|
+
this.announceAdoptionNotice(`copy|${relPath}|${entry.rev}`, { scope }, `duplicate projection of committed entry ${entry.id} at ${JSON.stringify(inlineUntrusted(relPath))} — the committed projection lives ${binding.scope === scope ? `at ${JSON.stringify(inlineUntrusted(this.bindingRelPath(binding)))}` : "in another memory scope"}; the copy is not served (a copy is not a scope credential) and stays on disk for an unrestricted harvest or manual removal to adjudicate`);
|
|
1477
1612
|
continue;
|
|
1478
1613
|
}
|
|
1479
1614
|
if (probe === "undecidable") {
|
|
1480
|
-
this.announceAdoptionNotice(`bindprobe|${relPath}`, `committed entry ${entry.id} appears at ${JSON.stringify(inlineUntrusted(relPath))} but is bound to ${JSON.stringify(inlineUntrusted(this.bindingRelPath(binding)))}, and the bound projection could not be probed conclusively (a read failure, or a foreign file at that address — not ENOENT) — nothing is served or adopted this pass`);
|
|
1615
|
+
this.announceAdoptionNotice(`bindprobe|${relPath}`, { scope }, `committed entry ${entry.id} appears at ${JSON.stringify(inlineUntrusted(relPath))} but is bound to ${binding.scope === scope ? JSON.stringify(inlineUntrusted(this.bindingRelPath(binding))) : "a path in another memory scope"}, and the bound projection could not be probed conclusively (a read failure, or a foreign file at that address — not ENOENT) — nothing is served or adopted this pass`);
|
|
1481
1616
|
continue;
|
|
1482
1617
|
}
|
|
1483
1618
|
if (this.settledAsObserved(observed(), entries, entry, relPath, f.slug, scope, committed, binding, text, "quarantined-only"))
|
|
@@ -1511,7 +1646,7 @@ export class FileMemoryEngineBackend {
|
|
|
1511
1646
|
continue;
|
|
1512
1647
|
}
|
|
1513
1648
|
if (verdict === "degraded") {
|
|
1514
|
-
this.announceAdoptionNotice(`chain-degraded|${relPath}|${entry.rev}`, `new memory entry file ${JSON.stringify(inlineUntrusted(relPath))} is NOT adopted: the transfer evidence chain is degraded (out-of-band tail damage), so "no delete row for this id" is no longer evidence it was never deleted — the file stays on disk unserved until the chain state is explicitly rebuilt (${CHAIN_DEGRADED_FILE})`);
|
|
1649
|
+
this.announceAdoptionNotice(`chain-degraded|${relPath}|${entry.rev}`, { scope }, `new memory entry file ${JSON.stringify(inlineUntrusted(relPath))} is NOT adopted: the transfer evidence chain is degraded (out-of-band tail damage), so "no delete row for this id" is no longer evidence it was never deleted — the file stays on disk unserved until the chain state is explicitly rebuilt (${CHAIN_DEGRADED_FILE})`);
|
|
1515
1650
|
continue;
|
|
1516
1651
|
}
|
|
1517
1652
|
}
|
|
@@ -1574,35 +1709,19 @@ export class FileMemoryEngineBackend {
|
|
|
1574
1709
|
}
|
|
1575
1710
|
}
|
|
1576
1711
|
if (moveAnnouncements.length > 0) {
|
|
1577
|
-
this.enqueueExternalItems(moveAnnouncements.slice(0, 12).concat(moveAnnouncements.length > 12 ? [`…and ${moveAnnouncements.length - 12} more adopted move(s)`] : []));
|
|
1712
|
+
this.enqueueExternalItems({ scope }, moveAnnouncements.slice(0, 12).concat(moveAnnouncements.length > 12 ? [`…and ${moveAnnouncements.length - 12} more adopted move(s)`] : []));
|
|
1578
1713
|
}
|
|
1579
1714
|
if (adoptedExternal.length > 0) {
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
items: adoptedExternal
|
|
1585
|
-
.slice(0, 12)
|
|
1586
|
-
.map((rel) => `out-of-session memory change adopted: ${JSON.stringify(inlineUntrusted(rel))} — re-read it before relying on prior knowledge of it`)
|
|
1587
|
-
.concat(adoptedExternal.length > 12 ? [`…and ${adoptedExternal.length - 12} more adopted change(s)`] : []),
|
|
1588
|
-
});
|
|
1589
|
-
}
|
|
1590
|
-
catch {
|
|
1591
|
-
}
|
|
1715
|
+
this.enqueueExternalItems({ scope }, adoptedExternal
|
|
1716
|
+
.slice(0, 12)
|
|
1717
|
+
.map((rel) => `out-of-session memory change adopted: ${JSON.stringify(inlineUntrusted(rel))} — re-read it before relying on prior knowledge of it`)
|
|
1718
|
+
.concat(adoptedExternal.length > 12 ? [`…and ${adoptedExternal.length - 12} more adopted change(s)`] : []));
|
|
1592
1719
|
}
|
|
1593
1720
|
if (skippedUnreadable.length > 0) {
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
items: skippedUnreadable
|
|
1599
|
-
.slice(0, 12)
|
|
1600
|
-
.map((rel) => `committed memory entry could not be read and is MISSING from this session's memory: ${JSON.stringify(inlineUntrusted(rel))} — check the file (permissions/fs)`)
|
|
1601
|
-
.concat(skippedUnreadable.length > 12 ? [`…and ${skippedUnreadable.length - 12} more unreadable entr(ies)`] : []),
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
catch {
|
|
1605
|
-
}
|
|
1721
|
+
this.enqueueExternalItems({ scope }, skippedUnreadable
|
|
1722
|
+
.slice(0, 12)
|
|
1723
|
+
.map((rel) => `committed memory entry could not be read and is MISSING from this session's memory: ${JSON.stringify(inlineUntrusted(rel))} — check the file (permissions/fs)`)
|
|
1724
|
+
.concat(skippedUnreadable.length > 12 ? [`…and ${skippedUnreadable.length - 12} more unreadable entr(ies)`] : []));
|
|
1606
1725
|
}
|
|
1607
1726
|
if (!sync && this.batchScan !== undefined)
|
|
1608
1727
|
this.batchScan.set(scope, entries);
|
|
@@ -1618,11 +1737,7 @@ export class FileMemoryEngineBackend {
|
|
|
1618
1737
|
return false;
|
|
1619
1738
|
const standIn = committed !== undefined && binding !== undefined && binding.scope === scope && binding.slug === slug ? this.readCommittedShadow(entry.id) : undefined;
|
|
1620
1739
|
const notice = observedDivergenceNotice(relPath, standIn !== undefined, hit.undecided === true);
|
|
1621
|
-
|
|
1622
|
-
enqueueMemoryAnnouncement(this.controlPlaneRoot, { kind: "external", at: this.now(), items: [notice] }, { supersedesPrefix: notice });
|
|
1623
|
-
}
|
|
1624
|
-
catch {
|
|
1625
|
-
}
|
|
1740
|
+
this.enqueueExternalItems({ scope }, [notice], { supersedesPrefix: notice });
|
|
1626
1741
|
if (standIn !== undefined)
|
|
1627
1742
|
out.push(entryFromFile(standIn, entry.id, slug, scope));
|
|
1628
1743
|
return true;
|
|
@@ -1669,7 +1784,7 @@ export class FileMemoryEngineBackend {
|
|
|
1669
1784
|
this.announceAdoptionNotice(`ambiguous|${entry.id}|${projections
|
|
1670
1785
|
.map((p) => `${p.scope}/${p.slug}`)
|
|
1671
1786
|
.sort()
|
|
1672
|
-
.join(",")}`, `committed entry ${entry.id} lost its committed projection and now appears at ${projections.length} path(s) — no copy is a scope credential, so none is served or adopted (read order never picks an owner); an unrestricted harvest or manual removal adjudicates which is real`);
|
|
1787
|
+
.join(",")}`, projections.every((p) => p.scope === scope) ? { scope } : "operator", `committed entry ${entry.id} lost its committed projection and now appears at ${projections.length} path(s) — no copy is a scope credential, so none is served or adopted (read order never picks an owner); an unrestricted harvest or manual removal adjudicates which is real`);
|
|
1673
1788
|
return undefined;
|
|
1674
1789
|
}
|
|
1675
1790
|
const gateFinding = this.inboundGate(relPath, text) ?? (committedRev !== entry.rev ? this.whitewashInboundFinding(relPath, entry, "quarantined-only") : undefined);
|
|
@@ -1679,7 +1794,7 @@ export class FileMemoryEngineBackend {
|
|
|
1679
1794
|
}
|
|
1680
1795
|
const now = this.now();
|
|
1681
1796
|
bindRowTracked(rows, entry.id, { rev: entry.rev, scope, slug, at: now }, moveEvents, "adopted-move");
|
|
1682
|
-
moveAnnouncements.push(`out-of-session memory move adopted: ${entry.id} ${JSON.stringify(inlineUntrusted(this.bindingRelPath(from)))} → ${JSON.stringify(inlineUntrusted(relPath))} — re-read it before relying on prior knowledge of it`);
|
|
1797
|
+
moveAnnouncements.push(`out-of-session memory move adopted: ${entry.id} ${from.scope === scope ? JSON.stringify(inlineUntrusted(this.bindingRelPath(from))) : "(from another memory scope)"} → ${JSON.stringify(inlineUntrusted(relPath))} — re-read it before relying on prior knowledge of it`);
|
|
1683
1798
|
if (committedRev !== entry.rev) {
|
|
1684
1799
|
adoptedExternal.push(relPath);
|
|
1685
1800
|
try {
|
|
@@ -2116,6 +2231,7 @@ export class FileMemoryEngineBackend {
|
|
|
2116
2231
|
});
|
|
2117
2232
|
}
|
|
2118
2233
|
admitsLandings = true;
|
|
2234
|
+
judgesErasureScopes = true;
|
|
2119
2235
|
txnLockDir() {
|
|
2120
2236
|
return join(this.controlPlaneRoot, STORE_TXN_LOCK_DIR);
|
|
2121
2237
|
}
|
|
@@ -2483,6 +2599,56 @@ export class FileMemoryEngineBackend {
|
|
|
2483
2599
|
}
|
|
2484
2600
|
return undefined;
|
|
2485
2601
|
}
|
|
2602
|
+
journalSweepRow(journal) {
|
|
2603
|
+
const req = (journal.transfers ?? []).find((t) => t.channel === "delete" && t.req !== undefined)?.req;
|
|
2604
|
+
if (req === undefined)
|
|
2605
|
+
return undefined;
|
|
2606
|
+
return { req, paths: journal.ops.filter((op) => op.kind === "delete").map((op) => erasureSweepRecordPathOf(this.directoryRoot, req, op.target)) };
|
|
2607
|
+
}
|
|
2608
|
+
recordJournalSweep(journal, row = this.journalSweepRow(journal)) {
|
|
2609
|
+
if (row !== undefined)
|
|
2610
|
+
recordErasureSweep(this.controlPlaneRoot, row.req, row.paths);
|
|
2611
|
+
}
|
|
2612
|
+
eraseQuarantineCopiesLocked(ids) {
|
|
2613
|
+
const qDir = join(this.controlPlaneRoot, QUARANTINE_DIR);
|
|
2614
|
+
let names = [];
|
|
2615
|
+
try {
|
|
2616
|
+
names = readdirSync(qDir);
|
|
2617
|
+
}
|
|
2618
|
+
catch (err) {
|
|
2619
|
+
if (err.code !== "ENOENT") {
|
|
2620
|
+
throw new ControlPlaneCorruptError(`erasure residual enumeration failed: the quarantine dir could not be read (${err.code ?? "io error"}) at ${qDir} — the attestation must not silently claim an empty residual set; retry after the filesystem fault clears (the deletions themselves are committed and a replay converges)`);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
const out = { removed: 0, remaining: 0, unattributed: 0 };
|
|
2624
|
+
for (const name of names.sort()) {
|
|
2625
|
+
const path = join(qDir, name);
|
|
2626
|
+
const text = readSafe(path);
|
|
2627
|
+
const qid = text === undefined ? undefined : parseEntryFile(text).id;
|
|
2628
|
+
if (qid === undefined) {
|
|
2629
|
+
out.unattributed++;
|
|
2630
|
+
continue;
|
|
2631
|
+
}
|
|
2632
|
+
if (!ids.has(qid))
|
|
2633
|
+
continue;
|
|
2634
|
+
try {
|
|
2635
|
+
rmSync(path, { force: true });
|
|
2636
|
+
out.removed++;
|
|
2637
|
+
}
|
|
2638
|
+
catch {
|
|
2639
|
+
out.remaining++;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
return out;
|
|
2643
|
+
}
|
|
2644
|
+
controlDirHoldsAnything(name) {
|
|
2645
|
+
try {
|
|
2646
|
+
return readdirSync(join(this.controlPlaneRoot, name)).length > 0;
|
|
2647
|
+
}
|
|
2648
|
+
catch (err) {
|
|
2649
|
+
return err.code !== "ENOENT";
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2486
2652
|
async eraseWithEvidence(input) {
|
|
2487
2653
|
const captured = captureErasureInput(input);
|
|
2488
2654
|
const bad = erasureRequestInvalid(captured);
|
|
@@ -2490,6 +2656,8 @@ export class FileMemoryEngineBackend {
|
|
|
2490
2656
|
throw erasureCodedError(`eraseWithEvidence: ${bad}`, "config.memory_erasure_request");
|
|
2491
2657
|
const requestId = captured.requestId;
|
|
2492
2658
|
const select = captured.select;
|
|
2659
|
+
const grant = captured.expectedScopes !== undefined ? canonicalExpectedScopes(captured.expectedScopes) : undefined;
|
|
2660
|
+
const selectorScopes = "scope" in select ? [select.scope] : [];
|
|
2493
2661
|
const lock = await this.acquireTxnLock();
|
|
2494
2662
|
try {
|
|
2495
2663
|
this.assertTxnLockOwnership(lock.token);
|
|
@@ -2508,8 +2676,17 @@ export class FileMemoryEngineBackend {
|
|
|
2508
2676
|
throw new ControlPlaneCorruptError(`erasure request ${JSON.stringify(requestId)} has ${localAnchors.length} anchors on the evidence chain — a second anchor cannot be minted by this store (the lock-held chain check runs first), so the chain was spliced out of band; refusing to pick one by file order (a human adjudicates)`);
|
|
2509
2677
|
}
|
|
2510
2678
|
const priorAnchor = localAnchors[0]?.parsed;
|
|
2679
|
+
if (priorAnchor !== undefined) {
|
|
2680
|
+
const recorded = priorAnchor.expectedScopes;
|
|
2681
|
+
const same = recorded === undefined || grant === undefined ? recorded === grant : recorded.length === grant.length && recorded.every((s, i) => grant[i] === s);
|
|
2682
|
+
if (!same) {
|
|
2683
|
+
throw erasureCodedError(`eraseWithEvidence: requestId ${JSON.stringify(requestId)} was first executed under a different expectedScopes set — a requestId names one request under one authorization; nothing is reported`, "config.memory_erasure_scope");
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
if (grant !== undefined && firstOutsideExpectedScopes(grant, selectorScopes) >= 0)
|
|
2687
|
+
throw erasureScopeRefusal("eraseWithEvidence");
|
|
2511
2688
|
if (priorAnchor !== undefined && priorAnchor.selectHash !== selectHash) {
|
|
2512
|
-
throw erasureCodedError(`eraseWithEvidence: requestId ${JSON.stringify(requestId)} was first executed with a DIFFERENT selector — a requestId names ONE request
|
|
2689
|
+
throw erasureCodedError(`eraseWithEvidence: requestId ${JSON.stringify(requestId)} was first executed with a DIFFERENT selector — a requestId names ONE request; use a new requestId for a new selector (the first request's selector hash is on its anchor row, never in this text)`, "memory.erasure_selector_mismatch");
|
|
2513
2690
|
}
|
|
2514
2691
|
const replay = priorAnchor !== undefined;
|
|
2515
2692
|
let census;
|
|
@@ -2545,13 +2722,24 @@ export class FileMemoryEngineBackend {
|
|
|
2545
2722
|
.map((c) => c.entryId)
|
|
2546
2723
|
.sort();
|
|
2547
2724
|
}
|
|
2725
|
+
const boundScope = (id) => (rowPresent(id) && isValidEntryId(id) ? rowsBinding(rows, id)?.scope : undefined);
|
|
2726
|
+
if (grant !== undefined) {
|
|
2727
|
+
const recorded = new Map();
|
|
2728
|
+
for (const r of replay ? chain : []) {
|
|
2729
|
+
const p = r.parsed;
|
|
2730
|
+
if (p.channel !== "erasure-request" || p.origin !== undefined || p.req !== requestId || p.selectHash !== priorAnchor?.selectHash)
|
|
2731
|
+
continue;
|
|
2732
|
+
for (const id of p.ids)
|
|
2733
|
+
recorded.set(id, recorded.has(id) && recorded.get(id) !== p.scope ? null : p.scope);
|
|
2734
|
+
}
|
|
2735
|
+
const judged = resolvedIds.map((id) => (!replay || rowPresent(id) || (takeCensus().byId.get(id) ?? []).length > 0 ? boundScope(id) : (recorded.get(id) ?? undefined)));
|
|
2736
|
+
if (firstOutsideExpectedScopes(grant, judged) >= 0)
|
|
2737
|
+
throw erasureScopeRefusal("eraseWithEvidence");
|
|
2738
|
+
}
|
|
2548
2739
|
const priorDeletes = new Map();
|
|
2549
2740
|
for (const r of chain) {
|
|
2550
2741
|
if (r.parsed.channel === "delete" && r.parsed.origin === undefined && r.parsed.req === requestId && typeof r.parsed.id === "string") {
|
|
2551
|
-
|
|
2552
|
-
const from = rawFrom !== undefined && typeof rawFrom.scope === "string" && typeof rawFrom.slug === "string" ? { scope: rawFrom.scope, slug: rawFrom.slug } : undefined;
|
|
2553
|
-
const prev = priorDeletes.get(r.parsed.id);
|
|
2554
|
-
priorDeletes.set(r.parsed.id, { ev: r.ev, at: r.parsed.at, ...(from !== undefined ? { from } : prev?.from !== undefined ? { from: prev.from } : {}) });
|
|
2742
|
+
priorDeletes.set(r.parsed.id, { ev: r.ev, at: r.parsed.at });
|
|
2555
2743
|
}
|
|
2556
2744
|
}
|
|
2557
2745
|
const transfers = [];
|
|
@@ -2562,24 +2750,21 @@ export class FileMemoryEngineBackend {
|
|
|
2562
2750
|
const conflicts = [];
|
|
2563
2751
|
const rowIds = resolvedIds.filter((id) => rowPresent(id));
|
|
2564
2752
|
const accountAbsentIds = resolvedIds.filter((id) => !rowPresent(id));
|
|
2565
|
-
|
|
2566
|
-
takeCensus();
|
|
2753
|
+
const censusRead = resolvedIds.length > 0 ? takeCensus() : undefined;
|
|
2567
2754
|
const censusOf = (id) => census?.byId.get(id) ?? [];
|
|
2568
2755
|
const unledgeredLiveIds = accountAbsentIds.filter((id) => censusOf(id).length > 0);
|
|
2569
2756
|
const trulyAbsentIds = accountAbsentIds.filter((id) => censusOf(id).length === 0);
|
|
2570
2757
|
if (!replay) {
|
|
2571
|
-
transfers.push({ ev: randomUUID(), channel: "erasure-anchor", req: requestId, select: cloneErasureSelect(select), selectHash, ids: [...resolvedIds], notFound: trulyAbsentIds, at: now });
|
|
2758
|
+
transfers.push({ ev: randomUUID(), channel: "erasure-anchor", req: requestId, select: cloneErasureSelect(select), selectHash, ids: [...resolvedIds], notFound: trulyAbsentIds, ...(grant !== undefined ? { expectedScopes: grant } : {}), at: now });
|
|
2572
2759
|
const byScope = new Map();
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
continue;
|
|
2579
|
-
const list = byScope.get(binding.scope) ?? [];
|
|
2760
|
+
resolvedIds.forEach((id) => {
|
|
2761
|
+
const scope = boundScope(id);
|
|
2762
|
+
if (scope === undefined)
|
|
2763
|
+
return;
|
|
2764
|
+
const list = byScope.get(scope) ?? [];
|
|
2580
2765
|
list.push(id);
|
|
2581
|
-
byScope.set(
|
|
2582
|
-
}
|
|
2766
|
+
byScope.set(scope, list);
|
|
2767
|
+
});
|
|
2583
2768
|
for (const scope of [...byScope.keys()].sort()) {
|
|
2584
2769
|
transfers.push({ ev: randomUUID(), channel: "erasure-request", req: requestId, scope, selectHash, ids: byScope.get(scope) ?? [], at: now });
|
|
2585
2770
|
}
|
|
@@ -2616,7 +2801,7 @@ export class FileMemoryEngineBackend {
|
|
|
2616
2801
|
erased.push({
|
|
2617
2802
|
id,
|
|
2618
2803
|
rev: row.rev,
|
|
2619
|
-
binding: binding !== undefined ? { state: "bound", scope: binding.scope
|
|
2804
|
+
binding: binding !== undefined ? { state: "bound", scope: binding.scope } : { state: "unbound" },
|
|
2620
2805
|
evidenceEv: ev,
|
|
2621
2806
|
projectionsRemoved: censusProjections.length,
|
|
2622
2807
|
sessions: preSessions,
|
|
@@ -2654,10 +2839,7 @@ export class FileMemoryEngineBackend {
|
|
|
2654
2839
|
continue;
|
|
2655
2840
|
const prior = priorDeletes.get(id);
|
|
2656
2841
|
if (prior !== undefined && custodyState === "complete") {
|
|
2657
|
-
|
|
2658
|
-
!Object.values(rows).some((row) => row.scope === prior.from.scope && row.slug === prior.from.slug) &&
|
|
2659
|
-
!existsSync(this.bindingAbsPath({ scope: prior.from.scope, slug: prior.from.slug }));
|
|
2660
|
-
erasedPreviously.push({ id, ev: prior.ev, at: prior.at, ...(fromFree ? { from: prior.from } : {}) });
|
|
2842
|
+
erasedPreviously.push({ id, ev: prior.ev, at: prior.at });
|
|
2661
2843
|
}
|
|
2662
2844
|
else {
|
|
2663
2845
|
notFoundRows.push({ id, ...(custodyState !== "complete" ? { historyUnknown: true } : {}) });
|
|
@@ -2669,7 +2851,9 @@ export class FileMemoryEngineBackend {
|
|
|
2669
2851
|
this.precheckTransfersAppendable();
|
|
2670
2852
|
const journal = { txn, ops, ledger2: ledgerEnvelope(rows, this.envelopeExtras), transfers };
|
|
2671
2853
|
this.refuseEscapingTargets(ops, "eraseWithEvidence (commit point)");
|
|
2854
|
+
const sweepRow = this.journalSweepRow(journal);
|
|
2672
2855
|
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
2856
|
+
this.recordJournalSweep(journal, sweepRow);
|
|
2673
2857
|
for (const op of ops) {
|
|
2674
2858
|
this.refuseEscapingTargets([op], "eraseWithEvidence (after the commit point; the journal is kept)");
|
|
2675
2859
|
if (op.kind === "delete") {
|
|
@@ -2691,40 +2875,12 @@ export class FileMemoryEngineBackend {
|
|
|
2691
2875
|
e.sessions = [...new Set([...e.sessions, ...lateSessions])].sort();
|
|
2692
2876
|
}
|
|
2693
2877
|
const resolvedSet = new Set(resolvedIds);
|
|
2694
|
-
const
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
let qNames = [];
|
|
2698
|
-
try {
|
|
2699
|
-
qNames = readdirSync(qDir);
|
|
2700
|
-
}
|
|
2701
|
-
catch (err) {
|
|
2702
|
-
if (err.code !== "ENOENT") {
|
|
2703
|
-
throw new ControlPlaneCorruptError(`erasure residual enumeration failed: the quarantine dir could not be read (${err.code ?? "io error"}) at ${qDir} — the attestation must not silently claim an empty residual set; retry after the filesystem fault clears (the deletions themselves are committed and a replay converges)`);
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
for (const name of qNames.sort()) {
|
|
2707
|
-
const text = readSafe(join(qDir, name));
|
|
2708
|
-
if (text === undefined) {
|
|
2709
|
-
quarantineOpaque++;
|
|
2710
|
-
continue;
|
|
2711
|
-
}
|
|
2712
|
-
const qid = parseEntryFile(text).id;
|
|
2713
|
-
if (qid === undefined) {
|
|
2714
|
-
quarantineOpaque++;
|
|
2715
|
-
continue;
|
|
2716
|
-
}
|
|
2717
|
-
if (resolvedSet.has(qid))
|
|
2718
|
-
quarantineHits.push(name);
|
|
2719
|
-
}
|
|
2720
|
-
const claimed = new Set([...erased.map((e) => e.id), ...erasedPreviously.map((e) => e.id)]);
|
|
2721
|
-
const notFoundSet = new Set(notFoundRows.map((n) => n.id));
|
|
2722
|
-
const complete = conflicts.length === 0 && resolvedIds.every((id) => claimed.has(id) || (custodyState === "complete" && notFoundSet.has(id)));
|
|
2723
|
-
return {
|
|
2724
|
-
v: 1,
|
|
2878
|
+
const quarantine = this.eraseQuarantineCopiesLocked(resolvedSet);
|
|
2879
|
+
const att = {
|
|
2880
|
+
v: 2,
|
|
2725
2881
|
requestId,
|
|
2726
2882
|
at: now,
|
|
2727
|
-
status:
|
|
2883
|
+
status: "partial",
|
|
2728
2884
|
evidenceCapability: "journal",
|
|
2729
2885
|
custodyState,
|
|
2730
2886
|
select: cloneErasureSelect(select),
|
|
@@ -2734,8 +2890,25 @@ export class FileMemoryEngineBackend {
|
|
|
2734
2890
|
notFound: notFoundRows,
|
|
2735
2891
|
...(erasedPreviously.length > 0 ? { erasedPreviously } : {}),
|
|
2736
2892
|
conflicts,
|
|
2737
|
-
residuals: {
|
|
2893
|
+
residuals: {
|
|
2894
|
+
carriers: {
|
|
2895
|
+
projection: { removed: erased.reduce((n, e) => n + e.projectionsRemoved, 0), remaining: 0 },
|
|
2896
|
+
shadow: { removed: ops.filter((op) => op.kind === "shadow-delete").length, remaining: 0 },
|
|
2897
|
+
indexLine: readErasureSweep(this.controlPlaneRoot, this.directoryRoot, requestId).length > 0 ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2898
|
+
quarantineCopy: { removed: quarantine.removed, remaining: quarantine.remaining },
|
|
2899
|
+
planArchive: this.controlDirHoldsAnything(CONSOLIDATION_DRIVER_PLANS_DIR) ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2900
|
+
planWorkbook: this.controlDirHoldsAnything(CONSOLIDATION_PLANS_DIR) ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2901
|
+
evidenceBinding: { removed: 0, remaining: chain.filter((r) => typeof r.parsed.id === "string" && resolvedSet.has(r.parsed.id) && (spellsSlug(r.parsed.from) || spellsSlug(r.parsed.to))).length },
|
|
2902
|
+
backendDerived: { removed: 0, remaining: 0 },
|
|
2903
|
+
},
|
|
2904
|
+
quarantineUnattributed: { count: quarantine.unattributed },
|
|
2905
|
+
derivedEntries: { count: new Set(resolvedIds.flatMap((id) => [...(censusRead?.distilledFrom.get(id) ?? [])]).filter((id) => !resolvedSet.has(id))).size },
|
|
2906
|
+
replay: "converges",
|
|
2907
|
+
propagation: "local-store-only",
|
|
2908
|
+
},
|
|
2738
2909
|
};
|
|
2910
|
+
att.status = erasureStatusOf(att);
|
|
2911
|
+
return att;
|
|
2739
2912
|
}
|
|
2740
2913
|
catch (err) {
|
|
2741
2914
|
this.ledger = undefined;
|
|
@@ -3116,9 +3289,9 @@ export class FileMemoryEngineBackend {
|
|
|
3116
3289
|
continue;
|
|
3117
3290
|
}
|
|
3118
3291
|
if (channel === "delete") {
|
|
3119
|
-
const
|
|
3120
|
-
if (
|
|
3121
|
-
if (scopeSet.has(
|
|
3292
|
+
const scope = typeof e.scope === "string" ? e.scope : e.from?.scope;
|
|
3293
|
+
if (typeof scope === "string") {
|
|
3294
|
+
if (scopeSet.has(scope))
|
|
3122
3295
|
custody.push(e);
|
|
3123
3296
|
}
|
|
3124
3297
|
else if (fullStore) {
|