agent-relay 2.3.13 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1421) hide show
  1. package/README.md +42 -176
  2. package/bin/agent-relay-broker-darwin-arm64 +0 -0
  3. package/bin/agent-relay-broker-darwin-x64 +0 -0
  4. package/bin/agent-relay-broker-linux-arm64 +0 -0
  5. package/bin/agent-relay-broker-linux-x64 +0 -0
  6. package/dist/index.cjs +50288 -63371
  7. package/dist/src/cli/bootstrap.d.ts +6 -0
  8. package/dist/src/cli/bootstrap.d.ts.map +1 -0
  9. package/dist/src/cli/bootstrap.js +109 -0
  10. package/dist/src/cli/bootstrap.js.map +1 -0
  11. package/dist/src/cli/commands/agent-management.d.ts +51 -0
  12. package/dist/src/cli/commands/agent-management.d.ts.map +1 -0
  13. package/dist/src/cli/commands/agent-management.js +290 -0
  14. package/dist/src/cli/commands/agent-management.js.map +1 -0
  15. package/dist/src/cli/commands/auth.d.ts +9 -0
  16. package/dist/src/cli/commands/auth.d.ts.map +1 -0
  17. package/dist/src/cli/commands/auth.js +33 -0
  18. package/dist/src/cli/commands/auth.js.map +1 -0
  19. package/dist/src/cli/commands/cloud.d.ts +18 -0
  20. package/dist/src/cli/commands/cloud.d.ts.map +1 -0
  21. package/dist/src/cli/commands/cloud.js +392 -0
  22. package/dist/src/cli/commands/cloud.js.map +1 -0
  23. package/dist/src/cli/commands/core.d.ts +107 -0
  24. package/dist/src/cli/commands/core.d.ts.map +1 -0
  25. package/dist/src/cli/commands/core.js +299 -0
  26. package/dist/src/cli/commands/core.js.map +1 -0
  27. package/dist/src/cli/commands/doctor.d.ts +1 -1
  28. package/dist/src/cli/commands/doctor.d.ts.map +1 -1
  29. package/dist/src/cli/commands/doctor.js +1 -485
  30. package/dist/src/cli/commands/doctor.js.map +1 -1
  31. package/dist/src/cli/commands/messaging.d.ts +61 -0
  32. package/dist/src/cli/commands/messaging.d.ts.map +1 -0
  33. package/dist/src/cli/commands/messaging.js +213 -0
  34. package/dist/src/cli/commands/messaging.js.map +1 -0
  35. package/dist/src/cli/commands/monitoring.d.ts +57 -0
  36. package/dist/src/cli/commands/monitoring.d.ts.map +1 -0
  37. package/dist/src/cli/commands/monitoring.js +350 -0
  38. package/dist/src/cli/commands/monitoring.js.map +1 -0
  39. package/dist/src/cli/commands/setup.d.ts +29 -0
  40. package/dist/src/cli/commands/setup.d.ts.map +1 -0
  41. package/dist/src/cli/commands/setup.js +324 -0
  42. package/dist/src/cli/commands/setup.js.map +1 -0
  43. package/dist/src/cli/commands/swarm.d.ts +3 -0
  44. package/dist/src/cli/commands/swarm.d.ts.map +1 -0
  45. package/dist/src/cli/commands/swarm.js +108 -0
  46. package/dist/src/cli/commands/swarm.js.map +1 -0
  47. package/dist/src/cli/index.d.ts +1 -28
  48. package/dist/src/cli/index.d.ts.map +1 -1
  49. package/dist/src/cli/index.js +4 -4936
  50. package/dist/src/cli/index.js.map +1 -1
  51. package/dist/src/cli/lib/agent-management-listing.d.ts +39 -0
  52. package/dist/src/cli/lib/agent-management-listing.d.ts.map +1 -0
  53. package/dist/src/cli/lib/agent-management-listing.js +253 -0
  54. package/dist/src/cli/lib/agent-management-listing.js.map +1 -0
  55. package/dist/src/cli/lib/auth-ssh.d.ts +48 -0
  56. package/dist/src/cli/lib/auth-ssh.d.ts.map +1 -0
  57. package/dist/src/cli/lib/auth-ssh.js +572 -0
  58. package/dist/src/cli/lib/auth-ssh.js.map +1 -0
  59. package/dist/src/cli/lib/bridge.d.ts +8 -0
  60. package/dist/src/cli/lib/bridge.d.ts.map +1 -0
  61. package/dist/src/cli/lib/bridge.js +100 -0
  62. package/dist/src/cli/lib/bridge.js.map +1 -0
  63. package/dist/src/cli/lib/broker-lifecycle.d.ts +20 -0
  64. package/dist/src/cli/lib/broker-lifecycle.d.ts.map +1 -0
  65. package/dist/src/cli/lib/broker-lifecycle.js +843 -0
  66. package/dist/src/cli/lib/broker-lifecycle.js.map +1 -0
  67. package/dist/src/cli/lib/client-factory.d.ts +24 -0
  68. package/dist/src/cli/lib/client-factory.d.ts.map +1 -0
  69. package/dist/src/cli/lib/client-factory.js +20 -0
  70. package/dist/src/cli/lib/client-factory.js.map +1 -0
  71. package/dist/src/cli/lib/cloud-client.d.ts +39 -0
  72. package/dist/src/cli/lib/cloud-client.d.ts.map +1 -0
  73. package/dist/src/cli/lib/cloud-client.js +120 -0
  74. package/dist/src/cli/lib/cloud-client.js.map +1 -0
  75. package/dist/src/cli/lib/core-maintenance.d.ts +13 -0
  76. package/dist/src/cli/lib/core-maintenance.d.ts.map +1 -0
  77. package/dist/src/cli/lib/core-maintenance.js +250 -0
  78. package/dist/src/cli/lib/core-maintenance.js.map +1 -0
  79. package/dist/src/cli/lib/doctor.d.ts +2 -0
  80. package/dist/src/cli/lib/doctor.d.ts.map +1 -0
  81. package/dist/src/cli/lib/doctor.js +484 -0
  82. package/dist/src/cli/lib/doctor.js.map +1 -0
  83. package/dist/src/cli/lib/formatting.d.ts +8 -0
  84. package/dist/src/cli/lib/formatting.d.ts.map +1 -0
  85. package/dist/src/cli/lib/formatting.js +48 -0
  86. package/dist/src/cli/lib/formatting.js.map +1 -0
  87. package/dist/src/cli/lib/index.d.ts +5 -0
  88. package/dist/src/cli/lib/index.d.ts.map +1 -0
  89. package/dist/src/cli/lib/index.js +5 -0
  90. package/dist/src/cli/lib/index.js.map +1 -0
  91. package/dist/src/cli/lib/jsonc.d.ts +8 -0
  92. package/dist/src/cli/lib/jsonc.d.ts.map +1 -0
  93. package/dist/src/cli/lib/jsonc.js +88 -0
  94. package/dist/src/cli/lib/jsonc.js.map +1 -0
  95. package/dist/src/cli/lib/monitoring-health.d.ts +32 -0
  96. package/dist/src/cli/lib/monitoring-health.d.ts.map +1 -0
  97. package/dist/src/cli/lib/monitoring-health.js +2 -0
  98. package/dist/src/cli/lib/monitoring-health.js.map +1 -0
  99. package/dist/src/cli/lib/paths.d.ts +2 -0
  100. package/dist/src/cli/lib/paths.d.ts.map +1 -0
  101. package/dist/src/cli/lib/paths.js +5 -0
  102. package/dist/src/cli/lib/paths.js.map +1 -0
  103. package/dist/src/index.d.ts +1 -5
  104. package/dist/src/index.d.ts.map +1 -1
  105. package/dist/src/index.js +1 -5
  106. package/dist/src/index.js.map +1 -1
  107. package/install.sh +0 -30
  108. package/package.json +84 -98
  109. package/packages/acp-bridge/README.md +8 -8
  110. package/packages/acp-bridge/dist/acp-agent.d.ts +8 -7
  111. package/packages/acp-bridge/dist/acp-agent.d.ts.map +1 -1
  112. package/packages/acp-bridge/dist/acp-agent.js +118 -143
  113. package/packages/acp-bridge/dist/acp-agent.js.map +1 -1
  114. package/packages/acp-bridge/dist/cli.d.ts +1 -1
  115. package/packages/acp-bridge/dist/cli.js +3 -3
  116. package/packages/acp-bridge/dist/index.d.ts +2 -2
  117. package/packages/acp-bridge/dist/index.d.ts.map +1 -1
  118. package/packages/acp-bridge/dist/index.js +1 -1
  119. package/packages/acp-bridge/dist/index.js.map +1 -1
  120. package/packages/acp-bridge/dist/types.d.ts +3 -3
  121. package/packages/acp-bridge/package.json +3 -3
  122. package/packages/acp-bridge/src/acp-agent.ts +123 -160
  123. package/packages/acp-bridge/src/cli.ts +3 -3
  124. package/packages/acp-bridge/src/index.ts +2 -2
  125. package/packages/acp-bridge/src/types.ts +3 -3
  126. package/packages/config/dist/bridge-config.d.ts +5 -5
  127. package/packages/config/dist/bridge-config.d.ts.map +1 -1
  128. package/packages/config/dist/bridge-config.js +16 -9
  129. package/packages/config/dist/bridge-config.js.map +1 -1
  130. package/packages/config/dist/cli-auth-config.d.ts +1 -1
  131. package/packages/config/dist/cli-auth-config.js +1 -1
  132. package/packages/config/dist/cli-registry.generated.d.ts +340 -0
  133. package/packages/config/dist/cli-registry.generated.d.ts.map +1 -0
  134. package/packages/config/dist/cli-registry.generated.js +297 -0
  135. package/packages/config/dist/cli-registry.generated.js.map +1 -0
  136. package/packages/config/dist/index.d.ts +1 -0
  137. package/packages/config/dist/index.d.ts.map +1 -1
  138. package/packages/config/dist/index.js +1 -0
  139. package/packages/config/dist/index.js.map +1 -1
  140. package/packages/config/dist/project-namespace.d.ts +9 -9
  141. package/packages/config/dist/project-namespace.js +3 -3
  142. package/packages/config/dist/relay-config.d.ts +1 -1
  143. package/packages/config/dist/relay-config.js +1 -1
  144. package/packages/config/dist/schemas.js +1 -1
  145. package/packages/config/dist/shadow-config.d.ts +2 -1
  146. package/packages/config/dist/shadow-config.d.ts.map +1 -1
  147. package/packages/config/dist/shadow-config.js.map +1 -1
  148. package/packages/config/package.json +2 -3
  149. package/packages/config/src/bridge-config.test.ts +20 -6
  150. package/packages/config/src/bridge-config.ts +20 -10
  151. package/packages/config/src/cli-auth-config.ts +1 -1
  152. package/packages/config/src/cli-registry.generated.ts +328 -0
  153. package/packages/config/src/index.ts +1 -0
  154. package/packages/config/src/project-namespace.ts +9 -9
  155. package/packages/config/src/relay-config.ts +1 -1
  156. package/packages/config/src/schemas.ts +1 -1
  157. package/packages/config/src/shadow-config.ts +8 -1
  158. package/packages/contracts/fixtures/error-fixtures.json +42 -0
  159. package/packages/contracts/fixtures/event-fixtures.json +161 -0
  160. package/packages/contracts/fixtures/health-fixtures.json +35 -0
  161. package/packages/contracts/fixtures/identity-fixtures.json +58 -0
  162. package/packages/contracts/fixtures/replay-fixtures.json +33 -0
  163. package/packages/hooks/dist/inbox-check/types.d.ts +2 -2
  164. package/packages/hooks/dist/types.d.ts +9 -3
  165. package/packages/hooks/dist/types.d.ts.map +1 -1
  166. package/packages/hooks/dist/types.js +1 -1
  167. package/packages/hooks/dist/types.js.map +1 -1
  168. package/packages/hooks/package.json +5 -5
  169. package/packages/hooks/src/inbox-check/types.ts +2 -2
  170. package/packages/hooks/src/types.ts +11 -3
  171. package/packages/memory/package.json +2 -2
  172. package/packages/policy/package.json +2 -2
  173. package/packages/sdk/.mcp.json +14 -0
  174. package/packages/sdk/.trajectories/active/traj_1771875803391_84ca57b2.json +50 -0
  175. package/packages/sdk/.trajectories/active/traj_1771891934534_06504121.json +50 -0
  176. package/packages/sdk/.trajectories/active/traj_1771891957929_211afc4e.json +50 -0
  177. package/packages/sdk/.trajectories/active/traj_1771891982509_38c84638.json +50 -0
  178. package/packages/sdk/.trajectories/completed/traj_1771875803188_cd6d181c.json +80 -0
  179. package/packages/sdk/.trajectories/completed/traj_1771875803204_f2aeb8c8.json +80 -0
  180. package/packages/sdk/.trajectories/completed/traj_1771875803210_d65f3f1a.json +80 -0
  181. package/packages/sdk/.trajectories/completed/traj_1771875803218_e454a25d.json +80 -0
  182. package/packages/sdk/.trajectories/completed/traj_1771875803223_d7a64815.json +80 -0
  183. package/packages/sdk/.trajectories/completed/traj_1771875803227_7e56da5b.json +80 -0
  184. package/packages/sdk/.trajectories/completed/traj_1771875803235_4fbf93b4.json +80 -0
  185. package/packages/sdk/.trajectories/completed/traj_1771875803243_47931c71.json +80 -0
  186. package/packages/sdk/.trajectories/completed/traj_1771875803258_3816f3fe.json +80 -0
  187. package/packages/sdk/.trajectories/completed/traj_1771875803268_8061140e.json +80 -0
  188. package/packages/sdk/.trajectories/completed/traj_1771875803326_ae6f9c78.json +80 -0
  189. package/packages/sdk/.trajectories/completed/traj_1771875808396_cbde0a6c.json +91 -0
  190. package/packages/sdk/.trajectories/completed/traj_1771875812026_aa2442bb.json +91 -0
  191. package/packages/sdk/.trajectories/completed/traj_1771875815431_c2c656c5.json +91 -0
  192. package/packages/sdk/.trajectories/completed/traj_1771875818645_3a4dbf02.json +91 -0
  193. package/packages/sdk/.trajectories/completed/traj_1771891934403_24923c03.json +80 -0
  194. package/packages/sdk/.trajectories/completed/traj_1771891934421_dca16e24.json +80 -0
  195. package/packages/sdk/.trajectories/completed/traj_1771891934430_057706f7.json +80 -0
  196. package/packages/sdk/.trajectories/completed/traj_1771891934442_faf97382.json +80 -0
  197. package/packages/sdk/.trajectories/completed/traj_1771891934454_5542ecd5.json +80 -0
  198. package/packages/sdk/.trajectories/completed/traj_1771891934464_12202a08.json +80 -0
  199. package/packages/sdk/.trajectories/completed/traj_1771891934487_94378275.json +80 -0
  200. package/packages/sdk/.trajectories/completed/traj_1771891934503_ca728c13.json +80 -0
  201. package/packages/sdk/.trajectories/completed/traj_1771891934519_100af69a.json +80 -0
  202. package/packages/sdk/.trajectories/completed/traj_1771891934536_62ad39d9.json +80 -0
  203. package/packages/sdk/.trajectories/completed/traj_1771891934553_d6798a52.json +80 -0
  204. package/packages/sdk/.trajectories/completed/traj_1771891939537_541c8096.json +91 -0
  205. package/packages/sdk/.trajectories/completed/traj_1771891942985_36ab9a4d.json +91 -0
  206. package/packages/sdk/.trajectories/completed/traj_1771891946453_e8a6e05f.json +91 -0
  207. package/packages/sdk/.trajectories/completed/traj_1771891949838_5de0de84.json +91 -0
  208. package/packages/sdk/.trajectories/completed/traj_1771891957807_0ecfb4f4.json +80 -0
  209. package/packages/sdk/.trajectories/completed/traj_1771891957827_c4539239.json +80 -0
  210. package/packages/sdk/.trajectories/completed/traj_1771891957836_91168b48.json +80 -0
  211. package/packages/sdk/.trajectories/completed/traj_1771891957848_8c5cad0b.json +80 -0
  212. package/packages/sdk/.trajectories/completed/traj_1771891957857_0986b293.json +80 -0
  213. package/packages/sdk/.trajectories/completed/traj_1771891957872_8a3113af.json +80 -0
  214. package/packages/sdk/.trajectories/completed/traj_1771891957884_0bb85208.json +80 -0
  215. package/packages/sdk/.trajectories/completed/traj_1771891957892_86c75e2e.json +80 -0
  216. package/packages/sdk/.trajectories/completed/traj_1771891957907_98ca0e6f.json +80 -0
  217. package/packages/sdk/.trajectories/completed/traj_1771891957918_d9091231.json +80 -0
  218. package/packages/sdk/.trajectories/completed/traj_1771891957931_dcaf77ed.json +80 -0
  219. package/packages/sdk/.trajectories/completed/traj_1771891962931_eb1fdee2.json +91 -0
  220. package/packages/sdk/.trajectories/completed/traj_1771891966262_9061a93f.json +91 -0
  221. package/packages/sdk/.trajectories/completed/traj_1771891969915_1adaba19.json +91 -0
  222. package/packages/sdk/.trajectories/completed/traj_1771891973588_f08b79e9.json +91 -0
  223. package/packages/sdk/.trajectories/completed/traj_1771891982421_f1985bce.json +80 -0
  224. package/packages/sdk/.trajectories/completed/traj_1771891982432_e7a84163.json +80 -0
  225. package/packages/sdk/.trajectories/completed/traj_1771891982447_369b842a.json +80 -0
  226. package/packages/sdk/.trajectories/completed/traj_1771891982469_5fc45199.json +80 -0
  227. package/packages/sdk/.trajectories/completed/traj_1771891982495_454c7cb3.json +80 -0
  228. package/packages/sdk/.trajectories/completed/traj_1771891982514_08098e03.json +80 -0
  229. package/packages/sdk/.trajectories/completed/traj_1771891982526_b351d778.json +80 -0
  230. package/packages/sdk/.trajectories/completed/traj_1771891982533_fa542d83.json +80 -0
  231. package/packages/sdk/.trajectories/completed/traj_1771891982540_18ab24dc.json +80 -0
  232. package/packages/sdk/.trajectories/completed/traj_1771891982544_5b4fa163.json +80 -0
  233. package/packages/sdk/.trajectories/completed/traj_1771891982548_c13f089a.json +80 -0
  234. package/packages/sdk/.trajectories/completed/traj_1771891987510_23f6da1f.json +91 -0
  235. package/packages/sdk/.trajectories/completed/traj_1771891991466_912c2e04.json +91 -0
  236. package/packages/sdk/.trajectories/completed/traj_1771891994891_60604be2.json +91 -0
  237. package/packages/sdk/.trajectories/completed/traj_1771891998370_cfaf9b8b.json +91 -0
  238. package/packages/sdk/README.md +68 -838
  239. package/packages/sdk/bin/agent-relay-broker +0 -0
  240. package/packages/sdk/dist/__tests__/contract-fixtures.test.d.ts +2 -0
  241. package/packages/sdk/dist/__tests__/contract-fixtures.test.d.ts.map +1 -0
  242. package/packages/sdk/dist/__tests__/contract-fixtures.test.js +85 -0
  243. package/packages/sdk/dist/__tests__/contract-fixtures.test.js.map +1 -0
  244. package/packages/sdk/dist/__tests__/facade.test.js +305 -0
  245. package/packages/sdk/dist/__tests__/facade.test.js.map +1 -0
  246. package/packages/sdk/dist/__tests__/integration.test.js +169 -0
  247. package/packages/sdk/dist/__tests__/integration.test.js.map +1 -0
  248. package/packages/sdk/dist/__tests__/pty.test.d.ts +2 -0
  249. package/packages/sdk/dist/__tests__/pty.test.d.ts.map +1 -0
  250. package/packages/sdk/dist/__tests__/pty.test.js +20 -0
  251. package/packages/sdk/dist/__tests__/pty.test.js.map +1 -0
  252. package/packages/sdk/dist/__tests__/quickstart.test.js +176 -0
  253. package/packages/sdk/dist/__tests__/quickstart.test.js.map +1 -0
  254. package/packages/sdk/dist/__tests__/spawn-from-env.test.d.ts +2 -0
  255. package/packages/sdk/dist/__tests__/spawn-from-env.test.d.ts.map +1 -0
  256. package/packages/sdk/dist/__tests__/spawn-from-env.test.js +206 -0
  257. package/packages/sdk/dist/__tests__/spawn-from-env.test.js.map +1 -0
  258. package/packages/sdk/dist/__tests__/unit.test.js +347 -0
  259. package/packages/sdk/dist/__tests__/unit.test.js.map +1 -0
  260. package/packages/sdk/dist/client.d.ts +140 -526
  261. package/packages/sdk/dist/client.d.ts.map +1 -1
  262. package/packages/sdk/dist/client.js +416 -1509
  263. package/packages/sdk/dist/client.js.map +1 -1
  264. package/packages/sdk/dist/examples/workflow-superiority.d.ts +32 -0
  265. package/packages/sdk/dist/examples/workflow-superiority.d.ts.map +1 -0
  266. package/packages/sdk/dist/examples/workflow-superiority.js +1421 -0
  267. package/packages/sdk/dist/examples/workflow-superiority.js.map +1 -0
  268. package/packages/sdk/dist/index.d.ts +13 -20
  269. package/packages/sdk/dist/index.d.ts.map +1 -1
  270. package/packages/sdk/dist/index.js +12 -26
  271. package/packages/sdk/dist/index.js.map +1 -1
  272. package/packages/sdk/dist/logs.d.ts +70 -25
  273. package/packages/sdk/dist/logs.d.ts.map +1 -1
  274. package/packages/sdk/dist/logs.js +238 -42
  275. package/packages/sdk/dist/logs.js.map +1 -1
  276. package/packages/sdk/dist/models.d.ts +9 -0
  277. package/packages/sdk/dist/models.d.ts.map +1 -0
  278. package/packages/sdk/dist/models.js +17 -0
  279. package/packages/sdk/dist/models.js.map +1 -0
  280. package/packages/sdk/dist/protocol.d.ts +366 -0
  281. package/packages/sdk/dist/protocol.d.ts.map +1 -0
  282. package/packages/sdk/dist/pty.d.ts.map +1 -0
  283. package/packages/sdk/dist/pty.js +26 -0
  284. package/packages/sdk/dist/pty.js.map +1 -0
  285. package/packages/sdk/dist/relay-adapter.d.ts +139 -0
  286. package/packages/sdk/dist/relay-adapter.d.ts.map +1 -0
  287. package/packages/sdk/dist/relay-adapter.js +210 -0
  288. package/packages/sdk/dist/relay-adapter.js.map +1 -0
  289. package/packages/sdk/dist/relay.d.ts +304 -0
  290. package/packages/sdk/dist/relay.d.ts.map +1 -0
  291. package/packages/sdk/dist/relay.js +910 -0
  292. package/packages/sdk/dist/relay.js.map +1 -0
  293. package/packages/sdk/dist/shadow.d.ts +101 -0
  294. package/packages/sdk/dist/shadow.d.ts.map +1 -0
  295. package/packages/sdk/dist/shadow.js.map +1 -0
  296. package/packages/sdk/dist/spawn-from-env.d.ts +77 -0
  297. package/packages/sdk/dist/spawn-from-env.d.ts.map +1 -0
  298. package/packages/sdk/dist/spawn-from-env.js +172 -0
  299. package/packages/sdk/dist/spawn-from-env.js.map +1 -0
  300. package/packages/sdk/dist/workflows/builder.d.ts +114 -0
  301. package/packages/sdk/dist/workflows/builder.d.ts.map +1 -0
  302. package/packages/sdk/dist/workflows/builder.js +201 -0
  303. package/packages/sdk/dist/workflows/builder.js.map +1 -0
  304. package/packages/sdk/dist/workflows/cli.d.ts +11 -0
  305. package/packages/sdk/dist/workflows/cli.d.ts.map +1 -0
  306. package/packages/sdk/dist/workflows/cli.js +144 -0
  307. package/packages/sdk/dist/workflows/cli.js.map +1 -0
  308. package/packages/sdk/dist/workflows/coordinator.d.ts +73 -0
  309. package/packages/sdk/dist/workflows/coordinator.d.ts.map +1 -0
  310. package/packages/sdk/dist/workflows/coordinator.js +647 -0
  311. package/packages/sdk/dist/workflows/coordinator.js.map +1 -0
  312. package/packages/sdk/dist/workflows/custom-steps.d.ts +73 -0
  313. package/packages/sdk/dist/workflows/custom-steps.d.ts.map +1 -0
  314. package/packages/sdk/dist/workflows/custom-steps.js +321 -0
  315. package/packages/sdk/dist/workflows/custom-steps.js.map +1 -0
  316. package/packages/sdk/dist/workflows/dry-run-format.d.ts +6 -0
  317. package/packages/sdk/dist/workflows/dry-run-format.d.ts.map +1 -0
  318. package/packages/sdk/dist/workflows/dry-run-format.js +68 -0
  319. package/packages/sdk/dist/workflows/dry-run-format.js.map +1 -0
  320. package/packages/sdk/dist/workflows/file-db.d.ts +33 -0
  321. package/packages/sdk/dist/workflows/file-db.d.ts.map +1 -0
  322. package/packages/sdk/dist/workflows/file-db.js +108 -0
  323. package/packages/sdk/dist/workflows/file-db.js.map +1 -0
  324. package/packages/sdk/dist/workflows/index.d.ts +15 -0
  325. package/packages/sdk/dist/workflows/index.d.ts.map +1 -0
  326. package/packages/sdk/dist/workflows/index.js +15 -0
  327. package/packages/sdk/dist/workflows/index.js.map +1 -0
  328. package/packages/sdk/dist/workflows/run.d.ts +38 -0
  329. package/packages/sdk/dist/workflows/run.d.ts.map +1 -0
  330. package/packages/sdk/dist/workflows/run.js +25 -0
  331. package/packages/sdk/dist/workflows/run.js.map +1 -0
  332. package/packages/sdk/dist/workflows/runner.d.ts +320 -0
  333. package/packages/sdk/dist/workflows/runner.d.ts.map +1 -0
  334. package/packages/sdk/dist/workflows/runner.js +2821 -0
  335. package/packages/sdk/dist/workflows/runner.js.map +1 -0
  336. package/packages/sdk/dist/workflows/templates.d.ts +47 -0
  337. package/packages/sdk/dist/workflows/templates.d.ts.map +1 -0
  338. package/packages/sdk/dist/workflows/templates.js +405 -0
  339. package/packages/sdk/dist/workflows/templates.js.map +1 -0
  340. package/packages/sdk/dist/workflows/trajectory.d.ts +87 -0
  341. package/packages/sdk/dist/workflows/trajectory.d.ts.map +1 -0
  342. package/packages/sdk/dist/workflows/trajectory.js +441 -0
  343. package/packages/sdk/dist/workflows/trajectory.js.map +1 -0
  344. package/packages/sdk/dist/workflows/types.d.ts +306 -0
  345. package/packages/sdk/dist/workflows/types.d.ts.map +1 -0
  346. package/packages/sdk/dist/workflows/types.js +23 -0
  347. package/packages/sdk/dist/workflows/types.js.map +1 -0
  348. package/packages/sdk/dist/workflows/validator.d.ts +11 -0
  349. package/packages/sdk/dist/workflows/validator.d.ts.map +1 -0
  350. package/packages/sdk/dist/workflows/validator.js +128 -0
  351. package/packages/sdk/dist/workflows/validator.js.map +1 -0
  352. package/packages/sdk/package.json +59 -53
  353. package/packages/sdk/scripts/bundle-agent-relay.mjs +53 -0
  354. package/packages/sdk/src/__tests__/contract-fixtures.test.ts +122 -0
  355. package/packages/sdk/src/__tests__/error-scenarios.test.ts +682 -0
  356. package/packages/sdk/src/__tests__/facade.test.ts +364 -0
  357. package/packages/sdk/src/__tests__/idle-nudge.test.ts +438 -0
  358. package/packages/sdk/src/__tests__/integration.test.ts +204 -0
  359. package/packages/sdk/src/__tests__/orchestration-upgrades.test.ts +797 -0
  360. package/packages/sdk/src/__tests__/pty.test.ts +24 -0
  361. package/packages/sdk/src/__tests__/quickstart.test.ts +198 -0
  362. package/packages/sdk/src/__tests__/spawn-from-env.test.ts +282 -0
  363. package/packages/sdk/src/__tests__/swarm-coordinator.test.ts +909 -0
  364. package/packages/sdk/src/__tests__/unit.test.ts +435 -0
  365. package/packages/sdk/src/__tests__/workflow-runner.test.ts +489 -0
  366. package/packages/sdk/src/__tests__/yaml-validation.test.ts +890 -0
  367. package/packages/sdk/src/client.ts +514 -1912
  368. package/packages/sdk/src/examples/workflow-superiority.ts +1485 -0
  369. package/packages/sdk/src/examples/workflows/README.md +156 -0
  370. package/packages/sdk/src/examples/workflows/ralph-overnight.yaml +421 -0
  371. package/packages/sdk/src/examples/workflows/ralph-swarm.yaml +411 -0
  372. package/packages/sdk/src/examples/workflows/ralph-tdd.yaml +259 -0
  373. package/packages/sdk/src/index.ts +13 -116
  374. package/packages/sdk/src/logs.ts +282 -54
  375. package/packages/sdk/src/models.ts +36 -0
  376. package/packages/sdk/src/protocol.ts +385 -0
  377. package/packages/sdk/src/pty.ts +35 -0
  378. package/packages/sdk/src/relay-adapter.ts +316 -0
  379. package/packages/sdk/src/relay.ts +1147 -0
  380. package/packages/sdk/src/shadow.ts +228 -0
  381. package/packages/sdk/src/spawn-from-env.ts +245 -0
  382. package/packages/sdk/src/workflows/README.md +656 -0
  383. package/packages/sdk/src/workflows/builder.ts +278 -0
  384. package/packages/sdk/src/workflows/builtin-templates/bug-fix.yaml +135 -0
  385. package/packages/sdk/src/workflows/builtin-templates/code-review.yaml +133 -0
  386. package/packages/sdk/src/workflows/builtin-templates/competitive.yaml +103 -0
  387. package/packages/sdk/src/workflows/builtin-templates/documentation.yaml +120 -0
  388. package/packages/sdk/src/workflows/builtin-templates/feature-dev.yaml +142 -0
  389. package/packages/sdk/src/workflows/builtin-templates/refactor.yaml +141 -0
  390. package/packages/sdk/src/workflows/builtin-templates/review-loop.yaml +223 -0
  391. package/packages/sdk/src/workflows/builtin-templates/security-audit.yaml +129 -0
  392. package/packages/sdk/src/workflows/cli.ts +162 -0
  393. package/packages/sdk/src/workflows/coordinator.ts +842 -0
  394. package/packages/sdk/src/workflows/custom-steps.ts +450 -0
  395. package/packages/sdk/src/workflows/dry-run-format.ts +75 -0
  396. package/packages/sdk/src/workflows/file-db.ts +117 -0
  397. package/packages/sdk/src/workflows/index.ts +24 -0
  398. package/packages/sdk/src/workflows/run.ts +72 -0
  399. package/packages/sdk/src/workflows/runner.ts +3409 -0
  400. package/packages/sdk/src/workflows/schema.json +651 -0
  401. package/packages/sdk/src/workflows/templates.ts +552 -0
  402. package/packages/sdk/src/workflows/trajectory.ts +631 -0
  403. package/packages/sdk/src/workflows/types.ts +389 -0
  404. package/packages/sdk/src/workflows/validator.ts +151 -0
  405. package/packages/sdk/tsconfig.build.json +25 -0
  406. package/packages/sdk/tsconfig.json +17 -18
  407. package/packages/sdk/vitest.config.ts +1 -1
  408. package/packages/sdk-py/README.md +106 -21
  409. package/packages/sdk-py/agent_relay/__init__.py +21 -0
  410. package/packages/sdk-py/agent_relay/models.py +206 -0
  411. package/packages/sdk-py/pyproject.toml +2 -2
  412. package/packages/sdk-py/src/agent_relay/__init__.py +76 -0
  413. package/packages/sdk-py/src/agent_relay/builder.py +430 -109
  414. package/packages/sdk-py/src/agent_relay/templates.py +197 -0
  415. package/packages/sdk-py/src/agent_relay/types.py +489 -15
  416. package/packages/sdk-py/tests/test_builder.py +115 -1
  417. package/packages/sdk-py/tests/test_workflow_templates.py +450 -0
  418. package/packages/shared/cli-registry.yaml +193 -0
  419. package/packages/shared/codegen-py.mjs +215 -0
  420. package/packages/shared/codegen-ts.mjs +227 -0
  421. package/packages/telemetry/dist/events.d.ts +8 -8
  422. package/packages/telemetry/dist/index.d.ts +1 -1
  423. package/packages/telemetry/package.json +2 -2
  424. package/packages/telemetry/src/events.ts +9 -9
  425. package/packages/telemetry/src/index.ts +2 -2
  426. package/packages/trajectory/package.json +2 -2
  427. package/packages/user-directory/dist/user-directory.js +1 -1
  428. package/packages/user-directory/dist/user-directory.js.map +1 -1
  429. package/packages/user-directory/package.json +2 -2
  430. package/packages/user-directory/src/user-directory.ts +1 -1
  431. package/packages/utils/dist/cjs/client-helpers.js +4 -4
  432. package/packages/utils/dist/cjs/discovery.js +9 -6
  433. package/packages/utils/dist/cjs/errors.js +5 -5
  434. package/packages/utils/dist/cjs/legacy-protocol.js +70 -0
  435. package/packages/utils/dist/cjs/logger.js +3 -3
  436. package/packages/utils/dist/cjs/precompiled-patterns.js +33 -2
  437. package/packages/utils/dist/cjs/relay-pty-path.js +0 -6
  438. package/packages/utils/dist/client-helpers.d.ts +1 -1
  439. package/packages/utils/dist/client-helpers.d.ts.map +1 -1
  440. package/packages/utils/dist/client-helpers.js +1 -1
  441. package/packages/utils/dist/client-helpers.js.map +1 -1
  442. package/packages/utils/dist/discovery.d.ts +7 -7
  443. package/packages/utils/dist/discovery.d.ts.map +1 -1
  444. package/packages/utils/dist/discovery.js +20 -17
  445. package/packages/utils/dist/discovery.js.map +1 -1
  446. package/packages/utils/dist/errors.d.ts +1 -1
  447. package/packages/utils/dist/errors.js +3 -3
  448. package/packages/utils/dist/legacy-protocol.d.ts +46 -0
  449. package/packages/utils/dist/legacy-protocol.d.ts.map +1 -0
  450. package/packages/utils/dist/legacy-protocol.js +47 -0
  451. package/packages/utils/dist/legacy-protocol.js.map +1 -0
  452. package/packages/utils/dist/logger.d.ts +2 -2
  453. package/packages/utils/dist/logger.js +2 -2
  454. package/packages/utils/dist/precompiled-patterns.d.ts.map +1 -1
  455. package/packages/utils/dist/precompiled-patterns.js +28 -2
  456. package/packages/utils/dist/precompiled-patterns.js.map +1 -1
  457. package/packages/utils/dist/relay-pty-path.d.ts.map +1 -1
  458. package/packages/utils/dist/relay-pty-path.js +1 -10
  459. package/packages/utils/dist/relay-pty-path.js.map +1 -1
  460. package/packages/utils/package.json +2 -3
  461. package/packages/utils/src/client-helpers.ts +1 -1
  462. package/packages/utils/src/consolidation.test.ts +3 -3
  463. package/packages/utils/src/discovery.test.ts +3 -3
  464. package/packages/utils/src/discovery.ts +21 -18
  465. package/packages/utils/src/errors.test.ts +6 -11
  466. package/packages/utils/src/errors.ts +3 -3
  467. package/packages/utils/src/legacy-protocol.ts +151 -0
  468. package/packages/utils/src/logger.ts +2 -2
  469. package/packages/utils/src/precompiled-patterns.test.ts +8 -0
  470. package/packages/utils/src/precompiled-patterns.ts +40 -2
  471. package/packages/utils/src/relay-pty-path.test.ts +23 -34
  472. package/packages/utils/src/relay-pty-path.ts +1 -11
  473. package/relay-snippets/agent-relay-protocol.md +6 -43
  474. package/relay-snippets/agent-relay-snippet.md +59 -203
  475. package/scripts/postinstall.js +44 -171
  476. package/bin/relay-pty-darwin-arm64 +0 -0
  477. package/bin/relay-pty-darwin-x64 +0 -0
  478. package/bin/relay-pty-linux-arm64 +0 -0
  479. package/bin/relay-pty-linux-x64 +0 -0
  480. package/dist/src/bridge/index.d.ts +0 -8
  481. package/dist/src/bridge/index.d.ts.map +0 -1
  482. package/dist/src/bridge/index.js +0 -8
  483. package/dist/src/bridge/index.js.map +0 -1
  484. package/dist/src/continuity/index.d.ts +0 -5
  485. package/dist/src/continuity/index.d.ts.map +0 -1
  486. package/dist/src/continuity/index.js +0 -5
  487. package/dist/src/continuity/index.js.map +0 -1
  488. package/dist/src/daemon/index.d.ts +0 -8
  489. package/dist/src/daemon/index.d.ts.map +0 -1
  490. package/dist/src/daemon/index.js +0 -9
  491. package/dist/src/daemon/index.js.map +0 -1
  492. package/dist/src/protocol/index.d.ts +0 -8
  493. package/dist/src/protocol/index.d.ts.map +0 -1
  494. package/dist/src/protocol/index.js +0 -8
  495. package/dist/src/protocol/index.js.map +0 -1
  496. package/dist/src/resiliency/index.d.ts +0 -5
  497. package/dist/src/resiliency/index.d.ts.map +0 -1
  498. package/dist/src/resiliency/index.js +0 -5
  499. package/dist/src/resiliency/index.js.map +0 -1
  500. package/dist/src/state/index.d.ts +0 -5
  501. package/dist/src/state/index.d.ts.map +0 -1
  502. package/dist/src/state/index.js +0 -5
  503. package/dist/src/state/index.js.map +0 -1
  504. package/dist/src/storage/index.d.ts +0 -8
  505. package/dist/src/storage/index.d.ts.map +0 -1
  506. package/dist/src/storage/index.js +0 -8
  507. package/dist/src/storage/index.js.map +0 -1
  508. package/dist/src/wrapper/index.d.ts +0 -8
  509. package/dist/src/wrapper/index.d.ts.map +0 -1
  510. package/dist/src/wrapper/index.js +0 -11
  511. package/dist/src/wrapper/index.js.map +0 -1
  512. package/packages/bridge/dist/cli-resolution.d.ts +0 -32
  513. package/packages/bridge/dist/cli-resolution.d.ts.map +0 -1
  514. package/packages/bridge/dist/cli-resolution.js +0 -88
  515. package/packages/bridge/dist/cli-resolution.js.map +0 -1
  516. package/packages/bridge/dist/index.d.ts +0 -9
  517. package/packages/bridge/dist/index.d.ts.map +0 -1
  518. package/packages/bridge/dist/index.js +0 -11
  519. package/packages/bridge/dist/index.js.map +0 -1
  520. package/packages/bridge/dist/multi-project-client.d.ts +0 -99
  521. package/packages/bridge/dist/multi-project-client.d.ts.map +0 -1
  522. package/packages/bridge/dist/multi-project-client.js +0 -389
  523. package/packages/bridge/dist/multi-project-client.js.map +0 -1
  524. package/packages/bridge/dist/shadow-cli.d.ts +0 -17
  525. package/packages/bridge/dist/shadow-cli.d.ts.map +0 -1
  526. package/packages/bridge/dist/shadow-cli.js +0 -75
  527. package/packages/bridge/dist/shadow-cli.js.map +0 -1
  528. package/packages/bridge/dist/spawner.d.ts +0 -263
  529. package/packages/bridge/dist/spawner.d.ts.map +0 -1
  530. package/packages/bridge/dist/spawner.js +0 -1758
  531. package/packages/bridge/dist/spawner.js.map +0 -1
  532. package/packages/bridge/dist/types.d.ts +0 -141
  533. package/packages/bridge/dist/types.d.ts.map +0 -1
  534. package/packages/bridge/dist/types.js +0 -6
  535. package/packages/bridge/dist/types.js.map +0 -1
  536. package/packages/bridge/dist/utils.d.ts +0 -39
  537. package/packages/bridge/dist/utils.d.ts.map +0 -1
  538. package/packages/bridge/dist/utils.js +0 -98
  539. package/packages/bridge/dist/utils.js.map +0 -1
  540. package/packages/bridge/package.json +0 -45
  541. package/packages/bridge/src/cli-resolution.test.ts +0 -225
  542. package/packages/bridge/src/cli-resolution.ts +0 -100
  543. package/packages/bridge/src/index.ts +0 -34
  544. package/packages/bridge/src/multi-project-client.test.ts +0 -340
  545. package/packages/bridge/src/multi-project-client.ts +0 -469
  546. package/packages/bridge/src/shadow-cli.ts +0 -95
  547. package/packages/bridge/src/spawner-mcp.test.ts +0 -505
  548. package/packages/bridge/src/spawner.ts +0 -2067
  549. package/packages/bridge/src/types.ts +0 -153
  550. package/packages/bridge/src/utils.test.ts +0 -235
  551. package/packages/bridge/src/utils.ts +0 -113
  552. package/packages/bridge/tsconfig.json +0 -29
  553. package/packages/bridge/vitest.config.ts +0 -9
  554. package/packages/broker-sdk/README.md +0 -97
  555. package/packages/broker-sdk/dist/__tests__/facade.test.js +0 -257
  556. package/packages/broker-sdk/dist/__tests__/facade.test.js.map +0 -1
  557. package/packages/broker-sdk/dist/__tests__/integration.test.js +0 -139
  558. package/packages/broker-sdk/dist/__tests__/integration.test.js.map +0 -1
  559. package/packages/broker-sdk/dist/__tests__/quickstart.test.js +0 -176
  560. package/packages/broker-sdk/dist/__tests__/quickstart.test.js.map +0 -1
  561. package/packages/broker-sdk/dist/__tests__/unit.test.js +0 -192
  562. package/packages/broker-sdk/dist/__tests__/unit.test.js.map +0 -1
  563. package/packages/broker-sdk/dist/client.d.ts +0 -95
  564. package/packages/broker-sdk/dist/client.d.ts.map +0 -1
  565. package/packages/broker-sdk/dist/client.js +0 -372
  566. package/packages/broker-sdk/dist/client.js.map +0 -1
  567. package/packages/broker-sdk/dist/index.d.ts +0 -10
  568. package/packages/broker-sdk/dist/index.d.ts.map +0 -1
  569. package/packages/broker-sdk/dist/index.js +0 -10
  570. package/packages/broker-sdk/dist/index.js.map +0 -1
  571. package/packages/broker-sdk/dist/logs.d.ts +0 -47
  572. package/packages/broker-sdk/dist/logs.d.ts.map +0 -1
  573. package/packages/broker-sdk/dist/logs.js +0 -137
  574. package/packages/broker-sdk/dist/logs.js.map +0 -1
  575. package/packages/broker-sdk/dist/protocol.d.ts +0 -254
  576. package/packages/broker-sdk/dist/protocol.d.ts.map +0 -1
  577. package/packages/broker-sdk/dist/pty.d.ts.map +0 -1
  578. package/packages/broker-sdk/dist/pty.js +0 -14
  579. package/packages/broker-sdk/dist/pty.js.map +0 -1
  580. package/packages/broker-sdk/dist/relay.d.ts +0 -172
  581. package/packages/broker-sdk/dist/relay.d.ts.map +0 -1
  582. package/packages/broker-sdk/dist/relay.js +0 -486
  583. package/packages/broker-sdk/dist/relay.js.map +0 -1
  584. package/packages/broker-sdk/dist/relaycast.d.ts +0 -67
  585. package/packages/broker-sdk/dist/relaycast.d.ts.map +0 -1
  586. package/packages/broker-sdk/dist/relaycast.js +0 -150
  587. package/packages/broker-sdk/dist/relaycast.js.map +0 -1
  588. package/packages/broker-sdk/dist/shadow.d.ts +0 -100
  589. package/packages/broker-sdk/dist/shadow.d.ts.map +0 -1
  590. package/packages/broker-sdk/dist/shadow.js.map +0 -1
  591. package/packages/broker-sdk/dist/workflows/builder.d.ts +0 -101
  592. package/packages/broker-sdk/dist/workflows/builder.d.ts.map +0 -1
  593. package/packages/broker-sdk/dist/workflows/builder.js +0 -179
  594. package/packages/broker-sdk/dist/workflows/builder.js.map +0 -1
  595. package/packages/broker-sdk/dist/workflows/cli.d.ts +0 -10
  596. package/packages/broker-sdk/dist/workflows/cli.d.ts.map +0 -1
  597. package/packages/broker-sdk/dist/workflows/cli.js +0 -82
  598. package/packages/broker-sdk/dist/workflows/cli.js.map +0 -1
  599. package/packages/broker-sdk/dist/workflows/coordinator.d.ts +0 -69
  600. package/packages/broker-sdk/dist/workflows/coordinator.d.ts.map +0 -1
  601. package/packages/broker-sdk/dist/workflows/coordinator.js +0 -585
  602. package/packages/broker-sdk/dist/workflows/coordinator.js.map +0 -1
  603. package/packages/broker-sdk/dist/workflows/index.d.ts +0 -11
  604. package/packages/broker-sdk/dist/workflows/index.d.ts.map +0 -1
  605. package/packages/broker-sdk/dist/workflows/index.js +0 -11
  606. package/packages/broker-sdk/dist/workflows/index.js.map +0 -1
  607. package/packages/broker-sdk/dist/workflows/run.d.ts +0 -33
  608. package/packages/broker-sdk/dist/workflows/run.d.ts.map +0 -1
  609. package/packages/broker-sdk/dist/workflows/run.js +0 -28
  610. package/packages/broker-sdk/dist/workflows/run.js.map +0 -1
  611. package/packages/broker-sdk/dist/workflows/runner.d.ts +0 -136
  612. package/packages/broker-sdk/dist/workflows/runner.d.ts.map +0 -1
  613. package/packages/broker-sdk/dist/workflows/runner.js +0 -900
  614. package/packages/broker-sdk/dist/workflows/runner.js.map +0 -1
  615. package/packages/broker-sdk/dist/workflows/templates.d.ts +0 -47
  616. package/packages/broker-sdk/dist/workflows/templates.d.ts.map +0 -1
  617. package/packages/broker-sdk/dist/workflows/templates.js +0 -395
  618. package/packages/broker-sdk/dist/workflows/templates.js.map +0 -1
  619. package/packages/broker-sdk/dist/workflows/trajectory.d.ts +0 -80
  620. package/packages/broker-sdk/dist/workflows/trajectory.d.ts.map +0 -1
  621. package/packages/broker-sdk/dist/workflows/trajectory.js +0 -362
  622. package/packages/broker-sdk/dist/workflows/trajectory.js.map +0 -1
  623. package/packages/broker-sdk/dist/workflows/types.d.ts +0 -140
  624. package/packages/broker-sdk/dist/workflows/types.d.ts.map +0 -1
  625. package/packages/broker-sdk/dist/workflows/types.js +0 -8
  626. package/packages/broker-sdk/dist/workflows/types.js.map +0 -1
  627. package/packages/broker-sdk/package.json +0 -81
  628. package/packages/broker-sdk/scripts/bundle-agent-relay.mjs +0 -53
  629. package/packages/broker-sdk/src/__tests__/error-scenarios.test.ts +0 -682
  630. package/packages/broker-sdk/src/__tests__/facade.test.ts +0 -296
  631. package/packages/broker-sdk/src/__tests__/integration.test.ts +0 -170
  632. package/packages/broker-sdk/src/__tests__/quickstart.test.ts +0 -198
  633. package/packages/broker-sdk/src/__tests__/swarm-coordinator.test.ts +0 -772
  634. package/packages/broker-sdk/src/__tests__/unit.test.ts +0 -243
  635. package/packages/broker-sdk/src/__tests__/workflow-runner.test.ts +0 -333
  636. package/packages/broker-sdk/src/client.ts +0 -510
  637. package/packages/broker-sdk/src/index.ts +0 -9
  638. package/packages/broker-sdk/src/logs.ts +0 -163
  639. package/packages/broker-sdk/src/protocol.ts +0 -271
  640. package/packages/broker-sdk/src/pty.ts +0 -16
  641. package/packages/broker-sdk/src/relay.ts +0 -614
  642. package/packages/broker-sdk/src/relaycast.ts +0 -185
  643. package/packages/broker-sdk/src/shadow.ts +0 -230
  644. package/packages/broker-sdk/src/workflows/README.md +0 -514
  645. package/packages/broker-sdk/src/workflows/builder.ts +0 -241
  646. package/packages/broker-sdk/src/workflows/builtin-templates/bug-fix.yaml +0 -75
  647. package/packages/broker-sdk/src/workflows/builtin-templates/code-review.yaml +0 -82
  648. package/packages/broker-sdk/src/workflows/builtin-templates/documentation.yaml +0 -70
  649. package/packages/broker-sdk/src/workflows/builtin-templates/feature-dev.yaml +0 -76
  650. package/packages/broker-sdk/src/workflows/builtin-templates/refactor.yaml +0 -82
  651. package/packages/broker-sdk/src/workflows/builtin-templates/security-audit.yaml +0 -84
  652. package/packages/broker-sdk/src/workflows/cli.ts +0 -93
  653. package/packages/broker-sdk/src/workflows/coordinator.ts +0 -758
  654. package/packages/broker-sdk/src/workflows/index.ts +0 -10
  655. package/packages/broker-sdk/src/workflows/run.ts +0 -55
  656. package/packages/broker-sdk/src/workflows/runner.ts +0 -1184
  657. package/packages/broker-sdk/src/workflows/schema.json +0 -333
  658. package/packages/broker-sdk/src/workflows/templates.ts +0 -544
  659. package/packages/broker-sdk/src/workflows/trajectory.ts +0 -507
  660. package/packages/broker-sdk/src/workflows/types.ts +0 -208
  661. package/packages/broker-sdk/tsconfig.json +0 -22
  662. package/packages/broker-sdk/vitest.config.ts +0 -9
  663. package/packages/continuity/dist/formatter.d.ts +0 -57
  664. package/packages/continuity/dist/formatter.d.ts.map +0 -1
  665. package/packages/continuity/dist/formatter.js +0 -448
  666. package/packages/continuity/dist/formatter.js.map +0 -1
  667. package/packages/continuity/dist/handoff-store.d.ts +0 -67
  668. package/packages/continuity/dist/handoff-store.d.ts.map +0 -1
  669. package/packages/continuity/dist/handoff-store.js +0 -472
  670. package/packages/continuity/dist/handoff-store.js.map +0 -1
  671. package/packages/continuity/dist/index.d.ts +0 -10
  672. package/packages/continuity/dist/index.d.ts.map +0 -1
  673. package/packages/continuity/dist/index.js +0 -11
  674. package/packages/continuity/dist/index.js.map +0 -1
  675. package/packages/continuity/dist/ledger-store.d.ts +0 -110
  676. package/packages/continuity/dist/ledger-store.d.ts.map +0 -1
  677. package/packages/continuity/dist/ledger-store.js +0 -500
  678. package/packages/continuity/dist/ledger-store.js.map +0 -1
  679. package/packages/continuity/dist/manager.d.ts +0 -183
  680. package/packages/continuity/dist/manager.d.ts.map +0 -1
  681. package/packages/continuity/dist/manager.js +0 -616
  682. package/packages/continuity/dist/manager.js.map +0 -1
  683. package/packages/continuity/dist/parser.d.ts +0 -76
  684. package/packages/continuity/dist/parser.d.ts.map +0 -1
  685. package/packages/continuity/dist/parser.js +0 -579
  686. package/packages/continuity/dist/parser.js.map +0 -1
  687. package/packages/continuity/dist/types.d.ts +0 -180
  688. package/packages/continuity/dist/types.d.ts.map +0 -1
  689. package/packages/continuity/dist/types.js +0 -2
  690. package/packages/continuity/dist/types.js.map +0 -1
  691. package/packages/continuity/package.json +0 -40
  692. package/packages/continuity/src/formatter.ts +0 -536
  693. package/packages/continuity/src/handoff-store.ts +0 -523
  694. package/packages/continuity/src/index.ts +0 -12
  695. package/packages/continuity/src/ledger-store.ts +0 -594
  696. package/packages/continuity/src/manager.test.ts +0 -291
  697. package/packages/continuity/src/manager.ts +0 -774
  698. package/packages/continuity/src/parser.test.ts +0 -292
  699. package/packages/continuity/src/parser.ts +0 -680
  700. package/packages/continuity/src/types.ts +0 -211
  701. package/packages/continuity/tsconfig.json +0 -21
  702. package/packages/continuity/vitest.config.ts +0 -9
  703. package/packages/daemon/dist/agent-manager.d.ts +0 -134
  704. package/packages/daemon/dist/agent-manager.d.ts.map +0 -1
  705. package/packages/daemon/dist/agent-manager.js +0 -578
  706. package/packages/daemon/dist/agent-manager.js.map +0 -1
  707. package/packages/daemon/dist/agent-registry.d.ts +0 -99
  708. package/packages/daemon/dist/agent-registry.d.ts.map +0 -1
  709. package/packages/daemon/dist/agent-registry.js +0 -213
  710. package/packages/daemon/dist/agent-registry.js.map +0 -1
  711. package/packages/daemon/dist/agent-signing.d.ts +0 -158
  712. package/packages/daemon/dist/agent-signing.d.ts.map +0 -1
  713. package/packages/daemon/dist/agent-signing.js +0 -523
  714. package/packages/daemon/dist/agent-signing.js.map +0 -1
  715. package/packages/daemon/dist/api.d.ts +0 -106
  716. package/packages/daemon/dist/api.d.ts.map +0 -1
  717. package/packages/daemon/dist/api.js +0 -895
  718. package/packages/daemon/dist/api.js.map +0 -1
  719. package/packages/daemon/dist/auth.d.ts +0 -94
  720. package/packages/daemon/dist/auth.d.ts.map +0 -1
  721. package/packages/daemon/dist/auth.js +0 -197
  722. package/packages/daemon/dist/auth.js.map +0 -1
  723. package/packages/daemon/dist/channel-membership-store.d.ts +0 -55
  724. package/packages/daemon/dist/channel-membership-store.d.ts.map +0 -1
  725. package/packages/daemon/dist/channel-membership-store.js +0 -176
  726. package/packages/daemon/dist/channel-membership-store.js.map +0 -1
  727. package/packages/daemon/dist/cli-auth.d.ts +0 -97
  728. package/packages/daemon/dist/cli-auth.d.ts.map +0 -1
  729. package/packages/daemon/dist/cli-auth.js +0 -808
  730. package/packages/daemon/dist/cli-auth.js.map +0 -1
  731. package/packages/daemon/dist/cloud-sync.d.ts +0 -263
  732. package/packages/daemon/dist/cloud-sync.d.ts.map +0 -1
  733. package/packages/daemon/dist/cloud-sync.js +0 -820
  734. package/packages/daemon/dist/cloud-sync.js.map +0 -1
  735. package/packages/daemon/dist/connection.d.ts +0 -137
  736. package/packages/daemon/dist/connection.d.ts.map +0 -1
  737. package/packages/daemon/dist/connection.js +0 -465
  738. package/packages/daemon/dist/connection.js.map +0 -1
  739. package/packages/daemon/dist/consensus-integration.d.ts +0 -168
  740. package/packages/daemon/dist/consensus-integration.d.ts.map +0 -1
  741. package/packages/daemon/dist/consensus-integration.js +0 -371
  742. package/packages/daemon/dist/consensus-integration.js.map +0 -1
  743. package/packages/daemon/dist/consensus.d.ts +0 -269
  744. package/packages/daemon/dist/consensus.d.ts.map +0 -1
  745. package/packages/daemon/dist/consensus.js +0 -632
  746. package/packages/daemon/dist/consensus.js.map +0 -1
  747. package/packages/daemon/dist/delivery-tracker.d.ts +0 -34
  748. package/packages/daemon/dist/delivery-tracker.d.ts.map +0 -1
  749. package/packages/daemon/dist/delivery-tracker.js +0 -104
  750. package/packages/daemon/dist/delivery-tracker.js.map +0 -1
  751. package/packages/daemon/dist/enhanced-features.d.ts +0 -118
  752. package/packages/daemon/dist/enhanced-features.d.ts.map +0 -1
  753. package/packages/daemon/dist/enhanced-features.js +0 -177
  754. package/packages/daemon/dist/enhanced-features.js.map +0 -1
  755. package/packages/daemon/dist/index.d.ts +0 -29
  756. package/packages/daemon/dist/index.d.ts.map +0 -1
  757. package/packages/daemon/dist/index.js +0 -34
  758. package/packages/daemon/dist/index.js.map +0 -1
  759. package/packages/daemon/dist/orchestrator.d.ts +0 -217
  760. package/packages/daemon/dist/orchestrator.d.ts.map +0 -1
  761. package/packages/daemon/dist/orchestrator.js +0 -1172
  762. package/packages/daemon/dist/orchestrator.js.map +0 -1
  763. package/packages/daemon/dist/rate-limiter.d.ts +0 -68
  764. package/packages/daemon/dist/rate-limiter.d.ts.map +0 -1
  765. package/packages/daemon/dist/rate-limiter.js +0 -130
  766. package/packages/daemon/dist/rate-limiter.js.map +0 -1
  767. package/packages/daemon/dist/registry.d.ts +0 -9
  768. package/packages/daemon/dist/registry.d.ts.map +0 -1
  769. package/packages/daemon/dist/registry.js +0 -9
  770. package/packages/daemon/dist/registry.js.map +0 -1
  771. package/packages/daemon/dist/repo-manager.d.ts +0 -116
  772. package/packages/daemon/dist/repo-manager.d.ts.map +0 -1
  773. package/packages/daemon/dist/repo-manager.js +0 -384
  774. package/packages/daemon/dist/repo-manager.js.map +0 -1
  775. package/packages/daemon/dist/router.d.ts +0 -389
  776. package/packages/daemon/dist/router.d.ts.map +0 -1
  777. package/packages/daemon/dist/router.js +0 -1607
  778. package/packages/daemon/dist/router.js.map +0 -1
  779. package/packages/daemon/dist/server.d.ts +0 -201
  780. package/packages/daemon/dist/server.d.ts.map +0 -1
  781. package/packages/daemon/dist/server.js +0 -1791
  782. package/packages/daemon/dist/server.js.map +0 -1
  783. package/packages/daemon/dist/spawn-manager.d.ts +0 -119
  784. package/packages/daemon/dist/spawn-manager.d.ts.map +0 -1
  785. package/packages/daemon/dist/spawn-manager.js +0 -319
  786. package/packages/daemon/dist/spawn-manager.js.map +0 -1
  787. package/packages/daemon/dist/sync-queue.d.ts +0 -116
  788. package/packages/daemon/dist/sync-queue.d.ts.map +0 -1
  789. package/packages/daemon/dist/sync-queue.js +0 -361
  790. package/packages/daemon/dist/sync-queue.js.map +0 -1
  791. package/packages/daemon/dist/types.d.ts +0 -133
  792. package/packages/daemon/dist/types.d.ts.map +0 -1
  793. package/packages/daemon/dist/types.js +0 -6
  794. package/packages/daemon/dist/types.js.map +0 -1
  795. package/packages/daemon/dist/workspace-manager.d.ts +0 -80
  796. package/packages/daemon/dist/workspace-manager.d.ts.map +0 -1
  797. package/packages/daemon/dist/workspace-manager.js +0 -314
  798. package/packages/daemon/dist/workspace-manager.js.map +0 -1
  799. package/packages/daemon/package.json +0 -56
  800. package/packages/daemon/src/agent-manager.ts +0 -679
  801. package/packages/daemon/src/agent-registry.ts +0 -284
  802. package/packages/daemon/src/agent-signing.ts +0 -707
  803. package/packages/daemon/src/api.ts +0 -1034
  804. package/packages/daemon/src/auth.ts +0 -276
  805. package/packages/daemon/src/channel-membership-store.ts +0 -217
  806. package/packages/daemon/src/cli-auth.ts +0 -945
  807. package/packages/daemon/src/cloud-sync.ts +0 -1100
  808. package/packages/daemon/src/connection.ts +0 -561
  809. package/packages/daemon/src/consensus-integration.ts +0 -510
  810. package/packages/daemon/src/consensus.ts +0 -848
  811. package/packages/daemon/src/delivery-tracker.ts +0 -145
  812. package/packages/daemon/src/enhanced-features.ts +0 -390
  813. package/packages/daemon/src/index.ts +0 -48
  814. package/packages/daemon/src/orchestrator.test.ts +0 -231
  815. package/packages/daemon/src/orchestrator.ts +0 -1376
  816. package/packages/daemon/src/rate-limiter.ts +0 -172
  817. package/packages/daemon/src/registry.ts +0 -8
  818. package/packages/daemon/src/repo-manager.ts +0 -468
  819. package/packages/daemon/src/router.test.ts +0 -181
  820. package/packages/daemon/src/router.ts +0 -1925
  821. package/packages/daemon/src/server.ts +0 -2051
  822. package/packages/daemon/src/spawn-manager-set-model.test.ts +0 -144
  823. package/packages/daemon/src/spawn-manager.ts +0 -415
  824. package/packages/daemon/src/sync-queue.ts +0 -477
  825. package/packages/daemon/src/types.ts +0 -158
  826. package/packages/daemon/src/workspace-manager.ts +0 -371
  827. package/packages/daemon/tsconfig.json +0 -21
  828. package/packages/daemon/vitest.config.ts +0 -9
  829. package/packages/mcp/CHANGELOG.md +0 -28
  830. package/packages/mcp/LICENSE +0 -190
  831. package/packages/mcp/README.md +0 -266
  832. package/packages/mcp/dist/bin.d.ts +0 -12
  833. package/packages/mcp/dist/bin.d.ts.map +0 -1
  834. package/packages/mcp/dist/bin.js +0 -179
  835. package/packages/mcp/dist/bin.js.map +0 -1
  836. package/packages/mcp/dist/client-adapter.d.ts +0 -164
  837. package/packages/mcp/dist/client-adapter.d.ts.map +0 -1
  838. package/packages/mcp/dist/client-adapter.js +0 -231
  839. package/packages/mcp/dist/client-adapter.js.map +0 -1
  840. package/packages/mcp/dist/cloud.d.ts +0 -13
  841. package/packages/mcp/dist/cloud.d.ts.map +0 -1
  842. package/packages/mcp/dist/cloud.js +0 -25
  843. package/packages/mcp/dist/cloud.js.map +0 -1
  844. package/packages/mcp/dist/errors.d.ts +0 -9
  845. package/packages/mcp/dist/errors.d.ts.map +0 -1
  846. package/packages/mcp/dist/errors.js +0 -9
  847. package/packages/mcp/dist/errors.js.map +0 -1
  848. package/packages/mcp/dist/file-transport.d.ts +0 -103
  849. package/packages/mcp/dist/file-transport.d.ts.map +0 -1
  850. package/packages/mcp/dist/file-transport.js +0 -204
  851. package/packages/mcp/dist/file-transport.js.map +0 -1
  852. package/packages/mcp/dist/hybrid-client.d.ts +0 -5
  853. package/packages/mcp/dist/hybrid-client.d.ts.map +0 -1
  854. package/packages/mcp/dist/hybrid-client.js +0 -23
  855. package/packages/mcp/dist/hybrid-client.js.map +0 -1
  856. package/packages/mcp/dist/index.d.ts +0 -11
  857. package/packages/mcp/dist/index.d.ts.map +0 -1
  858. package/packages/mcp/dist/index.js +0 -25
  859. package/packages/mcp/dist/index.js.map +0 -1
  860. package/packages/mcp/dist/install-cli.d.ts +0 -35
  861. package/packages/mcp/dist/install-cli.d.ts.map +0 -1
  862. package/packages/mcp/dist/install-cli.js +0 -157
  863. package/packages/mcp/dist/install-cli.js.map +0 -1
  864. package/packages/mcp/dist/install.d.ts +0 -123
  865. package/packages/mcp/dist/install.d.ts.map +0 -1
  866. package/packages/mcp/dist/install.js +0 -661
  867. package/packages/mcp/dist/install.js.map +0 -1
  868. package/packages/mcp/dist/prompts/index.d.ts +0 -2
  869. package/packages/mcp/dist/prompts/index.d.ts.map +0 -1
  870. package/packages/mcp/dist/prompts/index.js +0 -2
  871. package/packages/mcp/dist/prompts/index.js.map +0 -1
  872. package/packages/mcp/dist/prompts/protocol.d.ts +0 -11
  873. package/packages/mcp/dist/prompts/protocol.d.ts.map +0 -1
  874. package/packages/mcp/dist/prompts/protocol.js +0 -160
  875. package/packages/mcp/dist/prompts/protocol.js.map +0 -1
  876. package/packages/mcp/dist/resources/agents.d.ts +0 -11
  877. package/packages/mcp/dist/resources/agents.d.ts.map +0 -1
  878. package/packages/mcp/dist/resources/agents.js +0 -17
  879. package/packages/mcp/dist/resources/agents.js.map +0 -1
  880. package/packages/mcp/dist/resources/inbox.d.ts +0 -11
  881. package/packages/mcp/dist/resources/inbox.d.ts.map +0 -1
  882. package/packages/mcp/dist/resources/inbox.js +0 -17
  883. package/packages/mcp/dist/resources/inbox.js.map +0 -1
  884. package/packages/mcp/dist/resources/index.d.ts +0 -4
  885. package/packages/mcp/dist/resources/index.d.ts.map +0 -1
  886. package/packages/mcp/dist/resources/index.js +0 -4
  887. package/packages/mcp/dist/resources/index.js.map +0 -1
  888. package/packages/mcp/dist/resources/project.d.ts +0 -11
  889. package/packages/mcp/dist/resources/project.d.ts.map +0 -1
  890. package/packages/mcp/dist/resources/project.js +0 -21
  891. package/packages/mcp/dist/resources/project.js.map +0 -1
  892. package/packages/mcp/dist/server.d.ts +0 -23
  893. package/packages/mcp/dist/server.d.ts.map +0 -1
  894. package/packages/mcp/dist/server.js +0 -317
  895. package/packages/mcp/dist/server.js.map +0 -1
  896. package/packages/mcp/dist/simple.d.ts +0 -170
  897. package/packages/mcp/dist/simple.d.ts.map +0 -1
  898. package/packages/mcp/dist/simple.js +0 -120
  899. package/packages/mcp/dist/simple.js.map +0 -1
  900. package/packages/mcp/dist/tools/index.d.ts +0 -20
  901. package/packages/mcp/dist/tools/index.d.ts.map +0 -1
  902. package/packages/mcp/dist/tools/index.js +0 -20
  903. package/packages/mcp/dist/tools/index.js.map +0 -1
  904. package/packages/mcp/dist/tools/relay-broadcast.d.ts +0 -20
  905. package/packages/mcp/dist/tools/relay-broadcast.d.ts.map +0 -1
  906. package/packages/mcp/dist/tools/relay-broadcast.js +0 -25
  907. package/packages/mcp/dist/tools/relay-broadcast.js.map +0 -1
  908. package/packages/mcp/dist/tools/relay-channel.d.ts +0 -75
  909. package/packages/mcp/dist/tools/relay-channel.d.ts.map +0 -1
  910. package/packages/mcp/dist/tools/relay-channel.js +0 -124
  911. package/packages/mcp/dist/tools/relay-channel.js.map +0 -1
  912. package/packages/mcp/dist/tools/relay-connected.d.ts +0 -17
  913. package/packages/mcp/dist/tools/relay-connected.d.ts.map +0 -1
  914. package/packages/mcp/dist/tools/relay-connected.js +0 -54
  915. package/packages/mcp/dist/tools/relay-connected.js.map +0 -1
  916. package/packages/mcp/dist/tools/relay-consensus.d.ts +0 -45
  917. package/packages/mcp/dist/tools/relay-consensus.d.ts.map +0 -1
  918. package/packages/mcp/dist/tools/relay-consensus.js +0 -80
  919. package/packages/mcp/dist/tools/relay-consensus.js.map +0 -1
  920. package/packages/mcp/dist/tools/relay-continuity.d.ts +0 -35
  921. package/packages/mcp/dist/tools/relay-continuity.d.ts.map +0 -1
  922. package/packages/mcp/dist/tools/relay-continuity.js +0 -101
  923. package/packages/mcp/dist/tools/relay-continuity.js.map +0 -1
  924. package/packages/mcp/dist/tools/relay-health.d.ts +0 -20
  925. package/packages/mcp/dist/tools/relay-health.d.ts.map +0 -1
  926. package/packages/mcp/dist/tools/relay-health.js +0 -130
  927. package/packages/mcp/dist/tools/relay-health.js.map +0 -1
  928. package/packages/mcp/dist/tools/relay-inbox.d.ts +0 -26
  929. package/packages/mcp/dist/tools/relay-inbox.d.ts.map +0 -1
  930. package/packages/mcp/dist/tools/relay-inbox.js +0 -58
  931. package/packages/mcp/dist/tools/relay-inbox.js.map +0 -1
  932. package/packages/mcp/dist/tools/relay-logs.d.ts +0 -20
  933. package/packages/mcp/dist/tools/relay-logs.d.ts.map +0 -1
  934. package/packages/mcp/dist/tools/relay-logs.js +0 -90
  935. package/packages/mcp/dist/tools/relay-logs.js.map +0 -1
  936. package/packages/mcp/dist/tools/relay-messages.d.ts +0 -32
  937. package/packages/mcp/dist/tools/relay-messages.d.ts.map +0 -1
  938. package/packages/mcp/dist/tools/relay-messages.js +0 -61
  939. package/packages/mcp/dist/tools/relay-messages.js.map +0 -1
  940. package/packages/mcp/dist/tools/relay-metrics.d.ts +0 -17
  941. package/packages/mcp/dist/tools/relay-metrics.d.ts.map +0 -1
  942. package/packages/mcp/dist/tools/relay-metrics.js +0 -124
  943. package/packages/mcp/dist/tools/relay-metrics.js.map +0 -1
  944. package/packages/mcp/dist/tools/relay-release.d.ts +0 -20
  945. package/packages/mcp/dist/tools/relay-release.d.ts.map +0 -1
  946. package/packages/mcp/dist/tools/relay-release.js +0 -44
  947. package/packages/mcp/dist/tools/relay-release.js.map +0 -1
  948. package/packages/mcp/dist/tools/relay-remove-agent.d.ts +0 -20
  949. package/packages/mcp/dist/tools/relay-remove-agent.d.ts.map +0 -1
  950. package/packages/mcp/dist/tools/relay-remove-agent.js +0 -50
  951. package/packages/mcp/dist/tools/relay-remove-agent.js.map +0 -1
  952. package/packages/mcp/dist/tools/relay-send.d.ts +0 -29
  953. package/packages/mcp/dist/tools/relay-send.d.ts.map +0 -1
  954. package/packages/mcp/dist/tools/relay-send.js +0 -73
  955. package/packages/mcp/dist/tools/relay-send.js.map +0 -1
  956. package/packages/mcp/dist/tools/relay-set-model.d.ts +0 -23
  957. package/packages/mcp/dist/tools/relay-set-model.d.ts.map +0 -1
  958. package/packages/mcp/dist/tools/relay-set-model.js +0 -52
  959. package/packages/mcp/dist/tools/relay-set-model.js.map +0 -1
  960. package/packages/mcp/dist/tools/relay-shadow.d.ts +0 -30
  961. package/packages/mcp/dist/tools/relay-shadow.d.ts.map +0 -1
  962. package/packages/mcp/dist/tools/relay-shadow.js +0 -55
  963. package/packages/mcp/dist/tools/relay-shadow.js.map +0 -1
  964. package/packages/mcp/dist/tools/relay-spawn.d.ts +0 -36
  965. package/packages/mcp/dist/tools/relay-spawn.d.ts.map +0 -1
  966. package/packages/mcp/dist/tools/relay-spawn.js +0 -73
  967. package/packages/mcp/dist/tools/relay-spawn.js.map +0 -1
  968. package/packages/mcp/dist/tools/relay-status.d.ts +0 -11
  969. package/packages/mcp/dist/tools/relay-status.d.ts.map +0 -1
  970. package/packages/mcp/dist/tools/relay-status.js +0 -43
  971. package/packages/mcp/dist/tools/relay-status.js.map +0 -1
  972. package/packages/mcp/dist/tools/relay-subscribe.d.ts +0 -27
  973. package/packages/mcp/dist/tools/relay-subscribe.d.ts.map +0 -1
  974. package/packages/mcp/dist/tools/relay-subscribe.js +0 -49
  975. package/packages/mcp/dist/tools/relay-subscribe.js.map +0 -1
  976. package/packages/mcp/dist/tools/relay-who.d.ts +0 -20
  977. package/packages/mcp/dist/tools/relay-who.d.ts.map +0 -1
  978. package/packages/mcp/dist/tools/relay-who.js +0 -62
  979. package/packages/mcp/dist/tools/relay-who.js.map +0 -1
  980. package/packages/mcp/package.json +0 -82
  981. package/packages/mcp/src/bin.ts +0 -200
  982. package/packages/mcp/src/client-adapter.ts +0 -358
  983. package/packages/mcp/src/cloud.ts +0 -41
  984. package/packages/mcp/src/errors.ts +0 -17
  985. package/packages/mcp/src/file-transport.ts +0 -275
  986. package/packages/mcp/src/hybrid-client.ts +0 -25
  987. package/packages/mcp/src/index.ts +0 -143
  988. package/packages/mcp/src/install-cli.ts +0 -210
  989. package/packages/mcp/src/install.ts +0 -820
  990. package/packages/mcp/src/prompts/index.ts +0 -1
  991. package/packages/mcp/src/prompts/protocol.ts +0 -164
  992. package/packages/mcp/src/resources/agents.ts +0 -21
  993. package/packages/mcp/src/resources/inbox.ts +0 -21
  994. package/packages/mcp/src/resources/index.ts +0 -3
  995. package/packages/mcp/src/resources/project.ts +0 -29
  996. package/packages/mcp/src/server.ts +0 -475
  997. package/packages/mcp/src/simple.ts +0 -214
  998. package/packages/mcp/src/tools/index.ts +0 -155
  999. package/packages/mcp/src/tools/relay-broadcast.ts +0 -32
  1000. package/packages/mcp/src/tools/relay-channel.ts +0 -151
  1001. package/packages/mcp/src/tools/relay-connected.ts +0 -67
  1002. package/packages/mcp/src/tools/relay-consensus.ts +0 -92
  1003. package/packages/mcp/src/tools/relay-continuity.ts +0 -127
  1004. package/packages/mcp/src/tools/relay-health.ts +0 -148
  1005. package/packages/mcp/src/tools/relay-inbox.ts +0 -70
  1006. package/packages/mcp/src/tools/relay-logs.ts +0 -106
  1007. package/packages/mcp/src/tools/relay-messages.ts +0 -66
  1008. package/packages/mcp/src/tools/relay-metrics.ts +0 -142
  1009. package/packages/mcp/src/tools/relay-release.ts +0 -54
  1010. package/packages/mcp/src/tools/relay-remove-agent.ts +0 -58
  1011. package/packages/mcp/src/tools/relay-send.ts +0 -84
  1012. package/packages/mcp/src/tools/relay-set-model.ts +0 -62
  1013. package/packages/mcp/src/tools/relay-shadow.ts +0 -67
  1014. package/packages/mcp/src/tools/relay-spawn.ts +0 -87
  1015. package/packages/mcp/src/tools/relay-status.ts +0 -57
  1016. package/packages/mcp/src/tools/relay-subscribe.ts +0 -61
  1017. package/packages/mcp/src/tools/relay-who.ts +0 -75
  1018. package/packages/mcp/tests/client.test.ts +0 -451
  1019. package/packages/mcp/tests/discover.test.ts +0 -256
  1020. package/packages/mcp/tests/install.test.ts +0 -123
  1021. package/packages/mcp/tests/prompts.test.ts +0 -12
  1022. package/packages/mcp/tests/resources.test.ts +0 -53
  1023. package/packages/mcp/tests/tools.test.ts +0 -1516
  1024. package/packages/mcp/tsconfig.json +0 -22
  1025. package/packages/mcp/vitest.config.ts +0 -9
  1026. package/packages/protocol/dist/channels.d.ts +0 -137
  1027. package/packages/protocol/dist/channels.d.ts.map +0 -1
  1028. package/packages/protocol/dist/channels.js +0 -154
  1029. package/packages/protocol/dist/channels.js.map +0 -1
  1030. package/packages/protocol/dist/framing.d.ts +0 -80
  1031. package/packages/protocol/dist/framing.d.ts.map +0 -1
  1032. package/packages/protocol/dist/framing.js +0 -206
  1033. package/packages/protocol/dist/framing.js.map +0 -1
  1034. package/packages/protocol/dist/id-generator.d.ts +0 -35
  1035. package/packages/protocol/dist/id-generator.d.ts.map +0 -1
  1036. package/packages/protocol/dist/id-generator.js +0 -60
  1037. package/packages/protocol/dist/id-generator.js.map +0 -1
  1038. package/packages/protocol/dist/index.d.ts +0 -5
  1039. package/packages/protocol/dist/index.d.ts.map +0 -1
  1040. package/packages/protocol/dist/index.js +0 -5
  1041. package/packages/protocol/dist/index.js.map +0 -1
  1042. package/packages/protocol/dist/relay-pty-schemas.d.ts +0 -340
  1043. package/packages/protocol/dist/relay-pty-schemas.d.ts.map +0 -1
  1044. package/packages/protocol/dist/relay-pty-schemas.js +0 -60
  1045. package/packages/protocol/dist/relay-pty-schemas.js.map +0 -1
  1046. package/packages/protocol/dist/types.d.ts +0 -793
  1047. package/packages/protocol/dist/types.d.ts.map +0 -1
  1048. package/packages/protocol/dist/types.js +0 -8
  1049. package/packages/protocol/dist/types.js.map +0 -1
  1050. package/packages/protocol/package.json +0 -61
  1051. package/packages/protocol/src/channels.test.ts +0 -330
  1052. package/packages/protocol/src/channels.ts +0 -270
  1053. package/packages/protocol/src/framing.test.ts +0 -164
  1054. package/packages/protocol/src/framing.ts +0 -242
  1055. package/packages/protocol/src/id-generator.ts +0 -69
  1056. package/packages/protocol/src/index.ts +0 -4
  1057. package/packages/protocol/src/relay-pty-schemas.ts +0 -400
  1058. package/packages/protocol/src/types.test.ts +0 -271
  1059. package/packages/protocol/src/types.ts +0 -988
  1060. package/packages/protocol/tsconfig.json +0 -21
  1061. package/packages/protocol/vitest.config.ts +0 -9
  1062. package/packages/resiliency/dist/cgroup-manager.d.ts +0 -152
  1063. package/packages/resiliency/dist/cgroup-manager.d.ts.map +0 -1
  1064. package/packages/resiliency/dist/cgroup-manager.js +0 -394
  1065. package/packages/resiliency/dist/cgroup-manager.js.map +0 -1
  1066. package/packages/resiliency/dist/context-persistence.d.ts +0 -140
  1067. package/packages/resiliency/dist/context-persistence.d.ts.map +0 -1
  1068. package/packages/resiliency/dist/context-persistence.js +0 -397
  1069. package/packages/resiliency/dist/context-persistence.js.map +0 -1
  1070. package/packages/resiliency/dist/crash-insights.d.ts +0 -156
  1071. package/packages/resiliency/dist/crash-insights.d.ts.map +0 -1
  1072. package/packages/resiliency/dist/crash-insights.js +0 -492
  1073. package/packages/resiliency/dist/crash-insights.js.map +0 -1
  1074. package/packages/resiliency/dist/gossip-health.d.ts +0 -137
  1075. package/packages/resiliency/dist/gossip-health.d.ts.map +0 -1
  1076. package/packages/resiliency/dist/gossip-health.js +0 -241
  1077. package/packages/resiliency/dist/gossip-health.js.map +0 -1
  1078. package/packages/resiliency/dist/health-monitor.d.ts +0 -97
  1079. package/packages/resiliency/dist/health-monitor.d.ts.map +0 -1
  1080. package/packages/resiliency/dist/health-monitor.js +0 -291
  1081. package/packages/resiliency/dist/health-monitor.js.map +0 -1
  1082. package/packages/resiliency/dist/index.d.ts +0 -69
  1083. package/packages/resiliency/dist/index.d.ts.map +0 -1
  1084. package/packages/resiliency/dist/index.js +0 -69
  1085. package/packages/resiliency/dist/index.js.map +0 -1
  1086. package/packages/resiliency/dist/leader-watchdog.d.ts +0 -109
  1087. package/packages/resiliency/dist/leader-watchdog.d.ts.map +0 -1
  1088. package/packages/resiliency/dist/leader-watchdog.js +0 -189
  1089. package/packages/resiliency/dist/leader-watchdog.js.map +0 -1
  1090. package/packages/resiliency/dist/logger.d.ts +0 -114
  1091. package/packages/resiliency/dist/logger.d.ts.map +0 -1
  1092. package/packages/resiliency/dist/logger.js +0 -250
  1093. package/packages/resiliency/dist/logger.js.map +0 -1
  1094. package/packages/resiliency/dist/memory-monitor.d.ts +0 -172
  1095. package/packages/resiliency/dist/memory-monitor.d.ts.map +0 -1
  1096. package/packages/resiliency/dist/memory-monitor.js +0 -599
  1097. package/packages/resiliency/dist/memory-monitor.js.map +0 -1
  1098. package/packages/resiliency/dist/metrics.d.ts +0 -115
  1099. package/packages/resiliency/dist/metrics.d.ts.map +0 -1
  1100. package/packages/resiliency/dist/metrics.js +0 -239
  1101. package/packages/resiliency/dist/metrics.js.map +0 -1
  1102. package/packages/resiliency/dist/provider-context.d.ts +0 -100
  1103. package/packages/resiliency/dist/provider-context.d.ts.map +0 -1
  1104. package/packages/resiliency/dist/provider-context.js +0 -362
  1105. package/packages/resiliency/dist/provider-context.js.map +0 -1
  1106. package/packages/resiliency/dist/stateless-lead.d.ts +0 -149
  1107. package/packages/resiliency/dist/stateless-lead.d.ts.map +0 -1
  1108. package/packages/resiliency/dist/stateless-lead.js +0 -308
  1109. package/packages/resiliency/dist/stateless-lead.js.map +0 -1
  1110. package/packages/resiliency/dist/supervisor.d.ts +0 -147
  1111. package/packages/resiliency/dist/supervisor.d.ts.map +0 -1
  1112. package/packages/resiliency/dist/supervisor.js +0 -459
  1113. package/packages/resiliency/dist/supervisor.js.map +0 -1
  1114. package/packages/resiliency/package.json +0 -38
  1115. package/packages/resiliency/src/cgroup-manager.ts +0 -468
  1116. package/packages/resiliency/src/context-persistence.ts +0 -538
  1117. package/packages/resiliency/src/crash-insights.test.ts +0 -620
  1118. package/packages/resiliency/src/crash-insights.ts +0 -660
  1119. package/packages/resiliency/src/gossip-health.ts +0 -333
  1120. package/packages/resiliency/src/health-monitor.ts +0 -371
  1121. package/packages/resiliency/src/index.ts +0 -157
  1122. package/packages/resiliency/src/leader-watchdog.ts +0 -260
  1123. package/packages/resiliency/src/logger.ts +0 -320
  1124. package/packages/resiliency/src/memory-monitor.test.ts +0 -637
  1125. package/packages/resiliency/src/memory-monitor.ts +0 -740
  1126. package/packages/resiliency/src/metrics.ts +0 -311
  1127. package/packages/resiliency/src/provider-context.ts +0 -452
  1128. package/packages/resiliency/src/stateless-lead.ts +0 -408
  1129. package/packages/resiliency/src/supervisor.ts +0 -578
  1130. package/packages/resiliency/tsconfig.json +0 -21
  1131. package/packages/resiliency/vitest.config.ts +0 -9
  1132. package/packages/sdk/dist/discovery.d.ts +0 -10
  1133. package/packages/sdk/dist/discovery.d.ts.map +0 -1
  1134. package/packages/sdk/dist/discovery.js +0 -22
  1135. package/packages/sdk/dist/discovery.js.map +0 -1
  1136. package/packages/sdk/dist/errors.d.ts +0 -9
  1137. package/packages/sdk/dist/errors.d.ts.map +0 -1
  1138. package/packages/sdk/dist/errors.js +0 -9
  1139. package/packages/sdk/dist/errors.js.map +0 -1
  1140. package/packages/sdk/dist/protocol/index.d.ts +0 -8
  1141. package/packages/sdk/dist/protocol/index.d.ts.map +0 -1
  1142. package/packages/sdk/dist/protocol/index.js +0 -8
  1143. package/packages/sdk/dist/protocol/index.js.map +0 -1
  1144. package/packages/sdk/examples/SWARM_CAPABILITIES.md +0 -498
  1145. package/packages/sdk/examples/SWARM_PATTERNS.md +0 -541
  1146. package/packages/sdk/src/client.test.ts +0 -1041
  1147. package/packages/sdk/src/discovery.ts +0 -38
  1148. package/packages/sdk/src/errors.ts +0 -17
  1149. package/packages/sdk/src/logs.test.ts +0 -98
  1150. package/packages/sdk/src/protocol/framing.test.ts +0 -164
  1151. package/packages/sdk/src/protocol/index.ts +0 -8
  1152. package/packages/spawner/.trajectories/index.json +0 -5
  1153. package/packages/spawner/API.md +0 -256
  1154. package/packages/spawner/dist/index.d.ts +0 -8
  1155. package/packages/spawner/dist/index.d.ts.map +0 -1
  1156. package/packages/spawner/dist/index.js +0 -8
  1157. package/packages/spawner/dist/index.js.map +0 -1
  1158. package/packages/spawner/dist/types.d.ts +0 -552
  1159. package/packages/spawner/dist/types.d.ts.map +0 -1
  1160. package/packages/spawner/dist/types.js +0 -193
  1161. package/packages/spawner/dist/types.js.map +0 -1
  1162. package/packages/spawner/package.json +0 -47
  1163. package/packages/spawner/src/index.ts +0 -8
  1164. package/packages/spawner/src/types.test.ts +0 -385
  1165. package/packages/spawner/src/types.ts +0 -228
  1166. package/packages/spawner/tsconfig.json +0 -19
  1167. package/packages/spawner/vitest.config.ts +0 -9
  1168. package/packages/state/dist/agent-state.d.ts +0 -40
  1169. package/packages/state/dist/agent-state.d.ts.map +0 -1
  1170. package/packages/state/dist/agent-state.js +0 -120
  1171. package/packages/state/dist/agent-state.js.map +0 -1
  1172. package/packages/state/dist/index.d.ts +0 -8
  1173. package/packages/state/dist/index.d.ts.map +0 -1
  1174. package/packages/state/dist/index.js +0 -8
  1175. package/packages/state/dist/index.js.map +0 -1
  1176. package/packages/state/package.json +0 -37
  1177. package/packages/state/src/agent-state.test.ts +0 -335
  1178. package/packages/state/src/agent-state.ts +0 -153
  1179. package/packages/state/src/index.ts +0 -12
  1180. package/packages/state/tsconfig.json +0 -21
  1181. package/packages/state/vitest.config.ts +0 -9
  1182. package/packages/storage/dist/adapter.d.ts +0 -189
  1183. package/packages/storage/dist/adapter.d.ts.map +0 -1
  1184. package/packages/storage/dist/adapter.js +0 -267
  1185. package/packages/storage/dist/adapter.js.map +0 -1
  1186. package/packages/storage/dist/batched-sqlite-adapter.d.ts +0 -75
  1187. package/packages/storage/dist/batched-sqlite-adapter.d.ts.map +0 -1
  1188. package/packages/storage/dist/batched-sqlite-adapter.js +0 -189
  1189. package/packages/storage/dist/batched-sqlite-adapter.js.map +0 -1
  1190. package/packages/storage/dist/dead-letter-queue.d.ts +0 -196
  1191. package/packages/storage/dist/dead-letter-queue.d.ts.map +0 -1
  1192. package/packages/storage/dist/dead-letter-queue.js +0 -427
  1193. package/packages/storage/dist/dead-letter-queue.js.map +0 -1
  1194. package/packages/storage/dist/dlq-adapter.d.ts +0 -195
  1195. package/packages/storage/dist/dlq-adapter.d.ts.map +0 -1
  1196. package/packages/storage/dist/dlq-adapter.js +0 -664
  1197. package/packages/storage/dist/dlq-adapter.js.map +0 -1
  1198. package/packages/storage/dist/index.d.ts +0 -6
  1199. package/packages/storage/dist/index.d.ts.map +0 -1
  1200. package/packages/storage/dist/index.js +0 -7
  1201. package/packages/storage/dist/index.js.map +0 -1
  1202. package/packages/storage/dist/jsonl-adapter.d.ts +0 -91
  1203. package/packages/storage/dist/jsonl-adapter.d.ts.map +0 -1
  1204. package/packages/storage/dist/jsonl-adapter.js +0 -580
  1205. package/packages/storage/dist/jsonl-adapter.js.map +0 -1
  1206. package/packages/storage/dist/sqlite-adapter.d.ts +0 -131
  1207. package/packages/storage/dist/sqlite-adapter.d.ts.map +0 -1
  1208. package/packages/storage/dist/sqlite-adapter.js +0 -865
  1209. package/packages/storage/dist/sqlite-adapter.js.map +0 -1
  1210. package/packages/storage/package.json +0 -74
  1211. package/packages/storage/src/adapter.ts +0 -446
  1212. package/packages/storage/src/batched-sqlite-adapter.test.ts +0 -256
  1213. package/packages/storage/src/batched-sqlite-adapter.ts +0 -239
  1214. package/packages/storage/src/dead-letter-queue.ts +0 -643
  1215. package/packages/storage/src/dlq-adapter.test.ts +0 -509
  1216. package/packages/storage/src/dlq-adapter.ts +0 -954
  1217. package/packages/storage/src/index.ts +0 -6
  1218. package/packages/storage/src/jsonl-adapter.test.ts +0 -239
  1219. package/packages/storage/src/jsonl-adapter.ts +0 -704
  1220. package/packages/storage/src/memory-adapter.test.ts +0 -36
  1221. package/packages/storage/src/sqlite-adapter.test.ts +0 -580
  1222. package/packages/storage/src/sqlite-adapter.ts +0 -1099
  1223. package/packages/storage/tsconfig.json +0 -21
  1224. package/packages/storage/vitest.config.ts +0 -9
  1225. package/packages/wrapper/dist/__fixtures__/claude-outputs.d.ts +0 -49
  1226. package/packages/wrapper/dist/__fixtures__/claude-outputs.d.ts.map +0 -1
  1227. package/packages/wrapper/dist/__fixtures__/claude-outputs.js +0 -443
  1228. package/packages/wrapper/dist/__fixtures__/claude-outputs.js.map +0 -1
  1229. package/packages/wrapper/dist/__fixtures__/codex-outputs.d.ts +0 -9
  1230. package/packages/wrapper/dist/__fixtures__/codex-outputs.d.ts.map +0 -1
  1231. package/packages/wrapper/dist/__fixtures__/codex-outputs.js +0 -94
  1232. package/packages/wrapper/dist/__fixtures__/codex-outputs.js.map +0 -1
  1233. package/packages/wrapper/dist/__fixtures__/gemini-outputs.d.ts +0 -19
  1234. package/packages/wrapper/dist/__fixtures__/gemini-outputs.d.ts.map +0 -1
  1235. package/packages/wrapper/dist/__fixtures__/gemini-outputs.js +0 -144
  1236. package/packages/wrapper/dist/__fixtures__/gemini-outputs.js.map +0 -1
  1237. package/packages/wrapper/dist/__fixtures__/index.d.ts +0 -68
  1238. package/packages/wrapper/dist/__fixtures__/index.d.ts.map +0 -1
  1239. package/packages/wrapper/dist/__fixtures__/index.js +0 -44
  1240. package/packages/wrapper/dist/__fixtures__/index.js.map +0 -1
  1241. package/packages/wrapper/dist/auth-detection.d.ts +0 -49
  1242. package/packages/wrapper/dist/auth-detection.d.ts.map +0 -1
  1243. package/packages/wrapper/dist/auth-detection.js +0 -199
  1244. package/packages/wrapper/dist/auth-detection.js.map +0 -1
  1245. package/packages/wrapper/dist/base-wrapper.d.ts +0 -254
  1246. package/packages/wrapper/dist/base-wrapper.d.ts.map +0 -1
  1247. package/packages/wrapper/dist/base-wrapper.js +0 -664
  1248. package/packages/wrapper/dist/base-wrapper.js.map +0 -1
  1249. package/packages/wrapper/dist/client.d.ts +0 -291
  1250. package/packages/wrapper/dist/client.d.ts.map +0 -1
  1251. package/packages/wrapper/dist/client.js +0 -926
  1252. package/packages/wrapper/dist/client.js.map +0 -1
  1253. package/packages/wrapper/dist/id-generator.d.ts +0 -35
  1254. package/packages/wrapper/dist/id-generator.d.ts.map +0 -1
  1255. package/packages/wrapper/dist/id-generator.js +0 -60
  1256. package/packages/wrapper/dist/id-generator.js.map +0 -1
  1257. package/packages/wrapper/dist/idle-detector.d.ts +0 -114
  1258. package/packages/wrapper/dist/idle-detector.d.ts.map +0 -1
  1259. package/packages/wrapper/dist/idle-detector.js +0 -317
  1260. package/packages/wrapper/dist/idle-detector.js.map +0 -1
  1261. package/packages/wrapper/dist/inbox.d.ts +0 -37
  1262. package/packages/wrapper/dist/inbox.d.ts.map +0 -1
  1263. package/packages/wrapper/dist/inbox.js +0 -73
  1264. package/packages/wrapper/dist/inbox.js.map +0 -1
  1265. package/packages/wrapper/dist/index.d.ts +0 -40
  1266. package/packages/wrapper/dist/index.d.ts.map +0 -1
  1267. package/packages/wrapper/dist/index.js +0 -53
  1268. package/packages/wrapper/dist/index.js.map +0 -1
  1269. package/packages/wrapper/dist/opencode-api.d.ts +0 -106
  1270. package/packages/wrapper/dist/opencode-api.d.ts.map +0 -1
  1271. package/packages/wrapper/dist/opencode-api.js +0 -219
  1272. package/packages/wrapper/dist/opencode-api.js.map +0 -1
  1273. package/packages/wrapper/dist/opencode-wrapper.d.ts +0 -161
  1274. package/packages/wrapper/dist/opencode-wrapper.d.ts.map +0 -1
  1275. package/packages/wrapper/dist/opencode-wrapper.js +0 -438
  1276. package/packages/wrapper/dist/opencode-wrapper.js.map +0 -1
  1277. package/packages/wrapper/dist/parser.d.ts +0 -236
  1278. package/packages/wrapper/dist/parser.d.ts.map +0 -1
  1279. package/packages/wrapper/dist/parser.js +0 -1238
  1280. package/packages/wrapper/dist/parser.js.map +0 -1
  1281. package/packages/wrapper/dist/prompt-composer.d.ts +0 -67
  1282. package/packages/wrapper/dist/prompt-composer.d.ts.map +0 -1
  1283. package/packages/wrapper/dist/prompt-composer.js +0 -168
  1284. package/packages/wrapper/dist/prompt-composer.js.map +0 -1
  1285. package/packages/wrapper/dist/relay-pty-orchestrator.d.ts +0 -486
  1286. package/packages/wrapper/dist/relay-pty-orchestrator.d.ts.map +0 -1
  1287. package/packages/wrapper/dist/relay-pty-orchestrator.js +0 -2550
  1288. package/packages/wrapper/dist/relay-pty-orchestrator.js.map +0 -1
  1289. package/packages/wrapper/dist/shared.d.ts +0 -262
  1290. package/packages/wrapper/dist/shared.d.ts.map +0 -1
  1291. package/packages/wrapper/dist/shared.js +0 -507
  1292. package/packages/wrapper/dist/shared.js.map +0 -1
  1293. package/packages/wrapper/dist/stuck-detector.d.ts +0 -161
  1294. package/packages/wrapper/dist/stuck-detector.d.ts.map +0 -1
  1295. package/packages/wrapper/dist/stuck-detector.js +0 -402
  1296. package/packages/wrapper/dist/stuck-detector.js.map +0 -1
  1297. package/packages/wrapper/dist/tmux-resolver.d.ts +0 -55
  1298. package/packages/wrapper/dist/tmux-resolver.d.ts.map +0 -1
  1299. package/packages/wrapper/dist/tmux-resolver.js +0 -175
  1300. package/packages/wrapper/dist/tmux-resolver.js.map +0 -1
  1301. package/packages/wrapper/dist/tmux-wrapper.d.ts +0 -352
  1302. package/packages/wrapper/dist/tmux-wrapper.d.ts.map +0 -1
  1303. package/packages/wrapper/dist/tmux-wrapper.js +0 -1816
  1304. package/packages/wrapper/dist/tmux-wrapper.js.map +0 -1
  1305. package/packages/wrapper/dist/trajectory-integration.d.ts +0 -292
  1306. package/packages/wrapper/dist/trajectory-integration.d.ts.map +0 -1
  1307. package/packages/wrapper/dist/trajectory-integration.js +0 -979
  1308. package/packages/wrapper/dist/trajectory-integration.js.map +0 -1
  1309. package/packages/wrapper/dist/wrapper-events.d.ts +0 -489
  1310. package/packages/wrapper/dist/wrapper-events.d.ts.map +0 -1
  1311. package/packages/wrapper/dist/wrapper-events.js +0 -252
  1312. package/packages/wrapper/dist/wrapper-events.js.map +0 -1
  1313. package/packages/wrapper/dist/wrapper-types.d.ts +0 -41
  1314. package/packages/wrapper/dist/wrapper-types.d.ts.map +0 -1
  1315. package/packages/wrapper/dist/wrapper-types.js +0 -7
  1316. package/packages/wrapper/dist/wrapper-types.js.map +0 -1
  1317. package/packages/wrapper/package.json +0 -60
  1318. package/packages/wrapper/src/__fixtures__/claude-outputs.ts +0 -471
  1319. package/packages/wrapper/src/__fixtures__/codex-outputs.ts +0 -99
  1320. package/packages/wrapper/src/__fixtures__/gemini-outputs.ts +0 -151
  1321. package/packages/wrapper/src/__fixtures__/index.ts +0 -47
  1322. package/packages/wrapper/src/auth-detection.ts +0 -244
  1323. package/packages/wrapper/src/base-wrapper.test.ts +0 -589
  1324. package/packages/wrapper/src/base-wrapper.ts +0 -841
  1325. package/packages/wrapper/src/client.test.ts +0 -351
  1326. package/packages/wrapper/src/client.ts +0 -1166
  1327. package/packages/wrapper/src/id-generator.test.ts +0 -71
  1328. package/packages/wrapper/src/id-generator.ts +0 -69
  1329. package/packages/wrapper/src/idle-detector.test.ts +0 -418
  1330. package/packages/wrapper/src/idle-detector.ts +0 -384
  1331. package/packages/wrapper/src/inbox.test.ts +0 -233
  1332. package/packages/wrapper/src/inbox.ts +0 -89
  1333. package/packages/wrapper/src/index.ts +0 -199
  1334. package/packages/wrapper/src/opencode-api.test.ts +0 -292
  1335. package/packages/wrapper/src/opencode-api.ts +0 -285
  1336. package/packages/wrapper/src/opencode-wrapper.ts +0 -541
  1337. package/packages/wrapper/src/parser.regression.test.ts +0 -251
  1338. package/packages/wrapper/src/parser.test.ts +0 -1359
  1339. package/packages/wrapper/src/parser.ts +0 -1477
  1340. package/packages/wrapper/src/prompt-composer.test.ts +0 -219
  1341. package/packages/wrapper/src/prompt-composer.ts +0 -231
  1342. package/packages/wrapper/src/relay-pty-orchestrator.test.ts +0 -1386
  1343. package/packages/wrapper/src/relay-pty-orchestrator.ts +0 -3041
  1344. package/packages/wrapper/src/shared.test.ts +0 -467
  1345. package/packages/wrapper/src/shared.ts +0 -652
  1346. package/packages/wrapper/src/stuck-detector.test.ts +0 -303
  1347. package/packages/wrapper/src/stuck-detector.ts +0 -511
  1348. package/packages/wrapper/src/tmux-resolver.test.ts +0 -104
  1349. package/packages/wrapper/src/tmux-resolver.ts +0 -207
  1350. package/packages/wrapper/src/tmux-wrapper.test.ts +0 -316
  1351. package/packages/wrapper/src/tmux-wrapper.ts +0 -2095
  1352. package/packages/wrapper/src/trajectory-detection.test.ts +0 -151
  1353. package/packages/wrapper/src/trajectory-integration.ts +0 -1261
  1354. package/packages/wrapper/src/wrapper-events.ts +0 -395
  1355. package/packages/wrapper/src/wrapper-types.ts +0 -45
  1356. package/packages/wrapper/tsconfig.json +0 -19
  1357. package/packages/wrapper/vitest.config.ts +0 -9
  1358. /package/packages/{broker-sdk → sdk}/dist/__tests__/facade.test.d.ts +0 -0
  1359. /package/packages/{broker-sdk → sdk}/dist/__tests__/facade.test.d.ts.map +0 -0
  1360. /package/packages/{broker-sdk → sdk}/dist/__tests__/integration.test.d.ts +0 -0
  1361. /package/packages/{broker-sdk → sdk}/dist/__tests__/integration.test.d.ts.map +0 -0
  1362. /package/packages/{broker-sdk → sdk}/dist/__tests__/quickstart.test.d.ts +0 -0
  1363. /package/packages/{broker-sdk → sdk}/dist/__tests__/quickstart.test.d.ts.map +0 -0
  1364. /package/packages/{broker-sdk → sdk}/dist/__tests__/unit.test.d.ts +0 -0
  1365. /package/packages/{broker-sdk → sdk}/dist/__tests__/unit.test.d.ts.map +0 -0
  1366. /package/packages/{broker-sdk → sdk}/dist/browser.d.ts +0 -0
  1367. /package/packages/{broker-sdk → sdk}/dist/browser.d.ts.map +0 -0
  1368. /package/packages/{broker-sdk → sdk}/dist/browser.js +0 -0
  1369. /package/packages/{broker-sdk → sdk}/dist/browser.js.map +0 -0
  1370. /package/packages/{broker-sdk → sdk}/dist/consensus-helpers.d.ts +0 -0
  1371. /package/packages/{broker-sdk → sdk}/dist/consensus-helpers.d.ts.map +0 -0
  1372. /package/packages/{broker-sdk → sdk}/dist/consensus-helpers.js +0 -0
  1373. /package/packages/{broker-sdk → sdk}/dist/consensus-helpers.js.map +0 -0
  1374. /package/packages/{broker-sdk → sdk}/dist/consensus.d.ts +0 -0
  1375. /package/packages/{broker-sdk → sdk}/dist/consensus.d.ts.map +0 -0
  1376. /package/packages/{broker-sdk → sdk}/dist/consensus.js +0 -0
  1377. /package/packages/{broker-sdk → sdk}/dist/consensus.js.map +0 -0
  1378. /package/packages/{broker-sdk → sdk}/dist/examples/demo.d.ts +0 -0
  1379. /package/packages/{broker-sdk → sdk}/dist/examples/demo.d.ts.map +0 -0
  1380. /package/packages/{broker-sdk → sdk}/dist/examples/demo.js +0 -0
  1381. /package/packages/{broker-sdk → sdk}/dist/examples/demo.js.map +0 -0
  1382. /package/packages/{broker-sdk → sdk}/dist/examples/example.d.ts +0 -0
  1383. /package/packages/{broker-sdk → sdk}/dist/examples/example.d.ts.map +0 -0
  1384. /package/packages/{broker-sdk → sdk}/dist/examples/example.js +0 -0
  1385. /package/packages/{broker-sdk → sdk}/dist/examples/example.js.map +0 -0
  1386. /package/packages/{broker-sdk → sdk}/dist/examples/quickstart.d.ts +0 -0
  1387. /package/packages/{broker-sdk → sdk}/dist/examples/quickstart.d.ts.map +0 -0
  1388. /package/packages/{broker-sdk → sdk}/dist/examples/quickstart.js +0 -0
  1389. /package/packages/{broker-sdk → sdk}/dist/examples/quickstart.js.map +0 -0
  1390. /package/packages/{broker-sdk → sdk}/dist/examples/ralph-loop.d.ts +0 -0
  1391. /package/packages/{broker-sdk → sdk}/dist/examples/ralph-loop.d.ts.map +0 -0
  1392. /package/packages/{broker-sdk → sdk}/dist/examples/ralph-loop.js +0 -0
  1393. /package/packages/{broker-sdk → sdk}/dist/examples/ralph-loop.js.map +0 -0
  1394. /package/packages/{broker-sdk → sdk}/dist/protocol.js +0 -0
  1395. /package/packages/{broker-sdk → sdk}/dist/protocol.js.map +0 -0
  1396. /package/packages/{broker-sdk → sdk}/dist/pty.d.ts +0 -0
  1397. /package/packages/{broker-sdk → sdk}/dist/shadow.js +0 -0
  1398. /package/packages/{broker-sdk → sdk}/dist/workflows/barrier.d.ts +0 -0
  1399. /package/packages/{broker-sdk → sdk}/dist/workflows/barrier.d.ts.map +0 -0
  1400. /package/packages/{broker-sdk → sdk}/dist/workflows/barrier.js +0 -0
  1401. /package/packages/{broker-sdk → sdk}/dist/workflows/barrier.js.map +0 -0
  1402. /package/packages/{broker-sdk → sdk}/dist/workflows/memory-db.d.ts +0 -0
  1403. /package/packages/{broker-sdk → sdk}/dist/workflows/memory-db.d.ts.map +0 -0
  1404. /package/packages/{broker-sdk → sdk}/dist/workflows/memory-db.js +0 -0
  1405. /package/packages/{broker-sdk → sdk}/dist/workflows/memory-db.js.map +0 -0
  1406. /package/packages/{broker-sdk → sdk}/dist/workflows/state.d.ts +0 -0
  1407. /package/packages/{broker-sdk → sdk}/dist/workflows/state.d.ts.map +0 -0
  1408. /package/packages/{broker-sdk → sdk}/dist/workflows/state.js +0 -0
  1409. /package/packages/{broker-sdk → sdk}/dist/workflows/state.js.map +0 -0
  1410. /package/packages/{broker-sdk → sdk}/src/__tests__/workflow-trajectory.test.ts +0 -0
  1411. /package/packages/{broker-sdk → sdk}/src/browser.ts +0 -0
  1412. /package/packages/{broker-sdk → sdk}/src/consensus-helpers.ts +0 -0
  1413. /package/packages/{broker-sdk → sdk}/src/consensus.ts +0 -0
  1414. /package/packages/{broker-sdk → sdk}/src/examples/demo.ts +0 -0
  1415. /package/packages/{broker-sdk → sdk}/src/examples/example.ts +0 -0
  1416. /package/packages/{broker-sdk → sdk}/src/examples/quickstart.ts +0 -0
  1417. /package/packages/{broker-sdk → sdk}/src/examples/ralph-loop.ts +0 -0
  1418. /package/packages/{broker-sdk → sdk}/src/examples/sample-prd.json +0 -0
  1419. /package/packages/{broker-sdk → sdk}/src/workflows/barrier.ts +0 -0
  1420. /package/packages/{broker-sdk → sdk}/src/workflows/memory-db.ts +0 -0
  1421. /package/packages/{broker-sdk → sdk}/src/workflows/state.ts +0 -0
@@ -1,2071 +1,673 @@
1
- /**
2
- * RelayClient - Agent Relay SDK Client
3
- * @agent-relay/sdk
4
- *
5
- * Lightweight client for agent-to-agent communication via Agent Relay daemon.
6
- */
7
-
8
- import net from 'node:net';
9
- import { randomUUID } from 'node:crypto';
10
- import { discoverSocket } from '@agent-relay/utils/discovery';
11
- import { DaemonNotRunningError, ConnectionError } from '@agent-relay/utils/errors';
12
- // Import shared protocol types and framing utilities from @agent-relay/protocol
1
+ import { once } from 'node:events';
2
+ import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process';
3
+ import { createInterface, type Interface as ReadlineInterface } from 'node:readline';
4
+ import fs from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
13
9
  import {
14
- type Envelope,
15
- type HelloPayload,
16
- type WelcomePayload,
17
- type SendPayload,
18
- type SendMeta,
19
- type SendEnvelope,
20
- type DeliverEnvelope,
21
- type AckPayload,
22
- type ErrorPayload,
23
- type PayloadKind,
24
- type LogPayload,
25
- type SpeakOnTrigger,
26
- type EntityType,
27
- type ChannelMessagePayload,
28
- type ChannelJoinEnvelope,
29
- type ChannelLeaveEnvelope,
30
- type ChannelMessageEnvelope,
31
- type MessageAttachment,
32
- type SpawnPayload,
33
- type SpawnResultPayload,
34
- type ReleasePayload,
35
- type ReleaseResultPayload,
36
- type SendInputPayload,
37
- type SendInputResultPayload,
38
- type SetModelPayload,
39
- type SetModelResultPayload,
40
- type SetModelEnvelope,
41
- type ListWorkersPayload,
42
- type ListWorkersResultPayload,
43
- type SpawnEnvelope,
44
- type ReleaseEnvelope,
45
- type SendInputEnvelope,
46
- type ListWorkersEnvelope,
47
- type StatusResponsePayload,
48
- type InboxPayload,
49
- type InboxMessage,
50
- type InboxResponsePayload,
51
- type MessagesQueryPayload,
52
- type MessagesResponsePayload,
53
- type ListAgentsPayload,
54
- type AgentInfo,
55
- type ListAgentsResponsePayload,
56
- type ListConnectedAgentsPayload,
57
- type ListConnectedAgentsResponsePayload,
58
- type RemoveAgentPayload,
59
- type RemoveAgentResponsePayload,
60
- type HealthPayload,
61
- type HealthResponsePayload,
62
- type MetricsPayload,
63
- type MetricsResponsePayload,
64
- type CreateProposalOptions,
65
- type VoteOptions,
66
- type AgentReadyPayload,
67
10
  PROTOCOL_VERSION,
68
- encodeFrameLegacy,
69
- FrameParser,
70
- } from '@agent-relay/protocol';
71
-
72
- export type ClientState = 'DISCONNECTED' | 'CONNECTING' | 'HANDSHAKING' | 'READY' | 'BACKOFF';
73
-
74
- export interface SyncOptions {
75
- timeoutMs?: number;
76
- kind?: PayloadKind;
77
- data?: Record<string, unknown>;
78
- thread?: string;
11
+ type AgentRuntime,
12
+ type AgentSpec,
13
+ type BrokerEvent,
14
+ type BrokerStats,
15
+ type BrokerStatus,
16
+ type CrashInsightsResponse,
17
+ type ProtocolEnvelope,
18
+ type ProtocolError,
19
+ type RestartPolicy,
20
+ } from './protocol.js';
21
+
22
+ export interface AgentRelayClientOptions {
23
+ binaryPath?: string;
24
+ binaryArgs?: string[];
25
+ brokerName?: string;
26
+ channels?: string[];
27
+ cwd?: string;
28
+ env?: NodeJS.ProcessEnv;
29
+ requestTimeoutMs?: number;
30
+ shutdownTimeoutMs?: number;
31
+ clientName?: string;
32
+ clientVersion?: string;
79
33
  }
80
34
 
81
- /**
82
- * Options for the request() method.
83
- */
84
- export interface RequestOptions {
85
- /** Timeout in milliseconds (default: 30000) */
86
- timeout?: number;
87
- /** Optional structured data to include with the request */
88
- data?: Record<string, unknown>;
89
- /** Optional thread identifier for grouping related messages */
90
- thread?: string;
91
- /** Message kind (default: 'message') */
92
- kind?: PayloadKind;
35
+ export interface SpawnPtyInput {
36
+ name: string;
37
+ cli: string;
38
+ args?: string[];
39
+ channels?: string[];
40
+ task?: string;
41
+ model?: string;
42
+ cwd?: string;
43
+ team?: string;
44
+ shadowOf?: string;
45
+ shadowMode?: string;
46
+ /** Silence duration in seconds before emitting agent_idle (0 = disabled, default: 30). */
47
+ idleThresholdSecs?: number;
48
+ /** Auto-restart policy for crashed agents. */
49
+ restartPolicy?: RestartPolicy;
50
+ /** Name of a previously released agent whose continuity context should be injected. */
51
+ continueFrom?: string;
93
52
  }
94
53
 
95
- /**
96
- * Response from the request() method.
97
- */
98
- export interface RequestResponse {
99
- /** Sender of the response */
100
- from: string;
101
- /** Response body text */
102
- body: string;
103
- /** Optional structured data from the response */
104
- data?: Record<string, unknown>;
105
- /** The correlation ID used for this request/response */
106
- correlationId: string;
107
- /** Thread identifier if set */
108
- thread?: string;
109
- /** The full payload for advanced use cases */
110
- payload: SendPayload;
54
+ export interface SpawnHeadlessClaudeInput {
55
+ name: string;
56
+ args?: string[];
57
+ channels?: string[];
58
+ task?: string;
111
59
  }
112
60
 
113
- /**
114
- * Extended spawn result with optional readiness information.
115
- * When `waitForReady` is true, the spawn will wait for the agent to complete
116
- * its HELLO/WELCOME handshake before resolving.
117
- */
118
- export interface SpawnResult extends SpawnResultPayload {
119
- /** Whether the agent is ready to receive messages (only set when waitForReady is true) */
120
- ready?: boolean;
121
- /** Agent ready details (only set when waitForReady is true and spawn succeeded) */
122
- readyInfo?: AgentReadyPayload;
61
+ export interface SendMessageInput {
62
+ to: string;
63
+ text: string;
64
+ from?: string;
65
+ threadId?: string;
66
+ priority?: number;
67
+ data?: Record<string, unknown>;
123
68
  }
124
69
 
125
- export interface ClientConfig {
126
- /** Daemon socket path (default: /tmp/agent-relay.sock) */
127
- socketPath: string;
128
- /** Agent name */
129
- agentName: string;
130
- /** Entity type: 'agent' (default) or 'user' */
131
- entityType?: EntityType;
132
- /** CLI identifier (claude, codex, gemini, etc.) */
70
+ export interface ListAgent {
71
+ name: string;
72
+ runtime: AgentRuntime;
133
73
  cli?: string;
134
- /** Program identifier */
135
- program?: string;
136
- /** Model identifier */
137
74
  model?: string;
138
- /** Task description */
139
- task?: string;
140
- /** Working directory */
141
- workingDirectory?: string;
142
- /** Team name */
143
75
  team?: string;
144
- /** Display name for human users */
145
- displayName?: string;
146
- /** Avatar URL for human users */
147
- avatarUrl?: string;
148
- /** Suppress console logging */
149
- quiet?: boolean;
150
- /** Auto-reconnect on disconnect */
151
- reconnect: boolean;
152
- /** Max reconnect attempts */
153
- maxReconnectAttempts: number;
154
- /** Initial reconnect delay (ms) */
155
- reconnectDelayMs: number;
156
- /** Max reconnect delay (ms) */
157
- reconnectMaxDelayMs: number;
158
- /**
159
- * Mark this client as a system component.
160
- * Allows using reserved agent names (Dashboard, cli, system).
161
- * Should only be set by trusted system components.
162
- */
163
- _isSystemComponent?: boolean;
76
+ channels: string[];
77
+ parent?: string;
78
+ pid?: number;
164
79
  }
165
80
 
166
- const DEFAULT_SOCKET_PATH = '/tmp/agent-relay.sock';
167
-
168
- /**
169
- * Resolve the socket path using discovery if not explicitly provided.
170
- * Falls back to /tmp/agent-relay.sock if discovery fails.
171
- */
172
- function resolveSocketPath(configPath?: string): string {
173
- if (configPath) return configPath;
174
- const discovery = discoverSocket();
175
- return discovery?.socketPath || DEFAULT_SOCKET_PATH;
81
+ interface PendingRequest {
82
+ expectedType: 'ok' | 'hello_ack';
83
+ resolve: (value: ProtocolEnvelope<unknown>) => void;
84
+ reject: (error: Error) => void;
85
+ timeout: ReturnType<typeof setTimeout>;
176
86
  }
177
87
 
178
- const DEFAULT_CLIENT_CONFIG: ClientConfig = {
179
- socketPath: DEFAULT_SOCKET_PATH,
180
- agentName: 'agent',
181
- cli: undefined,
182
- quiet: false,
183
- reconnect: true,
184
- maxReconnectAttempts: 10,
185
- reconnectDelayMs: 1000, // Increased from 100ms to prevent reconnect storms
186
- reconnectMaxDelayMs: 30000,
187
- };
188
-
189
- // Simple ID generator
190
- let idCounter = 0;
191
- function generateId(): string {
192
- return `${Date.now().toString(36)}-${(++idCounter).toString(36)}`;
88
+ interface ParsedEnvelope {
89
+ v: number;
90
+ type: string;
91
+ request_id?: string;
92
+ payload: unknown;
193
93
  }
194
94
 
195
- /**
196
- * Circular buffer for O(1) deduplication with bounded memory.
197
- */
198
- class CircularDedupeCache {
199
- private ids: Set<string> = new Set();
200
- private ring: string[];
201
- private head = 0;
202
- private readonly capacity: number;
203
-
204
- constructor(capacity = 2000) {
205
- this.capacity = capacity;
206
- this.ring = new Array(capacity);
207
- }
208
-
209
- check(id: string): boolean {
210
- if (this.ids.has(id)) return true;
211
-
212
- if (this.ids.size >= this.capacity) {
213
- const oldest = this.ring[this.head];
214
- if (oldest) this.ids.delete(oldest);
215
- }
95
+ export class AgentRelayProtocolError extends Error {
96
+ code: string;
97
+ retryable: boolean;
98
+ data?: unknown;
216
99
 
217
- this.ring[this.head] = id;
218
- this.ids.add(id);
219
- this.head = (this.head + 1) % this.capacity;
220
-
221
- return false;
222
- }
223
-
224
- clear(): void {
225
- this.ids.clear();
226
- this.ring = new Array(this.capacity);
227
- this.head = 0;
100
+ constructor(payload: ProtocolError) {
101
+ super(payload.message);
102
+ this.name = 'AgentRelayProtocolError';
103
+ this.code = payload.code;
104
+ this.retryable = payload.retryable;
105
+ this.data = payload.data;
228
106
  }
229
107
  }
230
108
 
231
- /**
232
- * RelayClient for agent-to-agent communication.
233
- */
234
- export class RelayClient {
235
- private config: ClientConfig;
236
- private socket?: net.Socket;
237
- private parser: FrameParser;
238
-
239
- private _state: ClientState = 'DISCONNECTED';
240
- private sessionId?: string;
241
- private resumeToken?: string;
242
- private reconnectAttempts = 0;
243
- private reconnectDelay: number;
244
- private reconnectTimer?: NodeJS.Timeout;
245
- private _destroyed = false;
246
-
247
- private dedupeCache = new CircularDedupeCache(2000);
248
- private writeQueue: Buffer[] = [];
249
- private writeScheduled = false;
250
-
251
- private pendingSyncAcks: Map<string, {
252
- resolve: (ack: AckPayload) => void;
253
- reject: (err: Error) => void;
254
- timeoutHandle: NodeJS.Timeout;
255
- }> = new Map();
256
-
257
- private pendingSpawns: Map<string, {
258
- resolve: (result: SpawnResultPayload) => void;
259
- reject: (err: Error) => void;
260
- timeoutHandle: NodeJS.Timeout;
261
- }> = new Map();
262
-
263
- private pendingReleases: Map<string, {
264
- resolve: (result: ReleaseResultPayload) => void;
265
- reject: (err: Error) => void;
266
- timeoutHandle: NodeJS.Timeout;
267
- }> = new Map();
268
-
269
- private pendingSendInputs: Map<string, {
270
- resolve: (result: SendInputResultPayload) => void;
271
- reject: (err: Error) => void;
272
- timeoutHandle: NodeJS.Timeout;
273
- }> = new Map();
274
-
275
- private pendingSetModels: Map<string, {
276
- resolve: (result: SetModelResultPayload) => void;
277
- reject: (err: Error) => void;
278
- timeoutHandle: NodeJS.Timeout;
279
- }> = new Map();
280
-
281
- private pendingListWorkers: Map<string, {
282
- resolve: (result: ListWorkersResultPayload) => void;
283
- reject: (err: Error) => void;
284
- timeoutHandle: NodeJS.Timeout;
285
- }> = new Map();
286
-
287
- private pendingQueries: Map<string, {
288
- resolve: (payload: unknown) => void;
289
- reject: (err: Error) => void;
290
- timeoutHandle: NodeJS.Timeout;
291
- }> = new Map();
292
-
293
- private pendingRequests: Map<string, {
294
- resolve: (response: RequestResponse) => void;
295
- reject: (err: Error) => void;
296
- timeoutHandle: NodeJS.Timeout;
297
- targetAgent: string;
298
- }> = new Map();
299
-
300
- private pendingAgentReady: Map<string, {
301
- resolve: (info: AgentReadyPayload) => void;
302
- reject: (err: Error) => void;
303
- timeoutHandle: NodeJS.Timeout;
304
- }> = new Map();
305
-
306
- // Event handlers
307
- onMessage?: (from: string, payload: SendPayload, messageId: string, meta?: SendMeta, originalTo?: string) => void;
308
- /**
309
- * Callback for channel messages.
310
- */
311
- onChannelMessage?: (from: string, channel: string, body: string, envelope: Envelope<ChannelMessagePayload>) => void;
312
- onStateChange?: (state: ClientState) => void;
313
- onError?: (error: Error) => void;
314
- /**
315
- * Callback when an agent becomes ready (completes HELLO/WELCOME handshake).
316
- * This is broadcast by the daemon when any agent connects.
317
- * Useful for knowing when a spawned agent is ready to receive messages.
318
- */
319
- onAgentReady?: (info: AgentReadyPayload) => void;
320
-
321
- constructor(config: Partial<ClientConfig> = {}) {
322
- this.config = { ...DEFAULT_CLIENT_CONFIG, ...config };
323
- // Use socket discovery if no explicit socketPath was provided
324
- if (!config.socketPath) {
325
- this.config.socketPath = resolveSocketPath();
326
- }
327
- this.parser = new FrameParser();
328
- this.parser.setLegacyMode(true);
329
- this.reconnectDelay = this.config.reconnectDelayMs;
109
+ export class AgentRelayProcessError extends Error {
110
+ constructor(message: string) {
111
+ super(message);
112
+ this.name = 'AgentRelayProcessError';
330
113
  }
114
+ }
331
115
 
332
- get state(): ClientState {
333
- return this._state;
116
+ export class AgentRelayClient {
117
+ private readonly options: Required<AgentRelayClientOptions>;
118
+ private child?: ChildProcessWithoutNullStreams;
119
+ private stdoutRl?: ReadlineInterface;
120
+ private stderrRl?: ReadlineInterface;
121
+ private lastStderrLine?: string;
122
+ private requestSeq = 0;
123
+ private pending = new Map<string, PendingRequest>();
124
+ private startingPromise?: Promise<void>;
125
+ private eventListeners = new Set<(event: BrokerEvent) => void>();
126
+ private stderrListeners = new Set<(line: string) => void>();
127
+ private eventBuffer: BrokerEvent[] = [];
128
+ private maxBufferSize = 1000;
129
+ private exitPromise?: Promise<void>;
130
+ /** The workspace key returned by the broker in its hello_ack response. */
131
+ workspaceKey?: string;
132
+
133
+ constructor(options: AgentRelayClientOptions = {}) {
134
+ this.options = {
135
+ binaryPath: options.binaryPath ?? resolveDefaultBinaryPath(),
136
+ binaryArgs: options.binaryArgs ?? [],
137
+ brokerName: options.brokerName ?? (path.basename(options.cwd ?? process.cwd()) || 'project'),
138
+ channels: options.channels ?? ['general'],
139
+ cwd: options.cwd ?? process.cwd(),
140
+ env: options.env ?? process.env,
141
+ requestTimeoutMs: options.requestTimeoutMs ?? 10_000,
142
+ shutdownTimeoutMs: options.shutdownTimeoutMs ?? 3_000,
143
+ clientName: options.clientName ?? '@agent-relay/sdk',
144
+ clientVersion: options.clientVersion ?? '0.1.0',
145
+ };
334
146
  }
335
147
 
336
- get agentName(): string {
337
- return this.config.agentName;
148
+ static async start(options: AgentRelayClientOptions = {}): Promise<AgentRelayClient> {
149
+ const client = new AgentRelayClient(options);
150
+ await client.start();
151
+ return client;
338
152
  }
339
153
 
340
- get currentSessionId(): string | undefined {
341
- return this.sessionId;
154
+ onEvent(listener: (event: BrokerEvent) => void): () => void {
155
+ this.eventListeners.add(listener);
156
+ return () => {
157
+ this.eventListeners.delete(listener);
158
+ };
342
159
  }
343
160
 
344
- /**
345
- * Connect to the relay daemon.
346
- */
347
- connect(): Promise<void> {
348
- if (this._state !== 'DISCONNECTED' && this._state !== 'BACKOFF') {
349
- return Promise.resolve();
161
+ queryEvents(filter?: { kind?: string; name?: string; since?: number; limit?: number }): BrokerEvent[] {
162
+ let events = [...this.eventBuffer];
163
+ if (filter?.kind) {
164
+ events = events.filter((event) => event.kind === filter.kind);
350
165
  }
351
-
352
- return new Promise((resolve, reject) => {
353
- let settled = false;
354
- const settleResolve = (): void => {
355
- if (settled) return;
356
- settled = true;
357
- resolve();
358
- };
359
- const settleReject = (err: Error): void => {
360
- if (settled) return;
361
- settled = true;
362
- reject(err);
363
- };
364
-
365
- this.setState('CONNECTING');
366
-
367
- this.socket = net.createConnection(this.config.socketPath, () => {
368
- this.setState('HANDSHAKING');
369
- this.sendHello();
370
- });
371
-
372
- this.socket.on('data', (data) => this.handleData(data));
373
-
374
- this.socket.on('close', () => {
375
- this.handleDisconnect();
376
- });
377
-
378
- this.socket.on('error', (err) => {
379
- if (this._state === 'CONNECTING') {
380
- const errno = (err as NodeJS.ErrnoException).code;
381
- if (errno === 'ECONNREFUSED' || errno === 'ENOENT') {
382
- settleReject(new DaemonNotRunningError(`Cannot connect to daemon at ${this.config.socketPath}`));
383
- } else {
384
- settleReject(new ConnectionError(err.message));
385
- }
386
- }
387
- this.handleError(err);
388
- });
389
-
390
- const checkReady = setInterval(() => {
391
- if (this._state === 'READY') {
392
- clearInterval(checkReady);
393
- clearTimeout(timeout);
394
- settleResolve();
395
- }
396
- }, 10);
397
-
398
- const timeout = setTimeout(() => {
399
- if (this._state !== 'READY') {
400
- clearInterval(checkReady);
401
- this.socket?.destroy();
402
- settleReject(new Error('Connection timeout'));
403
- }
404
- }, 5000);
405
- });
406
- }
407
-
408
- /**
409
- * Disconnect from the relay daemon.
410
- */
411
- disconnect(): void {
412
- if (this.reconnectTimer) {
413
- clearTimeout(this.reconnectTimer);
414
- this.reconnectTimer = undefined;
166
+ if (filter?.name) {
167
+ events = events.filter((event) => 'name' in event && event.name === filter.name);
415
168
  }
416
-
417
- if (this.socket) {
418
- this.send({
419
- v: PROTOCOL_VERSION,
420
- type: 'BYE',
421
- id: generateId(),
422
- ts: Date.now(),
423
- payload: {},
424
- });
425
- this.socket.end();
426
- this.socket = undefined;
169
+ const since = filter?.since;
170
+ if (since !== undefined) {
171
+ events = events.filter(
172
+ (event) => 'timestamp' in event && typeof event.timestamp === 'number' && event.timestamp >= since
173
+ );
427
174
  }
428
-
429
- this.setState('DISCONNECTED');
430
- }
431
-
432
- /**
433
- * Permanently destroy the client.
434
- */
435
- destroy(): void {
436
- this._destroyed = true;
437
- this.disconnect();
438
- }
439
-
440
- /**
441
- * Send a message to another agent.
442
- */
443
- sendMessage(
444
- to: string,
445
- body: string,
446
- kind: PayloadKind = 'message',
447
- data?: Record<string, unknown>,
448
- thread?: string,
449
- meta?: SendMeta
450
- ): boolean {
451
- if (this._state !== 'READY') {
452
- return false;
175
+ const limit = filter?.limit;
176
+ if (limit !== undefined) {
177
+ events = events.slice(-limit);
453
178
  }
454
-
455
- const envelope: SendEnvelope = {
456
- v: PROTOCOL_VERSION,
457
- type: 'SEND',
458
- id: generateId(),
459
- ts: Date.now(),
460
- to,
461
- payload: {
462
- kind,
463
- body,
464
- data,
465
- thread,
466
- },
467
- payload_meta: meta,
468
- };
469
-
470
- return this.send(envelope);
179
+ return events;
471
180
  }
472
181
 
473
- /**
474
- * Send an ACK for a delivered message.
475
- */
476
- sendAck(payload: AckPayload): boolean {
477
- if (this._state !== 'READY') {
478
- return false;
182
+ getLastEvent(kind: string, name?: string): BrokerEvent | undefined {
183
+ for (let i = this.eventBuffer.length - 1; i >= 0; i -= 1) {
184
+ const event = this.eventBuffer[i];
185
+ if (event.kind === kind && (!name || ('name' in event && event.name === name))) {
186
+ return event;
187
+ }
479
188
  }
189
+ return undefined;
190
+ }
480
191
 
481
- const envelope: Envelope<AckPayload> = {
482
- v: PROTOCOL_VERSION,
483
- type: 'ACK',
484
- id: generateId(),
485
- ts: Date.now(),
486
- payload,
192
+ onBrokerStderr(listener: (line: string) => void): () => void {
193
+ this.stderrListeners.add(listener);
194
+ return () => {
195
+ this.stderrListeners.delete(listener);
487
196
  };
488
-
489
- return this.send(envelope);
490
197
  }
491
198
 
492
- /**
493
- * Send a message and wait for ACK response.
494
- */
495
- async sendAndWait(to: string, body: string, options: SyncOptions = {}): Promise<AckPayload> {
496
- if (this._state !== 'READY') {
497
- throw new Error('Client not ready');
199
+ async start(): Promise<void> {
200
+ if (this.child) {
201
+ return;
498
202
  }
499
-
500
- const correlationId = randomUUID();
501
- const timeoutMs = options.timeoutMs ?? 30000;
502
- const kind = options.kind ?? 'message';
503
-
504
- return new Promise<AckPayload>((resolve, reject) => {
505
- const timeoutHandle = setTimeout(() => {
506
- this.pendingSyncAcks.delete(correlationId);
507
- reject(new Error(`ACK timeout after ${timeoutMs}ms`));
508
- }, timeoutMs);
509
-
510
- this.pendingSyncAcks.set(correlationId, { resolve, reject, timeoutHandle });
511
-
512
- const envelope: SendEnvelope = {
513
- v: PROTOCOL_VERSION,
514
- type: 'SEND',
515
- id: generateId(),
516
- ts: Date.now(),
517
- to,
518
- payload: {
519
- kind,
520
- body,
521
- data: options.data,
522
- thread: options.thread,
523
- },
524
- payload_meta: {
525
- sync: {
526
- correlationId,
527
- timeoutMs,
528
- blocking: true,
529
- },
530
- },
531
- };
532
-
533
- const sent = this.send(envelope);
534
- if (!sent) {
535
- clearTimeout(timeoutHandle);
536
- this.pendingSyncAcks.delete(correlationId);
537
- reject(new Error('Failed to send message'));
538
- }
539
- });
540
- }
541
-
542
- /**
543
- * Send a request to another agent and wait for their response.
544
- *
545
- * This implements a request/response pattern where the message is sent with
546
- * a correlation ID, and the method waits for the target agent to respond
547
- * with a message containing that correlation ID.
548
- *
549
- * @example
550
- * ```typescript
551
- * // Simple request
552
- * const response = await client.request('Worker', 'Process this task');
553
- * console.log(response.body); // Worker's response
554
- *
555
- * // With options
556
- * const response = await client.request('Worker', 'Process task', {
557
- * timeout: 60000,
558
- * data: { taskId: '123', priority: 'high' },
559
- * thread: 'task-thread-1',
560
- * });
561
- * ```
562
- *
563
- * @param to - Target agent name
564
- * @param body - Request message body
565
- * @param options - Request options (timeout, data, thread, kind)
566
- * @returns Promise that resolves with the response from the target agent
567
- * @throws Error if client is not ready, send fails, timeout occurs, or agent disconnects
568
- */
569
- async request(to: string, body: string, options: RequestOptions = {}): Promise<RequestResponse> {
570
- if (this._state !== 'READY') {
571
- throw new Error('Client not ready');
203
+ if (this.startingPromise) {
204
+ return this.startingPromise;
572
205
  }
573
206
 
574
- const correlationId = randomUUID();
575
- const timeoutMs = options.timeout ?? 30000;
576
- const kind = options.kind ?? 'message';
577
-
578
- return new Promise<RequestResponse>((resolve, reject) => {
579
- const timeoutHandle = setTimeout(() => {
580
- this.pendingRequests.delete(correlationId);
581
- reject(new Error(`Request timeout after ${timeoutMs}ms waiting for response from ${to}`));
582
- }, timeoutMs);
583
-
584
- this.pendingRequests.set(correlationId, {
585
- resolve,
586
- reject,
587
- timeoutHandle,
588
- targetAgent: to,
589
- });
590
-
591
- const envelope: SendEnvelope = {
592
- v: PROTOCOL_VERSION,
593
- type: 'SEND',
594
- id: generateId(),
595
- ts: Date.now(),
596
- to,
597
- payload: {
598
- kind,
599
- body,
600
- data: {
601
- ...options.data,
602
- _correlationId: correlationId,
603
- },
604
- thread: options.thread,
605
- },
606
- payload_meta: {
607
- replyTo: correlationId,
608
- },
609
- };
610
-
611
- const sent = this.send(envelope);
612
- if (!sent) {
613
- clearTimeout(timeoutHandle);
614
- this.pendingRequests.delete(correlationId);
615
- reject(new Error('Failed to send request'));
616
- }
207
+ this.startingPromise = this.startInternal();
208
+ try {
209
+ await this.startingPromise;
210
+ } finally {
211
+ this.startingPromise = undefined;
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Pre-register a batch of agents with Relaycast before their steps execute.
217
+ * The broker warms its token cache in parallel; subsequent spawn_agent calls
218
+ * hit the cache rather than waiting on individual HTTP registrations.
219
+ * Fire-and-forget from the caller's perspective — broker responds immediately
220
+ * and registers in the background.
221
+ */
222
+ async preflightAgents(agents: Array<{ name: string; cli: string | AgentRuntime }>): Promise<void> {
223
+ if (agents.length === 0) return;
224
+ await this.start();
225
+ await this.requestOk<void>('preflight_agents', { agents });
226
+ }
227
+
228
+ async spawnPty(input: SpawnPtyInput): Promise<{ name: string; runtime: AgentRuntime }> {
229
+ await this.start();
230
+ const args = buildPtyArgsWithModel(input.cli, input.args ?? [], input.model);
231
+ const agent: AgentSpec = {
232
+ name: input.name,
233
+ runtime: 'pty',
234
+ cli: input.cli,
235
+ args,
236
+ channels: input.channels ?? [],
237
+ model: input.model,
238
+ cwd: input.cwd ?? this.options.cwd,
239
+ team: input.team,
240
+ shadow_of: input.shadowOf,
241
+ shadow_mode: input.shadowMode,
242
+ restart_policy: input.restartPolicy,
243
+ };
244
+ const result = await this.requestOk<{ name: string; runtime: AgentRuntime }>('spawn_agent', {
245
+ agent,
246
+ ...(input.task != null ? { initial_task: input.task } : {}),
247
+ ...(input.idleThresholdSecs != null ? { idle_threshold_secs: input.idleThresholdSecs } : {}),
248
+ ...(input.continueFrom != null ? { continue_from: input.continueFrom } : {}),
617
249
  });
618
- }
619
-
620
- /**
621
- * Respond to a request from another agent.
622
- *
623
- * This is a convenience method for responding to messages that have a
624
- * correlation ID. The response will be routed back to the requesting agent.
625
- *
626
- * @param correlationId - The correlation ID from the original request (from data._correlationId or meta.replyTo)
627
- * @param to - Target agent (the one who sent the original request)
628
- * @param body - Response body
629
- * @param data - Optional structured data to include in the response
630
- * @returns true if the message was sent
631
- */
632
- respond(correlationId: string, to: string, body: string, data?: Record<string, unknown>): boolean {
633
- if (this._state !== 'READY') {
634
- return false;
635
- }
636
-
637
- const envelope: SendEnvelope = {
638
- v: PROTOCOL_VERSION,
639
- type: 'SEND',
640
- id: generateId(),
641
- ts: Date.now(),
642
- to,
643
- payload: {
644
- kind: 'message',
645
- body,
646
- data: {
647
- ...data,
648
- _correlationId: correlationId,
649
- _isResponse: true,
650
- },
651
- },
652
- payload_meta: {
653
- replyTo: correlationId,
654
- },
250
+ return result;
251
+ }
252
+
253
+ async spawnHeadlessClaude(
254
+ input: SpawnHeadlessClaudeInput
255
+ ): Promise<{ name: string; runtime: AgentRuntime }> {
256
+ await this.start();
257
+ const agent: AgentSpec = {
258
+ name: input.name,
259
+ runtime: 'headless_claude',
260
+ args: input.args ?? [],
261
+ channels: input.channels ?? [],
655
262
  };
656
-
657
- return this.send(envelope);
658
- }
659
-
660
- /**
661
- * Broadcast a message to all agents.
662
- */
663
- broadcast(body: string, kind: PayloadKind = 'message', data?: Record<string, unknown>): boolean {
664
- return this.sendMessage('*', body, kind, data);
665
- }
666
-
667
- /**
668
- * Subscribe to a topic.
669
- */
670
- subscribe(topic: string): boolean {
671
- if (this._state !== 'READY') return false;
672
-
673
- return this.send({
674
- v: PROTOCOL_VERSION,
675
- type: 'SUBSCRIBE',
676
- id: generateId(),
677
- ts: Date.now(),
678
- topic,
679
- payload: {},
263
+ const result = await this.requestOk<{ name: string; runtime: AgentRuntime }>('spawn_agent', {
264
+ agent,
265
+ ...(input.task != null ? { initial_task: input.task } : {}),
680
266
  });
267
+ return result;
681
268
  }
682
269
 
683
- /**
684
- * Unsubscribe from a topic.
685
- */
686
- unsubscribe(topic: string): boolean {
687
- if (this._state !== 'READY') return false;
688
-
689
- return this.send({
690
- v: PROTOCOL_VERSION,
691
- type: 'UNSUBSCRIBE',
692
- id: generateId(),
693
- ts: Date.now(),
694
- topic,
695
- payload: {},
696
- });
270
+ async release(name: string, reason?: string): Promise<{ name: string }> {
271
+ await this.start();
272
+ return this.requestOk<{ name: string }>('release_agent', { name, reason });
697
273
  }
698
274
 
699
- /**
700
- * Bind as a shadow to a primary agent.
701
- */
702
- bindAsShadow(
703
- primaryAgent: string,
704
- options: {
705
- speakOn?: SpeakOnTrigger[];
706
- receiveIncoming?: boolean;
707
- receiveOutgoing?: boolean;
708
- } = {}
709
- ): boolean {
710
- if (this._state !== 'READY') return false;
711
-
712
- return this.send({
713
- v: PROTOCOL_VERSION,
714
- type: 'SHADOW_BIND',
715
- id: generateId(),
716
- ts: Date.now(),
717
- payload: {
718
- primaryAgent,
719
- speakOn: options.speakOn,
720
- receiveIncoming: options.receiveIncoming,
721
- receiveOutgoing: options.receiveOutgoing,
722
- },
723
- });
275
+ async sendInput(name: string, data: string): Promise<{ name: string; bytes_written: number }> {
276
+ await this.start();
277
+ return this.requestOk<{ name: string; bytes_written: number }>('send_input', { name, data });
724
278
  }
725
279
 
726
- /**
727
- * Unbind from a primary agent.
728
- */
729
- unbindAsShadow(primaryAgent: string): boolean {
730
- if (this._state !== 'READY') return false;
731
-
732
- return this.send({
733
- v: PROTOCOL_VERSION,
734
- type: 'SHADOW_UNBIND',
735
- id: generateId(),
736
- ts: Date.now(),
737
- payload: {
738
- primaryAgent,
739
- },
280
+ async setModel(
281
+ name: string,
282
+ model: string,
283
+ opts?: { timeoutMs?: number }
284
+ ): Promise<{ name: string; model: string; success: boolean }> {
285
+ await this.start();
286
+ return this.requestOk<{ name: string; model: string; success: boolean }>('set_model', {
287
+ name,
288
+ model,
289
+ timeout_ms: opts?.timeoutMs,
740
290
  });
741
291
  }
742
292
 
743
- /**
744
- * Send log output to the daemon for dashboard streaming.
745
- */
746
- sendLog(data: string): boolean {
747
- if (this._state !== 'READY') {
748
- return false;
749
- }
750
-
751
- const envelope: Envelope<LogPayload> = {
752
- v: PROTOCOL_VERSION,
753
- type: 'LOG',
754
- id: generateId(),
755
- ts: Date.now(),
756
- payload: {
757
- data,
758
- timestamp: Date.now(),
759
- },
760
- };
761
-
762
- return this.send(envelope);
293
+ async getMetrics(agent?: string): Promise<{
294
+ agents: Array<{ name: string; pid: number; memory_bytes: number; uptime_secs: number }>;
295
+ broker?: BrokerStats;
296
+ }> {
297
+ await this.start();
298
+ return this.requestOk<{
299
+ agents: Array<{ name: string; pid: number; memory_bytes: number; uptime_secs: number }>;
300
+ broker?: BrokerStats;
301
+ }>('get_metrics', { agent });
763
302
  }
764
303
 
765
- // =============================================================================
766
- // Spawn/Release Operations
767
- // =============================================================================
768
-
769
- /**
770
- * Spawn a new agent via the relay daemon.
771
- * @param options - Spawn options
772
- * @param options.name - Name for the new agent
773
- * @param options.cli - CLI to use (claude, codex, gemini, etc.)
774
- * @param options.task - Task description
775
- * @param options.cwd - Working directory
776
- * @param options.team - Team name
777
- * @param options.interactive - Interactive mode
778
- * @param options.shadowMode - Shadow execution mode ('subagent' or 'process')
779
- * @param options.shadowOf - Spawn as shadow of this agent
780
- * @param options.shadowAgent - Shadow agent profile to use (for subagent mode)
781
- * @param options.shadowTriggers - When to trigger the shadow (for subagent mode)
782
- * @param options.shadowSpeakOn - Shadow speak-on triggers
783
- * @param options.waitForReady - Wait for the agent to be ready before resolving (default: false)
784
- * @param options.readyTimeoutMs - Timeout for agent to become ready (default: 60000ms)
785
- * @param timeoutMs - Timeout for spawn operation (default: 60000ms)
786
- * @returns Spawn result. When waitForReady is true, includes `ready` and `readyInfo` fields.
787
- */
788
- async spawn(
789
- options: {
790
- name: string;
791
- cli: string;
792
- task?: string;
793
- cwd?: string;
794
- team?: string;
795
- /** Model override (e.g., 'opus', 'sonnet', 'haiku'). Takes precedence over agent profile. */
796
- model?: string;
797
- interactive?: boolean;
798
- shadowMode?: 'subagent' | 'process';
799
- shadowOf?: string;
800
- shadowAgent?: string;
801
- shadowTriggers?: SpeakOnTrigger[];
802
- shadowSpeakOn?: SpeakOnTrigger[];
803
- /** User ID for cloud persistence */
804
- userId?: string;
805
- /** Include ACK/DONE workflow conventions in agent instructions */
806
- includeWorkflowConventions?: boolean;
807
- /** Override the spawner name (defaults to this client's agentName) */
808
- spawnerName?: string;
809
- /** Wait for the agent to complete connection before resolving */
810
- waitForReady?: boolean;
811
- /** Timeout for agent to become ready (default: 60000ms). Only used when waitForReady is true. */
812
- readyTimeoutMs?: number;
813
- },
814
- timeoutMs = 60000
815
- ): Promise<SpawnResult> {
816
- if (this._state !== 'READY') {
817
- throw new Error('Client not ready');
818
- }
819
-
820
- const envelopeId = generateId();
821
- const waitForReady = options.waitForReady ?? false;
822
- const readyTimeoutMs = options.readyTimeoutMs ?? 60000;
823
-
824
- // If waitForReady, set up the agent ready listener BEFORE spawning
825
- // This ensures we don't miss the AGENT_READY event if it arrives quickly
826
- let readyPromise: Promise<AgentReadyPayload> | undefined;
827
- if (waitForReady) {
828
- // Check if we're already waiting for this agent (prevents overwriting existing waiter)
829
- if (this.pendingAgentReady.has(options.name)) {
830
- throw new Error(`Already waiting for agent ${options.name} to be ready`);
831
- }
832
-
833
- readyPromise = new Promise<AgentReadyPayload>((resolve, reject) => {
834
- const timeoutHandle = setTimeout(() => {
835
- this.pendingAgentReady.delete(options.name);
836
- reject(new Error(`Agent ${options.name} did not become ready within ${readyTimeoutMs}ms`));
837
- }, readyTimeoutMs);
304
+ async getCrashInsights(): Promise<CrashInsightsResponse> {
305
+ await this.start();
306
+ return this.requestOk<CrashInsightsResponse>('get_crash_insights', {});
307
+ }
838
308
 
839
- this.pendingAgentReady.set(options.name, { resolve, reject, timeoutHandle });
309
+ async sendMessage(input: SendMessageInput): Promise<{ event_id: string; targets: string[] }> {
310
+ await this.start();
311
+ try {
312
+ return await this.requestOk<{ event_id: string; targets: string[] }>('send_message', {
313
+ to: input.to,
314
+ text: input.text,
315
+ from: input.from,
316
+ thread_id: input.threadId,
317
+ priority: input.priority,
318
+ data: input.data,
840
319
  });
841
- }
842
-
843
- // Send the spawn request
844
- const spawnResult = await new Promise<SpawnResultPayload>((resolve, reject) => {
845
- const timeoutHandle = setTimeout(() => {
846
- this.pendingSpawns.delete(envelopeId);
847
- // Also clean up pending agent ready if spawn times out
848
- if (waitForReady) {
849
- const pending = this.pendingAgentReady.get(options.name);
850
- if (pending) {
851
- clearTimeout(pending.timeoutHandle);
852
- this.pendingAgentReady.delete(options.name);
853
- }
854
- }
855
- reject(new Error(`Spawn timeout after ${timeoutMs}ms`));
856
- }, timeoutMs);
857
-
858
- this.pendingSpawns.set(envelopeId, { resolve, reject, timeoutHandle });
859
-
860
- const envelope: SpawnEnvelope = {
861
- v: PROTOCOL_VERSION,
862
- type: 'SPAWN',
863
- id: envelopeId,
864
- ts: Date.now(),
865
- payload: {
866
- name: options.name,
867
- cli: options.cli,
868
- task: options.task || '',
869
- cwd: options.cwd,
870
- team: options.team,
871
- model: options.model,
872
- interactive: options.interactive,
873
- shadowMode: options.shadowMode,
874
- shadowOf: options.shadowOf,
875
- shadowAgent: options.shadowAgent,
876
- shadowTriggers: options.shadowTriggers,
877
- shadowSpeakOn: options.shadowSpeakOn,
878
- userId: options.userId,
879
- includeWorkflowConventions: options.includeWorkflowConventions,
880
- spawnerName: options.spawnerName || this.config.agentName,
881
- },
882
- };
883
-
884
- const sent = this.send(envelope);
885
- if (!sent) {
886
- clearTimeout(timeoutHandle);
887
- this.pendingSpawns.delete(envelopeId);
888
- // Also clean up pending agent ready if send fails
889
- if (waitForReady) {
890
- const pending = this.pendingAgentReady.get(options.name);
891
- if (pending) {
892
- clearTimeout(pending.timeoutHandle);
893
- this.pendingAgentReady.delete(options.name);
894
- }
895
- }
896
- reject(new Error('Failed to send spawn message'));
897
- }
898
- });
899
-
900
- // If spawn failed or we don't need to wait for ready, return immediately
901
- if (!spawnResult.success || !waitForReady || !readyPromise) {
902
- // Clean up pending agent ready if spawn failed
903
- if (!spawnResult.success && waitForReady) {
904
- const pending = this.pendingAgentReady.get(options.name);
905
- if (pending) {
906
- clearTimeout(pending.timeoutHandle);
907
- this.pendingAgentReady.delete(options.name);
908
- }
320
+ } catch (error) {
321
+ if (error instanceof AgentRelayProtocolError && error.code === 'unsupported_operation') {
322
+ return { event_id: 'unsupported_operation', targets: [] };
909
323
  }
910
- return spawnResult;
911
- }
912
-
913
- // Wait for the agent to become ready
914
- try {
915
- const readyInfo = await readyPromise;
916
- return {
917
- ...spawnResult,
918
- ready: true,
919
- readyInfo,
920
- };
921
- } catch (err) {
922
- // Agent spawned but didn't become ready in time
923
- // Return the spawn result with ready: false
924
- return {
925
- ...spawnResult,
926
- ready: false,
927
- };
324
+ throw error;
928
325
  }
929
326
  }
930
327
 
931
- /**
932
- * Wait for an agent to become ready (complete HELLO/WELCOME handshake).
933
- * This is useful when you want to wait for an agent that was spawned through
934
- * another mechanism, or to verify an agent is connected before sending messages.
935
- *
936
- * @example
937
- * ```typescript
938
- * // Wait for an agent that might be spawning
939
- * try {
940
- * const readyInfo = await client.waitForAgentReady('Worker', 30000);
941
- * console.log(`Worker is ready: ${readyInfo.cli}`);
942
- * } catch (err) {
943
- * console.error('Worker did not become ready in time');
944
- * }
945
- * ```
946
- *
947
- * @param name - Agent name to wait for
948
- * @param timeoutMs - Timeout in milliseconds (default: 60000ms)
949
- * @returns Promise that resolves with AgentReadyPayload when the agent connects
950
- * @throws Error if the agent doesn't become ready within the timeout
951
- */
952
- async waitForAgentReady(name: string, timeoutMs = 60000): Promise<AgentReadyPayload> {
953
- if (this._state !== 'READY') {
954
- throw new Error('Client not ready');
955
- }
956
-
957
- // Check if we're already waiting for this agent
958
- if (this.pendingAgentReady.has(name)) {
959
- throw new Error(`Already waiting for agent ${name} to be ready`);
960
- }
961
-
962
- return new Promise<AgentReadyPayload>((resolve, reject) => {
963
- const timeoutHandle = setTimeout(() => {
964
- this.pendingAgentReady.delete(name);
965
- reject(new Error(`Agent ${name} did not become ready within ${timeoutMs}ms`));
966
- }, timeoutMs);
967
-
968
- this.pendingAgentReady.set(name, { resolve, reject, timeoutHandle });
969
- });
328
+ async listAgents(): Promise<ListAgent[]> {
329
+ await this.start();
330
+ const result = await this.requestOk<{ agents: ListAgent[] }>('list_agents', {});
331
+ return result.agents;
970
332
  }
971
333
 
972
- /**
973
- * Release (terminate) an agent via the relay daemon.
974
- * @param name - Agent name to release
975
- * @param timeoutMs - Timeout for release operation (default: 10000ms)
976
- */
977
- async release(name: string, reason?: string, timeoutMs = 10000): Promise<ReleaseResultPayload> {
978
- if (this._state !== 'READY') {
979
- throw new Error('Client not ready');
980
- }
981
-
982
- const envelopeId = generateId();
983
-
984
- return new Promise<ReleaseResultPayload>((resolve, reject) => {
985
- const timeoutHandle = setTimeout(() => {
986
- this.pendingReleases.delete(envelopeId);
987
- reject(new Error(`Release timeout after ${timeoutMs}ms`));
988
- }, timeoutMs);
989
-
990
- this.pendingReleases.set(envelopeId, { resolve, reject, timeoutHandle });
991
-
992
- const envelope: ReleaseEnvelope = {
993
- v: PROTOCOL_VERSION,
994
- type: 'RELEASE',
995
- id: envelopeId,
996
- ts: Date.now(),
997
- payload: {
998
- name,
999
- reason,
1000
- },
1001
- };
1002
-
1003
- const sent = this.send(envelope);
1004
- if (!sent) {
1005
- clearTimeout(timeoutHandle);
1006
- this.pendingReleases.delete(envelopeId);
1007
- reject(new Error('Failed to send release message'));
1008
- }
1009
- });
334
+ async getStatus(): Promise<BrokerStatus> {
335
+ await this.start();
336
+ return this.requestOk<BrokerStatus>('get_status', {});
1010
337
  }
1011
338
 
1012
- /**
1013
- * Send input data to a spawned agent's PTY.
1014
- * @param name - Agent name to send input to
1015
- * @param data - Input data to send
1016
- * @param timeoutMs - Timeout for the operation (default: 10000ms)
1017
- */
1018
- async sendWorkerInput(name: string, data: string, timeoutMs = 10000): Promise<SendInputResultPayload> {
1019
- if (this._state !== 'READY') {
1020
- throw new Error('Client not ready');
339
+ async shutdown(): Promise<void> {
340
+ if (!this.child) {
341
+ return;
1021
342
  }
1022
343
 
1023
- const envelopeId = generateId();
1024
-
1025
- return new Promise<SendInputResultPayload>((resolve, reject) => {
1026
- const timeoutHandle = setTimeout(() => {
1027
- this.pendingSendInputs.delete(envelopeId);
1028
- reject(new Error(`Send input timeout after ${timeoutMs}ms`));
1029
- }, timeoutMs);
1030
-
1031
- this.pendingSendInputs.set(envelopeId, { resolve, reject, timeoutHandle });
1032
-
1033
- const envelope: SendInputEnvelope = {
1034
- v: PROTOCOL_VERSION,
1035
- type: 'SEND_INPUT',
1036
- id: envelopeId,
1037
- ts: Date.now(),
1038
- payload: {
1039
- name,
1040
- data,
1041
- },
1042
- };
1043
-
1044
- const sent = this.send(envelope);
1045
- if (!sent) {
1046
- clearTimeout(timeoutHandle);
1047
- this.pendingSendInputs.delete(envelopeId);
1048
- reject(new Error('Failed to send input message'));
1049
- }
1050
- });
1051
- }
1052
-
1053
- /**
1054
- * Change the model of a running spawned agent.
1055
- * The command waits for the agent to be idle before sending the model switch command.
1056
- *
1057
- * @param name - Agent name to switch model for
1058
- * @param model - Target model (e.g., 'opus', 'sonnet', 'haiku')
1059
- * @param options - Options including idle wait timeout
1060
- * @param operationTimeoutMs - Timeout for the overall protocol operation (default: 45000ms)
1061
- */
1062
- async setWorkerModel(
1063
- name: string,
1064
- model: string,
1065
- options?: { timeoutMs?: number },
1066
- operationTimeoutMs = 45000,
1067
- ): Promise<SetModelResultPayload> {
1068
- if (this._state !== 'READY') {
1069
- throw new Error('Client not ready');
344
+ try {
345
+ await this.requestOk('shutdown', {});
346
+ } catch {
347
+ // Continue shutdown path if broker is already unhealthy.
1070
348
  }
1071
349
 
1072
- const envelopeId = generateId();
1073
-
1074
- return new Promise<SetModelResultPayload>((resolve, reject) => {
1075
- const timeoutHandle = setTimeout(() => {
1076
- this.pendingSetModels.delete(envelopeId);
1077
- reject(new Error(`Set model timeout after ${operationTimeoutMs}ms`));
1078
- }, operationTimeoutMs);
1079
-
1080
- this.pendingSetModels.set(envelopeId, { resolve, reject, timeoutHandle });
1081
-
1082
- const envelope: SetModelEnvelope = {
1083
- v: PROTOCOL_VERSION,
1084
- type: 'SET_MODEL',
1085
- id: envelopeId,
1086
- ts: Date.now(),
1087
- payload: {
1088
- name,
1089
- model,
1090
- timeoutMs: options?.timeoutMs,
1091
- },
1092
- };
1093
-
1094
- const sent = this.send(envelope);
1095
- if (!sent) {
1096
- clearTimeout(timeoutHandle);
1097
- this.pendingSetModels.delete(envelopeId);
1098
- reject(new Error('Failed to send set model message'));
350
+ const child = this.child;
351
+ const wait = this.exitPromise ?? Promise.resolve();
352
+ const timeout = setTimeout(() => {
353
+ if (!child.killed) {
354
+ child.kill('SIGTERM');
1099
355
  }
1100
- });
1101
- }
356
+ }, this.options.shutdownTimeoutMs);
1102
357
 
1103
- /**
1104
- * List active spawned workers.
1105
- * @param timeoutMs - Timeout for the operation (default: 10000ms)
1106
- */
1107
- async listWorkers(timeoutMs = 10000): Promise<ListWorkersResultPayload> {
1108
- if (this._state !== 'READY') {
1109
- throw new Error('Client not ready');
1110
- }
1111
-
1112
- const envelopeId = generateId();
1113
-
1114
- return new Promise<ListWorkersResultPayload>((resolve, reject) => {
1115
- const timeoutHandle = setTimeout(() => {
1116
- this.pendingListWorkers.delete(envelopeId);
1117
- reject(new Error(`List workers timeout after ${timeoutMs}ms`));
1118
- }, timeoutMs);
1119
-
1120
- this.pendingListWorkers.set(envelopeId, { resolve, reject, timeoutHandle });
1121
-
1122
- const envelope: ListWorkersEnvelope = {
1123
- v: PROTOCOL_VERSION,
1124
- type: 'LIST_WORKERS',
1125
- id: envelopeId,
1126
- ts: Date.now(),
1127
- payload: {},
1128
- };
1129
-
1130
- const sent = this.send(envelope);
1131
- if (!sent) {
1132
- clearTimeout(timeoutHandle);
1133
- this.pendingListWorkers.delete(envelopeId);
1134
- reject(new Error('Failed to send list workers message'));
358
+ try {
359
+ await wait;
360
+ } finally {
361
+ clearTimeout(timeout);
362
+ if (this.child) {
363
+ this.child.kill('SIGKILL');
1135
364
  }
1136
- });
1137
- }
1138
-
1139
- // =============================================================================
1140
- // Channel Operations
1141
- // =============================================================================
1142
-
1143
- /**
1144
- * Join a channel.
1145
- * @param channel - Channel name (e.g., '#general', 'dm:alice:bob')
1146
- * @param displayName - Optional display name for this member
1147
- */
1148
- joinChannel(channel: string, displayName?: string): boolean {
1149
- if (this._state !== 'READY') {
1150
- return false;
1151
- }
1152
-
1153
- const envelope: ChannelJoinEnvelope = {
1154
- v: PROTOCOL_VERSION,
1155
- type: 'CHANNEL_JOIN',
1156
- id: generateId(),
1157
- ts: Date.now(),
1158
- payload: {
1159
- channel,
1160
- displayName,
1161
- },
1162
- };
1163
-
1164
- return this.send(envelope);
1165
- }
1166
-
1167
- /**
1168
- * Admin join: Add any member to a channel (does not require member to be connected).
1169
- * @param channel - Channel name
1170
- * @param member - Name of the member to add
1171
- */
1172
- adminJoinChannel(channel: string, member: string): boolean {
1173
- if (this._state !== 'READY') {
1174
- return false;
1175
- }
1176
-
1177
- const envelope: ChannelJoinEnvelope = {
1178
- v: PROTOCOL_VERSION,
1179
- type: 'CHANNEL_JOIN',
1180
- id: generateId(),
1181
- ts: Date.now(),
1182
- payload: {
1183
- channel,
1184
- member,
1185
- },
1186
- };
1187
-
1188
- return this.send(envelope);
1189
- }
1190
-
1191
- /**
1192
- * Leave a channel.
1193
- * @param channel - Channel name to leave
1194
- * @param reason - Optional reason for leaving
1195
- */
1196
- leaveChannel(channel: string, reason?: string): boolean {
1197
- if (this._state !== 'READY') return false;
1198
-
1199
- const envelope: ChannelLeaveEnvelope = {
1200
- v: PROTOCOL_VERSION,
1201
- type: 'CHANNEL_LEAVE',
1202
- id: generateId(),
1203
- ts: Date.now(),
1204
- payload: {
1205
- channel,
1206
- reason,
1207
- },
1208
- };
1209
-
1210
- return this.send(envelope);
1211
- }
1212
-
1213
- /**
1214
- * Admin remove: Remove any member from a channel.
1215
- * @param channel - Channel name
1216
- * @param member - Name of the member to remove
1217
- */
1218
- adminRemoveMember(channel: string, member: string): boolean {
1219
- if (this._state !== 'READY') {
1220
- return false;
1221
365
  }
1222
-
1223
- const envelope: ChannelLeaveEnvelope = {
1224
- v: PROTOCOL_VERSION,
1225
- type: 'CHANNEL_LEAVE',
1226
- id: generateId(),
1227
- ts: Date.now(),
1228
- payload: {
1229
- channel,
1230
- member,
1231
- },
1232
- };
1233
-
1234
- return this.send(envelope);
1235
366
  }
1236
367
 
1237
- /**
1238
- * Send a message to a channel.
1239
- * @param channel - Channel name
1240
- * @param body - Message content
1241
- * @param options - Optional thread, mentions, attachments
1242
- */
1243
- sendChannelMessage(
1244
- channel: string,
1245
- body: string,
1246
- options?: {
1247
- thread?: string;
1248
- mentions?: string[];
1249
- attachments?: MessageAttachment[];
1250
- data?: Record<string, unknown>;
1251
- }
1252
- ): boolean {
1253
- if (this._state !== 'READY') {
1254
- return false;
368
+ async waitForExit(): Promise<void> {
369
+ if (!this.child) {
370
+ return;
1255
371
  }
1256
-
1257
- const envelope: ChannelMessageEnvelope = {
1258
- v: PROTOCOL_VERSION,
1259
- type: 'CHANNEL_MESSAGE',
1260
- id: generateId(),
1261
- ts: Date.now(),
1262
- payload: {
1263
- channel,
1264
- body,
1265
- thread: options?.thread,
1266
- mentions: options?.mentions,
1267
- attachments: options?.attachments,
1268
- data: options?.data,
1269
- },
1270
- };
1271
-
1272
- return this.send(envelope);
372
+ await this.exitPromise;
1273
373
  }
1274
374
 
1275
- // =============================================================================
1276
- // Consensus Operations
1277
- // =============================================================================
1278
-
1279
- /**
1280
- * Create a consensus proposal.
1281
- *
1282
- * The proposal will be broadcast to all participants. They can vote using
1283
- * the `vote()` method. Results are delivered via `onMessage` callback.
1284
- *
1285
- * @example
1286
- * ```typescript
1287
- * client.createProposal({
1288
- * title: 'Approve API design',
1289
- * description: 'Should we proceed with the REST API design?',
1290
- * participants: ['Developer', 'Reviewer', 'Lead'],
1291
- * consensusType: 'majority',
1292
- * });
1293
- * ```
1294
- *
1295
- * @param options - Proposal options
1296
- * @returns true if the message was sent
1297
- */
1298
- createProposal(options: CreateProposalOptions): boolean {
1299
- if (this._state !== 'READY') {
1300
- return false;
375
+ private async startInternal(): Promise<void> {
376
+ const resolvedBinary = expandTilde(this.options.binaryPath);
377
+ if (isExplicitPath(this.options.binaryPath) && !fs.existsSync(resolvedBinary)) {
378
+ throw new AgentRelayProcessError(`broker binary not found: ${this.options.binaryPath}`);
1301
379
  }
380
+ this.lastStderrLine = undefined;
1302
381
 
1303
- // Build the PROPOSE command message
1304
- const lines: string[] = [
1305
- `PROPOSE: ${options.title}`,
1306
- `TYPE: ${options.consensusType ?? 'majority'}`,
1307
- `PARTICIPANTS: ${options.participants.join(', ')}`,
1308
- `DESCRIPTION: ${options.description}`,
382
+ const args = [
383
+ 'init',
384
+ '--name',
385
+ this.options.brokerName,
386
+ '--channels',
387
+ this.options.channels.join(','),
388
+ ...this.options.binaryArgs,
1309
389
  ];
1310
390
 
1311
- if (options.timeoutMs !== undefined) {
1312
- lines.push(`TIMEOUT: ${options.timeoutMs}`);
1313
- }
1314
- if (options.quorum !== undefined) {
1315
- lines.push(`QUORUM: ${options.quorum}`);
1316
- }
1317
- if (options.threshold !== undefined) {
1318
- lines.push(`THRESHOLD: ${options.threshold}`);
1319
- }
1320
-
1321
- const body = lines.join('\n');
1322
-
1323
- // Send to the special _consensus recipient
1324
- return this.sendMessage('_consensus', body, 'action');
1325
- }
1326
-
1327
- /**
1328
- * Vote on a consensus proposal.
1329
- *
1330
- * @example
1331
- * ```typescript
1332
- * // Approve with a reason
1333
- * client.vote({
1334
- * proposalId: 'prop_123',
1335
- * value: 'approve',
1336
- * reason: 'Looks good to me',
1337
- * });
1338
- *
1339
- * // Reject without reason
1340
- * client.vote({ proposalId: 'prop_123', value: 'reject' });
1341
- * ```
1342
- *
1343
- * @param options - Vote options
1344
- * @returns true if the message was sent
1345
- */
1346
- vote(options: VoteOptions): boolean {
1347
- if (this._state !== 'READY') {
1348
- return false;
1349
- }
1350
-
1351
- // Build the VOTE command
1352
- let body = `VOTE ${options.proposalId} ${options.value}`;
1353
- if (options.reason) {
1354
- body += ` ${options.reason}`;
1355
- }
1356
-
1357
- // Send to the special _consensus recipient
1358
- return this.sendMessage('_consensus', body, 'action');
1359
- }
1360
-
1361
- // =============================================================================
1362
- // Query Operations
1363
- // =============================================================================
1364
-
1365
- /**
1366
- * Send a query to the daemon and wait for a response.
1367
- * @internal
1368
- */
1369
- private async query<T>(type: string, payload: unknown, timeoutMs = 5000): Promise<T> {
1370
- if (this._state !== 'READY') {
1371
- throw new Error('Client not ready');
391
+ // Ensure the SDK bin directory (containing agent-relay-broker + relay_send) is on
392
+ // PATH so spawned workers can find relay_send without any user setup.
393
+ const env = { ...this.options.env };
394
+ if (isExplicitPath(this.options.binaryPath)) {
395
+ const binDir = path.dirname(path.resolve(resolvedBinary));
396
+ const currentPath = env.PATH ?? env.Path ?? '';
397
+ if (!currentPath.split(path.delimiter).includes(binDir)) {
398
+ env.PATH = `${binDir}${path.delimiter}${currentPath}`;
399
+ }
1372
400
  }
1373
401
 
1374
- const envelopeId = generateId();
402
+ console.log(`[broker] Starting: ${resolvedBinary} ${args.join(' ')}`);
403
+ const child = spawn(resolvedBinary, args, {
404
+ cwd: this.options.cwd,
405
+ env,
406
+ stdio: 'pipe',
407
+ });
1375
408
 
1376
- return new Promise<T>((resolve, reject) => {
1377
- const timeoutHandle = setTimeout(() => {
1378
- this.pendingQueries.delete(envelopeId);
1379
- reject(new Error(`Query timeout after ${timeoutMs}ms`));
1380
- }, timeoutMs);
409
+ this.child = child;
410
+ this.stdoutRl = createInterface({ input: child.stdout, crlfDelay: Infinity });
411
+ this.stderrRl = createInterface({ input: child.stderr, crlfDelay: Infinity });
1381
412
 
1382
- this.pendingQueries.set(envelopeId, {
1383
- resolve: resolve as (p: unknown) => void,
1384
- reject,
1385
- timeoutHandle,
1386
- });
413
+ this.stdoutRl.on('line', (line) => {
414
+ this.handleStdoutLine(line);
415
+ });
1387
416
 
1388
- const envelope: Envelope = {
1389
- v: PROTOCOL_VERSION,
1390
- type: type as Envelope['type'],
1391
- id: envelopeId,
1392
- ts: Date.now(),
1393
- payload,
1394
- };
1395
-
1396
- const sent = this.send(envelope);
1397
- if (!sent) {
1398
- clearTimeout(timeoutHandle);
1399
- this.pendingQueries.delete(envelopeId);
1400
- reject(new Error(`Failed to send ${type} query`));
417
+ this.stderrRl.on('line', (line) => {
418
+ const trimmed = line.trim();
419
+ if (trimmed) {
420
+ this.lastStderrLine = trimmed;
421
+ }
422
+ for (const listener of this.stderrListeners) {
423
+ listener(line);
1401
424
  }
1402
425
  });
1403
- }
1404
-
1405
- /**
1406
- * Get daemon status information.
1407
- * @returns Daemon status including version, uptime, and counts
1408
- */
1409
- async getStatus(): Promise<StatusResponsePayload> {
1410
- return this.query<StatusResponsePayload>('STATUS', {});
1411
- }
1412
426
 
1413
- /**
1414
- * Get messages from the inbox.
1415
- * @param options - Filter options
1416
- * @param options.limit - Maximum number of messages to return
1417
- * @param options.unreadOnly - Only return unread messages
1418
- * @param options.from - Filter by sender
1419
- * @param options.channel - Filter by channel
1420
- * @returns Array of inbox messages
1421
- */
1422
- async getInbox(options: {
1423
- limit?: number;
1424
- unreadOnly?: boolean;
1425
- from?: string;
1426
- channel?: string;
1427
- } = {}): Promise<InboxMessage[]> {
1428
- const payload: InboxPayload = {
1429
- agent: this.config.agentName,
1430
- limit: options.limit,
1431
- unreadOnly: options.unreadOnly,
1432
- from: options.from,
1433
- channel: options.channel,
1434
- };
1435
- const response = await this.query<InboxResponsePayload>('INBOX', payload);
1436
- return response.messages || [];
1437
- }
1438
-
1439
- /**
1440
- * Query all messages (not filtered by recipient).
1441
- * Used by dashboard to get message history.
1442
- * @param options - Query options
1443
- * @param options.limit - Maximum number of messages to return (default: 100)
1444
- * @param options.sinceTs - Only return messages after this timestamp
1445
- * @param options.from - Filter by sender
1446
- * @param options.to - Filter by recipient
1447
- * @param options.thread - Filter by thread ID
1448
- * @param options.order - Sort order ('asc' or 'desc', default: 'desc')
1449
- * @returns Array of messages
1450
- */
1451
- async queryMessages(options: {
1452
- limit?: number;
1453
- sinceTs?: number;
1454
- from?: string;
1455
- to?: string;
1456
- thread?: string;
1457
- order?: 'asc' | 'desc';
1458
- } = {}): Promise<MessagesResponsePayload['messages']> {
1459
- const payload: MessagesQueryPayload = {
1460
- limit: options.limit,
1461
- sinceTs: options.sinceTs,
1462
- from: options.from,
1463
- to: options.to,
1464
- thread: options.thread,
1465
- order: options.order,
1466
- };
1467
- const response = await this.query<MessagesResponsePayload>('MESSAGES_QUERY', payload);
1468
- return response.messages || [];
1469
- }
1470
-
1471
- /**
1472
- * List online agents.
1473
- * @param options - Filter options
1474
- * @param options.includeIdle - Include idle agents (default: true)
1475
- * @param options.project - Filter by project
1476
- * @returns Array of agent info
1477
- */
1478
- async listAgents(options: {
1479
- includeIdle?: boolean;
1480
- project?: string;
1481
- } = {}): Promise<AgentInfo[]> {
1482
- const payload: ListAgentsPayload = {
1483
- includeIdle: options.includeIdle ?? true,
1484
- project: options.project,
1485
- };
1486
- const response = await this.query<ListAgentsResponsePayload>('LIST_AGENTS', payload);
1487
- return response.agents || [];
1488
- }
1489
-
1490
- /**
1491
- * Get system health information.
1492
- * @param options - Include options
1493
- * @param options.includeCrashes - Include crash history (default: true)
1494
- * @param options.includeAlerts - Include alerts (default: true)
1495
- * @returns Health information including score, issues, and recommendations
1496
- */
1497
- async getHealth(options: {
1498
- includeCrashes?: boolean;
1499
- includeAlerts?: boolean;
1500
- } = {}): Promise<HealthResponsePayload> {
1501
- const payload: HealthPayload = {
1502
- includeCrashes: options.includeCrashes ?? true,
1503
- includeAlerts: options.includeAlerts ?? true,
1504
- };
1505
- return this.query<HealthResponsePayload>('HEALTH', payload);
1506
- }
1507
-
1508
- /**
1509
- * Get resource metrics for agents.
1510
- * @param options - Filter options
1511
- * @param options.agent - Filter to a specific agent
1512
- * @returns Metrics including memory, CPU, and system info
1513
- */
1514
- async getMetrics(options: {
1515
- agent?: string;
1516
- } = {}): Promise<MetricsResponsePayload> {
1517
- const payload: MetricsPayload = {
1518
- agent: options.agent,
1519
- };
1520
- return this.query<MetricsResponsePayload>('METRICS', payload);
1521
- }
1522
-
1523
- /**
1524
- * List only currently connected agents (not historical/registered agents).
1525
- * Use this instead of listAgents() when you need accurate liveness information.
1526
- * @param options - Filter options
1527
- * @param options.project - Filter by project
1528
- * @returns Array of currently connected agent info
1529
- */
1530
- async listConnectedAgents(options: {
1531
- project?: string;
1532
- } = {}): Promise<AgentInfo[]> {
1533
- const payload: ListConnectedAgentsPayload = {
1534
- project: options.project,
1535
- };
1536
- const response = await this.query<ListConnectedAgentsResponsePayload>('LIST_CONNECTED_AGENTS', payload);
1537
- return response.agents || [];
1538
- }
1539
-
1540
- /**
1541
- * Remove an agent from the registry (sessions, agents.json).
1542
- * Use this to clean up stale agents that are no longer needed.
1543
- * @param name - Agent name to remove
1544
- * @param options - Removal options
1545
- * @param options.removeMessages - Also remove all messages from/to this agent (default: false)
1546
- * @returns Result indicating if the agent was removed
1547
- */
1548
- async removeAgent(name: string, options: {
1549
- removeMessages?: boolean;
1550
- } = {}): Promise<RemoveAgentResponsePayload> {
1551
- const payload: RemoveAgentPayload = {
1552
- name,
1553
- removeMessages: options.removeMessages,
1554
- };
1555
- return this.query<RemoveAgentResponsePayload>('REMOVE_AGENT', payload);
1556
- }
1557
-
1558
- // Private methods
427
+ this.exitPromise = new Promise<void>((resolve) => {
428
+ child.once('exit', (code, signal) => {
429
+ const detail = this.lastStderrLine ? `: ${this.lastStderrLine}` : '';
430
+ const error = new AgentRelayProcessError(
431
+ `broker exited (code=${code ?? 'null'}, signal=${signal ?? 'null'})${detail}`
432
+ );
433
+ this.failAllPending(error);
434
+ this.disposeProcessHandles();
435
+ resolve();
436
+ });
437
+ child.once('error', (error) => {
438
+ this.failAllPending(error);
439
+ this.disposeProcessHandles();
440
+ resolve();
441
+ });
442
+ });
1559
443
 
1560
- private setState(state: ClientState): void {
1561
- this._state = state;
1562
- if (this.onStateChange) {
1563
- this.onStateChange(state);
444
+ const helloAck = await this.requestHello();
445
+ console.log('[broker] Broker ready (hello handshake complete)');
446
+ if (helloAck.workspace_key) {
447
+ this.workspaceKey = helloAck.workspace_key;
1564
448
  }
1565
449
  }
1566
450
 
1567
- private sendHello(): void {
1568
- const hello: Envelope<HelloPayload> = {
1569
- v: PROTOCOL_VERSION,
1570
- type: 'HELLO',
1571
- id: generateId(),
1572
- ts: Date.now(),
1573
- payload: {
1574
- agent: this.config.agentName,
1575
- entityType: this.config.entityType,
1576
- cli: this.config.cli,
1577
- program: this.config.program,
1578
- model: this.config.model,
1579
- task: this.config.task,
1580
- workingDirectory: this.config.workingDirectory,
1581
- team: this.config.team,
1582
- displayName: this.config.displayName,
1583
- avatarUrl: this.config.avatarUrl,
1584
- capabilities: {
1585
- ack: true,
1586
- resume: true,
1587
- max_inflight: 256,
1588
- supports_topics: true,
1589
- },
1590
- session: this.resumeToken ? { resume_token: this.resumeToken } : undefined,
1591
- _isSystemComponent: this.config._isSystemComponent,
1592
- },
1593
- };
1594
-
1595
- this.send(hello);
1596
- }
1597
-
1598
- private send(envelope: Envelope): boolean {
1599
- if (!this.socket) return false;
1600
-
1601
- try {
1602
- const frame = encodeFrameLegacy(envelope);
1603
- this.writeQueue.push(frame);
1604
-
1605
- if (!this.writeScheduled) {
1606
- this.writeScheduled = true;
1607
- setImmediate(() => this.flushWrites());
1608
- }
1609
- return true;
1610
- } catch (err) {
1611
- this.handleError(err as Error);
1612
- return false;
1613
- }
451
+ private disposeProcessHandles(): void {
452
+ this.stdoutRl?.close();
453
+ this.stderrRl?.close();
454
+ this.stdoutRl = undefined;
455
+ this.stderrRl = undefined;
456
+ this.lastStderrLine = undefined;
457
+ this.child = undefined;
458
+ this.exitPromise = undefined;
1614
459
  }
1615
460
 
1616
- private flushWrites(): void {
1617
- this.writeScheduled = false;
1618
- if (this.writeQueue.length === 0 || !this.socket) return;
1619
-
1620
- if (this.writeQueue.length === 1) {
1621
- this.socket.write(this.writeQueue[0]);
1622
- } else {
1623
- this.socket.write(Buffer.concat(this.writeQueue));
461
+ private failAllPending(error: Error): void {
462
+ for (const pending of this.pending.values()) {
463
+ clearTimeout(pending.timeout);
464
+ pending.reject(error);
1624
465
  }
1625
- this.writeQueue = [];
466
+ this.pending.clear();
1626
467
  }
1627
468
 
1628
- private handleData(data: Buffer): void {
469
+ private handleStdoutLine(line: string): void {
470
+ let parsed: ParsedEnvelope;
1629
471
  try {
1630
- const frames = this.parser.push(data);
1631
- for (const frame of frames) {
1632
- this.processFrame(frame);
1633
- }
1634
- } catch (err) {
1635
- this.handleError(err as Error);
1636
- }
1637
- }
1638
-
1639
- private processFrame(envelope: Envelope): void {
1640
- switch (envelope.type) {
1641
- case 'WELCOME':
1642
- this.handleWelcome(envelope as Envelope<WelcomePayload>);
1643
- break;
1644
-
1645
- case 'DELIVER':
1646
- this.handleDeliver(envelope as DeliverEnvelope);
1647
- break;
1648
-
1649
- case 'CHANNEL_MESSAGE':
1650
- this.handleChannelMessage(envelope as Envelope<ChannelMessagePayload> & { from?: string });
1651
- break;
1652
-
1653
- case 'PING':
1654
- this.handlePing(envelope);
1655
- break;
1656
-
1657
- case 'ACK':
1658
- this.handleAck(envelope as Envelope<AckPayload>);
1659
- break;
1660
-
1661
- case 'SPAWN_RESULT':
1662
- this.handleSpawnResult(envelope as Envelope<SpawnResultPayload>);
1663
- break;
1664
-
1665
- case 'RELEASE_RESULT':
1666
- this.handleReleaseResult(envelope as Envelope<ReleaseResultPayload>);
1667
- break;
1668
-
1669
- case 'SEND_INPUT_RESULT':
1670
- this.handleSendInputResult(envelope as Envelope<SendInputResultPayload>);
1671
- break;
1672
-
1673
- case 'SET_MODEL_RESULT':
1674
- this.handleSetModelResult(envelope as Envelope<SetModelResultPayload>);
1675
- break;
1676
-
1677
- case 'LIST_WORKERS_RESULT':
1678
- this.handleListWorkersResult(envelope as Envelope<ListWorkersResultPayload>);
1679
- break;
1680
-
1681
- case 'AGENT_READY':
1682
- this.handleAgentReady(envelope as Envelope<AgentReadyPayload>);
1683
- break;
1684
-
1685
- case 'ERROR':
1686
- this.handleErrorFrame(envelope as Envelope<ErrorPayload>);
1687
- break;
1688
-
1689
- case 'BUSY':
1690
- if (!this.config.quiet) {
1691
- console.warn('[sdk] Server busy, backing off');
1692
- }
1693
- break;
1694
-
1695
- case 'STATUS_RESPONSE':
1696
- case 'INBOX_RESPONSE':
1697
- case 'MESSAGES_RESPONSE':
1698
- case 'LIST_AGENTS_RESPONSE':
1699
- case 'LIST_CONNECTED_AGENTS_RESPONSE':
1700
- case 'REMOVE_AGENT_RESPONSE':
1701
- case 'HEALTH_RESPONSE':
1702
- case 'METRICS_RESPONSE':
1703
- this.handleQueryResponse(envelope);
1704
- break;
472
+ parsed = JSON.parse(line) as ParsedEnvelope;
473
+ } catch {
474
+ // Non-protocol output should not crash the SDK.
475
+ return;
1705
476
  }
1706
- }
1707
477
 
1708
- private handleWelcome(envelope: Envelope<WelcomePayload>): void {
1709
- this.sessionId = envelope.payload.session_id;
1710
- this.resumeToken = envelope.payload.resume_token;
1711
- this.reconnectAttempts = 0;
1712
- this.reconnectDelay = this.config.reconnectDelayMs;
1713
- this.setState('READY');
1714
- if (!this.config.quiet) {
1715
- console.log(`[sdk] Connected as ${this.config.agentName} (session: ${this.sessionId})`);
478
+ if (!parsed || typeof parsed !== 'object') {
479
+ return;
1716
480
  }
1717
- }
1718
-
1719
- private handleDeliver(envelope: DeliverEnvelope): void {
1720
- // Send ACK
1721
- this.send({
1722
- v: PROTOCOL_VERSION,
1723
- type: 'ACK',
1724
- id: generateId(),
1725
- ts: Date.now(),
1726
- payload: {
1727
- ack_id: envelope.id,
1728
- seq: envelope.delivery.seq,
1729
- },
1730
- });
1731
-
1732
- const duplicate = this.dedupeCache.check(envelope.id);
1733
- if (duplicate) {
481
+ if (parsed.v !== PROTOCOL_VERSION || typeof parsed.type !== 'string') {
1734
482
  return;
1735
483
  }
1736
484
 
1737
- // Check if this is a response to a pending request
1738
- const correlationId = this.extractCorrelationId(envelope);
1739
- if (correlationId && envelope.from) {
1740
- const pending = this.pendingRequests.get(correlationId);
1741
- if (pending) {
1742
- // This is a response to our request
1743
- clearTimeout(pending.timeoutHandle);
1744
- this.pendingRequests.delete(correlationId);
1745
- pending.resolve({
1746
- from: envelope.from,
1747
- body: envelope.payload.body,
1748
- data: envelope.payload.data,
1749
- correlationId,
1750
- thread: envelope.payload.thread,
1751
- payload: envelope.payload,
1752
- });
1753
- // Still call onMessage so the app is aware of the response if needed
485
+ const envelope: ProtocolEnvelope<unknown> = {
486
+ v: parsed.v,
487
+ type: parsed.type,
488
+ request_id: parsed.request_id,
489
+ payload: parsed.payload,
490
+ };
491
+
492
+ if (envelope.type === 'event') {
493
+ const payload = envelope.payload as BrokerEvent;
494
+ this.eventBuffer.push(payload);
495
+ if (this.eventBuffer.length > this.maxBufferSize) {
496
+ this.eventBuffer.shift();
497
+ }
498
+ for (const listener of this.eventListeners) {
499
+ listener(payload);
1754
500
  }
501
+ return;
1755
502
  }
1756
503
 
1757
- if (this.onMessage && envelope.from) {
1758
- this.onMessage(
1759
- envelope.from,
1760
- envelope.payload,
1761
- envelope.id,
1762
- envelope.payload_meta,
1763
- envelope.delivery.originalTo
1764
- );
504
+ if (!envelope.request_id) {
505
+ return;
1765
506
  }
1766
- }
1767
507
 
1768
- /**
1769
- * Extract correlation ID from a delivered message.
1770
- * Checks both payload_meta.replyTo and payload.data._correlationId
1771
- */
1772
- private extractCorrelationId(envelope: DeliverEnvelope): string | undefined {
1773
- // Check payload_meta.replyTo first (the preferred location)
1774
- if (envelope.payload_meta?.replyTo) {
1775
- return envelope.payload_meta.replyTo;
1776
- }
1777
- // Fall back to checking data._correlationId
1778
- if (envelope.payload.data && typeof envelope.payload.data._correlationId === 'string') {
1779
- return envelope.payload.data._correlationId;
508
+ const pending = this.pending.get(envelope.request_id);
509
+ if (!pending) {
510
+ return;
1780
511
  }
1781
- return undefined;
1782
- }
1783
512
 
1784
- private handleChannelMessage(envelope: Envelope<ChannelMessagePayload> & { from?: string }): void {
1785
- const duplicate = this.dedupeCache.check(envelope.id);
1786
- if (duplicate) {
513
+ if (envelope.type === 'error') {
514
+ clearTimeout(pending.timeout);
515
+ this.pending.delete(envelope.request_id);
516
+ pending.reject(new AgentRelayProtocolError(envelope.payload as ProtocolError));
1787
517
  return;
1788
518
  }
1789
519
 
1790
- // Notify channel message handler
1791
- if (this.onChannelMessage && envelope.from) {
1792
- this.onChannelMessage(
1793
- envelope.from,
1794
- envelope.payload.channel,
1795
- envelope.payload.body,
1796
- envelope as Envelope<ChannelMessagePayload>
520
+ if (envelope.type !== pending.expectedType) {
521
+ clearTimeout(pending.timeout);
522
+ this.pending.delete(envelope.request_id);
523
+ pending.reject(
524
+ new AgentRelayProcessError(
525
+ `unexpected response type '${envelope.type}' for request '${envelope.request_id}' (expected '${pending.expectedType}')`
526
+ )
1797
527
  );
528
+ return;
1798
529
  }
1799
530
 
1800
- // Also call onMessage for backwards compatibility
1801
- if (this.onMessage && envelope.from) {
1802
- const sendPayload: SendPayload = {
1803
- kind: 'message',
1804
- body: envelope.payload.body,
1805
- data: {
1806
- _isChannelMessage: true,
1807
- _channel: envelope.payload.channel,
1808
- _mentions: envelope.payload.mentions,
1809
- },
1810
- thread: envelope.payload.thread,
1811
- };
1812
- this.onMessage(envelope.from, sendPayload, envelope.id, undefined, envelope.payload.channel);
1813
- }
1814
- }
1815
-
1816
- private handleAck(envelope: Envelope<AckPayload>): void {
1817
- const correlationId = envelope.payload.correlationId;
1818
- if (!correlationId) return;
1819
-
1820
- const pending = this.pendingSyncAcks.get(correlationId);
1821
- if (!pending) return;
1822
-
1823
- clearTimeout(pending.timeoutHandle);
1824
- this.pendingSyncAcks.delete(correlationId);
1825
- pending.resolve(envelope.payload);
531
+ clearTimeout(pending.timeout);
532
+ this.pending.delete(envelope.request_id);
533
+ pending.resolve(envelope);
1826
534
  }
1827
535
 
1828
- private handleSpawnResult(envelope: Envelope<SpawnResultPayload>): void {
1829
- const replyTo = envelope.payload.replyTo;
1830
- if (!replyTo) return;
1831
-
1832
- const pending = this.pendingSpawns.get(replyTo);
1833
- if (!pending) return;
1834
-
1835
- clearTimeout(pending.timeoutHandle);
1836
- this.pendingSpawns.delete(replyTo);
1837
- pending.resolve(envelope.payload);
1838
- }
1839
-
1840
- private handleReleaseResult(envelope: Envelope<ReleaseResultPayload>): void {
1841
- const replyTo = envelope.payload.replyTo;
1842
- if (!replyTo) return;
1843
-
1844
- const pending = this.pendingReleases.get(replyTo);
1845
- if (!pending) return;
1846
-
1847
- clearTimeout(pending.timeoutHandle);
1848
- this.pendingReleases.delete(replyTo);
1849
- pending.resolve(envelope.payload);
1850
- }
1851
-
1852
- private handleSendInputResult(envelope: Envelope<SendInputResultPayload>): void {
1853
- const replyTo = envelope.payload.replyTo;
1854
- if (!replyTo) return;
1855
-
1856
- const pending = this.pendingSendInputs.get(replyTo);
1857
- if (!pending) return;
1858
-
1859
- clearTimeout(pending.timeoutHandle);
1860
- this.pendingSendInputs.delete(replyTo);
1861
- pending.resolve(envelope.payload);
1862
- }
1863
-
1864
- private handleSetModelResult(envelope: Envelope<SetModelResultPayload>): void {
1865
- const replyTo = envelope.payload.replyTo;
1866
- if (!replyTo) return;
1867
-
1868
- const pending = this.pendingSetModels.get(replyTo);
1869
- if (!pending) return;
1870
-
1871
- clearTimeout(pending.timeoutHandle);
1872
- this.pendingSetModels.delete(replyTo);
1873
- pending.resolve(envelope.payload);
536
+ private async requestHello(): Promise<{ broker_version: string; protocol_version: number; workspace_key?: string }> {
537
+ const payload = {
538
+ client_name: this.options.clientName,
539
+ client_version: this.options.clientVersion,
540
+ };
541
+ const frame = await this.sendRequest('hello', payload, 'hello_ack');
542
+ return frame.payload as { broker_version: string; protocol_version: number; workspace_key?: string };
1874
543
  }
1875
544
 
1876
- private handleListWorkersResult(envelope: Envelope<ListWorkersResultPayload>): void {
1877
- const replyTo = envelope.payload.replyTo;
1878
- if (!replyTo) return;
1879
-
1880
- const pending = this.pendingListWorkers.get(replyTo);
1881
- if (!pending) return;
1882
-
1883
- clearTimeout(pending.timeoutHandle);
1884
- this.pendingListWorkers.delete(replyTo);
1885
- pending.resolve(envelope.payload);
545
+ private async requestOk<T = unknown>(type: string, payload: unknown): Promise<T> {
546
+ const frame = await this.sendRequest(type, payload, 'ok');
547
+ const result = frame.payload as { result: T };
548
+ return result.result;
1886
549
  }
1887
550
 
1888
- private handleAgentReady(envelope: Envelope<AgentReadyPayload>): void {
1889
- const agentName = envelope.payload.name;
1890
-
1891
- // Resolve any pending waitForReady promises for this agent
1892
- const pending = this.pendingAgentReady.get(agentName);
1893
- if (pending) {
1894
- clearTimeout(pending.timeoutHandle);
1895
- this.pendingAgentReady.delete(agentName);
1896
- pending.resolve(envelope.payload);
551
+ private async sendRequest(
552
+ type: string,
553
+ payload: unknown,
554
+ expectedType: 'ok' | 'hello_ack'
555
+ ): Promise<ProtocolEnvelope<unknown>> {
556
+ if (!this.child) {
557
+ throw new AgentRelayProcessError('broker is not running');
1897
558
  }
1898
559
 
1899
- // Call the onAgentReady callback if registered
1900
- if (this.onAgentReady) {
1901
- this.onAgentReady(envelope.payload);
1902
- }
1903
- }
1904
-
1905
- private handleQueryResponse(envelope: Envelope): void {
1906
- // Query responses use the envelope id to match requests
1907
- const pending = this.pendingQueries.get(envelope.id);
1908
- if (!pending) return;
560
+ const requestId = `req_${++this.requestSeq}`;
561
+ const message: ProtocolEnvelope<unknown> = {
562
+ v: PROTOCOL_VERSION,
563
+ type,
564
+ request_id: requestId,
565
+ payload,
566
+ };
1909
567
 
1910
- clearTimeout(pending.timeoutHandle);
1911
- this.pendingQueries.delete(envelope.id);
1912
- pending.resolve(envelope.payload);
1913
- }
568
+ const responsePromise = new Promise<ProtocolEnvelope<unknown>>((resolve, reject) => {
569
+ const timeout = setTimeout(() => {
570
+ this.pending.delete(requestId);
571
+ reject(
572
+ new AgentRelayProcessError(
573
+ `request timed out after ${this.options.requestTimeoutMs}ms (type='${type}', request_id='${requestId}')`
574
+ )
575
+ );
576
+ }, this.options.requestTimeoutMs);
1914
577
 
1915
- private handlePing(envelope: Envelope): void {
1916
- this.send({
1917
- v: PROTOCOL_VERSION,
1918
- type: 'PONG',
1919
- id: generateId(),
1920
- ts: Date.now(),
1921
- payload: (envelope.payload as { nonce?: string }) ?? {},
578
+ this.pending.set(requestId, {
579
+ expectedType,
580
+ resolve,
581
+ reject,
582
+ timeout,
583
+ });
1922
584
  });
1923
- }
1924
-
1925
- private handleErrorFrame(envelope: Envelope<ErrorPayload>): void {
1926
- if (!this.config.quiet) {
1927
- console.error('[sdk] Server error:', envelope.payload);
1928
- }
1929
585
 
1930
- if (envelope.payload.code === 'RESUME_TOO_OLD') {
1931
- this.resumeToken = undefined;
1932
- this.sessionId = undefined;
586
+ const line = `${JSON.stringify(message)}\n`;
587
+ if (!this.child.stdin.write(line)) {
588
+ await once(this.child.stdin, 'drain');
1933
589
  }
1934
590
 
1935
- // Fatal errors (like DUPLICATE_CONNECTION) should prevent reconnection
1936
- if (envelope.payload.fatal) {
1937
- if (!this.config.quiet) {
1938
- console.error('[sdk] Fatal error received, will not reconnect:', envelope.payload.message);
1939
- }
1940
- this._destroyed = true;
1941
- }
591
+ return responsePromise;
1942
592
  }
593
+ }
1943
594
 
1944
- private handleDisconnect(): void {
1945
- this.parser.reset();
1946
- this.socket = undefined;
1947
- this.rejectPendingSyncAcks(new Error('Disconnected while awaiting ACK'));
1948
- this.rejectPendingSpawns(new Error('Disconnected while awaiting spawn result'));
1949
- this.rejectPendingReleases(new Error('Disconnected while awaiting release result'));
1950
- this.rejectPendingSendInputs(new Error('Disconnected while awaiting send input result'));
1951
- this.rejectPendingSetModels(new Error('Disconnected while awaiting set model result'));
1952
- this.rejectPendingListWorkers(new Error('Disconnected while awaiting list workers result'));
1953
- this.rejectPendingQueries(new Error('Disconnected while awaiting query response'));
1954
- this.rejectPendingRequests(new Error('Disconnected while awaiting request response'));
1955
- this.rejectPendingAgentReady(new Error('Disconnected while awaiting agent ready'));
1956
-
1957
- if (this._destroyed) {
1958
- this.setState('DISCONNECTED');
1959
- return;
1960
- }
595
+ const CLI_MODEL_FLAG_CLIS = new Set(['claude', 'codex', 'gemini', 'goose', 'aider']);
1961
596
 
1962
- if (this.config.reconnect && this.reconnectAttempts < this.config.maxReconnectAttempts) {
1963
- this.scheduleReconnect();
1964
- } else {
1965
- this.setState('DISCONNECTED');
1966
- if (this.reconnectAttempts >= this.config.maxReconnectAttempts && !this.config.quiet) {
1967
- console.error(
1968
- `[sdk] Max reconnect attempts reached (${this.config.maxReconnectAttempts}), giving up`
1969
- );
1970
- }
1971
- }
1972
- }
597
+ const CLI_DEFAULT_ARGS: Record<string, string[]> = {
598
+ codex: ['-c', 'check_for_update_on_startup=false'],
599
+ };
1973
600
 
1974
- private handleError(error: Error): void {
1975
- if (!this.config.quiet) {
1976
- console.error('[sdk] Error:', error.message);
1977
- }
1978
- if (this.onError) {
1979
- this.onError(error);
1980
- }
601
+ function buildPtyArgsWithModel(cli: string, args: string[], model?: string): string[] {
602
+ const cliName = cli.split(':')[0].trim().toLowerCase();
603
+ const defaultArgs = CLI_DEFAULT_ARGS[cliName] ?? [];
604
+ const baseArgs = [...defaultArgs, ...args];
605
+ if (!model) {
606
+ return baseArgs;
1981
607
  }
1982
-
1983
- private rejectPendingSyncAcks(error: Error): void {
1984
- for (const [correlationId, pending] of this.pendingSyncAcks.entries()) {
1985
- clearTimeout(pending.timeoutHandle);
1986
- pending.reject(error);
1987
- this.pendingSyncAcks.delete(correlationId);
1988
- }
608
+ if (!CLI_MODEL_FLAG_CLIS.has(cliName)) {
609
+ return baseArgs;
1989
610
  }
1990
-
1991
- private rejectPendingSpawns(error: Error): void {
1992
- for (const [id, pending] of this.pendingSpawns.entries()) {
1993
- clearTimeout(pending.timeoutHandle);
1994
- pending.reject(error);
1995
- this.pendingSpawns.delete(id);
1996
- }
611
+ if (hasModelArg(baseArgs)) {
612
+ return baseArgs;
1997
613
  }
614
+ return ['--model', model, ...baseArgs];
615
+ }
1998
616
 
1999
- private rejectPendingReleases(error: Error): void {
2000
- for (const [id, pending] of this.pendingReleases.entries()) {
2001
- clearTimeout(pending.timeoutHandle);
2002
- pending.reject(error);
2003
- this.pendingReleases.delete(id);
617
+ function hasModelArg(args: string[]): boolean {
618
+ for (let i = 0; i < args.length; i += 1) {
619
+ const arg = args[i];
620
+ if (arg === '--model') {
621
+ return true;
2004
622
  }
2005
- }
2006
-
2007
- private rejectPendingSendInputs(error: Error): void {
2008
- for (const [id, pending] of this.pendingSendInputs.entries()) {
2009
- clearTimeout(pending.timeoutHandle);
2010
- pending.reject(error);
2011
- this.pendingSendInputs.delete(id);
623
+ if (arg.startsWith('--model=')) {
624
+ return true;
2012
625
  }
2013
626
  }
627
+ return false;
628
+ }
2014
629
 
2015
- private rejectPendingSetModels(error: Error): void {
2016
- for (const [id, pending] of this.pendingSetModels.entries()) {
2017
- clearTimeout(pending.timeoutHandle);
2018
- pending.reject(error);
2019
- this.pendingSetModels.delete(id);
2020
- }
630
+ function expandTilde(p: string): string {
631
+ if (p === '~' || p.startsWith('~/') || p.startsWith('~\\')) {
632
+ const home = os.homedir();
633
+ return path.join(home, p.slice(2));
2021
634
  }
635
+ return p;
636
+ }
2022
637
 
2023
- private rejectPendingListWorkers(error: Error): void {
2024
- for (const [id, pending] of this.pendingListWorkers.entries()) {
2025
- clearTimeout(pending.timeoutHandle);
2026
- pending.reject(error);
2027
- this.pendingListWorkers.delete(id);
2028
- }
2029
- }
638
+ function isExplicitPath(binaryPath: string): boolean {
639
+ return (
640
+ binaryPath.includes('/') ||
641
+ binaryPath.includes('\\') ||
642
+ binaryPath.startsWith('.') ||
643
+ binaryPath.startsWith('~')
644
+ );
645
+ }
2030
646
 
2031
- private rejectPendingQueries(error: Error): void {
2032
- for (const [id, pending] of this.pendingQueries.entries()) {
2033
- clearTimeout(pending.timeoutHandle);
2034
- pending.reject(error);
2035
- this.pendingQueries.delete(id);
2036
- }
2037
- }
647
+ function resolveDefaultBinaryPath(): string {
648
+ const brokerExe = process.platform === 'win32' ? 'agent-relay-broker.exe' : 'agent-relay-broker';
649
+ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
2038
650
 
2039
- private rejectPendingRequests(error: Error): void {
2040
- for (const [correlationId, pending] of this.pendingRequests.entries()) {
2041
- clearTimeout(pending.timeoutHandle);
2042
- pending.reject(error);
2043
- this.pendingRequests.delete(correlationId);
2044
- }
651
+ // 1. In a source checkout, prefer Cargo's release binary to avoid stale bundled
652
+ // copies when local dev rebuilds happen while broker processes are running.
653
+ const workspaceRelease = path.resolve(moduleDir, '..', '..', '..', 'target', 'release', brokerExe);
654
+ if (fs.existsSync(workspaceRelease)) {
655
+ return workspaceRelease;
2045
656
  }
2046
657
 
2047
- private rejectPendingAgentReady(error: Error): void {
2048
- for (const [agentName, pending] of this.pendingAgentReady.entries()) {
2049
- clearTimeout(pending.timeoutHandle);
2050
- pending.reject(error);
2051
- this.pendingAgentReady.delete(agentName);
2052
- }
658
+ // 2. Check for bundled broker binary in SDK package (npm install)
659
+ const bundled = path.resolve(moduleDir, '..', 'bin', brokerExe);
660
+ if (fs.existsSync(bundled)) {
661
+ return bundled;
2053
662
  }
2054
663
 
2055
- private scheduleReconnect(): void {
2056
- this.setState('BACKOFF');
2057
- this.reconnectAttempts++;
2058
-
2059
- const jitter = Math.random() * 0.3 + 0.85;
2060
- const delay = Math.min(this.reconnectDelay * jitter, this.config.reconnectMaxDelayMs);
2061
- this.reconnectDelay *= 2;
2062
-
2063
- if (!this.config.quiet) {
2064
- console.log(`[sdk] Reconnecting in ${Math.round(delay)}ms (attempt ${this.reconnectAttempts})`);
2065
- }
2066
-
2067
- this.reconnectTimer = setTimeout(() => {
2068
- this.connect().catch(() => {});
2069
- }, delay);
664
+ // 3. Check for standalone broker binary in ~/.agent-relay/bin/ (install.sh)
665
+ const homeDir = process.env.HOME || process.env.USERPROFILE || '';
666
+ const standaloneBroker = path.join(homeDir, '.agent-relay', 'bin', brokerExe);
667
+ if (fs.existsSync(standaloneBroker)) {
668
+ return standaloneBroker;
2070
669
  }
670
+
671
+ // 4. Fall back to agent-relay on PATH (may be Node CLI — will fail for broker ops)
672
+ return 'agent-relay';
2071
673
  }