pulseed 0.6.2 → 0.6.4

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