Skip to content
TypeScript

feat(mobile): open threads and devices in a resizable iOS inspector (#24985)

Julius Marminge92125d612d11
diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx
index 8a07f8b7a08..b6b747e9dab 100644
--- a/apps/mobile/src/Stack.tsx
+++ b/apps/mobile/src/Stack.tsx
@@ -65,7 +65,10 @@ import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSh
import { ThreadAgentsSheet } from "./features/threads/ThreadAgentsSheet";
import { ThreadBackgroundWorkSheet } from "./features/threads/ThreadBackgroundWorkSheet";
import { ThreadQueueSheet } from "./features/threads/ThreadQueueControl";
-import { ThreadRouteScreen } from "./features/threads/ThreadRouteScreen";
+import {
+ FullscreenThreadRouteScreen,
+ ThreadRouteScreen,
+} from "./features/threads/ThreadRouteScreen";
import { McpAppFullscreenScreen } from "./features/threads/McpAppFullscreenScreen";
import { ConnectionsRouteScreen } from "./features/connection/ConnectionsRouteScreen";
import { ConnectionsNewRouteScreen } from "./features/connection/ConnectionsNewRouteScreen";
@@ -813,6 +816,13 @@ const RootStackConfig = createWorkspaceStackNavigator({
linking: `${THREAD_LINKING_PREFIX}/terminal`,
options: SOLID_HEADER_OPTIONS,
}),
+ ThreadInspectorFullscreen: createNativeStackScreen({
+ screen: FullscreenThreadRouteScreen,
+ options: {
+ ...THREAD_HEADER_OPTIONS,
+ presentation: "fullScreenModal",
+ },
+ }),
ThreadDevicePreview: createNativeStackScreen({
screen: DevicePreviewRouteScreen,
linking: `${THREAD_LINKING_PREFIX}/devices`,
diff --git a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
index 3e5899f870a..850049f111a 100644
--- a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
+++ b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
@@ -9,7 +9,7 @@ import {
import { useIsFocused, useNavigation, type StaticScreenProps } from "@react-navigation/native";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import * as Cause from "effect/Cause";
-import { useEffect, useRef, useState, type RefObject } from "react";
+import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
import * as Haptics from "expo-haptics";
import { Accelerometer } from "expo-sensors";
import { AppState, BackHandler, Pressable, StatusBar, View } from "react-native";
@@ -47,6 +47,7 @@ const OVERLAY_EXITING = FadeOut.duration(120).reduceMotion(ReduceMotion.System);
type DevicePreviewRouteScreenProps = StaticScreenProps<{
readonly environmentId: string;
readonly threadId: string;
+ readonly deviceKey?: string;
}>;
export function DevicePreviewRouteScreen({ route }: DevicePreviewRouteScreenProps) {
@@ -62,27 +63,33 @@ export function DevicePreviewRouteScreen({ route }: DevicePreviewRouteScreenProp
<DevicePreviewScreen
environmentId={EnvironmentId.make(environmentId)}
threadId={ThreadId.make(threadId)}
+ initialDeviceKey={route.params.deviceKey}
onClose={onClose}
/>
);
}
-function DevicePreviewScreen({
+export function DevicePreviewScreen({
environmentId,
threadId,
onClose,
+ onMaximize,
+ initialDeviceKey,
}: {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
readonly onClose: () => void;
+ readonly onMaximize?: (deviceKey: string | null) => void;
+ readonly initialDeviceKey?: string;
}) {
+ const embedded = onMaximize !== undefined;
const insets = useSafeAreaInsets();
// NativeColumnContent already insets the sides, so only a book fold moves the reveal handle.
const handleBounds = deriveBottomControlInsets(useNativeColumnLayoutMetrics());
const { themeVariables } = useAppearancePreferences();
const focused = useIsFocused();
const [foreground, setForeground] = useState(AppState.currentState !== "background");
- const [selectedKey, setSelectedKey] = useState<string | null>(null);
+ const [selectedKey, setSelectedKey] = useState<string | null>(initialDeviceKey ?? null);
const [inputConnected, setInputConnected] = useState(false);
const [streamAttempt, setStreamAttempt] = useState(0);
const [shuttingDown, setShuttingDown] = useState(false);
@@ -93,10 +100,13 @@ function DevicePreviewScreen({
const state = useEnvironmentQuery(deviceEnvironment.state({ environmentId, input: {} }));
const previews = threadDevicePreviews(state.data, threadId);
const preview = selectedThreadDevicePreview(previews, selectedKey);
- const onInputConnected = async (connected: boolean) => {
- setInputConnected(connected);
- if (connected) setControlsVisible(false);
- };
+ const onInputConnected = useCallback(
+ async (connected: boolean) => {
+ setInputConnected(connected);
+ if (connected && !embedded) setControlsVisible(false);
+ },
+ [embedded],
+ );
useEffect(() => {
const subscription = AppState.addEventListener("change", (state) =>
setForeground(state !== "background"),
@@ -107,7 +117,7 @@ function DevicePreviewScreen({
if (focused && state.data !== null && previews.length === 0) onClose();
}, [focused, state.data, previews.length, onClose]);
useEffect(() => {
- if (!focused || !foreground) return;
+ if (!focused || !foreground || embedded) return;
const shaken = createShakeDetector();
Accelerometer.setUpdateInterval(50);
const subscription = Accelerometer.addListener((sample) => {
@@ -116,7 +126,7 @@ function DevicePreviewScreen({
setControlsVisible((visible) => !visible);
});
return () => subscription.remove();
- }, [focused, foreground]);
+ }, [focused, foreground, embedded]);
useEffect(() => {
if (controlsVisible) return;
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
@@ -260,7 +270,23 @@ function DevicePreviewScreen({
];
return (
<View className="flex-1" style={{ backgroundColor: themeVariables["--color-sheet-solid"] }}>
- <StatusBar hidden animated />
+ {!embedded ? <StatusBar hidden animated /> : null}
+ {embedded ? (
+ <View
+ className="flex-row items-center gap-1 px-2 pb-2"
+ style={{ paddingTop: Math.max(insets.top, 8) }}
+ >
+ <SheetCloseButton accessibilityLabel="Close device preview" onClose={onClose} />
+ <AppText numberOfLines={1} className="min-w-0 flex-1 font-t3-medium text-sm">
+ {preview?.name ?? "Devices"}
+ </AppText>
+ <ControlPill
+ accessibilityLabel="Maximize device"
+ icon="arrow.up.left.and.arrow.down.right"
+ onPress={() => onMaximize(preview?.key ?? null)}
+ />
+ </View>
+ ) : null}
{preview && focused && foreground ? (
<OpenDevicePreview
key={`${preview.key}:${streamAttempt}`}
@@ -285,7 +311,20 @@ function DevicePreviewScreen({
) : null}
</View>
)}
- {controlsVisible ? (
+ {embedded ? (
+ <View
+ className="flex-row items-center justify-center gap-2 px-3 py-2"
+ style={{ paddingBottom: Math.max(insets.bottom, 8) }}
+ >
+ <ControlPill
+ accessibilityLabel="Home"
+ icon="house"
+ disabled={!inputConnected}
+ onPress={pressHome}
+ />
+ <DeviceOptionsMenu items={menuItems} />
+ </View>
+ ) : controlsVisible ? (
<Animated.View
entering={OVERLAY_ENTERING}
exiting={OVERLAY_EXITING}
@@ -321,9 +360,9 @@ function DevicePreviewScreen({
accessibilityLabel="Show device controls"
accessibilityHint="Shaking the phone also shows them"
hitSlop={12}
- className="absolute h-6 w-16 items-center justify-center self-center"
+ className="absolute h-11 w-16 items-center justify-center self-center"
style={{
- top: Math.max(insets.top - 18, 4),
+ top: Math.max(insets.top, 12),
transform: [{ translateX: (handleBounds.left - handleBounds.right) / 2 }],
}}
onPress={() => setControlsVisible(true)}
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index afb6366b6ee..7dd22f8fa3e 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -324,6 +324,7 @@ function AdaptiveWorkspaceLayoutContent(
deriveWorkspacePaneLayout({
layout,
viewportWidth: width,
+ nativeWorkspace,
primarySidebarPreferredVisible: showPrimarySidebar,
auxiliaryPanePreferredVisible,
auxiliaryPaneRole,
@@ -334,6 +335,7 @@ function AdaptiveWorkspaceLayoutContent(
auxiliaryPaneRole,
auxiliaryPanePreferredWidth,
layout,
+ nativeWorkspace,
showPrimarySidebar,
width,
],
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index e94a5ea9296..0b2efd9de24 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -29,8 +29,10 @@ import {
useState,
type ComponentProps,
} from "react";
-import { View } from "react-native";
+import { StyleSheet, useWindowDimensions, View } from "react-native";
import { Split, type SplitHostCommands } from "react-native-screens";
+import { SafeAreaView } from "react-native-safe-area-context";
+import { GestureHandlerRootView } from "react-native-gesture-handler";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { WorkspaceTabsProvider, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
@@ -42,6 +44,7 @@ import { setNativelyPoppingWorkspaceRoute } from "../workspace/workspace-detail-
import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
+import { WorkspacePaneDivider } from "./workspace-pane-divider";
import { WorkspaceEmptyDetail } from "./WorkspaceEmptyDetail";
import { NativeColumnContent as ColumnContent } from "../../native/NativeColumnContent.ios";
import {
@@ -185,6 +188,15 @@ function WorkspaceColumns(
sidebarByOrientation,
} = useAdaptiveWorkspaceLayout();
const deviceType = useDeviceType();
+ const windowDimensions = useWindowDimensions();
+ const nativeMetrics = useNativeLayoutMetrics();
+ const viewportWidth = nativeMetrics?.width ?? windowDimensions.width;
+ const [inspectorWidthFraction, setInspectorWidthFraction] = useState(0.4);
+ const inspectorWidth = Math.max(
+ 260,
+ Math.min(viewportWidth * 0.6, viewportWidth * inspectorWidthFraction),
+ );
+ const resizeStartWidth = useRef(inspectorWidth);
const settingsDetailIn = (detail: readonly Route[]) =>
layout.usesSplitView && detail[0] && isSettingsRoute(detail[0].name) ? detail[0] : undefined;
// Split screens must remain mounted while UIKit animates a detached route away.
@@ -361,6 +373,10 @@ function WorkspaceColumns(
maximumPrimaryColumnWidth: Math.max(380, layout.listPaneWidth ?? 0),
preferredPrimaryColumnWidthOrFraction: layout.listPaneWidth ?? 320,
minimumSecondaryColumnWidth: 320,
+ // UIKit can retain its automatic width despite a new preference; constrain both edges.
+ minimumInspectorColumnWidth: inspectorWidth,
+ maximumInspectorColumnWidth: inspectorWidth,
+ preferredInspectorColumnWidthOrFraction: inspectorWidth,
}}
>
<Split.Column>
@@ -433,7 +449,45 @@ function WorkspaceColumns(
{/* Inspector panes host their own native stacks, which UIKit insets for the Duo's
vertical bar wherever they sit, so each pane insets its own content instead. */}
<ColumnContent insetHorizontally={false}>
- <View className="flex-1 bg-screen">{inspector.render?.()}</View>
+ <View className="flex-1 bg-screen">
+ {inspector.render?.()}
+ {inspector.visible ? (
+ <GestureHandlerRootView
+ style={[StyleSheet.absoluteFill, { zIndex: 100 }]}
+ pointerEvents="box-none"
+ collapsable={false}
+ >
+ <SafeAreaView
+ style={{ flex: 1 }}
+ edges={["left", "right"]}
+ pointerEvents="box-none"
+ >
+ <View className="flex-1" pointerEvents="box-none">
+ <View
+ className="absolute inset-y-0 left-0 w-[22px] flex-row"
+ pointerEvents="box-none"
+ >
+ <WorkspacePaneDivider
+ accessibilityLabel="Resize inspector"
+ currentWidth={inspectorWidth}
+ resizeDirection={-1}
+ onResizeStart={() => {
+ resizeStartWidth.current = inspectorWidth;
+ }}
+ onResizeBy={(delta) => {
+ const width = Math.max(
+ 260,
+ Math.min(viewportWidth * 0.6, resizeStartWidth.current + delta),
+ );
+ setInspectorWidthFraction(width / viewportWidth);
+ }}
+ />
+ </View>
+ </View>
+ </SafeAreaView>
+ </GestureHandlerRootView>
+ ) : null}
+ </View>
</ColumnContent>
</Split.Inspector>
</Split.Host>
diff --git a/apps/mobile/src/features/layout/workspace-pane-divider.tsx b/apps/mobile/src/features/layout/workspace-pane-divider.tsx
index 8b2c75089d1..5fa62279b14 100644
--- a/apps/mobile/src/features/layout/workspace-pane-divider.tsx
+++ b/apps/mobile/src/features/layout/workspace-pane-divider.tsx
@@ -56,7 +56,7 @@ export function WorkspacePaneDivider(props: WorkspacePaneDividerProps) {
return (
<GestureDetector gesture={resizeGesture}>
<Pressable
- className="relative z-[100] -mx-[22px] w-11 self-stretch justify-center"
+ className="relative z-[100] -mx-[22px] w-[44px] self-stretch justify-center"
accessibilityActions={[
{ name: "increment", label: "Make pane wider" },
{ name: "decrement", label: "Make pane narrower" },
diff --git a/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx b/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
index 70179a06de8..fed455fe9ba 100644
--- a/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
+++ b/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
@@ -25,6 +25,8 @@ import { SubagentRow } from "./SubagentRow";
import { ScreenContent } from "../../components/ui/ScreenContent";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
+import { useOpenThreadInspector } from "./thread-inspector-navigation";
+
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
type AgentsTarget = { readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
@@ -45,6 +47,7 @@ export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
const { layout } = useAdaptiveWorkspaceLayout();
const target = route.params;
const navigation = useNavigation();
+ const openInspector = useOpenThreadInspector();
const insets = useSafeAreaInsets();
const turn = useThreadTurnSubagents(target);
const subagents = turn?.subagents ?? [];
@@ -52,6 +55,14 @@ export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
const openChildThread = (childThreadId: ThreadId) => {
void Haptics.selectionAsync();
+ if (
+ openInspector(target, {
+ type: "thread",
+ environmentId: target.environmentId,
+ threadId: childThreadId,
+ })
+ )
+ return;
// Replace this leaf sheet so the child enters the workspace stack expected by Home's Back button.
navigation.dispatch(
StackActions.replace("Thread", {
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
index 40cdfc1e3f8..708b1d2aa76 100644
--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
@@ -1,3 +1,4 @@
+import { useOpenThreadInspector } from "./thread-inspector-navigation";
import { useSidebarWorkspaceTabs } from "../workspace/useSystemWorkspaceTabBar";
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import {
@@ -15,7 +16,7 @@ import {
} from "../../state/entities";
import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
import { ChatGptUsageLimitNotice } from "./ChatGptUsageLimitNotice";
-import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
+import { useFocusEffect, useNavigation } from "@react-navigation/native";
import {
effectiveSnoozed,
threadWokeAt,
@@ -515,6 +516,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
if (sidebarSearchActive && composerOwnsKeyboard) setComposerOwnsKeyboard(false);
const navigation = useNavigation();
const openLinkedThread = useOpenLinkedThread();
+ const openInspector = useOpenThreadInspector();
const { session: voiceInputSession } = useGlobalVoiceInput();
const reportedModelSelection = useThreadReportedModelSelection(props.selectedThreadDetailRef);
const deviceState = useEnvironmentQuery(
@@ -523,6 +525,13 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
const devicePreviews = threadDevicePreviews(deviceState.data, props.selectedThread.id);
const openDevicePreview = () => {
Keyboard.dismiss();
+ if (
+ openInspector(
+ { environmentId: props.environmentId, threadId: props.selectedThread.id },
+ { type: "device", environmentId: props.environmentId, threadId: props.selectedThread.id },
+ )
+ )
+ return;
navigation.navigate("ThreadDevicePreview", {
environmentId: props.environmentId,
threadId: props.selectedThread.id,
@@ -789,12 +798,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
accessibilityLabel: `Open ${childInput.hasPendingApprovals ? "approval" : "question"} from ${childInput.title}`,
onPress: () => {
Keyboard.dismiss();
- navigation.dispatch(
- StackActions.push("Thread", {
- environmentId: props.environmentId,
- threadId: childInput.id,
- }),
- );
+ openLinkedThread({ environmentId: props.environmentId, threadId: childInput.id });
},
};
}
diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
index 45b11324c13..94d64799001 100644
--- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
@@ -5,13 +5,8 @@ import { buildProjectThreadStartTurnInput } from "../../lib/projectThreadStartTu
import { useWorktreeSetup } from "./use-worktree-setup";
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
import { AppBar } from "../../components/ui/AppBar";
-import {
- StackActions,
- useFocusEffect,
- useNavigation,
- type StaticScreenProps,
-} from "@react-navigation/native";
-import { useEffect, useRef, useState, type ReactNode } from "react";
+import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
+import { useEffect, useEffectEvent, useRef, useState, type ReactNode } from "react";
import * as Option from "effect/Option";
import {
AuthOrchestrationOperateScope,
@@ -99,6 +94,13 @@ import {
useWorkspaceBackNavigation,
} from "../workspace/useAndroidWorkspaceNavigation";
import { openSettings } from "../settings/settings-navigation";
+import {
+ InspectorContentScope,
+ ThreadInspectorHeader,
+ ThreadInspectorPreview,
+ type ThreadInspectorPresentation,
+} from "./thread-inspector-preview";
+import type { ThreadInspectorTarget } from "./thread-inspector-navigation";
import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";
interface ThreadInspectorSelection {
@@ -152,10 +154,12 @@ type ThreadRouteScreenRouteProps = StaticScreenProps<{
readonly environmentId?: string;
readonly threadId?: string;
readonly draft?: NewTaskDraftRouteParams;
+ readonly inspector?: ThreadInspectorTarget;
readonly prompt?: string | string[];
}>;
interface ThreadRouteScreenProps extends ThreadRouteScreenRouteProps {
+ readonly inspectorPresentation?: ThreadInspectorPresentation;
readonly onReturnToThread?: () => void;
readonly renderInspector?: (headerInset: number) => ReactNode;
}
@@ -233,13 +237,26 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
: scopedThreadKey(selectedThread.environmentId, selectedThread.id);
const selectedThreadDetailState = useSelectedThreadDetailState();
useThreadPromptLink(params, routeThreadKey);
+ const withInspectorHeader = (content: ReactNode) => (
+ <>
+ {props.inspectorPresentation ? (
+ <ThreadInspectorHeader
+ title={selectedThread?.title ?? "Thread"}
+ {...props.inspectorPresentation}
+ />
+ ) : null}
+ {content}
+ </>
+ );
if (environmentId === null || threadIdRaw === null) {
- return <OpeningThreadLoadingScreen />;
+ return withInspectorHeader(<OpeningThreadLoadingScreen />);
}
if (selectedThread !== null && selectedThreadKey === routeThreadKey) {
- return <ThreadRouteContent {...props} selectedThreadDetailState={selectedThreadDetailState} />;
+ return withInspectorHeader(
+ <ThreadRouteContent {...props} selectedThreadDetailState={selectedThreadDetailState} />,
+ );
}
const stillHydrating = threadRouteIsHydrating({
@@ -252,10 +269,10 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
});
if (stillHydrating) {
- return <OpeningThreadLoadingScreen />;
+ return withInspectorHeader(<OpeningThreadLoadingScreen />);
}
- return (
+ return withInspectorHeader(
<ThreadUnavailableScreen
actionLabel={
routeEnvironmentRuntime === null ? "Manage environments" : "Reconnect environment"
@@ -267,7 +284,7 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
}
openSettings(navigation, "SettingsEnvironments");
}}
- />
+ />,
);
}
@@ -383,7 +400,9 @@ function ThreadRouteContent(
const [inspectorSelection, setInspectorSelection] = useState<ThreadInspectorSelection | null>(
() => (props.renderInspector ? { routeThreadIdentity, mode: "route" } : null),
);
+ const previewTarget = props.inspectorPresentation ? undefined : params.inspector;
const inspectorMode = (() => {
+ if (previewTarget) return "preview";
if (inspectorSelection?.routeThreadIdentity === routeThreadIdentity) {
if (inspectorSelection.mode === "files" && selectedThreadCwd === null) {
return null;
@@ -394,6 +413,7 @@ function ThreadRouteContent(
})();
useEffect(() => {
if (
+ props.inspectorPresentation === undefined &&
fileInspector.supported &&
selectedThreadCwd === null &&
inspectorMode === null &&
@@ -405,6 +425,7 @@ function ThreadRouteContent(
fileInspector.supported,
inspectorMode,
panes.auxiliaryPaneVisible,
+ props.inspectorPresentation,
selectedThreadCwd,
toggleAuxiliaryPane,
]);
@@ -426,13 +447,10 @@ function ThreadRouteContent(
});
}, [props.renderInspector, routeThreadIdentity]);
- useFocusEffect(() => {
- return () => {
- if (props.renderInspector === undefined) {
- setInspectorSelection(null);
- }
- };
- });
+ const revealPreview = useEffectEvent(() => showAuxiliaryPane("inspector"));
+ useEffect(() => {
+ if (previewTarget) revealPreview();
+ }, [previewTarget]);
const routeEnvironmentRuntime = useRemoteEnvironmentRuntime(environmentId);
const routeConnectionState =
routeEnvironmentRuntime?.connectionState ?? (environmentId ? "available" : connectionState);
@@ -494,6 +512,7 @@ function ThreadRouteContent(
});
return;
}
+ navigation.setParams({ inspector: undefined });
setInspectorSelection({ routeThreadIdentity, mode: "git" });
showAuxiliaryPane("inspector");
};
@@ -508,6 +527,7 @@ function ThreadRouteContent(
});
return;
}
+ navigation.setParams({ inspector: undefined });
setInspectorSelection({
routeThreadIdentity,
mode: props.renderInspector === undefined ? "files" : "route",
@@ -557,9 +577,29 @@ function ThreadRouteContent(
/>
) : null;
const RouteInspector = () => props.renderInspector?.(inspectorHeaderInset);
+ const renderPreviewInspector = () =>
+ previewTarget && panes.auxiliaryPaneVisible ? (
+ <ThreadInspectorPreview
+ target={previewTarget}
+ renderThread={(screen) => <ThreadRouteScreen {...screen} />}
+ onClose={toggleAuxiliaryPane}
+ onOpen={(inspector) => {
+ if (
+ inspector.type === "thread" &&
+ inspector.environmentId === environmentId &&
+ inspector.threadId === threadId
+ ) {
+ toggleAuxiliaryPane();
+ return;
+ }
+ navigation.setParams({ inspector });
+ }}
+ />
+ ) : null;
const renderInspectorStack = () =>
inspectorMode === null ? null : (
<ThreadInspectorContentStack
+ renderPreview={renderPreviewInspector}
renderFiles={FilesInspector}
renderGit={GitInspector}
mode={inspectorMode}
@@ -567,7 +607,8 @@ function ThreadRouteContent(
renderRoute={props.renderInspector ? RouteInspector : undefined}
/>
);
- const activeInspectorRenderer = inspectorMode === null ? undefined : renderInspectorStack;
+ const activeInspectorRenderer =
+ props.inspectorPresentation || inspectorMode === null ? undefined : renderInspectorStack;
useRegisterWorkspaceInspector(activeInspectorRenderer);
const handleOpenConnectionEditor = () => {
@@ -908,21 +949,23 @@ function ThreadRouteContent(
<>
<ThreadScreenBinding
header={
- <ThreadHeader
- title={selectedThread.title}
- subtitle={headerSubtitle}
- headerColor={headerColor}
- usesNativeHeaderGlass={usesNativeHeaderGlass}
- gitControls={threadGitControlProps}
- hasThreadCwd={selectedThreadCwd !== null}
- hasWorkspaceRoot={Boolean(selectedThreadProject?.workspaceRoot)}
- fileInspectorSupported={fileInspector.supported}
- inspectorMode={inspectorMode}
- onToggleInspector={handleToggleInspector}
- onOpenGitInspector={handleOpenGitInspector}
- onOpenFilesInspector={handleOpenFilesInspector}
- onReturnToThread={props.onReturnToThread}
- />
+ props.inspectorPresentation ? null : (
+ <ThreadHeader
+ title={selectedThread.title}
+ subtitle={headerSubtitle}
+ headerColor={headerColor}
+ usesNativeHeaderGlass={usesNativeHeaderGlass}
+ gitControls={threadGitControlProps}
+ hasThreadCwd={selectedThreadCwd !== null}
+ hasWorkspaceRoot={Boolean(selectedThreadProject?.workspaceRoot)}
+ fileInspectorSupported={fileInspector.supported}
+ inspectorMode={inspectorMode}
+ onToggleInspector={handleToggleInspector}
+ onOpenGitInspector={handleOpenGitInspector}
+ onOpenFilesInspector={handleOpenFilesInspector}
+ onReturnToThread={props.onReturnToThread}
+ />
+ )
}
canOperateThread={canOperateThread}
selectedThread={selectedThreadWithDraftSettings ?? selectedThread}
@@ -1032,3 +1075,20 @@ function ThreadRouteContent(
</>
);
}
+
+export function FullscreenThreadRouteScreen(
+ props: StaticScreenProps<{
+ readonly environmentId: string;
+ readonly threadId: string;
+ }>,
+) {
+ const navigation = useNavigation();
+ return (
+ <InspectorContentScope>
+ <ThreadRouteScreen
+ route={props.route}
+ inspectorPresentation={{ onClose: () => navigation.goBack() }}
+ />
+ </InspectorContentScope>
+ );
+}
diff --git a/apps/mobile/src/features/threads/thread-inspector-content-stack.tsx b/apps/mobile/src/features/threads/thread-inspector-content-stack.tsx
index ae87fa9777e..9043a1f918b 100644
--- a/apps/mobile/src/features/threads/thread-inspector-content-stack.tsx
+++ b/apps/mobile/src/features/threads/thread-inspector-content-stack.tsx
@@ -4,7 +4,7 @@ import { View } from "react-native";
import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
import { NativeInspectorContent } from "../../native/NativeInspectorContent";
-export type ThreadInspectorMode = "route" | "git" | "files";
+export type ThreadInspectorMode = "route" | "git" | "files" | "preview";
const INSPECTOR_PREWARM_DELAY_MS = 350;
@@ -46,6 +46,7 @@ function InspectorContentPane(props: {
}
export function ThreadInspectorContentStack(props: {
+ readonly renderPreview?: () => ReactNode;
readonly renderFiles: () => ReactNode;
readonly renderGit?: () => ReactNode;
readonly mode: ThreadInspectorMode;
@@ -64,7 +65,7 @@ export function ThreadInspectorContentStack(props: {
return new Set([...current, props.mode]);
});
- if (props.mode === "route") {
+ if (props.mode === "route" || props.mode === "preview") {
return;
}
@@ -84,6 +85,11 @@ export function ThreadInspectorContentStack(props: {
return (
<View className="flex-1">
+ {props.mode === "preview" && props.renderPreview ? (
+ <InspectorContentPane mounted resetKeys={props.resetKeys} visible>
+ <InspectorRenderer render={props.renderPreview} />
+ </InspectorContentPane>
+ ) : null}
<InspectorContentPane
mounted={mountedModes.has("files") || props.mode === "files"}
resetKeys={props.resetKeys}
diff --git a/apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx b/apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx
new file mode 100644
index 00000000000..a8cf66463de
--- /dev/null
+++ b/apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx
@@ -0,0 +1,169 @@
+import * as NodeModule from "node:module";
+import { act, useLayoutEffect } from "react";
+import { createRoot } from "react-dom/client";
+import { expect, it, vi } from "vite-plus/test";
+
+const harness = vi.hoisted(() => ({
+ dispatch: (_action: unknown) => {},
+ getState: (): unknown => undefined,
+ getRoute: (): unknown => undefined,
+}));
+
+vi.mock("react-native", () => ({ Platform: { OS: "ios" } }));
+vi.mock("../layout/AdaptiveWorkspaceLayout", () => ({
+ useAdaptiveWorkspaceLayout: () => ({ fileInspector: { supported: true } }),
+}));
+vi.mock("@react-navigation/native", async () => {
+ const { createRequire } = await import("node:module");
+ const requireNavigation = createRequire(
+ createRequire(import.meta.url).resolve("@react-navigation/native/package.json"),
+ );
+ return {
+ StackActions: requireNavigation("@react-navigation/routers").StackActions,
+ useNavigation: () => ({ dispatch: harness.dispatch, getState: harness.getState }),
+ useRoute: () => harness.getRoute(),
+ };
+});
+
+import { useOpenThreadInspector } from "./thread-inspector-navigation";
+import { useOpenLinkedThread } from "./useOpenLinkedThread";
+
+const requireNavigation = NodeModule.createRequire(
+ NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"),
+);
+const { StackRouter, StackActions } = requireNavigation("@react-navigation/routers") as {
+ StackRouter: typeof import("@react-navigation/native").StackRouter;
+ StackActions: typeof import("@react-navigation/native").StackActions;
+};
+
+function setup(fromAgents: boolean, fullscreen = false) {
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+ const router = StackRouter({});
+ const options = {
+ routeNames: ["Home", "Thread", "ThreadAgents", "ThreadInspectorFullscreen"],
+ routeParamList: {},
+ routeGetIdList: {},
+ };
+ let state = router.getInitialState(options);
+ const dispatch = (action: Parameters<typeof router.getStateForAction>[1]) => {
+ const next = router.getStateForAction(state, action, options);
+ if (!next) throw new Error(`Rejected ${action.type}`);
+ state = router.getRehydratedState(next, options);
+ };
+ harness.dispatch = (action) => dispatch(action as Parameters<typeof dispatch>[0]);
+ harness.getState = () => state;
+ harness.getRoute = () => state.routes.at(-1);
+ const source = { environmentId: "remote-environment", threadId: "parent" };
+ dispatch(StackActions.push("Thread", { ...source, prompt: "retained prompt" }));
+ const parentKey = state.routes.at(-1)!.key;
+ if (fullscreen)
+ dispatch(StackActions.push("ThreadInspectorFullscreen", { ...source, threadId: "child" }));
+ if (fromAgents)
+ dispatch(
+ StackActions.push("ThreadAgents", fullscreen ? { ...source, threadId: "child" } : source),
+ );
+ let openInspector: ReturnType<typeof useOpenThreadInspector>;
+ let openLinkedThread: ReturnType<typeof useOpenLinkedThread>;
+ function Probe() {
+ const open = useOpenThreadInspector();
+ const openLinked = useOpenLinkedThread();
+ useLayoutEffect(() => {
+ openInspector = open;
+ openLinkedThread = openLinked;
+ });
+ return null;
+ }
+ const root = createRoot(document.createElement("div"));
+ act(() => root.render(<Probe />));
+ return {
+ source,
+ parentKey,
+ dispatch,
+ get state() {
+ return state;
+ },
+ open(target: Parameters<typeof openInspector>[1], from = source) {
+ let opened = false;
+ act(() => {
+ opened = openInspector(from, target);
+ });
+ return opened;
+ },
+ openLinked(threadId: string) {
+ act(() => openLinkedThread({ environmentId: source.environmentId, threadId }));
+ },
+ [Symbol.dispose]() {
+ act(() => root.unmount());
+ },
+ };
+}
+
+it("opens a subagent from the Agents sheet without replacing the parent thread", () => {
+ using screen = setup(true);
+ const inspector = {
+ type: "thread",
+ environmentId: screen.source.environmentId,
+ threadId: "child",
+ } as const;
+ screen.open(inspector);
+ expect(screen.state.routes.map((route) => route.name)).toEqual(["Home", "Thread"]);
+ expect(screen.state.routes.at(-1)).toMatchObject({
+ key: screen.parentKey,
+ params: { ...screen.source, prompt: "retained prompt", inspector },
+ });
+ screen.dispatch(StackActions.push("ThreadInspectorFullscreen", inspector));
+ screen.dispatch(StackActions.pop());
+ expect(screen.state.routes.at(-1)).toMatchObject({
+ key: screen.parentKey,
+ params: { ...screen.source, inspector },
+ });
+});
+
+it("opens a completion link in the parent inspector", () => {
+ using screen = setup(false);
+ screen.openLinked("child");
+ expect(screen.state.routes).toHaveLength(2);
+ expect(screen.state.routes.at(-1)).toMatchObject({
+ key: screen.parentKey,
+ params: {
+ ...screen.source,
+ inspector: { type: "thread", environmentId: screen.source.environmentId, threadId: "child" },
+ },
+ });
+});
+
+it("switches between subagents and devices in the same parent route", () => {
+ using screen = setup(false);
+ screen.open({ type: "thread", environmentId: screen.source.environmentId, threadId: "child" });
+ const inspector = { type: "device", ...screen.source } as const;
+ screen.open(inspector);
+ expect(screen.state.routes).toHaveLength(2);
+ expect(screen.state.routes.at(-1)).toMatchObject({
+ key: screen.parentKey,
+ params: { ...screen.source, inspector },
+ });
+});
+
+it.each(["thread", "device"] as const)(
+ "keeps the parent when a maximized child opens a %s preview",
+ (type) => {
+ using screen = setup(false, true);
+ const child = { ...screen.source, threadId: "child" };
+ const originalState = screen.state;
+ expect(screen.open({ type, ...child, threadId: "grandchild" }, child)).toBe(false);
+ expect(screen.state).toEqual(originalState);
+ screen.dispatch(StackActions.pop());
+ expect(screen.state.routes.at(-1)).toMatchObject({
+ key: screen.parentKey,
+ params: screen.source,
+ });
+ },
+);
+
+it("keeps the parent when the maximized child's Agents sheet opens another child", () => {
+ using screen = setup(true, true);
+ const child = { ...screen.source, threadId: "child" };
+ const originalState = screen.state;
+ expect(screen.open({ type: "thread", ...child, threadId: "grandchild" }, child)).toBe(false);
+ expect(screen.state).toEqual(originalState);
+});
diff --git a/apps/mobile/src/features/threads/thread-inspector-navigation.ts b/apps/mobile/src/features/threads/thread-inspector-navigation.ts
new file mode 100644
index 00000000000..3acd7e61397
--- /dev/null
+++ b/apps/mobile/src/features/threads/thread-inspector-navigation.ts
@@ -0,0 +1,44 @@
+import { StackActions, useNavigation } from "@react-navigation/native";
+import { createContext, use } from "react";
+import { Platform } from "react-native";
+
+import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
+
+export type ThreadInspectorTarget = {
+ readonly type: "thread" | "device";
+ readonly environmentId: string;
+ readonly threadId: string;
+ readonly deviceKey?: string;
+};
+
+export const ThreadInspectorNavigationContext = createContext<
+ ((target: ThreadInspectorTarget) => void) | null
+>(null);
+
+export function useOpenThreadInspector() {
+ const navigation = useNavigation();
+ const { fileInspector } = useAdaptiveWorkspaceLayout();
+ const openInInspector = use(ThreadInspectorNavigationContext);
+ return (
+ source: { readonly environmentId: string; readonly threadId: string },
+ target: ThreadInspectorTarget,
+ ) => {
+ if (Platform.OS !== "ios" || !fileInspector.supported) return false;
+ if (openInInspector) openInInspector(target);
+ else {
+ const parent = navigation.getState()?.routes.findLast((route) => route.name === "Thread");
+ if (
+ !parent?.params ||
+ !("environmentId" in parent.params) ||
+ parent.params.environmentId !== source.environmentId ||
+ !("threadId" in parent.params) ||
+ parent.params.threadId !== source.threadId
+ )
+ return false;
+ navigation.dispatch(
+ StackActions.popTo("Thread", { ...source, inspector: target }, { merge: true }),
+ );
+ }
+ return true;
+ };
+}
diff --git a/apps/mobile/src/features/threads/thread-inspector-preview.tsx b/apps/mobile/src/features/threads/thread-inspector-preview.tsx
new file mode 100644
index 00000000000..7c4e1e52c88
--- /dev/null
+++ b/apps/mobile/src/features/threads/thread-inspector-preview.tsx
@@ -0,0 +1,142 @@
+import {
+ NavigationContainer,
+ NavigationIndependentTree,
+ useIsFocused,
+ useNavigation,
+ type StaticScreenProps,
+} from "@react-navigation/native";
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
+import { type ReactNode } from "react";
+import { View } from "react-native";
+
+import { IconButton } from "../../components/ui/IconButton";
+import { SheetHeader } from "../../components/ui/SheetHeader";
+import { NativeInspectorContent } from "../../native/NativeInspectorContent";
+import { createV5StackNavigator } from "../../native/createV5StackNavigator";
+import { NativeStackScreenOptions } from "../../native/StackHeader";
+import { WorkspaceSlotOptionsContext } from "../../native/v5-workspace-context";
+import { useMobileNavigationTheme } from "../../lib/useMobileNavigationTheme";
+import { DevicePreviewScreen } from "../devices/DevicePreviewRouteScreen";
+import {
+ WorkspaceContentWidthContext,
+ WorkspaceSettledContentWidthContext,
+} from "../layout/workspace-content-width";
+import {
+ ThreadInspectorNavigationContext,
+ type ThreadInspectorTarget,
+} from "./thread-inspector-navigation";
+
+export interface ThreadInspectorPresentation {
+ readonly onClose: () => void;
+ readonly onMaximize?: () => void;
+}
+
+export function ThreadInspectorHeader(
+ props: ThreadInspectorPresentation & { readonly title: string },
+) {
+ return (
+ <>
+ <NativeStackScreenOptions options={{ headerShown: true, headerTransparent: true }} />
+ <SheetHeader
+ title={props.title}
+ onClose={props.onClose}
+ accessibilityLabel="Close thread preview"
+ trailing={
+ props.onMaximize ? (
+ <IconButton
+ icon="arrow.up.left.and.arrow.down.right"
+ accessibilityLabel="Maximize thread"
+ onPress={props.onMaximize}
+ />
+ ) : undefined
+ }
+ />
+ </>
+ );
+}
+
+const PreviewStack = createV5StackNavigator<{
+ Thread: { readonly environmentId: string; readonly threadId: string };
+}>();
+
+export function InspectorContentScope({ children }: { readonly children: ReactNode }) {
+ return (
+ <WorkspaceSlotOptionsContext value={null}>
+ <WorkspaceContentWidthContext value={null}>
+ <WorkspaceSettledContentWidthContext value={null}>
+ {children}
+ </WorkspaceSettledContentWidthContext>
+ </WorkspaceContentWidthContext>
+ </WorkspaceSlotOptionsContext>
+ );
+}
+
+export function ThreadInspectorPreview(props: {
+ readonly target: ThreadInspectorTarget;
+ readonly onClose: () => void;
+ readonly onOpen: (target: ThreadInspectorTarget) => void;
+ readonly renderThread: (
+ props: StaticScreenProps<{ readonly environmentId: string; readonly threadId: string }> & {
+ readonly inspectorPresentation: ThreadInspectorPresentation;
+ },
+ ) => ReactNode;
+}) {
+ const navigation = useNavigation();
+ const focused = useIsFocused();
+ const theme = useMobileNavigationTheme();
+ const { target } = props;
+ const maximizeDevice = (deviceKey: string | null) => {
+ props.onOpen({ ...target, deviceKey: deviceKey ?? undefined });
+ navigation.navigate("ThreadDevicePreview", {
+ environmentId: target.environmentId,
+ threadId: target.threadId,
+ deviceKey: deviceKey ?? undefined,
+ });
+ };
+ if (!focused) return null;
+ return (
+ <ThreadInspectorNavigationContext value={props.onOpen}>
+ <InspectorContentScope>
+ <NativeInspectorContent>
+ {target.type === "device" ? (
+ <DevicePreviewScreen
+ key={`${target.environmentId}:${target.threadId}`}
+ environmentId={EnvironmentId.make(target.environmentId)}
+ threadId={ThreadId.make(target.threadId)}
+ initialDeviceKey={target.deviceKey}
+ onClose={props.onClose}
+ onMaximize={maximizeDevice}
+ />
+ ) : (
+ <View className="flex-1 bg-screen">
+ <NavigationIndependentTree>
+ <NavigationContainer theme={theme} onUnhandledAction={navigation.dispatch}>
+ <PreviewStack.Navigator
+ key={`${target.environmentId}:${target.threadId}`}
+ screenOptions={{ headerBackVisible: false }}
+ >
+ <PreviewStack.Screen name="Thread" initialParams={target}>
+ {(screen) =>
+ props.renderThread({
+ route: screen.route,
+ inspectorPresentation: {
+ onClose: props.onClose,
+ onMaximize: () =>
+ navigation.navigate("ThreadInspectorFullscreen", {
+ environmentId: screen.route.params.environmentId,
+ threadId: screen.route.params.threadId,
+ }),
+ },
+ })
+ }
+ </PreviewStack.Screen>
+ </PreviewStack.Navigator>
+ </NavigationContainer>
+ </NavigationIndependentTree>
+ </View>
+ )}
+ </NativeInspectorContent>
+ </InspectorContentScope>
+ </ThreadInspectorNavigationContext>
+ );
+}
diff --git a/apps/mobile/src/features/threads/thread-subagent-group.tsx b/apps/mobile/src/features/threads/thread-subagent-group.tsx
index 5fa19568b06..c408b1771fc 100644
--- a/apps/mobile/src/features/threads/thread-subagent-group.tsx
+++ b/apps/mobile/src/features/threads/thread-subagent-group.tsx
@@ -22,6 +22,8 @@ import { subagentCardElapsed } from "./subagent-card-presentation";
import { SubagentRow } from "./SubagentRow";
import { WorkLogBlock } from "./work-log-layout";
+import { useOpenThreadInspector } from "./thread-inspector-navigation";
+
type SubagentItem = Extract<OrchestrationV2TurnItem, { type: "subagent" }>;
type AgentTiming = Pick<OrchestrationV2Subagent, "status" | "startedAt" | "completedAt">;
@@ -71,6 +73,7 @@ export function ThreadSubagentGroup(props: {
}) {
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
const navigation = useNavigation();
+ const openInspector = useOpenThreadInspector();
const members = props.activities.flatMap(({ projectedItem }) =>
projectedItem.item.type === "subagent" ? [projectedItem.item] : [],
);
@@ -158,14 +161,20 @@ export function ThreadSubagentGroup(props: {
}
disabled={threadId === null}
onPress={() => {
- // Push preserves Back to the parent; navigate would reuse this Thread route.
- if (threadId !== null)
- navigation.dispatch(
- StackActions.push("Thread", {
- environmentId: String(props.environmentId),
- threadId: String(threadId),
- }),
- );
+ if (threadId === null) return;
+ if (
+ openInspector(
+ { environmentId: props.environmentId, threadId: members[0]!.threadId },
+ { type: "thread", environmentId: props.environmentId, threadId },
+ )
+ )
+ return;
+ navigation.dispatch(
+ StackActions.push("Thread", {
+ environmentId: String(props.environmentId),
+ threadId: String(threadId),
+ }),
+ );
}}
className="rounded-lg px-3 py-3 active:bg-subtle"
>
diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsx
index 80e515aeec4..6ed0240f7c0 100644
--- a/apps/mobile/src/features/threads/thread-work-log.tsx
+++ b/apps/mobile/src/features/threads/thread-work-log.tsx
@@ -21,7 +21,7 @@ import { type AppSymbolName, SymbolView } from "../../components/ui/AppSymbol";
import { MaskedView } from "@expo/ui/community/masked-view";
import type { LegendListRef } from "@legendapp/list/react-native";
import { AnimatedLegendList } from "@legendapp/list/reanimated";
-import { StackActions, useIsFocused, useNavigation } from "@react-navigation/native";
+import { useIsFocused } from "@react-navigation/native";
import {
useEffect,
useEffectEvent,
@@ -105,6 +105,7 @@ import Animated, {
} from "react-native-reanimated";
import { useAssetUrl } from "../../state/assets";
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
+import { useOpenLinkedThread } from "./useOpenLinkedThread";
const SHIMMER_WIDTH = 72;
const SHIMMER_SWEEP_MS = 1_350;
@@ -882,7 +883,7 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
},
) {
const { row, expanded } = props;
- const navigation = useNavigation();
+ const openLinkedThread = useOpenLinkedThread();
const streamsOutput =
useCommandOutputStreaming(props.environmentId) &&
row.projectedItem.item.type === "command_execution";
@@ -1056,13 +1057,10 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
accessibilityState={canExpand ? { expanded } : undefined}
onPress={() => {
if (notifiedSubagentThreadId !== undefined) {
- // Push rather than navigate so Back returns to the parent thread instead of Home.
- navigation.dispatch(
- StackActions.push("Thread", {
- environmentId: String(props.environmentId),
- threadId: String(notifiedSubagentThreadId),
- }),
- );
+ openLinkedThread({
+ environmentId: String(props.environmentId),
+ threadId: String(notifiedSubagentThreadId),
+ });
return;
}
if (canExpand) {
diff --git a/apps/mobile/src/features/threads/thread-workflow-opening.tsx b/apps/mobile/src/features/threads/thread-workflow-opening.tsx
index e7ff27cb956..5165a4ac016 100644
--- a/apps/mobile/src/features/threads/thread-workflow-opening.tsx
+++ b/apps/mobile/src/features/threads/thread-workflow-opening.tsx
@@ -1,5 +1,4 @@
import { useAtomValue } from "@effect/atom-react";
-import { StackActions, useNavigation } from "@react-navigation/native";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import {
resolveWorkflowOpening,
@@ -17,6 +16,7 @@ import { useAppearancePreferences } from "../settings/appearance/AppearancePrefe
import { useMarkdownCodeHighlight } from "./markdownCodeHighlightState";
import { SubagentRow } from "./SubagentRow";
import { WorkLogBlock } from "./work-log-layout";
+import { useOpenLinkedThread } from "./useOpenLinkedThread";
const FOLDED_SCRIPT_LINES = 10;
@@ -74,7 +74,7 @@ export function ThreadWorkflowOpening(props: {
readonly threadId: ThreadId;
readonly opening: WorkflowOpeningValue;
}) {
- const navigation = useNavigation();
+ const openLinkedThread = useOpenLinkedThread();
const { opening } = props;
const headline = workflowOpeningHeadline(opening);
const canListMembers = opening.driver !== null && opening.providerInstanceId !== null;
@@ -90,12 +90,7 @@ export function ThreadWorkflowOpening(props: {
disabled={threadId === null}
onPress={() => {
if (threadId !== null)
- navigation.dispatch(
- StackActions.push("Thread", {
- environmentId: String(props.environmentId),
- threadId,
- }),
- );
+ openLinkedThread({ environmentId: String(props.environmentId), threadId });
}}
className="rounded-lg px-3 py-3 active:bg-subtle"
>
diff --git a/apps/mobile/src/features/threads/useOpenLinkedThread.ts b/apps/mobile/src/features/threads/useOpenLinkedThread.ts
index a3ecd7f685a..68531c4af25 100644
--- a/apps/mobile/src/features/threads/useOpenLinkedThread.ts
+++ b/apps/mobile/src/features/threads/useOpenLinkedThread.ts
@@ -1,16 +1,38 @@
-import { StackActions, useNavigation } from "@react-navigation/native";
-import { useCallback } from "react";
+import { StackActions, useNavigation, useRoute, type Route } from "@react-navigation/native";
+import { use, useCallback } from "react";
import { linkedThreadStep } from "../../lib/android-workspace-navigation";
+import {
+ ThreadInspectorNavigationContext,
+ useOpenThreadInspector,
+} from "./thread-inspector-navigation";
export function useOpenLinkedThread() {
const navigation = useNavigation();
+ const route = useRoute<Route<string, { environmentId?: string; threadId?: string }>>();
+ const openInspector = useOpenThreadInspector();
+ const openInInspector = use(ThreadInspectorNavigationContext);
return useCallback(
(target: { readonly environmentId: string; readonly threadId: string }) => {
+ if (openInInspector) {
+ openInInspector({ type: "thread", ...target });
+ return;
+ }
const state = navigation.getState();
const step = state ? linkedThreadStep(state, target) : "push";
+ if (
+ step === "push" &&
+ route.name === "Thread" &&
+ route.params?.environmentId &&
+ route.params.threadId &&
+ openInspector(
+ { environmentId: route.params.environmentId, threadId: route.params.threadId },
+ { type: "thread", ...target },
+ )
+ )
+ return;
if (step === "pop") navigation.dispatch(StackActions.pop());
else if (step === "push") navigation.dispatch(StackActions.push("Thread", target));
},
- [navigation],
+ [navigation, openInInspector, openInspector, route],
);
}
diff --git a/apps/mobile/src/lib/filePreview.test.ts b/apps/mobile/src/lib/filePreview.test.ts
index 84f86f8998b..0b89620619d 100644
--- a/apps/mobile/src/lib/filePreview.test.ts
+++ b/apps/mobile/src/lib/filePreview.test.ts
@@ -63,6 +63,7 @@ vi.mock("expo-audio", () => ({
vi.mock("@react-navigation/native", () => ({
useIsFocused: () => true,
useNavigation: () => ({ navigate: audio.navigate }),
+ useRoute: () => ({ name: "Thread", params: {} }),
useFocusEffect: (callback: () => (() => void) | undefined) => useEffect(callback, [callback]),
}));
vi.mock("react-native", () => ({
@@ -264,6 +265,9 @@ vi.mock("../features/threads/CopyTextButton", () => ({ CopyTextButton: () => nul
vi.mock("../features/threads/thread-work-log", () => ({ THREAD_DISCLOSURE_TRANSITION_MS: 100 }));
vi.mock("../features/threads/HtmlRenderWebView", () => ({}));
vi.mock("../features/threads/McpAppWebView", () => ({}));
+vi.mock("../features/layout/AdaptiveWorkspaceLayout", () => ({
+ useAdaptiveWorkspaceLayout: () => ({ fileInspector: { supported: false } }),
+}));
vi.mock("../features/threads/thread-workflow-opening", () => ({ useWorkflowOpening: () => null }));
vi.mock("../features/threads/useFileChipShare", () => ({ useFileChipShare: () => vi.fn() }));
vi.mock("../features/threads/ThreadMarkdownImage", async () => {
diff --git a/apps/mobile/src/lib/layout.test.ts b/apps/mobile/src/lib/layout.test.ts
index c4c0f73ae3d..09802951e99 100644
--- a/apps/mobile/src/lib/layout.test.ts
+++ b/apps/mobile/src/lib/layout.test.ts
@@ -128,6 +128,26 @@ describe("isPrimarySidebarPinned", () => {
});
describe("deriveWorkspacePaneLayout", () => {
+ it("lets UIKit keep the sidebar independent of the inspector in landscape", () => {
+ const layout = deriveLayout({ width: 1_194, height: 834 });
+ for (const primarySidebarPreferredVisible of [true, false]) {
+ expect(
+ deriveWorkspacePaneLayout({
+ layout,
+ viewportWidth: 1_194,
+ nativeWorkspace: true,
+ primarySidebarPreferredVisible,
+ auxiliaryPanePreferredVisible: true,
+ auxiliaryPaneRole: "inspector",
+ }),
+ ).toMatchObject({
+ primarySidebarVisible: primarySidebarPreferredVisible,
+ primarySidebarSuppressedByAuxiliary: false,
+ auxiliaryPaneVisible: true,
+ });
+ }
+ });
+
it("keeps an explicitly hidden thread sidebar hidden when the file inspector is visible", () => {
const layout = deriveLayout({ width: 1_024, height: 1_366 });
diff --git a/apps/mobile/src/lib/layout.ts b/apps/mobile/src/lib/layout.ts
index ae9e3f6c3e1..2bbd9edbe9a 100644
--- a/apps/mobile/src/lib/layout.ts
+++ b/apps/mobile/src/lib/layout.ts
@@ -189,6 +189,7 @@ export function isPrimarySidebarPinned(input: {
export function deriveWorkspacePaneLayout(input: {
readonly layout: Layout;
readonly viewportWidth: number;
+ readonly nativeWorkspace?: boolean;
readonly primarySidebarPreferredVisible: boolean;
readonly auxiliaryPanePreferredVisible: boolean;
readonly auxiliaryPaneRole?: WorkspaceAuxiliaryPaneRole;
@@ -212,6 +213,7 @@ export function deriveWorkspacePaneLayout(input: {
});
const auxiliaryPaneVisible = fileInspector.supported && input.auxiliaryPanePreferredVisible;
const primarySidebarSuppressedByAuxiliary =
+ !input.nativeWorkspace &&
preferredPrimarySidebarVisible &&
!input.layout.primarySidebarOverlaysContent &&
auxiliaryPaneVisible &&
diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts
index 69728880a79..0a063e182c3 100644
--- a/apps/mobile/vite.config.ts
+++ b/apps/mobile/vite.config.ts
@@ -4,6 +4,7 @@ import "vite-plus/test/config";
const reactTests = [
"src/features/pull-requests/usePullRequestEnvironmentFallback.test.tsx",
"src/lib/filePreview.test.ts",
+ "src/features/threads/thread-inspector-navigation.test.tsx",
"src/features/diffs/nativeReviewDiffSurface.test.tsx",
"src/features/pull-requests/usePullRequestDiff.test.tsx",
"src/components/ui/Dialog.android.test.tsx",
diff --git a/docs/user/devices.md b/docs/user/devices.md
index bf372009d58..6c32f94eeca 100644
--- a/docs/user/devices.md
+++ b/docs/user/devices.md
@@ -73,6 +73,8 @@ connected to the thread, the same way an agent-driven browser does. Turn off
**Auto-show floating preview** in **Settings → Integrations → Browser** to open a
right-panel tab instead. In the mobile app, open the agent's thread and tap the
device button above the composer to watch the live screen and control it.
+On iOS layouts with an inspector, the device opens beside the thread. Maximize
+it to fill the screen; closing the full-screen view returns to the inspector.
If the thread has several devices open, choose one in the viewer. Closing the
viewer stops streaming and leaves the device available to the agent. Device
activity also appears in the thread timeline.
diff --git a/docs/user/thread-sidebar.md b/docs/user/thread-sidebar.md
index 6e42704ee8e..02fd676dc39 100644
--- a/docs/user/thread-sidebar.md
+++ b/docs/user/thread-sidebar.md
@@ -230,6 +230,9 @@ snooze limit stops by default. Providers without a reset time offer manual
retry and the normal snooze choices.
On web and desktop, use **Agents** to follow work delegated to subagents.
+On mobile, open a subagent from its conversation card or **Agents**. On iOS
+layouts with an inspector, its thread opens beside the parent. Maximize it to
+fill the screen; close the full-screen view to return to the parent and inspector.
Stop on a thread also stops the subagents it delegated to.
Subagent threads started by the agent can't take messages; message the parent
diff --git a/scripts/effect-budget.json b/scripts/effect-budget.json
index eba1a2c4822..008ba170fd0 100644
--- a/scripts/effect-budget.json
+++ b/scripts/effect-budget.json
@@ -118,7 +118,7 @@
"apps/mobile/src/features/threads/ThreadMarkdownImage.tsx": 3,
"apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx": 3,
"apps/mobile/src/features/threads/ThreadQueueControl.tsx": 2,
- "apps/mobile/src/features/threads/ThreadRouteScreen.tsx": 2,
+ "apps/mobile/src/features/threads/ThreadRouteScreen.tsx": 3,
"apps/mobile/src/features/threads/ThreadScreenHost.tsx": 2,
"apps/mobile/src/features/threads/ThreadSettingsSheet.tsx": 2,
"apps/mobile/src/features/threads/UsageLimitRecoveryCard.tsx": 1,