@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,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The one rule that decides whether an OS banner is worth sending. */
|
|
7
|
+
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
9
|
+
import { Window } from 'happy-dom';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
requestNotificationPermission,
|
|
13
|
+
shouldShowSystemNotification,
|
|
14
|
+
showOsNotification,
|
|
15
|
+
} from '@/client/lib/notifications/os';
|
|
16
|
+
|
|
17
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator'] as const;
|
|
18
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
19
|
+
let win: Window;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
win = new Window({ url: 'http://localhost' });
|
|
23
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
24
|
+
for (const key of DOM_GLOBALS) {
|
|
25
|
+
if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
|
|
26
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
32
|
+
for (const key of DOM_GLOBALS) target[key] = nativeGlobals[key];
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function setVisibility(value: 'visible' | 'hidden'): void {
|
|
36
|
+
Object.defineProperty(document, 'visibilityState', { configurable: true, value });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function setFocus(value: boolean): void {
|
|
40
|
+
Object.defineProperty(document, 'hasFocus', { configurable: true, value: () => value });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('shouldShowSystemNotification', () => {
|
|
44
|
+
test('a backgrounded tab is worth a banner', () => {
|
|
45
|
+
setVisibility('hidden');
|
|
46
|
+
setFocus(false);
|
|
47
|
+
expect(shouldShowSystemNotification()).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('a desktop window behind another app is worth a banner', () => {
|
|
51
|
+
setVisibility('visible');
|
|
52
|
+
setFocus(false);
|
|
53
|
+
expect(shouldShowSystemNotification()).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('the window the user is reading is not', () => {
|
|
57
|
+
setVisibility('visible');
|
|
58
|
+
setFocus(true);
|
|
59
|
+
expect(shouldShowSystemNotification()).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('a browser without the Notification API', () => {
|
|
64
|
+
test('refuses permission instead of throwing', async () => {
|
|
65
|
+
expect(await requestNotificationPermission()).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('drops the banner instead of throwing', async () => {
|
|
69
|
+
await expect(showOsNotification({ title: 'Kabmo', body: 'Done.' })).resolves.toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('inside a Kabmo shell', () => {
|
|
74
|
+
type Call = { method: string; params?: Record<string, unknown> };
|
|
75
|
+
|
|
76
|
+
function installShell(answer: (call: Call) => unknown): Call[] {
|
|
77
|
+
const calls: Call[] = [];
|
|
78
|
+
window.__kabmoCall = (method, params) => {
|
|
79
|
+
calls.push({ method, params });
|
|
80
|
+
return Promise.resolve(answer({ method, params }));
|
|
81
|
+
};
|
|
82
|
+
return calls;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
afterEach(() => {
|
|
86
|
+
delete window.__kabmoCall;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('permission and the banner use the shell, not the browser API', async () => {
|
|
90
|
+
const calls = installShell(({ method }) =>
|
|
91
|
+
method === 'notification_request' ? { granted: true } : null);
|
|
92
|
+
|
|
93
|
+
expect(await requestNotificationPermission()).toBe(true);
|
|
94
|
+
await showOsNotification({
|
|
95
|
+
title: 'Fix the build',
|
|
96
|
+
body: 'Waiting for you.',
|
|
97
|
+
tag: 'ask:s1',
|
|
98
|
+
sessionId: 's1',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(calls).toEqual([
|
|
102
|
+
{ method: 'notification_request', params: {} },
|
|
103
|
+
{
|
|
104
|
+
method: 'notification_show',
|
|
105
|
+
params: { title: 'Fix the build', body: 'Waiting for you.', tag: 'ask:s1', sessionId: 's1' },
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('an untagged notification does not send an empty tag', async () => {
|
|
111
|
+
const calls = installShell(() => null);
|
|
112
|
+
await showOsNotification({ title: 'Kabmo', body: 'Done.' });
|
|
113
|
+
expect(calls[0]).toEqual({
|
|
114
|
+
method: 'notification_show',
|
|
115
|
+
params: { title: 'Kabmo', body: 'Done.' },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('a refused command is reported as false, never as a grant', async () => {
|
|
120
|
+
window.__kabmoCall = () => Promise.reject(new Error('This shell does not support notification_request.'));
|
|
121
|
+
expect(await requestNotificationPermission()).toBe(false);
|
|
122
|
+
// The refusal must not escape as an unhandled rejection.
|
|
123
|
+
await expect(showOsNotification({ title: 'Kabmo', body: 'Done.' })).resolves.toBeUndefined();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One system notification, through whichever OS the page is running inside.
|
|
8
|
+
*
|
|
9
|
+
* Two transports, one shape:
|
|
10
|
+
*
|
|
11
|
+
* - **A Kabmo shell** (Android, iOS, macOS, Windows, Linux) answers
|
|
12
|
+
* `notification_show` over the same bridge every other shell command uses.
|
|
13
|
+
* The shell owns the platform API — a WebView's `Notification` constructor is
|
|
14
|
+
* unavailable or unanswered on both phones.
|
|
15
|
+
* - **A plain browser** uses the Web Notification API, which is what makes the
|
|
16
|
+
* feature work outside a shell (desktop Chrome, an installed PWA).
|
|
17
|
+
*
|
|
18
|
+
* Permission is requested only when the user turns a notification setting on
|
|
19
|
+
* (`requestNotificationPermission`), never at boot: the settings default to
|
|
20
|
+
* false, and a permission prompt nobody asked for is exactly what those
|
|
21
|
+
* defaults exist to avoid.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { callShell, hasShellBridge } from '@/client/lib/shell/transport';
|
|
25
|
+
import { openSessionInUrl } from '@/client/lib/router/open-session';
|
|
26
|
+
|
|
27
|
+
export interface OsNotification {
|
|
28
|
+
title: string;
|
|
29
|
+
body: string;
|
|
30
|
+
/** Replaces an earlier notification for the same thing (a session, a run). */
|
|
31
|
+
tag?: string;
|
|
32
|
+
/** The session a click opens, when the event is about one. */
|
|
33
|
+
sessionId?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The browser's constructor, absent on iOS WebViews and in tests. */
|
|
37
|
+
type NotificationConstructor = typeof Notification;
|
|
38
|
+
|
|
39
|
+
function browserNotification(): NotificationConstructor | null {
|
|
40
|
+
if (typeof window === 'undefined' || !('Notification' in window)) return null;
|
|
41
|
+
const ctor = window.Notification;
|
|
42
|
+
return typeof ctor === 'function' ? ctor : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Ask for notification permission, and report what the platform answered.
|
|
47
|
+
*
|
|
48
|
+
* The shell answers its own permission state; a browser answers its prompt.
|
|
49
|
+
* A refusal is a `false`, never an exception — the caller only needs to know
|
|
50
|
+
* whether notifications can work, not why the OS said no.
|
|
51
|
+
*/
|
|
52
|
+
export async function requestNotificationPermission(): Promise<boolean> {
|
|
53
|
+
if (typeof window === 'undefined') return false;
|
|
54
|
+
|
|
55
|
+
if (hasShellBridge()) {
|
|
56
|
+
try {
|
|
57
|
+
const answer = await callShell<{ granted?: boolean } | null>('notification_request');
|
|
58
|
+
return answer?.granted === true;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.warn('[notifications] the shell refused the permission request:', error);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const ctor = browserNotification();
|
|
66
|
+
if (!ctor) return false;
|
|
67
|
+
if (ctor.permission === 'granted') return true;
|
|
68
|
+
if (ctor.permission === 'denied') return false;
|
|
69
|
+
try {
|
|
70
|
+
return (await ctor.requestPermission()) === 'granted';
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Send one system notification, or drop it when the platform cannot. */
|
|
77
|
+
export async function showOsNotification(notification: OsNotification): Promise<void> {
|
|
78
|
+
if (typeof window === 'undefined') return;
|
|
79
|
+
|
|
80
|
+
if (hasShellBridge()) {
|
|
81
|
+
try {
|
|
82
|
+
await callShell('notification_show', {
|
|
83
|
+
title: notification.title,
|
|
84
|
+
body: notification.body,
|
|
85
|
+
...(notification.tag ? { tag: notification.tag } : {}),
|
|
86
|
+
...(notification.sessionId ? { sessionId: notification.sessionId } : {}),
|
|
87
|
+
});
|
|
88
|
+
} catch (error) {
|
|
89
|
+
// A refused notification is not a failed run: the in-app badge is still
|
|
90
|
+
// the record. Report it once instead of disturbing the user with a toast
|
|
91
|
+
// about the toast.
|
|
92
|
+
console.warn('[notifications] the shell could not show a notification:', error);
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const ctor = browserNotification();
|
|
98
|
+
if (!ctor || ctor.permission !== 'granted') return;
|
|
99
|
+
try {
|
|
100
|
+
const shown = new ctor(notification.title, {
|
|
101
|
+
body: notification.body,
|
|
102
|
+
...(notification.tag ? { tag: notification.tag } : {}),
|
|
103
|
+
});
|
|
104
|
+
// A browser notification has no shell to route a click, so the click opens
|
|
105
|
+
// the session here. `focus()` first: a tab that stays in the background
|
|
106
|
+
// would change its URL while the user is looking at another window.
|
|
107
|
+
shown.onclick = () => {
|
|
108
|
+
if (typeof window.focus === 'function') window.focus();
|
|
109
|
+
if (notification.sessionId) openSessionInUrl(notification.sessionId);
|
|
110
|
+
shown.close();
|
|
111
|
+
};
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.warn('[notifications] the browser could not show a notification:', error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Whether a system notification is worth sending right now.
|
|
119
|
+
*
|
|
120
|
+
* Only when Kabmo is NOT the window the user is looking at. The sidebar badge
|
|
121
|
+
* and the inline error card already say these things on screen; a banner over
|
|
122
|
+
* the app the user is reading is noise. `visibilityState` catches a backgrounded
|
|
123
|
+
* tab and a paused WebView (both phones), `hasFocus` catches a desktop window
|
|
124
|
+
* behind another application.
|
|
125
|
+
*/
|
|
126
|
+
export function shouldShowSystemNotification(): boolean {
|
|
127
|
+
if (typeof document === 'undefined') return false;
|
|
128
|
+
if (document.visibilityState === 'hidden') return true;
|
|
129
|
+
return !document.hasFocus();
|
|
130
|
+
}
|
|
@@ -26,6 +26,7 @@ import { realtimeClient } from '@/shared/lib/realtime/client';
|
|
|
26
26
|
import { TOPIC_SIDEBAR, TOPIC_SIDEBAR_STATUS } from '@/shared/lib/realtime/protocol';
|
|
27
27
|
import { pluginContext } from '@/client/lib/plugins/context';
|
|
28
28
|
import { publishClientSignal } from '@/client/lib/signals';
|
|
29
|
+
import { openSessionInUrl } from '@/client/lib/router/open-session';
|
|
29
30
|
import { startPendingSession } from '@/client/hooks/chat/omp/pending-sessions';
|
|
30
31
|
import type { SidebarPayload, SidebarStatusPayload } from '@/shared/types/realtime';
|
|
31
32
|
import type { WorkspaceFolderData } from '@/shared/types';
|
|
@@ -136,25 +137,6 @@ export function refreshSidebarThreads(): void {
|
|
|
136
137
|
realtimeClient.refresh(TOPIC_SIDEBAR_STATUS);
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
/**
|
|
140
|
-
* Select a session, as clicking its row does.
|
|
141
|
-
*
|
|
142
|
-
* The app's only routing state is `?sessionId=`, written through the same
|
|
143
|
-
* `pushState` the sidebar uses — a plugin that set the URL itself would bypass
|
|
144
|
-
* the module store every mounted component reads, and the sidebar would keep
|
|
145
|
-
* showing the previous selection.
|
|
146
|
-
*/
|
|
147
|
-
function openSession(sessionId: string): void {
|
|
148
|
-
const url = new URL(window.location.href);
|
|
149
|
-
url.searchParams.set('sessionId', sessionId);
|
|
150
|
-
window.history.pushState(null, '', url);
|
|
151
|
-
// `pushState` does not fire `popstate`, so the search-param store has to be
|
|
152
|
-
// told; otherwise only a reload would show the new selection. A plain Event
|
|
153
|
-
// is enough — the store re-reads `location.search`, which pushState already
|
|
154
|
-
// moved — and it avoids depending on a constructor some environments lack.
|
|
155
|
-
window.dispatchEvent(new Event('popstate'));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
140
|
/** POST one session mutation, answering whether the server accepted it. */
|
|
159
141
|
async function postSession(sessionId: string, suffix: string, body?: FormData): Promise<boolean> {
|
|
160
142
|
try {
|
|
@@ -171,7 +153,7 @@ async function postSession(sessionId: string, suffix: string, body?: FormData):
|
|
|
171
153
|
/** The session actions, as the kit reads them. */
|
|
172
154
|
export function sidebarActions(): SidebarThreadActions {
|
|
173
155
|
return {
|
|
174
|
-
open:
|
|
156
|
+
open: openSessionInUrl,
|
|
175
157
|
rename: async (sessionId, title) => {
|
|
176
158
|
const body = new FormData();
|
|
177
159
|
body.set('name', title);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one navigation a notification click performs.
|
|
8
|
+
*
|
|
9
|
+
* The app's routing state is the URL, so the cases here are the ways a click
|
|
10
|
+
* could land somewhere wrong: it must replace `sessionId`, keep the folder the
|
|
11
|
+
* user was in, drop a subagent view, and tell the search-param store — a
|
|
12
|
+
* `pushState` alone re-renders nothing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { Window } from 'happy-dom';
|
|
17
|
+
|
|
18
|
+
import { openSessionInUrl } from '@/client/lib/router/open-session';
|
|
19
|
+
import { installOpenSessionDispatcher } from '@/client/lib/native/open-session';
|
|
20
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
21
|
+
|
|
22
|
+
let win: Window;
|
|
23
|
+
|
|
24
|
+
beforeAll(() => {
|
|
25
|
+
win = new Window({ url: 'http://localhost/' });
|
|
26
|
+
installDomGlobals(win);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
window.history.replaceState(null, '', '/');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterAll(() => {
|
|
34
|
+
restoreDomGlobals();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function go(search: string): void {
|
|
38
|
+
window.history.replaceState(null, '', `/${search}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('openSessionInUrl', () => {
|
|
42
|
+
test('selects the session and keeps the folder', () => {
|
|
43
|
+
go('?folderId=3&sessionId=old&subagent=9');
|
|
44
|
+
expect(openSessionInUrl('new-session')).toBe(true);
|
|
45
|
+
const url = new URL(window.location.href);
|
|
46
|
+
expect(url.searchParams.get('sessionId')).toBe('new-session');
|
|
47
|
+
expect(url.searchParams.get('folderId')).toBe('3');
|
|
48
|
+
expect(url.searchParams.has('subagent')).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('tells the router the URL moved', () => {
|
|
52
|
+
go('?sessionId=old');
|
|
53
|
+
let events = 0;
|
|
54
|
+
const listener = () => { events += 1; };
|
|
55
|
+
window.addEventListener('popstate', listener);
|
|
56
|
+
openSessionInUrl('next');
|
|
57
|
+
window.removeEventListener('popstate', listener);
|
|
58
|
+
expect(events).toBe(1);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a blank id changes nothing', () => {
|
|
62
|
+
go('?sessionId=keep');
|
|
63
|
+
expect(openSessionInUrl(' ')).toBe(false);
|
|
64
|
+
expect(window.location.search).toBe('?sessionId=keep');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('window.__kabmoOpenSession', () => {
|
|
69
|
+
test('the installed dispatcher is the same navigation', () => {
|
|
70
|
+
installOpenSessionDispatcher();
|
|
71
|
+
go('?sessionId=old');
|
|
72
|
+
expect(window.__kabmoOpenSession?.('from-notification')).toBe(true);
|
|
73
|
+
expect(new URL(window.location.href).searchParams.get('sessionId')).toBe('from-notification');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Select one session, as clicking its row does.
|
|
8
|
+
*
|
|
9
|
+
* The app's only routing state is `?sessionId=`, written through the same
|
|
10
|
+
* `pushState` the sidebar uses. A caller that set the URL itself would bypass the
|
|
11
|
+
* search-param store every mounted component reads, and the sidebar would keep
|
|
12
|
+
* showing the previous selection — which is why this is one function rather than
|
|
13
|
+
* the same four lines at each call site.
|
|
14
|
+
*
|
|
15
|
+
* `subagent` is dropped: a notification is about a session, and landing inside a
|
|
16
|
+
* subagent view of a SESSION would hide the transcript the notification named.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export function openSessionInUrl(sessionId: string): boolean {
|
|
20
|
+
if (typeof window === 'undefined') return false;
|
|
21
|
+
const id = sessionId.trim();
|
|
22
|
+
if (!id) return false;
|
|
23
|
+
|
|
24
|
+
const url = new URL(window.location.href);
|
|
25
|
+
url.searchParams.set('sessionId', id);
|
|
26
|
+
url.searchParams.delete('subagent');
|
|
27
|
+
window.history.pushState(null, '', url);
|
|
28
|
+
// `pushState` does not fire `popstate`, so the search-param store has to be
|
|
29
|
+
// told; otherwise only a reload would show the new selection. A plain Event is
|
|
30
|
+
// enough — the store re-reads `location.search`, which pushState already moved
|
|
31
|
+
// — and it avoids depending on a constructor some environments lack.
|
|
32
|
+
window.dispatchEvent(new Event('popstate'));
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
import { buildSessionTree, descendantsOf } from '@/client/lib/session-tree';
|
|
8
|
+
import type { SessionItemData } from '@/shared/types';
|
|
9
|
+
|
|
10
|
+
function session(id: string, parentSessionId?: string): SessionItemData {
|
|
11
|
+
return {
|
|
12
|
+
id,
|
|
13
|
+
folder_id: 1,
|
|
14
|
+
title: id,
|
|
15
|
+
...(parentSessionId ? { parentSessionId } : {}),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('buildSessionTree', () => {
|
|
20
|
+
test('nests children under their parent and keeps orphans as roots', () => {
|
|
21
|
+
const tree = buildSessionTree([
|
|
22
|
+
session('root'),
|
|
23
|
+
session('child', 'root'),
|
|
24
|
+
session('grandchild', 'child'),
|
|
25
|
+
session('orphan', 'missing'),
|
|
26
|
+
]);
|
|
27
|
+
expect(tree.roots.map((row) => row.id)).toEqual(['root', 'orphan']);
|
|
28
|
+
expect(tree.childrenOf.get('root')?.map((row) => row.id)).toEqual(['child']);
|
|
29
|
+
expect(tree.childrenOf.get('child')?.map((row) => row.id)).toEqual(['grandchild']);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('a self-parent is a root rather than an invisible row', () => {
|
|
33
|
+
const tree = buildSessionTree([session('self', 'self')]);
|
|
34
|
+
expect(tree.roots.map((row) => row.id)).toEqual(['self']);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('descendants carry depth and stop at a cycle', () => {
|
|
38
|
+
const childrenOf = new Map<string, SessionItemData[]>([
|
|
39
|
+
['a', [session('b', 'a')]],
|
|
40
|
+
['b', [session('c', 'b')]],
|
|
41
|
+
]);
|
|
42
|
+
expect(descendantsOf('a', childrenOf).map((row) => [row.session.id, row.depth])).toEqual([
|
|
43
|
+
['b', 1],
|
|
44
|
+
['c', 2],
|
|
45
|
+
]);
|
|
46
|
+
// A cycle is not walked forever.
|
|
47
|
+
childrenOf.set('c', [session('a', 'c')]);
|
|
48
|
+
expect(descendantsOf('a', childrenOf).map((row) => row.session.id)).toEqual(['b', 'c']);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A flat session list → roots plus a parent→children map.
|
|
8
|
+
*
|
|
9
|
+
* A child session is a session, so the sidebar draws it under its parent. A
|
|
10
|
+
* session whose parent is not in the same folder (a cross-folder relation, or
|
|
11
|
+
* one the current filter/window removed) stays a root: hiding it would make a
|
|
12
|
+
* row the user can still open by URL unreachable from the sidebar.
|
|
13
|
+
*
|
|
14
|
+
* Pure and order-preserving: the list's own sort is the tree's sort.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { SessionItemData } from '@/shared/types';
|
|
18
|
+
|
|
19
|
+
export interface SessionTree {
|
|
20
|
+
roots: SessionItemData[];
|
|
21
|
+
childrenOf: Map<string, SessionItemData[]>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function buildSessionTree(sessions: readonly SessionItemData[]): SessionTree {
|
|
25
|
+
const present = new Set(sessions.map((session) => String(session.id)));
|
|
26
|
+
const childrenOf = new Map<string, SessionItemData[]>();
|
|
27
|
+
const roots: SessionItemData[] = [];
|
|
28
|
+
|
|
29
|
+
for (const session of sessions) {
|
|
30
|
+
const parentId = session.parentSessionId;
|
|
31
|
+
if (!parentId || !present.has(parentId) || parentId === String(session.id)) {
|
|
32
|
+
roots.push(session);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const bucket = childrenOf.get(parentId);
|
|
36
|
+
if (bucket) bucket.push(session);
|
|
37
|
+
else childrenOf.set(parentId, [session]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { roots, childrenOf };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Every descendant of a session, depth-first, with its depth (root child = 1). */
|
|
44
|
+
export function descendantsOf(
|
|
45
|
+
sessionId: string,
|
|
46
|
+
childrenOf: Map<string, SessionItemData[]>,
|
|
47
|
+
depth = 1,
|
|
48
|
+
seen = new Set<string>(),
|
|
49
|
+
): Array<{ session: SessionItemData; depth: number }> {
|
|
50
|
+
if (seen.has(sessionId)) return [];
|
|
51
|
+
seen.add(sessionId);
|
|
52
|
+
const out: Array<{ session: SessionItemData; depth: number }> = [];
|
|
53
|
+
for (const child of childrenOf.get(sessionId) ?? []) {
|
|
54
|
+
if (seen.has(String(child.id))) continue;
|
|
55
|
+
out.push({ session: child, depth });
|
|
56
|
+
out.push(...descendantsOf(String(child.id), childrenOf, depth + 1, seen));
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
@@ -27,13 +27,16 @@ export type ClientSignalName =
|
|
|
27
27
|
/** A session was renamed (this tab), so the navbar follows without a refetch. */
|
|
28
28
|
| 'session-renamed'
|
|
29
29
|
/** A Kabmo-mode notice marker parsed out of a frame. */
|
|
30
|
-
| 'kabmo-mode'
|
|
30
|
+
| 'kabmo-mode'
|
|
31
|
+
/** The agent changed its own config/mode; the composer re-reads `/modes`. */
|
|
32
|
+
| 'session-modes-changed';
|
|
31
33
|
|
|
32
34
|
/** One signal's payload, keyed by the signal that carries it. */
|
|
33
35
|
export interface ClientSignalPayloads {
|
|
34
36
|
'session-title-hint': { sessionId: string; title: string };
|
|
35
37
|
'session-renamed': { sessionId: string; title: string };
|
|
36
38
|
'kabmo-mode': { sessionId?: string; marker?: unknown };
|
|
39
|
+
'session-modes-changed': { sessionId: string };
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
type Listener<N extends ClientSignalName> = (payload: ClientSignalPayloads[N]) => void;
|
|
@@ -42,6 +45,7 @@ const listeners: { [N in ClientSignalName]: Set<Listener<N>> } = {
|
|
|
42
45
|
'session-title-hint': new Set(),
|
|
43
46
|
'session-renamed': new Set(),
|
|
44
47
|
'kabmo-mode': new Set(),
|
|
48
|
+
'session-modes-changed': new Set(),
|
|
45
49
|
};
|
|
46
50
|
|
|
47
51
|
/** Subscribe to one signal. Returns the unsubscribe. */
|
package/src/client/main.tsx
CHANGED
|
@@ -16,6 +16,7 @@ import { installBackDispatcher } from '@/client/lib/native/back';
|
|
|
16
16
|
import { installPalettePublisher } from '@/client/lib/native/palette';
|
|
17
17
|
import { installShellTransport } from '@/client/lib/shell/transport';
|
|
18
18
|
import { installResumeDispatcher } from '@/client/lib/native/resume';
|
|
19
|
+
import { installOpenSessionDispatcher } from '@/client/lib/native/open-session';
|
|
19
20
|
import { installFileLaunchHandler } from '@/client/lib/launch/file-handlers';
|
|
20
21
|
import { installOpenPaths } from '@/client/lib/native/open-paths';
|
|
21
22
|
import { installDeviceFiles } from '@/client/lib/launch/device-files';
|
|
@@ -115,6 +116,11 @@ installFileLaunchHandler((result) => {
|
|
|
115
116
|
if (!result.ok) console.warn(`[kabmo] ${result.message}`);
|
|
116
117
|
});
|
|
117
118
|
|
|
119
|
+
// A native shell calls `window.__kabmoOpenSession(id)` when the user clicks a
|
|
120
|
+
// system notification. Installed before the first render for the same reason as
|
|
121
|
+
// the other native hooks: a click on a cold start can land before hydration.
|
|
122
|
+
installOpenSessionDispatcher();
|
|
123
|
+
|
|
118
124
|
// A file the OS handed to a DESKTOP shell — a double-click in Finder, "Open
|
|
119
125
|
// With → Kabmo", a drop on the Dock icon — arrives as a PATH, which no browser
|
|
120
126
|
// API can see. The shell injects the launch batch before this script and calls
|
package/src/client/tailwind.css
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
@import "tailwindcss";
|
|
2
|
-
@import "@xterm/xterm/css/xterm.css";
|
|
3
2
|
|
|
4
3
|
@theme {
|
|
5
4
|
/* The UI font stack, with the Nerd Font families LAST.
|
|
@@ -7,7 +6,7 @@
|
|
|
7
6
|
* omp heads a session title with a card icon — a private-use glyph
|
|
8
7
|
* (`title.icons: nf+emoji`, the default) that no Latin face contains. The
|
|
9
8
|
* terminal already names a Nerd Font for exactly this reason
|
|
10
|
-
* (`
|
|
9
|
+
* (`TERMINAL_GLYPH_FALLBACKS` + `NERD_SYMBOLS_FAMILY` in
|
|
11
10
|
* `data/theme/terminal.ts`), but the UI stack did not, so a title card
|
|
12
11
|
* rendered only where the DEVICE happened to have a Nerd Font installed: on
|
|
13
12
|
* the developer's desktop Chromium fell back to one, and on a phone — which
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
* fallback and downloads it on every machine.
|
|
25
24
|
*
|
|
26
25
|
* The family names are literals here because Tailwind's `@theme` cannot
|
|
27
|
-
* import a TS constant; they must stay equal to `
|
|
26
|
+
* import a TS constant; they must stay equal to `TERMINAL_GLYPH_FALLBACKS` and
|
|
28
27
|
* `NERD_SYMBOLS_FAMILY`, which `nerd-symbols.test.ts` asserts. */
|
|
29
28
|
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "FiraCode Nerd Font Mono", "FiraCode Nerd Font", "JetBrainsMono Nerd Font", "JetBrainsMono NF", "JetBrains Mono Nerd Font", "Hack Nerd Font", "MesloLGS NF", "MesloLGM Nerd Font", "CaskaydiaCove Nerd Font", "SauceCodePro Nerd Font", "Symbols Nerd Font Mono", "Symbols Nerd Font", "PowerlineSymbols", "Kabmo Nerd Symbols";
|
|
30
29
|
--color-ink: var(--theme-ink);
|
|
@@ -553,16 +552,23 @@
|
|
|
553
552
|
display: none;
|
|
554
553
|
}
|
|
555
554
|
|
|
556
|
-
/* The terminal
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
|
|
555
|
+
/* The terminal host: ghostty-web draws its scrollbar inside the canvas, so
|
|
556
|
+
* there is no native viewport to style. The drag-to-scroll handlers in
|
|
557
|
+
* `terminal-panel/mount.ts` own the gesture; `pan-y` keeps the browser from
|
|
558
|
+
* claiming it first, and momentum stays the platform's.
|
|
559
|
+
*
|
|
560
|
+
* `caret-color: transparent` is not cosmetic. ghostty-web marks the host it is
|
|
561
|
+
* opened on `contenteditable="true"` and `tabindex="0"` (the IME/`beforeinput`
|
|
562
|
+
* path), and its visible input is a hidden textarea — so a click on the 6px
|
|
563
|
+
* padding focuses the DIV itself and the browser paints a NATIVE caret there:
|
|
564
|
+
* a black blinking bar at the left edge, whose height follows the host's
|
|
565
|
+
* inherited 16px/24px line box (measured in Chromium: 24px, and it changes
|
|
566
|
+
* with the content beside the click point). The terminal's cursor is the
|
|
567
|
+
* canvas block, so the DOM caret is never wanted. */
|
|
568
|
+
.kabmo-terminal {
|
|
564
569
|
touch-action: pan-y;
|
|
565
570
|
-webkit-overflow-scrolling: touch;
|
|
571
|
+
caret-color: transparent;
|
|
566
572
|
}
|
|
567
573
|
|
|
568
574
|
/* The chat column's width, in ONE variable and ONE class.
|
package/src/server/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { readHandoverFromStdin } from '@/shared/lib/auth/handover';
|
|
|
10
10
|
import { ssrRoutes } from '@/server/plugins/ssr';
|
|
11
11
|
import { setListener } from '@/server/lib/lifecycle/listener';
|
|
12
12
|
import { getDatabasePath } from '@/server/db.server';
|
|
13
|
+
import { initAgentTokens } from '@/server/lib/sessions/agent-token.server';
|
|
13
14
|
import { logDetectedRegistry } from '@/server/lib/models/detected-registry.server';
|
|
14
15
|
import { ompStartupError, ompStartupLogLines } from '@/server/lib/omp/core/startup';
|
|
15
16
|
import { readInstanceRecord, removeInstanceRecord, writeInstanceRecord } from '@/server/lib/lifecycle/instance';
|
|
@@ -67,6 +68,7 @@ console.log(`[kabmo] mock mode: ${isMockMode() ? 'true (demo presets)' : 'f
|
|
|
67
68
|
console.log(`[kabmo] ui auth: ${authNotice}${runPassword.source === 'argv' ? ' [from argv]' : ''}`);
|
|
68
69
|
for (const line of ompStartupLogLines()) console.log(`[kabmo] ${line}`);
|
|
69
70
|
console.log(`[kabmo] db: ${await getDatabasePath()}`);
|
|
71
|
+
await initAgentTokens();
|
|
70
72
|
|
|
71
73
|
const port = Number(Bun.env.PORT) || 3000;
|
|
72
74
|
const host = Bun.env.HOST || 'localhost';
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
import { hashPassword, deriveCredentialKey, readSessionSecret, writeSessionSecret, type ActiveAuthConfig } from '@/server/lib/auth/config';
|
|
30
30
|
import { readSessionCookie, verifySessionToken } from '@/server/lib/auth/token';
|
|
31
|
+
import { agentTokenScopeForPath, bearerToken, verifyAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
31
32
|
import { rememberClientAddress } from '@/server/lib/auth/client-address';
|
|
32
33
|
import type { CredentialHandover } from '@/shared/lib/auth/handover';
|
|
33
34
|
|
|
@@ -290,6 +291,15 @@ export function authGate(request: Request, clientAddress?: string): Response | u
|
|
|
290
291
|
return undefined;
|
|
291
292
|
}
|
|
292
293
|
|
|
294
|
+
// An agent subprocess carries a bearer token instead of a cookie. It is
|
|
295
|
+
// scoped by path to the session it names; spawn is the one path a child may
|
|
296
|
+
// call under its own token (to create its own children).
|
|
297
|
+
const scope = agentTokenScopeForPath(pathname);
|
|
298
|
+
if (scope) {
|
|
299
|
+
const agentSession = verifyAgentToken(bearerToken(request));
|
|
300
|
+
if (agentSession && (scope === 'any' || scope === agentSession)) return undefined;
|
|
301
|
+
}
|
|
302
|
+
|
|
293
303
|
const wantsHtml = (request.headers.get('accept') ?? '').includes('text/html');
|
|
294
304
|
return rejectionResponse(pathname, wantsHtml);
|
|
295
305
|
}
|