@kabmo-labs/kabmo 0.24.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +585 -512
  3. package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
  4. package/dist/client/static/js/index-p2yw9ywf.css +1 -0
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  13. package/src/client/components/common/code-surface/shiki.ts +28 -7
  14. package/src/client/components/common/session-actions-menu/index.tsx +59 -2
  15. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  16. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  17. package/src/client/components/common/session-branch/index.tsx +169 -0
  18. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  19. package/src/client/components/common/session-branch/style.ts +29 -0
  20. package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
  21. package/src/client/components/common/session-row/index.tsx +28 -3
  22. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  23. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  24. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  25. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
  26. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  27. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  28. package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
  29. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
  31. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
  32. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  33. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
  34. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
  35. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
  36. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
  37. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
  38. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  39. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
  40. package/src/client/components/settings/Sidebar.tsx +1 -1
  41. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  42. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  43. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  44. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  45. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  46. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  47. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  48. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
  49. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  50. package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
  51. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
  52. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  53. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  55. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  56. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  58. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  59. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  60. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  61. package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
  62. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
  63. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  64. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  65. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  66. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  67. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  68. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  69. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  70. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  71. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  72. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  73. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  74. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  75. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  76. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  77. package/src/client/data/settings/omp-schema.json +1 -1
  78. package/src/client/data/theme/terminal.test.ts +25 -0
  79. package/src/client/data/theme/terminal.ts +96 -79
  80. package/src/client/hooks/chat/composer/items.test.ts +31 -26
  81. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  82. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  83. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  84. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  85. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  86. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  87. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  88. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  89. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  90. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  91. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  92. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  93. package/src/client/hooks/chat/omp/session-list.tsx +4 -0
  94. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  95. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  96. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  97. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  98. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  99. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  100. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  101. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  102. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  103. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  104. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  105. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  106. package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
  107. package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
  108. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  109. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  110. package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
  111. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  112. package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
  113. package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
  114. package/src/client/hooks/chat/timeline/send.test.ts +3 -1
  115. package/src/client/hooks/chat/timeline/send.ts +48 -133
  116. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  117. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  118. package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
  119. package/src/client/hooks/models/use-harness-update.test.ts +286 -0
  120. package/src/client/hooks/models/use-harness-update.ts +250 -0
  121. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  122. package/src/client/hooks/ui/notifications.ts +45 -0
  123. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  124. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  125. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  126. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  127. package/src/client/lib/native/open-session.ts +33 -0
  128. package/src/client/lib/notifications/os.test.ts +125 -0
  129. package/src/client/lib/notifications/os.ts +130 -0
  130. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  131. package/src/client/lib/router/open-session.test.ts +75 -0
  132. package/src/client/lib/router/open-session.ts +34 -0
  133. package/src/client/lib/session-tree.test.ts +50 -0
  134. package/src/client/lib/session-tree.ts +59 -0
  135. package/src/client/lib/signals.ts +5 -1
  136. package/src/client/main.tsx +6 -0
  137. package/src/client/tailwind.css +17 -11
  138. package/src/server/index.ts +2 -0
  139. package/src/server/lib/auth/guard.ts +10 -0
  140. package/src/server/lib/btw/session-copy.server.ts +6 -44
  141. package/src/server/lib/btw/session-copy.test.ts +2 -1
  142. package/src/server/lib/db/schema.ts +5 -0
  143. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  144. package/src/server/lib/db/seed.test.ts +1 -1
  145. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  146. package/src/server/lib/harness/acp/background-work.ts +320 -0
  147. package/src/server/lib/harness/acp/calls.ts +15 -1
  148. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  149. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  150. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  151. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  152. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  153. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  154. package/src/server/lib/harness/acp/client.ts +33 -23
  155. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  156. package/src/server/lib/harness/acp/commands.ts +14 -2
  157. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  158. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  159. package/src/server/lib/harness/acp/frames.ts +71 -158
  160. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  161. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  162. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  163. package/src/server/lib/harness/acp/mapper.ts +12 -0
  164. package/src/server/lib/harness/acp/permissions.ts +6 -0
  165. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  166. package/src/server/lib/harness/acp/prompt.ts +19 -3
  167. package/src/server/lib/harness/acp/protocol.ts +41 -2
  168. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  169. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  170. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  171. package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
  172. package/src/server/lib/harness/acp/session-handshake.ts +110 -7
  173. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  174. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  175. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  176. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  177. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  178. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  179. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  180. package/src/server/lib/harness/acp/session-requests.ts +89 -0
  181. package/src/server/lib/harness/acp/session-turns.ts +28 -8
  182. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  183. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  184. package/src/server/lib/harness/acp/session.test-util.ts +42 -2
  185. package/src/server/lib/harness/acp/session.ts +115 -115
  186. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  187. package/src/server/lib/harness/acp/turn.test.ts +183 -0
  188. package/src/server/lib/harness/acp/turn.ts +102 -10
  189. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  190. package/src/server/lib/harness/acp/v2.ts +220 -0
  191. package/src/server/lib/harness/acp/verbs.ts +58 -8
  192. package/src/server/lib/harness/launch.test.ts +25 -0
  193. package/src/server/lib/harness/launch.ts +24 -10
  194. package/src/server/lib/harness/session.ts +3 -0
  195. package/src/server/lib/harness/spawn.server.ts +15 -2
  196. package/src/server/lib/harness/update-job-store.test.ts +151 -0
  197. package/src/server/lib/harness/update-job-store.ts +115 -0
  198. package/src/server/lib/harness/update-job.server.ts +94 -0
  199. package/src/server/lib/harness/update-queue.server.ts +292 -0
  200. package/src/server/lib/harness/update-queue.test.ts +265 -0
  201. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  202. package/src/server/lib/harness/update-worker.test.ts +153 -0
  203. package/src/server/lib/harness/update-worker.ts +202 -0
  204. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  205. package/src/server/lib/lifecycle/paths.ts +28 -0
  206. package/src/server/lib/omp/rpc/manager.ts +5 -5
  207. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  208. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  209. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  210. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  211. package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
  212. package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
  213. package/src/server/lib/omp/session/delete.server.ts +5 -0
  214. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  215. package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
  216. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  217. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  218. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  219. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  220. package/src/server/lib/sessions/answers.server.ts +37 -0
  221. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  222. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  223. package/src/server/lib/sessions/fork.server.test.ts +277 -0
  224. package/src/server/lib/sessions/fork.server.ts +329 -0
  225. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  226. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  227. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  228. package/src/server/lib/sessions/notify.server.ts +212 -0
  229. package/src/server/lib/sessions/relation-types.ts +76 -0
  230. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  231. package/src/server/lib/sessions/relations.server.ts +337 -0
  232. package/src/server/lib/sessions/resolve.server.ts +106 -0
  233. package/src/server/lib/sessions/schema.server.ts +82 -0
  234. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  235. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  236. package/src/server/lib/sessions/spawn.server.test.ts +237 -0
  237. package/src/server/lib/sessions/spawn.server.ts +335 -0
  238. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  239. package/src/server/lib/terminal/output.test.ts +2 -2
  240. package/src/server/lib/terminal/output.ts +1 -1
  241. package/src/server/lib/terminal/resize.test.ts +99 -0
  242. package/src/server/lib/terminal/runtime.server.ts +26 -6
  243. package/src/server/lib/terminal/send-result.test.ts +18 -1
  244. package/src/server/lib/terminal/send-result.ts +26 -2
  245. package/src/server/lib/terminal/session.server.ts +6 -6
  246. package/src/server/lib/usage/new-api.test.ts +92 -0
  247. package/src/server/lib/usage/new-api.ts +131 -0
  248. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  249. package/src/server/lib/usage/provider-key.ts +33 -0
  250. package/src/server/lib/usage/providers.server.ts +10 -3
  251. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  252. package/src/server/lib/usage/vendor-http.ts +41 -0
  253. package/src/server/lib/usage/window.ts +55 -0
  254. package/src/server/routes/agent/command.ts +14 -1
  255. package/src/server/routes/agent/harness-command.ts +12 -5
  256. package/src/server/routes/agent/new.ts +15 -0
  257. package/src/server/routes/chat/stream.ts +7 -2
  258. package/src/server/routes/harness/add-provider.test.ts +9 -1
  259. package/src/server/routes/harness/import-action.ts +4 -0
  260. package/src/server/routes/harness/import.test.ts +1 -1
  261. package/src/server/routes/harness/index.ts +5 -1
  262. package/src/server/routes/harness/update-status.ts +32 -0
  263. package/src/server/routes/harness/update.test.ts +156 -0
  264. package/src/server/routes/harness/update.ts +64 -147
  265. package/src/server/routes/sessions/answer.ts +24 -0
  266. package/src/server/routes/sessions/batch-delete.ts +11 -5
  267. package/src/server/routes/sessions/body-readers.ts +43 -0
  268. package/src/server/routes/sessions/delete.ts +4 -2
  269. package/src/server/routes/sessions/fork.ts +89 -0
  270. package/src/server/routes/sessions/index.ts +14 -0
  271. package/src/server/routes/sessions/relations.ts +85 -0
  272. package/src/server/routes/sessions/routes.test.ts +1 -2
  273. package/src/server/routes/sessions/session.ts +23 -0
  274. package/src/server/routes/sessions/spawn.ts +137 -0
  275. package/src/server/routes/terminal/ws.ts +3 -3
  276. package/src/shared/lib/chat/composer/client.ts +31 -2
  277. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  278. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  279. package/src/shared/lib/chat/notice-text.ts +1 -1
  280. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  281. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  282. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  283. package/src/shared/lib/code/ansi.ts +1 -1
  284. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  285. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  286. package/src/shared/lib/harness/mode-signal.ts +20 -0
  287. package/src/shared/lib/harness/provider-facts.test.ts +27 -0
  288. package/src/shared/lib/harness/providers.ts +35 -1
  289. package/src/shared/lib/harness/session-modes.ts +24 -0
  290. package/src/shared/lib/harness/update-job.ts +80 -0
  291. package/src/shared/lib/harness/update-plan.test.ts +21 -6
  292. package/src/shared/lib/harness/update-plan.ts +12 -4
  293. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  294. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  295. package/src/shared/lib/notifications/outcomes.ts +64 -0
  296. package/src/shared/lib/notifications/settings.test.ts +49 -0
  297. package/src/shared/lib/notifications/settings.ts +34 -0
  298. package/src/shared/lib/omp/session/default-title.ts +5 -4
  299. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  300. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  301. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  302. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  303. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  304. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  305. package/src/shared/lib/settings/defaults.ts +3 -0
  306. package/src/shared/lib/theme/catalog.test.ts +13 -9
  307. package/src/shared/lib/theme/color.test.ts +2 -2
  308. package/src/shared/lib/theme/color.ts +4 -4
  309. package/src/shared/lib/theme/theme.test.ts +1 -1
  310. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  311. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  312. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  313. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  314. package/src/shared/types/chat.ts +1 -1
  315. package/src/shared/types/harness-update.ts +89 -0
  316. package/src/shared/types/omp/agent.ts +19 -2
  317. package/src/shared/types/realtime.ts +2 -0
  318. package/src/shared/types/settings/state.ts +10 -0
  319. package/src/shared/types/workspace.ts +8 -0
  320. package/src/test-support/fake-omp-fork.ts +16 -2
  321. package/src/test-support/harness-table.test-util.ts +31 -1
  322. package/dist/client/static/js/index-z3w7n85q.css +0 -1
  323. package/src/client/components/common/subagent-list/index.tsx +0 -165
  324. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  325. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -0,0 +1,320 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Work an ACP agent keeps doing AFTER it has answered `session/prompt`.
8
+ *
9
+ * antigravity's `invoke_subagent` returns immediately: the tool call is marked
10
+ * `completed`, the agent says "sedang membuatkan…", and `session/prompt`
11
+ * resolves with `end_turn` while the subagent is still running. Measured on agy
12
+ * 1.5.3, the subagent's later completion and the agent's follow-up answer are
13
+ * written to its transcript but **no `session/update` frame is sent while the
14
+ * connection is idle**; the frames are held until the next request (upstream
15
+ * issue google-antigravity/antigravity-cli#1461). The operator then sees a
16
+ * stopped chat with no notice.
17
+ *
18
+ * `session/load` is the one request that replays that transcript, so the turn
19
+ * that spawned the subagent is followed by a load probe: replay frames are
20
+ * collected instead of folded (they repeat the whole chat), and the text past
21
+ * the answer the operator already has is emitted as the agent's continuation.
22
+ *
23
+ * The probe backs off (2s → 30s) and gives up after ten minutes; it never
24
+ * substitutes a failure for an answer it did not see.
25
+ */
26
+
27
+ import { acpContentText } from '@/server/lib/harness/acp/mapper';
28
+ import { stampMessageModel } from '@/server/lib/harness/acp/session-config';
29
+ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
30
+ import { extractTextFromContent } from '@/shared/lib/omp/session/mapper';
31
+ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
32
+
33
+ /** Tool names that hand work to a process the turn does not await. */
34
+ const BACKGROUND_TOOLS: Record<string, true> = {
35
+ invoke_subagent: true,
36
+ spawn_subagent: true,
37
+ };
38
+
39
+ export const BACKGROUND_FIRST_DELAY_MS = 2_000;
40
+ export const BACKGROUND_MAX_DELAY_MS = 30_000;
41
+ export const BACKGROUND_TIMEOUT_MS = 10 * 60_000;
42
+ export const BACKGROUND_LOAD_TIMEOUT_MS = 120_000;
43
+
44
+ /** Did this turn hand work to a background worker? Read from the closed
45
+ * assistant message, which is the only place the tool call survives. */
46
+ export function spawnsBackgroundWork(message: unknown): boolean {
47
+ if (!message || typeof message !== 'object' || !('content' in message)) return false;
48
+ const content = message.content;
49
+ if (!Array.isArray(content)) return false;
50
+ return content.some((block) => {
51
+ if (!block || typeof block !== 'object') return false;
52
+ if (!('type' in block) || block.type !== 'toolCall') return false;
53
+ return 'name' in block && typeof block.name === 'string' && BACKGROUND_TOOLS[block.name.toLowerCase()] === true;
54
+ });
55
+ }
56
+
57
+ /** The prose the operator already has, for the suffix comparison. */
58
+ export function assistantTextOf(message: unknown): string {
59
+ if (!message || typeof message !== 'object' || !('content' in message)) return '';
60
+ return extractTextFromContent(message.content).trim();
61
+ }
62
+
63
+ /**
64
+ * The NEW assistant text in a replay, or null when it carries nothing past
65
+ * what the operator has already seen.
66
+ *
67
+ * A replay repeats the whole conversation, and a long conversation's earlier
68
+ * turns are not this turn's notice. Two guards keep the notice unique: the
69
+ * replay segment must extend the known text, and a replay that diverges from it
70
+ * (a retried prompt, a different agent's wording) is left alone rather than
71
+ * guessed at.
72
+ */
73
+ export function backgroundNotice(baseline: string, replay: string): string | null {
74
+ const current = replay.trim();
75
+ if (!current) return null;
76
+ const known = baseline.trim();
77
+ if (!known) return current;
78
+ if (!current.startsWith(known)) return null;
79
+ const extra = current.slice(known.length).trim();
80
+ return extra.length > 0 ? extra : null;
81
+ }
82
+
83
+ /** The frames a delayed answer is delivered with. It is a complete run: the
84
+ * client's fold only clears its generating flag on a terminal `agent_end`. */
85
+ export function backgroundNoticeFrames(text: string): AgentEvent[] {
86
+ const message = {
87
+ role: 'assistant',
88
+ id: `acp-bg-${crypto.randomUUID()}`,
89
+ content: [{ type: 'text', text }],
90
+ };
91
+ return [
92
+ { type: 'agent_start' },
93
+ { type: 'turn_start' },
94
+ {
95
+ type: 'message_update',
96
+ message,
97
+ assistantMessageEvent: { type: 'text_delta', delta: text },
98
+ },
99
+ { type: 'message_end', message },
100
+ { type: 'agent_end', isTerminal: true, stopReason: 'end_turn' },
101
+ ];
102
+ }
103
+
104
+ /** What the session must move when the probe hands it the delayed answer. */
105
+ export interface BackgroundNoticeHost {
106
+ sessionId: string;
107
+ runModel: { provider: string; modelId: string } | null;
108
+ messageCount: number;
109
+ assistantCount: number;
110
+ emit: (event: AgentEvent) => void;
111
+ }
112
+
113
+ export function deliverBackgroundNotice(host: BackgroundNoticeHost, text: string): void {
114
+ host.messageCount += 1;
115
+ host.assistantCount += 1;
116
+ for (const event of backgroundNoticeFrames(text)) {
117
+ host.emit(stampMessageModel(event, host.runModel));
118
+ }
119
+ emitRealtimeSignal('session-data-dirty', host.sessionId);
120
+ }
121
+
122
+ export interface AcpBackgroundProbeOptions {
123
+ /** Replay the session — `session/load` on the live process. */
124
+ load: () => Promise<unknown>;
125
+ /** A probe is a sign the session is still wanted. */
126
+ resetIdle: () => void;
127
+ /** The text past the answer already shown. */
128
+ emit: (text: string) => void;
129
+ timeoutMs?: number;
130
+ firstDelayMs?: number;
131
+ maxDelayMs?: number;
132
+ now?: () => number;
133
+ schedule?: (fn: () => void, ms: number) => unknown;
134
+ cancel?: (handle: unknown) => void;
135
+ }
136
+
137
+ /** Replay chunks collected since the last `user_message_chunk`. */
138
+ interface ReplaySegment {
139
+ text: string;
140
+ sawUser: boolean;
141
+ }
142
+
143
+ /**
144
+ * The load probe for one background turn.
145
+ *
146
+ * `consume` must be called for every notification while a probe is in flight:
147
+ * the replay repeats the whole transcript, and folding it into the live chat
148
+ * would duplicate history.
149
+ */
150
+ export class AcpBackgroundProbe {
151
+ private readonly load: () => Promise<unknown>;
152
+ private readonly resetIdle: () => void;
153
+ private readonly emitNotice: (text: string) => void;
154
+ private readonly timeoutMs: number;
155
+ private readonly firstDelayMs: number;
156
+ private readonly maxDelayMs: number;
157
+ private readonly now: () => number;
158
+ private readonly schedule: (fn: () => void, ms: number) => unknown;
159
+ private readonly cancel: (handle: unknown) => void;
160
+
161
+ private baseline = '';
162
+ private collecting: ReplaySegment | null = null;
163
+ /** The notice seen in the last replay; a repeated value is COMPLETE. */
164
+ private pendingNotice: string | null = null;
165
+ private timer: unknown = null;
166
+ private deadline = 0;
167
+ private delay: number;
168
+ private stopped = true;
169
+ private inFlight = false;
170
+ /** Consecutive `session/load` failures; a lost agent is not retried forever. */
171
+ private failures = 0;
172
+ private queued: string | null = null;
173
+
174
+ constructor(options: AcpBackgroundProbeOptions) {
175
+ this.load = options.load;
176
+ this.resetIdle = options.resetIdle;
177
+ this.emitNotice = options.emit;
178
+ this.timeoutMs = options.timeoutMs ?? BACKGROUND_TIMEOUT_MS;
179
+ this.firstDelayMs = options.firstDelayMs ?? BACKGROUND_FIRST_DELAY_MS;
180
+ this.maxDelayMs = options.maxDelayMs ?? BACKGROUND_MAX_DELAY_MS;
181
+ this.now = options.now ?? Date.now;
182
+ this.schedule = options.schedule ?? defaultSchedule;
183
+ this.cancel = options.cancel ?? defaultCancel;
184
+ this.delay = this.firstDelayMs;
185
+ }
186
+
187
+ /** Watch for the delayed answer to a turn that spawned background work. */
188
+ start(baseline: string): void {
189
+ this.baseline = baseline.trim();
190
+ this.pendingNotice = null;
191
+ // A previous probe's load can still be running. Queue this turn instead of
192
+ // interleaving two replays; the queued baseline starts when that load ends.
193
+ if (this.inFlight) {
194
+ this.queued = this.baseline;
195
+ return;
196
+ }
197
+ this.stopped = false;
198
+ this.deadline = this.now() + this.timeoutMs;
199
+ this.delay = this.firstDelayMs;
200
+ this.failures = 0;
201
+ this.arm();
202
+ }
203
+
204
+ stop(): void {
205
+ this.stopped = true;
206
+ this.queued = null;
207
+ this.pendingNotice = null;
208
+ if (this.timer !== null) {
209
+ this.cancel(this.timer);
210
+ this.timer = null;
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Swallow one replay notification. Returns true when the notification is part
216
+ * of a probe and must not reach the live session: a replay repeats the whole
217
+ * conversation, so folding it would open rows the operator already has.
218
+ */
219
+ consume(method: string, params: Record<string, unknown>): boolean {
220
+ if (!this.collecting || method !== 'session/update') return false;
221
+ const update = params.update;
222
+ if (!update || typeof update !== 'object') return true;
223
+ const record = update as Record<string, unknown>;
224
+ const kind = typeof record.sessionUpdate === 'string' ? record.sessionUpdate : '';
225
+ if (kind === 'user_message_chunk') {
226
+ // A new user turn starts a new assistant segment. Everything before it is
227
+ // history this probe does not need.
228
+ this.collecting.text = '';
229
+ this.collecting.sawUser = true;
230
+ return true;
231
+ }
232
+ if (kind === 'agent_message_chunk') {
233
+ this.collecting.text += acpContentText(record.content);
234
+ }
235
+ return true;
236
+ }
237
+
238
+ private arm(): void {
239
+ if (this.stopped) return;
240
+ this.timer = this.schedule(() => {
241
+ this.timer = null;
242
+ void this.probe();
243
+ }, this.delay);
244
+ }
245
+
246
+ private async probe(): Promise<void> {
247
+ if (this.stopped || this.inFlight) return;
248
+ this.inFlight = true;
249
+ this.collecting = { text: '', sawUser: false };
250
+ this.resetIdle();
251
+ let failed = false;
252
+ try {
253
+ await this.load();
254
+ } catch {
255
+ // The agent may be gone or refuse `session/load`; a probe never reports
256
+ // that as a turn failure. Stop rather than spinning against it.
257
+ failed = true;
258
+ } finally {
259
+ this.inFlight = false;
260
+ }
261
+ const segment = this.collecting;
262
+ this.collecting = null;
263
+
264
+ if (this.stopped) {
265
+ // A new prompt or a Stop already claimed the session; its own request is
266
+ // what flushes the agent's held update.
267
+ } else if (failed) {
268
+ // A parked permission can outlive the load's request budget. Retry a few
269
+ // times so approving the dialog still lets the notice through; a child
270
+ // that really exited is stopped by `stop()` from the session's exit hook.
271
+ this.failures += 1;
272
+ if (this.failures >= 3 || this.now() >= this.deadline) {
273
+ this.stopped = true;
274
+ } else {
275
+ this.delay = Math.min(this.delay * 2, this.maxDelayMs);
276
+ this.arm();
277
+ }
278
+ } else {
279
+ this.failures = 0;
280
+ // A replay that never reached a user chunk cannot be placed in the
281
+ // conversation, so it is not a notice.
282
+ const notice = segment?.sawUser ? backgroundNotice(this.baseline, segment.text) : null;
283
+ if (notice !== null) {
284
+ // The agent may still be writing: the first replay of a growing answer
285
+ // is a PREFIX. Emit only once a replay repeats the same text, which is
286
+ // the only completion signal ACP gives a replay.
287
+ const stable = notice === this.pendingNotice;
288
+ this.pendingNotice = notice;
289
+ if (stable || this.now() >= this.deadline) {
290
+ this.emitNotice(notice);
291
+ this.stopped = true;
292
+ } else {
293
+ this.delay = this.firstDelayMs;
294
+ this.arm();
295
+ }
296
+ } else if (this.now() >= this.deadline) {
297
+ this.stopped = true;
298
+ } else {
299
+ this.delay = Math.min(this.delay * 2, this.maxDelayMs);
300
+ this.arm();
301
+ }
302
+ }
303
+
304
+ if (this.queued !== null) {
305
+ const baseline = this.queued;
306
+ this.queued = null;
307
+ this.start(baseline);
308
+ }
309
+ }
310
+ }
311
+
312
+ function defaultSchedule(fn: () => void, ms: number): unknown {
313
+ const handle = setTimeout(fn, ms);
314
+ handle.unref?.();
315
+ return handle;
316
+ }
317
+
318
+ function defaultCancel(handle: unknown): void {
319
+ clearTimeout(handle as NodeJS.Timeout);
320
+ }
@@ -18,6 +18,18 @@
18
18
 
19
19
  import type { AcpId, AcpResponse } from '@/server/lib/harness/acp/protocol';
20
20
 
21
+ /** A JSON-RPC error answer, with the code the spec defines for it. */
22
+ export class AcpRequestError extends Error {
23
+ constructor(
24
+ message: string,
25
+ readonly code: number,
26
+ readonly data?: unknown,
27
+ ) {
28
+ super(message);
29
+ this.name = 'AcpRequestError';
30
+ }
31
+ }
32
+
21
33
  export interface Pending {
22
34
  resolve: (value: unknown) => void;
23
35
  reject: (error: Error) => void;
@@ -60,8 +72,10 @@ export class PendingCalls {
60
72
  this.map.delete(response.id);
61
73
  clearTimeout(entry.timer);
62
74
  if (response.error) {
63
- entry.reject(new Error(
75
+ entry.reject(new AcpRequestError(
64
76
  `${response.error.message}${response.error.data ? `: ${JSON.stringify(response.error.data)}` : ''}`,
77
+ response.error.code,
78
+ response.error.data,
65
79
  ));
66
80
  return true;
67
81
  }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The client's `initialize` advertisement and version negotiation.
8
+ *
9
+ * Both are promises made to the agent: the capability object says which
10
+ * agent→client calls this client will answer, and the answer to an unsupported
11
+ * protocol major has to be a refusal rather than a v2 frame parsed as v1.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+ import {
16
+ ACP_PROTOCOL_VERSION,
17
+ KABMO_CLIENT_CAPABILITIES,
18
+ assertProtocolVersion,
19
+ } from '@/server/lib/harness/acp/client-capabilities';
20
+
21
+ describe('client capabilities', () => {
22
+ test('advertises the fs methods the client actually implements', () => {
23
+ expect(KABMO_CLIENT_CAPABILITIES.fs).toEqual({ readTextFile: true, writeTextFile: true });
24
+ });
25
+
26
+ test('advertises notices, which the frame mapper already renders', () => {
27
+ expect(KABMO_CLIENT_CAPABILITIES.session.notices).toEqual({});
28
+ });
29
+
30
+ test('does not advertise surfaces with no bridge', () => {
31
+ const advertised = KABMO_CLIENT_CAPABILITIES as Record<string, unknown>;
32
+ expect(advertised.terminal).toBeUndefined();
33
+ expect(advertised.elicitation).toBeUndefined();
34
+ });
35
+ });
36
+
37
+ describe('protocol version negotiation', () => {
38
+ test('sends v2 as its latest version', () => {
39
+ expect(ACP_PROTOCOL_VERSION).toBe(2);
40
+ });
41
+
42
+ test('accepts both majors it implements', () => {
43
+ expect(() => assertProtocolVersion({ protocolVersion: 1 })).not.toThrow();
44
+ expect(() => assertProtocolVersion({ protocolVersion: 2 })).not.toThrow();
45
+ });
46
+
47
+ test('refuses a major it cannot speak, naming the agent and both versions', () => {
48
+ expect(() => assertProtocolVersion({ protocolVersion: 3, agentInfo: { title: 'Acme' } }))
49
+ .toThrow('Acme speaks ACP v3; Kabmo supports v1 and v2');
50
+ });
51
+
52
+ test('refuses an answer that reports no version at all', () => {
53
+ expect(() => assertProtocolVersion({})).toThrow('speaks ACP vundefined');
54
+ });
55
+ });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What Kabmo advertises as a **v1** ACP client at `initialize`.
8
+ *
9
+ * v2 removed the client fs and terminal execution APIs, so a v2 connection
10
+ * advertises `capabilities: {}` instead; the hybrid request in
11
+ * `client-initialize.ts` carries both field sets so a v1 peer still sees this
12
+ * object while a v2 peer ignores it as an unknown field.
13
+ *
14
+ * Every entry here is a promise the client answers itself, so the list is
15
+ * narrower than the protocol: an advertised capability the client cannot serve
16
+ * makes the agent park a turn on a call nobody answers (the failure mode
17
+ * `session-requests.ts` exists to prevent).
18
+ *
19
+ * - **fs** — `client-fs.ts` implements both methods against the session's
20
+ * workspace, so an agent that reads or writes through the client reaches the
21
+ * same files the user's editor is looking at.
22
+ * - **session.notices** — `AcpFrameMapper` already renders `notice` updates as
23
+ * notices; without the advertisement a spec-compliant agent had to model them
24
+ * as conversation text instead.
25
+ *
26
+ * Deliberately absent, each for a measured reason:
27
+ *
28
+ * - `terminal` — this client has no bridge that surfaces an ACP terminal's
29
+ * output in the timeline, and advertising it would route an agent's shell
30
+ * work through a terminal the user cannot see.
31
+ * - `elicitation` — no form/URL dialog exists yet; advertising it would make
32
+ * the agent block on an `elicitation/create` nobody draws.
33
+ * - `auth.terminal` — Kabmo does not reproduce the agent's launch line in an
34
+ * interactive terminal for login.
35
+ * - `session.configOptions.boolean` — the selector UI is select-only.
36
+ * - `session.compaction` — compaction updates have no renderer.
37
+ */
38
+ export const KABMO_CLIENT_CAPABILITIES = {
39
+ fs: { readTextFile: true, writeTextFile: true },
40
+ session: { notices: {} },
41
+ } as const;
42
+
43
+ /** The latest protocol major this client sends; it also speaks v1. */
44
+ export const ACP_PROTOCOL_VERSION = 2;
45
+
46
+ /** Every major this client implements. */
47
+ export const ACP_SUPPORTED_VERSIONS = [1, 2] as const;
48
+
49
+ /**
50
+ * Refuse an `initialize` answer this client cannot speak.
51
+ *
52
+ * Kabmo implements v1 and v2 side by side; a v1-only agent answers 1 and a v2
53
+ * agent answers 2. Anything else is a connection this client cannot parse.
54
+ */
55
+ export function assertProtocolVersion(result: { protocolVersion?: unknown; agentInfo?: { name?: string; title?: string } }): void {
56
+ if (result.protocolVersion === 1 || result.protocolVersion === 2) return;
57
+ const agent = result.agentInfo?.title ?? result.agentInfo?.name ?? 'The agent';
58
+ throw new Error(
59
+ `${agent} speaks ACP v${String(result.protocolVersion)}; Kabmo supports v1 and v2`,
60
+ );
61
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The ACP client's file surface.
8
+ *
9
+ * The cases that matter are the REFUSALS: an agent asking for a path outside the
10
+ * session's workspace must get `-32602`, not a read of the host's filesystem.
11
+ * The line window is pinned because ACP numbers lines from 1.
12
+ */
13
+
14
+ import { afterEach, describe, expect, test } from 'bun:test';
15
+ import { mkdtemp, rm, symlink } from 'node:fs/promises';
16
+ import { tmpdir } from 'node:os';
17
+ import { join } from 'node:path';
18
+ import { handleAcpFsRequest, isAcpFsMethod, type AcpFsHost } from '@/server/lib/harness/acp/client-fs';
19
+ import { testPosix } from '@/test-support/platform';
20
+ import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
21
+
22
+ const scratch: string[] = [];
23
+
24
+ async function workspace(): Promise<AcpFsHost> {
25
+ const cwd = await mkdtemp(join(tmpdir(), 'kabmo-acp-fs-'));
26
+ scratch.push(cwd);
27
+ return { cwd, sessionId: 's1' };
28
+ }
29
+
30
+ afterEach(async () => {
31
+ await Promise.all(scratch.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
32
+ });
33
+
34
+ describe('fs capability methods', () => {
35
+ test('recognises exactly the two methods it serves', () => {
36
+ expect(isAcpFsMethod('fs/read_text_file')).toBe(true);
37
+ expect(isAcpFsMethod('fs/write_text_file')).toBe(true);
38
+ expect(isAcpFsMethod('terminal/create')).toBe(false);
39
+ });
40
+ });
41
+
42
+ describe('fs/read_text_file', () => {
43
+ test('answers the whole file when no window is given', async () => {
44
+ const host = await workspace();
45
+ await Bun.write(join(host.cwd, 'a.txt'), 'one\ntwo\n');
46
+ const answer = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: join(host.cwd, 'a.txt') });
47
+ expect(answer).toEqual({ answered: true, result: { content: 'one\ntwo\n' } });
48
+ });
49
+
50
+ test('a line window is 1-based and counts limit lines', async () => {
51
+ const host = await workspace();
52
+ const file = join(host.cwd, 'a.txt');
53
+ await Bun.write(file, 'one\ntwo\nthree\nfour');
54
+ const second = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: file, line: 2, limit: 2 });
55
+ expect(second).toEqual({ answered: true, result: { content: 'two\nthree' } });
56
+ const tail = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: file, line: 3 });
57
+ expect(tail).toEqual({ answered: true, result: { content: 'three\nfour' } });
58
+ const past = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: file, line: 99 });
59
+ expect(past).toEqual({ answered: true, result: { content: '' } });
60
+ });
61
+
62
+ test('a missing file is -32002, the resource-not-found code', async () => {
63
+ const host = await workspace();
64
+ const answer = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: join(host.cwd, 'nope.txt') });
65
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.notFound });
66
+ });
67
+
68
+ test('a relative path is refused as invalid params', async () => {
69
+ const host = await workspace();
70
+ const answer = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: 'a.txt' });
71
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
72
+ });
73
+
74
+ test('a path outside the workspace is refused even when it exists', async () => {
75
+ const host = await workspace();
76
+ const answer = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: '/etc/hosts' });
77
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
78
+ });
79
+
80
+ // POSIX only: the fixture links to `/etc/hosts`, which does not exist on
81
+ // Windows, and creating a symlink there needs a privilege a default runner
82
+ // does not have. Measured on the Windows gate: the link was never made, so the
83
+ // handler answered `-32002 File not found` instead of the refusal under test —
84
+ // a failure about the fixture, not about the guard. The case ABOVE still runs
85
+ // there: an absolute path outside the workspace is refused before any read.
86
+ testPosix('a symlink out of the workspace is refused', async () => {
87
+ const host = await workspace();
88
+ const link = join(host.cwd, 'escape.txt');
89
+ await symlink('/etc/hosts', link);
90
+ const answer = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: link });
91
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
92
+ });
93
+
94
+ test('a window of 0 is invalid params, not an empty answer', async () => {
95
+ const host = await workspace();
96
+ const file = join(host.cwd, 'a.txt');
97
+ await Bun.write(file, 'one');
98
+ const answer = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 's1', path: file, line: 0 });
99
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
100
+ });
101
+
102
+ test('a request naming another session is refused', async () => {
103
+ const host = await workspace();
104
+ const file = join(host.cwd, 'a.txt');
105
+ await Bun.write(file, 'one');
106
+ const answer = await handleAcpFsRequest(host, 'fs/read_text_file', { sessionId: 'other', path: file });
107
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
108
+ });
109
+ });
110
+
111
+ describe('fs/write_text_file', () => {
112
+ test('creates the file and its parent directories', async () => {
113
+ const host = await workspace();
114
+ const target = join(host.cwd, 'nested', 'dir', 'a.txt');
115
+ const answer = await handleAcpFsRequest(host, 'fs/write_text_file', { sessionId: 's1', path: target, content: 'hello' });
116
+ expect(answer).toEqual({ answered: true, result: {} });
117
+ expect(await Bun.file(target).text()).toBe('hello');
118
+ });
119
+
120
+ test('a path outside the workspace is refused and nothing is written', async () => {
121
+ const host = await workspace();
122
+ const target = join(host.cwd, '..', 'escaped.txt');
123
+ const answer = await handleAcpFsRequest(host, 'fs/write_text_file', { sessionId: 's1', path: target, content: 'x' });
124
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
125
+ });
126
+
127
+ test('missing content is invalid params', async () => {
128
+ const host = await workspace();
129
+ const answer = await handleAcpFsRequest(host, 'fs/write_text_file', {
130
+ sessionId: 's1',
131
+ path: join(host.cwd, 'a.txt'),
132
+ });
133
+ expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
134
+ });
135
+ });