@creativeintelligence/abbie 0.1.3 → 0.1.5

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 (537) hide show
  1. package/dist/cli/commands/start.js +2 -1
  2. package/oclif.manifest.json +1 -1
  3. package/package.json +13 -7
  4. package/dist/cli/base-command.d.ts.map +0 -1
  5. package/dist/cli/commands/agent/list.d.ts.map +0 -1
  6. package/dist/cli/commands/annotation/ack.d.ts.map +0 -1
  7. package/dist/cli/commands/annotation/create.d.ts.map +0 -1
  8. package/dist/cli/commands/annotation/events.d.ts.map +0 -1
  9. package/dist/cli/commands/annotation/export.d.ts.map +0 -1
  10. package/dist/cli/commands/annotation/import.d.ts.map +0 -1
  11. package/dist/cli/commands/annotation/ingest.d.ts.map +0 -1
  12. package/dist/cli/commands/annotation/list.d.ts.map +0 -1
  13. package/dist/cli/commands/annotation/reply.d.ts.map +0 -1
  14. package/dist/cli/commands/annotation/resolve.d.ts.map +0 -1
  15. package/dist/cli/commands/auto/index.d.ts.map +0 -1
  16. package/dist/cli/commands/backlog/add.d.ts.map +0 -1
  17. package/dist/cli/commands/backlog/claim.d.ts.map +0 -1
  18. package/dist/cli/commands/backlog/complete.d.ts.map +0 -1
  19. package/dist/cli/commands/backlog/list.d.ts.map +0 -1
  20. package/dist/cli/commands/backlog/pick.d.ts.map +0 -1
  21. package/dist/cli/commands/backlog/sync.d.ts.map +0 -1
  22. package/dist/cli/commands/bootstrap.d.ts.map +0 -1
  23. package/dist/cli/commands/bridge.d.ts.map +0 -1
  24. package/dist/cli/commands/context/inject.d.ts.map +0 -1
  25. package/dist/cli/commands/context/list.d.ts.map +0 -1
  26. package/dist/cli/commands/context/publish.d.ts.map +0 -1
  27. package/dist/cli/commands/context/read.d.ts.map +0 -1
  28. package/dist/cli/commands/daemon.d.ts.map +0 -1
  29. package/dist/cli/commands/digest/index.d.ts.map +0 -1
  30. package/dist/cli/commands/docs/lint.d.ts.map +0 -1
  31. package/dist/cli/commands/docs/sync.d.ts.map +0 -1
  32. package/dist/cli/commands/doctor.d.ts.map +0 -1
  33. package/dist/cli/commands/find/index.d.ts.map +0 -1
  34. package/dist/cli/commands/gc.d.ts.map +0 -1
  35. package/dist/cli/commands/history/index.d.ts.map +0 -1
  36. package/dist/cli/commands/hooks/guard.d.ts.map +0 -1
  37. package/dist/cli/commands/hooks/list.d.ts.map +0 -1
  38. package/dist/cli/commands/hooks/lock.d.ts.map +0 -1
  39. package/dist/cli/commands/hooks/status.d.ts.map +0 -1
  40. package/dist/cli/commands/hooks/test.d.ts.map +0 -1
  41. package/dist/cli/commands/hooks/unlock.d.ts.map +0 -1
  42. package/dist/cli/commands/index.d.ts.map +0 -1
  43. package/dist/cli/commands/list.d.ts.map +0 -1
  44. package/dist/cli/commands/list.e2e.test.d.ts +0 -1
  45. package/dist/cli/commands/list.e2e.test.js +0 -47
  46. package/dist/cli/commands/login.d.ts.map +0 -1
  47. package/dist/cli/commands/logout.d.ts.map +0 -1
  48. package/dist/cli/commands/panes/broker.d.ts.map +0 -1
  49. package/dist/cli/commands/panes/pipe-sink.d.ts.map +0 -1
  50. package/dist/cli/commands/panes/snapshot.d.ts.map +0 -1
  51. package/dist/cli/commands/plan.d.ts.map +0 -1
  52. package/dist/cli/commands/plan.e2e.test.d.ts +0 -1
  53. package/dist/cli/commands/plan.e2e.test.js +0 -74
  54. package/dist/cli/commands/preview/index.d.ts.map +0 -1
  55. package/dist/cli/commands/preview/init.d.ts.map +0 -1
  56. package/dist/cli/commands/preview/list.d.ts.map +0 -1
  57. package/dist/cli/commands/preview/status.d.ts.map +0 -1
  58. package/dist/cli/commands/preview/stop.d.ts.map +0 -1
  59. package/dist/cli/commands/preview/sync.d.ts.map +0 -1
  60. package/dist/cli/commands/preview/watch.d.ts.map +0 -1
  61. package/dist/cli/commands/project/add.d.ts.map +0 -1
  62. package/dist/cli/commands/project/list.d.ts.map +0 -1
  63. package/dist/cli/commands/project/remove.d.ts.map +0 -1
  64. package/dist/cli/commands/push.d.ts.map +0 -1
  65. package/dist/cli/commands/reference/add.d.ts.map +0 -1
  66. package/dist/cli/commands/reference/delete.d.ts.map +0 -1
  67. package/dist/cli/commands/reference/extract.d.ts.map +0 -1
  68. package/dist/cli/commands/reference/list.d.ts.map +0 -1
  69. package/dist/cli/commands/reference/normalize.d.ts.map +0 -1
  70. package/dist/cli/commands/reference/open.d.ts.map +0 -1
  71. package/dist/cli/commands/reference/save.d.ts.map +0 -1
  72. package/dist/cli/commands/reference/search.d.ts.map +0 -1
  73. package/dist/cli/commands/reference/show.d.ts.map +0 -1
  74. package/dist/cli/commands/reference/update-index.d.ts.map +0 -1
  75. package/dist/cli/commands/reference/update.d.ts.map +0 -1
  76. package/dist/cli/commands/report/blocked.d.ts.map +0 -1
  77. package/dist/cli/commands/report/complete.d.ts.map +0 -1
  78. package/dist/cli/commands/report/progress.d.ts.map +0 -1
  79. package/dist/cli/commands/report/start.d.ts.map +0 -1
  80. package/dist/cli/commands/resource/acquire.d.ts.map +0 -1
  81. package/dist/cli/commands/resource/list.d.ts.map +0 -1
  82. package/dist/cli/commands/resource/release.d.ts.map +0 -1
  83. package/dist/cli/commands/resource/wait.d.ts.map +0 -1
  84. package/dist/cli/commands/review.d.ts.map +0 -1
  85. package/dist/cli/commands/session/attach.d.ts.map +0 -1
  86. package/dist/cli/commands/session/await.d.ts.map +0 -1
  87. package/dist/cli/commands/session/complete.d.ts.map +0 -1
  88. package/dist/cli/commands/session/create.d.ts.map +0 -1
  89. package/dist/cli/commands/session/heartbeat.d.ts.map +0 -1
  90. package/dist/cli/commands/session/list.d.ts.map +0 -1
  91. package/dist/cli/commands/session/mark-done.d.ts.map +0 -1
  92. package/dist/cli/commands/session/mine.d.ts.map +0 -1
  93. package/dist/cli/commands/session/replay.d.ts.map +0 -1
  94. package/dist/cli/commands/session/run.d.ts.map +0 -1
  95. package/dist/cli/commands/session/show.d.ts.map +0 -1
  96. package/dist/cli/commands/session/start.d.ts.map +0 -1
  97. package/dist/cli/commands/session/state/cleanup.d.ts.map +0 -1
  98. package/dist/cli/commands/session/state/end.d.ts.map +0 -1
  99. package/dist/cli/commands/session/state/get.d.ts.map +0 -1
  100. package/dist/cli/commands/session/state/init.d.ts.map +0 -1
  101. package/dist/cli/commands/session/state/list.d.ts.map +0 -1
  102. package/dist/cli/commands/session/state/update.d.ts.map +0 -1
  103. package/dist/cli/commands/session/stop.d.ts.map +0 -1
  104. package/dist/cli/commands/session/view.d.ts.map +0 -1
  105. package/dist/cli/commands/start.d.ts.map +0 -1
  106. package/dist/cli/commands/state/dump.d.ts.map +0 -1
  107. package/dist/cli/commands/status.d.ts.map +0 -1
  108. package/dist/cli/commands/sync.d.ts.map +0 -1
  109. package/dist/cli/commands/trace/export.d.ts.map +0 -1
  110. package/dist/cli/commands/triage/claim.d.ts.map +0 -1
  111. package/dist/cli/commands/triage/list.d.ts.map +0 -1
  112. package/dist/cli/commands/triage/next.d.ts.map +0 -1
  113. package/dist/cli/commands/triage/pull.d.ts.map +0 -1
  114. package/dist/cli/commands/triage/stats.d.ts.map +0 -1
  115. package/dist/cli/commands/tunnel/list.d.ts.map +0 -1
  116. package/dist/cli/commands/tunnel/start.d.ts.map +0 -1
  117. package/dist/cli/commands/tunnel/stop.d.ts.map +0 -1
  118. package/dist/cli/commands/tunnel/url.d.ts.map +0 -1
  119. package/dist/cli/commands/web/start.d.ts.map +0 -1
  120. package/dist/cli/commands/windows/context.d.ts.map +0 -1
  121. package/dist/cli/commands/windows/focus.d.ts.map +0 -1
  122. package/dist/cli/commands/windows/list.d.ts.map +0 -1
  123. package/dist/cli/commands/windows/map.d.ts.map +0 -1
  124. package/dist/cli/commands/windows/read.d.ts.map +0 -1
  125. package/dist/cli/commands/windows/search.d.ts.map +0 -1
  126. package/dist/cli/commands/windows/show.d.ts.map +0 -1
  127. package/dist/cli/commands/windows/watch.d.ts.map +0 -1
  128. package/dist/lib/active-sessions.d.ts.map +0 -1
  129. package/dist/lib/agent-adapters.d.ts.map +0 -1
  130. package/dist/lib/agent-sessions.d.ts.map +0 -1
  131. package/dist/lib/agent-trace.d.ts.map +0 -1
  132. package/dist/lib/analytics.d.ts.map +0 -1
  133. package/dist/lib/annotations-convex.d.ts.map +0 -1
  134. package/dist/lib/annotations.d.ts.map +0 -1
  135. package/dist/lib/auto/discover.d.ts.map +0 -1
  136. package/dist/lib/auto/ideate.d.ts.map +0 -1
  137. package/dist/lib/auto/spawn.d.ts.map +0 -1
  138. package/dist/lib/auto/workspace.d.ts.map +0 -1
  139. package/dist/lib/backlog.d.ts.map +0 -1
  140. package/dist/lib/backlog.test.d.ts +0 -1
  141. package/dist/lib/backlog.test.js +0 -162
  142. package/dist/lib/config-loader.d.ts.map +0 -1
  143. package/dist/lib/config-sync/adapters/claude.d.ts.map +0 -1
  144. package/dist/lib/config-sync/adapters/codex.d.ts.map +0 -1
  145. package/dist/lib/config-sync/adapters/copilot.d.ts.map +0 -1
  146. package/dist/lib/config-sync/adapters/gemini.d.ts.map +0 -1
  147. package/dist/lib/config-sync/adapters/index.d.ts.map +0 -1
  148. package/dist/lib/config-sync/adapters/opencode.d.ts.map +0 -1
  149. package/dist/lib/config-sync/index.d.ts.map +0 -1
  150. package/dist/lib/config-sync/types.d.ts.map +0 -1
  151. package/dist/lib/config-sync/writer.d.ts.map +0 -1
  152. package/dist/lib/content-sync/index.d.ts.map +0 -1
  153. package/dist/lib/content-sync/types.d.ts.map +0 -1
  154. package/dist/lib/contracts.d.ts.map +0 -1
  155. package/dist/lib/convex.d.ts.map +0 -1
  156. package/dist/lib/device.d.ts.map +0 -1
  157. package/dist/lib/digest/index.d.ts.map +0 -1
  158. package/dist/lib/docs/lint.d.ts.map +0 -1
  159. package/dist/lib/docs/lint.test.d.ts +0 -1
  160. package/dist/lib/docs/lint.test.js +0 -120
  161. package/dist/lib/docs/sync.d.ts.map +0 -1
  162. package/dist/lib/doctor/index.d.ts.map +0 -1
  163. package/dist/lib/doctor/repos.d.ts.map +0 -1
  164. package/dist/lib/doctor/templates.d.ts.map +0 -1
  165. package/dist/lib/errors.d.ts.map +0 -1
  166. package/dist/lib/events.d.ts.map +0 -1
  167. package/dist/lib/heartbeat.d.ts.map +0 -1
  168. package/dist/lib/heartbeat.test.d.ts +0 -1
  169. package/dist/lib/heartbeat.test.js +0 -124
  170. package/dist/lib/hooks/adapters/claude.d.ts.map +0 -1
  171. package/dist/lib/hooks/adapters/codex.d.ts.map +0 -1
  172. package/dist/lib/hooks/adapters/copilot.d.ts.map +0 -1
  173. package/dist/lib/hooks/context.d.ts.map +0 -1
  174. package/dist/lib/hooks/index.d.ts.map +0 -1
  175. package/dist/lib/hooks/registry.d.ts.map +0 -1
  176. package/dist/lib/hooks/runner.d.ts.map +0 -1
  177. package/dist/lib/hooks/types.d.ts.map +0 -1
  178. package/dist/lib/index.test.d.ts +0 -1
  179. package/dist/lib/index.test.js +0 -334
  180. package/dist/lib/managed-session.d.ts.map +0 -1
  181. package/dist/lib/math.d.ts.map +0 -1
  182. package/dist/lib/math.test.d.ts +0 -1
  183. package/dist/lib/math.test.js +0 -238
  184. package/dist/lib/ngrok.d.ts.map +0 -1
  185. package/dist/lib/nvim/discovery.d.ts.map +0 -1
  186. package/dist/lib/nvim/discovery.test.d.ts +0 -1
  187. package/dist/lib/nvim/discovery.test.js +0 -131
  188. package/dist/lib/nvim/index.d.ts.map +0 -1
  189. package/dist/lib/nvim/remote.d.ts.map +0 -1
  190. package/dist/lib/nvim/remote.test.d.ts +0 -1
  191. package/dist/lib/nvim/remote.test.js +0 -18
  192. package/dist/lib/panes/broker.d.ts.map +0 -1
  193. package/dist/lib/panes/index.d.ts.map +0 -1
  194. package/dist/lib/panes/server.d.ts.map +0 -1
  195. package/dist/lib/preview/detect.d.ts.map +0 -1
  196. package/dist/lib/preview/index.d.ts.map +0 -1
  197. package/dist/lib/preview/manager.d.ts.map +0 -1
  198. package/dist/lib/preview/schema.d.ts.map +0 -1
  199. package/dist/lib/preview/sprite.d.ts.map +0 -1
  200. package/dist/lib/preview/watcher.d.ts.map +0 -1
  201. package/dist/lib/process/index.d.ts.map +0 -1
  202. package/dist/lib/process/snapshot.d.ts.map +0 -1
  203. package/dist/lib/process/snapshot.test.d.ts +0 -1
  204. package/dist/lib/process/snapshot.test.js +0 -127
  205. package/dist/lib/project-identity.d.ts.map +0 -1
  206. package/dist/lib/provider-auth.d.ts.map +0 -1
  207. package/dist/lib/references.d.ts.map +0 -1
  208. package/dist/lib/report.d.ts.map +0 -1
  209. package/dist/lib/resources.d.ts.map +0 -1
  210. package/dist/lib/resources.test.d.ts +0 -1
  211. package/dist/lib/resources.test.js +0 -94
  212. package/dist/lib/runner.d.ts.map +0 -1
  213. package/dist/lib/runner.test.d.ts +0 -1
  214. package/dist/lib/runner.test.js +0 -234
  215. package/dist/lib/session-artifacts.d.ts.map +0 -1
  216. package/dist/lib/session-manager.d.ts.map +0 -1
  217. package/dist/lib/session-manager.test.d.ts +0 -1
  218. package/dist/lib/session-manager.test.js +0 -310
  219. package/dist/lib/session-result.d.ts.map +0 -1
  220. package/dist/lib/session-state.d.ts.map +0 -1
  221. package/dist/lib/slack-workspace.d.ts.map +0 -1
  222. package/dist/lib/tmux/bridge.d.ts.map +0 -1
  223. package/dist/lib/tmux/context.d.ts.map +0 -1
  224. package/dist/lib/tmux/context.test.d.ts +0 -1
  225. package/dist/lib/tmux/context.test.js +0 -215
  226. package/dist/lib/tmux/index.d.ts.map +0 -1
  227. package/dist/lib/tmux/map.d.ts.map +0 -1
  228. package/dist/lib/tmux/map.test.d.ts +0 -1
  229. package/dist/lib/tmux/map.test.js +0 -80
  230. package/dist/lib/tmux/panes.d.ts.map +0 -1
  231. package/dist/lib/tmux/redaction.d.ts.map +0 -1
  232. package/dist/lib/tmux/redaction.test.d.ts +0 -1
  233. package/dist/lib/tmux/redaction.test.js +0 -183
  234. package/dist/lib/triage-llm.d.ts.map +0 -1
  235. package/dist/lib/triage-tracker.d.ts.map +0 -1
  236. package/dist/lib/triage.d.ts.map +0 -1
  237. package/dist/lib/types.d.ts.map +0 -1
  238. package/dist/lib/windows/index.d.ts.map +0 -1
  239. package/dist/lib/windows/inventory.d.ts.map +0 -1
  240. package/dist/lib/windows/inventory.test.d.ts +0 -1
  241. package/dist/lib/windows/inventory.test.js +0 -292
  242. package/dist/lib/windows/types.d.ts.map +0 -1
  243. package/dist/lib.d.ts.map +0 -1
  244. package/dist/web/app/@overlay/default.d.ts +0 -1
  245. package/dist/web/app/@overlay/default.js +0 -3
  246. package/dist/web/app/about/page.d.ts +0 -1
  247. package/dist/web/app/about/page.js +0 -6
  248. package/dist/web/app/layout.d.ts +0 -7
  249. package/dist/web/app/layout.js +0 -19
  250. package/dist/web/app/page.d.ts +0 -1
  251. package/dist/web/app/page.js +0 -38
  252. package/dist/web/app/settings/page.d.ts +0 -1
  253. package/dist/web/app/settings/page.js +0 -6
  254. package/dist/web/app/shortcuts/page.d.ts +0 -1
  255. package/dist/web/app/shortcuts/page.js +0 -6
  256. package/dist/web/atoms/sidebar.d.ts +0 -16
  257. package/dist/web/atoms/sidebar.js +0 -58
  258. package/dist/web/atoms/state.d.ts +0 -24
  259. package/dist/web/atoms/state.js +0 -43
  260. package/dist/web/components/command-palette.d.ts +0 -6
  261. package/dist/web/components/command-palette.js +0 -297
  262. package/dist/web/components/main-view.d.ts +0 -1
  263. package/dist/web/components/main-view.js +0 -93
  264. package/dist/web/components/overlay/page-overlay.d.ts +0 -16
  265. package/dist/web/components/overlay/page-overlay.js +0 -84
  266. package/dist/web/components/pane-view.d.ts +0 -5
  267. package/dist/web/components/pane-view.js +0 -168
  268. package/dist/web/components/project-files-view.d.ts +0 -6
  269. package/dist/web/components/project-files-view.js +0 -205
  270. package/dist/web/components/project-planning-view.d.ts +0 -6
  271. package/dist/web/components/project-planning-view.js +0 -146
  272. package/dist/web/components/session-view.d.ts +0 -6
  273. package/dist/web/components/session-view.js +0 -211
  274. package/dist/web/components/sessions-list-view.d.ts +0 -1
  275. package/dist/web/components/sessions-list-view.js +0 -118
  276. package/dist/web/components/sidebar/index.d.ts +0 -9
  277. package/dist/web/components/sidebar/index.js +0 -29
  278. package/dist/web/components/sidebar/kbd.d.ts +0 -17
  279. package/dist/web/components/sidebar/kbd.js +0 -47
  280. package/dist/web/components/sidebar/nav-group.d.ts +0 -22
  281. package/dist/web/components/sidebar/nav-group.js +0 -43
  282. package/dist/web/components/sidebar/nav-item.d.ts +0 -17
  283. package/dist/web/components/sidebar/nav-item.js +0 -38
  284. package/dist/web/components/sidebar/sidebar-header.d.ts +0 -9
  285. package/dist/web/components/sidebar/sidebar-header.js +0 -18
  286. package/dist/web/components/sidebar/sidebar-nav.d.ts +0 -7
  287. package/dist/web/components/sidebar/sidebar-nav.js +0 -505
  288. package/dist/web/components/sidebar/sidebar-search.d.ts +0 -7
  289. package/dist/web/components/sidebar/sidebar-search.js +0 -18
  290. package/dist/web/components/sidebar/sidebar-settings.d.ts +0 -4
  291. package/dist/web/components/sidebar/sidebar-settings.js +0 -28
  292. package/dist/web/components/sidebar/sidebar-transition.d.ts +0 -12
  293. package/dist/web/components/sidebar/sidebar-transition.js +0 -58
  294. package/dist/web/components/status-bar.d.ts +0 -1
  295. package/dist/web/components/status-bar.js +0 -53
  296. package/dist/web/components/terminal.d.ts +0 -4
  297. package/dist/web/components/terminal.js +0 -324
  298. package/dist/web/components/toast.d.ts +0 -7
  299. package/dist/web/components/toast.js +0 -72
  300. package/dist/web/hooks/use-keybindings.d.ts +0 -30
  301. package/dist/web/hooks/use-keybindings.js +0 -322
  302. package/dist/web/hooks/use-state.d.ts +0 -11
  303. package/dist/web/hooks/use-state.js +0 -84
  304. package/dist/web/lib/api.d.ts +0 -179
  305. package/dist/web/lib/api.js +0 -79
  306. package/dist/web/lib/paths.d.ts +0 -2
  307. package/dist/web/lib/paths.js +0 -26
  308. package/dist/web/lib/utils.d.ts +0 -2
  309. package/dist/web/lib/utils.js +0 -5
  310. package/dist/web/lib/ws.d.ts +0 -18
  311. package/dist/web/lib/ws.js +0 -138
  312. package/dist/web/next.config.d.ts +0 -3
  313. package/dist/web/next.config.js +0 -9
  314. package/scripts/generate-manifest.ts +0 -44
  315. package/src/cli/base-command.ts +0 -233
  316. package/src/cli/commands/__tests__/annotations.test.ts +0 -704
  317. package/src/cli/commands/__tests__/bridge.test.ts +0 -101
  318. package/src/cli/commands/__tests__/daemon.test.ts +0 -79
  319. package/src/cli/commands/agent/list.ts +0 -75
  320. package/src/cli/commands/annotation/ack.ts +0 -37
  321. package/src/cli/commands/annotation/create.ts +0 -67
  322. package/src/cli/commands/annotation/events.ts +0 -63
  323. package/src/cli/commands/annotation/export.ts +0 -67
  324. package/src/cli/commands/annotation/import.ts +0 -98
  325. package/src/cli/commands/annotation/ingest.ts +0 -112
  326. package/src/cli/commands/annotation/list.ts +0 -57
  327. package/src/cli/commands/annotation/reply.ts +0 -46
  328. package/src/cli/commands/annotation/resolve.ts +0 -37
  329. package/src/cli/commands/auto/index.ts +0 -755
  330. package/src/cli/commands/backlog/add.ts +0 -74
  331. package/src/cli/commands/backlog/claim.ts +0 -53
  332. package/src/cli/commands/backlog/complete.ts +0 -51
  333. package/src/cli/commands/backlog/list.ts +0 -107
  334. package/src/cli/commands/backlog/pick.ts +0 -50
  335. package/src/cli/commands/backlog/sync.ts +0 -131
  336. package/src/cli/commands/bootstrap.ts +0 -205
  337. package/src/cli/commands/bridge.ts +0 -233
  338. package/src/cli/commands/context/inject.ts +0 -103
  339. package/src/cli/commands/context/list.ts +0 -112
  340. package/src/cli/commands/context/publish.ts +0 -83
  341. package/src/cli/commands/context/read.ts +0 -85
  342. package/src/cli/commands/daemon.ts +0 -1809
  343. package/src/cli/commands/digest/index.ts +0 -245
  344. package/src/cli/commands/docs/lint.ts +0 -93
  345. package/src/cli/commands/docs/sync.ts +0 -90
  346. package/src/cli/commands/doctor.ts +0 -267
  347. package/src/cli/commands/find/index.ts +0 -313
  348. package/src/cli/commands/history/index.ts +0 -269
  349. package/src/cli/commands/hooks/guard.ts +0 -71
  350. package/src/cli/commands/hooks/list.ts +0 -139
  351. package/src/cli/commands/hooks/lock.ts +0 -47
  352. package/src/cli/commands/hooks/status.ts +0 -56
  353. package/src/cli/commands/hooks/test.ts +0 -190
  354. package/src/cli/commands/hooks/unlock.ts +0 -56
  355. package/src/cli/commands/list.e2e.test.ts +0 -58
  356. package/src/cli/commands/list.ts +0 -96
  357. package/src/cli/commands/login.ts +0 -236
  358. package/src/cli/commands/logout.ts +0 -45
  359. package/src/cli/commands/panes/broker.ts +0 -68
  360. package/src/cli/commands/panes/pipe-sink.ts +0 -101
  361. package/src/cli/commands/panes/snapshot.ts +0 -156
  362. package/src/cli/commands/plan.e2e.test.ts +0 -90
  363. package/src/cli/commands/plan.ts +0 -68
  364. package/src/cli/commands/preview/index.ts +0 -282
  365. package/src/cli/commands/preview/list.ts +0 -116
  366. package/src/cli/commands/preview/status.ts +0 -137
  367. package/src/cli/commands/preview/stop.ts +0 -165
  368. package/src/cli/commands/project/add.ts +0 -110
  369. package/src/cli/commands/project/list.ts +0 -136
  370. package/src/cli/commands/project/remove.ts +0 -60
  371. package/src/cli/commands/push.ts +0 -115
  372. package/src/cli/commands/reference/add.ts +0 -266
  373. package/src/cli/commands/reference/delete.ts +0 -67
  374. package/src/cli/commands/reference/extract.ts +0 -389
  375. package/src/cli/commands/reference/list.ts +0 -117
  376. package/src/cli/commands/reference/normalize.ts +0 -90
  377. package/src/cli/commands/reference/open.ts +0 -92
  378. package/src/cli/commands/reference/save.ts +0 -103
  379. package/src/cli/commands/reference/search.ts +0 -85
  380. package/src/cli/commands/reference/show.ts +0 -174
  381. package/src/cli/commands/reference/update-index.ts +0 -103
  382. package/src/cli/commands/reference/update.ts +0 -136
  383. package/src/cli/commands/report/blocked.ts +0 -165
  384. package/src/cli/commands/report/complete.ts +0 -179
  385. package/src/cli/commands/report/progress.ts +0 -142
  386. package/src/cli/commands/report/start.ts +0 -140
  387. package/src/cli/commands/resource/acquire.ts +0 -116
  388. package/src/cli/commands/resource/list.ts +0 -77
  389. package/src/cli/commands/resource/release.ts +0 -64
  390. package/src/cli/commands/resource/wait.ts +0 -93
  391. package/src/cli/commands/review.ts +0 -105
  392. package/src/cli/commands/session/attach.ts +0 -200
  393. package/src/cli/commands/session/await.ts +0 -83
  394. package/src/cli/commands/session/complete.ts +0 -100
  395. package/src/cli/commands/session/create.ts +0 -92
  396. package/src/cli/commands/session/heartbeat.ts +0 -63
  397. package/src/cli/commands/session/list.ts +0 -281
  398. package/src/cli/commands/session/mark-done.ts +0 -132
  399. package/src/cli/commands/session/mine.ts +0 -189
  400. package/src/cli/commands/session/replay.ts +0 -659
  401. package/src/cli/commands/session/run.ts +0 -44
  402. package/src/cli/commands/session/show.ts +0 -177
  403. package/src/cli/commands/session/start.ts +0 -580
  404. package/src/cli/commands/session/state/cleanup.ts +0 -61
  405. package/src/cli/commands/session/state/end.ts +0 -47
  406. package/src/cli/commands/session/state/get.ts +0 -65
  407. package/src/cli/commands/session/state/init.ts +0 -50
  408. package/src/cli/commands/session/state/list.ts +0 -68
  409. package/src/cli/commands/session/state/update.ts +0 -108
  410. package/src/cli/commands/session/stop.ts +0 -134
  411. package/src/cli/commands/session/view.ts +0 -186
  412. package/src/cli/commands/start.ts +0 -256
  413. package/src/cli/commands/state/dump.ts +0 -449
  414. package/src/cli/commands/status.ts +0 -244
  415. package/src/cli/commands/sync.ts +0 -174
  416. package/src/cli/commands/trace/export.ts +0 -255
  417. package/src/cli/commands/triage/claim.ts +0 -203
  418. package/src/cli/commands/triage/list.ts +0 -137
  419. package/src/cli/commands/triage/next.ts +0 -73
  420. package/src/cli/commands/triage/pull.ts +0 -97
  421. package/src/cli/commands/triage/stats.ts +0 -82
  422. package/src/cli/commands/tunnel/list.ts +0 -113
  423. package/src/cli/commands/tunnel/start.ts +0 -122
  424. package/src/cli/commands/tunnel/stop.ts +0 -108
  425. package/src/cli/commands/tunnel/url.ts +0 -82
  426. package/src/cli/commands/web/start.ts +0 -125
  427. package/src/cli/commands/windows/context.ts +0 -439
  428. package/src/cli/commands/windows/focus.ts +0 -130
  429. package/src/cli/commands/windows/list.ts +0 -213
  430. package/src/cli/commands/windows/map.ts +0 -223
  431. package/src/cli/commands/windows/read.ts +0 -279
  432. package/src/cli/commands/windows/search.ts +0 -219
  433. package/src/cli/commands/windows/show.ts +0 -188
  434. package/src/cli/commands/windows/watch.ts +0 -262
  435. package/src/lib/__tests__/annotations-convex.test.ts +0 -104
  436. package/src/lib/active-sessions.ts +0 -1486
  437. package/src/lib/agent-adapters.ts +0 -412
  438. package/src/lib/agent-sessions.ts +0 -671
  439. package/src/lib/agent-trace.test.ts +0 -296
  440. package/src/lib/agent-trace.ts +0 -513
  441. package/src/lib/analytics.ts +0 -178
  442. package/src/lib/annotations-convex.ts +0 -296
  443. package/src/lib/annotations.test.ts +0 -274
  444. package/src/lib/annotations.ts +0 -836
  445. package/src/lib/auto/discover.ts +0 -545
  446. package/src/lib/auto/ideate.ts +0 -412
  447. package/src/lib/auto/spawn.ts +0 -549
  448. package/src/lib/auto/workspace.ts +0 -282
  449. package/src/lib/backlog.test.ts +0 -194
  450. package/src/lib/backlog.ts +0 -428
  451. package/src/lib/config-loader.ts +0 -391
  452. package/src/lib/config-sync/adapters/claude.ts +0 -91
  453. package/src/lib/config-sync/adapters/codex.ts +0 -135
  454. package/src/lib/config-sync/adapters/copilot.ts +0 -98
  455. package/src/lib/config-sync/adapters/gemini.ts +0 -86
  456. package/src/lib/config-sync/adapters/index.ts +0 -39
  457. package/src/lib/config-sync/adapters/opencode.ts +0 -94
  458. package/src/lib/config-sync/index.ts +0 -399
  459. package/src/lib/config-sync/types.ts +0 -92
  460. package/src/lib/config-sync/writer.ts +0 -188
  461. package/src/lib/content-sync/index.ts +0 -882
  462. package/src/lib/content-sync/types.ts +0 -104
  463. package/src/lib/contracts.test.ts +0 -186
  464. package/src/lib/contracts.ts +0 -195
  465. package/src/lib/convex.ts +0 -54
  466. package/src/lib/device.ts +0 -41
  467. package/src/lib/digest/index.ts +0 -529
  468. package/src/lib/docs/lint.test.ts +0 -135
  469. package/src/lib/docs/lint.ts +0 -310
  470. package/src/lib/docs/sync.ts +0 -184
  471. package/src/lib/doctor/index.ts +0 -647
  472. package/src/lib/doctor/repos.ts +0 -381
  473. package/src/lib/doctor/templates.ts +0 -191
  474. package/src/lib/errors.ts +0 -111
  475. package/src/lib/events.ts +0 -479
  476. package/src/lib/heartbeat.test.ts +0 -164
  477. package/src/lib/heartbeat.ts +0 -326
  478. package/src/lib/hooks/adapters/claude.ts +0 -115
  479. package/src/lib/hooks/adapters/codex.ts +0 -92
  480. package/src/lib/hooks/adapters/copilot.ts +0 -141
  481. package/src/lib/hooks/context.ts +0 -174
  482. package/src/lib/hooks/index.ts +0 -39
  483. package/src/lib/hooks/registry.ts +0 -101
  484. package/src/lib/hooks/runner.ts +0 -208
  485. package/src/lib/hooks/types.ts +0 -89
  486. package/src/lib/index.test.ts +0 -426
  487. package/src/lib/managed-session.ts +0 -117
  488. package/src/lib/math.test.ts +0 -299
  489. package/src/lib/math.ts +0 -120
  490. package/src/lib/ngrok.ts +0 -441
  491. package/src/lib/nvim/discovery.test.ts +0 -157
  492. package/src/lib/nvim/discovery.ts +0 -181
  493. package/src/lib/nvim/index.ts +0 -28
  494. package/src/lib/nvim/remote.test.ts +0 -21
  495. package/src/lib/nvim/remote.ts +0 -184
  496. package/src/lib/panes/README.md +0 -20
  497. package/src/lib/panes/broker.ts +0 -261
  498. package/src/lib/panes/index.ts +0 -1
  499. package/src/lib/panes/server.ts +0 -379
  500. package/src/lib/preview/detect.ts +0 -184
  501. package/src/lib/preview/index.ts +0 -1
  502. package/src/lib/process/index.ts +0 -16
  503. package/src/lib/process/snapshot.test.ts +0 -188
  504. package/src/lib/process/snapshot.ts +0 -257
  505. package/src/lib/provider-auth.ts +0 -258
  506. package/src/lib/references.ts +0 -481
  507. package/src/lib/report.ts +0 -973
  508. package/src/lib/resources.test.ts +0 -132
  509. package/src/lib/resources.ts +0 -429
  510. package/src/lib/runner.test.ts +0 -288
  511. package/src/lib/runner.ts +0 -1223
  512. package/src/lib/session-artifacts.test.ts +0 -107
  513. package/src/lib/session-artifacts.ts +0 -193
  514. package/src/lib/session-manager.test.ts +0 -402
  515. package/src/lib/session-manager.ts +0 -150
  516. package/src/lib/session-result.test.ts +0 -98
  517. package/src/lib/session-result.ts +0 -262
  518. package/src/lib/session-state.ts +0 -470
  519. package/src/lib/slack-workspace.ts +0 -25
  520. package/src/lib/tmux/bridge.ts +0 -439
  521. package/src/lib/tmux/context.test.ts +0 -242
  522. package/src/lib/tmux/context.ts +0 -380
  523. package/src/lib/tmux/index.ts +0 -46
  524. package/src/lib/tmux/map.test.ts +0 -99
  525. package/src/lib/tmux/map.ts +0 -252
  526. package/src/lib/tmux/panes.ts +0 -170
  527. package/src/lib/tmux/redaction.test.ts +0 -231
  528. package/src/lib/tmux/redaction.ts +0 -201
  529. package/src/lib/triage-llm.ts +0 -312
  530. package/src/lib/triage-tracker.ts +0 -400
  531. package/src/lib/triage.ts +0 -655
  532. package/src/lib/types.ts +0 -61
  533. package/src/lib/windows/index.ts +0 -2
  534. package/src/lib/windows/inventory.test.ts +0 -370
  535. package/src/lib/windows/inventory.ts +0 -352
  536. package/src/lib/windows/types.ts +0 -46
  537. package/src/lib.ts +0 -260
package/src/lib/runner.ts DELETED
@@ -1,1223 +0,0 @@
1
- /**
2
- * Runner/Supervisor process for agent sessions.
3
- *
4
- * This module implements the "runner" pattern:
5
- * - Runner owns the agent child process
6
- * - Captures stdout/stderr to log files
7
- * - Updates session status on process exit
8
- * - Writes canonical *-result.json envelope
9
- * - Writes legacy exit/output files for compatibility
10
- *
11
- * This avoids the broken pattern of:
12
- * - detached + unref (CLI exits, close handler dies)
13
- * - bun -e inline watcher scripts (syntax issues)
14
- */
15
-
16
- import { type ChildProcess, spawn, spawnSync } from "node:child_process";
17
- import { randomUUID } from "node:crypto";
18
- import {
19
- createReadStream,
20
- createWriteStream,
21
- existsSync,
22
- mkdirSync,
23
- readdirSync,
24
- readFileSync,
25
- renameSync,
26
- statSync,
27
- type WriteStream,
28
- writeFileSync,
29
- } from "node:fs";
30
- import { homedir } from "node:os";
31
- import { dirname, join } from "node:path";
32
- import { pathToFileURL } from "node:url";
33
- import type { ActiveSession, AgentType } from "./active-sessions.js";
34
- import { SessionArtifactStore } from "./session-artifacts.js";
35
- import { buildSessionResult, type SessionResult } from "./session-result.js";
36
-
37
- /**
38
- * Runner configuration passed via environment.
39
- */
40
- export interface RunnerConfig {
41
- sessionId: string;
42
- sessionPath: string;
43
- promptPath: string;
44
- outputPath: string;
45
- resultPath: string;
46
- stdoutPath: string;
47
- stderrPath: string;
48
- agent: AgentType;
49
- model?: string;
50
- }
51
-
52
- /**
53
- * Exit info written to exit.json.
54
- */
55
- export interface ExitInfo {
56
- exitCode: number | null;
57
- signal: NodeJS.Signals | null;
58
- endedAt: string;
59
- }
60
-
61
- interface BraintrustSpanLike {
62
- end(args?: { endTime?: number }): number;
63
- flush(): Promise<void>;
64
- log(event: {
65
- error?: unknown;
66
- input?: unknown;
67
- metadata?: Record<string, unknown>;
68
- output?: unknown;
69
- }): void;
70
- permalink(): Promise<string>;
71
- }
72
-
73
- interface BraintrustLoggerLike {
74
- flush(): Promise<void>;
75
- startSpan(args?: {
76
- event?: {
77
- error?: unknown;
78
- input?: unknown;
79
- metadata?: Record<string, unknown>;
80
- output?: unknown;
81
- };
82
- name?: string;
83
- }): BraintrustSpanLike;
84
- }
85
-
86
- interface BraintrustTracingModuleLike {
87
- createBraintrustLogger: (projectNameOrConfig: {
88
- apiKey?: string;
89
- appUrl?: string;
90
- projectName: string;
91
- } | string) => BraintrustLoggerLike | null;
92
- }
93
-
94
- function normalizeNonEmpty(value?: string | null): string | undefined {
95
- const next = value?.trim();
96
- return next ? next : undefined;
97
- }
98
-
99
- function resolveSharedPackagesRoot(): string {
100
- return process.env.LNITTMAN_PACKAGES_ROOT || "/Users/luke/Developer/packages";
101
- }
102
-
103
- function readFileUtf8IfExists(path: string): string {
104
- try {
105
- if (!existsSync(path)) return "";
106
- return readFileSync(path, "utf-8");
107
- } catch {
108
- return "";
109
- }
110
- }
111
-
112
- async function loadBraintrustTracingModule(): Promise<BraintrustTracingModuleLike | null> {
113
- const fallbackPath = pathToFileURL(
114
- join(resolveSharedPackagesRoot(), "evals", "dist", "tracing.js"),
115
- ).href;
116
- const candidates = ["@lnittman/evals/tracing", fallbackPath];
117
-
118
- for (const candidate of candidates) {
119
- try {
120
- const mod = await import(candidate);
121
- if (typeof mod?.createBraintrustLogger === "function") {
122
- return mod as BraintrustTracingModuleLike;
123
- }
124
- } catch {
125
- // Try next candidate.
126
- }
127
- }
128
-
129
- return null;
130
- }
131
-
132
- async function traceSessionRunToBraintrust(input: {
133
- artifacts: string[];
134
- config: RunnerConfig;
135
- endedAt: string;
136
- exitCode: number | null;
137
- outputContent: string;
138
- session: ActiveSession;
139
- status: SessionResult["status"];
140
- }): Promise<string | undefined> {
141
- const apiKey = normalizeNonEmpty(process.env.BRAINTRUST_API_KEY);
142
- if (!apiKey) return undefined;
143
-
144
- const projectName =
145
- normalizeNonEmpty(process.env.BRAINTRUST_PROJECT_NAME) ||
146
- normalizeNonEmpty(process.env.AGENTS_PROJECT) ||
147
- normalizeNonEmpty(input.session.project);
148
- if (!projectName) return undefined;
149
-
150
- const tracing = await loadBraintrustTracingModule();
151
- if (!tracing) return undefined;
152
-
153
- const logger = tracing.createBraintrustLogger({
154
- apiKey,
155
- appUrl: normalizeNonEmpty(process.env.BRAINTRUST_APP_URL),
156
- projectName,
157
- });
158
- if (!logger) return undefined;
159
-
160
- const promptContent = readFileUtf8IfExists(input.config.promptPath);
161
- const traceId = normalizeNonEmpty(input.session.trace_id) || normalizeNonEmpty(process.env.AGENTS_TRACE_ID);
162
-
163
- const span = logger.startSpan({
164
- name: "abbie.session.run",
165
- event: {
166
- input: {
167
- goal: input.session.goal,
168
- prompt: promptContent,
169
- },
170
- metadata: {
171
- agent: input.config.agent,
172
- artifactsCount: input.artifacts.length,
173
- cwd: input.session.cwd,
174
- endedAt: input.endedAt,
175
- exitCode: input.exitCode,
176
- issue: input.session.issue,
177
- model: input.config.model ?? null,
178
- outputPath: input.config.outputPath,
179
- project: input.session.project,
180
- promptPath: input.config.promptPath,
181
- resultPath: input.config.resultPath,
182
- sessionId: input.config.sessionId,
183
- startedAt: input.session.started_at,
184
- status: input.status,
185
- traceId: traceId ?? null,
186
- },
187
- },
188
- });
189
-
190
- span.log({
191
- ...(input.status === "failed" && input.outputContent.trim().length > 0
192
- ? { error: input.outputContent }
193
- : {}),
194
- output: {
195
- artifacts: input.artifacts,
196
- raw: input.outputContent,
197
- },
198
- });
199
- span.end();
200
- await span.flush();
201
- const traceUrl = await span.permalink();
202
- await logger.flush();
203
- return traceUrl;
204
- }
205
-
206
- /**
207
- * Wait for a write stream to finish/close safely.
208
- * Handles: already finished, close without finish, destroyed, errors.
209
- */
210
- function waitForStream(stream: WriteStream): Promise<void> {
211
- return new Promise((resolve, reject) => {
212
- // Already done
213
- if (stream.destroyed || stream.writableFinished) {
214
- resolve();
215
- return;
216
- }
217
-
218
- let settled = false;
219
- const settle = (err?: Error) => {
220
- if (settled) return;
221
- settled = true;
222
- stream.removeListener("finish", onFinish);
223
- stream.removeListener("close", onClose);
224
- stream.removeListener("error", onError);
225
- if (err) reject(err);
226
- else resolve();
227
- };
228
-
229
- const onFinish = () => settle();
230
- const onClose = () => settle(); // close without finish = still done
231
- const onError = (err: Error) => settle(err);
232
-
233
- stream.once("finish", onFinish);
234
- stream.once("close", onClose);
235
- stream.once("error", onError);
236
- });
237
- }
238
-
239
- /**
240
- * Parse runner config from environment.
241
- */
242
- export function parseRunnerConfig(env: NodeJS.ProcessEnv = process.env): RunnerConfig | null {
243
- const sessionId = env.AGENTS_RUNNER_SESSION_ID;
244
- const sessionPath = env.AGENTS_RUNNER_SESSION_PATH;
245
- const promptPath = env.AGENTS_RUNNER_PROMPT_PATH;
246
- const outputPath = env.AGENTS_RUNNER_OUTPUT_PATH;
247
- const resultPathFromEnv = env.AGENTS_RUNNER_RESULT_PATH;
248
- const stdoutPath = env.AGENTS_RUNNER_STDOUT_PATH;
249
- const stderrPath = env.AGENTS_RUNNER_STDERR_PATH;
250
- const agent = env.AGENTS_RUNNER_AGENT as AgentType;
251
- const model = env.AGENTS_RUNNER_MODEL;
252
-
253
- if (!sessionId || !sessionPath || !promptPath || !outputPath || !agent) {
254
- return null;
255
- }
256
-
257
- const defaultResultPath = join(dirname(outputPath), `${sessionId}-result.json`);
258
-
259
- return {
260
- sessionId,
261
- sessionPath,
262
- promptPath,
263
- outputPath,
264
- resultPath: resultPathFromEnv || defaultResultPath,
265
- stdoutPath: stdoutPath || outputPath.replace(/\.json$/, "-stdout.log"),
266
- stderrPath: stderrPath || outputPath.replace(/\.json$/, "-stderr.log"),
267
- agent,
268
- model: model || undefined,
269
- };
270
- }
271
-
272
- /**
273
- * Write JSON atomically (write to .tmp, then rename).
274
- */
275
- function writeJsonAtomic(path: string, data: unknown): void {
276
- const tmpPath = `${path}.tmp`;
277
- writeFileSync(tmpPath, JSON.stringify(data, null, 2));
278
- renameSync(tmpPath, path);
279
- }
280
-
281
- /**
282
- * Update session file atomically.
283
- */
284
- function updateSession(sessionPath: string, updates: Partial<ActiveSession>): ActiveSession | null {
285
- try {
286
- const session: ActiveSession = JSON.parse(readFileSync(sessionPath, "utf-8"));
287
- Object.assign(session, updates);
288
- writeJsonAtomic(sessionPath, session);
289
- return session;
290
- } catch {
291
- return null;
292
- }
293
- }
294
-
295
- /**
296
- * Get agent spawn configuration.
297
- */
298
- function getAgentSpawnConfig(
299
- config: RunnerConfig,
300
- _cwd: string,
301
- ): { command: string; args: string[]; env: Record<string, string>; useStdin: boolean } {
302
- const { agent, sessionId, model } = config;
303
-
304
- switch (agent) {
305
- case "claude": {
306
- // Claude Code 2.1.50+ has a bug where -p (print/pipe) mode hangs
307
- // indefinitely in all non-interactive contexts (stdin pipe, positional
308
- // arg, heredoc). The process connects to the API but never produces
309
- // output. Interactive mode works fine.
310
- //
311
- // Workaround: use `pi` as a relay when available. Pi's -p flag works
312
- // correctly and can target Claude models via --provider anthropic.
313
- // Falls back to direct claude -p if pi is not installed (may hang).
314
- // Locate pi binary: try PATH resolution first, then known NVM location
315
- const piPathFromWhich = spawnSync("which", ["pi"], { stdio: "pipe", encoding: "utf-8" });
316
- const piPath = piPathFromWhich.status === 0
317
- ? piPathFromWhich.stdout.trim()
318
- : join(homedir(), ".nvm", "versions", "node", "v22.22.0", "bin", "pi");
319
- const usePiRelay = existsSync(piPath);
320
-
321
- if (usePiRelay) {
322
- // Relay through pi: reliable non-interactive mode
323
- const piArgs = [
324
- "--no-extensions",
325
- "--provider", "anthropic",
326
- "--model", model || "claude-sonnet-4-20250514",
327
- "-p",
328
- ];
329
- return {
330
- command: piPath,
331
- args: piArgs,
332
- env: {
333
- PI_SESSION_ID: sessionId,
334
- AGENTS_SESSION_ID: sessionId,
335
- },
336
- useStdin: true,
337
- };
338
- }
339
-
340
- // Direct claude fallback (may hang in 2.1.50+)
341
- const claudeSessionId = randomUUID();
342
- const claudePath = join(homedir(), ".local", "bin", "claude");
343
- return {
344
- command: claudePath,
345
- args: [
346
- "-p",
347
- "--dangerously-skip-permissions",
348
- "--output-format",
349
- "text",
350
- "--session-id",
351
- claudeSessionId,
352
- ],
353
- env: { CLAUDE_SESSION_ID: sessionId },
354
- useStdin: true,
355
- };
356
- }
357
-
358
- case "codex": {
359
- const codexPath = join(homedir(), ".local", "bin", "codex");
360
- const codexArgs = [
361
- "exec",
362
- "-",
363
- "--dangerously-bypass-approvals-and-sandbox",
364
- "--skip-git-repo-check",
365
- ];
366
- if (model) {
367
- codexArgs.push("--model", model);
368
- }
369
- // Note: codex 0.98.0's `-o` (--output-last-message) doesn't reliably
370
- // write the response file. Instead we capture stdout like all other agents.
371
- return {
372
- command: codexPath,
373
- args: codexArgs,
374
- env: { CODEX_SESSION_ID: sessionId },
375
- useStdin: true,
376
- };
377
- }
378
-
379
- case "copilot": {
380
- // Copilot needs prompt via -p flag, not stdin
381
- const promptContent = readFileSync(config.promptPath, "utf-8").trim();
382
- const copilotArgs = ["-p", promptContent, "--yolo", "--stream", "off"];
383
- if (model) {
384
- copilotArgs.push("--model", model);
385
- }
386
- return {
387
- command: "copilot",
388
- args: copilotArgs,
389
- env: { COPILOT_SESSION_ID: sessionId },
390
- useStdin: false,
391
- };
392
- }
393
-
394
- case "gemini": {
395
- // Gemini needs prompt via -p flag, not stdin
396
- const promptContent = readFileSync(config.promptPath, "utf-8").trim();
397
- const geminiArgs = ["-p", promptContent];
398
- if (model) {
399
- geminiArgs.push("-m", model);
400
- }
401
-
402
- return {
403
- command: "gemini",
404
- args: geminiArgs,
405
- env: { GEMINI_SESSION_ID: sessionId },
406
- useStdin: false,
407
- };
408
- }
409
-
410
- case "pi": {
411
- // Pi needs prompt via -p flag, not stdin.
412
- // Run with extensions disabled to avoid user-local extension crashes
413
- // leaking into orchestrated agent sessions.
414
- const promptContent = readFileSync(config.promptPath, "utf-8").trim();
415
- const piArgs = ["--no-extensions"];
416
- if (model) {
417
- piArgs.push("--model", model);
418
- } else {
419
- // Stable default for environments where pi's built-in default model
420
- // may not be entitled.
421
- piArgs.push("--provider", "google", "--model", "gemini-2.5-flash-lite");
422
- }
423
- piArgs.push("-p", promptContent);
424
- return {
425
- command: "pi",
426
- args: piArgs,
427
- env: { PI_SESSION_ID: sessionId },
428
- useStdin: false,
429
- };
430
- }
431
-
432
- case "opencode": {
433
- // OpenCode supports run subcommand with JSON output
434
- const promptContent = readFileSync(config.promptPath, "utf-8").trim();
435
- const opencodeArgs = ["run", promptContent, "--format", "json"];
436
- if (model) {
437
- opencodeArgs.push("-m", model);
438
- }
439
- return {
440
- command: "opencode",
441
- args: opencodeArgs,
442
- env: { OPENCODE_SESSION_ID: sessionId },
443
- useStdin: false,
444
- };
445
- }
446
-
447
- case "droid": {
448
- // Factory Droid uses -m for message mode
449
- const promptContent = readFileSync(config.promptPath, "utf-8").trim();
450
- const droidArgs = ["-m", promptContent];
451
- if (model) {
452
- droidArgs.push("--model", model);
453
- }
454
- return {
455
- command: "droid",
456
- args: droidArgs,
457
- env: { DROID_SESSION_ID: sessionId },
458
- useStdin: false,
459
- };
460
- }
461
-
462
- default:
463
- throw new Error(`Unknown agent type: ${agent}`);
464
- }
465
- }
466
-
467
- /**
468
- * Strip ANSI escape codes and terminal control characters from a string.
469
- * Preserves newlines and tabs but removes everything else that would break JSON serialization.
470
- */
471
- function stripControlChars(str: string): string {
472
- // Remove ANSI escape sequences (CSI, OSC, etc.)
473
- const esc = "\u001b";
474
- const bell = "\u0007";
475
- const controlChars = "[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]";
476
- let cleaned = str.replace(new RegExp(`${esc}\\[[0-9;]*[A-Za-z]`, "g"), "");
477
- cleaned = cleaned.replace(new RegExp(`${esc}\\][^${bell}]*${bell}`, "g"), ""); // OSC sequences
478
- cleaned = cleaned.replace(new RegExp(`${esc}[()][AB012]`, "g"), ""); // Character set selection
479
- cleaned = cleaned.replace(
480
- new RegExp(`${esc}[\\x20-\\x2f][\\x30-\\x7e]`, "g"),
481
- "", // Other escape sequences
482
- );
483
- // Remove remaining control chars (except \n \r \t)
484
- cleaned = cleaned.replace(new RegExp(controlChars, "g"), "");
485
- return cleaned;
486
- }
487
-
488
- /**
489
- * Clean agent output: remove leading bullet markers and strip terminal control characters.
490
- */
491
- function cleanAgentOutput(outputPath: string): void {
492
- if (!existsSync(outputPath)) return;
493
- try {
494
- const raw = readFileSync(outputPath, "utf-8");
495
- let cleaned = stripControlChars(raw);
496
- // Remove leading copilot-style bullet markers
497
- cleaned = cleaned.replace(/^\s*(?:●|○|•)\s*/, "");
498
- if (cleaned !== raw) {
499
- writeFileSync(outputPath, cleaned);
500
- }
501
- } catch {
502
- // Best-effort cleanup
503
- }
504
- }
505
-
506
- function isGitRepo(cwd: string): boolean {
507
- const result = spawnSync("git", ["-C", cwd, "rev-parse", "--is-inside-work-tree"], {
508
- stdio: ["ignore", "pipe", "ignore"],
509
- encoding: "utf-8",
510
- });
511
- return result.status === 0 && result.stdout.trim() === "true";
512
- }
513
-
514
- function parseGitFileList(stdout: string): string[] {
515
- return stdout
516
- .split("\n")
517
- .map((line) => line.trim())
518
- .filter((line) => line.length > 0);
519
- }
520
-
521
- function collectGitArtifacts(cwd: string, startCommitSha?: string): string[] {
522
- if (!isGitRepo(cwd)) return [];
523
-
524
- const files = new Set<string>();
525
-
526
- const diffArgs = startCommitSha
527
- ? ["-C", cwd, "diff", "--name-only", "--relative", startCommitSha]
528
- : ["-C", cwd, "diff", "--name-only", "--relative"];
529
-
530
- const diffResult = spawnSync("git", diffArgs, {
531
- stdio: ["ignore", "pipe", "ignore"],
532
- encoding: "utf-8",
533
- });
534
- if (diffResult.status === 0) {
535
- for (const file of parseGitFileList(diffResult.stdout)) {
536
- files.add(file);
537
- }
538
- }
539
-
540
- const untrackedResult = spawnSync(
541
- "git",
542
- ["-C", cwd, "ls-files", "--others", "--exclude-standard"],
543
- {
544
- stdio: ["ignore", "pipe", "ignore"],
545
- encoding: "utf-8",
546
- },
547
- );
548
- if (untrackedResult.status === 0) {
549
- for (const file of parseGitFileList(untrackedResult.stdout)) {
550
- files.add(file);
551
- }
552
- }
553
-
554
- return Array.from(files).sort();
555
- }
556
-
557
- function buildResultEnvelope(input: {
558
- config: RunnerConfig;
559
- session: ActiveSession;
560
- status: SessionResult["status"];
561
- exitCode: number | null;
562
- endedAt: string;
563
- rawOutput: string;
564
- artifacts?: string[];
565
- traceUrl?: string;
566
- }): SessionResult {
567
- return buildSessionResult({
568
- sessionId: input.config.sessionId,
569
- agent: input.config.agent,
570
- status: input.status,
571
- exitCode: input.exitCode,
572
- startedAt: input.session.started_at,
573
- endedAt: input.endedAt,
574
- rawOutput: input.rawOutput,
575
- artifacts: input.artifacts,
576
- traceUrl: input.traceUrl,
577
- });
578
- }
579
-
580
- function readCopilotFailureDiagnostic(startedAtIso: string): string {
581
- const logsDir = join(homedir(), ".copilot", "logs");
582
- if (!existsSync(logsDir)) return "";
583
-
584
- let entries: { path: string; mtimeMs: number }[] = [];
585
- try {
586
- entries = readdirSync(logsDir)
587
- .filter((name) => name.endsWith(".log") && name.startsWith("process-"))
588
- .map((name) => {
589
- const path = join(logsDir, name);
590
- const mtimeMs = statSync(path).mtimeMs;
591
- return { path, mtimeMs };
592
- })
593
- .sort((a, b) => b.mtimeMs - a.mtimeMs)
594
- .slice(0, 5);
595
- } catch {
596
- return "";
597
- }
598
-
599
- if (entries.length === 0) return "";
600
-
601
- const startedAtMs = Date.parse(startedAtIso);
602
- for (const entry of entries) {
603
- if (Number.isFinite(startedAtMs) && entry.mtimeMs < startedAtMs - 60_000) {
604
- continue;
605
- }
606
-
607
- try {
608
- const content = readFileSync(entry.path, "utf-8");
609
- const lines = content
610
- .split(/\r?\n/)
611
- .map((line) => line.trim())
612
- .filter(Boolean);
613
-
614
- if (lines.length === 0) continue;
615
-
616
- const signalLines = lines.filter(
617
- (line) =>
618
- line.includes("Error loading models") ||
619
- line.includes("Failed to list models") ||
620
- line.includes("OAuth authentication failed") ||
621
- line.includes("requires authentication"),
622
- );
623
-
624
- const selected = signalLines.length > 0 ? signalLines.slice(-4) : lines.slice(-4);
625
- if (selected.length === 0) continue;
626
-
627
- return [
628
- "copilot exited without output.",
629
- `diagnostic source: ${entry.path}`,
630
- ...selected,
631
- ].join("\n");
632
- } catch {
633
- // Try next candidate
634
- }
635
- }
636
-
637
- return "";
638
- }
639
-
640
- /**
641
- * Run the agent as a supervised child process.
642
- * This function is called by the runner process.
643
- */
644
- export async function runAgent(config: RunnerConfig): Promise<number> {
645
- const { sessionPath, promptPath, outputPath, resultPath, stdoutPath, stderrPath, agent } = config;
646
- const artifactStore = new SessionArtifactStore();
647
-
648
- // Read session to get cwd
649
- let session: ActiveSession;
650
- try {
651
- session = JSON.parse(readFileSync(sessionPath, "utf-8"));
652
- } catch (err) {
653
- console.error(`Failed to read session: ${err}`);
654
- const endedAt = new Date().toISOString();
655
- writeJsonAtomic(
656
- resultPath,
657
- buildSessionResult({
658
- sessionId: config.sessionId,
659
- agent: config.agent,
660
- status: "failed",
661
- exitCode: 1,
662
- startedAt: endedAt,
663
- endedAt,
664
- rawOutput: "",
665
- artifacts: [],
666
- }),
667
- );
668
- return 1;
669
- }
670
-
671
- const cwd = session.cwd;
672
-
673
- // Ensure output directories exist (including stderr which may differ)
674
- try {
675
- mkdirSync(dirname(outputPath), { recursive: true });
676
- mkdirSync(dirname(resultPath), { recursive: true });
677
- mkdirSync(dirname(stdoutPath), { recursive: true });
678
- mkdirSync(dirname(stderrPath), { recursive: true });
679
- } catch (err) {
680
- console.error(`Failed to create output directories: ${err}`);
681
- updateSession(sessionPath, { status: "failed", exit_code: 1 });
682
- const endedAt = new Date().toISOString();
683
- writeJsonAtomic(
684
- resultPath,
685
- buildResultEnvelope({
686
- config,
687
- session,
688
- status: "failed",
689
- exitCode: 1,
690
- endedAt,
691
- rawOutput: "",
692
- artifacts: [],
693
- }),
694
- );
695
- return 1;
696
- }
697
-
698
- // Get spawn configuration
699
- let spawnConfig: ReturnType<typeof getAgentSpawnConfig>;
700
- try {
701
- spawnConfig = getAgentSpawnConfig(config, cwd);
702
- } catch (err) {
703
- console.error(`Failed to get agent spawn config: ${err}`);
704
- updateSession(sessionPath, { status: "failed", exit_code: 1 });
705
- const endedAt = new Date().toISOString();
706
- writeJsonAtomic(
707
- resultPath,
708
- buildResultEnvelope({
709
- config,
710
- session,
711
- status: "failed",
712
- exitCode: 1,
713
- endedAt,
714
- rawOutput: "",
715
- artifacts: collectGitArtifacts(cwd, session.start_commit_sha),
716
- }),
717
- );
718
- return 1;
719
- }
720
-
721
- // Ensure PATH includes user bin directories
722
- const localBin = join(homedir(), ".local", "bin");
723
- const pathWithLocalBin = process.env.PATH?.includes(localBin)
724
- ? process.env.PATH
725
- : `${localBin}:${process.env.PATH ?? ""}`;
726
-
727
- // Update session to running with our PID (runner PID is stable)
728
- updateSession(sessionPath, {
729
- status: "running",
730
- pid: process.pid,
731
- runner_pid: process.pid,
732
- });
733
-
734
- // Emit session:started progress event (best-effort, non-blocking)
735
- const traceIdForLifecycle = process.env.AGENTS_TRACE_ID;
736
- if (traceIdForLifecycle) {
737
- import("@creativeintelligence/sdk/convex")
738
- .then(({ api: cbApi, getHttpClient }) =>
739
- getHttpClient().mutation(cbApi.contextBus.publish, {
740
- traceId: traceIdForLifecycle,
741
- sessionId: config.sessionId,
742
- project: process.env.AGENTS_PROJECT || session.project,
743
- type: "progress" as const,
744
- title: "session:started",
745
- content: JSON.stringify({
746
- agent,
747
- goal: session.goal,
748
- cwd,
749
- }),
750
- }),
751
- )
752
- .catch(() => {
753
- // Best-effort
754
- });
755
- }
756
-
757
- return new Promise<number>((resolve) => {
758
- // Track if promise is already settled (for race conditions)
759
- let settled = false;
760
- const settleWith = (code: number) => {
761
- if (settled) return;
762
- settled = true;
763
- resolve(code);
764
- };
765
-
766
- // Helper: best-effort kill agent (process group if available)
767
- const tryKill = (pid: number, signal: NodeJS.Signals) => {
768
- try {
769
- process.kill(pid, signal);
770
- return true;
771
- } catch {
772
- return false;
773
- }
774
- };
775
-
776
- const tryKillGroup = (pgid: number, signal: NodeJS.Signals) => {
777
- // Negative PID targets the process group on POSIX; not supported on Windows.
778
- if (process.platform === "win32") return false;
779
- try {
780
- process.kill(-pgid, signal);
781
- return true;
782
- } catch {
783
- return false;
784
- }
785
- };
786
-
787
- let child: ChildProcess | undefined;
788
-
789
- // Forward termination signals to the agent so `abbie session stop` doesn't orphan it.
790
- // Install handlers BEFORE spawning to avoid races where the runner dies before forwarding.
791
- let requestedSignal: NodeJS.Signals | null = null;
792
- let signalForwarded = false;
793
- let killEscalationScheduled = false;
794
-
795
- const forwardIfPossible = () => {
796
- if (signalForwarded || !requestedSignal) return;
797
- const pid = child?.pid;
798
- if (!pid) return;
799
-
800
- signalForwarded = true;
801
-
802
- // Best-effort: signal the entire agent process group first, then the PID.
803
- tryKillGroup(pid, requestedSignal);
804
- tryKill(pid, requestedSignal);
805
-
806
- // Escalate if the agent doesn't exit promptly.
807
- if (!killEscalationScheduled) {
808
- killEscalationScheduled = true;
809
- const killDelayMs = 5000;
810
- const killTimer = setTimeout(() => {
811
- if (settled || child?.exitCode !== null) return;
812
- tryKillGroup(pid, "SIGKILL");
813
- tryKill(pid, "SIGKILL");
814
- }, killDelayMs);
815
- killTimer.unref();
816
- }
817
- };
818
-
819
- const requestStop = (signal: NodeJS.Signals) => {
820
- if (requestedSignal) return;
821
- requestedSignal = signal;
822
-
823
- // Mark session as stopped early so other tools reflect intent.
824
- updateSession(sessionPath, { status: "stopped" });
825
-
826
- forwardIfPossible();
827
- };
828
-
829
- process.once("SIGTERM", () => requestStop("SIGTERM"));
830
- process.once("SIGINT", () => requestStop("SIGINT"));
831
-
832
- // Spawn the agent. `detached: true` makes the agent its own process group leader (PGID=PID),
833
- // allowing us to reliably kill the whole subtree (agent + grandchildren) via `kill(-pid)`.
834
- child = spawn(spawnConfig.command, spawnConfig.args, {
835
- cwd,
836
- env: {
837
- ...process.env,
838
- ...spawnConfig.env,
839
- // Unset CLAUDECODE so spawned claude sessions don't refuse to start
840
- // (Claude Code blocks nested sessions unless this env var is cleared)
841
- CLAUDECODE: undefined,
842
- PATH: pathWithLocalBin,
843
- AGENTS_SESSION_ID: config.sessionId,
844
- AGENTS_PROJECT: session.project,
845
- AGENTS_TRACE_ID: session.trace_id || "",
846
- },
847
- detached: true,
848
- stdio: spawnConfig.useStdin ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"],
849
- });
850
-
851
- // CRITICAL: Attach error handler IMMEDIATELY after spawn, before any pid check.
852
- // This catches ENOENT, EACCES, and other spawn failures.
853
- child.once("error", (err) => {
854
- console.error(`Spawn error: ${err}`);
855
- updateSession(sessionPath, { status: "failed", exit_code: 1 });
856
- const endedAt = new Date().toISOString();
857
- writeJsonAtomic(
858
- resultPath,
859
- buildResultEnvelope({
860
- config,
861
- session,
862
- status: "failed",
863
- exitCode: 1,
864
- endedAt,
865
- rawOutput: String(err),
866
- artifacts: collectGitArtifacts(cwd, session.start_commit_sha),
867
- }),
868
- );
869
- settleWith(1);
870
- });
871
-
872
- // Check for immediate spawn failure (synchronous)
873
- // Note: The 'error' handler above catches async spawn failures
874
- if (!child.pid) {
875
- // Spawn failed synchronously - error handler will fire shortly
876
- // Don't resolve here - let the error handler do it
877
- return;
878
- }
879
-
880
- // Update session with actual agent PID (also PGID on POSIX due to detached: true)
881
- updateSession(sessionPath, { agent_pid: child.pid });
882
-
883
- // If a stop signal arrived before spawn completed, forward it now that we have a PID.
884
- forwardIfPossible();
885
-
886
- // Create streams with error handlers
887
- let promptStream: ReturnType<typeof createReadStream> | undefined;
888
- let stdoutStream: WriteStream | undefined;
889
- let stderrStream: WriteStream | undefined;
890
- let outputStream: WriteStream | undefined;
891
-
892
- // Helper to handle stream errors - mark session failed but don't kill child
893
- const handleStreamError = (streamName: string) => (err: Error) => {
894
- console.error(`${streamName} stream error: ${err.message}`);
895
- // Don't fail session here - let child exit handler determine final status
896
- };
897
-
898
- // Pipe stdin from prompt file if needed
899
- if (spawnConfig.useStdin && child.stdin) {
900
- try {
901
- promptStream = createReadStream(promptPath);
902
- promptStream.on("error", (err) => {
903
- console.error(`Prompt stream error: ${err.message}`);
904
- // Can't read prompt - kill the child
905
- tryKillGroup(child.pid!, "SIGTERM");
906
- tryKill(child.pid!, "SIGTERM");
907
- });
908
- promptStream.pipe(child.stdin);
909
- } catch (err) {
910
- console.error(`Failed to create prompt stream: ${err}`);
911
- tryKillGroup(child.pid!, "SIGTERM");
912
- tryKill(child.pid!, "SIGTERM");
913
- }
914
- }
915
-
916
- // Capture stdout to file (and to output for non-codex agents)
917
- try {
918
- stdoutStream = createWriteStream(stdoutPath);
919
- stdoutStream.on("error", handleStreamError("stdout"));
920
- child.stdout?.pipe(stdoutStream);
921
- } catch (err) {
922
- console.error(`Failed to create stdout stream: ${err}`);
923
- }
924
-
925
- // Capture stdout as agent output (response file)
926
- try {
927
- outputStream = createWriteStream(outputPath);
928
- outputStream.on("error", handleStreamError("output"));
929
- child.stdout?.pipe(outputStream);
930
- } catch (err) {
931
- console.error(`Failed to create output stream: ${err}`);
932
- }
933
-
934
- // Capture stderr to file
935
- try {
936
- stderrStream = createWriteStream(stderrPath);
937
- stderrStream.on("error", handleStreamError("stderr"));
938
- child.stderr?.pipe(stderrStream);
939
- } catch (err) {
940
- console.error(`Failed to create stderr stream: ${err}`);
941
- }
942
-
943
- // Handle process exit
944
- child.on("close", async (code, signal) => {
945
- const exitCode = code ?? (signal ? 1 : 0);
946
- const endedAt = new Date().toISOString();
947
-
948
- // Wrap entire handler in try/finally to ensure we always resolve
949
- try {
950
- // Wait for all streams to finish writing before checking output
951
- // Only wait for streams that were successfully created
952
- try {
953
- const streamWaits: Promise<void>[] = [];
954
- if (stdoutStream) streamWaits.push(waitForStream(stdoutStream));
955
- if (stderrStream) streamWaits.push(waitForStream(stderrStream));
956
- if (outputStream) streamWaits.push(waitForStream(outputStream));
957
- if (streamWaits.length > 0) {
958
- await Promise.all(streamWaits);
959
- }
960
- } catch (streamErr) {
961
- console.error(`Stream flush error: ${streamErr}`);
962
- }
963
-
964
- // Write exit info (wrapped in try/catch)
965
- try {
966
- const exitPath = outputPath.replace(/\.json$/, "-exit.json");
967
- const exitInfo: ExitInfo = {
968
- exitCode,
969
- signal,
970
- endedAt,
971
- };
972
- writeJsonAtomic(exitPath, exitInfo);
973
- } catch (exitErr) {
974
- console.error(`Failed to write exit info: ${exitErr}`);
975
- }
976
-
977
- // Clean agent output: strip control chars and bullet markers
978
- cleanAgentOutput(outputPath);
979
-
980
- let outputContent = "";
981
- if (existsSync(outputPath)) {
982
- outputContent = readFileSync(outputPath, "utf-8");
983
- }
984
-
985
- // Fallback: surface stderr if stdout payload is empty.
986
- if (outputContent.trim().length === 0 && existsSync(stderrPath)) {
987
- const stderrContent = readFileSync(stderrPath, "utf-8").trim();
988
- if (stderrContent.length > 0) {
989
- outputContent = stderrContent;
990
- }
991
- }
992
-
993
- // Copilot often exits with code 1 and empty stdio when auth/model lookup fails.
994
- // Bubble a readable diagnostic from ~/.copilot/logs into the result envelope.
995
- if (outputContent.trim().length === 0 && agent === "copilot") {
996
- const diagnostic = readCopilotFailureDiagnostic(session.started_at);
997
- if (diagnostic) {
998
- outputContent = diagnostic;
999
- }
1000
- }
1001
-
1002
- // Determine final status (wrapped in try/catch)
1003
- let status: SessionResult["status"] = "failed";
1004
- try {
1005
- // If user stopped the session (via runner signal handler or external write), preserve "stopped".
1006
- let currentStatus: ActiveSession["status"] | undefined;
1007
- try {
1008
- currentStatus = JSON.parse(readFileSync(sessionPath, "utf-8"))
1009
- .status as ActiveSession["status"];
1010
- } catch {
1011
- // Best-effort only
1012
- }
1013
-
1014
- if (currentStatus === "stopped" || requestedSignal) {
1015
- status = "stopped";
1016
- } else {
1017
- const hasOutput = outputContent.trim().length > 0;
1018
- status = exitCode === 0 && hasOutput ? "completed" : "failed";
1019
- }
1020
- } catch (readErr) {
1021
- console.error(`Failed to check output: ${readErr}`);
1022
- }
1023
-
1024
- const artifacts = collectGitArtifacts(cwd, session.start_commit_sha);
1025
- const braintrustConfigured = Boolean(normalizeNonEmpty(process.env.BRAINTRUST_API_KEY));
1026
- const braintrustProject =
1027
- normalizeNonEmpty(process.env.BRAINTRUST_PROJECT_NAME) ||
1028
- normalizeNonEmpty(process.env.AGENTS_PROJECT) ||
1029
- normalizeNonEmpty(session.project) ||
1030
- null;
1031
- let braintrustTraceUrl: string | undefined;
1032
- try {
1033
- braintrustTraceUrl = await traceSessionRunToBraintrust({
1034
- artifacts,
1035
- config,
1036
- endedAt,
1037
- exitCode,
1038
- outputContent,
1039
- session,
1040
- status,
1041
- });
1042
- } catch (traceErr) {
1043
- const message = traceErr instanceof Error ? traceErr.message : String(traceErr);
1044
- console.error(`Braintrust trace logging failed: ${message}`);
1045
- }
1046
-
1047
- if (braintrustTraceUrl) {
1048
- updateSession(sessionPath, { trace_url: braintrustTraceUrl });
1049
- }
1050
-
1051
- const sessionResult = buildResultEnvelope({
1052
- config,
1053
- session,
1054
- status,
1055
- exitCode,
1056
- endedAt,
1057
- rawOutput: outputContent,
1058
- artifacts,
1059
- traceUrl: braintrustTraceUrl,
1060
- });
1061
-
1062
- // Write canonical result envelope.
1063
- writeJsonAtomic(resultPath, sessionResult);
1064
-
1065
- // Update session status
1066
- updateSession(sessionPath, {
1067
- status,
1068
- exit_code: exitCode,
1069
- ...(braintrustTraceUrl ? { trace_url: braintrustTraceUrl } : {}),
1070
- });
1071
-
1072
- try {
1073
- artifactStore.markComplete(config.sessionId, {
1074
- status,
1075
- exitCode,
1076
- outputPath,
1077
- });
1078
- } catch {
1079
- // Best-effort: active session files remain source of truth.
1080
- }
1081
-
1082
- // Publish session output as artifact to contextBus (continuity substrate).
1083
- // Best-effort: never block exit.
1084
- const traceId = process.env.AGENTS_TRACE_ID;
1085
- if (traceId && status === "completed") {
1086
- try {
1087
- const outputForContext = sessionResult.output.raw.trim();
1088
- if (outputForContext) {
1089
- // Truncate to contextBus recommended limit (~2KB content)
1090
- const maxContent = 2000;
1091
- const content =
1092
- outputForContext.length > maxContent
1093
- ? `${outputForContext.slice(0, maxContent - 50)}\n\n[truncated — full output at ${outputPath}]`
1094
- : outputForContext;
1095
-
1096
- // Extract structured summary from output
1097
- const filesModified = [
1098
- ...new Set(
1099
- outputForContext.match(
1100
- /(?:^|\s)(?:created?|modif(?:ied|y)|edited?|updated?|wrote|deleted?)\s+[`'"]*([^\s`'"]+\.\w{1,6})[`'":]*/gim,
1101
- ) || [],
1102
- ),
1103
- ]
1104
- .map((m) => m.replace(/^.*?([^\s`'"]+\.\w{1,6}).*$/, "$1"))
1105
- .slice(0, 20);
1106
- const hasOutputContract = /\{[\s\S]*"status"[\s\S]*"confidence"[\s\S]*\}/.test(
1107
- outputForContext.slice(-500),
1108
- );
1109
-
1110
- const { api: cbApi, getHttpClient } = await import("@creativeintelligence/sdk/convex");
1111
- await getHttpClient().mutation(cbApi.contextBus.publish, {
1112
- traceId,
1113
- sessionId: config.sessionId,
1114
- project: process.env.AGENTS_PROJECT || session.project,
1115
- type: "artifact",
1116
- title: session.goal ? session.goal.slice(0, 200) : `${agent} session output`,
1117
- content,
1118
- metadata: {
1119
- agent,
1120
- project: session.project,
1121
- sessionId: config.sessionId,
1122
- outputPath,
1123
- exitCode,
1124
- filesModified: filesModified.length > 0 ? filesModified : artifacts.slice(0, 20),
1125
- hasOutputContract,
1126
- resultPath,
1127
- braintrustConfigured,
1128
- braintrustProject,
1129
- braintrustTraceCaptured: Boolean(braintrustTraceUrl),
1130
- ...(braintrustTraceUrl ? { traceUrl: braintrustTraceUrl } : {}),
1131
- },
1132
- });
1133
- }
1134
- } catch {
1135
- // Best-effort: contextBus publish must never prevent session completion
1136
- }
1137
- }
1138
-
1139
- // Update Convex session with terminal status + metadata (best-effort)
1140
- if (traceId) {
1141
- try {
1142
- const { getHttpClient, api } = await import("@creativeintelligence/sdk/convex");
1143
- const client = getHttpClient();
1144
-
1145
- // Read output excerpt for metadata
1146
- let outputExcerpt = "";
1147
- const raw = sessionResult.output.raw.trim();
1148
- outputExcerpt = raw.length > 500 ? raw.slice(0, 500) : raw;
1149
-
1150
- // Read prompt excerpt
1151
- let promptExcerpt = "";
1152
- if (existsSync(config.promptPath)) {
1153
- const raw = readFileSync(config.promptPath, "utf-8").trim();
1154
- promptExcerpt = raw.length > 500 ? raw.slice(0, 500) : raw;
1155
- }
1156
-
1157
- await client.mutation(api.sessions.update, {
1158
- sessionId: config.sessionId,
1159
- status: status as "completed" | "stopped" | "failed",
1160
- endedAt: Date.now(),
1161
- ...(braintrustTraceUrl ? { traceUrl: braintrustTraceUrl } : {}),
1162
- metadata: {
1163
- outputExcerpt,
1164
- promptExcerpt,
1165
- exitCode,
1166
- resultPath,
1167
- artifacts: artifacts.slice(0, 50),
1168
- outputTruncated: sessionResult.output.truncated,
1169
- braintrustConfigured,
1170
- braintrustProject,
1171
- braintrustTraceCaptured: Boolean(braintrustTraceUrl),
1172
- ...(braintrustTraceUrl
1173
- ? { trace_url: braintrustTraceUrl, traceUrl: braintrustTraceUrl }
1174
- : {}),
1175
- },
1176
- });
1177
- } catch {
1178
- // Best-effort: daemon backup sync handles this
1179
- }
1180
- }
1181
-
1182
- // Emit session lifecycle event (completed/failed/stopped)
1183
- if (traceId) {
1184
- try {
1185
- const { api: cbApi, getHttpClient } = await import("@creativeintelligence/sdk/convex");
1186
- await getHttpClient().mutation(cbApi.contextBus.publish, {
1187
- traceId,
1188
- sessionId: config.sessionId,
1189
- project: process.env.AGENTS_PROJECT || session.project,
1190
- type: "progress" as const,
1191
- title: `session:${status}`,
1192
- content: JSON.stringify({ agent, exitCode, status }),
1193
- });
1194
- } catch {
1195
- // Best-effort
1196
- }
1197
- }
1198
- } finally {
1199
- // Always resolve, even if something above threw
1200
- settleWith(exitCode);
1201
- }
1202
- });
1203
- });
1204
- }
1205
-
1206
- /**
1207
- * Main entry point for runner process.
1208
- * Called by `abbie session run <sessionId>`.
1209
- *
1210
- * Returns the exit code. The caller (CLI command) should set process.exitCode
1211
- * rather than calling process.exit() directly, to allow streams to flush.
1212
- */
1213
- export async function runnerMain(): Promise<number> {
1214
- const config = parseRunnerConfig();
1215
-
1216
- if (!config) {
1217
- console.error("Runner config not found in environment");
1218
- return 1;
1219
- }
1220
-
1221
- const exitCode = await runAgent(config);
1222
- return exitCode;
1223
- }