Skip to content

Commit 1aea09e

Browse files
committed
feat: side chats and forking
Users asked for a Codex-style /side conversation that inherits the current thread's context without bloating it, and for branching a conversation from a completed response into a new thread. Both are the same mechanism with two presentations. A fork is a new thread in the same project that inherits the source's model, modes, branch, and worktree and records immutable lineage (source thread, turn, and message). Its transcript starts empty; the provider session carries the inherited context and is created lazily on the fork's first turn: Codex uses thread/fork with the source turn as lastTurnId, Claude resumes the source session with forkSession, OpenCode uses session.fork. Cursor and Grok report the capability as unsupported and the UI hides or disables the actions. A fork never resumes the source session, and once its own session exists that session is what restarts resume. A side chat is a fork flagged sideChat. It is hidden from every thread list and rendered in the right panel beside its parent on web and desktop, and as a full-screen thread on mobile. Promote flips the flag through the existing meta update, closing a tab is local, and delete is the normal thread delete. Forked threads show a "Forked from" anchor back to their source. Entry points: a fork action on completed assistant responses, the thread header menu, the command palette, and chat.sideChat (mod+shift+b) plus an unbound chat.forkThread. Deleting a parent counts its side chats when deciding whether a worktree is orphaned. Implemented by GPT-5.6 Sol via Codex and Claude Fable 5.1 via Claude Code, with independent designs and two rounds of adversarial review by Claude Opus 5 and GPT-5.6 Sol.
1 parent ef6cc0b commit 1aea09e

95 files changed

Lines changed: 4095 additions & 190 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/home/homeThreadList.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,32 @@ function buildGroups(
7272
}
7373

7474
describe("buildHomeThreadGroups", () => {
75+
it("does not place side chats in the home list", () => {
76+
const environmentId = EnvironmentId.make("environment-1");
77+
const project = makeProject({
78+
environmentId,
79+
id: ProjectId.make("project-1"),
80+
title: "Project",
81+
});
82+
const main = makeThread({
83+
environmentId,
84+
id: ThreadId.make("thread-main"),
85+
projectId: project.id,
86+
title: "Main",
87+
});
88+
const sideChat = makeThread({
89+
environmentId,
90+
id: ThreadId.make("thread-side"),
91+
projectId: project.id,
92+
title: "Side chat",
93+
sideChat: true,
94+
});
95+
96+
expect(buildGroups([project], [main, sideChat])[0]?.threads.map((thread) => thread.id)).toEqual(
97+
[main.id],
98+
);
99+
});
100+
75101
it("builds one v2 scope for the same repository across environments", () => {
76102
const localEnvironmentId = EnvironmentId.make("environment-local");
77103
const remoteEnvironmentId = EnvironmentId.make("environment-remote");

‎apps/mobile/src/features/home/homeThreadList.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as Order from "effect/Order";
2626

2727
import { scopedProjectKey } from "../../lib/scopedEntities";
2828
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
29+
import { visibleTopLevelThreads } from "../threads/sideChats.logic";
2930

3031
export type HomeProjectSortOrder = Exclude<SidebarProjectSortOrder, "manual">;
3132

@@ -96,7 +97,7 @@ export function sortHomeProjectScopes(input: {
9697
);
9798
};
9899

99-
for (const thread of input.threads) {
100+
for (const thread of visibleTopLevelThreads(input.threads)) {
100101
if (thread.archivedAt !== null) continue;
101102
recordActivity(
102103
scopeKeyByProjectRef.get(scopedProjectKey(thread.environmentId, thread.projectId)),
@@ -273,7 +274,7 @@ export function buildHomeThreadGroups(input: {
273274
groups.get(groupKey)?.pendingTasks.push(pendingTask);
274275
}
275276

276-
for (const thread of input.threads) {
277+
for (const thread of visibleTopLevelThreads(input.threads)) {
277278
if (thread.archivedAt !== null) {
278279
continue;
279280
}

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,3 +569,16 @@ export function useArchivedThreadListActions(
569569

570570
return { unarchiveThread, confirmDeleteThread };
571571
}
572+
573+
export function useThreadDeleteAction(
574+
onDeleted: (thread: EnvironmentThreadShell) => void,
575+
): (thread: EnvironmentThreadShell) => void {
576+
const handleCompleted = useCallback(
577+
(action: ThreadListAction, thread: EnvironmentThreadShell) => {
578+
if (action === "delete") onDeleted(thread);
579+
},
580+
[onDeleted],
581+
);
582+
const executeAction = useThreadActionExecutor(handleCompleted);
583+
return useConfirmDeleteThread(executeAction);
584+
}

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import type {
1818
ProviderInteractionMode,
1919
RuntimeMode,
2020
ServerConfig as T3ServerConfig,
21+
ServerProviderSessionFork,
2122
ThreadId,
23+
TurnId,
2224
UserInputQuestion,
2325
} from "@t3tools/contracts";
2426
import * as Haptics from "expo-haptics";
@@ -148,6 +150,13 @@ export interface ThreadDetailScreenProps {
148150
) => void;
149151
readonly onSubmitUserInput: () => Promise<unknown>;
150152
readonly showContent?: boolean;
153+
readonly forkCapability?: ServerProviderSessionFork;
154+
readonly onForkAssistantMessage?: (input: {
155+
readonly messageId: MessageId;
156+
readonly turnId: TurnId;
157+
readonly sideChat: boolean;
158+
}) => void;
159+
readonly forkOrigin?: { readonly title: string; readonly onPress: () => void };
151160
}
152161

153162
function latestStreamingAssistantMessage(
@@ -717,6 +726,9 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
717726
skills={selectedProviderSkills}
718727
onUseArtifactTemplate={handleUseArtifactTemplate}
719728
loadEarlier={props.loadEarlier ?? null}
729+
forkCapability={props.forkCapability}
730+
onForkAssistantMessage={props.onForkAssistantMessage}
731+
forkOrigin={props.forkOrigin}
720732
/>
721733
</View>
722734
) : (

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
ChatImageAttachment,
99
EnvironmentId,
1010
MessageId,
11+
ServerProviderSessionFork,
1112
ThreadId,
1213
TurnId,
1314
} from "@t3tools/contracts";
@@ -110,6 +111,7 @@ import {
110111
type MediaVideoPreviewSource,
111112
} from "../../lib/videoPreviewSource";
112113
import { CopyTextButton } from "../../components/CopyTextButton";
114+
import { ControlPillMenu } from "../../components/ControlPill";
113115
import {
114116
parseReviewCommentMessageSegments,
115117
type ReviewInlineComment,
@@ -178,6 +180,7 @@ import {
178180
} from "../files/filePath";
179181
import { MARKDOWN_IMAGE_MAX_WIDTH, resolveMarkdownImageDisplaySize } from "./markdownImageSize";
180182
import { fileChipMenu, resolveFileChipTarget, type FileChipAction } from "./fileChipMenu";
183+
import { canForkMobileAssistantMessage } from "./sideChats.logic";
181184

182185
const WIDE_MARKDOWN_BLOCK_OPTIONS = {
183186
// Native iOS blockquotes and adjacent selectable text are separate layout
@@ -245,6 +248,13 @@ export interface ThreadFeedProps {
245248
readonly loading: boolean;
246249
readonly onLoadEarlier: () => void;
247250
} | null;
251+
readonly forkCapability?: ServerProviderSessionFork;
252+
readonly onForkAssistantMessage?: (input: {
253+
readonly messageId: MessageId;
254+
readonly turnId: TurnId;
255+
readonly sideChat: boolean;
256+
}) => void;
257+
readonly forkOrigin?: { readonly title: string; readonly onPress: () => void };
248258
}
249259

250260
function MessageAttachmentImage(props: {
@@ -1468,6 +1478,11 @@ function renderFeedEntry(
14681478
readonly workGroupScrollPositions: Map<string, ThreadWorkGroupScrollPosition>;
14691479
readonly terminalAssistantMessageIds: ReadonlySet<string>;
14701480
readonly unsettledTurnId: TurnId | null;
1481+
readonly latestTurn: ThreadFeedLatestTurn | null;
1482+
readonly forkCapability: ServerProviderSessionFork | undefined;
1483+
readonly onForkAssistantMessage:
1484+
| ((input: { messageId: MessageId; turnId: TurnId; sideChat: boolean }) => void)
1485+
| undefined;
14711486
readonly onCopyWorkRow: (rowId: string, value: string) => void;
14721487
readonly onToggleWorkGroup: (groupId: string, anchorKey: string) => void;
14731488
readonly onToggleWorkRow: (rowId: string, anchorKey: string) => void;
@@ -1556,6 +1571,13 @@ function renderFeedEntry(
15561571
props.terminalAssistantMessageIds.has(message.id) &&
15571572
!assistantTurnStillInProgress &&
15581573
!message.streaming;
1574+
const canFork = canForkMobileAssistantMessage({
1575+
capability: props.forkCapability,
1576+
completed: showAssistantMeta,
1577+
messageTurnId: message.turnId,
1578+
latestTurn: props.latestTurn,
1579+
});
1580+
const forkTurnId = canFork ? message.turnId : null;
15591581

15601582
if (isUser) {
15611583
const enterAnimated = isFreshTimestamp(message.createdAt);
@@ -1680,6 +1702,36 @@ function renderFeedEntry(
16801702
buttonSize={28}
16811703
iconSize={13}
16821704
/>
1705+
{forkTurnId && props.onForkAssistantMessage ? (
1706+
<ControlPillMenu
1707+
title="Fork response"
1708+
actions={[
1709+
{ id: "side-chat", title: "Open side chat" },
1710+
{ id: "fork-thread", title: "Fork to new thread" },
1711+
]}
1712+
onPressAction={({ nativeEvent }) => {
1713+
props.onForkAssistantMessage?.({
1714+
messageId: message.id,
1715+
turnId: forkTurnId,
1716+
sideChat: nativeEvent.event === "side-chat",
1717+
});
1718+
}}
1719+
>
1720+
<View
1721+
accessible
1722+
accessibilityRole="button"
1723+
accessibilityLabel="Fork from this response"
1724+
className="size-7 items-center justify-center"
1725+
>
1726+
<SymbolView
1727+
name="arrow.branch"
1728+
size={13}
1729+
tintColor={iconSubtleColor}
1730+
type="monochrome"
1731+
/>
1732+
</View>
1733+
</ControlPillMenu>
1734+
) : null}
16831735
<Text className="font-t3-medium text-xs tabular-nums text-adaptive-neutral-600-400">
16841736
{timestampLabel}
16851737
</Text>
@@ -2724,6 +2776,9 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
27242776
workGroupScrollPositions,
27252777
terminalAssistantMessageIds,
27262778
unsettledTurnId,
2779+
latestTurn: props.latestTurn,
2780+
forkCapability: props.forkCapability,
2781+
onForkAssistantMessage: props.onForkAssistantMessage,
27272782
onCopyWorkRow,
27282783
onToggleWorkGroup,
27292784
onToggleWorkRow,
@@ -2753,6 +2808,9 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
27532808
workGroupScrollPositions,
27542809
terminalAssistantMessageIds,
27552810
unsettledTurnId,
2811+
props.forkCapability,
2812+
props.latestTurn,
2813+
props.onForkAssistantMessage,
27562814
iconSubtleColor,
27572815
userBubbleColor,
27582816
markdownStyles,
@@ -2914,6 +2972,26 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
29142972
ListHeaderComponent={
29152973
<>
29162974
{usesNativeAutomaticInsets ? null : <View style={{ height: topContentInset }} />}
2975+
{props.forkOrigin ? (
2976+
<Pressable
2977+
accessibilityRole="link"
2978+
onPress={props.forkOrigin.onPress}
2979+
className="mb-3 self-start flex-row items-center gap-1.5 rounded-lg bg-subtle px-2.5 py-2 active:opacity-70"
2980+
>
2981+
<SymbolView
2982+
name="arrow.branch"
2983+
size={14}
2984+
tintColorClassName="accent-icon-subtle"
2985+
type="monochrome"
2986+
/>
2987+
<Text
2988+
numberOfLines={1}
2989+
className="max-w-[280px] font-t3-medium text-xs text-foreground-muted"
2990+
>
2991+
Forked from {props.forkOrigin.title}
2992+
</Text>
2993+
</Pressable>
2994+
) : null}
29172995
{props.loadEarlier != null ? (
29182996
<Pressable
29192997
onPress={props.loadEarlier.onLoadEarlier}

‎apps/mobile/src/features/threads/ThreadGitControls.tsx‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ type ThreadGitControlsProps = ThreadGitMenuProps & {
104104
readonly onOpenTerminal: (terminalId?: string | null) => void;
105105
readonly onOpenNewTerminal: () => void;
106106
readonly onRunProjectScript: (script: ProjectScript) => Promise<void>;
107+
readonly threadMenu?: {
108+
readonly onDelete?: () => void;
109+
readonly onPromote?: () => void;
110+
readonly sideChats: ReadonlyArray<{
111+
readonly id: ThreadId;
112+
readonly title: string;
113+
readonly onOpen: () => void;
114+
}>;
115+
};
107116
};
108117

109118
function useThreadGitControlModel(props: ThreadGitMenuProps) {
@@ -409,13 +418,38 @@ export function useThreadGitCenterHeaderItems(props: ThreadGitControlsProps): He
409418
export function ThreadGitControls(props: ThreadGitControlsProps) {
410419
const model = useThreadGitControlModel(props);
411420
const showActionControls = props.showActionControls ?? true;
421+
const threadMenu = props.threadMenu;
412422

413423
if (!showActionControls) {
414424
return null;
415425
}
416426

417427
return (
418428
<NativeHeaderToolbar placement="right">
429+
{showActionControls &&
430+
(threadMenu?.onDelete || threadMenu?.onPromote || (threadMenu?.sideChats.length ?? 0) > 0) ? (
431+
<NativeHeaderToolbar.Menu icon="ellipsis" separateBackground>
432+
{threadMenu?.onPromote ? (
433+
<NativeHeaderToolbar.MenuAction icon="arrow.up.right" onPress={threadMenu.onPromote}>
434+
<NativeHeaderToolbar.Label>Promote to thread</NativeHeaderToolbar.Label>
435+
</NativeHeaderToolbar.MenuAction>
436+
) : null}
437+
{threadMenu && threadMenu.sideChats.length > 0 ? (
438+
<NativeHeaderToolbar.Menu title="Side chats" icon="text.bubble" inline>
439+
{threadMenu.sideChats.map((sideChat) => (
440+
<NativeHeaderToolbar.MenuAction key={sideChat.id} onPress={sideChat.onOpen}>
441+
<NativeHeaderToolbar.Label>{sideChat.title}</NativeHeaderToolbar.Label>
442+
</NativeHeaderToolbar.MenuAction>
443+
))}
444+
</NativeHeaderToolbar.Menu>
445+
) : null}
446+
{threadMenu?.onDelete ? (
447+
<NativeHeaderToolbar.MenuAction destructive icon="trash" onPress={threadMenu.onDelete}>
448+
<NativeHeaderToolbar.Label>Delete</NativeHeaderToolbar.Label>
449+
</NativeHeaderToolbar.MenuAction>
450+
) : null}
451+
</NativeHeaderToolbar.Menu>
452+
) : null}
419453
{showActionControls && props.auxiliaryPaneControl ? (
420454
<NativeHeaderToolbar.Button
421455
accessibilityLabel={props.auxiliaryPaneControl.accessibilityLabel}

0 commit comments

Comments
 (0)