@kabmo-labs/kabmo 0.26.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 +502 -474
- package/dist/client/static/js/index-81f7berm.css +1 -0
- package/dist/client/static/js/{index-95b3n20k.js → index-xzvyrxya.js} +799 -799
- 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/Toast.test.tsx +28 -2
- package/src/client/components/common/Toast.tsx +21 -9
- 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/desktop-layout/LeftColumn.tsx +2 -1
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +4 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
- package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
- package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -1
- package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +12 -29
- package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
- 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 +5 -1
- package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
- package/src/client/components/mobile/SessionSidebar.tsx +2 -1
- 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/ClassicDrawer.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +4 -2
- package/src/client/components/mobile/mobile-session-sidebar/List.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 +7 -3
- 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/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
- package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -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 +61 -56
- 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/PendingChatView.tsx +11 -1
- package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
- 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/fork-preview.test.tsx +141 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +17 -6
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +3 -10
- 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/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
- 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/git-panel/index.tsx +2 -2
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +17 -6
- 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 +17 -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/omp/session-list.tsx +5 -0
- package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
- package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -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/fork-preview.test.ts +148 -0
- package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
- package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -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-branch.ts +9 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +53 -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/stop-with-queue.ts +1 -1
- package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
- package/src/client/hooks/chat/waiting/cancel.ts +15 -7
- 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 +50 -29
- package/src/client/hooks/chat/waiting/held.ts +38 -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/settings/providers/actions.ts +3 -2
- package/src/client/hooks/settings/providers/messages.ts +9 -7
- package/src/client/hooks/settings/providers/model-actions.ts +2 -1
- package/src/client/hooks/ui/editor-error-toast.ts +2 -1
- package/src/client/hooks/ui/notifications.ts +17 -8
- package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
- package/src/client/hooks/workspace/batch-archive.ts +4 -2
- package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
- package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
- package/src/client/hooks/workspace/panel-registry.ts +1 -1
- package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
- package/src/client/hooks/workspace/session-actions.test.ts +2 -1
- package/src/client/hooks/workspace/session-actions.ts +2 -1
- package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
- package/src/client/hooks/workspace/terminal/connection.ts +47 -0
- package/src/client/hooks/workspace/terminal/index.ts +35 -4
- package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
- 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/usage/report.server.ts +57 -0
- 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/chat/timeline/fork-preview.test.ts +62 -0
- package/src/shared/lib/chat/timeline/fork-preview.ts +36 -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/ui/toast-duration.test.ts +25 -1
- package/src/shared/lib/ui/toast-duration.ts +22 -4
- package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
- package/src/shared/lib/workspace/relative-time.ts +16 -0
- package/src/shared/lib/workspace/session-state/store.ts +4 -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-p2yw9ywf.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
|
@@ -31,6 +31,8 @@ import {
|
|
|
31
31
|
type AgentSessionWrapper,
|
|
32
32
|
} from '@/server/lib/omp/rpc/manager';
|
|
33
33
|
import { getRpcSession } from '@/server/lib/omp/rpc/session-registry';
|
|
34
|
+
import { ensureSessionLive } from '@/server/lib/sessions/dispatch.server';
|
|
35
|
+
import type { QueueDeliveryHost } from '@/server/lib/queue/delivery.server';
|
|
34
36
|
import { kabmoModeEnv } from '@/server/lib/omp/extensions/locator';
|
|
35
37
|
import { hasQueuedItem } from '@/server/lib/queue/store.server';
|
|
36
38
|
import { hasPendingDelivery } from '@/server/lib/queue/delivery.server';
|
|
@@ -86,6 +88,8 @@ export interface WaitingDeps {
|
|
|
86
88
|
modeEnv?: Record<string, string>,
|
|
87
89
|
): Promise<{ session: WaitingSessionHandle; realSessionId: string }>;
|
|
88
90
|
getSession(sessionId: string): AgentSessionWrapper | undefined;
|
|
91
|
+
/** Wake an EXISTING chat so a held next prompt can be delivered into it. */
|
|
92
|
+
ensureSessionLive(sessionId: string): Promise<QueueDeliveryHost | null>;
|
|
89
93
|
loadStreamStates(): Promise<StreamRowMap>;
|
|
90
94
|
/** Epoch ms of a session's last status write, or null when unknown. */
|
|
91
95
|
streamRowWrittenAt(sessionId: string): Promise<number | null>;
|
|
@@ -113,6 +117,7 @@ function defaultDeps(): WaitingDeps {
|
|
|
113
117
|
return {
|
|
114
118
|
startNewRpcSession,
|
|
115
119
|
getSession: getRpcSession,
|
|
120
|
+
ensureSessionLive,
|
|
116
121
|
loadStreamStates,
|
|
117
122
|
streamRowWrittenAt,
|
|
118
123
|
hasQueuedItem,
|
|
@@ -181,6 +186,16 @@ async function dispatchWaitingPrompt(
|
|
|
181
186
|
prompt: WaitingPrompt,
|
|
182
187
|
deps: WaitingDeps,
|
|
183
188
|
): Promise<{ sessionId: string }> {
|
|
189
|
+
// A next prompt in a chat that already exists is delivered THERE. Spawning
|
|
190
|
+
// would create a second session for text the user wrote in the first one.
|
|
191
|
+
if (prompt.targetSessionId) {
|
|
192
|
+
const target = await deps.ensureSessionLive(prompt.targetSessionId);
|
|
193
|
+
if (!target) throw new Error(`Session ${prompt.targetSessionId} could not be woken for the held prompt.`);
|
|
194
|
+
const send = (command: Record<string, unknown>) => target.send(command);
|
|
195
|
+
await applyModelSnapshot(send, prompt.model);
|
|
196
|
+
await send(promptCommand({ text: prompt.prompt, attachments: prompt.attachments, model: prompt.model }));
|
|
197
|
+
return { sessionId: prompt.targetSessionId };
|
|
198
|
+
}
|
|
184
199
|
const accessMode = prompt.model?.accessMode ?? (await deps.loadPersistedAccessMode());
|
|
185
200
|
const modeEnv = prompt.modes ? kabmoModeEnv(prompt.modes) : undefined;
|
|
186
201
|
const { session, realSessionId } = await deps.startNewRpcSession(prompt.cwd, accessMode, modeEnv);
|
|
@@ -215,6 +230,13 @@ export async function sweepWaitingPrompts(
|
|
|
215
230
|
for (const prompt of waiting) {
|
|
216
231
|
const state = await readDependencyState(prompt.dependsOn, deps, streams);
|
|
217
232
|
if (!dependencyVerdict(state, now).settled) continue;
|
|
233
|
+
// A target that is itself mid-turn refuses a prompt (omp drops it). The
|
|
234
|
+
// prompt is still wanted, so it stays `waiting` for the next sweep — the
|
|
235
|
+
// same conservative rule the dependency's own queue uses.
|
|
236
|
+
if (prompt.targetSessionId) {
|
|
237
|
+
const target = await readDependencyState(prompt.targetSessionId, deps, streams);
|
|
238
|
+
if (!dependencyVerdict(target, now).settled) continue;
|
|
239
|
+
}
|
|
218
240
|
if (!(await deps.claimWaitingPrompt(prompt.id))) continue;
|
|
219
241
|
try {
|
|
220
242
|
const { sessionId } = await withTimeout(
|
|
@@ -21,6 +21,7 @@ const WAITING_SCHEMA_SQL = `
|
|
|
21
21
|
pending_id TEXT,
|
|
22
22
|
depends_on TEXT NOT NULL,
|
|
23
23
|
depends_on_title TEXT,
|
|
24
|
+
target_session_id TEXT,
|
|
24
25
|
message TEXT NOT NULL DEFAULT '',
|
|
25
26
|
attachments TEXT NOT NULL DEFAULT '[]',
|
|
26
27
|
provider TEXT,
|
|
@@ -43,4 +44,11 @@ const WAITING_SCHEMA_SQL = `
|
|
|
43
44
|
/** Idempotent: the waiting prompts' own table, created on every database open. */
|
|
44
45
|
export async function ensureWaitingSchema(db: DbClient): Promise<void> {
|
|
45
46
|
await db.exec(WAITING_SCHEMA_SQL);
|
|
47
|
+
// `CREATE TABLE IF NOT EXISTS` does not add a column to an install that
|
|
48
|
+
// predates it, so the target column is installed separately. Same pattern as
|
|
49
|
+
// `btw/schema.server.ts`: introspect, then one ALTER.
|
|
50
|
+
const columns = (await db.all('PRAGMA table_info(waiting_prompts)')) as { name?: string }[];
|
|
51
|
+
if (!columns.some((column) => column.name === 'target_session_id')) {
|
|
52
|
+
await db.exec('ALTER TABLE waiting_prompts ADD COLUMN target_session_id TEXT');
|
|
53
|
+
}
|
|
46
54
|
}
|
|
@@ -55,6 +55,7 @@ const input = {
|
|
|
55
55
|
pendingId: 'new-1700000000000',
|
|
56
56
|
dependsOn: 'session-a',
|
|
57
57
|
dependsOnTitle: 'Session A',
|
|
58
|
+
targetSessionId: null,
|
|
58
59
|
prompt: 'summarise the diff',
|
|
59
60
|
attachments: [{ id: 'a1', preview: '', name: 'notes.txt', type: 'text/plain', content: 'hello' }],
|
|
60
61
|
model: { provider: 'anthropic', modelId: 'claude', thinkingLevel: 'high', accessMode: 'yolo' },
|
|
@@ -72,6 +73,7 @@ describe('waiting prompt store', () => {
|
|
|
72
73
|
pendingId: 'new-1700000000000',
|
|
73
74
|
dependsOn: 'session-a',
|
|
74
75
|
dependsOnTitle: 'Session A',
|
|
76
|
+
targetSessionId: null,
|
|
75
77
|
prompt: 'summarise the diff',
|
|
76
78
|
cwd: '/tmp/project',
|
|
77
79
|
folderId: 3,
|
|
@@ -86,6 +88,18 @@ describe('waiting prompt store', () => {
|
|
|
86
88
|
expect(stored?.attachments[0]?.content).toBe('hello');
|
|
87
89
|
});
|
|
88
90
|
|
|
91
|
+
test('a next prompt keeps the session it targets', async () => {
|
|
92
|
+
const created = await createWaitingPrompt({
|
|
93
|
+
...input,
|
|
94
|
+
pendingId: null,
|
|
95
|
+
targetSessionId: 'sess-open',
|
|
96
|
+
});
|
|
97
|
+
expect(await getWaitingPrompt(created.id)).toMatchObject({
|
|
98
|
+
pendingId: null,
|
|
99
|
+
targetSessionId: 'sess-open',
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
89
103
|
test('the claim is won once, and only from `waiting`', async () => {
|
|
90
104
|
const created = await createWaitingPrompt(input);
|
|
91
105
|
expect(await claimWaitingPrompt(created.id)).toBe(true);
|
|
@@ -32,6 +32,7 @@ interface WaitingRow {
|
|
|
32
32
|
pending_id: string | null;
|
|
33
33
|
depends_on: string;
|
|
34
34
|
depends_on_title: string | null;
|
|
35
|
+
target_session_id: string | null;
|
|
35
36
|
message: string;
|
|
36
37
|
attachments: string;
|
|
37
38
|
provider: string | null;
|
|
@@ -88,6 +89,7 @@ function rowToWaitingPrompt(row: WaitingRow): WaitingPrompt {
|
|
|
88
89
|
pendingId: row.pending_id,
|
|
89
90
|
dependsOn: row.depends_on,
|
|
90
91
|
dependsOnTitle: row.depends_on_title,
|
|
92
|
+
targetSessionId: row.target_session_id,
|
|
91
93
|
prompt: row.message,
|
|
92
94
|
attachments: Array.isArray(attachments) ? (attachments as Attachment[]) : [],
|
|
93
95
|
model: readModel(row),
|
|
@@ -106,6 +108,7 @@ export interface WaitingPromptInput {
|
|
|
106
108
|
pendingId?: string | null;
|
|
107
109
|
dependsOn: string;
|
|
108
110
|
dependsOnTitle?: string | null;
|
|
111
|
+
targetSessionId?: string | null;
|
|
109
112
|
prompt: string;
|
|
110
113
|
attachments?: unknown;
|
|
111
114
|
model?: unknown;
|
|
@@ -150,15 +153,16 @@ export async function createWaitingPrompt(input: WaitingPromptInput): Promise<Wa
|
|
|
150
153
|
const now = Date.now();
|
|
151
154
|
await db.run(
|
|
152
155
|
`INSERT INTO waiting_prompts
|
|
153
|
-
(id, pending_id, depends_on, depends_on_title, message, attachments,
|
|
156
|
+
(id, pending_id, depends_on, depends_on_title, target_session_id, message, attachments,
|
|
154
157
|
provider, model_id, thinking_level, access_mode, modes, cwd, folder_id,
|
|
155
158
|
status, session_id, error, created_at, updated_at)
|
|
156
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'waiting', NULL, NULL, ?, ?)`,
|
|
159
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'waiting', NULL, NULL, ?, ?)`,
|
|
157
160
|
[
|
|
158
161
|
id,
|
|
159
162
|
input.pendingId ?? null,
|
|
160
163
|
input.dependsOn,
|
|
161
164
|
input.dependsOnTitle ?? null,
|
|
165
|
+
input.targetSessionId ?? null,
|
|
162
166
|
input.prompt,
|
|
163
167
|
JSON.stringify(Array.isArray(input.attachments) ? input.attachments : []),
|
|
164
168
|
model?.provider ?? null,
|
|
@@ -48,13 +48,18 @@ describe('resuming a recorded non-omp chat', () => {
|
|
|
48
48
|
await releaseDb();
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
test('a retired harness id spawns NOTHING and
|
|
51
|
+
test('a retired harness id spawns NOTHING and refuses by name', async () => {
|
|
52
52
|
// `opencode2` is out of this build's catalog: a stale row must not be
|
|
53
|
-
// guessed at
|
|
53
|
+
// guessed at. The id is kept (a user-added harness has no static descriptor
|
|
54
|
+
// either), so the refusal names the missing launch line instead of the
|
|
55
|
+
// misleading "Session not found" — and no process is spawned.
|
|
54
56
|
await saveHarnessSession({ sessionId: RETIRED, harness: 'opencode2', agentSessionId: RETIRED, cwd: '/tmp' });
|
|
55
57
|
const response = await post(RETIRED, { type: 'prompt', message: 'hello' });
|
|
56
|
-
expect(response.status).toBe(
|
|
57
|
-
|
|
58
|
+
expect(response.status).toBe(400);
|
|
59
|
+
const body = await payload(response);
|
|
60
|
+
const message = typeof body.error === 'string' ? body.error : '';
|
|
61
|
+
expect(message).toContain('opencode2');
|
|
62
|
+
expect(message).not.toContain('Session not found');
|
|
58
63
|
});
|
|
59
64
|
|
|
60
65
|
test('a recorded non-omp chat is respawned on ITS OWN harness', async () => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which ACP mode a brand-new chat starts in.
|
|
8
|
+
*
|
|
9
|
+
* Two spellings reach this route: the composer's own ladder pick (`sessionMode`,
|
|
10
|
+
* the agent's vocabulary) and Kabmo's Plan flag (`modes.plan`, the omp toggle).
|
|
11
|
+
* The ladder wins — it can name any mode the agent publishes, and `plan` is just
|
|
12
|
+
* one of its values. A dropped mapping here starts the chat in the agent's
|
|
13
|
+
* default while the composer's chip names the operator's pick.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import { harnessModeSelection } from '@/server/routes/agent/new';
|
|
18
|
+
|
|
19
|
+
describe('harnessModeSelection', () => {
|
|
20
|
+
test("the composer's ladder pick is the mode", () => {
|
|
21
|
+
expect(harnessModeSelection({ sessionMode: 'architect' })).toBe('architect');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('the Plan flag maps to the plan mode when no ladder pick exists', () => {
|
|
25
|
+
expect(harnessModeSelection({ modes: { plan: true, goal: false } })).toBe('plan');
|
|
26
|
+
expect(harnessModeSelection({ modes: { plan: false, goal: true } })).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('an explicit pick wins over the flag, and a blank pick does not', () => {
|
|
30
|
+
expect(harnessModeSelection({ sessionMode: 'code', modes: { plan: true } })).toBe('code');
|
|
31
|
+
// A blank string is not a choice: the flag still decides.
|
|
32
|
+
expect(harnessModeSelection({ sessionMode: ' ', modes: { plan: true } })).toBe('plan');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('a spawn with neither names no mode', () => {
|
|
36
|
+
expect(harnessModeSelection({})).toBeNull();
|
|
37
|
+
expect(harnessModeSelection({ modes: null })).toBeNull();
|
|
38
|
+
expect(harnessModeSelection({ modes: { plan: 'yes' } })).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -8,7 +8,7 @@ import { rpcErrorResponse } from '@/server/lib/omp/rpc/errors';
|
|
|
8
8
|
import { kabmoModeEnv } from '@/server/lib/omp/extensions/locator';
|
|
9
9
|
import { parseModeSelection } from '@/server/lib/omp/mode/request';
|
|
10
10
|
import { projectModelForCwd } from '@/server/lib/workspace/project-model.server';
|
|
11
|
-
import {
|
|
11
|
+
import { harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
12
12
|
import { startAcpSession } from '@/server/lib/harness/spawn.server';
|
|
13
13
|
import { mintAgentEnvironment, rememberAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
14
14
|
import { isMockMode } from '@/server/mock.server';
|
|
@@ -80,7 +80,7 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
80
80
|
const modeEnv = modes ? kabmoModeEnv(modes) : undefined;
|
|
81
81
|
// A harness other than omp's RPC runs over ACP. The pick is validated
|
|
82
82
|
// against the catalog, so a typo cannot spawn an arbitrary binary.
|
|
83
|
-
const harness =
|
|
83
|
+
const harness = harnessDescriptor(typeof body.harness === 'string' ? body.harness : null) ? body.harness as HarnessId : 'omp-rpc';
|
|
84
84
|
// startNewRpcSession adopts the prewarmed idle process for this cwd when
|
|
85
85
|
// one exists (fired by the sidebar's New Session click) and otherwise
|
|
86
86
|
// cold-spawns — same contract, minus the boot wait when prewarmed.
|
|
@@ -158,23 +158,34 @@ async function startAcpChat({ harness, cwd, body, model, accessMode }: {
|
|
|
158
158
|
accessMode: ApprovalMode;
|
|
159
159
|
}): Promise<Response> {
|
|
160
160
|
const type = String(body.type ?? '');
|
|
161
|
-
const projectModel = await projectModelForCwd(await getDb(), cwd);
|
|
162
161
|
const thinkingLevel = typeof body.thinkingLevel === 'string' ? body.thinkingLevel : null;
|
|
163
162
|
const mode = harnessModeSelection(body);
|
|
164
163
|
const { token, env: agentEnv } = mintAgentEnvironment();
|
|
165
|
-
const { session, realSessionId } = await startAcpSession({
|
|
164
|
+
const { session, realSessionId, adopted } = await startAcpSession({
|
|
166
165
|
harness,
|
|
167
166
|
sessionId: `__new__${Bun.randomUUIDv7()}`,
|
|
168
167
|
cwd,
|
|
169
|
-
|
|
168
|
+
// The composer's pick, else the HARNESS's own configured default — resolved
|
|
169
|
+
// inside `startAcpSession` against what the agent published. omp's project
|
|
170
|
+
// and global model picks are deliberately NOT consulted: they name models
|
|
171
|
+
// this agent does not serve, and a value it happens to list would silently
|
|
172
|
+
// start the chat on a model the user never chose for it.
|
|
173
|
+
model,
|
|
170
174
|
thinkingLevel,
|
|
171
175
|
mode,
|
|
172
176
|
accessMode,
|
|
173
177
|
env: agentEnv,
|
|
178
|
+
// A pending chat's prewarm (fired when the harness was picked) is this
|
|
179
|
+
// chat's to adopt: the boot already happened while the prompt was written.
|
|
180
|
+
claimPrewarmed: true,
|
|
174
181
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
// A claimed warm child already recorded the token its environment carries;
|
|
183
|
+
// overwriting it here invalidated every callback that agent makes.
|
|
184
|
+
if (!adopted) {
|
|
185
|
+
await rememberAgentToken(realSessionId, token).catch((cause: unknown) => {
|
|
186
|
+
console.error(`[sessions] could not record the agent token for ${realSessionId}:`, cause);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
178
189
|
|
|
179
190
|
if (type === 'ensure_session') {
|
|
180
191
|
return json({ success: true, sessionId: realSessionId, model: session.runModel, data: null, harness });
|
|
@@ -190,8 +201,18 @@ async function startAcpChat({ harness, cwd, body, model, accessMode }: {
|
|
|
190
201
|
return json({ error: `Unsupported command: ${type}` }, { status: 400 });
|
|
191
202
|
}
|
|
192
203
|
|
|
193
|
-
/**
|
|
194
|
-
|
|
204
|
+
/**
|
|
205
|
+
* The ACP mode id a new chat asked for, when the composer sent one.
|
|
206
|
+
*
|
|
207
|
+
* Exported for its ONE contract: which of the two spellings wins. The route's
|
|
208
|
+
* ACP branch is a spawn, so this mapping is where a composer pick either reaches
|
|
209
|
+
* the agent or is silently dropped.
|
|
210
|
+
*/
|
|
211
|
+
export function harnessModeSelection(body: Record<string, unknown>): string | null {
|
|
212
|
+
// The composer's own mode ladder (a pending chat's pick from the harness
|
|
213
|
+
// probe). It wins over the Plan flag: the ladder IS the agent's vocabulary,
|
|
214
|
+
// and 'plan' is just one of its values.
|
|
215
|
+
if (typeof body.sessionMode === 'string' && body.sessionMode.trim()) return body.sessionMode;
|
|
195
216
|
const modes = asRecord(body.modes);
|
|
196
217
|
if (modes.plan === true) return 'plan';
|
|
197
218
|
return null;
|
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
import { json } from '@/server/lib/remix-compat';
|
|
2
2
|
import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
3
3
|
import { prewarmRpcSession } from '@/server/lib/omp/rpc/prewarm-pool';
|
|
4
|
+
import { prewarmAcpSession } from '@/server/lib/harness/acp/prewarm.server';
|
|
5
|
+
import { commandAvailable } from '@/server/lib/harness/auto-probe.server';
|
|
6
|
+
import { loadHarnessConfig } from '@/server/lib/harness/config.server';
|
|
7
|
+
import { kabmoModeEnv } from '@/server/lib/omp/extensions/locator';
|
|
8
|
+
import { parseModeSelection } from '@/server/lib/omp/mode/request';
|
|
4
9
|
import { isApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
5
10
|
import { loadPersistedAccessMode } from '@/shared/lib/omp/config/access-mode.server';
|
|
6
11
|
import { rpcErrorResponse } from '@/server/lib/omp/rpc/errors';
|
|
12
|
+
import { isMockMode } from '@/server/mock.server';
|
|
13
|
+
import { harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
/** A JSON object, or `{}` for anything else — same read as the spawn route. */
|
|
16
|
+
function asRecord(value: unknown): Record<string, unknown> {
|
|
17
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// POST /api/agent/prewarm — start an idle agent for the given cwd ahead of the
|
|
21
|
+
// first prompt so adopting it on send skips the boot. Fired when the user opens
|
|
22
|
+
// a new (pending) session and whenever the composer's harness pick moves; the
|
|
23
|
+
// spawn call in /api/agent/new claims it. Errors are non-fatal by design: a
|
|
24
|
+
// failed prewarm just means the next send spawns cold.
|
|
25
|
+
//
|
|
26
|
+
// `harness` selects the POOL: omp's RPC child (`omp --mode rpc-ui`) or an ACP
|
|
27
|
+
// agent's own process. Before this, only the RPC pool existed, so a pending chat
|
|
28
|
+
// on any ACP harness paid the full agent boot on its first prompt.
|
|
13
29
|
export async function action({ request }: ActionFunctionArgs) {
|
|
14
30
|
try {
|
|
15
31
|
const body = await request.json().catch(() => null);
|
|
@@ -19,8 +35,33 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
19
35
|
}
|
|
20
36
|
// Trust a client-supplied mode only when valid; else use the persisted pick.
|
|
21
37
|
const accessMode = isApprovalMode(body?.accessMode) ? body.accessMode : await loadPersistedAccessMode();
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
const harness: HarnessId = harnessDescriptor(typeof body?.harness === 'string' ? body.harness : null)
|
|
39
|
+
? body.harness as HarnessId
|
|
40
|
+
: 'omp-rpc';
|
|
41
|
+
// MOCK mode runs no agent BY DESIGN: spawning one here would either fail on
|
|
42
|
+
// every pending chat or start a real agent for a demo shell.
|
|
43
|
+
if (isMockMode()) return json({ success: true, harness, isMock: true });
|
|
44
|
+
|
|
45
|
+
if (harness !== 'omp-rpc' && !harnessDescriptor(harness)?.builtIn) {
|
|
46
|
+
// A harness whose binary is not installed has nothing to warm, and its
|
|
47
|
+
// spawn would fail on every key press of the pending chat. The picker
|
|
48
|
+
// already paints it as blocked; this keeps the pool from trying.
|
|
49
|
+
const config = await loadHarnessConfig(harness);
|
|
50
|
+
if (!commandAvailable(harness, config)) return json({ success: true, harness, unavailable: true });
|
|
51
|
+
// The ACP picks are config writes at claim time, so the entries carry no
|
|
52
|
+
// selection to match: every warm agent for this harness+cwd can serve it.
|
|
53
|
+
prewarmAcpSession(harness, cwd);
|
|
54
|
+
return json({ success: true, harness });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The omp child reads its selection from the START-TIME environment, so the
|
|
58
|
+
// prewarm carries the pending chat's Plan/Goal pick: a child warmed without
|
|
59
|
+
// it can never serve that chat and would be killed at the send.
|
|
60
|
+
const modeEnv = body?.modes !== undefined
|
|
61
|
+
? kabmoModeEnv(parseModeSelection(asRecord(body.modes)))
|
|
62
|
+
: undefined;
|
|
63
|
+
prewarmRpcSession(cwd, accessMode, modeEnv);
|
|
64
|
+
return json({ success: true, harness: 'omp-rpc' });
|
|
24
65
|
} catch (error) {
|
|
25
66
|
return rpcErrorResponse(error);
|
|
26
67
|
}
|
|
@@ -12,6 +12,7 @@ import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
|
|
|
12
12
|
import { checkWriteConflict, parseBaseMtime, stableMtime } from '@/server/lib/fs/write-conflict';
|
|
13
13
|
import { transferRefusal } from '@/shared/lib/fs/clipboard';
|
|
14
14
|
import { toDiskText } from '@/shared/lib/code/line-endings';
|
|
15
|
+
import { contentHash } from '@/shared/lib/fs/content-hash';
|
|
15
16
|
|
|
16
17
|
/** The two shapes a transfer action answers with, ready for `json`. */
|
|
17
18
|
function transferResponse(outcome: { path?: string; error?: string; status?: number }) {
|
|
@@ -128,7 +129,14 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
128
129
|
await fs.promises.mkdir(path.dirname(fullPath), { recursive: true });
|
|
129
130
|
await Bun.write(fullPath, content);
|
|
130
131
|
const written = await Bun.file(fullPath).stat().catch(() => null);
|
|
131
|
-
|
|
132
|
+
// The hash of the bytes just written travels back so the buffer adopts it as
|
|
133
|
+
// its own fingerprint. Without it the auto-refresh watcher would read the
|
|
134
|
+
// save as an EXTERNAL change and re-read the file the user just wrote.
|
|
135
|
+
return json({
|
|
136
|
+
success: true,
|
|
137
|
+
mtimeMs: written ? stableMtime(written.mtimeMs) : null,
|
|
138
|
+
hash: await contentHash(content),
|
|
139
|
+
});
|
|
132
140
|
} else if (actionType === 'saveAs') {
|
|
133
141
|
// Write the buffer to a NEW path. The destination is `path` (a directory) plus
|
|
134
142
|
// `name` (ONE segment), both resolved against this route's own scope — a
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's disk-digest probe.
|
|
8
|
+
*
|
|
9
|
+
* The rules that matter are the ones an mtime cannot express: a file rewritten
|
|
10
|
+
* with the SAME bytes answers the same hash (so a `touch` or a no-op formatter
|
|
11
|
+
* never replaces a buffer), a file whose bytes changed answers a different one,
|
|
12
|
+
* and a path outside the root allow-list is refused rather than answered.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import { fileDigest } from '@/server/routes/fs/digest';
|
|
19
|
+
import { contentHash } from '@/shared/lib/fs/content-hash';
|
|
20
|
+
|
|
21
|
+
const PROBE = path.join(process.cwd(), 'tmp-digest-probe.txt');
|
|
22
|
+
const NESTED = path.join(process.cwd(), 'tmp-digest-repo');
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
fs.rmSync(PROBE, { recursive: true, force: true });
|
|
26
|
+
fs.rmSync(NESTED, { recursive: true, force: true });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
async function digest(filePath: string, root: string = process.cwd(), repo?: string) {
|
|
30
|
+
const url = new URL('http://localhost/api/fs/digest');
|
|
31
|
+
url.searchParams.set('path', filePath);
|
|
32
|
+
url.searchParams.set('root', root);
|
|
33
|
+
if (repo) url.searchParams.set('repo', repo);
|
|
34
|
+
const res = await fileDigest({ request: new Request(url) } as never);
|
|
35
|
+
return {
|
|
36
|
+
status: res.status,
|
|
37
|
+
body: (await res.json()) as { exists?: boolean; mtimeMs?: number | null; hash?: string | null; error?: string },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('fs digest', () => {
|
|
42
|
+
test('a file answers the hash of its content', async () => {
|
|
43
|
+
fs.writeFileSync(PROBE, 'const a = 1;\n');
|
|
44
|
+
const { status, body } = await digest('tmp-digest-probe.txt');
|
|
45
|
+
|
|
46
|
+
expect(status).toBe(200);
|
|
47
|
+
expect(body.exists).toBe(true);
|
|
48
|
+
expect(body.hash).toBe(await contentHash('const a = 1;\n'));
|
|
49
|
+
expect(typeof body.mtimeMs).toBe('number');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('a file rewritten with the SAME bytes keeps its hash, however far the mtime moved', async () => {
|
|
53
|
+
fs.writeFileSync(PROBE, 'same bytes\n');
|
|
54
|
+
const first = await digest('tmp-digest-probe.txt');
|
|
55
|
+
|
|
56
|
+
// A `touch`, a formatter that changed nothing, a checkout of the revision
|
|
57
|
+
// already open: the clock moves, the bytes do not.
|
|
58
|
+
const later = new Date(Date.now() + 5_000);
|
|
59
|
+
fs.utimesSync(PROBE, later, later);
|
|
60
|
+
const second = await digest('tmp-digest-probe.txt');
|
|
61
|
+
|
|
62
|
+
expect(second.body.hash).toBe(first.body.hash);
|
|
63
|
+
expect(second.body.mtimeMs).not.toBe(first.body.mtimeMs);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('changed bytes answer a different hash', async () => {
|
|
67
|
+
fs.writeFileSync(PROBE, 'one\n');
|
|
68
|
+
const first = await digest('tmp-digest-probe.txt');
|
|
69
|
+
fs.writeFileSync(PROBE, 'two, and longer\n');
|
|
70
|
+
const second = await digest('tmp-digest-probe.txt');
|
|
71
|
+
|
|
72
|
+
expect(second.body.hash).not.toBe(first.body.hash);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('a missing file is not a digest', async () => {
|
|
76
|
+
const { status, body } = await digest('tmp-digest-probe.txt');
|
|
77
|
+
expect(status).toBe(200);
|
|
78
|
+
expect(body.exists).toBe(false);
|
|
79
|
+
expect(body.hash).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('a directory standing in the file’s place is not the file', async () => {
|
|
83
|
+
fs.mkdirSync(PROBE, { recursive: true });
|
|
84
|
+
const { body } = await digest('tmp-digest-probe.txt');
|
|
85
|
+
expect(body.exists).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a path outside the root allow-list is refused', async () => {
|
|
89
|
+
const { status, body } = await digest('../../etc/passwd');
|
|
90
|
+
expect(status).toBe(403);
|
|
91
|
+
expect(body.error).toBe('Invalid path');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('the scope travels with the probe, so a nested repo is read from its own tree', async () => {
|
|
95
|
+
fs.mkdirSync(NESTED, { recursive: true });
|
|
96
|
+
fs.writeFileSync(path.join(NESTED, 'a.txt'), 'nested\n');
|
|
97
|
+
const { body } = await digest('a.txt', process.cwd(), 'tmp-digest-repo');
|
|
98
|
+
expect(body.hash).toBe(await contentHash('nested\n'));
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GET /api/fs/digest?path=<rel>&root=<abs>&repo=<rel> — the content fingerprint
|
|
8
|
+
* of a file inside the panel's scope.
|
|
9
|
+
*
|
|
10
|
+
* The editor polls this while a tab is open so a file changed from OUTSIDE the
|
|
11
|
+
* console (an agent's tool call, `git checkout`, another editor) reaches the
|
|
12
|
+
* buffer without the user reloading anything. The question is deliberately not
|
|
13
|
+
* "did the mtime move": a checkout or a formatter rewrites a file with bytes
|
|
14
|
+
* the buffer may already hold, and reloading over that would drop a caret and a
|
|
15
|
+
* scroll position for no change at all. The answer is the hash of the content,
|
|
16
|
+
* so the caller replaces its buffer only when the bytes really differ.
|
|
17
|
+
*
|
|
18
|
+
* Scope resolution is identical to `/api/fs/exists` and `/api/fs/read` (same
|
|
19
|
+
* root allow-list, same `resolveWithinRoot` containment), so a path that reads
|
|
20
|
+
* as text is a path whose digest can be asked about.
|
|
21
|
+
*
|
|
22
|
+
* The hash is CACHED per path against the raw mtime and size, because a 3s poll
|
|
23
|
+
* of a 30 MB file would otherwise re-read and re-hash it forever. The cache's
|
|
24
|
+
* blind spot is the one the save path already documents: a write that leaves
|
|
25
|
+
* both the size and the millisecond-identical mtime unchanged is not seen until
|
|
26
|
+
* something else moves. `touch`ing a file invalidates the entry and re-reads —
|
|
27
|
+
* the answer is then the same hash, which is exactly what "the bytes did not
|
|
28
|
+
* change" means.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { json, type LoaderFunctionArgs } from '@/server/lib/remix-compat';
|
|
32
|
+
import { isMockMode } from '@/server/mock.server';
|
|
33
|
+
import { getDefaultFsRoot, resolveRoot, resolveWithinRoot } from '@/server/lib/fs/root';
|
|
34
|
+
import { stableMtime } from '@/server/lib/fs/write-conflict';
|
|
35
|
+
import { contentHash } from '@/shared/lib/fs/content-hash';
|
|
36
|
+
import { EDITOR_MAX_FILE_BYTES } from '@/shared/lib/fs/file-kind';
|
|
37
|
+
|
|
38
|
+
interface CachedDigest {
|
|
39
|
+
/** The RAW stat mtime the hash was built from; never the rounded value. */
|
|
40
|
+
mtimeMs: number;
|
|
41
|
+
size: number;
|
|
42
|
+
hash: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** One entry per open tab is the normal size; the cap only bounds a leak. */
|
|
46
|
+
const CACHE_LIMIT = 64;
|
|
47
|
+
const HASH_CACHE = new Map<string, CachedDigest>();
|
|
48
|
+
|
|
49
|
+
function cacheDigest(fullPath: string, digest: CachedDigest): void {
|
|
50
|
+
HASH_CACHE.delete(fullPath);
|
|
51
|
+
HASH_CACHE.set(fullPath, digest);
|
|
52
|
+
while (HASH_CACHE.size > CACHE_LIMIT) {
|
|
53
|
+
const oldest = HASH_CACHE.keys().next().value;
|
|
54
|
+
if (oldest === undefined) break;
|
|
55
|
+
HASH_CACHE.delete(oldest);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function fileDigest({ request }: LoaderFunctionArgs) {
|
|
60
|
+
const url = new URL(request.url);
|
|
61
|
+
const filePath = url.searchParams.get('path');
|
|
62
|
+
if (!filePath) {
|
|
63
|
+
return json({ error: 'Missing path' }, { status: 400 });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let baseDir = await resolveRoot(url.searchParams.get('root'), await getDefaultFsRoot(isMockMode()));
|
|
67
|
+
const repo = url.searchParams.get('repo');
|
|
68
|
+
if (repo && repo !== '.') {
|
|
69
|
+
const repoDir = resolveWithinRoot(baseDir, repo);
|
|
70
|
+
if (repoDir) baseDir = repoDir;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const fullPath = resolveWithinRoot(baseDir, filePath.replace(/^\/+/, ''));
|
|
74
|
+
if (!fullPath) {
|
|
75
|
+
return json({ error: 'Invalid path' }, { status: 403 });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// A directory standing where the file was is "gone" for the same reason the
|
|
79
|
+
// existence probe answers that way: the file the tab names is not there.
|
|
80
|
+
const stat = await Bun.file(fullPath).stat().catch(() => null);
|
|
81
|
+
if (!stat || stat.isDirectory()) {
|
|
82
|
+
return json({ exists: false, mtimeMs: null, hash: null });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// A file past the editor's ceiling was never openable, and hashing it would
|
|
86
|
+
// cost the read this route exists to avoid. `null` tells the caller it has no
|
|
87
|
+
// fingerprint to compare against.
|
|
88
|
+
if (stat.size > EDITOR_MAX_FILE_BYTES) {
|
|
89
|
+
return json({ exists: true, mtimeMs: stableMtime(stat.mtimeMs), hash: null });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const cached = HASH_CACHE.get(fullPath);
|
|
93
|
+
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
94
|
+
return json({ exists: true, mtimeMs: stableMtime(stat.mtimeMs), hash: cached.hash });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const hash = await contentHash(await Bun.file(fullPath).text());
|
|
99
|
+
cacheDigest(fullPath, { mtimeMs: stat.mtimeMs, size: stat.size, hash });
|
|
100
|
+
return json({ exists: true, mtimeMs: stableMtime(stat.mtimeMs), hash });
|
|
101
|
+
} catch {
|
|
102
|
+
// An unreadable file has no verdict — the caller must not treat a failed
|
|
103
|
+
// probe as "the disk changed".
|
|
104
|
+
return json({ exists: true, mtimeMs: stableMtime(stat.mtimeMs), hash: null });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -2,6 +2,7 @@ import { bindingsFor, type HandlerBinding } from '@/server/lib/route-adapter';
|
|
|
2
2
|
import { browseDirectories, listDirectory, listFiles, readFile, readReferencedFile } from '@/server/routes/fs/read';
|
|
3
3
|
import { resolveFileScope } from '@/server/routes/fs/scope';
|
|
4
4
|
import { fileExists } from '@/server/routes/fs/exists';
|
|
5
|
+
import { fileDigest } from '@/server/routes/fs/digest';
|
|
5
6
|
import { serveRawFile } from '@/server/routes/fs/raw';
|
|
6
7
|
import * as fsAction from '@/server/routes/fs/action';
|
|
7
8
|
import * as fsGit from '@/server/routes/fs/git';
|
|
@@ -18,6 +19,7 @@ export const fsBindings: HandlerBinding[] = [
|
|
|
18
19
|
...bindingsFor(fsSearch, '/api/fs/search'),
|
|
19
20
|
...bindingsFor(fsValidate, '/api/fs/validate'),
|
|
20
21
|
{ method: 'GET', path: '/api/fs/browse', handler: browseDirectories },
|
|
22
|
+
{ method: 'GET', path: '/api/fs/digest', handler: fileDigest },
|
|
21
23
|
{ method: 'GET', path: '/api/fs/dir', handler: listDirectory },
|
|
22
24
|
{ method: 'GET', path: '/api/fs/exists', handler: fileExists },
|
|
23
25
|
{ method: 'GET', path: '/api/fs/list', handler: listFiles },
|
|
@@ -7,6 +7,7 @@ import { json, type LoaderFunctionArgs } from '@/server/lib/remix-compat';
|
|
|
7
7
|
import { listDirectoryEntries } from '@/server/lib/fs/listing';
|
|
8
8
|
import { errorResponse } from '@/server/lib/route-adapter';
|
|
9
9
|
import { stableMtime } from '@/server/lib/fs/write-conflict';
|
|
10
|
+
import { contentHash } from '@/shared/lib/fs/content-hash';
|
|
10
11
|
import { homedir } from 'os';
|
|
11
12
|
import { dirname, isAbsolute, join, resolve } from 'path';
|
|
12
13
|
import fs from 'fs';
|
|
@@ -283,7 +284,11 @@ export async function readFile({ request }: LoaderFunctionArgs) {
|
|
|
283
284
|
// `baseMtime`, and the server refuses a write whose base is no longer what is
|
|
284
285
|
// on disk. A buffer with no base (a handle-backed file, an older client) still
|
|
285
286
|
// writes unconditionally — see `save-file.ts`.
|
|
286
|
-
|
|
287
|
+
//
|
|
288
|
+
// The content hash travels too, and it is the one the editor's auto-refresh
|
|
289
|
+
// compares against (`/api/fs/digest`): a file rewritten with the SAME bytes
|
|
290
|
+
// must not replace the buffer, and only a byte-level fingerprint can say so.
|
|
291
|
+
return json({ content, mtimeMs: stableMtime(stat.mtimeMs), hash: await contentHash(content) });
|
|
287
292
|
} catch (error) {
|
|
288
293
|
return errorResponse(error);
|
|
289
294
|
}
|