@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
|
@@ -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
|
/>
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
|
|
17
17
|
import type { Attachment, ChatMessageData, WorkspaceFolderData } from '@/shared/types';
|
|
18
18
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
19
|
+
import type { ForkPreview } from '@/client/hooks/chat/timeline/fork-preview';
|
|
19
20
|
import type { ComposerModes } from '@/client/components/workspace/chat-timeline/chat-input/modes-props';
|
|
20
21
|
import type { WaitingCandidate } from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
21
22
|
import type { DeferredModelStore } from '@/client/hooks/chat/timeline/deferred-model';
|
|
22
23
|
import { EmptyWorkspacePrompt } from '@/client/components/workspace/chat-timeline/EmptyWorkspacePrompt';
|
|
23
24
|
import type { SpawnTarget } from '@/client/hooks/chat/timeline/spawn-target';
|
|
25
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
24
26
|
|
|
25
27
|
export interface PendingChatViewProps {
|
|
26
28
|
className: string;
|
|
@@ -63,7 +65,20 @@ export interface PendingChatViewProps {
|
|
|
63
65
|
/** Where the chat will run: the folder, or one of its worktrees. */
|
|
64
66
|
spawnTarget?: SpawnTarget | null;
|
|
65
67
|
onSpawnTargetChange?: (next: SpawnTarget | null) => void;
|
|
66
|
-
|
|
68
|
+
/** The session this chat runs under, or null for a top-level chat. */
|
|
69
|
+
parentSessionId?: string | null;
|
|
70
|
+
onParentSessionChange?: (sessionId: string | null) => void;
|
|
71
|
+
/** "Parent session" for a child, "Fork from" for a fork. */
|
|
72
|
+
branchLabel?: string;
|
|
73
|
+
branchAllowNone?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The source transcript a FORK will carry, rendered above the composer so the
|
|
76
|
+
* operator composes the first turn with the history it continues in sight. The
|
|
77
|
+
* same prop keeps the branch picker reachable while the transcript is docked:
|
|
78
|
+
* switching "Fork from" swaps the rows, because the composer has not sent yet.
|
|
79
|
+
*/
|
|
80
|
+
branchPreview?: ForkPreview | null;
|
|
81
|
+
onWorktreeReport?: (message: string, tone?: ToastTone) => void;
|
|
67
82
|
/**
|
|
68
83
|
* The harness this chat will spawn on, and the pick that writes it.
|
|
69
84
|
*
|
|
@@ -119,6 +134,11 @@ export function PendingChatView(props: PendingChatViewProps) {
|
|
|
119
134
|
onCancelWait={props.onCancelWait}
|
|
120
135
|
spawnTarget={props.spawnTarget}
|
|
121
136
|
onSpawnTargetChange={props.onSpawnTargetChange}
|
|
137
|
+
parentSessionId={props.parentSessionId}
|
|
138
|
+
onParentSessionChange={props.onParentSessionChange}
|
|
139
|
+
branchLabel={props.branchLabel}
|
|
140
|
+
branchAllowNone={props.branchAllowNone}
|
|
141
|
+
{...(props.branchPreview ? { branchPreview: props.branchPreview } : {})}
|
|
122
142
|
onWorktreeReport={props.onWorktreeReport}
|
|
123
143
|
{...(props.harness ? { harness: props.harness } : {})}
|
|
124
144
|
harnessEditable={props.harnessEditable}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The pending chat's rows: the optimistic turn (`messages`) under the history a
|
|
8
|
+
* FORK inherits (`preview`), in source order.
|
|
9
|
+
*
|
|
10
|
+
* Split from `EmptyWorkspacePrompt` for the per-file ceiling; that file keeps
|
|
11
|
+
* the frame (target row, scroller, dock, composer) and this one owns what is
|
|
12
|
+
* drawn inside the scroller, so the two run-footer rules — one for rows this
|
|
13
|
+
* page mounted, none for the source's own rows — stay in one place.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { Fragment } from 'preact';
|
|
17
|
+
import { useMemo } from 'preact/hooks';
|
|
18
|
+
import type { Attachment, ChatMessageData } from '@/shared/types';
|
|
19
|
+
import { ChatMessageItem } from '@/client/components/workspace/chat-timeline/MessageItem';
|
|
20
|
+
import { RunFooter } from '@/client/components/workspace/chat-timeline/RunFooter';
|
|
21
|
+
import { resolveRunFooters, streamingRowIndex } from '@/shared/lib/chat/timeline/run-footer';
|
|
22
|
+
import type { ForkPreview } from '@/client/hooks/chat/timeline/fork-preview';
|
|
23
|
+
|
|
24
|
+
export interface PendingTranscriptProps {
|
|
25
|
+
/** Rows this chat mounted itself (the optimistic turn). */
|
|
26
|
+
messages: ChatMessageData[];
|
|
27
|
+
/** The branch's inherited history; present only for a pending fork. */
|
|
28
|
+
preview?: ForkPreview | null;
|
|
29
|
+
isGenerating: boolean;
|
|
30
|
+
isMobile: boolean;
|
|
31
|
+
provider?: string;
|
|
32
|
+
providerNames?: Record<string, string>;
|
|
33
|
+
modelName?: string;
|
|
34
|
+
modelNames?: Record<string, string>;
|
|
35
|
+
sessionThinkingLevel?: string | null;
|
|
36
|
+
harness?: string;
|
|
37
|
+
onUndo?: (id: string, content?: string) => void;
|
|
38
|
+
onRetry?: (id: string) => void;
|
|
39
|
+
onNewChat?: (content: string, attachments?: Attachment[]) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function PendingTranscript({
|
|
43
|
+
messages,
|
|
44
|
+
preview = null,
|
|
45
|
+
isGenerating,
|
|
46
|
+
isMobile,
|
|
47
|
+
provider,
|
|
48
|
+
providerNames,
|
|
49
|
+
modelName,
|
|
50
|
+
modelNames,
|
|
51
|
+
sessionThinkingLevel,
|
|
52
|
+
harness,
|
|
53
|
+
onUndo,
|
|
54
|
+
onRetry,
|
|
55
|
+
onNewChat,
|
|
56
|
+
}: PendingTranscriptProps) {
|
|
57
|
+
const previewMessages = preview?.messages ?? [];
|
|
58
|
+
const { streamingIdx, footers } = useMemo(
|
|
59
|
+
() => ({
|
|
60
|
+
streamingIdx: streamingRowIndex(messages),
|
|
61
|
+
footers: resolveRunFooters(messages, isGenerating),
|
|
62
|
+
}),
|
|
63
|
+
[messages, isGenerating],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="chat-column">
|
|
68
|
+
{/* The branch's own history, read-only: these rows belong to the SOURCE
|
|
69
|
+
session, so their Undo / Fork / New-chat actions would act on this
|
|
70
|
+
pending chat and do nothing. No run footer either — the model stamp on
|
|
71
|
+
screen must be the source's, and the fork has not run. */}
|
|
72
|
+
{previewMessages.map((msg, idx) => {
|
|
73
|
+
const prev = previewMessages[idx - 1];
|
|
74
|
+
const isAiFragment = msg.role !== 'user' && prev && prev.role !== 'user';
|
|
75
|
+
return (
|
|
76
|
+
<ChatMessageItem
|
|
77
|
+
key={msg.id}
|
|
78
|
+
msg={msg}
|
|
79
|
+
userActions={false}
|
|
80
|
+
isPrevAssistant={Boolean(prev && prev.role !== 'user')}
|
|
81
|
+
isMobile={isMobile}
|
|
82
|
+
className={isAiFragment ? 'mt-1' : 'mt-8'}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
})}
|
|
86
|
+
{preview?.loading && previewMessages.length === 0 && (
|
|
87
|
+
<div className="mt-8 text-xs text-ink/40">Loading the source transcript…</div>
|
|
88
|
+
)}
|
|
89
|
+
{preview?.error && (
|
|
90
|
+
<div className="mt-8 text-xs text-[var(--theme-error)]">
|
|
91
|
+
Could not read the source transcript: {preview.error}
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
{messages.map((msg, idx) => {
|
|
95
|
+
const prev = messages[idx - 1];
|
|
96
|
+
const isLoading = isGenerating && idx === streamingIdx && msg.role === 'ai';
|
|
97
|
+
const isAiFragment = msg.role !== 'user' && prev && prev.role !== 'user';
|
|
98
|
+
const footer = footers[idx];
|
|
99
|
+
return (
|
|
100
|
+
<Fragment key={msg.id}>
|
|
101
|
+
<ChatMessageItem
|
|
102
|
+
msg={msg}
|
|
103
|
+
isStreaming={isLoading}
|
|
104
|
+
onUndo={onUndo}
|
|
105
|
+
onNewChat={onNewChat}
|
|
106
|
+
isMobile={isMobile}
|
|
107
|
+
className={isAiFragment ? 'mt-1' : 'mt-8'}
|
|
108
|
+
/>
|
|
109
|
+
{footer && (
|
|
110
|
+
<RunFooter
|
|
111
|
+
msg={footer.msg}
|
|
112
|
+
provider={provider}
|
|
113
|
+
providerNames={providerNames}
|
|
114
|
+
modelName={modelName}
|
|
115
|
+
modelNames={modelNames}
|
|
116
|
+
thinkingLevel={sessionThinkingLevel ?? undefined}
|
|
117
|
+
{...(harness ? { harness } : {})}
|
|
118
|
+
durationMs={footer.durationMs}
|
|
119
|
+
answerText={footer.answerText}
|
|
120
|
+
retryTargetId={footer.runUserId}
|
|
121
|
+
onRetry={onRetry}
|
|
122
|
+
onNewChat={onNewChat}
|
|
123
|
+
/>
|
|
124
|
+
)}
|
|
125
|
+
</Fragment>
|
|
126
|
+
);
|
|
127
|
+
})}
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ACP agent's own session-mode selector.
|
|
8
|
+
*
|
|
9
|
+
* ACP exposes modes as a `mode`-category config option (the older `modes` list
|
|
10
|
+
* is normalized into the same shape server-side). Kabmo's Plan toggle only
|
|
11
|
+
* names one value; an agent that offers `ask`/`code`/`architect` needs the whole
|
|
12
|
+
* list. The control is hidden when there is nothing to choose — null for omp,
|
|
13
|
+
* or a one-value ladder — and `ModeToggles` then keeps the Plan button.
|
|
14
|
+
*
|
|
15
|
+
* The popover mirrors `AccessDropdown`: a chip, a list, a check on the current
|
|
16
|
+
* value, and dismissal on outside press.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { useRef, useState } from 'preact/hooks';
|
|
20
|
+
import { Check, Layers } from 'lucide-preact';
|
|
21
|
+
import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
|
|
22
|
+
import type { SessionModeState } from '@/shared/lib/harness/session-modes';
|
|
23
|
+
|
|
24
|
+
export interface SessionModeDropdownProps {
|
|
25
|
+
mode: SessionModeState | null;
|
|
26
|
+
/** A mode command is in flight; the chip reads as pending, not dead. */
|
|
27
|
+
pending: boolean;
|
|
28
|
+
onSelect: (value: string) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function SessionModeDropdown({ mode, pending, onSelect }: SessionModeDropdownProps) {
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
34
|
+
useOnClickOutside(ref, () => setOpen(false));
|
|
35
|
+
|
|
36
|
+
if (!mode || mode.values.length < 2) return null;
|
|
37
|
+
const current = mode.values.find((choice) => choice.value === mode.currentValue);
|
|
38
|
+
const label = current?.name ?? mode.currentValue;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className="relative" ref={ref}>
|
|
42
|
+
<button
|
|
43
|
+
type="button"
|
|
44
|
+
onClick={() => setOpen((value) => !value)}
|
|
45
|
+
disabled={pending}
|
|
46
|
+
aria-haspopup="listbox"
|
|
47
|
+
aria-expanded={open}
|
|
48
|
+
aria-label={`Session mode: ${label}`}
|
|
49
|
+
title={`Session mode: ${label}`}
|
|
50
|
+
className="tap-chip flex items-center space-x-1 hover:bg-ink/5 px-2 py-1 rounded transition-colors text-xs text-muted disabled:opacity-60 disabled:cursor-wait"
|
|
51
|
+
>
|
|
52
|
+
<Layers size={12} className="text-ink/60" />
|
|
53
|
+
<span className="hidden @[420px]:inline max-w-[9rem] truncate">{label}</span>
|
|
54
|
+
</button>
|
|
55
|
+
{open && (
|
|
56
|
+
<div
|
|
57
|
+
role="listbox"
|
|
58
|
+
aria-label="Session mode"
|
|
59
|
+
className="glass-popover absolute bottom-full left-0 mb-1 w-44 bg-paper border border-ink/20 rounded-md shadow-lg z-50 py-1 text-xs"
|
|
60
|
+
>
|
|
61
|
+
<div className="px-3 py-1 text-[10px] uppercase tracking-wider text-ink/40 font-semibold mb-1">
|
|
62
|
+
Session Mode
|
|
63
|
+
</div>
|
|
64
|
+
{mode.values.map((choice) => (
|
|
65
|
+
<button
|
|
66
|
+
key={choice.value}
|
|
67
|
+
type="button"
|
|
68
|
+
role="option"
|
|
69
|
+
aria-selected={choice.value === mode.currentValue}
|
|
70
|
+
onClick={() => {
|
|
71
|
+
setOpen(false);
|
|
72
|
+
onSelect(choice.value);
|
|
73
|
+
}}
|
|
74
|
+
className="w-full text-left px-3 py-1.5 hover:bg-ink/5 flex items-center justify-between gap-2 transition-colors"
|
|
75
|
+
>
|
|
76
|
+
<span className="truncate">{choice.name}</span>
|
|
77
|
+
{choice.value === mode.currentValue && <Check size={12} className="text-ink shrink-0" />}
|
|
78
|
+
</button>
|
|
79
|
+
))}
|
|
80
|
+
</div>
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { GoalContinuation, GoalRecord } from '@/shared/lib/omp/mode/types';
|
|
16
16
|
import type { ArmedGoal, GoalAction } from '@/shared/lib/omp/mode/actions';
|
|
17
17
|
import type { GoalActionResult } from '@/client/hooks/chat/timeline/goal-command';
|
|
18
|
+
import type { SessionModeState } from '@/shared/lib/harness/session-modes';
|
|
18
19
|
|
|
19
20
|
export interface ComposerModes {
|
|
20
21
|
plan: boolean;
|
|
@@ -48,6 +49,10 @@ export interface ComposerModes {
|
|
|
48
49
|
* button could only refuse.
|
|
49
50
|
*/
|
|
50
51
|
goalAvailable: boolean;
|
|
52
|
+
/** The agent's own mode selector (ACP), or null when it publishes none. */
|
|
53
|
+
sessionMode?: SessionModeState | null;
|
|
54
|
+
/** Move the agent's mode selector. */
|
|
55
|
+
onSelectSessionMode?: (value: string) => void;
|
|
51
56
|
/**
|
|
52
57
|
* The last mode-command refusal, from either side of the wire (the route's
|
|
53
58
|
* error, or a `KABMO_MODE_ERROR` from the extension). The composer renders
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The fork composer draws the history it is about to continue.
|
|
8
|
+
*
|
|
9
|
+
* A fork opens as an empty `new-…` chat, so the pending composer was the whole
|
|
10
|
+
* screen: the operator chose the branch's first turn with none of the source
|
|
11
|
+
* transcript in sight, and after moving "Fork from" the previous source's rows
|
|
12
|
+
* were all there was. Asserted from the mounted surface:
|
|
13
|
+
*
|
|
14
|
+
* - the preview rows render above the composer;
|
|
15
|
+
* - the "Fork from" picker stays reachable WHILE those rows are drawn (the
|
|
16
|
+
* docked branch used to drop the target row), and choosing another session
|
|
17
|
+
* reports it, which is what swaps the transcript.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
21
|
+
import { Window } from 'happy-dom';
|
|
22
|
+
import { h, render } from 'preact';
|
|
23
|
+
import { act } from 'preact/test-utils';
|
|
24
|
+
|
|
25
|
+
import { EmptyWorkspacePrompt } from '@/client/components/workspace/chat-timeline/EmptyWorkspacePrompt';
|
|
26
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
27
|
+
import { silenceRealtime, restoreRealtime } from '@/test-support/silent-socket';
|
|
28
|
+
import type { ChatMessageData, WorkspaceFolderData } from '@/shared/types';
|
|
29
|
+
|
|
30
|
+
let container: HTMLElement;
|
|
31
|
+
/** The runner's own fetch: a stub left installed poisons every later suite. */
|
|
32
|
+
const originalFetch = Bun.fetch;
|
|
33
|
+
|
|
34
|
+
beforeAll(() => {
|
|
35
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
36
|
+
(globalThis as unknown as Record<string, unknown>).getComputedStyle = window.getComputedStyle.bind(window);
|
|
37
|
+
});
|
|
38
|
+
afterAll(() => restoreDomGlobals());
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
silenceRealtime();
|
|
42
|
+
// Only the composer's catalog reads are answered; nothing here asserts them.
|
|
43
|
+
globalThis.fetch = (async () => Response.json({})) as unknown as typeof fetch;
|
|
44
|
+
container = document.createElement('div');
|
|
45
|
+
document.body.appendChild(container);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
globalThis.fetch = originalFetch;
|
|
50
|
+
render(null, container);
|
|
51
|
+
container.remove();
|
|
52
|
+
restoreRealtime();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const SOURCE_ROWS: ChatMessageData[] = [
|
|
56
|
+
{ id: 'u1', role: 'user', content: 'source question' },
|
|
57
|
+
{ id: 'a1', role: 'ai', content: 'source answer' },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const FOLDERS = [{
|
|
61
|
+
id: 1,
|
|
62
|
+
name: 'kabmo',
|
|
63
|
+
isExpanded: true,
|
|
64
|
+
sessions: [
|
|
65
|
+
{ id: 'sess-a', title: 'Branch A', folder_id: 1, is_archived: 0 },
|
|
66
|
+
{ id: 'sess-b', title: 'Branch B', folder_id: 1, is_archived: 0 },
|
|
67
|
+
],
|
|
68
|
+
hasMore: false,
|
|
69
|
+
totalSessions: 2,
|
|
70
|
+
}] as unknown as WorkspaceFolderData[];
|
|
71
|
+
|
|
72
|
+
function mount(props: Record<string, unknown>) {
|
|
73
|
+
act(() => {
|
|
74
|
+
render(h(EmptyWorkspacePrompt, {
|
|
75
|
+
folders: FOLDERS,
|
|
76
|
+
selectedFolderId: 1,
|
|
77
|
+
setSelectedFolderId: () => {},
|
|
78
|
+
inputValue: '',
|
|
79
|
+
setInputValue: () => {},
|
|
80
|
+
onSend: () => {},
|
|
81
|
+
isGenerating: false,
|
|
82
|
+
accessMode: 'always-ask',
|
|
83
|
+
onAccessModeChange: () => {},
|
|
84
|
+
composerModelRef: { current: null },
|
|
85
|
+
deferredComposerPickRef: { current: null },
|
|
86
|
+
parentSessionId: 'sess-a',
|
|
87
|
+
onParentSessionChange: () => {},
|
|
88
|
+
branchLabel: 'Fork from',
|
|
89
|
+
branchAllowNone: false,
|
|
90
|
+
branchPreview: { messages: SOURCE_ROWS, loading: false, error: null },
|
|
91
|
+
...props,
|
|
92
|
+
} as never), container);
|
|
93
|
+
});
|
|
94
|
+
return container;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function settle(): Promise<void> {
|
|
98
|
+
// The mocked catalog reads resolve through microtasks; drain them instead of
|
|
99
|
+
// waiting on a wall clock.
|
|
100
|
+
await act(async () => {
|
|
101
|
+
for (let tick = 0; tick < 8; tick += 1) await Promise.resolve();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
describe('fork preview in the pending composer', () => {
|
|
106
|
+
test('the source transcript renders above an otherwise empty chat', async () => {
|
|
107
|
+
const el = mount({});
|
|
108
|
+
await settle();
|
|
109
|
+
expect(el.textContent).toContain('source question');
|
|
110
|
+
// The assistant row is rendered through the answer renderer, which
|
|
111
|
+
// capitalizes the first letter; what matters is the row is there.
|
|
112
|
+
expect(el.textContent).toMatch(/source answer/i);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('preview rows belong to the source: no chat-owning actions on them', async () => {
|
|
116
|
+
const el = mount({});
|
|
117
|
+
await settle();
|
|
118
|
+
expect(el.querySelector('[aria-label="Fork this session from this message"]')).toBeNull();
|
|
119
|
+
expect(el.querySelector('[aria-label="Undo this message"]')).toBeNull();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('"Fork from" stays reachable while the preview is docked, and reports a new source', async () => {
|
|
123
|
+
const picked: string[] = [];
|
|
124
|
+
const el = mount({ onParentSessionChange: (id: string | null) => picked.push(String(id)) });
|
|
125
|
+
await settle();
|
|
126
|
+
|
|
127
|
+
const trigger = el.querySelector('[data-testid="parent-session-picker"]');
|
|
128
|
+
expect(trigger, 'the fork picker disappeared once the preview docked').not.toBeNull();
|
|
129
|
+
act(() => {
|
|
130
|
+
(trigger as HTMLElement).dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
|
|
131
|
+
});
|
|
132
|
+
await settle();
|
|
133
|
+
|
|
134
|
+
const other = el.querySelector('[data-testid="parent-candidate"][data-session-id="sess-b"]');
|
|
135
|
+
expect(other, 'the other source is not offered').not.toBeNull();
|
|
136
|
+
act(() => {
|
|
137
|
+
(other as HTMLElement).dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
|
|
138
|
+
});
|
|
139
|
+
expect(picked).toEqual(['sess-b']);
|
|
140
|
+
});
|
|
141
|
+
});
|