agent-relay 3.0.2 → 3.1.1

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 (266) hide show
  1. package/README.md +8 -0
  2. package/bin/agent-relay-broker-linux-x64 +0 -0
  3. package/dist/index.cjs +273 -56
  4. package/dist/src/cli/commands/core.d.ts +2 -0
  5. package/dist/src/cli/commands/core.d.ts.map +1 -1
  6. package/dist/src/cli/commands/core.js +9 -2
  7. package/dist/src/cli/commands/core.js.map +1 -1
  8. package/dist/src/cli/lib/broker-lifecycle.d.ts.map +1 -1
  9. package/dist/src/cli/lib/broker-lifecycle.js +87 -28
  10. package/dist/src/cli/lib/broker-lifecycle.js.map +1 -1
  11. package/package.json +9 -9
  12. package/packages/acp-bridge/README.md +50 -67
  13. package/packages/acp-bridge/package.json +2 -2
  14. package/packages/config/package.json +1 -1
  15. package/packages/hooks/package.json +4 -4
  16. package/packages/memory/package.json +2 -2
  17. package/packages/openclaw/README.md +78 -0
  18. package/packages/openclaw/bin/relay-openclaw.mjs +2 -0
  19. package/packages/openclaw/bridge/bridge.mjs +305 -0
  20. package/packages/openclaw/dist/__tests__/gateway-threads.test.d.ts +2 -0
  21. package/packages/openclaw/dist/__tests__/gateway-threads.test.d.ts.map +1 -0
  22. package/packages/openclaw/dist/__tests__/gateway-threads.test.js +320 -0
  23. package/packages/openclaw/dist/__tests__/gateway-threads.test.js.map +1 -0
  24. package/packages/openclaw/dist/__tests__/naming.test.d.ts +2 -0
  25. package/packages/openclaw/dist/__tests__/naming.test.d.ts.map +1 -0
  26. package/packages/openclaw/dist/__tests__/naming.test.js +21 -0
  27. package/packages/openclaw/dist/__tests__/naming.test.js.map +1 -0
  28. package/packages/openclaw/dist/__tests__/spawn-manager.test.d.ts +2 -0
  29. package/packages/openclaw/dist/__tests__/spawn-manager.test.d.ts.map +1 -0
  30. package/packages/openclaw/dist/__tests__/spawn-manager.test.js +126 -0
  31. package/packages/openclaw/dist/__tests__/spawn-manager.test.js.map +1 -0
  32. package/packages/openclaw/dist/auth/converter.d.ts +28 -0
  33. package/packages/openclaw/dist/auth/converter.d.ts.map +1 -0
  34. package/packages/openclaw/dist/auth/converter.js +64 -0
  35. package/packages/openclaw/dist/auth/converter.js.map +1 -0
  36. package/packages/openclaw/dist/cli.d.ts +2 -0
  37. package/packages/openclaw/dist/cli.d.ts.map +1 -0
  38. package/packages/openclaw/dist/cli.js +230 -0
  39. package/packages/openclaw/dist/cli.js.map +1 -0
  40. package/packages/openclaw/dist/config.d.ts +27 -0
  41. package/packages/openclaw/dist/config.d.ts.map +1 -0
  42. package/packages/openclaw/dist/config.js +97 -0
  43. package/packages/openclaw/dist/config.js.map +1 -0
  44. package/packages/openclaw/dist/control.d.ts +22 -0
  45. package/packages/openclaw/dist/control.d.ts.map +1 -0
  46. package/packages/openclaw/dist/control.js +58 -0
  47. package/packages/openclaw/dist/control.js.map +1 -0
  48. package/packages/openclaw/dist/gateway.d.ts +71 -0
  49. package/packages/openclaw/dist/gateway.d.ts.map +1 -0
  50. package/packages/openclaw/dist/gateway.js +785 -0
  51. package/packages/openclaw/dist/gateway.js.map +1 -0
  52. package/packages/openclaw/dist/identity/contract.d.ts +11 -0
  53. package/packages/openclaw/dist/identity/contract.d.ts.map +1 -0
  54. package/packages/openclaw/dist/identity/contract.js +40 -0
  55. package/packages/openclaw/dist/identity/contract.js.map +1 -0
  56. package/packages/openclaw/dist/identity/files.d.ts +33 -0
  57. package/packages/openclaw/dist/identity/files.d.ts.map +1 -0
  58. package/packages/openclaw/dist/identity/files.js +145 -0
  59. package/packages/openclaw/dist/identity/files.js.map +1 -0
  60. package/packages/openclaw/dist/identity/model.d.ts +11 -0
  61. package/packages/openclaw/dist/identity/model.d.ts.map +1 -0
  62. package/packages/openclaw/dist/identity/model.js +28 -0
  63. package/packages/openclaw/dist/identity/model.js.map +1 -0
  64. package/packages/openclaw/dist/identity/naming.d.ts +5 -0
  65. package/packages/openclaw/dist/identity/naming.d.ts.map +1 -0
  66. package/packages/openclaw/dist/identity/naming.js +7 -0
  67. package/packages/openclaw/dist/identity/naming.js.map +1 -0
  68. package/packages/openclaw/dist/index.d.ts +20 -0
  69. package/packages/openclaw/dist/index.d.ts.map +1 -0
  70. package/packages/openclaw/dist/index.js +27 -0
  71. package/packages/openclaw/dist/index.js.map +1 -0
  72. package/packages/openclaw/dist/inject.d.ts +14 -0
  73. package/packages/openclaw/dist/inject.d.ts.map +1 -0
  74. package/packages/openclaw/dist/inject.js +66 -0
  75. package/packages/openclaw/dist/inject.js.map +1 -0
  76. package/packages/openclaw/dist/mcp/server.d.ts +8 -0
  77. package/packages/openclaw/dist/mcp/server.d.ts.map +1 -0
  78. package/packages/openclaw/dist/mcp/server.js +105 -0
  79. package/packages/openclaw/dist/mcp/server.js.map +1 -0
  80. package/packages/openclaw/dist/mcp/tools.d.ts +17 -0
  81. package/packages/openclaw/dist/mcp/tools.d.ts.map +1 -0
  82. package/packages/openclaw/dist/mcp/tools.js +145 -0
  83. package/packages/openclaw/dist/mcp/tools.js.map +1 -0
  84. package/packages/openclaw/dist/runtime/openclaw-config.d.ts +20 -0
  85. package/packages/openclaw/dist/runtime/openclaw-config.d.ts.map +1 -0
  86. package/packages/openclaw/dist/runtime/openclaw-config.js +50 -0
  87. package/packages/openclaw/dist/runtime/openclaw-config.js.map +1 -0
  88. package/packages/openclaw/dist/runtime/patch.d.ts +24 -0
  89. package/packages/openclaw/dist/runtime/patch.d.ts.map +1 -0
  90. package/packages/openclaw/dist/runtime/patch.js +92 -0
  91. package/packages/openclaw/dist/runtime/patch.js.map +1 -0
  92. package/packages/openclaw/dist/runtime/setup.d.ts +26 -0
  93. package/packages/openclaw/dist/runtime/setup.d.ts.map +1 -0
  94. package/packages/openclaw/dist/runtime/setup.js +58 -0
  95. package/packages/openclaw/dist/runtime/setup.js.map +1 -0
  96. package/packages/openclaw/dist/setup.d.ts +29 -0
  97. package/packages/openclaw/dist/setup.d.ts.map +1 -0
  98. package/packages/openclaw/dist/setup.js +300 -0
  99. package/packages/openclaw/dist/setup.js.map +1 -0
  100. package/packages/openclaw/dist/spawn/docker.d.ts +58 -0
  101. package/packages/openclaw/dist/spawn/docker.d.ts.map +1 -0
  102. package/packages/openclaw/dist/spawn/docker.js +222 -0
  103. package/packages/openclaw/dist/spawn/docker.js.map +1 -0
  104. package/packages/openclaw/dist/spawn/manager.d.ts +45 -0
  105. package/packages/openclaw/dist/spawn/manager.d.ts.map +1 -0
  106. package/packages/openclaw/dist/spawn/manager.js +140 -0
  107. package/packages/openclaw/dist/spawn/manager.js.map +1 -0
  108. package/packages/openclaw/dist/spawn/process.d.ts +16 -0
  109. package/packages/openclaw/dist/spawn/process.d.ts.map +1 -0
  110. package/packages/openclaw/dist/spawn/process.js +241 -0
  111. package/packages/openclaw/dist/spawn/process.js.map +1 -0
  112. package/packages/openclaw/dist/spawn/types.d.ts +42 -0
  113. package/packages/openclaw/dist/spawn/types.d.ts.map +1 -0
  114. package/packages/openclaw/dist/spawn/types.js +2 -0
  115. package/packages/openclaw/dist/spawn/types.js.map +1 -0
  116. package/packages/openclaw/dist/types.d.ts +37 -0
  117. package/packages/openclaw/dist/types.d.ts.map +1 -0
  118. package/packages/openclaw/dist/types.js +2 -0
  119. package/packages/openclaw/dist/types.js.map +1 -0
  120. package/packages/openclaw/package.json +63 -0
  121. package/packages/openclaw/skill/SKILL.md +194 -0
  122. package/packages/openclaw/src/__tests__/gateway-threads.test.ts +384 -0
  123. package/packages/openclaw/src/__tests__/naming.test.ts +24 -0
  124. package/packages/openclaw/src/__tests__/spawn-manager.test.ts +152 -0
  125. package/packages/openclaw/src/auth/converter.ts +90 -0
  126. package/packages/openclaw/src/cli.ts +269 -0
  127. package/packages/openclaw/src/config.ts +124 -0
  128. package/packages/openclaw/src/control.ts +100 -0
  129. package/packages/openclaw/src/gateway.ts +941 -0
  130. package/packages/openclaw/src/identity/contract.ts +44 -0
  131. package/packages/openclaw/src/identity/files.ts +198 -0
  132. package/packages/openclaw/src/identity/model.ts +27 -0
  133. package/packages/openclaw/src/identity/naming.ts +6 -0
  134. package/packages/openclaw/src/index.ts +59 -0
  135. package/packages/openclaw/src/inject.ts +77 -0
  136. package/packages/openclaw/src/mcp/server.ts +121 -0
  137. package/packages/openclaw/src/mcp/tools.ts +174 -0
  138. package/packages/openclaw/src/runtime/openclaw-config.ts +64 -0
  139. package/packages/openclaw/src/runtime/patch.ts +103 -0
  140. package/packages/openclaw/src/runtime/setup.ts +89 -0
  141. package/packages/openclaw/src/setup.ts +336 -0
  142. package/packages/openclaw/src/spawn/docker.ts +261 -0
  143. package/packages/openclaw/src/spawn/manager.ts +181 -0
  144. package/packages/openclaw/src/spawn/process.ts +272 -0
  145. package/packages/openclaw/src/spawn/types.ts +43 -0
  146. package/packages/openclaw/src/types.ts +38 -0
  147. package/packages/openclaw/templates/SOUL.md.template +34 -0
  148. package/packages/openclaw/tsconfig.json +12 -0
  149. package/packages/policy/package.json +2 -2
  150. package/packages/sdk/README.md +169 -64
  151. package/packages/sdk/dist/__tests__/contract-fixtures.test.js +76 -9
  152. package/packages/sdk/dist/__tests__/contract-fixtures.test.js.map +1 -1
  153. package/packages/sdk/dist/__tests__/integration.test.js +5 -4
  154. package/packages/sdk/dist/__tests__/integration.test.js.map +1 -1
  155. package/packages/sdk/dist/client.d.ts +34 -3
  156. package/packages/sdk/dist/client.d.ts.map +1 -1
  157. package/packages/sdk/dist/client.js +120 -10
  158. package/packages/sdk/dist/client.js.map +1 -1
  159. package/packages/sdk/dist/protocol.d.ts +7 -1
  160. package/packages/sdk/dist/protocol.d.ts.map +1 -1
  161. package/packages/sdk/dist/relay.d.ts +47 -11
  162. package/packages/sdk/dist/relay.d.ts.map +1 -1
  163. package/packages/sdk/dist/relay.js +114 -23
  164. package/packages/sdk/dist/relay.js.map +1 -1
  165. package/packages/sdk/dist/workflows/runner.d.ts.map +1 -1
  166. package/packages/sdk/dist/workflows/runner.js +71 -36
  167. package/packages/sdk/dist/workflows/runner.js.map +1 -1
  168. package/packages/sdk/dist/workflows/types.d.ts +1 -1
  169. package/packages/sdk/dist/workflows/types.d.ts.map +1 -1
  170. package/packages/sdk/package.json +2 -2
  171. package/packages/sdk/src/__tests__/contract-fixtures.test.ts +88 -9
  172. package/packages/sdk/src/__tests__/error-scenarios.test.ts +1 -1
  173. package/packages/sdk/src/__tests__/idle-nudge.test.ts +205 -257
  174. package/packages/sdk/src/__tests__/integration.test.ts +5 -4
  175. package/packages/sdk/src/__tests__/orchestration-upgrades.test.ts +277 -13
  176. package/packages/sdk/src/__tests__/swarm-coordinator.test.ts +1 -0
  177. package/packages/sdk/src/__tests__/workflow-runner.test.ts +67 -7
  178. package/packages/sdk/src/__tests__/workflow-trajectory.test.ts +4 -5
  179. package/packages/sdk/src/client.ts +171 -14
  180. package/packages/sdk/src/examples/workflows/runner-idle-refactor.yaml +306 -0
  181. package/packages/sdk/src/protocol.ts +7 -2
  182. package/packages/sdk/src/relay.ts +196 -34
  183. package/packages/sdk/src/workflows/runner.ts +73 -42
  184. package/packages/sdk/src/workflows/schema.json +1 -1
  185. package/packages/sdk/src/workflows/types.ts +1 -1
  186. package/packages/sdk/vitest.config.ts +1 -0
  187. package/packages/sdk-py/README.md +89 -102
  188. package/packages/sdk-py/agent_relay/__init__.py +16 -19
  189. package/packages/sdk-py/pyproject.toml +5 -1
  190. package/packages/sdk-py/src/agent_relay/__init__.py +35 -1
  191. package/packages/sdk-py/src/agent_relay/client.py +776 -0
  192. package/packages/sdk-py/src/agent_relay/models.py +27 -0
  193. package/packages/sdk-py/src/agent_relay/protocol.py +114 -0
  194. package/packages/sdk-py/src/agent_relay/relay.py +860 -0
  195. package/packages/sdk-py/tests/test_relay_lifecycle_hooks.py +250 -0
  196. package/packages/telemetry/package.json +1 -1
  197. package/packages/trajectory/package.json +2 -2
  198. package/packages/user-directory/package.json +2 -2
  199. package/packages/utils/package.json +2 -2
  200. package/bin/agent-relay-broker-darwin-arm64 +0 -0
  201. package/bin/agent-relay-broker-darwin-x64 +0 -0
  202. package/bin/agent-relay-broker-linux-arm64 +0 -0
  203. package/packages/sdk/.trajectories/active/traj_1771875803391_84ca57b2.json +0 -50
  204. package/packages/sdk/.trajectories/active/traj_1771891934534_06504121.json +0 -50
  205. package/packages/sdk/.trajectories/active/traj_1771891957929_211afc4e.json +0 -50
  206. package/packages/sdk/.trajectories/active/traj_1771891982509_38c84638.json +0 -50
  207. package/packages/sdk/.trajectories/completed/traj_1771875803188_cd6d181c.json +0 -80
  208. package/packages/sdk/.trajectories/completed/traj_1771875803204_f2aeb8c8.json +0 -80
  209. package/packages/sdk/.trajectories/completed/traj_1771875803210_d65f3f1a.json +0 -80
  210. package/packages/sdk/.trajectories/completed/traj_1771875803218_e454a25d.json +0 -80
  211. package/packages/sdk/.trajectories/completed/traj_1771875803223_d7a64815.json +0 -80
  212. package/packages/sdk/.trajectories/completed/traj_1771875803227_7e56da5b.json +0 -80
  213. package/packages/sdk/.trajectories/completed/traj_1771875803235_4fbf93b4.json +0 -80
  214. package/packages/sdk/.trajectories/completed/traj_1771875803243_47931c71.json +0 -80
  215. package/packages/sdk/.trajectories/completed/traj_1771875803258_3816f3fe.json +0 -80
  216. package/packages/sdk/.trajectories/completed/traj_1771875803268_8061140e.json +0 -80
  217. package/packages/sdk/.trajectories/completed/traj_1771875803326_ae6f9c78.json +0 -80
  218. package/packages/sdk/.trajectories/completed/traj_1771875808396_cbde0a6c.json +0 -91
  219. package/packages/sdk/.trajectories/completed/traj_1771875812026_aa2442bb.json +0 -91
  220. package/packages/sdk/.trajectories/completed/traj_1771875815431_c2c656c5.json +0 -91
  221. package/packages/sdk/.trajectories/completed/traj_1771875818645_3a4dbf02.json +0 -91
  222. package/packages/sdk/.trajectories/completed/traj_1771891934403_24923c03.json +0 -80
  223. package/packages/sdk/.trajectories/completed/traj_1771891934421_dca16e24.json +0 -80
  224. package/packages/sdk/.trajectories/completed/traj_1771891934430_057706f7.json +0 -80
  225. package/packages/sdk/.trajectories/completed/traj_1771891934442_faf97382.json +0 -80
  226. package/packages/sdk/.trajectories/completed/traj_1771891934454_5542ecd5.json +0 -80
  227. package/packages/sdk/.trajectories/completed/traj_1771891934464_12202a08.json +0 -80
  228. package/packages/sdk/.trajectories/completed/traj_1771891934487_94378275.json +0 -80
  229. package/packages/sdk/.trajectories/completed/traj_1771891934503_ca728c13.json +0 -80
  230. package/packages/sdk/.trajectories/completed/traj_1771891934519_100af69a.json +0 -80
  231. package/packages/sdk/.trajectories/completed/traj_1771891934536_62ad39d9.json +0 -80
  232. package/packages/sdk/.trajectories/completed/traj_1771891934553_d6798a52.json +0 -80
  233. package/packages/sdk/.trajectories/completed/traj_1771891939537_541c8096.json +0 -91
  234. package/packages/sdk/.trajectories/completed/traj_1771891942985_36ab9a4d.json +0 -91
  235. package/packages/sdk/.trajectories/completed/traj_1771891946453_e8a6e05f.json +0 -91
  236. package/packages/sdk/.trajectories/completed/traj_1771891949838_5de0de84.json +0 -91
  237. package/packages/sdk/.trajectories/completed/traj_1771891957807_0ecfb4f4.json +0 -80
  238. package/packages/sdk/.trajectories/completed/traj_1771891957827_c4539239.json +0 -80
  239. package/packages/sdk/.trajectories/completed/traj_1771891957836_91168b48.json +0 -80
  240. package/packages/sdk/.trajectories/completed/traj_1771891957848_8c5cad0b.json +0 -80
  241. package/packages/sdk/.trajectories/completed/traj_1771891957857_0986b293.json +0 -80
  242. package/packages/sdk/.trajectories/completed/traj_1771891957872_8a3113af.json +0 -80
  243. package/packages/sdk/.trajectories/completed/traj_1771891957884_0bb85208.json +0 -80
  244. package/packages/sdk/.trajectories/completed/traj_1771891957892_86c75e2e.json +0 -80
  245. package/packages/sdk/.trajectories/completed/traj_1771891957907_98ca0e6f.json +0 -80
  246. package/packages/sdk/.trajectories/completed/traj_1771891957918_d9091231.json +0 -80
  247. package/packages/sdk/.trajectories/completed/traj_1771891957931_dcaf77ed.json +0 -80
  248. package/packages/sdk/.trajectories/completed/traj_1771891962931_eb1fdee2.json +0 -91
  249. package/packages/sdk/.trajectories/completed/traj_1771891966262_9061a93f.json +0 -91
  250. package/packages/sdk/.trajectories/completed/traj_1771891969915_1adaba19.json +0 -91
  251. package/packages/sdk/.trajectories/completed/traj_1771891973588_f08b79e9.json +0 -91
  252. package/packages/sdk/.trajectories/completed/traj_1771891982421_f1985bce.json +0 -80
  253. package/packages/sdk/.trajectories/completed/traj_1771891982432_e7a84163.json +0 -80
  254. package/packages/sdk/.trajectories/completed/traj_1771891982447_369b842a.json +0 -80
  255. package/packages/sdk/.trajectories/completed/traj_1771891982469_5fc45199.json +0 -80
  256. package/packages/sdk/.trajectories/completed/traj_1771891982495_454c7cb3.json +0 -80
  257. package/packages/sdk/.trajectories/completed/traj_1771891982514_08098e03.json +0 -80
  258. package/packages/sdk/.trajectories/completed/traj_1771891982526_b351d778.json +0 -80
  259. package/packages/sdk/.trajectories/completed/traj_1771891982533_fa542d83.json +0 -80
  260. package/packages/sdk/.trajectories/completed/traj_1771891982540_18ab24dc.json +0 -80
  261. package/packages/sdk/.trajectories/completed/traj_1771891982544_5b4fa163.json +0 -80
  262. package/packages/sdk/.trajectories/completed/traj_1771891982548_c13f089a.json +0 -80
  263. package/packages/sdk/.trajectories/completed/traj_1771891987510_23f6da1f.json +0 -91
  264. package/packages/sdk/.trajectories/completed/traj_1771891991466_912c2e04.json +0 -91
  265. package/packages/sdk/.trajectories/completed/traj_1771891994891_60604be2.json +0 -91
  266. package/packages/sdk/.trajectories/completed/traj_1771891998370_cfaf9b8b.json +0 -91
@@ -0,0 +1,250 @@
1
+ """Tests for spawn/release lifecycle hooks in the high-level relay facade."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ from unittest.mock import AsyncMock
7
+
8
+ import pytest
9
+
10
+ from agent_relay import AgentRelay, SpawnOptions
11
+
12
+
13
+ class _FakeRelayClient:
14
+ def __init__(self) -> None:
15
+ self.spawn_error: Exception | None = None
16
+ self.release_error: Exception | None = None
17
+ self.spawn_calls: list[dict] = []
18
+ self.release_calls: list[tuple[str, str | None]] = []
19
+
20
+ async def spawn_pty(self, **kwargs):
21
+ self.spawn_calls.append(kwargs)
22
+ if self.spawn_error:
23
+ raise self.spawn_error
24
+ return {"name": kwargs["name"], "runtime": "pty"}
25
+
26
+ async def release(self, name: str, reason: str | None = None):
27
+ self.release_calls.append((name, reason))
28
+ if self.release_error:
29
+ raise self.release_error
30
+ return {"name": name}
31
+
32
+
33
+ @pytest.mark.asyncio
34
+ async def test_spawn_lifecycle_hooks_success():
35
+ relay = AgentRelay()
36
+ client = _FakeRelayClient()
37
+ relay._ensure_started = AsyncMock(return_value=client)
38
+
39
+ events: list[tuple[str, dict]] = []
40
+ options = SpawnOptions(
41
+ channels=["general"],
42
+ on_start=lambda ctx: events.append(("start", dict(ctx))),
43
+ on_success=lambda ctx: events.append(("success", dict(ctx))),
44
+ on_error=lambda ctx: events.append(("error", dict(ctx))),
45
+ )
46
+
47
+ agent = await relay.spawn("HookWorker", "claude", "Do the work", options)
48
+
49
+ assert agent.name == "HookWorker"
50
+ assert events[0] == (
51
+ "start",
52
+ {
53
+ "name": "HookWorker",
54
+ "cli": "claude",
55
+ "channels": ["general"],
56
+ "task": "Do the work",
57
+ },
58
+ )
59
+ assert events[1] == (
60
+ "success",
61
+ {
62
+ "name": "HookWorker",
63
+ "cli": "claude",
64
+ "channels": ["general"],
65
+ "task": "Do the work",
66
+ "runtime": "pty",
67
+ },
68
+ )
69
+ assert len(events) == 2
70
+
71
+
72
+ @pytest.mark.asyncio
73
+ async def test_spawn_lifecycle_hooks_support_async_callbacks():
74
+ relay = AgentRelay()
75
+ client = _FakeRelayClient()
76
+ relay._ensure_started = AsyncMock(return_value=client)
77
+
78
+ start_done = False
79
+ success_done = False
80
+
81
+ async def on_start(_ctx):
82
+ nonlocal start_done
83
+ await asyncio.sleep(0)
84
+ start_done = True
85
+
86
+ async def on_success(_ctx):
87
+ nonlocal success_done
88
+ await asyncio.sleep(0)
89
+ success_done = True
90
+
91
+ options = SpawnOptions(
92
+ channels=["general"],
93
+ on_start=on_start,
94
+ on_success=on_success,
95
+ )
96
+
97
+ await relay.spawn("AsyncHookWorker", "claude", "Do the work", options)
98
+
99
+ assert start_done is True
100
+ assert success_done is True
101
+
102
+
103
+ @pytest.mark.asyncio
104
+ async def test_spawn_lifecycle_hooks_error():
105
+ relay = AgentRelay()
106
+ client = _FakeRelayClient()
107
+ client.spawn_error = RuntimeError("spawn failed")
108
+ relay._ensure_started = AsyncMock(return_value=client)
109
+
110
+ on_error_calls: list[dict] = []
111
+ options = SpawnOptions(
112
+ channels=["general"],
113
+ on_start=lambda _: None,
114
+ on_error=lambda ctx: on_error_calls.append(dict(ctx)),
115
+ )
116
+
117
+ with pytest.raises(RuntimeError, match="spawn failed"):
118
+ await relay.spawn("HookWorkerFail", "claude", "Do the work", options)
119
+
120
+ assert len(on_error_calls) == 1
121
+ error_ctx = on_error_calls[0]
122
+ assert error_ctx["name"] == "HookWorkerFail"
123
+ assert error_ctx["cli"] == "claude"
124
+ assert isinstance(error_ctx["error"], RuntimeError)
125
+
126
+
127
+ @pytest.mark.asyncio
128
+ async def test_shorthand_spawn_lifecycle_hooks_success():
129
+ relay = AgentRelay()
130
+ client = _FakeRelayClient()
131
+ relay._ensure_started = AsyncMock(return_value=client)
132
+
133
+ events: list[str] = []
134
+ agent = await relay.claude.spawn(
135
+ name="ShorthandWorker",
136
+ channels=["general"],
137
+ task="Run analysis",
138
+ on_start=lambda _: events.append("start"),
139
+ on_success=lambda _: events.append("success"),
140
+ on_error=lambda _: events.append("error"),
141
+ )
142
+
143
+ assert agent.name == "ShorthandWorker"
144
+ assert events == ["start", "success"]
145
+
146
+
147
+ @pytest.mark.asyncio
148
+ async def test_shorthand_spawn_does_not_fire_start_hook_if_broker_startup_fails():
149
+ relay = AgentRelay()
150
+ relay._ensure_started = AsyncMock(side_effect=RuntimeError("broker startup failed"))
151
+
152
+ start_called = False
153
+ error_called = False
154
+
155
+ def _mark_called(kind: str) -> None:
156
+ nonlocal start_called, error_called
157
+ if kind == "start":
158
+ start_called = True
159
+ else:
160
+ error_called = True
161
+
162
+ with pytest.raises(RuntimeError, match="broker startup failed"):
163
+ await relay.claude.spawn(
164
+ name="ShorthandWorkerStartupFail",
165
+ channels=["general"],
166
+ on_start=lambda _ctx: _mark_called("start"),
167
+ on_error=lambda _ctx: _mark_called("error"),
168
+ )
169
+
170
+ assert start_called is False
171
+ assert error_called is False
172
+
173
+
174
+ @pytest.mark.asyncio
175
+ async def test_release_lifecycle_hooks_success_and_error():
176
+ relay = AgentRelay()
177
+ client = _FakeRelayClient()
178
+ relay._ensure_started = AsyncMock(return_value=client)
179
+
180
+ agent = await relay.spawn("ReleaseWorker", "claude")
181
+
182
+ success_events: list[str] = []
183
+ await agent.release(
184
+ "cleanup",
185
+ on_start=lambda _: success_events.append("start"),
186
+ on_success=lambda _: success_events.append("success"),
187
+ on_error=lambda _: success_events.append("error"),
188
+ )
189
+
190
+ assert client.release_calls[-1] == ("ReleaseWorker", "cleanup")
191
+ assert success_events == ["start", "success"]
192
+
193
+ client.release_error = RuntimeError("release failed")
194
+ error_calls: list[dict] = []
195
+ with pytest.raises(RuntimeError, match="release failed"):
196
+ await agent.release(
197
+ "cleanup-again",
198
+ on_error=lambda ctx: error_calls.append(dict(ctx)),
199
+ )
200
+
201
+ assert len(error_calls) == 1
202
+ assert error_calls[0]["name"] == "ReleaseWorker"
203
+ assert isinstance(error_calls[0]["error"], RuntimeError)
204
+
205
+
206
+ @pytest.mark.asyncio
207
+ async def test_release_lifecycle_hooks_support_async_callbacks():
208
+ relay = AgentRelay()
209
+ client = _FakeRelayClient()
210
+ relay._ensure_started = AsyncMock(return_value=client)
211
+
212
+ agent = await relay.spawn("ReleaseAsyncWorker", "claude")
213
+
214
+ success_done = False
215
+
216
+ async def on_success(_ctx):
217
+ nonlocal success_done
218
+ await asyncio.sleep(0)
219
+ success_done = True
220
+
221
+ await agent.release("cleanup", on_success=on_success)
222
+
223
+ assert success_done is True
224
+
225
+
226
+ @pytest.mark.asyncio
227
+ async def test_release_does_not_fire_hooks_if_broker_startup_fails():
228
+ relay = AgentRelay()
229
+ client = _FakeRelayClient()
230
+ relay._ensure_started = AsyncMock(return_value=client)
231
+ agent = await relay.spawn("ReleaseStartupFailWorker", "claude")
232
+
233
+ relay._ensure_started = AsyncMock(side_effect=RuntimeError("broker startup failed"))
234
+
235
+ start_called = False
236
+ error_called = False
237
+
238
+ def mark_start(_ctx):
239
+ nonlocal start_called
240
+ start_called = True
241
+
242
+ def mark_error(_ctx):
243
+ nonlocal error_called
244
+ error_called = True
245
+
246
+ with pytest.raises(RuntimeError, match="broker startup failed"):
247
+ await agent.release("cleanup", on_start=mark_start, on_error=mark_error)
248
+
249
+ assert start_called is False
250
+ assert error_called is False
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/telemetry",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "description": "Anonymous telemetry for Agent Relay usage analytics",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/trajectory",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "description": "Trajectory integration utilities (trail/PDERO) for Relay",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "vitest"
23
23
  },
24
24
  "dependencies": {
25
- "@agent-relay/config": "3.0.2"
25
+ "@agent-relay/config": "3.1.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.19.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/user-directory",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "description": "User directory service for agent-relay (per-user credential storage)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "vitest"
23
23
  },
24
24
  "dependencies": {
25
- "@agent-relay/utils": "3.0.2"
25
+ "@agent-relay/utils": "3.1.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.19.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/utils",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "description": "Shared utilities for agent-relay: logging, name generation, command resolution, update checking",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",
@@ -112,7 +112,7 @@
112
112
  "vitest": "^3.2.4"
113
113
  },
114
114
  "dependencies": {
115
- "@agent-relay/config": "3.0.2",
115
+ "@agent-relay/config": "3.1.1",
116
116
  "compare-versions": "^6.1.1"
117
117
  },
118
118
  "publishConfig": {
Binary file
Binary file
Binary file
@@ -1,50 +0,0 @@
1
- {
2
- "id": "traj_1771875803391_84ca57b2",
3
- "version": 1,
4
- "task": {
5
- "title": "default run #18889026",
6
- "source": {
7
- "system": "workflow-runner",
8
- "id": "188890267c8264bd0f5a7422"
9
- }
10
- },
11
- "status": "active",
12
- "startedAt": "2026-02-23T19:43:23.391Z",
13
- "agents": [
14
- {
15
- "name": "orchestrator",
16
- "role": "workflow-runner",
17
- "joinedAt": "2026-02-23T19:43:23.391Z"
18
- },
19
- {
20
- "name": "agent-a",
21
- "role": "agent-a",
22
- "joinedAt": "2026-02-23T19:43:28.180Z"
23
- }
24
- ],
25
- "chapters": [
26
- {
27
- "id": "ch_ed619507",
28
- "title": "Planning",
29
- "agentName": "orchestrator",
30
- "startedAt": "2026-02-23T19:43:23.391Z",
31
- "events": [
32
- {
33
- "ts": 1771875803391,
34
- "type": "note",
35
- "content": "Workflow \"default\" started with 2 steps"
36
- },
37
- {
38
- "ts": 1771875803391,
39
- "type": "note",
40
- "content": "Parsed 2 steps, 1 dependent steps, DAG validated, no cycles"
41
- },
42
- {
43
- "ts": 1771875808180,
44
- "type": "note",
45
- "content": "Step \"step-1\" assigned to agent \"agent-a\""
46
- }
47
- ]
48
- }
49
- ]
50
- }
@@ -1,50 +0,0 @@
1
- {
2
- "id": "traj_1771891934534_06504121",
3
- "version": 1,
4
- "task": {
5
- "title": "default run #0a780183",
6
- "source": {
7
- "system": "workflow-runner",
8
- "id": "0a780183edfa9ba0236202fe"
9
- }
10
- },
11
- "status": "active",
12
- "startedAt": "2026-02-24T00:12:14.534Z",
13
- "agents": [
14
- {
15
- "name": "orchestrator",
16
- "role": "workflow-runner",
17
- "joinedAt": "2026-02-24T00:12:14.534Z"
18
- },
19
- {
20
- "name": "agent-a",
21
- "role": "agent-a",
22
- "joinedAt": "2026-02-24T00:12:19.066Z"
23
- }
24
- ],
25
- "chapters": [
26
- {
27
- "id": "ch_1558a41b",
28
- "title": "Planning",
29
- "agentName": "orchestrator",
30
- "startedAt": "2026-02-24T00:12:14.534Z",
31
- "events": [
32
- {
33
- "ts": 1771891934534,
34
- "type": "note",
35
- "content": "Workflow \"default\" started with 2 steps"
36
- },
37
- {
38
- "ts": 1771891934534,
39
- "type": "note",
40
- "content": "Parsed 2 steps, 1 dependent steps, DAG validated, no cycles"
41
- },
42
- {
43
- "ts": 1771891939066,
44
- "type": "note",
45
- "content": "Step \"step-1\" assigned to agent \"agent-a\""
46
- }
47
- ]
48
- }
49
- ]
50
- }
@@ -1,50 +0,0 @@
1
- {
2
- "id": "traj_1771891957929_211afc4e",
3
- "version": 1,
4
- "task": {
5
- "title": "default run #e0eb8bb0",
6
- "source": {
7
- "system": "workflow-runner",
8
- "id": "e0eb8bb09b4f17b228b7b97c"
9
- }
10
- },
11
- "status": "active",
12
- "startedAt": "2026-02-24T00:12:37.929Z",
13
- "agents": [
14
- {
15
- "name": "orchestrator",
16
- "role": "workflow-runner",
17
- "joinedAt": "2026-02-24T00:12:37.929Z"
18
- },
19
- {
20
- "name": "agent-a",
21
- "role": "agent-a",
22
- "joinedAt": "2026-02-24T00:12:41.616Z"
23
- }
24
- ],
25
- "chapters": [
26
- {
27
- "id": "ch_ab277099",
28
- "title": "Planning",
29
- "agentName": "orchestrator",
30
- "startedAt": "2026-02-24T00:12:37.929Z",
31
- "events": [
32
- {
33
- "ts": 1771891957929,
34
- "type": "note",
35
- "content": "Workflow \"default\" started with 2 steps"
36
- },
37
- {
38
- "ts": 1771891957929,
39
- "type": "note",
40
- "content": "Parsed 2 steps, 1 dependent steps, DAG validated, no cycles"
41
- },
42
- {
43
- "ts": 1771891961616,
44
- "type": "note",
45
- "content": "Step \"step-1\" assigned to agent \"agent-a\""
46
- }
47
- ]
48
- }
49
- ]
50
- }
@@ -1,50 +0,0 @@
1
- {
2
- "id": "traj_1771891982509_38c84638",
3
- "version": 1,
4
- "task": {
5
- "title": "default run #1fe87646",
6
- "source": {
7
- "system": "workflow-runner",
8
- "id": "1fe87646b1d24cb6ee8c31b9"
9
- }
10
- },
11
- "status": "active",
12
- "startedAt": "2026-02-24T00:13:02.509Z",
13
- "agents": [
14
- {
15
- "name": "orchestrator",
16
- "role": "workflow-runner",
17
- "joinedAt": "2026-02-24T00:13:02.509Z"
18
- },
19
- {
20
- "name": "agent-a",
21
- "role": "agent-a",
22
- "joinedAt": "2026-02-24T00:13:05.944Z"
23
- }
24
- ],
25
- "chapters": [
26
- {
27
- "id": "ch_8bc7d236",
28
- "title": "Planning",
29
- "agentName": "orchestrator",
30
- "startedAt": "2026-02-24T00:13:02.509Z",
31
- "events": [
32
- {
33
- "ts": 1771891982509,
34
- "type": "note",
35
- "content": "Workflow \"default\" started with 2 steps"
36
- },
37
- {
38
- "ts": 1771891982509,
39
- "type": "note",
40
- "content": "Parsed 2 steps, 1 dependent steps, DAG validated, no cycles"
41
- },
42
- {
43
- "ts": 1771891985944,
44
- "type": "note",
45
- "content": "Step \"step-1\" assigned to agent \"agent-a\""
46
- }
47
- ]
48
- }
49
- ]
50
- }
@@ -1,80 +0,0 @@
1
- {
2
- "id": "traj_1771875803188_cd6d181c",
3
- "version": 1,
4
- "task": {
5
- "title": "default run #f1ef6db7",
6
- "source": {
7
- "system": "workflow-runner",
8
- "id": "f1ef6db787ae83da31837011"
9
- }
10
- },
11
- "status": "completed",
12
- "startedAt": "2026-02-23T19:43:23.188Z",
13
- "agents": [
14
- {
15
- "name": "orchestrator",
16
- "role": "workflow-runner",
17
- "joinedAt": "2026-02-23T19:43:23.188Z"
18
- },
19
- {
20
- "name": "agent-a",
21
- "role": "agent-a",
22
- "joinedAt": "2026-02-23T19:43:23.194Z"
23
- }
24
- ],
25
- "chapters": [
26
- {
27
- "id": "ch_aa683478",
28
- "title": "Planning",
29
- "agentName": "orchestrator",
30
- "startedAt": "2026-02-23T19:43:23.188Z",
31
- "events": [
32
- {
33
- "ts": 1771875803189,
34
- "type": "note",
35
- "content": "Workflow \"default\" started with 1 steps"
36
- },
37
- {
38
- "ts": 1771875803189,
39
- "type": "note",
40
- "content": "Parsed 1 steps, DAG validated, no cycles"
41
- },
42
- {
43
- "ts": 1771875803194,
44
- "type": "note",
45
- "content": "Step \"step-1\" assigned to agent \"agent-a\""
46
- },
47
- {
48
- "ts": 1771875803200,
49
- "type": "finding",
50
- "content": "Step \"step-1\" completed: Agent exited (exited)",
51
- "significance": "medium"
52
- }
53
- ],
54
- "endedAt": "2026-02-23T19:43:23.201Z"
55
- },
56
- {
57
- "id": "ch_ea90fb42",
58
- "title": "Retrospective",
59
- "agentName": "orchestrator",
60
- "startedAt": "2026-02-23T19:43:23.202Z",
61
- "events": [
62
- {
63
- "ts": 1771875803202,
64
- "type": "reflection",
65
- "content": "Workflow completed in 0 seconds. 1/1 steps passed. (completed in 0 seconds)",
66
- "significance": "high"
67
- }
68
- ],
69
- "endedAt": "2026-02-23T19:43:23.202Z"
70
- }
71
- ],
72
- "completedAt": "2026-02-23T19:43:23.202Z",
73
- "retrospective": {
74
- "summary": "Workflow completed in 0 seconds. 1/1 steps passed.",
75
- "approach": "workflow-runner DAG execution",
76
- "confidence": 0.75,
77
- "learnings": [],
78
- "challenges": []
79
- }
80
- }
@@ -1,80 +0,0 @@
1
- {
2
- "id": "traj_1771875803204_f2aeb8c8",
3
- "version": 1,
4
- "task": {
5
- "title": "default run #8dcb0f8f",
6
- "source": {
7
- "system": "workflow-runner",
8
- "id": "8dcb0f8f3997ff66b1441525"
9
- }
10
- },
11
- "status": "completed",
12
- "startedAt": "2026-02-23T19:43:23.204Z",
13
- "agents": [
14
- {
15
- "name": "orchestrator",
16
- "role": "workflow-runner",
17
- "joinedAt": "2026-02-23T19:43:23.204Z"
18
- },
19
- {
20
- "name": "agent-a",
21
- "role": "agent-a",
22
- "joinedAt": "2026-02-23T19:43:23.205Z"
23
- }
24
- ],
25
- "chapters": [
26
- {
27
- "id": "ch_4ec95d3b",
28
- "title": "Planning",
29
- "agentName": "orchestrator",
30
- "startedAt": "2026-02-23T19:43:23.204Z",
31
- "events": [
32
- {
33
- "ts": 1771875803204,
34
- "type": "note",
35
- "content": "Workflow \"default\" started with 1 steps"
36
- },
37
- {
38
- "ts": 1771875803204,
39
- "type": "note",
40
- "content": "Parsed 1 steps, DAG validated, no cycles"
41
- },
42
- {
43
- "ts": 1771875803205,
44
- "type": "note",
45
- "content": "Step \"step-1\" assigned to agent \"agent-a\""
46
- },
47
- {
48
- "ts": 1771875803206,
49
- "type": "finding",
50
- "content": "Step \"step-1\" completed: Agent exited (exited)",
51
- "significance": "medium"
52
- }
53
- ],
54
- "endedAt": "2026-02-23T19:43:23.207Z"
55
- },
56
- {
57
- "id": "ch_fb0ea95b",
58
- "title": "Retrospective",
59
- "agentName": "orchestrator",
60
- "startedAt": "2026-02-23T19:43:23.207Z",
61
- "events": [
62
- {
63
- "ts": 1771875803207,
64
- "type": "reflection",
65
- "content": "Workflow completed in 0 seconds. 1/1 steps passed. (completed in 0 seconds)",
66
- "significance": "high"
67
- }
68
- ],
69
- "endedAt": "2026-02-23T19:43:23.207Z"
70
- }
71
- ],
72
- "completedAt": "2026-02-23T19:43:23.207Z",
73
- "retrospective": {
74
- "summary": "Workflow completed in 0 seconds. 1/1 steps passed.",
75
- "approach": "workflow-runner DAG execution",
76
- "confidence": 0.75,
77
- "learnings": [],
78
- "challenges": []
79
- }
80
- }