@sema-agent/core 7.57.0 → 7.59.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 (399) hide show
  1. package/CHANGELOG.md +1161 -0
  2. package/README.md +6 -4
  3. package/dist/agents/cc-peer-directory.js +8 -8
  4. package/dist/agents/child-model-seat.d.ts +4 -2
  5. package/dist/agents/child-model-seat.js +5 -3
  6. package/dist/agents/peer-directory.d.ts +9 -0
  7. package/dist/agents/peer-directory.js +6 -2
  8. package/dist/agents/send-message-tool.js +21 -12
  9. package/dist/agents/subagent-steps.js +2 -4
  10. package/dist/agents/subagent.js +33 -34
  11. package/dist/brain/anthropic.js +161 -45
  12. package/dist/brain/errors.d.ts +9 -3
  13. package/dist/brain/errors.js +7 -1
  14. package/dist/brain/failover.js +2 -1
  15. package/dist/brain/open-responses.js +3 -3
  16. package/dist/brain/openai.js +103 -53
  17. package/dist/brain/provider-dialect.d.ts +11 -0
  18. package/dist/brain/provider-dialect.js +5 -2
  19. package/dist/brain/reasoning-request.js +5 -4
  20. package/dist/brain/reasoning.d.ts +19 -0
  21. package/dist/brain/reasoning.js +17 -2
  22. package/dist/brain/request-route.d.ts +4 -1
  23. package/dist/brain/request-route.js +4 -1
  24. package/dist/brain/route-adjudicator.d.ts +84 -18
  25. package/dist/brain/route-adjudicator.js +89 -22
  26. package/dist/brain/route-conformance.js +1 -1
  27. package/dist/brain/stream-engine.js +84 -49
  28. package/dist/brain/stream-shared.d.ts +30 -0
  29. package/dist/brain/stream-shared.js +34 -1
  30. package/dist/brain/timeout.d.ts +62 -5
  31. package/dist/brain/timeout.js +93 -6
  32. package/dist/core/a2a.d.ts +2 -1
  33. package/dist/core/a2a.js +23 -10
  34. package/dist/core/account-row.d.ts +61 -0
  35. package/dist/core/account-row.js +51 -0
  36. package/dist/core/advisor-verdict.d.ts +2 -1
  37. package/dist/core/advisor-verdict.js +1 -1
  38. package/dist/core/allow-entry.d.ts +20 -7
  39. package/dist/core/allow-entry.js +18 -9
  40. package/dist/core/approval-object.d.ts +29 -15
  41. package/dist/core/approval-object.js +47 -19
  42. package/dist/core/ask-origin.d.ts +21 -2
  43. package/dist/core/ask-origin.js +5 -1
  44. package/dist/core/auto-compaction.d.ts +4 -0
  45. package/dist/core/auto-compaction.js +2 -2
  46. package/dist/core/auto-mode-directive.d.ts +29 -5
  47. package/dist/core/auto-mode-directive.js +38 -8
  48. package/dist/core/background-agent-store.d.ts +16 -3
  49. package/dist/core/checkpoint-requirements.d.ts +19 -1
  50. package/dist/core/checkpoint-requirements.js +5 -1
  51. package/dist/core/checkpoint-store.d.ts +85 -23
  52. package/dist/core/checkpoint-store.js +31 -9
  53. package/dist/core/child-clamp-seats.d.ts +29 -0
  54. package/dist/core/child-clamp-seats.js +56 -1
  55. package/dist/core/compliance.d.ts +2 -2
  56. package/dist/core/compliance.js +1 -1
  57. package/dist/core/effective-path-target.d.ts +8 -2
  58. package/dist/core/effective-path-target.js +8 -3
  59. package/dist/core/engine-notice.d.ts +99 -9
  60. package/dist/core/engine-notice.js +19 -5
  61. package/dist/core/fs-write-gate-policy.d.ts +4 -2
  62. package/dist/core/fs-write-gate-policy.js +7 -3
  63. package/dist/core/gate-fold.js +7 -4
  64. package/dist/core/gate-lanes.js +19 -6
  65. package/dist/core/gate-outcome.d.ts +32 -3
  66. package/dist/core/gate-outcome.js +19 -1
  67. package/dist/core/git-worktree-env.d.ts +53 -11
  68. package/dist/core/git-worktree-env.js +96 -12
  69. package/dist/core/governance-codes.d.ts +9 -1
  70. package/dist/core/governance-codes.js +13 -0
  71. package/dist/core/hooks.d.ts +35 -4
  72. package/dist/core/hooks.js +17 -11
  73. package/dist/core/human-input-projection.d.ts +1 -0
  74. package/dist/core/human-input-projection.js +3 -0
  75. package/dist/core/image-admission.d.ts +6 -5
  76. package/dist/core/image-admission.js +18 -14
  77. package/dist/core/locked-config.d.ts +20 -3
  78. package/dist/core/locked-config.js +40 -3
  79. package/dist/core/mailbox-store.d.ts +45 -1
  80. package/dist/core/mailbox-store.js +53 -9
  81. package/dist/core/mcp-call-meta.d.ts +66 -0
  82. package/dist/core/mcp-call-meta.js +103 -0
  83. package/dist/core/mcp-connection-pool.d.ts +3 -1
  84. package/dist/core/mcp-connection-pool.js +3 -1
  85. package/dist/core/mcp-failure.d.ts +117 -15
  86. package/dist/core/mcp-failure.js +71 -3
  87. package/dist/core/mcp-probe.d.ts +4 -0
  88. package/dist/core/mcp-probe.js +1 -1
  89. package/dist/core/mcp-server-link.d.ts +27 -3
  90. package/dist/core/mcp-server-link.js +25 -1
  91. package/dist/core/mcp-server-spec.d.ts +46 -18
  92. package/dist/core/mcp-server-spec.js +1 -18
  93. package/dist/core/mcp.d.ts +16 -20
  94. package/dist/core/mcp.js +112 -55
  95. package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
  96. package/dist/core/memory-engine/consolidation-driver.js +3 -3
  97. package/dist/core/memory-engine/consolidation.d.ts +4 -0
  98. package/dist/core/memory-engine/consolidation.js +1 -0
  99. package/dist/core/memory-engine/delegation-settlement.js +5 -12
  100. package/dist/core/memory-engine/distiller.js +2 -2
  101. package/dist/core/memory-engine/dual-root.d.ts +50 -1
  102. package/dist/core/memory-engine/dual-root.js +44 -1
  103. package/dist/core/memory-engine/engine.d.ts +67 -14
  104. package/dist/core/memory-engine/engine.js +384 -212
  105. package/dist/core/memory-engine/export-bundle.d.ts +23 -0
  106. package/dist/core/memory-engine/export-bundle.js +23 -4
  107. package/dist/core/memory-engine/file-backend.d.ts +128 -55
  108. package/dist/core/memory-engine/file-backend.js +290 -117
  109. package/dist/core/memory-engine/index.d.ts +1 -1
  110. package/dist/core/memory-engine/layout.d.ts +59 -11
  111. package/dist/core/memory-engine/layout.js +190 -40
  112. package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
  113. package/dist/core/memory-engine/memory-backend-contract.js +39 -2
  114. package/dist/core/memory-engine/scope-contract.d.ts +45 -4
  115. package/dist/core/memory-engine/scope-contract.js +80 -11
  116. package/dist/core/memory-engine/sync-client.d.ts +9 -1
  117. package/dist/core/memory-engine/sync-client.js +31 -8
  118. package/dist/core/memory-engine/sync.d.ts +5 -0
  119. package/dist/core/memory-engine/types.d.ts +6 -0
  120. package/dist/core/mode-policy.d.ts +8 -5
  121. package/dist/core/mode-policy.js +5 -4
  122. package/dist/core/mods/classic-events.d.ts +5 -1
  123. package/dist/core/mods/host.js +1 -1
  124. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  125. package/dist/core/mods/kernel/dispatch.js +12 -9
  126. package/dist/core/mods/kernel/events.d.ts +6 -1
  127. package/dist/core/mods/kernel/events.js +2 -2
  128. package/dist/core/mods/kernel/registration.d.ts +9 -1
  129. package/dist/core/mods/kernel/registration.js +3 -0
  130. package/dist/core/mods/kernel/site-rules.d.ts +3 -0
  131. package/dist/core/mods/kernel/site-rules.js +10 -0
  132. package/dist/core/mods/package.d.ts +23 -0
  133. package/dist/core/mods/package.js +118 -0
  134. package/dist/core/mods/stations.d.ts +33 -12
  135. package/dist/core/mods/stations.js +45 -11
  136. package/dist/core/mods/tool-call.d.ts +5 -1
  137. package/dist/core/mods/tool-call.js +13 -4
  138. package/dist/core/parent-spec-seat.d.ts +8 -3
  139. package/dist/core/parent-spec-seat.js +2 -0
  140. package/dist/core/park-selfcheck.js +6 -0
  141. package/dist/core/path-guard-rows.d.ts +20 -0
  142. package/dist/core/path-guard-rows.js +11 -0
  143. package/dist/core/peer-seat.d.ts +248 -0
  144. package/dist/core/peer-seat.js +439 -0
  145. package/dist/core/permission-rule-consent.js +10 -4
  146. package/dist/core/permission-rule-model.d.ts +16 -0
  147. package/dist/core/permission-rule-model.js +1 -1
  148. package/dist/core/present-plan-tool.d.ts +20 -3
  149. package/dist/core/present-plan-tool.js +48 -4
  150. package/dist/core/protocol-http-auth.d.ts +40 -29
  151. package/dist/core/protocol-http-auth.js +30 -32
  152. package/dist/core/redaction-marks.d.ts +16 -0
  153. package/dist/core/redaction-marks.js +16 -0
  154. package/dist/core/redaction-passes.js +8 -9
  155. package/dist/core/resume-startup-cause.js +1 -0
  156. package/dist/core/retention.d.ts +41 -15
  157. package/dist/core/retention.js +59 -12
  158. package/dist/core/rewrite-rejudge.d.ts +38 -0
  159. package/dist/core/rewrite-rejudge.js +42 -2
  160. package/dist/core/roles.d.ts +34 -2
  161. package/dist/core/roles.js +43 -4
  162. package/dist/core/run-origin.d.ts +40 -0
  163. package/dist/core/run-origin.js +37 -0
  164. package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
  165. package/dist/core/runner/advertised-writable-dirs.js +126 -0
  166. package/dist/core/runner/announce-once-ledger.d.ts +5 -4
  167. package/dist/core/runner/announce-once-ledger.js +4 -2
  168. package/dist/core/runner/call-hook-stations.js +2 -2
  169. package/dist/core/runner/compaction-restate.d.ts +15 -6
  170. package/dist/core/runner/compaction-restate.js +28 -2
  171. package/dist/core/runner/contracts.d.ts +33 -21
  172. package/dist/core/runner/credential-origin-seat.js +4 -3
  173. package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
  174. package/dist/core/runner/cwd-alignment-probe.js +21 -0
  175. package/dist/core/runner/decide-continuation.d.ts +2 -2
  176. package/dist/core/runner/gate-exit.d.ts +30 -8
  177. package/dist/core/runner/gate-exit.js +15 -8
  178. package/dist/core/runner/image-removed-seat.d.ts +12 -0
  179. package/dist/core/runner/image-removed-seat.js +19 -0
  180. package/dist/core/runner/inline-image.js +1 -1
  181. package/dist/core/runner/memory-consolidation-driver.js +3 -3
  182. package/dist/core/runner/park-commit.d.ts +1 -1
  183. package/dist/core/runner/park-commit.js +3 -0
  184. package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
  185. package/dist/core/runner/prepare-ask-lane.js +2 -1
  186. package/dist/core/runner/prepare-boundary-parks.js +2 -2
  187. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
  188. package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
  189. package/dist/core/runner/prepare-config-doors.d.ts +8 -5
  190. package/dist/core/runner/prepare-config-doors.js +14 -10
  191. package/dist/core/runner/prepare-context-lane.js +2 -0
  192. package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
  193. package/dist/core/runner/prepare-delegation-surface.js +16 -18
  194. package/dist/core/runner/prepare-gate-stations.js +1 -1
  195. package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
  196. package/dist/core/runner/prepare-hands-readface.js +9 -1
  197. package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
  198. package/dist/core/runner/prepare-inherited-gate.js +14 -27
  199. package/dist/core/runner/prepare-memory.d.ts +3 -0
  200. package/dist/core/runner/prepare-memory.js +26 -37
  201. package/dist/core/runner/prepare-park-ask.d.ts +1 -1
  202. package/dist/core/runner/prepare-park-ask.js +2 -1
  203. package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
  204. package/dist/core/runner/prepare-policy-chain.js +18 -15
  205. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  206. package/dist/core/runner/prepare-project-context.js +2 -2
  207. package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
  208. package/dist/core/runner/prepare-prompt-inputs.js +8 -19
  209. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
  210. package/dist/core/runner/prepare-protocol-tools.js +11 -3
  211. package/dist/core/runner/prepare-run-refs.d.ts +2 -3
  212. package/dist/core/runner/prepare-run-refs.js +4 -1
  213. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  214. package/dist/core/runner/prepare-suspend-saga.js +2 -1
  215. package/dist/core/runner/prepare-task.js +28 -13
  216. package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
  217. package/dist/core/runner/prepare-wiring-manifest.js +4 -3
  218. package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
  219. package/dist/core/runner/prepare-workspace-restore.js +4 -4
  220. package/dist/core/runner/reply-pricing.d.ts +30 -0
  221. package/dist/core/runner/reply-pricing.js +19 -0
  222. package/dist/core/runner/resume-admission.js +5 -3
  223. package/dist/core/runner/resume-apply.js +6 -1
  224. package/dist/core/runner/resume-checkpoint-screen.js +2 -0
  225. package/dist/core/runner/resume-policy-outcome.js +5 -5
  226. package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
  227. package/dist/core/runner/role-seat-defaulted.js +40 -0
  228. package/dist/core/runner/run-brain-sinks.js +2 -0
  229. package/dist/core/runner/run-harness-handlers.d.ts +3 -4
  230. package/dist/core/runner/run-harness-handlers.js +1 -8
  231. package/dist/core/runner/run-identity-wiring.d.ts +2 -5
  232. package/dist/core/runner/run-identity-wiring.js +6 -4
  233. package/dist/core/runner/run-leg.d.ts +2 -0
  234. package/dist/core/runner/run-leg.js +42 -29
  235. package/dist/core/runner/run-notification-lane.js +3 -0
  236. package/dist/core/runner/run-stop-and-final-verify.js +2 -2
  237. package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
  238. package/dist/core/runner/run-terminal-adoption.js +9 -3
  239. package/dist/core/runner/run-turn-boundary.js +77 -70
  240. package/dist/core/runner/runtask.d.ts +1 -1
  241. package/dist/core/runner/runtask.js +2 -2
  242. package/dist/core/runner/side-call-account.d.ts +1 -1
  243. package/dist/core/runner/side-call-account.js +3 -18
  244. package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
  245. package/dist/core/runner/sub-agent-deny-lists.js +10 -0
  246. package/dist/core/runner/terminal-account.js +3 -3
  247. package/dist/core/runner/tool-end-body.js +2 -1
  248. package/dist/core/runner/tool-occurrence.d.ts +5 -2
  249. package/dist/core/runner/tool-occurrence.js +4 -3
  250. package/dist/core/runner/turn-attachments.d.ts +26 -22
  251. package/dist/core/runner/turn-attachments.js +24 -26
  252. package/dist/core/runner/write-protection-station.d.ts +8 -2
  253. package/dist/core/runner/write-protection-station.js +2 -0
  254. package/dist/core/runner-deps.d.ts +3 -3
  255. package/dist/core/secret-env.d.ts +32 -2
  256. package/dist/core/secret-env.js +65 -3
  257. package/dist/core/sensitive-path-policy.js +9 -10
  258. package/dist/core/session-log-transfer.d.ts +24 -0
  259. package/dist/core/session-log-transfer.js +166 -0
  260. package/dist/core/session-policy-store.d.ts +3 -1
  261. package/dist/core/session-policy-store.js +13 -9
  262. package/dist/core/session-store.d.ts +86 -24
  263. package/dist/core/session-store.js +162 -24
  264. package/dist/core/session.d.ts +92 -1
  265. package/dist/core/shell-read-silence.js +1 -0
  266. package/dist/core/side-query.d.ts +11 -1
  267. package/dist/core/side-query.js +9 -0
  268. package/dist/core/skill-grant-binding.d.ts +31 -2
  269. package/dist/core/skill-grant-binding.js +31 -1
  270. package/dist/core/skill-grant.d.ts +8 -5
  271. package/dist/core/skill-grant.js +6 -6
  272. package/dist/core/steer-replay.d.ts +4 -2
  273. package/dist/core/steer-replay.js +2 -1
  274. package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
  275. package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
  276. package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
  277. package/dist/core/store-contracts/session-repo-contract.js +112 -5
  278. package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
  279. package/dist/core/store-contracts/session-store-contract.js +236 -2
  280. package/dist/core/synthetic-read-verdict.js +2 -1
  281. package/dist/core/task-event.d.ts +92 -8
  282. package/dist/core/task-notification.js +16 -10
  283. package/dist/core/task-registry-agent.js +1 -0
  284. package/dist/core/task-registry-shared.d.ts +7 -1
  285. package/dist/core/task-spec.d.ts +49 -1
  286. package/dist/core/task-stream.d.ts +2 -1
  287. package/dist/core/terminal-cause.d.ts +11 -1
  288. package/dist/core/tool-catalog-entries.js +1 -0
  289. package/dist/core/tool-check-reading.d.ts +1 -0
  290. package/dist/core/tool-check-reading.js +3 -3
  291. package/dist/core/tool-policy.d.ts +16 -0
  292. package/dist/core/tool-result-store.d.ts +17 -10
  293. package/dist/core/tool-result-store.js +3 -1
  294. package/dist/core/tool-roster.d.ts +112 -5
  295. package/dist/core/tool-roster.js +42 -1
  296. package/dist/core/tool-spec.d.ts +3 -1
  297. package/dist/core/types.d.ts +3 -3
  298. package/dist/core/types.js +1 -1
  299. package/dist/core/untrusted-egress.d.ts +0 -2
  300. package/dist/core/untrusted-egress.js +10 -14
  301. package/dist/core/user-attachment.js +1 -1
  302. package/dist/core/wiring-manifest.d.ts +18 -6
  303. package/dist/core/wiring-manifest.js +4 -3
  304. package/dist/core/workspace-snapshot.d.ts +44 -0
  305. package/dist/core/workspace-snapshot.js +34 -0
  306. package/dist/core/write-protect.d.ts +43 -3
  307. package/dist/core/write-protect.js +43 -16
  308. package/dist/engine/compaction/compaction.js +29 -3
  309. package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
  310. package/dist/engine/execution-env/node-execution-env.js +24 -23
  311. package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
  312. package/dist/engine/harness/agent-harness.d.ts +30 -2
  313. package/dist/engine/harness/agent-harness.js +43 -12
  314. package/dist/engine/harness/messages.d.ts +3 -1
  315. package/dist/engine/harness/messages.js +3 -2
  316. package/dist/engine/harness/types.d.ts +56 -7
  317. package/dist/engine/harness/types.js +5 -1
  318. package/dist/engine/llm/rejected-images.d.ts +46 -0
  319. package/dist/engine/llm/rejected-images.js +54 -0
  320. package/dist/engine/llm/tool-turns.d.ts +2 -1
  321. package/dist/engine/llm/types.d.ts +30 -10
  322. package/dist/engine/llm/types.js +1 -1
  323. package/dist/engine/loop/agent-loop.d.ts +8 -0
  324. package/dist/engine/loop/agent-loop.js +52 -15
  325. package/dist/engine/loop/types.d.ts +3 -1
  326. package/dist/engine/session/import-validate.js +3 -0
  327. package/dist/engine/session/memory-repo.d.ts +17 -9
  328. package/dist/engine/session/memory-repo.js +44 -34
  329. package/dist/engine/session/path-to-root.d.ts +38 -0
  330. package/dist/engine/session/path-to-root.js +39 -0
  331. package/dist/engine/session/repo-utils.d.ts +22 -4
  332. package/dist/engine/session/repo-utils.js +49 -1
  333. package/dist/engine/session/storage-base.d.ts +10 -1
  334. package/dist/engine/session/storage-base.js +11 -22
  335. package/dist/index.d.ts +29 -16
  336. package/dist/index.js +21 -11
  337. package/dist/internal/harness-types.d.ts +2 -2
  338. package/dist/internal/harness.d.ts +3 -2
  339. package/dist/internal/harness.js +2 -2
  340. package/dist/internal/llm.d.ts +1 -0
  341. package/dist/orchestration/workflow-observe.d.ts +17 -1
  342. package/dist/orchestration/workflow-observe.js +20 -0
  343. package/dist/orchestration/workflow-types.d.ts +32 -7
  344. package/dist/orchestration/workflow.js +739 -489
  345. package/dist/shell/counting-pass.d.ts +50 -0
  346. package/dist/shell/counting-pass.js +502 -0
  347. package/dist/shell/lex.d.ts +4 -2
  348. package/dist/shell/lex.js +93 -34
  349. package/dist/shell/shell-words.d.ts +1 -1
  350. package/dist/shell/shell-words.js +7 -6
  351. package/dist/stores/file/index.d.ts +4 -1
  352. package/dist/stores/file/index.js +4 -1
  353. package/dist/stores/file/mailbox-store.js +6 -10
  354. package/dist/stores/file/session-store.d.ts +15 -8
  355. package/dist/stores/file/session-store.js +28 -13
  356. package/dist/tools/fs/fs-bash.d.ts +6 -0
  357. package/dist/tools/fs/fs-bash.js +6 -3
  358. package/dist/tools/fs/fs-write.d.ts +6 -3
  359. package/dist/tools/fs/fs-write.js +8 -7
  360. package/dist/tools/fs/index.d.ts +3 -0
  361. package/dist/tools/fs/index.js +7 -3
  362. package/dist/tools/fs/program-read-model.d.ts +13 -0
  363. package/dist/tools/fs/program-read-model.js +15 -0
  364. package/dist/tools/fs/program-read-model.rows.js +1 -1
  365. package/dist/tools/fs/read-deny.d.ts +13 -10
  366. package/dist/tools/fs/read-deny.js +25 -5
  367. package/dist/tools/fs/read-floor.d.ts +19 -0
  368. package/dist/tools/fs/read-floor.js +23 -0
  369. package/dist/tools/fs/safety.js +40 -8
  370. package/dist/tools/fs/search.js +6 -24
  371. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  372. package/dist/tools/fs/shell-read-check.js +61 -16
  373. package/dist/tools/fs/shell-read-establish.js +2 -1
  374. package/dist/tools/fs/shell-read-identity.js +1 -1
  375. package/dist/tools/fs/shell-read-judge.d.ts +26 -9
  376. package/dist/tools/fs/shell-read-judge.js +10 -6
  377. package/dist/tools/fs/shell-read-plan.d.ts +6 -1
  378. package/dist/tools/fs/shell-read-plan.js +22 -15
  379. package/dist/tools/fs/shell-read-start.js +1 -0
  380. package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
  381. package/dist/tools/fs/shell-reentry-text.js +25 -3
  382. package/dist/tools/monitor.d.ts +4 -0
  383. package/dist/tools/monitor.js +2 -0
  384. package/dist/tools/worktree.d.ts +42 -15
  385. package/dist/tools/worktree.js +60 -32
  386. package/package.json +5 -2
  387. package/test/export-surface.snapshot.json +149 -1
  388. package/wire-changes/core-stores-sql@7.58.0.json +29 -0
  389. package/wire-changes/core-stores-sql@7.59.0.json +29 -0
  390. package/wire-changes/core@7.58.0.json +2188 -0
  391. package/wire-changes/core@7.59.0.json +2459 -0
  392. package/wire-changes/mods-kernel@7.58.0.json +81 -0
  393. package/wire-changes/mods-kernel@7.59.0.json +29 -0
  394. package/wire-changes/primitives@7.58.0.json +29 -0
  395. package/wire-changes/primitives@7.59.0.json +29 -0
  396. package/dist/primitives/credential-ref.d.ts +0 -89
  397. package/dist/primitives/credential-ref.js +0 -125
  398. package/dist/primitives/index.d.ts +0 -2
  399. package/dist/primitives/index.js +0 -1
@@ -1,9 +1,11 @@
1
1
  import type { ActorAssertion, AssistantMessage, ImageContent, Model, TextContent, UserMessage, UserMessageAttachment } from "../llm/index.js";
2
2
  import { type ToolTurnRepair } from "../llm/index.js";
3
+ import { type RejectedImageRemoval } from "../llm/rejected-images.js";
3
4
  import { runToolCall, type ExecutedToolCallOutcome } from "../loop/agent-loop.js";
4
5
  import type { HaltRemainingDirective } from "../loop/types.js";
5
6
  import type { AgentMessage, AgentTool, AgentToolCall, LoopMalformedToolUseRecovery, LoopThinkingOnlyRecovery, LoopTruncatedOutputRecovery, QueueMode, ThinkingLevel } from "../loop/types.js";
6
7
  import { type EngineSegment } from "../../core/untrusted-text.js";
8
+ import { type RunOrigin } from "../../core/run-origin.js";
7
9
  import type { CommittedFrameCarrier } from "../../core/frame-settlement.js";
8
10
  import type { AbortResult, AgentHarnessEvent, AgentHarnessEventResultMap, AgentHarnessOptions, AgentHarnessOwnEvent, AgentHarnessResources, AgentHarnessStreamOptions, ExecutionEnv, PromptTemplate, Skill } from "./types.js";
9
11
  /** [c209-C] 收口 C1/C2 — engine-provenance metadata a caller can stamp on the user message it
@@ -85,6 +87,10 @@ export interface UserMessageProvenance {
85
87
  * projection point `projectHumanInput`) BEFORE the frame wrapping — the harness never rewrites
86
88
  * text, so annotation stays adjacent to the frame it attributes. */
87
89
  actor?: ActorAssertion;
90
+ /** What brought the one input this message carries ({@link UserMessage.runOrigin}) — the caller passes it with a message
91
+ * that carries a single input only. Threaded onto the message when it is a member of the closed set; anything else is
92
+ * omitted at the mint. */
93
+ runOrigin?: RunOrigin;
88
94
  /** backlog #389 — an OPAQUE record the caller rides on a CALLER-AUTHORED queued frame so a durable
89
95
  * park can carry the instruction across the suspend instead of losing it. Same sidecar posture as
90
96
  * {@link UserMessageProvenance.enginePayload} (a WeakMap entry, never a message field, never
@@ -209,6 +215,13 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
209
215
  * with every request view that needed one (the transcript is never rewritten, so a broken turn is repaired, and
210
216
  * reported, on each request; the sink owns its dedup). Advisory: a throwing sink never breaks the request. */
211
217
  onToolTurnRepaired?: (repairs: readonly ToolTurnRepair[]) => void;
218
+ /** Runner-set sink for the images a provider refused in THIS run ({@link removeRejectedImages}) — a refusal recorded
219
+ * before the run began is not reported. Every request re-reads the transcript, so the sink owns its dedup (by
220
+ * `refusalAt`). Advisory: a throwing sink never breaks the request. */
221
+ onImagesRemoved?: (removals: readonly RejectedImageRemoval[]) => void;
222
+ /** The image refusals standing in the transcript when the current run began, by their identity
223
+ * ({@link RejectedImageRemoval.refusalAt}): the run that met them announced them. */
224
+ private priorImageRefusals?;
212
225
  /** The assistant messages standing in the transcript when the current run began — what the request view reads as
213
226
  * "before this run" (a message is the run's own unless it is in here). */
214
227
  private runHistory?;
@@ -217,10 +230,16 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
217
230
  * hands ENGINE payloads back for redelivery; user inputs have no redelivery semantics (a steer
218
231
  * aimed at a finished run must not silently fire at the next one), so their loss is ANNOUNCED
219
232
  * instead — the runner surfaces it as an operator notice, closing the "accepted then silently
220
- * dropped" window the #257 contract could only document. */
233
+ * dropped" window the #257 contract could only document. The second argument hands over the OPAQUE park records of the
234
+ * counted inputs that carried one, per lane in service order — the order the queue would serve them, so an
235
+ * `immediate`-class input leads the ones accepted before it (never interpreted here; the runner reads which input each
236
+ * is) — a lane's list shorter than its count means some counted input had none. */
221
237
  onUndrainedUserInputs?: (counts: {
222
238
  steer: number;
223
239
  followUp: number;
240
+ }, parkRecords?: {
241
+ steer: readonly unknown[];
242
+ followUp: readonly unknown[];
224
243
  }) => void;
225
244
  /** design/176 — runner-set sink fired at the CONSUMPTION boundary, once per engine-note payload,
226
245
  * in consumption order (steer/followUp drain and the turn-open nextTurn splice — the two points
@@ -257,6 +276,9 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
257
276
  * minted it. */
258
277
  engineInjectionsHeld?: () => boolean;
259
278
  /** The provider boundary's tool-turn law: the repaired view goes to the brain, the repairs to the runner's sink. */
279
+ /** The request view of `messages` under the provider's image refusals they hold ({@link removeRejectedImages}), and
280
+ * the removals this run met handed to {@link onImagesRemoved}. */
281
+ private imageRefusalView;
260
282
  private holdToolTurnLaw;
261
283
  /** RB-30 R2 belt-and-braces: runner-callable idempotent recovery for exit paths that reach
262
284
  * neither agent_end nor abort() (a pre-prompt throw after prepare). Swept entries are removed,
@@ -276,6 +298,7 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
276
298
  * frames are excluded, and the IN-FLIGHT slot counts (a frame spliced out of a queue and never injected
277
299
  * is as pending as one that never left it).
278
300
  */
301
+ private pendingUserInputFramesByLane;
279
302
  private pendingUserInputsByLane;
280
303
  /**
281
304
  * Is a PERSON's input waiting for this run's NEXT TURN BOUNDARY? The live read face over
@@ -632,11 +655,16 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
632
655
  * on a checkpoint, so their live frames leave the queues (identity-matched on the sidecar). Dropping
633
656
  * them here is what keeps the terminal `#259` account honest — a migrated instruction is not "accepted
634
657
  * then lost", and one this is never called for (a failed commit) still gets its loud undrained notice.
635
- * Returns the per-lane drop counts so the caller can subtract them from an account already taken.
658
+ * Returns the per-lane drop counts so the caller can subtract them from an account already taken, and the dropped
659
+ * records themselves per lane (opaque, in the order the queues held them) so it can subtract by identity too.
636
660
  */
637
661
  dropParkedUserInputs(records: readonly unknown[]): {
638
662
  steer: number;
639
663
  followUp: number;
664
+ records: {
665
+ steer: unknown[];
666
+ followUp: unknown[];
667
+ };
640
668
  };
641
669
  /**
642
670
  * backlog #389 (`control_request:"interrupt"`) — an interrupt does
@@ -1,8 +1,10 @@
1
1
  import { createAssistantMessageEventStream, ensureToolTurnInvariants, findToolByName, snapshotActorAssertion, stripEngineMetadata, userAttachmentOf } from "../llm/index.js";
2
+ import { imageRefusalAt, isImageRefusal, removeRejectedImages } from "../llm/rejected-images.js";
2
3
  import { finalizeToolOutcome, isBatchSafeToolCall, runAgentLoop, runToolCall } from "../loop/agent-loop.js";
3
4
  import { resolveAgentCoreStreamFn } from "../loop/runtime-deps.js";
4
5
  import { normalizeEngineSegments } from "../../core/untrusted-text.js";
5
6
  import { isCredentialHeaderName } from "../../core/secret-env.js";
7
+ import { isRunOrigin } from "../../core/run-origin.js";
6
8
  import { isProviderEchoShape } from "../../brain/errors.js";
7
9
  import { convertToLlm } from "./messages.js";
8
10
  import { readMember, thrownText } from "../../core/thrown-value.js";
@@ -37,6 +39,7 @@ function createUserMessage(text, images, provenance) {
37
39
  typeof provenance.actor.hostAsserted === "boolean"
38
40
  ? { actor: snapshotActorAssertion(provenance.actor) }
39
41
  : {}),
42
+ ...((runOrigin) => (isRunOrigin(runOrigin) ? { runOrigin } : {}))(provenance?.runOrigin),
40
43
  };
41
44
  }
42
45
  function createTrailingMessage(seed) {
@@ -222,12 +225,26 @@ export class AgentHarness {
222
225
  thinkingLevel;
223
226
  onUndrainedEngineNotes;
224
227
  onToolTurnRepaired;
228
+ onImagesRemoved;
229
+ priorImageRefusals;
225
230
  runHistory;
226
231
  onUndrainedUserInputs;
227
232
  onEngineNoteConsumed;
228
233
  onUserInputConsumed;
229
234
  onFrameCommitted;
230
235
  engineInjectionsHeld;
236
+ imageRefusalView(messages) {
237
+ const view = removeRejectedImages(messages);
238
+ const met = view.removals.filter((r) => this.priorImageRefusals?.has(r.refusalAt) !== true);
239
+ if (met.length > 0) {
240
+ try {
241
+ this.onImagesRemoved?.(met);
242
+ }
243
+ catch {
244
+ }
245
+ }
246
+ return view.messages;
247
+ }
231
248
  holdToolTurnLaw(messages) {
232
249
  const view = ensureToolTurnInvariants(messages, this.runHistory);
233
250
  if (view.repairs.length > 0) {
@@ -262,13 +279,17 @@ export class AgentHarness {
262
279
  }
263
280
  }
264
281
  }
265
- pendingUserInputsByLane() {
266
- const inFlight = (lane) => this.drainedPendingInjection.filter((m) => !engineAuthoredInjections.has(m) && drainedFromLane.get(m) === lane).length;
282
+ pendingUserInputFramesByLane() {
283
+ const inFlight = (lane) => this.drainedPendingInjection.filter((m) => !engineAuthoredInjections.has(m) && drainedFromLane.get(m) === lane);
267
284
  return {
268
- steer: this.steerQueue.filter((m) => !engineAuthoredInjections.has(m)).length + inFlight("steer"),
269
- followUp: this.followUpQueue.filter((m) => !engineAuthoredInjections.has(m)).length + inFlight("followUp"),
285
+ steer: [...inFlight("steer"), ...this.steerQueue.filter((m) => !engineAuthoredInjections.has(m))],
286
+ followUp: [...inFlight("followUp"), ...this.followUpQueue.filter((m) => !engineAuthoredInjections.has(m))],
270
287
  };
271
288
  }
289
+ pendingUserInputsByLane() {
290
+ const frames = this.pendingUserInputFramesByLane();
291
+ return { steer: frames.steer.length, followUp: frames.followUp.length };
292
+ }
272
293
  hasPendingUserInput() {
273
294
  if (this.aborting)
274
295
  return false;
@@ -278,7 +299,12 @@ export class AgentHarness {
278
299
  const counts = this.pendingUserInputsByLane();
279
300
  if ((counts.steer > 0 || counts.followUp > 0) && this.onUndrainedUserInputs) {
280
301
  try {
281
- this.onUndrainedUserInputs(counts);
302
+ const frames = this.pendingUserInputFramesByLane();
303
+ const records = (lane) => lane.flatMap((m) => {
304
+ const r = userInputParkRecords.get(m);
305
+ return r !== undefined ? [r] : [];
306
+ });
307
+ this.onUndrainedUserInputs(counts, { steer: records(frames.steer), followUp: records(frames.followUp) });
282
308
  }
283
309
  catch {
284
310
  }
@@ -669,17 +695,19 @@ export class AgentHarness {
669
695
  shouldStopAfterTurn: () => this.consultStopLatch("post_turn"),
670
696
  shouldHaltBeforeTurn: () => this.consultStopLatch("pre_turn"),
671
697
  transformContext: async (messages, signal) => {
672
- const result = await this.emitHook({ type: "context", messages: [...messages], ...(signal !== undefined ? { signal } : {}) });
698
+ const view = this.imageRefusalView(messages);
699
+ const result = await this.emitHook({ type: "context", messages: [...view], ...(signal !== undefined ? { signal } : {}) });
673
700
  if (result?.adoptSessionRebuild !== true) {
674
- return result?.messages ?? messages;
701
+ return result?.messages ?? view;
675
702
  }
676
703
  await this.flushPendingSessionWrites();
677
704
  const nextTurnState = await this.createTurnState();
678
705
  setTurnState(nextTurnState);
679
706
  const rebuiltContext = this.createContext(nextTurnState, runPromptOverride);
680
- const recheck = await this.emitHook({ type: "context", messages: [...rebuiltContext.messages], ...(signal !== undefined ? { signal } : {}), recheck: true });
707
+ const rebuiltView = this.imageRefusalView(rebuiltContext.messages);
708
+ const recheck = await this.emitHook({ type: "context", messages: [...rebuiltView], ...(signal !== undefined ? { signal } : {}), recheck: true });
681
709
  return {
682
- messages: recheck?.messages ?? rebuiltContext.messages,
710
+ messages: recheck?.messages ?? rebuiltView,
683
711
  adoptedContext: {
684
712
  messages: rebuiltContext.messages,
685
713
  systemPrompt: rebuiltContext.systemPrompt,
@@ -828,7 +856,7 @@ export class AgentHarness {
828
856
  usageMissing: true,
829
857
  stopReason: "error",
830
858
  ...(typeof errorMessage === "string" ? { errorMessage } : {}),
831
- ...(errorKind === "length_empty" || errorKind === "degenerate" || errorKind === "input_too_long" ? { errorKind } : {}),
859
+ ...(errorKind === "length_empty" || errorKind === "degenerate" || errorKind === "input_too_long" || errorKind === "image_unprocessable" ? { errorKind } : {}),
832
860
  timestamp: failure.timestamp,
833
861
  };
834
862
  try {
@@ -918,6 +946,7 @@ export class AgentHarness {
918
946
  this.promptReceipt = options?.onCommitted !== undefined ? { message: userMessage, commit: options.onCommitted } : undefined;
919
947
  const trailingMessages = (options?.trailing ?? []).map(createTrailingMessage);
920
948
  this.runHistory = new WeakSet(turnState.messages.filter((m) => m.role === "assistant"));
949
+ this.priorImageRefusals = new Set(turnState.messages.filter(isImageRefusal).map(imageRefusalAt));
921
950
  const beforeResult = await this.emitHook({
922
951
  type: "before_agent_start",
923
952
  prompt: text,
@@ -1428,7 +1457,7 @@ export class AgentHarness {
1428
1457
  return out;
1429
1458
  }
1430
1459
  dropParkedUserInputs(records) {
1431
- const dropped = { steer: 0, followUp: 0 };
1460
+ const dropped = { steer: 0, followUp: 0, records: { steer: [], followUp: [] } };
1432
1461
  if (records.length === 0)
1433
1462
  return dropped;
1434
1463
  const migrated = new Set(records);
@@ -1443,8 +1472,10 @@ export class AgentHarness {
1443
1472
  userInputParkRecords.delete(frame);
1444
1473
  q.splice(i, 1);
1445
1474
  i--;
1446
- if (lane !== undefined)
1475
+ if (lane !== undefined) {
1447
1476
  dropped[lane] += 1;
1477
+ dropped.records[lane].push(record);
1478
+ }
1448
1479
  }
1449
1480
  }
1450
1481
  return dropped;
@@ -26,5 +26,7 @@ export declare const NORMALIZED_CONTENT_PREFIX = "[invalid content block normali
26
26
  * `convertToLlm` (provider leg) and `serializeConversation` (compaction leg) — one helper, two mouths.
27
27
  */
28
28
  export declare function normalizeLlmMessageContent<T extends Message>(message: T): T;
29
- /** Convert harness transcript messages into the LLM-facing message sequence. */
29
+ /** Convert harness transcript messages into the LLM-facing message sequence. A provider's image refusal (live or its
30
+ * record) removes the images it refused ({@link removeRejectedImages}) for every leg — provider and compaction alike;
31
+ * the request leg applies it earlier, where its view starts, so there this pass is the identity. */
30
32
  export declare function convertToLlm(messages: AgentMessage[]): Message[];
@@ -1,4 +1,5 @@
1
1
  import { isSyntheticApiErrorMessage } from "./types.js";
2
+ import { removeRejectedImages } from "../llm/rejected-images.js";
2
3
  import { parseSessionTimestampMs, requireSessionTimestampMs } from "../session/timestamps.js";
3
4
  export function asAgentMessage(message) {
4
5
  return message;
@@ -107,8 +108,8 @@ export function normalizeLlmMessageContent(message) {
107
108
  return changed ? { ...message, content: blocks } : message;
108
109
  }
109
110
  export function convertToLlm(messages) {
110
- return messages
111
- .map((m) => {
111
+ return removeRejectedImages(messages)
112
+ .messages.map((m) => {
112
113
  const message = m;
113
114
  switch (message.role) {
114
115
  case "bashExecution":
@@ -340,12 +340,20 @@ export interface ExecutionEnvExecOptions {
340
340
  * behavior. Envs without detach support ignore this (opt-in, backward compatible).
341
341
  */
342
342
  autoBackgroundOnTimeout?: boolean;
343
+ /** VENDORED EDIT (the byte floor) — the read-deny table in force for the call starting this command ({@link ReadFloor}); what its processes OPEN is the environment's to keep. */
344
+ readFloor?: ReadFloor;
345
+ }
346
+ /** The read-deny table one command start carries ({@link ExecutionEnvExecOptions.readFloor}); what an environment keeps of it is INTEGRATION-CORE §11.1. */
347
+ export interface ReadFloor {
348
+ readonly rows: readonly string[];
349
+ /** The row denying an absolute path in this environment's namespace, or `null`: the read station's own judgment. Never throws. */
350
+ denies(absolutePath: string): string | null;
343
351
  }
344
352
  /**
345
353
  * Filesystem capability used by the harness.
346
354
  *
347
- * Paths passed to methods may be absolute or relative to {@link cwd}. Paths returned by file operations are addressed paths
348
- * in the filesystem namespace, but are not canonicalized through symlinks unless returned by {@link canonicalPath}.
355
+ * Paths passed to methods may be absolute or relative to {@link cwd}: an absolute path as written, a relative one ANCHORED at `cwd`; a `..` segment
356
+ * is the filesystem's to resolve (`bridge/../next`, `bridge` a symlink, is beside what it leads to), never folded lexically. Returned paths are addressed, not canonicalized unless from {@link canonicalPath}.
349
357
  *
350
358
  * Operation methods must never throw or reject. All filesystem failures, including unexpected backend failures, must be
351
359
  * encoded in the returned {@link Result}. Implementations must preserve this invariant.
@@ -353,9 +361,9 @@ export interface ExecutionEnvExecOptions {
353
361
  export interface FileSystem {
354
362
  /** Current working directory for relative paths. */
355
363
  cwd: string;
356
- /** Return an absolute addressed path without requiring it to exist and without resolving symlinks. */
364
+ /** An absolute addressed path, existence not required: ANCHOR ONLY (absolute as written, relative joined under {@link cwd}), no `..` folding, no symlink resolution; an environment with no working directory of its own answers an error. */
357
365
  absolutePath(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
358
- /** Join path segments in the filesystem namespace without requiring the result to exist. */
366
+ /** Join path segments in the filesystem namespace without requiring the result to exist, and without folding a `..`. */
359
367
  joinPath(parts: string[], abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
360
368
  /** Read a UTF-8 text file. */
361
369
  readTextFile(path: string, abortSignal?: AbortSignal): Promise<Result<string, FileError>>;
@@ -710,6 +718,10 @@ export interface ActiveWorktreeSession {
710
718
  originalCwd: string;
711
719
  baseSha: string;
712
720
  entered?: boolean;
721
+ /** The managed name (`.sema/worktrees/<name>`) the tree was CREATED under; absent for a tree entered by `path` or an older record. */
722
+ name?: string;
723
+ /** The branch the tree was CREATED on (`sema/<name>`), not refreshed when a shell switches branches; absent as `name` is (ExitWorktree then leaves every branch alone). */
724
+ branch?: string;
713
725
  }
714
726
  /**
715
727
  * REF-D3/D4 merge target: the session's WORKSPACE STATE container (nests {@link ActiveWorktreeSession}) —
@@ -942,6 +954,30 @@ export interface SessionHead {
942
954
  readonly incarnation: string | undefined;
943
955
  readonly leafId: string | null;
944
956
  }
957
+ /** Where a log stood when read: its entry count and last entry id (`null` = empty). Every append adds an id the log never held, so an
958
+ * appended log never shows the same mark again; a log replaced whole does only with as many entries ending on the same id. */
959
+ export interface SessionLogMark {
960
+ readonly length: number;
961
+ readonly lastEntryId: string | null;
962
+ }
963
+ /** What a conditional write of a session row expects of the row, judged by the repo INSIDE the write's own step (`sessionRowMatches`); a
964
+ * miss is refused `SessionError("conflict")` with nothing written, as the leaf CAS refuses a stale append. It is the row as a read of it
965
+ * answered: `row` = that read's owner and occupant cell (a {@link SessionHead} serves; `null` = no row), `log` (when the log binds) = the
966
+ * log's mark as read — a replacement judged against the log binds it, a deletion owed to the occupant does not. */
967
+ export interface SessionRowExpectation {
968
+ readonly row: {
969
+ readonly owner: string | null;
970
+ readonly incarnation: string | undefined;
971
+ } | null;
972
+ readonly log?: SessionLogMark;
973
+ }
974
+ /** One read of a row ({@link SessionRepo.readRow}): its metadata (placement included), its head and its whole log oldest-first, all of
975
+ * one row generation — the head is the one a write expecting this row names. */
976
+ export interface SessionRowRead<TMetadata extends SessionMetadata = SessionMetadata> {
977
+ readonly metadata: TMetadata;
978
+ readonly head: SessionHead;
979
+ readonly entries: SessionTreeEntry[];
980
+ }
945
981
  export interface JsonlSessionMetadata extends SessionMetadata {
946
982
  cwd: string;
947
983
  path: string;
@@ -1104,7 +1140,10 @@ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata
1104
1140
  /** Record activity on the row now: the time {@link list} answers as the row's `lastActiveAt` moves to now. A missing row is a no-op; a
1105
1141
  * fault rejects. Optional: a repo without it records only what its writes record. */
1106
1142
  touch?(sessionId: string): Promise<void>;
1107
- delete(metadata: TMetadata): Promise<void>;
1143
+ /** Remove the row and its whole log; an id with no row is a no-op. With `expect`, conditional: the repo judges the row against it in the
1144
+ * removal's own step and on a miss — no row, another generation, or (when the log binds) another log — removes nothing and refuses
1145
+ * `SessionError("conflict")` ({@link readRow}: which repos judge it). */
1146
+ delete(metadata: TMetadata, expect?: SessionRowExpectation): Promise<void>;
1108
1147
  /** A fork is a NEW row: `options.id` equal to the source's id is refused (`invalid_fork_target`) — onto its source it would mint a new occupant over the source's own transcript. */
1109
1148
  fork(source: TMetadata, options: SessionForkOptions & TCreateOptions): Promise<Session<TMetadata>>;
1110
1149
  /**
@@ -1116,10 +1155,19 @@ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata
1116
1155
  exportEntries?(sessionId: string): Promise<SessionTreeEntry[]>;
1117
1156
  /** The row's {@link SessionHead} in one read (`undefined` = no row); `TtlSessionStore` has a head read and an ownership pair only over a repo that has this. */
1118
1157
  headOf?(sessionId: string): Promise<SessionHead | undefined>;
1158
+ /** The row in one read — metadata, head and whole log (no compaction floor) of one generation; `undefined` = no row. A repo with this
1159
+ * judges every expectation its writes are handed; `TtlSessionStore` passes them, and has `delete` / `logTransfer`, only over such a repo. */
1160
+ readRow?(sessionId: string): Promise<SessionRowRead<TMetadata> | undefined>;
1119
1161
  /**
1120
1162
  * 2c session-sync: write a verbatim entry log (produced by {@link exportEntries} on another backend) into `sessionId` (the log is
1121
- * replaced, never the row: an existing row keeps its metadata whole; an absent id is a new row recording `owner`, `undefined` ⇒ `null` — the caller's principal, never the bundle's). The log MUST be passed through `validateEntriesForImport` first (the single fail-closed
1163
+ * replaced, never the row: an absent id is a new row recording `owner`, `undefined` ⇒ `null` — the caller's principal, never the bundle's;
1164
+ * an existing row keeps its metadata whole and takes the log only when it is already `owner`'s — compared null-safe — else the import is
1165
+ * refused `conflict`, and a placed row `placement_refused`, with nothing written; the owner check and the replacement are one step,
1166
+ * so a row another writer created after the caller looked is refused, never taken). The log MUST be passed through `validateEntriesForImport` first (the single fail-closed
1122
1167
  * invariant gate); a durable backend persists THAT function's output, it does not re-implement the checks.
1168
+ * With `options.expect`, the replacement is conditional on the row as the caller read it ({@link sessionRowMatches}, judged in the same
1169
+ * step as the owner check and the write): a miss writes nothing and is refused `SessionError("conflict")`. Answers the head of the row
1170
+ * the write committed (its owner and occupant, and the leaf the new log leaves it on), from that same step — never a later read.
1123
1171
  * Optional.
1124
1172
  *
1125
1173
  * design/171 §6.4 — `options.preserveActorAssertions` is the OPERATOR-level trusted-import
@@ -1131,7 +1179,8 @@ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata
1131
1179
  */
1132
1180
  importEntries?(sessionId: string, owner: string | undefined, entries: SessionTreeEntry[], options?: {
1133
1181
  preserveActorAssertions?: boolean;
1134
- }): Promise<void>;
1182
+ expect?: SessionRowExpectation;
1183
+ }): Promise<SessionHead>;
1135
1184
  }
1136
1185
  export interface JsonlSessionCreateOptions extends SessionCreateOptions {
1137
1186
  cwd: string;
@@ -128,7 +128,11 @@ export function normalizeWorkspaceState(value) {
128
128
  return undefined;
129
129
  if (w.entered !== undefined && typeof w.entered !== "boolean")
130
130
  return undefined;
131
- out.activeWorktree = { worktreeDir: w.worktreeDir, originalCwd: w.originalCwd, baseSha: w.baseSha, ...(w.entered === true ? { entered: true } : {}) };
131
+ if (w.name !== undefined && (typeof w.name !== "string" || !/^[A-Za-z0-9._/-]{1,64}$/.test(w.name)))
132
+ return undefined;
133
+ if (w.branch !== undefined && (typeof w.branch !== "string" || !/^sema\/[A-Za-z0-9._+-]{1,64}$/.test(w.branch)))
134
+ return undefined;
135
+ out.activeWorktree = { worktreeDir: w.worktreeDir, originalCwd: w.originalCwd, baseSha: w.baseSha, ...(w.entered === true ? { entered: true } : {}), ...(w.name !== undefined ? { name: w.name } : {}), ...(w.branch !== undefined ? { branch: w.branch } : {}) };
132
136
  }
133
137
  return out;
134
138
  }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The request view's reading of a provider's image refusal — restored on the way to the brain, never in the transcript.
3
+ *
4
+ * A turn the provider failed with `errorKind: "image_unprocessable"` (an image in the request could not be processed;
5
+ * classified at the brain boundary off the provider's envelope) is a MARKER, live in the loop's context and persisted
6
+ * as the transcript's API-failure record alike. Reading the messages in order, each marker:
7
+ * - replaces every image of the NEWEST earlier message that still carries one (a user message, a tool result, a
8
+ * custom message — never an assistant's) by a text block saying which image was removed and why;
9
+ * - leaves the view itself (a failure is not model output).
10
+ * An earlier marker has already emptied its carrier, so a second marker reaches the next older one: the request that
11
+ * failed loses one carrier's images per refusal, and a provider that names no position is still answered (the newest
12
+ * carrier is the one the failed request added last). Nothing else moves; messages without a marker before them are
13
+ * the same objects, and a view with no marker is the same array — the same transcript yields the same request bytes.
14
+ *
15
+ * The transcript keeps the images: a later reader of the session sees what was read, and every request built from it
16
+ * — the next turn, a resumed session, a compaction summary — reads the same record and removes the same images.
17
+ */
18
+ /** The `errorKind` a provider's image refusal carries (`AssistantMessage.errorKind`). */
19
+ export declare const IMAGE_REFUSAL_KIND = "image_unprocessable";
20
+ /** The text that stands in for the `ordinal`-th image (1-based) of a carrier the provider refused an image of. */
21
+ export declare function rejectedImagePlaceholder(ordinal: number): string;
22
+ /** Is this message a turn the provider failed because an image in the request could not be processed — the live
23
+ * failure or its persisted record? */
24
+ export declare function isImageRefusal(message: unknown): boolean;
25
+ /** One carrier whose images a marker removed: the marker, the carrier (both the view's input objects), how many, and
26
+ * the refusal's own time — the one identity a refusal keeps across its live failure, its persisted record and every
27
+ * rebuilt copy of either (the record is minted with the failure's timestamp). */
28
+ export interface RejectedImageRemoval {
29
+ readonly marker: object;
30
+ readonly carrier: object;
31
+ readonly images: number;
32
+ readonly refusalAt: number;
33
+ }
34
+ /** A refusal's identity ({@link RejectedImageRemoval.refusalAt}). */
35
+ export declare function imageRefusalAt(message: unknown): number;
36
+ /**
37
+ * The request view of `messages` under every image refusal they hold ({@link isImageRefusal}): each marker removed and
38
+ * the images of its carrier replaced. `removals` lists, in order, the carriers emptied — empty when no marker found
39
+ * an image to remove.
40
+ */
41
+ export declare function removeRejectedImages<T>(messages: readonly T[]): {
42
+ messages: T[];
43
+ removals: RejectedImageRemoval[];
44
+ };
45
+ /** Does `marker`, standing in `messages`, remove images in their request view — was there a carrier left for it? */
46
+ export declare function imageRefusalRemoves(messages: readonly unknown[], marker: object): boolean;
@@ -0,0 +1,54 @@
1
+ export const IMAGE_REFUSAL_KIND = "image_unprocessable";
2
+ export function rejectedImagePlaceholder(ordinal) {
3
+ return `[image ${ordinal} removed: rejected by provider: ${IMAGE_REFUSAL_KIND}]`;
4
+ }
5
+ export function isImageRefusal(message) {
6
+ const m = message;
7
+ return m?.role === "assistant" && m.isApiErrorMessage === true && m.errorKind === IMAGE_REFUSAL_KIND;
8
+ }
9
+ export function imageRefusalAt(message) {
10
+ const at = message?.timestamp;
11
+ return typeof at === "number" ? at : Number.NaN;
12
+ }
13
+ function imageCount(message) {
14
+ const m = message;
15
+ if (m === null || m === undefined || m.role === "assistant" || !Array.isArray(m.content))
16
+ return 0;
17
+ let n = 0;
18
+ for (const block of m.content)
19
+ if (block?.type === "image")
20
+ n++;
21
+ return n;
22
+ }
23
+ function withoutImages(message) {
24
+ let ordinal = 0;
25
+ const content = message.content.map((block) => block?.type === "image" ? { type: "text", text: rejectedImagePlaceholder(++ordinal) } : block);
26
+ return { ...message, content };
27
+ }
28
+ export function removeRejectedImages(messages) {
29
+ if (!messages.some(isImageRefusal))
30
+ return { messages: messages, removals: [] };
31
+ const out = [];
32
+ const carriers = [];
33
+ const removals = [];
34
+ for (const m of messages) {
35
+ if (!isImageRefusal(m)) {
36
+ out.push(m);
37
+ carriers.push(undefined);
38
+ continue;
39
+ }
40
+ for (let j = out.length - 1; j >= 0; j--) {
41
+ const images = imageCount(out[j]);
42
+ if (images === 0)
43
+ continue;
44
+ removals.push({ marker: m, carrier: (carriers[j] ?? out[j]), images, refusalAt: imageRefusalAt(m) });
45
+ carriers[j] = (carriers[j] ?? out[j]);
46
+ out[j] = withoutImages(out[j]);
47
+ break;
48
+ }
49
+ }
50
+ return { messages: out, removals };
51
+ }
52
+ export function imageRefusalRemoves(messages, marker) {
53
+ return removeRejectedImages(messages).removals.some((r) => r.marker === marker);
54
+ }
@@ -73,7 +73,8 @@ export type DropsTableCoversEveryForm = AssertAllKeysHandled<Exclude<ToolTurnRep
73
73
  * view of facts the model is already told in the turn itself. Closed:
74
74
  * · `truncated` — calls whose argument bytes were cut before they parsed: dropped, the model asked to re-issue them;
75
75
  * · `unnamed` — calls that arrived with no tool name: dropped the same way;
76
- * · `bad_frame` — provider stream frames that were not valid JSON: dropped, so the response may be missing content;
76
+ * · `bad_frame` — provider stream frames that were not valid JSON, or held members in no shape the stream defines:
77
+ * what could not be read was dropped, so the response may be missing content;
77
78
  * · `missing_result_synthesized` — a call with no recorded result, closed in the request view as interrupted with its
78
79
  * outcome unknown (the `missing_result` repair).
79
80
  * The first three are a brain's stream facts ({@link StreamDropCause}), stamped on the turn's own message; the fourth is
@@ -387,6 +387,15 @@ export interface UserMessage {
387
387
  * old-session-verbatim posture as the engine-provenance fields above.
388
388
  */
389
389
  actor?: ActorAssertion;
390
+ /**
391
+ * What brought the ONE input this message carries, when its host said so (`"scheduled"`: the deployment's scheduler handed
392
+ * it) — the objective's `TaskSpec.runOrigin`. A message that carries several inputs (a resumed leg's continuation: parked
393
+ * steers, a wake's message, an approver's words) carries none, exactly like {@link UserMessage.actor}; each input's word rides its
394
+ * `human_input` frame. Attribution metadata only: never sent to a provider ({@link stripEngineMetadata} strips it), never a
395
+ * decision input. The session-import gate keeps a member of the closed set and drops anything else. Absent = the host said
396
+ * nothing.
397
+ */
398
+ runOrigin?: import("../../core/run-origin.js").RunOrigin;
390
399
  /**
391
400
  * The DELIVERY RECORD of a user-attachment frame: this message is the engine-minted frame carrying one attachment
392
401
  * the user declared on the human message it follows, or one file a landed compaction re-read
@@ -592,8 +601,15 @@ export interface AssistantMessage {
592
601
  * twin). The loop's prompt-too-long recovery reads THIS seat first; the historic prose regex
593
602
  * over `errorMessage` remains as the fallback for brains that do not stamp it (additive — the
594
603
  * stamping obligation above extends to this member for cuts a Brain can classify structurally,
595
- * but unlike the two cut kinds there is no retired fallback: prose detection still works). */
596
- errorKind?: "length_empty" | "degenerate" | "input_too_long";
604
+ * but unlike the two cut kinds there is no retired fallback: prose detection still works).
605
+ *
606
+ * `"image_unprocessable"`: the provider refused the request because an image in it could not be processed
607
+ * (it does not decode, its type does not match its bytes, its pixels exceed the model's limit) — classified at the
608
+ * brain boundary off the provider's envelope (`brain/provider-dialect.ts`, `IMAGE_UNPROCESSABLE_RE`). Such a turn —
609
+ * live, or as the transcript's persisted record of it — is the request view's instruction to remove the images of
610
+ * the newest earlier message still carrying any (`engine/llm/rejected-images.ts`, at `convertToLlm`); the loop
611
+ * re-sends the turn without them. */
612
+ errorKind?: "length_empty" | "degenerate" | "input_too_long" | "image_unprocessable";
597
613
  /** The AUTHORITATIVE-NEGATIVE twin of `errorKind: "input_too_long"`: the brain's provenance-checked
598
614
  * classifier RAN and ruled this failure NOT input-too-long (wrong status family, or the provider's
599
615
  * own envelope states a different error). The loop's prompt-too-long recovery treats it as a hard
@@ -622,8 +638,9 @@ export interface AssistantMessage {
622
638
  * trailing call was already dropped by the finalize malformed path). Additive — absent everywhere else.
623
639
  */
624
640
  partialFinalized?: true;
625
- /** A stream-end word (`finish_reason`) outside the set the brain reads, in the echo shape (`?` past it): the turn
626
- * is kept, the Runner announces it (`route.finish_reason_unknown`), a completed run states it on `terminal.detail`. */
641
+ /** A stream-end word (`finish_reason`) outside the set the brain reads, in the echo shape (`?` past it, and `?` for an
642
+ * ending seat — `finish_reason` / `stop_reason` — that held no word at all): the turn is kept, the Runner announces it
643
+ * (`route.finish_reason_unknown`), a completed run states it on `terminal.detail`. */
627
644
  finishReasonUnknown?: string;
628
645
  /** Frames after the stream's first terminal statement (which decided this turn) that were not acted on — a later
629
646
  * ending (finish / stop reason), error or content — announced by the Runner (`route.stream_end_ignored`): the
@@ -667,10 +684,10 @@ export interface ToolResultMessage<TDetails = unknown> {
667
684
  export type Message = UserMessage | AssistantMessage | ToolResultMessage;
668
685
  /**
669
686
  * RB-3 (stage S4 carry): strip the engine-provenance metadata fields from user messages before
670
- * serializing a Context to an external wire. The seven fields (`enginePrefixChars`/`engineSegments`/
671
- * `engineMinted`/`provenance`/`actor`/`engineNoteKey`/`attachment`) are INTERNAL coordination between the engine's
687
+ * serializing a Context to an external wire. The eight fields (`enginePrefixChars`/`engineSegments`/
688
+ * `engineMinted`/`provenance`/`actor`/`engineNoteKey`/`attachment`/`runOrigin`) are INTERNAL coordination between the engine's
672
689
  * minting side and its consumers (permission classifier, compaction summarizer, prompt suggestions,
673
- * multiplayer attribution, attachment delivery) — they must never reach a provider payload. The built-in brains construct
690
+ * multiplayer attribution, attachment delivery, run attribution) — they must never reach a provider payload. The built-in brains construct
674
691
  * their own wire shapes and are immune; a CUSTOM Brain that whole-object-serializes messages
675
692
  * (`JSON.stringify(context.messages)`) would leak them — run the array through this projection first.
676
693
  */
@@ -1031,12 +1048,15 @@ export interface ImagesModel<TApi extends ImagesApi = ImagesApi> extends Omit<Mo
1031
1048
  /** The resolved credential a request would carry, tagged with its source (see {@link RouteCredentialSource}). */
1032
1049
  export interface RouteCredential {
1033
1050
  source: RouteCredentialSource;
1034
- /** The key itself, when the credential rides the apiKey knob. An EMPTY string is a present (per-call)
1035
- * credential that fails closed at emit time — presence, not truthiness (the degraded-secret contract). */
1051
+ /** The key the request carries in its lane's key header, when the credential rides the apiKey knob — never blank as
1052
+ * `resolveRouteCredential` resolves it. A BLANK key handed over (the empty string, or white space only —
1053
+ * `isBlankCredential`) is the keyless door: its source keeps its rank, so a lower source's credential never rides in
1054
+ * its place, and the resolved credential has no `apiKey` (`{ source: "per-model" }` carries nothing). */
1036
1055
  apiKey?: string;
1037
1056
  /** True when the credential rides (also) as credential HEADERS (`isCredentialHeaderName`: `authorization`,
1038
1057
  * `x-api-key`, `api-key`, a gateway's `Helicone-Auth`, …, any case) — alone, or beside the apiKey knob when one
1039
- * source sets both. The winning bag is named by {@link RouteCredential.carrierBag}. */
1058
+ * source sets both — and one of them holds a value that is not blank (a bag of blank credential headers keeps its
1059
+ * rank and rides nothing). The winning bag is named by {@link RouteCredential.carrierBag}. */
1040
1060
  headersBorne?: boolean;
1041
1061
  /** Which header bag carries a headers-borne credential (resolution precedence: options > model > config, one rank
1042
1062
  * per source; within the hook's answer (`options`) and within the deployment config (`config`) the knob and the
@@ -52,7 +52,7 @@ export function stripEngineMetadata(messages) {
52
52
  return messages.map((m) => {
53
53
  if (m.role !== "user")
54
54
  return m;
55
- const { enginePrefixChars: _a, engineSegments: _b, engineMinted: _c, provenance: _d, actor: _e, engineNoteKey: _f, attachment: _g, ...rest } = m;
55
+ const { enginePrefixChars: _a, engineSegments: _b, engineMinted: _c, provenance: _d, actor: _e, engineNoteKey: _f, attachment: _g, runOrigin: _h, ...rest } = m;
56
56
  return rest;
57
57
  });
58
58
  }
@@ -36,6 +36,8 @@ export type LoopContinueReason =
36
36
  | "follow_up_injected"
37
37
  /** ④b recovery: a prompt-too-long failure was recovered (compacted context) and retried in-turn. */
38
38
  | "reactive_compact_retry"
39
+ /** The provider refused an image; the request view removed it and the turn was re-sent in-turn. */
40
+ | "image_refusal_retry"
39
41
  /** ④b recovery: a `length`-stopped answer triggered a synthetic continue nudge for another turn. */
40
42
  | "max_output_tokens_recovery"
41
43
  /** S2 recovery (design/119): a `toolUse` stop with ZERO parseable tool calls got a retry nudge. */
@@ -172,11 +174,17 @@ export declare function isBatchSafeToolCall(tool: AgentTool | undefined, toolCal
172
174
  export type ExecutedToolCallOutcome = {
173
175
  result: AgentToolResult<unknown>;
174
176
  isError: boolean;
177
+ /** Present (`true`) exactly when the call's body never started: the run was aborted between the gate and the body, or the host's
178
+ * execution station ({@link AgentLoopConfig.executeTool}) settled the call without running it. Rides the end event as
179
+ * `notExecuted`, like {@link ImmediateToolCallOutcome.notExecuted}. */
180
+ notExecuted?: true;
175
181
  };
176
182
  type FinalizedToolCallOutcome = {
177
183
  toolCall: AgentToolCall;
178
184
  result: AgentToolResult<unknown>;
179
185
  isError: boolean;
186
+ /** The loop's own mark that the call settled without its body starting (see {@link ImmediateToolCallOutcome.notExecuted}); rides the end event. */
187
+ notExecuted?: true;
180
188
  };
181
189
  /**
182
190
  * THE reading a value gets on its way to becoming a call's arguments: the tool's own preparation (`prepareArguments` —