@sema-agent/core 7.63.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 +408 -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.js +20 -3
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +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/checkpoint-queries.d.ts +9 -6
- package/dist/core/checkpoint-queries.js +8 -3
- package/dist/core/checkpoint-store.d.ts +5 -1
- package/dist/core/context-settings.d.ts +40 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +26 -6
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +24 -1
- 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/governance-codes.d.ts +3 -1
- package/dist/core/governance-codes.js +4 -0
- 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.d.ts +3 -2
- package/dist/core/memory-engine/consolidation.js +16 -0
- 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/delegation-settlement.d.ts +21 -5
- package/dist/core/memory-engine/delegation-settlement.js +217 -26
- package/dist/core/memory-engine/dual-root.js +2 -2
- package/dist/core/memory-engine/engine.d.ts +38 -23
- package/dist/core/memory-engine/engine.js +14 -14
- package/dist/core/memory-engine/file-backend.d.ts +41 -65
- package/dist/core/memory-engine/file-backend.js +59 -166
- package/dist/core/memory-engine/index.d.ts +3 -2
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/layout.d.ts +6 -1
- package/dist/core/memory-engine/layout.js +12 -7
- package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
- package/dist/core/memory-engine/memory-backend-contract.js +158 -2
- package/dist/core/memory-engine/memory-deployment.d.ts +11 -3
- package/dist/core/memory-engine/memory-deployment.js +31 -6
- 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/session-write-home.d.ts +34 -1
- package/dist/core/memory-engine/session-write-home.js +37 -10
- package/dist/core/memory-engine/types.d.ts +44 -7
- package/dist/core/memory-engine/types.js +2 -1
- 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/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +21 -10
- package/dist/core/permission-rule-consent.js +50 -23
- package/dist/core/permission-rule-store.d.ts +41 -16
- package/dist/core/permission-rule-store.js +2 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -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/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 +21 -2
- 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 +11 -2
- package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
- package/dist/core/runner/memory-consolidation-driver.js +8 -5
- package/dist/core/runner/prepare-ask-lane.js +3 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
- 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-gate-stations.d.ts +5 -0
- package/dist/core/runner/prepare-gate-stations.js +5 -5
- package/dist/core/runner/prepare-hands-readface.js +1 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
- package/dist/core/runner/prepare-inherited-gate.js +4 -2
- package/dist/core/runner/prepare-memory.d.ts +4 -0
- package/dist/core/runner/prepare-memory.js +14 -20
- 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 +15 -10
- 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/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 +8 -4
- 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-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/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +1 -1
- package/dist/core/session-checkout.d.ts +63 -3
- package/dist/core/session-checkout.js +152 -58
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/task-event.d.ts +9 -5
- package/dist/core/task-notification.d.ts +110 -31
- package/dist/core/task-notification.js +180 -100
- package/dist/core/task-registry-agent.d.ts +11 -0
- package/dist/core/task-registry-agent.js +11 -3
- package/dist/core/task-registry-shared.d.ts +7 -0
- package/dist/core/task-registry.d.ts +18 -0
- package/dist/core/task-registry.js +27 -8
- package/dist/core/task-spec.d.ts +7 -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 +18 -1
- package/dist/core/tool-policy.js +16 -7
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +4 -0
- package/dist/core/trace.d.ts +3 -2
- 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/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +1 -0
- package/dist/engine/session/session.d.ts +7 -1
- package/dist/engine/session/session.js +5 -2
- package/dist/index.d.ts +7 -5
- package/dist/index.js +7 -5
- package/dist/orchestration/run-workflow-tool.d.ts +4 -0
- package/dist/orchestration/run-workflow-tool.js +7 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +2 -1
- 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/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/read-deny.d.ts +15 -2
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +7 -7
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +63 -1
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
|
@@ -9,7 +9,7 @@ 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, carriesEntry, scanEntryFiles } from "./entry-scan.js";
|
|
12
|
-
import { ControlPlaneCorruptError, CURSORS_FILE, QUARANTINE_DIR,
|
|
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
14
|
import { CONSOLIDATION_DRIVER_PLANS_DIR, CONSOLIDATION_PLANS_DIR, fileGovernanceStore } from "./consolidation.js";
|
|
15
15
|
import { canonicalExpectedScopes, expectedScopesInvalid, firstOutsideExpectedScopes } from "./export-bundle.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,26 @@ 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}`);
|
|
349
321
|
}
|
|
350
|
-
|
|
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;
|
|
330
|
+
}
|
|
331
|
+
return { rows, envelopeExtras };
|
|
351
332
|
}
|
|
352
333
|
function ledgerFormOnDisk(controlDir) {
|
|
353
334
|
const path = join(controlDir, LEDGER_FILE);
|
|
@@ -355,7 +336,8 @@ function ledgerFormOnDisk(controlDir) {
|
|
|
355
336
|
if (raw === undefined)
|
|
356
337
|
return "absent";
|
|
357
338
|
try {
|
|
358
|
-
|
|
339
|
+
parseLedgerText(raw, path);
|
|
340
|
+
return "v2";
|
|
359
341
|
}
|
|
360
342
|
catch (err) {
|
|
361
343
|
if (err instanceof ControlPlaneCorruptError)
|
|
@@ -622,8 +604,6 @@ export class FileMemoryEngineBackend {
|
|
|
622
604
|
onIncident;
|
|
623
605
|
ledger;
|
|
624
606
|
envelopeExtras;
|
|
625
|
-
persistedSchemaVersion;
|
|
626
|
-
announcedV1Compat = false;
|
|
627
607
|
unboundRowsKnown = false;
|
|
628
608
|
adoptionNoticeKeys = new Set();
|
|
629
609
|
transfersAppendFault;
|
|
@@ -650,7 +630,7 @@ export class FileMemoryEngineBackend {
|
|
|
650
630
|
}
|
|
651
631
|
catch {
|
|
652
632
|
}
|
|
653
|
-
if (this.
|
|
633
|
+
if (this.ledger !== undefined && hasUnboundRows(this.ledger)) {
|
|
654
634
|
let layoutDerivesPaths = false;
|
|
655
635
|
try {
|
|
656
636
|
const shape = scopeRegistryShape(this.controlPlaneRoot);
|
|
@@ -705,10 +685,9 @@ export class FileMemoryEngineBackend {
|
|
|
705
685
|
this.ledger = undefined;
|
|
706
686
|
this.loadLedger();
|
|
707
687
|
registeredScopes(this.controlPlaneRoot);
|
|
708
|
-
if (
|
|
688
|
+
if (hasUnboundRows(this.loadLedger()))
|
|
709
689
|
this.tryOpportunisticMigrate();
|
|
710
|
-
|
|
711
|
-
this.announceUnboundRows(this.loadLedger());
|
|
690
|
+
this.announceUnboundRows(this.loadLedger());
|
|
712
691
|
}
|
|
713
692
|
drainInboundFindings() {
|
|
714
693
|
const out = this.inboundFindings;
|
|
@@ -728,37 +707,21 @@ export class FileMemoryEngineBackend {
|
|
|
728
707
|
const raw = readControlFileOrAbsent(path, "committed-rev ledger");
|
|
729
708
|
if (raw === undefined) {
|
|
730
709
|
this.ledger = Object.create(null);
|
|
731
|
-
this.persistedSchemaVersion = "v2";
|
|
732
710
|
this.unboundRowsKnown = false;
|
|
733
711
|
return this.ledger;
|
|
734
712
|
}
|
|
735
713
|
const parsed = parseLedgerText(raw, path);
|
|
736
714
|
this.ledger = parsed.rows;
|
|
737
715
|
this.envelopeExtras = parsed.envelopeExtras;
|
|
738
|
-
this.persistedSchemaVersion = parsed.form;
|
|
739
716
|
this.unboundRowsKnown = hasUnboundRows(parsed.rows);
|
|
740
|
-
if (parsed.form === "v1" && !this.announcedV1Compat) {
|
|
741
|
-
this.announcedV1Compat = true;
|
|
742
|
-
this.enqueueExternalItems("every-scope", ["memory ledger v1-compat active — v2 binding guarantees not yet in force (the migration runs at the next uncontended entry)"]);
|
|
743
|
-
}
|
|
744
717
|
return this.ledger;
|
|
745
718
|
}
|
|
746
719
|
saveLedger() {
|
|
747
720
|
if (!this.ledger)
|
|
748
721
|
return;
|
|
749
|
-
if (this.persistedSchemaVersion !== "v2") {
|
|
750
|
-
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)");
|
|
751
|
-
}
|
|
752
722
|
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(ledgerEnvelope(this.ledger, this.envelopeExtras), null, 2)}\n`);
|
|
753
723
|
this.unboundRowsKnown = hasUnboundRows(this.ledger);
|
|
754
724
|
}
|
|
755
|
-
persistLedgerV1(rows) {
|
|
756
|
-
const map = Object.create(null);
|
|
757
|
-
for (const [id, row] of rowsEntries(rows))
|
|
758
|
-
map[id] = row.rev;
|
|
759
|
-
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(map, null, 2)}\n`);
|
|
760
|
-
this.unboundRowsKnown = Object.keys(map).length > 0;
|
|
761
|
-
}
|
|
762
725
|
enqueueExternalItems(to, items, opts) {
|
|
763
726
|
if (items.length === 0 && opts?.supersedesPrefix === undefined)
|
|
764
727
|
return;
|
|
@@ -889,28 +852,6 @@ export class FileMemoryEngineBackend {
|
|
|
889
852
|
}
|
|
890
853
|
return { complete, byId, distilledFrom };
|
|
891
854
|
}
|
|
892
|
-
writeV1BackupOnce() {
|
|
893
|
-
const raw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
894
|
-
if (raw === undefined)
|
|
895
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger vanished under the migration lock: ${join(this.controlPlaneRoot, LEDGER_FILE)}`);
|
|
896
|
-
const bak = join(this.controlPlaneRoot, LEDGER_V1_BACKUP_FILE);
|
|
897
|
-
let fd;
|
|
898
|
-
try {
|
|
899
|
-
fd = openSync(bak, "wx", 0o600);
|
|
900
|
-
}
|
|
901
|
-
catch (err) {
|
|
902
|
-
if (err.code === "EEXIST")
|
|
903
|
-
return;
|
|
904
|
-
throw err;
|
|
905
|
-
}
|
|
906
|
-
try {
|
|
907
|
-
writeAllSync(fd, raw);
|
|
908
|
-
fsyncSync(fd);
|
|
909
|
-
}
|
|
910
|
-
finally {
|
|
911
|
-
closeSync(fd);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
855
|
tryAcquireTxnLockSync() {
|
|
915
856
|
return tryStoreTxnLock(this.controlPlaneRoot, { now: this.now });
|
|
916
857
|
}
|
|
@@ -930,21 +871,19 @@ export class FileMemoryEngineBackend {
|
|
|
930
871
|
migrateLockedIfNeeded(lockToken) {
|
|
931
872
|
this.ledger = undefined;
|
|
932
873
|
const rows = this.loadLedger();
|
|
933
|
-
if (
|
|
874
|
+
if (!hasUnboundRows(rows))
|
|
934
875
|
return;
|
|
935
|
-
const fullMigration = this.persistedSchemaVersion === "v1";
|
|
936
876
|
const census = this.censusProjectionsLocked();
|
|
937
877
|
if (!census.complete) {
|
|
938
|
-
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");
|
|
939
879
|
return;
|
|
940
880
|
}
|
|
941
881
|
const now = this.now();
|
|
942
882
|
const next = Object.create(null);
|
|
943
883
|
const bound = [];
|
|
944
|
-
const unbound = [];
|
|
945
884
|
const events = [];
|
|
946
885
|
for (const [id, row] of rowsEntries(rows)) {
|
|
947
|
-
if (
|
|
886
|
+
if (rowsBinding(rows, id) !== undefined) {
|
|
948
887
|
next[id] = { ...row };
|
|
949
888
|
continue;
|
|
950
889
|
}
|
|
@@ -953,35 +892,23 @@ export class FileMemoryEngineBackend {
|
|
|
953
892
|
if (projections.length === 1 && sole !== undefined) {
|
|
954
893
|
next[id] = { ...row, scope: sole.scope, slug: sole.slug };
|
|
955
894
|
bound.push(id);
|
|
956
|
-
|
|
957
|
-
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 });
|
|
958
896
|
}
|
|
959
897
|
else {
|
|
960
898
|
next[id] = { ...row };
|
|
961
|
-
unbound.push(`${id} (${projections.length} projection(s))`);
|
|
962
899
|
}
|
|
963
900
|
}
|
|
964
|
-
if (
|
|
965
|
-
this.writeV1BackupOnce();
|
|
966
|
-
events.push({ ev: randomUUID(), channel: "migration", boundRows: bound.length, unboundRows: unbound.length, at: now });
|
|
967
|
-
}
|
|
968
|
-
else if (bound.length === 0) {
|
|
901
|
+
if (bound.length === 0)
|
|
969
902
|
return;
|
|
970
|
-
}
|
|
971
903
|
this.assertTxnLockOwnership(lockToken);
|
|
972
904
|
this.precheckTransfersAppendable();
|
|
973
905
|
const journal = { txn: `${Date.now()}-migrate`, ops: [], ledger2: ledgerEnvelope(next, this.envelopeExtras), transfers: events };
|
|
974
906
|
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
975
907
|
this.ledger = next;
|
|
976
|
-
this.persistedSchemaVersion = "v2";
|
|
977
908
|
this.saveLedger();
|
|
978
909
|
this.appendTransfers(events);
|
|
979
910
|
rmSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), { force: true });
|
|
980
|
-
this.enqueueExternalItems("operator", [
|
|
981
|
-
fullMigration
|
|
982
|
-
? `memory ledger upgraded to v2 (${bound.length} row(s) bound, ${unbound.length} unbound${unbound.length > 0 ? `: ${unbound.slice(0, 8).join(", ")}${unbound.length > 8 ? ", …" : ""}` : ""})`
|
|
983
|
-
: `memory ledger unbound row(s) converged to bound: ${bound.slice(0, 8).join(", ")}${bound.length > 8 ? ", …" : ""}`,
|
|
984
|
-
]);
|
|
911
|
+
this.enqueueExternalItems("operator", [`memory ledger unbound row(s) converged to bound: ${bound.slice(0, 8).join(", ")}${bound.length > 8 ? ", …" : ""}`]);
|
|
985
912
|
}
|
|
986
913
|
chainDegradedMarkerPresent() {
|
|
987
914
|
return readControlFileOrAbsent(join(this.controlPlaneRoot, CHAIN_DEGRADED_FILE), "evidence-chain degradation marker") !== undefined;
|
|
@@ -1184,8 +1111,7 @@ export class FileMemoryEngineBackend {
|
|
|
1184
1111
|
const raw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
1185
1112
|
if (raw === undefined)
|
|
1186
1113
|
return Object.create(null);
|
|
1187
|
-
|
|
1188
|
-
return parsed.form === "v2" ? parsed.rows : Object.create(null);
|
|
1114
|
+
return parseLedgerText(raw, join(this.controlPlaneRoot, LEDGER_FILE)).rows;
|
|
1189
1115
|
}
|
|
1190
1116
|
catch (err) {
|
|
1191
1117
|
const code = err.code ?? (err instanceof ControlPlaneCorruptError ? "corrupt" : "io error");
|
|
@@ -1263,18 +1189,7 @@ export class FileMemoryEngineBackend {
|
|
|
1263
1189
|
const raw = readControlFileOrAbsent(jp, "transaction journal");
|
|
1264
1190
|
if (raw !== undefined) {
|
|
1265
1191
|
const journal = parseJournal(raw, jp);
|
|
1266
|
-
const { rows: snapshotRows, extras: snapshotExtras
|
|
1267
|
-
if (snapshotForm === "v1") {
|
|
1268
|
-
try {
|
|
1269
|
-
if (ledgerFormOnDisk(this.controlPlaneRoot) === "v2") {
|
|
1270
|
-
this.enqueueExternalItems("every-scope", [
|
|
1271
|
-
"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.",
|
|
1272
|
-
]);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
catch {
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1192
|
+
const { rows: snapshotRows, extras: snapshotExtras } = journalLedgerSnapshot(journal, jp);
|
|
1278
1193
|
for (const op of journal.ops) {
|
|
1279
1194
|
const invalid = journalOpInvalid(op, this.directoryRoot);
|
|
1280
1195
|
if (invalid !== undefined) {
|
|
@@ -1301,8 +1216,6 @@ export class FileMemoryEngineBackend {
|
|
|
1301
1216
|
journalEvs.set(e.ev, canonical);
|
|
1302
1217
|
journalChainForms.set(e.ev, canonicalJsonStringify(chainFormOf(e)));
|
|
1303
1218
|
}
|
|
1304
|
-
if (snapshotForm === "v1")
|
|
1305
|
-
throw new ControlPlaneCorruptError(`transaction journal carries transfers with a v1 snapshot (impossible form): ${jp}`);
|
|
1306
1219
|
if (journalEvs.size > 0) {
|
|
1307
1220
|
for (const row of this.readTransferChain(fenceToken)) {
|
|
1308
1221
|
const j = journalEvs.get(row.ev);
|
|
@@ -1459,19 +1372,11 @@ export class FileMemoryEngineBackend {
|
|
|
1459
1372
|
}
|
|
1460
1373
|
this.recoveryCommitProbe?.();
|
|
1461
1374
|
this.assertTxnLockOwnership(fenceToken);
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
this.recordJournalSweep(journal);
|
|
1468
|
-
this.appendTransfers(journal.transfers ?? []);
|
|
1469
|
-
}
|
|
1470
|
-
else {
|
|
1471
|
-
this.ledger = snapshotRows;
|
|
1472
|
-
this.persistedSchemaVersion = "v1";
|
|
1473
|
-
this.persistLedgerV1(snapshotRows);
|
|
1474
|
-
}
|
|
1375
|
+
this.ledger = snapshotRows;
|
|
1376
|
+
this.envelopeExtras = snapshotExtras;
|
|
1377
|
+
this.saveLedger();
|
|
1378
|
+
this.recordJournalSweep(journal);
|
|
1379
|
+
this.appendTransfers(journal.transfers ?? []);
|
|
1475
1380
|
if (typeof journal.txn === "string") {
|
|
1476
1381
|
this.closeJournalIfOurs(journal.txn);
|
|
1477
1382
|
}
|
|
@@ -1585,7 +1490,7 @@ export class FileMemoryEngineBackend {
|
|
|
1585
1490
|
if (memo !== undefined)
|
|
1586
1491
|
return memo;
|
|
1587
1492
|
}
|
|
1588
|
-
if (this.
|
|
1493
|
+
if (this.unboundRowsKnown)
|
|
1589
1494
|
this.tryOpportunisticMigrate();
|
|
1590
1495
|
const dir = this.scopeDir(scope);
|
|
1591
1496
|
const files = scanEntryFiles(dir);
|
|
@@ -1937,7 +1842,7 @@ export class FileMemoryEngineBackend {
|
|
|
1937
1842
|
restrictedIdlessScope;
|
|
1938
1843
|
restrictedIdlessBaseline;
|
|
1939
1844
|
readScopeCommitted(scope, audit) {
|
|
1940
|
-
if (this.
|
|
1845
|
+
if (this.unboundRowsKnown)
|
|
1941
1846
|
this.tryOpportunisticMigrate();
|
|
1942
1847
|
const dir = this.scopeDir(scope);
|
|
1943
1848
|
const files = scanEntryFiles(dir, {
|
|
@@ -2132,11 +2037,10 @@ export class FileMemoryEngineBackend {
|
|
|
2132
2037
|
this.readScopeCommitted(scope, true);
|
|
2133
2038
|
const idlessBaseline = opts?.idlessWriteScope !== undefined && opts.idlessWriteScope === this.restrictedIdlessScope ? this.restrictedIdlessBaseline : undefined;
|
|
2134
2039
|
const idlessScope = idlessBaseline !== undefined ? opts?.idlessWriteScope : undefined;
|
|
2135
|
-
if (
|
|
2040
|
+
if (hasUnboundRows(this.loadLedger()))
|
|
2136
2041
|
this.tryOpportunisticMigrate();
|
|
2137
2042
|
const rows = { ...this.loadLedger() };
|
|
2138
|
-
|
|
2139
|
-
this.announceUnboundRows(rows);
|
|
2043
|
+
this.announceUnboundRows(rows);
|
|
2140
2044
|
const present = new Map();
|
|
2141
2045
|
let complete = true;
|
|
2142
2046
|
for (const scope of Object.keys(registeredScopes(this.controlPlaneRoot))) {
|
|
@@ -2979,13 +2883,7 @@ export class FileMemoryEngineBackend {
|
|
|
2979
2883
|
const raw = readControlFileOrAbsent(path, "committed-rev ledger");
|
|
2980
2884
|
if (raw === undefined)
|
|
2981
2885
|
return { raw, rows: Object.create(null) };
|
|
2982
|
-
|
|
2983
|
-
if (parsed.form === "v1") {
|
|
2984
|
-
throw new Error(`memory audit read refused: the committed-rev ledger at ${path} is still schema v1 (pre-binding) — ` +
|
|
2985
|
-
`migrate first (the store migrates itself at its next uncontended write/read entry or checkControlPlane); ` +
|
|
2986
|
-
`an audit read never triggers the migration`);
|
|
2987
|
-
}
|
|
2988
|
-
return { raw, rows: parsed.rows };
|
|
2886
|
+
return { raw, rows: parseLedgerText(raw, path).rows };
|
|
2989
2887
|
}
|
|
2990
2888
|
async auditStable(read) {
|
|
2991
2889
|
for (let attempt = 0; attempt < FileMemoryEngineBackend.AUDIT_FENCE_ATTEMPTS; attempt++) {
|
|
@@ -3132,7 +3030,7 @@ export class FileMemoryEngineBackend {
|
|
|
3132
3030
|
const ledgerRaw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
3133
3031
|
if (ledgerRaw !== undefined) {
|
|
3134
3032
|
const parsed = parseLedgerText(ledgerRaw, join(this.controlPlaneRoot, LEDGER_FILE));
|
|
3135
|
-
if (
|
|
3033
|
+
if (Object.prototype.hasOwnProperty.call(parsed.rows, id) && parsed.rows[id]?.prev !== undefined) {
|
|
3136
3034
|
out.state = "damaged";
|
|
3137
3035
|
}
|
|
3138
3036
|
}
|
|
@@ -3246,7 +3144,7 @@ export class FileMemoryEngineBackend {
|
|
|
3246
3144
|
const feed = (label, text) => {
|
|
3247
3145
|
h.update(JSON.stringify([label, text]));
|
|
3248
3146
|
};
|
|
3249
|
-
for (const file of
|
|
3147
|
+
for (const file of STRICT_CONTROL_PLANE_LEDGERS.map((ledger) => fileGovernanceDocOf(ledger).file)) {
|
|
3250
3148
|
feed(file, readControlFileOrAbsent(join(this.controlPlaneRoot, file), `${file} (export fence)`) ?? "<absent>");
|
|
3251
3149
|
let journalRaw;
|
|
3252
3150
|
try {
|
|
@@ -3420,9 +3318,6 @@ export class FileMemoryEngineBackend {
|
|
|
3420
3318
|
this.recoverJournal({ token: lock.token });
|
|
3421
3319
|
this.adoptLayoutLocked(lock.token);
|
|
3422
3320
|
const rows = this.loadLedger();
|
|
3423
|
-
if (this.persistedSchemaVersion !== "v2") {
|
|
3424
|
-
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);
|
|
3425
|
-
}
|
|
3426
3321
|
if (this.chainDegradedMarkerPresent()) {
|
|
3427
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);
|
|
3428
3323
|
}
|
|
@@ -3504,8 +3399,6 @@ export class FileMemoryEngineBackend {
|
|
|
3504
3399
|
this.recoverJournal({ token: lock.token });
|
|
3505
3400
|
this.adoptLayoutLocked(lock.token);
|
|
3506
3401
|
const rows = this.loadLedger();
|
|
3507
|
-
if (this.persistedSchemaVersion !== "v2")
|
|
3508
|
-
return { custody: [], unbound: [], complete: false, unsliceableCustody: 0, reason: "the committed-rev ledger is still schema v1 (migrate first)" };
|
|
3509
3402
|
if (this.chainDegradedMarkerPresent()) {
|
|
3510
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" };
|
|
3511
3404
|
}
|
|
@@ -14,8 +14,9 @@ export { CONSOLIDATION_DEFAULTS, ConsolidationRefusedError, MEMORY_SEARCH_SUPERS
|
|
|
14
14
|
export { DISTILLER_DEFAULT_MAX_INPUTS_PER_PRODUCT, LLM_DISTILLER_CONTRACT, LLM_DISTILLER_CONTRACT_DL2, LLM_DISTILLER_CONTRACT_DL3, LLM_DISTILLER_CONTRACTS, MEMORY_DISTILLER_CONTRACT_V1, contractGroupingDiff, driveConsolidationToFixpoint, isAliasModelId, llmPlanDistiller, mintExposurePartitionedPlan, mintLlmConsolidationPlan, MEMORY_DISTILLER_PURITY_CONTRACT_V1, detectCleanArmVerbatimLeak, type CleanArmLeakFinding, type CleanArmLeakVerdict, type MemoryDistillerPurityContract, openAiCompatChatSeat, parseJsonAnswer, planParseRepairs, sanitizeLlmGroups, scheduleUnderFuse, type ConsolidationDistillFn, type ConsolidationDriveCycleRow, type ConsolidationDriveEngine, type ConsolidationDriveResult, type ConsolidationFoldState, type DistillerCandidate, type DistillerChatAnswer, type DistillerChatFn, type DistillerChatRequest, type FuseSchedule, type LlmConsolidationPlan, type LlmConsolidationPlanArm, type LlmConsolidationPlanProduct, type LlmDistillerContract, type MintLlmConsolidationPlanResult, type PlanParseRepairs, type SanitizedLlmGroups, } from "./distiller.js";
|
|
15
15
|
export { CONSOLIDATION_WRITE_REFUSED_CODE, runMemoryConsolidationDriver, type ConsolidationDriverEngine, type ConsolidationDriverRunRow, type ConsolidationRunReceipt, type ConsolidationWriteJudge, type ConsolidationWriteTarget, type RunMemoryConsolidationOptions, } from "./consolidation-driver.js";
|
|
16
16
|
export type { OriginClearanceRow, OriginClearanceEvent, OriginClearanceShadow } from "./origin-clearance.js";
|
|
17
|
-
export { MEMORY_GOVERNANCE_DOC_NAMES, MEMORY_ORIGIN_CAUSES, writableRootOf } from "./types.js";
|
|
18
|
-
export
|
|
17
|
+
export { MEMORY_CONTROL_OBJECT_KINDS, MEMORY_GOVERNANCE_DOC_NAMES, MEMORY_ORIGIN_CAUSES, writableRootOf } from "./types.js";
|
|
18
|
+
export { adoptReplicaControlPlane, replicaControlPlaneStrays, type ControlPlaneAdoptionReport, type ReplicaControlPlaneStrays } from "./control-plane-adoption.js";
|
|
19
|
+
export type { ConsolidationTx, MemoryBackend, MemoryGovernanceStore, MemoryControlObjectKind, MemoryGovernanceDocName, MemoryGovernanceDocs, MemoryEntry, MemoryEntryFrontmatter, MemoryEntryOrigin, MemoryOriginCause, MemoryScopeEnumeration, MemoryEntryDistilled, MemoryEntryDistilledInput, MemoryEntryHeader, ScoredMemoryEntry, NotePatch, PatchReport, MaterializedFile, MemorySessionHandle, HarvestReport, HarvestRejection, HarvestRejectionCode, MemoryAnnouncement, ScanFinding, } from "./types.js";
|
|
19
20
|
export { memoryBackendContract, assertMemoryBackendSearchEquivalence, memoryGovernanceStoreContract, type MemoryBackendContractHooks, type MemoryGovernanceStoreContractHooks, } from "./memory-backend-contract.js";
|
|
20
21
|
export { SCOPE_SEGMENT_MAX_ENCODED, PROJECT_MARKER_PATH, encodeScopeSegment, decodeScopeSegment, parseScopeKey, formatUserScope, formatUserLocalScope, formatOrgScope, formatProjScope, formatUserProjScope, isPersonalScope, isReplicableScope, isOrgScopeKey, assertScopeContractPlacement, formatProjectMarker, parseProjectMarker, resolveProjectId, PROJECT_ID_REGEX, type ParsedScopeKey, } from "./scope-contract.js";
|
|
21
22
|
export { migrateScope, type MigrateScopeReport } from "./migrate.js";
|
|
@@ -13,7 +13,8 @@ export { deriveShadowedSet } from "./shadowing.js";
|
|
|
13
13
|
export { CONSOLIDATION_DEFAULTS, ConsolidationRefusedError, MEMORY_SEARCH_SUPERSEDED_TAG, consolidationTypeEligible, deriveSupersededSet, memorySupersededNote, supersessionFuseCeiling, DELETION_FUSE_FLOOR, fileGovernanceStore, memoryGovernanceDurability, CONSOLIDATION_RUN_STOP_REASONS, } from "./consolidation.js";
|
|
14
14
|
export { DISTILLER_DEFAULT_MAX_INPUTS_PER_PRODUCT, LLM_DISTILLER_CONTRACT, LLM_DISTILLER_CONTRACT_DL2, LLM_DISTILLER_CONTRACT_DL3, LLM_DISTILLER_CONTRACTS, MEMORY_DISTILLER_CONTRACT_V1, contractGroupingDiff, driveConsolidationToFixpoint, isAliasModelId, llmPlanDistiller, mintExposurePartitionedPlan, mintLlmConsolidationPlan, MEMORY_DISTILLER_PURITY_CONTRACT_V1, detectCleanArmVerbatimLeak, openAiCompatChatSeat, parseJsonAnswer, planParseRepairs, sanitizeLlmGroups, scheduleUnderFuse, } from "./distiller.js";
|
|
15
15
|
export { CONSOLIDATION_WRITE_REFUSED_CODE, runMemoryConsolidationDriver, } from "./consolidation-driver.js";
|
|
16
|
-
export { MEMORY_GOVERNANCE_DOC_NAMES, MEMORY_ORIGIN_CAUSES, writableRootOf } from "./types.js";
|
|
16
|
+
export { MEMORY_CONTROL_OBJECT_KINDS, MEMORY_GOVERNANCE_DOC_NAMES, MEMORY_ORIGIN_CAUSES, writableRootOf } from "./types.js";
|
|
17
|
+
export { adoptReplicaControlPlane, replicaControlPlaneStrays } from "./control-plane-adoption.js";
|
|
17
18
|
export { memoryBackendContract, assertMemoryBackendSearchEquivalence, memoryGovernanceStoreContract, } from "./memory-backend-contract.js";
|
|
18
19
|
export { SCOPE_SEGMENT_MAX_ENCODED, PROJECT_MARKER_PATH, encodeScopeSegment, decodeScopeSegment, parseScopeKey, formatUserScope, formatUserLocalScope, formatOrgScope, formatProjScope, formatUserProjScope, isPersonalScope, isReplicableScope, isOrgScopeKey, assertScopeContractPlacement, formatProjectMarker, parseProjectMarker, resolveProjectId, PROJECT_ID_REGEX, } from "./scope-contract.js";
|
|
19
20
|
export { migrateScope } from "./migrate.js";
|
|
@@ -1334,8 +1334,13 @@ export declare function challengedEntryIds(docs: MemoryGovernanceDocs): Promise<
|
|
|
1334
1334
|
}>>;
|
|
1335
1335
|
/** Full event read (host audit / tests). Throws on corruption. */
|
|
1336
1336
|
export declare function readChallengeEvents(docs: MemoryGovernanceDocs): Promise<ChallengeEvent[]>;
|
|
1337
|
-
/** Which fail-closed control-plane ledger a rebuild targets
|
|
1337
|
+
/** Which fail-closed control-plane ledger a rebuild targets: the governance documents a host may explicitly reset and
|
|
1338
|
+
* announce (where a document is kept, and how it is read and changed, is the store's answer — {@link fileGovernanceDocOf}
|
|
1339
|
+
* for a File store; which of them may be cleared after corruption is this set's). Each member is a document name:
|
|
1340
|
+
* {@link fileGovernanceDocOf} takes nothing else, so a member outside the documents does not compile. */
|
|
1338
1341
|
export type StrictControlPlaneLedger = "lineage" | "challenges";
|
|
1342
|
+
/** The rebuild targets, in the order their files are read (the export fence fingerprints them in this order). */
|
|
1343
|
+
export declare const STRICT_CONTROL_PLANE_LEDGERS: readonly StrictControlPlaneLedger[];
|
|
1339
1344
|
/** What one rebuild did — the deployment's record of a taint-bearing account it chose to reset. */
|
|
1340
1345
|
export interface ControlPlaneRebuildReceipt {
|
|
1341
1346
|
ledger: StrictControlPlaneLedger;
|
|
@@ -2228,6 +2228,8 @@ const FILE_GOVERNANCE_DOCS = Object.freeze({
|
|
|
2228
2228
|
settlements: Object.freeze({ file: DELEGATION_SETTLEMENT_FILE, what: "memory delegation-settlement ledger" }),
|
|
2229
2229
|
"session-accounts": Object.freeze({ file: SESSION_ACCOUNTS_FILE, what: "memory session-account ledger" }),
|
|
2230
2230
|
announcements: Object.freeze({ file: ANNOUNCEMENTS_FILE, what: "memory announcement queue" }),
|
|
2231
|
+
holds: Object.freeze({ file: "holds.json", what: "memory instruction-hold ledger" }),
|
|
2232
|
+
"origin-clearances": Object.freeze({ file: "origin-clearances.json", what: "memory origin-clearance ledger" }),
|
|
2231
2233
|
});
|
|
2232
2234
|
export function fileGovernanceDocOf(name) {
|
|
2233
2235
|
if (typeof name !== "string" || !Object.prototype.hasOwnProperty.call(FILE_GOVERNANCE_DOCS, name)) {
|
|
@@ -2774,10 +2776,14 @@ export async function challengedEntryIds(docs) {
|
|
|
2774
2776
|
export async function readChallengeEvents(docs) {
|
|
2775
2777
|
return coerceChallenges(await docs.readDoc("challenges")).events;
|
|
2776
2778
|
}
|
|
2779
|
+
const STRICT_LEDGER_SHAPES = Object.freeze({
|
|
2780
|
+
lineage: Object.freeze({ coerce: (raw) => coerceLineage(raw), empty: () => ({ version: 1, committed: {}, pending: {} }) }),
|
|
2781
|
+
challenges: Object.freeze({ coerce: (raw) => coerceChallenges(raw), empty: () => ({ version: 1, events: [] }) }),
|
|
2782
|
+
});
|
|
2783
|
+
export const STRICT_CONTROL_PLANE_LEDGERS = Object.freeze(Object.keys(STRICT_LEDGER_SHAPES));
|
|
2777
2784
|
export function isStrictControlPlaneLedgerCorrupt(controlDir, ledger) {
|
|
2778
|
-
const
|
|
2779
|
-
const
|
|
2780
|
-
const coerce = ledger === "lineage" ? coerceLineage : coerceChallenges;
|
|
2785
|
+
const { file: fileName, what } = fileGovernanceDocOf(ledger);
|
|
2786
|
+
const { coerce } = STRICT_LEDGER_SHAPES[ledger];
|
|
2781
2787
|
try {
|
|
2782
2788
|
coerce(readStrictSidecar(controlDir, fileName, what));
|
|
2783
2789
|
return false;
|
|
@@ -2789,10 +2795,9 @@ export function isStrictControlPlaneLedgerCorrupt(controlDir, ledger) {
|
|
|
2789
2795
|
}
|
|
2790
2796
|
}
|
|
2791
2797
|
export function rebuildStrictControlPlaneLedger(controlDir, ledger, now) {
|
|
2792
|
-
const
|
|
2793
|
-
const
|
|
2794
|
-
const
|
|
2795
|
-
const empty = ledger === "lineage" ? { version: 1, committed: {}, pending: {} } : { version: 1, events: [] };
|
|
2798
|
+
const { file: fileName, what } = fileGovernanceDocOf(ledger);
|
|
2799
|
+
const { coerce } = STRICT_LEDGER_SHAPES[ledger];
|
|
2800
|
+
const empty = STRICT_LEDGER_SHAPES[ledger].empty();
|
|
2796
2801
|
ensureDirExists(controlDir);
|
|
2797
2802
|
const file = join(controlDir, fileName);
|
|
2798
2803
|
const journal = `${file}.journal`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MemoryBackend, type MemoryGovernanceDocName, type MemoryGovernanceStore } from "./types.js";
|
|
1
|
+
import { type MemoryBackend, type MemoryControlObjectKind, type MemoryGovernanceDocName, type MemoryGovernanceStore } from "./types.js";
|
|
2
2
|
export interface MemoryBackendContractHooks {
|
|
3
3
|
make: () => Promise<MemoryBackend> | MemoryBackend;
|
|
4
4
|
/** A second backend instance over the SAME storage as the given one (cross-instance CAS cases). */
|
|
@@ -33,8 +33,15 @@ export interface MemoryGovernanceStoreContractHooks {
|
|
|
33
33
|
make: () => Promise<MemoryGovernanceStore> | MemoryGovernanceStore;
|
|
34
34
|
/** Leave `store`'s record of `record` malformed in its own storage (bytes that are not the record's shape — for a
|
|
35
35
|
* governance document, bytes that do not parse): the fail-closed cases read it back and must be refused, never read
|
|
36
|
-
* as an empty record.
|
|
37
|
-
|
|
36
|
+
* as an empty record. For a control object, leave `{ object, name }` standing but unreadable (the File store: a
|
|
37
|
+
* directory or a link to nothing in its place), and `{ listing }` a kind whose names cannot be enumerated (the File
|
|
38
|
+
* store: a file where the kind's directory is). */
|
|
39
|
+
corrupt: (store: MemoryGovernanceStore, record: "gate" | "intents" | "run" | MemoryGovernanceDocName | {
|
|
40
|
+
readonly object: MemoryControlObjectKind;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly listing: MemoryControlObjectKind;
|
|
44
|
+
}) => Promise<void> | void;
|
|
38
45
|
/** Wrap each case (vitest `it`, …). Default: run sequentially. */
|
|
39
46
|
runAssertion?: (name: string, fn: () => Promise<void>) => void | Promise<void>;
|
|
40
47
|
}
|