@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.
Files changed (204) hide show
  1. package/CHANGELOG.md +408 -0
  2. package/dist/agents/cc-peer-directory.js +1 -0
  3. package/dist/agents/cc-peer-wire.d.ts +4 -0
  4. package/dist/agents/cc-peer-wire.js +1 -0
  5. package/dist/agents/cc-uds-peer-channel.js +5 -0
  6. package/dist/agents/cross-session-judge.d.ts +3 -1
  7. package/dist/agents/cross-session-judge.js +4 -1
  8. package/dist/agents/peer-directory.d.ts +8 -0
  9. package/dist/agents/peer-directory.js +4 -0
  10. package/dist/agents/peer-held-queue.d.ts +9 -3
  11. package/dist/agents/peer-held-queue.js +12 -9
  12. package/dist/agents/peer-idle.d.ts +20 -1
  13. package/dist/agents/peer-idle.js +23 -12
  14. package/dist/agents/peer-notice-route.d.ts +16 -5
  15. package/dist/agents/peer-notice-route.js +11 -9
  16. package/dist/agents/peer-notices.d.ts +25 -8
  17. package/dist/agents/peer-notices.js +6 -1
  18. package/dist/agents/peer-session-drain.d.ts +32 -6
  19. package/dist/agents/peer-session-drain.js +100 -26
  20. package/dist/agents/send-message-tool.d.ts +7 -0
  21. package/dist/agents/send-message-tool.js +18 -6
  22. package/dist/agents/subagent.js +20 -3
  23. package/dist/core/allow-entry.d.ts +4 -0
  24. package/dist/core/ask-origin.d.ts +1 -1
  25. package/dist/core/ask-origin.js +2 -2
  26. package/dist/core/ask-unresolvable-notice.d.ts +13 -4
  27. package/dist/core/ask-unresolvable-notice.js +10 -3
  28. package/dist/core/auto-compaction.d.ts +7 -5
  29. package/dist/core/background-agent-store.d.ts +7 -0
  30. package/dist/core/background-agent-store.js +3 -0
  31. package/dist/core/checkpoint-queries.d.ts +9 -6
  32. package/dist/core/checkpoint-queries.js +8 -3
  33. package/dist/core/checkpoint-store.d.ts +5 -1
  34. package/dist/core/context-settings.d.ts +40 -9
  35. package/dist/core/context-settings.js +32 -10
  36. package/dist/core/engine-attestation.d.ts +26 -6
  37. package/dist/core/engine-attestation.js +5 -1
  38. package/dist/core/engine-notice.d.ts +24 -1
  39. package/dist/core/extension-requester.d.ts +9 -0
  40. package/dist/core/extension-requester.js +7 -0
  41. package/dist/core/file-history-store.d.ts +28 -0
  42. package/dist/core/file-history-store.js +48 -5
  43. package/dist/core/fs-write-gate-policy.js +1 -1
  44. package/dist/core/gate-fold.js +2 -0
  45. package/dist/core/gate-lanes.js +2 -0
  46. package/dist/core/gate-outcome.d.ts +39 -2
  47. package/dist/core/gate-outcome.js +20 -1
  48. package/dist/core/governance-codes.d.ts +3 -1
  49. package/dist/core/governance-codes.js +4 -0
  50. package/dist/core/leg-identity.d.ts +19 -1
  51. package/dist/core/leg-identity.js +12 -0
  52. package/dist/core/mailbox-store.d.ts +39 -4
  53. package/dist/core/mailbox-store.js +14 -2
  54. package/dist/core/memory-engine/consolidation.d.ts +3 -2
  55. package/dist/core/memory-engine/consolidation.js +16 -0
  56. package/dist/core/memory-engine/control-objects.d.ts +25 -0
  57. package/dist/core/memory-engine/control-objects.js +151 -0
  58. package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
  59. package/dist/core/memory-engine/control-plane-adoption.js +159 -0
  60. package/dist/core/memory-engine/delegation-settlement.d.ts +21 -5
  61. package/dist/core/memory-engine/delegation-settlement.js +217 -26
  62. package/dist/core/memory-engine/dual-root.js +2 -2
  63. package/dist/core/memory-engine/engine.d.ts +38 -23
  64. package/dist/core/memory-engine/engine.js +14 -14
  65. package/dist/core/memory-engine/file-backend.d.ts +41 -65
  66. package/dist/core/memory-engine/file-backend.js +59 -166
  67. package/dist/core/memory-engine/index.d.ts +3 -2
  68. package/dist/core/memory-engine/index.js +2 -1
  69. package/dist/core/memory-engine/layout.d.ts +6 -1
  70. package/dist/core/memory-engine/layout.js +12 -7
  71. package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
  72. package/dist/core/memory-engine/memory-backend-contract.js +158 -2
  73. package/dist/core/memory-engine/memory-deployment.d.ts +11 -3
  74. package/dist/core/memory-engine/memory-deployment.js +31 -6
  75. package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
  76. package/dist/core/memory-engine/origin-clearance.js +68 -9
  77. package/dist/core/memory-engine/session-write-home.d.ts +34 -1
  78. package/dist/core/memory-engine/session-write-home.js +37 -10
  79. package/dist/core/memory-engine/types.d.ts +44 -7
  80. package/dist/core/memory-engine/types.js +2 -1
  81. package/dist/core/mode-policy.js +3 -3
  82. package/dist/core/mods/agent-stations.d.ts +18 -0
  83. package/dist/core/mods/agent-stations.js +8 -6
  84. package/dist/core/mods/extension-call.d.ts +4 -0
  85. package/dist/core/mods/extension-call.js +8 -0
  86. package/dist/core/mods/tool-call.js +3 -4
  87. package/dist/core/parent-spec-seat.d.ts +2 -2
  88. package/dist/core/peer-channel.d.ts +5 -0
  89. package/dist/core/permission-rule-consent.d.ts +21 -10
  90. package/dist/core/permission-rule-consent.js +50 -23
  91. package/dist/core/permission-rule-store.d.ts +41 -16
  92. package/dist/core/permission-rule-store.js +2 -0
  93. package/dist/core/refusal-echo.d.ts +20 -0
  94. package/dist/core/refusal-echo.js +33 -0
  95. package/dist/core/retention.d.ts +180 -10
  96. package/dist/core/retention.js +45 -0
  97. package/dist/core/retired-keys.d.ts +5 -0
  98. package/dist/core/retired-keys.js +3 -0
  99. package/dist/core/rule-offer-read.d.ts +0 -4
  100. package/dist/core/rule-offer-read.js +2 -18
  101. package/dist/core/runner/classifier-ladder.d.ts +7 -1
  102. package/dist/core/runner/classifier-ladder.js +4 -2
  103. package/dist/core/runner/compact-session.js +10 -7
  104. package/dist/core/runner/compaction-call-options.d.ts +7 -7
  105. package/dist/core/runner/compaction-call-options.js +3 -2
  106. package/dist/core/runner/contracts.d.ts +21 -2
  107. package/dist/core/runner/delegation-owner.d.ts +10 -3
  108. package/dist/core/runner/delegation-owner.js +4 -1
  109. package/dist/core/runner/gate-exit.d.ts +6 -0
  110. package/dist/core/runner/gate-exit.js +11 -2
  111. package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
  112. package/dist/core/runner/memory-consolidation-driver.js +8 -5
  113. package/dist/core/runner/prepare-ask-lane.js +3 -3
  114. package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
  115. package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
  116. package/dist/core/runner/prepare-config-doors.js +4 -0
  117. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  118. package/dist/core/runner/prepare-delegation-surface.js +2 -2
  119. package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
  120. package/dist/core/runner/prepare-gate-stations.js +5 -5
  121. package/dist/core/runner/prepare-hands-readface.js +1 -1
  122. package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
  123. package/dist/core/runner/prepare-inherited-gate.js +4 -2
  124. package/dist/core/runner/prepare-memory.d.ts +4 -0
  125. package/dist/core/runner/prepare-memory.js +14 -20
  126. package/dist/core/runner/prepare-policy-chain.js +7 -7
  127. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  128. package/dist/core/runner/prepare-task.js +15 -10
  129. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  130. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  131. package/dist/core/runner/resume-admission.d.ts +2 -2
  132. package/dist/core/runner/resume-admission.js +2 -23
  133. package/dist/core/runner/role-resolution-table.d.ts +98 -0
  134. package/dist/core/runner/role-resolution-table.js +62 -0
  135. package/dist/core/runner/run-compaction-machinery.js +2 -2
  136. package/dist/core/runner/run-identity-wiring.js +12 -9
  137. package/dist/core/runner/run-leg.js +8 -4
  138. package/dist/core/runner/run-notification-lane.js +22 -22
  139. package/dist/core/runner/run-recovery-lanes.js +3 -3
  140. package/dist/core/runner/run-terminal-adoption.js +1 -1
  141. package/dist/core/runner/run-turn-boundary.js +14 -15
  142. package/dist/core/runner/runtask.js +1 -1
  143. package/dist/core/runner/tool-occurrence.d.ts +4 -2
  144. package/dist/core/runner/tool-occurrence.js +2 -2
  145. package/dist/core/runner-deps.d.ts +1 -1
  146. package/dist/core/session-checkout.d.ts +63 -3
  147. package/dist/core/session-checkout.js +152 -58
  148. package/dist/core/shell-read-silence.js +8 -0
  149. package/dist/core/store-contracts/peer-directory-contract.js +8 -1
  150. package/dist/core/task-event.d.ts +9 -5
  151. package/dist/core/task-notification.d.ts +110 -31
  152. package/dist/core/task-notification.js +180 -100
  153. package/dist/core/task-registry-agent.d.ts +11 -0
  154. package/dist/core/task-registry-agent.js +11 -3
  155. package/dist/core/task-registry-shared.d.ts +7 -0
  156. package/dist/core/task-registry.d.ts +18 -0
  157. package/dist/core/task-registry.js +27 -8
  158. package/dist/core/task-spec.d.ts +7 -2
  159. package/dist/core/tool-errors.d.ts +14 -6
  160. package/dist/core/tool-errors.js +1 -1
  161. package/dist/core/tool-policy.d.ts +18 -1
  162. package/dist/core/tool-policy.js +16 -7
  163. package/dist/core/tool-result-store.d.ts +20 -0
  164. package/dist/core/tool-spec.d.ts +4 -0
  165. package/dist/core/trace.d.ts +3 -2
  166. package/dist/core/workflow-journal-store.d.ts +11 -0
  167. package/dist/core/workflow-journal-store.js +7 -0
  168. package/dist/core/workflow-run-store.d.ts +9 -0
  169. package/dist/core/workflow-run-store.js +6 -0
  170. package/dist/engine/compaction/compaction.d.ts +2 -1
  171. package/dist/engine/harness/types.d.ts +1 -0
  172. package/dist/engine/session/session.d.ts +7 -1
  173. package/dist/engine/session/session.js +5 -2
  174. package/dist/index.d.ts +7 -5
  175. package/dist/index.js +7 -5
  176. package/dist/orchestration/run-workflow-tool.d.ts +4 -0
  177. package/dist/orchestration/run-workflow-tool.js +7 -0
  178. package/dist/orchestration/workflow-types.d.ts +2 -1
  179. package/dist/orchestration/workflow.d.ts +3 -0
  180. package/dist/orchestration/workflow.js +2 -1
  181. package/dist/stores/file/checkpoint-store.d.ts +6 -0
  182. package/dist/stores/file/checkpoint-store.js +4 -1
  183. package/dist/stores/file/file-history-store.d.ts +13 -0
  184. package/dist/stores/file/file-history-store.js +75 -13
  185. package/dist/stores/file/index.d.ts +11 -1
  186. package/dist/stores/file/index.js +7 -11
  187. package/dist/stores/file/permission-rule-store.d.ts +23 -0
  188. package/dist/stores/file/permission-rule-store.js +75 -7
  189. package/dist/stores/file/tool-result-store.d.ts +14 -0
  190. package/dist/stores/file/tool-result-store.js +39 -2
  191. package/dist/stores/file/workflow-journal-store.d.ts +4 -0
  192. package/dist/stores/file/workflow-journal-store.js +17 -0
  193. package/dist/stores/file/workflow-run-store.d.ts +3 -0
  194. package/dist/stores/file/workflow-run-store.js +15 -0
  195. package/dist/tools/fs/read-deny.d.ts +15 -2
  196. package/dist/tools/fs/read-deny.js +10 -2
  197. package/dist/tools/fs/shell-read-check.d.ts +8 -2
  198. package/dist/tools/fs/shell-read-check.js +7 -7
  199. package/package.json +2 -2
  200. package/test/export-surface.snapshot.json +63 -1
  201. package/wire-changes/core-stores-sql@7.64.0.json +30 -0
  202. package/wire-changes/core@7.64.0.json +2653 -0
  203. package/wire-changes/mods-kernel@7.64.0.json +30 -0
  204. 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, CHALLENGES_FILE, IMPORT_RECEIPTS_DIR, LINEAGE_FILE, 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";
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
- const hasV2 = journal.ledger2 !== undefined;
286
- const hasV1 = journal.ledger !== undefined;
287
- if (hasV2 === hasV1) {
288
- throw new ControlPlaneCorruptError(`transaction journal has ${hasV2 ? "both ledger snapshots" : "no ledger snapshot"} (wrong shape): ${jp}`);
289
- }
290
- if (hasV2) {
291
- const env = journal.ledger2;
292
- if (!env || typeof env !== "object" || Array.isArray(env) || env.v !== LEDGER_SCHEMA_VERSION) {
293
- throw new ControlPlaneCorruptError(`transaction journal ledger2 snapshot has the wrong shape: ${jp}`);
294
- }
295
- const extras = {};
296
- for (const [k, val] of Object.entries(env))
297
- if (k !== "v" && k !== "rows")
298
- extras[k] = val;
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
- const v = rec.v;
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 rows = Object.create(null);
344
- for (const [k, v] of Object.entries(rec)) {
345
- if (typeof v !== "string") {
346
- throw new ControlPlaneCorruptError(`committed-rev ledger entry ${JSON.stringify(k)} is not a string: ${path}`);
347
- }
348
- rows[k] = { rev: v };
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
- return { form: "v1", rows };
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
- return parseLedgerText(raw, path).form;
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.persistedSchemaVersion === "v1" || (this.ledger !== undefined && hasUnboundRows(this.ledger))) {
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 (this.persistedSchemaVersion === "v1" || hasUnboundRows(this.loadLedger()))
688
+ if (hasUnboundRows(this.loadLedger()))
709
689
  this.tryOpportunisticMigrate();
710
- if (this.persistedSchemaVersion === "v2")
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 (this.persistedSchemaVersion === "v2" && !hasUnboundRows(rows))
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", `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`);
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 (!fullMigration && rowsBinding(rows, id) !== undefined) {
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
- if (!fullMigration)
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 (fullMigration) {
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
- const parsed = parseLedgerText(raw, join(this.controlPlaneRoot, LEDGER_FILE));
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, form: snapshotForm } = journalLedgerSnapshot(journal, jp);
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
- if (snapshotForm === "v2") {
1463
- this.ledger = snapshotRows;
1464
- this.envelopeExtras = snapshotExtras;
1465
- this.persistedSchemaVersion = "v2";
1466
- this.saveLedger();
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.persistedSchemaVersion === "v1" || this.unboundRowsKnown)
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.persistedSchemaVersion === "v1" || this.unboundRowsKnown)
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 (this.persistedSchemaVersion === "v1" || hasUnboundRows(this.loadLedger()))
2040
+ if (hasUnboundRows(this.loadLedger()))
2136
2041
  this.tryOpportunisticMigrate();
2137
2042
  const rows = { ...this.loadLedger() };
2138
- if (this.persistedSchemaVersion === "v2")
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
- const parsed = parseLedgerText(raw, path);
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 (parsed.form === "v2" && Object.prototype.hasOwnProperty.call(parsed.rows, id) && parsed.rows[id]?.prev !== undefined) {
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 [LINEAGE_FILE, CHALLENGES_FILE]) {
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 type { ConsolidationTx, MemoryBackend, MemoryGovernanceStore, MemoryGovernanceDocName, MemoryGovernanceDocs, MemoryEntry, MemoryEntryFrontmatter, MemoryEntryOrigin, MemoryOriginCause, MemoryScopeEnumeration, MemoryEntryDistilled, MemoryEntryDistilledInput, MemoryEntryHeader, ScoredMemoryEntry, NotePatch, PatchReport, MaterializedFile, MemorySessionHandle, HarvestReport, HarvestRejection, HarvestRejectionCode, MemoryAnnouncement, ScanFinding, } from "./types.js";
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 fileName = ledger === "lineage" ? LINEAGE_FILE : CHALLENGES_FILE;
2779
- const what = ledger === "lineage" ? "memory lineage ledger" : "memory challenge ledger";
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 fileName = ledger === "lineage" ? LINEAGE_FILE : CHALLENGES_FILE;
2793
- const what = ledger === "lineage" ? "memory lineage ledger" : "memory challenge ledger";
2794
- const coerce = ledger === "lineage" ? coerceLineage : coerceChallenges;
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
- corrupt: (store: MemoryGovernanceStore, record: "gate" | "intents" | "run" | MemoryGovernanceDocName) => Promise<void> | void;
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
  }