@sema-agent/core 7.67.3 → 7.68.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 (496) hide show
  1. package/CHANGELOG.md +1516 -0
  2. package/README.md +18 -9
  3. package/README.zh-CN.md +16 -8
  4. package/dist/agents/agent-definition.d.ts +1 -1
  5. package/dist/agents/agent-definition.js +4 -1
  6. package/dist/agents/cascade.d.ts +2 -2
  7. package/dist/agents/cascade.js +3 -1
  8. package/dist/agents/cumulative-stats.d.ts +2 -1
  9. package/dist/agents/cumulative-stats.js +4 -1
  10. package/dist/agents/list-agents-tool.d.ts +30 -0
  11. package/dist/agents/list-agents-tool.js +45 -3
  12. package/dist/agents/peer-admission.d.ts +2 -2
  13. package/dist/agents/peer-session-drain.d.ts +2 -0
  14. package/dist/agents/peer-session-drain.js +1 -0
  15. package/dist/agents/repair-loop.js +3 -1
  16. package/dist/agents/retain-ledger.d.ts +61 -8
  17. package/dist/agents/retain-ledger.js +25 -3
  18. package/dist/agents/roster-store.d.ts +4 -2
  19. package/dist/agents/send-message-tool.d.ts +1 -1
  20. package/dist/agents/send-message-tool.js +20 -15
  21. package/dist/agents/subagent-steps.js +2 -10
  22. package/dist/agents/subagent.d.ts +3 -0
  23. package/dist/agents/subagent.js +106 -76
  24. package/dist/agents/tool-filter.d.ts +20 -11
  25. package/dist/agents/tool-filter.js +8 -4
  26. package/dist/agents/verify.d.ts +3 -1
  27. package/dist/agents/verify.js +2 -0
  28. package/dist/brain/anthropic.js +4 -4
  29. package/dist/brain/open-responses.js +3 -1
  30. package/dist/brain/openai.js +3 -1
  31. package/dist/brain/reasoning-request.d.ts +73 -19
  32. package/dist/brain/reasoning-request.js +164 -72
  33. package/dist/brain/reasoning-stamp.d.ts +26 -0
  34. package/dist/brain/reasoning-stamp.js +10 -0
  35. package/dist/brain/reasoning.d.ts +95 -162
  36. package/dist/brain/reasoning.js +31 -86
  37. package/dist/brain/route-adjudicator.d.ts +9 -7
  38. package/dist/brain/route-adjudicator.js +12 -10
  39. package/dist/brain/status-sink.d.ts +19 -64
  40. package/dist/brain/status-sink.js +5 -21
  41. package/dist/brain/stream-engine.d.ts +11 -2
  42. package/dist/brain/stream-engine.js +10 -0
  43. package/dist/core/a2a.d.ts +17 -5
  44. package/dist/core/a2a.js +11 -3
  45. package/dist/core/allow-entry.d.ts +35 -15
  46. package/dist/core/allow-entry.js +47 -60
  47. package/dist/core/ask-headline.d.ts +68 -0
  48. package/dist/core/ask-headline.js +23 -0
  49. package/dist/core/ask-origin.d.ts +36 -8
  50. package/dist/core/ask-origin.js +17 -10
  51. package/dist/core/ask-question.d.ts +34 -7
  52. package/dist/core/ask-question.js +10 -1
  53. package/dist/core/ask-unresolvable-notice.d.ts +7 -0
  54. package/dist/core/ask-unresolvable-notice.js +9 -3
  55. package/dist/core/auto-strip.d.ts +53 -0
  56. package/dist/core/auto-strip.js +76 -0
  57. package/dist/core/background-agent-store.d.ts +45 -5
  58. package/dist/core/background-agent-store.js +69 -15
  59. package/dist/core/background-shell.d.ts +2 -2
  60. package/dist/core/caller-text.js +2 -2
  61. package/dist/core/canonical-json.d.ts +13 -0
  62. package/dist/core/canonical-json.js +7 -0
  63. package/dist/core/checkpoint-features.d.ts +66 -20
  64. package/dist/core/checkpoint-features.js +12 -1
  65. package/dist/core/checkpoint-generation.d.ts +1 -1
  66. package/dist/core/checkpoint-queries.d.ts +1 -1
  67. package/dist/core/checkpoint-queries.js +4 -1
  68. package/dist/core/checkpoint-requirements.d.ts +25 -1
  69. package/dist/core/checkpoint-requirements.js +5 -1
  70. package/dist/core/checkpoint-row-verdict.d.ts +1 -0
  71. package/dist/core/checkpoint-row-verdict.js +4 -0
  72. package/dist/core/checkpoint-store.d.ts +66 -38
  73. package/dist/core/checkpoint-store.js +15 -6
  74. package/dist/core/child-clamp-seats.d.ts +6 -0
  75. package/dist/core/child-clamp-seats.js +1 -0
  76. package/dist/core/config-refusal-codes.d.ts +1 -1
  77. package/dist/core/config-refusal-codes.js +1 -0
  78. package/dist/core/delegation-frames.d.ts +9 -12
  79. package/dist/core/delegation-frames.js +9 -8
  80. package/dist/core/engine-capabilities.d.ts +21 -8
  81. package/dist/core/engine-capabilities.js +1 -1
  82. package/dist/core/engine-notice.d.ts +147 -34
  83. package/dist/core/engine-notice.js +27 -16
  84. package/dist/core/engine-storage-backend.d.ts +2 -1
  85. package/dist/core/env-budget.js +3 -3
  86. package/dist/core/env-knob-announce.d.ts +10 -10
  87. package/dist/core/env-knob-announce.js +3 -6
  88. package/dist/core/file-history-store.d.ts +29 -4
  89. package/dist/core/file-history-store.js +13 -0
  90. package/dist/core/frame-settlement.d.ts +2 -1
  91. package/dist/core/gate-fold.js +1 -1
  92. package/dist/core/gate-lanes.js +56 -49
  93. package/dist/core/governance-codes.d.ts +39 -3
  94. package/dist/core/governance-codes.js +61 -3
  95. package/dist/core/hooks.d.ts +29 -11
  96. package/dist/core/hooks.js +5 -2
  97. package/dist/core/human-input-projection.js +3 -3
  98. package/dist/core/input-author.d.ts +17 -3
  99. package/dist/core/input-author.js +15 -3
  100. package/dist/core/leg-identity.d.ts +10 -28
  101. package/dist/core/leg-identity.js +1 -21
  102. package/dist/core/lsp.d.ts +18 -13
  103. package/dist/core/lsp.js +30 -22
  104. package/dist/core/mailbox-store.d.ts +1 -1
  105. package/dist/core/mailbox-store.js +4 -4
  106. package/dist/core/mcp-connection-pool.d.ts +93 -4
  107. package/dist/core/mcp-connection-pool.js +104 -1
  108. package/dist/core/mcp-failure.d.ts +38 -12
  109. package/dist/core/mcp-failure.js +9 -13
  110. package/dist/core/mcp-probe.d.ts +4 -3
  111. package/dist/core/mcp-server-link.d.ts +4 -2
  112. package/dist/core/mcp-server-link.js +4 -5
  113. package/dist/core/mcp-server-spec.d.ts +3 -3
  114. package/dist/core/mcp-server-unavailable-notice.d.ts +22 -8
  115. package/dist/core/mcp-server-unavailable-notice.js +18 -4
  116. package/dist/core/mcp.d.ts +40 -6
  117. package/dist/core/mcp.js +39 -13
  118. package/dist/core/memory-engine/content-origin.js +2 -2
  119. package/dist/core/memory-engine/control-objects.d.ts +2 -4
  120. package/dist/core/memory-engine/control-objects.js +2 -10
  121. package/dist/core/memory-engine/delegation-settlement.js +6 -1
  122. package/dist/core/memory-engine/dual-root.js +3 -0
  123. package/dist/core/memory-engine/engine.d.ts +6 -4
  124. package/dist/core/memory-engine/engine.js +32 -29
  125. package/dist/core/memory-engine/file-backend.d.ts +20 -5
  126. package/dist/core/memory-engine/file-backend.js +21 -31
  127. package/dist/core/memory-engine/frontmatter.d.ts +2 -0
  128. package/dist/core/memory-engine/frontmatter.js +4 -0
  129. package/dist/core/memory-engine/layout.d.ts +114 -20
  130. package/dist/core/memory-engine/layout.js +340 -22
  131. package/dist/core/memory-engine/memory-deployment.d.ts +7 -5
  132. package/dist/core/memory-engine/mount-failed-notice.d.ts +19 -7
  133. package/dist/core/memory-engine/mount-failed-notice.js +43 -10
  134. package/dist/core/memory-engine/sync-client.js +4 -5
  135. package/dist/core/model-fallbacks.d.ts +5 -1
  136. package/dist/core/model-fallbacks.js +3 -3
  137. package/dist/core/model-receipt.d.ts +2 -1
  138. package/dist/core/model-receipt.js +12 -1
  139. package/dist/core/mods/kernel/dispatch.d.ts +2 -2
  140. package/dist/core/mods/kernel/dispatch.js +14 -6
  141. package/dist/core/mods/kernel/events.d.ts +8 -5
  142. package/dist/core/mods/kernel/events.js +2 -2
  143. package/dist/core/mods/kernel/index.d.ts +1 -1
  144. package/dist/core/mods/kernel/registration.d.ts +9 -0
  145. package/dist/core/mods/package.js +1 -1
  146. package/dist/core/mods/session-append.d.ts +4 -2
  147. package/dist/core/mods/session-append.js +3 -0
  148. package/dist/core/mods/stations.d.ts +7 -11
  149. package/dist/core/mods/stations.js +4 -7
  150. package/dist/core/mods/tool-call.d.ts +10 -8
  151. package/dist/core/mods/tool-call.js +15 -18
  152. package/dist/core/mounted-mcp.d.ts +0 -4
  153. package/dist/core/mounted-mcp.js +1 -1
  154. package/dist/core/park-noun.d.ts +24 -0
  155. package/dist/core/park-noun.js +21 -0
  156. package/dist/core/park-resumability.d.ts +60 -0
  157. package/dist/core/park-resumability.js +30 -0
  158. package/dist/core/permission-rule-provider.d.ts +24 -2
  159. package/dist/core/permission-rule-provider.js +11 -8
  160. package/dist/core/permission-rule-store.d.ts +8 -1
  161. package/dist/core/permission-rule-store.js +2 -3
  162. package/dist/core/permission-rules.d.ts +2 -1
  163. package/dist/core/permission-rules.js +8 -4
  164. package/dist/core/persisted-rule-arms.d.ts +3 -0
  165. package/dist/core/persisted-rule-arms.js +2 -1
  166. package/dist/core/present-plan-tool.d.ts +47 -3
  167. package/dist/core/present-plan-tool.js +62 -4
  168. package/dist/core/principal-name.d.ts +1 -1
  169. package/dist/core/principal-name.js +5 -5
  170. package/dist/core/process-identity.js +10 -5
  171. package/dist/core/protocol-http-auth.d.ts +20 -14
  172. package/dist/core/protocol-http-auth.js +70 -50
  173. package/dist/core/read-only-shell.js +9 -5
  174. package/dist/core/redaction-marks.d.ts +4 -26
  175. package/dist/core/redaction-marks.js +9 -21
  176. package/dist/core/remote-env.d.ts +43 -16
  177. package/dist/core/remote-env.js +1 -1
  178. package/dist/core/request-copy-projection.d.ts +1 -1
  179. package/dist/core/request-copy-projection.js +40 -50
  180. package/dist/core/resume-config-judge.js +1 -1
  181. package/dist/core/resume-startup-cause.d.ts +35 -18
  182. package/dist/core/resume-startup-cause.js +13 -10
  183. package/dist/core/retention.d.ts +167 -25
  184. package/dist/core/retention.js +100 -20
  185. package/dist/core/roles.d.ts +6 -0
  186. package/dist/core/roles.js +11 -5
  187. package/dist/core/rule-lane-reads.d.ts +3 -0
  188. package/dist/core/rule-lane-reads.js +5 -1
  189. package/dist/core/rule-store-fault.d.ts +70 -0
  190. package/dist/core/rule-store-fault.js +102 -0
  191. package/dist/core/runner/advertised-writable-dirs.js +16 -31
  192. package/dist/core/runner/announce-once-ledger.d.ts +19 -2
  193. package/dist/core/runner/announce-once-ledger.js +24 -2
  194. package/dist/core/runner/assemble-result.d.ts +6 -0
  195. package/dist/core/runner/assemble-result.js +1 -1
  196. package/dist/core/runner/auto-strip-notice.d.ts +36 -0
  197. package/dist/core/runner/auto-strip-notice.js +59 -0
  198. package/dist/core/runner/branch-window.d.ts +3 -0
  199. package/dist/core/runner/branch-window.js +37 -0
  200. package/dist/core/runner/caller-roster.d.ts +8 -3
  201. package/dist/core/runner/capability-withheld-seat.js +3 -9
  202. package/dist/core/runner/clock-and-limits.d.ts +22 -1
  203. package/dist/core/runner/clock-and-limits.js +30 -0
  204. package/dist/core/runner/contracts.d.ts +58 -35
  205. package/dist/core/runner/credential-refusal-seat.d.ts +2 -0
  206. package/dist/core/runner/credential-refusal-seat.js +47 -0
  207. package/dist/core/runner/cross-boundary-lane.js +6 -4
  208. package/dist/core/runner/decide-continuation.js +1 -1
  209. package/dist/core/runner/file-history-restore.d.ts +53 -2
  210. package/dist/core/runner/file-history-restore.js +29 -10
  211. package/dist/core/runner/forward-sink.d.ts +14 -1
  212. package/dist/core/runner/forward-sink.js +14 -12
  213. package/dist/core/runner/gate-exit.d.ts +8 -7
  214. package/dist/core/runner/gate-exit.js +13 -13
  215. package/dist/core/runner/git-status-frame.js +2 -4
  216. package/dist/core/runner/initial-run-state.js +1 -1
  217. package/dist/core/runner/main-call-account.d.ts +3 -1
  218. package/dist/core/runner/main-call-account.js +5 -3
  219. package/dist/core/runner/mcp-redial.d.ts +2 -5
  220. package/dist/core/runner/mcp-redial.js +2 -2
  221. package/dist/core/runner/nested-memory-content.d.ts +7 -1
  222. package/dist/core/runner/nested-memory-content.js +73 -13
  223. package/dist/core/runner/nested-memory-lane.d.ts +44 -19
  224. package/dist/core/runner/nested-memory-lane.js +152 -76
  225. package/dist/core/runner/park-commit.js +3 -1
  226. package/dist/core/runner/permission-rule-lanes.d.ts +8 -2
  227. package/dist/core/runner/permission-rule-lanes.js +29 -3
  228. package/dist/core/runner/person-path-rows.d.ts +3 -11
  229. package/dist/core/runner/person-path-rows.js +21 -24
  230. package/dist/core/runner/prepare-acquire-reconcile.js +3 -1
  231. package/dist/core/runner/prepare-artifact.d.ts +1 -1
  232. package/dist/core/runner/prepare-artifact.js +20 -14
  233. package/dist/core/runner/prepare-ask-lane.d.ts +9 -6
  234. package/dist/core/runner/prepare-ask-lane.js +6 -5
  235. package/dist/core/runner/prepare-boundary-parks.d.ts +7 -1
  236. package/dist/core/runner/prepare-boundary-parks.js +27 -24
  237. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -2
  238. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  239. package/dist/core/runner/prepare-config-doors.d.ts +9 -24
  240. package/dist/core/runner/prepare-config-doors.js +58 -41
  241. package/dist/core/runner/prepare-context-lane.d.ts +2 -2
  242. package/dist/core/runner/prepare-context-lane.js +3 -5
  243. package/dist/core/runner/prepare-defer-classify.d.ts +1 -1
  244. package/dist/core/runner/prepare-defer-classify.js +1 -1
  245. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
  246. package/dist/core/runner/prepare-delegation-surface.js +3 -2
  247. package/dist/core/runner/prepare-file-history.d.ts +62 -26
  248. package/dist/core/runner/prepare-file-history.js +117 -46
  249. package/dist/core/runner/prepare-gate-stations.d.ts +4 -0
  250. package/dist/core/runner/prepare-gate-stations.js +6 -5
  251. package/dist/core/runner/prepare-hands-readface.d.ts +9 -4
  252. package/dist/core/runner/prepare-hands-readface.js +8 -4
  253. package/dist/core/runner/prepare-inherited-gate.d.ts +11 -4
  254. package/dist/core/runner/prepare-inherited-gate.js +6 -6
  255. package/dist/core/runner/prepare-listings.d.ts +1 -1
  256. package/dist/core/runner/prepare-listings.js +1 -1
  257. package/dist/core/runner/prepare-memory.js +2 -2
  258. package/dist/core/runner/prepare-offload-wrappers.d.ts +1 -1
  259. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  260. package/dist/core/runner/prepare-park-ask.d.ts +10 -3
  261. package/dist/core/runner/prepare-park-ask.js +7 -9
  262. package/dist/core/runner/prepare-policy-chain.d.ts +18 -9
  263. package/dist/core/runner/prepare-policy-chain.js +18 -13
  264. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  265. package/dist/core/runner/prepare-project-context.js +5 -3
  266. package/dist/core/runner/prepare-prompt-assembly.js +2 -1
  267. package/dist/core/runner/prepare-prompt-inputs.d.ts +2 -2
  268. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  269. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -5
  270. package/dist/core/runner/prepare-protocol-tools.js +7 -7
  271. package/dist/core/runner/prepare-question-face.d.ts +4 -2
  272. package/dist/core/runner/prepare-run-refs.d.ts +7 -2
  273. package/dist/core/runner/prepare-run-refs.js +8 -7
  274. package/dist/core/runner/prepare-safety-scan.d.ts +4 -3
  275. package/dist/core/runner/prepare-suspend-saga.d.ts +3 -7
  276. package/dist/core/runner/prepare-suspend-saga.js +4 -3
  277. package/dist/core/runner/prepare-task.js +66 -53
  278. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +3 -2
  279. package/dist/core/runner/prepare-tool-disclosure-mount.js +2 -1
  280. package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
  281. package/dist/core/runner/prepare-turn-wiring.js +1 -1
  282. package/dist/core/runner/prepare-wiring-manifest.d.ts +9 -4
  283. package/dist/core/runner/prepare-wiring-manifest.js +14 -6
  284. package/dist/core/runner/prepare-workspace-restore.d.ts +4 -4
  285. package/dist/core/runner/prepare-workspace-restore.js +15 -6
  286. package/dist/core/runner/remote-env-retry.d.ts +3 -3
  287. package/dist/core/runner/restore-seat.d.ts +41 -0
  288. package/dist/core/runner/restore-seat.js +38 -0
  289. package/dist/core/runner/resume-admission.js +1 -1
  290. package/dist/core/runner/resume-apply.js +4 -3
  291. package/dist/core/runner/resume-checkpoint-screen.js +2 -1
  292. package/dist/core/runner/resume-internals-and-config.js +2 -1
  293. package/dist/core/runner/resume-preflight.js +2 -1
  294. package/dist/core/runner/rewind-files.js +22 -6
  295. package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -0
  296. package/dist/core/runner/rule-store-unreadable-notice.js +11 -0
  297. package/dist/core/runner/run-brain-sinks.d.ts +3 -6
  298. package/dist/core/runner/run-brain-sinks.js +6 -6
  299. package/dist/core/runner/run-compaction-machinery.d.ts +2 -2
  300. package/dist/core/runner/run-git-lane.d.ts +2 -0
  301. package/dist/core/runner/run-git-lane.js +2 -1
  302. package/dist/core/runner/run-harness-handlers.js +5 -4
  303. package/dist/core/runner/run-identity-wiring.js +20 -12
  304. package/dist/core/runner/run-leg.js +31 -72
  305. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  306. package/dist/core/runner/run-notification-lane.js +2 -4
  307. package/dist/core/runner/run-reasoning-seat.d.ts +5 -6
  308. package/dist/core/runner/run-reasoning-seat.js +13 -18
  309. package/dist/core/runner/run-settle-and-teardown.js +13 -9
  310. package/dist/core/runner/run-terminal-adoption.js +4 -8
  311. package/dist/core/runner/run-turn-boundary.js +6 -3
  312. package/dist/core/runner/runtask.d.ts +9 -4
  313. package/dist/core/runner/runtask.js +29 -22
  314. package/dist/core/runner/session-rule-policy.d.ts +11 -1
  315. package/dist/core/runner/shell-env-withheld.js +2 -7
  316. package/dist/core/runner/side-call-account.d.ts +5 -6
  317. package/dist/core/runner/side-call-account.js +2 -2
  318. package/dist/core/runner/stream-lifecycle-verbs.d.ts +3 -0
  319. package/dist/core/runner/stream-lifecycle-verbs.js +5 -3
  320. package/dist/core/runner/stream-settle-backstop.js +4 -6
  321. package/dist/core/runner/stream-steer-verb.d.ts +1 -1
  322. package/dist/core/runner/stream-steer-verb.js +4 -4
  323. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -3
  324. package/dist/core/runner/sub-agent-deny-lists.js +7 -4
  325. package/dist/core/runner/teardown-bounded.d.ts +7 -0
  326. package/dist/core/runner/teardown-bounded.js +7 -0
  327. package/dist/core/runner/terminal-account.js +41 -13
  328. package/dist/core/runner/terminal-projection.d.ts +1 -5
  329. package/dist/core/runner/tool-end-body.d.ts +9 -3
  330. package/dist/core/runner/tool-end-body.js +6 -3
  331. package/dist/core/runner/tool-output-projection.d.ts +13 -4
  332. package/dist/core/runner/tool-output-projection.js +10 -14
  333. package/dist/core/runner/turn-attachments.d.ts +3 -2
  334. package/dist/core/runner/turn-attachments.js +12 -5
  335. package/dist/core/runner-deps.d.ts +6 -6
  336. package/dist/core/runtime-caps.d.ts +2 -1
  337. package/dist/core/secret-env.d.ts +20 -3
  338. package/dist/core/secret-env.js +13 -15
  339. package/dist/core/session-checkout.d.ts +115 -15
  340. package/dist/core/session-checkout.js +435 -136
  341. package/dist/core/session-policy-store.js +21 -3
  342. package/dist/core/session-reconcile.js +1 -0
  343. package/dist/core/session-store.js +2 -0
  344. package/dist/core/session.d.ts +11 -1
  345. package/dist/core/shell-run-candidates.d.ts +1 -0
  346. package/dist/core/shell-run-candidates.js +1 -1
  347. package/dist/core/shutdown-debug.d.ts +6 -5
  348. package/dist/core/shutdown-debug.js +5 -1
  349. package/dist/core/skill-grant.js +4 -1
  350. package/dist/core/skills-directory.js +5 -3
  351. package/dist/core/spec-contract.d.ts +1 -1
  352. package/dist/core/store-contracts/checkpoint-store-contract.js +2 -7
  353. package/dist/core/store-contracts/file-history-store-contract.js +26 -2
  354. package/dist/core/store-contracts/session-deletion-cascade-contract.js +130 -14
  355. package/dist/core/store-contracts/task-list-store-contract.d.ts +2 -1
  356. package/dist/core/store-contracts/task-list-store-contract.js +28 -1
  357. package/dist/core/task-event.d.ts +48 -27
  358. package/dist/core/task-notification.d.ts +15 -9
  359. package/dist/core/task-notification.js +12 -0
  360. package/dist/core/task-registry-agent.d.ts +24 -22
  361. package/dist/core/task-registry-agent.js +65 -46
  362. package/dist/core/task-registry-shared.d.ts +17 -5
  363. package/dist/core/task-registry.d.ts +17 -6
  364. package/dist/core/task-registry.js +6 -1
  365. package/dist/core/task-result.d.ts +71 -25
  366. package/dist/core/task-spec-members.d.ts +0 -1
  367. package/dist/core/task-spec-members.js +1 -1
  368. package/dist/core/task-spec.d.ts +60 -52
  369. package/dist/core/task-stream.d.ts +45 -12
  370. package/dist/core/terminal-cause.d.ts +45 -8
  371. package/dist/core/terminal-cause.js +5 -0
  372. package/dist/core/tool-card-bound.d.ts +32 -0
  373. package/dist/core/tool-card-bound.js +33 -0
  374. package/dist/core/tool-catalog-entries.d.ts +9 -0
  375. package/dist/core/tool-catalog-entries.js +48 -0
  376. package/dist/core/tool-errors.d.ts +4 -3
  377. package/dist/core/tool-face.d.ts +3 -3
  378. package/dist/core/tool-mount-facts.d.ts +3 -2
  379. package/dist/core/tool-mount-facts.js +1 -1
  380. package/dist/core/tool-mount-static.js +7 -5
  381. package/dist/core/tool-policy.d.ts +21 -19
  382. package/dist/core/tool-policy.js +5 -6
  383. package/dist/core/tool-registry.d.ts +3 -1
  384. package/dist/core/tool-registry.js +15 -1
  385. package/dist/core/tool-result-store.d.ts +9 -3
  386. package/dist/core/tool-result-store.js +14 -1
  387. package/dist/core/tool-roster.d.ts +6 -0
  388. package/dist/core/tool-roster.js +18 -0
  389. package/dist/core/tool-spec.d.ts +17 -8
  390. package/dist/core/trace.d.ts +35 -31
  391. package/dist/core/types.d.ts +2 -2
  392. package/dist/core/untrusted-egress.d.ts +10 -9
  393. package/dist/core/untrusted-egress.js +9 -9
  394. package/dist/core/untrusted-text.d.ts +0 -18
  395. package/dist/core/untrusted-text.js +7 -3
  396. package/dist/core/user-attachment.d.ts +9 -6
  397. package/dist/core/user-attachment.js +12 -10
  398. package/dist/core/user-row-origin.d.ts +44 -25
  399. package/dist/core/user-row-origin.js +30 -20
  400. package/dist/core/wiring-manifest.d.ts +26 -7
  401. package/dist/core/wiring-manifest.js +14 -11
  402. package/dist/core/workspace-snapshot.d.ts +3 -1
  403. package/dist/core/workspace-snapshot.js +1 -0
  404. package/dist/engine/execution-env/node-execution-env.d.ts +23 -16
  405. package/dist/engine/execution-env/node-execution-env.js +127 -67
  406. package/dist/engine/harness/agent-harness.d.ts +4 -5
  407. package/dist/engine/harness/agent-harness.js +2 -7
  408. package/dist/engine/harness/types.d.ts +51 -19
  409. package/dist/engine/harness/types.js +28 -1
  410. package/dist/engine/llm/types.d.ts +26 -14
  411. package/dist/engine/llm/types.js +2 -2
  412. package/dist/engine/loop/agent-loop.d.ts +2 -2
  413. package/dist/engine/loop/agent-loop.js +51 -275
  414. package/dist/engine/loop/types.d.ts +0 -18
  415. package/dist/engine/session/import-validate.d.ts +3 -0
  416. package/dist/engine/session/import-validate.js +34 -2
  417. package/dist/engine/session/repo-utils.d.ts +42 -4
  418. package/dist/engine/session/repo-utils.js +33 -5
  419. package/dist/engine/session/session.d.ts +41 -14
  420. package/dist/engine/session/session.js +96 -25
  421. package/dist/index.d.ts +21 -16
  422. package/dist/index.js +16 -10
  423. package/dist/orchestration/run-spec.d.ts +1 -1
  424. package/dist/orchestration/run-workflow-tool.d.ts +12 -9
  425. package/dist/orchestration/run-workflow-tool.js +15 -19
  426. package/dist/orchestration/workflow-governance.js +13 -21
  427. package/dist/orchestration/workflow-observe.d.ts +4 -3
  428. package/dist/orchestration/workflow-primitives.d.ts +1 -1
  429. package/dist/orchestration/workflow-record-artifact.d.ts +14 -0
  430. package/dist/orchestration/workflow-record-artifact.js +32 -0
  431. package/dist/orchestration/workflow-script-store.d.ts +9 -0
  432. package/dist/orchestration/workflow-script-store.js +20 -1
  433. package/dist/orchestration/workflow-types.d.ts +33 -3
  434. package/dist/orchestration/workflow.d.ts +24 -14
  435. package/dist/orchestration/workflow.js +52 -23
  436. package/dist/prompt-assembly/artifact.js +4 -8
  437. package/dist/prompt-assembly/catalog/engine.d.ts +263 -0
  438. package/dist/prompt-assembly/catalog/engine.js +30 -0
  439. package/dist/prompt-assembly/catalog/index.d.ts +1 -1
  440. package/dist/prompt-assembly/catalog/index.js +2 -2
  441. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +1 -1
  442. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +29 -0
  443. package/dist/prompt-assembly/epoch.js +6 -8
  444. package/dist/prompt-assembly/turn-snapshot.js +8 -9
  445. package/dist/stores/file/background-agent-store.js +5 -6
  446. package/dist/stores/file/checkpoint-store.d.ts +0 -4
  447. package/dist/stores/file/checkpoint-store.js +7 -3
  448. package/dist/stores/file/file-history-store.d.ts +8 -0
  449. package/dist/stores/file/file-history-store.js +72 -0
  450. package/dist/stores/file/fs-atomic.js +17 -12
  451. package/dist/stores/file/index.js +11 -5
  452. package/dist/stores/file/mailbox-store.js +13 -4
  453. package/dist/stores/file/permission-rule-store.js +14 -13
  454. package/dist/stores/file/shared-ledger.d.ts +4 -0
  455. package/dist/stores/file/shared-ledger.js +4 -0
  456. package/dist/stores/file/task-list-store.js +12 -3
  457. package/dist/stores/file/workflow-run-store.js +1 -0
  458. package/dist/tools/fs/bash-program-position.d.ts +4 -2
  459. package/dist/tools/fs/bash-program-position.js +1 -1
  460. package/dist/tools/fs/bash-readonly-classifier.js +1 -1
  461. package/dist/tools/fs/bound-open.d.ts +97 -0
  462. package/dist/tools/fs/bound-open.js +103 -0
  463. package/dist/tools/fs/containment-face.d.ts +2 -2
  464. package/dist/tools/fs/fs-pdf.d.ts +7 -1
  465. package/dist/tools/fs/fs-pdf.js +31 -23
  466. package/dist/tools/fs/fs-read.d.ts +24 -17
  467. package/dist/tools/fs/fs-read.js +84 -53
  468. package/dist/tools/fs/fs-shared.d.ts +14 -12
  469. package/dist/tools/fs/fs-shared.js +5 -4
  470. package/dist/tools/fs/fs-write.d.ts +2 -2
  471. package/dist/tools/fs/fs-write.js +20 -12
  472. package/dist/tools/fs/index.d.ts +4 -4
  473. package/dist/tools/fs/index.js +2 -2
  474. package/dist/tools/fs/notebook.d.ts +1 -1
  475. package/dist/tools/fs/pdf.d.ts +12 -3
  476. package/dist/tools/fs/pdf.js +22 -9
  477. package/dist/tools/fs/read-deny-home.d.ts +3 -2
  478. package/dist/tools/fs/read-deny-home.js +8 -11
  479. package/dist/tools/fs/safety.d.ts +3 -2
  480. package/dist/tools/fs/shell-read-check.js +10 -9
  481. package/dist/tools/monitor.d.ts +6 -5
  482. package/dist/tools/task-list.d.ts +16 -6
  483. package/dist/tools/task-list.js +4 -0
  484. package/dist/tools/web.d.ts +9 -1
  485. package/dist/tools/web.js +8 -3
  486. package/dist/tools/worktree.d.ts +7 -5
  487. package/dist/tools/worktree.js +4 -3
  488. package/package.json +4 -3
  489. package/test/export-surface.snapshot.json +93 -7
  490. package/wire-changes/core-stores-sql@7.68.0.json +39 -0
  491. package/wire-changes/core@7.68.0.json +4257 -0
  492. package/wire-changes/mods-kernel@7.68.0.json +129 -0
  493. package/wire-changes/primitives@7.68.0.json +253 -0
  494. package/wire-changes/wiki-gate@7.68.0.json +39 -0
  495. package/dist/core/runner/credential-origin-seat.d.ts +0 -2
  496. package/dist/core/runner/credential-origin-seat.js +0 -20
@@ -373,24 +373,6 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
373
373
  * default — its knob is the CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY env; sema takes config).
374
374
  */
375
375
  maxToolConcurrency?: number;
376
- /**
377
- * design/120 P2: in-stream tool execution (CC StreamingToolExecutor, admission narrowed).
378
- * When true, a concurrency-safe tool call whose arguments completed mid-stream (`toolcall_end`)
379
- * starts executing while the model is still streaming, instead of waiting for the full response.
380
- *
381
- * Default: OFF (undefined) — behavior is exactly the P1 partitioned batch pipeline.
382
- *
383
- * Setting this true is the HOST'S PROMISE that no `beforeToolCall` gate on this run can durably
384
- * suspend (mint a checkpoint + abort): in-stream calls still run the full prepare chain (defense
385
- * in depth — block/updatedInput work as normal), but a mid-stream durable suspend has no stable
386
- * leaf to hang its checkpoint on. The harness wires this only when no `tool_call` hook handler
387
- * is registered (snapshot per turn); registering a suspending handler mid-run after opting in is
388
- * a host contract violation (undefined behavior). Admission per call additionally requires:
389
- * `toolExecution !== "sequential"`, the tool's `executionMode !== "sequential"`, the source-order
390
- * barrier (once any call bounces to the batch pipeline, every later call bounces too — the CC
391
- * processQueue FIFO-break equivalent), and in-flight < `maxToolConcurrency`.
392
- */
393
- streamingToolExecution?: boolean;
394
376
  /**
395
377
  * Converts AgentMessage[] to LLM-compatible Message[] before each LLM call.
396
378
  *
@@ -20,6 +20,9 @@ export declare class StreamingImportValidator {
20
20
  private done;
21
21
  /** design/171 — see {@link ImportValidatorOptions.preserveActorAssertions}. */
22
22
  private readonly preserveActorAssertions;
23
+ /** #3468: each session's first allocation entry and every restatement, judged against each other in {@link finish}. */
24
+ private readonly allocations;
25
+ private readonly statements;
23
26
  constructor(options?: ImportValidatorOptions);
24
27
  /** Validate ONE entry, in oldest-first order. Throws `SessionError("invalid_session")` on the first violation
25
28
  * (duplicate id, or a parent/structural reference not stepped before this entry). */
@@ -1,8 +1,9 @@
1
- import { SessionError, normalizeAnnouncedListing, normalizeReminderMark, normalizeGitAnnouncement, normalizeSessionCheckout, normalizeWorkspaceState, normalizeCompactionStateCarrier, isValidThinkingLevelChange, isValidModelChange, isOptionalDisplayString, } from "../harness/types.js";
1
+ import { SessionError, normalizeAnnouncedListing, normalizeReminderMark, normalizeGitAnnouncement, normalizeSessionCheckout, normalizeSessionCheckoutStatement, normalizeWorkspaceState, normalizeCompactionStateCarrier, isValidThinkingLevelChange, isValidModelChange, isOptionalDisplayString, } from "../harness/types.js";
2
2
  import { leafIdAfterEntry } from "./storage-base.js";
3
3
  import { parseSessionTimestampMs } from "./timestamps.js";
4
4
  import { flattenableUserText, normalizeEngineSegments } from "../../core/untrusted-text.js";
5
5
  import { isRunOrigin } from "../../core/run-origin.js";
6
+ import { isUserRowOrigin } from "../../core/user-row-origin.js";
6
7
  import { readBundledAttachments } from "../../core/attachment-source.js";
7
8
  import { readStoredPromptEpoch } from "../../prompt-assembly/epoch.js";
8
9
  import { MAX_MINTED_TOOL_RESULT_REF_CHARS } from "../../core/tool-result-store.js";
@@ -14,6 +15,11 @@ const INVOKED_SKILL_NAME_MAX_CHARS = 1024;
14
15
  const PERSISTED_REF_MAX_CHARS = MAX_MINTED_TOOL_RESULT_REF_CHARS;
15
16
  const ACTIVE_TOOL_NAME_MAX_CHARS = 1024;
16
17
  const ACTIVE_TOOLS_MAX_ENTRIES = 1000;
18
+ function contradictsAllocation(statement, allocated) {
19
+ if (statement.kind === "none")
20
+ return true;
21
+ return statement.kind === "record" && JSON.stringify({ ...statement.record, released: undefined }) !== JSON.stringify(allocated);
22
+ }
17
23
  export class StreamingImportValidator {
18
24
  seen = new Set();
19
25
  parentOf = new Map();
@@ -21,6 +27,8 @@ export class StreamingImportValidator {
21
27
  runningLeaf = null;
22
28
  done = false;
23
29
  preserveActorAssertions;
30
+ allocations = new Map();
31
+ statements = [];
24
32
  constructor(options) {
25
33
  this.preserveActorAssertions = options?.preserveActorAssertions === true;
26
34
  }
@@ -83,9 +91,12 @@ export class StreamingImportValidator {
83
91
  }
84
92
  }
85
93
  else if (e.type === "session_checkout") {
86
- if (normalizeSessionCheckout(e) === undefined) {
94
+ const record = normalizeSessionCheckout(e);
95
+ if (record === undefined) {
87
96
  throw new SessionError("invalid_session", `session_checkout entry "${e.id}" is structurally invalid`);
88
97
  }
98
+ if (record.released !== true && !this.allocations.has(record.sessionId))
99
+ this.allocations.set(record.sessionId, record);
89
100
  }
90
101
  else if (e.type === "reminder_mark") {
91
102
  if (normalizeReminderMark(e) === undefined) {
@@ -133,6 +144,17 @@ export class StreamingImportValidator {
133
144
  if (restatedGit !== undefined && !normalizeGitAnnouncement(restatedGit)) {
134
145
  throw new SessionError("invalid_session", `compaction "${e.id}" carries a structurally invalid gitAnnouncement restatement`);
135
146
  }
147
+ const restatedWorkspace = e.details?.workspaceState;
148
+ if (restatedWorkspace !== undefined && !normalizeWorkspaceState(restatedWorkspace)) {
149
+ throw new SessionError("invalid_session", `compaction "${e.id}" carries a structurally invalid workspaceState restatement`);
150
+ }
151
+ const restatedCheckout = e.details?.sessionCheckout;
152
+ const statement = restatedCheckout === undefined ? undefined : normalizeSessionCheckoutStatement(restatedCheckout);
153
+ if (restatedCheckout !== undefined && !statement) {
154
+ throw new SessionError("invalid_session", `compaction "${e.id}" carries a structurally invalid sessionCheckout restatement`);
155
+ }
156
+ if (statement !== undefined)
157
+ this.statements.push({ compactionId: e.id, statement });
136
158
  const carrier = e.details;
137
159
  const shaped = normalizeCompactionStateCarrier(e.details);
138
160
  if (carrier?.thinkingLevel !== undefined && shaped.thinkingLevel === undefined) {
@@ -234,6 +256,12 @@ export class StreamingImportValidator {
234
256
  if (this.runningLeaf !== null && !this.seen.has(this.runningLeaf)) {
235
257
  throw new SessionError("invalid_session", `Resolved leaf "${this.runningLeaf}" is not present in the import log`);
236
258
  }
259
+ for (const { compactionId, statement } of this.statements) {
260
+ const allocated = this.allocations.get(statement.sessionId);
261
+ if (allocated !== undefined && contradictsAllocation(statement, allocated)) {
262
+ throw new SessionError("invalid_session", `compaction "${compactionId}" restates session "${statement.sessionId}"'s checkout as ${statement.kind === "none" ? "none" : "another record"} while the same log holds that session's allocation entry`);
263
+ }
264
+ }
237
265
  return { leafId: this.runningLeaf };
238
266
  }
239
267
  }
@@ -300,6 +328,10 @@ function normalizeEngineProvenanceStamp(message, preserveActorAssertions = false
300
328
  delete m.attachment;
301
329
  if (m.runOrigin !== undefined && !isRunOrigin(m.runOrigin))
302
330
  delete m.runOrigin;
331
+ if (m.origin !== undefined && !isUserRowOrigin(m.origin))
332
+ delete m.origin;
333
+ if (m.inputId !== undefined && !(m.origin === "human_input" && typeof m.inputId === "string" && m.inputId.length > 0))
334
+ delete m.inputId;
303
335
  if (m.engineMinted !== undefined && m.engineMinted !== true)
304
336
  delete m.engineMinted;
305
337
  if (m.provenance !== undefined && m.provenance !== "engine-note")
@@ -1,10 +1,46 @@
1
1
  import { SessionError, type SessionHead, type SessionLogMark, type SessionMetadata, type SessionPlacementRecord, type SessionRowExpectation, type SessionStorage, type SessionTreeEntry } from "../harness/types.js";
2
2
  import type { Session } from "../harness/types.js";
3
3
  export declare function createSessionId(): string;
4
- /** The {@link SessionMetadata.incarnation} cell for a write laying a row's metadata down — the bundled repos' ONE mint point.
5
- * `existing` = the row before the write (`undefined`: none). A new row gets a fresh random v4 token (no time, no host); an
6
- * existing row keeps exactly what it had, including nothing (no token is minted for an occupant that predates the cell). */
7
- export declare function incarnationCell(existing: Pick<SessionMetadata, "incarnation"> | undefined): Pick<SessionMetadata, "incarnation">;
4
+ /** The {@link SessionMetadata.incarnation} cell for a write laying a row's metadata down — the bundled repos' ONE mint point. `existing`
5
+ * = the row before the write (`undefined`: none). Four cells, `tokenless` deciding only the last:
6
+ * - no row (`undefined`): a random v4 (no time, no host) followed by the address-epoch mark `.2` ({@link fileHistoryScopeOf}) — call it with
7
+ * `undefined` only in the write that CREATES the row;
8
+ * - a row holding a token: exactly that token;
9
+ * - a row with no token, `tokenless` `"keep"` (the default): `{}` — the row stays an unknown occupant, nothing is backfilled;
10
+ * - a row with no token, `tokenless` `"mint"`: a random v4 WITHOUT the mark — a token outside the address epoch, so the row's file-history
11
+ * scope stays its bare id and the history recorded there is still read, restored and deleted.
12
+ *
13
+ * `"mint"` is for a host whose own occupant test needs every row to hold a token, giving one to a row that already holds engine state; it
14
+ * changes the row's occupant cell, never where its history lives. Any other `tokenless` is refused whatever the row
15
+ * (`config.invalid_argument`), never read as the default. */
16
+ export declare function incarnationCell(existing: Pick<SessionMetadata, "incarnation"> | undefined, tokenless?: "keep" | "mint"): Pick<SessionMetadata, "incarnation">;
17
+ /** Does `sessionId` end in a scope tail (`~`, 22 of `[A-Za-z0-9_-]`, any `!`s)? Then it has no bare history scope ({@link fileHistoryScopeOf} refuses it) and, as a
18
+ * string, reads as the shorter id's address ({@link readFileHistoryScope}): the one predicate behind both, for a host's census of its ids (KL-3996-a). */
19
+ export declare function sessionIdHasScopeTail(sessionId: string): boolean;
20
+ /**
21
+ * THE file-history scope of a session row `(sessionId, occupant)`, `occupant` being its {@link SessionMetadata.incarnation}. A token the
22
+ * mint point minted ({@link incarnationCell}: a v4 then `.2`, matched whole) names a row born at its address: `sessionId~` + 22
23
+ * base64url characters of the token's SHA-256 — two occupants of one id never share a scope, and the token never appears in it. Any
24
+ * other occupant (none, a token from before the mark, a host's own — {@link incarnationCell}'s `"mint"` gives a row without one) reads as the id, where its history has always been — unless the id
25
+ * itself ends like an address (`~` + 22 base64url characters; `!`s after it, one rule for the shape): its bare id could be another row's
26
+ * address, so the call is refused (`config.invalid_argument`) and nothing is read, written or deleted for it; the way out is a new id.
27
+ * No scope is ever two rows'. Every seat naming a history scope (record, boundary, restore, carry, cascade, a host's erase / sync) asks this.
28
+ *
29
+ * Grammar: `scope = sessionId | sessionId "~" tail`, `tail` exactly 22 of `[A-Za-z0-9_-]` ending the scope; an id may carry `~` `%` `_`, so a scope is read
30
+ * from its end ({@link readFileHistoryScope}). Engine-minted scopes are unambiguous; a pre-epoch bare scope of a tail-ended id is not (KL-3996-a; INTEGRATION-CORE).
31
+ */
32
+ export declare function fileHistoryScopeOf(sessionId: string, occupant: string | undefined): string;
33
+ /** {@link readFileHistoryScope}'s answer: the session id, and for an address its tail (a digest of the occupant's token, which cannot be read back). */
34
+ export interface FileHistoryScopeParts {
35
+ readonly sessionId: string;
36
+ readonly tail?: string;
37
+ }
38
+ /**
39
+ * The inverse of {@link fileHistoryScopeOf}: `{ sessionId, tail? }`, `undefined` for a string no scope is (empty, a tail with no id, a tail then `!`s). It CANNOT
40
+ * tell a tail-ended string meant as a bare id from an address and reads it as the shorter id's: the engine never mints one ({@link sessionIdHasScopeTail}); a host's
41
+ * pre-epoch stock is the host's census (KL-3996-a). A store enumerates a session id's scopes with it, never by prefix.
42
+ */
43
+ export declare function readFileHistoryScope(scope: string): FileHistoryScopeParts | undefined;
8
44
  /** The one decoding of a stored {@link SessionMetadata.incarnation} cell read back by a backend (header line, SQL column):
9
45
  * a non-empty string is the occupant token; a cell that is not there (`undefined`, or `null` = SQL NULL) is an unknown
10
46
  * occupant, silently; a cell that is there but is not a token (`""`, a non-string) is an unknown occupant too and `disclose`
@@ -13,6 +49,8 @@ export declare function readIncarnationCell(raw: unknown, disclose: (detail: str
13
49
  /** What a value that is not a name (a non-empty string) is, said by its shape — an empty string, or a non-string by its kind. A
14
50
  * disclosure of a bad cell or member says this, never the value (the value may be a secret and always reaches a log). */
15
51
  export declare function notANameShape(raw: unknown): string;
52
+ /** What an incarnation value must be to name an occupant: a non-empty string. Anything else names nobody. */
53
+ export declare function isOccupantToken(raw: unknown): raw is string;
16
54
  /**
17
55
  * THE reading of "do two readings of one session id's occupant cell (`SessionMetadata.incarnation`) name one occupant": each side is
18
56
  * decoded as {@link readIncarnationCell} decodes a stored cell — a non-empty string is the token, anything else (absent, `""`, a
@@ -3,14 +3,42 @@ import { StoredSession } from "./session.js";
3
3
  import { uuidv7 } from "./uuid.js";
4
4
  import { PRINCIPAL_NAME_SPELLING, principalNameFault, principalNameOf } from "../../core/principal-name.js";
5
5
  import { receiptRefusal } from "../../core/own-property-receipt.js";
6
- import { randomUUID } from "node:crypto";
6
+ import { createHash, randomUUID } from "node:crypto";
7
7
  export function createSessionId() {
8
8
  return uuidv7();
9
9
  }
10
- export function incarnationCell(existing) {
10
+ export function incarnationCell(existing, tokenless = "keep") {
11
+ if (tokenless !== "keep" && tokenless !== "mint") {
12
+ throw receiptRefusal(`incarnationCell: tokenless must be "keep" or "mint", got ${typeof tokenless === "string" ? "another string" : nonStringShape(tokenless)}`);
13
+ }
11
14
  if (existing === undefined)
12
- return { incarnation: randomUUID() };
13
- return existing.incarnation !== undefined ? { incarnation: existing.incarnation } : {};
15
+ return { incarnation: `${randomUUID()}${ADDRESS_EPOCH_MARK}` };
16
+ if (existing.incarnation !== undefined)
17
+ return { incarnation: existing.incarnation };
18
+ return tokenless === "mint" ? { incarnation: randomUUID() } : {};
19
+ }
20
+ const ADDRESS_EPOCH_MARK = ".2";
21
+ const ADDRESS_EPOCH_TOKEN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.2$/;
22
+ const ADDRESS_TAIL = /~[A-Za-z0-9_-]{22}!*$/;
23
+ export function sessionIdHasScopeTail(sessionId) {
24
+ return ADDRESS_TAIL.test(sessionId);
25
+ }
26
+ export function fileHistoryScopeOf(sessionId, occupant) {
27
+ if (occupant !== undefined && ADDRESS_EPOCH_TOKEN.test(occupant))
28
+ return `${sessionId}~${createHash("sha256").update(occupant).digest("base64url").slice(0, 22)}`;
29
+ if (sessionIdHasScopeTail(sessionId)) {
30
+ throw Object.assign(new Error(`fileHistoryScopeOf: session "${sessionId}" ends like a file-history address but its occupant was not minted in the address epoch — a caller-chosen id collides with the address epoch; re-id the session (its file history is not read, written or deleted)`), { code: "config.invalid_argument" });
31
+ }
32
+ return sessionId;
33
+ }
34
+ const ADDRESS_END = /~([A-Za-z0-9_-]{22})$/;
35
+ export function readFileHistoryScope(scope) {
36
+ if (scope === "")
37
+ return undefined;
38
+ const address = ADDRESS_END.exec(scope);
39
+ if (address !== null)
40
+ return address.index === 0 ? undefined : { sessionId: scope.slice(0, address.index), tail: address[1] };
41
+ return sessionIdHasScopeTail(scope) ? undefined : { sessionId: scope };
14
42
  }
15
43
  export function readIncarnationCell(raw, disclose) {
16
44
  if (isOccupantToken(raw))
@@ -23,7 +51,7 @@ export function readIncarnationCell(raw, disclose) {
23
51
  export function notANameShape(raw) {
24
52
  return raw === "" ? "an empty string" : nonStringShape(raw);
25
53
  }
26
- function isOccupantToken(raw) {
54
+ export function isOccupantToken(raw) {
27
55
  return typeof raw === "string" && raw !== "";
28
56
  }
29
57
  function nonStringShape(raw) {
@@ -1,6 +1,6 @@
1
1
  import type { ImageContent, TextContent } from "../llm/index.js";
2
2
  import type { AgentMessage } from "../loop/types.js";
3
- import type { AnnouncedListingSnapshot, AnnouncedListingSnapshotInput, GitAnnouncementState, Session, SessionCheckoutRecord, SessionContext, SessionMetadata, SessionStorage, SessionTreeEntry, WorkspaceState } from "../harness/types.js";
3
+ import type { AnnouncedListingSnapshot, AnnouncedListingSnapshotInput, GitAnnouncementState, Session, SessionCheckoutRecord, SessionCheckoutStatement, SessionContext, SessionMetadata, SessionStorage, SessionTreeEntry, WorkspaceState } from "../harness/types.js";
4
4
  import type { BuildContextOptions } from "../harness/types.js";
5
5
  import type { PromptEpochDescriptor, StoredPromptEpoch } from "../../prompt-assembly/epoch.js";
6
6
  /** Build model context from the active session branch and its latest state markers.
@@ -96,12 +96,13 @@ export declare class StoredSession<TMetadata extends SessionMetadata = SessionMe
96
96
  getReminderMark(): Promise<string | undefined>;
97
97
  /**
98
98
  * design/155: recover the workspace-state snapshot for the ACTIVE branch — the nearest
99
- * `workspace_state` entry walking back from the leaf (SNAPSHOT semantics: first hit wins; a CLEAR
100
- * snapshot — no cwd, no worktree — is a real hit that shadows older state). Malformed entries are
101
- * skipped (defense in depth behind the import door). Undefined ⇒ no snapshot VISIBLE on this
102
- * branch: a fresh session, a pre-155 session, or a bounded-tail backend whose load floor cut every
103
- * snapshot — all degrade to fresh defaults (the task root), the pre-155 behavior. Rewind gets the
104
- * correct semantics for free: the branch path ends at the cut, so the walk finds the state that
99
+ * carrier walking back from the leaf — a `workspace_state` entry or a compaction's `details.workspaceState` restatement
100
+ * (#3468: `appendCompaction` restates the snapshot it reads, so a bounded-tail floor that cut the entry still recovers it)
101
+ * (SNAPSHOT semantics: first hit wins; a CLEAR snapshot — no cwd, no worktree — is a real hit that shadows older state).
102
+ * Malformed carriers are skipped (defense in depth behind the import door), and a compaction with no restatement (written
103
+ * before it existed) is walked past. Undefined ⇒ no snapshot VISIBLE on this branch: a fresh session, a pre-155 session, or a
104
+ * bounded-tail backend whose load floor cut every carrier — all degrade to fresh defaults (the task root), the pre-155
105
+ * behavior. Rewind gets the correct semantics for free: the branch path ends at the cut, so the walk finds the state that
105
106
  * was current THEN.
106
107
  */
107
108
  getWorkspaceState(): Promise<WorkspaceState | undefined>;
@@ -142,6 +143,15 @@ export declare class StoredSession<TMetadata extends SessionMetadata = SessionMe
142
143
  * caller-side logic — these two are derived from this session's own branch, so the session computes
143
144
  * them itself and every caller of `appendCompaction` gets the carry for free. A caller-supplied
144
145
  * `details` still wins if it names the same keys (explicit intent beats the automatic restatement).
146
+ *
147
+ * #3468: the session's other standing facts ride the same carry — the workspace state (`workspaceState`, the snapshot
148
+ * {@link getWorkspaceState} reads now) and the session's checkout (`sessionCheckout`, {@link SessionCheckoutStatement}: what
149
+ * the record reader answers now — a store read that throws states nothing). The newest compaction is inside every bounded
150
+ * window, so a later wake reads both whatever the floor cut. Every restatement is read at the leaf the record then lands on (its
151
+ * expected leaf): a write landing meanwhile makes the append a conflict. The workspace state has a public writer and follows
152
+ * the rule above; the checkout has none but the engine's, so a
153
+ * caller that names `sessionCheckout` is refused (`invalid_entry`) and nothing is written. A non-object `details` is the
154
+ * caller's own shape and carries nothing.
145
155
  */
146
156
  appendCompaction(summary: string, firstKeptEntryId: string, tokensBefore: number, details?: unknown, fromHook?: boolean): Promise<string>;
147
157
  /** Append a non-LLM transcript marker for harness-specific state. */
@@ -165,9 +175,11 @@ export declare class StoredSession<TMetadata extends SessionMetadata = SessionMe
165
175
  export declare function gitFrameContextVisible(branch: SessionTreeEntry[], entryId: string): boolean;
166
176
  /** What reading a session's checkout answered: none minted by this session, the one it minted (with `released` when it was
167
177
  * released), or a log the reader cannot vouch for — NOT "none" (a checkout that cannot be read is one the session cannot use).
168
- * `none` carries `window` when the storage was loaded from a bounded window (F3, `SessionStorage.getFloorId`): no record in the
169
- * window, and one below `floor` is not ruled out. A consumer that would REMOVE something on "none" reads that as unreadable (the
170
- * orphan doors do); a leg's open and the release read it as none. */
178
+ * `none` carries `window` when the storage was loaded from a bounded window (F3, `SessionStorage.getFloorId`) and nothing in that
179
+ * window states this session's checkout (no compaction in it restates it — a log whose compactions predate the restatement):
180
+ * one below `floor` is not ruled out. A consumer that would REMOVE something on "none" reads that as unreadable (the orphan doors
181
+ * do); a leg's open and the release read it as none. `unreadable` carries the same `window` when only the floor makes it so (a
182
+ * release whose allocation may be below it); every consumer reads it as unreadable, with or without. */
171
183
  export type SessionCheckoutRead = {
172
184
  readonly kind: "none";
173
185
  readonly window?: {
@@ -179,14 +191,29 @@ export type SessionCheckoutRead = {
179
191
  } | {
180
192
  readonly kind: "unreadable";
181
193
  readonly detail: string;
194
+ readonly window?: {
195
+ readonly floor: string;
196
+ };
182
197
  };
183
198
  /**
184
- * design/1456 R1′ (#2292): THE reader of a session's checkout. Scans the whole log (`findEntries`, never the branch: a rewind
185
- * to before the allocation must not drop the tree) for `session_checkout` entries minted by THIS session (`sessionId`), so a
186
- * fork's copied entries — the parent's — are not its own. Never best-effort: a store read that throws, an own entry that is not
187
- * a structurally valid record, a second allocation, or a release that names another allocation answers `unreadable`.
199
+ * design/1456 R1′ (#2292): THE reader of a session's checkout. Scans the whole loaded log (`findEntries`, never the branch: a
200
+ * rewind to before the allocation must not drop the tree) for the copies of THIS session's (`sessionId`) checkout: its
201
+ * `session_checkout` entries and the compactions' restatements of it (#3468, {@link SessionCheckoutStatement}) — a fork's
202
+ * copied entries and restatements, the parent's, are not its own. The copies are one fact: every allocation they hold must be
203
+ * the same record, a release anywhere releases it. The newest compaction is inside every bounded window, and every entry below
204
+ * the floor was written before any compaction inside it, so a window cut in log order with a restatement reads what the whole log
205
+ * reads (a window cut along the branch alone does not load other branches: KNOWN-LIMITS KL-3468-b). Never
206
+ * best-effort: a store read that throws, an own entry or restatement that is not structurally valid, a restatement that says
207
+ * unreadable, two different allocations, or a release that names another allocation answers `unreadable`.
188
208
  */
189
209
  export declare function readSessionCheckout(session: Session, sessionId: string): Promise<SessionCheckoutRead>;
210
+ /** #3468: what a compaction restates of `sessionId`'s checkout — only a fact of the log later entries add to but never overturn: what the
211
+ * reader vouches for (no `window`: not the view's), and a `none` only where no declaration can follow (`closed`:
212
+ * {@link checkoutDeclarationClosed} as the compaction lands). Else nothing. */
213
+ export declare function sessionCheckoutStatementOf(read: SessionCheckoutRead, sessionId: string, closed: boolean): SessionCheckoutStatement | undefined;
214
+ /** THE judgment "this session can no longer declare a checkout" (`openSessionCheckout` refuses on it): a session that is no fork declares
215
+ * only at its birth — once its log holds a message or a compaction it has begun. `landing`: as it stands once a compaction lands. */
216
+ export declare function checkoutDeclarationClosed(storage: SessionStorage, metadata: Pick<SessionMetadata, "forkedFrom">, landing?: boolean): Promise<boolean>;
190
217
  /** Append a session checkout entry (the allocation, or its one release), shape-gated by {@link normalizeSessionCheckout} and
191
218
  * conditioned on a leaf like every typed append: `observedLeafId` (the leaf read BEFORE the caller judged the session had no
192
219
  * allocation — so a writer that appended since, another leg allocating at the same time, makes this append fail instead of
@@ -1,5 +1,5 @@
1
1
  import { asAgentMessage, createCompactionSummaryMessage, createCustomMessage, } from "../harness/messages.js";
2
- import { SessionError, isSyntheticApiErrorMessage, isValidModelChange, normalizeAnnouncedListing, normalizeCompactionStateCarrier, normalizeGitAnnouncement, normalizeReminderMark, normalizeSessionCheckout, normalizeWorkspaceState } from "../harness/types.js";
2
+ import { SessionError, isSyntheticApiErrorMessage, isValidModelChange, normalizeAnnouncedListing, normalizeCompactionStateCarrier, normalizeGitAnnouncement, normalizeReminderMark, normalizeSessionCheckout, normalizeSessionCheckoutStatement, normalizeWorkspaceState } from "../harness/types.js";
3
3
  import { readStoredPromptEpoch } from "../../prompt-assembly/epoch.js";
4
4
  import { budgetInvokedSkillsRetention, readElidedMessages, readRetainedInvokedSkills, readUnsummarizedMessages, renderInvokedSkillsRetention, } from "../compaction/utils.js";
5
5
  import { thrownText } from "../../core/thrown-value.js";
@@ -258,11 +258,12 @@ export class StoredSession {
258
258
  const branch = await this.getBranch();
259
259
  for (let i = branch.length - 1; i >= 0; i--) {
260
260
  const entry = branch[i];
261
- if (entry.type === "workspace_state") {
262
- const shaped = normalizeWorkspaceState(entry);
263
- if (shaped)
264
- return shaped;
265
- }
261
+ const carried = entry.type === "workspace_state" ? entry : entry.type === "compaction" ? entry.details?.workspaceState : undefined;
262
+ if (carried === undefined)
263
+ continue;
264
+ const shaped = normalizeWorkspaceState(carried);
265
+ if (shaped)
266
+ return shaped;
266
267
  }
267
268
  return undefined;
268
269
  }
@@ -302,6 +303,11 @@ export class StoredSession {
302
303
  return anchor ? readStoredPromptEpoch(anchor) : undefined;
303
304
  }
304
305
  async appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromHook) {
306
+ const callerObject = details === undefined || (typeof details === "object" && details !== null && !Array.isArray(details));
307
+ if (callerObject && details?.sessionCheckout !== undefined) {
308
+ throw new SessionError("invalid_entry", "appendCompaction: details.sessionCheckout is the engine's restatement of the session's checkout record; a caller does not write it");
309
+ }
310
+ const parentId = await this.storage.getLeafId();
305
311
  const carried = await (async () => {
306
312
  try {
307
313
  const ctx = buildSessionContext(await this.getBranch());
@@ -311,16 +317,28 @@ export class StoredSession {
311
317
  return undefined;
312
318
  }
313
319
  })();
320
+ const standing = {};
321
+ if (callerObject) {
322
+ standing.workspaceState = await this.getWorkspaceState().catch(() => undefined);
323
+ try {
324
+ const metadata = await this.storage.getMetadata();
325
+ const read = foldSessionCheckout(await sessionCheckoutCopiesOf(this.storage), metadata.id);
326
+ standing.sessionCheckout = sessionCheckoutStatementOf(read, metadata.id, await checkoutDeclarationClosed(this.storage, metadata, true));
327
+ }
328
+ catch {
329
+ }
330
+ }
314
331
  const definedOverrides = Object.fromEntries(Object.entries(details ?? {}).filter(([, v]) => v !== undefined));
315
- const mergedDetails = carried === undefined
332
+ const restated = { ...(carried ?? {}), ...(standing.workspaceState !== undefined ? { workspaceState: standing.workspaceState } : {}) };
333
+ const mergedDetails = !callerObject
316
334
  ? details
317
- : details === undefined || (typeof details === "object" && details !== null && !Array.isArray(details))
318
- ? { ...carried, ...definedOverrides }
319
- : details;
335
+ : details === undefined && Object.keys(restated).length === 0 && standing.sessionCheckout === undefined
336
+ ? undefined
337
+ : { ...restated, ...definedOverrides, ...(standing.sessionCheckout !== undefined ? { sessionCheckout: standing.sessionCheckout } : {}) };
320
338
  return this.appendTypedEntry({
321
339
  type: "compaction",
322
340
  id: await this.storage.createEntryId(),
323
- parentId: await this.storage.getLeafId(),
341
+ parentId,
324
342
  timestamp: new Date().toISOString(),
325
343
  summary,
326
344
  firstKeptEntryId,
@@ -397,18 +415,37 @@ export function gitFrameContextVisible(branch, entryId) {
397
415
  return keptIdx !== -1 && frameIdx >= keptIdx;
398
416
  }
399
417
  export async function readSessionCheckout(session, sessionId) {
400
- let entries;
401
- let floor;
418
+ let copies;
402
419
  try {
403
- const storage = session.getStorage();
404
- entries = await storage.findEntries("session_checkout");
405
- floor = storage.getFloorId?.() ?? null;
420
+ copies = await sessionCheckoutCopiesOf(session.getStorage());
406
421
  }
407
422
  catch (err) {
408
423
  return { kind: "unreadable", detail: `the session log could not be read (${thrownText(err)})` };
409
424
  }
425
+ return foldSessionCheckout(copies, sessionId);
426
+ }
427
+ async function sessionCheckoutCopiesOf(storage) {
428
+ const floor = storage.getFloorId?.() ?? null;
429
+ const entries = await storage.findEntries("session_checkout");
430
+ return { entries, compactions: await storage.findEntries("compaction"), floor };
431
+ }
432
+ function foldSessionCheckout({ entries, compactions, floor }, sessionId) {
410
433
  let allocation;
411
434
  const releases = [];
435
+ let stated = false;
436
+ const take = (record) => {
437
+ if (record.released === true) {
438
+ releases.push(record.allocationId);
439
+ return undefined;
440
+ }
441
+ if (allocation === undefined)
442
+ allocation = record;
443
+ else if (allocation.allocationId !== record.allocationId)
444
+ return { kind: "unreadable", detail: `the session holds two checkout allocations (${allocation.allocationId}, ${record.allocationId})` };
445
+ else if (JSON.stringify(allocation) !== JSON.stringify(record))
446
+ return { kind: "unreadable", detail: `the session's checkout allocation ${record.allocationId} is recorded two different ways` };
447
+ return undefined;
448
+ };
412
449
  for (const entry of entries) {
413
450
  const shaped = normalizeSessionCheckout(entry);
414
451
  if (shaped === undefined) {
@@ -419,18 +456,52 @@ export async function readSessionCheckout(session, sessionId) {
419
456
  }
420
457
  if (shaped.sessionId !== sessionId)
421
458
  continue;
422
- if (shaped.released === true)
423
- releases.push(shaped);
424
- else if (allocation !== undefined)
425
- return { kind: "unreadable", detail: `the session holds two checkout allocations (${allocation.allocationId}, ${shaped.allocationId})` };
426
- else
427
- allocation = shaped;
459
+ const refused = take(shaped);
460
+ if (refused !== undefined)
461
+ return refused;
462
+ }
463
+ for (const compaction of compactions) {
464
+ const carried = compaction.details?.sessionCheckout;
465
+ if (carried === undefined)
466
+ continue;
467
+ const statement = normalizeSessionCheckoutStatement(carried);
468
+ if (statement === undefined) {
469
+ const owner = carried?.sessionId;
470
+ if (typeof owner === "string" && owner !== sessionId)
471
+ continue;
472
+ return { kind: "unreadable", detail: `compaction "${compaction.id}" restates the session's checkout in a shape that is not valid` };
473
+ }
474
+ if (statement.sessionId !== sessionId)
475
+ continue;
476
+ stated = true;
477
+ if (statement.kind === "unreadable")
478
+ return { kind: "unreadable", detail: `compaction "${compaction.id}" restates the session's checkout record as unreadable` };
479
+ if (statement.kind === "record") {
480
+ const { released, ...held } = statement.record;
481
+ const refused = take(held) ?? (released === true ? take(statement.record) : undefined);
482
+ if (refused !== undefined)
483
+ return refused;
484
+ }
428
485
  }
486
+ const unvouched = floor !== null && !stated ? { window: { floor } } : {};
429
487
  if (allocation === undefined)
430
- return releases.length === 0 ? { kind: "none", ...(floor !== null ? { window: { floor } } : {}) } : { kind: "unreadable", detail: "the session holds a checkout release with no allocation" };
431
- if (releases.some((r) => r.allocationId !== allocation.allocationId))
488
+ return releases.length === 0 ? { kind: "none", ...unvouched } : { kind: "unreadable", detail: "the session holds a checkout release with no allocation", ...unvouched };
489
+ const held = allocation;
490
+ if (releases.some((id) => id !== held.allocationId))
432
491
  return { kind: "unreadable", detail: "a checkout release names another allocation" };
433
- return { kind: "record", record: releases.length > 0 ? { ...allocation, released: true } : allocation };
492
+ return { kind: "record", record: releases.length > 0 ? { ...held, released: true } : held };
493
+ }
494
+ export function sessionCheckoutStatementOf(read, sessionId, closed) {
495
+ if (read.kind === "record")
496
+ return { sessionId, kind: "record", record: read.record };
497
+ if (read.window !== undefined)
498
+ return undefined;
499
+ return read.kind === "unreadable" ? { sessionId, kind: "unreadable" } : closed ? { sessionId, kind: "none" } : undefined;
500
+ }
501
+ export async function checkoutDeclarationClosed(storage, metadata, landing = false) {
502
+ if (metadata.forkedFrom !== undefined)
503
+ return false;
504
+ return landing || (await storage.findEntries("message")).length > 0 || (await storage.findEntries("compaction")).length > 0;
434
505
  }
435
506
  export async function appendSessionCheckout(session, record, observedLeafId) {
436
507
  const shaped = normalizeSessionCheckout(record);