@qduc/term2 0.27.0 → 0.28.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 (860) hide show
  1. package/README.md +9 -7
  2. package/dist/acp-v2/session-backend.d.ts +0 -1
  3. package/dist/acp-v2/session-backend.d.ts.map +1 -1
  4. package/dist/acp-v2/session-backend.js +0 -1
  5. package/dist/acp-v2/session-backend.js.map +1 -1
  6. package/dist/agent.d.ts +4 -1
  7. package/dist/agent.d.ts.map +1 -1
  8. package/dist/agent.js +6 -2
  9. package/dist/agent.js.map +1 -1
  10. package/dist/app-helpers.d.ts +0 -2
  11. package/dist/app-helpers.d.ts.map +1 -1
  12. package/dist/app-helpers.js +1 -1
  13. package/dist/app-helpers.js.map +1 -1
  14. package/dist/app.d.ts +9 -2
  15. package/dist/app.d.ts.map +1 -1
  16. package/dist/app.js +65 -12
  17. package/dist/app.js.map +1 -1
  18. package/dist/build-info.json +6 -0
  19. package/dist/cli.js +192 -41
  20. package/dist/cli.js.map +1 -1
  21. package/dist/commands/auto-approve-command.d.ts.map +1 -1
  22. package/dist/commands/auto-approve-command.js +2 -6
  23. package/dist/commands/auto-approve-command.js.map +1 -1
  24. package/dist/commands/effort-command.js +1 -1
  25. package/dist/commands/effort-command.js.map +1 -1
  26. package/dist/commands/goal-command.d.ts +8 -0
  27. package/dist/commands/goal-command.d.ts.map +1 -0
  28. package/dist/commands/goal-command.js +49 -0
  29. package/dist/commands/goal-command.js.map +1 -0
  30. package/dist/commands/handoff-command.js +1 -1
  31. package/dist/commands/handoff-command.js.map +1 -1
  32. package/dist/commands/mode-commands.d.ts +5 -1
  33. package/dist/commands/mode-commands.d.ts.map +1 -1
  34. package/dist/commands/mode-commands.js +14 -2
  35. package/dist/commands/mode-commands.js.map +1 -1
  36. package/dist/commands/model-command.js +1 -1
  37. package/dist/commands/model-command.js.map +1 -1
  38. package/dist/commands/resume-command.js +1 -1
  39. package/dist/commands/resume-command.js.map +1 -1
  40. package/dist/commands/rewind-command.d.ts.map +1 -1
  41. package/dist/commands/rewind-command.js +8 -4
  42. package/dist/commands/rewind-command.js.map +1 -1
  43. package/dist/commands/sandbox-command.js +1 -1
  44. package/dist/components/ErrorBoundary.d.ts.map +1 -1
  45. package/dist/components/ErrorBoundary.js +1 -3
  46. package/dist/components/ErrorBoundary.js.map +1 -1
  47. package/dist/components/InputBox.d.ts +4 -2
  48. package/dist/components/InputBox.d.ts.map +1 -1
  49. package/dist/components/InputBox.js +30 -7
  50. package/dist/components/InputBox.js.map +1 -1
  51. package/dist/components/MarkdownRenderer.js +1 -1
  52. package/dist/components/MarkdownRenderer.js.map +1 -1
  53. package/dist/components/common/MenuContainer.d.ts.map +1 -1
  54. package/dist/components/common/MenuContainer.js +8 -9
  55. package/dist/components/common/MenuContainer.js.map +1 -1
  56. package/dist/components/input/ApplicationInputSurface.d.ts +1 -1
  57. package/dist/components/input/ApplicationInputSurface.d.ts.map +1 -1
  58. package/dist/components/input/ApplicationInputSurface.js +5 -2
  59. package/dist/components/input/ApplicationInputSurface.js.map +1 -1
  60. package/dist/components/input/FirstRunSetupPrompt.d.ts.map +1 -1
  61. package/dist/components/input/FirstRunSetupPrompt.js +3 -4
  62. package/dist/components/input/FirstRunSetupPrompt.js.map +1 -1
  63. package/dist/components/input/MenuSurface.d.ts.map +1 -1
  64. package/dist/components/input/MenuSurface.js +9 -3
  65. package/dist/components/input/MenuSurface.js.map +1 -1
  66. package/dist/components/input/PendingQueueList.js +1 -1
  67. package/dist/components/input/ResumeMenuSession.js +1 -1
  68. package/dist/components/input/ResumeMenuSession.js.map +1 -1
  69. package/dist/components/input/menu-bindings.d.ts.map +1 -1
  70. package/dist/components/input/menu-bindings.js +1 -1
  71. package/dist/components/input/menu-bindings.js.map +1 -1
  72. package/dist/components/input/menu-registry.d.ts +0 -3
  73. package/dist/components/input/menu-registry.d.ts.map +1 -1
  74. package/dist/components/input/menu-registry.js +0 -3
  75. package/dist/components/input/menu-registry.js.map +1 -1
  76. package/dist/components/input/triggers.d.ts +0 -1
  77. package/dist/components/input/triggers.d.ts.map +1 -1
  78. package/dist/components/input/triggers.js +1 -1
  79. package/dist/components/input/triggers.js.map +1 -1
  80. package/dist/components/layout/BackgroundTaskManager.js +1 -1
  81. package/dist/components/layout/BackgroundTasksPanel.d.ts +0 -2
  82. package/dist/components/layout/BackgroundTasksPanel.d.ts.map +1 -1
  83. package/dist/components/layout/BackgroundTasksPanel.js +0 -1
  84. package/dist/components/layout/BackgroundTasksPanel.js.map +1 -1
  85. package/dist/components/layout/Banner.d.ts.map +1 -1
  86. package/dist/components/layout/Banner.js +2 -1
  87. package/dist/components/layout/Banner.js.map +1 -1
  88. package/dist/components/layout/BottomArea.d.ts.map +1 -1
  89. package/dist/components/layout/BottomArea.js +32 -12
  90. package/dist/components/layout/BottomArea.js.map +1 -1
  91. package/dist/components/layout/DiffView.d.ts +1 -1
  92. package/dist/components/layout/DiffView.d.ts.map +1 -1
  93. package/dist/components/layout/DiffView.js +1 -1
  94. package/dist/components/layout/DiffView.js.map +1 -1
  95. package/dist/components/layout/StatusBar.d.ts.map +1 -1
  96. package/dist/components/layout/StatusBar.js +14 -11
  97. package/dist/components/layout/StatusBar.js.map +1 -1
  98. package/dist/components/menu/CopyMenu.js +1 -1
  99. package/dist/components/menu/McpSelectionMenu.js +1 -1
  100. package/dist/components/menu/ModelSelectionMenu.d.ts.map +1 -1
  101. package/dist/components/menu/ModelSelectionMenu.js +4 -1
  102. package/dist/components/menu/ModelSelectionMenu.js.map +1 -1
  103. package/dist/components/menu/PathSelectionMenu.js +1 -1
  104. package/dist/components/menu/ProfileSelectionMenu.d.ts.map +1 -1
  105. package/dist/components/menu/ProfileSelectionMenu.js +6 -4
  106. package/dist/components/menu/ProfileSelectionMenu.js.map +1 -1
  107. package/dist/components/menu/ProviderSelectionMenu.js +7 -7
  108. package/dist/components/menu/ProviderSelectionMenu.js.map +1 -1
  109. package/dist/components/menu/ResumeSelectionMenu.d.ts +1 -1
  110. package/dist/components/menu/ResumeSelectionMenu.d.ts.map +1 -1
  111. package/dist/components/menu/ResumeSelectionMenu.js +33 -6
  112. package/dist/components/menu/ResumeSelectionMenu.js.map +1 -1
  113. package/dist/components/menu/RewindMenu.js +1 -1
  114. package/dist/components/menu/SettingsSelectionMenu.d.ts.map +1 -1
  115. package/dist/components/menu/SettingsSelectionMenu.js +6 -6
  116. package/dist/components/menu/SettingsSelectionMenu.js.map +1 -1
  117. package/dist/components/menu/SettingsValueSelectionMenu.d.ts.map +1 -1
  118. package/dist/components/menu/SettingsValueSelectionMenu.js +14 -5
  119. package/dist/components/menu/SettingsValueSelectionMenu.js.map +1 -1
  120. package/dist/components/menu/SkillSelectionMenu.d.ts.map +1 -1
  121. package/dist/components/menu/SkillSelectionMenu.js +6 -4
  122. package/dist/components/menu/SkillSelectionMenu.js.map +1 -1
  123. package/dist/components/menu/StandaloneModelPickerApp.d.ts +1 -1
  124. package/dist/components/menu/StandaloneModelPickerApp.d.ts.map +1 -1
  125. package/dist/components/menu/StandaloneModelPickerApp.js +1 -1
  126. package/dist/components/menu/StandaloneModelPickerApp.js.map +1 -1
  127. package/dist/components/menu/SubagentPoolSelectionMenu.d.ts +1 -1
  128. package/dist/components/menu/SubagentPoolSelectionMenu.d.ts.map +1 -1
  129. package/dist/components/menu/SubagentPoolSelectionMenu.js +5 -5
  130. package/dist/components/menu/SubagentPoolSelectionMenu.js.map +1 -1
  131. package/dist/components/menu/settings-value-formatter.d.ts +0 -1
  132. package/dist/components/menu/settings-value-formatter.d.ts.map +1 -1
  133. package/dist/components/menu/settings-value-formatter.js +7 -1
  134. package/dist/components/menu/settings-value-formatter.js.map +1 -1
  135. package/dist/components/message/CommandMessage.d.ts.map +1 -1
  136. package/dist/components/message/CommandMessage.js +15 -3
  137. package/dist/components/message/CommandMessage.js.map +1 -1
  138. package/dist/components/message/command-message-helpers.d.ts +3 -0
  139. package/dist/components/message/command-message-helpers.d.ts.map +1 -1
  140. package/dist/components/message/command-message-helpers.js +19 -0
  141. package/dist/components/message/command-message-helpers.js.map +1 -1
  142. package/dist/components/prompt/ApprovalPrompt.d.ts +1 -0
  143. package/dist/components/prompt/ApprovalPrompt.d.ts.map +1 -1
  144. package/dist/components/prompt/ApprovalPrompt.js +139 -69
  145. package/dist/components/prompt/ApprovalPrompt.js.map +1 -1
  146. package/dist/components/prompt/ConfirmPrompt.js +1 -1
  147. package/dist/components/prompt/QueuePausedPrompt.d.ts.map +1 -1
  148. package/dist/components/prompt/QueuePausedPrompt.js +7 -7
  149. package/dist/components/prompt/QueuePausedPrompt.js.map +1 -1
  150. package/dist/context/InputContext.d.ts +1 -2
  151. package/dist/context/InputContext.d.ts.map +1 -1
  152. package/dist/context/InputContext.js +1 -1
  153. package/dist/context/InputContext.js.map +1 -1
  154. package/dist/contracts/conversation-items.d.ts +3 -1
  155. package/dist/contracts/conversation-items.d.ts.map +1 -1
  156. package/dist/contracts/conversation.d.ts +2 -2
  157. package/dist/contracts/conversation.d.ts.map +1 -1
  158. package/dist/contracts/conversation.js +0 -2
  159. package/dist/contracts/conversation.js.map +1 -1
  160. package/dist/contracts/provider-input.d.ts +1 -0
  161. package/dist/contracts/provider-input.d.ts.map +1 -1
  162. package/dist/contracts/streamed-model-turn.d.ts +2 -0
  163. package/dist/contracts/streamed-model-turn.d.ts.map +1 -1
  164. package/dist/gateway/assertion.d.ts +0 -1
  165. package/dist/gateway/assertion.d.ts.map +1 -1
  166. package/dist/gateway/assertion.js +1 -2
  167. package/dist/gateway/assertion.js.map +1 -1
  168. package/dist/gateway/gateway.d.ts +1 -2
  169. package/dist/gateway/gateway.d.ts.map +1 -1
  170. package/dist/gateway/gateway.js +1 -2
  171. package/dist/gateway/gateway.js.map +1 -1
  172. package/dist/gateway/persistence/retention.d.ts +0 -1
  173. package/dist/gateway/persistence/retention.d.ts.map +1 -1
  174. package/dist/gateway/persistence/retention.js +1 -1
  175. package/dist/gateway/persistence/retention.js.map +1 -1
  176. package/dist/gateway/persistence/session-snapshot.d.ts +0 -1
  177. package/dist/gateway/persistence/session-snapshot.d.ts.map +1 -1
  178. package/dist/gateway/persistence/session-snapshot.js +1 -1
  179. package/dist/gateway/persistence/session-snapshot.js.map +1 -1
  180. package/dist/gateway/persistence/storage.d.ts +0 -3
  181. package/dist/gateway/persistence/storage.d.ts.map +1 -1
  182. package/dist/gateway/persistence/storage.js +2 -2
  183. package/dist/gateway/persistence/storage.js.map +1 -1
  184. package/dist/gateway/runtime-factory.d.ts +0 -2
  185. package/dist/gateway/runtime-factory.d.ts.map +1 -1
  186. package/dist/gateway/runtime-factory.js +2 -2
  187. package/dist/gateway/runtime-factory.js.map +1 -1
  188. package/dist/gateway/safe-log.d.ts +0 -1
  189. package/dist/gateway/safe-log.d.ts.map +1 -1
  190. package/dist/gateway/safe-log.js +1 -4
  191. package/dist/gateway/safe-log.js.map +1 -1
  192. package/dist/gateway/settings-rpc.d.ts +2 -15
  193. package/dist/gateway/settings-rpc.d.ts.map +1 -1
  194. package/dist/gateway/settings-rpc.js +5 -5
  195. package/dist/gateway/settings-rpc.js.map +1 -1
  196. package/dist/gateway/worker-boundary.d.ts +0 -4
  197. package/dist/gateway/worker-boundary.d.ts.map +1 -1
  198. package/dist/gateway/worker-boundary.js +2 -2
  199. package/dist/gateway/worker-boundary.js.map +1 -1
  200. package/dist/hooks/path-completion-filter.d.ts +1 -1
  201. package/dist/hooks/path-completion-filter.d.ts.map +1 -1
  202. package/dist/hooks/path-completion-filter.js +1 -1
  203. package/dist/hooks/path-completion-filter.js.map +1 -1
  204. package/dist/hooks/settings-completion-logic.d.ts.map +1 -1
  205. package/dist/hooks/settings-completion-logic.js +5 -1
  206. package/dist/hooks/settings-completion-logic.js.map +1 -1
  207. package/dist/hooks/use-app-commands.d.ts +5 -6
  208. package/dist/hooks/use-app-commands.d.ts.map +1 -1
  209. package/dist/hooks/use-app-commands.js +21 -8
  210. package/dist/hooks/use-app-commands.js.map +1 -1
  211. package/dist/hooks/use-app-keyboard-shortcuts.d.ts +2 -1
  212. package/dist/hooks/use-app-keyboard-shortcuts.d.ts.map +1 -1
  213. package/dist/hooks/use-app-keyboard-shortcuts.js +38 -1
  214. package/dist/hooks/use-app-keyboard-shortcuts.js.map +1 -1
  215. package/dist/hooks/use-conversation.d.ts +7 -2
  216. package/dist/hooks/use-conversation.d.ts.map +1 -1
  217. package/dist/hooks/use-conversation.js +39 -2
  218. package/dist/hooks/use-conversation.js.map +1 -1
  219. package/dist/hooks/use-escape-key.js +1 -1
  220. package/dist/hooks/use-escape-key.js.map +1 -1
  221. package/dist/hooks/use-first-run-setup.d.ts +0 -1
  222. package/dist/hooks/use-first-run-setup.d.ts.map +1 -1
  223. package/dist/hooks/use-first-run-setup.js +0 -2
  224. package/dist/hooks/use-first-run-setup.js.map +1 -1
  225. package/dist/hooks/use-input-history.d.ts +1 -0
  226. package/dist/hooks/use-input-history.d.ts.map +1 -1
  227. package/dist/hooks/use-input-history.js +1 -0
  228. package/dist/hooks/use-input-history.js.map +1 -1
  229. package/dist/hooks/use-resume-selection.d.ts +1 -2
  230. package/dist/hooks/use-resume-selection.d.ts.map +1 -1
  231. package/dist/hooks/use-resume-selection.js +3 -4
  232. package/dist/hooks/use-resume-selection.js.map +1 -1
  233. package/dist/hooks/use-rewind-selection.d.ts +0 -26
  234. package/dist/hooks/use-rewind-selection.d.ts.map +1 -1
  235. package/dist/hooks/use-rewind-selection.js +0 -94
  236. package/dist/hooks/use-rewind-selection.js.map +1 -1
  237. package/dist/hooks/use-settings-completion.d.ts.map +1 -1
  238. package/dist/hooks/use-settings-completion.js +2 -1
  239. package/dist/hooks/use-settings-completion.js.map +1 -1
  240. package/dist/hooks/use-skill-selection.d.ts +0 -1
  241. package/dist/hooks/use-skill-selection.d.ts.map +1 -1
  242. package/dist/hooks/use-skill-selection.js +0 -1
  243. package/dist/hooks/use-skill-selection.js.map +1 -1
  244. package/dist/hooks/use-subagent-pool-selection.d.ts +11 -1
  245. package/dist/hooks/use-subagent-pool-selection.d.ts.map +1 -1
  246. package/dist/hooks/use-subagent-pool-selection.js +26 -15
  247. package/dist/hooks/use-subagent-pool-selection.js.map +1 -1
  248. package/dist/lib/agent-client.d.ts +8 -2
  249. package/dist/lib/agent-client.d.ts.map +1 -1
  250. package/dist/lib/agent-client.js +45 -8
  251. package/dist/lib/agent-client.js.map +1 -1
  252. package/dist/lib/agent-configuration.d.ts +2 -0
  253. package/dist/lib/agent-configuration.d.ts.map +1 -1
  254. package/dist/lib/agent-configuration.js +3 -0
  255. package/dist/lib/agent-configuration.js.map +1 -1
  256. package/dist/lib/agent-factory.d.ts +3 -0
  257. package/dist/lib/agent-factory.d.ts.map +1 -1
  258. package/dist/lib/agent-factory.js +3 -1
  259. package/dist/lib/agent-factory.js.map +1 -1
  260. package/dist/non-interactive.d.ts +4 -2
  261. package/dist/non-interactive.d.ts.map +1 -1
  262. package/dist/non-interactive.js +23 -2
  263. package/dist/non-interactive.js.map +1 -1
  264. package/dist/prompts/durable-goal-context.d.ts +4 -0
  265. package/dist/prompts/durable-goal-context.d.ts.map +1 -0
  266. package/dist/prompts/durable-goal-context.js +24 -0
  267. package/dist/prompts/durable-goal-context.js.map +1 -0
  268. package/dist/prompts/durable-goal-context.test.ts +56 -0
  269. package/dist/prompts/durable-goal-context.ts +27 -0
  270. package/dist/providers/ai-sdk-streamed-model.d.ts +0 -5
  271. package/dist/providers/ai-sdk-streamed-model.d.ts.map +1 -1
  272. package/dist/providers/ai-sdk-streamed-model.js +1 -1
  273. package/dist/providers/ai-sdk-streamed-model.js.map +1 -1
  274. package/dist/providers/codex-auth.d.ts +1 -18
  275. package/dist/providers/codex-auth.d.ts.map +1 -1
  276. package/dist/providers/codex-auth.js +6 -19
  277. package/dist/providers/codex-auth.js.map +1 -1
  278. package/dist/providers/codex-compact.js +1 -1
  279. package/dist/providers/codex-compact.js.map +1 -1
  280. package/dist/providers/codex-responses-model.d.ts +1 -2
  281. package/dist/providers/codex-responses-model.d.ts.map +1 -1
  282. package/dist/providers/codex-responses-model.js +3 -2
  283. package/dist/providers/codex-responses-model.js.map +1 -1
  284. package/dist/providers/codex-turn-converter.d.ts +1 -3
  285. package/dist/providers/codex-turn-converter.d.ts.map +1 -1
  286. package/dist/providers/codex-turn-converter.js +2 -2
  287. package/dist/providers/codex-turn-converter.js.map +1 -1
  288. package/dist/providers/codex.provider.d.ts +1 -1
  289. package/dist/providers/codex.provider.d.ts.map +1 -1
  290. package/dist/providers/codex.provider.js +1 -1
  291. package/dist/providers/codex.provider.js.map +1 -1
  292. package/dist/providers/common/openai-compatible-messages.d.ts +0 -1
  293. package/dist/providers/common/openai-compatible-messages.d.ts.map +1 -1
  294. package/dist/providers/common/openai-compatible-messages.js +0 -30
  295. package/dist/providers/common/openai-compatible-messages.js.map +1 -1
  296. package/dist/providers/common/openai-compatible-utils.d.ts +0 -8
  297. package/dist/providers/common/openai-compatible-utils.d.ts.map +1 -1
  298. package/dist/providers/common/openai-compatible-utils.js +0 -23
  299. package/dist/providers/common/openai-compatible-utils.js.map +1 -1
  300. package/dist/providers/grok-auth.d.ts +1 -33
  301. package/dist/providers/grok-auth.d.ts.map +1 -1
  302. package/dist/providers/grok-auth.js +9 -9
  303. package/dist/providers/grok-auth.js.map +1 -1
  304. package/dist/providers/grok.provider.d.ts +0 -1
  305. package/dist/providers/grok.provider.d.ts.map +1 -1
  306. package/dist/providers/grok.provider.js +1 -1
  307. package/dist/providers/grok.provider.js.map +1 -1
  308. package/dist/providers/llama-cpp.provider.d.ts +0 -1
  309. package/dist/providers/llama-cpp.provider.d.ts.map +1 -1
  310. package/dist/providers/llama-cpp.provider.js +1 -1
  311. package/dist/providers/llama-cpp.provider.js.map +1 -1
  312. package/dist/providers/oauth-account-store.d.ts +0 -11
  313. package/dist/providers/oauth-account-store.d.ts.map +1 -1
  314. package/dist/providers/oauth-account-store.js +1 -1
  315. package/dist/providers/oauth-account-store.js.map +1 -1
  316. package/dist/providers/openai-compatible-middleware.d.ts +0 -1
  317. package/dist/providers/openai-compatible-middleware.d.ts.map +1 -1
  318. package/dist/providers/openai-compatible-middleware.js +0 -17
  319. package/dist/providers/openai-compatible-middleware.js.map +1 -1
  320. package/dist/providers/openai-compatible.provider.d.ts +0 -1
  321. package/dist/providers/openai-compatible.provider.d.ts.map +1 -1
  322. package/dist/providers/openai-compatible.provider.js +1 -1
  323. package/dist/providers/openai-compatible.provider.js.map +1 -1
  324. package/dist/providers/openai-request-prefix-binding.d.ts +0 -1
  325. package/dist/providers/openai-request-prefix-binding.d.ts.map +1 -1
  326. package/dist/providers/openai-request-prefix-binding.js +0 -3
  327. package/dist/providers/openai-request-prefix-binding.js.map +1 -1
  328. package/dist/providers/openai-responses-model.d.ts +1 -6
  329. package/dist/providers/openai-responses-model.d.ts.map +1 -1
  330. package/dist/providers/openai-responses-model.js +2 -1
  331. package/dist/providers/openai-responses-model.js.map +1 -1
  332. package/dist/providers/opencode-go-usage.d.ts +0 -2
  333. package/dist/providers/opencode-go-usage.d.ts.map +1 -1
  334. package/dist/providers/opencode-go-usage.js +1 -1
  335. package/dist/providers/opencode-go-usage.js.map +1 -1
  336. package/dist/providers/opencode-session.d.ts +0 -6
  337. package/dist/providers/opencode-session.d.ts.map +1 -1
  338. package/dist/providers/opencode-session.js +2 -2
  339. package/dist/providers/opencode-session.js.map +1 -1
  340. package/dist/providers/provider-opaque-compatibility.d.ts +3 -1
  341. package/dist/providers/provider-opaque-compatibility.d.ts.map +1 -1
  342. package/dist/providers/provider-opaque-compatibility.js +19 -2
  343. package/dist/providers/provider-opaque-compatibility.js.map +1 -1
  344. package/dist/providers/provider-service.d.ts +0 -2
  345. package/dist/providers/provider-service.d.ts.map +1 -1
  346. package/dist/providers/provider-service.js +1 -1
  347. package/dist/providers/provider-service.js.map +1 -1
  348. package/dist/providers/responses-websocket-sessions.d.ts +0 -1
  349. package/dist/providers/responses-websocket-sessions.d.ts.map +1 -1
  350. package/dist/providers/responses-websocket-sessions.js +1 -1
  351. package/dist/providers/responses-websocket-sessions.js.map +1 -1
  352. package/dist/providers/web-search/exa.provider.d.ts +2 -3
  353. package/dist/providers/web-search/exa.provider.d.ts.map +1 -1
  354. package/dist/providers/web-search/exa.provider.js +1 -1
  355. package/dist/providers/web-search/exa.provider.js.map +1 -1
  356. package/dist/providers/web-search/index.d.ts +1 -1
  357. package/dist/providers/web-search/index.d.ts.map +1 -1
  358. package/dist/providers/web-search/index.js +1 -1
  359. package/dist/providers/web-search/index.js.map +1 -1
  360. package/dist/providers/web-search/tavily.provider.d.ts +2 -3
  361. package/dist/providers/web-search/tavily.provider.d.ts.map +1 -1
  362. package/dist/providers/web-search/tavily.provider.js +1 -1
  363. package/dist/providers/web-search/tavily.provider.js.map +1 -1
  364. package/dist/providers/websocket-abort-race.d.ts +0 -2
  365. package/dist/providers/websocket-abort-race.d.ts.map +1 -1
  366. package/dist/providers/websocket-abort-race.js +1 -1
  367. package/dist/providers/websocket-abort-race.js.map +1 -1
  368. package/dist/services/agent-runtime/application-run-loop.d.ts +15 -3
  369. package/dist/services/agent-runtime/application-run-loop.d.ts.map +1 -1
  370. package/dist/services/agent-runtime/application-run-loop.js +224 -429
  371. package/dist/services/agent-runtime/application-run-loop.js.map +1 -1
  372. package/dist/services/agent-runtime/context-compaction/index.d.ts +0 -1
  373. package/dist/services/agent-runtime/context-compaction/index.d.ts.map +1 -1
  374. package/dist/services/agent-runtime/context-compaction/index.js +1 -1
  375. package/dist/services/agent-runtime/context-compaction/index.js.map +1 -1
  376. package/dist/services/agent-runtime/generation-guard.d.ts +0 -4
  377. package/dist/services/agent-runtime/generation-guard.d.ts.map +1 -1
  378. package/dist/services/agent-runtime/generation-guard.js +2 -2
  379. package/dist/services/agent-runtime/generation-guard.js.map +1 -1
  380. package/dist/services/agent-runtime/index.d.ts +2 -3
  381. package/dist/services/agent-runtime/index.d.ts.map +1 -1
  382. package/dist/services/agent-runtime/index.js +0 -4
  383. package/dist/services/agent-runtime/index.js.map +1 -1
  384. package/dist/services/agent-runtime/model-resolver.d.ts +16 -3
  385. package/dist/services/agent-runtime/model-resolver.d.ts.map +1 -1
  386. package/dist/services/agent-runtime/model-resolver.js +37 -14
  387. package/dist/services/agent-runtime/model-resolver.js.map +1 -1
  388. package/dist/services/agent-runtime/scope-resolver.d.ts +0 -5
  389. package/dist/services/agent-runtime/scope-resolver.d.ts.map +1 -1
  390. package/dist/services/agent-runtime/scope-resolver.js +0 -7
  391. package/dist/services/agent-runtime/scope-resolver.js.map +1 -1
  392. package/dist/services/agent-runtime/tool-call-execution.d.ts +65 -0
  393. package/dist/services/agent-runtime/tool-call-execution.d.ts.map +1 -0
  394. package/dist/services/agent-runtime/tool-call-execution.js +250 -0
  395. package/dist/services/agent-runtime/tool-call-execution.js.map +1 -0
  396. package/dist/services/agent-runtime/turn-input-mailbox.d.ts +33 -0
  397. package/dist/services/agent-runtime/turn-input-mailbox.d.ts.map +1 -0
  398. package/dist/services/agent-runtime/turn-input-mailbox.js +98 -0
  399. package/dist/services/agent-runtime/turn-input-mailbox.js.map +1 -0
  400. package/dist/services/agent-stream.d.ts +2 -0
  401. package/dist/services/agent-stream.d.ts.map +1 -1
  402. package/dist/services/agent-stream.js.map +1 -1
  403. package/dist/services/approval/non-interactive-approval-policy.d.ts +0 -1
  404. package/dist/services/approval/non-interactive-approval-policy.d.ts.map +1 -1
  405. package/dist/services/approval/non-interactive-approval-policy.js +1 -1
  406. package/dist/services/approval/non-interactive-approval-policy.js.map +1 -1
  407. package/dist/services/approval/session-read-access.d.ts +0 -1
  408. package/dist/services/approval/session-read-access.d.ts.map +1 -1
  409. package/dist/services/approval/session-read-access.js +1 -1
  410. package/dist/services/approval/session-read-access.js.map +1 -1
  411. package/dist/services/approval/shell-auto-approval-evaluator.d.ts.map +1 -1
  412. package/dist/services/approval/shell-auto-approval-evaluator.js +2 -4
  413. package/dist/services/approval/shell-auto-approval-evaluator.js.map +1 -1
  414. package/dist/services/approval/shell-auto-approval-resolver.d.ts +0 -3
  415. package/dist/services/approval/shell-auto-approval-resolver.d.ts.map +1 -1
  416. package/dist/services/approval/shell-auto-approval-resolver.js +3 -7
  417. package/dist/services/approval/shell-auto-approval-resolver.js.map +1 -1
  418. package/dist/services/approval/tool-approval-policy-registry.d.ts +1 -0
  419. package/dist/services/approval/tool-approval-policy-registry.d.ts.map +1 -1
  420. package/dist/services/approval/tool-approval-policy-registry.js +4 -2
  421. package/dist/services/approval/tool-approval-policy-registry.js.map +1 -1
  422. package/dist/services/control-socket/control-command.d.ts +6 -0
  423. package/dist/services/control-socket/control-command.d.ts.map +1 -0
  424. package/dist/services/control-socket/control-command.js +161 -0
  425. package/dist/services/control-socket/control-command.js.map +1 -0
  426. package/dist/services/control-socket/control-session-port.d.ts +24 -0
  427. package/dist/services/control-socket/control-session-port.d.ts.map +1 -0
  428. package/dist/services/control-socket/control-session-port.js +185 -0
  429. package/dist/services/control-socket/control-session-port.js.map +1 -0
  430. package/dist/services/control-socket/control-socket.d.ts +130 -0
  431. package/dist/services/control-socket/control-socket.d.ts.map +1 -0
  432. package/dist/services/control-socket/control-socket.js +600 -0
  433. package/dist/services/control-socket/control-socket.js.map +1 -0
  434. package/dist/services/conversation/conversation-adapter.d.ts +0 -4
  435. package/dist/services/conversation/conversation-adapter.d.ts.map +1 -1
  436. package/dist/services/conversation/conversation-adapter.js +1 -1
  437. package/dist/services/conversation/conversation-adapter.js.map +1 -1
  438. package/dist/services/conversation/conversation-checkpoint-provenance.d.ts +17 -0
  439. package/dist/services/conversation/conversation-checkpoint-provenance.d.ts.map +1 -0
  440. package/dist/services/conversation/conversation-checkpoint-provenance.js +130 -0
  441. package/dist/services/conversation/conversation-checkpoint-provenance.js.map +1 -0
  442. package/dist/services/conversation/conversation-decoder.d.ts +4 -0
  443. package/dist/services/conversation/conversation-decoder.d.ts.map +1 -1
  444. package/dist/services/conversation/conversation-decoder.js +80 -2
  445. package/dist/services/conversation/conversation-decoder.js.map +1 -1
  446. package/dist/services/conversation/conversation-events.d.ts +3 -1
  447. package/dist/services/conversation/conversation-events.d.ts.map +1 -1
  448. package/dist/services/conversation/conversation-events.js.map +1 -1
  449. package/dist/services/conversation/conversation-message-projection.d.ts +0 -1
  450. package/dist/services/conversation/conversation-message-projection.d.ts.map +1 -1
  451. package/dist/services/conversation/conversation-message-projection.js +1 -1
  452. package/dist/services/conversation/conversation-message-projection.js.map +1 -1
  453. package/dist/services/conversation/conversation-orchestrator.d.ts +9 -0
  454. package/dist/services/conversation/conversation-orchestrator.d.ts.map +1 -1
  455. package/dist/services/conversation/conversation-orchestrator.js +111 -29
  456. package/dist/services/conversation/conversation-orchestrator.js.map +1 -1
  457. package/dist/services/conversation/conversation-persistence.d.ts +6 -7
  458. package/dist/services/conversation/conversation-persistence.d.ts.map +1 -1
  459. package/dist/services/conversation/conversation-persistence.js +74 -39
  460. package/dist/services/conversation/conversation-persistence.js.map +1 -1
  461. package/dist/services/conversation/conversation-replay.d.ts +1 -0
  462. package/dist/services/conversation/conversation-replay.d.ts.map +1 -1
  463. package/dist/services/conversation/conversation-replay.js +22 -6
  464. package/dist/services/conversation/conversation-replay.js.map +1 -1
  465. package/dist/services/conversation/conversation-result-builder.d.ts.map +1 -1
  466. package/dist/services/conversation/conversation-result-builder.js +7 -1
  467. package/dist/services/conversation/conversation-result-builder.js.map +1 -1
  468. package/dist/services/conversation/conversation-runtime-factory.d.ts +0 -2
  469. package/dist/services/conversation/conversation-runtime-factory.d.ts.map +1 -1
  470. package/dist/services/conversation/conversation-runtime-factory.js.map +1 -1
  471. package/dist/services/conversation/conversation-service.d.ts +6 -0
  472. package/dist/services/conversation/conversation-service.d.ts.map +1 -1
  473. package/dist/services/conversation/conversation-service.js +6 -2
  474. package/dist/services/conversation/conversation-service.js.map +1 -1
  475. package/dist/services/conversation/conversation-state-projector.d.ts +0 -1
  476. package/dist/services/conversation/conversation-state-projector.d.ts.map +1 -1
  477. package/dist/services/conversation/conversation-state-projector.js +1 -1
  478. package/dist/services/conversation/conversation-state-projector.js.map +1 -1
  479. package/dist/services/conversation/conversation-state-schema.d.ts +0 -20
  480. package/dist/services/conversation/conversation-state-schema.d.ts.map +1 -1
  481. package/dist/services/conversation/conversation-state-schema.js +1 -1
  482. package/dist/services/conversation/conversation-state-schema.js.map +1 -1
  483. package/dist/services/conversation/conversation-turn-items.d.ts +0 -10
  484. package/dist/services/conversation/conversation-turn-items.d.ts.map +1 -1
  485. package/dist/services/conversation/conversation-turn-items.js +4 -13
  486. package/dist/services/conversation/conversation-turn-items.js.map +1 -1
  487. package/dist/services/conversation/durable-goal.d.ts +4 -0
  488. package/dist/services/conversation/durable-goal.d.ts.map +1 -0
  489. package/dist/services/conversation/durable-goal.js +21 -0
  490. package/dist/services/conversation/durable-goal.js.map +1 -0
  491. package/dist/services/conversation/local-checkpoint-projection.d.ts +18 -0
  492. package/dist/services/conversation/local-checkpoint-projection.d.ts.map +1 -0
  493. package/dist/services/conversation/local-checkpoint-projection.js +230 -0
  494. package/dist/services/conversation/local-checkpoint-projection.js.map +1 -0
  495. package/dist/services/conversation/run-item-normalizer.d.ts.map +1 -1
  496. package/dist/services/conversation/run-item-normalizer.js +7 -1
  497. package/dist/services/conversation/run-item-normalizer.js.map +1 -1
  498. package/dist/services/conversation/semantic-replay-classification.d.ts +11 -0
  499. package/dist/services/conversation/semantic-replay-classification.d.ts.map +1 -0
  500. package/dist/services/conversation/semantic-replay-classification.js +13 -0
  501. package/dist/services/conversation/semantic-replay-classification.js.map +1 -0
  502. package/dist/services/conversation/semantic-replay-projection.d.ts +20 -0
  503. package/dist/services/conversation/semantic-replay-projection.d.ts.map +1 -0
  504. package/dist/services/conversation/semantic-replay-projection.js +145 -0
  505. package/dist/services/conversation/semantic-replay-projection.js.map +1 -0
  506. package/dist/services/conversation/session-browser.d.ts +10 -2
  507. package/dist/services/conversation/session-browser.d.ts.map +1 -1
  508. package/dist/services/conversation/session-browser.js +27 -5
  509. package/dist/services/conversation/session-browser.js.map +1 -1
  510. package/dist/services/conversation/session-index/session-index-database.d.ts.map +1 -1
  511. package/dist/services/conversation/session-index/session-index-database.js +40 -28
  512. package/dist/services/conversation/session-index/session-index-database.js.map +1 -1
  513. package/dist/services/conversation/session-index/session-index-schema.d.ts +1 -2
  514. package/dist/services/conversation/session-index/session-index-schema.d.ts.map +1 -1
  515. package/dist/services/conversation/session-index/session-index-schema.js +3 -2
  516. package/dist/services/conversation/session-index/session-index-schema.js.map +1 -1
  517. package/dist/services/conversation/session-index/session-index-service.d.ts +0 -1
  518. package/dist/services/conversation/session-index/session-index-service.d.ts.map +1 -1
  519. package/dist/services/conversation/session-index/session-index-service.js +1 -1
  520. package/dist/services/conversation/session-index/session-index-service.js.map +1 -1
  521. package/dist/services/conversation/session-index/session-index-worker-client.d.ts +0 -1
  522. package/dist/services/conversation/session-index/session-index-worker-client.d.ts.map +1 -1
  523. package/dist/services/conversation/session-index/session-index-worker-client.js +1 -1
  524. package/dist/services/conversation/session-index/session-index-worker-client.js.map +1 -1
  525. package/dist/services/conversation/session-log-lifecycle.d.ts +5 -0
  526. package/dist/services/conversation/session-log-lifecycle.d.ts.map +1 -0
  527. package/dist/services/conversation/session-log-lifecycle.js +7 -0
  528. package/dist/services/conversation/session-log-lifecycle.js.map +1 -0
  529. package/dist/services/decision-shadow/decision-client.d.ts +0 -1
  530. package/dist/services/decision-shadow/decision-client.d.ts.map +1 -1
  531. package/dist/services/decision-shadow/decision-client.js +1 -1
  532. package/dist/services/decision-shadow/decision-client.js.map +1 -1
  533. package/dist/services/file-service.d.ts +0 -2
  534. package/dist/services/file-service.d.ts.map +1 -1
  535. package/dist/services/file-service.js +1 -2
  536. package/dist/services/file-service.js.map +1 -1
  537. package/dist/services/hooks/hook-contracts.d.ts +2 -4
  538. package/dist/services/hooks/hook-contracts.d.ts.map +1 -1
  539. package/dist/services/hooks/hook-contracts.js +3 -4
  540. package/dist/services/hooks/hook-contracts.js.map +1 -1
  541. package/dist/services/hooks/hook-discovery.d.ts +0 -1
  542. package/dist/services/hooks/hook-discovery.d.ts.map +1 -1
  543. package/dist/services/hooks/hook-discovery.js +0 -1
  544. package/dist/services/hooks/hook-discovery.js.map +1 -1
  545. package/dist/services/hooks/hook-editor-shim.d.ts +0 -2
  546. package/dist/services/hooks/hook-editor-shim.d.ts.map +1 -1
  547. package/dist/services/hooks/hook-editor-shim.js +2 -2
  548. package/dist/services/hooks/hook-editor-shim.js.map +1 -1
  549. package/dist/services/hooks/hook-module-loader.d.ts +0 -3
  550. package/dist/services/hooks/hook-module-loader.d.ts.map +1 -1
  551. package/dist/services/hooks/hook-module-loader.js +0 -1
  552. package/dist/services/hooks/hook-module-loader.js.map +1 -1
  553. package/dist/services/hooks/hook-registry.d.ts +0 -1
  554. package/dist/services/hooks/hook-registry.d.ts.map +1 -1
  555. package/dist/services/hooks/hook-registry.js +1 -1
  556. package/dist/services/hooks/hook-registry.js.map +1 -1
  557. package/dist/services/input-surge-guard.d.ts +0 -1
  558. package/dist/services/input-surge-guard.d.ts.map +1 -1
  559. package/dist/services/input-surge-guard.js +1 -1
  560. package/dist/services/input-surge-guard.js.map +1 -1
  561. package/dist/services/logging/conversation-log-events.d.ts +41 -2
  562. package/dist/services/logging/conversation-log-events.d.ts.map +1 -1
  563. package/dist/services/logging/conversation-log-events.js.map +1 -1
  564. package/dist/services/logging/conversation-log-writer.d.ts +3 -11
  565. package/dist/services/logging/conversation-log-writer.d.ts.map +1 -1
  566. package/dist/services/logging/conversation-log-writer.js +51 -45
  567. package/dist/services/logging/conversation-log-writer.js.map +1 -1
  568. package/dist/services/logging/conversation-logger.d.ts +4 -1
  569. package/dist/services/logging/conversation-logger.d.ts.map +1 -1
  570. package/dist/services/logging/conversation-logger.js +22 -2
  571. package/dist/services/logging/conversation-logger.js.map +1 -1
  572. package/dist/services/logging/provider-traffic.d.ts +0 -7
  573. package/dist/services/logging/provider-traffic.d.ts.map +1 -1
  574. package/dist/services/logging/provider-traffic.js +3 -3
  575. package/dist/services/logging/provider-traffic.js.map +1 -1
  576. package/dist/services/mcp/mcp-oauth-provider.d.ts +0 -2
  577. package/dist/services/mcp/mcp-oauth-provider.d.ts.map +1 -1
  578. package/dist/services/mcp/mcp-oauth-provider.js +1 -1
  579. package/dist/services/mcp/mcp-oauth-provider.js.map +1 -1
  580. package/dist/services/mcp/mcp-oauth-store.d.ts +0 -21
  581. package/dist/services/mcp/mcp-oauth-store.d.ts.map +1 -1
  582. package/dist/services/mcp/mcp-oauth-store.js +2 -2
  583. package/dist/services/mcp/mcp-oauth-store.js.map +1 -1
  584. package/dist/services/mcp/mcp-status.d.ts +0 -7
  585. package/dist/services/mcp/mcp-status.d.ts.map +1 -1
  586. package/dist/services/mcp/mcp-status.js +1 -1
  587. package/dist/services/mcp/mcp-status.js.map +1 -1
  588. package/dist/services/memory/memory-capabilities.d.ts +7 -0
  589. package/dist/services/memory/memory-capabilities.d.ts.map +1 -1
  590. package/dist/services/memory/memory-capabilities.js +9 -19
  591. package/dist/services/memory/memory-capabilities.js.map +1 -1
  592. package/dist/services/memory/memory-search.d.ts +0 -1
  593. package/dist/services/memory/memory-search.d.ts.map +1 -1
  594. package/dist/services/memory/memory-search.js +1 -1
  595. package/dist/services/memory/memory-search.js.map +1 -1
  596. package/dist/services/memory/memory-store.d.ts +0 -10
  597. package/dist/services/memory/memory-store.d.ts.map +1 -1
  598. package/dist/services/memory/memory-store.js +1 -1
  599. package/dist/services/memory/memory-store.js.map +1 -1
  600. package/dist/services/models/model-nicknames.d.ts +0 -16
  601. package/dist/services/models/model-nicknames.d.ts.map +1 -1
  602. package/dist/services/models/model-nicknames.js +1 -1
  603. package/dist/services/models/model-nicknames.js.map +1 -1
  604. package/dist/services/models/model-resolution.js +2 -2
  605. package/dist/services/models/model-resolution.js.map +1 -1
  606. package/dist/services/profiles/profile-transition.d.ts +0 -2
  607. package/dist/services/profiles/profile-transition.d.ts.map +1 -1
  608. package/dist/services/profiles/profile-transition.js +1 -1
  609. package/dist/services/profiles/profile-transition.js.map +1 -1
  610. package/dist/services/profiles/registry.d.ts +1 -11
  611. package/dist/services/profiles/registry.d.ts.map +1 -1
  612. package/dist/services/profiles/registry.js +6 -12
  613. package/dist/services/profiles/registry.js.map +1 -1
  614. package/dist/services/profiles/resolver.d.ts +1 -7
  615. package/dist/services/profiles/resolver.d.ts.map +1 -1
  616. package/dist/services/profiles/resolver.js +0 -45
  617. package/dist/services/profiles/resolver.js.map +1 -1
  618. package/dist/services/profiles/schema.d.ts +0 -950
  619. package/dist/services/profiles/schema.d.ts.map +1 -1
  620. package/dist/services/profiles/schema.js +5 -5
  621. package/dist/services/profiles/schema.js.map +1 -1
  622. package/dist/services/retry/conversation-retry-policy.d.ts +0 -5
  623. package/dist/services/retry/conversation-retry-policy.d.ts.map +1 -1
  624. package/dist/services/retry/conversation-retry-policy.js +0 -3
  625. package/dist/services/retry/conversation-retry-policy.js.map +1 -1
  626. package/dist/services/retry/retry-recovery-budget.d.ts +0 -10
  627. package/dist/services/retry/retry-recovery-budget.d.ts.map +1 -1
  628. package/dist/services/retry/retry-recovery-budget.js +1 -1
  629. package/dist/services/retry/retry-recovery-budget.js.map +1 -1
  630. package/dist/services/runtime-setting-router.d.ts +0 -1
  631. package/dist/services/runtime-setting-router.d.ts.map +1 -1
  632. package/dist/services/runtime-setting-router.js +1 -1
  633. package/dist/services/runtime-setting-router.js.map +1 -1
  634. package/dist/services/session/background-task-control.d.ts +1 -1
  635. package/dist/services/session/background-task-control.d.ts.map +1 -1
  636. package/dist/services/session/background-task-control.js +1 -1
  637. package/dist/services/session/background-task-control.js.map +1 -1
  638. package/dist/services/session/initial-input-preparer.d.ts.map +1 -1
  639. package/dist/services/session/initial-input-preparer.js +32 -0
  640. package/dist/services/session/initial-input-preparer.js.map +1 -1
  641. package/dist/services/session/pending-interaction-state.d.ts +6 -0
  642. package/dist/services/session/pending-interaction-state.d.ts.map +1 -1
  643. package/dist/services/session/pending-interaction-state.js +1 -1
  644. package/dist/services/session/pending-interaction-state.js.map +1 -1
  645. package/dist/services/session/session-client-factory.d.ts +1 -11
  646. package/dist/services/session/session-client-factory.d.ts.map +1 -1
  647. package/dist/services/session/session-client-factory.js +1 -6
  648. package/dist/services/session/session-client-factory.js.map +1 -1
  649. package/dist/services/session/session-composition.d.ts +11 -3
  650. package/dist/services/session/session-composition.d.ts.map +1 -1
  651. package/dist/services/session/session-composition.js +44 -8
  652. package/dist/services/session/session-composition.js.map +1 -1
  653. package/dist/services/session/session-input-planner.d.ts +5 -0
  654. package/dist/services/session/session-input-planner.d.ts.map +1 -1
  655. package/dist/services/session/session-input-planner.js +36 -0
  656. package/dist/services/session/session-input-planner.js.map +1 -1
  657. package/dist/services/session/session-stream-processor.d.ts.map +1 -1
  658. package/dist/services/session/session-stream-processor.js +6 -2
  659. package/dist/services/session/session-stream-processor.js.map +1 -1
  660. package/dist/services/session/turn-workflow.d.ts +0 -3
  661. package/dist/services/session/turn-workflow.d.ts.map +1 -1
  662. package/dist/services/session/turn-workflow.js +15 -37
  663. package/dist/services/session/turn-workflow.js.map +1 -1
  664. package/dist/services/session-rollover/session-rollover-brief.d.ts +0 -1
  665. package/dist/services/session-rollover/session-rollover-brief.d.ts.map +1 -1
  666. package/dist/services/session-rollover/session-rollover-brief.js +1 -1
  667. package/dist/services/session-rollover/session-rollover-brief.js.map +1 -1
  668. package/dist/services/settings/custom-provider-normalization.d.ts +0 -1
  669. package/dist/services/settings/custom-provider-normalization.d.ts.map +1 -1
  670. package/dist/services/settings/custom-provider-normalization.js +1 -1
  671. package/dist/services/settings/custom-provider-normalization.js.map +1 -1
  672. package/dist/services/settings/setting-schema-utils.d.ts +0 -2
  673. package/dist/services/settings/setting-schema-utils.d.ts.map +1 -1
  674. package/dist/services/settings/setting-schema-utils.js +0 -11
  675. package/dist/services/settings/setting-schema-utils.js.map +1 -1
  676. package/dist/services/settings/settings-merger.d.ts +0 -4
  677. package/dist/services/settings/settings-merger.d.ts.map +1 -1
  678. package/dist/services/settings/settings-merger.js +1 -1
  679. package/dist/services/settings/settings-merger.js.map +1 -1
  680. package/dist/services/settings/settings-schema.d.ts +41 -25
  681. package/dist/services/settings/settings-schema.d.ts.map +1 -1
  682. package/dist/services/settings/settings-schema.js +11 -5
  683. package/dist/services/settings/settings-schema.js.map +1 -1
  684. package/dist/services/settings/settings-ui-metadata.d.ts +0 -5
  685. package/dist/services/settings/settings-ui-metadata.d.ts.map +1 -1
  686. package/dist/services/settings/settings-ui-metadata.js +2 -2
  687. package/dist/services/settings/settings-ui-metadata.js.map +1 -1
  688. package/dist/services/settings/test-helpers/settings-consumer-inventory.d.ts +0 -1
  689. package/dist/services/settings/test-helpers/settings-consumer-inventory.d.ts.map +1 -1
  690. package/dist/services/settings/test-helpers/settings-consumer-inventory.js +0 -44
  691. package/dist/services/settings/test-helpers/settings-consumer-inventory.js.map +1 -1
  692. package/dist/services/ssh-service.d.ts +0 -23
  693. package/dist/services/ssh-service.d.ts.map +1 -1
  694. package/dist/services/ssh-service.js +1 -1
  695. package/dist/services/ssh-service.js.map +1 -1
  696. package/dist/services/subagents/role-loader.d.ts +0 -6
  697. package/dist/services/subagents/role-loader.d.ts.map +1 -1
  698. package/dist/services/subagents/role-loader.js +12 -6
  699. package/dist/services/subagents/role-loader.js.map +1 -1
  700. package/dist/services/subagents/subagent-notification-store.d.ts +0 -2
  701. package/dist/services/subagents/subagent-notification-store.d.ts.map +1 -1
  702. package/dist/services/subagents/subagent-notification-store.js +1 -1
  703. package/dist/services/subagents/subagent-notification-store.js.map +1 -1
  704. package/dist/services/subagents/subagent-pool-config.d.ts +0 -21
  705. package/dist/services/subagents/subagent-pool-config.d.ts.map +1 -1
  706. package/dist/services/subagents/subagent-pool-config.js +2 -2
  707. package/dist/services/subagents/subagent-pool-config.js.map +1 -1
  708. package/dist/services/subagents/subagent-role-pool-selector.d.ts +5 -4
  709. package/dist/services/subagents/subagent-role-pool-selector.d.ts.map +1 -1
  710. package/dist/services/subagents/subagent-role-pool-selector.js +16 -11
  711. package/dist/services/subagents/subagent-role-pool-selector.js.map +1 -1
  712. package/dist/services/subagents/tool-policy.d.ts +0 -1
  713. package/dist/services/subagents/tool-policy.d.ts.map +1 -1
  714. package/dist/services/subagents/tool-policy.js +1 -1
  715. package/dist/services/subagents/tool-policy.js.map +1 -1
  716. package/dist/services/subagents/types.d.ts +1 -2
  717. package/dist/services/subagents/types.d.ts.map +1 -1
  718. package/dist/services/subagents/types.js +0 -1
  719. package/dist/services/subagents/types.js.map +1 -1
  720. package/dist/services/subagents/utils.d.ts +0 -3
  721. package/dist/services/subagents/utils.d.ts.map +1 -1
  722. package/dist/services/subagents/utils.js +3 -3
  723. package/dist/services/subagents/utils.js.map +1 -1
  724. package/dist/services/tool-call-arguments.d.ts +0 -1
  725. package/dist/services/tool-call-arguments.d.ts.map +1 -1
  726. package/dist/services/tool-call-arguments.js +0 -15
  727. package/dist/services/tool-call-arguments.js.map +1 -1
  728. package/dist/services/tool-execution-ledger.d.ts +0 -4
  729. package/dist/services/tool-execution-ledger.d.ts.map +1 -1
  730. package/dist/services/tool-execution-ledger.js +3 -3
  731. package/dist/services/tool-execution-ledger.js.map +1 -1
  732. package/dist/services/tool-toggles.d.ts +0 -1
  733. package/dist/services/tool-toggles.d.ts.map +1 -1
  734. package/dist/services/tool-toggles.js +0 -3
  735. package/dist/services/tool-toggles.js.map +1 -1
  736. package/dist/services/workspace/active-workspace-root.d.ts +0 -4
  737. package/dist/services/workspace/active-workspace-root.d.ts.map +1 -1
  738. package/dist/services/workspace/active-workspace-root.js +1 -1
  739. package/dist/services/workspace/active-workspace-root.js.map +1 -1
  740. package/dist/services/workspace/worktree-transition.d.ts +0 -2
  741. package/dist/services/workspace/worktree-transition.d.ts.map +1 -1
  742. package/dist/services/workspace/worktree-transition.js +1 -1
  743. package/dist/services/workspace/worktree-transition.js.map +1 -1
  744. package/dist/tools/agent/ask-user-constants.d.ts +0 -2
  745. package/dist/tools/agent/ask-user-constants.d.ts.map +1 -1
  746. package/dist/tools/agent/ask-user-constants.js +0 -2
  747. package/dist/tools/agent/ask-user-constants.js.map +1 -1
  748. package/dist/tools/file/apply-patch.d.ts +0 -4
  749. package/dist/tools/file/apply-patch.d.ts.map +1 -1
  750. package/dist/tools/file/apply-patch.js +3 -5
  751. package/dist/tools/file/apply-patch.js.map +1 -1
  752. package/dist/tools/file/glob.d.ts +1 -2
  753. package/dist/tools/file/glob.d.ts.map +1 -1
  754. package/dist/tools/file/glob.js +0 -1
  755. package/dist/tools/file/glob.js.map +1 -1
  756. package/dist/tools/file/grep.d.ts +1 -2
  757. package/dist/tools/file/grep.d.ts.map +1 -1
  758. package/dist/tools/file/grep.js +1 -3
  759. package/dist/tools/file/grep.js.map +1 -1
  760. package/dist/tools/file/search-replace.d.ts.map +1 -1
  761. package/dist/tools/file/search-replace.js +3 -4
  762. package/dist/tools/file/search-replace.js.map +1 -1
  763. package/dist/tools/session-browser/session-browser-tools.js +1 -1
  764. package/dist/tools/session-browser/session-browser-tools.js.map +1 -1
  765. package/dist/tools/session-rollover/session-rollover-tool.d.ts.map +1 -1
  766. package/dist/tools/session-rollover/session-rollover-tool.js +4 -1
  767. package/dist/tools/session-rollover/session-rollover-tool.js.map +1 -1
  768. package/dist/tools/system/run-code/index.d.ts +4 -4
  769. package/dist/tools/system/run-code/index.d.ts.map +1 -1
  770. package/dist/tools/system/run-code/index.js +1 -4
  771. package/dist/tools/system/run-code/index.js.map +1 -1
  772. package/dist/tools/system/run-code/run-code-execution.d.ts +1 -0
  773. package/dist/tools/system/run-code/run-code-execution.d.ts.map +1 -1
  774. package/dist/tools/system/run-code/run-code-execution.js.map +1 -1
  775. package/dist/tools/system/run-code/run-code-runtime-contract.d.ts +1 -0
  776. package/dist/tools/system/run-code/run-code-runtime-contract.d.ts.map +1 -1
  777. package/dist/tools/system/run-code/run-code-runtime.d.ts +0 -3
  778. package/dist/tools/system/run-code/run-code-runtime.d.ts.map +1 -1
  779. package/dist/tools/system/run-code/run-code-runtime.js +7 -6
  780. package/dist/tools/system/run-code/run-code-runtime.js.map +1 -1
  781. package/dist/tools/system/run-code/run-code.d.ts +1 -1
  782. package/dist/tools/system/run-code/run-code.d.ts.map +1 -1
  783. package/dist/tools/system/run-code/run-code.js +5 -1
  784. package/dist/tools/system/run-code/run-code.js.map +1 -1
  785. package/dist/tools/system/shell.d.ts +1 -2
  786. package/dist/tools/system/shell.d.ts.map +1 -1
  787. package/dist/tools/system/shell.js +5 -4
  788. package/dist/tools/system/shell.js.map +1 -1
  789. package/dist/tools/system/worktree.d.ts +2 -2
  790. package/dist/tools/system/worktree.d.ts.map +1 -1
  791. package/dist/tools/system/worktree.js +1 -2
  792. package/dist/tools/system/worktree.js.map +1 -1
  793. package/dist/tools/types.d.ts +1 -1
  794. package/dist/tools/types.d.ts.map +1 -1
  795. package/dist/types/message.d.ts +0 -1
  796. package/dist/types/message.d.ts.map +1 -1
  797. package/dist/types/message.js +0 -1
  798. package/dist/types/message.js.map +1 -1
  799. package/dist/types/user-turn.d.ts +6 -0
  800. package/dist/types/user-turn.d.ts.map +1 -1
  801. package/dist/types/user-turn.js +1 -0
  802. package/dist/types/user-turn.js.map +1 -1
  803. package/dist/utils/conversation/conversation-utils.d.ts.map +1 -1
  804. package/dist/utils/conversation/conversation-utils.js +1 -2
  805. package/dist/utils/conversation/conversation-utils.js.map +1 -1
  806. package/dist/utils/conversation/static-commit-policy.d.ts.map +1 -1
  807. package/dist/utils/conversation/static-commit-policy.js +1 -0
  808. package/dist/utils/conversation/static-commit-policy.js.map +1 -1
  809. package/dist/utils/ink-render-options.d.ts +1 -0
  810. package/dist/utils/ink-render-options.d.ts.map +1 -1
  811. package/dist/utils/ink-render-options.js +1 -1
  812. package/dist/utils/ink-render-options.js.map +1 -1
  813. package/dist/utils/output/log-truncation.d.ts +0 -1
  814. package/dist/utils/output/log-truncation.d.ts.map +1 -1
  815. package/dist/utils/output/log-truncation.js +0 -3
  816. package/dist/utils/output/log-truncation.js.map +1 -1
  817. package/dist/utils/project-scope.d.ts +16 -0
  818. package/dist/utils/project-scope.d.ts.map +1 -0
  819. package/dist/utils/project-scope.js +62 -0
  820. package/dist/utils/project-scope.js.map +1 -0
  821. package/dist/utils/settings-command.d.ts.map +1 -1
  822. package/dist/utils/settings-command.js +5 -3
  823. package/dist/utils/settings-command.js.map +1 -1
  824. package/dist/utils/shell/sandbox/docker-host-control-grants.d.ts +0 -2
  825. package/dist/utils/shell/sandbox/docker-host-control-grants.d.ts.map +1 -1
  826. package/dist/utils/shell/sandbox/docker-host-control-grants.js +0 -1
  827. package/dist/utils/shell/sandbox/docker-host-control-grants.js.map +1 -1
  828. package/dist/utils/shell/temp-dir.d.ts +0 -1
  829. package/dist/utils/shell/temp-dir.d.ts.map +1 -1
  830. package/dist/utils/shell/temp-dir.js +0 -4
  831. package/dist/utils/shell/temp-dir.js.map +1 -1
  832. package/dist/utils/slash-command-dispatch.d.ts +1 -1
  833. package/dist/utils/slash-command-dispatch.d.ts.map +1 -1
  834. package/dist/utils/slash-command-dispatch.js +35 -3
  835. package/dist/utils/slash-command-dispatch.js.map +1 -1
  836. package/dist/utils/streaming/streaming-speed-tracker.d.ts +0 -9
  837. package/dist/utils/streaming/streaming-speed-tracker.d.ts.map +1 -1
  838. package/dist/utils/streaming/streaming-speed-tracker.js +1 -1
  839. package/dist/utils/streaming/streaming-speed-tracker.js.map +1 -1
  840. package/dist/utils/value-suggestions.d.ts +6 -0
  841. package/dist/utils/value-suggestions.d.ts.map +1 -1
  842. package/dist/utils/value-suggestions.js +23 -6
  843. package/dist/utils/value-suggestions.js.map +1 -1
  844. package/package.json +2 -3
  845. package/dist/gateway/index.d.ts +0 -22
  846. package/dist/gateway/index.d.ts.map +0 -1
  847. package/dist/gateway/index.js +0 -22
  848. package/dist/gateway/index.js.map +0 -1
  849. package/dist/providers/openrouter.d.ts +0 -2
  850. package/dist/providers/openrouter.d.ts.map +0 -1
  851. package/dist/providers/openrouter.js +0 -2
  852. package/dist/providers/openrouter.js.map +0 -1
  853. package/dist/services/agent-runtime/internal.d.ts +0 -15
  854. package/dist/services/agent-runtime/internal.d.ts.map +0 -1
  855. package/dist/services/agent-runtime/internal.js +0 -13
  856. package/dist/services/agent-runtime/internal.js.map +0 -1
  857. package/dist/services/openai-root-selector-parity-observer.d.ts +0 -53
  858. package/dist/services/openai-root-selector-parity-observer.d.ts.map +0 -1
  859. package/dist/services/openai-root-selector-parity-observer.js +0 -62
  860. package/dist/services/openai-root-selector-parity-observer.js.map +0 -1
@@ -3,8 +3,7 @@ import { createContinuationHandle, unwrapContinuationHandle, } from '../../contr
3
3
  import { createAgentStream } from '../agent-stream.js';
4
4
  import { getRunCodeExecutionResult, runCodeExecutionMetadata } from '../../tools/system/run-code/run-code-execution.js';
5
5
  import { isZodToolParameterSchema } from '../../tools/types.js';
6
- import { normalizeToolParameters } from '../../lib/tool-invoke.js';
7
- import { isCancellationError, isHarnessInvariantError } from '../../lib/harness-invariant-error.js';
6
+ import { describeError } from '../../utils/error-helpers.js';
8
7
  import { ApprovalLedger } from './tool-invocation-context.js';
9
8
  import { RunBudget, isRunBudgetInteraction, } from './run-budget.js';
10
9
  import { addTokenUsage, normalizeUsage } from '../../utils/ai/token-usage.js';
@@ -14,6 +13,8 @@ import { getCatalogPricingVersion, getModelPricing } from '../../services/cost/p
14
13
  import { DEFAULT_TOOL_ARGUMENT_RUNAWAY_SIGNATURE, GenerationGuard, GenerationGuardError, GenerationStreamDeadlines, ToolArgumentRunawayGuard, } from './generation-guard.js';
15
14
  import { classifyInLoopModelRetry, sleepWithAbort } from '../retry/in-loop-model-retry.js';
16
15
  import { buildFailureObservation } from '../decision-shadow/failure-observation.js';
16
+ import { TurnInputMailbox } from './turn-input-mailbox.js';
17
+ import { ToolCallExecution } from './tool-call-execution.js';
17
18
  /**
18
19
  * Tool results may carry provider-neutral content parts (for example the
19
20
  * image returned by read_file). Preserve only the known multimodal shape;
@@ -83,8 +84,6 @@ class EventQueue {
83
84
  * turns and silently drop later turns' records.
84
85
  */
85
86
  let nextCostRequestSeq = 0;
86
- let nextToolBatchSeq = 0;
87
- const DEFAULT_MAX_PARALLEL_TOOL_CALLS = 3;
88
87
  /**
89
88
  * Small provider-neutral agent loop. It owns model-turn sequencing and tool
90
89
  * execution; providers only implement `StreamedModelTurn`.
@@ -92,33 +91,15 @@ const DEFAULT_MAX_PARALLEL_TOOL_CALLS = 3;
92
91
  export class ApplicationRunLoop {
93
92
  #deps;
94
93
  #contextCompactionSessionState;
94
+ #turnInputMailbox;
95
95
  #activeAbortController = null;
96
- #runInFlight = false;
97
96
  #segmentGeneration = 0;
98
- /**
99
- * Set when a segment ends holding approvals, meaning the turn is pausing
100
- * rather than finishing. Injections offered during the pause wait here for
101
- * the continuation segment instead of being refused for want of a run.
102
- */
103
- #turnPaused = false;
104
- /**
105
- * Set while a caller that owns turn boundaries has a turn open, from before
106
- * its first request is built until after its last one settles.
107
- *
108
- * `#runInFlight` and `#turnPaused` only ever describe a *segment*, so between
109
- * them they leave every gap in a turn where no run exists yet: the startup
110
- * before the first request (provider model discovery, hooks, input
111
- * preparation) and the backoff before a retry restarts the stream. A turn is
112
- * steerable across those gaps, and only the caller that opened the turn knows
113
- * they belong to it.
114
- */
115
- #turnOpen = false;
116
- #pendingSteers = [];
117
97
  /** The run whose budget an out-of-band grant applies to, held across a pause. */
118
98
  #activeRunBudgetState;
119
99
  constructor(deps) {
120
100
  this.#deps = deps;
121
101
  this.#contextCompactionSessionState = deps.contextCompactionSessionState ?? { disabled: false };
102
+ this.#turnInputMailbox = new TurnInputMailbox((message, meta) => this.#deps.logDiagnostic?.(message, meta));
122
103
  }
123
104
  #observeTerminalFailure(error, request) {
124
105
  this.#observeDecisionShadow('failure_triage', () => {
@@ -147,25 +128,19 @@ export class ApplicationRunLoop {
147
128
  * be admitted now.
148
129
  */
149
130
  openTurn() {
150
- this.#releasePendingSteers({ reason: 'superseded_by_new_turn' });
151
- this.#turnOpen = true;
152
- this.#turnPaused = false;
131
+ this.#turnInputMailbox.openTurn();
153
132
  }
154
133
  /**
155
134
  * Declare the turn over. Whatever is still waiting had no boundary left, so
156
135
  * it is handed back for the caller to send as its own turn.
157
136
  */
158
137
  closeTurn() {
159
- this.#turnOpen = false;
160
- this.#turnPaused = false;
161
- this.#releasePendingSteers({ reason: 'turn_closed' });
138
+ this.#turnInputMailbox.closeTurn();
162
139
  }
163
140
  abort() {
164
141
  this.abortSegment();
165
142
  // An aborted turn will not resume, so nothing may keep waiting on it.
166
- this.#turnOpen = false;
167
- this.#turnPaused = false;
168
- this.#releasePendingSteers({ reason: 'aborted' });
143
+ this.#turnInputMailbox.abortTurn();
169
144
  }
170
145
  /**
171
146
  * Stop the segment currently streaming without judging the turn's fate.
@@ -209,6 +184,15 @@ export class ApplicationRunLoop {
209
184
  return true;
210
185
  return state.runBudget.grantExtension('parent').granted;
211
186
  }
187
+ #createToolCallExecution() {
188
+ return new ToolCallExecution({
189
+ toolLifecycle: this.#deps.toolLifecycle,
190
+ getOnToolDispatch: this.#deps.getOnToolDispatch,
191
+ resolveMaxParallelToolCalls: this.#deps.resolveMaxParallelToolCalls,
192
+ isMaxTurnsExceeded: (error) => error instanceof MaxTurnsExceededError,
193
+ logDiagnostic: this.#deps.logDiagnostic,
194
+ });
195
+ }
212
196
  /**
213
197
  * Hand the running turn a user message to send with its next model request.
214
198
  *
@@ -234,32 +218,21 @@ export class ApplicationRunLoop {
234
218
  * only released or admitted.
235
219
  */
236
220
  steer(items, options) {
237
- if (items.length === 0)
238
- return Promise.resolve('released');
239
- if (!this.#turnOpen && !this.#runInFlight && !this.#turnPaused)
240
- return Promise.resolve('released');
241
- return new Promise((resolve) => {
242
- this.#pendingSteers.push({ id: options?.id, items, resolve });
243
- });
221
+ return this.#turnInputMailbox.offer(items, options);
244
222
  }
245
223
  /**
246
224
  * Drop a still-waiting steer before it reaches a request boundary. Returns
247
225
  * `false` when the id is unknown, including when it was already admitted.
248
226
  *
249
- * Invariant: this and `#admitPendingSteers` are both synchronous, and the
250
- * latter drains `#pendingSteers` in a single pass — so the two can never
227
+ * Invariant: this and `TurnInputMailbox.admitAtRequestBoundary` are both synchronous,
228
+ * and the latter drains the mailbox in a single pass — so the two can never
251
229
  * interleave. A retraction is decided in the same tick against whatever is
252
- * currently in `#pendingSteers`; once an item has been admitted it is no
230
+ * currently pending; once an item has been admitted it is no
253
231
  * longer in that array for this method to find. No locking is needed to
254
232
  * close the race between "the user retracts" and "the turn admits".
255
233
  */
256
234
  retractSteer(id) {
257
- const index = this.#pendingSteers.findIndex((steer) => steer.id === id);
258
- if (index < 0)
259
- return false;
260
- const [steer] = this.#pendingSteers.splice(index, 1);
261
- steer.resolve('retracted');
262
- return true;
235
+ return this.#turnInputMailbox.retract(id);
263
236
  }
264
237
  /**
265
238
  * Replace a waiting steer's items in place, keeping its position (and thus
@@ -268,21 +241,7 @@ export class ApplicationRunLoop {
268
241
  * same synchronicity invariant as `retractSteer`.
269
242
  */
270
243
  editSteer(id, items) {
271
- const index = this.#pendingSteers.findIndex((steer) => steer.id === id);
272
- if (index < 0)
273
- return false;
274
- this.#pendingSteers[index] = { ...this.#pendingSteers[index], items };
275
- return true;
276
- }
277
- /** Settle every steer this run did not admit so callers stop waiting on it. */
278
- #releasePendingSteers(reason = {}) {
279
- const pending = this.#pendingSteers;
280
- this.#pendingSteers = [];
281
- if (pending.length > 0) {
282
- this.#deps.logDiagnostic?.('Steer released at run end', { released: pending.length, ...reason });
283
- }
284
- for (const steer of pending)
285
- steer.resolve('released');
244
+ return this.#turnInputMailbox.edit(id, items);
286
245
  }
287
246
  /**
288
247
  * Append waiting steers to the turn as ordinary user messages.
@@ -291,24 +250,6 @@ export class ApplicationRunLoop {
291
250
  * folded into a tool result — so the provider sees the user speaking after
292
251
  * the tool results of the round that was in flight when they typed.
293
252
  */
294
- #admitPendingSteers(state, stream, queue) {
295
- if (this.#pendingSteers.length === 0)
296
- return;
297
- const admitted = this.#pendingSteers;
298
- this.#pendingSteers = [];
299
- this.#deps.logDiagnostic?.('Steer admitted at request boundary', {
300
- admitted: admitted.length,
301
- turnCount: state.turnCount,
302
- });
303
- for (const steer of admitted) {
304
- for (const item of steer.items) {
305
- state.history.push(item);
306
- state.input.push(...normalizeApplicationInput([item]));
307
- outputPush(stream, queue, { type: 'item', item });
308
- }
309
- steer.resolve('admitted');
310
- }
311
- }
312
253
  startStream(agent, input, options = {}) {
313
254
  // Without a declared turn scope, a fresh stream is the only evidence this
314
255
  // loop gets that a new turn has begun: anything still waiting belonged to
@@ -316,14 +257,15 @@ export class ApplicationRunLoop {
316
257
  // With one, this call may equally be the same turn restarting after a
317
258
  // retry, which the loop cannot tell apart — so `openTurn`/`closeTurn` own
318
259
  // the decision instead.
319
- this.#turnPaused = false;
320
- if (!this.#turnOpen)
321
- this.#releasePendingSteers({ reason: 'superseded_by_new_turn' });
260
+ this.#turnInputMailbox.startStream();
322
261
  const state = {
323
262
  agent,
263
+ toolExecution: this.#createToolCallExecution(),
324
264
  recoveryBudget: options.recoveryBudget,
325
265
  input: normalizeInput(input),
326
266
  history: normalizeHistory(input),
267
+ compactionHistory: options.compactionHistory,
268
+ usesDeltaHistory: Boolean(options.previousResponseId) && options.disableChainingForAttempt !== true,
327
269
  // A response ID is usable only after its provider origin is recorded.
328
270
  // This also makes old callers that omit providerId fail closed.
329
271
  responseId: options.disableChainingForAttempt !== true &&
@@ -331,7 +273,6 @@ export class ApplicationRunLoop {
331
273
  options.supportsConversationChaining === true
332
274
  ? options.previousResponseId ?? undefined
333
275
  : undefined,
334
- pendingApprovals: [],
335
276
  supportsConversationChaining: options.supportsConversationChaining === true,
336
277
  currentProviderId: options.providerId,
337
278
  responseProviderId: options.providerId && options.supportsConversationChaining === true && options.previousResponseId
@@ -393,11 +334,8 @@ export class ApplicationRunLoop {
393
334
  state.approvals = new ApprovalLedger();
394
335
  // A continuation handle from before approval batching carried only the
395
336
  // current pending item. Normalize it into the queue used by current runs.
396
- if (!state.pendingApprovals)
397
- state.pendingApprovals = state.pendingApproval ? [state.pendingApproval] : [];
398
- if (!state.pendingApproval && state.pendingApprovals.length > 0) {
399
- state.pendingApproval = state.pendingApprovals[0];
400
- }
337
+ if (!state.toolExecution)
338
+ state.toolExecution = this.#createToolCallExecution();
401
339
  // Handles created before cost accounting existed have no record list.
402
340
  if (!state.costRecords)
403
341
  state.costRecords = [];
@@ -448,6 +386,8 @@ export class ApplicationRunLoop {
448
386
  // root closure for callers that do not provide one again.
449
387
  if (options.requestPreparation)
450
388
  state.requestPreparation = options.requestPreparation;
389
+ if (options.compactionHistory)
390
+ state.compactionHistory = options.compactionHistory;
451
391
  if (options.disableChainingForAttempt === true) {
452
392
  state.disableChainingForAttempt = true;
453
393
  state.responseId = undefined;
@@ -467,10 +407,8 @@ export class ApplicationRunLoop {
467
407
  this.abortSegment();
468
408
  const controller = new AbortController();
469
409
  this.#activeAbortController = controller;
470
- this.#runInFlight = true;
410
+ this.#turnInputMailbox.startSegment();
471
411
  state.runBudget?.resume();
472
- // This segment is running, so the turn is no longer paused between them.
473
- this.#turnPaused = false;
474
412
  if (options.signal) {
475
413
  if (options.signal.aborted)
476
414
  controller.abort();
@@ -531,42 +469,43 @@ export class ApplicationRunLoop {
531
469
  return;
532
470
  if (this.#activeAbortController === controller)
533
471
  this.#activeAbortController = null;
534
- this.#runInFlight = false;
535
472
  // A segment that ends holding approvals has paused the turn, not ended
536
473
  // it: the caller resumes through continueRunStream, which offers
537
474
  // another request boundary. Injections wait for it. Only a segment
538
475
  // that ends with nothing outstanding has truly finished the turn, and
539
476
  // then anything still waiting has to be sent as its own turn instead.
540
- const pendingApprovals = state.pendingApprovals?.length ?? 0;
477
+ const pendingApprovals = state.toolExecution.pendingApprovals.length;
541
478
  const pendingBudgetInteraction = state.pendingRunBudgetInteraction !== undefined;
542
479
  const cancelled = stream.cancelled === true;
543
- this.#turnPaused = (pendingApprovals > 0 || pendingBudgetInteraction) && !cancelled && exitError === undefined;
544
- if (this.#turnPaused)
480
+ const turnPaused = (pendingApprovals > 0 || pendingBudgetInteraction) && !cancelled && exitError === undefined;
481
+ this.#turnInputMailbox.settleSegment({
482
+ paused: turnPaused,
483
+ reason: {
484
+ pendingApprovals,
485
+ pendingBudgetInteraction,
486
+ cancelled,
487
+ error: exitError instanceof Error ? exitError.name : exitError ? String(exitError) : undefined,
488
+ turnCount: state.turnCount,
489
+ },
490
+ });
491
+ if (turnPaused)
545
492
  return;
546
493
  if (this.#activeRunBudgetState === state)
547
494
  this.#activeRunBudgetState = undefined;
548
- // A declared turn outlives its segments — this one may be about to be
549
- // retried, or resumed past a post-execute gate. Its owner says when it
550
- // is over.
551
- if (this.#turnOpen)
552
- return;
553
- this.#releasePendingSteers({
554
- pendingApprovals,
555
- pendingBudgetInteraction,
556
- cancelled,
557
- error: exitError instanceof Error ? exitError.name : exitError ? String(exitError) : undefined,
558
- turnCount: state.turnCount,
559
- });
560
495
  });
561
496
  this.#activeRunBudgetState = state.runBudget ? state : undefined;
562
497
  return stream;
563
498
  }
564
499
  /** Route boundary advice through the same admission lane as mode notices. */
565
500
  #queuePendingSystemNotice(text) {
566
- this.#pendingSteers.push({
567
- items: [{ type: 'message', role: 'user', content: `[Mode Notice] ${text}` }],
568
- resolve: () => undefined,
569
- });
501
+ this.#turnInputMailbox.enqueueInternal({ type: 'message', role: 'user', content: `[Mode Notice] ${text}` });
502
+ }
503
+ #admitPendingSteers(state, stream, queue) {
504
+ this.#turnInputMailbox.admitAtRequestBoundary((item) => {
505
+ state.history.push(item);
506
+ state.input.push(...normalizeApplicationInput([item]));
507
+ outputPush(stream, queue, { type: 'item', item });
508
+ }, state.turnCount);
570
509
  }
571
510
  async #execute(state, stream, queue, options, toolContext, requestAbortController) {
572
511
  while (true) {
@@ -586,35 +525,14 @@ export class ApplicationRunLoop {
586
525
  return this.#pauseForRunBudgetInteraction(state, stream, queue);
587
526
  }
588
527
  }
589
- state.pendingApprovals ??= state.pendingApproval ? [state.pendingApproval] : [];
590
- if (state.pendingApprovals.length > 0 && state.approvalDecision) {
591
- const selectedIndex = state.approvalDecisionCallId
592
- ? state.pendingApprovals.findIndex((pending) => getInterruptionCallId(pending.interruption) === state.approvalDecisionCallId)
593
- : -1;
594
- if (state.approvalDecisionCallId && selectedIndex < 0) {
595
- throw new Error(`Approval decision references unknown pending tool call: ${state.approvalDecisionCallId}`);
596
- }
597
- const pendingIndex = selectedIndex >= 0 ? selectedIndex : 0;
598
- const pending = state.pendingApprovals[pendingIndex];
599
- const approved = state.approvalDecision === 'approved';
600
- if (approved) {
601
- state.approvals.approveTool({ toolName: pending.toolName, callId: pending.callId });
602
- }
603
- else {
604
- state.approvals.rejectTool({ toolName: pending.toolName, callId: pending.callId }, { message: state.approvalMessage });
605
- }
606
- pending.plan.status = 'ready';
607
- if (!approved)
608
- pending.plan.output = state.approvalMessage ?? 'rejected';
609
- state.pendingApprovals.splice(pendingIndex, 1);
610
- state.pendingApproval = state.pendingApprovals[0];
528
+ if (state.toolExecution.pendingApprovals.length > 0 && state.approvalDecision) {
529
+ state.toolExecution.resolveApproval(state.approvalDecisionCallId, state.approvalDecision, state.approvalMessage, state.approvals);
611
530
  state.approvalDecision = undefined;
612
531
  state.approvalDecisionCallId = undefined;
613
532
  state.approvalMessage = undefined;
614
- await this.#settleToolPlan(state, stream, queue, toolContext);
615
- stream.interruptions = state.pendingApprovals.map((item) => item.interruption);
616
- if (state.pendingApprovals.length > 0) {
617
- this.#turnPaused = true;
533
+ await state.toolExecution.settle(this.#toolCallContext(state, stream, queue, toolContext));
534
+ stream.interruptions = state.toolExecution.pendingApprovals.map((item) => item.interruption);
535
+ if (state.toolExecution.pendingApprovals.length > 0) {
618
536
  return finish(stream, state, queue);
619
537
  }
620
538
  // Nothing is outstanding, so this segment is terminal — see
@@ -627,11 +545,10 @@ export class ApplicationRunLoop {
627
545
  // A budget interaction can park a response after its tool calls are
628
546
  // recorded but before any body runs. Resume those retained calls only
629
547
  // after processing an ordinary approval decision for that same plan.
630
- if (state.toolPlan) {
631
- await this.#settleToolPlan(state, stream, queue, toolContext);
632
- if (state.pendingApprovals?.length) {
633
- stream.interruptions = state.pendingApprovals.map((item) => item.interruption);
634
- this.#turnPaused = true;
548
+ if (state.toolExecution.hasPlan) {
549
+ await state.toolExecution.settle(this.#toolCallContext(state, stream, queue, toolContext));
550
+ if (state.toolExecution.pendingApprovals.length) {
551
+ stream.interruptions = state.toolExecution.pendingApprovals.map((item) => item.interruption);
635
552
  return finish(stream, state, queue);
636
553
  }
637
554
  }
@@ -643,25 +560,36 @@ export class ApplicationRunLoop {
643
560
  this.#evaluateRunBudget(state, stream, queue);
644
561
  if (state.pendingRunBudgetInteraction)
645
562
  return this.#pauseForRunBudgetInteraction(state, stream, queue);
646
- const boundaryDecision = options.onRequestBoundary?.(state.history, (text) => this.#queuePendingSystemNotice(text), {
563
+ const compactionHistoryResult = state.usesDeltaHistory
564
+ ? state.compactionHistory
565
+ ? mergeChainedCompactionHistory(state.compactionHistory, state.history)
566
+ : { kind: 'skipped', reason: 'missing_snapshot' }
567
+ : { kind: 'ready', history: state.history };
568
+ const boundaryDecision = options.onRequestBoundary?.(compactionHistoryResult.kind === 'ready' ? compactionHistoryResult.history : state.history, (text) => this.#queuePendingSystemNotice(text), {
647
569
  ...(state.lastCompletedInputTokens !== undefined
648
570
  ? { lastCompletedInputTokens: state.lastCompletedInputTokens }
649
571
  : {}),
572
+ ...(compactionHistoryResult.kind === 'skipped'
573
+ ? { compactionSkipReason: compactionHistoryResult.reason }
574
+ : {}),
650
575
  });
651
- if (options.boundaryCompaction && !boundaryDecision?.deferCompaction) {
576
+ const compactionHistory = compactionHistoryResult.kind === 'ready' ? compactionHistoryResult.history : undefined;
577
+ if (options.boundaryCompaction && compactionHistory && !boundaryDecision?.deferCompaction) {
652
578
  const compactionStartedAt = Date.now();
653
579
  const compaction = await options.boundaryCompaction.compact({
654
- history: state.history,
580
+ history: compactionHistory,
655
581
  automaticCompactionsThisRun: state.automaticCompactionsThisRun ?? 0,
656
582
  lastCompletedInputTokens: state.lastCompletedInputTokens,
657
583
  signal: options.signal,
658
584
  onStarted: (provider) => outputPush(stream, queue, { type: 'context_compaction_started', provider, strategy: 'local' }),
659
585
  });
660
586
  if (compaction.kind === 'compacted') {
587
+ state.compactedDuringRun = true;
661
588
  state.history.splice(0, state.history.length, ...compaction.history);
662
589
  state.input.splice(0, state.input.length, ...normalizeApplicationInput(compaction.modelInput));
663
590
  state.responseId = undefined;
664
591
  state.responseProviderId = undefined;
592
+ state.usesDeltaHistory = false;
665
593
  if (compaction.costRecords?.length) {
666
594
  state.costRecords ??= [];
667
595
  state.costRecords.push(...compaction.costRecords);
@@ -749,10 +677,19 @@ export class ApplicationRunLoop {
749
677
  state.responseId = undefined;
750
678
  state.responseProviderId = undefined;
751
679
  }
680
+ // A per-request signal lets a recoverable guard trip cancel only this
681
+ // provider request; the segment signal still cancels everything.
682
+ const requestSignal = new AbortController();
683
+ const abortRequest = () => requestSignal.abort();
684
+ if (options.signal?.aborted)
685
+ requestSignal.abort();
686
+ else
687
+ options.signal?.addEventListener('abort', abortRequest, { once: true });
688
+ const requestInstructions = state.agent.resolveInstructionsForRequest?.() ?? state.agent.instructions;
752
689
  const request = {
753
690
  instructions: criticalWrapUp
754
- ? `${state.agent.instructions}\n\nBudget containment is terminal. Do not call tools. In this one final response, summarize what you completed, the evidence you have, and what remains.`
755
- : state.agent.instructions,
691
+ ? `${requestInstructions}\n\nBudget containment is terminal. Do not call tools. In this one final response, summarize what you completed, the evidence you have, and what remains.`
692
+ : requestInstructions,
756
693
  ...(state.supportsConversationChaining &&
757
694
  !disableChaining &&
758
695
  state.responseId &&
@@ -780,7 +717,7 @@ export class ApplicationRunLoop {
780
717
  : state.agent.modelSettings.providerData,
781
718
  }
782
719
  : {}),
783
- ...(options.signal ? { signal: options.signal } : {}),
720
+ signal: requestSignal.signal,
784
721
  ...(state.recoveryBudget ? { recoveryBudget: state.recoveryBudget } : {}),
785
722
  };
786
723
  activeRequest = request;
@@ -884,7 +821,12 @@ export class ApplicationRunLoop {
884
821
  break;
885
822
  }
886
823
  catch (error) {
887
- if (error instanceof GenerationGuardError)
824
+ const recoverOversizedToolArgument = isOversizedToolArgumentTrip(error) &&
825
+ (state.oversizedToolArgumentRecoveries ?? 0) < MAX_OVERSIZED_TOOL_ARGUMENT_RECOVERIES &&
826
+ !options.signal?.aborted;
827
+ if (recoverOversizedToolArgument)
828
+ requestSignal.abort();
829
+ else if (error instanceof GenerationGuardError)
888
830
  requestAbortController.abort();
889
831
  const decision = classifyInLoopModelRetry(error, attempt, maxRetries, Math.random, {
890
832
  previousResponseId: activeRequest?.previousResponseId,
@@ -904,6 +846,23 @@ export class ApplicationRunLoop {
904
846
  });
905
847
  }
906
848
  };
849
+ if (recoverOversizedToolArgument) {
850
+ // No tool ran: a call is dispatched only after its arguments
851
+ // complete. Discard the partial response and ask for smaller calls.
852
+ state.oversizedToolArgumentRecoveries = (state.oversizedToolArgumentRecoveries ?? 0) + 1;
853
+ state.input.splice(inputLengthBefore);
854
+ state.history.splice(historyLengthBefore);
855
+ state.criticalWrapUpDispatched = criticalWrapUpDispatchedBefore;
856
+ rollbackProvisionalAttempt();
857
+ this.#deps.logDiagnostic?.('Recovering oversized tool argument in run loop', {
858
+ code: error.code,
859
+ recovery: state.oversizedToolArgumentRecoveries,
860
+ maxRecoveries: MAX_OVERSIZED_TOOL_ARGUMENT_RECOVERIES,
861
+ });
862
+ this.#queuePendingSystemNotice(oversizedToolArgumentNotice(error.message));
863
+ this.#admitPendingSteers(state, stream, queue);
864
+ continue;
865
+ }
907
866
  if (decision.retryable && !options.signal?.aborted) {
908
867
  attempt++;
909
868
  state.input.splice(inputLengthBefore);
@@ -920,7 +879,7 @@ export class ApplicationRunLoop {
920
879
  maxRetries,
921
880
  kind: decision.kind,
922
881
  delayMs: decision.delayMs,
923
- error: error instanceof Error ? error.message : String(error),
882
+ error: describeError(error),
924
883
  });
925
884
  await (this.#deps.waitBeforeModelRetry ?? sleepWithAbort)(decision.delayMs, options.signal);
926
885
  continue;
@@ -955,6 +914,9 @@ export class ApplicationRunLoop {
955
914
  });
956
915
  throw error;
957
916
  }
917
+ finally {
918
+ options.signal?.removeEventListener('abort', abortRequest);
919
+ }
958
920
  }
959
921
  if (!completion) {
960
922
  // A few application-owned model fixtures (and legacy adapters) end a
@@ -976,11 +938,10 @@ export class ApplicationRunLoop {
976
938
  return finish(stream, state, queue);
977
939
  }
978
940
  await this.#dispatchToolCalls(state, stream, queue, streamedToolCalls, toolContext);
979
- if (state.terminateAfterToolExecution)
941
+ if (state.toolExecution.terminateAfterExecution)
980
942
  return finish(stream, state, queue);
981
- if (state.pendingApprovals && state.pendingApprovals.length > 0) {
982
- stream.interruptions = state.pendingApprovals.map((item) => item.interruption);
983
- this.#turnPaused = true;
943
+ if (state.toolExecution.pendingApprovals.length > 0) {
944
+ stream.interruptions = state.toolExecution.pendingApprovals.map((item) => item.interruption);
984
945
  return finish(stream, state, queue);
985
946
  }
986
947
  continue;
@@ -1105,7 +1066,10 @@ export class ApplicationRunLoop {
1105
1066
  continue;
1106
1067
  const historyItem = {
1107
1068
  ...item.item,
1108
- providerOpaque: { provider: item.provider },
1069
+ providerOpaque: {
1070
+ provider: item.provider,
1071
+ ...(item.sourceProvider ? { sourceProvider: item.sourceProvider } : {}),
1072
+ },
1109
1073
  };
1110
1074
  state.history.push(historyItem);
1111
1075
  state.input.push(item);
@@ -1142,7 +1106,7 @@ export class ApplicationRunLoop {
1142
1106
  if (!state.criticalWrapUpPending && toolCalls.length > 0) {
1143
1107
  await this.#dispatchToolCalls(state, stream, queue, toolCalls, toolContext);
1144
1108
  }
1145
- if (state.terminateAfterToolExecution)
1109
+ if (state.toolExecution.terminateAfterExecution)
1146
1110
  return finish(stream, state, queue);
1147
1111
  // A critical subagent gets exactly this final tool-free model call.
1148
1112
  if (criticalWrapUp)
@@ -1150,9 +1114,8 @@ export class ApplicationRunLoop {
1150
1114
  if (state.pendingRunBudgetInteraction && toolCalls.length > 0) {
1151
1115
  return this.#pauseForRunBudgetInteraction(state, stream, queue);
1152
1116
  }
1153
- if (state.pendingApprovals.length > 0) {
1154
- stream.interruptions = state.pendingApprovals.map((item) => item.interruption);
1155
- this.#turnPaused = true;
1117
+ if (state.toolExecution.pendingApprovals.length > 0) {
1118
+ stream.interruptions = state.toolExecution.pendingApprovals.map((item) => item.interruption);
1156
1119
  return finish(stream, state, queue);
1157
1120
  }
1158
1121
  if (!sawToolCall) {
@@ -1164,178 +1127,51 @@ export class ApplicationRunLoop {
1164
1127
  }
1165
1128
  }
1166
1129
  async #dispatchToolCalls(state, stream, queue, events, toolContext) {
1167
- const plan = events.map((event) => {
1168
- const definition = state.agent.tools.find((tool) => tool.name === event.name);
1169
- const callItem = {
1170
- type: event.toolType === 'custom' ? 'custom_tool_call' : 'function_call',
1171
- callId: event.id,
1172
- name: event.name,
1173
- ...(event.toolType === 'custom' ? { input: event.arguments } : { arguments: event.arguments }),
1174
- };
1175
- state.history.push(callItem);
1176
- state.input.push({
1177
- type: 'tool_call',
1178
- id: event.id,
1179
- name: event.name,
1180
- arguments: event.arguments,
1181
- ...(event.toolType ? { toolType: event.toolType } : {}),
1182
- });
1183
- outputPush(stream, queue, { type: 'item', item: callItem });
1184
- return {
1185
- event,
1186
- definition,
1187
- parallelSafe: false,
1188
- status: 'ready',
1189
- };
1190
- });
1191
- state.toolPlan = plan;
1192
- for (const entry of plan) {
1193
- const { event, definition } = entry;
1194
- if (!definition) {
1195
- entry.output = `Unknown tool: ${event.name}`;
1196
- continue;
1197
- }
1198
- // Keep the raw-model invocation contract: normalization repairs the
1199
- // accepted object shape but intentionally does not Zod-parse it, which
1200
- // would apply schema defaults before execute. web_fetch relies on its
1201
- // executor fallbacks on the strict JSON-schema path.
1202
- try {
1203
- const parsedArguments = definition.parseModelArguments
1204
- ? definition.parseModelArguments(event.arguments)
1205
- : parseArguments(event.arguments);
1206
- entry.params = normalizeToolParameters(parsedArguments, definition.parameters);
1207
- }
1208
- catch (error) {
1209
- entry.output = `Error: Invalid patch: ${error instanceof Error ? error.message : String(error)}`;
1210
- continue;
1211
- }
1212
- const stallEvent = state.runBudget?.observeToolCall({
1213
- name: event.name,
1214
- argumentsText: event.arguments,
1215
- effect: definition.effect,
1216
- });
1217
- if (stallEvent) {
1218
- this.#emitRunBudgetEvent(state, stallEvent, 'Tool stall evidence', stream, queue);
1219
- }
1220
- // Consult this run's ledger before prompting: a decision already taken
1221
- // (in the parent run and replayed in, or earlier in this run) must not
1222
- // prompt again. This is what makes approval replay observable.
1223
- const alreadyDecided = state.approvals.isToolApproved({ toolName: event.name, callId: event.id });
1224
- if (alreadyDecided === false) {
1225
- entry.output = state.approvals.getRejectionMessage(event.name, event.id) ?? 'Tool execution was not approved.';
1226
- continue;
1227
- }
1228
- if (alreadyDecided !== true && (await definition.needsApproval(entry.params, toolContext))) {
1229
- entry.status = 'approval_pending';
1230
- const pending = {
1130
+ const context = this.#toolCallContext(state, stream, queue, toolContext);
1131
+ await state.toolExecution.plan(events, context);
1132
+ stream.interruptions = state.toolExecution.pendingApprovals.map((item) => item.interruption);
1133
+ if (!state.pendingRunBudgetInteraction)
1134
+ await state.toolExecution.settle(context);
1135
+ }
1136
+ #toolCallContext(state, stream, queue, toolContext) {
1137
+ return {
1138
+ tools: state.agent.tools,
1139
+ approvals: state.approvals,
1140
+ toolContext,
1141
+ sessionId: state.sessionId,
1142
+ turnId: state.turnId,
1143
+ hookScope: state.hookScope,
1144
+ onCall: (event) => {
1145
+ const callItem = {
1146
+ type: event.toolType === 'custom' ? 'custom_tool_call' : 'function_call',
1231
1147
  callId: event.id,
1232
- toolName: event.name,
1233
- argumentsText: event.arguments,
1234
- interruption: {
1235
- type: 'tool_approval_item',
1236
- rawItem: { type: 'function_call', callId: event.id, name: event.name, arguments: event.arguments },
1237
- callId: event.id,
1238
- name: event.name,
1239
- arguments: event.arguments,
1240
- },
1241
- definition,
1242
- params: entry.params,
1243
- plan: entry,
1148
+ name: event.name,
1149
+ ...(event.toolType === 'custom' ? { input: event.arguments } : { arguments: event.arguments }),
1244
1150
  };
1245
- state.pendingApprovals ??= [];
1246
- state.pendingApprovals.push(pending);
1247
- continue;
1248
- }
1249
- entry.parallelSafe = await isParallelSafe(definition, entry.params, toolContext);
1250
- }
1251
- state.pendingApproval = state.pendingApprovals?.[0];
1252
- stream.interruptions = (state.pendingApprovals ?? []).map((item) => item.interruption);
1253
- this.#deps.logDiagnostic?.('tool parallel eligibility', {
1254
- decisions: plan.map((entry) => ({
1255
- callId: entry.event.id,
1256
- toolName: entry.event.name,
1257
- parallelSafe: entry.parallelSafe,
1258
- approvalPending: entry.status === 'approval_pending',
1259
- })),
1260
- }, { severity: 'debug', eventType: 'tool.parallel.eligibility' });
1261
- // A main-agent budget escalation is a real boundary: retain the planned
1262
- // calls, but do not execute one more tool while human judgement is pending.
1263
- if (!state.pendingRunBudgetInteraction) {
1264
- await this.#settleToolPlan(state, stream, queue, toolContext);
1265
- }
1266
- }
1267
- async #settleToolPlan(state, stream, queue, toolContext) {
1268
- const plan = state.toolPlan;
1269
- if (!plan)
1270
- return;
1271
- const maxParallelToolCalls = Math.max(1, Math.floor(this.#deps.resolveMaxParallelToolCalls?.() ?? DEFAULT_MAX_PARALLEL_TOOL_CALLS));
1272
- while (true) {
1273
- const firstPending = plan.find((entry) => entry.status !== 'completed');
1274
- if (!firstPending) {
1275
- state.toolPlan = undefined;
1276
- return;
1277
- }
1278
- if (firstPending.status === 'approval_pending')
1279
- return;
1280
- const group = [];
1281
- for (const entry of plan) {
1282
- if (entry.status === 'completed')
1283
- continue;
1284
- if (entry.status === 'approval_pending')
1285
- break;
1286
- if (group.length > 0 && (!entry.parallelSafe || !group[0].parallelSafe || group.length >= maxParallelToolCalls))
1287
- break;
1288
- group.push(entry);
1289
- if (!entry.parallelSafe)
1290
- break;
1291
- }
1292
- const batchId = `tool-batch-${++nextToolBatchSeq}`;
1293
- this.#deps.logDiagnostic?.('tool batch dispatched', {
1294
- batchId,
1295
- callIds: group.map((entry) => entry.event.id),
1296
- parallel: group.length > 1,
1297
- maxParallelToolCalls,
1298
- dispatchOrder: group.map((entry) => entry.event.id),
1299
- }, { severity: 'debug', eventType: 'tool.batch.dispatched' });
1300
- for (const entry of group) {
1151
+ state.history.push(callItem);
1152
+ state.input.push({
1153
+ type: 'tool_call',
1154
+ id: event.id,
1155
+ name: event.name,
1156
+ arguments: event.arguments,
1157
+ ...(event.toolType ? { toolType: event.toolType } : {}),
1158
+ });
1159
+ outputPush(stream, queue, { type: 'item', item: callItem });
1160
+ },
1161
+ onDispatch: (entry) => {
1301
1162
  outputPush(stream, queue, {
1302
1163
  type: 'tool_call_dispatched',
1303
1164
  callId: entry.event.id,
1304
1165
  toolName: entry.event.name,
1305
1166
  });
1306
- }
1307
- if (group.length > 1) {
1308
- const results = await Promise.allSettled(group.map((entry) => this.#invokePlannedTool(entry, toolContext, state)));
1309
- const rejected = results.find((result) => result.status === 'rejected');
1310
- if (rejected)
1311
- throw rejected.reason;
1312
- for (const [index, result] of results.entries()) {
1313
- const value = result.value;
1314
- group[index].result = value;
1315
- this.#appendToolResult(state, stream, queue, group[index], value);
1316
- }
1317
- }
1318
- else {
1319
- const result = await this.#invokePlannedTool(group[0], toolContext, state);
1320
- group[0].result = result;
1321
- this.#appendToolResult(state, stream, queue, group[0], result);
1322
- }
1323
- this.#deps.logDiagnostic?.('tool batch settled', {
1324
- batchId,
1325
- settlementOrder: group.map((entry) => entry.event.id),
1326
- }, { severity: 'debug', eventType: 'tool.batch.settled' });
1327
- if (group.some((entry) => shouldTerminateAfterExecution(entry.definition, entry.result))) {
1328
- state.terminateAfterToolExecution = true;
1329
- state.toolPlan = undefined;
1330
- return;
1331
- }
1332
- }
1333
- }
1334
- async #invokePlannedTool(entry, toolContext, state) {
1335
- entry.status = 'completed';
1336
- if (entry.output !== undefined)
1337
- return entry.output;
1338
- return this.#invokeTool(entry.definition, entry.params, toolContext, entry.event.id, state);
1167
+ },
1168
+ onToolStall: (input) => {
1169
+ const stallEvent = state.runBudget?.observeToolCall(input);
1170
+ if (stallEvent)
1171
+ this.#emitRunBudgetEvent(state, stallEvent, 'Tool stall evidence', stream, queue);
1172
+ },
1173
+ onResult: (entry, result) => this.#appendToolResult(state, stream, queue, entry, result),
1174
+ };
1339
1175
  }
1340
1176
  #appendToolResult(state, stream, queue, entry, result) {
1341
1177
  const runCodeExecution = getRunCodeExecutionResult(result);
@@ -1363,57 +1199,6 @@ export class ApplicationRunLoop {
1363
1199
  outputPush(stream, queue, { type: 'item', item: resultItem });
1364
1200
  this.#evaluateRunBudget(state, stream, queue);
1365
1201
  }
1366
- /**
1367
- * A tool that throws must not take the run down with it.
1368
- *
1369
- * Most tools already report failure by returning `Error: ...` as their
1370
- * output, which the model reads and acts on. The handful that throw got the
1371
- * opposite treatment for no principled reason: the exception escaped to
1372
- * `#execute`, closed the event queue, and ended the turn — so the model never
1373
- * saw a recoverable problem like a path that does not exist, and the caller
1374
- * lost the whole turn. Worse, `#handleToolCall` pushes the `function_call`
1375
- * into history before executing, so an escape leaves a call with no matching
1376
- * result.
1377
- *
1378
- * Errors are therefore normalized into tool output, with two exceptions that
1379
- * must still propagate: cancellation (the run is ending on purpose) and
1380
- * `HarnessInvariantError` (a bug here, which the model cannot act on).
1381
- */
1382
- async #invokeTool(definition, params, toolContext, callId, state) {
1383
- const startedAt = Date.now();
1384
- const attempt = state
1385
- ? ((state.toolAttempts ??= new Map()).set(callId, (state.toolAttempts.get(callId) ?? 0) + 1),
1386
- state.toolAttempts.get(callId))
1387
- : 1;
1388
- const lifecycleContext = {
1389
- ...(state?.sessionId ? { sessionId: state.sessionId } : {}),
1390
- ...(state?.turnId ? { turnId: state.turnId } : {}),
1391
- toolCallId: callId,
1392
- toolName: definition.name,
1393
- normalizedArguments: params,
1394
- attempt,
1395
- scope: state?.hookScope ?? 'root',
1396
- };
1397
- // Dispatch mark must run before execute so a mid-tool stream failure can
1398
- // settle the ledger as unknown rather than aborted.
1399
- this.#deps.getOnToolDispatch?.()?.(callId);
1400
- await this.#notifyToolLifecycle(() => this.#deps.toolLifecycle?.before(lifecycleContext));
1401
- try {
1402
- const result = await definition.execute(params, toolContext, { toolCall: { callId } });
1403
- await this.#notifyToolLifecycle(() => this.#deps.toolLifecycle?.after(lifecycleContext, result, Date.now() - startedAt));
1404
- return result;
1405
- }
1406
- catch (error) {
1407
- if (isCancellationError(error) || isHarnessInvariantError(error) || error instanceof MaxTurnsExceededError) {
1408
- await this.#notifyToolLifecycle(() => this.#deps.toolLifecycle?.error(lifecycleContext, error, Date.now() - startedAt, false));
1409
- throw error;
1410
- }
1411
- const message = error instanceof Error ? error.message : String(error);
1412
- const result = `Error: ${message}`;
1413
- await this.#notifyToolLifecycle(() => this.#deps.toolLifecycle?.error(lifecycleContext, error, Date.now() - startedAt, true));
1414
- return result;
1415
- }
1416
- }
1417
1202
  #nextRequestId() {
1418
1203
  nextCostRequestSeq += 1;
1419
1204
  return `req-${nextCostRequestSeq}`;
@@ -1477,33 +1262,8 @@ export class ApplicationRunLoop {
1477
1262
  if (!interaction)
1478
1263
  return finish(stream, state, queue);
1479
1264
  stream.interruptions = [interaction];
1480
- this.#turnPaused = true;
1481
1265
  return finish(stream, state, queue);
1482
1266
  }
1483
- async #notifyToolLifecycle(operation) {
1484
- if (!operation)
1485
- return;
1486
- try {
1487
- await operation();
1488
- }
1489
- catch {
1490
- // Lifecycle observers are passive. A broken observer must not alter tool
1491
- // execution or turn recovery semantics.
1492
- }
1493
- }
1494
- }
1495
- function shouldTerminateAfterExecution(definition, result) {
1496
- const policy = definition?.terminateAfterExecution;
1497
- if (typeof policy === 'boolean')
1498
- return policy;
1499
- if (!policy)
1500
- return false;
1501
- try {
1502
- return policy(result);
1503
- }
1504
- catch {
1505
- return false;
1506
- }
1507
1267
  }
1508
1268
  function isLunaChainedRequest(state, request) {
1509
1269
  return (state.currentProviderId === 'codex' &&
@@ -1513,6 +1273,12 @@ function isLunaChainedRequest(state, request) {
1513
1273
  request.input.length === 1 &&
1514
1274
  request.input[0]?.type === 'tool_result');
1515
1275
  }
1276
+ function getInterruptionCallId(value) {
1277
+ if (typeof value !== 'object' || value === null)
1278
+ return undefined;
1279
+ const callId = value.callId;
1280
+ return typeof callId === 'string' ? callId : undefined;
1281
+ }
1516
1282
  function outputPush(stream, queue, item) {
1517
1283
  stream.output.push(item);
1518
1284
  if (stream.newItems !== stream.output)
@@ -1521,6 +1287,7 @@ function outputPush(stream, queue, item) {
1521
1287
  }
1522
1288
  function finish(stream, state, queue) {
1523
1289
  stream.history = state.history;
1290
+ stream.historyReplacedByCompaction = state.compactedDuringRun === true;
1524
1291
  stream.terminalCause = state.terminalCause;
1525
1292
  stream.latestProviderInputTokens = state.lastCompletedInputTokens;
1526
1293
  if (state.supportsConversationChaining &&
@@ -1623,31 +1390,6 @@ function normalizeModelUsage(usage) {
1623
1390
  reasoningTokens: rawUsage.outputTokens?.reasoning ?? rawUsage.reasoningTokens,
1624
1391
  });
1625
1392
  }
1626
- function parseArguments(value) {
1627
- try {
1628
- return JSON.parse(value);
1629
- }
1630
- catch {
1631
- return {};
1632
- }
1633
- }
1634
- async function isParallelSafe(definition, params, context) {
1635
- if (typeof definition.parallelSafe === 'function') {
1636
- try {
1637
- return await definition.parallelSafe(params, context);
1638
- }
1639
- catch {
1640
- return false;
1641
- }
1642
- }
1643
- return definition.parallelSafe === true;
1644
- }
1645
- function getInterruptionCallId(value) {
1646
- if (typeof value !== 'object' || value === null)
1647
- return undefined;
1648
- const callId = value.callId;
1649
- return typeof callId === 'string' ? callId : undefined;
1650
- }
1651
1393
  function toModelTools(tools) {
1652
1394
  return tools.map((tool) => tool.modelTool
1653
1395
  ? {
@@ -1685,6 +1427,37 @@ function normalizeHistory(input) {
1685
1427
  return [{ type: 'message', role: 'user', content: input }];
1686
1428
  return Array.isArray(input) ? [...input] : [input];
1687
1429
  }
1430
+ function mergeChainedCompactionHistory(sessionHistory, deltaHistory) {
1431
+ const firstDeltaItem = deltaHistory[0];
1432
+ if (!firstDeltaItem || firstDeltaItem.type !== 'message' || firstDeltaItem.role !== 'user') {
1433
+ return { kind: 'skipped', reason: 'user_mismatch' };
1434
+ }
1435
+ let latestUserIndex = -1;
1436
+ for (let index = sessionHistory.length - 1; index >= 0; index--) {
1437
+ const item = sessionHistory[index];
1438
+ if (item.type === 'message' && item.role === 'user') {
1439
+ latestUserIndex = index;
1440
+ break;
1441
+ }
1442
+ }
1443
+ if (latestUserIndex < 0)
1444
+ return { kind: 'skipped', reason: 'user_mismatch' };
1445
+ const latestSessionUser = sessionHistory[latestUserIndex];
1446
+ const normalizedDeltaUser = normalizeApplicationInput([firstDeltaItem]);
1447
+ const normalizedSessionUser = normalizeApplicationInput([latestSessionUser]);
1448
+ if (JSON.stringify(normalizedDeltaUser) !== JSON.stringify(normalizedSessionUser)) {
1449
+ return { kind: 'skipped', reason: 'user_mismatch' };
1450
+ }
1451
+ return {
1452
+ kind: 'ready',
1453
+ history: [
1454
+ ...sessionHistory.slice(0, latestUserIndex),
1455
+ firstDeltaItem,
1456
+ ...sessionHistory.slice(latestUserIndex + 1),
1457
+ ...deltaHistory.slice(1),
1458
+ ],
1459
+ };
1460
+ }
1688
1461
  function asRecord(value) {
1689
1462
  return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
1690
1463
  }
@@ -1814,7 +1587,14 @@ function isProviderOpaque(item) {
1814
1587
  function normalizeInputItem(item) {
1815
1588
  if (isProviderOpaque(item)) {
1816
1589
  const { providerOpaque: _marker, ...providerItem } = item;
1817
- return [{ type: 'provider_opaque', provider: item.providerOpaque.provider, item: providerItem }];
1590
+ return [
1591
+ {
1592
+ type: 'provider_opaque',
1593
+ provider: item.providerOpaque.provider,
1594
+ ...(item.providerOpaque.sourceProvider ? { sourceProvider: item.providerOpaque.sourceProvider } : {}),
1595
+ item: providerItem,
1596
+ },
1597
+ ];
1818
1598
  }
1819
1599
  if (item.type === 'function_call' || item.type === 'custom_tool_call') {
1820
1600
  return [
@@ -1866,4 +1646,19 @@ function normalizeInputItem(item) {
1866
1646
  }
1867
1647
  return [{ type: 'message', role, content }];
1868
1648
  }
1649
+ /**
1650
+ * A legitimate but oversized tool call (usually one large edit) trips the
1651
+ * tool-argument caps. Unlike runaway output it is answerable: tell the model
1652
+ * the call never ran and let it split the work, a bounded number of times.
1653
+ */
1654
+ const MAX_OVERSIZED_TOOL_ARGUMENT_RECOVERIES = 2;
1655
+ function isOversizedToolArgumentTrip(error) {
1656
+ return (error instanceof GenerationGuardError &&
1657
+ (error.code === 'tool_argument_characters' || error.code === 'cumulative_tool_argument_characters'));
1658
+ }
1659
+ function oversizedToolArgumentNotice(guardMessage) {
1660
+ return (`Your previous response was discarded and its tool call was not executed. ${guardMessage} ` +
1661
+ 'Redo the work in smaller tool calls, each well under that limit — for example, several targeted ' +
1662
+ 'patches instead of rewriting a whole file in one call.');
1663
+ }
1869
1664
  //# sourceMappingURL=application-run-loop.js.map