@kabmo-labs/kabmo 0.24.0 → 0.26.0

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 (325) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +585 -512
  3. package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
  4. package/dist/client/static/js/index-p2yw9ywf.css +1 -0
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  13. package/src/client/components/common/code-surface/shiki.ts +28 -7
  14. package/src/client/components/common/session-actions-menu/index.tsx +59 -2
  15. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  16. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  17. package/src/client/components/common/session-branch/index.tsx +169 -0
  18. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  19. package/src/client/components/common/session-branch/style.ts +29 -0
  20. package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
  21. package/src/client/components/common/session-row/index.tsx +28 -3
  22. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  23. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  24. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  25. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
  26. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  27. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  28. package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
  29. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
  31. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
  32. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  33. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
  34. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
  35. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
  36. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
  37. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
  38. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  39. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
  40. package/src/client/components/settings/Sidebar.tsx +1 -1
  41. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  42. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  43. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  44. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  45. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  46. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  47. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  48. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
  49. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  50. package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
  51. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
  52. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  53. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  55. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  56. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  58. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  59. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  60. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  61. package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
  62. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
  63. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  64. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  65. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  66. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  67. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  68. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  69. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  70. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  71. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  72. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  73. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  74. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  75. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  76. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  77. package/src/client/data/settings/omp-schema.json +1 -1
  78. package/src/client/data/theme/terminal.test.ts +25 -0
  79. package/src/client/data/theme/terminal.ts +96 -79
  80. package/src/client/hooks/chat/composer/items.test.ts +31 -26
  81. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  82. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  83. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  84. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  85. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  86. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  87. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  88. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  89. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  90. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  91. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  92. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  93. package/src/client/hooks/chat/omp/session-list.tsx +4 -0
  94. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  95. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  96. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  97. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  98. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  99. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  100. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  101. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  102. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  103. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  104. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  105. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  106. package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
  107. package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
  108. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  109. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  110. package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
  111. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  112. package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
  113. package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
  114. package/src/client/hooks/chat/timeline/send.test.ts +3 -1
  115. package/src/client/hooks/chat/timeline/send.ts +48 -133
  116. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  117. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  118. package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
  119. package/src/client/hooks/models/use-harness-update.test.ts +286 -0
  120. package/src/client/hooks/models/use-harness-update.ts +250 -0
  121. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  122. package/src/client/hooks/ui/notifications.ts +45 -0
  123. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  124. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  125. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  126. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  127. package/src/client/lib/native/open-session.ts +33 -0
  128. package/src/client/lib/notifications/os.test.ts +125 -0
  129. package/src/client/lib/notifications/os.ts +130 -0
  130. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  131. package/src/client/lib/router/open-session.test.ts +75 -0
  132. package/src/client/lib/router/open-session.ts +34 -0
  133. package/src/client/lib/session-tree.test.ts +50 -0
  134. package/src/client/lib/session-tree.ts +59 -0
  135. package/src/client/lib/signals.ts +5 -1
  136. package/src/client/main.tsx +6 -0
  137. package/src/client/tailwind.css +17 -11
  138. package/src/server/index.ts +2 -0
  139. package/src/server/lib/auth/guard.ts +10 -0
  140. package/src/server/lib/btw/session-copy.server.ts +6 -44
  141. package/src/server/lib/btw/session-copy.test.ts +2 -1
  142. package/src/server/lib/db/schema.ts +5 -0
  143. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  144. package/src/server/lib/db/seed.test.ts +1 -1
  145. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  146. package/src/server/lib/harness/acp/background-work.ts +320 -0
  147. package/src/server/lib/harness/acp/calls.ts +15 -1
  148. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  149. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  150. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  151. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  152. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  153. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  154. package/src/server/lib/harness/acp/client.ts +33 -23
  155. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  156. package/src/server/lib/harness/acp/commands.ts +14 -2
  157. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  158. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  159. package/src/server/lib/harness/acp/frames.ts +71 -158
  160. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  161. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  162. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  163. package/src/server/lib/harness/acp/mapper.ts +12 -0
  164. package/src/server/lib/harness/acp/permissions.ts +6 -0
  165. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  166. package/src/server/lib/harness/acp/prompt.ts +19 -3
  167. package/src/server/lib/harness/acp/protocol.ts +41 -2
  168. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  169. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  170. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  171. package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
  172. package/src/server/lib/harness/acp/session-handshake.ts +110 -7
  173. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  174. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  175. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  176. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  177. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  178. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  179. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  180. package/src/server/lib/harness/acp/session-requests.ts +89 -0
  181. package/src/server/lib/harness/acp/session-turns.ts +28 -8
  182. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  183. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  184. package/src/server/lib/harness/acp/session.test-util.ts +42 -2
  185. package/src/server/lib/harness/acp/session.ts +115 -115
  186. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  187. package/src/server/lib/harness/acp/turn.test.ts +183 -0
  188. package/src/server/lib/harness/acp/turn.ts +102 -10
  189. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  190. package/src/server/lib/harness/acp/v2.ts +220 -0
  191. package/src/server/lib/harness/acp/verbs.ts +58 -8
  192. package/src/server/lib/harness/launch.test.ts +25 -0
  193. package/src/server/lib/harness/launch.ts +24 -10
  194. package/src/server/lib/harness/session.ts +3 -0
  195. package/src/server/lib/harness/spawn.server.ts +15 -2
  196. package/src/server/lib/harness/update-job-store.test.ts +151 -0
  197. package/src/server/lib/harness/update-job-store.ts +115 -0
  198. package/src/server/lib/harness/update-job.server.ts +94 -0
  199. package/src/server/lib/harness/update-queue.server.ts +292 -0
  200. package/src/server/lib/harness/update-queue.test.ts +265 -0
  201. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  202. package/src/server/lib/harness/update-worker.test.ts +153 -0
  203. package/src/server/lib/harness/update-worker.ts +202 -0
  204. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  205. package/src/server/lib/lifecycle/paths.ts +28 -0
  206. package/src/server/lib/omp/rpc/manager.ts +5 -5
  207. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  208. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  209. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  210. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  211. package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
  212. package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
  213. package/src/server/lib/omp/session/delete.server.ts +5 -0
  214. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  215. package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
  216. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  217. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  218. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  219. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  220. package/src/server/lib/sessions/answers.server.ts +37 -0
  221. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  222. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  223. package/src/server/lib/sessions/fork.server.test.ts +277 -0
  224. package/src/server/lib/sessions/fork.server.ts +329 -0
  225. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  226. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  227. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  228. package/src/server/lib/sessions/notify.server.ts +212 -0
  229. package/src/server/lib/sessions/relation-types.ts +76 -0
  230. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  231. package/src/server/lib/sessions/relations.server.ts +337 -0
  232. package/src/server/lib/sessions/resolve.server.ts +106 -0
  233. package/src/server/lib/sessions/schema.server.ts +82 -0
  234. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  235. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  236. package/src/server/lib/sessions/spawn.server.test.ts +237 -0
  237. package/src/server/lib/sessions/spawn.server.ts +335 -0
  238. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  239. package/src/server/lib/terminal/output.test.ts +2 -2
  240. package/src/server/lib/terminal/output.ts +1 -1
  241. package/src/server/lib/terminal/resize.test.ts +99 -0
  242. package/src/server/lib/terminal/runtime.server.ts +26 -6
  243. package/src/server/lib/terminal/send-result.test.ts +18 -1
  244. package/src/server/lib/terminal/send-result.ts +26 -2
  245. package/src/server/lib/terminal/session.server.ts +6 -6
  246. package/src/server/lib/usage/new-api.test.ts +92 -0
  247. package/src/server/lib/usage/new-api.ts +131 -0
  248. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  249. package/src/server/lib/usage/provider-key.ts +33 -0
  250. package/src/server/lib/usage/providers.server.ts +10 -3
  251. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  252. package/src/server/lib/usage/vendor-http.ts +41 -0
  253. package/src/server/lib/usage/window.ts +55 -0
  254. package/src/server/routes/agent/command.ts +14 -1
  255. package/src/server/routes/agent/harness-command.ts +12 -5
  256. package/src/server/routes/agent/new.ts +15 -0
  257. package/src/server/routes/chat/stream.ts +7 -2
  258. package/src/server/routes/harness/add-provider.test.ts +9 -1
  259. package/src/server/routes/harness/import-action.ts +4 -0
  260. package/src/server/routes/harness/import.test.ts +1 -1
  261. package/src/server/routes/harness/index.ts +5 -1
  262. package/src/server/routes/harness/update-status.ts +32 -0
  263. package/src/server/routes/harness/update.test.ts +156 -0
  264. package/src/server/routes/harness/update.ts +64 -147
  265. package/src/server/routes/sessions/answer.ts +24 -0
  266. package/src/server/routes/sessions/batch-delete.ts +11 -5
  267. package/src/server/routes/sessions/body-readers.ts +43 -0
  268. package/src/server/routes/sessions/delete.ts +4 -2
  269. package/src/server/routes/sessions/fork.ts +89 -0
  270. package/src/server/routes/sessions/index.ts +14 -0
  271. package/src/server/routes/sessions/relations.ts +85 -0
  272. package/src/server/routes/sessions/routes.test.ts +1 -2
  273. package/src/server/routes/sessions/session.ts +23 -0
  274. package/src/server/routes/sessions/spawn.ts +137 -0
  275. package/src/server/routes/terminal/ws.ts +3 -3
  276. package/src/shared/lib/chat/composer/client.ts +31 -2
  277. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  278. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  279. package/src/shared/lib/chat/notice-text.ts +1 -1
  280. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  281. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  282. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  283. package/src/shared/lib/code/ansi.ts +1 -1
  284. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  285. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  286. package/src/shared/lib/harness/mode-signal.ts +20 -0
  287. package/src/shared/lib/harness/provider-facts.test.ts +27 -0
  288. package/src/shared/lib/harness/providers.ts +35 -1
  289. package/src/shared/lib/harness/session-modes.ts +24 -0
  290. package/src/shared/lib/harness/update-job.ts +80 -0
  291. package/src/shared/lib/harness/update-plan.test.ts +21 -6
  292. package/src/shared/lib/harness/update-plan.ts +12 -4
  293. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  294. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  295. package/src/shared/lib/notifications/outcomes.ts +64 -0
  296. package/src/shared/lib/notifications/settings.test.ts +49 -0
  297. package/src/shared/lib/notifications/settings.ts +34 -0
  298. package/src/shared/lib/omp/session/default-title.ts +5 -4
  299. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  300. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  301. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  302. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  303. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  304. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  305. package/src/shared/lib/settings/defaults.ts +3 -0
  306. package/src/shared/lib/theme/catalog.test.ts +13 -9
  307. package/src/shared/lib/theme/color.test.ts +2 -2
  308. package/src/shared/lib/theme/color.ts +4 -4
  309. package/src/shared/lib/theme/theme.test.ts +1 -1
  310. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  311. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  312. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  313. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  314. package/src/shared/types/chat.ts +1 -1
  315. package/src/shared/types/harness-update.ts +89 -0
  316. package/src/shared/types/omp/agent.ts +19 -2
  317. package/src/shared/types/realtime.ts +2 -0
  318. package/src/shared/types/settings/state.ts +10 -0
  319. package/src/shared/types/workspace.ts +8 -0
  320. package/src/test-support/fake-omp-fork.ts +16 -2
  321. package/src/test-support/harness-table.test-util.ts +31 -1
  322. package/dist/client/static/js/index-z3w7n85q.css +0 -1
  323. package/src/client/components/common/subagent-list/index.tsx +0 -165
  324. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  325. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -0,0 +1,250 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Starting harness updates, and following every background run they became.
8
+ *
9
+ * The POST used to hold the request open for the whole install; now it answers
10
+ * `202` and each run continues in a detached worker. So the dialog's job has two
11
+ * halves: start it, then poll `GET /api/harness/update/status` until the record
12
+ * says it finished — and, on open, ADOPT whatever is already in flight. That
13
+ * second half is what makes the update really background: closing About, or
14
+ * reloading the page, does not lose the button's state, and a reopened card
15
+ * shows the spinner for the run that is still installing.
16
+ *
17
+ * **ONE loop for EVERY run, because two presses are two records.** A second
18
+ * harness is accepted while the first installs: its record carries `queuedAt`
19
+ * and the server's queue starts it when the run ahead settles, so the card has
20
+ * to follow a run it did not start AND one that has not started yet. A finished
21
+ * run is reported once per harness, and a record that was already finished when
22
+ * the card opened is HISTORY — a reopened dialog must not re-toast last week's
23
+ * install.
24
+ *
25
+ * The rows are re-read once a run settles (`invalidateHarnessVersions`): the
26
+ * update forgot the cached probe, so the next read is the first honest one.
27
+ */
28
+
29
+ import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
30
+ import { invalidateHarnessVersions } from '@/client/hooks/models/use-harness-versions';
31
+ import {
32
+ isHarnessUpdateJob,
33
+ jobMoving,
34
+ jobUnfinished,
35
+ updateJobsFrom,
36
+ } from '@/shared/lib/harness/update-job';
37
+ import type { HarnessUpdateJob } from '@/shared/types/harness-update';
38
+
39
+ /** One poll per second: the worker flushes at 400ms, and this is a dialog. */
40
+ export const HARNESS_UPDATE_POLL_MS = 1_000;
41
+
42
+ /**
43
+ * Stop polling after this long and hand the control back.
44
+ *
45
+ * The install itself is bounded per step by the worker; this only stops an open
46
+ * dialog from asking forever if the server stopped answering. The run is not
47
+ * cancelled — closing the dialog never cancels anything, and a queued run is
48
+ * started by the server's own ticker.
49
+ */
50
+ const MAX_FOLLOW_MS = 45 * 60_000;
51
+
52
+ /** How the hook behaves, for the two callers that need to differ from the
53
+ * default: the dialog passes its own open state, and a test its own cadence. */
54
+ export interface HarnessUpdateOptions {
55
+ /** The poll cadence. One second suits a dialog. */
56
+ pollMs?: number;
57
+ /** Is the surface that owns this hook on screen? While it is not, no status is
58
+ * read and no run is followed — a run already in flight is ADOPTED on the
59
+ * next open, which is what "background" means here. */
60
+ enabled?: boolean;
61
+ }
62
+
63
+ export interface HarnessUpdateController {
64
+ /**
65
+ * The last known record per harness — waiting, installing, or the last run
66
+ * that finished.
67
+ *
68
+ * The rows render from this: `jobQueued`/`jobRunning`/`runningStepOf` answer
69
+ * what to draw, and the log dialog renders the record's own steps and output.
70
+ * A settled run is NOT cleared, because the interesting moment to read the log
71
+ * is often after it failed.
72
+ */
73
+ jobs: HarnessUpdateJob[];
74
+ /** Start an update; resolves to a refusal, or null when the run was started
75
+ * (immediately or queued behind the one already installing). */
76
+ start: (id: string) => Promise<string | null>;
77
+ }
78
+
79
+ type Settled = (message: string, ok: boolean) => void;
80
+
81
+ export function useHarnessUpdate(
82
+ onSettled: Settled,
83
+ { pollMs = HARNESS_UPDATE_POLL_MS, enabled = true }: HarnessUpdateOptions = {},
84
+ ): HarnessUpdateController {
85
+ const [jobs, setJobs] = useState<HarnessUpdateJob[]>([]);
86
+ const alive = useRef(true);
87
+ const polling = useRef(false);
88
+ // Which harnesses this card WATCHED install. A run it only saw as history is
89
+ // not one to toast about, and the same harness must not be reported twice.
90
+ const watched = useRef(new Set<string>());
91
+ const reported = useRef(new Set<string>());
92
+ // Runs whose post-install probe answer has already been reflected in the rows.
93
+ const probed = useRef(new Set<string>());
94
+ // The callback is read through a ref so an inline arrow from the caller does
95
+ // not restart the mount effect (and re-adopt the records) on every render.
96
+ const settled = useRef(onSettled);
97
+ settled.current = onSettled;
98
+
99
+ /** Fold one harness's record into the list, keeping the newer one. */
100
+ const merge = useCallback((incoming: HarnessUpdateJob | null) => {
101
+ if (!incoming) return;
102
+ setJobs((current) => {
103
+ const index = current.findIndex((job) => job.harness === incoming.harness);
104
+ if (index < 0) return [...current, incoming];
105
+ const next = current.slice();
106
+ next[index] = incoming;
107
+ return next;
108
+ });
109
+ }, []);
110
+
111
+ /**
112
+ * Report the runs that went from unfinished to finished, and re-read the rows
113
+ * once each run's post-install PROBE answers.
114
+ *
115
+ * The probe is what stops the row quoting the version the update replaced, and
116
+ * it lands AFTER the run settles — so the settle report and the version refresh
117
+ * are two separate moments, not one.
118
+ */
119
+ const observe = useCallback((incoming: HarnessUpdateJob[]) => {
120
+ setJobs(incoming);
121
+ for (const job of incoming) {
122
+ if (jobUnfinished(job)) {
123
+ watched.current.add(job.harness);
124
+ reported.current.delete(job.harness);
125
+ continue;
126
+ }
127
+ if (watched.current.has(job.harness) && !reported.current.has(job.harness)) {
128
+ reported.current.add(job.harness);
129
+ invalidateHarnessVersions();
130
+ settled.current(job.message ?? (job.ok ? 'Update finished' : 'Update failed'), Boolean(job.ok));
131
+ }
132
+ // A run whose probe settled: the numbers the row reads are now the new
133
+ // ones, so the cached rows must be dropped. `startedAt` identifies the run,
134
+ // because the next update replaces the record under the same harness.
135
+ if (job.probe === 'done') {
136
+ const key = `${job.harness}:${job.startedAt}`;
137
+ if (!probed.current.has(key)) {
138
+ probed.current.add(key);
139
+ invalidateHarnessVersions();
140
+ }
141
+ }
142
+ }
143
+ }, []);
144
+
145
+ /**
146
+ * Follow every unfinished record until they all settle.
147
+ *
148
+ * One loop, not one per harness: a queued run and an installing run are two
149
+ * rows of the same poll, and a loop per press would double the reads for no
150
+ * extra answer. `polling` keeps a second caller (the mount effect and a press
151
+ * landing together) from starting a second loop.
152
+ */
153
+ const follow = useCallback(async (): Promise<void> => {
154
+ if (polling.current) return;
155
+ polling.current = true;
156
+ const startedAt = Date.now();
157
+ try {
158
+ while (alive.current) {
159
+ let next: HarnessUpdateJob[] | null = null;
160
+ try {
161
+ const response = await fetch('/api/harness/update/status', { cache: 'no-store' });
162
+ if (!response.ok) throw new Error(String(response.status));
163
+ next = updateJobsFrom(await response.json());
164
+ } catch {
165
+ // A transient failure is not the update failing: the records live on
166
+ // disk and the next poll reads them.
167
+ }
168
+
169
+ if (!alive.current) return;
170
+ if (next) observe(next);
171
+ // Nothing left to watch — a queued run keeps this loop alive (the
172
+ // server starts it when the install ahead finishes), and so does a run
173
+ // whose post-install probe has not answered yet.
174
+ if (!next || !next.some(jobMoving)) return;
175
+ if (Date.now() - startedAt > MAX_FOLLOW_MS) return;
176
+ const { promise, resolve } = Promise.withResolvers<void>();
177
+ setTimeout(resolve, pollMs);
178
+ await promise;
179
+ }
180
+ } finally {
181
+ polling.current = false;
182
+ }
183
+ }, [observe, pollMs]);
184
+
185
+ // Adopt whatever is already going: another tab, a run accepted before a
186
+ // reload, or a queued one. A closed card has nothing to show and nothing to
187
+ // poll for; the workers and the queue keep going either way.
188
+ useEffect(() => {
189
+ if (!enabled) {
190
+ alive.current = false;
191
+ return;
192
+ }
193
+ alive.current = true;
194
+ void follow();
195
+ return () => {
196
+ alive.current = false;
197
+ };
198
+ }, [follow, enabled]);
199
+
200
+ const start = useCallback(async (id: string): Promise<string | null> => {
201
+ let response: Response;
202
+ try {
203
+ response = await fetch('/api/harness/update', {
204
+ method: 'POST',
205
+ headers: { 'Content-Type': 'application/json' },
206
+ body: JSON.stringify({ harness: id }),
207
+ });
208
+ } catch (cause) {
209
+ return cause instanceof Error ? cause.message : 'Update failed';
210
+ }
211
+
212
+ const payload = (await response.json().catch(() => ({}))) as {
213
+ error?: string;
214
+ message?: string;
215
+ success?: boolean;
216
+ started?: boolean;
217
+ queued?: boolean;
218
+ job?: unknown;
219
+ };
220
+
221
+ // The POST's own record is trusted only if it IS a record; a payload that
222
+ // fails the guard still means "started", just without a step to name.
223
+ const posted = isHarnessUpdateJob(payload.job) ? payload.job : null;
224
+
225
+ if (response.status === 202 && payload.started) {
226
+ // `started` covers both halves: installing now, or waiting its turn.
227
+ watched.current.add(id);
228
+ reported.current.delete(id);
229
+ merge(posted);
230
+ void follow();
231
+ return null;
232
+ }
233
+ if (!response.ok) {
234
+ // A refusal carries the record that caused it (`job`), so the reader can
235
+ // open ITS log instead of only being told to wait.
236
+ if (posted) merge(posted);
237
+ return payload.error ?? `Update failed (HTTP ${response.status})`;
238
+ }
239
+ if (payload.success) {
240
+ // Nothing to move: the row is already current, so there is no job to
241
+ // follow. Re-read it anyway — the previous run may have moved it.
242
+ invalidateHarnessVersions();
243
+ settled.current(payload.message ?? 'Update finished', true);
244
+ return null;
245
+ }
246
+ return payload.error ?? 'Update failed';
247
+ }, [follow, merge]);
248
+
249
+ return { jobs, start };
250
+ }
@@ -15,8 +15,9 @@
15
15
  */
16
16
 
17
17
  import { useEffect, useRef } from 'preact/hooks';
18
- import type { WorkspaceFolderData } from '@/shared/types';
18
+ import type { SessionItemData, WorkspaceFolderData } from '@/shared/types';
19
19
  import { triggerInputRequiredSound } from '@/client/hooks/ui/notification-sound';
20
+ import { sendNotification } from '@/client/hooks/ui/notifications';
20
21
 
21
22
  export function useInputRequiredAlert(folders: WorkspaceFolderData[]): void {
22
23
  // Null until the first snapshot: a page load must not replay a cue for
@@ -24,19 +25,25 @@ export function useInputRequiredAlert(folders: WorkspaceFolderData[]): void {
24
25
  const knownRef = useRef<Set<string> | null>(null);
25
26
 
26
27
  useEffect(() => {
27
- const waiting = new Set<string>();
28
+ const waiting = new Map<string, SessionItemData>();
28
29
  for (const folder of folders) {
29
30
  for (const session of folder.sessions ?? []) {
30
- if (session.awaitingInput) waiting.add(String(session.id));
31
+ if (session.awaitingInput) waiting.set(String(session.id), session);
31
32
  }
32
33
  }
33
34
 
34
35
  const known = knownRef.current;
35
- knownRef.current = waiting;
36
+ knownRef.current = new Set(waiting.keys());
36
37
  if (!known) return;
37
- for (const id of waiting) {
38
+ for (const [id, session] of waiting) {
38
39
  if (known.has(id)) continue;
39
40
  triggerInputRequiredSound();
41
+ sendNotification('ask', {
42
+ title: session.title?.trim() || 'Kabmo',
43
+ body: 'Waiting for your answer.',
44
+ tag: `ask:${id}`,
45
+ sessionId: id,
46
+ });
40
47
  return;
41
48
  }
42
49
  }, [folders]);
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The one gate every system notification passes through.
8
+ *
9
+ * Two rules, and both are the feature rather than plumbing:
10
+ *
11
+ * - the event's own setting must be the literal `true` (they ship false);
12
+ * - the page must not be the window the user is looking at. The sidebar badge,
13
+ * the ask card and the inline error row already report these events on
14
+ * screen, so a banner over the app would only repeat what is visible.
15
+ *
16
+ * Text is clipped here because a failure reason can be a whole provider
17
+ * response; an OS notification is a headline, not a log.
18
+ */
19
+
20
+ import { isNotificationEnabled, type NotificationEvent } from '@/shared/lib/notifications/settings';
21
+ import { showOsNotification, shouldShowSystemNotification } from '@/client/lib/notifications/os';
22
+
23
+ const TITLE_LIMIT = 120;
24
+ const BODY_LIMIT = 240;
25
+
26
+ function clip(text: string, limit: number): string {
27
+ const trimmed = text.trim();
28
+ if (trimmed.length <= limit) return trimmed;
29
+ return `${trimmed.slice(0, limit - 1).trimEnd()}…`;
30
+ }
31
+
32
+ /** Send a system notification for `event`, unless the setting or focus says no. */
33
+ export function sendNotification(
34
+ event: NotificationEvent,
35
+ notification: { title: string; body: string; tag?: string; sessionId?: string },
36
+ ): void {
37
+ if (!isNotificationEnabled(event)) return;
38
+ if (!shouldShowSystemNotification()) return;
39
+ void showOsNotification({
40
+ title: clip(notification.title, TITLE_LIMIT) || 'Kabmo',
41
+ body: clip(notification.body, BODY_LIMIT),
42
+ tag: notification.tag,
43
+ sessionId: notification.sessionId,
44
+ });
45
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * App-wide "a run ended" cue.
8
+ *
9
+ * It reads the shared session list rather than the open timeline for the same
10
+ * reason `useInputRequiredAlert` does: the run that mattered is usually NOT the
11
+ * session on screen. The status topic is written by the server on every
12
+ * terminal settle, so this reaches a background session this tab never opened.
13
+ *
14
+ * Only a transition earns a banner — `stream` to `finish`, checked by
15
+ * `runOutcomeNotices` — so the badges already present at page load stay silent.
16
+ * A failed run is the same transition carrying `runFailure`, so finish and
17
+ * error cannot fire for one run.
18
+ */
19
+
20
+ import { useEffect, useRef } from 'preact/hooks';
21
+ import type { WorkspaceFolderData } from '@/shared/types';
22
+ import {
23
+ runOutcomeNotices,
24
+ streamOutcomes,
25
+ type StreamOutcome,
26
+ } from '@/shared/lib/notifications/outcomes';
27
+ import { sendNotification } from '@/client/hooks/ui/notifications';
28
+
29
+ export function useRunOutcomeAlert(folders: WorkspaceFolderData[]): void {
30
+ // Null until the first snapshot: a page load must not announce runs that had
31
+ // already finished before it.
32
+ const knownRef = useRef<Map<string, StreamOutcome> | null>(null);
33
+
34
+ useEffect(() => {
35
+ const previous = knownRef.current;
36
+ knownRef.current = streamOutcomes(folders);
37
+ if (!previous) return;
38
+
39
+ for (const notice of runOutcomeNotices(previous, folders)) {
40
+ sendNotification(notice.kind, {
41
+ title: notice.title,
42
+ body: notice.detail,
43
+ tag: `${notice.kind}:${notice.sessionId}`,
44
+ sessionId: notice.sessionId,
45
+ });
46
+ }
47
+ }, [folders]);
48
+ }
@@ -4,27 +4,40 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Expanded-session rows, shared by the desktop and mobile session sidebars.
7
+ * Expanded-session branches, shared by the desktop and mobile session sidebars.
8
8
  *
9
- * A session row's roster (its `SubagentList`) is shown while that row's id is
10
- * in the expanded set, so both sidebars must read and write ONE set — persisted
11
- * in `app_settings.omp_sidebar_expanded_sessions` — or a row expanded on the
12
- * phone would come back collapsed on the desktop.
9
+ * One row has ONE branch — child sessions and its subagent roster — and one
10
+ * chevron opens it. Both sidebars must read and write ONE set, persisted in
11
+ * `app_settings.omp_sidebar_expanded_sessions`, or a branch expanded on the
12
+ * phone comes back collapsed on the desktop.
13
13
  *
14
14
  * The `?subagent=` deep link auto-expands its session row: a reload on a
15
- * subagent transcript must leave the roster entry that opened it visible.
15
+ * subagent transcript must leave the leaf that opened it visible.
16
+ *
17
+ * A pending CHILD (the row a "New child session" click creates) also opens its
18
+ * parent through `expandSessionBranch`, because the row would otherwise exist
19
+ * inside a collapsed branch and never be seen.
16
20
  */
17
21
 
18
22
  import { useCallback, useEffect, useState } from 'preact/hooks';
19
23
  import { useSearchParams } from '@/client/lib/router/search-params';
20
24
  import { loadExpandedSessionIds, saveExpandedSessionIds } from '@/shared/lib/workspace/sidebar-expanded';
21
25
 
26
+ /** Fired by a pending child's creator so every sidebar opens its parent. */
27
+ const EXPAND_SESSION_EVENT = 'omp:expand-session';
28
+
22
29
  export interface ExpandedSessionsHandle {
23
30
  expandedSessionIds: Set<string>;
24
- /** Collapse an expanded row, or expand a collapsed one. Persists the result. */
31
+ /** Collapse an expanded branch, or expand a collapsed one. Persists it. */
25
32
  toggleSession: (sessionId: string) => void;
26
33
  }
27
34
 
35
+ /** Open one session's branch from outside the sidebar (a pending child). */
36
+ export function expandSessionBranch(sessionId: string): void {
37
+ if (typeof window === 'undefined' || !sessionId) return;
38
+ window.dispatchEvent(new CustomEvent(EXPAND_SESSION_EVENT, { detail: { sessionId } }));
39
+ }
40
+
28
41
  export function useExpandedSessions(): ExpandedSessionsHandle {
29
42
  const [searchParams] = useSearchParams();
30
43
  const urlSubagentId = searchParams.get('subagent');
@@ -48,6 +61,22 @@ export function useExpandedSessions(): ExpandedSessionsHandle {
48
61
  });
49
62
  }, [urlSubagentId, urlSessionId]);
50
63
 
64
+ useEffect(() => {
65
+ const onExpand = (event: Event) => {
66
+ const id = (event as CustomEvent<{ sessionId?: string }>).detail?.sessionId;
67
+ if (!id) return;
68
+ setExpandedSessionIds(prev => {
69
+ if (prev.has(id)) return prev;
70
+ const next = new Set(prev);
71
+ next.add(id);
72
+ saveExpandedSessionIds(next);
73
+ return next;
74
+ });
75
+ };
76
+ window.addEventListener(EXPAND_SESSION_EVENT, onExpand);
77
+ return () => window.removeEventListener(EXPAND_SESSION_EVENT, onExpand);
78
+ }, []);
79
+
51
80
  const toggleSession = useCallback((sessionId: string) => {
52
81
  setExpandedSessionIds((prev) => {
53
82
  const next = new Set(prev);
@@ -5,7 +5,7 @@
5
5
 
6
6
  /**
7
7
  * Live terminal session for the right panel: the socket, its status, and the
8
- * attach/resize/input verbs the xterm view drives.
8
+ * attach/resize/input verbs the terminal view drives.
9
9
  *
10
10
  * The terminal id is per Kabmo session and persisted, which is what makes the
11
11
  * shell survive a page reload: the panel reattaches to the id it already owns
@@ -48,6 +48,12 @@ export interface UseTerminalResult {
48
48
  input: (data: Uint8Array) => void;
49
49
  /** Replace the shell with a fresh one. */
50
50
  restart: () => void;
51
+ /**
52
+ * Re-open the socket for the same terminal id. The server replays its
53
+ * retained scrollback, which is what lets a rebuilt renderer (a theme switch)
54
+ * regain its history without a new shell.
55
+ */
56
+ reattach: () => void;
51
57
  }
52
58
 
53
59
  export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult {
@@ -57,6 +63,8 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
57
63
  const [shell, setShell] = useState('');
58
64
  const [exitCode, setExitCode] = useState<number | null>(null);
59
65
  const [error, setError] = useState<string | null>(null);
66
+ /** Incremented by `reattach`; the socket effect owns the reconnect. */
67
+ const [generation, setGeneration] = useState(0);
60
68
 
61
69
  const socketRef = useRef<TerminalSocket | null>(null);
62
70
  // The grid the view reported, replayed on attach so a reconnect lands on the
@@ -133,7 +141,7 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
133
141
  socket.release();
134
142
  socketRef.current = null;
135
143
  };
136
- }, [ready, terminalId]);
144
+ }, [ready, terminalId, generation]);
137
145
 
138
146
  const restart = useCallback(() => {
139
147
  // Kill the old shell before minting a new id: leaving it to the idle
@@ -182,5 +190,11 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
182
190
  socketRef.current?.input(data);
183
191
  }, []);
184
192
 
185
- return { status, shell, exitCode, error, attach, resize, input, restart };
193
+ const reattach = useCallback(() => {
194
+ // The effect's cleanup releases the old socket and a new one attaches with
195
+ // the remembered size, so the server replays the same terminal id.
196
+ setGeneration((value) => value + 1);
197
+ }, []);
198
+
199
+ return { status, shell, exitCode, error, attach, resize, input, restart, reattach };
186
200
  }
@@ -13,9 +13,10 @@
13
13
  * bytes and is handed straight to `term.write(Uint8Array)`; the client never
14
14
  * decodes UTF-8 itself, which is what keeps a character split across two PTY
15
15
  * reads intact.
16
- * - **`onBinary` carries the same bytes as `onData`.** xterm reports non-UTF-8
17
- * payloads (some mouse reports, paste of raw bytes) on `onBinary`; forwarding
18
- * only `onData` would silently drop them.
16
+ * - **Non-UTF-8 payloads take the byte channel.** ghostty-web has no `onBinary`:
17
+ * it reports every keystroke and mouse report as one `onData` string, so
18
+ * `terminalInputFrame` splits the legacy X10 report back into bytes before the
19
+ * socket sees it. Encoding that payload as text would corrupt it.
19
20
  * - **Reconnect, not re-create.** A dropped socket re-dials the same terminal
20
21
  * id, so the shell and its scrollback survive a network blip or a page reload
21
22
  * instead of a second shell appearing.
@@ -99,7 +100,11 @@ export function connectTerminal(terminalId: string, handlers: TerminalSocketHand
99
100
  handleOutput(new Uint8Array(event.data));
100
101
  return;
101
102
  }
102
- const frame = decodeServerFrame(typeof event.data === 'string' ? event.data : '');
103
+ // Anything that is not a binary frame is a control frame. The server
104
+ // sends PTY bytes as Buffer views, so `event.data` is an ArrayBuffer and
105
+ // this branch only ever sees JSON.
106
+ if (typeof event.data !== 'string') return;
107
+ const frame = decodeServerFrame(event.data);
103
108
  if (frame) applyFrame(frame);
104
109
  };
105
110
 
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `window.__kabmoOpenSession(sessionId)` — what a native shell calls when the
8
+ * user clicks a notification.
9
+ *
10
+ * A plain function, not a bridge command: the shell has nothing to ask and no
11
+ * answer to wait for, the page already owns the routing state, and the shells
12
+ * reach it with `evaluateJavascript` / `evaluateJavaScript` / `ExecuteScriptAsync`
13
+ * / `run_javascript`. Same indirection as `__kabmoBack` and `__kabmoResume`, and
14
+ * for the same reason: the shell may call it during hydration, so it must exist
15
+ * before the first render.
16
+ */
17
+
18
+ import { openSessionInUrl } from '@/client/lib/router/open-session';
19
+
20
+ export const OPEN_SESSION_PROPERTY = '__kabmoOpenSession';
21
+
22
+ declare global {
23
+ interface Window {
24
+ /** Select the session a notification was about. Returns false for a blank id. */
25
+ __kabmoOpenSession?: (sessionId: string) => boolean;
26
+ }
27
+ }
28
+
29
+ /** Install the dispatcher. Idempotent — a hot reload re-runs it. */
30
+ export function installOpenSessionDispatcher(): void {
31
+ if (typeof window === 'undefined') return;
32
+ window[OPEN_SESSION_PROPERTY] = (sessionId) => openSessionInUrl(String(sessionId ?? ''));
33
+ }