@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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The New Chat card's harness capture.
|
|
8
|
+
*
|
|
9
|
+
* The card has no harness picker, so the agent that owns the chat it was opened
|
|
10
|
+
* FROM is the only source for the new chat's spawn. A capture that read the
|
|
11
|
+
* current render instead of the open-time pick would silently change when the
|
|
12
|
+
* sidebar's harness row settles — and a capture that was never taken spawned the
|
|
13
|
+
* new chat on omp's RPC default.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { h, render } from 'preact';
|
|
19
|
+
import { act } from 'preact/test-utils';
|
|
20
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
21
|
+
import { useNewChatOpen, type NewChatOpen, type NewChatOpenDeps } from '@/client/hooks/chat/timeline/new-chat-open';
|
|
22
|
+
|
|
23
|
+
let container: HTMLElement | undefined;
|
|
24
|
+
let hook: NewChatOpen | null = null;
|
|
25
|
+
|
|
26
|
+
function Probe({ deps }: { deps: NewChatOpenDeps }) {
|
|
27
|
+
hook = useNewChatOpen(deps);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function mount(deps: NewChatOpenDeps): Promise<void> {
|
|
32
|
+
container ??= document.body.appendChild(document.createElement('div'));
|
|
33
|
+
await act(async () => {
|
|
34
|
+
render(h(Probe, { deps }), container as HTMLElement);
|
|
35
|
+
});
|
|
36
|
+
await act(async () => {});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function deps(overrides: Partial<NewChatOpenDeps> = {}): NewChatOpenDeps {
|
|
40
|
+
return { folders: [], sessionId: 'sess-aaa', selectedFolderId: null, ...overrides };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
beforeAll(() => {
|
|
44
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterAll(() => {
|
|
48
|
+
restoreDomGlobals();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
if (container) render(null, container);
|
|
53
|
+
container?.remove();
|
|
54
|
+
container = undefined;
|
|
55
|
+
hook = null;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('useNewChatOpen', () => {
|
|
59
|
+
test('captures the source chat harness at open time', async () => {
|
|
60
|
+
await mount(deps({ harness: 'opencode' }));
|
|
61
|
+
|
|
62
|
+
await act(async () => { hook?.open('halo'); });
|
|
63
|
+
|
|
64
|
+
expect(hook?.content).toBe('halo');
|
|
65
|
+
expect(hook?.harness).toBe('opencode');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('a card opened from a chat with no resolved harness carries none', async () => {
|
|
69
|
+
await mount(deps());
|
|
70
|
+
|
|
71
|
+
await act(async () => { hook?.open('halo'); });
|
|
72
|
+
|
|
73
|
+
expect(hook?.content).toBe('halo');
|
|
74
|
+
expect(hook?.harness).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('closing the card drops the capture with the content', async () => {
|
|
78
|
+
await mount(deps({ harness: 'omp-acp' }));
|
|
79
|
+
await act(async () => { hook?.open('halo'); });
|
|
80
|
+
|
|
81
|
+
await act(async () => { hook?.close(); });
|
|
82
|
+
|
|
83
|
+
expect(hook?.content).toBeNull();
|
|
84
|
+
expect(hook?.harness).toBeUndefined();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* The folder resolution mirrors `useNewChatSubmit` — the active session's
|
|
16
16
|
* folder, else the composer's pick — because a prewarm in a different cwd is a
|
|
17
|
-
* process the send never claims, which costs a spawn AND a kill.
|
|
17
|
+
* process the send never claims, which costs a spawn AND a kill. The HARNESS is
|
|
18
|
+
* the second half of that rule: the pool holds omp RPC children, so a card
|
|
19
|
+
* opened from an ACP chat (whose new chat stays on that agent) warms nothing.
|
|
18
20
|
*/
|
|
19
21
|
|
|
20
22
|
import { useCallback, useState } from 'preact/hooks';
|
|
@@ -27,6 +29,13 @@ export interface NewChatOpen {
|
|
|
27
29
|
content: string | null;
|
|
28
30
|
/** Attachments of the row the card was opened from. */
|
|
29
31
|
attachments: Attachment[];
|
|
32
|
+
/**
|
|
33
|
+
* The harness of the chat the card was opened FROM, captured at open time.
|
|
34
|
+
* A New Chat from an ACP answer must stay on that agent: the dialog has no
|
|
35
|
+
* harness picker, and a spawn that omitted it quietly started the new chat on
|
|
36
|
+
* omp's RPC transport instead of the agent that wrote the answer.
|
|
37
|
+
*/
|
|
38
|
+
harness?: string;
|
|
30
39
|
/** Open the card on `content`, warming the child for the chat it will create. */
|
|
31
40
|
open: (content: string, attachments?: Attachment[]) => void;
|
|
32
41
|
close: () => void;
|
|
@@ -37,24 +46,33 @@ export interface NewChatOpenDeps {
|
|
|
37
46
|
/** Session the card was opened from — the scope the prewarm inherits. */
|
|
38
47
|
sessionId: string | null;
|
|
39
48
|
selectedFolderId: number | null;
|
|
49
|
+
/** The harness that owns `sessionId`, carried onto the new chat's spawn. */
|
|
50
|
+
harness?: string;
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
export function useNewChatOpen({ folders, sessionId, selectedFolderId }: NewChatOpenDeps): NewChatOpen {
|
|
53
|
+
export function useNewChatOpen({ folders, sessionId, selectedFolderId, harness }: NewChatOpenDeps): NewChatOpen {
|
|
43
54
|
const [content, setContent] = useState<string | null>(null);
|
|
44
55
|
const [attachments, setAttachments] = useState<Attachment[]>([]);
|
|
56
|
+
/** Captured on open, cleared with the card: the picker is not in the dialog. */
|
|
57
|
+
const [openedHarness, setOpenedHarness] = useState<string | undefined>(undefined);
|
|
45
58
|
|
|
46
59
|
const open = useCallback((next: string, rows?: Attachment[]) => {
|
|
47
60
|
const folderId = activeProjectForSession(folders, sessionId).folder?.id ?? selectedFolderId ?? undefined;
|
|
48
61
|
const cwd = spawnCwdForNewSession(folders, sessionId, folderId);
|
|
49
|
-
|
|
62
|
+
// The prewarm pool holds `omp --mode rpc-ui` children only. A card opened
|
|
63
|
+
// from an ACP chat now spawns that same agent, so warming omp would start a
|
|
64
|
+
// process the send never claims (then idle-reap it).
|
|
65
|
+
if (cwd && (!harness || harness === 'omp-rpc')) triggerSessionPrewarm(cwd);
|
|
50
66
|
setContent(next);
|
|
51
67
|
setAttachments(rows ?? []);
|
|
52
|
-
|
|
68
|
+
setOpenedHarness(harness);
|
|
69
|
+
}, [folders, sessionId, selectedFolderId, harness]);
|
|
53
70
|
|
|
54
71
|
const close = useCallback(() => {
|
|
55
72
|
setContent(null);
|
|
56
73
|
setAttachments([]);
|
|
74
|
+
setOpenedHarness(undefined);
|
|
57
75
|
}, []);
|
|
58
76
|
|
|
59
|
-
return { content, attachments, open, close };
|
|
77
|
+
return { content, attachments, ...(openedHarness ? { harness: openedHarness } : {}), open, close };
|
|
60
78
|
}
|
|
@@ -28,7 +28,7 @@ import type { Attachment, ChatMessageData, WorkspaceFolderData } from '@/shared/
|
|
|
28
28
|
|
|
29
29
|
let container: HTMLElement | undefined;
|
|
30
30
|
/** The hook result of the most recent render. */
|
|
31
|
-
let submit: ((text: string, attachments: Attachment[]) => void) | null = null;
|
|
31
|
+
let submit: ((text: string, attachments: Attachment[], harness?: string) => void) | null = null;
|
|
32
32
|
|
|
33
33
|
function Probe({ deps }: { deps: NewChatSubmitDeps }) {
|
|
34
34
|
submit = useNewChatSubmit(deps);
|
|
@@ -38,7 +38,7 @@ function Probe({ deps }: { deps: NewChatSubmitDeps }) {
|
|
|
38
38
|
interface Recorded {
|
|
39
39
|
/** Each send with the SCOPE the deps record carried when the callback was
|
|
40
40
|
* built — the regression this hook exists for. */
|
|
41
|
-
sends: Array<{ text: string; attachments: Attachment[]; scope: string | null }>;
|
|
41
|
+
sends: Array<{ text: string; attachments: Attachment[]; scope: string | null; harness?: string }>;
|
|
42
42
|
messages: ChatMessageData[];
|
|
43
43
|
/** The URL the hook's `setSearchParams` writes into. */
|
|
44
44
|
searchParams: URLSearchParams;
|
|
@@ -64,8 +64,8 @@ function makeDeps(overrides: Partial<NewChatSubmitDeps> = {}): Recorded {
|
|
|
64
64
|
setLocalMessages: (next) => {
|
|
65
65
|
messages.splice(0, messages.length, ...(typeof next === 'function' ? next(messages) : next));
|
|
66
66
|
},
|
|
67
|
-
executeSend: async (text, attachments) => {
|
|
68
|
-
sends.push({ text, attachments, scope });
|
|
67
|
+
executeSend: async (text, attachments, options) => {
|
|
68
|
+
sends.push({ text, attachments, scope, ...(options?.harness ? { harness: options.harness } : {}) });
|
|
69
69
|
return { ok: true, busy: false };
|
|
70
70
|
},
|
|
71
71
|
...overrides,
|
|
@@ -137,6 +137,34 @@ describe('useNewChatSubmit', () => {
|
|
|
137
137
|
expect(adopted.sends).toEqual([{ text: 'halo', attachments: [], scope: pendingId }]);
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
+
test('the parked harness rides the first send, so an ACP chat stays on its agent', async () => {
|
|
141
|
+
const opened = makeDeps({ sessionId: 'sess-aaa' });
|
|
142
|
+
const ui = await mount(opened.deps);
|
|
143
|
+
|
|
144
|
+
await act(async () => { submit?.('halo', [], 'opencode'); });
|
|
145
|
+
const pendingId = opened.searchParams.get('sessionId') ?? '';
|
|
146
|
+
|
|
147
|
+
const adopted = makeDeps({ sessionId: pendingId, folders: folderOwning(pendingId) });
|
|
148
|
+
await ui.rerender(adopted.deps);
|
|
149
|
+
|
|
150
|
+
// The dialog has no harness picker: without this the server defaulted the
|
|
151
|
+
// spawn to omp-rpc and the new chat lost the agent that wrote the answer.
|
|
152
|
+
expect(adopted.sends).toEqual([{ text: 'halo', attachments: [], scope: pendingId, harness: 'opencode' }]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('a send with no inherited harness leaves the spawn on the server default', async () => {
|
|
156
|
+
const opened = makeDeps({ sessionId: 'sess-aaa' });
|
|
157
|
+
const ui = await mount(opened.deps);
|
|
158
|
+
|
|
159
|
+
await act(async () => { submit?.('halo', []); });
|
|
160
|
+
const pendingId = opened.searchParams.get('sessionId') ?? '';
|
|
161
|
+
|
|
162
|
+
const adopted = makeDeps({ sessionId: pendingId, folders: folderOwning(pendingId) });
|
|
163
|
+
await ui.rerender(adopted.deps);
|
|
164
|
+
|
|
165
|
+
expect(adopted.sends).toEqual([{ text: 'halo', attachments: [], scope: pendingId }]);
|
|
166
|
+
});
|
|
167
|
+
|
|
140
168
|
test('the pending session carries the workspace the chat was started from', async () => {
|
|
141
169
|
// The first send SPAWNS an omp session in the folder's cwd. A dialog opened
|
|
142
170
|
// from a session picked in the sidebar had no `folderId` in the URL, so the
|
|
@@ -37,12 +37,20 @@ export interface NewChatSubmitDeps {
|
|
|
37
37
|
selectedFolderId: number | null;
|
|
38
38
|
setSearchParams: SetSearchParams;
|
|
39
39
|
setLocalMessages: Dispatch<SetStateAction<ChatMessageData[]>>;
|
|
40
|
-
executeSend: (text: string, attachments: Attachment[]) => Promise<PromptDispatchResult>;
|
|
40
|
+
executeSend: (text: string, attachments: Attachment[], options?: { harness?: string | null }) => Promise<PromptDispatchResult>;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* The dialog's send handler. `harness` is the source chat's agent, captured by
|
|
45
|
+
* `useNewChatOpen` when the card opened: the dialog has no harness picker, and
|
|
46
|
+
* a spawn that omitted the field started the new chat on omp's RPC transport
|
|
47
|
+
* even when the answer came from another agent.
|
|
48
|
+
*/
|
|
49
|
+
export function useNewChatSubmit(
|
|
50
|
+
deps: NewChatSubmitDeps,
|
|
51
|
+
): (text: string, attachments: Attachment[], harness?: string) => void {
|
|
44
52
|
const { sessionId, folders, selectedFolderId, setSearchParams, setLocalMessages, executeSend } = deps;
|
|
45
|
-
const parkedRef = useRef<{ pendingId: string; text: string; attachments: Attachment[] } | null>(null);
|
|
53
|
+
const parkedRef = useRef<{ pendingId: string; text: string; attachments: Attachment[]; harness?: string } | null>(null);
|
|
46
54
|
|
|
47
55
|
useEffect(() => {
|
|
48
56
|
const parked = parkedRef.current;
|
|
@@ -51,15 +59,19 @@ export function useNewChatSubmit(deps: NewChatSubmitDeps): (text: string, attach
|
|
|
51
59
|
// instead — it stays parked and is overwritten by the next New Chat.
|
|
52
60
|
if (!parked || sessionId !== parked.pendingId) return;
|
|
53
61
|
parkedRef.current = null;
|
|
54
|
-
void executeSend(
|
|
62
|
+
void executeSend(
|
|
63
|
+
parked.text,
|
|
64
|
+
parked.attachments,
|
|
65
|
+
parked.harness ? { harness: parked.harness } : undefined,
|
|
66
|
+
);
|
|
55
67
|
}, [sessionId, executeSend]);
|
|
56
68
|
|
|
57
|
-
return useCallback((text, attachments) => {
|
|
69
|
+
return useCallback((text, attachments, harness) => {
|
|
58
70
|
// The store mints the pending id and owns the row it stands for: the
|
|
59
71
|
// sidebar/navbar show a default title immediately, and the row survives the
|
|
60
72
|
// `new-…` → omp-UUID switch when the first send spawns.
|
|
61
73
|
const pendingId = startPendingSession(activeProjectForSession(folders, sessionId).folder?.id ?? selectedFolderId);
|
|
62
|
-
parkedRef.current = { pendingId, text, attachments };
|
|
74
|
+
parkedRef.current = { pendingId, text, attachments, ...(harness ? { harness } : {}) };
|
|
63
75
|
setSearchParams((prev) => {
|
|
64
76
|
const next = new URLSearchParams(prev);
|
|
65
77
|
next.set('sessionId', pendingId);
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
23
|
-
import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
|
|
23
|
+
import { buildPromptText, DelegationPromptError } from '@/client/hooks/chat/timeline/prompt-text';
|
|
24
24
|
import { invalidateComposerCache } from '@/shared/lib/chat/composer/client';
|
|
25
25
|
|
|
26
26
|
type TextFile = Parameters<typeof buildPromptText>[1][number] & { missing?: boolean };
|
|
@@ -60,6 +60,39 @@ function file(name: string, content: string): TextFile {
|
|
|
60
60
|
return { name, mimeType: 'text/plain', content, size: content.length };
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
describe('buildPromptText harness delegation', () => {
|
|
64
|
+
test('a bare harness mention compiles to a default-model spawn command', async () => {
|
|
65
|
+
const prompt = await buildPromptText('@claude review src/auth', []);
|
|
66
|
+
expect(prompt).toContain('[kabmo orchestration contract]');
|
|
67
|
+
expect(prompt).toContain('--harness claude --prompt-file -');
|
|
68
|
+
expect(prompt).not.toContain('--model');
|
|
69
|
+
expect(prompt).toContain('review src/auth');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('an explicit model rides the command', async () => {
|
|
73
|
+
const prompt = await buildPromptText('@harness:claude:opus review this', []);
|
|
74
|
+
expect(prompt).toContain('--harness claude --model opus');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('an omp agent mention still becomes a task directive', async () => {
|
|
78
|
+
const prompt = await buildPromptText('fix @architect the bug', []);
|
|
79
|
+
expect(prompt.startsWith('Use the task tool')).toBe(true);
|
|
80
|
+
expect(prompt).not.toContain('[kabmo orchestration contract]');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('two harnesses in one paragraph are refused before sending', async () => {
|
|
84
|
+
await expect(buildPromptText('@claude and @codex review', [])).rejects.toBeInstanceOf(
|
|
85
|
+
DelegationPromptError,
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('an unknown namespaced harness is refused', async () => {
|
|
90
|
+
await expect(buildPromptText('@harness:nope do it', [])).rejects.toBeInstanceOf(
|
|
91
|
+
DelegationPromptError,
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
63
96
|
describe('buildPromptText mentions', () => {
|
|
64
97
|
test('an agent mention becomes a task-tool delegation directive', async () => {
|
|
65
98
|
const result = await buildPromptText('fix @architect the bug', []);
|
|
@@ -4,26 +4,43 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Prompt assembly for Kabmo composer: rewrite composer-level mentions
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Prompt assembly for Kabmo composer: rewrite composer-level mentions into what
|
|
8
|
+
* the agent actually receives, then inline the text attachments the user
|
|
9
|
+
* dropped in. Extracted from the send path so that hook stays under the repo's
|
|
10
|
+
* per-file size ceiling.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { composeMessageWithTextAttachments } from '@/shared/lib/chat/attachments';
|
|
14
14
|
import { loadAgentNames } from '@/shared/lib/chat/composer/client';
|
|
15
|
+
import {
|
|
16
|
+
delegationErrorText,
|
|
17
|
+
formatDelegationPrompt,
|
|
18
|
+
parseHarnessMentions,
|
|
19
|
+
} from '@/shared/lib/chat/composer/delegation';
|
|
15
20
|
import { translateAgentMentions, translateFileMentions } from '@/shared/lib/chat/composer/translate';
|
|
16
21
|
|
|
17
22
|
type TextFileAttachment = Parameters<typeof composeMessageWithTextAttachments>[1][number];
|
|
18
23
|
|
|
24
|
+
/** A mention the composer cannot send, with the sentence the user needs. */
|
|
25
|
+
export class DelegationPromptError extends Error {
|
|
26
|
+
constructor(readonly reason: string) {
|
|
27
|
+
super(reason);
|
|
28
|
+
this.name = 'DelegationPromptError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
19
32
|
/**
|
|
20
|
-
* Build the outgoing prompt.
|
|
21
|
-
* task-tool delegation directive at send time (oh-my-pi has no `@agent`
|
|
22
|
-
* syntax); translation failures fall back to the raw prompt.
|
|
33
|
+
* Build the outgoing prompt.
|
|
23
34
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
35
|
+
* `@harness` mentions are compiled into an orchestrator contract plus one exact
|
|
36
|
+
* `kabmo session spawn` command per worker; the paragraph's own words become
|
|
37
|
+
* that worker's TASK. A bare `@claude` carries no model, so the spawn uses the
|
|
38
|
+
* harness's configured default (or the agent's own).
|
|
39
|
+
*
|
|
40
|
+
* `@agent` mentions are omp's subagent syntax and are rewritten only for the
|
|
41
|
+
* harnesses that have it. A file whose bytes could not be read is left OUT
|
|
42
|
+
* rather than inlined empty: an empty fenced block tells the model the file
|
|
43
|
+
* exists and says nothing, which is worse than not mentioning it.
|
|
27
44
|
*/
|
|
28
45
|
export async function buildPromptText(
|
|
29
46
|
text: string,
|
|
@@ -31,16 +48,26 @@ export async function buildPromptText(
|
|
|
31
48
|
options: { includeAgents?: boolean } = {},
|
|
32
49
|
): Promise<string> {
|
|
33
50
|
const readable = textFiles.filter((file) => !('missing' in file && file.missing));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
const names = options.includeAgents === false
|
|
52
|
+
? []
|
|
53
|
+
: await loadAgentNames().catch(() => []);
|
|
54
|
+
const plan = parseHarnessMentions(text, { agentNames: names });
|
|
55
|
+
const refusal = delegationErrorText(plan);
|
|
56
|
+
if (refusal) throw new DelegationPromptError(refusal);
|
|
57
|
+
|
|
58
|
+
let translated: string;
|
|
59
|
+
if (plan.delegations.length > 0) {
|
|
60
|
+
// The orchestrator's own paragraphs still get omp's agent rewrite; a
|
|
61
|
+
// worker task does not, because that text is read by a different harness
|
|
62
|
+
// and `task` is not its vocabulary.
|
|
63
|
+
if (options.includeAgents !== false && names.length > 0) {
|
|
64
|
+
plan.orchestratorText = translateAgentMentions(plan.orchestratorText, names).text;
|
|
65
|
+
}
|
|
66
|
+
translated = formatDelegationPrompt(plan);
|
|
67
|
+
} else {
|
|
68
|
+
translated = text;
|
|
69
|
+
if (options.includeAgents !== false && names.length > 0) {
|
|
70
|
+
translated = translateAgentMentions(translated, names).text;
|
|
44
71
|
}
|
|
45
72
|
}
|
|
46
73
|
// File mentions are namespaced (`@file:`) by the picker; strip the namespace
|
|
@@ -174,11 +174,23 @@ describe('handleRetry', () => {
|
|
|
174
174
|
expect(h.sent[0]?.attachments).toEqual([{ name: 'shot.png', preview: 'data:image/png;base64,QUJD', type: 'image/png', id: 'attachment-1' }]);
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
test('an
|
|
177
|
+
test('an omp-acp chat rewinds the shared JSONL, then re-sends the turn', async () => {
|
|
178
|
+
// `omp-acp` writes the SAME session file as `omp-rpc`; the endpoint tears the
|
|
179
|
+
// ACP child down first, so the retry is a real rewind rather than a refusal.
|
|
178
180
|
const h = makeHarness([user('u1'), ai('a1')], { harness: 'omp-acp' });
|
|
179
181
|
h.actions.handleRetry('u1');
|
|
180
182
|
await h.settled;
|
|
181
183
|
|
|
184
|
+
expect(h.rewinds.map((r) => r.entryId)).toEqual(['u1']);
|
|
185
|
+
expect(h.sent.map((s) => s.text)).toEqual(['do the thing']);
|
|
186
|
+
expect(h.errors).toEqual([]);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('another ACP agent refuses Retry instead of truncating a file it does not read', async () => {
|
|
190
|
+
const h = makeHarness([user('u1'), ai('a1')], { harness: 'claude' });
|
|
191
|
+
h.actions.handleRetry('u1');
|
|
192
|
+
await h.settled;
|
|
193
|
+
|
|
182
194
|
expect(h.rewinds).toEqual([]);
|
|
183
195
|
expect(h.sent).toEqual([]);
|
|
184
196
|
expect(h.errors[0]).toContain('not available on this harness');
|
|
@@ -248,6 +260,17 @@ describe('handleUndo', () => {
|
|
|
248
260
|
expect(h.messages.map((m) => m.id)).toEqual(['u1', 'a1']);
|
|
249
261
|
});
|
|
250
262
|
|
|
263
|
+
test('an omp-acp chat rewinds the shared JSONL and applies the truncated transcript', async () => {
|
|
264
|
+
const h = makeHarness([user('u1'), ai('a1'), user('u2'), ai('a2')], { harness: 'omp-acp' });
|
|
265
|
+
const ok = await h.actions.handleUndo('u2', 'second ask');
|
|
266
|
+
|
|
267
|
+
expect(ok).toBe(true);
|
|
268
|
+
expect(h.rewinds.map((r) => r.entryId)).toEqual(['u2']);
|
|
269
|
+
expect(h.drafts).toEqual(['second ask']);
|
|
270
|
+
expect(h.messages).toEqual([]);
|
|
271
|
+
expect(h.errors).toEqual([]);
|
|
272
|
+
});
|
|
273
|
+
|
|
251
274
|
test('an ACP chat refuses Undo rather than truncating a file its agent does not read', async () => {
|
|
252
275
|
const h = makeHarness([user('u1'), ai('a1')], { harness: 'claude' });
|
|
253
276
|
const ok = await h.actions.handleUndo('u1', 'first ask');
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
*
|
|
14
14
|
* - a real omp session rewinds its JSONL first — dropping only the client's
|
|
15
15
|
* rows left the abandoned turn on disk, so a reload resurrected the answer
|
|
16
|
-
* that was supposed to be replaced
|
|
16
|
+
* that was supposed to be replaced. Both omp transports share that file:
|
|
17
|
+
* the endpoint tears the live child down first, so an `omp-acp` chat is
|
|
18
|
+
* rewound exactly like an `omp-rpc` one;
|
|
17
19
|
* - the id Retry receives is the run's OPENING USER row, not the AI row the
|
|
18
20
|
* footer describes (a run spans thinking / tool / answer rows, so requiring
|
|
19
21
|
* the owner's immediate predecessor to be a user turn made the button a
|
|
@@ -27,13 +29,15 @@
|
|
|
27
29
|
import type { Dispatch, SetStateAction } from 'preact/compat';
|
|
28
30
|
import type { Attachment, ChatMessageData, OmpAgentHandle, PromptDispatchResult } from '@/shared/types';
|
|
29
31
|
import { toAttachmentList } from '@/shared/lib/chat/attachments';
|
|
32
|
+
import { harnessSupportsRewind } from '@/shared/lib/harness/rewind';
|
|
30
33
|
import { requestRewind } from '@/client/hooks/chat/timeline/rewind';
|
|
31
34
|
|
|
32
35
|
export interface RewindActionsDeps {
|
|
33
36
|
isGenerating: boolean;
|
|
34
37
|
isOmpSession: boolean;
|
|
35
|
-
/** The harness behind the chat.
|
|
36
|
-
*
|
|
38
|
+
/** The harness behind the chat. Only the harnesses that write omp's JSONL
|
|
39
|
+
* (`omp-rpc`, `omp-acp`) can be rewound; every other ACP agent keeps its own
|
|
40
|
+
* transcript. See `harnessSupportsRewind`. */
|
|
37
41
|
harness?: string | null;
|
|
38
42
|
/** Active session id; the omp paths post the rewind against it. */
|
|
39
43
|
sessionId: string | null;
|
|
@@ -88,12 +92,12 @@ export function createRewindActions(deps: RewindActionsDeps): RewindActions {
|
|
|
88
92
|
const handleUndo = async (msgId: string, content?: string): Promise<boolean> => {
|
|
89
93
|
stopActiveRun();
|
|
90
94
|
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
if (isOmpSession && harness
|
|
96
|
-
reportActionError('Undo is not available on this harness:
|
|
95
|
+
// Both omp transports share the JSONL and can be rewound; every other ACP
|
|
96
|
+
// agent keeps its own transcript and has no truncation, so truncating
|
|
97
|
+
// Kabmo's copy would leave the child answering from turns the timeline no
|
|
98
|
+
// longer shows. Refuse in words instead of a 404 or a silent divergence.
|
|
99
|
+
if (isOmpSession && !harnessSupportsRewind(harness)) {
|
|
100
|
+
reportActionError('Undo is not available on this harness: its agent keeps its own transcript and Kabmo cannot truncate it.');
|
|
97
101
|
return false;
|
|
98
102
|
}
|
|
99
103
|
|
|
@@ -145,8 +149,8 @@ export function createRewindActions(deps: RewindActionsDeps): RewindActions {
|
|
|
145
149
|
const handleRetry = (msgId: string) => {
|
|
146
150
|
stopActiveRun();
|
|
147
151
|
|
|
148
|
-
if (isOmpSession && harness
|
|
149
|
-
reportActionError('Retry is not available on this harness:
|
|
152
|
+
if (isOmpSession && !harnessSupportsRewind(harness)) {
|
|
153
|
+
reportActionError('Retry is not available on this harness: its agent keeps its own transcript and Kabmo cannot truncate it.');
|
|
150
154
|
return;
|
|
151
155
|
}
|
|
152
156
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which model the transcript's footer names.
|
|
8
|
+
*
|
|
9
|
+
* The sidebar's `runModel` belongs to the RUN row beside it: correct while a run
|
|
10
|
+
* is live (it is renamed from the agent's own `get_state`), stale the moment a
|
|
11
|
+
* chat switches model while idle. The session's own metadata is the answer
|
|
12
|
+
* there, and it is what `/api/chat/:id` re-reads from the agent.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { runIdentityFor } from '@/client/hooks/chat/timeline/run-identity';
|
|
17
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
18
|
+
|
|
19
|
+
const folder = (session: Record<string, unknown>): WorkspaceFolderData =>
|
|
20
|
+
({ sessions: [session] }) as unknown as WorkspaceFolderData;
|
|
21
|
+
|
|
22
|
+
describe('runIdentityFor', () => {
|
|
23
|
+
test('an idle chat prefers the session metadata over the last run row', () => {
|
|
24
|
+
const identity = runIdentityFor({
|
|
25
|
+
folders: [folder({ id: 's1', streamStatus: 'finish', runModel: { provider: 'p', modelId: 'first' } })],
|
|
26
|
+
sessionId: 's1',
|
|
27
|
+
sessionData: { model: { provider: 'p', modelId: 'second' } },
|
|
28
|
+
modelNames: { second: 'Second' },
|
|
29
|
+
});
|
|
30
|
+
expect(identity).toEqual({ sessionProvider: 'p', sessionModelName: 'Second' });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('a live run keeps the sidebar identity the agent is actually serving', () => {
|
|
34
|
+
const identity = runIdentityFor({
|
|
35
|
+
folders: [folder({ id: 's1', streamStatus: 'stream', runModel: { provider: 'p', modelId: 'served' } })],
|
|
36
|
+
sessionId: 's1',
|
|
37
|
+
sessionData: { model: { provider: 'p', modelId: 'stale' } },
|
|
38
|
+
modelNames: {},
|
|
39
|
+
});
|
|
40
|
+
expect(identity).toEqual({ sessionProvider: 'p', sessionModelName: 'served' });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('falls back to the run row when the session metadata has no model', () => {
|
|
44
|
+
const identity = runIdentityFor({
|
|
45
|
+
folders: [folder({ id: 's1', streamStatus: 'finish', runModel: { provider: 'p', modelId: 'last' } })],
|
|
46
|
+
sessionId: 's1',
|
|
47
|
+
sessionData: null,
|
|
48
|
+
modelNames: {},
|
|
49
|
+
});
|
|
50
|
+
expect(identity).toEqual({ sessionProvider: 'p', sessionModelName: 'last' });
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -15,31 +15,43 @@
|
|
|
15
15
|
|
|
16
16
|
import { useMemo } from 'preact/hooks';
|
|
17
17
|
import type { WorkspaceFolderData } from '@/shared/types';
|
|
18
|
-
import type { SessionDataShape } from '@/client/hooks/chat/timeline/session-
|
|
18
|
+
import type { SessionDataShape } from '@/client/hooks/chat/timeline/session-shapes';
|
|
19
19
|
|
|
20
20
|
export interface RunIdentity {
|
|
21
21
|
sessionProvider?: string;
|
|
22
22
|
sessionModelName?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export
|
|
25
|
+
export interface RunIdentityInput {
|
|
26
26
|
folders: WorkspaceFolderData[];
|
|
27
27
|
sessionId: string | null;
|
|
28
28
|
sessionData: SessionDataShape | null | undefined;
|
|
29
29
|
modelNames: Record<string, string>;
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function runIdentityFor(input: RunIdentityInput): RunIdentity {
|
|
31
33
|
const { folders, sessionId, sessionData, modelNames } = input;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
34
|
+
const sidebar = folders.flatMap((f) => f.sessions ?? []).find((s) => String(s.id) === String(sessionId)) ?? null;
|
|
35
|
+
const runModel = sidebar?.runModel ?? null;
|
|
36
|
+
// The sidebar's model describes the RUN row beside it. While a run is live it
|
|
37
|
+
// is the freshest identity (it is renamed from `get_state` mid-run), but for
|
|
38
|
+
// an idle chat it is the model of the LAST run — a `set_model` after that run
|
|
39
|
+
// never reached it, so the footer and the composer kept naming the first
|
|
40
|
+
// model the chat ever picked. An idle chat reads the session's own metadata,
|
|
41
|
+
// which `/api/chat/:id` re-reads from the live agent on a `model_changed`.
|
|
42
|
+
const liveRun = sidebar?.streamStatus === 'stream';
|
|
36
43
|
const fallback = sessionData?.model;
|
|
37
44
|
const fallbackModel = typeof fallback === 'object' ? fallback : null;
|
|
38
|
-
const
|
|
45
|
+
const chosen = liveRun ? runModel : (fallbackModel ?? runModel);
|
|
39
46
|
return {
|
|
40
|
-
sessionProvider:
|
|
41
|
-
sessionModelName:
|
|
42
|
-
? (modelNames[
|
|
47
|
+
sessionProvider: chosen?.provider,
|
|
48
|
+
sessionModelName: chosen?.modelId
|
|
49
|
+
? (modelNames[chosen.modelId] ?? chosen.modelId)
|
|
43
50
|
: (typeof fallback === 'string' ? fallback : undefined),
|
|
44
51
|
};
|
|
45
52
|
}
|
|
53
|
+
|
|
54
|
+
export function useRunIdentity(input: RunIdentityInput): RunIdentity {
|
|
55
|
+
const { folders, sessionId, sessionData, modelNames } = input;
|
|
56
|
+
return useMemo(() => runIdentityFor(input), [folders, sessionId, sessionData, modelNames]);
|
|
57
|
+
}
|