@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
@@ -206,8 +206,7 @@ describe('getSessionModes', () => {
206
206
  claimHarness(wrapper as never, 'claude');
207
207
  try {
208
208
  const res = (await getSessionModes(loaderArgs(acpId)) as unknown as Response);
209
- expect(res.status).toBe(200);
210
- expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false } });
209
+ expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false, mode: { currentValue: 'plan' } } });
211
210
  } finally {
212
211
  globalThis.__ompSessions.delete(acpId);
213
212
  }
@@ -16,6 +16,9 @@ import { getLiveSession, harnessOfSession } from '@/server/lib/omp/rpc/session-r
16
16
  import { knownHarness, loadHarnessSession } from '@/server/lib/harness/session-store.server';
17
17
  import { HARNESS_IDS } from '@/shared/lib/harness/catalog';
18
18
  import { loadAcpGoalState } from '@/server/lib/harness/acp/acp-goal-state.server';
19
+ import { selectValues } from '@/server/lib/harness/launch';
20
+ import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
21
+ import type { SessionModeState } from '@/shared/lib/harness/session-modes';
19
22
  import { asHarnessSession } from '@/server/lib/harness/registry';
20
23
  import { applyHarnessMode } from '@/server/routes/agent/harness-command';
21
24
  import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
@@ -77,12 +80,28 @@ export async function getSessionModes({ params }: LoaderFunctionArgs) {
77
80
  if (applied.ok) plan = (applied.data as { enabled?: unknown } | null)?.enabled === true;
78
81
  }
79
82
  const active = state.record?.status === 'active';
83
+ // The agent's own mode ladder, so the composer can offer all of it. `omp-acp`
84
+ // is excluded: its selector is just default/plan, which the dedicated Plan
85
+ // toggle (with the goal exclusion) already expresses.
86
+ let mode: SessionModeState | null = null;
87
+ if (liveSession?.isAlive() && acpHarness !== 'omp-acp') {
88
+ const snapshot = await liveSession.send({ type: 'get_state' }).catch(() => null) as
89
+ | { configOptions?: AcpConfigOption[] }
90
+ | null;
91
+ const selector = Array.isArray(snapshot?.configOptions)
92
+ ? snapshot.configOptions.find((option) => option.category === 'mode')
93
+ : undefined;
94
+ if (selector && typeof selector.currentValue === 'string') {
95
+ mode = { currentValue: selector.currentValue, values: selectValues(selector) };
96
+ }
97
+ }
80
98
  acpModes = {
81
99
  plan,
82
100
  goal: active,
83
101
  goalLive: active,
84
102
  goalRecord: state.record,
85
103
  goalContinuation: state.continuation,
104
+ ...(mode ? { mode } : {}),
86
105
  };
87
106
  }
88
107
 
@@ -19,10 +19,12 @@ import { json } from '@/server/lib/remix-compat';
19
19
  import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
20
20
  import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
21
21
  import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
22
+ import { readImages, readModel, readString } from '@/server/routes/sessions/body-readers';
23
+ import { isApprovalMode } from '@/shared/lib/omp/config/access-mode';
24
+ import { isMockMode } from '@/server/mock.server';
22
25
  import {
23
26
  SessionSpawnError,
24
27
  spawnChildSession,
25
- type SpawnChildSessionInput,
26
28
  } from '@/server/lib/sessions/spawn.server';
27
29
  import { bearerToken, verifyAgentToken } from '@/server/lib/sessions/agent-token.server';
28
30
 
@@ -36,25 +38,15 @@ interface SpawnBody {
36
38
  harness?: unknown;
37
39
  cwd?: unknown;
38
40
  prompt?: unknown;
41
+ images?: unknown;
39
42
  model?: unknown;
40
43
  thinkingLevel?: unknown;
44
+ accessMode?: unknown;
41
45
  lifecycleOwnerSessionId?: unknown;
42
46
  visibility?: unknown;
43
47
  parentNotifications?: unknown;
44
48
  }
45
49
 
46
- function readModel(value: unknown): SpawnChildSessionInput['model'] {
47
- if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
48
- const record = value as Record<string, unknown>;
49
- return typeof record.provider === 'string' && typeof record.modelId === 'string'
50
- ? { provider: record.provider, modelId: record.modelId }
51
- : null;
52
- }
53
-
54
- function readString(value: unknown): string | null {
55
- return typeof value === 'string' && value.trim() ? value.trim() : null;
56
- }
57
-
58
50
  function statusFor(code: SessionSpawnError['code']): number {
59
51
  switch (code) {
60
52
  case 'parent_not_found':
@@ -74,6 +66,12 @@ export async function spawnSession({ request }: ActionFunctionArgs) {
74
66
  const parsed = await parseJsonBody<SpawnBody>(request);
75
67
  if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
76
68
 
69
+ // MOCK mode has no agent process to start. The client takes its simulated
70
+ // path on this CODE, exactly as it does for `POST /api/agent/new`.
71
+ if (isMockMode()) {
72
+ return json({ error: 'Mock mode runs no agent process', code: 'mock_mode' }, { status: 400 });
73
+ }
74
+
77
75
  const prompt = readString(parsed.body.prompt);
78
76
  if (!prompt) return json({ error: 'prompt is required' }, { status: 400 });
79
77
 
@@ -107,6 +105,9 @@ export async function spawnSession({ request }: ActionFunctionArgs) {
107
105
  ) {
108
106
  return json({ error: 'parentNotifications must be auto, stuck or off' }, { status: 400 });
109
107
  }
108
+ if (parsed.body.accessMode !== undefined && !isApprovalMode(parsed.body.accessMode)) {
109
+ return json({ error: 'accessMode is not a valid approval mode' }, { status: 400 });
110
+ }
110
111
 
111
112
  try {
112
113
  const result = await spawnChildSession({
@@ -114,8 +115,10 @@ export async function spawnSession({ request }: ActionFunctionArgs) {
114
115
  harness: readString(parsed.body.harness),
115
116
  cwd: readString(parsed.body.cwd),
116
117
  prompt,
118
+ images: readImages(parsed.body.images),
117
119
  model: readModel(parsed.body.model),
118
120
  thinkingLevel: readString(parsed.body.thinkingLevel),
121
+ accessMode: isApprovalMode(parsed.body.accessMode) ? parsed.body.accessMode : null,
119
122
  lifecycleOwnerSessionId: readString(parsed.body.lifecycleOwnerSessionId),
120
123
  ...(visibility ? { visibility: visibility as Visibility } : {}),
121
124
  ...(notifications ? { parentNotifications: notifications as ParentNotifications } : {}),
@@ -18,6 +18,7 @@ import { extractTextFromContent, toChatMessage } from '@/shared/lib/omp/session/
18
18
  import { normalizeNoticeText } from '@/shared/lib/chat/notice-text';
19
19
  import { parseModeMarker } from '@/shared/lib/omp/mode/markers';
20
20
  import { emitKabmoModeSignal } from '@/shared/lib/omp/mode/client-signal';
21
+ import { emitSessionModesChanged } from '@/shared/lib/harness/mode-signal';
21
22
  import { KABMO_GOAL_EVALUATING_MARKER } from '@/shared/lib/omp/mode/types';
22
23
  import { materializeTerminalMessages } from '@/shared/lib/chat/omp/terminal-messages';
23
24
  import { invalidateComposerCache } from '@/shared/lib/chat/composer/client';
@@ -45,6 +46,9 @@ export function foldAgentEvent(data: OmpAgentEvent, deps: OmpAgentFoldDeps): voi
45
46
  switch (data.type) {
46
47
  case 'agent_start':
47
48
  deps.setState((prev) => ({ ...prev, isGenerating: true, error: null }));
49
+ // A cold chat has no live agent when the composer first reads `/modes`;
50
+ // this is the first frame after its spawn, so re-read the mode ladder.
51
+ emitSessionModesChanged(deps.sessionId);
48
52
  deps.toolResultsRef.current?.clear();
49
53
  deps.lastToolMessageRef.current = null;
50
54
  // A fresh run restarts level tracking; the first turn relies on the
@@ -276,6 +280,13 @@ export function foldAgentEvent(data: OmpAgentEvent, deps: OmpAgentFoldDeps): voi
276
280
  callbacks?.onModelChanged?.();
277
281
  break;
278
282
 
283
+ // An ACP agent changed a config selector itself. `mode` is one of them and
284
+ // the composer's mode dropdown reads the live session, so re-read it.
285
+ case 'mode_changed':
286
+ case 'config_changed':
287
+ emitSessionModesChanged(deps.sessionId);
288
+ break;
289
+
279
290
  // The live `thinking_level_changed` frame carries the new session level
280
291
  // (e.g. { thinkingLevel: "high", configured, resolved }); null → "off".
281
292
  // Record it so subsequent assistant turns are stamped with the level that
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * A cold chat has no live agent when the composer reads `/modes`; the first
6
+ * frame after its spawn is `agent_start`, so that frame must ask the composer
7
+ * to re-read the mode ladder.
8
+ */
9
+
10
+ import { describe, expect, test } from 'bun:test';
11
+ import { foldAgentEvent, type OmpAgentFoldDeps } from '@/shared/lib/chat/omp/agent-events';
12
+ import { subscribeClientSignal } from '@/client/lib/signals';
13
+
14
+ function foldDeps(): OmpAgentFoldDeps {
15
+ const noop = () => {};
16
+ const ref = <T,>(value: T) => ({ current: value });
17
+ return {
18
+ setState: noop,
19
+ sessionId: 'acp-cold-chat',
20
+ callbacksRef: { current: {} },
21
+ toolResultsRef: ref(new Map()),
22
+ lastToolMessageRef: ref(null),
23
+ activityRef: ref(''),
24
+ providerRetryVerbRef: ref(null),
25
+ currentThinkingLevelRef: ref(undefined),
26
+ fileMutatingCallsRef: ref(new Set()),
27
+ } as unknown as OmpAgentFoldDeps;
28
+ }
29
+
30
+ describe('session-modes-changed signal', () => {
31
+ test('agent_start re-reads the live mode ladder', () => {
32
+ const seen: string[] = [];
33
+ const off = subscribeClientSignal('session-modes-changed', (payload) => seen.push(payload.sessionId));
34
+ try {
35
+ foldAgentEvent({ type: 'agent_start' } as never, foldDeps());
36
+ } finally {
37
+ off();
38
+ }
39
+ expect(seen).toEqual(['acp-cold-chat']);
40
+ });
41
+ });
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The slice a fork preview shows.
8
+ *
9
+ * It mirrors the server cut (`cutIndexFor` in `fork.server.ts`), because a
10
+ * preview that ends on a different row than the branch file does is a promise
11
+ * the first send breaks.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+ import { forkPreviewMessages } from '@/shared/lib/chat/timeline/fork-preview';
16
+ import type { ChatMessageData } from '@/shared/types';
17
+
18
+ const row = (id: string, role: ChatMessageData['role']): ChatMessageData => ({ id, role, content: id });
19
+
20
+ // u1 a1 u2 a2 u3 a3 — a turn is a user row plus everything after it.
21
+ const transcript: ChatMessageData[] = [
22
+ row('u1', 'user'),
23
+ row('a1', 'ai'),
24
+ row('u2', 'user'),
25
+ row('a2', 'ai'),
26
+ row('u3', 'user'),
27
+ row('a3', 'ai'),
28
+ ];
29
+
30
+ describe('forkPreviewMessages', () => {
31
+ test('no anchor is the tip: the whole transcript', () => {
32
+ expect(forkPreviewMessages(transcript, null).map((m) => m.id)).toEqual([
33
+ 'u1', 'a1', 'u2', 'a2', 'u3', 'a3',
34
+ ]);
35
+ });
36
+
37
+ test('an anchor the transcript does not carry falls back to the tip', () => {
38
+ // A reload can outlive a message the source no longer has; the fork then
39
+ // branches at the tip, so the preview must not claim otherwise.
40
+ expect(forkPreviewMessages(transcript, 'gone').map((m) => m.id)).toEqual([
41
+ 'u1', 'a1', 'u2', 'a2', 'u3', 'a3',
42
+ ]);
43
+ });
44
+
45
+ test('a user anchor branches BEFORE that turn', () => {
46
+ expect(forkPreviewMessages(transcript, 'u2').map((m) => m.id)).toEqual(['u1', 'a1']);
47
+ });
48
+
49
+ test('an assistant anchor keeps the turn that contains it', () => {
50
+ expect(forkPreviewMessages(transcript, 'a2').map((m) => m.id)).toEqual([
51
+ 'u1', 'a1', 'u2', 'a2',
52
+ ]);
53
+ });
54
+
55
+ test('the first user turn forks to an empty transcript', () => {
56
+ expect(forkPreviewMessages(transcript, 'u1')).toEqual([]);
57
+ });
58
+
59
+ test('an anchor on the last turn keeps the whole transcript', () => {
60
+ expect(forkPreviewMessages(transcript, 'a3')).toHaveLength(6);
61
+ });
62
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The source transcript a fork will carry, for the pending composer's preview.
8
+ *
9
+ * A fork is composed as an EMPTY chat today, so the operator picks the first
10
+ * turn without seeing the history that turn continues. This slices the source's
11
+ * rows the way the server slices its JSONL (`cutIndexFor` in
12
+ * `fork.server.ts`), so what the preview shows is exactly what the branch file
13
+ * will hold:
14
+ *
15
+ * - an anchor on a USER turn branches BEFORE it — that message is the one
16
+ * being replaced, so it is not part of the fork;
17
+ * - an anchor anywhere else (an assistant reply, a tool row) branches AFTER
18
+ * the turn that contains it — the reply the user pointed at is kept;
19
+ * - no anchor, or an id the transcript does not carry, is the tip: everything.
20
+ */
21
+
22
+ import type { ChatMessageData } from '@/shared/types';
23
+
24
+ export function forkPreviewMessages(
25
+ messages: ChatMessageData[],
26
+ anchorEntryId: string | null | undefined,
27
+ ): ChatMessageData[] {
28
+ if (!anchorEntryId) return messages;
29
+ const anchorIndex = messages.findIndex((message) => message.id === anchorEntryId);
30
+ if (anchorIndex === -1) return messages;
31
+ if (messages[anchorIndex]?.role === 'user') return messages.slice(0, anchorIndex);
32
+ const nextTurn = messages.findIndex(
33
+ (message, index) => index > anchorIndex && message.role === 'user',
34
+ );
35
+ return messages.slice(0, nextTurn === -1 ? messages.length : nextTurn);
36
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Publishing "the agent changed its session mode/config".
8
+ *
9
+ * The fold sees `mode_changed` / `config_changed` frames; the composer's mode
10
+ * dropdown owns the `/modes` read and cannot see frames. This one-hop signal
11
+ * keeps the dropdown from polling: the frame is the event, and the consumer
12
+ * re-reads the authoritative value once.
13
+ */
14
+
15
+ import { publishClientSignal } from '@/client/lib/signals';
16
+
17
+ export function emitSessionModesChanged(sessionId: string | undefined): void {
18
+ if (!sessionId) return;
19
+ publishClientSignal('session-modes-changed', { sessionId });
20
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The ACP session-mode selector, as the composer reads it.
8
+ *
9
+ * ACP exposes modes as a `mode`-category config option; this is the normalized
10
+ * shape the `/modes` route answers and the dropdown renders. It is shared so
11
+ * the server route, the client hook and the component agree on one spelling.
12
+ */
13
+
14
+ export interface SessionModeChoice {
15
+ value: string;
16
+ name: string;
17
+ }
18
+
19
+ export interface SessionModeState {
20
+ /** The agent's current mode id. */
21
+ currentValue: string;
22
+ /** Every advertised value, in the agent's order. */
23
+ values: SessionModeChoice[];
24
+ }
@@ -4,10 +4,12 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Narrowing a harness-update record that came from somewhere else.
7
+ * Reading a harness-update record that came from somewhere else, and the three
8
+ * questions every reader asks of one: is it waiting, is it running, and which
9
+ * step is it on.
8
10
  *
9
11
  * Two readers get one over the wire or off disk — the About card, which parses
10
- * the status response, and the server, which parses the file a detached worker
12
+ * the status response, and the server, which parses the files a detached worker
11
13
  * wrote — and neither may assume the shape: a half-written file or an older
12
14
  * build's payload would otherwise reach `job.steps.find(...)` and throw inside a
13
15
  * render. The guard IS the check, so a payload that fails it reads as "no run".
@@ -25,9 +27,54 @@ export function isHarnessUpdateJob(value: unknown): value is HarnessUpdateJob {
25
27
  && (job.finishedAt === null || typeof job.finishedAt === 'number');
26
28
  }
27
29
 
28
- /** The `job` field of a status payload, or null when it is not a record. */
30
+ /** The `job` field of a refusal payload, or null when it is not a record. */
29
31
  export function updateJobFrom(payload: unknown): HarnessUpdateJob | null {
30
- if (!payload || typeof payload !== 'object') return null;
31
- const found: unknown = (payload as { job?: unknown }).job;
32
- return isHarnessUpdateJob(found) ? found : null;
32
+ if (!payload || typeof payload !== 'object' || !('job' in payload)) return null;
33
+ return isHarnessUpdateJob(payload.job) ? payload.job : null;
34
+ }
35
+
36
+ /** The `jobs` field of a status payload, dropping anything that is not a record. */
37
+ export function updateJobsFrom(payload: unknown): HarnessUpdateJob[] {
38
+ if (!payload || typeof payload !== 'object' || !('jobs' in payload)) return [];
39
+ const found = payload.jobs;
40
+ return Array.isArray(found) ? found.filter(isHarnessUpdateJob) : [];
41
+ }
42
+
43
+ /**
44
+ * Is this run WAITING for another install to finish?
45
+ *
46
+ * The queue keeps the record on disk before the worker exists, so the ordinary
47
+ * "no pid and not finished" test would call it a run that died without writing a
48
+ * result. `queuedAt` is what separates the two.
49
+ */
50
+ export function jobQueued(job: HarnessUpdateJob | null): boolean {
51
+ return job !== null && job.finishedAt === null && job.pid === null && (job.queuedAt ?? null) !== null;
52
+ }
53
+
54
+ /** Is a worker installing right now? A queued run is not one. */
55
+ export function jobRunning(job: HarnessUpdateJob | null): boolean {
56
+ return job !== null && job.finishedAt === null && !jobQueued(job);
57
+ }
58
+
59
+ /** Has this record got a result yet (running, queued, or settled)? */
60
+ export function jobUnfinished(job: HarnessUpdateJob | null): boolean {
61
+ return job !== null && job.finishedAt === null;
62
+ }
63
+
64
+ /**
65
+ * Is anything still moving for this record?
66
+ *
67
+ * A settled run is not always finished with the reader: the server probes the
68
+ * freshly installed agent afterwards, and until that answer lands the row quotes
69
+ * the version the update just replaced. Both the queue's ticker and the dialog's
70
+ * poll wait for `probe` to leave `pending`.
71
+ */
72
+ export function jobMoving(job: HarnessUpdateJob | null): boolean {
73
+ return jobUnfinished(job) || (job !== null && job.probe === 'pending');
74
+ }
75
+
76
+ /** The step the worker is on (`adapter`, `Claude Code`, …), when it says. */
77
+ export function runningStepOf(job: HarnessUpdateJob | null): string | null {
78
+ const steps = job && Array.isArray(job.steps) ? job.steps : [];
79
+ return steps.find((step) => step.state === 'running')?.part ?? null;
33
80
  }
@@ -33,40 +33,40 @@ import type { PaperBucket } from '@/shared/lib/icons/icon-tone';
33
33
  export const ICON_HUES: Readonly<Record<string, number>> = {
34
34
  Activity: 240, AlignJustify: 100, AlignLeft: 150, Archive: 50, ArchiveRestore: 90, ArrowDown: 100,
35
35
  ArrowDownToLine: 330, ArrowLeft: 350, ArrowRight: 80, ArrowUp: 150, ArrowUpDown: 310, ArrowUpRight: 70,
36
- BarChart3: 150, Blocks: 110, Bot: 220, Box: 260, Boxes: 220, Brain: 350,
37
- BrainCircuit: 300, Briefcase: 310, Camera: 60, CaseSensitive: 110, ChevronDown: 120, ChevronLeft: 250,
38
- ChevronRight: 300, ChevronUp: 250, ChevronsUpDown: 80, Circle: 50, CircleDashed: 120, CircleDot: 240,
39
- ClipboardCopy: 280, ClipboardList: 290, ClipboardPaste: 200, Cloud: 340, CloudDownload: 300, Code: 200,
40
- Code2: 260, Coins: 210, Columns: 280, Columns2: 20, Command: 100, Component: 200,
41
- Copy: 320, CopyPlus: 40, CornerDownLeft: 10, Cpu: 250, Database: 280, Dice5: 50,
42
- Diff: 300, DollarSign: 220, Download: 210, DownloadCloud: 180, Edit2: 210, Ellipsis: 100,
43
- ExternalLink: 60, Eye: 20, EyeOff: 350, File: 310, FileCode: 260, FileCog: 340,
44
- FileEdit: 270, FileImage: 40, FilePlus: 350, FilePlus2: 350, FileSearch: 310, FileText: 80,
45
- Files: 320, Flag: 350, FlaskConical: 170, Folder: 290, FolderGit: 190, FolderGit2: 190,
46
- FolderInput: 310, FolderOpen: 330, FolderPlus: 250, FolderSearch: 10, FolderTree: 10, Gamepad2: 300,
47
- GitBranch: 30, GitCommitVertical: 240, GitCompare: 340, GitFork: 30, GitMerge: 90, GitPullRequest: 10,
48
- Globe: 340, GraduationCap: 190, GripVertical: 350, Hammer: 310, Hand: 200, HardDrive: 0,
49
- Hash: 330, Heading: 250, Heart: 270, History: 110, Home: 20, Image: 140,
50
- Key: 240, KeyRound: 240, Keyboard: 120, Laptop: 170, Layers: 30, LayoutTemplate: 170,
51
- Leaf: 50, Library: 160, Lightbulb: 0, List: 170, ListChecks: 320, ListFilter: 230,
52
- ListOrdered: 220, ListTodo: 210, ListTree: 330, Loader2: 40, Lock: 220, LockKeyhole: 270,
53
- LockOpen: 180, LogIn: 140, LogOut: 190, Maximize: 310, Maximize2: 270, Menu: 100,
54
- MessageSquare: 150, MessageSquareOff: 40, MessageSquarePlus: 350, MessagesSquare: 220, Mic: 160, MicOff: 170,
55
- Minimize: 290, Minimize2: 130, Minus: 110, Monitor: 250, Moon: 80, MoreHorizontal: 160,
56
- MousePointerClick: 70, MoveVertical: 300, Music: 280, Package: 270, Paintbrush: 250, Palette: 320,
57
- PanelLeft: 280, PanelLeftClose: 160, PanelRight: 330, PanelRightClose: 350, Paperclip: 310, Pause: 10,
58
- Pencil: 0, PencilLine: 260, Pin: 0, PinOff: 50, Pipette: 120, Play: 310,
59
- Plug: 50, Plus: 210, Power: 340, Puzzle: 50, Quote: 110, Radio: 320,
60
- Ratio: 160, RefreshCw: 180, Regex: 280, Replace: 190, ReplaceAll: 140, Rocket: 210,
61
- RotateCcw: 330, RotateCw: 0, Rows: 160, Rows3: 250, Save: 40, SaveAll: 190,
62
- Scissors: 260, Search: 250, Send: 110, Server: 300, ServerCog: 50, Settings: 240,
63
- Settings2: 20, Shield: 160, Shrink: 160, Sliders: 290, SlidersHorizontal: 50, Smartphone: 20,
64
- Space: 290, Sparkles: 180, Square: 60, SquareFunction: 220, SquarePen: 10, Star: 170,
65
- StickyNote: 100, Store: 340, Sun: 90, Tablet: 290, Tag: 310, Target: 200,
66
- Terminal: 210, TextSelect: 220, Ticket: 170, Type: 170, Undo2: 310, Upload: 0,
67
- UploadCloud: 50, User: 140, Variable: 330, Volume2: 270, VolumeX: 50, Wand2: 270,
68
- WandSparkles: 40, Waypoints: 30, WholeWord: 240, WrapText: 340, Wrench: 0, X: 230,
69
- Zap: 120, ZoomIn: 250, ZoomOut: 340,
36
+ BarChart3: 150, BellRing: 260, Blocks: 110, Bot: 220, Box: 260, Boxes: 220,
37
+ Brain: 350, BrainCircuit: 300, Briefcase: 310, Camera: 60, CaseSensitive: 110, ChevronDown: 120,
38
+ ChevronLeft: 250, ChevronRight: 300, ChevronUp: 250, ChevronsUpDown: 80, Circle: 50, CircleCheck: 350,
39
+ CircleDashed: 120, CircleDot: 240, ClipboardCopy: 280, ClipboardList: 290, ClipboardPaste: 200, Cloud: 340,
40
+ CloudDownload: 300, Code: 200, Code2: 260, Coins: 210, Columns: 280, Columns2: 20,
41
+ Command: 100, Component: 200, Copy: 320, CopyPlus: 40, CornerDownLeft: 10, Cpu: 250,
42
+ Database: 280, Dice5: 50, Diff: 300, DollarSign: 220, Download: 210, DownloadCloud: 180,
43
+ Edit2: 210, Ellipsis: 100, ExternalLink: 60, Eye: 20, EyeOff: 350, File: 310,
44
+ FileCode: 260, FileCog: 340, FileEdit: 270, FileImage: 40, FilePlus: 350, FilePlus2: 350,
45
+ FileSearch: 310, FileText: 80, Files: 320, Flag: 350, FlaskConical: 170, Folder: 290,
46
+ FolderGit: 190, FolderGit2: 190, FolderInput: 310, FolderOpen: 330, FolderPlus: 250, FolderSearch: 10,
47
+ FolderTree: 10, Gamepad2: 300, GitBranch: 30, GitCommitVertical: 240, GitCompare: 340, GitFork: 30,
48
+ GitMerge: 90, GitPullRequest: 10, Globe: 340, GraduationCap: 190, GripVertical: 350, Hammer: 310,
49
+ Hand: 200, HardDrive: 0, Hash: 330, Heading: 250, Heart: 270, History: 110,
50
+ Home: 20, Image: 140, Key: 240, KeyRound: 240, Keyboard: 120, Laptop: 170,
51
+ Layers: 30, LayoutTemplate: 170, Leaf: 50, Library: 160, Lightbulb: 0, List: 170,
52
+ ListChecks: 320, ListFilter: 230, ListOrdered: 220, ListTodo: 210, ListTree: 330, Loader2: 40,
53
+ Lock: 220, LockKeyhole: 270, LockOpen: 180, LogIn: 140, LogOut: 190, Maximize: 310,
54
+ Maximize2: 270, Menu: 100, MessageSquare: 150, MessageSquareOff: 40, MessageSquarePlus: 350, MessagesSquare: 220,
55
+ Mic: 160, MicOff: 170, Minimize: 290, Minimize2: 130, Minus: 110, Monitor: 250,
56
+ Moon: 80, MoreHorizontal: 160, MousePointerClick: 70, MoveVertical: 300, Music: 280, Package: 270,
57
+ Paintbrush: 250, Palette: 320, PanelLeft: 280, PanelLeftClose: 160, PanelRight: 330, PanelRightClose: 350,
58
+ Paperclip: 310, Pause: 10, Pencil: 0, PencilLine: 260, Pin: 0, PinOff: 50,
59
+ Pipette: 120, Play: 310, Plug: 50, Plus: 210, Power: 340, Puzzle: 50,
60
+ Quote: 110, Radio: 320, Ratio: 160, RefreshCw: 180, Regex: 280, Replace: 190,
61
+ ReplaceAll: 140, Rocket: 210, RotateCcw: 330, RotateCw: 0, Rows: 160, Rows3: 250,
62
+ Save: 40, SaveAll: 190, Scissors: 260, Search: 250, Send: 110, Server: 300,
63
+ ServerCog: 50, Settings: 240, Settings2: 20, Shield: 160, Shrink: 160, Sliders: 290,
64
+ SlidersHorizontal: 50, Smartphone: 20, Space: 290, Sparkles: 180, Square: 60, SquareFunction: 220,
65
+ SquarePen: 10, Star: 170, StickyNote: 100, Store: 340, Sun: 90, Tablet: 290,
66
+ Tag: 310, Target: 200, Terminal: 210, TextSelect: 220, Ticket: 170, TriangleAlert: 210,
67
+ Type: 170, Undo2: 310, Upload: 0, UploadCloud: 50, User: 140, Variable: 330,
68
+ Volume2: 270, VolumeX: 50, Wand2: 270, WandSparkles: 40, Waypoints: 30, WholeWord: 240,
69
+ WrapText: 340, Wrench: 0, X: 230, Zap: 120, ZoomIn: 250, ZoomOut: 340,
70
70
  };
71
71
 
72
72
  /**
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /** Only a NEW stream→finish transition earns a notice; failures ride the same rule. */
7
+
8
+ import { describe, expect, test } from 'bun:test';
9
+
10
+ import {
11
+ runOutcomeNotices,
12
+ streamOutcomes,
13
+ type StreamOutcome,
14
+ } from '@/shared/lib/notifications/outcomes';
15
+ import type { WorkspaceFolderData } from '@/shared/types';
16
+
17
+ function folders(
18
+ sessions: Array<{
19
+ id: string;
20
+ title?: string;
21
+ streamStatus?: StreamOutcome;
22
+ runFailure?: string;
23
+ }>,
24
+ ): WorkspaceFolderData[] {
25
+ return [
26
+ {
27
+ id: 1,
28
+ name: 'workspace',
29
+ isExpanded: true,
30
+ hasMore: false,
31
+ totalSessions: sessions.length,
32
+ sessions: sessions.map((session) => ({
33
+ id: session.id,
34
+ folder_id: 1,
35
+ title: session.title ?? session.id,
36
+ streamStatus: session.streamStatus,
37
+ runFailure: session.runFailure,
38
+ })),
39
+ },
40
+ ];
41
+ }
42
+
43
+ describe('run outcome notices', () => {
44
+ test('a run that finished after streaming is one notice', () => {
45
+ const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
46
+ expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'finish' }]))).toEqual([
47
+ { kind: 'finish', sessionId: 'a', title: 'a', detail: 'The run finished.' },
48
+ ]);
49
+ });
50
+
51
+ test('a badge already present at page load is not news', () => {
52
+ const previous = streamOutcomes(folders([{ id: 'a', streamStatus: 'finish' }]));
53
+ expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'finish' }]))).toEqual([]);
54
+ });
55
+
56
+ test('an aborted run is silent', () => {
57
+ const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
58
+ expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'abort' }]))).toEqual([]);
59
+ });
60
+
61
+ test('a failure is an error notice carrying the reason', () => {
62
+ const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
63
+ expect(
64
+ runOutcomeNotices(previous, folders([
65
+ { id: 'a', title: 'Fix the build', streamStatus: 'finish', runFailure: ' 401 invalid api key ' },
66
+ ])),
67
+ ).toEqual([
68
+ { kind: 'error', sessionId: 'a', title: 'Fix the build', detail: '401 invalid api key' },
69
+ ]);
70
+ });
71
+
72
+ test('an untitled session still names Kabmo', () => {
73
+ const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
74
+ const [notice] = runOutcomeNotices(previous, folders([{ id: 'a', title: ' ', streamStatus: 'finish' }]));
75
+ expect(notice?.title).toBe('Kabmo');
76
+ });
77
+
78
+ test('only sessions that moved are reported', () => {
79
+ const previous = new Map<string, StreamOutcome>([
80
+ ['a', 'stream'],
81
+ ['b', 'finish'],
82
+ ['c', undefined],
83
+ ]);
84
+ const notices = runOutcomeNotices(previous, folders([
85
+ { id: 'a', streamStatus: 'finish' },
86
+ { id: 'b', streamStatus: 'finish' },
87
+ { id: 'c', streamStatus: 'finish' },
88
+ ]));
89
+ expect(notices.map((notice) => notice.sessionId)).toEqual(['a']);
90
+ });
91
+
92
+ test('a stream that keeps streaming earns nothing', () => {
93
+ const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
94
+ expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'stream' }]))).toEqual([]);
95
+ });
96
+ });
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The run outcomes a sidebar-status snapshot is worth a notification for.
8
+ *
9
+ * Only `stream → finish` is news. `abort` is not: the operator either stopped
10
+ * the run themselves or a heal pass settled a process that had already gone
11
+ * away, and neither is an event to raise a banner for. A `finish` badge that is
12
+ * ALREADY there when the page loads is not news either — it is the state of the
13
+ * world the page woke up to, which is why the caller compares against the
14
+ * previous snapshot rather than notifying on presence.
15
+ *
16
+ * A failed run is the same transition with `runFailure` set, so the two
17
+ * notifications share one rule and cannot disagree about when they fire.
18
+ */
19
+
20
+ import type { WorkspaceFolderData } from '@/shared/types';
21
+
22
+ export type StreamOutcome = 'stream' | 'finish' | 'abort' | undefined;
23
+
24
+ export interface RunOutcomeNotice {
25
+ kind: 'finish' | 'error';
26
+ /** The session the message is about; also the notification's tag. */
27
+ sessionId: string;
28
+ title: string;
29
+ detail: string;
30
+ }
31
+
32
+ /** The status map one folder snapshot carries, for the next comparison. */
33
+ export function streamOutcomes(folders: WorkspaceFolderData[]): Map<string, StreamOutcome> {
34
+ const outcomes = new Map<string, StreamOutcome>();
35
+ for (const folder of folders) {
36
+ for (const session of folder.sessions ?? []) {
37
+ outcomes.set(String(session.id), session.streamStatus);
38
+ }
39
+ }
40
+ return outcomes;
41
+ }
42
+
43
+ /** The notices `folders` earns against `previous`. */
44
+ export function runOutcomeNotices(
45
+ previous: ReadonlyMap<string, StreamOutcome>,
46
+ folders: WorkspaceFolderData[],
47
+ ): RunOutcomeNotice[] {
48
+ const notices: RunOutcomeNotice[] = [];
49
+ for (const folder of folders) {
50
+ for (const session of folder.sessions ?? []) {
51
+ const sessionId = String(session.id);
52
+ if (session.streamStatus !== 'finish') continue;
53
+ if (previous.get(sessionId) !== 'stream') continue;
54
+ const failure = typeof session.runFailure === 'string' ? session.runFailure.trim() : '';
55
+ notices.push({
56
+ kind: failure ? 'error' : 'finish',
57
+ sessionId,
58
+ title: session.title?.trim() || 'Kabmo',
59
+ detail: failure || 'The run finished.',
60
+ });
61
+ }
62
+ }
63
+ return notices;
64
+ }