@kabmo-labs/kabmo 0.23.0 → 0.25.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 +805 -736
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
- 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/Modal.tsx +2 -6
- 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/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -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 +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- 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 +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- 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 +5 -5
- 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 +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- 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/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- 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/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
- package/src/client/hooks/chat/timeline/send.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.ts +59 -53
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -0
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +26 -12
- 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 +4 -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/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- 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/client.ts +2 -2
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- 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.ts +6 -4
- 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/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +36 -3
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +54 -3
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +79 -79
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +54 -13
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +16 -116
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- 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/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
- package/src/server/lib/omp/session/delete.server.ts +17 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- 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 +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -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 +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -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 +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +22 -4
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +67 -113
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- 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/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -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/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +59 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +44 -1
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +69 -4
- package/src/shared/lib/harness/update-plan.ts +57 -9
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- 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/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/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +26 -10
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- 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 +65 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +21 -4
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -8,26 +8,25 @@
|
|
|
8
8
|
* the `HarnessSession` contract every route already speaks.
|
|
9
9
|
*
|
|
10
10
|
* It owns the session's own state — the id, the config selectors, the resolved
|
|
11
|
-
* model, the run flags the sidebar spinner and the queue
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* agent publishes about itself between turns) and `session-web-state.ts`
|
|
19
|
-
* (`get_state`, in the shape the omp transport reports it).
|
|
11
|
+
* model, the run flags the sidebar spinner and the queue delivery gate read, the
|
|
12
|
+
* agent's commands and the approval queue a reloaded tab replays. The RULES live
|
|
13
|
+
* beside it, one module per concern: `session-handshake.ts` (initialize/new/load
|
|
14
|
+
* + the picks), `session-turns.ts` (the ACK contract and turn-end bookkeeping),
|
|
15
|
+
* `session-config.ts` (config answers, parked dialogs), `session-permissions.ts`
|
|
16
|
+
* (the tier that answers before a dialog exists), `session-facts.ts` (what an
|
|
17
|
+
* agent publishes between turns) and `session-web-state.ts` (`get_state`).
|
|
20
18
|
*
|
|
21
|
-
* `send()`
|
|
19
|
+
* `send()` takes the SAME command vocabulary the routes already send omp, so
|
|
22
20
|
* `routes/agent/command.ts` needs no second dispatch table.
|
|
23
21
|
*/
|
|
24
22
|
|
|
25
23
|
import { AcpProcess } from '@/server/lib/harness/acp/client';
|
|
26
|
-
import { AcpTurns } from '@/server/lib/harness/acp/turn';
|
|
24
|
+
import { AcpTurns, type AcpTurnEndInfo } from '@/server/lib/harness/acp/turn';
|
|
27
25
|
import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
|
|
28
26
|
import type { AcpConfigOption, AcpId } from '@/server/lib/harness/acp/protocol';
|
|
29
27
|
import { promptBlocks } from '@/server/lib/harness/acp/prompt';
|
|
30
|
-
import {
|
|
28
|
+
import { withGatewayCompatibility } from '@/server/lib/harness/acp/gateway-env';
|
|
29
|
+
import { adoptConfigAnswer, publishConfigChange, settlePermissionDialog, stampMessageModel } from '@/server/lib/harness/acp/session-config';
|
|
31
30
|
import { beginAcpTurn, settleAcpTurn } from '@/server/lib/harness/acp/session-turns';
|
|
32
31
|
import { driveAcpGoalAfterTurn } from '@/server/lib/harness/acp/acp-goal-driver.server';
|
|
33
32
|
import { handshakeAcpSession } from '@/server/lib/harness/acp/session-handshake';
|
|
@@ -35,29 +34,27 @@ import { capabilitiesFrom } from '@/server/lib/harness/launch';
|
|
|
35
34
|
import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
36
35
|
import { handleSessionNotification } from '@/server/lib/harness/acp/session-notifications';
|
|
37
36
|
import { AcpUsageMeter, type AcpContextUsage } from '@/server/lib/harness/acp/session-usage';
|
|
38
|
-
import {
|
|
37
|
+
import { handleAcpClientRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
|
|
38
|
+
import { acpExitFailureFrames } from '@/server/lib/harness/acp/session-exit';
|
|
39
|
+
import { SessionListeners } from '@/server/lib/harness/acp/session-listeners';
|
|
40
|
+
import {
|
|
41
|
+
AcpBackgroundProbe,
|
|
42
|
+
BACKGROUND_LOAD_TIMEOUT_MS,
|
|
43
|
+
assistantTextOf,
|
|
44
|
+
deliverBackgroundNotice,
|
|
45
|
+
spawnsBackgroundWork,
|
|
46
|
+
} from '@/server/lib/harness/acp/background-work';
|
|
39
47
|
import { acpWebState } from '@/server/lib/harness/acp/session-web-state';
|
|
48
|
+
import { acpIdleReaper } from '@/server/lib/harness/acp/session-idle';
|
|
40
49
|
import { DEFAULT_APPROVAL_MODE, isApprovalMode, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
41
50
|
import { dispatchCommand, type AcpCommandHost } from '@/server/lib/harness/acp/commands';
|
|
42
51
|
import { markStreamStatus } from '@/shared/lib/omp/session/stream-state.server';
|
|
52
|
+
import type { AcpSessionOptions } from '@/server/lib/harness/acp/session-options';
|
|
43
53
|
import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
|
|
44
54
|
import type { HarnessSession } from '@/server/lib/harness/session';
|
|
45
55
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
46
56
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
47
|
-
|
|
48
|
-
export interface AcpSessionOptions {
|
|
49
|
-
harness: HarnessId;
|
|
50
|
-
command: string[];
|
|
51
|
-
env?: Record<string, string>;
|
|
52
|
-
/** Provider/model this session starts on, applied with
|
|
53
|
-
* `session/set_config_option` right after `session/new`. */
|
|
54
|
-
model?: { provider: string; modelId: string } | null;
|
|
55
|
-
thinkingLevel?: string | null;
|
|
56
|
-
mode?: string | null;
|
|
57
|
-
/** The composer's access pick. ACP has no spawn flag for it, so the session
|
|
58
|
-
* answers `session/request_permission` itself according to this tier. */
|
|
59
|
-
accessMode?: ApprovalMode | null;
|
|
60
|
-
}
|
|
57
|
+
import type { IdleReaper } from '@/server/lib/omp/rpc/idle-reaper';
|
|
61
58
|
|
|
62
59
|
export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
63
60
|
readonly harness: HarnessId;
|
|
@@ -100,11 +97,14 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
100
97
|
accessMode: ApprovalMode = DEFAULT_APPROVAL_MODE;
|
|
101
98
|
capabilities: HarnessCapabilities = capabilitiesFrom({ protocolVersion: 1 }, [], { usage: false, plan: false });
|
|
102
99
|
configOptions: AcpConfigOption[] = [];
|
|
103
|
-
|
|
104
100
|
private readonly proc: AcpProcess;
|
|
101
|
+
/** The quiet-window reclaim; the rules live in `session-idle.ts`. */
|
|
102
|
+
readonly idle: IdleReaper;
|
|
103
|
+
/** Watches for work that finishes after `end_turn`; see `background-work.ts`. */
|
|
104
|
+
private readonly background: AcpBackgroundProbe;
|
|
105
105
|
private readonly mapper = new AcpFrameMapper();
|
|
106
|
-
private readonly
|
|
107
|
-
|
|
106
|
+
private readonly events = new SessionListeners();
|
|
107
|
+
readonly permissions = new PendingPermissions();
|
|
108
108
|
private destroyHook: (() => void) | null = null;
|
|
109
109
|
private destroyed = false;
|
|
110
110
|
/** Set when Kabmo is the one ending the process, so the exit is not reported
|
|
@@ -115,14 +115,25 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
115
115
|
constructor(options: AcpSessionOptions, cwd: string) {
|
|
116
116
|
this.harness = options.harness;
|
|
117
117
|
this.cwd = cwd;
|
|
118
|
+
const env = withGatewayCompatibility(options.harness, options.env);
|
|
118
119
|
this.proc = new AcpProcess({
|
|
119
120
|
command: options.command,
|
|
120
121
|
cwd,
|
|
121
|
-
...(
|
|
122
|
+
...(env ? { env } : {}),
|
|
122
123
|
onNotification: (method, params) => this.onNotification(method, params),
|
|
123
124
|
onClientRequest: (id, method, params) => this.onClientRequest(id, method, params),
|
|
124
125
|
onExit: (info) => this.onExit(info),
|
|
125
126
|
});
|
|
127
|
+
this.idle = acpIdleReaper(this, options.idleDestroyMs);
|
|
128
|
+
// ACP holds updates produced while idle until the next request, so a turn
|
|
129
|
+
// that spawned a subagent is followed by a `session/load` probe. The replay
|
|
130
|
+
// is swallowed by the probe; only the text past the answer already shown is
|
|
131
|
+
// emitted, as the agent's continuation.
|
|
132
|
+
this.background = new AcpBackgroundProbe({
|
|
133
|
+
load: () => this.proc.loadSession(this.sessionId, this.cwd, BACKGROUND_LOAD_TIMEOUT_MS),
|
|
134
|
+
resetIdle: () => this.idle.reset(),
|
|
135
|
+
emit: (text) => deliverBackgroundNotice(this, text),
|
|
136
|
+
});
|
|
126
137
|
this.turns = new AcpTurns({
|
|
127
138
|
emit: (event) => this.emit(event),
|
|
128
139
|
prompt: (message, images) =>
|
|
@@ -130,7 +141,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
130
141
|
cancelAgent: () => this.proc.cancel(this.sessionId),
|
|
131
142
|
abandonPrompt: () => this.proc.abandonPrompt(this.sessionId),
|
|
132
143
|
resetMapper: () => this.mapper.reset(),
|
|
133
|
-
closeMessage: () => this.mapper.closeMessage(),
|
|
144
|
+
closeMessage: () => this.mapper.closeMessage().map((event) => stampMessageModel(event, this.runModel)),
|
|
134
145
|
openCalls: () => this.mapper.openCalls(),
|
|
135
146
|
// The follow-up queue is armed from the turn's END, exactly as the omp
|
|
136
147
|
// wrapper arms it from its own terminal settle. Without this an ACP chat's
|
|
@@ -148,15 +159,17 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
148
159
|
private readonly requestedModel: { provider: string; modelId: string } | null;
|
|
149
160
|
private readonly requestedThinking: string | null;
|
|
150
161
|
private readonly requestedMode: string | null;
|
|
151
|
-
|
|
152
162
|
/** `initialize` + `session/new|load|resume`, then the requested selections. */
|
|
153
|
-
async start(sessionIdToLoad?: string): Promise<{ sessionId: string }> {
|
|
163
|
+
async start(sessionIdToLoad?: string, forkFromSessionId?: string): Promise<{ sessionId: string }> {
|
|
154
164
|
await handshakeAcpSession(
|
|
155
165
|
this,
|
|
156
166
|
this.proc,
|
|
157
167
|
{ model: this.requestedModel, thinking: this.requestedThinking, mode: this.requestedMode },
|
|
158
168
|
sessionIdToLoad,
|
|
169
|
+
forkFromSessionId,
|
|
159
170
|
);
|
|
171
|
+
// A slow handshake is not idleness: the window starts once it is usable.
|
|
172
|
+
this.idle.reset(true);
|
|
160
173
|
return { sessionId: this.sessionId };
|
|
161
174
|
}
|
|
162
175
|
|
|
@@ -181,18 +194,11 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
181
194
|
}
|
|
182
195
|
|
|
183
196
|
onEvent(listener: (event: AgentEvent) => void): () => void {
|
|
184
|
-
this.
|
|
185
|
-
return () => this.listeners.delete(listener);
|
|
197
|
+
return this.events.add(listener);
|
|
186
198
|
}
|
|
187
199
|
|
|
188
200
|
emit(event: AgentEvent): void {
|
|
189
|
-
|
|
190
|
-
try {
|
|
191
|
-
listener(event);
|
|
192
|
-
} catch {
|
|
193
|
-
// One throwing subscriber must not starve the others.
|
|
194
|
-
}
|
|
195
|
-
}
|
|
201
|
+
this.events.emit(event);
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
getPendingUiDialogs(): Record<string, unknown>[] {
|
|
@@ -211,6 +217,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
async send(command: Record<string, unknown>): Promise<unknown> {
|
|
220
|
+
// A command is the clearest sign the session is still wanted.
|
|
221
|
+
this.idle.reset();
|
|
214
222
|
return dispatchCommand(this, command);
|
|
215
223
|
}
|
|
216
224
|
|
|
@@ -232,15 +240,22 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
232
240
|
/** Turn-end bookkeeping the panels read — see `session-turns.ts`. A cancelled
|
|
233
241
|
* turn closes the marker as an `abort` badge, every other ending a `finish`.
|
|
234
242
|
* The goal driver then audits the closed message and may open the next turn. */
|
|
235
|
-
onTurnEnded(info:
|
|
243
|
+
onTurnEnded(info: AcpTurnEndInfo): void {
|
|
236
244
|
if (info.closedMessage) this.assistantCount += 1;
|
|
237
245
|
this.usage.endTurn();
|
|
238
246
|
settleAcpTurn(this, info);
|
|
247
|
+
// A subagent outlives the turn that spawned it: antigravity answers
|
|
248
|
+
// `end_turn` right after `invoke_subagent`, and its completion is held
|
|
249
|
+
// until the next request (upstream #1461). Probe the transcript instead.
|
|
250
|
+
if (!info.cancelled && info.failed !== true && spawnsBackgroundWork(info.message)) {
|
|
251
|
+
this.background.start(assistantTextOf(info.message));
|
|
252
|
+
}
|
|
239
253
|
void driveAcpGoalAfterTurn(this, info.message, { cancelled: info.cancelled === true }).catch(() => {});
|
|
240
254
|
}
|
|
241
255
|
|
|
242
256
|
/** Dispatcher seam: stop the turn. The rules live in `AcpTurns.cancel`. */
|
|
243
257
|
cancelTurn(): void {
|
|
258
|
+
this.background.stop();
|
|
244
259
|
this.turns.cancel();
|
|
245
260
|
}
|
|
246
261
|
|
|
@@ -254,7 +269,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
254
269
|
* `session-config.ts` for why the AGENT's resolved value is what is kept. */
|
|
255
270
|
async setConfig(configId: string, value: string | boolean): Promise<unknown> {
|
|
256
271
|
const result = await this.proc.setConfigOption(this.sessionId, configId, value);
|
|
257
|
-
|
|
272
|
+
adoptConfigAnswer(this, result, { configId, value });
|
|
273
|
+
publishConfigChange(this, configId);
|
|
258
274
|
return result;
|
|
259
275
|
}
|
|
260
276
|
|
|
@@ -266,19 +282,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
266
282
|
}
|
|
267
283
|
|
|
268
284
|
webState(): Record<string, unknown> {
|
|
269
|
-
return acpWebState(
|
|
270
|
-
sessionId: this.sessionId,
|
|
271
|
-
isStreaming: this.isStreaming,
|
|
272
|
-
isPromptRunning: this.isPromptRunning,
|
|
273
|
-
messageCount: this.messageCount,
|
|
274
|
-
promptCount: this.promptCount,
|
|
275
|
-
assistantCount: this.assistantCount,
|
|
276
|
-
contextUsage: this.contextUsage,
|
|
277
|
-
totalCost: this.totalCost,
|
|
278
|
-
runModel: this.runModel,
|
|
279
|
-
configOptions: this.configOptions,
|
|
280
|
-
harness: this.harness,
|
|
281
|
-
});
|
|
285
|
+
return acpWebState(this);
|
|
282
286
|
}
|
|
283
287
|
|
|
284
288
|
/** Run one turn. The promise IS the turn: ACP resolves `session/prompt` when
|
|
@@ -287,12 +291,19 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
287
291
|
* `session-turns.ts`.
|
|
288
292
|
*/
|
|
289
293
|
startTurn(message: string, images: unknown): unknown {
|
|
294
|
+
// A new prompt is the next request, so the agent flushes any held update
|
|
295
|
+
// itself; a probe would duplicate it.
|
|
296
|
+
this.background.stop();
|
|
290
297
|
this.promptCount += 1;
|
|
291
298
|
this.usage.beginTurn();
|
|
292
299
|
return beginAcpTurn(this, this.turns, message, images);
|
|
293
300
|
}
|
|
294
301
|
|
|
295
302
|
private onNotification(method: string, params: Record<string, unknown>): void {
|
|
303
|
+
// A long turn emits no commands but plenty of `session/update` frames.
|
|
304
|
+
this.idle.reset();
|
|
305
|
+
// A `session/load` replay repeats the whole chat; leave it to the probe.
|
|
306
|
+
if (this.background.consume(method, params)) return;
|
|
296
307
|
handleSessionNotification(this, method, params);
|
|
297
308
|
}
|
|
298
309
|
|
|
@@ -302,36 +313,23 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
302
313
|
|
|
303
314
|
mapUpdate(update: Record<string, unknown>): AgentEvent[] { return this.mapper.mapUpdate(update); }
|
|
304
315
|
|
|
305
|
-
/** Agent→client requests
|
|
306
|
-
* parks the turn, which is the failure this method exists to prevent. */
|
|
316
|
+
/** Agent→client requests: every branch answers or refuses — an unanswered call parks the turn. */
|
|
307
317
|
private onClientRequest(
|
|
308
318
|
id: AcpId,
|
|
309
319
|
method: string,
|
|
310
320
|
params: Record<string, unknown>,
|
|
311
|
-
): Promise<
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
sessionId: this.sessionId,
|
|
315
|
-
accessMode: this.accessMode,
|
|
316
|
-
permissions: this.permissions,
|
|
317
|
-
emit: (event) => this.emit(event),
|
|
318
|
-
}, id, params);
|
|
319
|
-
}
|
|
320
|
-
return Promise.resolve({ answered: false, message: `Kabmo does not implement ${method}` });
|
|
321
|
+
): Promise<AcpClientRequestAnswer> {
|
|
322
|
+
this.idle.reset();
|
|
323
|
+
return handleAcpClientRequest(this, id, method, params);
|
|
321
324
|
}
|
|
322
325
|
|
|
323
326
|
private onExit(info: { code: number | null; stderrTail: string }): void {
|
|
324
327
|
this.destroyed = true;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
+
this.background.stop();
|
|
329
|
+
this.idle.stop();
|
|
330
|
+
if (!this.closing) {
|
|
331
|
+
for (const event of acpExitFailureFrames(this.harness, info)) this.emit(event);
|
|
328
332
|
}
|
|
329
|
-
const detail = info.stderrTail.trim().split('\n').slice(-3).join(' · ');
|
|
330
|
-
this.emit({
|
|
331
|
-
type: 'prompt_error',
|
|
332
|
-
errorMessage: detail || `The ${this.harness} agent exited (code ${info.code ?? 'signal'})`,
|
|
333
|
-
});
|
|
334
|
-
this.emit({ type: 'agent_end', isTerminal: true });
|
|
335
333
|
this.destroyHook?.();
|
|
336
334
|
}
|
|
337
335
|
|
|
@@ -343,6 +341,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
343
341
|
if (this.destroyed) return;
|
|
344
342
|
this.destroyed = true;
|
|
345
343
|
this.closing = true;
|
|
344
|
+
this.background.stop();
|
|
345
|
+
this.idle.stop();
|
|
346
346
|
this.permissions.clear();
|
|
347
347
|
await this.proc.dispose().catch(() => {});
|
|
348
348
|
this.destroyHook?.();
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { AcpTurns, type AcpTurnSeams } from '@/server/lib/harness/acp/turn';
|
|
3
|
+
|
|
4
|
+
type TurnEnd = Parameters<AcpTurnSeams['onTurnEnd']>[0];
|
|
5
|
+
|
|
6
|
+
function harness(overrides: Partial<AcpTurnSeams> = {}): {
|
|
7
|
+
turns: AcpTurns;
|
|
8
|
+
events: { type: string; errorMessage?: string }[];
|
|
9
|
+
ended: Promise<TurnEnd>;
|
|
10
|
+
} {
|
|
11
|
+
const events: { type: string; errorMessage?: string }[] = [];
|
|
12
|
+
const { promise: ended, resolve: resolveEnd } = Promise.withResolvers<TurnEnd>();
|
|
13
|
+
const turns = new AcpTurns({
|
|
14
|
+
emit: (event) => events.push(event as { type: string; errorMessage?: string }),
|
|
15
|
+
prompt: async () => ({}),
|
|
16
|
+
cancelAgent: () => {},
|
|
17
|
+
abandonPrompt: () => {},
|
|
18
|
+
resetMapper: () => {},
|
|
19
|
+
closeMessage: () => [],
|
|
20
|
+
openCalls: () => [],
|
|
21
|
+
onTurnEnd: (info) => resolveEnd(info),
|
|
22
|
+
...overrides,
|
|
23
|
+
});
|
|
24
|
+
return { turns, events, ended };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('AcpTurns failure classification', () => {
|
|
28
|
+
test('a turn that ends without an answer is failed, not completed', async () => {
|
|
29
|
+
const { turns, events, ended } = harness();
|
|
30
|
+
turns.start('do the work', undefined);
|
|
31
|
+
|
|
32
|
+
const info = await ended;
|
|
33
|
+
expect(info.failed).toBe(true);
|
|
34
|
+
expect(info.failure).toContain('without sending an answer');
|
|
35
|
+
expect(events.some((event) => event.type === 'prompt_error')).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('a rejected prompt keeps the agent error and is failed', async () => {
|
|
39
|
+
const { turns, events, ended } = harness({
|
|
40
|
+
prompt: async () => {
|
|
41
|
+
throw new Error('provider exploded');
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
turns.start('do the work', undefined);
|
|
45
|
+
|
|
46
|
+
const info = await ended;
|
|
47
|
+
expect(info.failed).toBe(true);
|
|
48
|
+
expect(info.failure).toBe('provider exploded');
|
|
49
|
+
expect(events.filter((event) => event.type === 'prompt_error')).toHaveLength(1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('an answered turn is not failed', async () => {
|
|
53
|
+
const { turns, ended } = harness({
|
|
54
|
+
closeMessage: () => [
|
|
55
|
+
{
|
|
56
|
+
type: 'message_end',
|
|
57
|
+
message: { role: 'assistant', content: [{ type: 'text', text: 'done' }] },
|
|
58
|
+
},
|
|
59
|
+
] as never,
|
|
60
|
+
});
|
|
61
|
+
turns.start('do the work', undefined);
|
|
62
|
+
|
|
63
|
+
const info = await ended;
|
|
64
|
+
expect(info.failed).toBeUndefined();
|
|
65
|
+
expect(info.closedMessage).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('a cancelled turn is interrupted, never failed', async () => {
|
|
69
|
+
const { turns, ended } = harness({ prompt: () => new Promise(() => {}) });
|
|
70
|
+
turns.start('do the work', undefined);
|
|
71
|
+
// The turn opens on the prompt chain's own microtask; cancel before that is
|
|
72
|
+
// the "nothing to cancel" path and would not emit a turn end.
|
|
73
|
+
await Promise.resolve();
|
|
74
|
+
await Promise.resolve();
|
|
75
|
+
turns.cancel();
|
|
76
|
+
|
|
77
|
+
const info = await ended;
|
|
78
|
+
expect(info.cancelled).toBe(true);
|
|
79
|
+
expect(info.failed).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
22
22
|
import { turnEndFrame } from '@/server/lib/harness/acp/frames';
|
|
23
23
|
|
|
24
|
+
/** What a closed turn reports to its session and the parent notice. */
|
|
25
|
+
export interface AcpTurnEndInfo {
|
|
26
|
+
stopReason?: string;
|
|
27
|
+
closedMessage: boolean;
|
|
28
|
+
message?: unknown;
|
|
29
|
+
cancelled?: boolean;
|
|
30
|
+
failed?: boolean;
|
|
31
|
+
failure?: string | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
export interface AcpTurnSeams {
|
|
25
35
|
/** Push one frame at the session's listeners. */
|
|
26
36
|
emit: (event: AgentEvent) => void;
|
|
@@ -41,7 +51,7 @@ export interface AcpTurnSeams {
|
|
|
41
51
|
* reason, the assistant message the mapper closed (the goal driver audits it),
|
|
42
52
|
* and whether the turn was cancelled (a stop must not be audited).
|
|
43
53
|
*/
|
|
44
|
-
onTurnEnd: (info:
|
|
54
|
+
onTurnEnd: (info: AcpTurnEndInfo) => void;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
export class AcpTurns {
|
|
@@ -86,11 +96,12 @@ export class AcpTurns {
|
|
|
86
96
|
(result) => this.settle(turnId, () => this.finish(result)),
|
|
87
97
|
(error: unknown) =>
|
|
88
98
|
this.settle(turnId, () => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
100
|
+
this.seams.emit({ type: 'prompt_error', errorMessage: message });
|
|
101
|
+
// The agent's own error is the reason. `finish` must not append its
|
|
102
|
+
// generic "no answer" verdict on top of it — the second frame lands
|
|
103
|
+
// last on the client and replaced the useful message.
|
|
104
|
+
this.finish(undefined, true, message);
|
|
94
105
|
}),
|
|
95
106
|
)
|
|
96
107
|
.finally(() => {
|
|
@@ -139,8 +150,10 @@ export class AcpTurns {
|
|
|
139
150
|
|
|
140
151
|
/** Flush the open message, fail abandoned cards, emit the terminal frame. A
|
|
141
152
|
* call left open by a cancelled turn would spin forever — the agent is never
|
|
142
|
-
* going to report an end for work it abandoned.
|
|
143
|
-
|
|
153
|
+
* going to report an end for work it abandoned. `reported` says the caller
|
|
154
|
+
* already emitted the failure reason, so only this module's generic silent
|
|
155
|
+
* verdict is suppressed. */
|
|
156
|
+
private finish(result: { stopReason?: string } | undefined, reported = false, failure?: string): void {
|
|
144
157
|
const flushed = this.seams.closeMessage();
|
|
145
158
|
for (const event of flushed) this.seams.emit(event);
|
|
146
159
|
const closed = flushed.find((event) => event.type === 'message_end')?.message;
|
|
@@ -152,14 +165,24 @@ export class AcpTurns {
|
|
|
152
165
|
// most agents (measured on pi-acp: it answers `session/prompt` with `{}` and
|
|
153
166
|
// sends no frames at all when its provider call fails). Reporting it beats
|
|
154
167
|
// leaving an empty bubble that reads as "the agent had nothing to say".
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
|
|
168
|
+
// Whitespace-only chunks are the same failure with a frame attached: the
|
|
169
|
+
// row renders no text, so the operator still sees nothing. Slash commands
|
|
170
|
+
// are exempt: an extension command is answered locally and correctly
|
|
171
|
+
// produces nothing, and a user's Stop is not a failure either.
|
|
172
|
+
const answered = hasRenderableAnswer(closed) || abandoned.length > 0;
|
|
158
173
|
const cancelled = result?.stopReason === 'cancelled';
|
|
159
|
-
|
|
174
|
+
const slash = this.promptText.trimStart().startsWith('/');
|
|
175
|
+
// `reported` means the caller already emitted the agent's own error. It is
|
|
176
|
+
// still a failed turn, and the parent notice must say so rather than let a
|
|
177
|
+
// refused worker read as completed.
|
|
178
|
+
const failed = !cancelled && !slash && (reported || !answered);
|
|
179
|
+
const reason = failed
|
|
180
|
+
? failure ?? 'The agent ended the turn without sending an answer'
|
|
181
|
+
: null;
|
|
182
|
+
if (!answered && !cancelled && !reported && !slash) {
|
|
160
183
|
this.seams.emit({
|
|
161
184
|
type: 'prompt_error',
|
|
162
|
-
errorMessage: 'The agent ended the turn without sending an answer',
|
|
185
|
+
errorMessage: reason ?? 'The agent ended the turn without sending an answer',
|
|
163
186
|
});
|
|
164
187
|
}
|
|
165
188
|
this.isPromptRunning = false;
|
|
@@ -170,6 +193,24 @@ export class AcpTurns {
|
|
|
170
193
|
closedMessage: flushed.some((event) => event.type === 'message_end'),
|
|
171
194
|
...(closed ? { message: closed } : {}),
|
|
172
195
|
...(cancelled ? { cancelled: true } : {}),
|
|
196
|
+
...(failed ? { failed: true, failure: reason } : {}),
|
|
173
197
|
});
|
|
174
198
|
}
|
|
175
199
|
}
|
|
200
|
+
|
|
201
|
+
/** Does the closed message carry anything the timeline draws? A whitespace-only
|
|
202
|
+
* chunk (or one that carried only an empty text block) opens a message row
|
|
203
|
+
* that renders nothing, which is the same operator-visible failure as no frame
|
|
204
|
+
* at all. Thinking and tool calls are content: they render as their own
|
|
205
|
+
* blocks. */
|
|
206
|
+
function hasRenderableAnswer(message: unknown): boolean {
|
|
207
|
+
if (!message || typeof message !== 'object' || !('content' in message)) return false;
|
|
208
|
+
const content = message.content;
|
|
209
|
+
if (!Array.isArray(content)) return false;
|
|
210
|
+
return content.some((block) => {
|
|
211
|
+
if (!block || typeof block !== 'object') return false;
|
|
212
|
+
if ('text' in block && typeof block.text === 'string') return block.text.trim().length > 0;
|
|
213
|
+
if ('thinking' in block && typeof block.thinking === 'string') return block.thinking.trim().length > 0;
|
|
214
|
+
return 'type' in block && block.type === 'toolCall';
|
|
215
|
+
});
|
|
216
|
+
}
|
|
@@ -36,8 +36,18 @@ export async function resumeSession(invoke: AcpInvoke, sessionId: string, cwd: s
|
|
|
36
36
|
return invoke('session/resume', { sessionId, cwd, mcpServers: [] }, timeoutMs);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export async function forkSession(
|
|
40
|
-
|
|
39
|
+
export async function forkSession(
|
|
40
|
+
invoke: AcpInvoke,
|
|
41
|
+
sessionId: string,
|
|
42
|
+
cwd: string,
|
|
43
|
+
timeoutMs = 120_000,
|
|
44
|
+
target?: Record<string, unknown>,
|
|
45
|
+
): Promise<AcpSessionNewResult> {
|
|
46
|
+
return invoke<AcpSessionNewResult>(
|
|
47
|
+
'session/fork',
|
|
48
|
+
{ sessionId, cwd, mcpServers: [], ...(target ? { target } : {}) },
|
|
49
|
+
timeoutMs,
|
|
50
|
+
);
|
|
41
51
|
}
|
|
42
52
|
|
|
43
53
|
export async function listSessions(invoke: AcpInvoke, cwd?: string, timeoutMs = 60_000): Promise<AcpSessionInfo[]> {
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The boot pass: every restart re-checks the harnesses the user keeps ON.
|
|
8
|
+
*
|
|
9
|
+
* The requirement is a ROSTER question before it is a probe question, so the
|
|
10
|
+
* cases here hold the selection: off means not spawned, built-in means not
|
|
11
|
+
* spawned, a missing launch command means not spawned. Only then "and the answer
|
|
12
|
+
* is stored" — the settings card reads the cache, not this pass.
|
|
13
|
+
*
|
|
14
|
+
* The seams (`ids`, `available`, `probe`) exist for these tests: a real probe
|
|
15
|
+
* spawns an agent, and a suite that depends on which binaries a runner happens to
|
|
16
|
+
* have is a suite that fails only on CI. The production defaults are the real
|
|
17
|
+
* catalog, `commandAvailable` and `probeWithConfig`.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
21
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
22
|
+
import {
|
|
23
|
+
autoProbeTargets,
|
|
24
|
+
runAutoProbe,
|
|
25
|
+
type AutoProbeOptions,
|
|
26
|
+
} from '@/server/lib/harness/auto-probe.server';
|
|
27
|
+
import type { HarnessProbe } from '@/server/lib/harness/capabilities';
|
|
28
|
+
import { loadProbes, probes } from '@/server/lib/harness/probe-cache.server';
|
|
29
|
+
import { saveHarnessEnabled } from '@/server/lib/harness/enabled.server';
|
|
30
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
31
|
+
|
|
32
|
+
function probe(id: HarnessId): HarnessProbe {
|
|
33
|
+
return {
|
|
34
|
+
harness: id,
|
|
35
|
+
capabilities: {
|
|
36
|
+
configModel: 5, configThinking: 6, configMode: 5, modeValues: ['plan'],
|
|
37
|
+
loadSession: true, listSessions: true, forkSession: true, deleteSession: false,
|
|
38
|
+
resumeSession: true, closeSession: true, hasUsage: false, hasPlan: false, steerMode: null,
|
|
39
|
+
agentVersion: '1.0.0',
|
|
40
|
+
},
|
|
41
|
+
models: [], thinking: [], modes: [], probedAt: Date.now(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const allAvailable = (): boolean => true;
|
|
46
|
+
|
|
47
|
+
beforeEach(async () => {
|
|
48
|
+
await isolateDb();
|
|
49
|
+
probes().clear();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
await releaseDb();
|
|
54
|
+
probes().clear();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterAll(async () => {
|
|
58
|
+
await releaseDb();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('autoProbeTargets', () => {
|
|
62
|
+
test('skips a switched-off harness and the built-in transport', async () => {
|
|
63
|
+
await saveHarnessEnabled('claude', false);
|
|
64
|
+
const checked: string[] = [];
|
|
65
|
+
const targets = await autoProbeTargets({
|
|
66
|
+
ids: ['omp-rpc', 'omp-acp', 'claude'],
|
|
67
|
+
available: (id) => {
|
|
68
|
+
checked.push(id);
|
|
69
|
+
return true;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
expect(targets).toEqual(['omp-acp']);
|
|
73
|
+
// The built-in transport never reaches the availability check: there is no
|
|
74
|
+
// agent behind it to ask about.
|
|
75
|
+
expect(checked).toEqual(['omp-acp']);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('skips a harness whose launch command is not resolvable', async () => {
|
|
79
|
+
const targets = await autoProbeTargets({
|
|
80
|
+
ids: ['omp-acp', 'claude', 'cursor'],
|
|
81
|
+
available: (id) => id === 'omp-acp',
|
|
82
|
+
});
|
|
83
|
+
expect(targets).toEqual(['omp-acp']);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('runAutoProbe', () => {
|
|
88
|
+
test('probes every target and stores each answer', async () => {
|
|
89
|
+
const seen: HarnessId[] = [];
|
|
90
|
+
const options: AutoProbeOptions = {
|
|
91
|
+
ids: ['omp-acp', 'claude'],
|
|
92
|
+
cwd: '/tmp',
|
|
93
|
+
available: allAvailable,
|
|
94
|
+
probe: async (id, cwd) => {
|
|
95
|
+
expect(cwd).toBe('/tmp');
|
|
96
|
+
seen.push(id);
|
|
97
|
+
return probe(id);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const outcome = await runAutoProbe(options);
|
|
101
|
+
expect(outcome.failed).toEqual([]);
|
|
102
|
+
expect(outcome.probed).toEqual(['omp-acp', 'claude']);
|
|
103
|
+
expect(seen).toEqual(['omp-acp', 'claude']);
|
|
104
|
+
expect((await loadProbes()).get('claude')?.capabilities.agentVersion).toBe('1.0.0');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('a probe that throws is reported and does not stop the pass', async () => {
|
|
108
|
+
const outcome = await runAutoProbe({
|
|
109
|
+
ids: ['omp-acp', 'claude'],
|
|
110
|
+
available: allAvailable,
|
|
111
|
+
probe: async (id) => {
|
|
112
|
+
if (id === 'omp-acp') throw new Error('boom');
|
|
113
|
+
return probe(id);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
expect(outcome.failed).toEqual([{ id: 'omp-acp', error: 'boom' }]);
|
|
117
|
+
expect(outcome.probed).toEqual(['claude']);
|
|
118
|
+
expect(probes().has('omp-acp')).toBe(false);
|
|
119
|
+
expect(probes().has('claude')).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
});
|