@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
@@ -4,17 +4,18 @@
4
4
  // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
5
5
  import { register, ctx } from '../job-registry.js';
6
6
  import { createLogger } from '../../../core/log.js';
7
+ import { Icons } from '../../../core/icons.js';
7
8
  import * as executionRegistry from '../../executions/registry.js';
8
9
  const log = createLogger('scheduled-task');
9
10
  import * as pendingTaskTracker from '../../tasks/pending-tracker.js';
10
11
  import { sessionStore } from '../../../store/session-registry-repo.js';
11
12
  import { threadStore } from '../../../store/thread-repo.js';
12
- import { getActiveProfile, getDefaultAgent } from '../../agents/index.js';
13
+ import { getActiveProfile } from '../../agents/index.js';
13
14
  import { projectStore } from '../../projects/index.js';
14
15
  import { normalizeSkillCommandPrefix } from '../../memory/skill-scanner.js';
15
16
  import { isValidDispatchPrompt, hasRunningExecutionForSchedule } from '../../tasks/dispatcher.js';
16
17
  import { allConfigsRateLimited } from '../../agents/facade.js';
17
- import { createThread, createDefaultThread } from '../../threads/index.js';
18
+ import { createThread } from '../../threads/index.js';
18
19
  import { runThread as runThreadExec, continueThread } from '../../threads/runner.js';
19
20
  import { maybeNotifyCodexLowUsage } from '../../costs/codex-usage-monitor.js';
20
21
  import { buildUserProcessingMessage, computeElapsed, buildSessionTag } from '../../../core/status-format.js';
@@ -67,7 +68,6 @@ async function resolveDispatchPlan(projectId, target, fallback) {
67
68
  fallback,
68
69
  fallbackChannel: projectId,
69
70
  lookups: {
70
- lookupSession: (name) => sessionStore.lookupSession(name),
71
71
  getThread: (id) => threadStore.get(id),
72
72
  },
73
73
  });
@@ -86,7 +86,7 @@ async function runScheduledTaskAsync({ normalizedMessage, message, projectId, sc
86
86
  if (plan.kind === 'skip') {
87
87
  log.info(`Skipping schedule ${scheduleTaskId}: ${plan.reason}`);
88
88
  try {
89
- await adapter.postMessage(projectReportDest, { text: `:fast_forward: Scheduled task skipped — ${plan.reason}` });
89
+ await adapter.postMessage(projectReportDest, { text: `${Icons.superseded} Scheduled task skipped — ${plan.reason}` });
90
90
  }
91
91
  catch { }
92
92
  return;
@@ -105,7 +105,7 @@ async function runScheduledTaskAsync({ normalizedMessage, message, projectId, sc
105
105
  if (result?.rateLimited) {
106
106
  const { elapsedStr } = computeElapsed(startTime);
107
107
  if (statusMsg) {
108
- const text = `:warning: ${buildSessionTag(sessionName, result?.sessionId)}Rate limited — all fallbacks exhausted (${elapsedStr})`;
108
+ const text = `${Icons.warning} ${buildSessionTag(sessionName, result?.sessionId)}Rate limited — all fallbacks exhausted (${elapsedStr})`;
109
109
  const queue = getOutboundQueue();
110
110
  if (queue) {
111
111
  await durableUpdate(queue, adapter, statusMsg, { text });
@@ -126,7 +126,7 @@ async function runScheduledTaskAsync({ normalizedMessage, message, projectId, sc
126
126
  const { elapsedStr } = computeElapsed(startTime);
127
127
  const queue = getOutboundQueue();
128
128
  if (statusMsg) {
129
- const text = `:x: ${buildSessionTag(sessionName, null)}Error (${elapsedStr})`;
129
+ const text = `${Icons.error} ${buildSessionTag(sessionName, null)}Error (${elapsedStr})`;
130
130
  if (queue) {
131
131
  await durableUpdate(queue, adapter, statusMsg, { text });
132
132
  }
@@ -150,26 +150,12 @@ function dispatchByPlan({ plan, normalizedMessage, message, scheduleTaskId, effe
150
150
  const onProgress = statusMsg ? buildProgressUpdater(ctx.adapter, statusMsg, startTime, effectiveProfile, sessionName) : undefined;
151
151
  const icb = ctx.buildInteractiveCallbacks?.(projectId, null);
152
152
  const baseRunOpts = {
153
- adapter: ctx.adapter, channel: projectId, threadTs: statusMsg?.messageId || null, statusMsg, startTime, onProgress,
153
+ adapter: ctx.adapter, channel: projectId, threadAnchorId: statusMsg?.messageId || null, statusMsg, startTime, onProgress,
154
154
  destination: projectReportDest,
155
155
  onToolUse: icb?.onToolUse ?? null, onPlanWritten: icb?.onPlanWritten ?? null, onAskUserQuestion: icb?.onAskUserQuestion ?? null,
156
156
  };
157
157
  if (plan.kind === 'continue-thread') {
158
- return continueThread(plan.threadId, normalizedMessage, { ...baseRunOpts, existingSessionId: null });
159
- }
160
- if (plan.kind === 'default-thread') {
161
- const defaultAgent = getDefaultAgent() || 'main';
162
- const thread = createDefaultThread(plan.channel, {
163
- agentName: defaultAgent,
164
- userMessage: normalizedMessage,
165
- userMessageTs: `sched_${Date.now()}`,
166
- platformThreadId: statusMsg?.messageId || null,
167
- projectId: project,
168
- });
169
- // Default-thread metadata is unused by createDefaultThread today, so attach trigger / scheduleTaskId
170
- // post-creation so executionRegistry rows still carry the schedule association.
171
- threadStore.set({ ...thread, metadata: { scheduleTaskId, trigger: 'scheduled', profileOverride: effectiveProfile } });
172
- return runThreadExec(thread.id, { ...baseRunOpts, existingSessionId: plan.existingSessionId });
158
+ return continueThread(plan.threadId, normalizedMessage, { ...baseRunOpts });
173
159
  }
174
160
  // plan.kind === 'fresh' — original scheduled-task semantics: scheduler template, fresh session.
175
161
  const thread = createThread(plan.channel, {
@@ -179,7 +165,7 @@ function dispatchByPlan({ plan, normalizedMessage, message, scheduleTaskId, effe
179
165
  projectId: project,
180
166
  metadata: { scheduleTaskId, trigger: 'scheduled', profileOverride: effectiveProfile },
181
167
  });
182
- return runThreadExec(thread.id, { ...baseRunOpts, existingSessionId: null });
168
+ return runThreadExec(thread.id, { ...baseRunOpts });
183
169
  }
184
170
  // Self-register
185
171
  register('scheduled-task', async (payload) => {
@@ -2,6 +2,7 @@
2
2
  // output: sync-public job runner — registers as 'sync-public'
3
3
  // pos: periodic fetch + cherry-pick from public/main to main (non-LLM programmatic work)
4
4
  import { register, ctx } from '../job-registry.js';
5
+ import { Icons } from '../../../core/icons.js';
5
6
  import { execSync } from 'child_process';
6
7
  const SYNC_SCRIPT = '/home/fangxin/Cortex/scripts/sync-pull-from-public.sh';
7
8
  // Self-register
@@ -20,15 +21,15 @@ register('sync-public', async (payload) => {
20
21
  // Quiet success — no message needed unless there were actual syncs
21
22
  const countLine = lines.find(l => l.includes('cherry-picked'));
22
23
  if (countLine && !countLine.includes('0 cherry-picked')) {
23
- await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `:arrows_counterclockwise: Public sync: ${countLine.trim()}` });
24
+ await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `${Icons.refresh} Public sync: ${countLine.trim()}` });
24
25
  }
25
26
  }
26
27
  else {
27
- await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `:warning: Public sync issue:\n\`\`\`\n${output.slice(-500)}\n\`\`\`` });
28
+ await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `${Icons.warning} Public sync issue:\n\`\`\`\n${output.slice(-500)}\n\`\`\`` });
28
29
  }
29
30
  }
30
31
  catch (err) {
31
32
  const msg = err?.stderr || err?.message || String(err);
32
- await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `:warning: Public sync error: ${msg.slice(0, 500)}` });
33
+ await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `${Icons.warning} Public sync error: ${msg.slice(0, 500)}` });
33
34
  }
34
35
  });
@@ -1,18 +1,13 @@
1
1
  import type { ScheduleTarget, ScheduleTask } from '../../../store/schedule-repo.js';
2
2
  import type { ThreadRecord } from '../../../core/types/thread-types.js';
3
- import type { Session } from '../../../store/session-registry-repo.js';
4
3
  /** What scheduled-task.ts should do at fire time. Each kind maps to one runtime branch:
5
- * - fresh / default-thread → createDefaultThread + runThreadExec (default-path)
4
+ * - fresh → createThread('scheduler') + runThreadExec (fresh scheduler session)
6
5
  * - continue-thread → continueThread (resumes the existing thread's slot session)
7
6
  * - skip → record lastSkipped, post a one-line Slack note, do not run.
8
7
  */
9
8
  export type DispatchPlan = {
10
9
  kind: 'fresh';
11
10
  channel: string;
12
- } | {
13
- kind: 'default-thread';
14
- channel: string;
15
- existingSessionId: string | null;
16
11
  } | {
17
12
  kind: 'continue-thread';
18
13
  channel: string;
@@ -22,8 +17,6 @@ export type DispatchPlan = {
22
17
  reason: string;
23
18
  };
24
19
  export interface DispatchLookups {
25
- /** Look up a cortex-XXXX session record. Null if it's been GC'd or never registered. */
26
- lookupSession(sessionName: string): Promise<Session | null>;
27
20
  /** Look up a thread record by id. Null if missing. */
28
21
  getThread(threadId: string): ThreadRecord | null;
29
22
  }
@@ -22,13 +22,6 @@ export async function planScheduledDispatch(input) {
22
22
  // The scheduler resolves projectId → channel before calling runScheduledTask.
23
23
  return { kind: 'fresh', channel: input.fallbackChannel };
24
24
  }
25
- if (target.kind === 'session') {
26
- const record = await input.lookups.lookupSession(target.sessionName);
27
- if (!record) {
28
- return applyFallback(input, `session ${target.sessionName} no longer exists`);
29
- }
30
- return { kind: 'default-thread', channel: record.channel, existingSessionId: record.sessionId };
31
- }
32
25
  if (target.kind === 'thread') {
33
26
  const thread = input.lookups.getThread(target.threadId);
34
27
  if (!thread) {
@@ -2,6 +2,7 @@
2
2
  // output: task-archive job runner — registers as 'task-archive'
3
3
  // pos: periodic completed task archiving (non-LLM programmatic work)
4
4
  import { register, ctx } from '../job-registry.js';
5
+ import { Icons } from '../../../core/icons.js';
5
6
  import { runTaskArchiver } from '../../tasks/archiver.js';
6
7
  // Self-register
7
8
  register('task-archive', async (payload) => {
@@ -10,10 +11,10 @@ register('task-archive', async (payload) => {
10
11
  const adapter = ctx.adapter;
11
12
  if (results.archived.length > 0) {
12
13
  const summary = results.archived.map((r) => `*${r.project}*: archived ${r.ids.length} tasks`).join('\n');
13
- await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `:file_folder: Task auto-archive:\n${summary}` });
14
+ await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `${Icons.folder} Task auto-archive:\n${summary}` });
14
15
  }
15
16
  if (results.errors.length > 0) {
16
17
  const errSummary = results.errors.join('\n');
17
- await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `:warning: Task archiver errors:\n${errSummary}` });
18
+ await adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `${Icons.warning} Task archiver errors:\n${errSummary}` });
18
19
  }
19
20
  });
@@ -1,8 +1,10 @@
1
1
  // input: task-store, execution-registry, pending-task-tracker
2
2
  // output: taskDispatchRunner job runner — registers as 'task-dispatch'
3
3
  // pos: programmatic task dispatch; provides cancelDispatchedTask for app.ts
4
+ import * as os from 'node:os';
4
5
  import { register, ctx } from '../job-registry.js';
5
6
  import { createLogger } from '../../../core/log.js';
7
+ import { Icons } from '../../../core/icons.js';
6
8
  import * as executionRegistry from '../../executions/registry.js';
7
9
  const log = createLogger('task-dispatch');
8
10
  import * as pendingTaskTracker from '../../tasks/pending-tracker.js';
@@ -10,8 +12,10 @@ import { sessionStore } from '../../../store/session-registry-repo.js';
10
12
  import { allConfigsRateLimited } from '../../agents/facade.js';
11
13
  import { selectAndClaimTask, computeNextInterval, updateScheduleInterval } from '../../tasks/dispatcher.js';
12
14
  import { taskMutator } from '../../tasks/mutator.js';
13
- import { createThread } from '../../threads/index.js';
15
+ import { createThread, detectSplitMarker } from '../../threads/index.js';
14
16
  import { runThread as runThreadExec } from '../../threads/runner.js';
17
+ import { processSplitOutcome, processAbortOutcome } from '../../tasks/dispatch-utils.js';
18
+ import { threadStore } from '../../../store/thread-repo.js';
15
19
  import { computeElapsed, buildSessionTag } from '../../../core/status-format.js';
16
20
  import { finalizeThreadSuccess } from './_shared.js';
17
21
  import { getOutboundQueue, durableUpdate, durablePost } from '../../../store/outbound-queue.js';
@@ -22,7 +26,25 @@ function sanitizeBlockReason(s) {
22
26
  return String(s).replace(/[\r\n\]]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 120);
23
27
  }
24
28
  // --- Guards ---
25
- const TASK_DISPATCH_MAX_CONCURRENT = 4;
29
+ // Max concurrent task dispatches. Resolution order:
30
+ // 1. TASK_DISPATCH_MAX_CONCURRENT env var (explicit override — used as-is if a positive int)
31
+ // 2. auto: max(4, os.cpus().length - 2) — scale to all-but-2 cores, floored at 4
32
+ function resolveMaxConcurrent() {
33
+ const raw = process.env.TASK_DISPATCH_MAX_CONCURRENT;
34
+ if (raw !== undefined && raw.trim() !== '') {
35
+ const n = Number.parseInt(raw, 10);
36
+ if (Number.isFinite(n) && n > 0) {
37
+ log.info(`Max concurrent dispatch = ${n} (from TASK_DISPATCH_MAX_CONCURRENT env)`);
38
+ return n;
39
+ }
40
+ log.warn(`Invalid TASK_DISPATCH_MAX_CONCURRENT="${raw}" — falling back to auto`);
41
+ }
42
+ const cpus = os.cpus().length;
43
+ const auto = Math.max(4, cpus - 2);
44
+ log.info(`Max concurrent dispatch = ${auto} (auto: max(4, ${cpus} cpus - 2))`);
45
+ return auto;
46
+ }
47
+ const TASK_DISPATCH_MAX_CONCURRENT = resolveMaxConcurrent();
26
48
  function passDispatchGuards() {
27
49
  const runningExecutions = executionRegistry.getRunningExecutions();
28
50
  const runningDispatches = runningExecutions.filter(r => r.kind === 'dispatch').length;
@@ -65,6 +87,8 @@ async function runDispatchAsync({ channel, scheduleTaskId, profileName }) {
65
87
  return;
66
88
  }
67
89
  selectedTask = selected.task;
90
+ ctx.bus.publish({ type: 'task.claimed', taskId: selectedTask.id, by: 'task-dispatcher' });
91
+ ctx.bus.publish({ type: 'task.dispatched', taskId: selectedTask.id, machine: 'local' });
68
92
  outcome = await executeDispatchTask({ selected, selectedTask: selectedTask, channel, scheduleTaskId, profileName, startTime });
69
93
  }
70
94
  catch (error) {
@@ -87,7 +111,7 @@ async function executeDispatchTask({ selected, selectedTask, channel, scheduleTa
87
111
  let statusMsg = null;
88
112
  try {
89
113
  statusMsg = await adapter.postMessage({ type: 'project-report', projectId: selectedTask.project || channel, trigger: 'task-dispatch', sessionId: '' }, {
90
- text: `:satellite: Dispatching: [${selectedTask.project}] ${selectedTask.text.substring(0, 80)}... | ${sessionName} | ${effectiveProfile}`,
114
+ text: `${Icons.satellite} Dispatching: [${selectedTask.project}] ${selectedTask.text.substring(0, 80)}... | ${sessionName} | ${effectiveProfile}`,
91
115
  });
92
116
  }
93
117
  catch { }
@@ -100,11 +124,17 @@ async function executeDispatchTask({ selected, selectedTask, channel, scheduleTa
100
124
  templateName: selected.template, userMessage: selected.prompt, userMessageTs: `dispatch_${Date.now()}`,
101
125
  platformThreadId: statusMsg?.messageId ?? null,
102
126
  projectId: selectedTask.project,
103
- metadata: { scheduleTaskId, trigger: 'task-dispatch', profileOverride: effectiveProfile },
127
+ metadata: {
128
+ scheduleTaskId, trigger: 'task-dispatch', profileOverride: effectiveProfile,
129
+ // DR-0014: persisted so a suspended parent's re-entry can rebuild the
130
+ // task-status-check onEnd hook (extraHooks are not persisted on ThreadRecord).
131
+ taskId: selectedTask.id ?? null, taskProject: selectedTask.project ?? null,
132
+ resumeDest: 'project-report',
133
+ },
104
134
  });
105
135
  const icb = ctx.buildInteractiveCallbacks?.(channel, null);
106
136
  const threadResult = await runThreadExec(thread.id, {
107
- adapter, channel: channel, threadTs: statusMsg?.messageId || null, statusMsg, startTime, existingSessionId: null,
137
+ adapter, channel: channel, threadAnchorId: statusMsg?.messageId || null, statusMsg, startTime,
108
138
  destination: { type: 'project-report', projectId: selectedTask.project || channel, trigger: 'task-dispatch', sessionId: '' },
109
139
  onToolUse: icb?.onToolUse ?? null, onPlanWritten: icb?.onPlanWritten ?? null, onAskUserQuestion: icb?.onAskUserQuestion ?? null,
110
140
  extraHooks: {
@@ -116,11 +146,89 @@ async function executeDispatchTask({ selected, selectedTask, channel, scheduleTa
116
146
  },
117
147
  });
118
148
  const result = threadResult.lastAgentResult;
149
+ // DR-0014: the thread suspended on child threads ([WAIT_CHILDREN]). Not a completion —
150
+ // keep the task claimed (thread-callback resumes the thread when children finish, and the
151
+ // rebuilt onEnd hook closes the task loop at true termination). Don't finalize, don't
152
+ // publish task.completed.
153
+ if (threadResult.thread?.status === 'waiting') {
154
+ const nThreads = threadResult.thread.metadata?.waitingOn?.length ?? 0;
155
+ const nTasks = threadResult.thread.metadata?.waitingOnTasks?.length ?? 0;
156
+ // DR-0014 §8: close the suspension race window (a child task that turned terminal
157
+ // between the snapshot and the waiting persist fired its event unheard).
158
+ if (nTasks > 0 && ctx.onThreadSuspended) {
159
+ await ctx.onThreadSuspended(thread.id).catch((e) => log.error(`onThreadSuspended: ${e.message}`));
160
+ }
161
+ if (statusMsg) {
162
+ // Persist the live status message so the post-resume settle can refresh it.
163
+ await threadStore.mutate(thread.id, (t) => { (t.metadata ??= {}).statusMsgRef = statusMsg; });
164
+ const parts = [nThreads > 0 ? `${nThreads} child thread(s)` : null, nTasks > 0 ? `${nTasks} child task(s)` : null].filter(Boolean);
165
+ const text = `${Icons.processing} [${selectedTask.project}] ${selectedTask.text.substring(0, 80)} | suspended — waiting on ${parts.join(' + ') || 'children'}`;
166
+ const queue = getOutboundQueue();
167
+ if (queue) {
168
+ await durableUpdate(queue, adapter, statusMsg, { text });
169
+ }
170
+ else {
171
+ await adapter.updateMessage(statusMsg, { text }).catch(() => { });
172
+ }
173
+ }
174
+ return { success: true, skipped: false, note: `Suspended [${selectedTask.project}] waiting on ${nThreads} thread(s) + ${nTasks} task(s)` };
175
+ }
176
+ // DR-0014 §8: worker escalation — [ABORT: <reason>] blocks the task (task.blocked event
177
+ // wakes the waiting manager, if any). Must run BEFORE finalizeThreadSuccess: aborted
178
+ // threads were previously finalized as successes and published a bogus task.completed.
179
+ const abortOutcome = await processAbortOutcome({ threadId: thread.id, taskId: selectedTask.id ?? null, project: selectedTask.project }, {
180
+ getThread: (id) => threadStore.get(id),
181
+ block: (tid, reason) => taskMutator.block(tid, reason),
182
+ });
183
+ if (abortOutcome.handled) {
184
+ const text = abortOutcome.error
185
+ ? `${Icons.error} [${selectedTask.project}] ${selectedTask.text.substring(0, 80)} | worker aborted but block failed: ${abortOutcome.error}`
186
+ : `${Icons.stopped} [${selectedTask.project}] ${selectedTask.text.substring(0, 80)} | ${abortOutcome.note}`;
187
+ if (statusMsg) {
188
+ const queue = getOutboundQueue();
189
+ if (queue) {
190
+ await durableUpdate(queue, adapter, statusMsg, { text });
191
+ }
192
+ else {
193
+ await adapter.updateMessage(statusMsg, { text }).catch(() => { });
194
+ }
195
+ }
196
+ if (selectedTask.id)
197
+ dispatchFailureCounts.delete(selectedTask.id); // abort is judgment, not fault
198
+ return { success: !abortOutcome.error, skipped: false, note: abortOutcome.error ? `abort-block failed: ${abortOutcome.error}` : `[${selectedTask.project}] ${abortOutcome.note}` };
199
+ }
200
+ // DR-0014: the worker proposed a [SPLIT] decomposition instead of doing the task.
201
+ // Decompose keep-parent (task becomes the join/acceptance node) and unclaim; the
202
+ // children flow through the normal dispatch queue.
203
+ const splitOutcome = await processSplitOutcome({ threadId: thread.id, taskId: selectedTask.id ?? null, project: selectedTask.project }, {
204
+ detect: detectSplitMarker,
205
+ // system:true — no agent lock in the dispatch path; defer if a foreign lock exists.
206
+ decompose: (p, t, subs, tid, opts) => taskMutator.decompose(p, t, subs, tid, { ...opts, system: true }),
207
+ unclaim: (tid) => taskMutator.unclaim(tid),
208
+ });
209
+ if (splitOutcome.handled) {
210
+ const text = splitOutcome.error
211
+ ? `${Icons.error} [${selectedTask.project}] ${selectedTask.text.substring(0, 80)} | [SPLIT] proposal invalid: ${splitOutcome.error} — task unclaimed`
212
+ : `🌿 [${selectedTask.project}] ${selectedTask.text.substring(0, 80)} | ${splitOutcome.note}`;
213
+ if (statusMsg) {
214
+ const queue = getOutboundQueue();
215
+ if (queue) {
216
+ await durableUpdate(queue, adapter, statusMsg, { text });
217
+ }
218
+ else {
219
+ await adapter.updateMessage(statusMsg, { text }).catch(() => { });
220
+ }
221
+ }
222
+ if (splitOutcome.error) {
223
+ return { success: false, skipped: false, note: `[SPLIT] invalid: ${splitOutcome.error}` };
224
+ }
225
+ return { success: true, skipped: false, note: `[${selectedTask.project}] ${splitOutcome.note}` };
226
+ }
119
227
  if (result?.rateLimited) {
120
228
  const { elapsedStr } = computeElapsed(startTime);
121
229
  await taskMutator.unclaim(selectedTask.id);
122
230
  if (statusMsg) {
123
- const text = `:warning: [${selectedTask.project}] ${selectedTask.text.substring(0, 80)} | ${buildSessionTag(sessionName, result?.sessionId)}Rate limited — all fallbacks exhausted (${elapsedStr})`;
231
+ const text = `${Icons.warning} [${selectedTask.project}] ${selectedTask.text.substring(0, 80)} | ${buildSessionTag(sessionName, result?.sessionId)}Rate limited — all fallbacks exhausted (${elapsedStr})`;
124
232
  const queue = getOutboundQueue();
125
233
  if (queue) {
126
234
  await durableUpdate(queue, adapter, statusMsg, { text });
@@ -136,8 +244,10 @@ async function executeDispatchTask({ selected, selectedTask, channel, scheduleTa
136
244
  label: selectedTask.text?.substring(0, 60) || null, sessionKind: 'scheduled',
137
245
  statusPrefix: `Done: [${selectedTask.project}] ${selectedTask.text.substring(0, 80)}`,
138
246
  });
139
- if (selectedTask.id)
247
+ if (selectedTask.id) {
140
248
  dispatchFailureCounts.delete(selectedTask.id);
249
+ ctx.bus.publish({ type: 'task.completed', taskId: selectedTask.id });
250
+ }
141
251
  return { success: true, skipped: false, note: `Completed [${selectedTask.project}] ${selectedTask.text.substring(0, 60)}` };
142
252
  }
143
253
  async function handleDispatchError(error, selectedTask, channel) {
@@ -174,7 +284,7 @@ async function handleDispatchError(error, selectedTask, channel) {
174
284
  try {
175
285
  const queue = getOutboundQueue();
176
286
  if (blocked && selectedTask) {
177
- const text = `:no_entry: Auto-blocked after ${DISPATCH_FAILURE_QUARANTINE_THRESHOLD} consecutive dispatch failures. Reason recorded in TASKS.yaml. Task: [${selectedTask.project}] ${String(selectedTask.text).substring(0, 80)}. Last error: ${error.message}. Unblock with \`cortex-task unblock --task-id ${selectedTask.id}\`.`;
287
+ const text = `${Icons.blocked} Auto-blocked after ${DISPATCH_FAILURE_QUARANTINE_THRESHOLD} consecutive dispatch failures. Reason recorded in TASKS.yaml. Task: [${selectedTask.project}] ${String(selectedTask.text).substring(0, 80)}. Last error: ${error.message}. Unblock with \`cortex-task unblock --task-id ${selectedTask.id}\`.`;
178
288
  const projDest = { type: 'project-report', projectId: selectedTask.project || errChannel, trigger: 'task-dispatch', sessionId: '' };
179
289
  if (queue) {
180
290
  await durablePost(queue, adapter, projDest, { text });
@@ -184,7 +294,7 @@ async function handleDispatchError(error, selectedTask, channel) {
184
294
  }
185
295
  }
186
296
  else {
187
- const text = `:x: Task dispatch error: ${error.message}`;
297
+ const text = `${Icons.error} Task dispatch error: ${error.message}`;
188
298
  const projDest = { type: 'project-report', projectId: selectedTask?.project || errChannel, trigger: 'task-dispatch', sessionId: '' };
189
299
  if (queue) {
190
300
  await durablePost(queue, adapter, projDest, { text });
@@ -203,7 +313,7 @@ export async function cancelDispatchedTask({ taskId, channel }) {
203
313
  try {
204
314
  executionRegistry.cancelExecutionByTaskId(taskId);
205
315
  pendingTaskTracker.clearTask(taskId);
206
- return { ok: true, message: `:octagonal_sign: Cancelled task [${taskId}].` };
316
+ return { ok: true, message: `${Icons.stopped} Cancelled task [${taskId}].` };
207
317
  }
208
318
  catch (error) {
209
319
  return { ok: false, message: `Failed to cancel \`${taskId}\`: ${error.message}` };
@@ -2,6 +2,7 @@
2
2
  // output: handleScheduleCommand dispatcher
3
3
  // pos: !schedule subcommand routing and profile pinning
4
4
  // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
5
+ import { Icons } from '../../core/icons.js';
5
6
  import { formatDuration, formatTimeUntil, parseDuration } from './scheduler.js';
6
7
  import { channelToProjectId } from '../../store/schedule-repo.js';
7
8
  import { listProfiles, resolveProfile, getDefaultProfileName } from '../agents/profile-manager.js';
@@ -79,7 +80,7 @@ async function handleRemove(parts, channel, adapter, scheduler) {
79
80
  }
80
81
  const removed = await scheduler.remove(id);
81
82
  await adapter.postMessage(toDest(channel), {
82
- text: removed ? `:white_check_mark: Removed task \`${id}\`.` : `:x: Task not found: \`${id}\``,
83
+ text: removed ? `${Icons.ok} Removed task \`${id}\`.` : `${Icons.error} Task not found: \`${id}\``,
83
84
  });
84
85
  }
85
86
  async function handlePause(parts, channel, adapter, scheduler) {
@@ -92,13 +93,13 @@ async function handlePause(parts, channel, adapter, scheduler) {
92
93
  try {
93
94
  const task = await scheduler.pause(id);
94
95
  if (!task) {
95
- await adapter.postMessage(toDest(channel), { text: `:x: Task not found: \`${id}\`` });
96
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} Task not found: \`${id}\`` });
96
97
  return;
97
98
  }
98
- await adapter.postMessage(toDest(channel), { text: `:double_vertical_bar: Paused task \`${id}\`.` });
99
+ await adapter.postMessage(toDest(channel), { text: `${Icons.paused} Paused task \`${id}\`.` });
99
100
  }
100
101
  catch (error) {
101
- await adapter.postMessage(toDest(channel), { text: `:x: ${error.message}` });
102
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
102
103
  }
103
104
  }
104
105
  async function handleResume(parts, channel, adapter, scheduler) {
@@ -111,14 +112,14 @@ async function handleResume(parts, channel, adapter, scheduler) {
111
112
  try {
112
113
  const task = await scheduler.resume(id);
113
114
  if (!task) {
114
- await adapter.postMessage(toDest(channel), { text: `:x: Task not found: \`${id}\`` });
115
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} Task not found: \`${id}\`` });
115
116
  return;
116
117
  }
117
118
  const nextAt = task.nextRun ? ` Next run: ${fmtTime(task.nextRun)}.` : '';
118
- await adapter.postMessage(toDest(channel), { text: `:arrow_forward: Resumed task \`${id}\`.${nextAt}` });
119
+ await adapter.postMessage(toDest(channel), { text: `${Icons.resume} Resumed task \`${id}\`.${nextAt}` });
119
120
  }
120
121
  catch (error) {
121
- await adapter.postMessage(toDest(channel), { text: `:x: ${error.message}` });
122
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
122
123
  }
123
124
  }
124
125
  function parseProfileArgs(args, usage) {
@@ -150,7 +151,7 @@ async function handleAddInterval(parts, channel, adapter, scheduler) {
150
151
  parsed = parseProfileArgs(parts.slice(4), '`!schedule add interval <duration> [--profile <name>] <message>`');
151
152
  }
152
153
  catch (error) {
153
- await adapter.postMessage(toDest(channel), { text: `:x: ${error.message}` });
154
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
154
155
  return;
155
156
  }
156
157
  const msg = parsed.rest.join(' ');
@@ -166,7 +167,7 @@ async function handleAddInterval(parts, channel, adapter, scheduler) {
166
167
  const resolvedProjectId = channelToProjectId(channel) ?? 'general';
167
168
  const task = await scheduler.add('interval', { intervalMs: ms, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
168
169
  const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
169
- await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`:white_check_mark: Scheduled every *${formatDuration(ms)}*: "${msg}"`, task, nextAt) });
170
+ await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} Scheduled every *${formatDuration(ms)}*: "${msg}"`, task, nextAt) });
170
171
  }
171
172
  async function handleAddDaily(parts, channel, adapter, scheduler) {
172
173
  const time = parts[3];
@@ -175,7 +176,7 @@ async function handleAddDaily(parts, channel, adapter, scheduler) {
175
176
  parsed = parseProfileArgs(parts.slice(4), '`!schedule add daily <HH:MM> [--profile <name>] <message>`');
176
177
  }
177
178
  catch (error) {
178
- await adapter.postMessage(toDest(channel), { text: `:x: ${error.message}` });
179
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
179
180
  return;
180
181
  }
181
182
  const msg = parsed.rest.join(' ');
@@ -190,7 +191,7 @@ async function handleAddDaily(parts, channel, adapter, scheduler) {
190
191
  const resolvedProjectId = channelToProjectId(channel) ?? 'general';
191
192
  const task = await scheduler.add('daily', { time, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
192
193
  const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
193
- await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`:white_check_mark: Scheduled daily at *${time}*: "${msg}"`, task, nextAt) });
194
+ await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} Scheduled daily at *${time}*: "${msg}"`, task, nextAt) });
194
195
  }
195
196
  async function handleAddWeekly(parts, channel, adapter, scheduler) {
196
197
  const dayStr = (parts[3] || '').toLowerCase();
@@ -200,7 +201,7 @@ async function handleAddWeekly(parts, channel, adapter, scheduler) {
200
201
  parsed = parseProfileArgs(parts.slice(5), '`!schedule add weekly <day> <HH:MM> [--profile <name>] <message>`');
201
202
  }
202
203
  catch (error) {
203
- await adapter.postMessage(toDest(channel), { text: `:x: ${error.message}` });
204
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
204
205
  return;
205
206
  }
206
207
  const msg = parsed.rest.join(' ');
@@ -221,7 +222,7 @@ async function handleAddWeekly(parts, channel, adapter, scheduler) {
221
222
  const resolvedProjectId = channelToProjectId(channel) ?? 'general';
222
223
  const task = await scheduler.add('weekly', { dayOfWeek, time, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
223
224
  const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
224
- await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`:white_check_mark: Scheduled weekly *${dayNames[dayOfWeek]} ${time}*: "${msg}"`, task, nextAt) });
225
+ await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} Scheduled weekly *${dayNames[dayOfWeek]} ${time}*: "${msg}"`, task, nextAt) });
225
226
  }
226
227
  async function handleAddOnce(parts, channel, adapter, scheduler) {
227
228
  const durationStr = parts[3];
@@ -230,7 +231,7 @@ async function handleAddOnce(parts, channel, adapter, scheduler) {
230
231
  parsed = parseProfileArgs(parts.slice(4), '`!schedule add once <duration> [--profile <name>] <message>`');
231
232
  }
232
233
  catch (error) {
233
- await adapter.postMessage(toDest(channel), { text: `:x: ${error.message}` });
234
+ await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
234
235
  return;
235
236
  }
236
237
  const msg = parsed.rest.join(' ');
@@ -246,7 +247,7 @@ async function handleAddOnce(parts, channel, adapter, scheduler) {
246
247
  const resolvedProjectId = channelToProjectId(channel) ?? 'general';
247
248
  const task = await scheduler.add('once', { delay: ms, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
248
249
  const runAt = task.runAt ? ` | runs at: ${fmtTime(task.runAt)}` : '';
249
- await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`:white_check_mark: Scheduled once in *${formatDuration(ms)}*: "${msg}"`, task, runAt) });
250
+ await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} Scheduled once in *${formatDuration(ms)}*: "${msg}"`, task, runAt) });
250
251
  }
251
252
  const ADD_TYPE_HANDLERS = {
252
253
  interval: handleAddInterval,
@@ -11,7 +11,7 @@ interface RunnerParams {
11
11
  profileName: string;
12
12
  /** Where the fired task should land — passed through so scheduled-task.ts can pick its dispatch branch. */
13
13
  target?: ScheduleTask['target'];
14
- /** What to do if the chosen target's session/thread no longer exists at fire time. */
14
+ /** What to do if the chosen target thread no longer exists at fire time. */
15
15
  fallback?: ScheduleTask['fallback'];
16
16
  }
17
17
  interface TaskDispatchParams {
@@ -5,6 +5,7 @@
5
5
  import { watch } from 'fs';
6
6
  import { execSync } from 'child_process';
7
7
  import { randomBytes } from 'crypto';
8
+ import { Icons } from '../../core/icons.js';
8
9
  import { DATA_DIR } from '../../core/utils.js';
9
10
  import { createLogger } from '../../core/log.js';
10
11
  import { getDefaultProfileName } from '../agents/profile-manager.js';
@@ -307,7 +308,7 @@ class Scheduler {
307
308
  }
308
309
  if (added || removed || updated) {
309
310
  log.info(`Hot-reload: +${added} -${removed} ~${updated} task(s), total ${this.timers.size}`);
310
- this._adminNotifier?.(`:arrows_counterclockwise: \`schedules.json\` hot-reloaded: +${added} -${removed} ~${updated} task(s), ${this.timers.size} total`);
311
+ this._adminNotifier?.(`${Icons.refresh} \`schedules.json\` hot-reloaded: +${added} -${removed} ~${updated} task(s), ${this.timers.size} total`);
311
312
  }
312
313
  }
313
314
  // Add a new scheduled task and return it
@@ -81,11 +81,11 @@ export declare function resolveOnNewProfileName(channel: string, sessionId: stri
81
81
  * Returns immediately; the hook subprocess and any injected agent turn run async
82
82
  * via the unified pipeline. The session is closed by the caller in parallel —
83
83
  * sessionId is captured up-front so the JSONL still resolves after deletion. */
84
- export declare function fireAndForgetPreCloseHook(channel: string, adapter: PlatformAdapter, threadTs?: string | null): Promise<void>;
84
+ export declare function fireAndForgetPreCloseHook(channel: string, adapter: PlatformAdapter, threadAnchorId?: string | null): Promise<void>;
85
85
  /** Synchronous variant of fireAndForgetPreCloseHook — awaits the hook to completion.
86
86
  * Reserved for cases where the caller wants to block on the !new pipeline (e.g.
87
87
  * test harness, scripted teardown). */
88
- export declare function runPreCloseHook(channel: string, adapter: PlatformAdapter, threadTs?: string | null): Promise<void>;
88
+ export declare function runPreCloseHook(channel: string, adapter: PlatformAdapter, threadAnchorId?: string | null): Promise<void>;
89
89
  export interface OnMessageEndArgs {
90
90
  channel: string;
91
91
  sessionId: string;