@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
|
@@ -100,6 +100,18 @@ describe('ACP stream marker', () => {
|
|
|
100
100
|
expect(streamMarks()).toEqual(['stream', 'abort']);
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
test('a failed turn carries the agent reason onto the finish mark', async () => {
|
|
104
|
+
const { session, turn, streamMarks, streamMarkFailures } = mountSession();
|
|
105
|
+
await session.send({ type: 'prompt', message: 'Say DUMMY_OK' });
|
|
106
|
+
await turn.started;
|
|
107
|
+
// No answer at all is the ACP silent-turn verdict, and the only reason the
|
|
108
|
+
// notification has to show.
|
|
109
|
+
turn.finish({ stopReason: 'end_turn' });
|
|
110
|
+
for (let i = 0; i < 4; i += 1) await Promise.resolve();
|
|
111
|
+
expect(streamMarks()).toEqual(['stream', 'finish']);
|
|
112
|
+
expect(streamMarkFailures()).toEqual([null, 'The agent ended the turn without sending an answer']);
|
|
113
|
+
});
|
|
114
|
+
|
|
103
115
|
test('a refused prompt writes nothing', async () => {
|
|
104
116
|
const { session, turn, streamMarks } = mountSession();
|
|
105
117
|
await session.send({ type: 'prompt', message: 'first' });
|
|
@@ -169,6 +181,24 @@ describe('ACP session facts', () => {
|
|
|
169
181
|
expect(await session.send({ type: 'get_commands' })).toEqual({ commands: session.agentCommands });
|
|
170
182
|
});
|
|
171
183
|
|
|
184
|
+
test('presents a notice that arrives with no turn open', () => {
|
|
185
|
+
const { session, events } = mountSession();
|
|
186
|
+
// `session.notices` is advertised, so a spec-compliant agent sends these
|
|
187
|
+
// between turns. The turn gate exists for abandoned output, not for a live
|
|
188
|
+
// notice — dropping it here would have made the advertisement a lie.
|
|
189
|
+
notify(session, {
|
|
190
|
+
sessionUpdate: 'notice',
|
|
191
|
+
severity: 'warning',
|
|
192
|
+
title: 'MCP server unavailable',
|
|
193
|
+
description: 'Continuing without it.',
|
|
194
|
+
});
|
|
195
|
+
expect(events.at(-1)).toEqual({
|
|
196
|
+
type: 'notice',
|
|
197
|
+
level: 'warning',
|
|
198
|
+
message: 'MCP server unavailable — Continuing without it.',
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
172
202
|
test('records the agent’s own title, which arrives BETWEEN turns', async () => {
|
|
173
203
|
const { session } = mountSession();
|
|
174
204
|
await saveHarnessSession({ sessionId: 'acp-1', harness: 'opencode', agentSessionId: '', cwd: '/tmp' });
|
|
@@ -190,4 +220,37 @@ describe('ACP session facts', () => {
|
|
|
190
220
|
const [row] = await loadAcpSessions();
|
|
191
221
|
expect(row.title).toBe('Release train');
|
|
192
222
|
});
|
|
223
|
+
|
|
224
|
+
test('publishes the legacy mode list as a selector every consumer reads', () => {
|
|
225
|
+
const { session } = mountSession();
|
|
226
|
+
session.modes = {
|
|
227
|
+
currentModeId: 'plan',
|
|
228
|
+
availableModes: [{ id: 'plan', name: 'Plan' }, { id: 'code', name: 'Code' }],
|
|
229
|
+
};
|
|
230
|
+
expect(session.webState().configOptions).toEqual(expect.arrayContaining([
|
|
231
|
+
expect.objectContaining({ id: 'mode', category: 'mode', currentValue: 'plan' }),
|
|
232
|
+
]));
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('an agent-initiated mode change is adopted by the session', () => {
|
|
236
|
+
const { session } = mountSession();
|
|
237
|
+
session.modes = { currentModeId: 'code', availableModes: [{ id: 'code', name: 'Code' }] };
|
|
238
|
+
notify(session, { sessionUpdate: 'current_mode_update', currentModeId: 'plan' });
|
|
239
|
+
expect(session.modes?.currentModeId).toBe('plan');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('agent-side delete runs only when the agent advertises it', async () => {
|
|
243
|
+
const { session, deletedSessions } = mountSession();
|
|
244
|
+
await session.deleteAgentSession();
|
|
245
|
+
expect(deletedSessions()).toEqual([]);
|
|
246
|
+
session.capabilities = { ...session.capabilities, deleteSession: true };
|
|
247
|
+
await session.deleteAgentSession();
|
|
248
|
+
expect(deletedSessions()).toEqual(['acp-1']);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('an image prompt is refused when the agent did not advertise image', () => {
|
|
252
|
+
const { session } = mountSession();
|
|
253
|
+
expect(() => session.startTurn('look', [{ data: 'AAAA', mimeType: 'image/png' }]))
|
|
254
|
+
.toThrow('does not accept image attachments');
|
|
255
|
+
});
|
|
193
256
|
});
|
|
@@ -103,3 +103,32 @@ describe('ACP permission gating', () => {
|
|
|
103
103
|
turn.finish({ stopReason: 'end_turn' });
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
|
+
|
|
107
|
+
describe('ACP cancellation answers parked approvals', () => {
|
|
108
|
+
test('Stop answers every parked request with the cancelled outcome', async () => {
|
|
109
|
+
const { session, permissionAnswers } = mountSession();
|
|
110
|
+
await permission(session, 21, 'execute');
|
|
111
|
+
session.cancelTurn();
|
|
112
|
+
expect(permissionAnswers()).toEqual([
|
|
113
|
+
{ id: 21, result: { outcome: { outcome: 'cancelled' } } },
|
|
114
|
+
]);
|
|
115
|
+
expect(session.isBusy()).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('$/cancel_request answers the named request and ignores an unknown id', async () => {
|
|
119
|
+
const { session, permissionAnswers } = mountSession();
|
|
120
|
+
await permission(session, 22, 'execute');
|
|
121
|
+
const cancel = (requestId: unknown): void => {
|
|
122
|
+
(session as unknown as {
|
|
123
|
+
onNotification(method: string, params: Record<string, unknown>): void;
|
|
124
|
+
}).onNotification('$/cancel_request', { requestId });
|
|
125
|
+
};
|
|
126
|
+
cancel(999);
|
|
127
|
+
expect(permissionAnswers()).toEqual([]);
|
|
128
|
+
cancel(22);
|
|
129
|
+
expect(permissionAnswers()).toEqual([
|
|
130
|
+
{ id: 22, result: { outcome: { outcome: 'cancelled' } } },
|
|
131
|
+
]);
|
|
132
|
+
expect(session.isBusy()).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -40,6 +40,42 @@ export function preApprovedOption(
|
|
|
40
40
|
return allowOption(options);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/** What `session/request_permission` returns; `AcpProcess` satisfies it. */
|
|
44
|
+
export interface AcpPermissionResponder {
|
|
45
|
+
respond(id: string | number, result: unknown): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Answer one parked request with the `cancelled` outcome.
|
|
50
|
+
*
|
|
51
|
+
* ACP requires this whenever the turn is cancelled: a cancelled prompt whose
|
|
52
|
+
* permission request is still parked leaves the agent waiting on a question the
|
|
53
|
+
* user can no longer see. `requestId` is a JSON-RPC id from `$/cancel_request`,
|
|
54
|
+
* or the dialog id from the client's own Stop.
|
|
55
|
+
*/
|
|
56
|
+
export function cancelAcpPermission(
|
|
57
|
+
permissions: PendingPermissions,
|
|
58
|
+
responder: AcpPermissionResponder,
|
|
59
|
+
requestId: string | number,
|
|
60
|
+
): boolean {
|
|
61
|
+
const entry = permissions.take(String(requestId));
|
|
62
|
+
if (!entry) return false;
|
|
63
|
+
responder.respond(entry.id, { outcome: { outcome: 'cancelled' } });
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Cancel every parked request — the client's half of `session/cancel`. */
|
|
68
|
+
export function cancelAllAcpPermissions(
|
|
69
|
+
permissions: PendingPermissions,
|
|
70
|
+
responder: AcpPermissionResponder,
|
|
71
|
+
): number {
|
|
72
|
+
const drained = permissions.drain();
|
|
73
|
+
for (const entry of drained) {
|
|
74
|
+
responder.respond(entry.id, { outcome: { outcome: 'cancelled' } });
|
|
75
|
+
}
|
|
76
|
+
return drained.length;
|
|
77
|
+
}
|
|
78
|
+
|
|
43
79
|
/** The slice of a session a permission request needs. */
|
|
44
80
|
export interface PermissionRequestHost {
|
|
45
81
|
readonly sessionId: string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Agent→client request routing.
|
|
8
|
+
*
|
|
9
|
+
* The two branches that are easy to get wrong: an unimplemented method must
|
|
10
|
+
* answer `-32601` (an agent falls back on that; an internal error looks like a
|
|
11
|
+
* client bug), and the advertised fs surface must actually be served rather
|
|
12
|
+
* than refused.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
17
|
+
import { tmpdir } from 'node:os';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
20
|
+
import { handleAcpClientRequest, type AcpClientRequestHost } from '@/server/lib/harness/acp/session-requests';
|
|
21
|
+
import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
22
|
+
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
23
|
+
|
|
24
|
+
const scratch: string[] = [];
|
|
25
|
+
|
|
26
|
+
function host(cwd = '/tmp', protocol: 1 | 2 = 1): AcpClientRequestHost {
|
|
27
|
+
return {
|
|
28
|
+
sessionId: 's1',
|
|
29
|
+
cwd,
|
|
30
|
+
protocol,
|
|
31
|
+
accessMode: 'always-ask',
|
|
32
|
+
permissions: new PendingPermissions(),
|
|
33
|
+
emit: (_event: AgentEvent) => {},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
afterEach(async () => {
|
|
38
|
+
await Promise.all(scratch.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('handleAcpClientRequest', () => {
|
|
42
|
+
test('an unimplemented method is refused with method-not-found', async () => {
|
|
43
|
+
const answer = await handleAcpClientRequest(host(), 1, 'terminal/create', {
|
|
44
|
+
sessionId: 's1',
|
|
45
|
+
command: 'ls',
|
|
46
|
+
});
|
|
47
|
+
expect(answer).toEqual({
|
|
48
|
+
answered: false,
|
|
49
|
+
message: 'Kabmo does not implement terminal/create',
|
|
50
|
+
code: ACP_ERROR.methodNotFound,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the advertised fs surface is served, not refused', async () => {
|
|
55
|
+
const dir = await mkdtemp(join(tmpdir(), 'kabmo-acp-req-'));
|
|
56
|
+
scratch.push(dir);
|
|
57
|
+
await Bun.write(join(dir, 'a.txt'), 'hi');
|
|
58
|
+
const answer = await handleAcpClientRequest(host(dir), 2, 'fs/read_text_file', {
|
|
59
|
+
sessionId: 's1',
|
|
60
|
+
path: join(dir, 'a.txt'),
|
|
61
|
+
});
|
|
62
|
+
expect(answer).toEqual({ answered: true, result: { content: 'hi' } });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('a v2 tool_call subject is applied like the v1 tool call', async () => {
|
|
66
|
+
const request = host('/tmp', 2);
|
|
67
|
+
const answer = await handleAcpClientRequest(request, 3, 'session/request_permission', {
|
|
68
|
+
sessionId: 's1',
|
|
69
|
+
title: 'Read a file?',
|
|
70
|
+
subject: { type: 'tool_call', toolCall: { toolCallId: 'c1', kind: 'read' } },
|
|
71
|
+
options: [{ optionId: 'allow', kind: 'allow_once' }],
|
|
72
|
+
});
|
|
73
|
+
// `always-ask` auto-runs the read tier, exactly as it does for v1.
|
|
74
|
+
expect(answer).toMatchObject({ answered: true, result: { outcome: { outcome: 'selected' } } });
|
|
75
|
+
expect(request.permissions.size()).toBe(0);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('a v2 command subject parks the dialog with the command visible', async () => {
|
|
79
|
+
const request = host('/tmp', 2);
|
|
80
|
+
const answer = await handleAcpClientRequest(request, 4, 'session/request_permission', {
|
|
81
|
+
sessionId: 's1',
|
|
82
|
+
title: 'Run the tests?',
|
|
83
|
+
subject: { type: 'command', command: 'cargo test', cwd: '/repo' },
|
|
84
|
+
options: [{ optionId: 'allow', kind: 'allow_once' }, { optionId: 'deny', kind: 'reject_once' }],
|
|
85
|
+
});
|
|
86
|
+
expect(answer).toEqual({ answered: false, deferred: true });
|
|
87
|
+
expect(request.permissions.pendingDialogs()[0]).toMatchObject({
|
|
88
|
+
title: 'Run the tests?',
|
|
89
|
+
message: '$ cargo test',
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Agent→client requests for an ACP session.
|
|
8
|
+
*
|
|
9
|
+
* Every branch answers or refuses — an unanswered call parks the turn — and the
|
|
10
|
+
* approval branch is the same code the in-process tier uses, so a dialog and an
|
|
11
|
+
* auto-answer cannot disagree.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { answerPermissionRequest, cancelAcpPermission } from '@/server/lib/harness/acp/session-permissions';
|
|
15
|
+
import { handleAcpFsRequest, isAcpFsMethod } from '@/server/lib/harness/acp/client-fs';
|
|
16
|
+
import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
17
|
+
import { normalizePermissionParams } from '@/server/lib/harness/acp/v2';
|
|
18
|
+
import type { AcpId, AcpProtocolVersion } from '@/server/lib/harness/acp/protocol';
|
|
19
|
+
import type { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
20
|
+
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
21
|
+
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
22
|
+
|
|
23
|
+
export interface AcpClientRequestHost {
|
|
24
|
+
readonly sessionId: string;
|
|
25
|
+
readonly cwd: string;
|
|
26
|
+
readonly protocol: AcpProtocolVersion;
|
|
27
|
+
accessMode: ApprovalMode;
|
|
28
|
+
permissions: PendingPermissions;
|
|
29
|
+
emit: (event: AgentEvent) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type AcpClientRequestAnswer =
|
|
33
|
+
| { answered: true; result: unknown }
|
|
34
|
+
| { answered: false; message: string; code?: number }
|
|
35
|
+
| { answered: false; deferred: true };
|
|
36
|
+
|
|
37
|
+
export function handleAcpClientRequest(
|
|
38
|
+
host: AcpClientRequestHost,
|
|
39
|
+
id: AcpId,
|
|
40
|
+
method: string,
|
|
41
|
+
params: Record<string, unknown>,
|
|
42
|
+
): Promise<AcpClientRequestAnswer> {
|
|
43
|
+
if (method === 'session/request_permission') {
|
|
44
|
+
// v2 restructured this call: a required `title` and an optional `subject`
|
|
45
|
+
// replace the v1 `toolCall`. The approval queue keeps its v1 shape.
|
|
46
|
+
const normalized = host.protocol === 2 ? normalizePermissionParams(params) : params;
|
|
47
|
+
return answerPermissionRequest({
|
|
48
|
+
sessionId: host.sessionId,
|
|
49
|
+
accessMode: host.accessMode,
|
|
50
|
+
permissions: host.permissions,
|
|
51
|
+
emit: (event) => host.emit(event),
|
|
52
|
+
}, id, normalized);
|
|
53
|
+
}
|
|
54
|
+
// The file surface the client advertised at `initialize`. Routed before the
|
|
55
|
+
// refusal so an agent that took the advertisement at its word gets an answer.
|
|
56
|
+
if (isAcpFsMethod(method)) return handleAcpFsRequest(host, method, params);
|
|
57
|
+
// `-32601`, not "internal error": the agent decides from the code whether this
|
|
58
|
+
// client simply lacks the method (Spec §Errors).
|
|
59
|
+
return Promise.resolve({
|
|
60
|
+
answered: false,
|
|
61
|
+
message: `Kabmo does not implement ${method}`,
|
|
62
|
+
code: ACP_ERROR.methodNotFound,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The host a cancellation notification needs; `AcpSession` satisfies it. */
|
|
67
|
+
export interface AcpCancelHost {
|
|
68
|
+
readonly permissions: PendingPermissions;
|
|
69
|
+
respond(id: AcpId, result: unknown): void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Handle `$/cancel_request` — the agent withdrawing a request it made on this
|
|
74
|
+
* client. The only long-lived one Kabmo parks is an approval, and ACP requires
|
|
75
|
+
* the `cancelled` outcome for it. Returns false for a different method so the
|
|
76
|
+
* caller keeps routing.
|
|
77
|
+
*/
|
|
78
|
+
export function handleAcpCancelRequest(
|
|
79
|
+
host: AcpCancelHost,
|
|
80
|
+
method: string,
|
|
81
|
+
params: Record<string, unknown>,
|
|
82
|
+
): boolean {
|
|
83
|
+
if (method !== '$/cancel_request') return false;
|
|
84
|
+
const requestId = params.requestId;
|
|
85
|
+
if (typeof requestId === 'string' || typeof requestId === 'number') {
|
|
86
|
+
cancelAcpPermission(host.permissions, host, requestId);
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
@@ -37,7 +37,10 @@
|
|
|
37
37
|
import { scheduleQueueDelivery } from '@/server/lib/queue/delivery.server';
|
|
38
38
|
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
39
39
|
import { saveAcpUsage } from '@/server/lib/harness/acp/acp-telemetry.server';
|
|
40
|
-
import
|
|
40
|
+
import { lastAssistantText } from '@/server/lib/omp/session/goal-driver.server';
|
|
41
|
+
import { noteChildOutcome } from '@/server/lib/sessions/notify.server';
|
|
42
|
+
import { saveSessionAnswer } from '@/server/lib/sessions/answers.server';
|
|
43
|
+
import type { AcpTurns, AcpTurnEndInfo } from '@/server/lib/harness/acp/turn';
|
|
41
44
|
|
|
42
45
|
/** What a turn reads and moves on the session. */
|
|
43
46
|
export interface AcpTurnTarget {
|
|
@@ -50,7 +53,7 @@ export interface AcpTurnTarget {
|
|
|
50
53
|
totalCost: number;
|
|
51
54
|
runModel: { provider: string; modelId: string } | null;
|
|
52
55
|
/** The durable run marker; a field on the session so a test can stub it. */
|
|
53
|
-
markStream: (status: 'stream' | 'finish' | 'abort') => void;
|
|
56
|
+
markStream: (status: 'stream' | 'finish' | 'abort', failure?: string | null) => void;
|
|
54
57
|
isAlive(): boolean;
|
|
55
58
|
isBusy(): boolean;
|
|
56
59
|
send(command: Record<string, unknown>): Promise<unknown>;
|
|
@@ -70,10 +73,7 @@ export function beginAcpTurn(
|
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
/** Turn-end bookkeeping: the closed message, the badge, then the queue. */
|
|
73
|
-
export function settleAcpTurn(
|
|
74
|
-
target: AcpTurnTarget,
|
|
75
|
-
info: { stopReason?: string; closedMessage: boolean },
|
|
76
|
-
): void {
|
|
76
|
+
export function settleAcpTurn(target: AcpTurnTarget, info: AcpTurnEndInfo): void {
|
|
77
77
|
if (info.closedMessage) target.messageCount += 1;
|
|
78
78
|
// ACP has no transcript to re-read, so the last usage snapshot is what lets
|
|
79
79
|
// the Context ring answer after a reload or a restart.
|
|
@@ -86,10 +86,30 @@ export function settleAcpTurn(
|
|
|
86
86
|
totalCost: target.totalCost,
|
|
87
87
|
runModel: target.runModel,
|
|
88
88
|
});
|
|
89
|
-
// A cancelled turn is an `abort` badge
|
|
90
|
-
|
|
89
|
+
// A cancelled turn is an `abort` badge; every other ending a `finish` — and a
|
|
90
|
+
// failed turn carries the agent's own reason, which is the only copy a tab
|
|
91
|
+
// that never opened the session can read.
|
|
92
|
+
const failure = info.failed === true
|
|
93
|
+
? (info.failure?.trim() || 'The agent ended the turn without an answer')
|
|
94
|
+
: null;
|
|
95
|
+
target.markStream(info.stopReason === 'cancelled' ? 'abort' : 'finish', failure);
|
|
91
96
|
// Todo/plan/telemetry panels read their own topics; without this signal an
|
|
92
97
|
// ACP turn's usage and titles never republished (the RPC settle path does it).
|
|
93
98
|
emitRealtimeSignal('session-data-dirty', target.sessionId);
|
|
99
|
+
const finalText = lastAssistantText([info.message]);
|
|
100
|
+
if (finalText) void saveSessionAnswer(target.sessionId, finalText).catch(() => {});
|
|
101
|
+
const status = info.cancelled === true
|
|
102
|
+
? 'interrupted'
|
|
103
|
+
: info.failed === true
|
|
104
|
+
? 'failed'
|
|
105
|
+
: 'completed';
|
|
106
|
+
void noteChildOutcome({
|
|
107
|
+
sessionId: target.sessionId,
|
|
108
|
+
status,
|
|
109
|
+
output: finalText,
|
|
110
|
+
...(status === 'failed' ? { failure: info.failure ?? 'The agent ended the turn without an answer' } : {}),
|
|
111
|
+
}).catch((error: unknown) => {
|
|
112
|
+
console.error('[sessions] could not record an ACP child outcome:', error);
|
|
113
|
+
});
|
|
94
114
|
scheduleQueueDelivery(target);
|
|
95
115
|
}
|
|
@@ -42,6 +42,10 @@ export class AcpUsageMeter {
|
|
|
42
42
|
this.turnPeak = Math.max(this.turnPeak, used);
|
|
43
43
|
}
|
|
44
44
|
const cost = update.cost;
|
|
45
|
+
if (cost === null) {
|
|
46
|
+
this.totalCost = 0;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
45
49
|
if (cost && typeof cost === 'object' && 'amount' in cost && typeof cost.amount === 'number') {
|
|
46
50
|
this.totalCost = cost.amount;
|
|
47
51
|
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import { configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
|
|
23
|
-
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
23
|
+
import type { AcpConfigOption, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
|
|
24
24
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
25
25
|
|
|
26
26
|
export interface AcpStateView {
|
|
@@ -34,9 +34,34 @@ export interface AcpStateView {
|
|
|
34
34
|
totalCost: number;
|
|
35
35
|
runModel: { provider: string; modelId: string } | null;
|
|
36
36
|
configOptions: AcpConfigOption[];
|
|
37
|
+
/** The older Session Modes API, when the agent published no selector. */
|
|
38
|
+
modes: AcpSessionModeState | null;
|
|
37
39
|
harness: HarnessId;
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The agent's legacy mode list as the selector every Kabmo consumer already
|
|
44
|
+
* reads. `applyHarnessMode` and the composer look for a `category: "mode"`
|
|
45
|
+
* config option; without this an agent that only speaks `modes` had no Plan
|
|
46
|
+
* control at all. Writing the synthesized id routes back to `session/set_mode`
|
|
47
|
+
* in `AcpSession.setConfig`.
|
|
48
|
+
*/
|
|
49
|
+
function modeSelector(modes: AcpSessionModeState | null): AcpConfigOption[] {
|
|
50
|
+
if (!modes) return [];
|
|
51
|
+
return [{
|
|
52
|
+
id: 'mode',
|
|
53
|
+
name: 'Session Mode',
|
|
54
|
+
category: 'mode',
|
|
55
|
+
type: 'select',
|
|
56
|
+
currentValue: modes.currentModeId,
|
|
57
|
+
options: modes.availableModes.map((entry) => ({
|
|
58
|
+
value: entry.id,
|
|
59
|
+
name: entry.name,
|
|
60
|
+
...(entry.description ? { description: entry.description } : {}),
|
|
61
|
+
})),
|
|
62
|
+
}];
|
|
63
|
+
}
|
|
64
|
+
|
|
40
65
|
export function acpWebState(view: AcpStateView): Record<string, unknown> {
|
|
41
66
|
const thinking = configOption(view.configOptions, 'thought_level');
|
|
42
67
|
// The run's model is seeded at `start()` and refreshed by every config write,
|
|
@@ -44,6 +69,9 @@ export function acpWebState(view: AcpStateView): Record<string, unknown> {
|
|
|
44
69
|
// must report, since an alias or a fallback can differ from the request. The
|
|
45
70
|
// fallback exists only for a session whose selector list never carried a model.
|
|
46
71
|
const serving = view.runModel ?? modelFromOption(configOption(view.configOptions, 'model'), view.harness);
|
|
72
|
+
const configOptions = configOption(view.configOptions, 'mode')
|
|
73
|
+
? view.configOptions
|
|
74
|
+
: [...view.configOptions, ...modeSelector(view.modes)];
|
|
47
75
|
return {
|
|
48
76
|
sessionId: view.sessionId,
|
|
49
77
|
isStreaming: view.isStreaming,
|
|
@@ -56,6 +84,6 @@ export function acpWebState(view: AcpStateView): Record<string, unknown> {
|
|
|
56
84
|
totalCost: view.totalCost,
|
|
57
85
|
model: serving ? { id: serving.modelId, provider: serving.provider } : undefined,
|
|
58
86
|
thinkingLevel: typeof thinking?.currentValue === 'string' ? thinking.currentValue : undefined,
|
|
59
|
-
configOptions
|
|
87
|
+
configOptions,
|
|
60
88
|
};
|
|
61
89
|
}
|
|
@@ -22,6 +22,7 @@ import { AcpSession } from '@/server/lib/harness/acp/session';
|
|
|
22
22
|
import { AcpUsageMeter } from '@/server/lib/harness/acp/session-usage';
|
|
23
23
|
import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
|
|
24
24
|
import { AcpTurns } from '@/server/lib/harness/acp/turn';
|
|
25
|
+
import { SessionListeners } from '@/server/lib/harness/acp/session-listeners';
|
|
25
26
|
import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
26
27
|
import { stampMessageModel } from '@/server/lib/harness/acp/session-config';
|
|
27
28
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
@@ -46,10 +47,25 @@ export interface MountedSession {
|
|
|
46
47
|
turnEnds: () => number;
|
|
47
48
|
/** The durable run markers written for this session, in order. */
|
|
48
49
|
streamMarks: () => string[];
|
|
50
|
+
/** The `failure` argument written with each marker, in the same order. */
|
|
51
|
+
streamMarkFailures: () => Array<string | null>;
|
|
52
|
+
/** Results the session answered an agent→client request with. */
|
|
53
|
+
permissionAnswers: () => { id: unknown; result: unknown }[];
|
|
54
|
+
/** Session ids the session asked the agent to delete. */
|
|
55
|
+
deletedSessions: () => string[];
|
|
49
56
|
/** How many times a command or frame deferred the idle reclaim. */
|
|
50
57
|
idleResets: () => number;
|
|
51
58
|
/** Whether a destroy stopped the reclaim clock. */
|
|
52
59
|
idleStopped: () => boolean;
|
|
60
|
+
/** Swap the background probe the session drives with one a case controls. */
|
|
61
|
+
setBackground: (probe: BackgroundProbeStub) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The slice of `AcpBackgroundProbe` a session calls. */
|
|
65
|
+
export interface BackgroundProbeStub {
|
|
66
|
+
start: (baseline: string) => void;
|
|
67
|
+
stop: () => void;
|
|
68
|
+
consume: (method: string, params: Record<string, unknown>) => boolean;
|
|
53
69
|
}
|
|
54
70
|
|
|
55
71
|
/** One in-flight `session/prompt` the stub can settle. */
|
|
@@ -96,6 +112,11 @@ export function mountSession(): MountedSession {
|
|
|
96
112
|
// A config write; the default reply omits the list, which is the shape a
|
|
97
113
|
// harness that ignores the protocol's "complete list" rule returns.
|
|
98
114
|
setConfigOption: async (_sessionId: string, _configId: string, _value: string | boolean) => ({}),
|
|
115
|
+
deleteSession: async (sessionId: string) => {
|
|
116
|
+
deletes.push(sessionId);
|
|
117
|
+
return {};
|
|
118
|
+
},
|
|
119
|
+
respond: (id: string | number, result: unknown) => answers.push({ id, result }),
|
|
99
120
|
dispose: async () => {},
|
|
100
121
|
isAlive: true,
|
|
101
122
|
};
|
|
@@ -114,9 +135,20 @@ export function mountSession(): MountedSession {
|
|
|
114
135
|
},
|
|
115
136
|
});
|
|
116
137
|
const marks: string[] = [];
|
|
138
|
+
const markFailures: Array<string | null> = [];
|
|
139
|
+
const answers: { id: unknown; result: unknown }[] = [];
|
|
140
|
+
const deletes: string[] = [];
|
|
141
|
+
const eventSink = new SessionListeners();
|
|
142
|
+
eventSink.add((event) => events.push(event));
|
|
143
|
+
let background: BackgroundProbeStub = {
|
|
144
|
+
start: () => {},
|
|
145
|
+
stop: () => {},
|
|
146
|
+
consume: () => false,
|
|
147
|
+
};
|
|
117
148
|
Object.assign(session as unknown as Record<string, unknown>, {
|
|
118
|
-
markStream: (status: string) => {
|
|
149
|
+
markStream: (status: string, failure?: string | null) => {
|
|
119
150
|
marks.push(status);
|
|
151
|
+
markFailures.push(failure ?? null);
|
|
120
152
|
},
|
|
121
153
|
harness: 'opencode',
|
|
122
154
|
cwd: '/tmp',
|
|
@@ -134,10 +166,11 @@ export function mountSession(): MountedSession {
|
|
|
134
166
|
assistantCount: 0,
|
|
135
167
|
usage: new AcpUsageMeter(),
|
|
136
168
|
runModel: null,
|
|
137
|
-
|
|
169
|
+
events: eventSink,
|
|
138
170
|
proc,
|
|
139
171
|
idle,
|
|
140
172
|
destroyed: false,
|
|
173
|
+
background,
|
|
141
174
|
});
|
|
142
175
|
return {
|
|
143
176
|
session,
|
|
@@ -145,8 +178,15 @@ export function mountSession(): MountedSession {
|
|
|
145
178
|
turn,
|
|
146
179
|
turnEnds: () => turnEndCount,
|
|
147
180
|
streamMarks: () => marks,
|
|
181
|
+
streamMarkFailures: () => markFailures,
|
|
182
|
+
permissionAnswers: () => answers,
|
|
183
|
+
deletedSessions: () => deletes,
|
|
148
184
|
idleResets: () => idleResets,
|
|
149
185
|
idleStopped: () => idleStopped,
|
|
186
|
+
setBackground: (probe) => {
|
|
187
|
+
background = probe;
|
|
188
|
+
Object.assign(session as unknown as Record<string, unknown>, { background: probe });
|
|
189
|
+
},
|
|
150
190
|
};
|
|
151
191
|
}
|
|
152
192
|
|