@kabmo-labs/kabmo 0.25.0 → 0.27.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 +448 -444
- package/dist/client/static/js/index-32rpkj6b.css +1 -0
- package/dist/client/static/js/{index-ga8cbpt4.js → index-e3qh2yps.js} +950 -950
- package/package.json +1 -1
- package/src/client/components/common/Toast.test.tsx +28 -2
- package/src/client/components/common/Toast.tsx +21 -9
- 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/desktop-layout/LeftColumn.tsx +2 -1
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +66 -69
- 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/SessionList.tsx +2 -1
- 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/UpdateSection.tsx +3 -2
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +30 -14
- package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +69 -85
- package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -1
- package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
- package/src/client/components/mobile/SessionSidebar.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +59 -62
- package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
- 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/Modal.tsx +1 -1
- 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/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
- package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +86 -93
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +21 -1
- package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -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/fork-preview.test.tsx +141 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +16 -22
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +116 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/components/workspace/git-panel/index.tsx +2 -2
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +8 -5
- package/src/client/components/workspace/terminal-panel/index.tsx +3 -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 +9 -0
- package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
- package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
- package/src/client/hooks/chat/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-preview.test.ts +148 -0
- package/src/client/hooks/chat/timeline/fork-preview.ts +104 -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/fork-send.test.ts +139 -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 +214 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +302 -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/chat/waiting/cancel.ts +2 -1
- package/src/client/hooks/chat/waiting/dispatch.ts +5 -4
- package/src/client/hooks/chat/waiting/held.ts +2 -1
- 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/settings/providers/actions.ts +3 -2
- package/src/client/hooks/settings/providers/messages.ts +9 -7
- package/src/client/hooks/settings/providers/model-actions.ts +2 -1
- package/src/client/hooks/ui/editor-error-toast.ts +2 -1
- package/src/client/hooks/ui/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/batch-archive.test.ts +2 -2
- package/src/client/hooks/workspace/batch-archive.ts +4 -2
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
- package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
- package/src/client/hooks/workspace/session-actions.test.ts +2 -1
- package/src/client/hooks/workspace/session-actions.ts +2 -1
- package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
- package/src/client/hooks/workspace/terminal/connection.ts +47 -0
- package/src/client/hooks/workspace/terminal/index.ts +35 -4
- package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
- package/src/client/lib/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/lib/usage/report.server.ts +57 -0
- 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/chat/timeline/fork-preview.test.ts +62 -0
- package/src/shared/lib/chat/timeline/fork-preview.ts +36 -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/lib/ui/toast-duration.test.ts +25 -1
- package/src/shared/lib/ui/toast-duration.ts +22 -4
- package/src/shared/lib/workspace/session-state/store.ts +4 -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,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
|
|
@@ -18,6 +18,18 @@
|
|
|
18
18
|
|
|
19
19
|
import type { AcpId, AcpResponse } from '@/server/lib/harness/acp/protocol';
|
|
20
20
|
|
|
21
|
+
/** A JSON-RPC error answer, with the code the spec defines for it. */
|
|
22
|
+
export class AcpRequestError extends Error {
|
|
23
|
+
constructor(
|
|
24
|
+
message: string,
|
|
25
|
+
readonly code: number,
|
|
26
|
+
readonly data?: unknown,
|
|
27
|
+
) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'AcpRequestError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
export interface Pending {
|
|
22
34
|
resolve: (value: unknown) => void;
|
|
23
35
|
reject: (error: Error) => void;
|
|
@@ -60,8 +72,10 @@ export class PendingCalls {
|
|
|
60
72
|
this.map.delete(response.id);
|
|
61
73
|
clearTimeout(entry.timer);
|
|
62
74
|
if (response.error) {
|
|
63
|
-
entry.reject(new
|
|
75
|
+
entry.reject(new AcpRequestError(
|
|
64
76
|
`${response.error.message}${response.error.data ? `: ${JSON.stringify(response.error.data)}` : ''}`,
|
|
77
|
+
response.error.code,
|
|
78
|
+
response.error.data,
|
|
65
79
|
));
|
|
66
80
|
return true;
|
|
67
81
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The client's `initialize` advertisement and version negotiation.
|
|
8
|
+
*
|
|
9
|
+
* Both are promises made to the agent: the capability object says which
|
|
10
|
+
* agent→client calls this client will answer, and the answer to an unsupported
|
|
11
|
+
* protocol major has to be a refusal rather than a v2 frame parsed as v1.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
import {
|
|
16
|
+
ACP_PROTOCOL_VERSION,
|
|
17
|
+
KABMO_CLIENT_CAPABILITIES,
|
|
18
|
+
assertProtocolVersion,
|
|
19
|
+
} from '@/server/lib/harness/acp/client-capabilities';
|
|
20
|
+
|
|
21
|
+
describe('client capabilities', () => {
|
|
22
|
+
test('advertises the fs methods the client actually implements', () => {
|
|
23
|
+
expect(KABMO_CLIENT_CAPABILITIES.fs).toEqual({ readTextFile: true, writeTextFile: true });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('advertises notices, which the frame mapper already renders', () => {
|
|
27
|
+
expect(KABMO_CLIENT_CAPABILITIES.session.notices).toEqual({});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('does not advertise surfaces with no bridge', () => {
|
|
31
|
+
const advertised = KABMO_CLIENT_CAPABILITIES as Record<string, unknown>;
|
|
32
|
+
expect(advertised.terminal).toBeUndefined();
|
|
33
|
+
expect(advertised.elicitation).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('protocol version negotiation', () => {
|
|
38
|
+
test('sends v2 as its latest version', () => {
|
|
39
|
+
expect(ACP_PROTOCOL_VERSION).toBe(2);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('accepts both majors it implements', () => {
|
|
43
|
+
expect(() => assertProtocolVersion({ protocolVersion: 1 })).not.toThrow();
|
|
44
|
+
expect(() => assertProtocolVersion({ protocolVersion: 2 })).not.toThrow();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('refuses a major it cannot speak, naming the agent and both versions', () => {
|
|
48
|
+
expect(() => assertProtocolVersion({ protocolVersion: 3, agentInfo: { title: 'Acme' } }))
|
|
49
|
+
.toThrow('Acme speaks ACP v3; Kabmo supports v1 and v2');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('refuses an answer that reports no version at all', () => {
|
|
53
|
+
expect(() => assertProtocolVersion({})).toThrow('speaks ACP vundefined');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What Kabmo advertises as a **v1** ACP client at `initialize`.
|
|
8
|
+
*
|
|
9
|
+
* v2 removed the client fs and terminal execution APIs, so a v2 connection
|
|
10
|
+
* advertises `capabilities: {}` instead; the hybrid request in
|
|
11
|
+
* `client-initialize.ts` carries both field sets so a v1 peer still sees this
|
|
12
|
+
* object while a v2 peer ignores it as an unknown field.
|
|
13
|
+
*
|
|
14
|
+
* Every entry here is a promise the client answers itself, so the list is
|
|
15
|
+
* narrower than the protocol: an advertised capability the client cannot serve
|
|
16
|
+
* makes the agent park a turn on a call nobody answers (the failure mode
|
|
17
|
+
* `session-requests.ts` exists to prevent).
|
|
18
|
+
*
|
|
19
|
+
* - **fs** — `client-fs.ts` implements both methods against the session's
|
|
20
|
+
* workspace, so an agent that reads or writes through the client reaches the
|
|
21
|
+
* same files the user's editor is looking at.
|
|
22
|
+
* - **session.notices** — `AcpFrameMapper` already renders `notice` updates as
|
|
23
|
+
* notices; without the advertisement a spec-compliant agent had to model them
|
|
24
|
+
* as conversation text instead.
|
|
25
|
+
*
|
|
26
|
+
* Deliberately absent, each for a measured reason:
|
|
27
|
+
*
|
|
28
|
+
* - `terminal` — this client has no bridge that surfaces an ACP terminal's
|
|
29
|
+
* output in the timeline, and advertising it would route an agent's shell
|
|
30
|
+
* work through a terminal the user cannot see.
|
|
31
|
+
* - `elicitation` — no form/URL dialog exists yet; advertising it would make
|
|
32
|
+
* the agent block on an `elicitation/create` nobody draws.
|
|
33
|
+
* - `auth.terminal` — Kabmo does not reproduce the agent's launch line in an
|
|
34
|
+
* interactive terminal for login.
|
|
35
|
+
* - `session.configOptions.boolean` — the selector UI is select-only.
|
|
36
|
+
* - `session.compaction` — compaction updates have no renderer.
|
|
37
|
+
*/
|
|
38
|
+
export const KABMO_CLIENT_CAPABILITIES = {
|
|
39
|
+
fs: { readTextFile: true, writeTextFile: true },
|
|
40
|
+
session: { notices: {} },
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
/** The latest protocol major this client sends; it also speaks v1. */
|
|
44
|
+
export const ACP_PROTOCOL_VERSION = 2;
|
|
45
|
+
|
|
46
|
+
/** Every major this client implements. */
|
|
47
|
+
export const ACP_SUPPORTED_VERSIONS = [1, 2] as const;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Refuse an `initialize` answer this client cannot speak.
|
|
51
|
+
*
|
|
52
|
+
* Kabmo implements v1 and v2 side by side; a v1-only agent answers 1 and a v2
|
|
53
|
+
* agent answers 2. Anything else is a connection this client cannot parse.
|
|
54
|
+
*/
|
|
55
|
+
export function assertProtocolVersion(result: { protocolVersion?: unknown; agentInfo?: { name?: string; title?: string } }): void {
|
|
56
|
+
if (result.protocolVersion === 1 || result.protocolVersion === 2) return;
|
|
57
|
+
const agent = result.agentInfo?.title ?? result.agentInfo?.name ?? 'The agent';
|
|
58
|
+
throw new Error(
|
|
59
|
+
`${agent} speaks ACP v${String(result.protocolVersion)}; Kabmo supports v1 and v2`,
|
|
60
|
+
);
|
|
61
|
+
}
|