@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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +585 -512
- package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/index.tsx +59 -2
- package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
- package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
- package/src/client/components/common/session-branch/index.tsx +169 -0
- package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
- package/src/client/components/common/session-branch/style.ts +29 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
- package/src/client/components/common/session-row/index.tsx +28 -3
- package/src/client/components/common/session-row/session-row.test.tsx +11 -0
- package/src/client/components/common/session-state-provider/index.tsx +1 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
- package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
- package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +1 -1
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +31 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
- package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
- package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
- package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
- package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
- package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/omp/run-switch.ts +1 -1
- package/src/client/hooks/chat/omp/session-list.tsx +4 -0
- package/src/client/hooks/chat/subagents/roster.ts +122 -0
- package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
- package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
- package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
- package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
- package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
- package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
- package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
- package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
- package/src/client/hooks/chat/timeline/modes.ts +42 -29
- package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
- package/src/client/hooks/chat/timeline/send.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.ts +48 -133
- package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
- package/src/client/hooks/models/use-harness-update.test.ts +286 -0
- package/src/client/hooks/models/use-harness-update.ts +250 -0
- package/src/client/hooks/ui/input-required-alert.ts +12 -5
- package/src/client/hooks/ui/notifications.ts +45 -0
- package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/native/open-session.ts +33 -0
- package/src/client/lib/notifications/os.test.ts +125 -0
- package/src/client/lib/notifications/os.ts +130 -0
- package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
- package/src/client/lib/router/open-session.test.ts +75 -0
- package/src/client/lib/router/open-session.ts +34 -0
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/lib/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/client/tailwind.css +17 -11
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +5 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/calls.ts +15 -1
- package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
- package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
- package/src/server/lib/harness/acp/client-fs.ts +131 -0
- package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
- package/src/server/lib/harness/acp/client-initialize.ts +84 -0
- package/src/server/lib/harness/acp/client.ts +33 -23
- package/src/server/lib/harness/acp/commands.test.ts +5 -5
- package/src/server/lib/harness/acp/commands.ts +14 -2
- package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
- package/src/server/lib/harness/acp/frames.ts +71 -158
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.test.ts +40 -0
- package/src/server/lib/harness/acp/mapper.ts +12 -0
- package/src/server/lib/harness/acp/permissions.ts +6 -0
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
- package/src/server/lib/harness/acp/session-handshake.ts +110 -7
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +41 -2
- package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
- package/src/server/lib/harness/acp/session-permissions.ts +36 -0
- package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
- package/src/server/lib/harness/acp/session-requests.ts +89 -0
- package/src/server/lib/harness/acp/session-turns.ts +28 -8
- package/src/server/lib/harness/acp/session-usage.ts +4 -0
- package/src/server/lib/harness/acp/session-web-state.ts +30 -2
- package/src/server/lib/harness/acp/session.test-util.ts +42 -2
- package/src/server/lib/harness/acp/session.ts +115 -115
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +183 -0
- package/src/server/lib/harness/acp/turn.ts +102 -10
- package/src/server/lib/harness/acp/v2.test.ts +144 -0
- package/src/server/lib/harness/acp/v2.ts +220 -0
- package/src/server/lib/harness/acp/verbs.ts +58 -8
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +24 -10
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +151 -0
- package/src/server/lib/harness/update-job-store.ts +115 -0
- package/src/server/lib/harness/update-job.server.ts +94 -0
- package/src/server/lib/harness/update-queue.server.ts +292 -0
- package/src/server/lib/harness/update-queue.test.ts +265 -0
- package/src/server/lib/harness/update-spawn.server.ts +96 -0
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +202 -0
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +28 -0
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
- package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
- package/src/server/lib/omp/session/delete.server.ts +5 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +277 -0
- package/src/server/lib/sessions/fork.server.ts +329 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +237 -0
- package/src/server/lib/sessions/spawn.server.ts +335 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +12 -5
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +4 -0
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/update-status.ts +32 -0
- package/src/server/routes/harness/update.test.ts +156 -0
- package/src/server/routes/harness/update.ts +64 -147
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +89 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +23 -0
- package/src/server/routes/sessions/spawn.ts +137 -0
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/omp/agent-events.ts +11 -0
- package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/provider-facts.test.ts +27 -0
- package/src/shared/lib/harness/providers.ts +35 -1
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +80 -0
- package/src/shared/lib/harness/update-plan.test.ts +21 -6
- package/src/shared/lib/harness/update-plan.ts +12 -4
- package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
- package/src/shared/lib/notifications/outcomes.test.ts +96 -0
- package/src/shared/lib/notifications/outcomes.ts +64 -0
- package/src/shared/lib/notifications/settings.test.ts +49 -0
- package/src/shared/lib/notifications/settings.ts +34 -0
- package/src/shared/lib/omp/session/default-title.ts +5 -4
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
- package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
- package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/settings/defaults.ts +3 -0
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/theme.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +89 -0
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +8 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/harness-table.test-util.ts +31 -1
- package/dist/client/static/js/index-z3w7n85q.css +0 -1
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ACP client's file surface: `fs/read_text_file` / `fs/write_text_file`.
|
|
8
|
+
*
|
|
9
|
+
* These are calls the AGENT makes on the CLIENT (see `file-system.md`), so the
|
|
10
|
+
* client performs the operation itself and is responsible for its own checks —
|
|
11
|
+
* a permission request does not replace them. Three rules here are the whole
|
|
12
|
+
* point of the module:
|
|
13
|
+
*
|
|
14
|
+
* - **Workspace containment.** Every path is canonicalized against the
|
|
15
|
+
* session's cwd with `pathHolds`, which resolves symlinks and the nearest
|
|
16
|
+
* existing ancestor. A path that merely LOOKS inside (`../`, a symlink to
|
|
17
|
+
* `/etc`) is refused with `-32602`, never read.
|
|
18
|
+
* - **Line numbers are 1-based.** `line`/`limit` select a window of lines, and
|
|
19
|
+
* an out-of-range window is an empty string, not an error.
|
|
20
|
+
* - **A write creates.** ACP says the client MUST create the file if it does
|
|
21
|
+
* not exist, which includes its parent directories.
|
|
22
|
+
*
|
|
23
|
+
* Capability advertisement lives in `client-capabilities.ts`; this module only
|
|
24
|
+
* serves what that object promises.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
import { pathHolds } from '@/server/lib/fs/canonical';
|
|
29
|
+
import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
30
|
+
|
|
31
|
+
/** The slice of a session an fs call reads. */
|
|
32
|
+
export interface AcpFsHost {
|
|
33
|
+
readonly cwd: string;
|
|
34
|
+
readonly sessionId: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Structurally the `answered: false` branch of the client-request answer. */
|
|
38
|
+
export type AcpFsAnswer =
|
|
39
|
+
| { answered: true; result: unknown }
|
|
40
|
+
| { answered: false; message: string; code: number };
|
|
41
|
+
|
|
42
|
+
export function isAcpFsMethod(method: string): boolean {
|
|
43
|
+
return method === 'fs/read_text_file' || method === 'fs/write_text_file';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function handleAcpFsRequest(
|
|
47
|
+
host: AcpFsHost,
|
|
48
|
+
method: string,
|
|
49
|
+
params: Record<string, unknown>,
|
|
50
|
+
): Promise<AcpFsAnswer> {
|
|
51
|
+
const requestedSession = params.sessionId;
|
|
52
|
+
// One process serves one session on this transport, so any other id names
|
|
53
|
+
// something this client cannot address. Silently serving it would let a
|
|
54
|
+
// second session reach a workspace it was never given.
|
|
55
|
+
if (typeof requestedSession === 'string' && requestedSession !== host.sessionId) {
|
|
56
|
+
return refuse(ACP_ERROR.invalidParams, `Unknown session: ${requestedSession}`);
|
|
57
|
+
}
|
|
58
|
+
const target = params.path;
|
|
59
|
+
if (typeof target !== 'string' || target.length === 0) {
|
|
60
|
+
return refuse(ACP_ERROR.invalidParams, 'path is required');
|
|
61
|
+
}
|
|
62
|
+
if (!path.isAbsolute(target)) {
|
|
63
|
+
return refuse(ACP_ERROR.invalidParams, `Path must be absolute: ${target}`);
|
|
64
|
+
}
|
|
65
|
+
if (!(await pathHolds(host.cwd, target))) {
|
|
66
|
+
return refuse(ACP_ERROR.invalidParams, `Path is outside this session's workspace: ${target}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return method === 'fs/read_text_file' ? read(target, params) : write(target, params);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function read(target: string, params: Record<string, unknown>): Promise<AcpFsAnswer> {
|
|
73
|
+
const line = optionalPositive(params.line);
|
|
74
|
+
if (line === false) return refuse(ACP_ERROR.invalidParams, 'line must be a positive integer');
|
|
75
|
+
const limit = optionalPositive(params.limit);
|
|
76
|
+
if (limit === false) return refuse(ACP_ERROR.invalidParams, 'limit must be a positive integer');
|
|
77
|
+
|
|
78
|
+
let text: string;
|
|
79
|
+
try {
|
|
80
|
+
text = await Bun.file(target).text();
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return fileError(target, error);
|
|
83
|
+
}
|
|
84
|
+
if (line === undefined && limit === undefined) return { answered: true, result: { content: text } };
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Splitting on '\n' keeps a trailing newline as a final empty element, so
|
|
88
|
+
* `line: 1, limit: 1` on "a\nb\n" answers "a" — not "a\n". The window is
|
|
89
|
+
* inclusive of `line` and counts `limit` lines, exactly as the spec words it.
|
|
90
|
+
*/
|
|
91
|
+
const lines = text.split('\n');
|
|
92
|
+
const start = (line ?? 1) - 1;
|
|
93
|
+
const end = limit === undefined ? undefined : start + limit;
|
|
94
|
+
return { answered: true, result: { content: lines.slice(start, end).join('\n') } };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function write(target: string, params: Record<string, unknown>): Promise<AcpFsAnswer> {
|
|
98
|
+
const content = params.content;
|
|
99
|
+
if (typeof content !== 'string') {
|
|
100
|
+
return refuse(ACP_ERROR.invalidParams, 'content is required');
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
// `Bun.write` creates missing parent directories, which is the "MUST create
|
|
104
|
+
// the file if it doesn't exist" half of the method.
|
|
105
|
+
await Bun.write(target, content);
|
|
106
|
+
return { answered: true, result: {} };
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return fileError(target, error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The optional positive integer a window parameter must be, or false. */
|
|
113
|
+
function optionalPositive(value: unknown): number | undefined | false {
|
|
114
|
+
if (value === undefined || value === null) return undefined;
|
|
115
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) return false;
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function refuse(code: number, message: string): AcpFsAnswer {
|
|
120
|
+
return { answered: false, message, code };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Map a filesystem failure onto the spec's codes. */
|
|
124
|
+
function fileError(target: string, error: unknown): AcpFsAnswer {
|
|
125
|
+
const code = (error as { code?: unknown } | null)?.code;
|
|
126
|
+
if (code === 'ENOENT') return refuse(ACP_ERROR.notFound, `File not found: ${target}`);
|
|
127
|
+
if (code === 'EISDIR' || code === 'ENOTDIR' || code === 'EINVAL') {
|
|
128
|
+
return refuse(ACP_ERROR.invalidParams, `Not a text file: ${target}`);
|
|
129
|
+
}
|
|
130
|
+
return refuse(ACP_ERROR.internal, error instanceof Error ? error.message : String(error));
|
|
131
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Version negotiation at `initialize`.
|
|
8
|
+
*
|
|
9
|
+
* The client sends v2 as its latest version and carries the v1 field names in
|
|
10
|
+
* the same request, so a v1 peer answers 1 without losing the client's
|
|
11
|
+
* capabilities. A strict v1 peer that REJECTS version 2 gets one clean v1
|
|
12
|
+
* retry; a dead process or timeout is not retried.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { initializeAcpAgent, type AcpInitializeInvoke } from '@/server/lib/harness/acp/client-initialize';
|
|
17
|
+
import { AcpRequestError } from '@/server/lib/harness/acp/calls';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A one-method invoke. The cast is the seam's own shape: `AcpInitializeInvoke`
|
|
21
|
+
* is generic over the caller's requested result, and these doubles answer the
|
|
22
|
+
* only method under test.
|
|
23
|
+
*/
|
|
24
|
+
function invokeAnswering(answer: (params: Record<string, unknown>) => Promise<unknown>): AcpInitializeInvoke {
|
|
25
|
+
return ((_method: string, params: unknown) => answer(params as Record<string, unknown>)) as AcpInitializeInvoke;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('initializeAcpAgent', () => {
|
|
29
|
+
test('sends v2 plus the v1 field names and normalizes a v2 answer', async () => {
|
|
30
|
+
const sent: Record<string, unknown>[] = [];
|
|
31
|
+
const result = await initializeAcpAgent(invokeAnswering(async (params) => {
|
|
32
|
+
sent.push(params);
|
|
33
|
+
return {
|
|
34
|
+
protocolVersion: 2,
|
|
35
|
+
info: { name: 'agent', version: '2.0' },
|
|
36
|
+
capabilities: { session: { prompt: { image: {} } } },
|
|
37
|
+
};
|
|
38
|
+
}));
|
|
39
|
+
expect(sent[0]).toMatchObject({
|
|
40
|
+
protocolVersion: 2,
|
|
41
|
+
capabilities: {},
|
|
42
|
+
info: { name: 'kabmo', version: '0.1' },
|
|
43
|
+
clientCapabilities: { fs: { readTextFile: true, writeTextFile: true } },
|
|
44
|
+
});
|
|
45
|
+
expect(result.protocolVersion).toBe(2);
|
|
46
|
+
expect(result.agentCapabilities?.promptCapabilities?.image).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('retries a rejected v2 initialize as a clean v1 request', async () => {
|
|
50
|
+
const versions: unknown[] = [];
|
|
51
|
+
const result = await initializeAcpAgent(invokeAnswering(async (params) => {
|
|
52
|
+
const version = params.protocolVersion;
|
|
53
|
+
versions.push(version);
|
|
54
|
+
if (version === 2) throw new AcpRequestError('Unsupported protocol version', -32022);
|
|
55
|
+
return { protocolVersion: 1, agentCapabilities: { loadSession: true } };
|
|
56
|
+
}));
|
|
57
|
+
expect(versions).toEqual([2, 1]);
|
|
58
|
+
expect(result.protocolVersion).toBe(1);
|
|
59
|
+
expect(result.agentCapabilities?.loadSession).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('does not retry a transport failure', async () => {
|
|
63
|
+
let calls = 0;
|
|
64
|
+
await expect(initializeAcpAgent(invokeAnswering(async () => {
|
|
65
|
+
calls += 1;
|
|
66
|
+
throw new Error('ACP agent exited');
|
|
67
|
+
}))).rejects.toThrow('ACP agent exited');
|
|
68
|
+
expect(calls).toBe(1);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The client half of `initialize`, kept out of `client.ts` because the transport
|
|
8
|
+
* file has a line ceiling and this is pure protocol.
|
|
9
|
+
*
|
|
10
|
+
* ## Speaking both majors
|
|
11
|
+
*
|
|
12
|
+
* The client sends v2 as its latest version, but the request also carries the v1
|
|
13
|
+
* field names (`clientCapabilities`/`clientInfo`). Migration §Version
|
|
14
|
+
* negotiation says a v1 agent reads a v2 request without those fields and loses
|
|
15
|
+
* the client's file-system support; carrying both means a v1 agent answers 1 and
|
|
16
|
+
* still sees the capabilities it understands, while a v2 agent ignores the v1
|
|
17
|
+
* names as unknown fields.
|
|
18
|
+
*
|
|
19
|
+
* A strict v1 agent may reject version 2 instead of answering 1. The connection
|
|
20
|
+
* is still uninitialized after a failed `initialize`, so one clean v1 retry is
|
|
21
|
+
* allowed and is what keeps such an agent working.
|
|
22
|
+
*
|
|
23
|
+
* The result is normalized into the v1-shaped record the rest of Kabmo reads
|
|
24
|
+
* (`normalizeInitializeResult`); the negotiated major is kept on it.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
ACP_PROTOCOL_VERSION,
|
|
29
|
+
KABMO_CLIENT_CAPABILITIES,
|
|
30
|
+
assertProtocolVersion,
|
|
31
|
+
} from '@/server/lib/harness/acp/client-capabilities';
|
|
32
|
+
import { AcpRequestError } from '@/server/lib/harness/acp/calls';
|
|
33
|
+
import { asRecord, normalizeInitializeResult } from '@/server/lib/harness/acp/v2';
|
|
34
|
+
import type { AcpInitializeResult } from '@/server/lib/harness/acp/protocol';
|
|
35
|
+
|
|
36
|
+
/** One request/response round trip; `AcpProcess.call` is one. */
|
|
37
|
+
export type AcpInitializeInvoke = <T>(method: string, params: unknown, timeoutMs: number) => Promise<T>;
|
|
38
|
+
|
|
39
|
+
const CLIENT_INFO = { name: 'kabmo', title: 'Kabmo', version: '0.1' };
|
|
40
|
+
|
|
41
|
+
/** v1 capabilities for a v1 peer; v2 removed fs/terminal and Kabmo advertises neither. */
|
|
42
|
+
function v1Request(capabilities: Record<string, unknown>): Record<string, unknown> {
|
|
43
|
+
return {
|
|
44
|
+
protocolVersion: 1,
|
|
45
|
+
clientCapabilities: capabilities,
|
|
46
|
+
clientInfo: CLIENT_INFO,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** v2 request plus the v1 field names, for a peer that selects v1 instead. */
|
|
51
|
+
function hybridRequest(capabilities: Record<string, unknown>): Record<string, unknown> {
|
|
52
|
+
return {
|
|
53
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
54
|
+
capabilities: {},
|
|
55
|
+
info: CLIENT_INFO,
|
|
56
|
+
clientCapabilities: capabilities,
|
|
57
|
+
clientInfo: CLIENT_INFO,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function initializeAcpAgent(
|
|
62
|
+
request: AcpInitializeInvoke,
|
|
63
|
+
capabilities: Record<string, unknown> = KABMO_CLIENT_CAPABILITIES,
|
|
64
|
+
timeoutMs = 60_000,
|
|
65
|
+
): Promise<AcpInitializeResult> {
|
|
66
|
+
let raw: Record<string, unknown>;
|
|
67
|
+
try {
|
|
68
|
+
raw = asRecord(await request<unknown>('initialize', hybridRequest(capabilities), timeoutMs)) ?? {};
|
|
69
|
+
} catch (first) {
|
|
70
|
+
// Only an ANSWERED initialize is retried: a dead process or a timeout has
|
|
71
|
+
// nothing to renegotiate. The connection is still uninitialized after a
|
|
72
|
+
// failed `initialize`, so a v1 retry is allowed by both specs.
|
|
73
|
+
if (!(first instanceof AcpRequestError)) throw first;
|
|
74
|
+
try {
|
|
75
|
+
raw = asRecord(await request<unknown>('initialize', v1Request(capabilities), timeoutMs)) ?? {};
|
|
76
|
+
} catch (retry) {
|
|
77
|
+
const b = retry instanceof Error ? retry.message : String(retry);
|
|
78
|
+
throw new Error(`initialize failed (v2 attempt: ${first.message}; v1 attempt: ${b})`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const result = normalizeInitializeResult(raw);
|
|
82
|
+
assertProtocolVersion(result);
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
@@ -31,10 +31,13 @@ import { PendingCalls } from '@/server/lib/harness/acp/calls';
|
|
|
31
31
|
import { killProcessTree } from '@/server/lib/lifecycle/kill-tree';
|
|
32
32
|
import { stripKabmoHostEnv, withToolchainPath } from '@kabmo-labs/kabmo-sdk';
|
|
33
33
|
import * as verbs from '@/server/lib/harness/acp/verbs';
|
|
34
|
+
import { initializeAcpAgent } from '@/server/lib/harness/acp/client-initialize';
|
|
35
|
+
import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
34
36
|
import type {
|
|
35
37
|
AcpId,
|
|
36
38
|
AcpInitializeResult,
|
|
37
39
|
AcpNotification,
|
|
40
|
+
AcpProtocolVersion,
|
|
38
41
|
AcpRequest,
|
|
39
42
|
AcpResponse,
|
|
40
43
|
} from '@/server/lib/harness/acp/protocol';
|
|
@@ -46,7 +49,11 @@ export type AcpClientRequestHandler = (
|
|
|
46
49
|
id: AcpId,
|
|
47
50
|
method: string,
|
|
48
51
|
params: Record<string, unknown>,
|
|
49
|
-
) => Promise<
|
|
52
|
+
) => Promise<
|
|
53
|
+
| { answered: true; result: unknown }
|
|
54
|
+
| { answered: false; message: string; code?: number }
|
|
55
|
+
| { answered: false; deferred: true }
|
|
56
|
+
>;
|
|
50
57
|
|
|
51
58
|
export interface AcpClientOptions {
|
|
52
59
|
command: string[];
|
|
@@ -75,6 +82,9 @@ export class AcpProcess {
|
|
|
75
82
|
private exited = false;
|
|
76
83
|
private stderrTail = '';
|
|
77
84
|
private writeQueue: Promise<void> = Promise.resolve();
|
|
85
|
+
/** The negotiated ACP major. 1 until `initialize` answers; every verb that
|
|
86
|
+
* changed shape between versions reads it. */
|
|
87
|
+
protocolVersion: AcpProtocolVersion = 1;
|
|
78
88
|
/** Set once `initialize` answers, so a request sent earlier fails loudly
|
|
79
89
|
* instead of racing the handshake. */
|
|
80
90
|
private initialized = false;
|
|
@@ -131,20 +141,10 @@ export class AcpProcess {
|
|
|
131
141
|
return this.child.pid ?? undefined;
|
|
132
142
|
}
|
|
133
143
|
|
|
134
|
-
/** `initialize
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
async initialize(capabilities: Record<string, unknown> = {}, timeoutMs = 60_000): Promise<AcpInitializeResult> {
|
|
139
|
-
const result = await this.request<AcpInitializeResult>(
|
|
140
|
-
'initialize',
|
|
141
|
-
{
|
|
142
|
-
protocolVersion: 1,
|
|
143
|
-
clientCapabilities: capabilities,
|
|
144
|
-
clientInfo: { name: 'kabmo', title: 'Kabmo', version: '0.1' },
|
|
145
|
-
},
|
|
146
|
-
timeoutMs,
|
|
147
|
-
);
|
|
144
|
+
/** `initialize`; the client advertises exactly what it can serve. */
|
|
145
|
+
async initialize(capabilities?: Record<string, unknown>, timeoutMs = 60_000): Promise<AcpInitializeResult> {
|
|
146
|
+
const result = await initializeAcpAgent(this.call, capabilities, timeoutMs);
|
|
147
|
+
this.protocolVersion = result.protocolVersion === 2 ? 2 : 1;
|
|
148
148
|
this.initialized = true;
|
|
149
149
|
return result;
|
|
150
150
|
}
|
|
@@ -158,7 +158,7 @@ export class AcpProcess {
|
|
|
158
158
|
// wire shape. Callers keep using `proc.newSession(...)`.
|
|
159
159
|
|
|
160
160
|
newSession(cwd: string, timeoutMs?: number) {
|
|
161
|
-
return verbs.newSession(this.call, cwd, timeoutMs);
|
|
161
|
+
return verbs.newSession(this.call, cwd, timeoutMs, this.protocolVersion);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
loadSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
@@ -166,11 +166,11 @@ export class AcpProcess {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
resumeSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
169
|
-
return verbs.resumeSession(this.call, sessionId, cwd, timeoutMs);
|
|
169
|
+
return verbs.resumeSession(this.call, sessionId, cwd, timeoutMs, this.protocolVersion);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
forkSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
173
|
-
return verbs.forkSession(this.call, sessionId, cwd, timeoutMs);
|
|
172
|
+
forkSession(sessionId: string, cwd: string, timeoutMs?: number, target?: Record<string, unknown>) {
|
|
173
|
+
return verbs.forkSession(this.call, sessionId, cwd, timeoutMs, target);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
listSessions(cwd?: string, timeoutMs?: number) {
|
|
@@ -192,7 +192,7 @@ export class AcpProcess {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
setConfigOption(sessionId: string, configId: string, value: string | boolean, timeoutMs?: number) {
|
|
195
|
-
return verbs.setConfigOption(this.call, sessionId, configId, value, timeoutMs);
|
|
195
|
+
return verbs.setConfigOption(this.call, sessionId, configId, value, timeoutMs, this.protocolVersion);
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
steer(sessionId: string, blocks: unknown[], queue?: 'steering' | 'followUp', timeoutMs?: number) {
|
|
@@ -203,6 +203,14 @@ export class AcpProcess {
|
|
|
203
203
|
return verbs.closeSession(this.call, sessionId, timeoutMs);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
setMode(sessionId: string, modeId: string, timeoutMs?: number) {
|
|
207
|
+
return verbs.setMode(this.call, sessionId, modeId, timeoutMs);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
deleteSession(sessionId: string, timeoutMs?: number) {
|
|
211
|
+
return verbs.deleteSession(this.call, sessionId, timeoutMs);
|
|
212
|
+
}
|
|
213
|
+
|
|
206
214
|
/** The invoke seam `verbs.ts` binds to. Arrow so it survives being passed. */
|
|
207
215
|
readonly call = <T,>(method: string, params: unknown, timeoutMs: number): Promise<T> =>
|
|
208
216
|
this.request<T>(method, params, timeoutMs);
|
|
@@ -212,7 +220,7 @@ export class AcpProcess {
|
|
|
212
220
|
this.write({ jsonrpc: '2.0', id, result });
|
|
213
221
|
}
|
|
214
222
|
|
|
215
|
-
respondError(id: AcpId, message: string, code =
|
|
223
|
+
respondError(id: AcpId, message: string, code: number = ACP_ERROR.internal): void {
|
|
216
224
|
this.write({ jsonrpc: '2.0', id, error: { code, message } });
|
|
217
225
|
}
|
|
218
226
|
|
|
@@ -329,8 +337,10 @@ export class AcpProcess {
|
|
|
329
337
|
// the same request twice.
|
|
330
338
|
if (handled && 'deferred' in handled) return;
|
|
331
339
|
// A refusal is REQUIRED, not optional: an unanswered agent→client call
|
|
332
|
-
// parks the turn forever (the agent's dispatcher waits on it).
|
|
333
|
-
|
|
340
|
+
// parks the turn forever (the agent's dispatcher waits on it). The code
|
|
341
|
+
// travels with it so the agent can distinguish "not implemented" from
|
|
342
|
+
// "that file is gone" and fall back accordingly.
|
|
343
|
+
this.respondError(id, handled?.message ?? `Kabmo does not implement ${method}`, handled?.code);
|
|
334
344
|
} catch (error) {
|
|
335
345
|
this.respondError(id, error instanceof Error ? error.message : String(error));
|
|
336
346
|
}
|
|
@@ -23,12 +23,12 @@ const option = (id: string, category: string, values: string[]): AcpConfigOption
|
|
|
23
23
|
options: values.map((value) => ({ value })),
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
function host(): AcpCommandHost & { writes: [string, string | boolean][];
|
|
26
|
+
function host(): AcpCommandHost & { writes: [string, string | boolean][]; accessModes: string[] } {
|
|
27
27
|
const writes: [string, string | boolean][] = [];
|
|
28
|
-
const
|
|
28
|
+
const accessModes: string[] = [];
|
|
29
29
|
return {
|
|
30
30
|
writes,
|
|
31
|
-
|
|
31
|
+
accessModes,
|
|
32
32
|
harness: 'claude',
|
|
33
33
|
sessionId: 's1',
|
|
34
34
|
capabilities: {
|
|
@@ -48,7 +48,7 @@ function host(): AcpCommandHost & { writes: [string, string | boolean][]; modes:
|
|
|
48
48
|
steer: async () => ({}),
|
|
49
49
|
cancelTurn: () => {},
|
|
50
50
|
setAccessMode: (mode) => {
|
|
51
|
-
|
|
51
|
+
accessModes.push(mode);
|
|
52
52
|
},
|
|
53
53
|
setConfig: async (id, value) => {
|
|
54
54
|
writes.push([id, value]);
|
|
@@ -82,7 +82,7 @@ describe('ACP dispatchCommand', () => {
|
|
|
82
82
|
test('the access tier is adopted before the command runs', async () => {
|
|
83
83
|
const stub = host();
|
|
84
84
|
await dispatchCommand(stub, { type: 'get_state', accessMode: 'yolo' });
|
|
85
|
-
expect(stub.
|
|
85
|
+
expect(stub.accessModes).toEqual(['yolo']);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
test('get_commands answers the agent’s own list', async () => {
|
|
@@ -24,7 +24,7 @@ import { configOption, promptBlocks } from '@/server/lib/harness/acp/prompt';
|
|
|
24
24
|
import { acpOptionValues } from '@/server/lib/harness/acp/protocol';
|
|
25
25
|
import { notePromptTitle } from '@/server/lib/harness/session-title.server';
|
|
26
26
|
import { isApprovalMode, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
27
|
-
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
27
|
+
import type { AcpConfigOption, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
|
|
28
28
|
import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
|
|
29
29
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
30
30
|
|
|
@@ -35,6 +35,10 @@ export interface AcpCommandHost {
|
|
|
35
35
|
readonly sessionId: string;
|
|
36
36
|
readonly capabilities: HarnessCapabilities;
|
|
37
37
|
readonly configOptions: AcpConfigOption[];
|
|
38
|
+
/** The older Session Modes API, when the agent publishes no selector. */
|
|
39
|
+
readonly modes?: AcpSessionModeState | null;
|
|
40
|
+
/** `session/set_mode`; present only when the session can speak it. */
|
|
41
|
+
setMode?(modeId: string): Promise<unknown>;
|
|
38
42
|
/** Dispatch one turn. Returns the ACK (`{agentInvoked:true}`), never the
|
|
39
43
|
* turn: the route's answer means "accepted", and the turn's end arrives as
|
|
40
44
|
* the session's `agent_end` frame. */
|
|
@@ -137,7 +141,15 @@ export interface AcpCommandHost {
|
|
|
137
141
|
case 'set_mode': {
|
|
138
142
|
const mode = String(command.mode ?? '');
|
|
139
143
|
const selector = configOption(host.configOptions, 'mode');
|
|
140
|
-
if (!selector)
|
|
144
|
+
if (!selector) {
|
|
145
|
+
// The older Session Modes API. An agent that publishes `modes` and no
|
|
146
|
+
// `mode` selector can still move; inventing a selector write would
|
|
147
|
+
// call a method it did not advertise.
|
|
148
|
+
if (host.modes?.availableModes.some((entry) => entry.id === mode) && host.setMode) {
|
|
149
|
+
return host.setMode(mode);
|
|
150
|
+
}
|
|
151
|
+
throw new Error(`This harness exposes no mode selector (${host.harness})`);
|
|
152
|
+
}
|
|
141
153
|
return host.setConfig(selector.id, mode);
|
|
142
154
|
}
|
|
143
155
|
|
|
@@ -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
|
+
});
|