@kabmo-labs/kabmo 0.25.0 → 0.27.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 (241) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +448 -444
  3. package/dist/client/static/js/index-32rpkj6b.css +1 -0
  4. package/dist/client/static/js/{index-ga8cbpt4.js → index-e3qh2yps.js} +950 -950
  5. package/package.json +1 -1
  6. package/src/client/components/common/Toast.test.tsx +28 -2
  7. package/src/client/components/common/Toast.tsx +21 -9
  8. package/src/client/components/common/session-actions-menu/index.tsx +38 -12
  9. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  10. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  11. package/src/client/components/common/session-branch/index.tsx +169 -0
  12. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  13. package/src/client/components/common/session-branch/style.ts +29 -0
  14. package/src/client/components/common/session-row/StatusSlot.tsx +15 -3
  15. package/src/client/components/common/session-row/index.tsx +24 -25
  16. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  17. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  18. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
  19. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +66 -69
  20. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  21. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  22. package/src/client/components/layout/session-sidebar/SessionItem.tsx +33 -30
  23. package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
  26. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
  28. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
  29. package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
  30. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +30 -14
  31. package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
  32. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +69 -85
  33. package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
  34. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -1
  35. package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
  36. package/src/client/components/mobile/SessionSidebar.tsx +2 -1
  37. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
  38. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +59 -62
  39. package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
  40. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  41. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
  42. package/src/client/components/settings/Modal.tsx +1 -1
  43. package/src/client/components/settings/Sidebar.tsx +1 -1
  44. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  45. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  46. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  47. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  48. package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
  49. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
  50. package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
  51. package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
  52. package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
  53. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  54. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  55. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +86 -93
  56. package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
  57. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +21 -1
  58. package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
  59. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  60. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  61. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  62. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  63. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  64. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  65. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  66. package/src/client/components/workspace/chat-timeline/fork-preview.test.tsx +141 -0
  67. package/src/client/components/workspace/chat-timeline/index.tsx +16 -22
  68. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +116 -0
  69. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  70. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
  71. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  72. package/src/client/components/workspace/git-panel/index.tsx +2 -2
  73. package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +8 -5
  74. package/src/client/components/workspace/terminal-panel/index.tsx +3 -0
  75. package/src/client/hooks/chat/composer/items.test.ts +19 -0
  76. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  77. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  78. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  79. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  80. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  81. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  82. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  83. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  84. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  85. package/src/client/hooks/chat/omp/session-list.tsx +9 -0
  86. package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
  87. package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
  88. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  89. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  90. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  91. package/src/client/hooks/chat/timeline/fork-preview.test.ts +148 -0
  92. package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
  93. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  94. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  95. package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -0
  96. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  97. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  98. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  99. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  100. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  101. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  102. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  103. package/src/client/hooks/chat/timeline/pending-branch.ts +214 -0
  104. package/src/client/hooks/chat/timeline/pending-dispatch.ts +302 -0
  105. package/src/client/hooks/chat/timeline/send.ts +17 -103
  106. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  107. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  108. package/src/client/hooks/chat/timeline/use-fork-session.ts +40 -31
  109. package/src/client/hooks/chat/waiting/cancel.ts +2 -1
  110. package/src/client/hooks/chat/waiting/dispatch.ts +5 -4
  111. package/src/client/hooks/chat/waiting/held.ts +2 -1
  112. package/src/client/hooks/models/use-harness-update.test.ts +137 -44
  113. package/src/client/hooks/models/use-harness-update.ts +133 -85
  114. package/src/client/hooks/settings/providers/actions.ts +3 -2
  115. package/src/client/hooks/settings/providers/messages.ts +9 -7
  116. package/src/client/hooks/settings/providers/model-actions.ts +2 -1
  117. package/src/client/hooks/ui/editor-error-toast.ts +2 -1
  118. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  119. package/src/client/hooks/ui/notifications.ts +45 -0
  120. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  121. package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
  122. package/src/client/hooks/workspace/batch-archive.ts +4 -2
  123. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  124. package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
  125. package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
  126. package/src/client/hooks/workspace/session-actions.test.ts +2 -1
  127. package/src/client/hooks/workspace/session-actions.ts +2 -1
  128. package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
  129. package/src/client/hooks/workspace/terminal/connection.ts +47 -0
  130. package/src/client/hooks/workspace/terminal/index.ts +35 -4
  131. package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
  132. package/src/client/lib/native/open-session.ts +33 -0
  133. package/src/client/lib/notifications/os.test.ts +125 -0
  134. package/src/client/lib/notifications/os.ts +130 -0
  135. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  136. package/src/client/lib/router/open-session.test.ts +75 -0
  137. package/src/client/lib/router/open-session.ts +34 -0
  138. package/src/client/lib/signals.ts +5 -1
  139. package/src/client/main.tsx +6 -0
  140. package/src/server/lib/db/schema.ts +1 -0
  141. package/src/server/lib/harness/acp/calls.ts +15 -1
  142. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  143. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  144. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  145. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  146. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  147. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  148. package/src/server/lib/harness/acp/client.ts +31 -21
  149. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  150. package/src/server/lib/harness/acp/commands.ts +14 -2
  151. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  152. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  153. package/src/server/lib/harness/acp/frames.ts +71 -158
  154. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  155. package/src/server/lib/harness/acp/mapper.ts +12 -0
  156. package/src/server/lib/harness/acp/permissions.ts +6 -0
  157. package/src/server/lib/harness/acp/protocol.ts +41 -2
  158. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  159. package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
  160. package/src/server/lib/harness/acp/session-handshake.ts +83 -6
  161. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  162. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  163. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  164. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  165. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  166. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  167. package/src/server/lib/harness/acp/session-requests.ts +48 -6
  168. package/src/server/lib/harness/acp/session-turns.ts +8 -3
  169. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  170. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  171. package/src/server/lib/harness/acp/session.test-util.ts +19 -1
  172. package/src/server/lib/harness/acp/session.ts +60 -60
  173. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  174. package/src/server/lib/harness/acp/turn.test.ts +102 -0
  175. package/src/server/lib/harness/acp/turn.ts +81 -6
  176. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  177. package/src/server/lib/harness/acp/v2.ts +220 -0
  178. package/src/server/lib/harness/acp/verbs.ts +46 -6
  179. package/src/server/lib/harness/launch.test.ts +25 -0
  180. package/src/server/lib/harness/launch.ts +21 -9
  181. package/src/server/lib/harness/session.ts +3 -0
  182. package/src/server/lib/harness/update-job-store.test.ts +37 -12
  183. package/src/server/lib/harness/update-job-store.ts +22 -16
  184. package/src/server/lib/harness/update-job.server.ts +66 -175
  185. package/src/server/lib/harness/update-queue.server.ts +292 -0
  186. package/src/server/lib/harness/update-queue.test.ts +265 -0
  187. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  188. package/src/server/lib/harness/update-worker.ts +8 -3
  189. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  190. package/src/server/lib/lifecycle/paths.ts +14 -9
  191. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  192. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  193. package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
  194. package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
  195. package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
  196. package/src/server/lib/sessions/fork.server.test.ts +68 -0
  197. package/src/server/lib/sessions/fork.server.ts +31 -6
  198. package/src/server/lib/sessions/spawn.server.test.ts +41 -0
  199. package/src/server/lib/sessions/spawn.server.ts +27 -2
  200. package/src/server/lib/usage/report.server.ts +57 -0
  201. package/src/server/routes/agent/harness-command.ts +6 -5
  202. package/src/server/routes/chat/stream.ts +7 -2
  203. package/src/server/routes/harness/update-status.ts +18 -12
  204. package/src/server/routes/harness/update.test.ts +53 -16
  205. package/src/server/routes/harness/update.ts +13 -8
  206. package/src/server/routes/sessions/body-readers.ts +43 -0
  207. package/src/server/routes/sessions/fork.ts +19 -4
  208. package/src/server/routes/sessions/routes.test.ts +1 -2
  209. package/src/server/routes/sessions/session.ts +19 -0
  210. package/src/server/routes/sessions/spawn.ts +16 -13
  211. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  212. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  213. package/src/shared/lib/chat/timeline/fork-preview.test.ts +62 -0
  214. package/src/shared/lib/chat/timeline/fork-preview.ts +36 -0
  215. package/src/shared/lib/harness/mode-signal.ts +20 -0
  216. package/src/shared/lib/harness/session-modes.ts +24 -0
  217. package/src/shared/lib/harness/update-job.ts +53 -6
  218. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  219. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  220. package/src/shared/lib/notifications/outcomes.ts +64 -0
  221. package/src/shared/lib/notifications/settings.test.ts +49 -0
  222. package/src/shared/lib/notifications/settings.ts +34 -0
  223. package/src/shared/lib/omp/session/default-title.ts +5 -4
  224. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  225. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  226. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  227. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  228. package/src/shared/lib/settings/defaults.ts +3 -0
  229. package/src/shared/lib/ui/toast-duration.test.ts +25 -1
  230. package/src/shared/lib/ui/toast-duration.ts +22 -4
  231. package/src/shared/lib/workspace/session-state/store.ts +4 -0
  232. package/src/shared/types/harness-update.ts +24 -0
  233. package/src/shared/types/realtime.ts +2 -0
  234. package/src/shared/types/settings/state.ts +10 -0
  235. package/src/shared/types/workspace.ts +4 -0
  236. package/src/test-support/harness-table.test-util.ts +25 -9
  237. package/dist/client/static/js/index-bc9aa4mx.css +0 -1
  238. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
  239. package/src/client/components/common/subagent-list/index.tsx +0 -165
  240. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
  241. package/src/client/hooks/workspace/child-expansion.ts +0 -33
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /** The notification preferences are opt-in, and only the boolean `true` opts in. */
7
+
8
+ import { afterEach, describe, expect, test } from 'bun:test';
9
+
10
+ import { primeKabmoSettings } from '@/shared/lib/settings/client';
11
+ import { DEFAULT_SETTINGS } from '@/shared/lib/settings/defaults';
12
+ import {
13
+ isNotificationEnabled,
14
+ NOTIFICATION_SETTING_KEYS,
15
+ type NotificationEvent,
16
+ } from '@/shared/lib/notifications/settings';
17
+
18
+ const EVENTS: NotificationEvent[] = ['finish', 'ask', 'error'];
19
+
20
+ afterEach(() => {
21
+ primeKabmoSettings({});
22
+ });
23
+
24
+ describe('notification settings', () => {
25
+ test('every event is off on a fresh install', () => {
26
+ primeKabmoSettings({});
27
+ for (const event of EVENTS) expect(isNotificationEnabled(event)).toBe(false);
28
+ });
29
+
30
+ test('the shipped defaults are all false', () => {
31
+ // The defaults object is what the settings modal seeds from, so a `true`
32
+ // here would silently turn notifications on for a new install.
33
+ for (const event of EVENTS) {
34
+ expect(DEFAULT_SETTINGS[NOTIFICATION_SETTING_KEYS[event] as keyof typeof DEFAULT_SETTINGS]).toBe(false);
35
+ }
36
+ });
37
+
38
+ test('each event reads its own key', () => {
39
+ primeKabmoSettings({ notifyOnFinish: true, notifyOnAsk: false, notifyOnError: true });
40
+ expect(isNotificationEnabled('finish')).toBe(true);
41
+ expect(isNotificationEnabled('ask')).toBe(false);
42
+ expect(isNotificationEnabled('error')).toBe(true);
43
+ });
44
+
45
+ test('a truthy non-boolean does not opt in', () => {
46
+ primeKabmoSettings({ notifyOnFinish: 'yes' });
47
+ expect(isNotificationEnabled('finish')).toBe(false);
48
+ });
49
+ });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which system notification each event is allowed to send.
8
+ *
9
+ * All three default to FALSE, and only the literal `true` enables one. That
10
+ * strictness is the feature: an install that predates these keys has no value
11
+ * at all, and a truthy string from a hand-edited settings blob must not opt the
12
+ * user into OS notifications they never chose. It also keeps a fresh install
13
+ * from being prompted for permission by a shell on first launch.
14
+ */
15
+
16
+ import { readKabmoSetting } from '@/shared/lib/settings/client';
17
+
18
+ /** The events a notification setting exists for. */
19
+ export type NotificationEvent = 'finish' | 'ask' | 'error';
20
+
21
+ /** The stored setting key for each event. */
22
+ export const NOTIFICATION_SETTING_KEYS: Readonly<Record<NotificationEvent, string>> = {
23
+ finish: 'notifyOnFinish',
24
+ ask: 'notifyOnAsk',
25
+ error: 'notifyOnError',
26
+ };
27
+
28
+ /** Whether the user asked for a system notification for `event`. */
29
+ export function isNotificationEnabled(
30
+ event: NotificationEvent,
31
+ appSettings?: Record<string, any>,
32
+ ): boolean {
33
+ return readKabmoSetting<boolean>(NOTIFICATION_SETTING_KEYS[event], appSettings) === true;
34
+ }
@@ -24,10 +24,11 @@ function pad2(value: number): string {
24
24
  }
25
25
 
26
26
  /** `New Session - yyyy-mm-ddThh:mm:ss` (local time); plain "New Session" when
27
- * the date is invalid. */
28
- export function formatNewSessionTitle(date: Date = new Date()): string {
29
- if (Number.isNaN(date.getTime())) return 'New Session';
30
- return `New Session - ${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`;
27
+ * the date is invalid. A child passes its own label (`New Child`), so a
28
+ * pending row says what it is before it has a transcript. */
29
+ export function formatNewSessionTitle(date: Date = new Date(), label = 'New Session'): string {
30
+ if (Number.isNaN(date.getTime())) return label;
31
+ return `${label} - ${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`;
31
32
  }
32
33
 
33
34
  /** True for client-side pending session ids (`new-<epochMs>`, pre-spawn). */
@@ -79,13 +79,14 @@ describe('contentProfile', () => {
79
79
  });
80
80
 
81
81
  describe('migrateSessionStreamStateColumns', () => {
82
- test('issues the additive owner, provider, and model columns', async () => {
82
+ test('issues the additive owner, provider, model and failure columns', async () => {
83
83
  const statements: string[] = [];
84
84
  await migrateSessionStreamStateColumns({ exec: async (sql: string) => { statements.push(sql); } } as never);
85
85
  expect(statements).toEqual([
86
86
  'ALTER TABLE session_stream_state ADD COLUMN owner_pid INTEGER;',
87
87
  'ALTER TABLE session_stream_state ADD COLUMN model_provider TEXT;',
88
88
  'ALTER TABLE session_stream_state ADD COLUMN model_id TEXT;',
89
+ 'ALTER TABLE session_stream_state ADD COLUMN failure TEXT;',
89
90
  ]);
90
91
  });
91
92
 
@@ -96,7 +97,7 @@ describe('migrateSessionStreamStateColumns', () => {
96
97
  await migrateSessionStreamStateColumns({
97
98
  exec: async () => { attempts += 1; throw new Error('duplicate column name: owner_pid'); },
98
99
  } as never);
99
- expect(attempts).toBe(3);
100
+ expect(attempts).toBe(4);
100
101
  });
101
102
  });
102
103
 
@@ -32,4 +32,8 @@ export async function migrateSessionStreamStateColumns(db: DbClient): Promise<vo
32
32
  // stream status — instead of re-deriving it from the session JSONL.
33
33
  await addColumn(db, 'ALTER TABLE session_stream_state ADD COLUMN model_provider TEXT;');
34
34
  await addColumn(db, 'ALTER TABLE session_stream_state ADD COLUMN model_id TEXT;');
35
+ // Why a terminal `finish` row ended: the notification's own reason, and the
36
+ // only durable place a background tab can learn that a run failed. NULL is a
37
+ // normal stop, so every existing row keeps its meaning.
38
+ await addColumn(db, 'ALTER TABLE session_stream_state ADD COLUMN failure TEXT;');
35
39
  }
@@ -77,6 +77,25 @@ describe('run model on the stream row', () => {
77
77
  expect((await loadStreamStates()).s1?.model).toEqual({ provider: 'openai', modelId: 'gpt-5' });
78
78
  });
79
79
 
80
+ test('a failed finish keeps its reason, and the next run clears it', async () => {
81
+ await markStreamStatus('s1', 'stream');
82
+ await markStreamStatus('s1', 'finish', undefined, ' 401 invalid api key ');
83
+ expect((await loadStreamStates()).s1).toEqual({
84
+ status: 'finish',
85
+ failure: '401 invalid api key',
86
+ });
87
+
88
+ // A new run must not inherit the previous run's failure: otherwise its
89
+ // normal end would be announced as an error.
90
+ await markStreamStatus('s1', 'stream');
91
+ expect((await loadStreamStates()).s1).toEqual({ status: 'stream' });
92
+ });
93
+
94
+ test('a reason is stored only on a finish row', async () => {
95
+ await markStreamStatus('s1', 'abort', undefined, 'not a finish');
96
+ expect((await loadStreamStates()).s1).toEqual({ status: 'abort' });
97
+ });
98
+
80
99
  test('a row written without a model reports none, and the status view is status-only', async () => {
81
100
  await markStreamStatus('s2', 'abort');
82
101
  expect((await loadStreamStates()).s2).toEqual({ status: 'abort' });
@@ -29,6 +29,11 @@
29
29
  * second instance opening its sidebar judged the first instance's live run by
30
30
  * its own empty registry and cleared a spinner that was still working.
31
31
  *
32
+ * A terminal `finish` may also carry `failure` — the agent's own reason when
33
+ * the run failed. It rides this row for the same reason the model does: a tab
34
+ * that never opened the session has no other durable source, and the failure
35
+ * notification is only useful with the reason. A new `stream` write clears it.
36
+ *
32
37
  * Every write raises the realtime `stream-status` signal, which is what the
33
38
  * socket's `sidebar:status` topic publishes from. All writes are
34
39
  * fire-and-forget: a status write must never fail a prompt.
@@ -49,6 +54,13 @@ export interface SessionRunModel {
49
54
  export interface SessionStreamState {
50
55
  status: SessionStreamStatus;
51
56
  model?: SessionRunModel;
57
+ /**
58
+ * Why a terminal `finish` run failed, when the agent said. NULL/absent is a
59
+ * normal stop. It rides this row because a tab that never opened the session
60
+ * has no other durable source for the reason, and the notification that says
61
+ * "this run failed" is only useful with it.
62
+ */
63
+ failure?: string;
52
64
  }
53
65
 
54
66
  /**
@@ -64,6 +76,7 @@ export async function markStreamStatus(
64
76
  sessionId: string,
65
77
  status: SessionStreamStatus,
66
78
  model?: SessionRunModel | null,
79
+ failure?: string | null,
67
80
  ): Promise<void> {
68
81
  try {
69
82
  const db = await getDb();
@@ -71,16 +84,20 @@ export async function markStreamStatus(
71
84
  // belongs to no process, and leaving a pid on it would invite a later read
72
85
  // to judge the badge by the liveness of a process it never concerned.
73
86
  const ownerPid = status === 'stream' ? process.pid : null;
87
+ // A live or aborted row never carries a reason, and a new `stream` write
88
+ // clears the previous run's: the next terminal settle must not inherit it.
89
+ const reason = status === 'finish' && typeof failure === 'string' ? failure.trim() : '';
74
90
  await db.run(
75
- `INSERT INTO session_stream_state (session_id, status, owner_pid, model_provider, model_id, updated_at)
76
- VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
91
+ `INSERT INTO session_stream_state (session_id, status, owner_pid, model_provider, model_id, failure, updated_at)
92
+ VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
77
93
  ON CONFLICT(session_id) DO UPDATE SET
78
94
  status = excluded.status,
79
95
  owner_pid = excluded.owner_pid,
80
96
  model_provider = COALESCE(excluded.model_provider, session_stream_state.model_provider),
81
97
  model_id = COALESCE(excluded.model_id, session_stream_state.model_id),
98
+ failure = excluded.failure,
82
99
  updated_at = excluded.updated_at`,
83
- [sessionId, status, ownerPid, model?.provider ?? null, model?.modelId ?? null],
100
+ [sessionId, status, ownerPid, model?.provider ?? null, model?.modelId ?? null, reason || null],
84
101
  );
85
102
  // The signal bus has no imports of its own, so this edge cannot close a
86
103
  // cycle: the realtime layer subscribes to it, and this module only raises.
@@ -168,20 +185,23 @@ export async function markStreamSeen(sessionId: string): Promise<boolean> {
168
185
  export async function loadStreamStates(): Promise<Record<string, SessionStreamState>> {
169
186
  try {
170
187
  const db = await getDb();
171
- const rows = (await db.all('SELECT session_id, status, model_provider, model_id FROM session_stream_state')) as {
188
+ const rows = (await db.all('SELECT session_id, status, model_provider, model_id, failure FROM session_stream_state')) as {
172
189
  session_id: string;
173
190
  status: string;
174
191
  model_provider: string | null;
175
192
  model_id: string | null;
193
+ failure: string | null;
176
194
  }[];
177
195
  const map: Record<string, SessionStreamState> = {};
178
196
  for (const row of rows) {
179
197
  if (row.status !== 'stream' && row.status !== 'finish' && row.status !== 'abort') continue;
198
+ const failure = typeof row.failure === 'string' ? row.failure.trim() : '';
180
199
  map[row.session_id] = {
181
200
  status: row.status,
182
201
  ...(row.model_provider && row.model_id
183
202
  ? { model: { provider: row.model_provider, modelId: row.model_id } }
184
203
  : {}),
204
+ ...(failure ? { failure } : {}),
185
205
  };
186
206
  }
187
207
  return map;
@@ -36,6 +36,9 @@ export const DEFAULT_SETTINGS = {
36
36
  autoSessionTitle: true,
37
37
  soundAlerts: true,
38
38
  chatCompletionSound: true,
39
+ notifyOnFinish: false,
40
+ notifyOnAsk: false,
41
+ notifyOnError: false,
39
42
  goalAuditEnabled: true,
40
43
  goalAuditModel: '',
41
44
  goalDefaultBudget: null,
@@ -14,7 +14,7 @@
14
14
  */
15
15
 
16
16
  import { describe, expect, test } from 'bun:test';
17
- import { TOAST_EXIT_MS, toastDurationMs } from '@/shared/lib/ui/toast-duration';
17
+ import { TOAST_EXIT_MS, toastDurationMs, updateOutcomeTone } from '@/shared/lib/ui/toast-duration';
18
18
 
19
19
  describe('toastDurationMs', () => {
20
20
  test('a short confirmation gets the success floor, not a flicker', () => {
@@ -67,8 +67,32 @@ describe('toastDurationMs', () => {
67
67
  );
68
68
  });
69
69
 
70
+ test('a warning outlasts a confirmation and gives way to a failure', () => {
71
+ const message = 'Merging feature stopped on a conflict; resolve it above.';
72
+ expect(toastDurationMs({ tone: 'warning', message })).toBeGreaterThan(
73
+ toastDurationMs({ tone: 'success', message })!,
74
+ );
75
+ expect(toastDurationMs({ tone: 'warning', message })).toBeLessThan(
76
+ toastDurationMs({ tone: 'error', message })!,
77
+ );
78
+ });
79
+
70
80
  test('the exit animation is a real duration, short enough to read as a fade', () => {
71
81
  expect(TOAST_EXIT_MS).toBeGreaterThan(0);
72
82
  expect(TOAST_EXIT_MS).toBeLessThan(400);
73
83
  });
74
84
  });
85
+
86
+ describe('updateOutcomeTone', () => {
87
+ test('a run that finished is a success', () => {
88
+ expect(updateOutcomeTone({ success: true, manual: false })).toBe('success');
89
+ });
90
+
91
+ test('a run the environment cannot perform is a warning: the user still has to act', () => {
92
+ expect(updateOutcomeTone({ success: true, manual: true })).toBe('warning');
93
+ });
94
+
95
+ test('a failed run is an error, even when it also names a manual command', () => {
96
+ expect(updateOutcomeTone({ success: false, manual: true })).toBe('error');
97
+ });
98
+ });
@@ -23,20 +23,25 @@
23
23
  * caller overriding it does so in one place.
24
24
  */
25
25
 
26
- export type ToastTone = 'success' | 'error';
26
+ export type ToastTone = 'success' | 'error' | 'warning';
27
27
 
28
28
  /** How long the fade-out runs. The timer and the class that animates agree here. */
29
29
  export const TOAST_EXIT_MS = 180;
30
30
 
31
- /** Notice-me base, per tone. */
32
- const BASE_MS: Record<ToastTone, number> = { success: 2500, error: 4000 };
31
+ /**
32
+ * Notice-me base, per tone. A warning sits between the two: it did not fail, but
33
+ * it names something the reader has to decide on (a stopped operation, a manual
34
+ * command), so it is noticed like a failure and skimmed like a confirmation.
35
+ */
36
+ const BASE_MS: Record<ToastTone, number> = { success: 2500, warning: 3200, error: 4000 };
33
37
 
34
38
  /** Reading rate per tone: an error is re-read, a confirmation is skimmed. */
35
- const PER_CHAR_MS: Record<ToastTone, number> = { success: 45, error: 55 };
39
+ const PER_CHAR_MS: Record<ToastTone, number> = { success: 45, warning: 50, error: 55 };
36
40
 
37
41
  /** Floor and ceiling per tone: nothing flickers, nothing sits for a minute. */
38
42
  const BOUNDS_MS: Record<ToastTone, { min: number; max: number }> = {
39
43
  success: { min: 3000, max: 8000 },
44
+ warning: { min: 4000, max: 10000 },
40
45
  error: { min: 5000, max: 12000 },
41
46
  };
42
47
 
@@ -68,3 +73,16 @@ export function toastDurationMs({ tone, message, explicit, sticky }: ToastDurati
68
73
  const byLength = BASE_MS[tone] + PER_CHAR_MS[tone] * message.trim().length;
69
74
  return Math.round(Math.min(max, Math.max(min, byLength)));
70
75
  }
76
+
77
+ /**
78
+ * The tone an update run's answer deserves.
79
+ *
80
+ * A failed run is an error. A run the environment could not perform for itself
81
+ * (`manual`) reports the command to run: the update is still waiting on the
82
+ * user, so it is neither a success nor a failure. Every shell that applies an
83
+ * update reads this, so the three of them cannot disagree about the same answer.
84
+ */
85
+ export function updateOutcomeTone(result: { success: boolean; manual: boolean }): ToastTone {
86
+ if (!result.success) return 'error';
87
+ return result.manual ? 'warning' : 'success';
88
+ }
@@ -45,6 +45,10 @@
45
45
  * - userBrowser.viewportMode string
46
46
  * - userBrowser.zoomLevel number
47
47
  * - terminal.id string (server-side PTY id; reattached on reload)
48
+ * - terminal.opened boolean — the session has had its terminal panel on
49
+ * screen, so its shell belongs to the session. A PTY
50
+ * is never started merely because the (hidden) panel
51
+ * mounted; see `hooks/workspace/terminal/connection.ts`
48
52
  * - git.viewMode 'flat' | 'tree'
49
53
  * - git.commitDraft string
50
54
  * - git.stagedExpanded boolean
@@ -37,6 +37,19 @@ export interface HarnessUpdateJob {
37
37
  startedAt: number;
38
38
  /** Null while running: this is the field that says whether to poll. */
39
39
  finishedAt: number | null;
40
+ /**
41
+ * When this run was ACCEPTED while another harness was already installing.
42
+ *
43
+ * Two presses are no longer one press refused: the record carries this stamp
44
+ * and the queue starts the install when the one ahead of it finishes. A record
45
+ * with `pid: null`, `finishedAt: null` and this set is WAITING — not a worker
46
+ * that died — and must never be settled as a failure. The worker clears it
47
+ * when it takes the run over.
48
+ *
49
+ * Optional because a record written before the queue existed has no such
50
+ * field; readers normalize with `jobQueued`.
51
+ */
52
+ queuedAt?: number | null;
40
53
  /** The WORKER process, used to tell a run that is still alive from one that
41
54
  * died without writing its result (a crash, a kill, a reboot). */
42
55
  pid: number | null;
@@ -51,6 +64,17 @@ export interface HarnessUpdateJob {
51
64
  * probe and CLI version caches, repoint the launch line). The worker cannot
52
65
  * do those: they read the database, which the server owns. */
53
66
  applied: boolean;
67
+ /**
68
+ * The post-install PROBE: the freshly installed agent is asked what it is, so
69
+ * the row stops quoting the version that was just replaced.
70
+ *
71
+ * `pending` while that probe runs (it spawns an agent process, so the
72
+ * install's own report is not held up by it), `done` once its answer is in the
73
+ * probe cache, and null when this run has nothing to probe — it failed, or the
74
+ * vendor owns the install. A polling dialog keys its "keep going" on this, and
75
+ * re-reads the version rows when it turns `done`.
76
+ */
77
+ probe?: 'pending' | 'done' | null;
54
78
  /** The launch command a successful install left behind, when it moved it. */
55
79
  repointed: string | null;
56
80
  }
@@ -28,6 +28,8 @@ export interface SidebarStatusEntry {
28
28
  streamStatus?: 'stream' | 'finish' | 'abort';
29
29
  awaitingInput?: boolean;
30
30
  runModel?: SessionRunModel;
31
+ /** Present only on a failed terminal run; the notification's own reason. */
32
+ runFailure?: string;
31
33
  }
32
34
 
33
35
  /** `sidebar:status` — keyed by session id. Absent id means "no volatile fields". */
@@ -81,6 +81,16 @@ export interface SettingsState {
81
81
  autoSessionTitle: boolean;
82
82
  soundAlerts: boolean;
83
83
  chatCompletionSound: boolean;
84
+ /**
85
+ * System notification when a run finishes. Off by default: a fresh install
86
+ * never asks for notification permission until one of these is turned on.
87
+ * Shown only while Kabmo is not the focused window.
88
+ */
89
+ notifyOnFinish: boolean;
90
+ /** System notification when an agent blocks on an ask/approval dialog. */
91
+ notifyOnAsk: boolean;
92
+ /** System notification when a run ends in failure. */
93
+ notifyOnError: boolean;
84
94
  /**
85
95
  * Whether Kabmo's goal loop runs at all: an independent auditor decides
86
96
  * after every finished turn whether the goal continues. Off means a goal
@@ -31,6 +31,10 @@ export interface SessionItemData {
31
31
  * waiting for a user answer. Derived from the running process registry, never
32
32
  * persisted — the process it describes is the same thing that owns the flag. */
33
33
  awaitingInput?: boolean;
34
+ /** Set on a terminal `finish` row whose run ended in failure, with the
35
+ * agent's own reason when it reported one. Rides the status topic beside
36
+ * `streamStatus` so a background tab can announce the failure. */
37
+ runFailure?: string;
34
38
  /** Model serving the session's current run — persisted beside `streamStatus`
35
39
  * (session_stream_state) so the generating indicator names the real
36
40
  * provider/model in every tab and Kabmo instances. Absent for a session
@@ -15,6 +15,7 @@ import { Window } from 'happy-dom';
15
15
  import { h, render } from 'preact';
16
16
  import { act } from 'preact/test-utils';
17
17
  import { HarnessTable } from '@/client/components/layout/session-sidebar/about-modal/HarnessTable';
18
+ import type { HarnessUpdateJob } from '@/shared/types/harness-update';
18
19
  import type { HarnessVersionRow } from '@/shared/types/harness-version';
19
20
  import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
20
21
  import type { HarnessSummary } from '@/shared/types/harness';
@@ -83,15 +84,13 @@ export function mountHarnessTable(
83
84
  onOpen?: (id: string) => void,
84
85
  onUpdate?: (id: string) => Promise<string | null>,
85
86
  /**
86
- * The in-flight update state and its record. Kept apart from the positional
87
- * arguments because only the log cases need it, and the earlier callers are
87
+ * The update records and the log opener. Kept apart from the positional
88
+ * arguments because only the log cases need them, and the earlier callers are
88
89
  * about the row's layout.
89
90
  */
90
91
  state?: {
91
- updating?: string | null;
92
- progress?: string | null;
93
- log?: { harness: string; message: string | null } | null;
94
- onOpenLog?: () => void;
92
+ jobs?: HarnessUpdateJob[];
93
+ onOpenLog?: (harness: string) => void;
95
94
  },
96
95
  ): HTMLElement {
97
96
  act(() =>
@@ -101,9 +100,7 @@ export function mountHarnessTable(
101
100
  versions,
102
101
  onOpenHarness: onOpen ?? (() => {}),
103
102
  onUpdate: onUpdate ?? (async () => null),
104
- updating: state?.updating ?? null,
105
- progress: state?.progress ?? null,
106
- log: state?.log ?? null,
103
+ jobs: state?.jobs ?? [],
107
104
  onOpenLog: state?.onOpenLog,
108
105
  }),
109
106
  container,
@@ -112,6 +109,25 @@ export function mountHarnessTable(
112
109
  return container;
113
110
  }
114
111
 
112
+ /** An update record: installing by default, queued or settled by override. */
113
+ export function updateJob(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
114
+ return {
115
+ harness: 'claude',
116
+ label: 'claude',
117
+ startedAt: Date.now(),
118
+ finishedAt: null,
119
+ queuedAt: null,
120
+ pid: 4242,
121
+ steps: [{ part: 'adapter', command: 'npm install -g x', argv: ['npm', 'install', '-g', 'x'], state: 'running', code: null }],
122
+ output: '',
123
+ ok: null,
124
+ message: null,
125
+ applied: false,
126
+ repointed: null,
127
+ ...overrides,
128
+ };
129
+ }
130
+
115
131
  /** The rows, which are the direct children of the grid that draws them. */
116
132
  export function harnessRows(el: HTMLElement): HTMLElement[] {
117
133
  // `data-harness-rows`, not the grid's scrollbar class: the list stopped being