pulseed 0.6.3 → 0.6.5

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 (615) hide show
  1. package/dist/adapters/datasources/artifact-metric-datasource.d.ts +11 -1
  2. package/dist/adapters/datasources/artifact-metric-datasource.d.ts.map +1 -1
  3. package/dist/adapters/datasources/artifact-metric-datasource.js +256 -9
  4. package/dist/adapters/datasources/artifact-metric-datasource.js.map +1 -1
  5. package/dist/base/config/global-config.d.ts +7 -4
  6. package/dist/base/config/global-config.d.ts.map +1 -1
  7. package/dist/base/config/global-config.js +3 -1
  8. package/dist/base/config/global-config.js.map +1 -1
  9. package/dist/base/protocol/exact-protocol.d.ts +47 -0
  10. package/dist/base/protocol/exact-protocol.d.ts.map +1 -0
  11. package/dist/base/protocol/exact-protocol.js +175 -0
  12. package/dist/base/protocol/exact-protocol.js.map +1 -0
  13. package/dist/base/types/core.d.ts +1 -1
  14. package/dist/base/types/core.d.ts.map +1 -1
  15. package/dist/base/types/core.js +1 -0
  16. package/dist/base/types/core.js.map +1 -1
  17. package/dist/base/utils/paths.d.ts +5 -0
  18. package/dist/base/utils/paths.d.ts.map +1 -1
  19. package/dist/base/utils/paths.js +7 -0
  20. package/dist/base/utils/paths.js.map +1 -1
  21. package/dist/base/utils/workspace-path.d.ts +6 -0
  22. package/dist/base/utils/workspace-path.d.ts.map +1 -0
  23. package/dist/base/utils/workspace-path.js +24 -0
  24. package/dist/base/utils/workspace-path.js.map +1 -0
  25. package/dist/base/utils/workspace-root.d.ts +6 -0
  26. package/dist/base/utils/workspace-root.d.ts.map +1 -0
  27. package/dist/base/utils/workspace-root.js +87 -0
  28. package/dist/base/utils/workspace-root.js.map +1 -0
  29. package/dist/index.d.ts +4 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/interface/chat/chat-event-state.d.ts +2 -0
  34. package/dist/interface/chat/chat-event-state.d.ts.map +1 -1
  35. package/dist/interface/chat/chat-event-state.js +22 -41
  36. package/dist/interface/chat/chat-event-state.js.map +1 -1
  37. package/dist/interface/chat/chat-events.d.ts +15 -1
  38. package/dist/interface/chat/chat-events.d.ts.map +1 -1
  39. package/dist/interface/chat/chat-history.d.ts +3816 -192
  40. package/dist/interface/chat/chat-history.d.ts.map +1 -1
  41. package/dist/interface/chat/chat-history.js +529 -5
  42. package/dist/interface/chat/chat-history.js.map +1 -1
  43. package/dist/interface/chat/chat-runner-commands.d.ts +2 -0
  44. package/dist/interface/chat/chat-runner-commands.d.ts.map +1 -1
  45. package/dist/interface/chat/chat-runner-commands.js +83 -22
  46. package/dist/interface/chat/chat-runner-commands.js.map +1 -1
  47. package/dist/interface/chat/chat-runner-contracts.d.ts +5 -1
  48. package/dist/interface/chat/chat-runner-contracts.d.ts.map +1 -1
  49. package/dist/interface/chat/chat-runner-event-bridge.d.ts +13 -1
  50. package/dist/interface/chat/chat-runner-event-bridge.d.ts.map +1 -1
  51. package/dist/interface/chat/chat-runner-event-bridge.js +51 -3
  52. package/dist/interface/chat/chat-runner-event-bridge.js.map +1 -1
  53. package/dist/interface/chat/chat-runner-routes.d.ts +5 -17
  54. package/dist/interface/chat/chat-runner-routes.d.ts.map +1 -1
  55. package/dist/interface/chat/chat-runner-routes.js +80 -51
  56. package/dist/interface/chat/chat-runner-routes.js.map +1 -1
  57. package/dist/interface/chat/chat-runner-runtime.d.ts.map +1 -1
  58. package/dist/interface/chat/chat-runner-runtime.js +4 -0
  59. package/dist/interface/chat/chat-runner-runtime.js.map +1 -1
  60. package/dist/interface/chat/chat-runner.d.ts +7 -1
  61. package/dist/interface/chat/chat-runner.d.ts.map +1 -1
  62. package/dist/interface/chat/chat-runner.js +135 -49
  63. package/dist/interface/chat/chat-runner.js.map +1 -1
  64. package/dist/interface/chat/chat-session-store.d.ts +3 -0
  65. package/dist/interface/chat/chat-session-store.d.ts.map +1 -1
  66. package/dist/interface/chat/chat-session-store.js +12 -0
  67. package/dist/interface/chat/chat-session-store.js.map +1 -1
  68. package/dist/interface/chat/cross-platform-session.d.ts +15 -0
  69. package/dist/interface/chat/cross-platform-session.d.ts.map +1 -1
  70. package/dist/interface/chat/cross-platform-session.js +260 -42
  71. package/dist/interface/chat/cross-platform-session.js.map +1 -1
  72. package/dist/interface/chat/failure-recovery.d.ts.map +1 -1
  73. package/dist/interface/chat/failure-recovery.js +15 -1
  74. package/dist/interface/chat/failure-recovery.js.map +1 -1
  75. package/dist/interface/chat/freeform-route-classifier.d.ts +4 -4
  76. package/dist/interface/chat/ingress-router.d.ts +3 -0
  77. package/dist/interface/chat/ingress-router.d.ts.map +1 -1
  78. package/dist/interface/chat/ingress-router.js +3 -0
  79. package/dist/interface/chat/ingress-router.js.map +1 -1
  80. package/dist/interface/chat/model-request-builder.d.ts +37 -0
  81. package/dist/interface/chat/model-request-builder.d.ts.map +1 -0
  82. package/dist/interface/chat/model-request-builder.js +76 -0
  83. package/dist/interface/chat/model-request-builder.js.map +1 -0
  84. package/dist/interface/chat/turn-context.d.ts +200 -0
  85. package/dist/interface/chat/turn-context.d.ts.map +1 -0
  86. package/dist/interface/chat/turn-context.js +249 -0
  87. package/dist/interface/chat/turn-context.js.map +1 -0
  88. package/dist/interface/chat/turn-protocol.d.ts +35 -0
  89. package/dist/interface/chat/turn-protocol.d.ts.map +1 -0
  90. package/dist/interface/chat/turn-protocol.js +27 -0
  91. package/dist/interface/chat/turn-protocol.js.map +1 -0
  92. package/dist/interface/chat/user-input.d.ts +55 -0
  93. package/dist/interface/chat/user-input.d.ts.map +1 -0
  94. package/dist/interface/chat/user-input.js +52 -0
  95. package/dist/interface/chat/user-input.js.map +1 -0
  96. package/dist/interface/cli/cli-command-registry.d.ts +1 -1
  97. package/dist/interface/cli/cli-command-registry.d.ts.map +1 -1
  98. package/dist/interface/cli/cli-command-registry.js +12 -16
  99. package/dist/interface/cli/cli-command-registry.js.map +1 -1
  100. package/dist/interface/cli/cli-runner.js +0 -0
  101. package/dist/interface/cli/commands/daemon-shared.d.ts +12 -1
  102. package/dist/interface/cli/commands/daemon-shared.d.ts.map +1 -1
  103. package/dist/interface/cli/commands/daemon-shared.js +26 -4
  104. package/dist/interface/cli/commands/daemon-shared.js.map +1 -1
  105. package/dist/interface/cli/commands/daemon.d.ts.map +1 -1
  106. package/dist/interface/cli/commands/daemon.js +66 -8
  107. package/dist/interface/cli/commands/daemon.js.map +1 -1
  108. package/dist/interface/cli/commands/doctor.d.ts +1 -1
  109. package/dist/interface/cli/commands/doctor.d.ts.map +1 -1
  110. package/dist/interface/cli/commands/doctor.js +61 -29
  111. package/dist/interface/cli/commands/doctor.js.map +1 -1
  112. package/dist/interface/cli/commands/goal-dispatch.d.ts.map +1 -1
  113. package/dist/interface/cli/commands/goal-dispatch.js +10 -6
  114. package/dist/interface/cli/commands/goal-dispatch.js.map +1 -1
  115. package/dist/interface/cli/commands/goal-utils.d.ts.map +1 -1
  116. package/dist/interface/cli/commands/goal-utils.js +3 -5
  117. package/dist/interface/cli/commands/goal-utils.js.map +1 -1
  118. package/dist/interface/cli/commands/run.d.ts.map +1 -1
  119. package/dist/interface/cli/commands/run.js +50 -0
  120. package/dist/interface/cli/commands/run.js.map +1 -1
  121. package/dist/interface/cli/setup.d.ts +1 -1
  122. package/dist/interface/cli/setup.d.ts.map +1 -1
  123. package/dist/interface/cli/setup.js +4 -3
  124. package/dist/interface/cli/setup.js.map +1 -1
  125. package/dist/interface/cli/utils/loop-runner.d.ts +1 -0
  126. package/dist/interface/cli/utils/loop-runner.d.ts.map +1 -1
  127. package/dist/interface/cli/utils/loop-runner.js +12 -3
  128. package/dist/interface/cli/utils/loop-runner.js.map +1 -1
  129. package/dist/interface/tui/app.d.ts +6 -1
  130. package/dist/interface/tui/app.d.ts.map +1 -1
  131. package/dist/interface/tui/app.js +29 -12
  132. package/dist/interface/tui/app.js.map +1 -1
  133. package/dist/interface/tui/bash-mode.d.ts.map +1 -1
  134. package/dist/interface/tui/bash-mode.js +2 -9
  135. package/dist/interface/tui/bash-mode.js.map +1 -1
  136. package/dist/interface/tui/chat/viewport.d.ts.map +1 -1
  137. package/dist/interface/tui/chat/viewport.js +57 -11
  138. package/dist/interface/tui/chat/viewport.js.map +1 -1
  139. package/dist/interface/tui/entry-deps.d.ts +6 -1
  140. package/dist/interface/tui/entry-deps.d.ts.map +1 -1
  141. package/dist/interface/tui/entry-deps.js +3 -0
  142. package/dist/interface/tui/entry-deps.js.map +1 -1
  143. package/dist/interface/tui/entry.d.ts.map +1 -1
  144. package/dist/interface/tui/entry.js +6 -2
  145. package/dist/interface/tui/entry.js.map +1 -1
  146. package/dist/interface/tui/input-action.d.ts.map +1 -1
  147. package/dist/interface/tui/input-action.js +3 -2
  148. package/dist/interface/tui/input-action.js.map +1 -1
  149. package/dist/interface/tui/intent-recognizer.d.ts.map +1 -1
  150. package/dist/interface/tui/intent-recognizer.js +21 -33
  151. package/dist/interface/tui/intent-recognizer.js.map +1 -1
  152. package/dist/orchestrator/execution/adapter-layer.d.ts +10 -1
  153. package/dist/orchestrator/execution/adapter-layer.d.ts.map +1 -1
  154. package/dist/orchestrator/execution/adapter-layer.js.map +1 -1
  155. package/dist/orchestrator/execution/agent-loop/agent-loop-command-classifier.d.ts +12 -1
  156. package/dist/orchestrator/execution/agent-loop/agent-loop-command-classifier.d.ts.map +1 -1
  157. package/dist/orchestrator/execution/agent-loop/agent-loop-command-classifier.js +16 -31
  158. package/dist/orchestrator/execution/agent-loop/agent-loop-command-classifier.js.map +1 -1
  159. package/dist/orchestrator/execution/agent-loop/agent-loop-compaction-record.d.ts +75 -0
  160. package/dist/orchestrator/execution/agent-loop/agent-loop-compaction-record.d.ts.map +1 -0
  161. package/dist/orchestrator/execution/agent-loop/agent-loop-compaction-record.js +10 -0
  162. package/dist/orchestrator/execution/agent-loop/agent-loop-compaction-record.js.map +1 -0
  163. package/dist/orchestrator/execution/agent-loop/agent-loop-compactor.d.ts +3 -2
  164. package/dist/orchestrator/execution/agent-loop/agent-loop-compactor.d.ts.map +1 -1
  165. package/dist/orchestrator/execution/agent-loop/agent-loop-compactor.js +185 -22
  166. package/dist/orchestrator/execution/agent-loop/agent-loop-compactor.js.map +1 -1
  167. package/dist/orchestrator/execution/agent-loop/agent-loop-context-assembler.d.ts.map +1 -1
  168. package/dist/orchestrator/execution/agent-loop/agent-loop-context-assembler.js +18 -1
  169. package/dist/orchestrator/execution/agent-loop/agent-loop-context-assembler.js.map +1 -1
  170. package/dist/orchestrator/execution/agent-loop/agent-loop-default-profile.d.ts.map +1 -1
  171. package/dist/orchestrator/execution/agent-loop/agent-loop-default-profile.js +7 -1
  172. package/dist/orchestrator/execution/agent-loop/agent-loop-default-profile.js.map +1 -1
  173. package/dist/orchestrator/execution/agent-loop/agent-loop-events.d.ts +8 -1
  174. package/dist/orchestrator/execution/agent-loop/agent-loop-events.d.ts.map +1 -1
  175. package/dist/orchestrator/execution/agent-loop/agent-loop-events.js.map +1 -1
  176. package/dist/orchestrator/execution/agent-loop/agent-loop-history.d.ts +3 -1
  177. package/dist/orchestrator/execution/agent-loop/agent-loop-history.d.ts.map +1 -1
  178. package/dist/orchestrator/execution/agent-loop/agent-loop-history.js +12 -3
  179. package/dist/orchestrator/execution/agent-loop/agent-loop-history.js.map +1 -1
  180. package/dist/orchestrator/execution/agent-loop/agent-loop-model-client.d.ts.map +1 -1
  181. package/dist/orchestrator/execution/agent-loop/agent-loop-model-client.js +7 -1
  182. package/dist/orchestrator/execution/agent-loop/agent-loop-model-client.js.map +1 -1
  183. package/dist/orchestrator/execution/agent-loop/agent-loop-model.d.ts +37 -0
  184. package/dist/orchestrator/execution/agent-loop/agent-loop-model.d.ts.map +1 -1
  185. package/dist/orchestrator/execution/agent-loop/agent-loop-model.js +21 -0
  186. package/dist/orchestrator/execution/agent-loop/agent-loop-model.js.map +1 -1
  187. package/dist/orchestrator/execution/agent-loop/agent-loop-prompts.d.ts.map +1 -1
  188. package/dist/orchestrator/execution/agent-loop/agent-loop-prompts.js +1 -0
  189. package/dist/orchestrator/execution/agent-loop/agent-loop-prompts.js.map +1 -1
  190. package/dist/orchestrator/execution/agent-loop/agent-loop-result.d.ts +19 -11
  191. package/dist/orchestrator/execution/agent-loop/agent-loop-result.d.ts.map +1 -1
  192. package/dist/orchestrator/execution/agent-loop/agent-loop-session-state.d.ts +4 -0
  193. package/dist/orchestrator/execution/agent-loop/agent-loop-session-state.d.ts.map +1 -1
  194. package/dist/orchestrator/execution/agent-loop/agent-loop-session-state.js +135 -0
  195. package/dist/orchestrator/execution/agent-loop/agent-loop-session-state.js.map +1 -1
  196. package/dist/orchestrator/execution/agent-loop/agent-loop-tool-runtime.d.ts +3 -2
  197. package/dist/orchestrator/execution/agent-loop/agent-loop-tool-runtime.d.ts.map +1 -1
  198. package/dist/orchestrator/execution/agent-loop/agent-loop-tool-runtime.js +68 -61
  199. package/dist/orchestrator/execution/agent-loop/agent-loop-tool-runtime.js.map +1 -1
  200. package/dist/orchestrator/execution/agent-loop/agent-loop-turn-context.d.ts +3 -1
  201. package/dist/orchestrator/execution/agent-loop/agent-loop-turn-context.d.ts.map +1 -1
  202. package/dist/orchestrator/execution/agent-loop/agent-loop-turn-context.js.map +1 -1
  203. package/dist/orchestrator/execution/agent-loop/agent-timeline.d.ts +12 -1
  204. package/dist/orchestrator/execution/agent-loop/agent-timeline.d.ts.map +1 -1
  205. package/dist/orchestrator/execution/agent-loop/agent-timeline.js +19 -56
  206. package/dist/orchestrator/execution/agent-loop/agent-timeline.js.map +1 -1
  207. package/dist/orchestrator/execution/agent-loop/anthropic-messages-agent-loop-model-client.d.ts.map +1 -1
  208. package/dist/orchestrator/execution/agent-loop/anthropic-messages-agent-loop-model-client.js +8 -2
  209. package/dist/orchestrator/execution/agent-loop/anthropic-messages-agent-loop-model-client.js.map +1 -1
  210. package/dist/orchestrator/execution/agent-loop/bounded-agent-loop-runner.d.ts +14 -0
  211. package/dist/orchestrator/execution/agent-loop/bounded-agent-loop-runner.d.ts.map +1 -1
  212. package/dist/orchestrator/execution/agent-loop/bounded-agent-loop-runner.js +440 -81
  213. package/dist/orchestrator/execution/agent-loop/bounded-agent-loop-runner.js.map +1 -1
  214. package/dist/orchestrator/execution/agent-loop/chat-agent-loop-runner.d.ts +1 -1
  215. package/dist/orchestrator/execution/agent-loop/chat-agent-loop-runner.d.ts.map +1 -1
  216. package/dist/orchestrator/execution/agent-loop/chat-agent-loop-runner.js +80 -12
  217. package/dist/orchestrator/execution/agent-loop/chat-agent-loop-runner.js.map +1 -1
  218. package/dist/orchestrator/execution/agent-loop/chat-display-output.d.ts +1 -0
  219. package/dist/orchestrator/execution/agent-loop/chat-display-output.d.ts.map +1 -1
  220. package/dist/orchestrator/execution/agent-loop/chat-display-output.js +3 -1
  221. package/dist/orchestrator/execution/agent-loop/chat-display-output.js.map +1 -1
  222. package/dist/orchestrator/execution/agent-loop/index.d.ts +3 -0
  223. package/dist/orchestrator/execution/agent-loop/index.d.ts.map +1 -1
  224. package/dist/orchestrator/execution/agent-loop/index.js +3 -0
  225. package/dist/orchestrator/execution/agent-loop/index.js.map +1 -1
  226. package/dist/orchestrator/execution/agent-loop/openai-responses-agent-loop-model-client.d.ts +1 -0
  227. package/dist/orchestrator/execution/agent-loop/openai-responses-agent-loop-model-client.d.ts.map +1 -1
  228. package/dist/orchestrator/execution/agent-loop/openai-responses-agent-loop-model-client.js +51 -9
  229. package/dist/orchestrator/execution/agent-loop/openai-responses-agent-loop-model-client.js.map +1 -1
  230. package/dist/orchestrator/execution/agent-loop/response-item-tool-router.d.ts +20 -0
  231. package/dist/orchestrator/execution/agent-loop/response-item-tool-router.d.ts.map +1 -0
  232. package/dist/orchestrator/execution/agent-loop/response-item-tool-router.js +181 -0
  233. package/dist/orchestrator/execution/agent-loop/response-item-tool-router.js.map +1 -0
  234. package/dist/orchestrator/execution/agent-loop/response-item.d.ts +805 -0
  235. package/dist/orchestrator/execution/agent-loop/response-item.d.ts.map +1 -0
  236. package/dist/orchestrator/execution/agent-loop/response-item.js +104 -0
  237. package/dist/orchestrator/execution/agent-loop/response-item.js.map +1 -0
  238. package/dist/orchestrator/execution/agent-loop/task-agent-loop-context.d.ts +7 -2
  239. package/dist/orchestrator/execution/agent-loop/task-agent-loop-context.d.ts.map +1 -1
  240. package/dist/orchestrator/execution/agent-loop/task-agent-loop-context.js +33 -1
  241. package/dist/orchestrator/execution/agent-loop/task-agent-loop-context.js.map +1 -1
  242. package/dist/orchestrator/execution/agent-loop/task-agent-loop-result.d.ts +32 -17
  243. package/dist/orchestrator/execution/agent-loop/task-agent-loop-result.d.ts.map +1 -1
  244. package/dist/orchestrator/execution/agent-loop/task-agent-loop-result.js +174 -16
  245. package/dist/orchestrator/execution/agent-loop/task-agent-loop-result.js.map +1 -1
  246. package/dist/orchestrator/execution/agent-loop/task-agent-loop-runner.d.ts +2 -0
  247. package/dist/orchestrator/execution/agent-loop/task-agent-loop-runner.d.ts.map +1 -1
  248. package/dist/orchestrator/execution/agent-loop/task-agent-loop-runner.js +10 -4
  249. package/dist/orchestrator/execution/agent-loop/task-agent-loop-runner.js.map +1 -1
  250. package/dist/orchestrator/execution/agent-loop/task-agent-loop-verification.d.ts +0 -1
  251. package/dist/orchestrator/execution/agent-loop/task-agent-loop-verification.d.ts.map +1 -1
  252. package/dist/orchestrator/execution/agent-loop/task-agent-loop-verification.js +7 -87
  253. package/dist/orchestrator/execution/agent-loop/task-agent-loop-verification.js.map +1 -1
  254. package/dist/orchestrator/execution/agent-loop/task-agent-loop-worktree.d.ts.map +1 -1
  255. package/dist/orchestrator/execution/agent-loop/task-agent-loop-worktree.js +25 -0
  256. package/dist/orchestrator/execution/agent-loop/task-agent-loop-worktree.js.map +1 -1
  257. package/dist/orchestrator/execution/context/issue-context-fetcher.d.ts +5 -1
  258. package/dist/orchestrator/execution/context/issue-context-fetcher.d.ts.map +1 -1
  259. package/dist/orchestrator/execution/context/issue-context-fetcher.js +7 -4
  260. package/dist/orchestrator/execution/context/issue-context-fetcher.js.map +1 -1
  261. package/dist/orchestrator/execution/task/task-artifact-contract.d.ts +18 -0
  262. package/dist/orchestrator/execution/task/task-artifact-contract.d.ts.map +1 -0
  263. package/dist/orchestrator/execution/task/task-artifact-contract.js +199 -0
  264. package/dist/orchestrator/execution/task/task-artifact-contract.js.map +1 -0
  265. package/dist/orchestrator/execution/task/task-diff-capture.d.ts +15 -1
  266. package/dist/orchestrator/execution/task/task-diff-capture.d.ts.map +1 -1
  267. package/dist/orchestrator/execution/task/task-diff-capture.js +271 -18
  268. package/dist/orchestrator/execution/task/task-diff-capture.js.map +1 -1
  269. package/dist/orchestrator/execution/task/task-execution-helpers.d.ts +1 -0
  270. package/dist/orchestrator/execution/task/task-execution-helpers.d.ts.map +1 -1
  271. package/dist/orchestrator/execution/task/task-execution-helpers.js +76 -17
  272. package/dist/orchestrator/execution/task/task-execution-helpers.js.map +1 -1
  273. package/dist/orchestrator/execution/task/task-execution-types.d.ts +2 -0
  274. package/dist/orchestrator/execution/task/task-execution-types.d.ts.map +1 -1
  275. package/dist/orchestrator/execution/task/task-execution-types.js.map +1 -1
  276. package/dist/orchestrator/execution/task/task-executor.d.ts +16 -1
  277. package/dist/orchestrator/execution/task/task-executor.d.ts.map +1 -1
  278. package/dist/orchestrator/execution/task/task-executor.js +56 -50
  279. package/dist/orchestrator/execution/task/task-executor.js.map +1 -1
  280. package/dist/orchestrator/execution/task/task-generation.d.ts +62 -2
  281. package/dist/orchestrator/execution/task/task-generation.d.ts.map +1 -1
  282. package/dist/orchestrator/execution/task/task-generation.js +30 -13
  283. package/dist/orchestrator/execution/task/task-generation.js.map +1 -1
  284. package/dist/orchestrator/execution/task/task-lifecycle-runner.d.ts +2 -2
  285. package/dist/orchestrator/execution/task/task-lifecycle-runner.d.ts.map +1 -1
  286. package/dist/orchestrator/execution/task/task-lifecycle-runner.js +32 -4
  287. package/dist/orchestrator/execution/task/task-lifecycle-runner.js.map +1 -1
  288. package/dist/orchestrator/execution/task/task-lifecycle.d.ts +3 -3
  289. package/dist/orchestrator/execution/task/task-lifecycle.d.ts.map +1 -1
  290. package/dist/orchestrator/execution/task/task-lifecycle.js +109 -10
  291. package/dist/orchestrator/execution/task/task-lifecycle.js.map +1 -1
  292. package/dist/orchestrator/execution/task/task-outcome-ledger.d.ts +9 -0
  293. package/dist/orchestrator/execution/task/task-outcome-ledger.d.ts.map +1 -1
  294. package/dist/orchestrator/execution/task/task-outcome-ledger.js +64 -3
  295. package/dist/orchestrator/execution/task/task-outcome-ledger.js.map +1 -1
  296. package/dist/orchestrator/execution/task/task-prompt-builder.d.ts +3 -1
  297. package/dist/orchestrator/execution/task/task-prompt-builder.d.ts.map +1 -1
  298. package/dist/orchestrator/execution/task/task-prompt-builder.js +28 -13
  299. package/dist/orchestrator/execution/task/task-prompt-builder.js.map +1 -1
  300. package/dist/orchestrator/execution/task/task-verifier-rules.d.ts +3 -2
  301. package/dist/orchestrator/execution/task/task-verifier-rules.d.ts.map +1 -1
  302. package/dist/orchestrator/execution/task/task-verifier-rules.js +377 -90
  303. package/dist/orchestrator/execution/task/task-verifier-rules.js.map +1 -1
  304. package/dist/orchestrator/execution/task/task-verifier-types.d.ts +13 -0
  305. package/dist/orchestrator/execution/task/task-verifier-types.d.ts.map +1 -1
  306. package/dist/orchestrator/execution/task/task-verifier-types.js.map +1 -1
  307. package/dist/orchestrator/execution/task/task-verifier.d.ts +5 -4
  308. package/dist/orchestrator/execution/task/task-verifier.d.ts.map +1 -1
  309. package/dist/orchestrator/execution/task/task-verifier.js +396 -25
  310. package/dist/orchestrator/execution/task/task-verifier.js.map +1 -1
  311. package/dist/orchestrator/execution/task/task-workspace.d.ts +5 -0
  312. package/dist/orchestrator/execution/task/task-workspace.d.ts.map +1 -1
  313. package/dist/orchestrator/execution/task/task-workspace.js +20 -10
  314. package/dist/orchestrator/execution/task/task-workspace.js.map +1 -1
  315. package/dist/orchestrator/execution/types/task-group.d.ts +85 -5
  316. package/dist/orchestrator/execution/types/task-group.d.ts.map +1 -1
  317. package/dist/orchestrator/execution/types/task.d.ts +155 -3
  318. package/dist/orchestrator/execution/types/task.d.ts.map +1 -1
  319. package/dist/orchestrator/execution/types/task.js +18 -0
  320. package/dist/orchestrator/execution/types/task.js.map +1 -1
  321. package/dist/orchestrator/loop/durable-loop/contracts.d.ts +2 -0
  322. package/dist/orchestrator/loop/durable-loop/contracts.d.ts.map +1 -1
  323. package/dist/orchestrator/loop/durable-loop/contracts.js.map +1 -1
  324. package/dist/orchestrator/loop/durable-loop/phase-specs.d.ts +12 -12
  325. package/dist/orchestrator/loop/durable-loop/preparation.d.ts.map +1 -1
  326. package/dist/orchestrator/loop/durable-loop/preparation.js +7 -1
  327. package/dist/orchestrator/loop/durable-loop/preparation.js.map +1 -1
  328. package/dist/orchestrator/loop/loop-report-helper.d.ts.map +1 -1
  329. package/dist/orchestrator/loop/loop-report-helper.js +2 -0
  330. package/dist/orchestrator/loop/loop-report-helper.js.map +1 -1
  331. package/dist/platform/corrections/memory-correction-ledger.d.ts +30 -30
  332. package/dist/platform/corrections/memory-governance.d.ts +2 -2
  333. package/dist/platform/corrections/memory-quarantine.d.ts +2 -2
  334. package/dist/platform/dream/playbook-memory.d.ts +4 -4
  335. package/dist/platform/knowledge/types/agent-memory.d.ts +46 -46
  336. package/dist/platform/observation/context-provider/collector.d.ts.map +1 -1
  337. package/dist/platform/observation/context-provider/collector.js +89 -24
  338. package/dist/platform/observation/context-provider/collector.js.map +1 -1
  339. package/dist/platform/observation/data-source-adapter.d.ts +2 -0
  340. package/dist/platform/observation/data-source-adapter.d.ts.map +1 -1
  341. package/dist/platform/observation/data-source-adapter.js.map +1 -1
  342. package/dist/platform/observation/observation-apply.d.ts.map +1 -1
  343. package/dist/platform/observation/observation-apply.js +8 -2
  344. package/dist/platform/observation/observation-apply.js.map +1 -1
  345. package/dist/platform/observation/observation-engine.d.ts.map +1 -1
  346. package/dist/platform/observation/observation-engine.js +118 -70
  347. package/dist/platform/observation/observation-engine.js.map +1 -1
  348. package/dist/platform/observation/observation-helpers.d.ts +2 -0
  349. package/dist/platform/observation/observation-helpers.d.ts.map +1 -1
  350. package/dist/platform/observation/observation-helpers.js.map +1 -1
  351. package/dist/platform/observation/types/data-source.d.ts +48 -0
  352. package/dist/platform/observation/types/data-source.d.ts.map +1 -1
  353. package/dist/platform/observation/types/data-source.js +4 -0
  354. package/dist/platform/observation/types/data-source.js.map +1 -1
  355. package/dist/platform/observation/workspace-context.d.ts.map +1 -1
  356. package/dist/platform/observation/workspace-context.js +13 -18
  357. package/dist/platform/observation/workspace-context.js.map +1 -1
  358. package/dist/platform/soil/contracts.d.ts +58 -58
  359. package/dist/prompt/purposes/verification.d.ts +2 -2
  360. package/dist/reporting/report-formatters.d.ts.map +1 -1
  361. package/dist/reporting/report-formatters.js +26 -1
  362. package/dist/reporting/report-formatters.js.map +1 -1
  363. package/dist/reporting/reporting-engine.d.ts.map +1 -1
  364. package/dist/reporting/reporting-engine.js +1 -0
  365. package/dist/reporting/reporting-engine.js.map +1 -1
  366. package/dist/reporting/reporting-types.d.ts +7 -0
  367. package/dist/reporting/reporting-types.d.ts.map +1 -1
  368. package/dist/reporting/types/report.d.ts +12 -0
  369. package/dist/reporting/types/report.d.ts.map +1 -1
  370. package/dist/reporting/types/report.js +1 -0
  371. package/dist/reporting/types/report.js.map +1 -1
  372. package/dist/runtime/approval-broker.d.ts +12 -0
  373. package/dist/runtime/approval-broker.d.ts.map +1 -1
  374. package/dist/runtime/approval-broker.js +27 -7
  375. package/dist/runtime/approval-broker.js.map +1 -1
  376. package/dist/runtime/control/daemon-runtime-control-executor.d.ts.map +1 -1
  377. package/dist/runtime/control/daemon-runtime-control-executor.js +9 -4
  378. package/dist/runtime/control/daemon-runtime-control-executor.js.map +1 -1
  379. package/dist/runtime/control/runtime-control-intent.d.ts.map +1 -1
  380. package/dist/runtime/control/runtime-control-intent.js +3 -2
  381. package/dist/runtime/control/runtime-control-intent.js.map +1 -1
  382. package/dist/runtime/control/runtime-control-service.d.ts +27 -1
  383. package/dist/runtime/control/runtime-control-service.d.ts.map +1 -1
  384. package/dist/runtime/control/runtime-control-service.js +181 -2
  385. package/dist/runtime/control/runtime-control-service.js.map +1 -1
  386. package/dist/runtime/control/runtime-target-resolver.js +2 -0
  387. package/dist/runtime/control/runtime-target-resolver.js.map +1 -1
  388. package/dist/runtime/daemon/browser-backpressure-policy.d.ts +22 -0
  389. package/dist/runtime/daemon/browser-backpressure-policy.d.ts.map +1 -0
  390. package/dist/runtime/daemon/browser-backpressure-policy.js +95 -0
  391. package/dist/runtime/daemon/browser-backpressure-policy.js.map +1 -0
  392. package/dist/runtime/daemon/client.d.ts +1 -0
  393. package/dist/runtime/daemon/client.d.ts.map +1 -1
  394. package/dist/runtime/daemon/client.js.map +1 -1
  395. package/dist/runtime/daemon/runner-goal-cycle.d.ts.map +1 -1
  396. package/dist/runtime/daemon/runner-goal-cycle.js +1 -2
  397. package/dist/runtime/daemon/runner-goal-cycle.js.map +1 -1
  398. package/dist/runtime/daemon/runner-recovery.d.ts +17 -3
  399. package/dist/runtime/daemon/runner-recovery.d.ts.map +1 -1
  400. package/dist/runtime/daemon/runner-recovery.js +50 -12
  401. package/dist/runtime/daemon/runner-recovery.js.map +1 -1
  402. package/dist/runtime/daemon/runner-startup.d.ts.map +1 -1
  403. package/dist/runtime/daemon/runner-startup.js +18 -1
  404. package/dist/runtime/daemon/runner-startup.js.map +1 -1
  405. package/dist/runtime/daemon/runner.d.ts.map +1 -1
  406. package/dist/runtime/daemon/runner.js +13 -3
  407. package/dist/runtime/daemon/runner.js.map +1 -1
  408. package/dist/runtime/daemon/runtime-ownership.d.ts +7 -1
  409. package/dist/runtime/daemon/runtime-ownership.d.ts.map +1 -1
  410. package/dist/runtime/daemon/runtime-ownership.js +171 -25
  411. package/dist/runtime/daemon/runtime-ownership.js.map +1 -1
  412. package/dist/runtime/daemon/wait-deadline-resolver.d.ts.map +1 -1
  413. package/dist/runtime/daemon/wait-deadline-resolver.js +2 -0
  414. package/dist/runtime/daemon/wait-deadline-resolver.js.map +1 -1
  415. package/dist/runtime/event/server-snapshot-reader.d.ts +3 -1
  416. package/dist/runtime/event/server-snapshot-reader.d.ts.map +1 -1
  417. package/dist/runtime/event/server-snapshot-reader.js +68 -2
  418. package/dist/runtime/event/server-snapshot-reader.js.map +1 -1
  419. package/dist/runtime/event/server-types.d.ts +2 -0
  420. package/dist/runtime/event/server-types.d.ts.map +1 -1
  421. package/dist/runtime/evidence-answer.d.ts.map +1 -1
  422. package/dist/runtime/evidence-answer.js +34 -7
  423. package/dist/runtime/evidence-answer.js.map +1 -1
  424. package/dist/runtime/gateway/channel-adapter.d.ts +3 -0
  425. package/dist/runtime/gateway/channel-adapter.d.ts.map +1 -1
  426. package/dist/runtime/gateway/channel-display-policy.d.ts +42 -0
  427. package/dist/runtime/gateway/channel-display-policy.d.ts.map +1 -0
  428. package/dist/runtime/gateway/channel-display-policy.js +85 -0
  429. package/dist/runtime/gateway/channel-display-policy.js.map +1 -0
  430. package/dist/runtime/gateway/chat-event-rendering.d.ts +2 -1
  431. package/dist/runtime/gateway/chat-event-rendering.d.ts.map +1 -1
  432. package/dist/runtime/gateway/chat-event-rendering.js +2 -0
  433. package/dist/runtime/gateway/chat-event-rendering.js.map +1 -1
  434. package/dist/runtime/gateway/chat-session-dispatch.d.ts.map +1 -1
  435. package/dist/runtime/gateway/chat-session-dispatch.js +4 -9
  436. package/dist/runtime/gateway/chat-session-dispatch.js.map +1 -1
  437. package/dist/runtime/gateway/chat-session-port.d.ts +2 -0
  438. package/dist/runtime/gateway/chat-session-port.d.ts.map +1 -1
  439. package/dist/runtime/gateway/chat-session-port.js.map +1 -1
  440. package/dist/runtime/gateway/discord-gateway-adapter.d.ts +4 -0
  441. package/dist/runtime/gateway/discord-gateway-adapter.d.ts.map +1 -1
  442. package/dist/runtime/gateway/discord-gateway-adapter.js +100 -31
  443. package/dist/runtime/gateway/discord-gateway-adapter.js.map +1 -1
  444. package/dist/runtime/gateway/index.d.ts +4 -0
  445. package/dist/runtime/gateway/index.d.ts.map +1 -1
  446. package/dist/runtime/gateway/index.js +2 -0
  447. package/dist/runtime/gateway/index.js.map +1 -1
  448. package/dist/runtime/gateway/non-tui-display-projector.d.ts +40 -0
  449. package/dist/runtime/gateway/non-tui-display-projector.d.ts.map +1 -0
  450. package/dist/runtime/gateway/non-tui-display-projector.js +166 -0
  451. package/dist/runtime/gateway/non-tui-display-projector.js.map +1 -0
  452. package/dist/runtime/gateway/signal-gateway-adapter.d.ts +1 -0
  453. package/dist/runtime/gateway/signal-gateway-adapter.d.ts.map +1 -1
  454. package/dist/runtime/gateway/signal-gateway-adapter.js +47 -4
  455. package/dist/runtime/gateway/signal-gateway-adapter.js.map +1 -1
  456. package/dist/runtime/gateway/slack-channel-adapter.d.ts +1 -0
  457. package/dist/runtime/gateway/slack-channel-adapter.d.ts.map +1 -1
  458. package/dist/runtime/gateway/slack-channel-adapter.js +93 -18
  459. package/dist/runtime/gateway/slack-channel-adapter.js.map +1 -1
  460. package/dist/runtime/gateway/telegram-gateway-adapter.d.ts +2 -0
  461. package/dist/runtime/gateway/telegram-gateway-adapter.d.ts.map +1 -1
  462. package/dist/runtime/gateway/telegram-gateway-adapter.js +61 -113
  463. package/dist/runtime/gateway/telegram-gateway-adapter.js.map +1 -1
  464. package/dist/runtime/gateway/whatsapp-gateway-adapter.d.ts +1 -0
  465. package/dist/runtime/gateway/whatsapp-gateway-adapter.d.ts.map +1 -1
  466. package/dist/runtime/gateway/whatsapp-gateway-adapter.js +49 -4
  467. package/dist/runtime/gateway/whatsapp-gateway-adapter.js.map +1 -1
  468. package/dist/runtime/interactive-automation/browser-session-resolver.d.ts +26 -0
  469. package/dist/runtime/interactive-automation/browser-session-resolver.d.ts.map +1 -0
  470. package/dist/runtime/interactive-automation/browser-session-resolver.js +75 -0
  471. package/dist/runtime/interactive-automation/browser-session-resolver.js.map +1 -0
  472. package/dist/runtime/interactive-automation/index.d.ts +2 -0
  473. package/dist/runtime/interactive-automation/index.d.ts.map +1 -1
  474. package/dist/runtime/interactive-automation/index.js +2 -0
  475. package/dist/runtime/interactive-automation/index.js.map +1 -1
  476. package/dist/runtime/interactive-automation/runtime-auth-handoff-store.d.ts +35 -0
  477. package/dist/runtime/interactive-automation/runtime-auth-handoff-store.d.ts.map +1 -0
  478. package/dist/runtime/interactive-automation/runtime-auth-handoff-store.js +125 -0
  479. package/dist/runtime/interactive-automation/runtime-auth-handoff-store.js.map +1 -0
  480. package/dist/runtime/permission-dialogue.d.ts +113 -0
  481. package/dist/runtime/permission-dialogue.d.ts.map +1 -0
  482. package/dist/runtime/permission-dialogue.js +82 -0
  483. package/dist/runtime/permission-dialogue.js.map +1 -0
  484. package/dist/runtime/run-spec/derive.d.ts +14 -14
  485. package/dist/runtime/run-spec/handoff.d.ts.map +1 -1
  486. package/dist/runtime/run-spec/handoff.js +33 -0
  487. package/dist/runtime/run-spec/handoff.js.map +1 -1
  488. package/dist/runtime/run-spec/types.d.ts +16 -16
  489. package/dist/runtime/session-registry/types.d.ts +12 -12
  490. package/dist/runtime/store/artifact-retention.d.ts +2 -0
  491. package/dist/runtime/store/artifact-retention.d.ts.map +1 -1
  492. package/dist/runtime/store/artifact-retention.js +24 -21
  493. package/dist/runtime/store/artifact-retention.js.map +1 -1
  494. package/dist/runtime/store/budget-store.d.ts +8 -8
  495. package/dist/runtime/store/evidence-ledger.d.ts.map +1 -1
  496. package/dist/runtime/store/evidence-ledger.js +39 -1
  497. package/dist/runtime/store/evidence-ledger.js.map +1 -1
  498. package/dist/runtime/store/evidence-types.d.ts +204 -204
  499. package/dist/runtime/store/experiment-queue-store.d.ts +20 -20
  500. package/dist/runtime/store/index.d.ts +2 -2
  501. package/dist/runtime/store/index.d.ts.map +1 -1
  502. package/dist/runtime/store/index.js +1 -1
  503. package/dist/runtime/store/index.js.map +1 -1
  504. package/dist/runtime/store/operator-handoff-store.d.ts +3 -3
  505. package/dist/runtime/store/reproducibility-manifest.d.ts +20 -20
  506. package/dist/runtime/store/runtime-operation-schemas.d.ts +95 -62
  507. package/dist/runtime/store/runtime-operation-schemas.d.ts.map +1 -1
  508. package/dist/runtime/store/runtime-operation-schemas.js +9 -0
  509. package/dist/runtime/store/runtime-operation-schemas.js.map +1 -1
  510. package/dist/runtime/store/runtime-paths.d.ts +2 -0
  511. package/dist/runtime/store/runtime-paths.d.ts.map +1 -1
  512. package/dist/runtime/store/runtime-paths.js +6 -0
  513. package/dist/runtime/store/runtime-paths.js.map +1 -1
  514. package/dist/runtime/store/runtime-schemas.d.ts +2256 -46
  515. package/dist/runtime/store/runtime-schemas.d.ts.map +1 -1
  516. package/dist/runtime/store/runtime-schemas.js +85 -0
  517. package/dist/runtime/store/runtime-schemas.js.map +1 -1
  518. package/dist/runtime/types/companion.d.ts +52 -52
  519. package/dist/runtime/types/daemon.d.ts +31 -31
  520. package/dist/tools/automation/InteractiveAutomationTools.d.ts +22 -2
  521. package/dist/tools/automation/InteractiveAutomationTools.d.ts.map +1 -1
  522. package/dist/tools/automation/InteractiveAutomationTools.js +75 -10
  523. package/dist/tools/automation/InteractiveAutomationTools.js.map +1 -1
  524. package/dist/tools/builtin/factory.d.ts +2 -1
  525. package/dist/tools/builtin/factory.d.ts.map +1 -1
  526. package/dist/tools/builtin/factory.js +6 -2
  527. package/dist/tools/builtin/factory.js.map +1 -1
  528. package/dist/tools/execution/MemorySaveTool/MemorySaveTool.d.ts +20 -20
  529. package/dist/tools/execution/RunAdapterTool/RunAdapterTool.d.ts +6 -0
  530. package/dist/tools/execution/RunAdapterTool/RunAdapterTool.d.ts.map +1 -1
  531. package/dist/tools/execution/RunAdapterTool/RunAdapterTool.js +2 -0
  532. package/dist/tools/execution/RunAdapterTool/RunAdapterTool.js.map +1 -1
  533. package/dist/tools/execution-orchestrator.d.ts +29 -0
  534. package/dist/tools/execution-orchestrator.d.ts.map +1 -0
  535. package/dist/tools/execution-orchestrator.js +153 -0
  536. package/dist/tools/execution-orchestrator.js.map +1 -0
  537. package/dist/tools/executor.d.ts +6 -0
  538. package/dist/tools/executor.d.ts.map +1 -1
  539. package/dist/tools/executor.js +48 -11
  540. package/dist/tools/executor.js.map +1 -1
  541. package/dist/tools/fs/ApplyPatchTool/ApplyPatchTool.d.ts.map +1 -1
  542. package/dist/tools/fs/ApplyPatchTool/ApplyPatchTool.js +130 -17
  543. package/dist/tools/fs/ApplyPatchTool/ApplyPatchTool.js.map +1 -1
  544. package/dist/tools/kaggle/KaggleExperimentTools.js +4 -3
  545. package/dist/tools/kaggle/KaggleExperimentTools.js.map +1 -1
  546. package/dist/tools/kaggle/KaggleSubmissionTools.js +6 -5
  547. package/dist/tools/kaggle/KaggleSubmissionTools.js.map +1 -1
  548. package/dist/tools/kaggle/KaggleWorkspacePrepareTool.js +6 -5
  549. package/dist/tools/kaggle/KaggleWorkspacePrepareTool.js.map +1 -1
  550. package/dist/tools/kaggle/paths.d.ts.map +1 -1
  551. package/dist/tools/kaggle/paths.js +12 -8
  552. package/dist/tools/kaggle/paths.js.map +1 -1
  553. package/dist/tools/mutation/TaskStopTool/TaskStopTool.d.ts.map +1 -1
  554. package/dist/tools/mutation/TaskStopTool/TaskStopTool.js +8 -0
  555. package/dist/tools/mutation/TaskStopTool/TaskStopTool.js.map +1 -1
  556. package/dist/tools/mutation/TaskUpdateTool/TaskUpdateTool.d.ts +8 -8
  557. package/dist/tools/mutation/TaskUpdateTool/TaskUpdateTool.d.ts.map +1 -1
  558. package/dist/tools/mutation/TaskUpdateTool/TaskUpdateTool.js +49 -7
  559. package/dist/tools/mutation/TaskUpdateTool/TaskUpdateTool.js.map +1 -1
  560. package/dist/tools/network/GitHubCliTool/GitHubCliTool.d.ts +4 -4
  561. package/dist/tools/network/McpStdioTool/McpStdioTool.d.ts +4 -4
  562. package/dist/tools/permission.d.ts +0 -1
  563. package/dist/tools/permission.d.ts.map +1 -1
  564. package/dist/tools/permission.js +9 -33
  565. package/dist/tools/permission.js.map +1 -1
  566. package/dist/tools/query/CodeReadContextTool/CodeReadContextTool.d.ts +4 -4
  567. package/dist/tools/query/CodeSearchRepairTool/CodeSearchRepairTool.d.ts +8 -8
  568. package/dist/tools/query/CodeSearchTool/CodeSearchTool.d.ts +4 -4
  569. package/dist/tools/query/MemoryRecallTool/MemoryRecallTool.d.ts +4 -4
  570. package/dist/tools/query/runtime-session-tools.d.ts +73 -5
  571. package/dist/tools/query/runtime-session-tools.d.ts.map +1 -1
  572. package/dist/tools/query/runtime-session-tools.js +114 -0
  573. package/dist/tools/query/runtime-session-tools.js.map +1 -1
  574. package/dist/tools/runtime/LongRunningRuntimeTools.d.ts +72 -54
  575. package/dist/tools/runtime/LongRunningRuntimeTools.d.ts.map +1 -1
  576. package/dist/tools/runtime/LongRunningRuntimeTools.js +4 -1
  577. package/dist/tools/runtime/LongRunningRuntimeTools.js.map +1 -1
  578. package/dist/tools/runtime/RunSpecHandoffTools.d.ts.map +1 -1
  579. package/dist/tools/runtime/RunSpecHandoffTools.js +162 -2
  580. package/dist/tools/runtime/RunSpecHandoffTools.js.map +1 -1
  581. package/dist/tools/runtime/SetupRuntimeControlTools.d.ts.map +1 -1
  582. package/dist/tools/runtime/SetupRuntimeControlTools.js +169 -17
  583. package/dist/tools/runtime/SetupRuntimeControlTools.js.map +1 -1
  584. package/dist/tools/system/EnvTool/EnvTool.d.ts +4 -4
  585. package/dist/tools/system/GitDiffTool/GitDiffTool.d.ts +4 -4
  586. package/dist/tools/system/GitLogTool/GitLogTool.d.ts +4 -4
  587. package/dist/tools/system/ShellCommandTool/ShellCommandTool.d.ts.map +1 -1
  588. package/dist/tools/system/ShellCommandTool/ShellCommandTool.js +8 -2
  589. package/dist/tools/system/ShellCommandTool/ShellCommandTool.js.map +1 -1
  590. package/dist/tools/system/ShellTool/ShellTool.d.ts.map +1 -1
  591. package/dist/tools/system/ShellTool/ShellTool.js +29 -11
  592. package/dist/tools/system/ShellTool/ShellTool.js.map +1 -1
  593. package/dist/tools/system/ShellTool/command-policy.d.ts +12 -8
  594. package/dist/tools/system/ShellTool/command-policy.d.ts.map +1 -1
  595. package/dist/tools/system/ShellTool/command-policy.js +412 -98
  596. package/dist/tools/system/ShellTool/command-policy.js.map +1 -1
  597. package/dist/tools/system/ShellTool/prompt.d.ts +1 -1
  598. package/dist/tools/system/ShellTool/prompt.d.ts.map +1 -1
  599. package/dist/tools/system/ShellTool/prompt.js +1 -1
  600. package/dist/tools/system/ShellTool/prompt.js.map +1 -1
  601. package/dist/tools/system/TestRunnerTool/TestRunnerTool.d.ts +1 -1
  602. package/dist/tools/system/TestRunnerTool/TestRunnerTool.d.ts.map +1 -1
  603. package/dist/tools/system/TestRunnerTool/TestRunnerTool.js +152 -8
  604. package/dist/tools/system/TestRunnerTool/TestRunnerTool.js.map +1 -1
  605. package/dist/tools/system/UpdatePlanTool/UpdatePlanTool.js +1 -1
  606. package/dist/tools/system/UpdatePlanTool/UpdatePlanTool.js.map +1 -1
  607. package/dist/tools/types.d.ts +36 -12
  608. package/dist/tools/types.d.ts.map +1 -1
  609. package/dist/tools/types.js +26 -3
  610. package/dist/tools/types.js.map +1 -1
  611. package/dist/tools/workspace-scope.d.ts +11 -0
  612. package/dist/tools/workspace-scope.d.ts.map +1 -0
  613. package/dist/tools/workspace-scope.js +77 -0
  614. package/dist/tools/workspace-scope.js.map +1 -0
  615. package/package.json +2 -2
@@ -1,9 +1,37 @@
1
- import { randomUUID } from "node:crypto";
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import * as fsp from "node:fs/promises";
3
+ import * as path from "node:path";
2
4
  import { execFileNoThrow } from "../../../base/utils/execFileNoThrow.js";
3
5
  import { createAgentLoopHistory } from "./agent-loop-history.js";
4
6
  import { formatAgentLoopModelRef } from "./agent-loop-model.js";
5
7
  import { ExtractiveAgentLoopCompactor } from "./agent-loop-compactor.js";
8
+ import { cloneAgentLoopCompactionRecords } from "./agent-loop-compaction-record.js";
6
9
  import { classifyAgentLoopCommandResult } from "./agent-loop-command-classifier.js";
10
+ import { assistantTextResponseItem, functionToolCallResponseItem, } from "./response-item.js";
11
+ function readToolResultCheckOnly(result) {
12
+ const data = result.rawResult?.data;
13
+ if (result.toolName === "apply_patch" &&
14
+ data &&
15
+ typeof data === "object" &&
16
+ "checkOnly" in data &&
17
+ typeof data.checkOnly === "boolean") {
18
+ return data.checkOnly;
19
+ }
20
+ return undefined;
21
+ }
22
+ const FILESYSTEM_SNAPSHOT_EXCLUDED_DIRS = new Set([
23
+ ".git",
24
+ "node_modules",
25
+ ".venv",
26
+ "venv",
27
+ "__pycache__",
28
+ ".cache",
29
+ "dist",
30
+ "build",
31
+ ]);
32
+ const FILESYSTEM_SNAPSHOT_MAX_FILES = 5_000;
33
+ const FILESYSTEM_SNAPSHOT_HASH_MAX_BYTES = 1_000_000;
34
+ const MIN_MUTATING_TOOL_BATCH_REMAINING_MS = 1_000;
7
35
  export class BoundedAgentLoopRunner {
8
36
  deps;
9
37
  compactor;
@@ -22,12 +50,16 @@ export class BoundedAgentLoopRunner {
22
50
  let completionValidationAttempts = resumed?.completionValidationAttempts ?? 0;
23
51
  let finalText = resumed?.finalText ?? "";
24
52
  let compactions = resumed?.compactions ?? 0;
53
+ let compactionRecords = cloneAgentLoopCompactionRecords(resumed?.compactionRecords);
25
54
  const calledTools = new Set(resumed?.calledTools ?? []);
26
55
  let lastToolLoopSignature = resumed?.lastToolLoopSignature ?? null;
27
56
  let repeatedToolLoopCount = resumed?.repeatedToolLoopCount ?? 0;
28
57
  const commandResults = [];
29
58
  const toolResultSummaries = [];
30
59
  const initialWorkspaceSnapshot = await this.captureWorkspaceSnapshot(turn.cwd);
60
+ let finalizationReserveUsed = false;
61
+ let forceFinalAnswerOnly = false;
62
+ const stop = (reason, startedAt, modelTurns, toolCalls, finalText, output, success = false, compactions = 0, changedFiles = [], toolResults = [], commandResults = [], messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, reasonDetail, failureReason) => this.stop(turn, reason, startedAt, modelTurns, toolCalls, finalText, output, success, compactions, changedFiles, toolResults, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, reasonDetail, failureReason, compactionRecords);
31
63
  await this.record(turn, {
32
64
  type: "started",
33
65
  ...this.baseEvent(turn),
@@ -41,27 +73,39 @@ export class BoundedAgentLoopRunner {
41
73
  });
42
74
  }
43
75
  let messages = resumed?.messages ? [...resumed.messages] : [...turn.messages];
44
- const preTurnCompaction = await this.compactIfNeeded(turn, messages, "pre_turn", "context_limit", undefined, compactions);
76
+ const preTurnCompaction = await this.compactIfNeeded(turn, messages, "pre_turn", "context_limit", undefined, compactions, compactionRecords);
45
77
  if (preTurnCompaction.error) {
46
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, [], toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
78
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, [], toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
47
79
  }
48
80
  messages = preTurnCompaction.messages;
81
+ compactionRecords = preTurnCompaction.compactionRecords;
49
82
  compactions += preTurnCompaction.compacted ? 1 : 0;
50
- await this.saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
83
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
51
84
  while (true) {
52
85
  if (Date.now() - startedAt > turn.budget.maxWallClockMs) {
53
- return this.stop(turn, "timeout", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
86
+ return stop("timeout", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
54
87
  }
55
88
  if (modelTurns >= turn.budget.maxModelTurns) {
56
- return this.stop(turn, "max_model_turns", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
89
+ if (!finalizationReserveUsed && this.shouldUseFinalizationReserve(turn, messages, toolResultSummaries, finalText)) {
90
+ finalizationReserveUsed = true;
91
+ forceFinalAnswerOnly = true;
92
+ messages.push({
93
+ role: "user",
94
+ content: this.buildFinalizationReservePrompt(turn),
95
+ });
96
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
97
+ }
98
+ else {
99
+ return stop("max_model_turns", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
100
+ }
57
101
  }
58
102
  if (toolCalls >= turn.budget.maxToolCalls) {
59
- return this.stop(turn, "max_tool_calls", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
103
+ return stop("max_tool_calls", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
60
104
  }
61
105
  if (turn.abortSignal?.aborted) {
62
- return this.stop(turn, "cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
106
+ return stop("cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
63
107
  }
64
- const tools = this.deps.toolRouter.modelVisibleTools(turn);
108
+ const tools = forceFinalAnswerOnly ? [] : this.deps.toolRouter.modelVisibleTools(turn);
65
109
  if (modelTurns === 0) {
66
110
  await this.record(turn, {
67
111
  type: "turn_context",
@@ -83,20 +127,22 @@ export class BoundedAgentLoopRunner {
83
127
  }
84
128
  catch (err) {
85
129
  if (turn.abortSignal?.aborted) {
86
- return this.stop(turn, "cancelled", startedAt, modelTurns, toolCalls, "Agent loop stopped: operator stop aborted active model work.", null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, err instanceof Error ? err.message : String(err));
130
+ return stop("cancelled", startedAt, modelTurns, toolCalls, "Agent loop stopped: operator stop aborted active model work.", null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, err instanceof Error ? err.message : String(err));
87
131
  }
88
132
  const failure = this.classifyRunFailure(err);
89
- return this.stop(turn, failure.reason, startedAt, modelTurns, toolCalls, failure.message, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, failure.detail);
133
+ return stop(failure.reason, startedAt, modelTurns, toolCalls, failure.message, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, failure.detail, failure.failureReason);
90
134
  }
91
135
  if (!protocol.responseCompleted) {
92
- return this.stop(turn, "protocol_incomplete", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
136
+ return stop("protocol_incomplete", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
93
137
  }
94
138
  if (turn.abortSignal?.aborted) {
95
- return this.stop(turn, "cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
139
+ return stop("cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
96
140
  }
97
141
  const response = this.protocolToResponse(protocol);
98
142
  modelTurns++;
99
143
  finalText = response.content;
144
+ const wasFinalAnswerOnly = forceFinalAnswerOnly;
145
+ forceFinalAnswerOnly = false;
100
146
  for (const assistant of protocol.assistant) {
101
147
  await this.record(turn, {
102
148
  type: "assistant_message",
@@ -111,20 +157,21 @@ export class BoundedAgentLoopRunner {
111
157
  if (response.content.trim().length === 0) {
112
158
  schemaRepairAttempts++;
113
159
  if (schemaRepairAttempts > turn.budget.maxSchemaRepairAttempts) {
114
- return this.stop(turn, "schema_error", startedAt, modelTurns, toolCalls, response.content, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
160
+ return stop("schema_error", startedAt, modelTurns, toolCalls, response.content, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
115
161
  }
116
162
  messages.push({ role: "assistant", content: response.content, phase: "final_answer" });
117
163
  messages.push({
118
164
  role: "user",
119
165
  content: "Your final answer was empty. Return a user-visible Markdown or plain text answer for the user.",
120
166
  });
121
- const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions);
167
+ const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions, compactionRecords);
122
168
  if (compacted.error) {
123
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
169
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
124
170
  }
125
171
  messages = compacted.messages;
172
+ compactionRecords = compacted.compactionRecords;
126
173
  compactions += compacted.compacted ? 1 : 0;
127
- await this.saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
174
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
128
175
  continue;
129
176
  }
130
177
  const missingRequiredTools = this.missingRequiredTools(turn, calledTools);
@@ -134,13 +181,14 @@ export class BoundedAgentLoopRunner {
134
181
  role: "user",
135
182
  content: `Before the final answer, call these required tool(s) at least once: ${missingRequiredTools.join(", ")}.`,
136
183
  });
137
- const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions);
184
+ const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions, compactionRecords);
138
185
  if (compacted.error) {
139
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
186
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
140
187
  }
141
188
  messages = compacted.messages;
189
+ compactionRecords = compacted.compactionRecords;
142
190
  compactions += compacted.compacted ? 1 : 0;
143
- await this.saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
191
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
144
192
  continue;
145
193
  }
146
194
  const changedFiles = await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot);
@@ -150,7 +198,7 @@ export class BoundedAgentLoopRunner {
150
198
  success: true,
151
199
  outputPreview: this.preview(response.content),
152
200
  });
153
- return this.stop(turn, "completed", startedAt, modelTurns, toolCalls, response.content, null, true, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
201
+ return stop("completed", startedAt, modelTurns, toolCalls, response.content, null, true, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
154
202
  }
155
203
  const parsed = this.parseFinal(response.content, turn.outputSchema);
156
204
  if (parsed.success) {
@@ -161,41 +209,45 @@ export class BoundedAgentLoopRunner {
161
209
  role: "user",
162
210
  content: `Before the final answer, call these required tool(s) at least once: ${missingRequiredTools.join(", ")}.`,
163
211
  });
164
- const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions);
212
+ const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions, compactionRecords);
165
213
  if (compacted.error) {
166
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
214
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
167
215
  }
168
216
  messages = compacted.messages;
217
+ compactionRecords = compacted.compactionRecords;
169
218
  compactions += compacted.compacted ? 1 : 0;
170
- await this.saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
219
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
171
220
  continue;
172
221
  }
173
222
  const changedFiles = await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot);
174
- const completionValidation = turn.completionValidator?.({
175
- output: parsed.output,
176
- changedFiles,
177
- commandResults,
178
- calledTools: [...calledTools],
179
- modelTurns,
180
- toolCalls,
181
- });
223
+ const completionValidation = turn.completionValidator
224
+ ? await turn.completionValidator({
225
+ output: parsed.output,
226
+ changedFiles,
227
+ commandResults,
228
+ calledTools: [...calledTools],
229
+ modelTurns,
230
+ toolCalls,
231
+ })
232
+ : undefined;
182
233
  if (completionValidation && !completionValidation.ok) {
183
234
  completionValidationAttempts++;
184
235
  if (completionValidationAttempts > turn.budget.maxCompletionValidationAttempts) {
185
- return this.stop(turn, "completion_gate_failed", startedAt, modelTurns, toolCalls, response.content, null, false, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
236
+ return stop("completion_gate_failed", startedAt, modelTurns, toolCalls, response.content, null, false, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
186
237
  }
187
238
  messages.push({ role: "assistant", content: response.content, phase: "final_answer" });
188
239
  messages.push({
189
240
  role: "user",
190
241
  content: this.buildCompletionRepairPrompt(completionValidation.reasons),
191
242
  });
192
- const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions);
243
+ const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions, compactionRecords);
193
244
  if (compacted.error) {
194
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
245
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
195
246
  }
196
247
  messages = compacted.messages;
248
+ compactionRecords = compacted.compactionRecords;
197
249
  compactions += compacted.compacted ? 1 : 0;
198
- await this.saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
250
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
199
251
  continue;
200
252
  }
201
253
  await this.record(turn, {
@@ -204,26 +256,35 @@ export class BoundedAgentLoopRunner {
204
256
  success: true,
205
257
  outputPreview: this.preview(response.content),
206
258
  });
207
- return this.stop(turn, "completed", startedAt, modelTurns, toolCalls, response.content, parsed.output, true, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
259
+ return stop("completed", startedAt, modelTurns, toolCalls, response.content, parsed.output, true, compactions, changedFiles, toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts);
208
260
  }
209
261
  schemaRepairAttempts++;
210
262
  if (schemaRepairAttempts > turn.budget.maxSchemaRepairAttempts) {
211
- return this.stop(turn, "schema_error", startedAt, modelTurns, toolCalls, response.content, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
263
+ return stop("schema_error", startedAt, modelTurns, toolCalls, response.content, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
212
264
  }
213
265
  messages.push({ role: "assistant", content: response.content, phase: "final_answer" });
214
266
  messages.push({
215
267
  role: "user",
216
268
  content: `Your final answer did not match the required JSON schema. Return only valid JSON. Parse error: ${parsed.error}`,
217
269
  });
218
- const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions);
270
+ const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions, compactionRecords);
219
271
  if (compacted.error) {
220
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
272
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
221
273
  }
222
274
  messages = compacted.messages;
275
+ compactionRecords = compacted.compactionRecords;
223
276
  compactions += compacted.compacted ? 1 : 0;
224
- await this.saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
277
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
225
278
  continue;
226
279
  }
280
+ if (wasFinalAnswerOnly) {
281
+ const detail = "Agent loop reached the finalization reserve, but the model attempted another tool call instead of returning final output.";
282
+ return stop("max_model_turns", startedAt, modelTurns, toolCalls, response.content || detail, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, detail, "max_model_turns");
283
+ }
284
+ const toolBatchBudgetRefusal = this.toolBatchBudgetRefusalReason(response.toolCalls, turn, startedAt);
285
+ if (toolBatchBudgetRefusal) {
286
+ return stop("timeout", startedAt, modelTurns, toolCalls, toolBatchBudgetRefusal, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, toolBatchBudgetRefusal, "tool_batch_deadline_exceeded");
287
+ }
227
288
  messages.push({
228
289
  role: "assistant",
229
290
  content: response.content || `Calling ${response.toolCalls.map((call) => call.name).join(", ")}`,
@@ -238,10 +299,10 @@ export class BoundedAgentLoopRunner {
238
299
  repeatedToolLoopCount = 1;
239
300
  }
240
301
  if (repeatedToolLoopCount > turn.budget.maxRepeatedToolCalls) {
241
- return this.stop(turn, "stalled_tool_loop", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
302
+ return stop("stalled_tool_loop", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, undefined, undefined, "repeated_tool_calls");
242
303
  }
243
304
  if (turn.abortSignal?.aborted) {
244
- return this.stop(turn, "cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
305
+ return stop("cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
245
306
  }
246
307
  for (const call of response.toolCalls) {
247
308
  const activityCategory = this.deps.toolRouter.resolveTool(call.name)?.metadata.activityCategory;
@@ -254,18 +315,40 @@ export class BoundedAgentLoopRunner {
254
315
  ...(activityCategory ? { activityCategory } : {}),
255
316
  });
256
317
  }
257
- const { results: toolResults, timedOut: toolBatchTimedOut } = await this.executeToolBatchWithinBudget(response.toolCalls, turn, startedAt);
318
+ let toolBatch;
319
+ try {
320
+ toolBatch = await this.executeToolBatchWithinBudget(response.toolCalls, turn, startedAt);
321
+ }
322
+ catch (err) {
323
+ const detail = this.errorDetail(err);
324
+ const message = `Agent loop stopped: tool runtime failed. ${detail ? `Detail: ${detail}. ` : ""}Inspect the tool execution trace.`;
325
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, message, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, detail, "tool_runtime_failure");
326
+ }
327
+ const { results: toolResults, timedOut: toolBatchTimedOut } = toolBatch;
328
+ if (toolBatchTimedOut && toolResults.length === 0) {
329
+ const timeoutReason = this.formatToolBatchWallClockExhaustedReason(response.toolCalls, turn.budget.maxWallClockMs);
330
+ return stop("timeout", startedAt, modelTurns, toolCalls, timeoutReason, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, timeoutReason, "tool_batch_timed_out");
331
+ }
258
332
  for (const result of toolResults) {
259
- calledTools.add(result.toolName);
333
+ const sourceCall = response.toolCalls.find((call) => call.id === result.callId);
334
+ const observation = this.createToolObservation(result, sourceCall, toolBatchTimedOut);
335
+ if (result.execution?.status !== "not_executed") {
336
+ calledTools.add(result.toolName);
337
+ }
260
338
  toolCalls++;
339
+ const toolResultSequence = toolCalls;
261
340
  if (result.success)
262
341
  consecutiveToolErrors = 0;
263
342
  else
264
343
  consecutiveToolErrors++;
344
+ const checkOnly = readToolResultCheckOnly(result);
265
345
  toolResultSummaries.push({
346
+ sequence: toolResultSequence,
266
347
  toolName: result.toolName,
267
348
  success: result.success,
268
349
  ...(result.execution ? { execution: result.execution } : {}),
350
+ ...(result.artifacts ? { artifacts: result.artifacts } : {}),
351
+ ...(checkOnly !== undefined ? { checkOnly } : {}),
269
352
  outputSummary: this.preview(result.content),
270
353
  durationMs: result.durationMs,
271
354
  });
@@ -274,6 +357,7 @@ export class BoundedAgentLoopRunner {
274
357
  toolCallId: result.callId,
275
358
  toolName: result.toolName,
276
359
  content: result.content,
360
+ observation,
277
361
  });
278
362
  await this.record(turn, {
279
363
  type: "tool_call_finished",
@@ -289,6 +373,11 @@ export class BoundedAgentLoopRunner {
289
373
  ...(result.truncated ? { truncated: result.truncated } : {}),
290
374
  ...(result.activityCategory ? { activityCategory: result.activityCategory } : {}),
291
375
  });
376
+ await this.record(turn, {
377
+ type: "tool_observation",
378
+ ...this.baseEvent(turn),
379
+ observation,
380
+ });
292
381
  if (result.disposition === "approval_denied") {
293
382
  await this.record(turn, {
294
383
  type: "approval",
@@ -309,38 +398,64 @@ export class BoundedAgentLoopRunner {
309
398
  const commandClassification = classifyAgentLoopCommandResult({
310
399
  toolName: result.toolName,
311
400
  command: result.command,
401
+ activityCategory: result.activityCategory,
402
+ verificationPlan: turn.verificationPlan,
312
403
  });
313
404
  commandResults.push({
405
+ sequence: toolResultSequence,
314
406
  toolName: result.toolName,
315
407
  command: result.command,
316
408
  cwd: result.cwd,
317
409
  success: result.success,
318
410
  ...(result.execution ? { execution: result.execution } : {}),
411
+ ...(result.activityCategory ? { activityCategory: result.activityCategory } : {}),
319
412
  category: commandClassification.category,
320
413
  evidenceEligible: commandClassification.evidenceEligible,
414
+ ...(commandClassification.evidenceSource ? { evidenceSource: commandClassification.evidenceSource } : {}),
321
415
  outputSummary: this.preview(result.content),
322
416
  durationMs: result.durationMs,
323
417
  });
324
418
  }
325
419
  if (result.disposition === "fatal" || result.fatal) {
326
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
420
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, undefined, undefined, "tool_fatal");
327
421
  }
328
422
  if (result.disposition === "cancelled") {
329
- return this.stop(turn, toolBatchTimedOut ? "timeout" : "cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
423
+ return stop(toolBatchTimedOut ? "timeout" : "cancelled", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, undefined, undefined, toolBatchTimedOut ? "tool_batch_timed_out" : "tool_cancelled");
330
424
  }
331
425
  if (consecutiveToolErrors >= turn.budget.maxConsecutiveToolErrors) {
332
- return this.stop(turn, "consecutive_tool_errors", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
426
+ return stop("consecutive_tool_errors", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, undefined, undefined, "consecutive_tool_errors");
333
427
  }
334
428
  }
335
- const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions);
429
+ const compacted = await this.compactIfNeeded(turn, messages, "mid_turn", "context_limit", this.responseUsageTokens(protocol), compactions, compactionRecords);
336
430
  if (compacted.error) {
337
- return this.stop(turn, "fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
431
+ return stop("fatal_error", startedAt, modelTurns, toolCalls, finalText, null, false, compactions, await this.collectChangedFiles(turn.cwd, initialWorkspaceSnapshot), toolResultSummaries, commandResults, messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount);
338
432
  }
339
433
  messages = compacted.messages;
434
+ compactionRecords = compacted.compactionRecords;
340
435
  compactions += compacted.compacted ? 1 : 0;
341
- await this.saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
436
+ await this.saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, "running");
342
437
  }
343
438
  }
439
+ shouldUseFinalizationReserve(turn, messages, toolResults, finalText) {
440
+ if (turn.finalOutputMode === "display_text")
441
+ return false;
442
+ if (toolResults.length === 0 && !messages.some((message) => message.role === "tool"))
443
+ return false;
444
+ const trimmed = finalText.trim();
445
+ return trimmed.length === 0 || trimmed.startsWith("Calling ");
446
+ }
447
+ buildFinalizationReservePrompt(turn) {
448
+ const requiredTools = turn.toolPolicy.requiredTools?.length
449
+ ? `Required tools already visible for this turn: ${turn.toolPolicy.requiredTools.join(", ")}.`
450
+ : "";
451
+ return [
452
+ "You have reached the tool/model turn budget. Do not call any more tools.",
453
+ "Return the final output now as JSON matching the required schema.",
454
+ "Use status=done only if the completed work and verification evidence satisfy the task; otherwise use partial or failed with blockers.",
455
+ "Include concrete completionEvidence and filesChanged from the work already performed.",
456
+ requiredTools,
457
+ ].filter(Boolean).join("\n");
458
+ }
344
459
  parseFinal(content, schema) {
345
460
  try {
346
461
  const json = this.extractJson(content);
@@ -354,12 +469,14 @@ export class BoundedAgentLoopRunner {
354
469
  const fence = content.match(/```json\s*([\s\S]*?)\s*```/);
355
470
  return fence?.[1] ?? content;
356
471
  }
357
- async stop(turn, reason, startedAt, modelTurns, toolCalls, finalText, output, success = false, compactions = 0, changedFiles = [], toolResults = [], commandResults = [], messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, reasonDetail) {
358
- await this.saveState(turn, messages ?? turn.messages, modelTurns, toolCalls, compactions, completionValidationAttempts ?? 0, calledTools ?? new Set(), lastToolLoopSignature ?? null, repeatedToolLoopCount ?? 0, finalText, success ? "completed" : "failed", reason, reasonDetail);
472
+ async stop(turn, reason, startedAt, modelTurns, toolCalls, finalText, output, success = false, compactions = 0, changedFiles = [], toolResults = [], commandResults = [], messages, calledTools, lastToolLoopSignature, repeatedToolLoopCount, completionValidationAttempts, reasonDetail, failureReason, compactionRecords = []) {
473
+ const resolvedFailureReason = success ? undefined : failureReason ?? this.defaultFailureReason(reason);
474
+ await this.saveState(turn, messages ?? turn.messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts ?? 0, calledTools ?? new Set(), lastToolLoopSignature ?? null, repeatedToolLoopCount ?? 0, finalText, success ? "completed" : "failed", reason, reasonDetail, resolvedFailureReason);
359
475
  await this.record(turn, {
360
476
  type: "stopped",
361
477
  ...this.baseEvent(turn),
362
478
  reason,
479
+ ...(resolvedFailureReason ? { failureReason: resolvedFailureReason } : {}),
363
480
  ...(reasonDetail ? { reasonDetail } : {}),
364
481
  });
365
482
  return {
@@ -367,6 +484,8 @@ export class BoundedAgentLoopRunner {
367
484
  output,
368
485
  finalText,
369
486
  stopReason: reason,
487
+ ...(resolvedFailureReason ? { failureReason: resolvedFailureReason } : {}),
488
+ ...(reasonDetail ? { failureDetail: reasonDetail } : {}),
370
489
  elapsedMs: Date.now() - startedAt,
371
490
  modelTurns,
372
491
  toolCalls,
@@ -378,6 +497,9 @@ export class BoundedAgentLoopRunner {
378
497
  traceId: turn.session.traceId,
379
498
  sessionId: turn.session.sessionId,
380
499
  turnId: turn.turnId,
500
+ ...(turn.profileName ? { profileName: turn.profileName } : {}),
501
+ ...(turn.reasoningEffort ? { reasoningEffort: turn.reasoningEffort } : {}),
502
+ ...(turn.executionPolicy ? { executionPolicy: turn.executionPolicy } : {}),
381
503
  };
382
504
  }
383
505
  buildCompletionRepairPrompt(reasons) {
@@ -419,47 +541,101 @@ export class BoundedAgentLoopRunner {
419
541
  return String(value);
420
542
  }
421
543
  }
544
+ defaultFailureReason(reason) {
545
+ switch (reason) {
546
+ case "timeout":
547
+ return "wall_clock_timeout";
548
+ case "max_model_turns":
549
+ return "max_model_turns";
550
+ case "max_tool_calls":
551
+ return "max_tool_calls";
552
+ case "consecutive_tool_errors":
553
+ return "consecutive_tool_errors";
554
+ case "stalled_tool_loop":
555
+ return "repeated_tool_calls";
556
+ case "schema_error":
557
+ return "schema_validation_failed";
558
+ case "cancelled":
559
+ return "operator_cancelled";
560
+ case "protocol_incomplete":
561
+ return "protocol_incomplete";
562
+ case "completion_gate_failed":
563
+ return "completion_gate_failed";
564
+ case "fatal_error":
565
+ default:
566
+ return "provider_failure";
567
+ }
568
+ }
422
569
  classifyRunFailure(error) {
423
- const detail = error instanceof Error
424
- ? [error.name !== "Error" ? error.name : null, error.message]
425
- .filter((part) => typeof part === "string" && part.length > 0)
426
- .join(": ")
427
- : String(error);
428
- const lowered = detail.toLowerCase();
429
- if (lowered.includes("timeout")
430
- || lowered.includes("timed out")
431
- || lowered.includes("aborterror")
432
- || lowered.includes("aborted")) {
570
+ const detail = this.errorDetail(error);
571
+ const structured = this.structuredRunFailureReason(error);
572
+ if (structured === "model_request_timeout") {
433
573
  return {
434
574
  reason: "timeout",
575
+ failureReason: "model_request_timeout",
435
576
  detail,
436
577
  message: "Agent loop stopped: model request timed out. Narrow broad repo-wide searches or increase `codex_timeout_ms` if this workload is expected.",
437
578
  };
438
579
  }
580
+ if (structured === "model_request_aborted") {
581
+ return {
582
+ reason: "fatal_error",
583
+ failureReason: "model_request_aborted",
584
+ detail,
585
+ message: "Agent loop stopped: model request was aborted by the provider or transport. Retry the turn or inspect the provider connection.",
586
+ };
587
+ }
439
588
  return {
440
589
  reason: "fatal_error",
590
+ failureReason: "provider_failure",
441
591
  detail,
442
592
  message: `Agent loop stopped: model request failed. ${detail ? `Detail: ${detail}. ` : ""}Retry the turn or inspect the provider connection.`,
443
593
  };
444
594
  }
445
- async compactIfNeeded(turn, messages, phase, reason, usageTokens, compactions) {
595
+ structuredRunFailureReason(error) {
596
+ if (!error || typeof error !== "object")
597
+ return null;
598
+ const value = error;
599
+ if (value.agentLoopFailureReason === "model_request_timeout" || value.agentLoopFailureReason === "model_request_aborted") {
600
+ return value.agentLoopFailureReason;
601
+ }
602
+ if (value.name === "TimeoutError" || value.code === "ETIMEDOUT" || value.code === "UND_ERR_HEADERS_TIMEOUT" || value.code === "UND_ERR_BODY_TIMEOUT") {
603
+ return "model_request_timeout";
604
+ }
605
+ if (value.name === "AbortError" || value.code === "ABORT_ERR") {
606
+ return "model_request_aborted";
607
+ }
608
+ return this.structuredRunFailureReason(value.cause);
609
+ }
610
+ errorDetail(error) {
611
+ return error instanceof Error
612
+ ? [error.name !== "Error" ? error.name : null, error.message]
613
+ .filter((part) => typeof part === "string" && part.length > 0)
614
+ .join(": ")
615
+ : String(error);
616
+ }
617
+ async compactIfNeeded(turn, messages, phase, reason, usageTokens, compactions, compactionRecords) {
446
618
  const limit = this.autoCompactLimit(turn);
447
619
  if (!limit || compactions >= turn.budget.maxCompactions) {
448
- return { messages, compacted: false };
620
+ return { messages, compactionRecords: cloneAgentLoopCompactionRecords(compactionRecords), compacted: false };
449
621
  }
450
622
  const tokens = usageTokens && usageTokens > 0 ? usageTokens : this.estimateTokens(messages);
451
623
  if (tokens < limit) {
452
- return { messages, compacted: false };
624
+ return { messages, compactionRecords: cloneAgentLoopCompactionRecords(compactionRecords), compacted: false };
453
625
  }
454
626
  try {
455
627
  const result = await this.compactor.compact({
456
- history: createAgentLoopHistory(messages),
628
+ history: createAgentLoopHistory(messages, compactionRecords),
457
629
  maxMessages: turn.budget.compactionMaxMessages,
458
630
  phase,
459
631
  reason,
460
632
  });
461
633
  if (!result.compacted) {
462
- return { messages: result.history.messages, compacted: false };
634
+ return {
635
+ messages: result.history.messages,
636
+ compactionRecords: cloneAgentLoopCompactionRecords(result.history.compactionRecords),
637
+ compacted: false,
638
+ };
463
639
  }
464
640
  await this.record(turn, {
465
641
  type: "context_compaction",
@@ -470,10 +646,19 @@ export class BoundedAgentLoopRunner {
470
646
  outputMessages: result.history.messages.length,
471
647
  summaryPreview: this.preview(result.summary ?? ""),
472
648
  });
473
- return { messages: result.history.messages, compacted: true };
649
+ return {
650
+ messages: result.history.messages,
651
+ compactionRecords: cloneAgentLoopCompactionRecords(result.history.compactionRecords),
652
+ compacted: true,
653
+ };
474
654
  }
475
655
  catch (err) {
476
- return { messages, compacted: false, error: err instanceof Error ? err.message : String(err) };
656
+ return {
657
+ messages,
658
+ compactionRecords: cloneAgentLoopCompactionRecords(compactionRecords),
659
+ compacted: false,
660
+ error: err instanceof Error ? err.message : String(err),
661
+ };
477
662
  }
478
663
  }
479
664
  autoCompactLimit(turn) {
@@ -484,7 +669,10 @@ export class BoundedAgentLoopRunner {
484
669
  return contextLimit && contextLimit > 0 ? Math.floor(contextLimit * 0.9) : undefined;
485
670
  }
486
671
  async executeToolBatchWithinBudget(calls, turn, startedAt) {
487
- const remainingMs = Math.max(1, turn.budget.maxWallClockMs - (Date.now() - startedAt));
672
+ const remainingMs = turn.budget.maxWallClockMs - (Date.now() - startedAt);
673
+ if (remainingMs <= 0) {
674
+ return { results: [], timedOut: true };
675
+ }
488
676
  const controller = new AbortController();
489
677
  const parentSignal = turn.abortSignal;
490
678
  let timedOut = false;
@@ -517,6 +705,34 @@ export class BoundedAgentLoopRunner {
517
705
  parentSignal?.removeEventListener("abort", abortFromParent);
518
706
  }
519
707
  }
708
+ toolBatchBudgetRefusalReason(calls, turn, startedAt) {
709
+ const remainingMs = turn.budget.maxWallClockMs - (Date.now() - startedAt);
710
+ if (remainingMs <= 0) {
711
+ return this.formatToolBatchWallClockExhaustedReason(calls, turn.budget.maxWallClockMs);
712
+ }
713
+ const mutatingToolNames = calls
714
+ .filter((call) => this.isMutatingToolCall(call))
715
+ .map((call) => call.name);
716
+ if (mutatingToolNames.length === 0 || remainingMs >= MIN_MUTATING_TOOL_BATCH_REMAINING_MS) {
717
+ return null;
718
+ }
719
+ return [
720
+ "Tool batch was not started because the remaining wall-clock budget",
721
+ `(${Math.floor(remainingMs)}ms) is below the ${MIN_MUTATING_TOOL_BATCH_REMAINING_MS}ms minimum`,
722
+ `for mutating tools: ${[...new Set(mutatingToolNames)].join(", ")}.`,
723
+ ].join(" ");
724
+ }
725
+ formatToolBatchWallClockExhaustedReason(calls, maxWallClockMs) {
726
+ return [
727
+ "Tool batch was not started because the agent loop wall-clock budget is exhausted",
728
+ `(0ms remaining; limit ${maxWallClockMs}ms).`,
729
+ `Requested tools: ${calls.map((call) => call.name).join(", ")}.`,
730
+ ].join(" ");
731
+ }
732
+ isMutatingToolCall(call) {
733
+ const metadata = this.deps.toolRouter.resolveTool(call.name)?.metadata;
734
+ return metadata?.isReadOnly !== true;
735
+ }
520
736
  responseUsageTokens(response) {
521
737
  if (!response.usage)
522
738
  return undefined;
@@ -529,6 +745,56 @@ export class BoundedAgentLoopRunner {
529
745
  missingRequiredTools(turn, calledTools) {
530
746
  return [...(turn.toolPolicy.requiredTools ?? [])].filter((toolName) => !calledTools.has(toolName));
531
747
  }
748
+ createToolObservation(result, sourceCall, toolBatchTimedOut) {
749
+ const state = this.toolObservationState(result, toolBatchTimedOut);
750
+ const execution = this.toolObservationExecution(result, state);
751
+ const rawResult = result.rawResult;
752
+ return {
753
+ type: "tool_observation",
754
+ callId: result.callId,
755
+ toolName: result.toolName,
756
+ arguments: sourceCall?.input ?? {},
757
+ state,
758
+ success: result.success,
759
+ execution,
760
+ durationMs: result.durationMs,
761
+ output: {
762
+ content: result.content,
763
+ ...(rawResult?.summary ? { summary: rawResult.summary } : {}),
764
+ ...(rawResult && Object.prototype.hasOwnProperty.call(rawResult, "data") ? { data: rawResult.data } : {}),
765
+ ...(rawResult?.error ? { error: rawResult.error } : {}),
766
+ },
767
+ ...(result.command ? { command: result.command } : {}),
768
+ ...(result.cwd ? { cwd: result.cwd } : {}),
769
+ ...(result.artifacts ? { artifacts: result.artifacts } : {}),
770
+ ...(result.truncated ? { truncated: result.truncated } : {}),
771
+ ...(result.activityCategory ? { activityCategory: result.activityCategory } : {}),
772
+ };
773
+ }
774
+ toolObservationState(result, toolBatchTimedOut) {
775
+ const reason = result.execution?.reason;
776
+ if (reason === "timed_out" || (toolBatchTimedOut && result.disposition === "cancelled"))
777
+ return "timed_out";
778
+ if (reason === "interrupted" || result.disposition === "cancelled")
779
+ return "interrupted";
780
+ if (reason === "approval_denied" || reason === "permission_denied")
781
+ return "denied";
782
+ if (reason === "policy_blocked" || reason === "dry_run")
783
+ return "blocked";
784
+ return result.success ? "success" : "failure";
785
+ }
786
+ toolObservationExecution(result, state) {
787
+ if (result.execution)
788
+ return result.execution;
789
+ if (state === "timed_out" || state === "interrupted") {
790
+ return {
791
+ status: "executed",
792
+ reason: state === "timed_out" ? "timed_out" : "interrupted",
793
+ message: result.content,
794
+ };
795
+ }
796
+ return { status: "executed" };
797
+ }
532
798
  async createTurnProtocol(turn, messages, tools) {
533
799
  if (this.deps.modelClient.createTurnProtocol) {
534
800
  return this.deps.modelClient.createTurnProtocol({
@@ -550,18 +816,36 @@ export class BoundedAgentLoopRunner {
550
816
  phase: response.toolCalls.length > 0 ? "commentary" : "final_answer",
551
817
  }] : [],
552
818
  toolCalls: response.toolCalls,
819
+ responseItems: [
820
+ ...(response.content || response.toolCalls.length > 0
821
+ ? [assistantTextResponseItem(response.content || `Calling ${response.toolCalls.map((call) => call.name).join(", ")}`, response.toolCalls.length > 0 ? "commentary" : "final_answer")]
822
+ : []),
823
+ ...response.toolCalls.map((call) => functionToolCallResponseItem(call)),
824
+ ],
553
825
  stopReason: response.stopReason,
554
826
  responseCompleted: true,
555
827
  usage: response.usage,
556
828
  };
557
829
  }
558
830
  protocolToResponse(protocol) {
831
+ const responseItemText = protocol.responseItems
832
+ ?.filter((item) => item.type === "assistant_text")
833
+ .map((item) => item.content)
834
+ .filter(Boolean)
835
+ .join("\n");
836
+ const responseItemToolCalls = protocol.responseItems
837
+ ?.filter((item) => item.type === "function_tool_call")
838
+ .map((item) => ({
839
+ id: item.id,
840
+ name: item.name,
841
+ input: item.arguments,
842
+ }));
559
843
  return {
560
- content: protocol.assistant.map((item) => item.content).filter(Boolean).join("\n"),
561
- toolCalls: protocol.toolCalls,
844
+ content: protocol.assistant.map((item) => item.content).filter(Boolean).join("\n") || responseItemText || "",
845
+ toolCalls: protocol.responseItems ? responseItemToolCalls ?? [] : protocol.toolCalls,
562
846
  };
563
847
  }
564
- async saveState(turn, messages, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, status, stopReason, stopDetail) {
848
+ async saveState(turn, messages, compactionRecords, modelTurns, toolCalls, compactions, completionValidationAttempts, calledTools, lastToolLoopSignature, repeatedToolLoopCount, finalText, status, stopReason, stopDetail, failureReason) {
565
849
  const state = {
566
850
  sessionId: turn.session.sessionId,
567
851
  traceId: turn.session.traceId,
@@ -571,6 +855,7 @@ export class BoundedAgentLoopRunner {
571
855
  cwd: turn.cwd,
572
856
  modelRef: formatAgentLoopModelRef(turn.model),
573
857
  messages,
858
+ compactionRecords: cloneAgentLoopCompactionRecords(compactionRecords),
574
859
  modelTurns,
575
860
  toolCalls,
576
861
  compactions,
@@ -581,6 +866,7 @@ export class BoundedAgentLoopRunner {
581
866
  finalText,
582
867
  status,
583
868
  ...(stopReason ? { stopReason } : {}),
869
+ ...(failureReason ? { failureReason } : {}),
584
870
  ...(stopDetail ? { stopDetail } : {}),
585
871
  updatedAt: new Date().toISOString(),
586
872
  };
@@ -588,18 +874,22 @@ export class BoundedAgentLoopRunner {
588
874
  }
589
875
  async captureWorkspaceSnapshot(cwd) {
590
876
  const result = await execFileNoThrow("git", ["status", "--porcelain", "--untracked-files=all"], { cwd, timeoutMs: 10_000 });
591
- if ((result.exitCode ?? 1) !== 0)
592
- return null;
593
- return new Set(this.parseGitStatusPaths(result.stdout));
877
+ if ((result.exitCode ?? 1) === 0) {
878
+ return { kind: "git", paths: new Set(this.parseGitStatusPaths(result.stdout)) };
879
+ }
880
+ return { kind: "filesystem", files: await this.captureFilesystemSnapshot(cwd) };
594
881
  }
595
882
  async collectChangedFiles(cwd, before) {
596
883
  const afterResult = await execFileNoThrow("git", ["status", "--porcelain", "--untracked-files=all"], { cwd, timeoutMs: 10_000 });
597
- if ((afterResult.exitCode ?? 1) !== 0)
598
- return [];
884
+ if ((afterResult.exitCode ?? 1) !== 0) {
885
+ if (before?.kind !== "filesystem")
886
+ return [];
887
+ return this.collectFilesystemChangedPaths(before.files, await this.captureFilesystemSnapshot(cwd));
888
+ }
599
889
  const after = new Set(this.parseGitStatusPaths(afterResult.stdout));
600
- if (!before)
890
+ if (!before || before.kind !== "git")
601
891
  return [...after];
602
- return [...after].filter((file) => !before.has(file));
892
+ return [...after].filter((file) => !before.paths.has(file));
603
893
  }
604
894
  parseGitStatusPaths(stdout) {
605
895
  return stdout
@@ -609,5 +899,74 @@ export class BoundedAgentLoopRunner {
609
899
  .map((line) => line.slice(3).trim())
610
900
  .map((filePath) => filePath.includes(" -> ") ? filePath.split(" -> ").at(-1) ?? filePath : filePath);
611
901
  }
902
+ async captureFilesystemSnapshot(cwd) {
903
+ const files = new Map();
904
+ const root = path.resolve(cwd);
905
+ const visit = async (dir) => {
906
+ if (files.size >= FILESYSTEM_SNAPSHOT_MAX_FILES)
907
+ return;
908
+ let entries;
909
+ try {
910
+ entries = await fsp.readdir(dir, { withFileTypes: true });
911
+ }
912
+ catch {
913
+ return;
914
+ }
915
+ for (const entry of entries) {
916
+ if (files.size >= FILESYSTEM_SNAPSHOT_MAX_FILES)
917
+ return;
918
+ if (entry.name.startsWith(".pulseed-"))
919
+ continue;
920
+ const absolutePath = path.join(dir, entry.name);
921
+ if (entry.isDirectory()) {
922
+ if (!FILESYSTEM_SNAPSHOT_EXCLUDED_DIRS.has(entry.name)) {
923
+ await visit(absolutePath);
924
+ }
925
+ continue;
926
+ }
927
+ if (!entry.isFile())
928
+ continue;
929
+ const relativePath = path.relative(root, absolutePath).replace(/\\/g, "/");
930
+ try {
931
+ const stat = await fsp.stat(absolutePath);
932
+ const snapshotEntry = {
933
+ size: stat.size,
934
+ mtimeMs: stat.mtimeMs,
935
+ };
936
+ if (stat.size <= FILESYSTEM_SNAPSHOT_HASH_MAX_BYTES) {
937
+ snapshotEntry.hash = createHash("sha256")
938
+ .update(await fsp.readFile(absolutePath))
939
+ .digest("hex");
940
+ }
941
+ files.set(relativePath, snapshotEntry);
942
+ }
943
+ catch {
944
+ // File may have changed while scanning; skip and let the next scan observe it.
945
+ }
946
+ }
947
+ };
948
+ await visit(root);
949
+ return files;
950
+ }
951
+ collectFilesystemChangedPaths(before, after) {
952
+ const changed = new Set();
953
+ for (const [filePath, afterEntry] of after) {
954
+ const beforeEntry = before.get(filePath);
955
+ if (!beforeEntry || !this.sameFilesystemEntry(beforeEntry, afterEntry)) {
956
+ changed.add(filePath);
957
+ }
958
+ }
959
+ for (const filePath of before.keys()) {
960
+ if (!after.has(filePath)) {
961
+ changed.add(filePath);
962
+ }
963
+ }
964
+ return [...changed].sort();
965
+ }
966
+ sameFilesystemEntry(left, right) {
967
+ if (left.hash && right.hash)
968
+ return left.hash === right.hash;
969
+ return left.size === right.size && left.mtimeMs === right.mtimeMs;
970
+ }
612
971
  }
613
972
  //# sourceMappingURL=bounded-agent-loop-runner.js.map