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