macro-agent 0.1.1 → 0.1.3

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 (1339) hide show
  1. package/.gitattributes +3 -0
  2. package/.opentasks/config.json +9 -0
  3. package/.sudocode/issues.jsonl +28 -0
  4. package/.sudocode/specs.jsonl +4 -0
  5. package/CLAUDE.md +433 -201
  6. package/README.md +129 -371
  7. package/dist/acp/index.d.ts +9 -51
  8. package/dist/acp/index.d.ts.map +1 -1
  9. package/dist/acp/index.js +5 -46
  10. package/dist/acp/index.js.map +1 -1
  11. package/dist/acp/macro-agent.d.ts +28 -255
  12. package/dist/acp/macro-agent.d.ts.map +1 -1
  13. package/dist/acp/macro-agent.js +593 -1231
  14. package/dist/acp/macro-agent.js.map +1 -1
  15. package/dist/acp/map-bridge.d.ts +62 -0
  16. package/dist/acp/map-bridge.d.ts.map +1 -0
  17. package/dist/acp/map-bridge.js +123 -0
  18. package/dist/acp/map-bridge.js.map +1 -0
  19. package/dist/acp/session-mapper.d.ts +29 -126
  20. package/dist/acp/session-mapper.d.ts.map +1 -1
  21. package/dist/acp/session-mapper.js +36 -234
  22. package/dist/acp/session-mapper.js.map +1 -1
  23. package/dist/acp/types.d.ts +24 -535
  24. package/dist/acp/types.d.ts.map +1 -1
  25. package/dist/acp/types.js +7 -7
  26. package/dist/acp/types.js.map +1 -1
  27. package/dist/acp/websocket-server.d.ts +16 -136
  28. package/dist/acp/websocket-server.d.ts.map +1 -1
  29. package/dist/acp/websocket-server.js +131 -371
  30. package/dist/acp/websocket-server.js.map +1 -1
  31. package/dist/adapters/federation.d.ts +76 -0
  32. package/dist/adapters/federation.d.ts.map +1 -0
  33. package/dist/adapters/federation.js +120 -0
  34. package/dist/adapters/federation.js.map +1 -0
  35. package/dist/adapters/inbox-adapter.d.ts +72 -0
  36. package/dist/adapters/inbox-adapter.d.ts.map +1 -0
  37. package/dist/adapters/inbox-adapter.js +196 -0
  38. package/dist/adapters/inbox-adapter.js.map +1 -0
  39. package/dist/adapters/inbox-client-adapter.d.ts +40 -0
  40. package/dist/adapters/inbox-client-adapter.d.ts.map +1 -0
  41. package/dist/adapters/inbox-client-adapter.js +135 -0
  42. package/dist/adapters/inbox-client-adapter.js.map +1 -0
  43. package/dist/adapters/index.d.ts +11 -0
  44. package/dist/adapters/index.d.ts.map +1 -0
  45. package/dist/adapters/index.js +10 -0
  46. package/dist/adapters/index.js.map +1 -0
  47. package/dist/adapters/opentasks-daemon.d.ts +32 -0
  48. package/dist/adapters/opentasks-daemon.d.ts.map +1 -0
  49. package/dist/adapters/opentasks-daemon.js +190 -0
  50. package/dist/adapters/opentasks-daemon.js.map +1 -0
  51. package/dist/adapters/tasks-adapter.d.ts +49 -0
  52. package/dist/adapters/tasks-adapter.d.ts.map +1 -0
  53. package/dist/adapters/tasks-adapter.js +209 -0
  54. package/dist/adapters/tasks-adapter.js.map +1 -0
  55. package/dist/adapters/types.d.ts +198 -0
  56. package/dist/adapters/types.d.ts.map +1 -0
  57. package/dist/adapters/types.js +13 -0
  58. package/dist/adapters/types.js.map +1 -0
  59. package/dist/agent/agent-manager-v2.d.ts +38 -0
  60. package/dist/agent/agent-manager-v2.d.ts.map +1 -0
  61. package/dist/agent/agent-manager-v2.js +1097 -0
  62. package/dist/agent/agent-manager-v2.js.map +1 -0
  63. package/dist/agent/agent-manager.d.ts +52 -42
  64. package/dist/agent/agent-manager.d.ts.map +1 -1
  65. package/dist/agent/agent-manager.js +11 -1255
  66. package/dist/agent/agent-manager.js.map +1 -1
  67. package/dist/agent/agent-store.d.ts +89 -0
  68. package/dist/agent/agent-store.d.ts.map +1 -0
  69. package/dist/agent/agent-store.js +279 -0
  70. package/dist/agent/agent-store.js.map +1 -0
  71. package/dist/agent/types.d.ts +7 -0
  72. package/dist/agent/types.d.ts.map +1 -1
  73. package/dist/agent/types.js.map +1 -1
  74. package/dist/api/index.d.ts +5 -3
  75. package/dist/api/index.d.ts.map +1 -1
  76. package/dist/api/index.js +4 -3
  77. package/dist/api/index.js.map +1 -1
  78. package/dist/api/server.d.ts +6 -123
  79. package/dist/api/server.d.ts.map +1 -1
  80. package/dist/api/server.js +247 -1489
  81. package/dist/api/server.js.map +1 -1
  82. package/dist/api/types.d.ts +20 -248
  83. package/dist/api/types.d.ts.map +1 -1
  84. package/dist/api/types.js +3 -1
  85. package/dist/api/types.js.map +1 -1
  86. package/dist/boot-v2.d.ts +165 -0
  87. package/dist/boot-v2.d.ts.map +1 -0
  88. package/dist/boot-v2.js +315 -0
  89. package/dist/boot-v2.js.map +1 -0
  90. package/dist/cli/acp.d.ts +6 -28
  91. package/dist/cli/acp.d.ts.map +1 -1
  92. package/dist/cli/acp.js +39 -373
  93. package/dist/cli/acp.js.map +1 -1
  94. package/dist/cli/index.d.ts +1 -2
  95. package/dist/cli/index.d.ts.map +1 -1
  96. package/dist/cli/index.js +65 -449
  97. package/dist/cli/index.js.map +1 -1
  98. package/dist/cli/mcp.d.ts +18 -8
  99. package/dist/cli/mcp.d.ts.map +1 -1
  100. package/dist/cli/mcp.js +231 -282
  101. package/dist/cli/mcp.js.map +1 -1
  102. package/dist/cognitive/analyst-role.d.ts +13 -0
  103. package/dist/cognitive/analyst-role.d.ts.map +1 -0
  104. package/dist/cognitive/analyst-role.js +48 -0
  105. package/dist/cognitive/analyst-role.js.map +1 -0
  106. package/dist/cognitive/index.d.ts +18 -0
  107. package/dist/cognitive/index.d.ts.map +1 -0
  108. package/dist/cognitive/index.js +21 -0
  109. package/dist/cognitive/index.js.map +1 -0
  110. package/dist/cognitive/macro-agent-backend.d.ts +40 -0
  111. package/dist/cognitive/macro-agent-backend.d.ts.map +1 -0
  112. package/dist/cognitive/macro-agent-backend.js +290 -0
  113. package/dist/cognitive/macro-agent-backend.js.map +1 -0
  114. package/dist/cognitive/session-converter.d.ts +30 -0
  115. package/dist/cognitive/session-converter.d.ts.map +1 -0
  116. package/dist/cognitive/session-converter.js +119 -0
  117. package/dist/cognitive/session-converter.js.map +1 -0
  118. package/dist/cognitive/types.d.ts +129 -0
  119. package/dist/cognitive/types.d.ts.map +1 -0
  120. package/dist/cognitive/types.js +12 -0
  121. package/dist/cognitive/types.js.map +1 -0
  122. package/dist/cognitive/workspace-handler.d.ts +46 -0
  123. package/dist/cognitive/workspace-handler.d.ts.map +1 -0
  124. package/dist/cognitive/workspace-handler.js +135 -0
  125. package/dist/cognitive/workspace-handler.js.map +1 -0
  126. package/dist/config/project-config.d.ts +13 -2
  127. package/dist/config/project-config.d.ts.map +1 -1
  128. package/dist/config/project-config.js +12 -2
  129. package/dist/config/project-config.js.map +1 -1
  130. package/dist/control/control-client.d.ts +63 -0
  131. package/dist/control/control-client.d.ts.map +1 -0
  132. package/dist/control/control-client.js +276 -0
  133. package/dist/control/control-client.js.map +1 -0
  134. package/dist/control/control-server.d.ts +46 -0
  135. package/dist/control/control-server.d.ts.map +1 -0
  136. package/dist/control/control-server.js +237 -0
  137. package/dist/control/control-server.js.map +1 -0
  138. package/dist/control/index.d.ts +9 -0
  139. package/dist/control/index.d.ts.map +1 -0
  140. package/dist/control/index.js +8 -0
  141. package/dist/control/index.js.map +1 -0
  142. package/dist/control/types.d.ts +64 -0
  143. package/dist/control/types.d.ts.map +1 -0
  144. package/dist/control/types.js +10 -0
  145. package/dist/control/types.js.map +1 -0
  146. package/dist/index.d.ts +15 -16
  147. package/dist/index.d.ts.map +1 -1
  148. package/dist/index.js +17 -34
  149. package/dist/index.js.map +1 -1
  150. package/dist/integrations/context-builder.d.ts +49 -0
  151. package/dist/integrations/context-builder.d.ts.map +1 -0
  152. package/dist/integrations/context-builder.js +160 -0
  153. package/dist/integrations/context-builder.js.map +1 -0
  154. package/dist/integrations/sessionlog.d.ts +58 -0
  155. package/dist/integrations/sessionlog.d.ts.map +1 -0
  156. package/dist/integrations/sessionlog.js +152 -0
  157. package/dist/integrations/sessionlog.js.map +1 -0
  158. package/dist/integrations/skilltree.d.ts +53 -0
  159. package/dist/integrations/skilltree.d.ts.map +1 -0
  160. package/dist/integrations/skilltree.js +140 -0
  161. package/dist/integrations/skilltree.js.map +1 -0
  162. package/dist/lifecycle/cleanup.d.ts +5 -14
  163. package/dist/lifecycle/cleanup.d.ts.map +1 -1
  164. package/dist/lifecycle/cleanup.js +4 -34
  165. package/dist/lifecycle/cleanup.js.map +1 -1
  166. package/dist/lifecycle/handlers-v2.d.ts +33 -0
  167. package/dist/lifecycle/handlers-v2.d.ts.map +1 -0
  168. package/dist/lifecycle/handlers-v2.js +319 -0
  169. package/dist/lifecycle/handlers-v2.js.map +1 -0
  170. package/dist/lifecycle/index.d.ts +3 -5
  171. package/dist/lifecycle/index.d.ts.map +1 -1
  172. package/dist/lifecycle/index.js +3 -12
  173. package/dist/lifecycle/index.js.map +1 -1
  174. package/dist/lifecycle/types.d.ts +2 -0
  175. package/dist/lifecycle/types.d.ts.map +1 -1
  176. package/dist/lifecycle/types.js.map +1 -1
  177. package/dist/map/acp-bridge.d.ts +39 -0
  178. package/dist/map/acp-bridge.d.ts.map +1 -0
  179. package/dist/map/acp-bridge.js +180 -0
  180. package/dist/map/acp-bridge.js.map +1 -0
  181. package/dist/map/cc-swarm-hooks.d.ts +36 -0
  182. package/dist/map/cc-swarm-hooks.d.ts.map +1 -0
  183. package/dist/map/cc-swarm-hooks.js +218 -0
  184. package/dist/map/cc-swarm-hooks.js.map +1 -0
  185. package/dist/map/coordination-handler.d.ts +36 -0
  186. package/dist/map/coordination-handler.d.ts.map +1 -0
  187. package/dist/map/coordination-handler.js +166 -0
  188. package/dist/map/coordination-handler.js.map +1 -0
  189. package/dist/map/index.d.ts +5 -10
  190. package/dist/map/index.d.ts.map +1 -1
  191. package/dist/map/index.js +4 -13
  192. package/dist/map/index.js.map +1 -1
  193. package/dist/map/lifecycle-bridge.d.ts +34 -0
  194. package/dist/map/lifecycle-bridge.d.ts.map +1 -0
  195. package/dist/map/lifecycle-bridge.js +96 -0
  196. package/dist/map/lifecycle-bridge.js.map +1 -0
  197. package/dist/map/server.d.ts +38 -0
  198. package/dist/map/server.d.ts.map +1 -0
  199. package/dist/map/server.js +461 -0
  200. package/dist/map/server.js.map +1 -0
  201. package/dist/map/sidecar.d.ts +24 -0
  202. package/dist/map/sidecar.d.ts.map +1 -0
  203. package/dist/map/sidecar.js +263 -0
  204. package/dist/map/sidecar.js.map +1 -0
  205. package/dist/map/task-bridge.d.ts +22 -0
  206. package/dist/map/task-bridge.d.ts.map +1 -0
  207. package/dist/map/task-bridge.js +67 -0
  208. package/dist/map/task-bridge.js.map +1 -0
  209. package/dist/map/trajectory-reporter.d.ts +24 -0
  210. package/dist/map/trajectory-reporter.d.ts.map +1 -0
  211. package/dist/map/trajectory-reporter.js +86 -0
  212. package/dist/map/trajectory-reporter.js.map +1 -0
  213. package/dist/map/types.d.ts +162 -226
  214. package/dist/map/types.d.ts.map +1 -1
  215. package/dist/map/types.js +6 -165
  216. package/dist/map/types.js.map +1 -1
  217. package/dist/mcp/index.d.ts +2 -2
  218. package/dist/mcp/index.d.ts.map +1 -1
  219. package/dist/mcp/index.js +2 -2
  220. package/dist/mcp/index.js.map +1 -1
  221. package/dist/mcp/mcp-server-v2.d.ts +44 -0
  222. package/dist/mcp/mcp-server-v2.d.ts.map +1 -0
  223. package/dist/mcp/mcp-server-v2.js +376 -0
  224. package/dist/mcp/mcp-server-v2.js.map +1 -0
  225. package/dist/mcp/tools/done-v2.d.ts +57 -0
  226. package/dist/mcp/tools/done-v2.d.ts.map +1 -0
  227. package/dist/mcp/tools/done-v2.js +129 -0
  228. package/dist/mcp/tools/done-v2.js.map +1 -0
  229. package/dist/metrics/index.d.ts +7 -1
  230. package/dist/metrics/index.d.ts.map +1 -1
  231. package/dist/metrics/index.js +6 -1
  232. package/dist/metrics/index.js.map +1 -1
  233. package/dist/metrics/metrics.d.ts +9 -70
  234. package/dist/metrics/metrics.d.ts.map +1 -1
  235. package/dist/metrics/metrics.js +89 -145
  236. package/dist/metrics/metrics.js.map +1 -1
  237. package/dist/metrics/types.d.ts +44 -0
  238. package/dist/metrics/types.d.ts.map +1 -0
  239. package/dist/metrics/types.js +7 -0
  240. package/dist/metrics/types.js.map +1 -0
  241. package/dist/roles/builtin/coordinator.d.ts.map +1 -1
  242. package/dist/roles/builtin/coordinator.js +2 -1
  243. package/dist/roles/builtin/coordinator.js.map +1 -1
  244. package/dist/roles/builtin/integrator.d.ts.map +1 -1
  245. package/dist/roles/builtin/integrator.js +2 -1
  246. package/dist/roles/builtin/integrator.js.map +1 -1
  247. package/dist/roles/builtin/worker.d.ts.map +1 -1
  248. package/dist/roles/builtin/worker.js +3 -1
  249. package/dist/roles/builtin/worker.js.map +1 -1
  250. package/dist/roles/capabilities.d.ts +6 -0
  251. package/dist/roles/capabilities.d.ts.map +1 -1
  252. package/dist/roles/capabilities.js +10 -0
  253. package/dist/roles/capabilities.js.map +1 -1
  254. package/dist/roles/config-loader.d.ts +1 -1
  255. package/dist/roles/config-loader.d.ts.map +1 -1
  256. package/dist/roles/config-loader.js +3 -2
  257. package/dist/roles/config-loader.js.map +1 -1
  258. package/dist/roles/types.d.ts +3 -1
  259. package/dist/roles/types.d.ts.map +1 -1
  260. package/dist/store/index.d.ts +3 -6
  261. package/dist/store/index.d.ts.map +1 -1
  262. package/dist/store/index.js +3 -21
  263. package/dist/store/index.js.map +1 -1
  264. package/dist/store/types/agents.d.ts +5 -0
  265. package/dist/store/types/agents.d.ts.map +1 -1
  266. package/dist/store/types/events.d.ts +3 -60
  267. package/dist/store/types/events.d.ts.map +1 -1
  268. package/dist/store/types/events.js +3 -46
  269. package/dist/store/types/events.js.map +1 -1
  270. package/dist/store/types/index.d.ts +0 -3
  271. package/dist/store/types/index.d.ts.map +1 -1
  272. package/dist/store/types/index.js +0 -3
  273. package/dist/store/types/index.js.map +1 -1
  274. package/dist/teams/index.d.ts +2 -2
  275. package/dist/teams/index.d.ts.map +1 -1
  276. package/dist/teams/index.js +1 -1
  277. package/dist/teams/index.js.map +1 -1
  278. package/dist/teams/seed-defaults.d.ts +20 -0
  279. package/dist/teams/seed-defaults.d.ts.map +1 -0
  280. package/dist/teams/seed-defaults.js +71 -0
  281. package/dist/teams/seed-defaults.js.map +1 -0
  282. package/dist/teams/team-loader.d.ts +6 -2
  283. package/dist/teams/team-loader.d.ts.map +1 -1
  284. package/dist/teams/team-loader.js +154 -162
  285. package/dist/teams/team-loader.js.map +1 -1
  286. package/dist/teams/team-manager-v2.d.ts +87 -0
  287. package/dist/teams/team-manager-v2.d.ts.map +1 -0
  288. package/dist/teams/team-manager-v2.js +203 -0
  289. package/dist/teams/team-manager-v2.js.map +1 -0
  290. package/dist/teams/team-runtime-v2.d.ts +149 -0
  291. package/dist/teams/team-runtime-v2.d.ts.map +1 -0
  292. package/dist/teams/team-runtime-v2.js +741 -0
  293. package/dist/teams/team-runtime-v2.js.map +1 -0
  294. package/dist/teams/types.d.ts +41 -151
  295. package/dist/teams/types.d.ts.map +1 -1
  296. package/dist/teams/types.js +2 -3
  297. package/dist/teams/types.js.map +1 -1
  298. package/dist/trigger/index.d.ts +2 -2
  299. package/dist/trigger/index.d.ts.map +1 -1
  300. package/dist/trigger/index.js +4 -4
  301. package/dist/trigger/index.js.map +1 -1
  302. package/dist/trigger/sources/cron/cron-service.d.ts +1 -1
  303. package/dist/trigger/sources/cron/cron-service.d.ts.map +1 -1
  304. package/dist/trigger/sources/webhook/webhook-handler.d.ts +1 -1
  305. package/dist/trigger/sources/webhook/webhook-handler.d.ts.map +1 -1
  306. package/dist/trigger/strategies/ai-router.d.ts +31 -0
  307. package/dist/trigger/strategies/ai-router.d.ts.map +1 -0
  308. package/dist/trigger/strategies/ai-router.js +132 -0
  309. package/dist/trigger/strategies/ai-router.js.map +1 -0
  310. package/dist/trigger/trigger-system-v2.d.ts +106 -0
  311. package/dist/trigger/trigger-system-v2.d.ts.map +1 -0
  312. package/dist/trigger/trigger-system-v2.js +347 -0
  313. package/dist/trigger/trigger-system-v2.js.map +1 -0
  314. package/dist/trigger/types.d.ts +8 -0
  315. package/dist/trigger/types.d.ts.map +1 -1
  316. package/dist/trigger/types.js.map +1 -1
  317. package/dist/workspace/strategies/optimistic.d.ts +13 -3
  318. package/dist/workspace/strategies/optimistic.d.ts.map +1 -1
  319. package/dist/workspace/strategies/optimistic.js +4 -4
  320. package/dist/workspace/strategies/optimistic.js.map +1 -1
  321. package/docs/design-subsystem-extraction.md +627 -0
  322. package/docs/lifecycle-events-design.md +111 -0
  323. package/docs/openhive-capability-summary.md +415 -0
  324. package/docs/openhive-integration.md +415 -0
  325. package/docs/roadmap-v2-gaps.md +216 -0
  326. package/docs/teams.md +73 -0
  327. package/package.json +26 -6
  328. package/src/__tests__/boot-v2.test.ts +196 -0
  329. package/src/__tests__/e2e/acp-over-map-live.e2e.test.ts +496 -0
  330. package/src/__tests__/e2e/acp-over-map.e2e.test.ts +365 -0
  331. package/src/__tests__/e2e/agent-lifecycle.e2e.test.ts +770 -0
  332. package/src/__tests__/e2e/cc-swarm-bridge.e2e.test.ts +253 -0
  333. package/src/__tests__/e2e/cognitive-workspace.e2e.test.ts +282 -0
  334. package/src/__tests__/e2e/done-scenarios.e2e.test.ts +322 -0
  335. package/src/__tests__/e2e/live-agent.e2e.test.ts +1330 -0
  336. package/src/__tests__/e2e/map-server.e2e.test.ts +128 -0
  337. package/src/__tests__/e2e/map-sidecar.e2e.test.ts +139 -0
  338. package/src/__tests__/e2e/opentasks-integration.e2e.test.ts +280 -0
  339. package/src/__tests__/e2e/pull-mode.e2e.test.ts +632 -0
  340. package/src/__tests__/e2e/resume-continue.e2e.test.ts +312 -0
  341. package/src/__tests__/e2e/swarmkit-integration.e2e.test.ts +562 -0
  342. package/src/__tests__/e2e/swarmkit-live.e2e.test.ts +1049 -0
  343. package/src/__tests__/e2e/trajectory-tracking.e2e.test.ts +258 -0
  344. package/src/__tests__/e2e/trigger-wake.e2e.test.ts +257 -0
  345. package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +375 -0
  346. package/src/acp/__tests__/macro-agent.test.ts +234 -945
  347. package/src/acp/__tests__/session-mapper.test.ts +82 -155
  348. package/src/acp/__tests__/websocket-server.test.ts +121 -270
  349. package/src/acp/index.ts +18 -118
  350. package/src/acp/macro-agent.ts +692 -1752
  351. package/src/acp/map-bridge.ts +193 -0
  352. package/src/acp/session-mapper.ts +43 -276
  353. package/src/acp/types.ts +39 -767
  354. package/src/acp/websocket-server.ts +152 -588
  355. package/src/adapters/__tests__/federation.test.ts +256 -0
  356. package/src/adapters/__tests__/inbox-adapter.test.ts +316 -0
  357. package/src/adapters/__tests__/tasks-adapter.test.ts +269 -0
  358. package/src/adapters/federation.ts +185 -0
  359. package/src/adapters/inbox-adapter.ts +292 -0
  360. package/src/adapters/inbox-client-adapter.ts +173 -0
  361. package/src/adapters/index.ts +44 -0
  362. package/src/adapters/opentasks-daemon.ts +252 -0
  363. package/src/adapters/tasks-adapter.ts +327 -0
  364. package/src/adapters/types.ts +285 -0
  365. package/src/agent/__tests__/agent-manager-v2.test.ts +554 -0
  366. package/src/agent/__tests__/agent-store.test.ts +413 -0
  367. package/src/agent/agent-manager-v2.ts +1476 -0
  368. package/src/agent/agent-manager.ts +41 -1723
  369. package/src/agent/agent-store.ts +385 -0
  370. package/src/agent/types.ts +9 -0
  371. package/src/api/__tests__/server.test.ts +238 -961
  372. package/src/api/index.ts +5 -3
  373. package/src/api/server.ts +276 -1870
  374. package/src/api/types.ts +25 -337
  375. package/src/boot-v2.ts +527 -0
  376. package/src/cli/acp.ts +40 -435
  377. package/src/cli/index.ts +68 -466
  378. package/src/cli/mcp.ts +260 -326
  379. package/src/cognitive/__tests__/macro-agent-backend.test.ts +478 -0
  380. package/src/cognitive/__tests__/session-converter.test.ts +423 -0
  381. package/src/cognitive/__tests__/workspace-handler.test.ts +221 -0
  382. package/src/cognitive/analyst-role.ts +59 -0
  383. package/src/cognitive/index.ts +49 -0
  384. package/src/cognitive/macro-agent-backend.ts +354 -0
  385. package/src/cognitive/session-converter.ts +151 -0
  386. package/src/cognitive/types.ts +163 -0
  387. package/src/cognitive/workspace-handler.ts +163 -0
  388. package/src/config/project-config.ts +27 -3
  389. package/src/control/__tests__/control-resilience.test.ts +251 -0
  390. package/src/control/__tests__/control-socket.test.ts +240 -0
  391. package/src/control/control-client.ts +337 -0
  392. package/src/control/control-server.ts +298 -0
  393. package/src/control/index.ts +17 -0
  394. package/src/control/types.ts +95 -0
  395. package/src/index.ts +43 -222
  396. package/src/integrations/__tests__/context-builder.test.ts +218 -0
  397. package/src/integrations/__tests__/sessionlog.test.ts +498 -0
  398. package/src/integrations/__tests__/skilltree.test.ts +136 -0
  399. package/src/integrations/context-builder.ts +280 -0
  400. package/src/integrations/sessionlog.ts +194 -0
  401. package/src/integrations/skilltree.ts +183 -0
  402. package/src/lifecycle/__tests__/handlers-v2.test.ts +565 -0
  403. package/src/lifecycle/cleanup.ts +6 -46
  404. package/src/lifecycle/handlers-v2.ts +437 -0
  405. package/src/lifecycle/index.ts +2 -28
  406. package/src/lifecycle/types.ts +3 -0
  407. package/src/map/__tests__/lifecycle-bridge.test.ts +223 -0
  408. package/src/map/__tests__/permission-forwarding.test.ts +143 -0
  409. package/src/map/__tests__/sidecar-integration.test.ts +190 -0
  410. package/src/map/__tests__/task-bridge.test.ts +153 -0
  411. package/src/map/__tests__/trajectory-reporter.test.ts +173 -0
  412. package/src/map/acp-bridge.ts +270 -0
  413. package/src/map/cc-swarm-hooks.ts +242 -0
  414. package/src/map/coordination-handler.ts +220 -0
  415. package/src/map/index.ts +13 -14
  416. package/src/map/lifecycle-bridge.ts +140 -0
  417. package/src/map/server.ts +527 -0
  418. package/src/map/sidecar.ts +312 -0
  419. package/src/map/task-bridge.ts +89 -0
  420. package/src/map/trajectory-reporter.ts +124 -0
  421. package/src/map/types.ts +195 -367
  422. package/src/mcp/__tests__/mcp-server-v2.test.ts +236 -0
  423. package/src/mcp/index.ts +2 -2
  424. package/src/mcp/mcp-server-v2.ts +485 -0
  425. package/src/mcp/tools/done-v2.ts +203 -0
  426. package/src/metrics/__tests__/metrics.test.ts +205 -0
  427. package/src/metrics/index.ts +13 -9
  428. package/src/metrics/metrics.ts +110 -239
  429. package/src/metrics/types.ts +63 -0
  430. package/src/roles/builtin/coordinator.ts +2 -0
  431. package/src/roles/builtin/integrator.ts +2 -0
  432. package/src/roles/builtin/worker.ts +3 -0
  433. package/src/roles/capabilities.ts +11 -0
  434. package/src/roles/config-loader.ts +3 -2
  435. package/src/roles/types.ts +7 -0
  436. package/src/store/index.ts +3 -64
  437. package/src/store/types/agents.ts +5 -0
  438. package/src/store/types/events.ts +5 -100
  439. package/src/store/types/index.ts +0 -3
  440. package/src/teams/__tests__/team-manager-v2.test.ts +425 -0
  441. package/src/teams/__tests__/team-runtime-v2.test.ts +402 -0
  442. package/src/teams/index.ts +20 -4
  443. package/src/teams/seed-defaults.ts +79 -0
  444. package/src/teams/team-loader.ts +200 -234
  445. package/src/teams/team-manager-v2.ts +268 -0
  446. package/src/teams/team-runtime-v2.ts +898 -0
  447. package/src/teams/types.ts +99 -200
  448. package/src/trigger/__tests__/trigger-system-v2.test.ts +257 -0
  449. package/src/trigger/index.ts +16 -31
  450. package/src/trigger/sources/cron/cron-service.ts +1 -1
  451. package/src/trigger/sources/webhook/webhook-handler.ts +1 -1
  452. package/src/trigger/strategies/ai-router.ts +170 -0
  453. package/src/trigger/trigger-system-v2.ts +536 -0
  454. package/src/trigger/types.ts +13 -0
  455. package/src/workspace/strategies/optimistic.ts +9 -6
  456. package/.claude/settings.local.json +0 -61
  457. package/dist/acp/websocket-stream.d.ts +0 -30
  458. package/dist/acp/websocket-stream.d.ts.map +0 -1
  459. package/dist/acp/websocket-stream.js +0 -118
  460. package/dist/acp/websocket-stream.js.map +0 -1
  461. package/dist/activity/deduplication.d.ts +0 -85
  462. package/dist/activity/deduplication.d.ts.map +0 -1
  463. package/dist/activity/deduplication.js +0 -149
  464. package/dist/activity/deduplication.js.map +0 -1
  465. package/dist/activity/index.d.ts +0 -16
  466. package/dist/activity/index.d.ts.map +0 -1
  467. package/dist/activity/index.js +0 -17
  468. package/dist/activity/index.js.map +0 -1
  469. package/dist/activity/relevance.d.ts +0 -81
  470. package/dist/activity/relevance.d.ts.map +0 -1
  471. package/dist/activity/relevance.js +0 -161
  472. package/dist/activity/relevance.js.map +0 -1
  473. package/dist/activity/types.d.ts +0 -169
  474. package/dist/activity/types.d.ts.map +0 -1
  475. package/dist/activity/types.js +0 -33
  476. package/dist/activity/types.js.map +0 -1
  477. package/dist/activity/watcher.d.ts +0 -64
  478. package/dist/activity/watcher.d.ts.map +0 -1
  479. package/dist/activity/watcher.js +0 -212
  480. package/dist/activity/watcher.js.map +0 -1
  481. package/dist/agent/wake.d.ts +0 -85
  482. package/dist/agent/wake.d.ts.map +0 -1
  483. package/dist/agent/wake.js +0 -278
  484. package/dist/agent/wake.js.map +0 -1
  485. package/dist/lifecycle/handlers/generic.d.ts +0 -27
  486. package/dist/lifecycle/handlers/generic.d.ts.map +0 -1
  487. package/dist/lifecycle/handlers/generic.js +0 -56
  488. package/dist/lifecycle/handlers/generic.js.map +0 -1
  489. package/dist/lifecycle/handlers/index.d.ts +0 -47
  490. package/dist/lifecycle/handlers/index.d.ts.map +0 -1
  491. package/dist/lifecycle/handlers/index.js +0 -93
  492. package/dist/lifecycle/handlers/index.js.map +0 -1
  493. package/dist/lifecycle/handlers/integrator.d.ts +0 -81
  494. package/dist/lifecycle/handlers/integrator.d.ts.map +0 -1
  495. package/dist/lifecycle/handlers/integrator.js +0 -451
  496. package/dist/lifecycle/handlers/integrator.js.map +0 -1
  497. package/dist/lifecycle/handlers/monitor.d.ts +0 -29
  498. package/dist/lifecycle/handlers/monitor.d.ts.map +0 -1
  499. package/dist/lifecycle/handlers/monitor.js +0 -79
  500. package/dist/lifecycle/handlers/monitor.js.map +0 -1
  501. package/dist/lifecycle/handlers/worker.d.ts +0 -56
  502. package/dist/lifecycle/handlers/worker.d.ts.map +0 -1
  503. package/dist/lifecycle/handlers/worker.js +0 -381
  504. package/dist/lifecycle/handlers/worker.js.map +0 -1
  505. package/dist/mail/conversation-map.d.ts +0 -33
  506. package/dist/mail/conversation-map.d.ts.map +0 -1
  507. package/dist/mail/conversation-map.js +0 -61
  508. package/dist/mail/conversation-map.js.map +0 -1
  509. package/dist/mail/index.d.ts +0 -11
  510. package/dist/mail/index.d.ts.map +0 -1
  511. package/dist/mail/index.js +0 -11
  512. package/dist/mail/index.js.map +0 -1
  513. package/dist/mail/mail-service.d.ts +0 -85
  514. package/dist/mail/mail-service.d.ts.map +0 -1
  515. package/dist/mail/mail-service.js +0 -121
  516. package/dist/mail/mail-service.js.map +0 -1
  517. package/dist/mail/stores/eventstore-conversation-store.d.ts +0 -40
  518. package/dist/mail/stores/eventstore-conversation-store.d.ts.map +0 -1
  519. package/dist/mail/stores/eventstore-conversation-store.js +0 -131
  520. package/dist/mail/stores/eventstore-conversation-store.js.map +0 -1
  521. package/dist/mail/stores/eventstore-participant-store.d.ts +0 -43
  522. package/dist/mail/stores/eventstore-participant-store.d.ts.map +0 -1
  523. package/dist/mail/stores/eventstore-participant-store.js +0 -145
  524. package/dist/mail/stores/eventstore-participant-store.js.map +0 -1
  525. package/dist/mail/stores/eventstore-thread-store.d.ts +0 -46
  526. package/dist/mail/stores/eventstore-thread-store.d.ts.map +0 -1
  527. package/dist/mail/stores/eventstore-thread-store.js +0 -118
  528. package/dist/mail/stores/eventstore-thread-store.js.map +0 -1
  529. package/dist/mail/stores/eventstore-turn-store.d.ts +0 -47
  530. package/dist/mail/stores/eventstore-turn-store.d.ts.map +0 -1
  531. package/dist/mail/stores/eventstore-turn-store.js +0 -153
  532. package/dist/mail/stores/eventstore-turn-store.js.map +0 -1
  533. package/dist/mail/stores/index.d.ts +0 -12
  534. package/dist/mail/stores/index.d.ts.map +0 -1
  535. package/dist/mail/stores/index.js +0 -12
  536. package/dist/mail/stores/index.js.map +0 -1
  537. package/dist/mail/stores/types.d.ts +0 -146
  538. package/dist/mail/stores/types.d.ts.map +0 -1
  539. package/dist/mail/stores/types.js +0 -13
  540. package/dist/mail/stores/types.js.map +0 -1
  541. package/dist/mail/turn-recorder.d.ts +0 -30
  542. package/dist/mail/turn-recorder.d.ts.map +0 -1
  543. package/dist/mail/turn-recorder.js +0 -98
  544. package/dist/mail/turn-recorder.js.map +0 -1
  545. package/dist/map/adapter/acp-over-map.d.ts +0 -115
  546. package/dist/map/adapter/acp-over-map.d.ts.map +0 -1
  547. package/dist/map/adapter/acp-over-map.js +0 -1024
  548. package/dist/map/adapter/acp-over-map.js.map +0 -1
  549. package/dist/map/adapter/connection-manager.d.ts +0 -150
  550. package/dist/map/adapter/connection-manager.d.ts.map +0 -1
  551. package/dist/map/adapter/connection-manager.js +0 -207
  552. package/dist/map/adapter/connection-manager.js.map +0 -1
  553. package/dist/map/adapter/event-log.d.ts +0 -87
  554. package/dist/map/adapter/event-log.d.ts.map +0 -1
  555. package/dist/map/adapter/event-log.js +0 -122
  556. package/dist/map/adapter/event-log.js.map +0 -1
  557. package/dist/map/adapter/event-translator.d.ts +0 -85
  558. package/dist/map/adapter/event-translator.d.ts.map +0 -1
  559. package/dist/map/adapter/event-translator.js +0 -295
  560. package/dist/map/adapter/event-translator.js.map +0 -1
  561. package/dist/map/adapter/extensions/agent-detection.d.ts +0 -49
  562. package/dist/map/adapter/extensions/agent-detection.d.ts.map +0 -1
  563. package/dist/map/adapter/extensions/agent-detection.js +0 -91
  564. package/dist/map/adapter/extensions/agent-detection.js.map +0 -1
  565. package/dist/map/adapter/extensions/agent-lifecycle.d.ts +0 -82
  566. package/dist/map/adapter/extensions/agent-lifecycle.d.ts.map +0 -1
  567. package/dist/map/adapter/extensions/agent-lifecycle.js +0 -164
  568. package/dist/map/adapter/extensions/agent-lifecycle.js.map +0 -1
  569. package/dist/map/adapter/extensions/index.d.ts +0 -89
  570. package/dist/map/adapter/extensions/index.d.ts.map +0 -1
  571. package/dist/map/adapter/extensions/index.js +0 -187
  572. package/dist/map/adapter/extensions/index.js.map +0 -1
  573. package/dist/map/adapter/extensions/mcp-bridge.d.ts +0 -57
  574. package/dist/map/adapter/extensions/mcp-bridge.d.ts.map +0 -1
  575. package/dist/map/adapter/extensions/mcp-bridge.js +0 -745
  576. package/dist/map/adapter/extensions/mcp-bridge.js.map +0 -1
  577. package/dist/map/adapter/extensions/rename.d.ts +0 -29
  578. package/dist/map/adapter/extensions/rename.d.ts.map +0 -1
  579. package/dist/map/adapter/extensions/rename.js +0 -49
  580. package/dist/map/adapter/extensions/rename.js.map +0 -1
  581. package/dist/map/adapter/extensions/resume.d.ts +0 -47
  582. package/dist/map/adapter/extensions/resume.d.ts.map +0 -1
  583. package/dist/map/adapter/extensions/resume.js +0 -59
  584. package/dist/map/adapter/extensions/resume.js.map +0 -1
  585. package/dist/map/adapter/extensions/task.d.ts +0 -40
  586. package/dist/map/adapter/extensions/task.d.ts.map +0 -1
  587. package/dist/map/adapter/extensions/task.js +0 -197
  588. package/dist/map/adapter/extensions/task.js.map +0 -1
  589. package/dist/map/adapter/extensions/update-metadata.d.ts +0 -29
  590. package/dist/map/adapter/extensions/update-metadata.d.ts.map +0 -1
  591. package/dist/map/adapter/extensions/update-metadata.js +0 -67
  592. package/dist/map/adapter/extensions/update-metadata.js.map +0 -1
  593. package/dist/map/adapter/extensions/wake.d.ts +0 -60
  594. package/dist/map/adapter/extensions/wake.d.ts.map +0 -1
  595. package/dist/map/adapter/extensions/wake.js +0 -144
  596. package/dist/map/adapter/extensions/wake.js.map +0 -1
  597. package/dist/map/adapter/extensions/workspace-files.d.ts +0 -42
  598. package/dist/map/adapter/extensions/workspace-files.d.ts.map +0 -1
  599. package/dist/map/adapter/extensions/workspace-files.js +0 -338
  600. package/dist/map/adapter/extensions/workspace-files.js.map +0 -1
  601. package/dist/map/adapter/extensions/workspace.d.ts +0 -57
  602. package/dist/map/adapter/extensions/workspace.d.ts.map +0 -1
  603. package/dist/map/adapter/extensions/workspace.js +0 -81
  604. package/dist/map/adapter/extensions/workspace.js.map +0 -1
  605. package/dist/map/adapter/index.d.ts +0 -20
  606. package/dist/map/adapter/index.d.ts.map +0 -1
  607. package/dist/map/adapter/index.js +0 -38
  608. package/dist/map/adapter/index.js.map +0 -1
  609. package/dist/map/adapter/interface.d.ts +0 -450
  610. package/dist/map/adapter/interface.d.ts.map +0 -1
  611. package/dist/map/adapter/interface.js +0 -24
  612. package/dist/map/adapter/interface.js.map +0 -1
  613. package/dist/map/adapter/mail-handler-adapter.d.ts +0 -27
  614. package/dist/map/adapter/mail-handler-adapter.d.ts.map +0 -1
  615. package/dist/map/adapter/mail-handler-adapter.js +0 -292
  616. package/dist/map/adapter/mail-handler-adapter.js.map +0 -1
  617. package/dist/map/adapter/map-adapter.d.ts +0 -200
  618. package/dist/map/adapter/map-adapter.d.ts.map +0 -1
  619. package/dist/map/adapter/map-adapter.js +0 -1199
  620. package/dist/map/adapter/map-adapter.js.map +0 -1
  621. package/dist/map/adapter/rpc-handler.d.ts +0 -263
  622. package/dist/map/adapter/rpc-handler.d.ts.map +0 -1
  623. package/dist/map/adapter/rpc-handler.js +0 -365
  624. package/dist/map/adapter/rpc-handler.js.map +0 -1
  625. package/dist/map/adapter/subscription-manager.d.ts +0 -174
  626. package/dist/map/adapter/subscription-manager.d.ts.map +0 -1
  627. package/dist/map/adapter/subscription-manager.js +0 -248
  628. package/dist/map/adapter/subscription-manager.js.map +0 -1
  629. package/dist/map/adapter/types.d.ts +0 -194
  630. package/dist/map/adapter/types.d.ts.map +0 -1
  631. package/dist/map/adapter/types.js +0 -27
  632. package/dist/map/adapter/types.js.map +0 -1
  633. package/dist/map/adapter/websocket-integration.d.ts +0 -113
  634. package/dist/map/adapter/websocket-integration.d.ts.map +0 -1
  635. package/dist/map/adapter/websocket-integration.js +0 -134
  636. package/dist/map/adapter/websocket-integration.js.map +0 -1
  637. package/dist/map/federation/envelope.d.ts +0 -98
  638. package/dist/map/federation/envelope.d.ts.map +0 -1
  639. package/dist/map/federation/envelope.js +0 -160
  640. package/dist/map/federation/envelope.js.map +0 -1
  641. package/dist/map/federation/federation-handler.d.ts +0 -50
  642. package/dist/map/federation/federation-handler.d.ts.map +0 -1
  643. package/dist/map/federation/federation-handler.js +0 -306
  644. package/dist/map/federation/federation-handler.js.map +0 -1
  645. package/dist/map/federation/index.d.ts +0 -14
  646. package/dist/map/federation/index.d.ts.map +0 -1
  647. package/dist/map/federation/index.js +0 -13
  648. package/dist/map/federation/index.js.map +0 -1
  649. package/dist/map/federation/types.d.ts +0 -239
  650. package/dist/map/federation/types.d.ts.map +0 -1
  651. package/dist/map/federation/types.js +0 -23
  652. package/dist/map/federation/types.js.map +0 -1
  653. package/dist/map/utils/address-translation.d.ts +0 -99
  654. package/dist/map/utils/address-translation.d.ts.map +0 -1
  655. package/dist/map/utils/address-translation.js +0 -285
  656. package/dist/map/utils/address-translation.js.map +0 -1
  657. package/dist/map/utils/index.d.ts +0 -7
  658. package/dist/map/utils/index.d.ts.map +0 -1
  659. package/dist/map/utils/index.js +0 -7
  660. package/dist/map/utils/index.js.map +0 -1
  661. package/dist/mcp/map-client.d.ts +0 -39
  662. package/dist/mcp/map-client.d.ts.map +0 -1
  663. package/dist/mcp/map-client.js +0 -129
  664. package/dist/mcp/map-client.js.map +0 -1
  665. package/dist/mcp/mcp-server.d.ts +0 -70
  666. package/dist/mcp/mcp-server.d.ts.map +0 -1
  667. package/dist/mcp/mcp-server.js +0 -1015
  668. package/dist/mcp/mcp-server.js.map +0 -1
  669. package/dist/mcp/tools/claim_task.d.ts +0 -35
  670. package/dist/mcp/tools/claim_task.d.ts.map +0 -1
  671. package/dist/mcp/tools/claim_task.js +0 -58
  672. package/dist/mcp/tools/claim_task.js.map +0 -1
  673. package/dist/mcp/tools/done.d.ts +0 -102
  674. package/dist/mcp/tools/done.d.ts.map +0 -1
  675. package/dist/mcp/tools/done.js +0 -234
  676. package/dist/mcp/tools/done.js.map +0 -1
  677. package/dist/mcp/tools/inject_context.d.ts +0 -61
  678. package/dist/mcp/tools/inject_context.d.ts.map +0 -1
  679. package/dist/mcp/tools/inject_context.js +0 -123
  680. package/dist/mcp/tools/inject_context.js.map +0 -1
  681. package/dist/mcp/tools/list_claimable_tasks.d.ts +0 -38
  682. package/dist/mcp/tools/list_claimable_tasks.d.ts.map +0 -1
  683. package/dist/mcp/tools/list_claimable_tasks.js +0 -63
  684. package/dist/mcp/tools/list_claimable_tasks.js.map +0 -1
  685. package/dist/mcp/tools/unclaim_task.d.ts +0 -31
  686. package/dist/mcp/tools/unclaim_task.d.ts.map +0 -1
  687. package/dist/mcp/tools/unclaim_task.js +0 -47
  688. package/dist/mcp/tools/unclaim_task.js.map +0 -1
  689. package/dist/mcp/tools/wait_for_activity.d.ts +0 -60
  690. package/dist/mcp/tools/wait_for_activity.d.ts.map +0 -1
  691. package/dist/mcp/tools/wait_for_activity.js +0 -135
  692. package/dist/mcp/tools/wait_for_activity.js.map +0 -1
  693. package/dist/monitor/health-check-service.d.ts +0 -143
  694. package/dist/monitor/health-check-service.d.ts.map +0 -1
  695. package/dist/monitor/health-check-service.js +0 -240
  696. package/dist/monitor/health-check-service.js.map +0 -1
  697. package/dist/monitor/index.d.ts +0 -14
  698. package/dist/monitor/index.d.ts.map +0 -1
  699. package/dist/monitor/index.js +0 -14
  700. package/dist/monitor/index.js.map +0 -1
  701. package/dist/monitor/stall-detector.d.ts +0 -109
  702. package/dist/monitor/stall-detector.d.ts.map +0 -1
  703. package/dist/monitor/stall-detector.js +0 -152
  704. package/dist/monitor/stall-detector.js.map +0 -1
  705. package/dist/peer/capability-manager.d.ts +0 -56
  706. package/dist/peer/capability-manager.d.ts.map +0 -1
  707. package/dist/peer/capability-manager.js +0 -186
  708. package/dist/peer/capability-manager.js.map +0 -1
  709. package/dist/peer/encapsulation-manager.d.ts +0 -190
  710. package/dist/peer/encapsulation-manager.d.ts.map +0 -1
  711. package/dist/peer/encapsulation-manager.js +0 -486
  712. package/dist/peer/encapsulation-manager.js.map +0 -1
  713. package/dist/peer/federation-manager.d.ts +0 -223
  714. package/dist/peer/federation-manager.d.ts.map +0 -1
  715. package/dist/peer/federation-manager.js +0 -528
  716. package/dist/peer/federation-manager.js.map +0 -1
  717. package/dist/peer/hierarchy-errors.d.ts +0 -208
  718. package/dist/peer/hierarchy-errors.d.ts.map +0 -1
  719. package/dist/peer/hierarchy-errors.js +0 -268
  720. package/dist/peer/hierarchy-errors.js.map +0 -1
  721. package/dist/peer/hierarchy-protocol.d.ts +0 -159
  722. package/dist/peer/hierarchy-protocol.d.ts.map +0 -1
  723. package/dist/peer/hierarchy-protocol.js +0 -142
  724. package/dist/peer/hierarchy-protocol.js.map +0 -1
  725. package/dist/peer/index.d.ts +0 -15
  726. package/dist/peer/index.d.ts.map +0 -1
  727. package/dist/peer/index.js +0 -15
  728. package/dist/peer/index.js.map +0 -1
  729. package/dist/peer/peer-manager.d.ts +0 -99
  730. package/dist/peer/peer-manager.d.ts.map +0 -1
  731. package/dist/peer/peer-manager.js +0 -333
  732. package/dist/peer/peer-manager.js.map +0 -1
  733. package/dist/peer/task-delegation.d.ts +0 -189
  734. package/dist/peer/task-delegation.d.ts.map +0 -1
  735. package/dist/peer/task-delegation.js +0 -303
  736. package/dist/peer/task-delegation.js.map +0 -1
  737. package/dist/peer/transports/index.d.ts +0 -8
  738. package/dist/peer/transports/index.d.ts.map +0 -1
  739. package/dist/peer/transports/index.js +0 -8
  740. package/dist/peer/transports/index.js.map +0 -1
  741. package/dist/peer/transports/local-transport.d.ts +0 -56
  742. package/dist/peer/transports/local-transport.d.ts.map +0 -1
  743. package/dist/peer/transports/local-transport.js +0 -263
  744. package/dist/peer/transports/local-transport.js.map +0 -1
  745. package/dist/peer/transports/websocket-transport.d.ts +0 -86
  746. package/dist/peer/transports/websocket-transport.d.ts.map +0 -1
  747. package/dist/peer/transports/websocket-transport.js +0 -338
  748. package/dist/peer/transports/websocket-transport.js.map +0 -1
  749. package/dist/peer/types.d.ts +0 -268
  750. package/dist/peer/types.d.ts.map +0 -1
  751. package/dist/peer/types.js +0 -36
  752. package/dist/peer/types.js.map +0 -1
  753. package/dist/router/address-resolver.d.ts +0 -102
  754. package/dist/router/address-resolver.d.ts.map +0 -1
  755. package/dist/router/address-resolver.js +0 -198
  756. package/dist/router/address-resolver.js.map +0 -1
  757. package/dist/router/broadcast.d.ts +0 -53
  758. package/dist/router/broadcast.d.ts.map +0 -1
  759. package/dist/router/broadcast.js +0 -75
  760. package/dist/router/broadcast.js.map +0 -1
  761. package/dist/router/channels.d.ts +0 -148
  762. package/dist/router/channels.d.ts.map +0 -1
  763. package/dist/router/channels.js +0 -126
  764. package/dist/router/channels.js.map +0 -1
  765. package/dist/router/index.d.ts +0 -21
  766. package/dist/router/index.d.ts.map +0 -1
  767. package/dist/router/index.js +0 -18
  768. package/dist/router/index.js.map +0 -1
  769. package/dist/router/message-router.d.ts +0 -197
  770. package/dist/router/message-router.d.ts.map +0 -1
  771. package/dist/router/message-router.js +0 -903
  772. package/dist/router/message-router.js.map +0 -1
  773. package/dist/router/message-types.d.ts +0 -183
  774. package/dist/router/message-types.d.ts.map +0 -1
  775. package/dist/router/message-types.js +0 -79
  776. package/dist/router/message-types.js.map +0 -1
  777. package/dist/router/role-resolver.d.ts +0 -67
  778. package/dist/router/role-resolver.d.ts.map +0 -1
  779. package/dist/router/role-resolver.js +0 -106
  780. package/dist/router/role-resolver.js.map +0 -1
  781. package/dist/router/signals.d.ts +0 -253
  782. package/dist/router/signals.d.ts.map +0 -1
  783. package/dist/router/signals.js +0 -53
  784. package/dist/router/signals.js.map +0 -1
  785. package/dist/router/types.d.ts +0 -191
  786. package/dist/router/types.d.ts.map +0 -1
  787. package/dist/router/types.js +0 -34
  788. package/dist/router/types.js.map +0 -1
  789. package/dist/router/wake.d.ts +0 -111
  790. package/dist/router/wake.d.ts.map +0 -1
  791. package/dist/router/wake.js +0 -180
  792. package/dist/router/wake.js.map +0 -1
  793. package/dist/server/combined-server.d.ts +0 -88
  794. package/dist/server/combined-server.d.ts.map +0 -1
  795. package/dist/server/combined-server.js +0 -331
  796. package/dist/server/combined-server.js.map +0 -1
  797. package/dist/steering/index.d.ts +0 -11
  798. package/dist/steering/index.d.ts.map +0 -1
  799. package/dist/steering/index.js +0 -11
  800. package/dist/steering/index.js.map +0 -1
  801. package/dist/steering/inject.d.ts +0 -39
  802. package/dist/steering/inject.d.ts.map +0 -1
  803. package/dist/steering/inject.js +0 -197
  804. package/dist/steering/inject.js.map +0 -1
  805. package/dist/steering/types.d.ts +0 -100
  806. package/dist/steering/types.d.ts.map +0 -1
  807. package/dist/steering/types.js +0 -11
  808. package/dist/steering/types.js.map +0 -1
  809. package/dist/store/backends/index.d.ts +0 -11
  810. package/dist/store/backends/index.d.ts.map +0 -1
  811. package/dist/store/backends/index.js +0 -15
  812. package/dist/store/backends/index.js.map +0 -1
  813. package/dist/store/backends/json-backend.d.ts +0 -23
  814. package/dist/store/backends/json-backend.d.ts.map +0 -1
  815. package/dist/store/backends/json-backend.js +0 -220
  816. package/dist/store/backends/json-backend.js.map +0 -1
  817. package/dist/store/backends/memory-backend.d.ts +0 -12
  818. package/dist/store/backends/memory-backend.d.ts.map +0 -1
  819. package/dist/store/backends/memory-backend.js +0 -205
  820. package/dist/store/backends/memory-backend.js.map +0 -1
  821. package/dist/store/backends/sqlite-backend.d.ts +0 -27
  822. package/dist/store/backends/sqlite-backend.d.ts.map +0 -1
  823. package/dist/store/backends/sqlite-backend.js +0 -231
  824. package/dist/store/backends/sqlite-backend.js.map +0 -1
  825. package/dist/store/backends/tinybase-backend.d.ts +0 -22
  826. package/dist/store/backends/tinybase-backend.d.ts.map +0 -1
  827. package/dist/store/backends/tinybase-backend.js +0 -203
  828. package/dist/store/backends/tinybase-backend.js.map +0 -1
  829. package/dist/store/backends/types.d.ts +0 -175
  830. package/dist/store/backends/types.d.ts.map +0 -1
  831. package/dist/store/backends/types.js +0 -28
  832. package/dist/store/backends/types.js.map +0 -1
  833. package/dist/store/event-store.d.ts +0 -128
  834. package/dist/store/event-store.d.ts.map +0 -1
  835. package/dist/store/event-store.js +0 -1739
  836. package/dist/store/event-store.js.map +0 -1
  837. package/dist/store/instance.d.ts +0 -283
  838. package/dist/store/instance.d.ts.map +0 -1
  839. package/dist/store/instance.js +0 -363
  840. package/dist/store/instance.js.map +0 -1
  841. package/dist/store/migrations.d.ts +0 -41
  842. package/dist/store/migrations.d.ts.map +0 -1
  843. package/dist/store/migrations.js +0 -79
  844. package/dist/store/migrations.js.map +0 -1
  845. package/dist/store/types/config.d.ts +0 -16
  846. package/dist/store/types/config.d.ts.map +0 -1
  847. package/dist/store/types/config.js +0 -8
  848. package/dist/store/types/config.js.map +0 -1
  849. package/dist/store/types/conversations.d.ts +0 -91
  850. package/dist/store/types/conversations.d.ts.map +0 -1
  851. package/dist/store/types/conversations.js +0 -8
  852. package/dist/store/types/conversations.js.map +0 -1
  853. package/dist/store/types/sessions.d.ts +0 -44
  854. package/dist/store/types/sessions.d.ts.map +0 -1
  855. package/dist/store/types/sessions.js +0 -9
  856. package/dist/store/types/sessions.js.map +0 -1
  857. package/dist/task/backend/index.d.ts +0 -93
  858. package/dist/task/backend/index.d.ts.map +0 -1
  859. package/dist/task/backend/index.js +0 -178
  860. package/dist/task/backend/index.js.map +0 -1
  861. package/dist/task/backend/memory.d.ts +0 -70
  862. package/dist/task/backend/memory.d.ts.map +0 -1
  863. package/dist/task/backend/memory.js +0 -621
  864. package/dist/task/backend/memory.js.map +0 -1
  865. package/dist/task/backend/opentasks/backend.d.ts +0 -140
  866. package/dist/task/backend/opentasks/backend.d.ts.map +0 -1
  867. package/dist/task/backend/opentasks/backend.js +0 -1023
  868. package/dist/task/backend/opentasks/backend.js.map +0 -1
  869. package/dist/task/backend/opentasks/client.d.ts +0 -337
  870. package/dist/task/backend/opentasks/client.d.ts.map +0 -1
  871. package/dist/task/backend/opentasks/client.js +0 -225
  872. package/dist/task/backend/opentasks/client.js.map +0 -1
  873. package/dist/task/backend/opentasks/daemon-manager.d.ts +0 -89
  874. package/dist/task/backend/opentasks/daemon-manager.d.ts.map +0 -1
  875. package/dist/task/backend/opentasks/daemon-manager.js +0 -195
  876. package/dist/task/backend/opentasks/daemon-manager.js.map +0 -1
  877. package/dist/task/backend/opentasks/index.d.ts +0 -21
  878. package/dist/task/backend/opentasks/index.d.ts.map +0 -1
  879. package/dist/task/backend/opentasks/index.js +0 -21
  880. package/dist/task/backend/opentasks/index.js.map +0 -1
  881. package/dist/task/backend/opentasks/mapping.d.ts +0 -48
  882. package/dist/task/backend/opentasks/mapping.d.ts.map +0 -1
  883. package/dist/task/backend/opentasks/mapping.js +0 -77
  884. package/dist/task/backend/opentasks/mapping.js.map +0 -1
  885. package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts +0 -54
  886. package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts.map +0 -1
  887. package/dist/task/backend/sudocode/__tests__/integration/test-utils.js +0 -88
  888. package/dist/task/backend/sudocode/__tests__/integration/test-utils.js.map +0 -1
  889. package/dist/task/backend/sudocode/backend.d.ts +0 -155
  890. package/dist/task/backend/sudocode/backend.d.ts.map +0 -1
  891. package/dist/task/backend/sudocode/backend.js +0 -942
  892. package/dist/task/backend/sudocode/backend.js.map +0 -1
  893. package/dist/task/backend/sudocode/client.d.ts +0 -303
  894. package/dist/task/backend/sudocode/client.d.ts.map +0 -1
  895. package/dist/task/backend/sudocode/client.js +0 -101
  896. package/dist/task/backend/sudocode/client.js.map +0 -1
  897. package/dist/task/backend/sudocode/index.d.ts +0 -19
  898. package/dist/task/backend/sudocode/index.d.ts.map +0 -1
  899. package/dist/task/backend/sudocode/index.js +0 -17
  900. package/dist/task/backend/sudocode/index.js.map +0 -1
  901. package/dist/task/backend/sudocode/mapping.d.ts +0 -51
  902. package/dist/task/backend/sudocode/mapping.d.ts.map +0 -1
  903. package/dist/task/backend/sudocode/mapping.js +0 -86
  904. package/dist/task/backend/sudocode/mapping.js.map +0 -1
  905. package/dist/task/backend/sudocode/server-client.d.ts +0 -56
  906. package/dist/task/backend/sudocode/server-client.d.ts.map +0 -1
  907. package/dist/task/backend/sudocode/server-client.js +0 -367
  908. package/dist/task/backend/sudocode/server-client.js.map +0 -1
  909. package/dist/task/backend/sudocode/standalone-client.d.ts +0 -91
  910. package/dist/task/backend/sudocode/standalone-client.d.ts.map +0 -1
  911. package/dist/task/backend/sudocode/standalone-client.js +0 -476
  912. package/dist/task/backend/sudocode/standalone-client.js.map +0 -1
  913. package/dist/task/backend/sudocode/sync-policy.d.ts +0 -166
  914. package/dist/task/backend/sudocode/sync-policy.d.ts.map +0 -1
  915. package/dist/task/backend/sudocode/sync-policy.js +0 -221
  916. package/dist/task/backend/sudocode/sync-policy.js.map +0 -1
  917. package/dist/task/backend/sudocode/tools.d.ts +0 -87
  918. package/dist/task/backend/sudocode/tools.d.ts.map +0 -1
  919. package/dist/task/backend/sudocode/tools.js +0 -743
  920. package/dist/task/backend/sudocode/tools.js.map +0 -1
  921. package/dist/task/backend/tool-provider.d.ts +0 -56
  922. package/dist/task/backend/tool-provider.d.ts.map +0 -1
  923. package/dist/task/backend/tool-provider.js +0 -424
  924. package/dist/task/backend/tool-provider.js.map +0 -1
  925. package/dist/task/backend/types.d.ts +0 -297
  926. package/dist/task/backend/types.d.ts.map +0 -1
  927. package/dist/task/backend/types.js +0 -27
  928. package/dist/task/backend/types.js.map +0 -1
  929. package/dist/task/backend/unified-tool-provider.d.ts +0 -57
  930. package/dist/task/backend/unified-tool-provider.d.ts.map +0 -1
  931. package/dist/task/backend/unified-tool-provider.js +0 -623
  932. package/dist/task/backend/unified-tool-provider.js.map +0 -1
  933. package/dist/task/index.d.ts +0 -7
  934. package/dist/task/index.d.ts.map +0 -1
  935. package/dist/task/index.js +0 -7
  936. package/dist/task/index.js.map +0 -1
  937. package/dist/task/retry-policy.d.ts +0 -89
  938. package/dist/task/retry-policy.d.ts.map +0 -1
  939. package/dist/task/retry-policy.js +0 -160
  940. package/dist/task/retry-policy.js.map +0 -1
  941. package/dist/task/task-manager.d.ts +0 -70
  942. package/dist/task/task-manager.d.ts.map +0 -1
  943. package/dist/task/task-manager.js +0 -319
  944. package/dist/task/task-manager.js.map +0 -1
  945. package/dist/task/types.d.ts +0 -72
  946. package/dist/task/types.d.ts.map +0 -1
  947. package/dist/task/types.js +0 -33
  948. package/dist/task/types.js.map +0 -1
  949. package/dist/teams/team-runtime.d.ts +0 -139
  950. package/dist/teams/team-runtime.d.ts.map +0 -1
  951. package/dist/teams/team-runtime.js +0 -615
  952. package/dist/teams/team-runtime.js.map +0 -1
  953. package/dist/trigger/router/index.d.ts +0 -11
  954. package/dist/trigger/router/index.d.ts.map +0 -1
  955. package/dist/trigger/router/index.js +0 -10
  956. package/dist/trigger/router/index.js.map +0 -1
  957. package/dist/trigger/router/strategies/ai-router-strategy.d.ts +0 -34
  958. package/dist/trigger/router/strategies/ai-router-strategy.d.ts.map +0 -1
  959. package/dist/trigger/router/strategies/ai-router-strategy.js +0 -359
  960. package/dist/trigger/router/strategies/ai-router-strategy.js.map +0 -1
  961. package/dist/trigger/router/strategies/direct-strategy.d.ts +0 -32
  962. package/dist/trigger/router/strategies/direct-strategy.d.ts.map +0 -1
  963. package/dist/trigger/router/strategies/direct-strategy.js +0 -119
  964. package/dist/trigger/router/strategies/direct-strategy.js.map +0 -1
  965. package/dist/trigger/router/strategies/index.d.ts +0 -11
  966. package/dist/trigger/router/strategies/index.d.ts.map +0 -1
  967. package/dist/trigger/router/strategies/index.js +0 -11
  968. package/dist/trigger/router/strategies/index.js.map +0 -1
  969. package/dist/trigger/router/strategies/role-strategy.d.ts +0 -39
  970. package/dist/trigger/router/strategies/role-strategy.d.ts.map +0 -1
  971. package/dist/trigger/router/strategies/role-strategy.js +0 -207
  972. package/dist/trigger/router/strategies/role-strategy.js.map +0 -1
  973. package/dist/trigger/router/trigger-router.d.ts +0 -54
  974. package/dist/trigger/router/trigger-router.d.ts.map +0 -1
  975. package/dist/trigger/router/trigger-router.js +0 -362
  976. package/dist/trigger/router/trigger-router.js.map +0 -1
  977. package/dist/trigger/router/types.d.ts +0 -225
  978. package/dist/trigger/router/types.d.ts.map +0 -1
  979. package/dist/trigger/router/types.js +0 -10
  980. package/dist/trigger/router/types.js.map +0 -1
  981. package/dist/trigger/trigger-system.d.ts +0 -77
  982. package/dist/trigger/trigger-system.d.ts.map +0 -1
  983. package/dist/trigger/trigger-system.js +0 -84
  984. package/dist/trigger/trigger-system.js.map +0 -1
  985. package/references/acp-factory-ref/CHANGELOG.md +0 -33
  986. package/references/acp-factory-ref/LICENSE +0 -21
  987. package/references/acp-factory-ref/README.md +0 -341
  988. package/references/acp-factory-ref/package-lock.json +0 -3102
  989. package/references/acp-factory-ref/package.json +0 -96
  990. package/references/acp-factory-ref/python/CHANGELOG.md +0 -33
  991. package/references/acp-factory-ref/python/LICENSE +0 -21
  992. package/references/acp-factory-ref/python/Makefile +0 -57
  993. package/references/acp-factory-ref/python/README.md +0 -253
  994. package/references/acp-factory-ref/python/pyproject.toml +0 -73
  995. package/references/acp-factory-ref/python/tests/e2e/__init__.py +0 -1
  996. package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +0 -349
  997. package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +0 -165
  998. package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +0 -296
  999. package/references/acp-factory-ref/python/tests/test_client_handler.py +0 -543
  1000. package/references/acp-factory-ref/python/tests/test_pushable.py +0 -199
  1001. package/references/claude-code-acp/.github/workflows/ci.yml +0 -45
  1002. package/references/claude-code-acp/.github/workflows/publish.yml +0 -34
  1003. package/references/claude-code-acp/.prettierrc.json +0 -4
  1004. package/references/claude-code-acp/CHANGELOG.md +0 -249
  1005. package/references/claude-code-acp/LICENSE +0 -222
  1006. package/references/claude-code-acp/README.md +0 -53
  1007. package/references/claude-code-acp/docs/RELEASES.md +0 -24
  1008. package/references/claude-code-acp/eslint.config.js +0 -48
  1009. package/references/claude-code-acp/package-lock.json +0 -4570
  1010. package/references/claude-code-acp/package.json +0 -88
  1011. package/references/claude-code-acp/scripts/release.sh +0 -119
  1012. package/references/claude-code-acp/src/acp-agent.ts +0 -2076
  1013. package/references/claude-code-acp/src/index.ts +0 -26
  1014. package/references/claude-code-acp/src/lib.ts +0 -38
  1015. package/references/claude-code-acp/src/mcp-server.ts +0 -911
  1016. package/references/claude-code-acp/src/settings.ts +0 -522
  1017. package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +0 -5
  1018. package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +0 -6
  1019. package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +0 -479
  1020. package/references/claude-code-acp/src/tests/acp-agent.test.ts +0 -1502
  1021. package/references/claude-code-acp/src/tests/extract-lines.test.ts +0 -103
  1022. package/references/claude-code-acp/src/tests/fork-session.test.ts +0 -335
  1023. package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +0 -334
  1024. package/references/claude-code-acp/src/tests/settings.test.ts +0 -617
  1025. package/references/claude-code-acp/src/tests/skills-options.test.ts +0 -187
  1026. package/references/claude-code-acp/src/tests/tools.test.ts +0 -318
  1027. package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +0 -558
  1028. package/references/claude-code-acp/src/tools.ts +0 -819
  1029. package/references/claude-code-acp/src/utils.ts +0 -171
  1030. package/references/claude-code-acp/tsconfig.json +0 -18
  1031. package/references/claude-code-acp/vitest.config.ts +0 -19
  1032. package/references/multi-agent-protocol/.sudocode/issues.jsonl +0 -111
  1033. package/references/multi-agent-protocol/.sudocode/specs.jsonl +0 -13
  1034. package/references/multi-agent-protocol/LICENSE +0 -21
  1035. package/references/multi-agent-protocol/README.md +0 -113
  1036. package/references/multi-agent-protocol/docs/00-design-specification.md +0 -496
  1037. package/references/multi-agent-protocol/docs/01-open-questions.md +0 -1050
  1038. package/references/multi-agent-protocol/docs/02-wire-protocol.md +0 -296
  1039. package/references/multi-agent-protocol/docs/03-streaming-semantics.md +0 -252
  1040. package/references/multi-agent-protocol/docs/04-error-handling.md +0 -231
  1041. package/references/multi-agent-protocol/docs/05-connection-model.md +0 -244
  1042. package/references/multi-agent-protocol/docs/06-visibility-permissions.md +0 -243
  1043. package/references/multi-agent-protocol/docs/07-federation.md +0 -259
  1044. package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +0 -253
  1045. package/references/multi-agent-protocol/docs/09-authentication.md +0 -680
  1046. package/references/multi-agent-protocol/docs/10-mail-protocol.md +0 -553
  1047. package/references/multi-agent-protocol/docs/agent-iam-integration.md +0 -877
  1048. package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +0 -459
  1049. package/references/multi-agent-protocol/docs/git-transport-draft.md +0 -251
  1050. package/references/multi-agent-protocol/docs-site/Gemfile +0 -22
  1051. package/references/multi-agent-protocol/docs-site/README.md +0 -82
  1052. package/references/multi-agent-protocol/docs-site/_config.yml +0 -91
  1053. package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +0 -20
  1054. package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +0 -42
  1055. package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +0 -34
  1056. package/references/multi-agent-protocol/docs-site/examples/full-integration.md +0 -510
  1057. package/references/multi-agent-protocol/docs-site/examples/index.md +0 -138
  1058. package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +0 -282
  1059. package/references/multi-agent-protocol/docs-site/examples/task-queue.md +0 -399
  1060. package/references/multi-agent-protocol/docs-site/getting-started/index.md +0 -98
  1061. package/references/multi-agent-protocol/docs-site/getting-started/installation.md +0 -219
  1062. package/references/multi-agent-protocol/docs-site/getting-started/overview.md +0 -172
  1063. package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +0 -237
  1064. package/references/multi-agent-protocol/docs-site/index.md +0 -136
  1065. package/references/multi-agent-protocol/docs-site/protocol/authentication.md +0 -391
  1066. package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +0 -376
  1067. package/references/multi-agent-protocol/docs-site/protocol/design.md +0 -284
  1068. package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +0 -312
  1069. package/references/multi-agent-protocol/docs-site/protocol/federation.md +0 -449
  1070. package/references/multi-agent-protocol/docs-site/protocol/index.md +0 -129
  1071. package/references/multi-agent-protocol/docs-site/protocol/permissions.md +0 -398
  1072. package/references/multi-agent-protocol/docs-site/protocol/streaming.md +0 -353
  1073. package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +0 -369
  1074. package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +0 -357
  1075. package/references/multi-agent-protocol/docs-site/sdk/api/client.md +0 -380
  1076. package/references/multi-agent-protocol/docs-site/sdk/api/index.md +0 -62
  1077. package/references/multi-agent-protocol/docs-site/sdk/api/server.md +0 -453
  1078. package/references/multi-agent-protocol/docs-site/sdk/api/types.md +0 -468
  1079. package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +0 -375
  1080. package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +0 -405
  1081. package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +0 -352
  1082. package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +0 -89
  1083. package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +0 -360
  1084. package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +0 -446
  1085. package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +0 -363
  1086. package/references/multi-agent-protocol/docs-site/sdk/index.md +0 -206
  1087. package/references/multi-agent-protocol/package-lock.json +0 -3886
  1088. package/references/multi-agent-protocol/package.json +0 -56
  1089. package/references/multi-agent-protocol/schema/meta.json +0 -467
  1090. package/references/multi-agent-protocol/schema/schema.json +0 -2558
  1091. package/src/__tests__/e2e/agent-spawn-visibility.e2e.test.ts +0 -761
  1092. package/src/__tests__/e2e/cascade-termination.e2e.test.ts +0 -588
  1093. package/src/__tests__/e2e/conflict-resolution-flow.e2e.test.ts +0 -790
  1094. package/src/__tests__/e2e/full-agent-conflict-resolution.e2e.test.ts +0 -714
  1095. package/src/__tests__/e2e/full-agent-orchestration.e2e.test.ts +0 -536
  1096. package/src/__tests__/e2e/mcp-server-debug.e2e.test.ts +0 -372
  1097. package/src/__tests__/e2e/mcp-thin-client-bridge.e2e.test.ts +0 -304
  1098. package/src/__tests__/e2e/mcp-tools-available.e2e.test.ts +0 -324
  1099. package/src/__tests__/e2e/multi-agent.e2e.test.ts +0 -1527
  1100. package/src/__tests__/e2e/multi-coordinator.e2e.test.ts +0 -602
  1101. package/src/__tests__/e2e/orchestration-flow.e2e.test.ts +0 -686
  1102. package/src/__tests__/e2e/spawn-session-streaming.e2e.test.ts +0 -563
  1103. package/src/__tests__/e2e/steering-task.e2e.test.ts +0 -840
  1104. package/src/__tests__/integration.e2e.test.ts +0 -407
  1105. package/src/acp/__tests__/combined-websocket-server.test.ts +0 -260
  1106. package/src/acp/__tests__/history.test.ts +0 -530
  1107. package/src/acp/__tests__/integration.test.ts +0 -1049
  1108. package/src/acp/__tests__/multi-client-mounting.test.ts +0 -303
  1109. package/src/acp/__tests__/session-persistence.test.ts +0 -276
  1110. package/src/acp/__tests__/websocket-full.e2e.test.ts +0 -401
  1111. package/src/acp/__tests__/websocket-integration.test.ts +0 -484
  1112. package/src/acp/__tests__/websocket-stream.test.ts +0 -281
  1113. package/src/acp/__tests__/websocket.e2e.test.ts +0 -390
  1114. package/src/acp/websocket-stream.ts +0 -140
  1115. package/src/activity/__tests__/deduplication.test.ts +0 -345
  1116. package/src/activity/__tests__/relevance.test.ts +0 -347
  1117. package/src/activity/__tests__/watcher.test.ts +0 -344
  1118. package/src/activity/deduplication.ts +0 -219
  1119. package/src/activity/index.ts +0 -51
  1120. package/src/activity/relevance.ts +0 -258
  1121. package/src/activity/types.ts +0 -263
  1122. package/src/activity/watcher.ts +0 -345
  1123. package/src/agent/__tests__/agent-manager.test.ts +0 -1382
  1124. package/src/agent/__tests__/wake.test.ts +0 -768
  1125. package/src/agent/wake.ts +0 -357
  1126. package/src/api/__tests__/conversation-api.test.ts +0 -468
  1127. package/src/cli/__tests__/acp.test.ts +0 -214
  1128. package/src/lifecycle/__tests__/cascade-termination.test.ts +0 -919
  1129. package/src/lifecycle/__tests__/cascade.test.ts +0 -595
  1130. package/src/lifecycle/__tests__/cleanup.test.ts +0 -322
  1131. package/src/lifecycle/__tests__/handlers.test.ts +0 -1826
  1132. package/src/lifecycle/__tests__/lifecycle.e2e.test.ts +0 -354
  1133. package/src/lifecycle/__tests__/merge-queue.e2e.test.ts +0 -602
  1134. package/src/lifecycle/handlers/generic.ts +0 -87
  1135. package/src/lifecycle/handlers/index.ts +0 -166
  1136. package/src/lifecycle/handlers/integrator.ts +0 -672
  1137. package/src/lifecycle/handlers/monitor.ts +0 -114
  1138. package/src/lifecycle/handlers/worker.ts +0 -506
  1139. package/src/mail/__tests__/conversation-lifecycle.test.ts +0 -409
  1140. package/src/mail/__tests__/eventstore-stores.test.ts +0 -1073
  1141. package/src/mail/__tests__/mail-full-agent.e2e.test.ts +0 -575
  1142. package/src/mail/__tests__/mail-integration.test.ts +0 -759
  1143. package/src/mail/__tests__/mail-map-protocol.e2e.test.ts +0 -1068
  1144. package/src/mail/__tests__/mail-service.test.ts +0 -506
  1145. package/src/mail/__tests__/turn-recorder.test.ts +0 -328
  1146. package/src/mail/conversation-map.ts +0 -107
  1147. package/src/mail/index.ts +0 -25
  1148. package/src/mail/mail-service.ts +0 -257
  1149. package/src/mail/stores/eventstore-conversation-store.ts +0 -146
  1150. package/src/mail/stores/eventstore-participant-store.ts +0 -172
  1151. package/src/mail/stores/eventstore-thread-store.ts +0 -129
  1152. package/src/mail/stores/eventstore-turn-store.ts +0 -173
  1153. package/src/mail/stores/index.ts +0 -12
  1154. package/src/mail/stores/types.ts +0 -160
  1155. package/src/mail/turn-recorder.ts +0 -124
  1156. package/src/map/README.md +0 -79
  1157. package/src/map/__tests__/adapter-types.test.ts +0 -326
  1158. package/src/map/__tests__/interface-types.test.ts +0 -342
  1159. package/src/map/__tests__/types.test.ts +0 -411
  1160. package/src/map/adapter/__tests__/acp-over-map-cancel.test.ts +0 -820
  1161. package/src/map/adapter/__tests__/acp-over-map-getmodels.test.ts +0 -355
  1162. package/src/map/adapter/__tests__/acp-over-map-history.test.ts +0 -1386
  1163. package/src/map/adapter/__tests__/acp-over-map-persistence.e2e.test.ts +0 -440
  1164. package/src/map/adapter/__tests__/connection-manager.test.ts +0 -344
  1165. package/src/map/adapter/__tests__/event-broadcast.test.ts +0 -420
  1166. package/src/map/adapter/__tests__/event-log.test.ts +0 -527
  1167. package/src/map/adapter/__tests__/event-translator.test.ts +0 -550
  1168. package/src/map/adapter/__tests__/extensions.test.ts +0 -1387
  1169. package/src/map/adapter/__tests__/map-adapter.test.ts +0 -926
  1170. package/src/map/adapter/__tests__/mcp-bridge.test.ts +0 -1187
  1171. package/src/map/adapter/__tests__/multi-client-broadcast.test.ts +0 -711
  1172. package/src/map/adapter/__tests__/rpc-handler.test.ts +0 -644
  1173. package/src/map/adapter/__tests__/subscription-manager.test.ts +0 -536
  1174. package/src/map/adapter/__tests__/websocket-integration.test.ts +0 -487
  1175. package/src/map/adapter/__tests__/workspace-files.test.ts +0 -673
  1176. package/src/map/adapter/acp-over-map.ts +0 -1483
  1177. package/src/map/adapter/connection-manager.ts +0 -400
  1178. package/src/map/adapter/event-log.ts +0 -208
  1179. package/src/map/adapter/event-translator.ts +0 -415
  1180. package/src/map/adapter/extensions/agent-detection.ts +0 -201
  1181. package/src/map/adapter/extensions/agent-lifecycle.ts +0 -267
  1182. package/src/map/adapter/extensions/index.ts +0 -280
  1183. package/src/map/adapter/extensions/mcp-bridge.ts +0 -995
  1184. package/src/map/adapter/extensions/resume.ts +0 -114
  1185. package/src/map/adapter/extensions/task.ts +0 -326
  1186. package/src/map/adapter/extensions/update-metadata.ts +0 -126
  1187. package/src/map/adapter/extensions/wake.ts +0 -239
  1188. package/src/map/adapter/extensions/workspace-files.ts +0 -449
  1189. package/src/map/adapter/extensions/workspace.ts +0 -176
  1190. package/src/map/adapter/index.ts +0 -158
  1191. package/src/map/adapter/interface.ts +0 -581
  1192. package/src/map/adapter/mail-handler-adapter.ts +0 -429
  1193. package/src/map/adapter/map-adapter.ts +0 -1749
  1194. package/src/map/adapter/rpc-handler.ts +0 -604
  1195. package/src/map/adapter/subscription-manager.ts +0 -474
  1196. package/src/map/adapter/types.ts +0 -259
  1197. package/src/map/adapter/websocket-integration.ts +0 -229
  1198. package/src/map/federation/__tests__/envelope.test.ts +0 -362
  1199. package/src/map/federation/__tests__/federation-handler.test.ts +0 -461
  1200. package/src/map/federation/envelope.ts +0 -243
  1201. package/src/map/federation/federation-handler.ts +0 -442
  1202. package/src/map/federation/index.ts +0 -65
  1203. package/src/map/federation/types.ts +0 -344
  1204. package/src/mcp/__tests__/map-client.test.ts +0 -386
  1205. package/src/mcp/__tests__/mcp-server-thin-client.test.ts +0 -368
  1206. package/src/mcp/__tests__/mcp-server.test.ts +0 -1002
  1207. package/src/mcp/map-client.ts +0 -177
  1208. package/src/mcp/mcp-server.ts +0 -1395
  1209. package/src/mcp/tools/__tests__/done.test.ts +0 -484
  1210. package/src/mcp/tools/claim_task.ts +0 -86
  1211. package/src/mcp/tools/done.ts +0 -338
  1212. package/src/mcp/tools/inject_context.ts +0 -173
  1213. package/src/mcp/tools/list_claimable_tasks.ts +0 -93
  1214. package/src/mcp/tools/unclaim_task.ts +0 -71
  1215. package/src/mcp/tools/wait_for_activity.ts +0 -185
  1216. package/src/monitor/__tests__/health-check-service.test.ts +0 -425
  1217. package/src/monitor/__tests__/stale-agent-flow.integration.test.ts +0 -393
  1218. package/src/monitor/__tests__/stall-detector.test.ts +0 -395
  1219. package/src/monitor/health-check-service.ts +0 -359
  1220. package/src/monitor/index.ts +0 -28
  1221. package/src/monitor/stall-detector.ts +0 -238
  1222. package/src/peer/__tests__/capability-manager.test.ts +0 -454
  1223. package/src/peer/__tests__/encapsulation-manager.test.ts +0 -787
  1224. package/src/peer/__tests__/federation-manager.test.ts +0 -828
  1225. package/src/peer/__tests__/hierarchy-errors.test.ts +0 -307
  1226. package/src/peer/__tests__/peer-manager.test.ts +0 -535
  1227. package/src/peer/__tests__/task-delegation.test.ts +0 -741
  1228. package/src/peer/capability-manager.ts +0 -289
  1229. package/src/peer/encapsulation-manager.ts +0 -831
  1230. package/src/peer/federation-manager.ts +0 -897
  1231. package/src/peer/hierarchy-errors.ts +0 -382
  1232. package/src/peer/hierarchy-protocol.ts +0 -328
  1233. package/src/peer/index.ts +0 -15
  1234. package/src/peer/peer-manager.ts +0 -540
  1235. package/src/peer/task-delegation.ts +0 -594
  1236. package/src/peer/transports/__tests__/local-transport.test.ts +0 -355
  1237. package/src/peer/transports/__tests__/websocket-transport.test.ts +0 -270
  1238. package/src/peer/transports/index.ts +0 -18
  1239. package/src/peer/transports/local-transport.ts +0 -348
  1240. package/src/peer/transports/websocket-transport.ts +0 -452
  1241. package/src/peer/types.ts +0 -331
  1242. package/src/roles/__tests__/capability-enforcement.test.ts +0 -989
  1243. package/src/roles/__tests__/message-routing.e2e.test.ts +0 -464
  1244. package/src/roles/__tests__/role-resolution.test.ts +0 -576
  1245. package/src/router/README.md +0 -120
  1246. package/src/router/__tests__/address-resolver.test.ts +0 -340
  1247. package/src/router/__tests__/broadcast.test.ts +0 -185
  1248. package/src/router/__tests__/message-router.test.ts +0 -1070
  1249. package/src/router/__tests__/role-channel.test.ts +0 -213
  1250. package/src/router/__tests__/send-to-address.test.ts +0 -731
  1251. package/src/router/__tests__/wake.test.ts +0 -459
  1252. package/src/router/address-resolver.ts +0 -303
  1253. package/src/router/broadcast.ts +0 -117
  1254. package/src/router/channels.ts +0 -283
  1255. package/src/router/index.ts +0 -148
  1256. package/src/router/message-router.ts +0 -1392
  1257. package/src/router/message-types.ts +0 -294
  1258. package/src/router/role-resolver.ts +0 -164
  1259. package/src/router/signals.ts +0 -335
  1260. package/src/router/types.ts +0 -306
  1261. package/src/router/wake.ts +0 -270
  1262. package/src/server/__tests__/combined-server.test.ts +0 -360
  1263. package/src/server/combined-server.ts +0 -530
  1264. package/src/steering/__tests__/inject.test.ts +0 -405
  1265. package/src/steering/__tests__/injection.e2e.test.ts +0 -932
  1266. package/src/steering/__tests__/steering-integration.test.ts +0 -747
  1267. package/src/steering/index.ts +0 -25
  1268. package/src/steering/inject.ts +0 -262
  1269. package/src/steering/types.ts +0 -143
  1270. package/src/store/README.md +0 -134
  1271. package/src/store/__tests__/event-store.test.ts +0 -1446
  1272. package/src/store/__tests__/instance.test.ts +0 -556
  1273. package/src/store/__tests__/migrations.test.ts +0 -109
  1274. package/src/store/backends/__tests__/memory-backend.test.ts +0 -383
  1275. package/src/store/backends/__tests__/sqlite-backend.test.ts +0 -427
  1276. package/src/store/backends/index.ts +0 -42
  1277. package/src/store/backends/json-backend.ts +0 -295
  1278. package/src/store/backends/memory-backend.ts +0 -256
  1279. package/src/store/backends/sqlite-backend.ts +0 -337
  1280. package/src/store/backends/tinybase-backend.ts +0 -276
  1281. package/src/store/backends/types.ts +0 -252
  1282. package/src/store/event-store.ts +0 -2204
  1283. package/src/store/instance.ts +0 -681
  1284. package/src/store/migrations.ts +0 -96
  1285. package/src/store/types/config.ts +0 -19
  1286. package/src/store/types/conversations.ts +0 -129
  1287. package/src/store/types/sessions.ts +0 -53
  1288. package/src/task/__tests__/retry-policy.test.ts +0 -409
  1289. package/src/task/__tests__/task-integration.test.ts +0 -457
  1290. package/src/task/__tests__/task-manager.test.ts +0 -815
  1291. package/src/task/backend/__tests__/create-task-backend.test.ts +0 -225
  1292. package/src/task/backend/__tests__/e2e/unified-tool-provider-opentasks.e2e.test.ts +0 -524
  1293. package/src/task/backend/__tests__/memory.test.ts +0 -1274
  1294. package/src/task/backend/__tests__/unified-tool-provider.test.ts +0 -579
  1295. package/src/task/backend/index.ts +0 -310
  1296. package/src/task/backend/memory.ts +0 -828
  1297. package/src/task/backend/opentasks/__tests__/backend.test.ts +0 -968
  1298. package/src/task/backend/opentasks/__tests__/daemon-manager.test.ts +0 -406
  1299. package/src/task/backend/opentasks/__tests__/mapping.test.ts +0 -84
  1300. package/src/task/backend/opentasks/__tests__/opentasks-backend.e2e.test.ts +0 -1338
  1301. package/src/task/backend/opentasks/backend.ts +0 -1323
  1302. package/src/task/backend/opentasks/client.ts +0 -652
  1303. package/src/task/backend/opentasks/daemon-manager.ts +0 -253
  1304. package/src/task/backend/opentasks/index.ts +0 -69
  1305. package/src/task/backend/opentasks/mapping.ts +0 -94
  1306. package/src/task/backend/types.ts +0 -458
  1307. package/src/task/backend/unified-tool-provider.ts +0 -779
  1308. package/src/task/index.ts +0 -7
  1309. package/src/task/retry-policy.ts +0 -204
  1310. package/src/task/task-manager.ts +0 -515
  1311. package/src/task/types.ts +0 -136
  1312. package/src/teams/__tests__/cross-subsystem.integration.test.ts +0 -983
  1313. package/src/teams/__tests__/e2e/team-runtime.e2e.test.ts +0 -553
  1314. package/src/teams/__tests__/team-system.test.ts +0 -1280
  1315. package/src/teams/team-runtime.ts +0 -729
  1316. package/src/trigger/CLAUDE.md +0 -308
  1317. package/src/trigger/README.md +0 -429
  1318. package/src/trigger/__tests__/macro-agent-regression.test.ts +0 -946
  1319. package/src/trigger/__tests__/routing-strategies.test.ts +0 -329
  1320. package/src/trigger/__tests__/trigger-router.test.ts +0 -433
  1321. package/src/trigger/__tests__/trigger-system-integration.test.ts +0 -581
  1322. package/src/trigger/router/index.ts +0 -36
  1323. package/src/trigger/router/strategies/ai-router-strategy.ts +0 -481
  1324. package/src/trigger/router/strategies/direct-strategy.ts +0 -162
  1325. package/src/trigger/router/strategies/index.ts +0 -26
  1326. package/src/trigger/router/strategies/role-strategy.ts +0 -274
  1327. package/src/trigger/router/trigger-router.ts +0 -463
  1328. package/src/trigger/router/types.ts +0 -273
  1329. package/src/trigger/trigger-system.ts +0 -206
  1330. package/src/workspace/__tests__/multi-coordinator.test.ts +0 -1005
  1331. package/src/workspace/__tests__/workspace-manager.test.ts +0 -391
  1332. package/src/workspace/__tests__/workspace.e2e.test.ts +0 -1155
  1333. package/src/workspace/merge-queue/__tests__/hierarchical-consolidation.e2e.test.ts +0 -414
  1334. package/test_fixtures/harness/__tests__/behavior-executor-and-stepper.test.ts +0 -714
  1335. package/test_fixtures/harness/__tests__/fixtures.test.ts +0 -347
  1336. package/test_fixtures/harness/__tests__/merge-queue-and-worktrees.test.ts +0 -452
  1337. package/test_fixtures/harness/__tests__/temp-repo-and-simulator.test.ts +0 -422
  1338. package/test_fixtures/harness/__tests__/test-harness-and-assertions.test.ts +0 -568
  1339. /package/{references/acp-factory-ref/python/tests/__init__.py → .opentasks/graph.jsonl} +0 -0
@@ -1,2204 +0,0 @@
1
- /**
2
- * Event Store implementation using TinyBase
3
- *
4
- * Provides an append-only event log with materialized views for:
5
- * - Agents
6
- * - Tasks
7
- * - Messages (per-agent queues)
8
- * - Subscriptions
9
- */
10
-
11
- import { createStore, Store } from 'tinybase';
12
- import { createCustomPersister, createCustomSqlitePersister } from 'tinybase/persisters';
13
- import type { DatabasePersisterConfig } from 'tinybase/persisters';
14
- import Database from 'better-sqlite3';
15
- import { nanoid } from 'nanoid';
16
- import * as path from 'path';
17
- import * as os from 'os';
18
- import * as fs from 'fs';
19
-
20
- import type {
21
- Event,
22
- EventInput,
23
- EventFilter,
24
- Agent,
25
- AgentState,
26
- AgentMetadataUpdate,
27
- Task,
28
- TaskStatus,
29
- QueuedMessage,
30
- Subscription,
31
- SubscriptionType,
32
- AgentId,
33
- TaskId,
34
- EventId,
35
- Timestamp,
36
- Conversation,
37
- ConversationTurn,
38
- ConversationThread,
39
- ConversationParticipant,
40
- ConversationFilter,
41
- TurnFilter,
42
- ConversationChangeCallback,
43
- TurnChangeCallback,
44
- ConversationType,
45
- ConversationStatus,
46
- Session,
47
- SessionState,
48
- } from './types/index.js';
49
- import { CURRENT_EVENT_VERSION } from './types/events.js';
50
- import { migrateEvent } from './migrations.js';
51
- import {
52
- type StoreConfig,
53
- type PeerVisibilityConfig,
54
- resolveInstancePath,
55
- ensureInstanceDir,
56
- createInstanceMeta,
57
- writeInstanceMeta,
58
- readInstanceMeta,
59
- touchInstance,
60
- registerInstance,
61
- DEFAULT_NAMESPACE,
62
- DEFAULT_PEER_VISIBILITY,
63
- filterEventsForPeer,
64
- } from './instance.js';
65
- import type { StorageBackend, ExportedEvent } from './backends/types.js';
66
- import { createTinyBaseBackend } from './backends/tinybase-backend.js';
67
-
68
- // ─────────────────────────────────────────────────────────────────────────────
69
- // Tabular better-sqlite3 Persister
70
- // ─────────────────────────────────────────────────────────────────────────────
71
-
72
- /**
73
- * Build tabular config for the 10 TinyBase tables.
74
- * Identity mapping: TinyBase table name === SQLite table name.
75
- */
76
- function getTabularConfig(): DatabasePersisterConfig {
77
- const tableNames = [
78
- 'events', 'agents', 'tasks', 'messages',
79
- 'sessions', 'conversations', 'turns',
80
- 'threads', 'subscriptions', 'participants',
81
- ];
82
-
83
- const load: Record<string, string> = {};
84
- const save: Record<string, string> = {};
85
- for (const t of tableNames) {
86
- load[t] = t; // SQLite table -> TinyBase table (same name)
87
- save[t] = t; // TinyBase table -> SQLite table (same name)
88
- }
89
-
90
- return {
91
- mode: 'tabular',
92
- tables: { load, save },
93
- autoLoadIntervalSeconds: 1,
94
- };
95
- }
96
-
97
- /**
98
- * Creates a tabular TinyBase persister backed by better-sqlite3.
99
- *
100
- * Unlike the old JSON blob approach (entire store as one JSON string in a
101
- * single row), tabular mode maps each TinyBase table to a real SQLite table
102
- * and only writes changed rows on autoSave — making persistence O(delta)
103
- * instead of O(total).
104
- */
105
- function createTabularBetterSqlite3Persister(
106
- store: Store,
107
- db: ReturnType<typeof Database>,
108
- ) {
109
- // Wrap better-sqlite3's sync API as the async DatabaseExecuteCommand.
110
- // TinyBase generates SQL with $1, $2, ... placeholders (PostgreSQL-style),
111
- // but better-sqlite3 uses ? for positional array binding. Convert them.
112
- const executeCommand = async (sql: string, params?: any[]): Promise<Record<string, any>[]> => {
113
- const convertedSql = sql.replace(/\$\d+/g, '?');
114
- const trimmed = convertedSql.trimStart().toUpperCase();
115
- const stmt = db.prepare(convertedSql);
116
- if (trimmed.startsWith('SELECT') || trimmed.startsWith('PRAGMA')) {
117
- return (params ? stmt.all(...params) : stmt.all()) as Record<string, any>[];
118
- }
119
- params ? stmt.run(...params) : stmt.run();
120
- return [];
121
- };
122
-
123
- return createCustomSqlitePersister(
124
- store,
125
- getTabularConfig(),
126
- executeCommand,
127
- // addChangeListener — better-sqlite3 has no native change events
128
- (_listener: (tableName: string) => void) => null as any,
129
- // delChangeListener — no-op
130
- (_handle: any) => {},
131
- // onSqlCommand
132
- undefined,
133
- // onIgnoredError
134
- (error: any) => console.warn('[EventStore] Persister error:', error),
135
- // destroy — do NOT close DB here; close() handles it after the persister drains
136
- () => {},
137
- // persist mode (1 = StoreOnly)
138
- 1 as any,
139
- // thing (the db instance)
140
- db,
141
- // getThing accessor name
142
- 'getDb',
143
- );
144
- }
145
-
146
- // View change callback types
147
- export type AgentChangeCallback = (agentId: AgentId, agent: Agent | null) => void;
148
- export type TaskChangeCallback = (taskId: TaskId, task: Task | null) => void;
149
- export type MessageCallback = (agentId: AgentId, messages: QueuedMessage[]) => void;
150
- export type SessionChangeCallback = (sessionId: string, session: Session | null) => void;
151
-
152
- // Unsubscribe function type
153
- export type Unsubscribe = () => void;
154
-
155
- // Archive-related types
156
- export interface ArchiveOptions {
157
- olderThan?: string; // "7d", "30d"
158
- before?: Timestamp;
159
- }
160
-
161
- export interface ArchiveResult {
162
- archivedCount: number;
163
- archivePath: string;
164
- oldestRetained: Timestamp;
165
- }
166
-
167
- export interface ArchiveInfo {
168
- archives: Array<{ path: string; from: Timestamp; to: Timestamp; eventCount: number }>;
169
- totalArchivedEvents: number;
170
- }
171
-
172
- interface ArchiveManifest {
173
- version: number;
174
- archives: Array<{ path: string; from: Timestamp; to: Timestamp; eventCount: number }>;
175
- }
176
-
177
- interface LoadArchiveOptions {
178
- from?: Timestamp;
179
- to?: Timestamp;
180
- }
181
-
182
- /**
183
- * Event Store interface
184
- */
185
- export interface EventStore {
186
- // ─── Instance Info ───
187
- /** Instance identifier */
188
- readonly instanceId: string;
189
- /** Namespace for discovery */
190
- readonly namespace: string;
191
- /** Path to instance directory (or ':memory:') */
192
- readonly instancePath: string;
193
- /** Base directory for all storage */
194
- readonly baseDir: string;
195
- /** Backend type being used */
196
- readonly backendType: string;
197
- /** Peer visibility configuration */
198
- readonly peerVisibility: import('./instance.js').PeerVisibilityConfig;
199
-
200
- // Event operations
201
- emit(event: EventInput): Event;
202
- query(filter?: EventFilter): Event[];
203
-
204
- // Agent view
205
- getAgent(agentId: AgentId): Agent | null;
206
- listAgents(filter?: { state?: AgentState; parent?: AgentId | null }): Agent[];
207
- updateAgentPlan(agentId: AgentId, plan: Array<{ content: string; priority: string; status: string }>): void;
208
- updateAgentMetadata(agentId: AgentId, updates: AgentMetadataUpdate): void;
209
-
210
- // Task view
211
- getTask(taskId: TaskId): Task | null;
212
- listTasks(filter?: { status?: TaskStatus; assigned_agent?: AgentId }): Task[];
213
-
214
- // Message queue
215
- getMessages(agentId: AgentId, limit?: number): QueuedMessage[];
216
- getFullMessage(messageId: EventId): string | null;
217
-
218
- // Subscriptions
219
- addSubscription(agentId: AgentId, subscription: Subscription): void;
220
- removeSubscription(agentId: AgentId, subscription: Subscription): void;
221
- getSubscriptions(agentId: AgentId): Subscription[];
222
- getSubscribers(subscription: Subscription): AgentId[];
223
-
224
- // Session views
225
- getSession(sessionId: string): Session | null;
226
- listSessions(filter?: { state?: SessionState; agent_id?: AgentId }): Session[];
227
-
228
- // Conversation views
229
- getConversation(conversationId: string): Conversation | null;
230
- listConversations(filter?: ConversationFilter): Conversation[];
231
- listTurns(filter: TurnFilter): ConversationTurn[];
232
- listParticipants(conversationId: string, active?: boolean): ConversationParticipant[];
233
-
234
- // Reactive updates
235
- onAgentChange(callback: AgentChangeCallback): Unsubscribe;
236
- onAgentChange(agentId: AgentId, callback: AgentChangeCallback): Unsubscribe;
237
- onTaskChange(callback: TaskChangeCallback): Unsubscribe;
238
- onMessageChange(agentId: AgentId, callback: MessageCallback): Unsubscribe;
239
- onSessionChange(callback: SessionChangeCallback): Unsubscribe;
240
- onConversationChange(callback: ConversationChangeCallback): Unsubscribe;
241
- onTurnChange(callback: TurnChangeCallback): Unsubscribe;
242
-
243
- // Lifecycle
244
- persist(): Promise<void>;
245
- reload(): Promise<void>;
246
- close(): Promise<void>;
247
-
248
- // Archival
249
- archive(options?: ArchiveOptions): Promise<ArchiveResult>;
250
- loadArchive(options?: LoadArchiveOptions): Promise<Event[]>;
251
- getArchiveInfo(): Promise<ArchiveInfo>;
252
-
253
- // ─── Export/Import (for sync) ───
254
- /**
255
- * Export events for peer sync.
256
- * @param filter Optional event filter
257
- * @param options Export options
258
- * @param options.forPeer If true, filter by peerVisibility config
259
- */
260
- exportEvents(filter?: EventFilter, options?: { forPeer?: boolean }): ExportedEvent[];
261
- /** Import events from peer */
262
- importEvents(events: ExportedEvent[]): void;
263
-
264
- // ─── Advanced ───
265
- /**
266
- * Get underlying storage backend (for advanced use).
267
- * Returns a StorageBackend wrapper around the internal TinyBase store.
268
- */
269
- getBackend(): import('./backends/types.js').StorageBackend;
270
- }
271
-
272
- /**
273
- * Parse a duration string (e.g., "30d", "7d") to milliseconds
274
- */
275
- export function parseDuration(duration: string): number {
276
- const match = duration.match(/^(\d+)([dhms])$/);
277
- if (!match) {
278
- throw new Error(`Invalid duration format: "${duration}". Use format like "30d", "7d", "24h", "60m", "30s".`);
279
- }
280
-
281
- const value = parseInt(match[1], 10);
282
- const unit = match[2];
283
-
284
- const multipliers: Record<string, number> = {
285
- s: 1000,
286
- m: 60 * 1000,
287
- h: 60 * 60 * 1000,
288
- d: 24 * 60 * 60 * 1000,
289
- };
290
-
291
- return value * multipliers[unit];
292
- }
293
-
294
- /**
295
- * Create an Event Store instance
296
- */
297
- export async function createEventStore(config: StoreConfig = {}): Promise<EventStore> {
298
- // Resolve instance configuration
299
- const resolved = resolveInstancePath(config);
300
- const { instanceId, instancePath, namespace, isNew, backendType } = resolved;
301
-
302
- // Reject deprecated legacy path option
303
- if (config.path) {
304
- throw new Error(
305
- '[macro-agent] The `path` option has been removed. ' +
306
- 'Use `instanceId` and `baseDir` instead for per-instance isolation.'
307
- );
308
- }
309
-
310
- // Track baseDir for MCP subprocess communication
311
- const baseDir = config.baseDir ?? path.join(os.homedir(), '.multiagent');
312
-
313
- // Get peer visibility config (default is restrictive)
314
- const peerVisibility: PeerVisibilityConfig =
315
- config.peerVisibility ?? DEFAULT_PEER_VISIBILITY;
316
-
317
- // Emit warning for in-memory mode (only in non-test environments)
318
- if (config.inMemory && process.env.NODE_ENV !== 'test') {
319
- console.warn(
320
- '[macro-agent] WARNING: Using in-memory EventStore. MCP tools (done, spawn_agent, etc.) will not work ' +
321
- 'because MCP servers run as separate subprocesses that cannot access in-memory data. ' +
322
- 'Use file-based storage (remove inMemory option) for real agent workflows.'
323
- );
324
- }
325
-
326
- const store = createStore();
327
-
328
- // Set up persister based on backend type
329
- let persister: ReturnType<typeof createTabularBetterSqlite3Persister> | null = null;
330
- let db: ReturnType<typeof Database> | null = null;
331
-
332
- if (!config.inMemory) {
333
- ensureInstanceDir(instancePath);
334
- const dbPath = path.join(instancePath, 'store.sqlite');
335
- db = new Database(dbPath);
336
- db.pragma('journal_mode = WAL');
337
- db.pragma('busy_timeout = 5000');
338
-
339
- // Migration: if old JSON blob table exists, load data from it first
340
- const oldTableExists = db.prepare(
341
- "SELECT name FROM sqlite_master WHERE type='table' AND name='tinybase_store'"
342
- ).get();
343
-
344
- if (oldTableExists) {
345
- const oldPersister = createCustomPersister(
346
- store,
347
- async () => {
348
- const row = db!.prepare("SELECT store FROM tinybase_store WHERE _id = '_'").get() as { store: string } | undefined;
349
- return row ? JSON.parse(row.store) : undefined;
350
- },
351
- async () => {},
352
- (listener) => setInterval(listener, 1000),
353
- (interval: ReturnType<typeof setInterval>) => clearInterval(interval),
354
- );
355
- await oldPersister.load();
356
- oldPersister.destroy();
357
- }
358
-
359
- persister = createTabularBetterSqlite3Persister(store, db);
360
-
361
- if (oldTableExists) {
362
- // Save migrated data to new tabular format, then drop old table
363
- await persister.save();
364
- db.exec('DROP TABLE IF EXISTS tinybase_store');
365
- }
366
-
367
- await persister.load();
368
- // Auto-save: persist to disk whenever the in-memory store changes.
369
- // Without this, emit() only writes to TinyBase's in-memory store and
370
- // data is lost if the server is killed before an explicit persist().
371
- await persister.startAutoSave();
372
- }
373
-
374
- // Initialize/update instance metadata
375
- if (!config.inMemory) {
376
- if (isNew) {
377
- const meta = createInstanceMeta(resolved, config);
378
- writeInstanceMeta(instancePath, meta);
379
- } else {
380
- touchInstance(instancePath);
381
- }
382
-
383
- // Register in namespace for discovery
384
- registerInstance(
385
- config.baseDir ?? path.join(os.homedir(), '.multiagent'),
386
- namespace,
387
- instanceId,
388
- { label: config.label }
389
- );
390
- }
391
-
392
- // Initialize tables if they don't exist
393
- initializeTables(store);
394
-
395
- // Rebuild materialized views from events
396
- rebuildViews(store);
397
-
398
- // Listener registries
399
- const agentListeners = new Set<AgentChangeCallback>();
400
- const agentIdListeners = new Map<AgentId, Set<AgentChangeCallback>>();
401
- const taskListeners = new Set<TaskChangeCallback>();
402
- const sessionListeners = new Set<SessionChangeCallback>();
403
- const messageListeners = new Map<AgentId, Set<MessageCallback>>();
404
- const conversationListeners = new Set<ConversationChangeCallback>();
405
- const turnListeners = new Set<TurnChangeCallback>();
406
-
407
- /**
408
- * Emit a new event to the store
409
- */
410
- function emit(input: EventInput): Event {
411
- const event: Event = {
412
- ...input,
413
- id: `evt_${nanoid(12)}`,
414
- version: CURRENT_EVENT_VERSION,
415
- timestamp: Date.now(),
416
- };
417
-
418
- // Store the event
419
- // Note: Use empty object for undefined source to avoid JSON.parse errors in query
420
- store.setRow('events', event.id, {
421
- id: event.id,
422
- version: event.version,
423
- timestamp: event.timestamp,
424
- type: event.type,
425
- source: JSON.stringify(event.source ?? {}),
426
- target: event.target ? JSON.stringify(event.target) : '',
427
- payload: JSON.stringify(event.payload),
428
- metadata: event.metadata ? JSON.stringify(event.metadata) : '',
429
- });
430
-
431
- // Update materialized views
432
- applyEventToViews(store, event, notifyAgentChange, notifyTaskChange, notifyMessageChange, notifySessionChange, notifyConversationChange, notifyTurnChange);
433
-
434
- return event;
435
- }
436
-
437
- /**
438
- * Query events with filters
439
- */
440
- function query(filter?: EventFilter): Event[] {
441
- const events: Event[] = [];
442
- const rowIds = store.getRowIds('events');
443
-
444
- for (const rowId of rowIds) {
445
- const row = store.getRow('events', rowId);
446
- if (!row.id) continue;
447
-
448
- // Parse raw event data
449
- // Handle legacy data where source might be stored as "undefined" string
450
- const sourceStr = row.source as string;
451
- const parsedSource = sourceStr && sourceStr !== 'undefined'
452
- ? JSON.parse(sourceStr)
453
- : {};
454
-
455
- const rawEvent = {
456
- id: row.id as string,
457
- version: row.version as number | undefined,
458
- timestamp: row.timestamp as number,
459
- type: row.type as string,
460
- source: parsedSource,
461
- target: row.target ? JSON.parse(row.target as string) : undefined,
462
- payload: JSON.parse(row.payload as string),
463
- metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,
464
- };
465
-
466
- // Migrate event to current version if needed
467
- const event = migrateEvent(rawEvent);
468
-
469
- // Apply filters
470
- if (filter) {
471
- if (filter.type && event.type !== filter.type) continue;
472
- if (filter.source_agent_id && event.source.agent_id !== filter.source_agent_id) continue;
473
- if (filter.target_agent_id && event.target?.agent_id !== filter.target_agent_id) continue;
474
- if (filter.after && event.timestamp <= filter.after) continue;
475
- if (filter.before && event.timestamp >= filter.before) continue;
476
- }
477
-
478
- events.push(event);
479
- }
480
-
481
- // Sort by timestamp
482
- events.sort((a, b) => a.timestamp - b.timestamp);
483
-
484
- // Apply limit
485
- if (filter?.limit) {
486
- return events.slice(0, filter.limit);
487
- }
488
-
489
- return events;
490
- }
491
-
492
- /**
493
- * Get agent by ID
494
- */
495
- function getAgent(agentId: AgentId): Agent | null {
496
- const row = store.getRow('agents', agentId);
497
- if (!row.id) return null;
498
- return rowToAgent(row);
499
- }
500
-
501
- /**
502
- * List agents with optional filter
503
- */
504
- function listAgents(filter?: { state?: AgentState; parent?: AgentId | null }): Agent[] {
505
- const agents: Agent[] = [];
506
- const rowIds = store.getRowIds('agents');
507
-
508
- for (const rowId of rowIds) {
509
- const row = store.getRow('agents', rowId);
510
- if (!row.id) continue;
511
-
512
- const agent = rowToAgent(row);
513
-
514
- if (filter) {
515
- if (filter.state && agent.state !== filter.state) continue;
516
- if (filter.parent !== undefined && agent.parent !== filter.parent) continue;
517
- }
518
-
519
- agents.push(agent);
520
- }
521
-
522
- return agents;
523
- }
524
-
525
- /**
526
- * Update agent metadata fields (name, plan, metadata).
527
- * Only provided fields are updated. Metadata is shallow-merged with existing.
528
- */
529
- function updateAgentMetadata(
530
- agentId: AgentId,
531
- updates: AgentMetadataUpdate,
532
- ): void {
533
- const row = store.getRow('agents', agentId);
534
- if (!row.id) return;
535
-
536
- const partial: Record<string, string | number | boolean> = {
537
- last_activity_at: Date.now(),
538
- };
539
-
540
- if (updates.name !== undefined) {
541
- partial.name = updates.name;
542
- }
543
- if (updates.plan !== undefined) {
544
- partial.plan = JSON.stringify(updates.plan);
545
- }
546
- if (updates.metadata !== undefined) {
547
- // Shallow merge with existing metadata
548
- const existing = row.metadata ? JSON.parse(row.metadata as string) : {};
549
- partial.metadata = JSON.stringify({ ...existing, ...updates.metadata });
550
- }
551
-
552
- store.setPartialRow('agents', agentId, partial);
553
-
554
- const agent = rowToAgent(store.getRow('agents', agentId));
555
- notifyAgentChange(agentId, agent);
556
- }
557
-
558
- /**
559
- * Update an agent's plan entries (persisted to SQLite via TinyBase).
560
- * Convenience wrapper around updateAgentMetadata.
561
- */
562
- function updateAgentPlan(
563
- agentId: AgentId,
564
- plan: Array<{ content: string; priority: string; status: string }>,
565
- ): void {
566
- updateAgentMetadata(agentId, { plan });
567
- }
568
-
569
-
570
- /**
571
- * Get task by ID
572
- */
573
- function getTask(taskId: TaskId): Task | null {
574
- const row = store.getRow('tasks', taskId);
575
- if (!row.id) return null;
576
- return rowToTask(row);
577
- }
578
-
579
- /**
580
- * List tasks with optional filter
581
- */
582
- function listTasks(filter?: { status?: TaskStatus; assigned_agent?: AgentId }): Task[] {
583
- const tasks: Task[] = [];
584
- const rowIds = store.getRowIds('tasks');
585
-
586
- for (const rowId of rowIds) {
587
- const row = store.getRow('tasks', rowId);
588
- if (!row.id) continue;
589
-
590
- const task = rowToTask(row);
591
-
592
- if (filter) {
593
- if (filter.status && task.status !== filter.status) continue;
594
- if (filter.assigned_agent && task.assigned_agent !== filter.assigned_agent) continue;
595
- }
596
-
597
- tasks.push(task);
598
- }
599
-
600
- return tasks;
601
- }
602
-
603
- /**
604
- * Get pending messages for an agent
605
- */
606
- function getMessages(agentId: AgentId, limit?: number): QueuedMessage[] {
607
- const messages: QueuedMessage[] = [];
608
- const rowIds = store.getRowIds('messages');
609
-
610
- for (const rowId of rowIds) {
611
- const row = store.getRow('messages', rowId);
612
- if (!row.id || row.recipient !== agentId) continue;
613
-
614
- messages.push({
615
- id: row.id as string,
616
- from: JSON.parse(row.from as string),
617
- content: row.content as string,
618
- timestamp: row.timestamp as number,
619
- truncated: row.truncated as boolean,
620
- correlation_id: row.correlation_id as string | undefined,
621
- });
622
- }
623
-
624
- // Sort by timestamp
625
- messages.sort((a, b) => a.timestamp - b.timestamp);
626
-
627
- if (limit) {
628
- return messages.slice(0, limit);
629
- }
630
-
631
- return messages;
632
- }
633
-
634
- /**
635
- * Get full message content by ID
636
- */
637
- function getFullMessage(messageId: EventId): string | null {
638
- // Look up the original event
639
- const row = store.getRow('events', messageId);
640
- if (!row.id || row.type !== 'message') return null;
641
-
642
- const payload = JSON.parse(row.payload as string);
643
- return payload.content ?? null;
644
- }
645
-
646
- /**
647
- * Add a subscription for an agent
648
- */
649
- function addSubscription(agentId: AgentId, subscription: Subscription): void {
650
- const subId = `${agentId}:${subscription.type}:${subscription.target}`;
651
- store.setRow('subscriptions', subId, {
652
- id: subId,
653
- agent_id: agentId,
654
- type: subscription.type,
655
- target: subscription.target,
656
- });
657
- }
658
-
659
- /**
660
- * Remove a subscription for an agent
661
- */
662
- function removeSubscription(agentId: AgentId, subscription: Subscription): void {
663
- const subId = `${agentId}:${subscription.type}:${subscription.target}`;
664
- store.delRow('subscriptions', subId);
665
- }
666
-
667
- /**
668
- * Get all subscriptions for an agent
669
- */
670
- function getSubscriptions(agentId: AgentId): Subscription[] {
671
- const subscriptions: Subscription[] = [];
672
- const rowIds = store.getRowIds('subscriptions');
673
-
674
- for (const rowId of rowIds) {
675
- const row = store.getRow('subscriptions', rowId);
676
- if (row.agent_id !== agentId) continue;
677
-
678
- subscriptions.push({
679
- type: row.type as SubscriptionType,
680
- target: row.target as string,
681
- });
682
- }
683
-
684
- return subscriptions;
685
- }
686
-
687
- /**
688
- * Get all agents subscribed to a given subscription
689
- */
690
- function getSubscribers(subscription: Subscription): AgentId[] {
691
- const subscribers: AgentId[] = [];
692
- const rowIds = store.getRowIds('subscriptions');
693
-
694
- for (const rowId of rowIds) {
695
- const row = store.getRow('subscriptions', rowId);
696
- if (row.type !== subscription.type || row.target !== subscription.target) continue;
697
-
698
- subscribers.push(row.agent_id as AgentId);
699
- }
700
-
701
- return subscribers;
702
- }
703
-
704
- /**
705
- * Notify agent change listeners
706
- */
707
- function notifyAgentChange(agentId: AgentId, agent: Agent | null): void {
708
- // Global listeners
709
- for (const callback of agentListeners) {
710
- callback(agentId, agent);
711
- }
712
-
713
- // Specific agent listeners
714
- const specificListeners = agentIdListeners.get(agentId);
715
- if (specificListeners) {
716
- for (const callback of specificListeners) {
717
- callback(agentId, agent);
718
- }
719
- }
720
- }
721
-
722
- /**
723
- * Notify task change listeners
724
- */
725
- function notifyTaskChange(taskId: TaskId, task: Task | null): void {
726
- for (const callback of taskListeners) {
727
- callback(taskId, task);
728
- }
729
- }
730
-
731
- /**
732
- * Notify message change listeners
733
- */
734
- function notifyMessageChange(agentId: AgentId): void {
735
- const listeners = messageListeners.get(agentId);
736
- if (listeners) {
737
- const messages = getMessages(agentId);
738
- for (const callback of listeners) {
739
- callback(agentId, messages);
740
- }
741
- }
742
- }
743
-
744
- /**
745
- * Subscribe to agent changes (all agents or specific agent)
746
- */
747
- function onAgentChange(callbackOrId: AgentChangeCallback | AgentId, callback?: AgentChangeCallback): Unsubscribe {
748
- if (typeof callbackOrId === 'function') {
749
- // Global subscription
750
- agentListeners.add(callbackOrId);
751
- return () => agentListeners.delete(callbackOrId);
752
- } else {
753
- // Specific agent subscription
754
- const agentId = callbackOrId;
755
- const cb = callback!;
756
- if (!agentIdListeners.has(agentId)) {
757
- agentIdListeners.set(agentId, new Set());
758
- }
759
- agentIdListeners.get(agentId)!.add(cb);
760
- return () => agentIdListeners.get(agentId)?.delete(cb);
761
- }
762
- }
763
-
764
- /**
765
- * Subscribe to task changes
766
- */
767
- function onTaskChange(callback: TaskChangeCallback): Unsubscribe {
768
- taskListeners.add(callback);
769
- return () => taskListeners.delete(callback);
770
- }
771
-
772
- /**
773
- * Subscribe to message changes for an agent
774
- */
775
- function onMessageChange(agentId: AgentId, callback: MessageCallback): Unsubscribe {
776
- if (!messageListeners.has(agentId)) {
777
- messageListeners.set(agentId, new Set());
778
- }
779
- messageListeners.get(agentId)!.add(callback);
780
- return () => messageListeners.get(agentId)?.delete(callback);
781
- }
782
-
783
- /**
784
- * Notify conversation change listeners
785
- */
786
- function notifyConversationChange(conversationId: string, conversation: Conversation | null): void {
787
- for (const callback of conversationListeners) {
788
- callback(conversationId, conversation);
789
- }
790
- }
791
-
792
- /**
793
- * Notify turn change listeners
794
- */
795
- function notifyTurnChange(conversationId: string, turn: ConversationTurn): void {
796
- for (const callback of turnListeners) {
797
- callback(conversationId, turn);
798
- }
799
- }
800
-
801
- /**
802
- * Subscribe to conversation changes
803
- */
804
- function onConversationChange(callback: ConversationChangeCallback): Unsubscribe {
805
- conversationListeners.add(callback);
806
- return () => conversationListeners.delete(callback);
807
- }
808
-
809
- /**
810
- * Subscribe to turn changes
811
- */
812
- function onTurnChange(callback: TurnChangeCallback): Unsubscribe {
813
- turnListeners.add(callback);
814
- return () => turnListeners.delete(callback);
815
- }
816
-
817
- // ─── Session View Queries ───
818
-
819
- function getSession(sessionId: string): Session | null {
820
- const row = store.getRow('sessions', sessionId);
821
- if (!row.id) return null;
822
- return rowToSession(row);
823
- }
824
-
825
- function listSessions(filter?: { state?: SessionState; agent_id?: AgentId }): Session[] {
826
- const sessions: Session[] = [];
827
- const rowIds = store.getRowIds('sessions');
828
-
829
- for (const rowId of rowIds) {
830
- const row = store.getRow('sessions', rowId);
831
- if (!row.id) continue;
832
-
833
- const session = rowToSession(row);
834
-
835
- if (filter) {
836
- if (filter.state && session.state !== filter.state) continue;
837
- if (filter.agent_id && session.current_agent_id !== filter.agent_id && session.head_manager_id !== filter.agent_id) continue;
838
- }
839
-
840
- sessions.push(session);
841
- }
842
-
843
- return sessions;
844
- }
845
-
846
- /**
847
- * Notify session change listeners
848
- */
849
- function notifySessionChange(sessionId: string, session: Session | null): void {
850
- for (const callback of sessionListeners) {
851
- callback(sessionId, session);
852
- }
853
- }
854
-
855
- /**
856
- * Subscribe to session changes
857
- */
858
- function onSessionChange(callback: SessionChangeCallback): Unsubscribe {
859
- sessionListeners.add(callback);
860
- return () => sessionListeners.delete(callback);
861
- }
862
-
863
- // ─── Conversation View Queries ───
864
-
865
- function getConversation(conversationId: string): Conversation | null {
866
- const row = store.getRow('conversations', conversationId);
867
- if (!row.id) return null;
868
- return rowToConversation(row);
869
- }
870
-
871
- function listConversations(filter?: ConversationFilter): Conversation[] {
872
- const conversations: Conversation[] = [];
873
- const rowIds = store.getRowIds('conversations');
874
-
875
- for (const rowId of rowIds) {
876
- const row = store.getRow('conversations', rowId);
877
- if (!row.id) continue;
878
-
879
- const conversation = rowToConversation(row);
880
-
881
- if (filter) {
882
- if (filter.type && conversation.type !== filter.type) continue;
883
- if (filter.status && conversation.status !== filter.status) continue;
884
- if (filter.parentConversationId && conversation.parentConversationId !== filter.parentConversationId) continue;
885
- if (filter.participantId) {
886
- // Check participants table for membership
887
- const partRow = store.getRow('participants', `${conversation.id}:${filter.participantId}`);
888
- if (!partRow.id) continue;
889
- // Skip if participant has left
890
- if (partRow.left_at && (partRow.left_at as number) > 0) continue;
891
- }
892
- }
893
-
894
- conversations.push(conversation);
895
- }
896
-
897
- return conversations;
898
- }
899
-
900
- function listTurns(filter: TurnFilter): ConversationTurn[] {
901
- const turns: ConversationTurn[] = [];
902
- const rowIds = store.getRowIds('turns');
903
-
904
- for (const rowId of rowIds) {
905
- const row = store.getRow('turns', rowId);
906
- if (!row.id) continue;
907
-
908
- const turn = rowToTurn(row);
909
-
910
- // Filter by conversation (required)
911
- if (turn.conversationId !== filter.conversationId) continue;
912
-
913
- // Optional filters
914
- if (filter.threadId && turn.threadId !== filter.threadId) continue;
915
- if (filter.contentType && turn.contentType !== filter.contentType) continue;
916
- if (filter.participantId && turn.participant !== filter.participantId) continue;
917
-
918
- turns.push(turn);
919
- }
920
-
921
- // Sort
922
- const order = filter.order ?? 'asc';
923
- turns.sort((a, b) => order === 'asc' ? a.timestamp - b.timestamp : b.timestamp - a.timestamp);
924
-
925
- // Limit
926
- if (filter.limit) {
927
- return turns.slice(0, filter.limit);
928
- }
929
-
930
- return turns;
931
- }
932
-
933
- function listParticipants(conversationId: string, active?: boolean): ConversationParticipant[] {
934
- const participants: ConversationParticipant[] = [];
935
- const rowIds = store.getRowIds('participants');
936
-
937
- for (const rowId of rowIds) {
938
- const row = store.getRow('participants', rowId);
939
- if (!row.id) continue;
940
-
941
- if (row.conversation_id !== conversationId) continue;
942
-
943
- const participant = rowToParticipant(row);
944
-
945
- if (active && participant.leftAt) continue;
946
-
947
- participants.push(participant);
948
- }
949
-
950
- return participants;
951
- }
952
-
953
- /**
954
- * Persist store to disk
955
- */
956
- async function persist(): Promise<void> {
957
- if (persister) {
958
- await persister.save();
959
- }
960
- }
961
-
962
- /**
963
- * Reload store from disk (refresh data from SQLite)
964
- */
965
- async function reload(): Promise<void> {
966
- if (persister) {
967
- await persister.load();
968
- // Rebuild materialized views from freshly loaded events
969
- rebuildViews(store);
970
- }
971
- }
972
-
973
- /**
974
- * Close the store
975
- */
976
- async function close(): Promise<void> {
977
- if (persister) {
978
- // Stop auto-save first to prevent race conditions between
979
- // auto-save callbacks and the explicit save/destroy sequence.
980
- await persister.stopAutoSave();
981
- await persister.save();
982
- // Destroy the persister (removes store listeners) BEFORE closing the DB.
983
- // The destroy callback is a no-op — we close the DB ourselves below
984
- // after giving TinyBase's internal async queues time to drain.
985
- persister.destroy();
986
- // Allow any in-flight TinyBase microtasks to settle before closing
987
- // the database connection. Without this, pending writes from store
988
- // change listeners can race against db.close().
989
- await new Promise(resolve => setTimeout(resolve, 50));
990
- }
991
- if (db) {
992
- db.close();
993
- }
994
- }
995
-
996
- /**
997
- * Get archives directory path
998
- */
999
- function getArchivesDir(): string {
1000
- return path.join(instancePath, 'archives');
1001
- }
1002
-
1003
- /**
1004
- * Get manifest file path
1005
- */
1006
- function getManifestPath(): string {
1007
- return path.join(getArchivesDir(), 'manifest.json');
1008
- }
1009
-
1010
- /**
1011
- * Read archive manifest
1012
- */
1013
- function readManifest(): ArchiveManifest {
1014
- const manifestPath = getManifestPath();
1015
- if (fs.existsSync(manifestPath)) {
1016
- return JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
1017
- }
1018
- return { version: 1, archives: [] };
1019
- }
1020
-
1021
- /**
1022
- * Write archive manifest
1023
- */
1024
- function writeManifest(manifest: ArchiveManifest): void {
1025
- const manifestPath = getManifestPath();
1026
- fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
1027
- }
1028
-
1029
- /**
1030
- * Archive old events to prevent unbounded store growth
1031
- */
1032
- async function archive(options: ArchiveOptions = {}): Promise<ArchiveResult> {
1033
- // Calculate cutoff timestamp
1034
- let cutoff: Timestamp;
1035
- if (options.before !== undefined) {
1036
- cutoff = options.before;
1037
- } else if (options.olderThan) {
1038
- cutoff = Date.now() - parseDuration(options.olderThan);
1039
- } else {
1040
- // Default to 30 days
1041
- cutoff = Date.now() - parseDuration('30d');
1042
- }
1043
-
1044
- // Query events older than cutoff
1045
- const allEvents = query();
1046
- const eventsToArchive = allEvents.filter((e) => e.timestamp < cutoff);
1047
- const eventsToRetain = allEvents.filter((e) => e.timestamp >= cutoff);
1048
-
1049
- if (eventsToArchive.length === 0) {
1050
- return {
1051
- archivedCount: 0,
1052
- archivePath: '',
1053
- oldestRetained: eventsToRetain.length > 0 ? eventsToRetain[0].timestamp : Date.now(),
1054
- };
1055
- }
1056
-
1057
- // Ensure archives directory exists
1058
- const archivesDir = getArchivesDir();
1059
- if (!fs.existsSync(archivesDir)) {
1060
- fs.mkdirSync(archivesDir, { recursive: true });
1061
- }
1062
-
1063
- // Group events by month
1064
- const eventsByMonth = new Map<string, Event[]>();
1065
- for (const event of eventsToArchive) {
1066
- const date = new Date(event.timestamp);
1067
- const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
1068
- if (!eventsByMonth.has(monthKey)) {
1069
- eventsByMonth.set(monthKey, []);
1070
- }
1071
- eventsByMonth.get(monthKey)!.push(event);
1072
- }
1073
-
1074
- // Read existing manifest
1075
- const manifest = readManifest();
1076
-
1077
- // Write archive files and update manifest
1078
- let lastArchivePath = '';
1079
- for (const [monthKey, monthEvents] of eventsByMonth) {
1080
- const archivePath = path.join(archivesDir, `${monthKey}.json`);
1081
- lastArchivePath = archivePath;
1082
-
1083
- // Read existing archive if it exists and merge
1084
- let existingEvents: Event[] = [];
1085
- if (fs.existsSync(archivePath)) {
1086
- existingEvents = JSON.parse(fs.readFileSync(archivePath, 'utf-8'));
1087
- }
1088
-
1089
- // Merge and deduplicate by event ID
1090
- const mergedEvents = [...existingEvents, ...monthEvents];
1091
- const uniqueEvents = Array.from(new Map(mergedEvents.map((e) => [e.id, e])).values());
1092
- uniqueEvents.sort((a, b) => a.timestamp - b.timestamp);
1093
-
1094
- // Write archive file
1095
- fs.writeFileSync(archivePath, JSON.stringify(uniqueEvents, null, 2));
1096
-
1097
- // Update manifest entry
1098
- const existingIndex = manifest.archives.findIndex((a) => a.path === archivePath);
1099
- const archiveEntry = {
1100
- path: archivePath,
1101
- from: uniqueEvents[0].timestamp,
1102
- to: uniqueEvents[uniqueEvents.length - 1].timestamp,
1103
- eventCount: uniqueEvents.length,
1104
- };
1105
-
1106
- if (existingIndex >= 0) {
1107
- manifest.archives[existingIndex] = archiveEntry;
1108
- } else {
1109
- manifest.archives.push(archiveEntry);
1110
- }
1111
- }
1112
-
1113
- // Sort manifest archives by date
1114
- manifest.archives.sort((a, b) => a.from - b.from);
1115
-
1116
- // Write updated manifest
1117
- writeManifest(manifest);
1118
-
1119
- // Remove archived events from active store
1120
- for (const event of eventsToArchive) {
1121
- store.delRow('events', event.id);
1122
- }
1123
-
1124
- // Persist the updated store
1125
- await persist();
1126
-
1127
- return {
1128
- archivedCount: eventsToArchive.length,
1129
- archivePath: lastArchivePath,
1130
- oldestRetained: eventsToRetain.length > 0 ? eventsToRetain[0].timestamp : Date.now(),
1131
- };
1132
- }
1133
-
1134
- /**
1135
- * Load archived events by date range
1136
- */
1137
- async function loadArchive(options: LoadArchiveOptions = {}): Promise<Event[]> {
1138
- const manifest = readManifest();
1139
- const events: Event[] = [];
1140
-
1141
- for (const archive of manifest.archives) {
1142
- // Skip archives outside the requested range
1143
- if (options.from !== undefined && archive.to < options.from) continue;
1144
- if (options.to !== undefined && archive.from > options.to) continue;
1145
-
1146
- // Read archive file
1147
- if (!fs.existsSync(archive.path)) continue;
1148
- const archiveEvents: Event[] = JSON.parse(fs.readFileSync(archive.path, 'utf-8'));
1149
-
1150
- // Filter by date range
1151
- for (const event of archiveEvents) {
1152
- if (options.from !== undefined && event.timestamp < options.from) continue;
1153
- if (options.to !== undefined && event.timestamp > options.to) continue;
1154
- events.push(event);
1155
- }
1156
- }
1157
-
1158
- // Sort by timestamp
1159
- events.sort((a, b) => a.timestamp - b.timestamp);
1160
-
1161
- return events;
1162
- }
1163
-
1164
- /**
1165
- * Get information about available archives
1166
- */
1167
- async function getArchiveInfo(): Promise<ArchiveInfo> {
1168
- const manifest = readManifest();
1169
- const totalArchivedEvents = manifest.archives.reduce((sum, a) => sum + a.eventCount, 0);
1170
-
1171
- return {
1172
- archives: manifest.archives,
1173
- totalArchivedEvents,
1174
- };
1175
- }
1176
-
1177
- /**
1178
- * Export events for peer sync
1179
- * @param filter Optional event filter
1180
- * @param options Export options
1181
- * @param options.forPeer If true, filter by peerVisibility config
1182
- */
1183
- function exportEvents(
1184
- filter?: EventFilter,
1185
- options?: { forPeer?: boolean }
1186
- ): ExportedEvent[] {
1187
- let events = query(filter);
1188
-
1189
- // If exporting for peer, apply visibility filter
1190
- if (options?.forPeer) {
1191
- events = filterEventsForPeer(events, peerVisibility);
1192
- }
1193
-
1194
- return events.map((event) => ({
1195
- ...event,
1196
- sourceInstance: instanceId,
1197
- }));
1198
- }
1199
-
1200
- /**
1201
- * Import events from peer
1202
- */
1203
- function importEvents(events: ExportedEvent[]): void {
1204
- for (const event of events) {
1205
- // Skip if event already exists
1206
- const existing = store.getRow('events', event.id);
1207
- if (existing.id) continue;
1208
-
1209
- // Store the event
1210
- store.setRow('events', event.id, {
1211
- id: event.id,
1212
- version: event.version,
1213
- timestamp: event.timestamp,
1214
- type: event.type,
1215
- source: JSON.stringify(event.source),
1216
- target: event.target ? JSON.stringify(event.target) : '',
1217
- payload: JSON.stringify(event.payload),
1218
- metadata: event.metadata ? JSON.stringify(event.metadata) : '',
1219
- });
1220
-
1221
- // Update materialized views
1222
- applyEventToViews(store, event, notifyAgentChange, notifyTaskChange, notifyMessageChange, notifySessionChange, notifyConversationChange, notifyTurnChange);
1223
- }
1224
- }
1225
-
1226
- /**
1227
- * Get underlying storage backend (for advanced use)
1228
- */
1229
- function getBackend(): StorageBackend {
1230
- return createTinyBaseBackend(store, {
1231
- onFlush: async () => {
1232
- if (persister) {
1233
- await persister.save();
1234
- }
1235
- },
1236
- onClose: async () => {
1237
- if (persister) {
1238
- await persister.save();
1239
- persister.destroy();
1240
- }
1241
- if (db) {
1242
- db.close();
1243
- }
1244
- },
1245
- });
1246
- }
1247
-
1248
- return {
1249
- // Instance info
1250
- instanceId,
1251
- namespace,
1252
- instancePath,
1253
- baseDir,
1254
- backendType,
1255
- peerVisibility,
1256
-
1257
- // Event operations
1258
- emit,
1259
- query,
1260
-
1261
- // Views
1262
- getAgent,
1263
- listAgents,
1264
- updateAgentPlan,
1265
- updateAgentMetadata,
1266
- getTask,
1267
- listTasks,
1268
- getMessages,
1269
- getFullMessage,
1270
- getSession,
1271
- listSessions,
1272
- getConversation,
1273
- listConversations,
1274
- listTurns,
1275
- listParticipants,
1276
-
1277
- // Subscriptions
1278
- addSubscription,
1279
- removeSubscription,
1280
- getSubscriptions,
1281
- getSubscribers,
1282
-
1283
- // Reactive updates
1284
- onAgentChange,
1285
- onTaskChange,
1286
- onMessageChange,
1287
- onSessionChange,
1288
- onConversationChange,
1289
- onTurnChange,
1290
-
1291
- // Lifecycle
1292
- persist,
1293
- reload,
1294
- close,
1295
-
1296
- // Archival
1297
- archive,
1298
- loadArchive,
1299
- getArchiveInfo,
1300
-
1301
- // Export/Import
1302
- exportEvents,
1303
- importEvents,
1304
-
1305
- // Advanced
1306
- getBackend,
1307
- };
1308
- }
1309
-
1310
- /**
1311
- * Initialize empty tables in the store
1312
- */
1313
- function initializeTables(store: Store): void {
1314
- // Events table is created implicitly when rows are added
1315
- // We just ensure the tables exist by checking row IDs
1316
- store.getRowIds('events');
1317
- store.getRowIds('agents');
1318
- store.getRowIds('tasks');
1319
- store.getRowIds('messages');
1320
- store.getRowIds('subscriptions');
1321
- store.getRowIds('sessions');
1322
- store.getRowIds('conversations');
1323
- store.getRowIds('turns');
1324
- store.getRowIds('threads');
1325
- store.getRowIds('participants');
1326
- }
1327
-
1328
- /**
1329
- * Rebuild materialized views from the event log
1330
- */
1331
- function rebuildViews(store: Store): void {
1332
- // Preserve out-of-band agent fields that aren't derived from events.
1333
- // These fields are written directly (not through events),
1334
- // so they would be lost when we clear and replay.
1335
- const OUT_OF_BAND_FIELDS = ['plan', 'name', 'metadata'] as const;
1336
- const savedOutOfBand = new Map<string, Record<string, string>>();
1337
- for (const rowId of store.getRowIds('agents')) {
1338
- const row = store.getRow('agents', rowId);
1339
- const saved: Record<string, string> = {};
1340
- for (const field of OUT_OF_BAND_FIELDS) {
1341
- const val = row[field] as string | undefined;
1342
- if (val && val !== '' && val !== '[]') {
1343
- saved[field] = val;
1344
- }
1345
- }
1346
- if (Object.keys(saved).length > 0) {
1347
- savedOutOfBand.set(rowId, saved);
1348
- }
1349
- }
1350
-
1351
- // Clear existing views
1352
- for (const rowId of store.getRowIds('agents')) {
1353
- store.delRow('agents', rowId);
1354
- }
1355
- for (const rowId of store.getRowIds('tasks')) {
1356
- store.delRow('tasks', rowId);
1357
- }
1358
- for (const rowId of store.getRowIds('messages')) {
1359
- store.delRow('messages', rowId);
1360
- }
1361
- for (const rowId of store.getRowIds('sessions')) {
1362
- store.delRow('sessions', rowId);
1363
- }
1364
- for (const rowId of store.getRowIds('conversations')) {
1365
- store.delRow('conversations', rowId);
1366
- }
1367
- for (const rowId of store.getRowIds('turns')) {
1368
- store.delRow('turns', rowId);
1369
- }
1370
- for (const rowId of store.getRowIds('threads')) {
1371
- store.delRow('threads', rowId);
1372
- }
1373
- for (const rowId of store.getRowIds('participants')) {
1374
- store.delRow('participants', rowId);
1375
- }
1376
-
1377
- // Replay all events to rebuild views
1378
- const events: Event[] = [];
1379
- for (const rowId of store.getRowIds('events')) {
1380
- const row = store.getRow('events', rowId);
1381
- if (!row.id) continue;
1382
-
1383
- // Parse raw event and migrate to current version
1384
- const rawEvent = {
1385
- id: row.id as string,
1386
- version: row.version as number | undefined,
1387
- timestamp: row.timestamp as number,
1388
- type: row.type as string,
1389
- source: JSON.parse(row.source as string),
1390
- target: row.target ? JSON.parse(row.target as string) : undefined,
1391
- payload: JSON.parse(row.payload as string),
1392
- metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,
1393
- };
1394
-
1395
- events.push(migrateEvent(rawEvent));
1396
- }
1397
-
1398
- // Sort by timestamp
1399
- events.sort((a, b) => a.timestamp - b.timestamp);
1400
-
1401
- // Apply each event (no-op callbacks since we're rebuilding)
1402
- const noop = () => {};
1403
- for (const event of events) {
1404
- applyEventToViews(store, event, noop, noop, noop, noop, noop, noop);
1405
- }
1406
-
1407
- // Restore out-of-band agent fields preserved before the wipe
1408
- for (const [agentId, fields] of savedOutOfBand) {
1409
- const row = store.getRow('agents', agentId);
1410
- if (row.id) {
1411
- store.setPartialRow('agents', agentId, fields);
1412
- }
1413
- }
1414
- }
1415
-
1416
- /**
1417
- * Apply a single event to materialized views
1418
- */
1419
- function applyEventToViews(
1420
- store: Store,
1421
- event: Event,
1422
- notifyAgentChange: (agentId: AgentId, agent: Agent | null) => void,
1423
- notifyTaskChange: (taskId: TaskId, task: Task | null) => void,
1424
- notifyMessageChange: (agentId: AgentId) => void,
1425
- notifySessionChange: (sessionId: string, session: Session | null) => void,
1426
- notifyConversationChange: (conversationId: string, conversation: Conversation | null) => void,
1427
- notifyTurnChange: (conversationId: string, turn: ConversationTurn) => void,
1428
- ): void {
1429
- switch (event.type) {
1430
- case 'spawn':
1431
- applySpawnEvent(store, event, notifyAgentChange);
1432
- break;
1433
- case 'stop':
1434
- applyStopEvent(store, event, notifyAgentChange);
1435
- break;
1436
- case 'status':
1437
- applyStatusEvent(store, event, notifyAgentChange);
1438
- break;
1439
- case 'message':
1440
- applyMessageEvent(store, event, notifyMessageChange);
1441
- break;
1442
- case 'task':
1443
- applyTaskEvent(store, event, notifyTaskChange);
1444
- break;
1445
- case 'session':
1446
- applySessionEvent(store, event, notifySessionChange);
1447
- break;
1448
- case 'conversation':
1449
- applyConversationEvent(store, event, notifyConversationChange);
1450
- break;
1451
- case 'turn':
1452
- applyTurnEvent(store, event, notifyTurnChange);
1453
- break;
1454
- case 'thread':
1455
- applyThreadEvent(store, event);
1456
- break;
1457
- case 'peer_message':
1458
- case 'peer_request':
1459
- // Peer events are stored in the event log for audit trail
1460
- // but not materialized into views since PeerManager handles
1461
- // in-memory queues. Events can be queried via eventStore.query().
1462
- break;
1463
- }
1464
- }
1465
-
1466
- /**
1467
- * Apply spawn event to agents view
1468
- */
1469
- function applySpawnEvent(
1470
- store: Store,
1471
- event: Event,
1472
- notify: (agentId: AgentId, agent: Agent | null) => void,
1473
- ): void {
1474
- const payload = event.payload as {
1475
- agent_id: AgentId;
1476
- session_id: string;
1477
- task: string;
1478
- task_id?: TaskId;
1479
- parent?: AgentId | null;
1480
- role?: string;
1481
- config?: Record<string, unknown>;
1482
- cwd?: string;
1483
- };
1484
-
1485
- const agentId = payload.agent_id;
1486
- const parent = payload.parent ?? null;
1487
-
1488
- // Compute lineage
1489
- let lineage: AgentId[] = [];
1490
- if (parent) {
1491
- const parentRow = store.getRow('agents', parent);
1492
- if (parentRow.lineage) {
1493
- lineage = [...JSON.parse(parentRow.lineage as string), parent];
1494
- } else {
1495
- lineage = [parent];
1496
- }
1497
- }
1498
-
1499
- store.setRow('agents', agentId, {
1500
- id: agentId,
1501
- name: '',
1502
- session_id: payload.session_id,
1503
- provider_session_id: '',
1504
- parent: parent ?? '',
1505
- lineage: JSON.stringify(lineage),
1506
- state: 'spawning',
1507
- stop_reason: '',
1508
- task: payload.task,
1509
- task_id: payload.task_id ?? '',
1510
- role: payload.role ?? '',
1511
- config: JSON.stringify(payload.config ?? {}),
1512
- cwd: payload.cwd ?? process.cwd(),
1513
- plan: '[]',
1514
- metadata: '',
1515
- created_at: event.timestamp,
1516
- started_at: 0,
1517
- stopped_at: 0,
1518
- last_activity_at: event.timestamp,
1519
- });
1520
-
1521
- const agent = rowToAgent(store.getRow('agents', agentId));
1522
- notify(agentId, agent);
1523
- }
1524
-
1525
- /**
1526
- * Apply stop event to agents view
1527
- */
1528
- function applyStopEvent(
1529
- store: Store,
1530
- event: Event,
1531
- notify: (agentId: AgentId, agent: Agent | null) => void,
1532
- ): void {
1533
- const agentId = event.source.agent_id;
1534
- if (!agentId) return;
1535
-
1536
- const payload = event.payload as { reason: string };
1537
-
1538
- store.setPartialRow('agents', agentId, {
1539
- state: 'stopped',
1540
- stop_reason: payload.reason,
1541
- stopped_at: event.timestamp,
1542
- last_activity_at: event.timestamp,
1543
- });
1544
-
1545
- const agent = rowToAgent(store.getRow('agents', agentId));
1546
- notify(agentId, agent);
1547
- }
1548
-
1549
- /**
1550
- * Apply status event to agents view
1551
- */
1552
- function applyStatusEvent(
1553
- store: Store,
1554
- event: Event,
1555
- notify: (agentId: AgentId, agent: Agent | null) => void,
1556
- ): void {
1557
- const agentId = event.source.agent_id;
1558
- if (!agentId) return;
1559
-
1560
- const payload = event.payload as { status_type: string; provider_session_id?: string };
1561
-
1562
- // Handle specific status types
1563
- if (payload.status_type === 'started') {
1564
- const updates: Record<string, string | number> = {
1565
- state: 'running',
1566
- started_at: event.timestamp,
1567
- last_activity_at: event.timestamp,
1568
- };
1569
- // Store the provider's session ID (e.g., Claude Code UUID for --resume)
1570
- if (payload.provider_session_id) {
1571
- updates.provider_session_id = payload.provider_session_id;
1572
- }
1573
- store.setPartialRow('agents', agentId, updates);
1574
- } else {
1575
- // Always update last_activity_at on any status event
1576
- store.setPartialRow('agents', agentId, {
1577
- last_activity_at: event.timestamp,
1578
- });
1579
- }
1580
-
1581
- const agent = rowToAgent(store.getRow('agents', agentId));
1582
- notify(agentId, agent);
1583
- }
1584
-
1585
- /**
1586
- * Apply message event to messages view
1587
- */
1588
- function applyMessageEvent(
1589
- store: Store,
1590
- event: Event,
1591
- notify: (agentId: AgentId) => void,
1592
- ): void {
1593
- const target = event.target;
1594
- if (!target) return;
1595
-
1596
- const payload = event.payload as { content?: unknown; correlation_id?: string };
1597
- // Handle various payload formats - content may be a string, object, or missing
1598
- const rawContent = payload.content;
1599
- const content = typeof rawContent === 'string'
1600
- ? rawContent
1601
- : rawContent != null
1602
- ? JSON.stringify(rawContent)
1603
- : '[no content]';
1604
-
1605
- // Truncate if needed (1000 chars limit)
1606
- const MAX_CONTENT_LENGTH = 1000;
1607
- const truncated = content.length > MAX_CONTENT_LENGTH;
1608
- const displayContent = truncated ? content.slice(0, MAX_CONTENT_LENGTH) + '...' : content;
1609
-
1610
- // Route to direct agent target
1611
- if (target.agent_id) {
1612
- const messageId = `${event.id}:${target.agent_id}`;
1613
- store.setRow('messages', messageId, {
1614
- id: event.id,
1615
- recipient: target.agent_id,
1616
- from: JSON.stringify(event.source),
1617
- content: displayContent,
1618
- timestamp: event.timestamp,
1619
- truncated,
1620
- correlation_id: payload.correlation_id ?? '',
1621
- });
1622
- notify(target.agent_id);
1623
- }
1624
-
1625
- // Route to topic subscribers
1626
- if (target.topic) {
1627
- const rowIds = store.getRowIds('subscriptions');
1628
- for (const rowId of rowIds) {
1629
- const row = store.getRow('subscriptions', rowId);
1630
- if (row.type === 'topic' && row.target === target.topic) {
1631
- const recipientId = row.agent_id as AgentId;
1632
- const messageId = `${event.id}:${recipientId}`;
1633
- store.setRow('messages', messageId, {
1634
- id: event.id,
1635
- recipient: recipientId,
1636
- from: JSON.stringify(event.source),
1637
- content: displayContent,
1638
- timestamp: event.timestamp,
1639
- truncated,
1640
- correlation_id: payload.correlation_id ?? '',
1641
- });
1642
- notify(recipientId);
1643
- }
1644
- }
1645
- }
1646
- }
1647
-
1648
- /**
1649
- * Apply task event to tasks view
1650
- */
1651
- function applyTaskEvent(
1652
- store: Store,
1653
- event: Event,
1654
- notify: (taskId: TaskId, task: Task | null) => void,
1655
- ): void {
1656
- const payload = event.payload as {
1657
- task_id: TaskId;
1658
- action: string;
1659
- details?: Record<string, unknown>;
1660
- };
1661
-
1662
- const taskId = payload.task_id;
1663
-
1664
- switch (payload.action) {
1665
- case 'created': {
1666
- const details = payload.details as {
1667
- description: string;
1668
- parent_task?: TaskId;
1669
- inputs?: Record<string, unknown>;
1670
- tags?: string[];
1671
- retryPolicy?: unknown;
1672
- };
1673
- store.setRow('tasks', taskId, {
1674
- id: taskId,
1675
- description: details.description,
1676
- status: 'pending',
1677
- assigned_agent: '',
1678
- parent_task: details.parent_task ?? '',
1679
- subtasks: JSON.stringify([]),
1680
- blockers: JSON.stringify([]),
1681
- tags: details.tags ? JSON.stringify(details.tags) : '',
1682
- created_at: event.timestamp,
1683
- started_at: 0,
1684
- completed_at: 0,
1685
- created_by: event.source.agent_id ?? '',
1686
- inputs: JSON.stringify(details.inputs ?? {}),
1687
- outputs: JSON.stringify({}),
1688
- artifacts: JSON.stringify([]),
1689
- agent_history: JSON.stringify([]),
1690
- retry_policy: details.retryPolicy
1691
- ? JSON.stringify(details.retryPolicy)
1692
- : '',
1693
- retry_state: '',
1694
- });
1695
- break;
1696
- }
1697
- case 'assigned': {
1698
- const details = payload.details as { agent_id: AgentId; role?: string };
1699
- const existing = store.getRow('tasks', taskId);
1700
- const history = existing.agent_history
1701
- ? JSON.parse(existing.agent_history as string)
1702
- : [];
1703
- history.push({
1704
- agent_id: details.agent_id,
1705
- role: details.role,
1706
- assigned_at: event.timestamp,
1707
- });
1708
- store.setPartialRow('tasks', taskId, {
1709
- status: 'assigned',
1710
- assigned_agent: details.agent_id,
1711
- agent_history: JSON.stringify(history),
1712
- });
1713
- break;
1714
- }
1715
- case 'unassigned': {
1716
- const details = payload.details as { agent_id: AgentId };
1717
- const existing = store.getRow('tasks', taskId);
1718
- const history = existing.agent_history
1719
- ? JSON.parse(existing.agent_history as string)
1720
- : [];
1721
- // Update the last entry for this agent with ended_at
1722
- for (let i = history.length - 1; i >= 0; i--) {
1723
- if (history[i].agent_id === details.agent_id && !history[i].ended_at) {
1724
- history[i].ended_at = event.timestamp;
1725
- break;
1726
- }
1727
- }
1728
- const updates: Record<string, string | number | boolean> = {
1729
- assigned_agent: '',
1730
- agent_history: JSON.stringify(history),
1731
- };
1732
- // Reset to pending if task was only assigned (not yet started)
1733
- if (existing.status === 'assigned') {
1734
- updates.status = 'pending';
1735
- }
1736
- store.setPartialRow('tasks', taskId, updates);
1737
- break;
1738
- }
1739
- case 'status_change': {
1740
- const details = payload.details as {
1741
- status?: TaskStatus;
1742
- outputs?: Record<string, unknown>;
1743
- artifacts?: unknown[];
1744
- description?: string;
1745
- subtask_added?: TaskId;
1746
- retryState?: unknown;
1747
- agent_id?: AgentId | null;
1748
- };
1749
- const updates: Record<string, unknown> = {};
1750
-
1751
- if (details.status) {
1752
- updates.status = details.status;
1753
- if (details.status === 'in_progress') {
1754
- const existing = store.getRow('tasks', taskId);
1755
- if (!existing.started_at) {
1756
- updates.started_at = event.timestamp;
1757
- }
1758
- }
1759
- }
1760
-
1761
- if (details.outputs !== undefined) {
1762
- updates.outputs = JSON.stringify(details.outputs);
1763
- }
1764
-
1765
- if (details.artifacts !== undefined) {
1766
- const existing = store.getRow('tasks', taskId);
1767
- const currentArtifacts = existing.artifacts
1768
- ? JSON.parse(existing.artifacts as string)
1769
- : [];
1770
- updates.artifacts = JSON.stringify([
1771
- ...currentArtifacts,
1772
- ...details.artifacts,
1773
- ]);
1774
- }
1775
-
1776
- if (details.description !== undefined) {
1777
- updates.description = details.description;
1778
- }
1779
-
1780
- if (details.subtask_added) {
1781
- const existing = store.getRow('tasks', taskId);
1782
- const subtasks = existing.subtasks
1783
- ? JSON.parse(existing.subtasks as string)
1784
- : [];
1785
- subtasks.push(details.subtask_added);
1786
- updates.subtasks = JSON.stringify(subtasks);
1787
- }
1788
-
1789
- if (details.retryState !== undefined) {
1790
- updates.retry_state = JSON.stringify(details.retryState);
1791
- }
1792
-
1793
- // Allow clearing the assigned agent (for retry)
1794
- if (details.agent_id === null) {
1795
- updates.assigned_agent = '';
1796
- }
1797
-
1798
- if (Object.keys(updates).length > 0) {
1799
- store.setPartialRow('tasks', taskId, updates as Record<string, string | number | boolean>);
1800
- }
1801
- break;
1802
- }
1803
- case 'completed': {
1804
- store.setPartialRow('tasks', taskId, {
1805
- status: 'completed',
1806
- completed_at: event.timestamp,
1807
- });
1808
- break;
1809
- }
1810
- case 'failed': {
1811
- store.setPartialRow('tasks', taskId, {
1812
- status: 'failed',
1813
- completed_at: event.timestamp,
1814
- });
1815
- break;
1816
- }
1817
- case 'blocker_added': {
1818
- const details = payload.details as { blocker_id: TaskId };
1819
- const existing = store.getRow('tasks', taskId);
1820
- const blockers = existing.blockers
1821
- ? JSON.parse(existing.blockers as string)
1822
- : [];
1823
- if (!blockers.includes(details.blocker_id)) {
1824
- blockers.push(details.blocker_id);
1825
- store.setPartialRow('tasks', taskId, {
1826
- blockers: JSON.stringify(blockers),
1827
- });
1828
- }
1829
- break;
1830
- }
1831
- case 'blocker_removed': {
1832
- const details = payload.details as { blocker_id: TaskId };
1833
- const existing = store.getRow('tasks', taskId);
1834
- const blockers = existing.blockers
1835
- ? JSON.parse(existing.blockers as string)
1836
- : [];
1837
- const idx = blockers.indexOf(details.blocker_id);
1838
- if (idx >= 0) {
1839
- blockers.splice(idx, 1);
1840
- store.setPartialRow('tasks', taskId, {
1841
- blockers: JSON.stringify(blockers),
1842
- });
1843
- }
1844
- break;
1845
- }
1846
- }
1847
-
1848
- const task = rowToTask(store.getRow('tasks', taskId));
1849
- notify(taskId, task);
1850
- }
1851
-
1852
- /**
1853
- * Convert a TinyBase row to an Agent object
1854
- */
1855
- function rowToAgent(row: Record<string, unknown>): Agent {
1856
- const stopReason = row.stop_reason as string;
1857
- return {
1858
- id: row.id as AgentId,
1859
- name: (row.name as string) || undefined,
1860
- session_id: row.session_id as string,
1861
- provider_session_id: (row.provider_session_id as string) || undefined,
1862
- parent: (row.parent as string) || null,
1863
- lineage: row.lineage ? JSON.parse(row.lineage as string) : [],
1864
- state: row.state as AgentState,
1865
- stop_reason: stopReason ? (stopReason as Agent['stop_reason']) : undefined,
1866
- task: row.task as string,
1867
- task_id: (row.task_id as string) || undefined,
1868
- role: (row.role as string) || undefined,
1869
- config: row.config ? JSON.parse(row.config as string) : {},
1870
- cwd: (row.cwd as string) || process.cwd(),
1871
- plan: row.plan ? JSON.parse(row.plan as string) : [],
1872
- metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,
1873
- created_at: row.created_at as Timestamp,
1874
- started_at: (row.started_at as number) || undefined,
1875
- stopped_at: (row.stopped_at as number) || undefined,
1876
- last_activity_at: (row.last_activity_at as number) || undefined,
1877
- };
1878
- }
1879
-
1880
- /**
1881
- * Convert a TinyBase row to a Task object
1882
- */
1883
- function rowToTask(row: Record<string, unknown>): Task {
1884
- return {
1885
- id: row.id as TaskId,
1886
- description: row.description as string,
1887
- status: row.status as TaskStatus,
1888
- assigned_agent: (row.assigned_agent as string) || undefined,
1889
- parent_task: (row.parent_task as string) || undefined,
1890
- subtasks: row.subtasks ? JSON.parse(row.subtasks as string) : undefined,
1891
- blockers: row.blockers ? JSON.parse(row.blockers as string) : undefined,
1892
- created_at: row.created_at as Timestamp,
1893
- started_at: (row.started_at as number) || undefined,
1894
- completed_at: (row.completed_at as number) || undefined,
1895
- created_by: row.created_by as AgentId,
1896
- inputs: row.inputs ? JSON.parse(row.inputs as string) : undefined,
1897
- outputs: row.outputs ? JSON.parse(row.outputs as string) : undefined,
1898
- artifacts: row.artifacts ? JSON.parse(row.artifacts as string) : undefined,
1899
- agent_history: row.agent_history ? JSON.parse(row.agent_history as string) : undefined,
1900
- tags: row.tags ? JSON.parse(row.tags as string) : undefined,
1901
- retryPolicy: row.retry_policy ? JSON.parse(row.retry_policy as string) : undefined,
1902
- retryState: row.retry_state ? JSON.parse(row.retry_state as string) : undefined,
1903
- };
1904
- }
1905
-
1906
- // ─────────────────────────────────────────────────────────────────────────────
1907
- // Session Event Handlers
1908
- // ─────────────────────────────────────────────────────────────────────────────
1909
-
1910
- /**
1911
- * Apply session event to sessions view
1912
- */
1913
- function applySessionEvent(
1914
- store: Store,
1915
- event: Event,
1916
- notify: (sessionId: string, session: Session | null) => void,
1917
- ): void {
1918
- const payload = event.payload as {
1919
- action: string;
1920
- session_id: string;
1921
- head_manager_id?: AgentId;
1922
- agent_id?: AgentId;
1923
- target_agent_id?: AgentId;
1924
- previous_agent_id?: AgentId;
1925
- };
1926
-
1927
- const sessionId = payload.session_id;
1928
-
1929
- switch (payload.action) {
1930
- case 'created': {
1931
- store.setRow('sessions', sessionId, {
1932
- id: sessionId,
1933
- head_manager_id: payload.head_manager_id ?? '',
1934
- current_agent_id: payload.head_manager_id ?? '',
1935
- state: 'active',
1936
- created_at: event.timestamp,
1937
- updated_at: event.timestamp,
1938
- closed_at: 0,
1939
- });
1940
- break;
1941
- }
1942
- case 'mounted': {
1943
- store.setPartialRow('sessions', sessionId, {
1944
- current_agent_id: payload.target_agent_id ?? '',
1945
- state: 'mounted',
1946
- updated_at: event.timestamp,
1947
- });
1948
- break;
1949
- }
1950
- case 'unmounted': {
1951
- const existing = store.getRow('sessions', sessionId);
1952
- store.setPartialRow('sessions', sessionId, {
1953
- current_agent_id: existing.head_manager_id as string,
1954
- state: 'active',
1955
- updated_at: event.timestamp,
1956
- });
1957
- break;
1958
- }
1959
- case 'closed': {
1960
- store.setPartialRow('sessions', sessionId, {
1961
- state: 'closed',
1962
- updated_at: event.timestamp,
1963
- closed_at: event.timestamp,
1964
- });
1965
- break;
1966
- }
1967
- }
1968
-
1969
- const session = rowToSession(store.getRow('sessions', sessionId));
1970
- notify(sessionId, session);
1971
- }
1972
-
1973
- /**
1974
- * Convert a TinyBase row to a Session object
1975
- */
1976
- function rowToSession(row: Record<string, unknown>): Session {
1977
- return {
1978
- id: row.id as string,
1979
- head_manager_id: row.head_manager_id as AgentId,
1980
- current_agent_id: row.current_agent_id as AgentId,
1981
- state: row.state as SessionState,
1982
- created_at: row.created_at as Timestamp,
1983
- updated_at: row.updated_at as Timestamp,
1984
- closed_at: (row.closed_at as number) || undefined,
1985
- };
1986
- }
1987
-
1988
- // ─────────────────────────────────────────────────────────────────────────────
1989
- // Conversation Event Handlers
1990
- // ─────────────────────────────────────────────────────────────────────────────
1991
-
1992
- /**
1993
- * Apply conversation event to conversations view
1994
- */
1995
- function applyConversationEvent(
1996
- store: Store,
1997
- event: Event,
1998
- notify: (conversationId: string, conversation: Conversation | null) => void,
1999
- ): void {
2000
- const payload = event.payload;
2001
- const conversationId = payload.conversation_id as string;
2002
-
2003
- switch (payload.action) {
2004
- case 'created': {
2005
- store.setRow('conversations', conversationId, {
2006
- id: conversationId,
2007
- type: payload.conversation_type as string,
2008
- status: 'active',
2009
- subject: (payload.subject as string) ?? '',
2010
- parent_conversation_id: (payload.parent_conversation_id as string) ?? '',
2011
- created_by: event.source.agent_id ?? 'unknown',
2012
- created_at: event.timestamp,
2013
- updated_at: event.timestamp,
2014
- closed_at: 0,
2015
- closed_by: '',
2016
- close_reason: '',
2017
- participant_count: 0,
2018
- metadata: payload.metadata ? JSON.stringify(payload.metadata) : '',
2019
- });
2020
- break;
2021
- }
2022
- case 'closed': {
2023
- const closeReason = (payload.close_reason as string) ?? '';
2024
- // Map close_reason to valid ConversationStatus
2025
- const validStatuses = new Set(['completed', 'failed', 'archived']);
2026
- const closedStatus = validStatuses.has(closeReason) ? closeReason : 'completed';
2027
- store.setPartialRow('conversations', conversationId, {
2028
- status: closedStatus,
2029
- closed_at: event.timestamp,
2030
- updated_at: event.timestamp,
2031
- closed_by: (payload.closed_by as string) ?? event.source.agent_id ?? '',
2032
- close_reason: closeReason,
2033
- });
2034
- break;
2035
- }
2036
- case 'participant_joined': {
2037
- const participantId = payload.participant_id as string;
2038
- const partId = `${conversationId}:${participantId}`;
2039
- store.setRow('participants', partId, {
2040
- id: participantId,
2041
- conversation_id: conversationId,
2042
- type: (payload.participant_type as string) ?? 'agent',
2043
- role: (payload.participant_role as string) ?? 'worker',
2044
- joined_at: event.timestamp,
2045
- left_at: 0,
2046
- agent_id: (payload.agent_id as string) ?? '',
2047
- });
2048
- // Increment participant count
2049
- const existing = store.getRow('conversations', conversationId);
2050
- if (existing.id) {
2051
- const count = (existing.participant_count as number) || 0;
2052
- store.setPartialRow('conversations', conversationId, {
2053
- participant_count: count + 1,
2054
- updated_at: event.timestamp,
2055
- });
2056
- }
2057
- break;
2058
- }
2059
- case 'participant_left': {
2060
- const leftParticipantId = payload.participant_id as string;
2061
- const partId = `${conversationId}:${leftParticipantId}`;
2062
- store.setPartialRow('participants', partId, {
2063
- left_at: event.timestamp,
2064
- });
2065
- // Decrement participant count
2066
- const existing = store.getRow('conversations', conversationId);
2067
- if (existing.id) {
2068
- const count = (existing.participant_count as number) || 0;
2069
- store.setPartialRow('conversations', conversationId, {
2070
- participant_count: Math.max(0, count - 1),
2071
- updated_at: event.timestamp,
2072
- });
2073
- }
2074
- break;
2075
- }
2076
- }
2077
-
2078
- const conversation = rowToConversation(store.getRow('conversations', conversationId));
2079
- notify(conversationId, conversation);
2080
- }
2081
-
2082
- /**
2083
- * Apply turn event to turns view
2084
- */
2085
- function applyTurnEvent(
2086
- store: Store,
2087
- event: Event,
2088
- notify: (conversationId: string, turn: ConversationTurn) => void,
2089
- ): void {
2090
- const payload = event.payload;
2091
-
2092
- if (payload.action !== 'recorded') return;
2093
-
2094
- const turnId = payload.turn_id as string;
2095
- const conversationId = payload.conversation_id as string;
2096
- const content = payload.content;
2097
-
2098
- store.setRow('turns', turnId, {
2099
- id: turnId,
2100
- conversation_id: conversationId,
2101
- participant: (payload.participant as string) ?? event.source.agent_id ?? '',
2102
- timestamp: event.timestamp,
2103
- content_type: (payload.content_type as string) ?? 'text',
2104
- content: typeof content === 'string' ? content : JSON.stringify(content),
2105
- thread_id: (payload.thread_id as string) ?? '',
2106
- in_reply_to: (payload.in_reply_to as string) ?? '',
2107
- source_type: (payload.source_type as string) ?? 'explicit',
2108
- source_message_id: (payload.source_message_id as string) ?? '',
2109
- metadata: payload.metadata ? JSON.stringify(payload.metadata) : '',
2110
- });
2111
-
2112
- // Update conversation's updatedAt
2113
- const convRow = store.getRow('conversations', conversationId);
2114
- if (convRow.id) {
2115
- store.setPartialRow('conversations', conversationId, {
2116
- updated_at: event.timestamp,
2117
- });
2118
- }
2119
-
2120
- const turn = rowToTurn(store.getRow('turns', turnId));
2121
- notify(conversationId, turn);
2122
- }
2123
-
2124
- /**
2125
- * Apply thread event to threads view
2126
- */
2127
- function applyThreadEvent(
2128
- store: Store,
2129
- event: Event,
2130
- ): void {
2131
- const payload = event.payload;
2132
-
2133
- if (payload.action !== 'created') return;
2134
-
2135
- const threadId = payload.thread_id as string;
2136
- store.setRow('threads', threadId, {
2137
- id: threadId,
2138
- conversation_id: (payload.conversation_id as string) ?? '',
2139
- root_turn_id: (payload.root_turn_id as string) ?? '',
2140
- subject: (payload.subject as string) ?? '',
2141
- parent_thread_id: (payload.parent_thread_id as string) ?? '',
2142
- created_by: event.source.agent_id ?? 'unknown',
2143
- created_at: event.timestamp,
2144
- turn_count: 0,
2145
- });
2146
- }
2147
-
2148
- // ─────────────────────────────────────────────────────────────────────────────
2149
- // Conversation Row Conversion Functions
2150
- // ─────────────────────────────────────────────────────────────────────────────
2151
-
2152
- function rowToConversation(row: Record<string, unknown>): Conversation {
2153
- return {
2154
- id: row.id as string,
2155
- type: row.type as ConversationType,
2156
- status: row.status as ConversationStatus,
2157
- subject: (row.subject as string) || undefined,
2158
- parentConversationId: (row.parent_conversation_id as string) || undefined,
2159
- createdBy: row.created_by as string,
2160
- createdAt: row.created_at as Timestamp,
2161
- updatedAt: row.updated_at as Timestamp,
2162
- closedAt: (row.closed_at as number) || undefined,
2163
- closedBy: (row.closed_by as string) || undefined,
2164
- closeReason: (row.close_reason as string) || undefined,
2165
- participantCount: (row.participant_count as number) || 0,
2166
- metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,
2167
- };
2168
- }
2169
-
2170
- function rowToTurn(row: Record<string, unknown>): ConversationTurn {
2171
- const rawContent = row.content as string;
2172
- let content: unknown;
2173
- try {
2174
- content = JSON.parse(rawContent);
2175
- } catch {
2176
- content = rawContent;
2177
- }
2178
-
2179
- return {
2180
- id: row.id as string,
2181
- conversationId: row.conversation_id as string,
2182
- participant: row.participant as string,
2183
- timestamp: row.timestamp as Timestamp,
2184
- contentType: row.content_type as string,
2185
- content,
2186
- threadId: (row.thread_id as string) || undefined,
2187
- inReplyTo: (row.in_reply_to as string) || undefined,
2188
- sourceType: (row.source_type as string) as ConversationTurn['sourceType'],
2189
- sourceMessageId: (row.source_message_id as string) || undefined,
2190
- metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,
2191
- };
2192
- }
2193
-
2194
- function rowToParticipant(row: Record<string, unknown>): ConversationParticipant {
2195
- return {
2196
- id: row.id as string,
2197
- conversationId: row.conversation_id as string,
2198
- type: row.type as ConversationParticipant['type'],
2199
- role: row.role as ConversationParticipant['role'],
2200
- joinedAt: row.joined_at as Timestamp,
2201
- leftAt: (row.left_at as number) || undefined,
2202
- agentId: (row.agent_id as string) || undefined,
2203
- };
2204
- }