operon-agents-core 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (511) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +7 -0
  3. package/dist/agent/agent.d.ts +65 -0
  4. package/dist/agent/agent.js +39 -0
  5. package/dist/agent/compose-hooks.d.ts +13 -0
  6. package/dist/agent/compose-hooks.js +197 -0
  7. package/dist/agent/concurrency.d.ts +22 -0
  8. package/dist/agent/concurrency.js +70 -0
  9. package/dist/agent/context-report.d.ts +60 -0
  10. package/dist/agent/context-report.js +45 -0
  11. package/dist/agent/graph.d.ts +48 -0
  12. package/dist/agent/graph.js +129 -0
  13. package/dist/agent/guardrail.d.ts +105 -0
  14. package/dist/agent/guardrail.js +314 -0
  15. package/dist/agent/handoff-executor.d.ts +21 -0
  16. package/dist/agent/handoff-executor.js +95 -0
  17. package/dist/agent/handoff.d.ts +42 -0
  18. package/dist/agent/handoff.js +70 -0
  19. package/dist/agent/index.d.ts +25 -0
  20. package/dist/agent/index.js +19 -0
  21. package/dist/agent/instruction-context.d.ts +33 -0
  22. package/dist/agent/instruction-context.js +100 -0
  23. package/dist/agent/pause.d.ts +12 -0
  24. package/dist/agent/pause.js +82 -0
  25. package/dist/agent/profile-builtins.d.ts +8 -0
  26. package/dist/agent/profile-builtins.js +130 -0
  27. package/dist/agent/profiles.d.ts +94 -0
  28. package/dist/agent/profiles.js +264 -0
  29. package/dist/agent/recovery.d.ts +10 -0
  30. package/dist/agent/recovery.js +151 -0
  31. package/dist/agent/run-support.d.ts +79 -0
  32. package/dist/agent/run-support.js +211 -0
  33. package/dist/agent/runner.d.ts +246 -0
  34. package/dist/agent/runner.js +786 -0
  35. package/dist/agent/session.d.ts +363 -0
  36. package/dist/agent/session.js +937 -0
  37. package/dist/agent/subagent-tools.d.ts +18 -0
  38. package/dist/agent/subagent-tools.js +650 -0
  39. package/dist/agent/subagent.d.ts +56 -0
  40. package/dist/agent/subagent.js +50 -0
  41. package/dist/agent/toolset.d.ts +24 -0
  42. package/dist/agent/toolset.js +112 -0
  43. package/dist/agent/workflow/index.d.ts +9 -0
  44. package/dist/agent/workflow/index.js +8 -0
  45. package/dist/agent/workflow/journal.d.ts +180 -0
  46. package/dist/agent/workflow/journal.js +224 -0
  47. package/dist/agent/workflow/manager.d.ts +27 -0
  48. package/dist/agent/workflow/manager.js +33 -0
  49. package/dist/agent/workflow/parse.d.ts +17 -0
  50. package/dist/agent/workflow/parse.js +174 -0
  51. package/dist/agent/workflow/prompt.d.ts +8 -0
  52. package/dist/agent/workflow/prompt.js +84 -0
  53. package/dist/agent/workflow/runtime.d.ts +64 -0
  54. package/dist/agent/workflow/runtime.js +380 -0
  55. package/dist/agent/workflow/sandbox.d.ts +35 -0
  56. package/dist/agent/workflow/sandbox.js +90 -0
  57. package/dist/agent/workflow/snapshot.d.ts +36 -0
  58. package/dist/agent/workflow/snapshot.js +9 -0
  59. package/dist/agent/workflow/structured.d.ts +35 -0
  60. package/dist/agent/workflow/structured.js +79 -0
  61. package/dist/agent/workflow/tool.d.ts +14 -0
  62. package/dist/agent/workflow/tool.js +569 -0
  63. package/dist/agent/workflow/types.d.ts +100 -0
  64. package/dist/agent/workflow/types.js +17 -0
  65. package/dist/agent/worktree.d.ts +38 -0
  66. package/dist/agent/worktree.js +56 -0
  67. package/dist/capabilities/assembler.d.ts +39 -0
  68. package/dist/capabilities/assembler.js +171 -0
  69. package/dist/capabilities/background/agent-task.d.ts +51 -0
  70. package/dist/capabilities/background/agent-task.js +101 -0
  71. package/dist/capabilities/background/command-task.d.ts +43 -0
  72. package/dist/capabilities/background/command-task.js +86 -0
  73. package/dist/capabilities/background/index.d.ts +20 -0
  74. package/dist/capabilities/background/index.js +57 -0
  75. package/dist/capabilities/background/manager.d.ts +194 -0
  76. package/dist/capabilities/background/manager.js +1131 -0
  77. package/dist/capabilities/background/persist-disk.d.ts +17 -0
  78. package/dist/capabilities/background/persist-disk.js +66 -0
  79. package/dist/capabilities/background/persist.d.ts +61 -0
  80. package/dist/capabilities/background/persist.js +117 -0
  81. package/dist/capabilities/background/question-task.d.ts +32 -0
  82. package/dist/capabilities/background/question-task.js +56 -0
  83. package/dist/capabilities/background/registrar.d.ts +12 -0
  84. package/dist/capabilities/background/registrar.js +9 -0
  85. package/dist/capabilities/background/swappable-sink.d.ts +20 -0
  86. package/dist/capabilities/background/swappable-sink.js +20 -0
  87. package/dist/capabilities/background/task.d.ts +114 -0
  88. package/dist/capabilities/background/task.js +20 -0
  89. package/dist/capabilities/background/tools.d.ts +6 -0
  90. package/dist/capabilities/background/tools.js +190 -0
  91. package/dist/capabilities/background/workflow-task.d.ts +48 -0
  92. package/dist/capabilities/background/workflow-task.js +91 -0
  93. package/dist/capabilities/capability-state.d.ts +13 -0
  94. package/dist/capabilities/capability-state.js +37 -0
  95. package/dist/capabilities/capability.d.ts +145 -0
  96. package/dist/capabilities/capability.js +2 -0
  97. package/dist/capabilities/compaction/full.d.ts +27 -0
  98. package/dist/capabilities/compaction/full.js +155 -0
  99. package/dist/capabilities/compaction/index.d.ts +17 -0
  100. package/dist/capabilities/compaction/index.js +145 -0
  101. package/dist/capabilities/compaction/instruction.d.ts +2 -0
  102. package/dist/capabilities/compaction/instruction.js +31 -0
  103. package/dist/capabilities/compaction/micro.d.ts +17 -0
  104. package/dist/capabilities/compaction/micro.js +57 -0
  105. package/dist/capabilities/compaction/service.d.ts +28 -0
  106. package/dist/capabilities/compaction/service.js +52 -0
  107. package/dist/capabilities/compaction/strategy.d.ts +43 -0
  108. package/dist/capabilities/compaction/strategy.js +116 -0
  109. package/dist/capabilities/compaction/tokens.d.ts +5 -0
  110. package/dist/capabilities/compaction/tokens.js +28 -0
  111. package/dist/capabilities/goal/goal-store.d.ts +69 -0
  112. package/dist/capabilities/goal/goal-store.js +172 -0
  113. package/dist/capabilities/goal/index.d.ts +6 -0
  114. package/dist/capabilities/goal/index.js +31 -0
  115. package/dist/capabilities/goal/injector.d.ts +9 -0
  116. package/dist/capabilities/goal/injector.js +79 -0
  117. package/dist/capabilities/goal/tools.d.ts +6 -0
  118. package/dist/capabilities/goal/tools.js +86 -0
  119. package/dist/capabilities/index.d.ts +25 -0
  120. package/dist/capabilities/index.js +22 -0
  121. package/dist/capabilities/injection.d.ts +44 -0
  122. package/dist/capabilities/injection.js +112 -0
  123. package/dist/capabilities/plan/index.d.ts +6 -0
  124. package/dist/capabilities/plan/index.js +25 -0
  125. package/dist/capabilities/plan/injector.d.ts +13 -0
  126. package/dist/capabilities/plan/injector.js +83 -0
  127. package/dist/capabilities/plan/plan-mode.d.ts +38 -0
  128. package/dist/capabilities/plan/plan-mode.js +113 -0
  129. package/dist/capabilities/plan/policies.d.ts +6 -0
  130. package/dist/capabilities/plan/policies.js +89 -0
  131. package/dist/capabilities/plan/tools.d.ts +15 -0
  132. package/dist/capabilities/plan/tools.js +87 -0
  133. package/dist/capabilities/skills/flow-provider.d.ts +6 -0
  134. package/dist/capabilities/skills/flow-provider.js +50 -0
  135. package/dist/capabilities/skills/index.d.ts +43 -0
  136. package/dist/capabilities/skills/index.js +48 -0
  137. package/dist/capabilities/skills/injector.d.ts +11 -0
  138. package/dist/capabilities/skills/injector.js +27 -0
  139. package/dist/capabilities/skills/parser.d.ts +36 -0
  140. package/dist/capabilities/skills/parser.js +334 -0
  141. package/dist/capabilities/skills/registry.d.ts +33 -0
  142. package/dist/capabilities/skills/registry.js +118 -0
  143. package/dist/capabilities/skills/scanner.d.ts +26 -0
  144. package/dist/capabilities/skills/scanner.js +154 -0
  145. package/dist/capabilities/skills/service.d.ts +39 -0
  146. package/dist/capabilities/skills/service.js +68 -0
  147. package/dist/capabilities/skills/skill-tool.d.ts +13 -0
  148. package/dist/capabilities/skills/skill-tool.js +72 -0
  149. package/dist/capabilities/skills/types.d.ts +62 -0
  150. package/dist/capabilities/skills/types.js +26 -0
  151. package/dist/capabilities/task/index.d.ts +23 -0
  152. package/dist/capabilities/task/index.js +38 -0
  153. package/dist/capabilities/task/injector.d.ts +9 -0
  154. package/dist/capabilities/task/injector.js +62 -0
  155. package/dist/capabilities/task/persist-disk.d.ts +19 -0
  156. package/dist/capabilities/task/persist-disk.js +84 -0
  157. package/dist/capabilities/task/persist.d.ts +52 -0
  158. package/dist/capabilities/task/persist.js +84 -0
  159. package/dist/capabilities/task/task-store.d.ts +44 -0
  160. package/dist/capabilities/task/task-store.js +106 -0
  161. package/dist/capabilities/task/tools.d.ts +12 -0
  162. package/dist/capabilities/task/tools.js +164 -0
  163. package/dist/capabilities/todo/index.d.ts +8 -0
  164. package/dist/capabilities/todo/index.js +21 -0
  165. package/dist/capabilities/todo/injector.d.ts +9 -0
  166. package/dist/capabilities/todo/injector.js +68 -0
  167. package/dist/capabilities/todo/todo-store.d.ts +19 -0
  168. package/dist/capabilities/todo/todo-store.js +36 -0
  169. package/dist/capabilities/todo/tools.d.ts +6 -0
  170. package/dist/capabilities/todo/tools.js +70 -0
  171. package/dist/capabilities/tool-provider.d.ts +12 -0
  172. package/dist/capabilities/tool-provider.js +20 -0
  173. package/dist/capabilities/user-hooks/engine.d.ts +22 -0
  174. package/dist/capabilities/user-hooks/engine.js +105 -0
  175. package/dist/capabilities/user-hooks/index.d.ts +13 -0
  176. package/dist/capabilities/user-hooks/index.js +126 -0
  177. package/dist/capabilities/user-hooks/types.d.ts +26 -0
  178. package/dist/capabilities/user-hooks/types.js +19 -0
  179. package/dist/capabilities/workflow/index.d.ts +16 -0
  180. package/dist/capabilities/workflow/index.js +15 -0
  181. package/dist/commands/index.d.ts +31 -0
  182. package/dist/commands/index.js +318 -0
  183. package/dist/config/config-store.d.ts +29 -0
  184. package/dist/config/config-store.js +103 -0
  185. package/dist/config/file-source.d.ts +40 -0
  186. package/dist/config/file-source.js +78 -0
  187. package/dist/config/flags.d.ts +13 -0
  188. package/dist/config/flags.js +25 -0
  189. package/dist/config/index.d.ts +17 -0
  190. package/dist/config/index.js +10 -0
  191. package/dist/config/merge.d.ts +5 -0
  192. package/dist/config/merge.js +57 -0
  193. package/dist/config/model-catalog.d.ts +17 -0
  194. package/dist/config/model-catalog.js +37 -0
  195. package/dist/config/paths.d.ts +31 -0
  196. package/dist/config/paths.js +28 -0
  197. package/dist/config/provider-manager.d.ts +57 -0
  198. package/dist/config/provider-manager.js +344 -0
  199. package/dist/config/resolver.d.ts +40 -0
  200. package/dist/config/resolver.js +52 -0
  201. package/dist/config/schema.d.ts +389 -0
  202. package/dist/config/schema.js +132 -0
  203. package/dist/events/events.d.ts +348 -0
  204. package/dist/events/events.js +146 -0
  205. package/dist/events/index.d.ts +10 -0
  206. package/dist/events/index.js +5 -0
  207. package/dist/events/projection.d.ts +207 -0
  208. package/dist/events/projection.js +438 -0
  209. package/dist/events/publisher.d.ts +48 -0
  210. package/dist/events/publisher.js +404 -0
  211. package/dist/events/redacting-sink.d.ts +11 -0
  212. package/dist/events/redacting-sink.js +31 -0
  213. package/dist/home.d.ts +16 -0
  214. package/dist/home.js +20 -0
  215. package/dist/index.d.ts +22 -0
  216. package/dist/index.js +22 -0
  217. package/dist/internal.d.ts +33 -0
  218. package/dist/internal.js +29 -0
  219. package/dist/llm/auth.d.ts +22 -0
  220. package/dist/llm/auth.js +112 -0
  221. package/dist/llm/capability.d.ts +13 -0
  222. package/dist/llm/capability.js +45 -0
  223. package/dist/llm/define-model.d.ts +110 -0
  224. package/dist/llm/define-model.js +252 -0
  225. package/dist/llm/errors.d.ts +33 -0
  226. package/dist/llm/errors.js +154 -0
  227. package/dist/llm/index.d.ts +14 -0
  228. package/dist/llm/index.js +8 -0
  229. package/dist/llm/model.d.ts +43 -0
  230. package/dist/llm/model.js +9 -0
  231. package/dist/llm/retry.d.ts +35 -0
  232. package/dist/llm/retry.js +160 -0
  233. package/dist/llm/runtime.d.ts +25 -0
  234. package/dist/llm/runtime.js +38 -0
  235. package/dist/logging/diagnostics.d.ts +21 -0
  236. package/dist/logging/diagnostics.js +46 -0
  237. package/dist/logging/index.d.ts +11 -0
  238. package/dist/logging/index.js +7 -0
  239. package/dist/logging/logger.d.ts +25 -0
  240. package/dist/logging/logger.js +54 -0
  241. package/dist/logging/paths.d.ts +11 -0
  242. package/dist/logging/paths.js +20 -0
  243. package/dist/logging/policy.d.ts +5 -0
  244. package/dist/logging/policy.js +19 -0
  245. package/dist/logging/redact.d.ts +10 -0
  246. package/dist/logging/redact.js +95 -0
  247. package/dist/logging/sinks.d.ts +67 -0
  248. package/dist/logging/sinks.js +117 -0
  249. package/dist/loop/context.d.ts +69 -0
  250. package/dist/loop/context.js +129 -0
  251. package/dist/loop/errors.d.ts +8 -0
  252. package/dist/loop/errors.js +27 -0
  253. package/dist/loop/events.d.ts +14 -0
  254. package/dist/loop/events.js +2 -0
  255. package/dist/loop/index.d.ts +10 -0
  256. package/dist/loop/index.js +7 -0
  257. package/dist/loop/interruption.d.ts +118 -0
  258. package/dist/loop/interruption.js +191 -0
  259. package/dist/loop/run-turn.d.ts +54 -0
  260. package/dist/loop/run-turn.js +203 -0
  261. package/dist/loop/scheduler.d.ts +18 -0
  262. package/dist/loop/scheduler.js +71 -0
  263. package/dist/loop/steer.d.ts +122 -0
  264. package/dist/loop/steer.js +209 -0
  265. package/dist/loop/tool-call.d.ts +41 -0
  266. package/dist/loop/tool-call.js +326 -0
  267. package/dist/loop/turn-step.d.ts +57 -0
  268. package/dist/loop/turn-step.js +298 -0
  269. package/dist/loop/types.d.ts +217 -0
  270. package/dist/loop/types.js +2 -0
  271. package/dist/loop/usage.d.ts +6 -0
  272. package/dist/loop/usage.js +44 -0
  273. package/dist/mcp/auth-tool.d.ts +12 -0
  274. package/dist/mcp/auth-tool.js +92 -0
  275. package/dist/mcp/capability.d.ts +7 -0
  276. package/dist/mcp/capability.js +91 -0
  277. package/dist/mcp/config-loader.d.ts +28 -0
  278. package/dist/mcp/config-loader.js +115 -0
  279. package/dist/mcp/filter.d.ts +18 -0
  280. package/dist/mcp/filter.js +35 -0
  281. package/dist/mcp/index.d.ts +23 -0
  282. package/dist/mcp/index.js +13 -0
  283. package/dist/mcp/manager.d.ts +51 -0
  284. package/dist/mcp/manager.js +412 -0
  285. package/dist/mcp/mock-transport.d.ts +40 -0
  286. package/dist/mcp/mock-transport.js +68 -0
  287. package/dist/mcp/oauth/callback-server.d.ts +14 -0
  288. package/dist/mcp/oauth/callback-server.js +122 -0
  289. package/dist/mcp/oauth/index.d.ts +9 -0
  290. package/dist/mcp/oauth/index.js +5 -0
  291. package/dist/mcp/oauth/provider.d.ts +39 -0
  292. package/dist/mcp/oauth/provider.js +121 -0
  293. package/dist/mcp/oauth/service.d.ts +34 -0
  294. package/dist/mcp/oauth/service.js +130 -0
  295. package/dist/mcp/oauth/store.d.ts +40 -0
  296. package/dist/mcp/oauth/store.js +134 -0
  297. package/dist/mcp/output.d.ts +12 -0
  298. package/dist/mcp/output.js +110 -0
  299. package/dist/mcp/provider.d.ts +7 -0
  300. package/dist/mcp/provider.js +56 -0
  301. package/dist/mcp/sdk-transport.d.ts +25 -0
  302. package/dist/mcp/sdk-transport.js +228 -0
  303. package/dist/mcp/server.d.ts +77 -0
  304. package/dist/mcp/server.js +120 -0
  305. package/dist/mcp/tool-naming.d.ts +4 -0
  306. package/dist/mcp/tool-naming.js +26 -0
  307. package/dist/mcp/types.d.ts +75 -0
  308. package/dist/mcp/types.js +2 -0
  309. package/dist/net/index.d.ts +3 -0
  310. package/dist/net/index.js +2 -0
  311. package/dist/net/proxy.d.ts +16 -0
  312. package/dist/net/proxy.js +42 -0
  313. package/dist/permission/auto-approver/index.d.ts +3 -0
  314. package/dist/permission/auto-approver/index.js +3 -0
  315. package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
  316. package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
  317. package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
  318. package/dist/permission/auto-approver/prompts-data.js +155 -0
  319. package/dist/permission/auto-approver/prompts.d.ts +18 -0
  320. package/dist/permission/auto-approver/prompts.js +40 -0
  321. package/dist/permission/auto-approver/transcript.d.ts +22 -0
  322. package/dist/permission/auto-approver/transcript.js +75 -0
  323. package/dist/permission/auto-approver/xml.d.ts +5 -0
  324. package/dist/permission/auto-approver/xml.js +25 -0
  325. package/dist/permission/index.d.ts +7 -0
  326. package/dist/permission/index.js +5 -0
  327. package/dist/permission/manager.d.ts +74 -0
  328. package/dist/permission/manager.js +162 -0
  329. package/dist/permission/matches-rule.d.ts +27 -0
  330. package/dist/permission/matches-rule.js +54 -0
  331. package/dist/permission/policies.d.ts +14 -0
  332. package/dist/permission/policies.js +233 -0
  333. package/dist/permission/types.d.ts +84 -0
  334. package/dist/permission/types.js +2 -0
  335. package/dist/plugins/archive.d.ts +3 -0
  336. package/dist/plugins/archive.js +58 -0
  337. package/dist/plugins/github-resolver.d.ts +13 -0
  338. package/dist/plugins/github-resolver.js +20 -0
  339. package/dist/plugins/hooks.d.ts +28 -0
  340. package/dist/plugins/hooks.js +296 -0
  341. package/dist/plugins/index.d.ts +23 -0
  342. package/dist/plugins/index.js +23 -0
  343. package/dist/plugins/injector.d.ts +11 -0
  344. package/dist/plugins/injector.js +32 -0
  345. package/dist/plugins/manager.d.ts +37 -0
  346. package/dist/plugins/manager.js +330 -0
  347. package/dist/plugins/manifest.d.ts +9 -0
  348. package/dist/plugins/manifest.js +234 -0
  349. package/dist/plugins/marketplace.d.ts +85 -0
  350. package/dist/plugins/marketplace.js +205 -0
  351. package/dist/plugins/source.d.ts +23 -0
  352. package/dist/plugins/source.js +87 -0
  353. package/dist/plugins/store.d.ts +20 -0
  354. package/dist/plugins/store.js +30 -0
  355. package/dist/plugins/types.d.ts +118 -0
  356. package/dist/plugins/types.js +5 -0
  357. package/dist/protocol/index.d.ts +4 -0
  358. package/dist/protocol/index.js +2 -0
  359. package/dist/protocol/tool-schema.d.ts +6 -0
  360. package/dist/protocol/tool-schema.js +2 -0
  361. package/dist/store/blob-store.d.ts +45 -0
  362. package/dist/store/blob-store.js +120 -0
  363. package/dist/store/catalog-store.d.ts +32 -0
  364. package/dist/store/catalog-store.js +73 -0
  365. package/dist/store/disk-store.d.ts +58 -0
  366. package/dist/store/disk-store.js +369 -0
  367. package/dist/store/index.d.ts +23 -0
  368. package/dist/store/index.js +15 -0
  369. package/dist/store/lock.d.ts +86 -0
  370. package/dist/store/lock.js +104 -0
  371. package/dist/store/log-store.d.ts +89 -0
  372. package/dist/store/log-store.js +296 -0
  373. package/dist/store/migrate.d.ts +26 -0
  374. package/dist/store/migrate.js +32 -0
  375. package/dist/store/origin.d.ts +89 -0
  376. package/dist/store/origin.js +16 -0
  377. package/dist/store/pg.d.ts +90 -0
  378. package/dist/store/pg.js +344 -0
  379. package/dist/store/redacting-store.d.ts +21 -0
  380. package/dist/store/redacting-store.js +46 -0
  381. package/dist/store/redis.d.ts +89 -0
  382. package/dist/store/redis.js +370 -0
  383. package/dist/store/repository.d.ts +150 -0
  384. package/dist/store/repository.js +508 -0
  385. package/dist/store/session-catalog.d.ts +32 -0
  386. package/dist/store/session-catalog.js +117 -0
  387. package/dist/store/storage.d.ts +27 -0
  388. package/dist/store/storage.js +54 -0
  389. package/dist/store/store.d.ts +262 -0
  390. package/dist/store/store.js +129 -0
  391. package/dist/store/workdir-key.d.ts +4 -0
  392. package/dist/store/workdir-key.js +28 -0
  393. package/dist/tool/access.d.ts +37 -0
  394. package/dist/tool/access.js +79 -0
  395. package/dist/tool/ask.d.ts +22 -0
  396. package/dist/tool/ask.js +38 -0
  397. package/dist/tool/background.d.ts +109 -0
  398. package/dist/tool/background.js +39 -0
  399. package/dist/tool/builtin/ask-user-question.d.ts +2 -0
  400. package/dist/tool/builtin/ask-user-question.js +175 -0
  401. package/dist/tool/builtin/bash.d.ts +2 -0
  402. package/dist/tool/builtin/bash.js +407 -0
  403. package/dist/tool/builtin/edit.d.ts +2 -0
  404. package/dist/tool/builtin/edit.js +202 -0
  405. package/dist/tool/builtin/glob.d.ts +3 -0
  406. package/dist/tool/builtin/glob.js +260 -0
  407. package/dist/tool/builtin/grep.d.ts +2 -0
  408. package/dist/tool/builtin/grep.js +574 -0
  409. package/dist/tool/builtin/line-endings.d.ts +10 -0
  410. package/dist/tool/builtin/line-endings.js +41 -0
  411. package/dist/tool/builtin/read.d.ts +28 -0
  412. package/dist/tool/builtin/read.js +498 -0
  413. package/dist/tool/builtin/write.d.ts +2 -0
  414. package/dist/tool/builtin/write.js +179 -0
  415. package/dist/tool/define.d.ts +46 -0
  416. package/dist/tool/define.js +45 -0
  417. package/dist/tool/file-freshness.d.ts +81 -0
  418. package/dist/tool/file-freshness.js +67 -0
  419. package/dist/tool/filesystem-tools.d.ts +16 -0
  420. package/dist/tool/filesystem-tools.js +19 -0
  421. package/dist/tool/git-context.d.ts +20 -0
  422. package/dist/tool/git-context.js +114 -0
  423. package/dist/tool/index.d.ts +37 -0
  424. package/dist/tool/index.js +34 -0
  425. package/dist/tool/machine-base.d.ts +138 -0
  426. package/dist/tool/machine-base.js +388 -0
  427. package/dist/tool/machine-local.d.ts +35 -0
  428. package/dist/tool/machine-local.js +316 -0
  429. package/dist/tool/machine-null.d.ts +36 -0
  430. package/dist/tool/machine-null.js +64 -0
  431. package/dist/tool/machine-ssh.d.ts +86 -0
  432. package/dist/tool/machine-ssh.js +576 -0
  433. package/dist/tool/machine.d.ts +333 -0
  434. package/dist/tool/machine.js +15 -0
  435. package/dist/tool/policies/path-access.d.ts +48 -0
  436. package/dist/tool/policies/path-access.js +186 -0
  437. package/dist/tool/policies/sensitive.d.ts +3 -0
  438. package/dist/tool/policies/sensitive.js +60 -0
  439. package/dist/tool/questions.d.ts +40 -0
  440. package/dist/tool/questions.js +8 -0
  441. package/dist/tool/search/activation.d.ts +13 -0
  442. package/dist/tool/search/activation.js +31 -0
  443. package/dist/tool/search/deferral.d.ts +37 -0
  444. package/dist/tool/search/deferral.js +128 -0
  445. package/dist/tool/search/search-tool.d.ts +9 -0
  446. package/dist/tool/search/search-tool.js +62 -0
  447. package/dist/tool/shell-env.d.ts +9 -0
  448. package/dist/tool/shell-env.js +34 -0
  449. package/dist/tool/support/bash-destructive.d.ts +24 -0
  450. package/dist/tool/support/bash-destructive.js +63 -0
  451. package/dist/tool/support/bash-paths.d.ts +7 -0
  452. package/dist/tool/support/bash-paths.js +247 -0
  453. package/dist/tool/support/bash-read-only.d.ts +8 -0
  454. package/dist/tool/support/bash-read-only.js +165 -0
  455. package/dist/tool/support/bash-rule-match.d.ts +20 -0
  456. package/dist/tool/support/bash-rule-match.js +191 -0
  457. package/dist/tool/support/file-type.d.ts +10 -0
  458. package/dist/tool/support/file-type.js +149 -0
  459. package/dist/tool/support/git-worktree.d.ts +10 -0
  460. package/dist/tool/support/git-worktree.js +63 -0
  461. package/dist/tool/support/image-compress.d.ts +69 -0
  462. package/dist/tool/support/image-compress.js +265 -0
  463. package/dist/tool/support/machine-ops.d.ts +34 -0
  464. package/dist/tool/support/machine-ops.js +34 -0
  465. package/dist/tool/support/path-glob-match.d.ts +12 -0
  466. package/dist/tool/support/path-glob-match.js +84 -0
  467. package/dist/tool/support/result-builder.d.ts +27 -0
  468. package/dist/tool/support/result-builder.js +108 -0
  469. package/dist/tool/support/rg-locator.d.ts +20 -0
  470. package/dist/tool/support/rg-locator.js +42 -0
  471. package/dist/tool/support/ripgrep-run.d.ts +65 -0
  472. package/dist/tool/support/ripgrep-run.js +40 -0
  473. package/dist/tool/support/rule-match.d.ts +6 -0
  474. package/dist/tool/support/rule-match.js +23 -0
  475. package/dist/tool/support/tool-path.d.ts +8 -0
  476. package/dist/tool/support/tool-path.js +28 -0
  477. package/dist/tool/support/workspace.d.ts +5 -0
  478. package/dist/tool/support/workspace.js +2 -0
  479. package/dist/tool/types.d.ts +131 -0
  480. package/dist/tool/types.js +2 -0
  481. package/dist/tool/web/fetch-url.d.ts +4 -0
  482. package/dist/tool/web/fetch-url.js +61 -0
  483. package/dist/tool/web/index.d.ts +11 -0
  484. package/dist/tool/web/index.js +7 -0
  485. package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
  486. package/dist/tool/web/providers/direct-fetch.js +198 -0
  487. package/dist/tool/web/providers/firecrawl.d.ts +16 -0
  488. package/dist/tool/web/providers/firecrawl.js +59 -0
  489. package/dist/tool/web/providers/tavily.d.ts +14 -0
  490. package/dist/tool/web/providers/tavily.js +43 -0
  491. package/dist/tool/web/types.d.ts +41 -0
  492. package/dist/tool/web/types.js +7 -0
  493. package/dist/tool/web/web-search.d.ts +4 -0
  494. package/dist/tool/web/web-search.js +68 -0
  495. package/dist/tool/workspace-spec.d.ts +74 -0
  496. package/dist/tool/workspace-spec.js +177 -0
  497. package/dist/tracing/bridge.d.ts +7 -0
  498. package/dist/tracing/bridge.js +171 -0
  499. package/dist/tracing/index.d.ts +9 -0
  500. package/dist/tracing/index.js +5 -0
  501. package/dist/tracing/otel.d.ts +38 -0
  502. package/dist/tracing/otel.js +221 -0
  503. package/dist/tracing/processor.d.ts +47 -0
  504. package/dist/tracing/processor.js +94 -0
  505. package/dist/tracing/spans.d.ts +94 -0
  506. package/dist/tracing/spans.js +56 -0
  507. package/dist/ui/ai-sdk.d.ts +114 -0
  508. package/dist/ui/ai-sdk.js +175 -0
  509. package/dist/ui/index.d.ts +2 -0
  510. package/dist/ui/index.js +2 -0
  511. package/package.json +101 -0
@@ -0,0 +1,118 @@
1
+ import type { ApprovalResponse } from "../permission/types.ts";
2
+ import type { AssistantMessage, Message, Usage } from "../protocol/index.ts";
3
+ import type { ToolInputRequest } from "../tool/types.ts";
4
+ import type { PendingInterrupt } from "./types.ts";
5
+ export declare const INTERRUPTION_STATE_KEY: "interrupt";
6
+ export declare const INTERRUPTION_STATE_VERSION: 1;
7
+ /** Stable identity of an agent definition. Instance identity lives on the frame. */
8
+ export interface AgentDefinitionReference {
9
+ readonly key: string;
10
+ readonly name: string;
11
+ }
12
+ /** Locates and validates the assistant batch whose execution is being continued. */
13
+ export interface InterruptionAnchor {
14
+ readonly toolCallId: string;
15
+ readonly assistantDigest: string;
16
+ }
17
+ export interface InterruptionExecution {
18
+ readonly turns: number;
19
+ readonly maxTurns: number;
20
+ readonly usage: Usage;
21
+ }
22
+ export interface InterruptionFrame {
23
+ readonly frameId: string;
24
+ readonly agentInstanceId: string;
25
+ readonly address: string;
26
+ readonly agent: AgentDefinitionReference;
27
+ readonly turnId: string;
28
+ readonly execution: InterruptionExecution;
29
+ readonly anchor: InterruptionAnchor;
30
+ readonly pending: readonly PendingInterrupt[];
31
+ /** Approval answers, replayed through the authorize hook on every re-run of the batch. */
32
+ readonly decisions: Readonly<Record<string, ApprovalResponse>>;
33
+ /** Input answers for suspended tool calls (toolCallId → data). One-shot: consumed by the
34
+ * re-run; dropped when the same call suspends again. */
35
+ readonly inputAnswers?: Readonly<Record<string, unknown>>;
36
+ /** Parent toolCallId -> child frameId. */
37
+ readonly children: Readonly<Record<string, string>>;
38
+ }
39
+ /** A caller's answer to one pending interrupt, routed by `kind` to the matching pending entry. */
40
+ export type InterruptAnswer = ({
41
+ readonly kind: "approval";
42
+ } & ApprovalResponse) | {
43
+ readonly kind: "input";
44
+ readonly data: unknown;
45
+ };
46
+ /**
47
+ * Lifecycle of a persisted interruption: `waiting` (paused, answers pending) →
48
+ * `resuming` (a resume is executing) → back to `waiting` on the next pause, or deleted on
49
+ * a terminal result. `recovery_required` is stamped when a resume THREW mid-flight — it is
50
+ * not a dead end: `applyInterruptionAnswers` unconditionally returns `phase: "resuming"`,
51
+ * so the exit is simply to re-read the persisted state (its `revision` was bumped along
52
+ * with the phase) and call `Runner.resume` with it again. Callers holding a pre-crash
53
+ * copy get a "stale interruption state" error — that error is the re-fetch signal.
54
+ */
55
+ export type InterruptionPhase = "waiting" | "resuming" | "recovery_required";
56
+ /**
57
+ * Bounded control state for a paused foreground agent tree. Conversation data remains in
58
+ * the per-address append logs and is reconstructed with replayContext.
59
+ */
60
+ export interface InterruptionState {
61
+ readonly version: typeof INTERRUPTION_STATE_VERSION;
62
+ readonly runId: string;
63
+ readonly interruptionId: string;
64
+ readonly phase: InterruptionPhase;
65
+ readonly revision: number;
66
+ readonly rootFrameId: string;
67
+ readonly frames: Readonly<Record<string, InterruptionFrame>>;
68
+ readonly createdAt: number;
69
+ readonly updatedAt: number;
70
+ }
71
+ /** Pending interrupt surfaced to callers (internal continuation state stripped).
72
+ * approvalId stays unique across parallel agent frames. */
73
+ export type PendingRunInterrupt = PendingInterrupt & {
74
+ readonly approvalId: string;
75
+ readonly frameId: string;
76
+ readonly address: string;
77
+ readonly agent: AgentDefinitionReference;
78
+ };
79
+ /** A child Agent tool call that reached a durable foreground interruption. */
80
+ export interface ToolCallSuspension {
81
+ readonly toolCallId: string;
82
+ readonly state: InterruptionState;
83
+ }
84
+ export declare function newInterruptionId(prefix?: "run" | "interrupt" | "frame" | "agent" | "handoff"): string;
85
+ export declare function interruptionAnchor(message: AssistantMessage, preferredToolCallId?: string): InterruptionAnchor;
86
+ export declare function digestAssistantToolCalls(message: AssistantMessage): string;
87
+ /** Finds the exact assistant batch in a replayed shard and rejects stale/mismatched logs. */
88
+ export declare function findAnchoredAssistant(messages: readonly Message[], anchor: InterruptionAnchor): AssistantMessage;
89
+ export declare function parseInterruptionState(raw: unknown): InterruptionState;
90
+ export declare function flattenPendingInterrupts(state: InterruptionState): PendingRunInterrupt[];
91
+ /**
92
+ * Merge caller answers into their owning frames — approval answers into `decisions`,
93
+ * input answers into `inputAnswers`, each validated against its pending entry's kind.
94
+ * Composite approvalId is authoritative; a raw toolCallId remains accepted when it is
95
+ * unambiguous in the paused tree.
96
+ */
97
+ export declare function applyInterruptionAnswers(state: InterruptionState, answers: Readonly<Record<string, InterruptAnswer>>): InterruptionState;
98
+ export declare function approvalId(frameId: string, toolCallId: string): string;
99
+ /**
100
+ * Internal-only unwind thrown by `ToolRunContext.suspend`: a tool suspending itself
101
+ * mid-execution with a user-facing `request` and a private continuation `state`.
102
+ * Caught by the tool-call layer and reified into a `PendingInputInterrupt`.
103
+ */
104
+ export declare class ToolSuspendSignal extends Error {
105
+ readonly request: ToolInputRequest;
106
+ readonly state?: unknown;
107
+ constructor(request: ToolInputRequest, state?: unknown);
108
+ }
109
+ export declare function isToolSuspendSignal(value: unknown): value is ToolSuspendSignal;
110
+ /** Internal-only structured unwind from an Agent tool into the parent tool batch. */
111
+ export declare class ToolInterruptionSignal extends Error {
112
+ readonly state: InterruptionState;
113
+ constructor(state: InterruptionState);
114
+ }
115
+ export declare function isToolInterruptionSignal(value: unknown): value is ToolInterruptionSignal;
116
+ export declare function attachInterruptionState<T extends object>(result: T, state: InterruptionState): T;
117
+ export declare function getInterruptionState(result: object): InterruptionState | undefined;
118
+ //# sourceMappingURL=interruption.d.ts.map
@@ -0,0 +1,191 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ export const INTERRUPTION_STATE_KEY = "interrupt";
3
+ export const INTERRUPTION_STATE_VERSION = 1;
4
+ export function newInterruptionId(prefix = "interrupt") {
5
+ return `${prefix}_${randomBytes(10).toString("hex")}`;
6
+ }
7
+ export function interruptionAnchor(message, preferredToolCallId) {
8
+ const calls = assistantToolCalls(message);
9
+ if (calls.length === 0)
10
+ throw new Error("Cannot interrupt: assistant message contains no tool calls.");
11
+ const toolCallId = preferredToolCallId ?? calls[0].id;
12
+ if (!calls.some((call) => call.id === toolCallId)) {
13
+ throw new Error(`Cannot interrupt: tool call "${toolCallId}" is not present in the assistant batch.`);
14
+ }
15
+ return { toolCallId, assistantDigest: digestAssistantToolCalls(message) };
16
+ }
17
+ export function digestAssistantToolCalls(message) {
18
+ const canonical = stableStringify(assistantToolCalls(message).map((call) => ({ id: call.id, name: call.name, arguments: call.arguments })));
19
+ return createHash("sha256").update(canonical).digest("hex");
20
+ }
21
+ /** Finds the exact assistant batch in a replayed shard and rejects stale/mismatched logs. */
22
+ export function findAnchoredAssistant(messages, anchor) {
23
+ for (let i = messages.length - 1; i >= 0; i--) {
24
+ const message = messages[i];
25
+ if (message.role !== "assistant")
26
+ continue;
27
+ if (!assistantToolCalls(message).some((call) => call.id === anchor.toolCallId))
28
+ continue;
29
+ const digest = digestAssistantToolCalls(message);
30
+ if (digest !== anchor.assistantDigest) {
31
+ throw new Error(`Cannot resume: assistant batch for tool call "${anchor.toolCallId}" changed (digest mismatch).`);
32
+ }
33
+ return message;
34
+ }
35
+ throw new Error(`Cannot resume: tool call "${anchor.toolCallId}" was not found in the replayed log.`);
36
+ }
37
+ export function parseInterruptionState(raw) {
38
+ const value = typeof raw === "string" ? JSON.parse(raw) : raw;
39
+ if (!isRecord(value) || value.version !== INTERRUPTION_STATE_VERSION) {
40
+ const version = isRecord(value) ? String(value.version) : "missing";
41
+ throw new Error(`Unsupported interruption state version ${version} (expected ${INTERRUPTION_STATE_VERSION}).`);
42
+ }
43
+ if (typeof value.runId !== "string" ||
44
+ typeof value.interruptionId !== "string" ||
45
+ typeof value.rootFrameId !== "string" ||
46
+ typeof value.revision !== "number" ||
47
+ !isRecord(value.frames) ||
48
+ !isRecord(value.frames[value.rootFrameId])) {
49
+ throw new Error("Invalid interruption state: missing run, root frame, revision, or frame table.");
50
+ }
51
+ if (value.phase !== "waiting" && value.phase !== "resuming" && value.phase !== "recovery_required") {
52
+ throw new Error(`Invalid interruption state phase "${String(value.phase)}".`);
53
+ }
54
+ return value;
55
+ }
56
+ export function flattenPendingInterrupts(state) {
57
+ const out = [];
58
+ const visit = (frameId) => {
59
+ const frame = state.frames[frameId];
60
+ if (!frame)
61
+ throw new Error(`Invalid interruption state: frame "${frameId}" is missing.`);
62
+ for (const pending of frame.pending) {
63
+ // The tool's continuation state is private to the frame — never surfaced to callers.
64
+ const publicPending = pending.kind === "input" ? (({ state: _state, ...rest }) => rest)(pending) : pending;
65
+ out.push({
66
+ ...publicPending,
67
+ approvalId: approvalId(frame.frameId, pending.toolCallId),
68
+ frameId: frame.frameId,
69
+ address: frame.address,
70
+ agent: frame.agent,
71
+ });
72
+ }
73
+ for (const childId of Object.values(frame.children))
74
+ visit(childId);
75
+ };
76
+ visit(state.rootFrameId);
77
+ return out;
78
+ }
79
+ /**
80
+ * Merge caller answers into their owning frames — approval answers into `decisions`,
81
+ * input answers into `inputAnswers`, each validated against its pending entry's kind.
82
+ * Composite approvalId is authoritative; a raw toolCallId remains accepted when it is
83
+ * unambiguous in the paused tree.
84
+ */
85
+ export function applyInterruptionAnswers(state, answers) {
86
+ const pending = flattenPendingInterrupts(state);
87
+ const byApprovalId = new Map(pending.map((item) => [item.approvalId, item]));
88
+ const byToolCallId = new Map();
89
+ for (const item of pending) {
90
+ const group = byToolCallId.get(item.toolCallId) ?? [];
91
+ group.push(item);
92
+ byToolCallId.set(item.toolCallId, group);
93
+ }
94
+ const decisionAdditions = new Map();
95
+ const inputAdditions = new Map();
96
+ for (const [key, answer] of Object.entries(answers)) {
97
+ let target = byApprovalId.get(key);
98
+ if (!target) {
99
+ const matches = byToolCallId.get(key) ?? [];
100
+ if (matches.length > 1) {
101
+ throw new Error(`Answer key "${key}" is ambiguous across agent frames; use approvalId instead.`);
102
+ }
103
+ target = matches[0];
104
+ }
105
+ if (!target)
106
+ throw new Error(`Answer key "${key}" is not pending on interruption "${state.interruptionId}".`);
107
+ if (answer.kind !== target.kind) {
108
+ throw new Error(`Answer for "${key}" has kind "${answer.kind}" but the pending interrupt expects "${target.kind}".`);
109
+ }
110
+ if (answer.kind === "input") {
111
+ const frameAnswers = inputAdditions.get(target.frameId) ?? {};
112
+ frameAnswers[target.toolCallId] = answer.data;
113
+ inputAdditions.set(target.frameId, frameAnswers);
114
+ }
115
+ else {
116
+ const { kind: _kind, ...response } = answer;
117
+ const frameAnswers = decisionAdditions.get(target.frameId) ?? {};
118
+ frameAnswers[target.toolCallId] = response;
119
+ decisionAdditions.set(target.frameId, frameAnswers);
120
+ }
121
+ }
122
+ const frames = {};
123
+ for (const [frameId, frame] of Object.entries(state.frames)) {
124
+ frames[frameId] = {
125
+ ...frame,
126
+ decisions: { ...frame.decisions, ...(decisionAdditions.get(frameId) ?? {}) },
127
+ inputAnswers: { ...(frame.inputAnswers ?? {}), ...(inputAdditions.get(frameId) ?? {}) },
128
+ };
129
+ }
130
+ const now = Date.now();
131
+ return { ...state, phase: "resuming", revision: state.revision + 1, frames, updatedAt: now };
132
+ }
133
+ export function approvalId(frameId, toolCallId) {
134
+ return `${frameId}:${toolCallId}`;
135
+ }
136
+ /**
137
+ * Internal-only unwind thrown by `ToolRunContext.suspend`: a tool suspending itself
138
+ * mid-execution with a user-facing `request` and a private continuation `state`.
139
+ * Caught by the tool-call layer and reified into a `PendingInputInterrupt`.
140
+ */
141
+ export class ToolSuspendSignal extends Error {
142
+ request;
143
+ state;
144
+ constructor(request, state) {
145
+ super("Tool suspended awaiting caller input.");
146
+ this.name = "ToolSuspendSignal";
147
+ this.request = request;
148
+ this.state = state;
149
+ }
150
+ }
151
+ export function isToolSuspendSignal(value) {
152
+ return value instanceof ToolSuspendSignal;
153
+ }
154
+ /** Internal-only structured unwind from an Agent tool into the parent tool batch. */
155
+ export class ToolInterruptionSignal extends Error {
156
+ state;
157
+ constructor(state) {
158
+ super("Foreground sub-agent interrupted.");
159
+ this.name = "ToolInterruptionSignal";
160
+ this.state = state;
161
+ }
162
+ }
163
+ export function isToolInterruptionSignal(value) {
164
+ return value instanceof ToolInterruptionSignal;
165
+ }
166
+ const interruptionStateSymbol = Symbol("operon.interruptionState");
167
+ export function attachInterruptionState(result, state) {
168
+ Object.defineProperty(result, interruptionStateSymbol, { value: state, enumerable: false });
169
+ return result;
170
+ }
171
+ export function getInterruptionState(result) {
172
+ return result[interruptionStateSymbol];
173
+ }
174
+ function assistantToolCalls(message) {
175
+ return message.content.filter((part) => part.type === "toolCall");
176
+ }
177
+ function stableStringify(value) {
178
+ if (value === null || typeof value !== "object")
179
+ return JSON.stringify(value) ?? "null";
180
+ if (Array.isArray(value))
181
+ return `[${value.map(stableStringify).join(",")}]`;
182
+ const record = value;
183
+ return `{${Object.keys(record)
184
+ .sort()
185
+ .map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`)
186
+ .join(",")}}`;
187
+ }
188
+ function isRecord(value) {
189
+ return typeof value === "object" && value !== null && !Array.isArray(value);
190
+ }
191
+ //# sourceMappingURL=interruption.js.map
@@ -0,0 +1,54 @@
1
+ import type { ChatModel } from "../llm/define-model.ts";
2
+ import type { AssistantMessage, Message, Usage } from "../protocol/index.ts";
3
+ import type { PromptOrigin } from "../store/origin.ts";
4
+ import type { Tool } from "../tool/types.ts";
5
+ import type { Machine } from "../tool/machine.ts";
6
+ import type { BackgroundSpawner } from "../tool/background.ts";
7
+ import type { QuestionResponder } from "../tool/questions.ts";
8
+ import { FileFreshnessLedger } from "../tool/file-freshness.ts";
9
+ import type { Logger } from "../logging/index.ts";
10
+ import { type RecordUsageResult } from "./turn-step.ts";
11
+ import type { ConversationContext } from "./context.ts";
12
+ import type { LoopEventDispatcher } from "./events.ts";
13
+ import type { BatchResume, LoopHooks, OutputGuardrailMonitorFactory, TurnResult } from "./types.ts";
14
+ export interface RunTurnInput {
15
+ readonly turnId: string;
16
+ readonly address?: string;
17
+ /** Forwarded to the request as provider prompt-cache affinity; see `ExecuteStepDeps`. */
18
+ readonly sessionId?: string;
19
+ readonly signal: AbortSignal;
20
+ readonly model: ChatModel;
21
+ readonly machine: Machine;
22
+ readonly background?: BackgroundSpawner;
23
+ /** Client interactive-question channel; forwarded to tool contexts (AskUserQuestion). */
24
+ readonly responder?: QuestionResponder;
25
+ /** Session-scoped file freshness ledger for this agent line; forwarded to tool contexts. */
26
+ readonly fileLedger?: FileFreshnessLedger;
27
+ readonly system?: string;
28
+ readonly params?: import("../llm/model.ts").LlmRequest["params"];
29
+ readonly context: ConversationContext;
30
+ readonly tools?: readonly Tool[];
31
+ /** Capability tools hidden until transcript load/use evidence activates them. */
32
+ readonly deferredToolNames?: ReadonlySet<string>;
33
+ readonly hooks?: LoopHooks;
34
+ /** Per-step optimistic output guardrail adapter supplied by the active agent layer. */
35
+ readonly createOutputGuardrailMonitor?: OutputGuardrailMonitorFactory;
36
+ readonly maxSteps?: number;
37
+ readonly maxRetriesPerStep?: number;
38
+ readonly recordStepUsage?: (usage: Usage) => RecordUsageResult | void | Promise<RecordUsageResult | void>;
39
+ /** Unified loop event sink — model stream, tool results, retries, dropped partials. */
40
+ readonly dispatchEvent?: LoopEventDispatcher;
41
+ readonly logger?: Logger;
42
+ readonly resumeFrom?: AssistantMessage;
43
+ /** Paired with `resumeFrom`: the paused frame's pending entries + input answers, consumed
44
+ * by the re-run batch (suspended-call continuation and auto re-park). */
45
+ readonly resume?: BatchResume;
46
+ readonly drainSteering?: () => readonly SteeredInput[];
47
+ }
48
+ /** A steered message plus its structured origin, mapped by the caller (which owns the SteerBus). */
49
+ export interface SteeredInput {
50
+ readonly message: Message;
51
+ readonly origin?: PromptOrigin;
52
+ }
53
+ export declare function runTurn(input: RunTurnInput): Promise<TurnResult>;
54
+ //# sourceMappingURL=run-turn.d.ts.map
@@ -0,0 +1,203 @@
1
+ import { FileFreshnessLedger } from "../tool/file-freshness.js";
2
+ import { addUsage, emptyUsage } from "./usage.js";
3
+ import { isAbortError, MaxStepsExceededError } from "./errors.js";
4
+ import { APIContextOverflowError } from "../llm/errors.js";
5
+ import { executeStep } from "./turn-step.js";
6
+ import { activeDeferredTools } from "../tool/search/activation.js";
7
+ import { runCalls } from "./tool-call.js";
8
+ /**
9
+ * Cap on `recoverStepError` claims per turn. A claimant that keeps "recovering" without
10
+ * changing the outcome (compaction that shrinks too little, say) would otherwise loop the
11
+ * failed step forever; two attempts cover "compact once, then compact harder" and no more.
12
+ */
13
+ const MAX_STEP_RECOVERIES_PER_TURN = 2;
14
+ export async function runTurn(input) {
15
+ const toolList = input.tools ?? [];
16
+ const deferredToolNames = input.deferredToolNames ?? new Set();
17
+ const fileLedger = input.fileLedger ?? new FileFreshnessLedger();
18
+ let usage = emptyUsage();
19
+ let steps = 0;
20
+ let stepRecoveries = 0;
21
+ // Normal exits overwrite this with the completed step's stop reason.
22
+ let stopReason = "end_turn";
23
+ let handoff;
24
+ let pending;
25
+ let suspensions;
26
+ const recordUsage = async (stepUsage) => {
27
+ usage = addUsage(usage, stepUsage);
28
+ return input.recordStepUsage?.(stepUsage);
29
+ };
30
+ try {
31
+ // HITL resume — re-run the interrupted batch with pre-loaded answers first.
32
+ if (input.resumeFrom) {
33
+ const resumeTools = activeDeferredTools(toolList, deferredToolNames, input.context.messages);
34
+ const resumeToolMap = new Map(resumeTools.map((tool) => [tool.schema.name, tool]));
35
+ const completed = completedToolCallIds(input.context.messages, input.resumeFrom);
36
+ const calls = input.resumeFrom.content.filter((p) => p.type === "toolCall" && !completed.has(p.id));
37
+ const batch = await runCalls({ turnId: input.turnId, stepNumber: 0, address: input.address, signal: input.signal, model: input.model, machine: input.machine, background: input.background, responder: input.responder, fileLedger, tools: resumeToolMap, hooks: input.hooks, dispatchEvent: input.dispatchEvent, logger: input.logger, resume: input.resume }, calls);
38
+ // No hand-written `message.appended` here (or at the two drains below): appending
39
+ // journals, and journaling broadcasts. See ConversationContext.onHistoryChange.
40
+ for (const result of batch.results)
41
+ input.context.appendMessage(result);
42
+ if ((batch.pending && batch.pending.length > 0) || (batch.suspensions && batch.suspensions.length > 0)) {
43
+ return {
44
+ stopReason: "interrupt",
45
+ steps,
46
+ usage,
47
+ pending: batch.pending,
48
+ suspensions: batch.suspensions,
49
+ };
50
+ }
51
+ if (batch.handoff) {
52
+ return { stopReason: "handoff", steps, usage, handoff: batch.handoff };
53
+ }
54
+ if (batch.stopTurn) {
55
+ return { stopReason: "end_turn", steps, usage };
56
+ }
57
+ }
58
+ while (true) {
59
+ input.signal.throwIfAborted();
60
+ // live history before this model step, so the model responds to them this turn.
61
+ if (input.drainSteering) {
62
+ for (const { message, origin } of input.drainSteering())
63
+ input.context.appendMessage(message, origin);
64
+ }
65
+ if (input.maxSteps !== undefined && input.maxSteps > 0 && steps >= input.maxSteps) {
66
+ throw new MaxStepsExceededError(input.maxSteps);
67
+ }
68
+ steps += 1;
69
+ let step;
70
+ try {
71
+ step = await executeStep({
72
+ turnId: input.turnId,
73
+ address: input.address,
74
+ sessionId: input.sessionId,
75
+ signal: input.signal,
76
+ model: input.model,
77
+ machine: input.machine,
78
+ background: input.background,
79
+ responder: input.responder,
80
+ fileLedger,
81
+ system: input.system,
82
+ context: input.context,
83
+ params: input.params,
84
+ tools: toolList,
85
+ deferredToolNames,
86
+ hooks: input.hooks,
87
+ createOutputGuardrailMonitor: input.createOutputGuardrailMonitor,
88
+ currentStep: steps,
89
+ maxRetriesPerStep: input.maxRetriesPerStep,
90
+ dispatchEvent: input.dispatchEvent,
91
+ logger: input.logger,
92
+ recordUsage,
93
+ });
94
+ }
95
+ catch (error) {
96
+ // An abort wins over recovery — the outer catch maps it to "aborted" as before.
97
+ if (isAbortError(error) || input.signal.aborted)
98
+ throw error;
99
+ const recovery = input.hooks?.recoverStepError && stepRecoveries < MAX_STEP_RECOVERIES_PER_TURN
100
+ ? await input.hooks.recoverStepError({
101
+ turnId: input.turnId,
102
+ stepNumber: steps,
103
+ address: input.address,
104
+ signal: input.signal,
105
+ model: input.model,
106
+ messages: input.context.messages,
107
+ context: input.context,
108
+ system: input.system,
109
+ error,
110
+ attempt: stepRecoveries + 1,
111
+ })
112
+ : undefined;
113
+ if (recovery?.recovered === true) {
114
+ stepRecoveries += 1;
115
+ input.dispatchEvent?.({
116
+ type: "turn.step.retrying",
117
+ turnId: input.turnId,
118
+ step: steps,
119
+ attempt: stepRecoveries,
120
+ maxAttempts: MAX_STEP_RECOVERIES_PER_TURN,
121
+ delayMs: 0,
122
+ reason: error instanceof Error ? error.message : String(error),
123
+ });
124
+ // A recovered step re-runs under the same number: it never produced an outcome, so
125
+ // it must not consume the turn's step budget.
126
+ steps -= 1;
127
+ continue;
128
+ }
129
+ // Unclaimed context overflow degrades exactly as before recovery existed: the turn
130
+ // settles with "error" instead of rejecting the whole run (the failed message is
131
+ // already preserved as an `overflow_dropped` transcript record by executeStep).
132
+ if (error instanceof APIContextOverflowError) {
133
+ stopReason = "error";
134
+ break;
135
+ }
136
+ throw error;
137
+ }
138
+ if (step.stopReason === "tool_use")
139
+ continue;
140
+ const terminal = step.stopReason;
141
+ stopReason = terminal;
142
+ // handoff / interrupt bubble straight to the Runner (no continuation hook).
143
+ if (terminal === "handoff") {
144
+ handoff = step.handoff;
145
+ break;
146
+ }
147
+ if (terminal === "interrupt") {
148
+ pending = step.pending;
149
+ suspensions = step.suspensions;
150
+ break;
151
+ }
152
+ const continuation = input.hooks?.shouldContinueAfterStop
153
+ ? await input.hooks.shouldContinueAfterStop({
154
+ turnId: input.turnId,
155
+ stepNumber: steps,
156
+ usage: step.usage,
157
+ stopReason: terminal,
158
+ signal: input.signal,
159
+ model: input.model,
160
+ })
161
+ : undefined;
162
+ if (continuation?.continue === true)
163
+ continue;
164
+ // pi `getSteeringMessages` semantics: a user steer that landed DURING this terminal step
165
+ // must be answered in THIS turn, not deferred to a fresh one. The top-of-loop drain only
166
+ // runs before a step, so re-drain here before breaking — if anything queued, inject it and
167
+ // loop for one more step. Follow-ups (cron/background) are a separate channel the Runner
168
+ // drains at the turn boundary, so they intentionally do NOT keep this turn alive.
169
+ if (input.drainSteering) {
170
+ const late = input.drainSteering();
171
+ if (late.length > 0) {
172
+ for (const { message, origin } of late)
173
+ input.context.appendMessage(message, origin);
174
+ continue;
175
+ }
176
+ }
177
+ break;
178
+ }
179
+ }
180
+ catch (error) {
181
+ if (isAbortError(error) || input.signal.aborted) {
182
+ return { stopReason: "aborted", steps, usage };
183
+ }
184
+ throw error;
185
+ }
186
+ return { stopReason, steps, usage, handoff, pending, suspensions };
187
+ }
188
+ /** Tool results already journaled after the anchored assistant are stable sibling completions. */
189
+ function completedToolCallIds(messages, assistant) {
190
+ const completed = new Set();
191
+ const index = messages.lastIndexOf(assistant);
192
+ if (index < 0)
193
+ return completed;
194
+ for (let i = index + 1; i < messages.length; i++) {
195
+ const message = messages[i];
196
+ if (message.role === "assistant")
197
+ break;
198
+ if (message.role === "toolResult")
199
+ completed.add(message.toolCallId);
200
+ }
201
+ return completed;
202
+ }
203
+ //# sourceMappingURL=run-turn.js.map
@@ -0,0 +1,18 @@
1
+ import type { ToolAccesses as Accesses } from "../tool/access.ts";
2
+ export interface ToolCallTask<Result> {
3
+ readonly accesses: Accesses;
4
+ readonly start: () => Promise<{
5
+ readonly result: Promise<Result>;
6
+ }>;
7
+ }
8
+ export declare class ToolScheduler<Result> {
9
+ private readonly activeTasks;
10
+ private queuedTasks;
11
+ add(task: ToolCallTask<Result>): Promise<Result>;
12
+ private isBlocked;
13
+ private conflictsWithAny;
14
+ private start;
15
+ private finish;
16
+ private startQueuedTasks;
17
+ }
18
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1,71 @@
1
+ import { ToolAccesses } from "../tool/access.js";
2
+ function createControlledPromise() {
3
+ let resolve;
4
+ let reject;
5
+ const promise = new Promise((res, rej) => {
6
+ resolve = res;
7
+ reject = rej;
8
+ });
9
+ promise.resolve = resolve;
10
+ promise.reject = reject;
11
+ return promise;
12
+ }
13
+ export class ToolScheduler {
14
+ activeTasks = [];
15
+ queuedTasks = [];
16
+ add(task) {
17
+ const result = createControlledPromise();
18
+ void result.catch(() => undefined);
19
+ const scheduledTask = { ...task, result };
20
+ if (this.isBlocked(task, this.queuedTasks)) {
21
+ this.queuedTasks.push(scheduledTask);
22
+ }
23
+ else {
24
+ this.start(scheduledTask);
25
+ }
26
+ return result;
27
+ }
28
+ isBlocked(task, queuedBefore) {
29
+ return this.conflictsWithAny(task, this.activeTasks) || this.conflictsWithAny(task, queuedBefore);
30
+ }
31
+ conflictsWithAny(task, candidates) {
32
+ return candidates.some((candidate) => ToolAccesses.conflict(task.accesses, candidate.accesses));
33
+ }
34
+ start(task) {
35
+ this.activeTasks.push(task);
36
+ let started;
37
+ try {
38
+ started = task.start();
39
+ }
40
+ catch (error) {
41
+ task.result.reject(error);
42
+ this.finish(task);
43
+ return;
44
+ }
45
+ void started
46
+ .then(({ result }) => result)
47
+ .then(task.result.resolve, task.result.reject)
48
+ .finally(() => {
49
+ this.finish(task);
50
+ });
51
+ }
52
+ finish(task) {
53
+ const index = this.activeTasks.indexOf(task);
54
+ if (index >= 0)
55
+ this.activeTasks.splice(index, 1);
56
+ this.startQueuedTasks();
57
+ }
58
+ startQueuedTasks() {
59
+ const stillQueued = [];
60
+ for (const task of this.queuedTasks) {
61
+ if (this.isBlocked(task, stillQueued)) {
62
+ stillQueued.push(task);
63
+ }
64
+ else {
65
+ this.start(task);
66
+ }
67
+ }
68
+ this.queuedTasks = stillQueued;
69
+ }
70
+ }
71
+ //# sourceMappingURL=scheduler.js.map