feat: side chats beside the main thread #26901
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/26901/headmerged by t3dotgg(GitHub profile, opens in a new tab) 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/server/src/orchestration-v2/Orchestrator.ts lines 4431 to 4435Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4222,3 +4234,17 @@42224234 cause: `Thread ${command.sourceThreadId} is not a fork of ${command.targetThreadId}.`,42234235 });42244236 }4237+ // The next dispatch consumes merge-backs and queued dispatches cannot, so a busy target would reject it.4238+ if (targetProjection.runs.some(isBlockingRun)) {4239+ return yield* new OrchestratorDispatchError({4240+ commandId: command.commandId,4241+ commandType: command.type,4242+ cause: `Thread ${command.targetThreadId} is still running. Bring back is available when it is idle.`,4243+ });4244+ }4245+ const otherPendingMergeBack = targetProjection.contextTransfers.find(4246+ (transfer) =>4247+ transfer.type === "merge_back" &&4248+ transfer.status === "pending" &&4249+ transfer.sourceThreadId !== command.sourceThreadId,4250+ );apps/server/src/orchestration-v2/Orchestrator.ts line 12637OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -12516,3 +12619,19 @@12516- idAllocator,12517- }),12619+ return { projection, plan };12620+ });12621+ const { projection, plan } = yield* planDeletion(command);12622+ // Side chats live inside their parent; deleting it from any client must not orphan them.12623+ const forkTargets = new Set(12624+ projection.contextTransfers.flatMap((transfer) =>12625+ transfer.type === "fork" && transfer.sourceThreadId === command.threadId12626+ ? [transfer.targetThreadId]12627+ : [],12628+ ),1251812629 );12630+ const sideChatPlans: Array<ThreadDeletionPlan> = [];12631+ for (const threadId of forkTargets) {12632+ const sideChat = yield* projectionStore.getThread(threadId).pipe(12633+ Effect.catchTags({ ProjectionStoreThreadNotFoundError: () => Effect.succeed(null) }),12634+ Effect.mapError((cause) => new OrchestratorProjectionError({ threadId, cause })),12635+ );12636+ if (sideChat?.lineage.sideChat !== true || sideChat.deletedAt !== null) continue;12637+ const sideChatDeletion = yield* planDeletion({apps/web/src/components/chat/useChatShortcuts.ts line 108OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -100,3 +105,4 @@100105 });101106 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- attaches window keydown listeners for chat shortcuts and find dismissal for the component's lifetime102107 useEffect(() => {108+ if (embedded) return;apps/server/src/orchestration-v2/ProviderTurnStartService.ts line 355OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -348,3 +349,7 @@348349 ))),349350 ))),350351 );352+ const sideChatContext =353+ projection.contextHandoffs.find(354+ (handoff) =>355+ handoff.targetRunId === run.id &&apps/web/src/components/ChatView.tsx line 3937Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3807,6 +3871,17 @@3807- keybindings={keybindings}3808- onAddTerminalContext={addTerminalContextToDraftStable}3809- />3871+ {embedded ? null : (3872+ <ChatTerminalDrawers3873+ activeThreadKey={activeThreadKey}3874+ activeTerminalOpen={Boolean(terminalUiState.terminalOpen)}3875+ composerHeight={composerReservedHeight}3876+ launchContext={activeTerminalLaunchContext ?? null}3877+ splitShortcutLabel={splitTerminalShortcutLabel ?? undefined}3878+ splitVerticalShortcutLabel={splitTerminalVerticalShortcutLabel ?? undefined}3879+ newShortcutLabel={newTerminalShortcutLabel ?? undefined}3880+ closeShortcutLabel={closeTerminalShortcutLabel ?? undefined}3881+ keybindings={keybindings}3882+ onAddTerminalContext={addTerminalContextToDraftStable}3883+ />3884+ )}38103885 </div>381138863812- {rightPanelPresent && activeThreadRef ? (3887+ {rightPanelPresent && activeThreadRef && !embedded ? (apps/web/src/components/chat/useComposerSend.ts line 746OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -730,14 +733,14 @@730733 }731734 return;732735 }733- const standaloneSlashCommand =734- sendInteractionModeEnabled &&736+ const textOnly =735737 composerImages.length === 0 &&736738 composerFiles.length === 0 &&737739 sendableComposerTerminalContexts.length === 0 &&738740 composerPreviewAnnotations.length === 0 &&739741 composerReviewComments.length === 0 &&740742 composerThreadContexts.length === 0 &&741- composerEnvironmentContexts.length === 0742- ? parseStandaloneComposerSlashCommand(trimmed)743- : null;743+ composerEnvironmentContexts.length === 0;744+ const standaloneSlashCommand =745+ sendInteractionModeEnabled && textOnly ? parseStandaloneComposerSlashCommand(trimmed) : null;746+ const sideChatCommand = onSideChat ? parseSideChatCommand(trimmed) : null;apps/web/src/components/chat/useComposerSend.ts line 758OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -739,5 +741,18 @@739741 composerReviewComments.length === 0 &&740742 composerThreadContexts.length === 0 &&741- composerEnvironmentContexts.length === 0742- ? parseStandaloneComposerSlashCommand(trimmed)743- : null;743+ composerEnvironmentContexts.length === 0;744+ const standaloneSlashCommand =745+ sendInteractionModeEnabled && textOnly ? parseStandaloneComposerSlashCommand(trimmed) : null;746+ const sideChatCommand = onSideChat ? parseSideChatCommand(trimmed) : null;747+ if (onSideChat && sideChatCommand) {748+ if (!textOnly) {749+ toastManager.add(750+ stackedThreadToast({751+ type: "warning",752+ title: "Side chats take text only",753+ description: "Remove the attachments and context, then send it again.",754+ }),755+ );756+ return;757+ }758+ onSideChat(sideChatCommand.prompt);apps/web/src/hooks/useRightPanelSurfaceClose.ts line 83Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -60,3 +69,9 @@6069 terminalActions.closeTerminalSession(terminalId);6170 }6271 }72+ if (73+ surface.kind === "side-chat" &&74+ readEnvironmentScope(ref.environmentId, AuthOrchestrationOperateScope) &&75+ readThreadShell(scopeThreadRef(ref.environmentId, surface.threadId))?.latestRun === null76+ ) {77+ void deleteThread({
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts lines 4544 to 4545OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -4540,3 +4540,6 @@45404540 planSelectionTransition: Effect.fn("ClaudeAdapterV2.planSelectionTransition")(function () {45414541 return Effect.succeed(turnScopedSelectionTransition());45424542 }),4543+ // Without an SDK message cursor, forkSession copies the whole session, including a live turn.4544+ canForkAtTurn: (turn) =>4545+ turn.nativeTurnRef?.nativeId != null && !isSyntheticClaudeTurnId(turn.nativeTurnRef.nativeId),apps/web/src/components/chat/useComposerSend.ts lines 744 to 747OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -730,14 +733,15 @@730733 }731734 return;732735 }733- const standaloneSlashCommand =734- sendInteractionModeEnabled &&736+ const textOnly =735737 composerImages.length === 0 &&736738 composerFiles.length === 0 &&737739 sendableComposerTerminalContexts.length === 0 &&738740 composerPreviewAnnotations.length === 0 &&739741 composerReviewComments.length === 0 &&740742 composerThreadContexts.length === 0 &&741- composerEnvironmentContexts.length === 0742- ? parseStandaloneComposerSlashCommand(trimmed)743- : null;743+ composerEnvironmentContexts.length === 0;744+ const standaloneSlashCommand =745+ sendInteractionModeEnabled && textOnly ? parseStandaloneComposerSlashCommand(trimmed) : null;746+ const sideChatCommand = onSideChat ? parseSideChatCommand(trimmed) : null;747+ if (onSideChat && sideChatCommand) {apps/web/src/components/chat/useComposerSend.ts lines 758 to 760OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -741,3 +743,18 @@741- composerEnvironmentContexts.length === 0742- ? parseStandaloneComposerSlashCommand(trimmed)743- : null;743+ composerEnvironmentContexts.length === 0;744+ const standaloneSlashCommand =745+ sendInteractionModeEnabled && textOnly ? parseStandaloneComposerSlashCommand(trimmed) : null;746+ const sideChatCommand = onSideChat ? parseSideChatCommand(trimmed) : null;747+ if (onSideChat && sideChatCommand) {748+ if (!textOnly) {749+ toastManager.add(750+ stackedThreadToast({751+ type: "warning",752+ title: "Side chats take text only",753+ description: "Remove the attachments and context, then send it again.",754+ }),755+ );756+ return;757+ }758+ onSideChat(sideChatCommand.prompt);759+ promptRef.current = "";760+ clearComposerDraftContent(composerDraftTarget);
- apps/web/src/components/chat/useComposerSend.ts lines 514 to 514OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -474,0 +494,21 @@494+ sendCtx.threadContexts.length > 0 ||495+ sendCtx.environmentContexts.length > 0496+ ) {497+ toastManager.add(498+ stackedThreadToast({499+ type: "warning",500+ title: "Side chats take text only",501+ description: "Remove the attachments and context, then send it again.",502+ }),503+ );504+ return;505+ }506+ const started = await onSideChat(sideChatCommand.prompt);507+ // Clear only what was sent; the user may have edited the draft or left meanwhile.508+ if (509+ started &&510+ currentRouteThreadKeyRef.current === routeThreadKey &&511+ promptRef.current === promptAtSend512+ ) {513+ promptRef.current = "";514+ clearComposerDraftContent(composerDraftTarget);packages/client-runtime/src/state/threadShell.ts lines 518 to 524Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -443,0 +499,21 @@499+ const ref = parseThreadKey(key);500+ let previous = EMPTY_THREAD_SHELLS;501+ return Atom.make((get) => {502+ const sideChats = get(environmentSideChatsByParentAtom(ref.environmentId)).get(ref.threadId);503+ if (sideChats === undefined) {504+ previous = EMPTY_THREAD_SHELLS;505+ return previous;506+ }507+ const subagentRequests = get(pendingSubagentRequestsAtom(ref.environmentId));508+ const next = sideChats.map((thread) =>509+ scopedThread(ref.environmentId, thread, subagentRequests),510+ );511+ if (512+ previous.length === next.length &&513+ previous.every(514+ (thread, index) =>515+ thread.id === next[index]?.id &&516+ thread.title === next[index]?.title &&517+ thread.hasPendingApprovals === next[index]?.hasPendingApprovals &&518+ thread.hasPendingUserInput === next[index]?.hasPendingUserInput,519+ )apps/server/src/orchestration-v2/Orchestrator.ts line 13193OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -13027,3 +13183,11 @@1302713183 commandThreadId(command),1302813184 dispatchWithReceiptEffect(command),1302913185 );13186+ // A parent's lock comes before its side chats' locks, so a delete cascade and a side chat13187+ // fork or command never interleave.13188+ if (13189+ command.type === "thread.fork" &&13190+ command.sideChat === true &&13191+ command.sourceThreadId !== command.targetThreadId13192+ )13193+ return yield* threadDispatch.withLock(command.sourceThreadId, dispatch);
- apps/web/src/hooks/useRightPanelSurfaceClose.ts line 82OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -60,3 +69,14 @@6069 terminalActions.closeTerminalSession(terminalId);6170 }6271 }72+ if (73+ surface.kind === "side-chat" &&74+ readEnvironmentScope(ref.environmentId, AuthOrchestrationOperateScope)75+ ) {76+ // The server keeps a side chat with a run or message; this client's shell can lag one.77+ void deleteThread({78+ environmentId: ref.environmentId,79+ input: { threadId: surface.threadId, onlyIfUnused: true },80+ });81+ if (82+ readThreadShell(scopeThreadRef(ref.environmentId, surface.threadId))?.latestRun !== null
- apps/web/src/components/RightPanelTabs.tsx lines 699 to 699OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -655,3 +691,9 @@655691 }656692 }657693694+// Static dots: a side chat tab can stay open for a whole run.695+function SideChatTabIcon(props: { environmentId: EnvironmentId | null; threadId: ThreadId }) {696+ const shell = useQuietThreadShell(697+ props.environmentId === null ? null : scopeThreadRef(props.environmentId, props.threadId),698+ );699+ const needsYou = shell !== null && (shell.hasPendingApprovals || shell.hasPendingUserInput);
- apps/web/src/browser/openFileInPreview.ts line 70OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -63,5 +67,4 @@6367 if (defaults instanceof BrowserSettingsReadError) {6468 return AsyncResult.failure(Cause.fail(defaults));6569 }66- const runtime = previewRuntimeFor(input.threadRef.environmentId);67- const previousActiveTabId = readThreadPreviewState(input.threadRef).activeTabId;70+ const threadRef = rightPanelHostRef(input.threadRef);
- apps/web/src/components/RightPanelTabs.tsx line 726Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -657,0 +694,21 @@694+// Static dots: a side chat tab can stay open for a whole run.695+function SideChatTabIcon(props: { environmentId: EnvironmentId | null; threadId: ThreadId }) {696+ const shell = useQuietThreadShell(697+ props.environmentId === null ? null : scopeThreadRef(props.environmentId, props.threadId),698+ );699+ const needsYou =700+ shell !== null &&701+ (shell.hasPendingApprovals ||702+ shell.hasPendingUserInput ||703+ Boolean(shell.pendingSubagentRequest));704+ const running = shell !== null && threadRuntimeIsActive(shell.runtime);705+ return (706+ <>707+ <MessagesSquare className="size-3 shrink-0" />708+ {needsYou || running ? (709+ <span710+ className={cn(711+ "absolute -top-0.5 -right-0.5 size-1.5 rounded-full",712+ needsYou ? "bg-info" : "bg-muted-foreground",713+ )}714+ aria-hidden
- apps/web/src/components/chat/useComposerSend.ts line 490OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -472,3 +482,9 @@472482 return;473483 }474484 const sendCtx = composerRef.current?.getSendContext();485+ // `/side` beats an open question and a plan follow-up, which would send the text to main.486+ const sideChatCommand =487+ sendCtx && !directAnnotation && !queuedRunEdit.isEditing488+ ? parseSideChatCommand(promptAtSend)489+ : null;490+ if (sideChatDisabledReason !== null && sideChatCommand) {
- apps/server/src/orchestration-v2/ContextHandoffService.ts line 155OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -98,0 +135,21 @@135+ "orchestrationV2.contextHandoff.readInheritedHandoffItems",136+)(function* (137+ projectionStore: Pick<ProjectionStoreV2Shape, "getThreadRecords">,138+ thread: OrchestrationV2AppThread,139+) {140+ const segments: Array<ReadonlyArray<OrchestrationV2TurnItem>> = [];141+ const seen = new Set([thread.id]);142+ let current = thread;143+ while (144+ current.forkedFrom?.type === "run" &&145+ current.lineage.sideChat !== true &&146+ !seen.has(current.forkedFrom.threadId)147+ ) {148+ const { threadId, runId } = current.forkedFrom;149+ seen.add(threadId);150+ const source = yield* projectionStore.getThreadRecords(threadId, ["runs"]);151+ const forkRun = source.runs.find((run) => run.id === runId);152+ if (forkRun === undefined) break;153+ const { turnItems } = yield* projectionStore.getThreadRecords(threadId, ["turnItems"], {154+ turnItemRunIds: [155+ ...source.runs.filter((run) => run.ordinal <= forkRun.ordinal).map((run) => run.id),
- apps/web/src/components/ChatView.tsx lines 1626 to 1626OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1590,4 +1622,5 @@15901622 worktreePath: activeThread?.worktreePath ?? null,15911623 })15921624 : null;1593- const gitStatusCwd = activeThread?.worktreePath ?? gitCwd;1625+ // The parent's view already watches the worktree an embedded side chat shares.1626+ const gitStatusCwd = embedded ? null : (activeThread?.worktreePath ?? gitCwd);
t3dotgg(GitHub profile, opens in a new tab) changed the title
t3dotgg(GitHub profile, opens in a new tab) changed the title
t3dotgg(GitHub profile, opens in a new tab) changed the title
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.




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