@creativeintelligence/abbie 0.1.4 → 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 +9 -5
  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
@@ -1,1486 +0,0 @@
1
- import { execSync, spawn, spawnSync } from "node:child_process";
2
- import { randomBytes } from "node:crypto";
3
- import {
4
- existsSync,
5
- mkdirSync,
6
- readdirSync,
7
- readFileSync,
8
- renameSync,
9
- unlinkSync,
10
- writeFileSync,
11
- } from "node:fs";
12
- import { homedir } from "node:os";
13
- import { join } from "node:path";
14
- import {
15
- findProjectPath,
16
- getConfigEnvironment,
17
- getPromptEnhancements,
18
- type LoadedConfig,
19
- loadConfigFromPath,
20
- } from "./config-loader.js";
21
- import { getContractTemplate } from "./contracts.js";
22
- import { getDeviceId } from "./device.js";
23
- import { createEvent, EventStore, generateSessionId } from "./events.js";
24
- import {
25
- type ReinjectMode,
26
- type SessionArtifactStatus,
27
- SessionArtifactStore,
28
- } from "./session-artifacts.js";
29
- import { getSessionLogPaths, readSessionResult, type SessionResult } from "./session-result.js";
30
- import { AGENTS, Agent, type AgentType, DEFAULT_AGENT, isValidAgent } from "./types.js";
31
-
32
- /**
33
- * Generate a trace ID for event correlation.
34
- * Format: tr_{24 hex chars} (e.g., tr_a1b2c3d4e5f6a1b2c3d4e5f6)
35
- */
36
- export function generateTraceId(): string {
37
- return `tr_${randomBytes(12).toString("hex")}`;
38
- }
39
-
40
- /**
41
- * Get or create a trace ID from environment or generate new.
42
- */
43
- export function getOrCreateTraceId(explicit?: string): string {
44
- if (explicit) return explicit;
45
- if (process.env.AGENTS_TRACE_ID) return process.env.AGENTS_TRACE_ID;
46
- return generateTraceId();
47
- }
48
-
49
- // Re-export from types.ts for backwards compatibility
50
- export { Agent, type AgentType, AGENTS, isValidAgent, DEFAULT_AGENT };
51
-
52
- /**
53
- * Deprecated alias for backwards compatibility.
54
- */
55
- export type ActiveAgentType = AgentType;
56
-
57
- /**
58
- * Active session state stored on disk.
59
- */
60
- export interface ActiveSession {
61
- session_id: string;
62
- agent: AgentType;
63
- project: string;
64
- goal: string;
65
- issue?: string;
66
- cwd: string;
67
- /**
68
- * Runner PID (supervisor process).
69
- *
70
- * Historical note: `pid` used to be overwritten by the runner with the agent PID,
71
- * which made stop semantics ambiguous. `pid` is now intended to remain the runner PID.
72
- */
73
- pid: number;
74
- /** Runner PID (explicit field for clarity) */
75
- runner_pid?: number;
76
- /**
77
- * Agent PID (child process).
78
- *
79
- * On POSIX systems the runner spawns the agent with `detached: true`, so `agent_pid`
80
- * is also the agent process group ID (PGID). This allows killing the whole tree via
81
- * `process.kill(-agent_pid, signal)`.
82
- */
83
- agent_pid?: number;
84
- started_at: string;
85
- status: "running" | "completed" | "failed" | "stopped";
86
- exit_code?: number;
87
- prompt_path?: string;
88
- output_path?: string;
89
- result_path?: string;
90
- stdout_path?: string;
91
- stderr_path?: string;
92
- /** Read-only mode - no writes allowed */
93
- read_only?: boolean;
94
- /** Trace ID for event correlation */
95
- trace_id?: string;
96
- /** Braintrust trace URL when available */
97
- trace_url?: string;
98
- /** Parent session that spawned this one */
99
- parent_session_id?: string;
100
- /** Tmux pane ID when spawned in terminal mode */
101
- pane_id?: string;
102
- /** How this session was spawned */
103
- spawn_mode?: "terminal" | "headless" | "nvim-terminal";
104
- /** Nvim server address for legacy nvim-terminal sessions. */
105
- nvim_server_addr?: string;
106
- /** Git HEAD sha captured at session start (for file provenance tracking) */
107
- start_commit_sha?: string;
108
- }
109
-
110
- /**
111
- * Options for starting a session.
112
- */
113
- export interface StartSessionOptions {
114
- agent: AgentType;
115
- project: string;
116
- goal: string;
117
- issue?: string;
118
- cwd?: string;
119
- /** Path to prompt file (instead of goal string) */
120
- promptFile?: string;
121
- /** Read-only mode - inject contract forbidding writes */
122
- readOnly?: boolean;
123
- /** Explicit trace ID (defaults to AGENTS_TRACE_ID or generates new) */
124
- traceId?: string;
125
- /** Parent session ID for hierarchy tracking */
126
- parentSessionId?: string;
127
- /** Prior session IDs to include as prompt context */
128
- reuseSessionIds?: string[];
129
- /** Reinject mode for prior session artifacts */
130
- reinjectMode?: ReinjectMode;
131
- /** Override default model for the agent */
132
- model?: string;
133
- /** If true, inject recent file_activity from contextBus as prior context (default: true) */
134
- autoContext?: boolean;
135
- /** If true, use runner pattern and block until complete */
136
- awaitCompletion?: boolean;
137
- /** If true, spawn as headless subprocess (no tmux window). Default: false (terminal mode). */
138
- headless?: boolean;
139
- /** Tmux session name for terminal mode. Defaults to "abbie" to avoid hijacking personal sessions. */
140
- tmuxSession?: string;
141
- /** Skill names to route the agent toward (injected as <skill> blocks) */
142
- skills?: string[];
143
- }
144
-
145
- /**
146
- * Result from starting a session.
147
- */
148
- export interface StartSessionResult {
149
- session_id: string;
150
- pid: number;
151
- prompt_path: string;
152
- output_path: string;
153
- result_path: string;
154
- status: "spawned" | "failed";
155
- error?: string;
156
- /** Trace ID for event correlation */
157
- trace_id: string;
158
- /** Whether session is read-only */
159
- read_only: boolean;
160
- }
161
-
162
- /** Best-effort git rev-parse HEAD in a directory. Returns undefined if not a git repo. */
163
- function getHeadSha(cwd: string): string | undefined {
164
- try {
165
- return execSync("git rev-parse HEAD", { cwd, timeout: 3000, stdio: "pipe" }).toString().trim();
166
- } catch {
167
- return undefined;
168
- }
169
- }
170
-
171
- /**
172
- * Active session manager - spawns and tracks running agents.
173
- */
174
- export class ActiveSessionManager {
175
- private basePath: string;
176
- private promptsPath: string;
177
- private eventStore: EventStore;
178
- private artifactStore: SessionArtifactStore;
179
-
180
- constructor(basePath?: string) {
181
- this.basePath = basePath || join(homedir(), ".abbie", "active-sessions");
182
- this.promptsPath = join(homedir(), ".abbie", "prompts");
183
- this.eventStore = new EventStore();
184
- this.artifactStore = new SessionArtifactStore();
185
-
186
- if (!existsSync(this.basePath)) {
187
- mkdirSync(this.basePath, { recursive: true });
188
- }
189
- if (!existsSync(this.promptsPath)) {
190
- mkdirSync(this.promptsPath, { recursive: true });
191
- }
192
- }
193
-
194
- /**
195
- * Expand tilde in path to home directory.
196
- */
197
- private expandTilde(path: string): string {
198
- if (path.startsWith("~/")) {
199
- return join(homedir(), path.slice(2));
200
- }
201
- if (path === "~") {
202
- return homedir();
203
- }
204
- return path;
205
- }
206
-
207
- /**
208
- * Start a new agent session using the runner/supervisor pattern.
209
- *
210
- * The runner pattern ensures reliable session completion:
211
- * - For --await mode: Runner runs in foreground, we wait for it
212
- * - For background mode: Runner is detached, handles its own lifecycle
213
- *
214
- * The runner:
215
- * - Owns the agent child process
216
- * - Captures stdout/stderr to log files
217
- * - Updates session status on process exit
218
- * - Writes result.json atomically
219
- */
220
- async start(options: StartSessionOptions): Promise<StartSessionResult> {
221
- // Resolve working directory - use config if cwd not provided
222
- let rawCwd = options.cwd;
223
- let loadedConfig: LoadedConfig | undefined;
224
-
225
- if (!rawCwd) {
226
- // Try to find project path from config
227
- const projectPath = findProjectPath(options.project);
228
- if (projectPath) {
229
- rawCwd = projectPath;
230
- loadedConfig = loadConfigFromPath(projectPath);
231
- } else {
232
- rawCwd = process.cwd();
233
- }
234
- } else {
235
- // Load config from provided cwd
236
- loadedConfig = loadConfigFromPath(rawCwd);
237
- }
238
-
239
- const cwd = this.expandTilde(rawCwd);
240
- const sessionId = generateSessionId(options.project);
241
- const traceId = getOrCreateTraceId(options.traceId);
242
- const readOnly = options.readOnly ?? false;
243
- const reinjectMode: ReinjectMode = options.reinjectMode ?? "off";
244
- const reuseSessionIds = options.reuseSessionIds ?? [];
245
- const reinjectionContext = this.artifactStore.buildReinjectionContext(
246
- reuseSessionIds,
247
- reinjectMode,
248
- );
249
-
250
- // Get config-derived values
251
- const configEnv = loadedConfig ? getConfigEnvironment(loadedConfig.config) : {};
252
- const promptEnhancements = loadedConfig ? getPromptEnhancements(loadedConfig) : "";
253
-
254
- // Prepare prompt file
255
- const promptPath = join(this.promptsPath, `${sessionId}.md`);
256
- const { outputPath, resultPath, stdoutPath, stderrPath } = getSessionLogPaths(
257
- sessionId,
258
- this.promptsPath,
259
- );
260
-
261
- // Auto-context: fetch recent file_activity from contextBus (opt-out via --no-auto-context)
262
- const fileProvenance =
263
- options.autoContext !== false ? await this.getFileProvenanceContext(options.project) : "";
264
-
265
- if (options.promptFile && existsSync(options.promptFile)) {
266
- // Copy prompt file - optionally prepend read-only contract, config, and awareness
267
- let content = readFileSync(options.promptFile, "utf-8");
268
- if (readOnly) {
269
- content = this.prependReadOnlyContract(content);
270
- }
271
- const awareness = this.getWorkspaceAwareness(cwd, sessionId);
272
- if (awareness) {
273
- content = `${awareness}${content}`;
274
- }
275
- if (fileProvenance) {
276
- content = `${fileProvenance}${content}`;
277
- }
278
- if (reinjectionContext) {
279
- content = `${reinjectionContext}${content}`;
280
- }
281
- if (promptEnhancements) {
282
- content = `${promptEnhancements}\n${content}`;
283
- }
284
- const skillRouting = this.buildSkillRouting(options.skills);
285
- if (skillRouting) {
286
- content = `${content}\n${skillRouting}`;
287
- }
288
- writeFileSync(promptPath, content);
289
- } else {
290
- // Build prompt from goal with workspace awareness
291
- const awareness = this.getWorkspaceAwareness(cwd, sessionId);
292
- const prompt = this.buildPrompt(
293
- options,
294
- readOnly,
295
- promptEnhancements,
296
- awareness,
297
- reinjectionContext,
298
- fileProvenance,
299
- );
300
- writeFileSync(promptPath, prompt);
301
- }
302
-
303
- // Capture HEAD sha at spawn time for file provenance tracking
304
- const startCommitSha = getHeadSha(cwd);
305
-
306
- // Create session record BEFORE spawning runner
307
- const session: ActiveSession = {
308
- session_id: sessionId,
309
- agent: options.agent,
310
- project: options.project,
311
- goal: options.goal,
312
- issue: options.issue,
313
- cwd,
314
- pid: 0, // Will be updated by runner
315
- started_at: new Date().toISOString(),
316
- status: "running",
317
- prompt_path: promptPath,
318
- output_path: outputPath,
319
- result_path: resultPath,
320
- stdout_path: stdoutPath,
321
- stderr_path: stderrPath,
322
- read_only: readOnly,
323
- trace_id: traceId,
324
- parent_session_id: options.parentSessionId,
325
- start_commit_sha: startCommitSha,
326
- };
327
-
328
- this.saveSession(session);
329
- this.saveSessionArtifactStart(session);
330
-
331
- // Best-effort Convex write for immediate visibility (daemon backup in 5s)
332
- this.writeSessionToStore(session).catch(() => {});
333
-
334
- // Log event
335
- this.eventStore.append(
336
- createEvent.sessionStart(sessionId, options.agent, {
337
- project: options.project,
338
- issue: options.issue,
339
- worktree: cwd,
340
- }),
341
- );
342
-
343
- // Determine spawn mode: terminal (default) or headless.
344
- // --await always runs headless in foreground.
345
- const useHeadless = options.headless || options.awaitCompletion;
346
-
347
- const localBin = join(homedir(), ".local", "bin");
348
- const pathWithLocalBin = process.env.PATH?.includes(localBin)
349
- ? process.env.PATH
350
- : `${localBin}:${process.env.PATH ?? ""}`;
351
- const agentsPath = join(localBin, "abbie");
352
- const sessionPath = join(this.basePath, `${sessionId}.json`);
353
-
354
- // Load user secrets (API keys) if not already in environment.
355
- const secretsEnv: Record<string, string> = {};
356
- const secretsFile = join(homedir(), ".config", "zsh", "secrets", "env.zsh");
357
- if (existsSync(secretsFile)) {
358
- try {
359
- const content = readFileSync(secretsFile, "utf-8");
360
- for (const line of content.split("\n")) {
361
- const match = line.match(/^\s*export\s+([A-Z_][A-Z0-9_]*)=["']?([^"'\n]*)["']?\s*$/);
362
- if (match?.[1] && !process.env[match[1]]) {
363
- secretsEnv[match[1]] = match[2];
364
- }
365
- }
366
- } catch {
367
- // Best-effort: secrets loading should never block session start
368
- }
369
- }
370
-
371
- const runnerEnvShared: Record<string, string> = {
372
- ...secretsEnv,
373
- ...configEnv,
374
- PATH: pathWithLocalBin,
375
- AGENTS_RUNNER_SESSION_ID: sessionId,
376
- AGENTS_RUNNER_SESSION_PATH: sessionPath,
377
- AGENTS_RUNNER_PROMPT_PATH: promptPath,
378
- AGENTS_RUNNER_OUTPUT_PATH: outputPath,
379
- AGENTS_RUNNER_RESULT_PATH: resultPath,
380
- AGENTS_RUNNER_STDOUT_PATH: stdoutPath,
381
- AGENTS_RUNNER_STDERR_PATH: stderrPath,
382
- AGENTS_RUNNER_AGENT: options.agent,
383
- AGENTS_RUNNER_MODEL: options.model || "",
384
- AGENTS_SESSION_ID: sessionId,
385
- AGENTS_PROJECT: options.project,
386
- AGENTS_TRACE_ID: traceId,
387
- };
388
-
389
- const runnerEnv = {
390
- ...process.env,
391
- ...runnerEnvShared,
392
- };
393
-
394
- if (!useHeadless) {
395
- // TERMINAL MODE: spawn runner in a tmux window.
396
- try {
397
- const { newWindow, getPaneId, isRunning, listSessions } = await import("./tmux/bridge.js");
398
- const { ensureManagedSession } = await import("./managed-session.js");
399
-
400
- const tmuxSession = options.tmuxSession
401
- ? options.tmuxSession
402
- : await ensureManagedSession();
403
-
404
- if (options.tmuxSession) {
405
- const running = await isRunning();
406
- const sessions = running ? await listSessions() : [];
407
- const exists = sessions.some((s) => s.name === tmuxSession);
408
- if (!exists) {
409
- await new Promise<void>((resolve, reject) => {
410
- const proc = spawn(
411
- "tmux",
412
- ["new-session", "-d", "-s", tmuxSession, "-n", "_abbie", "-c", homedir()],
413
- { stdio: ["ignore", "ignore", "ignore"] },
414
- );
415
- proc.on("close", (code) => {
416
- if (code === 0) resolve();
417
- else reject(new Error(`Failed to create tmux session: ${tmuxSession}`));
418
- });
419
- proc.on("error", reject);
420
- });
421
- }
422
- }
423
-
424
- const launchScript = join(this.promptsPath, `${sessionId}-runner-launch.sh`);
425
- const launchScriptContent = this.buildRunnerLaunchScript({
426
- cwd,
427
- agentsPath,
428
- sessionId,
429
- env: runnerEnvShared,
430
- });
431
- writeFileSync(launchScript, launchScriptContent, { mode: 0o755 });
432
-
433
- const windowName = `${options.project}-${options.agent}-${sessionId.slice(-4)}`;
434
- const command = `bash ${this.shellEscape(launchScript)}`;
435
- await newWindow({ name: windowName, cwd, command, session: tmuxSession });
436
-
437
- const paneId = await getPaneId(windowName, 0, tmuxSession);
438
- session.spawn_mode = "terminal";
439
- session.pane_id = paneId ?? undefined;
440
- this.saveSession(session);
441
-
442
- return {
443
- session_id: sessionId,
444
- pid: 0,
445
- prompt_path: promptPath,
446
- output_path: outputPath,
447
- result_path: resultPath,
448
- status: "spawned",
449
- trace_id: traceId,
450
- read_only: readOnly,
451
- };
452
- } catch (tmuxError) {
453
- // tmux unavailable - fall through to headless.
454
- const errMsg = (tmuxError as Error).message;
455
- if (
456
- !errMsg.includes("ENOENT") &&
457
- !errMsg.includes("not found") &&
458
- !errMsg.includes("no server")
459
- ) {
460
- session.status = "failed";
461
- this.saveSession(session);
462
- this.markSessionArtifactComplete(sessionId, {
463
- status: "failed",
464
- outputPath,
465
- });
466
- return {
467
- session_id: sessionId,
468
- pid: 0,
469
- prompt_path: promptPath,
470
- output_path: outputPath,
471
- result_path: resultPath,
472
- status: "failed",
473
- error: `Terminal spawn failed: ${errMsg}`,
474
- trace_id: traceId,
475
- read_only: readOnly,
476
- };
477
- }
478
- }
479
- }
480
-
481
- // HEADLESS MODE (--headless, --await, or tmux fallback)
482
- session.spawn_mode = "headless";
483
- this.saveSession(session);
484
-
485
- try {
486
- if (options.awaitCompletion) {
487
- // AWAIT MODE: spawn runner in foreground and wait.
488
- const runner = spawn(agentsPath, ["session", "run", sessionId], {
489
- cwd,
490
- env: runnerEnv,
491
- stdio: ["ignore", "pipe", "pipe"],
492
- });
493
-
494
- if (!runner.pid) {
495
- throw new Error("Failed to spawn runner process");
496
- }
497
-
498
- session.pid = runner.pid;
499
- session.runner_pid = runner.pid;
500
- this.saveSession(session);
501
-
502
- const exitCode = await new Promise<number>((resolve) => {
503
- runner.on("close", (code) => {
504
- resolve(code ?? 1);
505
- });
506
- runner.on("error", () => {
507
- resolve(1);
508
- });
509
- });
510
-
511
- const finalSession = this.get(sessionId);
512
- const finalPid = finalSession?.pid ?? runner.pid;
513
-
514
- if (finalSession) {
515
- if (finalSession.status === "completed") {
516
- this.eventStore.append(
517
- createEvent.complete(sessionId, options.agent, {
518
- summary: "Session completed",
519
- artifacts: [],
520
- duration_ms: Date.now() - new Date(session.started_at).getTime(),
521
- }),
522
- );
523
- } else if (finalSession.status === "failed") {
524
- this.eventStore.append({
525
- type: "session:failed",
526
- session_id: sessionId,
527
- agent: options.agent,
528
- data: { reason: `Exit code ${exitCode}` },
529
- });
530
- }
531
-
532
- this.markSessionArtifactComplete(sessionId, {
533
- status:
534
- finalSession.status === "completed"
535
- ? "completed"
536
- : finalSession.status === "stopped"
537
- ? "stopped"
538
- : "failed",
539
- exitCode: finalSession.exit_code ?? exitCode,
540
- outputPath: finalSession.output_path || outputPath,
541
- });
542
- }
543
-
544
- return {
545
- session_id: sessionId,
546
- pid: finalPid,
547
- prompt_path: promptPath,
548
- output_path: outputPath,
549
- result_path: resultPath,
550
- status: "spawned",
551
- trace_id: traceId,
552
- read_only: readOnly,
553
- };
554
- }
555
-
556
- // BACKGROUND MODE: spawn detached runner and return immediately.
557
- const runner = spawn(agentsPath, ["session", "run", sessionId], {
558
- cwd,
559
- env: runnerEnv,
560
- stdio: ["ignore", "ignore", "ignore"],
561
- detached: true,
562
- });
563
-
564
- if (!runner.pid) {
565
- throw new Error("Failed to spawn runner process");
566
- }
567
-
568
- session.pid = runner.pid;
569
- session.runner_pid = runner.pid;
570
- this.saveSession(session);
571
- runner.unref();
572
-
573
- return {
574
- session_id: sessionId,
575
- pid: runner.pid,
576
- prompt_path: promptPath,
577
- output_path: outputPath,
578
- result_path: resultPath,
579
- status: "spawned",
580
- trace_id: traceId,
581
- read_only: readOnly,
582
- };
583
- } catch (error) {
584
- session.status = "failed";
585
- this.saveSession(session);
586
- this.markSessionArtifactComplete(sessionId, {
587
- status: "failed",
588
- outputPath,
589
- });
590
-
591
- return {
592
- session_id: sessionId,
593
- pid: 0,
594
- prompt_path: promptPath,
595
- output_path: outputPath,
596
- result_path: resultPath,
597
- status: "failed",
598
- error: (error as Error).message,
599
- trace_id: traceId,
600
- read_only: readOnly,
601
- };
602
- }
603
- }
604
-
605
- /**
606
- * Wait for a session to complete.
607
- *
608
- * With the runner pattern, the runner process writes canonical result.json.
609
- * This method polls for that result envelope and returns it when available.
610
- *
611
- * Note: For --await mode, prefer using start({ awaitCompletion: true })
612
- * which blocks on the runner directly instead of polling.
613
- */
614
- async await(
615
- sessionId: string,
616
- options?: {
617
- pollIntervalMs?: number;
618
- timeoutMs?: number;
619
- },
620
- ): Promise<{
621
- status: "completed" | "failed" | "stopped" | "timeout";
622
- output?: SessionResult;
623
- error?: string;
624
- }> {
625
- const pollIntervalMs = Math.max(100, options?.pollIntervalMs ?? 1000);
626
- const timeoutMs = options?.timeoutMs ?? 0; // 0 = no timeout (wait forever)
627
- const startTime = Date.now();
628
-
629
- const sleep = (ms: number) =>
630
- new Promise<void>((resolve) => {
631
- setTimeout(resolve, ms);
632
- });
633
-
634
- while (true) {
635
- // Check timeout if configured
636
- if (timeoutMs > 0 && Date.now() - startTime >= timeoutMs) {
637
- return { status: "timeout", error: `Timed out after ${timeoutMs}ms` };
638
- }
639
-
640
- const session = this.get(sessionId);
641
- if (!session) {
642
- return { status: "failed", error: `Session not found: ${sessionId}` };
643
- }
644
-
645
- const resultPath =
646
- session.result_path || getSessionLogPaths(sessionId, this.promptsPath).resultPath;
647
- const result = readSessionResult(resultPath);
648
- if (result) {
649
- this.markSessionArtifactComplete(sessionId, {
650
- status: result.status,
651
- exitCode: result.exitCode ?? undefined,
652
- outputPath: session.output_path,
653
- });
654
- return { status: result.status, output: result };
655
- }
656
-
657
- if (session.status !== "running") {
658
- const normalizedStatus: "completed" | "failed" | "stopped" =
659
- session.status === "completed"
660
- ? "completed"
661
- : session.status === "stopped"
662
- ? "stopped"
663
- : "failed";
664
- const outputPath = session.output_path;
665
- const artifactStatus: SessionArtifactStatus =
666
- session.status === "completed"
667
- ? "completed"
668
- : session.status === "stopped"
669
- ? "stopped"
670
- : "failed";
671
- this.markSessionArtifactComplete(sessionId, {
672
- status: artifactStatus,
673
- exitCode: session.exit_code,
674
- outputPath,
675
- });
676
-
677
- return {
678
- status: normalizedStatus,
679
- error: `Result file not found: ${resultPath}`,
680
- };
681
- }
682
-
683
- // Still running - check if runner/presentation process is alive.
684
- let dead = false;
685
- const runnerPid = session.runner_pid ?? session.pid;
686
- if (runnerPid > 0 && !this.isProcessRunning(runnerPid)) {
687
- dead = true;
688
- } else if (
689
- session.spawn_mode === "terminal" &&
690
- runnerPid <= 0 &&
691
- session.pane_id &&
692
- !this.isTmuxPaneAlive(session.pane_id)
693
- ) {
694
- dead = true;
695
- }
696
-
697
- if (dead) {
698
- // Process/pane died without updating status - mark as failed
699
- await sleep(500); // Give a moment for file writes to flush
700
- const updatedSession = this.get(sessionId);
701
- if (updatedSession && updatedSession.status === "running") {
702
- updatedSession.status = "failed";
703
- this.saveSession(updatedSession);
704
- this.markSessionArtifactComplete(sessionId, {
705
- status: "failed",
706
- exitCode: updatedSession.exit_code,
707
- outputPath: updatedSession.output_path,
708
- });
709
- }
710
- continue; // Loop will catch the updated status
711
- }
712
-
713
- await sleep(pollIntervalMs);
714
- }
715
- }
716
-
717
- /**
718
- * Get session by ID.
719
- */
720
- get(sessionId: string): ActiveSession | undefined {
721
- const sessionPath = join(this.basePath, `${sessionId}.json`);
722
- if (!existsSync(sessionPath)) {
723
- return undefined;
724
- }
725
- return JSON.parse(readFileSync(sessionPath, "utf-8"));
726
- }
727
-
728
- /**
729
- * List all active sessions.
730
- */
731
- list(options?: { status?: ActiveSession["status"]; project?: string }): ActiveSession[] {
732
- const sessions: ActiveSession[] = [];
733
-
734
- if (!existsSync(this.basePath)) {
735
- return sessions;
736
- }
737
-
738
- const files = readdirSync(this.basePath).filter((f) => f.endsWith(".json"));
739
-
740
- for (const file of files) {
741
- const session: ActiveSession = JSON.parse(readFileSync(join(this.basePath, file), "utf-8"));
742
-
743
- // Check if process is still running.
744
- if (session.status === "running") {
745
- if (session.pid > 0 && !this.isProcessRunning(session.pid)) {
746
- // Headless runner died without updating status
747
- session.status = "failed";
748
- this.saveSession(session);
749
- this.markSessionArtifactComplete(session.session_id, {
750
- status: "failed",
751
- exitCode: session.exit_code,
752
- outputPath: session.output_path,
753
- });
754
- } else if (
755
- session.spawn_mode === "terminal" &&
756
- session.pane_id &&
757
- !this.isTmuxPaneAlive(session.pane_id)
758
- ) {
759
- // Terminal pane is gone — agent died without mark-done
760
- session.status = "failed";
761
- this.saveSession(session);
762
- this.markSessionArtifactComplete(session.session_id, {
763
- status: "failed",
764
- exitCode: session.exit_code,
765
- outputPath: session.output_path,
766
- });
767
- }
768
- }
769
-
770
- // Apply filters
771
- if (options?.status && session.status !== options.status) continue;
772
- if (options?.project && session.project !== options.project) continue;
773
-
774
- sessions.push(session);
775
- }
776
-
777
- return sessions.sort(
778
- (a, b) => new Date(b.started_at).getTime() - new Date(a.started_at).getTime(),
779
- );
780
- }
781
-
782
- /**
783
- * Get all sessions spawned by a parent session.
784
- */
785
- getChildren(parentSessionId: string): ActiveSession[] {
786
- return this.list().filter((session) => session.parent_session_id === parentSessionId);
787
- }
788
-
789
- /**
790
- * Stop a running session.
791
- */
792
- stop(sessionId: string, signal: NodeJS.Signals = "SIGTERM"): boolean {
793
- const session = this.get(sessionId);
794
- if (!session) {
795
- return false;
796
- }
797
-
798
- if (session.status !== "running") {
799
- return false;
800
- }
801
-
802
- try {
803
- const runnerPid = session.runner_pid ?? session.pid;
804
- const agentPid = session.agent_pid;
805
-
806
- const tryKill = (pid: number, sig: NodeJS.Signals) => {
807
- if (pid <= 0) return false;
808
- try {
809
- process.kill(pid, sig);
810
- return true;
811
- } catch {
812
- return false;
813
- }
814
- };
815
-
816
- const tryKillGroup = (pgid: number, sig: NodeJS.Signals) => {
817
- // Negative PID targets the process group on POSIX; not supported on Windows.
818
- if (pgid <= 0) return false;
819
- if (process.platform === "win32") return false;
820
- try {
821
- process.kill(-pgid, sig);
822
- return true;
823
- } catch {
824
- return false;
825
- }
826
- };
827
-
828
- // Runner-first stop path: signal runner PID / process group.
829
- const killedRunner =
830
- runnerPid > 0 ? tryKillGroup(runnerPid, signal) || tryKill(runnerPid, signal) : false;
831
- const killedAgent =
832
- agentPid !== undefined
833
- ? tryKillGroup(agentPid, signal) || tryKill(agentPid, signal)
834
- : false;
835
-
836
- // Legacy fallback for pre-runner terminal sessions that never recorded a runner PID.
837
- let signaledLegacy = false;
838
- if (!killedRunner && !killedAgent && session.spawn_mode === "terminal" && session.pane_id) {
839
- this.killPaneProcesses(session.pane_id, signal);
840
- signaledLegacy = true;
841
- }
842
-
843
- if (!killedRunner && !killedAgent && !signaledLegacy) {
844
- return false;
845
- }
846
-
847
- session.status = "stopped";
848
- this.saveSession(session);
849
- this.markSessionArtifactComplete(sessionId, {
850
- status: "stopped",
851
- exitCode: session.exit_code,
852
- outputPath: session.output_path,
853
- });
854
-
855
- // Best-effort Convex update
856
- this.updateSessionInStore(sessionId, "stopped").catch(() => {});
857
-
858
- this.eventStore.append(
859
- createEvent.complete(sessionId, session.agent, {
860
- summary: "Session stopped by user",
861
- artifacts: [],
862
- duration_ms: Date.now() - new Date(session.started_at).getTime(),
863
- }),
864
- );
865
-
866
- return true;
867
- } catch {
868
- return false;
869
- }
870
- }
871
-
872
- /**
873
- * Kill processes running inside a tmux pane.
874
- * Used only as a legacy fallback for pre-runner terminal sessions.
875
- */
876
- private killPaneProcesses(paneId: string, signal: NodeJS.Signals = "SIGTERM"): void {
877
- try {
878
- // Get the shell PID running in the pane
879
- const result = spawnSync("tmux", ["display-message", "-p", "-t", paneId, "#{pane_pid}"], {
880
- stdio: ["ignore", "pipe", "ignore"],
881
- });
882
- if (result.status !== 0 || !result.stdout) return;
883
-
884
- const shellPid = parseInt(result.stdout.toString().trim(), 10);
885
- if (Number.isNaN(shellPid) || shellPid <= 0) return;
886
-
887
- // Find all child processes of the shell (the agent and its children)
888
- const psResult = spawnSync("pgrep", ["-P", String(shellPid)], {
889
- stdio: ["ignore", "pipe", "ignore"],
890
- });
891
- if (psResult.status !== 0 || !psResult.stdout) return;
892
-
893
- const childPids = psResult.stdout
894
- .toString()
895
- .trim()
896
- .split("\n")
897
- .map((p) => parseInt(p, 10))
898
- .filter((p) => !Number.isNaN(p) && p > 0);
899
-
900
- // Kill each child process group (agent spawns sub-processes)
901
- for (const pid of childPids) {
902
- try {
903
- // Try killing the process group first (catches agent child processes)
904
- process.kill(-pid, signal);
905
- } catch {
906
- try {
907
- process.kill(pid, signal);
908
- } catch {
909
- // Process already gone
910
- }
911
- }
912
- }
913
- } catch {
914
- // Best-effort fallback only.
915
- }
916
- }
917
-
918
- /**
919
- * Get events for a session.
920
- */
921
- getEvents(sessionId: string): ReturnType<EventStore["readSession"]> {
922
- return this.eventStore.readSession(sessionId);
923
- }
924
-
925
- /**
926
- * Clean up completed/failed sessions older than N days.
927
- */
928
- cleanup(daysOld: number = 7): number {
929
- const cutoff = Date.now() - daysOld * 24 * 60 * 60 * 1000;
930
- const sessions = this.list();
931
- let cleaned = 0;
932
-
933
- for (const session of sessions) {
934
- if (session.status === "running") continue;
935
-
936
- const sessionAge = new Date(session.started_at).getTime();
937
- if (sessionAge < cutoff) {
938
- this.deleteSession(session.session_id);
939
- cleaned++;
940
- }
941
- }
942
-
943
- return cleaned;
944
- }
945
-
946
- private shellEscape(value: string): string {
947
- return `'${value.replace(/'/g, `'\\''`)}'`;
948
- }
949
-
950
- private buildRunnerLaunchScript(input: {
951
- cwd: string;
952
- agentsPath: string;
953
- sessionId: string;
954
- env: Record<string, string>;
955
- }): string {
956
- const lines = ["#!/usr/bin/env bash", "set -euo pipefail", `cd ${this.shellEscape(input.cwd)}`];
957
-
958
- for (const [key, value] of Object.entries(input.env)) {
959
- if (!/^[A-Z_][A-Z0-9_]*$/.test(key)) continue;
960
- lines.push(`export ${key}=${this.shellEscape(String(value))}`);
961
- }
962
-
963
- lines.push(
964
- `exec ${this.shellEscape(input.agentsPath)} session run ${this.shellEscape(input.sessionId)}`,
965
- );
966
- return `${lines.join("\n")}\n`;
967
- }
968
-
969
- /**
970
- * Build prompt for agent.
971
- */
972
- /**
973
- * Build workspace awareness context from other active sessions in the same cwd.
974
- */
975
- private getWorkspaceAwareness(cwd: string, excludeSessionId: string): string {
976
- const sessions = this.list();
977
- const siblings = sessions.filter(
978
- (s) => s.cwd === cwd && s.session_id !== excludeSessionId && s.status === "running",
979
- );
980
-
981
- if (siblings.length === 0) return "";
982
-
983
- const lines = siblings.map((s) => {
984
- const agent = s.agent || "unknown";
985
- const goal = s.goal ? `: ${s.goal.slice(0, 120)}` : "";
986
- return ` - ${s.session_id} (${agent})${goal}`;
987
- });
988
-
989
- return `<workspace_awareness>
990
- Other active sessions in this workspace:
991
- ${lines.join("\n")}
992
-
993
- Coordinate via context bus (traceId-scoped append-only log).
994
- Avoid editing the same files simultaneously. Check git status before committing.
995
- </workspace_awareness>
996
-
997
- `;
998
- }
999
-
1000
- /**
1001
- * Fetch recent file_activity entries from contextBus for auto-context injection.
1002
- * Returns XML block listing files changed by prior sessions in this project.
1003
- */
1004
- private async getFileProvenanceContext(project: string): Promise<string> {
1005
- try {
1006
- const { getHttpClient, api } = await import("@creativeintelligence/sdk/convex");
1007
- const client = getHttpClient();
1008
- const entries = await client.query(api.contextBus.readByProject, {
1009
- project,
1010
- type: "file_activity",
1011
- since: Date.now() - 24 * 60 * 60 * 1000, // last 24h
1012
- limit: 10,
1013
- });
1014
-
1015
- if (!entries || entries.length === 0) return "";
1016
-
1017
- const lines: string[] = [];
1018
- for (const entry of entries) {
1019
- const meta = entry.metadata as Record<string, unknown> | undefined;
1020
- const agent = meta?.agent ?? "unknown";
1021
- const sessionId = entry.sessionId ?? "unknown";
1022
- let changes: Array<{ status: string; file: string }> = [];
1023
- try {
1024
- changes = JSON.parse(entry.content);
1025
- } catch {
1026
- continue;
1027
- }
1028
- if (changes.length === 0) continue;
1029
-
1030
- lines.push(` <session agent="${agent}" id="${sessionId}">`);
1031
- for (const c of changes.slice(0, 20)) {
1032
- lines.push(` <file status="${c.status}">${c.file}</file>`);
1033
- }
1034
- if (changes.length > 20) {
1035
- lines.push(` <!-- +${changes.length - 20} more files -->`);
1036
- }
1037
- lines.push(" </session>");
1038
- }
1039
-
1040
- if (lines.length === 0) return "";
1041
-
1042
- return `<file_provenance project="${project}" window="24h">
1043
- Recent file changes by other agent sessions in this project:
1044
- ${lines.join("\n")}
1045
- </file_provenance>
1046
-
1047
- `;
1048
- } catch {
1049
- return ""; // Best-effort: skip if Convex unavailable
1050
- }
1051
- }
1052
-
1053
- private buildPrompt(
1054
- options: StartSessionOptions,
1055
- readOnly: boolean,
1056
- configEnhancements?: string,
1057
- awarenessContext?: string,
1058
- reinjectionContext?: string,
1059
- fileProvenanceContext?: string,
1060
- ): string {
1061
- const issueRef = options.issue ? `\nIssue: ${options.issue}` : "";
1062
- const readOnlyContract = readOnly ? this.getReadOnlyContract() : "";
1063
- const configBlock = configEnhancements ? `${configEnhancements}\n` : "";
1064
- const awareness = awarenessContext || "";
1065
- const reinjection = reinjectionContext || "";
1066
- const provenance = fileProvenanceContext || "";
1067
- const skillRouting = this.buildSkillRouting(options.skills);
1068
-
1069
- return `${readOnlyContract}${configBlock}${awareness}${provenance}${reinjection}<session>
1070
- Project: ${options.project}${issueRef}
1071
- </session>
1072
- ${skillRouting}
1073
- <goal>
1074
- ${options.goal}
1075
- </goal>
1076
-
1077
- <exploration>
1078
- Before implementing, explore the codebase:
1079
- 1. Run \`layer .\` to understand architecture
1080
- 2. Run \`outline\` on relevant directories to map code structure
1081
- 3. Use \`--callers\` and \`--callees\` to trace dependencies
1082
- </exploration>
1083
-
1084
- <verification>
1085
- After implementation:
1086
- 1. Run \`verify --format=summary\` to check tests
1087
- 2. Ensure no type errors
1088
- 3. Commit with descriptive message${options.issue ? ` referencing ${options.issue}` : ""}
1089
- </verification>
1090
-
1091
- <output_contract>
1092
- Conclude your work naturally — summarize what was done, the current state, and what comes next.
1093
-
1094
- If this session will be consumed by another agent or skill (not a human), also include this structured JSON at the END of your response for machine parsing:
1095
- ${readOnly ? getContractTemplate("exploration") : getContractTemplate("implementation")}
1096
-
1097
- When in doubt, write for a human reader first, then append the JSON block.
1098
- </output_contract>
1099
- `;
1100
- }
1101
-
1102
- /**
1103
- * Build skill blocks that inject the full SKILL.md content so the spawned
1104
- * agent can actually follow the skill's decision trees, workflows, and patterns.
1105
- * The primary skill (first -s flag) is injected in full as the priority workflow.
1106
- * Supplementary skills are injected as available reference patterns.
1107
- */
1108
- private buildSkillRouting(skills?: string[]): string {
1109
- if (!skills || skills.length === 0) return "";
1110
-
1111
- const skillsDir = join(homedir(), ".abbie", "skills");
1112
- const primary = skills[0];
1113
- const supplementary = skills.slice(1);
1114
-
1115
- // Helper: read SKILL.md, strip YAML frontmatter, return body
1116
- const readSkillBody = (name: string): string | null => {
1117
- const skillPath = join(skillsDir, name, "SKILL.md");
1118
- if (!existsSync(skillPath)) return null;
1119
- const content = readFileSync(skillPath, "utf-8");
1120
- // Strip YAML frontmatter (---\n...\n---)
1121
- return content.replace(/^---\n[\s\S]*?\n---\n*/, "").trim();
1122
- };
1123
-
1124
- const blocks: string[] = [];
1125
-
1126
- // Primary skill: full content injection as priority workflow
1127
- const primaryBody = readSkillBody(primary);
1128
- if (primaryBody) {
1129
- blocks.push(`<skill name="${primary}" role="primary">
1130
- Follow this skill as your priority workflow. Use its decision trees, patterns, and concrete values to guide your work.
1131
-
1132
- ${primaryBody}
1133
- </skill>`);
1134
- } else {
1135
- blocks.push(`<skill name="${primary}" role="primary">
1136
- Invoke the \`${primary}\` skill to guide your workflow. (SKILL.md not found — use your knowledge of this skill.)
1137
- </skill>`);
1138
- }
1139
-
1140
- // Supplementary skills: full content as reference patterns
1141
- for (const name of supplementary) {
1142
- const body = readSkillBody(name);
1143
- if (body) {
1144
- blocks.push(`<skill name="${name}" role="supplementary">
1145
- Available as a reference pattern. Use when relevant to your task.
1146
-
1147
- ${body}
1148
- </skill>`);
1149
- }
1150
- }
1151
-
1152
- return blocks.join("\n\n") + "\n";
1153
- }
1154
-
1155
- /**
1156
- * Get read-only contract to prepend to prompts.
1157
- */
1158
- private getReadOnlyContract(): string {
1159
- return `<read_only_contract>
1160
- CRITICAL: This is a READ-ONLY session. You MUST NOT:
1161
- - Create, modify, or delete any files
1162
- - Run commands that modify state (git commit, npm install, etc.)
1163
- - Make any changes to the filesystem
1164
-
1165
- You MAY:
1166
- - Read files and explore the codebase
1167
- - Run read-only commands (git status, git log, ls, cat, etc.)
1168
- - Analyze code and provide recommendations
1169
- - Generate output/analysis in your response
1170
-
1171
- If asked to make changes, explain what changes would be needed but DO NOT execute them.
1172
- Violation of this contract will cause session termination.
1173
- </read_only_contract>
1174
-
1175
- `;
1176
- }
1177
-
1178
- /**
1179
- * Prepend read-only contract to existing content.
1180
- */
1181
- private prependReadOnlyContract(content: string): string {
1182
- return this.getReadOnlyContract() + content;
1183
- }
1184
-
1185
- // NOTE: handleExit is no longer used - the runner handles exit status.
1186
- // Exit handling is now in src/lib/runner.ts
1187
-
1188
- // =========================================================================
1189
- // Store Integration (best-effort Convex writes + async reads)
1190
- // =========================================================================
1191
-
1192
- /**
1193
- * Write session to Convex store (best-effort, non-blocking).
1194
- * Called at session start for immediate Convex visibility.
1195
- */
1196
- private async writeSessionToStore(session: ActiveSession): Promise<void> {
1197
- try {
1198
- const { getHttpClient, api } = await import("@creativeintelligence/sdk/convex");
1199
- const client = getHttpClient();
1200
- await client.mutation(api.sessions.create, {
1201
- sessionId: session.session_id,
1202
- agent: session.agent as "claude" | "codex" | "copilot" | "gemini",
1203
- project: session.project,
1204
- goal: session.goal,
1205
- issue: session.issue,
1206
- status: session.status === "running" ? "running" : "spawned",
1207
- pid: session.pid > 0 ? session.pid : undefined,
1208
- cwd: session.cwd,
1209
- deviceId: getDeviceId(),
1210
- parentSessionId: session.parent_session_id,
1211
- traceId: session.trace_id,
1212
- traceUrl: session.trace_url,
1213
- promptPath: session.prompt_path,
1214
- outputPath: session.output_path,
1215
- startCommitSha: session.start_commit_sha,
1216
- metadata: {
1217
- readOnly: session.read_only,
1218
- spawnMode: session.spawn_mode,
1219
- resultPath: session.result_path,
1220
- stdoutPath: session.stdout_path,
1221
- stderrPath: session.stderr_path,
1222
- },
1223
- });
1224
- } catch {
1225
- // Best-effort: daemon picks it up within 5s
1226
- }
1227
- }
1228
-
1229
- /**
1230
- * Update session status in Convex store (best-effort, non-blocking).
1231
- */
1232
- private async updateSessionInStore(
1233
- sessionId: string,
1234
- status: string,
1235
- metadata?: Record<string, unknown>,
1236
- ): Promise<void> {
1237
- try {
1238
- const { getHttpClient, api } = await import("@creativeintelligence/sdk/convex");
1239
- const client = getHttpClient();
1240
- await client.mutation(api.sessions.update, {
1241
- sessionId,
1242
- status: status as "completed" | "stopped" | "failed" | "running",
1243
- endedAt: ["completed", "stopped", "failed"].includes(status) ? Date.now() : undefined,
1244
- metadata,
1245
- });
1246
- } catch {
1247
- // Best-effort: daemon picks it up within 5s
1248
- }
1249
- }
1250
-
1251
- /**
1252
- * Get session by ID from Convex store with local fallback.
1253
- */
1254
- async getAsync(sessionId: string): Promise<ActiveSession | undefined> {
1255
- try {
1256
- const { getHttpClient, api } = await import("@creativeintelligence/sdk/convex");
1257
- const client = getHttpClient();
1258
- const storeSession = await client.query(api.sessions.get, { sessionId });
1259
- if (storeSession) {
1260
- return this.storeSessionToActive(
1261
- storeSession as unknown as Parameters<typeof this.storeSessionToActive>[0],
1262
- );
1263
- }
1264
- } catch {
1265
- // Fall through to local
1266
- }
1267
- return this.get(sessionId);
1268
- }
1269
-
1270
- /**
1271
- * List sessions from Convex store with local fallback.
1272
- */
1273
- async listAsync(options?: {
1274
- status?: ActiveSession["status"];
1275
- project?: string;
1276
- limit?: number;
1277
- }): Promise<ActiveSession[]> {
1278
- try {
1279
- const { getHttpClient, api } = await import("@creativeintelligence/sdk/convex");
1280
- const client = getHttpClient();
1281
- const deviceId = getDeviceId();
1282
- const storeSessions = await client.query(api.sessions.list, {
1283
- status: options?.status,
1284
- project: options?.project,
1285
- deviceId,
1286
- limit: options?.limit ?? 50,
1287
- });
1288
-
1289
- if (storeSessions.length > 0) {
1290
- const sessions = storeSessions.map((s) =>
1291
- this.storeSessionToActive(
1292
- s as unknown as Parameters<typeof this.storeSessionToActive>[0],
1293
- ),
1294
- );
1295
- // PID liveness sweep for running sessions
1296
- for (const session of sessions) {
1297
- if (
1298
- session.status === "running" &&
1299
- session.pid > 0 &&
1300
- !this.isProcessRunning(session.pid)
1301
- ) {
1302
- session.status = "failed";
1303
- }
1304
- }
1305
- return sessions;
1306
- }
1307
- } catch {
1308
- // Fall through to local
1309
- }
1310
- return this.list(options);
1311
- }
1312
-
1313
- /**
1314
- * Get active sessions from Convex store with local fallback.
1315
- */
1316
- async getActiveAsync(): Promise<ActiveSession[]> {
1317
- try {
1318
- const { getHttpClient, api } = await import("@creativeintelligence/sdk/convex");
1319
- const client = getHttpClient();
1320
- const deviceId = getDeviceId();
1321
- const storeSessions = await client.query(api.sessions.getActive, { deviceId });
1322
-
1323
- if (storeSessions.length > 0) {
1324
- const sessions = storeSessions.map((s) =>
1325
- this.storeSessionToActive(
1326
- s as unknown as Parameters<typeof this.storeSessionToActive>[0],
1327
- ),
1328
- );
1329
- // PID liveness sweep
1330
- for (const session of sessions) {
1331
- if (
1332
- session.status === "running" &&
1333
- session.pid > 0 &&
1334
- !this.isProcessRunning(session.pid)
1335
- ) {
1336
- session.status = "failed";
1337
- this.updateSessionInStore(session.session_id, "failed").catch(() => {});
1338
- }
1339
- }
1340
- return sessions;
1341
- }
1342
- } catch {
1343
- // Fall through to local
1344
- }
1345
- return this.list({ status: "running" });
1346
- }
1347
-
1348
- /**
1349
- * Convert store Session to ActiveSession format.
1350
- */
1351
- private storeSessionToActive(s: {
1352
- sessionId: string;
1353
- agent: string;
1354
- project: string;
1355
- goal?: string;
1356
- issue?: string;
1357
- status: string;
1358
- pid?: number;
1359
- cwd: string;
1360
- startedAt: number;
1361
- traceId?: string;
1362
- traceUrl?: string;
1363
- parentSessionId?: string;
1364
- promptPath?: string;
1365
- outputPath?: string;
1366
- metadata?: Record<string, unknown>;
1367
- }): ActiveSession {
1368
- const meta = (s.metadata ?? {}) as Record<string, unknown>;
1369
- return {
1370
- session_id: s.sessionId,
1371
- agent: s.agent as AgentType,
1372
- project: s.project,
1373
- goal: s.goal ?? "",
1374
- issue: s.issue,
1375
- cwd: s.cwd,
1376
- pid: s.pid ?? 0,
1377
- started_at: new Date(s.startedAt).toISOString(),
1378
- status: s.status === "spawned" ? "running" : (s.status as ActiveSession["status"]),
1379
- prompt_path: s.promptPath,
1380
- output_path: s.outputPath,
1381
- result_path: (meta.resultPath as string | undefined) ?? undefined,
1382
- stdout_path: (meta.stdoutPath as string | undefined) ?? undefined,
1383
- stderr_path: (meta.stderrPath as string | undefined) ?? undefined,
1384
- trace_id: s.traceId,
1385
- trace_url: s.traceUrl,
1386
- parent_session_id: s.parentSessionId,
1387
- read_only: meta.readOnly as boolean | undefined,
1388
- spawn_mode: meta.spawnMode as "terminal" | "headless" | "nvim-terminal" | undefined,
1389
- };
1390
- }
1391
-
1392
- /**
1393
- * Save session to disk.
1394
- */
1395
- private saveSession(session: ActiveSession): void {
1396
- const sessionPath = join(this.basePath, `${session.session_id}.json`);
1397
- const tmpPath = `${sessionPath}.tmp`;
1398
- writeFileSync(tmpPath, JSON.stringify(session, null, 2));
1399
- renameSync(tmpPath, sessionPath);
1400
- }
1401
-
1402
- private saveSessionArtifactStart(session: ActiveSession): void {
1403
- try {
1404
- this.artifactStore.saveStart({
1405
- sessionId: session.session_id,
1406
- agent: session.agent,
1407
- project: session.project,
1408
- status: session.status,
1409
- startedAt: session.started_at,
1410
- issue: session.issue,
1411
- traceId: session.trace_id,
1412
- goal: session.goal,
1413
- promptPath: session.prompt_path,
1414
- outputPath: session.output_path,
1415
- });
1416
- } catch {
1417
- // Best-effort: active session files remain source of truth.
1418
- }
1419
- }
1420
-
1421
- private markSessionArtifactComplete(
1422
- sessionId: string,
1423
- opts: {
1424
- status: SessionArtifactStatus;
1425
- exitCode?: number;
1426
- outputPath?: string;
1427
- },
1428
- ): void {
1429
- try {
1430
- this.artifactStore.markComplete(sessionId, {
1431
- status: opts.status,
1432
- exitCode: opts.exitCode,
1433
- outputPath: opts.outputPath,
1434
- });
1435
- } catch {
1436
- // Best-effort: active session files remain source of truth.
1437
- }
1438
- }
1439
-
1440
- /**
1441
- * Delete session from disk.
1442
- */
1443
- private deleteSession(sessionId: string): void {
1444
- const sessionPath = join(this.basePath, `${sessionId}.json`);
1445
- if (existsSync(sessionPath)) {
1446
- unlinkSync(sessionPath);
1447
- }
1448
- }
1449
-
1450
- /**
1451
- * Check if a process is running.
1452
- */
1453
- private isProcessRunning(pid: number): boolean {
1454
- if (pid <= 0) return false;
1455
- try {
1456
- process.kill(pid, 0);
1457
- return true;
1458
- } catch {
1459
- return false;
1460
- }
1461
- }
1462
-
1463
- /**
1464
- * Check if a tmux pane is still alive.
1465
- * Uses list-panes which returns exit 1 for nonexistent targets
1466
- * (display-message returns 0 even for dead panes).
1467
- */
1468
- private isTmuxPaneAlive(paneId: string): boolean {
1469
- const result = spawnSync("tmux", ["list-panes", "-t", paneId], {
1470
- stdio: ["ignore", "ignore", "ignore"],
1471
- });
1472
- return result.status === 0;
1473
- }
1474
- }
1475
-
1476
- /**
1477
- * Singleton instance.
1478
- */
1479
- let _manager: ActiveSessionManager | undefined;
1480
-
1481
- export function getActiveSessionManager(): ActiveSessionManager {
1482
- if (!_manager) {
1483
- _manager = new ActiveSessionManager();
1484
- }
1485
- return _manager;
1486
- }