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