Skip to content

Commit 805790e

Browse files
fix(mobile): file links in question cards open the file viewer
A workspace file link in an agent question card was handed to the pull-request opener, which fell through to Linking.openURL and failed silently. Resolve file links against the thread's workspace root and navigate to ThreadFile like the chat does; other links are unchanged. Fixes #29119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9709d16 commit 805790e

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

‎apps/mobile/src/features/threads/PendingUserInputCard.test.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EnvironmentId, RuntimeRequestId } from "@t3tools/contracts";
1+
import type { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
22
import * as NodeModule from "node:module";
33
import type { ReactNode } from "react";
44
import { act } from "react";
@@ -145,6 +145,8 @@ function setup(questionMarkdown: string) {
145145
root.render(
146146
<PendingUserInputCard
147147
environmentId={"env-1" as EnvironmentId}
148+
threadId={"thread-1" as ThreadId}
149+
workspaceRoot="/repo"
148150
canOperateThread
149151
pendingUserInput={pendingUserInput}
150152
maxHeight={{ value: 600 } as never}
@@ -194,3 +196,15 @@ it("opens a workspace file link in a question in the thread's file viewer", asyn
194196
},
195197
});
196198
});
199+
200+
it("opens an absolute file link under the workspace root by its workspace path", async () => {
201+
using screen = setup("Should I update [probe.md](/repo/docs/probe.md)?");
202+
203+
await screen.pressLink("probe.md");
204+
205+
expect(screen.openedUrls).toEqual([]);
206+
expect(screen.state.routes.at(-1)).toMatchObject({
207+
name: "ThreadFile",
208+
params: { environmentId: "env-1", threadId: "thread-1", path: ["docs", "probe.md"] },
209+
});
210+
});

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Button } from "../../components/ui/Button";
22
import { QuestionAttachments } from "./QuestionAttachments";
3-
import type { EnvironmentId, RuntimeRequestId } from "@t3tools/contracts";
3+
import type { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
44
import type { ThreadUserInputQuestion } from "@t3tools/client-runtime/state/thread-requests";
55
import {
66
markdownProseDirection,
77
textDirection,
88
type TextDirection,
99
} from "@t3tools/shared/textDirection";
10+
import { useNavigation } from "@react-navigation/native";
1011
import { useRef } from "react";
1112
import { Platform, Pressable, ScrollView, View, type LayoutChangeEvent } from "react-native";
1213
import Animated, {
@@ -25,9 +26,15 @@ import { SymbolView } from "../../components/ui/AppSymbol";
2526
import { AppText as Text } from "../../components/ui/AppText";
2627
import { ControlPill } from "../../components/ui/ControlPill";
2728
import { cn } from "../../lib/cn";
29+
import { resolveMarkdownLinkPresentation } from "../../lib/markdownLinks";
2830
import { SelectableMarkdownText } from "../../native/SelectableMarkdownText";
2931
import { useOpenPullRequest } from "../../native/useOpenPullRequest";
3032
import { useMarkdownPreviewStyles } from "../files/FileMarkdownPreview";
33+
import {
34+
fileRoutePathSegments,
35+
resolveFileLinkPath,
36+
resolveWorkspaceRelativeFilePath,
37+
} from "../files/filePath";
3138
import { useLiveThreadLinkLabels } from "../../state/entities";
3239
import {
3340
isPendingUserInputOptionSelected,
@@ -37,6 +44,8 @@ import type { PendingUserInput } from "../../lib/threadActivity";
3744

3845
export interface PendingUserInputCardProps {
3946
readonly environmentId: EnvironmentId;
47+
readonly threadId: ThreadId;
48+
readonly workspaceRoot: string | null;
4049
readonly canOperateThread: boolean;
4150
readonly pendingUserInput: PendingUserInput;
4251
readonly maxHeight: DerivedValue<number>;
@@ -77,11 +86,31 @@ function proseDirectionStyle(text: string, setDirection: TextDirection | undefin
7786
function QuestionText(props: {
7887
readonly markdown: string;
7988
readonly environmentId: EnvironmentId;
89+
readonly threadId: ThreadId;
90+
readonly workspaceRoot: string | null;
8091
readonly setDirection: TextDirection | undefined;
8192
}) {
8293
const styles = useMarkdownPreviewStyles();
8394
const markdown = useLiveThreadLinkLabels(props.markdown, props.environmentId);
84-
const openLink = useOpenPullRequest();
95+
const navigation = useNavigation();
96+
const openPullRequest = useOpenPullRequest();
97+
const openLink = (href: string) => {
98+
const link = resolveMarkdownLinkPresentation(href);
99+
if (link.kind !== "file") {
100+
void openPullRequest(href);
101+
return;
102+
}
103+
const path = resolveFileLinkPath(props.workspaceRoot, link.path);
104+
if (path === null) return;
105+
navigation.navigate("ThreadFile", {
106+
environmentId: String(props.environmentId),
107+
threadId: String(props.threadId),
108+
path: fileRoutePathSegments(
109+
resolveWorkspaceRelativeFilePath(props.workspaceRoot, path) ?? path,
110+
),
111+
...(link.line ? { line: String(link.line) } : {}),
112+
});
113+
};
85114
return (
86115
<SelectableMarkdownText
87116
markdown={markdown}
@@ -91,7 +120,7 @@ function QuestionText(props: {
91120
textAlign={
92121
Platform.OS === "android" ? undefined : props.setDirection === "rtl" ? "right" : "left"
93122
}
94-
onLinkPress={(href) => void openLink(href)}
123+
onLinkPress={openLink}
95124
/>
96125
);
97126
}
@@ -257,6 +286,8 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
257286
<QuestionText
258287
markdown={question.question}
259288
environmentId={props.environmentId}
289+
threadId={props.threadId}
290+
workspaceRoot={props.workspaceRoot}
260291
setDirection={setDirection}
261292
/>
262293
<View className="gap-2">

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,8 @@ function ThreadDetailBody(
16771677
{props.activePendingUserInput ? (
16781678
<PendingUserInputCard
16791679
environmentId={props.environmentId}
1680+
threadId={props.selectedThread.id}
1681+
workspaceRoot={props.threadCwd}
16801682
canOperateThread={props.canOperateThread}
16811683
pendingUserInput={props.activePendingUserInput}
16821684
maxHeight={pendingUserInputMaxHeight}

0 commit comments

Comments
 (0)