@cortex-agent/server 2026.6.22 → 2026.7.30

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 (638) hide show
  1. package/README.md +25 -13
  2. package/defaults/.claude/settings.json +4 -0
  3. package/defaults/config/CORTEX.md +9 -0
  4. package/defaults/config/hooks/01-sensitive-file-edit.json +11 -0
  5. package/defaults/config/hooks/02-tasks-yaml-guard.json +11 -0
  6. package/defaults/config/hooks/03-ask-user-question-hook.json +19 -0
  7. package/defaults/config/hooks/04-exit-plan-mode-hook.json +19 -0
  8. package/defaults/config/hooks/05-memory-ref-tracker.json +10 -0
  9. package/defaults/config/hooks/06-rules-loader.json +10 -0
  10. package/defaults/config/hooks/07-session-activity-tracker.json +10 -0
  11. package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +10 -0
  12. package/defaults/config/hooks/09-permission-request-auto-allow.json +11 -0
  13. package/defaults/config/hooks/10-cortex-md-injector-session-start.json +10 -0
  14. package/defaults/config/hooks/11-task-status-check.json +14 -0
  15. package/defaults/config/hooks/12-session-new-hook.json +11 -0
  16. package/defaults/config/hooks/CORTEX.md +18 -0
  17. package/defaults/config/thread-templates/agents/coder-reviewer.json +25 -0
  18. package/defaults/config/thread-templates/agents/coder.json +30 -0
  19. package/defaults/config/thread-templates/agents/direct-review.json +17 -0
  20. package/defaults/config/thread-templates/agents/direct-web.json +16 -0
  21. package/defaults/config/thread-templates/agents/direct.json +16 -0
  22. package/defaults/config/thread-templates/agents/director.json +14 -0
  23. package/defaults/config/thread-templates/agents/doc-reviewer.json +14 -0
  24. package/defaults/config/thread-templates/agents/doc-writer.json +25 -0
  25. package/defaults/config/thread-templates/agents/executor-reviewer.json +14 -0
  26. package/defaults/config/thread-templates/agents/executor.json +25 -0
  27. package/defaults/config/thread-templates/agents/main.json +16 -0
  28. package/defaults/config/thread-templates/agents/manager.json +17 -0
  29. package/defaults/config/thread-templates/agents/scheduler-main.json +16 -0
  30. package/defaults/config/thread-templates/shells/worker-review.json +19 -0
  31. package/defaults/config/thread-templates/templates/coder-review.json +53 -0
  32. package/defaults/config/thread-templates/templates/default.json +10 -0
  33. package/defaults/config/thread-templates/templates/doc-review.json +6 -0
  34. package/defaults/config/thread-templates/templates/execute-review.json +6 -0
  35. package/defaults/config/thread-templates/templates/manager.json +11 -0
  36. package/defaults/config/thread-templates/templates/scheduler.json +19 -0
  37. package/defaults/context/decisions/DR-0012.md +1 -1
  38. package/defaults/context/user/CORTEX.md +2 -2
  39. package/defaults/gitignore +3 -0
  40. package/defaults/hooks/CORTEX.md +18 -0
  41. package/defaults/hooks/ask-user-question-hook.mjs +1 -0
  42. package/defaults/hooks/cortex-hook-api.mjs +84 -0
  43. package/defaults/hooks/cortex-md-injector.mjs +99 -49
  44. package/defaults/hooks/exit-plan-mode-hook.mjs +1 -0
  45. package/defaults/hooks/memory-ref-tracker.mjs +1 -0
  46. package/defaults/hooks/new-session-hook.mjs +1 -0
  47. package/defaults/hooks/post-task-hook.mjs +1 -0
  48. package/defaults/hooks/rules-loader.mjs +1 -0
  49. package/defaults/hooks/sensitive-file-edit.mjs +1 -0
  50. package/defaults/hooks/session-activity-tracker.mjs +8 -100
  51. package/defaults/hooks/task-status-check.mjs +10 -10
  52. package/defaults/hooks/tasks-yaml-guard.mjs +1 -0
  53. package/defaults/mcp-config-web.json +11 -0
  54. package/defaults/pi/agents/explore.md +9 -0
  55. package/defaults/pi/agents/general-purpose.md +6 -0
  56. package/defaults/pi/agents/plan.md +9 -0
  57. package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +1 -1
  58. package/defaults/plugins/cortex-coder/skills/cli-standards/SKILL.md +2 -2
  59. package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +33 -0
  60. package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +2 -2
  61. package/defaults/plugins/cortex-common/skills/debug-campaign/SKILL.md +16 -16
  62. package/defaults/plugins/cortex-common/skills/execute-method/SKILL.md +53 -0
  63. package/defaults/plugins/cortex-common/skills/execute-review-rubric/SKILL.md +102 -0
  64. package/defaults/plugins/cortex-common/skills/manager-method/SKILL.md +67 -0
  65. package/defaults/plugins/cortex-common/skills/solution-design/SKILL.md +3 -3
  66. package/defaults/plugins/cortex-feishu/.claude-plugin/plugin.json +5 -0
  67. package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +163 -0
  68. package/defaults/plugins/cortex-feishu/skills/feishu-doc/scripts/ensure-lark-cli.sh +53 -0
  69. package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +2 -2
  70. package/defaults/plugins/cortex-stage-gate/skills/director-method/SKILL.md +54 -0
  71. package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +132 -112
  72. package/defaults/plugins/cortex-system/.claude-plugin/plugin.json +1 -1
  73. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +17 -10
  74. package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +2 -2
  75. package/defaults/plugins/cortex-system/skills/orient/SKILL.md +1 -1
  76. package/defaults/plugins/cortex-system/skills/orient-project/SKILL.md +2 -2
  77. package/defaults/plugins/cortex-system/skills/thread/SKILL.md +66 -17
  78. package/defaults/prompts/directives/coder-reviewer.md +6 -6
  79. package/defaults/prompts/directives/coder.md +4 -29
  80. package/defaults/prompts/directives/director.md +4 -17
  81. package/defaults/prompts/directives/doc-reviewer.md +2 -35
  82. package/defaults/prompts/directives/doc-writer.md +2 -7
  83. package/defaults/prompts/directives/executor-reviewer.md +2 -39
  84. package/defaults/prompts/directives/executor.md +2 -7
  85. package/defaults/prompts/directives/manager.md +12 -27
  86. package/defaults/prompts/systemPrompts/coder.md +1 -1
  87. package/defaults/prompts/systemPrompts/direct.md +1 -1
  88. package/defaults/prompts/systemPrompts/web.md +5 -0
  89. package/defaults/prompts/systemPrompts/worker.md +1 -1
  90. package/dist/agent-adapter/bg-wait.d.ts +44 -0
  91. package/dist/agent-adapter/bg-wait.js +197 -0
  92. package/dist/agent-adapter/capabilities.d.ts +7 -1
  93. package/dist/agent-adapter/capabilities.js +18 -9
  94. package/dist/agent-adapter/claude/adapter-tui.d.ts +14 -0
  95. package/dist/agent-adapter/claude/adapter-tui.js +16 -0
  96. package/dist/agent-adapter/claude/adapter.d.ts +89 -5
  97. package/dist/agent-adapter/claude/adapter.js +410 -40
  98. package/dist/agent-adapter/claude/bg-task-tracker.d.ts +23 -8
  99. package/dist/agent-adapter/claude/bg-task-tracker.js +48 -19
  100. package/dist/agent-adapter/claude/compact-window.d.ts +9 -0
  101. package/dist/agent-adapter/claude/compact-window.js +46 -0
  102. package/dist/agent-adapter/claude/context-usage.d.ts +28 -0
  103. package/dist/agent-adapter/claude/context-usage.js +177 -0
  104. package/dist/agent-adapter/claude/defaults.d.ts +17 -3
  105. package/dist/agent-adapter/claude/defaults.js +25 -9
  106. package/dist/agent-adapter/claude/event-parser.d.ts +30 -0
  107. package/dist/agent-adapter/claude/event-parser.js +68 -4
  108. package/dist/agent-adapter/claude/hooks-builder.d.ts +23 -23
  109. package/dist/agent-adapter/claude/hooks-builder.js +63 -7
  110. package/dist/agent-adapter/claude/spawn-args.d.ts +25 -6
  111. package/dist/agent-adapter/claude/spawn-args.js +62 -22
  112. package/dist/agent-adapter/index.js +2 -4
  113. package/dist/agent-adapter/normalize/event-types.d.ts +8 -1
  114. package/dist/agent-adapter/normalize/event-types.js +1 -1
  115. package/dist/agent-adapter/normalize/tool-names.js +0 -9
  116. package/dist/agent-adapter/pi/adapter.d.ts +3 -33
  117. package/dist/agent-adapter/pi/adapter.js +461 -229
  118. package/dist/agent-adapter/pi/agent-dir.d.ts +6 -0
  119. package/dist/agent-adapter/pi/agent-dir.js +24 -14
  120. package/dist/agent-adapter/pi/defaults.d.ts +4 -0
  121. package/dist/agent-adapter/pi/defaults.js +11 -0
  122. package/dist/agent-adapter/pi/discovery.d.ts +4 -0
  123. package/dist/agent-adapter/pi/discovery.js +63 -0
  124. package/dist/agent-adapter/pi/event-parser.d.ts +13 -2
  125. package/dist/agent-adapter/pi/event-parser.js +139 -69
  126. package/dist/agent-adapter/pi/hook-bridge.d.ts +13 -28
  127. package/dist/agent-adapter/pi/hook-bridge.js +272 -167
  128. package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +24 -0
  129. package/dist/agent-adapter/pi/mcp-bridge-logic.js +39 -0
  130. package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -35
  131. package/dist/agent-adapter/pi/mcp-bridge.js +147 -137
  132. package/dist/agent-adapter/pi/pi-ext-types.d.ts +30 -0
  133. package/dist/agent-adapter/pi/pi-ext-types.js +2 -2
  134. package/dist/agent-adapter/pi/session-support.d.ts +96 -0
  135. package/dist/agent-adapter/pi/session-support.js +213 -0
  136. package/dist/agent-adapter/pi/spawn-args.d.ts +15 -0
  137. package/dist/agent-adapter/pi/spawn-args.js +46 -3
  138. package/dist/agent-adapter/pi/subagent.d.ts +68 -0
  139. package/dist/agent-adapter/pi/subagent.js +521 -0
  140. package/dist/agent-adapter/pi/tool-shims.d.ts +1 -13
  141. package/dist/agent-adapter/pi/tool-shims.js +182 -198
  142. package/dist/agent-adapter/pi/web-fetch.d.ts +13 -0
  143. package/dist/agent-adapter/pi/web-fetch.js +201 -0
  144. package/dist/agent-adapter/pi/web-search.d.ts +9 -0
  145. package/dist/agent-adapter/pi/web-search.js +513 -0
  146. package/dist/agent-adapter/types.d.ts +61 -10
  147. package/dist/agent-adapter/types.js +4 -4
  148. package/dist/core/atomic-write.d.ts +3 -5
  149. package/dist/core/atomic-write.js +26 -12
  150. package/dist/core/bg-held-sessions.d.ts +35 -0
  151. package/dist/core/bg-held-sessions.js +79 -0
  152. package/dist/core/calver.d.ts +1 -0
  153. package/dist/core/calver.js +29 -0
  154. package/dist/core/config-generator.d.ts +13 -2
  155. package/dist/core/config-generator.js +55 -5
  156. package/dist/core/debug-mode.d.ts +14 -0
  157. package/dist/core/debug-mode.js +32 -0
  158. package/dist/core/gateway-generator.js +15 -11
  159. package/dist/core/hook-bus.d.ts +23 -0
  160. package/dist/core/hook-bus.js +111 -0
  161. package/dist/core/hook-exec.d.ts +15 -0
  162. package/dist/core/hook-exec.js +90 -0
  163. package/dist/core/icons.d.ts +2 -0
  164. package/dist/core/icons.js +2 -0
  165. package/dist/core/locales/en.d.ts +30 -7
  166. package/dist/core/locales/en.js +4 -1
  167. package/dist/core/locales/slices/commands.d.ts +12 -2
  168. package/dist/core/locales/slices/commands.js +31 -7
  169. package/dist/core/locales/slices/init.d.ts +1 -1
  170. package/dist/core/locales/slices/init.js +2 -2
  171. package/dist/core/locales/slices/interactions.d.ts +6 -0
  172. package/dist/core/locales/slices/interactions.js +14 -0
  173. package/dist/core/locales/slices/status.d.ts +7 -3
  174. package/dist/core/locales/slices/status.js +16 -8
  175. package/dist/core/log.js +4 -3
  176. package/dist/core/paths.d.ts +9 -0
  177. package/dist/core/paths.js +20 -1
  178. package/dist/core/profile-generator.d.ts +2 -2
  179. package/dist/core/profile-generator.js +6 -9
  180. package/dist/core/running-executions.d.ts +10 -1
  181. package/dist/core/running-executions.js +10 -0
  182. package/dist/core/status-format.d.ts +14 -0
  183. package/dist/core/status-format.js +23 -1
  184. package/dist/core/task-node.d.ts +7 -0
  185. package/dist/core/task-node.js +29 -0
  186. package/dist/core/types/agent-types.d.ts +23 -2
  187. package/dist/core/types/agent-types.js +2 -2
  188. package/dist/core/types/thread-types.d.ts +90 -15
  189. package/dist/core/types/thread-types.js +3 -3
  190. package/dist/core/utils.d.ts +2 -2
  191. package/dist/core/utils.js +3 -3
  192. package/dist/domain/agents/config.d.ts +6 -5
  193. package/dist/domain/agents/config.js +17 -5
  194. package/dist/domain/agents/facade.d.ts +74 -10
  195. package/dist/domain/agents/facade.js +333 -62
  196. package/dist/domain/agents/index.d.ts +1 -0
  197. package/dist/domain/agents/index.js +1 -0
  198. package/dist/domain/agents/profile-manager.d.ts +14 -7
  199. package/dist/domain/agents/profile-manager.js +23 -7
  200. package/dist/domain/agents/profile-switch.d.ts +53 -0
  201. package/dist/domain/agents/profile-switch.js +79 -0
  202. package/dist/domain/costs/cost-tracker.d.ts +21 -1
  203. package/dist/domain/costs/cost-tracker.js +54 -26
  204. package/dist/domain/costs/gateway-manager.js +5 -3
  205. package/dist/domain/costs/rate-limit-throttle.d.ts +44 -19
  206. package/dist/domain/costs/rate-limit-throttle.js +331 -103
  207. package/dist/domain/costs/resume-registry.d.ts +17 -9
  208. package/dist/domain/costs/resume-registry.js +63 -8
  209. package/dist/domain/executions/log-tailer.d.ts +71 -0
  210. package/dist/domain/executions/log-tailer.js +195 -0
  211. package/dist/domain/executions/registry.d.ts +10 -1
  212. package/dist/domain/executions/registry.js +14 -0
  213. package/dist/domain/hooks/hook-view.d.ts +22 -0
  214. package/dist/domain/hooks/hook-view.js +38 -0
  215. package/dist/domain/mcp/core-server.d.ts +0 -1
  216. package/dist/domain/mcp/core-server.js +8 -40
  217. package/dist/domain/mcp/feishu/file.js +1 -11
  218. package/dist/domain/mcp/feishu/index.d.ts +0 -2
  219. package/dist/domain/mcp/feishu/index.js +5 -56
  220. package/dist/domain/mcp/feishu-server.d.ts +0 -1
  221. package/dist/domain/mcp/feishu-server.js +5 -6
  222. package/dist/domain/mcp/manager-qa-server.d.ts +1 -0
  223. package/dist/domain/mcp/manager-qa-server.js +23 -0
  224. package/dist/domain/mcp/server.d.ts +0 -1
  225. package/dist/domain/mcp/server.js +5 -31
  226. package/dist/domain/mcp/slack-server.d.ts +0 -1
  227. package/dist/domain/mcp/slack-server.js +3 -5
  228. package/dist/domain/mcp/tasks-server.d.ts +1 -0
  229. package/dist/domain/mcp/tasks-server.js +23 -0
  230. package/dist/domain/mcp/thread-server.d.ts +1 -0
  231. package/dist/domain/mcp/thread-server.js +25 -0
  232. package/dist/domain/mcp/tools/context.d.ts +3 -10
  233. package/dist/domain/mcp/tools/context.js +13 -29
  234. package/dist/domain/mcp/tools/manager-qa.d.ts +2 -1
  235. package/dist/domain/mcp/tools/manager-qa.js +49 -53
  236. package/dist/domain/mcp/tools/schedule.d.ts +1 -2
  237. package/dist/domain/mcp/tools/schedule.js +7 -10
  238. package/dist/domain/mcp/tools/slack.d.ts +0 -1
  239. package/dist/domain/mcp/tools/slack.js +2 -13
  240. package/dist/domain/mcp/tools/task-ops.js +10 -137
  241. package/dist/domain/mcp/tools/thread-ops.js +6 -11
  242. package/dist/domain/mcp/tools/tui-ask.d.ts +2 -0
  243. package/dist/domain/mcp/tools/tui-ask.js +8 -0
  244. package/dist/domain/mcp/tools/ui-file.d.ts +2 -0
  245. package/dist/domain/mcp/tools/ui-file.js +49 -0
  246. package/dist/domain/mcp/tui-server.d.ts +0 -1
  247. package/dist/domain/mcp/tui-server.js +39 -24
  248. package/dist/domain/mcp/web-server.d.ts +1 -0
  249. package/dist/domain/mcp/web-server.js +25 -0
  250. package/dist/domain/memory/cortex-md-injector.d.ts +4 -10
  251. package/dist/domain/memory/cortex-md-injector.js +113 -77
  252. package/dist/domain/memory/cortex-md-scanner.d.ts +1 -0
  253. package/dist/domain/memory/cortex-md-scanner.js +5 -2
  254. package/dist/domain/memory/skill-scanner.d.ts +3 -1
  255. package/dist/domain/memory/skill-scanner.js +8 -12
  256. package/dist/domain/memory/user-context.d.ts +6 -5
  257. package/dist/domain/memory/user-context.js +12 -7
  258. package/dist/domain/monitor/disk-monitor.js +2 -3
  259. package/dist/domain/projects/index.d.ts +1 -0
  260. package/dist/domain/projects/project-store.d.ts +18 -0
  261. package/dist/domain/projects/project-store.js +39 -3
  262. package/dist/domain/remote/client-hot-reload.d.ts +9 -2
  263. package/dist/domain/remote/client-hot-reload.js +81 -9
  264. package/dist/domain/remote/client-manager.d.ts +15 -1
  265. package/dist/domain/remote/client-manager.js +75 -11
  266. package/dist/domain/remote/cortex-client.js +6 -48
  267. package/dist/domain/scheduling/job-registry.d.ts +0 -2
  268. package/dist/domain/scheduling/job-registry.js +2 -6
  269. package/dist/domain/scheduling/jobs/_shared.d.ts +5 -1
  270. package/dist/domain/scheduling/jobs/_shared.js +2 -1
  271. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.d.ts +1 -0
  272. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.js +78 -0
  273. package/dist/domain/scheduling/jobs/scheduled-task.js +1 -3
  274. package/dist/domain/scheduling/jobs/task-dispatch.js +40 -31
  275. package/dist/domain/scheduling/scheduler.d.ts +0 -10
  276. package/dist/domain/scheduling/scheduler.js +9 -9
  277. package/dist/domain/sessions/session-hooks.d.ts +38 -15
  278. package/dist/domain/sessions/session-hooks.js +128 -122
  279. package/dist/domain/sessions/session-lifecycle.d.ts +38 -1
  280. package/dist/domain/sessions/session-lifecycle.js +41 -4
  281. package/dist/domain/sessions/session-registry.d.ts +3 -1
  282. package/dist/domain/system/doctor.d.ts +63 -0
  283. package/dist/domain/system/doctor.js +359 -0
  284. package/dist/domain/system/server-update-check.d.ts +2 -1
  285. package/dist/domain/system/server-update-check.js +7 -26
  286. package/dist/domain/system/system-notice.d.ts +18 -0
  287. package/dist/domain/system/system-notice.js +34 -0
  288. package/dist/domain/tasks/acceptance-ledger.d.ts +31 -0
  289. package/dist/domain/tasks/acceptance-ledger.js +83 -0
  290. package/dist/domain/tasks/claim-recovery.d.ts +10 -0
  291. package/dist/domain/tasks/claim-recovery.js +64 -0
  292. package/dist/domain/tasks/dispatch-utils.d.ts +19 -0
  293. package/dist/domain/tasks/dispatcher.js +1 -3
  294. package/dist/domain/tasks/mutator.d.ts +7 -1
  295. package/dist/domain/tasks/mutator.js +55 -3
  296. package/dist/domain/tasks/recommendation/extractor.js +3 -3
  297. package/dist/domain/tasks/system/cortex-run.js +0 -0
  298. package/dist/domain/tasks/system/task-cli.d.ts +2 -0
  299. package/dist/domain/tasks/system/task-cli.js +37 -7
  300. package/dist/domain/tasks/system/task-completion.js +148 -42
  301. package/dist/domain/tasks/system/task-lifecycle-edit.js +3 -0
  302. package/dist/domain/tasks/system/task-state.d.ts +10 -1
  303. package/dist/domain/tasks/system/task-state.js +31 -1
  304. package/dist/domain/threads/artifact-io.d.ts +3 -15
  305. package/dist/domain/threads/artifact-io.js +13 -119
  306. package/dist/domain/threads/hook-runner.d.ts +7 -2
  307. package/dist/domain/threads/hook-runner.js +68 -85
  308. package/dist/domain/threads/index.js +6 -1
  309. package/dist/domain/threads/prompt-builder.d.ts +14 -4
  310. package/dist/domain/threads/prompt-builder.js +38 -20
  311. package/dist/domain/threads/runner.d.ts +19 -5
  312. package/dist/domain/threads/runner.js +238 -82
  313. package/dist/domain/threads/shell-templates.d.ts +9 -0
  314. package/dist/domain/threads/shell-templates.js +117 -0
  315. package/dist/domain/threads/state-machine.d.ts +35 -7
  316. package/dist/domain/threads/state-machine.js +170 -29
  317. package/dist/domain/threads/template-loader.d.ts +15 -7
  318. package/dist/domain/threads/template-loader.js +204 -87
  319. package/dist/domain/threads/thread-transcript.d.ts +47 -0
  320. package/dist/domain/threads/thread-transcript.js +64 -0
  321. package/dist/domain/threads/utils.d.ts +8 -1
  322. package/dist/domain/threads/utils.js +17 -1
  323. package/dist/domain/tui-session/tui-session-service.js +9 -16
  324. package/dist/domain/tui-session/types.d.ts +12 -0
  325. package/dist/domain/ui-service/app-router.d.ts +670 -0
  326. package/dist/domain/ui-service/app-router.js +195 -0
  327. package/dist/domain/ui-service/index.d.ts +1 -1
  328. package/dist/domain/ui-service/input-schemas.d.ts +644 -0
  329. package/dist/domain/ui-service/input-schemas.js +385 -0
  330. package/dist/domain/ui-service/mutate/approvals.d.ts +31 -0
  331. package/dist/domain/ui-service/mutate/approvals.js +140 -0
  332. package/dist/domain/ui-service/mutate/config.d.ts +16 -0
  333. package/dist/domain/ui-service/mutate/config.js +72 -0
  334. package/dist/domain/ui-service/mutate/hooks.d.ts +16 -0
  335. package/dist/domain/ui-service/mutate/hooks.js +138 -0
  336. package/dist/domain/ui-service/mutate/issues.d.ts +18 -0
  337. package/dist/domain/ui-service/mutate/issues.js +111 -0
  338. package/dist/domain/ui-service/mutate/notes.d.ts +6 -0
  339. package/dist/domain/ui-service/mutate/notes.js +36 -0
  340. package/dist/domain/ui-service/mutate/projects.d.ts +4 -0
  341. package/dist/domain/ui-service/mutate/projects.js +10 -0
  342. package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
  343. package/dist/domain/ui-service/mutate/schedules.js +57 -3
  344. package/dist/domain/ui-service/mutate/sessions.d.ts +11 -0
  345. package/dist/domain/ui-service/mutate/sessions.js +198 -0
  346. package/dist/domain/ui-service/mutate/system.d.ts +2 -0
  347. package/dist/domain/ui-service/mutate/system.js +97 -0
  348. package/dist/domain/ui-service/query/approvals.d.ts +10 -0
  349. package/dist/domain/ui-service/query/approvals.js +109 -0
  350. package/dist/domain/ui-service/query/config.d.ts +8 -0
  351. package/dist/domain/ui-service/query/config.js +138 -0
  352. package/dist/domain/ui-service/query/executions.d.ts +2 -1
  353. package/dist/domain/ui-service/query/executions.js +47 -3
  354. package/dist/domain/ui-service/query/hooks.d.ts +7 -0
  355. package/dist/domain/ui-service/query/hooks.js +110 -0
  356. package/dist/domain/ui-service/query/issues.d.ts +14 -0
  357. package/dist/domain/ui-service/query/issues.js +85 -0
  358. package/dist/domain/ui-service/query/machines.d.ts +2 -0
  359. package/dist/domain/ui-service/query/machines.js +39 -0
  360. package/dist/domain/ui-service/query/memory.d.ts +5 -0
  361. package/dist/domain/ui-service/query/memory.js +199 -0
  362. package/dist/domain/ui-service/query/notes.d.ts +3 -0
  363. package/dist/domain/ui-service/query/notes.js +18 -0
  364. package/dist/domain/ui-service/query/schedules.js +1 -0
  365. package/dist/domain/ui-service/query/sessions.d.ts +3 -1
  366. package/dist/domain/ui-service/query/sessions.js +227 -15
  367. package/dist/domain/ui-service/query/skills.d.ts +2 -0
  368. package/dist/domain/ui-service/query/skills.js +14 -0
  369. package/dist/domain/ui-service/query/system.d.ts +3 -0
  370. package/dist/domain/ui-service/query/system.js +132 -0
  371. package/dist/domain/ui-service/query/task-verification.d.ts +2 -0
  372. package/dist/domain/ui-service/query/task-verification.js +60 -0
  373. package/dist/domain/ui-service/query/tasks.d.ts +1 -0
  374. package/dist/domain/ui-service/query/tasks.js +24 -16
  375. package/dist/domain/ui-service/query/thread-templates.d.ts +8 -0
  376. package/dist/domain/ui-service/query/thread-templates.js +54 -0
  377. package/dist/domain/ui-service/query/threads.d.ts +2 -1
  378. package/dist/domain/ui-service/query/threads.js +213 -4
  379. package/dist/domain/ui-service/subscribe.js +27 -1
  380. package/dist/domain/ui-service/trpc.d.ts +13 -0
  381. package/dist/domain/ui-service/trpc.js +12 -0
  382. package/dist/domain/ui-service/types.d.ts +1266 -4
  383. package/dist/domain/ui-service/types.js +4 -4
  384. package/dist/domain/ui-service/ui-service.d.ts +2 -1
  385. package/dist/domain/ui-service/ui-service.js +112 -10
  386. package/dist/entry/app.js +307 -36
  387. package/dist/entry/cli.js +10 -0
  388. package/dist/entry/daemon-notice.d.ts +17 -0
  389. package/dist/entry/daemon-notice.js +26 -0
  390. package/dist/entry/daemon.d.ts +23 -1
  391. package/dist/entry/daemon.js +126 -41
  392. package/dist/entry/doctor-cli.d.ts +12 -0
  393. package/dist/entry/doctor-cli.js +76 -0
  394. package/dist/entry/hook-cli.d.ts +18 -0
  395. package/dist/entry/hook-cli.js +468 -0
  396. package/dist/entry/init.js +22 -18
  397. package/dist/entry/start-ui-http.d.ts +44 -0
  398. package/dist/entry/start-ui-http.js +289 -0
  399. package/dist/entry/startup-notify.js +5 -9
  400. package/dist/entry/ui-http-gate.d.ts +11 -0
  401. package/dist/entry/ui-http-gate.js +29 -0
  402. package/dist/events/event-bus.d.ts +7 -2
  403. package/dist/events/event-bus.js +5 -2
  404. package/dist/events/event-logger.js +14 -0
  405. package/dist/events/event-types.d.ts +110 -0
  406. package/dist/events/event-types.js +3 -3
  407. package/dist/hooks/ask-user-question-hook.mjs +1 -0
  408. package/dist/hooks/cortex-hook-api.mjs +84 -0
  409. package/dist/hooks/cortex-md-injector.mjs +99 -49
  410. package/dist/hooks/exit-plan-mode-hook.mjs +1 -0
  411. package/dist/hooks/memory-ref-tracker.mjs +1 -0
  412. package/dist/hooks/new-session-hook.mjs +1 -0
  413. package/dist/hooks/post-task-hook.mjs +1 -0
  414. package/dist/hooks/rules-loader.mjs +1 -0
  415. package/dist/hooks/sensitive-file-edit.mjs +1 -0
  416. package/dist/hooks/session-activity-tracker.mjs +8 -100
  417. package/dist/hooks/task-status-check.mjs +10 -10
  418. package/dist/hooks/tasks-yaml-guard.mjs +1 -0
  419. package/dist/orchestration/agent-file-send.d.ts +54 -0
  420. package/dist/orchestration/agent-file-send.js +110 -0
  421. package/dist/orchestration/agent-runner.d.ts +49 -0
  422. package/dist/orchestration/agent-runner.js +368 -55
  423. package/dist/orchestration/bg-continuation.d.ts +51 -9
  424. package/dist/orchestration/bg-continuation.js +53 -15
  425. package/dist/orchestration/bg-wait-guard.d.ts +28 -0
  426. package/dist/orchestration/bg-wait-guard.js +73 -0
  427. package/dist/orchestration/conduit-queue.d.ts +2 -0
  428. package/dist/orchestration/conduit-queue.js +14 -1
  429. package/dist/orchestration/conversation-runner.d.ts +37 -5
  430. package/dist/orchestration/conversation-runner.js +71 -13
  431. package/dist/orchestration/delta-coalescer.d.ts +69 -0
  432. package/dist/orchestration/delta-coalescer.js +128 -0
  433. package/dist/orchestration/interactions/ask-user-question.d.ts +11 -3
  434. package/dist/orchestration/interactions/ask-user-question.js +27 -3
  435. package/dist/orchestration/interactions/interaction-handlers.js +11 -36
  436. package/dist/orchestration/interactions/interaction-records.d.ts +59 -0
  437. package/dist/orchestration/interactions/interaction-records.js +156 -0
  438. package/dist/orchestration/interactions/plan-approvals.d.ts +5 -0
  439. package/dist/orchestration/interactions/plan-approvals.js +8 -0
  440. package/dist/orchestration/interactions/plan-response.d.ts +8 -0
  441. package/dist/orchestration/interactions/plan-response.js +37 -0
  442. package/dist/orchestration/lifecycle.d.ts +10 -4
  443. package/dist/orchestration/lifecycle.js +155 -60
  444. package/dist/orchestration/manager-qa.d.ts +15 -4
  445. package/dist/orchestration/manager-qa.js +43 -37
  446. package/dist/orchestration/mid-turn-inject.d.ts +105 -0
  447. package/dist/orchestration/mid-turn-inject.js +298 -0
  448. package/dist/orchestration/pending-injection-recovery.d.ts +35 -0
  449. package/dist/orchestration/pending-injection-recovery.js +92 -0
  450. package/dist/orchestration/resume-dispatcher.d.ts +26 -4
  451. package/dist/orchestration/resume-dispatcher.js +89 -43
  452. package/dist/orchestration/routing/commands/cancel.d.ts +26 -0
  453. package/dist/orchestration/routing/commands/cancel.js +64 -18
  454. package/dist/orchestration/routing/commands/compact.d.ts +10 -0
  455. package/dist/orchestration/routing/commands/compact.js +26 -0
  456. package/dist/orchestration/routing/commands/index.d.ts +2 -0
  457. package/dist/orchestration/routing/commands/index.js +9 -0
  458. package/dist/orchestration/routing/commands/mode.js +24 -11
  459. package/dist/orchestration/routing/commands/restart.d.ts +22 -0
  460. package/dist/orchestration/routing/commands/restart.js +49 -0
  461. package/dist/orchestration/routing/commands/session.js +4 -0
  462. package/dist/orchestration/routing/commands/status.js +5 -0
  463. package/dist/orchestration/routing/edit-handler.js +1 -1
  464. package/dist/orchestration/routing/hook-bridge-subscribers.d.ts +2 -1
  465. package/dist/orchestration/routing/hook-bridge-subscribers.js +45 -4
  466. package/dist/orchestration/routing/hook-bridge.d.ts +10 -3
  467. package/dist/orchestration/routing/hook-bridge.js +26 -14
  468. package/dist/orchestration/routing/webhook.js +110 -19
  469. package/dist/orchestration/session-compact.d.ts +58 -0
  470. package/dist/orchestration/session-compact.js +82 -0
  471. package/dist/orchestration/session-events.d.ts +111 -0
  472. package/dist/orchestration/session-events.js +113 -0
  473. package/dist/orchestration/session-rewind.d.ts +72 -0
  474. package/dist/orchestration/session-rewind.js +104 -0
  475. package/dist/orchestration/session-send.d.ts +19 -0
  476. package/dist/orchestration/session-send.js +39 -0
  477. package/dist/orchestration/status-helpers.d.ts +4 -0
  478. package/dist/orchestration/status-helpers.js +18 -0
  479. package/dist/orchestration/thread-callback.d.ts +75 -3
  480. package/dist/orchestration/thread-callback.js +329 -74
  481. package/dist/orchestration/thread-executor.d.ts +1 -0
  482. package/dist/orchestration/thread-executor.js +23 -31
  483. package/dist/orchestration/web-bg-hold.d.ts +52 -0
  484. package/dist/orchestration/web-bg-hold.js +105 -0
  485. package/dist/platform/adapter.d.ts +3 -0
  486. package/dist/platform/adapter.js +2 -2
  487. package/dist/platform/adapters/composite-adapter.d.ts +6 -1
  488. package/dist/platform/adapters/composite-adapter.js +64 -4
  489. package/dist/platform/adapters/feishu.d.ts +6 -1
  490. package/dist/platform/adapters/feishu.js +52 -12
  491. package/dist/platform/adapters/slack.d.ts +2 -1
  492. package/dist/platform/adapters/slack.js +41 -9
  493. package/dist/platform/adapters/tui/index.d.ts +1 -1
  494. package/dist/platform/adapters/tui/ports.d.ts +8 -7
  495. package/dist/platform/adapters/tui/tui-gateway.d.ts +7 -0
  496. package/dist/platform/adapters/tui/tui-gateway.js +48 -5
  497. package/dist/platform/adapters/tui/tui-transcript.js +17 -29
  498. package/dist/platform/index.d.ts +1 -1
  499. package/dist/platform/index.js +1 -1
  500. package/dist/platform/interactive-builder.d.ts +7 -0
  501. package/dist/platform/interactive-builder.js +22 -2
  502. package/dist/platform/testing.d.ts +5 -0
  503. package/dist/platform/testing.js +7 -2
  504. package/dist/platform/tui/protocol.d.ts +0 -2
  505. package/dist/platform/tui/protocol.js +4 -53
  506. package/dist/platform/types.d.ts +12 -0
  507. package/dist/platform/types.js +5 -0
  508. package/dist/platform/ui-http/access-jwt.d.ts +28 -0
  509. package/dist/platform/ui-http/access-jwt.js +67 -0
  510. package/dist/platform/ui-http/app-update.d.ts +58 -0
  511. package/dist/platform/ui-http/app-update.js +155 -0
  512. package/dist/platform/ui-http/ui-http-server.d.ts +56 -0
  513. package/dist/platform/ui-http/ui-http-server.js +231 -0
  514. package/dist/platform/ui-http/ui-ota.d.ts +20 -0
  515. package/dist/platform/ui-http/ui-ota.js +128 -0
  516. package/dist/platform/ui-http/zip-writer.d.ts +13 -0
  517. package/dist/platform/ui-http/zip-writer.js +102 -0
  518. package/dist/platform/utils/reaction-diagnostics.d.ts +4 -0
  519. package/dist/platform/utils/reaction-diagnostics.js +23 -0
  520. package/dist/store/conversation-history-repo.d.ts +243 -0
  521. package/dist/store/conversation-history-repo.js +399 -0
  522. package/dist/store/execution-repo.d.ts +19 -1
  523. package/dist/store/execution-repo.js +18 -1
  524. package/dist/store/hook-registry.d.ts +83 -0
  525. package/dist/store/hook-registry.js +318 -0
  526. package/dist/store/hook-sync.d.ts +12 -16
  527. package/dist/store/hook-sync.js +169 -70
  528. package/dist/store/hook-writer.d.ts +49 -0
  529. package/dist/store/hook-writer.js +132 -0
  530. package/dist/store/outbound-queue.d.ts +8 -0
  531. package/dist/store/outbound-queue.js +24 -3
  532. package/dist/store/pending-injection-repo.d.ts +30 -0
  533. package/dist/store/pending-injection-repo.js +51 -0
  534. package/dist/store/plugin-sync.d.ts +21 -0
  535. package/dist/store/plugin-sync.js +119 -0
  536. package/dist/store/profile-repo.d.ts +2 -1
  537. package/dist/store/profile-repo.js +6 -11
  538. package/dist/store/project-notes-repo.d.ts +27 -0
  539. package/dist/store/project-notes-repo.js +214 -0
  540. package/dist/store/provider-state-repo.d.ts +18 -0
  541. package/dist/store/provider-state-repo.js +107 -0
  542. package/dist/store/schedule-repo.d.ts +0 -21
  543. package/dist/store/schedule-repo.js +4 -25
  544. package/dist/store/session-registry-repo.d.ts +47 -1
  545. package/dist/store/session-registry-repo.js +71 -3
  546. package/dist/store/version-migrations.d.ts +11 -0
  547. package/dist/store/version-migrations.js +286 -9
  548. package/dist/tui/App.js +219 -27
  549. package/dist/tui/components/Dashboard.d.ts +3 -1
  550. package/dist/tui/components/Dashboard.js +31 -12
  551. package/dist/tui/components/DashboardCostTab.js +17 -2
  552. package/dist/tui/components/DashboardExecutionsTab.js +21 -1
  553. package/dist/tui/components/DashboardSchedulesTab.js +8 -3
  554. package/dist/tui/components/DashboardTasksTab.js +11 -6
  555. package/dist/tui/components/DashboardThreadsTab.js +20 -2
  556. package/dist/tui/components/InputBox.d.ts +17 -1
  557. package/dist/tui/components/InputBox.js +263 -8
  558. package/dist/tui/components/Notifications.js +7 -2
  559. package/dist/tui/components/ProjectSwitcher.js +7 -2
  560. package/dist/tui/components/SessionPicker.js +10 -1
  561. package/dist/tui/components/SidePanel.d.ts +3 -1
  562. package/dist/tui/components/SidePanel.js +4 -2
  563. package/dist/tui/components/SlashMenu.d.ts +8 -0
  564. package/dist/tui/components/SlashMenu.js +14 -0
  565. package/dist/tui/components/StatusLine.d.ts +12 -3
  566. package/dist/tui/components/StatusLine.js +29 -10
  567. package/dist/tui/components/Transcript.d.ts +9 -0
  568. package/dist/tui/components/Transcript.js +131 -26
  569. package/dist/tui/components/dashboard-constants.d.ts +1 -0
  570. package/dist/tui/components/dashboard-constants.js +7 -0
  571. package/dist/tui/hooks/useKeybindings.d.ts +1 -0
  572. package/dist/tui/hooks/useKeybindings.js +9 -14
  573. package/dist/tui/hooks/useMouseHandler.d.ts +17 -0
  574. package/dist/tui/hooks/useMouseHandler.js +103 -0
  575. package/dist/tui/hooks/useTranscript.d.ts +7 -2
  576. package/dist/tui/hooks/useTranscript.js +76 -57
  577. package/dist/tui/index.js +106 -10
  578. package/dist/tui/logic.d.ts +146 -2
  579. package/dist/tui/logic.js +411 -6
  580. package/dist/tui/raf-batch.d.ts +33 -0
  581. package/dist/tui/raf-batch.js +103 -0
  582. package/dist/tui/render/inline-markdown.d.ts +22 -0
  583. package/dist/tui/render/inline-markdown.js +99 -0
  584. package/dist/tui/render/rich-blocks.js +10 -8
  585. package/dist/tui/render-output.d.ts +46 -0
  586. package/dist/tui/render-output.js +86 -0
  587. package/dist/tui/slash-commands.d.ts +21 -0
  588. package/dist/tui/slash-commands.js +73 -0
  589. package/dist/tui/turn-status.d.ts +10 -0
  590. package/dist/tui/turn-status.js +53 -0
  591. package/package.json +17 -7
  592. package/web/dist/apple-touch-icon.png +0 -0
  593. package/web/dist/assets/index-B19jLgji.js +138 -0
  594. package/web/dist/assets/index-BuFyPyRW.css +1 -0
  595. package/web/dist/assets/index-DCgngTJG.js +1 -0
  596. package/web/dist/assets/pdf-worker-DIEXcFxP.js +55 -0
  597. package/web/dist/assets/pdf.worker.min-DqNZU1-t.js +53 -0
  598. package/web/dist/favicon-32.png +0 -0
  599. package/web/dist/favicon.svg +7 -0
  600. package/web/dist/index.html +37 -0
  601. package/defaults/config/session-hooks.json +0 -7
  602. package/defaults/config/thread-templates.json +0 -594
  603. package/defaults/prompts/directives/milestone-executor.md +0 -119
  604. package/defaults/prompts/directives/milestone-reviewer.md +0 -108
  605. package/defaults/prompts/directives/plan-executor.md +0 -121
  606. package/defaults/prompts/directives/plan-reviewer.md +0 -99
  607. package/dist/agent-adapter/codex/adapter.d.ts +0 -42
  608. package/dist/agent-adapter/codex/adapter.js +0 -916
  609. package/dist/agent-adapter/codex/event-parser.d.ts +0 -17
  610. package/dist/agent-adapter/codex/event-parser.js +0 -41
  611. package/dist/agent-adapter/codex/spawn-args.d.ts +0 -6
  612. package/dist/agent-adapter/codex/spawn-args.js +0 -30
  613. package/dist/domain/costs/codex-event-format.d.ts +0 -4
  614. package/dist/domain/costs/codex-event-format.js +0 -66
  615. package/dist/domain/costs/codex-usage-monitor.d.ts +0 -6
  616. package/dist/domain/costs/codex-usage-monitor.js +0 -73
  617. package/dist/domain/costs/rate-limit-parser.d.ts +0 -11
  618. package/dist/domain/costs/rate-limit-parser.js +0 -87
  619. package/dist/domain/mcp/feishu/bitable.d.ts +0 -3
  620. package/dist/domain/mcp/feishu/bitable.js +0 -168
  621. package/dist/domain/mcp/feishu/block-types.d.ts +0 -44
  622. package/dist/domain/mcp/feishu/block-types.js +0 -127
  623. package/dist/domain/mcp/feishu/blocks-to-text.d.ts +0 -19
  624. package/dist/domain/mcp/feishu/blocks-to-text.js +0 -43
  625. package/dist/domain/mcp/feishu/docx.d.ts +0 -3
  626. package/dist/domain/mcp/feishu/docx.js +0 -163
  627. package/dist/domain/mcp/feishu/drive.d.ts +0 -23
  628. package/dist/domain/mcp/feishu/drive.js +0 -66
  629. package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +0 -40
  630. package/dist/domain/mcp/feishu/markdown-to-blocks.js +0 -191
  631. package/dist/domain/mcp/feishu/sheets.d.ts +0 -3
  632. package/dist/domain/mcp/feishu/sheets.js +0 -119
  633. package/dist/domain/mcp/feishu/wiki.d.ts +0 -3
  634. package/dist/domain/mcp/feishu/wiki.js +0 -77
  635. package/dist/tui/components/Header.d.ts +0 -11
  636. package/dist/tui/components/Header.js +0 -5
  637. package/dist/tui/components/MessageRow.d.ts +0 -7
  638. package/dist/tui/components/MessageRow.js +0 -10
package/dist/tui/App.js CHANGED
@@ -3,24 +3,31 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // output: Top-level layout + global key handler for M5 Ink client
4
4
  // pos: Main App component wiring all pieces together
5
5
  import { useCallback, useRef, useState, useEffect } from 'react';
6
- import { Box } from 'ink';
7
- import { Header } from './components/Header.js';
6
+ import { Box, useStdout } from 'ink';
8
7
  import { Transcript } from './components/Transcript.js';
9
8
  import { InputBox } from './components/InputBox.js';
10
9
  import { StatusLine } from './components/StatusLine.js';
11
10
  import { SidePanel } from './components/SidePanel.js';
12
- import { NotificationsBadge, NotificationsModal } from './components/Notifications.js';
11
+ import { NotificationsModal } from './components/Notifications.js';
13
12
  import { ProjectSwitcher } from './components/ProjectSwitcher.js';
14
13
  import { useMutate } from './hooks/useMutate.js';
15
14
  import { useTranscript } from './hooks/useTranscript.js';
16
15
  import { useKeybindings } from './hooks/useKeybindings.js';
16
+ import { useMouseHandler } from './hooks/useMouseHandler.js';
17
+ import { osc52Copy } from './logic.js';
17
18
  import { useNotifications } from './hooks/useNotifications.js';
18
19
  import { useDashboardData } from './hooks/useDashboardData.js';
19
20
  import { SessionPicker } from './components/SessionPicker.js';
21
+ import { SLASH_COMMANDS } from './slash-commands.js';
20
22
  import { AskUserModal } from './components/AskUserModal.js';
21
23
  import { PlanFeedbackModal } from './components/PlanFeedbackModal.js';
22
- import { isNotification, isUiQueryResult, isUiEvent, isErrorFrame } from '../platform/tui/protocol.js';
23
- import { computeFocusZone, isAgentResponseFrame } from './logic.js';
24
+ import { isNotification, isUiQueryResult, isUiEvent, isErrorFrame, isChatPost, isChatUpdate } from '../platform/tui/protocol.js';
25
+ import { computeFocusZone, isAgentResponseFrame, matchResumeTarget } from './logic.js';
26
+ import { parseTurnStatus, formatTurnStatus } from './turn-status.js';
27
+ /** A status message is the only TUI chat content that carries an `actions` rich-block. */
28
+ function hasActionsBlock(content) {
29
+ return !!content?.richBlocks?.some(b => b?.type === 'actions');
30
+ }
24
31
  export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect, onSendCancel, serverVersion, projectId, sessionName, errorMessage, onSetDispatch, resumableSessions, resumePending, onResumeSelect, onResumeCancel, }) {
25
32
  // ── Hooks ──
26
33
  const [activeModal, setActiveModal] = useState(null);
@@ -50,16 +57,52 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
50
57
  const [sidePanelVisible, setSidePanelVisible] = useState(false);
51
58
  const [notificationsOpen, setNotificationsOpen] = useState(false);
52
59
  const [projectSwitcherOpen, setProjectSwitcherOpen] = useState(false);
60
+ // Bottom-line shortcuts overlay — '?' on an empty input shows it; any key dismisses it.
61
+ const [showShortcuts, setShowShortcuts] = useState(false);
62
+ // Stable callbacks so the memoized InputBox isn't re-rendered by unrelated App state changes.
63
+ const handleToggleShortcuts = useCallback(() => setShowShortcuts(s => !s), []);
64
+ const handleDismissShortcuts = useCallback(() => setShowShortcuts(false), []);
65
+ // Mouse capture (SGR tracking) state. Default ON so the wheel scrolls the transcript (enabled at
66
+ // startup in index.tsx). Ctrl+T / `/mouse` toggles it OFF — writing the SGR disable sequence —
67
+ // to free the mouse for native click-drag text selection + right-click paste (the wheel stops).
68
+ const [mouseCapture, setMouseCapture] = useState(true);
69
+ // Toast message (e.g. "Copied to clipboard!") — auto-clears after 3 seconds.
70
+ const [toast, setToast] = useState(null);
71
+ const toastTimerRef = useRef(null);
72
+ const showToast = useCallback((msg) => {
73
+ if (toastTimerRef.current)
74
+ clearTimeout(toastTimerRef.current);
75
+ setToast(msg);
76
+ toastTimerRef.current = setTimeout(() => { setToast(null); toastTimerRef.current = null; }, 3000);
77
+ }, []);
53
78
  // Project switcher state
54
79
  const [projects, setProjects] = useState([]);
55
80
  const [projectsLoading, setProjectsLoading] = useState(false);
56
81
  const [projectsError, setProjectsError] = useState(null);
82
+ // `/resume` session picker (client-side, replaces the inert Resume button).
83
+ const [slashResumeSessions, setSlashResumeSessions] = useState(null);
84
+ // `/resume <id>` direct-jump target (session id / name / suffix). Resolved against the
85
+ // sessions.list result; null means "show the picker".
86
+ const resumeTargetRef = useRef(null);
87
+ // Dedicated turn-status line shown above the input (state/time/turns/cost). Status
88
+ // frames (identified by their `actions` rich-block) are routed here, NOT the transcript.
89
+ const [turnStatus, setTurnStatus] = useState(null);
57
90
  const transcriptRef = useRef(null);
58
- // Cost summary from dashboard state (computed)
59
- const costData = dashboard.state.tabs.cost.data.length > 0 ? dashboard.state.tabs.cost.data : [];
60
- const costSummary = costData.length > 0 && typeof costData[0]?.totalCost === 'number'
61
- ? `$${costData[0].totalCost.toFixed(2)}`
62
- : null;
91
+ // Terminal size — drives the full-screen root box and updates on resize so the layout
92
+ // always fills the alternate-screen buffer (see enterFullscreen in index.tsx).
93
+ const { stdout } = useStdout();
94
+ const [termSize, setTermSize] = useState(() => ({
95
+ rows: stdout?.rows ?? 24,
96
+ columns: stdout?.columns ?? 80,
97
+ }));
98
+ useEffect(() => {
99
+ if (!stdout)
100
+ return;
101
+ const onResize = () => setTermSize({ rows: stdout.rows, columns: stdout.columns });
102
+ onResize();
103
+ stdout.on('resize', onResize);
104
+ return () => { stdout.off('resize', onResize); };
105
+ }, [stdout]);
63
106
  // Active tab for dashboard
64
107
  const [activeTab, setActiveTab] = useState('threads');
65
108
  // Route non-mutate frames to the appropriate handler
@@ -76,6 +119,37 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
76
119
  return;
77
120
  }
78
121
  if (isUiQueryResult(frame) || isUiEvent(frame)) {
122
+ // Handle the `/resume` session list
123
+ if (isUiQueryResult(frame) && frame.id === 'slash-resume-list') {
124
+ const list = (frame.ok && Array.isArray(frame.data))
125
+ ? frame.data.map((s) => ({
126
+ sessionId: s.sessionId ?? s.id,
127
+ name: s.name,
128
+ projectId: s.projectId,
129
+ label: s.label ?? null,
130
+ }))
131
+ : [];
132
+ // `/resume <id>`: resolve the target and jump straight in, skipping the picker.
133
+ const target = resumeTargetRef.current;
134
+ resumeTargetRef.current = null;
135
+ if (target) {
136
+ const matchedId = matchResumeTarget(list, target);
137
+ if (matchedId) {
138
+ const matched = list.find(s => s.sessionId === matchedId);
139
+ sendFrame({
140
+ type: 'session.switch',
141
+ id: 'slash-resume-direct',
142
+ projectId: matched?.projectId ?? projectId ?? 'general',
143
+ sessionId: matchedId,
144
+ });
145
+ setSlashResumeSessions(null);
146
+ return;
147
+ }
148
+ // No match — fall through to the picker so the user can choose.
149
+ }
150
+ setSlashResumeSessions(list);
151
+ return;
152
+ }
79
153
  // Handle project switcher responses
80
154
  if (isUiQueryResult(frame) && frame.id === 'proj-switcher-list') {
81
155
  if (frame.ok) {
@@ -93,8 +167,16 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
93
167
  dashboard.dispatch(frame);
94
168
  return;
95
169
  }
170
+ // Status messages (the "⏳ Processing…/✅ Done…" line) carry an `actions` rich-block.
171
+ // Route them to the dedicated turn-status line above the input instead of the
172
+ // transcript, so the chat history holds only real user/assistant messages.
173
+ if ((isChatPost(frame) || isChatUpdate(frame)) && hasActionsBlock(frame.content)) {
174
+ const text = String(frame.content?.text ?? '');
175
+ setTurnStatus(text ? formatTurnStatus(parseTurnStatus(text)) : null);
176
+ return;
177
+ }
96
178
  transcript.dispatch(frame);
97
- }, [transcript.dispatch, dashboard.dispatch, notif.add]);
179
+ }, [transcript.dispatch, dashboard.dispatch, notif.add, sendFrame, projectId]);
98
180
  // Mutate hook: sends ui.mutate frames, correlates results by id, 10s timeout
99
181
  const { mutate, handleFrame } = useMutate({ sendFrame, onFrame: routeFrame });
100
182
  // Combined dispatch: mutate intercepts mutateResult; rest routes normally
@@ -105,11 +187,21 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
105
187
  useEffect(() => {
106
188
  sendFrame({ type: 'ui.query', id: 'dash-cost', scope: 'cost.summary', params: {} });
107
189
  }, []);
108
- // Switching project/session (session.switched is handled in index.tsx and never
109
- // reaches routeFrame) must release any pending send-lock from the old session.
190
+ // Switching project/session (session.switched is handled in index.tsx and never reaches
191
+ // routeFrame) must release any pending send-lock from the OLD session. With lazy session
192
+ // creation the first message transitions sessionName null→name — that is NOT a switch and
193
+ // must NOT clear the in-flight `awaitingResponse`/queued state, so we only reset when a real
194
+ // prior session existed and actually changed.
195
+ const prevSessionRef = useRef({ projectId, sessionName });
110
196
  useEffect(() => {
111
- setAwaitingResponse(false);
112
- setQueuedCount(0);
197
+ const prev = prevSessionRef.current;
198
+ const isRealSwitch = (prev.sessionName !== null && prev.sessionName !== sessionName)
199
+ || (prev.projectId !== null && prev.projectId !== projectId);
200
+ prevSessionRef.current = { projectId, sessionName };
201
+ if (isRealSwitch) {
202
+ setAwaitingResponse(false);
203
+ setQueuedCount(0);
204
+ }
113
205
  }, [projectId, sessionName]);
114
206
  // Submit message
115
207
  const handleSubmit = useCallback((text) => {
@@ -119,9 +211,14 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
119
211
  id,
120
212
  text,
121
213
  });
214
+ // Optimistically echo genuine user messages into the transcript (the server doesn't echo
215
+ // them back). Skip `!`-prefixed control commands (!new/!cancel/!restart…) — they aren't chat.
216
+ if (text && !text.startsWith('!')) {
217
+ transcript.addUserMessage(text);
218
+ }
122
219
  setQueuedCount(prev => prev + 1);
123
220
  setAwaitingResponse(true);
124
- }, [sendFrame]);
221
+ }, [sendFrame, transcript]);
125
222
  // Cancel (sends !cancel)
126
223
  const handleCancel = useCallback(() => {
127
224
  onSendCancel();
@@ -137,6 +234,10 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
137
234
  const handleScrollDown = useCallback((page) => {
138
235
  transcriptRef.current?.scrollDown(page);
139
236
  }, []);
237
+ // Coalesced wheel scroll: a batched net delta from useMouseHandler applied in one update.
238
+ const handleScrollByLines = useCallback((delta) => {
239
+ transcriptRef.current?.scrollByLines(delta);
240
+ }, []);
140
241
  // Side panel toggle
141
242
  const handleToggleSidePanel = useCallback(() => {
142
243
  setSidePanelVisible(prev => !prev);
@@ -149,6 +250,21 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
149
250
  const handleToggleProjectSwitcher = useCallback(() => {
150
251
  setProjectSwitcherOpen(prev => !prev);
151
252
  }, []);
253
+ // Toggle mouse capture. Writes the SGR mouse enable/disable sequences straight to the TTY so
254
+ // the change takes effect immediately: OFF frees the mouse for native text selection, ON
255
+ // restores wheel-scroll + in-TUI drag-select capture. ?1002h = button-event tracking (motion
256
+ // only while a button is held), ?1006h = SGR encoding. index.tsx's leaveFullscreen disables
257
+ // tracking on exit anyway.
258
+ const handleToggleMouse = useCallback(() => {
259
+ setMouseCapture(prev => {
260
+ const next = !prev;
261
+ try {
262
+ process.stdout.write(next ? '\x1b[?1002h\x1b[?1006h' : '\x1b[?1002l\x1b[?1006l');
263
+ }
264
+ catch { /* best effort */ }
265
+ return next;
266
+ });
267
+ }, []);
152
268
  // Project switcher select
153
269
  const handleProjectSelect = useCallback((selectedProjectId) => {
154
270
  sendFrame({
@@ -179,8 +295,57 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
179
295
  params: {},
180
296
  });
181
297
  }, [sendFrame]);
298
+ // Slash-command dispatch from the input palette.
299
+ const handleCommand = useCallback((name, args) => {
300
+ switch (name) {
301
+ case 'new':
302
+ // Clear the view, then start a new conversation (server runs the pre-close hook).
303
+ handleClearView();
304
+ handleSubmit('!new');
305
+ break;
306
+ case 'newx':
307
+ // Same, but skip the pre-close hook (no save).
308
+ handleClearView();
309
+ handleSubmit('!newq');
310
+ break;
311
+ case 'cancel':
312
+ handleCancel();
313
+ break;
314
+ case 'restart':
315
+ // Send the server-restart command. The WS connection drops during the respawn
316
+ // and the client reconnects automatically (no need to keep the input locked).
317
+ handleSubmit('!restart');
318
+ break;
319
+ case 'resume':
320
+ // `/resume` opens the picker; `/resume <id>` jumps straight to that session.
321
+ resumeTargetRef.current = args.trim() || null;
322
+ sendFrame({ type: 'ui.query', id: 'slash-resume-list', scope: 'sessions.list', params: { resumable: true } });
323
+ break;
324
+ case 'mouse':
325
+ // Client-side only (the server has no !mouse): toggle mouse capture for text selection.
326
+ handleToggleMouse();
327
+ break;
328
+ case 'help':
329
+ // The palette itself lists the commands — nothing else to do.
330
+ break;
331
+ default:
332
+ // Every other registered slash command mirrors a server `!` command (same name). Forward
333
+ // it as `!<name> <args>` so the server's command dispatcher handles it and replies into
334
+ // the transcript. `!`-prefixed text is not echoed as a chat message (see handleSubmit).
335
+ handleSubmit(`!${name}${args ? ` ${args}` : ''}`);
336
+ break;
337
+ }
338
+ }, [handleClearView, handleSubmit, handleCancel, handleToggleMouse, sendFrame]);
339
+ // `/resume` picker selection → switch to the chosen session; Esc/cancel closes it.
340
+ const handleSlashResumeSelect = useCallback((sessionId, pickedProjectId) => {
341
+ sendFrame({ type: 'session.switch', id: 'slash-resume', projectId: pickedProjectId, sessionId });
342
+ setSlashResumeSessions(null);
343
+ }, [sendFrame]);
344
+ const handleSlashResumeCancel = useCallback(() => {
345
+ setSlashResumeSessions(null);
346
+ }, []);
182
347
  // Modals pre-empt input; an open dashboard takes keyboard focus from the input.
183
- const modalOpen = activeModal !== null || notificationsOpen || projectSwitcherOpen;
348
+ const modalOpen = activeModal !== null || notificationsOpen || projectSwitcherOpen || slashResumeSessions !== null;
184
349
  const focusZone = computeFocusZone({ modalOpen, sidePanelVisible });
185
350
  // Keyboard bindings — toggles/cancel always active outside modals; scroll only
186
351
  // when the chat input owns focus; reconnect only when not connected.
@@ -194,26 +359,53 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
194
359
  onToggleSidePanel: handleToggleSidePanel,
195
360
  onToggleNotifications: handleToggleNotifications,
196
361
  onToggleProjectSwitcher: handleToggleProjectSwitcher,
362
+ onToggleMouse: handleToggleMouse,
197
363
  onReconnect,
198
364
  }, focusZone !== 'modal', {
199
365
  allowScroll: focusZone === 'input',
200
366
  allowReconnect: connectionState !== 'connected',
201
367
  });
202
- // Dashboard subscription management callbacks
368
+ // Mouse handler: wheel scroll, text selection (left-drag → OSC 52 copy), right-click hint.
369
+ const handleSelectionComplete = useCallback((range) => {
370
+ const text = transcriptRef.current?.getSelectedText(range);
371
+ if (text && text.length > 0) {
372
+ osc52Copy(text);
373
+ showToast(`Copied ${text.length} chars to clipboard (OSC 52)`);
374
+ }
375
+ }, [showToast]);
376
+ const handleRightClick = useCallback(() => {
377
+ showToast('Use Ctrl+Shift+V to paste');
378
+ }, [showToast]);
379
+ const { selection } = useMouseHandler({
380
+ onScrollUp: handleScrollUp,
381
+ onScrollDown: handleScrollDown,
382
+ onScrollByLines: handleScrollByLines,
383
+ onSelectionComplete: handleSelectionComplete,
384
+ onRightClick: handleRightClick,
385
+ });
386
+ // Dashboard subscription management callbacks. Depend on the stable inner
387
+ // functions (each a useCallback in useDashboardData), NOT the whole `dashboard`
388
+ // object — that object is recreated every render, which previously made these
389
+ // wrappers (and thus the Dashboard effect deps) change identity on every render.
390
+ const { markPending, registerSubscription, unregisterSubscription } = dashboard;
203
391
  const handleMarkPending = useCallback((tab) => {
204
- dashboard.markPending(tab);
205
- }, [dashboard]);
392
+ markPending(tab);
393
+ }, [markPending]);
206
394
  const handleRegisterSubscription = useCallback((queryId, tab) => {
207
- dashboard.registerSubscription(queryId, tab);
208
- }, [dashboard]);
395
+ registerSubscription(queryId, tab);
396
+ }, [registerSubscription]);
209
397
  const handleUnregisterSubscription = useCallback((queryId) => {
210
- dashboard.unregisterSubscription(queryId);
211
- }, [dashboard]);
398
+ unregisterSubscription(queryId);
399
+ }, [unregisterSubscription]);
400
+ // Compute the actual reserved rows for the bottom UI so Transcript sizes its viewport exactly.
401
+ // Base = marginTop(1) + border(3) + StatusLine(1) = 5, plus the optional line above the input
402
+ // (toast OR turn-status — InputBox renders one or the other) and the awaiting-response hint.
403
+ const reservedBottomRows = 5 + ((toast || turnStatus) ? 1 : 0) + (awaitingResponse && focusZone === 'input' ? 1 : 0);
212
404
  // If resume mode with sessions to pick, show picker instead of main layout
213
405
  if (resumableSessions && resumableSessions.length > 0 && onResumeSelect && onResumeCancel) {
214
- return (_jsx(Box, { flexDirection: "column", height: "100%", justifyContent: "center", alignItems: "center", children: _jsx(SessionPicker, { sessions: resumableSessions, onSelect: onResumeSelect, onCancel: onResumeCancel }) }));
406
+ return (_jsx(Box, { flexDirection: "column", height: termSize.rows, width: termSize.columns, justifyContent: "center", alignItems: "center", children: _jsx(SessionPicker, { sessions: resumableSessions, onSelect: onResumeSelect, onCancel: onResumeCancel }) }));
215
407
  }
216
- return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsx(Header, { projectId: projectId, sessionName: sessionName, queuedCount: queuedCount, connected: connectionState === 'connected', notificationCount: notif.unreadCount, costSummary: costSummary }), _jsxs(Box, { flexDirection: "row", flexGrow: 1, children: [_jsx(Box, { flexDirection: "column", flexGrow: 1, children: _jsx(Transcript, { ref: transcriptRef, messages: transcript.messages, ids: transcript.ids }) }), _jsx(SidePanel, { visible: sidePanelVisible, active: focusZone === 'dashboard', sendFrame: sendFrame, projectId: projectId, dashState: dashboard.state, onMarkPending: handleMarkPending, onRegisterSubscription: handleRegisterSubscription, onUnregisterSubscription: handleUnregisterSubscription, activeTab: activeTab, onSetActiveTab: setActiveTab, onMutate: mutate })] }), !notificationsOpen && notif.unreadCount > 0 ? (_jsx(Box, { justifyContent: "flex-end", marginRight: 2, children: _jsx(NotificationsBadge, { unreadCount: notif.unreadCount }) })) : null, activeModal ? (activeModal.modal.callbackId.startsWith('plan')
408
+ return (_jsxs(Box, { flexDirection: "column", height: termSize.rows, width: termSize.columns, children: [_jsx(Box, { flexDirection: "row", flexGrow: 1, justifyContent: "center", children: sidePanelVisible ? (_jsx(SidePanel, { visible: sidePanelVisible, active: focusZone === 'dashboard', sendFrame: sendFrame, projectId: projectId, dashState: dashboard.state, onMarkPending: handleMarkPending, onRegisterSubscription: handleRegisterSubscription, onUnregisterSubscription: handleUnregisterSubscription, activeTab: activeTab, onSetActiveTab: setActiveTab, onMutate: mutate, onClose: handleToggleSidePanel })) : (_jsx(Box, { flexDirection: "column", flexGrow: 1, children: _jsx(Transcript, { ref: transcriptRef, messages: transcript.messages, ids: transcript.ids, reservedRows: reservedBottomRows, selection: selection }) })) }), activeModal ? (activeModal.modal.callbackId.startsWith('plan')
217
409
  ? _jsx(PlanFeedbackModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })
218
- : _jsx(AskUserModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })) : modalOpen ? (_jsxs(Box, { borderStyle: "single", borderDimColor: true, paddingX: 1, marginTop: 1, children: [notificationsOpen ? (_jsx(NotificationsModal, { open: notificationsOpen, notifications: notif.notifications, ids: notif.ids, onMarkRead: notif.markRead, onClose: () => setNotificationsOpen(false), onSelect: handleNotificationSelect })) : null, projectSwitcherOpen ? (_jsx(ProjectSwitcher, { open: projectSwitcherOpen, projects: projects, loading: projectsLoading, error: projectsError, onSelect: handleProjectSelect, onClose: () => setProjectSwitcherOpen(false), onRequestRefresh: handleProjectsRefresh })) : null] })) : (_jsx(InputBox, { onSubmit: handleSubmit, awaitingResponse: awaitingResponse, focus: focusZone === 'input' })), _jsx(StatusLine, { connectionState: connectionState, queuedCount: queuedCount, notificationCount: notif.unreadCount, errorMessage: errorMessage })] }));
410
+ : _jsx(AskUserModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })) : modalOpen ? (_jsxs(Box, { borderStyle: "single", borderDimColor: true, paddingX: 1, marginTop: 1, children: [notificationsOpen ? (_jsx(NotificationsModal, { open: notificationsOpen, notifications: notif.notifications, ids: notif.ids, onMarkRead: notif.markRead, onClose: () => setNotificationsOpen(false), onSelect: handleNotificationSelect })) : null, projectSwitcherOpen ? (_jsx(ProjectSwitcher, { open: projectSwitcherOpen, projects: projects, loading: projectsLoading, error: projectsError, onSelect: handleProjectSelect, onClose: () => setProjectSwitcherOpen(false), onRequestRefresh: handleProjectsRefresh })) : null, slashResumeSessions !== null ? (_jsx(SessionPicker, { sessions: slashResumeSessions, onSelect: handleSlashResumeSelect, onCancel: handleSlashResumeCancel })) : null] })) : (_jsx(InputBox, { onSubmit: handleSubmit, onCommand: handleCommand, commands: SLASH_COMMANDS, awaitingResponse: awaitingResponse, focus: focusZone === 'input', showShortcuts: showShortcuts, onToggleShortcuts: handleToggleShortcuts, onDismissShortcuts: handleDismissShortcuts, statusLine: turnStatus, toast: toast })), _jsx(StatusLine, { connectionState: connectionState, errorMessage: errorMessage, projectId: projectId, queuedCount: queuedCount, notificationCount: notif.unreadCount, showShortcuts: showShortcuts && focusZone === 'input', dashboardActive: focusZone === 'dashboard', mouseCapture: mouseCapture })] }));
219
411
  }
@@ -18,6 +18,8 @@ interface DashboardProps {
18
18
  onUnregisterSubscription: (queryId: string) => void;
19
19
  activeTab: string;
20
20
  onSetActiveTab: (tab: string) => void;
21
+ /** Close the panel (Esc while the dashboard owns the keyboard, mirrors the Ctrl+D toggle). */
22
+ onClose?: () => void;
21
23
  }
22
- export declare function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, }: DashboardProps): React.JSX.Element;
24
+ export declare function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, onClose, }: DashboardProps): React.JSX.Element;
23
25
  export {};
@@ -20,6 +20,21 @@ export const DASHBOARD_TABS = [
20
20
  // ── Tab content renderer ──
21
21
  function TabContent({ tab, active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, }) {
22
22
  const initialQuerySent = useRef(false);
23
+ // The parent (App) hands us fresh callback / sendFrame identities on every render.
24
+ // Holding them in refs lets the query/subscribe effect depend only on
25
+ // [tab, projectId], so it never re-fires (and re-subscribes) merely because the
26
+ // parent re-rendered. Without this the effect cleaned up + re-ran every render,
27
+ // each run calling onMarkPending → setState → re-render → infinite loop (the
28
+ // Ctrl+D render storm that pegged a CPU core at ~95% with "Maximum update depth
29
+ // exceeded").
30
+ const sendFrameRef = useRef(sendFrame);
31
+ sendFrameRef.current = sendFrame;
32
+ const onMarkPendingRef = useRef(onMarkPending);
33
+ onMarkPendingRef.current = onMarkPending;
34
+ const onRegisterSubscriptionRef = useRef(onRegisterSubscription);
35
+ onRegisterSubscriptionRef.current = onRegisterSubscription;
36
+ const onUnregisterSubscriptionRef = useRef(onUnregisterSubscription);
37
+ onUnregisterSubscriptionRef.current = onUnregisterSubscription;
23
38
  // Initial query + subscribe (runs once per tab mount)
24
39
  React.useEffect(() => {
25
40
  const scope = TAB_SCOPES[tab];
@@ -29,29 +44,29 @@ function TabContent({ tab, active, sendFrame, mutate, projectId, dashState, onMa
29
44
  if (!initialQuerySent.current) {
30
45
  initialQuerySent.current = true;
31
46
  // Send query for initial data
32
- sendFrame({ type: 'ui.query', id: queryId, scope: tab === 'cost' ? 'cost.summary' : `${tab}.list`, params: projectId ? { projectId } : {} });
33
- onMarkPending(tab);
47
+ sendFrameRef.current({ type: 'ui.query', id: queryId, scope: tab === 'cost' ? 'cost.summary' : `${tab}.list`, params: projectId ? { projectId } : {} });
48
+ onMarkPendingRef.current(tab);
34
49
  // Subscribe to events
35
- sendFrame({ type: 'ui.subscribe', id: queryId, filter: { events: scope.events, projectId } });
36
- onRegisterSubscription(queryId, tab);
50
+ sendFrameRef.current({ type: 'ui.subscribe', id: queryId, filter: { events: scope.events, projectId } });
51
+ onRegisterSubscriptionRef.current(queryId, tab);
37
52
  }
38
53
  // Cleanup on unmount
39
54
  return () => {
40
- sendFrame({ type: 'ui.unsubscribe', id: queryId });
41
- onUnregisterSubscription(queryId);
55
+ sendFrameRef.current({ type: 'ui.unsubscribe', id: queryId });
56
+ onUnregisterSubscriptionRef.current(queryId);
42
57
  initialQuerySent.current = false;
43
58
  };
44
- }, [tab, projectId, sendFrame, onMarkPending, onRegisterSubscription, onUnregisterSubscription]);
59
+ }, [tab, projectId]);
45
60
  // Re-fetch when loading is triggered by a subscription event
46
61
  React.useEffect(() => {
47
62
  const scope = TAB_SCOPES[tab];
48
63
  if (!scope || !initialQuerySent.current)
49
64
  return;
50
65
  if (dashState.tabs[tab].loading) {
51
- sendFrame({ type: 'ui.query', id: scope.queryId, scope: tab === 'cost' ? 'cost.summary' : `${tab}.list`, params: projectId ? { projectId } : {} });
52
- onMarkPending(tab);
66
+ sendFrameRef.current({ type: 'ui.query', id: scope.queryId, scope: tab === 'cost' ? 'cost.summary' : `${tab}.list`, params: projectId ? { projectId } : {} });
67
+ onMarkPendingRef.current(tab);
53
68
  }
54
- }, [dashState.tabs[tab].loading, tab, projectId, sendFrame, onMarkPending]);
69
+ }, [dashState.tabs[tab].loading, tab, projectId]);
55
70
  switch (tab) {
56
71
  case 'threads':
57
72
  return _jsx(DashboardThreadsTab, { data: dashState.tabs.threads, mutate: mutate, active: active });
@@ -68,13 +83,17 @@ function TabContent({ tab, active, sendFrame, mutate, projectId, dashState, onMa
68
83
  }
69
84
  }
70
85
  // ── Component ──
71
- export function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, }) {
86
+ export function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, onClose, }) {
72
87
  useInput((_input, key) => {
88
+ if (key.escape) {
89
+ onClose?.();
90
+ return;
91
+ }
73
92
  if (key.tab) {
74
93
  const currentIdx = DASHBOARD_TABS.findIndex(t => t.key === activeTab);
75
94
  const nextIdx = (currentIdx + 1) % DASHBOARD_TABS.length;
76
95
  onSetActiveTab(DASHBOARD_TABS[nextIdx].key);
77
96
  }
78
97
  }, { isActive: active });
79
- return (_jsxs(Box, { flexDirection: "column", width: "100%", children: [_jsx(Box, { children: DASHBOARD_TABS.map(t => (_jsx(Box, { paddingX: 1, borderStyle: t.key === activeTab ? 'bold' : 'single', borderDimColor: t.key !== activeTab, children: _jsx(Text, { bold: t.key === activeTab, children: t.label }) }, t.key))) }), _jsx(Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, children: _jsx(TabContent, { tab: activeTab, active: active, sendFrame: sendFrame, mutate: mutate, projectId: projectId, dashState: dashState, onMarkPending: onMarkPending, onRegisterSubscription: onRegisterSubscription, onUnregisterSubscription: onUnregisterSubscription }) })] }));
98
+ return (_jsxs(Box, { flexDirection: "column", width: "100%", children: [_jsx(Box, { children: DASHBOARD_TABS.map((t, i) => (_jsxs(React.Fragment, { children: [i > 0 ? _jsx(Text, { dimColor: true, children: " " }) : null, _jsx(Text, { bold: t.key === activeTab, inverse: t.key === activeTab, children: t.label })] }, t.key))) }), _jsx(Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, children: _jsx(TabContent, { tab: activeTab, active: active, sendFrame: sendFrame, mutate: mutate, projectId: projectId, dashState: dashState, onMarkPending: onMarkPending, onRegisterSubscription: onRegisterSubscription, onUnregisterSubscription: onUnregisterSubscription }) })] }));
80
99
  }
@@ -10,7 +10,22 @@ export function DashboardCostTab({ data }) {
10
10
  if (!data.data || (Array.isArray(data.data) && data.data.length === 0)) {
11
11
  return _jsx(Text, { dimColor: true, children: "No cost data" });
12
12
  }
13
- // data.data might be a CostSummary object — handle both array and object
13
+ // The server returns a CostSummary object (domain/costs/cost-tracker.ts): top-level
14
+ // today/week/month/total are USD numbers; byMode maps mode → { today, week, month, total }.
15
+ // useDashboardData wraps a non-array response in a single-element array.
14
16
  const costData = Array.isArray(data.data) ? data.data[0] : data.data;
15
- return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "Cost Summary" }) }), costData?.totalCost != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Total: " }), _jsxs(Text, { bold: true, children: ["$", typeof costData.totalCost === 'number' ? costData.totalCost.toFixed(4) : costData.totalCost] })] })) : null, costData?.monthlyCost != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "This month: " }), _jsxs(Text, { bold: true, children: ["$", typeof costData.monthlyCost === 'number' ? costData.monthlyCost.toFixed(4) : costData.monthlyCost] })] })) : null, costData?.dailyCost != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Today: " }), _jsxs(Text, { bold: true, children: ["$", typeof costData.dailyCost === 'number' ? costData.dailyCost.toFixed(4) : costData.dailyCost] })] })) : null, costData?.models && typeof costData.models === 'object' ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, children: "By model:" }), Object.entries(costData.models).map(([model, cost]) => (_jsxs(Box, { marginLeft: 1, children: [_jsxs(Text, { dimColor: true, children: [model, ": "] }), _jsxs(Text, { children: ["$", typeof cost === 'number' ? cost.toFixed(4) : String(cost)] })] }, model)))] })) : null, costData?.budgetRemaining != null ? (_jsxs(Box, { marginTop: 1, children: [_jsx(Text, { children: "Budget remaining: " }), _jsxs(Text, { color: costData.budgetRemaining < 1 ? 'red' : 'green', children: ["$", typeof costData.budgetRemaining === 'number' ? costData.budgetRemaining.toFixed(4) : costData.budgetRemaining] })] })) : null, costData?.totalCost == null && costData?.monthlyCost == null && (!costData?.models || Object.keys(costData.models).length === 0) ? (_jsx(Text, { dimColor: true, children: "No cost summary available" })) : null] }));
17
+ const usd = (v) => `$${typeof v === 'number' ? v.toFixed(4) : String(v)}`;
18
+ // byMode is keyed by PERIOD (today/week/month/total); each value is a ModeBuckets
19
+ // { total, api, plan, ... } breaking that period down by cost type. The all-time
20
+ // bucket (byMode.total) gives the api/plan split; skip the 'total' meta key.
21
+ const allTime = costData?.byMode?.total && typeof costData.byMode.total === 'object' ? costData.byMode.total : {};
22
+ const modeEntries = Object.entries(allTime)
23
+ .filter(([k, v]) => k !== 'total' && typeof v === 'number' && v > 0);
24
+ const hasAnyTotal = costData?.total != null || costData?.month != null || costData?.today != null;
25
+ if (!hasAnyTotal && modeEntries.length === 0) {
26
+ return _jsx(Text, { dimColor: true, children: "No cost summary available" });
27
+ }
28
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "Cost Summary" }) }), costData?.total != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Total: " }), _jsx(Text, { children: usd(costData.total) })] })) : null, costData?.month != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "This month: " }), _jsx(Text, { children: usd(costData.month) })] })) : null, costData?.week != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "This week: " }), _jsx(Text, { children: usd(costData.week) })] })) : null, costData?.today != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Today: " }), _jsx(Text, { children: usd(costData.today) })] })) : null, modeEntries.length > 0 ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, children: "By cost type (all-time):" }), modeEntries
29
+ .sort(([, a], [, b]) => b - a)
30
+ .map(([mode, v]) => (_jsxs(Box, { marginLeft: 1, children: [_jsxs(Text, { dimColor: true, children: [mode, ": "] }), _jsx(Text, { children: usd(v) })] }, mode)))] })) : null] }));
16
31
  }
@@ -5,6 +5,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import { useState, useCallback, useRef, useEffect } from 'react';
6
6
  import { Box, Text, useInput } from 'ink';
7
7
  import { ConfirmModal } from './ConfirmModal.js';
8
+ import { computeFocusWindow } from '../logic.js';
9
+ import { DASHBOARD_MAX_VISIBLE_ROWS } from './dashboard-constants.js';
8
10
  export function DashboardExecutionsTab({ data, mutate, active = true }) {
9
11
  const [focusedIndex, setFocusedIndex] = useState(0);
10
12
  const [showConfirm, setShowConfirm] = useState(false);
@@ -66,6 +68,9 @@ export function DashboardExecutionsTab({ data, mutate, active = true }) {
66
68
  }
67
69
  // Clamp focused index to valid range
68
70
  const safeFocused = Math.min(focusedIndex, data.data.length - 1);
71
+ // Cap the rendered slice so a long list can't overflow the terminal (ghost-row corruption).
72
+ const { start, end, hiddenAbove, hiddenBelow } = computeFocusWindow(data.data.length, safeFocused, DASHBOARD_MAX_VISIBLE_ROWS);
73
+ const visible = data.data.slice(start, end);
69
74
  const focusedExec = showConfirm ? data.data[confirmIndexRef.current] : null;
70
75
  // Build ConfirmModal body from focused execution fields
71
76
  let confirmBody = '';
@@ -80,7 +85,22 @@ export function DashboardExecutionsTab({ data, mutate, active = true }) {
80
85
  }
81
86
  confirmBody = parts.join(' | ');
82
87
  }
83
- return (_jsxs(Box, { flexDirection: "column", children: [data.data.map((exec, i) => (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [_jsx(Text, { children: i === safeFocused ? '>' : ' ' }), _jsx(Text, { children: " " }), _jsx(ExecStatusIcon, { status: exec.status }), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: exec.type ?? 'local' }), exec.machine ? _jsxs(Text, { dimColor: true, children: [" @", exec.machine] }) : null] }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { dimColor: true, children: [exec.durationMs ? `${(exec.durationMs / 1000).toFixed(1)}s` : '', exec.cost != null ? ` | $${typeof exec.cost === 'number' ? exec.cost.toFixed(4) : exec.cost}` : '', exec.finishedAt ? ` | ${new Date(exec.finishedAt).toLocaleString()}` : ''] }) }), notFoundMsg?.index === i ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "red", children: notFoundMsg.message }) })) : null] }, exec.id ?? i))), showConfirm && focusedExec ? (_jsx(ConfirmModal, { title: "Cancel execution?", body: confirmBody, onConfirm: handleConfirm, onCancel: handleCancel })) : null] }));
88
+ return (_jsxs(Box, { flexDirection: "column", children: [hiddenAbove > 0 ? _jsxs(Text, { dimColor: true, children: ["\u2191 ", hiddenAbove, " more above"] }) : null, visible.map((exec, vi) => {
89
+ const i = start + vi;
90
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [_jsx(Text, { children: i === safeFocused ? '>' : ' ' }), _jsx(Text, { children: " " }), _jsx(ExecStatusIcon, { status: exec.status }), _jsx(Text, { children: " " }), _jsx(Text, { bold: i === safeFocused, children: exec.type ?? 'local' }), exec.machine ? _jsxs(Text, { dimColor: true, children: [" @", exec.machine] }) : null] }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { dimColor: true, children: execDetailLine(exec) }) }), notFoundMsg?.index === i ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "red", children: notFoundMsg.message }) })) : null] }, exec.id ?? i));
91
+ }), hiddenBelow > 0 ? _jsxs(Text, { dimColor: true, children: ["\u2193 ", hiddenBelow, " more below"] }) : null, showConfirm && focusedExec ? (_jsx(ConfirmModal, { title: "Cancel execution?", body: confirmBody, onConfirm: handleConfirm, onCancel: handleCancel })) : null] }));
92
+ }
93
+ /** Compose the "45.2s | $0.1234 | <time>" detail line, omitting any missing field so a
94
+ * zero/absent duration no longer renders a dangling leading " | ". */
95
+ function execDetailLine(exec) {
96
+ const parts = [];
97
+ if (exec.durationMs)
98
+ parts.push(`${(exec.durationMs / 1000).toFixed(1)}s`);
99
+ if (exec.cost != null)
100
+ parts.push(`$${typeof exec.cost === 'number' ? exec.cost.toFixed(4) : exec.cost}`);
101
+ if (exec.finishedAt)
102
+ parts.push(new Date(exec.finishedAt).toLocaleString());
103
+ return parts.join(' | ');
84
104
  }
85
105
  function ExecStatusIcon({ status }) {
86
106
  switch (status) {
@@ -5,6 +5,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import { useState, useRef, useEffect, useCallback } from 'react';
6
6
  import { Box, Text, useInput } from 'ink';
7
7
  import { ConfirmModal } from './ConfirmModal.js';
8
+ import { computeFocusWindow } from '../logic.js';
9
+ import { DASHBOARD_MAX_VISIBLE_ROWS } from './dashboard-constants.js';
8
10
  export function DashboardSchedulesTab({ data, mutate, active = true }) {
9
11
  if (data.loading && data.data.length === 0) {
10
12
  return _jsx(Text, { dimColor: true, children: "Loading schedules..." });
@@ -89,8 +91,11 @@ function SchedulesList({ data, mutate, active = true }) {
89
91
  removingScheduleIdRef.current = sched.id;
90
92
  }
91
93
  }, { isActive: isInputActive });
92
- // ── Build schedule rows ──
93
- const rows = schedules.map((sched, i) => {
94
+ // ── Build schedule rows (windowed so a long list can't overflow the terminal) ──
95
+ const safeFocused = Math.min(focusedRowIndex, schedules.length - 1);
96
+ const { start, end, hiddenAbove, hiddenBelow } = computeFocusWindow(schedules.length, safeFocused, DASHBOARD_MAX_VISIBLE_ROWS);
97
+ const rows = schedules.slice(start, end).map((sched, vi) => {
98
+ const i = start + vi;
94
99
  const isFocused = i === focusedRowIndex;
95
100
  return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [isFocused ? _jsx(Text, { bold: true, children: '> ' }) : _jsx(Text, { children: " " }), _jsx(ScheduleTypeBadge, { type: sched.type, paused: sched.paused, focused: isFocused }), _jsx(Text, { children: " " }), _jsxs(Text, { bold: isFocused, dimColor: !isFocused, children: [String(sched.message ?? '').slice(0, 25), (sched.message ?? '').length > 25 ? '…' : ''] })] }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { dimColor: true, children: sched.paused
96
101
  ? `paused by ${sched.pausedBy ?? '?'}`
@@ -115,7 +120,7 @@ function SchedulesList({ data, mutate, active = true }) {
115
120
  removingScheduleIdRef.current = null;
116
121
  } }));
117
122
  }
118
- return (_jsxs(Box, { flexDirection: "column", children: [rows, confirmModal] }));
123
+ return (_jsxs(Box, { flexDirection: "column", children: [hiddenAbove > 0 ? _jsxs(Text, { dimColor: true, children: ["\u2191 ", hiddenAbove, " more above"] }) : null, rows, hiddenBelow > 0 ? _jsxs(Text, { dimColor: true, children: ["\u2193 ", hiddenBelow, " more below"] }) : null, confirmModal] }));
119
124
  }
120
125
  function ScheduleTypeBadge({ type, paused, focused }) {
121
126
  const color = paused ? 'yellow' : 'green';
@@ -5,6 +5,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import { useState, useRef, useEffect, useCallback } from 'react';
6
6
  import { Box, Text, useInput } from 'ink';
7
7
  import { ConfirmModal } from './ConfirmModal.js';
8
+ import { computeFocusWindow } from '../logic.js';
9
+ import { DASHBOARD_MAX_VISIBLE_ROWS } from './dashboard-constants.js';
8
10
  // ── Component ──
9
11
  export function DashboardTasksTab({ data, mutate, projectId, active = true }) {
10
12
  if (data.loading && data.data.length === 0) {
@@ -174,12 +176,15 @@ function TasksList({ data, mutate, projectId, active = true }) {
174
176
  }
175
177
  }
176
178
  // ── Task list ──
177
- return (_jsx(Box, { flexDirection: "column", children: tasks.map((task, i) => {
178
- const isFocused = i === focusedIndex;
179
- const isLockBusy = lockBusyRows.has(i);
180
- const hasError = errorState?.index === i;
181
- return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [isFocused ? _jsx(Text, { color: "cyan", children: "\u25B8 " }) : _jsx(Text, { children: " " }), _jsx(TaskStatusIcon, { status: task.status }), _jsx(Text, { children: " " }), _jsx(PriorityBadge, { priority: task.priority }), _jsx(Text, { children: " " }), _jsxs(Text, { bold: isFocused, children: [String(task.text ?? '').slice(0, 30), (task.text ?? '').length > 30 ? '…' : ''] })] }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { dimColor: true, children: [task.claimedBy ? `👤 ${task.claimedBy}` : 'unclaimed', task.blockedBy ? ` | blocked: ${task.blockedBy}` : ''] }) }), isFocused && mutate ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { dimColor: true, children: "[c] Claim [u] Unclaim [d] Done [b] Block [B] Unblock" }) })) : null, isLockBusy ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "yellow", children: "busy \u2014 another agent holds the lock (auto-expires in 20m)" }) })) : null, hasError ? (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "red", children: [errorState.code, ": ", errorState.message] }) })) : null] }, task.id ?? i));
182
- }) }));
179
+ const safeFocused = Math.min(focusedIndex, tasks.length - 1);
180
+ const { start, end, hiddenAbove, hiddenBelow } = computeFocusWindow(tasks.length, safeFocused, DASHBOARD_MAX_VISIBLE_ROWS);
181
+ return (_jsxs(Box, { flexDirection: "column", children: [hiddenAbove > 0 ? _jsxs(Text, { dimColor: true, children: ["\u2191 ", hiddenAbove, " more above"] }) : null, tasks.slice(start, end).map((task, vi) => {
182
+ const i = start + vi;
183
+ const isFocused = i === focusedIndex;
184
+ const isLockBusy = lockBusyRows.has(i);
185
+ const hasError = errorState?.index === i;
186
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [isFocused ? _jsx(Text, { color: "cyan", children: "\u25B8 " }) : _jsx(Text, { children: " " }), _jsx(TaskStatusIcon, { status: task.status }), _jsx(Text, { children: " " }), _jsx(PriorityBadge, { priority: task.priority }), _jsx(Text, { children: " " }), _jsxs(Text, { bold: isFocused, children: [String(task.text ?? '').slice(0, 30), (task.text ?? '').length > 30 ? '…' : ''] })] }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { dimColor: true, children: [task.claimedBy ? `👤 ${task.claimedBy}` : 'unclaimed', task.blockedBy ? ` | blocked: ${task.blockedBy}` : ''] }) }), isFocused && mutate ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { dimColor: true, children: "[c] Claim [u] Unclaim [d] Done [b] Block [B] Unblock" }) })) : null, isLockBusy ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "yellow", children: "busy \u2014 another agent holds the lock (auto-expires in 20m)" }) })) : null, hasError ? (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "red", children: [errorState.code, ": ", errorState.message] }) })) : null] }, task.id ?? i));
187
+ }), hiddenBelow > 0 ? _jsxs(Text, { dimColor: true, children: ["\u2193 ", hiddenBelow, " more below"] }) : null] }));
183
188
  }
184
189
  // ── Sub-components ──
185
190
  function TaskStatusIcon({ status }) {