agent-relay 1.1.0 → 1.2.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 (567) hide show
  1. package/.gitattributes +3 -0
  2. package/.nvmrc +1 -0
  3. package/.trajectories/completed/2026-01/traj_1dviorhnkcb5.json +65 -0
  4. package/.trajectories/completed/2026-01/traj_1dviorhnkcb5.md +37 -0
  5. package/.trajectories/completed/2026-01/traj_1k5if5snst2e.json +65 -0
  6. package/.trajectories/completed/2026-01/traj_1k5if5snst2e.md +37 -0
  7. package/.trajectories/completed/2026-01/traj_1rp3rges5811.json +49 -0
  8. package/.trajectories/completed/2026-01/traj_1rp3rges5811.md +31 -0
  9. package/.trajectories/completed/2026-01/traj_22bhyulruouw.json +113 -0
  10. package/.trajectories/completed/2026-01/traj_22bhyulruouw.md +57 -0
  11. package/.trajectories/completed/2026-01/traj_2dao7ddgnta0.json +53 -0
  12. package/.trajectories/completed/2026-01/traj_2dao7ddgnta0.md +32 -0
  13. package/.trajectories/completed/2026-01/traj_3t0440mjeunc.json +26 -0
  14. package/.trajectories/completed/2026-01/traj_3t0440mjeunc.md +6 -0
  15. package/.trajectories/completed/2026-01/traj_45x9494d9xnr.json +47 -0
  16. package/.trajectories/completed/2026-01/traj_45x9494d9xnr.md +32 -0
  17. package/.trajectories/completed/2026-01/traj_4aa0bb77s4nh.json +53 -0
  18. package/.trajectories/completed/2026-01/traj_4aa0bb77s4nh.md +32 -0
  19. package/.trajectories/completed/2026-01/traj_5lhmzq8rxpqv.json +59 -0
  20. package/.trajectories/completed/2026-01/traj_5lhmzq8rxpqv.md +33 -0
  21. package/.trajectories/completed/2026-01/traj_5vr4e9erb1fs.json +53 -0
  22. package/.trajectories/completed/2026-01/traj_5vr4e9erb1fs.md +32 -0
  23. package/.trajectories/completed/2026-01/traj_6fgiwdoklvym.json +48 -0
  24. package/.trajectories/completed/2026-01/traj_6fgiwdoklvym.md +24 -0
  25. package/.trajectories/completed/2026-01/traj_7ludwvz45veh.json +209 -0
  26. package/.trajectories/completed/2026-01/traj_7ludwvz45veh.md +97 -0
  27. package/.trajectories/completed/2026-01/traj_9921cuhel0pj.json +48 -0
  28. package/.trajectories/completed/2026-01/traj_9921cuhel0pj.md +24 -0
  29. package/.trajectories/completed/2026-01/traj_ajs7zqfux4wc.json +49 -0
  30. package/.trajectories/completed/2026-01/traj_ajs7zqfux4wc.md +23 -0
  31. package/.trajectories/completed/2026-01/traj_cvtqhlwcq9s0.json +53 -0
  32. package/.trajectories/completed/2026-01/traj_cvtqhlwcq9s0.md +32 -0
  33. package/.trajectories/completed/2026-01/traj_cxofprm2m2en.json +49 -0
  34. package/.trajectories/completed/2026-01/traj_cxofprm2m2en.md +31 -0
  35. package/.trajectories/completed/2026-01/traj_d2hhz3k0vrhn.json +26 -0
  36. package/.trajectories/completed/2026-01/traj_d2hhz3k0vrhn.md +6 -0
  37. package/.trajectories/completed/2026-01/traj_dfuvww9pege5.json +59 -0
  38. package/.trajectories/completed/2026-01/traj_dfuvww9pege5.md +37 -0
  39. package/.trajectories/completed/2026-01/traj_g0fisy9h51mf.json +77 -0
  40. package/.trajectories/completed/2026-01/traj_g0fisy9h51mf.md +42 -0
  41. package/.trajectories/completed/2026-01/traj_gjdre5voouod.json +53 -0
  42. package/.trajectories/completed/2026-01/traj_gjdre5voouod.md +32 -0
  43. package/.trajectories/completed/2026-01/traj_gtlyqtta3x8l.json +25 -0
  44. package/.trajectories/completed/2026-01/traj_gtlyqtta3x8l.md +15 -0
  45. package/.trajectories/completed/2026-01/traj_h4xijiuip3w4.json +101 -0
  46. package/.trajectories/completed/2026-01/traj_h4xijiuip3w4.md +44 -0
  47. package/.trajectories/completed/2026-01/traj_hhxte7w4gjjx.json +22 -0
  48. package/.trajectories/completed/2026-01/traj_hhxte7w4gjjx.md +5 -0
  49. package/.trajectories/completed/2026-01/traj_hpungyhoj6v5.json +53 -0
  50. package/.trajectories/completed/2026-01/traj_hpungyhoj6v5.md +32 -0
  51. package/.trajectories/completed/2026-01/traj_m2xkjv0w2sq7.json +25 -0
  52. package/.trajectories/completed/2026-01/traj_m2xkjv0w2sq7.md +15 -0
  53. package/.trajectories/completed/2026-01/traj_noq5zbvnrdvz.json +53 -0
  54. package/.trajectories/completed/2026-01/traj_noq5zbvnrdvz.md +32 -0
  55. package/.trajectories/completed/2026-01/traj_ntbs6ppopf46.json +53 -0
  56. package/.trajectories/completed/2026-01/traj_ntbs6ppopf46.md +32 -0
  57. package/.trajectories/completed/2026-01/traj_ozd98si6a7ns.json +48 -0
  58. package/.trajectories/completed/2026-01/traj_ozd98si6a7ns.md +24 -0
  59. package/.trajectories/completed/2026-01/traj_prdza7a5cxp5.json +53 -0
  60. package/.trajectories/completed/2026-01/traj_prdza7a5cxp5.md +32 -0
  61. package/.trajectories/completed/2026-01/traj_qb3twvvywfwi.json +77 -0
  62. package/.trajectories/completed/2026-01/traj_qb3twvvywfwi.md +42 -0
  63. package/.trajectories/completed/2026-01/traj_qft54mi7nfor.json +53 -0
  64. package/.trajectories/completed/2026-01/traj_qft54mi7nfor.md +32 -0
  65. package/.trajectories/completed/2026-01/traj_qx9uhf8whhxo.json +83 -0
  66. package/.trajectories/completed/2026-01/traj_qx9uhf8whhxo.md +47 -0
  67. package/.trajectories/completed/2026-01/traj_rd9toccj18a0.json +59 -0
  68. package/.trajectories/completed/2026-01/traj_rd9toccj18a0.md +37 -0
  69. package/.trajectories/completed/2026-01/traj_rt4fiw3ecp50.json +48 -0
  70. package/.trajectories/completed/2026-01/traj_rt4fiw3ecp50.md +16 -0
  71. package/.trajectories/completed/2026-01/traj_st8j35b0hrlc.json +59 -0
  72. package/.trajectories/completed/2026-01/traj_st8j35b0hrlc.md +37 -0
  73. package/.trajectories/completed/2026-01/traj_t1yy8m7hbuxp.json +53 -0
  74. package/.trajectories/completed/2026-01/traj_t1yy8m7hbuxp.md +32 -0
  75. package/.trajectories/completed/2026-01/traj_tmux_orchestrator_analysis.json +84 -0
  76. package/.trajectories/completed/2026-01/traj_tmux_orchestrator_analysis.md +109 -0
  77. package/.trajectories/completed/2026-01/traj_u9n9eqasw16k.json +53 -0
  78. package/.trajectories/completed/2026-01/traj_u9n9eqasw16k.md +32 -0
  79. package/.trajectories/completed/2026-01/traj_v87hypnongqx.json +71 -0
  80. package/.trajectories/completed/2026-01/traj_v87hypnongqx.md +42 -0
  81. package/.trajectories/completed/2026-01/traj_wkp2fgzdyinb.json +53 -0
  82. package/.trajectories/completed/2026-01/traj_wkp2fgzdyinb.md +32 -0
  83. package/.trajectories/completed/2026-01/traj_x14t8w8rn7xg.json +20 -0
  84. package/.trajectories/completed/2026-01/traj_x14t8w8rn7xg.md +6 -0
  85. package/.trajectories/completed/2026-01/traj_xnwbznkvv8ua.json +175 -0
  86. package/.trajectories/completed/2026-01/traj_xnwbznkvv8ua.md +82 -0
  87. package/.trajectories/completed/2026-01/traj_ysjc8zaeqtd3.json +47 -0
  88. package/.trajectories/completed/2026-01/traj_ysjc8zaeqtd3.md +32 -0
  89. package/.trajectories/completed/2026-01/traj_yvdadtvdgnz3.json +59 -0
  90. package/.trajectories/completed/2026-01/traj_yvdadtvdgnz3.md +37 -0
  91. package/.trajectories/completed/2026-01/traj_z0vcw1wrzide.json +53 -0
  92. package/.trajectories/completed/2026-01/traj_z0vcw1wrzide.md +32 -0
  93. package/.trajectories/index.json +314 -0
  94. package/ARCHITECTURE.md +1245 -0
  95. package/README.md +1 -1
  96. package/TESTING.md +278 -0
  97. package/deploy/init-db.sql +5 -0
  98. package/deploy/scripts/setup-fly-workspaces.sh +69 -0
  99. package/deploy/scripts/setup-railway.sh +75 -0
  100. package/deploy/workspace/entrypoint-browser.sh +118 -0
  101. package/deploy/workspace/entrypoint.sh +348 -0
  102. package/deploy/workspace/git-credential-relay +111 -0
  103. package/dist/bridge/spawner.d.ts +53 -0
  104. package/dist/bridge/spawner.js +203 -19
  105. package/dist/bridge/types.d.ts +12 -0
  106. package/dist/cli/index.js +618 -5
  107. package/dist/cloud/api/auth.d.ts +3 -2
  108. package/dist/cloud/api/auth.js +10 -98
  109. package/dist/cloud/api/billing.js +30 -9
  110. package/dist/cloud/api/cli-pty-runner.d.ts +54 -0
  111. package/dist/cloud/api/cli-pty-runner.js +119 -0
  112. package/dist/cloud/api/codex-auth-helper.d.ts +15 -0
  113. package/dist/cloud/api/codex-auth-helper.js +100 -0
  114. package/dist/cloud/api/generic-webhooks.d.ts +8 -0
  115. package/dist/cloud/api/generic-webhooks.js +129 -0
  116. package/dist/cloud/api/git.d.ts +8 -0
  117. package/dist/cloud/api/git.js +152 -0
  118. package/dist/cloud/api/github-app.d.ts +11 -0
  119. package/dist/cloud/api/github-app.js +189 -0
  120. package/dist/cloud/api/middleware/planLimits.d.ts +7 -0
  121. package/dist/cloud/api/middleware/planLimits.js +39 -1
  122. package/dist/cloud/api/monitoring.d.ts +11 -0
  123. package/dist/cloud/api/monitoring.js +578 -0
  124. package/dist/cloud/api/nango-auth.d.ts +9 -0
  125. package/dist/cloud/api/nango-auth.js +377 -0
  126. package/dist/cloud/api/onboarding.d.ts +8 -1
  127. package/dist/cloud/api/onboarding.js +313 -119
  128. package/dist/cloud/api/policy.d.ts +8 -0
  129. package/dist/cloud/api/policy.js +229 -0
  130. package/dist/cloud/api/providers.js +114 -42
  131. package/dist/cloud/api/repos.d.ts +1 -0
  132. package/dist/cloud/api/repos.js +186 -0
  133. package/dist/cloud/api/test-helpers.d.ts +10 -0
  134. package/dist/cloud/api/test-helpers.js +575 -0
  135. package/dist/cloud/api/webhooks.d.ts +8 -0
  136. package/dist/cloud/api/webhooks.js +645 -0
  137. package/dist/cloud/api/workspaces.js +320 -12
  138. package/dist/cloud/billing/plans.js +32 -19
  139. package/dist/cloud/billing/types.d.ts +9 -3
  140. package/dist/cloud/config.d.ts +9 -2
  141. package/dist/cloud/config.js +13 -4
  142. package/dist/cloud/db/drizzle.d.ts +84 -1
  143. package/dist/cloud/db/drizzle.js +470 -0
  144. package/dist/cloud/db/index.d.ts +9 -4
  145. package/dist/cloud/db/index.js +11 -3
  146. package/dist/cloud/db/schema.d.ts +3283 -556
  147. package/dist/cloud/db/schema.js +314 -1
  148. package/dist/cloud/index.d.ts +1 -0
  149. package/dist/cloud/index.js +2 -0
  150. package/dist/cloud/provisioner/index.d.ts +56 -0
  151. package/dist/cloud/provisioner/index.js +676 -34
  152. package/dist/cloud/server.d.ts +1 -0
  153. package/dist/cloud/server.js +362 -13
  154. package/dist/cloud/services/auto-scaler.d.ts +152 -0
  155. package/dist/cloud/services/auto-scaler.js +439 -0
  156. package/dist/cloud/services/capacity-manager.d.ts +148 -0
  157. package/dist/cloud/services/capacity-manager.js +449 -0
  158. package/dist/cloud/services/ci-agent-spawner.d.ts +49 -0
  159. package/dist/cloud/services/ci-agent-spawner.js +373 -0
  160. package/dist/cloud/services/index.d.ts +12 -0
  161. package/dist/cloud/services/index.js +15 -0
  162. package/dist/cloud/services/mention-handler.d.ts +65 -0
  163. package/dist/cloud/services/mention-handler.js +405 -0
  164. package/dist/cloud/services/nango.d.ts +186 -0
  165. package/dist/cloud/services/nango.js +344 -0
  166. package/dist/cloud/services/persistence.d.ts +131 -0
  167. package/dist/cloud/services/persistence.js +200 -0
  168. package/dist/cloud/services/planLimits.d.ts +37 -0
  169. package/dist/cloud/services/planLimits.js +86 -5
  170. package/dist/cloud/services/scaling-orchestrator.d.ts +159 -0
  171. package/dist/cloud/services/scaling-orchestrator.js +502 -0
  172. package/dist/cloud/services/scaling-policy.d.ts +121 -0
  173. package/dist/cloud/services/scaling-policy.js +415 -0
  174. package/dist/cloud/vault/index.js +1 -1
  175. package/dist/cloud/webhooks/index.d.ts +24 -0
  176. package/dist/cloud/webhooks/index.js +29 -0
  177. package/dist/cloud/webhooks/parsers/github.d.ts +8 -0
  178. package/dist/cloud/webhooks/parsers/github.js +234 -0
  179. package/dist/cloud/webhooks/parsers/index.d.ts +23 -0
  180. package/dist/cloud/webhooks/parsers/index.js +30 -0
  181. package/dist/cloud/webhooks/parsers/linear.d.ts +9 -0
  182. package/dist/cloud/webhooks/parsers/linear.js +258 -0
  183. package/dist/cloud/webhooks/parsers/slack.d.ts +9 -0
  184. package/dist/cloud/webhooks/parsers/slack.js +214 -0
  185. package/dist/cloud/webhooks/responders/github.d.ts +8 -0
  186. package/dist/cloud/webhooks/responders/github.js +73 -0
  187. package/dist/cloud/webhooks/responders/index.d.ts +23 -0
  188. package/dist/cloud/webhooks/responders/index.js +30 -0
  189. package/dist/cloud/webhooks/responders/linear.d.ts +9 -0
  190. package/dist/cloud/webhooks/responders/linear.js +149 -0
  191. package/dist/cloud/webhooks/responders/slack.d.ts +20 -0
  192. package/dist/cloud/webhooks/responders/slack.js +178 -0
  193. package/dist/cloud/webhooks/router.d.ts +25 -0
  194. package/dist/cloud/webhooks/router.js +504 -0
  195. package/dist/cloud/webhooks/rules-engine.d.ts +24 -0
  196. package/dist/cloud/webhooks/rules-engine.js +287 -0
  197. package/dist/cloud/webhooks/types.d.ts +186 -0
  198. package/dist/cloud/webhooks/types.js +8 -0
  199. package/dist/continuity/formatter.d.ts +51 -0
  200. package/dist/continuity/formatter.js +313 -0
  201. package/dist/continuity/handoff-store.d.ts +67 -0
  202. package/dist/continuity/handoff-store.js +472 -0
  203. package/dist/continuity/index.d.ts +45 -0
  204. package/dist/continuity/index.js +48 -0
  205. package/dist/continuity/ledger-store.d.ts +110 -0
  206. package/dist/continuity/ledger-store.js +500 -0
  207. package/dist/continuity/manager.d.ts +178 -0
  208. package/dist/continuity/manager.js +562 -0
  209. package/dist/continuity/parser.d.ts +76 -0
  210. package/dist/continuity/parser.js +579 -0
  211. package/dist/continuity/types.d.ts +180 -0
  212. package/dist/continuity/types.js +9 -0
  213. package/dist/daemon/agent-manager.d.ts +27 -0
  214. package/dist/daemon/agent-manager.js +107 -6
  215. package/dist/daemon/agent-registry.d.ts +32 -0
  216. package/dist/daemon/agent-registry.js +42 -2
  217. package/dist/daemon/api.d.ts +12 -0
  218. package/dist/daemon/api.js +131 -2
  219. package/dist/daemon/cli-auth.d.ts +67 -0
  220. package/dist/daemon/cli-auth.js +537 -0
  221. package/dist/daemon/cloud-sync.js +9 -7
  222. package/dist/daemon/orchestrator.js +30 -0
  223. package/dist/daemon/router.d.ts +5 -0
  224. package/dist/daemon/router.js +78 -26
  225. package/dist/daemon/server.d.ts +5 -0
  226. package/dist/daemon/server.js +9 -1
  227. package/dist/daemon/services/browser-testing.d.ts +88 -0
  228. package/dist/daemon/services/browser-testing.js +244 -0
  229. package/dist/daemon/services/container-spawner.d.ts +135 -0
  230. package/dist/daemon/services/container-spawner.js +313 -0
  231. package/dist/daemon/types.d.ts +5 -1
  232. package/dist/dashboard/out/404.html +1 -1
  233. package/dist/dashboard/out/_next/static/chunks/116-2502180def231162.js +1 -0
  234. package/dist/dashboard/out/_next/static/chunks/282-980c2eb8fff20123.js +1 -0
  235. package/dist/dashboard/out/_next/static/chunks/699-3b1cd6618a45d259.js +1 -0
  236. package/dist/dashboard/out/_next/static/chunks/724-2dae7627550ab88f.js +9 -0
  237. package/dist/dashboard/out/_next/static/chunks/766-1f2dd8cb7f766b0b.js +1 -0
  238. package/dist/dashboard/out/_next/static/chunks/app/app/onboarding/page-3fdfa60e53f2810d.js +1 -0
  239. package/dist/dashboard/out/_next/static/chunks/app/app/page-e6381e5a6e1fbcfd.js +1 -0
  240. package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-3538dfe0ffe984b8.js +1 -0
  241. package/dist/dashboard/out/_next/static/chunks/app/history/{page-b6edd4dde8d08194.js → page-abb9ab2d329f56e9.js} +1 -1
  242. package/dist/dashboard/out/_next/static/chunks/app/layout-c0d118c0f92d969c.js +1 -0
  243. package/dist/dashboard/out/_next/static/chunks/app/login/page-c22d080201cbd9fb.js +1 -0
  244. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-67a3e98d9a43a6ed.js +1 -0
  245. package/dist/dashboard/out/_next/static/chunks/app/page-77e9c65420a06cfb.js +1 -0
  246. package/dist/dashboard/out/_next/static/chunks/app/pricing/page-b08ed1c34d14434a.js +1 -0
  247. package/dist/dashboard/out/_next/static/chunks/app/providers/page-e88bc117ef7671c3.js +1 -0
  248. package/dist/dashboard/out/_next/static/chunks/app/signup/page-68d34f50baa8ab6b.js +1 -0
  249. package/dist/dashboard/out/_next/static/chunks/e868780c-48e5f147c90a3a41.js +18 -0
  250. package/dist/dashboard/out/_next/static/chunks/{main-app-5d692157a8eb1fd9.js → main-app-6e8e8d3ef4e0192a.js} +1 -1
  251. package/dist/dashboard/out/_next/static/chunks/{main-c2f423b9c9f4591b.js → main-ed4e1fb6f29c34cf.js} +1 -1
  252. package/dist/dashboard/out/_next/static/chunks/webpack-1cdd8ed57114d5e1.js +1 -0
  253. package/dist/dashboard/out/_next/static/css/29852f26181969a0.css +1 -0
  254. package/dist/dashboard/out/_next/static/css/7c3ae9e8617d42a5.css +1 -0
  255. package/dist/dashboard/out/app/onboarding.html +1 -0
  256. package/dist/dashboard/out/app/onboarding.txt +7 -0
  257. package/dist/dashboard/out/app.html +1 -14
  258. package/dist/dashboard/out/app.txt +2 -2
  259. package/dist/dashboard/out/connect-repos.html +1 -0
  260. package/dist/dashboard/out/connect-repos.txt +7 -0
  261. package/dist/dashboard/out/history.html +1 -1
  262. package/dist/dashboard/out/history.txt +2 -2
  263. package/dist/dashboard/out/index.html +1 -1
  264. package/dist/dashboard/out/index.txt +2 -2
  265. package/dist/dashboard/out/login.html +6 -0
  266. package/dist/dashboard/out/login.txt +7 -0
  267. package/dist/dashboard/out/metrics.html +1 -1
  268. package/dist/dashboard/out/metrics.txt +2 -2
  269. package/dist/dashboard/out/pricing.html +3 -3
  270. package/dist/dashboard/out/pricing.txt +2 -2
  271. package/dist/dashboard/out/providers.html +1 -0
  272. package/dist/dashboard/out/providers.txt +7 -0
  273. package/dist/dashboard/out/signup.html +6 -0
  274. package/dist/dashboard/out/signup.txt +7 -0
  275. package/dist/dashboard-server/server.js +1308 -8
  276. package/dist/hooks/emitter.d.ts +40 -0
  277. package/dist/hooks/emitter.js +63 -0
  278. package/dist/hooks/index.d.ts +3 -0
  279. package/dist/hooks/index.js +3 -0
  280. package/dist/hooks/registry.d.ts +173 -0
  281. package/dist/hooks/registry.js +476 -0
  282. package/dist/hooks/trajectory-hooks.d.ts +52 -0
  283. package/dist/hooks/trajectory-hooks.js +183 -0
  284. package/dist/hooks/types.d.ts +141 -0
  285. package/dist/index.d.ts +2 -0
  286. package/dist/index.js +3 -0
  287. package/dist/memory/adapters/index.d.ts +8 -0
  288. package/dist/memory/adapters/index.js +8 -0
  289. package/dist/memory/adapters/inmemory.d.ts +59 -0
  290. package/dist/memory/adapters/inmemory.js +195 -0
  291. package/dist/memory/adapters/supermemory.d.ts +71 -0
  292. package/dist/memory/adapters/supermemory.js +338 -0
  293. package/dist/memory/factory.d.ts +48 -0
  294. package/dist/memory/factory.js +143 -0
  295. package/dist/memory/index.d.ts +32 -0
  296. package/dist/memory/index.js +32 -0
  297. package/dist/memory/memory-hooks.d.ts +60 -0
  298. package/dist/memory/memory-hooks.js +313 -0
  299. package/dist/memory/service.d.ts +49 -0
  300. package/dist/memory/service.js +146 -0
  301. package/dist/memory/types.d.ts +195 -0
  302. package/dist/memory/types.js +8 -0
  303. package/dist/policy/agent-policy.d.ts +225 -0
  304. package/dist/policy/agent-policy.js +665 -0
  305. package/dist/policy/cloud-policy-fetcher.d.ts +12 -0
  306. package/dist/policy/cloud-policy-fetcher.js +64 -0
  307. package/dist/resiliency/crash-insights.d.ts +156 -0
  308. package/dist/resiliency/crash-insights.js +492 -0
  309. package/dist/resiliency/gossip-health.d.ts +137 -0
  310. package/dist/resiliency/gossip-health.js +241 -0
  311. package/dist/resiliency/index.d.ts +5 -0
  312. package/dist/resiliency/index.js +5 -0
  313. package/dist/resiliency/leader-watchdog.d.ts +109 -0
  314. package/dist/resiliency/leader-watchdog.js +189 -0
  315. package/dist/resiliency/memory-monitor.d.ts +172 -0
  316. package/dist/resiliency/memory-monitor.js +593 -0
  317. package/dist/resiliency/stateless-lead.d.ts +149 -0
  318. package/dist/resiliency/stateless-lead.js +308 -0
  319. package/dist/resiliency/supervisor.d.ts +38 -0
  320. package/dist/resiliency/supervisor.js +122 -0
  321. package/dist/shared/cli-auth-config.d.ts +91 -0
  322. package/dist/shared/cli-auth-config.js +264 -0
  323. package/dist/storage/adapter.d.ts +1 -1
  324. package/dist/trajectory/config.d.ts +84 -0
  325. package/dist/trajectory/config.js +163 -0
  326. package/dist/trajectory/index.d.ts +8 -0
  327. package/dist/trajectory/index.js +8 -0
  328. package/dist/trajectory/integration.d.ts +292 -0
  329. package/dist/trajectory/integration.js +834 -0
  330. package/dist/utils/logger.js +1 -1
  331. package/dist/utils/project-namespace.d.ts +24 -0
  332. package/dist/utils/project-namespace.js +84 -0
  333. package/dist/wrapper/parser.d.ts +10 -0
  334. package/dist/wrapper/parser.js +100 -33
  335. package/dist/wrapper/pty-wrapper.d.ts +197 -16
  336. package/dist/wrapper/pty-wrapper.js +943 -106
  337. package/dist/wrapper/shared.d.ts +165 -0
  338. package/dist/wrapper/shared.js +270 -0
  339. package/dist/wrapper/tmux-wrapper.d.ts +73 -11
  340. package/dist/wrapper/tmux-wrapper.js +541 -120
  341. package/package.json +16 -16
  342. package/scripts/postinstall.js +60 -0
  343. package/test-push.txt +1 -0
  344. package/bin/tmux +0 -0
  345. package/dist/bridge/config.d.ts.map +0 -1
  346. package/dist/bridge/config.js.map +0 -1
  347. package/dist/bridge/index.d.ts.map +0 -1
  348. package/dist/bridge/index.js.map +0 -1
  349. package/dist/bridge/multi-project-client.d.ts.map +0 -1
  350. package/dist/bridge/multi-project-client.js.map +0 -1
  351. package/dist/bridge/shadow-cli.d.ts.map +0 -1
  352. package/dist/bridge/shadow-cli.js.map +0 -1
  353. package/dist/bridge/shadow-config.d.ts.map +0 -1
  354. package/dist/bridge/shadow-config.js.map +0 -1
  355. package/dist/bridge/spawner.d.ts.map +0 -1
  356. package/dist/bridge/spawner.js.map +0 -1
  357. package/dist/bridge/teams-config.d.ts.map +0 -1
  358. package/dist/bridge/teams-config.js.map +0 -1
  359. package/dist/bridge/types.d.ts.map +0 -1
  360. package/dist/bridge/types.js.map +0 -1
  361. package/dist/bridge/utils.d.ts.map +0 -1
  362. package/dist/bridge/utils.js.map +0 -1
  363. package/dist/cli/index.d.ts.map +0 -1
  364. package/dist/cli/index.js.map +0 -1
  365. package/dist/cloud/api/auth.d.ts.map +0 -1
  366. package/dist/cloud/api/auth.js.map +0 -1
  367. package/dist/cloud/api/billing.d.ts.map +0 -1
  368. package/dist/cloud/api/billing.js.map +0 -1
  369. package/dist/cloud/api/coordinators.d.ts.map +0 -1
  370. package/dist/cloud/api/coordinators.js.map +0 -1
  371. package/dist/cloud/api/daemons.d.ts.map +0 -1
  372. package/dist/cloud/api/daemons.js.map +0 -1
  373. package/dist/cloud/api/middleware/planLimits.d.ts.map +0 -1
  374. package/dist/cloud/api/middleware/planLimits.js.map +0 -1
  375. package/dist/cloud/api/onboarding.d.ts.map +0 -1
  376. package/dist/cloud/api/onboarding.js.map +0 -1
  377. package/dist/cloud/api/providers.d.ts.map +0 -1
  378. package/dist/cloud/api/providers.js.map +0 -1
  379. package/dist/cloud/api/repos.d.ts.map +0 -1
  380. package/dist/cloud/api/repos.js.map +0 -1
  381. package/dist/cloud/api/teams.d.ts.map +0 -1
  382. package/dist/cloud/api/teams.js.map +0 -1
  383. package/dist/cloud/api/usage.d.ts.map +0 -1
  384. package/dist/cloud/api/usage.js.map +0 -1
  385. package/dist/cloud/api/workspaces.d.ts.map +0 -1
  386. package/dist/cloud/api/workspaces.js.map +0 -1
  387. package/dist/cloud/billing/index.d.ts.map +0 -1
  388. package/dist/cloud/billing/index.js.map +0 -1
  389. package/dist/cloud/billing/plans.d.ts.map +0 -1
  390. package/dist/cloud/billing/plans.js.map +0 -1
  391. package/dist/cloud/billing/service.d.ts.map +0 -1
  392. package/dist/cloud/billing/service.js.map +0 -1
  393. package/dist/cloud/billing/types.d.ts.map +0 -1
  394. package/dist/cloud/billing/types.js.map +0 -1
  395. package/dist/cloud/config.d.ts.map +0 -1
  396. package/dist/cloud/config.js.map +0 -1
  397. package/dist/cloud/db/drizzle.d.ts.map +0 -1
  398. package/dist/cloud/db/drizzle.js.map +0 -1
  399. package/dist/cloud/db/index.d.ts.map +0 -1
  400. package/dist/cloud/db/index.js.map +0 -1
  401. package/dist/cloud/db/schema.d.ts.map +0 -1
  402. package/dist/cloud/db/schema.js.map +0 -1
  403. package/dist/cloud/index.d.ts.map +0 -1
  404. package/dist/cloud/index.js.map +0 -1
  405. package/dist/cloud/provisioner/index.d.ts.map +0 -1
  406. package/dist/cloud/provisioner/index.js.map +0 -1
  407. package/dist/cloud/server.d.ts.map +0 -1
  408. package/dist/cloud/server.js.map +0 -1
  409. package/dist/cloud/services/coordinator.d.ts.map +0 -1
  410. package/dist/cloud/services/coordinator.js.map +0 -1
  411. package/dist/cloud/services/planLimits.d.ts.map +0 -1
  412. package/dist/cloud/services/planLimits.js.map +0 -1
  413. package/dist/cloud/vault/index.d.ts.map +0 -1
  414. package/dist/cloud/vault/index.js.map +0 -1
  415. package/dist/daemon/agent-manager.d.ts.map +0 -1
  416. package/dist/daemon/agent-manager.js.map +0 -1
  417. package/dist/daemon/agent-registry.d.ts.map +0 -1
  418. package/dist/daemon/agent-registry.js.map +0 -1
  419. package/dist/daemon/api.d.ts.map +0 -1
  420. package/dist/daemon/api.js.map +0 -1
  421. package/dist/daemon/auth.d.ts.map +0 -1
  422. package/dist/daemon/auth.js.map +0 -1
  423. package/dist/daemon/cloud-sync.d.ts.map +0 -1
  424. package/dist/daemon/cloud-sync.js.map +0 -1
  425. package/dist/daemon/connection.d.ts.map +0 -1
  426. package/dist/daemon/connection.js.map +0 -1
  427. package/dist/daemon/index.d.ts.map +0 -1
  428. package/dist/daemon/index.js.map +0 -1
  429. package/dist/daemon/orchestrator.d.ts.map +0 -1
  430. package/dist/daemon/orchestrator.js.map +0 -1
  431. package/dist/daemon/registry.d.ts.map +0 -1
  432. package/dist/daemon/registry.js.map +0 -1
  433. package/dist/daemon/router.d.ts.map +0 -1
  434. package/dist/daemon/router.js.map +0 -1
  435. package/dist/daemon/server.d.ts.map +0 -1
  436. package/dist/daemon/server.js.map +0 -1
  437. package/dist/daemon/types.d.ts.map +0 -1
  438. package/dist/daemon/types.js.map +0 -1
  439. package/dist/daemon/workspace-manager.d.ts.map +0 -1
  440. package/dist/daemon/workspace-manager.js.map +0 -1
  441. package/dist/dashboard/out/_next/static/chunks/693-7b3301d8f6bc5014.js +0 -1
  442. package/dist/dashboard/out/_next/static/chunks/713-f78477eb185f1f4d.js +0 -1
  443. package/dist/dashboard/out/_next/static/chunks/766-e53e1cfe39b0b5b5.js +0 -1
  444. package/dist/dashboard/out/_next/static/chunks/900-037c64bfd797fb2a.js +0 -1
  445. package/dist/dashboard/out/_next/static/chunks/app/app/page-e3d9e1f4466b9bae.js +0 -1
  446. package/dist/dashboard/out/_next/static/chunks/app/layout-2433bb48965f4333.js +0 -1
  447. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-e68825a81db67ba1.js +0 -1
  448. package/dist/dashboard/out/_next/static/chunks/app/page-cc108bf68c8a657f.js +0 -1
  449. package/dist/dashboard/out/_next/static/chunks/app/pricing/page-d80e03a5297f95b6.js +0 -1
  450. package/dist/dashboard/out/_next/static/chunks/webpack-a5acc2831d094776.js +0 -1
  451. package/dist/dashboard/out/_next/static/css/79b80143647a07d7.css +0 -1
  452. package/dist/dashboard/out/_next/static/css/8cf277370ad48cfe.css +0 -1
  453. package/dist/dashboard-server/metrics.d.ts.map +0 -1
  454. package/dist/dashboard-server/metrics.js.map +0 -1
  455. package/dist/dashboard-server/needs-attention.d.ts.map +0 -1
  456. package/dist/dashboard-server/needs-attention.js.map +0 -1
  457. package/dist/dashboard-server/server.d.ts.map +0 -1
  458. package/dist/dashboard-server/server.js.map +0 -1
  459. package/dist/dashboard-server/start.d.ts.map +0 -1
  460. package/dist/dashboard-server/start.js.map +0 -1
  461. package/dist/hooks/inbox-check/hook.d.ts.map +0 -1
  462. package/dist/hooks/inbox-check/hook.js.map +0 -1
  463. package/dist/hooks/inbox-check/index.d.ts.map +0 -1
  464. package/dist/hooks/inbox-check/index.js.map +0 -1
  465. package/dist/hooks/inbox-check/types.d.ts.map +0 -1
  466. package/dist/hooks/inbox-check/types.js.map +0 -1
  467. package/dist/hooks/inbox-check/utils.d.ts.map +0 -1
  468. package/dist/hooks/inbox-check/utils.js.map +0 -1
  469. package/dist/hooks/index.d.ts.map +0 -1
  470. package/dist/hooks/index.js.map +0 -1
  471. package/dist/hooks/types.d.ts.map +0 -1
  472. package/dist/hooks/types.js.map +0 -1
  473. package/dist/index.d.ts.map +0 -1
  474. package/dist/index.js.map +0 -1
  475. package/dist/protocol/framing.d.ts.map +0 -1
  476. package/dist/protocol/framing.js.map +0 -1
  477. package/dist/protocol/index.d.ts.map +0 -1
  478. package/dist/protocol/index.js.map +0 -1
  479. package/dist/protocol/types.d.ts.map +0 -1
  480. package/dist/protocol/types.js.map +0 -1
  481. package/dist/resiliency/context-persistence.d.ts.map +0 -1
  482. package/dist/resiliency/context-persistence.js.map +0 -1
  483. package/dist/resiliency/health-monitor.d.ts.map +0 -1
  484. package/dist/resiliency/health-monitor.js.map +0 -1
  485. package/dist/resiliency/index.d.ts.map +0 -1
  486. package/dist/resiliency/index.js.map +0 -1
  487. package/dist/resiliency/logger.d.ts.map +0 -1
  488. package/dist/resiliency/logger.js.map +0 -1
  489. package/dist/resiliency/metrics.d.ts.map +0 -1
  490. package/dist/resiliency/metrics.js.map +0 -1
  491. package/dist/resiliency/provider-context.d.ts.map +0 -1
  492. package/dist/resiliency/provider-context.js.map +0 -1
  493. package/dist/resiliency/supervisor.d.ts.map +0 -1
  494. package/dist/resiliency/supervisor.js.map +0 -1
  495. package/dist/state/agent-state.d.ts.map +0 -1
  496. package/dist/state/agent-state.js.map +0 -1
  497. package/dist/storage/adapter.d.ts.map +0 -1
  498. package/dist/storage/adapter.js.map +0 -1
  499. package/dist/storage/sqlite-adapter.d.ts.map +0 -1
  500. package/dist/storage/sqlite-adapter.js.map +0 -1
  501. package/dist/utils/agent-config.d.ts.map +0 -1
  502. package/dist/utils/agent-config.js.map +0 -1
  503. package/dist/utils/command-resolver.d.ts.map +0 -1
  504. package/dist/utils/command-resolver.js.map +0 -1
  505. package/dist/utils/index.d.ts.map +0 -1
  506. package/dist/utils/index.js.map +0 -1
  507. package/dist/utils/logger.d.ts.map +0 -1
  508. package/dist/utils/logger.js.map +0 -1
  509. package/dist/utils/name-generator.d.ts.map +0 -1
  510. package/dist/utils/name-generator.js.map +0 -1
  511. package/dist/utils/project-namespace.d.ts.map +0 -1
  512. package/dist/utils/project-namespace.js.map +0 -1
  513. package/dist/utils/tmux-resolver.d.ts.map +0 -1
  514. package/dist/utils/tmux-resolver.js.map +0 -1
  515. package/dist/utils/update-checker.d.ts.map +0 -1
  516. package/dist/utils/update-checker.js.map +0 -1
  517. package/dist/wrapper/client.d.ts.map +0 -1
  518. package/dist/wrapper/client.js.map +0 -1
  519. package/dist/wrapper/inbox.d.ts.map +0 -1
  520. package/dist/wrapper/inbox.js.map +0 -1
  521. package/dist/wrapper/index.d.ts.map +0 -1
  522. package/dist/wrapper/index.js.map +0 -1
  523. package/dist/wrapper/parser.d.ts.map +0 -1
  524. package/dist/wrapper/parser.js.map +0 -1
  525. package/dist/wrapper/pty-wrapper.d.ts.map +0 -1
  526. package/dist/wrapper/pty-wrapper.js.map +0 -1
  527. package/dist/wrapper/tmux-wrapper.d.ts.map +0 -1
  528. package/dist/wrapper/tmux-wrapper.js.map +0 -1
  529. package/docs/AGENTS.md +0 -513
  530. package/docs/ARCHITECTURE_DECISIONS.md +0 -175
  531. package/docs/CHANGELOG.md +0 -11
  532. package/docs/CLI-SIMPLIFICATION-COMPLETE.md +0 -48
  533. package/docs/CLOUD-ARCHITECTURE.md +0 -652
  534. package/docs/CLOUD-ONBOARDING-DESIGN.md +0 -1983
  535. package/docs/COMPETITIVE_ANALYSIS.md +0 -897
  536. package/docs/CONTRIBUTING.md +0 -151
  537. package/docs/DESIGN_BRIDGE_STAFFING.md +0 -878
  538. package/docs/DESIGN_V2.md +0 -1079
  539. package/docs/INTEGRATION-GUIDE.md +0 -926
  540. package/docs/MONETIZATION.md +0 -1679
  541. package/docs/PROPOSAL-trajectories.md +0 -1582
  542. package/docs/PROTOCOL.md +0 -325
  543. package/docs/SCALING_ANALYSIS.md +0 -280
  544. package/docs/TESTING_PRESENCE_FEATURES.md +0 -327
  545. package/docs/TMUX_IMPLEMENTATION_NOTES.md +0 -364
  546. package/docs/TMUX_IMPROVEMENTS.md +0 -968
  547. package/docs/agent-relay-snippet.md +0 -168
  548. package/docs/competitive-analysis-mcp-agent-mail.md +0 -389
  549. package/docs/dashboard-v2-plan.md +0 -179
  550. package/docs/guides/CLOUD.md +0 -236
  551. package/docs/guides/LOCAL.md +0 -535
  552. package/docs/guides/SELF-HOSTED.md +0 -494
  553. package/docs/proposals/shadow-as-subagent.md +0 -765
  554. package/docs/proposals/slack-bot-integration.md +0 -1457
  555. package/docs/removable-code-analysis.md +0 -24
  556. package/scripts/dev/PUBLIC_RELEASE_PLAN.md +0 -88
  557. package/scripts/dev/dev-team-setup.sh +0 -431
  558. package/scripts/e2e-test.sh +0 -119
  559. package/scripts/games/game-protocol.md +0 -79
  560. package/scripts/games/hearts-setup.sh +0 -264
  561. package/scripts/tictactoe-setup.sh +0 -181
  562. /package/dist/dashboard/out/_next/static/chunks/{117-b2cd8d6485aacf2b.js → 117-f7b8ab0809342e77.js} +0 -0
  563. /package/dist/dashboard/out/_next/static/chunks/{648-8f3f26864ce515e5.js → 648-5cc6e1921389a58a.js} +0 -0
  564. /package/dist/dashboard/out/_next/static/chunks/app/_not-found/{page-0b990dbb71d72a98.js → page-53b8a69f76db17d0.js} +0 -0
  565. /package/dist/dashboard/out/_next/static/chunks/{fd9d1056-bf46c09eb57e019c.js → fd9d1056-609918ca7b6280bb.js} +0 -0
  566. /package/dist/dashboard/out/_next/static/{6HHWb2ZmnJ4OSm0zUP7h4 → wPgKJtcOmTFLpUncDg16A}/_buildManifest.js +0 -0
  567. /package/dist/dashboard/out/_next/static/{6HHWb2ZmnJ4OSm0zUP7h4 → wPgKJtcOmTFLpUncDg16A}/_ssgManifest.js +0 -0
@@ -0,0 +1,476 @@
1
+ /**
2
+ * Hook Registry
3
+ *
4
+ * Manages lifecycle hooks and pattern handlers for agent sessions.
5
+ * Provides a centralized way to register, unregister, and dispatch hooks.
6
+ */
7
+ import { randomUUID } from 'node:crypto';
8
+ /**
9
+ * Simple in-memory implementation of HookMemory
10
+ */
11
+ class InMemoryHookMemory {
12
+ store = new Map();
13
+ get(key) {
14
+ return this.store.get(key);
15
+ }
16
+ set(key, value) {
17
+ this.store.set(key, value);
18
+ }
19
+ delete(key) {
20
+ return this.store.delete(key);
21
+ }
22
+ has(key) {
23
+ return this.store.has(key);
24
+ }
25
+ clear() {
26
+ this.store.clear();
27
+ }
28
+ }
29
+ /**
30
+ * HookRegistry manages lifecycle hooks and dispatches events
31
+ */
32
+ export class HookRegistry {
33
+ sessionId;
34
+ agentId;
35
+ agentName;
36
+ workingDir;
37
+ projectId;
38
+ env;
39
+ task;
40
+ taskId;
41
+ taskSource;
42
+ memory;
43
+ relay;
44
+ outputHistory = [];
45
+ messageHistory = [];
46
+ sessionStartHooks = [];
47
+ sessionEndHooks = [];
48
+ outputHooks = [];
49
+ messageReceivedHooks = [];
50
+ messageSentHooks = [];
51
+ idleHooks = [];
52
+ errorHooks = [];
53
+ patternHandlers = new Map();
54
+ idleTimeout;
55
+ idleTimer;
56
+ idleCount = 0;
57
+ lastActivityTime = Date.now();
58
+ sessionStartTime = Date.now();
59
+ injectFn;
60
+ sendFn;
61
+ constructor(options = {}) {
62
+ this.sessionId = randomUUID();
63
+ this.agentId = options.agentId ?? randomUUID();
64
+ this.agentName = options.agentName ?? 'agent';
65
+ this.workingDir = options.workingDir ?? process.cwd();
66
+ this.projectId = options.projectId ?? 'default';
67
+ this.env = options.env ?? {};
68
+ this.task = options.task;
69
+ this.taskId = options.taskId;
70
+ this.taskSource = options.taskSource;
71
+ this.idleTimeout = options.idleTimeout ?? 30000;
72
+ this.injectFn = options.inject;
73
+ this.sendFn = options.send;
74
+ this.memory = new InMemoryHookMemory();
75
+ // Create relay interface (using arrow functions to capture 'this')
76
+ this.relay = {
77
+ send: async (to, body) => {
78
+ if (this.sendFn) {
79
+ await this.sendFn(to, body);
80
+ }
81
+ },
82
+ isConnected: () => {
83
+ return !!this.sendFn;
84
+ },
85
+ getAgentName: () => {
86
+ return this.agentName;
87
+ },
88
+ };
89
+ }
90
+ /**
91
+ * Register hooks from a configuration object
92
+ */
93
+ registerHooks(config) {
94
+ if (config.hooks) {
95
+ this.registerLifecycleHooks(config.hooks);
96
+ }
97
+ if (config.patterns) {
98
+ for (const [namespace, handler] of Object.entries(config.patterns)) {
99
+ if (handler !== 'builtin') {
100
+ this.registerPattern(namespace, handler);
101
+ }
102
+ }
103
+ }
104
+ if (config.idleTimeout !== undefined) {
105
+ this.idleTimeout = config.idleTimeout;
106
+ }
107
+ // Register memory hooks if configured
108
+ if (config.memory) {
109
+ this.registerMemoryHooksFromConfig(config.memory);
110
+ }
111
+ }
112
+ /**
113
+ * Register memory hooks from configuration
114
+ */
115
+ async registerMemoryHooksFromConfig(config) {
116
+ try {
117
+ // Dynamic import to avoid circular dependencies
118
+ const { createMemoryHooks } = await import('../memory/memory-hooks.js');
119
+ // Handle boolean config (true = use defaults)
120
+ if (config === true || config === false) {
121
+ if (!config)
122
+ return; // false means disabled
123
+ const hooks = createMemoryHooks({
124
+ agentId: this.agentId,
125
+ projectId: this.projectId,
126
+ });
127
+ this.registerLifecycleHooks(hooks);
128
+ return;
129
+ }
130
+ // Handle object config
131
+ const hooks = createMemoryHooks({
132
+ config: {
133
+ type: config.type,
134
+ apiKey: config.apiKey,
135
+ endpoint: config.endpoint,
136
+ },
137
+ agentId: this.agentId,
138
+ projectId: this.projectId,
139
+ injectOnStart: config.injectOnStart,
140
+ maxStartMemories: config.maxStartMemories,
141
+ promptOnEnd: config.promptOnEnd,
142
+ autoSave: config.autoSave,
143
+ autoSaveOnEnd: config.autoSaveOnEnd,
144
+ });
145
+ this.registerLifecycleHooks(hooks);
146
+ }
147
+ catch (error) {
148
+ console.error('[hooks] Failed to register memory hooks:', error);
149
+ }
150
+ }
151
+ /**
152
+ * Register memory hooks with custom options
153
+ */
154
+ async registerMemoryHooks(options) {
155
+ await this.registerMemoryHooksFromConfig(options ?? {});
156
+ }
157
+ /**
158
+ * Register lifecycle hooks
159
+ */
160
+ registerLifecycleHooks(hooks) {
161
+ if (hooks.onSessionStart) {
162
+ this.addHooks('sessionStart', hooks.onSessionStart);
163
+ }
164
+ if (hooks.onSessionEnd) {
165
+ this.addHooks('sessionEnd', hooks.onSessionEnd);
166
+ }
167
+ if (hooks.onOutput) {
168
+ this.addHooks('output', hooks.onOutput);
169
+ }
170
+ if (hooks.onMessageReceived) {
171
+ this.addHooks('messageReceived', hooks.onMessageReceived);
172
+ }
173
+ if (hooks.onMessageSent) {
174
+ this.addHooks('messageSent', hooks.onMessageSent);
175
+ }
176
+ if (hooks.onIdle) {
177
+ this.addHooks('idle', hooks.onIdle);
178
+ }
179
+ if (hooks.onError) {
180
+ this.addHooks('error', hooks.onError);
181
+ }
182
+ }
183
+ /**
184
+ * Add hooks for a specific event
185
+ */
186
+ addHooks(event, hooks) {
187
+ const hookArray = Array.isArray(hooks) ? hooks : [hooks];
188
+ switch (event) {
189
+ case 'sessionStart':
190
+ this.sessionStartHooks.push(...hookArray);
191
+ break;
192
+ case 'sessionEnd':
193
+ this.sessionEndHooks.push(...hookArray);
194
+ break;
195
+ case 'output':
196
+ this.outputHooks.push(...hookArray);
197
+ break;
198
+ case 'messageReceived':
199
+ this.messageReceivedHooks.push(...hookArray);
200
+ break;
201
+ case 'messageSent':
202
+ this.messageSentHooks.push(...hookArray);
203
+ break;
204
+ case 'idle':
205
+ this.idleHooks.push(...hookArray);
206
+ break;
207
+ case 'error':
208
+ this.errorHooks.push(...hookArray);
209
+ break;
210
+ }
211
+ }
212
+ /**
213
+ * Register a pattern handler
214
+ */
215
+ registerPattern(namespace, handler) {
216
+ this.patternHandlers.set(namespace, handler);
217
+ }
218
+ /**
219
+ * Get the base hook context
220
+ */
221
+ getBaseContext() {
222
+ return {
223
+ agentId: this.agentId,
224
+ sessionId: this.sessionId,
225
+ workingDir: this.workingDir,
226
+ env: this.env,
227
+ inject: (content) => {
228
+ if (this.injectFn) {
229
+ this.injectFn(content);
230
+ }
231
+ },
232
+ send: async (to, body) => {
233
+ if (this.sendFn) {
234
+ await this.sendFn(to, body);
235
+ }
236
+ },
237
+ memory: this.memory,
238
+ relay: this.relay,
239
+ output: [...this.outputHistory],
240
+ messages: [...this.messageHistory],
241
+ };
242
+ }
243
+ /**
244
+ * Run hooks and collect results
245
+ */
246
+ async runHooks(hooks, context) {
247
+ const combinedResult = {};
248
+ for (const hook of hooks) {
249
+ try {
250
+ const result = await hook(context);
251
+ if (result) {
252
+ if (result.inject) {
253
+ combinedResult.inject = (combinedResult.inject ?? '') + result.inject;
254
+ }
255
+ if (result.suppress) {
256
+ combinedResult.suppress = true;
257
+ }
258
+ if (result.stop) {
259
+ combinedResult.stop = true;
260
+ break;
261
+ }
262
+ }
263
+ }
264
+ catch (err) {
265
+ console.error('[hooks] Hook execution error:', err);
266
+ }
267
+ }
268
+ // Execute injection if any
269
+ if (combinedResult.inject && this.injectFn) {
270
+ this.injectFn(combinedResult.inject);
271
+ }
272
+ return combinedResult;
273
+ }
274
+ /**
275
+ * Dispatch session start event
276
+ */
277
+ async dispatchSessionStart() {
278
+ this.sessionStartTime = Date.now();
279
+ this.startIdleTimer();
280
+ const context = {
281
+ ...this.getBaseContext(),
282
+ task: this.task,
283
+ taskId: this.taskId,
284
+ taskSource: this.taskSource,
285
+ };
286
+ return this.runHooks(this.sessionStartHooks, context);
287
+ }
288
+ /**
289
+ * Dispatch session end event
290
+ */
291
+ async dispatchSessionEnd(exitCode, graceful = true) {
292
+ this.stopIdleTimer();
293
+ const context = {
294
+ ...this.getBaseContext(),
295
+ exitCode,
296
+ duration: Date.now() - this.sessionStartTime,
297
+ graceful,
298
+ };
299
+ return this.runHooks(this.sessionEndHooks, context);
300
+ }
301
+ /**
302
+ * Dispatch output event
303
+ */
304
+ async dispatchOutput(content, rawContent, isComplete = true) {
305
+ this.resetIdleTimer();
306
+ // Record in history
307
+ this.outputHistory.push({
308
+ type: 'text',
309
+ content,
310
+ timestamp: Date.now(),
311
+ });
312
+ const context = {
313
+ ...this.getBaseContext(),
314
+ content,
315
+ rawContent,
316
+ isComplete,
317
+ };
318
+ // Check for patterns
319
+ await this.checkPatterns(content, context);
320
+ return this.runHooks(this.outputHooks, context);
321
+ }
322
+ /**
323
+ * Dispatch message received event
324
+ */
325
+ async dispatchMessageReceived(from, body, messageId, thread) {
326
+ this.resetIdleTimer();
327
+ // Record in history
328
+ this.messageHistory.push({
329
+ role: 'user',
330
+ content: `[${from}]: ${body}`,
331
+ timestamp: Date.now(),
332
+ });
333
+ const context = {
334
+ ...this.getBaseContext(),
335
+ from,
336
+ body,
337
+ messageId,
338
+ thread,
339
+ };
340
+ return this.runHooks(this.messageReceivedHooks, context);
341
+ }
342
+ /**
343
+ * Dispatch message sent event
344
+ */
345
+ async dispatchMessageSent(to, body, thread) {
346
+ this.resetIdleTimer();
347
+ // Record in history
348
+ this.messageHistory.push({
349
+ role: 'assistant',
350
+ content: `[to ${to}]: ${body}`,
351
+ timestamp: Date.now(),
352
+ });
353
+ const context = {
354
+ ...this.getBaseContext(),
355
+ to,
356
+ body,
357
+ thread,
358
+ };
359
+ return this.runHooks(this.messageSentHooks, context);
360
+ }
361
+ /**
362
+ * Dispatch idle event
363
+ */
364
+ async dispatchIdle() {
365
+ this.idleCount++;
366
+ const context = {
367
+ ...this.getBaseContext(),
368
+ idleDuration: Date.now() - this.lastActivityTime,
369
+ idleCount: this.idleCount,
370
+ };
371
+ const result = await this.runHooks(this.idleHooks, context);
372
+ // Restart idle timer
373
+ this.startIdleTimer();
374
+ return result;
375
+ }
376
+ /**
377
+ * Dispatch error event
378
+ */
379
+ async dispatchError(error, phase) {
380
+ const context = {
381
+ ...this.getBaseContext(),
382
+ error,
383
+ phase,
384
+ };
385
+ return this.runHooks(this.errorHooks, context);
386
+ }
387
+ /**
388
+ * Check content for pattern matches
389
+ */
390
+ async checkPatterns(content, baseContext) {
391
+ // Match patterns like @namespace:target message
392
+ const patternRegex = /@(\w+):(\S+)\s*(.*)/g;
393
+ let match;
394
+ while ((match = patternRegex.exec(content)) !== null) {
395
+ const [, namespace, target, message] = match;
396
+ const handler = this.patternHandlers.get(namespace);
397
+ if (handler) {
398
+ try {
399
+ const result = await handler(target, message.trim(), baseContext);
400
+ if (result?.inject && this.injectFn) {
401
+ this.injectFn(result.inject);
402
+ }
403
+ }
404
+ catch (err) {
405
+ console.error(`[hooks] Pattern handler error for @${namespace}:`, err);
406
+ }
407
+ }
408
+ }
409
+ }
410
+ /**
411
+ * Start idle timer
412
+ */
413
+ startIdleTimer() {
414
+ this.stopIdleTimer();
415
+ if (this.idleHooks.length > 0 && this.idleTimeout > 0) {
416
+ this.idleTimer = setTimeout(() => {
417
+ this.dispatchIdle().catch(console.error);
418
+ }, this.idleTimeout);
419
+ }
420
+ }
421
+ /**
422
+ * Stop idle timer
423
+ */
424
+ stopIdleTimer() {
425
+ if (this.idleTimer) {
426
+ clearTimeout(this.idleTimer);
427
+ this.idleTimer = undefined;
428
+ }
429
+ }
430
+ /**
431
+ * Reset idle timer on activity
432
+ */
433
+ resetIdleTimer() {
434
+ this.lastActivityTime = Date.now();
435
+ this.startIdleTimer();
436
+ }
437
+ /**
438
+ * Get session info
439
+ */
440
+ getSessionInfo() {
441
+ return {
442
+ sessionId: this.sessionId,
443
+ agentId: this.agentId,
444
+ startTime: new Date(this.sessionStartTime),
445
+ duration: Date.now() - this.sessionStartTime,
446
+ };
447
+ }
448
+ /**
449
+ * Update inject function
450
+ */
451
+ setInjectFn(fn) {
452
+ this.injectFn = fn;
453
+ }
454
+ /**
455
+ * Update send function
456
+ */
457
+ setSendFn(fn) {
458
+ this.sendFn = fn;
459
+ }
460
+ /**
461
+ * Cleanup
462
+ */
463
+ destroy() {
464
+ this.stopIdleTimer();
465
+ this.memory.clear();
466
+ this.sessionStartHooks = [];
467
+ this.sessionEndHooks = [];
468
+ this.outputHooks = [];
469
+ this.messageReceivedHooks = [];
470
+ this.messageSentHooks = [];
471
+ this.idleHooks = [];
472
+ this.errorHooks = [];
473
+ this.patternHandlers.clear();
474
+ }
475
+ }
476
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Trajectory Hooks
3
+ *
4
+ * Provides trajectory tracking hooks that integrate with the PDERO paradigm.
5
+ * These hooks automatically track agent work when registered with a HookRegistry.
6
+ */
7
+ import type { LifecycleHooks } from './types.js';
8
+ /**
9
+ * Options for trajectory hooks
10
+ */
11
+ export interface TrajectoryHooksOptions {
12
+ /** Project identifier */
13
+ projectId: string;
14
+ /** Agent name */
15
+ agentName: string;
16
+ /** Whether to auto-detect phase transitions */
17
+ autoDetectPhase?: boolean;
18
+ /** Whether to detect and record tool calls */
19
+ detectTools?: boolean;
20
+ /** Whether to detect and record errors */
21
+ detectErrors?: boolean;
22
+ /** Whether to inject trail instructions on session start */
23
+ injectInstructions?: boolean;
24
+ /** Whether to prompt for retrospective on session end */
25
+ promptRetrospective?: boolean;
26
+ }
27
+ /**
28
+ * Create trajectory hooks for automatic PDERO tracking
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const hooks = createTrajectoryHooks({
33
+ * projectId: 'my-project',
34
+ * agentName: 'Alice',
35
+ * });
36
+ *
37
+ * registry.registerLifecycleHooks(hooks);
38
+ * ```
39
+ */
40
+ export declare function createTrajectoryHooks(options: TrajectoryHooksOptions): LifecycleHooks;
41
+ /**
42
+ * Get trajectory hooks for a project/agent combination
43
+ *
44
+ * This is a convenience function that creates trajectory hooks
45
+ * with default options.
46
+ */
47
+ export declare function getTrajectoryHooks(projectId: string, agentName: string): LifecycleHooks;
48
+ /**
49
+ * Utility to check if trajectory tracking is available
50
+ */
51
+ export declare function isTrajectoryTrackingAvailable(projectId: string, agentName: string): boolean;
52
+ //# sourceMappingURL=trajectory-hooks.d.ts.map
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Trajectory Hooks
3
+ *
4
+ * Provides trajectory tracking hooks that integrate with the PDERO paradigm.
5
+ * These hooks automatically track agent work when registered with a HookRegistry.
6
+ */
7
+ import { getTrajectoryIntegration, detectPhaseFromContent, detectToolCalls, detectErrors, getCompactTrailInstructions, } from '../trajectory/integration.js';
8
+ /**
9
+ * Create trajectory hooks for automatic PDERO tracking
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const hooks = createTrajectoryHooks({
14
+ * projectId: 'my-project',
15
+ * agentName: 'Alice',
16
+ * });
17
+ *
18
+ * registry.registerLifecycleHooks(hooks);
19
+ * ```
20
+ */
21
+ export function createTrajectoryHooks(options) {
22
+ const state = {
23
+ trajectory: getTrajectoryIntegration(options.projectId, options.agentName),
24
+ seenTools: new Set(),
25
+ seenErrors: new Set(),
26
+ options: {
27
+ autoDetectPhase: true,
28
+ detectTools: true,
29
+ detectErrors: true,
30
+ injectInstructions: true,
31
+ promptRetrospective: true,
32
+ ...options,
33
+ },
34
+ };
35
+ return {
36
+ onSessionStart: createSessionStartHook(state),
37
+ onSessionEnd: createSessionEndHook(state),
38
+ onOutput: createOutputHook(state),
39
+ onMessageReceived: createMessageReceivedHook(state),
40
+ onMessageSent: createMessageSentHook(state),
41
+ };
42
+ }
43
+ /**
44
+ * Session start hook - initializes trajectory tracking
45
+ */
46
+ function createSessionStartHook(state) {
47
+ return async (ctx) => {
48
+ const { trajectory, options } = state;
49
+ // Initialize trajectory with task if provided
50
+ if (ctx.task) {
51
+ const success = await trajectory.initialize(ctx.task, ctx.taskId, ctx.taskSource);
52
+ if (success) {
53
+ console.log(`[trajectory] Started tracking: ${ctx.task}`);
54
+ }
55
+ }
56
+ else {
57
+ await trajectory.initialize();
58
+ }
59
+ // Inject trail instructions if enabled and trail is available
60
+ if (options.injectInstructions && trajectory.isTrailInstalledSync()) {
61
+ const instructions = getCompactTrailInstructions();
62
+ return { inject: `\n${instructions}\n` };
63
+ }
64
+ };
65
+ }
66
+ /**
67
+ * Session end hook - completes or abandons trajectory
68
+ */
69
+ function createSessionEndHook(state) {
70
+ return async (ctx) => {
71
+ const { trajectory, options } = state;
72
+ if (!trajectory.hasActiveTrajectory()) {
73
+ return;
74
+ }
75
+ if (ctx.graceful) {
76
+ // Prompt for retrospective if enabled
77
+ if (options.promptRetrospective) {
78
+ const durationSeconds = Math.round(ctx.duration / 1000);
79
+ const result = {
80
+ inject: `
81
+ [SESSION ENDING]
82
+ Complete your trajectory with a summary:
83
+ trail complete --summary "What you accomplished" --confidence 0.9
84
+
85
+ Or if you need to document learnings:
86
+ trail decision "Key choice" --reasoning "Why"
87
+ `,
88
+ };
89
+ // Also complete the trajectory
90
+ await trajectory.complete({
91
+ summary: `Session ended after ${durationSeconds}s`,
92
+ });
93
+ return result;
94
+ }
95
+ else {
96
+ await trajectory.complete({
97
+ summary: `Session ended gracefully`,
98
+ });
99
+ }
100
+ }
101
+ else {
102
+ await trajectory.abandon('Session terminated');
103
+ }
104
+ };
105
+ }
106
+ /**
107
+ * Output hook - auto-detects PDERO phase transitions, tool calls, and errors
108
+ */
109
+ function createOutputHook(state) {
110
+ return async (ctx) => {
111
+ const { trajectory, options } = state;
112
+ // Detect and record phase transitions
113
+ if (options.autoDetectPhase) {
114
+ const detectedPhase = detectPhaseFromContent(ctx.content);
115
+ if (detectedPhase && detectedPhase !== state.lastDetectedPhase) {
116
+ state.lastDetectedPhase = detectedPhase;
117
+ await trajectory.transition(detectedPhase, 'Auto-detected from output');
118
+ }
119
+ }
120
+ // Detect and record tool calls
121
+ // Note: We deduplicate by tool+status to record each unique tool type once per session
122
+ // (e.g., "Read" started, "Read" completed). This provides a summary of tools used
123
+ // without flooding the trajectory with every individual invocation.
124
+ if (options.detectTools) {
125
+ const tools = detectToolCalls(ctx.content);
126
+ for (const tool of tools) {
127
+ const key = `${tool.tool}:${tool.status || 'started'}`;
128
+ if (!state.seenTools.has(key)) {
129
+ state.seenTools.add(key);
130
+ const statusLabel = tool.status === 'completed' ? ' (completed)' : '';
131
+ await trajectory.event(`Tool: ${tool.tool}${statusLabel}`, 'tool_call');
132
+ }
133
+ }
134
+ }
135
+ // Detect and record errors
136
+ if (options.detectErrors) {
137
+ const errors = detectErrors(ctx.content);
138
+ for (const error of errors) {
139
+ // Deduplicate by message content
140
+ if (!state.seenErrors.has(error.message)) {
141
+ state.seenErrors.add(error.message);
142
+ const prefix = error.type === 'warning' ? 'Warning' : 'Error';
143
+ await trajectory.event(`${prefix}: ${error.message}`, 'error');
144
+ }
145
+ }
146
+ }
147
+ };
148
+ }
149
+ /**
150
+ * Message received hook - records incoming messages
151
+ */
152
+ function createMessageReceivedHook(state) {
153
+ return async (ctx) => {
154
+ const { trajectory, options } = state;
155
+ await trajectory.message('received', ctx.from, options.agentName, ctx.body);
156
+ };
157
+ }
158
+ /**
159
+ * Message sent hook - records outgoing messages
160
+ */
161
+ function createMessageSentHook(state) {
162
+ return async (ctx) => {
163
+ const { trajectory, options } = state;
164
+ await trajectory.message('sent', options.agentName, ctx.to, ctx.body);
165
+ };
166
+ }
167
+ /**
168
+ * Get trajectory hooks for a project/agent combination
169
+ *
170
+ * This is a convenience function that creates trajectory hooks
171
+ * with default options.
172
+ */
173
+ export function getTrajectoryHooks(projectId, agentName) {
174
+ return createTrajectoryHooks({ projectId, agentName });
175
+ }
176
+ /**
177
+ * Utility to check if trajectory tracking is available
178
+ */
179
+ export function isTrajectoryTrackingAvailable(projectId, agentName) {
180
+ const trajectory = getTrajectoryIntegration(projectId, agentName);
181
+ return trajectory.isTrailInstalledSync();
182
+ }
183
+ //# sourceMappingURL=trajectory-hooks.js.map