@bastani/atomic 0.9.20-alpha.3 → 0.9.20-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (930) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/README.md +15 -7
  3. package/dist/builtin/intercom/CHANGELOG.md +24 -0
  4. package/dist/builtin/intercom/README.md +2 -2
  5. package/dist/builtin/intercom/broker/send-handler.ts +59 -2
  6. package/dist/builtin/intercom/index.bundle.mjs +101 -16
  7. package/dist/builtin/intercom/package.json +3 -3
  8. package/dist/builtin/intercom/session-target.ts +34 -9
  9. package/dist/builtin/intercom/skills/intercom/SKILL.md +36 -5
  10. package/dist/builtin/mcp/CHANGELOG.md +13 -0
  11. package/dist/builtin/mcp/OAUTH.md +1 -1
  12. package/dist/builtin/mcp/README.md +3 -1
  13. package/dist/builtin/mcp/index.bundle.mjs +412 -64
  14. package/dist/builtin/mcp/package.json +3 -3
  15. package/dist/builtin/subagents/CHANGELOG.md +39 -0
  16. package/dist/builtin/subagents/README.md +4 -2
  17. package/dist/builtin/subagents/agents/code-simplifier.md +3 -4
  18. package/dist/builtin/subagents/agents/codebase-analyzer.md +3 -4
  19. package/dist/builtin/subagents/agents/codebase-locator.md +2 -3
  20. package/dist/builtin/subagents/agents/codebase-online-researcher.md +5 -6
  21. package/dist/builtin/subagents/agents/codebase-pattern-finder.md +2 -3
  22. package/dist/builtin/subagents/agents/codebase-research-analyzer.md +2 -3
  23. package/dist/builtin/subagents/agents/codebase-research-locator.md +2 -3
  24. package/dist/builtin/subagents/agents/debugger.md +8 -7
  25. package/dist/builtin/subagents/agents/worker.md +5 -4
  26. package/dist/builtin/subagents/package.json +4 -8
  27. package/dist/builtin/subagents/skills/agent-browser/SKILL.md +56 -0
  28. package/dist/builtin/subagents/skills/subagent/SKILL.md +45 -19
  29. package/dist/builtin/subagents/src/extension/index.bundle.mjs +255 -66
  30. package/dist/builtin/web-access/CHANGELOG.md +12 -0
  31. package/dist/builtin/web-access/index.bundle.mjs +367 -295
  32. package/dist/builtin/web-access/package.json +3 -3
  33. package/dist/builtin/workflows/CHANGELOG.md +98 -0
  34. package/dist/builtin/workflows/README.md +33 -32
  35. package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
  36. package/dist/builtin/workflows/builtin/{chunk-xtxcq5tj.js → chunk-00ywx588.js} +17 -1
  37. package/dist/builtin/workflows/builtin/{chunk-z29qbehr.js → chunk-55p5dxjk.js} +4 -6
  38. package/dist/builtin/workflows/builtin/chunk-7f381xnq.js +9760 -0
  39. package/dist/builtin/workflows/builtin/{chunk-wf741bv3.js → chunk-7h7s5xdj.js} +4 -6
  40. package/dist/builtin/workflows/builtin/{chunk-a2kdsqn8.js → chunk-e83tc6nr.js} +2 -2
  41. package/dist/builtin/workflows/builtin/{chunk-6w6cvk6b.js → chunk-evfb0312.js} +4 -6
  42. package/dist/builtin/workflows/builtin/{chunk-fg9esgkj.js → chunk-ne6vh5ct.js} +4 -6
  43. package/dist/builtin/workflows/builtin/{chunk-yeee2jrc.js → chunk-pfm1kgqz.js} +66 -88
  44. package/dist/builtin/workflows/builtin/{chunk-zqtm1d2c.js → chunk-tdqvdrg1.js} +13 -218
  45. package/dist/builtin/workflows/builtin/{chunk-g0csgs7w.js → chunk-tvcydq13.js} +8 -10
  46. package/dist/builtin/workflows/builtin/{chunk-31j2gs7h.js → chunk-x2nftpgj.js} +4 -6
  47. package/dist/builtin/workflows/builtin/{chunk-ewkkkbak.js → chunk-zj5162bh.js} +10 -92
  48. package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
  49. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
  50. package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
  51. package/dist/builtin/workflows/builtin/goal.js +4 -4
  52. package/dist/builtin/workflows/builtin/index.d.ts +1 -1
  53. package/dist/builtin/workflows/builtin/index.js +12 -12
  54. package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
  55. package/dist/builtin/workflows/builtin/open-claude-design.d.ts +1 -1
  56. package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
  57. package/dist/builtin/workflows/builtin/ralph.js +4 -4
  58. package/dist/builtin/workflows/builtin/steering-context.js +1 -1
  59. package/dist/builtin/workflows/builtin/tournament.js +3 -3
  60. package/dist/builtin/workflows/package.json +3 -3
  61. package/dist/builtin/workflows/skills/impeccable/SKILL.md +18 -11
  62. package/dist/builtin/workflows/skills/impeccable/reference/adapt.md +1 -1
  63. package/dist/builtin/workflows/skills/impeccable/reference/adapt.native.md +1 -1
  64. package/dist/builtin/workflows/skills/impeccable/reference/animate.md +1 -1
  65. package/dist/builtin/workflows/skills/impeccable/reference/audit.md +5 -5
  66. package/dist/builtin/workflows/skills/impeccable/reference/audit.native.md +6 -6
  67. package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +2 -2
  68. package/dist/builtin/workflows/skills/impeccable/reference/clarify.md +1 -1
  69. package/dist/builtin/workflows/skills/impeccable/reference/colorize.md +1 -1
  70. package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +0 -6
  71. package/dist/builtin/workflows/skills/impeccable/reference/critique.md +19 -41
  72. package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +11 -65
  73. package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +3 -3
  74. package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +4 -4
  75. package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +1 -1
  76. package/dist/builtin/workflows/skills/impeccable/reference/delight.md +1 -1
  77. package/dist/builtin/workflows/skills/impeccable/reference/distill.md +2 -2
  78. package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +4 -4
  79. package/dist/builtin/workflows/skills/impeccable/reference/document.md +4 -4
  80. package/dist/builtin/workflows/skills/impeccable/reference/extract.md +1 -1
  81. package/dist/builtin/workflows/skills/impeccable/reference/harden.md +1 -1
  82. package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +21 -21
  83. package/dist/builtin/workflows/skills/impeccable/reference/init.md +8 -8
  84. package/dist/builtin/workflows/skills/impeccable/reference/layout.md +2 -2
  85. package/dist/builtin/workflows/skills/impeccable/reference/live-setup.md +10 -8
  86. package/dist/builtin/workflows/skills/impeccable/reference/live.md +39 -38
  87. package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +48 -21
  88. package/dist/builtin/workflows/skills/impeccable/reference/onboard.md +1 -1
  89. package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +1 -1
  90. package/dist/builtin/workflows/skills/impeccable/reference/overdrive.md +1 -1
  91. package/dist/builtin/workflows/skills/impeccable/reference/polish.md +11 -3
  92. package/dist/builtin/workflows/skills/impeccable/reference/quieter.md +2 -2
  93. package/dist/builtin/workflows/skills/impeccable/reference/routing.md +13 -7
  94. package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +2 -2
  95. package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +13 -19
  96. package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -0
  97. package/dist/builtin/workflows/skills/impeccable/scripts/data/font-index-failures.json +121 -0
  98. package/dist/builtin/workflows/skills/impeccable/scripts/data/font-index.json +1 -0
  99. package/dist/builtin/workflows/skills/impeccable/scripts/impeccable +212 -0
  100. package/dist/builtin/workflows/skills/impeccable/scripts/impeccable.cmd +218 -0
  101. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-dom.js +21 -0
  102. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-ignores.js +242 -0
  103. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +25 -4
  104. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +666 -197
  105. package/dist/builtin/workflows/skills/research-codebase/SKILL.md +1 -1
  106. package/dist/builtin/workflows/src/authoring.d.ts +2 -0
  107. package/dist/builtin/workflows/src/durable/dependency-doctor-types.d.ts +42 -0
  108. package/dist/builtin/workflows/src/extension/index.bundle.mjs +82204 -78828
  109. package/dist/builtin/workflows/src/index.js +8938 -1200
  110. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +11 -0
  111. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +4 -1
  112. package/dist/cli/args.js +2 -2
  113. package/dist/cli/args.js.map +1 -1
  114. package/dist/config.d.ts +1 -0
  115. package/dist/config.d.ts.map +1 -1
  116. package/dist/config.js +1 -0
  117. package/dist/config.js.map +1 -1
  118. package/dist/core/agent-session-accessors.d.ts.map +1 -1
  119. package/dist/core/agent-session-accessors.js +2 -1
  120. package/dist/core/agent-session-accessors.js.map +1 -1
  121. package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
  122. package/dist/core/agent-session-auto-compaction.js +9 -2
  123. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  124. package/dist/core/agent-session-bash.d.ts +3 -1
  125. package/dist/core/agent-session-bash.d.ts.map +1 -1
  126. package/dist/core/agent-session-bash.js +18 -6
  127. package/dist/core/agent-session-bash.js.map +1 -1
  128. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  129. package/dist/core/agent-session-compaction.js +25 -8
  130. package/dist/core/agent-session-compaction.js.map +1 -1
  131. package/dist/core/agent-session-events.d.ts +6 -6
  132. package/dist/core/agent-session-events.d.ts.map +1 -1
  133. package/dist/core/agent-session-events.js +145 -62
  134. package/dist/core/agent-session-events.js.map +1 -1
  135. package/dist/core/agent-session-export.d.ts +1 -1
  136. package/dist/core/agent-session-export.d.ts.map +1 -1
  137. package/dist/core/agent-session-export.js +18 -19
  138. package/dist/core/agent-session-export.js.map +1 -1
  139. package/dist/core/agent-session-extension-bindings.d.ts +3 -2
  140. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  141. package/dist/core/agent-session-extension-bindings.js +274 -70
  142. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  143. package/dist/core/agent-session-message-queue.d.ts +1 -1
  144. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  145. package/dist/core/agent-session-message-queue.js +30 -4
  146. package/dist/core/agent-session-message-queue.js.map +1 -1
  147. package/dist/core/agent-session-methods.d.ts +19 -11
  148. package/dist/core/agent-session-methods.d.ts.map +1 -1
  149. package/dist/core/agent-session-methods.js.map +1 -1
  150. package/dist/core/agent-session-models.d.ts +2 -2
  151. package/dist/core/agent-session-models.d.ts.map +1 -1
  152. package/dist/core/agent-session-models.js +38 -29
  153. package/dist/core/agent-session-models.js.map +1 -1
  154. package/dist/core/agent-session-persistent-custom-messages.d.ts +1 -1
  155. package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
  156. package/dist/core/agent-session-post-tool-compaction.d.ts.map +1 -1
  157. package/dist/core/agent-session-post-tool-compaction.js +18 -1
  158. package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
  159. package/dist/core/agent-session-prompt.d.ts +1 -1
  160. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  161. package/dist/core/agent-session-prompt.js +104 -22
  162. package/dist/core/agent-session-prompt.js.map +1 -1
  163. package/dist/core/agent-session-queue-pause.d.ts +2 -0
  164. package/dist/core/agent-session-queue-pause.d.ts.map +1 -1
  165. package/dist/core/agent-session-queue-pause.js +13 -2
  166. package/dist/core/agent-session-queue-pause.js.map +1 -1
  167. package/dist/core/agent-session-retry.d.ts +0 -3
  168. package/dist/core/agent-session-retry.d.ts.map +1 -1
  169. package/dist/core/agent-session-retry.js +24 -11
  170. package/dist/core/agent-session-retry.js.map +1 -1
  171. package/dist/core/agent-session-runtime-auth.d.ts.map +1 -1
  172. package/dist/core/agent-session-runtime-auth.js +10 -0
  173. package/dist/core/agent-session-runtime-auth.js.map +1 -1
  174. package/dist/core/agent-session-runtime.d.ts +17 -1
  175. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  176. package/dist/core/agent-session-runtime.js +428 -197
  177. package/dist/core/agent-session-runtime.js.map +1 -1
  178. package/dist/core/agent-session-services.d.ts +4 -0
  179. package/dist/core/agent-session-services.d.ts.map +1 -1
  180. package/dist/core/agent-session-services.js +31 -2
  181. package/dist/core/agent-session-services.js.map +1 -1
  182. package/dist/core/agent-session-state.d.ts +10 -2
  183. package/dist/core/agent-session-state.d.ts.map +1 -1
  184. package/dist/core/agent-session-state.js +32 -22
  185. package/dist/core/agent-session-state.js.map +1 -1
  186. package/dist/core/agent-session-summary.d.ts.map +1 -1
  187. package/dist/core/agent-session-summary.js +9 -2
  188. package/dist/core/agent-session-summary.js.map +1 -1
  189. package/dist/core/agent-session-tasks.d.ts +1 -0
  190. package/dist/core/agent-session-tasks.d.ts.map +1 -1
  191. package/dist/core/agent-session-tasks.js +24 -3
  192. package/dist/core/agent-session-tasks.js.map +1 -1
  193. package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
  194. package/dist/core/agent-session-tool-hooks.js +26 -3
  195. package/dist/core/agent-session-tool-hooks.js.map +1 -1
  196. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  197. package/dist/core/agent-session-tool-registry.js +0 -2
  198. package/dist/core/agent-session-tool-registry.js.map +1 -1
  199. package/dist/core/agent-session-transfer.js.map +1 -1
  200. package/dist/core/agent-session-tree.d.ts.map +1 -1
  201. package/dist/core/agent-session-tree.js +6 -0
  202. package/dist/core/agent-session-tree.js.map +1 -1
  203. package/dist/core/agent-session-types.d.ts +5 -0
  204. package/dist/core/agent-session-types.d.ts.map +1 -1
  205. package/dist/core/agent-session-types.js.map +1 -1
  206. package/dist/core/agent-session.d.ts +15 -8
  207. package/dist/core/agent-session.d.ts.map +1 -1
  208. package/dist/core/agent-session.js +113 -66
  209. package/dist/core/agent-session.js.map +1 -1
  210. package/dist/core/auth-storage.d.ts +5 -3
  211. package/dist/core/auth-storage.d.ts.map +1 -1
  212. package/dist/core/auth-storage.js +18 -5
  213. package/dist/core/auth-storage.js.map +1 -1
  214. package/dist/core/builtin-diagnostics.d.ts +2 -0
  215. package/dist/core/builtin-diagnostics.d.ts.map +1 -0
  216. package/dist/core/builtin-diagnostics.js +14 -0
  217. package/dist/core/builtin-diagnostics.js.map +1 -0
  218. package/dist/core/builtin-packages.d.ts +5 -2
  219. package/dist/core/builtin-packages.d.ts.map +1 -1
  220. package/dist/core/builtin-packages.js +24 -3
  221. package/dist/core/builtin-packages.js.map +1 -1
  222. package/dist/core/builtin-resource-loader.d.ts +4 -0
  223. package/dist/core/builtin-resource-loader.d.ts.map +1 -0
  224. package/dist/core/builtin-resource-loader.js +239 -0
  225. package/dist/core/builtin-resource-loader.js.map +1 -0
  226. package/dist/core/cache-retention.d.ts +4 -0
  227. package/dist/core/cache-retention.d.ts.map +1 -0
  228. package/dist/core/cache-retention.js +58 -0
  229. package/dist/core/cache-retention.js.map +1 -0
  230. package/dist/core/cache-stats.d.ts.map +1 -1
  231. package/dist/core/cache-stats.js +11 -0
  232. package/dist/core/cache-stats.js.map +1 -1
  233. package/dist/core/cache-warmer.d.ts +66 -0
  234. package/dist/core/cache-warmer.d.ts.map +1 -0
  235. package/dist/core/cache-warmer.js +313 -0
  236. package/dist/core/cache-warmer.js.map +1 -0
  237. package/dist/core/child-session-options.d.ts +5 -0
  238. package/dist/core/child-session-options.d.ts.map +1 -0
  239. package/dist/core/child-session-options.js +30 -0
  240. package/dist/core/child-session-options.js.map +1 -0
  241. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  242. package/dist/core/compaction/branch-summarization.js +2 -2
  243. package/dist/core/compaction/branch-summarization.js.map +1 -1
  244. package/dist/core/compaction/compaction-boundary.d.ts.map +1 -1
  245. package/dist/core/compaction/compaction-boundary.js +2 -1
  246. package/dist/core/compaction/compaction-boundary.js.map +1 -1
  247. package/dist/core/compaction/compaction.d.ts.map +1 -1
  248. package/dist/core/compaction/compaction.js +18 -0
  249. package/dist/core/compaction/compaction.js.map +1 -1
  250. package/dist/core/compaction/fallback-planner.d.ts +1 -0
  251. package/dist/core/compaction/fallback-planner.d.ts.map +1 -1
  252. package/dist/core/compaction/fallback-planner.js +2 -0
  253. package/dist/core/compaction/fallback-planner.js.map +1 -1
  254. package/dist/core/compaction/range-planner.d.ts.map +1 -1
  255. package/dist/core/compaction/range-planner.js +3 -3
  256. package/dist/core/compaction/range-planner.js.map +1 -1
  257. package/dist/core/compaction/session-summarization.d.ts.map +1 -1
  258. package/dist/core/compaction/session-summarization.js +2 -1
  259. package/dist/core/compaction/session-summarization.js.map +1 -1
  260. package/dist/core/credential-screening.d.ts +17 -0
  261. package/dist/core/credential-screening.d.ts.map +1 -0
  262. package/dist/core/credential-screening.js +30 -0
  263. package/dist/core/credential-screening.js.map +1 -0
  264. package/dist/core/decision-provider.d.ts +4 -0
  265. package/dist/core/decision-provider.d.ts.map +1 -0
  266. package/dist/core/decision-provider.js +12 -0
  267. package/dist/core/decision-provider.js.map +1 -0
  268. package/dist/core/execution-model-router.d.ts +30 -0
  269. package/dist/core/execution-model-router.d.ts.map +1 -0
  270. package/dist/core/execution-model-router.js +191 -0
  271. package/dist/core/execution-model-router.js.map +1 -0
  272. package/dist/core/extensions/agent-events.d.ts +4 -4
  273. package/dist/core/extensions/agent-events.d.ts.map +1 -1
  274. package/dist/core/extensions/agent-events.js.map +1 -1
  275. package/dist/core/extensions/api-types.d.ts +46 -40
  276. package/dist/core/extensions/api-types.d.ts.map +1 -1
  277. package/dist/core/extensions/api-types.js.map +1 -1
  278. package/dist/core/extensions/context-types.d.ts +7 -1
  279. package/dist/core/extensions/context-types.d.ts.map +1 -1
  280. package/dist/core/extensions/context-types.js.map +1 -1
  281. package/dist/core/extensions/event-results.d.ts +7 -6
  282. package/dist/core/extensions/event-results.d.ts.map +1 -1
  283. package/dist/core/extensions/event-results.js.map +1 -1
  284. package/dist/core/extensions/event-types.d.ts +2 -1
  285. package/dist/core/extensions/event-types.d.ts.map +1 -1
  286. package/dist/core/extensions/event-types.js.map +1 -1
  287. package/dist/core/extensions/extension-work.d.ts +14 -0
  288. package/dist/core/extensions/extension-work.d.ts.map +1 -0
  289. package/dist/core/extensions/extension-work.js +73 -0
  290. package/dist/core/extensions/extension-work.js.map +1 -0
  291. package/dist/core/extensions/herdr-file-integration.d.ts +36 -0
  292. package/dist/core/extensions/herdr-file-integration.d.ts.map +1 -0
  293. package/dist/core/extensions/herdr-file-integration.js +60 -0
  294. package/dist/core/extensions/herdr-file-integration.js.map +1 -0
  295. package/dist/core/extensions/host-input.d.ts +51 -0
  296. package/dist/core/extensions/host-input.d.ts.map +1 -0
  297. package/dist/core/extensions/host-input.js +211 -0
  298. package/dist/core/extensions/host-input.js.map +1 -0
  299. package/dist/core/extensions/index.d.ts +4 -2
  300. package/dist/core/extensions/index.d.ts.map +1 -1
  301. package/dist/core/extensions/index.js +0 -3
  302. package/dist/core/extensions/index.js.map +1 -1
  303. package/dist/core/extensions/jiti-loader.d.ts +2 -0
  304. package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
  305. package/dist/core/extensions/jiti-loader.js +3 -0
  306. package/dist/core/extensions/jiti-loader.js.map +1 -0
  307. package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
  308. package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
  309. package/dist/core/extensions/jiti-static-loader.js +3 -0
  310. package/dist/core/extensions/jiti-static-loader.js.map +1 -0
  311. package/dist/core/extensions/loader-api.d.ts +7 -0
  312. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  313. package/dist/core/extensions/loader-api.js +154 -28
  314. package/dist/core/extensions/loader-api.js.map +1 -1
  315. package/dist/core/extensions/loader-bindings.d.ts +24 -0
  316. package/dist/core/extensions/loader-bindings.d.ts.map +1 -0
  317. package/dist/core/extensions/loader-bindings.js +128 -0
  318. package/dist/core/extensions/loader-bindings.js.map +1 -0
  319. package/dist/core/extensions/loader-core.d.ts +2 -1
  320. package/dist/core/extensions/loader-core.d.ts.map +1 -1
  321. package/dist/core/extensions/loader-core.js +91 -14
  322. package/dist/core/extensions/loader-core.js.map +1 -1
  323. package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
  324. package/dist/core/extensions/loader-host-modules.js +3 -1
  325. package/dist/core/extensions/loader-host-modules.js.map +1 -1
  326. package/dist/core/extensions/loader-rollback.d.ts +14 -0
  327. package/dist/core/extensions/loader-rollback.d.ts.map +1 -0
  328. package/dist/core/extensions/loader-rollback.js +95 -0
  329. package/dist/core/extensions/loader-rollback.js.map +1 -0
  330. package/dist/core/extensions/loader-runtime.d.ts +3 -1
  331. package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
  332. package/dist/core/extensions/loader-runtime.js +38 -14
  333. package/dist/core/extensions/loader-runtime.js.map +1 -1
  334. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  335. package/dist/core/extensions/loader-virtual-modules.js +9 -2
  336. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  337. package/dist/core/extensions/loader.d.ts +1 -1
  338. package/dist/core/extensions/loader.d.ts.map +1 -1
  339. package/dist/core/extensions/loader.js +1 -1
  340. package/dist/core/extensions/loader.js.map +1 -1
  341. package/dist/core/extensions/reactive-widget.d.ts +1 -1
  342. package/dist/core/extensions/reactive-widget.js.map +1 -1
  343. package/dist/core/extensions/runner-context.d.ts +4 -0
  344. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  345. package/dist/core/extensions/runner-context.js +25 -0
  346. package/dist/core/extensions/runner-context.js.map +1 -1
  347. package/dist/core/extensions/runner-events.d.ts +8 -4
  348. package/dist/core/extensions/runner-events.d.ts.map +1 -1
  349. package/dist/core/extensions/runner-events.js +55 -53
  350. package/dist/core/extensions/runner-events.js.map +1 -1
  351. package/dist/core/extensions/runner-project-trust.d.ts.map +1 -1
  352. package/dist/core/extensions/runner-project-trust.js +2 -4
  353. package/dist/core/extensions/runner-project-trust.js.map +1 -1
  354. package/dist/core/extensions/runner.d.ts +31 -4
  355. package/dist/core/extensions/runner.d.ts.map +1 -1
  356. package/dist/core/extensions/runner.js +219 -23
  357. package/dist/core/extensions/runner.js.map +1 -1
  358. package/dist/core/extensions/runtime-types.d.ts +2 -0
  359. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  360. package/dist/core/extensions/runtime-types.js.map +1 -1
  361. package/dist/core/extensions/types.d.ts +3 -2
  362. package/dist/core/extensions/types.d.ts.map +1 -1
  363. package/dist/core/extensions/types.js +0 -12
  364. package/dist/core/extensions/types.js.map +1 -1
  365. package/dist/core/extensions/workflow-activity-hub.d.ts +2 -0
  366. package/dist/core/extensions/workflow-activity-hub.d.ts.map +1 -1
  367. package/dist/core/extensions/workflow-activity-hub.js +5 -3
  368. package/dist/core/extensions/workflow-activity-hub.js.map +1 -1
  369. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  370. package/dist/core/extensions/wrapper.js +5 -3
  371. package/dist/core/extensions/wrapper.js.map +1 -1
  372. package/dist/core/fast-model-routing.d.ts +3 -3
  373. package/dist/core/fast-model-routing.d.ts.map +1 -1
  374. package/dist/core/fast-model-routing.js +3 -3
  375. package/dist/core/fast-model-routing.js.map +1 -1
  376. package/dist/core/fast-model-variants.d.ts +4 -0
  377. package/dist/core/fast-model-variants.d.ts.map +1 -1
  378. package/dist/core/fast-model-variants.js +3 -0
  379. package/dist/core/fast-model-variants.js.map +1 -1
  380. package/dist/core/index.d.ts +4 -1
  381. package/dist/core/index.d.ts.map +1 -1
  382. package/dist/core/index.js +2 -0
  383. package/dist/core/index.js.map +1 -1
  384. package/dist/core/mandatory-resource-loader.d.ts +4 -0
  385. package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
  386. package/dist/core/mandatory-resource-loader.js +29 -1
  387. package/dist/core/mandatory-resource-loader.js.map +1 -1
  388. package/dist/core/mandatory-runtime-tools.d.ts +1 -4
  389. package/dist/core/mandatory-runtime-tools.d.ts.map +1 -1
  390. package/dist/core/mandatory-runtime-tools.js +1 -9
  391. package/dist/core/mandatory-runtime-tools.js.map +1 -1
  392. package/dist/core/messages.d.ts.map +1 -1
  393. package/dist/core/messages.js +8 -1
  394. package/dist/core/messages.js.map +1 -1
  395. package/dist/core/model-config.d.ts +41 -10
  396. package/dist/core/model-config.d.ts.map +1 -1
  397. package/dist/core/model-config.js +11 -2
  398. package/dist/core/model-config.js.map +1 -1
  399. package/dist/core/model-registry.d.ts +4 -2
  400. package/dist/core/model-registry.d.ts.map +1 -1
  401. package/dist/core/model-registry.js +6 -2
  402. package/dist/core/model-registry.js.map +1 -1
  403. package/dist/core/model-routing-constraints.d.ts +24 -0
  404. package/dist/core/model-routing-constraints.d.ts.map +1 -0
  405. package/dist/core/model-routing-constraints.js +46 -0
  406. package/dist/core/model-routing-constraints.js.map +1 -0
  407. package/dist/core/model-routing-task.d.ts +4 -0
  408. package/dist/core/model-routing-task.d.ts.map +1 -0
  409. package/dist/core/model-routing-task.js +77 -0
  410. package/dist/core/model-routing-task.js.map +1 -0
  411. package/dist/core/model-runtime-streaming.d.ts +13 -3
  412. package/dist/core/model-runtime-streaming.d.ts.map +1 -1
  413. package/dist/core/model-runtime-streaming.js +15 -5
  414. package/dist/core/model-runtime-streaming.js.map +1 -1
  415. package/dist/core/model-runtime-types.d.ts +2 -2
  416. package/dist/core/model-runtime-types.d.ts.map +1 -1
  417. package/dist/core/model-runtime-types.js.map +1 -1
  418. package/dist/core/model-runtime.d.ts +6 -3
  419. package/dist/core/model-runtime.d.ts.map +1 -1
  420. package/dist/core/model-runtime.js +29 -2
  421. package/dist/core/model-runtime.js.map +1 -1
  422. package/dist/core/provider-composer-internal.d.ts +3 -2
  423. package/dist/core/provider-composer-internal.d.ts.map +1 -1
  424. package/dist/core/provider-composer-internal.js +2 -0
  425. package/dist/core/provider-composer-internal.js.map +1 -1
  426. package/dist/core/provider-composer.d.ts.map +1 -1
  427. package/dist/core/provider-composer.js.map +1 -1
  428. package/dist/core/resolve-config-value.d.ts +2 -0
  429. package/dist/core/resolve-config-value.d.ts.map +1 -1
  430. package/dist/core/resolve-config-value.js +23 -1
  431. package/dist/core/resolve-config-value.js.map +1 -1
  432. package/dist/core/resource-loader-core.d.ts +6 -0
  433. package/dist/core/resource-loader-core.d.ts.map +1 -1
  434. package/dist/core/resource-loader-core.js +37 -6
  435. package/dist/core/resource-loader-core.js.map +1 -1
  436. package/dist/core/resource-loader-extensions.d.ts.map +1 -1
  437. package/dist/core/resource-loader-extensions.js +2 -0
  438. package/dist/core/resource-loader-extensions.js.map +1 -1
  439. package/dist/core/resource-loader-reload.d.ts.map +1 -1
  440. package/dist/core/resource-loader-reload.js +7 -2
  441. package/dist/core/resource-loader-reload.js.map +1 -1
  442. package/dist/core/resource-loader.d.ts +1 -1
  443. package/dist/core/resource-loader.d.ts.map +1 -1
  444. package/dist/core/resource-loader.js +1 -1
  445. package/dist/core/resource-loader.js.map +1 -1
  446. package/dist/core/runtime-credentials.d.ts +2 -0
  447. package/dist/core/runtime-credentials.d.ts.map +1 -1
  448. package/dist/core/runtime-credentials.js +15 -0
  449. package/dist/core/runtime-credentials.js.map +1 -1
  450. package/dist/core/sdk-types.d.ts +13 -5
  451. package/dist/core/sdk-types.d.ts.map +1 -1
  452. package/dist/core/sdk-types.js.map +1 -1
  453. package/dist/core/sdk.d.ts +3 -1
  454. package/dist/core/sdk.d.ts.map +1 -1
  455. package/dist/core/sdk.js +211 -37
  456. package/dist/core/sdk.js.map +1 -1
  457. package/dist/core/session-lifecycle-scope.d.ts +15 -0
  458. package/dist/core/session-lifecycle-scope.d.ts.map +1 -0
  459. package/dist/core/session-lifecycle-scope.js +13 -0
  460. package/dist/core/session-lifecycle-scope.js.map +1 -0
  461. package/dist/core/session-lifecycle-work.d.ts +17 -0
  462. package/dist/core/session-lifecycle-work.d.ts.map +1 -0
  463. package/dist/core/session-lifecycle-work.js +144 -0
  464. package/dist/core/session-lifecycle-work.js.map +1 -0
  465. package/dist/core/session-manager-core.d.ts +8 -4
  466. package/dist/core/session-manager-core.d.ts.map +1 -1
  467. package/dist/core/session-manager-core.js +27 -3
  468. package/dist/core/session-manager-core.js.map +1 -1
  469. package/dist/core/session-manager-history.d.ts.map +1 -1
  470. package/dist/core/session-manager-history.js +3 -0
  471. package/dist/core/session-manager-history.js.map +1 -1
  472. package/dist/core/session-manager-list.d.ts +3 -3
  473. package/dist/core/session-manager-list.d.ts.map +1 -1
  474. package/dist/core/session-manager-list.js +89 -74
  475. package/dist/core/session-manager-list.js.map +1 -1
  476. package/dist/core/session-manager-storage.d.ts.map +1 -1
  477. package/dist/core/session-manager-storage.js +10 -7
  478. package/dist/core/session-manager-storage.js.map +1 -1
  479. package/dist/core/session-manager-types.d.ts +13 -3
  480. package/dist/core/session-manager-types.d.ts.map +1 -1
  481. package/dist/core/session-manager-types.js.map +1 -1
  482. package/dist/core/session-manager.d.ts +1 -1
  483. package/dist/core/session-manager.d.ts.map +1 -1
  484. package/dist/core/session-manager.js.map +1 -1
  485. package/dist/core/session-startup-rollback.d.ts +5 -0
  486. package/dist/core/session-startup-rollback.d.ts.map +1 -0
  487. package/dist/core/session-startup-rollback.js +16 -0
  488. package/dist/core/session-startup-rollback.js.map +1 -0
  489. package/dist/core/settings-manager-basic-accessors.d.ts +5 -0
  490. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  491. package/dist/core/settings-manager-basic-accessors.js +35 -0
  492. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  493. package/dist/core/settings-manager-core.d.ts.map +1 -1
  494. package/dist/core/settings-manager-core.js +4 -0
  495. package/dist/core/settings-manager-core.js.map +1 -1
  496. package/dist/core/settings-manager.d.ts +1 -0
  497. package/dist/core/settings-manager.d.ts.map +1 -1
  498. package/dist/core/settings-manager.js +1 -0
  499. package/dist/core/settings-manager.js.map +1 -1
  500. package/dist/core/settings-types.d.ts +4 -0
  501. package/dist/core/settings-types.d.ts.map +1 -1
  502. package/dist/core/settings-types.js +1 -1
  503. package/dist/core/settings-types.js.map +1 -1
  504. package/dist/core/settings-write-ownership.d.ts +7 -0
  505. package/dist/core/settings-write-ownership.d.ts.map +1 -0
  506. package/dist/core/settings-write-ownership.js +24 -0
  507. package/dist/core/settings-write-ownership.js.map +1 -0
  508. package/dist/core/slash-commands.js +1 -1
  509. package/dist/core/slash-commands.js.map +1 -1
  510. package/dist/core/structured-output/index.d.ts +12 -0
  511. package/dist/core/structured-output/index.d.ts.map +1 -0
  512. package/dist/core/structured-output/index.js +251 -0
  513. package/dist/core/structured-output/index.js.map +1 -0
  514. package/dist/core/structured-output/invalid-output.d.ts +8 -0
  515. package/dist/core/structured-output/invalid-output.d.ts.map +1 -0
  516. package/dist/core/structured-output/invalid-output.js +4 -0
  517. package/dist/core/structured-output/invalid-output.js.map +1 -0
  518. package/dist/core/structured-output/jev-client.d.ts +20 -0
  519. package/dist/core/structured-output/jev-client.d.ts.map +1 -0
  520. package/dist/core/structured-output/jev-client.js +116 -0
  521. package/dist/core/structured-output/jev-client.js.map +1 -0
  522. package/dist/core/structured-output/jev.d.ts +5 -0
  523. package/dist/core/structured-output/jev.d.ts.map +1 -0
  524. package/dist/core/structured-output/jev.js +275 -0
  525. package/dist/core/structured-output/jev.js.map +1 -0
  526. package/dist/core/structured-output/resolver.d.ts +41 -0
  527. package/dist/core/structured-output/resolver.d.ts.map +1 -0
  528. package/dist/core/structured-output/resolver.js +56 -0
  529. package/dist/core/structured-output/resolver.js.map +1 -0
  530. package/dist/core/structured-output/types.d.ts +68 -0
  531. package/dist/core/structured-output/types.d.ts.map +1 -0
  532. package/dist/core/structured-output/types.js +2 -0
  533. package/dist/core/structured-output/types.js.map +1 -0
  534. package/dist/core/system-prompt.d.ts +48 -5
  535. package/dist/core/system-prompt.d.ts.map +1 -1
  536. package/dist/core/system-prompt.js +132 -100
  537. package/dist/core/system-prompt.js.map +1 -1
  538. package/dist/core/tasks/contracts.d.ts +6 -0
  539. package/dist/core/tasks/contracts.d.ts.map +1 -1
  540. package/dist/core/tasks/contracts.js.map +1 -1
  541. package/dist/core/tasks/supervisor.d.ts.map +1 -1
  542. package/dist/core/tasks/supervisor.js +7 -0
  543. package/dist/core/tasks/supervisor.js.map +1 -1
  544. package/dist/core/tools/ask-user-question/ask-user-question.d.ts +4 -1
  545. package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
  546. package/dist/core/tools/ask-user-question/ask-user-question.js +31 -35
  547. package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
  548. package/dist/core/tools/ask-user-question/index.d.ts +1 -1
  549. package/dist/core/tools/ask-user-question/index.js.map +1 -1
  550. package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts +1 -1
  551. package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -1
  552. package/dist/core/tools/ask-user-question/state/key-router.d.ts +1 -1
  553. package/dist/core/tools/ask-user-question/state/key-router.js.map +1 -1
  554. package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts +1 -1
  555. package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
  556. package/dist/core/tools/ask-user-question/state/row-intent.d.ts +1 -1
  557. package/dist/core/tools/ask-user-question/state/row-intent.js.map +1 -1
  558. package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts +1 -1
  559. package/dist/core/tools/ask-user-question/state/selectors/contract.js.map +1 -1
  560. package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts +1 -1
  561. package/dist/core/tools/ask-user-question/state/selectors/derivations.js.map +1 -1
  562. package/dist/core/tools/ask-user-question/state/state-reducer.d.ts +1 -1
  563. package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -1
  564. package/dist/core/tools/ask-user-question/state/state.d.ts +1 -1
  565. package/dist/core/tools/ask-user-question/state/state.js.map +1 -1
  566. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +1 -1
  567. package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -1
  568. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +1 -1
  569. package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -1
  570. package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts +1 -1
  571. package/dist/core/tools/ask-user-question/tool/validate-questionnaire.js.map +1 -1
  572. package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts +1 -1
  573. package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
  574. package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts +1 -1
  575. package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.js.map +1 -1
  576. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +1 -1
  577. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
  578. package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts +1 -1
  579. package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.js.map +1 -1
  580. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts +1 -1
  581. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js.map +1 -1
  582. package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -1
  583. package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -1
  584. package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts +1 -1
  585. package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -1
  586. package/dist/core/tools/ask-user-question/view/props-adapter.d.ts +1 -1
  587. package/dist/core/tools/ask-user-question/view/props-adapter.js.map +1 -1
  588. package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts +1 -1
  589. package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -1
  590. package/dist/core/tools/bash.d.ts.map +1 -1
  591. package/dist/core/tools/bash.js +16 -11
  592. package/dist/core/tools/bash.js.map +1 -1
  593. package/dist/core/tools/find.d.ts +2 -2
  594. package/dist/core/tools/find.d.ts.map +1 -1
  595. package/dist/core/tools/find.js +1 -1
  596. package/dist/core/tools/find.js.map +1 -1
  597. package/dist/core/usage-totals.d.ts.map +1 -1
  598. package/dist/core/usage-totals.js +4 -0
  599. package/dist/core/usage-totals.js.map +1 -1
  600. package/dist/extensions/herdr/index.d.ts.map +1 -1
  601. package/dist/extensions/herdr/index.js +0 -7
  602. package/dist/extensions/herdr/index.js.map +1 -1
  603. package/dist/extensions/llama/client.d.ts +2 -0
  604. package/dist/extensions/llama/client.d.ts.map +1 -1
  605. package/dist/extensions/llama/client.js +6 -2
  606. package/dist/extensions/llama/client.js.map +1 -1
  607. package/dist/extensions/llama/provider.d.ts.map +1 -1
  608. package/dist/extensions/llama/provider.js +18 -4
  609. package/dist/extensions/llama/provider.js.map +1 -1
  610. package/dist/index.d.ts +11 -2
  611. package/dist/index.d.ts.map +1 -1
  612. package/dist/index.js +6 -1
  613. package/dist/index.js.map +1 -1
  614. package/dist/main-session.d.ts.map +1 -1
  615. package/dist/main-session.js +19 -10
  616. package/dist/main-session.js.map +1 -1
  617. package/dist/main.d.ts.map +1 -1
  618. package/dist/main.js +4 -5
  619. package/dist/main.js.map +1 -1
  620. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  621. package/dist/modes/interactive/components/branch-summary-message.js +12 -5
  622. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  623. package/dist/modes/interactive/components/chat-message-renderer.d.ts +5 -1
  624. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  625. package/dist/modes/interactive/components/chat-message-renderer.js +4 -0
  626. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  627. package/dist/modes/interactive/components/chat-session-host-events.d.ts +2 -2
  628. package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
  629. package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
  630. package/dist/modes/interactive/components/compaction-boundary-message.js +17 -9
  631. package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
  632. package/dist/modes/interactive/components/custom-editor.d.ts +6 -0
  633. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  634. package/dist/modes/interactive/components/custom-editor.js +17 -0
  635. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  636. package/dist/modes/interactive/components/host-input-form-mount.d.ts +1 -1
  637. package/dist/modes/interactive/components/host-input-form-mount.js.map +1 -1
  638. package/dist/modes/interactive/components/host-input-form.d.ts +1 -1
  639. package/dist/modes/interactive/components/host-input-form.js.map +1 -1
  640. package/dist/modes/interactive/components/host-session-picker.d.ts +1 -1
  641. package/dist/modes/interactive/components/host-session-picker.js.map +1 -1
  642. package/dist/modes/interactive/components/reserved-bottom-overlay.d.ts +1 -1
  643. package/dist/modes/interactive/components/reserved-bottom-overlay.js.map +1 -1
  644. package/dist/modes/interactive/components/scroll-widget.d.ts +1 -1
  645. package/dist/modes/interactive/components/scroll-widget.js.map +1 -1
  646. package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
  647. package/dist/modes/interactive/components/settings-selector-handlers.js +3 -0
  648. package/dist/modes/interactive/components/settings-selector-handlers.js.map +1 -1
  649. package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
  650. package/dist/modes/interactive/components/settings-selector-items.js +50 -1
  651. package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
  652. package/dist/modes/interactive/components/settings-selector-submenus.d.ts.map +1 -1
  653. package/dist/modes/interactive/components/settings-selector-submenus.js +2 -1
  654. package/dist/modes/interactive/components/settings-selector-submenus.js.map +1 -1
  655. package/dist/modes/interactive/components/settings-selector-types.d.ts +6 -1
  656. package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
  657. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  658. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  659. package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
  660. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  661. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  662. package/dist/modes/interactive/components/tool-execution.js +14 -9
  663. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  664. package/dist/modes/interactive/interactive-auth-login.js +1 -1
  665. package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
  666. package/dist/modes/interactive/interactive-auth-routing.js +2 -2
  667. package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
  668. package/dist/modes/interactive/interactive-autocomplete.js +4 -0
  669. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  670. package/dist/modes/interactive/interactive-bash-compact.d.ts.map +1 -1
  671. package/dist/modes/interactive/interactive-bash-compact.js +13 -6
  672. package/dist/modes/interactive/interactive-bash-compact.js.map +1 -1
  673. package/dist/modes/interactive/interactive-extension-runtime.js +5 -0
  674. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  675. package/dist/modes/interactive/interactive-input-handling.js +2 -2
  676. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  677. package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
  678. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  679. package/dist/modes/interactive/interactive-mode-deps.js +1 -1
  680. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  681. package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -1
  682. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  683. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  684. package/dist/modes/interactive/interactive-render-chat.js +27 -25
  685. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  686. package/dist/modes/interactive/interactive-selectors.js +10 -0
  687. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  688. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  689. package/dist/modes/interactive/interactive-startup.js +2 -2
  690. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  691. package/dist/modes/interactive/interactive-tui.js.map +1 -1
  692. package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
  693. package/dist/modes/interactive-engine/engine-custom-ui.js +3 -1
  694. package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
  695. package/dist/modes/interactive-engine/engine-input-form.d.ts +1 -1
  696. package/dist/modes/interactive-engine/engine-input-form.js.map +1 -1
  697. package/dist/modes/interactive-engine/engine-session-picker.d.ts +1 -1
  698. package/dist/modes/interactive-engine/engine-session-picker.js.map +1 -1
  699. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  700. package/dist/modes/interactive-engine/isolated-runtime.js +10 -1
  701. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  702. package/dist/modes/interactive-engine/protocol.d.ts +1 -1
  703. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  704. package/dist/modes/interactive-engine/remote-component.js.map +1 -1
  705. package/dist/modes/rpc/rpc-keybindings-reload.d.ts +1 -1
  706. package/dist/modes/rpc/rpc-keybindings-reload.js.map +1 -1
  707. package/dist/modes/rpc/rpc-provider-auth.d.ts +1 -1
  708. package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
  709. package/dist/session-id-target.d.ts +31 -0
  710. package/dist/session-id-target.d.ts.map +1 -0
  711. package/dist/session-id-target.js +57 -0
  712. package/dist/session-id-target.js.map +1 -0
  713. package/dist/utils/abort.d.ts.map +1 -1
  714. package/dist/utils/abort.js +29 -4
  715. package/dist/utils/abort.js.map +1 -1
  716. package/dist/utils/clipboard-image.d.ts.map +1 -1
  717. package/dist/utils/clipboard-image.js +1 -12
  718. package/dist/utils/clipboard-image.js.map +1 -1
  719. package/dist/utils/clipboard.d.ts.map +1 -1
  720. package/dist/utils/clipboard.js +87 -23
  721. package/dist/utils/clipboard.js.map +1 -1
  722. package/dist/utils/wsl.d.ts +3 -0
  723. package/dist/utils/wsl.d.ts.map +1 -0
  724. package/dist/utils/wsl.js +15 -0
  725. package/dist/utils/wsl.js.map +1 -0
  726. package/docs/background-tasks.md +24 -14
  727. package/docs/build.md +6 -16
  728. package/docs/compaction/reference.md +10 -12
  729. package/docs/compaction.md +30 -112
  730. package/docs/computer-use.md +23 -24
  731. package/docs/containerization.md +4 -5
  732. package/docs/custom-provider/api-reference.md +10 -1
  733. package/docs/custom-provider/oauth.md +4 -2
  734. package/docs/custom-provider/streaming.md +8 -3
  735. package/docs/custom-provider.md +1 -1
  736. package/docs/development.md +13 -138
  737. package/docs/docs.json +19 -5
  738. package/docs/environment-variables.md +20 -4
  739. package/docs/extensions/api-reference.md +6 -2
  740. package/docs/extensions/authoring.md +10 -7
  741. package/docs/extensions/events.md +14 -24
  742. package/docs/extensions/ui.md +3 -4
  743. package/docs/extensions.md +22 -18
  744. package/docs/getting-started/authentication.md +4 -1
  745. package/docs/getting-started/first-session.md +10 -8
  746. package/docs/getting-started/installation.md +14 -6
  747. package/docs/getting-started/project-instructions.md +5 -1
  748. package/docs/guides/configuration.md +10 -5
  749. package/docs/guides/non-interactive.md +2 -2
  750. package/docs/guides.md +8 -17
  751. package/docs/herdr.md +2 -1
  752. package/docs/index.md +2 -2
  753. package/docs/intercom/operations.md +16 -70
  754. package/docs/intercom/reference.md +15 -5
  755. package/docs/intercom.md +16 -7
  756. package/docs/json.md +12 -2
  757. package/docs/keybindings.md +13 -8
  758. package/docs/llama-cpp.md +5 -1
  759. package/docs/{mcp.md → mcp-servers.md} +21 -2
  760. package/docs/models/evals.md +133 -465
  761. package/docs/models/model-selection.md +33 -118
  762. package/docs/models/reference.md +18 -21
  763. package/docs/models.md +7 -4
  764. package/docs/packages/authoring.md +5 -1
  765. package/docs/packages/reference.md +5 -1
  766. package/docs/packages.md +5 -3
  767. package/docs/programmatic.md +3 -1
  768. package/docs/prompt-templates.md +2 -10
  769. package/docs/providers/reference.md +2 -2
  770. package/docs/providers.md +41 -16
  771. package/docs/quickstart.md +8 -4
  772. package/docs/reference/cli.md +19 -11
  773. package/docs/reference.md +3 -6
  774. package/docs/rpc/protocol.md +11 -13
  775. package/docs/rpc.md +5 -1
  776. package/docs/sdk/reference.md +59 -239
  777. package/docs/sdk/structured-decisions.md +132 -0
  778. package/docs/sdk.md +181 -17
  779. package/docs/security.md +7 -4
  780. package/docs/session-format.md +18 -5
  781. package/docs/sessions.md +12 -6
  782. package/docs/settings.md +68 -16
  783. package/docs/skills/authoring.md +7 -1
  784. package/docs/skills.md +26 -7
  785. package/docs/subagents/authoring.md +11 -1
  786. package/docs/subagents/reference.md +98 -10
  787. package/docs/subagents.md +51 -35
  788. package/docs/terminal-setup.md +4 -2
  789. package/docs/termux.md +3 -1
  790. package/docs/themes/reference.md +4 -1
  791. package/docs/themes.md +1 -1
  792. package/docs/tools.md +431 -20
  793. package/docs/tui/reference.md +13 -14
  794. package/docs/tui.md +10 -6
  795. package/docs/usage.md +21 -7
  796. package/docs/web-access.md +5 -1
  797. package/docs/windows.md +18 -11
  798. package/docs/workflows/api-reference.md +134 -25
  799. package/docs/workflows/authoring.md +48 -39
  800. package/docs/workflows/builtins.md +22 -28
  801. package/docs/workflows/operations.md +284 -137
  802. package/docs/workflows/reliable-design.md +74 -130
  803. package/docs/workflows/verification.md +8 -8
  804. package/docs/workflows.md +10 -16
  805. package/examples/extensions/custom-provider-anthropic/index.ts +15 -10
  806. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  807. package/examples/extensions/prompt-customizer.ts +17 -37
  808. package/npm-shrinkwrap.json +502 -709
  809. package/package.json +12 -10
  810. package/dist/builtin/subagents/skills/playwright-cli/SKILL.md +0 -420
  811. package/dist/builtin/subagents/skills/playwright-cli/references/element-attributes.md +0 -23
  812. package/dist/builtin/subagents/skills/playwright-cli/references/playwright-tests.md +0 -39
  813. package/dist/builtin/subagents/skills/playwright-cli/references/request-mocking.md +0 -87
  814. package/dist/builtin/subagents/skills/playwright-cli/references/running-code.md +0 -241
  815. package/dist/builtin/subagents/skills/playwright-cli/references/session-management.md +0 -225
  816. package/dist/builtin/subagents/skills/playwright-cli/references/storage-state.md +0 -275
  817. package/dist/builtin/subagents/skills/playwright-cli/references/test-generation.md +0 -433
  818. package/dist/builtin/subagents/skills/playwright-cli/references/tracing.md +0 -139
  819. package/dist/builtin/subagents/skills/playwright-cli/references/video-recording.md +0 -143
  820. package/dist/builtin/workflows/builtin/chunk-m0xfsef8.js +0 -2813
  821. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_asset_producer.toml +0 -94
  822. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_documenter.toml +0 -27
  823. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_finish_reviewer.toml +0 -41
  824. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_manual_edit_applier.toml +0 -95
  825. package/dist/builtin/workflows/skills/impeccable/agents/openai.yaml +0 -4
  826. package/dist/builtin/workflows/skills/impeccable/scripts/concept-seed.mjs +0 -695
  827. package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +0 -325
  828. package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +0 -1503
  829. package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +0 -222
  830. package/dist/builtin/workflows/skills/impeccable/scripts/detect-csp.mjs +0 -198
  831. package/dist/builtin/workflows/skills/impeccable/scripts/detect.mjs +0 -21
  832. package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +0 -2073
  833. package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +0 -432
  834. package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +0 -1121
  835. package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +0 -8746
  836. package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns.mjs +0 -51
  837. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +0 -376
  838. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +0 -1168
  839. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +0 -1192
  840. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +0 -290
  841. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -189
  842. package/dist/builtin/workflows/skills/impeccable/scripts/detector/findings.mjs +0 -18
  843. package/dist/builtin/workflows/skills/impeccable/scripts/detector/node/file-system.mjs +0 -213
  844. package/dist/builtin/workflows/skills/impeccable/scripts/detector/profile/profiler.mjs +0 -166
  845. package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +0 -617
  846. package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +0 -5534
  847. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/color.mjs +0 -588
  848. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/constants.mjs +0 -112
  849. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/fonts.mjs +0 -30
  850. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/inline-ignores.mjs +0 -148
  851. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/page.mjs +0 -35
  852. package/dist/builtin/workflows/skills/impeccable/scripts/doctor.mjs +0 -338
  853. package/dist/builtin/workflows/skills/impeccable/scripts/embed-prompt.mjs +0 -270
  854. package/dist/builtin/workflows/skills/impeccable/scripts/generate-image.mjs +0 -277
  855. package/dist/builtin/workflows/skills/impeccable/scripts/hook-admin.mjs +0 -783
  856. package/dist/builtin/workflows/skills/impeccable/scripts/hook-lib.mjs +0 -2305
  857. package/dist/builtin/workflows/skills/impeccable/scripts/hook.mjs +0 -78
  858. package/dist/builtin/workflows/skills/impeccable/scripts/lib/artifact-schema.mjs +0 -93
  859. package/dist/builtin/workflows/skills/impeccable/scripts/lib/composition-catalog.mjs +0 -200
  860. package/dist/builtin/workflows/skills/impeccable/scripts/lib/concept-catalog.mjs +0 -395
  861. package/dist/builtin/workflows/skills/impeccable/scripts/lib/design-parser.mjs +0 -925
  862. package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +0 -640
  863. package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-paths.mjs +0 -137
  864. package/dist/builtin/workflows/skills/impeccable/scripts/lib/is-generated.mjs +0 -72
  865. package/dist/builtin/workflows/skills/impeccable/scripts/lib/open-system-browser.mjs +0 -57
  866. package/dist/builtin/workflows/skills/impeccable/scripts/lib/provider.mjs +0 -5
  867. package/dist/builtin/workflows/skills/impeccable/scripts/lib/roll-selection.mjs +0 -369
  868. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-deep.mjs +0 -483
  869. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-notice.mjs +0 -169
  870. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness.mjs +0 -528
  871. package/dist/builtin/workflows/skills/impeccable/scripts/lib/surface-briefs.mjs +0 -151
  872. package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-args.mjs +0 -42
  873. package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-slug.mjs +0 -33
  874. package/dist/builtin/workflows/skills/impeccable/scripts/lib/template-extensions.mjs +0 -146
  875. package/dist/builtin/workflows/skills/impeccable/scripts/live/accept-css.mjs +0 -617
  876. package/dist/builtin/workflows/skills/impeccable/scripts/live/accept-verify.mjs +0 -71
  877. package/dist/builtin/workflows/skills/impeccable/scripts/live/browser-script-parts.mjs +0 -77
  878. package/dist/builtin/workflows/skills/impeccable/scripts/live/completion.mjs +0 -28
  879. package/dist/builtin/workflows/skills/impeccable/scripts/live/event-validation.mjs +0 -199
  880. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/astro.mjs +0 -47
  881. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/detect-utils.mjs +0 -157
  882. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/index.mjs +0 -143
  883. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/journal.mjs +0 -205
  884. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/nextjs.mjs +0 -49
  885. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/nuxt.mjs +0 -170
  886. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/script-src.mjs +0 -26
  887. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/static-html.mjs +0 -26
  888. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/sveltekit.mjs +0 -71
  889. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/tag-strategy.mjs +0 -247
  890. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/tanstack-start.mjs +0 -70
  891. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/vite-generic.mjs +0 -42
  892. package/dist/builtin/workflows/skills/impeccable/scripts/live/generation-preflight.mjs +0 -149
  893. package/dist/builtin/workflows/skills/impeccable/scripts/live/insert-ui.mjs +0 -458
  894. package/dist/builtin/workflows/skills/impeccable/scripts/live/instructions.mjs +0 -169
  895. package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-apply.mjs +0 -939
  896. package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-edit-routes.mjs +0 -357
  897. package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-edits-buffer.mjs +0 -152
  898. package/dist/builtin/workflows/skills/impeccable/scripts/live/poll-lanes.mjs +0 -14
  899. package/dist/builtin/workflows/skills/impeccable/scripts/live/roots.mjs +0 -670
  900. package/dist/builtin/workflows/skills/impeccable/scripts/live/session-store.mjs +0 -563
  901. package/dist/builtin/workflows/skills/impeccable/scripts/live/source-lock.mjs +0 -105
  902. package/dist/builtin/workflows/skills/impeccable/scripts/live/source-search.mjs +0 -105
  903. package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-ast.mjs +0 -969
  904. package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-component.mjs +0 -1401
  905. package/dist/builtin/workflows/skills/impeccable/scripts/live/sveltekit-adapter.mjs +0 -314
  906. package/dist/builtin/workflows/skills/impeccable/scripts/live/tanstack-adapter.mjs +0 -280
  907. package/dist/builtin/workflows/skills/impeccable/scripts/live/ui-surfaces.mjs +0 -75
  908. package/dist/builtin/workflows/skills/impeccable/scripts/live/vocabulary.mjs +0 -171
  909. package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +0 -961
  910. package/dist/builtin/workflows/skills/impeccable/scripts/live-commit-manual-edits.mjs +0 -1244
  911. package/dist/builtin/workflows/skills/impeccable/scripts/live-complete.mjs +0 -107
  912. package/dist/builtin/workflows/skills/impeccable/scripts/live-copy-edit-agent.mjs +0 -800
  913. package/dist/builtin/workflows/skills/impeccable/scripts/live-discard-manual-edits.mjs +0 -51
  914. package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +0 -515
  915. package/dist/builtin/workflows/skills/impeccable/scripts/live-insert.mjs +0 -292
  916. package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +0 -371
  917. package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +0 -427
  918. package/dist/builtin/workflows/skills/impeccable/scripts/live-resume.mjs +0 -123
  919. package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +0 -1675
  920. package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +0 -71
  921. package/dist/builtin/workflows/skills/impeccable/scripts/live-target.mjs +0 -30
  922. package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +0 -927
  923. package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +0 -365
  924. package/dist/builtin/workflows/skills/impeccable/scripts/palette.mjs +0 -628
  925. package/dist/builtin/workflows/skills/impeccable/scripts/pin.mjs +0 -224
  926. package/dist/builtin/workflows/skills/impeccable/scripts/serve-question.mjs +0 -1540
  927. package/dist/builtin/workflows/skills/impeccable/scripts/surface-brief.mjs +0 -74
  928. package/docs/models/artificial-analysis-index.md +0 -89
  929. package/docs/models/pareto-efficiency.md +0 -90
  930. package/docs/tools/edit.md +0 -378
@@ -1,2813 +0,0 @@
1
- import {
2
- VERIFICATION_SCALE
3
- } from "./chunk-n1910xc4.js";
4
- import {
5
- DEFAULT_RISE_DELTA,
6
- DEFAULT_FALL_DELTA,
7
- classify_trend
8
- } from "./chunk-z0d03ktm.js";
9
- import {
10
- scoring_prompt_reads,
11
- build_scoring_prompt
12
- } from "./chunk-2377r57g.js";
13
-
14
- // dist/builtin/workflows/src/shared/workflow-artifacts.ts
15
- import { randomUUID as randomUUID2 } from "node:crypto";
16
- import { mkdir, readdir, rm, stat } from "node:fs/promises";
17
- import { dirname, join } from "node:path";
18
- import { getAgentDir, getEnvValue } from "@bastani/atomic";
19
- // dist/builtin/workflows/src/durable/backend-process-owner.ts
20
- var DURABLE_BACKEND_PROCESS_OWNER_KEY = Symbol.for("atomic-workflows/durable-backend-process-owner@1");
21
- function emptyOwner() {
22
- return {
23
- version: 1,
24
- injectedBackend: undefined,
25
- initializedBackend: undefined,
26
- initializing: undefined,
27
- warningSink: undefined,
28
- warningReported: false
29
- };
30
- }
31
- function ownerBag() {
32
- return globalThis;
33
- }
34
- function getDurableBackendProcessOwner() {
35
- const bag = ownerBag();
36
- const existing = bag[DURABLE_BACKEND_PROCESS_OWNER_KEY];
37
- if (existing !== undefined && existing.version === 1)
38
- return existing;
39
- const created = emptyOwner();
40
- bag[DURABLE_BACKEND_PROCESS_OWNER_KEY] = created;
41
- return created;
42
- }
43
- // dist/builtin/workflows/src/shared/possible-stages.ts
44
- var BUILTIN_BARREL_SPECIFIERS = new Set([
45
- "@bastani/atomic/workflows/builtin",
46
- "@bastani/workflows/builtin"
47
- ]);
48
- var TRACKED_NODE_METHODS = new Set(["stage", "task", "chain", "parallel", "workflow", "tool"]);
49
-
50
- // dist/builtin/workflows/src/shared/workflow-failures-contract.ts
51
- var WORKFLOW_FAILURE_KINDS = new Set([
52
- "auth",
53
- "rate_limit",
54
- "provider",
55
- "cancelled",
56
- "unknown"
57
- ]);
58
-
59
- // dist/builtin/workflows/src/shared/workflow-failures-decisions.ts
60
- var INVALID_API_KEY_CODES = new Set([
61
- "401",
62
- "invalid_api_key",
63
- "incorrect_api_key",
64
- "invalid_api_key_error",
65
- "invalid_credentials",
66
- "bad_credentials",
67
- "authentication_error"
68
- ]);
69
- var LOGIN_REQUIRED_CODES = new Set([
70
- "auth",
71
- "auth_required",
72
- "authentication_required",
73
- "login_required",
74
- "not_logged_in"
75
- ]);
76
- var MISSING_API_KEY_CODES = new Set(["missing_api_key", "api_key_missing", "no_api_key"]);
77
- var RATE_LIMIT_CODES = new Set(["429", "rate_limit", "rate_limited", "rate_limit_exceeded", "too_many_requests"]);
78
- var QUOTA_LIMIT_CODES = new Set([
79
- "quota",
80
- "quota_exceeded",
81
- "insufficient_quota",
82
- "usage_limit",
83
- "usage_limit_exceeded"
84
- ]);
85
- var CANCELLED_CODES = new Set(["aborterror", "aborted", "cancelled", "canceled"]);
86
- var PROVIDER_UNAVAILABLE_CODES = new Set([
87
- "500",
88
- "502",
89
- "503",
90
- "504",
91
- "provider_error",
92
- "service_unavailable",
93
- "temporarily_unavailable",
94
- "overloaded",
95
- "timeout",
96
- "network_error"
97
- ]);
98
- var UNKNOWN_MODEL_CODES = new Set(["unknown_model", "model_not_found", "model_not_available", "unsupported_model"]);
99
- var FORBIDDEN_CONFIG_CODES = new Set([
100
- "403",
101
- "forbidden",
102
- "permission_denied",
103
- "access_denied",
104
- "forbidden_config",
105
- "invalid_model_config",
106
- "model_access_denied"
107
- ]);
108
- var INVALID_API_KEY_CONTEXT = new Set(["invalid", "incorrect"]);
109
- var AUTH_CONTEXT = new Set([
110
- "token",
111
- "credential",
112
- "credentials",
113
- "required",
114
- "expired",
115
- "invalid",
116
- "missing",
117
- "unauthorized",
118
- "login",
119
- "signin"
120
- ]);
121
- var MODEL_PROVIDER_CONTEXT = new Set(["unavailable", "overloaded", "temporarily", "service"]);
122
- var PROVIDER_CONTEXT = new Set(["error", "failure", "failed", "overloaded", "unavailable", "temporarily", "service"]);
123
- var STATUS_MESSAGE_REFINEMENT_CODES = new Set([
124
- "invalid_api_key",
125
- "missing_api_key",
126
- "unknown_model",
127
- "forbidden_config"
128
- ]);
129
- var BROAD_AUTH_MESSAGE_REFINEMENT_CODES = new Set([
130
- "invalid_api_key",
131
- "missing_api_key"
132
- ]);
133
- var STATUS_RELATED_MESSAGE_REFINEMENT_CODES = new Set([
134
- "invalid_api_key",
135
- "missing_api_key",
136
- "unknown_model",
137
- "forbidden_config",
138
- "rate_limited",
139
- "quota_limited",
140
- "cancelled"
141
- ]);
142
- // dist/builtin/workflows/src/durable/dbos-process-owner.ts
143
- var DBOS_PROCESS_OWNER_KEY = Symbol.for("atomic-workflows/dbos-process-owner@1");
144
- function emptyOwner2() {
145
- return {
146
- version: 1,
147
- state: "uninitialized",
148
- configured: undefined,
149
- active: undefined,
150
- launchPromise: undefined,
151
- shutdownPromise: undefined,
152
- failure: undefined,
153
- wrappers: undefined
154
- };
155
- }
156
- function ownerBag2() {
157
- return globalThis;
158
- }
159
- function getDbosProcessOwner() {
160
- const bag = ownerBag2();
161
- const existing = bag[DBOS_PROCESS_OWNER_KEY];
162
- if (existing !== undefined && existing.version === 1)
163
- return existing;
164
- const created = emptyOwner2();
165
- bag[DBOS_PROCESS_OWNER_KEY] = created;
166
- return created;
167
- }
168
-
169
- // dist/builtin/workflows/src/durable/dbos-sdk-handle.ts
170
- var ATOMIC_EXECUTOR_ID = `atomic-${process.pid.toString(36)}-${crypto.randomUUID().slice(0, 8)}`;
171
-
172
- // dist/builtin/workflows/src/durable/local-command.ts
173
- import { createChildProcessEnvironment } from "@bastani/atomic";
174
-
175
- // dist/builtin/workflows/src/durable/dbos-embedded-postgres-root.ts
176
- var HASH_CHUNK_BYTES = 64 * 1024;
177
-
178
- // dist/builtin/workflows/src/durable/dbos-embedded-postgres.ts
179
- var EMBEDDED_HOST = "127.0.0.1";
180
- var EMBEDDED_PORT = 5439;
181
- var EMBEDDED_USER = "postgres";
182
- var EMBEDDED_PASSWORD = "atomic";
183
- var EMBEDDED_DBOS_SYSTEM_DATABASE_URL = `postgresql://${EMBEDDED_USER}:${EMBEDDED_PASSWORD}@${EMBEDDED_HOST}:${EMBEDDED_PORT}/atomic_workflows_dbos_sys?connect_timeout=10&sslmode=disable`;
184
-
185
- // dist/builtin/workflows/src/durable/dbos-lifecycle.ts
186
- class DbosDurabilityError extends Error {
187
- constructor(message, options) {
188
- super(message, options);
189
- this.name = "DbosDurabilityError";
190
- }
191
- }
192
-
193
- class DbosNotReadyError extends DbosDurabilityError {
194
- constructor() {
195
- super("DBOS workflow durability is not ready. Await initializeDurableBackend() before accessing workflows.");
196
- this.name = "DbosNotReadyError";
197
- }
198
- }
199
- function owner() {
200
- return getDbosProcessOwner();
201
- }
202
- function getReadyDbosBackendSync() {
203
- const slot = owner();
204
- return slot.state === "ready" ? slot.active?.backend : undefined;
205
- }
206
- function dbosLifecycleState() {
207
- return owner().state;
208
- }
209
-
210
- // dist/builtin/workflows/src/durable/factory.ts
211
- function isMemoizedBackendUsable(backend) {
212
- return !backend.persistent || dbosLifecycleState() === "ready";
213
- }
214
- function getDurableBackend() {
215
- const owner = getDurableBackendProcessOwner();
216
- const memoized = owner.initializedBackend !== undefined && isMemoizedBackendUsable(owner.initializedBackend) ? owner.initializedBackend : undefined;
217
- const backend = owner.injectedBackend ?? memoized ?? getReadyDbosBackendSync();
218
- if (backend === undefined)
219
- throw new DbosNotReadyError;
220
- return backend;
221
- }
222
-
223
- // dist/builtin/workflows/src/shared/pending-stage-delivery.ts
224
- var PENDING_STAGE_MESSAGE_LIMIT = 50;
225
- var PENDING_STAGE_UNDELIVERABLE_NOTIFICATION_PREFIX = "atomic-pending-stage-undeliverable";
226
- function queueStageMessage(messages, input, senderGroup, runGroup, stageIdentity) {
227
- if (normalizeDeliveryGroup(senderGroup) !== normalizeDeliveryGroup(runGroup)) {
228
- return { ok: false, reason: "group_mismatch", runId: input.runId, stageKey: input.stageKey };
229
- }
230
- const messageId = input.message.id;
231
- const queued = pendingStageMessagesFor(messages, input.runId, input.stageKey, stageIdentity);
232
- const existing = messages.find((entry) => entry.runId === input.runId && entry.id === messageId);
233
- if (existing !== undefined) {
234
- if (pendingStageMessageSignature(existing, stageIdentity) !== pendingStageMessageSignature(input, stageIdentity)) {
235
- return {
236
- ok: false,
237
- reason: "message_id_conflict",
238
- runId: input.runId,
239
- stageKey: input.stageKey,
240
- messageId
241
- };
242
- }
243
- const queuedPosition = queued.indexOf(existing);
244
- return {
245
- ok: true,
246
- messages,
247
- entry: existing,
248
- ...queuedPosition >= 0 ? { position: queuedPosition + 1 } : {},
249
- deduplicated: true
250
- };
251
- }
252
- if (queued.length >= PENDING_STAGE_MESSAGE_LIMIT) {
253
- return {
254
- ok: false,
255
- reason: "capacity",
256
- limit: PENDING_STAGE_MESSAGE_LIMIT,
257
- runId: input.runId,
258
- stageKey: input.stageKey
259
- };
260
- }
261
- const entry = {
262
- ...input,
263
- id: messageId,
264
- ...stageIdentity !== undefined ? { stageId: stageIdentity.id } : {},
265
- ...stageIdentity?.replayKey !== undefined ? { stageReplayKey: stageIdentity.replayKey } : {},
266
- admissionOrder: nextAdmissionOrder(messages, input.runId),
267
- status: "queued"
268
- };
269
- return {
270
- ok: true,
271
- messages: [...messages, entry],
272
- entry,
273
- position: queued.length + 1,
274
- deduplicated: false
275
- };
276
- }
277
- function queueStickyStageMessage(messages, input, senderGroup, runGroup) {
278
- if (normalizeDeliveryGroup(senderGroup) !== normalizeDeliveryGroup(runGroup)) {
279
- return { ok: false, reason: "group_mismatch", runId: input.runId, stageKey: input.targetPath };
280
- }
281
- const messageId = input.message.id;
282
- const existing = messages.find((entry) => entry.runId === input.runId && entry.id === messageId);
283
- if (existing !== undefined) {
284
- if (pendingStageMessageSignature(existing) !== pendingStageMessageSignature(input)) {
285
- return {
286
- ok: false,
287
- reason: "message_id_conflict",
288
- runId: input.runId,
289
- stageKey: input.targetPath,
290
- messageId
291
- };
292
- }
293
- const queuedForTarget = queuedStickyCount(messages, input.runId, input.targetPath);
294
- return {
295
- ok: true,
296
- messages,
297
- entry: existing,
298
- ...existing.status === "queued" ? { position: queuedForTarget } : {},
299
- deduplicated: true
300
- };
301
- }
302
- if (queuedStickyCount(messages, input.runId, input.targetPath) >= PENDING_STAGE_MESSAGE_LIMIT) {
303
- return {
304
- ok: false,
305
- reason: "capacity",
306
- limit: PENDING_STAGE_MESSAGE_LIMIT,
307
- runId: input.runId,
308
- stageKey: input.targetPath
309
- };
310
- }
311
- const entry = {
312
- ...input,
313
- id: messageId,
314
- stageKey: input.targetPath,
315
- sticky: true,
316
- deliveries: [],
317
- deliveryCount: 0,
318
- admissionOrder: nextAdmissionOrder(messages, input.runId),
319
- status: "queued"
320
- };
321
- return {
322
- ok: true,
323
- messages: [...messages, entry],
324
- entry,
325
- position: queuedStickyCount(messages, input.runId, input.targetPath) + 1,
326
- deduplicated: false
327
- };
328
- }
329
- function queuedStickyCount(messages, runId, targetPath) {
330
- return messages.filter((entry) => entry.runId === runId && entry.sticky === true && entry.targetPath === targetPath && entry.status === "queued").length;
331
- }
332
- function recordPendingStageMessageDeliveries(messages, runId, messageId, records, deliveredAt) {
333
- const index = messages.findIndex((entry) => entry.runId === runId && entry.id === messageId && entry.sticky === true && entry.status === "queued");
334
- if (index < 0)
335
- return messages;
336
- const entry = messages[index];
337
- const recorded = new Set((entry.deliveries ?? []).map((delivery) => `${delivery.runId}\x00${delivery.stageId}`));
338
- const additions = [];
339
- for (const record of records) {
340
- const key = `${record.runId}\x00${record.stageId}`;
341
- if (recorded.has(key))
342
- continue;
343
- recorded.add(key);
344
- additions.push({
345
- runId: record.runId,
346
- stageId: record.stageId,
347
- ...record.stageName === undefined ? {} : { stageName: record.stageName },
348
- deliveredAt
349
- });
350
- }
351
- if (additions.length === 0)
352
- return messages;
353
- const deliveries = [...entry.deliveries ?? [], ...additions];
354
- const next = { ...entry, deliveries, deliveryCount: deliveries.length };
355
- const result = [...messages];
356
- result[index] = next;
357
- return result;
358
- }
359
- function settleStickyPendingStageMessageDelivered(messages, runId, messageId, settledAt) {
360
- const index = messages.findIndex((entry) => entry.runId === runId && entry.id === messageId && entry.sticky === true && entry.status === "queued" && (entry.deliveryCount ?? 0) > 0);
361
- if (index < 0)
362
- return messages;
363
- const next = [...messages];
364
- next[index] = { ...next[index], status: "delivered", deliveredAt: settledAt };
365
- return next;
366
- }
367
- function pendingStageMessagesFor(messages, runId, stageKey, stageIdentity) {
368
- return messages.map((entry, index) => ({ entry, index })).filter(({ entry }) => matchesPendingStage(entry, runId, stageKey, stageIdentity) && entry.status === "queued").sort((left, right) => (left.entry.admissionOrder ?? left.index + 1) - (right.entry.admissionOrder ?? right.index + 1) || left.index - right.index).map(({ entry }) => entry);
369
- }
370
- function markPendingStageMessageDelivered(messages, runId, stageKey, messageId, deliveredAt, stageIdentity) {
371
- return updateQueuedPendingStageMessage(messages, runId, stageKey, messageId, stageIdentity, (entry) => ({
372
- ...entry,
373
- status: "delivered",
374
- deliveredAt
375
- }));
376
- }
377
- function markPendingStageMessageUndeliverable(messages, runId, stageKey, messageId, reason, stageIdentity) {
378
- return updateQueuedPendingStageMessage(messages, runId, stageKey, messageId, stageIdentity, (entry) => ({
379
- ...entry,
380
- status: "undeliverable",
381
- undeliverableReason: reason,
382
- undeliverableNotificationId: pendingStageUndeliverableNotificationId(entry)
383
- }));
384
- }
385
- function markPendingStageMessageUndeliverableNotified(messages, runId, stageKey, messageId, notificationId, notifiedAt) {
386
- const index = messages.findIndex((entry) => (entry.sticky === true ? entry.runId === runId : matchesPendingStage(entry, runId, stageKey)) && entry.id === messageId && entry.status === "undeliverable" && entry.undeliverableNotificationId === notificationId && entry.undeliverableNotifiedAt === undefined);
387
- if (index < 0)
388
- return messages;
389
- const next = [...messages];
390
- next[index] = { ...next[index], undeliverableNotifiedAt: notifiedAt };
391
- return next;
392
- }
393
- function pendingStageUndeliverableNotificationId(entry) {
394
- return [
395
- PENDING_STAGE_UNDELIVERABLE_NOTIFICATION_PREFIX,
396
- encodeURIComponent(entry.runId),
397
- encodeURIComponent(entry.stageKey),
398
- encodeURIComponent(entry.id)
399
- ].join(":");
400
- }
401
- function updateQueuedPendingStageMessage(messages, runId, stageKey, messageId, stageIdentity, update) {
402
- const index = messages.findIndex((entry) => queuedEntryMatches(entry, runId, stageKey, messageId, stageIdentity));
403
- if (index < 0)
404
- return messages;
405
- const next = [...messages];
406
- next[index] = update(next[index]);
407
- return next;
408
- }
409
- function queuedEntryMatches(entry, runId, stageKey, messageId, stageIdentity) {
410
- if (entry.runId !== runId || entry.id !== messageId || entry.status !== "queued")
411
- return false;
412
- return entry.sticky === true || matchesPendingStage(entry, runId, stageKey, stageIdentity);
413
- }
414
- function matchesPendingStage(entry, runId, stageKey, stageIdentity) {
415
- if (entry.sticky === true)
416
- return false;
417
- if (entry.runId !== runId)
418
- return false;
419
- if (stageIdentity === undefined)
420
- return entry.stageKey === stageKey;
421
- return entry.stageId === stageIdentity.id || entry.stageReplayKey !== undefined && entry.stageReplayKey === stageIdentity.replayKey || entry.stageId === undefined && stageIdentity.aliases.includes(entry.stageKey);
422
- }
423
- function nextAdmissionOrder(messages, runId) {
424
- let greatest = 0;
425
- let legacyPosition = 0;
426
- for (const entry of messages) {
427
- if (entry.runId !== runId)
428
- continue;
429
- legacyPosition += 1;
430
- greatest = Math.max(greatest, entry.admissionOrder ?? legacyPosition);
431
- }
432
- return greatest + 1;
433
- }
434
- function pendingStageMessageSignature(entry, stageIdentity) {
435
- const storedTarget = "status" in entry ? entry.stageReplayKey ?? entry.stageId : undefined;
436
- const { timestamp: transportTimestamp, ...logicalMessage } = entry.message;
437
- return stableJson({
438
- target: storedTarget ?? stageIdentity?.replayKey ?? stageIdentity?.id ?? entry.stageKey,
439
- sender: entry.senderReturnAddress ?? entry.from.id,
440
- message: {
441
- ...logicalMessage,
442
- expectsReply: logicalMessage.expectsReply ?? false,
443
- content: {
444
- ...logicalMessage.content,
445
- attachments: logicalMessage.content.attachments ?? []
446
- }
447
- }
448
- });
449
- }
450
- function stableJson(value) {
451
- return JSON.stringify(sortJsonValue(value));
452
- }
453
- function sortJsonValue(value) {
454
- if (Array.isArray(value))
455
- return value.map(sortJsonValue);
456
- if (typeof value !== "object" || value === null)
457
- return value;
458
- return Object.fromEntries(Object.entries(value).filter(([, nested]) => nested !== undefined).sort(([left], [right]) => left.localeCompare(right)).map(([key, nested]) => [key, sortJsonValue(nested)]));
459
- }
460
- function normalizeDeliveryGroup(value) {
461
- if (typeof value !== "string")
462
- return "default";
463
- const trimmed = value.trim();
464
- return trimmed.length > 0 ? trimmed : "default";
465
- }
466
- // dist/builtin/workflows/src/shared/session-scoped-singleton.ts
467
- import { sessionScopedExtensionState } from "@bastani/atomic";
468
- var SHARED_STATES_KEY = Symbol.for("atomic-workflows/session-scoped-singleton-pre-adoption@1");
469
- function processBag() {
470
- return globalThis;
471
- }
472
- function recordLocal(key, local) {
473
- const bag = processBag();
474
- let states = bag[SHARED_STATES_KEY];
475
- if (states === undefined || states.version !== 1) {
476
- states = { version: 1, byKey: new Map };
477
- bag[SHARED_STATES_KEY] = states;
478
- }
479
- const existing = states.byKey.get(key);
480
- if (existing !== undefined)
481
- return existing;
482
- const created = { local, instance: undefined, localClaimed: false };
483
- states.byKey.set(key, created);
484
- return created;
485
- }
486
- function createSessionScopedSingleton(key, createLocal) {
487
- const local = createLocal();
488
- const shared = recordLocal(key, local);
489
- let instance = local;
490
- const live = () => shared.instance ?? instance;
491
- const current = () => live();
492
- const adoptWithResult = (scope, options) => {
493
- const current = live();
494
- let targetCreated = false;
495
- const target = sessionScopedExtensionState(scope, key, () => {
496
- targetCreated = true;
497
- if (shared.localClaimed)
498
- return createLocal();
499
- shared.localClaimed = true;
500
- return shared.local;
501
- });
502
- const preservedCurrent = !targetCreated && target !== current && options?.preserveCurrentWhenTargetExists?.(current, target) === true;
503
- shared.instance = preservedCurrent ? current : target;
504
- instance = shared.instance;
505
- return { instance: shared.instance, preservedCurrent };
506
- };
507
- const adopt = (scope, options) => adoptWithResult(scope, options).instance;
508
- const facade = new Proxy(local, {
509
- get(_target, prop) {
510
- const value = Reflect.get(live(), prop, live());
511
- if (typeof value === "function") {
512
- return value.bind(live());
513
- }
514
- return value;
515
- },
516
- has(_target, prop) {
517
- return Reflect.has(live(), prop);
518
- }
519
- });
520
- return { facade, adopt, adoptWithResult, current };
521
- }
522
-
523
- // dist/builtin/workflows/src/shared/flat-string.ts
524
- function flattenTruncatedString(value) {
525
- return value.split("").join("");
526
- }
527
-
528
- // dist/builtin/workflows/src/shared/tool-payload-bounds.ts
529
- var TOOL_PAYLOAD_MAX_KEYS = 2048;
530
- var TOOL_PAYLOAD_VALUE_LIMIT = 16384;
531
- var TOOL_PAYLOAD_TRUNCATION_MARKER = "… [truncated]";
532
- var TOOL_PAYLOAD_CYCLE_PLACEHOLDER = "<cycle>";
533
- var TOOL_PAYLOAD_UNREADABLE_PLACEHOLDER = "<unreadable>";
534
- var TOOL_PAYLOAD_UNSERIALIZABLE_PLACEHOLDER = "<unserializable>";
535
- var TOOL_PAYLOAD_TRUNCATION_KEY = "…";
536
- var TOOL_PAYLOAD_MAX_DEPTH = 256;
537
- function isOmittedJsonValue(value) {
538
- return value === undefined || typeof value === "function" || typeof value === "symbol";
539
- }
540
- function isToolPayloadObject(value) {
541
- return value !== null && typeof value === "object" && !Array.isArray(value);
542
- }
543
- function isToolPayloadArray(value) {
544
- return Array.isArray(value);
545
- }
546
- function isToolPayloadObjectLike(value) {
547
- return value !== null && typeof value === "object";
548
- }
549
- function isToolPayloadCallable(value) {
550
- return typeof value === "function";
551
- }
552
- function readToolPayloadProperty(value, key) {
553
- try {
554
- const property = Reflect.get(value, key);
555
- return { ok: true, value: property };
556
- } catch {
557
- return { ok: false };
558
- }
559
- }
560
- function safeProperty(value, key) {
561
- const result = readToolPayloadProperty(value, key);
562
- return result.ok ? result.value : TOOL_PAYLOAD_UNREADABLE_PLACEHOLDER;
563
- }
564
- function safeOwnKeys(value, consumeKey) {
565
- let stopped = false;
566
- function* enumerate() {
567
- let keys;
568
- try {
569
- keys = Reflect.ownKeys(value);
570
- } catch {
571
- return;
572
- }
573
- for (const key of keys) {
574
- if (!consumeKey()) {
575
- stopped = true;
576
- return;
577
- }
578
- if (typeof key !== "string")
579
- continue;
580
- let descriptor;
581
- try {
582
- descriptor = Object.getOwnPropertyDescriptor(value, key);
583
- } catch {
584
- continue;
585
- }
586
- if (descriptor?.enumerable === true)
587
- yield key;
588
- }
589
- }
590
- return { keys: enumerate(), stoppedByLimit: () => stopped };
591
- }
592
- function safeArrayLength(value) {
593
- const result = readToolPayloadProperty(value, "length");
594
- if (!result.ok || typeof result.value !== "number")
595
- return 0;
596
- return Number.isSafeInteger(result.value) && result.value > 0 ? result.value : 0;
597
- }
598
- function resolveJsonValue(value) {
599
- if (!isToolPayloadObjectLike(value))
600
- return value;
601
- const toJson = readToolPayloadProperty(value, "toJSON");
602
- if (!toJson.ok)
603
- return TOOL_PAYLOAD_UNREADABLE_PLACEHOLDER;
604
- if (!isToolPayloadCallable(toJson.value))
605
- return value;
606
- try {
607
- return toJson.value.call(value);
608
- } catch {
609
- return TOOL_PAYLOAD_UNSERIALIZABLE_PLACEHOLDER;
610
- }
611
- }
612
- var NULL_COST = 4;
613
- var NUMBER_COST = 8;
614
- var BOOLEAN_COST = 5;
615
- var CONTAINER_COST = 2;
616
- var SEPARATOR_COST = 1;
617
- function consumeKeyBudget(state) {
618
- if (state.keysRemaining <= 0)
619
- return false;
620
- state.keysRemaining -= 1;
621
- return true;
622
- }
623
- function addTruncationMarker(record) {
624
- let key = TOOL_PAYLOAD_TRUNCATION_KEY;
625
- let suffix = 1;
626
- while (Object.hasOwn(record, key))
627
- key = `${TOOL_PAYLOAD_TRUNCATION_KEY}${suffix++}`;
628
- record[key] = TOOL_PAYLOAD_TRUNCATION_MARKER;
629
- }
630
- function cloneObjectLike(state, value) {
631
- if (state.seen.has(value))
632
- return TOOL_PAYLOAD_CYCLE_PLACEHOLDER;
633
- if (state.depth >= TOOL_PAYLOAD_MAX_DEPTH)
634
- return TOOL_PAYLOAD_TRUNCATION_MARKER;
635
- state.seen.add(value);
636
- state.depth += 1;
637
- state.remaining -= CONTAINER_COST;
638
- try {
639
- if (isToolPayloadArray(value)) {
640
- const items = [];
641
- const length = safeArrayLength(value);
642
- for (let index = 0;index < length; index++) {
643
- if (state.remaining <= 0) {
644
- items.push(TOOL_PAYLOAD_TRUNCATION_MARKER);
645
- break;
646
- }
647
- state.remaining -= SEPARATOR_COST;
648
- const item = safeProperty(value, index);
649
- if (isOmittedJsonValue(item)) {
650
- state.remaining -= NULL_COST;
651
- items.push(null);
652
- continue;
653
- }
654
- items.push(cloneValue(state, item));
655
- }
656
- return items;
657
- }
658
- const cloned = {};
659
- const scan = safeOwnKeys(value, () => state.remaining > 0 && consumeKeyBudget(state));
660
- for (const key of scan.keys) {
661
- state.remaining -= key.length + SEPARATOR_COST;
662
- const child = safeProperty(value, key);
663
- if (isOmittedJsonValue(child))
664
- continue;
665
- cloned[key] = cloneValue(state, child);
666
- }
667
- if (scan.stoppedByLimit())
668
- addTruncationMarker(cloned);
669
- return cloned;
670
- } finally {
671
- state.depth -= 1;
672
- state.seen.delete(value);
673
- }
674
- }
675
- function cloneValue(state, value) {
676
- const resolved = resolveJsonValue(value);
677
- if (resolved === null) {
678
- state.remaining -= NULL_COST;
679
- return null;
680
- }
681
- switch (typeof resolved) {
682
- case "string":
683
- return cloneString(state, resolved);
684
- case "number":
685
- state.remaining -= NUMBER_COST;
686
- return Number.isFinite(resolved) ? resolved : null;
687
- case "boolean":
688
- state.remaining -= BOOLEAN_COST;
689
- return resolved;
690
- case "object":
691
- return cloneObjectLike(state, resolved);
692
- case "bigint":
693
- state.remaining -= NUMBER_COST;
694
- return resolved;
695
- default:
696
- state.remaining -= TOOL_PAYLOAD_UNSERIALIZABLE_PLACEHOLDER.length;
697
- return TOOL_PAYLOAD_UNSERIALIZABLE_PLACEHOLDER;
698
- }
699
- }
700
- function boundedToolPayload(value, limit = TOOL_PAYLOAD_VALUE_LIMIT) {
701
- return cloneValue({ remaining: Math.max(1, limit), depth: 0, keysRemaining: TOOL_PAYLOAD_MAX_KEYS, seen: new Set }, value);
702
- }
703
- function boundedToolPayloadRecord(value, limit = TOOL_PAYLOAD_VALUE_LIMIT) {
704
- const record = {};
705
- if (!isToolPayloadObject(value) && !isToolPayloadArray(value))
706
- return record;
707
- const state = {
708
- remaining: Math.max(1, limit),
709
- depth: 0,
710
- keysRemaining: TOOL_PAYLOAD_MAX_KEYS,
711
- seen: new Set([value])
712
- };
713
- const scan = safeOwnKeys(value, () => state.remaining > 0 && consumeKeyBudget(state));
714
- for (const key of scan.keys) {
715
- state.remaining -= key.length + SEPARATOR_COST;
716
- const child = safeProperty(value, key);
717
- if (isOmittedJsonValue(child))
718
- continue;
719
- record[key] = cloneValue(state, child);
720
- }
721
- if (scan.stoppedByLimit())
722
- addTruncationMarker(record);
723
- return record;
724
- }
725
- function cloneString(state, value) {
726
- if (state.remaining <= 0)
727
- return TOOL_PAYLOAD_TRUNCATION_MARKER;
728
- if (value.length <= state.remaining) {
729
- state.remaining -= value.length;
730
- return value;
731
- }
732
- const keep = state.remaining;
733
- state.remaining = 0;
734
- return `${flattenTruncatedString(value.slice(0, keep))}${TOOL_PAYLOAD_TRUNCATION_MARKER}`;
735
- }
736
- function boundedToolText(value, limit = TOOL_PAYLOAD_VALUE_LIMIT) {
737
- const cap = Math.max(TOOL_PAYLOAD_TRUNCATION_MARKER.length + 1, limit);
738
- if (value.length <= cap)
739
- return value;
740
- const keep = Math.max(0, cap - TOOL_PAYLOAD_TRUNCATION_MARKER.length);
741
- return `${flattenTruncatedString(value.slice(0, keep))}${TOOL_PAYLOAD_TRUNCATION_MARKER}`;
742
- }
743
-
744
- // dist/builtin/workflows/src/shared/graph-store-snapshot.ts
745
- var COMPACT_RESULT_FIELD_LIMIT = 1024;
746
- var COMPACT_EXIT_OUTPUT_LIMIT = COMPACT_RESULT_FIELD_LIMIT * 4;
747
- function compactResultField(value) {
748
- if (typeof value !== "string")
749
- return;
750
- if (value.length <= COMPACT_RESULT_FIELD_LIMIT)
751
- return value;
752
- return flattenTruncatedString(value.slice(0, COMPACT_RESULT_FIELD_LIMIT));
753
- }
754
- function compactRunResult(result, preserveExitedOutputs = false) {
755
- if (result === undefined)
756
- return;
757
- const status = compactResultField(result.status);
758
- const summary = compactResultField(result.summary);
759
- const remainingWork = compactResultField(result.remaining_work);
760
- const resultText = compactResultField(result.result);
761
- const budgetDimension = status === "budget_exceeded" && (result.dimension === "duration" || result.dimension === "tokens" || result.dimension === "cost") ? result.dimension : undefined;
762
- const compact = {
763
- ...status !== undefined ? { status } : {},
764
- ...summary !== undefined ? { summary } : {},
765
- ...remainingWork !== undefined ? { remaining_work: remainingWork } : {},
766
- ...resultText !== undefined ? { result: resultText } : {},
767
- ...budgetDimension !== undefined ? { dimension: budgetDimension } : {}
768
- };
769
- if (!preserveExitedOutputs)
770
- return Object.keys(compact).length === 0 ? undefined : compact;
771
- return compactExitedOutputs(result, compact);
772
- }
773
- function compactExitedOutputs(result, compact) {
774
- try {
775
- const serialized = JSON.stringify(result);
776
- if (serialized !== undefined && serialized.length <= COMPACT_EXIT_OUTPUT_LIMIT) {
777
- const parsed = JSON.parse(serialized);
778
- if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
779
- return compactExitedObject(parsed);
780
- }
781
- }
782
- } catch {}
783
- return Object.keys(compact).length === 0 ? undefined : compact;
784
- }
785
- function compactExitedObject(result) {
786
- const compacted = { ...result };
787
- for (const key of ["status", "summary", "remaining_work", "result"]) {
788
- const value = compacted[key];
789
- if (typeof value === "string")
790
- compacted[key] = compactResultField(value) ?? "";
791
- }
792
- return Object.keys(compacted).length === 0 ? undefined : compacted;
793
- }
794
- function clonePrompt(prompt) {
795
- return {
796
- ...prompt,
797
- ...prompt.choices !== undefined ? { choices: [...prompt.choices] } : {}
798
- };
799
- }
800
- function cloneInputRequest(request) {
801
- return {
802
- ...request,
803
- questions: request.questions.map((question) => ({
804
- ...question,
805
- options: question.options.map((option) => ({ ...option }))
806
- }))
807
- };
808
- }
809
- function compactToolEvents(events) {
810
- const event = events.at(-1);
811
- return event === undefined ? [] : [{ name: event.name }];
812
- }
813
- function compactWorkflowChild(child) {
814
- return {
815
- ...child,
816
- outputs: {},
817
- outputCount: child.outputCount ?? Object.keys(child.outputs).length
818
- };
819
- }
820
- function compactStage(stage) {
821
- const {
822
- toolEvents,
823
- workflowChild,
824
- workflowChildRun,
825
- pendingPrompt,
826
- promptFootprint,
827
- inputRequest,
828
- notices,
829
- mcpScope: _mcpScope,
830
- attemptedModels: _attemptedModels,
831
- modelAttempts: _modelAttempts,
832
- result: _result,
833
- structured: _structured,
834
- ...metadata
835
- } = stage;
836
- return {
837
- ...metadata,
838
- parentIds: [...stage.parentIds],
839
- toolEvents: compactToolEvents(toolEvents),
840
- ...workflowChild !== undefined ? { workflowChild: compactWorkflowChild(workflowChild) } : {},
841
- ...workflowChildRun !== undefined ? { workflowChildRun: { ...workflowChildRun } } : {},
842
- ...pendingPrompt !== undefined ? { pendingPrompt: clonePrompt(pendingPrompt) } : {},
843
- ...promptFootprint !== undefined ? { promptFootprint: clonePrompt(promptFootprint) } : {},
844
- ...inputRequest !== undefined ? { inputRequest: cloneInputRequest(inputRequest) } : {},
845
- ...notices !== undefined ? { notices: notices.map((notice) => ({ ...notice })) } : {}
846
- };
847
- }
848
- function compactToolNode(node) {
849
- return {
850
- ...node,
851
- parentIds: [...node.parentIds],
852
- ...node.args !== undefined ? { args: boundedToolPayloadRecord(node.args) } : {},
853
- ...node.result !== undefined ? { result: boundedToolPayload(node.result) } : {},
854
- ...node.source !== undefined ? { source: boundedToolText(node.source) } : {}
855
- };
856
- }
857
- function compactRun(run) {
858
- const { inputs: _inputs, result: sourceResult, stages, toolNodes, pendingPrompt, ...metadata } = run;
859
- const result = compactRunResult(sourceResult, run.exited === true && run.status === "failed");
860
- return {
861
- ...metadata,
862
- inputs: {},
863
- stages: stages.map(compactStage),
864
- ...toolNodes !== undefined ? { toolNodes: toolNodes.map(compactToolNode) } : {},
865
- ...pendingPrompt !== undefined ? { pendingPrompt: clonePrompt(pendingPrompt) } : {},
866
- ...result !== undefined ? { result } : {}
867
- };
868
- }
869
- function createGraphStoreSnapshot(runs, notices, version) {
870
- const snapshot = {
871
- runs: runs.map(compactRun),
872
- notices: notices.map((notice) => ({ ...notice })),
873
- version
874
- };
875
- deepFreezeGraphValue(snapshot);
876
- return snapshot;
877
- }
878
- function deepFreezeGraphValue(value) {
879
- if (value === null || typeof value !== "object" || Object.isFrozen(value))
880
- return;
881
- Object.freeze(value);
882
- if (Array.isArray(value)) {
883
- for (const item of value)
884
- deepFreezeGraphValue(item);
885
- return;
886
- }
887
- for (const key of Object.keys(value)) {
888
- deepFreezeGraphValue(value[key]);
889
- }
890
- }
891
-
892
- // dist/builtin/workflows/src/shared/workflow-observation-runtime.ts
893
- import { randomUUID } from "node:crypto";
894
-
895
- // dist/builtin/workflows/src/shared/workflow-activity.ts
896
- function workflowActivityNodeKey(runId, nodeId) {
897
- return `${runId}:${nodeId}`;
898
- }
899
-
900
- // dist/builtin/workflows/src/shared/workflow-observation-runtime.ts
901
- class WorkflowObservationRuntime {
902
- runs;
903
- invalidate;
904
- liveRunIds = new Set;
905
- executingStageIds = new Set;
906
- executingToolNodeIds = new Set;
907
- stoppingRunIds = new Set;
908
- retryingStageIds = new Set;
909
- acknowledgedFailureRunIds = new Set;
910
- listeners = new Set;
911
- replayStageIds = new Set;
912
- previous = new Map;
913
- recoveryDepth = 0;
914
- constructor(runs, invalidate) {
915
- this.runs = runs;
916
- this.invalidate = invalidate;
917
- }
918
- get recovering() {
919
- return this.recoveryDepth > 0;
920
- }
921
- startRun(runId) {
922
- this.liveRunIds.add(runId);
923
- this.stoppingRunIds.delete(runId);
924
- }
925
- finishRun(runId) {
926
- this.liveRunIds.delete(runId);
927
- this.stoppingRunIds.delete(runId);
928
- for (const ids of [
929
- this.executingStageIds,
930
- this.executingToolNodeIds,
931
- this.retryingStageIds,
932
- this.replayStageIds
933
- ]) {
934
- for (const id of ids)
935
- if (id.startsWith(`${runId}:`))
936
- ids.delete(id);
937
- }
938
- this.invalidate();
939
- }
940
- emit(event) {
941
- for (const listener of this.listeners) {
942
- try {
943
- listener(event);
944
- } catch {}
945
- }
946
- }
947
- rootRunId(run) {
948
- if (run.rootRunId !== undefined)
949
- return run.rootRunId;
950
- if (run.parentRunId === undefined)
951
- return run.id;
952
- const parent = this.runs().find((candidate) => candidate.id === run.parentRunId);
953
- return parent ? this.rootRunId(parent) : run.parentRunId;
954
- }
955
- lifecycle(target, attribution = "unknown") {
956
- if (this.recovering && !this.liveRunIds.has(target.runId))
957
- return;
958
- const run = this.runs().find((candidate) => candidate.id === target.runId);
959
- if (!run)
960
- return;
961
- const rootRunId = this.rootRunId(run);
962
- const now = Date.now();
963
- this.emit({
964
- kind: "lifecycle",
965
- event: {
966
- type: "workflow_lifecycle",
967
- eventId: randomUUID(),
968
- runId: run.id,
969
- rootRunId,
970
- occurredAt: now,
971
- observedAt: now,
972
- target: canonicalTarget(target, rootRunId),
973
- attribution,
974
- delivery: target.kind === "stage" && this.replayStageIds.has(workflowActivityNodeKey(run.id, target.stageId)) ? "replay" : "live"
975
- }
976
- });
977
- }
978
- control(runId, action, attribution = "unknown") {
979
- const run = this.runs().find((candidate) => candidate.id === runId);
980
- if (!run)
981
- return;
982
- if ((action === "quit" || action === "kill" || action === "pause") && this.liveRunIds.has(runId))
983
- this.stoppingRunIds.add(runId);
984
- if (action === "resume")
985
- this.stoppingRunIds.delete(runId);
986
- this.lifecycle({ kind: "run", runId, status: run.status, action }, attribution);
987
- this.invalidate();
988
- }
989
- heartbeat(runId, scheduledAt, intervalMinutes) {
990
- const run = this.runs().find((candidate) => candidate.id === runId);
991
- if (run)
992
- this.emit({
993
- kind: "heartbeat",
994
- event: { type: "workflow_heartbeat", runId, rootRunId: this.rootRunId(run), scheduledAt, intervalMinutes }
995
- });
996
- }
997
- beginRecovery() {
998
- this.recoveryDepth++;
999
- if (this.recoveryDepth === 1)
1000
- this.emit({ kind: "availability" });
1001
- let ended = false;
1002
- return () => {
1003
- if (ended)
1004
- return;
1005
- ended = true;
1006
- this.capture();
1007
- this.recoveryDepth--;
1008
- if (!this.recovering)
1009
- this.emit({ kind: "availability" });
1010
- };
1011
- }
1012
- capture() {
1013
- const next = new Map;
1014
- const visit = (key, target, historical = false) => {
1015
- next.set(key, target);
1016
- const previous = this.previous.get(key);
1017
- if (!historical && this.liveRunIds.has(target.runId) && previous?.status !== target.status) {
1018
- this.lifecycle(previous && previous.kind !== "prompt" && target.kind !== "prompt" ? { ...target, previousStatus: previous.status } : target, this.runs().find((run) => run.id === target.runId)?.origin);
1019
- }
1020
- };
1021
- for (const run of this.runs()) {
1022
- const existing = this.previous.has(`run:${run.id}`);
1023
- visit(`run:${run.id}`, { kind: "run", runId: run.id, status: run.status });
1024
- for (const stage of run.stages) {
1025
- visit(`stage:${workflowActivityNodeKey(run.id, stage.id)}`, { kind: "stage", runId: run.id, stageId: stage.id, stageName: stage.name, status: stage.status }, !existing);
1026
- if (stage.pendingPrompt)
1027
- visit(`prompt:${stage.pendingPrompt.id}`, {
1028
- kind: "prompt",
1029
- runId: run.id,
1030
- stageId: stage.id,
1031
- promptId: stage.pendingPrompt.id,
1032
- status: "opened"
1033
- }, !existing);
1034
- }
1035
- for (const tool of run.toolNodes ?? [])
1036
- visit(`tool:${workflowActivityNodeKey(run.id, tool.id)}`, { kind: "tool", runId: run.id, toolNodeId: tool.id, toolName: tool.name, status: tool.status }, !existing);
1037
- if (run.pendingPrompt)
1038
- visit(`prompt:${run.pendingPrompt.id}`, { kind: "prompt", runId: run.id, promptId: run.pendingPrompt.id, status: "opened" }, !existing);
1039
- }
1040
- this.previous = next;
1041
- }
1042
- }
1043
- var workflowObservationRuntimeKey = Symbol.for("atomic-workflows/store-observation-runtime@1");
1044
- function canonicalTarget(target, rootRunId) {
1045
- if (target.runId === rootRunId)
1046
- return target;
1047
- switch (target.kind) {
1048
- case "stage":
1049
- return { ...target, stageId: workflowActivityNodeKey(target.runId, target.stageId) };
1050
- case "tool":
1051
- return { ...target, toolNodeId: workflowActivityNodeKey(target.runId, target.toolNodeId) };
1052
- case "prompt":
1053
- return target.stageId === undefined ? target : { ...target, stageId: workflowActivityNodeKey(target.runId, target.stageId) };
1054
- case "run":
1055
- return target;
1056
- }
1057
- }
1058
-
1059
- // dist/builtin/workflows/src/shared/store-internal.ts
1060
- var TERMINAL_STATUSES = new Set([
1061
- "completed",
1062
- "failed",
1063
- "killed",
1064
- "skipped",
1065
- "cancelled",
1066
- "blocked"
1067
- ]);
1068
- function isTerminalStageStatus(status) {
1069
- return status === "completed" || status === "failed" || status === "skipped";
1070
- }
1071
- function cannotAwaitInput(status) {
1072
- return isTerminalStageStatus(status) || status === "paused" || status === "blocked";
1073
- }
1074
- function cannotBlock(status) {
1075
- return isTerminalStageStatus(status) || status === "paused";
1076
- }
1077
- function cannotPause(status) {
1078
- return isTerminalStageStatus(status) || status === "paused" || status === "blocked";
1079
- }
1080
- function clearRunFailureMetadata(run) {
1081
- delete run.error;
1082
- delete run.failureKind;
1083
- delete run.failureCode;
1084
- delete run.failureRecoverability;
1085
- delete run.failureDisposition;
1086
- delete run.failureMessage;
1087
- delete run.failedStageId;
1088
- delete run.failedToolNodeId;
1089
- delete run.resumable;
1090
- delete run.retryAfterMs;
1091
- delete run.blockedAt;
1092
- delete run.exited;
1093
- delete run.exitReason;
1094
- }
1095
- function clearStaleBlockedRunMetadata(run, metadata) {
1096
- if (metadata?.failureKind === undefined)
1097
- delete run.failureKind;
1098
- if (metadata?.failureCode === undefined)
1099
- delete run.failureCode;
1100
- if (metadata?.failureRecoverability === undefined)
1101
- delete run.failureRecoverability;
1102
- if (metadata?.failureDisposition === undefined)
1103
- delete run.failureDisposition;
1104
- if (metadata?.failureMessage === undefined)
1105
- delete run.failureMessage;
1106
- if (metadata?.failedStageId === undefined)
1107
- delete run.failedStageId;
1108
- if (metadata?.failedToolNodeId === undefined)
1109
- delete run.failedToolNodeId;
1110
- if (metadata?.resumable === undefined)
1111
- delete run.resumable;
1112
- if (metadata?.retryAfterMs === undefined)
1113
- delete run.retryAfterMs;
1114
- if (metadata?.exited === undefined)
1115
- delete run.exited;
1116
- if (metadata?.exitReason === undefined)
1117
- delete run.exitReason;
1118
- }
1119
- function applyRunEndMetadata(run, metadata) {
1120
- if (metadata.failureKind !== undefined)
1121
- run.failureKind = metadata.failureKind;
1122
- if (metadata.failureCode !== undefined)
1123
- run.failureCode = metadata.failureCode;
1124
- if (metadata.failureRecoverability !== undefined)
1125
- run.failureRecoverability = metadata.failureRecoverability;
1126
- if (metadata.failureDisposition !== undefined)
1127
- run.failureDisposition = metadata.failureDisposition;
1128
- if (metadata.retryAfterMs !== undefined)
1129
- run.retryAfterMs = metadata.retryAfterMs;
1130
- if (metadata.failureMessage !== undefined)
1131
- run.failureMessage = metadata.failureMessage;
1132
- if (metadata.failedStageId !== undefined)
1133
- run.failedStageId = metadata.failedStageId;
1134
- if (metadata.failedToolNodeId !== undefined)
1135
- run.failedToolNodeId = metadata.failedToolNodeId;
1136
- if (metadata.resumable !== undefined)
1137
- run.resumable = metadata.resumable;
1138
- if (metadata.exited !== undefined)
1139
- run.exited = metadata.exited;
1140
- if (metadata.exitReason !== undefined)
1141
- run.exitReason = metadata.exitReason;
1142
- }
1143
- function createStoreState() {
1144
- return {
1145
- runs: [],
1146
- notices: [],
1147
- listeners: new Set,
1148
- invalidationListeners: new Set,
1149
- resolvers: new Map,
1150
- stagePromptAnswers: new Map,
1151
- stagePromptDrafts: new Map,
1152
- version: 0
1153
- };
1154
- }
1155
- function createStoreContext(state = createStoreState()) {
1156
- let cachedGraphVersion = -1;
1157
- let cachedGraphSnapshot;
1158
- const observation = new WorkflowObservationRuntime(() => state.runs, bumpAndNotify);
1159
- function snapshot() {
1160
- return JSON.parse(JSON.stringify({ runs: state.runs, notices: state.notices, version: state.version }));
1161
- }
1162
- function graphSnapshot() {
1163
- if (cachedGraphSnapshot === undefined || cachedGraphVersion !== state.version) {
1164
- cachedGraphSnapshot = createGraphStoreSnapshot(state.runs, state.notices, state.version);
1165
- cachedGraphVersion = state.version;
1166
- }
1167
- return cachedGraphSnapshot;
1168
- }
1169
- function notify() {
1170
- observation.capture();
1171
- for (const fn of state.invalidationListeners) {
1172
- try {
1173
- fn();
1174
- } catch {}
1175
- }
1176
- if (state.listeners.size > 0) {
1177
- const snap = snapshot();
1178
- for (const fn of state.listeners) {
1179
- try {
1180
- fn(snap);
1181
- } catch {}
1182
- }
1183
- }
1184
- }
1185
- function bumpAndNotify() {
1186
- state.version++;
1187
- notify();
1188
- }
1189
- function findRun(runId) {
1190
- return state.runs.find((r) => r.id === runId);
1191
- }
1192
- function findStage(run, stageId) {
1193
- return run.stages.find((s) => s.id === stageId);
1194
- }
1195
- function rejectPrompt(promptId, reason) {
1196
- const entry = state.resolvers.get(promptId);
1197
- if (!entry)
1198
- return;
1199
- state.resolvers.delete(promptId);
1200
- entry.reject(new Error(reason));
1201
- }
1202
- function stagePromptAnswerKey(runId, stageId) {
1203
- return JSON.stringify([runId, stageId]);
1204
- }
1205
- function stagePromptDraftKey(runId, stageId, promptId) {
1206
- return JSON.stringify([runId, stageId, promptId]);
1207
- }
1208
- function stageHasActiveTextPrompt(runId, stageId, promptId) {
1209
- const run = findRun(runId);
1210
- if (!run || TERMINAL_STATUSES.has(run.status))
1211
- return;
1212
- const stage = findStage(run, stageId);
1213
- if (!stage || isTerminalStageStatus(stage.status))
1214
- return;
1215
- const prompt = stage.pendingPrompt;
1216
- if (!prompt || prompt.id !== promptId)
1217
- return;
1218
- if (prompt.kind !== "input" && prompt.kind !== "editor")
1219
- return;
1220
- return { prompt };
1221
- }
1222
- function rejectStagePrompt(runId, stage, reason) {
1223
- const prompt = stage.pendingPrompt;
1224
- if (!prompt)
1225
- return;
1226
- observation.lifecycle({ kind: "prompt", runId, stageId: stage.id, promptId: prompt.id, status: "cancelled" });
1227
- stage.pendingPrompt = undefined;
1228
- state.stagePromptDrafts.delete(stagePromptDraftKey(runId, stage.id, prompt.id));
1229
- rejectPrompt(prompt.id, reason);
1230
- }
1231
- function rejectAllStagePrompts(runId, run, reason) {
1232
- for (const stage of run.stages) {
1233
- rejectStagePrompt(runId, stage, reason);
1234
- }
1235
- }
1236
- return {
1237
- state,
1238
- observation,
1239
- snapshot,
1240
- graphSnapshot,
1241
- notify,
1242
- bumpAndNotify,
1243
- findRun,
1244
- findStage,
1245
- rejectPrompt,
1246
- rejectStagePrompt,
1247
- rejectAllStagePrompts,
1248
- stagePromptAnswerKey,
1249
- stagePromptDraftKey,
1250
- stageHasActiveTextPrompt
1251
- };
1252
- }
1253
-
1254
- // dist/builtin/workflows/src/shared/store-pending-stage-delivery-methods.ts
1255
- function createPendingStageDeliveryStoreMethods(context) {
1256
- const transitions = new Map;
1257
- const serialize = async (runId, transition) => {
1258
- const previous = transitions.get(runId) ?? Promise.resolve();
1259
- const result = previous.catch(() => {
1260
- return;
1261
- }).then(transition);
1262
- const settled = result.then(() => {
1263
- return;
1264
- }, () => {
1265
- return;
1266
- });
1267
- transitions.set(runId, settled);
1268
- settled.finally(() => {
1269
- if (transitions.get(runId) === settled)
1270
- transitions.delete(runId);
1271
- });
1272
- return await result;
1273
- };
1274
- return {
1275
- async queueStageMessage(input, senderGroup, runGroup, backend) {
1276
- return await serialize(input.runId, async () => {
1277
- const run = context.findRun(input.runId);
1278
- if (run === undefined)
1279
- return;
1280
- const stageIdentity = resolvePendingStageIdentity(run, input.stageKey);
1281
- const result = queueStageMessage(run.pendingStageMessages ?? [], input, senderGroup, runGroup, stageIdentity);
1282
- if (result.ok && !result.deduplicated) {
1283
- await persistTransition(backend, input.runId, result.messages);
1284
- run.pendingStageMessages = [...result.messages];
1285
- context.bumpAndNotify();
1286
- }
1287
- return result;
1288
- });
1289
- },
1290
- async validateLiveStageMessage(input) {
1291
- return await serialize(input.runId, async () => {
1292
- const run = context.findRun(input.runId);
1293
- if (run === undefined)
1294
- return;
1295
- const result = queueStageMessage(run.pendingStageMessages ?? [], input, undefined, undefined, resolvePendingStageIdentity(run, input.stageKey));
1296
- if (!result.ok) {
1297
- return result.reason === "message_id_conflict" ? { outcome: "message_id_conflict", messageId: result.messageId } : { outcome: "forward" };
1298
- }
1299
- if (!result.deduplicated)
1300
- return { outcome: "forward" };
1301
- if (result.entry.status === "delivered")
1302
- return { outcome: "delivered" };
1303
- if (result.entry.status === "undeliverable") {
1304
- return { outcome: "undeliverable", reason: result.entry.undeliverableReason };
1305
- }
1306
- if (result.position === undefined) {
1307
- throw new Error(`atomic-workflows: queued message ${input.message.id} has no active position`);
1308
- }
1309
- return { outcome: "queued", position: result.position };
1310
- });
1311
- },
1312
- pendingStageMessagesFor(runId, stageKey) {
1313
- const run = context.findRun(runId);
1314
- return pendingStageMessagesFor(run?.pendingStageMessages ?? [], runId, stageKey, run === undefined ? undefined : resolvePendingStageIdentity(run, stageKey));
1315
- },
1316
- async markPendingStageMessageDelivered(runId, stageKey, messageId, deliveredAt, backend) {
1317
- return await serialize(runId, async () => {
1318
- const run = context.findRun(runId);
1319
- if (run === undefined)
1320
- return false;
1321
- const current = run.pendingStageMessages ?? [];
1322
- const next = markPendingStageMessageDelivered(current, runId, stageKey, messageId, deliveredAt, resolvePendingStageIdentity(run, stageKey));
1323
- if (next === current)
1324
- return false;
1325
- await persistTransition(backend, runId, next);
1326
- run.pendingStageMessages = [...next];
1327
- context.bumpAndNotify();
1328
- return true;
1329
- });
1330
- },
1331
- async markPendingStageMessageUndeliverable(runId, stageKey, messageId, reason, backend) {
1332
- return await serialize(runId, async () => {
1333
- const run = context.findRun(runId);
1334
- if (run === undefined)
1335
- return false;
1336
- const current = run.pendingStageMessages ?? [];
1337
- const next = markPendingStageMessageUndeliverable(current, runId, stageKey, messageId, reason, resolvePendingStageIdentity(run, stageKey));
1338
- if (next === current)
1339
- return false;
1340
- await persistTransition(backend, runId, next);
1341
- run.pendingStageMessages = [...next];
1342
- context.bumpAndNotify();
1343
- return true;
1344
- });
1345
- },
1346
- async markPendingStageMessageUndeliverableNotified(runId, stageKey, messageId, notificationId, notifiedAt, backend) {
1347
- return await serialize(runId, async () => {
1348
- const run = context.findRun(runId);
1349
- if (run === undefined)
1350
- return false;
1351
- const current = run.pendingStageMessages ?? [];
1352
- const next = markPendingStageMessageUndeliverableNotified(current, runId, stageKey, messageId, notificationId, notifiedAt);
1353
- if (next === current)
1354
- return false;
1355
- await persistTransition(backend, runId, next);
1356
- run.pendingStageMessages = [...next];
1357
- context.bumpAndNotify();
1358
- return true;
1359
- });
1360
- },
1361
- async queueStickyStageMessage(input, senderGroup, runGroup, backend) {
1362
- return await serialize(input.runId, async () => {
1363
- const run = context.findRun(input.runId);
1364
- if (run === undefined)
1365
- return;
1366
- const result = queueStickyStageMessage(run.pendingStageMessages ?? [], input, senderGroup, runGroup);
1367
- if (result.ok && !result.deduplicated) {
1368
- await persistTransition(backend, input.runId, result.messages);
1369
- run.pendingStageMessages = [...result.messages];
1370
- context.bumpAndNotify();
1371
- }
1372
- return result;
1373
- });
1374
- },
1375
- async recordPendingStageMessageDeliveries(runId, messageId, records, deliveredAt, backend) {
1376
- return await serialize(runId, async () => {
1377
- const run = context.findRun(runId);
1378
- if (run === undefined)
1379
- return false;
1380
- const current = run.pendingStageMessages ?? [];
1381
- const next = recordPendingStageMessageDeliveries(current, runId, messageId, records, deliveredAt);
1382
- if (next === current)
1383
- return false;
1384
- await persistTransition(backend, runId, next);
1385
- run.pendingStageMessages = [...next];
1386
- context.bumpAndNotify();
1387
- return true;
1388
- });
1389
- },
1390
- async settleStickyPendingStageMessageDelivered(runId, messageId, settledAt, backend) {
1391
- return await serialize(runId, async () => {
1392
- const run = context.findRun(runId);
1393
- if (run === undefined)
1394
- return false;
1395
- const current = run.pendingStageMessages ?? [];
1396
- const next = settleStickyPendingStageMessageDelivered(current, runId, messageId, settledAt);
1397
- if (next === current)
1398
- return false;
1399
- await persistTransition(backend, runId, next);
1400
- run.pendingStageMessages = [...next];
1401
- context.bumpAndNotify();
1402
- return true;
1403
- });
1404
- }
1405
- };
1406
- }
1407
- function resolvePendingStageIdentity(run, stageKey) {
1408
- const exactIds = run.stages.filter((stage) => stage.id === stageKey);
1409
- const candidates = exactIds.length > 0 ? exactIds : run.stages.filter((stage) => stage.name === stageKey);
1410
- if (candidates.length !== 1)
1411
- return;
1412
- const stage = candidates[0];
1413
- return {
1414
- id: stage.id,
1415
- ...stage.replayKey !== undefined ? { replayKey: stage.replayKey } : {},
1416
- aliases: stage.id === stage.name ? [stage.id] : [stage.id, stage.name]
1417
- };
1418
- }
1419
- async function persistTransition(backend, runId, messages) {
1420
- if (!await backend.persistPendingStageMessages(runId, messages)) {
1421
- throw new Error(`atomic-workflows: durable workflow ${runId} is unavailable for pending-stage persistence`);
1422
- }
1423
- }
1424
-
1425
- // dist/builtin/workflows/src/shared/store-prompt-methods.ts
1426
- function createPromptStoreMethods(context) {
1427
- const { state } = context;
1428
- return {
1429
- recordPendingPrompt(runId, prompt) {
1430
- const run = context.findRun(runId);
1431
- if (!run)
1432
- return false;
1433
- if (TERMINAL_STATUSES.has(run.status))
1434
- return false;
1435
- if (run.pendingPrompt !== undefined)
1436
- return false;
1437
- run.pendingPrompt = { ...prompt };
1438
- context.bumpAndNotify();
1439
- return true;
1440
- },
1441
- resolvePendingPrompt(runId, promptId, response) {
1442
- const run = context.findRun(runId);
1443
- if (!run)
1444
- return false;
1445
- const pending = run.pendingPrompt;
1446
- if (!pending || pending.id !== promptId)
1447
- return false;
1448
- context.observation.lifecycle({ kind: "prompt", runId, promptId, status: "answered" });
1449
- run.pendingPrompt = undefined;
1450
- context.bumpAndNotify();
1451
- const entry = state.resolvers.get(promptId);
1452
- if (entry) {
1453
- state.resolvers.delete(promptId);
1454
- entry.resolve(response);
1455
- }
1456
- return true;
1457
- },
1458
- awaitPendingPrompt(runId, promptId) {
1459
- return new Promise((resolve, reject) => {
1460
- const run = context.findRun(runId);
1461
- if (!run) {
1462
- reject(new Error(`atomic-workflows: run "${runId}" not found`));
1463
- return;
1464
- }
1465
- const pending = run.pendingPrompt;
1466
- if (!pending || pending.id !== promptId) {
1467
- reject(new Error(`atomic-workflows: pending prompt "${promptId}" not registered on run "${runId}"`));
1468
- return;
1469
- }
1470
- state.resolvers.set(promptId, { promptId, resolve, reject });
1471
- });
1472
- },
1473
- recordStagePendingPrompt(runId, stageId, prompt) {
1474
- const run = context.findRun(runId);
1475
- if (!run)
1476
- return false;
1477
- if (TERMINAL_STATUSES.has(run.status))
1478
- return false;
1479
- const stage = context.findStage(run, stageId);
1480
- if (!stage)
1481
- return false;
1482
- if (isTerminalStageStatus(stage.status))
1483
- return false;
1484
- if (stage.pendingPrompt !== undefined)
1485
- return false;
1486
- stage.pendingPrompt = { ...prompt };
1487
- stage.promptFootprint = { ...prompt };
1488
- stage.status = "awaiting_input";
1489
- stage.awaitingInputSince = prompt.createdAt;
1490
- context.bumpAndNotify();
1491
- return true;
1492
- },
1493
- resolveStagePendingPrompt(runId, stageId, promptId, response, options = {}) {
1494
- const run = context.findRun(runId);
1495
- if (!run)
1496
- return false;
1497
- const stage = context.findStage(run, stageId);
1498
- if (!stage)
1499
- return false;
1500
- const pending = stage.pendingPrompt;
1501
- if (!pending || pending.id !== promptId)
1502
- return false;
1503
- state.stagePromptDrafts.delete(context.stagePromptDraftKey(runId, stageId, promptId));
1504
- if (options.recordAnswer !== false) {
1505
- state.stagePromptAnswers.set(context.stagePromptAnswerKey(runId, stageId), {
1506
- runId,
1507
- stageId,
1508
- promptId,
1509
- kind: pending.kind,
1510
- value: response,
1511
- answeredAt: Date.now(),
1512
- ...options.answerSource !== undefined ? { answerSource: options.answerSource } : {}
1513
- });
1514
- stage.promptAnswerState = "available";
1515
- } else {
1516
- state.stagePromptAnswers.delete(context.stagePromptAnswerKey(runId, stageId));
1517
- delete stage.promptAnswerState;
1518
- }
1519
- context.observation.lifecycle({
1520
- kind: "prompt",
1521
- runId,
1522
- stageId,
1523
- promptId,
1524
- status: options.recordAnswer === false ? "cancelled" : "answered"
1525
- });
1526
- stage.pendingPrompt = undefined;
1527
- if (stage.status === "awaiting_input") {
1528
- stage.status = "running";
1529
- delete stage.awaitingInputSince;
1530
- }
1531
- context.bumpAndNotify();
1532
- const entry = state.resolvers.get(promptId);
1533
- if (entry) {
1534
- state.resolvers.delete(promptId);
1535
- entry.resolve(response);
1536
- }
1537
- return true;
1538
- },
1539
- awaitStagePendingPrompt(runId, stageId, promptId) {
1540
- return new Promise((resolve, reject) => {
1541
- const run = context.findRun(runId);
1542
- if (!run) {
1543
- reject(new Error(`atomic-workflows: run "${runId}" not found`));
1544
- return;
1545
- }
1546
- const stage = context.findStage(run, stageId);
1547
- if (!stage) {
1548
- reject(new Error(`atomic-workflows: stage "${stageId}" not found on run "${runId}"`));
1549
- return;
1550
- }
1551
- const pending = stage.pendingPrompt;
1552
- if (!pending || pending.id !== promptId) {
1553
- reject(new Error(`atomic-workflows: pending prompt "${promptId}" not registered on stage "${stageId}" in run "${runId}"`));
1554
- return;
1555
- }
1556
- state.resolvers.set(promptId, { promptId, resolve, reject });
1557
- });
1558
- },
1559
- recordStagePromptAnswer(runId, stageId, prompt, response, options = {}) {
1560
- const run = context.findRun(runId);
1561
- if (!run)
1562
- return false;
1563
- if (TERMINAL_STATUSES.has(run.status))
1564
- return false;
1565
- const stage = context.findStage(run, stageId);
1566
- if (!stage)
1567
- return false;
1568
- if (isTerminalStageStatus(stage.status))
1569
- return false;
1570
- state.stagePromptAnswers.set(context.stagePromptAnswerKey(runId, stageId), {
1571
- runId,
1572
- stageId,
1573
- promptId: prompt.id,
1574
- kind: prompt.kind,
1575
- value: response,
1576
- answeredAt: Date.now(),
1577
- ...options.answerSource !== undefined ? { answerSource: options.answerSource } : {}
1578
- });
1579
- if (stage.promptFootprint === undefined)
1580
- stage.promptFootprint = { ...prompt };
1581
- stage.promptAnswerState = "available";
1582
- if (stage.status === "awaiting_input") {
1583
- stage.status = "running";
1584
- delete stage.awaitingInputSince;
1585
- }
1586
- context.bumpAndNotify();
1587
- return true;
1588
- },
1589
- recordStagePromptDraft(runId, stageId, promptId, text) {
1590
- if (context.stageHasActiveTextPrompt(runId, stageId, promptId) === undefined)
1591
- return false;
1592
- state.stagePromptDrafts.set(context.stagePromptDraftKey(runId, stageId, promptId), text);
1593
- return true;
1594
- },
1595
- getStagePromptDraft(runId, stageId, promptId) {
1596
- if (context.stageHasActiveTextPrompt(runId, stageId, promptId) === undefined)
1597
- return;
1598
- return state.stagePromptDrafts.get(context.stagePromptDraftKey(runId, stageId, promptId));
1599
- },
1600
- clearStagePromptDraft(runId, stageId, promptId) {
1601
- return state.stagePromptDrafts.delete(context.stagePromptDraftKey(runId, stageId, promptId));
1602
- },
1603
- getStagePromptAnswer(runId, stageId) {
1604
- return state.stagePromptAnswers.get(context.stagePromptAnswerKey(runId, stageId));
1605
- },
1606
- clearStagePromptAnswer(runId, stageId) {
1607
- const removed = state.stagePromptAnswers.delete(context.stagePromptAnswerKey(runId, stageId));
1608
- const run = context.findRun(runId);
1609
- const stage = run ? context.findStage(run, stageId) : undefined;
1610
- const clearAvailabilityMarker = stage?.promptAnswerState === "available";
1611
- if (clearAvailabilityMarker) {
1612
- delete stage.promptAnswerState;
1613
- }
1614
- if (removed || clearAvailabilityMarker) {
1615
- context.bumpAndNotify();
1616
- }
1617
- }
1618
- };
1619
- }
1620
-
1621
- // dist/builtin/workflows/src/shared/run-visibility.ts
1622
- function isTopLevelWorkflowRun(run) {
1623
- return run.parentRunId === undefined;
1624
- }
1625
-
1626
- // dist/builtin/workflows/src/shared/timing.ts
1627
- function nonNegative(ms) {
1628
- return Math.max(0, ms);
1629
- }
1630
- function nextControlTimestamp(requestedAt, previousAt) {
1631
- const candidate = requestedAt ?? Date.now();
1632
- return previousAt === undefined || candidate > previousAt ? candidate : previousAt + 1;
1633
- }
1634
- function elapsedFromStart(startedAt, now, pausedDurationMs, pausedAt) {
1635
- const completedPausedSegment = pausedDurationMs ?? 0;
1636
- const activePausedSegment = pausedAt === undefined ? 0 : nonNegative(now - pausedAt);
1637
- return nonNegative(now - startedAt - completedPausedSegment - activePausedSegment);
1638
- }
1639
- function accumulatePausedDurationMs(pausedDurationMs, pausedAt, resumedAt) {
1640
- if (pausedAt === undefined)
1641
- return pausedDurationMs ?? 0;
1642
- return (pausedDurationMs ?? 0) + nonNegative(resumedAt - pausedAt);
1643
- }
1644
- function elapsedRunMs(run, now = Date.now()) {
1645
- if (run.durationMs !== undefined)
1646
- return nonNegative(run.durationMs);
1647
- const effectiveNow = run.endedAt ?? now;
1648
- return nonNegative(run.accumulatedDurationMs ?? 0) + elapsedFromStart(run.startedAt, effectiveNow, run.pausedDurationMs, run.pausedAt);
1649
- }
1650
-
1651
- // dist/builtin/workflows/src/shared/store-run-methods.ts
1652
- function createRunStoreMethods(context) {
1653
- const { state } = context;
1654
- return {
1655
- runs() {
1656
- return state.runs;
1657
- },
1658
- notices() {
1659
- return state.notices;
1660
- },
1661
- activeRunId() {
1662
- for (let i = state.runs.length - 1;i >= 0; i--) {
1663
- const run = state.runs[i];
1664
- if (run && isTopLevelWorkflowRun(run) && run.endedAt === undefined) {
1665
- return run.id;
1666
- }
1667
- }
1668
- for (let i = state.runs.length - 1;i >= 0; i--) {
1669
- const run = state.runs[i];
1670
- if (run && run.endedAt === undefined) {
1671
- return run.id;
1672
- }
1673
- }
1674
- return null;
1675
- },
1676
- recordRunStart(run) {
1677
- state.runs.push(run);
1678
- context.bumpAndNotify();
1679
- },
1680
- reconcileRunParentStage(runId, expectedParentStageId, parentStageId) {
1681
- const run = context.findRun(runId);
1682
- if (run?.parentStageId !== expectedParentStageId || parentStageId === expectedParentStageId)
1683
- return false;
1684
- run.parentStageId = parentStageId;
1685
- context.bumpAndNotify();
1686
- return true;
1687
- },
1688
- recordRunEnd(runId, status, result, error, metadata) {
1689
- const run = context.findRun(runId);
1690
- if (!run)
1691
- return false;
1692
- if (TERMINAL_STATUSES.has(run.status))
1693
- return false;
1694
- run.status = status;
1695
- run.endedAt = Date.now();
1696
- if (run.pausedAt !== undefined) {
1697
- run.pausedDurationMs = accumulatePausedDurationMs(run.pausedDurationMs, run.pausedAt, run.endedAt);
1698
- run.pausedAt = undefined;
1699
- }
1700
- run.durationMs = elapsedRunMs(run, run.endedAt);
1701
- if (result !== undefined && shouldStoreRunResult(status))
1702
- run.result = result;
1703
- const wasBlocked = run.blockedAt !== undefined || run.failureDisposition === "active_blocked";
1704
- delete run.blockedAt;
1705
- if (status === "completed" || status === "skipped" || status === "cancelled" || status === "blocked") {
1706
- clearRunFailureMetadata(run);
1707
- if (status === "blocked" && error !== undefined)
1708
- run.error = error;
1709
- if (metadata !== undefined)
1710
- applyRunEndMetadata(run, metadata);
1711
- } else {
1712
- if (wasBlocked && error === undefined)
1713
- delete run.error;
1714
- if ((status === "failed" || status === "killed") && error !== undefined) {
1715
- run.error = error;
1716
- }
1717
- if (wasBlocked)
1718
- clearStaleBlockedRunMetadata(run, metadata);
1719
- if (metadata !== undefined)
1720
- applyRunEndMetadata(run, metadata);
1721
- if (run.failureDisposition === "active_blocked")
1722
- delete run.failureDisposition;
1723
- if (status === "killed") {
1724
- run.failureRecoverability = "non_recoverable";
1725
- run.failureDisposition = "terminal_killed";
1726
- run.resumable = false;
1727
- }
1728
- }
1729
- const pending = run.pendingPrompt;
1730
- if (pending) {
1731
- context.observation.lifecycle({ kind: "prompt", runId, promptId: pending.id, status: "cancelled" });
1732
- run.pendingPrompt = undefined;
1733
- context.rejectPrompt(pending.id, `atomic-workflows: run ${runId} ended before prompt resolved`);
1734
- }
1735
- context.rejectAllStagePrompts(runId, run, `atomic-workflows: run ${runId} ended before prompt resolved`);
1736
- context.bumpAndNotify();
1737
- return true;
1738
- },
1739
- recordRunBlocked(runId, error, metadata) {
1740
- const run = context.findRun(runId);
1741
- if (!run)
1742
- return false;
1743
- if (TERMINAL_STATUSES.has(run.status))
1744
- return false;
1745
- run.status = "running";
1746
- run.error = error;
1747
- run.failureKind = metadata.failureKind;
1748
- run.failureCode = metadata.failureCode;
1749
- run.failureRecoverability = metadata.failureRecoverability;
1750
- run.failureDisposition = metadata.failureDisposition;
1751
- run.failureMessage = metadata.failureMessage;
1752
- if (metadata.failedStageId === undefined)
1753
- delete run.failedStageId;
1754
- else
1755
- run.failedStageId = metadata.failedStageId;
1756
- run.resumable = metadata.resumable;
1757
- run.blockedAt = metadata.blockedAt ?? Date.now();
1758
- if (metadata.endedAt !== undefined) {
1759
- run.endedAt = metadata.endedAt;
1760
- run.durationMs = elapsedRunMs(run, metadata.endedAt);
1761
- }
1762
- if (metadata.retryAfterMs !== undefined)
1763
- run.retryAfterMs = metadata.retryAfterMs;
1764
- if (metadata.result !== undefined)
1765
- run.result = metadata.result;
1766
- if (metadata.budgetState !== undefined)
1767
- run.budgetState = metadata.budgetState;
1768
- context.bumpAndNotify();
1769
- return true;
1770
- },
1771
- restoreActiveBlockedRun(source, error, metadata) {
1772
- const restored = {
1773
- ...source,
1774
- status: "running",
1775
- error,
1776
- resumable: metadata.resumable,
1777
- failureRecoverability: metadata.failureRecoverability,
1778
- failureDisposition: metadata.failureDisposition,
1779
- blockedAt: metadata.blockedAt ?? Date.now(),
1780
- stages: source.stages.map((stage) => ({ ...stage })),
1781
- toolNodes: source.toolNodes?.map((node) => ({ ...node }))
1782
- };
1783
- delete restored.endedAt;
1784
- delete restored.durationMs;
1785
- restored.failureKind = metadata.failureKind;
1786
- restored.failureCode = metadata.failureCode;
1787
- restored.failureMessage = metadata.failureMessage;
1788
- if (metadata.failedStageId === undefined)
1789
- delete restored.failedStageId;
1790
- else
1791
- restored.failedStageId = metadata.failedStageId;
1792
- if (metadata.retryAfterMs !== undefined)
1793
- restored.retryAfterMs = metadata.retryAfterMs;
1794
- if (metadata.result !== undefined)
1795
- restored.result = metadata.result;
1796
- if (metadata.budgetState !== undefined)
1797
- restored.budgetState = metadata.budgetState;
1798
- const index = state.runs.findIndex((candidate) => candidate.id === source.id);
1799
- if (index < 0)
1800
- state.runs.push(restored);
1801
- else
1802
- state.runs[index] = restored;
1803
- context.bumpAndNotify();
1804
- return true;
1805
- },
1806
- removeRun(runId) {
1807
- const index = state.runs.findIndex((r) => r.id === runId);
1808
- if (index < 0)
1809
- return false;
1810
- const run = state.runs[index];
1811
- const pending = run.pendingPrompt;
1812
- if (pending) {
1813
- context.observation.lifecycle({ kind: "prompt", runId, promptId: pending.id, status: "cancelled" });
1814
- context.rejectPrompt(pending.id, `atomic-workflows: run ${runId} was removed before prompt resolved`);
1815
- }
1816
- context.rejectAllStagePrompts(runId, run, `atomic-workflows: run ${runId} was removed before prompt resolved`);
1817
- for (const stage of run.stages) {
1818
- state.stagePromptAnswers.delete(context.stagePromptAnswerKey(runId, stage.id));
1819
- }
1820
- state.runs.splice(index, 1);
1821
- for (let i = state.notices.length - 1;i >= 0; i--) {
1822
- if (state.notices[i]?.runId === runId)
1823
- state.notices.splice(i, 1);
1824
- }
1825
- context.bumpAndNotify();
1826
- return true;
1827
- },
1828
- recordNotice(notice) {
1829
- state.notices.push(notice);
1830
- context.bumpAndNotify();
1831
- },
1832
- ackNotice(id) {
1833
- const notice = state.notices.find((n) => n.id === id);
1834
- if (!notice || notice.ackedAt !== undefined)
1835
- return false;
1836
- notice.ackedAt = Date.now();
1837
- context.bumpAndNotify();
1838
- return true;
1839
- },
1840
- recordRunPaused(runId, pausedAt, metadata) {
1841
- const run = context.findRun(runId);
1842
- if (!run)
1843
- return false;
1844
- if (TERMINAL_STATUSES.has(run.status))
1845
- return false;
1846
- const wasPaused = run.status === "paused";
1847
- if (!wasPaused) {
1848
- run.status = "paused";
1849
- run.pausedAt = nextControlTimestamp(pausedAt, run.resumedAt);
1850
- run.resumedAt = undefined;
1851
- delete run.pauseActor;
1852
- delete run.resumeActor;
1853
- delete run.resumeSource;
1854
- }
1855
- if (metadata?.resumable !== undefined)
1856
- run.resumable = metadata.resumable;
1857
- if (metadata?.exitReason !== undefined)
1858
- run.exitReason = metadata.exitReason;
1859
- if (metadata?.exitReason === "quit" && run.quitAt === undefined)
1860
- run.quitAt = nextControlTimestamp(undefined, run.pausedAt);
1861
- if (metadata?.actor !== undefined)
1862
- run.pauseActor = metadata.actor;
1863
- if (wasPaused && metadata === undefined)
1864
- return false;
1865
- context.bumpAndNotify();
1866
- return true;
1867
- },
1868
- recordRunResumed(runId, resumedAt, metadata) {
1869
- const run = context.findRun(runId);
1870
- if (!run)
1871
- return false;
1872
- if (TERMINAL_STATUSES.has(run.status))
1873
- return false;
1874
- const claimsRunControl = metadata?.source === "run_control";
1875
- if (run.status !== "paused") {
1876
- if (!claimsRunControl || run.status !== "running" || run.resumedAt === undefined)
1877
- return false;
1878
- if (run.resumeSource === "run_control" && run.resumeActor === metadata?.actor)
1879
- return false;
1880
- run.resumeSource = "run_control";
1881
- if (metadata?.actor === undefined)
1882
- delete run.resumeActor;
1883
- else
1884
- run.resumeActor = metadata.actor;
1885
- context.bumpAndNotify();
1886
- return false;
1887
- }
1888
- const resumedTs = nextControlTimestamp(resumedAt, run.pausedAt);
1889
- run.status = "running";
1890
- run.pausedDurationMs = accumulatePausedDurationMs(run.pausedDurationMs, run.pausedAt, resumedTs);
1891
- run.resumedAt = resumedTs;
1892
- run.pausedAt = undefined;
1893
- delete run.quitAt;
1894
- delete run.exitReason;
1895
- delete run.pauseActor;
1896
- if (metadata === undefined) {
1897
- delete run.resumeActor;
1898
- delete run.resumeSource;
1899
- } else {
1900
- run.resumeSource = metadata.source;
1901
- if (metadata.actor === undefined)
1902
- delete run.resumeActor;
1903
- else
1904
- run.resumeActor = metadata.actor;
1905
- }
1906
- context.bumpAndNotify();
1907
- return true;
1908
- },
1909
- clear() {
1910
- if (state.runs.length === 0 && state.notices.length === 0 && state.resolvers.size === 0 && state.stagePromptAnswers.size === 0 && state.stagePromptDrafts.size === 0)
1911
- return;
1912
- state.runs.length = 0;
1913
- state.notices.length = 0;
1914
- for (const entry of state.resolvers.values()) {
1915
- entry.reject(new Error("atomic-workflows: store cleared"));
1916
- }
1917
- state.resolvers.clear();
1918
- state.stagePromptAnswers.clear();
1919
- state.stagePromptDrafts.clear();
1920
- context.bumpAndNotify();
1921
- },
1922
- snapshot() {
1923
- return context.snapshot();
1924
- },
1925
- graphSnapshot() {
1926
- return context.graphSnapshot();
1927
- },
1928
- subscribe(fn) {
1929
- state.listeners.add(fn);
1930
- return () => {
1931
- state.listeners.delete(fn);
1932
- };
1933
- },
1934
- subscribeInvalidation(fn) {
1935
- state.invalidationListeners.add(fn);
1936
- return () => state.invalidationListeners.delete(fn);
1937
- }
1938
- };
1939
- }
1940
- function shouldStoreRunResult(status) {
1941
- return status === "completed" || status === "skipped" || status === "cancelled" || status === "blocked" || status === "failed";
1942
- }
1943
-
1944
- // dist/builtin/workflows/src/shared/store-tool-node-methods.ts
1945
- function nextExecutionOrder(run) {
1946
- const stageOrders = run.stages.map((stage) => stage.executionOrder ?? 0);
1947
- const toolOrders = (run.toolNodes ?? []).map((node) => node.executionOrder ?? 0);
1948
- return Math.max(0, ...stageOrders, ...toolOrders) + 1;
1949
- }
1950
- function createToolNodeStoreMethods(context) {
1951
- return {
1952
- recordToolNodeStart(runId, node) {
1953
- const run = context.findRun(runId);
1954
- if (run === undefined || TERMINAL_STATUSES.has(run.status))
1955
- return false;
1956
- const mutableRun = run;
1957
- if (mutableRun.toolNodes === undefined)
1958
- mutableRun.toolNodes = [];
1959
- const nodes = mutableRun.toolNodes;
1960
- if (nodes.some((candidate) => candidate.id === node.id))
1961
- return false;
1962
- if (node.executionOrder === undefined)
1963
- node.executionOrder = nextExecutionOrder(run);
1964
- nodes.push(node);
1965
- context.bumpAndNotify();
1966
- return true;
1967
- },
1968
- recordToolNodeRunning(runId, nodeId, startedAt) {
1969
- const node = context.findRun(runId)?.toolNodes?.find((candidate) => candidate.id === nodeId);
1970
- if (node === undefined || node.status !== "pending")
1971
- return false;
1972
- node.status = "running";
1973
- node.startedAt = startedAt;
1974
- if (context.observation.liveRunIds.has(runId))
1975
- context.observation.executingToolNodeIds.add(workflowActivityNodeKey(runId, nodeId));
1976
- context.bumpAndNotify();
1977
- return true;
1978
- },
1979
- recordToolNodeEnd(runId, nodeId, update) {
1980
- const node = context.findRun(runId)?.toolNodes?.find((candidate) => candidate.id === nodeId);
1981
- if (node === undefined || node.status === "completed" || node.status === "failed" || node.status === "cached" || node.status === "cancelled")
1982
- return false;
1983
- context.observation.executingToolNodeIds.delete(workflowActivityNodeKey(runId, nodeId));
1984
- node.status = update.status;
1985
- if (update.endedAt !== undefined)
1986
- node.endedAt = update.endedAt;
1987
- if (update.durationMs !== undefined)
1988
- node.durationMs = update.durationMs;
1989
- if (update.result !== undefined)
1990
- node.result = boundedToolPayload(update.result);
1991
- if (update.resultSummary !== undefined)
1992
- node.resultSummary = update.resultSummary;
1993
- if (update.error !== undefined)
1994
- node.error = update.error;
1995
- context.bumpAndNotify();
1996
- return true;
1997
- }
1998
- };
1999
- }
2000
-
2001
- // dist/builtin/workflows/src/shared/store-stage-methods.ts
2002
- function createStageStoreMethods(context) {
2003
- return {
2004
- recordStageStart(runId, stage) {
2005
- const run = context.findRun(runId);
2006
- if (!run)
2007
- return;
2008
- if (stage.executionOrder === undefined)
2009
- stage.executionOrder = nextExecutionOrder(run);
2010
- if (!run.stages.some((s) => s.id === stage.id)) {
2011
- run.stages.push(stage);
2012
- }
2013
- if (stage.status === "running" && context.observation.liveRunIds.has(runId)) {
2014
- context.observation.executingStageIds.add(workflowActivityNodeKey(runId, stage.id));
2015
- }
2016
- context.bumpAndNotify();
2017
- },
2018
- recordStageWorkflowChildRun(runId, stageId, ref) {
2019
- const run = context.findRun(runId);
2020
- if (!run)
2021
- return false;
2022
- const stage = context.findStage(run, stageId);
2023
- if (!stage)
2024
- return false;
2025
- const released = context.observation.executingStageIds.delete(workflowActivityNodeKey(runId, stageId));
2026
- if (stage.workflowChildRun?.runId === ref.runId && stage.workflowChildRun.alias === ref.alias && stage.workflowChildRun.workflow === ref.workflow) {
2027
- if (released)
2028
- context.bumpAndNotify();
2029
- return false;
2030
- }
2031
- stage.workflowChildRun = { ...ref };
2032
- context.bumpAndNotify();
2033
- return true;
2034
- },
2035
- recordToolStart(runId, stageId, evt) {
2036
- const run = context.findRun(runId);
2037
- if (!run)
2038
- return;
2039
- const stage = context.findStage(run, stageId);
2040
- if (!stage)
2041
- return;
2042
- const exists = stage.toolEvents.some((e) => e.name === evt.name && e.startedAt === evt.startedAt);
2043
- if (!exists) {
2044
- stage.toolEvents.push(evt);
2045
- }
2046
- context.bumpAndNotify();
2047
- },
2048
- recordToolEnd(runId, stageId, evt) {
2049
- const run = context.findRun(runId);
2050
- if (!run)
2051
- return;
2052
- const stage = context.findStage(run, stageId);
2053
- if (!stage)
2054
- return;
2055
- const existing = stage.toolEvents.find((e) => e.name === evt.name && e.startedAt === evt.startedAt);
2056
- if (existing) {
2057
- existing.endedAt = evt.endedAt;
2058
- existing.output = evt.output;
2059
- }
2060
- context.bumpAndNotify();
2061
- },
2062
- recordStageEnd(runId, stage) {
2063
- const run = context.findRun(runId);
2064
- if (!run)
2065
- return;
2066
- const existing = context.findStage(run, stage.id);
2067
- if (!existing)
2068
- return;
2069
- context.observation.executingStageIds.delete(workflowActivityNodeKey(runId, stage.id));
2070
- existing.status = stage.status;
2071
- existing.endedAt = stage.endedAt;
2072
- if (existing.endedAt !== undefined && existing.pausedAt !== undefined) {
2073
- existing.pausedDurationMs = accumulatePausedDurationMs(existing.pausedDurationMs, existing.pausedAt, existing.endedAt);
2074
- existing.pausedAt = undefined;
2075
- }
2076
- existing.durationMs = stage.durationMs;
2077
- existing.result = stage.result;
2078
- existing.error = stage.error;
2079
- if (stage.sessionId !== undefined)
2080
- existing.sessionId = stage.sessionId;
2081
- if (stage.sessionFile !== undefined)
2082
- existing.sessionFile = stage.sessionFile;
2083
- if (stage.modelAttempts !== undefined)
2084
- existing.modelAttempts = stage.modelAttempts;
2085
- existing.failureKind = stage.failureKind;
2086
- existing.failureCode = stage.failureCode;
2087
- existing.failureRecoverability = stage.failureRecoverability;
2088
- existing.failureDisposition = stage.failureDisposition;
2089
- existing.retryAfterMs = stage.retryAfterMs;
2090
- existing.failureMessage = stage.failureMessage;
2091
- existing.skippedReason = stage.skippedReason;
2092
- if (stage.replayKey !== undefined)
2093
- existing.replayKey = stage.replayKey;
2094
- if (stage.promptAnswerState !== undefined)
2095
- existing.promptAnswerState = stage.promptAnswerState;
2096
- if (stage.replayedFromStageId !== undefined)
2097
- existing.replayedFromStageId = stage.replayedFromStageId;
2098
- if (stage.replayed !== undefined)
2099
- existing.replayed = stage.replayed;
2100
- if (stage.status === "completed") {
2101
- if (stage.workflowChildRun !== undefined)
2102
- existing.workflowChildRun = { ...stage.workflowChildRun };
2103
- if (stage.workflowChild !== undefined)
2104
- existing.workflowChild = structuredClone(stage.workflowChild);
2105
- } else {
2106
- delete existing.workflowChildRun;
2107
- delete existing.workflowChild;
2108
- }
2109
- delete existing.awaitingInputSince;
2110
- delete existing.inputRequest;
2111
- context.rejectStagePrompt(runId, existing, `atomic-workflows: stage ${stage.id} ended before prompt resolved`);
2112
- context.bumpAndNotify();
2113
- },
2114
- recordStageSession(runId, stageId, session) {
2115
- const run = context.findRun(runId);
2116
- if (!run)
2117
- return false;
2118
- const stage = context.findStage(run, stageId);
2119
- if (!stage)
2120
- return false;
2121
- let changed = false;
2122
- if (session.sessionId !== undefined && stage.sessionId !== session.sessionId) {
2123
- stage.sessionId = session.sessionId;
2124
- changed = true;
2125
- }
2126
- if (session.sessionFile !== undefined && stage.sessionFile !== session.sessionFile) {
2127
- stage.sessionFile = session.sessionFile;
2128
- changed = true;
2129
- }
2130
- if (!changed)
2131
- return false;
2132
- context.bumpAndNotify();
2133
- return true;
2134
- },
2135
- recordStageAttachable(runId, stageId, attachable) {
2136
- const run = context.findRun(runId);
2137
- if (!run)
2138
- return false;
2139
- const stage = context.findStage(run, stageId);
2140
- if (!stage)
2141
- return false;
2142
- const next = attachable === true ? true : undefined;
2143
- if (stage.attachable === next)
2144
- return false;
2145
- if (next === undefined) {
2146
- delete stage.attachable;
2147
- } else {
2148
- stage.attachable = next;
2149
- }
2150
- context.bumpAndNotify();
2151
- return true;
2152
- },
2153
- recordStageAttached(runId, stageId, attached) {
2154
- const run = context.findRun(runId);
2155
- if (!run)
2156
- return false;
2157
- const stage = context.findStage(run, stageId);
2158
- if (!stage)
2159
- return false;
2160
- const next = attached === true ? true : undefined;
2161
- if (stage.attached === next)
2162
- return false;
2163
- if (next === undefined) {
2164
- delete stage.attached;
2165
- } else {
2166
- stage.attached = next;
2167
- }
2168
- context.bumpAndNotify();
2169
- return true;
2170
- },
2171
- recordStageAwaitingInput(runId, stageId, awaiting, ts) {
2172
- const run = context.findRun(runId);
2173
- if (!run)
2174
- return false;
2175
- if (TERMINAL_STATUSES.has(run.status))
2176
- return false;
2177
- const stage = context.findStage(run, stageId);
2178
- if (!stage)
2179
- return false;
2180
- if (cannotAwaitInput(stage.status))
2181
- return false;
2182
- if (awaiting) {
2183
- if (stage.status === "awaiting_input")
2184
- return false;
2185
- stage.status = "awaiting_input";
2186
- stage.awaitingInputSince = ts ?? Date.now();
2187
- } else {
2188
- if (stage.pendingPrompt !== undefined)
2189
- return false;
2190
- if (stage.status !== "awaiting_input")
2191
- return false;
2192
- stage.status = "running";
2193
- delete stage.awaitingInputSince;
2194
- }
2195
- context.bumpAndNotify();
2196
- return true;
2197
- },
2198
- recordStageInputRequest(runId, stageId, request) {
2199
- const run = context.findRun(runId);
2200
- if (!run)
2201
- return false;
2202
- if (TERMINAL_STATUSES.has(run.status))
2203
- return false;
2204
- const stage = context.findStage(run, stageId);
2205
- if (!stage)
2206
- return false;
2207
- if (isTerminalStageStatus(stage.status))
2208
- return false;
2209
- if (stage.inputRequest?.id === request.id)
2210
- return false;
2211
- stage.inputRequest = { ...request };
2212
- context.bumpAndNotify();
2213
- return true;
2214
- },
2215
- clearStageInputRequest(runId, stageId) {
2216
- const run = context.findRun(runId);
2217
- if (!run)
2218
- return false;
2219
- const stage = context.findStage(run, stageId);
2220
- if (!stage || stage.inputRequest === undefined)
2221
- return false;
2222
- delete stage.inputRequest;
2223
- context.bumpAndNotify();
2224
- return true;
2225
- },
2226
- recordStageBlocked(runId, stageId, blockedBy) {
2227
- const run = context.findRun(runId);
2228
- if (!run)
2229
- return false;
2230
- if (TERMINAL_STATUSES.has(run.status))
2231
- return false;
2232
- const stage = context.findStage(run, stageId);
2233
- if (!stage)
2234
- return false;
2235
- if (cannotBlock(stage.status))
2236
- return false;
2237
- if (stage.status === "blocked") {
2238
- if (stage.blockedByStageId === blockedBy)
2239
- return false;
2240
- stage.blockedByStageId = blockedBy;
2241
- } else {
2242
- stage.status = "blocked";
2243
- stage.blockedByStageId = blockedBy;
2244
- delete stage.awaitingInputSince;
2245
- }
2246
- context.bumpAndNotify();
2247
- return true;
2248
- },
2249
- recordStageUnblocked(runId, stageId) {
2250
- const run = context.findRun(runId);
2251
- if (!run)
2252
- return false;
2253
- const stage = context.findStage(run, stageId);
2254
- if (stage?.status !== "blocked")
2255
- return false;
2256
- stage.status = "pending";
2257
- delete stage.blockedByStageId;
2258
- delete stage.awaitingInputSince;
2259
- context.bumpAndNotify();
2260
- return true;
2261
- },
2262
- recordStageNotice(runId, stageId, notice) {
2263
- const run = context.findRun(runId);
2264
- if (!run)
2265
- return false;
2266
- const stage = context.findStage(run, stageId);
2267
- if (!stage)
2268
- return false;
2269
- if (!stage.notices)
2270
- stage.notices = [];
2271
- stage.notices.push(notice);
2272
- context.bumpAndNotify();
2273
- return true;
2274
- },
2275
- recordStagePaused(runId, stageId, pausedAt, metadata) {
2276
- const run = context.findRun(runId);
2277
- if (!run)
2278
- return false;
2279
- if (TERMINAL_STATUSES.has(run.status))
2280
- return false;
2281
- const stage = context.findStage(run, stageId);
2282
- if (!stage)
2283
- return false;
2284
- if (cannotPause(stage.status)) {
2285
- if (stage.status !== "paused" || metadata?.actor === undefined)
2286
- return false;
2287
- if (stage.pauseActor === metadata.actor)
2288
- return false;
2289
- stage.pauseActor = metadata.actor;
2290
- context.bumpAndNotify();
2291
- return false;
2292
- }
2293
- context.observation.executingStageIds.delete(workflowActivityNodeKey(runId, stageId));
2294
- stage.status = "paused";
2295
- stage.pausedAt = nextControlTimestamp(pausedAt, stage.resumedAt);
2296
- stage.resumedAt = undefined;
2297
- delete stage.awaitingInputSince;
2298
- delete stage.resumeActor;
2299
- if (metadata?.actor === undefined)
2300
- delete stage.pauseActor;
2301
- else
2302
- stage.pauseActor = metadata.actor;
2303
- context.bumpAndNotify();
2304
- return true;
2305
- },
2306
- recordStageResumed(runId, stageId, resumedAt, metadata) {
2307
- const run = context.findRun(runId);
2308
- if (!run)
2309
- return false;
2310
- if (TERMINAL_STATUSES.has(run.status))
2311
- return false;
2312
- const stage = context.findStage(run, stageId);
2313
- if (!stage)
2314
- return false;
2315
- if (stage.status !== "paused" && stage.status !== "blocked") {
2316
- if (stage.status !== "running" || stage.resumedAt === undefined || metadata?.actor === undefined) {
2317
- return false;
2318
- }
2319
- if (stage.resumeActor === metadata.actor)
2320
- return false;
2321
- stage.resumeActor = metadata.actor;
2322
- context.bumpAndNotify();
2323
- return false;
2324
- }
2325
- const resumedTs = nextControlTimestamp(resumedAt, stage.pausedAt);
2326
- if (context.observation.liveRunIds.has(runId))
2327
- context.observation.executingStageIds.add(workflowActivityNodeKey(runId, stageId));
2328
- stage.status = "running";
2329
- if (stage.startedAt !== undefined) {
2330
- stage.pausedDurationMs = accumulatePausedDurationMs(stage.pausedDurationMs, stage.pausedAt, resumedTs);
2331
- }
2332
- stage.resumedAt = resumedTs;
2333
- stage.pausedAt = undefined;
2334
- delete stage.blockedByStageId;
2335
- delete stage.awaitingInputSince;
2336
- delete stage.pauseActor;
2337
- if (metadata?.actor === undefined)
2338
- delete stage.resumeActor;
2339
- else
2340
- stage.resumeActor = metadata.actor;
2341
- context.bumpAndNotify();
2342
- return true;
2343
- }
2344
- };
2345
- }
2346
-
2347
- // dist/builtin/workflows/src/shared/store-factory.ts
2348
- function createStore() {
2349
- const context = createStoreContext();
2350
- const created = {
2351
- [workflowObservationRuntimeKey]: context.observation,
2352
- ...createRunStoreMethods(context),
2353
- ...createPendingStageDeliveryStoreMethods(context),
2354
- ...createStageStoreMethods(context),
2355
- ...createToolNodeStoreMethods(context),
2356
- ...createPromptStoreMethods(context)
2357
- };
2358
- return created;
2359
- }
2360
- var SESSION_KEY = "workflows:store:v1";
2361
- var singleton = createSessionScopedSingleton(SESSION_KEY, createStore);
2362
- var store = singleton.facade;
2363
- // dist/builtin/workflows/src/shared/workflow-artifact-env.ts
2364
- var WORKFLOW_ARTIFACT_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
2365
- var ENV_WORKFLOW_ARTIFACT_DIR = "ATOMIC_WORKFLOW_ARTIFACT_DIR";
2366
-
2367
- // dist/builtin/workflows/src/shared/workflow-artifacts.ts
2368
- var ARTIFACT_PRUNE_RECHECK_MS = 60 * 60 * 1000;
2369
- var lastArtifactPruneAt = new Map;
2370
- var pendingArtifactPrunes = new Map;
2371
- function workflowArtifactRoot() {
2372
- const override = getEnvValue(ENV_WORKFLOW_ARTIFACT_DIR);
2373
- if (override !== undefined && override.length > 0)
2374
- return override;
2375
- return join(dirname(getAgentDir()), "workflows");
2376
- }
2377
- function workflowArtifactRunsRoot() {
2378
- return join(workflowArtifactRoot(), "runs");
2379
- }
2380
- function safeRunId(runId) {
2381
- const safe = runId.replace(/[^A-Za-z0-9._-]/g, "_");
2382
- return safe.length > 0 ? safe : "run";
2383
- }
2384
- function workflowArtifactRunPath(runId) {
2385
- return join(workflowArtifactRunsRoot(), safeRunId(runId));
2386
- }
2387
- function storeRunState(run) {
2388
- const hasPendingInput = run.pendingPrompt !== undefined || run.stages.some((stage) => stage.status === "awaiting_input" || stage.status === "paused" || stage.status === "blocked");
2389
- if (hasPendingInput || run.status === "pending" || run.status === "running" || run.status === "paused" || run.status === "blocked" || run.exitReason === "quit") {
2390
- return "protected";
2391
- }
2392
- return "terminal";
2393
- }
2394
- function durableRunState(backend, runId) {
2395
- const handle = backend.getLoadableWorkflow(runId);
2396
- if (handle === undefined)
2397
- return;
2398
- if (handle.status === "running" || handle.status === "paused" || handle.status === "blocked" || handle.pendingPrompts > 0) {
2399
- return "protected";
2400
- }
2401
- return "terminal";
2402
- }
2403
- function createWorkflowArtifactRunStateResolver() {
2404
- const localRuns = new Map(store.runs().map((run) => [run.id, run]));
2405
- const findLocalRun = (runId) => localRuns.get(runId) ?? [...localRuns.values()].find((run) => safeRunId(run.id) === runId);
2406
- const protectedOwners = new Set;
2407
- for (const run of localRuns.values()) {
2408
- if (storeRunState(run) !== "protected")
2409
- continue;
2410
- let cursor = run;
2411
- const visited = new Set;
2412
- while (cursor !== undefined && !visited.has(cursor.id)) {
2413
- visited.add(cursor.id);
2414
- protectedOwners.add(safeRunId(cursor.id));
2415
- const sourceId = cursor.resumedFromRunId;
2416
- if (sourceId === undefined)
2417
- break;
2418
- protectedOwners.add(safeRunId(sourceId));
2419
- cursor = findLocalRun(sourceId);
2420
- }
2421
- }
2422
- let backend;
2423
- let backendReady = true;
2424
- try {
2425
- backend = getDurableBackend();
2426
- } catch {
2427
- backendReady = false;
2428
- }
2429
- return (runId) => {
2430
- if (protectedOwners.has(runId))
2431
- return "protected";
2432
- const local = findLocalRun(runId);
2433
- const localState = local === undefined ? undefined : storeRunState(local);
2434
- if (!backendReady) {
2435
- return localState === "protected" ? "protected" : undefined;
2436
- }
2437
- let durable;
2438
- if (backend !== undefined) {
2439
- try {
2440
- durable = durableRunState(backend, runId);
2441
- } catch {
2442
- backendReady = false;
2443
- return localState === "protected" ? "protected" : undefined;
2444
- }
2445
- }
2446
- if (durable === "protected" || localState === "protected")
2447
- return "protected";
2448
- if (durable === "terminal" || localState === "terminal")
2449
- return "terminal";
2450
- return "orphan";
2451
- };
2452
- }
2453
- async function deleteTerminalDurableEntry(runId) {
2454
- let backend;
2455
- try {
2456
- backend = getDurableBackend();
2457
- } catch {
2458
- return false;
2459
- }
2460
- try {
2461
- const result = await backend.deleteWorkflowIfInactive(runId);
2462
- return result.ok || result.reason === "not_found";
2463
- } catch {
2464
- return false;
2465
- }
2466
- }
2467
- async function pruneWorkflowArtifactRuns(root = workflowArtifactRunsRoot(), now = Date.now(), stateResolver) {
2468
- try {
2469
- const entries = await readdir(root, { withFileTypes: true, encoding: "utf8" });
2470
- for (const entry of entries) {
2471
- if (!entry.isDirectory())
2472
- continue;
2473
- const entryPath = join(root, entry.name);
2474
- let metadata;
2475
- try {
2476
- metadata = await stat(entryPath);
2477
- } catch (error) {
2478
- if (error instanceof Error && "code" in error && error.code === "ENOENT")
2479
- continue;
2480
- throw error;
2481
- }
2482
- if (now - metadata.mtimeMs <= WORKFLOW_ARTIFACT_RETENTION_MS)
2483
- continue;
2484
- if (stateResolver === undefined)
2485
- continue;
2486
- const state = stateResolver(entry.name);
2487
- if (state !== "terminal" && state !== "orphan")
2488
- continue;
2489
- if (state === "terminal" && !await deleteTerminalDurableEntry(entry.name))
2490
- continue;
2491
- await rm(entryPath, { recursive: true, force: true });
2492
- }
2493
- } catch (error) {
2494
- if (error instanceof Error && "code" in error && error.code === "ENOENT")
2495
- return;
2496
- throw error;
2497
- }
2498
- }
2499
- async function pruneArtifactRootIfDue(root, now) {
2500
- const pending = pendingArtifactPrunes.get(root);
2501
- if (pending !== undefined) {
2502
- try {
2503
- await pending;
2504
- } catch {}
2505
- return;
2506
- }
2507
- const previous = lastArtifactPruneAt.get(root);
2508
- if (previous !== undefined && now - previous < ARTIFACT_PRUNE_RECHECK_MS)
2509
- return;
2510
- const operation = pruneWorkflowArtifactRuns(root, now, createWorkflowArtifactRunStateResolver());
2511
- pendingArtifactPrunes.set(root, operation);
2512
- try {
2513
- await operation;
2514
- } catch {} finally {
2515
- lastArtifactPruneAt.set(root, now);
2516
- pendingArtifactPrunes.delete(root);
2517
- }
2518
- }
2519
- function workflowArtifactDirectoryPath(runId) {
2520
- const effectiveRunId = runId ?? randomUUID2();
2521
- return join(workflowArtifactRunPath(effectiveRunId), `artifact-${randomUUID2()}`);
2522
- }
2523
- async function ensureWorkflowArtifactDirectory(directory) {
2524
- await pruneArtifactRootIfDue(workflowArtifactRunsRoot(), Date.now());
2525
- await mkdir(directory, { recursive: true });
2526
- return directory;
2527
- }
2528
- async function createWorkflowArtifactDirectory(runId) {
2529
- return ensureWorkflowArtifactDirectory(workflowArtifactDirectoryPath(runId));
2530
- }
2531
-
2532
- // dist/builtin/workflows/builtin/goal-convergence.ts
2533
- var FRACTION_TREND_RISE_DELTA = DEFAULT_RISE_DELTA / (VERIFICATION_SCALE.max - VERIFICATION_SCALE.min);
2534
- var FRACTION_TREND_FALL_DELTA = DEFAULT_FALL_DELTA / (VERIFICATION_SCALE.max - VERIFICATION_SCALE.min);
2535
- function record_convergence(round) {
2536
- return {
2537
- unresolvedBlockingCount: round.unresolvedBlockingCount,
2538
- meanFindingConfidence: round.meanFindingConfidence,
2539
- fractionProven: round.fractionProven,
2540
- demotions: round.demotions,
2541
- usage: round.usage
2542
- };
2543
- }
2544
- function classify_convergence(entries) {
2545
- return {
2546
- blocking: classify_trend(entries.map((entry) => entry.unresolvedBlockingCount)),
2547
- proven: classify_trend(entries.map((entry) => entry.fractionProven), {
2548
- riseDelta: FRACTION_TREND_RISE_DELTA,
2549
- fallDelta: FRACTION_TREND_FALL_DELTA
2550
- })
2551
- };
2552
- }
2553
- function convergence_escalation_evidence(entries) {
2554
- if (entries.length === 0)
2555
- return [];
2556
- const { blocking, proven } = classify_convergence(entries);
2557
- if (blocking.trend === "regressing" || proven.trend === "rising" && blocking.trend !== "rising")
2558
- return [];
2559
- const latest = entries[entries.length - 1]?.meanFindingConfidence;
2560
- return [
2561
- `${entries.length} round${entries.length === 1 ? "" : "s"} recorded; no observed convergence: the blocking-count trend is ${blocking.trend}.`,
2562
- `Blocking-count trend: ${blocking.trend}; raw series: ${JSON.stringify(blocking.evidence.series)}.`,
2563
- `Fraction-proven trend: ${proven.trend}; raw series: ${JSON.stringify(proven.evidence.series)}.`,
2564
- latest === null ? "Latest mean finding confidence: no findings were filed." : `Latest mean finding confidence: ${latest}.`,
2565
- "This is escalation EVIDENCE only; it never approves or terminates anything."
2566
- ];
2567
- }
2568
-
2569
- // dist/builtin/workflows/builtin/review-convergence.ts
2570
- var FINAL_ACTION_PATTERN = /\b(?:pr|pull[- ]request|merge[- ]request|review request|github pr|create pr)\b/iu;
2571
- function isFinalActionTraceability(entry) {
2572
- return FINAL_ACTION_PATTERN.test(`${entry.requirement}
2573
- ${entry.evidence}`);
2574
- }
2575
- function finalActionRemaining(traceability) {
2576
- return traceability.some((entry) => entry.status !== "proven" && isFinalActionTraceability(entry));
2577
- }
2578
- var MAX_BLOCKING_PRIORITY = 2;
2579
- function findingBlocksClosure(finding) {
2580
- const alignment = finding.objective_alignment;
2581
- if (alignment === "beyond_objective" || alignment === "contradicts_objective") {
2582
- return false;
2583
- }
2584
- if (alignment === "required_by_objective")
2585
- return true;
2586
- if (alignment !== "consistent_with_objective")
2587
- return true;
2588
- const priority = finding.priority;
2589
- if (priority === undefined || priority === null)
2590
- return true;
2591
- return priority <= MAX_BLOCKING_PRIORITY;
2592
- }
2593
- function findingConsolidationKey(finding) {
2594
- const normalizedTitle = finding.title.replace(/^\s*\[P[0-3]\]\s*/iu, "").toLowerCase().replace(/\s+/gu, " ").trim();
2595
- return `${finding.code_location?.absolute_file_path ?? ""}::${normalizedTitle}`;
2596
- }
2597
- function consolidateFindingsBatch(reviews) {
2598
- const byKey = new Map;
2599
- for (const review of reviews) {
2600
- for (const finding of review.findings) {
2601
- const key = findingConsolidationKey(finding);
2602
- const existing = byKey.get(key);
2603
- if (existing === undefined) {
2604
- byKey.set(key, {
2605
- finding,
2606
- reviewers: [review.reviewer],
2607
- blocking: findingBlocksClosure(finding)
2608
- });
2609
- continue;
2610
- }
2611
- if (!existing.reviewers.includes(review.reviewer)) {
2612
- existing.reviewers.push(review.reviewer);
2613
- }
2614
- existing.blocking = existing.blocking || findingBlocksClosure(finding);
2615
- }
2616
- }
2617
- return [...byKey.values()].sort((a, b) => Number(b.blocking) - Number(a.blocking));
2618
- }
2619
- var PREVIEW_LIMIT = 500;
2620
- function rawTextPreview(rawText) {
2621
- const trimmed = rawText.trim();
2622
- if (trimmed.length === 0)
2623
- return;
2624
- return trimmed.slice(0, PREVIEW_LIMIT);
2625
- }
2626
- function parseFailureDiagnostics(reviewer, rawText) {
2627
- const preview = rawTextPreview(rawText);
2628
- const base = `Structured reviewer decision parse failed for ${reviewer}: no schema-valid JSON decision was returned.`;
2629
- return preview === undefined ? [base] : [base, `Raw reviewer output preview: ${preview}`];
2630
- }
2631
- function errorMessage2(error) {
2632
- return error instanceof Error ? error.message : String(error);
2633
- }
2634
- function reviewerFailureText(error) {
2635
- const messages = [errorMessage2(error)];
2636
- if (error instanceof AggregateError) {
2637
- for (const nested of error.errors) {
2638
- messages.push(errorMessage2(nested));
2639
- }
2640
- }
2641
- return [...new Set(messages.map((message) => message.trim()).filter(Boolean))].join(`
2642
- `);
2643
- }
2644
- function summarizeReviewConvergence(args) {
2645
- return {
2646
- parsed: args.parsed,
2647
- approved: args.approved,
2648
- stopReviewLoop: args.stopReviewLoop,
2649
- nextAction: args.nextAction,
2650
- finalActionRemaining: args.finalActionRemaining ?? args.nextAction === "pull-request",
2651
- diagnostics: args.diagnostics
2652
- };
2653
- }
2654
-
2655
- // dist/builtin/workflows/builtin/goal-reverify.ts
2656
- import { Type } from "typebox";
2657
- var DEFAULT_REVERIFY_THRESHOLD = 0.7;
2658
- var STANDARD_CONFIRM_THRESHOLD = 10;
2659
- var REQUIRED_CONFIRM_THRESHOLD = 6;
2660
- var DEFAULT_REPEATS = 3;
2661
- var REVERIFY_QUESTION = "Assess this specific finding against the code it cites: is it a real, objective-relevant, currently-unresolved blocker?";
2662
- var reverifySchema = Type.Object({
2663
- score: VERIFICATION_SCALE.schema,
2664
- evidence: Type.Array(Type.String())
2665
- }, { additionalProperties: false });
2666
- function isRecord(value) {
2667
- return typeof value === "object" && value !== null && !Array.isArray(value);
2668
- }
2669
- function isStringArray(value) {
2670
- return Array.isArray(value) && value.every((item) => typeof item === "string");
2671
- }
2672
- function parseReport(result) {
2673
- if (!isRecord(result.structured))
2674
- return;
2675
- const score = result.structured.score;
2676
- if (typeof score !== "number" || !Number.isInteger(score) || score < VERIFICATION_SCALE.min || score > VERIFICATION_SCALE.max) {
2677
- return;
2678
- }
2679
- const evidence = result.structured.evidence;
2680
- return {
2681
- score,
2682
- evidence: isStringArray(evidence) ? evidence : []
2683
- };
2684
- }
2685
- function requiredByObjective(finding) {
2686
- return finding.finding.objective_alignment === "required_by_objective";
2687
- }
2688
- function is_reverifiable(finding, threshold = DEFAULT_REVERIFY_THRESHOLD) {
2689
- const confidence = finding.finding.confidence_score;
2690
- return finding.blocking && finding.reviewers.length === 1 && typeof confidence === "number" && Number.isFinite(confidence) && confidence < threshold && finding.finding.objective_alignment !== "beyond_objective" && finding.finding.objective_alignment !== "contradicts_objective";
2691
- }
2692
- function readPaths(finding, candidateRefs) {
2693
- const codePath = finding.finding.code_location?.absolute_file_path;
2694
- return [
2695
- ...codePath === undefined ? [] : [codePath],
2696
- ...candidateRefs
2697
- ];
2698
- }
2699
- function promptFor(finding, context) {
2700
- const codePath = finding.finding.code_location?.absolute_file_path;
2701
- const candidate = {
2702
- ...codePath === undefined ? {} : { path: codePath },
2703
- body: [
2704
- `Title: ${finding.finding.title}`,
2705
- `Body: ${finding.finding.body ?? ""}`,
2706
- `Code location: ${codePath ?? "not supplied"}`
2707
- ].join(`
2708
- `)
2709
- };
2710
- const head = {
2711
- task: `${REVERIFY_QUESTION}
2712
-
2713
- Objective:
2714
- ${context.objective}`,
2715
- groundTruthNote: `The objective is the contract. Verify the finding against observed code, not reviewer narration.`,
2716
- candidates: [candidate],
2717
- outputFormat: "Call structured_output with score (an integer from 1 to 20) and evidence (an array of observed, concise reasons)."
2718
- };
2719
- const prompt = build_scoring_prompt(head, {
2720
- id: "finding_reverification",
2721
- name: "Finding re-verification",
2722
- description: REVERIFY_QUESTION
2723
- });
2724
- return {
2725
- prompt,
2726
- reads: [
2727
- ...readPaths(finding, context.candidateRefs),
2728
- ...scoring_prompt_reads(head)
2729
- ]
2730
- };
2731
- }
2732
- async function runRepeat(ctx, finding, context, stageName) {
2733
- try {
2734
- const rendered = promptFor(finding, context);
2735
- const options = {
2736
- prompt: rendered.prompt,
2737
- context: "fresh",
2738
- reads: rendered.reads,
2739
- schema: reverifySchema
2740
- };
2741
- return parseReport(await ctx.task(stageName, options));
2742
- } catch {
2743
- return;
2744
- }
2745
- }
2746
- async function reverify_finding(ctx, input) {
2747
- if (!is_reverifiable(input.finding, input.threshold)) {
2748
- throw new Error("Cannot re-verify an ineligible finding.");
2749
- }
2750
- const repeatCount = Number.isFinite(input.repeats) && input.repeats !== undefined ? Math.max(0, Math.floor(input.repeats)) : DEFAULT_REPEATS;
2751
- const perRepeat = [];
2752
- const evidence = [];
2753
- const validScores = [];
2754
- for (let repeat = 1;repeat <= repeatCount; repeat += 1) {
2755
- let report = await runRepeat(ctx, input.finding, input.context, `reverify-${repeat}`);
2756
- if (report === undefined) {
2757
- report = await runRepeat(ctx, input.finding, input.context, `reverify-${repeat}-reask`);
2758
- }
2759
- if (report === undefined) {
2760
- perRepeat.push(null);
2761
- evidence.push(`Re-verification repeat ${repeat} was invalid after one re-ask; doubt defaults to confirmed.`);
2762
- continue;
2763
- }
2764
- perRepeat.push(report.score);
2765
- validScores.push(report.score);
2766
- if (report.evidence.length === 0) {
2767
- evidence.push(`Re-verification repeat ${repeat} scored ${report.score}/20.`);
2768
- } else {
2769
- evidence.push(...report.evidence);
2770
- }
2771
- }
2772
- const meanScore = validScores.length === 0 ? 0 : validScores.reduce((total, score) => total + score, 0) / validScores.length;
2773
- const validCount = validScores.length;
2774
- const requiredQuorum = Math.ceil(repeatCount / 2);
2775
- const demoted = requiredByObjective(input.finding) ? repeatCount > 0 && validCount === repeatCount && meanScore < REQUIRED_CONFIRM_THRESHOLD : validCount > 0 && validCount >= requiredQuorum && meanScore < STANDARD_CONFIRM_THRESHOLD;
2776
- return {
2777
- verdict: demoted ? "demoted" : "confirmed",
2778
- meanScore,
2779
- perRepeat,
2780
- evidence
2781
- };
2782
- }
2783
- function auditKey(finding) {
2784
- return JSON.stringify([
2785
- finding.finding.code_location?.absolute_file_path ?? "",
2786
- finding.finding.title,
2787
- finding.reviewers
2788
- ]);
2789
- }
2790
- function apply_reverify_results(batch, audits) {
2791
- const demoted = new Set(audits.filter((audit) => audit.verdict === "demoted").map((audit) => auditKey(audit.finding)));
2792
- return {
2793
- batch: batch.map((entry) => demoted.has(auditKey(entry)) ? { ...entry, blocking: false } : entry),
2794
- audits
2795
- };
2796
- }
2797
- async function reverify_consolidated_batch(ctx, input) {
2798
- const audits = [];
2799
- for (const entry of input.batch) {
2800
- if (!is_reverifiable(entry, input.threshold))
2801
- continue;
2802
- const result = await reverify_finding(ctx, {
2803
- finding: entry,
2804
- context: input.context,
2805
- repeats: input.repeats,
2806
- threshold: input.threshold
2807
- });
2808
- audits.push({ finding: entry, ...result });
2809
- }
2810
- return apply_reverify_results(input.batch, audits);
2811
- }
2812
-
2813
- export { workflowArtifactDirectoryPath, ensureWorkflowArtifactDirectory, createWorkflowArtifactDirectory, record_convergence, convergence_escalation_evidence, finalActionRemaining, consolidateFindingsBatch, parseFailureDiagnostics, reviewerFailureText, summarizeReviewConvergence, reverify_consolidated_batch };