@warlock.js/ai 4.2.11 → 4.4.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 (432) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/cjs/index.cjs +10155 -4626
  3. package/cjs/index.cjs.map +1 -1
  4. package/cjs/magic-string.es-BtxW4VqG.cjs +1015 -0
  5. package/cjs/magic-string.es-BtxW4VqG.cjs.map +1 -0
  6. package/cjs/matcher-logic-SBnzYohQ.cjs +217 -0
  7. package/cjs/matcher-logic-SBnzYohQ.cjs.map +1 -0
  8. package/cjs/matchers-BBh3gyB-.cjs +13739 -0
  9. package/cjs/matchers-BBh3gyB-.cjs.map +1 -0
  10. package/esm/agent/agent-config.type.d.mts +19 -6
  11. package/esm/agent/agent-config.type.d.mts.map +1 -1
  12. package/esm/agent/agent.d.mts.map +1 -1
  13. package/esm/agent/agent.mjs +17 -6
  14. package/esm/agent/agent.mjs.map +1 -1
  15. package/esm/agent/index.d.mts +2 -1
  16. package/esm/agent/index.mjs +1 -0
  17. package/esm/agent/spawn-sub-agent.d.mts +87 -0
  18. package/esm/agent/spawn-sub-agent.d.mts.map +1 -0
  19. package/esm/agent/spawn-sub-agent.mjs +68 -0
  20. package/esm/agent/spawn-sub-agent.mjs.map +1 -0
  21. package/esm/ai.d.mts +58 -3
  22. package/esm/ai.d.mts.map +1 -1
  23. package/esm/ai.mjs +58 -3
  24. package/esm/ai.mjs.map +1 -1
  25. package/esm/batch/batch.d.mts +43 -0
  26. package/esm/batch/batch.d.mts.map +1 -0
  27. package/esm/batch/batch.mjs +179 -0
  28. package/esm/batch/batch.mjs.map +1 -0
  29. package/esm/batch/batch.type.d.mts +144 -0
  30. package/esm/batch/batch.type.d.mts.map +1 -0
  31. package/esm/batch/index.mjs +3 -0
  32. package/esm/batch/run-batch-item.mjs +100 -0
  33. package/esm/batch/run-batch-item.mjs.map +1 -0
  34. package/esm/batch/run-with-concurrency.mjs +39 -0
  35. package/esm/batch/run-with-concurrency.mjs.map +1 -0
  36. package/esm/checkpoint/index.d.mts +3 -0
  37. package/esm/checkpoint/memory.d.mts +21 -0
  38. package/esm/checkpoint/memory.d.mts.map +1 -0
  39. package/esm/checkpoint/memory.mjs +0 -0
  40. package/esm/checkpoint/memory.mjs.map +1 -0
  41. package/esm/checkpoint/pg.d.mts +37 -0
  42. package/esm/checkpoint/pg.d.mts.map +1 -0
  43. package/esm/checkpoint/pg.mjs +265 -0
  44. package/esm/checkpoint/pg.mjs.map +1 -0
  45. package/esm/checkpoint/redis.d.mts +39 -0
  46. package/esm/checkpoint/redis.d.mts.map +1 -0
  47. package/esm/checkpoint/redis.mjs +200 -0
  48. package/esm/checkpoint/redis.mjs.map +1 -0
  49. package/esm/config.d.mts +61 -14
  50. package/esm/config.d.mts.map +1 -1
  51. package/esm/config.mjs +25 -6
  52. package/esm/config.mjs.map +1 -1
  53. package/esm/contracts/agent/agent.contract.d.mts +43 -0
  54. package/esm/contracts/agent/agent.contract.d.mts.map +1 -1
  55. package/esm/contracts/agent/eval.type.d.mts +143 -0
  56. package/esm/contracts/agent/eval.type.d.mts.map +1 -0
  57. package/esm/contracts/agent/index.d.mts +1 -0
  58. package/esm/contracts/events/supervisor-events.type.d.mts +3 -3
  59. package/esm/contracts/fallback-model.contract.d.mts +65 -0
  60. package/esm/contracts/fallback-model.contract.d.mts.map +1 -0
  61. package/esm/contracts/index.d.mts +32 -12
  62. package/esm/contracts/memory/index.d.mts +4 -0
  63. package/esm/contracts/memory/memory-config.type.d.mts +150 -0
  64. package/esm/contracts/memory/memory-config.type.d.mts.map +1 -0
  65. package/esm/contracts/memory/memory-item.type.d.mts +64 -0
  66. package/esm/contracts/memory/memory-item.type.d.mts.map +1 -0
  67. package/esm/contracts/memory/memory.contract.d.mts +87 -0
  68. package/esm/contracts/memory/memory.contract.d.mts.map +1 -0
  69. package/esm/contracts/memory/recall-options.type.d.mts +33 -0
  70. package/esm/contracts/memory/recall-options.type.d.mts.map +1 -0
  71. package/esm/contracts/middleware/index.d.mts +2 -2
  72. package/esm/contracts/middleware/middleware-context.type.d.mts +42 -2
  73. package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -1
  74. package/esm/contracts/middleware/middleware.contract.d.mts +46 -2
  75. package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -1
  76. package/esm/contracts/model.contract.d.mts +63 -2
  77. package/esm/contracts/model.contract.d.mts.map +1 -1
  78. package/esm/contracts/orchestrator/checkpoint-store.contract.d.mts +91 -0
  79. package/esm/contracts/orchestrator/checkpoint-store.contract.d.mts.map +1 -0
  80. package/esm/contracts/orchestrator/index.d.mts +8 -0
  81. package/esm/contracts/orchestrator/orchestrator-commands.type.d.mts +43 -0
  82. package/esm/contracts/orchestrator/orchestrator-commands.type.d.mts.map +1 -0
  83. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +170 -0
  84. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -0
  85. package/esm/contracts/orchestrator/orchestrator-event.type.d.mts +118 -0
  86. package/esm/contracts/orchestrator/orchestrator-event.type.d.mts.map +1 -0
  87. package/esm/contracts/orchestrator/orchestrator-execute-options.type.d.mts +44 -0
  88. package/esm/contracts/orchestrator/orchestrator-execute-options.type.d.mts.map +1 -0
  89. package/esm/contracts/orchestrator/orchestrator.contract.d.mts +129 -0
  90. package/esm/contracts/orchestrator/orchestrator.contract.d.mts.map +1 -0
  91. package/esm/contracts/orchestrator/session.contract.d.mts +26 -0
  92. package/esm/contracts/orchestrator/session.contract.d.mts.map +1 -0
  93. package/esm/contracts/orchestrator/snapshot-store.contract.d.mts +89 -0
  94. package/esm/contracts/orchestrator/snapshot-store.contract.d.mts.map +1 -0
  95. package/esm/contracts/planner/index.d.mts +6 -0
  96. package/esm/contracts/planner/planner-capability.type.d.mts +39 -0
  97. package/esm/contracts/planner/planner-capability.type.d.mts.map +1 -0
  98. package/esm/contracts/planner/planner-config.type.d.mts +78 -0
  99. package/esm/contracts/planner/planner-config.type.d.mts.map +1 -0
  100. package/esm/contracts/planner/planner-execute-options.type.d.mts +43 -0
  101. package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -0
  102. package/esm/contracts/planner/planner-plan.type.d.mts +48 -0
  103. package/esm/contracts/planner/planner-plan.type.d.mts.map +1 -0
  104. package/esm/contracts/planner/planner-result.type.d.mts +88 -0
  105. package/esm/contracts/planner/planner-result.type.d.mts.map +1 -0
  106. package/esm/contracts/planner/planner.contract.d.mts +60 -0
  107. package/esm/contracts/planner/planner.contract.d.mts.map +1 -0
  108. package/esm/contracts/result/base-report.type.d.mts +7 -2
  109. package/esm/contracts/result/base-report.type.d.mts.map +1 -1
  110. package/esm/contracts/result/base-report.type.mjs.map +1 -1
  111. package/esm/contracts/result/index.d.mts +2 -1
  112. package/esm/contracts/result/model-pricing.type.d.mts +10 -0
  113. package/esm/contracts/result/model-pricing.type.d.mts.map +1 -1
  114. package/esm/contracts/result/orchestrator-result.type.d.mts +143 -0
  115. package/esm/contracts/result/orchestrator-result.type.d.mts.map +1 -0
  116. package/esm/contracts/result/session-send-result.type.d.mts +12 -3
  117. package/esm/contracts/result/session-send-result.type.d.mts.map +1 -1
  118. package/esm/contracts/result/supervisor-result.type.d.mts +2 -2
  119. package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
  120. package/esm/contracts/result/tool-call.type.d.mts +2 -2
  121. package/esm/contracts/result/tool-call.type.d.mts.map +1 -1
  122. package/esm/contracts/result/usage.type.d.mts +24 -0
  123. package/esm/contracts/result/usage.type.d.mts.map +1 -1
  124. package/esm/contracts/result/workflow-result.type.d.mts +1 -1
  125. package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
  126. package/esm/contracts/sdk-adapter.contract.d.mts +1 -1
  127. package/esm/contracts/supervisor/dispatch-context.type.d.mts +3 -3
  128. package/esm/contracts/supervisor/evaluate-context.type.d.mts +1 -1
  129. package/esm/contracts/supervisor/index.d.mts +5 -5
  130. package/esm/contracts/supervisor/route-context.type.d.mts +2 -2
  131. package/esm/contracts/supervisor/supervisor-config.type.d.mts +55 -13
  132. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
  133. package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +1 -1
  134. package/esm/contracts/supervisor/supervisor.contract.d.mts +9 -2
  135. package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -1
  136. package/esm/contracts/workflow/index.d.mts +2 -2
  137. package/esm/contracts/workflow/workflow.contract.d.mts +28 -7
  138. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
  139. package/esm/errors/error-code.type.d.mts +1 -1
  140. package/esm/errors/index.d.mts +7 -0
  141. package/esm/errors/index.mjs +7 -0
  142. package/esm/errors/orchestrator-cancelled-error.d.mts +32 -0
  143. package/esm/errors/orchestrator-cancelled-error.d.mts.map +1 -0
  144. package/esm/errors/orchestrator-cancelled-error.mjs +31 -0
  145. package/esm/errors/orchestrator-cancelled-error.mjs.map +1 -0
  146. package/esm/errors/orchestrator-config-error.d.mts +26 -0
  147. package/esm/errors/orchestrator-config-error.d.mts.map +1 -0
  148. package/esm/errors/orchestrator-config-error.mjs +30 -0
  149. package/esm/errors/orchestrator-config-error.mjs.map +1 -0
  150. package/esm/errors/orchestrator-drift-error.d.mts +38 -0
  151. package/esm/errors/orchestrator-drift-error.d.mts.map +1 -0
  152. package/esm/errors/orchestrator-drift-error.mjs +37 -0
  153. package/esm/errors/orchestrator-drift-error.mjs.map +1 -0
  154. package/esm/errors/orchestrator-failed-error.d.mts +33 -0
  155. package/esm/errors/orchestrator-failed-error.d.mts.map +1 -0
  156. package/esm/errors/orchestrator-failed-error.mjs +36 -0
  157. package/esm/errors/orchestrator-failed-error.mjs.map +1 -0
  158. package/esm/errors/planner-cancelled-error.d.mts +33 -0
  159. package/esm/errors/planner-cancelled-error.d.mts.map +1 -0
  160. package/esm/errors/planner-cancelled-error.mjs +29 -0
  161. package/esm/errors/planner-cancelled-error.mjs.map +1 -0
  162. package/esm/errors/planner-failed-error.d.mts +40 -0
  163. package/esm/errors/planner-failed-error.d.mts.map +1 -0
  164. package/esm/errors/planner-failed-error.mjs +37 -0
  165. package/esm/errors/planner-failed-error.mjs.map +1 -0
  166. package/esm/errors/planner-plan-invalid-error.d.mts +21 -0
  167. package/esm/errors/planner-plan-invalid-error.d.mts.map +1 -0
  168. package/esm/errors/planner-plan-invalid-error.mjs +25 -0
  169. package/esm/errors/planner-plan-invalid-error.mjs.map +1 -0
  170. package/esm/eval/eval-runner.d.mts +17 -0
  171. package/esm/eval/eval-runner.d.mts.map +1 -0
  172. package/esm/eval/eval-runner.mjs +121 -0
  173. package/esm/eval/eval-runner.mjs.map +1 -0
  174. package/esm/eval/index.d.mts +29 -0
  175. package/esm/eval/index.d.mts.map +1 -0
  176. package/esm/eval/index.mjs +30 -0
  177. package/esm/eval/index.mjs.map +1 -0
  178. package/esm/eval/judge-scorer.d.mts +21 -0
  179. package/esm/eval/judge-scorer.d.mts.map +1 -0
  180. package/esm/eval/judge-scorer.mjs +87 -0
  181. package/esm/eval/judge-scorer.mjs.map +1 -0
  182. package/esm/eval/scorers.d.mts +50 -0
  183. package/esm/eval/scorers.d.mts.map +1 -0
  184. package/esm/eval/scorers.mjs +101 -0
  185. package/esm/eval/scorers.mjs.map +1 -0
  186. package/esm/index.d.mts +95 -30
  187. package/esm/index.mjs +66 -22
  188. package/esm/memory/derive-id.mjs +24 -0
  189. package/esm/memory/derive-id.mjs.map +1 -0
  190. package/esm/memory/episodic-memory.mjs +106 -0
  191. package/esm/memory/episodic-memory.mjs.map +1 -0
  192. package/esm/memory/index.d.mts +5 -0
  193. package/esm/memory/memory.d.mts +42 -0
  194. package/esm/memory/memory.d.mts.map +1 -0
  195. package/esm/memory/memory.mjs +166 -0
  196. package/esm/memory/memory.mjs.map +1 -0
  197. package/esm/memory/procedural-memory.mjs +103 -0
  198. package/esm/memory/procedural-memory.mjs.map +1 -0
  199. package/esm/memory/semantic-memory.mjs +80 -0
  200. package/esm/memory/semantic-memory.mjs.map +1 -0
  201. package/esm/memory/working-memory.mjs +62 -0
  202. package/esm/memory/working-memory.mjs.map +1 -0
  203. package/esm/middleware/builtins/budget-contract.type.d.mts +126 -0
  204. package/esm/middleware/builtins/budget-contract.type.d.mts.map +1 -0
  205. package/esm/middleware/builtins/budget.d.mts +71 -1
  206. package/esm/middleware/builtins/budget.d.mts.map +1 -1
  207. package/esm/middleware/builtins/budget.mjs +119 -4
  208. package/esm/middleware/builtins/budget.mjs.map +1 -1
  209. package/esm/middleware/builtins/semantic-cache.d.mts +1 -1
  210. package/esm/middleware/index.d.mts +2 -1
  211. package/esm/middleware/index.mjs +1 -1
  212. package/esm/middleware/pipeline.d.mts +9 -6
  213. package/esm/middleware/pipeline.d.mts.map +1 -1
  214. package/esm/middleware/pipeline.mjs.map +1 -1
  215. package/esm/mock/index.d.mts +1 -0
  216. package/esm/mock/index.mjs +1 -0
  217. package/esm/mock/mock-router.d.mts +63 -0
  218. package/esm/mock/mock-router.d.mts.map +1 -0
  219. package/esm/mock/mock-router.mjs +58 -0
  220. package/esm/mock/mock-router.mjs.map +1 -0
  221. package/esm/model/fallback-model.d.mts +45 -0
  222. package/esm/model/fallback-model.d.mts.map +1 -0
  223. package/esm/model/fallback-model.mjs +218 -0
  224. package/esm/model/fallback-model.mjs.map +1 -0
  225. package/esm/model/index.d.mts +2 -0
  226. package/esm/model/index.mjs +3 -0
  227. package/esm/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +78 -0
  228. package/esm/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs.map +1 -0
  229. package/esm/node_modules/@vitest/expect/dist/index.mjs +1473 -0
  230. package/esm/node_modules/@vitest/expect/dist/index.mjs.map +1 -0
  231. package/esm/node_modules/@vitest/pretty-format/dist/index.mjs +888 -0
  232. package/esm/node_modules/@vitest/pretty-format/dist/index.mjs.map +1 -0
  233. package/esm/node_modules/@vitest/runner/dist/chunk-artifact.mjs +1533 -0
  234. package/esm/node_modules/@vitest/runner/dist/chunk-artifact.mjs.map +1 -0
  235. package/esm/node_modules/@vitest/runner/dist/index.mjs +3 -0
  236. package/esm/node_modules/@vitest/runner/dist/utils.mjs +3 -0
  237. package/esm/node_modules/@vitest/snapshot/dist/index.mjs +922 -0
  238. package/esm/node_modules/@vitest/snapshot/dist/index.mjs.map +1 -0
  239. package/esm/node_modules/@vitest/spy/dist/index.mjs +386 -0
  240. package/esm/node_modules/@vitest/spy/dist/index.mjs.map +1 -0
  241. package/esm/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs +82 -0
  242. package/esm/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs.map +1 -0
  243. package/esm/node_modules/@vitest/utils/dist/diff.mjs +1357 -0
  244. package/esm/node_modules/@vitest/utils/dist/diff.mjs.map +1 -0
  245. package/esm/node_modules/@vitest/utils/dist/display.mjs +559 -0
  246. package/esm/node_modules/@vitest/utils/dist/display.mjs.map +1 -0
  247. package/esm/node_modules/@vitest/utils/dist/error.mjs +38 -0
  248. package/esm/node_modules/@vitest/utils/dist/error.mjs.map +1 -0
  249. package/esm/node_modules/@vitest/utils/dist/helpers.mjs +181 -0
  250. package/esm/node_modules/@vitest/utils/dist/helpers.mjs.map +1 -0
  251. package/esm/node_modules/@vitest/utils/dist/offset.mjs +27 -0
  252. package/esm/node_modules/@vitest/utils/dist/offset.mjs.map +1 -0
  253. package/esm/node_modules/@vitest/utils/dist/serialize.mjs +77 -0
  254. package/esm/node_modules/@vitest/utils/dist/serialize.mjs.map +1 -0
  255. package/esm/node_modules/@vitest/utils/dist/source-map.mjs +374 -0
  256. package/esm/node_modules/@vitest/utils/dist/source-map.mjs.map +1 -0
  257. package/esm/node_modules/@vitest/utils/dist/timers.mjs +37 -0
  258. package/esm/node_modules/@vitest/utils/dist/timers.mjs.map +1 -0
  259. package/esm/node_modules/chai/index.mjs +2973 -0
  260. package/esm/node_modules/chai/index.mjs.map +1 -0
  261. package/esm/node_modules/magic-string/dist/magic-string.es.mjs +940 -0
  262. package/esm/node_modules/magic-string/dist/magic-string.es.mjs.map +1 -0
  263. package/esm/node_modules/tinyrainbow/dist/index.mjs +87 -0
  264. package/esm/node_modules/tinyrainbow/dist/index.mjs.map +1 -0
  265. package/esm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs +6 -0
  266. package/esm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs.map +1 -0
  267. package/esm/node_modules/vitest/dist/chunks/rpc.MzXet3jl.mjs +52 -0
  268. package/esm/node_modules/vitest/dist/chunks/rpc.MzXet3jl.mjs.map +1 -0
  269. package/esm/node_modules/vitest/dist/chunks/test.DNmyFkvJ.mjs +2697 -0
  270. package/esm/node_modules/vitest/dist/chunks/test.DNmyFkvJ.mjs.map +1 -0
  271. package/esm/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.mjs +45 -0
  272. package/esm/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.mjs.map +1 -0
  273. package/esm/orchestrator/as-tool.d.mts +42 -0
  274. package/esm/orchestrator/as-tool.d.mts.map +1 -0
  275. package/esm/orchestrator/as-tool.mjs +98 -0
  276. package/esm/orchestrator/as-tool.mjs.map +1 -0
  277. package/esm/orchestrator/checkpoint.mjs +75 -0
  278. package/esm/orchestrator/checkpoint.mjs.map +1 -0
  279. package/esm/orchestrator/commands.d.mts +38 -0
  280. package/esm/orchestrator/commands.d.mts.map +1 -0
  281. package/esm/orchestrator/commands.mjs +34 -0
  282. package/esm/orchestrator/commands.mjs.map +1 -0
  283. package/esm/orchestrator/compaction.mjs +206 -0
  284. package/esm/orchestrator/compaction.mjs.map +1 -0
  285. package/esm/orchestrator/dispatch.mjs +171 -0
  286. package/esm/orchestrator/dispatch.mjs.map +1 -0
  287. package/esm/orchestrator/emitter-port.type.d.mts +31 -0
  288. package/esm/orchestrator/emitter-port.type.d.mts.map +1 -0
  289. package/esm/orchestrator/emitter.d.mts +56 -0
  290. package/esm/orchestrator/emitter.d.mts.map +1 -0
  291. package/esm/orchestrator/emitter.mjs +85 -0
  292. package/esm/orchestrator/emitter.mjs.map +1 -0
  293. package/esm/orchestrator/engine-context.type.d.mts +56 -0
  294. package/esm/orchestrator/engine-context.type.d.mts.map +1 -0
  295. package/esm/orchestrator/execution.d.mts +116 -0
  296. package/esm/orchestrator/execution.d.mts.map +1 -0
  297. package/esm/orchestrator/execution.mjs +406 -0
  298. package/esm/orchestrator/execution.mjs.map +1 -0
  299. package/esm/orchestrator/index.d.mts +8 -0
  300. package/esm/orchestrator/index.mjs +10 -0
  301. package/esm/orchestrator/load.mjs +49 -0
  302. package/esm/orchestrator/load.mjs.map +1 -0
  303. package/esm/orchestrator/lock.mjs +75 -0
  304. package/esm/orchestrator/lock.mjs.map +1 -0
  305. package/esm/orchestrator/memory.d.mts +84 -0
  306. package/esm/orchestrator/memory.d.mts.map +1 -0
  307. package/esm/orchestrator/memory.mjs +141 -0
  308. package/esm/orchestrator/memory.mjs.map +1 -0
  309. package/esm/orchestrator/orchestrator-stream.d.mts +42 -0
  310. package/esm/orchestrator/orchestrator-stream.d.mts.map +1 -0
  311. package/esm/orchestrator/orchestrator-stream.mjs +98 -0
  312. package/esm/orchestrator/orchestrator-stream.mjs.map +1 -0
  313. package/esm/orchestrator/orchestrator.d.mts +38 -0
  314. package/esm/orchestrator/orchestrator.d.mts.map +1 -0
  315. package/esm/orchestrator/orchestrator.mjs +173 -0
  316. package/esm/orchestrator/orchestrator.mjs.map +1 -0
  317. package/esm/orchestrator/resume.mjs +74 -0
  318. package/esm/orchestrator/resume.mjs.map +1 -0
  319. package/esm/orchestrator/signature.d.mts +40 -0
  320. package/esm/orchestrator/signature.d.mts.map +1 -0
  321. package/esm/orchestrator/signature.mjs +120 -0
  322. package/esm/orchestrator/signature.mjs.map +1 -0
  323. package/esm/orchestrator/window.mjs +56 -0
  324. package/esm/orchestrator/window.mjs.map +1 -0
  325. package/esm/planner/index.d.mts +5 -0
  326. package/esm/planner/index.mjs +6 -0
  327. package/esm/planner/plan-prompt.d.mts +17 -0
  328. package/esm/planner/plan-prompt.d.mts.map +1 -0
  329. package/esm/planner/plan-prompt.mjs +30 -0
  330. package/esm/planner/plan-prompt.mjs.map +1 -0
  331. package/esm/planner/plan-schema.d.mts +27 -0
  332. package/esm/planner/plan-schema.d.mts.map +1 -0
  333. package/esm/planner/plan-schema.mjs +120 -0
  334. package/esm/planner/plan-schema.mjs.map +1 -0
  335. package/esm/planner/planner-run.d.mts +23 -0
  336. package/esm/planner/planner-run.d.mts.map +1 -0
  337. package/esm/planner/planner-run.mjs +344 -0
  338. package/esm/planner/planner-run.mjs.map +1 -0
  339. package/esm/planner/planner.d.mts +37 -0
  340. package/esm/planner/planner.d.mts.map +1 -0
  341. package/esm/planner/planner.mjs +120 -0
  342. package/esm/planner/planner.mjs.map +1 -0
  343. package/esm/planner/signature.d.mts +18 -0
  344. package/esm/planner/signature.d.mts.map +1 -0
  345. package/esm/planner/signature.mjs +27 -0
  346. package/esm/planner/signature.mjs.map +1 -0
  347. package/esm/snapshot/index.d.mts +3 -0
  348. package/esm/snapshot/memory.d.mts +26 -0
  349. package/esm/snapshot/memory.d.mts.map +1 -0
  350. package/esm/snapshot/memory.mjs +81 -0
  351. package/esm/snapshot/memory.mjs.map +1 -0
  352. package/esm/snapshot/pg.d.mts +41 -0
  353. package/esm/snapshot/pg.d.mts.map +1 -0
  354. package/esm/snapshot/pg.mjs +146 -0
  355. package/esm/snapshot/pg.mjs.map +1 -0
  356. package/esm/snapshot/redis.d.mts +42 -0
  357. package/esm/snapshot/redis.d.mts.map +1 -0
  358. package/esm/snapshot/redis.mjs +101 -0
  359. package/esm/snapshot/redis.mjs.map +1 -0
  360. package/esm/supervisor/as-tool.d.mts +0 -6
  361. package/esm/supervisor/as-tool.d.mts.map +1 -1
  362. package/esm/supervisor/as-tool.mjs +0 -6
  363. package/esm/supervisor/as-tool.mjs.map +1 -1
  364. package/esm/supervisor/execution.d.mts +43 -8
  365. package/esm/supervisor/execution.d.mts.map +1 -1
  366. package/esm/supervisor/execution.mjs +66 -16
  367. package/esm/supervisor/execution.mjs.map +1 -1
  368. package/esm/supervisor/fan-out.d.mts +65 -0
  369. package/esm/supervisor/fan-out.d.mts.map +1 -0
  370. package/esm/supervisor/fan-out.mjs +65 -0
  371. package/esm/supervisor/fan-out.mjs.map +1 -0
  372. package/esm/supervisor/index.d.mts +5 -3
  373. package/esm/supervisor/index.mjs +3 -1
  374. package/esm/supervisor/router-factory.d.mts +110 -0
  375. package/esm/supervisor/router-factory.d.mts.map +1 -0
  376. package/esm/supervisor/router-factory.mjs +141 -0
  377. package/esm/supervisor/router-factory.mjs.map +1 -0
  378. package/esm/supervisor/router-prompt.d.mts +1 -1
  379. package/esm/supervisor/snapshot.d.mts +4 -10
  380. package/esm/supervisor/snapshot.d.mts.map +1 -1
  381. package/esm/supervisor/snapshot.mjs +8 -16
  382. package/esm/supervisor/snapshot.mjs.map +1 -1
  383. package/esm/supervisor/supervisor.mjs +1 -0
  384. package/esm/supervisor/supervisor.mjs.map +1 -1
  385. package/esm/system-prompt/index.mjs +6 -0
  386. package/esm/system-prompt/system-prompt.d.mts +51 -3
  387. package/esm/system-prompt/system-prompt.d.mts.map +1 -1
  388. package/esm/system-prompt/system-prompt.mjs +52 -6
  389. package/esm/system-prompt/system-prompt.mjs.map +1 -1
  390. package/esm/testing/matcher-logic.d.mts +76 -0
  391. package/esm/testing/matcher-logic.d.mts.map +1 -0
  392. package/esm/testing/matcher-logic.mjs +144 -0
  393. package/esm/testing/matcher-logic.mjs.map +1 -0
  394. package/esm/testing/matchers.d.mts +48 -0
  395. package/esm/testing/matchers.d.mts.map +1 -0
  396. package/esm/testing/matchers.mjs +37 -0
  397. package/esm/testing/matchers.mjs.map +1 -0
  398. package/esm/testing/register-lazy.d.mts +20 -0
  399. package/esm/testing/register-lazy.d.mts.map +1 -0
  400. package/esm/testing/register-lazy.mjs +24 -0
  401. package/esm/testing/register-lazy.mjs.map +1 -0
  402. package/esm/tool/executable-as-tool.d.mts +87 -0
  403. package/esm/tool/executable-as-tool.d.mts.map +1 -0
  404. package/esm/tool/executable-as-tool.mjs +81 -0
  405. package/esm/tool/executable-as-tool.mjs.map +1 -0
  406. package/esm/tool/index.d.mts +2 -1
  407. package/esm/tool/index.mjs +1 -0
  408. package/esm/workflow/as-tool.mjs +0 -6
  409. package/esm/workflow/as-tool.mjs.map +1 -1
  410. package/esm/workflow/engine.mjs +2 -2
  411. package/esm/workflow/snapshot.mjs +13 -7
  412. package/esm/workflow/snapshot.mjs.map +1 -1
  413. package/esm/workflow/step-runner.mjs +1 -1
  414. package/esm/workflow/workflow.mjs +1 -0
  415. package/esm/workflow/workflow.mjs.map +1 -1
  416. package/llms-full.txt +947 -42
  417. package/llms.txt +13 -8
  418. package/package.json +3 -3
  419. package/skills/README.md +25 -5
  420. package/skills/ai-basics/SKILL.md +18 -7
  421. package/skills/ai-dx-helpers/SKILL.md +180 -0
  422. package/skills/attach-ai-middleware/SKILL.md +32 -3
  423. package/skills/handle-ai-errors/SKILL.md +20 -6
  424. package/skills/manage-ai-stores/SKILL.md +127 -0
  425. package/skills/persist-ai-data/SKILL.md +21 -10
  426. package/skills/pick-ai-provider/SKILL.md +46 -12
  427. package/skills/run-ai-agent/SKILL.md +51 -2
  428. package/skills/run-orchestrator/SKILL.md +198 -0
  429. package/skills/run-planner/SKILL.md +68 -0
  430. package/skills/run-supervisor/SKILL.md +47 -2
  431. package/skills/use-ai-memory/SKILL.md +124 -0
  432. package/skills/write-system-prompt/SKILL.md +14 -1
@@ -0,0 +1,68 @@
1
+ ---
2
+ name: run-planner
3
+ description: 'Goal-driven planning with ai.planner({...}) — an LLM GENERATES an ordered execution plan over your registered capabilities (agents / workflows / supervisors / tools), then the planner EXECUTES that plan step-by-step, threading each step output into the next, and returns the unified {data, report, usage, error} envelope with report.type "planner". A plan step may delegate via ai.spawnSubAgent({...}) — a GENERAL one-shot-agent helper (a fresh agent + optional per-task budget), covered fully in `@warlock.js/ai/run-ai-agent/SKILL.md`; it is not planner-specific and the planner engine does not require it. Triggers: `ai.planner`, `planner.execute`, `spawnSubAgent`, `PlannerConfig`, `PlannerCapability`, `PlannerResult`, `PlannerReport`, `PlannerPlan`, `PlannerStep`, `maxSteps`, `report.plan`, `report.executedSteps`; ''let the model plan the steps'', ''dynamic plan from a goal'', ''decompose a goal into capability calls'', ''spawn a sub-agent for a subtask''; typical import `import { ai } from "@warlock.js/ai"`. Skip: a FIXED known pipeline — `@warlock.js/ai/run-ai-workflow/SKILL.md`; routing one input to a specialist each turn — `@warlock.js/ai/run-supervisor/SKILL.md`; a single model + tools call — `@warlock.js/ai/run-ai-agent/SKILL.md`; competing libs `langgraph`, `crewai`.'
4
+ ---
5
+
6
+ # `ai.planner()` — LLM-generated, then executed, plans
7
+
8
+ A planner turns a free-form **goal** into an ordered **plan** the LLM writes itself (referencing only the capabilities you registered), then runs that plan one step at a time through each capability's own `execute()`. Use it when you do NOT know the steps up front — the model decides the sequence.
9
+
10
+ ## When to reach for it
11
+
12
+ - **`agent`** — one model + tools, single task. No multi-step decomposition.
13
+ - **`workflow`** — a FIXED pipeline you author by hand (`steps: [...]`). The steps are known at design time.
14
+ - **`supervisor`** — routes one input to the right specialist each turn; loops on a quality verdict.
15
+ - **`planner`** — the steps are NOT known in advance. The LLM generates the ordered plan from the goal, then the planner executes it. Bounded v1: strictly sequential, no DAG scheduling, no mid-plan re-planning.
16
+
17
+ ## Shape
18
+
19
+ ```ts
20
+ import { ai } from "@warlock.js/ai";
21
+
22
+ const research = ai.planner({
23
+ name: "research-assistant",
24
+ model: ai.openai.model({ name: "gpt-4o" }), // the plan-GENERATION brain
25
+ capabilities: [
26
+ { name: "search", description: "Search the web for sources", executable: searchAgent },
27
+ { name: "summarize", description: "Summarize text into bullet points", executable: summarizer },
28
+ { name: "write", description: "Draft a final report", executable: writerAgent },
29
+ ],
30
+ maxSteps: 6, // hard cap; steps beyond it are recorded as "skipped"
31
+ });
32
+
33
+ const { data, report, usage, error } = await research.execute("Compare React vs Vue in 2026");
34
+
35
+ console.log(report.plan?.summary); // the LLM's one-line strategy
36
+ for (const step of report.executedSteps) { // forensic, in execution order
37
+ console.log(step.step.capability, step.status);
38
+ }
39
+ ```
40
+
41
+ - `model` builds an internal planning agent with a generated plan-prompt baked on. **Mutually exclusive** with `planner`.
42
+ - `planner` lets you bring your own fully-configured planning agent (custom prompt, middleware). The planner injects the plan schema as that agent's per-call `output`.
43
+ - A `capability` is `{ name, description, executable }`. The `name` is what the LLM references per step; the `description` is what it reads to pick. `executable` is any `ExecutableContract` (agent / workflow / supervisor / tool).
44
+
45
+ ## Execution model (bounded v1)
46
+
47
+ 1. **Generate** — the planning agent is asked for a `{ steps, summary? }` plan via a generated schema whose `capability` field is an `enum` of your capability names.
48
+ 2. **Execute** — steps run **strictly in array order**. Each completed step's output is threaded into the next step's input as "Context from earlier steps". `dependsOn` on a step is advisory metadata only — recorded, not scheduled on.
49
+ 3. **Finalize** — when `output` is set (factory or per-call), the LAST completed step's structured output is validated into `result.data`. A capability that should feed typed output to the planner's `output` should declare its own `output` schema (the planner reads `data`, falling back to an agent's raw `text`).
50
+
51
+ `report.type === "planner"`; `report.children[]` carries every dispatched capability report (plus the planning trip), with usage rolled up. Lazy capability loading is **deferred** — every capability is fully constructed up front.
52
+
53
+ ## Failure + cancellation
54
+
55
+ `execute()` never throws — failures surface on `result.error`:
56
+
57
+ - **`PlannerPlanInvalidError`** (`PLANNER_PLAN_INVALID`, category `schema`) — empty plan or a step naming an unknown capability; also a final-output validation failure.
58
+ - **`PlannerCancelledError`** (`PLANNER_CANCELLED`, category `cancelled`) — the `AbortSignal` fired. `report.status === "cancelled"`, `report.cancelledAt` set; remaining steps are `skipped`.
59
+ - A child capability's own error (agent / tool / provider) flows through unchanged on the failing step's snapshot and as `result.error`. The planner stops at the first failed step and marks the rest `skipped`.
60
+ - **`PlannerFailedError`** is the base for the `PLANNER_*` family.
61
+
62
+ ## Delegating a step with `ai.spawnSubAgent()`
63
+
64
+ A plan step can hand a bounded subtask to a fresh single-use agent with a hard spend cap via `ai.spawnSubAgent({...})`. It is **not** a planner feature — it's a general one-shot-agent helper (a fresh `ai.agent()` + an optional per-task `budget`, run once) that works identically inside a tool, a workflow step, a supervisor intent, or hand-rolled orchestration. The planner engine never calls it; it's simply a primitive a capability *you* write can reach for. Full coverage: [`@warlock.js/ai/run-ai-agent/SKILL.md`](@warlock.js/ai/run-ai-agent/SKILL.md).
65
+
66
+ ## Testing
67
+
68
+ Use `MockSDK` for the planning model — script the plan as a JSON string matching `{ steps, summary? }`. Capabilities can be `mockAgent({ name, responses })`. See `src/planner/planner.spec.ts`.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: run-supervisor
3
- description: 'Multi-intent routing with ai.supervisor({...}) — classifier (iter-0 dispatch), router agent OR route callback, intents as agents / workflows / callbacks, fan-out, evaluate quality loop, ack receptionist. Triggers: `ai.supervisor`, `supervisor.execute`, `supervisor.resume`, `intents`, `router`, `route`, `classifier`, `evaluate`, `ack`, `artifactsSchema`, `END`, `ctx.intents.X.execute`; ''route one input across specialists'', ''multi-intent dispatch'', ''fan-out then evaluate'', ''classifier then router''; typical import `import { ai } from "@warlock.js/ai"`. Skip: fixed pipelines — `@warlock.js/ai/run-ai-workflow/SKILL.md`; single agent — `@warlock.js/ai/run-ai-agent/SKILL.md`; competing libs `langgraph`, `crewai`.'
3
+ description: 'Multi-intent routing with ai.supervisor({...}) — classifier (iter-0 dispatch), router agent OR route callback, intents as agents / workflows / callbacks, fan-out, evaluate quality loop, ack receptionist, supervisor-level middleware. Triggers: `ai.supervisor`, `ai.router`, `ai.fanOut`, `supervisor.execute`, `supervisor.resume`, `intents`, `router`, `route`, `classifier`, `evaluate`, `ack`, `artifactsSchema`, `middleware`, `END`, `ctx.intents.X.execute`; ''route one input across specialists'', ''multi-intent dispatch'', ''fan-out then evaluate'', ''classifier then router'', ''supervisor middleware'', ''self-consistency / voting''; typical import `import { ai } from "@warlock.js/ai"`. Skip: durable multi-turn sessions — `@warlock.js/ai/run-orchestrator/SKILL.md`; fixed pipelines — `@warlock.js/ai/run-ai-workflow/SKILL.md`; single agent — `@warlock.js/ai/run-ai-agent/SKILL.md`; competing libs `langgraph`, `crewai`.'
4
4
  ---
5
5
 
6
6
  # `ai.supervisor()` — multi-intent routing
@@ -12,7 +12,7 @@ A supervisor takes one input, picks which intent(s) handle it, runs them, option
12
12
  - **`agent`** — one model + tools, single task. Doesn't fit when the right specialist depends on the input.
13
13
  - **`workflow`** — fixed step order. Doesn't fit when routing decisions need an LLM or vary per request.
14
14
  - **`supervisor`** — when the right specialist is decided per-call and you may iterate to a goal.
15
- - **`orchestrator` (v2)** — when the *session* matters: long-running conversations.
15
+ - **`orchestrator`** — when the *session* matters: long-running conversations with durable cross-turn state, history windowing/compaction, and mid-turn resume. See [`@warlock.js/ai/run-orchestrator/SKILL.md`](@warlock.js/ai/run-orchestrator/SKILL.md).
16
16
 
17
17
  ## Three dispatch surfaces
18
18
 
@@ -73,6 +73,41 @@ The router agent's output MUST include `next: string | string[] | typeof END`; `
73
73
 
74
74
  `evaluate` pairs with both `router` AND `route` — state-driven termination is useful in either dispatch mode.
75
75
 
76
+ #### `ai.router()` — skip the boilerplate
77
+
78
+ `ai.router({ model, intents })` builds the routing agent for you: it generates the `{ next, reasoning }` output schema (with the intent names + `END` baked in as a JSON-Schema `enum`) and auto-writes the routing system prompt listing every intent + description. Pass the **same** `intents` object you pass to `ai.supervisor()`.
79
+
80
+ ```ts
81
+ const intents = { billing, shipping, returns, escalate };
82
+
83
+ const supportBot = ai.supervisor({
84
+ router: ai.router({
85
+ model,
86
+ intents,
87
+ systemPrompt: "You coordinate a customer-support team.", // optional framing on top
88
+ }),
89
+ intents,
90
+ });
91
+ ```
92
+
93
+ The result is a plain `AgentContract` — usable standalone or as `router`. Hand-writing the agent (above) still works; `ai.router()` is the shortcut.
94
+
95
+ #### `ai.fanOut()` — voting / self-consistency
96
+
97
+ `ai.fanOut(unit, n)` spreads one agent/workflow into `n` distinctly-keyed intent entries (`writer1..writerN`) so the supervisor can dispatch them in parallel and a downstream intent can pick the best/majority answer. Spread it into `intents`:
98
+
99
+ ```ts
100
+ ai.supervisor({
101
+ intents: {
102
+ ...ai.fanOut(writer, 3), // writer1, writer2, writer3
103
+ vote: { run: pickMajority, description: "Choose the majority answer." },
104
+ },
105
+ route: (ctx) => (ctx.iteration === 0 ? ["writer1", "writer2", "writer3"] : "vote"),
106
+ });
107
+ ```
108
+
109
+ Each key references the same underlying unit; the description defaults to the unit's. Override the key base with `{ keyPrefix }` and the per-entry text with `{ description }`.
110
+
76
111
  ## The `intents` map — five accepted shapes
77
112
 
78
113
  ```ts
@@ -246,6 +281,16 @@ await supportBot.execute(message, {
246
281
 
247
282
  `history` precedence: per-call → factory `config.history`. Slice with `historyWindow.{router,agents,ack}` (default ack = 0, router/agents = unbounded) or per-entry `history(ctx)` override.
248
283
 
284
+ ## Supervisor-level middleware
285
+
286
+ `middleware: AgentMiddleware[]` fires each middleware's optional `supervisor` hook map (`before` / `after` / `onError`) ONCE around the whole `execute()` / `stream()` / `resume()` run:
287
+
288
+ ```ts
289
+ ai.supervisor({ name: "support", router, intents, middleware: [auditTrail] });
290
+ ```
291
+
292
+ Same onion semantics as the agent pipeline: `before` top-down (return a `SupervisorResult` to short-circuit, throw to abort), `after` / `onError` bottom-up. A middleware without a `supervisor` hook map is skipped — the SAME builtin objects (budget, guardrail, …) can be registered on agents AND here, each declaring whichever level applies. Each needs a unique `name`. See [`@warlock.js/ai/attach-ai-middleware/SKILL.md`](@warlock.js/ai/attach-ai-middleware/SKILL.md).
293
+
249
294
  ## Iteration model
250
295
 
251
296
  1. Router/route picks `next` (or `END`).
@@ -0,0 +1,124 @@
1
+ ---
2
+ name: use-ai-memory
3
+ description: 'Agent memory with ai.memory({...}) — a provider-neutral store with FOUR tiers: WORKING (in-run scratch, recalled by recency), SEMANTIC (durable facts by cosine similarity over a @warlock.js/cache vector driver via .similar()), EPISODIC (durable events, similarity blended with recency), and PROCEDURAL (durable how-tos, similarity blended with reinforcement). remember() / recall() / clear(); wire it into ai.orchestrator({ memory }). Triggers: `ai.memory`, `memory.remember`, `memory.recall`, `memory.clear`, `MemoryContract`, `MemoryConfig`, `MemoryItem`, `RecalledMemory`, `MemoryTier`, `SemanticMemoryConfig`, `EpisodicMemoryConfig`, `ProceduralMemoryConfig`, `working`, `semantic`, `episodic`, `procedural`, `defaultTier`, `threshold`, `recencyWeight`, `halfLifeMs`, `reinforcementWeight`, `injectKey`; ''give the agent memory'', ''remember user preferences'', ''semantic recall'', ''per-session working memory'', ''episodic / event memory'', ''procedural / how-to memory'', ''recency-weighted recall'', ''reinforce a procedure''; typical import `import { ai } from "@warlock.js/ai"`. Skip: orchestrator wiring of the memory — `@warlock.js/ai/run-orchestrator/SKILL.md`; the vector cache driver itself — `@warlock.js/cache/cache-basics/SKILL.md`; embeddings primitive — `@warlock.js/ai/embed-text/SKILL.md`; competing libs `mem0`, `langchain` memory.'
4
+ ---
5
+
6
+ # `ai.memory()` — agent memory store
7
+
8
+ A single provider-neutral store that holds and retrieves what an agent / orchestrator should remember across turns. Four tiers ship in 4.3.0:
9
+
10
+ - **working** — in-run scratch threaded across turns of one session. Volatile, unscored, recalled in insertion order (recency). On by default.
11
+ - **semantic** — durable *facts* stored as embeddings in a `@warlock.js/cache` driver, retrieved by cosine similarity via the driver's native `.similar()` — the same delegation the `semanticCache` middleware uses. Activates only when you pass `semantic` config.
12
+ - **episodic** — durable *events*: a timestamped log retrieved by similarity **blended with recency** (recent episodes rank higher). Embedder-backed like semantic; tune with `recencyWeight` + `halfLifeMs`.
13
+ - **procedural** — durable *how-tos*: learned procedures retrieved by similarity **blended with reinforcement** — re-remembering a procedure increments its use count so well-worn procedures rank higher. Tune with `reinforcementWeight`.
14
+
15
+ > **Still deferred** — decay / forgetting (TTL falloff, eviction). The four tiers above are the full 4.3.0 surface; the `MemoryTier` union widened from `"working" | "semantic"` to add `"episodic" | "procedural"` (a non-breaking change).
16
+
17
+ ## Shape
18
+
19
+ ```ts
20
+ import { ai } from "@warlock.js/ai";
21
+ import { MemoryCacheDriver } from "@warlock.js/cache";
22
+ import { OpenAISDK } from "@warlock.js/ai-openai";
23
+
24
+ const openai = new OpenAISDK({ apiKey: process.env.OPENAI_API_KEY! });
25
+
26
+ const store = new MemoryCacheDriver();
27
+ store.setOptions({});
28
+
29
+ const mem = ai.memory({
30
+ semantic: {
31
+ embedder: openai.embedder({ name: "text-embedding-3-small" }),
32
+ store, // vector-capable CacheDriver
33
+ namespace: "ai.memory", // key prefix; default "ai.memory"
34
+ },
35
+ defaultTier: "semantic", // tier a remember() item lands in without its own `tier`
36
+ k: 5, // default recall count
37
+ threshold: 0.7, // default semantic similarity floor [0,1]
38
+ });
39
+
40
+ await mem.remember({ text: "User prefers concise answers." });
41
+ const hits = await mem.recall("how should I respond?", { k: 3 });
42
+ ```
43
+
44
+ ## Configuration rules (loud at construction)
45
+
46
+ - **At least one tier must be enabled** — `working` defaults to `true`; `semantic` / `episodic` / `procedural` each activate only when you pass their config. Enabling neither throws (`a memory with no tiers can't store or recall`).
47
+ - **A vector tier with no store throws now** — pass the tier's `store`, or set `ai.config({ defaultStore })` at boot. Applies to `semantic`, `episodic`, and `procedural`. Resolution happens once at construction, not silently on first use (the same loud-now contract `semanticCache` follows).
48
+ - **`defaultTier` must reference an enabled tier** — defaults to `"working"`.
49
+ - Set `working: false` for a durable-only memory (then set `defaultTier` to an enabled vector tier).
50
+
51
+ ## Episodic & procedural tiers
52
+
53
+ Both are durable, embedder-backed tiers wired like `semantic` (`{ embedder, store? }`), but they re-rank by *time* and *use*:
54
+
55
+ ```ts
56
+ const mem = ai.memory({
57
+ episodic: { embedder, store, recencyWeight: 0.3, halfLifeMs: 7 * 24 * 60 * 60 * 1000 },
58
+ procedural: { embedder, store, reinforcementWeight: 0.3 },
59
+ defaultTier: "episodic",
60
+ });
61
+
62
+ await mem.remember({ text: "Refunded order 5821 after a cracked-item complaint.", tier: "episodic" });
63
+ await mem.remember({ id: "esc", text: "Escalate refunds over $500 to a human.", tier: "procedural" });
64
+ await mem.remember({ id: "esc", text: "Escalate refunds over $500 to a human.", tier: "procedural" }); // reinforce → uses 1→2
65
+ ```
66
+
67
+ - **episodic** — stamps each entry with the remember time and decays its recency on an exponential half-life; at equal similarity a recent episode wins. `recencyWeight: 0` → pure similarity. The similarity `threshold` still gates relevance (recency never surfaces an irrelevant-but-recent episode). `now` is injectable for deterministic tests.
68
+ - **procedural** — keeps a per-procedure use count; re-remembering (same `id`, or same text → same derived id) **reinforces** it with diminishing returns. Recall is side-effect-free.
69
+ - Each vector tier defaults to its own namespace (`ai.memory.semantic` / `.episodic` / `.procedural`) so they don't collide on a shared driver; override with `namespace`.
70
+
71
+ ## The three methods
72
+
73
+ ### `remember(items)`
74
+
75
+ ```ts
76
+ await mem.remember({ text: "User is on the Enterprise plan.", tier: "semantic", metadata: { source: "crm" } });
77
+ await mem.remember([{ text: "a" }, { text: "b", tier: "working" }]); // batch
78
+ ```
79
+
80
+ A `MemoryItem` is `{ text, tier?, id?, metadata? }`. `text` is the only required field — it's what gets embedded (semantic) and surfaced back on recall. `tier` defaults to the factory `defaultTier`. Semantic items are embedded + indexed; working items append to the in-run buffer. **Re-remembering an item whose id (explicit or text-derived) already exists overwrites in place rather than duplicating.** `metadata` is an opaque bag round-tripped verbatim onto the recalled memory.
81
+
82
+ ### `recall(query, options?)`
83
+
84
+ ```ts
85
+ const hits = await mem.recall("which plan is the user on?", {
86
+ k: 5, // cap result count (defaults to factory k)
87
+ threshold: 0.75, // raise the semantic floor for this call
88
+ tier: "semantic", // restrict to one tier; omit to query every enabled tier
89
+ });
90
+
91
+ for (const hit of hits) {
92
+ hit.id; hit.text; hit.tier; hit.score; hit.metadata;
93
+ }
94
+ ```
95
+
96
+ Returns `RecalledMemory[]` scored and ordered by descending relevance. By default queries every enabled tier and merges. `score` is in `[0,1]` for **every** tier — cosine similarity (semantic), a recency proxy (working, most-recent = 1), similarity×recency (episodic), or similarity×reinforcement (procedural) — so a mixed recall set sorts on one field without special-casing the tier. Returns `[]` when nothing clears the threshold — never throws on "no hits".
97
+
98
+ **Memory never mutates the prompt.** `recall()` hands you scored entries; surfacing the recalled text (system prefix, a synthesized "what you remember" block, …) is YOUR call so the injection point stays explicit.
99
+
100
+ ### `clear(tier?)`
101
+
102
+ ```ts
103
+ await mem.clear(); // every tier
104
+ await mem.clear("working"); // just working — e.g. at session end, keeping durable recall
105
+ ```
106
+
107
+ ## Wiring into an orchestrator
108
+
109
+ Pass the store as `ai.orchestrator({ memory })` to recall before each turn's dispatch and remember the settled outcome after. Recalled memories land in `ctx.context[injectKey]` (default `"memories"`). See [`@warlock.js/ai/run-orchestrator/SKILL.md`](@warlock.js/ai/run-orchestrator/SKILL.md) for the per-turn `memory` field, `recall.k: 0` (write-only), `remember: false` (read-only), and `rememberTier`.
110
+
111
+ ## Picking a vector driver
112
+
113
+ The semantic tier delegates similarity entirely to the `CacheDriver`:
114
+ - **Dev / tests** — `new MemoryCacheDriver()` (zero config, O(N) scan; fine up to a few thousand entries).
115
+ - **Production** — a driver with a real ANN index: `pg` with pgvector, `redis` with RediSearch.
116
+
117
+ Drivers without similarity support throw `CacheUnsupportedError` from `set({ vector })` / `similar()`. See [`@warlock.js/cache/cache-basics/SKILL.md`](@warlock.js/cache/cache-basics/SKILL.md).
118
+
119
+ ## See also
120
+
121
+ - [`@warlock.js/ai/run-orchestrator/SKILL.md`](@warlock.js/ai/run-orchestrator/SKILL.md) — the `memory` field on a session
122
+ - [`@warlock.js/ai/embed-text/SKILL.md`](@warlock.js/ai/embed-text/SKILL.md) — the embedder the semantic tier needs
123
+ - [`@warlock.js/ai/attach-ai-middleware/SKILL.md`](@warlock.js/ai/attach-ai-middleware/SKILL.md) — `semanticCache`, the sibling `.similar()` consumer
124
+ - [`@warlock.js/cache/cache-basics/SKILL.md`](@warlock.js/cache/cache-basics/SKILL.md) — vector driver catalog
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: write-system-prompt
3
- description: 'Compose system prompts via ai.systemPrompt() / ai.persona() / ai.instruction() — immutable builders with {{placeholder}} substitution. Triggers: `ai.systemPrompt`, `ai.persona`, `ai.instruction`, `SystemPromptBlockContract`, `PersonaContract`, `InstructionContract`, `placeholders`, `{{placeholder|default}}`; ''write a system prompt'', ''compose persona + instructions'', ''per-call prompt override'', ''mustache placeholder''; typical import `import { ai } from "@warlock.js/ai"`. Skip: agent factory wiring — `@warlock.js/ai/run-ai-agent/SKILL.md`; competing libs `langchain` `PromptTemplate`, raw f-strings.'
3
+ description: 'Compose system prompts via ai.systemPrompt() / ai.persona() / ai.instruction() — immutable builders with {{placeholder}} substitution, plus ai.systemPrompt.fromFile(path) to seed from a file read once at construction. Triggers: `ai.systemPrompt`, `ai.systemPrompt.fromFile`, `ai.persona`, `ai.instruction`, `SystemPromptBlockContract`, `PersonaContract`, `InstructionContract`, `placeholders`, `{{placeholder|default}}`, `InvalidRequestError`; ''write a system prompt'', ''compose persona + instructions'', ''prompt from a file'', ''per-call prompt override'', ''mustache placeholder''; typical import `import { ai } from "@warlock.js/ai"`. Skip: agent factory wiring — `@warlock.js/ai/run-ai-agent/SKILL.md`; competing libs `langchain` `PromptTemplate`, raw f-strings.'
4
4
  ---
5
5
 
6
6
  # System prompts — immutable builders
@@ -15,6 +15,7 @@ import { ai } from "@warlock.js/ai";
15
15
  ai.systemPrompt(); // empty — chain .persona(), .instruction() onto it
16
16
  ai.systemPrompt("literal text"); // one-shot string form
17
17
  ai.systemPrompt([block1, block2]); // array form — blocks render in declaration order
18
+ ai.systemPrompt.fromFile(path); // seed from a file read once at construction
18
19
 
19
20
  ai.persona(text); // PersonaContract block
20
21
  ai.instruction(text); // InstructionContract block
@@ -51,6 +52,18 @@ ai.systemPrompt([
51
52
  ]);
52
53
  ```
53
54
 
55
+ ### From a file — `ai.systemPrompt.fromFile(path)`
56
+
57
+ Read a prompt template from disk ONCE, synchronously, at construction. The file's UTF-8 contents seed one instruction block — so `{{placeholders}}` inside the file resolve at `resolve()` time and the result forks with further `.persona()` / `.instruction()` calls:
58
+
59
+ ```ts
60
+ const prompt = ai.systemPrompt.fromFile("./prompts/support-agent.md");
61
+ const localized = prompt.instruction("Respond in {{language|English}}.");
62
+ localized.resolve({ language: "Arabic" });
63
+ ```
64
+
65
+ One-shot by design (never re-read on `resolve()`). Throws `InvalidRequestError` when the file can't be read — a path typo fails loudly at construction instead of silently producing an empty prompt. `ai.systemPrompt.fromFile(path)` === `SystemPrompt.fromFile(path)`.
66
+
54
67
  ## Block ordering
55
68
 
56
69
  `SystemPrompt` stores `blocks: readonly SystemPromptBlockContract[]` — not separate persona + instructions fields. Rendering honors insertion order.