@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
@@ -1,7 +1,7 @@
1
1
  import { InMemorySessionRepo, ParentChainGuard, SessionError, findUnansweredToolBatch, compareOccupants, ownerCell, sessionLogMarkOf, uuidv7, } from "../internal/harness.js";
2
2
  import { isSessionConflict, readSessionListQuery } from "./session.js";
3
3
  import { readRetentionDeclaration } from "./retention.js";
4
- import { readMember } from "./thrown-value.js";
4
+ import { readMember, thrownText } from "./thrown-value.js";
5
5
  import { principalNameFault, principalNameOf } from "./principal-name.js";
6
6
  import { DECLARATION_RECEIPT_MODE, optionKeys, receiptRefusal, receiveMembers, receiveOptions } from "./own-property-receipt.js";
7
7
  import { describeFault, receive } from "./mods/kernel/receive.js";
@@ -261,7 +261,8 @@ export class TtlSessionStore {
261
261
  ...(forkedFrom !== undefined ? { forkedFrom } : {}),
262
262
  };
263
263
  }
264
- async fork(sourceId, owner) {
264
+ async fork(sourceId, owner, opts) {
265
+ const placement = opts?.placement;
265
266
  let source;
266
267
  try {
267
268
  source = await this.repo.open({ id: sourceId, createdAt: "" });
@@ -273,13 +274,32 @@ export class TtlSessionStore {
273
274
  throw err;
274
275
  }
275
276
  const forkOptions = await settledForkOptions(source);
276
- const forked = await this.repo.fork(await source.getMetadata(), { ...forkOptions, id: uuidv7(), ...(owner !== undefined ? { owner } : {}) });
277
+ const forked = await this.repo.fork(await source.getMetadata(), { ...forkOptions, id: uuidv7(), ...(owner !== undefined ? { owner } : {}), ...(placement !== undefined ? { placement } : {}) });
277
278
  const meta = await forked.getMetadata();
279
+ if (placement !== undefined) {
280
+ try {
281
+ this.assertPlacementAdmission(meta.id, meta.placement, { placement });
282
+ }
283
+ catch (refusal) {
284
+ let left;
285
+ try {
286
+ const created = { row: { owner: meta.owner ?? null, incarnation: meta.incarnation } };
287
+ await this.deleteRow(meta, this.repoHead !== undefined ? async () => created : undefined);
288
+ }
289
+ catch (err) {
290
+ left = err;
291
+ }
292
+ if (left === undefined)
293
+ throw refusal;
294
+ throw new SessionError("placement_refused", `${refusal.message} — and the copy ${meta.id} this fork created could not be removed (${thrownText(left)}); delete it by id`, refusal);
295
+ }
296
+ }
278
297
  this.entries.set(meta.id, {
279
298
  session: forked,
280
299
  lastActiveAt: Date.now(),
281
300
  createdAt: meta.createdAt,
282
301
  forkedFrom: meta.forkedFrom ?? sourceId,
302
+ ...(meta.placement !== undefined ? { placement: meta.placement } : {}),
283
303
  });
284
304
  return meta.id;
285
305
  }
@@ -35,7 +35,8 @@ export interface SessionPlacement {
35
35
  handle?: string;
36
36
  /** The delegation tree's owner: the owner of the tree root's row as the root run read it, carried unchanged to every descendant
37
37
  * (`null` = the root is anonymous). The placing write records exactly it in the row's owner cell — never in the tuple
38
- * ({@link SessionPlacementRecord} has no owner); a re-open ignores it (first-write immutable). */
38
+ * ({@link SessionPlacementRecord} has no owner); a re-open ignores it (first-write immutable). A placed FORK takes the tuple
39
+ * without it ({@link SessionStore.fork}: the fork's own owner argument is the row's owner). */
39
40
  owner: string | null;
40
41
  }
41
42
  /**
@@ -319,8 +320,18 @@ export interface SessionStore<S extends SessionStoreSummary = SessionStoreSummar
319
320
  * string is refused, with no row left behind) records that owner.
320
321
  * MUST copy the COMMITTED leaf (an in-flight uncommitted turn of an active source is not included — a fork is a
321
322
  * snapshot at the fork point).
323
+ *
324
+ * `opts.placement` (subagent transcript persistence): fork INTO the placement partition — the fork's creating write lays the
325
+ * tuple down exactly as a placed `acquire` does (first-write immutable, `placedAt` stamped by the store), so the forked row owes
326
+ * every placement obligation above and the row's placement reads back that tuple. The tuple carries no owner: the row's
327
+ * owner cell is the `owner` argument's, by the rule above (a background fork records its delegation tree's owner, which is its
328
+ * source row's). Trusted-internals channel only, as for `acquire`. On a store that declares {@link placements}, a fork whose
329
+ * row comes back without the declared tuple (a repo that dropped it) is refused `SessionError("placement_refused")` and the row
330
+ * is removed — the same mirror judgement a placed `acquire` takes.
322
331
  */
323
- fork?(sourceId: string, owner?: string | null): Promise<string | null>;
332
+ fork?(sourceId: string, owner?: string | null, opts?: {
333
+ placement?: Omit<SessionPlacement, "owner">;
334
+ }): Promise<string | null>;
324
335
  /**
325
336
  * The row's {@link SessionHead} for `sessionId` — owner, occupant and active leaf — in ONE read of the row, never assembled from
326
337
  * separate reads (a delete and re-create of the id between two reads would pair one generation's owner with the next one's
@@ -452,6 +463,9 @@ export interface SessionStoreHooks {
452
463
  export declare function hasSessionFork(store: SessionStore): store is SessionStore & {
453
464
  fork: NonNullable<SessionStore["fork"]>;
454
465
  };
466
+ /** Does this store declare the subagent placement partition ({@link SessionStore.placements})? The opt-in a placing write needs: the
467
+ * store that CREATES a row is handed a placement only when it declares, so no store holds tuples it never opted into. */
468
+ export declare function declaresSubagentPlacement(store: Pick<SessionStore, "placements">): boolean;
455
469
  /**
456
470
  * F3 bounded-wake recipe, packaged. Given the **path-ordered** entries of a branch
457
471
  * (root→leaf, e.g. `await session.getBranch(leafId)` or a durable store's leaf-walk),
@@ -63,6 +63,9 @@ function readListCursor(raw) {
63
63
  export function hasSessionFork(store) {
64
64
  return typeof store.fork === "function";
65
65
  }
66
+ export function declaresSubagentPlacement(store) {
67
+ return store.placements?.subagent !== undefined;
68
+ }
66
69
  export function boundedTail(pathEntries) {
67
70
  let lastCompaction;
68
71
  for (const e of pathEntries) {
@@ -1,6 +1,7 @@
1
1
  import { types } from "node:util";
2
2
  import { dispositionsOfRow, SHELL_READ_FINDINGS } from "../tools/fs/shell-read-judge.js";
3
3
  import { receiveContract } from "./decision-receipt.js";
4
+ import { refusalEchoDefects } from "./refusal-echo.js";
4
5
  import { egressThrownText } from "./untrusted-egress.js";
5
6
  import { receive } from "./mods/kernel/receive.js";
6
7
  import { attest, attestationOf } from "./engine-attestation.js";
@@ -13,6 +14,7 @@ const MEMBER_KINDS = {
13
14
  face: "face",
14
15
  sentence: "word",
15
16
  details: "record",
17
+ echoed: "list",
16
18
  readRootCandidate: "record",
17
19
  unestablished: "mark",
18
20
  writesPlaced: "mark",
@@ -43,6 +45,12 @@ function receivedAnswer(answer, call) {
43
45
  return undefined;
44
46
  v = data.value;
45
47
  }
48
+ if (kind === "list") {
49
+ const data = receive(v, OWNED_DATA_MODE);
50
+ if (!data.ok || !Array.isArray(data.value) || refusalEchoDefects(data.value).length > 0)
51
+ return undefined;
52
+ v = Object.freeze(data.value);
53
+ }
46
54
  if (kind === "admission") {
47
55
  const admission = v;
48
56
  v = () => {
@@ -2,18 +2,6 @@ import { type Checkpoint, type CheckpointStore, type ResumeOutcome } from "../ch
2
2
  import type { GateOutcome } from "../gate-outcome.js";
3
3
  import { type CheckpointFields } from "../pause-registry.js";
4
4
  import { type ContractAssertionRunner } from "./contract-harness.js";
5
- /**
6
- * design/159 S1 — the cross-backend {@link CheckpointStore} contract, extracted VERBATIM from
7
- * `test/cross-backend-shared.ts` (design/87 §3 gap [cross-backend-enforce], the anti-drift guard
8
- * born in design/80 §6.3) into a vitest-free kit a third-party backend implementor can import and
9
- * run under any harness (or none — see {@link ContractAssertionRunner}).
10
- *
11
- * `make()` must return a FRESH, empty store each call. Core binds this to InMemory + File
12
- * (`test/cross-backend-inmem-file.test.ts`) and Pg via pg-mem (`test/pg-cross-backend.test.ts`);
13
- * a third-party durable backend passes its own factory.
14
- *
15
- * Version lockstep: see `contract-kit-version.ts` (`CONTRACT_KIT_ENGINE_VERSION`).
16
- */
17
5
  /** Build a {@link Checkpoint} fixture. `createdAt` is FIXED (not wall-clock) so summary projections
18
6
  * are deterministic and cross-backend byte-comparable; override via `over` for ordering tests. */
19
7
  export declare function createCheckpointFixture(over?: Partial<CheckpointFields>): Checkpoint;
@@ -5,6 +5,7 @@ import { judgeCheckpointRow } from "../checkpoint-row-verdict.js";
5
5
  import { memberPresent } from "../own-property-receipt.js";
6
6
  import { checkpointFrom } from "../pause-registry.js";
7
7
  import { beginContract } from "./contract-harness.js";
8
+ const unhashedCall = (call) => call;
8
9
  export function createCheckpointFixture(over = {}) {
9
10
  const token = over.token ?? mintCheckpointToken();
10
11
  return checkpointFrom({
@@ -13,17 +14,16 @@ export function createCheckpointFixture(over = {}) {
13
14
  sessionId: "sess-1",
14
15
  leafId: "leaf-1",
15
16
  gate: { kind: "human", reason: "approve", toolName: "Write" },
16
- pendingAction: {
17
+ pendingAction: unhashedCall({
17
18
  kind: "tool_approval",
18
19
  origin: "policy",
19
20
  toolCallId: "call-3",
20
21
  toolName: "Write",
21
22
  args: { path: "/x", content: "y" },
22
- boundInputHash: "h0",
23
23
  boundGrantAbsence: "not_bindable",
24
24
  batchToolCallIds: ["call-3"],
25
25
  completedCallIds: [],
26
- },
26
+ }),
27
27
  state: {
28
28
  activeTools: [],
29
29
  nestedStats: { tokens: 0, turns: 0, tasks: 0, costMicroUsd: 0, anyUnpriced: false },
@@ -286,7 +286,7 @@ export async function checkpointStoreContract(make, runAssertion, options = {})
286
286
  const store = make();
287
287
  const okRow = createCheckpointFixture({
288
288
  sessionId: "verdict-ok",
289
- pendingAction: { kind: "tool_approval", origin: "policy", toolCallId: "call-3", toolName: "Write", args: { path: "/x", content: "y" }, preview: { lines: ["a"] }, boundInputHash: "h0", boundGrantAbsence: "not_bindable", batchToolCallIds: ["call-3"], completedCallIds: [] },
289
+ pendingAction: unhashedCall({ kind: "tool_approval", origin: "policy", toolCallId: "call-3", toolName: "Write", args: { path: "/x", content: "y" }, preview: { lines: ["a"] }, boundGrantAbsence: "not_bindable", batchToolCallIds: ["call-3"], completedCallIds: [] }),
290
290
  });
291
291
  const damagedRow = damagedWriteFaceFixture({ sessionId: "verdict-damaged" });
292
292
  for (const cp of [okRow, damagedRow])
@@ -720,7 +720,7 @@ export async function checkpointListByScopeSummaries(store) {
720
720
  toolName: "open_pr",
721
721
  riskDescriptor: { severity: 5, axes: { egress: true, irreversible: true }, toolName: "open_pr" },
722
722
  },
723
- pendingAction: {
723
+ pendingAction: unhashedCall({
724
724
  kind: "tool_approval",
725
725
  origin: "policy",
726
726
  mandated: true,
@@ -729,10 +729,9 @@ export async function checkpointListByScopeSummaries(store) {
729
729
  toolCallId: "call-pr",
730
730
  toolName: "open_pr",
731
731
  args: { repo: "x" },
732
- boundInputHash: "h0",
733
732
  batchToolCallIds: ["call-pr"],
734
733
  completedCallIds: [],
735
- },
734
+ }),
736
735
  });
737
736
  const resource = createCheckpointFixture({
738
737
  token: "tok-resource",
@@ -3,7 +3,7 @@ import { readPeerSessionRecord, resolvePeerSessions } from "../../agents/peer-di
3
3
  import { beginContract } from "./contract-harness.js";
4
4
  export const PEER_DIRECTORY_CONTRACT_SCOPE = "peer-kit-A";
5
5
  function row(name, sessionId, over = {}) {
6
- return { schemaVersion: 1, sessionId, scope: PEER_DIRECTORY_CONTRACT_SCOPE, name, startedAt: 1_000, updatedAt: 2_000, liveness: "live", where: "hosted", ...over };
6
+ return { schemaVersion: 1, sessionId, occupant: `occ-${sessionId}`, scope: PEER_DIRECTORY_CONTRACT_SCOPE, name, startedAt: 1_000, updatedAt: 2_000, liveness: "live", where: "hosted", ...over };
7
7
  }
8
8
  async function withDirs(mk, fn) {
9
9
  const live = [];
@@ -90,5 +90,12 @@ export async function peerDirectoryContract(mk, hooks) {
90
90
  assert.ok(read.ok, `listed row ${r.sessionId} is refused by the engine's reader (${read.ok ? "" : `${read.reason}${read.field !== undefined ? `: ${read.field}` : ""}`})`);
91
91
  }
92
92
  });
93
+ run("a row's occupant is listed as written — a token and null (a row with no token) alike", async (make) => {
94
+ const d = make();
95
+ await hooks.write(d, row("alpha", "sess-a"));
96
+ await hooks.write(d, row("beta", "sess-b", { occupant: null }));
97
+ const listed = await d.listPeerSessions({ scope: S });
98
+ assert.deepEqual(Object.fromEntries(listed.map((r) => [r.sessionId, r.occupant])), { "sess-a": "occ-sess-a", "sess-b": null }, "the occupant is what a sender stamps on what it parks in that session's box; a directory that loses or rewrites it misaddresses every message");
99
+ });
93
100
  await settle();
94
101
  }
@@ -780,6 +780,45 @@ async function runSessionStoreContract(make, hooks) {
780
780
  assert.ok(scoped.includes(complete) && scoped.includes(incomplete) && !scoped.includes(elsewhere), "scope narrows to one tenant");
781
781
  assert.ok(!(await store.listPlaced("subagent", { olderThanMs: 60 * 60 * 1000 })).some((r) => r.sessionId === complete), "a session placed just now is not an hour old");
782
782
  });
783
+ faceRun("[placements] a fork carrying a placement is created into the partition — the tuple reads back on the forked row, which stays off the host list, refuses a claim-form acquire, is listed placed and is deleted by its release, while its source stays ordinary — before and after a restart", ["placements", "fork"], async (store, open) => {
784
+ const src = freshId();
785
+ await append((await store.acquire(src)).session, userEntry("e1", null));
786
+ const { owner: _treeOwner, ...tuple } = placementFor(`kit-${uuidv7().slice(-12)}`);
787
+ const forkedId = await store.fork(src, null, { placement: { ...tuple, parentSessionId: src, rootSessionId: src } });
788
+ assert.ok(forkedId !== null && forkedId !== src, "a placed fork of an existing session is a new id");
789
+ const meta = await (await readBack(store, forkedId)).getMetadata();
790
+ assert.equal(meta.forkedFrom, src, "a placed fork still names its source");
791
+ assert.deepEqual({ kind: meta.placement?.kind, scope: meta.placement?.scope, handle: meta.placement?.handle, parentSessionId: meta.placement?.parentSessionId, rootSessionId: meta.placement?.rootSessionId }, { kind: "subagent", scope: tuple.scope, handle: tuple.handle, parentSessionId: src, rootSessionId: src }, "the fork's creating write laid the tuple down");
792
+ assert.equal(typeof meta.placement?.placedAt, "number", "the store stamped placedAt");
793
+ assert.deepEqual(await pathIds(await readBack(store, forkedId)), ["e1"], "the placed fork carries the source's committed history");
794
+ await rejectsWithCode(() => store.acquire(forkedId), "placement_refused", "obligation 6: a placed fork is not claimable");
795
+ await store.acquire(src);
796
+ if (typeof store.list === "function") {
797
+ const rows = await store.list();
798
+ assert.equal(rowOf(rows, forkedId), undefined, "obligation 2: a placed fork is not a host session");
799
+ assert.ok(rowOf(rows, src) !== undefined, "its source stays an ordinary, listed session");
800
+ }
801
+ if (typeof store.listPlaced === "function") {
802
+ const listed = (await store.listPlaced("subagent", { scope: tuple.scope })).find((r) => r.sessionId === forkedId);
803
+ assert.ok(listed !== undefined && !("tupleIncomplete" in listed) && listed.handle === tuple.handle, "the placed listing carries the fork with its join tuple");
804
+ }
805
+ const second = await open(hooks.reopen(store));
806
+ assert.equal((await readBack(second, forkedId).then((s) => s.getMetadata())).placement?.handle, tuple.handle, "the tuple lives in the row, not in an instance");
807
+ await rejectsWithCode(() => second.acquire(forkedId), "placement_refused", "obligation 6 after a restart");
808
+ await second.release(forkedId);
809
+ await rejectsWithCode(() => second.acquire(forkedId, { requireExisting: true }), "not_found", "obligation 4: the placed fork's release is a real deletion");
810
+ assert.deepEqual(await pathIds(await readBack(second, src)), ["e1"], "the source is untouched");
811
+ });
812
+ run("[placements] a store that does not declare placements still forks for a fork carrying a placement (ignoring it is legal, refusing the fork is not)", async (store) => {
813
+ if (declaresPlacements(store) || !hasSessionFork(store))
814
+ return;
815
+ const src = freshId();
816
+ await append((await store.acquire(src)).session, userEntry("e1", null));
817
+ const { owner: _treeOwner, ...tuple } = placementFor();
818
+ const forkedId = await store.fork(src, null, { placement: tuple });
819
+ assert.ok(forkedId !== null && forkedId !== src);
820
+ assert.deepEqual(await pathIds(await readBack(store, forkedId)), ["e1"]);
821
+ });
783
822
  faceRun("[head] headOf answers undefined for an id with no row; for a row, its owner, its occupant and its active leaf — the leaf follows appends and a branch switch", ["headOf"], async (store) => {
784
823
  const id = freshId();
785
824
  assert.equal(await headOf(store, id), undefined, "no row ⇒ undefined");
@@ -871,10 +871,12 @@ export type TaskEvent = ({
871
871
  * - `"blocked"` — a `preCompact` hook deliberately blocked the pass.
872
872
  * - `"suppressed"` — wanted to fire, held under the §25.2 anti-thrash floor.
873
873
  * - `"noop"` — the pass ran but found nothing to compact (no valid cut point/empty history).
874
- * - `"disabled"` — an explicit (manual/forced) request was refused because compaction is off,
875
- * or the rapid-refill breaker disabled compaction mid-task (`reason` says which). A spec
876
- * that statically disables compaction does NOT produce one of these per boundary (that
877
- * would be per-boundary noise about a static configuration, not a state change).
874
+ * - `"disabled"` — a requested pass (`trigger:"manual"`) was refused because the `manualCompact`
875
+ * seat is off, or the rapid-refill breaker disabled compaction mid-task (`reason` says so; the
876
+ * trigger is the landing pass's). The `trigger` names the seat: a `"manual"` frame is the
877
+ * `manualCompact` seat's, never the `autoCompact` seat's. A seat that is statically off does NOT
878
+ * produce one of these per boundary for the passes the engine would start (that would be
879
+ * per-boundary noise about a static configuration, not a state change).
878
880
  * - `"mooted"` — the pass did not run to its end: a manual request no boundary could serve
879
881
  * (`trigger:"manual"`, `reason:"task_ending"`), or a request withdrawn / a pass cut in flight by its
880
882
  * caller — a `compact({ signal })` withdrawal, `halt()`, `interrupt()`, `destroy()` or the task's own
@@ -1285,6 +1287,27 @@ export type TaskEvent = ({
1285
1287
  dir: string;
1286
1288
  byPath?: true;
1287
1289
  };
1290
+ /** The session's checkout (`TaskSpec.workspace`), one entry per repository, fixed by the session's first leg:
1291
+ * `repository` = the repository's root; `root` = which declared root lives there; `baseSha` = the commit the session's
1292
+ * code starts from. `dir` / `name` / `branch` / `baseRef` (present together) = the session's own tree of that
1293
+ * repository — with `root: "taskRoot"`, this leg's `root` is the task root's place in it. `source` = the declared
1294
+ * code source for that repository. ABSENT = the session declared no workspace. */
1295
+ session?: ReadonlyArray<{
1296
+ repository: string;
1297
+ root: "taskRoot" | {
1298
+ directory: string;
1299
+ };
1300
+ baseSha: string;
1301
+ dir?: string;
1302
+ name?: string;
1303
+ branch?: string;
1304
+ baseRef?: "fresh" | "head" | "source";
1305
+ source?: {
1306
+ remote: string;
1307
+ sha: string;
1308
+ ref?: string;
1309
+ };
1310
+ }>;
1288
1311
  /** This leg's project identity, decided ONCE at leg start and fixed for the leg: `marker` = the checkout's
1289
1312
  * `.sema/project` (a `TaskSpec.projectId`, when given, equals it); `declared` = `TaskSpec.projectId` in a checkout
1290
1313
  * that carries no marker. ABSENT = no marker and no declaration, or the marker could not be read (the deployment's
@@ -1371,6 +1394,8 @@ export interface HumanInputAttachment {
1371
1394
  * durable suspend / plan review in flight), or the task settled before any boundary arrived.
1372
1395
  * - `"noop"` — the attempt ran but there was nothing to compact (no valid cut point / empty history).
1373
1396
  * - `"blocked"` — a `preCompact` hook deliberately blocked this compaction (not a failure).
1374
- * - `"disabled"` — compaction is disabled by the task spec (`compaction.enabled: false`).
1397
+ * - `"disabled"` — requested compaction is switched off: the `manualCompact` seat is `false` (the task's
1398
+ * `compaction.manualCompact`, else the deployment's `contextSettings[word].manualCompact`). No pass ran. The
1399
+ * `autoCompact` seat never answers a request: with it off a requested pass still runs.
1375
1400
  */
1376
1401
  export type CompactOutcome = "compacted" | "failed" | "mooted" | "noop" | "blocked" | "disabled";