@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
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Starting harness updates, and following every background run they became.
|
|
8
|
+
*
|
|
9
|
+
* The POST used to hold the request open for the whole install; now it answers
|
|
10
|
+
* `202` and each run continues in a detached worker. So the dialog's job has two
|
|
11
|
+
* halves: start it, then poll `GET /api/harness/update/status` until the record
|
|
12
|
+
* says it finished — and, on open, ADOPT whatever is already in flight. That
|
|
13
|
+
* second half is what makes the update really background: closing About, or
|
|
14
|
+
* reloading the page, does not lose the button's state, and a reopened card
|
|
15
|
+
* shows the spinner for the run that is still installing.
|
|
16
|
+
*
|
|
17
|
+
* **ONE loop for EVERY run, because two presses are two records.** A second
|
|
18
|
+
* harness is accepted while the first installs: its record carries `queuedAt`
|
|
19
|
+
* and the server's queue starts it when the run ahead settles, so the card has
|
|
20
|
+
* to follow a run it did not start AND one that has not started yet. A finished
|
|
21
|
+
* run is reported once per harness, and a record that was already finished when
|
|
22
|
+
* the card opened is HISTORY — a reopened dialog must not re-toast last week's
|
|
23
|
+
* install.
|
|
24
|
+
*
|
|
25
|
+
* The rows are re-read once a run settles (`invalidateHarnessVersions`): the
|
|
26
|
+
* update forgot the cached probe, so the next read is the first honest one.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
30
|
+
import { invalidateHarnessVersions } from '@/client/hooks/models/use-harness-versions';
|
|
31
|
+
import {
|
|
32
|
+
isHarnessUpdateJob,
|
|
33
|
+
jobMoving,
|
|
34
|
+
jobUnfinished,
|
|
35
|
+
updateJobsFrom,
|
|
36
|
+
} from '@/shared/lib/harness/update-job';
|
|
37
|
+
import type { HarnessUpdateJob } from '@/shared/types/harness-update';
|
|
38
|
+
|
|
39
|
+
/** One poll per second: the worker flushes at 400ms, and this is a dialog. */
|
|
40
|
+
export const HARNESS_UPDATE_POLL_MS = 1_000;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Stop polling after this long and hand the control back.
|
|
44
|
+
*
|
|
45
|
+
* The install itself is bounded per step by the worker; this only stops an open
|
|
46
|
+
* dialog from asking forever if the server stopped answering. The run is not
|
|
47
|
+
* cancelled — closing the dialog never cancels anything, and a queued run is
|
|
48
|
+
* started by the server's own ticker.
|
|
49
|
+
*/
|
|
50
|
+
const MAX_FOLLOW_MS = 45 * 60_000;
|
|
51
|
+
|
|
52
|
+
/** How the hook behaves, for the two callers that need to differ from the
|
|
53
|
+
* default: the dialog passes its own open state, and a test its own cadence. */
|
|
54
|
+
export interface HarnessUpdateOptions {
|
|
55
|
+
/** The poll cadence. One second suits a dialog. */
|
|
56
|
+
pollMs?: number;
|
|
57
|
+
/** Is the surface that owns this hook on screen? While it is not, no status is
|
|
58
|
+
* read and no run is followed — a run already in flight is ADOPTED on the
|
|
59
|
+
* next open, which is what "background" means here. */
|
|
60
|
+
enabled?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface HarnessUpdateController {
|
|
64
|
+
/**
|
|
65
|
+
* The last known record per harness — waiting, installing, or the last run
|
|
66
|
+
* that finished.
|
|
67
|
+
*
|
|
68
|
+
* The rows render from this: `jobQueued`/`jobRunning`/`runningStepOf` answer
|
|
69
|
+
* what to draw, and the log dialog renders the record's own steps and output.
|
|
70
|
+
* A settled run is NOT cleared, because the interesting moment to read the log
|
|
71
|
+
* is often after it failed.
|
|
72
|
+
*/
|
|
73
|
+
jobs: HarnessUpdateJob[];
|
|
74
|
+
/** Start an update; resolves to a refusal, or null when the run was started
|
|
75
|
+
* (immediately or queued behind the one already installing). */
|
|
76
|
+
start: (id: string) => Promise<string | null>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type Settled = (message: string, ok: boolean) => void;
|
|
80
|
+
|
|
81
|
+
export function useHarnessUpdate(
|
|
82
|
+
onSettled: Settled,
|
|
83
|
+
{ pollMs = HARNESS_UPDATE_POLL_MS, enabled = true }: HarnessUpdateOptions = {},
|
|
84
|
+
): HarnessUpdateController {
|
|
85
|
+
const [jobs, setJobs] = useState<HarnessUpdateJob[]>([]);
|
|
86
|
+
const alive = useRef(true);
|
|
87
|
+
const polling = useRef(false);
|
|
88
|
+
// Which harnesses this card WATCHED install. A run it only saw as history is
|
|
89
|
+
// not one to toast about, and the same harness must not be reported twice.
|
|
90
|
+
const watched = useRef(new Set<string>());
|
|
91
|
+
const reported = useRef(new Set<string>());
|
|
92
|
+
// Runs whose post-install probe answer has already been reflected in the rows.
|
|
93
|
+
const probed = useRef(new Set<string>());
|
|
94
|
+
// The callback is read through a ref so an inline arrow from the caller does
|
|
95
|
+
// not restart the mount effect (and re-adopt the records) on every render.
|
|
96
|
+
const settled = useRef(onSettled);
|
|
97
|
+
settled.current = onSettled;
|
|
98
|
+
|
|
99
|
+
/** Fold one harness's record into the list, keeping the newer one. */
|
|
100
|
+
const merge = useCallback((incoming: HarnessUpdateJob | null) => {
|
|
101
|
+
if (!incoming) return;
|
|
102
|
+
setJobs((current) => {
|
|
103
|
+
const index = current.findIndex((job) => job.harness === incoming.harness);
|
|
104
|
+
if (index < 0) return [...current, incoming];
|
|
105
|
+
const next = current.slice();
|
|
106
|
+
next[index] = incoming;
|
|
107
|
+
return next;
|
|
108
|
+
});
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Report the runs that went from unfinished to finished, and re-read the rows
|
|
113
|
+
* once each run's post-install PROBE answers.
|
|
114
|
+
*
|
|
115
|
+
* The probe is what stops the row quoting the version the update replaced, and
|
|
116
|
+
* it lands AFTER the run settles — so the settle report and the version refresh
|
|
117
|
+
* are two separate moments, not one.
|
|
118
|
+
*/
|
|
119
|
+
const observe = useCallback((incoming: HarnessUpdateJob[]) => {
|
|
120
|
+
setJobs(incoming);
|
|
121
|
+
for (const job of incoming) {
|
|
122
|
+
if (jobUnfinished(job)) {
|
|
123
|
+
watched.current.add(job.harness);
|
|
124
|
+
reported.current.delete(job.harness);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (watched.current.has(job.harness) && !reported.current.has(job.harness)) {
|
|
128
|
+
reported.current.add(job.harness);
|
|
129
|
+
invalidateHarnessVersions();
|
|
130
|
+
settled.current(job.message ?? (job.ok ? 'Update finished' : 'Update failed'), Boolean(job.ok));
|
|
131
|
+
}
|
|
132
|
+
// A run whose probe settled: the numbers the row reads are now the new
|
|
133
|
+
// ones, so the cached rows must be dropped. `startedAt` identifies the run,
|
|
134
|
+
// because the next update replaces the record under the same harness.
|
|
135
|
+
if (job.probe === 'done') {
|
|
136
|
+
const key = `${job.harness}:${job.startedAt}`;
|
|
137
|
+
if (!probed.current.has(key)) {
|
|
138
|
+
probed.current.add(key);
|
|
139
|
+
invalidateHarnessVersions();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, []);
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Follow every unfinished record until they all settle.
|
|
147
|
+
*
|
|
148
|
+
* One loop, not one per harness: a queued run and an installing run are two
|
|
149
|
+
* rows of the same poll, and a loop per press would double the reads for no
|
|
150
|
+
* extra answer. `polling` keeps a second caller (the mount effect and a press
|
|
151
|
+
* landing together) from starting a second loop.
|
|
152
|
+
*/
|
|
153
|
+
const follow = useCallback(async (): Promise<void> => {
|
|
154
|
+
if (polling.current) return;
|
|
155
|
+
polling.current = true;
|
|
156
|
+
const startedAt = Date.now();
|
|
157
|
+
try {
|
|
158
|
+
while (alive.current) {
|
|
159
|
+
let next: HarnessUpdateJob[] | null = null;
|
|
160
|
+
try {
|
|
161
|
+
const response = await fetch('/api/harness/update/status', { cache: 'no-store' });
|
|
162
|
+
if (!response.ok) throw new Error(String(response.status));
|
|
163
|
+
next = updateJobsFrom(await response.json());
|
|
164
|
+
} catch {
|
|
165
|
+
// A transient failure is not the update failing: the records live on
|
|
166
|
+
// disk and the next poll reads them.
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!alive.current) return;
|
|
170
|
+
if (next) observe(next);
|
|
171
|
+
// Nothing left to watch — a queued run keeps this loop alive (the
|
|
172
|
+
// server starts it when the install ahead finishes), and so does a run
|
|
173
|
+
// whose post-install probe has not answered yet.
|
|
174
|
+
if (!next || !next.some(jobMoving)) return;
|
|
175
|
+
if (Date.now() - startedAt > MAX_FOLLOW_MS) return;
|
|
176
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
177
|
+
setTimeout(resolve, pollMs);
|
|
178
|
+
await promise;
|
|
179
|
+
}
|
|
180
|
+
} finally {
|
|
181
|
+
polling.current = false;
|
|
182
|
+
}
|
|
183
|
+
}, [observe, pollMs]);
|
|
184
|
+
|
|
185
|
+
// Adopt whatever is already going: another tab, a run accepted before a
|
|
186
|
+
// reload, or a queued one. A closed card has nothing to show and nothing to
|
|
187
|
+
// poll for; the workers and the queue keep going either way.
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (!enabled) {
|
|
190
|
+
alive.current = false;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
alive.current = true;
|
|
194
|
+
void follow();
|
|
195
|
+
return () => {
|
|
196
|
+
alive.current = false;
|
|
197
|
+
};
|
|
198
|
+
}, [follow, enabled]);
|
|
199
|
+
|
|
200
|
+
const start = useCallback(async (id: string): Promise<string | null> => {
|
|
201
|
+
let response: Response;
|
|
202
|
+
try {
|
|
203
|
+
response = await fetch('/api/harness/update', {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
headers: { 'Content-Type': 'application/json' },
|
|
206
|
+
body: JSON.stringify({ harness: id }),
|
|
207
|
+
});
|
|
208
|
+
} catch (cause) {
|
|
209
|
+
return cause instanceof Error ? cause.message : 'Update failed';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const payload = (await response.json().catch(() => ({}))) as {
|
|
213
|
+
error?: string;
|
|
214
|
+
message?: string;
|
|
215
|
+
success?: boolean;
|
|
216
|
+
started?: boolean;
|
|
217
|
+
queued?: boolean;
|
|
218
|
+
job?: unknown;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// The POST's own record is trusted only if it IS a record; a payload that
|
|
222
|
+
// fails the guard still means "started", just without a step to name.
|
|
223
|
+
const posted = isHarnessUpdateJob(payload.job) ? payload.job : null;
|
|
224
|
+
|
|
225
|
+
if (response.status === 202 && payload.started) {
|
|
226
|
+
// `started` covers both halves: installing now, or waiting its turn.
|
|
227
|
+
watched.current.add(id);
|
|
228
|
+
reported.current.delete(id);
|
|
229
|
+
merge(posted);
|
|
230
|
+
void follow();
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
// A refusal carries the record that caused it (`job`), so the reader can
|
|
235
|
+
// open ITS log instead of only being told to wait.
|
|
236
|
+
if (posted) merge(posted);
|
|
237
|
+
return payload.error ?? `Update failed (HTTP ${response.status})`;
|
|
238
|
+
}
|
|
239
|
+
if (payload.success) {
|
|
240
|
+
// Nothing to move: the row is already current, so there is no job to
|
|
241
|
+
// follow. Re-read it anyway — the previous run may have moved it.
|
|
242
|
+
invalidateHarnessVersions();
|
|
243
|
+
settled.current(payload.message ?? 'Update finished', true);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
return payload.error ?? 'Update failed';
|
|
247
|
+
}, [follow, merge]);
|
|
248
|
+
|
|
249
|
+
return { jobs, start };
|
|
250
|
+
}
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { useEffect, useRef } from 'preact/hooks';
|
|
18
|
-
import type { WorkspaceFolderData } from '@/shared/types';
|
|
18
|
+
import type { SessionItemData, WorkspaceFolderData } from '@/shared/types';
|
|
19
19
|
import { triggerInputRequiredSound } from '@/client/hooks/ui/notification-sound';
|
|
20
|
+
import { sendNotification } from '@/client/hooks/ui/notifications';
|
|
20
21
|
|
|
21
22
|
export function useInputRequiredAlert(folders: WorkspaceFolderData[]): void {
|
|
22
23
|
// Null until the first snapshot: a page load must not replay a cue for
|
|
@@ -24,19 +25,25 @@ export function useInputRequiredAlert(folders: WorkspaceFolderData[]): void {
|
|
|
24
25
|
const knownRef = useRef<Set<string> | null>(null);
|
|
25
26
|
|
|
26
27
|
useEffect(() => {
|
|
27
|
-
const waiting = new
|
|
28
|
+
const waiting = new Map<string, SessionItemData>();
|
|
28
29
|
for (const folder of folders) {
|
|
29
30
|
for (const session of folder.sessions ?? []) {
|
|
30
|
-
if (session.awaitingInput) waiting.
|
|
31
|
+
if (session.awaitingInput) waiting.set(String(session.id), session);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
const known = knownRef.current;
|
|
35
|
-
knownRef.current = waiting;
|
|
36
|
+
knownRef.current = new Set(waiting.keys());
|
|
36
37
|
if (!known) return;
|
|
37
|
-
for (const id of waiting) {
|
|
38
|
+
for (const [id, session] of waiting) {
|
|
38
39
|
if (known.has(id)) continue;
|
|
39
40
|
triggerInputRequiredSound();
|
|
41
|
+
sendNotification('ask', {
|
|
42
|
+
title: session.title?.trim() || 'Kabmo',
|
|
43
|
+
body: 'Waiting for your answer.',
|
|
44
|
+
tag: `ask:${id}`,
|
|
45
|
+
sessionId: id,
|
|
46
|
+
});
|
|
40
47
|
return;
|
|
41
48
|
}
|
|
42
49
|
}, [folders]);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one gate every system notification passes through.
|
|
8
|
+
*
|
|
9
|
+
* Two rules, and both are the feature rather than plumbing:
|
|
10
|
+
*
|
|
11
|
+
* - the event's own setting must be the literal `true` (they ship false);
|
|
12
|
+
* - the page must not be the window the user is looking at. The sidebar badge,
|
|
13
|
+
* the ask card and the inline error row already report these events on
|
|
14
|
+
* screen, so a banner over the app would only repeat what is visible.
|
|
15
|
+
*
|
|
16
|
+
* Text is clipped here because a failure reason can be a whole provider
|
|
17
|
+
* response; an OS notification is a headline, not a log.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { isNotificationEnabled, type NotificationEvent } from '@/shared/lib/notifications/settings';
|
|
21
|
+
import { showOsNotification, shouldShowSystemNotification } from '@/client/lib/notifications/os';
|
|
22
|
+
|
|
23
|
+
const TITLE_LIMIT = 120;
|
|
24
|
+
const BODY_LIMIT = 240;
|
|
25
|
+
|
|
26
|
+
function clip(text: string, limit: number): string {
|
|
27
|
+
const trimmed = text.trim();
|
|
28
|
+
if (trimmed.length <= limit) return trimmed;
|
|
29
|
+
return `${trimmed.slice(0, limit - 1).trimEnd()}…`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Send a system notification for `event`, unless the setting or focus says no. */
|
|
33
|
+
export function sendNotification(
|
|
34
|
+
event: NotificationEvent,
|
|
35
|
+
notification: { title: string; body: string; tag?: string; sessionId?: string },
|
|
36
|
+
): void {
|
|
37
|
+
if (!isNotificationEnabled(event)) return;
|
|
38
|
+
if (!shouldShowSystemNotification()) return;
|
|
39
|
+
void showOsNotification({
|
|
40
|
+
title: clip(notification.title, TITLE_LIMIT) || 'Kabmo',
|
|
41
|
+
body: clip(notification.body, BODY_LIMIT),
|
|
42
|
+
tag: notification.tag,
|
|
43
|
+
sessionId: notification.sessionId,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* App-wide "a run ended" cue.
|
|
8
|
+
*
|
|
9
|
+
* It reads the shared session list rather than the open timeline for the same
|
|
10
|
+
* reason `useInputRequiredAlert` does: the run that mattered is usually NOT the
|
|
11
|
+
* session on screen. The status topic is written by the server on every
|
|
12
|
+
* terminal settle, so this reaches a background session this tab never opened.
|
|
13
|
+
*
|
|
14
|
+
* Only a transition earns a banner — `stream` to `finish`, checked by
|
|
15
|
+
* `runOutcomeNotices` — so the badges already present at page load stay silent.
|
|
16
|
+
* A failed run is the same transition carrying `runFailure`, so finish and
|
|
17
|
+
* error cannot fire for one run.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
21
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
22
|
+
import {
|
|
23
|
+
runOutcomeNotices,
|
|
24
|
+
streamOutcomes,
|
|
25
|
+
type StreamOutcome,
|
|
26
|
+
} from '@/shared/lib/notifications/outcomes';
|
|
27
|
+
import { sendNotification } from '@/client/hooks/ui/notifications';
|
|
28
|
+
|
|
29
|
+
export function useRunOutcomeAlert(folders: WorkspaceFolderData[]): void {
|
|
30
|
+
// Null until the first snapshot: a page load must not announce runs that had
|
|
31
|
+
// already finished before it.
|
|
32
|
+
const knownRef = useRef<Map<string, StreamOutcome> | null>(null);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const previous = knownRef.current;
|
|
36
|
+
knownRef.current = streamOutcomes(folders);
|
|
37
|
+
if (!previous) return;
|
|
38
|
+
|
|
39
|
+
for (const notice of runOutcomeNotices(previous, folders)) {
|
|
40
|
+
sendNotification(notice.kind, {
|
|
41
|
+
title: notice.title,
|
|
42
|
+
body: notice.detail,
|
|
43
|
+
tag: `${notice.kind}:${notice.sessionId}`,
|
|
44
|
+
sessionId: notice.sessionId,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, [folders]);
|
|
48
|
+
}
|
|
@@ -4,27 +4,40 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Expanded-session
|
|
7
|
+
* Expanded-session branches, shared by the desktop and mobile session sidebars.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* phone
|
|
9
|
+
* One row has ONE branch — child sessions and its subagent roster — and one
|
|
10
|
+
* chevron opens it. Both sidebars must read and write ONE set, persisted in
|
|
11
|
+
* `app_settings.omp_sidebar_expanded_sessions`, or a branch expanded on the
|
|
12
|
+
* phone comes back collapsed on the desktop.
|
|
13
13
|
*
|
|
14
14
|
* The `?subagent=` deep link auto-expands its session row: a reload on a
|
|
15
|
-
* subagent transcript must leave the
|
|
15
|
+
* subagent transcript must leave the leaf that opened it visible.
|
|
16
|
+
*
|
|
17
|
+
* A pending CHILD (the row a "New child session" click creates) also opens its
|
|
18
|
+
* parent through `expandSessionBranch`, because the row would otherwise exist
|
|
19
|
+
* inside a collapsed branch and never be seen.
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
22
|
import { useCallback, useEffect, useState } from 'preact/hooks';
|
|
19
23
|
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
20
24
|
import { loadExpandedSessionIds, saveExpandedSessionIds } from '@/shared/lib/workspace/sidebar-expanded';
|
|
21
25
|
|
|
26
|
+
/** Fired by a pending child's creator so every sidebar opens its parent. */
|
|
27
|
+
const EXPAND_SESSION_EVENT = 'omp:expand-session';
|
|
28
|
+
|
|
22
29
|
export interface ExpandedSessionsHandle {
|
|
23
30
|
expandedSessionIds: Set<string>;
|
|
24
|
-
/** Collapse an expanded
|
|
31
|
+
/** Collapse an expanded branch, or expand a collapsed one. Persists it. */
|
|
25
32
|
toggleSession: (sessionId: string) => void;
|
|
26
33
|
}
|
|
27
34
|
|
|
35
|
+
/** Open one session's branch from outside the sidebar (a pending child). */
|
|
36
|
+
export function expandSessionBranch(sessionId: string): void {
|
|
37
|
+
if (typeof window === 'undefined' || !sessionId) return;
|
|
38
|
+
window.dispatchEvent(new CustomEvent(EXPAND_SESSION_EVENT, { detail: { sessionId } }));
|
|
39
|
+
}
|
|
40
|
+
|
|
28
41
|
export function useExpandedSessions(): ExpandedSessionsHandle {
|
|
29
42
|
const [searchParams] = useSearchParams();
|
|
30
43
|
const urlSubagentId = searchParams.get('subagent');
|
|
@@ -48,6 +61,22 @@ export function useExpandedSessions(): ExpandedSessionsHandle {
|
|
|
48
61
|
});
|
|
49
62
|
}, [urlSubagentId, urlSessionId]);
|
|
50
63
|
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const onExpand = (event: Event) => {
|
|
66
|
+
const id = (event as CustomEvent<{ sessionId?: string }>).detail?.sessionId;
|
|
67
|
+
if (!id) return;
|
|
68
|
+
setExpandedSessionIds(prev => {
|
|
69
|
+
if (prev.has(id)) return prev;
|
|
70
|
+
const next = new Set(prev);
|
|
71
|
+
next.add(id);
|
|
72
|
+
saveExpandedSessionIds(next);
|
|
73
|
+
return next;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
window.addEventListener(EXPAND_SESSION_EVENT, onExpand);
|
|
77
|
+
return () => window.removeEventListener(EXPAND_SESSION_EVENT, onExpand);
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
51
80
|
const toggleSession = useCallback((sessionId: string) => {
|
|
52
81
|
setExpandedSessionIds((prev) => {
|
|
53
82
|
const next = new Set(prev);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Live terminal session for the right panel: the socket, its status, and the
|
|
8
|
-
* attach/resize/input verbs the
|
|
8
|
+
* attach/resize/input verbs the terminal view drives.
|
|
9
9
|
*
|
|
10
10
|
* The terminal id is per Kabmo session and persisted, which is what makes the
|
|
11
11
|
* shell survive a page reload: the panel reattaches to the id it already owns
|
|
@@ -48,6 +48,12 @@ export interface UseTerminalResult {
|
|
|
48
48
|
input: (data: Uint8Array) => void;
|
|
49
49
|
/** Replace the shell with a fresh one. */
|
|
50
50
|
restart: () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Re-open the socket for the same terminal id. The server replays its
|
|
53
|
+
* retained scrollback, which is what lets a rebuilt renderer (a theme switch)
|
|
54
|
+
* regain its history without a new shell.
|
|
55
|
+
*/
|
|
56
|
+
reattach: () => void;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult {
|
|
@@ -57,6 +63,8 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
|
|
|
57
63
|
const [shell, setShell] = useState('');
|
|
58
64
|
const [exitCode, setExitCode] = useState<number | null>(null);
|
|
59
65
|
const [error, setError] = useState<string | null>(null);
|
|
66
|
+
/** Incremented by `reattach`; the socket effect owns the reconnect. */
|
|
67
|
+
const [generation, setGeneration] = useState(0);
|
|
60
68
|
|
|
61
69
|
const socketRef = useRef<TerminalSocket | null>(null);
|
|
62
70
|
// The grid the view reported, replayed on attach so a reconnect lands on the
|
|
@@ -133,7 +141,7 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
|
|
|
133
141
|
socket.release();
|
|
134
142
|
socketRef.current = null;
|
|
135
143
|
};
|
|
136
|
-
}, [ready, terminalId]);
|
|
144
|
+
}, [ready, terminalId, generation]);
|
|
137
145
|
|
|
138
146
|
const restart = useCallback(() => {
|
|
139
147
|
// Kill the old shell before minting a new id: leaving it to the idle
|
|
@@ -182,5 +190,11 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
|
|
|
182
190
|
socketRef.current?.input(data);
|
|
183
191
|
}, []);
|
|
184
192
|
|
|
185
|
-
|
|
193
|
+
const reattach = useCallback(() => {
|
|
194
|
+
// The effect's cleanup releases the old socket and a new one attaches with
|
|
195
|
+
// the remembered size, so the server replays the same terminal id.
|
|
196
|
+
setGeneration((value) => value + 1);
|
|
197
|
+
}, []);
|
|
198
|
+
|
|
199
|
+
return { status, shell, exitCode, error, attach, resize, input, restart, reattach };
|
|
186
200
|
}
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* bytes and is handed straight to `term.write(Uint8Array)`; the client never
|
|
14
14
|
* decodes UTF-8 itself, which is what keeps a character split across two PTY
|
|
15
15
|
* reads intact.
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* - **Non-UTF-8 payloads take the byte channel.** ghostty-web has no `onBinary`:
|
|
17
|
+
* it reports every keystroke and mouse report as one `onData` string, so
|
|
18
|
+
* `terminalInputFrame` splits the legacy X10 report back into bytes before the
|
|
19
|
+
* socket sees it. Encoding that payload as text would corrupt it.
|
|
19
20
|
* - **Reconnect, not re-create.** A dropped socket re-dials the same terminal
|
|
20
21
|
* id, so the shell and its scrollback survive a network blip or a page reload
|
|
21
22
|
* instead of a second shell appearing.
|
|
@@ -99,7 +100,11 @@ export function connectTerminal(terminalId: string, handlers: TerminalSocketHand
|
|
|
99
100
|
handleOutput(new Uint8Array(event.data));
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
+
// Anything that is not a binary frame is a control frame. The server
|
|
104
|
+
// sends PTY bytes as Buffer views, so `event.data` is an ArrayBuffer and
|
|
105
|
+
// this branch only ever sees JSON.
|
|
106
|
+
if (typeof event.data !== 'string') return;
|
|
107
|
+
const frame = decodeServerFrame(event.data);
|
|
103
108
|
if (frame) applyFrame(frame);
|
|
104
109
|
};
|
|
105
110
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `window.__kabmoOpenSession(sessionId)` — what a native shell calls when the
|
|
8
|
+
* user clicks a notification.
|
|
9
|
+
*
|
|
10
|
+
* A plain function, not a bridge command: the shell has nothing to ask and no
|
|
11
|
+
* answer to wait for, the page already owns the routing state, and the shells
|
|
12
|
+
* reach it with `evaluateJavascript` / `evaluateJavaScript` / `ExecuteScriptAsync`
|
|
13
|
+
* / `run_javascript`. Same indirection as `__kabmoBack` and `__kabmoResume`, and
|
|
14
|
+
* for the same reason: the shell may call it during hydration, so it must exist
|
|
15
|
+
* before the first render.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { openSessionInUrl } from '@/client/lib/router/open-session';
|
|
19
|
+
|
|
20
|
+
export const OPEN_SESSION_PROPERTY = '__kabmoOpenSession';
|
|
21
|
+
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
/** Select the session a notification was about. Returns false for a blank id. */
|
|
25
|
+
__kabmoOpenSession?: (sessionId: string) => boolean;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Install the dispatcher. Idempotent — a hot reload re-runs it. */
|
|
30
|
+
export function installOpenSessionDispatcher(): void {
|
|
31
|
+
if (typeof window === 'undefined') return;
|
|
32
|
+
window[OPEN_SESSION_PROPERTY] = (sessionId) => openSessionInUrl(String(sessionId ?? ''));
|
|
33
|
+
}
|