@kabmo-labs/kabmo 0.25.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 +440 -436
- package/dist/client/static/js/{index-ga8cbpt4.js → index-95b3n20k.js} +945 -945
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/session-actions-menu/index.tsx +38 -12
- 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 +15 -3
- package/src/client/components/common/session-row/index.tsx +24 -25
- 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/session-sidebar/CategoryItem.tsx +64 -68
- 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 +33 -30
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -13
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +59 -57
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +57 -61
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
- 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/EmptyWorkspacePrompt.tsx +28 -39
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -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/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/index.tsx +10 -21
- 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/hooks/chat/composer/items.test.ts +19 -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/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/send.ts +17 -103
- 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 +40 -31
- package/src/client/hooks/models/use-harness-update.test.ts +137 -44
- package/src/client/hooks/models/use-harness-update.ts +133 -85
- 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/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/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/server/lib/db/schema.ts +1 -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 +31 -21
- 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/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/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
- package/src/server/lib/harness/acp/session-handshake.ts +83 -6
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- 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 +48 -6
- package/src/server/lib/harness/acp/session-turns.ts +8 -3
- 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 +19 -1
- package/src/server/lib/harness/acp/session.ts +60 -60
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +102 -0
- package/src/server/lib/harness/acp/turn.ts +81 -6
- 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 +46 -6
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +21 -9
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/update-job-store.test.ts +37 -12
- package/src/server/lib/harness/update-job-store.ts +22 -16
- package/src/server/lib/harness/update-job.server.ts +66 -175
- 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.ts +8 -3
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +14 -9
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
- package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
- package/src/server/lib/sessions/fork.server.test.ts +68 -0
- package/src/server/lib/sessions/fork.server.ts +31 -6
- package/src/server/lib/sessions/spawn.server.test.ts +41 -0
- package/src/server/lib/sessions/spawn.server.ts +27 -2
- package/src/server/routes/agent/harness-command.ts +6 -5
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/update-status.ts +18 -12
- package/src/server/routes/harness/update.test.ts +53 -16
- package/src/server/routes/harness/update.ts +13 -8
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/fork.ts +19 -4
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +19 -0
- package/src/server/routes/sessions/spawn.ts +16 -13
- 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/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +53 -6
- 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/settings/defaults.ts +3 -0
- package/src/shared/types/harness-update.ts +24 -0
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/harness-table.test-util.ts +25 -9
- package/dist/client/static/js/index-bc9aa4mx.css +0 -1
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
- package/src/client/hooks/workspace/child-expansion.ts +0 -33
|
@@ -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);
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|