@kabmo-labs/kabmo 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +440 -436
- package/dist/client/static/js/{index-ga8cbpt4.js → index-95b3n20k.js} +945 -945
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/session-actions-menu/index.tsx +38 -12
- package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
- package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
- package/src/client/components/common/session-branch/index.tsx +169 -0
- package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
- package/src/client/components/common/session-branch/style.ts +29 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +15 -3
- package/src/client/components/common/session-row/index.tsx +24 -25
- package/src/client/components/common/session-row/session-row.test.tsx +11 -0
- package/src/client/components/common/session-state-provider/index.tsx +1 -1
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +64 -68
- package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
- package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +33 -30
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -13
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +59 -57
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +57 -61
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +28 -39
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +10 -21
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/hooks/chat/composer/items.test.ts +19 -0
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
- package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
- package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
- package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
- package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
- package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
- package/src/client/hooks/chat/omp/run-switch.ts +1 -1
- package/src/client/hooks/chat/omp/session-list.tsx +4 -0
- package/src/client/hooks/chat/subagents/roster.ts +122 -0
- package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
- package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
- package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
- package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
- package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
- package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
- package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
- package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
- package/src/client/hooks/chat/timeline/modes.ts +42 -29
- package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
- package/src/client/hooks/chat/timeline/send.ts +17 -103
- package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +40 -31
- package/src/client/hooks/models/use-harness-update.test.ts +137 -44
- package/src/client/hooks/models/use-harness-update.ts +133 -85
- package/src/client/hooks/ui/input-required-alert.ts +12 -5
- package/src/client/hooks/ui/notifications.ts +45 -0
- package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/lib/native/open-session.ts +33 -0
- package/src/client/lib/notifications/os.test.ts +125 -0
- package/src/client/lib/notifications/os.ts +130 -0
- package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
- package/src/client/lib/router/open-session.test.ts +75 -0
- package/src/client/lib/router/open-session.ts +34 -0
- package/src/client/lib/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/server/lib/db/schema.ts +1 -0
- package/src/server/lib/harness/acp/calls.ts +15 -1
- package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
- package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
- package/src/server/lib/harness/acp/client-fs.ts +131 -0
- package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
- package/src/server/lib/harness/acp/client-initialize.ts +84 -0
- package/src/server/lib/harness/acp/client.ts +31 -21
- package/src/server/lib/harness/acp/commands.test.ts +5 -5
- package/src/server/lib/harness/acp/commands.ts +14 -2
- package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
- package/src/server/lib/harness/acp/frames.ts +71 -158
- package/src/server/lib/harness/acp/mapper.test.ts +40 -0
- package/src/server/lib/harness/acp/mapper.ts +12 -0
- package/src/server/lib/harness/acp/permissions.ts +6 -0
- package/src/server/lib/harness/acp/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
- package/src/server/lib/harness/acp/session-handshake.ts +83 -6
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- package/src/server/lib/harness/acp/session-notifications.ts +41 -2
- package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
- package/src/server/lib/harness/acp/session-permissions.ts +36 -0
- package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
- package/src/server/lib/harness/acp/session-requests.ts +48 -6
- package/src/server/lib/harness/acp/session-turns.ts +8 -3
- package/src/server/lib/harness/acp/session-usage.ts +4 -0
- package/src/server/lib/harness/acp/session-web-state.ts +30 -2
- package/src/server/lib/harness/acp/session.test-util.ts +19 -1
- package/src/server/lib/harness/acp/session.ts +60 -60
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +102 -0
- package/src/server/lib/harness/acp/turn.ts +81 -6
- package/src/server/lib/harness/acp/v2.test.ts +144 -0
- package/src/server/lib/harness/acp/v2.ts +220 -0
- package/src/server/lib/harness/acp/verbs.ts +46 -6
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +21 -9
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/update-job-store.test.ts +37 -12
- package/src/server/lib/harness/update-job-store.ts +22 -16
- package/src/server/lib/harness/update-job.server.ts +66 -175
- package/src/server/lib/harness/update-queue.server.ts +292 -0
- package/src/server/lib/harness/update-queue.test.ts +265 -0
- package/src/server/lib/harness/update-spawn.server.ts +96 -0
- package/src/server/lib/harness/update-worker.ts +8 -3
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +14 -9
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
- package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
- package/src/server/lib/sessions/fork.server.test.ts +68 -0
- package/src/server/lib/sessions/fork.server.ts +31 -6
- package/src/server/lib/sessions/spawn.server.test.ts +41 -0
- package/src/server/lib/sessions/spawn.server.ts +27 -2
- package/src/server/routes/agent/harness-command.ts +6 -5
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/update-status.ts +18 -12
- package/src/server/routes/harness/update.test.ts +53 -16
- package/src/server/routes/harness/update.ts +13 -8
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/fork.ts +19 -4
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +19 -0
- package/src/server/routes/sessions/spawn.ts +16 -13
- package/src/shared/lib/chat/omp/agent-events.ts +11 -0
- package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
- package/src/shared/lib/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +53 -6
- package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
- package/src/shared/lib/notifications/outcomes.test.ts +96 -0
- package/src/shared/lib/notifications/outcomes.ts +64 -0
- package/src/shared/lib/notifications/settings.test.ts +49 -0
- package/src/shared/lib/notifications/settings.ts +34 -0
- package/src/shared/lib/omp/session/default-title.ts +5 -4
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
- package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
- package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
- package/src/shared/lib/settings/defaults.ts +3 -0
- package/src/shared/types/harness-update.ts +24 -0
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/harness-table.test-util.ts +25 -9
- package/dist/client/static/js/index-bc9aa4mx.css +0 -1
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
- package/src/client/hooks/workspace/child-expansion.ts +0 -33
|
@@ -0,0 +1,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
|
|
@@ -13,7 +13,9 @@ import { useChatTimeline } from '@/client/hooks/chat/timeline';
|
|
|
13
13
|
import { useSessionTitle } from '@/client/hooks/chat/timeline/session-title';
|
|
14
14
|
import { useSubagentView } from '@/client/hooks/chat/timeline/subagent-view';
|
|
15
15
|
import { useUndoConfirmation } from '@/client/hooks/chat/timeline/undo-confirmation';
|
|
16
|
+
import { usePendingBranch } from '@/client/hooks/chat/timeline/pending-branch';
|
|
16
17
|
import { useForkSession } from '@/client/hooks/chat/timeline/use-fork-session';
|
|
18
|
+
import { useStopWithQueuedPrompts } from '@/client/hooks/chat/timeline/stop-with-queue';
|
|
17
19
|
import { useModelNames } from '@/client/hooks/models/use-model-names';
|
|
18
20
|
import { useRunIdentity } from '@/client/hooks/chat/timeline/run-identity';
|
|
19
21
|
import { useProviderNames } from '@/client/hooks/models/use-provider-names';
|
|
@@ -119,23 +121,8 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
119
121
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
120
122
|
|
|
121
123
|
// Stop-all semantics: the run stops AND the queued follow-ups stay in the
|
|
122
|
-
// panel (the auto-process holds off)
|
|
123
|
-
|
|
124
|
-
const handleStop = useCallback(() => {
|
|
125
|
-
const heldCount = stopGenerating();
|
|
126
|
-
if (heldCount === 0) return;
|
|
127
|
-
pushToast(
|
|
128
|
-
`Stopped. ${heldCount} message${heldCount > 1 ? 's' : ''} still queued — nothing was sent.`,
|
|
129
|
-
'success',
|
|
130
|
-
{
|
|
131
|
-
action: { label: 'Send now', onClick: () => {
|
|
132
|
-
const first = messageQueue[0];
|
|
133
|
-
if (first) void handleSendNowQueueItem(first);
|
|
134
|
-
} },
|
|
135
|
-
duration: 8000,
|
|
136
|
-
},
|
|
137
|
-
);
|
|
138
|
-
}, [stopGenerating, pushToast, messageQueue, handleSendNowQueueItem]);
|
|
124
|
+
// panel (the auto-process holds off); the toast offers the head item.
|
|
125
|
+
const handleStop = useStopWithQueuedPrompts(stopGenerating, messageQueue, handleSendNowQueueItem, pushToast);
|
|
139
126
|
const { activeSubagent, back: handleSubagentBack } = useSubagentView(
|
|
140
127
|
sessionId,
|
|
141
128
|
searchParams.get('subagent'),
|
|
@@ -149,7 +136,6 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
149
136
|
}, [jumpToUserTurn]);
|
|
150
137
|
|
|
151
138
|
const handleNewChat = newChat.open;
|
|
152
|
-
const handleFork = useForkSession(sessionId, pushToast);
|
|
153
139
|
const modelNames = useModelNames();
|
|
154
140
|
const { sessionProvider, sessionModelName } = useRunIdentity({ folders, sessionId, sessionData, modelNames });
|
|
155
141
|
const providerNames = useProviderNames();
|
|
@@ -164,6 +150,8 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
164
150
|
// uses, so the pending composer's pill does not promise Kabmo's global pick.
|
|
165
151
|
const pendingProjectModel = usePendingProjectModel(folders, selectedFolderId);
|
|
166
152
|
const sessionDataModel = typeof sessionData?.model === 'object' ? sessionData.model : null;
|
|
153
|
+
const branch = usePendingBranch({ sessionId, folders, selectedFolderId, setSelectedFolderId, urlParentId: searchParams.get('parentSessionId'), urlForkFrom: searchParams.get('forkFrom'), urlForkAt: searchParams.get('forkAt'), setSearchParams, harnessPicker: activeHarness.picker, pendingHarnessRef });
|
|
154
|
+
const fork = useForkSession(sessionId, folders, selectedFolderId);
|
|
167
155
|
|
|
168
156
|
// The chat-level "a run is in flight" flag is computed in `useChatTimeline`
|
|
169
157
|
// (it owns the queue-vs-send decision that depends on it) and consumed here
|
|
@@ -203,7 +191,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
203
191
|
modes={modes}
|
|
204
192
|
composerModelRef={composerModelRef}
|
|
205
193
|
deferredComposerPickRef={deferredComposerPickRef}
|
|
206
|
-
sessionModel={sessionDataModel ?? pendingProjectModel}
|
|
194
|
+
sessionModel={branch.parentModel ?? sessionDataModel ?? pendingProjectModel}
|
|
207
195
|
sessionThinkingLevel={sessionData?.thinkingLevel}
|
|
208
196
|
generatingVerb={generatingVerb}
|
|
209
197
|
variant={variant}
|
|
@@ -218,8 +206,9 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
218
206
|
onCancelWait={cancelHeldWait}
|
|
219
207
|
spawnTarget={spawnTarget}
|
|
220
208
|
onSpawnTargetChange={setSpawnTarget}
|
|
209
|
+
{...branch.viewProps}
|
|
221
210
|
onWorktreeReport={(message) => pushToast(message, 'success', { duration: 6000 })}
|
|
222
|
-
{...
|
|
211
|
+
{...branch.composerProps}
|
|
223
212
|
/>
|
|
224
213
|
);
|
|
225
214
|
}
|
|
@@ -267,7 +256,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
267
256
|
onUndo={handleRequestUndo}
|
|
268
257
|
onRetry={handleRetry}
|
|
269
258
|
onNewChat={handleNewChat}
|
|
270
|
-
onFork={
|
|
259
|
+
onFork={fork}
|
|
271
260
|
showScrollBottom={showScrollBottom}
|
|
272
261
|
jumpToBottom={jumpToBottom}
|
|
273
262
|
rowWindow={rowWindow}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The draft-target row above a not-yet-started chat: where it runs, in which
|
|
8
|
+
* checkout, under which parent, and what it waits for.
|
|
9
|
+
*
|
|
10
|
+
* One row because these are one question — the context the first prompt is born
|
|
11
|
+
* into — and splitting it back into the composer would put four independent
|
|
12
|
+
* placements in two files. Extracted from `EmptyWorkspacePrompt` for the
|
|
13
|
+
* per-file ceiling.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { WorkspacePicker } from '@/client/components/workspace/chat-timeline/target-picker/WorkspacePicker';
|
|
17
|
+
import { WorktreePicker } from '@/client/components/workspace/chat-timeline/target-picker/WorktreePicker';
|
|
18
|
+
import { ParentSessionPicker } from '@/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker';
|
|
19
|
+
import {
|
|
20
|
+
WaitingDependencyPicker,
|
|
21
|
+
type WaitingCandidate,
|
|
22
|
+
} from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
23
|
+
import type { SpawnTarget } from '@/client/hooks/chat/timeline/spawn-target';
|
|
24
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
25
|
+
|
|
26
|
+
export interface DraftTargetRowProps {
|
|
27
|
+
folders: WorkspaceFolderData[];
|
|
28
|
+
selectedFolderId: number | null;
|
|
29
|
+
setSelectedFolderId: (id: number | null) => void;
|
|
30
|
+
spawnTarget?: SpawnTarget | null;
|
|
31
|
+
onSpawnTargetChange?: (next: SpawnTarget | null) => void;
|
|
32
|
+
/** Reports a worktree the composer created or failed to create. */
|
|
33
|
+
onWorktreeReport?: (message: string) => void;
|
|
34
|
+
/** The session this chat runs under, or null for a top-level chat. */
|
|
35
|
+
parentSessionId?: string | null;
|
|
36
|
+
onParentSessionChange?: (sessionId: string | null) => void;
|
|
37
|
+
/** "Parent session" for a child, "Fork from" for a fork. */
|
|
38
|
+
branchLabel?: string;
|
|
39
|
+
/** False when the pending chat must have a source (a fork). */
|
|
40
|
+
branchAllowNone?: boolean;
|
|
41
|
+
waitingFor?: WaitingCandidate | null;
|
|
42
|
+
onWaitingForChange?: (candidate: WaitingCandidate | null) => void;
|
|
43
|
+
streamStatusMap?: Record<string, string | undefined>;
|
|
44
|
+
/** A name for a streaming session the sidebar has not scanned yet. */
|
|
45
|
+
titleForSession?: (id: string) => string | undefined;
|
|
46
|
+
candidates: WaitingCandidate[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function DraftTargetRow({
|
|
50
|
+
folders,
|
|
51
|
+
selectedFolderId,
|
|
52
|
+
setSelectedFolderId,
|
|
53
|
+
spawnTarget = null,
|
|
54
|
+
onSpawnTargetChange,
|
|
55
|
+
onWorktreeReport,
|
|
56
|
+
parentSessionId = null,
|
|
57
|
+
onParentSessionChange,
|
|
58
|
+
branchLabel = 'Parent session',
|
|
59
|
+
branchAllowNone = true,
|
|
60
|
+
waitingFor = null,
|
|
61
|
+
onWaitingForChange,
|
|
62
|
+
streamStatusMap = {},
|
|
63
|
+
titleForSession,
|
|
64
|
+
candidates,
|
|
65
|
+
}: DraftTargetRowProps) {
|
|
66
|
+
return (
|
|
67
|
+
<div className="flex items-center gap-1 flex-wrap">
|
|
68
|
+
{/* Two controls, because they answer two questions: the workspace (which
|
|
69
|
+
project) and the worktree (which checkout of it). The worktree control
|
|
70
|
+
draws itself only for a git repository, and it reads its list on mount
|
|
71
|
+
because its own trigger names the branch the project root holds. */}
|
|
72
|
+
<WorkspacePicker
|
|
73
|
+
folders={folders}
|
|
74
|
+
selectedFolderId={selectedFolderId}
|
|
75
|
+
setSelectedFolderId={setSelectedFolderId}
|
|
76
|
+
onClearWorktree={() => onSpawnTargetChange?.(null)}
|
|
77
|
+
/>
|
|
78
|
+
{onSpawnTargetChange && (
|
|
79
|
+
<WorktreePicker
|
|
80
|
+
folders={folders}
|
|
81
|
+
selectedFolderId={selectedFolderId}
|
|
82
|
+
target={spawnTarget}
|
|
83
|
+
setTarget={onSpawnTargetChange}
|
|
84
|
+
onReport={onWorktreeReport}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
{/* ALL sessions, not just the active one: the composer may have been
|
|
88
|
+
opened from one row and the user may want the chat under another.
|
|
89
|
+
Choosing a parent also moves the workspace to that session's folder. */}
|
|
90
|
+
{onParentSessionChange && (
|
|
91
|
+
<ParentSessionPicker
|
|
92
|
+
folders={folders}
|
|
93
|
+
value={parentSessionId}
|
|
94
|
+
onChange={onParentSessionChange}
|
|
95
|
+
label={branchLabel}
|
|
96
|
+
allowNone={branchAllowNone}
|
|
97
|
+
/>
|
|
98
|
+
)}
|
|
99
|
+
{/* The wait picker sits BESIDE the workspace picker, because both answer
|
|
100
|
+
the same question about the chat that has not started: where it runs,
|
|
101
|
+
and what it waits for. It only appears while there is something to
|
|
102
|
+
wait for (or a pick already made). */}
|
|
103
|
+
{onWaitingForChange && (waitingFor || candidates.length > 0) && (
|
|
104
|
+
<WaitingDependencyPicker
|
|
105
|
+
folders={folders}
|
|
106
|
+
streamStatusMap={streamStatusMap}
|
|
107
|
+
sessionId={null}
|
|
108
|
+
titleFor={titleForSession}
|
|
109
|
+
value={waitingFor}
|
|
110
|
+
onChange={onWaitingForChange}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* "Parent session" — which session a NEW chat branches under.
|
|
8
|
+
*
|
|
9
|
+
* The composer's draft-target row already answers where a chat runs; this is
|
|
10
|
+
* the other half of the same question for a child: what it runs UNDER. The
|
|
11
|
+
* list is ALL real sessions, not only the active one, because the row that
|
|
12
|
+
* opened the composer may not be the parent the user ends up wanting.
|
|
13
|
+
*
|
|
14
|
+
* A pending chat is never offered (it has no id to parent), and neither is an
|
|
15
|
+
* archived one (the server refuses to spawn under it).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { useCallback, useMemo, useRef, useState } from 'preact/hooks';
|
|
19
|
+
import { Check, ChevronDown, GitBranch, X } from 'lucide-preact';
|
|
20
|
+
import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
|
|
21
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
22
|
+
|
|
23
|
+
export interface ParentSessionOption {
|
|
24
|
+
id: string;
|
|
25
|
+
title: string;
|
|
26
|
+
folderId: number | string;
|
|
27
|
+
folderName: string;
|
|
28
|
+
harness?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Every real session, in sidebar order, excluding the chat being composed. */
|
|
32
|
+
export function parentSessionOptions(
|
|
33
|
+
folders: WorkspaceFolderData[],
|
|
34
|
+
excludeId?: string | null,
|
|
35
|
+
): ParentSessionOption[] {
|
|
36
|
+
const options: ParentSessionOption[] = [];
|
|
37
|
+
for (const folder of folders) {
|
|
38
|
+
for (const session of folder.sessions ?? []) {
|
|
39
|
+
const id = String(session.id);
|
|
40
|
+
if (id.startsWith('new-') || session.is_archived === 1) continue;
|
|
41
|
+
if (excludeId && id === excludeId) continue;
|
|
42
|
+
options.push({
|
|
43
|
+
id,
|
|
44
|
+
title: session.title || id,
|
|
45
|
+
folderId: folder.id,
|
|
46
|
+
folderName: folder.name,
|
|
47
|
+
...(session.harness ? { harness: session.harness } : {}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ParentSessionPickerProps {
|
|
55
|
+
folders: WorkspaceFolderData[];
|
|
56
|
+
/** The pending chat itself, never offered as its own parent. */
|
|
57
|
+
sessionId?: string | null;
|
|
58
|
+
value: string | null;
|
|
59
|
+
onChange: (sessionId: string | null) => void;
|
|
60
|
+
/** "Parent session" for a child, "Fork from" for a fork. */
|
|
61
|
+
label?: string;
|
|
62
|
+
/** False when the pending chat MUST have a source (a fork). */
|
|
63
|
+
allowNone?: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function ParentSessionPicker({
|
|
67
|
+
folders,
|
|
68
|
+
sessionId,
|
|
69
|
+
value,
|
|
70
|
+
onChange,
|
|
71
|
+
label = 'Parent session',
|
|
72
|
+
allowNone = true,
|
|
73
|
+
}: ParentSessionPickerProps) {
|
|
74
|
+
const [open, setOpen] = useState(false);
|
|
75
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
76
|
+
const close = useCallback(() => setOpen(false), []);
|
|
77
|
+
useOnClickOutside(ref, close);
|
|
78
|
+
const options = useMemo(() => parentSessionOptions(folders, sessionId), [folders, sessionId]);
|
|
79
|
+
const selected = value ? options.find((option) => option.id === value) : undefined;
|
|
80
|
+
const triggerLabel = selected ? selected.title : value ? value : `${label}: none`;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div className="relative shrink-0" ref={ref}>
|
|
84
|
+
<button
|
|
85
|
+
type="button"
|
|
86
|
+
data-testid="parent-session-picker"
|
|
87
|
+
onClick={() => setOpen((prev) => !prev)}
|
|
88
|
+
title={selected ? `${label}: ${selected.title}` : `Choose a session for ${label.toLowerCase()}`}
|
|
89
|
+
aria-label={selected ? `${label}: ${selected.title}` : label}
|
|
90
|
+
aria-expanded={open}
|
|
91
|
+
className={`tap-chip group flex items-center gap-1.5 rounded-md px-1.5 py-1 text-xs font-medium transition-all focus-visible:bg-ink/5 cursor-pointer select-none ${
|
|
92
|
+
selected ? 'bg-ink/10 text-ink' : 'text-ink/75 hover:text-ink hover:bg-ink/5'
|
|
93
|
+
}`}
|
|
94
|
+
>
|
|
95
|
+
<GitBranch size={13} className={`flex-shrink-0 ${selected ? 'text-ink/80' : 'text-ink/50 group-hover:text-ink/80'}`} />
|
|
96
|
+
<span className="max-w-[220px] truncate tracking-tight">{triggerLabel}</span>
|
|
97
|
+
<ChevronDown
|
|
98
|
+
size={13}
|
|
99
|
+
className={`flex-shrink-0 text-ink/40 transition-transform duration-150 ${open ? 'rotate-180 text-ink/70' : ''}`}
|
|
100
|
+
/>
|
|
101
|
+
</button>
|
|
102
|
+
|
|
103
|
+
{open && (
|
|
104
|
+
<div className="glass-popover absolute bottom-full left-0 mb-1.5 w-80 bg-paper border border-ink/10 rounded-lg shadow-lg z-50 flex flex-col overflow-hidden text-xs py-1">
|
|
105
|
+
<div className="flex items-center justify-between px-3 py-1.5 border-b border-ink/5">
|
|
106
|
+
<span className="text-[10px] uppercase tracking-wider text-ink/40 font-semibold">
|
|
107
|
+
{label}
|
|
108
|
+
</span>
|
|
109
|
+
{value && allowNone && (
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
onClick={() => {
|
|
113
|
+
onChange(null);
|
|
114
|
+
setOpen(false);
|
|
115
|
+
}}
|
|
116
|
+
title="Start a top-level chat"
|
|
117
|
+
aria-label="Clear parent session"
|
|
118
|
+
className="flex items-center gap-1 text-[10px] text-ink/50 hover:text-ink cursor-pointer"
|
|
119
|
+
>
|
|
120
|
+
<X size={10} /> clear
|
|
121
|
+
</button>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
<div className="max-h-64 scrollbar-overlay-container py-1">
|
|
125
|
+
{allowNone && (
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
data-testid="parent-candidate-none"
|
|
129
|
+
onClick={() => {
|
|
130
|
+
onChange(null);
|
|
131
|
+
setOpen(false);
|
|
132
|
+
}}
|
|
133
|
+
className={`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors cursor-pointer hover:bg-ink/5 ${
|
|
134
|
+
value ? 'text-ink/70' : 'text-ink font-medium'
|
|
135
|
+
}`}
|
|
136
|
+
>
|
|
137
|
+
<span className="w-3 shrink-0">{!value && <Check size={11} />}</span>
|
|
138
|
+
<span className="min-w-0 flex-1 truncate">No parent (top-level chat)</span>
|
|
139
|
+
</button>
|
|
140
|
+
)}
|
|
141
|
+
{options.map((option) => {
|
|
142
|
+
const active = option.id === value;
|
|
143
|
+
return (
|
|
144
|
+
<button
|
|
145
|
+
key={option.id}
|
|
146
|
+
type="button"
|
|
147
|
+
data-testid="parent-candidate"
|
|
148
|
+
data-session-id={option.id}
|
|
149
|
+
onClick={() => {
|
|
150
|
+
onChange(option.id);
|
|
151
|
+
setOpen(false);
|
|
152
|
+
}}
|
|
153
|
+
className={`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors cursor-pointer hover:bg-ink/5 ${
|
|
154
|
+
active ? 'text-ink font-medium' : 'text-ink/70'
|
|
155
|
+
}`}
|
|
156
|
+
>
|
|
157
|
+
<span className="w-3 shrink-0">{active && <Check size={11} />}</span>
|
|
158
|
+
<span className="min-w-0 flex-1 truncate">{option.title}</span>
|
|
159
|
+
<span className="shrink-0 max-w-[7rem] truncate text-[10px] text-ink/40">
|
|
160
|
+
{option.folderName}
|
|
161
|
+
</span>
|
|
162
|
+
</button>
|
|
163
|
+
);
|
|
164
|
+
})}
|
|
165
|
+
{options.length === 0 && (
|
|
166
|
+
<div className="px-3 py-2 text-ink/40 italic">No sessions to parent under yet</div>
|
|
167
|
+
)}
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
}
|
package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which sessions the child composer may name as a parent: every REAL session,
|
|
8
|
+
* in sidebar order, never a pending or archived one.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, expect, test } from 'bun:test';
|
|
12
|
+
import { parentSessionOptions } from '@/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker';
|
|
13
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
14
|
+
|
|
15
|
+
const folders = [
|
|
16
|
+
{
|
|
17
|
+
id: 1,
|
|
18
|
+
name: 'one',
|
|
19
|
+
sessions: [
|
|
20
|
+
{ id: 'a', folder_id: 1, title: 'Alpha' },
|
|
21
|
+
{ id: 'new-123', folder_id: 1, title: 'Pending' },
|
|
22
|
+
{ id: 'archived', folder_id: 1, title: 'Old', is_archived: 1 },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 2,
|
|
27
|
+
name: 'two',
|
|
28
|
+
sessions: [{ id: 'b', folder_id: 2, title: 'Beta', harness: 'claude' }],
|
|
29
|
+
},
|
|
30
|
+
] as unknown as WorkspaceFolderData[];
|
|
31
|
+
|
|
32
|
+
describe('parentSessionOptions', () => {
|
|
33
|
+
test('lists real sessions in sidebar order with their folder', () => {
|
|
34
|
+
expect(parentSessionOptions(folders)).toEqual([
|
|
35
|
+
{ id: 'a', title: 'Alpha', folderId: 1, folderName: 'one' },
|
|
36
|
+
{ id: 'b', title: 'Beta', folderId: 2, folderName: 'two', harness: 'claude' },
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('never offers a pending chat or an archived session', () => {
|
|
41
|
+
const ids = parentSessionOptions(folders).map((option) => option.id);
|
|
42
|
+
expect(ids).not.toContain('new-123');
|
|
43
|
+
expect(ids).not.toContain('archived');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('excludes the chat being composed', () => {
|
|
47
|
+
expect(parentSessionOptions(folders, 'a').map((option) => option.id)).toEqual(['b']);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -301,6 +301,25 @@ describe('loadComposerItems', () => {
|
|
|
301
301
|
expect(requested.length).toBe(6);
|
|
302
302
|
});
|
|
303
303
|
|
|
304
|
+
test('commands are scoped to the live session, with one cache entry per session', async () => {
|
|
305
|
+
answer = (url) => (url.includes('sessionId=s1')
|
|
306
|
+
? { body: { commands: [{ id: 'c1', name: 'test', description: 'Run tests', scope: 'system', template: '' }], skills: [] } }
|
|
307
|
+
: { body: { commands: [], skills: [] } });
|
|
308
|
+
|
|
309
|
+
const forS1 = await loadComposerItems('command', '/repo', 's1');
|
|
310
|
+
expect(requested).toContain('/api/settings/commands?root=%2Frepo&sessionId=s1');
|
|
311
|
+
expect(forS1.some((item) => item.name === 'test')).toBe(true);
|
|
312
|
+
|
|
313
|
+
// Another chat must not be served s1's vocabulary from the cache.
|
|
314
|
+
const forS2 = await loadComposerItems('command', '/repo', 's2');
|
|
315
|
+
expect(requested.some((url) => url.includes('sessionId=s2'))).toBe(true);
|
|
316
|
+
expect(forS2.some((item) => item.name === 'test')).toBe(false);
|
|
317
|
+
|
|
318
|
+
const before = requested.length;
|
|
319
|
+
await loadComposerItems('command', '/repo', 's1');
|
|
320
|
+
expect(requested.length).toBe(before);
|
|
321
|
+
});
|
|
322
|
+
|
|
304
323
|
test('a command entry is a /name token and a skill is prefixed', async () => {
|
|
305
324
|
answer = (url) => url.includes('/commands')
|
|
306
325
|
? { body: { commands: [{ id: 'c', name: 'fix', description: 'fix it', scope: 'user', template: '/fix' }] } }
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { useEffect, useMemo, useRef } from 'preact/hooks';
|
|
28
|
-
import type { PendingSessionEntry } from '@/client/hooks/chat/omp/pending-
|
|
28
|
+
import type { PendingSessionEntry } from '@/client/hooks/chat/omp/pending-entry';
|
|
29
29
|
import { pendingHostFolderIds } from '@/client/hooks/chat/omp/pending-rows';
|
|
30
30
|
import { setFolderExpanded } from '@/client/hooks/workspace/folder-expansion';
|
|
31
31
|
import type { WorkspaceFolderData } from '@/shared/types';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The pending → real id switch a spawn performs, and who may claim it.
|
|
8
|
+
*
|
|
9
|
+
* Split from the store (`pending-sessions.ts`) because the two readers ask
|
|
10
|
+
* different questions of the same record: the session-state provider claims it
|
|
11
|
+
* once to carry a draft across, while the agent hook only peeks to know the
|
|
12
|
+
* conversation did not change. Neither may treat a plain session switch as an
|
|
13
|
+
* adoption — that mistake copied one chat's draft into another and cleared the
|
|
14
|
+
* run's tool map mid-turn.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** `toId → fromId` for a spawn adoption, written where the spawn answers. */
|
|
18
|
+
const adoptions = new Map<string, string>();
|
|
19
|
+
|
|
20
|
+
/** Record a spawn adoption; bounded by the store, which drops the source. */
|
|
21
|
+
export function recordAdoption(fromId: string, toId: string): void {
|
|
22
|
+
adoptions.set(toId, fromId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether `toId` is the id a spawn answered with for `fromId` — consuming the
|
|
27
|
+
* record so one adoption is claimed once.
|
|
28
|
+
*
|
|
29
|
+
* Only a real spawn may carry the transient slot's UI state across: clicking a
|
|
30
|
+
* different session from a pending chat is the same URL transition, and was
|
|
31
|
+
* measured copying `chat.draft` into the other session.
|
|
32
|
+
*/
|
|
33
|
+
export function consumeAdoption(fromId: string | null | undefined, toId: string): boolean {
|
|
34
|
+
if (!fromId || adoptions.get(toId) !== fromId) return false;
|
|
35
|
+
adoptions.delete(toId);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether `toId` is the id a spawn answered with for `fromId`, WITHOUT claiming
|
|
41
|
+
* the record.
|
|
42
|
+
*
|
|
43
|
+
* The agent hook's question is "is this the SAME conversation under a new id",
|
|
44
|
+
* not "may I carry this UI state across": treating an adoption as a session
|
|
45
|
+
* switch threw away `toolResultsRef`/`lastToolMessageRef` mid-turn, so every
|
|
46
|
+
* later progress frame lost its card. The provider still owns the single claim,
|
|
47
|
+
* so peeking here cannot steal it.
|
|
48
|
+
*/
|
|
49
|
+
export function isSpawnAdoption(fromId: string | null | undefined, toId: string): boolean {
|
|
50
|
+
return Boolean(fromId) && adoptions.get(toId) === fromId;
|
|
51
|
+
}
|