@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,183 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { AcpRequestError } from '@/server/lib/harness/acp/calls';
|
|
3
|
+
import { AcpTurns, type AcpTurnSeams } from '@/server/lib/harness/acp/turn';
|
|
4
|
+
|
|
5
|
+
type TurnEnd = Parameters<AcpTurnSeams['onTurnEnd']>[0];
|
|
6
|
+
|
|
7
|
+
function harness(overrides: Partial<AcpTurnSeams> = {}): {
|
|
8
|
+
turns: AcpTurns;
|
|
9
|
+
events: { type: string; errorMessage?: string }[];
|
|
10
|
+
ended: Promise<TurnEnd>;
|
|
11
|
+
} {
|
|
12
|
+
const events: { type: string; errorMessage?: string }[] = [];
|
|
13
|
+
const { promise: ended, resolve: resolveEnd } = Promise.withResolvers<TurnEnd>();
|
|
14
|
+
const turns = new AcpTurns({
|
|
15
|
+
emit: (event) => events.push(event as { type: string; errorMessage?: string }),
|
|
16
|
+
prompt: async () => ({}),
|
|
17
|
+
cancelAgent: () => {},
|
|
18
|
+
abandonPrompt: () => {},
|
|
19
|
+
resetMapper: () => {},
|
|
20
|
+
closeMessage: () => [],
|
|
21
|
+
openCalls: () => [],
|
|
22
|
+
onTurnEnd: (info) => resolveEnd(info),
|
|
23
|
+
...overrides,
|
|
24
|
+
});
|
|
25
|
+
return { turns, events, ended };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('AcpTurns failure classification', () => {
|
|
29
|
+
test('a turn that ends without an answer is failed, not completed', async () => {
|
|
30
|
+
const { turns, events, ended } = harness();
|
|
31
|
+
turns.start('do the work', undefined);
|
|
32
|
+
|
|
33
|
+
const info = await ended;
|
|
34
|
+
expect(info.failed).toBe(true);
|
|
35
|
+
expect(info.failure).toContain('without sending an answer');
|
|
36
|
+
expect(events.some((event) => event.type === 'prompt_error')).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('a rejected prompt keeps the agent error and is failed', async () => {
|
|
40
|
+
const { turns, events, ended } = harness({
|
|
41
|
+
prompt: async () => {
|
|
42
|
+
throw new Error('provider exploded');
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
turns.start('do the work', undefined);
|
|
46
|
+
|
|
47
|
+
const info = await ended;
|
|
48
|
+
expect(info.failed).toBe(true);
|
|
49
|
+
expect(info.failure).toBe('provider exploded');
|
|
50
|
+
expect(events.filter((event) => event.type === 'prompt_error')).toHaveLength(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('an answered turn is not failed', async () => {
|
|
54
|
+
const { turns, ended } = harness({
|
|
55
|
+
closeMessage: () => [
|
|
56
|
+
{
|
|
57
|
+
type: 'message_end',
|
|
58
|
+
message: { role: 'assistant', content: [{ type: 'text', text: 'done' }] },
|
|
59
|
+
},
|
|
60
|
+
] as never,
|
|
61
|
+
});
|
|
62
|
+
turns.start('do the work', undefined);
|
|
63
|
+
|
|
64
|
+
const info = await ended;
|
|
65
|
+
expect(info.failed).toBeUndefined();
|
|
66
|
+
expect(info.closedMessage).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('an ACP -32800 answer is a cancelled turn, not a prompt error', async () => {
|
|
70
|
+
const { turns, events, ended } = harness({
|
|
71
|
+
prompt: async () => {
|
|
72
|
+
throw new AcpRequestError('Request cancelled', -32800);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
turns.start('do the work', undefined);
|
|
76
|
+
|
|
77
|
+
const info = await ended;
|
|
78
|
+
expect(info.cancelled).toBe(true);
|
|
79
|
+
expect(info.failed).toBeUndefined();
|
|
80
|
+
expect(events.some((event) => event.type === 'prompt_error')).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('a cancelled turn is interrupted, never failed', async () => {
|
|
84
|
+
const { turns, ended } = harness({ prompt: () => new Promise(() => {}) });
|
|
85
|
+
turns.start('do the work', undefined);
|
|
86
|
+
// The turn opens on the prompt chain's own microtask; cancel before that is
|
|
87
|
+
// the "nothing to cancel" path and would not emit a turn end.
|
|
88
|
+
await Promise.resolve();
|
|
89
|
+
await Promise.resolve();
|
|
90
|
+
turns.cancel();
|
|
91
|
+
|
|
92
|
+
const info = await ended;
|
|
93
|
+
expect(info.cancelled).toBe(true);
|
|
94
|
+
expect(info.failed).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('AcpTurns v2 completion', () => {
|
|
99
|
+
test('acceptance does not end the turn; an idle state_update does', async () => {
|
|
100
|
+
const { turns, ended } = harness();
|
|
101
|
+
turns.completion = 'state';
|
|
102
|
+
turns.start('do the work', undefined);
|
|
103
|
+
await Promise.resolve();
|
|
104
|
+
await Promise.resolve();
|
|
105
|
+
|
|
106
|
+
let finished = false;
|
|
107
|
+
void ended.then(() => { finished = true; });
|
|
108
|
+
await Promise.resolve();
|
|
109
|
+
expect(finished).toBe(false);
|
|
110
|
+
|
|
111
|
+
turns.onStateUpdate({ state: 'idle', stopReason: 'end_turn' });
|
|
112
|
+
const info = await ended;
|
|
113
|
+
expect(info.stopReason).toBe('end_turn');
|
|
114
|
+
expect(info.cancelled).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('idle without a stop reason is not a failure in v2', async () => {
|
|
118
|
+
const { turns, ended, events } = harness();
|
|
119
|
+
turns.completion = 'state';
|
|
120
|
+
turns.start('do the work', undefined);
|
|
121
|
+
await Promise.resolve();
|
|
122
|
+
await Promise.resolve();
|
|
123
|
+
turns.onStateUpdate({ state: 'idle' });
|
|
124
|
+
|
|
125
|
+
const info = await ended;
|
|
126
|
+
expect(info.failed).toBeUndefined();
|
|
127
|
+
expect(events.some((event) => event.type === 'prompt_error')).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('an idle error carries the agent message as the failure', async () => {
|
|
131
|
+
const { turns, ended, events } = harness();
|
|
132
|
+
turns.completion = 'state';
|
|
133
|
+
turns.start('do the work', undefined);
|
|
134
|
+
await Promise.resolve();
|
|
135
|
+
await Promise.resolve();
|
|
136
|
+
turns.onStateUpdate({
|
|
137
|
+
state: 'idle',
|
|
138
|
+
stopReason: 'error',
|
|
139
|
+
error: { code: -32000, message: 'Authentication required' },
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const info = await ended;
|
|
143
|
+
expect(info.failed).toBe(true);
|
|
144
|
+
expect(info.failure).toBe('Authentication required');
|
|
145
|
+
expect(events.some((event) => event.type === 'prompt_error')).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('a cancelled v2 turn is not reopened by the cancelled run late states', async () => {
|
|
149
|
+
const { turns, ended } = harness();
|
|
150
|
+
turns.completion = 'state';
|
|
151
|
+
turns.start('do the work', undefined);
|
|
152
|
+
await Promise.resolve();
|
|
153
|
+
await Promise.resolve();
|
|
154
|
+
turns.cancel();
|
|
155
|
+
await ended;
|
|
156
|
+
turns.onStateUpdate({ state: 'running' });
|
|
157
|
+
expect(turns.isStreaming).toBe(false);
|
|
158
|
+
turns.onStateUpdate({ state: 'idle' });
|
|
159
|
+
expect(turns.isStreaming).toBe(false);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('agent-initiated work opens a turn and idle closes it', async () => {
|
|
163
|
+
const { turns, ended, events } = harness();
|
|
164
|
+
turns.completion = 'state';
|
|
165
|
+
turns.onStateUpdate({ state: 'running' });
|
|
166
|
+
expect(turns.isStreaming).toBe(true);
|
|
167
|
+
expect(events.some((event) => event.type === 'agent_start')).toBe(true);
|
|
168
|
+
turns.onStateUpdate({ state: 'idle', stopReason: 'end_turn' });
|
|
169
|
+
await expect(ended).resolves.toMatchObject({ stopReason: 'end_turn' });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('a running state does not close the turn', async () => {
|
|
173
|
+
const { turns, ended } = harness();
|
|
174
|
+
turns.completion = 'state';
|
|
175
|
+
turns.start('do the work', undefined);
|
|
176
|
+
await Promise.resolve();
|
|
177
|
+
await Promise.resolve();
|
|
178
|
+
turns.onStateUpdate({ state: 'running' });
|
|
179
|
+
turns.onStateUpdate({ state: 'requires_action' });
|
|
180
|
+
turns.onStateUpdate({ state: 'idle', stopReason: 'end_turn' });
|
|
181
|
+
await expect(ended).resolves.toMatchObject({ stopReason: 'end_turn' });
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -19,8 +19,19 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
22
|
+
import { AcpRequestError } from '@/server/lib/harness/acp/calls';
|
|
22
23
|
import { turnEndFrame } from '@/server/lib/harness/acp/frames';
|
|
23
24
|
|
|
25
|
+
/** What a closed turn reports to its session and the parent notice. */
|
|
26
|
+
export interface AcpTurnEndInfo {
|
|
27
|
+
stopReason?: string;
|
|
28
|
+
closedMessage: boolean;
|
|
29
|
+
message?: unknown;
|
|
30
|
+
cancelled?: boolean;
|
|
31
|
+
failed?: boolean;
|
|
32
|
+
failure?: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
export interface AcpTurnSeams {
|
|
25
36
|
/** Push one frame at the session's listeners. */
|
|
26
37
|
emit: (event: AgentEvent) => void;
|
|
@@ -41,12 +52,18 @@ export interface AcpTurnSeams {
|
|
|
41
52
|
* reason, the assistant message the mapper closed (the goal driver audits it),
|
|
42
53
|
* and whether the turn was cancelled (a stop must not be audited).
|
|
43
54
|
*/
|
|
44
|
-
onTurnEnd: (info:
|
|
55
|
+
onTurnEnd: (info: AcpTurnEndInfo) => void;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
export class AcpTurns {
|
|
48
59
|
isStreaming = false;
|
|
49
60
|
isPromptRunning = false;
|
|
61
|
+
/**
|
|
62
|
+
* How a turn ENDS. v1: the `session/prompt` response carries `stopReason`.
|
|
63
|
+
* v2: the response acknowledges insertion; an idle `state_update` ends the
|
|
64
|
+
* turn, so the prompt's resolution only clears the acceptance request.
|
|
65
|
+
*/
|
|
66
|
+
completion: 'response' | 'state' = 'response';
|
|
50
67
|
/** The turn whose frames are accepted, null when none is open. */
|
|
51
68
|
private open: number | null = null;
|
|
52
69
|
/** Identity of the last turn started; only ever grows, so a late reply can be
|
|
@@ -56,6 +73,8 @@ export class AcpTurns {
|
|
|
56
73
|
private request: Promise<unknown> | null = null;
|
|
57
74
|
/** The prompt text of the turn being opened, for the silent-turn verdict. */
|
|
58
75
|
private promptText = '';
|
|
76
|
+
/** Set by a local cancel: non-idle states are the cancelled run, not new work. */
|
|
77
|
+
private awaitingCancellation = false;
|
|
59
78
|
|
|
60
79
|
constructor(private readonly seams: AcpTurnSeams) {}
|
|
61
80
|
|
|
@@ -68,6 +87,7 @@ export class AcpTurns {
|
|
|
68
87
|
this.seq += 1;
|
|
69
88
|
const turnId = this.seq;
|
|
70
89
|
this.promptText = message;
|
|
90
|
+
this.awaitingCancellation = false;
|
|
71
91
|
this.isPromptRunning = true;
|
|
72
92
|
this.isStreaming = true;
|
|
73
93
|
this.seams.emit({ type: 'agent_start' });
|
|
@@ -83,17 +103,26 @@ export class AcpTurns {
|
|
|
83
103
|
this.request = request;
|
|
84
104
|
void request
|
|
85
105
|
.then(
|
|
86
|
-
(result) =>
|
|
106
|
+
(result) => {
|
|
107
|
+
// v2: acceptance is not completion. The idle `state_update` closes it.
|
|
108
|
+
if (this.completion === 'state') return;
|
|
109
|
+
this.settle(turnId, () => this.finish(result as { stopReason?: string } | undefined));
|
|
110
|
+
},
|
|
87
111
|
(error: unknown) =>
|
|
88
112
|
this.settle(turnId, () => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
113
|
+
// `-32800` is ACP's "Request cancelled": an agent that aborted the
|
|
114
|
+
// turn itself (context limit, internal timeout) answered with this
|
|
115
|
+
// instead of a stop reason. It is not a failure to show the user.
|
|
116
|
+
if (error instanceof AcpRequestError && error.code === -32800) {
|
|
117
|
+
this.finish({ stopReason: 'cancelled' });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
121
|
+
this.seams.emit({ type: 'prompt_error', errorMessage: message });
|
|
93
122
|
// The agent's own error is the reason. `finish` must not append its
|
|
94
123
|
// generic "no answer" verdict on top of it — the second frame lands
|
|
95
124
|
// last on the client and replaced the useful message.
|
|
96
|
-
this.finish(undefined, true);
|
|
125
|
+
this.finish(undefined, true, message);
|
|
97
126
|
}),
|
|
98
127
|
)
|
|
99
128
|
.finally(() => {
|
|
@@ -113,6 +142,7 @@ export class AcpTurns {
|
|
|
113
142
|
* turn is chained behind.
|
|
114
143
|
*/
|
|
115
144
|
cancel(): void {
|
|
145
|
+
this.awaitingCancellation = true;
|
|
116
146
|
if (this.open === null) {
|
|
117
147
|
// Nothing dispatched yet, but a turn may be queued behind the previous
|
|
118
148
|
// request: clear its flags too, or Stop leaves the session permanently
|
|
@@ -132,6 +162,59 @@ export class AcpTurns {
|
|
|
132
162
|
return this.open !== null;
|
|
133
163
|
}
|
|
134
164
|
|
|
165
|
+
/**
|
|
166
|
+
* v2's turn boundary: an idle `state_update` ends foreground work.
|
|
167
|
+
*
|
|
168
|
+
* `running`/`requires_action` do not open a turn: a prompt that is still being
|
|
169
|
+
* inserted is already open, and agent-initiated work without a prompt is not
|
|
170
|
+
* represented as a Kabmo turn yet. Repeats are idempotent because `settle`
|
|
171
|
+
* matches the turn id.
|
|
172
|
+
*/
|
|
173
|
+
onStateUpdate(update: Record<string, unknown>): void {
|
|
174
|
+
if (this.completion !== 'state') return;
|
|
175
|
+
const state = typeof update.state === 'string' ? update.state : '';
|
|
176
|
+
if (state !== 'idle') {
|
|
177
|
+
// The cancelled run may still report running/requires_action before its
|
|
178
|
+
// idle; those are not a new foreground interval.
|
|
179
|
+
if (this.awaitingCancellation) return;
|
|
180
|
+
// v2 allows foreground work with no prompt (a goal, a follow-up on a
|
|
181
|
+
// background task). Open a turn so its frames are accepted and rendered.
|
|
182
|
+
if (this.open === null && !this.isPromptRunning && !this.isStreaming) this.beginAgentTurn();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
this.awaitingCancellation = false;
|
|
186
|
+
if (this.open === null) return;
|
|
187
|
+
const turnId = this.open;
|
|
188
|
+
this.settle(turnId, () => {
|
|
189
|
+
const error = update.error && typeof update.error === 'object'
|
|
190
|
+
? (update.error as Record<string, unknown>)
|
|
191
|
+
: undefined;
|
|
192
|
+
const failure = typeof error?.message === 'string' ? error.message : undefined;
|
|
193
|
+
const stopReason = typeof update.stopReason === 'string' ? update.stopReason : undefined;
|
|
194
|
+
if (stopReason === 'error') {
|
|
195
|
+
this.seams.emit({
|
|
196
|
+
type: 'prompt_error',
|
|
197
|
+
errorMessage: failure ?? 'The agent ended the turn with an error',
|
|
198
|
+
});
|
|
199
|
+
this.finish({ stopReason: 'error' }, true, failure);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
this.finish(stopReason ? { stopReason } : undefined);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** A v2 foreground interval that no `session/prompt` started. */
|
|
207
|
+
private beginAgentTurn(): void {
|
|
208
|
+
this.seq += 1;
|
|
209
|
+
this.open = this.seq;
|
|
210
|
+
this.promptText = '';
|
|
211
|
+
this.isPromptRunning = true;
|
|
212
|
+
this.isStreaming = true;
|
|
213
|
+
this.seams.resetMapper();
|
|
214
|
+
this.seams.emit({ type: 'agent_start' });
|
|
215
|
+
this.seams.emit({ type: 'turn_start' });
|
|
216
|
+
}
|
|
217
|
+
|
|
135
218
|
/** Close a turn, unless it was cancelled first: a cancelled turn's late reply
|
|
136
219
|
* must not close the one the user is now watching. */
|
|
137
220
|
private settle(turnId: number, close: () => void): void {
|
|
@@ -145,7 +228,7 @@ export class AcpTurns {
|
|
|
145
228
|
* going to report an end for work it abandoned. `reported` says the caller
|
|
146
229
|
* already emitted the failure reason, so only this module's generic silent
|
|
147
230
|
* verdict is suppressed. */
|
|
148
|
-
private finish(result: { stopReason?: string } | undefined, reported = false): void {
|
|
231
|
+
private finish(result: { stopReason?: string } | undefined, reported = false, failure?: string): void {
|
|
149
232
|
const flushed = this.seams.closeMessage();
|
|
150
233
|
for (const event of flushed) this.seams.emit(event);
|
|
151
234
|
const closed = flushed.find((event) => event.type === 'message_end')?.message;
|
|
@@ -163,10 +246,18 @@ export class AcpTurns {
|
|
|
163
246
|
// produces nothing, and a user's Stop is not a failure either.
|
|
164
247
|
const answered = hasRenderableAnswer(closed) || abandoned.length > 0;
|
|
165
248
|
const cancelled = result?.stopReason === 'cancelled';
|
|
166
|
-
|
|
249
|
+
const slash = this.promptText.trimStart().startsWith('/');
|
|
250
|
+
// v2 says clients cannot infer failure from an idle without a stop reason;
|
|
251
|
+
// the "silent answer is a failure" rule is a v1 agent behaviour (pi-acp).
|
|
252
|
+
const failed = !cancelled && !slash
|
|
253
|
+
&& (reported || (this.completion === 'response' && !answered));
|
|
254
|
+
const reason = failed
|
|
255
|
+
? failure ?? 'The agent ended the turn without sending an answer'
|
|
256
|
+
: null;
|
|
257
|
+
if (failed && !reported && !slash) {
|
|
167
258
|
this.seams.emit({
|
|
168
259
|
type: 'prompt_error',
|
|
169
|
-
errorMessage: 'The agent ended the turn without sending an answer',
|
|
260
|
+
errorMessage: reason ?? 'The agent ended the turn without sending an answer',
|
|
170
261
|
});
|
|
171
262
|
}
|
|
172
263
|
this.isPromptRunning = false;
|
|
@@ -177,6 +268,7 @@ export class AcpTurns {
|
|
|
177
268
|
closedMessage: flushed.some((event) => event.type === 'message_end'),
|
|
178
269
|
...(closed ? { message: closed } : {}),
|
|
179
270
|
...(cancelled ? { cancelled: true } : {}),
|
|
271
|
+
...(failed ? { failed: true, failure: reason } : {}),
|
|
180
272
|
});
|
|
181
273
|
}
|
|
182
274
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The v2 adapter.
|
|
8
|
+
*
|
|
9
|
+
* Every case pins a field the rest of Kabmo would otherwise read as v1:
|
|
10
|
+
* role-agnostic `info`/`capabilities`, object support markers, `configId`,
|
|
11
|
+
* permission `subject`, keyed plans, and the setup response's initial commands.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
import {
|
|
16
|
+
normalizeCommands,
|
|
17
|
+
normalizeConfigOptions,
|
|
18
|
+
normalizeInitializeResult,
|
|
19
|
+
normalizePermissionParams,
|
|
20
|
+
normalizeSessionResult,
|
|
21
|
+
planEntries,
|
|
22
|
+
} from '@/server/lib/harness/acp/v2';
|
|
23
|
+
|
|
24
|
+
const v2Init = {
|
|
25
|
+
protocolVersion: 2,
|
|
26
|
+
info: { name: 'agent', title: 'Agent', version: '2.0.0' },
|
|
27
|
+
capabilities: {
|
|
28
|
+
session: {
|
|
29
|
+
prompt: { image: {} },
|
|
30
|
+
mcp: { http: {} },
|
|
31
|
+
delete: {},
|
|
32
|
+
additionalDirectories: {},
|
|
33
|
+
},
|
|
34
|
+
_meta: { steering: { supported: true } },
|
|
35
|
+
},
|
|
36
|
+
authMethods: [{ methodId: 'login', type: 'agent', name: 'Login' }],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe('normalizeInitializeResult', () => {
|
|
40
|
+
test('maps role-agnostic info and nested session capabilities to the v1 record', () => {
|
|
41
|
+
const init = normalizeInitializeResult(v2Init);
|
|
42
|
+
expect(init.protocolVersion).toBe(2);
|
|
43
|
+
expect(init.agentInfo).toEqual({ name: 'agent', title: 'Agent', version: '2.0.0' });
|
|
44
|
+
expect(init.agentCapabilities).toMatchObject({
|
|
45
|
+
loadSession: false,
|
|
46
|
+
promptCapabilities: { image: true, audio: false, embeddedContext: false },
|
|
47
|
+
mcpCapabilities: { http: true, sse: false },
|
|
48
|
+
sessionCapabilities: {
|
|
49
|
+
list: {},
|
|
50
|
+
resume: {},
|
|
51
|
+
close: {},
|
|
52
|
+
delete: {},
|
|
53
|
+
additionalDirectories: {},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
expect(init.authMethods).toEqual([{ id: 'login', type: 'agent', name: 'Login' }]);
|
|
57
|
+
expect(init._meta).toMatchObject({ steering: { supported: true } });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('an agent without capabilities.session claims no session methods', () => {
|
|
61
|
+
const init = normalizeInitializeResult({ protocolVersion: 2, info: { name: 'x', version: '1' }, capabilities: {} });
|
|
62
|
+
expect(init.agentCapabilities?.sessionCapabilities).toEqual({});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('a v1 result is passed through untouched', () => {
|
|
66
|
+
const v1 = { protocolVersion: 1, agentCapabilities: { loadSession: true } };
|
|
67
|
+
expect(normalizeInitializeResult(v1)).toBe(v1 as never);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('normalizeConfigOptions', () => {
|
|
72
|
+
test('renames configId and groupId and keeps nested selects', () => {
|
|
73
|
+
const options = normalizeConfigOptions([
|
|
74
|
+
{
|
|
75
|
+
configId: 'model',
|
|
76
|
+
name: 'Model',
|
|
77
|
+
category: 'model',
|
|
78
|
+
type: 'select',
|
|
79
|
+
currentValue: 'a',
|
|
80
|
+
options: [{ groupId: 'recommended', name: 'Recommended', options: [{ value: 'a', name: 'A' }] }],
|
|
81
|
+
},
|
|
82
|
+
{ configId: 'brave', name: 'Brave', type: 'boolean', currentValue: false },
|
|
83
|
+
]);
|
|
84
|
+
expect(options[0]).toMatchObject({ id: 'model', currentValue: 'a' });
|
|
85
|
+
expect(options[0]?.options?.[0]).toMatchObject({ group: 'recommended' });
|
|
86
|
+
expect(options[1]).toMatchObject({ id: 'brave', type: 'boolean', currentValue: false });
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('normalizeSessionResult', () => {
|
|
91
|
+
test('adopts initial config options and slash commands', () => {
|
|
92
|
+
const result = normalizeSessionResult({
|
|
93
|
+
sessionId: 's1',
|
|
94
|
+
configOptions: [{ configId: 'mode', category: 'mode', type: 'select', currentValue: 'ask' }],
|
|
95
|
+
availableCommands: [{ type: 'command', name: 'test', description: 'Run tests', input: { type: 'text', hint: 'args' } }],
|
|
96
|
+
});
|
|
97
|
+
expect(result.sessionId).toBe('s1');
|
|
98
|
+
expect(result.configOptions?.[0]).toMatchObject({ id: 'mode' });
|
|
99
|
+
expect(result.availableCommands).toEqual([{ name: 'test', description: 'Run tests', inputHint: 'args' }]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('normalizeCommands drops entries without a name', () => {
|
|
103
|
+
expect(normalizeCommands([{ name: 'x' }, { description: 'nameless' }, null])).toEqual([{ name: 'x' }]);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('normalizePermissionParams', () => {
|
|
108
|
+
test('a tool_call subject becomes the queue tool call, keeping the title', () => {
|
|
109
|
+
const params = normalizePermissionParams({
|
|
110
|
+
sessionId: 's1',
|
|
111
|
+
title: 'Approve file edit?',
|
|
112
|
+
subject: { type: 'tool_call', toolCall: { toolCallId: 'c1', kind: 'edit' } },
|
|
113
|
+
options: [{ optionId: 'allow', kind: 'allow_once' }],
|
|
114
|
+
});
|
|
115
|
+
expect(params.toolCall).toMatchObject({ toolCallId: 'c1', kind: 'edit', title: 'Approve file edit?' });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('a command subject becomes an exec tool call with the command as rawInput', () => {
|
|
119
|
+
const params = normalizePermissionParams({
|
|
120
|
+
sessionId: 's1',
|
|
121
|
+
title: 'Run the tests?',
|
|
122
|
+
subject: { type: 'command', command: 'cargo test', cwd: '/repo' },
|
|
123
|
+
options: [],
|
|
124
|
+
});
|
|
125
|
+
expect(params.toolCall).toMatchObject({
|
|
126
|
+
title: 'Run the tests?',
|
|
127
|
+
kind: 'execute',
|
|
128
|
+
rawInput: { command: 'cargo test', cwd: '/repo' },
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('an absent subject still yields a titled prompt', () => {
|
|
133
|
+
const params = normalizePermissionParams({ sessionId: 's1', title: 'Proceed?', options: [] });
|
|
134
|
+
expect(params.toolCall).toMatchObject({ title: 'Proceed?' });
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('planEntries', () => {
|
|
139
|
+
test('reads an items plan and replaces unknown types with an empty plan', () => {
|
|
140
|
+
expect(planEntries({ plan: { type: 'items', planId: 'p1', entries: [{ content: 'a' }] } })).toEqual([{ content: 'a' }]);
|
|
141
|
+
expect(planEntries({ plan: { type: '_future', planId: 'p2', entries: [{ content: 'a' }] } })).toEqual([]);
|
|
142
|
+
expect(planEntries({})).toEqual([]);
|
|
143
|
+
});
|
|
144
|
+
});
|