@devries-cameron20 / t3code Mirror · read-only / commits / 8fbc22ca95
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 05:30 UTC

feat(mobile): link, unlink and watch a thread's pull requests from its sheet (#20394)

oliver committed Oct 18, 2026 at 00:06 UTC 8fbc22ca955ff165b53be1770196453fea1a7d30
58 files changed +1315 -390
apps/mobile/src/Stack.tsx
+11
@@ -67,6 +67,7 @@ import { GitBranchesSheet } from "./features/threads/git/GitBranchesSheet";
67 import { GitCommitSheet } from "./features/threads/git/GitCommitSheet";
68 import { GitConfirmSheet } from "./features/threads/git/GitConfirmSheet";
69 import { GitOverviewSheet } from "./features/threads/git/GitOverviewSheet";
70 +import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSheet";
71 import { ThreadAgentsSheet } from "./features/threads/ThreadAgentsSheet";
72 import { ThreadQueueSheet } from "./features/threads/ThreadQueueControl";
73 import { ThreadRouteScreen } from "./features/threads/ThreadRouteScreen";
@@ -550,6 +551,7 @@ const WORKSPACE_OVERLAY_ROUTES = new Set([
551 "SettingsLegal",
552 "SettingsSheet",
553 "ThreadAgents",
554 + "ThreadPullRequests",
555 "ThreadQueue",
556 "ThreadReviewComment",
557 "ThreadDevicePreview",
@@ -871,6 +873,15 @@ const RootStackConfig = createWorkspaceStackNavigator({
873 sheetGrabberVisible: true,
874 },
875 }),
876 + ThreadPullRequests: createNativeStackScreen({
877 + screen: ThreadPullRequestsSheet,
878 + linking: `${THREAD_LINKING_PREFIX}/pull-requests`,
879 + options: {
880 + ...FORM_SHEET_PRESENTATION_OPTIONS,
881 + sheetAllowedDetents: [0.55, 0.92],
882 + sheetGrabberVisible: true,
883 + },
884 + }),
885 GitCommit: createNativeStackScreen({
886 screen: GitCommitSheet,
887 linking: `${THREAD_LINKING_PREFIX}/git/commit`,
apps/mobile/src/components/ui/Dialog.android.tsx
+35 -23
@@ -117,6 +117,7 @@ export function Host() {
117 inputInitialValue={
118 presented.kind === "text-input" ? presented.request.initialValue : undefined
119 }
120 + inputPlaceholder={presented.kind === "text-input" ? presented.request.placeholder : undefined}
121 onInputChange={setInputValue}
122 onCancel={handleCancel}
123 onConfirm={handleConfirm}
@@ -200,29 +201,39 @@ function DialogPresentation(props: DialogPresentationProps) {
201 </AlertDialog.Title>
202 {props.inputInitialValue !== undefined ? (
203 <AlertDialog.Text>
203 - <OutlinedTextField
204 - autoFocus
205 - singleLine
206 - value={inputState}
207 - selection={inputSelection}
208 - onValueChange={props.onInputChange}
209 - textStyle={inputTypography}
210 - keyboardOptions={{ imeAction: "done" }}
211 - keyboardActions={{
212 - onDone: confirm,
213 - }}
214 - colors={{
215 - focusedTextColor: colors["--color-foreground"],
216 - unfocusedTextColor: colors["--color-foreground"],
217 - focusedIndicatorColor: colors["--color-focus"],
218 - unfocusedIndicatorColor: colors["--color-border"],
219 - cursorColor: colors["--color-focus"],
220 - }}
221 - >
222 - <OutlinedTextField.Label>
223 - <Text style={bodyTypography}>{props.request.title}</Text>
224 - </OutlinedTextField.Label>
225 - </OutlinedTextField>
204 + <Column verticalArrangement={{ spacedBy: 16 }}>
205 + {props.request.message ? (
206 + <Text style={bodyTypography}>{props.request.message}</Text>
207 + ) : null}
208 + <OutlinedTextField
209 + autoFocus
210 + singleLine
211 + value={inputState}
212 + selection={inputSelection}
213 + onValueChange={props.onInputChange}
214 + textStyle={inputTypography}
215 + keyboardOptions={{ imeAction: "done" }}
216 + keyboardActions={{
217 + onDone: confirm,
218 + }}
219 + colors={{
220 + focusedTextColor: colors["--color-foreground"],
221 + unfocusedTextColor: colors["--color-foreground"],
222 + focusedIndicatorColor: colors["--color-focus"],
223 + unfocusedIndicatorColor: colors["--color-border"],
224 + cursorColor: colors["--color-focus"],
225 + }}
226 + >
227 + <OutlinedTextField.Label>
228 + <Text style={bodyTypography}>{props.request.title}</Text>
229 + </OutlinedTextField.Label>
230 + {props.inputPlaceholder ? (
231 + <OutlinedTextField.Placeholder>
232 + <Text style={bodyTypography}>{props.inputPlaceholder}</Text>
233 + </OutlinedTextField.Placeholder>
234 + ) : null}
235 + </OutlinedTextField>
236 + </Column>
237 </AlertDialog.Text>
238 ) : props.request.message ? (
239 <AlertDialog.Text>
@@ -253,6 +264,7 @@ interface DialogPresentationProps {
264 "title" | "message" | "cancelText" | "confirmText" | "destructive"
265 >;
266 readonly inputInitialValue?: string;
267 + readonly inputPlaceholder?: string;
268 readonly onInputChange?: (value: string) => void;
269 readonly onCancel: () => void;
270 readonly onConfirm: (inputValue?: string) => void;
apps/mobile/src/components/ui/Dialog.tsx
+1 -1
@@ -22,7 +22,7 @@ export function confirm(request: ConfirmDialogRequest): void {
22 export function prompt(request: TextInputDialogRequest): void {
23 Alert.prompt(
24 request.title,
25 - undefined,
25 + request.message,
26 [
27 { text: request.cancelText ?? "Cancel", style: "cancel", onPress: request.onCancel },
28 { text: request.confirmText, onPress: (value) => request.onConfirm(value ?? "") },
apps/mobile/src/components/ui/Dialog.types.ts
+2
@@ -10,6 +10,8 @@ export type ConfirmDialogRequest = {
10
11 export type TextInputDialogRequest = {
12 readonly title: string;
13 + readonly message?: string;
14 + readonly placeholder?: string;
15 readonly initialValue: string;
16 readonly cancelText?: string;
17 readonly confirmText: string;
apps/mobile/src/components/ui/Sheet.tsx
+3 -7
@@ -1,16 +1,12 @@
1 import { useId, useState } from "react";
2 import { Platform, View } from "react-native";
3 -import { FormSheet, Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
4 -import { useResolveClassNames, withUniwind } from "uniwind";
3 +import { FormSheet, ScreenStack } from "react-native-screens";
4 +import { useResolveClassNames } from "uniwind";
5
6 import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
7 +import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
8
9 const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
9 -const NativeScreen = withUniwind(Screen);
10 -const NativeHeader = withUniwind(ScreenStackHeaderConfig, {
11 - color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },
12 - titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },
13 -});
10
11 export type { SheetProps } from "./Sheet.types";
12 import type { SheetProps } from "./Sheet.types";
apps/mobile/src/features/home/HomeScreen.tsx
+12
@@ -63,6 +63,8 @@ import {
63 ThreadListV2WorkingShelfHeader,
64 } from "../threads/thread-list-v2-items";
65 import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance";
66 +import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
67 +import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
68 import {
69 buildThreadListV2Items,
70 getThreadListV2OrderedSection,
@@ -330,6 +332,14 @@ export function HomeScreen(props: HomeScreenProps) {
332 const handleScrollBeginDrag = useCallback(() => {
333 openSwipeableRef.current?.close();
334 }, []);
335 + const openThreadPullRequests = useOpenThreadPullRequests();
336 + const handleOpenThreadPullRequests = useCallback(
337 + (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
338 + openSwipeableRef.current?.close();
339 + openThreadPullRequests(thread, pr);
340 + },
341 + [openThreadPullRequests],
342 + );
343 const onFabScroll = useFabScroll();
344 const listRef = useRef<LegendListRef>(null);
345 const searchMode = workspace?.state.tabs.threads.searchMode;
@@ -769,6 +779,7 @@ export function HomeScreen(props: HomeScreenProps) {
779 )}
780 searchQuery={props.searchQuery}
781 onSelectThread={props.onSelectThread}
782 + onOpenThreadPullRequests={handleOpenThreadPullRequests}
783 onDeleteThread={handleDeleteThread}
784 onArchiveThread={props.onArchiveThread}
785 onRenameThread={handleRenameThread}
@@ -802,6 +813,7 @@ export function HomeScreen(props: HomeScreenProps) {
813 },
814 [
815 handleDeleteThread,
816 + handleOpenThreadPullRequests,
817 activeReorderEnvironmentIds,
818 handleMoveThread,
819 handlePinThread,
apps/mobile/src/features/home/ThreadListToolbar.tsx
+2 -1
@@ -23,6 +23,7 @@ import { WorkspaceConnectionTitle } from "./WorkspaceConnectionTitle";
23 import { useWorkspaceState } from "../../state/workspace";
24 import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
25 import { useToolbarLayout } from "../../components/ui/useToolbarLayout";
26 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
27
28 /** One toolbar height for the compact list and expanded sidebar, including search. */
29 export function ThreadListToolbar(props: {
@@ -129,7 +130,7 @@ export function ThreadListToolbar(props: {
130 {props.sidebar && workspace ? (
131 <AndroidHeaderIconButton
132 accessibilityLabel="Show pull requests"
132 - icon="arrow.triangle.pull"
133 + icon={PullRequestGlyph.pullRequest}
134 onPress={showPullRequests}
135 />
136 ) : null}
apps/mobile/src/features/keyboard/CommandPalette.tsx
+2 -1
@@ -38,6 +38,7 @@ import {
38 } from "./commandPaletteItems";
39 import { parseActiveThreadPath, type HardwareKeyboardCommand } from "./hardwareKeyboardCommands";
40 import { threadJumpIndex } from "./threadKeyboardShortcuts";
41 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
42
43 const PALETTE_COMMANDS: ReadonlyArray<HardwareKeyboardCommand> = [
44 "commandPalette",
@@ -59,7 +60,7 @@ const ACTION_ICONS: Record<string, AppSymbolName> = {
60 archive: "archivebox",
61 files: "doc.text",
62 terminal: "terminal",
62 - review: "arrow.triangle.pull",
63 + review: PullRequestGlyph.pullRequest,
64 copyThreadReference: "link",
65 };
66
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+4
@@ -64,6 +64,7 @@ import { AndroidWorkspaceSidebar } from "../workspace/AndroidWorkspaceSidebar";
64 import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
65 import { HomeListOptionsProvider } from "../home/home-list-options";
66 import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
67 +import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
68 import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
69 import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
70 import { WorkspaceInspectorPane } from "./workspace-inspector-pane";
@@ -460,6 +461,8 @@ function AdaptiveWorkspaceLayoutContent(
461 });
462 }, [navigation]);
463
464 + const handleOpenThreadPullRequests = useOpenThreadPullRequests();
465 +
466 const handleNewThreadOnBranch = useCallback(
467 (thread: EnvironmentThreadShell) => {
468 navigation.navigate("NewTaskSheet", {
@@ -758,6 +761,7 @@ function AdaptiveWorkspaceLayoutContent(
761 onNewThreadInProject={handleNewThreadInProject}
762 onNewThreadOnBranch={handleNewThreadOnBranch}
763 onSelectThread={handleSelectThread}
764 + onOpenThreadPullRequests={handleOpenThreadPullRequests}
765 onSearchQueryChange={setPrimarySidebarSearchQuery}
766 searchQuery={primarySidebarSearchQuery}
767 />
apps/mobile/src/features/pull-requests/PullRequestListRow.tsx
+29 -23
@@ -11,14 +11,23 @@ import {
11 THREAD_LIST_V2_SIDEBAR_ROW_STYLE,
12 THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE,
13 } from "../threads/thread-list-v2-row-appearance";
14 -import { PullRequestAvatar, PullRequestDiffStats } from "./PullRequestPresentation";
14 +import {
15 + PullRequestAvatar,
16 + PullRequestConflictBadge,
17 + PullRequestDiffStats,
18 +} from "./PullRequestPresentation";
19 import {
20 pullRequestLabelColor,
21 pullRequestListReviewStatus,
22 pullRequestListRowsAreEqual,
23 type EnvironmentPullRequestListEntry,
24 } from "./pullRequestList";
21 -import { pullRequestStatus } from "./pullRequestStatus";
25 +import {
26 + pullRequestChecksStatus,
27 + pullRequestConflict,
28 + pullRequestStatus,
29 +} from "./pullRequestStatus";
30 +import { PullRequestGlyph } from "./pullRequestGlyphs";
31
32 export const PullRequestListRow = memo(
33 function PullRequestListRow(props: {
@@ -47,13 +56,9 @@ export const PullRequestListRow = memo(
56 ? "text-drawer-foreground-muted"
57 : "text-foreground-tertiary";
58 const status = pullRequestStatus(item);
59 + const conflict = pullRequestConflict(item);
60 const review = pullRequestListReviewStatus(item);
51 - const checkTint =
52 - item.checksState === "passing"
53 - ? "accent-adaptive-emerald-600-400"
54 - : item.checksState === "failing"
55 - ? "accent-danger-foreground"
56 - : "accent-warning-foreground";
61 + const checks = item.checksState ? pullRequestChecksStatus(item.checksState) : null;
62 return (
63 <View style={props.sidebar ? THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE : undefined}>
64 <Menu
@@ -65,7 +70,7 @@ export const PullRequestListRow = memo(
70 <Pressable
71 accessibilityRole="button"
72 accessibilityState={{ selected: props.selected, busy: props.busy }}
68 - accessibilityLabel={`Pull request ${item.number}, ${item.title}, ${status.label}, by ${item.author?.login ?? "unknown author"}${review ? `, ${review.accessibleLabel}` : ""}${item.checksState ? `, checks ${item.checksState}` : ""}${item.stack ? `, stack ${item.stack.position} of ${item.stack.size}` : ""}${item.labels.length ? `, ${item.labels.map((label) => label.name).join(", ")}` : ""}, ${item.additions} additions, ${item.deletions} deletions`}
73 + accessibilityLabel={`Pull request ${item.number}, ${item.title}, ${status.label}${conflict ? `, ${conflict.label.toLowerCase()}` : ""}, by ${item.author?.login ?? "unknown author"}${review ? `, ${review.accessibleLabel}` : ""}${item.checksState ? `, checks ${item.checksState}` : ""}${item.stack ? `, stack ${item.stack.position} of ${item.stack.size}` : ""}${item.labels.length ? `, ${item.labels.map((label) => label.name).join(", ")}` : ""}, ${item.additions} additions, ${item.deletions} deletions`}
74 accessibilityHint="Double tap to open. Touch and hold for quick actions."
75 onPress={() => props.onSelect(item)}
76 disabled={props.busy}
@@ -79,8 +84,19 @@ export const PullRequestListRow = memo(
84 props.busy && "opacity-50",
85 )}
86 >
82 - <View className={props.sidebar ? "pt-0.5" : "pt-2.5"}>
87 + <View className={cn("self-start", props.sidebar ? "pt-0.5" : "pt-2.5")}>
88 <SymbolView name={status.icon} size={20} tintColorClassName={status.tint} />
89 + {conflict ? (
90 + <PullRequestConflictBadge
91 + surfaceClassName={
92 + props.selected
93 + ? "text-thread-selected"
94 + : props.sidebar
95 + ? "text-drawer"
96 + : "text-screen"
97 + }
98 + />
99 + ) : null}
100 </View>
101 <View
102 className={cn(
@@ -96,7 +112,7 @@ export const PullRequestListRow = memo(
112 {item.stack ? (
113 <View className="flex-row items-center gap-1">
114 <SymbolView
99 - name="square.3.layers.3d"
115 + name={PullRequestGlyph.stack}
116 size={12}
117 tintColorClassName={
118 props.selected
@@ -155,19 +171,9 @@ export const PullRequestListRow = memo(
171 </Text>
172 ) : null}
173 </View>
158 - {item.checksState ? (
174 + {checks ? (
175 <View className="shrink-0" accessibilityLabel={`Checks ${item.checksState}`}>
160 - <SymbolView
161 - name={
162 - item.checksState === "passing"
163 - ? "checkmark.circle"
164 - : item.checksState === "failing"
165 - ? "xmark.circle.fill"
166 - : "clock"
167 - }
168 - size={13}
169 - tintColorClassName={checkTint}
170 - />
176 + <SymbolView name={checks.icon} size={13} tintColorClassName={checks.tint} />
177 </View>
178 ) : null}
179 {review ? (
apps/mobile/src/features/pull-requests/PullRequestMergeControls.tsx
+2 -1
@@ -25,6 +25,7 @@ import { pullRequestStackMerge, singlePullRequestMergeAllowed } from "./pullRequ
25 import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
26 import { usePullRequestPermissions } from "./usePullRequestPermissions";
27 import type { PullRequestStackState } from "./usePullRequestStack";
28 +import { PullRequestGlyph } from "./pullRequestGlyphs";
29
30 export function PullRequestMergeControls(props: {
31 readonly pr: PullRequestDetail;
@@ -200,7 +201,7 @@ export function PullRequestMergeControls(props: {
201 <AppActivityIndicator size="small" colorClassName="accent-icon-muted" />
202 ) : (
203 <SymbolView
203 - name="arrow.triangle.merge"
204 + name={PullRequestGlyph.merged}
205 size={16}
206 tintColorClassName={
207 canMerge ? "accent-prominent-action-foreground" : "accent-icon-muted"
apps/mobile/src/features/pull-requests/PullRequestOverviewLoading.tsx
+2 -1
@@ -7,6 +7,7 @@ import { PullRequestStackCard } from "./PullRequestStackCard";
7 import type { PullRequestParams } from "./usePullRequestDiff";
8 import type { PullRequestStackState } from "./usePullRequestStack";
9 import { pullRequestListReviewStatus } from "./pullRequestList";
10 +import { PullRequestGlyph } from "./pullRequestGlyphs";
11
12 export function PullRequestOverviewLoading({
13 summary,
@@ -74,7 +75,7 @@ export function PullRequestOverviewLoading({
75 : "Branch"
76 }
77 icon={
77 - conflicting ? "exclamationmark.triangle" : clean ? "checkmark.circle" : "arrow.branch"
78 + conflicting ? PullRequestGlyph.conflicting : clean ? "checkmark.circle" : "arrow.branch"
79 }
80 tint={
81 conflicting
apps/mobile/src/features/pull-requests/PullRequestPresentation.tsx
+15
@@ -1,7 +1,9 @@
1 import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
2 import type { PullRequestActor } from "@t3tools/contracts";
3 +import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
4 import { Image } from "expo-image";
5 import { View } from "react-native";
6 +import { useResolveClassNames } from "uniwind";
7
8 import { AppText as Text } from "../../components/ui/AppText";
9 import { cn } from "../../lib/cn";
@@ -18,6 +20,19 @@ export function PullRequestReadStatus(props: {
20 ) : null;
21 }
22
23 +export function PullRequestConflictBadge(props: { readonly surfaceClassName: string }) {
24 + const { color } = useResolveClassNames("text-danger-foreground");
25 + const { color: surface } = useResolveClassNames(props.surfaceClassName);
26 + return (
27 + <View pointerEvents="none" className="absolute -right-1 -bottom-1">
28 + <IconAlertTriangle size={15} strokeWidth={2.5} color={surface} fill={surface} />
29 + <View className="absolute inset-0">
30 + <IconAlertTriangle size={15} strokeWidth={2.5} color={color} />
31 + </View>
32 + </View>
33 + );
34 +}
35 +
36 export function PullRequestAvatar(props: {
37 readonly actor: PullRequestActor | null;
38 readonly size?: number;
apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx
+3 -2
@@ -7,6 +7,7 @@ import { PullRequestCardGroup, PullRequestCardRow } from "./PullRequestControls"
7 import { pullRequestStatus } from "./pullRequestStatus";
8 import type { PullRequestParams } from "./usePullRequestDiff";
9 import type { PullRequestStackState } from "./usePullRequestStack";
10 +import { PullRequestGlyph } from "./pullRequestGlyphs";
11
12 export function PullRequestStackCard(props: {
13 readonly params: PullRequestParams;
@@ -26,7 +27,7 @@ export function PullRequestStackCard(props: {
27 <PullRequestCardGroup>
28 <PullRequestCardRow
29 title="Stack"
29 - icon="square.3.layers.3d"
30 + icon={PullRequestGlyph.stack}
31 value={`${summary.position} of ${summary.size}`}
32 last
33 />
@@ -38,7 +39,7 @@ export function PullRequestStackCard(props: {
39 <PullRequestCardGroup>
40 <PullRequestCardRow
41 title="Stack"
41 - icon="square.3.layers.3d"
42 + icon={PullRequestGlyph.stack}
43 value={`${position} of ${stack.layers.length}`}
44 accessibilityLabel={`Stack, ${position} of ${stack.layers.length}${props.state.isFresh ? "" : ", showing saved stack"}`}
45 expanded={expanded}
apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
+4 -1
@@ -12,6 +12,7 @@ import { Menu } from "../../components/ui/Menu";
12 import { PullRequestAvatar } from "./PullRequestPresentation";
13 import { PullRequestCardRow } from "./PullRequestControls";
14 import { PullRequestAgentRow } from "./PullRequestAgentRow";
15 +import { PullRequestGlyph } from "./pullRequestGlyphs";
16 import { composerPullRequests } from "../../state/pull-requests";
17 import { useEnvironmentQuery } from "../../state/query";
18 import { allowedUpdateMethods, PR_ACTION_ICONS, PR_ACTION_LABELS } from "./pullRequestActions";
@@ -189,7 +190,9 @@ export function PullRequestBranchRow(props: RowProps) {
190 ? `No conflicts with ${props.pr.baseBranch}`
191 : "Branch"
192 }
192 - icon={conflicting ? "exclamationmark.triangle" : clean ? "checkmark.circle" : "arrow.branch"}
193 + icon={
194 + conflicting ? PullRequestGlyph.conflicting : clean ? "checkmark.circle" : "arrow.branch"
195 + }
196 tint={
197 conflicting
198 ? "accent-danger-foreground"
apps/mobile/src/features/pull-requests/pullRequestActions.ts
+2 -1
@@ -6,6 +6,7 @@ import type {
6 SourceControlProviderKind,
7 } from "@t3tools/contracts";
8 import type { AppSymbolName } from "../../components/ui/AppSymbol";
9 +import { PullRequestGlyph } from "./pullRequestGlyphs";
10
11 type ActionDetail = Pick<
12 PullRequestDetail,
@@ -46,7 +47,7 @@ export const PR_ACTION_LABELS = {
47 } as const satisfies Record<PullRequestAction, string>;
48
49 export const PR_ACTION_ICONS = {
49 - merge: "arrow.triangle.merge",
50 + merge: PullRequestGlyph.merged,
51 ready: "checkmark.circle",
52 draft: "pencil",
53 close: "xmark",
apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts new
+10
@@ -0,0 +1,10 @@
1 +import type { AppSymbolName } from "../../components/ui/AppSymbol";
2 +
3 +export const PullRequestGlyph = {
4 + pullRequest: "arrow.triangle.pull",
5 + draft: "git.pull-request.draft",
6 + closed: "git.pull-request.closed",
7 + merged: "arrow.triangle.merge",
8 + stack: "square.3.layers.3d",
9 + conflicting: "exclamationmark.triangle",
10 +} as const satisfies Record<string, AppSymbolName>;
apps/mobile/src/features/pull-requests/pullRequestList.test.ts
+2
@@ -88,6 +88,8 @@ describe("recycled PR list rows", () => {
88 { viewerReviewRequested: true },
89 { isDraft: true },
90 { state: "closed" as const },
91 + { mergeability: "conflicting" as const },
92 + { baseBranch: "release" },
93 { author: { login: "another", name: null, avatarUrl: null } },
94 { author: { login: "octocat", name: null, avatarUrl: "https://example.com/avatar.png" } },
95 { labels: [{ name: "bug", color: "ff0000" }] },
apps/mobile/src/features/pull-requests/pullRequestList.ts
+2
@@ -60,6 +60,8 @@ export function pullRequestListRowsAreEqual(
60 previous.url === next.url &&
61 previous.state === next.state &&
62 previous.isDraft === next.isDraft &&
63 + previous.mergeability === next.mergeability &&
64 + previous.baseBranch === next.baseBranch &&
65 previous.updatedAt === next.updatedAt &&
66 previous.additions === next.additions &&
67 previous.deletions === next.deletions &&
apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts
+32 -1
@@ -1,6 +1,10 @@
1 import type { PullRequestActivity, PullRequestCheck, PullRequestComment } from "@t3tools/contracts";
2 import { describe, expect, it } from "vite-plus/test";
3 -import { pullRequestChecksSummary, pullRequestReviewSummary } from "./pullRequestStatus";
3 +import {
4 + pullRequestChecksSummary,
5 + pullRequestConflict,
6 + pullRequestReviewSummary,
7 +} from "./pullRequestStatus";
8
9 const author = { login: "julius", name: null, avatarUrl: null };
10 function review(state: string, at: string): PullRequestComment {
@@ -107,3 +111,30 @@ describe("mobile overview check status", () => {
111 ).toMatchObject({ title: "1 check failing", count: "1 of 3" });
112 });
113 });
114 +
115 +describe("mobile pull request conflict", () => {
116 + it("names the base branch of an open pull request with conflicts", () => {
117 + expect(
118 + pullRequestConflict({
119 + state: "open",
120 + isDraft: false,
121 + mergeability: "conflicting",
122 + baseBranch: "main",
123 + })?.label,
124 + ).toBe("Conflicts with main");
125 + expect(
126 + pullRequestConflict({ state: "open", isDraft: false, mergeability: "conflicting" })?.label,
127 + ).toBe("Has conflicts");
128 + });
129 +
130 + it.each([
131 + { state: "open" as const, isDraft: true, mergeability: "conflicting" as const },
132 + { state: "merged" as const, isDraft: false, mergeability: "conflicting" as const },
133 + { state: "closed" as const, isDraft: false, mergeability: "conflicting" as const },
134 + { state: "open" as const, isDraft: false, mergeability: "mergeable" as const },
135 + { state: "open" as const, isDraft: false, mergeability: "unknown" as const },
136 + { state: "open" as const, isDraft: false },
137 + ])("stays quiet when it cannot conflict or has not been reported: %j", (pr) => {
138 + expect(pullRequestConflict(pr)).toBeNull();
139 + });
140 +});
apps/mobile/src/features/pull-requests/pullRequestStatus.ts
+25 -4
@@ -1,36 +1,39 @@
1 import type {
2 PullRequestActivity,
3 PullRequestCheck,
4 + PullRequestChecksState,
5 PullRequestDetail,
6 PullRequestListEntry,
7 + PullRequestMergeability,
8 } from "@t3tools/contracts";
9 import type { AppSymbolName } from "../../components/ui/AppSymbol";
10 +import { PullRequestGlyph } from "./pullRequestGlyphs";
11
12 const STATES = {
13 open: {
14 label: "Open",
12 - icon: "arrow.triangle.pull",
15 + icon: PullRequestGlyph.pullRequest,
16 tint: "accent-adaptive-emerald-600-400",
17 text: "text-adaptive-emerald-600-400",
18 background: "bg-adaptive-emerald-500-a12-a16",
19 },
20 merged: {
21 label: "Merged",
19 - icon: "arrow.triangle.merge",
22 + icon: PullRequestGlyph.merged,
23 tint: "accent-adaptive-violet-600-400",
24 text: "text-adaptive-violet-600-400",
25 background: "bg-adaptive-violet-500-a12-a16",
26 },
27 closed: {
28 label: "Closed",
26 - icon: "git.pull-request.closed",
29 + icon: PullRequestGlyph.closed,
30 tint: "accent-danger-foreground",
31 text: "text-danger-foreground",
32 background: "bg-danger",
33 },
34 draft: {
35 label: "Draft",
33 - icon: "git.pull-request.draft",
36 + icon: PullRequestGlyph.draft,
37 tint: "accent-icon-muted",
38 text: "text-foreground-muted",
39 background: "bg-grouped-card",
@@ -44,6 +47,16 @@ export function pullRequestStatus(pr: Pick<PullRequestListEntry, "state" | "isDr
47 return STATES[pr.isDraft && pr.state === "open" ? "draft" : pr.state];
48 }
49
50 +export function pullRequestConflict(pr: {
51 + readonly state: PullRequestListEntry["state"];
52 + readonly isDraft: boolean;
53 + readonly mergeability?: PullRequestMergeability | undefined;
54 + readonly baseBranch?: string | undefined;
55 +}) {
56 + if (pr.state !== "open" || pr.isDraft || pr.mergeability !== "conflicting") return null;
57 + return { label: pr.baseBranch ? `Conflicts with ${pr.baseBranch}` : "Has conflicts" };
58 +}
59 +
60 export function checkStatus(check: PullRequestCheck) {
61 switch (check.status) {
62 case "success":
@@ -200,3 +213,11 @@ export function pullRequestBranchSummary(
213 if (pr.baseComparison === "up-to-date") return "Up to date";
214 return pr.mergeability === "mergeable" ? "No conflicts" : "Not reported";
215 }
216 +
217 +export function pullRequestChecksStatus(state: PullRequestChecksState) {
218 + if (state === "passing")
219 + return { icon: "checkmark.circle", tint: "accent-adaptive-emerald-600-400" } as const;
220 + if (state === "failing")
221 + return { icon: "xmark.circle.fill", tint: "accent-danger-foreground" } as const;
222 + return { icon: "clock", tint: "accent-warning-foreground" } as const;
223 +}
apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx
+2 -1
@@ -39,6 +39,7 @@ import {
39 uniformMobileSetting,
40 type ScopedMobileSettingsTarget,
41 } from "./settings-scoped-server";
42 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
43
44 type SettingsPage = "new-threads" | "source-control" | "agent-behavior" | "maintenance";
45
@@ -359,7 +360,7 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
360 />
361 <SettingsSection title="Pull requests">
362 <SettingsSwitchRow
362 - icon="arrow.triangle.merge"
363 + icon={PullRequestGlyph.merged}
364 label="Remove agent credits when merging"
365 subtitle="Remove recognized agent credits from GitHub merge and squash messages, keeping human co-authors. Includes auto-merge. Excludes merge queues, stack merges, and existing commits."
366 value={uniform("removeAgentCreditsOnMerge")}
apps/mobile/src/features/threads/ComposerCommandPopover.tsx
+7 -2
@@ -16,6 +16,7 @@ import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
16 import { AppText as Text } from "../../components/ui/AppText";
17 import { GlassSurface } from "../../components/ui/GlassSurface";
18 import { PierreEntryIcon } from "../../components/PierreEntryIcon";
19 +import { pullRequestStatus } from "../pull-requests/pullRequestStatus";
20 export type ComposerCommandItem =
21 | {
22 readonly id: string;
@@ -99,7 +100,7 @@ const SKILL_SOURCE_SYMBOL_BY_KIND: Record<ProviderSkillSourceKind, AppSymbolName
100 function itemIcon(item: ComposerCommandItem): AppSymbolName | null {
101 switch (item.type) {
102 case "pull-request":
102 - return { ios: "arrow.triangle.pull", android: "merge" };
103 + return pullRequestStatus(item.pullRequest).icon;
104 case "slash-command":
105 case "provider-slash-command":
106 return "terminal";
@@ -166,7 +167,11 @@ const CommandRow = memo(function CommandRow(props: {
167 <SymbolView
168 name={iconName}
169 size={14}
169 - tintColorClassName={"accent-icon-subtle"}
170 + tintColorClassName={
171 + props.item.type === "pull-request"
172 + ? pullRequestStatus(props.item.pullRequest).tint
173 + : "accent-icon-subtle"
174 + }
175 type="monochrome"
176 />
177 ) : null}
apps/mobile/src/features/threads/LinkedPullRequestList.tsx new
+174
@@ -0,0 +1,174 @@
1 +import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2 +import {
3 + pullRequestListLines,
4 + resolveThreadPullRequestChains,
5 + threadPullRequestKeyOf,
6 + type PullRequestListLine,
7 +} from "@t3tools/shared/threadPullRequests";
8 +import { memo, useMemo } from "react";
9 +import { Pressable, useWindowDimensions, View } from "react-native";
10 +
11 +import { SymbolView } from "../../components/ui/AppSymbol";
12 +import { AppText as Text } from "../../components/ui/AppText";
13 +import * as Dialog from "../../components/ui/Dialog";
14 +import { Menu } from "../../components/ui/Menu";
15 +import { cn } from "../../lib/cn";
16 +import { relativeTime } from "../../lib/time";
17 +import type { EnvironmentRuntimeState } from "../../state/remote-runtime-types";
18 +import { useScaledTextRole } from "../settings/appearance/useScaledTextRole";
19 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
20 +import type { LinkedPullRequestActions } from "./useLinkedPullRequestActions";
21 +import { pullRequestListReviewStatus } from "../pull-requests/pullRequestList";
22 +import {
23 + PullRequestAvatar,
24 + PullRequestConflictBadge,
25 + PullRequestDiffStats,
26 +} from "../pull-requests/PullRequestPresentation";
27 +import {
28 + pullRequestChecksStatus,
29 + pullRequestConflict,
30 + pullRequestStatus,
31 +} from "../pull-requests/pullRequestStatus";
32 +
33 +export function useLinkedPullRequestLines(
34 + thread: EnvironmentThreadShell | null,
35 + runtime: EnvironmentRuntimeState | null,
36 +) {
37 + const supported = runtime?.serverConfig?.environment.capabilities.threadPullRequests === true;
38 + const pullRequests = thread?.pullRequests;
39 + return useMemo(() => {
40 + const chains = resolveThreadPullRequestChains(supported ? (pullRequests ?? []) : []);
41 + const open = chains.filter((chain) => chain.layers.some(isOpenLink));
42 + const done = chains.filter((chain) => !chain.layers.some(isOpenLink));
43 + return [...pullRequestListLines(open), ...pullRequestListLines(done)];
44 + }, [pullRequests, supported]);
45 +}
46 +
47 +function isOpenLink(link: PullRequestListLine["link"]) {
48 + return link.snapshot === null || link.snapshot.state === "open";
49 +}
50 +
51 +export function linkedPullRequestKey(line: PullRequestListLine) {
52 + return threadPullRequestKeyOf(line.link);
53 +}
54 +
55 +export const LinkedPullRequestRow = memo(function LinkedPullRequestRow(props: {
56 + readonly line: PullRequestListLine;
57 + readonly separator: boolean;
58 + readonly surfaceClassName: string;
59 + readonly openPullRequest: (url: string) => Promise<boolean>;
60 + readonly actions: LinkedPullRequestActions | null;
61 +}) {
62 + const { link, depth, stack } = props.line;
63 + const snapshot = link.snapshot;
64 + const status = snapshot === null ? null : pullRequestStatus(snapshot);
65 + const conflict = snapshot === null ? null : pullRequestConflict(snapshot);
66 + const open = snapshot === null || snapshot.state === "open";
67 + const checks =
68 + open && snapshot?.checksState ? pullRequestChecksStatus(snapshot.checksState) : null;
69 + const review =
70 + open && snapshot?.reviewDecision
71 + ? pullRequestListReviewStatus({
72 + reviewDecision: snapshot.reviewDecision,
73 + viewerReviewRequested: false,
74 + })
75 + : null;
76 + const watching = open && link.watch !== undefined;
77 + const additions = snapshot?.additions ?? 0;
78 + const deletions = snapshot?.deletions ?? 0;
79 + const metaLineHeight = useScaledTextRole("label").lineHeight * useWindowDimensions().fontScale;
80 + const row = (
81 + <Pressable
82 + accessibilityRole="button"
83 + accessibilityLabel={`Pull request ${link.number}, ${snapshot?.title ?? "waiting for host state"}${status ? `, ${status.label}` : ""}${conflict ? `, ${conflict.label.toLowerCase()}` : ""}, ${link.repository}${stack ? `, stack of ${stack.size}` : ""}${watching ? ", watching" : ""}${checks ? `, checks ${snapshot?.checksState}` : ""}${review ? `, ${review.accessibleLabel}` : ""}`}
84 + accessibilityHint={props.actions ? "Touch and hold for actions." : undefined}
85 + onPress={() => {
86 + void props.openPullRequest(link.url).then((opened) => {
87 + if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
88 + });
89 + }}
90 + // Steps in per layer like the web list, capped so deep stacks keep their width.
91 + style={{ paddingLeft: 16 + Math.min(depth, 3) * 16 }}
92 + className="flex-row gap-3 rounded-xl pr-4 active:bg-row-hover"
93 + >
94 + {depth > 0 ? <View className="-ml-2 w-px self-stretch bg-border" /> : null}
95 + <View className="self-start pt-2.5">
96 + <SymbolView
97 + name={status?.icon ?? PullRequestGlyph.pullRequest}
98 + size={20}
99 + tintColorClassName={status?.tint ?? "accent-icon-muted"}
100 + />
101 + {conflict ? <PullRequestConflictBadge surfaceClassName={props.surfaceClassName} /> : null}
102 + </View>
103 + <View
104 + className={cn(
105 + "min-w-0 flex-1 gap-1 py-2.5",
106 + props.separator && "border-b border-border-subtle",
107 + )}
108 + >
109 + <View className="flex-row items-center gap-1.5">
110 + {snapshot?.author ? <PullRequestAvatar actor={snapshot.author} size={16} /> : null}
111 + <Text className="min-w-0 shrink text-xs text-foreground-muted" numberOfLines={1}>
112 + {link.repository}
113 + </Text>
114 + <Text className="shrink-0 text-xs text-foreground-tertiary">#{link.number}</Text>
115 + <View className="flex-1" />
116 + {stack ? (
117 + <View className="flex-row items-center gap-1">
118 + <SymbolView
119 + name={PullRequestGlyph.stack}
120 + size={12}
121 + tintColorClassName="accent-foreground-muted"
122 + />
123 + <Text className="text-2xs tabular-nums text-foreground-muted">{stack.size}</Text>
124 + </View>
125 + ) : null}
126 + {watching ? (
127 + <SymbolView name="eye" size={13} tintColorClassName="accent-foreground-muted" />
128 + ) : null}
129 + {checks ? (
130 + <SymbolView name={checks.icon} size={13} tintColorClassName={checks.tint} />
131 + ) : null}
132 + {review ? (
133 + <SymbolView name={review.icon} size={13} tintColorClassName={review.tint} />
134 + ) : null}
135 + {additions + deletions > 0 || snapshot?.updatedAt ? (
136 + <View
137 + className="-ml-1.5 flex-row flex-wrap items-center gap-x-1.5 overflow-hidden"
138 + style={{ height: metaLineHeight, flexShrink: 100 }}
139 + >
140 + <View className="w-0" />
141 + {additions + deletions > 0 ? (
142 + <PullRequestDiffStats additions={additions} deletions={deletions} compact />
143 + ) : null}
144 + {snapshot?.updatedAt ? (
145 + <Text className="text-2xs tabular-nums text-foreground-tertiary">
146 + {relativeTime(snapshot.updatedAt)}
147 + </Text>
148 + ) : null}
149 + </View>
150 + ) : null}
151 + </View>
152 + <Text
153 + className="text-base leading-5 font-t3-medium text-foreground"
154 + numberOfLines={2}
155 + ellipsizeMode="tail"
156 + >
157 + {snapshot?.title ?? "Waiting for host state"}
158 + </Text>
159 + </View>
160 + </Pressable>
161 + );
162 + const actions = props.actions;
163 + if (actions === null) return row;
164 + return (
165 + <Menu
166 + shouldOpenOnLongPress
167 + title={`#${link.number} · ${link.repository}`}
168 + actions={actions.menuActions(link)}
169 + onPressAction={({ nativeEvent }) => actions.onMenuAction(link, nativeEvent.event)}
170 + >
171 + {row}
172 + </Menu>
173 + );
174 +});
apps/mobile/src/features/threads/ThreadGitControls.tsx
+2 -1
@@ -20,6 +20,7 @@ import { useNavigation } from "@react-navigation/native";
20
21 import { useCallback, useMemo } from "react";
22 import { useEnvironmentScope } from "../../state/session";
23 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
24 import {
25 basename,
26 getTerminalStatusLabel,
@@ -385,7 +386,7 @@ function useThreadGitHeaderActionItems(props: ThreadGitControlsProps): ThreadGit
386 ? [
387 {
388 description: "Bring this thread's latest turn into its source",
388 - icon: { name: "arrow.triangle.merge", type: "sfSymbol" as const },
389 + icon: { name: PullRequestGlyph.merged, type: "sfSymbol" as const },
390 label: "Merge back to source",
391 onPress: props.onMergeBack,
392 type: "action" as const,
apps/mobile/src/features/threads/ThreadHeader.tsx
+2 -1
@@ -6,6 +6,7 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
6 import type { ThreadInspectorMode } from "./thread-inspector-content-stack";
7 import { useThreadHeaderOptions } from "./useThreadHeaderOptions";
8 import { useWorkspaceListNavigation } from "../workspace/useAndroidWorkspaceNavigation";
9 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
10
11 export function ThreadHeader(
12 props: Parameters<typeof useThreadHeaderOptions>[0] & {
@@ -55,7 +56,7 @@ export function ThreadHeader(
56 if (onMergeBack) {
57 actions.push({
58 accessibilityLabel: "Merge back to source",
58 - icon: "arrow.triangle.merge",
59 + icon: PullRequestGlyph.merged,
60 onPress: onMergeBack,
61 });
62 }
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+14
@@ -65,6 +65,7 @@ import {
65 ThreadListV2WorkingShelfHeader,
66 } from "./thread-list-v2-items";
67 import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
68 +import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
69 import {
70 buildThreadListV2Items,
71 getThreadListV2OrderedSection,
@@ -93,6 +94,10 @@ interface ThreadNavigationSidebarProps {
94 readonly onNewThreadInProject: (project: EnvironmentProject) => void;
95 readonly onSearchQueryChange: (query: string) => void;
96 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
97 + readonly onOpenThreadPullRequests: (
98 + thread: EnvironmentThreadShell,
99 + pr: ThreadPrPresentation,
100 + ) => void;
101 readonly onRequestVisibility: () => void;
102 readonly searchQuery: string;
103 }
@@ -557,6 +562,13 @@ function ThreadNavigationSidebarPane(
562 },
563 [props.onSelectThread],
564 );
565 + const handleOpenThreadPullRequests = useCallback(
566 + (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
567 + props.onOpenThreadPullRequests(thread, pr);
568 + openSwipeableRef.current?.close();
569 + },
570 + [props.onOpenThreadPullRequests],
571 + );
572 const handleScrollBeginDrag = useCallback(() => {
573 openSwipeableRef.current?.close();
574 }, []);
@@ -684,6 +696,7 @@ function ThreadNavigationSidebarPane(
696 }
697 fullSwipeWidth={props.width - 20}
698 onSelectThread={handleSelectThread}
699 + onOpenThreadPullRequests={handleOpenThreadPullRequests}
700 onDeleteThread={confirmDeleteThread}
701 onArchiveThread={archiveThread}
702 onRenameThread={renameThread}
@@ -759,6 +772,7 @@ function ThreadNavigationSidebarPane(
772 activeReorderEnvironmentIds,
773 confirmDeletePendingTask,
774 confirmDeleteThread,
775 + handleOpenThreadPullRequests,
776 handleSelectThread,
777 handleSwipeableClose,
778 handleSwipeableWillOpen,
apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx new
+162
@@ -0,0 +1,162 @@
1 +import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
2 +import { LegendList } from "@legendapp/list/react-native";
3 +import { useMemo } from "react";
4 +import { Platform, View } from "react-native";
5 +import { ScreenStack } from "react-native-screens";
6 +import { useSafeAreaInsets } from "react-native-safe-area-context";
7 +
8 +import { AndroidSheetHeader } from "../../components/ui/AndroidScreenHeader";
9 +import { AppText as Text } from "../../components/ui/AppText";
10 +import { ScreenContent } from "../../components/ui/ScreenContent";
11 +import { NativeSheetContent } from "../../native/NativeSheetContent";
12 +import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
13 +import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
14 +import { useOpenPullRequest } from "../../native/useOpenPullRequest";
15 +import { useThreadSelection } from "../../state/use-thread-selection";
16 +import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
17 +import {
18 + LinkedPullRequestRow,
19 + linkedPullRequestKey,
20 + useLinkedPullRequestLines,
21 +} from "./LinkedPullRequestList";
22 +import { useLinkedPullRequestActions } from "./useLinkedPullRequestActions";
23 +
24 +const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
25 +const TITLE = "Linked pull requests";
26 +
27 +export function ThreadPullRequestsSheet(
28 + _props: StaticScreenProps<{ readonly environmentId: string; readonly threadId: string }>,
29 +) {
30 + const { layout } = useAdaptiveWorkspaceLayout();
31 + const navigation = useNavigation();
32 + const insets = useSafeAreaInsets();
33 + const { selectedThread, selectedThreadProject, selectedEnvironmentRuntime } =
34 + useThreadSelection();
35 + const lines = useLinkedPullRequestLines(selectedThread, selectedEnvironmentRuntime);
36 + const openCount = useMemo(
37 + () =>
38 + lines.filter((line) => line.link.snapshot === null || line.link.snapshot.state === "open")
39 + .length,
40 + [lines],
41 + );
42 + const openPullRequest = useOpenPullRequest({
43 + replace: true,
44 + context: selectedThread ?? undefined,
45 + });
46 + const actions = useLinkedPullRequestActions({
47 + thread: selectedThread,
48 + project: selectedThreadProject,
49 + runtime: selectedEnvironmentRuntime,
50 + });
51 + const rowInputs = useMemo(() => ({ lines, actions }), [lines, actions]);
52 +
53 + const content = (
54 + <View className="flex-1 android:bg-sheet-solid ios:bg-screen">
55 + <LegendList
56 + data={lines}
57 + keyExtractor={linkedPullRequestKey}
58 + extraData={rowInputs}
59 + renderItem={({ item, index }) => (
60 + <LinkedPullRequestRow
61 + line={item}
62 + separator={index < lines.length - 1}
63 + surfaceClassName={Platform.OS === "ios" ? "text-screen" : "text-sheet-solid"}
64 + openPullRequest={openPullRequest}
65 + actions={actions}
66 + />
67 + )}
68 + estimatedItemSize={88}
69 + recycleItems
70 + alwaysBounceVertical
71 + style={{ flex: 1 }}
72 + contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
73 + showsVerticalScrollIndicator={false}
74 + contentContainerStyle={{
75 + paddingBottom: Math.max(insets.bottom, 18) + 18,
76 + paddingHorizontal: 8,
77 + }}
78 + ListHeaderComponent={
79 + lines.length > 0 ? (
80 + <Text className="px-4 pt-2 pb-1 text-xs text-foreground-muted">
81 + {openCount} open · {lines.length} linked
82 + </Text>
83 + ) : null
84 + }
85 + ListEmptyComponent={
86 + <Text className="pt-6 text-center text-sm text-foreground-muted">
87 + No linked pull requests.
88 + </Text>
89 + }
90 + />
91 + </View>
92 + );
93 +
94 + if (Platform.OS === "ios") {
95 + // A plain formSheet screen never renders a stack header, so it comes from
96 + // a nested native stack inside the sheet (same shape as the git sheet).
97 + return (
98 + <View collapsable={false} className="flex-1 bg-sheet">
99 + <ScreenStack style={{ flex: 1 }}>
100 + <NativeScreen
101 + activityState={2}
102 + enabled
103 + isNativeStack
104 + screenId="thread-pull-requests-sheet-native"
105 + scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}
106 + className="flex-1 bg-sheet"
107 + >
108 + <NativeSheetContent>{content}</NativeSheetContent>
109 + <NativeHeader
110 + backgroundColor="rgba(0,0,0,0)"
111 + tintColorClassName="accent-foreground"
112 + hideBackButton
113 + hideShadow={false}
114 + navigationItemStyle="editor"
115 + title={TITLE}
116 + titleColorClassName="accent-foreground"
117 + titleFontSize={18}
118 + titleFontWeight="800"
119 + translucent
120 + headerRightBarButtonItems={
121 + actions.canLink
122 + ? [
123 + {
124 + type: "button",
125 + accessibilityLabel: "Link pull request",
126 + icon: { name: "plus", type: "sfSymbol" },
127 + identifier: "thread-pull-requests-link",
128 + onPress: actions.promptLink,
129 + },
130 + ]
131 + : undefined
132 + }
133 + />
134 + </NativeScreen>
135 + </ScreenStack>
136 + </View>
137 + );
138 + }
139 +
140 + return (
141 + <View collapsable={false} className="flex-1 bg-header">
142 + <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
143 + <AndroidSheetHeader
144 + title={TITLE}
145 + hideBottomBorder
146 + onBack={() => navigation.goBack()}
147 + actions={
148 + actions.canLink
149 + ? [
150 + {
151 + accessibilityLabel: "Link pull request",
152 + icon: "plus",
153 + onPress: actions.promptLink,
154 + },
155 + ]
156 + : undefined
157 + }
158 + />
159 + <ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
160 + </View>
161 + );
162 +}
apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
+42 -61
@@ -6,10 +6,6 @@ import {
6 getGitActionDisabledReason,
7 requiresDefaultBranchConfirmation,
8 } from "@t3tools/client-runtime/state/vcs";
9 -import {
10 - resolveThreadPullRequestChains,
11 - threadPullRequestKeyOf,
12 -} from "@t3tools/shared/threadPullRequests";
9 import { EnvironmentId, ThreadId } from "@t3tools/contracts";
10 import {
11 CommonActions,
@@ -45,6 +41,12 @@ import { useSelectedThreadWorktree } from "../../../state/use-selected-thread-wo
41 import { vcsEnvironment } from "../../../state/vcs";
42 import { resolveGitOverviewReviewNavigationAction } from "./git-overview-navigation";
43 import { MetaCard, SheetListRow, menuItemIconName, statusSummary } from "./gitSheetComponents";
44 +import {
45 + LinkedPullRequestRow,
46 + linkedPullRequestKey,
47 + useLinkedPullRequestLines,
48 +} from "../LinkedPullRequestList";
49 +import { useLinkedPullRequestActions } from "../useLinkedPullRequestActions";
50
51 const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
52
@@ -72,21 +74,22 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
74 const navigation = useNavigation();
75 const insets = useSafeAreaInsets();
76 const presentation = props.presentation ?? "sheet";
75 - const openPullRequest = useOpenPullRequest({ replace: presentation === "sheet" });
77 const isInspector = presentation === "inspector";
78 const environmentId = EnvironmentId.make(props.route.params.environmentId);
79 const threadId = ThreadId.make(props.route.params.threadId);
79 - const { selectedThread, selectedEnvironmentRuntime } = useThreadSelection();
80 + const { selectedThread, selectedThreadProject, selectedEnvironmentRuntime } =
81 + useThreadSelection();
82 + const openPullRequest = useOpenPullRequest({
83 + replace: presentation === "sheet",
84 + context: selectedThread ?? undefined,
85 + });
86 const { selectedThreadCwd, selectedThreadWorktreePath } = useSelectedThreadWorktree();
81 - const supportsLinkedPrSnapshots =
82 - selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.threadPullRequests === true;
83 - const linkedPrChains = useMemo(
84 - () =>
85 - resolveThreadPullRequestChains(
86 - supportsLinkedPrSnapshots ? (selectedThread?.pullRequests ?? []) : [],
87 - ),
88 - [selectedThread?.pullRequests, supportsLinkedPrSnapshots],
89 - );
87 + const linkedPrLines = useLinkedPullRequestLines(selectedThread, selectedEnvironmentRuntime);
88 + const linkedPrActions = useLinkedPullRequestActions({
89 + thread: selectedThread,
90 + project: selectedThreadProject,
91 + runtime: selectedEnvironmentRuntime,
92 + });
93 const gitState = useSelectedThreadGitState();
94 const gitActions = useSelectedThreadGitActions();
95 const { canWriteSourceControl, canChangeThreadBranch } = gitActions;
@@ -349,58 +352,36 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
352 })
353 }
354 />
355 + {linkedPrActions.canLink ? (
356 + <>
357 + {Platform.OS !== "android" ? <View className="ml-12 h-px bg-border" /> : null}
358 + <SheetListRow
359 + icon="link"
360 + title="Link pull request"
361 + subtitle="Attach a pull request by URL or number"
362 + onPress={linkedPrActions.promptLink}
363 + />
364 + </>
365 + ) : null}
366 </View>
367
354 - {linkedPrChains.length > 0 ? (
368 + {linkedPrLines.length > 0 ? (
369 <View className="gap-2">
370 <Text className="px-1 text-xs font-t3-bold text-foreground-muted">
371 Linked pull requests
372 </Text>
359 - {linkedPrChains.map((chain) => (
360 - <View
361 - key={threadPullRequestKeyOf(chain.layers[0]!)}
362 - className="overflow-hidden bg-card android:rounded-[20px] ios:rounded-2xl ios:border ios:border-border ios:px-3 ios:py-1"
363 - >
364 - {chain.layers.length > 1 ? (
365 - <View className="flex-row items-center gap-2 px-1 pt-2 pb-1">
366 - <SymbolView
367 - name="square.3.layers.3d"
368 - size={14}
369 - tintColorClassName="accent-foreground-muted"
370 - />
371 - <Text className="text-xs text-foreground-muted">
372 - {chain.kind === "native" ? "Stack" : "Branch stack"} · {chain.layers.length} PRs
373 - · bottom to top
374 - </Text>
375 - </View>
376 - ) : null}
377 - {chain.layers.map((link, index) => (
378 - <View
379 - key={threadPullRequestKeyOf(link)}
380 - // Steps in per layer like the web list, capped so deep stacks keep their width.
381 - style={{ paddingLeft: Math.min(chain.depths[index]!, 3) * 16 }}
382 - >
383 - {index > 0 && Platform.OS !== "android" ? (
384 - <View className="ml-12 h-px bg-border" />
385 - ) : null}
386 - <SheetListRow
387 - icon="arrow.triangle.pull"
388 - title={`#${link.number} ${link.snapshot?.title ?? "Pull request"}`}
389 - subtitle={`${link.repository} · ${link.snapshot === null ? "Status pending" : link.snapshot.isDraft && link.snapshot.state === "open" ? "Draft" : link.snapshot.state}${link.watch === undefined ? "" : " · Watching"}`}
390 - onPress={() => {
391 - void openPullRequest(link.url).then((opened) => {
392 - if (!opened)
393 - Dialog.alert(
394 - "Unable to open PR",
395 - "The pull request could not be opened.",
396 - );
397 - });
398 - }}
399 - />
400 - </View>
401 - ))}
402 - </View>
403 - ))}
373 + <View className="overflow-hidden bg-card android:rounded-[20px] ios:rounded-2xl ios:border ios:border-border">
374 + {linkedPrLines.map((line, index) => (
375 + <LinkedPullRequestRow
376 + key={linkedPullRequestKey(line)}
377 + line={line}
378 + separator={index < linkedPrLines.length - 1}
379 + surfaceClassName="text-card"
380 + openPullRequest={openPullRequest}
381 + actions={linkedPrActions}
382 + />
383 + ))}
384 + </View>
385 </View>
386 ) : null}
387
apps/mobile/src/features/threads/git/gitSheetComponents.tsx
+2 -1
@@ -83,6 +83,7 @@ export function MetaCard(props: { readonly label: string; readonly value: string
83
84 export function SheetListRow(props: {
85 readonly icon: ComponentProps<typeof SymbolView>["name"];
86 + readonly iconTintClassName?: string | undefined;
87 readonly title: string;
88 readonly subtitle?: string | null;
89 readonly disabled?: boolean;
@@ -98,7 +99,7 @@ export function SheetListRow(props: {
99 <SymbolView
100 name={props.icon}
101 size={Platform.OS === "android" ? 24 : 16}
101 - tintColorClassName="accent-icon"
102 + tintColorClassName={props.iconTintClassName ?? "accent-icon"}
103 type="monochrome"
104 />
105 </View>
apps/mobile/src/features/threads/thread-list-v2-items.tsx
+45 -3
@@ -37,6 +37,10 @@ import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
37 import { useUniwindTheme } from "../../lib/useUniwindTheme";
38 import { useEnvironmentScope } from "../../state/session";
39 import type { PendingNewTask } from "../../state/use-pending-new-tasks";
40 +import {
41 + resolveThreadPrBadgeAction,
42 + type ThreadPrPresentation,
43 +} from "../../state/thread-pr-presentation";
44 import { useThreadPr } from "../../state/use-thread-pr";
45 import { useSwipeRowDormant } from "../home/swipe-row-activation";
46 import { ThreadSwipeable } from "../home/thread-swipe-actions";
@@ -54,6 +58,8 @@ import {
58 import { QueuedMessageIcon } from "./queued-message-icon";
59 import { shouldRecedeThreadRow } from "./thread-row-emphasis";
60 import { ThreadSearchMatchExcerpt } from "./thread-search-match";
61 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
62 +import { pullRequestStatus } from "../pull-requests/pullRequestStatus";
63
64 interface StatusLabel {
65 readonly label: string;
@@ -485,6 +491,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
491 readonly selected?: boolean;
492 readonly fullSwipeWidth?: number;
493 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
494 + readonly onOpenThreadPullRequests: (
495 + thread: EnvironmentThreadShell,
496 + pr: ThreadPrPresentation,
497 + ) => void;
498 readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
499 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
500 readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
@@ -521,6 +531,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
531 thread,
532 variant,
533 onSelectThread,
534 + onOpenThreadPullRequests,
535 onDeleteThread,
536 onRenameThread,
537 onRegenerateThreadTitle,
@@ -553,6 +564,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
564
565 const providerInstance = props.providerInstance;
566 const pr = useThreadPr(thread);
567 + const prBadgeLabel = pr ? resolveThreadPrBadgeAction(pr).accessibilityLabel : null;
568 + const handleOpenPullRequests = useCallback(() => {
569 + if (pr) onOpenThreadPullRequests(thread, pr);
570 + }, [onOpenThreadPullRequests, pr, thread]);
571 + // VoiceOver cannot focus the badge inside the accessible row, so the row
572 + // exposes the same action.
573 + const rowAccessibilityActions = useMemo(
574 + () => (prBadgeLabel ? [{ name: "openPullRequests", label: prBadgeLabel }] : undefined),
575 + [prBadgeLabel],
576 + );
577
578 const theme = useUniwindTheme();
579 const sidebarPane = props.pane === "sidebar";
@@ -1047,9 +1068,26 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
1068 <View className="flex-1" />
1069 )}
1070 {pr ? (
1050 - <View className="flex-row items-center gap-1" accessibilityLabel={pr.accessibilityLabel}>
1071 + <Pressable
1072 + // Padding cancelled by negative margin grows the touch target into
1073 + // the row padding without moving the badge.
1074 + className="-m-2.5 flex-row items-center gap-1 p-2.5"
1075 + accessibilityRole="button"
1076 + accessibilityLabel={prBadgeLabel ?? undefined}
1077 + onPress={handleOpenPullRequests}
1078 + // Without a long-press handler a hold that opens the row's iOS
1079 + // context menu would also open the pull request on release.
1080 + onLongPress={() => undefined}
1081 + style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
1082 + >
1083 <SymbolView
1052 - name={pr.kind === "stack" ? "square.3.layers.3d" : "arrow.triangle.pull"}
1084 + name={
1085 + pr.kind === "stack"
1086 + ? PullRequestGlyph.stack
1087 + : pr.state === null
1088 + ? PullRequestGlyph.pullRequest
1089 + : pullRequestStatus({ state: pr.state, isDraft: pr.isDraft }).icon
1090 + }
1091 size={12}
1092 tintColorClassName={
1093 pr.state === null || pr.isDraft
@@ -1068,7 +1106,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
1106 >
1107 {pr.label}
1108 </Text>
1071 - </View>
1109 + </Pressable>
1110 ) : null}
1111 {providerInstance ? (
1112 <View className="flex-row items-center">
@@ -1111,6 +1149,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
1149 }
1150 accessibilityRole="button"
1151 accessibilityState={{ selected }}
1152 + accessibilityActions={rowAccessibilityActions}
1153 + onAccessibilityAction={(event) => {
1154 + if (event.nativeEvent.actionName === "openPullRequests") handleOpenPullRequests();
1155 + }}
1156 onPress={() => {
1157 close();
1158 onSelectThread(thread);
apps/mobile/src/features/threads/thread-work-log.tsx
+3 -2
@@ -106,6 +106,7 @@ import Animated, {
106 withTiming,
107 } from "react-native-reanimated";
108 import { useAssetUrl } from "../../state/assets";
109 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
110
111 const SHIMMER_WIDTH = 72;
112 const SHIMMER_SWEEP_MS = 1_350;
@@ -147,7 +148,7 @@ function WorkLogIcon(props: {
148 <SymbolView
149 name={
150 props.icon === "pull-request"
150 - ? "arrow.triangle.pull"
151 + ? PullRequestGlyph.pullRequest
152 : props.icon === "browser"
153 ? { ios: "globe", android: "public" }
154 : props.icon === "device"
@@ -1634,7 +1635,7 @@ function toolGroupSummarySymbolName(kind: ToolGroupSummaryKind): AppSymbolName {
1635 case "list-prs":
1636 case "watch-pr":
1637 case "unwatch-pr":
1637 - return "arrow.triangle.pull";
1638 + return PullRequestGlyph.pullRequest;
1639 case "read":
1640 return { ios: "eye", android: "visibility" };
1641 case "edit":
apps/mobile/src/features/threads/use-open-thread-pull-requests.ts new
+34
@@ -0,0 +1,34 @@
1 +import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2 +import { useNavigation } from "@react-navigation/native";
3 +import { useCallback } from "react";
4 +
5 +import * as Dialog from "../../components/ui/Dialog";
6 +import { useNavigateToPullRequest } from "../../native/useOpenPullRequest";
7 +import {
8 + resolveThreadPrBadgeAction,
9 + type ThreadPrPresentation,
10 +} from "../../state/thread-pr-presentation";
11 +
12 +/** Called once per thread list so virtualized rows share one stable handler. */
13 +export function useOpenThreadPullRequests() {
14 + const navigation = useNavigation();
15 + const navigateToPullRequest = useNavigateToPullRequest();
16 + return useCallback(
17 + (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
18 + if (resolveThreadPrBadgeAction(pr).kind === "list") {
19 + navigation.navigate("ThreadPullRequests", {
20 + environmentId: String(thread.environmentId),
21 + threadId: String(thread.id),
22 + });
23 + return;
24 + }
25 + void navigateToPullRequest(pr.url, {
26 + environmentId: String(thread.environmentId),
27 + projectId: String(thread.projectId),
28 + }).then((opened) => {
29 + if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
30 + });
31 + },
32 + [navigation, navigateToPullRequest],
33 + );
34 +}
apps/mobile/src/features/threads/useLinkedPullRequestActions.ts new
+177
@@ -0,0 +1,177 @@
1 +import {
2 + pullRequestLinkProject,
3 + resolveLinkPullRequestInput,
4 +} from "@t3tools/client-runtime/pull-request-link-input";
5 +import type {
6 + EnvironmentProject,
7 + EnvironmentThreadShell,
8 +} from "@t3tools/client-runtime/state/shell";
9 +import {
10 + isAtomCommandInterrupted,
11 + squashAtomCommandFailure,
12 + type AtomCommandResult,
13 +} from "@t3tools/client-runtime/state/runtime";
14 +import { planThreadPullRequestMutation } from "@t3tools/client-runtime/thread-pull-request-compatibility";
15 +import { AuthOrchestrationOperateScope, type ThreadPullRequestLink } from "@t3tools/contracts";
16 +import * as Clipboard from "expo-clipboard";
17 +import { useCallback, useMemo } from "react";
18 +
19 +import * as Dialog from "../../components/ui/Dialog";
20 +import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
21 +import type { MenuProps } from "../../components/ui/Menu.types";
22 +import type { EnvironmentRuntimeState } from "../../state/remote-runtime-types";
23 +import { useEnvironmentScope } from "../../state/session";
24 +import { threadEnvironment } from "../../state/threads";
25 +import { useAtomCommand } from "../../state/use-atom-command";
26 +
27 +type MenuAction = MenuProps["actions"][number];
28 +
29 +export function useLinkedPullRequestActions(input: {
30 + readonly thread: EnvironmentThreadShell | null;
31 + readonly project: EnvironmentProject | null;
32 + readonly runtime: EnvironmentRuntimeState | null;
33 +}) {
34 + const { thread, project, runtime } = input;
35 + const capabilities = runtime?.serverConfig?.environment.capabilities;
36 + const canOperate = useEnvironmentScope(
37 + thread?.environmentId ?? null,
38 + AuthOrchestrationOperateScope,
39 + );
40 + const canEdit = canOperate && capabilities?.threadPullRequests === true;
41 + const canWatch = canOperate && capabilities?.threadPullRequestWatch === true;
42 + const canStartWatch =
43 + canWatch &&
44 + thread !== null &&
45 + thread.archivedAt === null &&
46 + thread.settledAt === null &&
47 + thread.settledOverride !== "settled" &&
48 + thread.lineage.relationshipToParent !== "subagent";
49 + const link = useAtomCommand(threadEnvironment.linkPullRequest, { reportFailure: false });
50 + const unlink = useAtomCommand(threadEnvironment.unlinkPullRequest, { reportFailure: false });
51 + const watch = useAtomCommand(threadEnvironment.watchPullRequest, { reportFailure: false });
52 +
53 + const run = useCallback(
54 + async (failureTitle: string, pending: Promise<AtomCommandResult<unknown, unknown>>) => {
55 + const result = await pending;
56 + if (result._tag === "Success" || isAtomCommandInterrupted(result)) return;
57 + const cause = squashAtomCommandFailure(result);
58 + Dialog.alert(failureTitle, cause instanceof Error ? cause.message : "Try again.");
59 + },
60 + [],
61 + );
62 +
63 + const setLinked = useCallback(
64 + (
65 + reference: { host: string; repository: string; number: number; url: string },
66 + linked: boolean,
67 + ) => {
68 + if (thread === null) return;
69 + const mutation = planThreadPullRequestMutation({
70 + capabilities,
71 + threadId: thread.id,
72 + reference,
73 + legacyProjectId: null,
74 + linked,
75 + });
76 + if (mutation === null || mutation.type === "thread.meta.update") return;
77 + const environmentId = thread.environmentId;
78 + void run(
79 + linked ? "Couldn't link this pull request" : "Couldn't unlink this pull request",
80 + mutation.type === "thread.pull-request.link"
81 + ? link({ environmentId, input: mutation.input })
82 + : unlink({ environmentId, input: mutation.input }),
83 + );
84 + },
85 + [capabilities, link, run, thread, unlink],
86 + );
87 +
88 + const promptLink = useCallback(() => {
89 + Dialog.prompt({
90 + title: "Link pull request",
91 + message: "Paste a pull request URL, or enter 123 / #123 for this thread's repository.",
92 + placeholder: "Pull request URL or #42",
93 + initialValue: "",
94 + confirmText: "Link",
95 + onConfirm: (reference) => {
96 + const resolved = resolveLinkPullRequestInput({
97 + reference,
98 + project: pullRequestLinkProject(project?.repositoryIdentity),
99 + hasProject: () => true,
100 + });
101 + if (resolved === null) {
102 + Dialog.alert("Couldn't link this pull request", "Use a pull request URL, 123, or #123.");
103 + return;
104 + }
105 + if ("error" in resolved) {
106 + Dialog.alert("Couldn't link this pull request", resolved.error);
107 + return;
108 + }
109 + setLinked(resolved.link, true);
110 + },
111 + });
112 + }, [project, setLinked]);
113 +
114 + const menuActions = useCallback(
115 + (link: ThreadPullRequestLink): MenuAction[] => {
116 + const open = link.snapshot === null || link.snapshot.state === "open";
117 + const watching = link.watch !== undefined;
118 + return [
119 + { id: "copy", title: "Copy link", image: "link" },
120 + { id: "browser", title: "Open in browser", image: "safari" },
121 + ...((watching ? canWatch : canStartWatch) && open
122 + ? [
123 + {
124 + id: "watch",
125 + title: watching ? "Stop watching" : "Watch for changes",
126 + image: watching ? "eye.slash" : "eye",
127 + },
128 + ]
129 + : []),
130 + ...(canEdit
131 + ? [
132 + {
133 + id: "unlink",
134 + title: link.source === "stack" ? "Dismiss from thread" : "Unlink from thread",
135 + image: "xmark",
136 + attributes: { destructive: true },
137 + },
138 + ]
139 + : []),
140 + ];
141 + },
142 + [canEdit, canStartWatch, canWatch],
143 + );
144 +
145 + const onMenuAction = useCallback(
146 + (link: ThreadPullRequestLink, action: string) => {
147 + if (action === "copy") void Clipboard.setStringAsync(link.url);
148 + else if (action === "browser")
149 + void tryOpenExternalUrl(link.url, "pull-request").then((opened) => {
150 + if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
151 + });
152 + else if (action === "watch" && thread !== null)
153 + void run(
154 + "Couldn't change watching",
155 + watch({
156 + environmentId: thread.environmentId,
157 + input: {
158 + threadId: thread.id,
159 + host: link.host,
160 + repository: link.repository,
161 + number: link.number,
162 + watching: link.watch === undefined,
163 + },
164 + }),
165 + );
166 + else if (action === "unlink") setLinked(link, false);
167 + },
168 + [run, setLinked, thread, watch],
169 + );
170 +
171 + return useMemo(
172 + () => ({ canLink: canEdit, promptLink, menuActions, onMenuAction }),
173 + [canEdit, promptLink, menuActions, onMenuAction],
174 + );
175 +}
176 +
177 +export type LinkedPullRequestActions = ReturnType<typeof useLinkedPullRequestActions>;
apps/mobile/src/features/workspace/WorkspaceDock.tsx
+2 -1
@@ -4,6 +4,7 @@ import { SymbolView } from "../../components/ui/AppSymbol";
4 import { GlassSurface } from "../../components/ui/GlassSurface";
5 import { useWorkspaceTabs } from "./WorkspaceTabsContext";
6 import { WORKSPACE_DOCK } from "./workspace-tabs-state";
7 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
8
9 export function WorkspaceDock(props: { readonly onNewTask: () => void }) {
10 const workspace = useWorkspaceTabs()!;
@@ -40,7 +41,7 @@ export function WorkspaceDock(props: { readonly onNewTask: () => void }) {
41 }
42 >
43 <SymbolView
43 - name={tab === "threads" ? "text.bubble" : "arrow.triangle.pull"}
44 + name={tab === "threads" ? "text.bubble" : PullRequestGlyph.pullRequest}
45 size={23}
46 tintColorClassName={selected ? "accent-focus" : "accent-icon"}
47 />
apps/mobile/src/features/workspace/WorkspaceToolbar.tsx
+2 -1
@@ -20,10 +20,11 @@ import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands
20 import { WorkspaceDock } from "./WorkspaceDock";
21 import { useWorkspaceTabs } from "./WorkspaceTabsContext";
22 import { WORKSPACE_TOOLBAR, type WorkspaceTab } from "./workspace-tabs-state";
23 +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
24
25 const TABS: ReadonlyArray<{ id: WorkspaceTab; label: string; icon: AppSymbolName }> = [
26 { id: "threads", label: "Threads", icon: "text.bubble" },
26 - { id: "pullRequests", label: "PRs", icon: "arrow.triangle.pull" },
27 + { id: "pullRequests", label: "PRs", icon: PullRequestGlyph.pullRequest },
28 ];
29
30 function ToolbarButton(props: {
apps/mobile/src/native/ThemedScreenStack.tsx new
+8
@@ -0,0 +1,8 @@
1 +import { Screen, ScreenStackHeaderConfig } from "react-native-screens";
2 +import { withUniwind } from "uniwind";
3 +
4 +export const NativeScreen = withUniwind(Screen);
5 +export const NativeHeader = withUniwind(ScreenStackHeaderConfig, {
6 + color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },
7 + titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },
8 +});
apps/mobile/src/native/useOpenPullRequest.ts
+27 -14
@@ -7,11 +7,31 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
7 import { useThreadShell } from "../state/entities";
8 import { tryOpenExternalUrl } from "../lib/openExternalUrl";
9
10 +type PullRequestContext = { readonly environmentId: string; readonly projectId: string };
11 +
12 +// Route-free so navigator layouts such as the workspace sidebar, which have no
13 +// route context for useRoute, can open pull requests for any thread.
14 +export function useNavigateToPullRequest(options?: { readonly replace?: boolean }) {
15 + const navigation = useNavigation();
16 + const replace = options?.replace;
17 + return useCallback(
18 + async (url: string, context: PullRequestContext | null) => {
19 + const params = nativePullRequestDestination(url, context);
20 + if (!params) return tryOpenExternalUrl(url, "pull-request");
21 + if (Platform.OS === "android")
22 + resetAndroidWorkspace(navigation, { name: "PullRequest", params });
23 + else if (replace) navigation.dispatch(StackActions.replace("PullRequest", params));
24 + else navigation.navigate("PullRequest", params);
25 + return true;
26 + },
27 + [navigation, replace],
28 + );
29 +}
30 +
31 export function useOpenPullRequest(options?: {
32 readonly replace?: boolean;
12 - readonly context?: { readonly environmentId: string; readonly projectId: string };
33 + readonly context?: PullRequestContext;
34 }) {
14 - const navigation = useNavigation();
35 const route = useRoute();
36 const routeContext = route.params as
37 | {
@@ -33,22 +53,15 @@ export function useOpenPullRequest(options?: {
53 );
54 const projectId =
55 options?.context?.projectId ?? first(routeContext?.projectId) ?? thread?.projectId;
36 - const replace = options?.replace;
56 + const navigateToPullRequest = useNavigateToPullRequest({ replace: options?.replace });
57 return useCallback(
38 - async (url: string) => {
39 - const params = nativePullRequestDestination(
58 + (url: string) =>
59 + navigateToPullRequest(
60 url,
61 environmentId && projectId
62 ? { environmentId: String(environmentId), projectId: String(projectId) }
63 : null,
44 - );
45 - if (!params) return tryOpenExternalUrl(url, "pull-request");
46 - if (Platform.OS === "android")
47 - resetAndroidWorkspace(navigation, { name: "PullRequest", params });
48 - else if (replace) navigation.dispatch(StackActions.replace("PullRequest", params));
49 - else navigation.navigate("PullRequest", params);
50 - return true;
51 - },
52 - [environmentId, projectId, navigation, replace],
64 + ),
65 + [environmentId, projectId, navigateToPullRequest],
66 );
67 }
apps/mobile/src/state/thread-pr-presentation.ts
+6
@@ -117,3 +117,9 @@ export function resolveThreadPrSource(
117 : (thread.linkedPullRequest ?? thread.branchPullRequest)) ?? null);
118 return { linkedPresentation, pullRequestRef };
119 }
120 +
121 +export function resolveThreadPrBadgeAction(pr: ThreadPrPresentation) {
122 + return pr.kind === "stack" || pr.others > 0
123 + ? { kind: "list" as const, accessibilityLabel: `Show ${pr.accessibilityLabel}` }
124 + : { kind: "open" as const, accessibilityLabel: `Open ${pr.accessibilityLabel}` };
125 +}
apps/mobile/src/state/use-thread-pr.test.ts
+31
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
5 import {
6 presentThreadLinkedPullRequests,
7 presentThreadPr,
8 + resolveThreadPrBadgeAction,
9 resolveThreadPrSource,
10 } from "./thread-pr-presentation";
11
@@ -156,6 +157,36 @@ describe("presentThreadLinkedPullRequests", () => {
157 });
158 });
159
160 +describe("resolveThreadPrBadgeAction", () => {
161 + it("opens a single linked or branch pull request directly", () => {
162 + expect(resolveThreadPrBadgeAction(presentThreadLinkedPullRequests([linkedPr(1)])!)).toEqual({
163 + kind: "open",
164 + accessibilityLabel: "Open #1 pull request open",
165 + });
166 + expect(resolveThreadPrBadgeAction(presentThreadPr(pullRequest, null))).toMatchObject({
167 + kind: "open",
168 + });
169 + });
170 +
171 + it("lists unrelated linked pull requests", () => {
172 + expect(
173 + resolveThreadPrBadgeAction(presentThreadLinkedPullRequests([linkedPr(1), linkedPr(2)])!),
174 + ).toEqual({
175 + kind: "list",
176 + accessibilityLabel: "Show 2 linked pull requests, overall open",
177 + });
178 + });
179 +
180 + it("lists a stack even though the badge shows its top pull request", () => {
181 + const top = linkedPr(2);
182 + const stack = presentThreadLinkedPullRequests([
183 + linkedPr(1),
184 + { ...top, snapshot: { ...top.snapshot!, baseBranch: "change-1" } },
185 + ])!;
186 + expect(resolveThreadPrBadgeAction(stack)).toMatchObject({ kind: "list" });
187 + });
188 +});
189 +
190 describe("resolveThreadPrSource compatibility", () => {
191 const legacyRef = {
192 projectId: ProjectId.make("project"),
apps/web/src/components/BranchToolbarBranchSelector.tsx
+1 -1
@@ -42,7 +42,7 @@ import { vcsEnvironment } from "../state/vcs";
42 import { cn } from "../lib/utils";
43 import { THREAD_DETAILS_PANEL_ICON_CLASS } from "./chat/threadDetailsPanelStyles";
44 import { ThreadDetailsPrRows } from "./chat/ThreadDetailsPrRows";
45 -import { parsePullRequestReference } from "../pullRequestReference";
45 +import { parsePullRequestReference } from "@t3tools/client-runtime/pull-request-link-input";
46 import { getSourceControlPresentation } from "../sourceControlPresentation";
47 import { useComposerMenuProps } from "./chat/composerEventScope";
48 import {
apps/web/src/components/PullRequestThreadDialog.tsx
+1 -1
@@ -16,7 +16,7 @@ import {
16 usePullRequestResolution,
17 } from "~/lib/sourceControlActions";
18 import { cn } from "~/lib/utils";
19 -import { parsePullRequestReference } from "~/pullRequestReference";
19 +import { parsePullRequestReference } from "@t3tools/client-runtime/pull-request-link-input";
20 import { getSourceControlPresentation } from "~/sourceControlPresentation";
21 import { useEnvironmentQuery } from "~/state/query";
22 import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
apps/web/src/components/ThreadStatusIndicators.tsx
+2 -2
@@ -21,10 +21,11 @@ import { useEnvironment, usePrimaryEnvironmentId } from "../state/environments";
21 import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
22 import { useProject } from "../state/entities";
23 import {
24 + pullRequestListLines,
25 resolveThreadCurrentPullRequestLink,
26 resolveThreadPullRequestChains,
26 - visibleThreadPullRequests,
27 type ThreadPullRequestBadge,
28 + visibleThreadPullRequests,
29 } from "@t3tools/shared/threadPullRequests";
30 import { useRender } from "@base-ui/react/use-render";
31 import {
@@ -56,7 +57,6 @@ import {
57 import type { SidebarThreadSummary } from "../types";
58 import { formatWorktreePathForDisplay } from "../worktreeCleanup";
59 import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
59 -import { pullRequestListLines } from "./pullRequest/pullRequestListLines";
60 import {
61 PULL_REQUEST_STATE_PRESENTATION,
62 PullRequestGlyph,
apps/web/src/components/chat/ThreadDetailsPrRows.tsx
+1 -1
@@ -1,6 +1,7 @@
1 import { ThreadDetailsControl } from "./ThreadDetailsControl";
2 import type { EnvironmentId, ScopedThreadRef, ThreadPullRequestLink } from "@t3tools/contracts";
3 import {
4 + pullRequestListLines,
5 resolveThreadPullRequestChains,
6 threadPullRequestKeyOf,
7 visibleThreadPullRequests,
@@ -14,7 +15,6 @@ import { useProjects } from "~/state/entities";
15 import { threadEnvironment } from "~/state/threads";
16 import { useAtomCommand } from "~/state/use-atom-command";
17
17 -import { pullRequestListLines } from "../pullRequest/pullRequestListLines";
18 import { MorphIcon } from "~/components/MorphIcon";
19 import { linkedPullRequestSnapshotStatus, prStatusIndicator } from "../ThreadStatusIndicators";
20
apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx
+9 -79
@@ -1,11 +1,12 @@
1 -import { pullRequestHostOf, type ScopedThreadRef } from "@t3tools/contracts";
2 -import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
1 +import type { ScopedThreadRef } from "@t3tools/contracts";
2 +import {
3 + pullRequestLinkProject,
4 + resolveLinkPullRequestInput,
5 +} from "@t3tools/client-runtime/pull-request-link-input";
6 import { useAtomValue } from "@effect/atom-react";
7 import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
8 import { useEffect, useRef, useState } from "react";
9
7 -import { parseChangeRequestUrl } from "~/lib/openPullRequestLink";
8 -import { parsePullRequestReference } from "~/pullRequestReference";
10 import { useProjects, useThreadShell } from "~/state/entities";
11 import { usePullRequestLinking } from "~/hooks/usePullRequestLinking";
12 import { appAtomRegistry } from "~/rpc/atomRegistry";
@@ -60,78 +61,6 @@ export function LinkPullRequestDialogHost() {
61 );
62 }
63
63 -interface ResolvedLink {
64 - readonly host: string;
65 - readonly repository: string;
66 - readonly number: number;
67 - readonly url: string;
68 -}
69 -
70 -export function resolveLinkPullRequestInput(input: {
71 - readonly reference: string;
72 - readonly project: {
73 - readonly host: string;
74 - readonly repository: string;
75 - readonly webUrl: (number: number) => string | null;
76 - } | null;
77 - readonly hasProject: (reference: ResolvedLink) => boolean;
78 -}): { link: ResolvedLink } | { error: string } | null {
79 - const parsed =
80 - parseChangeRequestUrl(input.reference.trim()) !== null
81 - ? input.reference.trim()
82 - : parsePullRequestReference(input.reference);
83 - if (parsed === null) return null;
84 - const url = parseChangeRequestUrl(parsed);
85 - if (url !== null) {
86 - if (!input.hasProject({ ...url, url: parsed })) {
87 - return { error: `No project in this environment can read ${url.host}/${url.repository}.` };
88 - }
89 - return {
90 - link: { host: url.host, repository: url.repository, number: url.number, url: parsed },
91 - };
92 - }
93 - const number = Number(parsed);
94 - if (!Number.isSafeInteger(number) || number < 1) return null;
95 - if (input.project === null) {
96 - return { error: "Paste a full URL to link a pull request from another repository." };
97 - }
98 - const webUrl = input.project.webUrl(number);
99 - const webReference = webUrl === null ? null : parseChangeRequestUrl(webUrl);
100 - if (webUrl === null || webReference === null) {
101 - return { error: "Paste a full URL; this project's host has no known pull request URL." };
102 - }
103 - return {
104 - link: { ...webReference, url: webUrl },
105 - };
106 -}
107 -
108 -function resolveOwnProject(
109 - environmentProjects: ReturnType<typeof useProjects>,
110 - projectId: LinkPullRequestDialogProps["projectId"],
111 -) {
112 - const project = environmentProjects.find((candidate) => candidate.id === projectId);
113 - const identity = project?.repositoryIdentity;
114 - if (!project || !identity) return null;
115 - const repository =
116 - identity.displayName ??
117 - (identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null);
118 - if (repository === null) return null;
119 - const definition = sourceControlClients.get(identity.provider ?? "unknown");
120 - const host = pullRequestHostOf(identity, definition.kind);
121 - return {
122 - host,
123 - repository,
124 - webUrl: (number: number) =>
125 - definition.changeRequestUrl({
126 - host,
127 - repository,
128 - number,
129 - remoteUrl: identity.locator.remoteUrl,
130 - webUrl: identity.webUrl,
131 - }),
132 - };
133 -}
134 -
64 function LinkPullRequestDialog({
65 open,
66 threadRef,
@@ -143,9 +72,10 @@ function LinkPullRequestDialog({
72 const [dirty, setDirty] = useState(false);
73 const [submitError, setSubmitError] = useState<string | null>(null);
74 const projects = useProjects();
146 - const ownProject = resolveOwnProject(
147 - projects.filter((project) => project.environmentId === threadRef.environmentId),
148 - projectId,
75 + const ownProject = pullRequestLinkProject(
76 + projects.find(
77 + (project) => project.environmentId === threadRef.environmentId && project.id === projectId,
78 + )?.repositoryIdentity,
79 );
80 const linking = usePullRequestLinking(threadRef.environmentId);
81 const [pending, setPending] = useState(false);
apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
+2 -1
@@ -4,6 +4,8 @@ import {
4 UNKNOWN_SOURCE_CONTROL_CLIENT,
5 } from "@t3tools/client-runtime/source-control-clients";
6 import {
7 + type PullRequestListLine,
8 + pullRequestListLines,
9 resolveThreadPullRequestChains,
10 visibleThreadPullRequests,
11 } from "@t3tools/shared/threadPullRequests";
@@ -36,7 +38,6 @@ import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
38 import { MiddleTruncate } from "../ui/middle-truncate";
39 import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
40 import { openLinkPullRequestDialog } from "./LinkPullRequestDialog";
39 -import { pullRequestListLines, type PullRequestListLine } from "./pullRequestListLines";
41 import {
42 PULL_REQUEST_ROW_CLASS,
43 PULL_REQUEST_ROW_NUMBER_CLASS,
apps/web/src/components/pullRequest/pullRequestListLines.ts deleted
-40
@@ -1,40 +0,0 @@
1 -import type { ThreadPullRequestLink } from "@t3tools/contracts";
2 -import type { ThreadPullRequestChain } from "@t3tools/shared/threadPullRequests";
3 -
4 -export interface PullRequestListLine {
5 - readonly link: ThreadPullRequestLink;
6 - readonly depth: number;
7 - readonly chainKey: string;
8 - readonly stack: { readonly kind: ThreadPullRequestChain["kind"]; readonly size: number } | null;
9 -}
10 -
11 -function activityAt(link: ThreadPullRequestLink): number {
12 - const ms = Date.parse(link.snapshot?.updatedAt ?? link.linkedAt);
13 - return Number.isNaN(ms) ? 0 : ms;
14 -}
15 -
16 -function chainKeyOf(chain: ThreadPullRequestChain): string {
17 - const bottom = chain.layers[0]!;
18 - return `${bottom.host}/${bottom.repository}#${bottom.number}`;
19 -}
20 -
21 -export function pullRequestListLines(
22 - chains: ReadonlyArray<ThreadPullRequestChain>,
23 -): ReadonlyArray<PullRequestListLine> {
24 - const ordered = [...chains].sort(
25 - (left, right) =>
26 - Math.max(...right.layers.map(activityAt)) - Math.max(...left.layers.map(activityAt)),
27 - );
28 - return ordered.flatMap((chain) => {
29 - const chainKey = chainKeyOf(chain);
30 - return chain.layers.map((link, index) => ({
31 - link,
32 - depth: chain.depths[index]!,
33 - chainKey,
34 - stack:
35 - index === 0 && chain.layers.length > 1
36 - ? { kind: chain.kind, size: chain.layers.length }
37 - : null,
38 - }));
39 - });
40 -}
apps/web/src/pullRequestReference.test.ts deleted
-73
@@ -1,73 +0,0 @@
1 -import { describe, expect, it } from "vite-plus/test";
2 -
3 -import { parsePullRequestReference } from "./pullRequestReference";
4 -
5 -describe("parsePullRequestReference", () => {
6 - it("accepts GitHub pull request URLs", () => {
7 - expect(parsePullRequestReference("https://github.com/pingdotgg/t3code/pull/42")).toBe(
8 - "https://github.com/pingdotgg/t3code/pull/42",
9 - );
10 - });
11 -
12 - it("accepts Azure DevOps pull request URLs", () => {
13 - expect(
14 - parsePullRequestReference("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42"),
15 - ).toBe("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42");
16 - });
17 -
18 - it("accepts GitLab merge request URLs", () => {
19 - expect(parsePullRequestReference("https://gitlab.com/group/project/-/merge_requests/42")).toBe(
20 - "https://gitlab.com/group/project/-/merge_requests/42",
21 - );
22 - });
23 -
24 - it("accepts legacy Azure DevOps pull request URLs", () => {
25 - expect(
26 - parsePullRequestReference("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42"),
27 - ).toBe("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42");
28 - });
29 -
30 - it("accepts raw numbers", () => {
31 - expect(parsePullRequestReference("42")).toBe("42");
32 - });
33 -
34 - it("accepts #number references", () => {
35 - expect(parsePullRequestReference("#42")).toBe("42");
36 - });
37 -
38 - it("accepts gh pr checkout commands with raw numbers", () => {
39 - expect(parsePullRequestReference("gh pr checkout 42")).toBe("42");
40 - });
41 -
42 - it("accepts gh pr checkout commands with #number references", () => {
43 - expect(parsePullRequestReference("gh pr checkout #42")).toBe("42");
44 - });
45 -
46 - it("accepts gh pr checkout commands with GitHub pull request URLs", () => {
47 - expect(
48 - parsePullRequestReference("gh pr checkout https://github.com/pingdotgg/t3code/pull/42"),
49 - ).toBe("https://github.com/pingdotgg/t3code/pull/42");
50 - });
51 -
52 - it("accepts glab mr checkout commands with raw numbers", () => {
53 - expect(parsePullRequestReference("glab mr checkout 42")).toBe("42");
54 - });
55 -
56 - it("accepts az repos pr checkout commands with raw numbers", () => {
57 - expect(parsePullRequestReference("az repos pr checkout --id 42")).toBe("42");
58 - });
59 -
60 - it("accepts az repos pr checkout commands with equals-style ids", () => {
61 - expect(parsePullRequestReference("az repos pr checkout --id=42")).toBe("42");
62 - });
63 -
64 - it("accepts az repos pr checkout commands with extra flags", () => {
65 - expect(parsePullRequestReference("az repos pr checkout --id 42 --remote-name origin")).toBe(
66 - "42",
67 - );
68 - });
69 -
70 - it("rejects non-pull-request input", () => {
71 - expect(parsePullRequestReference("feature/my-branch")).toBeNull();
72 - });
73 -});
apps/web/src/pullRequestReference.ts deleted
-33
@@ -1,33 +0,0 @@
1 -import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2 -
3 -const PULL_REQUEST_NUMBER_PATTERN = /^#?(\d+)$/;
4 -
5 -export function parsePullRequestReference(input: string): string | null {
6 - const trimmed = input.trim();
7 - if (trimmed.length === 0) {
8 - return null;
9 - }
10 -
11 - const normalizedInput =
12 - sourceControlClients.definitions
13 - .map((definition) => definition.checkoutCommandArgument(trimmed))
14 - .find((argument) => argument !== null) ?? trimmed;
15 - if (normalizedInput.length === 0) {
16 - return null;
17 - }
18 -
19 - if (
20 - sourceControlClients.definitions.some((definition) =>
21 - definition.isChangeRequestReference(normalizedInput),
22 - )
23 - ) {
24 - return normalizedInput;
25 - }
26 -
27 - const numberMatch = PULL_REQUEST_NUMBER_PATTERN.exec(normalizedInput);
28 - if (numberMatch?.[1]) {
29 - return numberMatch[1];
30 - }
31 -
32 - return null;
33 -}
oxlint-plugin-t3code/index.ts
+2
@@ -8,6 +8,7 @@ import noLowValueComments from "./rules/no-low-value-comments.ts";
8 import noManualMemo from "./rules/no-manual-memo.ts";
9 import noManualEffectRuntimeInTests from "./rules/no-manual-effect-runtime-in-tests.ts";
10 import noMobileUniwindThemeEscapeHatches from "./rules/no-mobile-uniwind-theme-escape-hatches.ts";
11 +import noMobilePullRequestGlyphLiterals from "./rules/no-mobile-pull-request-glyph-literals.ts";
12 import noNativeTitleTooltip from "./rules/no-native-title-tooltip.ts";
13 import noOutsetStateIndicators from "./rules/no-outset-state-indicators.ts";
14 import noRawMcpRegistration from "./rules/no-raw-mcp-registration.ts";
@@ -32,6 +33,7 @@ export default definePlugin({
33 "no-manual-effect-runtime-in-tests": noManualEffectRuntimeInTests,
34 "no-manual-memo": noManualMemo,
35 "no-mobile-uniwind-theme-escape-hatches": noMobileUniwindThemeEscapeHatches,
36 + "no-mobile-pull-request-glyph-literals": noMobilePullRequestGlyphLiterals,
37 "no-native-title-tooltip": noNativeTitleTooltip,
38 "no-outset-state-indicators": noOutsetStateIndicators,
39 "no-raw-mcp-registration": noRawMcpRegistration,
oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.test.ts new
+66
@@ -0,0 +1,66 @@
1 +import { assert, describe } from "@effect/vitest";
2 +
3 +import { createOxlintRuleHarness } from "../test/utils.ts";
4 +
5 +const rule = createOxlintRuleHarness("t3code/no-mobile-pull-request-glyph-literals", {
6 + filename: "apps/mobile/src/features/threads/PullRequestBadge.tsx",
7 +});
8 +
9 +describe("t3code/no-mobile-pull-request-glyph-literals", () => {
10 + rule.valid(
11 + "allows glyphs picked from the module",
12 + `
13 + import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
14 +
15 + const badge = <SymbolView name={merged ? PullRequestGlyph.merged : PullRequestGlyph.pullRequest} />;
16 + `,
17 + );
18 +
19 + rule.valid(
20 + "allows unrelated symbols and copy that mentions pull requests",
21 + `
22 + const branch = <SymbolView name="arrow.triangle.branch" />;
23 + const label = "Merge pull request";
24 + `,
25 + );
26 +
27 + rule.invalid(
28 + "reports a pull request glyph in a JSX attribute",
29 + `const badge = <SymbolView name="arrow.triangle.pull" />;`,
30 + (output) => {
31 + assert.match(output, /PullRequestGlyph/);
32 + },
33 + );
34 +
35 + rule.invalid(
36 + "reports state glyphs chosen inline",
37 + `const name = state === "closed" ? "git.pull-request.closed" : "git.pull-request.draft";`,
38 + );
39 +
40 + rule.invalid(
41 + "reports glyphs in platform symbol objects",
42 + `const icon = { ios: "arrow.triangle.merge", android: "merge" };`,
43 + );
44 +
45 + rule.invalid(
46 + "reports an Android-only pull request glyph",
47 + `const icon = { ios: "arrow.triangle.branch", android: "merge" };`,
48 + );
49 +
50 + rule.valid(
51 + "allows merge as an ordinary string outside an android symbol slot",
52 + `const action = { kind: "merge", label: "Merge" };`,
53 + );
54 +
55 + rule.valid(
56 + "allows merge in an android key outside a platform symbol object",
57 + `const command = { id: "pr.merge", android: "merge" };`,
58 + );
59 +
60 + rule.invalid(
61 + "reports an Android-only pull request glyph written as a template literal",
62 + 'const icon = { ios: "arrow.triangle.branch", android: `merge` };',
63 + );
64 +
65 + rule.invalid("reports glyphs in template literals", "const name = `square.3.layers.3d`;");
66 +});
oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.ts new
+65
@@ -0,0 +1,65 @@
1 +import { defineRule, type ESTree } from "@oxlint/plugins";
2 +
3 +const PULL_REQUEST_GLYPH_NAMES = new Set([
4 + "arrow.triangle.pull",
5 + "arrow.triangle.merge",
6 + "git.pull-request.closed",
7 + "git.pull-request.draft",
8 + "square.3.layers.3d",
9 +]);
10 +
11 +// Material names reach AppSymbol only through `{ ios, android }` objects, and
12 +// "merge" is too common a string to ban outside that slot.
13 +const ANDROID_PULL_REQUEST_GLYPH_NAMES = new Set(["merge"]);
14 +
15 +const MESSAGE =
16 + "Pick a glyph by meaning from PullRequestGlyph in apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts so every surface draws the same pull request the same way.";
17 +
18 +function propertyKey(node: { key: ESTree.PropertyKey }) {
19 + if (node.key.type === "Identifier") return node.key.name;
20 + if (node.key.type === "Literal") return node.key.value;
21 + return null;
22 +}
23 +
24 +function staticString(node: ESTree.Node) {
25 + if (node.type === "Literal") return typeof node.value === "string" ? node.value : null;
26 + if (node.type === "TemplateLiteral" && node.expressions.length === 0) {
27 + return node.quasis[0]?.value.cooked ?? null;
28 + }
29 + return null;
30 +}
31 +
32 +export default defineRule({
33 + meta: {
34 + type: "problem",
35 + docs: {
36 + description:
37 + "Disallow pull request symbol names as string literals in mobile code; the import restriction that guards web cannot see string names.",
38 + },
39 + },
40 + create(context) {
41 + return {
42 + Literal(node) {
43 + if (typeof node.value !== "string" || !PULL_REQUEST_GLYPH_NAMES.has(node.value)) return;
44 + context.report({ node, message: MESSAGE });
45 + },
46 + Property(node) {
47 + if (
48 + propertyKey(node) !== "android" ||
49 + node.parent.type !== "ObjectExpression" ||
50 + !node.parent.properties.some(
51 + (property) => property.type === "Property" && propertyKey(property) === "ios",
52 + )
53 + )
54 + return;
55 + const value = staticString(node.value);
56 + if (value === null || !ANDROID_PULL_REQUEST_GLYPH_NAMES.has(value)) return;
57 + context.report({ node: node.value, message: MESSAGE });
58 + },
59 + TemplateElement(node) {
60 + if (!PULL_REQUEST_GLYPH_NAMES.has(node.value.cooked ?? "")) return;
61 + context.report({ node, message: MESSAGE });
62 + },
63 + };
64 + },
65 +});
packages/client-runtime/package.json
+4
@@ -355,6 +355,10 @@
355 "types": "./src/work-log/scrollAnchor.ts",
356 "default": "./src/work-log/scrollAnchor.ts"
357 },
358 + "./pull-request-link-input": {
359 + "types": "./src/pullRequestLinkInput.ts",
360 + "default": "./src/pullRequestLinkInput.ts"
361 + },
362 "./thread-pull-request-compatibility": {
363 "types": "./src/threadPullRequestCompatibility.ts",
364 "default": "./src/threadPullRequestCompatibility.ts"
packages/client-runtime/src/pullRequestLinkInput.test.ts renamed
+72 -2
@@ -1,8 +1,8 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
3 +import { sourceControlClients } from "./sourceControlClients.ts";
4
5 -import { resolveLinkPullRequestInput } from "./LinkPullRequestDialog";
5 +import { parsePullRequestReference, resolveLinkPullRequestInput } from "./pullRequestLinkInput.ts";
6
7 const changeRequestWebUrl = (kind: string, host: string, repository: string, number: number) =>
8 sourceControlClients.get(kind).changeRequestUrl({ host, repository, number });
@@ -139,3 +139,73 @@ describe("changeRequestWebUrl", () => {
139 expect(changeRequestWebUrl("unknown", "x", "a/b", 1)).toBeNull();
140 });
141 });
142 +
143 +describe("parsePullRequestReference", () => {
144 + it("accepts GitHub pull request URLs", () => {
145 + expect(parsePullRequestReference("https://github.com/pingdotgg/t3code/pull/42")).toBe(
146 + "https://github.com/pingdotgg/t3code/pull/42",
147 + );
148 + });
149 +
150 + it("accepts Azure DevOps pull request URLs", () => {
151 + expect(
152 + parsePullRequestReference("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42"),
153 + ).toBe("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42");
154 + });
155 +
156 + it("accepts GitLab merge request URLs", () => {
157 + expect(parsePullRequestReference("https://gitlab.com/group/project/-/merge_requests/42")).toBe(
158 + "https://gitlab.com/group/project/-/merge_requests/42",
159 + );
160 + });
161 +
162 + it("accepts legacy Azure DevOps pull request URLs", () => {
163 + expect(
164 + parsePullRequestReference("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42"),
165 + ).toBe("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42");
166 + });
167 +
168 + it("accepts raw numbers", () => {
169 + expect(parsePullRequestReference("42")).toBe("42");
170 + });
171 +
172 + it("accepts #number references", () => {
173 + expect(parsePullRequestReference("#42")).toBe("42");
174 + });
175 +
176 + it("accepts gh pr checkout commands with raw numbers", () => {
177 + expect(parsePullRequestReference("gh pr checkout 42")).toBe("42");
178 + });
179 +
180 + it("accepts gh pr checkout commands with #number references", () => {
181 + expect(parsePullRequestReference("gh pr checkout #42")).toBe("42");
182 + });
183 +
184 + it("accepts gh pr checkout commands with GitHub pull request URLs", () => {
185 + expect(
186 + parsePullRequestReference("gh pr checkout https://github.com/pingdotgg/t3code/pull/42"),
187 + ).toBe("https://github.com/pingdotgg/t3code/pull/42");
188 + });
189 +
190 + it("accepts glab mr checkout commands with raw numbers", () => {
191 + expect(parsePullRequestReference("glab mr checkout 42")).toBe("42");
192 + });
193 +
194 + it("accepts az repos pr checkout commands with raw numbers", () => {
195 + expect(parsePullRequestReference("az repos pr checkout --id 42")).toBe("42");
196 + });
197 +
198 + it("accepts az repos pr checkout commands with equals-style ids", () => {
199 + expect(parsePullRequestReference("az repos pr checkout --id=42")).toBe("42");
200 + });
201 +
202 + it("accepts az repos pr checkout commands with extra flags", () => {
203 + expect(parsePullRequestReference("az repos pr checkout --id 42 --remote-name origin")).toBe(
204 + "42",
205 + );
206 + });
207 +
208 + it("rejects non-pull-request input", () => {
209 + expect(parsePullRequestReference("feature/my-branch")).toBeNull();
210 + });
211 +});
packages/client-runtime/src/pullRequestLinkInput.ts new
+104
@@ -0,0 +1,104 @@
1 +import { pullRequestHostOf, type RepositoryIdentity } from "@t3tools/contracts";
2 +import { parseChangeRequestUrl } from "@t3tools/shared/changeRequestUrl";
3 +
4 +import { sourceControlClients } from "./sourceControlClients.ts";
5 +
6 +const PULL_REQUEST_NUMBER_PATTERN = /^#?(\d+)$/;
7 +
8 +export function parsePullRequestReference(input: string): string | null {
9 + const trimmed = input.trim();
10 + if (trimmed.length === 0) {
11 + return null;
12 + }
13 +
14 + const normalizedInput =
15 + sourceControlClients.definitions
16 + .map((definition) => definition.checkoutCommandArgument(trimmed))
17 + .find((argument) => argument !== null) ?? trimmed;
18 + if (normalizedInput.length === 0) {
19 + return null;
20 + }
21 +
22 + if (
23 + sourceControlClients.definitions.some((definition) =>
24 + definition.isChangeRequestReference(normalizedInput),
25 + )
26 + ) {
27 + return normalizedInput;
28 + }
29 +
30 + const numberMatch = PULL_REQUEST_NUMBER_PATTERN.exec(normalizedInput);
31 + if (numberMatch?.[1]) {
32 + return numberMatch[1];
33 + }
34 +
35 + return null;
36 +}
37 +
38 +/** The thread project's repository, so a bare number resolves to one of its pull requests. */
39 +export function pullRequestLinkProject(identity: RepositoryIdentity | null | undefined) {
40 + if (!identity) return null;
41 + const repository =
42 + identity.displayName ??
43 + (identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null);
44 + if (repository === null) return null;
45 + const definition = sourceControlClients.get(identity.provider ?? "unknown");
46 + const host = pullRequestHostOf(identity, definition.kind);
47 + return {
48 + host,
49 + repository,
50 + webUrl: (number: number) =>
51 + definition.changeRequestUrl({
52 + host,
53 + repository,
54 + number,
55 + remoteUrl: identity.locator.remoteUrl,
56 + webUrl: identity.webUrl,
57 + }),
58 + };
59 +}
60 +
61 +interface ResolvedLink {
62 + readonly host: string;
63 + readonly repository: string;
64 + readonly number: number;
65 + readonly url: string;
66 +}
67 +
68 +export function resolveLinkPullRequestInput(input: {
69 + readonly reference: string;
70 + readonly project: {
71 + readonly host: string;
72 + readonly repository: string;
73 + readonly webUrl: (number: number) => string | null;
74 + } | null;
75 + readonly hasProject: (reference: ResolvedLink) => boolean;
76 +}): { link: ResolvedLink } | { error: string } | null {
77 + const parsed =
78 + parseChangeRequestUrl(input.reference.trim()) !== null
79 + ? input.reference.trim()
80 + : parsePullRequestReference(input.reference);
81 + if (parsed === null) return null;
82 + const url = parseChangeRequestUrl(parsed);
83 + if (url !== null) {
84 + if (!input.hasProject({ ...url, url: parsed })) {
85 + return { error: `No project in this environment can read ${url.host}/${url.repository}.` };
86 + }
87 + return {
88 + link: { host: url.host, repository: url.repository, number: url.number, url: parsed },
89 + };
90 + }
91 + const number = Number(parsed);
92 + if (!Number.isSafeInteger(number) || number < 1) return null;
93 + if (input.project === null) {
94 + return { error: "Paste a full URL to link a pull request from another repository." };
95 + }
96 + const webUrl = input.project.webUrl(number);
97 + const webReference = webUrl === null ? null : parseChangeRequestUrl(webUrl);
98 + if (webUrl === null || webReference === null) {
99 + return { error: "Paste a full URL; this project's host has no known pull request URL." };
100 + }
101 + return {
102 + link: { ...webReference, url: webUrl },
103 + };
104 +}
packages/shared/src/threadPullRequestListLines.test.ts renamed
+1 -2
@@ -1,8 +1,7 @@
1 import type { ThreadPullRequestLink } from "@t3tools/contracts";
2 -import { resolveThreadPullRequestChains } from "@t3tools/shared/threadPullRequests";
2 import { describe, expect, it } from "vite-plus/test";
3
5 -import { pullRequestListLines } from "./pullRequestListLines";
4 +import { pullRequestListLines, resolveThreadPullRequestChains } from "./threadPullRequests.ts";
5
6 function link(
7 number: number,
packages/shared/src/threadPullRequests.ts
+34
@@ -364,3 +364,37 @@ export function applyThreadPullRequestLinkUpdate(
364 ),
365 };
366 }
367 +
368 +export interface PullRequestListLine {
369 + readonly link: ThreadPullRequestLink;
370 + readonly depth: number;
371 + readonly chainKey: string;
372 + readonly stack: { readonly kind: ThreadPullRequestChain["kind"]; readonly size: number } | null;
373 +}
374 +
375 +function chainKeyOf(chain: ThreadPullRequestChain): string {
376 + const bottom = chain.layers[0]!;
377 + return `${bottom.host}/${bottom.repository}#${bottom.number}`;
378 +}
379 +
380 +export function pullRequestListLines(
381 + chains: ReadonlyArray<ThreadPullRequestChain>,
382 +): ReadonlyArray<PullRequestListLine> {
383 + const ordered = [...chains].sort(
384 + (left, right) =>
385 + Math.max(...right.layers.map(latestUpdatedAt)) -
386 + Math.max(...left.layers.map(latestUpdatedAt)),
387 + );
388 + return ordered.flatMap((chain) => {
389 + const chainKey = chainKeyOf(chain);
390 + return chain.layers.map((link, index) => ({
391 + link,
392 + depth: chain.depths[index]!,
393 + chainKey,
394 + stack:
395 + index === 0 && chain.layers.length > 1
396 + ? { kind: chain.kind, size: chain.layers.length }
397 + : null,
398 + }));
399 + });
400 +}
vite.config.ts
+9
@@ -247,6 +247,15 @@ export default defineConfig({
247 files: ["apps/mobile/src/**"],
248 rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
249 },
250 + {
251 + files: ["apps/mobile/src/**"],
252 + excludeFiles: [
253 + "apps/mobile/src/components/ui/AppSymbol.tsx",
254 + "apps/mobile/src/components/ui/AppSymbol.ios.tsx",
255 + "apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts",
256 + ],
257 + rules: { "t3code/no-mobile-pull-request-glyph-literals": "error" },
258 + },
259 {
260 // React commits state set in a raw ResizeObserver callback after the paint, so derived
261 // layout lands a frame late. observeResize flushes every observed resize in one render.