@warlock.js/ai 4.4.0 → 4.5.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 (535) hide show
  1. package/CHANGELOG.md +52 -55
  2. package/cjs/index.cjs +221 -14147
  3. package/cjs/src-C02yzsLs.cjs +22991 -0
  4. package/cjs/src-C02yzsLs.cjs.map +1 -0
  5. package/cjs/src-DFibP2FQ.cjs +30 -0
  6. package/esm/agent/agent-config.type.d.mts +90 -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 +203 -30
  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/ai-openai/src/embedder.mjs +4 -0
  21. package/esm/ai-openai/src/index.mjs +4 -0
  22. package/esm/ai-openai/src/model.mjs +5 -0
  23. package/esm/ai-openai/src/sdk.mjs +6 -0
  24. package/esm/ai-openai/src/utils/index.mjs +4 -0
  25. package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
  26. package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
  27. package/esm/ai.d.mts +119 -53
  28. package/esm/ai.d.mts.map +1 -1
  29. package/esm/ai.mjs +43 -8
  30. package/esm/ai.mjs.map +1 -1
  31. package/esm/batch/batch.d.mts.map +1 -1
  32. package/esm/batch/batch.mjs +21 -1
  33. package/esm/batch/batch.mjs.map +1 -1
  34. package/esm/batch/batch.type.d.mts +11 -4
  35. package/esm/batch/batch.type.d.mts.map +1 -1
  36. package/esm/config.d.mts +39 -3
  37. package/esm/config.d.mts.map +1 -1
  38. package/esm/config.mjs +26 -2
  39. package/esm/config.mjs.map +1 -1
  40. package/esm/contracts/agent/agent-options.type.d.mts +11 -3
  41. package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
  42. package/esm/contracts/agent/eval.type.d.mts +43 -2
  43. package/esm/contracts/agent/eval.type.d.mts.map +1 -1
  44. package/esm/contracts/attachment-policy.type.d.mts +51 -0
  45. package/esm/contracts/attachment-policy.type.d.mts.map +1 -0
  46. package/esm/contracts/attachment.type.d.mts +16 -7
  47. package/esm/contracts/attachment.type.d.mts.map +1 -1
  48. package/esm/contracts/content-part.type.d.mts +14 -5
  49. package/esm/contracts/content-part.type.d.mts.map +1 -1
  50. package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -1
  51. package/esm/contracts/index.d.mts +6 -4
  52. package/esm/contracts/model.contract.d.mts +11 -8
  53. package/esm/contracts/model.contract.d.mts.map +1 -1
  54. package/esm/contracts/orchestrator/index.d.mts +1 -0
  55. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +31 -2
  56. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -1
  57. package/esm/contracts/orchestrator/session-lock.contract.d.mts +47 -0
  58. package/esm/contracts/orchestrator/session-lock.contract.d.mts.map +1 -0
  59. package/esm/contracts/planner/index.d.mts +1 -1
  60. package/esm/contracts/planner/planner-config.type.d.mts +31 -0
  61. package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
  62. package/esm/contracts/planner/planner-execute-options.type.d.mts +48 -1
  63. package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -1
  64. package/esm/contracts/planner/planner-result.type.d.mts +8 -0
  65. package/esm/contracts/planner/planner-result.type.d.mts.map +1 -1
  66. package/esm/contracts/planner/planner.contract.d.mts +1 -1
  67. package/esm/contracts/result/agent-result.type.d.mts +6 -4
  68. package/esm/contracts/result/agent-result.type.d.mts.map +1 -1
  69. package/esm/contracts/result/base-report.type.d.mts +21 -3
  70. package/esm/contracts/result/base-report.type.d.mts.map +1 -1
  71. package/esm/contracts/result/base-report.type.mjs.map +1 -1
  72. package/esm/contracts/result/execution-report.type.d.mts +53 -1
  73. package/esm/contracts/result/execution-report.type.d.mts.map +1 -1
  74. package/esm/contracts/result/supervisor-result.type.d.mts +14 -2
  75. package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
  76. package/esm/contracts/result/workflow-result.type.d.mts +2 -1
  77. package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
  78. package/esm/contracts/supervisor/supervisor-config.type.d.mts +29 -0
  79. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
  80. package/esm/contracts/system-prompt.contract.d.mts +103 -1
  81. package/esm/contracts/system-prompt.contract.d.mts.map +1 -1
  82. package/esm/contracts/team/index.d.mts +1 -0
  83. package/esm/contracts/team/team-config.type.d.mts +127 -0
  84. package/esm/contracts/team/team-config.type.d.mts.map +1 -0
  85. package/esm/contracts/tool.contract.d.mts +4 -2
  86. package/esm/contracts/tool.contract.d.mts.map +1 -1
  87. package/esm/contracts/workflow/step.contract.d.mts +30 -5
  88. package/esm/contracts/workflow/step.contract.d.mts.map +1 -1
  89. package/esm/contracts/workflow/workflow.contract.d.mts +16 -0
  90. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
  91. package/esm/errors/error-code.type.d.mts +1 -1
  92. package/esm/errors/index.d.mts +1 -0
  93. package/esm/errors/index.mjs +1 -0
  94. package/esm/errors/outbound-policy-error.d.mts +27 -0
  95. package/esm/errors/outbound-policy-error.d.mts.map +1 -0
  96. package/esm/errors/outbound-policy-error.mjs +32 -0
  97. package/esm/errors/outbound-policy-error.mjs.map +1 -0
  98. package/esm/eval/dataset.d.mts +28 -0
  99. package/esm/eval/dataset.d.mts.map +1 -0
  100. package/esm/eval/dataset.mjs +112 -0
  101. package/esm/eval/dataset.mjs.map +1 -0
  102. package/esm/eval/dataset.type.d.mts +53 -0
  103. package/esm/eval/dataset.type.d.mts.map +1 -0
  104. package/esm/eval/eval-runner.d.mts.map +1 -1
  105. package/esm/eval/eval-runner.mjs +16 -2
  106. package/esm/eval/eval-runner.mjs.map +1 -1
  107. package/esm/eval/index.d.mts +20 -1
  108. package/esm/eval/index.d.mts.map +1 -1
  109. package/esm/eval/index.mjs +20 -2
  110. package/esm/eval/index.mjs.map +1 -1
  111. package/esm/eval/regression.d.mts +30 -0
  112. package/esm/eval/regression.d.mts.map +1 -0
  113. package/esm/eval/regression.mjs +51 -0
  114. package/esm/eval/regression.mjs.map +1 -0
  115. package/esm/eval/report-json.d.mts +30 -0
  116. package/esm/eval/report-json.d.mts.map +1 -0
  117. package/esm/eval/report-json.mjs +33 -0
  118. package/esm/eval/report-json.mjs.map +1 -0
  119. package/esm/eval/report-junit.d.mts +22 -0
  120. package/esm/eval/report-junit.d.mts.map +1 -0
  121. package/esm/eval/report-junit.mjs +60 -0
  122. package/esm/eval/report-junit.mjs.map +1 -0
  123. package/esm/guard/contracts/guard-options.type.d.mts +165 -0
  124. package/esm/guard/contracts/guard-options.type.d.mts.map +1 -0
  125. package/esm/guard/contracts/guardrail.contract.d.mts +78 -0
  126. package/esm/guard/contracts/guardrail.contract.d.mts.map +1 -0
  127. package/esm/guard/contracts/index.d.mts +4 -0
  128. package/esm/guard/contracts/openai-client.contract.d.mts +51 -0
  129. package/esm/guard/contracts/openai-client.contract.d.mts.map +1 -0
  130. package/esm/guard/contracts/verdict.type.d.mts +76 -0
  131. package/esm/guard/contracts/verdict.type.d.mts.map +1 -0
  132. package/esm/guard/detectors/index.d.mts +4 -0
  133. package/esm/guard/detectors/index.mjs +6 -0
  134. package/esm/guard/detectors/injection.d.mts +34 -0
  135. package/esm/guard/detectors/injection.d.mts.map +1 -0
  136. package/esm/guard/detectors/injection.mjs +254 -0
  137. package/esm/guard/detectors/injection.mjs.map +1 -0
  138. package/esm/guard/detectors/moderation.d.mts +32 -0
  139. package/esm/guard/detectors/moderation.d.mts.map +1 -0
  140. package/esm/guard/detectors/moderation.mjs +134 -0
  141. package/esm/guard/detectors/moderation.mjs.map +1 -0
  142. package/esm/guard/detectors/pii.d.mts +41 -0
  143. package/esm/guard/detectors/pii.d.mts.map +1 -0
  144. package/esm/guard/detectors/pii.mjs +199 -0
  145. package/esm/guard/detectors/pii.mjs.map +1 -0
  146. package/esm/guard/detectors/topic.d.mts +29 -0
  147. package/esm/guard/detectors/topic.d.mts.map +1 -0
  148. package/esm/guard/detectors/topic.mjs +99 -0
  149. package/esm/guard/detectors/topic.mjs.map +1 -0
  150. package/esm/guard/errors.d.mts +12 -0
  151. package/esm/guard/errors.d.mts.map +1 -0
  152. package/esm/guard/errors.mjs +18 -0
  153. package/esm/guard/errors.mjs.map +1 -0
  154. package/esm/guard/guard.d.mts +67 -0
  155. package/esm/guard/guard.d.mts.map +1 -0
  156. package/esm/guard/guard.mjs +209 -0
  157. package/esm/guard/guard.mjs.map +1 -0
  158. package/esm/guard/guardrail.d.mts +39 -0
  159. package/esm/guard/guardrail.d.mts.map +1 -0
  160. package/esm/guard/guardrail.mjs +22 -0
  161. package/esm/guard/guardrail.mjs.map +1 -0
  162. package/esm/human/contracts/approval.type.d.mts +154 -0
  163. package/esm/human/contracts/approval.type.d.mts.map +1 -0
  164. package/esm/human/contracts/human-approval.type.d.mts +38 -0
  165. package/esm/human/contracts/human-approval.type.d.mts.map +1 -0
  166. package/esm/human/contracts/index.d.mts +4 -0
  167. package/esm/human/contracts/interrupt-store.contract.d.mts +112 -0
  168. package/esm/human/contracts/interrupt-store.contract.d.mts.map +1 -0
  169. package/esm/human/contracts/resume.type.d.mts +77 -0
  170. package/esm/human/contracts/resume.type.d.mts.map +1 -0
  171. package/esm/human/errors.d.mts +84 -0
  172. package/esm/human/errors.d.mts.map +1 -0
  173. package/esm/human/errors.mjs +60 -0
  174. package/esm/human/errors.mjs.map +1 -0
  175. package/esm/human/human-approval.d.mts +57 -0
  176. package/esm/human/human-approval.d.mts.map +1 -0
  177. package/esm/human/human-approval.mjs +170 -0
  178. package/esm/human/human-approval.mjs.map +1 -0
  179. package/esm/human/policy.d.mts +55 -0
  180. package/esm/human/policy.d.mts.map +1 -0
  181. package/esm/human/policy.mjs +67 -0
  182. package/esm/human/policy.mjs.map +1 -0
  183. package/esm/human/register.mjs +37 -0
  184. package/esm/human/register.mjs.map +1 -0
  185. package/esm/human/resume-seed.mjs +53 -0
  186. package/esm/human/resume-seed.mjs.map +1 -0
  187. package/esm/human/resume.d.mts +54 -0
  188. package/esm/human/resume.d.mts.map +1 -0
  189. package/esm/human/resume.mjs +121 -0
  190. package/esm/human/resume.mjs.map +1 -0
  191. package/esm/human/stores/index.mjs +5 -0
  192. package/esm/human/stores/memory.d.mts +30 -0
  193. package/esm/human/stores/memory.d.mts.map +1 -0
  194. package/esm/human/stores/memory.mjs +91 -0
  195. package/esm/human/stores/memory.mjs.map +1 -0
  196. package/esm/human/stores/pg.d.mts +59 -0
  197. package/esm/human/stores/pg.d.mts.map +1 -0
  198. package/esm/human/stores/pg.mjs +220 -0
  199. package/esm/human/stores/pg.mjs.map +1 -0
  200. package/esm/human/stores/redis.d.mts +56 -0
  201. package/esm/human/stores/redis.d.mts.map +1 -0
  202. package/esm/human/stores/redis.mjs +201 -0
  203. package/esm/human/stores/redis.mjs.map +1 -0
  204. package/esm/index.d.mts +113 -22
  205. package/esm/index.mjs +82 -11
  206. package/esm/middleware/builtins/budget.mjs +6 -2
  207. package/esm/middleware/builtins/budget.mjs.map +1 -1
  208. package/esm/middleware/utils/extract-user-text.d.mts +8 -1
  209. package/esm/middleware/utils/extract-user-text.d.mts.map +1 -1
  210. package/esm/middleware/utils/extract-user-text.mjs +8 -1
  211. package/esm/middleware/utils/extract-user-text.mjs.map +1 -1
  212. package/esm/object-stream/index.d.mts +2 -0
  213. package/esm/object-stream/index.mjs +4 -0
  214. package/esm/object-stream/parse-partial-json.d.mts +22 -0
  215. package/esm/object-stream/parse-partial-json.d.mts.map +1 -0
  216. package/esm/object-stream/parse-partial-json.mjs +78 -0
  217. package/esm/object-stream/parse-partial-json.mjs.map +1 -0
  218. package/esm/object-stream/stream-object.d.mts +68 -0
  219. package/esm/object-stream/stream-object.d.mts.map +1 -0
  220. package/esm/object-stream/stream-object.mjs +104 -0
  221. package/esm/object-stream/stream-object.mjs.map +1 -0
  222. package/esm/observe/index.mjs +4 -0
  223. package/esm/observe/observer-registry.d.mts +30 -0
  224. package/esm/observe/observer-registry.d.mts.map +1 -0
  225. package/esm/observe/observer-registry.mjs +51 -0
  226. package/esm/observe/observer-registry.mjs.map +1 -0
  227. package/esm/observe/observer.contract.d.mts +40 -0
  228. package/esm/observe/observer.contract.d.mts.map +1 -0
  229. package/esm/observe/resolve-observers.d.mts +40 -0
  230. package/esm/observe/resolve-observers.d.mts.map +1 -0
  231. package/esm/observe/resolve-observers.mjs +73 -0
  232. package/esm/observe/resolve-observers.mjs.map +1 -0
  233. package/esm/orchestrator/execution.d.mts.map +1 -1
  234. package/esm/orchestrator/execution.mjs +5 -2
  235. package/esm/orchestrator/execution.mjs.map +1 -1
  236. package/esm/orchestrator/index.d.mts +1 -0
  237. package/esm/orchestrator/index.mjs +1 -0
  238. package/esm/orchestrator/orchestrator.d.mts.map +1 -1
  239. package/esm/orchestrator/orchestrator.mjs +39 -6
  240. package/esm/orchestrator/orchestrator.mjs.map +1 -1
  241. package/esm/orchestrator/session-lock.d.mts +25 -0
  242. package/esm/orchestrator/session-lock.d.mts.map +1 -0
  243. package/esm/orchestrator/session-lock.mjs +83 -0
  244. package/esm/orchestrator/session-lock.mjs.map +1 -0
  245. package/esm/planner/dag-scheduler.mjs +97 -0
  246. package/esm/planner/dag-scheduler.mjs.map +1 -0
  247. package/esm/planner/plan-prompt.d.mts +1 -1
  248. package/esm/planner/plan-prompt.d.mts.map +1 -1
  249. package/esm/planner/plan-prompt.mjs +2 -1
  250. package/esm/planner/plan-prompt.mjs.map +1 -1
  251. package/esm/planner/planner-run.d.mts.map +1 -1
  252. package/esm/planner/planner-run.mjs +300 -29
  253. package/esm/planner/planner-run.mjs.map +1 -1
  254. package/esm/planner/planner.mjs +1 -1
  255. package/esm/planner/planner.mjs.map +1 -1
  256. package/esm/prompt/errors.d.mts +57 -0
  257. package/esm/prompt/errors.d.mts.map +1 -0
  258. package/esm/prompt/errors.mjs +73 -0
  259. package/esm/prompt/errors.mjs.map +1 -0
  260. package/esm/prompt/index.d.mts +3 -0
  261. package/esm/prompt/index.mjs +4 -0
  262. package/esm/prompt/prompt-langfuse-sync.mjs +104 -0
  263. package/esm/prompt/prompt-langfuse-sync.mjs.map +1 -0
  264. package/esm/prompt/prompt-langfuse-sync.type.d.mts +32 -0
  265. package/esm/prompt/prompt-langfuse-sync.type.d.mts.map +1 -0
  266. package/esm/prompt/prompt-validate.mjs +170 -0
  267. package/esm/prompt/prompt-validate.mjs.map +1 -0
  268. package/esm/prompt/prompt.d.mts +54 -0
  269. package/esm/prompt/prompt.d.mts.map +1 -0
  270. package/esm/prompt/prompt.mjs +218 -0
  271. package/esm/prompt/prompt.mjs.map +1 -0
  272. package/esm/prompt/prompt.type.d.mts +174 -0
  273. package/esm/prompt/prompt.type.d.mts.map +1 -0
  274. package/esm/prompts/index.d.mts +3 -0
  275. package/esm/prompts/index.mjs +3 -0
  276. package/esm/prompts/prompts-manager.contract.d.mts +154 -0
  277. package/esm/prompts/prompts-manager.contract.d.mts.map +1 -0
  278. package/esm/prompts/prompts-manager.d.mts +38 -0
  279. package/esm/prompts/prompts-manager.d.mts.map +1 -0
  280. package/esm/prompts/prompts-manager.mjs +410 -0
  281. package/esm/prompts/prompts-manager.mjs.map +1 -0
  282. package/esm/prompts/prompts-manager.type.d.mts +172 -0
  283. package/esm/prompts/prompts-manager.type.d.mts.map +1 -0
  284. package/esm/prompts/prompts-validate.mjs +200 -0
  285. package/esm/prompts/prompts-validate.mjs.map +1 -0
  286. package/esm/rag/as-tool.mjs +48 -0
  287. package/esm/rag/as-tool.mjs.map +1 -0
  288. package/esm/rag/chunk/chunk.d.mts +24 -0
  289. package/esm/rag/chunk/chunk.d.mts.map +1 -0
  290. package/esm/rag/chunk/chunk.mjs +44 -0
  291. package/esm/rag/chunk/chunk.mjs.map +1 -0
  292. package/esm/rag/chunk/fixed.mjs +32 -0
  293. package/esm/rag/chunk/fixed.mjs.map +1 -0
  294. package/esm/rag/chunk/markdown.mjs +75 -0
  295. package/esm/rag/chunk/markdown.mjs.map +1 -0
  296. package/esm/rag/chunk/recursive.mjs +132 -0
  297. package/esm/rag/chunk/recursive.mjs.map +1 -0
  298. package/esm/rag/chunk/sentence.mjs +73 -0
  299. package/esm/rag/chunk/sentence.mjs.map +1 -0
  300. package/esm/rag/contracts/chunk-options.type.d.mts +35 -0
  301. package/esm/rag/contracts/chunk-options.type.d.mts.map +1 -0
  302. package/esm/rag/contracts/citation.type.d.mts +35 -0
  303. package/esm/rag/contracts/citation.type.d.mts.map +1 -0
  304. package/esm/rag/contracts/index.d.mts +4 -0
  305. package/esm/rag/contracts/rag-config.type.d.mts +68 -0
  306. package/esm/rag/contracts/rag-config.type.d.mts.map +1 -0
  307. package/esm/rag/contracts/rag-document.type.d.mts +21 -0
  308. package/esm/rag/contracts/rag-document.type.d.mts.map +1 -0
  309. package/esm/rag/hybrid/bm25.d.mts +23 -0
  310. package/esm/rag/hybrid/bm25.d.mts.map +1 -0
  311. package/esm/rag/hybrid/bm25.mjs +51 -0
  312. package/esm/rag/hybrid/bm25.mjs.map +1 -0
  313. package/esm/rag/hybrid/hybrid-rank.d.mts +33 -0
  314. package/esm/rag/hybrid/hybrid-rank.d.mts.map +1 -0
  315. package/esm/rag/hybrid/hybrid-rank.mjs +29 -0
  316. package/esm/rag/hybrid/hybrid-rank.mjs.map +1 -0
  317. package/esm/rag/hybrid/rrf.d.mts +25 -0
  318. package/esm/rag/hybrid/rrf.d.mts.map +1 -0
  319. package/esm/rag/hybrid/rrf.mjs +30 -0
  320. package/esm/rag/hybrid/rrf.mjs.map +1 -0
  321. package/esm/rag/index.d.mts +15 -0
  322. package/esm/rag/index.mjs +11 -0
  323. package/esm/rag/rag.d.mts +38 -0
  324. package/esm/rag/rag.d.mts.map +1 -0
  325. package/esm/rag/rag.mjs +126 -0
  326. package/esm/rag/rag.mjs.map +1 -0
  327. package/esm/rag/rerank/keyword-reranker.d.mts +32 -0
  328. package/esm/rag/rerank/keyword-reranker.d.mts.map +1 -0
  329. package/esm/rag/rerank/keyword-reranker.mjs +58 -0
  330. package/esm/rag/rerank/keyword-reranker.mjs.map +1 -0
  331. package/esm/rag/rerank/llm-reranker.d.mts +36 -0
  332. package/esm/rag/rerank/llm-reranker.d.mts.map +1 -0
  333. package/esm/rag/rerank/llm-reranker.mjs +85 -0
  334. package/esm/rag/rerank/llm-reranker.mjs.map +1 -0
  335. package/esm/rag/rerank/reranker.contract.d.mts +28 -0
  336. package/esm/rag/rerank/reranker.contract.d.mts.map +1 -0
  337. package/esm/rag/retrieve.mjs +68 -0
  338. package/esm/rag/retrieve.mjs.map +1 -0
  339. package/esm/rag/store/cache-vector-store.d.mts +27 -0
  340. package/esm/rag/store/cache-vector-store.d.mts.map +1 -0
  341. package/esm/rag/store/cache-vector-store.mjs +48 -0
  342. package/esm/rag/store/cache-vector-store.mjs.map +1 -0
  343. package/esm/rag/store/vector-store.contract.d.mts +38 -0
  344. package/esm/rag/store/vector-store.contract.d.mts.map +1 -0
  345. package/esm/rag/transforms/multi-query.d.mts +27 -0
  346. package/esm/rag/transforms/multi-query.d.mts.map +1 -0
  347. package/esm/rag/transforms/multi-query.mjs +41 -0
  348. package/esm/rag/transforms/multi-query.mjs.map +1 -0
  349. package/esm/security/index.mjs +5 -0
  350. package/esm/security/outbound-policy.d.mts +46 -0
  351. package/esm/security/outbound-policy.d.mts.map +1 -0
  352. package/esm/security/outbound-policy.mjs +187 -0
  353. package/esm/security/outbound-policy.mjs.map +1 -0
  354. package/esm/security/outbound-policy.type.d.mts +74 -0
  355. package/esm/security/outbound-policy.type.d.mts.map +1 -0
  356. package/esm/security/private-ip.d.mts +15 -0
  357. package/esm/security/private-ip.d.mts.map +1 -0
  358. package/esm/security/private-ip.mjs +48 -0
  359. package/esm/security/private-ip.mjs.map +1 -0
  360. package/esm/security/redact.d.mts +59 -0
  361. package/esm/security/redact.d.mts.map +1 -0
  362. package/esm/security/redact.mjs +122 -0
  363. package/esm/security/redact.mjs.map +1 -0
  364. package/esm/serve/serve.d.mts +50 -0
  365. package/esm/serve/serve.d.mts.map +1 -0
  366. package/esm/serve/serve.mjs +90 -0
  367. package/esm/serve/serve.mjs.map +1 -0
  368. package/esm/serve/sse.d.mts +20 -0
  369. package/esm/serve/sse.d.mts.map +1 -0
  370. package/esm/serve/sse.mjs +25 -0
  371. package/esm/serve/sse.mjs.map +1 -0
  372. package/esm/serve/stream-to-sse.d.mts +29 -0
  373. package/esm/serve/stream-to-sse.d.mts.map +1 -0
  374. package/esm/serve/stream-to-sse.mjs +37 -0
  375. package/esm/serve/stream-to-sse.mjs.map +1 -0
  376. package/esm/skills/catalog.d.mts +49 -0
  377. package/esm/skills/catalog.d.mts.map +1 -0
  378. package/esm/skills/catalog.mjs +140 -0
  379. package/esm/skills/catalog.mjs.map +1 -0
  380. package/esm/skills/contracts/skill-record.type.d.mts +37 -0
  381. package/esm/skills/contracts/skill-record.type.d.mts.map +1 -0
  382. package/esm/skills/contracts/skills-config.type.d.mts +108 -0
  383. package/esm/skills/contracts/skills-config.type.d.mts.map +1 -0
  384. package/esm/skills/contracts/skills-store.contract.d.mts +28 -0
  385. package/esm/skills/contracts/skills-store.contract.d.mts.map +1 -0
  386. package/esm/skills/contracts/skills.contract.d.mts +43 -0
  387. package/esm/skills/contracts/skills.contract.d.mts.map +1 -0
  388. package/esm/skills/index.d.mts +16 -0
  389. package/esm/skills/index.mjs +14 -0
  390. package/esm/skills/load-skill-tool.d.mts +38 -0
  391. package/esm/skills/load-skill-tool.d.mts.map +1 -0
  392. package/esm/skills/load-skill-tool.mjs +65 -0
  393. package/esm/skills/load-skill-tool.mjs.map +1 -0
  394. package/esm/skills/review-gate.d.mts +33 -0
  395. package/esm/skills/review-gate.d.mts.map +1 -0
  396. package/esm/skills/review-gate.mjs +60 -0
  397. package/esm/skills/review-gate.mjs.map +1 -0
  398. package/esm/skills/save-skill-tool.d.mts +39 -0
  399. package/esm/skills/save-skill-tool.d.mts.map +1 -0
  400. package/esm/skills/save-skill-tool.mjs +65 -0
  401. package/esm/skills/save-skill-tool.mjs.map +1 -0
  402. package/esm/skills/skills.d.mts +33 -0
  403. package/esm/skills/skills.d.mts.map +1 -0
  404. package/esm/skills/skills.mjs +109 -0
  405. package/esm/skills/skills.mjs.map +1 -0
  406. package/esm/skills/sources/directory-source.d.mts +19 -0
  407. package/esm/skills/sources/directory-source.d.mts.map +1 -0
  408. package/esm/skills/sources/directory-source.mjs +108 -0
  409. package/esm/skills/sources/directory-source.mjs.map +1 -0
  410. package/esm/skills/sources/index.d.mts +18 -0
  411. package/esm/skills/sources/index.d.mts.map +1 -0
  412. package/esm/skills/sources/index.mjs +27 -0
  413. package/esm/skills/sources/index.mjs.map +1 -0
  414. package/esm/skills/sources/parse-frontmatter.d.mts +27 -0
  415. package/esm/skills/sources/parse-frontmatter.d.mts.map +1 -0
  416. package/esm/skills/sources/parse-frontmatter.mjs +46 -0
  417. package/esm/skills/sources/parse-frontmatter.mjs.map +1 -0
  418. package/esm/skills/sources/store-source.d.mts +14 -0
  419. package/esm/skills/sources/store-source.d.mts.map +1 -0
  420. package/esm/skills/sources/store-source.mjs +15 -0
  421. package/esm/skills/sources/store-source.mjs.map +1 -0
  422. package/esm/skills/sources/url-source.d.mts +29 -0
  423. package/esm/skills/sources/url-source.d.mts.map +1 -0
  424. package/esm/skills/sources/url-source.mjs +117 -0
  425. package/esm/skills/sources/url-source.mjs.map +1 -0
  426. package/esm/skills/store/mock-skills-store.d.mts +57 -0
  427. package/esm/skills/store/mock-skills-store.d.mts.map +1 -0
  428. package/esm/skills/store/mock-skills-store.mjs +100 -0
  429. package/esm/skills/store/mock-skills-store.mjs.map +1 -0
  430. package/esm/skills/store/procedural-skill-store.d.mts +30 -0
  431. package/esm/skills/store/procedural-skill-store.d.mts.map +1 -0
  432. package/esm/skills/store/procedural-skill-store.mjs +125 -0
  433. package/esm/skills/store/procedural-skill-store.mjs.map +1 -0
  434. package/esm/supervisor/as-tool.mjs +2 -2
  435. package/esm/supervisor/as-tool.mjs.map +1 -1
  436. package/esm/supervisor/execution.d.mts.map +1 -1
  437. package/esm/supervisor/execution.mjs +31 -28
  438. package/esm/supervisor/execution.mjs.map +1 -1
  439. package/esm/supervisor/supervisor.d.mts.map +1 -1
  440. package/esm/supervisor/supervisor.mjs +8 -3
  441. package/esm/supervisor/supervisor.mjs.map +1 -1
  442. package/esm/system-prompt/index.d.mts +4 -0
  443. package/esm/system-prompt/system-prompt.d.mts +68 -4
  444. package/esm/system-prompt/system-prompt.d.mts.map +1 -1
  445. package/esm/system-prompt/system-prompt.mjs +89 -5
  446. package/esm/system-prompt/system-prompt.mjs.map +1 -1
  447. package/esm/team/gates.mjs +48 -0
  448. package/esm/team/gates.mjs.map +1 -0
  449. package/esm/team/index.d.mts +1 -0
  450. package/esm/team/index.mjs +3 -0
  451. package/esm/team/team.d.mts +42 -0
  452. package/esm/team/team.d.mts.map +1 -0
  453. package/esm/team/team.mjs +94 -0
  454. package/esm/team/team.mjs.map +1 -0
  455. package/esm/tool/executable-as-tool.d.mts.map +1 -1
  456. package/esm/tool/executable-as-tool.mjs +2 -2
  457. package/esm/tool/executable-as-tool.mjs.map +1 -1
  458. package/esm/tool/tool.d.mts.map +1 -1
  459. package/esm/tool/tool.mjs +2 -2
  460. package/esm/tool/tool.mjs.map +1 -1
  461. package/esm/utils/compute-cost.d.mts +17 -1
  462. package/esm/utils/compute-cost.d.mts.map +1 -1
  463. package/esm/utils/compute-cost.mjs +26 -1
  464. package/esm/utils/compute-cost.mjs.map +1 -1
  465. package/esm/utils/extract-json-lenient.d.mts +42 -0
  466. package/esm/utils/extract-json-lenient.d.mts.map +1 -0
  467. package/esm/utils/extract-json-lenient.mjs +97 -0
  468. package/esm/utils/extract-json-lenient.mjs.map +1 -0
  469. package/esm/utils/index.d.mts +4 -2
  470. package/esm/utils/index.mjs +3 -1
  471. package/esm/utils/json-schema.d.mts +1 -1
  472. package/esm/utils/prepare-attachment-part.d.mts +10 -1
  473. package/esm/utils/prepare-attachment-part.d.mts.map +1 -1
  474. package/esm/utils/prepare-attachment-part.mjs +103 -11
  475. package/esm/utils/prepare-attachment-part.mjs.map +1 -1
  476. package/esm/utils/resolve-attachment.d.mts +4 -3
  477. package/esm/utils/resolve-attachment.d.mts.map +1 -1
  478. package/esm/utils/resolve-attachment.mjs +4 -3
  479. package/esm/utils/resolve-attachment.mjs.map +1 -1
  480. package/esm/utils/run-context.d.mts +94 -0
  481. package/esm/utils/run-context.d.mts.map +1 -0
  482. package/esm/utils/run-context.mjs +98 -0
  483. package/esm/utils/run-context.mjs.map +1 -0
  484. package/esm/vcr/cassette-io.mjs +57 -0
  485. package/esm/vcr/cassette-io.mjs.map +1 -0
  486. package/esm/vcr/errors.d.mts +42 -0
  487. package/esm/vcr/errors.d.mts.map +1 -0
  488. package/esm/vcr/errors.mjs +37 -0
  489. package/esm/vcr/errors.mjs.map +1 -0
  490. package/esm/vcr/hash-request.d.mts +28 -0
  491. package/esm/vcr/hash-request.d.mts.map +1 -0
  492. package/esm/vcr/hash-request.mjs +118 -0
  493. package/esm/vcr/hash-request.mjs.map +1 -0
  494. package/esm/vcr/index.d.mts +4 -0
  495. package/esm/vcr/index.mjs +5 -0
  496. package/esm/vcr/vcr.d.mts +32 -0
  497. package/esm/vcr/vcr.d.mts.map +1 -0
  498. package/esm/vcr/vcr.mjs +248 -0
  499. package/esm/vcr/vcr.mjs.map +1 -0
  500. package/esm/vcr/vcr.type.d.mts +118 -0
  501. package/esm/vcr/vcr.type.d.mts.map +1 -0
  502. package/esm/workflow/as-tool.mjs +2 -2
  503. package/esm/workflow/as-tool.mjs.map +1 -1
  504. package/esm/workflow/engine.mjs +1 -0
  505. package/esm/workflow/engine.mjs.map +1 -1
  506. package/esm/workflow/step-runner.mjs +19 -20
  507. package/esm/workflow/step-runner.mjs.map +1 -1
  508. package/esm/workflow/workflow.d.mts.map +1 -1
  509. package/esm/workflow/workflow.mjs +8 -3
  510. package/esm/workflow/workflow.mjs.map +1 -1
  511. package/llms-full.txt +1683 -68
  512. package/llms.txt +16 -4
  513. package/package.json +7 -3
  514. package/skills/README.md +40 -4
  515. package/skills/ai-dx-helpers/SKILL.md +2 -2
  516. package/skills/approve-tool-calls/SKILL.md +134 -0
  517. package/skills/attach-ai-middleware/SKILL.md +1 -1
  518. package/skills/detect-and-redact-pii/SKILL.md +104 -0
  519. package/skills/durable-resume/SKILL.md +128 -0
  520. package/skills/escalate-block-to-human/SKILL.md +85 -0
  521. package/skills/eval-datasets-and-ci/SKILL.md +117 -0
  522. package/skills/guard-input-output/SKILL.md +117 -0
  523. package/skills/manage-prompts/SKILL.md +186 -0
  524. package/skills/observe-ai-flows/SKILL.md +94 -0
  525. package/skills/record-replay-llm/SKILL.md +92 -0
  526. package/skills/run-ai-agent/SKILL.md +26 -1
  527. package/skills/run-ai-rag/SKILL.md +139 -0
  528. package/skills/run-ai-team/SKILL.md +107 -0
  529. package/skills/run-orchestrator/SKILL.md +2 -0
  530. package/skills/run-planner/SKILL.md +73 -8
  531. package/skills/run-supervisor/SKILL.md +20 -1
  532. package/skills/use-runtime-skills/SKILL.md +106 -0
  533. package/skills/write-system-prompt/SKILL.md +30 -1
  534. package/cjs/index.cjs.map +0 -1
  535. package/esm/contracts/result/index.d.mts +0 -15
@@ -0,0 +1,97 @@
1
+ import { PlannerPlanInvalidError } from "../errors/planner-plan-invalid-error.mjs";
2
+
3
+ //#region ../@warlock.js/ai/src/planner/dag-scheduler.ts
4
+ /**
5
+ * Build the execution DAG from a plan's steps.
6
+ *
7
+ * Each step's `id` (falling back to its array index) and its `dependsOn`
8
+ * become an adjacency list. A `dependsOn` that names a step not in the
9
+ * plan, or any dependency cycle, raises a typed
10
+ * {@link PlannerPlanInvalidError} BEFORE any step runs — the same error
11
+ * class `generatePlan` uses for an unusable plan, with forensic context.
12
+ *
13
+ * @throws PlannerPlanInvalidError on a duplicate id, an unknown
14
+ * `dependsOn` target, or a cycle.
15
+ */
16
+ function buildDag(steps, plannerName = "planner") {
17
+ const nodes = [];
18
+ const byId = /* @__PURE__ */ new Map();
19
+ for (let index = 0; index < steps.length; index++) {
20
+ const step = steps[index];
21
+ const id = step.id ?? String(index);
22
+ if (byId.has(id)) throw new PlannerPlanInvalidError(`ai.planner("${plannerName}"): duplicate step id "${id}" in DAG plan`, { context: { id } });
23
+ const node = {
24
+ id,
25
+ index,
26
+ step,
27
+ dependencies: []
28
+ };
29
+ nodes.push(node);
30
+ byId.set(id, node);
31
+ }
32
+ const dependents = /* @__PURE__ */ new Map();
33
+ for (const node of nodes) {
34
+ const seen = /* @__PURE__ */ new Set();
35
+ for (const dependency of node.step.dependsOn ?? []) {
36
+ if (dependency === node.id) continue;
37
+ if (!byId.has(dependency)) throw new PlannerPlanInvalidError(`ai.planner("${plannerName}"): step "${node.id}" depends on unknown step "${dependency}"`, { context: {
38
+ id: node.id,
39
+ dependency
40
+ } });
41
+ if (seen.has(dependency)) continue;
42
+ seen.add(dependency);
43
+ node.dependencies.push(dependency);
44
+ const reverse = dependents.get(dependency) ?? [];
45
+ reverse.push(node.id);
46
+ dependents.set(dependency, reverse);
47
+ }
48
+ }
49
+ assertAcyclic(nodes, byId, plannerName);
50
+ return {
51
+ nodes,
52
+ byId,
53
+ dependents
54
+ };
55
+ }
56
+ /**
57
+ * Compute the next ready set: nodes not yet done whose every dependency
58
+ * is in `completed`. Preserves original plan order so a level dispatches
59
+ * deterministically. A node whose dependency is `unreachable` (a failed
60
+ * or skipped ancestor) is NOT ready — it never becomes ready and is
61
+ * recorded skipped by the caller.
62
+ */
63
+ function readyNodes(dag, completed, done) {
64
+ return dag.nodes.filter((node) => !done.has(node.id) && node.dependencies.every((dependency) => completed.has(dependency)));
65
+ }
66
+ /**
67
+ * The topological sink(s) — nodes nothing depends on. Used to define the
68
+ * "final output" under parallelism: with an `output` schema set, a
69
+ * single sink is the unambiguous final step; multiple sinks are a
70
+ * convergence error the caller surfaces.
71
+ */
72
+ function sinkNodes(dag) {
73
+ return dag.nodes.filter((node) => (dag.dependents.get(node.id) ?? []).length === 0);
74
+ }
75
+ /**
76
+ * Depth-first cycle detection over the dependency edges. A back-edge to
77
+ * a node on the current recursion stack means a cycle — raised as a
78
+ * typed {@link PlannerPlanInvalidError} naming the offending node.
79
+ */
80
+ function assertAcyclic(nodes, byId, plannerName) {
81
+ const VISITING = 1;
82
+ const DONE = 2;
83
+ const state = /* @__PURE__ */ new Map();
84
+ const visit = (node) => {
85
+ const current = state.get(node.id);
86
+ if (current === DONE) return;
87
+ if (current === VISITING) throw new PlannerPlanInvalidError(`ai.planner("${plannerName}"): dependency cycle detected at step "${node.id}"`, { context: { id: node.id } });
88
+ state.set(node.id, VISITING);
89
+ for (const dependency of node.dependencies) visit(byId.get(dependency));
90
+ state.set(node.id, DONE);
91
+ };
92
+ for (const node of nodes) visit(node);
93
+ }
94
+
95
+ //#endregion
96
+ export { buildDag, readyNodes, sinkNodes };
97
+ //# sourceMappingURL=dag-scheduler.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dag-scheduler.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/dag-scheduler.ts"],"sourcesContent":["import type { PlannerStep } from \"../contracts/planner/planner-plan.type\";\nimport { PlannerPlanInvalidError } from \"../errors/planner-plan-invalid-error\";\n\n/**\n * One node in the planner's execution DAG — a plan step plus the\n * resolved structural metadata the scheduler needs to order it.\n *\n * `id` is the step's own `id` when present, falling back to the step's\n * array index stringified (exactly as {@link PlannerStep.id} documents).\n * `dependencies` is the resolved set of node ids this step waits on,\n * de-duplicated and self-references dropped.\n */\nexport type DagNode = {\n /** Stable id — the step's own `id`, or its array index as a string. */\n id: string;\n /** 0-based position of the step in the original plan array. */\n index: number;\n /** The plan step this node schedules. */\n step: PlannerStep;\n /** Resolved ids this step depends on (subset of the DAG's node ids). */\n dependencies: string[];\n};\n\n/**\n * The built execution DAG — the ordered node list plus the lookups the\n * scheduler walks. Ordering follows the original plan array so a\n * dependency-free plan executes in author order, level by level.\n */\nexport type PlannerDag = {\n /** Nodes in original plan order. */\n nodes: DagNode[];\n /** id → node, for dependency resolution and sink detection. */\n byId: Map<string, DagNode>;\n /** id → ids of the nodes that depend on it (reverse edges). */\n dependents: Map<string, string[]>;\n};\n\n/**\n * Build the execution DAG from a plan's steps.\n *\n * Each step's `id` (falling back to its array index) and its `dependsOn`\n * become an adjacency list. A `dependsOn` that names a step not in the\n * plan, or any dependency cycle, raises a typed\n * {@link PlannerPlanInvalidError} BEFORE any step runs — the same error\n * class `generatePlan` uses for an unusable plan, with forensic context.\n *\n * @throws PlannerPlanInvalidError on a duplicate id, an unknown\n * `dependsOn` target, or a cycle.\n */\nexport function buildDag(steps: PlannerStep[], plannerName = \"planner\"): PlannerDag {\n const nodes: DagNode[] = [];\n const byId = new Map<string, DagNode>();\n\n // Pass 1 — assign every step a stable id (own id or array index) and\n // index the nodes. Duplicate explicit ids are a malformed plan.\n for (let index = 0; index < steps.length; index++) {\n const step = steps[index] as PlannerStep;\n const id = step.id ?? String(index);\n\n if (byId.has(id)) {\n throw new PlannerPlanInvalidError(\n `ai.planner(\"${plannerName}\"): duplicate step id \"${id}\" in DAG plan`,\n { context: { id } },\n );\n }\n\n const node: DagNode = { id, index, step, dependencies: [] };\n nodes.push(node);\n byId.set(id, node);\n }\n\n // Pass 2 — resolve dependencies against the id set; reject unknowns,\n // dedupe, and drop self-references (a no-op edge, never a cycle).\n const dependents = new Map<string, string[]>();\n\n for (const node of nodes) {\n const seen = new Set<string>();\n\n for (const dependency of node.step.dependsOn ?? []) {\n if (dependency === node.id) {\n continue;\n }\n\n if (!byId.has(dependency)) {\n throw new PlannerPlanInvalidError(\n `ai.planner(\"${plannerName}\"): step \"${node.id}\" depends on unknown step \"${dependency}\"`,\n { context: { id: node.id, dependency } },\n );\n }\n\n if (seen.has(dependency)) {\n continue;\n }\n\n seen.add(dependency);\n node.dependencies.push(dependency);\n\n const reverse = dependents.get(dependency) ?? [];\n reverse.push(node.id);\n dependents.set(dependency, reverse);\n }\n }\n\n assertAcyclic(nodes, byId, plannerName);\n\n return { nodes, byId, dependents };\n}\n\n/**\n * Compute the next ready set: nodes not yet done whose every dependency\n * is in `completed`. Preserves original plan order so a level dispatches\n * deterministically. A node whose dependency is `unreachable` (a failed\n * or skipped ancestor) is NOT ready — it never becomes ready and is\n * recorded skipped by the caller.\n */\nexport function readyNodes(\n dag: PlannerDag,\n completed: ReadonlySet<string>,\n done: ReadonlySet<string>,\n): DagNode[] {\n return dag.nodes.filter(\n (node) =>\n !done.has(node.id) &&\n node.dependencies.every((dependency) => completed.has(dependency)),\n );\n}\n\n/**\n * The topological sink(s) — nodes nothing depends on. Used to define the\n * \"final output\" under parallelism: with an `output` schema set, a\n * single sink is the unambiguous final step; multiple sinks are a\n * convergence error the caller surfaces.\n */\nexport function sinkNodes(dag: PlannerDag): DagNode[] {\n return dag.nodes.filter((node) => (dag.dependents.get(node.id) ?? []).length === 0);\n}\n\n/**\n * Depth-first cycle detection over the dependency edges. A back-edge to\n * a node on the current recursion stack means a cycle — raised as a\n * typed {@link PlannerPlanInvalidError} naming the offending node.\n */\nfunction assertAcyclic(\n nodes: DagNode[],\n byId: Map<string, DagNode>,\n plannerName: string,\n): void {\n const VISITING = 1;\n const DONE = 2;\n const state = new Map<string, number>();\n\n const visit = (node: DagNode): void => {\n const current = state.get(node.id);\n\n if (current === DONE) {\n return;\n }\n\n if (current === VISITING) {\n throw new PlannerPlanInvalidError(\n `ai.planner(\"${plannerName}\"): dependency cycle detected at step \"${node.id}\"`,\n { context: { id: node.id } },\n );\n }\n\n state.set(node.id, VISITING);\n\n for (const dependency of node.dependencies) {\n visit(byId.get(dependency) as DagNode);\n }\n\n state.set(node.id, DONE);\n };\n\n for (const node of nodes) {\n visit(node);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,SAAgB,SAAS,OAAsB,cAAc,WAAuB;CAClF,MAAM,QAAmB,CAAC;CAC1B,MAAM,uBAAO,IAAI,IAAqB;CAItC,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,OAAO,MAAM;EACnB,MAAM,KAAK,KAAK,MAAM,OAAO,KAAK;EAElC,IAAI,KAAK,IAAI,EAAE,GACb,MAAM,IAAI,wBACR,eAAe,YAAY,yBAAyB,GAAG,gBACvD,EAAE,SAAS,EAAE,GAAG,EAAE,CACpB;EAGF,MAAM,OAAgB;GAAE;GAAI;GAAO;GAAM,cAAc,CAAC;EAAE;EAC1D,MAAM,KAAK,IAAI;EACf,KAAK,IAAI,IAAI,IAAI;CACnB;CAIA,MAAM,6BAAa,IAAI,IAAsB;CAE7C,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,uBAAO,IAAI,IAAY;EAE7B,KAAK,MAAM,cAAc,KAAK,KAAK,aAAa,CAAC,GAAG;GAClD,IAAI,eAAe,KAAK,IACtB;GAGF,IAAI,CAAC,KAAK,IAAI,UAAU,GACtB,MAAM,IAAI,wBACR,eAAe,YAAY,YAAY,KAAK,GAAG,6BAA6B,WAAW,IACvF,EAAE,SAAS;IAAE,IAAI,KAAK;IAAI;GAAW,EAAE,CACzC;GAGF,IAAI,KAAK,IAAI,UAAU,GACrB;GAGF,KAAK,IAAI,UAAU;GACnB,KAAK,aAAa,KAAK,UAAU;GAEjC,MAAM,UAAU,WAAW,IAAI,UAAU,KAAK,CAAC;GAC/C,QAAQ,KAAK,KAAK,EAAE;GACpB,WAAW,IAAI,YAAY,OAAO;EACpC;CACF;CAEA,cAAc,OAAO,MAAM,WAAW;CAEtC,OAAO;EAAE;EAAO;EAAM;CAAW;AACnC;;;;;;;;AASA,SAAgB,WACd,KACA,WACA,MACW;CACX,OAAO,IAAI,MAAM,QACd,SACC,CAAC,KAAK,IAAI,KAAK,EAAE,KACjB,KAAK,aAAa,OAAO,eAAe,UAAU,IAAI,UAAU,CAAC,CACrE;AACF;;;;;;;AAQA,SAAgB,UAAU,KAA4B;CACpD,OAAO,IAAI,MAAM,QAAQ,UAAU,IAAI,WAAW,IAAI,KAAK,EAAE,KAAK,CAAC,EAAC,CAAE,WAAW,CAAC;AACpF;;;;;;AAOA,SAAS,cACP,OACA,MACA,aACM;CACN,MAAM,WAAW;CACjB,MAAM,OAAO;CACb,MAAM,wBAAQ,IAAI,IAAoB;CAEtC,MAAM,SAAS,SAAwB;EACrC,MAAM,UAAU,MAAM,IAAI,KAAK,EAAE;EAEjC,IAAI,YAAY,MACd;EAGF,IAAI,YAAY,UACd,MAAM,IAAI,wBACR,eAAe,YAAY,yCAAyC,KAAK,GAAG,IAC5E,EAAE,SAAS,EAAE,IAAI,KAAK,GAAG,EAAE,CAC7B;EAGF,MAAM,IAAI,KAAK,IAAI,QAAQ;EAE3B,KAAK,MAAM,cAAc,KAAK,cAC5B,MAAM,KAAK,IAAI,UAAU,CAAY;EAGvC,MAAM,IAAI,KAAK,IAAI,IAAI;CACzB;CAEA,KAAK,MAAM,QAAQ,OACjB,MAAM,IAAI;AAEd"}
@@ -11,7 +11,7 @@ import { PlannerCapability } from "../contracts/planner/planner-capability.type.
11
11
  * planner's lifetime) — the produced string is baked onto the internal
12
12
  * planning agent.
13
13
  */
14
- declare function buildPlanSystemPrompt(capabilities: PlannerCapability[], maxSteps: number, prefix: SystemPromptContract | string | undefined): string;
14
+ declare function buildPlanSystemPrompt(capabilities: PlannerCapability[], maxSteps: number, prefix: SystemPromptContract | string | undefined, dag?: boolean): string;
15
15
  //#endregion
16
16
  export { buildPlanSystemPrompt };
17
17
  //# sourceMappingURL=plan-prompt.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plan-prompt.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,qBAAA,CACd,YAAA,EAAc,iBAAA,IACd,QAAA,UACA,MAAA,EAAQ,oBAAoB"}
1
+ {"version":3,"file":"plan-prompt.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,qBAAA,CACd,YAAA,EAAc,iBAAA,IACd,QAAA,UACA,MAAA,EAAQ,oBAAoB,uBAC5B,GAAA"}
@@ -8,12 +8,13 @@
8
8
  * planner's lifetime) — the produced string is baked onto the internal
9
9
  * planning agent.
10
10
  */
11
- function buildPlanSystemPrompt(capabilities, maxSteps, prefix) {
11
+ function buildPlanSystemPrompt(capabilities, maxSteps, prefix, dag = false) {
12
12
  const capabilityLines = capabilities.map((capability) => `- ${capability.name}: ${capability.description}`);
13
13
  const sections = [];
14
14
  const resolvedPrefix = resolvePrefix(prefix);
15
15
  if (resolvedPrefix && resolvedPrefix.trim().length > 0) sections.push(resolvedPrefix.trim(), "");
16
16
  sections.push("You are a planner. Break the user's goal into an ordered sequence of steps,", "each one dispatching exactly one of the available capabilities below.", "", "Available capabilities:", ...capabilityLines, "", "Rules:", `- Produce at most ${maxSteps} steps.`, "- Each step's `capability` must be exactly one name from the list above.", "- Each step's `input` is the concrete instruction passed to that capability.", "- Order the steps so each builds on the outputs of the ones before it.", "- Never invent a capability name that is not listed.", "- Keep the plan minimal — only the steps actually needed to satisfy the goal.");
17
+ if (dag) sections.push("- Give each step a stable `id` and list the ids it builds on in `dependsOn`.", "- Steps with no `dependsOn` between them run in PARALLEL — only add a", " dependency when a step genuinely needs an earlier step's output.", "- The plan must converge: avoid dependency cycles.");
17
18
  return sections.join("\n");
18
19
  }
19
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"plan-prompt.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"sourcesContent":["import type { PlannerCapability } from \"../contracts/planner/planner-capability.type\";\nimport type { SystemPromptContract } from \"../contracts/system-prompt.contract\";\n\n/**\n * Assemble the plan-generation system prompt: optional caller framing on\n * top, then the mechanical block listing every capability + its\n * description and the rules for emitting an ordered plan.\n *\n * Runs once at factory time (the capability set is fixed for the\n * planner's lifetime) — the produced string is baked onto the internal\n * planning agent.\n */\nexport function buildPlanSystemPrompt(\n capabilities: PlannerCapability[],\n maxSteps: number,\n prefix: SystemPromptContract | string | undefined,\n): string {\n const capabilityLines = capabilities.map(\n (capability) => `- ${capability.name}: ${capability.description}`,\n );\n\n const sections: string[] = [];\n const resolvedPrefix = resolvePrefix(prefix);\n\n if (resolvedPrefix && resolvedPrefix.trim().length > 0) {\n sections.push(resolvedPrefix.trim(), \"\");\n }\n\n sections.push(\n \"You are a planner. Break the user's goal into an ordered sequence of steps,\",\n \"each one dispatching exactly one of the available capabilities below.\",\n \"\",\n \"Available capabilities:\",\n ...capabilityLines,\n \"\",\n \"Rules:\",\n `- Produce at most ${maxSteps} steps.`,\n \"- Each step's `capability` must be exactly one name from the list above.\",\n \"- Each step's `input` is the concrete instruction passed to that capability.\",\n \"- Order the steps so each builds on the outputs of the ones before it.\",\n \"- Never invent a capability name that is not listed.\",\n \"- Keep the plan minimal — only the steps actually needed to satisfy the goal.\",\n );\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Resolve a caller-supplied `systemPrompt` (string or contract) to plain\n * text. Returns `undefined` when none was supplied.\n */\nfunction resolvePrefix(prompt: SystemPromptContract | string | undefined): string | undefined {\n if (!prompt) {\n return undefined;\n }\n\n return typeof prompt === \"string\" ? prompt : prompt.resolve();\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,sBACd,cACA,UACA,QACQ;CACR,MAAM,kBAAkB,aAAa,KAClC,eAAe,KAAK,WAAW,KAAK,IAAI,WAAW,aACtD;CAEA,MAAM,WAAqB,CAAC;CAC5B,MAAM,iBAAiB,cAAc,MAAM;CAE3C,IAAI,kBAAkB,eAAe,KAAK,CAAC,CAAC,SAAS,GACnD,SAAS,KAAK,eAAe,KAAK,GAAG,EAAE;CAGzC,SAAS,KACP,+EACA,yEACA,IACA,2BACA,GAAG,iBACH,IACA,UACA,qBAAqB,SAAS,UAC9B,4EACA,gFACA,0EACA,wDACA,+EACF;CAEA,OAAO,SAAS,KAAK,IAAI;AAC3B;;;;;AAMA,SAAS,cAAc,QAAuE;CAC5F,IAAI,CAAC,QACH;CAGF,OAAO,OAAO,WAAW,WAAW,SAAS,OAAO,QAAQ;AAC9D"}
1
+ {"version":3,"file":"plan-prompt.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"sourcesContent":["import type { PlannerCapability } from \"../contracts/planner/planner-capability.type\";\nimport type { SystemPromptContract } from \"../contracts/system-prompt.contract\";\n\n/**\n * Assemble the plan-generation system prompt: optional caller framing on\n * top, then the mechanical block listing every capability + its\n * description and the rules for emitting an ordered plan.\n *\n * Runs once at factory time (the capability set is fixed for the\n * planner's lifetime) — the produced string is baked onto the internal\n * planning agent.\n */\nexport function buildPlanSystemPrompt(\n capabilities: PlannerCapability[],\n maxSteps: number,\n prefix: SystemPromptContract | string | undefined,\n dag = false,\n): string {\n const capabilityLines = capabilities.map(\n (capability) => `- ${capability.name}: ${capability.description}`,\n );\n\n const sections: string[] = [];\n const resolvedPrefix = resolvePrefix(prefix);\n\n if (resolvedPrefix && resolvedPrefix.trim().length > 0) {\n sections.push(resolvedPrefix.trim(), \"\");\n }\n\n sections.push(\n \"You are a planner. Break the user's goal into an ordered sequence of steps,\",\n \"each one dispatching exactly one of the available capabilities below.\",\n \"\",\n \"Available capabilities:\",\n ...capabilityLines,\n \"\",\n \"Rules:\",\n `- Produce at most ${maxSteps} steps.`,\n \"- Each step's `capability` must be exactly one name from the list above.\",\n \"- Each step's `input` is the concrete instruction passed to that capability.\",\n \"- Order the steps so each builds on the outputs of the ones before it.\",\n \"- Never invent a capability name that is not listed.\",\n \"- Keep the plan minimal — only the steps actually needed to satisfy the goal.\",\n );\n\n if (dag) {\n // DAG mode — the runtime schedules independent steps in parallel off\n // `dependsOn`, so the model should declare dependencies explicitly\n // rather than relying purely on array order.\n sections.push(\n \"- Give each step a stable `id` and list the ids it builds on in `dependsOn`.\",\n \"- Steps with no `dependsOn` between them run in PARALLEL — only add a\",\n \" dependency when a step genuinely needs an earlier step's output.\",\n \"- The plan must converge: avoid dependency cycles.\",\n );\n }\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Resolve a caller-supplied `systemPrompt` (string or contract) to plain\n * text. Returns `undefined` when none was supplied.\n */\nfunction resolvePrefix(prompt: SystemPromptContract | string | undefined): string | undefined {\n if (!prompt) {\n return undefined;\n }\n\n return typeof prompt === \"string\" ? prompt : prompt.resolve();\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,sBACd,cACA,UACA,QACA,MAAM,OACE;CACR,MAAM,kBAAkB,aAAa,KAClC,eAAe,KAAK,WAAW,KAAK,IAAI,WAAW,aACtD;CAEA,MAAM,WAAqB,CAAC;CAC5B,MAAM,iBAAiB,cAAc,MAAM;CAE3C,IAAI,kBAAkB,eAAe,KAAK,CAAC,CAAC,SAAS,GACnD,SAAS,KAAK,eAAe,KAAK,GAAG,EAAE;CAGzC,SAAS,KACP,+EACA,yEACA,IACA,2BACA,GAAG,iBACH,IACA,UACA,qBAAqB,SAAS,UAC9B,4EACA,gFACA,0EACA,wDACA,+EACF;CAEA,IAAI,KAIF,SAAS,KACP,gFACA,yEACA,sEACA,oDACF;CAGF,OAAO,SAAS,KAAK,IAAI;AAC3B;;;;;AAMA,SAAS,cAAc,QAAuE;CAC5F,IAAI,CAAC,QACH;CAGF,OAAO,OAAO,WAAW,WAAW,SAAS,OAAO,QAAQ;AAC9D"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner-run.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/planner-run.ts"],"mappings":";;;;;;;AA8BA;;;;KAAY,cAAA;EACV,MAAA,EAAQ,aAAA,CAAc,OAAA;EACtB,YAAA,EAAc,GAAA,SAAY,iBAAA;EAC1B,QAAA;EACA,SAAA;EACA,aAAA,EAAe,aAAA;EACf,IAAA;EACA,OAAA,GAAU,qBAAA,CAAsB,OAAA;AAAA"}
1
+ {"version":3,"file":"planner-run.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/planner-run.ts"],"mappings":";;;;;;;AAqCA;;;;KAAY,cAAA;EACV,MAAA,EAAQ,aAAA,CAAc,OAAA;EACtB,YAAA,EAAc,GAAA,SAAY,iBAAA;EAC1B,QAAA;EACA,SAAA;EACA,aAAA,EAAe,aAAA;EACf,IAAA;EACA,OAAA,GAAU,qBAAA,CAAsB,OAAA;AAAA"}
@@ -5,8 +5,11 @@ 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";
11
14
 
12
15
  //#region ../@warlock.js/ai/src/planner/planner-run.ts
@@ -40,6 +43,8 @@ var PlannerRun = class {
40
43
  };
41
44
  this.children = [];
42
45
  this.executedSteps = [];
46
+ this.awaitingApproval = false;
47
+ this.replanCount = 0;
43
48
  this.runId = args.options?.runId ?? generateRunId("planner");
44
49
  }
45
50
  /**
@@ -49,14 +54,31 @@ var PlannerRun = class {
49
54
  * `report.status`.
50
55
  */
51
56
  async run() {
57
+ const result = await this.runPlan();
58
+ await notifyObservers(this.args.config.observe, result.report);
59
+ captureChildReport(result.report);
60
+ return result;
61
+ }
62
+ /**
63
+ * Drive the planner lifecycle and return the built result WITHOUT
64
+ * routing it — `run()` owns observer routing + auto-nesting so the
65
+ * unified tree is emitted exactly once.
66
+ */
67
+ async runPlan() {
52
68
  try {
53
69
  if (this.isAborted()) {
54
70
  this.markCancelled();
55
71
  return this.buildResult();
56
72
  }
57
- const plan = await this.generatePlan();
73
+ const plan = this.args.options?.approvedPlan ?? await this.generatePlan();
58
74
  if (this.error || !plan) return this.buildResult();
75
+ this.assertPlanValid(plan);
76
+ if (this.error) return this.buildResult();
59
77
  this.plan = plan;
78
+ if (this.args.options?.mode === "plan-only" && !this.args.options?.approvedPlan) {
79
+ this.awaitingApproval = true;
80
+ return this.buildResult();
81
+ }
60
82
  await this.executePlan(plan);
61
83
  await this.finalizeOutput();
62
84
  } catch (caught) {
@@ -70,15 +92,19 @@ var PlannerRun = class {
70
92
  * agent's per-call `output`, so the model is steered to reference only
71
93
  * real capabilities. The planning trip's usage + report roll into the
72
94
  * planner's totals regardless of outcome.
95
+ *
96
+ * `feedback` is set only on a RE-plan: the regenerated request is
97
+ * seeded with the executed-step digest plus the caller's feedback so
98
+ * the planner revises the remaining work rather than starting cold.
73
99
  */
74
- async generatePlan() {
100
+ async generatePlan(feedback) {
75
101
  const schema = planSchema([...this.args.capabilities.keys()], this.args.maxSteps);
76
- const result = await this.args.planningAgent.execute(this.buildPlanPrompt(), {
102
+ const result = await withoutRunFrame(() => this.args.planningAgent.execute(this.buildPlanPrompt(feedback), {
77
103
  output: schema,
78
104
  placeholders: this.args.options?.placeholders,
79
105
  signal: this.args.options?.signal,
80
106
  sessionId: this.args.options?.sessionId
81
- });
107
+ }));
82
108
  this.absorb(result.usage, result.report);
83
109
  if (result.error) {
84
110
  this.error = result.error instanceof SchemaValidationError ? new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, {
@@ -92,43 +118,174 @@ var PlannerRun = class {
92
118
  this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
93
119
  return;
94
120
  }
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
- } });
121
+ this.assertPlanValid(plan);
122
+ if (this.error) return;
123
+ return plan;
124
+ }
125
+ /**
126
+ * Shared plan-validity guard — used both for a freshly generated plan
127
+ * and for a caller-supplied `approvedPlan`. Sets `this.error` to a
128
+ * typed {@link PlannerPlanInvalidError} when the plan is empty or names
129
+ * an unknown capability; a stale `approvedPlan` thus fails the same way
130
+ * a hallucinated capability does, never silently mis-dispatching.
131
+ */
132
+ assertPlanValid(plan) {
133
+ if (!Array.isArray(plan.steps) || plan.steps.length === 0) {
134
+ this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
101
135
  return;
102
136
  }
103
- return plan;
137
+ const unknownStep = plan.steps.find((step) => !this.args.capabilities.has(step.capability));
138
+ if (unknownStep) this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): plan references unknown capability "${unknownStep.capability}"`, { context: {
139
+ runId: this.runId,
140
+ capability: unknownStep.capability
141
+ } });
104
142
  }
105
143
  /**
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.
144
+ * Phase 2 — execute the plan. Branches on `config.dag`: the default is
145
+ * the strict array-order sequential loop (byte-for-byte today's
146
+ * behavior when neither `onStep` nor `replan` is configured); `dag:
147
+ * true` schedules independent `dependsOn` branches in parallel.
111
148
  */
112
149
  async executePlan(plan) {
150
+ if (this.args.config.dag) return this.executeDag(plan);
151
+ return this.executeSequential(plan);
152
+ }
153
+ /**
154
+ * Sequential executor — the original strict array-order loop, threading
155
+ * each completed step's output into the next step's input context.
156
+ * Stops at the first step failure or when the abort signal fires
157
+ * between steps; steps beyond `maxSteps` are recorded `skipped`.
158
+ *
159
+ * **Additive hooks (inert by default).** After each step settles it
160
+ * fires the `onStep` directive hook; an `abort` directive stops the run
161
+ * like a failure, and a `replan` directive (or, when `config.replan` is
162
+ * set, an unhandled failure) regenerates the REMAINING plan instead of
163
+ * aborting. With no `onStep` and no `replan`, the behavior is identical
164
+ * to before.
165
+ */
166
+ async executeSequential(plan) {
113
167
  const previousOutputs = [];
114
- for (let index = 0; index < plan.steps.length; index++) {
115
- const step = plan.steps[index];
168
+ let steps = plan.steps;
169
+ let index = 0;
170
+ while (index < steps.length) {
171
+ const step = steps[index];
116
172
  if (index >= this.args.maxSteps) {
117
173
  this.recordSkipped(index, step);
174
+ index++;
118
175
  continue;
119
176
  }
120
177
  if (this.isAborted()) {
121
178
  this.markCancelled();
122
179
  this.recordSkipped(index, step);
180
+ index++;
181
+ continue;
182
+ }
183
+ const completed = await this.executeStep(index, step, previousOutputs);
184
+ const snapshot = this.snapshotFor(index);
185
+ const directive = snapshot ? await this.resolveDirective(snapshot, plan, completed) : void 0;
186
+ if (directive?.type === "replan") {
187
+ const remaining = await this.regeneratePlan(directive.feedback);
188
+ if (this.error || !remaining) {
189
+ this.skipRest(steps, index + 1);
190
+ return;
191
+ }
192
+ steps = remaining.steps;
193
+ index = 0;
194
+ previousOutputs.length = 0;
195
+ previousOutputs.push(...this.executedDigest());
123
196
  continue;
124
197
  }
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]);
198
+ if (directive?.type === "abort") {
199
+ this.skipRest(steps, index + 1);
127
200
  return;
128
201
  }
202
+ index++;
129
203
  }
130
204
  }
131
205
  /**
206
+ * DAG executor — schedule independent `dependsOn` branches in parallel.
207
+ *
208
+ * Builds the DAG (cycle / unknown-id → `PlannerPlanInvalidError`),
209
+ * then repeatedly computes the ready set (steps whose deps all
210
+ * completed), dispatches up to `maxConcurrency` of them with
211
+ * `Promise.all`, and feeds each step ONLY its dependencies' outputs. A
212
+ * failed step blocks just its descendants (recorded `skipped`);
213
+ * independent branches still settle. With an `output` schema set, the
214
+ * final `data` is the topological SINK's output (multiple sinks → a
215
+ * convergence error).
216
+ */
217
+ async executeDag(plan) {
218
+ const dag = buildDag(plan.steps, this.args.config.name);
219
+ const maxConcurrency = Math.max(1, this.args.config.maxConcurrency ?? 4);
220
+ const completed = /* @__PURE__ */ new Set();
221
+ const done = /* @__PURE__ */ new Set();
222
+ const outputs = /* @__PURE__ */ new Map();
223
+ const rawOutputs = /* @__PURE__ */ new Map();
224
+ let executedCount = 0;
225
+ while (done.size < dag.nodes.length) {
226
+ if (this.isAborted()) {
227
+ this.markCancelled();
228
+ this.skipDagRest(dag, done);
229
+ return;
230
+ }
231
+ const ready = readyNodes(dag, completed, done);
232
+ if (ready.length === 0) {
233
+ this.skipDagRest(dag, done);
234
+ return;
235
+ }
236
+ const batch = ready.slice(0, maxConcurrency);
237
+ const settled = await Promise.all(batch.map(async (node) => {
238
+ if (executedCount >= this.args.maxSteps) {
239
+ this.recordSkipped(node.index, node.step);
240
+ return {
241
+ node,
242
+ ran: false,
243
+ completed: false
244
+ };
245
+ }
246
+ executedCount++;
247
+ const previousOutputs = node.dependencies.map((dependency) => outputs.get(dependency));
248
+ const stepCompleted = await this.executeStep(node.index, node.step, previousOutputs);
249
+ if (stepCompleted) {
250
+ const rawOutput = this.snapshotFor(node.index)?.output;
251
+ rawOutputs.set(node.id, rawOutput);
252
+ outputs.set(node.id, this.stringifyOutput(node.step.capability, rawOutput));
253
+ }
254
+ return {
255
+ node,
256
+ ran: true,
257
+ completed: stepCompleted
258
+ };
259
+ }));
260
+ for (const entry of settled) {
261
+ done.add(entry.node.id);
262
+ if (entry.completed) completed.add(entry.node.id);
263
+ }
264
+ let replanFeedback;
265
+ let shouldAbort = false;
266
+ for (const entry of settled) {
267
+ if (!entry.ran) continue;
268
+ const snapshot = this.snapshotFor(entry.node.index);
269
+ const directive = snapshot ? await this.resolveDirective(snapshot, plan, entry.completed) : void 0;
270
+ if (directive?.type === "replan") replanFeedback = directive.feedback;
271
+ else if (directive?.type === "abort") shouldAbort = true;
272
+ }
273
+ if (shouldAbort) {
274
+ this.skipDagRest(dag, done);
275
+ return;
276
+ }
277
+ if (replanFeedback !== void 0) {
278
+ const remaining = await this.regeneratePlan(replanFeedback);
279
+ if (this.error || !remaining) {
280
+ this.skipDagRest(dag, done);
281
+ return;
282
+ }
283
+ return this.executeDag(remaining);
284
+ }
285
+ }
286
+ this.finalizeDagOutput(dag, completed, rawOutputs);
287
+ }
288
+ /**
132
289
  * Dispatch one plan step through its capability's `executable.execute()`
133
290
  * and fold the outcome into the accumulators. Returns `true` when the
134
291
  * step completed, `false` when it failed (setting the run error).
@@ -138,10 +295,10 @@ var PlannerRun = class {
138
295
  const stepStart = performance.now();
139
296
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
140
297
  const input = this.composeStepInput(step, previousOutputs);
141
- const result = await capability.executable.execute(input, {
298
+ const result = await withoutRunFrame(() => capability.executable.execute(input, {
142
299
  signal: this.args.options?.signal,
143
300
  sessionId: this.args.options?.sessionId
144
- });
301
+ }));
145
302
  const childReport = "report" in result ? result.report : void 0;
146
303
  this.absorb(result.usage, childReport);
147
304
  const output = this.extractOutput(result);
@@ -167,6 +324,104 @@ var PlannerRun = class {
167
324
  return true;
168
325
  }
169
326
  /**
327
+ * Resolve the steering directive for a just-settled step, shared by the
328
+ * sequential and DAG executors. Fires the user's `onStep` hook, then
329
+ * normalizes the result against the `replan` budget:
330
+ *
331
+ * - explicit `replan` directive — honored only when `config.replan` is
332
+ * set and the budget remains; otherwise downgraded to `continue`.
333
+ * - explicit `abort` — honored.
334
+ * - failed step with no overriding directive — auto-`replan` when
335
+ * `config.replan` is set and the budget remains (feedback = the step
336
+ * error message), else `abort` (today's abort-on-first-failure).
337
+ *
338
+ * Returns `undefined` when the run should simply continue. A returned
339
+ * `replan` directive has ALREADY consumed one unit of the replan budget.
340
+ */
341
+ async resolveDirective(snapshot, plan, completed) {
342
+ const hook = this.args.options?.onStep;
343
+ const userDirective = hook ? await hook(snapshot, plan) : void 0;
344
+ if (userDirective?.type === "replan") {
345
+ if (this.canReplan()) {
346
+ this.replanCount++;
347
+ return userDirective;
348
+ }
349
+ } else if (userDirective?.type === "abort") return { type: "abort" };
350
+ else if (userDirective?.type === "continue") return;
351
+ if (!completed) {
352
+ if (this.canReplan()) {
353
+ this.replanCount++;
354
+ return {
355
+ type: "replan",
356
+ feedback: snapshot.error?.message ?? "step failed"
357
+ };
358
+ }
359
+ return { type: "abort" };
360
+ }
361
+ }
362
+ /** Whether a re-plan is configured and the budget has room. */
363
+ canReplan() {
364
+ const replan = this.args.config.replan;
365
+ return replan !== void 0 && this.replanCount < replan.maxReplans;
366
+ }
367
+ /**
368
+ * Re-ask the planning agent for a plan over the REMAINING work — a
369
+ * second `generatePlan()` seeded with the executed-step digest plus the
370
+ * caller's feedback. Reuses the exact `generatePlan` plumbing (same
371
+ * schema, same `PlannerPlanInvalidError` handling), so a regenerated
372
+ * plan that is empty or names an unknown capability fails identically.
373
+ * The failed step's error is cleared so the regenerated plan runs
374
+ * cleanly; a fresh failure (or exhausted budget) re-sets it.
375
+ */
376
+ async regeneratePlan(feedback) {
377
+ this.error = void 0;
378
+ return this.generatePlan(feedback);
379
+ }
380
+ /**
381
+ * The executed-so-far digest — one context line per completed step, in
382
+ * execution order. Seeds the regenerated plan's first step so it builds
383
+ * on what already ran.
384
+ */
385
+ executedDigest() {
386
+ return this.executedSteps.filter((snapshot) => snapshot.status === "completed").map((snapshot) => this.stringifyOutput(snapshot.step.capability, snapshot.output));
387
+ }
388
+ /** The last-pushed snapshot for a given step index, if any. */
389
+ snapshotFor(index) {
390
+ for (let position = this.executedSteps.length - 1; position >= 0; position--) {
391
+ const snapshot = this.executedSteps[position];
392
+ if (snapshot.index === index) return snapshot;
393
+ }
394
+ }
395
+ /** Record every step from `from` onward (in a flat array plan) as skipped. */
396
+ skipRest(steps, from) {
397
+ for (let rest = from; rest < steps.length; rest++) this.recordSkipped(rest, steps[rest]);
398
+ }
399
+ /** Record every not-yet-`done` DAG node as skipped, in plan order. */
400
+ skipDagRest(dag, done) {
401
+ for (const node of dag.nodes) if (!done.has(node.id)) this.recordSkipped(node.index, node.step);
402
+ }
403
+ /**
404
+ * Set `this.data` from the DAG's topological sink for a configured
405
+ * `output` schema. "Last completed step" is meaningless under
406
+ * parallelism, so the sink (the step nothing depends on) is the
407
+ * unambiguous final output. Multiple sinks while an `output` schema is
408
+ * set is a convergence error — a typed `PlannerPlanInvalidError`.
409
+ */
410
+ finalizeDagOutput(dag, completed, rawOutputs) {
411
+ if (!(this.args.options?.output ?? this.args.config.output) || this.error) return;
412
+ const sinks = sinkNodes(dag).filter((node) => completed.has(node.id));
413
+ if (sinks.length > 1) {
414
+ 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: {
415
+ runId: this.runId,
416
+ sinks: sinks.map((node) => node.id)
417
+ } });
418
+ this.data = void 0;
419
+ return;
420
+ }
421
+ const sink = sinks[0];
422
+ this.data = sink ? rawOutputs.get(sink.id) : void 0;
423
+ }
424
+ /**
170
425
  * Phase 3 — when an `output` schema is configured (factory or per-call
171
426
  * override), validate the final completed step's output into typed
172
427
  * `result.data`. A validation failure replaces the run error and flips
@@ -205,6 +460,7 @@ var PlannerRun = class {
205
460
  version: this.args.config.version,
206
461
  type: "planner",
207
462
  status,
463
+ ...this.error ? { error: this.error } : {},
208
464
  startedAt: this.startedAt,
209
465
  endedAt: (/* @__PURE__ */ new Date()).toISOString(),
210
466
  duration: performance.now() - this.startPerf,
@@ -220,27 +476,42 @@ var PlannerRun = class {
220
476
  rootRunId: this.runId,
221
477
  sessionId: this.args.options?.sessionId
222
478
  });
223
- return {
479
+ const result = {
224
480
  type: "planner",
225
481
  data: this.error ? void 0 : this.data,
226
482
  error: this.error,
227
483
  usage: this.usage,
228
484
  report
229
485
  };
486
+ if (this.awaitingApproval) result.plan = this.plan;
487
+ return result;
230
488
  }
231
489
  /**
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.
490
+ * Resolve the terminal status from the accumulated outcome.
491
+ * `awaiting-approval` (plan-only short-circuit) wins over everything
492
+ * nothing executed, so neither cancellation nor error applies.
493
+ * Otherwise cancelled wins over failed (an abort that also produced a
494
+ * step error still reads as cancelled); failed wins over completed.
235
495
  */
236
496
  resolveStatus() {
497
+ if (this.awaitingApproval) return "awaiting-approval";
237
498
  if (this.cancelledAt !== void 0) return "cancelled";
238
499
  if (this.error) return "failed";
239
500
  return "completed";
240
501
  }
241
- /** Build the prompt handed to the planning agent — the user's goal. */
242
- buildPlanPrompt() {
243
- return this.args.goal;
502
+ /**
503
+ * Build the prompt handed to the planning agent. On the first pass this
504
+ * is just the user's goal (byte-for-byte unchanged). On a RE-plan it
505
+ * prepends the executed-step digest and the steering feedback so the
506
+ * planner revises the remaining work.
507
+ */
508
+ buildPlanPrompt(feedback) {
509
+ if (feedback === void 0) return this.args.goal;
510
+ const digest = this.executedDigest();
511
+ const sections = [`Goal: ${this.args.goal}`, ""];
512
+ if (digest.length > 0) sections.push("Steps already completed:", ...digest, "");
513
+ sections.push(`Feedback requiring a revised plan: ${feedback}`, "", "Produce a plan for the REMAINING work only.");
514
+ return sections.join("\n");
244
515
  }
245
516
  /**
246
517
  * Compose a step's effective input: the step's own `input`, prefixed