agent-relay 1.1.0 → 1.2.0

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 (490) hide show
  1. package/README.md +1 -1
  2. package/dist/bridge/spawner.d.ts +53 -0
  3. package/dist/bridge/spawner.d.ts.map +1 -1
  4. package/dist/bridge/spawner.js +203 -19
  5. package/dist/bridge/spawner.js.map +1 -1
  6. package/dist/bridge/types.d.ts +12 -0
  7. package/dist/bridge/types.d.ts.map +1 -1
  8. package/dist/cli/index.js +401 -5
  9. package/dist/cli/index.js.map +1 -1
  10. package/dist/cloud/api/auth.d.ts +3 -2
  11. package/dist/cloud/api/auth.d.ts.map +1 -1
  12. package/dist/cloud/api/auth.js +10 -98
  13. package/dist/cloud/api/auth.js.map +1 -1
  14. package/dist/cloud/api/cli-pty-runner.d.ts +54 -0
  15. package/dist/cloud/api/cli-pty-runner.d.ts.map +1 -0
  16. package/dist/cloud/api/cli-pty-runner.js +119 -0
  17. package/dist/cloud/api/cli-pty-runner.js.map +1 -0
  18. package/dist/cloud/api/generic-webhooks.d.ts +8 -0
  19. package/dist/cloud/api/generic-webhooks.d.ts.map +1 -0
  20. package/dist/cloud/api/generic-webhooks.js +129 -0
  21. package/dist/cloud/api/generic-webhooks.js.map +1 -0
  22. package/dist/cloud/api/git.d.ts +8 -0
  23. package/dist/cloud/api/git.d.ts.map +1 -0
  24. package/dist/cloud/api/git.js +131 -0
  25. package/dist/cloud/api/git.js.map +1 -0
  26. package/dist/cloud/api/github-app.d.ts +11 -0
  27. package/dist/cloud/api/github-app.d.ts.map +1 -0
  28. package/dist/cloud/api/github-app.js +189 -0
  29. package/dist/cloud/api/github-app.js.map +1 -0
  30. package/dist/cloud/api/middleware/planLimits.d.ts +7 -0
  31. package/dist/cloud/api/middleware/planLimits.d.ts.map +1 -1
  32. package/dist/cloud/api/middleware/planLimits.js +39 -1
  33. package/dist/cloud/api/middleware/planLimits.js.map +1 -1
  34. package/dist/cloud/api/monitoring.d.ts +11 -0
  35. package/dist/cloud/api/monitoring.d.ts.map +1 -0
  36. package/dist/cloud/api/monitoring.js +578 -0
  37. package/dist/cloud/api/monitoring.js.map +1 -0
  38. package/dist/cloud/api/nango-auth.d.ts +9 -0
  39. package/dist/cloud/api/nango-auth.d.ts.map +1 -0
  40. package/dist/cloud/api/nango-auth.js +377 -0
  41. package/dist/cloud/api/nango-auth.js.map +1 -0
  42. package/dist/cloud/api/onboarding.d.ts +8 -1
  43. package/dist/cloud/api/onboarding.d.ts.map +1 -1
  44. package/dist/cloud/api/onboarding.js +300 -119
  45. package/dist/cloud/api/onboarding.js.map +1 -1
  46. package/dist/cloud/api/policy.d.ts +8 -0
  47. package/dist/cloud/api/policy.d.ts.map +1 -0
  48. package/dist/cloud/api/policy.js +229 -0
  49. package/dist/cloud/api/policy.js.map +1 -0
  50. package/dist/cloud/api/providers.js +114 -42
  51. package/dist/cloud/api/providers.js.map +1 -1
  52. package/dist/cloud/api/test-helpers.d.ts +10 -0
  53. package/dist/cloud/api/test-helpers.d.ts.map +1 -0
  54. package/dist/cloud/api/test-helpers.js +575 -0
  55. package/dist/cloud/api/test-helpers.js.map +1 -0
  56. package/dist/cloud/api/webhooks.d.ts +7 -0
  57. package/dist/cloud/api/webhooks.d.ts.map +1 -0
  58. package/dist/cloud/api/webhooks.js +496 -0
  59. package/dist/cloud/api/webhooks.js.map +1 -0
  60. package/dist/cloud/api/workspaces.js +225 -8
  61. package/dist/cloud/api/workspaces.js.map +1 -1
  62. package/dist/cloud/billing/plans.d.ts.map +1 -1
  63. package/dist/cloud/billing/plans.js +13 -0
  64. package/dist/cloud/billing/plans.js.map +1 -1
  65. package/dist/cloud/billing/types.d.ts +9 -3
  66. package/dist/cloud/billing/types.d.ts.map +1 -1
  67. package/dist/cloud/config.d.ts +9 -2
  68. package/dist/cloud/config.d.ts.map +1 -1
  69. package/dist/cloud/config.js +13 -4
  70. package/dist/cloud/config.js.map +1 -1
  71. package/dist/cloud/db/drizzle.d.ts +84 -1
  72. package/dist/cloud/db/drizzle.d.ts.map +1 -1
  73. package/dist/cloud/db/drizzle.js +470 -0
  74. package/dist/cloud/db/drizzle.js.map +1 -1
  75. package/dist/cloud/db/index.d.ts +9 -4
  76. package/dist/cloud/db/index.d.ts.map +1 -1
  77. package/dist/cloud/db/index.js +11 -3
  78. package/dist/cloud/db/index.js.map +1 -1
  79. package/dist/cloud/db/schema.d.ts +3283 -556
  80. package/dist/cloud/db/schema.d.ts.map +1 -1
  81. package/dist/cloud/db/schema.js +314 -1
  82. package/dist/cloud/db/schema.js.map +1 -1
  83. package/dist/cloud/index.d.ts +1 -0
  84. package/dist/cloud/index.d.ts.map +1 -1
  85. package/dist/cloud/index.js +2 -0
  86. package/dist/cloud/index.js.map +1 -1
  87. package/dist/cloud/provisioner/index.d.ts +24 -0
  88. package/dist/cloud/provisioner/index.d.ts.map +1 -1
  89. package/dist/cloud/provisioner/index.js +319 -18
  90. package/dist/cloud/provisioner/index.js.map +1 -1
  91. package/dist/cloud/server.d.ts +1 -0
  92. package/dist/cloud/server.d.ts.map +1 -1
  93. package/dist/cloud/server.js +357 -13
  94. package/dist/cloud/server.js.map +1 -1
  95. package/dist/cloud/services/auto-scaler.d.ts +152 -0
  96. package/dist/cloud/services/auto-scaler.d.ts.map +1 -0
  97. package/dist/cloud/services/auto-scaler.js +439 -0
  98. package/dist/cloud/services/auto-scaler.js.map +1 -0
  99. package/dist/cloud/services/capacity-manager.d.ts +148 -0
  100. package/dist/cloud/services/capacity-manager.d.ts.map +1 -0
  101. package/dist/cloud/services/capacity-manager.js +449 -0
  102. package/dist/cloud/services/capacity-manager.js.map +1 -0
  103. package/dist/cloud/services/ci-agent-spawner.d.ts +49 -0
  104. package/dist/cloud/services/ci-agent-spawner.d.ts.map +1 -0
  105. package/dist/cloud/services/ci-agent-spawner.js +373 -0
  106. package/dist/cloud/services/ci-agent-spawner.js.map +1 -0
  107. package/dist/cloud/services/index.d.ts +12 -0
  108. package/dist/cloud/services/index.d.ts.map +1 -0
  109. package/dist/cloud/services/index.js +15 -0
  110. package/dist/cloud/services/index.js.map +1 -0
  111. package/dist/cloud/services/mention-handler.d.ts +65 -0
  112. package/dist/cloud/services/mention-handler.d.ts.map +1 -0
  113. package/dist/cloud/services/mention-handler.js +405 -0
  114. package/dist/cloud/services/mention-handler.js.map +1 -0
  115. package/dist/cloud/services/nango.d.ts +126 -0
  116. package/dist/cloud/services/nango.d.ts.map +1 -0
  117. package/dist/cloud/services/nango.js +191 -0
  118. package/dist/cloud/services/nango.js.map +1 -0
  119. package/dist/cloud/services/persistence.d.ts +131 -0
  120. package/dist/cloud/services/persistence.d.ts.map +1 -0
  121. package/dist/cloud/services/persistence.js +200 -0
  122. package/dist/cloud/services/persistence.js.map +1 -0
  123. package/dist/cloud/services/planLimits.d.ts +15 -0
  124. package/dist/cloud/services/planLimits.d.ts.map +1 -1
  125. package/dist/cloud/services/planLimits.js +28 -0
  126. package/dist/cloud/services/planLimits.js.map +1 -1
  127. package/dist/cloud/services/scaling-orchestrator.d.ts +159 -0
  128. package/dist/cloud/services/scaling-orchestrator.d.ts.map +1 -0
  129. package/dist/cloud/services/scaling-orchestrator.js +502 -0
  130. package/dist/cloud/services/scaling-orchestrator.js.map +1 -0
  131. package/dist/cloud/services/scaling-policy.d.ts +121 -0
  132. package/dist/cloud/services/scaling-policy.d.ts.map +1 -0
  133. package/dist/cloud/services/scaling-policy.js +415 -0
  134. package/dist/cloud/services/scaling-policy.js.map +1 -0
  135. package/dist/cloud/vault/index.js +1 -1
  136. package/dist/cloud/vault/index.js.map +1 -1
  137. package/dist/cloud/webhooks/index.d.ts +24 -0
  138. package/dist/cloud/webhooks/index.d.ts.map +1 -0
  139. package/dist/cloud/webhooks/index.js +29 -0
  140. package/dist/cloud/webhooks/index.js.map +1 -0
  141. package/dist/cloud/webhooks/parsers/github.d.ts +8 -0
  142. package/dist/cloud/webhooks/parsers/github.d.ts.map +1 -0
  143. package/dist/cloud/webhooks/parsers/github.js +234 -0
  144. package/dist/cloud/webhooks/parsers/github.js.map +1 -0
  145. package/dist/cloud/webhooks/parsers/index.d.ts +23 -0
  146. package/dist/cloud/webhooks/parsers/index.d.ts.map +1 -0
  147. package/dist/cloud/webhooks/parsers/index.js +30 -0
  148. package/dist/cloud/webhooks/parsers/index.js.map +1 -0
  149. package/dist/cloud/webhooks/parsers/linear.d.ts +9 -0
  150. package/dist/cloud/webhooks/parsers/linear.d.ts.map +1 -0
  151. package/dist/cloud/webhooks/parsers/linear.js +258 -0
  152. package/dist/cloud/webhooks/parsers/linear.js.map +1 -0
  153. package/dist/cloud/webhooks/parsers/slack.d.ts +9 -0
  154. package/dist/cloud/webhooks/parsers/slack.d.ts.map +1 -0
  155. package/dist/cloud/webhooks/parsers/slack.js +214 -0
  156. package/dist/cloud/webhooks/parsers/slack.js.map +1 -0
  157. package/dist/cloud/webhooks/responders/github.d.ts +8 -0
  158. package/dist/cloud/webhooks/responders/github.d.ts.map +1 -0
  159. package/dist/cloud/webhooks/responders/github.js +73 -0
  160. package/dist/cloud/webhooks/responders/github.js.map +1 -0
  161. package/dist/cloud/webhooks/responders/index.d.ts +23 -0
  162. package/dist/cloud/webhooks/responders/index.d.ts.map +1 -0
  163. package/dist/cloud/webhooks/responders/index.js +30 -0
  164. package/dist/cloud/webhooks/responders/index.js.map +1 -0
  165. package/dist/cloud/webhooks/responders/linear.d.ts +9 -0
  166. package/dist/cloud/webhooks/responders/linear.d.ts.map +1 -0
  167. package/dist/cloud/webhooks/responders/linear.js +149 -0
  168. package/dist/cloud/webhooks/responders/linear.js.map +1 -0
  169. package/dist/cloud/webhooks/responders/slack.d.ts +20 -0
  170. package/dist/cloud/webhooks/responders/slack.d.ts.map +1 -0
  171. package/dist/cloud/webhooks/responders/slack.js +178 -0
  172. package/dist/cloud/webhooks/responders/slack.js.map +1 -0
  173. package/dist/cloud/webhooks/router.d.ts +25 -0
  174. package/dist/cloud/webhooks/router.d.ts.map +1 -0
  175. package/dist/cloud/webhooks/router.js +504 -0
  176. package/dist/cloud/webhooks/router.js.map +1 -0
  177. package/dist/cloud/webhooks/rules-engine.d.ts +24 -0
  178. package/dist/cloud/webhooks/rules-engine.d.ts.map +1 -0
  179. package/dist/cloud/webhooks/rules-engine.js +287 -0
  180. package/dist/cloud/webhooks/rules-engine.js.map +1 -0
  181. package/dist/cloud/webhooks/types.d.ts +186 -0
  182. package/dist/cloud/webhooks/types.d.ts.map +1 -0
  183. package/dist/cloud/webhooks/types.js +8 -0
  184. package/dist/cloud/webhooks/types.js.map +1 -0
  185. package/dist/continuity/formatter.d.ts +51 -0
  186. package/dist/continuity/formatter.d.ts.map +1 -0
  187. package/dist/continuity/formatter.js +313 -0
  188. package/dist/continuity/formatter.js.map +1 -0
  189. package/dist/continuity/handoff-store.d.ts +67 -0
  190. package/dist/continuity/handoff-store.d.ts.map +1 -0
  191. package/dist/continuity/handoff-store.js +472 -0
  192. package/dist/continuity/handoff-store.js.map +1 -0
  193. package/dist/continuity/index.d.ts +45 -0
  194. package/dist/continuity/index.d.ts.map +1 -0
  195. package/dist/continuity/index.js +48 -0
  196. package/dist/continuity/index.js.map +1 -0
  197. package/dist/continuity/ledger-store.d.ts +110 -0
  198. package/dist/continuity/ledger-store.d.ts.map +1 -0
  199. package/dist/continuity/ledger-store.js +500 -0
  200. package/dist/continuity/ledger-store.js.map +1 -0
  201. package/dist/continuity/manager.d.ts +178 -0
  202. package/dist/continuity/manager.d.ts.map +1 -0
  203. package/dist/continuity/manager.js +562 -0
  204. package/dist/continuity/manager.js.map +1 -0
  205. package/dist/continuity/parser.d.ts +76 -0
  206. package/dist/continuity/parser.d.ts.map +1 -0
  207. package/dist/continuity/parser.js +579 -0
  208. package/dist/continuity/parser.js.map +1 -0
  209. package/dist/continuity/types.d.ts +180 -0
  210. package/dist/continuity/types.d.ts.map +1 -0
  211. package/dist/continuity/types.js +9 -0
  212. package/dist/continuity/types.js.map +1 -0
  213. package/dist/daemon/agent-manager.d.ts +27 -0
  214. package/dist/daemon/agent-manager.d.ts.map +1 -1
  215. package/dist/daemon/agent-manager.js +107 -6
  216. package/dist/daemon/agent-manager.js.map +1 -1
  217. package/dist/daemon/agent-registry.d.ts +32 -0
  218. package/dist/daemon/agent-registry.d.ts.map +1 -1
  219. package/dist/daemon/agent-registry.js +42 -2
  220. package/dist/daemon/agent-registry.js.map +1 -1
  221. package/dist/daemon/api.d.ts +12 -0
  222. package/dist/daemon/api.d.ts.map +1 -1
  223. package/dist/daemon/api.js +131 -2
  224. package/dist/daemon/api.js.map +1 -1
  225. package/dist/daemon/cli-auth.d.ts +67 -0
  226. package/dist/daemon/cli-auth.d.ts.map +1 -0
  227. package/dist/daemon/cli-auth.js +537 -0
  228. package/dist/daemon/cli-auth.js.map +1 -0
  229. package/dist/daemon/cloud-sync.d.ts.map +1 -1
  230. package/dist/daemon/cloud-sync.js +9 -7
  231. package/dist/daemon/cloud-sync.js.map +1 -1
  232. package/dist/daemon/orchestrator.d.ts.map +1 -1
  233. package/dist/daemon/orchestrator.js +30 -0
  234. package/dist/daemon/orchestrator.js.map +1 -1
  235. package/dist/daemon/router.d.ts +5 -0
  236. package/dist/daemon/router.d.ts.map +1 -1
  237. package/dist/daemon/router.js +78 -26
  238. package/dist/daemon/router.js.map +1 -1
  239. package/dist/daemon/server.d.ts +5 -0
  240. package/dist/daemon/server.d.ts.map +1 -1
  241. package/dist/daemon/server.js +9 -1
  242. package/dist/daemon/server.js.map +1 -1
  243. package/dist/daemon/services/browser-testing.d.ts +88 -0
  244. package/dist/daemon/services/browser-testing.d.ts.map +1 -0
  245. package/dist/daemon/services/browser-testing.js +244 -0
  246. package/dist/daemon/services/browser-testing.js.map +1 -0
  247. package/dist/daemon/services/container-spawner.d.ts +135 -0
  248. package/dist/daemon/services/container-spawner.d.ts.map +1 -0
  249. package/dist/daemon/services/container-spawner.js +313 -0
  250. package/dist/daemon/services/container-spawner.js.map +1 -0
  251. package/dist/daemon/types.d.ts +5 -1
  252. package/dist/daemon/types.d.ts.map +1 -1
  253. package/dist/dashboard/out/404.html +1 -1
  254. package/dist/dashboard/out/_next/static/chunks/116-2502180def231162.js +1 -0
  255. package/dist/dashboard/out/_next/static/chunks/282-980c2eb8fff20123.js +1 -0
  256. package/dist/dashboard/out/_next/static/chunks/480-2d4111711d4e473c.js +1 -0
  257. package/dist/dashboard/out/_next/static/chunks/724-73c1ee5f60abe860.js +9 -0
  258. package/dist/dashboard/out/_next/static/chunks/766-c3a14283c88d815b.js +1 -0
  259. package/dist/dashboard/out/_next/static/chunks/app/app/page-7120be68bea622f3.js +1 -0
  260. package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-dc2e3a1a22478efc.js +1 -0
  261. package/dist/dashboard/out/_next/static/chunks/app/history/{page-b6edd4dde8d08194.js → page-56a8b4616a90dc43.js} +1 -1
  262. package/dist/dashboard/out/_next/static/chunks/app/login/page-3eac37ea6f5dd153.js +1 -0
  263. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-1081dd190a331a91.js +1 -0
  264. package/dist/dashboard/out/_next/static/chunks/app/page-daf87e86f783f980.js +1 -0
  265. package/dist/dashboard/out/_next/static/chunks/app/providers/page-b68a681526eb145e.js +1 -0
  266. package/dist/dashboard/out/_next/static/chunks/app/signup/page-fee4ed1709070bcd.js +1 -0
  267. package/dist/dashboard/out/_next/static/chunks/e868780c-48e5f147c90a3a41.js +18 -0
  268. package/dist/dashboard/out/_next/static/chunks/{main-c2f423b9c9f4591b.js → main-97850e03d723ea8c.js} +1 -1
  269. package/dist/dashboard/out/_next/static/chunks/webpack-1cdd8ed57114d5e1.js +1 -0
  270. package/dist/dashboard/out/_next/static/css/29852f26181969a0.css +1 -0
  271. package/dist/dashboard/out/_next/static/css/411ce23ffeae9f76.css +1 -0
  272. package/dist/dashboard/out/app.html +1 -14
  273. package/dist/dashboard/out/app.txt +2 -2
  274. package/dist/dashboard/out/connect-repos.html +1 -0
  275. package/dist/dashboard/out/connect-repos.txt +7 -0
  276. package/dist/dashboard/out/history.html +1 -1
  277. package/dist/dashboard/out/history.txt +2 -2
  278. package/dist/dashboard/out/index.html +1 -1
  279. package/dist/dashboard/out/index.txt +2 -2
  280. package/dist/dashboard/out/login.html +6 -0
  281. package/dist/dashboard/out/login.txt +7 -0
  282. package/dist/dashboard/out/metrics.html +1 -1
  283. package/dist/dashboard/out/metrics.txt +2 -2
  284. package/dist/dashboard/out/pricing.html +2 -2
  285. package/dist/dashboard/out/pricing.txt +2 -2
  286. package/dist/dashboard/out/providers.html +1 -0
  287. package/dist/dashboard/out/providers.txt +7 -0
  288. package/dist/dashboard/out/signup.html +6 -0
  289. package/dist/dashboard/out/signup.txt +7 -0
  290. package/dist/dashboard-server/server.d.ts.map +1 -1
  291. package/dist/dashboard-server/server.js +1308 -8
  292. package/dist/dashboard-server/server.js.map +1 -1
  293. package/dist/hooks/emitter.d.ts +40 -0
  294. package/dist/hooks/emitter.d.ts.map +1 -0
  295. package/dist/hooks/emitter.js +63 -0
  296. package/dist/hooks/emitter.js.map +1 -0
  297. package/dist/hooks/index.d.ts +3 -0
  298. package/dist/hooks/index.d.ts.map +1 -1
  299. package/dist/hooks/index.js +3 -0
  300. package/dist/hooks/index.js.map +1 -1
  301. package/dist/hooks/registry.d.ts +173 -0
  302. package/dist/hooks/registry.d.ts.map +1 -0
  303. package/dist/hooks/registry.js +476 -0
  304. package/dist/hooks/registry.js.map +1 -0
  305. package/dist/hooks/trajectory-hooks.d.ts +52 -0
  306. package/dist/hooks/trajectory-hooks.d.ts.map +1 -0
  307. package/dist/hooks/trajectory-hooks.js +183 -0
  308. package/dist/hooks/trajectory-hooks.js.map +1 -0
  309. package/dist/hooks/types.d.ts +141 -0
  310. package/dist/hooks/types.d.ts.map +1 -1
  311. package/dist/index.d.ts +2 -0
  312. package/dist/index.d.ts.map +1 -1
  313. package/dist/index.js +3 -0
  314. package/dist/index.js.map +1 -1
  315. package/dist/memory/adapters/index.d.ts +8 -0
  316. package/dist/memory/adapters/index.d.ts.map +1 -0
  317. package/dist/memory/adapters/index.js +8 -0
  318. package/dist/memory/adapters/index.js.map +1 -0
  319. package/dist/memory/adapters/inmemory.d.ts +59 -0
  320. package/dist/memory/adapters/inmemory.d.ts.map +1 -0
  321. package/dist/memory/adapters/inmemory.js +195 -0
  322. package/dist/memory/adapters/inmemory.js.map +1 -0
  323. package/dist/memory/adapters/supermemory.d.ts +71 -0
  324. package/dist/memory/adapters/supermemory.d.ts.map +1 -0
  325. package/dist/memory/adapters/supermemory.js +338 -0
  326. package/dist/memory/adapters/supermemory.js.map +1 -0
  327. package/dist/memory/factory.d.ts +48 -0
  328. package/dist/memory/factory.d.ts.map +1 -0
  329. package/dist/memory/factory.js +143 -0
  330. package/dist/memory/factory.js.map +1 -0
  331. package/dist/memory/index.d.ts +32 -0
  332. package/dist/memory/index.d.ts.map +1 -0
  333. package/dist/memory/index.js +32 -0
  334. package/dist/memory/index.js.map +1 -0
  335. package/dist/memory/memory-hooks.d.ts +60 -0
  336. package/dist/memory/memory-hooks.d.ts.map +1 -0
  337. package/dist/memory/memory-hooks.js +313 -0
  338. package/dist/memory/memory-hooks.js.map +1 -0
  339. package/dist/memory/service.d.ts +49 -0
  340. package/dist/memory/service.d.ts.map +1 -0
  341. package/dist/memory/service.js +146 -0
  342. package/dist/memory/service.js.map +1 -0
  343. package/dist/memory/types.d.ts +195 -0
  344. package/dist/memory/types.d.ts.map +1 -0
  345. package/dist/memory/types.js +8 -0
  346. package/dist/memory/types.js.map +1 -0
  347. package/dist/policy/agent-policy.d.ts +225 -0
  348. package/dist/policy/agent-policy.d.ts.map +1 -0
  349. package/dist/policy/agent-policy.js +665 -0
  350. package/dist/policy/agent-policy.js.map +1 -0
  351. package/dist/policy/cloud-policy-fetcher.d.ts +12 -0
  352. package/dist/policy/cloud-policy-fetcher.d.ts.map +1 -0
  353. package/dist/policy/cloud-policy-fetcher.js +64 -0
  354. package/dist/policy/cloud-policy-fetcher.js.map +1 -0
  355. package/dist/resiliency/crash-insights.d.ts +156 -0
  356. package/dist/resiliency/crash-insights.d.ts.map +1 -0
  357. package/dist/resiliency/crash-insights.js +492 -0
  358. package/dist/resiliency/crash-insights.js.map +1 -0
  359. package/dist/resiliency/gossip-health.d.ts +137 -0
  360. package/dist/resiliency/gossip-health.d.ts.map +1 -0
  361. package/dist/resiliency/gossip-health.js +241 -0
  362. package/dist/resiliency/gossip-health.js.map +1 -0
  363. package/dist/resiliency/index.d.ts +5 -0
  364. package/dist/resiliency/index.d.ts.map +1 -1
  365. package/dist/resiliency/index.js +5 -0
  366. package/dist/resiliency/index.js.map +1 -1
  367. package/dist/resiliency/leader-watchdog.d.ts +109 -0
  368. package/dist/resiliency/leader-watchdog.d.ts.map +1 -0
  369. package/dist/resiliency/leader-watchdog.js +189 -0
  370. package/dist/resiliency/leader-watchdog.js.map +1 -0
  371. package/dist/resiliency/memory-monitor.d.ts +172 -0
  372. package/dist/resiliency/memory-monitor.d.ts.map +1 -0
  373. package/dist/resiliency/memory-monitor.js +593 -0
  374. package/dist/resiliency/memory-monitor.js.map +1 -0
  375. package/dist/resiliency/stateless-lead.d.ts +149 -0
  376. package/dist/resiliency/stateless-lead.d.ts.map +1 -0
  377. package/dist/resiliency/stateless-lead.js +308 -0
  378. package/dist/resiliency/stateless-lead.js.map +1 -0
  379. package/dist/resiliency/supervisor.d.ts +38 -0
  380. package/dist/resiliency/supervisor.d.ts.map +1 -1
  381. package/dist/resiliency/supervisor.js +122 -0
  382. package/dist/resiliency/supervisor.js.map +1 -1
  383. package/dist/shared/cli-auth-config.d.ts +91 -0
  384. package/dist/shared/cli-auth-config.d.ts.map +1 -0
  385. package/dist/shared/cli-auth-config.js +264 -0
  386. package/dist/shared/cli-auth-config.js.map +1 -0
  387. package/dist/storage/adapter.d.ts +1 -1
  388. package/dist/storage/adapter.d.ts.map +1 -1
  389. package/dist/trajectory/config.d.ts +84 -0
  390. package/dist/trajectory/config.d.ts.map +1 -0
  391. package/dist/trajectory/config.js +163 -0
  392. package/dist/trajectory/config.js.map +1 -0
  393. package/dist/trajectory/index.d.ts +8 -0
  394. package/dist/trajectory/index.d.ts.map +1 -0
  395. package/dist/trajectory/index.js +8 -0
  396. package/dist/trajectory/index.js.map +1 -0
  397. package/dist/trajectory/integration.d.ts +292 -0
  398. package/dist/trajectory/integration.d.ts.map +1 -0
  399. package/dist/trajectory/integration.js +834 -0
  400. package/dist/trajectory/integration.js.map +1 -0
  401. package/dist/utils/logger.js +1 -1
  402. package/dist/utils/logger.js.map +1 -1
  403. package/dist/utils/project-namespace.d.ts +24 -0
  404. package/dist/utils/project-namespace.d.ts.map +1 -1
  405. package/dist/utils/project-namespace.js +84 -0
  406. package/dist/utils/project-namespace.js.map +1 -1
  407. package/dist/wrapper/parser.d.ts +10 -0
  408. package/dist/wrapper/parser.d.ts.map +1 -1
  409. package/dist/wrapper/parser.js +100 -33
  410. package/dist/wrapper/parser.js.map +1 -1
  411. package/dist/wrapper/pty-wrapper.d.ts +197 -16
  412. package/dist/wrapper/pty-wrapper.d.ts.map +1 -1
  413. package/dist/wrapper/pty-wrapper.js +943 -106
  414. package/dist/wrapper/pty-wrapper.js.map +1 -1
  415. package/dist/wrapper/shared.d.ts +165 -0
  416. package/dist/wrapper/shared.d.ts.map +1 -0
  417. package/dist/wrapper/shared.js +270 -0
  418. package/dist/wrapper/shared.js.map +1 -0
  419. package/dist/wrapper/tmux-wrapper.d.ts +73 -11
  420. package/dist/wrapper/tmux-wrapper.d.ts.map +1 -1
  421. package/dist/wrapper/tmux-wrapper.js +541 -120
  422. package/dist/wrapper/tmux-wrapper.js.map +1 -1
  423. package/docs/CLOUD-ARCHITECTURE.md +152 -0
  424. package/docs/HOOKS_API.md +394 -0
  425. package/docs/WRAPPER_EVENTS.md +358 -0
  426. package/docs/agent-policy-snippet.md +40 -0
  427. package/docs/agent-relay-protocol.md +238 -0
  428. package/docs/agent-relay-snippet.md +53 -47
  429. package/docs/archive/EXECUTIVE_SUMMARY.md +358 -0
  430. package/docs/archive/ROADMAP.md +329 -0
  431. package/docs/competitive/GASTOWN.md +451 -0
  432. package/docs/{COMPETITIVE_ANALYSIS.md → competitive/OVERVIEW.md} +1 -0
  433. package/docs/competitive/README.md +34 -0
  434. package/docs/competitive/TMUX_ORCHESTRATOR.md +605 -0
  435. package/docs/dashboard.png +0 -0
  436. package/docs/design/ci-failure-webhooks.md +812 -0
  437. package/docs/design/comprehensive-integrations.md +238 -0
  438. package/docs/design/e2b-sandbox-integration.md +504 -0
  439. package/docs/design/github-app-permissions.md +264 -0
  440. package/docs/local-testing.md +428 -0
  441. package/docs/proposals/continuous-claude-integration.md +622 -0
  442. package/docs/proposals/custom-commands.md +368 -0
  443. package/docs/tasks/global-skills-system.tasks.md +230 -0
  444. package/docs/tasks/webhook-integrations.tasks.md +184 -0
  445. package/docs/tasks/workspace-capabilities.tasks.md +121 -0
  446. package/docs/testing/RESILIENCY-TEST-PLAN-2026-01-01.md +366 -0
  447. package/package.json +16 -7
  448. package/scripts/cloud-setup.sh +96 -0
  449. package/scripts/manual-qa.sh +293 -0
  450. package/scripts/postinstall.js +60 -0
  451. package/scripts/run-cloud-qa.sh +220 -0
  452. package/scripts/test-cli-auth/Dockerfile +44 -0
  453. package/scripts/test-cli-auth/Dockerfile.real +79 -0
  454. package/scripts/test-cli-auth/README.md +286 -0
  455. package/scripts/test-cli-auth/ci-test-real-clis.ts +251 -0
  456. package/scripts/test-cli-auth/ci-test-runner.ts +263 -0
  457. package/scripts/test-cli-auth/mock-cli.sh +147 -0
  458. package/scripts/test-cli-auth/package.json +14 -0
  459. package/scripts/test-cli-auth/test-oauth-flow.ts +220 -0
  460. package/scripts/test-pty-input-auto.js +222 -0
  461. package/scripts/test-pty-input.js +150 -0
  462. package/dist/dashboard/out/_next/static/chunks/693-7b3301d8f6bc5014.js +0 -1
  463. package/dist/dashboard/out/_next/static/chunks/713-f78477eb185f1f4d.js +0 -1
  464. package/dist/dashboard/out/_next/static/chunks/766-e53e1cfe39b0b5b5.js +0 -1
  465. package/dist/dashboard/out/_next/static/chunks/900-037c64bfd797fb2a.js +0 -1
  466. package/dist/dashboard/out/_next/static/chunks/app/app/page-e3d9e1f4466b9bae.js +0 -1
  467. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-e68825a81db67ba1.js +0 -1
  468. package/dist/dashboard/out/_next/static/chunks/app/page-cc108bf68c8a657f.js +0 -1
  469. package/dist/dashboard/out/_next/static/chunks/webpack-a5acc2831d094776.js +0 -1
  470. package/dist/dashboard/out/_next/static/css/79b80143647a07d7.css +0 -1
  471. package/dist/dashboard/out/_next/static/css/8cf277370ad48cfe.css +0 -1
  472. /package/dist/dashboard/out/_next/static/{6HHWb2ZmnJ4OSm0zUP7h4 → H5aWG0udPB4iOUIl_gytz}/_buildManifest.js +0 -0
  473. /package/dist/dashboard/out/_next/static/{6HHWb2ZmnJ4OSm0zUP7h4 → H5aWG0udPB4iOUIl_gytz}/_ssgManifest.js +0 -0
  474. /package/dist/dashboard/out/_next/static/chunks/{117-b2cd8d6485aacf2b.js → 117-b100311aff8d5c61.js} +0 -0
  475. /package/dist/dashboard/out/_next/static/chunks/{648-8f3f26864ce515e5.js → 648-a13d3c2b1be45466.js} +0 -0
  476. /package/dist/dashboard/out/_next/static/chunks/app/_not-found/{page-0b990dbb71d72a98.js → page-a4973f3e3c82fb67.js} +0 -0
  477. /package/dist/dashboard/out/_next/static/chunks/app/pricing/{page-d80e03a5297f95b6.js → page-4d72d5a5d8a9b618.js} +0 -0
  478. /package/docs/{CHANGELOG.md → archive/CHANGELOG.md} +0 -0
  479. /package/docs/{CLI-SIMPLIFICATION-COMPLETE.md → archive/CLI-SIMPLIFICATION-COMPLETE.md} +0 -0
  480. /package/docs/{DESIGN_BRIDGE_STAFFING.md → archive/DESIGN_BRIDGE_STAFFING.md} +0 -0
  481. /package/docs/{DESIGN_V2.md → archive/DESIGN_V2.md} +0 -0
  482. /package/docs/{MONETIZATION.md → archive/MONETIZATION.md} +0 -0
  483. /package/docs/{PROPOSAL-trajectories.md → archive/PROPOSAL-trajectories.md} +0 -0
  484. /package/docs/{SCALING_ANALYSIS.md → archive/SCALING_ANALYSIS.md} +0 -0
  485. /package/docs/{TESTING_PRESENCE_FEATURES.md → archive/TESTING_PRESENCE_FEATURES.md} +0 -0
  486. /package/docs/{TMUX_IMPLEMENTATION_NOTES.md → archive/TMUX_IMPLEMENTATION_NOTES.md} +0 -0
  487. /package/docs/{TMUX_IMPROVEMENTS.md → archive/TMUX_IMPROVEMENTS.md} +0 -0
  488. /package/docs/{dashboard-v2-plan.md → archive/dashboard-v2-plan.md} +0 -0
  489. /package/docs/{removable-code-analysis.md → archive/removable-code-analysis.md} +0 -0
  490. /package/docs/{competitive-analysis-mcp-agent-mail.md → competitive/MCP_AGENT_MAIL.md} +0 -0
@@ -0,0 +1,834 @@
1
+ /**
2
+ * Trajectory Integration Module
3
+ *
4
+ * Integrates with the agent-trajectories package to provide
5
+ * PDERO paradigm tracking within agent-relay.
6
+ *
7
+ * This module provides a bridge between agent-relay and the
8
+ * external `trail` CLI / agent-trajectories library.
9
+ *
10
+ * Key integration points:
11
+ * - Auto-starts trajectory when agent is instantiated with a task
12
+ * - Records all inter-agent messages
13
+ * - Auto-detects PDERO phase transitions from output
14
+ * - Provides hooks for key agent lifecycle events
15
+ */
16
+ import { spawn, execSync } from 'node:child_process';
17
+ import { readFileSync, existsSync } from 'node:fs';
18
+ import { join } from 'node:path';
19
+ import { getProjectPaths } from '../utils/project-namespace.js';
20
+ import { getPrimaryTrajectoriesDir, getAllTrajectoriesDirs, getTrajectoryEnvVars, } from './config.js';
21
+ /**
22
+ * Read a single trajectory index file from a directory
23
+ */
24
+ function readSingleTrajectoryIndex(trajectoriesDir) {
25
+ try {
26
+ const indexPath = join(trajectoriesDir, 'index.json');
27
+ if (!existsSync(indexPath)) {
28
+ return null;
29
+ }
30
+ const content = readFileSync(indexPath, 'utf-8');
31
+ return JSON.parse(content);
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ /**
38
+ * Read and merge trajectory indexes from all locations (repo + user-level)
39
+ * This allows reading trajectories from both places
40
+ */
41
+ function readTrajectoryIndex() {
42
+ const dirs = getAllTrajectoriesDirs();
43
+ if (dirs.length === 0) {
44
+ return null;
45
+ }
46
+ // Read and merge all indexes
47
+ let mergedIndex = null;
48
+ for (const dir of dirs) {
49
+ const index = readSingleTrajectoryIndex(dir);
50
+ if (!index)
51
+ continue;
52
+ if (!mergedIndex) {
53
+ mergedIndex = index;
54
+ }
55
+ else {
56
+ // Merge trajectories, preferring more recent entries
57
+ for (const [id, entry] of Object.entries(index.trajectories)) {
58
+ const existing = mergedIndex.trajectories[id];
59
+ if (!existing) {
60
+ mergedIndex.trajectories[id] = entry;
61
+ }
62
+ else {
63
+ // Keep the more recently updated one
64
+ const existingTime = new Date(existing.completedAt || existing.startedAt).getTime();
65
+ const newTime = new Date(entry.completedAt || entry.startedAt).getTime();
66
+ if (newTime > existingTime) {
67
+ mergedIndex.trajectories[id] = entry;
68
+ }
69
+ }
70
+ }
71
+ // Update lastUpdated to most recent
72
+ if (new Date(index.lastUpdated) > new Date(mergedIndex.lastUpdated)) {
73
+ mergedIndex.lastUpdated = index.lastUpdated;
74
+ }
75
+ }
76
+ }
77
+ return mergedIndex;
78
+ }
79
+ /**
80
+ * Read a specific trajectory file directly from filesystem
81
+ */
82
+ function readTrajectoryFile(trajectoryPath) {
83
+ try {
84
+ if (!existsSync(trajectoryPath)) {
85
+ return null;
86
+ }
87
+ const content = readFileSync(trajectoryPath, 'utf-8');
88
+ return JSON.parse(content);
89
+ }
90
+ catch {
91
+ return null;
92
+ }
93
+ }
94
+ /**
95
+ * Run a trail CLI command
96
+ * Uses config-based environment to control trajectory storage location
97
+ */
98
+ async function runTrail(args) {
99
+ return new Promise((resolve) => {
100
+ // Get trajectory env vars to set correct storage location
101
+ const trajectoryEnv = getTrajectoryEnvVars();
102
+ const proc = spawn('trail', args, {
103
+ cwd: getProjectPaths().projectRoot,
104
+ env: { ...process.env, ...trajectoryEnv },
105
+ stdio: ['pipe', 'pipe', 'pipe'],
106
+ });
107
+ let stdout = '';
108
+ let stderr = '';
109
+ proc.stdout?.on('data', (data) => {
110
+ stdout += data.toString();
111
+ });
112
+ proc.stderr?.on('data', (data) => {
113
+ stderr += data.toString();
114
+ });
115
+ proc.on('error', (err) => {
116
+ resolve({ success: false, output: '', error: `Failed to run trail: ${err.message}` });
117
+ });
118
+ proc.on('close', (code) => {
119
+ if (code === 0) {
120
+ resolve({ success: true, output: stdout.trim() });
121
+ }
122
+ else {
123
+ resolve({ success: false, output: stdout.trim(), error: stderr.trim() || `Exit code: ${code}` });
124
+ }
125
+ });
126
+ });
127
+ }
128
+ /**
129
+ * Check if trail CLI is available
130
+ */
131
+ export async function isTrailAvailable() {
132
+ const result = await runTrail(['--version']);
133
+ return result.success;
134
+ }
135
+ /**
136
+ * Start a new trajectory
137
+ */
138
+ export async function startTrajectory(options) {
139
+ const args = ['start', options.task];
140
+ if (options.taskId) {
141
+ args.push('--task-id', options.taskId);
142
+ }
143
+ if (options.source) {
144
+ args.push('--source', options.source);
145
+ }
146
+ if (options.agentName) {
147
+ args.push('--agent', options.agentName);
148
+ }
149
+ if (options.phase) {
150
+ args.push('--phase', options.phase);
151
+ }
152
+ const result = await runTrail(args);
153
+ if (result.success) {
154
+ // Parse trajectory ID from output like "✓ Trajectory started: traj_xxx"
155
+ const match = result.output.match(/traj_[a-z0-9]+/i);
156
+ return { success: true, trajectoryId: match?.[0] };
157
+ }
158
+ return { success: false, error: result.error };
159
+ }
160
+ /**
161
+ * Get current trajectory status
162
+ * Reads directly from .trajectories/index.json instead of using CLI
163
+ */
164
+ export async function getTrajectoryStatus() {
165
+ const index = readTrajectoryIndex();
166
+ if (!index) {
167
+ return { active: false };
168
+ }
169
+ // Find an active trajectory
170
+ for (const [id, entry] of Object.entries(index.trajectories)) {
171
+ if (entry.status === 'active') {
172
+ // Read the full trajectory file to get phase info
173
+ const trajectory = readTrajectoryFile(entry.path);
174
+ let currentPhase;
175
+ if (trajectory?.chapters?.length) {
176
+ const lastChapter = trajectory.chapters[trajectory.chapters.length - 1];
177
+ // Check events for phase transitions
178
+ for (const event of [...(lastChapter.events || [])].reverse()) {
179
+ if (event.type === 'phase_transition' || event.type === 'phase') {
180
+ const phaseMatch = event.content?.match(/phase[:\s]+(\w+)/i);
181
+ if (phaseMatch) {
182
+ currentPhase = phaseMatch[1].toLowerCase();
183
+ break;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ return {
189
+ active: true,
190
+ trajectoryId: id,
191
+ phase: currentPhase,
192
+ task: entry.title,
193
+ };
194
+ }
195
+ }
196
+ return { active: false };
197
+ }
198
+ /**
199
+ * Transition to a new PDERO phase
200
+ */
201
+ export async function transitionPhase(phase, reason, agentName) {
202
+ const args = ['phase', phase];
203
+ if (reason) {
204
+ args.push('--reason', reason);
205
+ }
206
+ if (agentName) {
207
+ args.push('--agent', agentName);
208
+ }
209
+ const result = await runTrail(args);
210
+ return { success: result.success, error: result.error };
211
+ }
212
+ /**
213
+ * Record a decision
214
+ */
215
+ export async function recordDecision(options) {
216
+ const args = ['decision', options.choice];
217
+ if (options.question) {
218
+ args.push('--question', options.question);
219
+ }
220
+ if (options.alternatives && options.alternatives.length > 0) {
221
+ args.push('--alternatives', options.alternatives.join(','));
222
+ }
223
+ if (options.reasoning) {
224
+ args.push('--reasoning', options.reasoning);
225
+ }
226
+ if (options.confidence !== undefined) {
227
+ args.push('--confidence', options.confidence.toString());
228
+ }
229
+ const result = await runTrail(args);
230
+ return { success: result.success, error: result.error };
231
+ }
232
+ /**
233
+ * Record an event/observation
234
+ */
235
+ export async function recordEvent(content, type = 'observation', agentName) {
236
+ const args = ['event', content, '--type', type];
237
+ if (agentName) {
238
+ args.push('--agent', agentName);
239
+ }
240
+ const result = await runTrail(args);
241
+ return { success: result.success, error: result.error };
242
+ }
243
+ /**
244
+ * Record a message (sent or received)
245
+ */
246
+ export async function recordMessage(direction, from, to, body) {
247
+ const content = `Message ${direction}: ${direction === 'sent' ? `→ ${to}` : `← ${from}`}: ${body.slice(0, 100)}${body.length > 100 ? '...' : ''}`;
248
+ return recordEvent(content, 'observation');
249
+ }
250
+ /**
251
+ * Complete the current trajectory
252
+ */
253
+ export async function completeTrajectory(options = {}) {
254
+ const args = ['complete'];
255
+ if (options.summary) {
256
+ args.push('--summary', options.summary);
257
+ }
258
+ if (options.confidence !== undefined) {
259
+ args.push('--confidence', options.confidence.toString());
260
+ }
261
+ if (options.challenges && options.challenges.length > 0) {
262
+ args.push('--challenges', options.challenges.join(','));
263
+ }
264
+ if (options.learnings && options.learnings.length > 0) {
265
+ args.push('--learnings', options.learnings.join(','));
266
+ }
267
+ const result = await runTrail(args);
268
+ return { success: result.success, error: result.error };
269
+ }
270
+ /**
271
+ * Abandon the current trajectory
272
+ */
273
+ export async function abandonTrajectory(reason) {
274
+ const args = ['abandon'];
275
+ if (reason) {
276
+ args.push('--reason', reason);
277
+ }
278
+ const result = await runTrail(args);
279
+ return { success: result.success, error: result.error };
280
+ }
281
+ /**
282
+ * List trajectory steps/events
283
+ * Returns steps for the current or specified trajectory
284
+ * Reads directly from filesystem instead of using CLI
285
+ */
286
+ export async function listTrajectorySteps(trajectoryId) {
287
+ const index = readTrajectoryIndex();
288
+ if (!index) {
289
+ return { success: true, steps: [] };
290
+ }
291
+ // Find the trajectory to load
292
+ let trajectoryPath;
293
+ if (trajectoryId) {
294
+ // Use specified trajectory
295
+ const entry = index.trajectories[trajectoryId];
296
+ if (entry) {
297
+ trajectoryPath = entry.path;
298
+ }
299
+ }
300
+ else {
301
+ // Find active trajectory
302
+ for (const [_id, entry] of Object.entries(index.trajectories)) {
303
+ if (entry.status === 'active') {
304
+ trajectoryPath = entry.path;
305
+ break;
306
+ }
307
+ }
308
+ }
309
+ if (!trajectoryPath) {
310
+ return { success: true, steps: [] };
311
+ }
312
+ const trajectory = readTrajectoryFile(trajectoryPath);
313
+ if (!trajectory) {
314
+ return { success: true, steps: [] };
315
+ }
316
+ // Extract events from all chapters
317
+ const steps = [];
318
+ let stepIndex = 0;
319
+ for (const chapter of trajectory.chapters || []) {
320
+ for (const event of chapter.events || []) {
321
+ steps.push({
322
+ id: `step-${stepIndex++}`,
323
+ timestamp: event.ts || Date.now(),
324
+ type: mapEventType(event.type),
325
+ title: event.content?.slice(0, 50) || event.type || 'Event',
326
+ description: event.content,
327
+ metadata: event.raw,
328
+ status: mapEventStatus(trajectory.status),
329
+ });
330
+ }
331
+ }
332
+ return { success: true, steps };
333
+ }
334
+ /**
335
+ * Get trajectory history - list all trajectories
336
+ * Reads directly from filesystem
337
+ */
338
+ export async function getTrajectoryHistory() {
339
+ const index = readTrajectoryIndex();
340
+ if (!index) {
341
+ return { success: true, trajectories: [] };
342
+ }
343
+ const trajectories = [];
344
+ for (const [id, entry] of Object.entries(index.trajectories)) {
345
+ const historyEntry = {
346
+ id,
347
+ title: entry.title,
348
+ status: entry.status,
349
+ startedAt: entry.startedAt,
350
+ completedAt: entry.completedAt,
351
+ };
352
+ // Try to read full trajectory for additional details
353
+ if (entry.path) {
354
+ const trajectory = readTrajectoryFile(entry.path);
355
+ if (trajectory) {
356
+ historyEntry.agents = trajectory.agents?.map(a => a.name);
357
+ if (trajectory.retrospective) {
358
+ historyEntry.summary = trajectory.retrospective.summary;
359
+ historyEntry.confidence = trajectory.retrospective.confidence;
360
+ }
361
+ }
362
+ }
363
+ trajectories.push(historyEntry);
364
+ }
365
+ // Sort by startedAt descending (most recent first)
366
+ trajectories.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());
367
+ return { success: true, trajectories };
368
+ }
369
+ /**
370
+ * Map trail event type to dashboard type
371
+ */
372
+ function mapEventType(type) {
373
+ switch (type?.toLowerCase()) {
374
+ case 'tool':
375
+ case 'tool_call':
376
+ case 'tool_use':
377
+ return 'tool_call';
378
+ case 'decision':
379
+ case 'choice':
380
+ return 'decision';
381
+ case 'message':
382
+ case 'observation':
383
+ return 'message';
384
+ case 'phase':
385
+ case 'phase_change':
386
+ case 'phase_transition':
387
+ return 'phase_transition';
388
+ case 'error':
389
+ case 'failure':
390
+ return 'error';
391
+ default:
392
+ return 'state_change';
393
+ }
394
+ }
395
+ /**
396
+ * Map trail status to dashboard status
397
+ */
398
+ function mapEventStatus(status) {
399
+ switch (status?.toLowerCase()) {
400
+ case 'running':
401
+ case 'in_progress':
402
+ case 'active':
403
+ return 'running';
404
+ case 'success':
405
+ case 'completed':
406
+ case 'done':
407
+ return 'success';
408
+ case 'error':
409
+ case 'failed':
410
+ case 'abandoned':
411
+ return 'error';
412
+ case 'pending':
413
+ case 'queued':
414
+ return 'pending';
415
+ default:
416
+ return undefined;
417
+ }
418
+ }
419
+ /**
420
+ * Detect PDERO phase from content
421
+ */
422
+ export function detectPhaseFromContent(content) {
423
+ const lowerContent = content.toLowerCase();
424
+ const phasePatterns = [
425
+ { phase: 'plan', patterns: ['planning', 'analyzing requirements', 'breaking down', 'creating plan', 'task list', 'todo', 'outline'] },
426
+ { phase: 'design', patterns: ['designing', 'architecting', 'choosing pattern', 'interface design', 'schema design', 'architecture'] },
427
+ { phase: 'execute', patterns: ['implementing', 'writing', 'coding', 'building', 'creating file', 'modifying', 'editing'] },
428
+ { phase: 'review', patterns: ['testing', 'reviewing', 'validating', 'checking', 'verifying', 'running tests', 'test passed', 'test failed'] },
429
+ { phase: 'observe', patterns: ['observing', 'monitoring', 'reflecting', 'documenting', 'retrospective', 'learnings', 'summary'] },
430
+ ];
431
+ for (const { phase, patterns } of phasePatterns) {
432
+ for (const pattern of patterns) {
433
+ if (lowerContent.includes(pattern)) {
434
+ return phase;
435
+ }
436
+ }
437
+ }
438
+ return undefined;
439
+ }
440
+ /**
441
+ * All known Claude Code tool names
442
+ */
443
+ const TOOL_NAMES = [
444
+ 'Read', 'Write', 'Edit', 'Bash', 'Glob', 'Grep', 'Task', 'TaskOutput',
445
+ 'WebFetch', 'WebSearch', 'NotebookEdit', 'TodoWrite', 'AskUserQuestion',
446
+ 'KillShell', 'EnterPlanMode', 'ExitPlanMode', 'Skill', 'SlashCommand',
447
+ ];
448
+ const TOOL_NAME_PATTERN = TOOL_NAMES.join('|');
449
+ /**
450
+ * Tool call patterns for Claude Code and similar AI CLIs
451
+ */
452
+ const TOOL_PATTERNS = [
453
+ // Claude Code tool invocations (displayed in output with parenthesis/braces)
454
+ new RegExp(`(?:^|\\n)\\s*(?:${TOOL_NAME_PATTERN})\\s*[({]`, 'i'),
455
+ // Tool completion markers (checkmarks, spinners)
456
+ new RegExp(`(?:^|\\n)\\s*(?:✓|✔|⠋|⠙|⠹|⠸|⠼|⠴|⠦|⠧|⠇|⠏)\\s*(${TOOL_NAME_PATTERN})`, 'i'),
457
+ // Function call patterns (explicit mentions)
458
+ new RegExp(`(?:^|\\n)\\s*(?:Calling|Using|Invoking)\\s+(?:tool\\s+)?['"]?(${TOOL_NAME_PATTERN})['"]?`, 'i'),
459
+ // Tool result patterns
460
+ new RegExp(`(?:^|\\n)\\s*(?:Tool result|Result from)\\s*:?\\s*(${TOOL_NAME_PATTERN})`, 'i'),
461
+ ];
462
+ /**
463
+ * Error patterns for detecting failures in output
464
+ * Note: Patterns are ordered from most specific to least specific
465
+ */
466
+ const ERROR_PATTERNS = [
467
+ // JavaScript/TypeScript runtime errors (most specific)
468
+ /(?:^|\n)((?:TypeError|ReferenceError|SyntaxError|RangeError|EvalError|URIError):\s*.+)/i,
469
+ // Named Error with message (e.g., "Error: Something went wrong")
470
+ /(?:^|\n)(Error:\s+.+)/,
471
+ // Failed assertions
472
+ /(?:^|\n)\s*(AssertionError:\s*.+)/i,
473
+ // Test failures (Vitest, Jest patterns)
474
+ /(?:^|\n)\s*(FAIL\s+\S+\.(?:ts|js|tsx|jsx))/i,
475
+ /(?:^|\n)\s*(✗|✘|×)\s+(.+)/,
476
+ // Command/process failures
477
+ /(?:^|\n)\s*(Command failed[^\n]+)/i,
478
+ /(?:^|\n)\s*((?:Exit|exit)\s+code[:\s]+[1-9]\d*)/i,
479
+ /(?:^|\n)\s*(exited with (?:code\s+)?[1-9]\d*)/i,
480
+ // Node.js/system errors
481
+ /(?:^|\n)\s*(EACCES|EPERM|ENOENT|ECONNREFUSED|ETIMEDOUT|ENOTFOUND)(?::\s*.+)?/,
482
+ // Build/compile errors (webpack, tsc, etc.)
483
+ /(?:^|\n)\s*(error TS\d+:\s*.+)/i,
484
+ /(?:^|\n)\s*(error\[\S+\]:\s*.+)/i,
485
+ ];
486
+ /**
487
+ * Warning patterns for detecting potential issues
488
+ */
489
+ const WARNING_PATTERNS = [
490
+ /(?:^|\n)\s*(?:warning|WARN|⚠️?)\s*[:\[]?\s*(.+)/i,
491
+ /(?:^|\n)\s*(?:deprecated|DEPRECATED):\s*(.+)/i,
492
+ ];
493
+ /**
494
+ * Detect tool calls from agent output
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * const tools = detectToolCalls(output);
499
+ * // Returns: [{ tool: 'Read', args: 'file.ts' }, { tool: 'Bash', status: 'completed' }]
500
+ * ```
501
+ */
502
+ export function detectToolCalls(content) {
503
+ const detected = [];
504
+ const seenTools = new Set();
505
+ const toolNameExtractor = new RegExp(`\\b(${TOOL_NAME_PATTERN})\\b`, 'i');
506
+ for (const pattern of TOOL_PATTERNS) {
507
+ const matches = content.matchAll(new RegExp(pattern.source, 'gi'));
508
+ for (const match of matches) {
509
+ // Extract tool name from the match
510
+ const fullMatch = match[0];
511
+ const toolNameMatch = fullMatch.match(toolNameExtractor);
512
+ if (toolNameMatch) {
513
+ const tool = toolNameMatch[1];
514
+ // Avoid duplicates by position (same tool at same position)
515
+ const key = `${tool}:${match.index}`;
516
+ if (!seenTools.has(key)) {
517
+ seenTools.add(key);
518
+ detected.push({
519
+ tool,
520
+ status: fullMatch.includes('✓') || fullMatch.includes('✔') ? 'completed' : 'started',
521
+ });
522
+ }
523
+ }
524
+ }
525
+ }
526
+ return detected;
527
+ }
528
+ /**
529
+ * Detect errors from agent output
530
+ *
531
+ * @example
532
+ * ```typescript
533
+ * const errors = detectErrors(output);
534
+ * // Returns: [{ type: 'error', message: 'TypeError: Cannot read property...' }]
535
+ * ```
536
+ */
537
+ export function detectErrors(content) {
538
+ const detected = [];
539
+ const seenMessages = new Set();
540
+ // Check for error patterns
541
+ for (const pattern of ERROR_PATTERNS) {
542
+ const matches = content.matchAll(new RegExp(pattern, 'gi'));
543
+ for (const match of matches) {
544
+ const message = match[1] || match[0];
545
+ const cleanMessage = message.trim().slice(0, 200); // Limit length
546
+ if (!seenMessages.has(cleanMessage)) {
547
+ seenMessages.add(cleanMessage);
548
+ detected.push({
549
+ type: 'error',
550
+ message: cleanMessage,
551
+ });
552
+ }
553
+ }
554
+ }
555
+ // Check for warning patterns
556
+ for (const pattern of WARNING_PATTERNS) {
557
+ const matches = content.matchAll(new RegExp(pattern, 'gi'));
558
+ for (const match of matches) {
559
+ const message = match[1] || match[0];
560
+ const cleanMessage = message.trim().slice(0, 200);
561
+ if (!seenMessages.has(cleanMessage)) {
562
+ seenMessages.add(cleanMessage);
563
+ detected.push({
564
+ type: 'warning',
565
+ message: cleanMessage,
566
+ });
567
+ }
568
+ }
569
+ }
570
+ return detected;
571
+ }
572
+ /**
573
+ * TrajectoryIntegration class for managing trajectory state
574
+ *
575
+ * This class enforces trajectory tracking during agent lifecycle:
576
+ * - Auto-starts trajectory when agent is instantiated with a task
577
+ * - Records all inter-agent messages
578
+ * - Auto-detects PDERO phase transitions
579
+ * - Provides lifecycle hooks for tmux/pty wrappers
580
+ */
581
+ export class TrajectoryIntegration {
582
+ projectId;
583
+ agentName;
584
+ trailAvailable = null;
585
+ currentPhase = null;
586
+ trajectoryId = null;
587
+ initialized = false;
588
+ task = null;
589
+ constructor(projectId, agentName) {
590
+ this.projectId = projectId;
591
+ this.agentName = agentName;
592
+ }
593
+ /**
594
+ * Check if trail is available (cached)
595
+ */
596
+ async isAvailable() {
597
+ if (this.trailAvailable === null) {
598
+ this.trailAvailable = await isTrailAvailable();
599
+ }
600
+ return this.trailAvailable;
601
+ }
602
+ /**
603
+ * Check if trail CLI is installed synchronously
604
+ */
605
+ isTrailInstalledSync() {
606
+ try {
607
+ execSync('which trail', { stdio: 'pipe' });
608
+ return true;
609
+ }
610
+ catch {
611
+ return false;
612
+ }
613
+ }
614
+ /**
615
+ * Initialize trajectory tracking for agent lifecycle
616
+ * Called automatically when agent starts with a task
617
+ */
618
+ async initialize(task, taskId, source) {
619
+ if (this.initialized)
620
+ return true;
621
+ if (!(await this.isAvailable())) {
622
+ return false;
623
+ }
624
+ // If task provided, auto-start trajectory
625
+ if (task) {
626
+ const success = await this.start(task, taskId, source);
627
+ if (success) {
628
+ this.initialized = true;
629
+ this.task = task;
630
+ }
631
+ return success;
632
+ }
633
+ this.initialized = true;
634
+ return true;
635
+ }
636
+ /**
637
+ * Start tracking a trajectory
638
+ */
639
+ async start(task, taskId, source) {
640
+ if (!(await this.isAvailable()))
641
+ return false;
642
+ const result = await startTrajectory({
643
+ task,
644
+ taskId,
645
+ source,
646
+ agentName: this.agentName,
647
+ phase: 'plan',
648
+ });
649
+ if (result.success) {
650
+ this.currentPhase = 'plan';
651
+ this.trajectoryId = result.trajectoryId || null;
652
+ this.task = task;
653
+ }
654
+ return result.success;
655
+ }
656
+ /**
657
+ * Check if there's an active trajectory
658
+ */
659
+ hasActiveTrajectory() {
660
+ return this.currentPhase !== null;
661
+ }
662
+ /**
663
+ * Get the current task
664
+ */
665
+ getTask() {
666
+ return this.task;
667
+ }
668
+ /**
669
+ * Get trajectory ID
670
+ */
671
+ getTrajectoryId() {
672
+ return this.trajectoryId;
673
+ }
674
+ /**
675
+ * Record a message
676
+ */
677
+ async message(direction, from, to, body) {
678
+ if (!(await this.isAvailable()))
679
+ return;
680
+ await recordMessage(direction, from, to, body);
681
+ // Check for phase transition based on content
682
+ const detectedPhase = detectPhaseFromContent(body);
683
+ if (detectedPhase && detectedPhase !== this.currentPhase) {
684
+ await this.transition(detectedPhase, 'Auto-detected from message content');
685
+ }
686
+ }
687
+ /**
688
+ * Transition to a new phase
689
+ */
690
+ async transition(phase, reason) {
691
+ if (!(await this.isAvailable()))
692
+ return false;
693
+ if (phase === this.currentPhase)
694
+ return true;
695
+ const result = await transitionPhase(phase, reason, this.agentName);
696
+ if (result.success) {
697
+ this.currentPhase = phase;
698
+ }
699
+ return result.success;
700
+ }
701
+ /**
702
+ * Record a decision
703
+ */
704
+ async decision(choice, options) {
705
+ if (!(await this.isAvailable()))
706
+ return false;
707
+ const result = await recordDecision({
708
+ choice,
709
+ ...options,
710
+ });
711
+ return result.success;
712
+ }
713
+ /**
714
+ * Record an event
715
+ */
716
+ async event(content, type = 'observation') {
717
+ if (!(await this.isAvailable()))
718
+ return false;
719
+ const result = await recordEvent(content, type, this.agentName);
720
+ // Check for phase transition
721
+ const detectedPhase = detectPhaseFromContent(content);
722
+ if (detectedPhase && detectedPhase !== this.currentPhase) {
723
+ await this.transition(detectedPhase, 'Auto-detected from event content');
724
+ }
725
+ return result.success;
726
+ }
727
+ /**
728
+ * Complete the trajectory
729
+ */
730
+ async complete(options) {
731
+ if (!(await this.isAvailable()))
732
+ return false;
733
+ const result = await completeTrajectory(options);
734
+ if (result.success) {
735
+ this.currentPhase = null;
736
+ }
737
+ return result.success;
738
+ }
739
+ /**
740
+ * Abandon the trajectory
741
+ */
742
+ async abandon(reason) {
743
+ if (!(await this.isAvailable()))
744
+ return false;
745
+ const result = await abandonTrajectory(reason);
746
+ if (result.success) {
747
+ this.currentPhase = null;
748
+ }
749
+ return result.success;
750
+ }
751
+ /**
752
+ * Get current phase
753
+ */
754
+ getPhase() {
755
+ return this.currentPhase;
756
+ }
757
+ }
758
+ /**
759
+ * Global trajectory integration instances
760
+ */
761
+ const instances = new Map();
762
+ /**
763
+ * Get or create a TrajectoryIntegration instance
764
+ */
765
+ export function getTrajectoryIntegration(projectId, agentName) {
766
+ const key = `${projectId}:${agentName}`;
767
+ let instance = instances.get(key);
768
+ if (!instance) {
769
+ instance = new TrajectoryIntegration(projectId, agentName);
770
+ instances.set(key, instance);
771
+ }
772
+ return instance;
773
+ }
774
+ /**
775
+ * Generate trail usage instructions for agents
776
+ */
777
+ export function getTrailInstructions() {
778
+ return [
779
+ '📍 TRAJECTORY TRACKING (PDERO Paradigm)',
780
+ '',
781
+ 'You MUST use trail commands to track your work:',
782
+ '',
783
+ 'PHASES: plan → design → execute → review → observe',
784
+ '',
785
+ 'COMMANDS:',
786
+ ' trail start "task" Start trajectory for a task',
787
+ ' trail phase <phase> Transition to new phase',
788
+ ' trail decision "choice" Record key decisions',
789
+ ' trail event "what happened" Log significant events',
790
+ ' trail complete Complete with summary',
791
+ '',
792
+ 'WHEN TO USE:',
793
+ ' - Start: At beginning of any task',
794
+ ' - Phase: When shifting focus (planning→implementing, etc.)',
795
+ ' - Decision: For architecture/approach choices',
796
+ ' - Event: For tool calls, errors, milestones',
797
+ ' - Complete: When task is done',
798
+ '',
799
+ 'Example workflow:',
800
+ ' trail start "Implement auth feature"',
801
+ ' trail phase design',
802
+ ' trail decision "Use JWT" --reasoning "Stateless, scalable"',
803
+ ' trail phase execute',
804
+ ' trail event "Created auth middleware"',
805
+ ' trail phase review',
806
+ ' trail event "All tests passing"',
807
+ ' trail complete --summary "Auth implemented" --confidence 0.9',
808
+ ];
809
+ }
810
+ /**
811
+ * Get a compact trail instruction string for injection
812
+ */
813
+ export function getCompactTrailInstructions() {
814
+ return [
815
+ '[TRAIL] Track work with PDERO: plan→design→execute→review→observe.',
816
+ 'Commands: trail start "task" | trail phase <phase> | trail decision "choice" | trail event "log" | trail complete',
817
+ 'Use trail often to document your thought process.',
818
+ ].join(' ');
819
+ }
820
+ /**
821
+ * Get environment variables for trail CLI
822
+ * If dataDir is not provided, uses config-based storage location
823
+ */
824
+ export function getTrailEnvVars(projectId, agentName, dataDir) {
825
+ // Use config-based path if dataDir not explicitly provided
826
+ const effectiveDataDir = dataDir ?? getPrimaryTrajectoriesDir();
827
+ return {
828
+ TRAJECTORIES_PROJECT: projectId,
829
+ TRAJECTORIES_DATA_DIR: effectiveDataDir,
830
+ TRAJECTORIES_AGENT: agentName,
831
+ TRAIL_AUTO_PHASE: '1', // Enable auto phase detection
832
+ };
833
+ }
834
+ //# sourceMappingURL=integration.js.map