@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,68 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The timeline fields ACP frames did not carry: a message stamp at first
8
+ * chunk, and the turn's measured duration at close. Without them the assistant
9
+ * footer had no date or response time for any ACP harness.
10
+ *
11
+ * Split from `frames.test.ts` to stay under the file ceiling.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+ import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
16
+ import { toChatMessage } from '@/shared/lib/omp/session/mapper';
17
+
18
+ const textChunk = (text: string, messageId = 'm1') => ({
19
+ sessionUpdate: 'agent_message_chunk',
20
+ content: { type: 'text', text },
21
+ messageId,
22
+ });
23
+
24
+ /** The frame's message as a record, for assertions on fields the event type
25
+ * widens to `unknown`. The mapper built it, so the shape is ours. */
26
+ const messageOf = (frame: unknown): Record<string, unknown> | null => {
27
+ if (!frame || typeof frame !== 'object' || !('message' in frame)) return null;
28
+ const message = frame.message;
29
+ return message && typeof message === 'object' ? message as Record<string, unknown> : null;
30
+ };
31
+
32
+ describe('acp frame mapper — message timing', () => {
33
+ test('stamps the message start once, not every chunk', () => {
34
+ const mapper = new AcpFrameMapper();
35
+ const first = messageOf(mapper.mapUpdate(textChunk('hello '))[0]);
36
+ const second = messageOf(mapper.mapUpdate(textChunk('world'))[0]);
37
+ expect(typeof first?.timestamp).toBe('number');
38
+ expect(second?.timestamp).toBe(first?.timestamp);
39
+ });
40
+
41
+ test('the closed message carries a duration measured from the turn start', () => {
42
+ const mapper = new AcpFrameMapper();
43
+ mapper.reset(1_000);
44
+ mapper.mapUpdate(textChunk('done'));
45
+ const message = messageOf(mapper.closeMessage()[0]);
46
+ const { timestamp, completedAt, duration } = message ?? {};
47
+ if (typeof timestamp !== 'number' || typeof completedAt !== 'number' || typeof duration !== 'number') {
48
+ throw new Error('message_end is missing its timing fields');
49
+ }
50
+ expect(timestamp).toBeGreaterThanOrEqual(1_000);
51
+ expect(completedAt).toBeGreaterThanOrEqual(timestamp);
52
+ expect(duration).toBe(completedAt - 1_000);
53
+ });
54
+
55
+ test('the client mapper turns those fields into the footer stamp and duration', () => {
56
+ const mapper = new AcpFrameMapper();
57
+ mapper.reset(1_000);
58
+ mapper.mapUpdate(textChunk('done'));
59
+ const message = messageOf(mapper.closeMessage()[0]);
60
+ if (!message) throw new Error('message_end carried no message');
61
+ const converted = toChatMessage(message, false);
62
+ expect(converted?.date).toStartWith('Today,');
63
+ expect(converted?.timestamp).toMatch(/^\d{1,2}:\d{2}\s(AM|PM)$/);
64
+ const duration = message.duration;
65
+ if (typeof duration !== 'number') throw new Error('message_end carried no duration');
66
+ expect(converted?.durationMs).toBe(duration);
67
+ });
68
+ });
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * v2 frame semantics: whole-message upserts, one tool-call upsert, streaming
8
+ * tool content, keyed plans, and the two extra final statuses.
9
+ *
10
+ * Split from `frames.test.ts` to stay under the file ceiling.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
15
+
16
+ describe('acp v2 updates', () => {
17
+ test('a whole agent_message replaces content and a chunk appends to it', () => {
18
+ const mapper = new AcpFrameMapper();
19
+ const whole = mapper.mapUpdate({
20
+ sessionUpdate: 'agent_message',
21
+ messageId: 'm1',
22
+ content: [{ type: 'text', text: 'hello' }],
23
+ });
24
+ expect(whole.at(-1)).toMatchObject({
25
+ type: 'message_update',
26
+ message: { content: [{ type: 'text', text: 'hello' }] },
27
+ });
28
+ const chunk = mapper.mapUpdate({
29
+ sessionUpdate: 'agent_message_chunk',
30
+ messageId: 'm1',
31
+ content: { type: 'text', text: ' world' },
32
+ });
33
+ expect(chunk.at(-1)).toMatchObject({
34
+ type: 'message_update',
35
+ message: { content: [{ type: 'text', text: 'hello world' }] },
36
+ });
37
+ });
38
+
39
+ test('a later whole message replaces the text it streamed before', () => {
40
+ const mapper = new AcpFrameMapper();
41
+ mapper.mapUpdate({ sessionUpdate: 'agent_message', messageId: 'm1', content: [{ type: 'text', text: 'old' }] });
42
+ const replaced = mapper.mapUpdate({
43
+ sessionUpdate: 'agent_message',
44
+ messageId: 'm1',
45
+ content: [{ type: 'text', text: 'new' }],
46
+ });
47
+ expect(replaced.at(-1)).toMatchObject({ message: { content: [{ type: 'text', text: 'new' }] } });
48
+ });
49
+
50
+ test('a first tool_call_update creates the call and content chunks reach its result', () => {
51
+ const mapper = new AcpFrameMapper();
52
+ const start = mapper.mapUpdate({
53
+ sessionUpdate: 'tool_call_update',
54
+ toolCallId: 't1',
55
+ title: 'Run tests',
56
+ name: 'bash',
57
+ kind: 'execute',
58
+ status: 'in_progress',
59
+ });
60
+ expect(start.some((event) => event.type === 'tool_execution_start')).toBe(true);
61
+ mapper.mapUpdate({
62
+ sessionUpdate: 'tool_call_content_chunk',
63
+ toolCallId: 't1',
64
+ content: { type: 'content', content: { type: 'text', text: 'out' } },
65
+ });
66
+ const end = mapper.mapUpdate({ sessionUpdate: 'tool_call_update', toolCallId: 't1', status: 'completed' });
67
+ expect(end[0]).toMatchObject({ type: 'tool_execution_end', output: 'out', isError: false });
68
+ });
69
+
70
+ test('cancelled is a final tool status and paused is not', () => {
71
+ const mapper = new AcpFrameMapper();
72
+ mapper.mapUpdate({ sessionUpdate: 'tool_call_update', toolCallId: 'p1', status: 'paused' });
73
+ expect(mapper.openCalls()).toEqual(['p1']);
74
+ const cancelled = mapper.mapUpdate({ sessionUpdate: 'tool_call_update', toolCallId: 'p1', status: 'cancelled' });
75
+ expect(cancelled[0]).toMatchObject({ type: 'tool_execution_end', isError: true });
76
+ });
77
+
78
+ test('plan_update feeds the entries the Todos panel reads', () => {
79
+ const frames = new AcpFrameMapper().mapUpdate({
80
+ sessionUpdate: 'plan_update',
81
+ plan: { type: 'items', planId: 'p1', entries: [{ content: 'step', status: 'pending' }] },
82
+ });
83
+ expect(frames[0]).toMatchObject({ type: 'plan_updated', entries: [{ content: 'step' }] });
84
+ });
85
+ });
@@ -33,55 +33,42 @@
33
33
  */
34
34
 
35
35
  import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
36
- import {
37
- acpContentDetails,
38
- acpContentText,
39
- acpToolDetails,
40
- acpToolOutput,
41
- acpToolTarget,
42
- isKnownToolName,
43
- toolTypeFor,
44
- } from '@/server/lib/harness/acp/mapper';
45
- import type { AcpToolKind, AcpToolStatus } from '@/server/lib/harness/acp/protocol';
36
+ import { acpContentText } from '@/server/lib/harness/acp/mapper';
37
+ import { planEntries } from '@/server/lib/harness/acp/v2';
38
+ import { AcpToolCalls, type ToolCallBlock } from '@/server/lib/harness/acp/tool-calls';
46
39
 
47
40
  /** One block of the accumulated assistant message, in `parseMessageBlocks` shape. */
48
41
  type MessageBlock =
49
42
  | { type: 'text'; text: string }
50
43
  | { type: 'thinking'; thinking: string }
51
- | { type: 'toolCall'; id: string; name: string; arguments?: Record<string, unknown>; toolKind?: AcpToolKind; toolType?: string };
52
-
53
- interface OpenTool {
54
- id: string;
55
- name: string;
56
- kind?: AcpToolKind;
57
- title?: string;
58
- status: AcpToolStatus;
59
- rawOutput?: unknown;
60
- /** `tool_call(Update).content` — where some agents put the diff/output. */
61
- content?: unknown;
62
- locations?: unknown;
63
- startedAt: number;
64
- }
44
+ | ToolCallBlock;
65
45
 
66
46
  /** Per-session accumulator; one instance per live ACP session. */
67
47
  export class AcpFrameMapper {
68
48
  private blocks: MessageBlock[] = [];
69
49
  private messageId: string | null = null;
70
- private readonly open = new Map<string, OpenTool>();
50
+ /** When the turn was dispatched, the base for its duration. */
51
+ private turnStartedAt: number | null = null;
52
+ /** When the open message's first frame arrived, its timeline stamp. */
53
+ private openedAt: number | null = null;
54
+ private readonly tools = new AcpToolCalls({
55
+ pushBlock: (block) => this.blocks.push(block),
56
+ snapshot: () => this.snapshot(),
57
+ });
71
58
 
72
- /** Forget per-turn state (an aborted run, a fresh load). */
73
- reset(): void {
59
+ /** Forget per-turn state (an aborted run, a fresh load) and start its clock. */
60
+ reset(startedAt: number = Date.now()): void {
74
61
  this.blocks = [];
75
62
  this.messageId = null;
76
- this.open.clear();
63
+ this.openedAt = null;
64
+ this.turnStartedAt = startedAt;
65
+ this.tools.reset();
77
66
  }
78
67
 
79
68
  /** Tool calls still running — the driver closes them if the agent exits
80
69
  * mid-turn, so no card is left spinning forever. */
81
70
  openCalls(): string[] {
82
- return [...this.open.values()]
83
- .filter((call) => call.status === 'pending' || call.status === 'in_progress')
84
- .map((call) => call.id);
71
+ return this.tools.openCalls();
85
72
  }
86
73
 
87
74
  /**
@@ -97,14 +84,29 @@ export class AcpFrameMapper {
97
84
  return this.appendChunk(update, 'text');
98
85
  case 'agent_thought_chunk':
99
86
  return this.appendChunk(update, 'thinking');
87
+ // v2 whole-message upserts: replace that message's content, keep tool blocks.
88
+ case 'agent_message':
89
+ return this.upsertMessage(update, 'text');
90
+ case 'agent_thought':
91
+ return this.upsertMessage(update, 'thinking');
92
+ case 'user_message':
100
93
  case 'user_message_chunk':
101
94
  // Live user chunks only arrive on replay/steering; the composer already
102
95
  // drew the optimistic bubble, so this is a receipt, not a new row.
103
96
  return [];
104
97
  case 'tool_call':
105
- return this.openTool(update);
98
+ return this.tools.open(update);
106
99
  case 'tool_call_update':
107
- return this.patchTool(update);
100
+ return this.tools.patch(update);
101
+ case 'tool_call_content_chunk':
102
+ return this.tools.appendContent(update);
103
+ // v2's turn boundary is handled by `AcpTurns.onStateUpdate`, not mapped.
104
+ case 'state_update':
105
+ case 'terminal_update':
106
+ case 'terminal_output_chunk':
107
+ case 'compaction_update':
108
+ case 'compaction_summary_chunk':
109
+ return [];
108
110
  case 'usage_update':
109
111
  return this.usage(update);
110
112
  case 'available_commands_update':
@@ -123,6 +125,9 @@ export class AcpFrameMapper {
123
125
  // The spec defines it; no measured agent sends it. Forwarded so a future
124
126
  // adapter lights the panel with no change here.
125
127
  return [{ type: 'plan_updated', entries: update.entries ?? [] }];
128
+ case 'plan_update':
129
+ // v2 keyed plans; Kabmo's Todos panel renders one list.
130
+ return [{ type: 'plan_updated', entries: planEntries(update) }];
126
131
  case 'notice':
127
132
  return [{
128
133
  type: 'notice',
@@ -140,9 +145,16 @@ export class AcpFrameMapper {
140
145
  /** Close the open assistant row (turn end, abort, disconnect). */
141
146
  closeMessage(): AgentEvent[] {
142
147
  if (!this.messageId && this.blocks.length === 0) return [];
148
+ const completedAt = Date.now();
143
149
  const message = this.snapshot();
150
+ const startedAt = this.turnStartedAt ?? this.openedAt;
151
+ if (startedAt !== null) {
152
+ message.completedAt = completedAt;
153
+ message.duration = Math.max(0, completedAt - startedAt);
154
+ }
144
155
  this.blocks = [];
145
156
  this.messageId = null;
157
+ this.openedAt = null;
146
158
  return [{ type: 'message_end', message }];
147
159
  }
148
160
 
@@ -158,9 +170,11 @@ export class AcpFrameMapper {
158
170
  */
159
171
  private snapshot(): Record<string, unknown> {
160
172
  const id = this.messageId ??= `acp-${crypto.randomUUID()}`;
173
+ const timestamp = this.openedAt ??= Date.now();
161
174
  return {
162
175
  role: 'assistant',
163
176
  id,
177
+ timestamp,
164
178
  content: this.blocks.map((block) => ({ ...block })),
165
179
  };
166
180
  }
@@ -194,134 +208,33 @@ export class AcpFrameMapper {
194
208
  return frames;
195
209
  }
196
210
 
197
- private openTool(update: Record<string, unknown>): AgentEvent[] {
198
- const toolCallId = typeof update.toolCallId === 'string' ? update.toolCallId : '';
199
- if (!toolCallId) return [];
200
- const name = typeof update.name === 'string' && update.name
201
- ? update.name
202
- : typeof update.title === 'string' && update.title
203
- ? update.title
204
- : 'tool';
205
- const kind = typeof update.kind === 'string' ? (update.kind as AcpToolKind) : undefined;
206
- const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : 'pending';
207
- // A specific kind is authoritative. `other`/absent is only an explicit type
208
- // when the name is one the renderers know; otherwise the shared parser's
209
- // own inference from the name is better informed than a forced `read`.
210
- const toolType = kind !== undefined && kind !== 'other'
211
- ? toolTypeFor(kind, name)
212
- : isKnownToolName(name) ? toolTypeFor(kind, name) : undefined;
213
- const rawInput = update.rawInput;
214
- const args = rawInput && typeof rawInput === 'object' && !Array.isArray(rawInput)
215
- ? Object.fromEntries(Object.entries(rawInput))
216
- : undefined;
217
-
218
- // The card is drawn from the message block, so opening a call means adding
219
- // the block and re-emitting the message — not emitting a separate card row.
220
- // `toolType` travels with the block: the shared parser's name inference
221
- // cannot know that ACP `kind:"execute"` means bash when the name is `Shell`.
222
- this.blocks.push({
223
- type: 'toolCall',
224
- id: toolCallId,
225
- name,
226
- ...(args ? { arguments: args } : {}),
227
- ...(kind ? { toolKind: kind } : {}),
228
- ...(toolType ? { toolType } : {}),
229
- });
230
-
231
- const frames: AgentEvent[] = [
232
- { type: 'message_update', message: this.snapshot(), assistantMessageEvent: { type: 'toolcall_start' } },
233
- {
234
- type: 'tool_execution_start',
235
- toolCallId,
236
- toolName: name,
237
- ...(toolType ? { toolType } : {}),
238
- ...(args ? { args } : {}),
239
- ...(typeof update.title === 'string' ? { intent: update.title } : {}),
240
- ...(acpToolTarget(update.locations, rawInput) ? { target: acpToolTarget(update.locations, rawInput) } : {}),
241
- },
242
- ];
243
-
244
- // Some agents announce a call ONLY once it is finished (`tool_call` with
245
- // `status:"completed"` and no later update). Leaving it in the open map
246
- // meant the turn's cleanup closed it as an ERROR, overwriting a success.
247
- if (status === 'completed' || status === 'failed') {
248
- frames.push({
249
- type: 'tool_execution_end',
250
- toolCallId,
251
- toolName: name,
252
- result: update.rawOutput ?? (update.content === undefined ? undefined : { content: update.content }),
253
- isError: status === 'failed',
254
- details: acpToolDetails(update.rawOutput) ?? acpContentDetails(update.content),
255
- output: acpToolOutput(update.rawOutput) || acpContentText(update.content),
256
- });
257
- } else {
258
- this.open.set(toolCallId, {
259
- id: toolCallId,
260
- name,
261
- kind,
262
- title: typeof update.title === 'string' ? update.title : undefined,
263
- status,
264
- rawOutput: update.rawOutput,
265
- content: update.content,
266
- locations: update.locations,
267
- startedAt: Date.now(),
268
- });
269
- }
270
- return frames;
271
- }
272
-
273
211
  /**
274
- * `tool_call_update` is a PATCH: every field but `toolCallId` is optional and
275
- * an omitted one means UNCHANGED. Merging is what keeps a completed card's
276
- * body — measured, the completion update carries only `status` and
277
- * `rawOutput.details`.
212
+ * v2 whole-message upsert: replace that message's blocks of one kind.
213
+ *
214
+ * Tool-call blocks are entities of their own in v2; they stay in place, and
215
+ * the text/thinking content for the message is replaced wholesale.
278
216
  */
279
- private patchTool(update: Record<string, unknown>): AgentEvent[] {
280
- const toolCallId = typeof update.toolCallId === 'string' ? update.toolCallId : '';
281
- if (!toolCallId) return [];
282
- const existing = this.open.get(toolCallId);
283
- // An update for a call this mapper never saw (a replay window, a resumed
284
- // session): treat it as an opening call rather than dropping the work.
285
- if (!existing) return this.openTool(update);
286
-
287
- if (update.rawOutput !== undefined) existing.rawOutput = update.rawOutput;
288
- if (update.content !== undefined) existing.content = update.content;
289
- if (update.locations !== undefined) existing.locations = update.locations;
290
- if (typeof update.title === 'string') existing.title = update.title;
291
- const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : existing.status;
292
- existing.status = status;
293
-
294
- // Some agents report the result as `content` blocks instead of `rawOutput`;
295
- // the diff block only becomes visible through the details bridge.
296
- const result = existing.rawOutput ?? (existing.content === undefined ? undefined : { content: existing.content });
297
- const output = acpToolOutput(existing.rawOutput) || acpContentText(existing.content);
298
- const details = acpToolDetails(existing.rawOutput) ?? acpContentDetails(existing.content);
299
-
300
- if (status === 'completed' || status === 'failed') {
301
- const failed = status === 'failed';
302
- this.open.delete(toolCallId);
303
- return [{
304
- type: 'tool_execution_end',
305
- toolCallId,
306
- toolName: existing.name,
307
- result,
308
- isError: failed,
309
- details,
310
- durationMs: Math.max(0, Date.now() - existing.startedAt),
311
- output,
312
- }];
217
+ private upsertMessage(update: Record<string, unknown>, kind: 'text' | 'thinking'): AgentEvent[] {
218
+ const messageId = typeof update.messageId === 'string' ? update.messageId : '';
219
+ if (!messageId || !('content' in update)) return [];
220
+ const frames: AgentEvent[] = [];
221
+ if (this.messageId && this.messageId !== messageId) frames.push(...this.closeMessage());
222
+ this.messageId = messageId;
223
+ const raw = update.content;
224
+ const text = raw === null || (Array.isArray(raw) && raw.length === 0) ? '' : acpContentText(raw);
225
+ this.blocks = this.blocks.filter((block) => block.type !== kind);
226
+ if (text) {
227
+ this.blocks.push(kind === 'text' ? { type: 'text', text } : { type: 'thinking', thinking: text });
313
228
  }
314
-
315
- return [{
316
- type: 'tool_execution_update',
317
- toolCallId,
318
- toolName: existing.name,
319
- partialResult: result,
320
- // The ACP output shape may nest text (`{type:"content", content:{…}}`),
321
- // which `toolResultText` does not walk. The flattened read travels with
322
- // the raw result so the card is not blank while the call is running.
323
- output,
324
- }];
229
+ frames.push({
230
+ type: 'message_update',
231
+ message: this.snapshot(),
232
+ assistantMessageEvent: {
233
+ type: kind === 'text' ? 'text_delta' : 'thinking_delta',
234
+ delta: text,
235
+ },
236
+ });
237
+ return frames;
325
238
  }
326
239
 
327
240
  private usage(update: Record<string, unknown>): AgentEvent[] {
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The pure ACP content helpers the mapper feeds the renderers with.
8
+ *
9
+ * Split from `frames.test.ts` when the v2 cases pushed that file past the line
10
+ * ceiling; these cases do not need the accumulator.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { acpContentText, acpToolOutput, acpToolTarget } from '@/server/lib/harness/acp/mapper';
15
+
16
+ describe('acp mapper helpers', () => {
17
+ test('both measured content shapes yield text', () => {
18
+ expect(acpContentText([{ type: 'text', text: 'a' }, { type: 'text', text: 'b' }])).toBe('a\nb');
19
+ expect(acpContentText([{ type: 'content', content: { type: 'text', text: 'wrapped' } }])).toBe('wrapped');
20
+ expect(acpContentText('plain')).toBe('plain');
21
+ // MCP-style tool output: the embedded text is readable, a link is named.
22
+ expect(acpContentText([{ type: 'resource', resource: { uri: 'file:///a.txt', text: 'hello' } }])).toBe('hello');
23
+ expect(acpContentText([{ type: 'resource', resource: { uri: 'file:///a.bin', blob: 'AA==' } }]))
24
+ .toBe('[binary resource file:///a.bin]');
25
+ expect(acpContentText([{ type: 'resource_link', uri: 'file:///a.md', name: 'a.md' }]))
26
+ .toBe('a.md (file:///a.md)');
27
+ });
28
+
29
+ test('rawOutput keeps omp-shaped fallbacks', () => {
30
+ expect(acpToolOutput({ content: [{ type: 'text', text: 'x' }] })).toBe('x');
31
+ expect(acpToolOutput({ output: 'y' })).toBe('y');
32
+ expect(acpToolOutput(null)).toBe('');
33
+ });
34
+
35
+ test('target prefers locations, then the input bag', () => {
36
+ expect(acpToolTarget([{ path: '/a' }], { path: 'b' })).toBe('/a');
37
+ expect(acpToolTarget(undefined, { command: 'ls -la' })).toBe('ls -la');
38
+ expect(acpToolTarget(undefined, undefined)).toBeUndefined();
39
+ });
40
+ });
@@ -80,6 +80,18 @@ function entryText(entry: unknown): string {
80
80
  if (!('type' in entry)) return '';
81
81
  if (entry.type === 'text' && 'text' in entry && typeof entry.text === 'string') return entry.text;
82
82
  if (entry.type === 'content' && 'content' in entry) return entryText(entry.content);
83
+ // MCP tool output commonly carries complete resources. The text form is
84
+ // readable; a blob has no text, so the card names it rather than showing
85
+ // nothing at all.
86
+ if (entry.type === 'resource' && 'resource' in entry && entry.resource && typeof entry.resource === 'object') {
87
+ if ('text' in entry.resource && typeof entry.resource.text === 'string') return entry.resource.text;
88
+ const uri = 'uri' in entry.resource && typeof entry.resource.uri === 'string' ? entry.resource.uri : '';
89
+ return uri ? `[binary resource ${uri}]` : '';
90
+ }
91
+ if (entry.type === 'resource_link' && 'uri' in entry && typeof entry.uri === 'string') {
92
+ const name = 'name' in entry && typeof entry.name === 'string' ? entry.name : entry.uri;
93
+ return `${name} (${entry.uri})`;
94
+ }
83
95
  return '';
84
96
  }
85
97
 
@@ -109,6 +109,12 @@ export class PendingPermissions {
109
109
  this.entries.length = 0;
110
110
  }
111
111
 
112
+ /** Remove and return every pending request, for a caller that must answer
113
+ * each one (a cancelled turn answers them all with `cancelled`). */
114
+ drain(): PendingPermission[] {
115
+ return this.entries.splice(0, this.entries.length);
116
+ }
117
+
112
118
  size(): number {
113
119
  return this.entries.length;
114
120
  }
@@ -22,6 +22,25 @@
22
22
  /** A JSON-RPC id. ACP forbids `null`, and replies echo whatever was sent. */
23
23
  export type AcpId = string | number;
24
24
 
25
+ /**
26
+ * The JSON-RPC/ACP error codes Kabmo answers with.
27
+ *
28
+ * A refusal is not "internal error": an agent decides whether to fall back, retry
29
+ * or give up from the code, so `-32601` for a method this client does not
30
+ * implement and `-32002` for a missing file are part of the contract rather than
31
+ * cosmetic detail.
32
+ */
33
+ export const ACP_ERROR = {
34
+ parse: -32700,
35
+ invalidRequest: -32600,
36
+ methodNotFound: -32601,
37
+ invalidParams: -32602,
38
+ internal: -32603,
39
+ cancelled: -32800,
40
+ authRequired: -32000,
41
+ notFound: -32002,
42
+ } as const;
43
+
25
44
  export interface AcpRequest {
26
45
  jsonrpc: '2.0';
27
46
  id: AcpId;
@@ -61,7 +80,17 @@ export type AcpToolKind =
61
80
  | 'switch_mode'
62
81
  | 'other';
63
82
 
64
- export type AcpToolStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
83
+ export type AcpToolStatus = 'pending' | 'in_progress' | 'paused' | 'completed' | 'failed' | 'cancelled';
84
+
85
+ /** A protocol major this client can speak. */
86
+ export type AcpProtocolVersion = 1 | 2;
87
+
88
+ /** One slash command, in the shape the composer consumes. */
89
+ export interface AcpAgentCommand {
90
+ name: string;
91
+ description?: string;
92
+ inputHint?: string;
93
+ }
65
94
 
66
95
  export interface AcpToolLocation {
67
96
  path: string;
@@ -112,7 +141,17 @@ export interface AcpConfigOption {
112
141
  export interface AcpSessionNewResult {
113
142
  sessionId: string;
114
143
  configOptions?: AcpConfigOption[];
115
- modes?: unknown;
144
+ /** The older Session Modes API. A client that understands `configOptions`
145
+ * SHOULD ignore this; Kabmo falls back to it when no `mode` selector exists. */
146
+ modes?: AcpSessionModeState;
147
+ /** v2 setup responses may advertise the initial slash commands. */
148
+ availableCommands?: AcpAgentCommand[];
149
+ }
150
+
151
+ /** `session/new|load|resume`'s legacy mode state, and `session/set_mode`. */
152
+ export interface AcpSessionModeState {
153
+ currentModeId: string;
154
+ availableModes: { id: string; name: string; description?: string }[];
116
155
  }
117
156
 
118
157
  export interface AcpInitializeResult {
@@ -66,6 +66,6 @@ export function metadataCapabilities(
66
66
  kind: string,
67
67
  ): HarnessCapabilities {
68
68
  if (kind === 'usage_update') return { ...capabilities, hasUsage: true };
69
- if (kind === 'plan') return { ...capabilities, hasPlan: true };
69
+ if (kind === 'plan' || kind === 'plan_update') return { ...capabilities, hasPlan: true };
70
70
  return capabilities;
71
71
  }