@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
|
@@ -1,13 +1,64 @@
|
|
|
1
|
-
import { useState } from 'preact/hooks';
|
|
2
|
-
import {
|
|
1
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
2
|
+
import {
|
|
3
|
+
BellRing,
|
|
4
|
+
CircleCheck,
|
|
5
|
+
CircleQuestionMark,
|
|
6
|
+
Sparkles,
|
|
7
|
+
TriangleAlert,
|
|
8
|
+
Volume2,
|
|
9
|
+
VolumeX,
|
|
10
|
+
} from 'lucide-preact';
|
|
3
11
|
import type { SettingsState } from '@/shared/types';
|
|
4
12
|
import { playNotificationSound } from '@/client/hooks/ui/notification-sound';
|
|
13
|
+
import { requestNotificationPermission } from '@/client/lib/notifications/os';
|
|
5
14
|
|
|
6
15
|
interface NotificationSettingsProps {
|
|
7
16
|
settings: SettingsState;
|
|
8
17
|
onUpdate: (updater: Partial<SettingsState> | ((prev: SettingsState) => SettingsState)) => void;
|
|
9
18
|
}
|
|
10
19
|
|
|
20
|
+
interface SystemToggleProps {
|
|
21
|
+
icon: typeof BellRing;
|
|
22
|
+
title: string;
|
|
23
|
+
description: string;
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
onToggle: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function SystemToggle({ icon: Icon, title, description, enabled, onToggle }: SystemToggleProps) {
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex items-start justify-between gap-4 py-3">
|
|
31
|
+
<div className="flex items-start gap-3">
|
|
32
|
+
<div className="w-8 h-8 rounded-md bg-ink/5 border border-ink/10 flex items-center justify-center flex-shrink-0 mt-0.5">
|
|
33
|
+
<Icon size={16} className={enabled ? 'text-ink' : 'text-ink/40'} />
|
|
34
|
+
</div>
|
|
35
|
+
<div>
|
|
36
|
+
<div className="text-sm font-semibold text-ink">{title}</div>
|
|
37
|
+
<p className="text-ink/65 text-[11px] mt-1 leading-relaxed">{description}</p>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<button
|
|
42
|
+
type="button"
|
|
43
|
+
role="switch"
|
|
44
|
+
aria-checked={enabled}
|
|
45
|
+
aria-label={`${enabled ? 'Disable' : 'Enable'} ${title}`}
|
|
46
|
+
onClick={onToggle}
|
|
47
|
+
className={`relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${
|
|
48
|
+
enabled ? 'bg-ink' : 'bg-ink/20'
|
|
49
|
+
}`}
|
|
50
|
+
>
|
|
51
|
+
<span
|
|
52
|
+
aria-hidden="true"
|
|
53
|
+
className={`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-paper shadow ring-0 transition duration-200 ease-in-out ${
|
|
54
|
+
enabled ? 'translate-x-5' : 'translate-x-0'
|
|
55
|
+
}`}
|
|
56
|
+
/>
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
11
62
|
export function NotificationSettings({ settings, onUpdate }: NotificationSettingsProps) {
|
|
12
63
|
const [isPlayingTest, setIsPlayingTest] = useState(false);
|
|
13
64
|
|
|
@@ -18,6 +69,24 @@ export function NotificationSettings({ settings, onUpdate }: NotificationSetting
|
|
|
18
69
|
};
|
|
19
70
|
|
|
20
71
|
const isSoundEnabled = settings.chatCompletionSound ?? settings.soundAlerts ?? true;
|
|
72
|
+
const anySystemNotification = settings.notifyOnFinish === true
|
|
73
|
+
|| settings.notifyOnAsk === true
|
|
74
|
+
|| settings.notifyOnError === true;
|
|
75
|
+
|
|
76
|
+
// A preference can be turned on in another tab, a browser, or before this
|
|
77
|
+
// shell was installed — and the OS permission belongs to THIS shell. Opening
|
|
78
|
+
// the page that owns the preference is the honest moment to ask, and the
|
|
79
|
+
// shell answers immediately when permission is already granted.
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (anySystemNotification) void requestNotificationPermission();
|
|
82
|
+
}, [anySystemNotification]);
|
|
83
|
+
|
|
84
|
+
// Turning one of these on asks for permission immediately, so the toggle can
|
|
85
|
+
// never read "on" without the shell having had its chance to prompt.
|
|
86
|
+
const setSystemNotification = (key: 'notifyOnFinish' | 'notifyOnAsk' | 'notifyOnError', next: boolean) => {
|
|
87
|
+
onUpdate({ [key]: next });
|
|
88
|
+
if (next) void requestNotificationPermission();
|
|
89
|
+
};
|
|
21
90
|
|
|
22
91
|
return (
|
|
23
92
|
<div className="w-full space-y-6 text-xs text-ink">
|
|
@@ -92,6 +161,47 @@ export function NotificationSettings({ settings, onUpdate }: NotificationSetting
|
|
|
92
161
|
</button>
|
|
93
162
|
</div>
|
|
94
163
|
</div>
|
|
164
|
+
|
|
165
|
+
{/* System Notifications */}
|
|
166
|
+
<div className="bg-paper border border-ink/15 rounded-lg p-4 shadow-xs">
|
|
167
|
+
<div className="flex items-start gap-3 pb-3 border-b border-ink/10">
|
|
168
|
+
<div className="w-8 h-8 rounded-md bg-ink/5 border border-ink/10 flex items-center justify-center flex-shrink-0 mt-0.5">
|
|
169
|
+
<BellRing size={16} className="text-ink" />
|
|
170
|
+
</div>
|
|
171
|
+
<div>
|
|
172
|
+
<div className="text-sm font-semibold text-ink">System Notifications</div>
|
|
173
|
+
<p className="text-ink/65 text-[11px] mt-1 leading-relaxed">
|
|
174
|
+
Shown by Android, iOS and the desktop shell — and by the browser outside a shell — only
|
|
175
|
+
while Kabmo is not the window you are looking at. Clicking one opens that session.
|
|
176
|
+
The sidebar badge stays the in-app record either way.
|
|
177
|
+
</p>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
|
|
181
|
+
<div className="divide-y divide-ink/10">
|
|
182
|
+
<SystemToggle
|
|
183
|
+
icon={CircleCheck}
|
|
184
|
+
title="Run finished"
|
|
185
|
+
description="A session's agent finished its turn."
|
|
186
|
+
enabled={settings.notifyOnFinish === true}
|
|
187
|
+
onToggle={() => setSystemNotification('notifyOnFinish', settings.notifyOnFinish !== true)}
|
|
188
|
+
/>
|
|
189
|
+
<SystemToggle
|
|
190
|
+
icon={CircleQuestionMark}
|
|
191
|
+
title="Waiting for you"
|
|
192
|
+
description="An agent is blocked on a question or an approval."
|
|
193
|
+
enabled={settings.notifyOnAsk === true}
|
|
194
|
+
onToggle={() => setSystemNotification('notifyOnAsk', settings.notifyOnAsk !== true)}
|
|
195
|
+
/>
|
|
196
|
+
<SystemToggle
|
|
197
|
+
icon={TriangleAlert}
|
|
198
|
+
title="Run failed"
|
|
199
|
+
description="A run ended in failure, with the reason when the agent reported one."
|
|
200
|
+
enabled={settings.notifyOnError === true}
|
|
201
|
+
onToggle={() => setSystemNotification('notifyOnError', settings.notifyOnError !== true)}
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
95
205
|
</div>
|
|
96
206
|
);
|
|
97
207
|
}
|
|
@@ -193,7 +193,7 @@ export function HarnessCard({
|
|
|
193
193
|
<div className="grid gap-x-6 sm:grid-cols-2">
|
|
194
194
|
<div>
|
|
195
195
|
<div className="mb-1 text-[10px] font-semibold uppercase tracking-wider text-ink/40">Session</div>
|
|
196
|
-
<Capability label="Load / resume history" value={caps ? caps.loadSession : null} />
|
|
196
|
+
<Capability label="Load / resume history" value={caps ? caps.loadSession || caps.resumeSession : null} />
|
|
197
197
|
<Capability label="List sessions" value={caps ? caps.listSessions : null} />
|
|
198
198
|
<Capability label="Fork" value={caps ? caps.forkSession : null} />
|
|
199
199
|
<Capability label="Delete" value={caps ? caps.deleteSession : null} />
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The assistant run footer's Fork action.
|
|
8
|
+
*
|
|
9
|
+
* The footer already carries a `msgId`, but it is the run's OPENING user row
|
|
10
|
+
* (Retry rewinds there). Forking at that anchor branches BEFORE the answer the
|
|
11
|
+
* button sits under, so the footer's fork has to use the run's owner row. These
|
|
12
|
+
* pin the anchor on both the desktop strip and the phone sheet — the same
|
|
13
|
+
* handler feeds both, and a future call site that passes only `msgId` must not
|
|
14
|
+
* silently fork at the wrong place.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
18
|
+
import { Window } from 'happy-dom';
|
|
19
|
+
import { h, render } from 'preact';
|
|
20
|
+
import { act } from 'preact/test-utils';
|
|
21
|
+
|
|
22
|
+
import { RunFooter } from '@/client/components/workspace/chat-timeline/RunFooter';
|
|
23
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
24
|
+
import type { ChatMessageData } from '@/shared/types';
|
|
25
|
+
|
|
26
|
+
let container: HTMLElement;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
30
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
render(null, container);
|
|
35
|
+
container.remove();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterAll(() => restoreDomGlobals());
|
|
39
|
+
|
|
40
|
+
function mount(node: preact.ComponentChild): HTMLElement {
|
|
41
|
+
act(() => {
|
|
42
|
+
render(node, container);
|
|
43
|
+
});
|
|
44
|
+
return container;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const answerRow: ChatMessageData = {
|
|
48
|
+
id: 'ai-7',
|
|
49
|
+
role: 'ai',
|
|
50
|
+
content: 'the answer',
|
|
51
|
+
model: 'gpt-5',
|
|
52
|
+
provider: 'openai',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
describe('assistant footer fork', () => {
|
|
56
|
+
test('desktop forks at the run owner row, not the Retry anchor', () => {
|
|
57
|
+
const calls: string[] = [];
|
|
58
|
+
const el = mount(h(RunFooter, {
|
|
59
|
+
msg: answerRow,
|
|
60
|
+
retryTargetId: 'user-3',
|
|
61
|
+
onFork: (id) => calls.push(id),
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const fork = el.querySelector('button[aria-label="Fork session from this answer"]') as HTMLButtonElement | null;
|
|
65
|
+
expect(fork).not.toBeNull();
|
|
66
|
+
act(() => fork!.click());
|
|
67
|
+
|
|
68
|
+
expect(calls).toEqual(['ai-7']);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('the phone sheet offers the same fork action', () => {
|
|
72
|
+
const calls: string[] = [];
|
|
73
|
+
const el = mount(h(RunFooter, {
|
|
74
|
+
msg: answerRow,
|
|
75
|
+
retryTargetId: 'user-3',
|
|
76
|
+
isMobile: true,
|
|
77
|
+
onFork: (id) => calls.push(id),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
act(() => {
|
|
81
|
+
(el.querySelector('button[aria-label="More actions"]') as HTMLButtonElement).click();
|
|
82
|
+
});
|
|
83
|
+
const fork = el.querySelector('button[aria-label="Fork session from this answer"]') as HTMLButtonElement | null;
|
|
84
|
+
expect(fork).not.toBeNull();
|
|
85
|
+
act(() => fork!.click());
|
|
86
|
+
|
|
87
|
+
expect(calls).toEqual(['ai-7']);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('no onFork keeps the strip unchanged', () => {
|
|
91
|
+
const el = mount(h(RunFooter, { msg: answerRow, retryTargetId: 'user-3' }));
|
|
92
|
+
expect(el.querySelector('button[aria-label="Fork session from this answer"]')).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'preact/hooks';
|
|
2
2
|
import type { ReactNode } from 'preact/compat';
|
|
3
|
-
import { Brain, Clock3, Coins, Hourglass, MessageSquarePlus, MoreHorizontal, RotateCcw, X } from 'lucide-preact';
|
|
3
|
+
import { Brain, Clock3, Coins, GitFork, Hourglass, MessageSquarePlus, MoreHorizontal, RotateCcw, X } from 'lucide-preact';
|
|
4
4
|
import { CopyButton } from '@/client/components/common/CopyButton';
|
|
5
5
|
import { RunMark } from '@/client/components/workspace/chat-timeline/RunMark';
|
|
6
6
|
import { PluginMessageActions } from '@/client/components/workspace/chat-timeline/PluginMessageActions';
|
|
@@ -33,12 +33,20 @@ interface AiMessageFooterProps {
|
|
|
33
33
|
msgId: string;
|
|
34
34
|
onRetry?: (msgId: string) => void;
|
|
35
35
|
onNewChat?: (content: string) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Anchor row for Fork. Separate from `msgId`, which Retry resolves to the
|
|
38
|
+
* run's OPENING user row: forking there branches before the answer this
|
|
39
|
+
* footer sits under. The anchor is the run's owner row instead, so the fork
|
|
40
|
+
* keeps the answer.
|
|
41
|
+
*/
|
|
42
|
+
forkTargetId?: string;
|
|
43
|
+
onFork?: (msgId: string) => void;
|
|
36
44
|
isMobile?: boolean;
|
|
37
45
|
/**
|
|
38
|
-
* Whether the row offers Retry / New-chat.
|
|
39
|
-
* turn, branch a
|
|
40
|
-
* row the chat does not own — the BTW panel's side answer —
|
|
41
|
-
* instead of rendering buttons that do nothing.
|
|
46
|
+
* Whether the row offers Retry / Fork / New-chat. All of them act on the
|
|
47
|
+
* CHAT (re-run a chat turn, branch a session from it), so a footer that
|
|
48
|
+
* describes a row the chat does not own — the BTW panel's side answer —
|
|
49
|
+
* turns them off instead of rendering buttons that do nothing.
|
|
42
50
|
*/
|
|
43
51
|
showActions?: boolean;
|
|
44
52
|
}
|
|
@@ -56,6 +64,8 @@ export function AiMessageFooter({
|
|
|
56
64
|
harness,
|
|
57
65
|
onRetry,
|
|
58
66
|
onNewChat,
|
|
67
|
+
forkTargetId,
|
|
68
|
+
onFork,
|
|
59
69
|
isMobile = false,
|
|
60
70
|
showActions = true,
|
|
61
71
|
}: AiMessageFooterProps) {
|
|
@@ -71,6 +81,11 @@ export function AiMessageFooter({
|
|
|
71
81
|
onNewChat?.(content);
|
|
72
82
|
};
|
|
73
83
|
|
|
84
|
+
const handleFork = () => {
|
|
85
|
+
setIsMenuOpen(false);
|
|
86
|
+
if (forkTargetId) onFork?.(forkTargetId);
|
|
87
|
+
};
|
|
88
|
+
|
|
74
89
|
useEffect(() => {
|
|
75
90
|
if (!isMenuOpen) return;
|
|
76
91
|
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
|
|
@@ -221,6 +236,12 @@ export function AiMessageFooter({
|
|
|
221
236
|
<RotateCcw size={20} className="shrink-0 text-ink/55" />
|
|
222
237
|
<span>Retry response</span>
|
|
223
238
|
</button>
|
|
239
|
+
{onFork && forkTargetId && (
|
|
240
|
+
<button type="button" aria-label="Fork session from this answer" onClick={handleFork} className="flex min-h-12 w-full items-center gap-3 rounded-lg px-3 text-left text-sm text-ink transition-colors hover:bg-ink/5 cursor-pointer">
|
|
241
|
+
<GitFork size={20} className="shrink-0 text-ink/55" />
|
|
242
|
+
<span>Fork from this answer</span>
|
|
243
|
+
</button>
|
|
244
|
+
)}
|
|
224
245
|
<button type="button" aria-label="Start new chat from this answer" onClick={handleNewChat} className="flex min-h-12 w-full items-center gap-3 rounded-lg px-3 text-left text-sm text-ink transition-colors hover:bg-ink/5 cursor-pointer">
|
|
225
246
|
<MessageSquarePlus size={20} className="shrink-0 text-ink/55" />
|
|
226
247
|
<span>Start new chat from this answer</span>
|
|
@@ -267,6 +288,11 @@ export function AiMessageFooter({
|
|
|
267
288
|
ariaLabel="Copy response"
|
|
268
289
|
emptyTitle="Nothing to copy — this run produced no text"
|
|
269
290
|
/>
|
|
291
|
+
{showActions && onFork && forkTargetId && (
|
|
292
|
+
<button type="button" className="flex items-center hover:text-ink transition-colors p-1 rounded hover:bg-ink/5 cursor-pointer" title="Fork from here" aria-label="Fork session from this answer" onClick={handleFork}>
|
|
293
|
+
<GitFork size={12} />
|
|
294
|
+
</button>
|
|
295
|
+
)}
|
|
270
296
|
{showActions && (
|
|
271
297
|
<button type="button" className="flex items-center hover:text-ink transition-colors p-1 rounded hover:bg-ink/5 cursor-pointer" title="New Chat from here" aria-label="Start new chat from this answer" onClick={handleNewChat}>
|
|
272
298
|
<MessageSquarePlus size={12} />
|
|
@@ -10,13 +10,11 @@ import { GeneratingIndicator } from '@/client/components/workspace/chat-timeline
|
|
|
10
10
|
import { resolveRunFooters, streamingRowIndex } from '@/shared/lib/chat/timeline/run-footer';
|
|
11
11
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
12
12
|
import {
|
|
13
|
-
WaitingDependencyPicker,
|
|
14
13
|
waitingCandidates,
|
|
15
14
|
type WaitingCandidate,
|
|
16
15
|
} from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
17
16
|
import { Hourglass } from 'lucide-preact';
|
|
18
|
-
import {
|
|
19
|
-
import { WorktreePicker } from '@/client/components/workspace/chat-timeline/target-picker/WorktreePicker';
|
|
17
|
+
import { DraftTargetRow } from '@/client/components/workspace/chat-timeline/target-picker/DraftTargetRow';
|
|
20
18
|
import type { SpawnTarget } from '@/client/hooks/chat/timeline/spawn-target';
|
|
21
19
|
|
|
22
20
|
interface EmptyWorkspacePromptProps {
|
|
@@ -74,6 +72,12 @@ interface EmptyWorkspacePromptProps {
|
|
|
74
72
|
*/
|
|
75
73
|
spawnTarget?: SpawnTarget | null;
|
|
76
74
|
onSpawnTargetChange?: (next: SpawnTarget | null) => void;
|
|
75
|
+
/** The session this chat runs UNDER, or null for a top-level chat. */
|
|
76
|
+
parentSessionId?: string | null;
|
|
77
|
+
onParentSessionChange?: (sessionId: string | null) => void;
|
|
78
|
+
/** "Parent session" for a child, "Fork from" for a fork. */
|
|
79
|
+
branchLabel?: string;
|
|
80
|
+
branchAllowNone?: boolean;
|
|
77
81
|
/** Reports a worktree the composer created or failed to create. */
|
|
78
82
|
onWorktreeReport?: (message: string) => void;
|
|
79
83
|
/** The "wait for session" pick, persisted per chat. */
|
|
@@ -126,6 +130,10 @@ export function EmptyWorkspacePrompt({
|
|
|
126
130
|
titleForSession,
|
|
127
131
|
spawnTarget = null,
|
|
128
132
|
onSpawnTargetChange,
|
|
133
|
+
parentSessionId = null,
|
|
134
|
+
onParentSessionChange,
|
|
135
|
+
branchLabel,
|
|
136
|
+
branchAllowNone,
|
|
129
137
|
onWorktreeReport,
|
|
130
138
|
waitingFor = null,
|
|
131
139
|
onWaitingForChange,
|
|
@@ -295,42 +303,23 @@ export function EmptyWorkspacePrompt({
|
|
|
295
303
|
{/* Workspace Selection Seamless Dropdown (No border, transparent
|
|
296
304
|
background). A chat with rows keeps its target and drops the
|
|
297
305
|
picker; this branch is only the chat that has not started. */}
|
|
298
|
-
<
|
|
299
|
-
{
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
{
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
setTarget={onSpawnTargetChange}
|
|
316
|
-
onReport={onWorktreeReport}
|
|
317
|
-
/>
|
|
318
|
-
)}
|
|
319
|
-
{/* The wait picker sits BESIDE the workspace picker, because both
|
|
320
|
-
answer the same question about the chat that has not started:
|
|
321
|
-
where it runs, and what it waits for. It only appears while
|
|
322
|
-
there is something to wait for (or a pick already made). */}
|
|
323
|
-
{onWaitingForChange && (waitingFor || candidates.length > 0) && (
|
|
324
|
-
<WaitingDependencyPicker
|
|
325
|
-
folders={folders}
|
|
326
|
-
streamStatusMap={streamStatusMap}
|
|
327
|
-
sessionId={null}
|
|
328
|
-
titleFor={titleForSession}
|
|
329
|
-
value={waitingFor}
|
|
330
|
-
onChange={onWaitingForChange}
|
|
331
|
-
/>
|
|
332
|
-
)}
|
|
333
|
-
</div>
|
|
306
|
+
<DraftTargetRow
|
|
307
|
+
folders={folders as WorkspaceFolderData[]}
|
|
308
|
+
selectedFolderId={selectedFolderId}
|
|
309
|
+
setSelectedFolderId={setSelectedFolderId}
|
|
310
|
+
spawnTarget={spawnTarget}
|
|
311
|
+
onSpawnTargetChange={onSpawnTargetChange}
|
|
312
|
+
onWorktreeReport={onWorktreeReport}
|
|
313
|
+
parentSessionId={parentSessionId}
|
|
314
|
+
onParentSessionChange={onParentSessionChange}
|
|
315
|
+
branchLabel={branchLabel}
|
|
316
|
+
branchAllowNone={branchAllowNone}
|
|
317
|
+
waitingFor={waitingFor}
|
|
318
|
+
onWaitingForChange={onWaitingForChange}
|
|
319
|
+
streamStatusMap={streamStatusMap}
|
|
320
|
+
titleForSession={titleForSession}
|
|
321
|
+
candidates={candidates}
|
|
322
|
+
/>
|
|
334
323
|
{/* A held prompt owns this chat until it is released: there is no
|
|
335
324
|
session to send a second prompt to, and a composer that looked live
|
|
336
325
|
would accept one that could not be delivered. */}
|
|
@@ -32,11 +32,11 @@ export interface MessageListProps {
|
|
|
32
32
|
onFork?: (msgId: string) => void;
|
|
33
33
|
isMobile?: boolean;
|
|
34
34
|
/**
|
|
35
|
-
* Whether chat-owning actions render: a USER row's Undo / New-chat,
|
|
36
|
-
* run footer's Retry / New-chat. All of them act on the CHAT
|
|
37
|
-
* turn, re-run it, branch a session from it), so a renderer
|
|
38
|
-
* the chat does not own — the BTW panel's side question and
|
|
39
|
-
* them off instead of showing buttons that do nothing.
|
|
35
|
+
* Whether chat-owning actions render: a USER row's Undo / Fork / New-chat,
|
|
36
|
+
* and the run footer's Retry / Fork / New-chat. All of them act on the CHAT
|
|
37
|
+
* (rewind a chat turn, re-run it, branch a session from it), so a renderer
|
|
38
|
+
* that draws rows the chat does not own — the BTW panel's side question and
|
|
39
|
+
* its answer — turns them off instead of showing buttons that do nothing.
|
|
40
40
|
*/
|
|
41
41
|
userActions?: boolean;
|
|
42
42
|
/**
|
|
@@ -162,6 +162,7 @@ export const MessageList = memo(function MessageList({
|
|
|
162
162
|
retryTargetId={inlineFooter.runUserId}
|
|
163
163
|
onRetry={onRetry}
|
|
164
164
|
onNewChat={onNewChat}
|
|
165
|
+
onFork={onFork}
|
|
165
166
|
isMobile={isMobile}
|
|
166
167
|
showActions={userActions}
|
|
167
168
|
/>
|
|
@@ -184,6 +185,7 @@ export const MessageList = memo(function MessageList({
|
|
|
184
185
|
retryTargetId={trailingFooter.runUserId}
|
|
185
186
|
onRetry={onRetry}
|
|
186
187
|
onNewChat={onNewChat}
|
|
188
|
+
onFork={onFork}
|
|
187
189
|
isMobile={isMobile}
|
|
188
190
|
showActions={userActions}
|
|
189
191
|
/>
|
|
@@ -63,6 +63,12 @@ export interface PendingChatViewProps {
|
|
|
63
63
|
/** Where the chat will run: the folder, or one of its worktrees. */
|
|
64
64
|
spawnTarget?: SpawnTarget | null;
|
|
65
65
|
onSpawnTargetChange?: (next: SpawnTarget | null) => void;
|
|
66
|
+
/** The session this chat runs under, or null for a top-level chat. */
|
|
67
|
+
parentSessionId?: string | null;
|
|
68
|
+
onParentSessionChange?: (sessionId: string | null) => void;
|
|
69
|
+
/** "Parent session" for a child, "Fork from" for a fork. */
|
|
70
|
+
branchLabel?: string;
|
|
71
|
+
branchAllowNone?: boolean;
|
|
66
72
|
onWorktreeReport?: (message: string) => void;
|
|
67
73
|
/**
|
|
68
74
|
* The harness this chat will spawn on, and the pick that writes it.
|
|
@@ -119,6 +125,10 @@ export function PendingChatView(props: PendingChatViewProps) {
|
|
|
119
125
|
onCancelWait={props.onCancelWait}
|
|
120
126
|
spawnTarget={props.spawnTarget}
|
|
121
127
|
onSpawnTargetChange={props.onSpawnTargetChange}
|
|
128
|
+
parentSessionId={props.parentSessionId}
|
|
129
|
+
onParentSessionChange={props.onParentSessionChange}
|
|
130
|
+
branchLabel={props.branchLabel}
|
|
131
|
+
branchAllowNone={props.branchAllowNone}
|
|
122
132
|
onWorktreeReport={props.onWorktreeReport}
|
|
123
133
|
{...(props.harness ? { harness: props.harness } : {})}
|
|
124
134
|
harnessEditable={props.harnessEditable}
|
|
@@ -31,12 +31,18 @@ interface RunFooterProps {
|
|
|
31
31
|
retryTargetId?: string;
|
|
32
32
|
onRetry?: (msgId: string) => void;
|
|
33
33
|
onNewChat?: (content: string, attachments?: Attachment[]) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Branch the session from this answer. The anchor is the run's owner row
|
|
36
|
+
* (`msg.id`), never `retryTargetId`: the opening user row would fork BEFORE
|
|
37
|
+
* the answer, while the footer sits under it.
|
|
38
|
+
*/
|
|
39
|
+
onFork?: (msgId: string) => void;
|
|
34
40
|
/** Mobile uses a compact provider/model footer with a bottom-sheet menu. */
|
|
35
41
|
isMobile?: boolean;
|
|
36
42
|
/**
|
|
37
|
-
* Whether the footer offers Retry / New-chat.
|
|
38
|
-
* footer describing a row the chat does not own (the BTW panel's
|
|
39
|
-
* turns them off rather than rendering dead buttons.
|
|
43
|
+
* Whether the footer offers Retry / Fork / New-chat. All of them act on the
|
|
44
|
+
* CHAT, so a footer describing a row the chat does not own (the BTW panel's
|
|
45
|
+
* side answer) turns them off rather than rendering dead buttons.
|
|
40
46
|
*/
|
|
41
47
|
showActions?: boolean;
|
|
42
48
|
}
|
|
@@ -60,6 +66,7 @@ export function RunFooter({
|
|
|
60
66
|
retryTargetId,
|
|
61
67
|
onRetry,
|
|
62
68
|
onNewChat,
|
|
69
|
+
onFork,
|
|
63
70
|
isMobile = false,
|
|
64
71
|
showActions = true,
|
|
65
72
|
}: RunFooterProps) {
|
|
@@ -78,6 +85,8 @@ export function RunFooter({
|
|
|
78
85
|
msgId={retryTargetId || msg.id}
|
|
79
86
|
onRetry={onRetry}
|
|
80
87
|
onNewChat={onNewChat}
|
|
88
|
+
forkTargetId={msg.id}
|
|
89
|
+
onFork={onFork}
|
|
81
90
|
isMobile={isMobile}
|
|
82
91
|
showActions={showActions}
|
|
83
92
|
/>
|
|
@@ -111,6 +111,8 @@ export function AttachmentToolbar({ attachments, onFilesSelected, onRemove, mode
|
|
|
111
111
|
onOpenGoal={onOpenGoal}
|
|
112
112
|
planAvailable={modes.planAvailable}
|
|
113
113
|
goalAvailable={modes.goalAvailable}
|
|
114
|
+
mode={modes.sessionMode ?? null}
|
|
115
|
+
onSelectMode={modes.onSelectSessionMode}
|
|
114
116
|
/>
|
|
115
117
|
</div>
|
|
116
118
|
)}
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
import { ClipboardList, Target } from 'lucide-preact';
|
|
31
31
|
import type { GoalRecord } from '@/shared/lib/omp/mode/types';
|
|
32
32
|
import type { ArmedGoal } from '@/shared/lib/omp/mode/actions';
|
|
33
|
+
import type { SessionModeState } from '@/shared/lib/harness/session-modes';
|
|
34
|
+
import { SessionModeDropdown } from '@/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown';
|
|
33
35
|
|
|
34
36
|
export interface ModeTogglesProps {
|
|
35
37
|
plan: boolean;
|
|
@@ -49,6 +51,10 @@ export interface ModeTogglesProps {
|
|
|
49
51
|
/** Whether Goal is offered at all: a non-omp ACP agent has no `/kabmo-mode`
|
|
50
52
|
* extension, so the button could only produce a refusal. */
|
|
51
53
|
goalAvailable: boolean;
|
|
54
|
+
/** The agent's own mode selector. When it has more than one value the
|
|
55
|
+
* dropdown replaces the Plan button, so plan is still reachable. */
|
|
56
|
+
mode?: SessionModeState | null;
|
|
57
|
+
onSelectMode?: (value: string) => void;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
/** omp's own footer shows goal token usage beside the mode indicator; that
|
|
@@ -73,10 +79,18 @@ export function ModeToggles({
|
|
|
73
79
|
onOpenGoal,
|
|
74
80
|
planAvailable,
|
|
75
81
|
goalAvailable,
|
|
82
|
+
mode,
|
|
83
|
+
onSelectMode,
|
|
76
84
|
}: ModeTogglesProps) {
|
|
85
|
+
// More than one mode: the dropdown can express every value, including plan,
|
|
86
|
+
// so the single-purpose Plan button would be a second control for one item.
|
|
87
|
+
const hasModeMenu = Boolean(mode && mode.values.length > 1 && onSelectMode);
|
|
77
88
|
return (
|
|
78
89
|
<div className="flex items-center gap-0.5">
|
|
79
|
-
{
|
|
90
|
+
{hasModeMenu && mode && onSelectMode && (
|
|
91
|
+
<SessionModeDropdown mode={mode} pending={pending} onSelect={onSelectMode} />
|
|
92
|
+
)}
|
|
93
|
+
{!hasModeMenu && planAvailable && (
|
|
80
94
|
<button
|
|
81
95
|
type="button"
|
|
82
96
|
onClick={() => onTogglePlan(!plan)}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ACP mode chip: hidden when there is nothing to choose, and it reports the
|
|
8
|
+
* chosen value. Rendered with `h()` against happy-dom.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
12
|
+
import { Window } from 'happy-dom';
|
|
13
|
+
import { h, render } from 'preact';
|
|
14
|
+
import { act } from 'preact/test-utils';
|
|
15
|
+
import { SessionModeDropdown } from '@/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown';
|
|
16
|
+
import type { SessionModeState } from '@/shared/lib/harness/session-modes';
|
|
17
|
+
|
|
18
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
19
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
20
|
+
|
|
21
|
+
let container: HTMLElement | undefined;
|
|
22
|
+
|
|
23
|
+
const TWO_MODES: SessionModeState = {
|
|
24
|
+
currentValue: 'ask',
|
|
25
|
+
values: [{ value: 'ask', name: 'Ask' }, { value: 'code', name: 'Code' }],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
beforeAll(() => {
|
|
29
|
+
const win = new Window({ url: 'http://localhost' });
|
|
30
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
31
|
+
for (const key of DOM_GLOBALS) {
|
|
32
|
+
if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
|
|
33
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterAll(() => {
|
|
38
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
39
|
+
for (const key of DOM_GLOBALS) {
|
|
40
|
+
if (nativeGlobals[key] === undefined) delete target[key];
|
|
41
|
+
else target[key] = nativeGlobals[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
if (container) render(null, container);
|
|
47
|
+
container?.remove();
|
|
48
|
+
container = undefined;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
async function mount(mode: SessionModeState | null, onSelect: (value: string) => void = () => {}) {
|
|
52
|
+
container ??= document.body.appendChild(document.createElement('div'));
|
|
53
|
+
await act(async () => {
|
|
54
|
+
render(h(SessionModeDropdown, { mode, pending: false, onSelect }), container as HTMLElement);
|
|
55
|
+
});
|
|
56
|
+
return container;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('SessionModeDropdown', () => {
|
|
60
|
+
test('renders nothing for a harness with no selector or one value', async () => {
|
|
61
|
+
expect((await mount(null)).textContent).toBe('');
|
|
62
|
+
await mount({ currentValue: 'ask', values: [{ value: 'ask', name: 'Ask' }] });
|
|
63
|
+
expect(container?.textContent).toBe('');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('names the current mode and reports a pick', async () => {
|
|
67
|
+
const picks: string[] = [];
|
|
68
|
+
const el = await mount(TWO_MODES, (value) => picks.push(value));
|
|
69
|
+
const trigger = el.querySelector('button[aria-haspopup="listbox"]');
|
|
70
|
+
expect(trigger?.getAttribute('aria-label')).toBe('Session mode: Ask');
|
|
71
|
+
|
|
72
|
+
await act(async () => {
|
|
73
|
+
(trigger as HTMLButtonElement).click();
|
|
74
|
+
});
|
|
75
|
+
const options = el.querySelectorAll('[role="option"]');
|
|
76
|
+
expect(options).toHaveLength(2);
|
|
77
|
+
expect(options[0]?.getAttribute('aria-selected')).toBe('true');
|
|
78
|
+
|
|
79
|
+
await act(async () => {
|
|
80
|
+
(options[1] as HTMLButtonElement).click();
|
|
81
|
+
});
|
|
82
|
+
expect(picks).toEqual(['code']);
|
|
83
|
+
expect(el.querySelector('[role="listbox"]')).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
});
|