@namzu/sdk 0.4.1 → 0.4.3

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 (685) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/__tests__/replay-public-surface.test.d.ts +2 -0
  3. package/dist/__tests__/replay-public-surface.test.d.ts.map +1 -0
  4. package/dist/__tests__/replay-public-surface.test.js +45 -0
  5. package/dist/__tests__/replay-public-surface.test.js.map +1 -0
  6. package/dist/advisory/context.test.d.ts +16 -0
  7. package/dist/advisory/context.test.d.ts.map +1 -0
  8. package/dist/advisory/context.test.js +92 -0
  9. package/dist/advisory/context.test.js.map +1 -0
  10. package/dist/advisory/evaluator.test.d.ts +34 -0
  11. package/dist/advisory/evaluator.test.d.ts.map +1 -0
  12. package/dist/advisory/evaluator.test.js +172 -0
  13. package/dist/advisory/evaluator.test.js.map +1 -0
  14. package/dist/advisory/executor.test.d.ts +35 -0
  15. package/dist/advisory/executor.test.d.ts.map +1 -0
  16. package/dist/advisory/executor.test.js +233 -0
  17. package/dist/advisory/executor.test.js.map +1 -0
  18. package/dist/advisory/registry.test.d.ts +16 -0
  19. package/dist/advisory/registry.test.d.ts.map +1 -0
  20. package/dist/advisory/registry.test.js +62 -0
  21. package/dist/advisory/registry.test.js.map +1 -0
  22. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  23. package/dist/agents/SupervisorAgent.js.map +1 -1
  24. package/dist/bridge/a2a/agent-card.test.d.ts +24 -0
  25. package/dist/bridge/a2a/agent-card.test.d.ts.map +1 -0
  26. package/dist/bridge/a2a/agent-card.test.js +118 -0
  27. package/dist/bridge/a2a/agent-card.test.js.map +1 -0
  28. package/dist/bridge/a2a/mapper.test.d.ts +29 -0
  29. package/dist/bridge/a2a/mapper.test.d.ts.map +1 -0
  30. package/dist/bridge/a2a/mapper.test.js +265 -0
  31. package/dist/bridge/a2a/mapper.test.js.map +1 -0
  32. package/dist/bridge/a2a/message.test.d.ts +20 -0
  33. package/dist/bridge/a2a/message.test.d.ts.map +1 -0
  34. package/dist/bridge/a2a/message.test.js +116 -0
  35. package/dist/bridge/a2a/message.test.js.map +1 -0
  36. package/dist/bridge/a2a/task.d.ts +2 -2
  37. package/dist/bridge/a2a/task.d.ts.map +1 -1
  38. package/dist/bridge/a2a/task.js.map +1 -1
  39. package/dist/bridge/a2a/task.test.d.ts +29 -0
  40. package/dist/bridge/a2a/task.test.d.ts.map +1 -0
  41. package/dist/bridge/a2a/task.test.js +198 -0
  42. package/dist/bridge/a2a/task.test.js.map +1 -0
  43. package/dist/bridge/mcp/connector/adapter.test.d.ts +27 -0
  44. package/dist/bridge/mcp/connector/adapter.test.d.ts.map +1 -0
  45. package/dist/bridge/mcp/connector/adapter.test.js +203 -0
  46. package/dist/bridge/mcp/connector/adapter.test.js.map +1 -0
  47. package/dist/bridge/sse/mapper.test.d.ts +27 -0
  48. package/dist/bridge/sse/mapper.test.d.ts.map +1 -0
  49. package/dist/bridge/sse/mapper.test.js +271 -0
  50. package/dist/bridge/sse/mapper.test.js.map +1 -0
  51. package/dist/bridge/tools/connector/adapter.test.d.ts +28 -0
  52. package/dist/bridge/tools/connector/adapter.test.d.ts.map +1 -0
  53. package/dist/bridge/tools/connector/adapter.test.js +182 -0
  54. package/dist/bridge/tools/connector/adapter.test.js.map +1 -0
  55. package/dist/bridge/tools/connector/definitions.test.d.ts +23 -0
  56. package/dist/bridge/tools/connector/definitions.test.d.ts.map +1 -0
  57. package/dist/bridge/tools/connector/definitions.test.js +158 -0
  58. package/dist/bridge/tools/connector/definitions.test.js.map +1 -0
  59. package/dist/bridge/tools/connector/router.test.d.ts +21 -0
  60. package/dist/bridge/tools/connector/router.test.d.ts.map +1 -0
  61. package/dist/bridge/tools/connector/router.test.js +139 -0
  62. package/dist/bridge/tools/connector/router.test.js.map +1 -0
  63. package/dist/bus/breaker.test.d.ts +41 -0
  64. package/dist/bus/breaker.test.d.ts.map +1 -0
  65. package/dist/bus/breaker.test.js +242 -0
  66. package/dist/bus/breaker.test.js.map +1 -0
  67. package/dist/bus/index.test.d.ts +25 -0
  68. package/dist/bus/index.test.d.ts.map +1 -0
  69. package/dist/bus/index.test.js +151 -0
  70. package/dist/bus/index.test.js.map +1 -0
  71. package/dist/bus/lock.test.d.ts +44 -0
  72. package/dist/bus/lock.test.d.ts.map +1 -0
  73. package/dist/bus/lock.test.js +226 -0
  74. package/dist/bus/lock.test.js.map +1 -0
  75. package/dist/bus/ownership.test.d.ts +26 -0
  76. package/dist/bus/ownership.test.d.ts.map +1 -0
  77. package/dist/bus/ownership.test.js +205 -0
  78. package/dist/bus/ownership.test.js.map +1 -0
  79. package/dist/config/runtime.d.ts +24 -25
  80. package/dist/config/runtime.d.ts.map +1 -1
  81. package/dist/config/runtime.js.map +1 -1
  82. package/dist/connector/BaseConnector.test.d.ts +21 -0
  83. package/dist/connector/BaseConnector.test.d.ts.map +1 -0
  84. package/dist/connector/BaseConnector.test.js +108 -0
  85. package/dist/connector/BaseConnector.test.js.map +1 -0
  86. package/dist/connector/builtins/http.test.d.ts +30 -0
  87. package/dist/connector/builtins/http.test.d.ts.map +1 -0
  88. package/dist/connector/builtins/http.test.js +232 -0
  89. package/dist/connector/builtins/http.test.js.map +1 -0
  90. package/dist/connector/builtins/webhook.test.d.ts +20 -0
  91. package/dist/connector/builtins/webhook.test.d.ts.map +1 -0
  92. package/dist/connector/builtins/webhook.test.js +113 -0
  93. package/dist/connector/builtins/webhook.test.js.map +1 -0
  94. package/dist/connector/execution/factory.test.d.ts +16 -0
  95. package/dist/connector/execution/factory.test.d.ts.map +1 -0
  96. package/dist/connector/execution/factory.test.js +64 -0
  97. package/dist/connector/execution/factory.test.js.map +1 -0
  98. package/dist/connector/execution/remote.test.d.ts +16 -0
  99. package/dist/connector/execution/remote.test.d.ts.map +1 -0
  100. package/dist/connector/execution/remote.test.js +53 -0
  101. package/dist/connector/execution/remote.test.js.map +1 -0
  102. package/dist/connector/mcp/adapter.test.d.ts +34 -0
  103. package/dist/connector/mcp/adapter.test.d.ts.map +1 -0
  104. package/dist/connector/mcp/adapter.test.js +199 -0
  105. package/dist/connector/mcp/adapter.test.js.map +1 -0
  106. package/dist/contracts/api.d.ts +2 -2
  107. package/dist/contracts/api.d.ts.map +1 -1
  108. package/dist/contracts/index.d.ts +1 -2
  109. package/dist/contracts/index.d.ts.map +1 -1
  110. package/dist/contracts/index.js.map +1 -1
  111. package/dist/contracts/schemas.d.ts +10 -10
  112. package/dist/index.d.ts +3 -103
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +9 -89
  115. package/dist/index.js.map +1 -1
  116. package/dist/manager/agent/__tests__/lifecycle.test.js.map +1 -1
  117. package/dist/manager/agent/lifecycle.d.ts +1 -1
  118. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  119. package/dist/manager/agent/lifecycle.js +1 -1
  120. package/dist/manager/agent/lifecycle.js.map +1 -1
  121. package/dist/manager/run/persistence.d.ts +3 -3
  122. package/dist/manager/run/persistence.d.ts.map +1 -1
  123. package/dist/manager/run/persistence.js.map +1 -1
  124. package/dist/manager/thread/__tests__/lifecycle.test.js.map +1 -1
  125. package/dist/manager/thread/lifecycle.d.ts +1 -1
  126. package/dist/manager/thread/lifecycle.d.ts.map +1 -1
  127. package/dist/plugin/loader.d.ts +0 -5
  128. package/dist/plugin/loader.d.ts.map +1 -1
  129. package/dist/plugin/loader.js +1 -13
  130. package/dist/plugin/loader.js.map +1 -1
  131. package/dist/public-runtime.d.ts +70 -0
  132. package/dist/public-runtime.d.ts.map +1 -0
  133. package/dist/public-runtime.js +108 -0
  134. package/dist/public-runtime.js.map +1 -0
  135. package/dist/public-tools.d.ts +19 -0
  136. package/dist/public-tools.d.ts.map +1 -0
  137. package/dist/public-tools.js +34 -0
  138. package/dist/public-tools.js.map +1 -0
  139. package/dist/public-types.d.ts +55 -0
  140. package/dist/public-types.d.ts.map +1 -0
  141. package/dist/public-types.js +14 -0
  142. package/dist/public-types.js.map +1 -0
  143. package/dist/rag/chunking.test.d.ts +20 -0
  144. package/dist/rag/chunking.test.d.ts.map +1 -0
  145. package/dist/rag/chunking.test.js +92 -0
  146. package/dist/rag/chunking.test.js.map +1 -0
  147. package/dist/rag/context-assembler.test.d.ts +19 -0
  148. package/dist/rag/context-assembler.test.d.ts.map +1 -0
  149. package/dist/rag/context-assembler.test.js +98 -0
  150. package/dist/rag/context-assembler.test.js.map +1 -0
  151. package/dist/rag/embedding.test.d.ts +19 -0
  152. package/dist/rag/embedding.test.d.ts.map +1 -0
  153. package/dist/rag/embedding.test.js +115 -0
  154. package/dist/rag/embedding.test.js.map +1 -0
  155. package/dist/rag/ingestion.test.d.ts +22 -0
  156. package/dist/rag/ingestion.test.d.ts.map +1 -0
  157. package/dist/rag/ingestion.test.js +99 -0
  158. package/dist/rag/ingestion.test.js.map +1 -0
  159. package/dist/rag/knowledge-base.test.d.ts +17 -0
  160. package/dist/rag/knowledge-base.test.d.ts.map +1 -0
  161. package/dist/rag/knowledge-base.test.js +77 -0
  162. package/dist/rag/knowledge-base.test.js.map +1 -0
  163. package/dist/rag/rag-tool.d.ts +1 -1
  164. package/dist/rag/rag-tool.test.d.ts +21 -0
  165. package/dist/rag/rag-tool.test.d.ts.map +1 -0
  166. package/dist/rag/rag-tool.test.js +149 -0
  167. package/dist/rag/rag-tool.test.js.map +1 -0
  168. package/dist/rag/retriever.test.d.ts +26 -0
  169. package/dist/rag/retriever.test.d.ts.map +1 -0
  170. package/dist/rag/retriever.test.js +180 -0
  171. package/dist/rag/retriever.test.js.map +1 -0
  172. package/dist/rag/vector-store.test.d.ts +38 -0
  173. package/dist/rag/vector-store.test.d.ts.map +1 -0
  174. package/dist/rag/vector-store.test.js +175 -0
  175. package/dist/rag/vector-store.test.js.map +1 -0
  176. package/dist/registry/ManagedRegistry.test.d.ts +21 -0
  177. package/dist/registry/ManagedRegistry.test.d.ts.map +1 -0
  178. package/dist/registry/ManagedRegistry.test.js +98 -0
  179. package/dist/registry/ManagedRegistry.test.js.map +1 -0
  180. package/dist/registry/Registry.test.d.ts +18 -0
  181. package/dist/registry/Registry.test.d.ts.map +1 -0
  182. package/dist/registry/Registry.test.js +79 -0
  183. package/dist/registry/Registry.test.js.map +1 -0
  184. package/dist/registry/agent/definitions.test.d.ts +15 -0
  185. package/dist/registry/agent/definitions.test.d.ts.map +1 -0
  186. package/dist/registry/agent/definitions.test.js +84 -0
  187. package/dist/registry/agent/definitions.test.js.map +1 -0
  188. package/dist/registry/connector/definitions.test.d.ts +13 -0
  189. package/dist/registry/connector/definitions.test.d.ts.map +1 -0
  190. package/dist/registry/connector/definitions.test.js +41 -0
  191. package/dist/registry/connector/definitions.test.js.map +1 -0
  192. package/dist/registry/connector/scoped.test.d.ts +21 -0
  193. package/dist/registry/connector/scoped.test.d.ts.map +1 -0
  194. package/dist/registry/connector/scoped.test.js +115 -0
  195. package/dist/registry/connector/scoped.test.js.map +1 -0
  196. package/dist/registry/plugin/index.test.d.ts +12 -0
  197. package/dist/registry/plugin/index.test.d.ts.map +1 -0
  198. package/dist/registry/plugin/index.test.js +69 -0
  199. package/dist/registry/plugin/index.test.js.map +1 -0
  200. package/dist/registry/tool/execute.test.d.ts +42 -0
  201. package/dist/registry/tool/execute.test.d.ts.map +1 -0
  202. package/dist/registry/tool/execute.test.js +281 -0
  203. package/dist/registry/tool/execute.test.js.map +1 -0
  204. package/dist/run/LimitChecker.d.ts +0 -1
  205. package/dist/run/LimitChecker.d.ts.map +1 -1
  206. package/dist/run/LimitChecker.js +0 -6
  207. package/dist/run/LimitChecker.js.map +1 -1
  208. package/dist/run/reporter.d.ts +2 -2
  209. package/dist/run/reporter.d.ts.map +1 -1
  210. package/dist/run/reporter.js.map +1 -1
  211. package/dist/runtime/query/__tests__/checkpoint.test.d.ts +2 -0
  212. package/dist/runtime/query/__tests__/checkpoint.test.d.ts.map +1 -0
  213. package/dist/runtime/query/__tests__/checkpoint.test.js +150 -0
  214. package/dist/runtime/query/__tests__/checkpoint.test.js.map +1 -0
  215. package/dist/runtime/query/checkpoint.d.ts +23 -0
  216. package/dist/runtime/query/checkpoint.d.ts.map +1 -1
  217. package/dist/runtime/query/checkpoint.js +49 -0
  218. package/dist/runtime/query/checkpoint.js.map +1 -1
  219. package/dist/runtime/query/context.d.ts +0 -2
  220. package/dist/runtime/query/context.d.ts.map +1 -1
  221. package/dist/runtime/query/context.js +0 -4
  222. package/dist/runtime/query/context.js.map +1 -1
  223. package/dist/runtime/query/index.d.ts +3 -3
  224. package/dist/runtime/query/index.d.ts.map +1 -1
  225. package/dist/runtime/query/iteration/phases/advisory.test.d.ts +42 -0
  226. package/dist/runtime/query/iteration/phases/advisory.test.d.ts.map +1 -0
  227. package/dist/runtime/query/iteration/phases/advisory.test.js +334 -0
  228. package/dist/runtime/query/iteration/phases/advisory.test.js.map +1 -0
  229. package/dist/runtime/query/replay/__tests__/mutate.test.d.ts +2 -0
  230. package/dist/runtime/query/replay/__tests__/mutate.test.d.ts.map +1 -0
  231. package/dist/runtime/query/replay/__tests__/mutate.test.js +123 -0
  232. package/dist/runtime/query/replay/__tests__/mutate.test.js.map +1 -0
  233. package/dist/runtime/query/replay/__tests__/prepare.test.d.ts +2 -0
  234. package/dist/runtime/query/replay/__tests__/prepare.test.d.ts.map +1 -0
  235. package/dist/runtime/query/replay/__tests__/prepare.test.js +171 -0
  236. package/dist/runtime/query/replay/__tests__/prepare.test.js.map +1 -0
  237. package/dist/runtime/query/replay/list.d.ts +24 -0
  238. package/dist/runtime/query/replay/list.d.ts.map +1 -0
  239. package/dist/runtime/query/replay/list.js +21 -0
  240. package/dist/runtime/query/replay/list.js.map +1 -0
  241. package/dist/runtime/query/replay/mutate.d.ts +17 -0
  242. package/dist/runtime/query/replay/mutate.d.ts.map +1 -0
  243. package/dist/runtime/query/replay/mutate.js +62 -0
  244. package/dist/runtime/query/replay/mutate.js.map +1 -0
  245. package/dist/runtime/query/replay/prepare.d.ts +56 -0
  246. package/dist/runtime/query/replay/prepare.d.ts.map +1 -0
  247. package/dist/runtime/query/replay/prepare.js +65 -0
  248. package/dist/runtime/query/replay/prepare.js.map +1 -0
  249. package/dist/runtime/query/result.d.ts +2 -2
  250. package/dist/runtime/query/result.d.ts.map +1 -1
  251. package/dist/session/__tests__/integration/_fixtures.d.ts +4 -4
  252. package/dist/session/__tests__/integration/_fixtures.d.ts.map +1 -1
  253. package/dist/session/__tests__/integration/_fixtures.js.map +1 -1
  254. package/dist/session/__tests__/integration/archive-gate.test.js.map +1 -1
  255. package/dist/session/__tests__/integration/capacity-caps.test.js.map +1 -1
  256. package/dist/session/__tests__/integration/e2e-spawn.test.js.map +1 -1
  257. package/dist/session/__tests__/integration/handoff-broadcast-e2e.test.js.map +1 -1
  258. package/dist/session/__tests__/integration/handoff-single-e2e.test.js.map +1 -1
  259. package/dist/session/__tests__/integration/prev-artifact-dag.test.js.map +1 -1
  260. package/dist/session/__tests__/integration/retention-archive.test.js.map +1 -1
  261. package/dist/session/__tests__/integration/spawn-rollback.test.js.map +1 -1
  262. package/dist/session/__tests__/integration/summary-materialization-e2e.test.js +1 -1
  263. package/dist/session/__tests__/integration/summary-materialization-e2e.test.js.map +1 -1
  264. package/dist/session/errors.d.ts +1 -1
  265. package/dist/session/errors.d.ts.map +1 -1
  266. package/dist/session/events/index.d.ts +3 -3
  267. package/dist/session/events/index.d.ts.map +1 -1
  268. package/dist/session/events/index.js +3 -2
  269. package/dist/session/events/index.js.map +1 -1
  270. package/dist/session/handoff/__tests__/broadcast.test.js.map +1 -1
  271. package/dist/session/handoff/__tests__/capacity.test.js.map +1 -1
  272. package/dist/session/handoff/__tests__/single.test.js.map +1 -1
  273. package/dist/session/handoff/assignment.d.ts +1 -1
  274. package/dist/session/handoff/assignment.d.ts.map +1 -1
  275. package/dist/session/handoff/broadcast.d.ts.map +1 -1
  276. package/dist/session/handoff/broadcast.js.map +1 -1
  277. package/dist/session/handoff/single.d.ts.map +1 -1
  278. package/dist/session/handoff/single.js.map +1 -1
  279. package/dist/session/index.d.ts +0 -1
  280. package/dist/session/index.d.ts.map +1 -1
  281. package/dist/session/index.js +7 -6
  282. package/dist/session/index.js.map +1 -1
  283. package/dist/session/intervention/__tests__/prev-artifact.test.js.map +1 -1
  284. package/dist/session/intervention/prev-artifact.d.ts +1 -1
  285. package/dist/session/intervention/prev-artifact.d.ts.map +1 -1
  286. package/dist/session/retention/__tests__/archive.test.js.map +1 -1
  287. package/dist/session/retention/__tests__/disk-backend.test.js.map +1 -1
  288. package/dist/session/retention/archive.d.ts +1 -1
  289. package/dist/session/retention/archive.d.ts.map +1 -1
  290. package/dist/session/retention/backend.d.ts +4 -4
  291. package/dist/session/retention/backend.d.ts.map +1 -1
  292. package/dist/session/retention/disk-backend.d.ts +1 -1
  293. package/dist/session/retention/disk-backend.d.ts.map +1 -1
  294. package/dist/session/retention/index.d.ts +3 -3
  295. package/dist/session/retention/index.d.ts.map +1 -1
  296. package/dist/session/retention/index.js +4 -2
  297. package/dist/session/retention/index.js.map +1 -1
  298. package/dist/session/status/__tests__/derive.test.d.ts +2 -0
  299. package/dist/session/status/__tests__/derive.test.d.ts.map +1 -0
  300. package/dist/session/{hierarchy/__tests__/session.test.js → status/__tests__/derive.test.js} +2 -2
  301. package/dist/session/status/__tests__/derive.test.js.map +1 -0
  302. package/dist/session/status/derive.d.ts +33 -0
  303. package/dist/session/status/derive.d.ts.map +1 -0
  304. package/dist/session/{hierarchy/session.js → status/derive.js} +6 -1
  305. package/dist/session/status/derive.js.map +1 -0
  306. package/dist/session/summary/__tests__/materialize.test.js +2 -1
  307. package/dist/session/summary/__tests__/materialize.test.js.map +1 -1
  308. package/dist/session/summary/errors.d.ts +43 -0
  309. package/dist/session/summary/errors.d.ts.map +1 -0
  310. package/dist/session/summary/errors.js +37 -0
  311. package/dist/session/summary/errors.js.map +1 -0
  312. package/dist/session/summary/index.d.ts +4 -3
  313. package/dist/session/summary/index.d.ts.map +1 -1
  314. package/dist/session/summary/index.js +5 -4
  315. package/dist/session/summary/index.js.map +1 -1
  316. package/dist/session/summary/materialize.d.ts +2 -2
  317. package/dist/session/summary/materialize.d.ts.map +1 -1
  318. package/dist/session/summary/materialize.js +2 -1
  319. package/dist/session/summary/materialize.js.map +1 -1
  320. package/dist/session/workspace/__tests__/git-worktree.test.js.map +1 -1
  321. package/dist/session/workspace/driver.d.ts +2 -2
  322. package/dist/session/workspace/driver.d.ts.map +1 -1
  323. package/dist/session/workspace/git-worktree.d.ts +1 -1
  324. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  325. package/dist/session/workspace/git-worktree.js.map +1 -1
  326. package/dist/session/workspace/index.d.ts +1 -1
  327. package/dist/session/workspace/index.d.ts.map +1 -1
  328. package/dist/session/workspace/index.js +3 -2
  329. package/dist/session/workspace/index.js.map +1 -1
  330. package/dist/store/run/disk.d.ts +4 -4
  331. package/dist/store/run/disk.d.ts.map +1 -1
  332. package/dist/store/run/disk.js.map +1 -1
  333. package/dist/store/session/__tests__/disk.test.js.map +1 -1
  334. package/dist/store/session/__tests__/memory.test.js.map +1 -1
  335. package/dist/store/session/disk.d.ts +6 -6
  336. package/dist/store/session/disk.d.ts.map +1 -1
  337. package/dist/store/session/disk.js +1 -1
  338. package/dist/store/session/disk.js.map +1 -1
  339. package/dist/store/session/index.d.ts +1 -1
  340. package/dist/store/session/index.d.ts.map +1 -1
  341. package/dist/store/session/index.js +2 -1
  342. package/dist/store/session/index.js.map +1 -1
  343. package/dist/store/session/linkage.d.ts +1 -1
  344. package/dist/store/session/linkage.d.ts.map +1 -1
  345. package/dist/store/session/memory.d.ts +5 -5
  346. package/dist/store/session/memory.d.ts.map +1 -1
  347. package/dist/store/session/memory.js +1 -1
  348. package/dist/store/session/memory.js.map +1 -1
  349. package/dist/store/thread/disk.d.ts +1 -1
  350. package/dist/store/thread/disk.d.ts.map +1 -1
  351. package/dist/store/thread/memory.d.ts +1 -1
  352. package/dist/store/thread/memory.d.ts.map +1 -1
  353. package/dist/telemetry/attributes.d.ts +0 -1
  354. package/dist/telemetry/attributes.d.ts.map +1 -1
  355. package/dist/telemetry/attributes.js +0 -3
  356. package/dist/telemetry/attributes.js.map +1 -1
  357. package/dist/telemetry/runtime-accessors.d.ts +1 -2
  358. package/dist/telemetry/runtime-accessors.d.ts.map +1 -1
  359. package/dist/telemetry/runtime-accessors.js +1 -4
  360. package/dist/telemetry/runtime-accessors.js.map +1 -1
  361. package/dist/test-setup.d.ts +22 -0
  362. package/dist/test-setup.d.ts.map +1 -0
  363. package/dist/test-setup.js +23 -0
  364. package/dist/test-setup.js.map +1 -0
  365. package/dist/tools/builtins/bash.d.ts +1 -1
  366. package/dist/tools/builtins/computer-use.d.ts +4 -4
  367. package/dist/tools/builtins/edit.d.ts +1 -1
  368. package/dist/tools/builtins/glob.d.ts +1 -1
  369. package/dist/tools/builtins/grep.d.ts +1 -1
  370. package/dist/tools/builtins/ls.d.ts +1 -1
  371. package/dist/tools/builtins/read-file.d.ts +1 -1
  372. package/dist/tools/builtins/search-tools.d.ts +1 -1
  373. package/dist/tools/builtins/write-file.d.ts +1 -1
  374. package/dist/types/agent/task.d.ts +2 -2
  375. package/dist/types/agent/task.d.ts.map +1 -1
  376. package/dist/{session/hierarchy/project.d.ts → types/project/entity.d.ts} +4 -4
  377. package/dist/types/project/entity.d.ts.map +1 -0
  378. package/dist/types/project/entity.js +2 -0
  379. package/dist/types/project/entity.js.map +1 -0
  380. package/dist/types/project/index.d.ts +2 -0
  381. package/dist/types/project/index.d.ts.map +1 -0
  382. package/dist/types/project/index.js +4 -0
  383. package/dist/types/project/index.js.map +1 -0
  384. package/dist/types/retention/archive-backend-ref.d.ts.map +1 -0
  385. package/dist/types/retention/archive-backend-ref.js.map +1 -0
  386. package/dist/types/retention/index.d.ts +4 -0
  387. package/dist/types/retention/index.d.ts.map +1 -0
  388. package/dist/types/retention/index.js +4 -0
  389. package/dist/types/retention/index.js.map +1 -0
  390. package/dist/types/retention/policy.d.ts.map +1 -0
  391. package/dist/types/retention/policy.js.map +1 -0
  392. package/dist/types/run/entity.d.ts +56 -0
  393. package/dist/types/run/entity.d.ts.map +1 -0
  394. package/dist/types/run/entity.js +2 -0
  395. package/dist/types/run/entity.js.map +1 -0
  396. package/dist/types/run/events.d.ts +2 -2
  397. package/dist/types/run/events.d.ts.map +1 -1
  398. package/dist/types/run/index.d.ts +7 -1
  399. package/dist/types/run/index.d.ts.map +1 -1
  400. package/dist/types/run/index.js +8 -9
  401. package/dist/types/run/index.js.map +1 -1
  402. package/dist/{session/hierarchy → types/run}/lineage.d.ts +1 -1
  403. package/dist/types/run/lineage.d.ts.map +1 -0
  404. package/dist/types/run/lineage.js.map +1 -0
  405. package/dist/types/run/replay.d.ts +53 -0
  406. package/dist/types/run/replay.d.ts.map +1 -0
  407. package/dist/types/run/replay.js +15 -0
  408. package/dist/types/run/replay.js.map +1 -0
  409. package/dist/types/run/schema-version.d.ts.map +1 -0
  410. package/dist/types/run/schema-version.js.map +1 -0
  411. package/dist/{session/events/types.d.ts → types/run/subsession-events.d.ts} +5 -5
  412. package/dist/types/run/subsession-events.d.ts.map +1 -0
  413. package/dist/types/run/subsession-events.js +2 -0
  414. package/dist/types/run/subsession-events.js.map +1 -0
  415. package/dist/{session/hierarchy → types/session}/actor.d.ts +1 -1
  416. package/dist/types/session/actor.d.ts.map +1 -0
  417. package/dist/{session/hierarchy → types/session}/actor.js.map +1 -1
  418. package/dist/types/session/entity.d.ts +51 -0
  419. package/dist/types/session/entity.d.ts.map +1 -0
  420. package/dist/types/session/entity.js +2 -0
  421. package/dist/types/session/entity.js.map +1 -0
  422. package/dist/types/session/index.d.ts +4 -0
  423. package/dist/types/session/index.d.ts.map +1 -1
  424. package/dist/{store → types}/session/messages.d.ts +2 -2
  425. package/dist/{store → types}/session/messages.d.ts.map +1 -1
  426. package/dist/types/session/messages.js.map +1 -0
  427. package/dist/types/session/store.d.ts +6 -6
  428. package/dist/types/session/store.d.ts.map +1 -1
  429. package/dist/{session/hierarchy → types/session}/sub-session.d.ts +9 -9
  430. package/dist/types/session/sub-session.d.ts.map +1 -0
  431. package/dist/types/session/sub-session.js.map +1 -0
  432. package/dist/{session → types}/summary/deliverable.d.ts +2 -2
  433. package/dist/types/summary/deliverable.d.ts.map +1 -0
  434. package/dist/types/summary/deliverable.js.map +1 -0
  435. package/dist/types/summary/index.d.ts +4 -0
  436. package/dist/types/summary/index.d.ts.map +1 -0
  437. package/dist/types/summary/index.js +4 -0
  438. package/dist/types/summary/index.js.map +1 -0
  439. package/dist/{session → types}/summary/ref.d.ts +9 -36
  440. package/dist/types/summary/ref.d.ts.map +1 -0
  441. package/dist/types/summary/ref.js +28 -0
  442. package/dist/types/summary/ref.js.map +1 -0
  443. package/dist/{session/hierarchy/tenant.d.ts → types/tenant/entity.d.ts} +2 -2
  444. package/dist/types/tenant/entity.d.ts.map +1 -0
  445. package/dist/types/tenant/entity.js +2 -0
  446. package/dist/types/tenant/entity.js.map +1 -0
  447. package/dist/types/tenant/index.d.ts +2 -0
  448. package/dist/types/tenant/index.d.ts.map +1 -0
  449. package/dist/types/tenant/index.js +4 -0
  450. package/dist/types/tenant/index.js.map +1 -0
  451. package/dist/{session/hierarchy/thread.d.ts → types/thread/entity.d.ts} +31 -7
  452. package/dist/types/thread/entity.d.ts.map +1 -0
  453. package/dist/types/thread/entity.js +2 -0
  454. package/dist/types/thread/entity.js.map +1 -0
  455. package/dist/types/thread/index.d.ts +1 -0
  456. package/dist/types/thread/index.d.ts.map +1 -1
  457. package/dist/types/thread/store.d.ts +1 -1
  458. package/dist/types/thread/store.d.ts.map +1 -1
  459. package/dist/types/workspace/index.d.ts +2 -0
  460. package/dist/types/workspace/index.d.ts.map +1 -0
  461. package/dist/types/workspace/index.js +7 -0
  462. package/dist/types/workspace/index.js.map +1 -0
  463. package/dist/{session → types}/workspace/ref.d.ts +1 -1
  464. package/dist/types/workspace/ref.d.ts.map +1 -0
  465. package/dist/types/workspace/ref.js.map +1 -0
  466. package/dist/utils/logger.d.ts +1 -1
  467. package/dist/utils/logger.d.ts.map +1 -1
  468. package/dist/utils/logger.js +5 -0
  469. package/dist/utils/logger.js.map +1 -1
  470. package/package.json +4 -1
  471. package/src/__tests__/replay-public-surface.test.ts +54 -0
  472. package/src/advisory/context.test.ts +109 -0
  473. package/src/advisory/evaluator.test.ts +192 -0
  474. package/src/advisory/executor.test.ts +272 -0
  475. package/src/advisory/registry.test.ts +75 -0
  476. package/src/agents/SupervisorAgent.ts +1 -1
  477. package/src/bridge/a2a/agent-card.test.ts +140 -0
  478. package/src/bridge/a2a/mapper.test.ts +293 -0
  479. package/src/bridge/a2a/message.test.ts +138 -0
  480. package/src/bridge/a2a/task.test.ts +235 -0
  481. package/src/bridge/a2a/task.ts +4 -4
  482. package/src/bridge/mcp/connector/adapter.test.ts +230 -0
  483. package/src/bridge/sse/mapper.test.ts +422 -0
  484. package/src/bridge/tools/connector/adapter.test.ts +224 -0
  485. package/src/bridge/tools/connector/definitions.test.ts +183 -0
  486. package/src/bridge/tools/connector/router.test.ts +159 -0
  487. package/src/bus/breaker.test.ts +274 -0
  488. package/src/bus/index.test.ts +183 -0
  489. package/src/bus/lock.test.ts +265 -0
  490. package/src/bus/ownership.test.ts +243 -0
  491. package/src/config/runtime.ts +0 -2
  492. package/src/connector/BaseConnector.test.ts +130 -0
  493. package/src/connector/builtins/http.test.ts +290 -0
  494. package/src/connector/builtins/webhook.test.ts +138 -0
  495. package/src/connector/execution/factory.test.ts +75 -0
  496. package/src/connector/execution/remote.test.ts +63 -0
  497. package/src/connector/mcp/adapter.test.ts +249 -0
  498. package/src/contracts/api.ts +2 -2
  499. package/src/contracts/index.ts +1 -3
  500. package/src/index.ts +11 -362
  501. package/src/manager/agent/__tests__/lifecycle.test.ts +2 -2
  502. package/src/manager/agent/lifecycle.ts +5 -5
  503. package/src/manager/run/persistence.ts +4 -4
  504. package/src/manager/thread/__tests__/lifecycle.test.ts +1 -1
  505. package/src/manager/thread/lifecycle.ts +2 -2
  506. package/src/plugin/loader.ts +0 -16
  507. package/src/public-runtime.ts +373 -0
  508. package/src/public-tools.ts +63 -0
  509. package/src/public-types.ts +156 -0
  510. package/src/rag/chunking.test.ts +107 -0
  511. package/src/rag/context-assembler.test.ts +114 -0
  512. package/src/rag/embedding.test.ts +130 -0
  513. package/src/rag/ingestion.test.ts +114 -0
  514. package/src/rag/knowledge-base.test.ts +106 -0
  515. package/src/rag/rag-tool.test.ts +167 -0
  516. package/src/rag/retriever.test.ts +210 -0
  517. package/src/rag/vector-store.test.ts +196 -0
  518. package/src/registry/ManagedRegistry.test.ts +118 -0
  519. package/src/registry/Registry.test.ts +91 -0
  520. package/src/registry/agent/definitions.test.ts +100 -0
  521. package/src/registry/connector/definitions.test.ts +51 -0
  522. package/src/registry/connector/scoped.test.ts +129 -0
  523. package/src/registry/plugin/index.test.ts +85 -0
  524. package/src/registry/tool/execute.test.ts +330 -0
  525. package/src/run/LimitChecker.ts +0 -9
  526. package/src/run/reporter.ts +3 -3
  527. package/src/runtime/query/__tests__/checkpoint.test.ts +169 -0
  528. package/src/runtime/query/checkpoint.ts +54 -0
  529. package/src/runtime/query/context.ts +0 -5
  530. package/src/runtime/query/index.ts +4 -4
  531. package/src/runtime/query/iteration/phases/advisory.test.ts +412 -0
  532. package/src/runtime/query/replay/__tests__/mutate.test.ts +134 -0
  533. package/src/runtime/query/replay/__tests__/prepare.test.ts +207 -0
  534. package/src/runtime/query/replay/list.ts +32 -0
  535. package/src/runtime/query/replay/mutate.ts +76 -0
  536. package/src/runtime/query/replay/prepare.ts +114 -0
  537. package/src/runtime/query/result.ts +2 -2
  538. package/src/session/__tests__/integration/_fixtures.ts +2 -2
  539. package/src/session/__tests__/integration/archive-gate.test.ts +1 -1
  540. package/src/session/__tests__/integration/capacity-caps.test.ts +1 -1
  541. package/src/session/__tests__/integration/e2e-spawn.test.ts +1 -1
  542. package/src/session/__tests__/integration/handoff-broadcast-e2e.test.ts +1 -1
  543. package/src/session/__tests__/integration/handoff-single-e2e.test.ts +1 -1
  544. package/src/session/__tests__/integration/prev-artifact-dag.test.ts +4 -1
  545. package/src/session/__tests__/integration/retention-archive.test.ts +1 -1
  546. package/src/session/__tests__/integration/spawn-rollback.test.ts +2 -2
  547. package/src/session/__tests__/integration/summary-materialization-e2e.test.ts +1 -1
  548. package/src/session/errors.ts +1 -1
  549. package/src/session/events/index.ts +5 -4
  550. package/src/session/handoff/__tests__/broadcast.test.ts +1 -1
  551. package/src/session/handoff/__tests__/capacity.test.ts +1 -1
  552. package/src/session/handoff/__tests__/single.test.ts +1 -1
  553. package/src/session/handoff/assignment.ts +1 -1
  554. package/src/session/handoff/broadcast.ts +2 -2
  555. package/src/session/handoff/single.ts +2 -2
  556. package/src/session/index.ts +7 -6
  557. package/src/session/intervention/__tests__/prev-artifact.test.ts +4 -1
  558. package/src/session/intervention/prev-artifact.ts +1 -1
  559. package/src/session/retention/__tests__/archive.test.ts +3 -3
  560. package/src/session/retention/__tests__/disk-backend.test.ts +4 -4
  561. package/src/session/retention/archive.ts +2 -2
  562. package/src/session/retention/backend.ts +4 -4
  563. package/src/session/retention/disk-backend.ts +4 -4
  564. package/src/session/retention/index.ts +6 -4
  565. package/src/session/{hierarchy/__tests__/session.test.ts → status/__tests__/derive.test.ts} +3 -2
  566. package/src/session/{hierarchy/session.ts → status/derive.ts} +9 -55
  567. package/src/session/summary/__tests__/materialize.test.ts +4 -7
  568. package/src/session/summary/errors.ts +51 -0
  569. package/src/session/summary/index.ts +7 -10
  570. package/src/session/summary/materialize.ts +4 -5
  571. package/src/session/workspace/__tests__/git-worktree.test.ts +1 -1
  572. package/src/session/workspace/driver.ts +2 -2
  573. package/src/session/workspace/git-worktree.ts +1 -1
  574. package/src/session/workspace/index.ts +7 -6
  575. package/src/store/run/disk.ts +4 -4
  576. package/src/store/session/__tests__/disk.test.ts +2 -2
  577. package/src/store/session/__tests__/memory.test.ts +2 -2
  578. package/src/store/session/disk.ts +12 -12
  579. package/src/store/session/index.ts +3 -2
  580. package/src/store/session/linkage.ts +1 -1
  581. package/src/store/session/memory.ts +6 -6
  582. package/src/store/thread/disk.ts +1 -1
  583. package/src/store/thread/memory.ts +1 -1
  584. package/src/telemetry/attributes.ts +0 -4
  585. package/src/telemetry/runtime-accessors.ts +1 -5
  586. package/src/test-setup.ts +24 -0
  587. package/src/types/agent/task.ts +2 -2
  588. package/src/{session/hierarchy/project.ts → types/project/entity.ts} +3 -3
  589. package/src/types/project/index.ts +4 -0
  590. package/src/types/retention/index.ts +6 -0
  591. package/src/types/run/entity.ts +63 -0
  592. package/src/types/run/events.ts +6 -6
  593. package/src/types/run/index.ts +16 -9
  594. package/src/{session/hierarchy → types/run}/lineage.ts +1 -1
  595. package/src/types/run/replay.ts +61 -0
  596. package/src/{session/events/types.ts → types/run/subsession-events.ts} +4 -4
  597. package/src/{session/hierarchy → types/session}/actor.ts +1 -1
  598. package/src/types/session/entity.ts +59 -0
  599. package/src/types/session/index.ts +15 -0
  600. package/src/{store → types}/session/messages.ts +2 -2
  601. package/src/types/session/store.ts +6 -6
  602. package/src/{session/hierarchy → types/session}/sub-session.ts +9 -9
  603. package/src/{session → types}/summary/deliverable.ts +2 -2
  604. package/src/types/summary/index.ts +18 -0
  605. package/src/{session → types}/summary/ref.ts +9 -44
  606. package/src/{session/hierarchy/tenant.ts → types/tenant/entity.ts} +1 -1
  607. package/src/types/tenant/index.ts +4 -0
  608. package/src/{session/hierarchy/thread.ts → types/thread/entity.ts} +30 -6
  609. package/src/types/thread/index.ts +1 -0
  610. package/src/types/thread/store.ts +1 -1
  611. package/src/types/workspace/index.ts +12 -0
  612. package/src/{session → types}/workspace/ref.ts +1 -1
  613. package/src/utils/logger.ts +6 -1
  614. package/dist/contracts/ids.d.ts +0 -2
  615. package/dist/contracts/ids.d.ts.map +0 -1
  616. package/dist/contracts/ids.js +0 -2
  617. package/dist/contracts/ids.js.map +0 -1
  618. package/dist/session/events/schema-version.d.ts.map +0 -1
  619. package/dist/session/events/schema-version.js.map +0 -1
  620. package/dist/session/events/types.d.ts.map +0 -1
  621. package/dist/session/events/types.js +0 -2
  622. package/dist/session/events/types.js.map +0 -1
  623. package/dist/session/hierarchy/__tests__/session.test.d.ts +0 -2
  624. package/dist/session/hierarchy/__tests__/session.test.d.ts.map +0 -1
  625. package/dist/session/hierarchy/__tests__/session.test.js.map +0 -1
  626. package/dist/session/hierarchy/actor.d.ts.map +0 -1
  627. package/dist/session/hierarchy/index.d.ts +0 -9
  628. package/dist/session/hierarchy/index.d.ts.map +0 -1
  629. package/dist/session/hierarchy/index.js +0 -4
  630. package/dist/session/hierarchy/index.js.map +0 -1
  631. package/dist/session/hierarchy/lineage.d.ts.map +0 -1
  632. package/dist/session/hierarchy/lineage.js.map +0 -1
  633. package/dist/session/hierarchy/project.d.ts.map +0 -1
  634. package/dist/session/hierarchy/project.js +0 -2
  635. package/dist/session/hierarchy/project.js.map +0 -1
  636. package/dist/session/hierarchy/session.d.ts +0 -71
  637. package/dist/session/hierarchy/session.d.ts.map +0 -1
  638. package/dist/session/hierarchy/session.js.map +0 -1
  639. package/dist/session/hierarchy/sub-session.d.ts.map +0 -1
  640. package/dist/session/hierarchy/sub-session.js.map +0 -1
  641. package/dist/session/hierarchy/tenant.d.ts.map +0 -1
  642. package/dist/session/hierarchy/tenant.js +0 -2
  643. package/dist/session/hierarchy/tenant.js.map +0 -1
  644. package/dist/session/hierarchy/thread.d.ts.map +0 -1
  645. package/dist/session/hierarchy/thread.js +0 -2
  646. package/dist/session/hierarchy/thread.js.map +0 -1
  647. package/dist/session/retention/archive-backend-ref.d.ts.map +0 -1
  648. package/dist/session/retention/archive-backend-ref.js.map +0 -1
  649. package/dist/session/retention/policy.d.ts.map +0 -1
  650. package/dist/session/retention/policy.js.map +0 -1
  651. package/dist/session/summary/deliverable.d.ts.map +0 -1
  652. package/dist/session/summary/deliverable.js.map +0 -1
  653. package/dist/session/summary/ref.d.ts.map +0 -1
  654. package/dist/session/summary/ref.js +0 -51
  655. package/dist/session/summary/ref.js.map +0 -1
  656. package/dist/session/workspace/ref.d.ts.map +0 -1
  657. package/dist/session/workspace/ref.js.map +0 -1
  658. package/dist/store/session/messages.js.map +0 -1
  659. package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts +0 -140
  660. package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts.map +0 -1
  661. package/dist/tools/builtins/__tests__/structuredOutput.example.js +0 -183
  662. package/dist/tools/builtins/__tests__/structuredOutput.example.js.map +0 -1
  663. package/dist/types/run/state.d.ts +0 -30
  664. package/dist/types/run/state.d.ts.map +0 -1
  665. package/dist/types/run/state.js +0 -2
  666. package/dist/types/run/state.js.map +0 -1
  667. package/src/contracts/ids.ts +0 -1
  668. package/src/session/hierarchy/index.ts +0 -18
  669. package/src/tools/builtins/__tests__/structuredOutput.example.ts +0 -221
  670. package/src/types/run/state.ts +0 -35
  671. /package/dist/{session → types}/retention/archive-backend-ref.d.ts +0 -0
  672. /package/dist/{session → types}/retention/archive-backend-ref.js +0 -0
  673. /package/dist/{session → types}/retention/policy.d.ts +0 -0
  674. /package/dist/{session → types}/retention/policy.js +0 -0
  675. /package/dist/{session/hierarchy → types/run}/lineage.js +0 -0
  676. /package/dist/{session/events → types/run}/schema-version.d.ts +0 -0
  677. /package/dist/{session/events → types/run}/schema-version.js +0 -0
  678. /package/dist/{session/hierarchy → types/session}/actor.js +0 -0
  679. /package/dist/{store → types}/session/messages.js +0 -0
  680. /package/dist/{session/hierarchy → types/session}/sub-session.js +0 -0
  681. /package/dist/{session → types}/summary/deliverable.js +0 -0
  682. /package/dist/{session → types}/workspace/ref.js +0 -0
  683. /package/src/{session → types}/retention/archive-backend-ref.ts +0 -0
  684. /package/src/{session → types}/retention/policy.ts +0 -0
  685. /package/src/{session/events → types/run}/schema-version.ts +0 -0
@@ -0,0 +1,123 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { MutationNotApplicableError } from '../../../../types/run/replay.js';
3
+ import { applyMutations } from '../mutate.js';
4
+ function assistantWithCalls(toolCallIds) {
5
+ return {
6
+ role: 'assistant',
7
+ content: null,
8
+ toolCalls: toolCallIds.map((id) => ({
9
+ id,
10
+ type: 'function',
11
+ function: { name: 'noop', arguments: '{}' },
12
+ })),
13
+ };
14
+ }
15
+ describe('applyMutations / injectToolResponse', () => {
16
+ it('appends a ToolMessage when the toolCallId is pending', () => {
17
+ const messages = [
18
+ { role: 'user', content: 'do stuff' },
19
+ assistantWithCalls(['call_a', 'call_b']),
20
+ { role: 'tool', content: 'a done', toolCallId: 'call_a' },
21
+ ];
22
+ const mutations = [
23
+ {
24
+ type: 'injectToolResponse',
25
+ toolCallId: 'call_b',
26
+ response: { success: true, output: 'mocked-b', data: { x: 1 } },
27
+ },
28
+ ];
29
+ const result = applyMutations(messages, mutations);
30
+ expect(result).toHaveLength(4);
31
+ const last = result[3];
32
+ expect(last.role).toBe('tool');
33
+ expect(last.toolCallId).toBe('call_b');
34
+ expect(last.content).toBe('mocked-b');
35
+ });
36
+ it('throws MutationNotApplicableError when no pending tool calls exist', () => {
37
+ const messages = [
38
+ { role: 'user', content: 'hi' },
39
+ { role: 'assistant', content: 'hello' },
40
+ ];
41
+ expect(() => applyMutations(messages, [
42
+ {
43
+ type: 'injectToolResponse',
44
+ toolCallId: 'call_missing',
45
+ response: { success: true, output: 'x' },
46
+ },
47
+ ])).toThrow(MutationNotApplicableError);
48
+ });
49
+ it('throws with availableToolCallIds populated when toolCallId is not pending', () => {
50
+ const messages = [
51
+ { role: 'user', content: 'do stuff' },
52
+ assistantWithCalls(['call_a', 'call_b']),
53
+ ];
54
+ try {
55
+ applyMutations(messages, [
56
+ {
57
+ type: 'injectToolResponse',
58
+ toolCallId: 'call_z',
59
+ response: { success: true, output: 'x' },
60
+ },
61
+ ]);
62
+ expect.fail('expected MutationNotApplicableError');
63
+ }
64
+ catch (err) {
65
+ expect(err).toBeInstanceOf(MutationNotApplicableError);
66
+ const e = err;
67
+ expect(e.availableToolCallIds).toEqual(['call_a', 'call_b']);
68
+ }
69
+ });
70
+ it('considers a tool call satisfied only when a subsequent ToolMessage responds to it', () => {
71
+ const messages = [
72
+ { role: 'user', content: 'do stuff' },
73
+ assistantWithCalls(['call_a', 'call_b', 'call_c']),
74
+ { role: 'tool', content: 'a done', toolCallId: 'call_a' },
75
+ { role: 'tool', content: 'c done', toolCallId: 'call_c' },
76
+ ];
77
+ try {
78
+ applyMutations(messages, [
79
+ {
80
+ type: 'injectToolResponse',
81
+ toolCallId: 'call_a',
82
+ response: { success: true, output: 're-answered' },
83
+ },
84
+ ]);
85
+ expect.fail('expected MutationNotApplicableError — call_a already satisfied');
86
+ }
87
+ catch (err) {
88
+ const e = err;
89
+ expect(e.availableToolCallIds).toEqual(['call_b']);
90
+ }
91
+ });
92
+ it('applies mutations in order so a later mutation sees earlier ones', () => {
93
+ const messages = [
94
+ { role: 'user', content: 'two calls pending' },
95
+ assistantWithCalls(['call_x', 'call_y']),
96
+ ];
97
+ const result = applyMutations(messages, [
98
+ {
99
+ type: 'injectToolResponse',
100
+ toolCallId: 'call_x',
101
+ response: { success: true, output: 'x-result' },
102
+ },
103
+ {
104
+ type: 'injectToolResponse',
105
+ toolCallId: 'call_y',
106
+ response: { success: true, output: 'y-result' },
107
+ },
108
+ ]);
109
+ expect(result).toHaveLength(4);
110
+ expect(result[2].toolCallId).toBe('call_x');
111
+ expect(result[3].toolCallId).toBe('call_y');
112
+ });
113
+ it('returns the original messages unchanged when the mutation list is empty', () => {
114
+ const messages = [
115
+ { role: 'user', content: 'no-op' },
116
+ { role: 'assistant', content: 'ok' },
117
+ ];
118
+ const result = applyMutations(messages, []);
119
+ expect(result).toEqual(messages);
120
+ expect(result).not.toBe(messages);
121
+ });
122
+ });
123
+ //# sourceMappingURL=mutate.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutate.test.js","sourceRoot":"","sources":["../../../../../src/runtime/query/replay/__tests__/mutate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAG7C,OAAO,EAAiB,0BAA0B,EAAE,MAAM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../src/runtime/query/replay/__tests__/prepare.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,171 @@
1
+ import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
5
+ import { prepareReplayState } from '../prepare.js';
6
+ const RUN_ID = 'run_source';
7
+ function makeCheckpoint(overrides) {
8
+ return {
9
+ id: 'cp_default',
10
+ runId: RUN_ID,
11
+ iteration: 1,
12
+ messages: [{ role: 'user', content: 'hi' }],
13
+ tokenUsage: {
14
+ promptTokens: 0,
15
+ completionTokens: 0,
16
+ totalTokens: 0,
17
+ cachedTokens: 0,
18
+ cacheWriteTokens: 0,
19
+ },
20
+ costInfo: { inputCostPer1M: 0, outputCostPer1M: 0, totalCost: 0, cacheDiscount: 0 },
21
+ guardState: { iterationCount: 1, elapsedMs: 0 },
22
+ createdAt: Date.now(),
23
+ ...overrides,
24
+ };
25
+ }
26
+ async function seedCheckpoint(baseDir, cp) {
27
+ const cpDir = join(baseDir, cp.runId, 'checkpoints');
28
+ await mkdir(cpDir, { recursive: true });
29
+ await writeFile(join(cpDir, `${cp.id}.json`), JSON.stringify(cp), 'utf-8');
30
+ }
31
+ async function seedEmergency(emergencyDir, dump) {
32
+ await mkdir(emergencyDir, { recursive: true });
33
+ await writeFile(join(emergencyDir, `${dump.runId}.json`), JSON.stringify(dump), 'utf-8');
34
+ }
35
+ describe('prepareReplayState', () => {
36
+ let baseDir;
37
+ let emergencyDir;
38
+ beforeEach(async () => {
39
+ const wrapper = await mkdtemp(join(tmpdir(), 'namzu-prepare-replay-'));
40
+ baseDir = join(wrapper, 'runs');
41
+ emergencyDir = join(wrapper, 'emergency');
42
+ await mkdir(baseDir, { recursive: true });
43
+ });
44
+ afterEach(async () => {
45
+ // Per-test tmpdir isolation; vitest cleans tmpdir between runs.
46
+ });
47
+ it('resolves a specific CheckpointId and returns the checkpoint messages', async () => {
48
+ const cp = makeCheckpoint({
49
+ id: 'cp_one',
50
+ iteration: 3,
51
+ messages: [
52
+ { role: 'user', content: 'start' },
53
+ { role: 'assistant', content: 'ok' },
54
+ ],
55
+ });
56
+ await seedCheckpoint(baseDir, cp);
57
+ const prepared = await prepareReplayState({
58
+ baseDir,
59
+ runId: RUN_ID,
60
+ fromCheckpoint: 'cp_one',
61
+ });
62
+ expect(prepared.sourceCheckpoint.id).toBe('cp_one');
63
+ expect(prepared.messages).toEqual(cp.messages);
64
+ expect(prepared.attribution.sourceRunId).toBe(RUN_ID);
65
+ expect(prepared.attribution.fromCheckpointId).toBe('cp_one');
66
+ expect(prepared.attribution.mutations).toEqual([]);
67
+ expect(prepared.attribution.replayedAt).toBeGreaterThan(0);
68
+ });
69
+ it("resolves 'latest' to the checkpoint with the highest iteration", async () => {
70
+ await seedCheckpoint(baseDir, makeCheckpoint({ id: 'cp_a', iteration: 1 }));
71
+ await seedCheckpoint(baseDir, makeCheckpoint({ id: 'cp_b', iteration: 5 }));
72
+ await seedCheckpoint(baseDir, makeCheckpoint({ id: 'cp_c', iteration: 3 }));
73
+ const prepared = await prepareReplayState({
74
+ baseDir,
75
+ runId: RUN_ID,
76
+ fromCheckpoint: 'latest',
77
+ });
78
+ expect(prepared.sourceCheckpoint.id).toBe('cp_b');
79
+ expect(prepared.sourceCheckpoint.iteration).toBe(5);
80
+ });
81
+ it("throws when 'latest' is requested but no checkpoints exist", async () => {
82
+ await expect(prepareReplayState({
83
+ baseDir,
84
+ runId: RUN_ID,
85
+ fromCheckpoint: 'latest',
86
+ })).rejects.toThrow(/No checkpoints found/);
87
+ });
88
+ it('throws when a specific CheckpointId does not resolve', async () => {
89
+ await expect(prepareReplayState({
90
+ baseDir,
91
+ runId: RUN_ID,
92
+ fromCheckpoint: 'cp_missing',
93
+ })).rejects.toThrow(/not found/);
94
+ });
95
+ it('applies injectToolResponse mutations at the fork point', async () => {
96
+ const assistantMsg = {
97
+ role: 'assistant',
98
+ content: null,
99
+ toolCalls: [{ id: 'call_a', type: 'function', function: { name: 'noop', arguments: '{}' } }],
100
+ };
101
+ const cp = makeCheckpoint({
102
+ id: 'cp_with_tool',
103
+ messages: [{ role: 'user', content: 'run tool' }, assistantMsg],
104
+ });
105
+ await seedCheckpoint(baseDir, cp);
106
+ const mutations = [
107
+ {
108
+ type: 'injectToolResponse',
109
+ toolCallId: 'call_a',
110
+ response: { success: true, output: 'mocked-a' },
111
+ },
112
+ ];
113
+ const prepared = await prepareReplayState({
114
+ baseDir,
115
+ runId: RUN_ID,
116
+ fromCheckpoint: 'cp_with_tool',
117
+ mutate: mutations,
118
+ });
119
+ expect(prepared.messages).toHaveLength(3);
120
+ const appended = prepared.messages[2];
121
+ expect(appended.role).toBe('tool');
122
+ expect(appended.toolCallId).toBe('call_a');
123
+ expect(appended.content).toBe('mocked-a');
124
+ expect(prepared.attribution.mutations).toEqual(mutations);
125
+ });
126
+ it("resolves 'emergency' via the emergency dump and projects it to a checkpoint", async () => {
127
+ const dump = {
128
+ id: 'esave_xyz',
129
+ runId: RUN_ID,
130
+ messages: [{ role: 'user', content: 'before crash' }],
131
+ tokenUsage: {
132
+ promptTokens: 4,
133
+ completionTokens: 2,
134
+ totalTokens: 6,
135
+ cachedTokens: 0,
136
+ cacheWriteTokens: 0,
137
+ },
138
+ currentIteration: 9,
139
+ startedAt: 1_000,
140
+ savedAt: 2_000,
141
+ processSignal: 'SIGTERM',
142
+ };
143
+ await seedEmergency(emergencyDir, dump);
144
+ const prepared = await prepareReplayState({
145
+ baseDir,
146
+ runId: RUN_ID,
147
+ fromCheckpoint: 'emergency',
148
+ emergencyDir,
149
+ });
150
+ expect(prepared.sourceCheckpoint.id).toBe('cp_emergency_xyz');
151
+ expect(prepared.sourceCheckpoint.iteration).toBe(9);
152
+ expect(prepared.messages).toEqual(dump.messages);
153
+ expect(prepared.attribution.fromCheckpointId).toBe('cp_emergency_xyz');
154
+ });
155
+ it("throws when 'emergency' is requested without emergencyDir", async () => {
156
+ await expect(prepareReplayState({
157
+ baseDir,
158
+ runId: RUN_ID,
159
+ fromCheckpoint: 'emergency',
160
+ })).rejects.toThrow(/emergencyDir/);
161
+ });
162
+ it("throws when 'emergency' dump file is missing", async () => {
163
+ await expect(prepareReplayState({
164
+ baseDir,
165
+ runId: RUN_ID,
166
+ fromCheckpoint: 'emergency',
167
+ emergencyDir,
168
+ })).rejects.toThrow(/No emergency dump/);
169
+ });
170
+ });
171
+ //# sourceMappingURL=prepare.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.test.js","sourceRoot":"","sources":["../../../../../src/runtime/query/replay/__tests__/prepare.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAMpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,MAAM,MAAM,GAAG,YAAqB,CAAA;AAEpC,SAAS,cAAc,CAAC,SAAuC;IAC9D,OAAO;QACN,EAAE,EAAE,YAA4B;QAChC,KAAK,EAAE,MAAM;QACb,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3C,UAAU,EAAE;YACX,YAAY,EAAE,CAAC;YACf,gBAAgB,EAAE,CAAC;YACnB,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,gBAAgB,EAAE,CAAC;SACnB;QACD,QAAQ,EAAE,EAAE,cAAc,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EA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kB,CAAC;YAClB,OAAO;YACP,KAAK,EAAE,MAAM;YACb,cAAc,EAAE,WAAW;SAC3B,CAAC,CACF,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,MAAM,CACX,kBAAkB,CAAC;YAClB,OAAO;YACP,KAAK,EAAE,MAAM;YACb,cAAc,EAAE,WAAW;YAC3B,YAAY;SACZ,CAAC,CACF,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { RunId } from '../../../types/ids/index.js';
2
+ import type { CheckpointListEntry } from '../../../types/run/replay.js';
3
+ import type { Logger } from '../../../utils/logger.js';
4
+ export interface ListCheckpointsInput {
5
+ /** Directory that contains `<runId>/` for the target run. */
6
+ baseDir: string;
7
+ /** Run whose checkpoints should be listed. */
8
+ runId: RunId;
9
+ logger?: Logger;
10
+ }
11
+ /**
12
+ * Read-only listing of a run's checkpoints for use with {@link
13
+ * import('./prepare.js').prepareReplayState}. Returns the public
14
+ * {@link CheckpointListEntry} projection — just enough for a caller to
15
+ * pick a fork point — not the full `IterationCheckpoint` payload.
16
+ *
17
+ * Entries are returned in the order the underlying store returns them
18
+ * (disk store sorts by `createdAt` ascending). Callers that want a
19
+ * specific order should sort client-side.
20
+ *
21
+ * See ses_005-deterministic-replay/design.md §3.1.
22
+ */
23
+ export declare function listCheckpoints(input: ListCheckpointsInput): Promise<CheckpointListEntry[]>;
24
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/runtime/query/replay/list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAGtD,MAAM,WAAW,oBAAoB;IACpC,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf,8CAA8C;IAC9C,KAAK,EAAE,KAAK,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAKjG"}
@@ -0,0 +1,21 @@
1
+ import { RunDiskStore } from '../../../store/run/disk.js';
2
+ import { CheckpointManager } from '../checkpoint.js';
3
+ /**
4
+ * Read-only listing of a run's checkpoints for use with {@link
5
+ * import('./prepare.js').prepareReplayState}. Returns the public
6
+ * {@link CheckpointListEntry} projection — just enough for a caller to
7
+ * pick a fork point — not the full `IterationCheckpoint` payload.
8
+ *
9
+ * Entries are returned in the order the underlying store returns them
10
+ * (disk store sorts by `createdAt` ascending). Callers that want a
11
+ * specific order should sort client-side.
12
+ *
13
+ * See ses_005-deterministic-replay/design.md §3.1.
14
+ */
15
+ export async function listCheckpoints(input) {
16
+ const store = new RunDiskStore({ baseDir: input.baseDir, logger: input.logger });
17
+ await store.initRun(input.runId);
18
+ const mgr = new CheckpointManager(store);
19
+ return mgr.listEntries();
20
+ }
21
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../src/runtime/query/replay/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAIzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAUpD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAA2B;IAChE,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;IAChF,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAChC,MAAM,GAAG,GAAG,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAA;IACxC,OAAO,GAAG,CAAC,WAAW,EAAE,CAAA;AACzB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type Message } from '../../../types/message/index.js';
2
+ import { type Mutation } from '../../../types/run/replay.js';
3
+ /**
4
+ * Apply an ordered list of {@link Mutation} to a checkpoint's message
5
+ * history at the fork point, producing a new message array that the
6
+ * resumed iteration loop consumes. Pure function; does not touch the run
7
+ * store, does not emit events.
8
+ *
9
+ * Throws {@link MutationNotApplicableError} when an `injectToolResponse`
10
+ * mutation targets a tool call id that is not pending at the fork point —
11
+ * the error payload carries the list of ids that *are* pending so the
12
+ * caller can recover without guessing.
13
+ *
14
+ * See ses_005-deterministic-replay design §3.3.
15
+ */
16
+ export declare function applyMutations(messages: readonly Message[], mutations: readonly Mutation[]): Message[];
17
+ //# sourceMappingURL=mutate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutate.d.ts","sourceRoot":"","sources":["../../../../src/runtime/query/replay/mutate.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,OAAO,EAGZ,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,KAAK,QAAQ,EAA8B,MAAM,8BAA8B,CAAA;AA8BxF;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,SAAS,EAAE,SAAS,QAAQ,EAAE,GAC5B,OAAO,EAAE,CAMX"}
@@ -0,0 +1,62 @@
1
+ import { createToolMessage, } from '../../../types/message/index.js';
2
+ import { MutationNotApplicableError } from '../../../types/run/replay.js';
3
+ /**
4
+ * Returns the tool calls on the most recent assistant message that do not
5
+ * yet have a matching {@link import('../../../types/message/index.js').ToolMessage}
6
+ * response further down the message list. These are the fork-point "pending"
7
+ * tool calls that mutations may target.
8
+ */
9
+ function findPendingToolCalls(messages) {
10
+ let lastAssistantIdx = -1;
11
+ for (let i = messages.length - 1; i >= 0; i--) {
12
+ const msg = messages[i];
13
+ if (msg && msg.role === 'assistant' && (msg.toolCalls?.length ?? 0) > 0) {
14
+ lastAssistantIdx = i;
15
+ break;
16
+ }
17
+ }
18
+ if (lastAssistantIdx === -1)
19
+ return [];
20
+ const assistant = messages[lastAssistantIdx];
21
+ const satisfied = new Set();
22
+ for (let i = lastAssistantIdx + 1; i < messages.length; i++) {
23
+ const msg = messages[i];
24
+ if (msg && msg.role === 'tool') {
25
+ satisfied.add(msg.toolCallId);
26
+ }
27
+ }
28
+ return (assistant.toolCalls ?? []).filter((tc) => !satisfied.has(tc.id));
29
+ }
30
+ /**
31
+ * Apply an ordered list of {@link Mutation} to a checkpoint's message
32
+ * history at the fork point, producing a new message array that the
33
+ * resumed iteration loop consumes. Pure function; does not touch the run
34
+ * store, does not emit events.
35
+ *
36
+ * Throws {@link MutationNotApplicableError} when an `injectToolResponse`
37
+ * mutation targets a tool call id that is not pending at the fork point —
38
+ * the error payload carries the list of ids that *are* pending so the
39
+ * caller can recover without guessing.
40
+ *
41
+ * See ses_005-deterministic-replay design §3.3.
42
+ */
43
+ export function applyMutations(messages, mutations) {
44
+ let current = [...messages];
45
+ for (const m of mutations) {
46
+ current = applyOne(current, m);
47
+ }
48
+ return current;
49
+ }
50
+ function applyOne(messages, mutation) {
51
+ switch (mutation.type) {
52
+ case 'injectToolResponse': {
53
+ const pending = findPendingToolCalls(messages);
54
+ const match = pending.find((tc) => tc.id === mutation.toolCallId);
55
+ if (!match) {
56
+ throw new MutationNotApplicableError(`No pending tool call ${mutation.toolCallId} at fork point`, pending.map((tc) => tc.id));
57
+ }
58
+ return [...messages, createToolMessage(mutation.response.output, mutation.toolCallId)];
59
+ }
60
+ }
61
+ }
62
+ //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{ Message } from '../../../types/message/index.js';
4
+ import type { Mutation, ReplayAttribution } from '../../../types/run/replay.js';
5
+ import type { Logger } from '../../../utils/logger.js';
6
+ export type CheckpointSelector = CheckpointId | 'latest' | 'emergency';
7
+ export interface PrepareReplayInput {
8
+ /** Directory that contains `<runId>/` for the source run. */
9
+ baseDir: string;
10
+ /** Source run to fork from. */
11
+ runId: RunId;
12
+ /** Which checkpoint to fork at. */
13
+ fromCheckpoint: CheckpointSelector;
14
+ /** Optional mutations applied at the fork point before the caller hands state to `query()`. */
15
+ mutate?: Mutation[];
16
+ /**
17
+ * Directory that holds emergency dumps. Required only when `fromCheckpoint`
18
+ * is `'emergency'`; conventionally sibling of `baseDir` (the `.namzu/emergency`
19
+ * folder), but left explicit so callers with non-default layouts can redirect.
20
+ */
21
+ emergencyDir?: string;
22
+ logger?: Logger;
23
+ }
24
+ export interface PreparedReplayState {
25
+ /**
26
+ * Message history at the fork point, with mutations applied. Seed this
27
+ * as the new run's initial messages and pass `sourceCheckpoint.id` as
28
+ * `resumeFromCheckpoint` when you call `query()`.
29
+ */
30
+ messages: Message[];
31
+ /** The checkpoint the replay forks from (already projected if emergency). */
32
+ sourceCheckpoint: IterationCheckpoint;
33
+ /**
34
+ * Attribution to stamp on the replay run once it is created. The caller
35
+ * sets `Run.replayOf = buildAttribution(prepared, replayedAt)` on the
36
+ * new `RunPersistence` before persisting the first time.
37
+ */
38
+ attribution: ReplayAttribution;
39
+ }
40
+ /**
41
+ * Produce the state materials needed to execute a replay run — the mutated
42
+ * message history, the resolved source checkpoint, and the replay
43
+ * attribution record. Pure read; does not touch the run store beyond
44
+ * reading the source run's checkpoint files.
45
+ *
46
+ * This is the state-preparation half of the replay primitive. The
47
+ * caller is expected to thread the returned `messages` +
48
+ * `sourceCheckpoint.id` into `query({ resumeFromCheckpoint, messages,
49
+ * ... })` and stamp `Run.replayOf = prepared.attribution` on the resulting
50
+ * run. The end-to-end `replay()` entry that does all of this in one call
51
+ * is a follow-up session (`ReplayEnvironment` shape).
52
+ *
53
+ * See `ses_005-deterministic-replay/design.md` §3.1.
54
+ */
55
+ export declare function prepareReplayState(input: PrepareReplayInput): Promise<PreparedReplayState>;
56
+ //# sourceMappingURL=prepare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../../../../src/runtime/query/replay/prepare.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAC/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAItD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEtE,MAAM,WAAW,kBAAkB;IAClC,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf,+BAA+B;IAC/B,KAAK,EAAE,KAAK,CAAA;IACZ,mCAAmC;IACnC,cAAc,EAAE,kBAAkB,CAAA;IAClC,+FAA+F;IAC/F,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAA;IACnB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB;IACnC;;;;OAIG;IACH,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,6EAA6E;IAC7E,gBAAgB,EAAE,mBAAmB,CAAA;IACrC;;;;OAIG;IACH,WAAW,EAAE,iBAAiB,CAAA;CAC9B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAahG"}
@@ -0,0 +1,65 @@
1
+ import { join } from 'node:path';
2
+ import { EmergencySaveManager } from '../../../manager/run/emergency.js';
3
+ import { RunDiskStore } from '../../../store/run/disk.js';
4
+ import { projectEmergencyToCheckpoint } from '../checkpoint.js';
5
+ import { applyMutations } from './mutate.js';
6
+ /**
7
+ * Produce the state materials needed to execute a replay run — the mutated
8
+ * message history, the resolved source checkpoint, and the replay
9
+ * attribution record. Pure read; does not touch the run store beyond
10
+ * reading the source run's checkpoint files.
11
+ *
12
+ * This is the state-preparation half of the replay primitive. The
13
+ * caller is expected to thread the returned `messages` +
14
+ * `sourceCheckpoint.id` into `query({ resumeFromCheckpoint, messages,
15
+ * ... })` and stamp `Run.replayOf = prepared.attribution` on the resulting
16
+ * run. The end-to-end `replay()` entry that does all of this in one call
17
+ * is a follow-up session (`ReplayEnvironment` shape).
18
+ *
19
+ * See `ses_005-deterministic-replay/design.md` §3.1.
20
+ */
21
+ export async function prepareReplayState(input) {
22
+ const sourceCheckpoint = await resolveCheckpoint(input);
23
+ const mutations = input.mutate ?? [];
24
+ const messages = applyMutations(sourceCheckpoint.messages, mutations);
25
+ const attribution = {
26
+ sourceRunId: input.runId,
27
+ fromCheckpointId: sourceCheckpoint.id,
28
+ mutations,
29
+ replayedAt: Date.now(),
30
+ };
31
+ return { messages, sourceCheckpoint, attribution };
32
+ }
33
+ async function resolveCheckpoint(input) {
34
+ if (input.fromCheckpoint === 'emergency') {
35
+ return resolveEmergency(input);
36
+ }
37
+ const store = new RunDiskStore({ baseDir: input.baseDir, logger: input.logger });
38
+ await store.initRun(input.runId);
39
+ if (input.fromCheckpoint === 'latest') {
40
+ const all = await store.listCheckpoints();
41
+ if (all.length === 0) {
42
+ throw new Error(`No checkpoints found for run ${input.runId} in ${input.baseDir}`);
43
+ }
44
+ return [...all].sort((a, b) => b.iteration - a.iteration)[0];
45
+ }
46
+ const checkpoint = await store.readCheckpoint(input.fromCheckpoint);
47
+ if (!checkpoint) {
48
+ throw new Error(`Checkpoint ${input.fromCheckpoint} not found for run ${input.runId}`);
49
+ }
50
+ return checkpoint;
51
+ }
52
+ async function resolveEmergency(input) {
53
+ if (!input.emergencyDir) {
54
+ throw new Error("fromCheckpoint: 'emergency' requires an `emergencyDir` — conventionally sibling of baseDir");
55
+ }
56
+ const path = join(input.emergencyDir, `${input.runId}.json`);
57
+ try {
58
+ const dump = EmergencySaveManager.loadSave(path);
59
+ return projectEmergencyToCheckpoint(dump);
60
+ }
61
+ catch (err) {
62
+ throw new Error(`No emergency dump found for run ${input.runId} at ${path}`, { cause: err });
63
+ }
64
+ }
65
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../../../src/runtime/query/replay/prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAMzD,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAuC5C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAAyB;IACjE,MAAM,gBAAgB,GAAG,MAAM,iBAAiB,CAAC,KAAK,CAAC,CAAA;IACvD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAA;IACpC,MAAM,QAAQ,GAAG,cAAc,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAErE,MAAM,WAAW,GAAsB;QACtC,WAAW,EAAE,KAAK,CAAC,KAAK;QACxB,gBAAgB,EAAE,gBAAgB,CAAC,EAAE;QACrC,SAAS;QACT,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAA;IAED,OAAO,EAAE,QAAQ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KAAK,CACd,4FAA4F,CAC5F,CAAA;IACF,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,KAAK,OAAO,CAAC,CAAA;IAC5D,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAChD,OAAO,4BAA4B,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,KAAK,CAAC,KAAK,OAAO,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;IAC7F,CAAC;AACF,CAAC"}
@@ -2,7 +2,7 @@ import { type Span } from '@opentelemetry/api';
2
2
  import type { PlanManager } from '../../manager/plan/lifecycle.js';
3
3
  import type { RunPersistence } from '../../manager/run/persistence.js';
4
4
  import type { ActivityStore } from '../../store/activity/memory.js';
5
- import type { AgentRun, RunEvent } from '../../types/run/index.js';
5
+ import type { Run, RunEvent } from '../../types/run/index.js';
6
6
  import type { Logger } from '../../utils/logger.js';
7
7
  import type { EmitEvent } from './events.js';
8
8
  export interface ResultAssemblerConfig {
@@ -19,6 +19,6 @@ export declare class ResultAssembler {
19
19
  completeRun(rootSpan: Span): AsyncGenerator<RunEvent>;
20
20
  completeSession(rootSpan: Span): AsyncGenerator<RunEvent>;
21
21
  handleError(err: unknown, rootSpan: Span): AsyncGenerator<RunEvent>;
22
- finalize(): Promise<AgentRun>;
22
+ finalize(): Promise<Run>;
23
23
  }
24
24
  //# sourceMappingURL=result.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAkB,MAAM,oBAAoB,CAAA;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,C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