@warlock.js/ai 4.4.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (648) hide show
  1. package/CHANGELOG.md +63 -52
  2. package/cjs/index.cjs +240 -14147
  3. package/cjs/src-Bmajk4Qg.cjs +30 -0
  4. package/cjs/src-OZyDYHxm.cjs +25089 -0
  5. package/cjs/src-OZyDYHxm.cjs.map +1 -0
  6. package/esm/agent/agent-config.type.d.mts +119 -1
  7. package/esm/agent/agent-config.type.d.mts.map +1 -1
  8. package/esm/agent/agent-input-builder.mjs +27 -6
  9. package/esm/agent/agent-input-builder.mjs.map +1 -1
  10. package/esm/agent/agent.d.mts +40 -1
  11. package/esm/agent/agent.d.mts.map +1 -1
  12. package/esm/agent/agent.mjs +328 -36
  13. package/esm/agent/agent.mjs.map +1 -1
  14. package/esm/agent/index.d.mts +2 -1
  15. package/esm/agent/index.mjs +1 -0
  16. package/esm/agent/judge-config.type.d.mts +33 -0
  17. package/esm/agent/judge-config.type.d.mts.map +1 -0
  18. package/esm/agent/judge-config.type.mjs +13 -0
  19. package/esm/agent/judge-config.type.mjs.map +1 -0
  20. package/esm/agent/signature.mjs +57 -0
  21. package/esm/agent/signature.mjs.map +1 -0
  22. package/esm/agent/snapshot.mjs +101 -0
  23. package/esm/agent/snapshot.mjs.map +1 -0
  24. package/esm/ai-openai/src/embedder.mjs +4 -0
  25. package/esm/ai-openai/src/image.mjs +5 -0
  26. package/esm/ai-openai/src/index.mjs +7 -0
  27. package/esm/ai-openai/src/model.mjs +5 -0
  28. package/esm/ai-openai/src/sdk.mjs +9 -0
  29. package/esm/ai-openai/src/speech.mjs +5 -0
  30. package/esm/ai-openai/src/transcription.mjs +6 -0
  31. package/esm/ai-openai/src/utils/index.mjs +5 -0
  32. package/esm/ai-openai/src/utils/to-openai-messages.mjs +3 -0
  33. package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
  34. package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
  35. package/esm/ai.d.mts +164 -53
  36. package/esm/ai.d.mts.map +1 -1
  37. package/esm/ai.mjs +79 -8
  38. package/esm/ai.mjs.map +1 -1
  39. package/esm/batch/batch.d.mts.map +1 -1
  40. package/esm/batch/batch.mjs +21 -1
  41. package/esm/batch/batch.mjs.map +1 -1
  42. package/esm/batch/batch.type.d.mts +11 -4
  43. package/esm/batch/batch.type.d.mts.map +1 -1
  44. package/esm/config.d.mts +39 -3
  45. package/esm/config.d.mts.map +1 -1
  46. package/esm/config.mjs +26 -2
  47. package/esm/config.mjs.map +1 -1
  48. package/esm/contracts/agent/agent-options.type.d.mts +33 -5
  49. package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
  50. package/esm/contracts/agent/agent-snapshot.type.d.mts +90 -0
  51. package/esm/contracts/agent/agent-snapshot.type.d.mts.map +1 -0
  52. package/esm/contracts/agent/agent.contract.d.mts +29 -1
  53. package/esm/contracts/agent/agent.contract.d.mts.map +1 -1
  54. package/esm/contracts/agent/eval.type.d.mts +43 -2
  55. package/esm/contracts/agent/eval.type.d.mts.map +1 -1
  56. package/esm/contracts/agent/index.d.mts +2 -1
  57. package/esm/contracts/attachment-policy.type.d.mts +51 -0
  58. package/esm/contracts/attachment-policy.type.d.mts.map +1 -0
  59. package/esm/contracts/attachment.type.d.mts +16 -7
  60. package/esm/contracts/attachment.type.d.mts.map +1 -1
  61. package/esm/contracts/content-part.type.d.mts +14 -5
  62. package/esm/contracts/content-part.type.d.mts.map +1 -1
  63. package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -1
  64. package/esm/contracts/image-model.contract.d.mts +156 -0
  65. package/esm/contracts/image-model.contract.d.mts.map +1 -0
  66. package/esm/contracts/index.d.mts +13 -6
  67. package/esm/contracts/model.contract.d.mts +11 -8
  68. package/esm/contracts/model.contract.d.mts.map +1 -1
  69. package/esm/contracts/orchestrator/index.d.mts +1 -0
  70. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +31 -2
  71. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -1
  72. package/esm/contracts/orchestrator/session-lock.contract.d.mts +47 -0
  73. package/esm/contracts/orchestrator/session-lock.contract.d.mts.map +1 -0
  74. package/esm/contracts/planner/index.d.mts +3 -2
  75. package/esm/contracts/planner/planner-config.type.d.mts +61 -0
  76. package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
  77. package/esm/contracts/planner/planner-execute-options.type.d.mts +60 -1
  78. package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -1
  79. package/esm/contracts/planner/planner-result.type.d.mts +8 -0
  80. package/esm/contracts/planner/planner-result.type.d.mts.map +1 -1
  81. package/esm/contracts/planner/planner-snapshot.type.d.mts +77 -0
  82. package/esm/contracts/planner/planner-snapshot.type.d.mts.map +1 -0
  83. package/esm/contracts/planner/planner.contract.d.mts +21 -1
  84. package/esm/contracts/planner/planner.contract.d.mts.map +1 -1
  85. package/esm/contracts/result/agent-result.type.d.mts +6 -4
  86. package/esm/contracts/result/agent-result.type.d.mts.map +1 -1
  87. package/esm/contracts/result/base-report.type.d.mts +21 -3
  88. package/esm/contracts/result/base-report.type.d.mts.map +1 -1
  89. package/esm/contracts/result/base-report.type.mjs.map +1 -1
  90. package/esm/contracts/result/execution-report.type.d.mts +53 -1
  91. package/esm/contracts/result/execution-report.type.d.mts.map +1 -1
  92. package/esm/contracts/result/supervisor-result.type.d.mts +14 -2
  93. package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
  94. package/esm/contracts/result/workflow-result.type.d.mts +2 -1
  95. package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
  96. package/esm/contracts/sdk-adapter.contract.d.mts +37 -0
  97. package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -1
  98. package/esm/contracts/speech-model.contract.d.mts +97 -0
  99. package/esm/contracts/speech-model.contract.d.mts.map +1 -0
  100. package/esm/contracts/supervisor/supervisor-config.type.d.mts +29 -0
  101. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
  102. package/esm/contracts/system-prompt.contract.d.mts +103 -1
  103. package/esm/contracts/system-prompt.contract.d.mts.map +1 -1
  104. package/esm/contracts/team/index.d.mts +1 -0
  105. package/esm/contracts/team/team-config.type.d.mts +127 -0
  106. package/esm/contracts/team/team-config.type.d.mts.map +1 -0
  107. package/esm/contracts/tool.contract.d.mts +4 -2
  108. package/esm/contracts/tool.contract.d.mts.map +1 -1
  109. package/esm/contracts/transcription-model.contract.d.mts +101 -0
  110. package/esm/contracts/transcription-model.contract.d.mts.map +1 -0
  111. package/esm/contracts/workflow/step.contract.d.mts +30 -5
  112. package/esm/contracts/workflow/step.contract.d.mts.map +1 -1
  113. package/esm/contracts/workflow/workflow.contract.d.mts +16 -0
  114. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
  115. package/esm/errors/agent-drift-error.d.mts +32 -0
  116. package/esm/errors/agent-drift-error.d.mts.map +1 -0
  117. package/esm/errors/agent-drift-error.mjs +31 -0
  118. package/esm/errors/agent-drift-error.mjs.map +1 -0
  119. package/esm/errors/error-code.type.d.mts +1 -1
  120. package/esm/errors/index.d.mts +3 -0
  121. package/esm/errors/index.mjs +3 -0
  122. package/esm/errors/outbound-policy-error.d.mts +27 -0
  123. package/esm/errors/outbound-policy-error.d.mts.map +1 -0
  124. package/esm/errors/outbound-policy-error.mjs +32 -0
  125. package/esm/errors/outbound-policy-error.mjs.map +1 -0
  126. package/esm/errors/planner-drift-error.d.mts +34 -0
  127. package/esm/errors/planner-drift-error.d.mts.map +1 -0
  128. package/esm/errors/planner-drift-error.mjs +33 -0
  129. package/esm/errors/planner-drift-error.mjs.map +1 -0
  130. package/esm/eval/dataset.d.mts +28 -0
  131. package/esm/eval/dataset.d.mts.map +1 -0
  132. package/esm/eval/dataset.mjs +112 -0
  133. package/esm/eval/dataset.mjs.map +1 -0
  134. package/esm/eval/dataset.type.d.mts +53 -0
  135. package/esm/eval/dataset.type.d.mts.map +1 -0
  136. package/esm/eval/eval-runner.d.mts.map +1 -1
  137. package/esm/eval/eval-runner.mjs +16 -2
  138. package/esm/eval/eval-runner.mjs.map +1 -1
  139. package/esm/eval/index.d.mts +20 -1
  140. package/esm/eval/index.d.mts.map +1 -1
  141. package/esm/eval/index.mjs +20 -2
  142. package/esm/eval/index.mjs.map +1 -1
  143. package/esm/eval/regression.d.mts +30 -0
  144. package/esm/eval/regression.d.mts.map +1 -0
  145. package/esm/eval/regression.mjs +51 -0
  146. package/esm/eval/regression.mjs.map +1 -0
  147. package/esm/eval/report-json.d.mts +30 -0
  148. package/esm/eval/report-json.d.mts.map +1 -0
  149. package/esm/eval/report-json.mjs +33 -0
  150. package/esm/eval/report-json.mjs.map +1 -0
  151. package/esm/eval/report-junit.d.mts +22 -0
  152. package/esm/eval/report-junit.d.mts.map +1 -0
  153. package/esm/eval/report-junit.mjs +60 -0
  154. package/esm/eval/report-junit.mjs.map +1 -0
  155. package/esm/guard/contracts/guard-options.type.d.mts +165 -0
  156. package/esm/guard/contracts/guard-options.type.d.mts.map +1 -0
  157. package/esm/guard/contracts/guardrail.contract.d.mts +78 -0
  158. package/esm/guard/contracts/guardrail.contract.d.mts.map +1 -0
  159. package/esm/guard/contracts/index.d.mts +4 -0
  160. package/esm/guard/contracts/openai-client.contract.d.mts +51 -0
  161. package/esm/guard/contracts/openai-client.contract.d.mts.map +1 -0
  162. package/esm/guard/contracts/verdict.type.d.mts +76 -0
  163. package/esm/guard/contracts/verdict.type.d.mts.map +1 -0
  164. package/esm/guard/detectors/index.d.mts +4 -0
  165. package/esm/guard/detectors/index.mjs +6 -0
  166. package/esm/guard/detectors/injection.d.mts +34 -0
  167. package/esm/guard/detectors/injection.d.mts.map +1 -0
  168. package/esm/guard/detectors/injection.mjs +254 -0
  169. package/esm/guard/detectors/injection.mjs.map +1 -0
  170. package/esm/guard/detectors/moderation.d.mts +32 -0
  171. package/esm/guard/detectors/moderation.d.mts.map +1 -0
  172. package/esm/guard/detectors/moderation.mjs +134 -0
  173. package/esm/guard/detectors/moderation.mjs.map +1 -0
  174. package/esm/guard/detectors/pii.d.mts +41 -0
  175. package/esm/guard/detectors/pii.d.mts.map +1 -0
  176. package/esm/guard/detectors/pii.mjs +199 -0
  177. package/esm/guard/detectors/pii.mjs.map +1 -0
  178. package/esm/guard/detectors/topic.d.mts +29 -0
  179. package/esm/guard/detectors/topic.d.mts.map +1 -0
  180. package/esm/guard/detectors/topic.mjs +99 -0
  181. package/esm/guard/detectors/topic.mjs.map +1 -0
  182. package/esm/guard/errors.d.mts +12 -0
  183. package/esm/guard/errors.d.mts.map +1 -0
  184. package/esm/guard/errors.mjs +18 -0
  185. package/esm/guard/errors.mjs.map +1 -0
  186. package/esm/guard/guard.d.mts +67 -0
  187. package/esm/guard/guard.d.mts.map +1 -0
  188. package/esm/guard/guard.mjs +209 -0
  189. package/esm/guard/guard.mjs.map +1 -0
  190. package/esm/guard/guardrail.d.mts +39 -0
  191. package/esm/guard/guardrail.d.mts.map +1 -0
  192. package/esm/guard/guardrail.mjs +22 -0
  193. package/esm/guard/guardrail.mjs.map +1 -0
  194. package/esm/human/contracts/approval.type.d.mts +154 -0
  195. package/esm/human/contracts/approval.type.d.mts.map +1 -0
  196. package/esm/human/contracts/human-approval.type.d.mts +38 -0
  197. package/esm/human/contracts/human-approval.type.d.mts.map +1 -0
  198. package/esm/human/contracts/index.d.mts +4 -0
  199. package/esm/human/contracts/interrupt-store.contract.d.mts +112 -0
  200. package/esm/human/contracts/interrupt-store.contract.d.mts.map +1 -0
  201. package/esm/human/contracts/resume.type.d.mts +77 -0
  202. package/esm/human/contracts/resume.type.d.mts.map +1 -0
  203. package/esm/human/errors.d.mts +84 -0
  204. package/esm/human/errors.d.mts.map +1 -0
  205. package/esm/human/errors.mjs +60 -0
  206. package/esm/human/errors.mjs.map +1 -0
  207. package/esm/human/human-approval.d.mts +57 -0
  208. package/esm/human/human-approval.d.mts.map +1 -0
  209. package/esm/human/human-approval.mjs +170 -0
  210. package/esm/human/human-approval.mjs.map +1 -0
  211. package/esm/human/policy.d.mts +55 -0
  212. package/esm/human/policy.d.mts.map +1 -0
  213. package/esm/human/policy.mjs +67 -0
  214. package/esm/human/policy.mjs.map +1 -0
  215. package/esm/human/register.mjs +37 -0
  216. package/esm/human/register.mjs.map +1 -0
  217. package/esm/human/resume-seed.mjs +53 -0
  218. package/esm/human/resume-seed.mjs.map +1 -0
  219. package/esm/human/resume.d.mts +54 -0
  220. package/esm/human/resume.d.mts.map +1 -0
  221. package/esm/human/resume.mjs +121 -0
  222. package/esm/human/resume.mjs.map +1 -0
  223. package/esm/human/stores/index.mjs +5 -0
  224. package/esm/human/stores/memory.d.mts +30 -0
  225. package/esm/human/stores/memory.d.mts.map +1 -0
  226. package/esm/human/stores/memory.mjs +91 -0
  227. package/esm/human/stores/memory.mjs.map +1 -0
  228. package/esm/human/stores/pg.d.mts +59 -0
  229. package/esm/human/stores/pg.d.mts.map +1 -0
  230. package/esm/human/stores/pg.mjs +220 -0
  231. package/esm/human/stores/pg.mjs.map +1 -0
  232. package/esm/human/stores/redis.d.mts +56 -0
  233. package/esm/human/stores/redis.d.mts.map +1 -0
  234. package/esm/human/stores/redis.mjs +201 -0
  235. package/esm/human/stores/redis.mjs.map +1 -0
  236. package/esm/image/image-cost.d.mts +32 -0
  237. package/esm/image/image-cost.d.mts.map +1 -0
  238. package/esm/image/image-cost.mjs +55 -0
  239. package/esm/image/image-cost.mjs.map +1 -0
  240. package/esm/image/image.d.mts +92 -0
  241. package/esm/image/image.d.mts.map +1 -0
  242. package/esm/image/image.mjs +113 -0
  243. package/esm/image/image.mjs.map +1 -0
  244. package/esm/image/index.mjs +4 -0
  245. package/esm/index.d.mts +137 -24
  246. package/esm/index.mjs +101 -11
  247. package/esm/middleware/builtins/budget.mjs +6 -2
  248. package/esm/middleware/builtins/budget.mjs.map +1 -1
  249. package/esm/middleware/utils/extract-user-text.d.mts +8 -1
  250. package/esm/middleware/utils/extract-user-text.d.mts.map +1 -1
  251. package/esm/middleware/utils/extract-user-text.mjs +8 -1
  252. package/esm/middleware/utils/extract-user-text.mjs.map +1 -1
  253. package/esm/mock/index.d.mts +3 -0
  254. package/esm/mock/index.mjs +3 -0
  255. package/esm/mock/mock-config.type.d.mts +22 -0
  256. package/esm/mock/mock-config.type.d.mts.map +1 -1
  257. package/esm/mock/mock-image-model.d.mts +41 -0
  258. package/esm/mock/mock-image-model.d.mts.map +1 -0
  259. package/esm/mock/mock-image-model.mjs +52 -0
  260. package/esm/mock/mock-image-model.mjs.map +1 -0
  261. package/esm/mock/mock-sdk.d.mts +7 -1
  262. package/esm/mock/mock-sdk.d.mts.map +1 -1
  263. package/esm/mock/mock-sdk.mjs +27 -0
  264. package/esm/mock/mock-sdk.mjs.map +1 -1
  265. package/esm/mock/mock-speech-model.d.mts +31 -0
  266. package/esm/mock/mock-speech-model.d.mts.map +1 -0
  267. package/esm/mock/mock-speech-model.mjs +39 -0
  268. package/esm/mock/mock-speech-model.mjs.map +1 -0
  269. package/esm/mock/mock-transcription-model.d.mts +32 -0
  270. package/esm/mock/mock-transcription-model.d.mts.map +1 -0
  271. package/esm/mock/mock-transcription-model.mjs +36 -0
  272. package/esm/mock/mock-transcription-model.mjs.map +1 -0
  273. package/esm/object-stream/index.d.mts +2 -0
  274. package/esm/object-stream/index.mjs +4 -0
  275. package/esm/object-stream/parse-partial-json.d.mts +22 -0
  276. package/esm/object-stream/parse-partial-json.d.mts.map +1 -0
  277. package/esm/object-stream/parse-partial-json.mjs +78 -0
  278. package/esm/object-stream/parse-partial-json.mjs.map +1 -0
  279. package/esm/object-stream/stream-object.d.mts +68 -0
  280. package/esm/object-stream/stream-object.d.mts.map +1 -0
  281. package/esm/object-stream/stream-object.mjs +104 -0
  282. package/esm/object-stream/stream-object.mjs.map +1 -0
  283. package/esm/observe/index.mjs +4 -0
  284. package/esm/observe/observer-registry.d.mts +30 -0
  285. package/esm/observe/observer-registry.d.mts.map +1 -0
  286. package/esm/observe/observer-registry.mjs +51 -0
  287. package/esm/observe/observer-registry.mjs.map +1 -0
  288. package/esm/observe/observer.contract.d.mts +40 -0
  289. package/esm/observe/observer.contract.d.mts.map +1 -0
  290. package/esm/observe/resolve-observers.d.mts +40 -0
  291. package/esm/observe/resolve-observers.d.mts.map +1 -0
  292. package/esm/observe/resolve-observers.mjs +73 -0
  293. package/esm/observe/resolve-observers.mjs.map +1 -0
  294. package/esm/orchestrator/execution.d.mts.map +1 -1
  295. package/esm/orchestrator/execution.mjs +5 -2
  296. package/esm/orchestrator/execution.mjs.map +1 -1
  297. package/esm/orchestrator/index.d.mts +1 -0
  298. package/esm/orchestrator/index.mjs +1 -0
  299. package/esm/orchestrator/orchestrator.d.mts.map +1 -1
  300. package/esm/orchestrator/orchestrator.mjs +39 -6
  301. package/esm/orchestrator/orchestrator.mjs.map +1 -1
  302. package/esm/orchestrator/session-lock.d.mts +25 -0
  303. package/esm/orchestrator/session-lock.d.mts.map +1 -0
  304. package/esm/orchestrator/session-lock.mjs +83 -0
  305. package/esm/orchestrator/session-lock.mjs.map +1 -0
  306. package/esm/planner/dag-scheduler.mjs +97 -0
  307. package/esm/planner/dag-scheduler.mjs.map +1 -0
  308. package/esm/planner/plan-prompt.d.mts +1 -1
  309. package/esm/planner/plan-prompt.d.mts.map +1 -1
  310. package/esm/planner/plan-prompt.mjs +2 -1
  311. package/esm/planner/plan-prompt.mjs.map +1 -1
  312. package/esm/planner/planner-run.d.mts +8 -0
  313. package/esm/planner/planner-run.d.mts.map +1 -1
  314. package/esm/planner/planner-run.mjs +457 -31
  315. package/esm/planner/planner-run.mjs.map +1 -1
  316. package/esm/planner/planner.d.mts.map +1 -1
  317. package/esm/planner/planner.mjs +26 -2
  318. package/esm/planner/planner.mjs.map +1 -1
  319. package/esm/planner/snapshot.mjs +95 -0
  320. package/esm/planner/snapshot.mjs.map +1 -0
  321. package/esm/prompt/errors.d.mts +57 -0
  322. package/esm/prompt/errors.d.mts.map +1 -0
  323. package/esm/prompt/errors.mjs +73 -0
  324. package/esm/prompt/errors.mjs.map +1 -0
  325. package/esm/prompt/index.d.mts +3 -0
  326. package/esm/prompt/index.mjs +4 -0
  327. package/esm/prompt/prompt-langfuse-sync.mjs +104 -0
  328. package/esm/prompt/prompt-langfuse-sync.mjs.map +1 -0
  329. package/esm/prompt/prompt-langfuse-sync.type.d.mts +32 -0
  330. package/esm/prompt/prompt-langfuse-sync.type.d.mts.map +1 -0
  331. package/esm/prompt/prompt-validate.mjs +170 -0
  332. package/esm/prompt/prompt-validate.mjs.map +1 -0
  333. package/esm/prompt/prompt.d.mts +54 -0
  334. package/esm/prompt/prompt.d.mts.map +1 -0
  335. package/esm/prompt/prompt.mjs +218 -0
  336. package/esm/prompt/prompt.mjs.map +1 -0
  337. package/esm/prompt/prompt.type.d.mts +174 -0
  338. package/esm/prompt/prompt.type.d.mts.map +1 -0
  339. package/esm/prompts/index.d.mts +3 -0
  340. package/esm/prompts/index.mjs +3 -0
  341. package/esm/prompts/prompts-manager.contract.d.mts +154 -0
  342. package/esm/prompts/prompts-manager.contract.d.mts.map +1 -0
  343. package/esm/prompts/prompts-manager.d.mts +38 -0
  344. package/esm/prompts/prompts-manager.d.mts.map +1 -0
  345. package/esm/prompts/prompts-manager.mjs +410 -0
  346. package/esm/prompts/prompts-manager.mjs.map +1 -0
  347. package/esm/prompts/prompts-manager.type.d.mts +172 -0
  348. package/esm/prompts/prompts-manager.type.d.mts.map +1 -0
  349. package/esm/prompts/prompts-validate.mjs +200 -0
  350. package/esm/prompts/prompts-validate.mjs.map +1 -0
  351. package/esm/rag/as-tool.mjs +48 -0
  352. package/esm/rag/as-tool.mjs.map +1 -0
  353. package/esm/rag/chunk/chunk.d.mts +24 -0
  354. package/esm/rag/chunk/chunk.d.mts.map +1 -0
  355. package/esm/rag/chunk/chunk.mjs +44 -0
  356. package/esm/rag/chunk/chunk.mjs.map +1 -0
  357. package/esm/rag/chunk/fixed.mjs +32 -0
  358. package/esm/rag/chunk/fixed.mjs.map +1 -0
  359. package/esm/rag/chunk/markdown.mjs +75 -0
  360. package/esm/rag/chunk/markdown.mjs.map +1 -0
  361. package/esm/rag/chunk/recursive.mjs +132 -0
  362. package/esm/rag/chunk/recursive.mjs.map +1 -0
  363. package/esm/rag/chunk/sentence.mjs +73 -0
  364. package/esm/rag/chunk/sentence.mjs.map +1 -0
  365. package/esm/rag/contracts/chunk-options.type.d.mts +35 -0
  366. package/esm/rag/contracts/chunk-options.type.d.mts.map +1 -0
  367. package/esm/rag/contracts/citation.type.d.mts +35 -0
  368. package/esm/rag/contracts/citation.type.d.mts.map +1 -0
  369. package/esm/rag/contracts/index.d.mts +4 -0
  370. package/esm/rag/contracts/rag-config.type.d.mts +68 -0
  371. package/esm/rag/contracts/rag-config.type.d.mts.map +1 -0
  372. package/esm/rag/contracts/rag-document.type.d.mts +21 -0
  373. package/esm/rag/contracts/rag-document.type.d.mts.map +1 -0
  374. package/esm/rag/hybrid/bm25.d.mts +23 -0
  375. package/esm/rag/hybrid/bm25.d.mts.map +1 -0
  376. package/esm/rag/hybrid/bm25.mjs +51 -0
  377. package/esm/rag/hybrid/bm25.mjs.map +1 -0
  378. package/esm/rag/hybrid/hybrid-rank.d.mts +33 -0
  379. package/esm/rag/hybrid/hybrid-rank.d.mts.map +1 -0
  380. package/esm/rag/hybrid/hybrid-rank.mjs +29 -0
  381. package/esm/rag/hybrid/hybrid-rank.mjs.map +1 -0
  382. package/esm/rag/hybrid/rrf.d.mts +25 -0
  383. package/esm/rag/hybrid/rrf.d.mts.map +1 -0
  384. package/esm/rag/hybrid/rrf.mjs +30 -0
  385. package/esm/rag/hybrid/rrf.mjs.map +1 -0
  386. package/esm/rag/index.d.mts +22 -0
  387. package/esm/rag/index.mjs +18 -0
  388. package/esm/rag/loaders/errors.d.mts +19 -0
  389. package/esm/rag/loaders/errors.d.mts.map +1 -0
  390. package/esm/rag/loaders/errors.mjs +25 -0
  391. package/esm/rag/loaders/errors.mjs.map +1 -0
  392. package/esm/rag/loaders/index.mjs +7 -0
  393. package/esm/rag/loaders/load-html.d.mts +26 -0
  394. package/esm/rag/loaders/load-html.d.mts.map +1 -0
  395. package/esm/rag/loaders/load-html.mjs +138 -0
  396. package/esm/rag/loaders/load-html.mjs.map +1 -0
  397. package/esm/rag/loaders/load-pdf.d.mts +38 -0
  398. package/esm/rag/loaders/load-pdf.d.mts.map +1 -0
  399. package/esm/rag/loaders/load-pdf.mjs +150 -0
  400. package/esm/rag/loaders/load-pdf.mjs.map +1 -0
  401. package/esm/rag/loaders/load-text.d.mts +47 -0
  402. package/esm/rag/loaders/load-text.d.mts.map +1 -0
  403. package/esm/rag/loaders/load-text.mjs +60 -0
  404. package/esm/rag/loaders/load-text.mjs.map +1 -0
  405. package/esm/rag/loaders/load-web.d.mts +42 -0
  406. package/esm/rag/loaders/load-web.d.mts.map +1 -0
  407. package/esm/rag/loaders/load-web.mjs +89 -0
  408. package/esm/rag/loaders/load-web.mjs.map +1 -0
  409. package/esm/rag/loaders/loader.type.d.mts +89 -0
  410. package/esm/rag/loaders/loader.type.d.mts.map +1 -0
  411. package/esm/rag/rag.d.mts +38 -0
  412. package/esm/rag/rag.d.mts.map +1 -0
  413. package/esm/rag/rag.mjs +126 -0
  414. package/esm/rag/rag.mjs.map +1 -0
  415. package/esm/rag/rerank/keyword-reranker.d.mts +32 -0
  416. package/esm/rag/rerank/keyword-reranker.d.mts.map +1 -0
  417. package/esm/rag/rerank/keyword-reranker.mjs +58 -0
  418. package/esm/rag/rerank/keyword-reranker.mjs.map +1 -0
  419. package/esm/rag/rerank/llm-reranker.d.mts +36 -0
  420. package/esm/rag/rerank/llm-reranker.d.mts.map +1 -0
  421. package/esm/rag/rerank/llm-reranker.mjs +85 -0
  422. package/esm/rag/rerank/llm-reranker.mjs.map +1 -0
  423. package/esm/rag/rerank/reranker.contract.d.mts +28 -0
  424. package/esm/rag/rerank/reranker.contract.d.mts.map +1 -0
  425. package/esm/rag/retrieve.mjs +68 -0
  426. package/esm/rag/retrieve.mjs.map +1 -0
  427. package/esm/rag/store/cache-vector-store.d.mts +27 -0
  428. package/esm/rag/store/cache-vector-store.d.mts.map +1 -0
  429. package/esm/rag/store/cache-vector-store.mjs +48 -0
  430. package/esm/rag/store/cache-vector-store.mjs.map +1 -0
  431. package/esm/rag/store/pg-vector-store.d.mts +139 -0
  432. package/esm/rag/store/pg-vector-store.d.mts.map +1 -0
  433. package/esm/rag/store/pg-vector-store.mjs +328 -0
  434. package/esm/rag/store/pg-vector-store.mjs.map +1 -0
  435. package/esm/rag/store/vector-store.contract.d.mts +38 -0
  436. package/esm/rag/store/vector-store.contract.d.mts.map +1 -0
  437. package/esm/rag/transforms/multi-query.d.mts +27 -0
  438. package/esm/rag/transforms/multi-query.d.mts.map +1 -0
  439. package/esm/rag/transforms/multi-query.mjs +41 -0
  440. package/esm/rag/transforms/multi-query.mjs.map +1 -0
  441. package/esm/security/index.mjs +5 -0
  442. package/esm/security/outbound-policy.d.mts +46 -0
  443. package/esm/security/outbound-policy.d.mts.map +1 -0
  444. package/esm/security/outbound-policy.mjs +187 -0
  445. package/esm/security/outbound-policy.mjs.map +1 -0
  446. package/esm/security/outbound-policy.type.d.mts +74 -0
  447. package/esm/security/outbound-policy.type.d.mts.map +1 -0
  448. package/esm/security/private-ip.d.mts +15 -0
  449. package/esm/security/private-ip.d.mts.map +1 -0
  450. package/esm/security/private-ip.mjs +48 -0
  451. package/esm/security/private-ip.mjs.map +1 -0
  452. package/esm/security/redact.d.mts +59 -0
  453. package/esm/security/redact.d.mts.map +1 -0
  454. package/esm/security/redact.mjs +122 -0
  455. package/esm/security/redact.mjs.map +1 -0
  456. package/esm/serve/serve.d.mts +50 -0
  457. package/esm/serve/serve.d.mts.map +1 -0
  458. package/esm/serve/serve.mjs +90 -0
  459. package/esm/serve/serve.mjs.map +1 -0
  460. package/esm/serve/sse.d.mts +20 -0
  461. package/esm/serve/sse.d.mts.map +1 -0
  462. package/esm/serve/sse.mjs +25 -0
  463. package/esm/serve/sse.mjs.map +1 -0
  464. package/esm/serve/stream-to-sse.d.mts +29 -0
  465. package/esm/serve/stream-to-sse.d.mts.map +1 -0
  466. package/esm/serve/stream-to-sse.mjs +37 -0
  467. package/esm/serve/stream-to-sse.mjs.map +1 -0
  468. package/esm/skills/catalog.d.mts +49 -0
  469. package/esm/skills/catalog.d.mts.map +1 -0
  470. package/esm/skills/catalog.mjs +140 -0
  471. package/esm/skills/catalog.mjs.map +1 -0
  472. package/esm/skills/contracts/skill-record.type.d.mts +37 -0
  473. package/esm/skills/contracts/skill-record.type.d.mts.map +1 -0
  474. package/esm/skills/contracts/skills-config.type.d.mts +108 -0
  475. package/esm/skills/contracts/skills-config.type.d.mts.map +1 -0
  476. package/esm/skills/contracts/skills-store.contract.d.mts +28 -0
  477. package/esm/skills/contracts/skills-store.contract.d.mts.map +1 -0
  478. package/esm/skills/contracts/skills.contract.d.mts +43 -0
  479. package/esm/skills/contracts/skills.contract.d.mts.map +1 -0
  480. package/esm/skills/index.d.mts +16 -0
  481. package/esm/skills/index.mjs +14 -0
  482. package/esm/skills/load-skill-tool.d.mts +38 -0
  483. package/esm/skills/load-skill-tool.d.mts.map +1 -0
  484. package/esm/skills/load-skill-tool.mjs +65 -0
  485. package/esm/skills/load-skill-tool.mjs.map +1 -0
  486. package/esm/skills/review-gate.d.mts +33 -0
  487. package/esm/skills/review-gate.d.mts.map +1 -0
  488. package/esm/skills/review-gate.mjs +60 -0
  489. package/esm/skills/review-gate.mjs.map +1 -0
  490. package/esm/skills/save-skill-tool.d.mts +39 -0
  491. package/esm/skills/save-skill-tool.d.mts.map +1 -0
  492. package/esm/skills/save-skill-tool.mjs +65 -0
  493. package/esm/skills/save-skill-tool.mjs.map +1 -0
  494. package/esm/skills/skills.d.mts +33 -0
  495. package/esm/skills/skills.d.mts.map +1 -0
  496. package/esm/skills/skills.mjs +109 -0
  497. package/esm/skills/skills.mjs.map +1 -0
  498. package/esm/skills/sources/directory-source.d.mts +19 -0
  499. package/esm/skills/sources/directory-source.d.mts.map +1 -0
  500. package/esm/skills/sources/directory-source.mjs +108 -0
  501. package/esm/skills/sources/directory-source.mjs.map +1 -0
  502. package/esm/skills/sources/index.d.mts +18 -0
  503. package/esm/skills/sources/index.d.mts.map +1 -0
  504. package/esm/skills/sources/index.mjs +27 -0
  505. package/esm/skills/sources/index.mjs.map +1 -0
  506. package/esm/skills/sources/parse-frontmatter.d.mts +27 -0
  507. package/esm/skills/sources/parse-frontmatter.d.mts.map +1 -0
  508. package/esm/skills/sources/parse-frontmatter.mjs +46 -0
  509. package/esm/skills/sources/parse-frontmatter.mjs.map +1 -0
  510. package/esm/skills/sources/store-source.d.mts +14 -0
  511. package/esm/skills/sources/store-source.d.mts.map +1 -0
  512. package/esm/skills/sources/store-source.mjs +15 -0
  513. package/esm/skills/sources/store-source.mjs.map +1 -0
  514. package/esm/skills/sources/url-source.d.mts +29 -0
  515. package/esm/skills/sources/url-source.d.mts.map +1 -0
  516. package/esm/skills/sources/url-source.mjs +117 -0
  517. package/esm/skills/sources/url-source.mjs.map +1 -0
  518. package/esm/skills/store/mock-skills-store.d.mts +57 -0
  519. package/esm/skills/store/mock-skills-store.d.mts.map +1 -0
  520. package/esm/skills/store/mock-skills-store.mjs +100 -0
  521. package/esm/skills/store/mock-skills-store.mjs.map +1 -0
  522. package/esm/skills/store/procedural-skill-store.d.mts +30 -0
  523. package/esm/skills/store/procedural-skill-store.d.mts.map +1 -0
  524. package/esm/skills/store/procedural-skill-store.mjs +125 -0
  525. package/esm/skills/store/procedural-skill-store.mjs.map +1 -0
  526. package/esm/speech/index.mjs +3 -0
  527. package/esm/speech/speech.d.mts +65 -0
  528. package/esm/speech/speech.d.mts.map +1 -0
  529. package/esm/speech/speech.mjs +123 -0
  530. package/esm/speech/speech.mjs.map +1 -0
  531. package/esm/supervisor/as-tool.mjs +2 -2
  532. package/esm/supervisor/as-tool.mjs.map +1 -1
  533. package/esm/supervisor/entries.mjs +2 -2
  534. package/esm/supervisor/entries.mjs.map +1 -1
  535. package/esm/supervisor/execution.d.mts.map +1 -1
  536. package/esm/supervisor/execution.mjs +31 -28
  537. package/esm/supervisor/execution.mjs.map +1 -1
  538. package/esm/supervisor/supervisor.d.mts.map +1 -1
  539. package/esm/supervisor/supervisor.mjs +8 -3
  540. package/esm/supervisor/supervisor.mjs.map +1 -1
  541. package/esm/system-prompt/index.d.mts +4 -0
  542. package/esm/system-prompt/system-prompt.d.mts +68 -4
  543. package/esm/system-prompt/system-prompt.d.mts.map +1 -1
  544. package/esm/system-prompt/system-prompt.mjs +89 -5
  545. package/esm/system-prompt/system-prompt.mjs.map +1 -1
  546. package/esm/team/gates.mjs +48 -0
  547. package/esm/team/gates.mjs.map +1 -0
  548. package/esm/team/index.d.mts +1 -0
  549. package/esm/team/index.mjs +3 -0
  550. package/esm/team/team.d.mts +42 -0
  551. package/esm/team/team.d.mts.map +1 -0
  552. package/esm/team/team.mjs +94 -0
  553. package/esm/team/team.mjs.map +1 -0
  554. package/esm/tool/executable-as-tool.d.mts.map +1 -1
  555. package/esm/tool/executable-as-tool.mjs +2 -2
  556. package/esm/tool/executable-as-tool.mjs.map +1 -1
  557. package/esm/tool/tool.d.mts.map +1 -1
  558. package/esm/tool/tool.mjs +2 -2
  559. package/esm/tool/tool.mjs.map +1 -1
  560. package/esm/transcribe/audio-input.d.mts +47 -0
  561. package/esm/transcribe/audio-input.d.mts.map +1 -0
  562. package/esm/transcribe/audio-input.mjs +84 -0
  563. package/esm/transcribe/audio-input.mjs.map +1 -0
  564. package/esm/transcribe/index.mjs +4 -0
  565. package/esm/transcribe/transcribe.d.mts +64 -0
  566. package/esm/transcribe/transcribe.d.mts.map +1 -0
  567. package/esm/transcribe/transcribe.mjs +128 -0
  568. package/esm/transcribe/transcribe.mjs.map +1 -0
  569. package/esm/utils/compute-cost.d.mts +17 -1
  570. package/esm/utils/compute-cost.d.mts.map +1 -1
  571. package/esm/utils/compute-cost.mjs +26 -1
  572. package/esm/utils/compute-cost.mjs.map +1 -1
  573. package/esm/utils/extract-json-lenient.d.mts +42 -0
  574. package/esm/utils/extract-json-lenient.d.mts.map +1 -0
  575. package/esm/utils/extract-json-lenient.mjs +97 -0
  576. package/esm/utils/extract-json-lenient.mjs.map +1 -0
  577. package/esm/utils/index.d.mts +4 -2
  578. package/esm/utils/index.mjs +3 -1
  579. package/esm/utils/json-schema.d.mts +1 -1
  580. package/esm/utils/prepare-attachment-part.d.mts +10 -1
  581. package/esm/utils/prepare-attachment-part.d.mts.map +1 -1
  582. package/esm/utils/prepare-attachment-part.mjs +103 -11
  583. package/esm/utils/prepare-attachment-part.mjs.map +1 -1
  584. package/esm/utils/resolve-attachment.d.mts +4 -3
  585. package/esm/utils/resolve-attachment.d.mts.map +1 -1
  586. package/esm/utils/resolve-attachment.mjs +4 -3
  587. package/esm/utils/resolve-attachment.mjs.map +1 -1
  588. package/esm/utils/run-context.d.mts +94 -0
  589. package/esm/utils/run-context.d.mts.map +1 -0
  590. package/esm/utils/run-context.mjs +98 -0
  591. package/esm/utils/run-context.mjs.map +1 -0
  592. package/esm/vcr/cassette-io.mjs +57 -0
  593. package/esm/vcr/cassette-io.mjs.map +1 -0
  594. package/esm/vcr/errors.d.mts +42 -0
  595. package/esm/vcr/errors.d.mts.map +1 -0
  596. package/esm/vcr/errors.mjs +37 -0
  597. package/esm/vcr/errors.mjs.map +1 -0
  598. package/esm/vcr/hash-request.d.mts +28 -0
  599. package/esm/vcr/hash-request.d.mts.map +1 -0
  600. package/esm/vcr/hash-request.mjs +118 -0
  601. package/esm/vcr/hash-request.mjs.map +1 -0
  602. package/esm/vcr/index.d.mts +4 -0
  603. package/esm/vcr/index.mjs +5 -0
  604. package/esm/vcr/vcr.d.mts +32 -0
  605. package/esm/vcr/vcr.d.mts.map +1 -0
  606. package/esm/vcr/vcr.mjs +248 -0
  607. package/esm/vcr/vcr.mjs.map +1 -0
  608. package/esm/vcr/vcr.type.d.mts +118 -0
  609. package/esm/vcr/vcr.type.d.mts.map +1 -0
  610. package/esm/workflow/as-tool.mjs +2 -2
  611. package/esm/workflow/as-tool.mjs.map +1 -1
  612. package/esm/workflow/engine.mjs +1 -0
  613. package/esm/workflow/engine.mjs.map +1 -1
  614. package/esm/workflow/step-runner.mjs +19 -20
  615. package/esm/workflow/step-runner.mjs.map +1 -1
  616. package/esm/workflow/workflow.d.mts.map +1 -1
  617. package/esm/workflow/workflow.mjs +8 -3
  618. package/esm/workflow/workflow.mjs.map +1 -1
  619. package/llms-full.txt +2572 -204
  620. package/llms.txt +21 -4
  621. package/package.json +7 -3
  622. package/skills/README.md +44 -4
  623. package/skills/ai-dx-helpers/SKILL.md +2 -2
  624. package/skills/approve-tool-calls/SKILL.md +134 -0
  625. package/skills/attach-ai-middleware/SKILL.md +1 -1
  626. package/skills/detect-and-redact-pii/SKILL.md +104 -0
  627. package/skills/durable-agent-runs/SKILL.md +135 -0
  628. package/skills/durable-resume/SKILL.md +128 -0
  629. package/skills/escalate-block-to-human/SKILL.md +85 -0
  630. package/skills/eval-datasets-and-ci/SKILL.md +117 -0
  631. package/skills/generate-images/SKILL.md +138 -0
  632. package/skills/generate-speech/SKILL.md +139 -0
  633. package/skills/guard-input-output/SKILL.md +117 -0
  634. package/skills/manage-prompts/SKILL.md +186 -0
  635. package/skills/observe-ai-flows/SKILL.md +94 -0
  636. package/skills/rag-loaders-and-stores/SKILL.md +164 -0
  637. package/skills/record-replay-llm/SKILL.md +92 -0
  638. package/skills/run-ai-agent/SKILL.md +26 -1
  639. package/skills/run-ai-rag/SKILL.md +139 -0
  640. package/skills/run-ai-team/SKILL.md +107 -0
  641. package/skills/run-orchestrator/SKILL.md +2 -0
  642. package/skills/run-planner/SKILL.md +73 -8
  643. package/skills/run-supervisor/SKILL.md +20 -1
  644. package/skills/transcribe-audio/SKILL.md +157 -0
  645. package/skills/use-runtime-skills/SKILL.md +106 -0
  646. package/skills/write-system-prompt/SKILL.md +30 -1
  647. package/cjs/index.cjs.map +0 -1
  648. package/esm/contracts/result/index.d.mts +0 -15
@@ -5,9 +5,14 @@ import { PlannerPlanInvalidError } from "../errors/planner-plan-invalid-error.mj
5
5
  import { SchemaValidationError } from "../errors/schema-validation-error.mjs";
6
6
  import { accumulateCost } from "../utils/compute-cost.mjs";
7
7
  import { generateRunId } from "../utils/generate-run-id.mjs";
8
+ import { captureChildReport, withoutRunFrame } from "../utils/run-context.mjs";
8
9
  import { REPORT_SCHEMA_VERSION } from "../contracts/result/base-report.type.mjs";
9
10
  import { stampReportLineage } from "../utils/stamp-report-lineage.mjs";
11
+ import { notifyObservers } from "../observe/resolve-observers.mjs";
12
+ import { buildDag, readyNodes, sinkNodes } from "./dag-scheduler.mjs";
10
13
  import { planSchema } from "./plan-schema.mjs";
14
+ import { deletePlannerSnapshot, persistPlannerSnapshot } from "./snapshot.mjs";
15
+ import { log } from "@warlock.js/logger";
11
16
 
12
17
  //#region ../@warlock.js/ai/src/planner/planner-run.ts
13
18
  /**
@@ -40,7 +45,18 @@ var PlannerRun = class {
40
45
  };
41
46
  this.children = [];
42
47
  this.executedSteps = [];
43
- this.runId = args.options?.runId ?? generateRunId("planner");
48
+ this.awaitingApproval = false;
49
+ this.replanCount = 0;
50
+ this.dagResumeConsumed = false;
51
+ this.runId = args.resumeFrom?.runId ?? args.options?.runId ?? generateRunId("planner");
52
+ if (args.resumeFrom) {
53
+ this.plan = args.resumeFrom.plan;
54
+ this.executedSteps.push(...args.resumeFrom.executedSteps);
55
+ this.children.push(...args.resumeFrom.children);
56
+ this.mergeUsage(this.usage, args.resumeFrom.usage);
57
+ this.replanCount = args.resumeFrom.replanCount;
58
+ this.startedAt = args.resumeFrom.startedAt;
59
+ }
44
60
  }
45
61
  /**
46
62
  * Run the planner end-to-end. Never throws on runtime failure —
@@ -49,19 +65,57 @@ var PlannerRun = class {
49
65
  * `report.status`.
50
66
  */
51
67
  async run() {
68
+ const result = await this.runPlan();
69
+ await notifyObservers(this.args.config.observe, result.report);
70
+ captureChildReport(result.report);
71
+ return result;
72
+ }
73
+ /**
74
+ * Drive the planner lifecycle and return the built result WITHOUT
75
+ * routing it — `run()` owns observer routing + auto-nesting so the
76
+ * unified tree is emitted exactly once.
77
+ */
78
+ async runPlan() {
79
+ if (this.args.resumeFrom && this.args.resumeFrom.status === "completed") {
80
+ this.rebuildResumedTerminal("completed");
81
+ return this.buildResult();
82
+ }
52
83
  try {
53
84
  if (this.isAborted()) {
54
85
  this.markCancelled();
86
+ await this.checkpoint(this.resolveSnapshotStatus());
87
+ return this.buildResult();
88
+ }
89
+ const plan = this.args.resumeFrom ? this.plan : this.args.options?.approvedPlan ?? await this.generatePlan();
90
+ if (this.error || !plan) {
91
+ await this.checkpoint(this.resolveSnapshotStatus());
55
92
  return this.buildResult();
56
93
  }
57
- const plan = await this.generatePlan();
58
- if (this.error || !plan) return this.buildResult();
94
+ if (!this.args.resumeFrom) {
95
+ this.assertPlanValid(plan);
96
+ if (this.error) {
97
+ await this.checkpoint(this.resolveSnapshotStatus());
98
+ return this.buildResult();
99
+ }
100
+ }
59
101
  this.plan = plan;
102
+ if (!this.args.resumeFrom && this.args.options?.mode === "plan-only" && !this.args.options?.approvedPlan) {
103
+ this.awaitingApproval = true;
104
+ return this.buildResult();
105
+ }
60
106
  await this.executePlan(plan);
61
107
  await this.finalizeOutput();
62
108
  } catch (caught) {
63
109
  this.error = this.toAIError(caught);
64
110
  }
111
+ await this.checkpoint(this.resolveSnapshotStatus());
112
+ if (!this.error && this.args.config.durable?.deleteOnComplete) {
113
+ const outcome = await deletePlannerSnapshot({
114
+ durable: this.args.config.durable,
115
+ runId: this.runId
116
+ });
117
+ if (!outcome.ok) this.logDurableFailure("snapshot.delete.failed", outcome.error);
118
+ }
65
119
  return this.buildResult();
66
120
  }
67
121
  /**
@@ -70,15 +124,19 @@ var PlannerRun = class {
70
124
  * agent's per-call `output`, so the model is steered to reference only
71
125
  * real capabilities. The planning trip's usage + report roll into the
72
126
  * planner's totals regardless of outcome.
127
+ *
128
+ * `feedback` is set only on a RE-plan: the regenerated request is
129
+ * seeded with the executed-step digest plus the caller's feedback so
130
+ * the planner revises the remaining work rather than starting cold.
73
131
  */
74
- async generatePlan() {
132
+ async generatePlan(feedback) {
75
133
  const schema = planSchema([...this.args.capabilities.keys()], this.args.maxSteps);
76
- const result = await this.args.planningAgent.execute(this.buildPlanPrompt(), {
134
+ const result = await withoutRunFrame(() => this.args.planningAgent.execute(this.buildPlanPrompt(feedback), {
77
135
  output: schema,
78
136
  placeholders: this.args.options?.placeholders,
79
137
  signal: this.args.options?.signal,
80
138
  sessionId: this.args.options?.sessionId
81
- });
139
+ }));
82
140
  this.absorb(result.usage, result.report);
83
141
  if (result.error) {
84
142
  this.error = result.error instanceof SchemaValidationError ? new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, {
@@ -92,43 +150,179 @@ var PlannerRun = class {
92
150
  this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
93
151
  return;
94
152
  }
95
- const unknownStep = plan.steps.find((step) => !this.args.capabilities.has(step.capability));
96
- if (unknownStep) {
97
- this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): plan references unknown capability "${unknownStep.capability}"`, { context: {
98
- runId: this.runId,
99
- capability: unknownStep.capability
100
- } });
153
+ this.assertPlanValid(plan);
154
+ if (this.error) return;
155
+ return plan;
156
+ }
157
+ /**
158
+ * Shared plan-validity guard — used both for a freshly generated plan
159
+ * and for a caller-supplied `approvedPlan`. Sets `this.error` to a
160
+ * typed {@link PlannerPlanInvalidError} when the plan is empty or names
161
+ * an unknown capability; a stale `approvedPlan` thus fails the same way
162
+ * a hallucinated capability does, never silently mis-dispatching.
163
+ */
164
+ assertPlanValid(plan) {
165
+ if (!Array.isArray(plan.steps) || plan.steps.length === 0) {
166
+ this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
101
167
  return;
102
168
  }
103
- return plan;
169
+ const unknownStep = plan.steps.find((step) => !this.args.capabilities.has(step.capability));
170
+ if (unknownStep) this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): plan references unknown capability "${unknownStep.capability}"`, { context: {
171
+ runId: this.runId,
172
+ capability: unknownStep.capability
173
+ } });
104
174
  }
105
175
  /**
106
- * Phase 2 — execute the plan's steps strictly in order, threading each
107
- * completed step's output into the next step's input context. Stops at
108
- * the first step failure (its `error` becomes the run error) or when
109
- * the abort signal fires between steps. Steps beyond `maxSteps` are
110
- * recorded as `skipped` without running.
176
+ * Phase 2 — execute the plan. Branches on `config.dag`: the default is
177
+ * the strict array-order sequential loop (byte-for-byte today's
178
+ * behavior when neither `onStep` nor `replan` is configured); `dag:
179
+ * true` schedules independent `dependsOn` branches in parallel.
111
180
  */
112
181
  async executePlan(plan) {
182
+ if (this.args.config.dag) return this.executeDag(plan);
183
+ return this.executeSequential(plan);
184
+ }
185
+ /**
186
+ * Sequential executor — the original strict array-order loop, threading
187
+ * each completed step's output into the next step's input context.
188
+ * Stops at the first step failure or when the abort signal fires
189
+ * between steps; steps beyond `maxSteps` are recorded `skipped`.
190
+ *
191
+ * **Additive hooks (inert by default).** After each step settles it
192
+ * fires the `onStep` directive hook; an `abort` directive stops the run
193
+ * like a failure, and a `replan` directive (or, when `config.replan` is
194
+ * set, an unhandled failure) regenerates the REMAINING plan instead of
195
+ * aborting. With no `onStep` and no `replan`, the behavior is identical
196
+ * to before.
197
+ */
198
+ async executeSequential(plan) {
113
199
  const previousOutputs = [];
114
- for (let index = 0; index < plan.steps.length; index++) {
115
- const step = plan.steps[index];
200
+ let steps = plan.steps;
201
+ let index = 0;
202
+ if (this.args.resumeFrom) index = this.rehydrateSequentialState(steps, previousOutputs);
203
+ while (index < steps.length) {
204
+ const step = steps[index];
116
205
  if (index >= this.args.maxSteps) {
117
206
  this.recordSkipped(index, step);
207
+ index++;
118
208
  continue;
119
209
  }
120
210
  if (this.isAborted()) {
121
211
  this.markCancelled();
122
212
  this.recordSkipped(index, step);
213
+ index++;
214
+ continue;
215
+ }
216
+ const completed = await this.executeStep(index, step, previousOutputs);
217
+ const snapshot = this.snapshotFor(index);
218
+ const directive = snapshot ? await this.resolveDirective(snapshot, plan, completed) : void 0;
219
+ if (directive?.type === "replan") {
220
+ const remaining = await this.regeneratePlan(directive.feedback);
221
+ if (this.error || !remaining) {
222
+ this.skipRest(steps, index + 1);
223
+ return;
224
+ }
225
+ steps = remaining.steps;
226
+ index = 0;
227
+ previousOutputs.length = 0;
228
+ previousOutputs.push(...this.executedDigest());
123
229
  continue;
124
230
  }
125
- if (!await this.executeStep(index, step, previousOutputs)) {
126
- for (let rest = index + 1; rest < plan.steps.length; rest++) this.recordSkipped(rest, plan.steps[rest]);
231
+ if (directive?.type === "abort") {
232
+ this.skipRest(steps, index + 1);
127
233
  return;
128
234
  }
235
+ index++;
129
236
  }
130
237
  }
131
238
  /**
239
+ * DAG executor — schedule independent `dependsOn` branches in parallel.
240
+ *
241
+ * Builds the DAG (cycle / unknown-id → `PlannerPlanInvalidError`),
242
+ * then repeatedly computes the ready set (steps whose deps all
243
+ * completed), dispatches up to `maxConcurrency` of them with
244
+ * `Promise.all`, and feeds each step ONLY its dependencies' outputs. A
245
+ * failed step blocks just its descendants (recorded `skipped`);
246
+ * independent branches still settle. With an `output` schema set, the
247
+ * final `data` is the topological SINK's output (multiple sinks → a
248
+ * convergence error).
249
+ */
250
+ async executeDag(plan) {
251
+ const dag = buildDag(plan.steps, this.args.config.name);
252
+ const maxConcurrency = Math.max(1, this.args.config.maxConcurrency ?? 4);
253
+ const completed = /* @__PURE__ */ new Set();
254
+ const done = /* @__PURE__ */ new Set();
255
+ const outputs = /* @__PURE__ */ new Map();
256
+ const rawOutputs = /* @__PURE__ */ new Map();
257
+ let executedCount = 0;
258
+ if (this.args.resumeFrom && !this.dagResumeConsumed) {
259
+ this.dagResumeConsumed = true;
260
+ executedCount = this.rehydrateDagState(dag, completed, done, outputs, rawOutputs);
261
+ }
262
+ while (done.size < dag.nodes.length) {
263
+ if (this.isAborted()) {
264
+ this.markCancelled();
265
+ this.skipDagRest(dag, done);
266
+ return;
267
+ }
268
+ const ready = readyNodes(dag, completed, done);
269
+ if (ready.length === 0) {
270
+ this.skipDagRest(dag, done);
271
+ return;
272
+ }
273
+ const batch = ready.slice(0, maxConcurrency);
274
+ const settled = await Promise.all(batch.map(async (node) => {
275
+ if (executedCount >= this.args.maxSteps) {
276
+ this.recordSkipped(node.index, node.step);
277
+ return {
278
+ node,
279
+ ran: false,
280
+ completed: false
281
+ };
282
+ }
283
+ executedCount++;
284
+ const previousOutputs = node.dependencies.map((dependency) => outputs.get(dependency));
285
+ const stepCompleted = await this.executeStep(node.index, node.step, previousOutputs);
286
+ if (stepCompleted) {
287
+ const rawOutput = this.snapshotFor(node.index)?.output;
288
+ rawOutputs.set(node.id, rawOutput);
289
+ outputs.set(node.id, this.stringifyOutput(node.step.capability, rawOutput));
290
+ }
291
+ return {
292
+ node,
293
+ ran: true,
294
+ completed: stepCompleted
295
+ };
296
+ }));
297
+ for (const entry of settled) {
298
+ done.add(entry.node.id);
299
+ if (entry.completed) completed.add(entry.node.id);
300
+ }
301
+ let replanFeedback;
302
+ let shouldAbort = false;
303
+ for (const entry of settled) {
304
+ if (!entry.ran) continue;
305
+ const snapshot = this.snapshotFor(entry.node.index);
306
+ const directive = snapshot ? await this.resolveDirective(snapshot, plan, entry.completed) : void 0;
307
+ if (directive?.type === "replan") replanFeedback = directive.feedback;
308
+ else if (directive?.type === "abort") shouldAbort = true;
309
+ }
310
+ if (shouldAbort) {
311
+ this.skipDagRest(dag, done);
312
+ return;
313
+ }
314
+ if (replanFeedback !== void 0) {
315
+ const remaining = await this.regeneratePlan(replanFeedback);
316
+ if (this.error || !remaining) {
317
+ this.skipDagRest(dag, done);
318
+ return;
319
+ }
320
+ return this.executeDag(remaining);
321
+ }
322
+ }
323
+ this.finalizeDagOutput(dag, completed, rawOutputs);
324
+ }
325
+ /**
132
326
  * Dispatch one plan step through its capability's `executable.execute()`
133
327
  * and fold the outcome into the accumulators. Returns `true` when the
134
328
  * step completed, `false` when it failed (setting the run error).
@@ -138,10 +332,10 @@ var PlannerRun = class {
138
332
  const stepStart = performance.now();
139
333
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
140
334
  const input = this.composeStepInput(step, previousOutputs);
141
- const result = await capability.executable.execute(input, {
335
+ const result = await withoutRunFrame(() => capability.executable.execute(input, {
142
336
  signal: this.args.options?.signal,
143
337
  sessionId: this.args.options?.sessionId
144
- });
338
+ }));
145
339
  const childReport = "report" in result ? result.report : void 0;
146
340
  this.absorb(result.usage, childReport);
147
341
  const output = this.extractOutput(result);
@@ -158,6 +352,7 @@ var PlannerRun = class {
158
352
  usage: result.usage,
159
353
  childReport
160
354
  });
355
+ await this.checkpoint("running");
161
356
  if (failed) {
162
357
  this.error = result.error;
163
358
  return false;
@@ -167,6 +362,104 @@ var PlannerRun = class {
167
362
  return true;
168
363
  }
169
364
  /**
365
+ * Resolve the steering directive for a just-settled step, shared by the
366
+ * sequential and DAG executors. Fires the user's `onStep` hook, then
367
+ * normalizes the result against the `replan` budget:
368
+ *
369
+ * - explicit `replan` directive — honored only when `config.replan` is
370
+ * set and the budget remains; otherwise downgraded to `continue`.
371
+ * - explicit `abort` — honored.
372
+ * - failed step with no overriding directive — auto-`replan` when
373
+ * `config.replan` is set and the budget remains (feedback = the step
374
+ * error message), else `abort` (today's abort-on-first-failure).
375
+ *
376
+ * Returns `undefined` when the run should simply continue. A returned
377
+ * `replan` directive has ALREADY consumed one unit of the replan budget.
378
+ */
379
+ async resolveDirective(snapshot, plan, completed) {
380
+ const hook = this.args.options?.onStep;
381
+ const userDirective = hook ? await hook(snapshot, plan) : void 0;
382
+ if (userDirective?.type === "replan") {
383
+ if (this.canReplan()) {
384
+ this.replanCount++;
385
+ return userDirective;
386
+ }
387
+ } else if (userDirective?.type === "abort") return { type: "abort" };
388
+ else if (userDirective?.type === "continue") return;
389
+ if (!completed) {
390
+ if (this.canReplan()) {
391
+ this.replanCount++;
392
+ return {
393
+ type: "replan",
394
+ feedback: snapshot.error?.message ?? "step failed"
395
+ };
396
+ }
397
+ return { type: "abort" };
398
+ }
399
+ }
400
+ /** Whether a re-plan is configured and the budget has room. */
401
+ canReplan() {
402
+ const replan = this.args.config.replan;
403
+ return replan !== void 0 && this.replanCount < replan.maxReplans;
404
+ }
405
+ /**
406
+ * Re-ask the planning agent for a plan over the REMAINING work — a
407
+ * second `generatePlan()` seeded with the executed-step digest plus the
408
+ * caller's feedback. Reuses the exact `generatePlan` plumbing (same
409
+ * schema, same `PlannerPlanInvalidError` handling), so a regenerated
410
+ * plan that is empty or names an unknown capability fails identically.
411
+ * The failed step's error is cleared so the regenerated plan runs
412
+ * cleanly; a fresh failure (or exhausted budget) re-sets it.
413
+ */
414
+ async regeneratePlan(feedback) {
415
+ this.error = void 0;
416
+ return this.generatePlan(feedback);
417
+ }
418
+ /**
419
+ * The executed-so-far digest — one context line per completed step, in
420
+ * execution order. Seeds the regenerated plan's first step so it builds
421
+ * on what already ran.
422
+ */
423
+ executedDigest() {
424
+ return this.executedSteps.filter((snapshot) => snapshot.status === "completed").map((snapshot) => this.stringifyOutput(snapshot.step.capability, snapshot.output));
425
+ }
426
+ /** The last-pushed snapshot for a given step index, if any. */
427
+ snapshotFor(index) {
428
+ for (let position = this.executedSteps.length - 1; position >= 0; position--) {
429
+ const snapshot = this.executedSteps[position];
430
+ if (snapshot.index === index) return snapshot;
431
+ }
432
+ }
433
+ /** Record every step from `from` onward (in a flat array plan) as skipped. */
434
+ skipRest(steps, from) {
435
+ for (let rest = from; rest < steps.length; rest++) this.recordSkipped(rest, steps[rest]);
436
+ }
437
+ /** Record every not-yet-`done` DAG node as skipped, in plan order. */
438
+ skipDagRest(dag, done) {
439
+ for (const node of dag.nodes) if (!done.has(node.id)) this.recordSkipped(node.index, node.step);
440
+ }
441
+ /**
442
+ * Set `this.data` from the DAG's topological sink for a configured
443
+ * `output` schema. "Last completed step" is meaningless under
444
+ * parallelism, so the sink (the step nothing depends on) is the
445
+ * unambiguous final output. Multiple sinks while an `output` schema is
446
+ * set is a convergence error — a typed `PlannerPlanInvalidError`.
447
+ */
448
+ finalizeDagOutput(dag, completed, rawOutputs) {
449
+ if (!(this.args.options?.output ?? this.args.config.output) || this.error) return;
450
+ const sinks = sinkNodes(dag).filter((node) => completed.has(node.id));
451
+ if (sinks.length > 1) {
452
+ this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): DAG has multiple sinks but an \`output\` schema is set — the plan must converge to a single final step`, { context: {
453
+ runId: this.runId,
454
+ sinks: sinks.map((node) => node.id)
455
+ } });
456
+ this.data = void 0;
457
+ return;
458
+ }
459
+ const sink = sinks[0];
460
+ this.data = sink ? rawOutputs.get(sink.id) : void 0;
461
+ }
462
+ /**
170
463
  * Phase 3 — when an `output` schema is configured (factory or per-call
171
464
  * override), validate the final completed step's output into typed
172
465
  * `result.data`. A validation failure replaces the run error and flips
@@ -205,6 +498,7 @@ var PlannerRun = class {
205
498
  version: this.args.config.version,
206
499
  type: "planner",
207
500
  status,
501
+ ...this.error ? { error: this.error } : {},
208
502
  startedAt: this.startedAt,
209
503
  endedAt: (/* @__PURE__ */ new Date()).toISOString(),
210
504
  duration: performance.now() - this.startPerf,
@@ -220,27 +514,42 @@ var PlannerRun = class {
220
514
  rootRunId: this.runId,
221
515
  sessionId: this.args.options?.sessionId
222
516
  });
223
- return {
517
+ const result = {
224
518
  type: "planner",
225
519
  data: this.error ? void 0 : this.data,
226
520
  error: this.error,
227
521
  usage: this.usage,
228
522
  report
229
523
  };
524
+ if (this.awaitingApproval) result.plan = this.plan;
525
+ return result;
230
526
  }
231
527
  /**
232
- * Resolve the terminal status from the accumulated outcome. Cancelled
233
- * wins over failed (an abort that also produced a step error still
234
- * reads as cancelled); failed wins over completed.
528
+ * Resolve the terminal status from the accumulated outcome.
529
+ * `awaiting-approval` (plan-only short-circuit) wins over everything
530
+ * nothing executed, so neither cancellation nor error applies.
531
+ * Otherwise cancelled wins over failed (an abort that also produced a
532
+ * step error still reads as cancelled); failed wins over completed.
235
533
  */
236
534
  resolveStatus() {
535
+ if (this.awaitingApproval) return "awaiting-approval";
237
536
  if (this.cancelledAt !== void 0) return "cancelled";
238
537
  if (this.error) return "failed";
239
538
  return "completed";
240
539
  }
241
- /** Build the prompt handed to the planning agent — the user's goal. */
242
- buildPlanPrompt() {
243
- return this.args.goal;
540
+ /**
541
+ * Build the prompt handed to the planning agent. On the first pass this
542
+ * is just the user's goal (byte-for-byte unchanged). On a RE-plan it
543
+ * prepends the executed-step digest and the steering feedback so the
544
+ * planner revises the remaining work.
545
+ */
546
+ buildPlanPrompt(feedback) {
547
+ if (feedback === void 0) return this.args.goal;
548
+ const digest = this.executedDigest();
549
+ const sections = [`Goal: ${this.args.goal}`, ""];
550
+ if (digest.length > 0) sections.push("Steps already completed:", ...digest, "");
551
+ sections.push(`Feedback requiring a revised plan: ${feedback}`, "", "Produce a plan for the REMAINING work only.");
552
+ return sections.join("\n");
244
553
  }
245
554
  /**
246
555
  * Compose a step's effective input: the step's own `input`, prefixed
@@ -313,6 +622,123 @@ var PlannerRun = class {
313
622
  const mergedCost = accumulateCost(target.cost, child.cost);
314
623
  if (mergedCost !== void 0) target.cost = mergedCost;
315
624
  }
625
+ /**
626
+ * Re-derive the sequential cursor + prior-output context from the
627
+ * persisted ledger on resume. Threads every already-`completed` node's
628
+ * output into `previousOutputs`, returns the first index NOT completed
629
+ * as the resume cursor, and prunes stale non-completed ledger entries
630
+ * (the failed node + any skipped tail) at-or-after that cursor so the
631
+ * re-run repopulates them without duplicating.
632
+ */
633
+ rehydrateSequentialState(steps, previousOutputs) {
634
+ let cursor = 0;
635
+ for (let index = 0; index < steps.length; index++) {
636
+ const snapshot = this.snapshotFor(index);
637
+ if (snapshot?.status === "completed") {
638
+ const step = steps[index];
639
+ previousOutputs.push(this.stringifyOutput(step.capability, snapshot.output));
640
+ cursor = index + 1;
641
+ continue;
642
+ }
643
+ break;
644
+ }
645
+ this.pruneLedgerFrom(cursor);
646
+ return cursor;
647
+ }
648
+ /**
649
+ * Re-derive the DAG scheduler's working sets from the persisted ledger
650
+ * on resume. Completed nodes go into `completed` + `done` with their
651
+ * string + raw outputs restored (so dependents read the right context);
652
+ * stale non-completed entries are pruned so the re-run repopulates them.
653
+ * Returns the count of nodes already dispatched (for the `maxSteps`
654
+ * truncation budget).
655
+ */
656
+ rehydrateDagState(dag, completed, done, outputs, rawOutputs) {
657
+ const completedIndices = /* @__PURE__ */ new Set();
658
+ for (const node of dag.nodes) {
659
+ const snapshot = this.snapshotFor(node.index);
660
+ if (snapshot?.status !== "completed") continue;
661
+ completed.add(node.id);
662
+ done.add(node.id);
663
+ completedIndices.add(node.index);
664
+ rawOutputs.set(node.id, snapshot.output);
665
+ outputs.set(node.id, this.stringifyOutput(node.step.capability, snapshot.output));
666
+ }
667
+ const retained = this.executedSteps.filter((snapshot) => completedIndices.has(snapshot.index));
668
+ this.executedSteps.length = 0;
669
+ this.executedSteps.push(...retained);
670
+ return completedIndices.size;
671
+ }
672
+ /**
673
+ * Drop every ledger entry whose index is at or after `from`. Used by
674
+ * the sequential resume re-seed to clear the crashed run's failed /
675
+ * skipped frontier before the re-run repopulates it.
676
+ */
677
+ pruneLedgerFrom(from) {
678
+ const retained = this.executedSteps.filter((snapshot) => snapshot.index < from);
679
+ this.executedSteps.length = 0;
680
+ this.executedSteps.push(...retained);
681
+ }
682
+ /**
683
+ * Map the run's terminal outcome to the persisted snapshot status.
684
+ * `awaiting-approval` (plan-only) never persists a durable snapshot
685
+ * (resume is always an execution), so it folds to `running` here —
686
+ * but the durable + plan-only combination is disallowed at the call
687
+ * site, so this path is effectively unreachable.
688
+ */
689
+ resolveSnapshotStatus() {
690
+ if (this.cancelledAt !== void 0) return "cancelled";
691
+ if (this.error) return "failed";
692
+ if (this.awaitingApproval) return "running";
693
+ return "completed";
694
+ }
695
+ /**
696
+ * Build and persist a {@link PlannerSnapshot} from the current
697
+ * accumulators. The per-node and terminal checkpoints both route
698
+ * through here. No-op when `durable` is absent. A failed persist is
699
+ * logged and swallowed (never aborts the run), matching the supervisor
700
+ * / workflow checkpoint policy.
701
+ */
702
+ async checkpoint(status) {
703
+ if (!this.args.config.durable || !this.plan) return;
704
+ const outcome = await persistPlannerSnapshot({
705
+ durable: this.args.config.durable,
706
+ runId: this.runId,
707
+ plannerName: this.args.config.name,
708
+ signature: this.args.signature,
709
+ version: this.args.config.version,
710
+ goal: this.args.goal,
711
+ plan: this.plan,
712
+ executedSteps: this.executedSteps,
713
+ usage: this.usage,
714
+ children: this.children,
715
+ replanCount: this.replanCount,
716
+ status,
717
+ startedAt: this.startedAt
718
+ });
719
+ if (!outcome.ok) this.logDurableFailure("snapshot.persist.failed", outcome.error);
720
+ }
721
+ /**
722
+ * Re-derive the terminal state when a resume short-circuits a snapshot
723
+ * whose run already COMPLETED. The persisted ledger is the
724
+ * authoritative outcome — `this.data` is restored from the last
725
+ * completed node so the rebuilt result carries the final output.
726
+ *
727
+ * Only reached for a `completed` snapshot — `failed` / `cancelled`
728
+ * snapshots re-enter execution to retry the unfinished frontier instead.
729
+ */
730
+ rebuildResumedTerminal(_status) {
731
+ const lastCompleted = [...this.executedSteps].reverse().find((snapshot) => snapshot.status === "completed");
732
+ if (lastCompleted) this.data = lastCompleted.output;
733
+ }
734
+ /** Structured-log a durable persist/delete failure. */
735
+ logDurableFailure(action, error) {
736
+ log.warn("ai.planner", action, "durable snapshot operation failed", {
737
+ runId: this.runId,
738
+ planner: this.args.config.name,
739
+ error: error instanceof Error ? error.message : String(error)
740
+ });
741
+ }
316
742
  /** Whether the caller's abort signal has fired. */
317
743
  isAborted() {
318
744
  return this.args.options?.signal?.aborted === true;