@namzu/sdk 48.3.1 → 50.0.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 (838) hide show
  1. package/CHANGELOG.md +542 -0
  2. package/README.md +137 -125
  3. package/dist/agents/QueryAgent.d.ts.map +1 -1
  4. package/dist/agents/QueryAgent.js +1 -0
  5. package/dist/agents/QueryAgent.js.map +1 -1
  6. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  7. package/dist/agents/examples/SupervisorAgent.js +1 -0
  8. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  9. package/dist/agents/runAgent.d.ts +2 -0
  10. package/dist/agents/runAgent.d.ts.map +1 -1
  11. package/dist/agents/runAgent.js +1 -0
  12. package/dist/agents/runAgent.js.map +1 -1
  13. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  14. package/dist/authorization/shell-lexer.js +16 -1
  15. package/dist/authorization/shell-lexer.js.map +1 -1
  16. package/dist/bridge/acp/permission.d.ts +8 -2
  17. package/dist/bridge/acp/permission.d.ts.map +1 -1
  18. package/dist/bridge/acp/permission.js +1 -0
  19. package/dist/bridge/acp/permission.js.map +1 -1
  20. package/dist/bridge/acp/server.d.ts +25 -1
  21. package/dist/bridge/acp/server.d.ts.map +1 -1
  22. package/dist/bridge/acp/server.js +205 -21
  23. package/dist/bridge/acp/server.js.map +1 -1
  24. package/dist/bridge/acp/tasks.d.ts +5 -0
  25. package/dist/bridge/acp/tasks.d.ts.map +1 -0
  26. package/dist/bridge/acp/tasks.js +19 -0
  27. package/dist/bridge/acp/tasks.js.map +1 -0
  28. package/dist/bridge/acp/update.d.ts.map +1 -1
  29. package/dist/bridge/acp/update.js +148 -13
  30. package/dist/bridge/acp/update.js.map +1 -1
  31. package/dist/config/registry.d.ts +2 -0
  32. package/dist/config/registry.d.ts.map +1 -1
  33. package/dist/config/registry.js +23 -3
  34. package/dist/config/registry.js.map +1 -1
  35. package/dist/config/runtime.d.ts +31 -31
  36. package/dist/connector/mcp/adapter.d.ts.map +1 -1
  37. package/dist/connector/mcp/adapter.js +11 -4
  38. package/dist/connector/mcp/adapter.js.map +1 -1
  39. package/dist/connector/mcp/client.d.ts.map +1 -1
  40. package/dist/connector/mcp/client.js +6 -3
  41. package/dist/connector/mcp/client.js.map +1 -1
  42. package/dist/connector/mcp/discovery.d.ts +9 -5
  43. package/dist/connector/mcp/discovery.d.ts.map +1 -1
  44. package/dist/connector/mcp/discovery.js +16 -8
  45. package/dist/connector/mcp/discovery.js.map +1 -1
  46. package/dist/connector/mcp/mcp-toolset.d.ts +3 -0
  47. package/dist/connector/mcp/mcp-toolset.d.ts.map +1 -1
  48. package/dist/connector/mcp/mcp-toolset.js +20 -2
  49. package/dist/connector/mcp/mcp-toolset.js.map +1 -1
  50. package/dist/connector/mcp/reconnect.d.ts +2 -0
  51. package/dist/connector/mcp/reconnect.d.ts.map +1 -1
  52. package/dist/connector/mcp/reconnect.js +36 -5
  53. package/dist/connector/mcp/reconnect.js.map +1 -1
  54. package/dist/constants/acp/index.d.ts +3 -0
  55. package/dist/constants/acp/index.d.ts.map +1 -1
  56. package/dist/constants/acp/index.js +3 -0
  57. package/dist/constants/acp/index.js.map +1 -1
  58. package/dist/contracts/a2a.d.ts +80 -80
  59. package/dist/contracts/schemas.d.ts +2 -2
  60. package/dist/contracts/session/schemas.d.ts +10 -10
  61. package/dist/manager/agent/lifecycle.d.ts +11 -0
  62. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  63. package/dist/manager/agent/lifecycle.js +178 -3
  64. package/dist/manager/agent/lifecycle.js.map +1 -1
  65. package/dist/manager/plan/lifecycle.d.ts +7 -8
  66. package/dist/manager/plan/lifecycle.d.ts.map +1 -1
  67. package/dist/manager/plan/lifecycle.js +7 -8
  68. package/dist/manager/plan/lifecycle.js.map +1 -1
  69. package/dist/manager/resident/consumption.d.ts +8 -8
  70. package/dist/manager/resident/learning-cycle.d.ts +2 -2
  71. package/dist/manager/resident/learning-observation.d.ts +12 -12
  72. package/dist/manager/resident/learning.d.ts +82 -82
  73. package/dist/manager/resident/outbox.d.ts +8 -8
  74. package/dist/manager/resident/proposal.d.ts +2 -2
  75. package/dist/manager/resident/store.d.ts +10 -10
  76. package/dist/manager/session/attribution.d.ts +1 -0
  77. package/dist/manager/session/attribution.d.ts.map +1 -1
  78. package/dist/manager/session/attribution.js +9 -1
  79. package/dist/manager/session/attribution.js.map +1 -1
  80. package/dist/manager/session/streamed-message-identity.d.ts +6 -0
  81. package/dist/manager/session/streamed-message-identity.d.ts.map +1 -0
  82. package/dist/manager/session/streamed-message-identity.js +14 -0
  83. package/dist/manager/session/streamed-message-identity.js.map +1 -0
  84. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  85. package/dist/manager/session/turn-recorder.js +4 -3
  86. package/dist/manager/session/turn-recorder.js.map +1 -1
  87. package/dist/pals/activity/causality.d.ts +23 -0
  88. package/dist/pals/activity/causality.d.ts.map +1 -0
  89. package/dist/pals/activity/causality.js +205 -0
  90. package/dist/pals/activity/causality.js.map +1 -0
  91. package/dist/pals/activity/projection.d.ts +5 -0
  92. package/dist/pals/activity/projection.d.ts.map +1 -0
  93. package/dist/pals/activity/projection.js +79 -0
  94. package/dist/pals/activity/projection.js.map +1 -0
  95. package/dist/pals/activity/source.d.ts +16 -0
  96. package/dist/pals/activity/source.d.ts.map +1 -0
  97. package/dist/pals/activity/source.js +235 -0
  98. package/dist/pals/activity/source.js.map +1 -0
  99. package/dist/pals/activity/subscription-policy.d.ts +38 -0
  100. package/dist/pals/activity/subscription-policy.d.ts.map +1 -0
  101. package/dist/pals/activity/subscription-policy.js +183 -0
  102. package/dist/pals/activity/subscription-policy.js.map +1 -0
  103. package/dist/pals/activity/subscription-schema.d.ts +353 -0
  104. package/dist/pals/activity/subscription-schema.d.ts.map +1 -0
  105. package/dist/pals/activity/subscription-schema.js +24 -0
  106. package/dist/pals/activity/subscription-schema.js.map +1 -0
  107. package/dist/pals/activity/subscription-store.d.ts +25 -0
  108. package/dist/pals/activity/subscription-store.d.ts.map +1 -0
  109. package/dist/pals/activity/subscription-store.js +152 -0
  110. package/dist/pals/activity/subscription-store.js.map +1 -0
  111. package/dist/pals/activity/subscription-types.d.ts +42 -0
  112. package/dist/pals/activity/subscription-types.d.ts.map +1 -0
  113. package/dist/pals/activity/subscription-types.js +2 -0
  114. package/dist/pals/activity/subscription-types.js.map +1 -0
  115. package/dist/pals/activity/subscriptions.d.ts +32 -0
  116. package/dist/pals/activity/subscriptions.d.ts.map +1 -0
  117. package/dist/pals/activity/subscriptions.js +151 -0
  118. package/dist/pals/activity/subscriptions.js.map +1 -0
  119. package/dist/pals/activity/types.d.ts +77 -0
  120. package/dist/pals/activity/types.d.ts.map +1 -0
  121. package/dist/pals/activity/types.js +2 -0
  122. package/dist/pals/activity/types.js.map +1 -0
  123. package/dist/pals/channels/ingress.d.ts +9 -0
  124. package/dist/pals/channels/ingress.d.ts.map +1 -0
  125. package/dist/pals/channels/ingress.js +131 -0
  126. package/dist/pals/channels/ingress.js.map +1 -0
  127. package/dist/pals/channels/routes.d.ts +20 -0
  128. package/dist/pals/channels/routes.d.ts.map +1 -0
  129. package/dist/pals/channels/routes.js +111 -0
  130. package/dist/pals/channels/routes.js.map +1 -0
  131. package/dist/pals/channels/routing.d.ts +37 -0
  132. package/dist/pals/channels/routing.d.ts.map +1 -0
  133. package/dist/pals/channels/routing.js +150 -0
  134. package/dist/pals/channels/routing.js.map +1 -0
  135. package/dist/pals/channels/schema.d.ts +234 -0
  136. package/dist/pals/channels/schema.d.ts.map +1 -0
  137. package/dist/pals/channels/schema.js +94 -0
  138. package/dist/pals/channels/schema.js.map +1 -0
  139. package/dist/pals/channels/types.d.ts +115 -0
  140. package/dist/pals/channels/types.d.ts.map +1 -0
  141. package/dist/pals/channels/types.js +2 -0
  142. package/dist/pals/channels/types.js.map +1 -0
  143. package/dist/pals/communication/broker.d.ts +8 -0
  144. package/dist/pals/communication/broker.d.ts.map +1 -0
  145. package/dist/pals/communication/broker.js +121 -0
  146. package/dist/pals/communication/broker.js.map +1 -0
  147. package/dist/pals/communication/dispatch.d.ts +4 -0
  148. package/dist/pals/communication/dispatch.d.ts.map +1 -0
  149. package/dist/pals/communication/dispatch.js +57 -0
  150. package/dist/pals/communication/dispatch.js.map +1 -0
  151. package/dist/pals/communication/inbound.d.ts +9 -0
  152. package/dist/pals/communication/inbound.d.ts.map +1 -0
  153. package/dist/pals/communication/inbound.js +155 -0
  154. package/dist/pals/communication/inbound.js.map +1 -0
  155. package/dist/pals/communication/ingress-dispatch.d.ts +5 -0
  156. package/dist/pals/communication/ingress-dispatch.d.ts.map +1 -0
  157. package/dist/pals/communication/ingress-dispatch.js +51 -0
  158. package/dist/pals/communication/ingress-dispatch.js.map +1 -0
  159. package/dist/pals/communication/ingress-inbound.d.ts +9 -0
  160. package/dist/pals/communication/ingress-inbound.d.ts.map +1 -0
  161. package/dist/pals/communication/ingress-inbound.js +222 -0
  162. package/dist/pals/communication/ingress-inbound.js.map +1 -0
  163. package/dist/pals/communication/ingress-schema.d.ts +7829 -0
  164. package/dist/pals/communication/ingress-schema.d.ts.map +1 -0
  165. package/dist/pals/communication/ingress-schema.js +479 -0
  166. package/dist/pals/communication/ingress-schema.js.map +1 -0
  167. package/dist/pals/communication/ingress-types.d.ts +187 -0
  168. package/dist/pals/communication/ingress-types.d.ts.map +1 -0
  169. package/dist/pals/communication/ingress-types.js +73 -0
  170. package/dist/pals/communication/ingress-types.js.map +1 -0
  171. package/dist/pals/communication/operator.d.ts +75 -0
  172. package/dist/pals/communication/operator.d.ts.map +1 -0
  173. package/dist/pals/communication/operator.js +217 -0
  174. package/dist/pals/communication/operator.js.map +1 -0
  175. package/dist/pals/communication/policy.d.ts +41 -0
  176. package/dist/pals/communication/policy.d.ts.map +1 -0
  177. package/dist/pals/communication/policy.js +138 -0
  178. package/dist/pals/communication/policy.js.map +1 -0
  179. package/dist/pals/communication/schema.d.ts +2000 -0
  180. package/dist/pals/communication/schema.d.ts.map +1 -0
  181. package/dist/pals/communication/schema.js +170 -0
  182. package/dist/pals/communication/schema.js.map +1 -0
  183. package/dist/pals/communication/store.d.ts +61 -0
  184. package/dist/pals/communication/store.d.ts.map +1 -0
  185. package/dist/pals/communication/store.js +450 -0
  186. package/dist/pals/communication/store.js.map +1 -0
  187. package/dist/pals/communication/tools.d.ts +23 -0
  188. package/dist/pals/communication/tools.d.ts.map +1 -0
  189. package/dist/pals/communication/tools.js +107 -0
  190. package/dist/pals/communication/tools.js.map +1 -0
  191. package/dist/pals/communication/types.d.ts +168 -0
  192. package/dist/pals/communication/types.d.ts.map +1 -0
  193. package/dist/pals/communication/types.js +24 -0
  194. package/dist/pals/communication/types.js.map +1 -0
  195. package/dist/pals/communication/verify.d.ts +22 -0
  196. package/dist/pals/communication/verify.d.ts.map +1 -0
  197. package/dist/pals/communication/verify.js +142 -0
  198. package/dist/pals/communication/verify.js.map +1 -0
  199. package/dist/pals/lifecycle.d.ts +37 -0
  200. package/dist/pals/lifecycle.d.ts.map +1 -0
  201. package/dist/pals/lifecycle.js +22 -0
  202. package/dist/pals/lifecycle.js.map +1 -0
  203. package/dist/pals/prompt.d.ts +30 -0
  204. package/dist/pals/prompt.d.ts.map +1 -0
  205. package/dist/pals/prompt.js +65 -0
  206. package/dist/pals/prompt.js.map +1 -0
  207. package/dist/pals/reference-images.d.ts +44 -0
  208. package/dist/pals/reference-images.d.ts.map +1 -0
  209. package/dist/pals/reference-images.js +248 -0
  210. package/dist/pals/reference-images.js.map +1 -0
  211. package/dist/pals/runtime.d.ts +46 -0
  212. package/dist/pals/runtime.d.ts.map +1 -0
  213. package/dist/pals/runtime.js +624 -0
  214. package/dist/pals/runtime.js.map +1 -0
  215. package/dist/pals/store.d.ts +26 -0
  216. package/dist/pals/store.d.ts.map +1 -0
  217. package/dist/pals/store.js +334 -0
  218. package/dist/pals/store.js.map +1 -0
  219. package/dist/pals/types.d.ts +145 -0
  220. package/dist/pals/types.d.ts.map +1 -0
  221. package/dist/pals/types.js +2 -0
  222. package/dist/pals/types.js.map +1 -0
  223. package/dist/peers/envelope.js +1 -1
  224. package/dist/peers/envelope.js.map +1 -1
  225. package/dist/peers/protocol.d.ts +83 -83
  226. package/dist/peers/record.d.ts +10 -10
  227. package/dist/plugin/lifecycle.d.ts +14 -10
  228. package/dist/plugin/lifecycle.d.ts.map +1 -1
  229. package/dist/plugin/lifecycle.js +178 -41
  230. package/dist/plugin/lifecycle.js.map +1 -1
  231. package/dist/plugin/shell-hook.d.ts.map +1 -1
  232. package/dist/plugin/shell-hook.js +7 -2
  233. package/dist/plugin/shell-hook.js.map +1 -1
  234. package/dist/process/kill-tree.d.ts.map +1 -1
  235. package/dist/process/kill-tree.js +9 -1
  236. package/dist/process/kill-tree.js.map +1 -1
  237. package/dist/prompt/resident-learning.js +2 -2
  238. package/dist/prompt/resident-learning.js.map +1 -1
  239. package/dist/prompt/resident-step.d.ts +2 -2
  240. package/dist/prompt/resident-step.js +4 -4
  241. package/dist/prompt/resident-step.js.map +1 -1
  242. package/dist/provider/errors.d.ts +19 -0
  243. package/dist/provider/errors.d.ts.map +1 -1
  244. package/dist/provider/errors.js +123 -2
  245. package/dist/provider/errors.js.map +1 -1
  246. package/dist/public-runtime.d.ts +43 -15
  247. package/dist/public-runtime.d.ts.map +1 -1
  248. package/dist/public-runtime.js +37 -9
  249. package/dist/public-runtime.js.map +1 -1
  250. package/dist/public-tools.d.ts +8 -3
  251. package/dist/public-tools.d.ts.map +1 -1
  252. package/dist/public-tools.js +8 -3
  253. package/dist/public-tools.js.map +1 -1
  254. package/dist/public-types.d.ts +27 -7
  255. package/dist/public-types.d.ts.map +1 -1
  256. package/dist/registry/tool/presentation.d.ts +1 -0
  257. package/dist/registry/tool/presentation.d.ts.map +1 -1
  258. package/dist/registry/tool/presentation.js +9 -7
  259. package/dist/registry/tool/presentation.js.map +1 -1
  260. package/dist/registry/tool/screen.d.ts.map +1 -1
  261. package/dist/registry/tool/screen.js +33 -2
  262. package/dist/registry/tool/screen.js.map +1 -1
  263. package/dist/runtime/harness-session/index.d.ts +5 -0
  264. package/dist/runtime/harness-session/index.d.ts.map +1 -0
  265. package/dist/runtime/harness-session/index.js +928 -0
  266. package/dist/runtime/harness-session/index.js.map +1 -0
  267. package/dist/runtime/harness-session/journal.d.ts +37 -0
  268. package/dist/runtime/harness-session/journal.d.ts.map +1 -0
  269. package/dist/runtime/harness-session/journal.js +177 -0
  270. package/dist/runtime/harness-session/journal.js.map +1 -0
  271. package/dist/runtime/harness-session/saved-view.d.ts +8 -0
  272. package/dist/runtime/harness-session/saved-view.d.ts.map +1 -0
  273. package/dist/runtime/harness-session/saved-view.js +112 -0
  274. package/dist/runtime/harness-session/saved-view.js.map +1 -0
  275. package/dist/runtime/jobs/awaited-jobs.d.ts +2 -1
  276. package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -1
  277. package/dist/runtime/jobs/awaited-jobs.js +2 -1
  278. package/dist/runtime/jobs/awaited-jobs.js.map +1 -1
  279. package/dist/runtime/jobs/registry.d.ts +56 -1
  280. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  281. package/dist/runtime/jobs/registry.js +377 -39
  282. package/dist/runtime/jobs/registry.js.map +1 -1
  283. package/dist/runtime/query/abandon-turn.d.ts +12 -1
  284. package/dist/runtime/query/abandon-turn.d.ts.map +1 -1
  285. package/dist/runtime/query/abandon-turn.js +3 -1
  286. package/dist/runtime/query/abandon-turn.js.map +1 -1
  287. package/dist/runtime/query/checkpoint.d.ts +4 -0
  288. package/dist/runtime/query/checkpoint.d.ts.map +1 -1
  289. package/dist/runtime/query/checkpoint.js +10 -0
  290. package/dist/runtime/query/checkpoint.js.map +1 -1
  291. package/dist/runtime/query/durable-inbound.d.ts +5 -0
  292. package/dist/runtime/query/durable-inbound.d.ts.map +1 -0
  293. package/dist/runtime/query/durable-inbound.js +89 -0
  294. package/dist/runtime/query/durable-inbound.js.map +1 -0
  295. package/dist/runtime/query/events.d.ts +4 -0
  296. package/dist/runtime/query/events.d.ts.map +1 -1
  297. package/dist/runtime/query/events.js +22 -5
  298. package/dist/runtime/query/events.js.map +1 -1
  299. package/dist/runtime/query/executor/tool-call-admission.d.ts +5 -1
  300. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  301. package/dist/runtime/query/executor/tool-call-admission.js +85 -13
  302. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  303. package/dist/runtime/query/executor.d.ts +41 -18
  304. package/dist/runtime/query/executor.d.ts.map +1 -1
  305. package/dist/runtime/query/executor.js +227 -114
  306. package/dist/runtime/query/executor.js.map +1 -1
  307. package/dist/runtime/query/index.d.ts +9 -0
  308. package/dist/runtime/query/index.d.ts.map +1 -1
  309. package/dist/runtime/query/index.js +41 -5
  310. package/dist/runtime/query/index.js.map +1 -1
  311. package/dist/runtime/query/iteration/index.d.ts +18 -6
  312. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  313. package/dist/runtime/query/iteration/index.js +176 -75
  314. package/dist/runtime/query/iteration/index.js.map +1 -1
  315. package/dist/runtime/query/iteration/outstanding-work.d.ts +9 -5
  316. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  317. package/dist/runtime/query/iteration/outstanding-work.js +63 -6
  318. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  319. package/dist/runtime/query/iteration/phases/context.d.ts +8 -0
  320. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  321. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  322. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  323. package/dist/runtime/query/iteration/phases/tool-review.js +106 -17
  324. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  325. package/dist/runtime/query/iteration/step-shaping.d.ts +2 -0
  326. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  327. package/dist/runtime/query/iteration/step-shaping.js +5 -1
  328. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  329. package/dist/runtime/query/observation-context.d.ts +2 -2
  330. package/dist/runtime/query/observation-context.d.ts.map +1 -1
  331. package/dist/runtime/query/observation-context.js +20 -13
  332. package/dist/runtime/query/observation-context.js.map +1 -1
  333. package/dist/runtime/query/prepare-turn.js +2 -2
  334. package/dist/runtime/query/prepare-turn.js.map +1 -1
  335. package/dist/runtime/query/prompt-cache.d.ts +1 -0
  336. package/dist/runtime/query/prompt-cache.d.ts.map +1 -1
  337. package/dist/runtime/query/prompt-cache.js +2 -0
  338. package/dist/runtime/query/prompt-cache.js.map +1 -1
  339. package/dist/runtime/query/prompt.d.ts +2 -0
  340. package/dist/runtime/query/prompt.d.ts.map +1 -1
  341. package/dist/runtime/query/prompt.js +23 -1
  342. package/dist/runtime/query/prompt.js.map +1 -1
  343. package/dist/runtime/query/repeat-call.d.ts +12 -3
  344. package/dist/runtime/query/repeat-call.d.ts.map +1 -1
  345. package/dist/runtime/query/repeat-call.js +33 -10
  346. package/dist/runtime/query/repeat-call.js.map +1 -1
  347. package/dist/runtime/query/resume-pending.d.ts +5 -6
  348. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  349. package/dist/runtime/query/resume-pending.js +30 -3
  350. package/dist/runtime/query/resume-pending.js.map +1 -1
  351. package/dist/runtime/query/resume-session.js +1 -1
  352. package/dist/runtime/query/resume-session.js.map +1 -1
  353. package/dist/runtime/query/review-policy.d.ts +8 -1
  354. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  355. package/dist/runtime/query/review-policy.js +6 -0
  356. package/dist/runtime/query/review-policy.js.map +1 -1
  357. package/dist/runtime/query/saved-presentation.d.ts +13 -0
  358. package/dist/runtime/query/saved-presentation.d.ts.map +1 -0
  359. package/dist/runtime/query/saved-presentation.js +63 -0
  360. package/dist/runtime/query/saved-presentation.js.map +1 -0
  361. package/dist/runtime/query/steering.d.ts +6 -9
  362. package/dist/runtime/query/steering.d.ts.map +1 -1
  363. package/dist/runtime/query/steering.js.map +1 -1
  364. package/dist/runtime/query/tool-executions.d.ts +7 -3
  365. package/dist/runtime/query/tool-executions.d.ts.map +1 -1
  366. package/dist/runtime/query/tool-executions.js +89 -9
  367. package/dist/runtime/query/tool-executions.js.map +1 -1
  368. package/dist/runtime/query/tooling.d.ts +3 -1
  369. package/dist/runtime/query/tooling.d.ts.map +1 -1
  370. package/dist/runtime/query/tooling.js +3 -0
  371. package/dist/runtime/query/tooling.js.map +1 -1
  372. package/dist/scheduler/completion-inbox.d.ts +25 -1
  373. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  374. package/dist/scheduler/completion-inbox.js +102 -8
  375. package/dist/scheduler/completion-inbox.js.map +1 -1
  376. package/dist/scheduler/delegating.d.ts.map +1 -1
  377. package/dist/scheduler/delegating.js +5 -0
  378. package/dist/scheduler/delegating.js.map +1 -1
  379. package/dist/scheduler/local.d.ts.map +1 -1
  380. package/dist/scheduler/local.js +2 -0
  381. package/dist/scheduler/local.js.map +1 -1
  382. package/dist/session/summary/materialize.d.ts +10 -6
  383. package/dist/session/summary/materialize.d.ts.map +1 -1
  384. package/dist/session/summary/materialize.js +41 -8
  385. package/dist/session/summary/materialize.js.map +1 -1
  386. package/dist/store/budget/ledger.d.ts +9 -0
  387. package/dist/store/budget/ledger.d.ts.map +1 -1
  388. package/dist/store/budget/ledger.js +58 -6
  389. package/dist/store/budget/ledger.js.map +1 -1
  390. package/dist/store/evidence/index-page.d.ts +12 -12
  391. package/dist/store/evidence/source-text.d.ts +4 -4
  392. package/dist/store/index.d.ts +1 -0
  393. package/dist/store/index.d.ts.map +1 -1
  394. package/dist/store/index.js +1 -0
  395. package/dist/store/index.js.map +1 -1
  396. package/dist/store/memory/disk.d.ts +7 -2
  397. package/dist/store/memory/disk.d.ts.map +1 -1
  398. package/dist/store/memory/disk.js +58 -5
  399. package/dist/store/memory/disk.js.map +1 -1
  400. package/dist/store/memory/index.d.ts +9 -0
  401. package/dist/store/memory/index.d.ts.map +1 -1
  402. package/dist/store/memory/index.js +43 -5
  403. package/dist/store/memory/index.js.map +1 -1
  404. package/dist/store/memory/markdown.d.ts +7 -2
  405. package/dist/store/memory/markdown.d.ts.map +1 -1
  406. package/dist/store/memory/markdown.js +33 -0
  407. package/dist/store/memory/markdown.js.map +1 -1
  408. package/dist/store/memory/memory.d.ts +7 -2
  409. package/dist/store/memory/memory.d.ts.map +1 -1
  410. package/dist/store/memory/memory.js +34 -0
  411. package/dist/store/memory/memory.js.map +1 -1
  412. package/dist/store/memory/revision.d.ts +16 -0
  413. package/dist/store/memory/revision.d.ts.map +1 -0
  414. package/dist/store/memory/revision.js +144 -0
  415. package/dist/store/memory/revision.js.map +1 -0
  416. package/dist/store/session/disk.d.ts +9 -4
  417. package/dist/store/session/disk.d.ts.map +1 -1
  418. package/dist/store/session/disk.js +57 -11
  419. package/dist/store/session/disk.js.map +1 -1
  420. package/dist/store/session/memory.d.ts +5 -3
  421. package/dist/store/session/memory.d.ts.map +1 -1
  422. package/dist/store/session/memory.js +24 -7
  423. package/dist/store/session/memory.js.map +1 -1
  424. package/dist/store/session-log/core.d.ts +26 -6
  425. package/dist/store/session-log/core.d.ts.map +1 -1
  426. package/dist/store/session-log/core.js +61 -8
  427. package/dist/store/session-log/core.js.map +1 -1
  428. package/dist/store/session-log/disk.d.ts +2 -2
  429. package/dist/store/session-log/disk.d.ts.map +1 -1
  430. package/dist/store/session-log/disk.js +1 -0
  431. package/dist/store/session-log/disk.js.map +1 -1
  432. package/dist/store/session-log/fold.d.ts +7 -0
  433. package/dist/store/session-log/fold.d.ts.map +1 -1
  434. package/dist/store/session-log/fold.js +21 -0
  435. package/dist/store/session-log/fold.js.map +1 -1
  436. package/dist/store/session-log/index.d.ts +5 -3
  437. package/dist/store/session-log/index.d.ts.map +1 -1
  438. package/dist/store/session-log/index.js +3 -1
  439. package/dist/store/session-log/index.js.map +1 -1
  440. package/dist/store/session-log/memory.d.ts +1 -1
  441. package/dist/store/session-log/memory.d.ts.map +1 -1
  442. package/dist/store/session-log/memory.js +1 -0
  443. package/dist/store/session-log/memory.js.map +1 -1
  444. package/dist/store/session-log/spill.d.ts +10 -3
  445. package/dist/store/session-log/spill.d.ts.map +1 -1
  446. package/dist/store/session-log/spill.js +70 -5
  447. package/dist/store/session-log/spill.js.map +1 -1
  448. package/dist/store/session-log/structured-result.d.ts +21 -0
  449. package/dist/store/session-log/structured-result.d.ts.map +1 -0
  450. package/dist/store/session-log/structured-result.js +67 -0
  451. package/dist/store/session-log/structured-result.js.map +1 -0
  452. package/dist/store/task/disk.d.ts +11 -0
  453. package/dist/store/task/disk.d.ts.map +1 -1
  454. package/dist/store/task/disk.js +41 -2
  455. package/dist/store/task/disk.js.map +1 -1
  456. package/dist/store/task/memory.d.ts.map +1 -1
  457. package/dist/store/task/memory.js +15 -3
  458. package/dist/store/task/memory.js.map +1 -1
  459. package/dist/tools/admit-facts.d.ts +13 -0
  460. package/dist/tools/admit-facts.d.ts.map +1 -0
  461. package/dist/tools/admit-facts.js +142 -0
  462. package/dist/tools/admit-facts.js.map +1 -0
  463. package/dist/tools/builtins/bash.d.ts +4 -1
  464. package/dist/tools/builtins/bash.d.ts.map +1 -1
  465. package/dist/tools/builtins/bash.js +108 -22
  466. package/dist/tools/builtins/bash.js.map +1 -1
  467. package/dist/tools/builtins/browser.d.ts +10 -10
  468. package/dist/tools/builtins/computer-use.d.ts +90 -90
  469. package/dist/tools/builtins/edit.d.ts +17 -0
  470. package/dist/tools/builtins/edit.d.ts.map +1 -1
  471. package/dist/tools/builtins/edit.js +34 -0
  472. package/dist/tools/builtins/edit.js.map +1 -1
  473. package/dist/tools/builtins/file-write-result.d.ts.map +1 -1
  474. package/dist/tools/builtins/file-write-result.js +13 -0
  475. package/dist/tools/builtins/file-write-result.js.map +1 -1
  476. package/dist/tools/builtins/glob.d.ts.map +1 -1
  477. package/dist/tools/builtins/glob.js +12 -0
  478. package/dist/tools/builtins/glob.js.map +1 -1
  479. package/dist/tools/builtins/grep.d.ts.map +1 -1
  480. package/dist/tools/builtins/grep.js +14 -0
  481. package/dist/tools/builtins/grep.js.map +1 -1
  482. package/dist/tools/builtins/index.d.ts +2 -0
  483. package/dist/tools/builtins/index.d.ts.map +1 -1
  484. package/dist/tools/builtins/index.js +1 -0
  485. package/dist/tools/builtins/index.js.map +1 -1
  486. package/dist/tools/builtins/job.d.ts.map +1 -1
  487. package/dist/tools/builtins/job.js +4 -1
  488. package/dist/tools/builtins/job.js.map +1 -1
  489. package/dist/tools/builtins/lsp.d.ts +2 -2
  490. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  491. package/dist/tools/builtins/read-file.js +49 -0
  492. package/dist/tools/builtins/read-file.js.map +1 -1
  493. package/dist/tools/builtins/view-image.d.ts +24 -0
  494. package/dist/tools/builtins/view-image.d.ts.map +1 -0
  495. package/dist/tools/builtins/view-image.js +385 -0
  496. package/dist/tools/builtins/view-image.js.map +1 -0
  497. package/dist/tools/builtins/wait-for-job-bounds.d.ts +8 -4
  498. package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
  499. package/dist/tools/builtins/wait-for-job-bounds.js +43 -8
  500. package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
  501. package/dist/tools/builtins/wait-for-job.d.ts +3 -0
  502. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  503. package/dist/tools/builtins/wait-for-job.js +127 -15
  504. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  505. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  506. package/dist/tools/builtins/write-file.js +1 -0
  507. package/dist/tools/builtins/write-file.js.map +1 -1
  508. package/dist/tools/command-shell.d.ts +37 -2
  509. package/dist/tools/command-shell.d.ts.map +1 -1
  510. package/dist/tools/command-shell.js +100 -3
  511. package/dist/tools/command-shell.js.map +1 -1
  512. package/dist/tools/coordinator/agent.d.ts +9 -19
  513. package/dist/tools/coordinator/agent.d.ts.map +1 -1
  514. package/dist/tools/coordinator/agent.js.map +1 -1
  515. package/dist/tools/coordinator/index.d.ts.map +1 -1
  516. package/dist/tools/coordinator/index.js +127 -67
  517. package/dist/tools/coordinator/index.js.map +1 -1
  518. package/dist/tools/coordinator/wait-with-idle-bound.d.ts +2 -0
  519. package/dist/tools/coordinator/wait-with-idle-bound.d.ts.map +1 -1
  520. package/dist/tools/coordinator/wait-with-idle-bound.js +1 -1
  521. package/dist/tools/coordinator/wait-with-idle-bound.js.map +1 -1
  522. package/dist/tools/defineTool.d.ts.map +1 -1
  523. package/dist/tools/defineTool.js +4 -0
  524. package/dist/tools/defineTool.js.map +1 -1
  525. package/dist/tools/failure-facts.d.ts +8 -0
  526. package/dist/tools/failure-facts.d.ts.map +1 -0
  527. package/dist/tools/failure-facts.js +24 -0
  528. package/dist/tools/failure-facts.js.map +1 -0
  529. package/dist/tools/host-output.d.ts +24 -0
  530. package/dist/tools/host-output.d.ts.map +1 -0
  531. package/dist/tools/host-output.js +117 -0
  532. package/dist/tools/host-output.js.map +1 -0
  533. package/dist/tools/memory/delete.d.ts.map +1 -1
  534. package/dist/tools/memory/delete.js +38 -3
  535. package/dist/tools/memory/delete.js.map +1 -1
  536. package/dist/tools/memory/read.d.ts.map +1 -1
  537. package/dist/tools/memory/read.js +38 -2
  538. package/dist/tools/memory/read.js.map +1 -1
  539. package/dist/tools/memory/search.d.ts.map +1 -1
  540. package/dist/tools/memory/search.js +38 -7
  541. package/dist/tools/memory/search.js.map +1 -1
  542. package/dist/tools/memory/update.d.ts.map +1 -1
  543. package/dist/tools/memory/update.js +30 -3
  544. package/dist/tools/memory/update.js.map +1 -1
  545. package/dist/tools/oem-code-pages.d.ts +8 -0
  546. package/dist/tools/oem-code-pages.d.ts.map +1 -0
  547. package/dist/tools/oem-code-pages.js +23 -0
  548. package/dist/tools/oem-code-pages.js.map +1 -0
  549. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  550. package/dist/tools/schedules/schedule-tool.js +35 -6
  551. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  552. package/dist/tools/schedules/types.d.ts +23 -3
  553. package/dist/tools/schedules/types.d.ts.map +1 -1
  554. package/dist/tools/task/list.d.ts.map +1 -1
  555. package/dist/tools/task/list.js +14 -6
  556. package/dist/tools/task/list.js.map +1 -1
  557. package/dist/tools/task/present.d.ts.map +1 -1
  558. package/dist/tools/task/present.js +26 -6
  559. package/dist/tools/task/present.js.map +1 -1
  560. package/dist/tools/task/update.d.ts.map +1 -1
  561. package/dist/tools/task/update.js +12 -5
  562. package/dist/tools/task/update.js.map +1 -1
  563. package/dist/tools/text-window.d.ts +19 -0
  564. package/dist/tools/text-window.d.ts.map +1 -0
  565. package/dist/tools/text-window.js +83 -0
  566. package/dist/tools/text-window.js.map +1 -0
  567. package/dist/toolsets/manager.d.ts +24 -0
  568. package/dist/toolsets/manager.d.ts.map +1 -1
  569. package/dist/toolsets/manager.js +105 -2
  570. package/dist/toolsets/manager.js.map +1 -1
  571. package/dist/turn/memory-recall.d.ts +2 -0
  572. package/dist/turn/memory-recall.d.ts.map +1 -1
  573. package/dist/turn/memory-recall.js +3 -1
  574. package/dist/turn/memory-recall.js.map +1 -1
  575. package/dist/types/acp/index.d.ts +137 -1
  576. package/dist/types/acp/index.d.ts.map +1 -1
  577. package/dist/types/agent/base.d.ts +3 -0
  578. package/dist/types/agent/base.d.ts.map +1 -1
  579. package/dist/types/agent/manager.d.ts +8 -23
  580. package/dist/types/agent/manager.d.ts.map +1 -1
  581. package/dist/types/agent/scheduler.d.ts +10 -1
  582. package/dist/types/agent/scheduler.d.ts.map +1 -1
  583. package/dist/types/agent/task.d.ts +4 -0
  584. package/dist/types/agent/task.d.ts.map +1 -1
  585. package/dist/types/authorization/index.d.ts +30 -30
  586. package/dist/types/connector/mcp.d.ts +7 -0
  587. package/dist/types/connector/mcp.d.ts.map +1 -1
  588. package/dist/types/errors/catalog.d.ts.map +1 -1
  589. package/dist/types/errors/catalog.js +4 -2
  590. package/dist/types/errors/catalog.js.map +1 -1
  591. package/dist/types/harness/schema.d.ts +354 -0
  592. package/dist/types/harness/schema.d.ts.map +1 -0
  593. package/dist/types/harness/schema.js +203 -0
  594. package/dist/types/harness/schema.js.map +1 -0
  595. package/dist/types/harness/session.d.ts +278 -0
  596. package/dist/types/harness/session.d.ts.map +1 -0
  597. package/dist/types/harness/session.js +2 -0
  598. package/dist/types/harness/session.js.map +1 -0
  599. package/dist/types/hitl/index.d.ts +12 -0
  600. package/dist/types/hitl/index.d.ts.map +1 -1
  601. package/dist/types/hitl/index.js.map +1 -1
  602. package/dist/types/job/index.d.ts +47 -0
  603. package/dist/types/job/index.d.ts.map +1 -0
  604. package/dist/types/job/index.js +2 -0
  605. package/dist/types/job/index.js.map +1 -0
  606. package/dist/types/memory/index.d.ts +29 -0
  607. package/dist/types/memory/index.d.ts.map +1 -1
  608. package/dist/types/memory/index.js +6 -0
  609. package/dist/types/memory/index.js.map +1 -1
  610. package/dist/types/message/inbound-delivery.d.ts +44 -0
  611. package/dist/types/message/inbound-delivery.d.ts.map +1 -0
  612. package/dist/types/message/inbound-delivery.js +14 -0
  613. package/dist/types/message/inbound-delivery.js.map +1 -0
  614. package/dist/types/message/index.d.ts +4 -1
  615. package/dist/types/message/index.d.ts.map +1 -1
  616. package/dist/types/message/index.js +5 -1
  617. package/dist/types/message/index.js.map +1 -1
  618. package/dist/types/plugin/index.d.ts +18 -8
  619. package/dist/types/plugin/index.d.ts.map +1 -1
  620. package/dist/types/plugin/index.js +5 -2
  621. package/dist/types/plugin/index.js.map +1 -1
  622. package/dist/types/sandbox/index.d.ts +39 -2
  623. package/dist/types/sandbox/index.d.ts.map +1 -1
  624. package/dist/types/sandbox/index.js.map +1 -1
  625. package/dist/types/session/checkpoint.d.ts +24 -17
  626. package/dist/types/session/checkpoint.d.ts.map +1 -1
  627. package/dist/types/session/checkpoint.js +1 -0
  628. package/dist/types/session/checkpoint.js.map +1 -1
  629. package/dist/types/session/events.d.ts +23 -1
  630. package/dist/types/session/events.d.ts.map +1 -1
  631. package/dist/types/session/events.js.map +1 -1
  632. package/dist/types/session/records.d.ts +1514 -565
  633. package/dist/types/session/records.d.ts.map +1 -1
  634. package/dist/types/session/records.js +89 -1
  635. package/dist/types/session/records.js.map +1 -1
  636. package/dist/types/session/step.d.ts +2 -0
  637. package/dist/types/session/step.d.ts.map +1 -1
  638. package/dist/types/session/step.js.map +1 -1
  639. package/dist/types/session/store.d.ts +19 -10
  640. package/dist/types/session/store.d.ts.map +1 -1
  641. package/dist/types/session/tool-execution.d.ts +6 -0
  642. package/dist/types/session/tool-execution.d.ts.map +1 -1
  643. package/dist/types/structured-output/index.d.ts +12 -2
  644. package/dist/types/structured-output/index.d.ts.map +1 -1
  645. package/dist/types/summary/ref.d.ts +3 -1
  646. package/dist/types/summary/ref.d.ts.map +1 -1
  647. package/dist/types/tool/index.d.ts +32 -4
  648. package/dist/types/tool/index.d.ts.map +1 -1
  649. package/dist/types/tool/index.js.map +1 -1
  650. package/dist/types/tool/presentation.d.ts +106 -0
  651. package/dist/types/tool/presentation.d.ts.map +1 -1
  652. package/dist/utils/json-snapshot.d.ts +6 -2
  653. package/dist/utils/json-snapshot.d.ts.map +1 -1
  654. package/dist/utils/json-snapshot.js +19 -9
  655. package/dist/utils/json-snapshot.js.map +1 -1
  656. package/dist/utils/structured-result-json.d.ts +5 -0
  657. package/dist/utils/structured-result-json.d.ts.map +1 -0
  658. package/dist/utils/structured-result-json.js +10 -0
  659. package/dist/utils/structured-result-json.js.map +1 -0
  660. package/package.json +1 -1
  661. package/src/agents/QueryAgent.ts +1 -0
  662. package/src/agents/examples/SupervisorAgent.ts +1 -0
  663. package/src/agents/runAgent.ts +3 -0
  664. package/src/authorization/shell-lexer.ts +16 -1
  665. package/src/bridge/acp/permission.ts +17 -3
  666. package/src/bridge/acp/server.ts +271 -25
  667. package/src/bridge/acp/tasks.ts +23 -0
  668. package/src/bridge/acp/update.ts +167 -13
  669. package/src/config/registry.ts +24 -3
  670. package/src/connector/mcp/adapter.ts +16 -4
  671. package/src/connector/mcp/client.ts +6 -2
  672. package/src/connector/mcp/discovery.ts +29 -8
  673. package/src/connector/mcp/mcp-toolset.ts +25 -4
  674. package/src/connector/mcp/reconnect.ts +34 -4
  675. package/src/constants/acp/index.ts +4 -0
  676. package/src/manager/agent/lifecycle.ts +230 -3
  677. package/src/manager/plan/lifecycle.ts +11 -9
  678. package/src/manager/session/attribution.ts +12 -2
  679. package/src/manager/session/streamed-message-identity.ts +21 -0
  680. package/src/manager/session/turn-recorder.ts +4 -3
  681. package/src/pals/activity/causality.ts +261 -0
  682. package/src/pals/activity/projection.ts +89 -0
  683. package/src/pals/activity/source.ts +240 -0
  684. package/src/pals/activity/subscription-policy.ts +230 -0
  685. package/src/pals/activity/subscription-schema.ts +27 -0
  686. package/src/pals/activity/subscription-store.ts +172 -0
  687. package/src/pals/activity/subscription-types.ts +48 -0
  688. package/src/pals/activity/subscriptions.ts +209 -0
  689. package/src/pals/activity/types.ts +108 -0
  690. package/src/pals/channels/ingress.ts +153 -0
  691. package/src/pals/channels/routes.ts +118 -0
  692. package/src/pals/channels/routing.ts +197 -0
  693. package/src/pals/channels/schema.ts +108 -0
  694. package/src/pals/channels/types.ts +156 -0
  695. package/src/pals/communication/broker.ts +131 -0
  696. package/src/pals/communication/dispatch.ts +66 -0
  697. package/src/pals/communication/inbound.ts +193 -0
  698. package/src/pals/communication/ingress-dispatch.ts +63 -0
  699. package/src/pals/communication/ingress-inbound.ts +269 -0
  700. package/src/pals/communication/ingress-schema.ts +526 -0
  701. package/src/pals/communication/ingress-types.ts +336 -0
  702. package/src/pals/communication/operator.ts +315 -0
  703. package/src/pals/communication/policy.ts +174 -0
  704. package/src/pals/communication/schema.ts +173 -0
  705. package/src/pals/communication/store.ts +577 -0
  706. package/src/pals/communication/tools.ts +139 -0
  707. package/src/pals/communication/types.ts +227 -0
  708. package/src/pals/communication/verify.ts +220 -0
  709. package/src/pals/lifecycle.ts +54 -0
  710. package/src/pals/prompt.ts +101 -0
  711. package/src/pals/reference-images.ts +322 -0
  712. package/src/pals/runtime.ts +670 -0
  713. package/src/pals/store.ts +369 -0
  714. package/src/pals/types.ts +157 -0
  715. package/src/peers/envelope.ts +1 -1
  716. package/src/plugin/lifecycle.ts +217 -46
  717. package/src/plugin/shell-hook.ts +8 -2
  718. package/src/process/kill-tree.ts +10 -1
  719. package/src/prompt/resident-learning.ts +2 -2
  720. package/src/prompt/resident-step.ts +4 -4
  721. package/src/provider/errors.ts +135 -2
  722. package/src/public-runtime.ts +119 -12
  723. package/src/public-tools.ts +13 -1
  724. package/src/public-types.ts +69 -7
  725. package/src/registry/tool/presentation.ts +9 -4
  726. package/src/registry/tool/screen.ts +34 -2
  727. package/src/runtime/harness-session/index.ts +1125 -0
  728. package/src/runtime/harness-session/journal.ts +209 -0
  729. package/src/runtime/harness-session/saved-view.ts +122 -0
  730. package/src/runtime/jobs/awaited-jobs.ts +2 -1
  731. package/src/runtime/jobs/registry.ts +423 -50
  732. package/src/runtime/query/abandon-turn.ts +18 -2
  733. package/src/runtime/query/checkpoint.ts +11 -0
  734. package/src/runtime/query/durable-inbound.ts +101 -0
  735. package/src/runtime/query/events.ts +22 -5
  736. package/src/runtime/query/executor/tool-call-admission.ts +125 -32
  737. package/src/runtime/query/executor.ts +316 -130
  738. package/src/runtime/query/index.ts +48 -5
  739. package/src/runtime/query/iteration/index.ts +253 -114
  740. package/src/runtime/query/iteration/outstanding-work.ts +57 -7
  741. package/src/runtime/query/iteration/phases/context.ts +8 -0
  742. package/src/runtime/query/iteration/phases/tool-review.ts +124 -22
  743. package/src/runtime/query/iteration/step-shaping.ts +9 -1
  744. package/src/runtime/query/observation-context.ts +22 -16
  745. package/src/runtime/query/prepare-turn.ts +2 -2
  746. package/src/runtime/query/prompt-cache.ts +3 -0
  747. package/src/runtime/query/prompt.ts +32 -1
  748. package/src/runtime/query/repeat-call.ts +40 -10
  749. package/src/runtime/query/resume-pending.ts +60 -7
  750. package/src/runtime/query/resume-session.ts +1 -1
  751. package/src/runtime/query/review-policy.ts +23 -2
  752. package/src/runtime/query/saved-presentation.ts +70 -0
  753. package/src/runtime/query/steering.ts +6 -9
  754. package/src/runtime/query/tool-executions.ts +108 -9
  755. package/src/runtime/query/tooling.ts +6 -1
  756. package/src/scheduler/completion-inbox.ts +108 -7
  757. package/src/scheduler/delegating.ts +5 -0
  758. package/src/scheduler/local.ts +2 -0
  759. package/src/session/summary/materialize.ts +51 -9
  760. package/src/store/budget/ledger.ts +60 -5
  761. package/src/store/index.ts +1 -0
  762. package/src/store/memory/disk.ts +82 -7
  763. package/src/store/memory/index.ts +66 -7
  764. package/src/store/memory/markdown.ts +54 -2
  765. package/src/store/memory/memory.ts +52 -2
  766. package/src/store/memory/revision.ts +158 -0
  767. package/src/store/session/disk.ts +77 -10
  768. package/src/store/session/memory.ts +32 -7
  769. package/src/store/session-log/core.ts +118 -11
  770. package/src/store/session-log/disk.ts +9 -2
  771. package/src/store/session-log/fold.ts +22 -0
  772. package/src/store/session-log/index.ts +5 -0
  773. package/src/store/session-log/memory.ts +2 -1
  774. package/src/store/session-log/spill.ts +89 -6
  775. package/src/store/session-log/structured-result.ts +96 -0
  776. package/src/store/task/disk.ts +46 -2
  777. package/src/store/task/memory.ts +13 -3
  778. package/src/tools/admit-facts.ts +145 -0
  779. package/src/tools/builtins/bash.ts +132 -24
  780. package/src/tools/builtins/edit.ts +42 -0
  781. package/src/tools/builtins/file-write-result.ts +14 -0
  782. package/src/tools/builtins/glob.ts +12 -0
  783. package/src/tools/builtins/grep.ts +14 -0
  784. package/src/tools/builtins/index.ts +2 -0
  785. package/src/tools/builtins/job.ts +4 -1
  786. package/src/tools/builtins/read-file.ts +57 -0
  787. package/src/tools/builtins/view-image.ts +409 -0
  788. package/src/tools/builtins/wait-for-job-bounds.ts +45 -7
  789. package/src/tools/builtins/wait-for-job.ts +159 -36
  790. package/src/tools/builtins/write-file.ts +4 -2
  791. package/src/tools/command-shell.ts +132 -5
  792. package/src/tools/coordinator/agent.ts +9 -19
  793. package/src/tools/coordinator/index.ts +150 -75
  794. package/src/tools/coordinator/wait-with-idle-bound.ts +3 -1
  795. package/src/tools/defineTool.ts +4 -0
  796. package/src/tools/failure-facts.ts +24 -0
  797. package/src/tools/host-output.ts +136 -0
  798. package/src/tools/memory/delete.ts +33 -3
  799. package/src/tools/memory/read.ts +35 -2
  800. package/src/tools/memory/search.ts +38 -7
  801. package/src/tools/memory/update.ts +28 -3
  802. package/src/tools/oem-code-pages.ts +22 -0
  803. package/src/tools/schedules/schedule-tool.ts +38 -5
  804. package/src/tools/schedules/types.ts +23 -3
  805. package/src/tools/task/list.ts +15 -7
  806. package/src/tools/task/present.ts +37 -7
  807. package/src/tools/task/update.ts +12 -5
  808. package/src/tools/text-window.ts +87 -0
  809. package/src/toolsets/manager.ts +132 -2
  810. package/src/turn/memory-recall.ts +5 -1
  811. package/src/types/acp/index.ts +150 -4
  812. package/src/types/agent/base.ts +3 -0
  813. package/src/types/agent/manager.ts +8 -23
  814. package/src/types/agent/scheduler.ts +10 -1
  815. package/src/types/agent/task.ts +4 -0
  816. package/src/types/connector/mcp.ts +7 -0
  817. package/src/types/errors/catalog.ts +4 -2
  818. package/src/types/harness/schema.ts +203 -0
  819. package/src/types/harness/session.ts +306 -0
  820. package/src/types/hitl/index.ts +17 -1
  821. package/src/types/job/index.ts +42 -0
  822. package/src/types/memory/index.ts +43 -0
  823. package/src/types/message/inbound-delivery.ts +63 -0
  824. package/src/types/message/index.ts +8 -1
  825. package/src/types/plugin/index.ts +11 -6
  826. package/src/types/sandbox/index.ts +46 -0
  827. package/src/types/session/checkpoint.ts +4 -1
  828. package/src/types/session/events.ts +23 -1
  829. package/src/types/session/records.ts +114 -2
  830. package/src/types/session/step.ts +2 -0
  831. package/src/types/session/store.ts +23 -9
  832. package/src/types/session/tool-execution.ts +6 -0
  833. package/src/types/structured-output/index.ts +13 -2
  834. package/src/types/summary/ref.ts +3 -1
  835. package/src/types/tool/index.ts +39 -5
  836. package/src/types/tool/presentation.ts +121 -0
  837. package/src/utils/json-snapshot.ts +26 -9
  838. package/src/utils/structured-result-json.ts +10 -0
@@ -49,6 +49,7 @@ interface PluginContributionRecord {
49
49
  mcpToolsets: Toolset[]
50
50
  mcpUnsubscribers: Array<() => void>
51
51
  mcpNamesBySource: Map<string, Set<string>>
52
+ configReleases: Array<() => void>
52
53
  /** Namespaced skill names, so rollback and disable can take them back. */
53
54
  skillNames: string[]
54
55
  }
@@ -62,6 +63,68 @@ interface PluginAdmission {
62
63
  readonly inCode?: DefinedPlugin
63
64
  }
64
65
 
66
+ const DEFAULT_PLUGIN_MCP_CONNECT_TIMEOUT_MS = 10_000
67
+ const PLUGIN_MCP_CLOSE_TIMEOUT_MS = 5_000
68
+
69
+ /** One deadline across handshake and all initial discovery requests. */
70
+ async function beforePluginMcpDeadline<T>(
71
+ work: () => Promise<T>,
72
+ deadlineAt: number,
73
+ timeoutMs: number,
74
+ serverName: string,
75
+ onLate?: (value: T) => void,
76
+ onTimeout?: () => void,
77
+ ): Promise<T> {
78
+ const expired = (): Error =>
79
+ new Error(`Plugin MCP server "${serverName}" did not answer within ${timeoutMs}ms`)
80
+ const remaining = deadlineAt - Date.now()
81
+ if (remaining <= 0) throw expired()
82
+ let timer: ReturnType<typeof setTimeout> | undefined
83
+ let timedOut = false
84
+ try {
85
+ const pending = work()
86
+ // A timed-out discovery can still finish after rollback. In particular,
87
+ // mcpToolset() starts a reconnect supervisor just before it returns.
88
+ // Close that late result without publishing any of its tools.
89
+ void pending.then(
90
+ (value) => {
91
+ if (timedOut) onLate?.(value)
92
+ },
93
+ () => {},
94
+ )
95
+ return await Promise.race([
96
+ pending,
97
+ new Promise<never>((_, reject) => {
98
+ timer = setTimeout(() => {
99
+ timedOut = true
100
+ onTimeout?.()
101
+ reject(expired())
102
+ }, remaining)
103
+ }),
104
+ ])
105
+ } finally {
106
+ if (timer) clearTimeout(timer)
107
+ }
108
+ }
109
+
110
+ /** Teardown is best-effort, but one stalled close must not block rollback or disable. */
111
+ async function closePluginMcpWithin(work: () => Promise<void>, label: string): Promise<void> {
112
+ let timer: ReturnType<typeof setTimeout> | undefined
113
+ try {
114
+ await Promise.race([
115
+ work(),
116
+ new Promise<never>((_, reject) => {
117
+ timer = setTimeout(
118
+ () => reject(new Error(`${label} did not close within ${PLUGIN_MCP_CLOSE_TIMEOUT_MS}ms`)),
119
+ PLUGIN_MCP_CLOSE_TIMEOUT_MS,
120
+ )
121
+ }),
122
+ ])
123
+ } finally {
124
+ if (timer) clearTimeout(timer)
125
+ }
126
+ }
127
+
65
128
  /** Dynamic imports bypass ToolDefinition's TypeScript contract. */
66
129
  function assertPluginTool(
67
130
  value: unknown,
@@ -100,6 +163,9 @@ function immutableManifest(manifest: PluginDefinition['manifest']): PluginDefini
100
163
  command: server.command,
101
164
  ...(server.args ? { args: Object.freeze([...server.args]) } : {}),
102
165
  ...(server.env ? { env: Object.freeze({ ...server.env }) } : {}),
166
+ ...(server.connectTimeoutMs !== undefined
167
+ ? { connectTimeoutMs: server.connectTimeoutMs }
168
+ : {}),
103
169
  }),
104
170
  )
105
171
  return Object.freeze({
@@ -199,6 +265,8 @@ export class PluginLifecycleManager {
199
265
  }>
200
266
  > = new Map()
201
267
  private pluginContributions: Map<PluginId, PluginContributionRecord> = new Map()
268
+ /** Reserve each id before async admission so lifecycle calls cannot overlap. */
269
+ private readonly lifecycleTails = new Map<PluginId, Promise<void>>()
202
270
  /** Immutable executable admissions owned by this manager, never by the mutable registry. */
203
271
  private pluginAdmissions: Map<PluginId, PluginAdmission> = new Map()
204
272
  private hookTimeoutMs: number
@@ -206,18 +274,16 @@ export class PluginLifecycleManager {
206
274
  private readonly scopeRoots: Readonly<Record<PluginScope, string>>
207
275
  private log: Logger
208
276
  /**
209
- * The admission boundary for everything a plugin's MCP servers advertise.
277
+ * The cross-enable drift history for each plugin-owned MCP source.
210
278
  *
211
- * One instance for the whole manager rather than one per plugin, and that
212
- * is the part that matters: the instance is what remembers each server's
213
- * previously admitted tool set, so a server that changes between one
214
- * plugin being disabled and the next being enabled is still noticed. A
215
- * per-plugin instance would forget on every teardown, which is precisely
216
- * the window a rug pull uses.
279
+ * The toolset applies policy and performs the only listing. It passes the
280
+ * admitted snapshot here after it commits, keyed by its full plugin source.
281
+ * Keeping this recorder for the manager lifetime detects a server that
282
+ * changes between disable and the next enable without conflating unrelated
283
+ * plugins that use the same local server label.
217
284
  *
218
- * Its client list is deliberately left empty — `discoverFrom` takes the
219
- * client directly, so registering it here would be bookkeeping nothing
220
- * reads.
285
+ * Its client list stays empty because this instance records snapshots;
286
+ * it never makes a second request to the server.
221
287
  */
222
288
  private mcpDiscovery: MCPToolDiscovery
223
289
  private readonly mcpToolPolicies?: Readonly<Record<string, MCPToolPolicy>>
@@ -235,8 +301,20 @@ export class PluginLifecycleManager {
235
301
  this.onMCPToolDrift = config.onMCPToolDrift
236
302
  this.log = config.log.child({ [SCOPE_ATTRIBUTE]: 'plugin/lifecycle' })
237
303
  this.mcpDiscovery = new MCPToolDiscovery([], {
238
- ...(config.mcpToolPolicies ? { policies: config.mcpToolPolicies } : {}),
239
- ...(config.onMCPToolDrift ? { onDrift: config.onMCPToolDrift } : {}),
304
+ ...(config.onMCPToolDrift
305
+ ? {
306
+ onDrift: (event) => {
307
+ try {
308
+ this.onMCPToolDrift?.(event)
309
+ } catch (error) {
310
+ this.log.warn('Plugin MCP drift listener failed', {
311
+ 'namzu.plugin.mcp_server': event.serverName,
312
+ 'exception.message': toErrorMessage(error),
313
+ })
314
+ }
315
+ },
316
+ }
317
+ : {}),
240
318
  logger: this.log,
241
319
  })
242
320
  }
@@ -453,6 +531,21 @@ export class PluginLifecycleManager {
453
531
  })
454
532
  }
455
533
 
534
+ private serializeLifecycle<T>(pluginId: PluginId, work: () => Promise<T>): Promise<T> {
535
+ const previous = this.lifecycleTails.get(pluginId) ?? Promise.resolve()
536
+ const running = previous.then(work)
537
+ // A failed enable must not poison later disable, retry or uninstall.
538
+ const tail = running.then(
539
+ () => undefined,
540
+ () => undefined,
541
+ )
542
+ this.lifecycleTails.set(pluginId, tail)
543
+ void tail.then(() => {
544
+ if (this.lifecycleTails.get(pluginId) === tail) this.lifecycleTails.delete(pluginId)
545
+ })
546
+ return running
547
+ }
548
+
456
549
  private async readLegacyAdmission(plugin: PluginDefinition): Promise<PluginAdmission> {
457
550
  const rootDir = await resolveWithinReal(this.scopeRoots[plugin.scope], plugin.rootDir)
458
551
  const manifest = immutableManifest(
@@ -482,7 +575,11 @@ export class PluginLifecycleManager {
482
575
  })
483
576
  }
484
577
 
485
- async enable(pluginId: PluginId): Promise<void> {
578
+ enable(pluginId: PluginId): Promise<void> {
579
+ return this.serializeLifecycle(pluginId, () => this.enableOwned(pluginId))
580
+ }
581
+
582
+ private async enableOwned(pluginId: PluginId): Promise<void> {
486
583
  const plugin = this.pluginRegistry.getOrThrow(pluginId)
487
584
  let admission = this.pluginAdmissions.get(pluginId)
488
585
 
@@ -543,6 +640,7 @@ export class PluginLifecycleManager {
543
640
  mcpToolsets: [],
544
641
  mcpUnsubscribers: [],
545
642
  mcpNamesBySource: new Map(),
643
+ configReleases: [],
546
644
  skillNames: [],
547
645
  }
548
646
 
@@ -703,30 +801,75 @@ export class PluginLifecycleManager {
703
801
  },
704
802
  logger: this.log,
705
803
  })
706
-
707
- await client.connect()
804
+ // A failed handshake still owns a transport (and possibly a child
805
+ // process). Put it under rollback ownership before the first await.
708
806
  contributions.mcpClients.push(client)
807
+ const timeoutMs = config.connectTimeoutMs ?? DEFAULT_PLUGIN_MCP_CONNECT_TIMEOUT_MS
808
+ const deadlineAt = Date.now() + timeoutMs
809
+ const closeLateClient = () => {
810
+ void closePluginMcpWithin(
811
+ () => client.disconnect(),
812
+ `Plugin MCP server "${config.name}" after late connection`,
813
+ ).catch((error) => {
814
+ this.log.warn('Late MCP disconnect failed', {
815
+ 'namzu.mcp.client_id': client.id,
816
+ 'exception.message': toErrorMessage(error),
817
+ })
818
+ })
819
+ }
820
+ await beforePluginMcpDeadline(
821
+ () => client.connect(),
822
+ deadlineAt,
823
+ timeoutMs,
824
+ config.name,
825
+ closeLateClient,
826
+ )
709
827
 
710
828
  // The toolset owns reconnection and reads this policy on each attempt.
711
829
  const policyScope = this.configRegistry?.register(
712
- `mcp.${config.name}`,
830
+ `mcp.plugin.${pluginName}.${config.name}`,
713
831
  MCPReconnectOptionsSchema,
714
832
  )
715
- // Preserve cross-disable drift detection. The live toolset below owns
716
- // changes during this enablement; this manager-owned discovery remembers
717
- // the server's earlier admission across clients and plugin lifetimes.
718
- await this.mcpDiscovery.discoverFrom(client)
833
+ if (policyScope) contributions.configReleases.push(() => policyScope.dispose())
834
+ // The toolset performs the only listing. Record precisely the admitted
835
+ // snapshot it mounts, including later refreshes, under the plugin source.
719
836
  const sourceId = `plugin:${pluginName}/mcp:${config.name}`
720
837
  const policy = this.mcpToolPolicies?.[config.name] ?? this.mcpToolPolicies?.['*']
721
- const entries = await mcpToolset(client, {
722
- id: sourceId,
723
- availability: 'deferred',
724
- allow: policy?.allow,
725
- deny: policy?.deny,
726
- reconnect: policyScope ? () => policyScope.get() : {},
727
- onDrift: this.onMCPToolDrift,
728
- logger: this.log,
729
- })
838
+ let acceptingSnapshot = true
839
+ const entries = await beforePluginMcpDeadline(
840
+ () =>
841
+ mcpToolset(client, {
842
+ id: sourceId,
843
+ availability: 'deferred',
844
+ allow: policy?.allow,
845
+ deny: policy?.deny,
846
+ reconnect: policyScope ? () => policyScope.get() : {},
847
+ onToolsAdmitted: (tools) => {
848
+ if (acceptingSnapshot) {
849
+ this.mcpDiscovery.recordAdmittedTools(sourceId, client.id, config.name, tools)
850
+ }
851
+ },
852
+ logger: this.log,
853
+ }),
854
+ deadlineAt,
855
+ timeoutMs,
856
+ config.name,
857
+ (lateEntries) => {
858
+ for (const entry of lateEntries) {
859
+ void closePluginMcpWithin(async () => {
860
+ await entry.close?.()
861
+ }, `Late MCP toolset ${entry.source.id}`).catch((error) => {
862
+ this.log.warn('Late MCP toolset close failed', {
863
+ 'namzu.toolset.source_id': entry.source.id,
864
+ 'exception.message': toErrorMessage(error),
865
+ })
866
+ })
867
+ }
868
+ },
869
+ () => {
870
+ acceptingSnapshot = false
871
+ },
872
+ )
730
873
  contributions.mcpToolsets.push(...entries)
731
874
  const wrapped = entries.map((entry) =>
732
875
  prefixed(entry, `${pluginName}${PLUGIN_NAMESPACE_SEPARATOR}`),
@@ -779,25 +922,49 @@ export class PluginLifecycleManager {
779
922
  contributions: PluginContributionRecord,
780
923
  operation: 'rollback' | 'disable',
781
924
  ): Promise<void> {
782
- for (const unsubscribe of contributions.mcpUnsubscribers) unsubscribe()
783
- for (const entry of contributions.mcpToolsets) await entry.close?.()
784
- for (const client of contributions.mcpClients) {
785
- try {
786
- await client.disconnect()
787
- } catch (error) {
788
- this.log.warn('MCP disconnect failed', {
789
- 'namzu.plugin.operation': operation,
790
- 'namzu.mcp.client_id': client.id,
791
- 'exception.message': toErrorMessage(error),
792
- })
925
+ try {
926
+ for (const unsubscribe of contributions.mcpUnsubscribers) unsubscribe()
927
+ await Promise.all(
928
+ contributions.mcpToolsets.map(async (entry) => {
929
+ try {
930
+ await closePluginMcpWithin(async () => {
931
+ await entry.close?.()
932
+ }, `MCP toolset ${entry.source.id}`)
933
+ } catch (error) {
934
+ this.log.warn('MCP toolset close failed', {
935
+ 'namzu.plugin.operation': operation,
936
+ 'namzu.toolset.source_id': entry.source.id,
937
+ 'exception.message': toErrorMessage(error),
938
+ })
939
+ }
940
+ }),
941
+ )
942
+ await Promise.all(
943
+ contributions.mcpClients.map(async (client) => {
944
+ try {
945
+ await closePluginMcpWithin(() => client.disconnect(), `MCP client ${client.id}`)
946
+ } catch (error) {
947
+ this.log.warn('MCP disconnect failed', {
948
+ 'namzu.plugin.operation': operation,
949
+ 'namzu.mcp.client_id': client.id,
950
+ 'exception.message': toErrorMessage(error),
951
+ })
952
+ }
953
+ }),
954
+ )
955
+ for (const names of contributions.mcpNamesBySource.values()) {
956
+ for (const name of names) this.removeContributedTool(name)
793
957
  }
958
+ } finally {
959
+ for (const release of contributions.configReleases) release()
794
960
  }
795
- for (const names of contributions.mcpNamesBySource.values()) {
796
- for (const name of names) this.removeContributedTool(name)
797
- }
798
961
  }
799
962
 
800
- async disable(pluginId: PluginId): Promise<void> {
963
+ disable(pluginId: PluginId): Promise<void> {
964
+ return this.serializeLifecycle(pluginId, () => this.disableOwned(pluginId))
965
+ }
966
+
967
+ private async disableOwned(pluginId: PluginId): Promise<void> {
801
968
  const plugin = this.pluginRegistry.getOrThrow(pluginId)
802
969
  const admission = this.pluginAdmissions.get(pluginId)
803
970
  const contributions = this.pluginContributions.get(pluginId)
@@ -856,12 +1023,16 @@ export class PluginLifecycleManager {
856
1023
  })
857
1024
  }
858
1025
 
859
- async uninstall(pluginId: PluginId): Promise<void> {
1026
+ uninstall(pluginId: PluginId): Promise<void> {
1027
+ return this.serializeLifecycle(pluginId, () => this.uninstallOwned(pluginId))
1028
+ }
1029
+
1030
+ private async uninstallOwned(pluginId: PluginId): Promise<void> {
860
1031
  const plugin = this.pluginRegistry.getOrThrow(pluginId)
861
1032
  const admission = this.pluginAdmissions.get(pluginId)
862
1033
 
863
1034
  if (this.pluginContributions.has(pluginId)) {
864
- await this.disable(pluginId)
1035
+ await this.disableOwned(pluginId)
865
1036
  }
866
1037
 
867
1038
  this.pluginRegistry.unregister(pluginId)
@@ -58,8 +58,9 @@
58
58
  * and does not block: one that could not answer in time has not answered no.
59
59
  */
60
60
 
61
- import { spawn } from 'node:child_process'
61
+ import type { spawn } from 'node:child_process'
62
62
 
63
+ import { spawnHostShell } from '../tools/command-shell.js'
63
64
  import type { PluginId } from '../types/ids/index.js'
64
65
  import type {
65
66
  PluginCompactionInfo,
@@ -211,7 +212,7 @@ export function runShellHook(
211
212
  return new Promise((resolve) => {
212
213
  let child: ReturnType<typeof spawn>
213
214
  try {
214
- child = spawn('sh', ['-c', entry.command], {
215
+ child = spawnHostShell(entry.command, {
215
216
  cwd: input.cwd,
216
217
  env: {
217
218
  ...inherited,
@@ -229,6 +230,11 @@ export function runShellHook(
229
230
  // the stdout pipe, and the outcome cannot settle until it exits on
230
231
  // its own — the hook's deadline becomes the grandchild's.
231
232
  detached: process.platform !== 'win32',
233
+ // A hook has always run under `sh`, whatever shell the `bash` tool
234
+ // chose. Windows has no `sh`, so there the host's own shell runs it.
235
+ ...(process.platform === 'win32'
236
+ ? {}
237
+ : { shell: { path: 'sh', dialect: 'sh', source: 'sh' } as const }),
232
238
  })
233
239
  } catch (error) {
234
240
  resolve({
@@ -1,6 +1,12 @@
1
1
  import { execFileSync } from 'node:child_process'
2
2
  import type { spawn } from 'node:child_process'
3
3
 
4
+ /** The system's own taskkill, so a PATH entry cannot stand in for it. */
5
+ function taskkillPath(): string {
6
+ const root = process.env.SystemRoot ?? process.env.windir
7
+ return root ? `${root}\\System32\\taskkill.exe` : 'taskkill'
8
+ }
9
+
4
10
  /**
5
11
  * Signal a spawned child AND everything it forked.
6
12
  *
@@ -40,7 +46,10 @@ export function killTree(child: ReturnType<typeof spawn>, signal: NodeJS.Signals
40
46
  if (!child.pid) return
41
47
  try {
42
48
  if (process.platform === 'win32') {
43
- execFileSync('taskkill', ['/pid', String(child.pid), '/t', '/f'], { stdio: 'ignore' })
49
+ execFileSync(taskkillPath(), ['/pid', String(child.pid), '/t', '/f'], {
50
+ stdio: 'ignore',
51
+ windowsHide: true,
52
+ })
44
53
  } else {
45
54
  process.kill(-child.pid, signal)
46
55
  }
@@ -103,7 +103,7 @@ export function createResidentStepContext(
103
103
  ...contributions,
104
104
  Object.freeze({
105
105
  id: 'namzu.resident-step.learning-catalogue',
106
- placement: 'dynamic' as const,
106
+ placement: 'context' as const,
107
107
  render: () =>
108
108
  [
109
109
  '## Available evaluated resident skills',
@@ -113,7 +113,7 @@ export function createResidentStepContext(
113
113
  }),
114
114
  Object.freeze({
115
115
  id: 'namzu.resident-step.selected-learning',
116
- placement: 'turn' as const,
116
+ placement: 'context' as const,
117
117
  render: () => {
118
118
  if (!selected.size) return null
119
119
  try {
@@ -58,8 +58,8 @@ export interface ResidentStepPromptOptions {
58
58
  * contributions. Register them on the registry supplied to `query`.
59
59
  *
60
60
  * The static contribution carries stable work guidance and the host's output
61
- * contract. The dynamic contribution captures this invocation's state and
62
- * approved learning, outside the cached prefix. Both remain present on every
61
+ * contract. The context contribution captures this invocation's state and
62
+ * approved learning as request-only user-role context. Both remain present on every
63
63
  * iteration; build fresh contributions for the next admitted step.
64
64
  *
65
65
  * Project instructions and authorization remain on their existing host/runtime
@@ -128,14 +128,14 @@ export function createResidentStepContributions(
128
128
  }),
129
129
  Object.freeze({
130
130
  id: 'namzu.resident-step.continuation',
131
- placement: 'dynamic' as const,
131
+ placement: 'context' as const,
132
132
  render: () => snapshot,
133
133
  }),
134
134
  ...(boundNames.length
135
135
  ? [
136
136
  Object.freeze({
137
137
  id: 'namzu.resident-step.source-bound-learning',
138
- placement: 'turn' as const,
138
+ placement: 'context' as const,
139
139
  render: () => {
140
140
  let sources: readonly ResidentLearningSource[] = []
141
141
  try {
@@ -386,6 +386,71 @@ function vendorRetryAfter(err: unknown): string | undefined {
386
386
  return undefined
387
387
  }
388
388
 
389
+ /** Response headers that name the request, as the vendors that send one spell it. */
390
+ const REQUEST_ID_HEADERS = ['x-request-id', 'request-id', 'x-goog-request-id'] as const
391
+
392
+ /** A header off an SDK error's captured response headers (a `Headers` or a plain object). */
393
+ function vendorHeader(err: unknown, names: readonly string[]): string | undefined {
394
+ if (typeof err !== 'object' || err === null) return undefined
395
+ const headers =
396
+ (err as { headers?: unknown }).headers ??
397
+ (err as { $response?: { headers?: unknown } }).$response?.headers
398
+ if (!headers) return undefined
399
+ for (const name of names) {
400
+ if (typeof (headers as Headers).get === 'function') {
401
+ const value = (headers as Headers).get(name)
402
+ if (value) return value
403
+ continue
404
+ }
405
+ const value = (headers as Record<string, unknown>)[name]
406
+ if (typeof value === 'string' && value) return value
407
+ }
408
+ return undefined
409
+ }
410
+
411
+ const FIELD_VALUE = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/
412
+
413
+ function fieldValue(value: unknown): string | undefined {
414
+ return typeof value === 'string' && FIELD_VALUE.test(value) && redactSecrets(value) === value
415
+ ? value
416
+ : undefined
417
+ }
418
+
419
+ /**
420
+ * The provider's structured fields beside its sentence, in the one body shape every host already
421
+ * reads (`{"error":{"message","type","code","param"},"request_id"}`).
422
+ *
423
+ * A vendor SDK whose error message is only the parsed sentence (OpenAI's "403 <message>") still
424
+ * holds the body's `type`, `code`, `param` and the response's request ID as fields; a host that
425
+ * receives the message alone cannot show them, while Anthropic's message carries its whole body
426
+ * and so shows them. The fields are bounded identifiers (never a body), so nothing echoed can ride
427
+ * along. With nothing but a sentence the result is that sentence unchanged.
428
+ */
429
+ export function structuredVendorDetail(input: {
430
+ readonly message: string | undefined
431
+ readonly type?: unknown
432
+ readonly code?: unknown
433
+ readonly param?: unknown
434
+ readonly requestId?: unknown
435
+ }): string | undefined {
436
+ const message = vendorDetail(input.message?.replace(/^\d{3}\s+/, ''))
437
+ const type = fieldValue(input.type)
438
+ const code = fieldValue(input.code)
439
+ const param = fieldValue(input.param)
440
+ const requestId = fieldValue(input.requestId)
441
+ if (!type && !code && !param && !requestId) return message
442
+ if (!message) return undefined
443
+ return JSON.stringify({
444
+ error: {
445
+ message,
446
+ ...(type ? { type } : {}),
447
+ ...(code ? { code } : {}),
448
+ ...(param ? { param } : {}),
449
+ },
450
+ ...(requestId ? { request_id: requestId } : {}),
451
+ })
452
+ }
453
+
389
454
  /**
390
455
  * Classify an error thrown by a vendor SDK and replace it.
391
456
  *
@@ -460,7 +525,18 @@ export function providerVendorError(input: {
460
525
  input.retryAfter ?? vendorRetryAfter(error),
461
526
  input.now ?? Date.now(),
462
527
  )
463
- const detail = vendorDetail(message)
528
+ const fields = error as { type?: unknown; param?: unknown; requestID?: unknown } | null
529
+ // A message that already carries its body (Anthropic's) has the fields; one that is only the
530
+ // parsed sentence (OpenAI's) gets them from the SDK error's own properties.
531
+ const detail = carriesBody(message)
532
+ ? vendorDetail(message)
533
+ : structuredVendorDetail({
534
+ message,
535
+ type: fields?.type,
536
+ code: exactProviderCode,
537
+ param: fields?.param,
538
+ requestId: fields?.requestID ?? vendorHeader(error, REQUEST_ID_HEADERS),
539
+ })
464
540
  return new ProviderRequestError({
465
541
  kind,
466
542
  providerId: input.providerId,
@@ -471,6 +547,51 @@ export function providerVendorError(input: {
471
547
  })
472
548
  }
473
549
 
550
+ /** Anthropic's SDK words a failure "<status> <JSON body>"; OpenAI's is "<status> <sentence>", which may itself hold a brace. */
551
+ function carriesBody(message: string): boolean {
552
+ const rest = message.replace(/^\d{3}\s+/, '').trim()
553
+ if (!rest.startsWith('{')) return false
554
+ try {
555
+ const parsed: unknown = JSON.parse(rest)
556
+ return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
557
+ } catch {
558
+ return false
559
+ }
560
+ }
561
+
562
+ function parsedBody(body: unknown): Record<string, unknown> | undefined {
563
+ let decoded = body
564
+ if (typeof decoded === 'string') {
565
+ try {
566
+ decoded = JSON.parse(decoded)
567
+ } catch {
568
+ return undefined
569
+ }
570
+ }
571
+ return typeof decoded === 'object' && decoded !== null && !Array.isArray(decoded)
572
+ ? (decoded as Record<string, unknown>)
573
+ : undefined
574
+ }
575
+
576
+ /** `type`/`status`, `code` and `param` of a `{ error: {...} }` body, only where it spells them. */
577
+ function bodyErrorFields(body: Record<string, unknown> | undefined): {
578
+ type?: unknown
579
+ code?: unknown
580
+ param?: unknown
581
+ } {
582
+ const inner =
583
+ body && typeof body.error === 'object' && body.error !== null
584
+ ? (body.error as Record<string, unknown>)
585
+ : undefined
586
+ if (!inner) return {}
587
+ // Google names its type `status` ("PERMISSION_DENIED") and sends a numeric `code` that is the HTTP status.
588
+ return {
589
+ type: inner.type ?? (typeof inner.status === 'string' ? inner.status : undefined),
590
+ code: typeof inner.code === 'string' ? inner.code : undefined,
591
+ param: inner.param,
592
+ }
593
+ }
594
+
474
595
  /**
475
596
  * Build a classified error from a failed HTTP response.
476
597
  *
@@ -482,11 +603,23 @@ export function providerHttpError(input: {
482
603
  readonly status: number
483
604
  readonly body?: string | null
484
605
  readonly retryAfter?: string | null
606
+ /** The response's request ID header, when the driver read one. */
607
+ readonly requestId?: string | null
485
608
  readonly now?: number
486
609
  }): ProviderRequestError {
487
610
  const kind = classifyProviderHttpStatus(input.status, input.body)
488
611
  const retryAfterMs = parseRetryAfterMs(input.retryAfter, input.now ?? Date.now())
489
- const detail = vendorDetail(input.body)
612
+ const body = parsedBody(input.body)
613
+ const bodyError = bodyErrorFields(body)
614
+ const detail = body
615
+ ? structuredVendorDetail({
616
+ message: vendorDetail(input.body),
617
+ type: bodyError.type,
618
+ code: bodyError.code,
619
+ param: bodyError.param,
620
+ requestId: input.requestId,
621
+ })
622
+ : vendorDetail(input.body)
490
623
  const exactProviderCode = providerCode(input.body)
491
624
  return new ProviderRequestError({
492
625
  kind,