agent-relay 2.0.29 → 2.0.32

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 (894) hide show
  1. package/README.md +19 -0
  2. package/dist/index.cjs +85691 -0
  3. package/dist/src/bridge/index.d.ts.map +1 -0
  4. package/dist/src/bridge/index.js.map +1 -0
  5. package/dist/src/cli/commands/doctor.d.ts +2 -0
  6. package/dist/src/cli/commands/doctor.d.ts.map +1 -0
  7. package/dist/src/cli/commands/doctor.js +451 -0
  8. package/dist/src/cli/commands/doctor.js.map +1 -0
  9. package/dist/src/cli/index.d.ts.map +1 -0
  10. package/dist/src/cli/index.js +29 -1
  11. package/dist/src/cli/index.js.map +1 -0
  12. package/dist/src/config/relay-config.d.ts.map +1 -0
  13. package/dist/src/config/relay-config.js.map +1 -0
  14. package/dist/src/continuity/index.d.ts.map +1 -0
  15. package/dist/src/continuity/index.js.map +1 -0
  16. package/dist/src/daemon/index.d.ts.map +1 -0
  17. package/dist/src/daemon/index.js.map +1 -0
  18. package/dist/src/health-worker-manager.d.ts.map +1 -0
  19. package/dist/src/health-worker-manager.js.map +1 -0
  20. package/dist/src/health-worker.d.ts.map +1 -0
  21. package/dist/src/health-worker.js.map +1 -0
  22. package/dist/src/hooks/index.d.ts.map +1 -0
  23. package/dist/src/hooks/index.js.map +1 -0
  24. package/dist/src/index.d.ts.map +1 -0
  25. package/dist/src/index.js.map +1 -0
  26. package/dist/src/memory/index.d.ts.map +1 -0
  27. package/dist/src/memory/index.js.map +1 -0
  28. package/dist/src/policy/index.d.ts.map +1 -0
  29. package/dist/src/policy/index.js.map +1 -0
  30. package/dist/src/protocol/index.d.ts.map +1 -0
  31. package/dist/src/protocol/index.js.map +1 -0
  32. package/dist/src/resiliency/index.d.ts.map +1 -0
  33. package/dist/src/resiliency/index.js.map +1 -0
  34. package/dist/src/shared/cli-auth-config.d.ts.map +1 -0
  35. package/dist/src/shared/cli-auth-config.js.map +1 -0
  36. package/dist/src/state/index.d.ts.map +1 -0
  37. package/dist/src/state/index.js.map +1 -0
  38. package/dist/src/storage/index.d.ts.map +1 -0
  39. package/dist/src/storage/index.js.map +1 -0
  40. package/dist/src/trajectory/index.d.ts.map +1 -0
  41. package/dist/src/trajectory/index.js.map +1 -0
  42. package/dist/src/utils/index.d.ts.map +1 -0
  43. package/dist/src/utils/index.js.map +1 -0
  44. package/dist/src/wrapper/index.d.ts.map +1 -0
  45. package/dist/src/wrapper/index.js.map +1 -0
  46. package/package.json +83 -20
  47. package/packages/api-types/dist/index.d.ts.map +1 -0
  48. package/packages/api-types/dist/index.js.map +1 -0
  49. package/packages/api-types/dist/schemas/agent.d.ts.map +1 -0
  50. package/packages/api-types/dist/schemas/agent.js.map +1 -0
  51. package/packages/api-types/dist/schemas/api.d.ts.map +1 -0
  52. package/packages/api-types/dist/schemas/api.js.map +1 -0
  53. package/packages/api-types/dist/schemas/decision.d.ts.map +1 -0
  54. package/packages/api-types/dist/schemas/decision.js.map +1 -0
  55. package/packages/api-types/dist/schemas/fleet.d.ts.map +1 -0
  56. package/packages/api-types/dist/schemas/fleet.js.map +1 -0
  57. package/packages/api-types/dist/schemas/history.d.ts.map +1 -0
  58. package/packages/api-types/dist/schemas/history.js.map +1 -0
  59. package/packages/api-types/dist/schemas/index.d.ts.map +1 -0
  60. package/packages/api-types/dist/schemas/index.js.map +1 -0
  61. package/packages/api-types/dist/schemas/message.d.ts.map +1 -0
  62. package/packages/api-types/dist/schemas/message.js.map +1 -0
  63. package/packages/api-types/dist/schemas/session.d.ts.map +1 -0
  64. package/packages/api-types/dist/schemas/session.js.map +1 -0
  65. package/packages/api-types/dist/schemas/task.d.ts.map +1 -0
  66. package/packages/api-types/dist/schemas/task.js.map +1 -0
  67. package/packages/api-types/package.json +1 -1
  68. package/packages/api-types/src/index.ts +22 -0
  69. package/packages/api-types/src/schemas/agent.test.ts +164 -0
  70. package/packages/api-types/src/schemas/agent.ts +110 -0
  71. package/packages/api-types/src/schemas/api.test.ts +372 -0
  72. package/packages/api-types/src/schemas/api.ts +194 -0
  73. package/packages/api-types/src/schemas/decision.test.ts +324 -0
  74. package/packages/api-types/src/schemas/decision.ts +136 -0
  75. package/packages/api-types/src/schemas/fleet.test.ts +212 -0
  76. package/packages/api-types/src/schemas/fleet.ts +83 -0
  77. package/packages/api-types/src/schemas/history.test.ts +242 -0
  78. package/packages/api-types/src/schemas/history.ts +84 -0
  79. package/packages/api-types/src/schemas/index.ts +148 -0
  80. package/packages/api-types/src/schemas/message.test.ts +192 -0
  81. package/packages/api-types/src/schemas/message.ts +98 -0
  82. package/packages/api-types/src/schemas/session.test.ts +104 -0
  83. package/packages/api-types/src/schemas/session.ts +40 -0
  84. package/packages/api-types/src/schemas/task.test.ts +192 -0
  85. package/packages/api-types/src/schemas/task.ts +78 -0
  86. package/packages/api-types/tsconfig.json +19 -0
  87. package/packages/api-types/vitest.config.ts +9 -0
  88. package/packages/benchmark/README.md +200 -0
  89. package/packages/benchmark/datasets/coding-tasks.yaml +127 -0
  90. package/packages/benchmark/datasets/coordination-tasks.yaml +122 -0
  91. package/packages/benchmark/dist/benchmark.d.ts +47 -0
  92. package/packages/benchmark/dist/benchmark.d.ts.map +1 -0
  93. package/packages/benchmark/dist/benchmark.js +224 -0
  94. package/packages/benchmark/dist/benchmark.js.map +1 -0
  95. package/packages/benchmark/dist/cli.d.ts +8 -0
  96. package/packages/benchmark/dist/cli.d.ts.map +1 -0
  97. package/packages/benchmark/dist/cli.js +185 -0
  98. package/packages/benchmark/dist/cli.js.map +1 -0
  99. package/packages/benchmark/dist/harbor.d.ts +53 -0
  100. package/packages/benchmark/dist/harbor.d.ts.map +1 -0
  101. package/packages/benchmark/dist/harbor.js +127 -0
  102. package/packages/benchmark/dist/harbor.js.map +1 -0
  103. package/packages/benchmark/dist/index.d.ts +48 -0
  104. package/packages/benchmark/dist/index.d.ts.map +1 -0
  105. package/packages/benchmark/dist/index.js +50 -0
  106. package/packages/benchmark/dist/index.js.map +1 -0
  107. package/packages/benchmark/dist/runners/base.d.ts +63 -0
  108. package/packages/benchmark/dist/runners/base.d.ts.map +1 -0
  109. package/packages/benchmark/dist/runners/base.js +155 -0
  110. package/packages/benchmark/dist/runners/base.js.map +1 -0
  111. package/packages/benchmark/dist/runners/index.d.ts +10 -0
  112. package/packages/benchmark/dist/runners/index.d.ts.map +1 -0
  113. package/packages/benchmark/dist/runners/index.js +10 -0
  114. package/packages/benchmark/dist/runners/index.js.map +1 -0
  115. package/packages/benchmark/dist/runners/single.d.ts +19 -0
  116. package/packages/benchmark/dist/runners/single.d.ts.map +1 -0
  117. package/packages/benchmark/dist/runners/single.js +111 -0
  118. package/packages/benchmark/dist/runners/single.js.map +1 -0
  119. package/packages/benchmark/dist/runners/subagent.d.ts +32 -0
  120. package/packages/benchmark/dist/runners/subagent.d.ts.map +1 -0
  121. package/packages/benchmark/dist/runners/subagent.js +212 -0
  122. package/packages/benchmark/dist/runners/subagent.js.map +1 -0
  123. package/packages/benchmark/dist/runners/swarm.d.ts +36 -0
  124. package/packages/benchmark/dist/runners/swarm.d.ts.map +1 -0
  125. package/packages/benchmark/dist/runners/swarm.js +273 -0
  126. package/packages/benchmark/dist/runners/swarm.js.map +1 -0
  127. package/packages/benchmark/dist/types.d.ts +178 -0
  128. package/packages/benchmark/dist/types.d.ts.map +1 -0
  129. package/packages/benchmark/dist/types.js +16 -0
  130. package/packages/benchmark/dist/types.js.map +1 -0
  131. package/packages/benchmark/package.json +80 -0
  132. package/packages/benchmark/src/benchmark.ts +298 -0
  133. package/packages/benchmark/src/cli.ts +240 -0
  134. package/packages/benchmark/src/harbor.ts +170 -0
  135. package/packages/benchmark/src/index.ts +73 -0
  136. package/packages/benchmark/src/runners/base.ts +204 -0
  137. package/packages/benchmark/src/runners/index.ts +10 -0
  138. package/packages/benchmark/src/runners/single.ts +121 -0
  139. package/packages/benchmark/src/runners/subagent.ts +240 -0
  140. package/packages/benchmark/src/runners/swarm.ts +326 -0
  141. package/packages/benchmark/src/types.ts +205 -0
  142. package/packages/benchmark/tsconfig.json +20 -0
  143. package/packages/bridge/dist/index.d.ts.map +1 -0
  144. package/packages/bridge/dist/index.js.map +1 -0
  145. package/packages/bridge/dist/multi-project-client.d.ts.map +1 -0
  146. package/packages/bridge/dist/multi-project-client.js.map +1 -0
  147. package/packages/bridge/dist/shadow-cli.d.ts.map +1 -0
  148. package/packages/bridge/dist/shadow-cli.js.map +1 -0
  149. package/packages/bridge/dist/spawner.d.ts.map +1 -0
  150. package/packages/bridge/dist/spawner.js +10 -2
  151. package/packages/bridge/dist/spawner.js.map +1 -0
  152. package/packages/bridge/dist/types.d.ts.map +1 -0
  153. package/packages/bridge/dist/types.js.map +1 -0
  154. package/packages/bridge/dist/utils.d.ts.map +1 -0
  155. package/packages/bridge/dist/utils.js.map +1 -0
  156. package/packages/bridge/package.json +8 -8
  157. package/packages/bridge/src/index.ts +25 -0
  158. package/packages/bridge/src/multi-project-client.test.ts +340 -0
  159. package/packages/bridge/src/multi-project-client.ts +469 -0
  160. package/packages/bridge/src/shadow-cli.ts +95 -0
  161. package/packages/bridge/src/spawner-mcp.test.ts +505 -0
  162. package/packages/bridge/src/spawner.ts +1724 -0
  163. package/packages/bridge/src/types.ts +145 -0
  164. package/packages/bridge/src/utils.test.ts +98 -0
  165. package/packages/bridge/src/utils.ts +67 -0
  166. package/packages/bridge/tsconfig.json +29 -0
  167. package/packages/bridge/vitest.config.ts +9 -0
  168. package/packages/cli-tester/dist/index.d.ts.map +1 -0
  169. package/packages/cli-tester/dist/index.js.map +1 -0
  170. package/packages/cli-tester/dist/utils/credential-check.d.ts.map +1 -0
  171. package/packages/cli-tester/dist/utils/credential-check.js.map +1 -0
  172. package/packages/cli-tester/dist/utils/socket-client.d.ts.map +1 -0
  173. package/packages/cli-tester/dist/utils/socket-client.js.map +1 -0
  174. package/packages/cli-tester/docker/Dockerfile +61 -0
  175. package/packages/cli-tester/docker/docker-compose.yml +71 -0
  176. package/packages/cli-tester/package.json +1 -1
  177. package/packages/cli-tester/src/index.ts +40 -0
  178. package/packages/cli-tester/src/utils/credential-check.ts +284 -0
  179. package/packages/cli-tester/src/utils/socket-client.ts +211 -0
  180. package/packages/cli-tester/tests/credential-check.test.ts +56 -0
  181. package/packages/cli-tester/tsconfig.json +11 -0
  182. package/packages/config/dist/agent-config.d.ts.map +1 -0
  183. package/packages/config/dist/agent-config.js.map +1 -0
  184. package/packages/config/dist/bridge-config.d.ts.map +1 -0
  185. package/packages/config/dist/bridge-config.js.map +1 -0
  186. package/packages/config/dist/bridge-utils.d.ts.map +1 -0
  187. package/packages/config/dist/bridge-utils.js.map +1 -0
  188. package/packages/config/dist/cli-auth-config.d.ts.map +1 -0
  189. package/packages/config/dist/cli-auth-config.js.map +1 -0
  190. package/packages/config/dist/cloud-config.d.ts.map +1 -0
  191. package/packages/config/dist/cloud-config.js.map +1 -0
  192. package/packages/config/dist/index.d.ts.map +1 -0
  193. package/packages/config/dist/index.js.map +1 -0
  194. package/packages/config/dist/project-namespace.d.ts.map +1 -0
  195. package/packages/config/dist/project-namespace.js.map +1 -0
  196. package/packages/config/dist/relay-config.d.ts.map +1 -0
  197. package/packages/config/dist/relay-config.js.map +1 -0
  198. package/packages/config/dist/relay-file-writer.d.ts.map +1 -0
  199. package/packages/config/dist/relay-file-writer.js.map +1 -0
  200. package/packages/config/dist/schemas.d.ts.map +1 -0
  201. package/packages/config/dist/schemas.js.map +1 -0
  202. package/packages/config/dist/shadow-config.d.ts.map +1 -0
  203. package/packages/config/dist/shadow-config.js.map +1 -0
  204. package/packages/config/dist/teams-config.d.ts.map +1 -0
  205. package/packages/config/dist/teams-config.js.map +1 -0
  206. package/packages/config/dist/trajectory-config.d.ts.map +1 -0
  207. package/packages/config/dist/trajectory-config.js.map +1 -0
  208. package/packages/config/package.json +2 -2
  209. package/packages/config/src/agent-config.test.ts +245 -0
  210. package/packages/config/src/agent-config.ts +160 -0
  211. package/packages/config/src/bridge-config.test.ts +132 -0
  212. package/packages/config/src/bridge-config.ts +189 -0
  213. package/packages/config/src/bridge-utils.ts +59 -0
  214. package/packages/config/src/cli-auth-config.ts +548 -0
  215. package/packages/config/src/cloud-config.ts +208 -0
  216. package/packages/config/src/index.ts +12 -0
  217. package/packages/config/src/project-namespace.ts +344 -0
  218. package/packages/config/src/relay-config.test.ts +51 -0
  219. package/packages/config/src/relay-config.ts +36 -0
  220. package/packages/config/src/relay-file-writer.test.ts +351 -0
  221. package/packages/config/src/relay-file-writer.ts +508 -0
  222. package/packages/config/src/schemas.test.ts +59 -0
  223. package/packages/config/src/schemas.ts +201 -0
  224. package/packages/config/src/shadow-config.ts +205 -0
  225. package/packages/config/src/teams-config.ts +135 -0
  226. package/packages/config/src/trajectory-config.ts +222 -0
  227. package/packages/config/tsconfig.json +21 -0
  228. package/packages/config/vitest.config.ts +9 -0
  229. package/packages/continuity/dist/formatter.d.ts.map +1 -0
  230. package/packages/continuity/dist/formatter.js.map +1 -0
  231. package/packages/continuity/dist/handoff-store.d.ts.map +1 -0
  232. package/packages/continuity/dist/handoff-store.js.map +1 -0
  233. package/packages/continuity/dist/index.d.ts.map +1 -0
  234. package/packages/continuity/dist/index.js.map +1 -0
  235. package/packages/continuity/dist/ledger-store.d.ts.map +1 -0
  236. package/packages/continuity/dist/ledger-store.js.map +1 -0
  237. package/packages/continuity/dist/manager.d.ts.map +1 -0
  238. package/packages/continuity/dist/manager.js.map +1 -0
  239. package/packages/continuity/dist/parser.d.ts.map +1 -0
  240. package/packages/continuity/dist/parser.js.map +1 -0
  241. package/packages/continuity/dist/types.d.ts.map +1 -0
  242. package/packages/continuity/dist/types.js.map +1 -0
  243. package/packages/continuity/package.json +1 -1
  244. package/packages/continuity/src/formatter.ts +371 -0
  245. package/packages/continuity/src/handoff-store.ts +523 -0
  246. package/packages/continuity/src/index.ts +9 -0
  247. package/packages/continuity/src/ledger-store.ts +594 -0
  248. package/packages/continuity/src/manager.test.ts +291 -0
  249. package/packages/continuity/src/manager.ts +774 -0
  250. package/packages/continuity/src/parser.test.ts +292 -0
  251. package/packages/continuity/src/parser.ts +680 -0
  252. package/packages/continuity/src/types.ts +211 -0
  253. package/packages/continuity/tsconfig.json +21 -0
  254. package/packages/continuity/vitest.config.ts +9 -0
  255. package/packages/daemon/dist/agent-manager.d.ts.map +1 -0
  256. package/packages/daemon/dist/agent-manager.js.map +1 -0
  257. package/packages/daemon/dist/agent-registry.d.ts.map +1 -0
  258. package/packages/daemon/dist/agent-registry.js.map +1 -0
  259. package/packages/daemon/dist/agent-signing.d.ts.map +1 -0
  260. package/packages/daemon/dist/agent-signing.js.map +1 -0
  261. package/packages/daemon/dist/api.d.ts.map +1 -0
  262. package/packages/daemon/dist/api.js.map +1 -0
  263. package/packages/daemon/dist/auth.d.ts.map +1 -0
  264. package/packages/daemon/dist/auth.js.map +1 -0
  265. package/packages/daemon/dist/channel-membership-store.d.ts.map +1 -0
  266. package/packages/daemon/dist/channel-membership-store.js.map +1 -0
  267. package/packages/daemon/dist/cli-auth.d.ts.map +1 -0
  268. package/packages/daemon/dist/cli-auth.js.map +1 -0
  269. package/packages/daemon/dist/cloud-sync.d.ts.map +1 -0
  270. package/packages/daemon/dist/cloud-sync.js.map +1 -0
  271. package/packages/daemon/dist/connection.d.ts.map +1 -0
  272. package/packages/daemon/dist/connection.js.map +1 -0
  273. package/packages/daemon/dist/consensus-integration.d.ts.map +1 -0
  274. package/packages/daemon/dist/consensus-integration.js.map +1 -0
  275. package/packages/daemon/dist/consensus.d.ts.map +1 -0
  276. package/packages/daemon/dist/consensus.js.map +1 -0
  277. package/packages/daemon/dist/delivery-tracker.d.ts.map +1 -0
  278. package/packages/daemon/dist/delivery-tracker.js.map +1 -0
  279. package/packages/daemon/dist/enhanced-features.d.ts.map +1 -0
  280. package/packages/daemon/dist/enhanced-features.js.map +1 -0
  281. package/packages/daemon/dist/index.d.ts.map +1 -0
  282. package/packages/daemon/dist/index.js.map +1 -0
  283. package/packages/daemon/dist/migrations/index.d.ts.map +1 -0
  284. package/packages/daemon/dist/migrations/index.js.map +1 -0
  285. package/packages/daemon/dist/orchestrator.d.ts.map +1 -0
  286. package/packages/daemon/dist/orchestrator.js.map +1 -0
  287. package/packages/daemon/dist/rate-limiter.d.ts.map +1 -0
  288. package/packages/daemon/dist/rate-limiter.js.map +1 -0
  289. package/packages/daemon/dist/registry.d.ts.map +1 -0
  290. package/packages/daemon/dist/registry.js.map +1 -0
  291. package/packages/daemon/dist/relay-ledger.d.ts.map +1 -0
  292. package/packages/daemon/dist/relay-ledger.js.map +1 -0
  293. package/packages/daemon/dist/relay-watchdog.d.ts.map +1 -0
  294. package/packages/daemon/dist/relay-watchdog.js.map +1 -0
  295. package/packages/daemon/dist/repo-manager.d.ts.map +1 -0
  296. package/packages/daemon/dist/repo-manager.js.map +1 -0
  297. package/packages/daemon/dist/router.d.ts.map +1 -0
  298. package/packages/daemon/dist/router.js.map +1 -0
  299. package/packages/daemon/dist/server.d.ts +1 -0
  300. package/packages/daemon/dist/server.d.ts.map +1 -0
  301. package/packages/daemon/dist/server.js +46 -16
  302. package/packages/daemon/dist/server.js.map +1 -0
  303. package/packages/daemon/dist/spawn-manager.d.ts.map +1 -0
  304. package/packages/daemon/dist/spawn-manager.js.map +1 -0
  305. package/packages/daemon/dist/sync-queue.d.ts.map +1 -0
  306. package/packages/daemon/dist/sync-queue.js.map +1 -0
  307. package/packages/daemon/dist/types.d.ts.map +1 -0
  308. package/packages/daemon/dist/types.js.map +1 -0
  309. package/packages/daemon/dist/workspace-manager.d.ts.map +1 -0
  310. package/packages/daemon/dist/workspace-manager.js.map +1 -0
  311. package/packages/daemon/package.json +12 -12
  312. package/packages/daemon/src/agent-manager.ts +679 -0
  313. package/packages/daemon/src/agent-registry.ts +284 -0
  314. package/packages/daemon/src/agent-signing.ts +707 -0
  315. package/packages/daemon/src/api.ts +1012 -0
  316. package/packages/daemon/src/auth.ts +276 -0
  317. package/packages/daemon/src/channel-membership-store.ts +217 -0
  318. package/packages/daemon/src/cli-auth.ts +906 -0
  319. package/packages/daemon/src/cloud-sync.ts +902 -0
  320. package/packages/daemon/src/connection.ts +534 -0
  321. package/packages/daemon/src/consensus-integration.ts +510 -0
  322. package/packages/daemon/src/consensus.ts +848 -0
  323. package/packages/daemon/src/delivery-tracker.ts +145 -0
  324. package/packages/daemon/src/enhanced-features.ts +390 -0
  325. package/packages/daemon/src/index.ts +52 -0
  326. package/packages/daemon/src/migrations/0001_initial.sql +72 -0
  327. package/packages/daemon/src/migrations/index.test.ts +195 -0
  328. package/packages/daemon/src/migrations/index.ts +286 -0
  329. package/packages/daemon/src/orchestrator.test.ts +231 -0
  330. package/packages/daemon/src/orchestrator.ts +1376 -0
  331. package/packages/daemon/src/rate-limiter.ts +172 -0
  332. package/packages/daemon/src/registry.ts +8 -0
  333. package/packages/daemon/src/relay-ledger.test.ts +358 -0
  334. package/packages/daemon/src/relay-ledger.ts +713 -0
  335. package/packages/daemon/src/relay-watchdog.test.ts +881 -0
  336. package/packages/daemon/src/relay-watchdog.ts +785 -0
  337. package/packages/daemon/src/repo-manager.ts +468 -0
  338. package/packages/daemon/src/router.test.ts +149 -0
  339. package/packages/daemon/src/router.ts +1885 -0
  340. package/packages/daemon/src/server.ts +1871 -0
  341. package/packages/daemon/src/spawn-manager.ts +275 -0
  342. package/packages/daemon/src/sync-queue.ts +477 -0
  343. package/packages/daemon/src/types.ts +158 -0
  344. package/packages/daemon/src/workspace-manager.ts +371 -0
  345. package/packages/daemon/tsconfig.json +21 -0
  346. package/packages/hooks/dist/browser.d.ts.map +1 -0
  347. package/packages/hooks/dist/browser.js.map +1 -0
  348. package/packages/hooks/dist/emitter.d.ts.map +1 -0
  349. package/packages/hooks/dist/emitter.js.map +1 -0
  350. package/packages/hooks/dist/inbox-check/hook.d.ts.map +1 -0
  351. package/packages/hooks/dist/inbox-check/hook.js.map +1 -0
  352. package/packages/hooks/dist/inbox-check/index.d.ts.map +1 -0
  353. package/packages/hooks/dist/inbox-check/index.js.map +1 -0
  354. package/packages/hooks/dist/inbox-check/types.d.ts.map +1 -0
  355. package/packages/hooks/dist/inbox-check/types.js.map +1 -0
  356. package/packages/hooks/dist/inbox-check/utils.d.ts.map +1 -0
  357. package/packages/hooks/dist/inbox-check/utils.js.map +1 -0
  358. package/packages/hooks/dist/index.d.ts.map +1 -0
  359. package/packages/hooks/dist/index.js.map +1 -0
  360. package/packages/hooks/dist/registry.d.ts.map +1 -0
  361. package/packages/hooks/dist/registry.js.map +1 -0
  362. package/packages/hooks/dist/trajectory-hooks.d.ts.map +1 -0
  363. package/packages/hooks/dist/trajectory-hooks.js.map +1 -0
  364. package/packages/hooks/dist/types.d.ts.map +1 -0
  365. package/packages/hooks/dist/types.js.map +1 -0
  366. package/packages/hooks/package.json +4 -4
  367. package/packages/hooks/src/browser.ts +2 -0
  368. package/packages/hooks/src/emitter.ts +84 -0
  369. package/packages/hooks/src/inbox-check/hook.ts +114 -0
  370. package/packages/hooks/src/inbox-check/index.ts +8 -0
  371. package/packages/hooks/src/inbox-check/types.ts +39 -0
  372. package/packages/hooks/src/inbox-check/utils.test.ts +287 -0
  373. package/packages/hooks/src/inbox-check/utils.ts +125 -0
  374. package/packages/hooks/src/index.ts +11 -0
  375. package/packages/hooks/src/registry.ts +614 -0
  376. package/packages/hooks/src/shims.d.ts +3 -0
  377. package/packages/hooks/src/trajectory-hooks.ts +251 -0
  378. package/packages/hooks/src/types.ts +342 -0
  379. package/packages/hooks/tsconfig.json +21 -0
  380. package/packages/hooks/vitest.config.ts +9 -0
  381. package/packages/mcp/dist/bin.d.ts.map +1 -0
  382. package/packages/mcp/dist/bin.js.map +1 -0
  383. package/packages/mcp/dist/client.d.ts +9 -15
  384. package/packages/mcp/dist/client.d.ts.map +1 -0
  385. package/packages/mcp/dist/client.js +42 -74
  386. package/packages/mcp/dist/client.js.map +1 -0
  387. package/packages/mcp/dist/cloud.d.ts.map +1 -0
  388. package/packages/mcp/dist/cloud.js.map +1 -0
  389. package/packages/mcp/dist/errors.d.ts.map +1 -0
  390. package/packages/mcp/dist/errors.js.map +1 -0
  391. package/packages/mcp/dist/file-transport.d.ts.map +1 -0
  392. package/packages/mcp/dist/file-transport.js.map +1 -0
  393. package/packages/mcp/dist/hybrid-client.d.ts.map +1 -0
  394. package/packages/mcp/dist/hybrid-client.js.map +1 -0
  395. package/packages/mcp/dist/index.d.ts.map +1 -0
  396. package/packages/mcp/dist/index.js.map +1 -0
  397. package/packages/mcp/dist/install-cli.d.ts.map +1 -0
  398. package/packages/mcp/dist/install-cli.js.map +1 -0
  399. package/packages/mcp/dist/install.d.ts.map +1 -0
  400. package/packages/mcp/dist/install.js.map +1 -0
  401. package/packages/mcp/dist/prompts/index.d.ts.map +1 -0
  402. package/packages/mcp/dist/prompts/index.js.map +1 -0
  403. package/packages/mcp/dist/prompts/protocol.d.ts.map +1 -0
  404. package/packages/mcp/dist/prompts/protocol.js.map +1 -0
  405. package/packages/mcp/dist/resources/agents.d.ts.map +1 -0
  406. package/packages/mcp/dist/resources/agents.js.map +1 -0
  407. package/packages/mcp/dist/resources/inbox.d.ts.map +1 -0
  408. package/packages/mcp/dist/resources/inbox.js.map +1 -0
  409. package/packages/mcp/dist/resources/index.d.ts.map +1 -0
  410. package/packages/mcp/dist/resources/index.js.map +1 -0
  411. package/packages/mcp/dist/resources/project.d.ts.map +1 -0
  412. package/packages/mcp/dist/resources/project.js.map +1 -0
  413. package/packages/mcp/dist/server.d.ts.map +1 -0
  414. package/packages/mcp/dist/server.js.map +1 -0
  415. package/packages/mcp/dist/simple.d.ts +2 -5
  416. package/packages/mcp/dist/simple.d.ts.map +1 -0
  417. package/packages/mcp/dist/simple.js.map +1 -0
  418. package/packages/mcp/dist/tools/index.d.ts.map +1 -0
  419. package/packages/mcp/dist/tools/index.js.map +1 -0
  420. package/packages/mcp/dist/tools/relay-broadcast.d.ts.map +1 -0
  421. package/packages/mcp/dist/tools/relay-broadcast.js.map +1 -0
  422. package/packages/mcp/dist/tools/relay-channel.d.ts.map +1 -0
  423. package/packages/mcp/dist/tools/relay-channel.js.map +1 -0
  424. package/packages/mcp/dist/tools/relay-connected.d.ts.map +1 -0
  425. package/packages/mcp/dist/tools/relay-connected.js.map +1 -0
  426. package/packages/mcp/dist/tools/relay-consensus.d.ts.map +1 -0
  427. package/packages/mcp/dist/tools/relay-consensus.js.map +1 -0
  428. package/packages/mcp/dist/tools/relay-continuity.d.ts.map +1 -0
  429. package/packages/mcp/dist/tools/relay-continuity.js.map +1 -0
  430. package/packages/mcp/dist/tools/relay-health.d.ts.map +1 -0
  431. package/packages/mcp/dist/tools/relay-health.js.map +1 -0
  432. package/packages/mcp/dist/tools/relay-inbox.d.ts.map +1 -0
  433. package/packages/mcp/dist/tools/relay-inbox.js.map +1 -0
  434. package/packages/mcp/dist/tools/relay-logs.d.ts.map +1 -0
  435. package/packages/mcp/dist/tools/relay-logs.js.map +1 -0
  436. package/packages/mcp/dist/tools/relay-metrics.d.ts.map +1 -0
  437. package/packages/mcp/dist/tools/relay-metrics.js.map +1 -0
  438. package/packages/mcp/dist/tools/relay-release.d.ts.map +1 -0
  439. package/packages/mcp/dist/tools/relay-release.js.map +1 -0
  440. package/packages/mcp/dist/tools/relay-remove-agent.d.ts.map +1 -0
  441. package/packages/mcp/dist/tools/relay-remove-agent.js.map +1 -0
  442. package/packages/mcp/dist/tools/relay-send.d.ts.map +1 -0
  443. package/packages/mcp/dist/tools/relay-send.js +4 -2
  444. package/packages/mcp/dist/tools/relay-send.js.map +1 -0
  445. package/packages/mcp/dist/tools/relay-shadow.d.ts.map +1 -0
  446. package/packages/mcp/dist/tools/relay-shadow.js.map +1 -0
  447. package/packages/mcp/dist/tools/relay-spawn.d.ts.map +1 -0
  448. package/packages/mcp/dist/tools/relay-spawn.js.map +1 -0
  449. package/packages/mcp/dist/tools/relay-status.d.ts.map +1 -0
  450. package/packages/mcp/dist/tools/relay-status.js.map +1 -0
  451. package/packages/mcp/dist/tools/relay-subscribe.d.ts.map +1 -0
  452. package/packages/mcp/dist/tools/relay-subscribe.js.map +1 -0
  453. package/packages/mcp/dist/tools/relay-who.d.ts.map +1 -0
  454. package/packages/mcp/dist/tools/relay-who.js.map +1 -0
  455. package/packages/mcp/package.json +3 -3
  456. package/packages/mcp/src/bin.ts +149 -0
  457. package/packages/mcp/src/client.ts +400 -0
  458. package/packages/mcp/src/cloud.ts +523 -0
  459. package/packages/mcp/src/errors.ts +54 -0
  460. package/packages/mcp/src/file-transport.ts +268 -0
  461. package/packages/mcp/src/hybrid-client.ts +209 -0
  462. package/packages/mcp/src/index.ts +122 -0
  463. package/packages/mcp/src/install-cli.ts +210 -0
  464. package/packages/mcp/src/install.ts +745 -0
  465. package/packages/mcp/src/prompts/index.ts +1 -0
  466. package/packages/mcp/src/prompts/protocol.ts +164 -0
  467. package/packages/mcp/src/resources/agents.ts +21 -0
  468. package/packages/mcp/src/resources/inbox.ts +21 -0
  469. package/packages/mcp/src/resources/index.ts +3 -0
  470. package/packages/mcp/src/resources/project.ts +29 -0
  471. package/packages/mcp/src/server.ts +431 -0
  472. package/packages/mcp/src/simple.ts +214 -0
  473. package/packages/mcp/src/tools/index.ts +133 -0
  474. package/packages/mcp/src/tools/relay-broadcast.ts +32 -0
  475. package/packages/mcp/src/tools/relay-channel.ts +93 -0
  476. package/packages/mcp/src/tools/relay-connected.ts +52 -0
  477. package/packages/mcp/src/tools/relay-consensus.ts +92 -0
  478. package/packages/mcp/src/tools/relay-continuity.ts +127 -0
  479. package/packages/mcp/src/tools/relay-health.ts +148 -0
  480. package/packages/mcp/src/tools/relay-inbox.ts +70 -0
  481. package/packages/mcp/src/tools/relay-logs.ts +106 -0
  482. package/packages/mcp/src/tools/relay-metrics.ts +140 -0
  483. package/packages/mcp/src/tools/relay-release.ts +54 -0
  484. package/packages/mcp/src/tools/relay-remove-agent.ts +58 -0
  485. package/packages/mcp/src/tools/relay-send.ts +84 -0
  486. package/packages/mcp/src/tools/relay-shadow.ts +67 -0
  487. package/packages/mcp/src/tools/relay-spawn.ts +87 -0
  488. package/packages/mcp/src/tools/relay-status.ts +57 -0
  489. package/packages/mcp/src/tools/relay-subscribe.ts +61 -0
  490. package/packages/mcp/src/tools/relay-who.ts +59 -0
  491. package/packages/mcp/tests/client.test.ts +476 -0
  492. package/packages/mcp/tests/discover.test.ts +195 -0
  493. package/packages/mcp/tests/install.test.ts +123 -0
  494. package/packages/mcp/tests/prompts.test.ts +12 -0
  495. package/packages/mcp/tests/resources.test.ts +53 -0
  496. package/packages/mcp/tests/tools.test.ts +1242 -0
  497. package/packages/mcp/tsconfig.json +22 -0
  498. package/packages/mcp/vitest.config.ts +9 -0
  499. package/packages/memory/dist/adapters/index.d.ts.map +1 -0
  500. package/packages/memory/dist/adapters/index.js.map +1 -0
  501. package/packages/memory/dist/adapters/inmemory.d.ts.map +1 -0
  502. package/packages/memory/dist/adapters/inmemory.js.map +1 -0
  503. package/packages/memory/dist/adapters/supermemory.d.ts.map +1 -0
  504. package/packages/memory/dist/adapters/supermemory.js.map +1 -0
  505. package/packages/memory/dist/context-compaction.d.ts.map +1 -0
  506. package/packages/memory/dist/context-compaction.js.map +1 -0
  507. package/packages/memory/dist/factory.d.ts.map +1 -0
  508. package/packages/memory/dist/factory.js.map +1 -0
  509. package/packages/memory/dist/index.d.ts.map +1 -0
  510. package/packages/memory/dist/index.js.map +1 -0
  511. package/packages/memory/dist/memory-hooks.d.ts.map +1 -0
  512. package/packages/memory/dist/memory-hooks.js.map +1 -0
  513. package/packages/memory/dist/service.d.ts.map +1 -0
  514. package/packages/memory/dist/service.js.map +1 -0
  515. package/packages/memory/dist/types.d.ts.map +1 -0
  516. package/packages/memory/dist/types.js.map +1 -0
  517. package/packages/memory/package.json +2 -2
  518. package/packages/memory/src/adapters/index.ts +8 -0
  519. package/packages/memory/src/adapters/inmemory.ts +265 -0
  520. package/packages/memory/src/adapters/supermemory.ts +449 -0
  521. package/packages/memory/src/context-compaction.test.ts +660 -0
  522. package/packages/memory/src/context-compaction.ts +612 -0
  523. package/packages/memory/src/factory.ts +170 -0
  524. package/packages/memory/src/index.ts +33 -0
  525. package/packages/memory/src/memory-hooks.ts +410 -0
  526. package/packages/memory/src/service.ts +194 -0
  527. package/packages/memory/src/types.ts +211 -0
  528. package/packages/memory/tsconfig.json +21 -0
  529. package/packages/memory/vitest.config.ts +9 -0
  530. package/packages/policy/dist/agent-policy.d.ts.map +1 -0
  531. package/packages/policy/dist/agent-policy.js.map +1 -0
  532. package/packages/policy/dist/cloud-policy-fetcher.d.ts.map +1 -0
  533. package/packages/policy/dist/cloud-policy-fetcher.js.map +1 -0
  534. package/packages/policy/dist/index.d.ts.map +1 -0
  535. package/packages/policy/dist/index.js.map +1 -0
  536. package/packages/policy/package.json +2 -2
  537. package/packages/policy/src/agent-policy.ts +866 -0
  538. package/packages/policy/src/cloud-policy-fetcher.ts +78 -0
  539. package/packages/policy/src/index.ts +21 -0
  540. package/packages/policy/tsconfig.json +21 -0
  541. package/packages/policy/vitest.config.ts +9 -0
  542. package/packages/protocol/dist/channels.d.ts.map +1 -0
  543. package/packages/protocol/dist/channels.js.map +1 -0
  544. package/packages/protocol/dist/framing.d.ts.map +1 -0
  545. package/packages/protocol/dist/framing.js.map +1 -0
  546. package/packages/protocol/dist/id-generator.d.ts.map +1 -0
  547. package/packages/protocol/dist/id-generator.js.map +1 -0
  548. package/packages/protocol/dist/index.d.ts.map +1 -0
  549. package/packages/protocol/dist/index.js.map +1 -0
  550. package/packages/protocol/dist/relay-pty-schemas.d.ts +70 -2
  551. package/packages/protocol/dist/relay-pty-schemas.d.ts.map +1 -0
  552. package/packages/protocol/dist/relay-pty-schemas.js.map +1 -0
  553. package/packages/protocol/dist/types.d.ts +8 -0
  554. package/packages/protocol/dist/types.d.ts.map +1 -0
  555. package/packages/protocol/dist/types.js.map +1 -0
  556. package/packages/protocol/package.json +1 -1
  557. package/packages/protocol/src/channels.test.ts +330 -0
  558. package/packages/protocol/src/channels.ts +270 -0
  559. package/packages/protocol/src/framing.test.ts +164 -0
  560. package/packages/protocol/src/framing.ts +242 -0
  561. package/packages/protocol/src/id-generator.ts +69 -0
  562. package/packages/protocol/src/index.ts +4 -0
  563. package/packages/protocol/src/relay-pty-schemas.ts +400 -0
  564. package/packages/protocol/src/types.test.ts +271 -0
  565. package/packages/protocol/src/types.ts +846 -0
  566. package/packages/protocol/tsconfig.json +21 -0
  567. package/packages/protocol/vitest.config.ts +9 -0
  568. package/packages/resiliency/dist/cgroup-manager.d.ts.map +1 -0
  569. package/packages/resiliency/dist/cgroup-manager.js.map +1 -0
  570. package/packages/resiliency/dist/context-persistence.d.ts.map +1 -0
  571. package/packages/resiliency/dist/context-persistence.js.map +1 -0
  572. package/packages/resiliency/dist/crash-insights.d.ts.map +1 -0
  573. package/packages/resiliency/dist/crash-insights.js.map +1 -0
  574. package/packages/resiliency/dist/gossip-health.d.ts.map +1 -0
  575. package/packages/resiliency/dist/gossip-health.js.map +1 -0
  576. package/packages/resiliency/dist/health-monitor.d.ts.map +1 -0
  577. package/packages/resiliency/dist/health-monitor.js.map +1 -0
  578. package/packages/resiliency/dist/index.d.ts.map +1 -0
  579. package/packages/resiliency/dist/index.js.map +1 -0
  580. package/packages/resiliency/dist/leader-watchdog.d.ts.map +1 -0
  581. package/packages/resiliency/dist/leader-watchdog.js.map +1 -0
  582. package/packages/resiliency/dist/logger.d.ts.map +1 -0
  583. package/packages/resiliency/dist/logger.js.map +1 -0
  584. package/packages/resiliency/dist/memory-monitor.d.ts.map +1 -0
  585. package/packages/resiliency/dist/memory-monitor.js.map +1 -0
  586. package/packages/resiliency/dist/metrics.d.ts.map +1 -0
  587. package/packages/resiliency/dist/metrics.js.map +1 -0
  588. package/packages/resiliency/dist/provider-context.d.ts.map +1 -0
  589. package/packages/resiliency/dist/provider-context.js.map +1 -0
  590. package/packages/resiliency/dist/stateless-lead.d.ts.map +1 -0
  591. package/packages/resiliency/dist/stateless-lead.js.map +1 -0
  592. package/packages/resiliency/dist/supervisor.d.ts.map +1 -0
  593. package/packages/resiliency/dist/supervisor.js.map +1 -0
  594. package/packages/resiliency/package.json +1 -1
  595. package/packages/resiliency/src/cgroup-manager.ts +468 -0
  596. package/packages/resiliency/src/context-persistence.ts +538 -0
  597. package/packages/resiliency/src/crash-insights.test.ts +620 -0
  598. package/packages/resiliency/src/crash-insights.ts +660 -0
  599. package/packages/resiliency/src/gossip-health.ts +333 -0
  600. package/packages/resiliency/src/health-monitor.ts +371 -0
  601. package/packages/resiliency/src/index.ts +157 -0
  602. package/packages/resiliency/src/leader-watchdog.ts +260 -0
  603. package/packages/resiliency/src/logger.ts +320 -0
  604. package/packages/resiliency/src/memory-monitor.test.ts +637 -0
  605. package/packages/resiliency/src/memory-monitor.ts +740 -0
  606. package/packages/resiliency/src/metrics.ts +311 -0
  607. package/packages/resiliency/src/provider-context.ts +452 -0
  608. package/packages/resiliency/src/stateless-lead.ts +408 -0
  609. package/packages/resiliency/src/supervisor.ts +578 -0
  610. package/packages/resiliency/tsconfig.json +21 -0
  611. package/packages/resiliency/vitest.config.ts +9 -0
  612. package/packages/sdk/dist/client.d.ts.map +1 -0
  613. package/packages/sdk/dist/client.js.map +1 -0
  614. package/packages/sdk/dist/index.d.ts.map +1 -0
  615. package/packages/sdk/dist/index.js.map +1 -0
  616. package/packages/sdk/dist/logs.d.ts.map +1 -0
  617. package/packages/sdk/dist/logs.js.map +1 -0
  618. package/packages/sdk/dist/protocol/index.d.ts.map +1 -0
  619. package/packages/sdk/dist/protocol/index.js.map +1 -0
  620. package/packages/sdk/dist/standalone.d.ts.map +1 -0
  621. package/packages/sdk/dist/standalone.js.map +1 -0
  622. package/packages/sdk/examples/SWARM_CAPABILITIES.md +498 -0
  623. package/packages/sdk/examples/SWARM_PATTERNS.md +541 -0
  624. package/packages/sdk/package.json +2 -2
  625. package/packages/sdk/src/client.test.ts +568 -0
  626. package/packages/sdk/src/client.ts +1418 -0
  627. package/packages/sdk/src/index.ts +103 -0
  628. package/packages/sdk/src/logs.test.ts +98 -0
  629. package/packages/sdk/src/logs.ts +126 -0
  630. package/packages/sdk/src/protocol/framing.test.ts +164 -0
  631. package/packages/sdk/src/protocol/index.ts +8 -0
  632. package/packages/sdk/src/standalone.ts +176 -0
  633. package/packages/sdk/tsconfig.json +22 -0
  634. package/packages/sdk/vitest.config.ts +9 -0
  635. package/packages/spawner/.trajectories/index.json +5 -0
  636. package/packages/spawner/dist/index.d.ts.map +1 -0
  637. package/packages/spawner/dist/index.js.map +1 -0
  638. package/packages/spawner/dist/types.d.ts.map +1 -0
  639. package/packages/spawner/dist/types.js.map +1 -0
  640. package/packages/spawner/package.json +1 -1
  641. package/packages/spawner/src/index.ts +8 -0
  642. package/packages/spawner/src/types.test.ts +385 -0
  643. package/packages/spawner/src/types.ts +228 -0
  644. package/packages/spawner/tsconfig.json +19 -0
  645. package/packages/spawner/vitest.config.ts +9 -0
  646. package/packages/state/dist/agent-state.d.ts.map +1 -0
  647. package/packages/state/dist/agent-state.js.map +1 -0
  648. package/packages/state/dist/index.d.ts.map +1 -0
  649. package/packages/state/dist/index.js.map +1 -0
  650. package/packages/state/package.json +1 -1
  651. package/packages/state/src/agent-state.test.ts +335 -0
  652. package/packages/state/src/agent-state.ts +153 -0
  653. package/packages/state/src/index.ts +12 -0
  654. package/packages/state/tsconfig.json +21 -0
  655. package/packages/state/vitest.config.ts +9 -0
  656. package/packages/storage/dist/adapter.d.ts +28 -1
  657. package/packages/storage/dist/adapter.d.ts.map +1 -0
  658. package/packages/storage/dist/adapter.js +104 -10
  659. package/packages/storage/dist/adapter.js.map +1 -0
  660. package/packages/storage/dist/batched-sqlite-adapter.d.ts.map +1 -0
  661. package/packages/storage/dist/batched-sqlite-adapter.js.map +1 -0
  662. package/packages/storage/dist/dead-letter-queue.d.ts.map +1 -0
  663. package/packages/storage/dist/dead-letter-queue.js.map +1 -0
  664. package/packages/storage/dist/dlq-adapter.d.ts.map +1 -0
  665. package/packages/storage/dist/dlq-adapter.js.map +1 -0
  666. package/packages/storage/dist/index.d.ts +1 -0
  667. package/packages/storage/dist/index.d.ts.map +1 -0
  668. package/packages/storage/dist/index.js +1 -0
  669. package/packages/storage/dist/index.js.map +1 -0
  670. package/packages/storage/dist/jsonl-adapter.d.ts +77 -0
  671. package/packages/storage/dist/jsonl-adapter.d.ts.map +1 -0
  672. package/packages/storage/dist/jsonl-adapter.js +505 -0
  673. package/packages/storage/dist/jsonl-adapter.js.map +1 -0
  674. package/packages/storage/dist/sqlite-adapter.d.ts +6 -1
  675. package/packages/storage/dist/sqlite-adapter.d.ts.map +1 -0
  676. package/packages/storage/dist/sqlite-adapter.js +47 -0
  677. package/packages/storage/dist/sqlite-adapter.js.map +1 -0
  678. package/packages/storage/package.json +2 -2
  679. package/packages/storage/src/adapter.ts +438 -0
  680. package/packages/storage/src/batched-sqlite-adapter.test.ts +240 -0
  681. package/packages/storage/src/batched-sqlite-adapter.ts +239 -0
  682. package/packages/storage/src/dead-letter-queue.ts +643 -0
  683. package/packages/storage/src/dlq-adapter.test.ts +492 -0
  684. package/packages/storage/src/dlq-adapter.ts +954 -0
  685. package/packages/storage/src/index.ts +6 -0
  686. package/packages/storage/src/jsonl-adapter.test.ts +200 -0
  687. package/packages/storage/src/jsonl-adapter.ts +618 -0
  688. package/packages/storage/src/memory-adapter.test.ts +36 -0
  689. package/packages/storage/src/sqlite-adapter.test.ts +562 -0
  690. package/packages/storage/src/sqlite-adapter.ts +1058 -0
  691. package/packages/storage/tsconfig.json +21 -0
  692. package/packages/storage/vitest.config.ts +9 -0
  693. package/packages/telemetry/dist/client.d.ts.map +1 -0
  694. package/packages/telemetry/dist/client.js.map +1 -0
  695. package/packages/telemetry/dist/config.d.ts.map +1 -0
  696. package/packages/telemetry/dist/config.js.map +1 -0
  697. package/packages/telemetry/dist/events.d.ts.map +1 -0
  698. package/packages/telemetry/dist/events.js.map +1 -0
  699. package/packages/telemetry/dist/index.d.ts.map +1 -0
  700. package/packages/telemetry/dist/index.js.map +1 -0
  701. package/packages/telemetry/dist/machine-id.d.ts.map +1 -0
  702. package/packages/telemetry/dist/machine-id.js.map +1 -0
  703. package/packages/telemetry/dist/posthog-config.d.ts.map +1 -0
  704. package/packages/telemetry/dist/posthog-config.js.map +1 -0
  705. package/packages/telemetry/package.json +1 -1
  706. package/packages/telemetry/src/client.ts +158 -0
  707. package/packages/telemetry/src/config.ts +110 -0
  708. package/packages/telemetry/src/events.ts +137 -0
  709. package/packages/telemetry/src/index.ts +46 -0
  710. package/packages/telemetry/src/machine-id.ts +63 -0
  711. package/packages/telemetry/src/posthog-config.ts +39 -0
  712. package/packages/telemetry/tsconfig.json +21 -0
  713. package/packages/trajectory/dist/index.d.ts.map +1 -0
  714. package/packages/trajectory/dist/index.js.map +1 -0
  715. package/packages/trajectory/dist/integration.d.ts.map +1 -0
  716. package/packages/trajectory/dist/integration.js.map +1 -0
  717. package/packages/trajectory/package.json +2 -2
  718. package/packages/trajectory/src/index.ts +1 -0
  719. package/packages/trajectory/src/integration.ts +1268 -0
  720. package/packages/trajectory/tsconfig.json +21 -0
  721. package/packages/trajectory/vitest.config.ts +9 -0
  722. package/packages/user-directory/dist/index.d.ts.map +1 -0
  723. package/packages/user-directory/dist/index.js.map +1 -0
  724. package/packages/user-directory/dist/user-directory.d.ts.map +1 -0
  725. package/packages/user-directory/dist/user-directory.js.map +1 -0
  726. package/packages/user-directory/package.json +2 -2
  727. package/packages/user-directory/src/index.ts +12 -0
  728. package/packages/user-directory/src/user-directory.ts +393 -0
  729. package/packages/user-directory/tsconfig.json +21 -0
  730. package/packages/user-directory/vitest.config.ts +9 -0
  731. package/packages/utils/dist/cjs/client-helpers.js +127 -0
  732. package/packages/utils/dist/cjs/command-resolver.js +89 -0
  733. package/packages/utils/dist/cjs/error-tracking.js +106 -0
  734. package/packages/utils/dist/cjs/git-remote.js +120 -0
  735. package/packages/utils/dist/cjs/index.js +40 -0
  736. package/packages/utils/dist/cjs/logger.js +105 -0
  737. package/packages/utils/dist/cjs/model-mapping.js +54 -0
  738. package/packages/utils/dist/cjs/name-generator.js +179 -0
  739. package/packages/utils/dist/cjs/package.json +3 -0
  740. package/packages/utils/dist/cjs/precompiled-patterns.js +271 -0
  741. package/packages/utils/dist/cjs/relay-pty-path.js +143 -0
  742. package/packages/utils/dist/cjs/update-checker.js +185 -0
  743. package/packages/utils/dist/client-helpers.d.ts +73 -0
  744. package/packages/utils/dist/client-helpers.d.ts.map +1 -0
  745. package/packages/utils/dist/client-helpers.js +130 -0
  746. package/packages/utils/dist/client-helpers.js.map +1 -0
  747. package/packages/utils/dist/command-resolver.d.ts.map +1 -0
  748. package/packages/utils/dist/command-resolver.js.map +1 -0
  749. package/packages/utils/dist/error-tracking.d.ts.map +1 -0
  750. package/packages/utils/dist/error-tracking.js.map +1 -0
  751. package/packages/utils/dist/git-remote.d.ts.map +1 -0
  752. package/packages/utils/dist/git-remote.js.map +1 -0
  753. package/packages/utils/dist/index.d.ts +1 -0
  754. package/packages/utils/dist/index.d.ts.map +1 -0
  755. package/packages/utils/dist/index.js +1 -0
  756. package/packages/utils/dist/index.js.map +1 -0
  757. package/packages/utils/dist/logger.d.ts.map +1 -0
  758. package/packages/utils/dist/logger.js.map +1 -0
  759. package/packages/utils/dist/model-mapping.d.ts.map +1 -0
  760. package/packages/utils/dist/model-mapping.js.map +1 -0
  761. package/packages/utils/dist/name-generator.d.ts.map +1 -0
  762. package/packages/utils/dist/name-generator.js.map +1 -0
  763. package/packages/utils/dist/precompiled-patterns.d.ts.map +1 -0
  764. package/packages/utils/dist/precompiled-patterns.js.map +1 -0
  765. package/packages/utils/dist/relay-pty-path.d.ts +11 -5
  766. package/packages/utils/dist/relay-pty-path.d.ts.map +1 -0
  767. package/packages/utils/dist/relay-pty-path.js +60 -5
  768. package/packages/utils/dist/relay-pty-path.js.map +1 -0
  769. package/packages/utils/dist/update-checker.d.ts.map +1 -0
  770. package/packages/utils/dist/update-checker.js.map +1 -0
  771. package/packages/utils/package.json +37 -14
  772. package/packages/utils/scripts/build-cjs.mjs +24 -0
  773. package/packages/utils/src/client-helpers.ts +221 -0
  774. package/packages/utils/src/command-resolver.ts +82 -0
  775. package/packages/utils/src/error-tracking.ts +189 -0
  776. package/packages/utils/src/git-remote.ts +143 -0
  777. package/packages/utils/src/index.ts +10 -0
  778. package/packages/utils/src/logger.ts +107 -0
  779. package/packages/utils/src/model-mapping.test.ts +122 -0
  780. package/packages/utils/src/model-mapping.ts +58 -0
  781. package/packages/utils/src/name-generator.test.ts +259 -0
  782. package/packages/utils/src/name-generator.ts +56 -0
  783. package/packages/utils/src/precompiled-patterns.test.ts +452 -0
  784. package/packages/utils/src/precompiled-patterns.ts +395 -0
  785. package/packages/utils/src/relay-pty-path.ts +196 -0
  786. package/packages/utils/src/update-checker.test.ts +260 -0
  787. package/packages/utils/src/update-checker.ts +211 -0
  788. package/packages/utils/tsconfig.json +21 -0
  789. package/packages/utils/vitest.config.ts +9 -0
  790. package/packages/wrapper/dist/__fixtures__/claude-outputs.d.ts.map +1 -0
  791. package/packages/wrapper/dist/__fixtures__/claude-outputs.js.map +1 -0
  792. package/packages/wrapper/dist/__fixtures__/codex-outputs.d.ts.map +1 -0
  793. package/packages/wrapper/dist/__fixtures__/codex-outputs.js.map +1 -0
  794. package/packages/wrapper/dist/__fixtures__/gemini-outputs.d.ts.map +1 -0
  795. package/packages/wrapper/dist/__fixtures__/gemini-outputs.js.map +1 -0
  796. package/packages/wrapper/dist/__fixtures__/index.d.ts.map +1 -0
  797. package/packages/wrapper/dist/__fixtures__/index.js.map +1 -0
  798. package/packages/wrapper/dist/auth-detection.d.ts.map +1 -0
  799. package/packages/wrapper/dist/auth-detection.js.map +1 -0
  800. package/packages/wrapper/dist/base-wrapper.d.ts.map +1 -0
  801. package/packages/wrapper/dist/base-wrapper.js.map +1 -0
  802. package/packages/wrapper/dist/client.d.ts.map +1 -0
  803. package/packages/wrapper/dist/client.js.map +1 -0
  804. package/packages/wrapper/dist/id-generator.d.ts.map +1 -0
  805. package/packages/wrapper/dist/id-generator.js.map +1 -0
  806. package/packages/wrapper/dist/idle-detector.d.ts.map +1 -0
  807. package/packages/wrapper/dist/idle-detector.js.map +1 -0
  808. package/packages/wrapper/dist/inbox.d.ts.map +1 -0
  809. package/packages/wrapper/dist/inbox.js.map +1 -0
  810. package/packages/wrapper/dist/index.d.ts.map +1 -0
  811. package/packages/wrapper/dist/index.js.map +1 -0
  812. package/packages/wrapper/dist/parser.d.ts.map +1 -0
  813. package/packages/wrapper/dist/parser.js.map +1 -0
  814. package/packages/wrapper/dist/prompt-composer.d.ts.map +1 -0
  815. package/packages/wrapper/dist/prompt-composer.js.map +1 -0
  816. package/packages/wrapper/dist/relay-pty-orchestrator.d.ts +10 -0
  817. package/packages/wrapper/dist/relay-pty-orchestrator.d.ts.map +1 -0
  818. package/packages/wrapper/dist/relay-pty-orchestrator.js +69 -0
  819. package/packages/wrapper/dist/relay-pty-orchestrator.js.map +1 -0
  820. package/packages/wrapper/dist/shared.d.ts.map +1 -0
  821. package/packages/wrapper/dist/shared.js.map +1 -0
  822. package/packages/wrapper/dist/stuck-detector.d.ts.map +1 -0
  823. package/packages/wrapper/dist/stuck-detector.js.map +1 -0
  824. package/packages/wrapper/dist/tmux-resolver.d.ts.map +1 -0
  825. package/packages/wrapper/dist/tmux-resolver.js.map +1 -0
  826. package/packages/wrapper/dist/tmux-wrapper.d.ts.map +1 -0
  827. package/packages/wrapper/dist/tmux-wrapper.js.map +1 -0
  828. package/packages/wrapper/dist/trajectory-integration.d.ts.map +1 -0
  829. package/packages/wrapper/dist/trajectory-integration.js.map +1 -0
  830. package/packages/wrapper/dist/wrapper-types.d.ts.map +1 -0
  831. package/packages/wrapper/dist/wrapper-types.js.map +1 -0
  832. package/packages/wrapper/package.json +6 -9
  833. package/packages/wrapper/src/__fixtures__/claude-outputs.ts +471 -0
  834. package/packages/wrapper/src/__fixtures__/codex-outputs.ts +99 -0
  835. package/packages/wrapper/src/__fixtures__/gemini-outputs.ts +151 -0
  836. package/packages/wrapper/src/__fixtures__/index.ts +47 -0
  837. package/packages/wrapper/src/auth-detection.ts +244 -0
  838. package/packages/wrapper/src/base-wrapper.test.ts +589 -0
  839. package/packages/wrapper/src/base-wrapper.ts +810 -0
  840. package/packages/wrapper/src/client.test.ts +262 -0
  841. package/packages/wrapper/src/client.ts +984 -0
  842. package/packages/wrapper/src/id-generator.test.ts +71 -0
  843. package/packages/wrapper/src/id-generator.ts +69 -0
  844. package/packages/wrapper/src/idle-detector.test.ts +418 -0
  845. package/packages/wrapper/src/idle-detector.ts +384 -0
  846. package/packages/wrapper/src/inbox.test.ts +233 -0
  847. package/packages/wrapper/src/inbox.ts +89 -0
  848. package/packages/wrapper/src/index.ts +170 -0
  849. package/packages/wrapper/src/parser.regression.test.ts +251 -0
  850. package/packages/wrapper/src/parser.test.ts +1359 -0
  851. package/packages/wrapper/src/parser.ts +1477 -0
  852. package/packages/wrapper/src/prompt-composer.test.ts +219 -0
  853. package/packages/wrapper/src/prompt-composer.ts +231 -0
  854. package/packages/wrapper/src/relay-pty-orchestrator.test.ts +1204 -0
  855. package/packages/wrapper/src/relay-pty-orchestrator.ts +2626 -0
  856. package/packages/wrapper/src/shared.test.ts +322 -0
  857. package/packages/wrapper/src/shared.ts +495 -0
  858. package/packages/wrapper/src/stuck-detector.test.ts +303 -0
  859. package/packages/wrapper/src/stuck-detector.ts +511 -0
  860. package/packages/wrapper/src/tmux-resolver.test.ts +104 -0
  861. package/packages/wrapper/src/tmux-resolver.ts +207 -0
  862. package/packages/wrapper/src/tmux-wrapper.test.ts +316 -0
  863. package/packages/wrapper/src/tmux-wrapper.ts +2095 -0
  864. package/packages/wrapper/src/trajectory-detection.test.ts +151 -0
  865. package/packages/wrapper/src/trajectory-integration.ts +1261 -0
  866. package/packages/wrapper/src/wrapper-types.ts +45 -0
  867. package/packages/wrapper/tsconfig.json +19 -0
  868. package/packages/wrapper/vitest.config.ts +9 -0
  869. package/scripts/build-cjs.mjs +23 -0
  870. package/scripts/postinstall.js +132 -0
  871. package/.cursor/mcp.json +0 -11
  872. package/.gitattributes +0 -3
  873. package/.gitleaks.toml +0 -26
  874. package/.mcp.json +0 -11
  875. package/.nvmrc +0 -1
  876. package/ARCHITECTURE.md +0 -1245
  877. package/CHANGELOG.md +0 -231
  878. package/TESTING.md +0 -278
  879. package/TRAIL_GIT_AUTH_FIX.md +0 -113
  880. package/scripts/demos/README.md +0 -79
  881. package/scripts/demos/server-capacity.sh +0 -69
  882. package/scripts/demos/sprint-planning.sh +0 -73
  883. package/scripts/hooks/install.sh +0 -16
  884. package/scripts/hooks/pre-commit +0 -60
  885. package/scripts/post-publish-verify/README.md +0 -80
  886. package/scripts/post-publish-verify/run-verify.sh +0 -127
  887. package/scripts/post-publish-verify/verify-install.sh +0 -249
  888. package/scripts/stress-test-orchestrator-integration.mts +0 -1366
  889. package/scripts/stress-test-orchestrator.mjs +0 -584
  890. package/scripts/stress-test-relay-pty.sh +0 -452
  891. package/scripts/test-interactive-terminal.sh +0 -248
  892. package/specs/PRIMITIVES_ROADMAP.md +0 -2154
  893. package/tests/benchmarks/protocol.bench.ts +0 -310
  894. package/turbo.json +0 -37
@@ -0,0 +1,1268 @@
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
+
17
+ import { spawn, execSync } from 'node:child_process';
18
+ import { readFileSync, existsSync, readdirSync } from 'node:fs';
19
+ import { join } from 'node:path';
20
+ import { getProjectPaths } from '@agent-relay/config/project-namespace';
21
+ import {
22
+ getPrimaryTrajectoriesDir,
23
+ getAllTrajectoriesDirs,
24
+ getTrajectoryEnvVars,
25
+ } from '@agent-relay/config/trajectory-config';
26
+
27
+ /**
28
+ * Trajectory index file structure
29
+ */
30
+ interface TrajectoryIndexEntry {
31
+ title: string;
32
+ status: 'active' | 'completed' | 'abandoned';
33
+ startedAt: string;
34
+ completedAt?: string;
35
+ path: string;
36
+ }
37
+
38
+ interface TrajectoryIndex {
39
+ version: number;
40
+ lastUpdated: string;
41
+ trajectories: Record<string, TrajectoryIndexEntry>;
42
+ }
43
+
44
+ /**
45
+ * Full trajectory file structure
46
+ */
47
+ interface TrajectoryFile {
48
+ id: string;
49
+ version: number;
50
+ task: {
51
+ title: string;
52
+ source?: { system: string; id: string };
53
+ };
54
+ status: 'active' | 'completed' | 'abandoned';
55
+ startedAt: string;
56
+ completedAt?: string;
57
+ agents: Array<{ name: string; role: string; joinedAt: string }>;
58
+ chapters: Array<{
59
+ id: string;
60
+ title: string;
61
+ agentName: string;
62
+ startedAt: string;
63
+ endedAt?: string;
64
+ events: Array<{
65
+ ts: number;
66
+ type: string;
67
+ content: string;
68
+ raw?: Record<string, unknown>;
69
+ significance?: string;
70
+ }>;
71
+ }>;
72
+ retrospective?: {
73
+ summary: string;
74
+ approach: string;
75
+ confidence: number;
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Read a single trajectory index file from a directory
81
+ */
82
+ function resolveIndexEntryPath(trajectoriesDir: string, entryPath: string): string {
83
+ if (!entryPath) {
84
+ return entryPath;
85
+ }
86
+
87
+ if (existsSync(entryPath)) {
88
+ return entryPath;
89
+ }
90
+
91
+ const normalized = entryPath.replace(/\\/g, '/');
92
+ const marker = '/.trajectories/';
93
+ const markerIndex = normalized.indexOf(marker);
94
+
95
+ if (markerIndex >= 0) {
96
+ const relative = normalized.slice(markerIndex + marker.length);
97
+ const candidate = join(trajectoriesDir, relative);
98
+ if (existsSync(candidate)) {
99
+ return candidate;
100
+ }
101
+ }
102
+
103
+ const subdirMatch = normalized.match(/\/(active|completed)\/.+$/);
104
+ if (subdirMatch) {
105
+ const relative = subdirMatch[0].slice(1);
106
+ const candidate = join(trajectoriesDir, relative);
107
+ if (existsSync(candidate)) {
108
+ return candidate;
109
+ }
110
+ }
111
+
112
+ return entryPath;
113
+ }
114
+
115
+ function readSingleTrajectoryIndex(trajectoriesDir: string): TrajectoryIndex | null {
116
+ try {
117
+ const indexPath = join(trajectoriesDir, 'index.json');
118
+ if (!existsSync(indexPath)) {
119
+ return null;
120
+ }
121
+ const content = readFileSync(indexPath, 'utf-8');
122
+ const index = JSON.parse(content) as TrajectoryIndex;
123
+ const trajectories = index.trajectories ?? {};
124
+
125
+ for (const [id, entry] of Object.entries(trajectories)) {
126
+ trajectories[id] = {
127
+ ...entry,
128
+ path: resolveIndexEntryPath(trajectoriesDir, entry.path),
129
+ };
130
+ }
131
+
132
+ return { ...index, trajectories };
133
+ } catch {
134
+ return null;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Read and merge trajectory indexes from all locations (repo + user-level)
140
+ * This allows reading trajectories from both places
141
+ */
142
+ function readTrajectoryIndex(): TrajectoryIndex | null {
143
+ const dirs = getAllTrajectoriesDirs();
144
+
145
+ if (dirs.length === 0) {
146
+ return null;
147
+ }
148
+
149
+ // Read and merge all indexes
150
+ let mergedIndex: TrajectoryIndex | null = null;
151
+
152
+ for (const dir of dirs) {
153
+ const index = readSingleTrajectoryIndex(dir);
154
+ if (!index) continue;
155
+
156
+ if (!mergedIndex) {
157
+ mergedIndex = index;
158
+ } else {
159
+ // Merge trajectories, preferring more recent entries
160
+ for (const [id, entry] of Object.entries(index.trajectories)) {
161
+ const existing = mergedIndex.trajectories[id];
162
+ if (!existing) {
163
+ mergedIndex.trajectories[id] = entry;
164
+ } else {
165
+ // Keep the more recently updated one
166
+ const existingTime = new Date(existing.completedAt || existing.startedAt).getTime();
167
+ const newTime = new Date(entry.completedAt || entry.startedAt).getTime();
168
+ if (newTime > existingTime) {
169
+ mergedIndex.trajectories[id] = entry;
170
+ }
171
+ }
172
+ }
173
+ // Update lastUpdated to most recent
174
+ if (new Date(index.lastUpdated) > new Date(mergedIndex.lastUpdated)) {
175
+ mergedIndex.lastUpdated = index.lastUpdated;
176
+ }
177
+ }
178
+ }
179
+
180
+ return mergedIndex;
181
+ }
182
+
183
+ /**
184
+ * Read a specific trajectory file directly from filesystem
185
+ */
186
+ function readTrajectoryFile(trajectoryPath: string): TrajectoryFile | null {
187
+ try {
188
+ if (!existsSync(trajectoryPath)) {
189
+ return null;
190
+ }
191
+ const content = readFileSync(trajectoryPath, 'utf-8');
192
+ return JSON.parse(content) as TrajectoryFile;
193
+ } catch {
194
+ return null;
195
+ }
196
+ }
197
+
198
+ function getCurrentPhaseFromTrajectory(trajectory: TrajectoryFile | null): PDEROPhase | undefined {
199
+ if (!trajectory?.chapters?.length) {
200
+ return undefined;
201
+ }
202
+
203
+ const lastChapter = trajectory.chapters[trajectory.chapters.length - 1];
204
+ for (const event of [...(lastChapter.events || [])].reverse()) {
205
+ if (event.type === 'phase_transition' || event.type === 'phase') {
206
+ const phaseMatch = event.content?.match(/phase[:\s]+(\w+)/i);
207
+ if (phaseMatch) {
208
+ return phaseMatch[1].toLowerCase() as PDEROPhase;
209
+ }
210
+ }
211
+ }
212
+
213
+ return undefined;
214
+ }
215
+
216
+ function listActiveTrajectoryFiles(trajectoriesDir: string): string[] {
217
+ const activeDir = join(trajectoriesDir, 'active');
218
+ if (!existsSync(activeDir)) {
219
+ return [];
220
+ }
221
+
222
+ return readdirSync(activeDir, { withFileTypes: true })
223
+ .filter(entry => entry.isFile() && entry.name.endsWith('.json'))
224
+ .map(entry => join(activeDir, entry.name));
225
+ }
226
+
227
+ function findActiveTrajectoryPathById(trajectoryDirs: string[], trajectoryId: string): string | null {
228
+ for (const dir of trajectoryDirs) {
229
+ const candidate = join(dir, 'active', `${trajectoryId}.json`);
230
+ if (existsSync(candidate)) {
231
+ return candidate;
232
+ }
233
+ }
234
+
235
+ return null;
236
+ }
237
+
238
+ /**
239
+ * PDERO phases for agent work lifecycle
240
+ */
241
+ export type PDEROPhase = 'plan' | 'design' | 'execute' | 'review' | 'observe';
242
+
243
+ /**
244
+ * Options for starting a trajectory
245
+ */
246
+ export interface StartTrajectoryOptions {
247
+ task: string;
248
+ taskId?: string;
249
+ source?: string;
250
+ agentName: string;
251
+ phase?: PDEROPhase;
252
+ }
253
+
254
+ /**
255
+ * Options for completing a trajectory
256
+ */
257
+ export interface CompleteTrajectoryOptions {
258
+ summary?: string;
259
+ confidence?: number;
260
+ challenges?: string[];
261
+ learnings?: string[];
262
+ }
263
+
264
+ /**
265
+ * Options for recording a decision
266
+ */
267
+ export interface DecisionOptions {
268
+ choice: string;
269
+ question?: string;
270
+ alternatives?: string[];
271
+ reasoning?: string;
272
+ confidence?: number;
273
+ }
274
+
275
+ /**
276
+ * Run a trail CLI command
277
+ * Uses config-based environment to control trajectory storage location
278
+ */
279
+ async function runTrail(args: string[]): Promise<{ success: boolean; output: string; error?: string }> {
280
+ return new Promise((resolve) => {
281
+ // Get trajectory env vars to set correct storage location
282
+ const trajectoryEnv = getTrajectoryEnvVars();
283
+
284
+ const proc = spawn('trail', args, {
285
+ cwd: getProjectPaths().projectRoot,
286
+ env: { ...process.env, ...trajectoryEnv },
287
+ stdio: ['pipe', 'pipe', 'pipe'],
288
+ });
289
+
290
+ let stdout = '';
291
+ let stderr = '';
292
+
293
+ proc.stdout?.on('data', (data) => {
294
+ stdout += data.toString();
295
+ });
296
+
297
+ proc.stderr?.on('data', (data) => {
298
+ stderr += data.toString();
299
+ });
300
+
301
+ proc.on('error', (err) => {
302
+ resolve({ success: false, output: '', error: `Failed to run trail: ${err.message}` });
303
+ });
304
+
305
+ proc.on('close', (code) => {
306
+ if (code === 0) {
307
+ resolve({ success: true, output: stdout.trim() });
308
+ } else {
309
+ resolve({ success: false, output: stdout.trim(), error: stderr.trim() || `Exit code: ${code}` });
310
+ }
311
+ });
312
+ });
313
+ }
314
+
315
+ /**
316
+ * Check if trail CLI is available
317
+ */
318
+ export async function isTrailAvailable(): Promise<boolean> {
319
+ const result = await runTrail(['--version']);
320
+ return result.success;
321
+ }
322
+
323
+ /**
324
+ * Start a new trajectory
325
+ */
326
+ export async function startTrajectory(options: StartTrajectoryOptions): Promise<{ success: boolean; trajectoryId?: string; error?: string }> {
327
+ const args = ['start', options.task];
328
+
329
+ if (options.taskId) {
330
+ args.push('--task-id', options.taskId);
331
+ }
332
+ if (options.source) {
333
+ args.push('--source', options.source);
334
+ }
335
+ if (options.agentName) {
336
+ args.push('--agent', options.agentName);
337
+ }
338
+ if (options.phase) {
339
+ args.push('--phase', options.phase);
340
+ }
341
+
342
+ const result = await runTrail(args);
343
+ if (result.success) {
344
+ // Parse trajectory ID from output like "✓ Trajectory started: traj_xxx"
345
+ const match = result.output.match(/traj_[a-z0-9]+/i);
346
+ return { success: true, trajectoryId: match?.[0] };
347
+ }
348
+ return { success: false, error: result.error };
349
+ }
350
+
351
+ /**
352
+ * Get current trajectory status
353
+ * Reads directly from .trajectories/index.json instead of using CLI
354
+ */
355
+ export async function getTrajectoryStatus(): Promise<{ active: boolean; trajectoryId?: string; phase?: PDEROPhase; task?: string }> {
356
+ const index = readTrajectoryIndex();
357
+ const trajectoryDirs = getAllTrajectoriesDirs();
358
+ if (!index && trajectoryDirs.length === 0) {
359
+ return { active: false };
360
+ }
361
+
362
+ // Find an active trajectory
363
+ if (index) {
364
+ for (const [id, entry] of Object.entries(index.trajectories)) {
365
+ if (entry.status === 'active') {
366
+ // Read the full trajectory file to get phase info
367
+ const trajectory = readTrajectoryFile(entry.path);
368
+ const currentPhase = getCurrentPhaseFromTrajectory(trajectory);
369
+
370
+ return {
371
+ active: true,
372
+ trajectoryId: id,
373
+ phase: currentPhase,
374
+ task: entry.title,
375
+ };
376
+ }
377
+ }
378
+ }
379
+
380
+ for (const dir of trajectoryDirs) {
381
+ for (const activePath of listActiveTrajectoryFiles(dir)) {
382
+ const trajectory = readTrajectoryFile(activePath);
383
+ if (!trajectory) {
384
+ continue;
385
+ }
386
+
387
+ return {
388
+ active: true,
389
+ trajectoryId: trajectory.id,
390
+ phase: getCurrentPhaseFromTrajectory(trajectory),
391
+ task: trajectory.task?.title,
392
+ };
393
+ }
394
+ }
395
+
396
+ return { active: false };
397
+ }
398
+
399
+ /**
400
+ * Transition to a new PDERO phase
401
+ */
402
+ export async function transitionPhase(phase: PDEROPhase, reason?: string, agentName?: string): Promise<{ success: boolean; error?: string }> {
403
+ const args = ['phase', phase];
404
+
405
+ if (reason) {
406
+ args.push('--reason', reason);
407
+ }
408
+ if (agentName) {
409
+ args.push('--agent', agentName);
410
+ }
411
+
412
+ const result = await runTrail(args);
413
+ return { success: result.success, error: result.error };
414
+ }
415
+
416
+ /**
417
+ * Record a decision
418
+ */
419
+ export async function recordDecision(options: DecisionOptions): Promise<{ success: boolean; error?: string }> {
420
+ const args = ['decision', options.choice];
421
+
422
+ if (options.question) {
423
+ args.push('--question', options.question);
424
+ }
425
+ if (options.alternatives && options.alternatives.length > 0) {
426
+ args.push('--alternatives', options.alternatives.join(','));
427
+ }
428
+ if (options.reasoning) {
429
+ args.push('--reasoning', options.reasoning);
430
+ }
431
+ if (options.confidence !== undefined) {
432
+ args.push('--confidence', options.confidence.toString());
433
+ }
434
+
435
+ const result = await runTrail(args);
436
+ return { success: result.success, error: result.error };
437
+ }
438
+
439
+ /**
440
+ * Record an event/observation
441
+ */
442
+ export async function recordEvent(
443
+ content: string,
444
+ type: 'tool_call' | 'observation' | 'checkpoint' | 'error' = 'observation',
445
+ agentName?: string
446
+ ): Promise<{ success: boolean; error?: string }> {
447
+ const args = ['event', content, '--type', type];
448
+
449
+ if (agentName) {
450
+ args.push('--agent', agentName);
451
+ }
452
+
453
+ const result = await runTrail(args);
454
+ return { success: result.success, error: result.error };
455
+ }
456
+
457
+ /**
458
+ * Record a message (sent or received)
459
+ */
460
+ export async function recordMessage(
461
+ direction: 'sent' | 'received',
462
+ from: string,
463
+ to: string,
464
+ body: string
465
+ ): Promise<{ success: boolean; error?: string }> {
466
+ const content = `Message ${direction}: ${direction === 'sent' ? `→ ${to}` : `← ${from}`}: ${body.slice(0, 100)}${body.length > 100 ? '...' : ''}`;
467
+ return recordEvent(content, 'observation');
468
+ }
469
+
470
+ /**
471
+ * Complete the current trajectory
472
+ */
473
+ export async function completeTrajectory(options: CompleteTrajectoryOptions = {}): Promise<{ success: boolean; error?: string }> {
474
+ const args = ['complete'];
475
+
476
+ if (options.summary) {
477
+ args.push('--summary', options.summary);
478
+ }
479
+ if (options.confidence !== undefined) {
480
+ args.push('--confidence', options.confidence.toString());
481
+ }
482
+ if (options.challenges && options.challenges.length > 0) {
483
+ args.push('--challenges', options.challenges.join(','));
484
+ }
485
+ if (options.learnings && options.learnings.length > 0) {
486
+ args.push('--learnings', options.learnings.join(','));
487
+ }
488
+
489
+ const result = await runTrail(args);
490
+ return { success: result.success, error: result.error };
491
+ }
492
+
493
+ /**
494
+ * Abandon the current trajectory
495
+ */
496
+ export async function abandonTrajectory(reason?: string): Promise<{ success: boolean; error?: string }> {
497
+ const args = ['abandon'];
498
+
499
+ if (reason) {
500
+ args.push('--reason', reason);
501
+ }
502
+
503
+ const result = await runTrail(args);
504
+ return { success: result.success, error: result.error };
505
+ }
506
+
507
+ /**
508
+ * Trajectory step for dashboard display
509
+ */
510
+ export interface TrajectoryStepData {
511
+ id: string;
512
+ timestamp: string | number;
513
+ type: 'tool_call' | 'decision' | 'message' | 'state_change' | 'error' | 'phase_transition';
514
+ phase?: PDEROPhase;
515
+ title: string;
516
+ description?: string;
517
+ metadata?: Record<string, unknown>;
518
+ duration?: number;
519
+ status?: 'pending' | 'running' | 'success' | 'error';
520
+ }
521
+
522
+ /**
523
+ * List trajectory steps/events
524
+ * Returns steps for the current or specified trajectory
525
+ * Reads directly from filesystem instead of using CLI
526
+ */
527
+ export async function listTrajectorySteps(trajectoryId?: string): Promise<{
528
+ success: boolean;
529
+ steps: TrajectoryStepData[];
530
+ error?: string;
531
+ }> {
532
+ const trajectoryDirs = getAllTrajectoriesDirs();
533
+ const index = readTrajectoryIndex();
534
+
535
+ if (!index && trajectoryDirs.length === 0) {
536
+ return { success: true, steps: [] };
537
+ }
538
+
539
+ // Collect all trajectory paths to load
540
+ const trajectoryPaths = new Set<string>();
541
+
542
+ if (trajectoryId) {
543
+ // Use specified trajectory - try multiple lookup strategies
544
+ let foundPath: string | null = null;
545
+
546
+ // Strategy 1: Look up by index key
547
+ const entry = index?.trajectories[trajectoryId];
548
+ if (entry) {
549
+ foundPath = entry.path;
550
+ console.log('[trajectory] Found by index key:', trajectoryId, '->', foundPath);
551
+ }
552
+
553
+ // Strategy 2: If not found by key, search index entries by file's internal ID
554
+ // This handles cases where the index key differs from the file's internal ID
555
+ if (!foundPath && index) {
556
+ for (const [_key, indexEntry] of Object.entries(index.trajectories)) {
557
+ const trajectory = readTrajectoryFile(indexEntry.path);
558
+ if (trajectory && trajectory.id === trajectoryId) {
559
+ foundPath = indexEntry.path;
560
+ console.log('[trajectory] Found by file ID scan:', trajectoryId, '->', foundPath);
561
+ break;
562
+ }
563
+ }
564
+ }
565
+
566
+ // Strategy 3: Fall back to active directory filename match
567
+ if (!foundPath) {
568
+ foundPath = findActiveTrajectoryPathById(trajectoryDirs, trajectoryId);
569
+ if (foundPath) {
570
+ console.log('[trajectory] Found by active dir fallback:', trajectoryId, '->', foundPath);
571
+ }
572
+ }
573
+
574
+ if (foundPath) {
575
+ trajectoryPaths.add(foundPath);
576
+ } else {
577
+ console.log('[trajectory] Not found:', trajectoryId);
578
+ }
579
+ } else {
580
+ // Collect ALL active trajectories (not just the first one)
581
+ if (index) {
582
+ for (const [_id, entry] of Object.entries(index.trajectories)) {
583
+ if (entry.status === 'active') {
584
+ trajectoryPaths.add(entry.path);
585
+ }
586
+ }
587
+ }
588
+
589
+ for (const dir of trajectoryDirs) {
590
+ for (const activePath of listActiveTrajectoryFiles(dir)) {
591
+ trajectoryPaths.add(activePath);
592
+ }
593
+ }
594
+ }
595
+
596
+ if (trajectoryPaths.size === 0) {
597
+ return { success: true, steps: [] };
598
+ }
599
+
600
+ // Load all trajectories and merge their steps
601
+ const steps: TrajectoryStepData[] = [];
602
+ let stepIndex = 0;
603
+
604
+ for (const trajectoryPath of trajectoryPaths) {
605
+ const trajectory = readTrajectoryFile(trajectoryPath);
606
+ if (!trajectory) {
607
+ continue;
608
+ }
609
+
610
+ // Extract events from all chapters
611
+ // Include trajectory ID in step IDs to ensure uniqueness across trajectories
612
+ // This prevents React key collisions when switching between trajectories
613
+ const trajId = trajectory.id || 'unknown';
614
+ for (const chapter of trajectory.chapters || []) {
615
+ for (const event of chapter.events || []) {
616
+ steps.push({
617
+ id: `${trajId}-step-${stepIndex++}`,
618
+ timestamp: event.ts || Date.now(),
619
+ type: mapEventType(event.type),
620
+ title: event.content?.slice(0, 50) || event.type || 'Event',
621
+ description: event.content,
622
+ metadata: event.raw,
623
+ status: mapEventStatus(trajectory.status),
624
+ });
625
+ }
626
+ }
627
+ }
628
+
629
+ // Sort steps by timestamp to maintain chronological order across all trajectories
630
+ steps.sort((a, b) => {
631
+ const timeA = typeof a.timestamp === 'number' ? a.timestamp : new Date(a.timestamp as string).getTime();
632
+ const timeB = typeof b.timestamp === 'number' ? b.timestamp : new Date(b.timestamp as string).getTime();
633
+ return timeA - timeB;
634
+ });
635
+
636
+ return { success: true, steps };
637
+ }
638
+
639
+ /**
640
+ * Trajectory history entry for dashboard display
641
+ */
642
+ export interface TrajectoryHistoryEntry {
643
+ id: string;
644
+ title: string;
645
+ status: 'active' | 'completed' | 'abandoned';
646
+ startedAt: string;
647
+ completedAt?: string;
648
+ agents?: string[];
649
+ summary?: string;
650
+ confidence?: number;
651
+ }
652
+
653
+ /**
654
+ * Get trajectory history - list all trajectories
655
+ * Reads directly from filesystem
656
+ */
657
+ export async function getTrajectoryHistory(): Promise<{
658
+ success: boolean;
659
+ trajectories: TrajectoryHistoryEntry[];
660
+ error?: string;
661
+ }> {
662
+ const trajectoryDirs = getAllTrajectoriesDirs();
663
+ const index = readTrajectoryIndex();
664
+ if (!index && trajectoryDirs.length === 0) {
665
+ return { success: true, trajectories: [] };
666
+ }
667
+
668
+ const trajectories: TrajectoryHistoryEntry[] = [];
669
+ const seenIds = new Set<string>();
670
+
671
+ if (index) {
672
+ for (const [indexKey, entry] of Object.entries(index.trajectories)) {
673
+ // Read the trajectory file to get the actual internal ID
674
+ // This ensures consistency between history list IDs and file content
675
+ const trajectory = entry.path ? readTrajectoryFile(entry.path) : null;
676
+
677
+ // Use the file's internal ID if available, otherwise fall back to index key
678
+ // This fixes the mismatch where index key differs from file's internal ID
679
+ const actualId = trajectory?.id || indexKey;
680
+
681
+ // Skip if we've already seen this ID (from a previous directory's index)
682
+ if (seenIds.has(actualId)) {
683
+ continue;
684
+ }
685
+
686
+ const historyEntry: TrajectoryHistoryEntry = {
687
+ id: actualId,
688
+ title: trajectory?.task?.title || entry.title,
689
+ status: entry.status,
690
+ startedAt: trajectory?.startedAt || entry.startedAt,
691
+ completedAt: trajectory?.completedAt || entry.completedAt,
692
+ };
693
+
694
+ // Add additional details from trajectory file
695
+ if (trajectory) {
696
+ historyEntry.agents = trajectory.agents?.map(a => a.name);
697
+ if (trajectory.retrospective) {
698
+ historyEntry.summary = trajectory.retrospective.summary;
699
+ historyEntry.confidence = trajectory.retrospective.confidence;
700
+ }
701
+ }
702
+
703
+ trajectories.push(historyEntry);
704
+ seenIds.add(actualId);
705
+ }
706
+ }
707
+
708
+ for (const dir of trajectoryDirs) {
709
+ for (const activePath of listActiveTrajectoryFiles(dir)) {
710
+ const trajectory = readTrajectoryFile(activePath);
711
+ if (!trajectory || seenIds.has(trajectory.id)) {
712
+ continue;
713
+ }
714
+
715
+ const historyEntry: TrajectoryHistoryEntry = {
716
+ id: trajectory.id,
717
+ title: trajectory.task?.title || 'Untitled trajectory',
718
+ status: trajectory.status ?? 'active',
719
+ startedAt: trajectory.startedAt,
720
+ completedAt: trajectory.completedAt,
721
+ agents: trajectory.agents?.map(a => a.name),
722
+ };
723
+
724
+ if (trajectory.retrospective) {
725
+ historyEntry.summary = trajectory.retrospective.summary;
726
+ historyEntry.confidence = trajectory.retrospective.confidence;
727
+ }
728
+
729
+ trajectories.push(historyEntry);
730
+ seenIds.add(trajectory.id);
731
+ }
732
+ }
733
+
734
+ // Sort by startedAt descending (most recent first)
735
+ trajectories.sort((a, b) =>
736
+ new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
737
+ );
738
+
739
+ return { success: true, trajectories };
740
+ }
741
+
742
+ /**
743
+ * Map trail event type to dashboard type
744
+ */
745
+ function mapEventType(type?: string): TrajectoryStepData['type'] {
746
+ switch (type?.toLowerCase()) {
747
+ case 'tool':
748
+ case 'tool_call':
749
+ case 'tool_use':
750
+ return 'tool_call';
751
+ case 'decision':
752
+ case 'choice':
753
+ return 'decision';
754
+ case 'message':
755
+ case 'observation':
756
+ return 'message';
757
+ case 'phase':
758
+ case 'phase_change':
759
+ case 'phase_transition':
760
+ return 'phase_transition';
761
+ case 'error':
762
+ case 'failure':
763
+ return 'error';
764
+ default:
765
+ return 'state_change';
766
+ }
767
+ }
768
+
769
+ /**
770
+ * Map trail status to dashboard status
771
+ */
772
+ function mapEventStatus(status?: string): TrajectoryStepData['status'] | undefined {
773
+ switch (status?.toLowerCase()) {
774
+ case 'running':
775
+ case 'in_progress':
776
+ case 'active':
777
+ return 'running';
778
+ case 'success':
779
+ case 'completed':
780
+ case 'done':
781
+ return 'success';
782
+ case 'error':
783
+ case 'failed':
784
+ case 'abandoned':
785
+ return 'error';
786
+ case 'pending':
787
+ case 'queued':
788
+ return 'pending';
789
+ default:
790
+ return undefined;
791
+ }
792
+ }
793
+
794
+ /**
795
+ * Detect PDERO phase from content
796
+ */
797
+ export function detectPhaseFromContent(content: string): PDEROPhase | undefined {
798
+ const lowerContent = content.toLowerCase();
799
+
800
+ const phasePatterns: Array<{ phase: PDEROPhase; patterns: string[] }> = [
801
+ { phase: 'plan', patterns: ['planning', 'analyzing requirements', 'breaking down', 'creating plan', 'task list', 'todo', 'outline'] },
802
+ { phase: 'design', patterns: ['designing', 'architecting', 'choosing pattern', 'interface design', 'schema design', 'architecture'] },
803
+ { phase: 'execute', patterns: ['implementing', 'writing', 'coding', 'building', 'creating file', 'modifying', 'editing'] },
804
+ { phase: 'review', patterns: ['testing', 'reviewing', 'validating', 'checking', 'verifying', 'running tests', 'test passed', 'test failed'] },
805
+ { phase: 'observe', patterns: ['observing', 'monitoring', 'reflecting', 'documenting', 'retrospective', 'learnings', 'summary'] },
806
+ ];
807
+
808
+ for (const { phase, patterns } of phasePatterns) {
809
+ for (const pattern of patterns) {
810
+ if (lowerContent.includes(pattern)) {
811
+ return phase;
812
+ }
813
+ }
814
+ }
815
+
816
+ return undefined;
817
+ }
818
+
819
+ /**
820
+ * Detected tool call information
821
+ */
822
+ export interface DetectedToolCall {
823
+ tool: string;
824
+ args?: string;
825
+ status?: 'started' | 'completed' | 'failed';
826
+ }
827
+
828
+ /**
829
+ * Detected error information
830
+ */
831
+ export interface DetectedError {
832
+ type: 'error' | 'warning' | 'failure';
833
+ message: string;
834
+ stack?: string;
835
+ }
836
+
837
+ /**
838
+ * All known Claude Code tool names
839
+ */
840
+ const TOOL_NAMES = [
841
+ 'Read', 'Write', 'Edit', 'Bash', 'Glob', 'Grep', 'Task', 'TaskOutput',
842
+ 'WebFetch', 'WebSearch', 'NotebookEdit', 'TodoWrite', 'AskUserQuestion',
843
+ 'KillShell', 'EnterPlanMode', 'ExitPlanMode', 'Skill', 'SlashCommand',
844
+ ];
845
+
846
+ const TOOL_NAME_PATTERN = TOOL_NAMES.join('|');
847
+
848
+ /**
849
+ * Tool call patterns for Claude Code and similar AI CLIs
850
+ */
851
+ const TOOL_PATTERNS = [
852
+ // Claude Code tool invocations (displayed in output with parenthesis/braces)
853
+ new RegExp(`(?:^|\\n)\\s*(?:${TOOL_NAME_PATTERN})\\s*[({]`, 'i'),
854
+ // Tool completion markers (checkmarks, spinners)
855
+ new RegExp(`(?:^|\\n)\\s*(?:✓|✔|⠋|⠙|⠹|⠸|⠼|⠴|⠦|⠧|⠇|⠏)\\s*(${TOOL_NAME_PATTERN})`, 'i'),
856
+ // Function call patterns (explicit mentions)
857
+ new RegExp(`(?:^|\\n)\\s*(?:Calling|Using|Invoking)\\s+(?:tool\\s+)?['"]?(${TOOL_NAME_PATTERN})['"]?`, 'i'),
858
+ // Tool result patterns
859
+ new RegExp(`(?:^|\\n)\\s*(?:Tool result|Result from)\\s*:?\\s*(${TOOL_NAME_PATTERN})`, 'i'),
860
+ ];
861
+
862
+ /**
863
+ * Error patterns for detecting failures in output
864
+ * Note: Patterns are ordered from most specific to least specific
865
+ */
866
+ const ERROR_PATTERNS = [
867
+ // JavaScript/TypeScript runtime errors (most specific)
868
+ /(?:^|\n)((?:TypeError|ReferenceError|SyntaxError|RangeError|EvalError|URIError):\s*.+)/i,
869
+ // Named Error with message (e.g., "Error: Something went wrong")
870
+ /(?:^|\n)(Error:\s+.+)/,
871
+ // Failed assertions
872
+ /(?:^|\n)\s*(AssertionError:\s*.+)/i,
873
+ // Test failures (Vitest, Jest patterns)
874
+ /(?:^|\n)\s*(FAIL\s+\S+\.(?:ts|js|tsx|jsx))/i,
875
+ /(?:^|\n)\s*(✗|✘|×)\s+(.+)/,
876
+ // Command/process failures
877
+ /(?:^|\n)\s*(Command failed[^\n]+)/i,
878
+ /(?:^|\n)\s*((?:Exit|exit)\s+code[:\s]+[1-9]\d*)/i,
879
+ /(?:^|\n)\s*(exited with (?:code\s+)?[1-9]\d*)/i,
880
+ // Node.js/system errors
881
+ /(?:^|\n)\s*(EACCES|EPERM|ENOENT|ECONNREFUSED|ETIMEDOUT|ENOTFOUND)(?::\s*.+)?/,
882
+ // Build/compile errors (webpack, tsc, etc.)
883
+ /(?:^|\n)\s*(error TS\d+:\s*.+)/i,
884
+ /(?:^|\n)\s*(error\[\S+\]:\s*.+)/i,
885
+ ];
886
+
887
+ /**
888
+ * Warning patterns for detecting potential issues
889
+ */
890
+ const WARNING_PATTERNS = [
891
+ /(?:^|\n)\s*(?:warning|WARN|⚠️?)\s*[:\[]?\s*(.+)/i,
892
+ /(?:^|\n)\s*(?:deprecated|DEPRECATED):\s*(.+)/i,
893
+ ];
894
+
895
+ /**
896
+ * Detect tool calls from agent output
897
+ *
898
+ * @example
899
+ * ```typescript
900
+ * const tools = detectToolCalls(output);
901
+ * // Returns: [{ tool: 'Read', args: 'file.ts' }, { tool: 'Bash', status: 'completed' }]
902
+ * ```
903
+ */
904
+ export function detectToolCalls(content: string): DetectedToolCall[] {
905
+ const detected: DetectedToolCall[] = [];
906
+ const seenTools = new Set<string>();
907
+ const toolNameExtractor = new RegExp(`\\b(${TOOL_NAME_PATTERN})\\b`, 'i');
908
+
909
+ for (const pattern of TOOL_PATTERNS) {
910
+ const matches = content.matchAll(new RegExp(pattern.source, 'gi'));
911
+ for (const match of matches) {
912
+ // Extract tool name from the match
913
+ const fullMatch = match[0];
914
+ const toolNameMatch = fullMatch.match(toolNameExtractor);
915
+ if (toolNameMatch) {
916
+ const tool = toolNameMatch[1];
917
+ // Avoid duplicates by position (same tool at same position)
918
+ const key = `${tool}:${match.index}`;
919
+ if (!seenTools.has(key)) {
920
+ seenTools.add(key);
921
+ detected.push({
922
+ tool,
923
+ status: fullMatch.includes('✓') || fullMatch.includes('✔') ? 'completed' : 'started',
924
+ });
925
+ }
926
+ }
927
+ }
928
+ }
929
+
930
+ return detected;
931
+ }
932
+
933
+ /**
934
+ * Detect errors from agent output
935
+ *
936
+ * @example
937
+ * ```typescript
938
+ * const errors = detectErrors(output);
939
+ * // Returns: [{ type: 'error', message: 'TypeError: Cannot read property...' }]
940
+ * ```
941
+ */
942
+ export function detectErrors(content: string): DetectedError[] {
943
+ const detected: DetectedError[] = [];
944
+ const seenMessages = new Set<string>();
945
+
946
+ // Check for error patterns
947
+ for (const pattern of ERROR_PATTERNS) {
948
+ const matches = content.matchAll(new RegExp(pattern, 'gi'));
949
+ for (const match of matches) {
950
+ const message = match[1] || match[0];
951
+ const cleanMessage = message.trim().slice(0, 200); // Limit length
952
+ if (!seenMessages.has(cleanMessage)) {
953
+ seenMessages.add(cleanMessage);
954
+ detected.push({
955
+ type: 'error',
956
+ message: cleanMessage,
957
+ });
958
+ }
959
+ }
960
+ }
961
+
962
+ // Check for warning patterns
963
+ for (const pattern of WARNING_PATTERNS) {
964
+ const matches = content.matchAll(new RegExp(pattern, 'gi'));
965
+ for (const match of matches) {
966
+ const message = match[1] || match[0];
967
+ const cleanMessage = message.trim().slice(0, 200);
968
+ if (!seenMessages.has(cleanMessage)) {
969
+ seenMessages.add(cleanMessage);
970
+ detected.push({
971
+ type: 'warning',
972
+ message: cleanMessage,
973
+ });
974
+ }
975
+ }
976
+ }
977
+
978
+ return detected;
979
+ }
980
+
981
+ /**
982
+ * TrajectoryIntegration class for managing trajectory state
983
+ *
984
+ * This class enforces trajectory tracking during agent lifecycle:
985
+ * - Auto-starts trajectory when agent is instantiated with a task
986
+ * - Records all inter-agent messages
987
+ * - Auto-detects PDERO phase transitions
988
+ * - Provides lifecycle hooks for tmux/pty wrappers
989
+ */
990
+ export class TrajectoryIntegration {
991
+ private projectId: string;
992
+ private agentName: string;
993
+ private trailAvailable: boolean | null = null;
994
+ private currentPhase: PDEROPhase | null = null;
995
+ private trajectoryId: string | null = null;
996
+ private initialized = false;
997
+ private task: string | null = null;
998
+
999
+ constructor(projectId: string, agentName: string) {
1000
+ this.projectId = projectId;
1001
+ this.agentName = agentName;
1002
+ }
1003
+
1004
+ /**
1005
+ * Check if trail is available (cached)
1006
+ */
1007
+ async isAvailable(): Promise<boolean> {
1008
+ if (this.trailAvailable === null) {
1009
+ this.trailAvailable = await isTrailAvailable();
1010
+ }
1011
+ return this.trailAvailable;
1012
+ }
1013
+
1014
+ /**
1015
+ * Check if trail CLI is installed synchronously
1016
+ */
1017
+ isTrailInstalledSync(): boolean {
1018
+ try {
1019
+ execSync('which trail', { stdio: 'pipe' });
1020
+ return true;
1021
+ } catch {
1022
+ return false;
1023
+ }
1024
+ }
1025
+
1026
+ /**
1027
+ * Initialize trajectory tracking for agent lifecycle
1028
+ * Called automatically when agent starts with a task
1029
+ */
1030
+ async initialize(task?: string, taskId?: string, source?: string): Promise<boolean> {
1031
+ if (this.initialized) return true;
1032
+
1033
+ if (!(await this.isAvailable())) {
1034
+ return false;
1035
+ }
1036
+
1037
+ // If task provided, auto-start trajectory
1038
+ if (task) {
1039
+ const success = await this.start(task, taskId, source);
1040
+ if (success) {
1041
+ this.initialized = true;
1042
+ this.task = task;
1043
+ }
1044
+ return success;
1045
+ }
1046
+
1047
+ this.initialized = true;
1048
+ return true;
1049
+ }
1050
+
1051
+ /**
1052
+ * Start tracking a trajectory
1053
+ */
1054
+ async start(task: string, taskId?: string, source?: string): Promise<boolean> {
1055
+ if (!(await this.isAvailable())) return false;
1056
+
1057
+ const result = await startTrajectory({
1058
+ task,
1059
+ taskId,
1060
+ source,
1061
+ agentName: this.agentName,
1062
+ phase: 'plan',
1063
+ });
1064
+
1065
+ if (result.success) {
1066
+ this.currentPhase = 'plan';
1067
+ this.trajectoryId = result.trajectoryId || null;
1068
+ this.task = task;
1069
+ }
1070
+
1071
+ return result.success;
1072
+ }
1073
+
1074
+ /**
1075
+ * Check if there's an active trajectory
1076
+ */
1077
+ hasActiveTrajectory(): boolean {
1078
+ return this.currentPhase !== null;
1079
+ }
1080
+
1081
+ /**
1082
+ * Get the current task
1083
+ */
1084
+ getTask(): string | null {
1085
+ return this.task;
1086
+ }
1087
+
1088
+ /**
1089
+ * Get trajectory ID
1090
+ */
1091
+ getTrajectoryId(): string | null {
1092
+ return this.trajectoryId;
1093
+ }
1094
+
1095
+ /**
1096
+ * Record a message
1097
+ */
1098
+ async message(direction: 'sent' | 'received', from: string, to: string, body: string): Promise<void> {
1099
+ if (!(await this.isAvailable())) return;
1100
+
1101
+ await recordMessage(direction, from, to, body);
1102
+
1103
+ // Check for phase transition based on content
1104
+ const detectedPhase = detectPhaseFromContent(body);
1105
+ if (detectedPhase && detectedPhase !== this.currentPhase) {
1106
+ await this.transition(detectedPhase, 'Auto-detected from message content');
1107
+ }
1108
+ }
1109
+
1110
+ /**
1111
+ * Transition to a new phase
1112
+ */
1113
+ async transition(phase: PDEROPhase, reason?: string): Promise<boolean> {
1114
+ if (!(await this.isAvailable())) return false;
1115
+ if (phase === this.currentPhase) return true;
1116
+
1117
+ const result = await transitionPhase(phase, reason, this.agentName);
1118
+ if (result.success) {
1119
+ this.currentPhase = phase;
1120
+ }
1121
+ return result.success;
1122
+ }
1123
+
1124
+ /**
1125
+ * Record a decision
1126
+ */
1127
+ async decision(choice: string, options?: Partial<DecisionOptions>): Promise<boolean> {
1128
+ if (!(await this.isAvailable())) return false;
1129
+
1130
+ const result = await recordDecision({
1131
+ choice,
1132
+ ...options,
1133
+ });
1134
+ return result.success;
1135
+ }
1136
+
1137
+ /**
1138
+ * Record an event
1139
+ */
1140
+ async event(content: string, type: 'tool_call' | 'observation' | 'checkpoint' | 'error' = 'observation'): Promise<boolean> {
1141
+ if (!(await this.isAvailable())) return false;
1142
+
1143
+ const result = await recordEvent(content, type, this.agentName);
1144
+
1145
+ // Check for phase transition
1146
+ const detectedPhase = detectPhaseFromContent(content);
1147
+ if (detectedPhase && detectedPhase !== this.currentPhase) {
1148
+ await this.transition(detectedPhase, 'Auto-detected from event content');
1149
+ }
1150
+
1151
+ return result.success;
1152
+ }
1153
+
1154
+ /**
1155
+ * Complete the trajectory
1156
+ */
1157
+ async complete(options?: CompleteTrajectoryOptions): Promise<boolean> {
1158
+ if (!(await this.isAvailable())) return false;
1159
+
1160
+ const result = await completeTrajectory(options);
1161
+ if (result.success) {
1162
+ this.currentPhase = null;
1163
+ }
1164
+ return result.success;
1165
+ }
1166
+
1167
+ /**
1168
+ * Abandon the trajectory
1169
+ */
1170
+ async abandon(reason?: string): Promise<boolean> {
1171
+ if (!(await this.isAvailable())) return false;
1172
+
1173
+ const result = await abandonTrajectory(reason);
1174
+ if (result.success) {
1175
+ this.currentPhase = null;
1176
+ }
1177
+ return result.success;
1178
+ }
1179
+
1180
+ /**
1181
+ * Get current phase
1182
+ */
1183
+ getPhase(): PDEROPhase | null {
1184
+ return this.currentPhase;
1185
+ }
1186
+ }
1187
+
1188
+ /**
1189
+ * Global trajectory integration instances
1190
+ */
1191
+ const instances = new Map<string, TrajectoryIntegration>();
1192
+
1193
+ /**
1194
+ * Get or create a TrajectoryIntegration instance
1195
+ */
1196
+ export function getTrajectoryIntegration(projectId: string, agentName: string): TrajectoryIntegration {
1197
+ const key = `${projectId}:${agentName}`;
1198
+ let instance = instances.get(key);
1199
+ if (!instance) {
1200
+ instance = new TrajectoryIntegration(projectId, agentName);
1201
+ instances.set(key, instance);
1202
+ }
1203
+ return instance;
1204
+ }
1205
+
1206
+ /**
1207
+ * Generate trail usage instructions for agents
1208
+ */
1209
+ export function getTrailInstructions(): string[] {
1210
+ return [
1211
+ '📍 TRAJECTORY TRACKING (PDERO Paradigm)',
1212
+ '',
1213
+ 'You MUST use trail commands to track your work:',
1214
+ '',
1215
+ 'PHASES: plan → design → execute → review → observe',
1216
+ '',
1217
+ 'COMMANDS:',
1218
+ ' trail start "task" Start trajectory for a task',
1219
+ ' trail phase <phase> Transition to new phase',
1220
+ ' trail decision "choice" Record key decisions',
1221
+ ' trail event "what happened" Log significant events',
1222
+ ' trail complete Complete with summary',
1223
+ '',
1224
+ 'WHEN TO USE:',
1225
+ ' - Start: At beginning of any task',
1226
+ ' - Phase: When shifting focus (planning→implementing, etc.)',
1227
+ ' - Decision: For architecture/approach choices',
1228
+ ' - Event: For tool calls, errors, milestones',
1229
+ ' - Complete: When task is done',
1230
+ '',
1231
+ 'Example workflow:',
1232
+ ' trail start "Implement auth feature"',
1233
+ ' trail phase design',
1234
+ ' trail decision "Use JWT" --reasoning "Stateless, scalable"',
1235
+ ' trail phase execute',
1236
+ ' trail event "Created auth middleware"',
1237
+ ' trail phase review',
1238
+ ' trail event "All tests passing"',
1239
+ ' trail complete --summary "Auth implemented" --confidence 0.9',
1240
+ ];
1241
+ }
1242
+
1243
+ /**
1244
+ * Get a compact trail instruction string for injection
1245
+ */
1246
+ export function getCompactTrailInstructions(): string {
1247
+ return [
1248
+ '[TRAIL] Track work with PDERO: plan→design→execute→review→observe.',
1249
+ 'Commands: trail start "task" | trail phase <phase> | trail decision "choice" | trail event "log" | trail complete',
1250
+ 'Use trail often to document your thought process.',
1251
+ ].join(' ');
1252
+ }
1253
+
1254
+ /**
1255
+ * Get environment variables for trail CLI
1256
+ * If dataDir is not provided, uses config-based storage location
1257
+ */
1258
+ export function getTrailEnvVars(projectId: string, agentName: string, dataDir?: string): Record<string, string> {
1259
+ // Use config-based path if dataDir not explicitly provided
1260
+ const effectiveDataDir = dataDir ?? getPrimaryTrajectoriesDir();
1261
+
1262
+ return {
1263
+ TRAJECTORIES_PROJECT: projectId,
1264
+ TRAJECTORIES_DATA_DIR: effectiveDataDir,
1265
+ TRAJECTORIES_AGENT: agentName,
1266
+ TRAIL_AUTO_PHASE: '1', // Enable auto phase detection
1267
+ };
1268
+ }