macro-agent 0.2.5 → 0.2.6

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 (992) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +30 -56
  3. package/dist/acp/websocket-server.d.ts +6 -0
  4. package/dist/acp/websocket-server.d.ts.map +1 -1
  5. package/dist/acp/websocket-server.js +13 -0
  6. package/dist/acp/websocket-server.js.map +1 -1
  7. package/dist/acp/websocket-stream.d.ts +30 -0
  8. package/dist/acp/websocket-stream.d.ts.map +1 -0
  9. package/dist/acp/websocket-stream.js +118 -0
  10. package/dist/acp/websocket-stream.js.map +1 -0
  11. package/dist/activity/deduplication.d.ts +85 -0
  12. package/dist/activity/deduplication.d.ts.map +1 -0
  13. package/dist/activity/deduplication.js +149 -0
  14. package/dist/activity/deduplication.js.map +1 -0
  15. package/dist/activity/index.d.ts +16 -0
  16. package/dist/activity/index.d.ts.map +1 -0
  17. package/dist/activity/index.js +17 -0
  18. package/dist/activity/index.js.map +1 -0
  19. package/dist/activity/relevance.d.ts +81 -0
  20. package/dist/activity/relevance.d.ts.map +1 -0
  21. package/dist/activity/relevance.js +161 -0
  22. package/dist/activity/relevance.js.map +1 -0
  23. package/dist/activity/types.d.ts +169 -0
  24. package/dist/activity/types.d.ts.map +1 -0
  25. package/dist/activity/types.js +33 -0
  26. package/dist/activity/types.js.map +1 -0
  27. package/dist/activity/watcher.d.ts +64 -0
  28. package/dist/activity/watcher.d.ts.map +1 -0
  29. package/dist/activity/watcher.js +212 -0
  30. package/dist/activity/watcher.js.map +1 -0
  31. package/dist/adapters/federation.d.ts +8 -1
  32. package/dist/adapters/federation.d.ts.map +1 -1
  33. package/dist/adapters/federation.js +33 -2
  34. package/dist/adapters/federation.js.map +1 -1
  35. package/dist/agent/agent-manager-v2.d.ts.map +1 -1
  36. package/dist/agent/agent-manager-v2.js +7 -24
  37. package/dist/agent/agent-manager-v2.js.map +1 -1
  38. package/dist/agent/wake.d.ts +85 -0
  39. package/dist/agent/wake.d.ts.map +1 -0
  40. package/dist/agent/wake.js +278 -0
  41. package/dist/agent/wake.js.map +1 -0
  42. package/dist/api/server.d.ts.map +1 -1
  43. package/dist/api/server.js +41 -25
  44. package/dist/api/server.js.map +1 -1
  45. package/dist/api/types.d.ts +6 -0
  46. package/dist/api/types.d.ts.map +1 -1
  47. package/dist/auth/server-auth.d.ts +43 -0
  48. package/dist/auth/server-auth.d.ts.map +1 -0
  49. package/dist/auth/server-auth.js +80 -0
  50. package/dist/auth/server-auth.js.map +1 -0
  51. package/dist/auth/token.d.ts +4 -0
  52. package/dist/auth/token.d.ts.map +1 -1
  53. package/dist/auth/token.js +7 -6
  54. package/dist/auth/token.js.map +1 -1
  55. package/dist/boot-v2.d.ts +6 -3
  56. package/dist/boot-v2.d.ts.map +1 -1
  57. package/dist/boot-v2.js +44 -25
  58. package/dist/boot-v2.js.map +1 -1
  59. package/dist/cognitive/team-lifecycle.d.ts +82 -0
  60. package/dist/cognitive/team-lifecycle.d.ts.map +1 -0
  61. package/dist/cognitive/team-lifecycle.js +121 -0
  62. package/dist/cognitive/team-lifecycle.js.map +1 -0
  63. package/dist/cognitive/trajectory-extractor.d.ts +25 -0
  64. package/dist/cognitive/trajectory-extractor.d.ts.map +1 -0
  65. package/dist/cognitive/trajectory-extractor.js +134 -0
  66. package/dist/cognitive/trajectory-extractor.js.map +1 -0
  67. package/dist/control/control-server.d.ts.map +1 -1
  68. package/dist/control/control-server.js +10 -0
  69. package/dist/control/control-server.js.map +1 -1
  70. package/dist/dispatch/mail-inbound-consumer.d.ts.map +1 -1
  71. package/dist/dispatch/mail-inbound-consumer.js +43 -10
  72. package/dist/dispatch/mail-inbound-consumer.js.map +1 -1
  73. package/dist/index.d.ts +4 -0
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +6 -1
  76. package/dist/index.js.map +1 -1
  77. package/dist/lifecycle/handlers/generic.d.ts +27 -0
  78. package/dist/lifecycle/handlers/generic.d.ts.map +1 -0
  79. package/dist/lifecycle/handlers/generic.js +56 -0
  80. package/dist/lifecycle/handlers/generic.js.map +1 -0
  81. package/dist/lifecycle/handlers/index.d.ts +51 -0
  82. package/dist/lifecycle/handlers/index.d.ts.map +1 -0
  83. package/dist/lifecycle/handlers/index.js +110 -0
  84. package/dist/lifecycle/handlers/index.js.map +1 -0
  85. package/dist/lifecycle/handlers/integrator.d.ts +81 -0
  86. package/dist/lifecycle/handlers/integrator.d.ts.map +1 -0
  87. package/dist/lifecycle/handlers/integrator.js +451 -0
  88. package/dist/lifecycle/handlers/integrator.js.map +1 -0
  89. package/dist/lifecycle/handlers/monitor.d.ts +29 -0
  90. package/dist/lifecycle/handlers/monitor.d.ts.map +1 -0
  91. package/dist/lifecycle/handlers/monitor.js +79 -0
  92. package/dist/lifecycle/handlers/monitor.js.map +1 -0
  93. package/dist/lifecycle/handlers/worker.d.ts +56 -0
  94. package/dist/lifecycle/handlers/worker.d.ts.map +1 -0
  95. package/dist/lifecycle/handlers/worker.js +381 -0
  96. package/dist/lifecycle/handlers/worker.js.map +1 -0
  97. package/dist/lifecycle/handlers-v2.d.ts +0 -2
  98. package/dist/lifecycle/handlers-v2.d.ts.map +1 -1
  99. package/dist/lifecycle/handlers-v2.js +4 -55
  100. package/dist/lifecycle/handlers-v2.js.map +1 -1
  101. package/dist/mail/conversation-map.d.ts +33 -0
  102. package/dist/mail/conversation-map.d.ts.map +1 -0
  103. package/dist/mail/conversation-map.js +61 -0
  104. package/dist/mail/conversation-map.js.map +1 -0
  105. package/dist/mail/index.d.ts +11 -0
  106. package/dist/mail/index.d.ts.map +1 -0
  107. package/dist/mail/index.js +11 -0
  108. package/dist/mail/index.js.map +1 -0
  109. package/dist/mail/mail-service.d.ts +85 -0
  110. package/dist/mail/mail-service.d.ts.map +1 -0
  111. package/dist/mail/mail-service.js +121 -0
  112. package/dist/mail/mail-service.js.map +1 -0
  113. package/dist/mail/stores/eventstore-conversation-store.d.ts +40 -0
  114. package/dist/mail/stores/eventstore-conversation-store.d.ts.map +1 -0
  115. package/dist/mail/stores/eventstore-conversation-store.js +131 -0
  116. package/dist/mail/stores/eventstore-conversation-store.js.map +1 -0
  117. package/dist/mail/stores/eventstore-participant-store.d.ts +43 -0
  118. package/dist/mail/stores/eventstore-participant-store.d.ts.map +1 -0
  119. package/dist/mail/stores/eventstore-participant-store.js +145 -0
  120. package/dist/mail/stores/eventstore-participant-store.js.map +1 -0
  121. package/dist/mail/stores/eventstore-thread-store.d.ts +46 -0
  122. package/dist/mail/stores/eventstore-thread-store.d.ts.map +1 -0
  123. package/dist/mail/stores/eventstore-thread-store.js +118 -0
  124. package/dist/mail/stores/eventstore-thread-store.js.map +1 -0
  125. package/dist/mail/stores/eventstore-turn-store.d.ts +47 -0
  126. package/dist/mail/stores/eventstore-turn-store.d.ts.map +1 -0
  127. package/dist/mail/stores/eventstore-turn-store.js +153 -0
  128. package/dist/mail/stores/eventstore-turn-store.js.map +1 -0
  129. package/dist/mail/stores/index.d.ts +12 -0
  130. package/dist/mail/stores/index.d.ts.map +1 -0
  131. package/dist/mail/stores/index.js +12 -0
  132. package/dist/mail/stores/index.js.map +1 -0
  133. package/dist/mail/stores/types.d.ts +146 -0
  134. package/dist/mail/stores/types.d.ts.map +1 -0
  135. package/dist/mail/stores/types.js +13 -0
  136. package/dist/mail/stores/types.js.map +1 -0
  137. package/dist/mail/turn-recorder.d.ts +30 -0
  138. package/dist/mail/turn-recorder.d.ts.map +1 -0
  139. package/dist/mail/turn-recorder.js +98 -0
  140. package/dist/mail/turn-recorder.js.map +1 -0
  141. package/dist/map/adapter/acp-over-map.d.ts +115 -0
  142. package/dist/map/adapter/acp-over-map.d.ts.map +1 -0
  143. package/dist/map/adapter/acp-over-map.js +1024 -0
  144. package/dist/map/adapter/acp-over-map.js.map +1 -0
  145. package/dist/map/adapter/connection-manager.d.ts +150 -0
  146. package/dist/map/adapter/connection-manager.d.ts.map +1 -0
  147. package/dist/map/adapter/connection-manager.js +207 -0
  148. package/dist/map/adapter/connection-manager.js.map +1 -0
  149. package/dist/map/adapter/event-log.d.ts +87 -0
  150. package/dist/map/adapter/event-log.d.ts.map +1 -0
  151. package/dist/map/adapter/event-log.js +122 -0
  152. package/dist/map/adapter/event-log.js.map +1 -0
  153. package/dist/map/adapter/event-translator.d.ts +85 -0
  154. package/dist/map/adapter/event-translator.d.ts.map +1 -0
  155. package/dist/map/adapter/event-translator.js +295 -0
  156. package/dist/map/adapter/event-translator.js.map +1 -0
  157. package/dist/map/adapter/extensions/agent-detection.d.ts +49 -0
  158. package/dist/map/adapter/extensions/agent-detection.d.ts.map +1 -0
  159. package/dist/map/adapter/extensions/agent-detection.js +91 -0
  160. package/dist/map/adapter/extensions/agent-detection.js.map +1 -0
  161. package/dist/map/adapter/extensions/agent-lifecycle.d.ts +82 -0
  162. package/dist/map/adapter/extensions/agent-lifecycle.d.ts.map +1 -0
  163. package/dist/map/adapter/extensions/agent-lifecycle.js +164 -0
  164. package/dist/map/adapter/extensions/agent-lifecycle.js.map +1 -0
  165. package/dist/map/adapter/extensions/cognitive.d.ts +27 -0
  166. package/dist/map/adapter/extensions/cognitive.d.ts.map +1 -0
  167. package/dist/map/adapter/extensions/cognitive.js +158 -0
  168. package/dist/map/adapter/extensions/cognitive.js.map +1 -0
  169. package/dist/map/adapter/extensions/index.d.ts +95 -0
  170. package/dist/map/adapter/extensions/index.d.ts.map +1 -0
  171. package/dist/map/adapter/extensions/index.js +228 -0
  172. package/dist/map/adapter/extensions/index.js.map +1 -0
  173. package/dist/map/adapter/extensions/mcp-bridge.d.ts +57 -0
  174. package/dist/map/adapter/extensions/mcp-bridge.d.ts.map +1 -0
  175. package/dist/map/adapter/extensions/mcp-bridge.js +745 -0
  176. package/dist/map/adapter/extensions/mcp-bridge.js.map +1 -0
  177. package/dist/map/adapter/extensions/resume.d.ts +47 -0
  178. package/dist/map/adapter/extensions/resume.d.ts.map +1 -0
  179. package/dist/map/adapter/extensions/resume.js +59 -0
  180. package/dist/map/adapter/extensions/resume.js.map +1 -0
  181. package/dist/map/adapter/extensions/streams.d.ts +95 -0
  182. package/dist/map/adapter/extensions/streams.d.ts.map +1 -0
  183. package/dist/map/adapter/extensions/streams.js +515 -0
  184. package/dist/map/adapter/extensions/streams.js.map +1 -0
  185. package/dist/map/adapter/extensions/task.d.ts +40 -0
  186. package/dist/map/adapter/extensions/task.d.ts.map +1 -0
  187. package/dist/map/adapter/extensions/task.js +197 -0
  188. package/dist/map/adapter/extensions/task.js.map +1 -0
  189. package/dist/map/adapter/extensions/update-metadata.d.ts +29 -0
  190. package/dist/map/adapter/extensions/update-metadata.d.ts.map +1 -0
  191. package/dist/map/adapter/extensions/update-metadata.js +67 -0
  192. package/dist/map/adapter/extensions/update-metadata.js.map +1 -0
  193. package/dist/map/adapter/extensions/wake.d.ts +60 -0
  194. package/dist/map/adapter/extensions/wake.d.ts.map +1 -0
  195. package/dist/map/adapter/extensions/wake.js +144 -0
  196. package/dist/map/adapter/extensions/wake.js.map +1 -0
  197. package/dist/map/adapter/extensions/workspace-files.d.ts +42 -0
  198. package/dist/map/adapter/extensions/workspace-files.d.ts.map +1 -0
  199. package/dist/map/adapter/extensions/workspace-files.js +338 -0
  200. package/dist/map/adapter/extensions/workspace-files.js.map +1 -0
  201. package/dist/map/adapter/extensions/workspace.d.ts +57 -0
  202. package/dist/map/adapter/extensions/workspace.d.ts.map +1 -0
  203. package/dist/map/adapter/extensions/workspace.js +81 -0
  204. package/dist/map/adapter/extensions/workspace.js.map +1 -0
  205. package/dist/map/adapter/index.d.ts +20 -0
  206. package/dist/map/adapter/index.d.ts.map +1 -0
  207. package/dist/map/adapter/index.js +40 -0
  208. package/dist/map/adapter/index.js.map +1 -0
  209. package/dist/map/adapter/interface.d.ts +450 -0
  210. package/dist/map/adapter/interface.d.ts.map +1 -0
  211. package/dist/map/adapter/interface.js +24 -0
  212. package/dist/map/adapter/interface.js.map +1 -0
  213. package/dist/map/adapter/mail-handler-adapter.d.ts +27 -0
  214. package/dist/map/adapter/mail-handler-adapter.d.ts.map +1 -0
  215. package/dist/map/adapter/mail-handler-adapter.js +292 -0
  216. package/dist/map/adapter/mail-handler-adapter.js.map +1 -0
  217. package/dist/map/adapter/map-adapter.d.ts +200 -0
  218. package/dist/map/adapter/map-adapter.d.ts.map +1 -0
  219. package/dist/map/adapter/map-adapter.js +1199 -0
  220. package/dist/map/adapter/map-adapter.js.map +1 -0
  221. package/dist/map/adapter/rpc-handler.d.ts +263 -0
  222. package/dist/map/adapter/rpc-handler.d.ts.map +1 -0
  223. package/dist/map/adapter/rpc-handler.js +365 -0
  224. package/dist/map/adapter/rpc-handler.js.map +1 -0
  225. package/dist/map/adapter/subscription-manager.d.ts +174 -0
  226. package/dist/map/adapter/subscription-manager.d.ts.map +1 -0
  227. package/dist/map/adapter/subscription-manager.js +248 -0
  228. package/dist/map/adapter/subscription-manager.js.map +1 -0
  229. package/dist/map/adapter/types.d.ts +194 -0
  230. package/dist/map/adapter/types.d.ts.map +1 -0
  231. package/dist/map/adapter/types.js +27 -0
  232. package/dist/map/adapter/types.js.map +1 -0
  233. package/dist/map/adapter/websocket-integration.d.ts +113 -0
  234. package/dist/map/adapter/websocket-integration.d.ts.map +1 -0
  235. package/dist/map/adapter/websocket-integration.js +134 -0
  236. package/dist/map/adapter/websocket-integration.js.map +1 -0
  237. package/dist/map/cascade-action-handler.d.ts.map +1 -1
  238. package/dist/map/cascade-action-handler.js +19 -5
  239. package/dist/map/cascade-action-handler.js.map +1 -1
  240. package/dist/map/federation/envelope.d.ts +98 -0
  241. package/dist/map/federation/envelope.d.ts.map +1 -0
  242. package/dist/map/federation/envelope.js +160 -0
  243. package/dist/map/federation/envelope.js.map +1 -0
  244. package/dist/map/federation/federation-handler.d.ts +50 -0
  245. package/dist/map/federation/federation-handler.d.ts.map +1 -0
  246. package/dist/map/federation/federation-handler.js +306 -0
  247. package/dist/map/federation/federation-handler.js.map +1 -0
  248. package/dist/map/federation/index.d.ts +14 -0
  249. package/dist/map/federation/index.d.ts.map +1 -0
  250. package/dist/map/federation/index.js +13 -0
  251. package/dist/map/federation/index.js.map +1 -0
  252. package/dist/map/federation/types.d.ts +239 -0
  253. package/dist/map/federation/types.d.ts.map +1 -0
  254. package/dist/map/federation/types.js +23 -0
  255. package/dist/map/federation/types.js.map +1 -0
  256. package/dist/map/server.d.ts.map +1 -1
  257. package/dist/map/server.js +17 -2
  258. package/dist/map/server.js.map +1 -1
  259. package/dist/map/types.d.ts +6 -0
  260. package/dist/map/types.d.ts.map +1 -1
  261. package/dist/mcp/map-client.d.ts +39 -0
  262. package/dist/mcp/map-client.d.ts.map +1 -0
  263. package/dist/mcp/map-client.js +129 -0
  264. package/dist/mcp/map-client.js.map +1 -0
  265. package/dist/mcp/mcp-server.d.ts +72 -0
  266. package/dist/mcp/mcp-server.d.ts.map +1 -0
  267. package/dist/mcp/mcp-server.js +1027 -0
  268. package/dist/mcp/mcp-server.js.map +1 -0
  269. package/dist/mcp/tools/claim_task.d.ts +35 -0
  270. package/dist/mcp/tools/claim_task.d.ts.map +1 -0
  271. package/dist/mcp/tools/claim_task.js +58 -0
  272. package/dist/mcp/tools/claim_task.js.map +1 -0
  273. package/dist/mcp/tools/done-v2.d.ts +0 -1
  274. package/dist/mcp/tools/done-v2.d.ts.map +1 -1
  275. package/dist/mcp/tools/done-v2.js +0 -1
  276. package/dist/mcp/tools/done-v2.js.map +1 -1
  277. package/dist/mcp/tools/done.d.ts +102 -0
  278. package/dist/mcp/tools/done.d.ts.map +1 -0
  279. package/dist/mcp/tools/done.js +253 -0
  280. package/dist/mcp/tools/done.js.map +1 -0
  281. package/dist/mcp/tools/inject_context.d.ts +61 -0
  282. package/dist/mcp/tools/inject_context.d.ts.map +1 -0
  283. package/dist/mcp/tools/inject_context.js +123 -0
  284. package/dist/mcp/tools/inject_context.js.map +1 -0
  285. package/dist/mcp/tools/list_claimable_tasks.d.ts +38 -0
  286. package/dist/mcp/tools/list_claimable_tasks.d.ts.map +1 -0
  287. package/dist/mcp/tools/list_claimable_tasks.js +63 -0
  288. package/dist/mcp/tools/list_claimable_tasks.js.map +1 -0
  289. package/dist/mcp/tools/unclaim_task.d.ts +31 -0
  290. package/dist/mcp/tools/unclaim_task.d.ts.map +1 -0
  291. package/dist/mcp/tools/unclaim_task.js +47 -0
  292. package/dist/mcp/tools/unclaim_task.js.map +1 -0
  293. package/dist/mcp/tools/wait_for_activity.d.ts +60 -0
  294. package/dist/mcp/tools/wait_for_activity.d.ts.map +1 -0
  295. package/dist/mcp/tools/wait_for_activity.js +135 -0
  296. package/dist/mcp/tools/wait_for_activity.js.map +1 -0
  297. package/dist/monitor/health-check-service.d.ts +143 -0
  298. package/dist/monitor/health-check-service.d.ts.map +1 -0
  299. package/dist/monitor/health-check-service.js +240 -0
  300. package/dist/monitor/health-check-service.js.map +1 -0
  301. package/dist/monitor/index.d.ts +14 -0
  302. package/dist/monitor/index.d.ts.map +1 -0
  303. package/dist/monitor/index.js +14 -0
  304. package/dist/monitor/index.js.map +1 -0
  305. package/dist/monitor/stall-detector.d.ts +109 -0
  306. package/dist/monitor/stall-detector.d.ts.map +1 -0
  307. package/dist/monitor/stall-detector.js +152 -0
  308. package/dist/monitor/stall-detector.js.map +1 -0
  309. package/dist/peer/capability-manager.d.ts +56 -0
  310. package/dist/peer/capability-manager.d.ts.map +1 -0
  311. package/dist/peer/capability-manager.js +186 -0
  312. package/dist/peer/capability-manager.js.map +1 -0
  313. package/dist/peer/encapsulation-manager.d.ts +190 -0
  314. package/dist/peer/encapsulation-manager.d.ts.map +1 -0
  315. package/dist/peer/encapsulation-manager.js +486 -0
  316. package/dist/peer/encapsulation-manager.js.map +1 -0
  317. package/dist/peer/federation-manager.d.ts +223 -0
  318. package/dist/peer/federation-manager.d.ts.map +1 -0
  319. package/dist/peer/federation-manager.js +528 -0
  320. package/dist/peer/federation-manager.js.map +1 -0
  321. package/dist/peer/hierarchy-errors.d.ts +208 -0
  322. package/dist/peer/hierarchy-errors.d.ts.map +1 -0
  323. package/dist/peer/hierarchy-errors.js +268 -0
  324. package/dist/peer/hierarchy-errors.js.map +1 -0
  325. package/dist/peer/hierarchy-protocol.d.ts +159 -0
  326. package/dist/peer/hierarchy-protocol.d.ts.map +1 -0
  327. package/dist/peer/hierarchy-protocol.js +142 -0
  328. package/dist/peer/hierarchy-protocol.js.map +1 -0
  329. package/dist/peer/index.d.ts +15 -0
  330. package/dist/peer/index.d.ts.map +1 -0
  331. package/dist/peer/index.js +15 -0
  332. package/dist/peer/index.js.map +1 -0
  333. package/dist/peer/peer-manager.d.ts +99 -0
  334. package/dist/peer/peer-manager.d.ts.map +1 -0
  335. package/dist/peer/peer-manager.js +333 -0
  336. package/dist/peer/peer-manager.js.map +1 -0
  337. package/dist/peer/task-delegation.d.ts +189 -0
  338. package/dist/peer/task-delegation.d.ts.map +1 -0
  339. package/dist/peer/task-delegation.js +303 -0
  340. package/dist/peer/task-delegation.js.map +1 -0
  341. package/dist/peer/transports/index.d.ts +8 -0
  342. package/dist/peer/transports/index.d.ts.map +1 -0
  343. package/dist/peer/transports/index.js +8 -0
  344. package/dist/peer/transports/index.js.map +1 -0
  345. package/dist/peer/transports/local-transport.d.ts +56 -0
  346. package/dist/peer/transports/local-transport.d.ts.map +1 -0
  347. package/dist/peer/transports/local-transport.js +263 -0
  348. package/dist/peer/transports/local-transport.js.map +1 -0
  349. package/dist/peer/transports/websocket-transport.d.ts +86 -0
  350. package/dist/peer/transports/websocket-transport.d.ts.map +1 -0
  351. package/dist/peer/transports/websocket-transport.js +338 -0
  352. package/dist/peer/transports/websocket-transport.js.map +1 -0
  353. package/dist/peer/types.d.ts +268 -0
  354. package/dist/peer/types.d.ts.map +1 -0
  355. package/dist/peer/types.js +36 -0
  356. package/dist/peer/types.js.map +1 -0
  357. package/dist/router/address-resolver.d.ts +102 -0
  358. package/dist/router/address-resolver.d.ts.map +1 -0
  359. package/dist/router/address-resolver.js +198 -0
  360. package/dist/router/address-resolver.js.map +1 -0
  361. package/dist/router/broadcast.d.ts +53 -0
  362. package/dist/router/broadcast.d.ts.map +1 -0
  363. package/dist/router/broadcast.js +75 -0
  364. package/dist/router/broadcast.js.map +1 -0
  365. package/dist/router/channels.d.ts +148 -0
  366. package/dist/router/channels.d.ts.map +1 -0
  367. package/dist/router/channels.js +126 -0
  368. package/dist/router/channels.js.map +1 -0
  369. package/dist/router/index.d.ts +21 -0
  370. package/dist/router/index.d.ts.map +1 -0
  371. package/dist/router/index.js +18 -0
  372. package/dist/router/index.js.map +1 -0
  373. package/dist/router/message-router.d.ts +197 -0
  374. package/dist/router/message-router.d.ts.map +1 -0
  375. package/dist/router/message-router.js +903 -0
  376. package/dist/router/message-router.js.map +1 -0
  377. package/dist/router/message-types.d.ts +183 -0
  378. package/dist/router/message-types.d.ts.map +1 -0
  379. package/dist/router/message-types.js +79 -0
  380. package/dist/router/message-types.js.map +1 -0
  381. package/dist/router/role-resolver.d.ts +67 -0
  382. package/dist/router/role-resolver.d.ts.map +1 -0
  383. package/dist/router/role-resolver.js +106 -0
  384. package/dist/router/role-resolver.js.map +1 -0
  385. package/dist/router/signals.d.ts +253 -0
  386. package/dist/router/signals.d.ts.map +1 -0
  387. package/dist/router/signals.js +53 -0
  388. package/dist/router/signals.js.map +1 -0
  389. package/dist/router/types.d.ts +191 -0
  390. package/dist/router/types.d.ts.map +1 -0
  391. package/dist/router/types.js +34 -0
  392. package/dist/router/types.js.map +1 -0
  393. package/dist/router/wake.d.ts +111 -0
  394. package/dist/router/wake.d.ts.map +1 -0
  395. package/dist/router/wake.js +180 -0
  396. package/dist/router/wake.js.map +1 -0
  397. package/dist/server/combined-server.d.ts +95 -0
  398. package/dist/server/combined-server.d.ts.map +1 -0
  399. package/dist/server/combined-server.js +335 -0
  400. package/dist/server/combined-server.js.map +1 -0
  401. package/dist/steering/index.d.ts +11 -0
  402. package/dist/steering/index.d.ts.map +1 -0
  403. package/dist/steering/index.js +11 -0
  404. package/dist/steering/index.js.map +1 -0
  405. package/dist/steering/inject.d.ts +39 -0
  406. package/dist/steering/inject.d.ts.map +1 -0
  407. package/dist/steering/inject.js +197 -0
  408. package/dist/steering/inject.js.map +1 -0
  409. package/dist/steering/types.d.ts +100 -0
  410. package/dist/steering/types.d.ts.map +1 -0
  411. package/dist/steering/types.js +11 -0
  412. package/dist/steering/types.js.map +1 -0
  413. package/dist/store/backends/index.d.ts +11 -0
  414. package/dist/store/backends/index.d.ts.map +1 -0
  415. package/dist/store/backends/index.js +15 -0
  416. package/dist/store/backends/index.js.map +1 -0
  417. package/dist/store/backends/json-backend.d.ts +23 -0
  418. package/dist/store/backends/json-backend.d.ts.map +1 -0
  419. package/dist/store/backends/json-backend.js +220 -0
  420. package/dist/store/backends/json-backend.js.map +1 -0
  421. package/dist/store/backends/memory-backend.d.ts +12 -0
  422. package/dist/store/backends/memory-backend.d.ts.map +1 -0
  423. package/dist/store/backends/memory-backend.js +205 -0
  424. package/dist/store/backends/memory-backend.js.map +1 -0
  425. package/dist/store/backends/sqlite-backend.d.ts +27 -0
  426. package/dist/store/backends/sqlite-backend.d.ts.map +1 -0
  427. package/dist/store/backends/sqlite-backend.js +231 -0
  428. package/dist/store/backends/sqlite-backend.js.map +1 -0
  429. package/dist/store/backends/tinybase-backend.d.ts +22 -0
  430. package/dist/store/backends/tinybase-backend.d.ts.map +1 -0
  431. package/dist/store/backends/tinybase-backend.js +203 -0
  432. package/dist/store/backends/tinybase-backend.js.map +1 -0
  433. package/dist/store/backends/types.d.ts +175 -0
  434. package/dist/store/backends/types.d.ts.map +1 -0
  435. package/dist/store/backends/types.js +28 -0
  436. package/dist/store/backends/types.js.map +1 -0
  437. package/dist/store/event-store.d.ts +128 -0
  438. package/dist/store/event-store.d.ts.map +1 -0
  439. package/dist/store/event-store.js +1751 -0
  440. package/dist/store/event-store.js.map +1 -0
  441. package/dist/store/instance.d.ts +290 -0
  442. package/dist/store/instance.d.ts.map +1 -0
  443. package/dist/store/instance.js +363 -0
  444. package/dist/store/instance.js.map +1 -0
  445. package/dist/store/migrations.d.ts +41 -0
  446. package/dist/store/migrations.d.ts.map +1 -0
  447. package/dist/store/migrations.js +79 -0
  448. package/dist/store/migrations.js.map +1 -0
  449. package/dist/store/test-utils.d.ts +63 -0
  450. package/dist/store/test-utils.d.ts.map +1 -0
  451. package/dist/store/test-utils.js +63 -0
  452. package/dist/store/test-utils.js.map +1 -0
  453. package/dist/store/types/config.d.ts +16 -0
  454. package/dist/store/types/config.d.ts.map +1 -0
  455. package/dist/store/types/config.js +8 -0
  456. package/dist/store/types/config.js.map +1 -0
  457. package/dist/store/types/conversations.d.ts +91 -0
  458. package/dist/store/types/conversations.d.ts.map +1 -0
  459. package/dist/store/types/conversations.js +8 -0
  460. package/dist/store/types/conversations.js.map +1 -0
  461. package/dist/store/types/sessions.d.ts +44 -0
  462. package/dist/store/types/sessions.d.ts.map +1 -0
  463. package/dist/store/types/sessions.js +9 -0
  464. package/dist/store/types/sessions.js.map +1 -0
  465. package/dist/store/types.d.ts +115 -0
  466. package/dist/store/types.d.ts.map +1 -0
  467. package/dist/store/types.js +6 -0
  468. package/dist/store/types.js.map +1 -0
  469. package/dist/task/backend/index.d.ts +93 -0
  470. package/dist/task/backend/index.d.ts.map +1 -0
  471. package/dist/task/backend/index.js +178 -0
  472. package/dist/task/backend/index.js.map +1 -0
  473. package/dist/task/backend/memory.d.ts +70 -0
  474. package/dist/task/backend/memory.d.ts.map +1 -0
  475. package/dist/task/backend/memory.js +621 -0
  476. package/dist/task/backend/memory.js.map +1 -0
  477. package/dist/task/backend/opentasks/backend.d.ts +140 -0
  478. package/dist/task/backend/opentasks/backend.d.ts.map +1 -0
  479. package/dist/task/backend/opentasks/backend.js +1023 -0
  480. package/dist/task/backend/opentasks/backend.js.map +1 -0
  481. package/dist/task/backend/opentasks/client.d.ts +337 -0
  482. package/dist/task/backend/opentasks/client.d.ts.map +1 -0
  483. package/dist/task/backend/opentasks/client.js +225 -0
  484. package/dist/task/backend/opentasks/client.js.map +1 -0
  485. package/dist/task/backend/opentasks/daemon-manager.d.ts +89 -0
  486. package/dist/task/backend/opentasks/daemon-manager.d.ts.map +1 -0
  487. package/dist/task/backend/opentasks/daemon-manager.js +195 -0
  488. package/dist/task/backend/opentasks/daemon-manager.js.map +1 -0
  489. package/dist/task/backend/opentasks/index.d.ts +21 -0
  490. package/dist/task/backend/opentasks/index.d.ts.map +1 -0
  491. package/dist/task/backend/opentasks/index.js +21 -0
  492. package/dist/task/backend/opentasks/index.js.map +1 -0
  493. package/dist/task/backend/opentasks/mapping.d.ts +48 -0
  494. package/dist/task/backend/opentasks/mapping.d.ts.map +1 -0
  495. package/dist/task/backend/opentasks/mapping.js +77 -0
  496. package/dist/task/backend/opentasks/mapping.js.map +1 -0
  497. package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts +54 -0
  498. package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts.map +1 -0
  499. package/dist/task/backend/sudocode/__tests__/integration/test-utils.js +88 -0
  500. package/dist/task/backend/sudocode/__tests__/integration/test-utils.js.map +1 -0
  501. package/dist/task/backend/sudocode/backend.d.ts +155 -0
  502. package/dist/task/backend/sudocode/backend.d.ts.map +1 -0
  503. package/dist/task/backend/sudocode/backend.js +942 -0
  504. package/dist/task/backend/sudocode/backend.js.map +1 -0
  505. package/dist/task/backend/sudocode/client.d.ts +303 -0
  506. package/dist/task/backend/sudocode/client.d.ts.map +1 -0
  507. package/dist/task/backend/sudocode/client.js +101 -0
  508. package/dist/task/backend/sudocode/client.js.map +1 -0
  509. package/dist/task/backend/sudocode/index.d.ts +19 -0
  510. package/dist/task/backend/sudocode/index.d.ts.map +1 -0
  511. package/dist/task/backend/sudocode/index.js +17 -0
  512. package/dist/task/backend/sudocode/index.js.map +1 -0
  513. package/dist/task/backend/sudocode/mapping.d.ts +51 -0
  514. package/dist/task/backend/sudocode/mapping.d.ts.map +1 -0
  515. package/dist/task/backend/sudocode/mapping.js +86 -0
  516. package/dist/task/backend/sudocode/mapping.js.map +1 -0
  517. package/dist/task/backend/sudocode/server-client.d.ts +56 -0
  518. package/dist/task/backend/sudocode/server-client.d.ts.map +1 -0
  519. package/dist/task/backend/sudocode/server-client.js +367 -0
  520. package/dist/task/backend/sudocode/server-client.js.map +1 -0
  521. package/dist/task/backend/sudocode/standalone-client.d.ts +91 -0
  522. package/dist/task/backend/sudocode/standalone-client.d.ts.map +1 -0
  523. package/dist/task/backend/sudocode/standalone-client.js +476 -0
  524. package/dist/task/backend/sudocode/standalone-client.js.map +1 -0
  525. package/dist/task/backend/sudocode/sync-policy.d.ts +166 -0
  526. package/dist/task/backend/sudocode/sync-policy.d.ts.map +1 -0
  527. package/dist/task/backend/sudocode/sync-policy.js +221 -0
  528. package/dist/task/backend/sudocode/sync-policy.js.map +1 -0
  529. package/dist/task/backend/sudocode/tools.d.ts +87 -0
  530. package/dist/task/backend/sudocode/tools.d.ts.map +1 -0
  531. package/dist/task/backend/sudocode/tools.js +743 -0
  532. package/dist/task/backend/sudocode/tools.js.map +1 -0
  533. package/dist/task/backend/tool-provider.d.ts +56 -0
  534. package/dist/task/backend/tool-provider.d.ts.map +1 -0
  535. package/dist/task/backend/tool-provider.js +424 -0
  536. package/dist/task/backend/tool-provider.js.map +1 -0
  537. package/dist/task/backend/types.d.ts +297 -0
  538. package/dist/task/backend/types.d.ts.map +1 -0
  539. package/dist/task/backend/types.js +27 -0
  540. package/dist/task/backend/types.js.map +1 -0
  541. package/dist/task/backend/unified-tool-provider.d.ts +57 -0
  542. package/dist/task/backend/unified-tool-provider.d.ts.map +1 -0
  543. package/dist/task/backend/unified-tool-provider.js +623 -0
  544. package/dist/task/backend/unified-tool-provider.js.map +1 -0
  545. package/dist/task/index.d.ts +7 -0
  546. package/dist/task/index.d.ts.map +1 -0
  547. package/dist/task/index.js +7 -0
  548. package/dist/task/index.js.map +1 -0
  549. package/dist/task/retry-policy.d.ts +89 -0
  550. package/dist/task/retry-policy.d.ts.map +1 -0
  551. package/dist/task/retry-policy.js +160 -0
  552. package/dist/task/retry-policy.js.map +1 -0
  553. package/dist/task/task-manager.d.ts +70 -0
  554. package/dist/task/task-manager.d.ts.map +1 -0
  555. package/dist/task/task-manager.js +319 -0
  556. package/dist/task/task-manager.js.map +1 -0
  557. package/dist/task/types.d.ts +72 -0
  558. package/dist/task/types.d.ts.map +1 -0
  559. package/dist/task/types.js +33 -0
  560. package/dist/task/types.js.map +1 -0
  561. package/dist/teams/team-loader.d.ts +2 -1
  562. package/dist/teams/team-loader.d.ts.map +1 -1
  563. package/dist/teams/team-loader.js +2 -1
  564. package/dist/teams/team-loader.js.map +1 -1
  565. package/dist/teams/team-manager.d.ts +101 -0
  566. package/dist/teams/team-manager.d.ts.map +1 -0
  567. package/dist/teams/team-manager.js +260 -0
  568. package/dist/teams/team-manager.js.map +1 -0
  569. package/dist/teams/team-runtime-v2.d.ts +0 -3
  570. package/dist/teams/team-runtime-v2.d.ts.map +1 -1
  571. package/dist/teams/team-runtime-v2.js +8 -87
  572. package/dist/teams/team-runtime-v2.js.map +1 -1
  573. package/dist/teams/team-runtime.d.ts +245 -0
  574. package/dist/teams/team-runtime.d.ts.map +1 -0
  575. package/dist/teams/team-runtime.js +1023 -0
  576. package/dist/teams/team-runtime.js.map +1 -0
  577. package/dist/trigger/router/index.d.ts +11 -0
  578. package/dist/trigger/router/index.d.ts.map +1 -0
  579. package/dist/trigger/router/index.js +10 -0
  580. package/dist/trigger/router/index.js.map +1 -0
  581. package/dist/trigger/router/strategies/ai-router-strategy.d.ts +34 -0
  582. package/dist/trigger/router/strategies/ai-router-strategy.d.ts.map +1 -0
  583. package/dist/trigger/router/strategies/ai-router-strategy.js +359 -0
  584. package/dist/trigger/router/strategies/ai-router-strategy.js.map +1 -0
  585. package/dist/trigger/router/strategies/direct-strategy.d.ts +32 -0
  586. package/dist/trigger/router/strategies/direct-strategy.d.ts.map +1 -0
  587. package/dist/trigger/router/strategies/direct-strategy.js +119 -0
  588. package/dist/trigger/router/strategies/direct-strategy.js.map +1 -0
  589. package/dist/trigger/router/strategies/index.d.ts +11 -0
  590. package/dist/trigger/router/strategies/index.d.ts.map +1 -0
  591. package/dist/trigger/router/strategies/index.js +11 -0
  592. package/dist/trigger/router/strategies/index.js.map +1 -0
  593. package/dist/trigger/router/strategies/role-strategy.d.ts +39 -0
  594. package/dist/trigger/router/strategies/role-strategy.d.ts.map +1 -0
  595. package/dist/trigger/router/strategies/role-strategy.js +207 -0
  596. package/dist/trigger/router/strategies/role-strategy.js.map +1 -0
  597. package/dist/trigger/router/trigger-router.d.ts +54 -0
  598. package/dist/trigger/router/trigger-router.d.ts.map +1 -0
  599. package/dist/trigger/router/trigger-router.js +362 -0
  600. package/dist/trigger/router/trigger-router.js.map +1 -0
  601. package/dist/trigger/router/types.d.ts +225 -0
  602. package/dist/trigger/router/types.d.ts.map +1 -0
  603. package/dist/trigger/router/types.js +10 -0
  604. package/dist/trigger/router/types.js.map +1 -0
  605. package/dist/trigger/sources/cron/cron-service.d.ts.map +1 -1
  606. package/dist/trigger/sources/cron/cron-service.js +6 -3
  607. package/dist/trigger/sources/cron/cron-service.js.map +1 -1
  608. package/dist/trigger/trigger-system.d.ts +77 -0
  609. package/dist/trigger/trigger-system.d.ts.map +1 -0
  610. package/dist/trigger/trigger-system.js +84 -0
  611. package/dist/trigger/trigger-system.js.map +1 -0
  612. package/dist/util/git-safety.d.ts +33 -0
  613. package/dist/util/git-safety.d.ts.map +1 -0
  614. package/dist/util/git-safety.js +94 -0
  615. package/dist/util/git-safety.js.map +1 -0
  616. package/dist/workspace/dataplane-adapter.d.ts +260 -0
  617. package/dist/workspace/dataplane-adapter.d.ts.map +1 -0
  618. package/dist/workspace/dataplane-adapter.js +416 -0
  619. package/dist/workspace/dataplane-adapter.js.map +1 -0
  620. package/dist/workspace/index.d.ts +0 -1
  621. package/dist/workspace/index.d.ts.map +1 -1
  622. package/dist/workspace/index.js +0 -2
  623. package/dist/workspace/index.js.map +1 -1
  624. package/dist/workspace/landing/direct-push.d.ts.map +1 -1
  625. package/dist/workspace/landing/direct-push.js +22 -7
  626. package/dist/workspace/landing/direct-push.js.map +1 -1
  627. package/dist/workspace/landing/queue-to-branch.d.ts.map +1 -1
  628. package/dist/workspace/landing/queue-to-branch.js +1 -3
  629. package/dist/workspace/landing/queue-to-branch.js.map +1 -1
  630. package/dist/workspace/types.d.ts +0 -13
  631. package/dist/workspace/types.d.ts.map +1 -1
  632. package/dist/workspace/workspace-manager.d.ts +0 -11
  633. package/dist/workspace/workspace-manager.d.ts.map +1 -1
  634. package/dist/workspace/workspace-manager.js +0 -30
  635. package/dist/workspace/workspace-manager.js.map +1 -1
  636. package/package.json +28 -2
  637. package/templates/teams/self-driving/prompts/grinder.md +1 -0
  638. package/templates/teams/self-driving/prompts/judge.md +1 -0
  639. package/templates/teams/self-driving/prompts/planner.md +1 -0
  640. package/templates/teams/self-driving/roles/grinder.yaml +15 -0
  641. package/templates/teams/self-driving/roles/judge.yaml +10 -0
  642. package/templates/teams/self-driving/roles/planner.yaml +16 -0
  643. package/.claude/commands/openspec/apply.md +0 -23
  644. package/.claude/commands/openspec/archive.md +0 -27
  645. package/.claude/commands/openspec/proposal.md +0 -28
  646. package/.claude/settings.json +0 -133
  647. package/.gitattributes +0 -3
  648. package/.opentasks/config.json +0 -9
  649. package/.opentasks/graph.jsonl +0 -0
  650. package/.sessionlog/settings.json +0 -4
  651. package/.sudocode/issues.jsonl +0 -183
  652. package/.sudocode/specs.jsonl +0 -56
  653. package/AGENTS.md +0 -18
  654. package/CLAUDE.md +0 -923
  655. package/docs/architecture.md +0 -508
  656. package/docs/configuration.md +0 -323
  657. package/docs/conflict-recovery.md +0 -472
  658. package/docs/design/task-dispatcher.md +0 -880
  659. package/docs/design-subsystem-extraction.md +0 -627
  660. package/docs/git-cascade-integration-gaps.md +0 -678
  661. package/docs/implementation-details.md +0 -1127
  662. package/docs/implementation-summary.md +0 -448
  663. package/docs/lifecycle-events-design.md +0 -111
  664. package/docs/mail-integration.md +0 -608
  665. package/docs/openhive-capability-summary.md +0 -415
  666. package/docs/openhive-integration.md +0 -415
  667. package/docs/plan-self-driving-support.md +0 -433
  668. package/docs/roadmap-v2-gaps.md +0 -216
  669. package/docs/spec-self-driving-support.md +0 -462
  670. package/docs/team-templates.md +0 -860
  671. package/docs/teams.md +0 -306
  672. package/docs/trigger-system-design.md +0 -333
  673. package/docs/troubleshooting.md +0 -489
  674. package/docs/workspace-interfaces.md +0 -731
  675. package/docs/workspace-redesign-plan.md +0 -302
  676. package/examples/distributed-peer-communication.ts +0 -202
  677. package/examples/local-peer-communication.ts +0 -165
  678. package/index.js +0 -2
  679. package/mvp_docs/agent-execution-system.md +0 -347
  680. package/mvp_docs/agent-interface.md +0 -580
  681. package/mvp_docs/data-structures.md +0 -701
  682. package/mvp_docs/dynamic-meta-orchestration.md +0 -116
  683. package/mvp_docs/multi-agent-interaction-design.md +0 -779
  684. package/mvp_docs/mvp-implementation-plan.md +0 -1148
  685. package/renovate.json5 +0 -6
  686. package/scripts/test-acp-integration.ts +0 -422
  687. package/src/__tests__/boot-v2.test.ts +0 -631
  688. package/src/__tests__/e2e/acp-over-map-live.e2e.test.ts +0 -496
  689. package/src/__tests__/e2e/acp-over-map.e2e.test.ts +0 -457
  690. package/src/__tests__/e2e/agent-lifecycle.e2e.test.ts +0 -770
  691. package/src/__tests__/e2e/auto-sync.e2e.test.ts +0 -257
  692. package/src/__tests__/e2e/bootstrap.e2e.test.ts +0 -319
  693. package/src/__tests__/e2e/cascade-rebase.e2e.test.ts +0 -254
  694. package/src/__tests__/e2e/cc-swarm-bridge.e2e.test.ts +0 -253
  695. package/src/__tests__/e2e/cli-run.e2e.test.ts +0 -167
  696. package/src/__tests__/e2e/cognitive-workspace.e2e.test.ts +0 -282
  697. package/src/__tests__/e2e/dispatch-coordination.e2e.test.ts +0 -495
  698. package/src/__tests__/e2e/dispatch-live.e2e.test.ts +0 -564
  699. package/src/__tests__/e2e/dispatch-opentasks.e2e.test.ts +0 -496
  700. package/src/__tests__/e2e/dispatch-phase2-live.e2e.test.ts +0 -456
  701. package/src/__tests__/e2e/dispatch-phase2.e2e.test.ts +0 -386
  702. package/src/__tests__/e2e/dispatch.e2e.test.ts +0 -376
  703. package/src/__tests__/e2e/done-scenarios.e2e.test.ts +0 -322
  704. package/src/__tests__/e2e/live-agent.e2e.test.ts +0 -1330
  705. package/src/__tests__/e2e/map-server.e2e.test.ts +0 -128
  706. package/src/__tests__/e2e/map-sidecar.e2e.test.ts +0 -139
  707. package/src/__tests__/e2e/opentasks-integration.e2e.test.ts +0 -280
  708. package/src/__tests__/e2e/pull-mode.e2e.test.ts +0 -632
  709. package/src/__tests__/e2e/resume-continue.e2e.test.ts +0 -312
  710. package/src/__tests__/e2e/self-driving-v3.e2e.test.ts +0 -197
  711. package/src/__tests__/e2e/spawn-resolver.e2e.test.ts +0 -200
  712. package/src/__tests__/e2e/swarmkit-integration.e2e.test.ts +0 -562
  713. package/src/__tests__/e2e/swarmkit-live.e2e.test.ts +0 -1049
  714. package/src/__tests__/e2e/trajectory-tracking.e2e.test.ts +0 -258
  715. package/src/__tests__/e2e/trigger-wake.e2e.test.ts +0 -257
  716. package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +0 -383
  717. package/src/__tests__/e2e/workspace-v3.e2e.test.ts +0 -413
  718. package/src/acp/__tests__/claude-code-replay.test.ts +0 -225
  719. package/src/acp/__tests__/macro-agent.test.ts +0 -387
  720. package/src/acp/__tests__/session-mapper.test.ts +0 -152
  721. package/src/acp/__tests__/websocket-server.test.ts +0 -194
  722. package/src/acp/claude-code-replay.ts +0 -208
  723. package/src/acp/index.ts +0 -32
  724. package/src/acp/macro-agent.ts +0 -995
  725. package/src/acp/map-bridge.ts +0 -193
  726. package/src/acp/session-mapper.ts +0 -116
  727. package/src/acp/types.ts +0 -99
  728. package/src/acp/websocket-server.ts +0 -213
  729. package/src/adapters/__tests__/federation.test.ts +0 -256
  730. package/src/adapters/__tests__/inbox-adapter.test.ts +0 -316
  731. package/src/adapters/__tests__/tasks-adapter.test.ts +0 -270
  732. package/src/adapters/federation.ts +0 -185
  733. package/src/adapters/inbox-adapter.ts +0 -292
  734. package/src/adapters/inbox-client-adapter.ts +0 -173
  735. package/src/adapters/index.ts +0 -44
  736. package/src/adapters/opentasks-daemon.ts +0 -252
  737. package/src/adapters/tasks-adapter.ts +0 -330
  738. package/src/adapters/types.ts +0 -286
  739. package/src/agent/__tests__/agent-manager-topology.test.ts +0 -73
  740. package/src/agent/__tests__/agent-manager-v2.completion-signal.test.ts +0 -284
  741. package/src/agent/__tests__/agent-manager-v2.permission-interception.test.ts +0 -296
  742. package/src/agent/__tests__/agent-manager-v2.permissions.test.ts +0 -233
  743. package/src/agent/__tests__/agent-manager-v2.test.ts +0 -614
  744. package/src/agent/__tests__/agent-store.test.ts +0 -465
  745. package/src/agent/__tests__/task-ref-resolution.test.ts +0 -231
  746. package/src/agent/agent-manager-v2.ts +0 -2187
  747. package/src/agent/agent-manager.ts +0 -403
  748. package/src/agent/agent-store.ts +0 -409
  749. package/src/agent/index.ts +0 -7
  750. package/src/agent/prompts/coordinator-signals.ts +0 -115
  751. package/src/agent/prompts/index.ts +0 -7
  752. package/src/agent/system-prompt.ts +0 -298
  753. package/src/agent/types.ts +0 -480
  754. package/src/agent-detection/__tests__/command-builder.test.ts +0 -336
  755. package/src/agent-detection/__tests__/detector.test.ts +0 -768
  756. package/src/agent-detection/__tests__/registry.test.ts +0 -254
  757. package/src/agent-detection/command-builder.ts +0 -90
  758. package/src/agent-detection/detector.ts +0 -307
  759. package/src/agent-detection/index.ts +0 -36
  760. package/src/agent-detection/registry.ts +0 -200
  761. package/src/agent-detection/types.ts +0 -184
  762. package/src/api/__tests__/server.test.ts +0 -292
  763. package/src/api/index.ts +0 -8
  764. package/src/api/server.ts +0 -380
  765. package/src/api/types.ts +0 -39
  766. package/src/auth/__tests__/token.test.ts +0 -100
  767. package/src/auth/index.ts +0 -1
  768. package/src/auth/token.ts +0 -82
  769. package/src/boot-v2.ts +0 -1343
  770. package/src/cli/__tests__/stable-instance-id.test.ts +0 -57
  771. package/src/cli/acp.ts +0 -101
  772. package/src/cli/inbox-mcp-proxy.ts +0 -56
  773. package/src/cli/index.ts +0 -566
  774. package/src/cli/mcp.ts +0 -305
  775. package/src/cli/parse-args.ts +0 -54
  776. package/src/cli/stable-instance-id.ts +0 -14
  777. package/src/cognitive/__tests__/macro-agent-backend.test.ts +0 -673
  778. package/src/cognitive/__tests__/session-converter.test.ts +0 -423
  779. package/src/cognitive/__tests__/workspace-handler.test.ts +0 -221
  780. package/src/cognitive/analyst-role.ts +0 -59
  781. package/src/cognitive/index.ts +0 -49
  782. package/src/cognitive/macro-agent-backend.ts +0 -402
  783. package/src/cognitive/session-converter.ts +0 -151
  784. package/src/cognitive/types.ts +0 -187
  785. package/src/cognitive/workspace-handler.ts +0 -163
  786. package/src/config/index.ts +0 -9
  787. package/src/config/project-config.ts +0 -294
  788. package/src/control/__tests__/control-resilience.test.ts +0 -251
  789. package/src/control/__tests__/control-socket.test.ts +0 -240
  790. package/src/control/control-client.ts +0 -337
  791. package/src/control/control-server.ts +0 -298
  792. package/src/control/index.ts +0 -17
  793. package/src/control/types.ts +0 -95
  794. package/src/dispatch/CLAUDE.md +0 -129
  795. package/src/dispatch/__tests__/loadout-translation.test.ts +0 -141
  796. package/src/dispatch/__tests__/mail-inbound-consumer.integration.test.ts +0 -519
  797. package/src/dispatch/__tests__/mail-inbound-consumer.test.ts +0 -800
  798. package/src/dispatch/__tests__/mail-inbound-reuse-consumer.test.ts +0 -575
  799. package/src/dispatch/__tests__/permission-evaluator.test.ts +0 -196
  800. package/src/dispatch/__tests__/permission-overlay.test.ts +0 -56
  801. package/src/dispatch/__tests__/permissions-handler.test.ts +0 -168
  802. package/src/dispatch/__tests__/spawn-agent-handler.test.ts +0 -282
  803. package/src/dispatch/loadout-translation.ts +0 -138
  804. package/src/dispatch/mail-inbound-consumer.ts +0 -560
  805. package/src/dispatch/mail-inbound-reuse-consumer.ts +0 -479
  806. package/src/dispatch/permission-evaluator.ts +0 -191
  807. package/src/dispatch/permission-overlay.ts +0 -89
  808. package/src/dispatch/permissions-handler.ts +0 -112
  809. package/src/dispatch/spawn-agent-handler.ts +0 -160
  810. package/src/index.ts +0 -117
  811. package/src/integrations/__tests__/context-builder.test.ts +0 -218
  812. package/src/integrations/__tests__/sessionlog.test.ts +0 -498
  813. package/src/integrations/__tests__/skilltree.test.ts +0 -136
  814. package/src/integrations/context-builder.ts +0 -280
  815. package/src/integrations/sessionlog.ts +0 -194
  816. package/src/integrations/skilltree.ts +0 -184
  817. package/src/lifecycle/__tests__/cascade-consolidation.test.ts +0 -240
  818. package/src/lifecycle/__tests__/handlers-v2.test.ts +0 -565
  819. package/src/lifecycle/cascade.ts +0 -335
  820. package/src/lifecycle/cleanup.ts +0 -373
  821. package/src/lifecycle/handlers-v2.ts +0 -508
  822. package/src/lifecycle/index.ts +0 -76
  823. package/src/lifecycle/types.ts +0 -260
  824. package/src/map/__tests__/cascade-bridge.test.ts +0 -229
  825. package/src/map/__tests__/cascade-diff-server.test.ts +0 -434
  826. package/src/map/__tests__/emit-event.test.ts +0 -71
  827. package/src/map/__tests__/lifecycle-bridge.test.ts +0 -430
  828. package/src/map/__tests__/mail-bridge.test.ts +0 -321
  829. package/src/map/__tests__/permission-forwarding.test.ts +0 -143
  830. package/src/map/__tests__/sidecar-diff-install-smoke.test.ts +0 -90
  831. package/src/map/__tests__/sidecar-integration.test.ts +0 -190
  832. package/src/map/__tests__/task-bridge.test.ts +0 -153
  833. package/src/map/__tests__/trajectory-reporter.test.ts +0 -173
  834. package/src/map/acp-bridge.ts +0 -293
  835. package/src/map/cascade-action-handler.ts +0 -205
  836. package/src/map/cascade-bridge.ts +0 -339
  837. package/src/map/cascade-diff-server.ts +0 -404
  838. package/src/map/cc-swarm-hooks.ts +0 -242
  839. package/src/map/coordination-handler.ts +0 -232
  840. package/src/map/index.ts +0 -18
  841. package/src/map/lifecycle-bridge.ts +0 -236
  842. package/src/map/mail-bridge.ts +0 -263
  843. package/src/map/repo-workspace.ts +0 -82
  844. package/src/map/server.ts +0 -758
  845. package/src/map/sidecar.ts +0 -826
  846. package/src/map/task-bridge.ts +0 -89
  847. package/src/map/trajectory-reporter.ts +0 -124
  848. package/src/map/types.ts +0 -304
  849. package/src/mcp/__tests__/mcp-server-v2.test.ts +0 -236
  850. package/src/mcp/index.ts +0 -6
  851. package/src/mcp/mcp-server-v2.ts +0 -485
  852. package/src/mcp/tools/done-v2.ts +0 -213
  853. package/src/mcp/types.ts +0 -432
  854. package/src/metrics/__tests__/metrics.test.ts +0 -205
  855. package/src/metrics/index.ts +0 -13
  856. package/src/metrics/metrics.ts +0 -151
  857. package/src/metrics/types.ts +0 -63
  858. package/src/roles/__tests__/config-loader.test.ts +0 -540
  859. package/src/roles/builtin/coordinator.ts +0 -75
  860. package/src/roles/builtin/generic.ts +0 -39
  861. package/src/roles/builtin/index.ts +0 -51
  862. package/src/roles/builtin/integrator.ts +0 -62
  863. package/src/roles/builtin/monitor.ts +0 -65
  864. package/src/roles/builtin/worker.ts +0 -134
  865. package/src/roles/capabilities.ts +0 -257
  866. package/src/roles/config-loader.ts +0 -405
  867. package/src/roles/index.ts +0 -141
  868. package/src/roles/registry.ts +0 -713
  869. package/src/roles/types.ts +0 -344
  870. package/src/store/index.ts +0 -8
  871. package/src/store/types/agents.ts +0 -69
  872. package/src/store/types/events.ts +0 -91
  873. package/src/store/types/index.ts +0 -9
  874. package/src/store/types/messages.ts +0 -32
  875. package/src/store/types/primitives.ts +0 -9
  876. package/src/store/types/tasks.ts +0 -124
  877. package/src/teams/__tests__/team-manager-v2.test.ts +0 -425
  878. package/src/teams/__tests__/team-runtime-v2.test.ts +0 -402
  879. package/src/teams/index.ts +0 -29
  880. package/src/teams/seed-defaults.ts +0 -83
  881. package/src/teams/team-loader.ts +0 -476
  882. package/src/teams/team-manager-v2.ts +0 -343
  883. package/src/teams/team-runtime-v2.ts +0 -943
  884. package/src/teams/types.ts +0 -276
  885. package/src/trigger/__tests__/cron-service.test.ts +0 -548
  886. package/src/trigger/__tests__/scheduler.test.ts +0 -371
  887. package/src/trigger/__tests__/system-event-queue.test.ts +0 -147
  888. package/src/trigger/__tests__/trigger-system-v2.test.ts +0 -257
  889. package/src/trigger/__tests__/wake-manager.test.ts +0 -356
  890. package/src/trigger/__tests__/webhook-handler.test.ts +0 -567
  891. package/src/trigger/index.ts +0 -110
  892. package/src/trigger/queue/index.ts +0 -21
  893. package/src/trigger/queue/system-event-queue.ts +0 -232
  894. package/src/trigger/queue/types.ts +0 -149
  895. package/src/trigger/sources/cron/cron-service.ts +0 -499
  896. package/src/trigger/sources/cron/index.ts +0 -41
  897. package/src/trigger/sources/cron/scheduler.ts +0 -344
  898. package/src/trigger/sources/cron/types.ts +0 -333
  899. package/src/trigger/sources/index.ts +0 -10
  900. package/src/trigger/sources/webhook/index.ts +0 -25
  901. package/src/trigger/sources/webhook/types.ts +0 -205
  902. package/src/trigger/sources/webhook/webhook-handler.ts +0 -410
  903. package/src/trigger/strategies/ai-router.ts +0 -170
  904. package/src/trigger/trigger-system-v2.ts +0 -536
  905. package/src/trigger/types.ts +0 -228
  906. package/src/trigger/wake/index.ts +0 -22
  907. package/src/trigger/wake/types.ts +0 -162
  908. package/src/trigger/wake/wake-manager.ts +0 -390
  909. package/src/workspace/__tests__/git-cascade-adapter.test.ts +0 -563
  910. package/src/workspace/__tests__/land-dispatch.test.ts +0 -214
  911. package/src/workspace/__tests__/self-driving-yaml.test.ts +0 -122
  912. package/src/workspace/__tests__/shared-worktree-refcount.test.ts +0 -154
  913. package/src/workspace/__tests__/standalone-mode.test.ts +0 -118
  914. package/src/workspace/__tests__/workspace-manager-v3.test.ts +0 -245
  915. package/src/workspace/__tests__/yaml-schema.test.ts +0 -210
  916. package/src/workspace/config.ts +0 -165
  917. package/src/workspace/git-cascade-adapter.ts +0 -1213
  918. package/src/workspace/index.ts +0 -110
  919. package/src/workspace/landing/__tests__/strategies.test.ts +0 -184
  920. package/src/workspace/landing/direct-push.ts +0 -91
  921. package/src/workspace/landing/index.ts +0 -40
  922. package/src/workspace/landing/merge-to-parent.ts +0 -229
  923. package/src/workspace/landing/optimistic-push.ts +0 -36
  924. package/src/workspace/landing/queue-to-branch.ts +0 -108
  925. package/src/workspace/merge-queue/__tests__/conflict-resolution-git.e2e.test.ts +0 -641
  926. package/src/workspace/merge-queue/__tests__/conflict-resolution.test.ts +0 -707
  927. package/src/workspace/merge-queue/__tests__/merge-queue-concurrent.test.ts +0 -628
  928. package/src/workspace/merge-queue/__tests__/merge-queue-edge-cases.test.ts +0 -1217
  929. package/src/workspace/merge-queue/__tests__/merge-queue.test.ts +0 -506
  930. package/src/workspace/merge-queue/__tests__/real-git-operations.e2e.test.ts +0 -556
  931. package/src/workspace/merge-queue/__tests__/resolver-flow.test.ts +0 -472
  932. package/src/workspace/merge-queue/index.ts +0 -38
  933. package/src/workspace/merge-queue/merge-queue.ts +0 -585
  934. package/src/workspace/merge-queue/schema.ts +0 -98
  935. package/src/workspace/merge-queue/types.ts +0 -316
  936. package/src/workspace/pool/__tests__/worktree-pool.integration.test.ts +0 -1281
  937. package/src/workspace/pool/__tests__/worktree-pool.test.ts +0 -590
  938. package/src/workspace/pool/index.ts +0 -26
  939. package/src/workspace/pool/types.ts +0 -276
  940. package/src/workspace/pool/worktree-pool.ts +0 -659
  941. package/src/workspace/recovery/__tests__/auto-resolve-integration.test.ts +0 -127
  942. package/src/workspace/recovery/__tests__/spawn-resolver.test.ts +0 -139
  943. package/src/workspace/recovery/__tests__/strategies.test.ts +0 -145
  944. package/src/workspace/recovery/abandon.ts +0 -51
  945. package/src/workspace/recovery/auto-resolve.ts +0 -119
  946. package/src/workspace/recovery/defer.ts +0 -23
  947. package/src/workspace/recovery/escalate.ts +0 -30
  948. package/src/workspace/recovery/index.ts +0 -58
  949. package/src/workspace/recovery/spawn-resolver.ts +0 -152
  950. package/src/workspace/recovery/types.ts +0 -54
  951. package/src/workspace/strategies/index.ts +0 -18
  952. package/src/workspace/strategies/optimistic.ts +0 -139
  953. package/src/workspace/strategies/queue.ts +0 -81
  954. package/src/workspace/strategies/registry.ts +0 -89
  955. package/src/workspace/strategies/trunk.ts +0 -123
  956. package/src/workspace/strategies/types.ts +0 -145
  957. package/src/workspace/topology/__tests__/yaml-driven.test.ts +0 -345
  958. package/src/workspace/topology/index.ts +0 -18
  959. package/src/workspace/topology/no-workspace.ts +0 -39
  960. package/src/workspace/topology/types.ts +0 -116
  961. package/src/workspace/topology/yaml-driven.ts +0 -316
  962. package/src/workspace/types-v3.ts +0 -162
  963. package/src/workspace/types.ts +0 -541
  964. package/src/workspace/workspace-manager.ts +0 -1577
  965. package/src/workspace/yaml-schema.ts +0 -216
  966. package/test_fixtures/README.md +0 -425
  967. package/test_fixtures/fixtures/behaviors/coordinators.ts +0 -196
  968. package/test_fixtures/fixtures/behaviors/index.ts +0 -62
  969. package/test_fixtures/fixtures/behaviors/integrators.ts +0 -143
  970. package/test_fixtures/fixtures/behaviors/monitors.ts +0 -199
  971. package/test_fixtures/fixtures/behaviors/workers.ts +0 -348
  972. package/test_fixtures/fixtures/index.ts +0 -7
  973. package/test_fixtures/fixtures/projects/index.ts +0 -23
  974. package/test_fixtures/fixtures/projects/project-with-specs.ts +0 -44
  975. package/test_fixtures/fixtures/projects/typescript-project.ts +0 -200
  976. package/test_fixtures/fixtures/repos/index.ts +0 -6
  977. package/test_fixtures/fixtures/repos/temp-repo-factory.ts +0 -299
  978. package/test_fixtures/fixtures/repos/types.ts +0 -174
  979. package/test_fixtures/harness/assertions/harness-assertions.ts +0 -752
  980. package/test_fixtures/harness/assertions/index.ts +0 -8
  981. package/test_fixtures/harness/index.ts +0 -15
  982. package/test_fixtures/harness/simulator/agent-simulator.ts +0 -768
  983. package/test_fixtures/harness/simulator/behavior-executor.ts +0 -580
  984. package/test_fixtures/harness/simulator/index.ts +0 -14
  985. package/test_fixtures/harness/simulator/types.ts +0 -459
  986. package/test_fixtures/harness/test-harness.ts +0 -770
  987. package/test_fixtures/harness/timing/event-stepper.ts +0 -344
  988. package/test_fixtures/harness/timing/index.ts +0 -8
  989. package/tsconfig.json +0 -21
  990. package/vitest.config.ts +0 -30
  991. package/vitest.e2e.config.ts +0 -28
  992. package/vitest.setup.ts +0 -12
@@ -1,1127 +0,0 @@
1
- # Implementation Details: Self-Driving Support
2
-
3
- Detailed implementation plan for each phase, with resolved ambiguities, concrete interface designs, and precise code integration points.
4
-
5
- Companion to [plan-self-driving-support.md](plan-self-driving-support.md) (high-level plan) and [team-templates.md](team-templates.md) (team template design).
6
-
7
- ---
8
-
9
- ## Ambiguities and Design Decisions
10
-
11
- These are questions that arose when mapping the design documents to the actual codebase. Each is resolved here with rationale.
12
-
13
- ### A1: Where does TeamRuntime sit in the dependency graph?
14
-
15
- **Problem**: TeamRuntime needs access to RoleRegistry, AgentManager, MessageRouter, TaskBackend, and IntegrationStrategy. But these services are created independently in the CLI (`src/cli/index.ts`) and passed around via dependency injection. TeamRuntime isn't a service — it's a configuration layer that modifies how existing services behave.
16
-
17
- **Resolution**: TeamRuntime is initialized *after* core services are created but *before* any agents are spawned. It receives service references and configures them:
18
-
19
- ```typescript
20
- // In CLI start/chat commands (or equivalent bootstrap path):
21
- const eventStore = await createEventStore({ inMemory: false });
22
- const messageRouter = createMessageRouter(eventStore);
23
- const agentManager = createAgentManager(eventStore, messageRouter);
24
- const taskBackend = createInMemoryTaskBackend(eventStore);
25
-
26
- // NEW: Load and apply team configuration
27
- let teamRuntime: TeamRuntime | null = null;
28
- if (teamName) {
29
- const manifest = await TeamLoader.load(teamName);
30
- teamRuntime = new TeamRuntime(manifest, {
31
- roleRegistry: agentManager.getRoleRegistry(), // exposed getter
32
- messageRouter,
33
- taskBackend,
34
- eventStore,
35
- });
36
- await teamRuntime.initialize();
37
- }
38
- ```
39
-
40
- TeamRuntime does three things at `initialize()`:
41
- 1. Registers team roles into the RoleRegistry (team layer, highest priority)
42
- 2. Sets up an IntegrationStrategy from the registry
43
- 3. Stores team state (manifest, active strategy, task mode) for later use during spawns
44
-
45
- TeamRuntime does **not** wrap or replace AgentManager. Instead, it hooks into the spawn flow via a **spawn interceptor** pattern (see A2).
46
-
47
- ### A2: How does TeamRuntime intercept agent spawns?
48
-
49
- **Problem**: When an agent is spawned within a team, the TeamRuntime needs to:
50
- - Add topic subscriptions from the communication topology
51
- - Set up peer routes
52
- - Inject the role's static prompt
53
- - Add MCP servers from the team config
54
- - Set team environment variables
55
-
56
- Currently, `AgentManager.spawn()` handles all of this. We need team context without a deep refactor.
57
-
58
- **Resolution**: Add a `spawnInterceptor` hook to AgentManager. The interceptor receives the `SpawnAgentOptions` and returns modified options before the spawn proceeds.
59
-
60
- ```typescript
61
- // In agent-manager.ts
62
- type SpawnInterceptor = (options: SpawnAgentOptions) => SpawnAgentOptions | Promise<SpawnAgentOptions>;
63
-
64
- interface AgentManagerConfig {
65
- // ... existing fields
66
- spawnInterceptor?: SpawnInterceptor;
67
- }
68
- ```
69
-
70
- TeamRuntime registers itself as the interceptor:
71
-
72
- ```typescript
73
- // In TeamRuntime.initialize()
74
- agentManager.setSpawnInterceptor((options) => {
75
- const roleManifest = this.manifest.roles.find(r => r.name === options.role);
76
- if (!roleManifest) return options; // Unknown role, pass through
77
-
78
- return {
79
- ...options,
80
- // Inject team topic subscriptions
81
- topics: [
82
- ...(options.topics ?? []),
83
- ...this.getTopicsForRole(options.role),
84
- ],
85
- // Add team MCP servers
86
- config: {
87
- ...options.config,
88
- mcpServers: [
89
- ...(options.config?.mcpServers ?? []),
90
- ...this.getMCPServersForRole(options.role),
91
- ],
92
- env: {
93
- ...options.config?.env,
94
- MACRO_TEAM_NAME: this.manifest.name,
95
- MACRO_INTEGRATION_STRATEGY: this.manifest.macro_agent.integration.strategy,
96
- MACRO_TASK_MODE: this.manifest.macro_agent.task_assignment.mode,
97
- },
98
- },
99
- // Team's custom prompt replaces the default
100
- customPrompt: roleManifest.prompt
101
- ? this.loadedPrompts.get(roleManifest.prompt)
102
- : options.customPrompt,
103
- };
104
- });
105
- ```
106
-
107
- The interceptor pattern is minimal — one new optional field on AgentManagerConfig, one check in spawn(). No existing code changes beyond the hook point.
108
-
109
- **Where the hook goes in spawn()**: After options destructuring (line ~346), before capability checks (line ~379):
110
-
111
- ```typescript
112
- async function spawn(rawOptions: SpawnAgentOptions): Promise<SpawnedAgent> {
113
- // Apply spawn interceptor if present
114
- const options = spawnInterceptor
115
- ? await spawnInterceptor(rawOptions)
116
- : rawOptions;
117
-
118
- const { task, task_id, parent, ... } = options;
119
- // ... rest of spawn continues unchanged
120
- }
121
- ```
122
-
123
- ### A3: How do companion agents work without a parent-child relationship?
124
-
125
- **Problem**: The self-driving team has a judge companion — a peer of the planner, not its child. But `AgentManager.spawn()` assumes every agent has a parent (except the head manager). Companions need to be discoverable via role addressing (`{ role: "judge" }`) without being in anyone's subtree.
126
-
127
- **Resolution**: Companions are spawned by the TeamRuntime bootstrap, not by any agent. They use `parent: null` (no parent, like a head manager) but are tagged with the team name for scoping.
128
-
129
- ```typescript
130
- // In TeamRuntime.bootstrap()
131
- async bootstrap(): Promise<void> {
132
- // 1. Spawn root agent
133
- const root = await this.agentManager.spawn({
134
- task: `Team root: ${this.manifest.name}`,
135
- parent: null, // head-like agent
136
- role: this.manifest.topology.root.role,
137
- config: this.manifest.topology.root.config,
138
- });
139
- this.rootAgentId = root.id;
140
-
141
- // 2. Spawn companions
142
- for (const companion of this.manifest.topology.companions ?? []) {
143
- const agent = await this.agentManager.spawn({
144
- task: `Companion: ${companion.role}`,
145
- parent: null, // peer, not child
146
- role: companion.role,
147
- config: companion.config,
148
- });
149
- this.companionAgentIds.push(agent.id);
150
- }
151
-
152
- // 3. Set up peer subscriptions between root and companions
153
- // (neither is in the other's subtree, so explicit subscriptions needed)
154
- for (const peerId of this.companionAgentIds) {
155
- this.setupPeerSubscriptions(this.rootAgentId, peerId);
156
- }
157
- }
158
- ```
159
-
160
- **Peer discovery**: Companions are discoverable via `{ role: "judge" }` MAP addressing because `setupDefaultSubscriptions` already subscribes agents to their role channel when `role` is provided (line 1078-1081 in message-router.ts). No changes needed for role-based discovery.
161
-
162
- **Subtree visibility**: Since the judge is not in the planner's subtree, it won't automatically receive worker status updates. The TeamRuntime's spawn interceptor adds explicit topic subscriptions (from the communication topology) to solve this — the judge subscribes to `work_coordination` and `health` topics.
163
-
164
- ### A4: How does IntegrationStrategy inject into the done() handler?
165
-
166
- **Problem**: The worker done() handler (in `src/lifecycle/handlers/worker.ts`) currently receives `WorkerHandlerDeps` which includes `mergeQueue?`. We need to replace (or augment) this with `integrationStrategy`. But `WorkerHandlerDeps` is used in `AllHandlerDeps` (in `handlers/index.ts`), which is constructed in `createDoneHandler` (in `mcp/tools/done.ts`) from `DoneToolDeps`.
167
-
168
- The dependency chain is:
169
- ```
170
- DoneToolDeps → AllHandlerDeps → WorkerHandlerDeps → mergeQueue?
171
- ```
172
-
173
- **Resolution**: Add `integrationStrategy?` to `AllHandlerDeps` (and thus `WorkerHandlerDeps`). The worker handler checks for it first, falls back to mergeQueue:
174
-
175
- ```typescript
176
- // In handlers/index.ts
177
- export interface AllHandlerDeps {
178
- messageRouter: MessageRouter;
179
- agentManager: AgentManager;
180
- mergeQueue?: MergeQueueInterface; // existing
181
- getWorkspacePath?: (agentId: string) => string | undefined;
182
- integrationStrategy?: IntegrationStrategy; // NEW
183
- taskMode?: 'push' | 'pull'; // NEW
184
- }
185
- ```
186
-
187
- ```typescript
188
- // In handlers/worker.ts, Step 4 (merge/integration)
189
- if (args.status === 'completed' && context.workspacePath) {
190
- if (deps.integrationStrategy) {
191
- // NEW: use pluggable strategy
192
- const result = await deps.integrationStrategy.land({
193
- streamId: context.streamId ?? 'default',
194
- workerBranch: sourceBranch,
195
- integrationBranch: context.integrationBranch ?? 'main',
196
- workerAgentId: context.agentId,
197
- taskId: context.taskId ?? '',
198
- workspacePath: context.workspacePath,
199
- });
200
- // Handle result...
201
- } else if (deps.mergeQueue) {
202
- // EXISTING: fall back to merge queue (backward compatible)
203
- // ... current merge queue logic unchanged ...
204
- }
205
- }
206
- ```
207
-
208
- The `DoneToolDeps` gets a new optional field:
209
-
210
- ```typescript
211
- export interface DoneToolDeps {
212
- // ... existing fields
213
- integrationStrategy?: IntegrationStrategy;
214
- taskMode?: 'push' | 'pull';
215
- }
216
- ```
217
-
218
- And in `createDoneHandler`, it passes through to `AllHandlerDeps`:
219
-
220
- ```typescript
221
- const handlerDeps: AllHandlerDeps = {
222
- messageRouter,
223
- agentManager,
224
- mergeQueue: workspaceManager?.getMergeQueue?.(),
225
- getWorkspacePath: ...,
226
- integrationStrategy: deps.integrationStrategy, // NEW
227
- taskMode: deps.taskMode, // NEW
228
- };
229
- ```
230
-
231
- **Where does the strategy come from at MCP server creation time?** The `MCPServices` type gets extended with optional team context:
232
-
233
- ```typescript
234
- // In mcp-server.ts
235
- interface MCPServices {
236
- // ... existing fields
237
- integrationStrategy?: IntegrationStrategy;
238
- taskMode?: 'push' | 'pull';
239
- }
240
- ```
241
-
242
- TeamRuntime sets these on the MCPServices when it's active. When no team is loaded, these are undefined and the existing mergeQueue path is used.
243
-
244
- ### A5: How does the pull-mode done() handler keep agents alive?
245
-
246
- **Problem**: Currently, `handleWorkerDone` returns `{ shouldTerminate: true }` for completed/failed status. In pull mode, a completed worker should NOT terminate — it should continue its claim loop.
247
-
248
- **Resolution**: The worker handler checks `deps.taskMode`:
249
-
250
- ```typescript
251
- // In handlers/worker.ts, final return
252
- if (deps.taskMode === 'pull' && args.status === 'completed') {
253
- return {
254
- shouldTerminate: false, // Worker continues to claim next task
255
- warnings: handlerWarnings,
256
- };
257
- }
258
-
259
- return {
260
- shouldTerminate: args.status === 'completed' || args.status === 'failed',
261
- warnings: handlerWarnings,
262
- };
263
- ```
264
-
265
- The worker agent's prompt (from the team template) instructs it to call `claim_task()` after `done()`. The `done()` tool returning `shouldTerminate: false` means the MCP server stays alive and the agent can continue.
266
-
267
- **Idle timeout**: The agent is responsible for tracking idle time. If `claim_task()` returns empty repeatedly beyond the configured `idle_timeout_s`, the agent calls `done({ status: "completed", summary: "idle exit" })`. This is conveyed in the injected interaction pattern section of the system prompt (see team-templates.md "Interaction Pattern Injection").
268
-
269
- ### A6: How does `claim_task` work with optimistic locking in InMemoryTaskBackend?
270
-
271
- **Problem**: `InMemoryTaskBackend` wraps the EventStore. Tasks are materialized views from events. There's no explicit version field for CAS operations. Under concurrency (multiple MCP server processes calling claim), we need atomicity.
272
-
273
- **Resolution**: The EventStore's SQLite backend serializes writes. Since all task state comes from events, a claim operation is:
274
-
275
- 1. Read task state (from materialized view)
276
- 2. Check status is `pending` or `ready` (claimable)
277
- 3. Emit an `assign` event
278
- 4. The materialized view updates the task to `assigned`
279
-
280
- Since the EventStore is SQLite-backed and writes are serialized, two concurrent claims for the same task will be ordered — the second one will see the task is already assigned and fail.
281
-
282
- ```typescript
283
- // In memory.ts
284
- async claim(agentId: string, filters?: ClaimFilters): Promise<ExtendedTask | null> {
285
- // 1. Find claimable tasks matching filters
286
- const candidates = this.eventStore.listTasks({
287
- status: 'pending',
288
- ...filters,
289
- }).filter(t => !t.assigned_agent);
290
-
291
- if (candidates.length === 0) return null;
292
-
293
- // 2. Pick one (first match, or random for load distribution)
294
- const target = candidates[0];
295
-
296
- // 3. Try to assign — this emits an event through SQLite
297
- // If another process claimed it first, the task status won't be 'pending'
298
- // and assign() will throw (status transition validation)
299
- try {
300
- await this.assign(target.id, agentId);
301
- await this.start(target.id);
302
- return this.get(target.id);
303
- } catch {
304
- // Another agent claimed it — return null to retry
305
- return null;
306
- }
307
- }
308
- ```
309
-
310
- This is not true CAS, but it works because:
311
- - SQLite serializes writes across processes
312
- - `assign()` validates status transitions (only `pending` → `assigned` is valid)
313
- - The window between read and write is small (same process, synchronous event emit)
314
- - Under contention, the failure mode is "try again" not "corrupt state"
315
-
316
- For the InMemory backend this is sufficient. If a higher-concurrency backend is needed later, it can implement true CAS.
317
-
318
- ### A7: How does the system prompt change for team-loaded roles?
319
-
320
- **Problem**: Currently, `generateSystemPrompt()` in `system-prompt.ts` generates a fixed structure. Team templates provide static prompt files and interaction pattern injections. How do these compose?
321
-
322
- **Resolution**: Extend `SystemPromptContext` with optional team fields:
323
-
324
- ```typescript
325
- interface SystemPromptContext {
326
- // ... existing fields
327
- teamPrompt?: string; // Static prompt from team template prompts/<role>.md
328
- interactionPatterns?: string[]; // Auto-injected sections (pull mode, trunk integration, etc.)
329
- }
330
- ```
331
-
332
- The prompt assembly order in `generateSystemPrompt()` becomes:
333
-
334
- ```
335
- 1. Identity section ← always (agent ID, task, lineage)
336
- 2. Role section ← existing role guidance OR team prompt (mutually exclusive)
337
- 3. Interaction patterns ← NEW: auto-injected operational sections
338
- 4. MCP tools listing ← always (capability-filtered)
339
- 5. Communication guidelines ← always
340
- 6. Guidelines section ← always (execution, error handling)
341
- ```
342
-
343
- In `AgentManager.spawn()`, the team prompt replaces the default role section:
344
-
345
- ```typescript
346
- // Current code (line ~421-424):
347
- const resolvedRole = roleRegistry.resolveRole(role ?? "worker");
348
- if (resolvedRole.systemPrompt) {
349
- systemPrompt += `\n\n# Role-Specific Instructions\n\n${resolvedRole.systemPrompt}`;
350
- }
351
-
352
- // With team support:
353
- const resolvedRole = roleRegistry.resolveRole(role ?? "worker");
354
- if (teamPrompt) {
355
- // Team prompt replaces role.systemPrompt
356
- systemPrompt += `\n\n# Role Instructions\n\n${teamPrompt}`;
357
- } else if (resolvedRole.systemPrompt) {
358
- systemPrompt += `\n\n# Role-Specific Instructions\n\n${resolvedRole.systemPrompt}`;
359
- }
360
-
361
- // Append interaction pattern sections
362
- for (const pattern of interactionPatterns ?? []) {
363
- systemPrompt += `\n\n${pattern}`;
364
- }
365
- ```
366
-
367
- The spawn interceptor (A2) provides `teamPrompt` and `interactionPatterns` via the spawn options. This requires adding these fields to `SpawnAgentOptions` and `SystemPromptContext`.
368
-
369
- ### A8: What happens to existing behavior when no team is loaded?
370
-
371
- **Problem**: We need to ensure that without `--team`, everything works exactly as before.
372
-
373
- **Resolution**: All new code paths are guarded by optional checks:
374
-
375
- - No `spawnInterceptor`? Options pass through unchanged.
376
- - No `integrationStrategy`? Worker handler falls back to `mergeQueue` (existing path).
377
- - No `taskMode`? Done handler returns `shouldTerminate: true` (existing behavior).
378
- - No `teamPrompt`? System prompt uses `resolvedRole.systemPrompt` (existing behavior).
379
- - No team roles registered? RoleRegistry resolves to built-in roles (existing behavior).
380
-
381
- The `queue` integration strategy wraps the existing merge queue with no behavioral change.
382
-
383
- ### A9: How do signal channels map to topics at runtime?
384
-
385
- **Problem**: The team manifest defines named channels (`task_updates`, `work_coordination`, `health`) with signal lists. The router has `topic` channels. How do we bridge these?
386
-
387
- **Resolution**: Each named channel becomes a topic. When the TeamRuntime's spawn interceptor adds topics for a role, it uses the channel names:
388
-
389
- ```yaml
390
- # In team.yaml
391
- communication:
392
- channels:
393
- task_updates:
394
- signals: [TASK_CREATED, TASK_COMPLETED, TASK_FAILED]
395
- subscriptions:
396
- planner:
397
- - channel: task_updates
398
- ```
399
-
400
- Maps to:
401
-
402
- ```typescript
403
- // In TeamRuntime.getTopicsForRole("planner")
404
- return ["task_updates"]; // topic name = channel name
405
- ```
406
-
407
- When an agent emits a signal (e.g., `TASK_CREATED`), it publishes to the channel's topic:
408
-
409
- ```typescript
410
- // In a future emit_signal MCP tool (or via emit_status with signal details)
411
- messageRouter.sendToAddress({
412
- from: agentId,
413
- to: { scope: "task_updates" }, // ScopeAddress → routes to topic subscribers
414
- content: JSON.stringify({ signal: "TASK_CREATED", taskId, ... }),
415
- });
416
- ```
417
-
418
- **Signal filtering**: For subscriptions with specific signals (e.g., `judge subscribes to task_updates but only TASK_FAILED`), filtering happens at message receive time. The agent receives all messages on the `task_updates` topic, but the MCP tool (or a thin filtering wrapper) only surfaces messages matching the subscribed signals. This avoids adding filtering complexity to the router.
419
-
420
- Implementation options for filtering:
421
- 1. **Filter in `check_messages`**: When the MCP tool retrieves messages, apply the signal filter from the team manifest. This is simplest.
422
- 2. **Separate topics per signal**: `task_updates.TASK_CREATED`, `task_updates.TASK_FAILED`. More topics but no filtering needed. Verbose.
423
- 3. **Router-level filter**: Add filter predicates to subscriptions. Most powerful but changes the router.
424
-
425
- **Recommendation**: Option 1 (filter in check_messages) for Phase 1. It's the least invasive. The team manifest's signal filters are stored in TeamRuntime and applied when the agent reads messages. Can upgrade to option 3 later if performance requires it.
426
-
427
- ### A10: Enforcement of emissions — where does it happen?
428
-
429
- **Problem**: The team manifest declares what signals a role can emit. The current router has no emission restrictions.
430
-
431
- **Resolution**: Enforcement happens at the MCP tool level, not the router level. When an agent calls `emit_status` (or a future `emit_signal` tool), the tool handler checks the team manifest's `emissions` declaration for the agent's role.
432
-
433
- ```typescript
434
- // In the emit_status tool handler (or a wrapper)
435
- if (teamRuntime && enforcement === 'strict') {
436
- const allowed = teamRuntime.getAllowedEmissions(context.role);
437
- if (allowed && !allowed.includes(signal)) {
438
- return { error: `Role ${context.role} cannot emit signal ${signal}` };
439
- }
440
- }
441
- ```
442
-
443
- For `permissive` mode, the check logs a warning but allows the emission. For `audit` mode, it records the emission in the EventStore for later analysis.
444
-
445
- This keeps the router clean (it doesn't need to know about team-level enforcement) and is easy to implement as a thin layer in the MCP tool.
446
-
447
- ---
448
-
449
- ## Phase 1: Team Template System — Implementation Details
450
-
451
- ### 1.1 TeamManifest Types (`src/teams/types.ts`)
452
-
453
- ```typescript
454
- // ─────────────────────────────────────────────────────────────
455
- // Core manifest types (generic, portable)
456
- // ─────────────────────────────────────────────────────────────
457
-
458
- export interface TeamManifest {
459
- /** Team name (directory name) */
460
- name: string;
461
- /** Human-readable description */
462
- description: string;
463
- /** Schema version */
464
- version: number;
465
-
466
- /** Role names used by this team */
467
- roles: string[];
468
-
469
- /** Agent spawn topology */
470
- topology: TeamTopology;
471
-
472
- /** Communication topology */
473
- communication: TeamCommunication;
474
-
475
- /** macro-agent specific extensions */
476
- macro_agent: MacroAgentExtensions;
477
-
478
- /** Resolved role definitions (populated by TeamLoader) */
479
- _resolvedRoles: Map<string, ResolvedTeamRole>;
480
- /** Loaded prompt contents (populated by TeamLoader) */
481
- _loadedPrompts: Map<string, string>;
482
- /** Loaded MCP server configs (populated by TeamLoader) */
483
- _mcpServers: Map<string, McpServerConfig[]>;
484
- }
485
-
486
- // ─────────────────────────────────────────────────────────────
487
- // Topology
488
- // ─────────────────────────────────────────────────────────────
489
-
490
- export interface TeamTopology {
491
- /** The initial agent spawned when the team starts */
492
- root: TopologyNode;
493
- /** Agents spawned alongside root (peers, not children) */
494
- companions?: TopologyNode[];
495
- /** Which roles can spawn which other roles */
496
- spawn_rules?: Record<string, string[]>;
497
- }
498
-
499
- export interface TopologyNode {
500
- role: string;
501
- prompt?: string; // path to prompt file relative to team dir
502
- config?: {
503
- model?: string;
504
- [key: string]: unknown;
505
- };
506
- }
507
-
508
- // ─────────────────────────────────────────────────────────────
509
- // Communication
510
- // ─────────────────────────────────────────────────────────────
511
-
512
- export interface TeamCommunication {
513
- /** Named signal channels */
514
- channels?: Record<string, ChannelDefinition>;
515
- /** Per-role subscription declarations */
516
- subscriptions?: Record<string, ChannelSubscription[]>;
517
- /** Per-role emission declarations */
518
- emissions?: Record<string, string[]>;
519
- /** Routing configuration */
520
- routing?: CommunicationRouting;
521
- /** Enforcement level */
522
- enforcement?: 'strict' | 'permissive' | 'audit';
523
- }
524
-
525
- export interface ChannelDefinition {
526
- description?: string;
527
- signals: string[];
528
- }
529
-
530
- export interface ChannelSubscription {
531
- channel: string;
532
- /** If omitted, subscribes to all signals in the channel */
533
- signals?: string[];
534
- }
535
-
536
- export interface CommunicationRouting {
537
- /** Status flow direction */
538
- status?: 'upstream';
539
- /** Explicit peer connections */
540
- peers?: PeerConnection[];
541
- }
542
-
543
- export interface PeerConnection {
544
- from: string; // role name
545
- to: string; // role name
546
- via: 'direct' | 'topic' | 'scope';
547
- signals?: string[];
548
- }
549
-
550
- // ─────────────────────────────────────────────────────────────
551
- // macro-agent extensions
552
- // ─────────────────────────────────────────────────────────────
553
-
554
- export interface MacroAgentExtensions {
555
- task_assignment?: {
556
- mode: 'push' | 'pull';
557
- pull?: {
558
- idle_timeout_s?: number;
559
- claim_retry_delay_ms?: number;
560
- max_concurrent_per_agent?: number;
561
- };
562
- };
563
-
564
- integration?: {
565
- strategy: string; // 'queue' | 'trunk' | 'optimistic' | custom name
566
- config?: Record<string, unknown>;
567
- };
568
-
569
- lifecycle?: {
570
- continuations?: {
571
- enabled: boolean;
572
- max_history_messages?: number;
573
- checkpoint_interval?: 'round_trip' | 'none';
574
- };
575
- scaling?: {
576
- min_workers?: number;
577
- max_workers?: number;
578
- scale_on?: 'task_queue_depth' | 'manual';
579
- idle_drain?: boolean;
580
- };
581
- };
582
-
583
- observability?: {
584
- metrics_window_s?: number;
585
- snapshot_interval_s?: number;
586
- };
587
- }
588
-
589
- // ─────────────────────────────────────────────────────────────
590
- // Role definition within a team template
591
- // ─────────────────────────────────────────────────────────────
592
-
593
- export interface TeamRoleDefinition {
594
- name: string;
595
- extends?: string;
596
- display_name?: string;
597
- description?: string;
598
-
599
- /** Full replacement capability list */
600
- capabilities?: string[];
601
-
602
- /** Additive/subtractive capabilities (relative to extends) */
603
- capabilities_add?: string[];
604
- capabilities_remove?: string[];
605
-
606
- /** Path to prompt file (relative to team dir) */
607
- prompt?: string;
608
-
609
- /** macro-agent specific role config */
610
- macro_agent?: {
611
- workspace?: {
612
- type?: string;
613
- branch_pattern?: string;
614
- cleanup_on_terminate?: boolean;
615
- };
616
- lifecycle?: {
617
- type?: 'ephemeral' | 'persistent' | 'daemon' | 'event-driven';
618
- cascade_terminate?: boolean;
619
- self_cleanup?: boolean;
620
- task_bound?: boolean;
621
- parent_bound?: boolean;
622
- max_duration_ms?: number;
623
- };
624
- };
625
- }
626
-
627
- /** Role definition with inheritance resolved and capabilities computed */
628
- export interface ResolvedTeamRole {
629
- name: string;
630
- baseRole: string; // The built-in role this extends
631
- capabilities: string[]; // Final computed capability set
632
- prompt?: string; // Loaded prompt content
633
- roleDefinition: import('../roles/types.js').RoleDefinition; // For RoleRegistry
634
- }
635
- ```
636
-
637
- ### 1.2 TeamLoader (`src/teams/team-loader.ts`)
638
-
639
- ```
640
- TeamLoader.load(teamName: string, basePath?: string): Promise<TeamManifest>
641
-
642
- Steps:
643
- 1. Resolve directory: basePath ?? cwd / .multiagent/teams/<teamName>/
644
- 2. Read and parse team.yaml (use yaml library, already in deps or add)
645
- 3. Validate manifest against TeamManifest schema (Zod validation)
646
- 4. For each role name in manifest.roles:
647
- a. Check roles/<name>.yaml exists → parse TeamRoleDefinition
648
- b. If not found, check if it's a built-in role name → use as-is
649
- c. Resolve extends chain:
650
- - Load parent role from RoleRegistry
651
- - Compute final capabilities:
652
- - If TeamRoleDefinition.capabilities is set → full replacement
653
- - If .capabilities_add/.capabilities_remove → parent.capabilities + add - remove
654
- d. Build ResolvedTeamRole with final RoleDefinition
655
- 5. For each prompt reference in topology and roles:
656
- a. Read prompts/<name>.md → store in _loadedPrompts map
657
- 6. If tools/mcp-servers.json exists:
658
- a. Parse → store per-role MCP server configs in _mcpServers map
659
- 7. Validate communication topology:
660
- a. All subscription channel refs exist in channels
661
- b. All emission signals exist in some channel
662
- c. All peer connection roles exist in manifest.roles
663
- 8. Return fully resolved TeamManifest
664
- ```
665
-
666
- **Dependencies**: `js-yaml` for YAML parsing (add to package.json), `zod` for validation (already used).
667
-
668
- **Error handling**: TeamLoader throws typed errors (`TeamLoadError`) with specific codes: `MANIFEST_NOT_FOUND`, `INVALID_MANIFEST`, `ROLE_NOT_FOUND`, `PROMPT_NOT_FOUND`, `INVALID_COMMUNICATION`.
669
-
670
- ### 1.3 TeamRuntime (`src/teams/team-runtime.ts`)
671
-
672
- ```typescript
673
- export class TeamRuntime {
674
- private manifest: TeamManifest;
675
- private services: TeamServices;
676
- private integrationStrategy?: IntegrationStrategy;
677
- private rootAgentId?: string;
678
- private companionAgentIds: string[] = [];
679
-
680
- constructor(manifest: TeamManifest, services: TeamServices);
681
-
682
- /** Wire team config into running services */
683
- async initialize(): Promise<void>;
684
-
685
- /** Spawn root + companion agents */
686
- async bootstrap(): Promise<{ rootId: string; companionIds: string[] }>;
687
-
688
- /** Tear down team (terminate agents, clean up) */
689
- async teardown(): Promise<void>;
690
-
691
- /** Get integration strategy (for DoneToolDeps) */
692
- getIntegrationStrategy(): IntegrationStrategy | undefined;
693
-
694
- /** Get task mode (for DoneToolDeps) */
695
- getTaskMode(): 'push' | 'pull';
696
-
697
- /** Get topics a role should subscribe to (for spawn interceptor) */
698
- getTopicsForRole(role: string): string[];
699
-
700
- /** Get MCP servers for a role (for spawn interceptor) */
701
- getMCPServersForRole(role: string): McpServerConfig[];
702
-
703
- /** Get the loaded prompt for a role (for spawn interceptor) */
704
- getPromptForRole(role: string): string | undefined;
705
-
706
- /** Get interaction pattern injection sections (for spawn interceptor) */
707
- getInteractionPatterns(): string[];
708
-
709
- /** Check if a signal emission is allowed for a role */
710
- isEmissionAllowed(role: string, signal: string): boolean;
711
-
712
- /** Get active manifest (for API) */
713
- getManifest(): TeamManifest;
714
- }
715
-
716
- interface TeamServices {
717
- roleRegistry: DefaultRoleRegistry;
718
- messageRouter: MessageRouter;
719
- taskBackend: TaskBackend;
720
- eventStore: EventStore;
721
- agentManager: AgentManager;
722
- }
723
- ```
724
-
725
- ### 1.4 SpawnInterceptor in AgentManager
726
-
727
- Changes to `src/agent/agent-manager.ts`:
728
-
729
- 1. Add `spawnInterceptor?: SpawnInterceptor` to `AgentManagerConfig`
730
- 2. Add `setSpawnInterceptor(fn)` method to AgentManager
731
- 3. In `spawn()`, call interceptor before proceeding (see A2 above)
732
- 4. Add `customPrompt?: string` to `SpawnAgentOptions` for team prompt injection
733
- 5. Expose `getRoleRegistry()` getter for TeamRuntime access
734
-
735
- ### 1.5 CLI Integration
736
-
737
- Changes to `src/cli/index.ts`:
738
-
739
- ```typescript
740
- program
741
- .command("start")
742
- .option("--team <name>", "Load team template")
743
- .action(async (options) => {
744
- const eventStore = await createEventStore({ inMemory: false });
745
- const messageRouter = createMessageRouter(eventStore);
746
- const agentManager = createAgentManager(eventStore, messageRouter);
747
-
748
- // Load team if specified
749
- let teamRuntime: TeamRuntime | null = null;
750
- if (options.team) {
751
- const manifest = await TeamLoader.load(options.team);
752
- teamRuntime = new TeamRuntime(manifest, {
753
- roleRegistry: agentManager.getRoleRegistry(),
754
- messageRouter,
755
- taskBackend: createInMemoryTaskBackend(eventStore),
756
- eventStore,
757
- agentManager,
758
- });
759
- await teamRuntime.initialize();
760
- }
761
-
762
- // Create API server (pass teamRuntime for API endpoints)
763
- const server = createAPIServer(
764
- { eventStore, agentManager, taskManager, messageRouter, teamRuntime },
765
- { port: parseInt(options.port), host: options.host }
766
- );
767
-
768
- await server.start();
769
-
770
- // Bootstrap team agents if team loaded
771
- if (teamRuntime) {
772
- const { rootId, companionIds } = await teamRuntime.bootstrap();
773
- console.log(`Team '${options.team}' started: root=${rootId}, companions=${companionIds.join(', ')}`);
774
- }
775
- });
776
- ```
777
-
778
- ### 1.6 Testing Strategy
779
-
780
- **Unit tests** (`src/teams/__tests__/`):
781
- - `team-loader.test.ts`: Parse valid manifest, handle missing files, validate schema, resolve role inheritance, compute capabilities
782
- - `team-runtime.test.ts`: Role registration, spawn interceptor behavior, topic computation, prompt resolution, integration strategy selection
783
-
784
- **Integration test** (`src/teams/__tests__/team-integration.test.ts`):
785
- - Load a fixture team template from `src/teams/__tests__/fixtures/test-team/`
786
- - Initialize TeamRuntime with real services
787
- - Spawn an agent and verify: correct topics subscribed, correct MCP servers, correct prompt, correct env vars
788
-
789
- ---
790
-
791
- ## Phase 2: Pluggable Integration Strategies — Implementation Details
792
-
793
- ### New Module: `src/workspace/strategies/`
794
-
795
- ```
796
- src/workspace/strategies/
797
- ├── types.ts # IntegrationStrategy, LandRequest, LandResult
798
- ├── registry.ts # IntegrationStrategyRegistry
799
- ├── queue.ts # QueueIntegrationStrategy (wraps merge queue)
800
- ├── trunk.ts # TrunkIntegrationStrategy (push + rebase)
801
- ├── optimistic.ts # OptimisticIntegrationStrategy (push + async validate)
802
- └── index.ts # Re-exports
803
- ```
804
-
805
- ### IntegrationStrategy interface (`types.ts`)
806
-
807
- As defined in plan-self-driving-support.md. No changes needed.
808
-
809
- ### QueueIntegrationStrategy (`queue.ts`)
810
-
811
- This wraps the existing merge queue behavior from `handleWorkerDone` Step 4 (worker.ts lines ~229-387). It extracts that logic into the strategy:
812
-
813
- ```typescript
814
- export class QueueIntegrationStrategy implements IntegrationStrategy {
815
- readonly name = 'queue';
816
- private mergeQueue?: MergeQueueInterface;
817
-
818
- async initialize(streamId: string, config: Record<string, unknown>): Promise<void> {
819
- // mergeQueue is injected via constructor or config
820
- }
821
-
822
- async land(request: LandRequest): Promise<LandResult> {
823
- if (!this.mergeQueue) {
824
- return { status: 'failed', error: 'No merge queue configured' };
825
- }
826
- // Extract logic from current worker.ts:
827
- // 1. Detect source/target branch from workspace
828
- // 2. Submit merge request to queue
829
- // 3. Return result
830
- const entry = await this.mergeQueue.submit({
831
- streamId: request.streamId,
832
- sourceBranch: request.workerBranch,
833
- targetBranch: request.integrationBranch,
834
- agentId: request.workerAgentId,
835
- taskId: request.taskId,
836
- });
837
- return { status: 'landed', mergeCommit: entry.id };
838
- }
839
- }
840
- ```
841
-
842
- ### TrunkIntegrationStrategy (`trunk.ts`)
843
-
844
- ```typescript
845
- export class TrunkIntegrationStrategy implements IntegrationStrategy {
846
- readonly name = 'trunk';
847
-
848
- async land(request: LandRequest): Promise<LandResult> {
849
- const { maxRetries = 3, conflictAction = 'abandon' } = request.options ?? {};
850
-
851
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
852
- try {
853
- // 1. Fetch latest integration branch
854
- await git.fetch(request.workspacePath, 'origin', request.integrationBranch);
855
-
856
- // 2. Rebase worker branch onto integration branch
857
- await git.rebase(request.workspacePath, `origin/${request.integrationBranch}`);
858
-
859
- // 3. Push to integration branch
860
- await git.push(request.workspacePath, 'origin', request.integrationBranch);
861
-
862
- // 4. Get merge commit SHA
863
- const sha = await git.getHead(request.workspacePath);
864
- return { status: 'landed', mergeCommit: sha };
865
- } catch (error) {
866
- if (isConflictError(error)) {
867
- await git.rebaseAbort(request.workspacePath);
868
- if (attempt === maxRetries) {
869
- const conflictFiles = await git.getConflictFiles(request.workspacePath);
870
- return {
871
- status: 'conflict',
872
- conflictFiles,
873
- action: conflictAction === 'abandon' ? 'abandoned' : 'queued_for_resolution',
874
- };
875
- }
876
- // Retry with fresh state
877
- continue;
878
- }
879
- return { status: 'failed', error: String(error) };
880
- }
881
- }
882
- return { status: 'retry_exhausted', attempts: maxRetries };
883
- }
884
- }
885
- ```
886
-
887
- **Git operations**: These will use the same git helpers used elsewhere in the codebase (check if `src/workspace/` has git utility functions, otherwise add a thin wrapper around child_process exec of git commands).
888
-
889
- ### IntegrationStrategyRegistry (`registry.ts`)
890
-
891
- ```typescript
892
- type StrategyFactory = (config: Record<string, unknown>) => IntegrationStrategy;
893
-
894
- export class IntegrationStrategyRegistry {
895
- private factories = new Map<string, StrategyFactory>();
896
-
897
- register(name: string, factory: StrategyFactory): void;
898
- get(name: string, config?: Record<string, unknown>): IntegrationStrategy;
899
- has(name: string): boolean;
900
- list(): string[];
901
- }
902
-
903
- // Register built-ins at module load
904
- export const defaultRegistry = new IntegrationStrategyRegistry();
905
- defaultRegistry.register('queue', (config) => new QueueIntegrationStrategy(config));
906
- defaultRegistry.register('trunk', (config) => new TrunkIntegrationStrategy(config));
907
- defaultRegistry.register('optimistic', (config) => new OptimisticIntegrationStrategy(config));
908
- ```
909
-
910
- ### Worker handler refactor
911
-
912
- The key change in `src/lifecycle/handlers/worker.ts` is replacing the direct merge queue calls in Step 4 with a strategy dispatch. The existing merge queue logic moves into `QueueIntegrationStrategy`. The handler becomes:
913
-
914
- ```
915
- Step 1: Commit uncommitted changes (unchanged)
916
- Step 2: Create checkpoints (unchanged)
917
- Step 3: Handle blocked/deferred (unchanged)
918
- Step 4: Emit WORKER_DONE signal (unchanged)
919
- Step 5: Land changes via strategy (NEW)
920
- - if integrationStrategy: call strategy.land()
921
- - else if mergeQueue: existing merge queue logic (backward compat)
922
- - else: skip integration
923
- Step 6: Signal descendants (unchanged)
924
- Step 7: Return shouldTerminate based on taskMode (MODIFIED for pull mode)
925
- ```
926
-
927
- **Backward compatibility**: When no team is loaded and no integrationStrategy is set, the handler falls back to the existing mergeQueue path. Zero behavior change for existing users.
928
-
929
- ---
930
-
931
- ## Phase 3: Task Pull Model — Implementation Details
932
-
933
- ### TaskBackend interface additions (`src/task/backend/types.ts`)
934
-
935
- ```typescript
936
- export interface TaskBackend {
937
- // ... existing methods
938
-
939
- // NEW: Pull model
940
- claim(agentId: string, filters?: ClaimFilters): Promise<ExtendedTask | null>;
941
- unclaim(taskId: TaskId, reason?: string): Promise<void>;
942
- listClaimable(filters?: ClaimFilters): Promise<ExtendedTask[]>;
943
- }
944
-
945
- export interface ClaimFilters {
946
- /** Only tasks with these tags */
947
- tags?: string[];
948
- /** Only tasks with these statuses (default: ['pending']) */
949
- status?: string[];
950
- /** Exclude tasks that were previously claimed by this agent and failed */
951
- excludePreviousFails?: boolean;
952
- }
953
- ```
954
-
955
- ### Tags on tasks (`src/store/types/tasks.ts`)
956
-
957
- Add `tags?: string[]` to the task type. Tags are set at creation time and used for filtered claiming.
958
-
959
- ### New MCP tools
960
-
961
- **`src/mcp/tools/claim_task.ts`**:
962
- ```
963
- claim_task(filters?: { tags?: string[], status?: string[] })
964
- → { task: ExtendedTask } | { empty: true, message: "No claimable tasks" }
965
- ```
966
-
967
- **`src/mcp/tools/unclaim_task.ts`**:
968
- ```
969
- unclaim_task(task_id: string, reason?: string)
970
- → { success: true }
971
- ```
972
-
973
- **`src/mcp/tools/list_claimable_tasks.ts`**:
974
- ```
975
- list_claimable_tasks(filters?: { tags?: string[] }, limit?: number)
976
- → { tasks: ExtendedTask[] }
977
- ```
978
-
979
- ### Capability gating
980
-
981
- Add `task.claim` to `CAPABILITY_TOOL_MAP` in `src/roles/capabilities.ts`:
982
-
983
- ```typescript
984
- 'task.claim': ['claim_task', 'unclaim_task', 'list_claimable_tasks'],
985
- ```
986
-
987
- ### MCP registration
988
-
989
- In `src/mcp/mcp-server.ts`, register the three new tools alongside existing task tools. They follow the same pattern as `create_task` — gated by capability, receive `taskBackend` from MCPServices.
990
-
991
- ---
992
-
993
- ## Phase 4: Session Continuations — Implementation Details
994
-
995
- ### Session history storage
996
-
997
- Add a new event type: `conversation` events already exist in the EventStore. Session continuations build on the existing conversation/turn infrastructure:
998
-
999
- - When an agent's `done()` is called with continuation enabled, the agent's conversation transcript is already stored as turns in the EventStore's conversation view.
1000
- - `AgentManager.resume(agentId)` loads the conversation turns, formats them as a resume context, and spawns a new agent with that context prepended.
1001
-
1002
- ```typescript
1003
- // In agent-manager.ts
1004
- async function resume(agentId: string, options?: ResumeOptions): Promise<SpawnedAgent> {
1005
- const agent = eventStore.getAgent(agentId);
1006
- if (!agent) throw new Error(`Agent not found: ${agentId}`);
1007
-
1008
- // Load conversation history
1009
- const turns = eventStore.listTurns({ agent_id: agentId });
1010
- const maxMessages = options?.maxMessages ?? 50;
1011
- const recentTurns = turns.slice(-maxMessages);
1012
-
1013
- // Build resume context
1014
- const resumeContext = formatResumeContext(recentTurns, agent);
1015
-
1016
- // Spawn new agent with same role, task, and resume context
1017
- return spawn({
1018
- task: agent.task,
1019
- task_id: agent.task_id,
1020
- parent: agent.parent,
1021
- role: agent.role,
1022
- customPrompt: resumeContext, // Prepended to system prompt
1023
- });
1024
- }
1025
- ```
1026
-
1027
- This is the simplest approach — no new event types, no new storage. We build on the existing conversation tracking. The main implementation work is:
1028
- 1. Ensuring conversation turns are captured during agent operation (already happening via MailService)
1029
- 2. Building `formatResumeContext()` to create a useful summary
1030
- 3. Adding `resume()` to AgentManager
1031
- 4. Adding periodic checkpointing if turns aren't already captured at each round-trip
1032
-
1033
- ---
1034
-
1035
- ## File Change Summary
1036
-
1037
- ### New files
1038
- | File | Description |
1039
- |------|-------------|
1040
- | `src/teams/types.ts` | TeamManifest, TeamTopology, TeamCommunication, MacroAgentExtensions types |
1041
- | `src/teams/team-loader.ts` | TeamLoader — reads and validates team template directories |
1042
- | `src/teams/team-runtime.ts` | TeamRuntime — wires team config into running services |
1043
- | `src/teams/index.ts` | Re-exports |
1044
- | `src/workspace/strategies/types.ts` | IntegrationStrategy, LandRequest, LandResult |
1045
- | `src/workspace/strategies/registry.ts` | IntegrationStrategyRegistry |
1046
- | `src/workspace/strategies/queue.ts` | QueueIntegrationStrategy |
1047
- | `src/workspace/strategies/trunk.ts` | TrunkIntegrationStrategy |
1048
- | `src/workspace/strategies/optimistic.ts` | OptimisticIntegrationStrategy |
1049
- | `src/workspace/strategies/index.ts` | Re-exports |
1050
- | `src/mcp/tools/claim_task.ts` | claim_task MCP tool |
1051
- | `src/mcp/tools/unclaim_task.ts` | unclaim_task MCP tool |
1052
- | `src/mcp/tools/list_claimable_tasks.ts` | list_claimable_tasks MCP tool |
1053
- | `.multiagent/teams/self-driving/` | Reference team template (team.yaml, roles/, prompts/) |
1054
- | `.multiagent/teams/structured/` | Backward-compat structured team template |
1055
-
1056
- ### Modified files
1057
- | File | Change |
1058
- |------|--------|
1059
- | `src/agent/agent-manager.ts` | Add spawnInterceptor hook, customPrompt support, getRoleRegistry(), resume() |
1060
- | `src/agent/system-prompt.ts` | Add teamPrompt and interactionPatterns to SystemPromptContext |
1061
- | `src/lifecycle/handlers/index.ts` | Add integrationStrategy and taskMode to AllHandlerDeps |
1062
- | `src/lifecycle/handlers/worker.ts` | Add strategy dispatch (A4), pull mode shouldTerminate (A5) |
1063
- | `src/mcp/tools/done.ts` | Pass integrationStrategy/taskMode through DoneToolDeps |
1064
- | `src/mcp/mcp-server.ts` | Register claim_task/unclaim_task/list_claimable_tasks, add MCPServices fields |
1065
- | `src/task/backend/types.ts` | Add claim(), unclaim(), listClaimable(), ClaimFilters, tags |
1066
- | `src/task/backend/memory.ts` | Implement claim/unclaim/listClaimable |
1067
- | `src/store/types/tasks.ts` | Add tags field to task type |
1068
- | `src/roles/capabilities.ts` | Add task.claim capability mapping |
1069
- | `src/cli/index.ts` | Add --team flag, TeamLoader/TeamRuntime initialization, bootstrap |
1070
- | `src/api/server.ts` | Add GET /api/team endpoint |
1071
-
1072
- ---
1073
-
1074
- ## Implementation Order and Dependencies
1075
-
1076
- ```
1077
- Phase 1 (Foundation)
1078
- 1.1 Types → 1.2 Loader → 1.3 Runtime → 1.4 Spawn interceptor
1079
- 1.5 CLI integration → 1.6 Bootstrap → 1.7 API → 1.8-1.9 Tests → 1.10 Reference template
1080
-
1081
- Phase 2 (Integration Strategies) ── can start after 1.3
1082
- 2.1 Types → 2.2 Registry → 2.3 Queue → 2.4 Trunk → 2.5 Optimistic
1083
- 2.6 Worker handler refactor → 2.7 Wire into TeamRuntime → 2.8-2.11 Tests
1084
-
1085
- Phase 3 (Task Pull) ── can start after 1.3
1086
- 3.1 Tags → 3.2-3.4 Backend methods → 3.5 Capabilities → 3.6-3.8 MCP tools
1087
- 3.9 Registration → 3.10 Pull mode done → 3.11 Idle timeout → 3.12-3.13 Tests
1088
-
1089
- Phase 4 (Session Continuations) ── can start after 1.3
1090
- 4.1-4.2 Storage → 4.3-4.4 Persistence hooks → 4.5 Resume
1091
- 4.6-4.7 Config → 4.8-4.9 Tests
1092
-
1093
- Phase 5 (Observability) ── depends on 2 + 3
1094
- 5.1-5.2 Metric events → 5.3-5.5 Views → 5.6 API → 5.7-5.8 Tests
1095
-
1096
- Phase 6 (Templates + Docs) ── depends on all
1097
- 6.1-6.4 Reference templates, docs, E2E test
1098
- ```
1099
-
1100
- Phases 2, 3, and 4 can be developed in parallel once Phase 1.3 (TeamRuntime) is done, since they each hook into different parts of the system. Phase 5 requires 2 and 3 for the metric events to be meaningful.
1101
-
1102
- ---
1103
-
1104
- ## Resolved Open Questions
1105
-
1106
- These questions were resolved during spec review. See `docs/spec-self-driving-support.md` for the binding decisions (RD1-RD7).
1107
-
1108
- 1. **YAML library**: `js-yaml` (RD7).
1109
-
1110
- 2. **Git operations for trunk strategy**: Need a thin wrapper around child_process git commands. Check if `src/workspace/` has existing helpers to reuse.
1111
-
1112
- 3. **Optimistic strategy validation**: The strategy is thin — push + emit event. Validation is the judge agent's responsibility via its role prompt (RD5).
1113
-
1114
- 4. **MCP subprocess team context**: Store `team_config` event in EventStore. MCP subprocess reads it to reconstruct strategy and taskMode (RD2). No HTTP API between processes.
1115
-
1116
- 5. **Team selection**: Via `.multiagent/config.json` (new file), CLI `--team` overrides (RD6).
1117
-
1118
- 6. **spawn_rules vs capabilities**: spawn_rules are syntactic sugar — TeamLoader translates them into capability additions (RD3).
1119
-
1120
- 7. **Team prompt vs base role prompt**: Team prompt replaces base systemPrompt entirely (RD4).
1121
-
1122
- 8. **done() hardcoded roles**: Must be fixed as prerequisite (RD1). Replace with RoleRegistry lookup.
1123
-
1124
- ### Deferred
1125
-
1126
- - **Team template hot-reloading**: Not needed for Phase 1. The `RoleRegistry` already supports file watching, so this could be added later.
1127
- - **Multiple simultaneous teams**: Single team focus for now. Architecture supports it but CLI only accepts one `--team` flag.