@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
@@ -11,14 +11,19 @@
11
11
  * auto-answer cannot disagree.
12
12
  */
13
13
 
14
- import { answerPermissionRequest } from '@/server/lib/harness/acp/session-permissions';
15
- import type { AcpId } from '@/server/lib/harness/acp/protocol';
14
+ import { answerPermissionRequest, cancelAcpPermission } from '@/server/lib/harness/acp/session-permissions';
15
+ import { handleAcpFsRequest, isAcpFsMethod } from '@/server/lib/harness/acp/client-fs';
16
+ import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
17
+ import { normalizePermissionParams } from '@/server/lib/harness/acp/v2';
18
+ import type { AcpId, AcpProtocolVersion } from '@/server/lib/harness/acp/protocol';
16
19
  import type { PendingPermissions } from '@/server/lib/harness/acp/permissions';
17
20
  import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
18
21
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
19
22
 
20
23
  export interface AcpClientRequestHost {
21
- sessionId: string;
24
+ readonly sessionId: string;
25
+ readonly cwd: string;
26
+ readonly protocol: AcpProtocolVersion;
22
27
  accessMode: ApprovalMode;
23
28
  permissions: PendingPermissions;
24
29
  emit: (event: AgentEvent) => void;
@@ -26,7 +31,7 @@ export interface AcpClientRequestHost {
26
31
 
27
32
  export type AcpClientRequestAnswer =
28
33
  | { answered: true; result: unknown }
29
- | { answered: false; message: string }
34
+ | { answered: false; message: string; code?: number }
30
35
  | { answered: false; deferred: true };
31
36
 
32
37
  export function handleAcpClientRequest(
@@ -36,12 +41,49 @@ export function handleAcpClientRequest(
36
41
  params: Record<string, unknown>,
37
42
  ): Promise<AcpClientRequestAnswer> {
38
43
  if (method === 'session/request_permission') {
44
+ // v2 restructured this call: a required `title` and an optional `subject`
45
+ // replace the v1 `toolCall`. The approval queue keeps its v1 shape.
46
+ const normalized = host.protocol === 2 ? normalizePermissionParams(params) : params;
39
47
  return answerPermissionRequest({
40
48
  sessionId: host.sessionId,
41
49
  accessMode: host.accessMode,
42
50
  permissions: host.permissions,
43
51
  emit: (event) => host.emit(event),
44
- }, id, params);
52
+ }, id, normalized);
45
53
  }
46
- return Promise.resolve({ answered: false, message: `Kabmo does not implement ${method}` });
54
+ // The file surface the client advertised at `initialize`. Routed before the
55
+ // refusal so an agent that took the advertisement at its word gets an answer.
56
+ if (isAcpFsMethod(method)) return handleAcpFsRequest(host, method, params);
57
+ // `-32601`, not "internal error": the agent decides from the code whether this
58
+ // client simply lacks the method (Spec §Errors).
59
+ return Promise.resolve({
60
+ answered: false,
61
+ message: `Kabmo does not implement ${method}`,
62
+ code: ACP_ERROR.methodNotFound,
63
+ });
64
+ }
65
+
66
+ /** The host a cancellation notification needs; `AcpSession` satisfies it. */
67
+ export interface AcpCancelHost {
68
+ readonly permissions: PendingPermissions;
69
+ respond(id: AcpId, result: unknown): void;
70
+ }
71
+
72
+ /**
73
+ * Handle `$/cancel_request` — the agent withdrawing a request it made on this
74
+ * client. The only long-lived one Kabmo parks is an approval, and ACP requires
75
+ * the `cancelled` outcome for it. Returns false for a different method so the
76
+ * caller keeps routing.
77
+ */
78
+ export function handleAcpCancelRequest(
79
+ host: AcpCancelHost,
80
+ method: string,
81
+ params: Record<string, unknown>,
82
+ ): boolean {
83
+ if (method !== '$/cancel_request') return false;
84
+ const requestId = params.requestId;
85
+ if (typeof requestId === 'string' || typeof requestId === 'number') {
86
+ cancelAcpPermission(host.permissions, host, requestId);
87
+ }
88
+ return true;
47
89
  }
@@ -53,7 +53,7 @@ export interface AcpTurnTarget {
53
53
  totalCost: number;
54
54
  runModel: { provider: string; modelId: string } | null;
55
55
  /** The durable run marker; a field on the session so a test can stub it. */
56
- markStream: (status: 'stream' | 'finish' | 'abort') => void;
56
+ markStream: (status: 'stream' | 'finish' | 'abort', failure?: string | null) => void;
57
57
  isAlive(): boolean;
58
58
  isBusy(): boolean;
59
59
  send(command: Record<string, unknown>): Promise<unknown>;
@@ -86,8 +86,13 @@ export function settleAcpTurn(target: AcpTurnTarget, info: AcpTurnEndInfo): void
86
86
  totalCost: target.totalCost,
87
87
  runModel: target.runModel,
88
88
  });
89
- // A cancelled turn is an `abort` badge, every other ending a `finish`.
90
- target.markStream(info.stopReason === 'cancelled' ? 'abort' : 'finish');
89
+ // A cancelled turn is an `abort` badge; every other ending a `finish` — and a
90
+ // failed turn carries the agent's own reason, which is the only copy a tab
91
+ // that never opened the session can read.
92
+ const failure = info.failed === true
93
+ ? (info.failure?.trim() || 'The agent ended the turn without an answer')
94
+ : null;
95
+ target.markStream(info.stopReason === 'cancelled' ? 'abort' : 'finish', failure);
91
96
  // Todo/plan/telemetry panels read their own topics; without this signal an
92
97
  // ACP turn's usage and titles never republished (the RPC settle path does it).
93
98
  emitRealtimeSignal('session-data-dirty', target.sessionId);
@@ -42,6 +42,10 @@ export class AcpUsageMeter {
42
42
  this.turnPeak = Math.max(this.turnPeak, used);
43
43
  }
44
44
  const cost = update.cost;
45
+ if (cost === null) {
46
+ this.totalCost = 0;
47
+ return;
48
+ }
45
49
  if (cost && typeof cost === 'object' && 'amount' in cost && typeof cost.amount === 'number') {
46
50
  this.totalCost = cost.amount;
47
51
  }
@@ -20,7 +20,7 @@
20
20
  */
21
21
 
22
22
  import { configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
23
- import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
23
+ import type { AcpConfigOption, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
24
24
  import type { HarnessId } from '@/shared/lib/harness/catalog';
25
25
 
26
26
  export interface AcpStateView {
@@ -34,9 +34,34 @@ export interface AcpStateView {
34
34
  totalCost: number;
35
35
  runModel: { provider: string; modelId: string } | null;
36
36
  configOptions: AcpConfigOption[];
37
+ /** The older Session Modes API, when the agent published no selector. */
38
+ modes: AcpSessionModeState | null;
37
39
  harness: HarnessId;
38
40
  }
39
41
 
42
+ /**
43
+ * The agent's legacy mode list as the selector every Kabmo consumer already
44
+ * reads. `applyHarnessMode` and the composer look for a `category: "mode"`
45
+ * config option; without this an agent that only speaks `modes` had no Plan
46
+ * control at all. Writing the synthesized id routes back to `session/set_mode`
47
+ * in `AcpSession.setConfig`.
48
+ */
49
+ function modeSelector(modes: AcpSessionModeState | null): AcpConfigOption[] {
50
+ if (!modes) return [];
51
+ return [{
52
+ id: 'mode',
53
+ name: 'Session Mode',
54
+ category: 'mode',
55
+ type: 'select',
56
+ currentValue: modes.currentModeId,
57
+ options: modes.availableModes.map((entry) => ({
58
+ value: entry.id,
59
+ name: entry.name,
60
+ ...(entry.description ? { description: entry.description } : {}),
61
+ })),
62
+ }];
63
+ }
64
+
40
65
  export function acpWebState(view: AcpStateView): Record<string, unknown> {
41
66
  const thinking = configOption(view.configOptions, 'thought_level');
42
67
  // The run's model is seeded at `start()` and refreshed by every config write,
@@ -44,6 +69,9 @@ export function acpWebState(view: AcpStateView): Record<string, unknown> {
44
69
  // must report, since an alias or a fallback can differ from the request. The
45
70
  // fallback exists only for a session whose selector list never carried a model.
46
71
  const serving = view.runModel ?? modelFromOption(configOption(view.configOptions, 'model'), view.harness);
72
+ const configOptions = configOption(view.configOptions, 'mode')
73
+ ? view.configOptions
74
+ : [...view.configOptions, ...modeSelector(view.modes)];
47
75
  return {
48
76
  sessionId: view.sessionId,
49
77
  isStreaming: view.isStreaming,
@@ -56,6 +84,6 @@ export function acpWebState(view: AcpStateView): Record<string, unknown> {
56
84
  totalCost: view.totalCost,
57
85
  model: serving ? { id: serving.modelId, provider: serving.provider } : undefined,
58
86
  thinkingLevel: typeof thinking?.currentValue === 'string' ? thinking.currentValue : undefined,
59
- configOptions: view.configOptions,
87
+ configOptions,
60
88
  };
61
89
  }
@@ -47,6 +47,12 @@ export interface MountedSession {
47
47
  turnEnds: () => number;
48
48
  /** The durable run markers written for this session, in order. */
49
49
  streamMarks: () => string[];
50
+ /** The `failure` argument written with each marker, in the same order. */
51
+ streamMarkFailures: () => Array<string | null>;
52
+ /** Results the session answered an agent→client request with. */
53
+ permissionAnswers: () => { id: unknown; result: unknown }[];
54
+ /** Session ids the session asked the agent to delete. */
55
+ deletedSessions: () => string[];
50
56
  /** How many times a command or frame deferred the idle reclaim. */
51
57
  idleResets: () => number;
52
58
  /** Whether a destroy stopped the reclaim clock. */
@@ -106,6 +112,11 @@ export function mountSession(): MountedSession {
106
112
  // A config write; the default reply omits the list, which is the shape a
107
113
  // harness that ignores the protocol's "complete list" rule returns.
108
114
  setConfigOption: async (_sessionId: string, _configId: string, _value: string | boolean) => ({}),
115
+ deleteSession: async (sessionId: string) => {
116
+ deletes.push(sessionId);
117
+ return {};
118
+ },
119
+ respond: (id: string | number, result: unknown) => answers.push({ id, result }),
109
120
  dispose: async () => {},
110
121
  isAlive: true,
111
122
  };
@@ -124,6 +135,9 @@ export function mountSession(): MountedSession {
124
135
  },
125
136
  });
126
137
  const marks: string[] = [];
138
+ const markFailures: Array<string | null> = [];
139
+ const answers: { id: unknown; result: unknown }[] = [];
140
+ const deletes: string[] = [];
127
141
  const eventSink = new SessionListeners();
128
142
  eventSink.add((event) => events.push(event));
129
143
  let background: BackgroundProbeStub = {
@@ -132,8 +146,9 @@ export function mountSession(): MountedSession {
132
146
  consume: () => false,
133
147
  };
134
148
  Object.assign(session as unknown as Record<string, unknown>, {
135
- markStream: (status: string) => {
149
+ markStream: (status: string, failure?: string | null) => {
136
150
  marks.push(status);
151
+ markFailures.push(failure ?? null);
137
152
  },
138
153
  harness: 'opencode',
139
154
  cwd: '/tmp',
@@ -163,6 +178,9 @@ export function mountSession(): MountedSession {
163
178
  turn,
164
179
  turnEnds: () => turnEndCount,
165
180
  streamMarks: () => marks,
181
+ streamMarkFailures: () => markFailures,
182
+ permissionAnswers: () => answers,
183
+ deletedSessions: () => deletes,
166
184
  idleResets: () => idleResets,
167
185
  idleStopped: () => idleStopped,
168
186
  setBackground: (probe) => {
@@ -23,7 +23,7 @@
23
23
  import { AcpProcess } from '@/server/lib/harness/acp/client';
24
24
  import { AcpTurns, type AcpTurnEndInfo } from '@/server/lib/harness/acp/turn';
25
25
  import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
26
- import type { AcpConfigOption, AcpId } from '@/server/lib/harness/acp/protocol';
26
+ import type { AcpConfigOption, AcpId, AcpProtocolVersion, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
27
27
  import { promptBlocks } from '@/server/lib/harness/acp/prompt';
28
28
  import { withGatewayCompatibility } from '@/server/lib/harness/acp/gateway-env';
29
29
  import { adoptConfigAnswer, publishConfigChange, settlePermissionDialog, stampMessageModel } from '@/server/lib/harness/acp/session-config';
@@ -32,9 +32,10 @@ import { driveAcpGoalAfterTurn } from '@/server/lib/harness/acp/acp-goal-driver.
32
32
  import { handshakeAcpSession } from '@/server/lib/harness/acp/session-handshake';
33
33
  import { capabilitiesFrom } from '@/server/lib/harness/launch';
34
34
  import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
35
+ import { cancelAllAcpPermissions } from '@/server/lib/harness/acp/session-permissions';
35
36
  import { handleSessionNotification } from '@/server/lib/harness/acp/session-notifications';
36
37
  import { AcpUsageMeter, type AcpContextUsage } from '@/server/lib/harness/acp/session-usage';
37
- import { handleAcpClientRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
38
+ import { handleAcpClientRequest, handleAcpCancelRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
38
39
  import { acpExitFailureFrames } from '@/server/lib/harness/acp/session-exit';
39
40
  import { SessionListeners } from '@/server/lib/harness/acp/session-listeners';
40
41
  import {
@@ -64,13 +65,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
64
65
  /** The turn in flight — the only one whose frames are accepted. */
65
66
  private readonly turns: AcpTurns;
66
67
  runModel: { provider: string; modelId: string } | null = null;
67
- /** The agent's own slash-command list, from `available_commands_update`; the
68
- * composer's `/` pool reads it for this session (omp's utility child answers
69
- * that question for the RPC transport). */
68
+ /** The agent's own slash-command list; the composer's `/` pool reads it. */
70
69
  agentCommands: { name: string; description?: string; inputHint?: string }[] = [];
71
- /** The agent's plan entries from `session/update plan`, as published. The
72
- * Todos panel renders them through the same payload omp's transcript
73
- * snapshot produces. */
70
+ /** The agent's plan entries, published for the Todos panel. */
74
71
  planEntries: unknown[] = [];
75
72
  /** Messages this session has moved: prompts sent plus assistant messages the
76
73
  * mapper closed. omp reports the same quantity from its transcript. */
@@ -81,22 +78,17 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
81
78
  assistantCount = 0;
82
79
  /** The last `usage_update` the agent reported, or null when it never did. */
83
80
  private readonly usage = new AcpUsageMeter();
84
-
85
- get contextUsage(): AcpContextUsage | null {
86
- return this.usage.contextUsage;
87
- }
88
-
89
- get totalCost(): number {
90
- return this.usage.totalCost;
91
- }
92
-
93
- get usageTokens(): number {
94
- return this.usage.usageTokens;
95
- }
81
+ get contextUsage(): AcpContextUsage | null { return this.usage.contextUsage; }
82
+ get totalCost(): number { return this.usage.totalCost; }
83
+ get usageTokens(): number { return this.usage.usageTokens; }
96
84
  /** The composer's approval tier. Answered in-process by {@link onClientRequest}. */
97
85
  accessMode: ApprovalMode = DEFAULT_APPROVAL_MODE;
98
86
  capabilities: HarnessCapabilities = capabilitiesFrom({ protocolVersion: 1 }, [], { usage: false, plan: false });
99
87
  configOptions: AcpConfigOption[] = [];
88
+ /** The older Session Modes API, adopted when the agent publishes one. */
89
+ modes: AcpSessionModeState | null = null;
90
+ /** Whether the agent advertised `promptCapabilities.image`. */
91
+ acceptsImages = false;
100
92
  private readonly proc: AcpProcess;
101
93
  /** The quiet-window reclaim; the rules live in `session-idle.ts`. */
102
94
  readonly idle: IdleReaper;
@@ -107,9 +99,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
107
99
  readonly permissions = new PendingPermissions();
108
100
  private destroyHook: (() => void) | null = null;
109
101
  private destroyed = false;
110
- /** Set when Kabmo is the one ending the process, so the exit is not reported
111
- * as an agent failure. `force_reset` is the Stop button's escalation, and the
112
- * user must not get an "agent exited" error for a stop they asked for. */
102
+ /** Set when Kabmo ends the process, so a requested stop is not reported as a failure. */
113
103
  private closing = false;
114
104
 
115
105
  constructor(options: AcpSessionOptions, cwd: string) {
@@ -173,33 +163,16 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
173
163
  return { sessionId: this.sessionId };
174
164
  }
175
165
 
176
- isAlive(): boolean {
177
- return !this.destroyed && this.proc.isAlive;
178
- }
179
-
180
- get isStreaming(): boolean {
181
- return this.turns.isStreaming;
182
- }
183
-
184
- get isPromptRunning(): boolean {
185
- return this.turns.isPromptRunning;
186
- }
187
-
188
- isRunning(): boolean {
189
- return this.isAlive() && (this.turns.isPromptRunning || this.turns.isStreaming);
190
- }
191
-
192
- isBusy(): boolean {
193
- return this.isRunning() || this.permissions.size() > 0;
194
- }
195
-
196
- onEvent(listener: (event: AgentEvent) => void): () => void {
197
- return this.events.add(listener);
198
- }
199
-
200
- emit(event: AgentEvent): void {
201
- this.events.emit(event);
202
- }
166
+ get protocol(): AcpProtocolVersion { return this.proc.protocolVersion === 2 ? 2 : 1; }
167
+ /** Set by the handshake as soon as `initialize` answers. */
168
+ onProtocol(version: AcpProtocolVersion): void { this.turns.completion = version === 2 ? 'state' : 'response'; }
169
+ isAlive(): boolean { return !this.destroyed && this.proc.isAlive; }
170
+ get isStreaming(): boolean { return this.turns.isStreaming; }
171
+ get isPromptRunning(): boolean { return this.turns.isPromptRunning; }
172
+ isRunning(): boolean { return this.isAlive() && (this.turns.isPromptRunning || this.turns.isStreaming); }
173
+ isBusy(): boolean { return this.isRunning() || this.permissions.size() > 0; }
174
+ onEvent(listener: (event: AgentEvent) => void): () => void { return this.events.add(listener); }
175
+ emit(event: AgentEvent): void { this.events.emit(event); }
203
176
 
204
177
  getPendingUiDialogs(): Record<string, unknown>[] {
205
178
  // Widened for the shared `HarnessSession` contract, which predates the
@@ -232,9 +205,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
232
205
  * spinner and a reattaching tab's "still running" answer read. A field so a
233
206
  * unit test can stub it: the default writes the same row omp's dispatch writes.
234
207
  */
235
- markStream: (status: 'stream' | 'finish' | 'abort') => void = (status) => {
208
+ markStream: (status: 'stream' | 'finish' | 'abort', failure?: string | null) => void = (status, failure) => {
236
209
  if (!this.sessionId) return;
237
- void markStreamStatus(this.sessionId, status, status === 'stream' ? this.runModel : undefined).catch(() => {});
210
+ void markStreamStatus(this.sessionId, status, status === 'stream' ? this.runModel : undefined, failure).catch(() => {});
238
211
  };
239
212
 
240
213
  /** Turn-end bookkeeping the panels read — see `session-turns.ts`. A cancelled
@@ -253,10 +226,11 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
253
226
  void driveAcpGoalAfterTurn(this, info.message, { cancelled: info.cancelled === true }).catch(() => {});
254
227
  }
255
228
 
256
- /** Dispatcher seam: stop the turn. The rules live in `AcpTurns.cancel`. */
229
+ /** Dispatcher seam: stop the turn and answer every parked approval. */
257
230
  cancelTurn(): void {
258
231
  this.background.stop();
259
232
  this.turns.cancel();
233
+ cancelAllAcpPermissions(this.permissions, this.proc);
260
234
  }
261
235
 
262
236
  /** Dispatcher seam: adopt the composer's access pick. ACP answers approvals
@@ -268,12 +242,25 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
268
242
  /** Dispatcher seam: write one config selector and adopt the answer — see
269
243
  * `session-config.ts` for why the AGENT's resolved value is what is kept. */
270
244
  async setConfig(configId: string, value: string | boolean): Promise<unknown> {
245
+ // The synthesized selector `webState()` publishes for an agent that speaks
246
+ // only `modes`; there is no config option to write, so the mode verb is.
247
+ if (configId === 'mode' && typeof value === 'string' && !this.configOptions.some((option) => option.id === 'mode') && this.modes) {
248
+ return this.setMode(value);
249
+ }
271
250
  const result = await this.proc.setConfigOption(this.sessionId, configId, value);
272
251
  adoptConfigAnswer(this, result, { configId, value });
273
252
  publishConfigChange(this, configId);
274
253
  return result;
275
254
  }
276
255
 
256
+ /** `session/set_mode`: the pre-config-options way to move a mode. */
257
+ async setMode(modeId: string): Promise<unknown> {
258
+ const result = await this.proc.setMode(this.sessionId, modeId);
259
+ if (this.modes) this.modes = { ...this.modes, currentModeId: modeId };
260
+ this.emit({ type: 'mode_changed', modeId });
261
+ return result;
262
+ }
263
+
277
264
  /** Dispatcher seam: answer a pending approval dialog. Every exit answers the
278
265
  * agent — a silent return would hang it (see `session-config.ts`). */
279
266
  resolvePermission(dialogId: string, confirmed: boolean): unknown {
@@ -281,9 +268,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
281
268
  return null;
282
269
  }
283
270
 
284
- webState(): Record<string, unknown> {
285
- return acpWebState(this);
286
- }
271
+ webState(): Record<string, unknown> { return acpWebState(this); }
287
272
 
288
273
  /** Run one turn. The promise IS the turn: ACP resolves `session/prompt` when
289
274
  * the agent is done, so the reply is awaited for its whole duration. The ACK,
@@ -291,6 +276,11 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
291
276
  * `session-turns.ts`.
292
277
  */
293
278
  startTurn(message: string, images: unknown): unknown {
279
+ // ACP's prompt capabilities are a MUST: an agent that did not advertise
280
+ // `image` has to be told, not sent blocks its dispatcher rejects.
281
+ if (!this.acceptsImages && Array.isArray(images) && images.length > 0) {
282
+ throw new Error(`This harness does not accept image attachments (${this.harness})`);
283
+ }
294
284
  // A new prompt is the next request, so the agent flushes any held update
295
285
  // itself; a probe would duplicate it.
296
286
  this.background.stop();
@@ -302,6 +292,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
302
292
  private onNotification(method: string, params: Record<string, unknown>): void {
303
293
  // A long turn emits no commands but plenty of `session/update` frames.
304
294
  this.idle.reset();
295
+ // `$/cancel_request` names an agent→client request the agent no longer
296
+ // wants; the approval it parks is answered `cancelled`.
297
+ if (handleAcpCancelRequest(this, method, params)) return;
305
298
  // A `session/load` replay repeats the whole chat; leave it to the probe.
306
299
  if (this.background.consume(method, params)) return;
307
300
  handleSessionNotification(this, method, params);
@@ -310,9 +303,10 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
310
303
  absorbUsage(update: Record<string, unknown>): void { this.usage.absorb(update); }
311
304
  resetUsageTokens(): void { this.usage.reset(); }
312
305
  acceptingFrames(): boolean { return this.turns.acceptingFrames(); }
313
-
314
306
  mapUpdate(update: Record<string, unknown>): AgentEvent[] { return this.mapper.mapUpdate(update); }
315
-
307
+ onStateUpdate(update: Record<string, unknown>): void { this.turns.onStateUpdate(update); }
308
+ /** Answer an agent→client request with a result (cancellation uses it). */
309
+ respond(id: AcpId, result: unknown): void { this.proc.respond(id, result); }
316
310
  /** Agent→client requests: every branch answers or refuses — an unanswered call parks the turn. */
317
311
  private onClientRequest(
318
312
  id: AcpId,
@@ -333,8 +327,14 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
333
327
  this.destroyHook?.();
334
328
  }
335
329
 
336
- destroy(): void {
337
- void this.destroyAndWait();
330
+ destroy(): void { void this.destroyAndWait(); }
331
+
332
+ /** Remove this chat from the agent's own history, when it offers the method. */
333
+ async deleteAgentSession(): Promise<void> {
334
+ if (!this.sessionId || !this.capabilities.deleteSession) return;
335
+ await this.proc.deleteSession(this.sessionId, 10_000).catch((error: unknown) => {
336
+ console.error(`[harness] could not delete ${this.harness} session ${this.sessionId}:`, error);
337
+ });
338
338
  }
339
339
 
340
340
  async destroyAndWait(): Promise<void> {