@kabmo-labs/kabmo 0.27.0 → 0.28.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 +495 -467
- package/dist/client/static/js/index-81f7berm.css +1 -0
- package/dist/client/static/js/{index-e3qh2yps.js → index-xzvyrxya.js} +795 -795
- package/marketplace/plugins/command-runner/package.json +3 -17
- package/marketplace/plugins/command-runner/settings-schema.json +14 -0
- package/marketplace/plugins/git-forge/README.md +17 -7
- package/marketplace/plugins/git-forge/package.json +4 -30
- package/marketplace/plugins/git-forge/panel.css +16 -0
- package/marketplace/plugins/git-forge/settings-schema.json +27 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +35 -22
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +20 -24
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +16 -7
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +31 -26
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +18 -2
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +160 -96
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +60 -44
- package/marketplace/plugins/git-forge/src/panel/List.tsx +150 -22
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +11 -5
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +17 -15
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +84 -61
- package/marketplace/plugins/git-forge/src/panel/format.test.ts +99 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +59 -16
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +109 -5
- package/marketplace/plugins/git-forge/src/panel/index.tsx +37 -4
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +17 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +31 -0
- package/marketplace/plugins/session-info/package.json +2 -10
- package/marketplace/plugins/session-info/settings-schema.json +8 -0
- package/marketplace/plugins/stats/README.md +17 -5
- package/marketplace/plugins/stats/package.json +3 -23
- package/marketplace/plugins/stats/settings-schema.json +20 -0
- package/marketplace/plugins/stats/src/app.tsx +1 -1
- package/marketplace/plugins/stats/src/groups.test.ts +46 -1
- package/marketplace/plugins/stats/src/groups.ts +22 -11
- package/marketplace/plugins/stats/src/harness-leases.test.ts +84 -0
- package/marketplace/plugins/stats/src/harness-leases.ts +132 -0
- package/marketplace/plugins/stats/src/labels.test.ts +54 -1
- package/marketplace/plugins/stats/src/labels.ts +33 -7
- package/marketplace/plugins/stats/src/sampler.test.ts +61 -0
- package/marketplace/plugins/stats/src/sampler.ts +39 -5
- package/marketplace/plugins/stats/src/snapshot.ts +6 -0
- package/package.json +2 -2
- package/src/client/components/common/harness-glyph/index.tsx +18 -1
- package/src/client/components/common/session-actions-menu/index.test.tsx +106 -0
- package/src/client/components/common/session-actions-menu/index.tsx +43 -1
- package/src/client/components/common/session-row/TrailingSlot.tsx +9 -4
- package/src/client/components/common/session-row/index.tsx +4 -0
- package/src/client/components/common/session-row/session-row.test.tsx +6 -0
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +2 -1
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +2 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +202 -0
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +80 -19
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +23 -3
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +156 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +6 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +9 -1
- package/src/client/components/settings/Modal.tsx +6 -2
- package/src/client/components/settings/Sidebar.tsx +30 -3
- package/src/client/components/settings/categories/HarnessSettings.tsx +11 -7
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +40 -15
- package/src/client/components/settings/categories/NotificationSettings.tsx +142 -64
- package/src/client/components/settings/categories/PanelPluginSettings.tsx +1 -1
- package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -0
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +11 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +1 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +15 -1
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.test.tsx +165 -0
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +24 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +8 -4
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +34 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -2
- package/src/client/components/workspace/chat-timeline/MessageItem.fork.test.ts +80 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +9 -3
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +8 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +9 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +24 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +13 -20
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +5 -5
- package/src/client/components/workspace/chat-timeline/index.tsx +11 -5
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +1 -9
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +101 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +2 -2
- package/src/client/components/workspace/editor/FilePane.tsx +9 -4
- package/src/client/components/workspace/editor/Notices.tsx +2 -2
- package/src/client/components/workspace/editor/Pane.tsx +2 -2
- package/src/client/components/workspace/editor/Toolbar.tsx +16 -10
- package/src/client/components/workspace/editor/index.tsx +6 -10
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +4 -3
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +23 -14
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +9 -1
- package/src/client/components/workspace/terminal-panel/focus.test.ts +70 -0
- package/src/client/components/workspace/terminal-panel/focus.ts +46 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +14 -1
- package/src/client/components/workspace/terminal-panel/mount.ts +17 -9
- package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +158 -0
- package/src/client/components/workspace/terminal-panel/scroll-hold.ts +136 -0
- package/src/client/hooks/chat/composer/use-draft.ts +45 -1
- package/src/client/hooks/chat/omp/pending-sessions.waiting.test.ts +11 -10
- package/src/client/hooks/chat/omp/pending-waiting.ts +15 -7
- package/src/client/hooks/chat/omp/prompt-send.test.ts +11 -0
- package/src/client/hooks/chat/omp/prompt-send.ts +3 -0
- package/src/client/hooks/chat/timeline/actions.ts +4 -4
- package/src/client/hooks/chat/timeline/composer-modes.ts +13 -2
- package/src/client/hooks/chat/timeline/fork-open.ts +52 -0
- package/src/client/hooks/chat/timeline/index.ts +5 -2
- package/src/client/hooks/chat/timeline/mode-availability.ts +7 -0
- package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
- package/src/client/hooks/chat/timeline/modes-hydrate.ts +93 -0
- package/src/client/hooks/chat/timeline/modes.ts +32 -52
- package/src/client/hooks/chat/timeline/new-chat-open.ts +7 -6
- package/src/client/hooks/chat/timeline/new-chat.ts +10 -1
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +4 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.test.ts +136 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.ts +69 -0
- package/src/client/hooks/chat/timeline/pending-warmup.test.ts +147 -0
- package/src/client/hooks/chat/timeline/pending-warmup.ts +62 -0
- package/src/client/hooks/chat/timeline/run-identity.test.ts +12 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +4 -1
- package/src/client/hooks/chat/timeline/send-props.ts +2 -0
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test-util.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test.ts +1 -0
- package/src/client/hooks/chat/timeline/session-harness.ts +4 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
- package/src/client/hooks/chat/waiting/cancel.ts +13 -6
- package/src/client/hooks/chat/waiting/choice.ts +13 -16
- package/src/client/hooks/chat/waiting/composer-wait.ts +70 -0
- package/src/client/hooks/chat/waiting/dispatch.ts +48 -28
- package/src/client/hooks/chat/waiting/held.ts +37 -13
- package/src/client/hooks/chat/waiting/hold.test.ts +22 -0
- package/src/client/hooks/chat/waiting/hold.ts +20 -11
- package/src/client/hooks/chat/waiting/restore.test.ts +69 -0
- package/src/client/hooks/chat/waiting/restore.ts +34 -0
- package/src/client/hooks/chat/waiting/store.ts +9 -3
- package/src/client/hooks/editor/file-editor-types.ts +21 -12
- package/src/client/hooks/editor/save-file.test.ts +1 -1
- package/src/client/hooks/editor/save-file.ts +35 -8
- package/src/client/hooks/editor/target-key.ts +17 -0
- package/src/client/hooks/editor/use-disk-digest.test.ts +82 -0
- package/src/client/hooks/editor/use-disk-digest.ts +164 -0
- package/src/client/hooks/editor/use-disk-sync.ts +212 -0
- package/src/client/hooks/editor/use-file-cache.ts +113 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +90 -0
- package/src/client/hooks/editor/use-file-editor.ts +90 -52
- package/src/client/hooks/editor/use-file-read.ts +24 -10
- package/src/client/hooks/editor/use-file-writes.ts +4 -4
- package/src/client/hooks/models/harness-catalog.ts +15 -0
- package/src/client/hooks/ui/notifications.ts +17 -8
- package/src/client/hooks/workspace/panel-registry.ts +1 -1
- package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
- package/src/client/lib/notifications/os.test.ts +1 -30
- package/src/client/lib/notifications/os.ts +0 -15
- package/src/client/lib/notifications/platform.test.ts +68 -0
- package/src/client/lib/notifications/platform.ts +36 -0
- package/src/server/index.ts +7 -0
- package/src/server/lib/harness/acp/client.ts +81 -87
- package/src/server/lib/harness/acp/prewarm.server.ts +237 -0
- package/src/server/lib/harness/acp/prewarm.test.ts +171 -0
- package/src/server/lib/harness/acp/prompt.test.ts +70 -1
- package/src/server/lib/harness/acp/prompt.ts +32 -1
- package/src/server/lib/harness/acp/protocol.ts +23 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +26 -0
- package/src/server/lib/harness/acp/session-handshake.ts +22 -20
- package/src/server/lib/harness/acp/session-options.ts +16 -0
- package/src/server/lib/harness/acp/session-process.ts +43 -0
- package/src/server/lib/harness/acp/session.ts +11 -12
- package/src/server/lib/harness/acp/stdio.ts +129 -0
- package/src/server/lib/harness/acp/verbs.test.ts +97 -0
- package/src/server/lib/harness/acp/verbs.ts +16 -6
- package/src/server/lib/harness/auto-probe.server.ts +4 -3
- package/src/server/lib/harness/capabilities.ts +8 -0
- package/src/server/lib/harness/config.server.ts +3 -2
- package/src/server/lib/harness/custom.server.ts +209 -0
- package/src/server/lib/harness/launch.ts +6 -1
- package/src/server/lib/harness/register.server.ts +8 -1
- package/src/server/lib/harness/schema.server.ts +21 -0
- package/src/server/lib/harness/session-lease.server.test.ts +99 -0
- package/src/server/lib/harness/session-lease.server.ts +193 -0
- package/src/server/lib/harness/session-store.server.test.ts +8 -8
- package/src/server/lib/harness/session-store.server.ts +25 -4
- package/src/server/lib/harness/session-title.server.ts +12 -2
- package/src/server/lib/harness/spawn.server.ts +123 -20
- package/src/server/lib/harness/update-queue.server.ts +3 -3
- package/src/server/lib/lifecycle/after-listen.ts +12 -1
- package/src/server/lib/lifecycle/paths.ts +19 -1
- package/src/server/lib/mcp/registry.server.ts +155 -0
- package/src/server/lib/mcp/registry.test.ts +169 -0
- package/src/server/lib/mcp/store.server.ts +38 -0
- package/src/server/lib/omp/rpc/frame-fold-contract.ts +59 -0
- package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +64 -1
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold.test.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
- package/src/server/lib/omp/rpc/prewarm-pool.ts +19 -5
- package/src/server/lib/omp/rpc/run-model.test.ts +116 -0
- package/src/server/lib/omp/rpc/run-model.ts +4 -2
- package/src/server/lib/omp/session/sidebar-data.harness.test.ts +6 -3
- package/src/server/lib/omp/session/standby.server.ts +13 -2
- package/src/server/lib/panels/manifest.test.ts +47 -1
- package/src/server/lib/panels/manifest.ts +19 -0
- package/src/server/lib/panels/registry.server.ts +19 -2
- package/src/server/lib/panels/scan.server.ts +26 -2
- package/src/server/lib/panels/settings-schema.server.ts +72 -0
- package/src/server/lib/plugins/background.server.ts +21 -3
- package/src/server/lib/plugins/background.test.ts +13 -0
- package/src/server/lib/plugins/loader.server.ts +35 -51
- package/src/server/lib/plugins/mcp.server.ts +100 -0
- package/src/server/lib/plugins/mcp.test.ts +75 -0
- package/src/server/lib/plugins/schedule-runner.server.ts +153 -0
- package/src/server/lib/plugins/schedule-runner.test.ts +186 -0
- package/src/server/lib/plugins/schedule-store.server.ts +107 -0
- package/src/server/lib/plugins/schema.server.ts +8 -0
- package/src/server/lib/plugins/settings.server.ts +56 -19
- package/src/server/lib/plugins/shutdown.server.ts +58 -0
- package/src/server/lib/plugins/shutdown.test.ts +28 -3
- package/src/server/lib/realtime/topics/global.server.ts +5 -1
- package/src/server/lib/schedule/rows.server.ts +9 -0
- package/src/server/lib/schedule/runtime.server.test.ts +91 -0
- package/src/server/lib/schedule/runtime.server.ts +101 -23
- package/src/server/lib/schedule/schema.server.ts +15 -0
- package/src/server/lib/schedule/store.server.test.ts +34 -0
- package/src/server/lib/schedule/store.server.ts +33 -9
- package/src/server/lib/sessions/fork.server.test.ts +47 -0
- package/src/server/lib/sessions/fork.server.ts +17 -1
- package/src/server/lib/sessions/spawn.server.ts +2 -2
- package/src/server/lib/waiting/runtime.server.test.ts +48 -0
- package/src/server/lib/waiting/runtime.server.ts +22 -0
- package/src/server/lib/waiting/schema.server.ts +8 -0
- package/src/server/lib/waiting/store.server.test.ts +14 -0
- package/src/server/lib/waiting/store.server.ts +6 -2
- package/src/server/routes/agent/command-resume.test.ts +9 -4
- package/src/server/routes/agent/new-mode.test.ts +40 -0
- package/src/server/routes/agent/new.ts +31 -10
- package/src/server/routes/agent/prewarm.ts +48 -7
- package/src/server/routes/fs/action.ts +9 -1
- package/src/server/routes/fs/digest.test.ts +100 -0
- package/src/server/routes/fs/digest.ts +106 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/harness/custom.test.ts +131 -0
- package/src/server/routes/harness/import-action.ts +2 -2
- package/src/server/routes/harness/root.ts +41 -8
- package/src/server/routes/harness/update.ts +2 -2
- package/src/server/routes/panels/bindings.ts +2 -0
- package/src/server/routes/panels/settings.test.ts +165 -0
- package/src/server/routes/panels/settings.ts +106 -0
- package/src/server/routes/schedule/body.ts +14 -0
- package/src/server/routes/schedule/index.ts +28 -4
- package/src/server/routes/settings/mcp.ts +9 -26
- package/src/server/routes/waiting/index.ts +21 -2
- package/src/server/routes/waiting/routes.test.ts +21 -0
- package/src/shared/lib/chat/composer/delegation.ts +3 -3
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +97 -0
- package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
- package/src/shared/lib/fs/content-hash.ts +29 -0
- package/src/shared/lib/harness/catalog.ts +48 -6
- package/src/shared/lib/harness/fork.ts +60 -0
- package/src/shared/lib/harness/mcp-facts.test.ts +30 -0
- package/src/shared/lib/harness/mcp-facts.ts +65 -0
- package/src/shared/lib/harness/menu.test.ts +16 -1
- package/src/shared/lib/harness/menu.ts +2 -2
- package/src/shared/lib/harness/rewind.ts +6 -6
- package/src/shared/lib/harness/session-modes.ts +31 -0
- package/src/shared/lib/harness/transcript.test.ts +29 -0
- package/src/shared/lib/harness/transcript.ts +19 -0
- package/src/shared/lib/notifications/settings.test.ts +21 -0
- package/src/shared/lib/notifications/settings.ts +24 -0
- package/src/shared/lib/omp/session/prewarm.test.ts +28 -4
- package/src/shared/lib/omp/session/prewarm.ts +25 -6
- package/src/shared/lib/omp/session/stream-state.server.test.ts +25 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +8 -4
- package/src/shared/lib/panels/capabilities.test.ts +1 -1
- package/src/shared/lib/panels/capabilities.ts +3 -0
- package/src/shared/lib/plugins/settings.ts +22 -0
- package/src/shared/lib/schedule/parse.test.ts +48 -0
- package/src/shared/lib/schedule/parse.ts +69 -45
- package/src/shared/lib/schedule/timezone.ts +128 -0
- package/src/shared/lib/settings/defaults.ts +2 -0
- package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
- package/src/shared/lib/workspace/relative-time.ts +16 -0
- package/src/shared/types/harness.ts +7 -0
- package/src/shared/types/omp/agent.ts +6 -0
- package/src/shared/types/panels-registry.ts +3 -3
- package/src/shared/types/panels.ts +4 -2
- package/src/shared/types/schedule.ts +13 -0
- package/src/shared/types/settings/state.ts +12 -1
- package/src/shared/types/waiting.ts +9 -0
- package/src/test-support/file-editor.test-util.ts +70 -5
- package/dist/client/static/js/index-32rpkj6b.css +0 -1
- package/src/client/hooks/editor/use-external-change-notice.ts +0 -71
- package/src/client/hooks/editor/use-external-change.test.ts +0 -88
- package/src/client/hooks/editor/use-external-change.ts +0 -146
|
@@ -51,6 +51,8 @@ export interface ChatTimelineSendDeps {
|
|
|
51
51
|
pendingThinkingLevelRef: { current: string | null };
|
|
52
52
|
/** Harness picked on the pending `new-…` chat; rides the spawn. */
|
|
53
53
|
pendingHarnessRef: { current: string | null };
|
|
54
|
+
/** ACP mode picked on the pending `new-…` chat; rides the spawn. */
|
|
55
|
+
pendingAgentModeRef: { current: string | null };
|
|
54
56
|
/** Global access-control mode (persisted user preference), read at send time
|
|
55
57
|
* so the spawn-capable requests carry the latest value. */
|
|
56
58
|
accessModeRef: { current: ApprovalMode };
|
|
@@ -184,6 +184,7 @@ function makeSendHarness(options: {
|
|
|
184
184
|
pendingComposerModelRef: { current: null },
|
|
185
185
|
pendingThinkingLevelRef: { current: null },
|
|
186
186
|
pendingHarnessRef: { current: null },
|
|
187
|
+
pendingAgentModeRef: { current: null },
|
|
187
188
|
deferredComposerPickRef: options.deferredPick ?? { current: null },
|
|
188
189
|
accessModeRef: { current: 'always-ask' },
|
|
189
190
|
spawnSelectionRef,
|
|
@@ -255,6 +255,7 @@ export function makeSendHarness(options: {
|
|
|
255
255
|
pendingComposerModelRef: { current: null },
|
|
256
256
|
pendingThinkingLevelRef: { current: null },
|
|
257
257
|
pendingHarnessRef: { current: null },
|
|
258
|
+
pendingAgentModeRef: { current: null },
|
|
258
259
|
deferredComposerPickRef: (options.deferredPick ?? { current: null }) as ChatTimelineSendDeps['deferredComposerPickRef'],
|
|
259
260
|
accessModeRef: { current: 'always-ask' },
|
|
260
261
|
spawnSelectionRef,
|
|
@@ -189,6 +189,7 @@ function makeSendHarness(options: {
|
|
|
189
189
|
pendingComposerModelRef: { current: null },
|
|
190
190
|
pendingThinkingLevelRef: { current: null },
|
|
191
191
|
pendingHarnessRef: { current: null },
|
|
192
|
+
pendingAgentModeRef: { current: null },
|
|
192
193
|
deferredComposerPickRef: options.deferredPick ?? { current: null },
|
|
193
194
|
accessModeRef: { current: 'always-ask' },
|
|
194
195
|
spawnSelectionRef,
|
|
@@ -150,6 +150,10 @@ export function useSessionHarness(
|
|
|
150
150
|
const pick = useCallback((next: string) => {
|
|
151
151
|
// The ref is what the SEND path reads; the store is what every renderer
|
|
152
152
|
// reads. A pick that moved only one of them is the reported defect.
|
|
153
|
+
//
|
|
154
|
+
// The WARM of the picked agent is not fired here: `usePendingWarmup` owns it
|
|
155
|
+
// and re-fires on this store change, so there is one path that decides which
|
|
156
|
+
// process is warmed (and it resolves the cwd exactly as the send does).
|
|
153
157
|
pendingHarnessRef.current = next;
|
|
154
158
|
setHarnessPick(sessionId, next);
|
|
155
159
|
}, [pendingHarnessRef, sessionId]);
|
|
@@ -15,43 +15,30 @@
|
|
|
15
15
|
|
|
16
16
|
import { useCallback } from 'preact/hooks';
|
|
17
17
|
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { formatNewSessionTitle } from '@/shared/lib/omp/session/default-title';
|
|
18
|
+
import { forkAnchorFor, type ForkAnchorRole } from '@/shared/lib/chat/timeline/fork-anchor';
|
|
19
|
+
import { openForkSession } from '@/client/hooks/chat/timeline/fork-open';
|
|
21
20
|
import type { WorkspaceFolderData } from '@/shared/types';
|
|
22
21
|
|
|
23
22
|
export function useForkSession(
|
|
24
23
|
sessionId: string | null | undefined,
|
|
25
24
|
folders: WorkspaceFolderData[],
|
|
26
25
|
selectedFolderId: number | null,
|
|
27
|
-
): (messageId: string) => void {
|
|
26
|
+
): (messageId: string, role: ForkAnchorRole) => void {
|
|
28
27
|
const [, setSearchParams] = useSearchParams();
|
|
29
28
|
|
|
30
29
|
return useCallback(
|
|
31
|
-
(messageId: string) => {
|
|
30
|
+
(messageId: string, role: ForkAnchorRole) => {
|
|
32
31
|
if (!sessionId) return;
|
|
33
32
|
const source = folders
|
|
34
33
|
.flatMap((folder) => folder.sessions ?? [])
|
|
35
34
|
.find((session) => String(session.id) === sessionId);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
title: formatNewSessionTitle(new Date(), 'Fork'),
|
|
35
|
+
openForkSession({
|
|
36
|
+
sourceSessionId: String(sessionId),
|
|
39
37
|
...(source?.harness ? { harness: source.harness } : {}),
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
folderId: source?.folder_id ?? selectedFolderId ?? null,
|
|
39
|
+
anchorEntryId: forkAnchorFor(source?.harness, messageId, role),
|
|
40
|
+
setSearchParams,
|
|
42
41
|
});
|
|
43
|
-
// The picker's first tab is the source's agent; the fork cannot change
|
|
44
|
-
// provider because that agent owns the history being branched.
|
|
45
|
-
if (source?.harness) setHarnessPick(pendingId, source.harness);
|
|
46
|
-
setSearchParams((prev) => {
|
|
47
|
-
const next = new URLSearchParams(prev);
|
|
48
|
-
next.set('sessionId', pendingId);
|
|
49
|
-
next.set('forkFrom', String(sessionId));
|
|
50
|
-
next.set('forkAt', messageId);
|
|
51
|
-
next.delete('parentSessionId');
|
|
52
|
-
if (folderId !== null && folderId !== undefined) next.set('folderId', String(folderId));
|
|
53
|
-
return next;
|
|
54
|
-
}, { replace: true });
|
|
55
42
|
},
|
|
56
43
|
[sessionId, folders, selectedFolderId, setSearchParams],
|
|
57
44
|
);
|
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Dropping a held prompt from the row that shows it.
|
|
8
8
|
*
|
|
9
|
+
* Cancelling returns the prompt to the composer, never to nowhere: the send
|
|
10
|
+
* path cleared the draft when the row was created, so the row is the only copy
|
|
11
|
+
* of what the user wrote. The chat itself is KEPT (the pending entry is not
|
|
12
|
+
* released) — the text it was going to send is back in the box the user is
|
|
13
|
+
* looking at.
|
|
14
|
+
*
|
|
9
15
|
* A refusal is REPORTED: the only two refusals are "already sent" (the prompt
|
|
10
16
|
* is running now, so Stop the session instead) and "no longer there", and both
|
|
11
17
|
* leave the row on screen. Swallowing them would leave a row that looks stuck
|
|
@@ -14,7 +20,8 @@
|
|
|
14
20
|
|
|
15
21
|
import { useCallback } from 'preact/hooks';
|
|
16
22
|
import { cancelWaitingPromptRequest } from '@/client/hooks/chat/waiting/store';
|
|
17
|
-
import {
|
|
23
|
+
import { markPendingSessionDraft } from '@/client/hooks/chat/omp/pending-waiting';
|
|
24
|
+
import { restoreHeldDraft } from '@/client/hooks/chat/waiting/restore';
|
|
18
25
|
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
19
26
|
|
|
20
27
|
export type CancelWait = (waitId: string) => void;
|
|
@@ -22,14 +29,14 @@ export type CancelWait = (waitId: string) => void;
|
|
|
22
29
|
export function useCancelWait(onNotice?: (message: string, type?: ToastTone) => void): CancelWait {
|
|
23
30
|
return useCallback((waitId: string) => {
|
|
24
31
|
void cancelWaitingPromptRequest(waitId).then((result) => {
|
|
25
|
-
if (!result.ok) {
|
|
32
|
+
if (!result.ok || !result.prompt) {
|
|
26
33
|
onNotice?.(result.error ?? 'Could not cancel the waiting prompt.', 'error');
|
|
27
34
|
return;
|
|
28
35
|
}
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
onNotice?.('Waiting prompt cancelled.', 'success');
|
|
36
|
+
restoreHeldDraft(result.prompt);
|
|
37
|
+
// The chat stays as an UNSENT draft carrying the restored text.
|
|
38
|
+
if (result.prompt.pendingId) markPendingSessionDraft(result.prompt.pendingId);
|
|
39
|
+
onNotice?.('Waiting prompt cancelled — your draft is back in the composer.', 'success');
|
|
33
40
|
});
|
|
34
41
|
}, [onNotice]);
|
|
35
42
|
}
|
|
@@ -6,17 +6,19 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* The composer's "wait for session" pick, per chat.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Applies to whatever this chat sends NEXT: the first prompt of a pending
|
|
10
|
+
* `new-…` chat, or a follow-up in a chat that already has a session. Held in
|
|
11
|
+
* the session's own UI state (`chat.waitingFor`) rather than in component
|
|
12
|
+
* state: the composer is remounted by a stretch, a tab switch and a reload, and
|
|
13
|
+
* a pick that evaporated with it would silently send the prompt immediately —
|
|
14
|
+
* the one outcome the user explicitly deferred.
|
|
13
15
|
*
|
|
14
16
|
* The ref is the other half, and it is not redundant: the send handler is
|
|
15
17
|
* created once per deps record, so reading the pick from render state there
|
|
16
18
|
* would dispatch with whatever it was when that closure was built.
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
|
-
import { useCallback,
|
|
21
|
+
import { useCallback, useRef } from 'preact/hooks';
|
|
20
22
|
import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
21
23
|
import type { WaitingCandidate } from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
22
24
|
|
|
@@ -27,21 +29,16 @@ export interface WaitingDependencyChoice {
|
|
|
27
29
|
clear: () => void;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export function useWaitingDependencyChoice(
|
|
32
|
+
export function useWaitingDependencyChoice(): WaitingDependencyChoice {
|
|
31
33
|
const [stored, setStored] = useSessionState<WaitingCandidate | null>('chat.waitingFor', null);
|
|
32
34
|
const ref = useRef<WaitingCandidate | null>(stored);
|
|
33
35
|
ref.current = stored;
|
|
34
36
|
|
|
35
|
-
// The pick belongs to
|
|
36
|
-
//
|
|
37
|
-
// cleared
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
const pending = Boolean(sessionId?.startsWith('new-'));
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (!pending && stored !== null) setStored(null);
|
|
43
|
-
}, [pending, stored, setStored]);
|
|
44
|
-
|
|
37
|
+
// The pick belongs to THIS chat's next prompt, whatever the chat is: a pending
|
|
38
|
+
// `new-…` chat defers its first send, and a chat with an omp id defers a
|
|
39
|
+
// follow-up. It is cleared by the send that consumes it, never by the session
|
|
40
|
+
// id changing shape — that clearing was what confined the feature to a new
|
|
41
|
+
// chat's first prompt.
|
|
45
42
|
const set = useCallback((candidate: WaitingCandidate | null) => {
|
|
46
43
|
ref.current = candidate;
|
|
47
44
|
setStored(candidate);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The chat composer's "wait for session" wiring, in one place.
|
|
8
|
+
*
|
|
9
|
+
* Two facts have to agree: the candidates are the sessions with a run in flight
|
|
10
|
+
* (never this chat), and the held banner belongs to whichever chat the row
|
|
11
|
+
* names. Keeping them in one hook is what stops the toolbar picker and the
|
|
12
|
+
* banner from reading two different lists — and it keeps `ChatTimeline` under
|
|
13
|
+
* the per-file ceiling.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { useMemo } from 'preact/hooks';
|
|
17
|
+
import { useHeldWait } from '@/client/hooks/chat/waiting/held';
|
|
18
|
+
import { waitingCandidates, type WaitingCandidate } from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
19
|
+
import type { WorkspaceFolderData } from '@/shared/types/workspace';
|
|
20
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
21
|
+
|
|
22
|
+
export interface ComposerWaitOptions {
|
|
23
|
+
sessionId: string | null;
|
|
24
|
+
folders: WorkspaceFolderData[];
|
|
25
|
+
streamStatusMap: Record<string, string | undefined>;
|
|
26
|
+
/** A name for a streaming id the sidebar structure has not scanned yet. */
|
|
27
|
+
titleFor?: (id: string) => string | undefined;
|
|
28
|
+
value: WaitingCandidate | null;
|
|
29
|
+
onChange: (candidate: WaitingCandidate | null) => void;
|
|
30
|
+
onNotice?: (message: string, tone?: ToastTone) => void;
|
|
31
|
+
/** A held prompt for this chat was delivered by the server's sweep. */
|
|
32
|
+
onDispatched?: (sessionId: string) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ComposerWait {
|
|
36
|
+
/** Props for the composer toolbar's picker. */
|
|
37
|
+
waiting: {
|
|
38
|
+
value: WaitingCandidate | null;
|
|
39
|
+
candidates: WaitingCandidate[];
|
|
40
|
+
onChange: (candidate: WaitingCandidate | null) => void;
|
|
41
|
+
};
|
|
42
|
+
/** Props for the held-prompt banner above the composer. */
|
|
43
|
+
held: {
|
|
44
|
+
heldWait: { title: string | null } | null;
|
|
45
|
+
onCancelWait: () => void;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useComposerWait(options: ComposerWaitOptions): ComposerWait {
|
|
50
|
+
const { sessionId, folders, streamStatusMap, titleFor, value, onChange, onNotice, onDispatched } = options;
|
|
51
|
+
const { heldWait, cancelHeldWait } = useHeldWait(sessionId, {
|
|
52
|
+
...(onNotice ? { onNotice } : {}),
|
|
53
|
+
...(onDispatched ? { onDispatched } : {}),
|
|
54
|
+
});
|
|
55
|
+
const candidates = useMemo(
|
|
56
|
+
() => waitingCandidates(folders, streamStatusMap, sessionId, titleFor),
|
|
57
|
+
[folders, streamStatusMap, sessionId, titleFor],
|
|
58
|
+
);
|
|
59
|
+
const waiting = useMemo(
|
|
60
|
+
() => ({ value, candidates, onChange }),
|
|
61
|
+
[value, candidates, onChange],
|
|
62
|
+
);
|
|
63
|
+
return {
|
|
64
|
+
waiting,
|
|
65
|
+
held: {
|
|
66
|
+
heldWait: heldWait ? { title: heldWait.dependsOnTitle } : null,
|
|
67
|
+
onCancelWait: cancelHeldWait,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -21,9 +21,9 @@ import { useEffect, useRef } from 'preact/hooks';
|
|
|
21
21
|
import { useWaitingPrompts } from '@/client/hooks/chat/waiting/store';
|
|
22
22
|
import {
|
|
23
23
|
adoptPendingSession,
|
|
24
|
-
releasePendingSession,
|
|
25
24
|
} from '@/client/hooks/chat/omp/pending-sessions';
|
|
26
|
-
import {
|
|
25
|
+
import { markPendingSessionDraft, pendingSessionWait } from '@/client/hooks/chat/omp/pending-waiting';
|
|
26
|
+
import { restoreHeldDraft } from '@/client/hooks/chat/waiting/restore';
|
|
27
27
|
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
28
28
|
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
29
29
|
|
|
@@ -47,45 +47,65 @@ export function useWaitingDispatch({ onNotice }: WaitingDispatchOptions = {}): v
|
|
|
47
47
|
// be an effect dependency: every unrelated render would re-run this walk.
|
|
48
48
|
const noticeRef = useRef(onNotice);
|
|
49
49
|
noticeRef.current = onNotice;
|
|
50
|
+
// Rows are retained for a day, so an outcome must be handled ONCE per tab —
|
|
51
|
+
// otherwise every waiting-topic frame adopts again and repeats the toast.
|
|
52
|
+
const handledRef = useRef(new Set<string>());
|
|
50
53
|
|
|
51
54
|
useEffect(() => {
|
|
55
|
+
const openId = new URLSearchParams(window.location.search).get('sessionId');
|
|
52
56
|
for (const prompt of prompts) {
|
|
53
57
|
const pendingId = prompt.pendingId;
|
|
54
|
-
|
|
55
|
-
const held = pendingSessionWait(pendingId);
|
|
58
|
+
const targetId = prompt.targetSessionId;
|
|
59
|
+
const held = pendingId ? pendingSessionWait(pendingId) : null;
|
|
60
|
+
// The chat this outcome belongs to: a pending slot this tab still holds
|
|
61
|
+
// (or has open), or an existing session open in this tab.
|
|
62
|
+
const ownsPending = Boolean(pendingId) && (Boolean(held) || openId === pendingId);
|
|
63
|
+
const ownsTarget = Boolean(targetId) && openId === targetId;
|
|
64
|
+
if (!pendingId && !targetId) continue;
|
|
65
|
+
|
|
66
|
+
const outcomeKey = `${prompt.id}:${prompt.status}`;
|
|
67
|
+
if (handledRef.current.has(outcomeKey)) continue;
|
|
56
68
|
|
|
57
69
|
if (prompt.status === 'dispatched' && prompt.sessionId) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
handledRef.current.add(outcomeKey);
|
|
71
|
+
if (pendingId && ownsPending) {
|
|
72
|
+
adoptPendingSession(pendingId, prompt.sessionId, prompt.folderId);
|
|
73
|
+
// The URL may still name the pending id — this tab was left on the chat
|
|
74
|
+
// while the dispatch happened elsewhere.
|
|
75
|
+
setSearchParams((prev) => {
|
|
76
|
+
if (prev.get('sessionId') !== pendingId) return prev;
|
|
77
|
+
const next = new URLSearchParams(prev);
|
|
78
|
+
next.set('sessionId', prompt.sessionId as string);
|
|
79
|
+
return next;
|
|
80
|
+
}, { replace: true });
|
|
81
|
+
noticeRef.current?.('Waiting finished — your prompt is now running in a new session.', 'success');
|
|
82
|
+
} else if (targetId && ownsTarget) {
|
|
83
|
+
// The transcript reload is driven by the chat's own `useHeldWait`
|
|
84
|
+
// (it sees this row flip); this is only the user-facing report.
|
|
85
|
+
noticeRef.current?.('Waiting finished — your prompt is now running in this chat.', 'success');
|
|
86
|
+
}
|
|
74
87
|
continue;
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
if (prompt.status === 'error') {
|
|
78
|
-
|
|
79
|
-
if (!
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
noticeRef.current?.(
|
|
91
|
+
handledRef.current.add(outcomeKey);
|
|
92
|
+
if (!ownsPending && !ownsTarget) continue;
|
|
93
|
+
restoreHeldDraft(prompt);
|
|
94
|
+
if (pendingId) markPendingSessionDraft(pendingId);
|
|
95
|
+
noticeRef.current?.(
|
|
96
|
+
`The prompt you held was not sent: ${prompt.error ?? 'the dispatch failed.'} Your draft is back in the composer.`,
|
|
97
|
+
'error',
|
|
98
|
+
);
|
|
83
99
|
continue;
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
if (prompt.status === 'cancelled'
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
if (prompt.status === 'cancelled') {
|
|
103
|
+
handledRef.current.add(outcomeKey);
|
|
104
|
+
if (!ownsPending && !ownsTarget) continue;
|
|
105
|
+
// The tab that cancelled already reported it; this covers a cancel from
|
|
106
|
+
// another tab/instance. The chat and its draft are kept either way.
|
|
107
|
+
restoreHeldDraft(prompt);
|
|
108
|
+
if (pendingId) markPendingSessionDraft(pendingId);
|
|
89
109
|
}
|
|
90
110
|
}
|
|
91
111
|
}, [prompts, setSearchParams]);
|
|
@@ -6,38 +6,62 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* The held prompt of the chat on screen, and how to drop it.
|
|
8
8
|
*
|
|
9
|
-
* A chat whose prompt is deferred has no
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* A chat whose prompt is deferred has no new transcript, so the composer is the
|
|
10
|
+
* only place the wait is visible — and it must be DISABLED while the wait
|
|
11
|
+
* lasts: a second prompt would have nowhere to go. The wait may belong to a
|
|
12
|
+
* pending `new-…` chat or to an existing session's NEXT prompt, so the lookup
|
|
13
|
+
* names both slots.
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
|
-
import { useCallback, useMemo } from 'preact/hooks';
|
|
16
|
+
import { useCallback, useEffect, useMemo, useRef } from 'preact/hooks';
|
|
15
17
|
import { useWaitingPrompts } from '@/client/hooks/chat/waiting/store';
|
|
16
18
|
import { useCancelWait } from '@/client/hooks/chat/waiting/cancel';
|
|
17
19
|
import type { WaitingPrompt } from '@/shared/types/waiting';
|
|
18
20
|
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
19
21
|
|
|
22
|
+
export interface HeldWaitOptions {
|
|
23
|
+
onNotice?: (message: string, type?: ToastTone) => void;
|
|
24
|
+
/**
|
|
25
|
+
* A prompt held for THIS existing chat was just delivered elsewhere (the
|
|
26
|
+
* server's sweep). The transcript has no local frames for it, so the view
|
|
27
|
+
* asks the session to reload.
|
|
28
|
+
*/
|
|
29
|
+
onDispatched?: (sessionId: string) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
export interface HeldWait {
|
|
21
33
|
/** The waiting row for the open chat, or null. */
|
|
22
34
|
heldWait: WaitingPrompt | null;
|
|
23
35
|
cancelHeldWait: () => void;
|
|
24
36
|
}
|
|
25
37
|
|
|
26
|
-
export function useHeldWait(
|
|
27
|
-
sessionId: string | null,
|
|
28
|
-
isPendingSession: boolean,
|
|
29
|
-
onNotice?: (message: string, type?: ToastTone) => void,
|
|
30
|
-
): HeldWait {
|
|
38
|
+
export function useHeldWait(sessionId: string | null, options: HeldWaitOptions = {}): HeldWait {
|
|
31
39
|
const { prompts } = useWaitingPrompts();
|
|
32
|
-
const cancelWait = useCancelWait(onNotice);
|
|
40
|
+
const cancelWait = useCancelWait(options.onNotice);
|
|
41
|
+
const { onDispatched } = options;
|
|
33
42
|
const heldWait = useMemo(
|
|
34
|
-
() => (
|
|
35
|
-
? prompts.find((prompt) => prompt.
|
|
43
|
+
() => (sessionId
|
|
44
|
+
? prompts.find((prompt) => prompt.status === 'waiting'
|
|
45
|
+
&& (prompt.pendingId === sessionId || prompt.targetSessionId === sessionId)) ?? null
|
|
36
46
|
: null),
|
|
37
|
-
[
|
|
47
|
+
[sessionId, prompts],
|
|
38
48
|
);
|
|
39
49
|
const cancelHeldWait = useCallback(() => {
|
|
40
50
|
if (heldWait) cancelWait(heldWait.id);
|
|
41
51
|
}, [heldWait, cancelWait]);
|
|
52
|
+
|
|
53
|
+
// The sweep writes `dispatched`; nothing else tells an open chat to re-read
|
|
54
|
+
// its own transcript. One reload per row, not per topic frame.
|
|
55
|
+
const dispatchedRef = useRef(new Set<string>());
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!sessionId || !onDispatched) return;
|
|
58
|
+
for (const prompt of prompts) {
|
|
59
|
+
if (prompt.status !== 'dispatched' || prompt.targetSessionId !== sessionId) continue;
|
|
60
|
+
if (dispatchedRef.current.has(prompt.id)) continue;
|
|
61
|
+
dispatchedRef.current.add(prompt.id);
|
|
62
|
+
onDispatched(sessionId);
|
|
63
|
+
}
|
|
64
|
+
}, [prompts, sessionId, onDispatched]);
|
|
65
|
+
|
|
42
66
|
return { heldWait, cancelHeldWait };
|
|
43
67
|
}
|
|
@@ -46,6 +46,7 @@ function harness(overrides: Partial<HoldDeps> = {}): { deps: HoldDeps; recorded:
|
|
|
46
46
|
const recorded: Recorded = { drafts: [], attachments: [], errors: [], cleared: 0, posted: [] };
|
|
47
47
|
const deps: HoldDeps = {
|
|
48
48
|
sessionId: pendingId,
|
|
49
|
+
targetSessionId: null,
|
|
49
50
|
folders: [{ id: 1, name: 'alpha', project_path: '/tmp/alpha', isExpanded: true, hasMore: false, totalSessions: 0, sessions: [] }],
|
|
50
51
|
selectedFolderId: 1,
|
|
51
52
|
composerModelRef: { current: { provider: 'anthropic', modelId: 'claude', thinkingLevel: 'high' } },
|
|
@@ -107,6 +108,27 @@ describe('holdPromptForDependency', () => {
|
|
|
107
108
|
expect(recorded.drafts).toEqual([]);
|
|
108
109
|
});
|
|
109
110
|
|
|
111
|
+
// A NEXT prompt in a chat that already exists is delivered into that chat.
|
|
112
|
+
// It has no pending slot to mark, and the cwd comes from the session itself.
|
|
113
|
+
test('an existing chat targets its own session and needs no pending cue', async () => {
|
|
114
|
+
const { deps, recorded } = harness({
|
|
115
|
+
sessionId: 'sess-open',
|
|
116
|
+
targetSessionId: 'sess-open',
|
|
117
|
+
selectedFolderId: null,
|
|
118
|
+
folders: [],
|
|
119
|
+
});
|
|
120
|
+
expect(await holdPromptForDependency(deps, DEPENDENCY, 'do it after', [])).toBe(true);
|
|
121
|
+
expect(createdBody).toMatchObject({
|
|
122
|
+
pendingId: null,
|
|
123
|
+
targetSessionId: 'sess-open',
|
|
124
|
+
dependsOn: 'sess-a',
|
|
125
|
+
prompt: 'do it after',
|
|
126
|
+
cwd: '',
|
|
127
|
+
});
|
|
128
|
+
expect(recorded.drafts).toEqual(['']);
|
|
129
|
+
expect(recorded.errors).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
|
|
110
132
|
// The dropdown was opened while the dependency was running; by the time the
|
|
111
133
|
// user hit send it had finished. Holding would be a wait of zero length.
|
|
112
134
|
test('a dependency that finished meanwhile sends instead, and says so', async () => {
|
|
@@ -46,24 +46,30 @@ export interface ComposerHoldDeps {
|
|
|
46
46
|
waitingDependencyRef?: { current: WaitingCandidate | null };
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** A pending chat has no omp id yet; everything else is a real session. */
|
|
50
|
+
function isPendingChat(sessionId: string | null): boolean {
|
|
51
|
+
return !sessionId || sessionId.startsWith('new-');
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
/**
|
|
50
|
-
* The composer's own entry point: hold the draft if a dependency is picked
|
|
51
|
-
*
|
|
55
|
+
* The composer's own entry point: hold the draft if a dependency is picked,
|
|
56
|
+
* else answer false and let the normal send proceed.
|
|
52
57
|
*
|
|
53
|
-
*
|
|
54
|
-
* a
|
|
55
|
-
*
|
|
58
|
+
* A chat with a run in flight is NOT excluded: holding is a deferral to another
|
|
59
|
+
* session, not a send, so it is the one path that may run while this chat is
|
|
60
|
+
* busy. The running chat's own follow-up still takes the queue branch, because
|
|
61
|
+
* without a pick this function returns false and the send path queues it.
|
|
56
62
|
*/
|
|
57
63
|
export async function holdFromComposer(
|
|
58
64
|
deps: ComposerHoldDeps,
|
|
59
65
|
text: string,
|
|
60
66
|
attachments: Attachment[],
|
|
61
|
-
busy: boolean,
|
|
62
67
|
): Promise<boolean> {
|
|
63
68
|
const choice = deps.waitingDependencyRef?.current ?? null;
|
|
64
|
-
if (!choice
|
|
69
|
+
if (!choice) return false;
|
|
65
70
|
return holdPromptForDependency({
|
|
66
71
|
sessionId: deps.sessionId,
|
|
72
|
+
targetSessionId: isPendingChat(deps.sessionId) ? null : deps.sessionId,
|
|
67
73
|
folders: deps.folders,
|
|
68
74
|
selectedFolderId: deps.selectedFolderId,
|
|
69
75
|
composerModelRef: deps.composerModelRef,
|
|
@@ -79,6 +85,8 @@ export async function holdFromComposer(
|
|
|
79
85
|
|
|
80
86
|
export interface HoldDeps {
|
|
81
87
|
sessionId: string | null;
|
|
88
|
+
/** The existing chat this prompt is sent into; null for a pending chat. */
|
|
89
|
+
targetSessionId: string | null;
|
|
82
90
|
folders: WorkspaceFolderData[];
|
|
83
91
|
selectedFolderId: number | null;
|
|
84
92
|
composerModelRef: { current: { provider: string; modelId: string; thinkingLevel: string } | null };
|
|
@@ -114,8 +122,8 @@ export async function holdPromptForDependency(
|
|
|
114
122
|
return false;
|
|
115
123
|
}
|
|
116
124
|
const folder = deps.folders.find((entry) => String(entry.id) === String(deps.selectedFolderId));
|
|
117
|
-
const cwd = folder?.project_path || folder?.name;
|
|
118
|
-
if (!cwd) {
|
|
125
|
+
const cwd = folder?.project_path || folder?.name || '';
|
|
126
|
+
if (!cwd && !deps.targetSessionId) {
|
|
119
127
|
deps.reportActionError('Pick a workspace before holding this prompt.');
|
|
120
128
|
return false;
|
|
121
129
|
}
|
|
@@ -126,7 +134,8 @@ export async function holdPromptForDependency(
|
|
|
126
134
|
const composerPick = deps.composerModelRef.current;
|
|
127
135
|
try {
|
|
128
136
|
const created = await createWaitingPromptRequest({
|
|
129
|
-
pendingId: deps.sessionId,
|
|
137
|
+
pendingId: deps.targetSessionId ? null : deps.sessionId,
|
|
138
|
+
targetSessionId: deps.targetSessionId,
|
|
130
139
|
dependsOn: dependency.id,
|
|
131
140
|
dependsOnTitle: dependency.title,
|
|
132
141
|
prompt: text,
|
|
@@ -136,7 +145,7 @@ export async function holdPromptForDependency(
|
|
|
136
145
|
cwd,
|
|
137
146
|
folderId: folder ? Number(folder.id) : null,
|
|
138
147
|
});
|
|
139
|
-
if (deps.sessionId) {
|
|
148
|
+
if (deps.sessionId && !deps.targetSessionId) {
|
|
140
149
|
markPendingSessionWaiting(deps.sessionId, {
|
|
141
150
|
waitId: created.id,
|
|
142
151
|
dependsOn: dependency.id,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Cancelling or failing a held prompt must return its text.
|
|
8
|
+
*
|
|
9
|
+
* The send path clears the composer when it creates the row, so the row is the
|
|
10
|
+
* only copy remaining. These cases pin where that copy goes back: the pending
|
|
11
|
+
* chat's draft slot, or the existing session's — and nowhere at all when the row
|
|
12
|
+
* names neither.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { restoreHeldDraft, waitingDraftSessionId } from '@/client/hooks/chat/waiting/restore';
|
|
17
|
+
import { forgetSession, getSessionValue } from '@/shared/lib/workspace/session-state/store';
|
|
18
|
+
import { CHAT_DRAFT_ATTACHMENTS_KEY, CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
19
|
+
import type { WaitingPrompt } from '@/shared/types/waiting';
|
|
20
|
+
|
|
21
|
+
function prompt(overrides: Partial<WaitingPrompt> = {}): WaitingPrompt {
|
|
22
|
+
return {
|
|
23
|
+
id: 'wait-1',
|
|
24
|
+
pendingId: 'new-1',
|
|
25
|
+
dependsOn: 'sess-a',
|
|
26
|
+
dependsOnTitle: 'Session A',
|
|
27
|
+
targetSessionId: null,
|
|
28
|
+
prompt: 'summarise the diff',
|
|
29
|
+
attachments: [{ id: 'a1', preview: 'data:text/plain;base64,aGk=', name: 'notes.txt', content: 'hi' }],
|
|
30
|
+
model: null,
|
|
31
|
+
modes: null,
|
|
32
|
+
cwd: '/tmp/project',
|
|
33
|
+
folderId: 1,
|
|
34
|
+
status: 'cancelled',
|
|
35
|
+
sessionId: null,
|
|
36
|
+
error: null,
|
|
37
|
+
createdAt: 0,
|
|
38
|
+
updatedAt: 0,
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
forgetSession('new-1');
|
|
45
|
+
forgetSession('sess-open');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('restoreHeldDraft', () => {
|
|
49
|
+
test('writes a pending chat’s text and attachments back into its draft', () => {
|
|
50
|
+
restoreHeldDraft(prompt());
|
|
51
|
+
expect(getSessionValue('new-1', CHAT_DRAFT_KEY)).toBe('summarise the diff');
|
|
52
|
+
expect(getSessionValue('new-1', CHAT_DRAFT_ATTACHMENTS_KEY)).toEqual([
|
|
53
|
+
{ id: 'a1', preview: 'data:text/plain;base64,aGk=', name: 'notes.txt', content: 'hi' },
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('restores a next prompt into the session it targeted', () => {
|
|
58
|
+
restoreHeldDraft(prompt({ pendingId: null, targetSessionId: 'sess-open' }));
|
|
59
|
+
expect(waitingDraftSessionId(prompt({ pendingId: null, targetSessionId: 'sess-open' }))).toBe('sess-open');
|
|
60
|
+
expect(getSessionValue('sess-open', CHAT_DRAFT_KEY)).toBe('summarise the diff');
|
|
61
|
+
expect(getSessionValue('new-1', CHAT_DRAFT_KEY)).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('a row naming no chat writes nothing', () => {
|
|
65
|
+
restoreHeldDraft(prompt({ pendingId: null, targetSessionId: null }));
|
|
66
|
+
expect(getSessionValue('new-1', CHAT_DRAFT_KEY)).toBeUndefined();
|
|
67
|
+
expect(getSessionValue('sess-open', CHAT_DRAFT_KEY)).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
});
|