@cortex-agent/server 2026.5.25 → 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 (355) 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/system/server-update-check.js +2 -2
  122. package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
  123. package/dist/domain/tasks/dispatch-utils.js +53 -4
  124. package/dist/domain/tasks/dispatcher.js +26 -0
  125. package/dist/domain/tasks/lint.js +28 -0
  126. package/dist/domain/tasks/mutator.d.ts +16 -3
  127. package/dist/domain/tasks/mutator.js +41 -12
  128. package/dist/domain/tasks/pending-tracker.js +6 -5
  129. package/dist/domain/tasks/system/task-cli.d.ts +2 -0
  130. package/dist/domain/tasks/system/task-cli.js +37 -6
  131. package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
  132. package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
  133. package/dist/domain/tasks/system/task-mutations.js +166 -8
  134. package/dist/domain/threads/contract.d.ts +17 -0
  135. package/dist/domain/threads/contract.js +59 -0
  136. package/dist/domain/threads/hook-runner.js +7 -6
  137. package/dist/domain/threads/index.d.ts +2 -0
  138. package/dist/domain/threads/index.js +3 -1
  139. package/dist/domain/threads/prompt-builder.d.ts +15 -1
  140. package/dist/domain/threads/prompt-builder.js +41 -2
  141. package/dist/domain/threads/runner.d.ts +6 -5
  142. package/dist/domain/threads/runner.js +128 -79
  143. package/dist/domain/threads/state-machine.d.ts +23 -21
  144. package/dist/domain/threads/state-machine.js +113 -54
  145. package/dist/domain/threads/template-loader.js +3 -2
  146. package/dist/domain/threads/tree.d.ts +45 -0
  147. package/dist/domain/threads/tree.js +171 -0
  148. package/dist/domain/tui-session/index.d.ts +2 -0
  149. package/dist/domain/tui-session/index.js +3 -0
  150. package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
  151. package/dist/domain/tui-session/tui-session-service.js +103 -0
  152. package/dist/domain/tui-session/types.d.ts +67 -0
  153. package/dist/domain/tui-session/types.js +4 -0
  154. package/dist/domain/ui-service/index.d.ts +5 -0
  155. package/dist/domain/ui-service/index.js +3 -0
  156. package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
  157. package/dist/domain/ui-service/mutate/executions.js +15 -0
  158. package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
  159. package/dist/domain/ui-service/mutate/schedules.js +39 -0
  160. package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
  161. package/dist/domain/ui-service/mutate/tasks.js +59 -0
  162. package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
  163. package/dist/domain/ui-service/mutate/threads.js +21 -0
  164. package/dist/domain/ui-service/query/cost.d.ts +3 -0
  165. package/dist/domain/ui-service/query/cost.js +6 -0
  166. package/dist/domain/ui-service/query/executions.d.ts +2 -0
  167. package/dist/domain/ui-service/query/executions.js +35 -0
  168. package/dist/domain/ui-service/query/projects.d.ts +2 -0
  169. package/dist/domain/ui-service/query/projects.js +30 -0
  170. package/dist/domain/ui-service/query/schedules.d.ts +2 -0
  171. package/dist/domain/ui-service/query/schedules.js +23 -0
  172. package/dist/domain/ui-service/query/sessions.d.ts +2 -0
  173. package/dist/domain/ui-service/query/sessions.js +35 -0
  174. package/dist/domain/ui-service/query/tasks.d.ts +2 -0
  175. package/dist/domain/ui-service/query/tasks.js +30 -0
  176. package/dist/domain/ui-service/query/threads.d.ts +2 -0
  177. package/dist/domain/ui-service/query/threads.js +27 -0
  178. package/dist/domain/ui-service/subscribe.d.ts +5 -0
  179. package/dist/domain/ui-service/subscribe.js +118 -0
  180. package/dist/domain/ui-service/types.d.ts +237 -0
  181. package/dist/domain/ui-service/types.js +5 -0
  182. package/dist/domain/ui-service/ui-service.d.ts +2 -0
  183. package/dist/domain/ui-service/ui-service.js +83 -0
  184. package/dist/entry/app.js +94 -5
  185. package/dist/entry/cli.d.ts +12 -0
  186. package/dist/entry/cli.js +122 -12
  187. package/dist/entry/feishu-login.d.ts +28 -0
  188. package/dist/entry/feishu-login.js +218 -0
  189. package/dist/entry/init.d.ts +25 -2
  190. package/dist/entry/init.js +211 -64
  191. package/dist/events/event-types.d.ts +14 -0
  192. package/dist/hooks/cortex-md-injector.mjs +47 -31
  193. package/dist/hooks/post-task-hook.mjs +6 -0
  194. package/dist/hooks/task-status-check.mjs +8 -0
  195. package/dist/orchestration/agent-runner.d.ts +2 -1
  196. package/dist/orchestration/agent-runner.js +55 -55
  197. package/dist/orchestration/conduit-queue.d.ts +18 -0
  198. package/dist/orchestration/conduit-queue.js +32 -0
  199. package/dist/orchestration/conversation-runner.d.ts +48 -0
  200. package/dist/orchestration/conversation-runner.js +109 -0
  201. package/dist/orchestration/dispatch-reconciler.js +8 -1
  202. package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
  203. package/dist/orchestration/interactions/ask-user-question.js +3 -3
  204. package/dist/orchestration/interactions/interaction-handlers.js +48 -17
  205. package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
  206. package/dist/orchestration/interactions/plan-handler.js +4 -3
  207. package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
  208. package/dist/orchestration/interactions/update-prompt.js +100 -0
  209. package/dist/orchestration/lifecycle.d.ts +4 -4
  210. package/dist/orchestration/lifecycle.js +24 -22
  211. package/dist/orchestration/orchestrator.d.ts +1 -1
  212. package/dist/orchestration/routing/commands/cancel.js +39 -47
  213. package/dist/orchestration/routing/commands/channel.js +24 -11
  214. package/dist/orchestration/routing/commands/cost.js +2 -1
  215. package/dist/orchestration/routing/commands/device.js +3 -2
  216. package/dist/orchestration/routing/commands/dispatch.js +6 -5
  217. package/dist/orchestration/routing/commands/index.d.ts +1 -1
  218. package/dist/orchestration/routing/commands/index.js +11 -10
  219. package/dist/orchestration/routing/commands/mode.js +19 -18
  220. package/dist/orchestration/routing/commands/nvtop.js +10 -9
  221. package/dist/orchestration/routing/commands/sendfile.js +7 -6
  222. package/dist/orchestration/routing/commands/session.d.ts +1 -1
  223. package/dist/orchestration/routing/commands/session.js +17 -33
  224. package/dist/orchestration/routing/commands/tail.js +4 -3
  225. package/dist/orchestration/routing/commands/task.js +4 -3
  226. package/dist/orchestration/routing/commands/thread-handlers.js +16 -6
  227. package/dist/orchestration/routing/edit-handler.js +8 -7
  228. package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
  229. package/dist/orchestration/routing/message-router.d.ts +1 -1
  230. package/dist/orchestration/routing/message-router.js +9 -9
  231. package/dist/orchestration/routing/webhook.js +233 -2
  232. package/dist/orchestration/status-helpers.d.ts +5 -1
  233. package/dist/orchestration/status-helpers.js +7 -6
  234. package/dist/orchestration/thread-callback.d.ts +67 -0
  235. package/dist/orchestration/thread-callback.js +465 -0
  236. package/dist/orchestration/thread-executor.d.ts +22 -1
  237. package/dist/orchestration/thread-executor.js +85 -36
  238. package/dist/platform/adapter.d.ts +6 -2
  239. package/dist/platform/adapters/composite-adapter.d.ts +89 -0
  240. package/dist/platform/adapters/composite-adapter.js +318 -0
  241. package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
  242. package/dist/platform/adapters/feishu-output-stream.js +274 -36
  243. package/dist/platform/adapters/feishu.d.ts +50 -5
  244. package/dist/platform/adapters/feishu.js +370 -116
  245. package/dist/platform/adapters/index.d.ts +24 -3
  246. package/dist/platform/adapters/index.js +89 -11
  247. package/dist/platform/adapters/project-conduits.d.ts +9 -0
  248. package/dist/platform/adapters/project-conduits.js +42 -0
  249. package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
  250. package/dist/platform/adapters/slack-project-conduits.js +6 -40
  251. package/dist/platform/adapters/slack.d.ts +9 -2
  252. package/dist/platform/adapters/slack.js +83 -39
  253. package/dist/platform/adapters/tui/index.d.ts +9 -0
  254. package/dist/platform/adapters/tui/index.js +10 -0
  255. package/dist/platform/adapters/tui/ports.d.ts +20 -0
  256. package/dist/platform/adapters/tui/ports.js +4 -0
  257. package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
  258. package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
  259. package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
  260. package/dist/platform/adapters/tui/tui-connection.js +53 -0
  261. package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
  262. package/dist/platform/adapters/tui/tui-gateway.js +919 -0
  263. package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
  264. package/dist/platform/adapters/tui/tui-notifications.js +60 -0
  265. package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
  266. package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
  267. package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
  268. package/dist/platform/adapters/tui/tui-transcript.js +56 -0
  269. package/dist/platform/index.d.ts +1 -0
  270. package/dist/platform/index.js +2 -1
  271. package/dist/platform/interactive-builder.js +3 -2
  272. package/dist/platform/output-stream.d.ts +5 -0
  273. package/dist/platform/testing.d.ts +7 -11
  274. package/dist/platform/testing.js +18 -15
  275. package/dist/platform/tool-trace.js +15 -5
  276. package/dist/platform/tui/protocol.d.ts +355 -0
  277. package/dist/platform/tui/protocol.js +199 -0
  278. package/dist/platform/types.d.ts +12 -3
  279. package/dist/store/execution-repo.d.ts +6 -1
  280. package/dist/store/execution-repo.js +13 -3
  281. package/dist/store/hook-sync.d.ts +18 -0
  282. package/dist/store/hook-sync.js +92 -0
  283. package/dist/store/outbound-queue.js +2 -2
  284. package/dist/store/profile-repo.js +3 -2
  285. package/dist/store/schedule-repo.d.ts +1 -8
  286. package/dist/store/session-registry-repo.d.ts +9 -1
  287. package/dist/store/session-registry-repo.js +19 -3
  288. package/dist/store/session-repo.d.ts +14 -0
  289. package/dist/store/session-repo.js +23 -0
  290. package/dist/store/thread-repo.d.ts +3 -0
  291. package/dist/store/thread-repo.js +49 -2
  292. package/dist/store/version-migrations.js +95 -0
  293. package/dist/tui/App.d.ts +27 -0
  294. package/dist/tui/App.js +219 -0
  295. package/dist/tui/components/AskUserModal.d.ts +11 -0
  296. package/dist/tui/components/AskUserModal.js +364 -0
  297. package/dist/tui/components/ConfirmModal.d.ts +12 -0
  298. package/dist/tui/components/ConfirmModal.js +31 -0
  299. package/dist/tui/components/Dashboard.d.ts +23 -0
  300. package/dist/tui/components/Dashboard.js +80 -0
  301. package/dist/tui/components/DashboardCostTab.d.ts +7 -0
  302. package/dist/tui/components/DashboardCostTab.js +16 -0
  303. package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
  304. package/dist/tui/components/DashboardExecutionsTab.js +94 -0
  305. package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
  306. package/dist/tui/components/DashboardSchedulesTab.js +124 -0
  307. package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
  308. package/dist/tui/components/DashboardTasksTab.js +200 -0
  309. package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
  310. package/dist/tui/components/DashboardThreadsTab.js +81 -0
  311. package/dist/tui/components/Header.d.ts +11 -0
  312. package/dist/tui/components/Header.js +5 -0
  313. package/dist/tui/components/InputBox.d.ts +10 -0
  314. package/dist/tui/components/InputBox.js +19 -0
  315. package/dist/tui/components/MessageRow.d.ts +7 -0
  316. package/dist/tui/components/MessageRow.js +10 -0
  317. package/dist/tui/components/Notifications.d.ts +19 -0
  318. package/dist/tui/components/Notifications.js +72 -0
  319. package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
  320. package/dist/tui/components/PlanFeedbackModal.js +161 -0
  321. package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
  322. package/dist/tui/components/ProjectSwitcher.js +43 -0
  323. package/dist/tui/components/SessionPicker.d.ts +14 -0
  324. package/dist/tui/components/SessionPicker.js +34 -0
  325. package/dist/tui/components/SidePanel.d.ts +19 -0
  326. package/dist/tui/components/SidePanel.js +8 -0
  327. package/dist/tui/components/StatusLine.d.ts +10 -0
  328. package/dist/tui/components/StatusLine.js +29 -0
  329. package/dist/tui/components/Transcript.d.ts +13 -0
  330. package/dist/tui/components/Transcript.js +56 -0
  331. package/dist/tui/hooks/useDashboardData.d.ts +32 -0
  332. package/dist/tui/hooks/useDashboardData.js +104 -0
  333. package/dist/tui/hooks/useKeybindings.d.ts +19 -0
  334. package/dist/tui/hooks/useKeybindings.js +87 -0
  335. package/dist/tui/hooks/useMutate.d.ts +22 -0
  336. package/dist/tui/hooks/useMutate.js +56 -0
  337. package/dist/tui/hooks/useNotifications.d.ts +28 -0
  338. package/dist/tui/hooks/useNotifications.js +70 -0
  339. package/dist/tui/hooks/useTranscript.d.ts +39 -0
  340. package/dist/tui/hooks/useTranscript.js +265 -0
  341. package/dist/tui/hooks/useWsClient.d.ts +29 -0
  342. package/dist/tui/hooks/useWsClient.js +69 -0
  343. package/dist/tui/index.d.ts +2 -0
  344. package/dist/tui/index.js +210 -0
  345. package/dist/tui/logic.d.ts +16 -0
  346. package/dist/tui/logic.js +49 -0
  347. package/dist/tui/render/markdown.d.ts +10 -0
  348. package/dist/tui/render/markdown.js +38 -0
  349. package/dist/tui/render/rich-blocks.d.ts +11 -0
  350. package/dist/tui/render/rich-blocks.js +24 -0
  351. package/dist/tui/ws-client.d.ts +44 -0
  352. package/dist/tui/ws-client.js +157 -0
  353. package/package.json +11 -3
  354. package/dist/orchestration/channel-queue.d.ts +0 -18
  355. package/dist/orchestration/channel-queue.js +0 -32
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // input: useTranscript hook + MessageRow
3
+ // output: Scrollable transcript, anchored bottom, scroll-up freezes auto-scroll
4
+ // pos: Main transcript view for M5 Ink client
5
+ import { useRef, useCallback, useState, useEffect, forwardRef, useImperativeHandle } from 'react';
6
+ import { Box, Text, useStdout } from 'ink';
7
+ import { MessageRow } from './MessageRow.js';
8
+ import { computeVisibleWindow } from '../logic.js';
9
+ // Rows reserved for header + input + status + borders/margins.
10
+ const RESERVED_ROWS = 10;
11
+ export const Transcript = forwardRef(function Transcript({ messages, ids }, ref) {
12
+ const { stdout } = useStdout();
13
+ const [scrollOffset, setScrollOffset] = useState(0);
14
+ const userScrolledUpRef = useRef(false);
15
+ // Approximate how many message rows fit in the terminal.
16
+ const rows = stdout?.rows ?? 24;
17
+ const visibleCount = Math.max(3, rows - RESERVED_ROWS);
18
+ const scrollUp = useCallback((page = false) => {
19
+ userScrolledUpRef.current = true;
20
+ setScrollOffset(prev => prev + (page ? 10 : 1));
21
+ }, []);
22
+ const scrollDown = useCallback((page = false) => {
23
+ setScrollOffset(prev => {
24
+ const next = prev - (page ? 10 : 1);
25
+ if (next <= 0) {
26
+ userScrolledUpRef.current = false;
27
+ return 0;
28
+ }
29
+ return next;
30
+ });
31
+ }, []);
32
+ const scrollToEnd = useCallback(() => {
33
+ userScrolledUpRef.current = false;
34
+ setScrollOffset(0);
35
+ }, []);
36
+ useImperativeHandle(ref, () => ({ scrollUp, scrollDown, scrollToEnd }), [scrollUp, scrollDown, scrollToEnd]);
37
+ // Auto-stick to bottom on new messages unless the user has scrolled up.
38
+ useEffect(() => {
39
+ if (!userScrolledUpRef.current && scrollOffset !== 0) {
40
+ setScrollOffset(0);
41
+ }
42
+ }, [ids.length]);
43
+ // Bottom-anchored visible window.
44
+ const { start, end } = computeVisibleWindow(ids.length, visibleCount, scrollOffset);
45
+ const visibleIds = ids.slice(start, end);
46
+ const hiddenAbove = start;
47
+ if (ids.length === 0) {
48
+ return (_jsx(Box, { flexDirection: "column", flexGrow: 1, children: _jsx(Text, { dimColor: true, children: "\u2014 no messages \u2014" }) }));
49
+ }
50
+ return (_jsxs(Box, { flexDirection: "column", flexGrow: 1, children: [hiddenAbove > 0 ? (_jsxs(Text, { dimColor: true, children: ["\u2191 ", hiddenAbove, " more above"] })) : null, visibleIds.map((id) => {
51
+ const msg = messages.get(id);
52
+ if (!msg)
53
+ return null;
54
+ return _jsx(MessageRow, { message: msg }, id);
55
+ })] }));
56
+ });
@@ -0,0 +1,32 @@
1
+ import type { UiQueryResult, UiEvent } from '../../platform/tui/protocol.js';
2
+ export interface TabData {
3
+ data: unknown[];
4
+ loading: boolean;
5
+ error: string | null;
6
+ lastUpdated: number | null;
7
+ }
8
+ export type TabName = 'threads' | 'tasks' | 'schedules' | 'executions' | 'cost';
9
+ export interface DashState {
10
+ tabs: Record<TabName, TabData>;
11
+ pendingQueries: Set<string>;
12
+ }
13
+ export declare const EMPTY_DASH_STATE: DashState;
14
+ export declare const TAB_SCOPES: Record<TabName, {
15
+ queryId: string;
16
+ events: string[];
17
+ }>;
18
+ export declare function _createPendingQuery(prev: DashState, tab: TabName): DashState;
19
+ export declare function _clearPendingQuery(prev: DashState, tab: TabName): DashState;
20
+ export declare function _handleQueryResult(prev: DashState, queryId: string, scopes: Record<string, {
21
+ queryId: string;
22
+ events: string[];
23
+ }>, frame: UiQueryResult): DashState;
24
+ export declare function _handleEvent(prev: DashState, activeSubscriptions: Map<string, TabName>, frame: UiEvent): DashState;
25
+ export declare function useDashboardData(): {
26
+ state: DashState;
27
+ dispatch: (frame: UiQueryResult | UiEvent) => void;
28
+ markPending: (tab: TabName) => void;
29
+ registerSubscription: (queryId: string, tab: TabName) => void;
30
+ unregisterSubscription: (queryId: string) => void;
31
+ activeSubscriptions: Map<string, TabName>;
32
+ };
@@ -0,0 +1,104 @@
1
+ // input: UiQueryResult, UiEvent frames from protocol
2
+ // output: Per-tab dashboard data management — query/subscribe/refresh lifecycle
3
+ // pos: State hook for dashboard tabs
4
+ import { useState, useCallback } from 'react';
5
+ const INITIAL_TAB = { data: [], loading: false, error: null, lastUpdated: null };
6
+ export const EMPTY_DASH_STATE = {
7
+ tabs: {
8
+ threads: { ...INITIAL_TAB },
9
+ tasks: { ...INITIAL_TAB },
10
+ schedules: { ...INITIAL_TAB },
11
+ executions: { ...INITIAL_TAB },
12
+ cost: { ...INITIAL_TAB },
13
+ },
14
+ pendingQueries: new Set(),
15
+ };
16
+ export const TAB_SCOPES = {
17
+ threads: { queryId: 'dash-threads', events: ['thread.created', 'thread.completed', 'thread.transitioned', 'thread.failed'] },
18
+ tasks: { queryId: 'dash-tasks', events: ['task.claimed', 'task.unclaimed', 'task.completed', 'task.dispatched', 'task.blocked', 'task.unblocked'] },
19
+ schedules: { queryId: 'dash-schedules', events: ['scheduler.tick'] },
20
+ executions: { queryId: 'dash-executions', events: ['agent.started', 'agent.completed', 'agent.failed', 'agent.superseded'] },
21
+ cost: { queryId: 'dash-cost', events: ['agent.completed'] },
22
+ };
23
+ // ── Pure state helpers (exported for testing) ──
24
+ export function _createPendingQuery(prev, tab) {
25
+ const pending = new Set(prev.pendingQueries);
26
+ pending.add(tab);
27
+ return { ...prev, pendingQueries: pending };
28
+ }
29
+ export function _clearPendingQuery(prev, tab) {
30
+ const pending = new Set(prev.pendingQueries);
31
+ pending.delete(tab);
32
+ return { ...prev, pendingQueries: pending };
33
+ }
34
+ export function _handleQueryResult(prev, queryId, scopes, frame) {
35
+ // Only accept frames that echo our query id
36
+ if (frame.id !== queryId)
37
+ return prev;
38
+ // Find which tab this queryId maps to
39
+ const tabEntry = Object.entries(scopes).find(([, s]) => s.queryId === queryId);
40
+ if (!tabEntry)
41
+ return prev;
42
+ const tab = tabEntry[0];
43
+ if (frame.ok) {
44
+ const data = Array.isArray(frame.data) ? frame.data : (frame.data != null ? [frame.data] : []);
45
+ const tabs = {
46
+ ...prev.tabs,
47
+ [tab]: { data, loading: false, error: null, lastUpdated: Date.now() },
48
+ };
49
+ const pending = new Set(prev.pendingQueries);
50
+ pending.delete(tab);
51
+ return { tabs, pendingQueries: pending };
52
+ }
53
+ else {
54
+ const tabs = {
55
+ ...prev.tabs,
56
+ [tab]: { data: [], loading: false, error: frame.error?.message ?? 'Unknown error', lastUpdated: null },
57
+ };
58
+ const pending = new Set(prev.pendingQueries);
59
+ pending.delete(tab);
60
+ return { tabs, pendingQueries: pending };
61
+ }
62
+ }
63
+ export function _handleEvent(prev, activeSubscriptions, frame) {
64
+ // Find which tab this subscription id maps to
65
+ const tab = activeSubscriptions.get(frame.id);
66
+ if (!tab)
67
+ return prev;
68
+ // Mark the tab as needing a refresh (set loading to trigger re-fetch)
69
+ const tabs = {
70
+ ...prev.tabs,
71
+ [tab]: { ...prev.tabs[tab], loading: true },
72
+ };
73
+ return { ...prev, tabs };
74
+ }
75
+ // ── Hook ──
76
+ export function useDashboardData() {
77
+ const [state, setState] = useState(EMPTY_DASH_STATE);
78
+ const [activeSubscriptions] = useState(() => new Map());
79
+ const dispatch = useCallback((frame) => {
80
+ if (frame.type === 'ui.queryResult') {
81
+ setState(prev => _handleQueryResult(prev, frame.id, TAB_SCOPES, frame));
82
+ }
83
+ else if (frame.type === 'ui.event') {
84
+ setState(prev => _handleEvent(prev, activeSubscriptions, frame));
85
+ }
86
+ }, [activeSubscriptions]);
87
+ const markPending = useCallback((tab) => {
88
+ setState(prev => _createPendingQuery(prev, tab));
89
+ }, []);
90
+ const registerSubscription = useCallback((queryId, tab) => {
91
+ activeSubscriptions.set(queryId, tab);
92
+ }, [activeSubscriptions]);
93
+ const unregisterSubscription = useCallback((queryId) => {
94
+ activeSubscriptions.delete(queryId);
95
+ }, [activeSubscriptions]);
96
+ return {
97
+ state,
98
+ dispatch,
99
+ markPending,
100
+ registerSubscription,
101
+ unregisterSubscription,
102
+ activeSubscriptions,
103
+ };
104
+ }
@@ -0,0 +1,19 @@
1
+ export interface KeybindingHandlers {
2
+ onSubmit: (text: string) => void;
3
+ onCancel: () => void;
4
+ onScrollUp: (page?: boolean) => void;
5
+ onScrollDown: (page?: boolean) => void;
6
+ onClearView: () => void;
7
+ onExit: () => void;
8
+ onToggleSidePanel?: () => void;
9
+ onToggleNotifications?: () => void;
10
+ onToggleProjectSwitcher?: () => void;
11
+ onReconnect?: () => void;
12
+ }
13
+ export interface KeybindingOpts {
14
+ /** Handle scroll/clear keys here. False when another zone (dashboard) owns nav. */
15
+ allowScroll?: boolean;
16
+ /** Allow R to trigger reconnect (only meaningful when not connected). */
17
+ allowReconnect?: boolean;
18
+ }
19
+ export declare function useKeybindings(handlers: KeybindingHandlers, isActive?: boolean, opts?: KeybindingOpts): void;
@@ -0,0 +1,87 @@
1
+ // input: ink useInput hook
2
+ // output: Global key handlers for M5 Ink client
3
+ // pos: Single source of truth for keyboard shortcuts
4
+ import { useInput } from 'ink';
5
+ import { useRef } from 'react';
6
+ export function useKeybindings(handlers, isActive = true, opts = {}) {
7
+ const lastCtrlCTs = useRef(0);
8
+ const handlersRef = useRef(handlers);
9
+ handlersRef.current = handlers;
10
+ const optsRef = useRef(opts);
11
+ optsRef.current = opts;
12
+ useInput((input, key) => {
13
+ if (!isActive)
14
+ return;
15
+ const h = handlersRef.current;
16
+ const o = optsRef.current;
17
+ const allowScroll = o.allowScroll !== false;
18
+ // Ctrl+C: first sends !cancel, second within 1s exits
19
+ if (input === 'c' && key.ctrl) {
20
+ const now = Date.now();
21
+ if (now - lastCtrlCTs.current < 1000) {
22
+ h.onExit();
23
+ return;
24
+ }
25
+ lastCtrlCTs.current = now;
26
+ h.onCancel(); // sends !cancel
27
+ return;
28
+ }
29
+ // R: reconnect (only when disconnected/reconnecting)
30
+ if ((input === 'r' || input === 'R') && !key.ctrl && o.allowReconnect && h.onReconnect) {
31
+ h.onReconnect();
32
+ return;
33
+ }
34
+ // Enter: submit
35
+ if (key.return) {
36
+ return;
37
+ }
38
+ // Escape: cancel current input
39
+ if (key.escape) {
40
+ h.onCancel();
41
+ return;
42
+ }
43
+ // Ctrl+L: clear transcript view
44
+ if (input === 'l' && key.ctrl) {
45
+ if (allowScroll)
46
+ h.onClearView();
47
+ return;
48
+ }
49
+ // Ctrl+D: toggle side panel
50
+ if (input === 'd' && key.ctrl) {
51
+ h.onToggleSidePanel?.();
52
+ return;
53
+ }
54
+ // Ctrl+N: open notifications
55
+ if (input === 'n' && key.ctrl) {
56
+ h.onToggleNotifications?.();
57
+ return;
58
+ }
59
+ // Ctrl+P: open project switcher
60
+ if (input === 'p' && key.ctrl) {
61
+ h.onToggleProjectSwitcher?.();
62
+ return;
63
+ }
64
+ // ↑/↓: scroll (only when this zone owns navigation)
65
+ if (key.upArrow) {
66
+ if (allowScroll)
67
+ h.onScrollUp();
68
+ return;
69
+ }
70
+ if (key.downArrow) {
71
+ if (allowScroll)
72
+ h.onScrollDown();
73
+ return;
74
+ }
75
+ // PgUp/PgDn: paginated scroll
76
+ if (key.pageUp) {
77
+ if (allowScroll)
78
+ h.onScrollUp(true);
79
+ return;
80
+ }
81
+ if (key.pageDown) {
82
+ if (allowScroll)
83
+ h.onScrollDown(true);
84
+ return;
85
+ }
86
+ });
87
+ }
@@ -0,0 +1,22 @@
1
+ import type { TuiFrame } from '../../platform/tui/protocol.js';
2
+ export interface MutateSuccess {
3
+ ok: true;
4
+ data?: unknown;
5
+ }
6
+ export interface MutateError {
7
+ ok: false;
8
+ error: {
9
+ code: string;
10
+ message: string;
11
+ };
12
+ }
13
+ export type MutateResult = MutateSuccess | MutateError;
14
+ export interface UseMutateOpts {
15
+ sendFrame: (frame: TuiFrame) => void;
16
+ onFrame?: (frame: TuiFrame) => void;
17
+ }
18
+ export interface UseMutateResult {
19
+ mutate: (op: string, args: Record<string, unknown>) => Promise<MutateResult>;
20
+ handleFrame: (frame: TuiFrame) => void;
21
+ }
22
+ export declare function useMutate({ sendFrame, onFrame }: UseMutateOpts): UseMutateResult;
@@ -0,0 +1,56 @@
1
+ // input: UiMutate + UiMutateResult frames from protocol
2
+ // output: Hook for ui.mutate request/response correlation — sends mutate frames, matches results by id, 10s timeout, cleanup on unmount
3
+ // pos: Async action hook for Phase 3 dashboard mutation buttons
4
+ import { useEffect, useRef, useCallback } from 'react';
5
+ import { randomUUID } from 'crypto';
6
+ import { isUiMutateResult } from '../../platform/tui/protocol.js';
7
+ // ── Hook ──
8
+ export function useMutate({ sendFrame, onFrame }) {
9
+ const pendingRef = useRef(new Map());
10
+ const onFrameRef = useRef(onFrame);
11
+ onFrameRef.current = onFrame;
12
+ // Cleanup pending entries on unmount
13
+ useEffect(() => {
14
+ const pending = pendingRef.current;
15
+ return () => {
16
+ for (const [, entry] of pending) {
17
+ clearTimeout(entry.timer);
18
+ }
19
+ pending.clear();
20
+ };
21
+ }, []);
22
+ const handleFrame = useCallback((frame) => {
23
+ if (isUiMutateResult(frame)) {
24
+ const pending = pendingRef.current;
25
+ const entry = pending.get(frame.id);
26
+ if (entry) {
27
+ clearTimeout(entry.timer);
28
+ pending.delete(frame.id);
29
+ if (frame.ok) {
30
+ entry.resolve({ ok: true, data: frame.data });
31
+ }
32
+ else {
33
+ entry.resolve({ ok: false, error: frame.error });
34
+ }
35
+ return; // Consumed — do not pass through
36
+ }
37
+ }
38
+ // Pass through to user's handler
39
+ onFrameRef.current?.(frame);
40
+ }, []);
41
+ const mutate = useCallback((op, args) => {
42
+ const id = randomUUID();
43
+ return new Promise((resolve) => {
44
+ const timer = setTimeout(() => {
45
+ const pending = pendingRef.current;
46
+ if (pending.has(id)) {
47
+ pending.delete(id);
48
+ resolve({ ok: false, error: { code: 'timeout', message: 'no ui.mutateResult within 10s' } });
49
+ }
50
+ }, 10_000);
51
+ pendingRef.current.set(id, { resolve, timer });
52
+ sendFrame({ type: 'ui.mutate', id, op, args });
53
+ });
54
+ }, [sendFrame]);
55
+ return { mutate, handleFrame };
56
+ }
@@ -0,0 +1,28 @@
1
+ import type { Notification } from '../../platform/tui/protocol.js';
2
+ export interface NotificationEntry {
3
+ id: string;
4
+ kind: 'project-report' | 'system-notice' | 'thread-report';
5
+ projectId: string;
6
+ sessionId?: string | null;
7
+ title: string;
8
+ body: string;
9
+ ts: number;
10
+ read: boolean;
11
+ }
12
+ export interface NotifState {
13
+ notifications: Map<string, NotificationEntry>;
14
+ ids: string[];
15
+ unreadCount: number;
16
+ }
17
+ export declare const EMPTY_NOTIF_STATE: NotifState;
18
+ export declare function _addNotification(prev: NotifState, frame: Notification): NotifState;
19
+ export declare function _markRead(prev: NotifState, notificationId: string): NotifState;
20
+ export declare function _clearNotifications(): NotifState;
21
+ export declare function useNotifications(): {
22
+ notifications: Map<string, NotificationEntry>;
23
+ ids: string[];
24
+ unreadCount: number;
25
+ add: (frame: Notification) => void;
26
+ markRead: (id: string) => void;
27
+ clear: () => void;
28
+ };
@@ -0,0 +1,70 @@
1
+ // input: Notification frame type from protocol
2
+ // output: Notification ring buffer — Map<id, Notification> cap 50, add/markRead/clear
3
+ // pos: State hook for corner notification badge
4
+ import { useState, useCallback } from 'react';
5
+ // ── Constants ──
6
+ const MAX_NOTIFICATIONS = 50;
7
+ export const EMPTY_NOTIF_STATE = {
8
+ notifications: new Map(),
9
+ ids: [],
10
+ unreadCount: 0,
11
+ };
12
+ // ── Pure state helpers (exported for testing) ──
13
+ export function _addNotification(prev, frame) {
14
+ const id = `notif-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
15
+ const entry = {
16
+ id,
17
+ kind: frame.kind,
18
+ projectId: frame.projectId,
19
+ sessionId: frame.sessionId ?? null,
20
+ title: frame.title,
21
+ body: frame.body,
22
+ ts: Date.now(),
23
+ read: false,
24
+ };
25
+ const notifications = new Map(prev.notifications);
26
+ const ids = [...prev.ids, id];
27
+ notifications.set(id, entry);
28
+ // Evict oldest if over cap
29
+ while (ids.length > MAX_NOTIFICATIONS) {
30
+ const oldestId = ids.shift();
31
+ notifications.delete(oldestId);
32
+ }
33
+ return { notifications, ids, unreadCount: prev.unreadCount + 1 };
34
+ }
35
+ export function _markRead(prev, notificationId) {
36
+ const existing = prev.notifications.get(notificationId);
37
+ if (!existing || existing.read)
38
+ return prev;
39
+ const notifications = new Map(prev.notifications);
40
+ notifications.set(notificationId, { ...existing, read: true });
41
+ return {
42
+ notifications,
43
+ ids: prev.ids,
44
+ unreadCount: Math.max(0, prev.unreadCount - 1),
45
+ };
46
+ }
47
+ export function _clearNotifications() {
48
+ return { notifications: new Map(), ids: [], unreadCount: 0 };
49
+ }
50
+ // ── Hook ──
51
+ export function useNotifications() {
52
+ const [state, setState] = useState(EMPTY_NOTIF_STATE);
53
+ const add = useCallback((frame) => {
54
+ setState(prev => _addNotification(prev, frame));
55
+ }, []);
56
+ const markRead = useCallback((id) => {
57
+ setState(prev => _markRead(prev, id));
58
+ }, []);
59
+ const clear = useCallback(() => {
60
+ setState(_clearNotifications());
61
+ }, []);
62
+ return {
63
+ notifications: state.notifications,
64
+ ids: state.ids,
65
+ unreadCount: state.unreadCount,
66
+ add,
67
+ markRead,
68
+ clear,
69
+ };
70
+ }
@@ -0,0 +1,39 @@
1
+ import type { ChatPost, ChatUpdate, ChatDelete, ChatMarkQueued, StreamText, StreamMutableOpen, StreamMutableUpdate, ModalOpen, ModalAck, TuiFrame } from '../../platform/tui/protocol.js';
2
+ export interface StreamState {
3
+ segments: string[];
4
+ mutable: Map<string, string>;
5
+ }
6
+ export interface RenderedMessage {
7
+ messageId: string;
8
+ text: string;
9
+ richBlocks?: Array<{
10
+ type: string;
11
+ text?: string;
12
+ [key: string]: unknown;
13
+ }>;
14
+ queued: boolean;
15
+ streams: Map<string, StreamState>;
16
+ }
17
+ interface TranscriptState {
18
+ messages: Map<string, RenderedMessage>;
19
+ ids: string[];
20
+ }
21
+ export declare function useTranscript(opts?: {
22
+ onModalOpen?: (frame: ModalOpen) => void;
23
+ onModalAck?: (frame: ModalAck) => void;
24
+ }): {
25
+ messages: Map<string, RenderedMessage>;
26
+ ids: string[];
27
+ messageCount: number;
28
+ dispatch: (frame: TuiFrame) => void;
29
+ clear: () => void;
30
+ flushBatch: () => void;
31
+ };
32
+ export declare function _handleChatPost(prev: TranscriptState, frame: ChatPost): TranscriptState;
33
+ export declare function _handleChatUpdate(prev: TranscriptState, frame: ChatUpdate): TranscriptState;
34
+ export declare function _handleChatDelete(prev: TranscriptState, frame: ChatDelete): TranscriptState;
35
+ export declare function _handleChatMarkQueued(prev: TranscriptState, frame: ChatMarkQueued): TranscriptState;
36
+ export declare function _handleStreamText(prev: TranscriptState, frame: StreamText): TranscriptState;
37
+ export declare function _handleStreamMutableOpen(prev: TranscriptState, frame: StreamMutableOpen): TranscriptState;
38
+ export declare function _handleStreamMutableUpdate(prev: TranscriptState, frame: StreamMutableUpdate): TranscriptState;
39
+ export {};