@cortex-agent/server 2026.5.25-1 → 2026.6.11

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 (354) hide show
  1. package/defaults/config/thread-templates.json +28 -1
  2. package/defaults/hooks/cortex-md-injector.mjs +47 -31
  3. package/defaults/hooks/post-task-hook.mjs +6 -0
  4. package/defaults/hooks/task-status-check.mjs +8 -0
  5. package/defaults/mcp-config-slack.json +11 -0
  6. package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +18 -0
  7. package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +5 -6
  8. package/defaults/prompts/directives/manager.md +67 -0
  9. package/dist/agent-adapter/claude/adapter-tui.d.ts +35 -3
  10. package/dist/agent-adapter/claude/adapter-tui.js +91 -12
  11. package/dist/agent-adapter/claude/adapter.js +11 -0
  12. package/dist/agent-adapter/claude/defaults.d.ts +30 -0
  13. package/dist/agent-adapter/claude/defaults.js +30 -0
  14. package/dist/agent-adapter/claude/jsonl-tail.d.ts +2 -2
  15. package/dist/agent-adapter/claude/jsonl-tail.js +25 -20
  16. package/dist/agent-adapter/claude/spawn-args.d.ts +11 -0
  17. package/dist/agent-adapter/claude/spawn-args.js +49 -7
  18. package/dist/agent-adapter/claude/tmux-control.d.ts +20 -0
  19. package/dist/agent-adapter/claude/tmux-control.js +54 -8
  20. package/dist/agent-adapter/codex/adapter.js +1 -1
  21. package/dist/agent-adapter/normalize/event-types.d.ts +1 -0
  22. package/dist/agent-adapter/pi/adapter.js +46 -19
  23. package/dist/agent-adapter/pi/agent-dir.d.ts +21 -0
  24. package/dist/agent-adapter/pi/agent-dir.js +53 -2
  25. package/dist/agent-adapter/pi/event-parser.js +13 -1
  26. package/dist/agent-adapter/pi/mcp-bridge.d.ts +12 -0
  27. package/dist/agent-adapter/pi/mcp-bridge.js +47 -9
  28. package/dist/agent-adapter/pi/tool-shims.d.ts +14 -0
  29. package/dist/agent-adapter/pi/tool-shims.js +167 -140
  30. package/dist/agent-adapter/types.d.ts +7 -2
  31. package/dist/core/atomic-write.js +21 -0
  32. package/dist/core/config-generator.d.ts +10 -0
  33. package/dist/core/config-generator.js +28 -0
  34. package/dist/core/gateway-generator.d.ts +77 -7
  35. package/dist/core/gateway-generator.js +301 -29
  36. package/dist/core/icons.d.ts +68 -0
  37. package/dist/core/icons.js +67 -0
  38. package/dist/core/profile-generator.d.ts +6 -0
  39. package/dist/core/profile-generator.js +35 -7
  40. package/dist/core/running-executions.d.ts +51 -41
  41. package/dist/core/running-executions.js +120 -73
  42. package/dist/core/status-format.js +3 -2
  43. package/dist/core/task-parser.d.ts +3 -0
  44. package/dist/core/task-parser.js +3 -1
  45. package/dist/core/types/thread-types.d.ts +54 -8
  46. package/dist/domain/agents/facade.d.ts +18 -0
  47. package/dist/domain/agents/facade.js +26 -3
  48. package/dist/domain/agents/profile-manager.d.ts +11 -0
  49. package/dist/domain/agents/profile-manager.js +21 -2
  50. package/dist/domain/costs/codex-usage-monitor.js +2 -1
  51. package/dist/domain/costs/rate-limit-throttle.js +14 -2
  52. package/dist/domain/executions/registry.d.ts +24 -0
  53. package/dist/domain/executions/registry.js +38 -0
  54. package/dist/domain/mcp/core-server.js +15 -3
  55. package/dist/domain/mcp/feishu/bitable.d.ts +3 -0
  56. package/dist/domain/mcp/feishu/bitable.js +168 -0
  57. package/dist/domain/mcp/feishu/block-types.d.ts +44 -0
  58. package/dist/domain/mcp/feishu/block-types.js +127 -0
  59. package/dist/domain/mcp/feishu/blocks-to-text.d.ts +19 -0
  60. package/dist/domain/mcp/feishu/blocks-to-text.js +43 -0
  61. package/dist/domain/mcp/feishu/client.d.ts +46 -0
  62. package/dist/domain/mcp/feishu/client.js +87 -0
  63. package/dist/domain/mcp/feishu/docx.d.ts +3 -0
  64. package/dist/domain/mcp/feishu/docx.js +163 -0
  65. package/dist/domain/mcp/feishu/drive.d.ts +23 -0
  66. package/dist/domain/mcp/feishu/drive.js +66 -0
  67. package/dist/domain/mcp/feishu/file.d.ts +14 -0
  68. package/dist/domain/mcp/feishu/file.js +107 -0
  69. package/dist/domain/mcp/feishu/index.d.ts +6 -0
  70. package/dist/domain/mcp/feishu/index.js +61 -0
  71. package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +40 -0
  72. package/dist/domain/mcp/feishu/markdown-to-blocks.js +191 -0
  73. package/dist/domain/mcp/feishu/sheets.d.ts +3 -0
  74. package/dist/domain/mcp/feishu/sheets.js +119 -0
  75. package/dist/domain/mcp/feishu/types.d.ts +26 -0
  76. package/dist/domain/mcp/feishu/types.js +38 -0
  77. package/dist/domain/mcp/feishu/user-auth.d.ts +140 -0
  78. package/dist/domain/mcp/feishu/user-auth.js +286 -0
  79. package/dist/domain/mcp/feishu/wiki.d.ts +3 -0
  80. package/dist/domain/mcp/feishu/wiki.js +77 -0
  81. package/dist/domain/mcp/feishu-server.d.ts +2 -0
  82. package/dist/domain/mcp/feishu-server.js +33 -0
  83. package/dist/domain/mcp/server.d.ts +0 -1
  84. package/dist/domain/mcp/server.js +6 -25
  85. package/dist/domain/mcp/slack-server.d.ts +3 -0
  86. package/dist/domain/mcp/slack-server.js +46 -0
  87. package/dist/domain/mcp/tools/context.js +1 -1
  88. package/dist/domain/mcp/tools/schedule.d.ts +1 -1
  89. package/dist/domain/mcp/tools/schedule.js +6 -20
  90. package/dist/domain/mcp/tools/slack.js +20 -7
  91. package/dist/domain/mcp/tools/thread-ops.d.ts +2 -0
  92. package/dist/domain/mcp/tools/thread-ops.js +121 -0
  93. package/dist/domain/mcp/tools/time.d.ts +2 -0
  94. package/dist/domain/mcp/tools/time.js +66 -0
  95. package/dist/domain/mcp/tools/tui-ask.js +1 -1
  96. package/dist/domain/mcp/tools/tui-plan.js +2 -2
  97. package/dist/domain/mcp/tui-server.js +1 -0
  98. package/dist/domain/monitor/disk-monitor.js +2 -1
  99. package/dist/domain/monitor/gpu-monitor.js +2 -1
  100. package/dist/domain/remote/client-hot-reload.js +3 -2
  101. package/dist/domain/remote/client-manager.js +8 -6
  102. package/dist/domain/scheduling/job-registry.d.ts +4 -0
  103. package/dist/domain/scheduling/job-registry.js +1 -0
  104. package/dist/domain/scheduling/jobs/_shared.js +2 -1
  105. package/dist/domain/scheduling/jobs/memory-index-regen.js +3 -2
  106. package/dist/domain/scheduling/jobs/scheduled-task.js +9 -23
  107. package/dist/domain/scheduling/jobs/sync-public.js +4 -3
  108. package/dist/domain/scheduling/jobs/target-dispatch.d.ts +1 -8
  109. package/dist/domain/scheduling/jobs/target-dispatch.js +0 -7
  110. package/dist/domain/scheduling/jobs/task-archive.js +3 -2
  111. package/dist/domain/scheduling/jobs/task-dispatch.js +120 -10
  112. package/dist/domain/scheduling/schedule-command.js +16 -15
  113. package/dist/domain/scheduling/scheduler.d.ts +1 -1
  114. package/dist/domain/scheduling/scheduler.js +2 -1
  115. package/dist/domain/sessions/session-hooks.d.ts +2 -2
  116. package/dist/domain/sessions/session-hooks.js +19 -18
  117. package/dist/domain/sessions/session-lifecycle.d.ts +38 -0
  118. package/dist/domain/sessions/session-lifecycle.js +44 -0
  119. package/dist/domain/system/install-cli.d.ts +7 -0
  120. package/dist/domain/system/install-cli.js +106 -0
  121. package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
  122. package/dist/domain/tasks/dispatch-utils.js +53 -4
  123. package/dist/domain/tasks/dispatcher.js +26 -0
  124. package/dist/domain/tasks/lint.js +28 -0
  125. package/dist/domain/tasks/mutator.d.ts +16 -3
  126. package/dist/domain/tasks/mutator.js +41 -12
  127. package/dist/domain/tasks/pending-tracker.js +6 -5
  128. package/dist/domain/tasks/system/task-cli.d.ts +2 -0
  129. package/dist/domain/tasks/system/task-cli.js +37 -6
  130. package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
  131. package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
  132. package/dist/domain/tasks/system/task-mutations.js +166 -8
  133. package/dist/domain/threads/contract.d.ts +17 -0
  134. package/dist/domain/threads/contract.js +59 -0
  135. package/dist/domain/threads/hook-runner.js +7 -6
  136. package/dist/domain/threads/index.d.ts +2 -0
  137. package/dist/domain/threads/index.js +3 -1
  138. package/dist/domain/threads/prompt-builder.d.ts +15 -1
  139. package/dist/domain/threads/prompt-builder.js +41 -2
  140. package/dist/domain/threads/runner.d.ts +6 -5
  141. package/dist/domain/threads/runner.js +128 -79
  142. package/dist/domain/threads/state-machine.d.ts +23 -21
  143. package/dist/domain/threads/state-machine.js +113 -54
  144. package/dist/domain/threads/template-loader.js +3 -2
  145. package/dist/domain/threads/tree.d.ts +45 -0
  146. package/dist/domain/threads/tree.js +171 -0
  147. package/dist/domain/tui-session/index.d.ts +2 -0
  148. package/dist/domain/tui-session/index.js +3 -0
  149. package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
  150. package/dist/domain/tui-session/tui-session-service.js +103 -0
  151. package/dist/domain/tui-session/types.d.ts +67 -0
  152. package/dist/domain/tui-session/types.js +4 -0
  153. package/dist/domain/ui-service/index.d.ts +5 -0
  154. package/dist/domain/ui-service/index.js +3 -0
  155. package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
  156. package/dist/domain/ui-service/mutate/executions.js +15 -0
  157. package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
  158. package/dist/domain/ui-service/mutate/schedules.js +39 -0
  159. package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
  160. package/dist/domain/ui-service/mutate/tasks.js +59 -0
  161. package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
  162. package/dist/domain/ui-service/mutate/threads.js +21 -0
  163. package/dist/domain/ui-service/query/cost.d.ts +3 -0
  164. package/dist/domain/ui-service/query/cost.js +6 -0
  165. package/dist/domain/ui-service/query/executions.d.ts +2 -0
  166. package/dist/domain/ui-service/query/executions.js +35 -0
  167. package/dist/domain/ui-service/query/projects.d.ts +2 -0
  168. package/dist/domain/ui-service/query/projects.js +30 -0
  169. package/dist/domain/ui-service/query/schedules.d.ts +2 -0
  170. package/dist/domain/ui-service/query/schedules.js +23 -0
  171. package/dist/domain/ui-service/query/sessions.d.ts +2 -0
  172. package/dist/domain/ui-service/query/sessions.js +35 -0
  173. package/dist/domain/ui-service/query/tasks.d.ts +2 -0
  174. package/dist/domain/ui-service/query/tasks.js +30 -0
  175. package/dist/domain/ui-service/query/threads.d.ts +2 -0
  176. package/dist/domain/ui-service/query/threads.js +27 -0
  177. package/dist/domain/ui-service/subscribe.d.ts +5 -0
  178. package/dist/domain/ui-service/subscribe.js +118 -0
  179. package/dist/domain/ui-service/types.d.ts +237 -0
  180. package/dist/domain/ui-service/types.js +5 -0
  181. package/dist/domain/ui-service/ui-service.d.ts +2 -0
  182. package/dist/domain/ui-service/ui-service.js +83 -0
  183. package/dist/entry/app.js +94 -5
  184. package/dist/entry/cli.d.ts +12 -0
  185. package/dist/entry/cli.js +122 -12
  186. package/dist/entry/feishu-login.d.ts +28 -0
  187. package/dist/entry/feishu-login.js +218 -0
  188. package/dist/entry/init.d.ts +25 -2
  189. package/dist/entry/init.js +211 -64
  190. package/dist/events/event-types.d.ts +14 -0
  191. package/dist/hooks/cortex-md-injector.mjs +47 -31
  192. package/dist/hooks/post-task-hook.mjs +6 -0
  193. package/dist/hooks/task-status-check.mjs +8 -0
  194. package/dist/orchestration/agent-runner.d.ts +2 -1
  195. package/dist/orchestration/agent-runner.js +55 -55
  196. package/dist/orchestration/conduit-queue.d.ts +18 -0
  197. package/dist/orchestration/conduit-queue.js +32 -0
  198. package/dist/orchestration/conversation-runner.d.ts +48 -0
  199. package/dist/orchestration/conversation-runner.js +109 -0
  200. package/dist/orchestration/dispatch-reconciler.js +8 -1
  201. package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
  202. package/dist/orchestration/interactions/ask-user-question.js +3 -3
  203. package/dist/orchestration/interactions/interaction-handlers.js +48 -17
  204. package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
  205. package/dist/orchestration/interactions/plan-handler.js +4 -3
  206. package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
  207. package/dist/orchestration/interactions/update-prompt.js +100 -0
  208. package/dist/orchestration/lifecycle.d.ts +4 -4
  209. package/dist/orchestration/lifecycle.js +24 -22
  210. package/dist/orchestration/orchestrator.d.ts +1 -1
  211. package/dist/orchestration/routing/commands/cancel.js +39 -47
  212. package/dist/orchestration/routing/commands/channel.js +24 -11
  213. package/dist/orchestration/routing/commands/cost.js +2 -1
  214. package/dist/orchestration/routing/commands/device.js +3 -2
  215. package/dist/orchestration/routing/commands/dispatch.js +6 -5
  216. package/dist/orchestration/routing/commands/index.d.ts +1 -1
  217. package/dist/orchestration/routing/commands/index.js +11 -10
  218. package/dist/orchestration/routing/commands/mode.js +19 -18
  219. package/dist/orchestration/routing/commands/nvtop.js +10 -9
  220. package/dist/orchestration/routing/commands/sendfile.js +7 -6
  221. package/dist/orchestration/routing/commands/session.d.ts +1 -1
  222. package/dist/orchestration/routing/commands/session.js +17 -33
  223. package/dist/orchestration/routing/commands/tail.js +4 -3
  224. package/dist/orchestration/routing/commands/task.js +4 -3
  225. package/dist/orchestration/routing/commands/thread-handlers.js +16 -6
  226. package/dist/orchestration/routing/edit-handler.js +8 -7
  227. package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
  228. package/dist/orchestration/routing/message-router.d.ts +1 -1
  229. package/dist/orchestration/routing/message-router.js +9 -9
  230. package/dist/orchestration/routing/webhook.js +233 -2
  231. package/dist/orchestration/status-helpers.d.ts +5 -1
  232. package/dist/orchestration/status-helpers.js +7 -6
  233. package/dist/orchestration/thread-callback.d.ts +67 -0
  234. package/dist/orchestration/thread-callback.js +465 -0
  235. package/dist/orchestration/thread-executor.d.ts +22 -1
  236. package/dist/orchestration/thread-executor.js +85 -36
  237. package/dist/platform/adapter.d.ts +6 -2
  238. package/dist/platform/adapters/composite-adapter.d.ts +89 -0
  239. package/dist/platform/adapters/composite-adapter.js +318 -0
  240. package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
  241. package/dist/platform/adapters/feishu-output-stream.js +274 -36
  242. package/dist/platform/adapters/feishu.d.ts +50 -5
  243. package/dist/platform/adapters/feishu.js +370 -116
  244. package/dist/platform/adapters/index.d.ts +24 -3
  245. package/dist/platform/adapters/index.js +89 -11
  246. package/dist/platform/adapters/project-conduits.d.ts +9 -0
  247. package/dist/platform/adapters/project-conduits.js +42 -0
  248. package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
  249. package/dist/platform/adapters/slack-project-conduits.js +6 -40
  250. package/dist/platform/adapters/slack.d.ts +9 -2
  251. package/dist/platform/adapters/slack.js +83 -39
  252. package/dist/platform/adapters/tui/index.d.ts +9 -0
  253. package/dist/platform/adapters/tui/index.js +10 -0
  254. package/dist/platform/adapters/tui/ports.d.ts +20 -0
  255. package/dist/platform/adapters/tui/ports.js +4 -0
  256. package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
  257. package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
  258. package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
  259. package/dist/platform/adapters/tui/tui-connection.js +53 -0
  260. package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
  261. package/dist/platform/adapters/tui/tui-gateway.js +919 -0
  262. package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
  263. package/dist/platform/adapters/tui/tui-notifications.js +60 -0
  264. package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
  265. package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
  266. package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
  267. package/dist/platform/adapters/tui/tui-transcript.js +56 -0
  268. package/dist/platform/index.d.ts +1 -0
  269. package/dist/platform/index.js +2 -1
  270. package/dist/platform/interactive-builder.js +3 -2
  271. package/dist/platform/output-stream.d.ts +5 -0
  272. package/dist/platform/testing.d.ts +7 -11
  273. package/dist/platform/testing.js +18 -15
  274. package/dist/platform/tool-trace.js +15 -5
  275. package/dist/platform/tui/protocol.d.ts +355 -0
  276. package/dist/platform/tui/protocol.js +199 -0
  277. package/dist/platform/types.d.ts +12 -3
  278. package/dist/store/execution-repo.d.ts +6 -1
  279. package/dist/store/execution-repo.js +13 -3
  280. package/dist/store/hook-sync.d.ts +18 -0
  281. package/dist/store/hook-sync.js +92 -0
  282. package/dist/store/outbound-queue.js +2 -2
  283. package/dist/store/profile-repo.js +3 -2
  284. package/dist/store/schedule-repo.d.ts +1 -8
  285. package/dist/store/session-registry-repo.d.ts +9 -1
  286. package/dist/store/session-registry-repo.js +19 -3
  287. package/dist/store/session-repo.d.ts +14 -0
  288. package/dist/store/session-repo.js +23 -0
  289. package/dist/store/thread-repo.d.ts +3 -0
  290. package/dist/store/thread-repo.js +49 -2
  291. package/dist/store/version-migrations.js +95 -0
  292. package/dist/tui/App.d.ts +27 -0
  293. package/dist/tui/App.js +219 -0
  294. package/dist/tui/components/AskUserModal.d.ts +11 -0
  295. package/dist/tui/components/AskUserModal.js +364 -0
  296. package/dist/tui/components/ConfirmModal.d.ts +12 -0
  297. package/dist/tui/components/ConfirmModal.js +31 -0
  298. package/dist/tui/components/Dashboard.d.ts +23 -0
  299. package/dist/tui/components/Dashboard.js +80 -0
  300. package/dist/tui/components/DashboardCostTab.d.ts +7 -0
  301. package/dist/tui/components/DashboardCostTab.js +16 -0
  302. package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
  303. package/dist/tui/components/DashboardExecutionsTab.js +94 -0
  304. package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
  305. package/dist/tui/components/DashboardSchedulesTab.js +124 -0
  306. package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
  307. package/dist/tui/components/DashboardTasksTab.js +200 -0
  308. package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
  309. package/dist/tui/components/DashboardThreadsTab.js +81 -0
  310. package/dist/tui/components/Header.d.ts +11 -0
  311. package/dist/tui/components/Header.js +5 -0
  312. package/dist/tui/components/InputBox.d.ts +10 -0
  313. package/dist/tui/components/InputBox.js +19 -0
  314. package/dist/tui/components/MessageRow.d.ts +7 -0
  315. package/dist/tui/components/MessageRow.js +10 -0
  316. package/dist/tui/components/Notifications.d.ts +19 -0
  317. package/dist/tui/components/Notifications.js +72 -0
  318. package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
  319. package/dist/tui/components/PlanFeedbackModal.js +161 -0
  320. package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
  321. package/dist/tui/components/ProjectSwitcher.js +43 -0
  322. package/dist/tui/components/SessionPicker.d.ts +14 -0
  323. package/dist/tui/components/SessionPicker.js +34 -0
  324. package/dist/tui/components/SidePanel.d.ts +19 -0
  325. package/dist/tui/components/SidePanel.js +8 -0
  326. package/dist/tui/components/StatusLine.d.ts +10 -0
  327. package/dist/tui/components/StatusLine.js +29 -0
  328. package/dist/tui/components/Transcript.d.ts +13 -0
  329. package/dist/tui/components/Transcript.js +56 -0
  330. package/dist/tui/hooks/useDashboardData.d.ts +32 -0
  331. package/dist/tui/hooks/useDashboardData.js +104 -0
  332. package/dist/tui/hooks/useKeybindings.d.ts +19 -0
  333. package/dist/tui/hooks/useKeybindings.js +87 -0
  334. package/dist/tui/hooks/useMutate.d.ts +22 -0
  335. package/dist/tui/hooks/useMutate.js +56 -0
  336. package/dist/tui/hooks/useNotifications.d.ts +28 -0
  337. package/dist/tui/hooks/useNotifications.js +70 -0
  338. package/dist/tui/hooks/useTranscript.d.ts +39 -0
  339. package/dist/tui/hooks/useTranscript.js +265 -0
  340. package/dist/tui/hooks/useWsClient.d.ts +29 -0
  341. package/dist/tui/hooks/useWsClient.js +69 -0
  342. package/dist/tui/index.d.ts +2 -0
  343. package/dist/tui/index.js +210 -0
  344. package/dist/tui/logic.d.ts +16 -0
  345. package/dist/tui/logic.js +49 -0
  346. package/dist/tui/render/markdown.d.ts +10 -0
  347. package/dist/tui/render/markdown.js +38 -0
  348. package/dist/tui/render/rich-blocks.d.ts +11 -0
  349. package/dist/tui/render/rich-blocks.js +24 -0
  350. package/dist/tui/ws-client.d.ts +44 -0
  351. package/dist/tui/ws-client.js +157 -0
  352. package/package.json +11 -3
  353. package/dist/orchestration/channel-queue.d.ts +0 -18
  354. package/dist/orchestration/channel-queue.js +0 -32
@@ -0,0 +1,35 @@
1
+ // input: UiServiceDeps + ExecutionsListParams
2
+ // output: handleExecutionsList → ExecutionInfo[]
3
+ // pos: query handler for 'executions.list'
4
+ export async function handleExecutionsList(deps, params) {
5
+ const { status, limit } = params;
6
+ let executions = deps.executionRegistry.getAll();
7
+ if (status && status.length > 0) {
8
+ const statusSet = new Set(status);
9
+ executions = executions.filter((e) => statusSet.has(e.status));
10
+ }
11
+ // Sort by startedAt descending
12
+ executions.sort((a, b) => (b.runtime?.startedAt || '').localeCompare(a.runtime?.startedAt || ''));
13
+ if (limit && limit > 0) {
14
+ executions = executions.slice(0, limit);
15
+ }
16
+ return executions.map((e) => {
17
+ const startedAt = e.runtime?.startedAt || '';
18
+ const finishedAt = e.runtime?.endedAt || null;
19
+ const startMs = new Date(startedAt).getTime();
20
+ const endMs = finishedAt ? new Date(finishedAt).getTime() : null;
21
+ return {
22
+ id: e.id,
23
+ type: e.kind === 'dispatch' ? 'dispatch' : 'local',
24
+ status: e.status,
25
+ taskId: e.dispatch?.taskId ?? null,
26
+ sessionId: e.session?.sessionId ?? null,
27
+ projectId: e.project ?? null,
28
+ machine: e.dispatch?.machine ?? null,
29
+ startedAt,
30
+ finishedAt,
31
+ durationMs: endMs ? endMs - startMs : null,
32
+ cost: e.metrics?.costUsd ?? null,
33
+ };
34
+ });
35
+ }
@@ -0,0 +1,2 @@
1
+ import type { UiServiceDeps, ProjectConduitInfo } from '../types.js';
2
+ export declare function handleProjectsList(deps: UiServiceDeps): Promise<ProjectConduitInfo[]>;
@@ -0,0 +1,30 @@
1
+ // input: UiServiceDeps
2
+ // output: handleProjectsList → ProjectConduitInfo[]
3
+ // pos: query handler for 'projects.list'
4
+ import * as fs from 'node:fs';
5
+ import * as path from 'node:path';
6
+ function projectHasMission(contextDir) {
7
+ try {
8
+ return fs.existsSync(path.join(contextDir, 'mission.md'));
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
14
+ export async function handleProjectsList(deps) {
15
+ const projects = deps.projectStore.list();
16
+ let conduits = {};
17
+ try {
18
+ conduits = await deps.adapter.getProjectConduits();
19
+ }
20
+ catch {
21
+ // conduit lookup failure is non-fatal; projects still listed with empty conduits
22
+ }
23
+ return projects.map((p) => ({
24
+ id: p.id,
25
+ kind: p.kind === 'general' ? 'general' : 'research',
26
+ contextDir: p.contextDir,
27
+ hasMission: projectHasMission(p.contextDir),
28
+ conduits,
29
+ }));
30
+ }
@@ -0,0 +1,2 @@
1
+ import type { UiServiceDeps, ScheduleInfo, SchedulesListParams } from '../types.js';
2
+ export declare function handleSchedulesList(deps: UiServiceDeps, params: SchedulesListParams): Promise<ScheduleInfo[]>;
@@ -0,0 +1,23 @@
1
+ // input: UiServiceDeps + SchedulesListParams
2
+ // output: handleSchedulesList → ScheduleInfo[]
3
+ // pos: query handler for 'schedules.list'
4
+ export async function handleSchedulesList(deps, params) {
5
+ const { projectId, paused } = params;
6
+ let schedules = await deps.scheduler.list();
7
+ if (projectId) {
8
+ schedules = schedules.filter((s) => s.projectId === projectId);
9
+ }
10
+ if (paused !== undefined) {
11
+ schedules = schedules.filter((s) => (s.isPaused ?? false) === paused);
12
+ }
13
+ return schedules.map((s) => ({
14
+ id: s.id,
15
+ type: s.type,
16
+ message: s.message,
17
+ projectId: s.projectId,
18
+ nextRun: s.nextRun != null ? new Date(s.nextRun).toISOString() : null,
19
+ lastRun: s.lastRun != null ? new Date(s.lastRun).toISOString() : null,
20
+ paused: s.isPaused ?? false,
21
+ pausedBy: s.pausedBy ?? null,
22
+ }));
23
+ }
@@ -0,0 +1,2 @@
1
+ import type { UiServiceDeps, SessionInfo, SessionsListParams } from '../types.js';
2
+ export declare function handleSessionsList(deps: UiServiceDeps, params: SessionsListParams): Promise<SessionInfo[]>;
@@ -0,0 +1,35 @@
1
+ // input: UiServiceDeps + SessionsListParams
2
+ // output: handleSessionsList → SessionInfo[]
3
+ // pos: query handler for 'sessions.list'
4
+ export async function handleSessionsList(deps, params) {
5
+ const { projectId, resumable } = params;
6
+ let sessions;
7
+ if (resumable) {
8
+ sessions = await deps.sessionStore.listResumable(projectId);
9
+ }
10
+ else if (projectId) {
11
+ sessions = await deps.sessionStore.listByProject(projectId);
12
+ }
13
+ else {
14
+ // list all — iterate through listByProject for each known project
15
+ // or fall back to listing all sessions via the store
16
+ const allProjects = deps.projectStore.list();
17
+ const results = [];
18
+ for (const p of allProjects) {
19
+ const projectSessions = await deps.sessionStore.listByProject(p.id);
20
+ results.push(...projectSessions);
21
+ }
22
+ sessions = results;
23
+ }
24
+ return sessions.map((s) => ({
25
+ sessionId: s.sessionId,
26
+ name: s.name,
27
+ projectId: s.projectId,
28
+ backend: s.backend,
29
+ kind: s.kind,
30
+ createdAt: s.createdAt,
31
+ lastUsedAt: s.lastUsedAt,
32
+ resumable: s.kind !== 'scheduled',
33
+ label: s.label ?? null,
34
+ }));
35
+ }
@@ -0,0 +1,2 @@
1
+ import type { UiServiceDeps, TaskInfo, TasksListParams } from '../types.js';
2
+ export declare function handleTasksList(deps: UiServiceDeps, params: TasksListParams): Promise<TaskInfo[]>;
@@ -0,0 +1,30 @@
1
+ // input: UiServiceDeps + TasksListParams
2
+ // output: handleTasksList → TaskInfo[]
3
+ // pos: query handler for 'tasks.list'
4
+ export async function handleTasksList(deps, params) {
5
+ const { projectId, status, actionable } = params;
6
+ deps.taskStore.refresh();
7
+ let tasks = deps.taskStore.getAll(projectId || undefined);
8
+ if (status) {
9
+ tasks = tasks.filter((t) => t.status === status);
10
+ }
11
+ if (actionable !== undefined) {
12
+ tasks = tasks.filter((t) => {
13
+ const isActionable = t.status === 'open' && !t.claimed_by && !t.blocked_by && !t.paused;
14
+ return actionable ? isActionable : !isActionable;
15
+ });
16
+ }
17
+ return tasks.map((t) => ({
18
+ id: t.id,
19
+ text: t.text,
20
+ project: t.project,
21
+ status: t.status === 'done' ? 'done' : 'open',
22
+ priority: t.priority || 'medium',
23
+ actionable: !!(t.status === 'open' && !t.claimed_by && !t.blocked_by && !t.paused),
24
+ claimedBy: t.claimed_by ?? null,
25
+ blockedBy: t.blocked_by ?? null,
26
+ dependsOn: t.depends_on || [],
27
+ plan: t.plan ?? null,
28
+ template: t.template || 'coder-review',
29
+ }));
30
+ }
@@ -0,0 +1,2 @@
1
+ import type { UiServiceDeps, ThreadInfo, ThreadsListParams } from '../types.js';
2
+ export declare function handleThreadsList(deps: UiServiceDeps, params: ThreadsListParams): Promise<ThreadInfo[]>;
@@ -0,0 +1,27 @@
1
+ // input: UiServiceDeps + ThreadsListParams
2
+ // output: handleThreadsList → ThreadInfo[]
3
+ // pos: query handler for 'threads.list'
4
+ export async function handleThreadsList(deps, params) {
5
+ const { projectId, status } = params;
6
+ let threads = deps.threadStore.getAll();
7
+ if (projectId) {
8
+ threads = threads.filter((t) => t.projectId === projectId);
9
+ }
10
+ if (status && status.length > 0) {
11
+ const statusSet = new Set(status);
12
+ threads = threads.filter((t) => statusSet.has(t.status));
13
+ }
14
+ return threads.map((t) => ({
15
+ id: t.id,
16
+ templateName: t.templateName || 'unknown',
17
+ currentStep: t.currentStepIndex != null
18
+ ? { index: t.currentStepIndex, name: t.currentStepName || `step-${t.currentStepIndex}` }
19
+ : null,
20
+ status: t.status,
21
+ projectId: t.projectId,
22
+ createdAt: t.createdAt,
23
+ updatedAt: t.updatedAt,
24
+ totalSteps: (t.template?.agents?.length) || t.steps?.length || 0,
25
+ artifactPath: t.artifactPath ?? null,
26
+ }));
27
+ }
@@ -0,0 +1,5 @@
1
+ import type { EventBus } from '../../events/index.js';
2
+ import type { SubscribeFilter, UiEvent } from './types.js';
3
+ export declare function createSubscription(bus: EventBus, filter: SubscribeFilter): AsyncIterable<UiEvent> & {
4
+ close(): void;
5
+ };
@@ -0,0 +1,118 @@
1
+ // input: EventBus + SubscribeFilter
2
+ // output: AsyncIterable<UiEvent> & { close() } — bounded queue, overflow emits synthetic dropped event
3
+ // pos: subscribe primitive for UiService
4
+ const QUEUE_CAP = 256;
5
+ /**
6
+ * Create an async queue with bounded capacity. When `onOverflow` is set, it
7
+ * is called from within a re-entrant guard so that push() calls from the
8
+ * callback do not recursively trigger overflow — guaranteeing that exactly
9
+ * one oldest item is dropped per real overflow.
10
+ */
11
+ function createAsyncQueue(cap, onOverflow) {
12
+ const buffer = [];
13
+ let resolve = null;
14
+ let _closed = false;
15
+ let _inOverflow = false;
16
+ return {
17
+ push(item) {
18
+ if (_closed)
19
+ return;
20
+ if (!_inOverflow && buffer.length >= cap) {
21
+ buffer.shift();
22
+ if (onOverflow) {
23
+ _inOverflow = true;
24
+ try {
25
+ onOverflow();
26
+ }
27
+ finally {
28
+ _inOverflow = false;
29
+ }
30
+ }
31
+ }
32
+ if (resolve) {
33
+ const r = resolve;
34
+ resolve = null;
35
+ r({ value: item, done: false });
36
+ }
37
+ else {
38
+ buffer.push(item);
39
+ }
40
+ },
41
+ close() {
42
+ _closed = true;
43
+ if (resolve) {
44
+ const r = resolve;
45
+ resolve = null;
46
+ r({ value: undefined, done: true });
47
+ }
48
+ },
49
+ [Symbol.asyncIterator]() {
50
+ return {
51
+ next: () => {
52
+ if (buffer.length > 0) {
53
+ const value = buffer.shift();
54
+ return Promise.resolve({ value, done: false });
55
+ }
56
+ if (_closed) {
57
+ return Promise.resolve({ value: undefined, done: true });
58
+ }
59
+ return new Promise((res) => {
60
+ resolve = res;
61
+ });
62
+ },
63
+ };
64
+ },
65
+ };
66
+ }
67
+ export function createSubscription(bus, filter) {
68
+ const eventTypes = filter.events;
69
+ const projectId = filter.projectId ?? null;
70
+ let droppedCount = 0;
71
+ // Wire overflow handler: push a synthetic UiEvent onto the queue.
72
+ // The queue's _inOverflow guard ensures push() from this callback does
73
+ // NOT re-trigger overflow, so the synthetic always lands safely.
74
+ const queue = createAsyncQueue(QUEUE_CAP, () => {
75
+ droppedCount++;
76
+ const synthetic = {
77
+ type: 'ui-subscribe.dropped',
78
+ ts: new Date().toISOString(),
79
+ payload: { droppedCount },
80
+ };
81
+ // push() from within the guard: no overflow shift, item always appended.
82
+ queue.push(synthetic);
83
+ });
84
+ const subscriptions = eventTypes.map((type) => {
85
+ const sub = bus.subscribe(type, (event) => {
86
+ // Post-filter by projectId if specified
87
+ if (projectId && event.projectId && event.projectId !== projectId) {
88
+ return;
89
+ }
90
+ if (projectId && event.payload?.projectId && event.payload.projectId !== projectId) {
91
+ return;
92
+ }
93
+ const uiEvent = {
94
+ type: event.type,
95
+ ts: event.ts,
96
+ payload: event,
97
+ };
98
+ queue.push(uiEvent);
99
+ });
100
+ return sub;
101
+ });
102
+ let closed = false;
103
+ const close = () => {
104
+ if (closed)
105
+ return;
106
+ closed = true;
107
+ for (const sub of subscriptions) {
108
+ sub.unsubscribe();
109
+ }
110
+ queue.close();
111
+ };
112
+ return {
113
+ [Symbol.asyncIterator]() {
114
+ return queue[Symbol.asyncIterator]();
115
+ },
116
+ close,
117
+ };
118
+ }
@@ -0,0 +1,237 @@
1
+ import type { Project } from '../projects/index.js';
2
+ import type { CostSummary } from '../costs/cost-tracker.js';
3
+ import type { EventBus } from '../../events/index.js';
4
+ import type { RunningExecutions } from '../../core/running-executions.js';
5
+ import type { PlatformAdapter } from '../../platform/adapter.js';
6
+ import type { Session } from '../../store/session-registry-repo.js';
7
+ import type { ScheduleTask } from '../../store/schedule-repo.js';
8
+ export type Ok<T> = {
9
+ ok: true;
10
+ data: T;
11
+ };
12
+ export type Err = {
13
+ ok: false;
14
+ code: string;
15
+ message: string;
16
+ };
17
+ export type Result<T> = Ok<T> | Err;
18
+ export type QueryScope = 'projects.list' | 'sessions.list' | 'threads.list' | 'tasks.list' | 'schedules.list' | 'executions.list' | 'cost.summary';
19
+ export type MutateOp = 'threads.cancel' | 'executions.cancel' | 'schedules.pause' | 'schedules.resume' | 'schedules.remove' | 'tasks.claim' | 'tasks.unclaim' | 'tasks.complete' | 'tasks.block' | 'tasks.unblock';
20
+ export interface SubscribeFilter {
21
+ events: string[];
22
+ projectId?: string | null;
23
+ }
24
+ export interface UiEvent {
25
+ type: string;
26
+ ts: string;
27
+ payload: unknown;
28
+ }
29
+ export interface SessionsListParams {
30
+ projectId?: string;
31
+ resumable?: boolean;
32
+ }
33
+ export interface ThreadsListParams {
34
+ projectId?: string;
35
+ status?: string[];
36
+ }
37
+ export interface TasksListParams {
38
+ projectId?: string;
39
+ status?: 'open' | 'done';
40
+ actionable?: boolean;
41
+ }
42
+ export interface SchedulesListParams {
43
+ projectId?: string;
44
+ paused?: boolean;
45
+ }
46
+ export interface ExecutionsListParams {
47
+ status?: string[];
48
+ limit?: number;
49
+ }
50
+ export interface CostSummaryParams {
51
+ projectId?: string | null;
52
+ }
53
+ export interface ThreadsCancelArgs {
54
+ threadId: string;
55
+ }
56
+ export interface ExecutionsCancelArgs {
57
+ executionId: string;
58
+ }
59
+ export interface ScheduleActionArgs {
60
+ scheduleId: string;
61
+ }
62
+ export interface TaskActionArgs {
63
+ projectId: string;
64
+ taskId: string;
65
+ }
66
+ export interface TaskCompleteArgs extends TaskActionArgs {
67
+ note?: string;
68
+ }
69
+ export interface TaskBlockArgs extends TaskActionArgs {
70
+ reason: string;
71
+ }
72
+ export interface ProjectConduitInfo {
73
+ id: string;
74
+ kind: 'research' | 'general';
75
+ contextDir: string;
76
+ hasMission: boolean;
77
+ conduits: Record<string, string>;
78
+ }
79
+ export interface SessionInfo {
80
+ sessionId: string;
81
+ name: string;
82
+ projectId: string;
83
+ backend: string;
84
+ kind: 'local' | 'scheduled';
85
+ createdAt: string;
86
+ lastUsedAt: string;
87
+ resumable: boolean;
88
+ label: string | null;
89
+ }
90
+ export interface ThreadInfo {
91
+ id: string;
92
+ templateName: string;
93
+ currentStep: {
94
+ index: number;
95
+ name: string;
96
+ } | null;
97
+ status: 'running' | 'waiting' | 'completed' | 'failed' | 'cancelled' | 'aborted';
98
+ projectId: string;
99
+ createdAt: string;
100
+ updatedAt: string;
101
+ totalSteps: number;
102
+ artifactPath: string | null;
103
+ }
104
+ export interface TaskInfo {
105
+ id: string;
106
+ text: string;
107
+ project: string;
108
+ status: 'open' | 'done';
109
+ priority: 'high' | 'medium' | 'low';
110
+ actionable: boolean;
111
+ claimedBy: string | null;
112
+ blockedBy: string | null;
113
+ dependsOn: string[];
114
+ plan: string | null;
115
+ template: string;
116
+ }
117
+ export interface ScheduleInfo {
118
+ id: string;
119
+ type: 'interval' | 'daily' | 'weekly' | 'once';
120
+ message: string;
121
+ projectId: string;
122
+ nextRun: string | null;
123
+ lastRun: string | null;
124
+ paused: boolean;
125
+ pausedBy: string | null;
126
+ }
127
+ export interface ExecutionInfo {
128
+ id: string;
129
+ type: 'local' | 'dispatch';
130
+ status: 'running' | 'completed' | 'failed' | 'cancelled' | 'stale';
131
+ taskId: string | null;
132
+ sessionId: string | null;
133
+ projectId: string | null;
134
+ machine: string | null;
135
+ startedAt: string;
136
+ finishedAt: string | null;
137
+ durationMs: number | null;
138
+ cost: number | null;
139
+ }
140
+ export interface ThreadsCancelReturn {
141
+ cancelled: boolean;
142
+ }
143
+ export interface ExecutionsCancelReturn {
144
+ cancelled: boolean;
145
+ }
146
+ export interface QueryParamMap {
147
+ 'projects.list': Record<string, never>;
148
+ 'sessions.list': SessionsListParams;
149
+ 'threads.list': ThreadsListParams;
150
+ 'tasks.list': TasksListParams;
151
+ 'schedules.list': SchedulesListParams;
152
+ 'executions.list': ExecutionsListParams;
153
+ 'cost.summary': CostSummaryParams;
154
+ }
155
+ export interface QueryReturnMap {
156
+ 'projects.list': ProjectConduitInfo[];
157
+ 'sessions.list': SessionInfo[];
158
+ 'threads.list': ThreadInfo[];
159
+ 'tasks.list': TaskInfo[];
160
+ 'schedules.list': ScheduleInfo[];
161
+ 'executions.list': ExecutionInfo[];
162
+ 'cost.summary': CostSummary;
163
+ }
164
+ export interface MutateArgsMap {
165
+ 'threads.cancel': ThreadsCancelArgs;
166
+ 'executions.cancel': ExecutionsCancelArgs;
167
+ 'schedules.pause': ScheduleActionArgs;
168
+ 'schedules.resume': ScheduleActionArgs;
169
+ 'schedules.remove': ScheduleActionArgs;
170
+ 'tasks.claim': TaskActionArgs;
171
+ 'tasks.unclaim': TaskActionArgs;
172
+ 'tasks.complete': TaskCompleteArgs;
173
+ 'tasks.block': TaskBlockArgs;
174
+ 'tasks.unblock': TaskActionArgs;
175
+ }
176
+ export interface MutateReturnMap {
177
+ 'threads.cancel': ThreadsCancelReturn;
178
+ 'executions.cancel': ExecutionsCancelReturn;
179
+ 'schedules.pause': void;
180
+ 'schedules.resume': void;
181
+ 'schedules.remove': void;
182
+ 'tasks.claim': void;
183
+ 'tasks.unclaim': void;
184
+ 'tasks.complete': void;
185
+ 'tasks.block': void;
186
+ 'tasks.unblock': void;
187
+ }
188
+ export type QueryParams<S extends QueryScope> = S extends keyof QueryParamMap ? QueryParamMap[S] : never;
189
+ export type QueryReturn<S extends QueryScope> = S extends keyof QueryReturnMap ? QueryReturnMap[S] : never;
190
+ export type MutateArgs<O extends MutateOp> = O extends keyof MutateArgsMap ? MutateArgsMap[O] : never;
191
+ export type MutateReturn<O extends MutateOp> = O extends keyof MutateReturnMap ? MutateReturnMap[O] : never;
192
+ export interface UiService {
193
+ query<S extends QueryScope>(scope: S, params: QueryParams<S>): Promise<Result<QueryReturn<S>>>;
194
+ mutate<O extends MutateOp>(op: O, args: MutateArgs<O>): Promise<Result<MutateReturn<O>>>;
195
+ subscribe(filter: SubscribeFilter): AsyncIterable<UiEvent> & {
196
+ close(): void;
197
+ };
198
+ }
199
+ export interface UiServiceDeps {
200
+ projectStore: {
201
+ list(): Project[];
202
+ get(id: string): Project | undefined;
203
+ exists(id: string): boolean;
204
+ getDefault(): Project;
205
+ };
206
+ sessionStore: {
207
+ listByProject(projectId: string): Promise<Session[]>;
208
+ listResumable(projectId?: string): Promise<Session[]>;
209
+ getById(sessionId: string): Promise<Session | null>;
210
+ };
211
+ threadStore: {
212
+ getAll(): any[];
213
+ get(id: string): any | null;
214
+ };
215
+ taskStore: {
216
+ getAll(project?: string): any[];
217
+ getById(taskId: string): any | null;
218
+ load(): void;
219
+ refresh(): void;
220
+ };
221
+ scheduler: {
222
+ list(): Promise<ScheduleTask[]>;
223
+ get(id: string): Promise<ScheduleTask | null>;
224
+ pause(id: string, pausedBy?: 'user' | 'rate-limit'): Promise<ScheduleTask | null>;
225
+ resume(id: string): Promise<ScheduleTask | null>;
226
+ remove(id: string): Promise<boolean>;
227
+ };
228
+ executionRegistry: {
229
+ getExecution(id: string): any | null;
230
+ getAll(): any[];
231
+ cancelExecution(id: string, metrics?: any): any | null;
232
+ };
233
+ runningExecutions: RunningExecutions;
234
+ costSummary: (projectId?: string | null) => Promise<CostSummary>;
235
+ bus: EventBus;
236
+ adapter: PlatformAdapter;
237
+ }
@@ -0,0 +1,5 @@
1
+ // input: nothing (leaf module)
2
+ // output: UiService types — Result, QueryScope, MutateOp, DTOs, UiService interface, UiServiceDeps
3
+ // pos: leaf types module, depends only on domain types pulled in by query/mutate handlers
4
+ // >>> If I am updated, update CORTEX.md and the parent folder's CORTEX.md <<<
5
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { UiServiceDeps, UiService } from './types.js';
2
+ export declare function createUiService(deps: UiServiceDeps): UiService;
@@ -0,0 +1,83 @@
1
+ // input: UiServiceDeps
2
+ // output: createUiService(deps): UiService — facade routing scope/op strings to per-module handlers
3
+ // pos: transport-agnostic UI service facade
4
+ import { handleProjectsList } from './query/projects.js';
5
+ import { handleSessionsList } from './query/sessions.js';
6
+ import { handleThreadsList } from './query/threads.js';
7
+ import { handleTasksList } from './query/tasks.js';
8
+ import { handleSchedulesList } from './query/schedules.js';
9
+ import { handleExecutionsList } from './query/executions.js';
10
+ import { handleCostSummary } from './query/cost.js';
11
+ import { handleCancelThread } from './mutate/threads.js';
12
+ import { handleCancelExecution } from './mutate/executions.js';
13
+ import { handlePauseSchedule, handleResumeSchedule, handleRemoveSchedule, } from './mutate/schedules.js';
14
+ import { handleClaimTask, handleUnclaimTask, handleCompleteTask, handleBlockTask, handleUnblockTask, } from './mutate/tasks.js';
15
+ import { createSubscription } from './subscribe.js';
16
+ const queryHandlers = {
17
+ 'projects.list': (deps) => handleProjectsList(deps),
18
+ 'sessions.list': (deps, params) => handleSessionsList(deps, params),
19
+ 'threads.list': (deps, params) => handleThreadsList(deps, params),
20
+ 'tasks.list': (deps, params) => handleTasksList(deps, params),
21
+ 'schedules.list': (deps, params) => handleSchedulesList(deps, params),
22
+ 'executions.list': (deps, params) => handleExecutionsList(deps, params),
23
+ 'cost.summary': (deps, params) => handleCostSummary(deps, params),
24
+ };
25
+ const mutateHandlers = {
26
+ 'threads.cancel': (deps, args) => handleCancelThread(deps, args),
27
+ 'executions.cancel': (deps, args) => handleCancelExecution(deps, args),
28
+ 'schedules.pause': (deps, args) => handlePauseSchedule(deps, args),
29
+ 'schedules.resume': (deps, args) => handleResumeSchedule(deps, args),
30
+ 'schedules.remove': (deps, args) => handleRemoveSchedule(deps, args),
31
+ 'tasks.claim': (deps, args) => handleClaimTask(deps, args),
32
+ 'tasks.unclaim': (deps, args) => handleUnclaimTask(deps, args),
33
+ 'tasks.complete': (deps, args) => handleCompleteTask(deps, args),
34
+ 'tasks.block': (deps, args) => handleBlockTask(deps, args),
35
+ 'tasks.unblock': (deps, args) => handleUnblockTask(deps, args),
36
+ };
37
+ export function createUiService(deps) {
38
+ return {
39
+ async query(scope, params) {
40
+ const handler = queryHandlers[scope];
41
+ if (!handler) {
42
+ return { ok: false, code: 'invalid-args', message: `Unknown query scope: ${scope}` };
43
+ }
44
+ try {
45
+ const data = await handler(deps, params);
46
+ return { ok: true, data };
47
+ }
48
+ catch (err) {
49
+ return { ok: false, code: 'internal', message: err?.message || String(err) };
50
+ }
51
+ },
52
+ async mutate(op, args) {
53
+ const handler = mutateHandlers[op];
54
+ if (!handler) {
55
+ return { ok: false, code: 'invalid-args', message: `Unknown mutate op: ${op}` };
56
+ }
57
+ try {
58
+ const result = await handler(deps, args);
59
+ // Publish audit event before returning
60
+ deps.bus.publish({
61
+ type: 'ui.mutate-invoked',
62
+ op,
63
+ args,
64
+ result: result.ok ? { ok: true } : { ok: false, code: result.code },
65
+ });
66
+ return result;
67
+ }
68
+ catch (err) {
69
+ const errResult = { ok: false, code: 'internal', message: err?.message || String(err) };
70
+ deps.bus.publish({
71
+ type: 'ui.mutate-invoked',
72
+ op,
73
+ args,
74
+ result: { ok: false, code: 'internal' },
75
+ });
76
+ return errResult;
77
+ }
78
+ },
79
+ subscribe(filter) {
80
+ return createSubscription(deps.bus, filter);
81
+ },
82
+ };
83
+ }