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,56 @@
1
+ import type { SessionStore } from "../store/index.ts";
2
+ export type SubagentStatus = "running" | "completed" | "error" | "paused" | "cancelled" | "lost";
3
+ /** One spawned background subagent, projected from its task-store record: `agentId` names the
4
+ * instance, `address` is its journal shard, `type` is the agent definition to re-run on resume. */
5
+ export interface SubagentRecord {
6
+ readonly agentId: string;
7
+ readonly type: string;
8
+ readonly address: string;
9
+ readonly description?: string;
10
+ readonly background: boolean;
11
+ /** The background task handle. */
12
+ readonly taskId?: string;
13
+ readonly createdAt: number;
14
+ status: SubagentStatus;
15
+ updatedAt: number;
16
+ }
17
+ /** The structured `details` an Agent tool result carries in the conversation — the human/model
18
+ * facing spawn record. Subagent lifecycle state itself now lives in the task store, not a fold. */
19
+ export interface AgentSpawnDetails {
20
+ readonly agentId: string;
21
+ readonly type: string;
22
+ readonly status: SubagentStatus;
23
+ readonly background?: boolean;
24
+ readonly description?: string;
25
+ readonly taskId?: string;
26
+ readonly usage?: unknown;
27
+ }
28
+ /** A unique per-spawn id so two spawns of the same type get separate shards (and resume). */
29
+ export declare function newAgentId(type: string): string;
30
+ /**
31
+ * Why a caller-chosen agent name is checked rather than sanitized: the name becomes the id
32
+ * teammates address and `resume` looks up, so quietly rewriting it would leave the caller
33
+ * holding a name that reaches nobody. `/` is barred because ids are address segments.
34
+ *
35
+ * Returns the reason it is unusable, or `undefined` when it is fine.
36
+ */
37
+ export declare function invalidAgentName(name: string): string | undefined;
38
+ /**
39
+ * Audit-only meta record written to a subagent's own shard at spawn.
40
+ *
41
+ * This is what makes a shard self-describing: its agent type is recoverable from the shard
42
+ * itself, with no fold over the parent conversation and no live registry. That is the whole
43
+ * reason an agent at `main/<id>` can be started again by anyone holding the store — its
44
+ * parent frame does not have to exist, let alone be running.
45
+ */
46
+ export declare const SUBAGENT_META = "subagent_meta";
47
+ export interface SubagentMeta {
48
+ readonly agentId: string;
49
+ readonly type: string;
50
+ readonly description?: string;
51
+ readonly background: boolean;
52
+ readonly parentAddress?: string;
53
+ readonly parentToolCallId?: string;
54
+ }
55
+ export declare function readSubagentMeta(store: SessionStore, address: string): Promise<SubagentMeta | undefined>;
56
+ //# sourceMappingURL=subagent.d.ts.map
@@ -0,0 +1,50 @@
1
+ import { randomBytes } from "node:crypto";
2
+ /** A unique per-spawn id so two spawns of the same type get separate shards (and resume). */
3
+ export function newAgentId(type) {
4
+ const safe = type.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "agent";
5
+ return `${safe}-${randomBytes(4).toString("hex")}`;
6
+ }
7
+ /**
8
+ * Why a caller-chosen agent name is checked rather than sanitized: the name becomes the id
9
+ * teammates address and `resume` looks up, so quietly rewriting it would leave the caller
10
+ * holding a name that reaches nobody. `/` is barred because ids are address segments.
11
+ *
12
+ * Returns the reason it is unusable, or `undefined` when it is fine.
13
+ */
14
+ export function invalidAgentName(name) {
15
+ if (name.length > 64)
16
+ return `Agent name "${name}" is too long (max 64 characters).`;
17
+ if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
18
+ return `Agent name "${name}" may only contain letters, digits, "_" and "-" — it is used as an address segment and as the id peers address you by.`;
19
+ }
20
+ return undefined;
21
+ }
22
+ // ── Subagent meta (address-keyed identity) ───────────────────────────────────────────────
23
+ /**
24
+ * Audit-only meta record written to a subagent's own shard at spawn.
25
+ *
26
+ * This is what makes a shard self-describing: its agent type is recoverable from the shard
27
+ * itself, with no fold over the parent conversation and no live registry. That is the whole
28
+ * reason an agent at `main/<id>` can be started again by anyone holding the store — its
29
+ * parent frame does not have to exist, let alone be running.
30
+ */
31
+ export const SUBAGENT_META = "subagent_meta";
32
+ export async function readSubagentMeta(store, address) {
33
+ for await (const record of store.readRecords({ address })) {
34
+ if (record.type !== "custom" || record.name !== SUBAGENT_META)
35
+ continue;
36
+ const data = record.data;
37
+ if (data !== undefined && typeof data.type === "string" && typeof data.agentId === "string") {
38
+ return {
39
+ agentId: data.agentId,
40
+ type: data.type,
41
+ description: data.description,
42
+ background: data.background === true,
43
+ parentAddress: data.parentAddress,
44
+ parentToolCallId: data.parentToolCallId,
45
+ };
46
+ }
47
+ }
48
+ return undefined;
49
+ }
50
+ //# sourceMappingURL=subagent.js.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Per-turn toolset assembly — extracted from the Engine. Builds the active agent's tool
3
+ * list (own tools ∪ capability tools ∪ handoff tools ∪ subagent-spawning tools) and the
4
+ * `SubagentSpawner` seam those spawn tools share. The engine's run loop is injected as a
5
+ * plain callback (`runAgent`), so only TYPES are imported from `runner.ts` and no
6
+ * value-level cycle exists.
7
+ */
8
+ import type { Tool } from "../tool/types.ts";
9
+ import type { ChatModel } from "../llm/define-model.ts";
10
+ import type { Agent } from "./agent.ts";
11
+ import type { RunState, SubagentSpawner } from "./runner.ts";
12
+ /** The engine call a spawner runs child agents through (`Engine.run`, injected). */
13
+ export type RunAgentFn<TContext> = SubagentSpawner<TContext>["run"];
14
+ /**
15
+ * The execution registry stays complete so a newly loaded schema can become
16
+ * callable on the next step without rebuilding capability connections. The
17
+ * deferred-name set controls only the model-facing projection.
18
+ */
19
+ export interface RunToolset {
20
+ readonly tools: readonly Tool[];
21
+ readonly deferredToolNames: ReadonlySet<string>;
22
+ }
23
+ export declare function buildRunTools<TContext>(active: Agent<TContext>, state: RunState<TContext>, runAgent: RunAgentFn<TContext>, model: ChatModel): Promise<RunToolset>;
24
+ //# sourceMappingURL=toolset.d.ts.map
@@ -0,0 +1,112 @@
1
+ import { buildWorkflowTool } from "./workflow/tool.js";
2
+ import { buildSubagentTool, buildAgentTool } from "./subagent-tools.js";
3
+ import { buildSearchTool } from "../tool/search/search-tool.js";
4
+ import { findAgentByName } from "./graph.js";
5
+ import { deriveChild, emitRunEvent, runCtxFor } from "./run-support.js";
6
+ import { toolSource } from "../capabilities/tool-provider.js";
7
+ export async function buildRunTools(active, state, runAgent, model) {
8
+ // Capability (MCP) tools are the deferred-loading candidates. When the agent
9
+ // opts in, they stay executable but are omitted from the model-facing schema
10
+ // projection until a SearchTool result adds their names to the transcript.
11
+ const rawCapTools = await state.capabilities.listTools();
12
+ // A tagged (dynamically contributed) tool loses a name clash and says so; untagged tools are
13
+ // trusted contributors and keep theirs. Between two tagged claimants the first one survives,
14
+ // so a clash never makes the name vanish entirely. See `tagToolSource`.
15
+ const untaggedNames = new Set([...active.tools, ...rawCapTools.filter((tool) => toolSource(tool) === undefined)].map((tool) => tool.schema.name));
16
+ const claimed = new Set();
17
+ const capTools = rawCapTools.filter((tool) => {
18
+ const source = toolSource(tool);
19
+ if (source === undefined)
20
+ return true;
21
+ const name = tool.schema.name;
22
+ if (!untaggedNames.has(name) && !claimed.has(name)) {
23
+ claimed.add(name);
24
+ return true;
25
+ }
26
+ emitRunEvent(state, {
27
+ type: "warning",
28
+ message: `Tool provider "${source}" tool "${name}" collides with an existing tool and was omitted.`,
29
+ });
30
+ return false;
31
+ });
32
+ const deferEnabled = active.deferTools === true && capTools.length > 0 && model.supportsDeferredTools;
33
+ const deferredToolNames = new Set(deferEnabled ? capTools.map((tool) => tool.schema.name) : []);
34
+ const tools = [...active.tools, ...capTools];
35
+ if (deferEnabled)
36
+ tools.push(buildSearchTool(capTools.map((t) => t.schema)));
37
+ for (const h of active.handoffs)
38
+ tools.push(h.asTool());
39
+ // Subagent types come from the agent's static `subagents` plus any runtime provider
40
+ // (e.g. profile-loaded agents). The unified "Agent" tool spawns/resumes by type.
41
+ const providerAgents = state.subagentProvider !== undefined ? [...(await state.subagentProvider.list())] : [];
42
+ if (active.subagents.length === 0 && providerAgents.length === 0) {
43
+ return finish(state, tools, deferredToolNames);
44
+ }
45
+ // One spawner (the engine seam) shared by every subagent-spawning tool: the static
46
+ // `agent_<name>` tools, the unified `Agent` tool, and `Workflow`.
47
+ const spawner = makeSpawner(active, state, providerAgents, runAgent);
48
+ for (const sub of active.subagents)
49
+ tools.push(buildSubagentTool(sub, spawner, state));
50
+ if (!tools.some((tool) => tool.schema.name === "Agent")) {
51
+ tools.push(buildAgentTool(spawner, state));
52
+ }
53
+ // `workflowTool: false` withholds only this one — subagents and the `Agent`
54
+ // tool above stay, for a host that brings its own workflow orchestration.
55
+ if (state.workflowTool !== false && !tools.some((tool) => tool.schema.name === "Workflow")) {
56
+ tools.push(buildWorkflowTool(spawner, state));
57
+ }
58
+ return finish(state, tools, deferredToolNames);
59
+ }
60
+ /**
61
+ * Last stop before the turn: let capabilities narrow the complete registry (the extension
62
+ * runtime's `setActiveTools` rides this). Filtering happens AFTER assembly so a filter sees
63
+ * handoff and subagent tools too, and the deferred-name set is pruned to whatever survived.
64
+ */
65
+ function finish(state, tools, deferredToolNames) {
66
+ const filtered = state.capabilities.applyToolFilters(tools);
67
+ if (filtered === tools)
68
+ return { tools, deferredToolNames };
69
+ const surviving = new Set(filtered.map((tool) => tool.schema.name));
70
+ return {
71
+ tools: filtered,
72
+ deferredToolNames: new Set([...deferredToolNames].filter((name) => surviving.has(name))),
73
+ };
74
+ }
75
+ /**
76
+ * Build the `SubagentSpawner` for `active`: the available types (static subagents ∪
77
+ * provider agents), their resolver, and the engine handles (`derive` = fork a child
78
+ * runtime, `run` = the loop). This is what lets a tool run an agent without reaching
79
+ * into the Runner.
80
+ */
81
+ /** Run frames already warned about provider agents shadowed by static subagents — the
82
+ * toolset is rebuilt every turn, so without this the same warning would repeat per turn. */
83
+ const shadowWarned = new WeakSet();
84
+ function makeSpawner(active, parent, providerAgents, runAgent) {
85
+ const subagents = active.subagents;
86
+ // Available types = static subagents ∪ provider (profile) agents; static wins on name clash.
87
+ const shadowed = providerAgents.filter((p) => subagents.some((sub) => sub.name === p.name));
88
+ if (shadowed.length > 0 && !shadowWarned.has(parent)) {
89
+ shadowWarned.add(parent);
90
+ // Silent dedupe reads as "my profile agent just doesn't load" — say who won and why.
91
+ emitRunEvent(parent, {
92
+ type: "warning",
93
+ message: `Runtime-provided subagent type(s) ${shadowed.map((p) => `"${p.name}"`).join(", ")} are shadowed by agent "${active.name}"'s static subagents of the same name; the static definitions win.`,
94
+ });
95
+ }
96
+ const available = [
97
+ ...subagents.map((sub) => ({ name: sub.name, description: sub.handoffDescription })),
98
+ ...providerAgents.filter((p) => !subagents.some((sub) => sub.name === p.name)),
99
+ ];
100
+ const defaultType = available.find((a) => a.name === "coder")?.name ?? available[0]?.name ?? subagents[0]?.name ?? "";
101
+ return {
102
+ available,
103
+ defaultType,
104
+ // Resolve a type to an Agent: prefer the static graph, then the runtime provider.
105
+ resolve: async (type) => subagents.find((sub) => sub.name === type) ?? (await parent.subagentProvider?.get(type)),
106
+ resolveInGraph: (root, key) => findAgentByName(root, key),
107
+ derive: (opts) => deriveChild(parent, opts),
108
+ run: runAgent,
109
+ ctxFor: (childState) => runCtxFor(childState),
110
+ };
111
+ }
112
+ //# sourceMappingURL=toolset.js.map
@@ -0,0 +1,9 @@
1
+ export * from "./types.ts";
2
+ export { parseWorkflow, type ParseResult } from "./parse.ts";
3
+ export { WorkflowJournal, journalAddress, type JournalResult, type JournalEvent, type JournalAgentLabel } from "./journal.ts";
4
+ export type { WorkflowSnapshot, WorkflowSnapshotStatus, WorkflowRunDetails } from "./snapshot.ts";
5
+ export { WorkflowManager } from "./manager.ts";
6
+ export { runWorkflow, type RunWorkflowResult, WorkflowAgentCapError, WorkflowBudgetExceededError, WorkflowAbortedError, } from "./runtime.ts";
7
+ export { workflowPrompt } from "./prompt.ts";
8
+ export { makeStructuredOutputTool, cloneAgentWithTool, validateValue, structuredInstruction, getValidator, type StructuredCapture, } from "./structured.ts";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ export * from "./types.js";
2
+ export { parseWorkflow } from "./parse.js";
3
+ export { WorkflowJournal, journalAddress } from "./journal.js";
4
+ export { WorkflowManager } from "./manager.js";
5
+ export { runWorkflow, WorkflowAgentCapError, WorkflowBudgetExceededError, WorkflowAbortedError, } from "./runtime.js";
6
+ export { workflowPrompt } from "./prompt.js";
7
+ export { makeStructuredOutputTool, cloneAgentWithTool, validateValue, structuredInstruction, getValidator, } from "./structured.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Workflow journal — enables `resumeFromRunId`. Each agent() call is
3
+ * keyed by a SHA-256 CHAIN over (previous key + prompt + stable-stringified opts),
4
+ * rolled in execution order. Because the key is chained, changing or inserting any
5
+ * call shifts every key after it, which (together with the runtime's `diverged`
6
+ * latch) gives "longest-unchanged-prefix" resume: the leading run of unchanged
7
+ * calls returns cached instantly, and everything from the first change onward
8
+ * re-runs.
9
+ *
10
+ * Two entry kinds are journaled per call:
11
+ * - `started` is appended BEFORE the agent runs (with its agentId), so an
12
+ * interruption leaves a started-without-result trail the next resume detects
13
+ * and respawns;
14
+ * - `result` is appended after it completes.
15
+ *
16
+ * This is exactly why the sandbox forbids Date.now()/Math.random(): non-determinism
17
+ * would change the prompts/order (and thus the keys) and defeat resume.
18
+ *
19
+ * Persistence is the SessionStore's append log under a per-run address
20
+ * (`workflow:<runId>`): the journal is agent bookkeeping shaped exactly like the
21
+ * log facet — crash-safe appends, replayed whole on load — so it never touches
22
+ * the Machine or the host filesystem. `custom` entries are audit-only and
23
+ * are never folded into a conversation.
24
+ */
25
+ import type { SessionStore } from "../../store/index.ts";
26
+ import type { AgentHookOptions } from "./types.ts";
27
+ /**
28
+ * What a run writes down. Two audiences read these, which is why the shape carries more than
29
+ * resume strictly needs:
30
+ *
31
+ * - RESUME reads `started` / `result` by key, exactly as before.
32
+ * - EVERYONE ELSE (the model via BackgroundOutput, a UI seeding its progress view, someone
33
+ * asking why a run came back empty) reads them in append order as the run's story. That
34
+ * audience needs the labels a human recognises, the phases the script declared, its own
35
+ * narration, and — most of all — the failures, which used to be emitted to a live progress
36
+ * stream and then forgotten.
37
+ *
38
+ * `run` and `outcome` bracket the sequence: the inputs the run was given, and what it
39
+ * produced. With both present the address is self-contained — the script that ran, the args
40
+ * it ran on, every agent result, and the payload — so a run can be replayed, inspected, or
41
+ * served long after the process that ran it is gone.
42
+ */
43
+ type JournalEntry = ({
44
+ type: "run";
45
+ runId: string;
46
+ name: string;
47
+ args?: unknown;
48
+ scriptBody: string;
49
+ parentAddress?: string;
50
+ } | {
51
+ type: "phase";
52
+ index: number;
53
+ title: string;
54
+ kind: "normal" | "child";
55
+ } | {
56
+ type: "queued";
57
+ key: string;
58
+ index: number;
59
+ label: string;
60
+ phase?: string;
61
+ } | {
62
+ type: "started";
63
+ key: string;
64
+ agentId: string;
65
+ address?: string;
66
+ index?: number;
67
+ label?: string;
68
+ phase?: string;
69
+ } | {
70
+ type: "result";
71
+ key: string;
72
+ agentId: string;
73
+ address?: string;
74
+ result?: unknown;
75
+ index?: number;
76
+ label?: string;
77
+ phase?: string;
78
+ } | {
79
+ type: "error";
80
+ key: string;
81
+ agentId: string;
82
+ address?: string;
83
+ error: string;
84
+ index?: number;
85
+ label?: string;
86
+ phase?: string;
87
+ } | {
88
+ type: "log";
89
+ message: string;
90
+ } | {
91
+ type: "outcome";
92
+ status: "completed" | "failed" | "aborted";
93
+ ok: boolean;
94
+ result?: unknown;
95
+ error?: string;
96
+ failures: string[];
97
+ agentCount: number;
98
+ }) & {
99
+ readonly parentToolCallId?: string;
100
+ };
101
+ /** An entry as read back, with the append time the store stamped on its record. */
102
+ export type JournalEvent = JournalEntry & {
103
+ readonly time?: number;
104
+ };
105
+ export interface JournalResult {
106
+ readonly agentId: string;
107
+ readonly address?: string;
108
+ readonly result: unknown;
109
+ }
110
+ /** Identity of the agent() call an entry belongs to; omitted on `run`/`phase`/`log`/`outcome`. */
111
+ export interface JournalAgentLabel {
112
+ readonly index?: number;
113
+ readonly label?: string;
114
+ readonly phase?: string;
115
+ /** Conversation shard of the concrete child run, for replay-time stream correlation. */
116
+ readonly address?: string;
117
+ }
118
+ export declare const JOURNAL_KEY_VERSION = "v2";
119
+ /** The per-run log address journal entries live under. */
120
+ export declare function journalAddress(runId: string): string;
121
+ export declare class WorkflowJournal {
122
+ private readonly store;
123
+ private readonly address;
124
+ private readonly runId;
125
+ private readonly parentToolCallId?;
126
+ /** key → completed result (loaded on resume). */
127
+ private readonly results;
128
+ /** keys that were `started` on a prior run (used to detect interrupted agents). */
129
+ private readonly started;
130
+ /** Every entry in append order — the run's story, for readers that want it whole. */
131
+ private readonly events;
132
+ constructor(runId: string, store: SessionStore, parentToolCallId?: string);
133
+ /** Chained key for an agent() call: hash(prevKey + prompt + opts). */
134
+ keyFor(prevKey: string, prompt: string, opts: AgentHookOptions | undefined): string;
135
+ /** Load prior records (no-op for a fresh run). */
136
+ load(): Promise<void>;
137
+ /** A completed result for this key, or undefined (never ran, or interrupted). */
138
+ getResult(key: string): JournalResult | undefined;
139
+ /** Whether this key was `started` on a prior run (interrupted if also no result). */
140
+ wasStarted(key: string): boolean;
141
+ /** Every entry in append order, including any loaded from a prior process. */
142
+ readEvents(): readonly JournalEvent[];
143
+ /** The exact source this run was launched with (meta block included), when recorded. */
144
+ recordedScript(): string | undefined;
145
+ /** The run's own outcome, once written. */
146
+ outcome(): Extract<JournalEvent, {
147
+ type: "outcome";
148
+ }> | undefined;
149
+ /**
150
+ * The inputs, written before anything runs. `scriptBody` here is the SOURCE as given — meta
151
+ * block included — because a resume re-parses it, and `parseWorkflow` strips that block off.
152
+ *
153
+ * Carries the script in full rather than a path:
154
+ * a path points at the machine, which is a cache — the file can be edited, overwritten by
155
+ * the next run of the same workflow, or vanish with a sandbox. Replay needs the exact bytes
156
+ * that produced these keys, so the record holds them.
157
+ */
158
+ recordRun(name: string, scriptBody: string, args: unknown, origin?: {
159
+ readonly parentAddress: string;
160
+ readonly parentToolCallId: string;
161
+ }): Promise<void>;
162
+ recordPhase(index: number, title: string, kind: "normal" | "child"): Promise<void>;
163
+ recordQueued(key: string, label: JournalAgentLabel & {
164
+ readonly index: number;
165
+ readonly label: string;
166
+ }): Promise<void>;
167
+ recordStarted(key: string, agentId: string, label?: JournalAgentLabel): Promise<void>;
168
+ recordResult(key: string, agentId: string, result: unknown, label?: JournalAgentLabel): Promise<void>;
169
+ /** A failed agent. Never recorded before, so a failed run left no trace of WHICH step broke
170
+ * — the one question anyone asks of a run that came back empty. */
171
+ recordError(key: string, agentId: string, error: string, label?: JournalAgentLabel): Promise<void>;
172
+ /** The script's own narration (`log()`), which exists nowhere else. */
173
+ recordLog(message: string): Promise<void>;
174
+ recordOutcome(entry: Omit<Extract<JournalEntry, {
175
+ type: "outcome";
176
+ }>, "type">): Promise<void>;
177
+ private append;
178
+ }
179
+ export {};
180
+ //# sourceMappingURL=journal.d.ts.map
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Workflow journal — enables `resumeFromRunId`. Each agent() call is
3
+ * keyed by a SHA-256 CHAIN over (previous key + prompt + stable-stringified opts),
4
+ * rolled in execution order. Because the key is chained, changing or inserting any
5
+ * call shifts every key after it, which (together with the runtime's `diverged`
6
+ * latch) gives "longest-unchanged-prefix" resume: the leading run of unchanged
7
+ * calls returns cached instantly, and everything from the first change onward
8
+ * re-runs.
9
+ *
10
+ * Two entry kinds are journaled per call:
11
+ * - `started` is appended BEFORE the agent runs (with its agentId), so an
12
+ * interruption leaves a started-without-result trail the next resume detects
13
+ * and respawns;
14
+ * - `result` is appended after it completes.
15
+ *
16
+ * This is exactly why the sandbox forbids Date.now()/Math.random(): non-determinism
17
+ * would change the prompts/order (and thus the keys) and defeat resume.
18
+ *
19
+ * Persistence is the SessionStore's append log under a per-run address
20
+ * (`workflow:<runId>`): the journal is agent bookkeeping shaped exactly like the
21
+ * log facet — crash-safe appends, replayed whole on load — so it never touches
22
+ * the Machine or the host filesystem. `custom` entries are audit-only and
23
+ * are never folded into a conversation.
24
+ */
25
+ import { createHash } from "node:crypto";
26
+ export const JOURNAL_KEY_VERSION = "v2";
27
+ const JOURNAL_ENTRY_NAME = "wf_journal";
28
+ function sanitize(id) {
29
+ return id.replace(/[^a-zA-Z0-9_-]/g, "_");
30
+ }
31
+ /** The per-run log address journal entries live under. */
32
+ export function journalAddress(runId) {
33
+ return `workflow:${sanitize(runId)}`;
34
+ }
35
+ /** Stable stringify of the opts that affect an agent's result. */
36
+ function stableOpts(opts) {
37
+ if (!opts)
38
+ return "{}";
39
+ const picked = {};
40
+ for (const key of ["schema", "model", "agentType", "isolation"]) {
41
+ const v = opts[key];
42
+ if (v === undefined || typeof v === "function")
43
+ continue;
44
+ picked[key] = v;
45
+ }
46
+ const sortDeep = (val) => {
47
+ if (Array.isArray(val))
48
+ return val.map(sortDeep);
49
+ if (val && typeof val === "object") {
50
+ const out = {};
51
+ for (const k of Object.keys(val).sort()) {
52
+ out[k] = sortDeep(val[k]);
53
+ }
54
+ return out;
55
+ }
56
+ return val;
57
+ };
58
+ return JSON.stringify(sortDeep(picked));
59
+ }
60
+ const ENTRY_TYPES = new Set(["run", "phase", "queued", "started", "result", "error", "log", "outcome"]);
61
+ /** Validate an untrusted record: older wire versions wrote only `started`/`result`, and a
62
+ * reader must skip anything it does not recognise rather than fail the whole load. */
63
+ function isJournalEntry(value) {
64
+ if (typeof value !== "object" || value === null)
65
+ return false;
66
+ const o = value;
67
+ const type = o["type"];
68
+ if (typeof type !== "string" || !ENTRY_TYPES.has(type))
69
+ return false;
70
+ if (type === "started" || type === "result" || type === "error") {
71
+ return typeof o["key"] === "string" && typeof o["agentId"] === "string";
72
+ }
73
+ if (type === "queued")
74
+ return typeof o["key"] === "string" && typeof o["index"] === "number";
75
+ if (type === "run")
76
+ return typeof o["name"] === "string" && typeof o["scriptBody"] === "string";
77
+ if (type === "phase")
78
+ return typeof o["title"] === "string";
79
+ if (type === "log")
80
+ return typeof o["message"] === "string";
81
+ return (typeof o["ok"] === "boolean" &&
82
+ (o["status"] === "completed" || o["status"] === "failed" || o["status"] === "aborted"));
83
+ }
84
+ export class WorkflowJournal {
85
+ store;
86
+ address;
87
+ runId;
88
+ parentToolCallId;
89
+ /** key → completed result (loaded on resume). */
90
+ results = new Map();
91
+ /** keys that were `started` on a prior run (used to detect interrupted agents). */
92
+ started = new Set();
93
+ /** Every entry in append order — the run's story, for readers that want it whole. */
94
+ events = [];
95
+ constructor(runId, store, parentToolCallId) {
96
+ this.store = store;
97
+ this.runId = runId;
98
+ this.parentToolCallId = parentToolCallId;
99
+ this.address = journalAddress(runId);
100
+ }
101
+ /** Chained key for an agent() call: hash(prevKey + prompt + opts). */
102
+ keyFor(prevKey, prompt, opts) {
103
+ const hash = createHash("sha256")
104
+ .update(prevKey)
105
+ .update("\0")
106
+ .update(prompt)
107
+ .update("\0")
108
+ .update(stableOpts(opts))
109
+ .digest("hex");
110
+ return `${JOURNAL_KEY_VERSION}:${hash}`;
111
+ }
112
+ /** Load prior records (no-op for a fresh run). */
113
+ async load() {
114
+ try {
115
+ for await (const stored of this.store.readRecords({ address: this.address })) {
116
+ if (stored.type !== "custom" || stored.name !== JOURNAL_ENTRY_NAME)
117
+ continue;
118
+ const entry = stored.data;
119
+ if (!isJournalEntry(entry))
120
+ continue;
121
+ this.events.push(stored.time === undefined ? entry : { ...entry, time: stored.time });
122
+ if (entry.type === "started")
123
+ this.started.add(entry.key);
124
+ else if (entry.type === "result") {
125
+ this.results.set(entry.key, {
126
+ agentId: entry.agentId,
127
+ ...(entry.address !== undefined ? { address: entry.address } : {}),
128
+ result: entry.result,
129
+ });
130
+ }
131
+ }
132
+ }
133
+ catch {
134
+ return;
135
+ }
136
+ }
137
+ /** A completed result for this key, or undefined (never ran, or interrupted). */
138
+ getResult(key) {
139
+ return this.results.get(key);
140
+ }
141
+ /** Whether this key was `started` on a prior run (interrupted if also no result). */
142
+ wasStarted(key) {
143
+ return this.started.has(key);
144
+ }
145
+ /** Every entry in append order, including any loaded from a prior process. */
146
+ readEvents() {
147
+ return this.events;
148
+ }
149
+ /** The exact source this run was launched with (meta block included), when recorded. */
150
+ recordedScript() {
151
+ for (const event of this.events)
152
+ if (event.type === "run")
153
+ return event.scriptBody;
154
+ return undefined;
155
+ }
156
+ /** The run's own outcome, once written. */
157
+ outcome() {
158
+ for (let i = this.events.length - 1; i >= 0; i--) {
159
+ const event = this.events[i];
160
+ if (event?.type === "outcome")
161
+ return event;
162
+ }
163
+ return undefined;
164
+ }
165
+ /**
166
+ * The inputs, written before anything runs. `scriptBody` here is the SOURCE as given — meta
167
+ * block included — because a resume re-parses it, and `parseWorkflow` strips that block off.
168
+ *
169
+ * Carries the script in full rather than a path:
170
+ * a path points at the machine, which is a cache — the file can be edited, overwritten by
171
+ * the next run of the same workflow, or vanish with a sandbox. Replay needs the exact bytes
172
+ * that produced these keys, so the record holds them.
173
+ */
174
+ async recordRun(name, scriptBody, args, origin) {
175
+ await this.append({
176
+ type: "run",
177
+ runId: this.runId,
178
+ name,
179
+ scriptBody,
180
+ ...(args === undefined ? {} : { args }),
181
+ ...origin,
182
+ }).catch(() => { });
183
+ }
184
+ async recordPhase(index, title, kind) {
185
+ await this.append({ type: "phase", index, title, kind }).catch(() => { });
186
+ }
187
+ async recordQueued(key, label) {
188
+ await this.append({ type: "queued", key, ...label }).catch(() => { });
189
+ }
190
+ async recordStarted(key, agentId, label = {}) {
191
+ this.started.add(key);
192
+ await this.append({ type: "started", key, agentId, ...label }).catch(() => { });
193
+ }
194
+ async recordResult(key, agentId, result, label = {}) {
195
+ this.results.set(key, { agentId, ...(label.address !== undefined ? { address: label.address } : {}), result });
196
+ await this.append({ type: "result", key, agentId, result, ...label });
197
+ }
198
+ /** A failed agent. Never recorded before, so a failed run left no trace of WHICH step broke
199
+ * — the one question anyone asks of a run that came back empty. */
200
+ async recordError(key, agentId, error, label = {}) {
201
+ await this.append({ type: "error", key, agentId, error, ...label }).catch(() => { });
202
+ }
203
+ /** The script's own narration (`log()`), which exists nowhere else. */
204
+ async recordLog(message) {
205
+ await this.append({ type: "log", message }).catch(() => { });
206
+ }
207
+ async recordOutcome(entry) {
208
+ await this.append({ type: "outcome", ...entry }).catch(() => { });
209
+ }
210
+ async append(entry) {
211
+ const identified = this.parentToolCallId === undefined || entry.parentToolCallId !== undefined
212
+ ? entry
213
+ : { ...entry, parentToolCallId: this.parentToolCallId };
214
+ this.events.push(identified);
215
+ const record = {
216
+ address: this.address,
217
+ type: "custom",
218
+ name: JOURNAL_ENTRY_NAME,
219
+ data: identified,
220
+ };
221
+ await this.store.appendRecord(record);
222
+ }
223
+ }
224
+ //# sourceMappingURL=journal.js.map