feat(web): side chats let you ask about a thread without interrupting it #18243
Closedshivamhwp(GitHub profile, opens in a new tab)wants to merge 17 commits into
main fromfeat/side-chatsopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/chat/ChatComposer.tsx line 2735OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2709,3 +2715,21 @@27092715 },2716+ ...(props.onSideChatCommand2717+ ? ([2718+ {2719+ id: "slash:side",2720+ type: "slash-command",2721+ command: "side",2722+ label: "/side",2723+ description: "Ask a side question without interrupting this thread",2724+ },2725+ {2726+ id: "slash:btw",2727+ type: "slash-command",2728+ command: "btw",2729+ label: "/btw",2730+ description: "Same as /side. Add a question to send it right away",2731+ },2732+ ] as const)2733+ : []),27102734 ...(planModeUiEnabled27112735 ? ([apps/web/src/components/ChatView.tsx line 8889OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -8805,3 +8881,9 @@88058881 return;88068882 }880788838884+ // `/side` and `/btw` typed in full, like `/usage`: a question after it goes8885+ // straight to a new side chat, the bare command reopens the latest one.8886+ if (sideChatsAvailable && !directAnnotation && !composerHasNonPromptContent) {8887+ const sideCommand = parseSideCommand(promptRef.current);8888+ if (sideCommand !== null) {8889+ promptRef.current = "";apps/web/src/components/chat/ChatComposer.tsx line 4057OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4029,3 +4054,4 @@40294054 return;40304055 }40314056 if (item.type === "slash-command") {4057+ if ((item.command === "side" || item.command === "btw") && onSideChatCommand) {apps/web/src/components/chat/ChatComposer.tsx line 5780OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5731,3 +5776,5 @@57315776 },57325777 });57335778 if (command !== "composer.stash") return;5779+ // A side chat mounts a second composer; only the one whose chat has focus stashes.5780+ if (!isInSameChatView(event.target, composerFormRef.current)) return;
- apps/server/src/orchestration-v2/Orchestrator.ts lines 2533 to 2558Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2209,0 +2212,21 @@2212+ const parentThread =2213+ command.parentThreadId === undefined2214+ ? null2215+ : yield* projectionStore2216+ .getThread(command.parentThreadId)2217+ .pipe(2218+ Effect.mapError(2219+ (cause) =>2220+ new OrchestratorProjectionError({ threadId: command.parentThreadId!, cause }),2221+ ),2222+ );2223+ if (2224+ parentThread !== null &&2225+ (parentThread.deletedAt !== null || parentThread.projectId !== command.projectId)2226+ ) {2227+ return yield* new OrchestratorDispatchError({2228+ commandId: command.commandId,2229+ commandType: command.type,2230+ cause: `Parent thread ${parentThread.id} is deleted or belongs to another project.`,2231+ });2232+ }apps/web/src/components/chat/composerEventScope.ts lines 36 to 37OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -27,3 +27,11 @@2727 };2828 }292930+/**31+ * Whether `target` belongs to the same chat view as `own`. A side chat renders32+ * a second chat view inside the host's, so window-level composer shortcuts33+ * check this to act on one composer only.34+ */35+export function isInSameChatView(target: EventTarget | null, own: Element | null): boolean {36+ const targetChat = target instanceof Element ? target.closest("[data-chat-embedded]") : null;37+ return targetChat === (own?.closest("[data-chat-embedded]") ?? null);apps/web/src/components/CommandPalette.tsx line 1170OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1154,3 +1167,4 @@11541167 threads.filter(11551168 (thread) =>11561169 thread.archivedAt === null &&1170+ !thread.sideChat &&apps/web/src/hooks/useSideChatActions.ts lines 101 to 178OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +158,21 @@158+ messageId: newMessageId(),159+ role: "user",160+ text: `${quote}${question}`,161+ attachments: [],162+ },163+ titleSeed: question.slice(0, 80),164+ runtimeMode: SIDE_CHAT_READ_ONLY_RUNTIME_MODE,165+ interactionMode: "default",166+ dispatchMode: "auto",167+ },168+ });169+ if (sent._tag === "Failure" && !isAtomCommandInterrupted(sent)) {170+ reportFailure("Could not send the question", squashAtomCommandFailure(sent));171+ }172+ } else if (quote.length > 0) {173+ useComposerDraftStore.getState().setPrompt(childRef, quote);174+ }175+ return childRef;176+ },177+ [createThread, forkFromRun, parentRef, projection, startTurn, supported],178+ );
- apps/web/src/components/ChatView.tsx line 8888OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -8805,3 +8881,8 @@88058881 return;88068882 }880788838884+ // `/side` and `/btw` typed in full, like `/usage`: a question after it goes8885+ // straight to a new side chat, the bare command reopens the latest one.8886+ if (sideChatsAvailable && !directAnnotation && !composerHasNonPromptContent) {8887+ const typedPrompt = promptRef.current;8888+ const sideCommand = parseSideCommand(typedPrompt);
- apps/web/src/components/ChatView.tsx line 8065OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -8009,3 +8062,4 @@80098062 const closeThreadFind = useCallback(() => threadFindControlsRef.current?.close(), []);8010806380118064 useEffect(() => {8065+ if (embedded) return;
- apps/web/src/components/ChatView.tsx lines 640 to 644OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -626,3 +636,9 @@626636 const VISIT_DISPATCH_THROTTLE_MS = 10_000;627637 const EMPTY_PROVIDER_SKILLS: ServerProvider["skills"] = [];628638 const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};639+/** Panel layout shortcuts the host thread still handles while a side chat has focus. */640+const SIDE_CHAT_PASSTHROUGH_COMMANDS: ReadonlySet<KeybindingCommand> = new Set([641+ "rightPanel.close",642+ "rightPanel.toggle",643+ "threadPanel.toggle",644+]);
- apps/web/src/components/ChatView.tsx line 12165OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -11884,18 +12163,3 @@11884- loadBalancingSettings.loadBalancingEnabled11885- ? onAutoEnvironment11886- : undefined11887- }11888- availableEnvironments={logicalProjectEnvironments}11889- composerControlsHostRef={setRestingComposerControlsHost}11890- contextStripVisible={showComposerContextStrip}11891- />11892- </div>11893- )}11894- </div>11895- </div>11896- </ComposerSurface.Shell>11897- <div11898- aria-hidden11899- className="h-[calc(env(safe-area-inset-bottom)+1rem)] sm:h-[calc(env(safe-area-inset-bottom)+1.25rem)]"11900- />11901- </div>12163+ {embedded ? (12164+ sideComposerFocused && sideComposerSlot !== null ? (12165+ createPortal(sideComposerFrame, sideComposerSlot)
- apps/web/src/components/ChatView.tsx lines 8631 to 8631OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -8410,5 +8625,7 @@84108625 pasteAsTextShortcutUntilRef.current = Date.now() + 1_000;84118626 }84128627 };8628+ if (embedded) return;84138629 const handler = (event: ClipboardEvent) => {84148630 if (!activeThreadId || isCommandPaletteOpen()) return;8631+ if (event.target instanceof Element && event.target.closest("[data-chat-embedded]")) return;
- apps/web/src/components/ChatView.tsx line 11707OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -11314,0 +11687,21 @@11687+ ref={queuedRunsControlRef}11688+ steerShortcutLabel={shortcutLabelForCommand(11689+ keybindings,11690+ "thread.steerQueuedMessage",11691+ { context: { terminalFocus: false } },11692+ )}11693+ editShortcutLabel={shortcutLabelForCommand(11694+ keybindings,11695+ "thread.editQueuedMessage",11696+ { context: { composerFocus: true } },11697+ )}11698+ environmentId={activeThread.environmentId}11699+ threadId={activeThread.id}11700+ optimisticMessages={optimisticUserMessages}11701+ editingRunId={editingQueuedRun?.runId ?? null}11702+ onEditQueuedRun={beginEditingQueuedRun}11703+ onCancelEdit={cancelEditingQueuedRun}11704+ />11705+ ) : null11706+ }11707+ bannerItems={composerBannerItems}
- apps/web/src/hooks/useSideChatActions.ts lines 287 to 300OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +280,21 @@280+ reportFailure("Could not discard the side chat", squashAtomCommandFailure(result));281+ }282+ },283+ [closeSurface, deleteThread, parentRef],284+ );285+286+ /** Closing a side chat that never got a message throws it away; otherwise it stays listed. */287+ const close = useCallback(288+ async (childThreadId: ThreadId) => {289+ closeSurface(childThreadId);290+ const shell = readSideChats().find((thread) => thread.id === childThreadId);291+ if (parentRef === null || shell === undefined || !isEmptySideChat(shell)) return;292+ // This client's copy can lag a question that already landed, so the293+ // server deletes only if the thread is still empty. If not, it stays listed.294+ await deleteThread({295+ environmentId: parentRef.environmentId,296+ input: { threadId: childThreadId, expectedEmpty: true },297+ });298+ },299+ [closeSurface, deleteThread, parentRef, readSideChats],300+ );
- apps/web/src/sideChat.logic.ts line 70OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +50,21 @@50+ */51+export function makeSideChatListingFilter<T extends SideChatListingShell>(52+ threads: ReadonlyArray<T>,53+): (thread: T) => boolean {54+ const present = new Set(55+ threads.flatMap((thread) => (thread.deletedAt ? [] : [`${thread.environmentId}:${thread.id}`])),56+ );57+ return (thread) => {58+ const parentThreadId = thread.lineage?.parentThreadId;59+ return (60+ !thread.sideChat ||61+ !parentThreadId ||62+ !present.has(`${thread.environmentId}:${parentThreadId}`)63+ );64+ };65+}66+67+const SETTLED_RUN_STATUSES = new Set(["completed", "failed", "interrupted", "cancelled"]);68+69+/** A side chat is "previous" once nothing is running in it, like a finished subagent. */70+export function isPreviousSideChat(thread: Pick<SideChatShell, "latestRun">): boolean {apps/web/src/sideChat.logic.ts lines 67 to 67OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +47,21 @@47+ * Builds the sidebar and palette test for "list this thread". A side chat stays48+ * out while its parent is around to list it; once the parent is deleted, a49+ * surviving side chat shows up like an ordinary thread instead of vanishing.50+ */51+export function makeSideChatListingFilter<T extends SideChatListingShell>(52+ threads: ReadonlyArray<T>,53+): (thread: T) => boolean {54+ const present = new Set(55+ threads.flatMap((thread) => (thread.deletedAt ? [] : [`${thread.environmentId}:${thread.id}`])),56+ );57+ return (thread) => {58+ const parentThreadId = thread.lineage?.parentThreadId;59+ return (60+ !thread.sideChat ||61+ !parentThreadId ||62+ !present.has(`${thread.environmentId}:${parentThreadId}`)63+ );64+ };65+}66+67+const SETTLED_RUN_STATUSES = new Set(["completed", "failed", "interrupted", "cancelled"]);apps/web/src/components/ChatView.tsx line 2165Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6890,4 +7038,5 @@68907038 // terminal is a surface and is recognized by the predicate instead. Mobile is left alone so68917039 // returning to the app does not raise the keyboard.68927040 useEffect(() => {6893- if (!activeThread?.id || terminalUiState.terminalOpen || isMobileViewport) return;7041+ // The host thread owns refocus; two composers would race for it.7042+ if (embedded || !activeThread?.id || terminalUiState.terminalOpen || isMobileViewport) return;
- apps/mobile/src/features/threads/threadListV2.ts lines 717 to 724OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -707,5 +714,11 @@707714 let nextSnoozeWakeAt: string | null = null;708715 // An empty set is treated as absent so `?.` skips building the key.709716 const queuedThreadKeys = input.queuedThreadKeys?.size ? input.queuedThreadKeys : undefined;717+ const listable = makeSideChatListingFilter(input.threads);710718 for (const thread of input.threads) {711- if (thread.archivedAt !== null || thread.lineage.relationshipToParent === "subagent") continue;719+ if (720+ thread.archivedAt !== null ||721+ thread.lineage.relationshipToParent === "subagent" ||722+ !listable(thread)723+ )724+ continue;apps/web/src/components/ChatView.tsx lines 11881 to 11881OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -11694,6 +11866,16 @@1169411866 </div>1169511867 </div>1169611868 ) : null}11697- <div11698- ref={draftHeroTransition.composerAnchorRef}11699- className="relative z-10"11869+ <ComposerAnchor11870+ anchorRef={draftHeroTransition.composerAnchorRef}11871+ placement={11872+ sideChat11873+ ? {11874+ kind: "side-chat",11875+ threadId,11876+ focused: sideChat.focused,11877+ slot: sideChat.composerSlot,11878+ replyBar: (11879+ <SideChatReplyBar11880+ needsAnswer={11881+ pendingApprovals.length > 0 || pendingUserInputs.length > 0apps/web/src/hooks/useSideChatActions.ts line 185OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +165,21 @@165+ const quote = input.quote === undefined ? "" : quoteForSideChat(input.quote);166+ if (question.length > 0) {167+ const sent = await startTurn({168+ environmentId: ownerRef.environmentId,169+ input: {170+ threadId: childThreadId,171+ message: {172+ messageId: newMessageId(),173+ role: "user",174+ text: `${quote}${question}`,175+ attachments: [],176+ },177+ titleSeed: question.slice(0, 80),178+ runtimeMode: SIDE_CHAT_READ_ONLY_RUNTIME_MODE,179+ interactionMode: "default",180+ dispatchMode: "auto",181+ },182+ });183+ if (sent._tag === "Failure") {184+ // Keep the question in the side chat so it can be sent again.185+ useComposerDraftStore.getState().setPrompt(childRef, `${quote}${question}`);apps/web/src/hooks/useSideChatHost.ts line 60OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +40,21 @@40+ const hadFocusedSideChat = useRef(false);41+ useEffect(() => {42+ if (focusedSideChatId === null && hadFocusedSideChat.current) {43+ composerRef.current?.focusAtEnd();44+ }45+ hadFocusedSideChat.current = focusedSideChatId !== null;46+ }, [composerRef, focusedSideChatId]);47+48+ const start = actions.start;49+ const threadId = threadRef?.threadId ?? null;50+ const onAskAboutResponse = useCallback(51+ async (target: { readonly sourceThreadId: ThreadId; readonly runId: RunId }) => {52+ if (target.sourceThreadId !== threadId) return;53+ await start({ history: "with", runId: target.runId });54+ },55+ [start, threadId],56+ );57+ const defaultHistory = actions.defaultHistory;58+ const onAskAssistantText = useCallback(59+ (citation: AssistantCitation) => {60+ void start({ history: defaultHistory, quote: citation.text });
- apps/web/src/components/CommandPalette.tsx line 1116OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1103,3 +1113,4 @@11031113 threads.filter(11041114 (thread) =>11051115 thread.archivedAt === null &&1116+ !thread.sideChat &&
- packages/client-runtime/src/state/threadWorkflows.ts lines 275 to 289Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -188,0 +251,21 @@251+252+/**253+ * Builds the sidebar and palette test for "list this thread". A side chat stays254+ * out while its parent is around to list it; once the parent is deleted, a255+ * surviving side chat shows up like an ordinary thread instead of vanishing.256+ */257+export function makeSideChatListingFilter<T extends SideChatListingShell>(258+ threads: ReadonlyArray<T>,259+): (thread: T) => boolean {260+ const present = new Set(261+ threads.flatMap((thread) => (thread.deletedAt ? [] : [`${thread.environmentId}:${thread.id}`])),262+ );263+ return (thread) => {264+ const parentThreadId = thread.lineage?.parentThreadId;265+ return (266+ !thread.sideChat ||267+ !parentThreadId ||268+ !present.has(`${thread.environmentId}:${parentThreadId}`)269+ );270+ };271+}
- apps/server/src/orchestration-v2/Orchestrator.ts line 180OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -152,3 +153,3 @@152153 {153154 commandId: CommandId,154155 commandType: Schema.String,
- apps/web/src/components/ChatView.tsx lines 1823 to 1825OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1742,4 +1817,9 @@17421817 }17431818 };17441819 const onInterruptStable = useStableCallback(onInterrupt);1745- useEffect(() => subscribeSnapShotComposerFocus(focusComposerStable), [focusComposerStable]);1820+ // SnapShot captures land in the route thread's draft, so a side chat never1821+ // takes the focus that follows one.1822+ useEffect(1823+ () => (embedded ? undefined : subscribeSnapShotComposerFocus(focusComposerStable)),1824+ [embedded, focusComposerStable],1825+ );
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
t3dotgg(GitHub profile, opens in a new tab) closed this
juliusmarminge removed labelspr:needs-julius
Sign in to join this conversation.












macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed