@kabmo-labs/kabmo 0.24.0 → 0.26.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 +585 -512
- package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/index.tsx +59 -2
- package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
- package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
- package/src/client/components/common/session-branch/index.tsx +169 -0
- package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
- package/src/client/components/common/session-branch/style.ts +29 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
- package/src/client/components/common/session-row/index.tsx +28 -3
- package/src/client/components/common/session-row/session-row.test.tsx +11 -0
- package/src/client/components/common/session-state-provider/index.tsx +1 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
- package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
- package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +1 -1
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +31 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
- package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
- package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
- package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
- package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
- package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/omp/run-switch.ts +1 -1
- package/src/client/hooks/chat/omp/session-list.tsx +4 -0
- package/src/client/hooks/chat/subagents/roster.ts +122 -0
- package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
- package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
- package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
- package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
- package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
- package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
- package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
- package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
- package/src/client/hooks/chat/timeline/modes.ts +42 -29
- package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
- package/src/client/hooks/chat/timeline/send.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.ts +48 -133
- package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
- package/src/client/hooks/models/use-harness-update.test.ts +286 -0
- package/src/client/hooks/models/use-harness-update.ts +250 -0
- package/src/client/hooks/ui/input-required-alert.ts +12 -5
- package/src/client/hooks/ui/notifications.ts +45 -0
- package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/native/open-session.ts +33 -0
- package/src/client/lib/notifications/os.test.ts +125 -0
- package/src/client/lib/notifications/os.ts +130 -0
- package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
- package/src/client/lib/router/open-session.test.ts +75 -0
- package/src/client/lib/router/open-session.ts +34 -0
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/lib/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/client/tailwind.css +17 -11
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +5 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/calls.ts +15 -1
- package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
- package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
- package/src/server/lib/harness/acp/client-fs.ts +131 -0
- package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
- package/src/server/lib/harness/acp/client-initialize.ts +84 -0
- package/src/server/lib/harness/acp/client.ts +33 -23
- package/src/server/lib/harness/acp/commands.test.ts +5 -5
- package/src/server/lib/harness/acp/commands.ts +14 -2
- package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
- package/src/server/lib/harness/acp/frames.ts +71 -158
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.test.ts +40 -0
- package/src/server/lib/harness/acp/mapper.ts +12 -0
- package/src/server/lib/harness/acp/permissions.ts +6 -0
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
- package/src/server/lib/harness/acp/session-handshake.ts +110 -7
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +41 -2
- package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
- package/src/server/lib/harness/acp/session-permissions.ts +36 -0
- package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
- package/src/server/lib/harness/acp/session-requests.ts +89 -0
- package/src/server/lib/harness/acp/session-turns.ts +28 -8
- package/src/server/lib/harness/acp/session-usage.ts +4 -0
- package/src/server/lib/harness/acp/session-web-state.ts +30 -2
- package/src/server/lib/harness/acp/session.test-util.ts +42 -2
- package/src/server/lib/harness/acp/session.ts +115 -115
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +183 -0
- package/src/server/lib/harness/acp/turn.ts +102 -10
- package/src/server/lib/harness/acp/v2.test.ts +144 -0
- package/src/server/lib/harness/acp/v2.ts +220 -0
- package/src/server/lib/harness/acp/verbs.ts +58 -8
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +24 -10
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +151 -0
- package/src/server/lib/harness/update-job-store.ts +115 -0
- package/src/server/lib/harness/update-job.server.ts +94 -0
- package/src/server/lib/harness/update-queue.server.ts +292 -0
- package/src/server/lib/harness/update-queue.test.ts +265 -0
- package/src/server/lib/harness/update-spawn.server.ts +96 -0
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +202 -0
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +28 -0
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
- package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
- package/src/server/lib/omp/session/delete.server.ts +5 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +277 -0
- package/src/server/lib/sessions/fork.server.ts +329 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +237 -0
- package/src/server/lib/sessions/spawn.server.ts +335 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +12 -5
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +4 -0
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/update-status.ts +32 -0
- package/src/server/routes/harness/update.test.ts +156 -0
- package/src/server/routes/harness/update.ts +64 -147
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +89 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +23 -0
- package/src/server/routes/sessions/spawn.ts +137 -0
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/omp/agent-events.ts +11 -0
- package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/provider-facts.test.ts +27 -0
- package/src/shared/lib/harness/providers.ts +35 -1
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +80 -0
- package/src/shared/lib/harness/update-plan.test.ts +21 -6
- package/src/shared/lib/harness/update-plan.ts +12 -4
- package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
- package/src/shared/lib/notifications/outcomes.test.ts +96 -0
- package/src/shared/lib/notifications/outcomes.ts +64 -0
- package/src/shared/lib/notifications/settings.test.ts +49 -0
- package/src/shared/lib/notifications/settings.ts +34 -0
- package/src/shared/lib/omp/session/default-title.ts +5 -4
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
- package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
- package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/settings/defaults.ts +3 -0
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/theme.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +89 -0
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +8 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/harness-table.test-util.ts +31 -1
- package/dist/client/static/js/index-z3w7n85q.css +0 -1
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Updating ONE harness — and refusing where Kabmo must not act.
|
|
7
|
+
* Updating ONE harness — as a BACKGROUND job, and refusing where Kabmo must not act.
|
|
8
8
|
*
|
|
9
9
|
* Three mechanisms, and the refusal is as much of the feature as the button:
|
|
10
10
|
*
|
|
@@ -21,103 +21,65 @@
|
|
|
21
21
|
* **An adapter is TWO installs.** `claude` is `@agentclientprotocol/claude-agent-acp`
|
|
22
22
|
* (the number the probe reports) on top of the `claude` CLI, and they move
|
|
23
23
|
* independently — measured here: adapter 0.100.0 under CLI 2.1.318. So one press
|
|
24
|
-
* moves EVERY part that is behind and none that is current
|
|
24
|
+
* moves EVERY part that is behind and none that is current. The decision itself
|
|
25
|
+
* is pure (`planHarnessUpdate`); this route only resolves the facts it needs and
|
|
26
|
+
* hands the argv to the worker.
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* that
|
|
33
|
-
*
|
|
34
|
-
* Every run is a POST that answers plain JSON, not an SSE stream: an npm install
|
|
35
|
-
* of one package, or one `upgrade` subcommand, is seconds rather than the minutes
|
|
36
|
-
* `omp update` and the Kabmo self-update take. If one of these grows long enough
|
|
37
|
-
* to need streaming, it should reuse `updates/apply.ts` rather than grow a second
|
|
38
|
-
* progress protocol here.
|
|
28
|
+
* **The route does not run the installs.** They used to run here, inside the POST:
|
|
29
|
+
* the request stayed open for minutes, a reload forgot the run, and a five-minute
|
|
30
|
+
* child timeout could kill `npm install -g` halfway through writing a package
|
|
31
|
+
* tree — the corruption this design removes. The run is a detached worker
|
|
32
|
+
* (`update-worker.ts`) that writes progress to `harness-update.json`; this route
|
|
33
|
+
* answers `202` in milliseconds and `GET /api/harness/update/status` reports the
|
|
34
|
+
* outcome. A second press while one runs is a `409`, read from that same record,
|
|
35
|
+
* so a reloaded page cannot start a competing install.
|
|
39
36
|
*/
|
|
40
37
|
|
|
41
|
-
import { json } from '@/server/lib/remix-compat';
|
|
38
|
+
import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
|
|
42
39
|
import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
43
40
|
import { methodNotAllowed } from '@/server/lib/route-adapter';
|
|
44
41
|
import { HARNESS_IDS, harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
45
|
-
import { harnessUpdateFacts, latestSourceFor
|
|
46
|
-
import {
|
|
47
|
-
import {
|
|
48
|
-
import { planHarnessUpdate,
|
|
49
|
-
import { loadHarnessConfig, saveHarnessConfig } from '@/server/lib/harness/config.server';
|
|
42
|
+
import { harnessUpdateFacts, latestSourceFor } from '@/shared/lib/harness/updates';
|
|
43
|
+
import { loadProbes } from '@/server/lib/harness/probe-cache.server';
|
|
44
|
+
import { harnessVersionState, type HarnessVersionState } from '@/server/lib/harness/update-state.server';
|
|
45
|
+
import { planHarnessUpdate, type HarnessUpdateStep } from '@/shared/lib/harness/update-plan';
|
|
50
46
|
import { resolveOmpBin } from '@/server/lib/omp/core/cli';
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
import {
|
|
48
|
+
startHarnessUpdateJob,
|
|
49
|
+
unfinishedUpdateJob,
|
|
50
|
+
} from '@/server/lib/harness/update-job.server';
|
|
51
|
+
import { jobQueued } from '@/shared/lib/harness/update-job';
|
|
55
52
|
|
|
56
|
-
/** The
|
|
53
|
+
/** The answer to a press that has nothing to move, still plain JSON. */
|
|
57
54
|
interface HarnessUpdateOutcome {
|
|
58
55
|
success: boolean;
|
|
59
56
|
id: string;
|
|
60
57
|
message: string;
|
|
61
|
-
/** The commands that ran, so the reader can repeat them themselves. */
|
|
62
|
-
command?: string;
|
|
63
|
-
/** The tail of their output — what actually failed, when it failed. */
|
|
64
|
-
output?: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Run a command, capturing its combined output for the report. */
|
|
68
|
-
async function run(command: string[], cwd?: string): Promise<{ code: number | null; output: string }> {
|
|
69
|
-
const proc = Bun.spawn({
|
|
70
|
-
cmd: command,
|
|
71
|
-
stdin: 'ignore',
|
|
72
|
-
stdout: 'pipe',
|
|
73
|
-
stderr: 'pipe',
|
|
74
|
-
timeout: UPDATE_TIMEOUT_MS,
|
|
75
|
-
env: { ...Bun.env, PAGER: 'cat', FORCE_COLOR: '0' },
|
|
76
|
-
...(cwd ? { cwd } : {}),
|
|
77
|
-
});
|
|
78
|
-
const [stdout, stderr] = await Promise.all([
|
|
79
|
-
new Response(proc.stdout).text(),
|
|
80
|
-
new Response(proc.stderr).text(),
|
|
81
|
-
]);
|
|
82
|
-
const code = await proc.exited;
|
|
83
|
-
return { code, output: [stdout, stderr].filter(Boolean).join('\n').trim() };
|
|
84
58
|
}
|
|
85
59
|
|
|
86
|
-
/**
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
60
|
+
/** A readable description of the numbers currently on disk, for "already current". */
|
|
61
|
+
function currentParts(state: HarnessVersionState, cliName: string | undefined): string {
|
|
62
|
+
return [
|
|
63
|
+
state.agent.version && `adapter ${state.agent.version}`,
|
|
64
|
+
state.cli?.version && `${cliName ?? 'CLI'} ${state.cli.version}`,
|
|
65
|
+
].filter(Boolean).join(', ');
|
|
90
66
|
}
|
|
91
67
|
|
|
92
68
|
/**
|
|
93
|
-
*
|
|
69
|
+
* The argv for a `self` harness: the vendor's own updater, resolved by name.
|
|
94
70
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* consults, so the press reported success while every new session still started
|
|
99
|
-
* the old pinned build — measured on `claude` (global 0.101.0, launch requested
|
|
100
|
-
* 0.100.0) and reproduced for codex/pi/zcode by construction.
|
|
101
|
-
*
|
|
102
|
-
* Once the install succeeded AND the binary is on PATH, the harness's launch
|
|
103
|
-
* line is pointed at it. A user's own configured command is never replaced: it
|
|
104
|
-
* is an explicit choice about how this machine launches the harness.
|
|
71
|
+
* `omp` has its own resolver (`KABMO_OMP_BIN`, then PATH): a custom install is
|
|
72
|
+
* launchable and already reported as installed, so checking PATH alone refused
|
|
73
|
+
* the one updater the harness actually has.
|
|
105
74
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
steps,
|
|
115
|
-
config.command,
|
|
116
|
-
facts.agentBin ? Boolean(Bun.which(facts.agentBin)) : false,
|
|
117
|
-
);
|
|
118
|
-
if (!bin) return null;
|
|
119
|
-
await saveHarnessConfig(harness, { ...config, command: bin });
|
|
120
|
-
return bin;
|
|
75
|
+
function selfSteps(harness: HarnessId, label: string, command: string): { steps: HarnessUpdateStep[]; error?: string } {
|
|
76
|
+
const argv = command.split(' ');
|
|
77
|
+
const binary = argv[0];
|
|
78
|
+
const resolved = harness === 'omp-acp' ? resolveOmpBin() : binary ? Bun.which(binary) : null;
|
|
79
|
+
if (!binary || !resolved) {
|
|
80
|
+
return { steps: [], error: `${label}: \`${binary || 'the updater'}\` is not on PATH` };
|
|
81
|
+
}
|
|
82
|
+
return { steps: [{ part: label, command, argv: [resolved, ...argv.slice(1)] }] };
|
|
121
83
|
}
|
|
122
84
|
|
|
123
85
|
export async function action({ request, params }: ActionFunctionArgs) {
|
|
@@ -150,26 +112,27 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
150
112
|
}, { status: 400 });
|
|
151
113
|
}
|
|
152
114
|
|
|
115
|
+
// Read BEFORE planning: the answer to a press must not depend on what this
|
|
116
|
+
// press would have planned, and planning reads the npm registry.
|
|
117
|
+
//
|
|
118
|
+
// Only THIS harness's own unfinished record refuses the press. A different
|
|
119
|
+
// harness is ACCEPTED and queued: one install runs at a time (they share the
|
|
120
|
+
// global npm prefix), but "update these two" is one decision the user gets to
|
|
121
|
+
// make, and the queue is what makes the second press work instead of 409.
|
|
122
|
+
const running = await unfinishedUpdateJob(harness);
|
|
123
|
+
if (running) {
|
|
124
|
+
return json({
|
|
125
|
+
error: `${running.label} update is already ${jobQueued(running) ? 'queued' : 'running'} — it continues in the background`,
|
|
126
|
+
job: running,
|
|
127
|
+
}, { status: 409, headers: NO_STORE_HEADERS });
|
|
128
|
+
}
|
|
129
|
+
|
|
153
130
|
if (facts.kind === 'self') {
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const resolved = harness === 'omp-acp' ? resolveOmpBin() : binary ? Bun.which(binary) : null;
|
|
160
|
-
if (!binary || !resolved) {
|
|
161
|
-
return json({ error: `${label}: \`${binary ?? 'the updater'}\` is not on PATH` }, { status: 400 });
|
|
162
|
-
}
|
|
163
|
-
const result = await run([resolved, ...command.slice(1)]);
|
|
164
|
-
const ok = result.code === 0;
|
|
165
|
-
const outcome: HarnessUpdateOutcome = {
|
|
166
|
-
success: ok,
|
|
167
|
-
id: harness,
|
|
168
|
-
message: ok ? `${label} updated` : `${label} update failed (exit ${result.code ?? 'killed'})`,
|
|
169
|
-
command: facts.command,
|
|
170
|
-
...(result.output ? { output: tail(result.output) } : {}),
|
|
171
|
-
};
|
|
172
|
-
return json(outcome);
|
|
131
|
+
if (!facts.command) return json({ error: `${label} names no updater command` }, { status: 400 });
|
|
132
|
+
const { steps, error } = selfSteps(harness, label, facts.command);
|
|
133
|
+
if (error) return json({ error }, { status: 400 });
|
|
134
|
+
const job = await startHarnessUpdateJob(harness, label, steps);
|
|
135
|
+
return json({ started: true, queued: jobQueued(job), job }, { status: 202, headers: NO_STORE_HEADERS });
|
|
173
136
|
}
|
|
174
137
|
|
|
175
138
|
// `npm`: install the package at the version the registry reports NOW, so the
|
|
@@ -191,17 +154,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
191
154
|
return json({ error: `${label} is not installed on this machine` }, { status: 400 });
|
|
192
155
|
}
|
|
193
156
|
|
|
194
|
-
// `harnessVersionState` was read with `force`, so both latest numbers are what
|
|
195
|
-
// the registry serves NOW rather than what the dialog remembered.
|
|
196
|
-
|
|
197
157
|
const steps = planHarnessUpdate(label, facts, state, agentVersion);
|
|
198
158
|
|
|
199
159
|
if (steps.length === 0) {
|
|
200
160
|
// Nothing to install. Reported as a success the UI can state plainly, rather
|
|
201
161
|
// than running an install that would change nothing.
|
|
202
|
-
const current =
|
|
203
|
-
.filter(Boolean)
|
|
204
|
-
.join(', ');
|
|
162
|
+
const current = currentParts(state, facts.cli?.name);
|
|
205
163
|
return json({
|
|
206
164
|
success: true,
|
|
207
165
|
id: harness,
|
|
@@ -213,47 +171,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
213
171
|
} satisfies HarnessUpdateOutcome);
|
|
214
172
|
}
|
|
215
173
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
let ok = true;
|
|
219
|
-
for (const step of steps) {
|
|
220
|
-
const result = await run(step.argv);
|
|
221
|
-
if (result.output) outputs.push(result.output);
|
|
222
|
-
if (result.code !== 0) {
|
|
223
|
-
ok = false;
|
|
224
|
-
// The first failure ends the run: installing the CLI on top of a failed
|
|
225
|
-
// adapter install would report two outcomes for one broken state.
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (ok) {
|
|
231
|
-
// The cached probe describes the binary that WAS installed. Keeping it would
|
|
232
|
-
// report the old version until the TTL (30 min) or a manual re-probe — and
|
|
233
|
-
// measured after a real `npm install`: the row still read 0.100.0 while npm
|
|
234
|
-
// had 0.101.0 on disk, because the running adapter was the previous process.
|
|
235
|
-
await forgetProbe(harness);
|
|
236
|
-
// The CLI's `--version` read has the same problem: it is cached for ten
|
|
237
|
-
// minutes, so the row would keep claiming the old number after it moved.
|
|
238
|
-
if (facts.cli) forgetCliVersion(facts.cli.bin);
|
|
239
|
-
}
|
|
240
|
-
// Only after the install succeeded: the launch line is repointed at the binary
|
|
241
|
-
// that install wrote, or the next session would start the pinned one forever.
|
|
242
|
-
const repointed = ok ? await pointAtInstalledAdapter(harness, facts, steps) : null;
|
|
243
|
-
|
|
244
|
-
const moved = steps.map((step) => step.part);
|
|
245
|
-
return json({
|
|
246
|
-
success: ok,
|
|
247
|
-
id: harness,
|
|
248
|
-
message: ok
|
|
249
|
-
? `${label} updated (${moved.join(' + ')})${repointed ? ` — launches now run \`${repointed}\`` : ''} — check its status to read the new version`
|
|
250
|
-
: `${label} update failed`,
|
|
251
|
-
command: steps.map((step) => step.command).join(' && '),
|
|
252
|
-
...(outputs.length > 0 ? { output: tail(outputs.join('\n')) } : {}),
|
|
253
|
-
} satisfies HarnessUpdateOutcome);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** GET answers the same rows the versions route does, so a mistake reads plainly. */
|
|
257
|
-
export async function loader() {
|
|
258
|
-
return json({ harnesses: await harnessVersionRows() });
|
|
174
|
+
const job = await startHarnessUpdateJob(harness, label, steps);
|
|
175
|
+
return json({ started: true, queued: jobQueued(job), job }, { status: 202, headers: NO_STORE_HEADERS });
|
|
259
176
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GET /api/sessions/:sessionId/answer — the last assistant text a turn closed.
|
|
8
|
+
*
|
|
9
|
+
* ACP has no transcript for `/api/chat/:id` to read after the process dies, so
|
|
10
|
+
* `kabmo session output` needs this row. A null answer is a real state (the
|
|
11
|
+
* session has not answered yet), not an error.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { json } from '@/server/lib/remix-compat';
|
|
15
|
+
import type { LoaderFunctionArgs } from '@/server/lib/remix-compat';
|
|
16
|
+
import { methodNotAllowed } from '@/server/lib/route-adapter';
|
|
17
|
+
import { loadSessionAnswer } from '@/server/lib/sessions/answers.server';
|
|
18
|
+
|
|
19
|
+
export async function getSessionAnswer({ request, params }: LoaderFunctionArgs) {
|
|
20
|
+
if (request.method !== 'GET') return methodNotAllowed({ request, params });
|
|
21
|
+
const sessionId = params.sessionId;
|
|
22
|
+
if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
|
|
23
|
+
return json({ sessionId, answer: await loadSessionAnswer(sessionId) });
|
|
24
|
+
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { json } from '@/server/lib/remix-compat';
|
|
21
21
|
import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
22
22
|
import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
|
|
23
|
-
import {
|
|
23
|
+
import { removeSessionTree } from '@/server/lib/omp/session/delete-flow.server';
|
|
24
24
|
|
|
25
25
|
/** One request cannot carry an unbounded selection. */
|
|
26
26
|
const MAX_BATCH = 500;
|
|
@@ -44,6 +44,7 @@ export async function batchDeleteSessions({ request }: ActionFunctionArgs) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const removed: string[] = [];
|
|
47
|
+
const removedDependents: string[] = [];
|
|
47
48
|
const refused: { id: string; error: string; code?: string }[] = [];
|
|
48
49
|
|
|
49
50
|
// Sequential, deliberately: every removal may have to destroy an omp child
|
|
@@ -51,10 +52,15 @@ export async function batchDeleteSessions({ request }: ActionFunctionArgs) {
|
|
|
51
52
|
// transcript writer per session at once for no gain — the work is dominated
|
|
52
53
|
// by process teardown, not by the filesystem.
|
|
53
54
|
for (const id of ids) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const tree = await removeSessionTree(id);
|
|
56
|
+
const result = tree.result;
|
|
57
|
+
if (result.ok) {
|
|
58
|
+
removed.push(id);
|
|
59
|
+
removedDependents.push(...tree.removedDependents);
|
|
60
|
+
} else {
|
|
61
|
+
refused.push({ id, error: result.error ?? 'Could not delete the session.', code: result.code });
|
|
62
|
+
}
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
return json({ success: refused.length === 0, removed, refused });
|
|
65
|
+
return json({ success: refused.length === 0, removed, removedDependents, refused });
|
|
60
66
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The JSON body readers shared by the session routes that accept a composer's
|
|
8
|
+
* picks: `/api/sessions/spawn` and `/api/sessions/:id/fork`.
|
|
9
|
+
*
|
|
10
|
+
* One copy, because the two endpoints promise the same shape (`harness`-style
|
|
11
|
+
* explicit picks, a model pair, images) and a second parser would drift into
|
|
12
|
+
* accepting something the other refuses.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { AgentImage } from '@/shared/types/omp/agent';
|
|
16
|
+
import type { SelectedModel } from '@/shared/types/models';
|
|
17
|
+
|
|
18
|
+
/** A trimmed non-empty string, or null — the routes' "absent" spelling. */
|
|
19
|
+
export function readString(value: unknown): string | null {
|
|
20
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A `{provider, modelId}` pair, or null when either half is missing. */
|
|
24
|
+
export function readModel(value: unknown): SelectedModel | null {
|
|
25
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
26
|
+
const record = value as Record<string, unknown>;
|
|
27
|
+
return typeof record.provider === 'string' && typeof record.modelId === 'string'
|
|
28
|
+
? { provider: record.provider, modelId: record.modelId }
|
|
29
|
+
: null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Image parts of a prompt, dropping entries without bytes or a MIME type. */
|
|
33
|
+
export function readImages(value: unknown): AgentImage[] | null {
|
|
34
|
+
if (!Array.isArray(value)) return null;
|
|
35
|
+
const images = value.flatMap((entry): AgentImage[] => {
|
|
36
|
+
if (!entry || typeof entry !== 'object') return [];
|
|
37
|
+
const record = entry as Record<string, unknown>;
|
|
38
|
+
return typeof record.data === 'string' && typeof record.mimeType === 'string'
|
|
39
|
+
? [{ type: 'image', data: record.data, mimeType: record.mimeType }]
|
|
40
|
+
: [];
|
|
41
|
+
});
|
|
42
|
+
return images.length ? images : null;
|
|
43
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { json } from '@/server/lib/remix-compat';
|
|
18
18
|
import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
19
19
|
import { methodNotAllowed } from '@/server/lib/route-adapter';
|
|
20
|
-
import {
|
|
20
|
+
import { removeSessionTree } from '@/server/lib/omp/session/delete-flow.server';
|
|
21
21
|
|
|
22
22
|
export async function deleteSession({ request, params }: ActionFunctionArgs) {
|
|
23
23
|
if (request.method !== 'DELETE') {
|
|
@@ -27,7 +27,8 @@ export async function deleteSession({ request, params }: ActionFunctionArgs) {
|
|
|
27
27
|
const sessionId = params.sessionId;
|
|
28
28
|
if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const tree = await removeSessionTree(sessionId);
|
|
31
|
+
const result = tree.result;
|
|
31
32
|
if (!result.ok) {
|
|
32
33
|
return json(
|
|
33
34
|
{ error: result.error, code: result.code },
|
|
@@ -38,6 +39,7 @@ export async function deleteSession({ request, params }: ActionFunctionArgs) {
|
|
|
38
39
|
return json({
|
|
39
40
|
success: true,
|
|
40
41
|
sessionId,
|
|
42
|
+
removedDependents: tree.removedDependents,
|
|
41
43
|
fileRemoved: result.fileRemoved,
|
|
42
44
|
artifactsRemoved: result.artifactsRemoved,
|
|
43
45
|
btwTopicsRemoved: result.btwTopicsRemoved,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* POST /api/sessions/:sessionId/fork — branch a session at an anchor.
|
|
8
|
+
*
|
|
9
|
+
* Mounted under the same `:sessionId` position as the folder loader, so the
|
|
10
|
+
* parameter keeps that name; the suffix is what makes the route distinct.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { json } from '@/server/lib/remix-compat';
|
|
14
|
+
import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
15
|
+
import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
|
|
16
|
+
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
17
|
+
import { readImages, readModel, readString } from '@/server/routes/sessions/body-readers';
|
|
18
|
+
import { isApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
19
|
+
import { isMockMode } from '@/server/mock.server';
|
|
20
|
+
import {
|
|
21
|
+
SessionForkError,
|
|
22
|
+
forkSession,
|
|
23
|
+
} from '@/server/lib/sessions/fork.server';
|
|
24
|
+
|
|
25
|
+
interface ForkBody {
|
|
26
|
+
anchorEntryId?: unknown;
|
|
27
|
+
prompt?: unknown;
|
|
28
|
+
images?: unknown;
|
|
29
|
+
model?: unknown;
|
|
30
|
+
thinkingLevel?: unknown;
|
|
31
|
+
accessMode?: unknown;
|
|
32
|
+
title?: unknown;
|
|
33
|
+
cwd?: unknown;
|
|
34
|
+
visibility?: unknown;
|
|
35
|
+
lifecycleOwnerSessionId?: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function forkSessionRoute({ request, params }: ActionFunctionArgs) {
|
|
39
|
+
if (request.method !== 'POST') return methodNotAllowed({ request, params });
|
|
40
|
+
const sourceSessionId = params.sessionId;
|
|
41
|
+
if (!sourceSessionId) return json({ error: 'Missing session id' }, { status: 400 });
|
|
42
|
+
|
|
43
|
+
const parsed = await parseJsonBody<ForkBody>(request);
|
|
44
|
+
if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
|
|
45
|
+
// MOCK mode has no transcript to branch. The client answers with the
|
|
46
|
+
// simulated stream on this CODE, as it does for a new chat.
|
|
47
|
+
if (isMockMode()) {
|
|
48
|
+
return json({ error: 'Mock mode runs no agent process', code: 'mock_mode' }, { status: 400 });
|
|
49
|
+
}
|
|
50
|
+
const visibility = parsed.body.visibility;
|
|
51
|
+
if (visibility !== undefined && visibility !== 'visible' && visibility !== 'hidden') {
|
|
52
|
+
return json({ error: 'visibility must be "visible" or "hidden"' }, { status: 400 });
|
|
53
|
+
}
|
|
54
|
+
if (parsed.body.accessMode !== undefined && !isApprovalMode(parsed.body.accessMode)) {
|
|
55
|
+
return json({ error: 'accessMode is not a valid approval mode' }, { status: 400 });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const result = await forkSession({
|
|
60
|
+
sourceSessionId,
|
|
61
|
+
anchorEntryId: readString(parsed.body.anchorEntryId),
|
|
62
|
+
prompt: readString(parsed.body.prompt),
|
|
63
|
+
images: readImages(parsed.body.images),
|
|
64
|
+
model: readModel(parsed.body.model),
|
|
65
|
+
thinkingLevel: readString(parsed.body.thinkingLevel),
|
|
66
|
+
accessMode: isApprovalMode(parsed.body.accessMode) ? parsed.body.accessMode : null,
|
|
67
|
+
title: readString(parsed.body.title),
|
|
68
|
+
cwd: readString(parsed.body.cwd),
|
|
69
|
+
...(visibility ? { visibility: visibility as 'visible' | 'hidden' } : {}),
|
|
70
|
+
lifecycleOwnerSessionId: readString(parsed.body.lifecycleOwnerSessionId),
|
|
71
|
+
});
|
|
72
|
+
emitRealtimeSignal('sidebar-structure');
|
|
73
|
+
return json(result, { status: 201 });
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof SessionForkError) {
|
|
76
|
+
const status =
|
|
77
|
+
error.code === 'source_not_found'
|
|
78
|
+
? 404
|
|
79
|
+
: error.code === 'source_archived' || error.code === 'fork_requires_checkpoint'
|
|
80
|
+
? 409
|
|
81
|
+
: 400;
|
|
82
|
+
return json({ error: error.message, code: error.code }, { status });
|
|
83
|
+
}
|
|
84
|
+
return json(
|
|
85
|
+
{ error: error instanceof Error ? error.message : 'Could not fork the session' },
|
|
86
|
+
{ status: 500 },
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -16,9 +16,16 @@ import { cancelSubagent, steerSubagent } from '@/server/routes/sessions/subagent
|
|
|
16
16
|
import { deleteSession } from '@/server/routes/sessions/delete';
|
|
17
17
|
import { batchDeleteSessions } from '@/server/routes/sessions/batch-delete';
|
|
18
18
|
import { batchArchiveSessions } from '@/server/routes/sessions/batch-archive';
|
|
19
|
+
import { spawnSession } from '@/server/routes/sessions/spawn';
|
|
20
|
+
import { getSessionRelations, updateSessionParent } from '@/server/routes/sessions/relations';
|
|
21
|
+
import { forkSessionRoute } from '@/server/routes/sessions/fork';
|
|
22
|
+
import { getSessionAnswer } from '@/server/routes/sessions/answer';
|
|
19
23
|
|
|
20
24
|
export const sessionsBindings: HandlerBinding[] = [
|
|
21
25
|
...bindingsFor(sessionsList, '/api/sessions/list'),
|
|
26
|
+
// Static before the `:sessionId` routes, for the same reason batch-delete is:
|
|
27
|
+
// a parameter route winning the match answers 405.
|
|
28
|
+
{ method: 'POST', path: '/api/sessions/spawn', handler: spawnSession },
|
|
22
29
|
// Registered BEFORE the `:sessionId` routes: the segment is static, and the
|
|
23
30
|
// batch route is POST while `:sessionId` answers DELETE, so an id route
|
|
24
31
|
// winning the match would turn every batch into a 405.
|
|
@@ -27,6 +34,13 @@ export const sessionsBindings: HandlerBinding[] = [
|
|
|
27
34
|
// `:sessionId` routes for the same reason as batch-delete.
|
|
28
35
|
{ method: 'POST', path: '/api/sessions/batch-archive', handler: batchArchiveSessions },
|
|
29
36
|
...bindingsFor(sessionsFolder, '/api/sessions/:sessionId'),
|
|
37
|
+
// The tree around one session. Both are static suffixes under the same
|
|
38
|
+
// `:sessionId` position, whose name must stay `sessionId` — Elysia requires
|
|
39
|
+
// one parameter name per position across every `/api/sessions/*` route.
|
|
40
|
+
{ method: 'GET', path: '/api/sessions/:sessionId/relations', handler: getSessionRelations },
|
|
41
|
+
{ method: 'POST', path: '/api/sessions/:sessionId/parent', handler: updateSessionParent },
|
|
42
|
+
{ method: 'POST', path: '/api/sessions/:sessionId/fork', handler: forkSessionRoute },
|
|
43
|
+
{ method: 'GET', path: '/api/sessions/:sessionId/answer', handler: getSessionAnswer },
|
|
30
44
|
// DELETE-only on the same path the folder loader answers GET on: mounting it
|
|
31
45
|
// through `actionBindings` would register a 405 GET fallback that Elysia
|
|
32
46
|
// applies after the loader, replacing the workspace listing with it.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The tree around one session: its parent, children, forks and cleanup owner.
|
|
8
|
+
*
|
|
9
|
+
* A fork is deliberately NOT in `children`: it is a source-derived session and
|
|
10
|
+
* stays silent, so listing it under the parent edge would promise a
|
|
11
|
+
* notification that never comes. The info panel draws it from `forks`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { json } from '@/server/lib/remix-compat';
|
|
15
|
+
import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
|
|
16
|
+
import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
|
|
17
|
+
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
18
|
+
import { SessionRelationError } from '@/server/lib/sessions/relation-types';
|
|
19
|
+
import {
|
|
20
|
+
getSessionRelation,
|
|
21
|
+
listChildRelations,
|
|
22
|
+
listForkRelations,
|
|
23
|
+
listOwnedRelations,
|
|
24
|
+
setSessionParent,
|
|
25
|
+
} from '@/server/lib/sessions/relations.server';
|
|
26
|
+
|
|
27
|
+
export async function getSessionRelations({ request, params }: LoaderFunctionArgs) {
|
|
28
|
+
if (request.method !== 'GET') return methodNotAllowed({ request, params });
|
|
29
|
+
const sessionId = params.sessionId;
|
|
30
|
+
if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
|
|
31
|
+
|
|
32
|
+
const [relation, children, forks, owned] = await Promise.all([
|
|
33
|
+
getSessionRelation(sessionId),
|
|
34
|
+
listChildRelations(sessionId),
|
|
35
|
+
listForkRelations(sessionId),
|
|
36
|
+
listOwnedRelations(sessionId),
|
|
37
|
+
]);
|
|
38
|
+
return json({
|
|
39
|
+
sessionId,
|
|
40
|
+
parent: relation?.parentSessionId ? { sessionId: relation.parentSessionId } : null,
|
|
41
|
+
parentNotifications: relation?.parentNotifications ?? 'auto',
|
|
42
|
+
visibility: relation?.visibility ?? 'visible',
|
|
43
|
+
origin: relation?.originKind
|
|
44
|
+
? { kind: relation.originKind, sourceSessionId: relation.sourceSessionId }
|
|
45
|
+
: null,
|
|
46
|
+
children: children.map((row) => ({
|
|
47
|
+
sessionId: row.sessionId,
|
|
48
|
+
visibility: row.visibility,
|
|
49
|
+
parentNotifications: row.parentNotifications,
|
|
50
|
+
depth: row.depth,
|
|
51
|
+
})),
|
|
52
|
+
forks: forks.map((row) => ({ sessionId: row.sessionId, visibility: row.visibility })),
|
|
53
|
+
lifecycleOwner: relation?.lifecycleOwnerSessionId
|
|
54
|
+
? { sessionId: relation.lifecycleOwnerSessionId }
|
|
55
|
+
: null,
|
|
56
|
+
owned: owned.map((row) => ({ sessionId: row.sessionId })),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function updateSessionParent({ request, params }: ActionFunctionArgs) {
|
|
61
|
+
if (request.method !== 'POST') return methodNotAllowed({ request, params });
|
|
62
|
+
const sessionId = params.sessionId;
|
|
63
|
+
if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
|
|
64
|
+
|
|
65
|
+
const parsed = await parseJsonBody<{ parentSessionId?: unknown }>(request);
|
|
66
|
+
if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
|
|
67
|
+
const raw = parsed.body.parentSessionId;
|
|
68
|
+
if (raw !== null && typeof raw !== 'string') {
|
|
69
|
+
return json({ error: 'parentSessionId must be a string or null' }, { status: 400 });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const relation = await setSessionParent(sessionId, raw);
|
|
74
|
+
emitRealtimeSignal('sidebar-structure');
|
|
75
|
+
return json({ ok: true, parentSessionId: relation.parentSessionId, depth: relation.depth });
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error instanceof SessionRelationError) {
|
|
78
|
+
return json({ error: error.message, code: error.code }, { status: 409 });
|
|
79
|
+
}
|
|
80
|
+
return json(
|
|
81
|
+
{ error: error instanceof Error ? error.message : 'Could not reparent the session' },
|
|
82
|
+
{ status: 500 },
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -206,8 +206,7 @@ describe('getSessionModes', () => {
|
|
|
206
206
|
claimHarness(wrapper as never, 'claude');
|
|
207
207
|
try {
|
|
208
208
|
const res = (await getSessionModes(loaderArgs(acpId)) as unknown as Response);
|
|
209
|
-
expect(res.
|
|
210
|
-
expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false } });
|
|
209
|
+
expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false, mode: { currentValue: 'plan' } } });
|
|
211
210
|
} finally {
|
|
212
211
|
globalThis.__ompSessions.delete(acpId);
|
|
213
212
|
}
|