@namzu/sdk 43.0.0 → 44.1.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 (2112) hide show
  1. package/CHANGELOG.md +520 -0
  2. package/README.md +41 -34
  3. package/dist/advisory/budget.js +3 -3
  4. package/dist/advisory/budget.js.map +1 -1
  5. package/dist/advisory/context.d.ts +5 -5
  6. package/dist/advisory/context.d.ts.map +1 -1
  7. package/dist/advisory/context.js +6 -6
  8. package/dist/advisory/context.js.map +1 -1
  9. package/dist/advisory/evaluator.js +2 -2
  10. package/dist/advisory/evaluator.js.map +1 -1
  11. package/dist/advisory/parse.d.ts +1 -1
  12. package/dist/advisory/parse.js +1 -1
  13. package/dist/agents/AbstractAgent.d.ts +47 -40
  14. package/dist/agents/AbstractAgent.d.ts.map +1 -1
  15. package/dist/agents/AbstractAgent.js +60 -46
  16. package/dist/agents/AbstractAgent.js.map +1 -1
  17. package/dist/agents/PipelineAgent.d.ts +7 -7
  18. package/dist/agents/PipelineAgent.d.ts.map +1 -1
  19. package/dist/agents/PipelineAgent.js +75 -23
  20. package/dist/agents/PipelineAgent.js.map +1 -1
  21. package/dist/agents/ReactiveAgent.d.ts +7 -7
  22. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  23. package/dist/agents/ReactiveAgent.js +32 -25
  24. package/dist/agents/ReactiveAgent.js.map +1 -1
  25. package/dist/agents/RouterAgent.d.ts +7 -7
  26. package/dist/agents/RouterAgent.d.ts.map +1 -1
  27. package/dist/agents/RouterAgent.js +29 -32
  28. package/dist/agents/RouterAgent.js.map +1 -1
  29. package/dist/agents/SupervisorAgent.d.ts +13 -10
  30. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  31. package/dist/agents/SupervisorAgent.js +50 -36
  32. package/dist/agents/SupervisorAgent.js.map +1 -1
  33. package/dist/agents/budget.d.ts +17 -4
  34. package/dist/agents/budget.d.ts.map +1 -1
  35. package/dist/agents/budget.js +55 -14
  36. package/dist/agents/budget.js.map +1 -1
  37. package/dist/agents/defineAgent.d.ts +2 -2
  38. package/dist/agents/defineAgent.d.ts.map +1 -1
  39. package/dist/agents/defineAgent.js.map +1 -1
  40. package/dist/agents/handle.d.ts +12 -14
  41. package/dist/agents/handle.d.ts.map +1 -1
  42. package/dist/agents/handle.js +6 -6
  43. package/dist/agents/handle.js.map +1 -1
  44. package/dist/agents/lock.js +4 -4
  45. package/dist/agents/lock.js.map +1 -1
  46. package/dist/agents/runAgent.d.ts +42 -29
  47. package/dist/agents/runAgent.d.ts.map +1 -1
  48. package/dist/agents/runAgent.js +53 -14
  49. package/dist/agents/runAgent.js.map +1 -1
  50. package/dist/agents/storage.d.ts +21 -0
  51. package/dist/agents/storage.d.ts.map +1 -0
  52. package/dist/agents/storage.js +33 -0
  53. package/dist/agents/storage.js.map +1 -0
  54. package/dist/authorization/command-line.d.ts +1 -1
  55. package/dist/authorization/command-line.js +1 -1
  56. package/dist/authorization/gate.js +1 -1
  57. package/dist/authorization/gate.js.map +1 -1
  58. package/dist/authorization/permission-presets.d.ts +4 -4
  59. package/dist/authorization/permission-presets.d.ts.map +1 -1
  60. package/dist/authorization/permission-presets.js +2 -2
  61. package/dist/bridge/a2a/client.d.ts +1 -1
  62. package/dist/bridge/a2a/client.js +2 -2
  63. package/dist/bridge/a2a/client.js.map +1 -1
  64. package/dist/bridge/a2a/context.d.ts +26 -0
  65. package/dist/bridge/a2a/context.d.ts.map +1 -0
  66. package/dist/bridge/a2a/context.js +20 -0
  67. package/dist/bridge/a2a/context.js.map +1 -0
  68. package/dist/bridge/a2a/index.d.ts +4 -2
  69. package/dist/bridge/a2a/index.d.ts.map +1 -1
  70. package/dist/bridge/a2a/index.js +6 -2
  71. package/dist/bridge/a2a/index.js.map +1 -1
  72. package/dist/bridge/a2a/mapper.d.ts +12 -4
  73. package/dist/bridge/a2a/mapper.d.ts.map +1 -1
  74. package/dist/bridge/a2a/mapper.js +38 -31
  75. package/dist/bridge/a2a/mapper.js.map +1 -1
  76. package/dist/bridge/a2a/task.d.ts +39 -7
  77. package/dist/bridge/a2a/task.d.ts.map +1 -1
  78. package/dist/bridge/a2a/task.js +52 -31
  79. package/dist/bridge/a2a/task.js.map +1 -1
  80. package/dist/bridge/acp/permission.d.ts +2 -2
  81. package/dist/bridge/acp/server.d.ts +22 -8
  82. package/dist/bridge/acp/server.d.ts.map +1 -1
  83. package/dist/bridge/acp/server.js +18 -5
  84. package/dist/bridge/acp/server.js.map +1 -1
  85. package/dist/bridge/acp/update.d.ts +4 -4
  86. package/dist/bridge/acp/update.d.ts.map +1 -1
  87. package/dist/bridge/acp/update.js +6 -6
  88. package/dist/bridge/acp/update.js.map +1 -1
  89. package/dist/bridge/external-session.d.ts +43 -0
  90. package/dist/bridge/external-session.d.ts.map +1 -0
  91. package/dist/bridge/external-session.js +28 -0
  92. package/dist/bridge/external-session.js.map +1 -0
  93. package/dist/bridge/sse/index.d.ts +1 -1
  94. package/dist/bridge/sse/index.d.ts.map +1 -1
  95. package/dist/bridge/sse/index.js +1 -1
  96. package/dist/bridge/sse/index.js.map +1 -1
  97. package/dist/bridge/sse/mapper.d.ts +21 -13
  98. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  99. package/dist/bridge/sse/mapper.js +100 -129
  100. package/dist/bridge/sse/mapper.js.map +1 -1
  101. package/dist/bus/breaker.d.ts +6 -6
  102. package/dist/bus/breaker.d.ts.map +1 -1
  103. package/dist/bus/breaker.js +28 -27
  104. package/dist/bus/breaker.js.map +1 -1
  105. package/dist/bus/index.d.ts +2 -2
  106. package/dist/bus/index.d.ts.map +1 -1
  107. package/dist/bus/index.js +6 -6
  108. package/dist/bus/index.js.map +1 -1
  109. package/dist/bus/lock.d.ts +5 -5
  110. package/dist/bus/lock.d.ts.map +1 -1
  111. package/dist/bus/lock.js.map +1 -1
  112. package/dist/bus/ownership.d.ts +8 -8
  113. package/dist/bus/ownership.d.ts.map +1 -1
  114. package/dist/bus/ownership.js.map +1 -1
  115. package/dist/compaction/consolidation.d.ts +23 -11
  116. package/dist/compaction/consolidation.d.ts.map +1 -1
  117. package/dist/compaction/consolidation.js +43 -13
  118. package/dist/compaction/consolidation.js.map +1 -1
  119. package/dist/compaction/context-window.d.ts +4 -4
  120. package/dist/compaction/context-window.js +4 -4
  121. package/dist/compaction/index.d.ts +1 -1
  122. package/dist/compaction/index.d.ts.map +1 -1
  123. package/dist/compaction/index.js +2 -2
  124. package/dist/compaction/index.js.map +1 -1
  125. package/dist/compaction/manager.d.ts +4 -4
  126. package/dist/compaction/manager.js +4 -4
  127. package/dist/compaction/manual.d.ts +2 -2
  128. package/dist/compaction/manual.js +3 -3
  129. package/dist/compaction/manual.js.map +1 -1
  130. package/dist/compaction/plan.d.ts +5 -5
  131. package/dist/compaction/plan.js +4 -4
  132. package/dist/compaction/plan.js.map +1 -1
  133. package/dist/compaction/reducer.d.ts +8 -8
  134. package/dist/compaction/reducer.d.ts.map +1 -1
  135. package/dist/compaction/retention.js +2 -2
  136. package/dist/compaction/salience/bm25.d.ts +2 -2
  137. package/dist/compaction/salience/bm25.js +2 -2
  138. package/dist/compaction/salience/goal.d.ts +3 -3
  139. package/dist/compaction/salience/goal.js +3 -3
  140. package/dist/compaction/salience/minhash.d.ts +1 -1
  141. package/dist/compaction/salience/minhash.js +1 -1
  142. package/dist/compaction/salience/score.d.ts +2 -2
  143. package/dist/compaction/salience/score.js +3 -3
  144. package/dist/compaction/salience/score.js.map +1 -1
  145. package/dist/compaction/salience/tokenize.d.ts +1 -1
  146. package/dist/compaction/salience/tokenize.js +1 -1
  147. package/dist/compaction/verifier.d.ts +6 -6
  148. package/dist/compaction/verifier.js +5 -5
  149. package/dist/compaction/verifier.js.map +1 -1
  150. package/dist/compaction/wire.d.ts +1 -1
  151. package/dist/config/registry.d.ts +4 -4
  152. package/dist/config/registry.js +2 -2
  153. package/dist/config/runtime.d.ts +24 -24
  154. package/dist/config/runtime.js +3 -3
  155. package/dist/connector/http-operation.d.ts +1 -1
  156. package/dist/connector/http-operation.js +1 -1
  157. package/dist/connector/mcp/adapter.js +1 -1
  158. package/dist/connector/mcp/client.d.ts +1 -1
  159. package/dist/connector/mcp/client.js +1 -1
  160. package/dist/connector/mcp/discovery.d.ts +1 -1
  161. package/dist/connector/mcp/discovery.js +1 -1
  162. package/dist/connector/mcp/discovery.js.map +1 -1
  163. package/dist/connector/mcp/policy.d.ts +1 -1
  164. package/dist/connector/mcp/prompt-adapter.d.ts +1 -1
  165. package/dist/connector/mcp/prompt-adapter.js +3 -3
  166. package/dist/connector/mcp/prompt-adapter.js.map +1 -1
  167. package/dist/constants/a2a/index.d.ts +8 -2
  168. package/dist/constants/a2a/index.d.ts.map +1 -1
  169. package/dist/constants/a2a/index.js +9 -2
  170. package/dist/constants/a2a/index.js.map +1 -1
  171. package/dist/constants/continuation.d.ts +1 -1
  172. package/dist/constants/continuation.js +1 -1
  173. package/dist/constants/index.d.ts +0 -1
  174. package/dist/constants/index.d.ts.map +1 -1
  175. package/dist/constants/index.js +0 -1
  176. package/dist/constants/index.js.map +1 -1
  177. package/dist/constants/limits.d.ts +2 -2
  178. package/dist/constants/limits.js +2 -2
  179. package/dist/constants/telemetry/index.d.ts +9 -3
  180. package/dist/constants/telemetry/index.d.ts.map +1 -1
  181. package/dist/constants/telemetry/index.js +14 -12
  182. package/dist/constants/telemetry/index.js.map +1 -1
  183. package/dist/constants/tools/index.d.ts +2 -2
  184. package/dist/constants/tools/index.js +2 -2
  185. package/dist/contracts/a2a.d.ts +2 -2
  186. package/dist/contracts/api.d.ts +11 -126
  187. package/dist/contracts/api.d.ts.map +1 -1
  188. package/dist/contracts/index.d.ts +3 -2
  189. package/dist/contracts/index.d.ts.map +1 -1
  190. package/dist/contracts/index.js +7 -2
  191. package/dist/contracts/index.js.map +1 -1
  192. package/dist/contracts/schemas.d.ts +6 -165
  193. package/dist/contracts/schemas.d.ts.map +1 -1
  194. package/dist/contracts/schemas.js +6 -36
  195. package/dist/contracts/schemas.js.map +1 -1
  196. package/dist/contracts/session/api.d.ts +94 -0
  197. package/dist/contracts/session/api.d.ts.map +1 -0
  198. package/dist/contracts/session/api.js +10 -0
  199. package/dist/contracts/session/api.js.map +1 -0
  200. package/dist/contracts/session/index.d.ts +7 -0
  201. package/dist/contracts/session/index.d.ts.map +1 -0
  202. package/dist/contracts/session/index.js +7 -0
  203. package/dist/contracts/session/index.js.map +1 -0
  204. package/dist/contracts/session/schemas.d.ts +173 -0
  205. package/dist/contracts/session/schemas.d.ts.map +1 -0
  206. package/dist/contracts/session/schemas.js +52 -0
  207. package/dist/contracts/session/schemas.js.map +1 -0
  208. package/dist/contracts/session/turn-status.d.ts +45 -0
  209. package/dist/contracts/session/turn-status.d.ts.map +1 -0
  210. package/dist/contracts/session/turn-status.js +46 -0
  211. package/dist/contracts/session/turn-status.js.map +1 -0
  212. package/dist/contracts/session/turn.d.ts +64 -0
  213. package/dist/contracts/session/turn.d.ts.map +1 -0
  214. package/dist/contracts/session/turn.js +2 -0
  215. package/dist/contracts/session/turn.js.map +1 -0
  216. package/dist/directory/derive-supervisor.d.ts +1 -1
  217. package/dist/directory/derive-supervisor.js +2 -2
  218. package/dist/directory/derive-supervisor.js.map +1 -1
  219. package/dist/directory/derive.d.ts +2 -2
  220. package/dist/directory/derive.d.ts.map +1 -1
  221. package/dist/directory/derive.js +2 -2
  222. package/dist/directory/derive.js.map +1 -1
  223. package/dist/directory/index.d.ts +2 -2
  224. package/dist/directory/index.d.ts.map +1 -1
  225. package/dist/directory/index.js +1 -1
  226. package/dist/directory/index.js.map +1 -1
  227. package/dist/directory/load.js +2 -2
  228. package/dist/directory/load.js.map +1 -1
  229. package/dist/directory/types.d.ts +2 -2
  230. package/dist/directory/types.d.ts.map +1 -1
  231. package/dist/eval/experiment.d.ts +5 -5
  232. package/dist/eval/experiment.d.ts.map +1 -1
  233. package/dist/eval/experiment.js +18 -18
  234. package/dist/eval/experiment.js.map +1 -1
  235. package/dist/eval/from-turn.d.ts +30 -0
  236. package/dist/eval/from-turn.d.ts.map +1 -0
  237. package/dist/eval/from-turn.js +46 -0
  238. package/dist/eval/from-turn.js.map +1 -0
  239. package/dist/eval/harness-verification.js +7 -7
  240. package/dist/eval/harness-verification.js.map +1 -1
  241. package/dist/eval/index.d.ts +2 -2
  242. package/dist/eval/index.d.ts.map +1 -1
  243. package/dist/eval/index.js +1 -1
  244. package/dist/eval/index.js.map +1 -1
  245. package/dist/eval/judge.d.ts +3 -3
  246. package/dist/eval/judge.d.ts.map +1 -1
  247. package/dist/eval/judge.js +6 -6
  248. package/dist/eval/judge.js.map +1 -1
  249. package/dist/eval/scorers.d.ts +8 -8
  250. package/dist/eval/scorers.d.ts.map +1 -1
  251. package/dist/eval/scorers.js +21 -21
  252. package/dist/eval/scorers.js.map +1 -1
  253. package/dist/eval/types.d.ts +12 -12
  254. package/dist/eval/types.d.ts.map +1 -1
  255. package/dist/eval/uncertainty.d.ts +2 -2
  256. package/dist/eval/uncertainty.js +2 -2
  257. package/dist/execution/code-runtime/types.d.ts +4 -4
  258. package/dist/execution/code-runtime/types.js +2 -2
  259. package/dist/execution/code-runtime/worker.d.ts +1 -1
  260. package/dist/execution/code-runtime/worker.js +1 -1
  261. package/dist/invariants/index.d.ts +1 -1
  262. package/dist/manager/agent/child-session.d.ts +49 -0
  263. package/dist/manager/agent/child-session.d.ts.map +1 -0
  264. package/dist/manager/agent/child-session.js +94 -0
  265. package/dist/manager/agent/child-session.js.map +1 -0
  266. package/dist/manager/agent/lifecycle.d.ts +90 -13
  267. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  268. package/dist/manager/agent/lifecycle.js +332 -88
  269. package/dist/manager/agent/lifecycle.js.map +1 -1
  270. package/dist/manager/index.d.ts +1 -2
  271. package/dist/manager/index.d.ts.map +1 -1
  272. package/dist/manager/index.js +1 -2
  273. package/dist/manager/index.js.map +1 -1
  274. package/dist/manager/plan/lifecycle.d.ts +11 -7
  275. package/dist/manager/plan/lifecycle.d.ts.map +1 -1
  276. package/dist/manager/plan/lifecycle.js +12 -9
  277. package/dist/manager/plan/lifecycle.js.map +1 -1
  278. package/dist/manager/resident/consumption.d.ts +12 -6
  279. package/dist/manager/resident/consumption.d.ts.map +1 -1
  280. package/dist/manager/resident/consumption.js +7 -5
  281. package/dist/manager/resident/consumption.js.map +1 -1
  282. package/dist/manager/resident/evidence-recall.d.ts +5 -5
  283. package/dist/manager/resident/evidence-recall.d.ts.map +1 -1
  284. package/dist/manager/resident/evidence-recall.js +9 -9
  285. package/dist/manager/resident/evidence-recall.js.map +1 -1
  286. package/dist/manager/resident/host.d.ts +2 -2
  287. package/dist/manager/resident/host.d.ts.map +1 -1
  288. package/dist/manager/resident/host.js +1 -1
  289. package/dist/manager/resident/learning-cycle.d.ts +8 -4
  290. package/dist/manager/resident/learning-cycle.d.ts.map +1 -1
  291. package/dist/manager/resident/learning-cycle.js +4 -2
  292. package/dist/manager/resident/learning-cycle.js.map +1 -1
  293. package/dist/manager/resident/learning-observation.d.ts +12 -7
  294. package/dist/manager/resident/learning-observation.d.ts.map +1 -1
  295. package/dist/manager/resident/learning-observation.js +8 -4
  296. package/dist/manager/resident/learning-observation.js.map +1 -1
  297. package/dist/manager/resident/learning-store.d.ts +13 -0
  298. package/dist/manager/resident/learning-store.d.ts.map +1 -1
  299. package/dist/manager/resident/learning-store.js +35 -16
  300. package/dist/manager/resident/learning-store.js.map +1 -1
  301. package/dist/manager/resident/learning.d.ts +14 -14
  302. package/dist/manager/resident/outbox.d.ts +4 -4
  303. package/dist/manager/resident/store.d.ts +8 -8
  304. package/dist/manager/resident/tool-evidence.d.ts +15 -10
  305. package/dist/manager/resident/tool-evidence.d.ts.map +1 -1
  306. package/dist/manager/resident/tool-evidence.js +14 -14
  307. package/dist/manager/resident/tool-evidence.js.map +1 -1
  308. package/dist/manager/session/turn-recorder.d.ts +261 -0
  309. package/dist/manager/session/turn-recorder.d.ts.map +1 -0
  310. package/dist/manager/session/turn-recorder.js +1115 -0
  311. package/dist/manager/session/turn-recorder.js.map +1 -0
  312. package/dist/plugin/lifecycle.d.ts +4 -4
  313. package/dist/plugin/lifecycle.d.ts.map +1 -1
  314. package/dist/plugin/lifecycle.js +17 -10
  315. package/dist/plugin/lifecycle.js.map +1 -1
  316. package/dist/plugin/shell-hook.d.ts +35 -12
  317. package/dist/plugin/shell-hook.d.ts.map +1 -1
  318. package/dist/plugin/shell-hook.js +52 -20
  319. package/dist/plugin/shell-hook.js.map +1 -1
  320. package/dist/pricing/index.d.ts +4 -4
  321. package/dist/pricing/index.js +5 -5
  322. package/dist/pricing/index.js.map +1 -1
  323. package/dist/probe/context.d.ts +3 -2
  324. package/dist/probe/context.d.ts.map +1 -1
  325. package/dist/probe/context.js +2 -1
  326. package/dist/probe/context.js.map +1 -1
  327. package/dist/probe/registry.js +1 -1
  328. package/dist/probe/registry.js.map +1 -1
  329. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  330. package/dist/prompt/coding-agent-doctrine.js +1 -1
  331. package/dist/prompt/contributions.d.ts +27 -6
  332. package/dist/prompt/contributions.d.ts.map +1 -1
  333. package/dist/prompt/contributions.js +1 -1
  334. package/dist/prompt/contributions.js.map +1 -1
  335. package/dist/prompt/resident-learning.js +2 -2
  336. package/dist/prompt/resident-learning.js.map +1 -1
  337. package/dist/provider/collect-chat-completion.d.ts +2 -2
  338. package/dist/provider/collect-chat-completion.js +3 -3
  339. package/dist/provider/collect-chat-completion.js.map +1 -1
  340. package/dist/provider/conformance.d.ts +8 -1
  341. package/dist/provider/conformance.d.ts.map +1 -1
  342. package/dist/provider/conformance.js.map +1 -1
  343. package/dist/provider/errors.d.ts +1 -1
  344. package/dist/provider/errors.js +2 -2
  345. package/dist/provider/fallback.d.ts +4 -4
  346. package/dist/provider/fallback.js +6 -6
  347. package/dist/provider/fallback.js.map +1 -1
  348. package/dist/provider/idle-timeout.d.ts +2 -2
  349. package/dist/provider/idle-timeout.d.ts.map +1 -1
  350. package/dist/provider/idle-timeout.js +3 -3
  351. package/dist/provider/idle-timeout.js.map +1 -1
  352. package/dist/provider/instrumentation.d.ts +5 -2
  353. package/dist/provider/instrumentation.d.ts.map +1 -1
  354. package/dist/provider/instrumentation.js +9 -5
  355. package/dist/provider/instrumentation.js.map +1 -1
  356. package/dist/provider/mock.d.ts +1 -1
  357. package/dist/provider/mock.js +1 -1
  358. package/dist/provider/retry.d.ts +2 -2
  359. package/dist/provider/retry.js +6 -6
  360. package/dist/provider/retry.js.map +1 -1
  361. package/dist/provider/stream-text.d.ts +1 -1
  362. package/dist/provider/stream-text.d.ts.map +1 -1
  363. package/dist/provider/stream-text.js +1 -1
  364. package/dist/provider/stream-text.js.map +1 -1
  365. package/dist/provider/thinking-support.js +2 -2
  366. package/dist/provider/thinking-support.js.map +1 -1
  367. package/dist/provider/token-budget.d.ts +2 -2
  368. package/dist/provider/token-budget.d.ts.map +1 -1
  369. package/dist/provider/token-budget.js.map +1 -1
  370. package/dist/public-runtime.d.ts +69 -55
  371. package/dist/public-runtime.d.ts.map +1 -1
  372. package/dist/public-runtime.js +104 -99
  373. package/dist/public-runtime.js.map +1 -1
  374. package/dist/public-tools.d.ts +2 -2
  375. package/dist/public-tools.d.ts.map +1 -1
  376. package/dist/public-tools.js +7 -7
  377. package/dist/public-tools.js.map +1 -1
  378. package/dist/public-types.d.ts +18 -16
  379. package/dist/public-types.d.ts.map +1 -1
  380. package/dist/rag/embedding.js +1 -1
  381. package/dist/rag/embedding.js.map +1 -1
  382. package/dist/read-model/index.d.ts +2 -2
  383. package/dist/read-model/index.d.ts.map +1 -1
  384. package/dist/read-model/index.js +1 -1
  385. package/dist/read-model/index.js.map +1 -1
  386. package/dist/read-model/registry.d.ts +11 -11
  387. package/dist/read-model/registry.d.ts.map +1 -1
  388. package/dist/read-model/registry.js +2 -2
  389. package/dist/read-model/registry.js.map +1 -1
  390. package/dist/read-model/session-status.d.ts +34 -0
  391. package/dist/read-model/session-status.d.ts.map +1 -0
  392. package/dist/read-model/session-status.js +58 -0
  393. package/dist/read-model/session-status.js.map +1 -0
  394. package/dist/registry/command/kernel-commands.d.ts +4 -4
  395. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  396. package/dist/registry/command/kernel-commands.js +6 -6
  397. package/dist/registry/command/kernel-commands.js.map +1 -1
  398. package/dist/registry/tool/dialect.js +1 -1
  399. package/dist/registry/tool/execute.d.ts +2 -2
  400. package/dist/registry/tool/execute.d.ts.map +1 -1
  401. package/dist/registry/tool/execute.js +19 -7
  402. package/dist/registry/tool/execute.js.map +1 -1
  403. package/dist/registry/tool/portable.d.ts +1 -1
  404. package/dist/registry/tool/portable.js +1 -1
  405. package/dist/registry/tool/presentation.d.ts +1 -1
  406. package/dist/registry/tool/presentation.js +1 -1
  407. package/dist/registry/tool/schema.js +1 -1
  408. package/dist/registry/tool/screen.js +3 -3
  409. package/dist/registry/tool/screen.js.map +1 -1
  410. package/dist/runtime/bidi/index.d.ts +2 -2
  411. package/dist/runtime/bidi/index.d.ts.map +1 -1
  412. package/dist/runtime/bidi/index.js +1 -1
  413. package/dist/runtime/bidi/index.js.map +1 -1
  414. package/dist/runtime/bidi/session.d.ts +14 -11
  415. package/dist/runtime/bidi/session.d.ts.map +1 -1
  416. package/dist/runtime/bidi/session.js +27 -21
  417. package/dist/runtime/bidi/session.js.map +1 -1
  418. package/dist/runtime/jobs/awaited-jobs.d.ts +15 -15
  419. package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -1
  420. package/dist/runtime/jobs/awaited-jobs.js +13 -13
  421. package/dist/runtime/jobs/awaited-jobs.js.map +1 -1
  422. package/dist/runtime/jobs/registry.d.ts +10 -10
  423. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  424. package/dist/runtime/jobs/registry.js +5 -5
  425. package/dist/runtime/jobs/registry.js.map +1 -1
  426. package/dist/runtime/query/abandon-turn.d.ts +35 -0
  427. package/dist/runtime/query/abandon-turn.d.ts.map +1 -0
  428. package/dist/runtime/query/abandon-turn.js +81 -0
  429. package/dist/runtime/query/abandon-turn.js.map +1 -0
  430. package/dist/runtime/query/approval-policy.d.ts +10 -10
  431. package/dist/runtime/query/approval-policy.d.ts.map +1 -1
  432. package/dist/runtime/query/approval-policy.js +5 -5
  433. package/dist/runtime/query/approval-policy.js.map +1 -1
  434. package/dist/runtime/query/callback-inference.d.ts +1 -1
  435. package/dist/runtime/query/callback-inference.d.ts.map +1 -1
  436. package/dist/runtime/query/callback-inference.js +4 -4
  437. package/dist/runtime/query/callback-inference.js.map +1 -1
  438. package/dist/runtime/query/cancelled-before-start.d.ts +20 -20
  439. package/dist/runtime/query/cancelled-before-start.d.ts.map +1 -1
  440. package/dist/runtime/query/cancelled-before-start.js +72 -55
  441. package/dist/runtime/query/cancelled-before-start.js.map +1 -1
  442. package/dist/runtime/query/checkpoint.d.ts +153 -220
  443. package/dist/runtime/query/checkpoint.d.ts.map +1 -1
  444. package/dist/runtime/query/checkpoint.js +399 -370
  445. package/dist/runtime/query/checkpoint.js.map +1 -1
  446. package/dist/runtime/query/compact-session.d.ts +20 -0
  447. package/dist/runtime/query/compact-session.d.ts.map +1 -0
  448. package/dist/runtime/query/compact-session.js +81 -0
  449. package/dist/runtime/query/compact-session.js.map +1 -0
  450. package/dist/runtime/query/context.d.ts +42 -85
  451. package/dist/runtime/query/context.d.ts.map +1 -1
  452. package/dist/runtime/query/context.js +36 -75
  453. package/dist/runtime/query/context.js.map +1 -1
  454. package/dist/runtime/query/events.d.ts +54 -26
  455. package/dist/runtime/query/events.d.ts.map +1 -1
  456. package/dist/runtime/query/events.js +122 -114
  457. package/dist/runtime/query/events.js.map +1 -1
  458. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  459. package/dist/runtime/query/executor/tool-call-admission.js +6 -5
  460. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  461. package/dist/runtime/query/executor.d.ts +56 -34
  462. package/dist/runtime/query/executor.d.ts.map +1 -1
  463. package/dist/runtime/query/executor.js +165 -85
  464. package/dist/runtime/query/executor.js.map +1 -1
  465. package/dist/runtime/query/file-evidence-seed.d.ts +1 -1
  466. package/dist/runtime/query/file-evidence-seed.d.ts.map +1 -1
  467. package/dist/runtime/query/file-evidence-seed.js +1 -1
  468. package/dist/runtime/query/finalize-turn.d.ts +55 -0
  469. package/dist/runtime/query/finalize-turn.d.ts.map +1 -0
  470. package/dist/runtime/query/finalize-turn.js +129 -0
  471. package/dist/runtime/query/finalize-turn.js.map +1 -0
  472. package/dist/runtime/query/fork/list.d.ts +15 -0
  473. package/dist/runtime/query/fork/list.d.ts.map +1 -0
  474. package/dist/runtime/query/fork/list.js +11 -0
  475. package/dist/runtime/query/fork/list.js.map +1 -0
  476. package/dist/runtime/query/fork/mutate.d.ts +17 -0
  477. package/dist/runtime/query/fork/mutate.d.ts.map +1 -0
  478. package/dist/runtime/query/fork/mutate.js +69 -0
  479. package/dist/runtime/query/fork/mutate.js.map +1 -0
  480. package/dist/runtime/query/fork/prepare.d.ts +52 -0
  481. package/dist/runtime/query/fork/prepare.d.ts.map +1 -0
  482. package/dist/runtime/query/fork/prepare.js +43 -0
  483. package/dist/runtime/query/fork/prepare.js.map +1 -0
  484. package/dist/runtime/query/guard.d.ts +16 -16
  485. package/dist/runtime/query/guard.d.ts.map +1 -1
  486. package/dist/runtime/query/guard.js +16 -16
  487. package/dist/runtime/query/guard.js.map +1 -1
  488. package/dist/runtime/query/guardrail-presets.d.ts +10 -10
  489. package/dist/runtime/query/guardrail-presets.js +12 -12
  490. package/dist/runtime/query/guardrail-presets.js.map +1 -1
  491. package/dist/runtime/query/guardrails.d.ts +4 -4
  492. package/dist/runtime/query/guardrails.js +11 -11
  493. package/dist/runtime/query/guardrails.js.map +1 -1
  494. package/dist/runtime/query/index.d.ts +193 -155
  495. package/dist/runtime/query/index.d.ts.map +1 -1
  496. package/dist/runtime/query/index.js +1295 -1260
  497. package/dist/runtime/query/index.js.map +1 -1
  498. package/dist/runtime/query/iteration/index.d.ts +16 -16
  499. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  500. package/dist/runtime/query/iteration/index.js +285 -243
  501. package/dist/runtime/query/iteration/index.js.map +1 -1
  502. package/dist/runtime/query/iteration/outstanding-work.d.ts +22 -22
  503. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  504. package/dist/runtime/query/iteration/outstanding-work.js +63 -63
  505. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  506. package/dist/runtime/query/iteration/phases/advisory.js +16 -16
  507. package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
  508. package/dist/runtime/query/iteration/phases/checkpoint.d.ts +2 -2
  509. package/dist/runtime/query/iteration/phases/checkpoint.d.ts.map +1 -1
  510. package/dist/runtime/query/iteration/phases/checkpoint.js +25 -8
  511. package/dist/runtime/query/iteration/phases/checkpoint.js.map +1 -1
  512. package/dist/runtime/query/iteration/phases/compaction.d.ts +2 -2
  513. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  514. package/dist/runtime/query/iteration/phases/compaction.js +74 -72
  515. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  516. package/dist/runtime/query/iteration/phases/context.d.ts +34 -29
  517. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  518. package/dist/runtime/query/iteration/phases/context.js +29 -29
  519. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  520. package/dist/runtime/query/iteration/phases/plan.d.ts +2 -2
  521. package/dist/runtime/query/iteration/phases/plan.d.ts.map +1 -1
  522. package/dist/runtime/query/iteration/phases/plan.js +5 -4
  523. package/dist/runtime/query/iteration/phases/plan.js.map +1 -1
  524. package/dist/runtime/query/iteration/phases/tool-review.d.ts +2 -2
  525. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  526. package/dist/runtime/query/iteration/phases/tool-review.js +140 -25
  527. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  528. package/dist/runtime/query/iteration/phases/working-memory.d.ts +27 -3
  529. package/dist/runtime/query/iteration/phases/working-memory.d.ts.map +1 -1
  530. package/dist/runtime/query/iteration/phases/working-memory.js +54 -20
  531. package/dist/runtime/query/iteration/phases/working-memory.js.map +1 -1
  532. package/dist/runtime/query/iteration/step-context.d.ts +11 -0
  533. package/dist/runtime/query/iteration/step-context.d.ts.map +1 -0
  534. package/dist/runtime/query/iteration/step-context.js +14 -0
  535. package/dist/runtime/query/iteration/step-context.js.map +1 -0
  536. package/dist/runtime/query/iteration/step-shaping.d.ts +4 -3
  537. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  538. package/dist/runtime/query/iteration/step-shaping.js +20 -19
  539. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  540. package/dist/runtime/query/iteration/stream-turn.d.ts +5 -3
  541. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  542. package/dist/runtime/query/iteration/stream-turn.js +32 -28
  543. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  544. package/dist/runtime/query/plugin-hooks.js +1 -1
  545. package/dist/runtime/query/plugin-hooks.js.map +1 -1
  546. package/dist/runtime/query/prepare-turn.d.ts +105 -0
  547. package/dist/runtime/query/prepare-turn.d.ts.map +1 -0
  548. package/dist/runtime/query/prepare-turn.js +779 -0
  549. package/dist/runtime/query/prepare-turn.js.map +1 -0
  550. package/dist/runtime/query/project-instructions.d.ts +5 -4
  551. package/dist/runtime/query/project-instructions.d.ts.map +1 -1
  552. package/dist/runtime/query/project-instructions.js.map +1 -1
  553. package/dist/runtime/query/prompt-cache.js +1 -1
  554. package/dist/runtime/query/prompt-cache.js.map +1 -1
  555. package/dist/runtime/query/prompt.d.ts +3 -3
  556. package/dist/runtime/query/prompt.d.ts.map +1 -1
  557. package/dist/runtime/query/prompt.js +3 -3
  558. package/dist/runtime/query/prompt.js.map +1 -1
  559. package/dist/runtime/query/question-park.d.ts +7 -7
  560. package/dist/runtime/query/question-park.d.ts.map +1 -1
  561. package/dist/runtime/query/question-park.js +5 -5
  562. package/dist/runtime/query/question-park.js.map +1 -1
  563. package/dist/runtime/query/release-turn.d.ts +53 -0
  564. package/dist/runtime/query/release-turn.d.ts.map +1 -0
  565. package/dist/runtime/query/release-turn.js +95 -0
  566. package/dist/runtime/query/release-turn.js.map +1 -0
  567. package/dist/runtime/query/repeat-call.d.ts +2 -2
  568. package/dist/runtime/query/repeat-call.js +7 -7
  569. package/dist/runtime/query/repeat-call.js.map +1 -1
  570. package/dist/runtime/query/result.d.ts +25 -17
  571. package/dist/runtime/query/result.d.ts.map +1 -1
  572. package/dist/runtime/query/result.js +110 -115
  573. package/dist/runtime/query/result.js.map +1 -1
  574. package/dist/runtime/query/resume-pending.d.ts +34 -17
  575. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  576. package/dist/runtime/query/resume-pending.js +70 -30
  577. package/dist/runtime/query/resume-pending.js.map +1 -1
  578. package/dist/runtime/query/resume-session.d.ts +65 -0
  579. package/dist/runtime/query/resume-session.d.ts.map +1 -0
  580. package/dist/runtime/query/resume-session.js +88 -0
  581. package/dist/runtime/query/resume-session.js.map +1 -0
  582. package/dist/runtime/query/review-policy.d.ts +57 -16
  583. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  584. package/dist/runtime/query/review-policy.js +115 -11
  585. package/dist/runtime/query/review-policy.js.map +1 -1
  586. package/dist/runtime/query/sandbox-lifecycle.d.ts +5 -5
  587. package/dist/runtime/query/sandbox-lifecycle.d.ts.map +1 -1
  588. package/dist/runtime/query/sandbox-lifecycle.js +4 -4
  589. package/dist/runtime/query/sandbox-lifecycle.js.map +1 -1
  590. package/dist/runtime/query/session-storage.d.ts +75 -0
  591. package/dist/runtime/query/session-storage.d.ts.map +1 -0
  592. package/dist/runtime/query/session-storage.js +236 -0
  593. package/dist/runtime/query/session-storage.js.map +1 -0
  594. package/dist/runtime/query/steering.d.ts +9 -3
  595. package/dist/runtime/query/steering.d.ts.map +1 -1
  596. package/dist/runtime/query/steering.js +12 -2
  597. package/dist/runtime/query/steering.js.map +1 -1
  598. package/dist/runtime/query/token-budget.d.ts +19 -5
  599. package/dist/runtime/query/token-budget.d.ts.map +1 -1
  600. package/dist/runtime/query/token-budget.js +43 -74
  601. package/dist/runtime/query/token-budget.js.map +1 -1
  602. package/dist/runtime/query/tool-call-budget.d.ts +6 -5
  603. package/dist/runtime/query/tool-call-budget.d.ts.map +1 -1
  604. package/dist/runtime/query/tool-call-budget.js +10 -12
  605. package/dist/runtime/query/tool-call-budget.js.map +1 -1
  606. package/dist/runtime/query/tool-executions.d.ts +26 -0
  607. package/dist/runtime/query/tool-executions.d.ts.map +1 -0
  608. package/dist/runtime/query/tool-executions.js +66 -0
  609. package/dist/runtime/query/tool-executions.js.map +1 -0
  610. package/dist/runtime/query/tool-grants.d.ts +3 -3
  611. package/dist/runtime/query/tool-grants.js +3 -3
  612. package/dist/runtime/query/tool-output-budget.d.ts +2 -2
  613. package/dist/runtime/query/tool-output-budget.js +4 -4
  614. package/dist/runtime/query/tool-output-budget.js.map +1 -1
  615. package/dist/runtime/query/tool-pause.d.ts +4 -3
  616. package/dist/runtime/query/tool-pause.d.ts.map +1 -1
  617. package/dist/runtime/query/tool-pause.js +5 -4
  618. package/dist/runtime/query/tool-pause.js.map +1 -1
  619. package/dist/runtime/query/tooling.d.ts +15 -10
  620. package/dist/runtime/query/tooling.d.ts.map +1 -1
  621. package/dist/runtime/query/tooling.js +7 -4
  622. package/dist/runtime/query/tooling.js.map +1 -1
  623. package/dist/runtime/query/turn-state.d.ts +56 -0
  624. package/dist/runtime/query/turn-state.d.ts.map +1 -0
  625. package/dist/runtime/query/turn-state.js +99 -0
  626. package/dist/runtime/query/turn-state.js.map +1 -0
  627. package/dist/sandbox/isolation.d.ts +1 -1
  628. package/dist/sandbox/isolation.js +2 -2
  629. package/dist/sandbox/isolation.js.map +1 -1
  630. package/dist/sandbox/provider/local.d.ts +2 -2
  631. package/dist/sandbox/provider/local.js +7 -7
  632. package/dist/sandbox/provider/local.js.map +1 -1
  633. package/dist/scheduler/completion-inbox.d.ts +21 -21
  634. package/dist/scheduler/completion-inbox.js +36 -36
  635. package/dist/scheduler/completion-inbox.js.map +1 -1
  636. package/dist/scheduler/delegating.d.ts +6 -3
  637. package/dist/scheduler/delegating.d.ts.map +1 -1
  638. package/dist/scheduler/delegating.js +15 -8
  639. package/dist/scheduler/delegating.js.map +1 -1
  640. package/dist/scheduler/local.d.ts +10 -8
  641. package/dist/scheduler/local.d.ts.map +1 -1
  642. package/dist/scheduler/local.js +37 -11
  643. package/dist/scheduler/local.js.map +1 -1
  644. package/dist/session/events/index.d.ts +3 -3
  645. package/dist/session/events/index.d.ts.map +1 -1
  646. package/dist/session/events/index.js +4 -8
  647. package/dist/session/events/index.js.map +1 -1
  648. package/dist/session/handoff/broadcast.d.ts +3 -3
  649. package/dist/session/handoff/broadcast.d.ts.map +1 -1
  650. package/dist/session/handoff/broadcast.js +4 -4
  651. package/dist/session/handoff/broadcast.js.map +1 -1
  652. package/dist/session/handoff/events.d.ts +1 -1
  653. package/dist/session/handoff/events.js +1 -1
  654. package/dist/session/handoff/index.d.ts +1 -1
  655. package/dist/session/handoff/index.d.ts.map +1 -1
  656. package/dist/session/handoff/single.d.ts +12 -12
  657. package/dist/session/handoff/single.d.ts.map +1 -1
  658. package/dist/session/handoff/single.js +9 -9
  659. package/dist/session/handoff/single.js.map +1 -1
  660. package/dist/session/handoff/version.d.ts +7 -7
  661. package/dist/session/handoff/version.d.ts.map +1 -1
  662. package/dist/session/handoff/version.js +2 -2
  663. package/dist/session/handoff/version.js.map +1 -1
  664. package/dist/session/home.d.ts +23 -0
  665. package/dist/session/home.d.ts.map +1 -0
  666. package/dist/session/home.js +45 -0
  667. package/dist/session/home.js.map +1 -0
  668. package/dist/session/index.d.ts +1 -0
  669. package/dist/session/index.d.ts.map +1 -1
  670. package/dist/session/index.js +1 -0
  671. package/dist/session/index.js.map +1 -1
  672. package/dist/session/log-hash.d.ts +25 -0
  673. package/dist/session/log-hash.d.ts.map +1 -0
  674. package/dist/session/log-hash.js +82 -0
  675. package/dist/session/log-hash.js.map +1 -0
  676. package/dist/session/messages.d.ts +11 -0
  677. package/dist/session/messages.d.ts.map +1 -0
  678. package/dist/session/messages.js +32 -0
  679. package/dist/session/messages.js.map +1 -0
  680. package/dist/session/paths.d.ts +168 -0
  681. package/dist/session/paths.d.ts.map +1 -0
  682. package/dist/session/paths.js +338 -0
  683. package/dist/session/paths.js.map +1 -0
  684. package/dist/session/retention/archive.d.ts +8 -1
  685. package/dist/session/retention/archive.d.ts.map +1 -1
  686. package/dist/session/retention/archive.js +3 -5
  687. package/dist/session/retention/archive.js.map +1 -1
  688. package/dist/session/status/derive.d.ts +13 -13
  689. package/dist/session/status/derive.d.ts.map +1 -1
  690. package/dist/session/status/derive.js +20 -20
  691. package/dist/session/status/derive.js.map +1 -1
  692. package/dist/session/workspace/git-worktree.d.ts +8 -1
  693. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  694. package/dist/session/workspace/git-worktree.js +29 -1
  695. package/dist/session/workspace/git-worktree.js.map +1 -1
  696. package/dist/session/workspace/index.d.ts +2 -4
  697. package/dist/session/workspace/index.d.ts.map +1 -1
  698. package/dist/session/workspace/index.js +2 -3
  699. package/dist/session/workspace/index.js.map +1 -1
  700. package/dist/session/workspace/shared-session.d.ts +112 -0
  701. package/dist/session/workspace/shared-session.d.ts.map +1 -0
  702. package/dist/session/workspace/shared-session.js +290 -0
  703. package/dist/session/workspace/shared-session.js.map +1 -0
  704. package/dist/session-query/index.d.ts +67 -0
  705. package/dist/session-query/index.d.ts.map +1 -0
  706. package/dist/session-query/index.js +100 -0
  707. package/dist/session-query/index.js.map +1 -0
  708. package/dist/skills/registry.d.ts +1 -1
  709. package/dist/skills/registry.js +1 -1
  710. package/dist/store/activity/memory.d.ts +3 -3
  711. package/dist/store/activity/memory.d.ts.map +1 -1
  712. package/dist/store/activity/memory.js +4 -4
  713. package/dist/store/activity/memory.js.map +1 -1
  714. package/dist/store/attachment/index.d.ts +4 -4
  715. package/dist/store/attachment/index.d.ts.map +1 -1
  716. package/dist/store/attachment/index.js +3 -3
  717. package/dist/store/attachment/index.js.map +1 -1
  718. package/dist/store/budget/disk.d.ts +59 -0
  719. package/dist/store/budget/disk.d.ts.map +1 -0
  720. package/dist/store/budget/disk.js +179 -0
  721. package/dist/store/budget/disk.js.map +1 -0
  722. package/dist/store/budget/index.d.ts +6 -0
  723. package/dist/store/budget/index.d.ts.map +1 -0
  724. package/dist/store/budget/index.js +6 -0
  725. package/dist/store/budget/index.js.map +1 -0
  726. package/dist/store/budget/ledger.d.ts +156 -0
  727. package/dist/store/budget/ledger.d.ts.map +1 -0
  728. package/dist/store/budget/ledger.js +683 -0
  729. package/dist/store/budget/ledger.js.map +1 -0
  730. package/dist/store/budget/memory.d.ts +18 -0
  731. package/dist/store/budget/memory.d.ts.map +1 -0
  732. package/dist/store/budget/memory.js +31 -0
  733. package/dist/store/budget/memory.js.map +1 -0
  734. package/dist/store/checkpoint/contract.d.ts +140 -0
  735. package/dist/store/checkpoint/contract.d.ts.map +1 -0
  736. package/dist/store/checkpoint/contract.js +91 -0
  737. package/dist/store/checkpoint/contract.js.map +1 -0
  738. package/dist/store/checkpoint/disk.d.ts +44 -0
  739. package/dist/store/checkpoint/disk.d.ts.map +1 -0
  740. package/dist/store/checkpoint/disk.js +168 -0
  741. package/dist/store/checkpoint/disk.js.map +1 -0
  742. package/dist/store/checkpoint/index.d.ts +9 -0
  743. package/dist/store/checkpoint/index.d.ts.map +1 -0
  744. package/dist/store/checkpoint/index.js +7 -0
  745. package/dist/store/checkpoint/index.js.map +1 -0
  746. package/dist/store/checkpoint/memory.d.ts +27 -0
  747. package/dist/store/checkpoint/memory.d.ts.map +1 -0
  748. package/dist/store/checkpoint/memory.js +80 -0
  749. package/dist/store/checkpoint/memory.js.map +1 -0
  750. package/dist/store/checkpoint/prune.d.ts +45 -0
  751. package/dist/store/checkpoint/prune.d.ts.map +1 -0
  752. package/dist/store/checkpoint/prune.js +71 -0
  753. package/dist/store/checkpoint/prune.js.map +1 -0
  754. package/dist/store/config/index.d.ts +1 -1
  755. package/dist/store/config/index.js +1 -1
  756. package/dist/store/evidence/disk.d.ts +25 -8
  757. package/dist/store/evidence/disk.d.ts.map +1 -1
  758. package/dist/store/evidence/disk.js +148 -47
  759. package/dist/store/evidence/disk.js.map +1 -1
  760. package/dist/store/evidence/index-page.d.ts +31 -140
  761. package/dist/store/evidence/index-page.d.ts.map +1 -1
  762. package/dist/store/evidence/index-page.js +59 -129
  763. package/dist/store/evidence/index-page.js.map +1 -1
  764. package/dist/store/evidence/source-text.d.ts +7 -6
  765. package/dist/store/evidence/source-text.d.ts.map +1 -1
  766. package/dist/store/evidence/source-text.js +16 -23
  767. package/dist/store/evidence/source-text.js.map +1 -1
  768. package/dist/store/evidence/types.d.ts +38 -39
  769. package/dist/store/evidence/types.d.ts.map +1 -1
  770. package/dist/store/feedback/conformance.d.ts +6 -6
  771. package/dist/store/feedback/conformance.d.ts.map +1 -1
  772. package/dist/store/feedback/conformance.js +30 -29
  773. package/dist/store/feedback/conformance.js.map +1 -1
  774. package/dist/store/feedback/disk.d.ts +20 -19
  775. package/dist/store/feedback/disk.d.ts.map +1 -1
  776. package/dist/store/feedback/disk.js +53 -53
  777. package/dist/store/feedback/disk.js.map +1 -1
  778. package/dist/store/feedback/index.d.ts +1 -1
  779. package/dist/store/feedback/index.d.ts.map +1 -1
  780. package/dist/store/feedback/index.js +1 -1
  781. package/dist/store/feedback/index.js.map +1 -1
  782. package/dist/store/feedback/memory.d.ts +8 -5
  783. package/dist/store/feedback/memory.d.ts.map +1 -1
  784. package/dist/store/feedback/memory.js +0 -0
  785. package/dist/store/feedback/memory.js.map +1 -1
  786. package/dist/store/feedback/types.d.ts +12 -11
  787. package/dist/store/feedback/types.d.ts.map +1 -1
  788. package/dist/store/feedback/types.js +3 -3
  789. package/dist/store/feedback/types.js.map +1 -1
  790. package/dist/store/index.d.ts +7 -8
  791. package/dist/store/index.d.ts.map +1 -1
  792. package/dist/store/index.js +4 -16
  793. package/dist/store/index.js.map +1 -1
  794. package/dist/store/memory/digest.d.ts +15 -0
  795. package/dist/store/memory/digest.d.ts.map +1 -0
  796. package/dist/store/memory/digest.js +27 -0
  797. package/dist/store/memory/digest.js.map +1 -0
  798. package/dist/store/memory/disk.d.ts.map +1 -1
  799. package/dist/store/memory/disk.js +42 -7
  800. package/dist/store/memory/disk.js.map +1 -1
  801. package/dist/store/memory/index-file.d.ts +56 -0
  802. package/dist/store/memory/index-file.d.ts.map +1 -0
  803. package/dist/store/memory/index-file.js +92 -0
  804. package/dist/store/memory/index-file.js.map +1 -0
  805. package/dist/store/memory/index.d.ts.map +1 -1
  806. package/dist/store/memory/index.js +4 -2
  807. package/dist/store/memory/index.js.map +1 -1
  808. package/dist/store/memory/links.d.ts +15 -0
  809. package/dist/store/memory/links.d.ts.map +1 -0
  810. package/dist/store/memory/links.js +35 -0
  811. package/dist/store/memory/links.js.map +1 -0
  812. package/dist/store/memory/markdown-format.d.ts +88 -0
  813. package/dist/store/memory/markdown-format.d.ts.map +1 -0
  814. package/dist/store/memory/markdown-format.js +222 -0
  815. package/dist/store/memory/markdown-format.js.map +1 -0
  816. package/dist/store/memory/markdown.d.ts +109 -0
  817. package/dist/store/memory/markdown.d.ts.map +1 -0
  818. package/dist/store/memory/markdown.js +606 -0
  819. package/dist/store/memory/markdown.js.map +1 -0
  820. package/dist/store/memory/memory.d.ts.map +1 -1
  821. package/dist/store/memory/memory.js +17 -4
  822. package/dist/store/memory/memory.js.map +1 -1
  823. package/dist/store/memory/naming.d.ts +66 -0
  824. package/dist/store/memory/naming.d.ts.map +1 -0
  825. package/dist/store/memory/naming.js +162 -0
  826. package/dist/store/memory/naming.js.map +1 -0
  827. package/dist/store/memory/origin.d.ts +25 -0
  828. package/dist/store/memory/origin.d.ts.map +1 -0
  829. package/dist/store/memory/origin.js +26 -0
  830. package/dist/store/memory/origin.js.map +1 -0
  831. package/dist/store/session/disk.d.ts +21 -24
  832. package/dist/store/session/disk.d.ts.map +1 -1
  833. package/dist/store/session/disk.js +27 -132
  834. package/dist/store/session/disk.js.map +1 -1
  835. package/dist/store/session/index.d.ts +0 -3
  836. package/dist/store/session/index.d.ts.map +1 -1
  837. package/dist/store/session/index.js +5 -7
  838. package/dist/store/session/index.js.map +1 -1
  839. package/dist/store/session/memory.d.ts +1 -8
  840. package/dist/store/session/memory.d.ts.map +1 -1
  841. package/dist/store/session/memory.js +1 -58
  842. package/dist/store/session/memory.js.map +1 -1
  843. package/dist/store/session-claim.d.ts +30 -0
  844. package/dist/store/session-claim.d.ts.map +1 -0
  845. package/dist/store/session-claim.js +71 -0
  846. package/dist/store/session-claim.js.map +1 -0
  847. package/dist/store/session-index/fts.d.ts +60 -0
  848. package/dist/store/session-index/fts.d.ts.map +1 -0
  849. package/dist/store/session-index/fts.js +160 -0
  850. package/dist/store/session-index/fts.js.map +1 -0
  851. package/dist/store/session-index/index.d.ts +206 -0
  852. package/dist/store/session-index/index.d.ts.map +1 -0
  853. package/dist/store/session-index/index.js +22 -0
  854. package/dist/store/session-index/index.js.map +1 -0
  855. package/dist/store/session-index/rebuild.d.ts +180 -0
  856. package/dist/store/session-index/rebuild.d.ts.map +1 -0
  857. package/dist/store/session-index/rebuild.js +669 -0
  858. package/dist/store/session-index/rebuild.js.map +1 -0
  859. package/dist/store/session-index/refs.d.ts +66 -0
  860. package/dist/store/session-index/refs.d.ts.map +1 -0
  861. package/dist/store/session-index/refs.js +107 -0
  862. package/dist/store/session-index/refs.js.map +1 -0
  863. package/dist/store/session-index/scan.d.ts +42 -0
  864. package/dist/store/session-index/scan.d.ts.map +1 -0
  865. package/dist/store/session-index/scan.js +188 -0
  866. package/dist/store/session-index/scan.js.map +1 -0
  867. package/dist/store/session-index/sqlite.d.ts +76 -0
  868. package/dist/store/session-index/sqlite.d.ts.map +1 -0
  869. package/dist/store/session-index/sqlite.js +547 -0
  870. package/dist/store/session-index/sqlite.js.map +1 -0
  871. package/dist/store/session-log/chain.d.ts +111 -0
  872. package/dist/store/session-log/chain.d.ts.map +1 -0
  873. package/dist/store/session-log/chain.js +212 -0
  874. package/dist/store/session-log/chain.js.map +1 -0
  875. package/dist/store/session-log/conformance.d.ts +61 -0
  876. package/dist/store/session-log/conformance.d.ts.map +1 -0
  877. package/dist/store/session-log/conformance.js +392 -0
  878. package/dist/store/session-log/conformance.js.map +1 -0
  879. package/dist/store/session-log/core.d.ts +203 -0
  880. package/dist/store/session-log/core.d.ts.map +1 -0
  881. package/dist/store/session-log/core.js +516 -0
  882. package/dist/store/session-log/core.js.map +1 -0
  883. package/dist/store/session-log/disk.d.ts +56 -0
  884. package/dist/store/session-log/disk.d.ts.map +1 -0
  885. package/dist/store/session-log/disk.js +169 -0
  886. package/dist/store/session-log/disk.js.map +1 -0
  887. package/dist/store/session-log/fold.d.ts +115 -0
  888. package/dist/store/session-log/fold.d.ts.map +1 -0
  889. package/dist/store/session-log/fold.js +265 -0
  890. package/dist/store/session-log/fold.js.map +1 -0
  891. package/dist/store/session-log/heal.d.ts +34 -0
  892. package/dist/store/session-log/heal.d.ts.map +1 -0
  893. package/dist/store/session-log/heal.js +12 -0
  894. package/dist/store/session-log/heal.js.map +1 -0
  895. package/dist/store/session-log/held-leases.d.ts +56 -0
  896. package/dist/store/session-log/held-leases.d.ts.map +1 -0
  897. package/dist/store/session-log/held-leases.js +67 -0
  898. package/dist/store/session-log/held-leases.js.map +1 -0
  899. package/dist/store/session-log/index.d.ts +10 -0
  900. package/dist/store/session-log/index.d.ts.map +1 -0
  901. package/dist/store/session-log/index.js +16 -0
  902. package/dist/store/session-log/index.js.map +1 -0
  903. package/dist/store/session-log/lease.d.ts +126 -0
  904. package/dist/store/session-log/lease.d.ts.map +1 -0
  905. package/dist/store/session-log/lease.js +226 -0
  906. package/dist/store/session-log/lease.js.map +1 -0
  907. package/dist/store/session-log/memory.d.ts +43 -0
  908. package/dist/store/session-log/memory.d.ts.map +1 -0
  909. package/dist/store/session-log/memory.js +78 -0
  910. package/dist/store/session-log/memory.js.map +1 -0
  911. package/dist/store/session-log/spill.d.ts +109 -0
  912. package/dist/store/session-log/spill.d.ts.map +1 -0
  913. package/dist/store/session-log/spill.js +223 -0
  914. package/dist/store/session-log/spill.js.map +1 -0
  915. package/dist/store/task/context.d.ts +25 -0
  916. package/dist/store/task/context.d.ts.map +1 -0
  917. package/dist/store/task/context.js +18 -0
  918. package/dist/store/task/context.js.map +1 -0
  919. package/dist/store/task/disk.d.ts +29 -26
  920. package/dist/store/task/disk.d.ts.map +1 -1
  921. package/dist/store/task/disk.js +102 -137
  922. package/dist/store/task/disk.js.map +1 -1
  923. package/dist/store/task/memory.d.ts +2 -2
  924. package/dist/store/task/memory.d.ts.map +1 -1
  925. package/dist/store/task/memory.js +10 -6
  926. package/dist/store/task/memory.js.map +1 -1
  927. package/dist/store/topic/index.js +2 -2
  928. package/dist/store/topic/index.js.map +1 -1
  929. package/dist/store/topic/objective.d.ts.map +1 -1
  930. package/dist/store/topic/objective.js +10 -3
  931. package/dist/store/topic/objective.js.map +1 -1
  932. package/dist/store/topic/state.js +1 -1
  933. package/dist/streaming/coalesce.d.ts +3 -3
  934. package/dist/streaming/coalesce.d.ts.map +1 -1
  935. package/dist/streaming/coalesce.js +1 -1
  936. package/dist/streaming/coalesce.js.map +1 -1
  937. package/dist/telemetry/attributes.d.ts +9 -8
  938. package/dist/telemetry/attributes.d.ts.map +1 -1
  939. package/dist/telemetry/attributes.js +6 -5
  940. package/dist/telemetry/attributes.js.map +1 -1
  941. package/dist/telemetry/metrics.d.ts +2 -2
  942. package/dist/telemetry/metrics.d.ts.map +1 -1
  943. package/dist/telemetry/metrics.js +5 -5
  944. package/dist/telemetry/metrics.js.map +1 -1
  945. package/dist/telemetry/runtime-accessors.js +1 -1
  946. package/dist/telemetry/runtime-accessors.js.map +1 -1
  947. package/dist/test-support/ids.d.ts +4 -4
  948. package/dist/test-support/ids.d.ts.map +1 -1
  949. package/dist/test-support/ids.js +3 -3
  950. package/dist/test-support/ids.js.map +1 -1
  951. package/dist/testing.d.ts +4 -6
  952. package/dist/testing.d.ts.map +1 -1
  953. package/dist/testing.js +3 -5
  954. package/dist/testing.js.map +1 -1
  955. package/dist/tools/advisory/index.js +1 -1
  956. package/dist/tools/advisory/index.js.map +1 -1
  957. package/dist/tools/builtins/bash.d.ts +6 -0
  958. package/dist/tools/builtins/bash.d.ts.map +1 -1
  959. package/dist/tools/builtins/bash.js +37 -5
  960. package/dist/tools/builtins/bash.js.map +1 -1
  961. package/dist/tools/builtins/content-fingerprint.d.ts +2 -2
  962. package/dist/tools/builtins/content-fingerprint.js +2 -2
  963. package/dist/tools/builtins/edit-apply.js +1 -1
  964. package/dist/tools/builtins/edit-apply.js.map +1 -1
  965. package/dist/tools/builtins/edit.d.ts.map +1 -1
  966. package/dist/tools/builtins/edit.js +3 -0
  967. package/dist/tools/builtins/edit.js.map +1 -1
  968. package/dist/tools/builtins/glob.d.ts.map +1 -1
  969. package/dist/tools/builtins/glob.js +3 -0
  970. package/dist/tools/builtins/glob.js.map +1 -1
  971. package/dist/tools/builtins/grep.d.ts.map +1 -1
  972. package/dist/tools/builtins/grep.js +3 -0
  973. package/dist/tools/builtins/grep.js.map +1 -1
  974. package/dist/tools/builtins/job.js +5 -5
  975. package/dist/tools/builtins/job.js.map +1 -1
  976. package/dist/tools/builtins/ls.d.ts +1 -1
  977. package/dist/tools/builtins/ls.d.ts.map +1 -1
  978. package/dist/tools/builtins/ls.js +3 -0
  979. package/dist/tools/builtins/ls.js.map +1 -1
  980. package/dist/tools/builtins/lsp.d.ts +1 -1
  981. package/dist/tools/builtins/lsp.d.ts.map +1 -1
  982. package/dist/tools/builtins/lsp.js +5 -2
  983. package/dist/tools/builtins/lsp.js.map +1 -1
  984. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  985. package/dist/tools/builtins/read-file.js +3 -0
  986. package/dist/tools/builtins/read-file.js.map +1 -1
  987. package/dist/tools/builtins/run-code.js +9 -9
  988. package/dist/tools/builtins/run-code.js.map +1 -1
  989. package/dist/tools/builtins/skill.js +3 -3
  990. package/dist/tools/builtins/skill.js.map +1 -1
  991. package/dist/tools/builtins/wait-for-job-bounds.d.ts +4 -4
  992. package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
  993. package/dist/tools/builtins/wait-for-job-bounds.js +2 -2
  994. package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
  995. package/dist/tools/builtins/wait-for-job.js +3 -3
  996. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  997. package/dist/tools/builtins/web-guidance.d.ts +2 -2
  998. package/dist/tools/builtins/web-guidance.js +2 -2
  999. package/dist/tools/builtins/web.js +3 -3
  1000. package/dist/tools/builtins/web.js.map +1 -1
  1001. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  1002. package/dist/tools/builtins/write-file.js +3 -0
  1003. package/dist/tools/builtins/write-file.js.map +1 -1
  1004. package/dist/tools/coordinator/agent.d.ts +1 -1
  1005. package/dist/tools/coordinator/agent.js +7 -7
  1006. package/dist/tools/coordinator/agent.js.map +1 -1
  1007. package/dist/tools/coordinator/ask-user-question.d.ts +10 -9
  1008. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  1009. package/dist/tools/coordinator/ask-user-question.js +9 -8
  1010. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  1011. package/dist/tools/coordinator/index.d.ts +17 -11
  1012. package/dist/tools/coordinator/index.d.ts.map +1 -1
  1013. package/dist/tools/coordinator/index.js +45 -44
  1014. package/dist/tools/coordinator/index.js.map +1 -1
  1015. package/dist/tools/coordinator/outcome.d.ts +5 -5
  1016. package/dist/tools/coordinator/outcome.js +7 -7
  1017. package/dist/tools/coordinator/outcome.js.map +1 -1
  1018. package/dist/tools/coordinator/plan-dependencies.js +1 -1
  1019. package/dist/tools/coordinator/plan-dependencies.js.map +1 -1
  1020. package/dist/tools/coordinator/wait-with-idle-bound.d.ts +4 -4
  1021. package/dist/tools/coordinator/wait-with-idle-bound.d.ts.map +1 -1
  1022. package/dist/tools/coordinator/wait-with-idle-bound.js +2 -2
  1023. package/dist/tools/coordinator/wait-with-idle-bound.js.map +1 -1
  1024. package/dist/tools/defineTool.d.ts +5 -1
  1025. package/dist/tools/defineTool.d.ts.map +1 -1
  1026. package/dist/tools/defineTool.js +4 -0
  1027. package/dist/tools/defineTool.js.map +1 -1
  1028. package/dist/tools/env-scrub.d.ts +1 -1
  1029. package/dist/tools/env-scrub.js +1 -1
  1030. package/dist/tools/goal/index.d.ts +10 -6
  1031. package/dist/tools/goal/index.d.ts.map +1 -1
  1032. package/dist/tools/goal/index.js +9 -9
  1033. package/dist/tools/goal/index.js.map +1 -1
  1034. package/dist/tools/memory/fields.d.ts +8 -0
  1035. package/dist/tools/memory/fields.d.ts.map +1 -0
  1036. package/dist/tools/memory/fields.js +22 -0
  1037. package/dist/tools/memory/fields.js.map +1 -0
  1038. package/dist/tools/memory/read.d.ts.map +1 -1
  1039. package/dist/tools/memory/read.js +60 -7
  1040. package/dist/tools/memory/read.js.map +1 -1
  1041. package/dist/tools/memory/resolve.d.ts +21 -0
  1042. package/dist/tools/memory/resolve.d.ts.map +1 -0
  1043. package/dist/tools/memory/resolve.js +23 -0
  1044. package/dist/tools/memory/resolve.js.map +1 -0
  1045. package/dist/tools/memory/save.d.ts.map +1 -1
  1046. package/dist/tools/memory/save.js +57 -18
  1047. package/dist/tools/memory/save.js.map +1 -1
  1048. package/dist/tools/memory/search.d.ts.map +1 -1
  1049. package/dist/tools/memory/search.js +9 -2
  1050. package/dist/tools/memory/search.js.map +1 -1
  1051. package/dist/tools/memory/update.d.ts.map +1 -1
  1052. package/dist/tools/memory/update.js +45 -7
  1053. package/dist/tools/memory/update.js.map +1 -1
  1054. package/dist/tools/paths.d.ts +29 -3
  1055. package/dist/tools/paths.d.ts.map +1 -1
  1056. package/dist/tools/paths.js +81 -23
  1057. package/dist/tools/paths.js.map +1 -1
  1058. package/dist/tools/posix-path.js +1 -1
  1059. package/dist/tools/posix-path.js.map +1 -1
  1060. package/dist/tools/resident-history.d.ts +1 -1
  1061. package/dist/tools/resident-history.js +1 -1
  1062. package/dist/tools/resident-tool-evidence.d.ts +1 -1
  1063. package/dist/tools/resident-tool-evidence.d.ts.map +1 -1
  1064. package/dist/tools/resident-tool-evidence.js +1 -1
  1065. package/dist/tools/resident-tool-evidence.js.map +1 -1
  1066. package/dist/tools/task/create.d.ts +2 -2
  1067. package/dist/tools/task/create.d.ts.map +1 -1
  1068. package/dist/tools/task/create.js +7 -3
  1069. package/dist/tools/task/create.js.map +1 -1
  1070. package/dist/tools/task/index.d.ts +16 -2
  1071. package/dist/tools/task/index.d.ts.map +1 -1
  1072. package/dist/tools/task/index.js +4 -3
  1073. package/dist/tools/task/index.js.map +1 -1
  1074. package/dist/tools/task/list.d.ts +4 -2
  1075. package/dist/tools/task/list.d.ts.map +1 -1
  1076. package/dist/tools/task/list.js +12 -5
  1077. package/dist/tools/task/list.js.map +1 -1
  1078. package/dist/tools/task/present.d.ts +18 -0
  1079. package/dist/tools/task/present.d.ts.map +1 -0
  1080. package/dist/tools/task/present.js +88 -0
  1081. package/dist/tools/task/present.js.map +1 -0
  1082. package/dist/tools/task/update.d.ts.map +1 -1
  1083. package/dist/tools/task/update.js +9 -1
  1084. package/dist/tools/task/update.js.map +1 -1
  1085. package/dist/turn/LimitChecker.d.ts +30 -0
  1086. package/dist/turn/LimitChecker.d.ts.map +1 -0
  1087. package/dist/turn/LimitChecker.js +57 -0
  1088. package/dist/turn/LimitChecker.js.map +1 -0
  1089. package/dist/turn/command-gate.d.ts +107 -0
  1090. package/dist/turn/command-gate.d.ts.map +1 -0
  1091. package/dist/turn/command-gate.js +221 -0
  1092. package/dist/turn/command-gate.js.map +1 -0
  1093. package/dist/turn/drain.d.ts +138 -0
  1094. package/dist/turn/drain.d.ts.map +1 -0
  1095. package/dist/turn/drain.js +209 -0
  1096. package/dist/turn/drain.js.map +1 -0
  1097. package/dist/turn/evidence-query.d.ts +41 -0
  1098. package/dist/turn/evidence-query.d.ts.map +1 -0
  1099. package/dist/turn/evidence-query.js +270 -0
  1100. package/dist/turn/evidence-query.js.map +1 -0
  1101. package/dist/turn/evidence-recall.d.ts +102 -0
  1102. package/dist/turn/evidence-recall.d.ts.map +1 -0
  1103. package/dist/turn/evidence-recall.js +635 -0
  1104. package/dist/turn/evidence-recall.js.map +1 -0
  1105. package/dist/turn/index.d.ts +17 -0
  1106. package/dist/turn/index.d.ts.map +1 -0
  1107. package/dist/turn/index.js +9 -0
  1108. package/dist/turn/index.js.map +1 -0
  1109. package/dist/turn/json-claim-verifier.d.ts +83 -0
  1110. package/dist/turn/json-claim-verifier.d.ts.map +1 -0
  1111. package/dist/turn/json-claim-verifier.js +200 -0
  1112. package/dist/turn/json-claim-verifier.js.map +1 -0
  1113. package/dist/turn/memory-promoter.d.ts +43 -0
  1114. package/dist/turn/memory-promoter.d.ts.map +1 -0
  1115. package/dist/turn/memory-promoter.js +111 -0
  1116. package/dist/turn/memory-promoter.js.map +1 -0
  1117. package/dist/turn/memory-recall.d.ts +33 -0
  1118. package/dist/turn/memory-recall.d.ts.map +1 -0
  1119. package/dist/turn/memory-recall.js +248 -0
  1120. package/dist/turn/memory-recall.js.map +1 -0
  1121. package/dist/turn/preparation-context-error.d.ts.map +1 -0
  1122. package/dist/turn/preparation-context-error.js.map +1 -0
  1123. package/dist/turn/reporter.d.ts +8 -0
  1124. package/dist/turn/reporter.d.ts.map +1 -0
  1125. package/dist/turn/reporter.js +420 -0
  1126. package/dist/turn/reporter.js.map +1 -0
  1127. package/dist/turn/workspace-fingerprint.d.ts.map +1 -0
  1128. package/dist/turn/workspace-fingerprint.js.map +1 -0
  1129. package/dist/types/activity/index.d.ts +2 -2
  1130. package/dist/types/activity/index.d.ts.map +1 -1
  1131. package/dist/types/advisory/config.d.ts +7 -7
  1132. package/dist/types/advisory/config.d.ts.map +1 -1
  1133. package/dist/types/agent/base.d.ts +71 -44
  1134. package/dist/types/agent/base.d.ts.map +1 -1
  1135. package/dist/types/agent/core.d.ts +10 -10
  1136. package/dist/types/agent/core.d.ts.map +1 -1
  1137. package/dist/types/agent/delegate.d.ts +2 -2
  1138. package/dist/types/agent/factory.d.ts +6 -4
  1139. package/dist/types/agent/factory.d.ts.map +1 -1
  1140. package/dist/types/agent/manager.d.ts +6 -6
  1141. package/dist/types/agent/manager.d.ts.map +1 -1
  1142. package/dist/types/agent/pipeline.d.ts +5 -4
  1143. package/dist/types/agent/pipeline.d.ts.map +1 -1
  1144. package/dist/types/agent/reactive.d.ts +11 -10
  1145. package/dist/types/agent/reactive.d.ts.map +1 -1
  1146. package/dist/types/agent/router.d.ts +1 -1
  1147. package/dist/types/agent/scheduler.d.ts +27 -11
  1148. package/dist/types/agent/scheduler.d.ts.map +1 -1
  1149. package/dist/types/agent/supervisor.d.ts +13 -13
  1150. package/dist/types/agent/task.d.ts +48 -12
  1151. package/dist/types/agent/task.d.ts.map +1 -1
  1152. package/dist/types/agent/working-memory.d.ts +5 -4
  1153. package/dist/types/agent/working-memory.d.ts.map +1 -1
  1154. package/dist/types/authorization/index.d.ts +6 -6
  1155. package/dist/types/bidi/index.d.ts +21 -12
  1156. package/dist/types/bidi/index.d.ts.map +1 -1
  1157. package/dist/types/bus/index.d.ts +34 -28
  1158. package/dist/types/bus/index.d.ts.map +1 -1
  1159. package/dist/types/code-navigation/index.d.ts +1 -1
  1160. package/dist/types/common/index.d.ts +10 -18
  1161. package/dist/types/common/index.d.ts.map +1 -1
  1162. package/dist/types/common/index.js +3 -2
  1163. package/dist/types/common/index.js.map +1 -1
  1164. package/dist/types/connector/core.d.ts +2 -2
  1165. package/dist/types/connector/definition.d.ts +1 -1
  1166. package/dist/types/connector/mcp.d.ts +1 -1
  1167. package/dist/types/errors/catalog.js +4 -4
  1168. package/dist/types/errors/catalog.js.map +1 -1
  1169. package/dist/types/errors/index.d.ts +5 -5
  1170. package/dist/types/errors/index.d.ts.map +1 -1
  1171. package/dist/types/guardrail/index.d.ts +12 -10
  1172. package/dist/types/guardrail/index.d.ts.map +1 -1
  1173. package/dist/types/hitl/index.d.ts +60 -117
  1174. package/dist/types/hitl/index.d.ts.map +1 -1
  1175. package/dist/types/hitl/index.js +1 -1
  1176. package/dist/types/hitl/index.js.map +1 -1
  1177. package/dist/types/hitl/policy.d.ts +8 -6
  1178. package/dist/types/hitl/policy.d.ts.map +1 -1
  1179. package/dist/types/ids/brand.d.ts +10 -3
  1180. package/dist/types/ids/brand.d.ts.map +1 -1
  1181. package/dist/types/ids/brand.js.map +1 -1
  1182. package/dist/types/ids/index.d.ts +10 -4
  1183. package/dist/types/ids/index.d.ts.map +1 -1
  1184. package/dist/types/ids/index.js.map +1 -1
  1185. package/dist/types/memory/index.d.ts +35 -0
  1186. package/dist/types/memory/index.d.ts.map +1 -1
  1187. package/dist/types/memory/index.js +17 -0
  1188. package/dist/types/memory/index.js.map +1 -1
  1189. package/dist/types/message/index.d.ts +4 -4
  1190. package/dist/types/plan/index.d.ts +5 -3
  1191. package/dist/types/plan/index.d.ts.map +1 -1
  1192. package/dist/types/plugin/index.d.ts +27 -19
  1193. package/dist/types/plugin/index.d.ts.map +1 -1
  1194. package/dist/types/plugin/index.js +16 -3
  1195. package/dist/types/plugin/index.js.map +1 -1
  1196. package/dist/types/probe/event-kind.d.ts +3 -3
  1197. package/dist/types/probe/event-kind.d.ts.map +1 -1
  1198. package/dist/types/probe/registry.d.ts +3 -2
  1199. package/dist/types/probe/registry.d.ts.map +1 -1
  1200. package/dist/types/project/entity.d.ts +3 -3
  1201. package/dist/types/provider/config.d.ts +3 -3
  1202. package/dist/types/provider/error.d.ts +1 -1
  1203. package/dist/types/provider/errors.d.ts +2 -2
  1204. package/dist/types/provider/errors.js +2 -2
  1205. package/dist/types/provider/errors.js.map +1 -1
  1206. package/dist/types/provider/interface.d.ts +5 -5
  1207. package/dist/types/router/task-router.d.ts +1 -1
  1208. package/dist/types/sandbox/index.d.ts +14 -14
  1209. package/dist/types/sandbox/index.d.ts.map +1 -1
  1210. package/dist/types/sandbox/index.js +4 -4
  1211. package/dist/types/session/answer-review.d.ts +80 -0
  1212. package/dist/types/session/answer-review.d.ts.map +1 -0
  1213. package/dist/types/session/answer-review.js.map +1 -0
  1214. package/dist/types/session/audit.d.ts +153 -0
  1215. package/dist/types/session/audit.d.ts.map +1 -0
  1216. package/dist/types/session/audit.js +35 -0
  1217. package/dist/types/session/audit.js.map +1 -0
  1218. package/dist/types/session/cancel-cause.d.ts +49 -0
  1219. package/dist/types/session/cancel-cause.d.ts.map +1 -0
  1220. package/dist/types/session/cancel-cause.js +39 -0
  1221. package/dist/types/session/cancel-cause.js.map +1 -0
  1222. package/dist/types/session/checkpoint.d.ts +325 -0
  1223. package/dist/types/session/checkpoint.d.ts.map +1 -0
  1224. package/dist/types/session/checkpoint.js +100 -0
  1225. package/dist/types/session/checkpoint.js.map +1 -0
  1226. package/dist/types/session/config.d.ts +199 -0
  1227. package/dist/types/session/config.d.ts.map +1 -0
  1228. package/dist/types/session/config.js.map +1 -0
  1229. package/dist/types/session/derive-status.d.ts +28 -0
  1230. package/dist/types/session/derive-status.d.ts.map +1 -0
  1231. package/dist/types/session/derive-status.js +49 -0
  1232. package/dist/types/session/derive-status.js.map +1 -0
  1233. package/dist/types/session/durable.d.ts +142 -0
  1234. package/dist/types/session/durable.d.ts.map +1 -0
  1235. package/dist/types/session/durable.js +11 -0
  1236. package/dist/types/session/durable.js.map +1 -0
  1237. package/dist/types/session/entity.d.ts +1 -1
  1238. package/dist/types/session/events.d.ts +1147 -0
  1239. package/dist/types/session/events.d.ts.map +1 -0
  1240. package/dist/types/session/events.js +15 -0
  1241. package/dist/types/session/events.js.map +1 -0
  1242. package/dist/types/session/fork.d.ts +45 -0
  1243. package/dist/types/session/fork.d.ts.map +1 -0
  1244. package/dist/types/session/fork.js +15 -0
  1245. package/dist/types/session/fork.js.map +1 -0
  1246. package/dist/types/session/ids.d.ts +1 -1
  1247. package/dist/types/session/ids.d.ts.map +1 -1
  1248. package/dist/types/session/index.d.ts +20 -1
  1249. package/dist/types/session/index.d.ts.map +1 -1
  1250. package/dist/types/session/index.js +22 -4
  1251. package/dist/types/session/index.js.map +1 -1
  1252. package/dist/types/session/lineage.d.ts +15 -0
  1253. package/dist/types/session/lineage.d.ts.map +1 -0
  1254. package/dist/types/session/lineage.js.map +1 -0
  1255. package/dist/types/session/log-cursor.d.ts +57 -0
  1256. package/dist/types/session/log-cursor.d.ts.map +1 -0
  1257. package/dist/types/session/log-cursor.js +34 -0
  1258. package/dist/types/session/log-cursor.js.map +1 -0
  1259. package/dist/types/session/memory-promotion.d.ts +91 -0
  1260. package/dist/types/session/memory-promotion.d.ts.map +1 -0
  1261. package/dist/types/session/memory-promotion.js +39 -0
  1262. package/dist/types/session/memory-promotion.js.map +1 -0
  1263. package/dist/types/session/messages.d.ts +1 -1
  1264. package/dist/types/session/messages.js +1 -1
  1265. package/dist/types/session/prepare-step.d.ts +278 -0
  1266. package/dist/types/session/prepare-step.d.ts.map +1 -0
  1267. package/dist/types/session/prepare-step.js.map +1 -0
  1268. package/dist/types/session/records.d.ts +5597 -0
  1269. package/dist/types/session/records.d.ts.map +1 -0
  1270. package/dist/types/session/records.js +721 -0
  1271. package/dist/types/session/records.js.map +1 -0
  1272. package/dist/types/session/step.d.ts +195 -0
  1273. package/dist/types/session/step.d.ts.map +1 -0
  1274. package/dist/types/session/step.js +26 -0
  1275. package/dist/types/session/step.js.map +1 -0
  1276. package/dist/types/session/stop-reason.d.ts +67 -0
  1277. package/dist/types/session/stop-reason.d.ts.map +1 -0
  1278. package/dist/types/session/stop-reason.js.map +1 -0
  1279. package/dist/types/session/store.d.ts +2 -43
  1280. package/dist/types/session/store.d.ts.map +1 -1
  1281. package/dist/types/session/tool-execution.d.ts +34 -0
  1282. package/dist/types/session/tool-execution.d.ts.map +1 -0
  1283. package/dist/types/session/tool-execution.js +11 -0
  1284. package/dist/types/session/tool-execution.js.map +1 -0
  1285. package/dist/types/session/turn-state.d.ts +74 -0
  1286. package/dist/types/session/turn-state.d.ts.map +1 -0
  1287. package/dist/types/session/turn-state.js +59 -0
  1288. package/dist/types/session/turn-state.js.map +1 -0
  1289. package/dist/types/session/turn.d.ts +215 -0
  1290. package/dist/types/session/turn.d.ts.map +1 -0
  1291. package/dist/types/session/turn.js +44 -0
  1292. package/dist/types/session/turn.js.map +1 -0
  1293. package/dist/types/structured-output/index.d.ts +2 -2
  1294. package/dist/types/structured-output/index.d.ts.map +1 -1
  1295. package/dist/types/summary/deliverable.d.ts +4 -4
  1296. package/dist/types/summary/deliverable.d.ts.map +1 -1
  1297. package/dist/types/task/index.d.ts +8 -4
  1298. package/dist/types/task/index.d.ts.map +1 -1
  1299. package/dist/types/tool/index.d.ts +73 -26
  1300. package/dist/types/tool/index.d.ts.map +1 -1
  1301. package/dist/types/tool/index.js.map +1 -1
  1302. package/dist/types/topic/entity.d.ts +6 -6
  1303. package/dist/types/topic/objective.d.ts +10 -5
  1304. package/dist/types/topic/objective.d.ts.map +1 -1
  1305. package/dist/types/topic/objective.js.map +1 -1
  1306. package/dist/types/topic/state.d.ts +4 -4
  1307. package/dist/types/topic/store.d.ts +1 -1
  1308. package/dist/types/topic/store.js +1 -1
  1309. package/dist/types/workspace/index.d.ts +1 -1
  1310. package/dist/types/workspace/index.d.ts.map +1 -1
  1311. package/dist/types/workspace/index.js +1 -1
  1312. package/dist/types/workspace/index.js.map +1 -1
  1313. package/dist/types/workspace/ref.d.ts +3 -3
  1314. package/dist/types/workspace/shared-session.d.ts +61 -0
  1315. package/dist/types/workspace/shared-session.d.ts.map +1 -0
  1316. package/dist/types/workspace/shared-session.js +2 -0
  1317. package/dist/types/workspace/shared-session.js.map +1 -0
  1318. package/dist/utils/abort.js +4 -4
  1319. package/dist/utils/abort.js.map +1 -1
  1320. package/dist/utils/atomic-write.d.ts +29 -1
  1321. package/dist/utils/atomic-write.d.ts.map +1 -1
  1322. package/dist/utils/atomic-write.js +60 -4
  1323. package/dist/utils/atomic-write.js.map +1 -1
  1324. package/dist/utils/cost.d.ts +3 -3
  1325. package/dist/utils/cost.d.ts.map +1 -1
  1326. package/dist/utils/cost.js +11 -12
  1327. package/dist/utils/cost.js.map +1 -1
  1328. package/dist/utils/env.d.ts +1 -1
  1329. package/dist/utils/env.js +1 -1
  1330. package/dist/utils/id.d.ts +9 -8
  1331. package/dist/utils/id.d.ts.map +1 -1
  1332. package/dist/utils/id.js +20 -13
  1333. package/dist/utils/id.js.map +1 -1
  1334. package/dist/utils/log/create-logger.js +1 -1
  1335. package/dist/utils/log/create-logger.js.map +1 -1
  1336. package/dist/utils/log/redact.js +1 -1
  1337. package/dist/utils/log/redact.js.map +1 -1
  1338. package/dist/utils/log/sinks.d.ts +1 -1
  1339. package/dist/utils/log/sinks.js +2 -2
  1340. package/dist/utils/log/sinks.js.map +1 -1
  1341. package/dist/utils/log/types.js +1 -1
  1342. package/dist/utils/log/types.js.map +1 -1
  1343. package/dist/utils/shell-compress.js +2 -2
  1344. package/dist/utils/shell-compress.js.map +1 -1
  1345. package/dist/utils/uuidv7.d.ts +33 -0
  1346. package/dist/utils/uuidv7.d.ts.map +1 -0
  1347. package/dist/utils/uuidv7.js +70 -0
  1348. package/dist/utils/uuidv7.js.map +1 -0
  1349. package/dist/vault/instrumentation.d.ts +5 -2
  1350. package/dist/vault/instrumentation.d.ts.map +1 -1
  1351. package/dist/vault/instrumentation.js +12 -6
  1352. package/dist/vault/instrumentation.js.map +1 -1
  1353. package/package.json +1 -1
  1354. package/src/advisory/budget.ts +3 -3
  1355. package/src/advisory/context.ts +9 -9
  1356. package/src/advisory/evaluator.ts +2 -2
  1357. package/src/advisory/parse.ts +1 -1
  1358. package/src/agents/AbstractAgent.ts +74 -50
  1359. package/src/agents/PipelineAgent.ts +91 -26
  1360. package/src/agents/ReactiveAgent.ts +35 -29
  1361. package/src/agents/RouterAgent.ts +32 -44
  1362. package/src/agents/SupervisorAgent.ts +55 -41
  1363. package/src/agents/budget.ts +73 -16
  1364. package/src/agents/defineAgent.ts +7 -3
  1365. package/src/agents/handle.ts +17 -19
  1366. package/src/agents/lock.ts +4 -4
  1367. package/src/agents/runAgent.ts +96 -38
  1368. package/src/agents/storage.ts +36 -0
  1369. package/src/authorization/command-line.ts +1 -1
  1370. package/src/authorization/gate.ts +1 -1
  1371. package/src/authorization/permission-presets.ts +4 -4
  1372. package/src/bridge/a2a/client.ts +2 -2
  1373. package/src/bridge/a2a/context.ts +46 -0
  1374. package/src/bridge/a2a/index.ts +12 -5
  1375. package/src/bridge/a2a/mapper.ts +48 -38
  1376. package/src/bridge/a2a/task.ts +91 -37
  1377. package/src/bridge/acp/permission.ts +2 -2
  1378. package/src/bridge/acp/server.ts +45 -11
  1379. package/src/bridge/acp/update.ts +9 -9
  1380. package/src/bridge/external-session.ts +82 -0
  1381. package/src/bridge/sse/index.ts +1 -1
  1382. package/src/bridge/sse/mapper.ts +117 -145
  1383. package/src/bus/breaker.ts +30 -29
  1384. package/src/bus/index.ts +7 -7
  1385. package/src/bus/lock.ts +7 -7
  1386. package/src/bus/ownership.ts +8 -8
  1387. package/src/compaction/consolidation.ts +61 -15
  1388. package/src/compaction/context-window.ts +4 -4
  1389. package/src/compaction/index.ts +2 -2
  1390. package/src/compaction/manager.ts +4 -4
  1391. package/src/compaction/manual.ts +5 -5
  1392. package/src/compaction/plan.ts +8 -8
  1393. package/src/compaction/reducer.ts +8 -8
  1394. package/src/compaction/retention.ts +2 -2
  1395. package/src/compaction/salience/bm25.ts +2 -2
  1396. package/src/compaction/salience/goal.ts +3 -3
  1397. package/src/compaction/salience/minhash.ts +1 -1
  1398. package/src/compaction/salience/score.ts +3 -3
  1399. package/src/compaction/salience/tokenize.ts +1 -1
  1400. package/src/compaction/verifier.ts +7 -7
  1401. package/src/compaction/wire.ts +1 -1
  1402. package/src/config/registry.ts +4 -4
  1403. package/src/config/runtime.ts +3 -3
  1404. package/src/connector/http-operation.ts +1 -1
  1405. package/src/connector/mcp/adapter.ts +1 -1
  1406. package/src/connector/mcp/client.ts +1 -1
  1407. package/src/connector/mcp/discovery.ts +2 -2
  1408. package/src/connector/mcp/policy.ts +1 -1
  1409. package/src/connector/mcp/prompt-adapter.ts +3 -3
  1410. package/src/constants/a2a/index.ts +10 -3
  1411. package/src/constants/continuation.ts +1 -1
  1412. package/src/constants/index.ts +0 -1
  1413. package/src/constants/limits.ts +2 -2
  1414. package/src/constants/telemetry/index.ts +15 -12
  1415. package/src/constants/tools/index.ts +2 -2
  1416. package/src/contracts/api.ts +11 -202
  1417. package/src/contracts/index.ts +8 -15
  1418. package/src/contracts/schemas.ts +6 -39
  1419. package/src/contracts/session/api.ts +150 -0
  1420. package/src/contracts/session/index.ts +29 -0
  1421. package/src/contracts/session/schemas.ts +60 -0
  1422. package/src/contracts/session/turn-status.ts +83 -0
  1423. package/src/contracts/session/turn.ts +67 -0
  1424. package/src/directory/derive-supervisor.ts +2 -2
  1425. package/src/directory/derive.ts +4 -4
  1426. package/src/directory/index.ts +2 -2
  1427. package/src/directory/load.ts +2 -2
  1428. package/src/directory/types.ts +2 -2
  1429. package/src/eval/experiment.ts +23 -23
  1430. package/src/eval/from-turn.ts +50 -0
  1431. package/src/eval/harness-verification.ts +7 -7
  1432. package/src/eval/index.ts +2 -2
  1433. package/src/eval/judge.ts +10 -10
  1434. package/src/eval/scorers.ts +23 -23
  1435. package/src/eval/types.ts +12 -12
  1436. package/src/eval/uncertainty.ts +2 -2
  1437. package/src/execution/code-runtime/types.ts +4 -4
  1438. package/src/execution/code-runtime/worker.ts +1 -1
  1439. package/src/invariants/index.ts +2 -2
  1440. package/src/manager/agent/child-session.ts +120 -0
  1441. package/src/manager/agent/lifecycle.ts +422 -102
  1442. package/src/manager/index.ts +1 -2
  1443. package/src/manager/plan/lifecycle.ts +16 -10
  1444. package/src/manager/resident/consumption.ts +8 -6
  1445. package/src/manager/resident/evidence-recall.ts +14 -14
  1446. package/src/manager/resident/host.ts +2 -2
  1447. package/src/manager/resident/learning-cycle.ts +5 -3
  1448. package/src/manager/resident/learning-observation.ts +9 -4
  1449. package/src/manager/resident/learning-store.ts +46 -16
  1450. package/src/manager/resident/tool-evidence.ts +38 -31
  1451. package/src/manager/session/turn-recorder.ts +1291 -0
  1452. package/src/plugin/lifecycle.ts +20 -13
  1453. package/src/plugin/shell-hook.ts +64 -25
  1454. package/src/pricing/index.ts +5 -5
  1455. package/src/pricing/rates.source.json +5 -5
  1456. package/src/probe/context.ts +5 -3
  1457. package/src/probe/registry.ts +1 -1
  1458. package/src/prompt/coding-agent-doctrine.ts +1 -1
  1459. package/src/prompt/contributions.ts +28 -6
  1460. package/src/prompt/resident-learning.ts +2 -2
  1461. package/src/provider/collect-chat-completion.ts +3 -3
  1462. package/src/provider/conformance.ts +8 -5
  1463. package/src/provider/errors.ts +2 -2
  1464. package/src/provider/fallback.ts +8 -8
  1465. package/src/provider/idle-timeout.ts +4 -4
  1466. package/src/provider/instrumentation.ts +14 -7
  1467. package/src/provider/mock.ts +1 -1
  1468. package/src/provider/retry.ts +7 -7
  1469. package/src/provider/stream-text.ts +1 -1
  1470. package/src/provider/thinking-support.ts +2 -2
  1471. package/src/provider/token-budget.ts +2 -2
  1472. package/src/public-runtime.ts +213 -141
  1473. package/src/public-tools.ts +14 -7
  1474. package/src/public-types.ts +71 -59
  1475. package/src/rag/embedding.ts +1 -1
  1476. package/src/read-model/index.ts +2 -2
  1477. package/src/read-model/registry.ts +11 -11
  1478. package/src/read-model/session-status.ts +87 -0
  1479. package/src/registry/command/kernel-commands.ts +10 -10
  1480. package/src/registry/tool/dialect.ts +1 -1
  1481. package/src/registry/tool/execute.ts +20 -7
  1482. package/src/registry/tool/portable.ts +1 -1
  1483. package/src/registry/tool/presentation.ts +1 -1
  1484. package/src/registry/tool/schema.ts +1 -1
  1485. package/src/registry/tool/screen.ts +3 -3
  1486. package/src/runtime/bidi/index.ts +2 -2
  1487. package/src/runtime/bidi/session.ts +45 -34
  1488. package/src/runtime/jobs/awaited-jobs.ts +13 -13
  1489. package/src/runtime/jobs/registry.ts +11 -11
  1490. package/src/runtime/query/abandon-turn.ts +110 -0
  1491. package/src/runtime/query/approval-policy.ts +13 -13
  1492. package/src/runtime/query/callback-inference.ts +8 -5
  1493. package/src/runtime/query/cancelled-before-start.ts +96 -79
  1494. package/src/runtime/query/checkpoint.ts +519 -420
  1495. package/src/runtime/query/compact-session.ts +92 -0
  1496. package/src/runtime/query/context.ts +80 -136
  1497. package/src/runtime/query/events.ts +160 -126
  1498. package/src/runtime/query/executor/tool-call-admission.ts +6 -5
  1499. package/src/runtime/query/executor.ts +206 -111
  1500. package/src/runtime/query/file-evidence-seed.ts +2 -2
  1501. package/src/runtime/query/finalize-turn.ts +209 -0
  1502. package/src/runtime/query/fork/list.ts +20 -0
  1503. package/src/runtime/query/fork/mutate.ts +82 -0
  1504. package/src/runtime/query/fork/prepare.ts +92 -0
  1505. package/src/runtime/query/guard.ts +22 -22
  1506. package/src/runtime/query/guardrail-presets.ts +12 -12
  1507. package/src/runtime/query/guardrails.ts +11 -11
  1508. package/src/runtime/query/index.ts +1624 -1533
  1509. package/src/runtime/query/iteration/index.ts +304 -253
  1510. package/src/runtime/query/iteration/outstanding-work.ts +65 -65
  1511. package/src/runtime/query/iteration/phases/advisory.ts +16 -16
  1512. package/src/runtime/query/iteration/phases/checkpoint.ts +26 -10
  1513. package/src/runtime/query/iteration/phases/compaction.ts +74 -72
  1514. package/src/runtime/query/iteration/phases/context.ts +59 -60
  1515. package/src/runtime/query/iteration/phases/plan.ts +9 -6
  1516. package/src/runtime/query/iteration/phases/tool-review.ts +153 -28
  1517. package/src/runtime/query/iteration/phases/working-memory.ts +57 -22
  1518. package/src/runtime/query/iteration/step-context.ts +17 -0
  1519. package/src/runtime/query/iteration/step-shaping.ts +21 -24
  1520. package/src/runtime/query/iteration/stream-turn.ts +36 -32
  1521. package/src/runtime/query/plugin-hooks.ts +1 -1
  1522. package/src/runtime/query/prepare-turn.ts +932 -0
  1523. package/src/runtime/query/project-instructions.ts +5 -4
  1524. package/src/runtime/query/prompt-cache.ts +1 -1
  1525. package/src/runtime/query/prompt.ts +5 -5
  1526. package/src/runtime/query/question-park.ts +7 -7
  1527. package/src/runtime/query/release-turn.ts +157 -0
  1528. package/src/runtime/query/repeat-call.ts +7 -7
  1529. package/src/runtime/query/result.ts +123 -131
  1530. package/src/runtime/query/resume-pending.ts +101 -44
  1531. package/src/runtime/query/resume-session.ts +153 -0
  1532. package/src/runtime/query/review-policy.ts +147 -19
  1533. package/src/runtime/query/sandbox-lifecycle.ts +5 -5
  1534. package/src/runtime/query/session-storage.ts +302 -0
  1535. package/src/runtime/query/steering.ts +17 -4
  1536. package/src/runtime/query/token-budget.ts +59 -93
  1537. package/src/runtime/query/tool-call-budget.ts +14 -14
  1538. package/src/runtime/query/tool-executions.ts +77 -0
  1539. package/src/runtime/query/tool-grants.ts +3 -3
  1540. package/src/runtime/query/tool-output-budget.ts +4 -4
  1541. package/src/runtime/query/tool-pause.ts +8 -6
  1542. package/src/runtime/query/tooling.ts +22 -14
  1543. package/src/runtime/query/turn-state.ts +153 -0
  1544. package/src/sandbox/isolation.ts +2 -2
  1545. package/src/sandbox/provider/local.ts +8 -8
  1546. package/src/scheduler/completion-inbox.ts +36 -36
  1547. package/src/scheduler/delegating.ts +27 -13
  1548. package/src/scheduler/local.ts +49 -21
  1549. package/src/session/events/index.ts +10 -14
  1550. package/src/session/handoff/broadcast.ts +7 -7
  1551. package/src/session/handoff/events.ts +1 -1
  1552. package/src/session/handoff/index.ts +1 -1
  1553. package/src/session/handoff/single.ts +21 -21
  1554. package/src/session/handoff/version.ts +11 -7
  1555. package/src/session/home.ts +66 -0
  1556. package/src/session/index.ts +1 -0
  1557. package/src/session/log-hash.ts +115 -0
  1558. package/src/session/messages.ts +39 -0
  1559. package/src/session/paths.ts +449 -0
  1560. package/src/session/retention/archive.ts +13 -5
  1561. package/src/session/status/derive.ts +21 -21
  1562. package/src/session/workspace/git-worktree.ts +31 -2
  1563. package/src/session/workspace/index.ts +5 -8
  1564. package/src/session/workspace/shared-session.ts +354 -0
  1565. package/src/session-query/index.ts +152 -0
  1566. package/src/skills/registry.ts +1 -1
  1567. package/src/store/activity/memory.ts +5 -5
  1568. package/src/store/attachment/index.ts +5 -5
  1569. package/src/store/budget/disk.ts +243 -0
  1570. package/src/store/budget/index.ts +24 -0
  1571. package/src/store/budget/ledger.ts +836 -0
  1572. package/src/store/budget/memory.ts +39 -0
  1573. package/src/store/checkpoint/contract.ts +225 -0
  1574. package/src/store/checkpoint/disk.ts +209 -0
  1575. package/src/store/checkpoint/index.ts +22 -0
  1576. package/src/store/checkpoint/memory.ts +112 -0
  1577. package/src/store/checkpoint/prune.ts +93 -0
  1578. package/src/store/config/index.ts +1 -1
  1579. package/src/store/evidence/disk.ts +185 -81
  1580. package/src/store/evidence/index-page.ts +67 -140
  1581. package/src/store/evidence/source-text.ts +23 -28
  1582. package/src/store/evidence/types.ts +51 -41
  1583. package/src/store/feedback/conformance.ts +37 -35
  1584. package/src/store/feedback/disk.ts +61 -63
  1585. package/src/store/feedback/index.ts +1 -1
  1586. package/src/store/feedback/memory.ts +0 -0
  1587. package/src/store/feedback/types.ts +14 -13
  1588. package/src/store/index.ts +24 -28
  1589. package/src/store/memory/digest.ts +35 -0
  1590. package/src/store/memory/disk.ts +66 -20
  1591. package/src/store/memory/index-file.ts +121 -0
  1592. package/src/store/memory/index.ts +4 -2
  1593. package/src/store/memory/links.ts +37 -0
  1594. package/src/store/memory/markdown-format.ts +276 -0
  1595. package/src/store/memory/markdown.ts +741 -0
  1596. package/src/store/memory/memory.ts +39 -17
  1597. package/src/store/memory/naming.ts +195 -0
  1598. package/src/store/memory/origin.ts +35 -0
  1599. package/src/store/session/disk.ts +27 -200
  1600. package/src/store/session/index.ts +5 -9
  1601. package/src/store/session/memory.ts +1 -78
  1602. package/src/store/session-claim.ts +101 -0
  1603. package/src/store/session-index/fts.ts +215 -0
  1604. package/src/store/session-index/index.ts +253 -0
  1605. package/src/store/session-index/rebuild.ts +869 -0
  1606. package/src/store/session-index/refs.ts +164 -0
  1607. package/src/store/session-index/scan.ts +273 -0
  1608. package/src/store/session-index/sqlite.ts +772 -0
  1609. package/src/store/session-log/chain.ts +314 -0
  1610. package/src/store/session-log/conformance.ts +487 -0
  1611. package/src/store/session-log/core.ts +809 -0
  1612. package/src/store/session-log/disk.ts +217 -0
  1613. package/src/store/session-log/fold.ts +368 -0
  1614. package/src/store/session-log/heal.ts +44 -0
  1615. package/src/store/session-log/held-leases.ts +103 -0
  1616. package/src/store/session-log/index.ts +87 -0
  1617. package/src/store/session-log/lease.ts +354 -0
  1618. package/src/store/session-log/memory.ts +111 -0
  1619. package/src/store/session-log/spill.ts +311 -0
  1620. package/src/store/task/context.ts +33 -0
  1621. package/src/store/task/disk.ts +122 -141
  1622. package/src/store/task/memory.ts +14 -8
  1623. package/src/store/topic/index.ts +2 -2
  1624. package/src/store/topic/objective.ts +12 -3
  1625. package/src/store/topic/state.ts +1 -1
  1626. package/src/streaming/coalesce.ts +8 -7
  1627. package/src/telemetry/attributes.ts +10 -9
  1628. package/src/telemetry/metrics.ts +6 -6
  1629. package/src/telemetry/runtime-accessors.ts +1 -1
  1630. package/src/test-support/ids.ts +5 -6
  1631. package/src/testing.ts +11 -16
  1632. package/src/tools/advisory/index.ts +1 -1
  1633. package/src/tools/builtins/bash.ts +43 -5
  1634. package/src/tools/builtins/content-fingerprint.ts +2 -2
  1635. package/src/tools/builtins/edit-apply.ts +1 -1
  1636. package/src/tools/builtins/edit.ts +3 -0
  1637. package/src/tools/builtins/glob.ts +3 -0
  1638. package/src/tools/builtins/grep.ts +3 -0
  1639. package/src/tools/builtins/job.ts +5 -5
  1640. package/src/tools/builtins/ls.ts +3 -0
  1641. package/src/tools/builtins/lsp.ts +5 -2
  1642. package/src/tools/builtins/read-file.ts +3 -0
  1643. package/src/tools/builtins/run-code.ts +11 -11
  1644. package/src/tools/builtins/skill.ts +3 -3
  1645. package/src/tools/builtins/wait-for-job-bounds.ts +6 -6
  1646. package/src/tools/builtins/wait-for-job.ts +3 -3
  1647. package/src/tools/builtins/web-guidance.ts +2 -2
  1648. package/src/tools/builtins/web.ts +3 -3
  1649. package/src/tools/builtins/write-file.ts +3 -0
  1650. package/src/tools/coordinator/agent.ts +8 -8
  1651. package/src/tools/coordinator/ask-user-question.ts +16 -14
  1652. package/src/tools/coordinator/index.ts +64 -54
  1653. package/src/tools/coordinator/outcome.ts +7 -7
  1654. package/src/tools/coordinator/plan-dependencies.ts +1 -1
  1655. package/src/tools/coordinator/wait-with-idle-bound.ts +6 -6
  1656. package/src/tools/defineTool.ts +9 -1
  1657. package/src/tools/env-scrub.ts +1 -1
  1658. package/src/tools/goal/index.ts +16 -12
  1659. package/src/tools/memory/fields.ts +26 -0
  1660. package/src/tools/memory/read.ts +75 -8
  1661. package/src/tools/memory/resolve.ts +37 -0
  1662. package/src/tools/memory/save.ts +54 -18
  1663. package/src/tools/memory/search.ts +9 -5
  1664. package/src/tools/memory/update.ts +43 -7
  1665. package/src/tools/paths.ts +87 -27
  1666. package/src/tools/posix-path.ts +1 -1
  1667. package/src/tools/resident-history.ts +1 -1
  1668. package/src/tools/resident-tool-evidence.ts +1 -1
  1669. package/src/tools/task/create.ts +11 -4
  1670. package/src/tools/task/index.ts +20 -4
  1671. package/src/tools/task/list.ts +16 -7
  1672. package/src/tools/task/present.ts +102 -0
  1673. package/src/tools/task/update.ts +9 -1
  1674. package/src/turn/LimitChecker.ts +99 -0
  1675. package/src/turn/command-gate.ts +294 -0
  1676. package/src/turn/drain.ts +324 -0
  1677. package/src/turn/evidence-query.ts +333 -0
  1678. package/src/turn/evidence-recall.ts +860 -0
  1679. package/src/turn/index.ts +38 -0
  1680. package/src/turn/json-claim-verifier.ts +298 -0
  1681. package/src/turn/memory-promoter.ts +160 -0
  1682. package/src/turn/memory-recall.ts +285 -0
  1683. package/src/turn/reporter.ts +469 -0
  1684. package/src/types/activity/index.ts +2 -2
  1685. package/src/types/advisory/config.ts +7 -7
  1686. package/src/types/agent/base.ts +74 -44
  1687. package/src/types/agent/core.ts +10 -10
  1688. package/src/types/agent/delegate.ts +2 -2
  1689. package/src/types/agent/factory.ts +8 -4
  1690. package/src/types/agent/manager.ts +6 -6
  1691. package/src/types/agent/pipeline.ts +5 -4
  1692. package/src/types/agent/reactive.ts +11 -10
  1693. package/src/types/agent/router.ts +1 -1
  1694. package/src/types/agent/scheduler.ts +28 -11
  1695. package/src/types/agent/supervisor.ts +13 -13
  1696. package/src/types/agent/task.ts +53 -12
  1697. package/src/types/agent/working-memory.ts +6 -4
  1698. package/src/types/bidi/index.ts +31 -12
  1699. package/src/types/bus/index.ts +32 -26
  1700. package/src/types/code-navigation/index.ts +1 -1
  1701. package/src/types/common/index.ts +12 -26
  1702. package/src/types/connector/core.ts +2 -2
  1703. package/src/types/connector/definition.ts +1 -1
  1704. package/src/types/connector/mcp.ts +1 -1
  1705. package/src/types/errors/catalog.ts +4 -4
  1706. package/src/types/errors/index.ts +5 -5
  1707. package/src/types/guardrail/index.ts +12 -10
  1708. package/src/types/hitl/index.ts +81 -125
  1709. package/src/types/hitl/policy.ts +8 -6
  1710. package/src/types/ids/brand.ts +10 -2
  1711. package/src/types/ids/index.ts +10 -4
  1712. package/src/types/memory/index.ts +53 -0
  1713. package/src/types/message/index.ts +4 -4
  1714. package/src/types/plan/index.ts +5 -3
  1715. package/src/types/plugin/index.ts +41 -24
  1716. package/src/types/probe/event-kind.ts +3 -3
  1717. package/src/types/probe/registry.ts +3 -2
  1718. package/src/types/project/entity.ts +3 -3
  1719. package/src/types/provider/config.ts +3 -3
  1720. package/src/types/provider/error.ts +1 -1
  1721. package/src/types/provider/errors.ts +3 -3
  1722. package/src/types/provider/interface.ts +5 -5
  1723. package/src/types/router/task-router.ts +1 -1
  1724. package/src/types/sandbox/index.ts +12 -12
  1725. package/src/types/session/answer-review.ts +85 -0
  1726. package/src/types/session/audit.ts +167 -0
  1727. package/src/types/session/cancel-cause.ts +60 -0
  1728. package/src/types/session/checkpoint.ts +167 -0
  1729. package/src/types/session/config.ts +212 -0
  1730. package/src/types/session/derive-status.ts +61 -0
  1731. package/src/types/session/durable.ts +150 -0
  1732. package/src/types/session/entity.ts +1 -1
  1733. package/src/types/session/events.ts +1195 -0
  1734. package/src/types/session/fork.ts +52 -0
  1735. package/src/types/session/ids.ts +1 -1
  1736. package/src/types/session/index.ts +24 -4
  1737. package/src/types/session/lineage.ts +15 -0
  1738. package/src/types/session/log-cursor.ts +69 -0
  1739. package/src/types/session/memory-promotion.ts +116 -0
  1740. package/src/types/session/messages.ts +1 -1
  1741. package/src/types/session/prepare-step.ts +299 -0
  1742. package/src/types/session/records.ts +931 -0
  1743. package/src/types/session/step.ts +214 -0
  1744. package/src/types/session/stop-reason.ts +83 -0
  1745. package/src/types/session/store.ts +5 -52
  1746. package/src/types/session/tool-execution.ts +32 -0
  1747. package/src/types/session/turn-state.ts +136 -0
  1748. package/src/types/session/turn.ts +289 -0
  1749. package/src/types/structured-output/index.ts +4 -4
  1750. package/src/types/summary/deliverable.ts +4 -4
  1751. package/src/types/task/index.ts +8 -4
  1752. package/src/types/tool/index.ts +74 -27
  1753. package/src/types/topic/entity.ts +6 -6
  1754. package/src/types/topic/objective.ts +7 -5
  1755. package/src/types/topic/state.ts +4 -4
  1756. package/src/types/topic/store.ts +1 -1
  1757. package/src/types/workspace/index.ts +8 -8
  1758. package/src/types/workspace/ref.ts +3 -3
  1759. package/src/types/workspace/shared-session.ts +65 -0
  1760. package/src/utils/abort.ts +4 -4
  1761. package/src/utils/atomic-write.ts +67 -4
  1762. package/src/utils/cost.ts +11 -12
  1763. package/src/utils/env.ts +1 -1
  1764. package/src/utils/id.ts +25 -18
  1765. package/src/utils/log/attributes.ts +2 -2
  1766. package/src/utils/log/create-logger.ts +1 -1
  1767. package/src/utils/log/redact.ts +1 -1
  1768. package/src/utils/log/sinks.ts +2 -2
  1769. package/src/utils/log/types.ts +1 -1
  1770. package/src/utils/shell-compress.ts +2 -2
  1771. package/src/utils/uuidv7.ts +107 -0
  1772. package/src/vault/instrumentation.ts +21 -8
  1773. package/dist/constants/emergency.d.ts +0 -4
  1774. package/dist/constants/emergency.d.ts.map +0 -1
  1775. package/dist/constants/emergency.js +0 -4
  1776. package/dist/constants/emergency.js.map +0 -1
  1777. package/dist/contracts/run-status.d.ts +0 -17
  1778. package/dist/contracts/run-status.d.ts.map +0 -1
  1779. package/dist/contracts/run-status.js +0 -41
  1780. package/dist/contracts/run-status.js.map +0 -1
  1781. package/dist/eval/from-run.d.ts +0 -30
  1782. package/dist/eval/from-run.d.ts.map +0 -1
  1783. package/dist/eval/from-run.js +0 -46
  1784. package/dist/eval/from-run.js.map +0 -1
  1785. package/dist/manager/run/emergency.d.ts +0 -19
  1786. package/dist/manager/run/emergency.d.ts.map +0 -1
  1787. package/dist/manager/run/emergency.js +0 -122
  1788. package/dist/manager/run/emergency.js.map +0 -1
  1789. package/dist/manager/run/persistence.d.ts +0 -312
  1790. package/dist/manager/run/persistence.d.ts.map +0 -1
  1791. package/dist/manager/run/persistence.js +0 -656
  1792. package/dist/manager/run/persistence.js.map +0 -1
  1793. package/dist/read-model/run-status.d.ts +0 -43
  1794. package/dist/read-model/run-status.d.ts.map +0 -1
  1795. package/dist/read-model/run-status.js +0 -89
  1796. package/dist/read-model/run-status.js.map +0 -1
  1797. package/dist/run/LimitChecker.d.ts +0 -30
  1798. package/dist/run/LimitChecker.d.ts.map +0 -1
  1799. package/dist/run/LimitChecker.js +0 -57
  1800. package/dist/run/LimitChecker.js.map +0 -1
  1801. package/dist/run/command-gate.d.ts +0 -107
  1802. package/dist/run/command-gate.d.ts.map +0 -1
  1803. package/dist/run/command-gate.js +0 -221
  1804. package/dist/run/command-gate.js.map +0 -1
  1805. package/dist/run/drain.d.ts +0 -204
  1806. package/dist/run/drain.d.ts.map +0 -1
  1807. package/dist/run/drain.js +0 -238
  1808. package/dist/run/drain.js.map +0 -1
  1809. package/dist/run/evidence-query.d.ts +0 -41
  1810. package/dist/run/evidence-query.d.ts.map +0 -1
  1811. package/dist/run/evidence-query.js +0 -270
  1812. package/dist/run/evidence-query.js.map +0 -1
  1813. package/dist/run/evidence-recall.d.ts +0 -99
  1814. package/dist/run/evidence-recall.d.ts.map +0 -1
  1815. package/dist/run/evidence-recall.js +0 -633
  1816. package/dist/run/evidence-recall.js.map +0 -1
  1817. package/dist/run/index.d.ts +0 -19
  1818. package/dist/run/index.d.ts.map +0 -1
  1819. package/dist/run/index.js +0 -11
  1820. package/dist/run/index.js.map +0 -1
  1821. package/dist/run/json-claim-verifier.d.ts +0 -83
  1822. package/dist/run/json-claim-verifier.d.ts.map +0 -1
  1823. package/dist/run/json-claim-verifier.js +0 -200
  1824. package/dist/run/json-claim-verifier.js.map +0 -1
  1825. package/dist/run/memory-promoter.d.ts +0 -38
  1826. package/dist/run/memory-promoter.d.ts.map +0 -1
  1827. package/dist/run/memory-promoter.js +0 -109
  1828. package/dist/run/memory-promoter.js.map +0 -1
  1829. package/dist/run/memory-recall.d.ts +0 -25
  1830. package/dist/run/memory-recall.d.ts.map +0 -1
  1831. package/dist/run/memory-recall.js +0 -228
  1832. package/dist/run/memory-recall.js.map +0 -1
  1833. package/dist/run/preparation-context-error.d.ts.map +0 -1
  1834. package/dist/run/preparation-context-error.js.map +0 -1
  1835. package/dist/run/reporter.d.ts +0 -8
  1836. package/dist/run/reporter.d.ts.map +0 -1
  1837. package/dist/run/reporter.js +0 -420
  1838. package/dist/run/reporter.js.map +0 -1
  1839. package/dist/run/token-budget.d.ts +0 -116
  1840. package/dist/run/token-budget.d.ts.map +0 -1
  1841. package/dist/run/token-budget.js +0 -626
  1842. package/dist/run/token-budget.js.map +0 -1
  1843. package/dist/run/workspace-fingerprint.d.ts.map +0 -1
  1844. package/dist/run/workspace-fingerprint.js.map +0 -1
  1845. package/dist/run-query/index.d.ts +0 -90
  1846. package/dist/run-query/index.d.ts.map +0 -1
  1847. package/dist/run-query/index.js +0 -127
  1848. package/dist/run-query/index.js.map +0 -1
  1849. package/dist/runtime/query/finalize-run.d.ts +0 -55
  1850. package/dist/runtime/query/finalize-run.d.ts.map +0 -1
  1851. package/dist/runtime/query/finalize-run.js +0 -113
  1852. package/dist/runtime/query/finalize-run.js.map +0 -1
  1853. package/dist/runtime/query/prepare-run.d.ts +0 -94
  1854. package/dist/runtime/query/prepare-run.d.ts.map +0 -1
  1855. package/dist/runtime/query/prepare-run.js +0 -589
  1856. package/dist/runtime/query/prepare-run.js.map +0 -1
  1857. package/dist/runtime/query/release-run.d.ts +0 -56
  1858. package/dist/runtime/query/release-run.d.ts.map +0 -1
  1859. package/dist/runtime/query/release-run.js +0 -101
  1860. package/dist/runtime/query/release-run.js.map +0 -1
  1861. package/dist/runtime/query/replay/list.d.ts +0 -40
  1862. package/dist/runtime/query/replay/list.d.ts.map +0 -1
  1863. package/dist/runtime/query/replay/list.js +0 -38
  1864. package/dist/runtime/query/replay/list.js.map +0 -1
  1865. package/dist/runtime/query/replay/mutate.d.ts +0 -17
  1866. package/dist/runtime/query/replay/mutate.d.ts.map +0 -1
  1867. package/dist/runtime/query/replay/mutate.js +0 -69
  1868. package/dist/runtime/query/replay/mutate.js.map +0 -1
  1869. package/dist/runtime/query/replay/prepare.d.ts +0 -66
  1870. package/dist/runtime/query/replay/prepare.d.ts.map +0 -1
  1871. package/dist/runtime/query/replay/prepare.js +0 -81
  1872. package/dist/runtime/query/replay/prepare.js.map +0 -1
  1873. package/dist/runtime/query/resume-run.d.ts +0 -103
  1874. package/dist/runtime/query/resume-run.d.ts.map +0 -1
  1875. package/dist/runtime/query/resume-run.js +0 -105
  1876. package/dist/runtime/query/resume-run.js.map +0 -1
  1877. package/dist/runtime/query/run-state.d.ts +0 -57
  1878. package/dist/runtime/query/run-state.d.ts.map +0 -1
  1879. package/dist/runtime/query/run-state.js +0 -96
  1880. package/dist/runtime/query/run-state.js.map +0 -1
  1881. package/dist/session/workspace/path-builder.d.ts +0 -50
  1882. package/dist/session/workspace/path-builder.d.ts.map +0 -1
  1883. package/dist/session/workspace/path-builder.js +0 -51
  1884. package/dist/session/workspace/path-builder.js.map +0 -1
  1885. package/dist/session/workspace/shared-run.d.ts +0 -112
  1886. package/dist/session/workspace/shared-run.d.ts.map +0 -1
  1887. package/dist/session/workspace/shared-run.js +0 -290
  1888. package/dist/session/workspace/shared-run.js.map +0 -1
  1889. package/dist/store/evidence/compaction-archive.d.ts +0 -109
  1890. package/dist/store/evidence/compaction-archive.d.ts.map +0 -1
  1891. package/dist/store/evidence/compaction-archive.js +0 -125
  1892. package/dist/store/evidence/compaction-archive.js.map +0 -1
  1893. package/dist/store/evidence/linked.d.ts +0 -9
  1894. package/dist/store/evidence/linked.d.ts.map +0 -1
  1895. package/dist/store/evidence/linked.js +0 -314
  1896. package/dist/store/evidence/linked.js.map +0 -1
  1897. package/dist/store/evidence/record-chain.d.ts +0 -42
  1898. package/dist/store/evidence/record-chain.d.ts.map +0 -1
  1899. package/dist/store/evidence/record-chain.js +0 -111
  1900. package/dist/store/evidence/record-chain.js.map +0 -1
  1901. package/dist/store/run/checkpoint-disk.d.ts +0 -98
  1902. package/dist/store/run/checkpoint-disk.d.ts.map +0 -1
  1903. package/dist/store/run/checkpoint-disk.js +0 -190
  1904. package/dist/store/run/checkpoint-disk.js.map +0 -1
  1905. package/dist/store/run/checkpoint-memory.d.ts +0 -51
  1906. package/dist/store/run/checkpoint-memory.d.ts.map +0 -1
  1907. package/dist/store/run/checkpoint-memory.js +0 -178
  1908. package/dist/store/run/checkpoint-memory.js.map +0 -1
  1909. package/dist/store/run/claim-disk.d.ts +0 -130
  1910. package/dist/store/run/claim-disk.d.ts.map +0 -1
  1911. package/dist/store/run/claim-disk.js +0 -570
  1912. package/dist/store/run/claim-disk.js.map +0 -1
  1913. package/dist/store/run/conformance.d.ts +0 -159
  1914. package/dist/store/run/conformance.d.ts.map +0 -1
  1915. package/dist/store/run/conformance.js +0 -466
  1916. package/dist/store/run/conformance.js.map +0 -1
  1917. package/dist/store/run/disk.d.ts +0 -189
  1918. package/dist/store/run/disk.d.ts.map +0 -1
  1919. package/dist/store/run/disk.js +0 -804
  1920. package/dist/store/run/disk.js.map +0 -1
  1921. package/dist/store/run/listing.d.ts +0 -118
  1922. package/dist/store/run/listing.d.ts.map +0 -1
  1923. package/dist/store/run/listing.js +0 -333
  1924. package/dist/store/run/listing.js.map +0 -1
  1925. package/dist/store/run/memory.d.ts +0 -55
  1926. package/dist/store/run/memory.d.ts.map +0 -1
  1927. package/dist/store/run/memory.js +0 -176
  1928. package/dist/store/run/memory.js.map +0 -1
  1929. package/dist/store/run/token-budget-disk.d.ts +0 -37
  1930. package/dist/store/run/token-budget-disk.d.ts.map +0 -1
  1931. package/dist/store/run/token-budget-disk.js +0 -211
  1932. package/dist/store/run/token-budget-disk.js.map +0 -1
  1933. package/dist/store/run/tool-executions.d.ts +0 -13
  1934. package/dist/store/run/tool-executions.d.ts.map +0 -1
  1935. package/dist/store/run/tool-executions.js +0 -99
  1936. package/dist/store/run/tool-executions.js.map +0 -1
  1937. package/dist/store/session/sqlite.d.ts +0 -57
  1938. package/dist/store/session/sqlite.d.ts.map +0 -1
  1939. package/dist/store/session/sqlite.js +0 -430
  1940. package/dist/store/session/sqlite.js.map +0 -1
  1941. package/dist/types/run/answer-review.d.ts +0 -79
  1942. package/dist/types/run/answer-review.d.ts.map +0 -1
  1943. package/dist/types/run/answer-review.js.map +0 -1
  1944. package/dist/types/run/audit.d.ts +0 -150
  1945. package/dist/types/run/audit.d.ts.map +0 -1
  1946. package/dist/types/run/audit.js +0 -39
  1947. package/dist/types/run/audit.js.map +0 -1
  1948. package/dist/types/run/cancel-cause.d.ts +0 -49
  1949. package/dist/types/run/cancel-cause.d.ts.map +0 -1
  1950. package/dist/types/run/cancel-cause.js +0 -39
  1951. package/dist/types/run/cancel-cause.js.map +0 -1
  1952. package/dist/types/run/checkpoint-store.d.ts +0 -511
  1953. package/dist/types/run/checkpoint-store.d.ts.map +0 -1
  1954. package/dist/types/run/checkpoint-store.js +0 -12
  1955. package/dist/types/run/checkpoint-store.js.map +0 -1
  1956. package/dist/types/run/config.d.ts +0 -207
  1957. package/dist/types/run/config.d.ts.map +0 -1
  1958. package/dist/types/run/config.js.map +0 -1
  1959. package/dist/types/run/derive-status.d.ts +0 -29
  1960. package/dist/types/run/derive-status.d.ts.map +0 -1
  1961. package/dist/types/run/derive-status.js +0 -49
  1962. package/dist/types/run/derive-status.js.map +0 -1
  1963. package/dist/types/run/emergency.d.ts +0 -32
  1964. package/dist/types/run/emergency.d.ts.map +0 -1
  1965. package/dist/types/run/emergency.js +0 -6
  1966. package/dist/types/run/emergency.js.map +0 -1
  1967. package/dist/types/run/entity.d.ts +0 -151
  1968. package/dist/types/run/entity.d.ts.map +0 -1
  1969. package/dist/types/run/entity.js +0 -2
  1970. package/dist/types/run/entity.js.map +0 -1
  1971. package/dist/types/run/event-cursor.d.ts +0 -90
  1972. package/dist/types/run/event-cursor.d.ts.map +0 -1
  1973. package/dist/types/run/event-cursor.js +0 -47
  1974. package/dist/types/run/event-cursor.js.map +0 -1
  1975. package/dist/types/run/events.d.ts +0 -1064
  1976. package/dist/types/run/events.d.ts.map +0 -1
  1977. package/dist/types/run/events.js +0 -31
  1978. package/dist/types/run/events.js.map +0 -1
  1979. package/dist/types/run/index.d.ts +0 -24
  1980. package/dist/types/run/index.d.ts.map +0 -1
  1981. package/dist/types/run/index.js +0 -23
  1982. package/dist/types/run/index.js.map +0 -1
  1983. package/dist/types/run/lineage.d.ts +0 -15
  1984. package/dist/types/run/lineage.d.ts.map +0 -1
  1985. package/dist/types/run/lineage.js.map +0 -1
  1986. package/dist/types/run/memory-promotion.d.ts +0 -90
  1987. package/dist/types/run/memory-promotion.d.ts.map +0 -1
  1988. package/dist/types/run/memory-promotion.js +0 -38
  1989. package/dist/types/run/memory-promotion.js.map +0 -1
  1990. package/dist/types/run/metadata.d.ts +0 -47
  1991. package/dist/types/run/metadata.d.ts.map +0 -1
  1992. package/dist/types/run/metadata.js +0 -2
  1993. package/dist/types/run/metadata.js.map +0 -1
  1994. package/dist/types/run/prepare-step.d.ts +0 -271
  1995. package/dist/types/run/prepare-step.d.ts.map +0 -1
  1996. package/dist/types/run/prepare-step.js.map +0 -1
  1997. package/dist/types/run/replay.d.ts +0 -53
  1998. package/dist/types/run/replay.d.ts.map +0 -1
  1999. package/dist/types/run/replay.js +0 -15
  2000. package/dist/types/run/replay.js.map +0 -1
  2001. package/dist/types/run/schema-version.d.ts +0 -19
  2002. package/dist/types/run/schema-version.d.ts.map +0 -1
  2003. package/dist/types/run/schema-version.js +0 -18
  2004. package/dist/types/run/schema-version.js.map +0 -1
  2005. package/dist/types/run/state.d.ts +0 -109
  2006. package/dist/types/run/state.d.ts.map +0 -1
  2007. package/dist/types/run/state.js +0 -109
  2008. package/dist/types/run/state.js.map +0 -1
  2009. package/dist/types/run/status.d.ts +0 -26
  2010. package/dist/types/run/status.d.ts.map +0 -1
  2011. package/dist/types/run/status.js +0 -2
  2012. package/dist/types/run/status.js.map +0 -1
  2013. package/dist/types/run/step.d.ts +0 -198
  2014. package/dist/types/run/step.d.ts.map +0 -1
  2015. package/dist/types/run/step.js +0 -26
  2016. package/dist/types/run/step.js.map +0 -1
  2017. package/dist/types/run/stop-reason.d.ts +0 -67
  2018. package/dist/types/run/stop-reason.d.ts.map +0 -1
  2019. package/dist/types/run/stop-reason.js.map +0 -1
  2020. package/dist/types/run/store.d.ts +0 -300
  2021. package/dist/types/run/store.d.ts.map +0 -1
  2022. package/dist/types/run/store.js +0 -2
  2023. package/dist/types/run/store.js.map +0 -1
  2024. package/dist/types/run/subsession-events.d.ts +0 -64
  2025. package/dist/types/run/subsession-events.d.ts.map +0 -1
  2026. package/dist/types/run/subsession-events.js +0 -2
  2027. package/dist/types/run/subsession-events.js.map +0 -1
  2028. package/dist/types/run/token-budget-store.d.ts +0 -29
  2029. package/dist/types/run/token-budget-store.d.ts.map +0 -1
  2030. package/dist/types/run/token-budget-store.js +0 -25
  2031. package/dist/types/run/token-budget-store.js.map +0 -1
  2032. package/dist/types/workspace/shared-run.d.ts +0 -61
  2033. package/dist/types/workspace/shared-run.d.ts.map +0 -1
  2034. package/dist/types/workspace/shared-run.js +0 -2
  2035. package/dist/types/workspace/shared-run.js.map +0 -1
  2036. package/src/constants/emergency.ts +0 -3
  2037. package/src/contracts/run-status.ts +0 -43
  2038. package/src/eval/from-run.ts +0 -48
  2039. package/src/manager/run/emergency.ts +0 -148
  2040. package/src/manager/run/persistence.ts +0 -746
  2041. package/src/read-model/run-status.ts +0 -127
  2042. package/src/run/LimitChecker.ts +0 -99
  2043. package/src/run/command-gate.ts +0 -294
  2044. package/src/run/drain.ts +0 -403
  2045. package/src/run/evidence-query.ts +0 -333
  2046. package/src/run/evidence-recall.ts +0 -854
  2047. package/src/run/index.ts +0 -42
  2048. package/src/run/json-claim-verifier.ts +0 -298
  2049. package/src/run/memory-promoter.ts +0 -147
  2050. package/src/run/memory-recall.ts +0 -254
  2051. package/src/run/reporter.ts +0 -469
  2052. package/src/run/token-budget.ts +0 -733
  2053. package/src/run-query/index.ts +0 -177
  2054. package/src/runtime/query/finalize-run.ts +0 -192
  2055. package/src/runtime/query/prepare-run.ts +0 -718
  2056. package/src/runtime/query/release-run.ts +0 -168
  2057. package/src/runtime/query/replay/list.ts +0 -66
  2058. package/src/runtime/query/replay/mutate.ts +0 -82
  2059. package/src/runtime/query/replay/prepare.ts +0 -147
  2060. package/src/runtime/query/resume-run.ts +0 -202
  2061. package/src/runtime/query/run-state.ts +0 -138
  2062. package/src/session/workspace/path-builder.ts +0 -72
  2063. package/src/session/workspace/shared-run.ts +0 -354
  2064. package/src/store/evidence/compaction-archive.ts +0 -139
  2065. package/src/store/evidence/linked.ts +0 -365
  2066. package/src/store/evidence/record-chain.ts +0 -108
  2067. package/src/store/run/checkpoint-disk.ts +0 -264
  2068. package/src/store/run/checkpoint-memory.ts +0 -216
  2069. package/src/store/run/claim-disk.ts +0 -638
  2070. package/src/store/run/conformance.ts +0 -728
  2071. package/src/store/run/disk.ts +0 -911
  2072. package/src/store/run/listing.ts +0 -422
  2073. package/src/store/run/memory.ts +0 -204
  2074. package/src/store/run/token-budget-disk.ts +0 -250
  2075. package/src/store/run/tool-executions.ts +0 -112
  2076. package/src/store/session/sqlite.ts +0 -584
  2077. package/src/types/run/answer-review.ts +0 -84
  2078. package/src/types/run/audit.ts +0 -164
  2079. package/src/types/run/cancel-cause.ts +0 -60
  2080. package/src/types/run/checkpoint-store.ts +0 -545
  2081. package/src/types/run/config.ts +0 -221
  2082. package/src/types/run/derive-status.ts +0 -62
  2083. package/src/types/run/emergency.ts +0 -28
  2084. package/src/types/run/entity.ts +0 -161
  2085. package/src/types/run/event-cursor.ts +0 -118
  2086. package/src/types/run/events.ts +0 -1146
  2087. package/src/types/run/index.ts +0 -32
  2088. package/src/types/run/lineage.ts +0 -15
  2089. package/src/types/run/memory-promotion.ts +0 -112
  2090. package/src/types/run/metadata.ts +0 -51
  2091. package/src/types/run/prepare-step.ts +0 -292
  2092. package/src/types/run/replay.ts +0 -61
  2093. package/src/types/run/schema-version.ts +0 -19
  2094. package/src/types/run/state.ts +0 -206
  2095. package/src/types/run/status.ts +0 -33
  2096. package/src/types/run/step.ts +0 -217
  2097. package/src/types/run/stop-reason.ts +0 -83
  2098. package/src/types/run/store.ts +0 -325
  2099. package/src/types/run/subsession-events.ts +0 -71
  2100. package/src/types/run/token-budget-store.ts +0 -54
  2101. package/src/types/workspace/shared-run.ts +0 -65
  2102. /package/dist/{run → turn}/preparation-context-error.d.ts +0 -0
  2103. /package/dist/{run → turn}/preparation-context-error.js +0 -0
  2104. /package/dist/{run → turn}/workspace-fingerprint.d.ts +0 -0
  2105. /package/dist/{run → turn}/workspace-fingerprint.js +0 -0
  2106. /package/dist/types/{run → session}/answer-review.js +0 -0
  2107. /package/dist/types/{run → session}/config.js +0 -0
  2108. /package/dist/types/{run → session}/lineage.js +0 -0
  2109. /package/dist/types/{run → session}/prepare-step.js +0 -0
  2110. /package/dist/types/{run → session}/stop-reason.js +0 -0
  2111. /package/src/{run → turn}/preparation-context-error.ts +0 -0
  2112. /package/src/{run → turn}/workspace-fingerprint.ts +0 -0
@@ -33,14 +33,14 @@ import {
33
33
  } from '../../../types/message/index.js'
34
34
  import { classifyProviderError } from '../../../types/provider/errors.js'
35
35
  import type { ChatCompletionResponse } from '../../../types/provider/index.js'
36
- import type { AnswerReview, AnswerReviewContext } from '../../../types/run/answer-review.js'
36
+ import type { AnswerReview, AnswerReviewContext } from '../../../types/session/answer-review.js'
37
37
  import type {
38
- RunEvent,
38
+ SessionEvent,
39
39
  StepFailure,
40
40
  StepProvenance,
41
41
  StepResult,
42
42
  StopReason,
43
- } from '../../../types/run/index.js'
43
+ } from '../../../types/session/index.js'
44
44
  import type { LLMToolSchema, ToolRegistryContract } from '../../../types/tool/index.js'
45
45
  import { toErrorMessage } from '../../../utils/error.js'
46
46
  import { stableDigest } from '../../../utils/hash.js'
@@ -74,7 +74,7 @@ import {
74
74
  import type { IterationContext } from './phases/index.js'
75
75
  import { runPlanGate } from './phases/plan.js'
76
76
  import { runToolReview } from './phases/tool-review.js'
77
- import { refreshWorkingMemory } from './phases/working-memory.js'
77
+ import { refreshWorkingMemory, splitWorkingMemoryForRequest } from './phases/working-memory.js'
78
78
  import { streamWithProviderRejectedImageRecovery } from './provider-rejected-image.js'
79
79
  import {
80
80
  type StepShaping,
@@ -105,16 +105,16 @@ export type { PhaseSignal } from './phases/index.js'
105
105
  export type { ToolReviewOutcome } from './phases/index.js'
106
106
 
107
107
  /**
108
- * How many times an answer may be handed back before the run stops.
108
+ * How many times an answer may be handed back before the turn stops.
109
109
  *
110
110
  * Bounded for the same reason the structured-output re-prompt is: a judge
111
111
  * that never accepts would otherwise spend the whole token budget
112
- * rediscovering that, and the run would end on a budget error rather than
112
+ * rediscovering that, and the turn would end on a budget error rather than
113
113
  * on the thing that actually went wrong.
114
114
  */
115
115
  const DEFAULT_ANSWER_REVIEW_LIMIT = 3
116
116
 
117
- // Ending a run changes the available actions, not the strength of its evidence.
117
+ // Ending a turn changes the available actions, not the strength of its evidence.
118
118
  // Use the same standard for warning closure and empty-completion recovery.
119
119
  const CLOSING_RESPONSE_GUIDANCE =
120
120
  'Give a concise response using only what the available evidence supports. Attribute unverified statements to their source instead of presenting them as observed facts. If evidence is missing or conflicting, state what cannot be established. Do not claim unfinished work is complete. Do not request any more tool calls.'
@@ -136,20 +136,20 @@ export class IterationOrchestrator {
136
136
  | import('../../../advisory/executor.js').AdvisoryTurnContext
137
137
  | undefined {
138
138
  const turn = this.advisoryTurn
139
- if (!turn || turn.iteration !== this.ctx.runMgr.currentIteration) return undefined
140
- const start = this.ctx.runMgr.messages.indexOf(turn.response)
139
+ if (!turn || turn.iteration !== this.ctx.recorder.currentIteration) return undefined
140
+ const start = this.ctx.recorder.messages.indexOf(turn.response)
141
141
  if (start < 0) return undefined
142
142
  return {
143
143
  iteration: turn.iteration,
144
144
  requestMessages: turn.requestMessages,
145
- subsequentMessages: this.ctx.runMgr.messages.slice(start),
145
+ subsequentMessages: this.ctx.recorder.messages.slice(start),
146
146
  }
147
147
  }
148
148
  /** Rejections so far. See {@link DEFAULT_ANSWER_REVIEW_LIMIT}. */
149
149
  private answerReviewAttempts = 0
150
150
  /**
151
- * The last request envelope this run recorded, so an unchanged one
152
- * costs a hash and no event. Per RUNNER, not module-level: two runs in
151
+ * The last request envelope this turn recorded, so an unchanged one
152
+ * costs a hash and no event. Per RUNNER, not module-level: two turns in
153
153
  * one process must not suppress each other's first envelope.
154
154
  */
155
155
  private lastEnvelopeKey: string | undefined
@@ -166,10 +166,10 @@ export class IterationOrchestrator {
166
166
  /**
167
167
  * The previous iteration held a `stopWhen` decision open for a worker.
168
168
  *
169
- * Set when the stop predicate fired and the run took one extra turn to
170
- * read a delegated result, so the turn that then ends the run can report
169
+ * Set when the stop predicate fired and the turn took one extra turn to
170
+ * read a delegated result, so the turn that then ends the turn can report
171
171
  * WHY it is over. Without it the outcome was right and the record was
172
- * wrong: the run stopped because the host said so and reported `end_turn`,
172
+ * wrong: the turn stopped because the host said so and reported `end_turn`,
173
173
  * and this repo carries thirteen `StopReason` values precisely so that a
174
174
  * run which ends for a nameable reason names it.
175
175
  *
@@ -266,7 +266,7 @@ export class IterationOrchestrator {
266
266
  })
267
267
  await this.ctx.emitEvent({
268
268
  type: 'capability_warning',
269
- runId: this.ctx.runMgr.id,
269
+ turnId: this.ctx.recorder.turnId,
270
270
  capability,
271
271
  contentSource: 'tool-result',
272
272
  providerId: this.ctx.provider.id,
@@ -279,19 +279,19 @@ export class IterationOrchestrator {
279
279
  }
280
280
 
281
281
  /**
282
- * Adopt the run's span after construction.
282
+ * Adopt the turn's span after construction.
283
283
  *
284
284
  * The orchestrator is built before `query()` enters its generator body,
285
- * which is where the run span is created — so the parent cannot be a
285
+ * which is where the turn span is created — so the parent cannot be a
286
286
  * constructor argument without reordering setup around one field.
287
287
  */
288
288
  setRootSpan(span: Span): void {
289
289
  this.ctx = { ...this.ctx, rootSpan: span }
290
290
  }
291
291
 
292
- async *runLoop(): AsyncGenerator<RunEvent> {
293
- const { runConfig, runMgr } = this.ctx
294
- const { model } = runConfig
292
+ async *runLoop(): AsyncGenerator<SessionEvent> {
293
+ const { turnConfig, recorder } = this.ctx
294
+ const { model } = turnConfig
295
295
  const tracer = getTracer()
296
296
  // Resume hydration happens after construction, before the loop starts.
297
297
  this.latestUserMessage = this.ctx.checkpointMgr.restoredLatestUserMessage
@@ -299,22 +299,29 @@ export class IterationOrchestrator {
299
299
  this.structuredReviewAttempts = this.ctx.checkpointMgr.restoredStructuredReviewAttempts ?? 0
300
300
  this.nativeStructuredAttempts = this.ctx.checkpointMgr.restoredNativeStructuredAttempts ?? 0
301
301
  if (!this.latestUserMessage) {
302
- for (const message of runMgr.messages) this.rememberUserMessage(message, false)
302
+ for (const message of recorder.messages) this.rememberUserMessage(message, false)
303
303
  }
304
304
  // The restored field can outlive the historical message it describes.
305
305
  // Only known post-checkpoint arrivals may supersede it, never an old
306
306
  // retained user turn encountered while scanning restored history.
307
307
  for (const message of this.ctx.resumedInput ?? []) this.rememberUserMessage(message)
308
308
 
309
- // One context-overflow relief per *stuck point*, not per run.
309
+ // What a recoverable failure pauses on when it lands before this
310
+ // loop wrote a checkpoint of its own: without it a 429 on the first
311
+ // request failed the turn, while the same 429 one request later
312
+ // paused it. Taken after the intent above is known, so the
313
+ // checkpoint names the message the turn is answering.
314
+ await this.ctx.checkpointMgr.markLoopStart?.(recorder)
315
+
316
+ // One context-overflow relief per *stuck point*, not per turn.
310
317
  //
311
318
  // The latch exists so that a second overflow immediately after a
312
319
  // successful compaction — meaning the prompt is irreducible — stops
313
320
  // instead of looping. It was never meant to disarm the mechanism for
314
- // the rest of the run, which is what a run-scoped flag did: one
321
+ // the rest of the turn, which is what a turn-scoped flag did: one
315
322
  // relief at iteration 3 left iteration 40 to die on an overflow with
316
323
  // obvious moves left. It is cleared by a turn that actually
317
- // succeeded, which is the evidence that the run is no longer stuck.
324
+ // succeeded, which is the evidence that the turn is no longer stuck.
318
325
  let overflowRelieved = false
319
326
 
320
327
  const planSignal = yield* runPlanGate(this.ctx)
@@ -324,7 +331,7 @@ export class IterationOrchestrator {
324
331
  // beside `iterSpan.end()` below: this loop leaves by eight `break`s,
325
332
  // two `return`s and a `throw`, and a rule every future edit has to
326
333
  // remember is a rule that gets forgotten — measured, it had been. Only
327
- // the ordinary final-answer exit consulted the inbox, so a run that
334
+ // the ordinary final-answer exit consulted the inbox, so a turn that
328
335
  // ended on a terminal tool, a structured output or the host's
329
336
  // `stopWhen` settled over a finished worker's output and threw it away.
330
337
  // A `finally` also covers a generator abandoned by its consumer, which
@@ -332,22 +339,22 @@ export class IterationOrchestrator {
332
339
  try {
333
340
  while (true) {
334
341
  if (this.ctx.abortController.signal.aborted) {
335
- runMgr.setStopReason('cancelled')
336
- runMgr.markCancelled()
342
+ recorder.setStopReason('cancelled')
343
+ recorder.markCancelled()
337
344
  break
338
345
  }
339
346
  if (
340
347
  this.ctx.structuredOutput?.mode === 'native' &&
341
348
  this.nativeStructuredAttempts > this.structuredOutputRetryLimit()
342
349
  ) {
343
- runMgr.setStopReason('structured_output_failed')
350
+ recorder.setStopReason('structured_output_failed')
344
351
  break
345
352
  }
346
353
  if (
347
354
  this.ctx.reviewAnswer &&
348
355
  this.answerReviewAttempts > (this.ctx.maxAnswerReviews ?? DEFAULT_ANSWER_REVIEW_LIMIT)
349
356
  ) {
350
- runMgr.setStopReason('answer_rejected')
357
+ recorder.setStopReason('answer_rejected')
351
358
  break
352
359
  }
353
360
  if (
@@ -355,7 +362,7 @@ export class IterationOrchestrator {
355
362
  this.structuredReviewAttempts >
356
363
  (this.ctx.structuredOutput.maxReviews ?? DEFAULT_ANSWER_REVIEW_LIMIT)
357
364
  ) {
358
- runMgr.setStopReason('answer_rejected')
365
+ recorder.setStopReason('answer_rejected')
359
366
  break
360
367
  }
361
368
  // Read AND clear, in that order, in this one place.
@@ -372,30 +379,33 @@ export class IterationOrchestrator {
372
379
  const stopWasDeferredForOutstandingWork = this.stopDeferredForOutstandingWork
373
380
  this.stopDeferredForOutstandingWork = false
374
381
 
375
- const guardResult = this.ctx.guard.beforeIteration(runMgr, this.ctx.abortController.signal)
382
+ const guardResult = this.ctx.guard.beforeIteration(
383
+ recorder,
384
+ this.ctx.abortController.signal,
385
+ )
376
386
 
377
387
  if (guardResult.shouldStop) {
378
388
  if (guardResult.isCancelled) {
379
- this.ctx.log.info('Run cancelled by signal', {
380
- [NAMZU.RUN_ID]: runMgr.id,
389
+ this.ctx.log.info('Turn cancelled by signal', {
390
+ [NAMZU.TURN_ID]: recorder.turnId,
381
391
  })
382
- runMgr.setStopReason('cancelled')
383
- runMgr.markCancelled()
392
+ recorder.setStopReason('cancelled')
393
+ recorder.markCancelled()
384
394
  break
385
395
  }
386
396
 
387
397
  const stopReason = guardResult.stopReason ?? 'end_turn'
388
398
  this.ctx.log.info('Guard enforcing stop', {
389
- [NAMZU.RUN_ID]: runMgr.id,
399
+ [NAMZU.TURN_ID]: recorder.turnId,
390
400
  'namzu.runtime.stop_reason': stopReason,
391
- [NAMZU.ITERATION]: runMgr.currentIteration,
392
- 'namzu.runtime.input_tokens': runMgr.tokenUsage.promptTokens,
393
- 'namzu.runtime.output_tokens': runMgr.tokenUsage.completionTokens,
401
+ [NAMZU.ITERATION]: recorder.currentIteration,
402
+ 'namzu.runtime.input_tokens': recorder.tokenUsage.promptTokens,
403
+ 'namzu.runtime.output_tokens': recorder.tokenUsage.completionTokens,
394
404
  })
395
405
  // A hard stop has no budget left for another model request.
396
406
  // Closing prose is requested at the warning threshold while
397
407
  // headroom remains; the completed work is already in history.
398
- runMgr.setStopReason(stopReason)
408
+ recorder.setStopReason(stopReason)
399
409
  break
400
410
  }
401
411
 
@@ -404,13 +414,13 @@ export class IterationOrchestrator {
404
414
  // and so can only speak after the step it disliked has already
405
415
  // run and been paid for; this is the seam a host with a live
406
416
  // rate limit or a revoked tenant actually needs.
407
- const veto = await beforeStep(this.stepShaping(), runMgr.currentIteration + 1)
408
- // The hook may settle because its run signal was aborted. Stop
417
+ const veto = await beforeStep(this.stepShaping(), recorder.currentIteration + 1)
418
+ // The hook may settle because its turn signal was aborted. Stop
409
419
  // before interpreting that settlement as a policy refusal or
410
420
  // counting an iteration that will never reach the provider.
411
421
  if (this.ctx.abortController.signal.aborted) {
412
- runMgr.setStopReason('cancelled')
413
- runMgr.markCancelled()
422
+ recorder.setStopReason('cancelled')
423
+ recorder.markCancelled()
414
424
  break
415
425
  }
416
426
  if (veto) {
@@ -418,23 +428,23 @@ export class IterationOrchestrator {
418
428
  // the frozen inventory LOG-22 exists to drain; a new call site
419
429
  // has no reason to join it.
420
430
  this.ctx.log.info('Step refused by beforeStep', {
421
- [NAMZU.RUN_ID]: runMgr.id,
422
- [NAMZU.ITERATION]: runMgr.currentIteration + 1,
431
+ [NAMZU.TURN_ID]: recorder.turnId,
432
+ [NAMZU.ITERATION]: recorder.currentIteration + 1,
423
433
  'namzu.step.veto_reason': veto.reason,
424
434
  })
425
- runMgr.setLastError(`beforeStep refused the next step: ${veto.reason}`)
426
- runMgr.setStopReason('step_refused')
435
+ recorder.setLastError(`beforeStep refused the next step: ${veto.reason}`)
436
+ recorder.setStopReason('step_refused')
427
437
  break
428
438
  }
429
439
 
430
440
  const forceFinalize = guardResult.forceFinalize
431
- const iterationNum = runMgr.incrementIteration()
441
+ const iterationNum = recorder.incrementIteration()
432
442
  this.ctx.log.debug('Iteration started', {
433
- [NAMZU.RUN_ID]: runMgr.id,
443
+ [NAMZU.TURN_ID]: recorder.turnId,
434
444
  [NAMZU.ITERATION]: iterationNum,
435
445
  [GENAI.REQUEST_MODEL]: model,
436
446
  'namzu.runtime.force_finalize': forceFinalize,
437
- 'namzu.runtime.message_count': runMgr.messages.length,
447
+ 'namzu.runtime.message_count': recorder.messages.length,
438
448
  })
439
449
 
440
450
  const iterationActivity = this.ctx.activityStore.create({
@@ -447,7 +457,7 @@ export class IterationOrchestrator {
447
457
 
448
458
  // Parent explicitly: this body is an async generator, so the
449
459
  // ambient context at resume time belongs to the CONSUMER, not to
450
- // whoever created the run span. Without this every iteration
460
+ // whoever created the turn span. Without this every iteration
451
461
  // emits as its own root and a 20-turn run shows up as 21
452
462
  // disconnected traces.
453
463
  const iterSpan = tracer.startSpan(
@@ -472,8 +482,8 @@ export class IterationOrchestrator {
472
482
  // where they always did, so compaction and the working-memory
473
483
  // refresh stay outside a successful step's window.
474
484
  let stepStartedAt = Date.now()
475
- let usageBefore: TokenUsage = { ...runMgr.tokenUsage }
476
- let costBefore: CostInfo = { ...runMgr.costInfo }
485
+ let usageBefore: TokenUsage = { ...recorder.tokenUsage }
486
+ let costBefore: CostInfo = { ...recorder.costInfo }
477
487
  let stepModel = model
478
488
  let stepMessageId: MessageId | undefined
479
489
  let stepResponse: ChatCompletionResponse | undefined
@@ -484,18 +494,19 @@ export class IterationOrchestrator {
484
494
  // the try rather than before it: a throw from any of these left
485
495
  // the span open, and an iteration span that never ends is a
486
496
  // trace that never closes — the export is incomplete for exactly
487
- // the run that failed.
497
+ // the turn that failed.
488
498
  this.ctx.toolExecutor.setParentSpan(iterSpan)
489
499
 
490
500
  iterSpan.setAttributes({
491
501
  [NAMZU.ITERATION]: iterationNum,
492
- [NAMZU.RUN_ID]: runMgr.id,
502
+ [GENAI.CONVERSATION_ID]: recorder.sessionId,
503
+ [NAMZU.TURN_ID]: recorder.turnId,
493
504
  [GENAI.REQUEST_MODEL]: model,
494
505
  })
495
506
 
496
507
  await this.ctx.emitEvent({
497
508
  type: 'iteration_started',
498
- runId: runMgr.id,
509
+ turnId: recorder.turnId,
499
510
  iteration: iterationNum,
500
511
  })
501
512
  yield* this.ctx.drainPending()
@@ -504,7 +515,8 @@ export class IterationOrchestrator {
504
515
  const hookResults = await this.ctx.pluginManager.executeHooks(
505
516
  'iteration_start',
506
517
  {
507
- runId: runMgr.id,
518
+ sessionId: recorder.sessionId,
519
+ turnId: recorder.turnId,
508
520
  iteration: iterationNum,
509
521
  signal: this.ctx.abortController.signal,
510
522
  },
@@ -528,7 +540,7 @@ export class IterationOrchestrator {
528
540
  // risks a 400 because the history still carries
529
541
  // tool_use/tool_result blocks.
530
542
  // Snapshot the cumulative counters so the step can report ITS
531
- // own usage rather than the run total.
543
+ // own usage rather than the turn total.
532
544
  stepStartedAt = Date.now()
533
545
 
534
546
  // Shape this step before calling the model. `stopWhen` decides
@@ -536,9 +548,9 @@ export class IterationOrchestrator {
536
548
  // supplied no hook.
537
549
  const contextModelBeforePreparation = this.ctx.contextModel ?? model
538
550
  const step = await prepareStep(this.stepShaping(), iterationNum)
539
- // Preparation inference belongs to the run, not the main-model step.
540
- usageBefore = { ...runMgr.tokenUsage }
541
- costBefore = { ...runMgr.costInfo }
551
+ // Preparation inference belongs to the turn, not the main-model step.
552
+ usageBefore = { ...recorder.tokenUsage }
553
+ costBefore = { ...recorder.costInfo }
542
554
  stepModel = step.model ?? model
543
555
  await selectContextModel(this.stepShaping(), stepModel)
544
556
  // Preserve post-compaction preparation/recall semantics. A changed
@@ -564,20 +576,21 @@ export class IterationOrchestrator {
564
576
  const enforceToolInputSchema = enforcedModelInputToolNames(this.ctx.tools, llmTools)
565
577
  stepModel = step.model ?? model
566
578
 
567
- const baseMessages = forceFinalize
568
- ? [
569
- ...runMgr.messages,
570
- createRuntimeContextMessage(
571
- `[SYSTEM] You are approaching your resource limits. ${CLOSING_RESPONSE_GUIDANCE}`,
572
- 'limit-finalization',
573
- ),
574
- ]
575
- : runMgr.messages
579
+ // The closing directive is appended LAST, after every piece of
580
+ // request-only context below, so it is the final thing the model
581
+ // reads on a forced-final step.
582
+ const closingDirective = forceFinalize
583
+ ? createRuntimeContextMessage(
584
+ `[SYSTEM] You are approaching your resource limits. ${CLOSING_RESPONSE_GUIDANCE}`,
585
+ 'limit-finalization',
586
+ )
587
+ : undefined
588
+ const baseMessages = recorder.messages
576
589
 
577
590
  // Step guidance is appended to the REQUEST, never pushed onto
578
- // the run's history: it applies to this step only, and pushing
591
+ // the turn's history: it applies to this step only, and pushing
579
592
  // it would accumulate one stale instruction per iteration.
580
- // Copy before it crosses the provider boundary. `runMgr.messages`
593
+ // Copy before it crosses the provider boundary. `recorder.messages`
581
594
  // is the LIVE run array, and the loop pushes onto it after the
582
595
  // call returns — so a driver that retains what it was handed
583
596
  // (to log it, cache it, or replay it on retry) watched its own
@@ -597,7 +610,7 @@ export class IterationOrchestrator {
597
610
  // A supervision change rides the same ephemeral slot, and for
598
611
  // the same reason: it applies to what happens next, not to the
599
612
  // run's history. The model plans around how closely it is being
600
- // watched — a run that silently stops asking a human leaves it
613
+ // watched — a turn that silently stops asking a human leaves it
601
614
  // batching destructive calls it expects to be reviewed, and one
602
615
  // that silently starts leaves it waiting on permission nobody
603
616
  // is left to give.
@@ -609,7 +622,7 @@ export class IterationOrchestrator {
609
622
  const policyNotice = policyChange
610
623
  ? `Approval policy changed from "${policyChange.from}" to "${policyChange.to}" (${policyChange.reason}). Tool calls from here on are reviewed under the new policy.`
611
624
  : null
612
- // State that changed during the run, reported once per turn.
625
+ // State that changed during the turn, reported once per turn.
613
626
  // `turn` contributions are recomputed here, not fixed when the
614
627
  // run's prompt is assembled. They retain system authority and
615
628
  // may affect caching just like the other system contributions.
@@ -618,31 +631,51 @@ export class IterationOrchestrator {
618
631
  iteration: iterationNum,
619
632
  }) ?? []
620
633
 
634
+ // Request-only context: observations that need no system
635
+ // authority and change from request to request. They ride
636
+ // runtime-context messages of kind `step-context` after the
637
+ // history, which every driver keeps there and a caching driver
638
+ // ends its breakpoint before — so a changed pin or a new turn
639
+ // snapshot costs its own tokens, not a re-read of the history.
640
+ // The working-memory slot keeps its place in the turn's history
641
+ // (compaction preserves it there) and leaves the request's
642
+ // system run here.
643
+ const workingMemory = splitWorkingMemoryForRequest(baseMessages)
644
+ const contextSections =
645
+ this.ctx.promptContributions?.render('context', {
646
+ iteration: iterationNum,
647
+ }) ?? []
648
+
621
649
  const stepPreamble = [step.system, stepSkills, policyNotice, ...turnSections]
622
650
  .filter(Boolean)
623
651
  .join('\n\n')
624
652
  const requestHistory = stepPreamble
625
- ? [...baseMessages, createSystemMessage(stepPreamble)]
626
- : [...baseMessages]
653
+ ? [...workingMemory.history, createSystemMessage(stepPreamble)]
654
+ : [...workingMemory.history]
655
+ if (workingMemory.context) requestHistory.push(workingMemory.context)
656
+ if (contextSections.length > 0)
657
+ requestHistory.push(stepContextMessage(contextSections.join('\n\n')))
627
658
  if (step.context) requestHistory.push(stepContextMessage(step.context))
628
659
  const messages = projectRequestRichContent(
629
660
  this.projectObservations(requestHistory),
630
- this.ctx.runConfig.maxRequestRichContentBytes ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES,
661
+ this.ctx.turnConfig.maxRequestRichContentBytes ??
662
+ DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES,
631
663
  )
632
664
  appendWorkContext(this.stepShaping(), messages, iterationNum, step)
665
+ if (closingDirective) messages.push(closingDirective)
633
666
  await this.reportUnsupportedToolResults(messages)
634
667
  yield* this.ctx.drainPending()
635
668
 
636
669
  // What the model is about to be ASKED, recorded when it
637
- // changed. `run_started` carries one system prompt and tool
670
+ // changed. `turn_started` carries one system prompt and tool
638
671
  // schemas never reached the transcript at all — while
639
672
  // `prepareStep` rewrites the system text, narrows the tool
640
673
  // list or swaps the model, and a step's skills ride the
641
674
  // ephemeral preamble above. So a transcript showed one
642
- // question for a run that had asked several.
675
+ // question for a turn that had asked several.
643
676
  //
644
677
  // Emitted only on a change: the digest is compared against
645
- // the last one this run recorded, so the common case costs
678
+ // the last one this turn recorded, so the common case costs
646
679
  // one hash and nothing else. Copying an unchanged system
647
680
  // prompt every iteration is the fastest way to make a
648
681
  // durable log too large to read.
@@ -650,7 +683,7 @@ export class IterationOrchestrator {
650
683
  model: stepModel,
651
684
  // Read off `messages`, which is what the request is actually
652
685
  // built from — including the ephemeral preamble. Recomputing
653
- // it from the run's history would describe a request nobody
686
+ // it from the turn's history would describe a request nobody
654
687
  // sent the moment the two diverge.
655
688
  systemPrompt: messages
656
689
  .filter((m) => m.role === 'system')
@@ -669,7 +702,7 @@ export class IterationOrchestrator {
669
702
  this.lastEnvelopeKey = envelopeKey
670
703
  await this.ctx.emitEvent?.({
671
704
  type: 'request_envelope',
672
- runId: runMgr.id,
705
+ turnId: recorder.turnId,
673
706
  iteration: iterationNum,
674
707
  ...envelope,
675
708
  toolNames: Object.freeze([...envelope.toolNames]),
@@ -690,21 +723,22 @@ export class IterationOrchestrator {
690
723
  const hookResults = await this.ctx.pluginManager.executeHooks(
691
724
  'pre_llm_call',
692
725
  {
693
- runId: runMgr.id,
726
+ sessionId: recorder.sessionId,
727
+ turnId: recorder.turnId,
694
728
  iteration: iterationNum,
695
729
  signal: this.ctx.abortController.signal,
696
- // Built inside the guard: a run with no plugins installed
730
+ // Built inside the guard: a turn with no plugins installed
697
731
  // pays nothing for a projection nobody reads.
698
732
  request: Object.freeze({
699
733
  context,
700
734
  model: stepModel,
701
735
  // Copied per turn, not handed over live: these are the
702
736
  // run's own message objects, and a hook writing into
703
- // one would edit the history the run is about to send.
737
+ // one would edit the history the turn is about to send.
704
738
  messages: Object.freeze(messages.map((m) => Object.freeze({ ...m }))),
705
739
  toolNames: Object.freeze(llmTools.map((t) => t.function.name)),
706
- temperature: step.temperature ?? runConfig.temperature,
707
- maxTokens: step.maxResponseTokens ?? runConfig.maxResponseTokens,
740
+ temperature: step.temperature ?? turnConfig.temperature,
741
+ maxTokens: step.maxResponseTokens ?? turnConfig.maxResponseTokens,
708
742
  }),
709
743
  },
710
744
  this.ctx.emitEvent,
@@ -716,7 +750,7 @@ export class IterationOrchestrator {
716
750
  // Phase 4 (ses_001-tool-stream-events): consume the
717
751
  // streaming response natively, emitting message and
718
752
  // tool-input lifecycle events as deltas arrive. The
719
- // helper yields RunEvents through drainPending() so SSE
753
+ // helper yields SessionEvents through drainPending() so SSE
720
754
  // consumers see live progress; its return value is the
721
755
  // aggregated `ChatCompletionResponse` for the legacy
722
756
  // downstream paths (assistantMsg construction, working
@@ -776,20 +810,22 @@ export class IterationOrchestrator {
776
810
  : llmTools.length > 0
777
811
  ? step.toolChoice
778
812
  : undefined,
779
- temperature: step.temperature ?? runConfig.temperature,
780
- maxTokens: step.maxResponseTokens ?? runConfig.maxResponseTokens,
813
+ temperature: step.temperature ?? turnConfig.temperature,
814
+ maxTokens: step.maxResponseTokens ?? turnConfig.maxResponseTokens,
781
815
  cacheControl: { type: 'auto' },
782
- ...(runConfig.thinking ? { thinking: runConfig.thinking } : {}),
783
- ...(runConfig.effort ? { effort: runConfig.effort } : {}),
784
- ...(!forceFinalize && runConfig.webSearch ? { webSearch: runConfig.webSearch } : {}),
785
- // Thread the run abort into the model call so a Stop tears the
816
+ ...(turnConfig.thinking ? { thinking: turnConfig.thinking } : {}),
817
+ ...(turnConfig.effort ? { effort: turnConfig.effort } : {}),
818
+ ...(!forceFinalize && turnConfig.webSearch
819
+ ? { webSearch: turnConfig.webSearch }
820
+ : {}),
821
+ // Thread the turn abort into the model call so a Stop tears the
786
822
  // in-flight turn down (provider passes it to fetch; the consumer
787
823
  // also races it). Inert when never aborted.
788
824
  signal: this.ctx.abortController.signal,
789
825
  },
790
826
  this.ctx.emitEvent,
791
827
  this.ctx.drainPending,
792
- runMgr.id,
828
+ recorder.turnId,
793
829
  iterationNum,
794
830
  forceFinalize,
795
831
  this.ctx.log,
@@ -801,6 +837,7 @@ export class IterationOrchestrator {
801
837
  Boolean(
802
838
  this.ctx.reviewAnswer || this.ctx.structuredOutput?.review || this.ctx.advisoryCtx,
803
839
  ),
840
+ recorder.sessionId,
804
841
  )
805
842
  stepResponse = response
806
843
  const reviewRequest: ReviewRequest = {
@@ -841,13 +878,13 @@ export class IterationOrchestrator {
841
878
  // model it was asked for. This is the seam that ended the
842
879
  // always-zero cost: the rate lookup happens per turn,
843
880
  // against who actually answered, rather than against one
844
- // table the run was constructed with.
845
- runMgr.recordTurnUsage(response.usage, {
881
+ // table the turn was constructed with.
882
+ recorder.recordTurnUsage(response.usage, {
846
883
  providerId: servedBy.providerId,
847
884
  model: servedBy.model,
848
885
  })
849
886
 
850
- // The turn went through, so the run is not sitting on an
887
+ // The turn went through, so the turn is not sitting on an
851
888
  // irreducible prompt any more. Re-arm relief for the next one.
852
889
  overflowRelieved = false
853
890
 
@@ -855,7 +892,8 @@ export class IterationOrchestrator {
855
892
  const hookResults = await this.ctx.pluginManager.executeHooks(
856
893
  'post_llm_call',
857
894
  {
858
- runId: runMgr.id,
895
+ sessionId: recorder.sessionId,
896
+ turnId: recorder.turnId,
859
897
  iteration: iterationNum,
860
898
  signal: this.ctx.abortController.signal,
861
899
  response: Object.freeze({
@@ -874,7 +912,7 @@ export class IterationOrchestrator {
874
912
  }
875
913
 
876
914
  this.ctx.log.debug('LLM response received', {
877
- [NAMZU.RUN_ID]: runMgr.id,
915
+ [NAMZU.TURN_ID]: recorder.turnId,
878
916
  [NAMZU.ITERATION]: iterationNum,
879
917
  'namzu.runtime.finish_reason': response.finishReason,
880
918
  'namzu.runtime.has_content':
@@ -882,8 +920,8 @@ export class IterationOrchestrator {
882
920
  'namzu.runtime.tool_call_count': response.message.toolCalls?.length ?? 0,
883
921
  [GENAI.USAGE_INPUT_TOKENS]: response.usage.promptTokens,
884
922
  [GENAI.USAGE_OUTPUT_TOKENS]: response.usage.completionTokens,
885
- 'namzu.usage.total_tokens': runMgr.tokenUsage.totalTokens,
886
- 'namzu.runtime.total_cost': runMgr.costInfo.totalCost,
923
+ 'namzu.usage.total_tokens': recorder.tokenUsage.totalTokens,
924
+ 'namzu.runtime.total_cost': recorder.costInfo.totalCost,
887
925
  })
888
926
 
889
927
  // The context figures ride with the spend figures because a
@@ -893,7 +931,7 @@ export class IterationOrchestrator {
893
931
  // are measured here rather than left to be derived, since the
894
932
  // only correct derivation needs internals a host cannot see.
895
933
  //
896
- // Absent when the run has no compaction config: nothing then
934
+ // Absent when the turn has no compaction config: nothing then
897
935
  // resolves a window, and inventing one would be the guess this
898
936
  // replaces.
899
937
  const contextFigures = this.ctx.compactionConfig
@@ -911,10 +949,10 @@ export class IterationOrchestrator {
911
949
 
912
950
  await this.ctx.emitEvent({
913
951
  type: 'token_usage_updated',
914
- runId: runMgr.id,
915
- usage: runMgr.tokenUsage,
916
- budget: runMgr.budget?.summary(),
917
- cost: runMgr.costInfo,
952
+ turnId: recorder.turnId,
953
+ usage: recorder.tokenUsage,
954
+ budget: recorder.budget?.summary(),
955
+ cost: recorder.costInfo,
918
956
  ...contextFigures,
919
957
  })
920
958
 
@@ -939,7 +977,7 @@ export class IterationOrchestrator {
939
977
  },
940
978
  response.message.textParts,
941
979
  )
942
- runMgr.pushMessage(assistantMsg)
980
+ recorder.pushMessage(assistantMsg)
943
981
  if (this.ctx.advisoryCtx && requestMessages) {
944
982
  this.advisoryTurn = { iteration: iterationNum, requestMessages, response: assistantMsg }
945
983
  }
@@ -988,7 +1026,7 @@ export class IterationOrchestrator {
988
1026
  // Every task-dispatch tool (create_task, continue_task, Agent)
989
1027
  // is BLOCKING: the worker's output returns as the dispatching
990
1028
  // tool_use's canonical tool_result, so by the time the model
991
- // ends its turn nothing launched by this run should still be
1029
+ // ends its turn nothing launched by this turn should still be
992
1030
  // in flight. A running task here is an orphan (interrupted
993
1031
  // tool execution, cancel race) with no delivery path back to
994
1032
  // the parent — the <task-notification> producer was removed
@@ -996,9 +1034,9 @@ export class IterationOrchestrator {
996
1034
  // out. Log the orphans honestly and end the turn normally.
997
1035
  if (!forceFinalize && this.hasRunningAgentTasks()) {
998
1036
  this.ctx.log.warn(
999
- 'LLM ended turn with agent tasks still running — ending run without waiting (orphan tasks have no delivery path)',
1037
+ 'LLM ended turn with agent tasks still running — ending turn without waiting (orphan tasks have no delivery path)',
1000
1038
  {
1001
- [NAMZU.RUN_ID]: runMgr.id,
1039
+ [NAMZU.TURN_ID]: recorder.turnId,
1002
1040
  [NAMZU.ITERATION]: iterationNum,
1003
1041
  },
1004
1042
  )
@@ -1009,7 +1047,7 @@ export class IterationOrchestrator {
1009
1047
  // It did not, and the ledger's own contract said it should:
1010
1048
  // `StepResult` is documented as "what one iteration of the
1011
1049
  // agent loop did" and `stepNumber` as "1-based, matching
1012
- // `iteration` on the run events". Every path below emits
1050
+ // `iteration` on the turn events". Every path below emits
1013
1051
  // `iteration_completed` with this iteration's number, and
1014
1052
  // none of them recorded a step — so the events said
1015
1053
  // iteration N happened and `steps` had no entry N. The
@@ -1041,7 +1079,7 @@ export class IterationOrchestrator {
1041
1079
  // executor, and the empty-completion retry a few lines below
1042
1080
  // all spend tokens inside an iteration without being one.
1043
1081
  // Their usage reaches `run.tokenUsage` and no step, so the
1044
- // ledger reconciles with the run total for a run that makes
1082
+ // ledger reconciles with the turn total for a turn that makes
1045
1083
  // no side calls and undercounts by exactly those calls for a
1046
1084
  // run that does. That residual is named rather than fixed
1047
1085
  // here: attributing a side call needs a record that is not a
@@ -1075,16 +1113,16 @@ export class IterationOrchestrator {
1075
1113
  )
1076
1114
  else {
1077
1115
  this.nativeStructuredAttempts++
1078
- runMgr.pushMessage(
1116
+ recorder.pushMessage(
1079
1117
  createRuntimeContextMessage(
1080
1118
  'Return a complete JSON value matching the supplied response schema. Do not continue a partial JSON fragment.',
1081
1119
  'structured-output',
1082
1120
  ),
1083
1121
  )
1084
- const checkpoint = await this.ctx.checkpointMgr.create(runMgr, iterationNum)
1122
+ const checkpoint = await this.ctx.checkpointMgr.create(recorder, iterationNum)
1085
1123
  await this.ctx.emitEvent({
1086
1124
  type: 'checkpoint_created',
1087
- runId: runMgr.id,
1125
+ turnId: recorder.turnId,
1088
1126
  checkpointId: checkpoint.id,
1089
1127
  iteration: iterationNum,
1090
1128
  })
@@ -1095,14 +1133,14 @@ export class IterationOrchestrator {
1095
1133
  }
1096
1134
  await this.ctx.emitEvent({
1097
1135
  type: 'iteration_completed',
1098
- runId: runMgr.id,
1136
+ turnId: recorder.turnId,
1099
1137
  iteration: iterationNum,
1100
1138
  hasToolCalls: false,
1101
1139
  })
1102
1140
  yield* this.ctx.drainPending()
1103
1141
  if (this.ctx.abortController.signal.aborted || outcome === 'cancelled') {
1104
- runMgr.setStopReason('cancelled')
1105
- runMgr.markCancelled()
1142
+ recorder.setStopReason('cancelled')
1143
+ recorder.markCancelled()
1106
1144
  break
1107
1145
  }
1108
1146
  if (outcome === 'accepted') {
@@ -1114,16 +1152,16 @@ export class IterationOrchestrator {
1114
1152
  if (changed || inbound > 0) continue
1115
1153
  }
1116
1154
  if (this.ctx.abortController.signal.aborted) {
1117
- runMgr.setStopReason('cancelled')
1118
- runMgr.markCancelled()
1155
+ recorder.setStopReason('cancelled')
1156
+ recorder.markCancelled()
1119
1157
  break
1120
1158
  }
1121
1159
  this.publishStructuredOutput()
1122
- runMgr.setStopReason('end_turn')
1160
+ recorder.setStopReason('end_turn')
1123
1161
  break
1124
1162
  }
1125
1163
  if (outcome === 'exhausted') {
1126
- runMgr.setStopReason(
1164
+ recorder.setStopReason(
1127
1165
  candidate.success ? 'answer_rejected' : 'structured_output_failed',
1128
1166
  )
1129
1167
  break
@@ -1155,16 +1193,16 @@ export class IterationOrchestrator {
1155
1193
  // - max_iterations bounds the loop in any case.
1156
1194
  if (!forceFinalize && response.finishReason === 'length' && hasContent) {
1157
1195
  this.ctx.log.info('LLM hit max_tokens mid-text — auto-continuing', {
1158
- [NAMZU.RUN_ID]: runMgr.id,
1196
+ [NAMZU.TURN_ID]: recorder.turnId,
1159
1197
  [NAMZU.ITERATION]: iterationNum,
1160
1198
  [GENAI.USAGE_OUTPUT_TOKENS]: response.usage.completionTokens,
1161
1199
  })
1162
- runMgr.pushMessage(
1200
+ recorder.pushMessage(
1163
1201
  createRuntimeContextMessage(AUTO_CONTINUATION_USER_MESSAGE, 'auto-continuation'),
1164
1202
  )
1165
1203
  await this.ctx.emitEvent({
1166
1204
  type: 'iteration_completed',
1167
- runId: runMgr.id,
1205
+ turnId: recorder.turnId,
1168
1206
  iteration: iterationNum,
1169
1207
  hasToolCalls: false,
1170
1208
  })
@@ -1182,23 +1220,23 @@ export class IterationOrchestrator {
1182
1220
  const limit = this.structuredOutputRetryLimit()
1183
1221
  if (attempt > limit) {
1184
1222
  this.ctx.log.warn('Structured output not produced within its retries', {
1185
- [NAMZU.RUN_ID]: runMgr.id,
1223
+ [NAMZU.TURN_ID]: recorder.turnId,
1186
1224
  'namzu.runtime.attempts': attempt - 1,
1187
1225
  })
1188
- runMgr.setStopReason('structured_output_failed')
1226
+ recorder.setStopReason('structured_output_failed')
1189
1227
  break
1190
1228
  }
1191
1229
  this.ctx.log.info('Re-prompting for structured output', {
1192
- [NAMZU.RUN_ID]: runMgr.id,
1230
+ [NAMZU.TURN_ID]: recorder.turnId,
1193
1231
  'namzu.retry.attempt': attempt,
1194
1232
  'namzu.runtime.limit': limit,
1195
1233
  })
1196
- runMgr.pushMessage(
1234
+ recorder.pushMessage(
1197
1235
  createRuntimeContextMessage(STRUCTURED_OUTPUT_REPROMPT, 'structured-output'),
1198
1236
  )
1199
1237
  await this.ctx.emitEvent({
1200
1238
  type: 'iteration_completed',
1201
- runId: runMgr.id,
1239
+ turnId: recorder.turnId,
1202
1240
  iteration: iterationNum,
1203
1241
  hasToolCalls: false,
1204
1242
  })
@@ -1210,10 +1248,10 @@ export class IterationOrchestrator {
1210
1248
  //
1211
1249
  // The stop predicate is only consulted after tools ran, so
1212
1250
  // there was no seam here at all: the moment the model
1213
- // stopped calling tools the run finalized, whatever it had
1251
+ // stopped calling tools the turn finalized, whatever it had
1214
1252
  // produced. Verify-then-fix — run the build, feed the
1215
1253
  // failure back, let it try again — meant starting a whole
1216
- // new run and re-supplying the context the first one had.
1254
+ // new turn and re-supplying the context the first one had.
1217
1255
  //
1218
1256
  // Shaped after the structured-output re-prompt directly
1219
1257
  // above, which solves the same problem for one specific
@@ -1226,45 +1264,45 @@ export class IterationOrchestrator {
1226
1264
  stepModel,
1227
1265
  )
1228
1266
  if (this.ctx.abortController.signal.aborted) {
1229
- runMgr.setStopReason('cancelled')
1230
- runMgr.markCancelled()
1267
+ recorder.setStopReason('cancelled')
1268
+ recorder.markCancelled()
1231
1269
  break
1232
1270
  }
1233
1271
  if (review && !review.accept) {
1234
1272
  const attempt = ++this.answerReviewAttempts
1235
- runMgr.pushMessage(createRuntimeContextMessage(review.feedback, 'answer-review'))
1273
+ recorder.pushMessage(createRuntimeContextMessage(review.feedback, 'answer-review'))
1236
1274
  // Commit the consumed allowance with its feedback before another
1237
1275
  // request, including exhaustion. Compaction cannot reset this quota.
1238
- const checkpoint = await this.ctx.checkpointMgr.create(runMgr, iterationNum)
1276
+ const checkpoint = await this.ctx.checkpointMgr.create(recorder, iterationNum)
1239
1277
  await this.ctx.emitEvent({
1240
1278
  type: 'checkpoint_created',
1241
- runId: runMgr.id,
1279
+ turnId: recorder.turnId,
1242
1280
  checkpointId: checkpoint.id,
1243
1281
  iteration: iterationNum,
1244
1282
  })
1245
1283
  if (this.ctx.abortController.signal.aborted) {
1246
- runMgr.setStopReason('cancelled')
1247
- runMgr.markCancelled()
1284
+ recorder.setStopReason('cancelled')
1285
+ recorder.markCancelled()
1248
1286
  break
1249
1287
  }
1250
1288
  const limit = this.ctx.maxAnswerReviews ?? DEFAULT_ANSWER_REVIEW_LIMIT
1251
1289
  if (attempt > limit) {
1252
- this.ctx.log.warn('Answer rejected more times than the run allows', {
1253
- [NAMZU.RUN_ID]: runMgr.id,
1290
+ this.ctx.log.warn('Answer rejected more times than the turn allows', {
1291
+ [NAMZU.TURN_ID]: recorder.turnId,
1254
1292
  'namzu.runtime.attempts': attempt - 1,
1255
1293
  'namzu.runtime.limit': limit,
1256
1294
  })
1257
- runMgr.setStopReason('answer_rejected')
1295
+ recorder.setStopReason('answer_rejected')
1258
1296
  break
1259
1297
  }
1260
1298
  this.ctx.log.info('Answer rejected — returning it to the model', {
1261
- [NAMZU.RUN_ID]: runMgr.id,
1299
+ [NAMZU.TURN_ID]: recorder.turnId,
1262
1300
  'namzu.retry.attempt': attempt,
1263
1301
  'namzu.runtime.limit': limit,
1264
1302
  })
1265
1303
  await this.ctx.emitEvent({
1266
1304
  type: 'iteration_completed',
1267
- runId: runMgr.id,
1305
+ turnId: recorder.turnId,
1268
1306
  iteration: iterationNum,
1269
1307
  hasToolCalls: false,
1270
1308
  })
@@ -1274,11 +1312,11 @@ export class IterationOrchestrator {
1274
1312
  }
1275
1313
 
1276
1314
  // A background worker is still out there, and this turn was
1277
- // about to end the run.
1315
+ // about to end the turn.
1278
1316
  //
1279
1317
  // Settling here would throw away the very thing the launch
1280
1318
  // existed to produce: the supervisor said "launched", the
1281
- // worker had not finished, and the run closed over it.
1319
+ // worker had not finished, and the turn closed over it.
1282
1320
  if (
1283
1321
  !forceFinalize &&
1284
1322
  (yield* holdForOutstandingWork(this.ctx, iterationNum, false, () =>
@@ -1300,7 +1338,7 @@ export class IterationOrchestrator {
1300
1338
  if (!forceFinalize && this.deliverInbound() > 0) {
1301
1339
  await this.ctx.emitEvent({
1302
1340
  type: 'iteration_completed',
1303
- runId: runMgr.id,
1341
+ turnId: recorder.turnId,
1304
1342
  iteration: iterationNum,
1305
1343
  hasToolCalls: false,
1306
1344
  })
@@ -1325,18 +1363,18 @@ export class IterationOrchestrator {
1325
1363
 
1326
1364
  await this.ctx.emitEvent({
1327
1365
  type: 'iteration_completed',
1328
- runId: runMgr.id,
1366
+ turnId: recorder.turnId,
1329
1367
  iteration: iterationNum,
1330
1368
  hasToolCalls: false,
1331
1369
  })
1332
1370
  yield* this.ctx.drainPending()
1333
1371
  // A Stop that lands AFTER the final turn streamed but before
1334
- // this break must settle the run as cancelled, not end_turn —
1372
+ // this break must settle the turn as cancelled, not end_turn —
1335
1373
  // otherwise the just-produced answer is recorded as a clean
1336
1374
  // completion. Mirrors the between-iteration cancel at :511.
1337
1375
  if (this.ctx.abortController.signal.aborted) {
1338
- runMgr.setStopReason('cancelled')
1339
- runMgr.markCancelled()
1376
+ recorder.setStopReason('cancelled')
1377
+ recorder.markCancelled()
1340
1378
  break
1341
1379
  }
1342
1380
  // The host's stop predicate, if the previous turn deferred it
@@ -1344,13 +1382,13 @@ export class IterationOrchestrator {
1344
1382
  // is prose, and `stopWhen` is consulted only after a tool
1345
1383
  // batch, so the predicate is never asked again — reporting
1346
1384
  // `end_turn` would name the shape of the last message rather
1347
- // than the reason the run is over.
1385
+ // than the reason the turn is over.
1348
1386
  //
1349
1387
  // Only here. A terminal tool and a captured structured output
1350
1388
  // also settle as `end_turn`, and there the deferred predicate
1351
- // is not why the run ended: those decided the answer
1389
+ // is not why the turn ended: those decided the answer
1352
1390
  // themselves.
1353
- runMgr.setStopReason(
1391
+ recorder.setStopReason(
1354
1392
  closingStopReason ??
1355
1393
  (stopWasDeferredForOutstandingWork ? 'stop_condition' : 'end_turn'),
1356
1394
  )
@@ -1359,7 +1397,7 @@ export class IterationOrchestrator {
1359
1397
 
1360
1398
  const reviewOutcome = yield* runToolReview(this.ctx, response, iterationNum)
1361
1399
 
1362
- // The step record is built even for a rejected batch: a run that
1400
+ // The step record is built even for a rejected batch: a turn that
1363
1401
  // spent a turn getting its tools refused still spent the tokens,
1364
1402
  // and a caller reconstructing cost per step must see it.
1365
1403
  this.recordStep({
@@ -1404,34 +1442,34 @@ export class IterationOrchestrator {
1404
1442
  ) {
1405
1443
  await this.ctx.emitEvent({
1406
1444
  type: 'iteration_completed',
1407
- runId: runMgr.id,
1445
+ turnId: recorder.turnId,
1408
1446
  iteration: iterationNum,
1409
1447
  hasToolCalls: true,
1410
1448
  })
1411
1449
  yield* this.ctx.drainPending()
1412
1450
  if (this.ctx.abortController.signal.aborted) {
1413
- runMgr.setStopReason('cancelled')
1414
- runMgr.markCancelled()
1451
+ recorder.setStopReason('cancelled')
1452
+ recorder.markCancelled()
1415
1453
  break
1416
1454
  }
1417
1455
  if (structuredOutcome === 'retry') continue
1418
- runMgr.setStopReason(
1456
+ recorder.setStopReason(
1419
1457
  structuredOutcome === 'cancelled' ? 'cancelled' : 'answer_rejected',
1420
1458
  )
1421
- if (structuredOutcome === 'cancelled') runMgr.markCancelled()
1459
+ if (structuredOutcome === 'cancelled') recorder.markCancelled()
1422
1460
  break
1423
1461
  }
1424
1462
  if (structuredOutcome === 'accepted') {
1425
1463
  await this.ctx.emitEvent({
1426
1464
  type: 'iteration_completed',
1427
- runId: runMgr.id,
1465
+ turnId: recorder.turnId,
1428
1466
  iteration: iterationNum,
1429
1467
  hasToolCalls: true,
1430
1468
  })
1431
1469
  yield* this.ctx.drainPending()
1432
1470
  if (this.ctx.abortController.signal.aborted) {
1433
- runMgr.setStopReason('cancelled')
1434
- runMgr.markCancelled()
1471
+ recorder.setStopReason('cancelled')
1472
+ recorder.markCancelled()
1435
1473
  break
1436
1474
  }
1437
1475
  if (!forceFinalize) {
@@ -1441,20 +1479,20 @@ export class IterationOrchestrator {
1441
1479
  if (inbound > 0 || this.latestUserMessage !== operatorInputAtDispatch) continue
1442
1480
  }
1443
1481
  if (this.ctx.abortController.signal.aborted) {
1444
- runMgr.setStopReason('cancelled')
1445
- runMgr.markCancelled()
1482
+ recorder.setStopReason('cancelled')
1483
+ recorder.markCancelled()
1446
1484
  break
1447
1485
  }
1448
- this.ctx.log.info('Structured output produced — ending run', {
1449
- [NAMZU.RUN_ID]: runMgr.id,
1486
+ this.ctx.log.info('Structured output produced — ending turn', {
1487
+ [NAMZU.TURN_ID]: recorder.turnId,
1450
1488
  [NAMZU.ITERATION]: iterationNum,
1451
1489
  })
1452
1490
  this.publishStructuredOutput()
1453
- runMgr.setStopReason('end_turn')
1491
+ recorder.setStopReason('end_turn')
1454
1492
  break
1455
1493
  }
1456
1494
 
1457
- // A tool the author declared terminal settles the run with its
1495
+ // A tool the author declared terminal settles the turn with its
1458
1496
  // own output, the same rule `structured_output` has always
1459
1497
  // had. Without it a delegation cost the parent one more model
1460
1498
  // call at full context whose only job was to restate what the
@@ -1463,16 +1501,16 @@ export class IterationOrchestrator {
1463
1501
  // worker's words.
1464
1502
  const settled = this.terminalToolOutput(reviewOutcome.results, response)
1465
1503
  if (settled !== undefined) {
1466
- this.ctx.log.info('Terminal tool produced the answer — ending run', {
1467
- [NAMZU.RUN_ID]: runMgr.id,
1504
+ this.ctx.log.info('Terminal tool produced the answer — ending turn', {
1505
+ [NAMZU.TURN_ID]: recorder.turnId,
1468
1506
  [NAMZU.ITERATION]: iterationNum,
1469
1507
  [GENAI.TOOL_NAME]: settled.toolName,
1470
1508
  })
1471
- runMgr.setResult(settled.output)
1472
- runMgr.setStopReason('end_turn')
1509
+ recorder.setResult(settled.output, 'review')
1510
+ recorder.setStopReason('end_turn')
1473
1511
  await this.ctx.emitEvent({
1474
1512
  type: 'iteration_completed',
1475
- runId: runMgr.id,
1513
+ turnId: recorder.turnId,
1476
1514
  iteration: iterationNum,
1477
1515
  hasToolCalls: true,
1478
1516
  })
@@ -1507,7 +1545,7 @@ export class IterationOrchestrator {
1507
1545
  // outstanding. One task deferred it once; two awaited
1508
1546
  // jobs exiting a minute apart defer it twice, each time
1509
1547
  // for a turn the model spends on news it has not read.
1510
- // `maxIterations` and the run's own deadline bound all of
1548
+ // `maxIterations` and the turn's own deadline bound all of
1511
1549
  // it regardless, and a leg with nothing pending never
1512
1550
  // opens a hold at all.
1513
1551
  if (
@@ -1516,20 +1554,20 @@ export class IterationOrchestrator {
1516
1554
  )
1517
1555
  ) {
1518
1556
  // Remember WHY the next turn exists, so the turn that
1519
- // ends the run can name the host's decision instead of
1557
+ // ends the turn can name the host's decision instead of
1520
1558
  // reporting the shape of the last message.
1521
1559
  this.stopDeferredForOutstandingWork = true
1522
1560
  continue
1523
1561
  }
1524
1562
 
1525
1563
  this.ctx.log.info('Stop condition met', {
1526
- [NAMZU.RUN_ID]: runMgr.id,
1564
+ [NAMZU.TURN_ID]: recorder.turnId,
1527
1565
  [NAMZU.ITERATION]: iterationNum,
1528
1566
  })
1529
- runMgr.setStopReason('stop_condition')
1567
+ recorder.setStopReason('stop_condition')
1530
1568
  await this.ctx.emitEvent({
1531
1569
  type: 'iteration_completed',
1532
- runId: runMgr.id,
1570
+ turnId: recorder.turnId,
1533
1571
  iteration: iterationNum,
1534
1572
  hasToolCalls: true,
1535
1573
  })
@@ -1564,11 +1602,11 @@ export class IterationOrchestrator {
1564
1602
  const unheard = this.ctx.completionInbox?.drain() ?? []
1565
1603
  if (unheard.length > 0) {
1566
1604
  this.ctx.log.info('Delivering unawaited task completions', {
1567
- [NAMZU.RUN_ID]: runMgr.id,
1605
+ [NAMZU.TURN_ID]: recorder.turnId,
1568
1606
  [NAMZU.ITERATION]: iterationNum,
1569
1607
  'namzu.runtime.tasks': unheard.map((h) => h.taskId),
1570
1608
  })
1571
- runMgr.pushMessage(
1609
+ recorder.pushMessage(
1572
1610
  createRuntimeContextMessage(formatCompletionNotification(unheard), 'task-completion'),
1573
1611
  )
1574
1612
  }
@@ -1585,7 +1623,8 @@ export class IterationOrchestrator {
1585
1623
  const hookResults = await this.ctx.pluginManager.executeHooks(
1586
1624
  'iteration_end',
1587
1625
  {
1588
- runId: runMgr.id,
1626
+ sessionId: recorder.sessionId,
1627
+ turnId: recorder.turnId,
1589
1628
  iteration: iterationNum,
1590
1629
  signal: this.ctx.abortController.signal,
1591
1630
  },
@@ -1597,7 +1636,7 @@ export class IterationOrchestrator {
1597
1636
 
1598
1637
  await this.ctx.emitEvent({
1599
1638
  type: 'iteration_completed',
1600
- runId: runMgr.id,
1639
+ turnId: recorder.turnId,
1601
1640
  iteration: iterationNum,
1602
1641
  hasToolCalls: true,
1603
1642
  })
@@ -1623,7 +1662,7 @@ export class IterationOrchestrator {
1623
1662
  // wrote down for itself. All three exits spend a turn: the
1624
1663
  // cancellation breaks, the overflow-relief retry continues
1625
1664
  // under a NEW iteration number (so its tokens belong to no
1626
- // later step), and the re-throw ends the run.
1665
+ // later step), and the re-throw ends the turn.
1627
1666
  //
1628
1667
  // What it carries is what the iteration got as far as knowing.
1629
1668
  // `usage` is the same subtraction a successful step makes, so
@@ -1640,10 +1679,10 @@ export class IterationOrchestrator {
1640
1679
  // class of wrong as dropping them and harder to notice, since
1641
1680
  // the ledger would look fuller rather than emptier. That turn's
1642
1681
  // own verdict is already written down; the failure that
1643
- // followed it reaches the caller as the run's error.
1682
+ // followed it reaches the caller as the turn's error.
1644
1683
  if (this.steps.at(-1)?.stepNumber === iterationNum) {
1645
1684
  this.ctx.log.warn('Iteration failed after its step was already recorded', {
1646
- [NAMZU.RUN_ID]: runMgr.id,
1685
+ [NAMZU.TURN_ID]: recorder.turnId,
1647
1686
  [NAMZU.ITERATION]: iterationNum,
1648
1687
  'exception.message': toErrorMessage(err),
1649
1688
  })
@@ -1674,15 +1713,15 @@ export class IterationOrchestrator {
1674
1713
  }
1675
1714
 
1676
1715
  // A Stop that aborted the in-flight turn surfaces here as a
1677
- // thrown abort (the provider stream was raced against the run
1716
+ // thrown abort (the provider stream was raced against the turn
1678
1717
  // signal). Settle it as a CANCELLATION — mirroring the
1679
1718
  // between-iteration cancel at the top of the loop — rather than
1680
1719
  // recording it as an SDK failure (error span + failed activity)
1681
- // and re-throwing. The run then returns cleanly with a
1720
+ // and re-throwing. The turn then returns cleanly with a
1682
1721
  // 'cancelled' stop reason instead of propagating an error.
1683
1722
  if (cancelled) {
1684
- runMgr.setStopReason('cancelled')
1685
- runMgr.markCancelled()
1723
+ recorder.setStopReason('cancelled')
1724
+ recorder.markCancelled()
1686
1725
  break
1687
1726
  }
1688
1727
 
@@ -1690,8 +1729,8 @@ export class IterationOrchestrator {
1690
1729
  // about. `context_length_exceeded` is correctly non-retryable —
1691
1730
  // resending the identical prompt cannot help — but the kernel
1692
1731
  // owns a compaction subsystem that can make the prompt smaller.
1693
- // Without this the run died holding the remedy: the threshold
1694
- // path had simply guessed low, which a run carrying images or a
1732
+ // Without this the turn died holding the remedy: the threshold
1733
+ // path had simply guessed low, which a turn carrying images or a
1695
1734
  // language the chars-per-token ratio does not fit will do.
1696
1735
  //
1697
1736
  // Relief is attempted ONCE per iteration and only when it
@@ -1707,7 +1746,7 @@ export class IterationOrchestrator {
1707
1746
  const shed = await relieveOverflow(this.ctx)
1708
1747
  if (shed) {
1709
1748
  this.ctx.log.info('Retrying the turn after relieving a context overflow', {
1710
- [NAMZU.RUN_ID]: runMgr.id,
1749
+ [NAMZU.TURN_ID]: recorder.turnId,
1711
1750
  [NAMZU.ITERATION]: iterationNum,
1712
1751
  })
1713
1752
  if (iterationActivity) {
@@ -1756,7 +1795,7 @@ export class IterationOrchestrator {
1756
1795
  }
1757
1796
  }
1758
1797
 
1759
- /** Steps completed so far, exposed on the returned `Run`. */
1798
+ /** Steps completed so far, exposed on the returned `Turn`. */
1760
1799
  private readonly steps: StepResult[] = []
1761
1800
 
1762
1801
  getSteps(): readonly StepResult[] {
@@ -1768,17 +1807,17 @@ export class IterationOrchestrator {
1768
1807
  *
1769
1808
  * Every field here was already computed somewhere in the loop; the only
1770
1809
  * new work is subtracting the cumulative counters so the step carries
1771
- * ITS usage rather than the run's running total, which is the number a
1810
+ * ITS usage rather than the turn's running total, which is the number a
1772
1811
  * caller asking "what did this step cost" actually wants.
1773
1812
  */
1774
1813
  /**
1775
- * Take everything queued for this run since the last turn.
1814
+ * Take everything queued for this turn since the last turn.
1776
1815
  *
1777
1816
  * Both channels drain here. `inboundMessages` is the manager's queue —
1778
1817
  * what `continueTask` and `queueMessage` push onto and nothing ever
1779
1818
  * collected. `steering` is the host's, and it could only ride on a tool
1780
1819
  * result, so guidance queued during a turn that called no tools stayed
1781
- * pending until the run ended.
1820
+ * pending until the turn ended.
1782
1821
  *
1783
1822
  * Returns the count so a caller can decide whether a turn is owed. An
1784
1823
  * empty drain must change nothing at all: a `continue` on nothing queued
@@ -1799,7 +1838,7 @@ export class IterationOrchestrator {
1799
1838
  private deliverInbound(): number {
1800
1839
  const queued = this.ctx.inboundMessages?.() ?? []
1801
1840
  for (const message of queued) {
1802
- this.ctx.runMgr.pushMessage(message)
1841
+ this.ctx.recorder.pushMessage(message)
1803
1842
  this.rememberUserMessage(message)
1804
1843
  }
1805
1844
 
@@ -1809,7 +1848,7 @@ export class IterationOrchestrator {
1809
1848
  const stranded = this.ctx.steering?.drain()
1810
1849
  if (stranded) {
1811
1850
  const message = createRuntimeContextMessage(formatSteeringNote(stranded), 'steering')
1812
- this.ctx.runMgr.pushMessage(message)
1851
+ this.ctx.recorder.pushMessage(message)
1813
1852
  this.rememberUserMessage(createRuntimeContextMessage(stranded, 'steering'))
1814
1853
  }
1815
1854
 
@@ -1841,7 +1880,7 @@ export class IterationOrchestrator {
1841
1880
  */
1842
1881
  unfinished?: { finishReason: 'error' | 'cancelled'; failure?: StepFailure }
1843
1882
  }): void {
1844
- const { runMgr } = this.ctx
1883
+ const { recorder } = this.ctx
1845
1884
  const toolCalls = input.response?.message.toolCalls ?? []
1846
1885
  const byId = new Map(input.toolResults.map((r) => [r.toolCallId, r]))
1847
1886
 
@@ -1882,10 +1921,10 @@ export class IterationOrchestrator {
1882
1921
  // tool execution did not end in `tool_calls`.
1883
1922
  finishReason: input.unfinished?.finishReason ?? input.response?.finishReason ?? 'error',
1884
1923
  ...(input.unfinished?.failure ? { failure: input.unfinished.failure } : {}),
1885
- usage: subtractUsage(runMgr.tokenUsage, input.usageBefore),
1924
+ usage: subtractUsage(recorder.tokenUsage, input.usageBefore),
1886
1925
  costDelta: {
1887
- ...runMgr.costInfo,
1888
- totalCost: round6(runMgr.costInfo.totalCost - input.costBefore.totalCost),
1926
+ ...recorder.costInfo,
1927
+ totalCost: round6(recorder.costInfo.totalCost - input.costBefore.totalCost),
1889
1928
  },
1890
1929
  startedAt: input.startedAt,
1891
1930
  durationMs: Date.now() - input.startedAt,
@@ -1902,13 +1941,13 @@ export class IterationOrchestrator {
1902
1941
  // Nothing here is allowed to throw over the failure that is already
1903
1942
  // unwinding — the same rule `settleCancelledTurn` states for the
1904
1943
  // cancellation path. A host callback that throws while being told a
1905
- // turn failed would REPLACE the reason the turn failed, so the run
1944
+ // turn failed would REPLACE the reason the turn failed, so the turn
1906
1945
  // would report the observer's bug and lose the original.
1907
1946
  try {
1908
1947
  this.ctx.onStepFinish?.(step)
1909
1948
  } catch (err) {
1910
1949
  this.ctx.log.warn('onStepFinish threw while recording a failed step', {
1911
- [NAMZU.RUN_ID]: runMgr.id,
1950
+ [NAMZU.TURN_ID]: recorder.turnId,
1912
1951
  'namzu.runtime.step': input.stepNumber,
1913
1952
  'exception.message': toErrorMessage(err),
1914
1953
  })
@@ -1934,7 +1973,7 @@ export class IterationOrchestrator {
1934
1973
  /**
1935
1974
  * The answer a terminal tool produced, or `undefined` to keep looping.
1936
1975
  *
1937
- * Deliberately narrow. A terminal call decides the run only when it is
1976
+ * Deliberately narrow. A terminal call decides the turn only when it is
1938
1977
  * the ONLY call the model made in that turn: a model that asked for
1939
1978
  * other work meant to see those results, and settling here would throw
1940
1979
  * away answers it requested. Same for a failed terminal call — an
@@ -1954,7 +1993,7 @@ export class IterationOrchestrator {
1954
1993
  const callCount = response.message.toolCalls?.length ?? 0
1955
1994
  if (callCount > 1) {
1956
1995
  this.ctx.log.info('Terminal tool shared its turn — relaying instead of settling', {
1957
- [NAMZU.RUN_ID]: this.ctx.runMgr.id,
1996
+ [NAMZU.TURN_ID]: this.ctx.recorder.turnId,
1958
1997
  [GENAI.TOOL_NAME]: terminal[0]?.toolName,
1959
1998
  'namzu.runtime.calls_in_turn': callCount,
1960
1999
  })
@@ -1964,7 +2003,7 @@ export class IterationOrchestrator {
1964
2003
  const hit = terminal[0]
1965
2004
  if (!hit || hit.isError) {
1966
2005
  this.ctx.log.info('Terminal tool failed — returning the error to the model', {
1967
- [NAMZU.RUN_ID]: this.ctx.runMgr.id,
2006
+ [NAMZU.TURN_ID]: this.ctx.recorder.turnId,
1968
2007
  [GENAI.TOOL_NAME]: hit?.toolName,
1969
2008
  })
1970
2009
  return undefined
@@ -1987,7 +2026,7 @@ export class IterationOrchestrator {
1987
2026
  * by the time this runs — `runToolReview` settles it, side effects
1988
2027
  * included, before either of these is consulted — so settling here is
1989
2028
  * worse than discarding an answer the model wanted: the work happened,
1990
- * its results went into the transcript, and the run ended before any
2029
+ * its results went into the transcript, and the turn ended before any
1991
2030
  * model turn could read them. Nothing consumed what was spent, and
1992
2031
  * nothing said so.
1993
2032
  *
@@ -2009,7 +2048,7 @@ export class IterationOrchestrator {
2009
2048
  * avoids it by not pairing.
2010
2049
  *
2011
2050
  * NOT charged to `maxRetries`. That budget bounds a model that cannot
2012
- * satisfy the SCHEMA, and this one did. A run reading two files a turn
2051
+ * satisfy the SCHEMA, and this one did. A turn reading two files a turn
2013
2052
  * while optimistically attaching its answer is making progress, and it
2014
2053
  * must not die reported as `structured_output_failed` — a failure that
2015
2054
  * did not happen. `maxIterations` is the bound for a model that keeps
@@ -2030,7 +2069,7 @@ export class IterationOrchestrator {
2030
2069
  const callCount = response.message.toolCalls?.length ?? 0
2031
2070
  if (callCount > 1) {
2032
2071
  this.ctx.log.info('Structured output shared its turn — relaying instead of settling', {
2033
- [NAMZU.RUN_ID]: this.ctx.runMgr.id,
2072
+ [NAMZU.TURN_ID]: this.ctx.recorder.turnId,
2034
2073
  'namzu.runtime.calls_in_turn': callCount,
2035
2074
  })
2036
2075
  return 'absent'
@@ -2052,7 +2091,7 @@ export class IterationOrchestrator {
2052
2091
  }
2053
2092
 
2054
2093
  private publishStructuredOutput(): void {
2055
- this.ctx.runMgr.setStructuredOutput(this.pendingStructuredOutput)
2094
+ this.ctx.recorder.setStructuredOutput(this.pendingStructuredOutput)
2056
2095
  this.structuredOutputDone = true
2057
2096
  }
2058
2097
 
@@ -2078,10 +2117,11 @@ export class IterationOrchestrator {
2078
2117
  Promise.resolve().then(() => {
2079
2118
  signal.throwIfAborted()
2080
2119
  return reviewer(structuredClone(parsed), {
2081
- runId: this.ctx.runMgr.id,
2082
- iteration: this.ctx.runMgr.currentIteration,
2120
+ sessionId: this.ctx.recorder.sessionId,
2121
+ turnId: this.ctx.recorder.turnId,
2122
+ iteration: this.ctx.recorder.currentIteration,
2083
2123
  signal,
2084
- messages: this.ctx.runMgr.messages,
2124
+ messages: this.ctx.recorder.messages,
2085
2125
  ...reviewRequest,
2086
2126
  generateText: inference.generateText,
2087
2127
  })
@@ -2102,18 +2142,20 @@ export class IterationOrchestrator {
2102
2142
  if (typeof verdict.feedback !== 'string' || verdict.feedback.trim().length === 0)
2103
2143
  throw new Error('Structured reviewer rejection requires feedback')
2104
2144
  this.structuredReviewAttempts++
2105
- this.ctx.runMgr.pushMessage(createRuntimeContextMessage(verdict.feedback, 'answer-review'))
2145
+ this.ctx.recorder.pushMessage(
2146
+ createRuntimeContextMessage(verdict.feedback, 'answer-review'),
2147
+ )
2106
2148
  // Persist both the feedback and its consumed allowance before the
2107
2149
  // next request. This checkpoint is not an approval/park boundary.
2108
2150
  const checkpoint = await this.ctx.checkpointMgr.create(
2109
- this.ctx.runMgr,
2110
- this.ctx.runMgr.currentIteration,
2151
+ this.ctx.recorder,
2152
+ this.ctx.recorder.currentIteration,
2111
2153
  )
2112
2154
  await this.ctx.emitEvent({
2113
2155
  type: 'checkpoint_created',
2114
- runId: this.ctx.runMgr.id,
2156
+ turnId: this.ctx.recorder.turnId,
2115
2157
  checkpointId: checkpoint.id,
2116
- iteration: this.ctx.runMgr.currentIteration,
2158
+ iteration: this.ctx.recorder.currentIteration,
2117
2159
  })
2118
2160
  if (signal.aborted) return 'cancelled'
2119
2161
  return this.structuredReviewAttempts >
@@ -2146,10 +2188,11 @@ export class IterationOrchestrator {
2146
2188
  Promise.resolve().then(() => {
2147
2189
  signal.throwIfAborted()
2148
2190
  return reviewer(answer, {
2149
- runId: this.ctx.runMgr.id,
2150
- iteration: this.ctx.runMgr.currentIteration,
2191
+ sessionId: this.ctx.recorder.sessionId,
2192
+ turnId: this.ctx.recorder.turnId,
2193
+ iteration: this.ctx.recorder.currentIteration,
2151
2194
  signal,
2152
- messages: this.ctx.runMgr.messages,
2195
+ messages: this.ctx.recorder.messages,
2153
2196
  ...reviewRequest,
2154
2197
  generateText: inference.generateText,
2155
2198
  })
@@ -2180,14 +2223,14 @@ export class IterationOrchestrator {
2180
2223
  return await stopWhen({
2181
2224
  steps: this.steps,
2182
2225
  latestStep,
2183
- totalUsage: this.ctx.runMgr.tokenUsage,
2184
- totalCost: this.ctx.runMgr.costInfo,
2226
+ totalUsage: this.ctx.recorder.tokenUsage,
2227
+ totalCost: this.ctx.recorder.costInfo,
2185
2228
  })
2186
2229
  } catch (err) {
2187
- // A throwing predicate must not kill a run that is otherwise
2230
+ // A throwing predicate must not kill a turn that is otherwise
2188
2231
  // healthy; failing open keeps the existing budgets in charge.
2189
- this.ctx.log.error('Stop condition threw — continuing the run', {
2190
- [NAMZU.RUN_ID]: this.ctx.runMgr.id,
2232
+ this.ctx.log.error('Stop condition threw — continuing the turn', {
2233
+ [NAMZU.TURN_ID]: this.ctx.recorder.turnId,
2191
2234
  'exception.message': toErrorMessage(err),
2192
2235
  })
2193
2236
  return false
@@ -2202,14 +2245,14 @@ export class IterationOrchestrator {
2202
2245
  }
2203
2246
 
2204
2247
  private async acceptProviderRejectedImage(identity: RequestImageIdentity): Promise<void> {
2205
- const repaired = markProviderRejectedImage(this.ctx.runMgr.messages, identity)
2248
+ const repaired = markProviderRejectedImage(this.ctx.recorder.messages, identity)
2206
2249
  if (repaired.count === 0) {
2207
2250
  throw new Error('Provider-rejected image recovery could not find its durable source image')
2208
2251
  }
2209
- this.ctx.runMgr.replaceMessages(repaired.messages)
2252
+ this.ctx.recorder.replaceMessages(repaired.messages)
2210
2253
  await this.ctx.emitEvent?.({
2211
2254
  type: 'message_history_repaired',
2212
- runId: this.ctx.runMgr.id,
2255
+ turnId: this.ctx.recorder.turnId,
2213
2256
  source: 'provider-rejected-image',
2214
2257
  duplicateToolResultsRemoved: 0,
2215
2258
  orphanedToolResultsRemoved: 0,
@@ -2224,7 +2267,7 @@ export class IterationOrchestrator {
2224
2267
  ): Promise<StopReason | undefined> {
2225
2268
  if (this.ctx.structuredOutput?.mode === 'native') return 'structured_output_failed'
2226
2269
 
2227
- const lastAssistant = [...this.ctx.runMgr.messages]
2270
+ const lastAssistant = [...this.ctx.recorder.messages]
2228
2271
  .reverse()
2229
2272
  .find((m) => m.role === 'assistant')
2230
2273
 
@@ -2234,11 +2277,11 @@ export class IterationOrchestrator {
2234
2277
  lastAssistant.content.length > 0
2235
2278
 
2236
2279
  if (hasResult) return
2237
- // An empty completion may itself have exhausted the run. This fallback
2280
+ // An empty completion may itself have exhausted the turn. This fallback
2238
2281
  // is another billed request, so it must pass the same hard limits as
2239
2282
  // the next normal iteration and preserve their unfinished stop reason.
2240
2283
  const guardResult = this.ctx.guard.beforeIteration(
2241
- this.ctx.runMgr,
2284
+ this.ctx.recorder,
2242
2285
  this.ctx.abortController.signal,
2243
2286
  )
2244
2287
  if (guardResult.shouldStop) return guardResult.stopReason
@@ -2248,18 +2291,26 @@ export class IterationOrchestrator {
2248
2291
  })
2249
2292
 
2250
2293
  try {
2294
+ // The working-memory slot leaves the system run exactly as it does
2295
+ // for a normal step, and for the same cache reason.
2296
+ const workingMemory = splitWorkingMemoryForRequest(this.ctx.recorder.messages)
2251
2297
  const finalHistory = [
2252
- ...this.ctx.runMgr.messages,
2253
- createRuntimeContextMessage(
2254
- `[SYSTEM] Run is ending due to ${reason}. ${CLOSING_RESPONSE_GUIDANCE}`,
2255
- 'limit-finalization',
2256
- ),
2298
+ ...workingMemory.history,
2299
+ ...(workingMemory.context ? [workingMemory.context] : []),
2257
2300
  ]
2258
2301
  const finalMessages = projectRequestRichContent(
2259
2302
  this.projectObservations(finalHistory),
2260
- this.ctx.runConfig.maxRequestRichContentBytes ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES,
2303
+ this.ctx.turnConfig.maxRequestRichContentBytes ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES,
2261
2304
  )
2262
2305
  appendWorkContext(this.stepShaping(), finalMessages, this.steps.length + 1, { model })
2306
+ // The closing directive is the last thing the model reads: after
2307
+ // the working memory and any work context above.
2308
+ finalMessages.push(
2309
+ createRuntimeContextMessage(
2310
+ `[SYSTEM] Turn is ending due to ${reason}. ${CLOSING_RESPONSE_GUIDANCE}`,
2311
+ 'limit-finalization',
2312
+ ),
2313
+ )
2263
2314
  await this.reportUnsupportedToolResults(finalMessages)
2264
2315
 
2265
2316
  // Same cache discipline as the forced-final iteration: keep the
@@ -2283,14 +2334,14 @@ export class IterationOrchestrator {
2283
2334
  tools: finalTools.length > 0 ? finalTools : undefined,
2284
2335
  ...(finalEnforced ? { enforceToolInputSchema: finalEnforced } : {}),
2285
2336
  toolChoice: finalTools.length > 0 ? 'none' : undefined,
2286
- temperature: this.ctx.runConfig.temperature,
2287
- maxTokens: this.ctx.runConfig.maxResponseTokens,
2337
+ temperature: this.ctx.turnConfig.temperature,
2338
+ maxTokens: this.ctx.turnConfig.maxResponseTokens,
2288
2339
  cacheControl: { type: 'auto' },
2289
- ...(this.ctx.runConfig.thinking ? { thinking: this.ctx.runConfig.thinking } : {}),
2340
+ ...(this.ctx.turnConfig.thinking ? { thinking: this.ctx.turnConfig.thinking } : {}),
2290
2341
  // This turn is a hand-maintained duplicate of the one above, which
2291
2342
  // is exactly the shape a field goes missing from — so it is tested
2292
2343
  // separately rather than assumed to have been kept in step.
2293
- ...(this.ctx.runConfig.effort ? { effort: this.ctx.runConfig.effort } : {}),
2344
+ ...(this.ctx.turnConfig.effort ? { effort: this.ctx.turnConfig.effort } : {}),
2294
2345
  // Cancellable too: a Stop during the closing summary must not
2295
2346
  // stream to completion.
2296
2347
  signal: this.ctx.abortController.signal,
@@ -2307,7 +2358,7 @@ export class IterationOrchestrator {
2307
2358
  model: servingMember.model ?? model,
2308
2359
  chainIndex: servingMember.index,
2309
2360
  }
2310
- this.ctx.runMgr.accumulateUsage(response.usage, {
2361
+ this.ctx.recorder.accumulateUsage(response.usage, {
2311
2362
  providerId: servedBy.providerId,
2312
2363
  model: servedBy.model,
2313
2364
  })
@@ -2326,19 +2377,19 @@ export class IterationOrchestrator {
2326
2377
  },
2327
2378
  response.message.textParts,
2328
2379
  )
2329
- this.ctx.runMgr.pushMessage(assistantMsg)
2380
+ this.ctx.recorder.pushMessage(assistantMsg)
2330
2381
 
2331
2382
  const finalMessageId = generateMessageId()
2332
2383
  await this.ctx.emitEvent({
2333
2384
  type: 'message_started',
2334
- runId: this.ctx.runMgr.id,
2335
- iteration: this.ctx.runMgr.currentIteration,
2385
+ turnId: this.ctx.recorder.turnId,
2386
+ iteration: this.ctx.recorder.currentIteration,
2336
2387
  messageId: finalMessageId,
2337
2388
  })
2338
2389
  await this.ctx.emitEvent({
2339
2390
  type: 'message_completed',
2340
- runId: this.ctx.runMgr.id,
2341
- iteration: this.ctx.runMgr.currentIteration,
2391
+ turnId: this.ctx.recorder.turnId,
2392
+ iteration: this.ctx.recorder.currentIteration,
2342
2393
  messageId: finalMessageId,
2343
2394
  stopReason: 'forced_finalize',
2344
2395
  usage: response.usage,