@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
|
@@ -142,6 +142,45 @@ describe('executeSend', () => {
|
|
|
142
142
|
expect(h1.params).toEqual(['sessionId=uuid-9']);
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
+
test('a failed spawn reports the server reason and never simulates a reply', async () => {
|
|
146
|
+
const h1 = makeSendHarness({
|
|
147
|
+
isOmpSession: false,
|
|
148
|
+
sessionId: 'new-1',
|
|
149
|
+
folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
|
|
150
|
+
selectedFolderId: 4,
|
|
151
|
+
agent: { spawnResult: null, spawnError: 'Cannot start dsh: deepseek-harness refused model "m"' },
|
|
152
|
+
});
|
|
153
|
+
await act(async () => {
|
|
154
|
+
const result = await h1.sends.executeSend('first prompt', []);
|
|
155
|
+
expect(result.ok).toBe(false);
|
|
156
|
+
expect(result.error).toContain('deepseek-harness refused model');
|
|
157
|
+
});
|
|
158
|
+
// Nothing may be left on screen for a turn the agent never took, and the
|
|
159
|
+
// failure may not fall through to the simulated stream — that is what made
|
|
160
|
+
// a refused ACP spawn look like a slow chat that then "answered".
|
|
161
|
+
expect(h1.state.messages).toEqual([]);
|
|
162
|
+
expect(h1.reported).toEqual(['Prompt not sent: Cannot start dsh: deepseek-harness refused model "m"']);
|
|
163
|
+
expect(h1.generating).toEqual([true, false]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('mock mode falls through to the simulated stream instead of reporting', async () => {
|
|
167
|
+
// Mock has no agent process BY DESIGN, so there is no failure to report —
|
|
168
|
+
// the demo shell answers from the simulated stream. Measured on the CI E2E
|
|
169
|
+
// legs: `POST /api/agent/new` answered 400 (no `omp` on the runner) and the
|
|
170
|
+
// landing composer did nothing at all, so no chat ever opened.
|
|
171
|
+
const h1 = makeSendHarness({
|
|
172
|
+
isOmpSession: false,
|
|
173
|
+
sessionId: 'new-1',
|
|
174
|
+
folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
|
|
175
|
+
selectedFolderId: 4,
|
|
176
|
+
agent: { spawnResult: null, spawnError: 'Mock mode runs no agent process', spawnCode: 'mock_mode' },
|
|
177
|
+
});
|
|
178
|
+
await act(async () => {
|
|
179
|
+
await h1.sends.executeSend('first prompt', []);
|
|
180
|
+
});
|
|
181
|
+
expect(h1.reported).not.toContainEqual(expect.stringContaining('Prompt not sent'));
|
|
182
|
+
});
|
|
183
|
+
|
|
145
184
|
test('a harness picked on the pending view rides the spawn body', async () => {
|
|
146
185
|
const h1 = makeSendHarness({
|
|
147
186
|
isOmpSession: false,
|
|
@@ -161,6 +200,23 @@ describe('executeSend', () => {
|
|
|
161
200
|
expect(h1.deps.pendingHarnessRef.current).toBeNull();
|
|
162
201
|
});
|
|
163
202
|
|
|
203
|
+
test('a New Chat harness inherited from the source chat outranks a stale pick', async () => {
|
|
204
|
+
// The dialog has no picker, so its `options.harness` is the only honest
|
|
205
|
+
// answer; a ref left by an earlier pick on the pending view must not win.
|
|
206
|
+
const h1 = makeSendHarness({
|
|
207
|
+
isOmpSession: false,
|
|
208
|
+
sessionId: 'new-1',
|
|
209
|
+
folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
|
|
210
|
+
selectedFolderId: 4,
|
|
211
|
+
agent: { spawnResult: { sessionId: 'uuid-12' } },
|
|
212
|
+
});
|
|
213
|
+
h1.deps.pendingHarnessRef.current = 'opencode';
|
|
214
|
+
await act(async () => {
|
|
215
|
+
await h1.sends.executeSend('first prompt', [], { harness: 'omp-acp' });
|
|
216
|
+
});
|
|
217
|
+
expect(h1.agent.calls.newPrompts[0]?.options).toMatchObject({ harness: 'omp-acp' });
|
|
218
|
+
});
|
|
219
|
+
|
|
164
220
|
test("the spawn's answered harness is what the run is reported as", async () => {
|
|
165
221
|
const h1 = makeSendHarness({
|
|
166
222
|
isOmpSession: false,
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
import type { Dispatch, SetStateAction } from 'preact/compat';
|
|
13
13
|
import type { AgentImage, Attachment, ChatMessageData, PromptDispatchResult } from '@/shared/types';
|
|
14
14
|
import { streamChatResponse } from '@/client/hooks/chat/stream';
|
|
15
|
+
import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
|
|
15
16
|
import { createMockStreamCallbacks } from '@/shared/lib/chat/timeline/stream-callbacks';
|
|
16
|
-
import { attachmentImage, attachmentName, attachmentSize, attachmentType } from '@/shared/lib/chat/attachments';
|
|
17
|
+
import { readTextAttachments, attachmentImage, attachmentName, attachmentSize, attachmentType, type ReadTextAttachment } from '@/shared/lib/chat/attachments';
|
|
17
18
|
|
|
18
19
|
/** The image payload of a delivery: the attachments that carry real bytes. A
|
|
19
20
|
* replayed attachment has no live `File`, so it is dropped unless the data
|
|
@@ -62,6 +63,34 @@ export function buildOptimisticRows(args: {
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
/** What the send path needs from a prompt, before it decides which transport runs it. */
|
|
67
|
+
export type PromptAssembly =
|
|
68
|
+
| { ok: true; textFiles: ReadTextAttachment[]; promptText: string }
|
|
69
|
+
| { ok: false; error: string };
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Read attachments and assemble the outgoing prompt once.
|
|
73
|
+
*
|
|
74
|
+
* A delegation refusal (two harnesses in one paragraph, an unknown harness, an
|
|
75
|
+
* empty task) is a send-time failure, not a prompt to send anyway: the caller
|
|
76
|
+
* reports it before any optimistic bubble exists.
|
|
77
|
+
*/
|
|
78
|
+
export async function assemblePrompt(
|
|
79
|
+
text: string,
|
|
80
|
+
attachments: Attachment[],
|
|
81
|
+
includeAgents: boolean,
|
|
82
|
+
): Promise<PromptAssembly> {
|
|
83
|
+
const textFiles = await readTextAttachments(attachments);
|
|
84
|
+
try {
|
|
85
|
+
return { ok: true, textFiles, promptText: await buildPromptText(text, textFiles, { includeAgents }) };
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
ok: false,
|
|
89
|
+
error: error instanceof Error ? error.message : 'Prompt could not be assembled',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
65
94
|
/** The simulated SSE path, taken by a Kabmo-created session and as the
|
|
66
95
|
* fallback when a real spawn is impossible (MOCK mode, no workspace cwd). */
|
|
67
96
|
export async function streamMockFallback(args: {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import type { Dispatch, SetStateAction } from 'preact/compat';
|
|
16
16
|
import type { Attachment, ChatMessageData, OmpAgentHandle, PromptDispatchResult, QueuedMessageModel } from '@/shared/types';
|
|
17
17
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
18
|
-
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-
|
|
18
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
19
19
|
import type { DeferredModelStore } from '@/client/hooks/chat/timeline/deferred-model';
|
|
20
20
|
import type { ArmedGoal } from '@/shared/lib/omp/mode/actions';
|
|
21
21
|
|
|
@@ -94,10 +94,12 @@ export interface ChatTimelineSendResult {
|
|
|
94
94
|
steerOmpAgent: (text: string, attachments: Attachment[]) => Promise<PromptDispatchResult>;
|
|
95
95
|
/** `model` re-applies a queued item's snapshot before the prompt runs
|
|
96
96
|
* (set_model / set_thinking_level RPC + prompt access mode). `busy: true`
|
|
97
|
-
* means omp REFUSED the prompt mid-turn — the caller queues it instead.
|
|
97
|
+
* means omp REFUSED the prompt mid-turn — the caller queues it instead.
|
|
98
|
+
* `harness` is the New Chat dialog's inherited agent, used only by the
|
|
99
|
+
* brand-new-session branch (`/api/agent/new`). */
|
|
98
100
|
executeSend: (
|
|
99
101
|
text: string,
|
|
100
102
|
attachments: Attachment[],
|
|
101
|
-
options?: { model?: QueuedMessageModel | null },
|
|
103
|
+
options?: { model?: QueuedMessageModel | null; harness?: string | null },
|
|
102
104
|
) => Promise<PromptDispatchResult>;
|
|
103
105
|
}
|
|
@@ -18,9 +18,7 @@ import {
|
|
|
18
18
|
type ChatTimelineSendDeps,
|
|
19
19
|
type ChatTimelineSendResult,
|
|
20
20
|
} from '@/client/hooks/chat/timeline/send';
|
|
21
|
-
import {
|
|
22
|
-
type SessionSeed,
|
|
23
|
-
} from '@/client/hooks/chat/timeline/session-load';
|
|
21
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
24
22
|
|
|
25
23
|
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
26
24
|
/** The runner's own globals, restored on teardown so later files still have them. */
|
|
@@ -101,7 +99,9 @@ function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
|
|
|
101
99
|
},
|
|
102
100
|
sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
|
|
103
101
|
calls.newPrompts.push({ text, cwd, options });
|
|
104
|
-
return calls.spawnResult
|
|
102
|
+
return calls.spawnResult
|
|
103
|
+
? { ok: true as const, session: calls.spawnResult }
|
|
104
|
+
: { ok: false as const, error: 'spawn failed' };
|
|
105
105
|
},
|
|
106
106
|
steerOmpRun: async (text: string, images: unknown) => {
|
|
107
107
|
calls.steers.push({ text, images });
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
type ChatTimelineSendDeps,
|
|
25
25
|
type ChatTimelineSendResult,
|
|
26
26
|
} from '@/client/hooks/chat/timeline/send';
|
|
27
|
-
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-
|
|
27
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
28
28
|
|
|
29
29
|
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
30
30
|
|
|
@@ -130,6 +130,10 @@ export interface AgentCalls {
|
|
|
130
130
|
sendPromptBusy: boolean;
|
|
131
131
|
/** The server-supplied reason, when the send was refused. */
|
|
132
132
|
sendPromptError: string | undefined;
|
|
133
|
+
/** The reason a fresh spawn failed, when `spawnResult` is null. */
|
|
134
|
+
spawnError?: string;
|
|
135
|
+
/** The server's discriminator, e.g. `mock_mode`. */
|
|
136
|
+
spawnCode?: string;
|
|
133
137
|
spawnResult: { sessionId: string; model?: { provider: string; modelId: string }; harness?: string } | null;
|
|
134
138
|
}
|
|
135
139
|
|
|
@@ -158,7 +162,9 @@ export function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
|
|
|
158
162
|
},
|
|
159
163
|
sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
|
|
160
164
|
calls.newPrompts.push({ text, cwd, options });
|
|
161
|
-
return calls.spawnResult
|
|
165
|
+
return calls.spawnResult
|
|
166
|
+
? { ok: true as const, session: calls.spawnResult }
|
|
167
|
+
: { ok: false as const, error: calls.spawnError ?? 'spawn failed', ...(calls.spawnCode ? { code: calls.spawnCode } : {}) };
|
|
162
168
|
},
|
|
163
169
|
steerOmpRun: async (text: string, images: unknown) => {
|
|
164
170
|
calls.interrupts.push({ text, images });
|
|
@@ -19,9 +19,7 @@ import {
|
|
|
19
19
|
type ChatTimelineSendDeps,
|
|
20
20
|
type ChatTimelineSendResult,
|
|
21
21
|
} from '@/client/hooks/chat/timeline/send';
|
|
22
|
-
import {
|
|
23
|
-
type SessionSeed,
|
|
24
|
-
} from '@/client/hooks/chat/timeline/session-load';
|
|
22
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
25
23
|
|
|
26
24
|
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
27
25
|
/** The runner's own globals, restored on teardown so later files still have them. */
|
|
@@ -101,7 +99,9 @@ function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
|
|
|
101
99
|
},
|
|
102
100
|
sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
|
|
103
101
|
calls.newPrompts.push({ text, cwd, options });
|
|
104
|
-
return calls.spawnResult
|
|
102
|
+
return calls.spawnResult
|
|
103
|
+
? { ok: true as const, session: calls.spawnResult }
|
|
104
|
+
: { ok: false as const, error: 'spawn failed' };
|
|
105
105
|
},
|
|
106
106
|
steerOmpRun: async (text: string, images: unknown) => {
|
|
107
107
|
calls.interrupts.push({ text, images });
|
|
@@ -15,10 +15,8 @@ import type { ChatTimelineSendDeps, ChatTimelineSendResult } from '@/client/hook
|
|
|
15
15
|
|
|
16
16
|
export type { ChatTimelineSendDeps, ChatTimelineSendResult };
|
|
17
17
|
import type { AgentImage, Attachment, PromptDispatchResult, QueuedMessageModel } from '@/shared/types';
|
|
18
|
-
import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
|
|
19
18
|
import { flushDeferredPick } from '@/client/hooks/chat/timeline/deferred-model';
|
|
20
|
-
import {
|
|
21
|
-
import { buildOptimisticRows, collectImages, streamMockFallback } from '@/client/hooks/chat/timeline/send-helpers';
|
|
19
|
+
import { buildOptimisticRows, collectImages, assemblePrompt, streamMockFallback } from '@/client/hooks/chat/timeline/send-helpers';
|
|
22
20
|
import { adoptPendingSession, markPendingSessionSent } from '@/client/hooks/chat/omp/pending-sessions';
|
|
23
21
|
import { recordSpawnHarness } from '@/client/hooks/chat/timeline/spawn-harness';
|
|
24
22
|
import { postModeCommand } from '@/client/hooks/chat/timeline/mode-post';
|
|
@@ -67,24 +65,10 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
67
65
|
const includeAgents = !harness || harness === 'omp-rpc' || harness === 'omp-acp';
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
|
-
* Start the armed goal
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* - `create` — the record is written with `startTurn: false`, and the prompt
|
|
76
|
-
* that follows is the goal's first turn. The prompt is still sent.
|
|
77
|
-
* - `guided` — there is no objective yet (the model writes it at the end of
|
|
78
|
-
* the interview), so the operator's message IS the interview's opening
|
|
79
|
-
* turn: the extension renders its kickoff prompt with their words folded
|
|
80
|
-
* in (`<rough-goal>`) and runs that as turn one. The raw message is
|
|
81
|
-
* therefore NOT sent separately — it is already inside that turn.
|
|
82
|
-
*
|
|
83
|
-
* A refusal is reported rather than swallowed, and the prompt still goes out
|
|
84
|
-
* for `create`: the goal the operator set is missing, but their words are not
|
|
85
|
-
* the goal's business. A refused `guided` cannot fall back the same way — the
|
|
86
|
-
* interview kickoff is the extension's text — so it resolves false and the
|
|
87
|
-
* caller sends the message as an ordinary prompt.
|
|
68
|
+
* Start the armed goal before the prompt leaves. `guided` folds the operator's
|
|
69
|
+
* words into the interview's opening turn (the caller must not send it again);
|
|
70
|
+
* `create` writes the record and lets the prompt be its first turn. A refusal
|
|
71
|
+
* is reported, and the prompt still goes out for `create`.
|
|
88
72
|
*/
|
|
89
73
|
const startArmedGoal = useCallback(async (targetId: string, armed: ArmedGoal, promptText: string): Promise<boolean> => {
|
|
90
74
|
const posted = armed.kind === 'guided'
|
|
@@ -114,11 +98,11 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
114
98
|
text: string,
|
|
115
99
|
attachments: Attachment[],
|
|
116
100
|
): Promise<{ promptText: string; images?: AgentImage[] }> => {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
pendingUserDisplaysRef.current = [...pendingUserDisplaysRef.current.slice(-7), { sent: promptText, display: text }];
|
|
120
|
-
return { promptText, images: collectImages(attachments) };
|
|
121
|
-
}, [includeAgents]);
|
|
101
|
+
const assembled = await assemblePrompt(text, attachments, includeAgents);
|
|
102
|
+
if (!assembled.ok) throw new Error(assembled.error);
|
|
103
|
+
pendingUserDisplaysRef.current = [...pendingUserDisplaysRef.current.slice(-7), { sent: assembled.promptText, display: text }];
|
|
104
|
+
return { promptText: assembled.promptText, images: collectImages(attachments) };
|
|
105
|
+
}, [includeAgents, pendingUserDisplaysRef]);
|
|
122
106
|
|
|
123
107
|
// Steer the running omp agent (interrupt-and-reply). Returns the outcome so
|
|
124
108
|
// the caller can report a refusal: the composer is cleared before this runs.
|
|
@@ -126,16 +110,24 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
126
110
|
// A steer IS a new prompt: a pick made during the interrupted turn belongs
|
|
127
111
|
// to it, so it is pushed before the interrupt-and-reply starts the turn.
|
|
128
112
|
await flushDeferredPick(ompAgent, deferredComposerPickRef);
|
|
129
|
-
|
|
130
|
-
|
|
113
|
+
let deliverable: { promptText: string; images?: AgentImage[] };
|
|
114
|
+
try {
|
|
115
|
+
deliverable = await prepareDeliverable(text, attachments);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
118
|
+
reportActionError(message);
|
|
119
|
+
setInputValue(text);
|
|
120
|
+
return { ok: false, busy: false, error: message };
|
|
121
|
+
}
|
|
122
|
+
const result = await ompAgent.steerOmpRun(deliverable.promptText, deliverable.images);
|
|
131
123
|
if (!result.ok) setInputValue(text);
|
|
132
124
|
return result;
|
|
133
|
-
}, [ompAgent, prepareDeliverable, setInputValue, deferredComposerPickRef]);
|
|
125
|
+
}, [ompAgent, prepareDeliverable, setInputValue, deferredComposerPickRef, reportActionError]);
|
|
134
126
|
|
|
135
127
|
const executeSend = useCallback(async (
|
|
136
128
|
text: string,
|
|
137
129
|
attachments: Attachment[],
|
|
138
|
-
options?: { model?: QueuedMessageModel | null },
|
|
130
|
+
options?: { model?: QueuedMessageModel | null; harness?: string | null },
|
|
139
131
|
) => {
|
|
140
132
|
// Last gate before a prompt leaves the client. `handleSend` already refuses
|
|
141
133
|
// these, but `executeSend` is also reached by a retry of a stored turn, a
|
|
@@ -151,12 +143,15 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
151
143
|
const userMsgId = `msg-${Date.now()}-user`;
|
|
152
144
|
const aiPlaceholderId = `msg-${Date.now() + 1}-ai`;
|
|
153
145
|
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
// A delegation refusal (two harnesses in one paragraph, an unknown
|
|
147
|
+
// harness, an empty task) must land before any optimistic bubble exists.
|
|
148
|
+
const assembled = await assemblePrompt(text, attachments, includeAgents);
|
|
149
|
+
if (!assembled.ok) {
|
|
150
|
+
reportActionError(assembled.error);
|
|
151
|
+
return { ok: false, busy: false, error: assembled.error };
|
|
152
|
+
}
|
|
153
|
+
const { textFiles, promptText } = assembled;
|
|
158
154
|
const textContentById = new Map(textFiles.map((file) => [file.id, file.content]));
|
|
159
|
-
|
|
160
155
|
const now = Date.now();
|
|
161
156
|
const { newUserMsg, initialAiMsg } = buildOptimisticRows({
|
|
162
157
|
text,
|
|
@@ -214,13 +209,7 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
214
209
|
}
|
|
215
210
|
}
|
|
216
211
|
const images = collectImages(attachments);
|
|
217
|
-
//
|
|
218
|
-
// content as fenced blocks, not just the filename.
|
|
219
|
-
const promptText = await buildPromptText(text, textFiles, { includeAgents });
|
|
220
|
-
// The armed goal is created HERE, at the fence of the prompt that will be
|
|
221
|
-
// its first turn — never earlier (nothing to act on) and never after the
|
|
222
|
-
// prompt (the goal would miss its opening turn). An armed INTERVIEW
|
|
223
|
-
// consumes this prompt as its kickoff, so nothing is sent after it.
|
|
212
|
+
// `promptText` was assembled once above, so no refusal can reach here.
|
|
224
213
|
const armed = goalArmRef.current;
|
|
225
214
|
const consumed = armed && sessionId ? await startArmedGoal(sessionId, armed, promptText) : false;
|
|
226
215
|
if (consumed) return { ok: true, busy: false };
|
|
@@ -250,7 +239,6 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
250
239
|
const cwd = spawnWorktreeRef.current || currentFolder?.project_path || currentFolder?.name;
|
|
251
240
|
if (cwd) {
|
|
252
241
|
const images = collectImages(attachments);
|
|
253
|
-
const promptText = await buildPromptText(text, textFiles, { includeAgents });
|
|
254
242
|
optimisticUserIdRef.current = userMsgId;
|
|
255
243
|
const composerModel = pendingComposerModelRef.current;
|
|
256
244
|
const composerThinking = pendingThinkingLevelRef.current;
|
|
@@ -273,25 +261,31 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
273
261
|
accessMode: accessModeRef.current,
|
|
274
262
|
modes: spawnModes,
|
|
275
263
|
// A harness picked on the pending view rides the spawn; cleared on
|
|
276
|
-
// success below so it cannot leak onto the next new chat.
|
|
277
|
-
|
|
264
|
+
// success below so it cannot leak onto the next new chat. A New
|
|
265
|
+
// Chat opened from an ACP answer passes the SOURCE chat's harness
|
|
266
|
+
// explicitly (that dialog has no picker), and it must outrank the
|
|
267
|
+
// ref a previous pick left behind.
|
|
268
|
+
...((options?.harness ?? pendingHarnessRef.current)
|
|
269
|
+
? { harness: options?.harness ?? pendingHarnessRef.current }
|
|
270
|
+
: {}),
|
|
278
271
|
},
|
|
279
272
|
armed ? (id) => startArmedGoal(id, armed, promptText) : undefined,
|
|
280
273
|
);
|
|
281
|
-
if (spawned) {
|
|
274
|
+
if (spawned.ok) {
|
|
275
|
+
const { session } = spawned;
|
|
282
276
|
// The harness the SERVER answered with: `new.ts` reports it for an ACP
|
|
283
277
|
// spawn and omits it for the RPC branch, which means omp. Read rather
|
|
284
278
|
// than replayed from the request, so a pick the server did not honour
|
|
285
279
|
// cannot be reported as the agent running the chat.
|
|
286
|
-
recordSpawnHarness(
|
|
280
|
+
recordSpawnHarness(session.sessionId, session.harness ?? 'omp-rpc');
|
|
287
281
|
spawnSelectionRef.current = null;
|
|
288
|
-
adoptedSessionIdRef.current =
|
|
282
|
+
adoptedSessionIdRef.current = session.sessionId;
|
|
289
283
|
// The sidebar's row moves with the id: `new-…` was the client's own
|
|
290
284
|
// placeholder, and the spawn answers with omp's real one, which omp
|
|
291
285
|
// has still not written a transcript for. Without this the row
|
|
292
286
|
// vanished at exactly the moment the URL stopped naming the pending
|
|
293
287
|
// id, which is the gap this store exists to close.
|
|
294
|
-
adoptPendingSession(sessionId,
|
|
288
|
+
adoptPendingSession(sessionId, session.sessionId, currentFolder?.id ?? null);
|
|
295
289
|
// The placeholder ref is already armed (with its row) before the
|
|
296
290
|
// spawn — see the note at the assignment; re-arming here would be
|
|
297
291
|
// harmless but is redundant.
|
|
@@ -299,18 +293,18 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
299
293
|
// composer taking over from the pending view reports the run's real
|
|
300
294
|
// setting instead of a catalog default (the JSONL that carries it is
|
|
301
295
|
// not locatable yet).
|
|
302
|
-
seedSession({ model:
|
|
296
|
+
seedSession({ model: session.model, thinkingLevel: composerThinking });
|
|
303
297
|
pendingComposerModelRef.current = null;
|
|
304
298
|
pendingThinkingLevelRef.current = null;
|
|
305
299
|
pendingHarnessRef.current = null;
|
|
306
|
-
fetch(`/api/chat/${encodeURIComponent(
|
|
300
|
+
fetch(`/api/chat/${encodeURIComponent(session.sessionId)}`, {
|
|
307
301
|
method: 'POST',
|
|
308
302
|
headers: { 'Content-Type': 'application/json' },
|
|
309
303
|
body: JSON.stringify({ messages: [newUserMsg] }),
|
|
310
304
|
}).catch(err => console.error('Error persisting spawned user turn:', err));
|
|
311
305
|
setSearchParams(prev => {
|
|
312
306
|
const next = new URLSearchParams(prev);
|
|
313
|
-
next.set('sessionId',
|
|
307
|
+
next.set('sessionId', session.sessionId);
|
|
314
308
|
return next;
|
|
315
309
|
}, { replace: true });
|
|
316
310
|
// The sidebar already re-read at prompt dispatch (sendNewPrompt
|
|
@@ -318,6 +312,18 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
318
312
|
// waiting for the JSONL to carry the user turn.
|
|
319
313
|
return { ok: true, busy: false };
|
|
320
314
|
}
|
|
315
|
+
// `mock_mode` is not a failure — mock has no agent process BY DESIGN, so
|
|
316
|
+
// the demo shell answers from the simulated stream below.
|
|
317
|
+
if (spawned.code !== 'mock_mode') {
|
|
318
|
+
// A real spawn failure REPORTS: falling through here once made a failed
|
|
319
|
+
// ACP spawn look like a slow chat that then "answered".
|
|
320
|
+
setLocalMessages(prev => prev.filter(m => m.id !== userMsgId && m.id !== aiPlaceholderId));
|
|
321
|
+
aiPlaceholderIdRef.current = null;
|
|
322
|
+
optimisticUserIdRef.current = null;
|
|
323
|
+
setGenerating(false);
|
|
324
|
+
reportActionError(`Prompt not sent: ${spawned.error}`);
|
|
325
|
+
return { ok: false, busy: false, error: spawned.error };
|
|
326
|
+
}
|
|
321
327
|
}
|
|
322
328
|
}
|
|
323
329
|
|
|
@@ -338,6 +344,6 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
338
344
|
setGeneratingVerb,
|
|
339
345
|
scrollToBottom,
|
|
340
346
|
});
|
|
341
|
-
}, [appSettings, folders, isOmpSession, harness, ompAgent, selectedFolderId, sessionId, scrollToBottom, jumpToBottom, persistMessages, seedSession, pendingComposerModelRef, pendingThinkingLevelRef, deferredComposerPickRef, accessModeRef, setLocalMessages]);
|
|
347
|
+
}, [appSettings, folders, isOmpSession, harness, ompAgent, selectedFolderId, sessionId, scrollToBottom, jumpToBottom, persistMessages, seedSession, pendingComposerModelRef, pendingThinkingLevelRef, deferredComposerPickRef, accessModeRef, setLocalMessages, reportActionError]);
|
|
342
348
|
return { steerOmpAgent, executeSend };
|
|
343
349
|
}
|
|
@@ -168,11 +168,15 @@ export async function mount(sessionId: string, api: ProbeApi): Promise<void> {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
/** Land the registered fetch, as the server's response would. */
|
|
171
|
-
export async function resolveLoad(
|
|
171
|
+
export async function resolveLoad(
|
|
172
|
+
messages: unknown[],
|
|
173
|
+
index = 0,
|
|
174
|
+
sessionExtra: Record<string, unknown> = {},
|
|
175
|
+
): Promise<void> {
|
|
172
176
|
const gate = gates[index];
|
|
173
177
|
if (!gate) throw new Error('no session fetch was registered');
|
|
174
178
|
await act(async () => {
|
|
175
|
-
gate.resolve({ session: { id: 'sess-1', messages }, hasMore: false, oldestIndex: 0 });
|
|
179
|
+
gate.resolve({ session: { id: 'sess-1', messages, ...sessionExtra }, hasMore: false, oldestIndex: 0 });
|
|
176
180
|
});
|
|
177
181
|
for (let i = 0; i < 3; i += 1) await act(async () => {});
|
|
178
182
|
}
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
|
|
30
30
|
import { describe, expect, test } from 'bun:test';
|
|
31
31
|
import { act } from 'preact/test-utils';
|
|
32
|
+
import { h, render } from 'preact';
|
|
33
|
+
import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
|
|
34
|
+
import { useHarnesses } from '@/client/hooks/models/use-harnesses';
|
|
32
35
|
import {
|
|
33
36
|
AI_PLACEHOLDER,
|
|
34
37
|
ECHOED_TURN,
|
|
@@ -219,4 +222,32 @@ describe('a committed fetch with no local run', () => {
|
|
|
219
222
|
expect(ids(api)).toEqual([]);
|
|
220
223
|
expect(api.generatingCalls.length).toBe(before);
|
|
221
224
|
});
|
|
225
|
+
|
|
226
|
+
test('publishes the live chat\'s selector lists to its harness', async () => {
|
|
227
|
+
stubChatFetch();
|
|
228
|
+
resetHarnessesStore();
|
|
229
|
+
const live = { models: [{ value: 'gpt-5-codex', name: 'GPT-5 Codex' }], thinking: [{ value: 'high', name: 'High' }] };
|
|
230
|
+
const seen: Record<string, unknown> = {};
|
|
231
|
+
const api = makeApi();
|
|
232
|
+
// The loader's session fetch is `gates[0]`; the store read below issues the
|
|
233
|
+
// harness-catalog read, so it must mount after the probe.
|
|
234
|
+
await mount('sess-1', api);
|
|
235
|
+
const box = document.body.appendChild(document.createElement('div'));
|
|
236
|
+
await act(async () => { render(h(LiveModelsRead, { sink: seen }), box); });
|
|
237
|
+
|
|
238
|
+
await resolveLoad([ECHOED_TURN], 0, { harness: 'codex', liveModels: live });
|
|
239
|
+
|
|
240
|
+
// The picker for that harness lists what the running chat reported, not what
|
|
241
|
+
// the throwaway probe guessed.
|
|
242
|
+
expect(seen.liveModels).toEqual({ codex: live });
|
|
243
|
+
await act(async () => { render(null, box); });
|
|
244
|
+
box.remove();
|
|
245
|
+
});
|
|
222
246
|
});
|
|
247
|
+
|
|
248
|
+
/** Read the harness store the way a model picker does. */
|
|
249
|
+
function LiveModelsRead({ sink }: { sink: Record<string, unknown> }) {
|
|
250
|
+
const { liveModels } = useHarnesses();
|
|
251
|
+
sink.liveModels = liveModels;
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
@@ -21,25 +21,13 @@ import type { Dispatch, RefObject, SetStateAction } from 'preact/compat';
|
|
|
21
21
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
22
22
|
|
|
23
23
|
import type { ChatMessageData } from '@/shared/types';
|
|
24
|
+
import type { SessionDataShape, SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
25
|
+
import { publishLiveModels } from '@/client/hooks/models/use-harnesses';
|
|
24
26
|
import { SESSION_META_RETRY_SCHEDULE_MS } from '@/shared/lib/workspace/refresh-cadence';
|
|
25
27
|
import { useSessionPagination } from '@/client/hooks/chat/timeline/session-pagination';
|
|
26
28
|
import { useLostRunRecovery } from '@/client/hooks/chat/timeline/lost-run';
|
|
27
29
|
import { isOwnSpawn, isSpawnArrival } from '@/client/hooks/chat/timeline/session-switch';
|
|
28
30
|
|
|
29
|
-
export interface SessionDataShape {
|
|
30
|
-
id?: string;
|
|
31
|
-
title?: string;
|
|
32
|
-
model?: string | { provider: string; modelId: string };
|
|
33
|
-
thinkingLevel?: string;
|
|
34
|
-
messages?: any[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Session identity a spawn established before omp's JSONL is readable. */
|
|
38
|
-
export interface SessionSeed {
|
|
39
|
-
model?: { provider: string; modelId: string } | null;
|
|
40
|
-
thinkingLevel?: string | null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
31
|
export interface UseSessionLoadDeps {
|
|
44
32
|
sessionId: string | null;
|
|
45
33
|
setLocalMessages: Dispatch<SetStateAction<ChatMessageData[]>>;
|
|
@@ -106,6 +94,10 @@ export function useSessionLoad(deps: UseSessionLoadDeps) {
|
|
|
106
94
|
|
|
107
95
|
const applySessionData = useCallback((incoming: SessionDataShape) => {
|
|
108
96
|
if (incoming.model && typeof incoming.model === 'object') seededModelRef.current = incoming.model;
|
|
97
|
+
// The live chat's own selector lists are what the picker must list for this
|
|
98
|
+
// harness from now on: a probe is one throwaway spawn, and a chat already
|
|
99
|
+
// running can contradict it (codex refuses the probe while offering models).
|
|
100
|
+
if (incoming.harness && incoming.liveModels) publishLiveModels(incoming.harness, incoming.liveModels);
|
|
109
101
|
const model = incoming.model ?? (isGeneratingRef.current ? seededModelRef.current ?? undefined : undefined);
|
|
110
102
|
const thinkingLevel = incoming.thinkingLevel ?? seededThinkingLevelRef.current ?? undefined;
|
|
111
103
|
setSessionData({ ...incoming, model, thinkingLevel });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The payload `/api/chat/:id` answers with, and the identity a spawn established
|
|
8
|
+
* before that payload can be trusted.
|
|
9
|
+
*
|
|
10
|
+
* Types only, in their own module: `session-load.ts` owns the fetching and the
|
|
11
|
+
* seeding rules and sits against the per-file size ceiling.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { LiveHarnessModels } from '@/shared/types/harness';
|
|
15
|
+
|
|
16
|
+
export interface SessionDataShape {
|
|
17
|
+
id?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
model?: string | { provider: string; modelId: string };
|
|
20
|
+
thinkingLevel?: string;
|
|
21
|
+
messages?: any[];
|
|
22
|
+
/** Harness the live session runs, with the model/thinking selectors it
|
|
23
|
+
* published. Only a live non-omp session reports them. */
|
|
24
|
+
harness?: string;
|
|
25
|
+
liveModels?: LiveHarnessModels;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Session identity a spawn established before omp's JSONL is readable. */
|
|
29
|
+
export interface SessionSeed {
|
|
30
|
+
model?: { provider: string; modelId: string } | null;
|
|
31
|
+
thinkingLevel?: string | null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fork the current chat at a clicked row.
|
|
8
|
+
*
|
|
9
|
+
* The API call and the navigation live together because the refusal has to be
|
|
10
|
+
* shown where the action was taken. The server answers a typed code and a
|
|
11
|
+
* message; the hook surfaces the message and never navigates on a failure —
|
|
12
|
+
* a silent tip fork would be worse than the error.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { useCallback } from 'preact/hooks';
|
|
16
|
+
|
|
17
|
+
type ToastKind = 'success' | 'error';
|
|
18
|
+
|
|
19
|
+
export function useForkSession(
|
|
20
|
+
sessionId: string | null | undefined,
|
|
21
|
+
pushToast: (message: string, type?: ToastKind) => void,
|
|
22
|
+
): (messageId: string) => Promise<void> {
|
|
23
|
+
return useCallback(
|
|
24
|
+
async (messageId: string) => {
|
|
25
|
+
if (!sessionId) return;
|
|
26
|
+
try {
|
|
27
|
+
const response = await fetch(`/api/sessions/${encodeURIComponent(sessionId)}/fork`, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: { 'content-type': 'application/json' },
|
|
30
|
+
body: JSON.stringify({ anchorEntryId: messageId }),
|
|
31
|
+
});
|
|
32
|
+
const body = (await response.json().catch(() => null)) as
|
|
33
|
+
| { sessionId?: string; error?: string }
|
|
34
|
+
| null;
|
|
35
|
+
if (!response.ok || !body?.sessionId) {
|
|
36
|
+
pushToast(body?.error ?? 'Could not fork this session.', 'error');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// A full navigation is deliberate: the fork is a different session with
|
|
40
|
+
// its own transcript, and the workspace's session param is the source of
|
|
41
|
+
// truth the sidebar and the composer read on mount.
|
|
42
|
+
window.location.assign(`/?sessionId=${encodeURIComponent(body.sessionId)}`);
|
|
43
|
+
} catch {
|
|
44
|
+
pushToast('Could not fork this session.', 'error');
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[sessionId, pushToast],
|
|
48
|
+
);
|
|
49
|
+
}
|