@sema-agent/core 7.62.0 → 7.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/CHANGELOG.md +936 -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-transcript-placement.d.ts +23 -0
  23. package/dist/agents/subagent-transcript-placement.js +14 -0
  24. package/dist/agents/subagent.js +102 -54
  25. package/dist/brain/route-adjudicator.js +9 -4
  26. package/dist/core/allow-entry.d.ts +4 -0
  27. package/dist/core/approval-object.js +1 -1
  28. package/dist/core/arg-summary.js +1 -1
  29. package/dist/core/ask-origin.d.ts +1 -1
  30. package/dist/core/ask-origin.js +2 -2
  31. package/dist/core/ask-question.d.ts +2 -2
  32. package/dist/core/ask-unresolvable-notice.d.ts +13 -4
  33. package/dist/core/ask-unresolvable-notice.js +10 -3
  34. package/dist/core/auto-compaction.d.ts +7 -5
  35. package/dist/core/background-agent-store.d.ts +7 -0
  36. package/dist/core/background-agent-store.js +3 -0
  37. package/dist/core/canonical-json.d.ts +23 -13
  38. package/dist/core/canonical-json.js +4 -4
  39. package/dist/core/checkpoint-queries.d.ts +50 -4
  40. package/dist/core/checkpoint-queries.js +42 -17
  41. package/dist/core/checkpoint-requirements.d.ts +3 -3
  42. package/dist/core/checkpoint-requirements.js +2 -1
  43. package/dist/core/checkpoint-row-verdict.d.ts +15 -4
  44. package/dist/core/checkpoint-row-verdict.js +22 -2
  45. package/dist/core/checkpoint-store.d.ts +28 -11
  46. package/dist/core/checkpoint-store.js +45 -4
  47. package/dist/core/compliance.d.ts +6 -2
  48. package/dist/core/compliance.js +3 -3
  49. package/dist/core/context-settings.d.ts +40 -9
  50. package/dist/core/context-settings.js +32 -10
  51. package/dist/core/engine-attestation.d.ts +27 -7
  52. package/dist/core/engine-attestation.js +5 -1
  53. package/dist/core/engine-notice.d.ts +43 -5
  54. package/dist/core/extension-requester.d.ts +9 -0
  55. package/dist/core/extension-requester.js +7 -0
  56. package/dist/core/file-history-store.d.ts +28 -0
  57. package/dist/core/file-history-store.js +48 -5
  58. package/dist/core/fs-write-gate-policy.js +1 -1
  59. package/dist/core/gate-fold.js +2 -0
  60. package/dist/core/gate-lanes.js +2 -0
  61. package/dist/core/gate-outcome.d.ts +39 -2
  62. package/dist/core/gate-outcome.js +20 -1
  63. package/dist/core/git-worktree-env.d.ts +62 -3
  64. package/dist/core/git-worktree-env.js +91 -30
  65. package/dist/core/governance-codes.d.ts +9 -3
  66. package/dist/core/governance-codes.js +17 -3
  67. package/dist/core/leg-identity.d.ts +19 -1
  68. package/dist/core/leg-identity.js +12 -0
  69. package/dist/core/mailbox-store.d.ts +39 -4
  70. package/dist/core/mailbox-store.js +14 -2
  71. package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
  72. package/dist/core/memory-engine/consolidation-driver.js +99 -98
  73. package/dist/core/memory-engine/consolidation.d.ts +74 -10
  74. package/dist/core/memory-engine/consolidation.js +183 -11
  75. package/dist/core/memory-engine/control-objects.d.ts +25 -0
  76. package/dist/core/memory-engine/control-objects.js +151 -0
  77. package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
  78. package/dist/core/memory-engine/control-plane-adoption.js +159 -0
  79. package/dist/core/memory-engine/data-plane.d.ts +8 -4
  80. package/dist/core/memory-engine/data-plane.js +11 -6
  81. package/dist/core/memory-engine/delegation-settlement.d.ts +58 -40
  82. package/dist/core/memory-engine/delegation-settlement.js +270 -85
  83. package/dist/core/memory-engine/dual-root.d.ts +12 -6
  84. package/dist/core/memory-engine/dual-root.js +11 -7
  85. package/dist/core/memory-engine/engine.d.ts +136 -58
  86. package/dist/core/memory-engine/engine.js +491 -394
  87. package/dist/core/memory-engine/entry-scan.d.ts +8 -0
  88. package/dist/core/memory-engine/entry-scan.js +3 -0
  89. package/dist/core/memory-engine/file-backend.d.ts +62 -60
  90. package/dist/core/memory-engine/file-backend.js +122 -198
  91. package/dist/core/memory-engine/index.d.ts +8 -7
  92. package/dist/core/memory-engine/index.js +7 -6
  93. package/dist/core/memory-engine/landing-admission.d.ts +5 -3
  94. package/dist/core/memory-engine/landing-admission.js +3 -3
  95. package/dist/core/memory-engine/layout.d.ts +127 -46
  96. package/dist/core/memory-engine/layout.js +264 -109
  97. package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
  98. package/dist/core/memory-engine/memory-backend-contract.js +476 -0
  99. package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
  100. package/dist/core/memory-engine/memory-deployment.js +54 -15
  101. package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
  102. package/dist/core/memory-engine/origin-clearance.js +68 -9
  103. package/dist/core/memory-engine/scope-contract.d.ts +52 -11
  104. package/dist/core/memory-engine/scope-contract.js +68 -19
  105. package/dist/core/memory-engine/session-write-home.d.ts +37 -2
  106. package/dist/core/memory-engine/session-write-home.js +38 -11
  107. package/dist/core/memory-engine/sync-client.d.ts +3 -1
  108. package/dist/core/memory-engine/sync-client.js +7 -0
  109. package/dist/core/memory-engine/sync-report.d.ts +3 -2
  110. package/dist/core/memory-engine/sync-report.js +6 -2
  111. package/dist/core/memory-engine/tools.d.ts +2 -2
  112. package/dist/core/memory-engine/tools.js +10 -10
  113. package/dist/core/memory-engine/types.d.ts +155 -19
  114. package/dist/core/memory-engine/types.js +2 -0
  115. package/dist/core/memory.js +15 -6
  116. package/dist/core/mode-policy.js +3 -3
  117. package/dist/core/mods/agent-stations.d.ts +18 -0
  118. package/dist/core/mods/agent-stations.js +8 -6
  119. package/dist/core/mods/extension-call.d.ts +4 -0
  120. package/dist/core/mods/extension-call.js +8 -0
  121. package/dist/core/mods/stations.d.ts +20 -1
  122. package/dist/core/mods/stations.js +21 -2
  123. package/dist/core/mods/tool-call.js +3 -4
  124. package/dist/core/parent-spec-seat.d.ts +2 -2
  125. package/dist/core/park-selfcheck.js +2 -2
  126. package/dist/core/pause-registry.d.ts +2 -0
  127. package/dist/core/pause-registry.js +3 -0
  128. package/dist/core/peer-channel.d.ts +5 -0
  129. package/dist/core/permission-rule-consent.d.ts +26 -8
  130. package/dist/core/permission-rule-consent.js +76 -36
  131. package/dist/core/permission-rule-store.d.ts +72 -13
  132. package/dist/core/permission-rule-store.js +29 -8
  133. package/dist/core/read-only-shell.js +3 -2
  134. package/dist/core/redaction-marks.d.ts +8 -0
  135. package/dist/core/redaction-marks.js +6 -0
  136. package/dist/core/refusal-echo.d.ts +20 -0
  137. package/dist/core/refusal-echo.js +33 -0
  138. package/dist/core/remote-env.d.ts +12 -1
  139. package/dist/core/remote-env.js +3 -0
  140. package/dist/core/retention.d.ts +180 -10
  141. package/dist/core/retention.js +45 -0
  142. package/dist/core/retired-keys.d.ts +5 -0
  143. package/dist/core/retired-keys.js +3 -0
  144. package/dist/core/rule-offer-read.d.ts +0 -4
  145. package/dist/core/rule-offer-read.js +2 -18
  146. package/dist/core/runner/child-tree.d.ts +29 -3
  147. package/dist/core/runner/child-tree.js +39 -16
  148. package/dist/core/runner/classifier-ladder.d.ts +7 -1
  149. package/dist/core/runner/classifier-ladder.js +4 -2
  150. package/dist/core/runner/compact-session.js +10 -7
  151. package/dist/core/runner/compaction-call-options.d.ts +7 -7
  152. package/dist/core/runner/compaction-call-options.js +3 -2
  153. package/dist/core/runner/contracts.d.ts +39 -11
  154. package/dist/core/runner/delegation-owner.d.ts +10 -3
  155. package/dist/core/runner/delegation-owner.js +4 -1
  156. package/dist/core/runner/gate-exit.d.ts +6 -0
  157. package/dist/core/runner/gate-exit.js +13 -4
  158. package/dist/core/runner/inherited-ask-grants.js +1 -1
  159. package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
  160. package/dist/core/runner/memory-consolidation-driver.js +12 -9
  161. package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
  162. package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
  163. package/dist/core/runner/person-path-rows.d.ts +8 -3
  164. package/dist/core/runner/person-path-rows.js +5 -1
  165. package/dist/core/runner/placement-fence.d.ts +12 -0
  166. package/dist/core/runner/placement-fence.js +20 -6
  167. package/dist/core/runner/prepare-ask-lane.js +5 -5
  168. package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
  169. package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
  170. package/dist/core/runner/prepare-config-doors.js +4 -0
  171. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  172. package/dist/core/runner/prepare-delegation-surface.js +2 -2
  173. package/dist/core/runner/prepare-execution-env.js +17 -6
  174. package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
  175. package/dist/core/runner/prepare-gate-stations.js +5 -5
  176. package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
  177. package/dist/core/runner/prepare-hands-readface.js +5 -4
  178. package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
  179. package/dist/core/runner/prepare-inherited-gate.js +12 -6
  180. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
  181. package/dist/core/runner/prepare-memory-engine-session.js +4 -4
  182. package/dist/core/runner/prepare-memory.d.ts +7 -2
  183. package/dist/core/runner/prepare-memory.js +41 -39
  184. package/dist/core/runner/prepare-park-ask.js +4 -3
  185. package/dist/core/runner/prepare-policy-chain.js +7 -7
  186. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  187. package/dist/core/runner/prepare-task.js +26 -18
  188. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  189. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  190. package/dist/core/runner/prepare-workspace-restore.js +3 -6
  191. package/dist/core/runner/resume-admission.d.ts +2 -2
  192. package/dist/core/runner/resume-admission.js +2 -23
  193. package/dist/core/runner/role-resolution-table.d.ts +98 -0
  194. package/dist/core/runner/role-resolution-table.js +62 -0
  195. package/dist/core/runner/run-compaction-machinery.js +2 -2
  196. package/dist/core/runner/run-identity-wiring.js +12 -9
  197. package/dist/core/runner/run-leg.js +9 -5
  198. package/dist/core/runner/run-notification-lane.js +22 -22
  199. package/dist/core/runner/run-recovery-lanes.js +3 -3
  200. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  201. package/dist/core/runner/run-terminal-adoption.js +1 -1
  202. package/dist/core/runner/run-turn-boundary.js +14 -15
  203. package/dist/core/runner/runtask.js +1 -1
  204. package/dist/core/runner/terminal-account.js +1 -1
  205. package/dist/core/runner/tool-occurrence.d.ts +4 -2
  206. package/dist/core/runner/tool-occurrence.js +2 -2
  207. package/dist/core/runner-deps.d.ts +7 -3
  208. package/dist/core/secret-env.d.ts +1 -1
  209. package/dist/core/secret-env.js +4 -4
  210. package/dist/core/session-checkout.d.ts +168 -0
  211. package/dist/core/session-checkout.js +579 -0
  212. package/dist/core/session-store.d.ts +12 -4
  213. package/dist/core/session-store.js +23 -3
  214. package/dist/core/session.d.ts +16 -2
  215. package/dist/core/session.js +3 -0
  216. package/dist/core/shell-read-silence.js +8 -0
  217. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
  218. package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
  219. package/dist/core/store-contracts/peer-directory-contract.js +8 -1
  220. package/dist/core/store-contracts/session-store-contract.js +39 -0
  221. package/dist/core/task-event.d.ts +30 -5
  222. package/dist/core/task-notification.d.ts +119 -32
  223. package/dist/core/task-notification.js +186 -100
  224. package/dist/core/task-registry-agent.d.ts +25 -2
  225. package/dist/core/task-registry-agent.js +56 -22
  226. package/dist/core/task-registry-shared.d.ts +33 -11
  227. package/dist/core/task-registry.d.ts +33 -9
  228. package/dist/core/task-registry.js +36 -18
  229. package/dist/core/task-spec-members.js +1 -1
  230. package/dist/core/task-spec.d.ts +27 -2
  231. package/dist/core/tool-errors.d.ts +14 -6
  232. package/dist/core/tool-errors.js +1 -1
  233. package/dist/core/tool-policy.d.ts +32 -13
  234. package/dist/core/tool-policy.js +27 -17
  235. package/dist/core/tool-result-store.d.ts +20 -0
  236. package/dist/core/tool-spec.d.ts +42 -19
  237. package/dist/core/trace.d.ts +3 -2
  238. package/dist/core/types.d.ts +1 -1
  239. package/dist/core/untrusted-egress.d.ts +15 -4
  240. package/dist/core/untrusted-egress.js +23 -22
  241. package/dist/core/workflow-journal-store.d.ts +11 -0
  242. package/dist/core/workflow-journal-store.js +7 -0
  243. package/dist/core/workflow-run-store.d.ts +9 -0
  244. package/dist/core/workflow-run-store.js +6 -0
  245. package/dist/core/workspace-snapshot.d.ts +3 -1
  246. package/dist/core/workspace-snapshot.js +1 -0
  247. package/dist/engine/compaction/compaction.d.ts +2 -1
  248. package/dist/engine/harness/types.d.ts +67 -1
  249. package/dist/engine/harness/types.js +108 -0
  250. package/dist/engine/session/import-validate.js +6 -1
  251. package/dist/engine/session/session.d.ts +30 -1
  252. package/dist/engine/session/session.js +48 -1
  253. package/dist/index.d.ts +12 -7
  254. package/dist/index.js +12 -7
  255. package/dist/internal/harness-types.d.ts +1 -1
  256. package/dist/orchestration/run-workflow-tool.d.ts +8 -1
  257. package/dist/orchestration/run-workflow-tool.js +8 -0
  258. package/dist/orchestration/workflow-types.d.ts +2 -1
  259. package/dist/orchestration/workflow.d.ts +6 -0
  260. package/dist/orchestration/workflow.js +5 -2
  261. package/dist/stores/file/checkpoint-store.d.ts +6 -0
  262. package/dist/stores/file/checkpoint-store.js +4 -1
  263. package/dist/stores/file/file-history-store.d.ts +13 -0
  264. package/dist/stores/file/file-history-store.js +75 -13
  265. package/dist/stores/file/index.d.ts +11 -1
  266. package/dist/stores/file/index.js +7 -11
  267. package/dist/stores/file/permission-rule-store.d.ts +23 -0
  268. package/dist/stores/file/permission-rule-store.js +75 -7
  269. package/dist/stores/file/session-store.js +2 -1
  270. package/dist/stores/file/tool-result-store.d.ts +14 -0
  271. package/dist/stores/file/tool-result-store.js +39 -2
  272. package/dist/stores/file/workflow-journal-store.d.ts +4 -0
  273. package/dist/stores/file/workflow-journal-store.js +17 -0
  274. package/dist/stores/file/workflow-run-store.d.ts +3 -0
  275. package/dist/stores/file/workflow-run-store.js +15 -0
  276. package/dist/tools/fs/bash-program-position.js +3 -3
  277. package/dist/tools/fs/program-read-model.d.ts +34 -10
  278. package/dist/tools/fs/program-read-model.js +37 -7
  279. package/dist/tools/fs/program-read-model.rows.js +13 -2
  280. package/dist/tools/fs/read-deny.d.ts +28 -3
  281. package/dist/tools/fs/read-deny.js +18 -2
  282. package/dist/tools/fs/removal-targets.js +3 -3
  283. package/dist/tools/fs/safety.d.ts +2 -0
  284. package/dist/tools/fs/safety.js +1 -1
  285. package/dist/tools/fs/shell-read-argv.d.ts +8 -1
  286. package/dist/tools/fs/shell-read-argv.js +34 -29
  287. package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
  288. package/dist/tools/fs/shell-read-bindings.js +5 -1
  289. package/dist/tools/fs/shell-read-brace.d.ts +18 -0
  290. package/dist/tools/fs/shell-read-brace.js +79 -0
  291. package/dist/tools/fs/shell-read-check.d.ts +8 -2
  292. package/dist/tools/fs/shell-read-check.js +16 -14
  293. package/dist/tools/fs/shell-read-establish.js +23 -16
  294. package/dist/tools/fs/shell-read-judge.d.ts +11 -0
  295. package/dist/tools/fs/shell-read-judge.js +3 -3
  296. package/dist/tools/fs/shell-read-plan.d.ts +10 -0
  297. package/dist/tools/fs/shell-read-plan.js +189 -93
  298. package/dist/tools/fs/shell-read-start.d.ts +19 -9
  299. package/dist/tools/fs/shell-read-start.js +20 -12
  300. package/dist/tools/fs/shell-read-word.d.ts +10 -0
  301. package/dist/tools/fs/shell-read-word.js +9 -5
  302. package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
  303. package/dist/tools/fs/shell-read-workdir.js +73 -12
  304. package/dist/tools/fs/shell-read-write-targets.js +13 -8
  305. package/dist/tools/worktree.d.ts +3 -2
  306. package/dist/tools/worktree.js +7 -35
  307. package/package.json +3 -2
  308. package/test/export-surface.snapshot.json +135 -11
  309. package/wire-changes/core-stores-sql@7.63.0.json +30 -0
  310. package/wire-changes/core-stores-sql@7.64.0.json +30 -0
  311. package/wire-changes/core@7.63.0.json +3523 -0
  312. package/wire-changes/core@7.64.0.json +2653 -0
  313. package/wire-changes/mods-kernel@7.63.0.json +30 -0
  314. package/wire-changes/mods-kernel@7.64.0.json +30 -0
  315. package/wire-changes/primitives@7.63.0.json +445 -0
  316. package/wire-changes/primitives@7.64.0.json +30 -0
  317. package/dist/core/credential-vocabulary.d.ts +0 -176
  318. package/dist/core/credential-vocabulary.js +0 -190
  319. package/dist/core/redaction-passes.d.ts +0 -82
  320. package/dist/core/redaction-passes.js +0 -377
@@ -2,7 +2,8 @@ import { uuidv7 } from "../../internal/harness.js";
2
2
  import { firstSentence } from "../memory.js";
3
3
  import { computeEntryRev, parseEntryFile, serializeEntryFile, UNCLOSED_MEMORY_FILE_REASON } from "./frontmatter.js";
4
4
  import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
5
- import { MEMORY_INDEX_FILENAME } from "./entry-scan.js";
5
+ import { MEMORY_INDEX_FILENAME, carriesEntry } from "./entry-scan.js";
6
+ import { deletionFuseCeiling } from "./consolidation.js";
6
7
  import { scopeDirName } from "./layout.js";
7
8
  export const REMOTE_HARVEST_PER_FILE_BYTES = 100 * 1024;
8
9
  export const REMOTE_MASS_DELETION_FUSE_RATIO = 0.5;
@@ -33,7 +34,8 @@ export function harvestFilesToPatches(baseline, files, opts = {}) {
33
34
  const writeScope = baseline.writeScope;
34
35
  if (writeScope === null)
35
36
  return out;
36
- const byRel = new Map(files.map((f) => [f.relPath, f]));
37
+ const carried = files.filter((f) => carriesEntry(f.content));
38
+ const byRel = new Map(carried.map((f) => [f.relPath, f]));
37
39
  const baseByRel = new Map(baseline.files.map((b) => [b.relPath, b]));
38
40
  const basePathById = new Map(baseline.files.filter((b) => !b.readonly).map((b) => [b.id, b.relPath]));
39
41
  const readonlyPrefixes = new Set();
@@ -70,7 +72,7 @@ export function harvestFilesToPatches(baseline, files, opts = {}) {
70
72
  }
71
73
  const presentIds = new Set();
72
74
  const parsedByRel = new Map();
73
- for (const f of files) {
75
+ for (const f of carried) {
74
76
  if (baseByRel.get(f.relPath)?.readonly)
75
77
  continue;
76
78
  const p = parseEntryFile(f.content);
@@ -81,16 +83,19 @@ export function harvestFilesToPatches(baseline, files, opts = {}) {
81
83
  const writable = baseline.files.filter((b) => !b.readonly);
82
84
  const missingWritable = writable.filter((b) => !byRel.has(b.relPath) && !presentIds.has(b.id));
83
85
  out.missing.push(...missingWritable.map((b) => b.relPath));
84
- if (writable.length > 0 && missingWritable.length / writable.length > fuseRatio) {
86
+ const ceiling = deletionFuseCeiling(writable.length, fuseRatio);
87
+ if (missingWritable.length > ceiling) {
85
88
  out.incident = {
86
89
  kind: "mass_deletion",
87
- detail: `${missingWritable.length}/${writable.length} materialized memory files are missing from the read-back set — judged an accident, harvest refused (no patches; explicit frontmatter tombstones are the only deletion channel)`,
90
+ detail: `${missingWritable.length}/${writable.length} materialized memory files are missing from the read-back set — more than one harvest may remove (${ceiling}), judged an accident: harvest refused, no patches`,
88
91
  };
89
92
  out.patches = [];
90
93
  return out;
91
94
  }
95
+ for (const b of missingWritable)
96
+ out.patches.push({ op: "delete", id: b.id, baseRev: b.rev });
92
97
  let kept = 0;
93
- for (const f of files) {
98
+ for (const f of carried) {
94
99
  const base = baseByRel.get(f.relPath);
95
100
  if (base?.readonly)
96
101
  continue;
@@ -1,5 +1,4 @@
1
- import type { MemoryOriginCause } from "./types.js";
2
- export declare const DELEGATION_SETTLEMENT_FILE = "delegation-settlement.json";
1
+ import type { MemoryGovernanceDocs, MemoryOriginCause } from "./types.js";
3
2
  /** A row's FIRST-WRITE status. Rows are immutable after their first write — every later transition
4
3
  * is an append-only event ({@link SettlementEvent}); the effective status is the fold. */
5
4
  export type SettlementRowStatus = "pending" | "unattestable";
@@ -45,12 +44,12 @@ export declare function syncSettleId(sessionId: string, toolCallId: string): str
45
44
  * or corrupt ledger — the launch site fails the launch loudly (a delegation that cannot be
46
45
  * accounted must not run: the whole point is that no child exists outside the account).
47
46
  */
48
- export declare function registerDelegationLaunch(controlDir: string, input: {
47
+ export declare function registerDelegationLaunch(docs: MemoryGovernanceDocs, input: {
49
48
  settleId: string;
50
49
  sessionId: string;
51
50
  now: () => number;
52
51
  toolUseId?: string;
53
- }): void;
52
+ }): Promise<void>;
54
53
  /**
55
54
  * §3.5 (r5-3) — the SYNC lane's unattestable row: a synchronous delegation delivered with a
56
55
  * missing/unknown attestation under the "attested-only" evidence standard. The row is a durable
@@ -59,11 +58,11 @@ export declare function registerDelegationLaunch(controlDir: string, input: {
59
58
  * throw here as "deliver an error instead" (fail-closed — unattested content must not ride into
60
59
  * the transcript of a session whose account could not record the fact).
61
60
  */
62
- export declare function recordSyncUnattestable(controlDir: string, input: {
61
+ export declare function recordSyncUnattestable(docs: MemoryGovernanceDocs, input: {
63
62
  sessionId: string;
64
63
  toolCallId: string;
65
64
  now: () => number;
66
- }): void;
65
+ }): Promise<void>;
67
66
  /**
68
67
  * §3.3 settle — append one observed terminal (idempotent per eventId; the default eventId keys on
69
68
  * (settleId, status) so an at-least-once observer replays into one event). Transition legality is
@@ -71,13 +70,13 @@ export declare function recordSyncUnattestable(controlDir: string, input: {
71
70
  * after `expired`) still lands — as an event row the fold reads as an annotation-grade fact — so
72
71
  * the account never loses an observation (事件不丢), it just doesn't let it rewrite history.
73
72
  */
74
- export declare function settleDelegation(controlDir: string, input: {
73
+ export declare function settleDelegation(docs: MemoryGovernanceDocs, input: {
75
74
  settleId: string;
76
75
  status: "clean" | "external" | "expired" | "void" | "unattestable";
77
76
  now: () => number;
78
77
  eventId?: string;
79
78
  note?: string;
80
- }): void;
79
+ }): Promise<void>;
81
80
  /**
82
81
  * §3.3 host valve — `resolveSettlement(settleId, "clean"|"external", requestId)`. Advisory, same
83
82
  * trust plane as the host API family; `requestId` is the audit anchor and is REQUIRED (a
@@ -85,12 +84,12 @@ export declare function settleDelegation(controlDir: string, input: {
85
84
  * semantics live in the fold: an admin `clean` flips the EFFECTIVE state (releases post-expiry)
86
85
  * but never the history bit, and a LATER observed `external` overrides it (观测证据>admin 裁决).
87
86
  */
88
- export declare function resolveSettlementRecord(controlDir: string, input: {
87
+ export declare function resolveSettlementRecord(docs: MemoryGovernanceDocs, input: {
89
88
  settleId: string;
90
89
  to: "clean" | "external";
91
90
  requestId: string;
92
91
  now: () => number;
93
- }): void;
92
+ }): Promise<void>;
94
93
  /** One settlement's folded (effective) view. */
95
94
  export interface EffectiveSettlement {
96
95
  row: DelegationSettlementRow;
@@ -104,9 +103,9 @@ export interface EffectiveSettlement {
104
103
  terminalEventId?: string;
105
104
  }
106
105
  /** Lock-less folded read of the whole ledger (journal-aware, fail-closed on corruption). */
107
- export declare function effectiveSettlements(controlDir: string): EffectiveSettlement[];
106
+ export declare function effectiveSettlements(docs: MemoryGovernanceDocs): Promise<EffectiveSettlement[]>;
108
107
  /** One session's folded rows (the harvest classifier's input). */
109
- export declare function sessionSettlements(controlDir: string, sessionId: string): EffectiveSettlement[];
108
+ export declare function sessionSettlements(docs: MemoryGovernanceDocs, sessionId: string): Promise<EffectiveSettlement[]>;
110
109
  /**
111
110
  * §3.1 — the session exposure classifier over the settlement account (the durable pollution marker
112
111
  * is the OTHER input; the caller ORs them). `exposed` ⇔ any {external, unattestable, expired}
@@ -123,10 +122,10 @@ export declare function classifySessionSettlements(rows: readonly EffectiveSettl
123
122
  * §3.3-4 — expire overdue pending rows (reconciliation's first leg). Every expiry is an event
124
123
  * (idempotent by (settleId, "expired") key); returns the settleIds newly expired this pass.
125
124
  */
126
- export declare function expireOverdueSettlements(controlDir: string, input: {
125
+ export declare function expireOverdueSettlements(docs: MemoryGovernanceDocs, input: {
127
126
  timeoutMs: number;
128
127
  now: () => number;
129
- }): string[];
128
+ }): Promise<string[]>;
130
129
  /**
131
130
  * §3.3-2 — replay the EXTERNAL rows' side effects (账先落、副作用可重放): ensure the durable
132
131
  * pollution marker is in place (wx, first-write-wins) and the retroaction challenge sweep has
@@ -136,14 +135,13 @@ export declare function expireOverdueSettlements(controlDir: string, input: {
136
135
  * `carry` scopes the sweep domain exactly like the engine's own sweeps (marked rows carry their
137
136
  * account under "carry"; the "off" width challenges everything).
138
137
  */
139
- export declare function replayExternalSettlementEffects(controlDir: string, input: {
138
+ export declare function replayExternalSettlementEffects(docs: MemoryGovernanceDocs, controlDir: string, input: {
140
139
  carry: boolean;
141
140
  now: () => number;
142
- }): Array<{
141
+ }): Promise<Array<{
143
142
  settleId: string;
144
143
  sessionId: string;
145
- }>;
146
- export declare const SESSION_ACCOUNTS_FILE = "session-accounts.json";
144
+ }>>;
147
145
  /** One member of the sticky set: the ledger form `(scope, rel)` — `rel` relative to the scope's
148
146
  * home, `/`-separated. Location-free, so a home move never re-keys the membership. */
149
147
  export interface UnattributedMember {
@@ -183,11 +181,14 @@ export interface SessionAccountRow {
183
181
  }
184
182
  /** The one-time v1 key-form conversions of the three engine sidecars, in one call (each in its own
185
183
  * lock, each idempotent). The layout adoption runs this before any later scope registration can
186
- * change what a v1 key's first segment names. */
184
+ * change what a v1 key's first segment names. A step of the File layout's own upgrade: it converts
185
+ * the hold ledger (a control-plane file, beside its custody) and the session-account document the File
186
+ * store keeps under `controlDir`, in place (a store that keeps documents elsewhere never held the v1
187
+ * form); the reads below convert the same way on first touch. */
187
188
  export declare function convertV1SidecarKeys(controlDir: string): void;
188
189
  /** The dangling-trigger read: open rows (and unadjudicated closes) belonging to OTHER sessions.
189
190
  * These are what arm the unattributed residue classification at a session's materialize. */
190
- export declare function foreignDanglingSessionAccounts(controlDir: string, selfSessionId: string): SessionAccountRow[];
191
+ export declare function foreignDanglingSessionAccounts(docs: MemoryGovernanceDocs, controlDir: string, selfSessionId: string): Promise<SessionAccountRow[]>;
191
192
  /** The live writers of the store's layers, as the account knows them: every row other than the one
192
193
  * held by `selfLeg` (the asking mount's own leg — another leg of the same session is another
193
194
  * writer) whose session's leg has not ended (no `terminatedAt` — running, or ended without
@@ -196,20 +197,20 @@ export declare function foreignDanglingSessionAccounts(controlDir: string, selfS
196
197
  * whether the leg ended) reads as before: live while never closed, counted in `unscoped` — a
197
198
  * writer of an unknown layer. Sessions that open no row (no session id, provenance "off", an
198
199
  * adoption-restricted mount) are not visible here. */
199
- export declare function openLayerWriters(controlDir: string, selfLeg: string | undefined): {
200
+ export declare function openLayerWriters(docs: MemoryGovernanceDocs, controlDir: string, selfLeg: string | undefined): Promise<{
200
201
  scopes: Set<string>;
201
202
  unscoped: number;
202
- };
203
+ }>;
203
204
  /** The leg that holds `sessionId`'s account row (undefined ⇔ no row, or a row without one). */
204
- export declare function sessionAccountLeg(controlDir: string, sessionId: string): string | undefined;
205
+ export declare function sessionAccountLeg(docs: MemoryGovernanceDocs, controlDir: string, sessionId: string): Promise<string | undefined>;
205
206
  /** The write scope `sessionId`'s account row records — the scope its newest account-opening mount wrote
206
207
  * under (the value that mount's handle carries as `writeScope`), whether that leg is still live or has
207
208
  * ended. Undefined ⇔ no row, a row written before the field, or a v1 ledger (whose rows predate it —
208
209
  * answered without the conversion, so this read writes nothing). Throws on a corrupt ledger. */
209
- export declare function sessionAccountWriteHome(controlDir: string, sessionId: string): {
210
+ export declare function sessionAccountWriteHome(docs: MemoryGovernanceDocs, sessionId: string): Promise<{
210
211
  writeScope: string;
211
212
  openedAt: number;
212
- } | undefined;
213
+ } | undefined>;
213
214
  /** The membership question the harvest asks per file: is `(scope, rel)` in the session's sticky
214
215
  * set? A session carrying members the conversion could not attribute answers yes for every seat. */
215
216
  export interface SessionUnattributedSet {
@@ -220,15 +221,15 @@ export interface SessionUnattributedSet {
220
221
  export declare function emptyUnattributedSet(): SessionUnattributedSet;
221
222
  /** Open (or re-open, on a same-session resume) the session's account row, persisting the sticky
222
223
  * unattributed classification frozen at THIS materialize. */
223
- export declare function openSessionAccount(controlDir: string, input: {
224
+ export declare function openSessionAccount(docs: MemoryGovernanceDocs, controlDir: string, input: {
224
225
  sessionId: string;
225
226
  now: () => number;
226
227
  unattributed: readonly UnattributedMember[];
227
228
  writeScope?: string;
228
229
  leg?: string;
229
- }): void;
230
+ }): Promise<void>;
230
231
  /** The current session's sticky unattributed set (the harvest's residue-arm input). */
231
- export declare function sessionUnattributedSet(controlDir: string, sessionId: string): SessionUnattributedSet;
232
+ export declare function sessionUnattributedSet(docs: MemoryGovernanceDocs, controlDir: string, sessionId: string): Promise<SessionUnattributedSet>;
232
233
  /** Close the session's account row — called ONLY after a FULL-domain harvest (zero BUDGET-deferred
233
234
  * files, i.e. `HarvestReport.degraded` absent): a partial harvest's close would launder the deferred
234
235
  * residue window (§3.6 序则②). A normal full close also clears every standing `unadjudicated` flag
@@ -243,32 +244,34 @@ export declare function sessionUnattributedSet(controlDir: string, sessionId: st
243
244
  * Returns what happened ({@link SessionAccountWrite}): `"absent"` (a session that never opened an
244
245
  * account — e.g. an adoption-restricted materialize — has no close, and the caller's disclosure
245
246
  * must not claim one), or `"stale"` when `leg` names a mount that no longer holds the row. */
246
- export declare function closeSessionAccount(controlDir: string, input: {
247
+ export declare function closeSessionAccount(docs: MemoryGovernanceDocs, controlDir: string, input: {
247
248
  sessionId: string;
248
249
  now: () => number;
249
250
  leg?: string;
250
- }): SessionAccountWrite;
251
+ }): Promise<SessionAccountWrite>;
251
252
  /** What a close / leg end did: wrote the row, found none, or found the row held by ANOTHER leg (the
252
253
  * caller's leg is over — a resume re-opened the row — so nothing was written). */
253
254
  export type SessionAccountWrite = "written" | "absent" | "stale";
254
255
  /** Record that the session's leg ended ({@link SessionAccountRow.terminatedAt}). Touches nothing
255
256
  * else — `closedAt` stays whatever the harvests made it. `leg` (the caller's mount) must hold the
256
257
  * row: a leg that is over does not end the one that re-opened it. */
257
- export declare function terminateSessionAccount(controlDir: string, input: {
258
+ export declare function terminateSessionAccount(docs: MemoryGovernanceDocs, controlDir: string, input: {
258
259
  sessionId: string;
259
260
  now: () => number;
260
261
  leg?: string;
261
- }): SessionAccountWrite;
262
+ }): Promise<SessionAccountWrite>;
262
263
  /** The host valve for a dangling row (advisory; §3.6 — dangling rows never auto-expire). The
263
264
  * close is `closed-unadjudicated` (r7-3): it stops the row dangling but the residue arm keeps
264
265
  * firing until a full-domain harvest closes normally. `requestId` required (audit, #123). */
265
- export declare function resolveSessionAccountRecord(controlDir: string, input: {
266
+ export declare function resolveSessionAccountRecord(docs: MemoryGovernanceDocs, controlDir: string, input: {
266
267
  sessionId: string;
267
268
  requestId: string;
268
269
  now: () => number;
269
- }): void;
270
- export declare const HOLDS_FILE = "holds.json";
271
- export declare const HOLD_DIR = "hold";
270
+ }): Promise<void>;
271
+ /** The hold ledger's file: the File store's coordinate of the governance document `holds`. */
272
+ export declare const HOLDS_FILE: string;
273
+ /** The hold custody directory: the File store's directory of the control-object kind `hold`. */
274
+ export declare const HOLD_DIR: string;
272
275
  export type HoldStatus = "capturing" | "held" | "released" | "disposed";
273
276
  export type HoldTerminal = "dirty" | "expired" | "conflict" | "discarded" | "capture_lost";
274
277
  export interface HoldRow {
@@ -384,17 +387,32 @@ export declare function openInstructionHold(controlDir: string, input: {
384
387
  * - `capturing` + custody absent + plane file gone ⇒ `capture_lost` (nothing to hold).
385
388
  * - `held` + plane file REAPPEARED at the seat ⇒ left alone (a fresh write is a fresh file —
386
389
  * the next harvest judges it on its own; the hold's custody bytes stay the hold's).
390
+ * - `disposed` + the row names its quarantine seat + the custody file is still at the custody seat
391
+ * ⇒ the disposal's move finishes (the row is written before the bytes move).
387
392
  */
388
393
  export declare function reconcileHolds(controlDir: string, input: {
389
394
  homeOf: (scope: string) => string;
390
395
  now: () => number;
396
+ onStranded: (scope: string, line: string) => void;
391
397
  }): void;
392
- /** Dispose one held row: custody bytes move to the quarantine directory (host-auditable), the row
393
- * records its terminal + quarantineName (from-row-to-bytes addressing survives every terminal). */
398
+ /** The quarantine seat of a hold's custody bytes: a function of the ROW, never of a clock. The same
399
+ * row names the same seat on every call, in every process, after any crash — the old
400
+ * `<ms>-hold-<captureName>` shape with the row's own content digest where the wall clock was. */
401
+ export declare function holdQuarantineNameOf(row: Pick<HoldRow, "captureName" | "contentDigest">): string;
402
+ /** Dispose one held row: the row records its terminal and the quarantine seat NAMED BY THE ROW
403
+ * ({@link holdQuarantineNameOf}) first, then the custody bytes move there (host-auditable;
404
+ * from-row-to-bytes addressing survives every terminal). Row first, bytes second: a crash between
405
+ * the two leaves a row whose bytes are at the custody seat or the quarantine seat — both of which
406
+ * {@link readHoldCustody} tries — and {@link reconcileHolds} finishes the move; the reverse order
407
+ * would leave bytes in quarantine under a name no row recorded. Whether the row names a seat is read
408
+ * INSIDE the ledger lock, from what stands at the custody seat and the quarantine seat at that
409
+ * moment: a row with no custody bytes anywhere records the terminal with no name (nothing to move).
410
+ * The verdict always lands: a quarantine seat held by something that is not the hold's bytes records
411
+ * the terminal with no name, leaves the custody bytes where they are and replaces nothing — and then
412
+ * refuses loudly (the caller hears it; a refused intake is terminal all the same). */
394
413
  export declare function disposeHold(controlDir: string, input: {
395
414
  holdId: string;
396
415
  terminal: HoldTerminal;
397
- now: () => number;
398
416
  }): {
399
417
  ok: boolean;
400
418
  quarantineName?: string;
@@ -444,4 +462,4 @@ export declare function clearHoldResolution(controlDir: string, input: {
444
462
  export declare function readHoldCustody(controlDir: string, row: HoldRow): string | undefined;
445
463
  /** True ⇔ the session's pollution marker or any non-clean settlement row blocks a clean release
446
464
  * (§4.2-1: any non-clean row in the session's account keeps the hold held/disposed). */
447
- export declare function sessionBlocksCleanRelease(controlDir: string, sessionId: string): boolean;
465
+ export declare function sessionBlocksCleanRelease(docs: MemoryGovernanceDocs, controlDir: string, sessionId: string): Promise<boolean>;