@namzu/sdk 0.6.0 → 1.1.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 (429) hide show
  1. package/CHANGELOG.md +529 -0
  2. package/dist/advisory/executor.d.ts.map +1 -1
  3. package/dist/advisory/executor.js +9 -2
  4. package/dist/advisory/executor.js.map +1 -1
  5. package/dist/advisory/executor.test.d.ts +2 -1
  6. package/dist/advisory/executor.test.d.ts.map +1 -1
  7. package/dist/advisory/executor.test.js +7 -4
  8. package/dist/advisory/executor.test.js.map +1 -1
  9. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  10. package/dist/agents/ReactiveAgent.js +7 -0
  11. package/dist/agents/ReactiveAgent.js.map +1 -1
  12. package/dist/agents/SupervisorAgent.d.ts +22 -1
  13. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  14. package/dist/agents/SupervisorAgent.js +54 -14
  15. package/dist/agents/SupervisorAgent.js.map +1 -1
  16. package/dist/agents/__tests__/supervisor-ledger.test.d.ts +2 -0
  17. package/dist/agents/__tests__/supervisor-ledger.test.d.ts.map +1 -0
  18. package/dist/agents/__tests__/supervisor-ledger.test.js +131 -0
  19. package/dist/agents/__tests__/supervisor-ledger.test.js.map +1 -0
  20. package/dist/bridge/sse/mapper.test.js +2 -2
  21. package/dist/config/runtime.d.ts +24 -0
  22. package/dist/config/runtime.d.ts.map +1 -1
  23. package/dist/config/runtime.js +9 -0
  24. package/dist/config/runtime.js.map +1 -1
  25. package/dist/connector/builtins/webhook.test.js +17 -0
  26. package/dist/connector/builtins/webhook.test.js.map +1 -1
  27. package/dist/connector/index.d.ts +1 -0
  28. package/dist/connector/index.d.ts.map +1 -1
  29. package/dist/connector/index.js +1 -0
  30. package/dist/connector/index.js.map +1 -1
  31. package/dist/connector/mcp/client.d.ts.map +1 -1
  32. package/dist/connector/mcp/client.js +4 -0
  33. package/dist/connector/mcp/client.js.map +1 -1
  34. package/dist/connector/mcp/index.d.ts +1 -0
  35. package/dist/connector/mcp/index.d.ts.map +1 -1
  36. package/dist/connector/mcp/index.js +1 -0
  37. package/dist/connector/mcp/index.js.map +1 -1
  38. package/dist/connector/mcp/streamable-http.d.ts +22 -0
  39. package/dist/connector/mcp/streamable-http.d.ts.map +1 -0
  40. package/dist/connector/mcp/streamable-http.js +128 -0
  41. package/dist/connector/mcp/streamable-http.js.map +1 -0
  42. package/dist/connector/mcp/streamable-http.test.d.ts +2 -0
  43. package/dist/connector/mcp/streamable-http.test.d.ts.map +1 -0
  44. package/dist/connector/mcp/streamable-http.test.js +132 -0
  45. package/dist/connector/mcp/streamable-http.test.js.map +1 -0
  46. package/dist/constants/compaction/index.d.ts.map +1 -1
  47. package/dist/constants/compaction/index.js +8 -3
  48. package/dist/constants/compaction/index.js.map +1 -1
  49. package/dist/constants/sandbox/index.d.ts +21 -0
  50. package/dist/constants/sandbox/index.d.ts.map +1 -1
  51. package/dist/constants/sandbox/index.js +30 -0
  52. package/dist/constants/sandbox/index.js.map +1 -1
  53. package/dist/constants/tools/index.d.ts.map +1 -1
  54. package/dist/constants/tools/index.js +33 -2
  55. package/dist/constants/tools/index.js.map +1 -1
  56. package/dist/manager/run/persistence.d.ts.map +1 -1
  57. package/dist/manager/run/persistence.js +35 -5
  58. package/dist/manager/run/persistence.js.map +1 -1
  59. package/dist/persona/assembler.d.ts +1 -0
  60. package/dist/persona/assembler.d.ts.map +1 -1
  61. package/dist/persona/assembler.js +37 -6
  62. package/dist/persona/assembler.js.map +1 -1
  63. package/dist/provider/collect.d.ts.map +1 -1
  64. package/dist/provider/collect.js +4 -1
  65. package/dist/provider/collect.js.map +1 -1
  66. package/dist/provider/collect.test.js +2 -2
  67. package/dist/public-runtime.d.ts +6 -5
  68. package/dist/public-runtime.d.ts.map +1 -1
  69. package/dist/public-runtime.js +6 -5
  70. package/dist/public-runtime.js.map +1 -1
  71. package/dist/public-tools.d.ts +2 -0
  72. package/dist/public-tools.d.ts.map +1 -1
  73. package/dist/public-tools.js +2 -0
  74. package/dist/public-tools.js.map +1 -1
  75. package/dist/public-types.d.ts +3 -0
  76. package/dist/public-types.d.ts.map +1 -1
  77. package/dist/registry/index.d.ts +2 -0
  78. package/dist/registry/index.d.ts.map +1 -1
  79. package/dist/registry/index.js +1 -0
  80. package/dist/registry/index.js.map +1 -1
  81. package/dist/registry/tool/execute.d.ts +27 -0
  82. package/dist/registry/tool/execute.d.ts.map +1 -1
  83. package/dist/registry/tool/execute.js +192 -7
  84. package/dist/registry/tool/execute.js.map +1 -1
  85. package/dist/registry/tool/execute.test.d.ts +9 -4
  86. package/dist/registry/tool/execute.test.d.ts.map +1 -1
  87. package/dist/registry/tool/execute.test.js +178 -7
  88. package/dist/registry/tool/execute.test.js.map +1 -1
  89. package/dist/registry/toolset/catalog.d.ts +42 -0
  90. package/dist/registry/toolset/catalog.d.ts.map +1 -0
  91. package/dist/registry/toolset/catalog.js +217 -0
  92. package/dist/registry/toolset/catalog.js.map +1 -0
  93. package/dist/registry/toolset/catalog.test.d.ts +2 -0
  94. package/dist/registry/toolset/catalog.test.d.ts.map +1 -0
  95. package/dist/registry/toolset/catalog.test.js +147 -0
  96. package/dist/registry/toolset/catalog.test.js.map +1 -0
  97. package/dist/runtime/query/__tests__/deferred-tools.test.d.ts +2 -0
  98. package/dist/runtime/query/__tests__/deferred-tools.test.d.ts.map +1 -0
  99. package/dist/runtime/query/__tests__/deferred-tools.test.js +185 -0
  100. package/dist/runtime/query/__tests__/deferred-tools.test.js.map +1 -0
  101. package/dist/runtime/query/__tests__/executor-concurrency.test.d.ts +2 -0
  102. package/dist/runtime/query/__tests__/executor-concurrency.test.d.ts.map +1 -0
  103. package/dist/runtime/query/__tests__/executor-concurrency.test.js +98 -0
  104. package/dist/runtime/query/__tests__/executor-concurrency.test.js.map +1 -0
  105. package/dist/runtime/query/__tests__/executor-plugin-hooks.test.js +38 -3
  106. package/dist/runtime/query/__tests__/executor-plugin-hooks.test.js.map +1 -1
  107. package/dist/runtime/query/__tests__/long-document-flow.test.d.ts +2 -0
  108. package/dist/runtime/query/__tests__/long-document-flow.test.d.ts.map +1 -0
  109. package/dist/runtime/query/__tests__/long-document-flow.test.js +154 -0
  110. package/dist/runtime/query/__tests__/long-document-flow.test.js.map +1 -0
  111. package/dist/runtime/query/__tests__/prompt.test.js +51 -2
  112. package/dist/runtime/query/__tests__/prompt.test.js.map +1 -1
  113. package/dist/runtime/query/__tests__/stream-recovery.test.d.ts +2 -0
  114. package/dist/runtime/query/__tests__/stream-recovery.test.d.ts.map +1 -0
  115. package/dist/runtime/query/__tests__/stream-recovery.test.js +126 -0
  116. package/dist/runtime/query/__tests__/stream-recovery.test.js.map +1 -0
  117. package/dist/runtime/query/continuation.d.ts +16 -0
  118. package/dist/runtime/query/continuation.d.ts.map +1 -0
  119. package/dist/runtime/query/continuation.js +16 -0
  120. package/dist/runtime/query/continuation.js.map +1 -0
  121. package/dist/runtime/query/executor.d.ts +3 -0
  122. package/dist/runtime/query/executor.d.ts.map +1 -1
  123. package/dist/runtime/query/executor.js +71 -3
  124. package/dist/runtime/query/executor.js.map +1 -1
  125. package/dist/runtime/query/index.d.ts +9 -0
  126. package/dist/runtime/query/index.d.ts.map +1 -1
  127. package/dist/runtime/query/index.js +42 -5
  128. package/dist/runtime/query/index.js.map +1 -1
  129. package/dist/runtime/query/iteration/index.d.ts +24 -0
  130. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  131. package/dist/runtime/query/iteration/index.js +326 -66
  132. package/dist/runtime/query/iteration/index.js.map +1 -1
  133. package/dist/runtime/query/iteration/phases/checkpoint.d.ts.map +1 -1
  134. package/dist/runtime/query/iteration/phases/checkpoint.js +2 -2
  135. package/dist/runtime/query/iteration/phases/checkpoint.js.map +1 -1
  136. package/dist/runtime/query/iteration/phases/compaction.d.ts +8 -0
  137. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  138. package/dist/runtime/query/iteration/phases/compaction.js +84 -3
  139. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  140. package/dist/runtime/query/iteration/phases/context.d.ts +22 -0
  141. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  142. package/dist/runtime/query/iteration/phases/context.js +53 -0
  143. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  144. package/dist/runtime/query/iteration/phases/hitl-abort-race.test.d.ts +2 -0
  145. package/dist/runtime/query/iteration/phases/hitl-abort-race.test.d.ts.map +1 -0
  146. package/dist/runtime/query/iteration/phases/hitl-abort-race.test.js +73 -0
  147. package/dist/runtime/query/iteration/phases/hitl-abort-race.test.js.map +1 -0
  148. package/dist/runtime/query/iteration/phases/hitl-answer-question.test.d.ts +2 -0
  149. package/dist/runtime/query/iteration/phases/hitl-answer-question.test.d.ts.map +1 -0
  150. package/dist/runtime/query/iteration/phases/hitl-answer-question.test.js +120 -0
  151. package/dist/runtime/query/iteration/phases/hitl-answer-question.test.js.map +1 -0
  152. package/dist/runtime/query/iteration/phases/tool-review.d.ts +1 -1
  153. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  154. package/dist/runtime/query/iteration/phases/tool-review.js +7 -2
  155. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  156. package/dist/runtime/query/iteration/phases/working-memory-compaction.test.d.ts +19 -0
  157. package/dist/runtime/query/iteration/phases/working-memory-compaction.test.d.ts.map +1 -0
  158. package/dist/runtime/query/iteration/phases/working-memory-compaction.test.js +177 -0
  159. package/dist/runtime/query/iteration/phases/working-memory-compaction.test.js.map +1 -0
  160. package/dist/runtime/query/iteration/phases/working-memory.d.ts +31 -0
  161. package/dist/runtime/query/iteration/phases/working-memory.d.ts.map +1 -0
  162. package/dist/runtime/query/iteration/phases/working-memory.js +81 -0
  163. package/dist/runtime/query/iteration/phases/working-memory.js.map +1 -0
  164. package/dist/runtime/query/prompt.d.ts.map +1 -1
  165. package/dist/runtime/query/prompt.js +21 -1
  166. package/dist/runtime/query/prompt.js.map +1 -1
  167. package/dist/runtime/query/tooling.d.ts +1 -0
  168. package/dist/runtime/query/tooling.d.ts.map +1 -1
  169. package/dist/runtime/query/tooling.js +1 -0
  170. package/dist/runtime/query/tooling.js.map +1 -1
  171. package/dist/sandbox/provider/local.d.ts.map +1 -1
  172. package/dist/sandbox/provider/local.js +32 -1
  173. package/dist/sandbox/provider/local.js.map +1 -1
  174. package/dist/session/workspace/__tests__/shared-run.test.d.ts +2 -0
  175. package/dist/session/workspace/__tests__/shared-run.test.d.ts.map +1 -0
  176. package/dist/session/workspace/__tests__/shared-run.test.js +147 -0
  177. package/dist/session/workspace/__tests__/shared-run.test.js.map +1 -0
  178. package/dist/session/workspace/index.d.ts +2 -0
  179. package/dist/session/workspace/index.d.ts.map +1 -1
  180. package/dist/session/workspace/index.js +1 -0
  181. package/dist/session/workspace/index.js.map +1 -1
  182. package/dist/session/workspace/shared-run.d.ts +81 -0
  183. package/dist/session/workspace/shared-run.d.ts.map +1 -0
  184. package/dist/session/workspace/shared-run.js +252 -0
  185. package/dist/session/workspace/shared-run.js.map +1 -0
  186. package/dist/skills/loader.d.ts.map +1 -1
  187. package/dist/skills/loader.js +36 -6
  188. package/dist/skills/loader.js.map +1 -1
  189. package/dist/skills/loader.test.d.ts +2 -0
  190. package/dist/skills/loader.test.d.ts.map +1 -0
  191. package/dist/skills/loader.test.js +65 -0
  192. package/dist/skills/loader.test.js.map +1 -0
  193. package/dist/streaming/coalesce.test.js +1 -1
  194. package/dist/streaming/coalesce.test.js.map +1 -1
  195. package/dist/tools/builtins/__tests__/edit.test.d.ts +2 -0
  196. package/dist/tools/builtins/__tests__/edit.test.d.ts.map +1 -0
  197. package/dist/tools/builtins/__tests__/edit.test.js +38 -0
  198. package/dist/tools/builtins/__tests__/edit.test.js.map +1 -0
  199. package/dist/tools/builtins/__tests__/payload-budget.test.d.ts +2 -0
  200. package/dist/tools/builtins/__tests__/payload-budget.test.d.ts.map +1 -0
  201. package/dist/tools/builtins/__tests__/payload-budget.test.js +70 -0
  202. package/dist/tools/builtins/__tests__/payload-budget.test.js.map +1 -0
  203. package/dist/tools/builtins/__tests__/read-file.test.d.ts +2 -0
  204. package/dist/tools/builtins/__tests__/read-file.test.d.ts.map +1 -0
  205. package/dist/tools/builtins/__tests__/read-file.test.js +33 -0
  206. package/dist/tools/builtins/__tests__/read-file.test.js.map +1 -0
  207. package/dist/tools/builtins/__tests__/verify-outputs.test.d.ts +2 -0
  208. package/dist/tools/builtins/__tests__/verify-outputs.test.d.ts.map +1 -0
  209. package/dist/tools/builtins/__tests__/verify-outputs.test.js +52 -0
  210. package/dist/tools/builtins/__tests__/verify-outputs.test.js.map +1 -0
  211. package/dist/tools/builtins/__tests__/write-file.test.d.ts +2 -0
  212. package/dist/tools/builtins/__tests__/write-file.test.d.ts.map +1 -0
  213. package/dist/tools/builtins/__tests__/write-file.test.js +74 -0
  214. package/dist/tools/builtins/__tests__/write-file.test.js.map +1 -0
  215. package/dist/tools/builtins/bash.d.ts.map +1 -1
  216. package/dist/tools/builtins/bash.js +40 -7
  217. package/dist/tools/builtins/bash.js.map +1 -1
  218. package/dist/tools/builtins/edit.d.ts +5 -2
  219. package/dist/tools/builtins/edit.d.ts.map +1 -1
  220. package/dist/tools/builtins/edit.js +114 -18
  221. package/dist/tools/builtins/edit.js.map +1 -1
  222. package/dist/tools/builtins/index.d.ts +1 -0
  223. package/dist/tools/builtins/index.d.ts.map +1 -1
  224. package/dist/tools/builtins/index.js +13 -13
  225. package/dist/tools/builtins/index.js.map +1 -1
  226. package/dist/tools/builtins/read-file.d.ts +1 -0
  227. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  228. package/dist/tools/builtins/read-file.js +73 -10
  229. package/dist/tools/builtins/read-file.js.map +1 -1
  230. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  231. package/dist/tools/builtins/search-tools.js +35 -7
  232. package/dist/tools/builtins/search-tools.js.map +1 -1
  233. package/dist/tools/builtins/verify-outputs.d.ts +5 -0
  234. package/dist/tools/builtins/verify-outputs.d.ts.map +1 -0
  235. package/dist/tools/builtins/verify-outputs.js +103 -0
  236. package/dist/tools/builtins/verify-outputs.js.map +1 -0
  237. package/dist/tools/builtins/write-file.d.ts +3 -2
  238. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  239. package/dist/tools/builtins/write-file.js +72 -12
  240. package/dist/tools/builtins/write-file.js.map +1 -1
  241. package/dist/tools/coordinator/__tests__/agent.test.d.ts +15 -0
  242. package/dist/tools/coordinator/__tests__/agent.test.d.ts.map +1 -0
  243. package/dist/tools/coordinator/__tests__/agent.test.js +142 -0
  244. package/dist/tools/coordinator/__tests__/agent.test.js.map +1 -0
  245. package/dist/tools/coordinator/__tests__/approve-plan.test.d.ts +2 -0
  246. package/dist/tools/coordinator/__tests__/approve-plan.test.d.ts.map +1 -0
  247. package/dist/tools/coordinator/__tests__/approve-plan.test.js +114 -0
  248. package/dist/tools/coordinator/__tests__/approve-plan.test.js.map +1 -0
  249. package/dist/tools/coordinator/__tests__/ask-user-question.test.d.ts +2 -0
  250. package/dist/tools/coordinator/__tests__/ask-user-question.test.d.ts.map +1 -0
  251. package/dist/tools/coordinator/__tests__/ask-user-question.test.js +309 -0
  252. package/dist/tools/coordinator/__tests__/ask-user-question.test.js.map +1 -0
  253. package/dist/tools/coordinator/__tests__/task-list.test.d.ts +13 -0
  254. package/dist/tools/coordinator/__tests__/task-list.test.d.ts.map +1 -0
  255. package/dist/tools/coordinator/__tests__/task-list.test.js +162 -0
  256. package/dist/tools/coordinator/__tests__/task-list.test.js.map +1 -0
  257. package/dist/tools/coordinator/agent.d.ts +34 -0
  258. package/dist/tools/coordinator/agent.d.ts.map +1 -0
  259. package/dist/tools/coordinator/agent.js +107 -0
  260. package/dist/tools/coordinator/agent.js.map +1 -0
  261. package/dist/tools/coordinator/index.d.ts +15 -0
  262. package/dist/tools/coordinator/index.d.ts.map +1 -1
  263. package/dist/tools/coordinator/index.js +305 -35
  264. package/dist/tools/coordinator/index.js.map +1 -1
  265. package/dist/types/agent/base.d.ts +8 -0
  266. package/dist/types/agent/base.d.ts.map +1 -1
  267. package/dist/types/agent/index.d.ts +1 -0
  268. package/dist/types/agent/index.d.ts.map +1 -1
  269. package/dist/types/agent/index.js +1 -0
  270. package/dist/types/agent/index.js.map +1 -1
  271. package/dist/types/agent/reactive.d.ts +38 -0
  272. package/dist/types/agent/reactive.d.ts.map +1 -1
  273. package/dist/types/agent/supervisor.d.ts +32 -0
  274. package/dist/types/agent/supervisor.d.ts.map +1 -1
  275. package/dist/types/agent/working-memory.d.ts +29 -0
  276. package/dist/types/agent/working-memory.d.ts.map +1 -0
  277. package/dist/types/agent/working-memory.js +2 -0
  278. package/dist/types/agent/working-memory.js.map +1 -0
  279. package/dist/types/common/index.d.ts +10 -0
  280. package/dist/types/common/index.d.ts.map +1 -1
  281. package/dist/types/common/index.js +18 -0
  282. package/dist/types/common/index.js.map +1 -1
  283. package/dist/types/common/usage-merge.test.d.ts +2 -0
  284. package/dist/types/common/usage-merge.test.d.ts.map +1 -0
  285. package/dist/types/common/usage-merge.test.js +48 -0
  286. package/dist/types/common/usage-merge.test.js.map +1 -0
  287. package/dist/types/connector/mcp.d.ts +9 -2
  288. package/dist/types/connector/mcp.d.ts.map +1 -1
  289. package/dist/types/hitl/index.d.ts +42 -0
  290. package/dist/types/hitl/index.d.ts.map +1 -1
  291. package/dist/types/hitl/index.js +11 -0
  292. package/dist/types/hitl/index.js.map +1 -1
  293. package/dist/types/message/index.d.ts +22 -1
  294. package/dist/types/message/index.d.ts.map +1 -1
  295. package/dist/types/message/index.js +7 -2
  296. package/dist/types/message/index.js.map +1 -1
  297. package/dist/types/provider/chat.d.ts +11 -9
  298. package/dist/types/provider/chat.d.ts.map +1 -1
  299. package/dist/types/run/events.d.ts +6 -0
  300. package/dist/types/run/events.d.ts.map +1 -1
  301. package/dist/types/run/events.js.map +1 -1
  302. package/dist/types/sandbox/index.d.ts +193 -0
  303. package/dist/types/sandbox/index.d.ts.map +1 -1
  304. package/dist/types/sandbox/index.js.map +1 -1
  305. package/dist/types/skills/index.d.ts +2 -0
  306. package/dist/types/skills/index.d.ts.map +1 -1
  307. package/dist/types/tool/index.d.ts +22 -0
  308. package/dist/types/tool/index.d.ts.map +1 -1
  309. package/dist/types/toolset/index.d.ts +71 -0
  310. package/dist/types/toolset/index.d.ts.map +1 -0
  311. package/dist/types/toolset/index.js +2 -0
  312. package/dist/types/toolset/index.js.map +1 -0
  313. package/dist/types/workspace/index.d.ts +1 -0
  314. package/dist/types/workspace/index.d.ts.map +1 -1
  315. package/dist/types/workspace/shared-run.d.ts +61 -0
  316. package/dist/types/workspace/shared-run.d.ts.map +1 -0
  317. package/dist/types/workspace/shared-run.js +2 -0
  318. package/dist/types/workspace/shared-run.js.map +1 -0
  319. package/dist/verification/index.d.ts +1 -0
  320. package/dist/verification/index.d.ts.map +1 -1
  321. package/dist/verification/index.js +1 -0
  322. package/dist/verification/index.js.map +1 -1
  323. package/dist/verification/presets.d.ts +53 -0
  324. package/dist/verification/presets.d.ts.map +1 -0
  325. package/dist/verification/presets.js +70 -0
  326. package/dist/verification/presets.js.map +1 -0
  327. package/dist/verification/presets.test.d.ts +16 -0
  328. package/dist/verification/presets.test.d.ts.map +1 -0
  329. package/dist/verification/presets.test.js +79 -0
  330. package/dist/verification/presets.test.js.map +1 -0
  331. package/dist/version.d.ts.map +1 -1
  332. package/dist/version.js +25 -4
  333. package/dist/version.js.map +1 -1
  334. package/package.json +3 -2
  335. package/src/advisory/executor.test.ts +7 -4
  336. package/src/advisory/executor.ts +11 -2
  337. package/src/agents/ReactiveAgent.ts +7 -0
  338. package/src/agents/SupervisorAgent.ts +63 -16
  339. package/src/agents/__tests__/supervisor-ledger.test.ts +185 -0
  340. package/src/bridge/sse/mapper.test.ts +2 -2
  341. package/src/config/runtime.ts +9 -0
  342. package/src/connector/builtins/webhook.test.ts +21 -0
  343. package/src/connector/index.ts +1 -0
  344. package/src/connector/mcp/client.ts +4 -0
  345. package/src/connector/mcp/index.ts +1 -0
  346. package/src/connector/mcp/streamable-http.test.ts +169 -0
  347. package/src/connector/mcp/streamable-http.ts +152 -0
  348. package/src/constants/compaction/index.ts +8 -3
  349. package/src/constants/sandbox/index.ts +37 -0
  350. package/src/constants/tools/index.ts +33 -2
  351. package/src/manager/run/persistence.ts +34 -6
  352. package/src/persona/assembler.ts +43 -8
  353. package/src/provider/collect.test.ts +2 -2
  354. package/src/provider/collect.ts +4 -1
  355. package/src/public-runtime.ts +15 -1
  356. package/src/public-tools.ts +2 -0
  357. package/src/public-types.ts +7 -0
  358. package/src/registry/index.ts +7 -0
  359. package/src/registry/tool/execute.test.ts +211 -7
  360. package/src/registry/tool/execute.ts +199 -11
  361. package/src/registry/toolset/catalog.test.ts +165 -0
  362. package/src/registry/toolset/catalog.ts +283 -0
  363. package/src/runtime/query/__tests__/deferred-tools.test.ts +230 -0
  364. package/src/runtime/query/__tests__/executor-concurrency.test.ts +122 -0
  365. package/src/runtime/query/__tests__/executor-plugin-hooks.test.ts +48 -3
  366. package/src/runtime/query/__tests__/long-document-flow.test.ts +180 -0
  367. package/src/runtime/query/__tests__/prompt.test.ts +55 -2
  368. package/src/runtime/query/__tests__/stream-recovery.test.ts +156 -0
  369. package/src/runtime/query/continuation.ts +16 -0
  370. package/src/runtime/query/executor.ts +82 -13
  371. package/src/runtime/query/index.ts +58 -5
  372. package/src/runtime/query/iteration/index.ts +361 -74
  373. package/src/runtime/query/iteration/phases/checkpoint.ts +7 -2
  374. package/src/runtime/query/iteration/phases/compaction.ts +89 -3
  375. package/src/runtime/query/iteration/phases/context.ts +68 -0
  376. package/src/runtime/query/iteration/phases/hitl-abort-race.test.ts +86 -0
  377. package/src/runtime/query/iteration/phases/hitl-answer-question.test.ts +139 -0
  378. package/src/runtime/query/iteration/phases/tool-review.ts +7 -3
  379. package/src/runtime/query/iteration/phases/working-memory-compaction.test.ts +215 -0
  380. package/src/runtime/query/iteration/phases/working-memory.ts +86 -0
  381. package/src/runtime/query/prompt.ts +17 -1
  382. package/src/runtime/query/tooling.ts +2 -0
  383. package/src/sandbox/provider/local.ts +33 -0
  384. package/src/session/workspace/__tests__/shared-run.test.ts +181 -0
  385. package/src/session/workspace/index.ts +6 -0
  386. package/src/session/workspace/shared-run.ts +317 -0
  387. package/src/skills/loader.test.ts +89 -0
  388. package/src/skills/loader.ts +37 -6
  389. package/src/streaming/coalesce.test.ts +4 -4
  390. package/src/tools/builtins/__tests__/edit.test.ts +57 -0
  391. package/src/tools/builtins/__tests__/payload-budget.test.ts +92 -0
  392. package/src/tools/builtins/__tests__/read-file.test.ts +43 -0
  393. package/src/tools/builtins/__tests__/verify-outputs.test.ts +71 -0
  394. package/src/tools/builtins/__tests__/write-file.test.ts +97 -0
  395. package/src/tools/builtins/bash.ts +48 -7
  396. package/src/tools/builtins/edit.ts +162 -27
  397. package/src/tools/builtins/index.ts +13 -13
  398. package/src/tools/builtins/read-file.ts +81 -10
  399. package/src/tools/builtins/search-tools.ts +42 -7
  400. package/src/tools/builtins/verify-outputs.ts +126 -0
  401. package/src/tools/builtins/write-file.ts +83 -14
  402. package/src/tools/coordinator/__tests__/agent.test.ts +172 -0
  403. package/src/tools/coordinator/__tests__/approve-plan.test.ts +139 -0
  404. package/src/tools/coordinator/__tests__/ask-user-question.test.ts +370 -0
  405. package/src/tools/coordinator/__tests__/task-list.test.ts +182 -0
  406. package/src/tools/coordinator/agent.ts +157 -0
  407. package/src/tools/coordinator/index.ts +355 -39
  408. package/src/types/agent/base.ts +8 -0
  409. package/src/types/agent/index.ts +1 -0
  410. package/src/types/agent/reactive.ts +42 -0
  411. package/src/types/agent/supervisor.ts +36 -0
  412. package/src/types/agent/working-memory.ts +29 -0
  413. package/src/types/common/index.ts +19 -0
  414. package/src/types/common/usage-merge.test.ts +53 -0
  415. package/src/types/connector/mcp.ts +14 -2
  416. package/src/types/hitl/index.ts +52 -1
  417. package/src/types/message/index.ts +32 -2
  418. package/src/types/provider/chat.ts +12 -9
  419. package/src/types/run/events.ts +6 -0
  420. package/src/types/sandbox/index.ts +219 -0
  421. package/src/types/skills/index.ts +4 -0
  422. package/src/types/tool/index.ts +24 -0
  423. package/src/types/toolset/index.ts +86 -0
  424. package/src/types/workspace/index.ts +9 -0
  425. package/src/types/workspace/shared-run.ts +65 -0
  426. package/src/verification/index.ts +1 -0
  427. package/src/verification/presets.test.ts +112 -0
  428. package/src/verification/presets.ts +72 -0
  429. package/src/version.ts +26 -4
@@ -0,0 +1,169 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest'
2
+
3
+ import type { MCPJsonRpcMessage } from '../../types/connector/index.js'
4
+ import { MCPClient } from './client.js'
5
+
6
+ afterEach(() => {
7
+ vi.unstubAllGlobals()
8
+ })
9
+
10
+ describe('Streamable HTTP MCP transport', () => {
11
+ it('connects through MCPClient, preserves session headers, and parses SSE responses', async () => {
12
+ const fetchMock = vi.fn<typeof fetch>()
13
+ fetchMock
14
+ .mockResolvedValueOnce(
15
+ jsonResponse(
16
+ {
17
+ jsonrpc: '2.0',
18
+ id: 1,
19
+ result: {
20
+ protocolVersion: '2024-11-05',
21
+ capabilities: { tools: { listChanged: true } },
22
+ serverInfo: { name: 'github' },
23
+ },
24
+ },
25
+ { 'mcp-session-id': 'sid_123' },
26
+ ),
27
+ )
28
+ .mockResolvedValueOnce(new Response('', { status: 202 }))
29
+ .mockResolvedValueOnce(
30
+ sseResponse([
31
+ { jsonrpc: '2.0', method: 'notifications/progress', params: { pct: 50 } },
32
+ {
33
+ jsonrpc: '2.0',
34
+ id: 2,
35
+ result: {
36
+ tools: [
37
+ {
38
+ name: 'search_repositories',
39
+ description: 'Search repositories',
40
+ inputSchema: { type: 'object' },
41
+ },
42
+ ],
43
+ },
44
+ },
45
+ ]),
46
+ )
47
+ vi.stubGlobal('fetch', fetchMock)
48
+
49
+ const client = new MCPClient({
50
+ serverName: 'github',
51
+ transport: {
52
+ type: 'streamable_http',
53
+ url: 'https://mcp.example.test/mcp',
54
+ headers: { Authorization: 'Bearer token' },
55
+ },
56
+ })
57
+ const notifications: string[] = []
58
+ client.onNotification((method) => notifications.push(method))
59
+
60
+ await client.connect()
61
+ const tools = await client.listTools()
62
+
63
+ expect(tools.map((tool) => tool.name)).toEqual(['search_repositories'])
64
+ expect(notifications).toEqual(['notifications/progress'])
65
+ expect(fetchMock).toHaveBeenCalledTimes(3)
66
+
67
+ const initialize = requestAt(fetchMock, 0)
68
+ expect(initialize.input).toBe('https://mcp.example.test/mcp')
69
+ expect(initialize.body.method).toBe('initialize')
70
+ expect(initialize.headers.Authorization).toBe('Bearer token')
71
+ expect(initialize.headers.Accept).toBe('application/json, text/event-stream')
72
+
73
+ const initialized = requestAt(fetchMock, 1)
74
+ expect(initialized.body.method).toBe('notifications/initialized')
75
+ expect(initialized.headers['Mcp-Session-Id']).toBe('sid_123')
76
+
77
+ const listTools = requestAt(fetchMock, 2)
78
+ expect(listTools.body.method).toBe('tools/list')
79
+ expect(listTools.headers['Mcp-Session-Id']).toBe('sid_123')
80
+ })
81
+
82
+ it('supports the streamable-http alias without non-standard hint headers', async () => {
83
+ const fetchMock = vi.fn<typeof fetch>()
84
+ fetchMock
85
+ .mockResolvedValueOnce(
86
+ jsonResponse(
87
+ {
88
+ jsonrpc: '2.0',
89
+ id: 1,
90
+ result: {
91
+ protocolVersion: '2024-11-05',
92
+ capabilities: { tools: {} },
93
+ serverInfo: { name: 'linear' },
94
+ },
95
+ },
96
+ { 'Mcp-Session-Id': 'sid_alias' },
97
+ ),
98
+ )
99
+ .mockResolvedValueOnce(new Response(null, { status: 204 }))
100
+ .mockResolvedValueOnce(
101
+ jsonResponse({
102
+ jsonrpc: '2.0',
103
+ id: 2,
104
+ result: { content: [{ type: 'text', text: 'ok' }] },
105
+ }),
106
+ )
107
+ vi.stubGlobal('fetch', fetchMock)
108
+
109
+ const client = new MCPClient({
110
+ serverName: 'linear',
111
+ transport: {
112
+ type: 'streamable-http',
113
+ url: 'https://mcp.example.test/linear',
114
+ },
115
+ })
116
+
117
+ await client.connect()
118
+ const result = await client.callTool('create_issue', { title: 'Bug' })
119
+
120
+ expect(result.content).toEqual([{ type: 'text', text: 'ok' }])
121
+ const callTool = requestAt(fetchMock, 2)
122
+ expect(callTool.body.method).toBe('tools/call')
123
+ expect(callTool.headers).toEqual({
124
+ 'Content-Type': 'application/json',
125
+ Accept: 'application/json, text/event-stream',
126
+ 'Mcp-Session-Id': 'sid_alias',
127
+ })
128
+ })
129
+ })
130
+
131
+ function jsonResponse(body: MCPJsonRpcMessage, headers?: Record<string, string>): Response {
132
+ return new Response(JSON.stringify(body), {
133
+ status: 200,
134
+ headers: {
135
+ 'content-type': 'application/json',
136
+ ...headers,
137
+ },
138
+ })
139
+ }
140
+
141
+ function sseResponse(messages: MCPJsonRpcMessage[]): Response {
142
+ return new Response(messages.map((message) => `data: ${JSON.stringify(message)}\n\n`).join(''), {
143
+ status: 200,
144
+ headers: {
145
+ 'content-type': 'text/event-stream',
146
+ },
147
+ })
148
+ }
149
+
150
+ function requestAt(
151
+ fetchMock: ReturnType<typeof vi.fn<typeof fetch>>,
152
+ index: number,
153
+ ): {
154
+ input: Parameters<typeof fetch>[0]
155
+ headers: Record<string, string>
156
+ body: MCPJsonRpcMessage
157
+ } {
158
+ const call = fetchMock.mock.calls[index]
159
+ if (!call) {
160
+ throw new Error(`No fetch call at index ${index}`)
161
+ }
162
+ const [input, init] = call
163
+ if (!init) {
164
+ throw new Error(`Fetch call at index ${index} had no init`)
165
+ }
166
+ const headers = init.headers as Record<string, string>
167
+ const body = JSON.parse(String(init.body)) as MCPJsonRpcMessage
168
+ return { input, headers, body }
169
+ }
@@ -0,0 +1,152 @@
1
+ import type {
2
+ MCPJsonRpcMessage,
3
+ MCPStreamableHttpTransportConfig,
4
+ MCPTransport,
5
+ } from '../../types/connector/index.js'
6
+ import { type Logger, getRootLogger } from '../../utils/logger.js'
7
+
8
+ const DEFAULT_TIMEOUT_MS = 30_000
9
+
10
+ export class StreamableHttpTransport implements MCPTransport {
11
+ private messageHandlers: Array<(message: MCPJsonRpcMessage) => void> = []
12
+ private closeHandlers: Array<() => void> = []
13
+ private errorHandlers: Array<(error: Error) => void> = []
14
+ private connected = false
15
+ private sessionId: string | null = null
16
+ private log: Logger
17
+
18
+ constructor(private readonly config: MCPStreamableHttpTransportConfig) {
19
+ this.log = getRootLogger().child({ component: 'StreamableHttpTransport' })
20
+ }
21
+
22
+ async connect(): Promise<void> {
23
+ if (this.connected) return
24
+ this.connected = true
25
+ this.log.info(`StreamableHttpTransport connected to ${this.config.url}`)
26
+ }
27
+
28
+ async close(): Promise<void> {
29
+ if (!this.connected) return
30
+ this.connected = false
31
+ for (const handler of this.closeHandlers) handler()
32
+ }
33
+
34
+ async send(message: MCPJsonRpcMessage): Promise<void> {
35
+ if (!this.connected) {
36
+ throw new Error('StreamableHttpTransport: not connected')
37
+ }
38
+
39
+ const controller = new AbortController()
40
+ const timeout = setTimeout(
41
+ () => controller.abort(),
42
+ this.config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
43
+ )
44
+
45
+ try {
46
+ const response = await fetch(this.config.url, {
47
+ method: 'POST',
48
+ headers: this.buildHeaders(),
49
+ body: JSON.stringify(message),
50
+ signal: controller.signal,
51
+ })
52
+
53
+ this.captureSessionId(response)
54
+
55
+ if (!response.ok) {
56
+ throw new Error(`StreamableHttpTransport: HTTP ${response.status}: ${response.statusText}`)
57
+ }
58
+
59
+ await this.dispatchResponseMessages(response)
60
+ } catch (err) {
61
+ const error = err instanceof Error ? err : new Error(String(err))
62
+ for (const handler of this.errorHandlers) handler(error)
63
+ throw error
64
+ } finally {
65
+ clearTimeout(timeout)
66
+ }
67
+ }
68
+
69
+ onMessage(handler: (message: MCPJsonRpcMessage) => void): void {
70
+ this.messageHandlers.push(handler)
71
+ }
72
+
73
+ onClose(handler: () => void): void {
74
+ this.closeHandlers.push(handler)
75
+ }
76
+
77
+ onError(handler: (error: Error) => void): void {
78
+ this.errorHandlers.push(handler)
79
+ }
80
+
81
+ isConnected(): boolean {
82
+ return this.connected
83
+ }
84
+
85
+ private buildHeaders(): Record<string, string> {
86
+ const headers: Record<string, string> = {
87
+ 'Content-Type': 'application/json',
88
+ Accept: 'application/json, text/event-stream',
89
+ ...this.config.headers,
90
+ }
91
+
92
+ if (this.sessionId) {
93
+ headers['Mcp-Session-Id'] = this.sessionId
94
+ }
95
+
96
+ return headers
97
+ }
98
+
99
+ private captureSessionId(response: Response): void {
100
+ const sessionId =
101
+ response.headers.get('mcp-session-id') ?? response.headers.get('Mcp-Session-Id')
102
+ if (sessionId && sessionId.length > 0) {
103
+ this.sessionId = sessionId
104
+ }
105
+ }
106
+
107
+ private async dispatchResponseMessages(response: Response): Promise<void> {
108
+ const text = await response.text()
109
+ if (text.trim().length === 0) return
110
+
111
+ const contentType = response.headers.get('content-type') ?? ''
112
+ const messages = contentType.includes('text/event-stream')
113
+ ? parseSseMessages(text)
114
+ : parseJsonMessages(text)
115
+
116
+ for (const message of messages) {
117
+ for (const handler of this.messageHandlers) handler(message)
118
+ }
119
+ }
120
+ }
121
+
122
+ function parseJsonMessages(raw: string): MCPJsonRpcMessage[] {
123
+ const parsed = JSON.parse(raw) as MCPJsonRpcMessage | MCPJsonRpcMessage[]
124
+ return Array.isArray(parsed) ? parsed : [parsed]
125
+ }
126
+
127
+ function parseSseMessages(raw: string): MCPJsonRpcMessage[] {
128
+ const normalized = raw.replace(/\r\n/g, '\n')
129
+ const events = normalized.split(/\n\n+/)
130
+ const messages: MCPJsonRpcMessage[] = []
131
+
132
+ for (const event of events) {
133
+ const dataLines = event
134
+ .split('\n')
135
+ .filter((line) => line.startsWith('data:'))
136
+ .map((line) => line.slice('data:'.length).trimStart())
137
+
138
+ if (dataLines.length === 0) continue
139
+
140
+ const data = dataLines.join('\n').trim()
141
+ if (data.length === 0 || data === '[DONE]') continue
142
+
143
+ const parsed = JSON.parse(data) as MCPJsonRpcMessage | MCPJsonRpcMessage[]
144
+ if (Array.isArray(parsed)) {
145
+ messages.push(...parsed)
146
+ } else {
147
+ messages.push(parsed)
148
+ }
149
+ }
150
+
151
+ return messages
152
+ }
@@ -1,10 +1,15 @@
1
- export const READ_TOOLS = new Set(['read_file'])
1
+ // Tool-name buckets used by the compaction extractor to classify
2
+ // captured tool results. Lowercase to match the canonical builtin
3
+ // tool names (Anthropic Claude emits `tool_use.name` lowercase, see
4
+ // ses_008-tool-name-case-fix). `edit` is grouped with `write`
5
+ // because both mutate file content.
6
+ export const READ_TOOLS = new Set(['read'])
2
7
 
3
- export const EDIT_TOOLS = new Set(['write_file'])
8
+ export const EDIT_TOOLS = new Set(['write', 'edit'])
4
9
 
5
10
  export const SHELL_TOOLS = new Set(['bash'])
6
11
 
7
- export const SEARCH_TOOLS = new Set(['glob', 'search_tools'])
12
+ export const SEARCH_TOOLS = new Set(['glob', 'grep'])
8
13
 
9
14
  export const SECTION_HEADERS = {
10
15
  task: '## Task',
@@ -29,3 +29,40 @@ export const SANDBOX_SAFE_ENV_KEYS = new Set([
29
29
  'LC_ALL',
30
30
  'LC_CTYPE',
31
31
  ])
32
+
33
+ // ---------------------------------------------------------------------------
34
+ // ContainerSandboxLayout default container paths
35
+ // ---------------------------------------------------------------------------
36
+ //
37
+ // Mirrors the taxonomy Anthropic's container architecture exposes to
38
+ // the model (Claude container blueprint, Code Interpreter, "skills").
39
+ // Exported so prompt-template consumers can write
40
+ // `Outputs go to ${SANDBOX_DEFAULT_OUTPUTS_PATH}` instead of
41
+ // hard-coding the string in two places that drift.
42
+
43
+ /** Default container path for the user-visible outputs (RW) bind. */
44
+ export const SANDBOX_DEFAULT_OUTPUTS_PATH = '/mnt/user-data/outputs'
45
+
46
+ /** Default container path for user-uploaded files (RO). */
47
+ export const SANDBOX_DEFAULT_UPLOADS_PATH = '/mnt/user-data/uploads'
48
+
49
+ /**
50
+ * Default container path for the agent's working/scratch space (RW).
51
+ * Sibling mount to {@link SANDBOX_DEFAULT_OUTPUTS_PATH} — anything
52
+ * written here is invisible to the output collector by design,
53
+ * mirroring the Anthropic Cowork pattern (`/home/claude` scratch vs.
54
+ * `/mnt/user-data/outputs` user-visible).
55
+ */
56
+ export const SANDBOX_DEFAULT_SCRATCH_PATH = '/mnt/user-data/scratch'
57
+
58
+ /** Default container path for cached tool fetches (RO). */
59
+ export const SANDBOX_DEFAULT_TOOL_RESULTS_PATH = '/mnt/user-data/tool_results'
60
+
61
+ /** Default container path for prior-conversation transcripts (RO). */
62
+ export const SANDBOX_DEFAULT_TRANSCRIPTS_PATH = '/mnt/transcripts'
63
+
64
+ /**
65
+ * Default parent path under which each skill bundle binds.
66
+ * Per-skill default is `${SANDBOX_DEFAULT_SKILLS_PARENT}/<skill-id>`.
67
+ */
68
+ export const SANDBOX_DEFAULT_SKILLS_PARENT = '/mnt/skills'
@@ -1,3 +1,34 @@
1
- export const DANGEROUS_PATTERNS = [/rm\s+-rf\s+\//, /mkfs/, /dd\s+if=/, /:(){ :\|:& };:/]
1
+ // Patterns the verification gate's `deny_dangerous_patterns` rule
2
+ // matches against the JSON-serialised tool input. The list is
3
+ // intentionally short and high-signal: the goal is to catch the
4
+ // canonical "I will brick the host" mistakes (filesystem wipes,
5
+ // disk reformat, fork bomb) plus the most common shell-side
6
+ // privilege/escape patterns (root sudo, world-writable chmod, the
7
+ // classic curl|bash / wget|bash exfil-then-exec pipe, raw eval).
8
+ //
9
+ // This is NOT a security boundary — Cursor learned the hard way
10
+ // that bash denylists are bypassed via shell tricks like `e""cho`
11
+ // (see Backslash Security 2025). Sandbox enforcement (FS isolation,
12
+ // network egress proxy) is the real boundary; these patterns only
13
+ // catch the most blatant attempts and turn them into an explicit
14
+ // review prompt instead of a silent execute.
15
+ export const DANGEROUS_PATTERNS = [
16
+ // Filesystem wipe / fork bomb / raw disk write.
17
+ /rm\s+-rf\s+\//,
18
+ /mkfs/,
19
+ /dd\s+if=/,
20
+ /:(){ :\|:& };:/,
21
+ // Privilege escalation + world-writable chmod on /.
22
+ /\bsudo\b/,
23
+ /\bsu\s+-/,
24
+ /chmod\s+(?:-R\s+)?777\s+\//,
25
+ // Pipe-to-shell from network — exfil-then-exec staging.
26
+ /\bcurl\b[^|]*\|\s*(?:sh|bash|zsh)\b/,
27
+ /\bwget\b[^|]*\|\s*(?:sh|bash|zsh)\b/,
28
+ // Remote shell / outbound SSH.
29
+ /\bssh\s+\S+@/,
30
+ // Raw eval of dynamic strings.
31
+ /\beval\s+["'`$]/,
32
+ ]
2
33
 
3
- export const FILESYSTEM_TOOLS = new Set(['glob', 'read_file', 'write_file', 'bash'])
34
+ export const FILESYSTEM_TOOLS = new Set(['glob', 'read', 'write', 'bash'])
@@ -1,8 +1,9 @@
1
1
  import { EMPTY_TOKEN_USAGE } from '../../constants/limits.js'
2
+ import { AUTO_CONTINUATION_USER_MESSAGE } from '../../runtime/query/continuation.js'
2
3
  import { RunDiskStore } from '../../store/run/disk.js'
3
4
  import { type CostInfo, type TokenUsage, accumulateTokenUsage } from '../../types/common/index.js'
4
5
  import type { RunId, SessionId, TenantId } from '../../types/ids/index.js'
5
- import type { AssistantMessage, Message } from '../../types/message/index.js'
6
+ import type { Message } from '../../types/message/index.js'
6
7
  import type { EmergencySaveData } from '../../types/run/emergency.js'
7
8
  import type { Run, RunPersistenceConfig, StopReason } from '../../types/run/index.js'
8
9
  import type { ProjectId, ThreadId } from '../../types/session/ids.js'
@@ -169,12 +170,39 @@ export class RunPersistence {
169
170
  }
170
171
 
171
172
  private resolveResult(): void {
172
- const lastAssistant = [...this.run.messages]
173
- .reverse()
174
- .find((m): m is AssistantMessage => m.role === 'assistant' && m.content !== null)
173
+ // Walk the tail of the message log to assemble the final
174
+ // assistant output. The iteration loop's auto-continuation
175
+ // path (see `runtime/query/iteration/index.ts`) inserts a
176
+ // synthetic user prompt — exactly equal to
177
+ // `AUTO_CONTINUATION_USER_MESSAGE` — between two assistant
178
+ // messages whenever a turn ended with
179
+ // `stop_reason: max_tokens` mid-text. Treat that synthetic
180
+ // user as transparent: keep collecting assistant content past
181
+ // it so the run's persisted `result` carries the full
182
+ // multi-turn output, not just the trailing continuation
183
+ // chunk. Stops at the first non-assistant, non-marker
184
+ // message (e.g. the real user prompt that started the run,
185
+ // or a tool message between turns).
186
+ const chunks: string[] = []
187
+ for (let i = this.run.messages.length - 1; i >= 0; i--) {
188
+ const msg = this.run.messages[i]
189
+ if (!msg) continue
190
+ if (msg.role === 'assistant') {
191
+ if (msg.content !== null) chunks.push(msg.content)
192
+ continue
193
+ }
194
+ if (msg.role === 'user' && msg.content === AUTO_CONTINUATION_USER_MESSAGE) {
195
+ // Synthetic continuation prompt — skip and keep
196
+ // collecting the partial that preceded it.
197
+ continue
198
+ }
199
+ break
200
+ }
175
201
 
176
- if (lastAssistant?.content) {
177
- this.run.result = lastAssistant.content
202
+ if (chunks.length > 0) {
203
+ // chunks were collected newest-first; reverse so the
204
+ // assembled string is chronological.
205
+ this.run.result = chunks.reverse().join('')
178
206
  }
179
207
  }
180
208
 
@@ -23,14 +23,9 @@ export function assembleSystemPrompt(persona: AgentPersona, skills?: Skill[]): s
23
23
  }
24
24
  }
25
25
 
26
- if (skills && skills.length > 0) {
27
- const loadedSkills = skills.filter((s) => s.body)
28
- if (loadedSkills.length > 0) {
29
- const skillSections = loadedSkills.map(
30
- (s) => `### ${s.metadata.name}\n**Skill directory:** \`${s.dirPath}\`\n\n${s.body}`,
31
- )
32
- sections.push(`## Skills\n\n${skillSections.join('\n\n')}`)
33
- }
26
+ const skillsSection = renderSkillsSection(skills)
27
+ if (skillsSection) {
28
+ sections.push(skillsSection)
34
29
  }
35
30
 
36
31
  if (persona.reflexes?.outputDiscipline) {
@@ -48,6 +43,46 @@ export function assembleSystemPrompt(persona: AgentPersona, skills?: Skill[]): s
48
43
  return sections.join('\n\n')
49
44
  }
50
45
 
46
+ export function renderSkillsSection(skills?: Skill[]): string | null {
47
+ if (!skills || skills.length === 0) return null
48
+
49
+ const available = skills
50
+ .map((s) => {
51
+ const lines = [
52
+ '<skill>',
53
+ `<name>${s.metadata.name}</name>`,
54
+ `<description>${s.metadata.description.trim()}</description>`,
55
+ `<location>${s.dirPath}/SKILL.md</location>`,
56
+ ]
57
+ if (s.metadata.compatibility) {
58
+ lines.push(`<compatibility>${s.metadata.compatibility}</compatibility>`)
59
+ }
60
+ if (s.metadata.license) {
61
+ lines.push(`<license>${s.metadata.license}</license>`)
62
+ }
63
+ if (s.metadata.allowedTools) {
64
+ lines.push(`<allowed_tools>${s.metadata.allowedTools}</allowed_tools>`)
65
+ }
66
+ lines.push('</skill>')
67
+ return lines.join('\n')
68
+ })
69
+ .join('\n')
70
+
71
+ const loadedSkills = skills.filter((s) => s.body)
72
+ const sections = [
73
+ `## Available Skills\nThe following block is a manifest, not the full skill content. Skill metadata is always visible; SKILL.md bodies are loaded only when the user's task matches the skill description.\n\n<available_skills>\n${available}\n</available_skills>\n\nSkill usage protocol:\n- Plain questions do not require a skill.\n- When a matching skill is already listed under Loaded Skills, apply its loaded instructions.\n- When a matching skill is not loaded and the runtime exposes filesystem or skill-loading tools, read the SKILL.md at its <location> before writing code, creating files, running shell commands for that workflow, or calling mutation tools guided by the skill.\n- Do not claim to have read a SKILL.md until its content is actually present in the prompt or returned by a tool.\n- Tool schemas and runtime permissions remain authoritative; skills provide guidance, not hidden tools.`,
74
+ ]
75
+
76
+ if (loadedSkills.length > 0) {
77
+ const skillSections = loadedSkills.map(
78
+ (s) => `### ${s.metadata.name}\n**Skill directory:** \`${s.dirPath}\`\n\n${s.body}`,
79
+ )
80
+ sections.push(`## Loaded Skills\n\n${skillSections.join('\n\n')}`)
81
+ }
82
+
83
+ return sections.join('\n\n')
84
+ }
85
+
51
86
  export function renderOutputDiscipline(discipline: OutputDiscipline): string {
52
87
  const lines: string[] = []
53
88
 
@@ -57,7 +57,7 @@ describe('collect()', () => {
57
57
  id: 'm',
58
58
  delta: {
59
59
  toolCalls: [
60
- { index: 0, id: 'toolu_a', function: { name: 'Read' } },
60
+ { index: 0, id: 'toolu_a', function: { name: 'read' } },
61
61
  { index: 1, id: 'toolu_b', function: { name: 'WebSearch' } },
62
62
  ],
63
63
  },
@@ -84,7 +84,7 @@ describe('collect()', () => {
84
84
  {
85
85
  id: 'toolu_a',
86
86
  type: 'function',
87
- function: { name: 'Read', arguments: '{"file_path":"/a"}' },
87
+ function: { name: 'read', arguments: '{"file_path":"/a"}' },
88
88
  },
89
89
  {
90
90
  id: 'toolu_b',
@@ -1,3 +1,4 @@
1
+ import { mergeTokenUsage } from '../types/common/index.js'
1
2
  import type { ChatCompletionResponse } from '../types/provider/chat.js'
2
3
  import type { StreamChunk } from '../types/provider/stream.js'
3
4
 
@@ -60,7 +61,9 @@ export async function collect(stream: AsyncIterable<StreamChunk>): Promise<ChatC
60
61
  }
61
62
 
62
63
  if (chunk.finishReason) finishReason = chunk.finishReason
63
- if (chunk.usage) usage = chunk.usage
64
+ // Merge (per-field max), not last-write-wins: a late frame that omits
65
+ // input/cache tokens must not zero the counts captured earlier in the stream.
66
+ if (chunk.usage) usage = mergeTokenUsage(usage, chunk.usage)
64
67
  }
65
68
 
66
69
  const toolCalls = [...toolBuckets.entries()]
@@ -113,7 +113,11 @@ export {
113
113
  ManagedRegistry,
114
114
  PluginRegistry,
115
115
  Registry,
116
+ ToolCatalog,
116
117
  ToolRegistry,
118
+ createToolCatalogFromRegistry,
119
+ loadingFromAvailability,
120
+ toolDefinitionToCatalogEntry,
117
121
  } from './registry/index.js'
118
122
 
119
123
  export {
@@ -129,8 +133,11 @@ export {
129
133
  EmergencySaveManager,
130
134
  PlanManager,
131
135
  RunPersistence,
136
+ ThreadManager,
132
137
  } from './manager/index.js'
133
138
 
139
+ export { InMemoryThreadStore } from './store/thread/memory.js'
140
+
134
141
  export { LocalTaskGateway } from './gateway/local.js'
135
142
 
136
143
  // ─── providers, sandbox, vault ───────────────────────────────────────────
@@ -187,6 +194,7 @@ export {
187
194
  RemoteExecutionContext,
188
195
  ScopedConnectorRegistry,
189
196
  StdioTransport,
197
+ StreamableHttpTransport,
190
198
  TenantConnectorManager,
191
199
  toolDefinitionToMCPTool,
192
200
  toolResultToMCPToolResult,
@@ -220,7 +228,12 @@ export {
220
228
  FileLockManager,
221
229
  } from './bus/index.js'
222
230
 
223
- export { evaluateRule, VerificationGate } from './verification/index.js'
231
+ export {
232
+ defaultSandboxedGateConfig,
233
+ defaultSandboxedShellGateConfig,
234
+ evaluateRule,
235
+ VerificationGate,
236
+ } from './verification/index.js'
224
237
 
225
238
  // ─── probe (typed observation over AgentBus + RunEvent stream) ───────────
226
239
 
@@ -254,6 +267,7 @@ export {
254
267
  DefaultPathBuilder,
255
268
  GitWorktreeDriver,
256
269
  parseWorktreeList,
270
+ SharedRunWorkspace,
257
271
  WorkspaceBackendRegistry,
258
272
  } from './session/workspace/index.js'
259
273
 
@@ -24,6 +24,7 @@ export { GlobTool } from './tools/builtins/glob.js'
24
24
  export { GrepTool } from './tools/builtins/grep.js'
25
25
  export { LsTool } from './tools/builtins/ls.js'
26
26
  export { SearchToolsTool } from './tools/builtins/search-tools.js'
27
+ export { VerifyOutputsTool } from './tools/builtins/verify-outputs.js'
27
28
  export {
28
29
  createStructuredOutputTool,
29
30
  STRUCTURED_OUTPUT_TOOL_NAME,
@@ -44,6 +45,7 @@ export {
44
45
  export { buildAdvisoryTools } from './tools/advisory/index.js'
45
46
  export { buildMemoryTools } from './tools/memory/index.js'
46
47
  export { buildCoordinatorTools } from './tools/coordinator/index.js'
48
+ export { buildAgentTool, type AgentToolOptions } from './tools/coordinator/agent.js'
47
49
 
48
50
  // ─── RAG tool builder ────────────────────────────────────────────────────
49
51
 
@@ -17,6 +17,7 @@ export type * from './types/ids/index.js'
17
17
  export type * from './types/message/index.js'
18
18
  export type * from './types/common/index.js'
19
19
  export type * from './types/tool/index.js'
20
+ export type * from './types/toolset/index.js'
20
21
  export type * from './types/permission/index.js'
21
22
  export type * from './types/run/index.js'
22
23
  export type * from './types/provider/index.js'
@@ -44,6 +45,7 @@ export type * from './types/verification/index.js'
44
45
  export type * from './types/bus/index.js'
45
46
  export type * from './types/probe/index.js'
46
47
  export type * from './types/doctor/index.js'
48
+ export type * from './types/workspace/index.js'
47
49
 
48
50
  // Session-hierarchy type surface (ses_010 moved entities here).
49
51
  export type * from './types/session/index.js'
@@ -118,6 +120,11 @@ export type { AdvisoryToolsOptions } from './tools/advisory/index.js'
118
120
 
119
121
  export type { CoordinatorToolsOptions, TaskLaunchedCallback } from './tools/coordinator/index.js'
120
122
 
123
+ export type {
124
+ RegisterSharedRunPlanInput,
125
+ SharedRunWorkspaceConfig,
126
+ } from './session/workspace/index.js'
127
+
121
128
  export type {
122
129
  ConnectorManagerConfig,
123
130
  EnvironmentConnectorManagerConfig,