@sema-agent/core 7.64.0 → 7.66.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 (192) hide show
  1. package/CHANGELOG.md +571 -0
  2. package/dist/agents/delegation-registry-seat.d.ts +15 -0
  3. package/dist/agents/delegation-registry-seat.js +13 -0
  4. package/dist/agents/org-delivery-gate.d.ts +8 -1
  5. package/dist/agents/org-delivery-gate.js +9 -3
  6. package/dist/agents/peer-held-queue.js +1 -1
  7. package/dist/agents/peer-idle.js +1 -1
  8. package/dist/agents/peer-session-drain.d.ts +51 -12
  9. package/dist/agents/peer-session-drain.js +47 -34
  10. package/dist/agents/read-inbox-tool.d.ts +6 -2
  11. package/dist/agents/read-inbox-tool.js +18 -5
  12. package/dist/agents/subagent.d.ts +3 -1
  13. package/dist/agents/subagent.js +84 -77
  14. package/dist/brain/reasoning.d.ts +2 -0
  15. package/dist/brain/reasoning.js +1 -0
  16. package/dist/core/allow-entry.d.ts +9 -0
  17. package/dist/core/allow-entry.js +7 -1
  18. package/dist/core/ask-origin.d.ts +23 -3
  19. package/dist/core/ask-origin.js +11 -1
  20. package/dist/core/auto-promote.d.ts +3 -2
  21. package/dist/core/background-agent-store.d.ts +7 -0
  22. package/dist/core/checkpoint-store.d.ts +2 -3
  23. package/dist/core/context-settings.d.ts +1 -2
  24. package/dist/core/context-settings.js +1 -1
  25. package/dist/core/engine-attestation.d.ts +2 -2
  26. package/dist/core/engine-notice.d.ts +13 -1
  27. package/dist/core/engine-notice.js +3 -1
  28. package/dist/core/file-history-store.d.ts +2 -2
  29. package/dist/core/file-history-store.js +0 -4
  30. package/dist/core/gate-fold.js +3 -1
  31. package/dist/core/governance-codes.d.ts +6 -4
  32. package/dist/core/governance-codes.js +5 -3
  33. package/dist/core/human-input-projection.d.ts +9 -0
  34. package/dist/core/human-input-projection.js +13 -0
  35. package/dist/core/input-author.d.ts +66 -6
  36. package/dist/core/input-author.js +21 -3
  37. package/dist/core/leg-identity.d.ts +18 -2
  38. package/dist/core/leg-identity.js +5 -7
  39. package/dist/core/mailbox-store.d.ts +1 -1
  40. package/dist/core/memory-engine/consolidation.d.ts +30 -10
  41. package/dist/core/memory-engine/consolidation.js +41 -6
  42. package/dist/core/memory-engine/control-objects.d.ts +36 -3
  43. package/dist/core/memory-engine/control-objects.js +134 -12
  44. package/dist/core/memory-engine/control-plane-adoption.d.ts +13 -9
  45. package/dist/core/memory-engine/control-plane-adoption.js +58 -31
  46. package/dist/core/memory-engine/delegation-settlement.d.ts +75 -52
  47. package/dist/core/memory-engine/delegation-settlement.js +211 -228
  48. package/dist/core/memory-engine/dual-root.d.ts +3 -2
  49. package/dist/core/memory-engine/dual-root.js +5 -1
  50. package/dist/core/memory-engine/engine.d.ts +33 -16
  51. package/dist/core/memory-engine/engine.js +213 -177
  52. package/dist/core/memory-engine/file-backend.d.ts +21 -12
  53. package/dist/core/memory-engine/file-backend.js +58 -104
  54. package/dist/core/memory-engine/index.d.ts +2 -2
  55. package/dist/core/memory-engine/index.js +2 -2
  56. package/dist/core/memory-engine/layout.d.ts +184 -83
  57. package/dist/core/memory-engine/layout.js +267 -172
  58. package/dist/core/memory-engine/memory-age.d.ts +12 -0
  59. package/dist/core/memory-engine/memory-age.js +17 -0
  60. package/dist/core/memory-engine/memory-backend-contract.js +12 -11
  61. package/dist/core/memory-engine/memory-deployment.d.ts +4 -3
  62. package/dist/core/memory-engine/memory-deployment.js +6 -3
  63. package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
  64. package/dist/core/memory-engine/origin-clearance.js +142 -58
  65. package/dist/core/memory-engine/tools.d.ts +2 -2
  66. package/dist/core/memory-engine/tools.js +7 -7
  67. package/dist/core/memory-engine/types.d.ts +16 -10
  68. package/dist/core/memory-vector.d.ts +6 -14
  69. package/dist/core/memory.d.ts +0 -462
  70. package/dist/core/memory.js +0 -333
  71. package/dist/core/model-receipt.d.ts +2 -1
  72. package/dist/core/model-receipt.js +5 -0
  73. package/dist/core/mods/dollar.d.ts +12 -0
  74. package/dist/core/mods/kernel/dispatch.d.ts +3 -1
  75. package/dist/core/mods/kernel/dispatch.js +5 -2
  76. package/dist/core/mods/kernel/events.d.ts +3 -1
  77. package/dist/core/mods/kernel/events.js +2 -2
  78. package/dist/core/mods/prompt-submit.d.ts +4 -0
  79. package/dist/core/mods/prompt-submit.js +24 -0
  80. package/dist/core/mods/stations.d.ts +23 -4
  81. package/dist/core/mods/stations.js +14 -7
  82. package/dist/core/permission-rule-consent.d.ts +49 -18
  83. package/dist/core/permission-rule-consent.js +59 -38
  84. package/dist/core/permission-rule-store.d.ts +24 -14
  85. package/dist/core/retention.d.ts +2 -7
  86. package/dist/core/retention.js +0 -1
  87. package/dist/core/retired-host-table-account.d.ts +19 -0
  88. package/dist/core/retired-host-table-account.js +28 -0
  89. package/dist/core/retired-tool-name-account.d.ts +60 -0
  90. package/dist/core/retired-tool-name-account.js +32 -0
  91. package/dist/core/roles.d.ts +3 -1
  92. package/dist/core/roles.js +5 -2
  93. package/dist/core/runner/classifier-ladder.d.ts +3 -1
  94. package/dist/core/runner/classifier-ladder.js +2 -2
  95. package/dist/core/runner/compact-session.js +2 -1
  96. package/dist/core/runner/contracts.d.ts +9 -9
  97. package/dist/core/runner/delegation-owner.d.ts +0 -8
  98. package/dist/core/runner/delegation-owner.js +1 -3
  99. package/dist/core/runner/gate-exit.js +9 -2
  100. package/dist/core/runner/memory-consolidation-driver.js +2 -2
  101. package/dist/core/runner/prepare-config-doors.js +1 -1
  102. package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
  103. package/dist/core/runner/prepare-delegation-surface.js +5 -3
  104. package/dist/core/runner/prepare-gate-stations.d.ts +8 -5
  105. package/dist/core/runner/prepare-gate-stations.js +13 -5
  106. package/dist/core/runner/prepare-inherited-gate.js +2 -0
  107. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  108. package/dist/core/runner/prepare-memory.js +35 -14
  109. package/dist/core/runner/prepare-policy-chain.js +12 -3
  110. package/dist/core/runner/prepare-project-context.js +2 -2
  111. package/dist/core/runner/prepare-task.d.ts +9 -1
  112. package/dist/core/runner/prepare-task.js +6 -5
  113. package/dist/core/runner/prepare-wiring-manifest.js +5 -4
  114. package/dist/core/runner/prompt-suggestions.js +1 -1
  115. package/dist/core/runner/run-identity-wiring.js +2 -2
  116. package/dist/core/runner/run-leg.js +3 -3
  117. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  118. package/dist/core/runner/run-notification-lane.js +2 -2
  119. package/dist/core/runner/runtask.js +6 -3
  120. package/dist/core/runner/steer-admission.d.ts +11 -2
  121. package/dist/core/runner/stream-steer-verb.d.ts +5 -2
  122. package/dist/core/runner/stream-steer-verb.js +67 -14
  123. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -8
  124. package/dist/core/runner/sub-agent-deny-lists.js +22 -8
  125. package/dist/core/runner-deps.d.ts +4 -4
  126. package/dist/core/secret-env.d.ts +2 -2
  127. package/dist/core/secret-env.js +6 -20
  128. package/dist/core/session-store.d.ts +6 -6
  129. package/dist/core/session-store.js +3 -3
  130. package/dist/core/shell-run-candidates.js +3 -3
  131. package/dist/core/side-query.js +1 -1
  132. package/dist/core/skill-grant.d.ts +7 -0
  133. package/dist/core/skill-grant.js +14 -5
  134. package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
  135. package/dist/core/task-event.d.ts +14 -0
  136. package/dist/core/task-notification.d.ts +35 -8
  137. package/dist/core/task-notification.js +31 -13
  138. package/dist/core/task-registry-agent.js +1 -0
  139. package/dist/core/task-registry-shared.d.ts +4 -0
  140. package/dist/core/tool-errors.d.ts +3 -3
  141. package/dist/core/tool-policy.js +2 -3
  142. package/dist/core/tool-spec.d.ts +20 -10
  143. package/dist/core/user-attachment.d.ts +5 -1
  144. package/dist/core/user-attachment.js +11 -5
  145. package/dist/core/write-protect.d.ts +16 -0
  146. package/dist/core/write-protect.js +10 -0
  147. package/dist/engine/harness/agent-harness.d.ts +19 -11
  148. package/dist/engine/harness/agent-harness.js +7 -4
  149. package/dist/engine/llm/types.d.ts +22 -10
  150. package/dist/engine/session/repo-utils.d.ts +14 -4
  151. package/dist/engine/session/repo-utils.js +5 -4
  152. package/dist/index.d.ts +10 -8
  153. package/dist/index.js +9 -7
  154. package/dist/prompts/default.d.ts +1 -2
  155. package/dist/scenarios/full-body.d.ts +1 -1
  156. package/dist/shell/lex.d.ts +50 -15
  157. package/dist/shell/lex.js +43 -9
  158. package/dist/stores/file/adoption/adopt.d.ts +1 -1
  159. package/dist/stores/file/index.d.ts +1 -15
  160. package/dist/stores/file/index.js +1 -15
  161. package/dist/stores/file/permission-rule-store.d.ts +12 -1
  162. package/dist/stores/file/permission-rule-store.js +31 -4
  163. package/dist/stores/file/session-store.js +1 -1
  164. package/dist/tools/fs/fs-bash.js +3 -3
  165. package/dist/tools/fs/removal-targets.d.ts +8 -2
  166. package/dist/tools/fs/removal-targets.js +31 -4
  167. package/dist/tools/fs/shell-read-argv.js +7 -1
  168. package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
  169. package/dist/tools/fs/shell-read-bindings.js +130 -44
  170. package/dist/tools/fs/shell-read-plan.js +95 -29
  171. package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
  172. package/dist/tools/fs/shell-read-sourced.js +119 -0
  173. package/dist/tools/fs/shell-read-word.d.ts +2 -2
  174. package/dist/tools/fs/shell-read-word.js +4 -5
  175. package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
  176. package/dist/tools/fs/shell-read-workdir.js +60 -15
  177. package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
  178. package/dist/tools/fs/shell-reentry-text.js +11 -4
  179. package/package.json +2 -2
  180. package/test/export-surface.snapshot.json +21 -79
  181. package/wire-changes/core-stores-sql@7.65.0.json +30 -0
  182. package/wire-changes/core-stores-sql@7.66.0.json +30 -0
  183. package/wire-changes/core@7.65.0.json +1650 -0
  184. package/wire-changes/core@7.66.0.json +1218 -0
  185. package/wire-changes/mods-kernel@7.65.0.json +30 -0
  186. package/wire-changes/mods-kernel@7.66.0.json +65 -0
  187. package/wire-changes/primitives@7.65.0.json +337 -0
  188. package/wire-changes/primitives@7.66.0.json +30 -0
  189. package/dist/core/memory-recall.d.ts +0 -208
  190. package/dist/core/memory-recall.js +0 -136
  191. package/dist/stores/file/memory-store.d.ts +0 -124
  192. package/dist/stores/file/memory-store.js +0 -353
@@ -4,6 +4,7 @@ import { homedir } from "node:os";
4
4
  import { createHash, randomUUID } from "node:crypto";
5
5
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
6
  import { MEMORY_GOVERNANCE_DOC_NAMES, MEMORY_ORIGIN_CAUSES } from "./types.js";
7
+ import { parseEntryFile } from "./frontmatter.js";
7
8
  import { physicalPathOf, physicalPathOfExisting, priorCallerCasedPathOf } from "../physical-path.js";
8
9
  import { thrownLabel, thrownText } from "../thrown-value.js";
9
10
  import { egressText } from "../untrusted-egress.js";
@@ -748,9 +749,11 @@ export function isContainedIn(root, child) {
748
749
  const c = canonicalize(child);
749
750
  return c === r || c.startsWith(`${r}${sep}`);
750
751
  }
751
- export const STORE_FORM_REFUSAL_CODES = Object.freeze(["memory.target_outside_store", "memory.scope_home_not_directory"]);
752
+ export const STORE_FORM_REFUSAL_CODES = Object.freeze(["memory.target_outside_store", "memory.scope_home_not_directory", "memory.control_plane_links_unsupported", "memory.control_plane_strays"]);
752
753
  export const TARGET_OUTSIDE_STORE = "memory.target_outside_store";
753
754
  export const SCOPE_HOME_NOT_DIRECTORY = "memory.scope_home_not_directory";
755
+ export const CONTROL_PLANE_LINKS_UNSUPPORTED = "memory.control_plane_links_unsupported";
756
+ export const CONTROL_PLANE_STRAYS = "memory.control_plane_strays";
754
757
  export const SCOPE_HOME_FORMS = Object.freeze(["symlink", "file", "other"]);
755
758
  const SCOPE_HOME_FORM_PHRASE = {
756
759
  symlink: "a symbolic link",
@@ -775,6 +778,13 @@ export function storeRootAbsentRefusal(path, anchor) {
775
778
  export function scopeHomeRefusal(form, path) {
776
779
  return storeFormRefusal(SCOPE_HOME_NOT_DIRECTORY, `a scope home must be a real directory, but this one is ${SCOPE_HOME_FORM_PHRASE[form]} — refused (fail-closed); put the real directory back`, { path, form });
777
780
  }
781
+ export function controlPlaneLinksRefusal(path, fault) {
782
+ return storeFormRefusal(CONTROL_PLANE_LINKS_UNSUPPORTED, `the memory control plane is on a file system that cannot make hard links (link answered ${fault ?? "an error with no code"}) — the store publishes its control objects (quarantine copies, held files, pollution markers) with link, so it is not opened and no entry or control object was written; move the control plane (controlDir, or the memory engine root) to a volume that supports hard links`, { path });
783
+ }
784
+ export function controlPlaneStraysRefusal(path, strays) {
785
+ const named = [...strays.docs.map((d) => `the ${d} document`), ...Object.entries(strays.objects).map(([kind, n]) => `${n} ${kind} entr${n === 1 ? "y" : "ies"}`)];
786
+ return storeFormRefusal(CONTROL_PLANE_STRAYS, `the memory backend carries its own governance store, and the engine's control plane still holds that store's records from before (${named.join(", ")}) — they would be read by nobody, so the engine is not opened and nothing was written; adopt them into the carrier first (adoptReplicaControlPlane(detail.path, <the backend's governance store>), which removes each one it hands over), then reopen`, { path });
787
+ }
778
788
  export function landingPathOf(p) {
779
789
  return landingPathWithin(resolve(p), 0);
780
790
  }
@@ -1313,31 +1323,109 @@ export function restoreContainedBaseline(path, committed, leftOnPlane) {
1313
1323
  }
1314
1324
  }
1315
1325
  let quarantineSeq = 0;
1316
- export function quarantineAndTombstone(path, content, quarantineDir, now) {
1317
- let captured;
1318
- let detail;
1319
- try {
1320
- ensureDirExists(quarantineDir);
1321
- const base = `${now()}-${basename(path)}`;
1322
- for (let attempt = 0; captured === undefined && attempt < 10; attempt++) {
1323
- const candidate = join(quarantineDir, attempt === 0 ? base : `${base}.${attempt}`);
1324
- try {
1325
- writeFileSync(candidate, content, { encoding: "utf8", flag: "wx" });
1326
- captured = candidate;
1327
- }
1328
- catch (err) {
1329
- if (!(err instanceof Error && "code" in err && err.code === "EEXIST"))
1330
- throw err;
1331
- }
1326
+ export async function putControlObjectOnce(objects, kind, name, bytes) {
1327
+ try {
1328
+ return await objects.putObject(kind, name, bytes);
1329
+ }
1330
+ catch (err) {
1331
+ let standing;
1332
+ try {
1333
+ standing = await objects.getObject(kind, name);
1332
1334
  }
1333
- if (captured === undefined) {
1334
- const last = join(quarantineDir, `${base}.${process.pid}.${quarantineSeq++}`);
1335
- writeFileSync(last, content, { encoding: "utf8", flag: "wx" });
1336
- captured = last;
1335
+ catch {
1336
+ throw err;
1337
+ }
1338
+ if (standing === undefined)
1339
+ throw err;
1340
+ return "existed";
1341
+ }
1342
+ }
1343
+ export function quarantineCaptureName(base, attempt) {
1344
+ return attempt === 0 ? base : attempt < 10 ? `${base}.${attempt}` : `${base}.${process.pid}.${quarantineSeq++}`;
1345
+ }
1346
+ export function quarantineCaptureBase(path, now) {
1347
+ return `${now()}-${basename(path).replace(/\\/g, "%5C")}`;
1348
+ }
1349
+ export async function captureIntoQuarantine(objects, path, content, now) {
1350
+ const bytes = new TextEncoder().encode(content);
1351
+ const base = quarantineCaptureBase(path, now);
1352
+ try {
1353
+ for (let attempt = 0; attempt <= 10; attempt++) {
1354
+ const name = quarantineCaptureName(base, attempt);
1355
+ if ((await putControlObjectOnce(objects, "quarantine", name, bytes)) === "created")
1356
+ return { name };
1337
1357
  }
1358
+ return { failed: "quarantine copy failed: every capture name already stands" };
1359
+ }
1360
+ catch (err) {
1361
+ return { failed: `quarantine copy failed: ${thrownText(err)}` };
1362
+ }
1363
+ }
1364
+ export async function eraseQuarantineCopies(objects, ids) {
1365
+ let listed;
1366
+ try {
1367
+ listed = await objects.listObjects("quarantine");
1338
1368
  }
1339
1369
  catch (err) {
1340
- detail = `quarantine copy failed: ${thrownText(err)}`;
1370
+ throw new ControlPlaneCorruptError(`memory erasure: the quarantine objects could not be listed (${thrownText(err)}) — the attestation must not silently claim an empty residual set; retry after the store's fault clears (the deletions themselves are committed and a replay converges)`, { cause: err });
1371
+ }
1372
+ if (!Array.isArray(listed) || !Array.from(listed).every((name) => typeof name === "string")) {
1373
+ throw new ControlPlaneCorruptError("memory erasure: the store's listing of its quarantine objects is not a list of names — the attestation must not silently claim an empty residual set; retry after the store's fault clears (the deletions themselves are committed and a replay converges)");
1374
+ }
1375
+ const out = { removed: 0, remaining: 0, unreadable: 0, unattributed: 0 };
1376
+ for (const name of new Set(listed)) {
1377
+ let text;
1378
+ try {
1379
+ const bytes = await objects.getObject("quarantine", name);
1380
+ if (bytes === undefined)
1381
+ continue;
1382
+ text = new TextDecoder().decode(bytes);
1383
+ }
1384
+ catch {
1385
+ text = undefined;
1386
+ }
1387
+ if (text === undefined) {
1388
+ out.remaining++;
1389
+ out.unreadable++;
1390
+ continue;
1391
+ }
1392
+ const id = parseEntryFile(text).id;
1393
+ if (id === undefined) {
1394
+ out.unattributed++;
1395
+ continue;
1396
+ }
1397
+ if (!ids.has(id))
1398
+ continue;
1399
+ try {
1400
+ const deleted = await objects.deleteObject("quarantine", name);
1401
+ if (deleted === true)
1402
+ out.removed++;
1403
+ else if (deleted !== false)
1404
+ out.remaining++;
1405
+ }
1406
+ catch {
1407
+ out.remaining++;
1408
+ }
1409
+ }
1410
+ return out;
1411
+ }
1412
+ export function clearContainedPath(path, content, capture) {
1413
+ const captured = "name" in capture ? capture.name : undefined;
1414
+ let detail = "failed" in capture ? capture.failed : undefined;
1415
+ let onDisk;
1416
+ try {
1417
+ onDisk = readFileSync(path, "utf8");
1418
+ }
1419
+ catch {
1420
+ onDisk = undefined;
1421
+ }
1422
+ if (onDisk !== undefined && onDisk !== content) {
1423
+ return {
1424
+ ...(captured !== undefined ? { dest: captured } : {}),
1425
+ removed: false,
1426
+ leftOnPlane: content,
1427
+ detail: `${detail !== undefined ? `${detail}; ` : ""}the file was rewritten after it was read — the newer bytes are not the captured copy and were left in place`,
1428
+ };
1341
1429
  }
1342
1430
  let left = content;
1343
1431
  let removed = false;
@@ -1364,11 +1452,32 @@ export function quarantineAndTombstone(path, content, quarantineDir, now) {
1364
1452
  ...(detail !== undefined ? { detail } : {}),
1365
1453
  };
1366
1454
  }
1455
+ export async function keepCopiesBeforeOverwrite(text, keep, reread) {
1456
+ const failed = [];
1457
+ let held = text;
1458
+ for (let copies = 0; copies < 3; copies++) {
1459
+ const outcome = await keep(held);
1460
+ if (outcome !== true)
1461
+ failed.push(outcome);
1462
+ let onDisk;
1463
+ try {
1464
+ onDisk = reread();
1465
+ }
1466
+ catch (err) {
1467
+ return { landed: false, failed: [...failed, `the file could not be read again after its copy: ${thrownText(err)}`] };
1468
+ }
1469
+ if (onDisk === undefined || onDisk === held)
1470
+ return { landed: failed.length === 0, failed };
1471
+ held = onDisk;
1472
+ }
1473
+ return { landed: false, failed: [...failed, "the file kept being rewritten while its copy was kept — its last version was not captured"] };
1474
+ }
1367
1475
  export const ATOMIC_WRITE_TMP_PREFIX = ".tmp-";
1476
+ export const LINK_PROBE_PREFIX = ".link-probe-";
1368
1477
  export const LOCK_TOMB_INFIX = ".stale-";
1369
1478
  export const STORE_OPEN_ARTIFACTS = Object.freeze({
1370
1479
  files: Object.freeze([ROOT_ANCHOR_FILE, SCOPES_FILE, `${SCOPES_FILE}.journal`]),
1371
- filePrefixes: Object.freeze([ATOMIC_WRITE_TMP_PREFIX]),
1480
+ filePrefixes: Object.freeze([ATOMIC_WRITE_TMP_PREFIX, LINK_PROBE_PREFIX]),
1372
1481
  lockDirs: Object.freeze([`${ROOT_ANCHOR_FILE}.lock`, `${SCOPES_FILE}.lock`, STORE_TXN_LOCK_DIR]),
1373
1482
  memoryFilePrefixes: Object.freeze([CASEFOLD_PROBE_PREFIX]),
1374
1483
  });
@@ -1387,23 +1496,32 @@ function isLockTreeName(name) {
1387
1496
  return STORE_OPEN_ARTIFACTS.lockDirs.some((lock) => name === lock || name.startsWith(`${lock}${LOCK_TOMB_INFIX}`));
1388
1497
  }
1389
1498
  export function storeHoldsRecord(memoryDir, controlDir) {
1390
- return treeHoldsRecord(controlDir, "control", (name) => namedArtifactDamaged(memoryDir, controlDir, name)) || treeHoldsRecord(memoryDir, "memory");
1499
+ return treeHoldsRecord(controlDir, "control", (name) => namedArtifactFault(memoryDir, controlDir, name) !== undefined) || treeHoldsRecord(memoryDir, "memory");
1391
1500
  }
1392
- function namedArtifactDamaged(memoryDir, controlDir, name) {
1501
+ function namedArtifactFault(memoryDir, controlDir, name) {
1393
1502
  try {
1394
1503
  if (name === ROOT_ANCHOR_FILE)
1395
1504
  readStoreRootAnchor(controlDir, memoryDir);
1396
1505
  else if (name === SCOPES_FILE || name === `${SCOPES_FILE}.journal`) {
1397
- for (const file of [`${SCOPES_FILE}.journal`, SCOPES_FILE])
1506
+ for (const file of [`${SCOPES_FILE}.journal`, SCOPES_FILE]) {
1398
1507
  if (!absentOrRegularFile(join(controlDir, file)))
1399
- return true;
1508
+ return new ControlPlaneCorruptError(`memory store file ${join(controlDir, file)} is no regular file the scope registry can be read from (a pipe, a device, a directory, or a link that leads nowhere) — the store's registry cannot be checked, so nothing in the store was opened`);
1509
+ }
1400
1510
  readScopesRecord(controlDir);
1401
1511
  }
1402
- return false;
1512
+ return undefined;
1403
1513
  }
1404
- catch {
1405
- return true;
1514
+ catch (err) {
1515
+ return err instanceof ControlPlaneCorruptError ? err : new ControlPlaneCorruptError(`memory store artifact ${name} could not be read (${err.code ?? thrownLabel(err)}): ${thrownText(err)}`, { cause: err });
1516
+ }
1517
+ }
1518
+ export function storeOpenArtifactFault(memoryDir, controlDir) {
1519
+ for (const name of STORE_OPEN_ARTIFACTS.files) {
1520
+ const fault = namedArtifactFault(memoryDir, controlDir, name);
1521
+ if (fault !== undefined)
1522
+ return fault;
1406
1523
  }
1524
+ return undefined;
1407
1525
  }
1408
1526
  function absentOrRegularFile(path) {
1409
1527
  const entry = lstatOrAbsent(path);
@@ -1913,61 +2031,48 @@ function isIncarnationSeat(raw) {
1913
2031
  export function usableSessionIncarnation(raw) {
1914
2032
  return isIncarnationSeat(raw) ? raw : undefined;
1915
2033
  }
1916
- function sessionRecordPath(controlDir, dir, sessionId, incarnation) {
1917
- const name = incarnation === undefined ? `${encodeURIComponent(sessionId)}.json` : `${encodeURIComponent(sessionId)}@${encodeURIComponent(incarnation)}.json`;
1918
- return join(controlDir, dir, name);
2034
+ function sessionRecordName(sessionId, incarnation) {
2035
+ return incarnation === undefined ? `${encodeURIComponent(sessionId)}.json` : `${encodeURIComponent(sessionId)}@${encodeURIComponent(incarnation)}.json`;
1919
2036
  }
1920
- function standingOwnerAt(path) {
1921
- let raw;
2037
+ async function mintSessionRecordObjects(objects, kind, sessionId, incarnation, bytes) {
1922
2038
  try {
1923
- raw = readFileSync(path, "utf8");
2039
+ if ((await putControlObjectOnce(objects, kind, sessionRecordName(sessionId), bytes)) === "created")
2040
+ return "created";
1924
2041
  }
1925
- catch (err) {
1926
- if (err.code !== "ENOENT")
1927
- return "unattributable";
1928
- try {
1929
- lstatSync(path);
1930
- }
1931
- catch {
1932
- return "unattributable";
1933
- }
1934
- return { owner: undefined };
2042
+ catch {
2043
+ return "unpersisted";
1935
2044
  }
2045
+ const own = usableSessionIncarnation(incarnation);
2046
+ const standing = await sessionRecordOwnerOf(objects, kind, sessionRecordName(sessionId));
2047
+ const vouches = standing !== "unattributable" && (standing.owner === undefined || standing.owner === own);
2048
+ const unnamed = vouches || own === undefined ? undefined : await sessionRecordOwnerOf(objects, kind, sessionRecordName(sessionId, ""));
2049
+ if (vouches || (unnamed !== undefined && unnamed !== "unattributable" && unnamed.owner === undefined))
2050
+ return "existed";
1936
2051
  try {
1937
- const parsed = JSON.parse(raw);
1938
- if (parsed !== null && typeof parsed === "object")
1939
- return { owner: readIncarnationSeat(parsed) };
2052
+ return (await putControlObjectOnce(objects, kind, sessionRecordName(sessionId, own ?? ""), bytes)) === "created" ? "created" : "existed";
1940
2053
  }
1941
2054
  catch {
2055
+ return "unpersisted";
1942
2056
  }
1943
- return "unattributable";
1944
2057
  }
1945
- function mintSessionRecordSlots(controlDir, dir, sessionId, incarnation, text) {
1946
- const idSlot = sessionRecordPath(controlDir, dir, sessionId);
2058
+ async function sessionRecordOwnerOf(objects, kind, name) {
2059
+ let bytes;
1947
2060
  try {
1948
- ensureDirExists(dirname(idSlot));
1949
- writeFileSync(idSlot, text, { encoding: "utf8", flag: "wx" });
1950
- return "created";
2061
+ bytes = await objects.getObject(kind, name);
1951
2062
  }
1952
- catch (err) {
1953
- if (!(err instanceof Error && "code" in err && err.code === "EEXIST"))
1954
- return "unpersisted";
2063
+ catch {
2064
+ return "unattributable";
1955
2065
  }
1956
- const own = usableSessionIncarnation(incarnation);
1957
- const standing = standingOwnerAt(idSlot);
1958
- const vouches = standing !== "unattributable" && (standing.owner === undefined || standing.owner === own);
1959
- const unnamed = vouches || own === undefined ? undefined : standingOwnerAt(sessionRecordPath(controlDir, dir, sessionId, ""));
1960
- if (vouches || (unnamed !== undefined && unnamed !== "unattributable" && unnamed.owner === undefined))
1961
- return "existed";
2066
+ if (bytes === undefined)
2067
+ return "unattributable";
1962
2068
  try {
1963
- writeFileSync(sessionRecordPath(controlDir, dir, sessionId, own ?? ""), text, { encoding: "utf8", flag: "wx" });
1964
- return "created";
2069
+ const parsed = JSON.parse(new TextDecoder().decode(bytes));
2070
+ if (parsed !== null && typeof parsed === "object")
2071
+ return { owner: readIncarnationSeat(parsed) };
1965
2072
  }
1966
- catch (err) {
1967
- if (err instanceof Error && "code" in err && err.code === "EEXIST")
1968
- return "existed";
1969
- return "unpersisted";
2073
+ catch {
1970
2074
  }
2075
+ return "unattributable";
1971
2076
  }
1972
2077
  function bindOrSeparate(record, identity, asking, unknownSlot) {
1973
2078
  if (sessionRecordBindsIncarnation(record.incarnation, asking))
@@ -1992,38 +2097,32 @@ function sessionIdOfRecordName(name) {
1992
2097
  }
1993
2098
  }
1994
2099
  export const SESSION_POLLUTION_DIR = "session-pollution";
1995
- function pollutionPath(controlDir, sessionId, incarnation) {
1996
- return sessionRecordPath(controlDir, SESSION_POLLUTION_DIR, sessionId, incarnation);
1997
- }
1998
- export function markSessionPolluted(controlDir, sessionId, reason, now, cause, incarnation) {
2100
+ export async function markSessionPolluted(objects, sessionId, reason, now, cause, incarnation) {
1999
2101
  const record = { at: now(), reason, ...(cause !== undefined ? { cause } : {}), ...(incarnation !== undefined ? { incarnation } : {}) };
2000
- return mintSessionRecordSlots(controlDir, SESSION_POLLUTION_DIR, sessionId, incarnation, `${JSON.stringify(record, null, 2)}\n`);
2102
+ return mintSessionRecordObjects(objects, "pollution", sessionId, incarnation, new TextEncoder().encode(`${JSON.stringify(record, null, 2)}\n`));
2001
2103
  }
2002
- export function readSessionPollution(controlDir, sessionId, identity) {
2104
+ export async function readSessionPollution(objects, sessionId, identity) {
2003
2105
  const asking = usableSessionIncarnation(identity?.incarnation);
2004
2106
  if (asking !== undefined) {
2005
- const own = readPollutionAt(pollutionPath(controlDir, sessionId, asking));
2107
+ const own = await readPollutionObject(objects, sessionRecordName(sessionId, asking));
2006
2108
  if (own !== undefined)
2007
2109
  return own;
2008
2110
  }
2009
- const unnamedSlot = () => readPollutionAt(pollutionPath(controlDir, sessionId, ""));
2010
- const standing = readPollutionAt(pollutionPath(controlDir, sessionId));
2011
- return standing === undefined ? unnamedSlot() : bindOrSeparate(standing, identity, asking, unnamedSlot);
2111
+ const unnamed = await readPollutionObject(objects, sessionRecordName(sessionId, ""));
2112
+ const standing = await readPollutionObject(objects, sessionRecordName(sessionId));
2113
+ return standing === undefined ? unnamed : bindOrSeparate(standing, identity, asking, () => unnamed);
2012
2114
  }
2013
- function readPollutionAt(path) {
2014
- let raw;
2115
+ async function readPollutionObject(objects, name) {
2116
+ let bytes;
2015
2117
  try {
2016
- raw = readFileSync(path, "utf8");
2118
+ bytes = await objects.getObject("pollution", name);
2017
2119
  }
2018
2120
  catch {
2019
- try {
2020
- lstatSync(path);
2021
- }
2022
- catch {
2023
- return undefined;
2024
- }
2025
2121
  return { at: 0, reason: "pollution marker present but unreadable (kept fail-closed)" };
2026
2122
  }
2123
+ return bytes === undefined ? undefined : pollutionRecordOf(new TextDecoder().decode(bytes));
2124
+ }
2125
+ function pollutionRecordOf(raw) {
2027
2126
  try {
2028
2127
  const parsed = JSON.parse(raw);
2029
2128
  if (parsed !== null && typeof parsed === "object") {
@@ -2040,88 +2139,74 @@ function readPollutionAt(path) {
2040
2139
  }
2041
2140
  return { at: 0, reason: "pollution marker present but unreadable (kept fail-closed)" };
2042
2141
  }
2043
- export function listSessionPollution(controlDir) {
2044
- const dir = join(controlDir, SESSION_POLLUTION_DIR);
2045
- let names;
2046
- try {
2047
- names = readdirSync(dir);
2048
- }
2049
- catch (err) {
2050
- if (err.code === "ENOENT")
2051
- return {};
2052
- throw new ControlPlaneCorruptError(`session pollution markers could not be enumerated (${err.code ?? "io error"}) at ${dir} — an enumeration failure is not an empty set (fail-closed)`, { cause: err });
2053
- }
2142
+ export async function listSessionPollution(objects) {
2143
+ const names = await objects.listObjects("pollution");
2054
2144
  const out = Object.create(null);
2055
- for (const name of names.sort()) {
2145
+ for (const name of [...names].sort()) {
2056
2146
  const sessionId = sessionIdOfRecordName(name);
2057
2147
  if (sessionId === undefined || Object.prototype.hasOwnProperty.call(out, sessionId))
2058
2148
  continue;
2059
- const rec = readPollutionAt(join(dir, name));
2149
+ const rec = await readPollutionObject(objects, name);
2060
2150
  if (rec !== undefined)
2061
2151
  out[sessionId] = rec;
2062
2152
  }
2063
2153
  return out;
2064
2154
  }
2065
- export function importSessionPollution(controlDir, sessionId, record) {
2066
- const path = pollutionPath(controlDir, sessionId);
2067
- ensureDirExists(dirname(path));
2068
- try {
2069
- writeFileSync(path, `${JSON.stringify({ at: record.at, reason: record.reason, ...(record.cause !== undefined ? { cause: record.cause } : {}) }, null, 2)}\n`, { encoding: "utf8", flag: "wx" });
2155
+ export async function importSessionPollution(objects, sessionId, record) {
2156
+ const text = `${JSON.stringify({ at: record.at, reason: record.reason, ...(record.cause !== undefined ? { cause: record.cause } : {}) }, null, 2)}\n`;
2157
+ if ((await putControlObjectOnce(objects, "pollution", sessionRecordName(sessionId), new TextEncoder().encode(text))) === "created")
2070
2158
  return "written";
2071
- }
2072
- catch (err) {
2073
- if (!(err instanceof Error && "code" in err && err.code === "EEXIST"))
2074
- throw err;
2075
- }
2076
- const standing = readSessionPollution(controlDir, sessionId);
2159
+ const standing = await readSessionPollution(objects, sessionId);
2077
2160
  return standing !== undefined && standing.at === record.at && standing.reason === record.reason ? "already" : "divergent";
2078
2161
  }
2079
2162
  export const SESSION_CAPTURE_OPTOUT_DIR = "session-capture-optout";
2080
- function captureOptOutPath(controlDir, sessionId, incarnation) {
2081
- return sessionRecordPath(controlDir, SESSION_CAPTURE_OPTOUT_DIR, sessionId, incarnation);
2163
+ const UNREADABLE_CAPTURE_RECORD = Object.freeze({ at: 0, reason: "capture opt-out record present but unreadable (kept fail-closed)" });
2164
+ function captureIndeterminate(name, err) {
2165
+ return new ControlPlaneCorruptError(`session capture opt-out record state is INDETERMINATE for ${JSON.stringify(name)} (${thrownText(err)}) — the store cannot establish whether a record exists; consumers must suppress on the fault axis (an outage is never reported as a user request)`, { cause: err });
2082
2166
  }
2083
- export function markSessionCaptureOptOut(controlDir, sessionId, reason, now, incarnation) {
2084
- const record = { at: now(), reason, ...(incarnation !== undefined ? { incarnation } : {}) };
2085
- return mintSessionRecordSlots(controlDir, SESSION_CAPTURE_OPTOUT_DIR, sessionId, incarnation, `${JSON.stringify(record, null, 2)}\n`);
2167
+ export async function markSessionCaptureObjects(objects, sessionId, record) {
2168
+ try {
2169
+ const stored = { at: record.at, reason: record.reason, ...(record.incarnation !== undefined ? { incarnation: record.incarnation } : {}) };
2170
+ return await mintSessionRecordObjects(objects, "capture", sessionId, record.incarnation, new TextEncoder().encode(`${JSON.stringify(stored, null, 2)}\n`));
2171
+ }
2172
+ catch {
2173
+ return "unpersisted";
2174
+ }
2086
2175
  }
2087
- export function readSessionCaptureOptOut(controlDir, sessionId, identity) {
2176
+ export async function readSessionCaptureObjects(objects, sessionId, identity) {
2088
2177
  const asking = usableSessionIncarnation(identity?.incarnation);
2089
2178
  if (asking !== undefined) {
2090
- const own = readCaptureOptOutAt(captureOptOutPath(controlDir, sessionId, asking));
2179
+ const own = await readCaptureObject(objects, sessionRecordName(sessionId, asking));
2091
2180
  if (own !== undefined)
2092
2181
  return own;
2093
2182
  }
2094
- const unnamedSlot = () => readCaptureOptOutAt(captureOptOutPath(controlDir, sessionId, ""));
2095
- const standing = readCaptureOptOutAt(captureOptOutPath(controlDir, sessionId));
2096
- return standing === undefined ? unnamedSlot() : bindOrSeparate(standing, identity, asking, unnamedSlot);
2183
+ const standing = await readCaptureObject(objects, sessionRecordName(sessionId));
2184
+ if (standing === undefined)
2185
+ return readCaptureObject(objects, sessionRecordName(sessionId, ""));
2186
+ const unnamed = sessionRecordBindsIncarnation(standing.incarnation, asking) ? undefined : await readCaptureObject(objects, sessionRecordName(sessionId, ""));
2187
+ return bindOrSeparate(standing, identity, asking, () => unnamed);
2097
2188
  }
2098
- function readCaptureOptOutAt(path) {
2099
- let raw;
2189
+ async function readCaptureObject(objects, name) {
2190
+ let bytes;
2100
2191
  try {
2101
- raw = readFileSync(path, "utf8");
2192
+ bytes = await objects.getObject("capture", name);
2102
2193
  }
2103
2194
  catch (err) {
2104
- if (err.code === "ENOENT") {
2105
- try {
2106
- lstatSync(path);
2107
- }
2108
- catch (lerr) {
2109
- if (lerr.code === "ENOENT")
2110
- return undefined;
2111
- throw new ControlPlaneCorruptError(`session capture opt-out record state is INDETERMINATE (${lerr.code ?? "io error"}) at ${path} — the store cannot establish whether a record exists; consumers must suppress on the fault axis (an outage is never reported as a user request)`, { cause: lerr });
2112
- }
2113
- return { at: 0, reason: "capture opt-out record present but unreadable (kept fail-closed)" };
2114
- }
2195
+ let standing;
2115
2196
  try {
2116
- statSync(path);
2197
+ standing = await objects.listObjects("capture");
2117
2198
  }
2118
- catch {
2119
- throw new ControlPlaneCorruptError(`session capture opt-out record state is INDETERMINATE (${err.code ?? "io error"}) at ${path} — the store cannot establish whether a record exists; consumers must suppress on the fault axis (an outage is never reported as a user request)`, { cause: err });
2199
+ catch (lerr) {
2200
+ throw captureIndeterminate(name, lerr);
2120
2201
  }
2121
- return { at: 0, reason: "capture opt-out record present but unreadable (kept fail-closed)" };
2202
+ if (Array.isArray(standing) && standing.includes(name))
2203
+ return UNREADABLE_CAPTURE_RECORD;
2204
+ throw captureIndeterminate(name, err);
2122
2205
  }
2206
+ if (bytes === undefined)
2207
+ return undefined;
2123
2208
  try {
2124
- const parsed = JSON.parse(raw);
2209
+ const parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
2125
2210
  if (parsed !== null && typeof parsed === "object") {
2126
2211
  const at = parsed.at;
2127
2212
  const reason = parsed.reason;
@@ -2132,37 +2217,30 @@ function readCaptureOptOutAt(path) {
2132
2217
  }
2133
2218
  catch {
2134
2219
  }
2135
- return { at: 0, reason: "capture opt-out record present but unreadable (kept fail-closed)" };
2220
+ return UNREADABLE_CAPTURE_RECORD;
2136
2221
  }
2137
- export function listSessionCaptureOptOut(controlDir) {
2138
- const dir = join(controlDir, SESSION_CAPTURE_OPTOUT_DIR);
2222
+ export async function listSessionCaptureObjects(objects) {
2139
2223
  let names;
2140
2224
  try {
2141
- names = readdirSync(dir);
2225
+ names = await objects.listObjects("capture");
2142
2226
  }
2143
2227
  catch (err) {
2144
- if (err.code === "ENOENT")
2145
- return {};
2146
- throw new ControlPlaneCorruptError(`session capture opt-out records could not be enumerated (${err.code ?? "io error"}) at ${dir} — an enumeration failure is not an empty set (fail-closed)`, { cause: err });
2228
+ throw new ControlPlaneCorruptError(`session capture opt-out records could not be enumerated (${thrownText(err)}) — an enumeration failure is not an empty set (fail-closed)`, { cause: err });
2229
+ }
2230
+ if (!Array.isArray(names) || !Array.from(names).every((n) => typeof n === "string")) {
2231
+ throw new ControlPlaneCorruptError("session capture opt-out records: the store's listing is not a list of names — an enumeration failure is not an empty set (fail-closed)");
2147
2232
  }
2148
2233
  const out = Object.create(null);
2149
- for (const name of names.sort()) {
2234
+ for (const name of [...names].sort()) {
2150
2235
  const sessionId = sessionIdOfRecordName(name);
2151
2236
  if (sessionId === undefined || Object.prototype.hasOwnProperty.call(out, sessionId))
2152
2237
  continue;
2153
- const rec = readCaptureOptOutAt(join(dir, name));
2238
+ const rec = await readCaptureObject(objects, name);
2154
2239
  if (rec !== undefined)
2155
2240
  out[sessionId] = rec;
2156
2241
  }
2157
2242
  return out;
2158
2243
  }
2159
- export function fileSessionCaptureRecordStore(controlDir) {
2160
- return {
2161
- mark: (sessionId, record) => markSessionCaptureOptOut(controlDir, sessionId, record.reason, () => record.at, record.incarnation),
2162
- read: (sessionId, identity) => readSessionCaptureOptOut(controlDir, sessionId, identity),
2163
- list: () => listSessionCaptureOptOut(controlDir),
2164
- };
2165
- }
2166
2244
  export const USAGE_RETRIEVED_FILE = "usage-retrieved.json";
2167
2245
  export const USAGE_RETRIEVED_MAX_IDS = 4096;
2168
2246
  function coerceRetrievedAccount(raw) {
@@ -2287,6 +2365,27 @@ export function lockedStrictUpdate(controlDir, fileName, what, coerce, fn) {
2287
2365
  releaseSidecarLock(lock, token);
2288
2366
  }
2289
2367
  }
2368
+ export function lockedStrictRemove(controlDir, fileName, what, removable) {
2369
+ const file = join(controlDir, fileName);
2370
+ const journal = `${file}.journal`;
2371
+ const lock = `${file}.lock`;
2372
+ const token = acquireSidecarLock(lock, { onDeadline: "throw" });
2373
+ try {
2374
+ const fence = () => assertSidecarLockOwnership(lock, token, what, "strict");
2375
+ rollForwardStrictSidecar(file, journal, fence);
2376
+ const committed = readStrictSidecarRaw(file, what);
2377
+ if (committed === undefined)
2378
+ return "absent";
2379
+ if (!removable(committed))
2380
+ return "kept";
2381
+ fence();
2382
+ rmSync(file);
2383
+ return "removed";
2384
+ }
2385
+ finally {
2386
+ releaseSidecarLock(lock, token);
2387
+ }
2388
+ }
2290
2389
  function readStrictSidecarRaw(file, what) {
2291
2390
  let raw;
2292
2391
  try {
@@ -2497,8 +2596,8 @@ export const IMPORT_RECEIPTS_DIR = "import-receipts";
2497
2596
  export function importLatchTxnId(bundleHash) {
2498
2597
  return `import:${bundleHash}`;
2499
2598
  }
2500
- function importReceiptPath(controlDir, bundleHash) {
2501
- return join(controlDir, IMPORT_RECEIPTS_DIR, `${bundleHash}.json`);
2599
+ export function importReceiptName(bundleHash) {
2600
+ return `${bundleHash}.json`;
2502
2601
  }
2503
2602
  export async function stageImportLatch(docs, bundleHash, rows, now) {
2504
2603
  const txnId = importLatchTxnId(bundleHash);
@@ -2517,27 +2616,23 @@ export async function stageImportLatch(docs, bundleHash, rows, now) {
2517
2616
  });
2518
2617
  return txnId;
2519
2618
  }
2520
- export async function releaseImportLatch(docs, controlDir, txnId) {
2619
+ export async function releaseImportLatch(store, txnId) {
2521
2620
  const prefix = "import:";
2522
2621
  if (!txnId.startsWith(prefix) || !/^[0-9a-f]{64}$/.test(txnId.slice(prefix.length))) {
2523
2622
  throw new ControlPlaneCorruptError(`releaseImportLatch: ${JSON.stringify(txnId)} is not an import-latch transaction id (import:<64-hex bundleHash>)`);
2524
2623
  }
2525
- const receipt = importReceiptPath(controlDir, txnId.slice(prefix.length));
2526
- let receiptPresent;
2624
+ const receipt = importReceiptName(txnId.slice(prefix.length));
2625
+ let bytes;
2527
2626
  try {
2528
- readFileSync(receipt);
2529
- receiptPresent = true;
2627
+ bytes = await store.getObject("import-receipt", receipt);
2530
2628
  }
2531
2629
  catch (err) {
2532
- if (err.code !== "ENOENT") {
2533
- throw new ControlPlaneCorruptError(`releaseImportLatch: the completion receipt at ${receipt} could not be read (${err.code ?? "io error"}) — a probe failure is not absence (fail-closed), and absence would refuse the release`, { cause: err });
2534
- }
2535
- receiptPresent = false;
2630
+ throw new ControlPlaneCorruptError(`releaseImportLatch: the completion receipt ${receipt} could not be read (${thrownText(err)}) — a probe failure is not absence (fail-closed), and absence would refuse the release`, { cause: err });
2536
2631
  }
2537
- if (!receiptPresent) {
2538
- throw new ControlPlaneCorruptError(`releaseImportLatch: no completion receipt at ${receipt} — the import's governance legs are not proven landed, the latch stays; re-run the same bundle import to converge`);
2632
+ if (bytes === undefined) {
2633
+ throw new ControlPlaneCorruptError(`releaseImportLatch: no completion receipt ${receipt} — the import's governance legs are not proven landed, the latch stays; re-run the same bundle import to converge`);
2539
2634
  }
2540
- await docs.updateDoc("lineage", coerceLineage, (rec) => {
2635
+ await store.updateDoc("lineage", coerceLineage, (rec) => {
2541
2636
  const txn = rec.pending[txnId];
2542
2637
  if (txn === undefined)
2543
2638
  return { result: undefined };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Render a memory entry's age as a natural-language phrase (CC-parity P0-1). CC's eval found
3
+ * models reason about memory age much better from natural language ("3 days ago") than from a boolean
4
+ * "older note" flag (verify-claims 0/2 → 3/3 once the age was spelled out), because the model can weigh
5
+ * staleness proportionally instead of as a single cliff. This is the relative phrase only; it is additional
6
+ * signal beside the entry, not a verdict on it.
7
+ *
8
+ * Buckets (each chooses the coarsest unit that's ≥1): `today` (<1 day, incl. future mtime / clock skew →
9
+ * clamped to today, never a negative age), `yesterday` (1–2 days), `N days ago` (2–7 days),
10
+ * `N weeks ago` (1 week – ~1 month), `N months ago` (≥ ~1 month). N is floored to the whole unit.
11
+ */
12
+ export declare function formatMemoryAge(ageMs: number): string;