Skip to content
TypeScript

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

oliver8fbc22ca955f
diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx
index 00645ddc091..c35d9911ca4 100644
--- a/apps/mobile/src/Stack.tsx
+++ b/apps/mobile/src/Stack.tsx
@@ -67,6 +67,7 @@ import { GitBranchesSheet } from "./features/threads/git/GitBranchesSheet";
import { GitCommitSheet } from "./features/threads/git/GitCommitSheet";
import { GitConfirmSheet } from "./features/threads/git/GitConfirmSheet";
import { GitOverviewSheet } from "./features/threads/git/GitOverviewSheet";
+import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSheet";
import { ThreadAgentsSheet } from "./features/threads/ThreadAgentsSheet";
import { ThreadQueueSheet } from "./features/threads/ThreadQueueControl";
import { ThreadRouteScreen } from "./features/threads/ThreadRouteScreen";
@@ -550,6 +551,7 @@ const WORKSPACE_OVERLAY_ROUTES = new Set([
"SettingsLegal",
"SettingsSheet",
"ThreadAgents",
+ "ThreadPullRequests",
"ThreadQueue",
"ThreadReviewComment",
"ThreadDevicePreview",
@@ -871,6 +873,15 @@ const RootStackConfig = createWorkspaceStackNavigator({
sheetGrabberVisible: true,
},
}),
+ ThreadPullRequests: createNativeStackScreen({
+ screen: ThreadPullRequestsSheet,
+ linking: `${THREAD_LINKING_PREFIX}/pull-requests`,
+ options: {
+ ...FORM_SHEET_PRESENTATION_OPTIONS,
+ sheetAllowedDetents: [0.55, 0.92],
+ sheetGrabberVisible: true,
+ },
+ }),
GitCommit: createNativeStackScreen({
screen: GitCommitSheet,
linking: `${THREAD_LINKING_PREFIX}/git/commit`,
diff --git a/apps/mobile/src/components/ui/Dialog.android.tsx b/apps/mobile/src/components/ui/Dialog.android.tsx
index fc0a911c030..5cd3519c1b6 100644
--- a/apps/mobile/src/components/ui/Dialog.android.tsx
+++ b/apps/mobile/src/components/ui/Dialog.android.tsx
@@ -117,6 +117,7 @@ export function Host() {
inputInitialValue={
presented.kind === "text-input" ? presented.request.initialValue : undefined
}
+ inputPlaceholder={presented.kind === "text-input" ? presented.request.placeholder : undefined}
onInputChange={setInputValue}
onCancel={handleCancel}
onConfirm={handleConfirm}
@@ -200,29 +201,39 @@ function DialogPresentation(props: DialogPresentationProps) {
</AlertDialog.Title>
{props.inputInitialValue !== undefined ? (
<AlertDialog.Text>
- <OutlinedTextField
- autoFocus
- singleLine
- value={inputState}
- selection={inputSelection}
- onValueChange={props.onInputChange}
- textStyle={inputTypography}
- keyboardOptions={{ imeAction: "done" }}
- keyboardActions={{
- onDone: confirm,
- }}
- colors={{
- focusedTextColor: colors["--color-foreground"],
- unfocusedTextColor: colors["--color-foreground"],
- focusedIndicatorColor: colors["--color-focus"],
- unfocusedIndicatorColor: colors["--color-border"],
- cursorColor: colors["--color-focus"],
- }}
- >
- <OutlinedTextField.Label>
- <Text style={bodyTypography}>{props.request.title}</Text>
- </OutlinedTextField.Label>
- </OutlinedTextField>
+ <Column verticalArrangement={{ spacedBy: 16 }}>
+ {props.request.message ? (
+ <Text style={bodyTypography}>{props.request.message}</Text>
+ ) : null}
+ <OutlinedTextField
+ autoFocus
+ singleLine
+ value={inputState}
+ selection={inputSelection}
+ onValueChange={props.onInputChange}
+ textStyle={inputTypography}
+ keyboardOptions={{ imeAction: "done" }}
+ keyboardActions={{
+ onDone: confirm,
+ }}
+ colors={{
+ focusedTextColor: colors["--color-foreground"],
+ unfocusedTextColor: colors["--color-foreground"],
+ focusedIndicatorColor: colors["--color-focus"],
+ unfocusedIndicatorColor: colors["--color-border"],
+ cursorColor: colors["--color-focus"],
+ }}
+ >
+ <OutlinedTextField.Label>
+ <Text style={bodyTypography}>{props.request.title}</Text>
+ </OutlinedTextField.Label>
+ {props.inputPlaceholder ? (
+ <OutlinedTextField.Placeholder>
+ <Text style={bodyTypography}>{props.inputPlaceholder}</Text>
+ </OutlinedTextField.Placeholder>
+ ) : null}
+ </OutlinedTextField>
+ </Column>
</AlertDialog.Text>
) : props.request.message ? (
<AlertDialog.Text>
@@ -253,6 +264,7 @@ interface DialogPresentationProps {
"title" | "message" | "cancelText" | "confirmText" | "destructive"
>;
readonly inputInitialValue?: string;
+ readonly inputPlaceholder?: string;
readonly onInputChange?: (value: string) => void;
readonly onCancel: () => void;
readonly onConfirm: (inputValue?: string) => void;
diff --git a/apps/mobile/src/components/ui/Dialog.tsx b/apps/mobile/src/components/ui/Dialog.tsx
index 8096f0836c7..dbbc1096e1e 100644
--- a/apps/mobile/src/components/ui/Dialog.tsx
+++ b/apps/mobile/src/components/ui/Dialog.tsx
@@ -22,7 +22,7 @@ export function confirm(request: ConfirmDialogRequest): void {
export function prompt(request: TextInputDialogRequest): void {
Alert.prompt(
request.title,
- undefined,
+ request.message,
[
{ text: request.cancelText ?? "Cancel", style: "cancel", onPress: request.onCancel },
{ text: request.confirmText, onPress: (value) => request.onConfirm(value ?? "") },
diff --git a/apps/mobile/src/components/ui/Dialog.types.ts b/apps/mobile/src/components/ui/Dialog.types.ts
index 7a32787cc32..8f1cc5cba27 100644
--- a/apps/mobile/src/components/ui/Dialog.types.ts
+++ b/apps/mobile/src/components/ui/Dialog.types.ts
@@ -10,6 +10,8 @@ export type ConfirmDialogRequest = {
export type TextInputDialogRequest = {
readonly title: string;
+ readonly message?: string;
+ readonly placeholder?: string;
readonly initialValue: string;
readonly cancelText?: string;
readonly confirmText: string;
diff --git a/apps/mobile/src/components/ui/Sheet.tsx b/apps/mobile/src/components/ui/Sheet.tsx
index a2b50a084ee..fcf5426809b 100644
--- a/apps/mobile/src/components/ui/Sheet.tsx
+++ b/apps/mobile/src/components/ui/Sheet.tsx
@@ -1,16 +1,12 @@
import { useId, useState } from "react";
import { Platform, View } from "react-native";
-import { FormSheet, Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
-import { useResolveClassNames, withUniwind } from "uniwind";
+import { FormSheet, ScreenStack } from "react-native-screens";
+import { useResolveClassNames } from "uniwind";
import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
+import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
-const NativeScreen = withUniwind(Screen);
-const NativeHeader = withUniwind(ScreenStackHeaderConfig, {
- color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },
- titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },
-});
export type { SheetProps } from "./Sheet.types";
import type { SheetProps } from "./Sheet.types";
diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx
index a6f098a05ea..12ff121e756 100644
--- a/apps/mobile/src/features/home/HomeScreen.tsx
+++ b/apps/mobile/src/features/home/HomeScreen.tsx
@@ -63,6 +63,8 @@ import {
ThreadListV2WorkingShelfHeader,
} from "../threads/thread-list-v2-items";
import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance";
+import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
+import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
import {
buildThreadListV2Items,
getThreadListV2OrderedSection,
@@ -330,6 +332,14 @@ export function HomeScreen(props: HomeScreenProps) {
const handleScrollBeginDrag = useCallback(() => {
openSwipeableRef.current?.close();
}, []);
+ const openThreadPullRequests = useOpenThreadPullRequests();
+ const handleOpenThreadPullRequests = useCallback(
+ (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
+ openSwipeableRef.current?.close();
+ openThreadPullRequests(thread, pr);
+ },
+ [openThreadPullRequests],
+ );
const onFabScroll = useFabScroll();
const listRef = useRef<LegendListRef>(null);
const searchMode = workspace?.state.tabs.threads.searchMode;
@@ -769,6 +779,7 @@ export function HomeScreen(props: HomeScreenProps) {
)}
searchQuery={props.searchQuery}
onSelectThread={props.onSelectThread}
+ onOpenThreadPullRequests={handleOpenThreadPullRequests}
onDeleteThread={handleDeleteThread}
onArchiveThread={props.onArchiveThread}
onRenameThread={handleRenameThread}
@@ -802,6 +813,7 @@ export function HomeScreen(props: HomeScreenProps) {
},
[
handleDeleteThread,
+ handleOpenThreadPullRequests,
activeReorderEnvironmentIds,
handleMoveThread,
handlePinThread,
diff --git a/apps/mobile/src/features/home/ThreadListToolbar.tsx b/apps/mobile/src/features/home/ThreadListToolbar.tsx
index 873b5f1b4eb..14b50e036b8 100644
--- a/apps/mobile/src/features/home/ThreadListToolbar.tsx
+++ b/apps/mobile/src/features/home/ThreadListToolbar.tsx
@@ -23,6 +23,7 @@ import { WorkspaceConnectionTitle } from "./WorkspaceConnectionTitle";
import { useWorkspaceState } from "../../state/workspace";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import { useToolbarLayout } from "../../components/ui/useToolbarLayout";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
/** One toolbar height for the compact list and expanded sidebar, including search. */
export function ThreadListToolbar(props: {
@@ -129,7 +130,7 @@ export function ThreadListToolbar(props: {
{props.sidebar && workspace ? (
<AndroidHeaderIconButton
accessibilityLabel="Show pull requests"
- icon="arrow.triangle.pull"
+ icon={PullRequestGlyph.pullRequest}
onPress={showPullRequests}
/>
) : null}
diff --git a/apps/mobile/src/features/keyboard/CommandPalette.tsx b/apps/mobile/src/features/keyboard/CommandPalette.tsx
index 771a3a4f961..d264c0765bc 100644
--- a/apps/mobile/src/features/keyboard/CommandPalette.tsx
+++ b/apps/mobile/src/features/keyboard/CommandPalette.tsx
@@ -38,6 +38,7 @@ import {
} from "./commandPaletteItems";
import { parseActiveThreadPath, type HardwareKeyboardCommand } from "./hardwareKeyboardCommands";
import { threadJumpIndex } from "./threadKeyboardShortcuts";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
const PALETTE_COMMANDS: ReadonlyArray<HardwareKeyboardCommand> = [
"commandPalette",
@@ -59,7 +60,7 @@ const ACTION_ICONS: Record<string, AppSymbolName> = {
archive: "archivebox",
files: "doc.text",
terminal: "terminal",
- review: "arrow.triangle.pull",
+ review: PullRequestGlyph.pullRequest,
copyThreadReference: "link",
};
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index 74b4afa4fcb..58110d6a586 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -64,6 +64,7 @@ import { AndroidWorkspaceSidebar } from "../workspace/AndroidWorkspaceSidebar";
import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
import { HomeListOptionsProvider } from "../home/home-list-options";
import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
+import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
import { WorkspaceInspectorPane } from "./workspace-inspector-pane";
@@ -460,6 +461,8 @@ function AdaptiveWorkspaceLayoutContent(
});
}, [navigation]);
+ const handleOpenThreadPullRequests = useOpenThreadPullRequests();
+
const handleNewThreadOnBranch = useCallback(
(thread: EnvironmentThreadShell) => {
navigation.navigate("NewTaskSheet", {
@@ -758,6 +761,7 @@ function AdaptiveWorkspaceLayoutContent(
onNewThreadInProject={handleNewThreadInProject}
onNewThreadOnBranch={handleNewThreadOnBranch}
onSelectThread={handleSelectThread}
+ onOpenThreadPullRequests={handleOpenThreadPullRequests}
onSearchQueryChange={setPrimarySidebarSearchQuery}
searchQuery={primarySidebarSearchQuery}
/>
diff --git a/apps/mobile/src/features/pull-requests/PullRequestListRow.tsx b/apps/mobile/src/features/pull-requests/PullRequestListRow.tsx
index b32da7693a0..cd461028e27 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestListRow.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestListRow.tsx
@@ -11,14 +11,23 @@ import {
THREAD_LIST_V2_SIDEBAR_ROW_STYLE,
THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE,
} from "../threads/thread-list-v2-row-appearance";
-import { PullRequestAvatar, PullRequestDiffStats } from "./PullRequestPresentation";
+import {
+ PullRequestAvatar,
+ PullRequestConflictBadge,
+ PullRequestDiffStats,
+} from "./PullRequestPresentation";
import {
pullRequestLabelColor,
pullRequestListReviewStatus,
pullRequestListRowsAreEqual,
type EnvironmentPullRequestListEntry,
} from "./pullRequestList";
-import { pullRequestStatus } from "./pullRequestStatus";
+import {
+ pullRequestChecksStatus,
+ pullRequestConflict,
+ pullRequestStatus,
+} from "./pullRequestStatus";
+import { PullRequestGlyph } from "./pullRequestGlyphs";
export const PullRequestListRow = memo(
function PullRequestListRow(props: {
@@ -47,13 +56,9 @@ export const PullRequestListRow = memo(
? "text-drawer-foreground-muted"
: "text-foreground-tertiary";
const status = pullRequestStatus(item);
+ const conflict = pullRequestConflict(item);
const review = pullRequestListReviewStatus(item);
- const checkTint =
- item.checksState === "passing"
- ? "accent-adaptive-emerald-600-400"
- : item.checksState === "failing"
- ? "accent-danger-foreground"
- : "accent-warning-foreground";
+ const checks = item.checksState ? pullRequestChecksStatus(item.checksState) : null;
return (
<View style={props.sidebar ? THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE : undefined}>
<Menu
@@ -65,7 +70,7 @@ export const PullRequestListRow = memo(
<Pressable
accessibilityRole="button"
accessibilityState={{ selected: props.selected, busy: props.busy }}
- 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`}
+ 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`}
accessibilityHint="Double tap to open. Touch and hold for quick actions."
onPress={() => props.onSelect(item)}
disabled={props.busy}
@@ -79,8 +84,19 @@ export const PullRequestListRow = memo(
props.busy && "opacity-50",
)}
>
- <View className={props.sidebar ? "pt-0.5" : "pt-2.5"}>
+ <View className={cn("self-start", props.sidebar ? "pt-0.5" : "pt-2.5")}>
<SymbolView name={status.icon} size={20} tintColorClassName={status.tint} />
+ {conflict ? (
+ <PullRequestConflictBadge
+ surfaceClassName={
+ props.selected
+ ? "text-thread-selected"
+ : props.sidebar
+ ? "text-drawer"
+ : "text-screen"
+ }
+ />
+ ) : null}
</View>
<View
className={cn(
@@ -96,7 +112,7 @@ export const PullRequestListRow = memo(
{item.stack ? (
<View className="flex-row items-center gap-1">
<SymbolView
- name="square.3.layers.3d"
+ name={PullRequestGlyph.stack}
size={12}
tintColorClassName={
props.selected
@@ -155,19 +171,9 @@ export const PullRequestListRow = memo(
</Text>
) : null}
</View>
- {item.checksState ? (
+ {checks ? (
<View className="shrink-0" accessibilityLabel={`Checks ${item.checksState}`}>
- <SymbolView
- name={
- item.checksState === "passing"
- ? "checkmark.circle"
- : item.checksState === "failing"
- ? "xmark.circle.fill"
- : "clock"
- }
- size={13}
- tintColorClassName={checkTint}
- />
+ <SymbolView name={checks.icon} size={13} tintColorClassName={checks.tint} />
</View>
) : null}
{review ? (
diff --git a/apps/mobile/src/features/pull-requests/PullRequestMergeControls.tsx b/apps/mobile/src/features/pull-requests/PullRequestMergeControls.tsx
index 2fc73c0ea87..c479ad24082 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestMergeControls.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestMergeControls.tsx
@@ -25,6 +25,7 @@ import { pullRequestStackMerge, singlePullRequestMergeAllowed } from "./pullRequ
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
import { usePullRequestPermissions } from "./usePullRequestPermissions";
import type { PullRequestStackState } from "./usePullRequestStack";
+import { PullRequestGlyph } from "./pullRequestGlyphs";
export function PullRequestMergeControls(props: {
readonly pr: PullRequestDetail;
@@ -200,7 +201,7 @@ export function PullRequestMergeControls(props: {
<AppActivityIndicator size="small" colorClassName="accent-icon-muted" />
) : (
<SymbolView
- name="arrow.triangle.merge"
+ name={PullRequestGlyph.merged}
size={16}
tintColorClassName={
canMerge ? "accent-prominent-action-foreground" : "accent-icon-muted"
diff --git a/apps/mobile/src/features/pull-requests/PullRequestOverviewLoading.tsx b/apps/mobile/src/features/pull-requests/PullRequestOverviewLoading.tsx
index 6f1ffd59590..647aa26e463 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestOverviewLoading.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestOverviewLoading.tsx
@@ -7,6 +7,7 @@ import { PullRequestStackCard } from "./PullRequestStackCard";
import type { PullRequestParams } from "./usePullRequestDiff";
import type { PullRequestStackState } from "./usePullRequestStack";
import { pullRequestListReviewStatus } from "./pullRequestList";
+import { PullRequestGlyph } from "./pullRequestGlyphs";
export function PullRequestOverviewLoading({
summary,
@@ -74,7 +75,7 @@ export function PullRequestOverviewLoading({
: "Branch"
}
icon={
- conflicting ? "exclamationmark.triangle" : clean ? "checkmark.circle" : "arrow.branch"
+ conflicting ? PullRequestGlyph.conflicting : clean ? "checkmark.circle" : "arrow.branch"
}
tint={
conflicting
diff --git a/apps/mobile/src/features/pull-requests/PullRequestPresentation.tsx b/apps/mobile/src/features/pull-requests/PullRequestPresentation.tsx
index 815aeb62ca8..4b39248a50e 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestPresentation.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestPresentation.tsx
@@ -1,7 +1,9 @@
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
import type { PullRequestActor } from "@t3tools/contracts";
+import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
import { Image } from "expo-image";
import { View } from "react-native";
+import { useResolveClassNames } from "uniwind";
import { AppText as Text } from "../../components/ui/AppText";
import { cn } from "../../lib/cn";
@@ -18,6 +20,19 @@ export function PullRequestReadStatus(props: {
) : null;
}
+export function PullRequestConflictBadge(props: { readonly surfaceClassName: string }) {
+ const { color } = useResolveClassNames("text-danger-foreground");
+ const { color: surface } = useResolveClassNames(props.surfaceClassName);
+ return (
+ <View pointerEvents="none" className="absolute -right-1 -bottom-1">
+ <IconAlertTriangle size={15} strokeWidth={2.5} color={surface} fill={surface} />
+ <View className="absolute inset-0">
+ <IconAlertTriangle size={15} strokeWidth={2.5} color={color} />
+ </View>
+ </View>
+ );
+}
+
export function PullRequestAvatar(props: {
readonly actor: PullRequestActor | null;
readonly size?: number;
diff --git a/apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx b/apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx
index 2dba8de3c4a..734be2162a6 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestStackCard.tsx
@@ -7,6 +7,7 @@ import { PullRequestCardGroup, PullRequestCardRow } from "./PullRequestControls"
import { pullRequestStatus } from "./pullRequestStatus";
import type { PullRequestParams } from "./usePullRequestDiff";
import type { PullRequestStackState } from "./usePullRequestStack";
+import { PullRequestGlyph } from "./pullRequestGlyphs";
export function PullRequestStackCard(props: {
readonly params: PullRequestParams;
@@ -26,7 +27,7 @@ export function PullRequestStackCard(props: {
<PullRequestCardGroup>
<PullRequestCardRow
title="Stack"
- icon="square.3.layers.3d"
+ icon={PullRequestGlyph.stack}
value={`${summary.position} of ${summary.size}`}
last
/>
@@ -38,7 +39,7 @@ export function PullRequestStackCard(props: {
<PullRequestCardGroup>
<PullRequestCardRow
title="Stack"
- icon="square.3.layers.3d"
+ icon={PullRequestGlyph.stack}
value={`${position} of ${stack.layers.length}`}
accessibilityLabel={`Stack, ${position} of ${stack.layers.length}${props.state.isFresh ? "" : ", showing saved stack"}`}
expanded={expanded}
diff --git a/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx b/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
index 64360946875..e086259a11f 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
@@ -12,6 +12,7 @@ import { Menu } from "../../components/ui/Menu";
import { PullRequestAvatar } from "./PullRequestPresentation";
import { PullRequestCardRow } from "./PullRequestControls";
import { PullRequestAgentRow } from "./PullRequestAgentRow";
+import { PullRequestGlyph } from "./pullRequestGlyphs";
import { composerPullRequests } from "../../state/pull-requests";
import { useEnvironmentQuery } from "../../state/query";
import { allowedUpdateMethods, PR_ACTION_ICONS, PR_ACTION_LABELS } from "./pullRequestActions";
@@ -189,7 +190,9 @@ export function PullRequestBranchRow(props: RowProps) {
? `No conflicts with ${props.pr.baseBranch}`
: "Branch"
}
- icon={conflicting ? "exclamationmark.triangle" : clean ? "checkmark.circle" : "arrow.branch"}
+ icon={
+ conflicting ? PullRequestGlyph.conflicting : clean ? "checkmark.circle" : "arrow.branch"
+ }
tint={
conflicting
? "accent-danger-foreground"
diff --git a/apps/mobile/src/features/pull-requests/pullRequestActions.ts b/apps/mobile/src/features/pull-requests/pullRequestActions.ts
index c402d4d2cb3..f3133d409b4 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestActions.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestActions.ts
@@ -6,6 +6,7 @@ import type {
SourceControlProviderKind,
} from "@t3tools/contracts";
import type { AppSymbolName } from "../../components/ui/AppSymbol";
+import { PullRequestGlyph } from "./pullRequestGlyphs";
type ActionDetail = Pick<
PullRequestDetail,
@@ -46,7 +47,7 @@ export const PR_ACTION_LABELS = {
} as const satisfies Record<PullRequestAction, string>;
export const PR_ACTION_ICONS = {
- merge: "arrow.triangle.merge",
+ merge: PullRequestGlyph.merged,
ready: "checkmark.circle",
draft: "pencil",
close: "xmark",
diff --git a/apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts b/apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts
new file mode 100644
index 00000000000..fa79d882cc2
--- /dev/null
+++ b/apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts
@@ -0,0 +1,10 @@
+import type { AppSymbolName } from "../../components/ui/AppSymbol";
+
+export const PullRequestGlyph = {
+ pullRequest: "arrow.triangle.pull",
+ draft: "git.pull-request.draft",
+ closed: "git.pull-request.closed",
+ merged: "arrow.triangle.merge",
+ stack: "square.3.layers.3d",
+ conflicting: "exclamationmark.triangle",
+} as const satisfies Record<string, AppSymbolName>;
diff --git a/apps/mobile/src/features/pull-requests/pullRequestList.test.ts b/apps/mobile/src/features/pull-requests/pullRequestList.test.ts
index f5d6755190b..af0d64c0826 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestList.test.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestList.test.ts
@@ -88,6 +88,8 @@ describe("recycled PR list rows", () => {
{ viewerReviewRequested: true },
{ isDraft: true },
{ state: "closed" as const },
+ { mergeability: "conflicting" as const },
+ { baseBranch: "release" },
{ author: { login: "another", name: null, avatarUrl: null } },
{ author: { login: "octocat", name: null, avatarUrl: "https://example.com/avatar.png" } },
{ labels: [{ name: "bug", color: "ff0000" }] },
diff --git a/apps/mobile/src/features/pull-requests/pullRequestList.ts b/apps/mobile/src/features/pull-requests/pullRequestList.ts
index 7577c81fa5b..976d62e1068 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestList.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestList.ts
@@ -60,6 +60,8 @@ export function pullRequestListRowsAreEqual(
previous.url === next.url &&
previous.state === next.state &&
previous.isDraft === next.isDraft &&
+ previous.mergeability === next.mergeability &&
+ previous.baseBranch === next.baseBranch &&
previous.updatedAt === next.updatedAt &&
previous.additions === next.additions &&
previous.deletions === next.deletions &&
diff --git a/apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts b/apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts
index 3699ff2ba27..55e3563ec52 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts
@@ -1,6 +1,10 @@
import type { PullRequestActivity, PullRequestCheck, PullRequestComment } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
-import { pullRequestChecksSummary, pullRequestReviewSummary } from "./pullRequestStatus";
+import {
+ pullRequestChecksSummary,
+ pullRequestConflict,
+ pullRequestReviewSummary,
+} from "./pullRequestStatus";
const author = { login: "julius", name: null, avatarUrl: null };
function review(state: string, at: string): PullRequestComment {
@@ -107,3 +111,30 @@ describe("mobile overview check status", () => {
).toMatchObject({ title: "1 check failing", count: "1 of 3" });
});
});
+
+describe("mobile pull request conflict", () => {
+ it("names the base branch of an open pull request with conflicts", () => {
+ expect(
+ pullRequestConflict({
+ state: "open",
+ isDraft: false,
+ mergeability: "conflicting",
+ baseBranch: "main",
+ })?.label,
+ ).toBe("Conflicts with main");
+ expect(
+ pullRequestConflict({ state: "open", isDraft: false, mergeability: "conflicting" })?.label,
+ ).toBe("Has conflicts");
+ });
+
+ it.each([
+ { state: "open" as const, isDraft: true, mergeability: "conflicting" as const },
+ { state: "merged" as const, isDraft: false, mergeability: "conflicting" as const },
+ { state: "closed" as const, isDraft: false, mergeability: "conflicting" as const },
+ { state: "open" as const, isDraft: false, mergeability: "mergeable" as const },
+ { state: "open" as const, isDraft: false, mergeability: "unknown" as const },
+ { state: "open" as const, isDraft: false },
+ ])("stays quiet when it cannot conflict or has not been reported: %j", (pr) => {
+ expect(pullRequestConflict(pr)).toBeNull();
+ });
+});
diff --git a/apps/mobile/src/features/pull-requests/pullRequestStatus.ts b/apps/mobile/src/features/pull-requests/pullRequestStatus.ts
index 51c98a065f7..7e4021adfe2 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestStatus.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestStatus.ts
@@ -1,36 +1,39 @@
import type {
PullRequestActivity,
PullRequestCheck,
+ PullRequestChecksState,
PullRequestDetail,
PullRequestListEntry,
+ PullRequestMergeability,
} from "@t3tools/contracts";
import type { AppSymbolName } from "../../components/ui/AppSymbol";
+import { PullRequestGlyph } from "./pullRequestGlyphs";
const STATES = {
open: {
label: "Open",
- icon: "arrow.triangle.pull",
+ icon: PullRequestGlyph.pullRequest,
tint: "accent-adaptive-emerald-600-400",
text: "text-adaptive-emerald-600-400",
background: "bg-adaptive-emerald-500-a12-a16",
},
merged: {
label: "Merged",
- icon: "arrow.triangle.merge",
+ icon: PullRequestGlyph.merged,
tint: "accent-adaptive-violet-600-400",
text: "text-adaptive-violet-600-400",
background: "bg-adaptive-violet-500-a12-a16",
},
closed: {
label: "Closed",
- icon: "git.pull-request.closed",
+ icon: PullRequestGlyph.closed,
tint: "accent-danger-foreground",
text: "text-danger-foreground",
background: "bg-danger",
},
draft: {
label: "Draft",
- icon: "git.pull-request.draft",
+ icon: PullRequestGlyph.draft,
tint: "accent-icon-muted",
text: "text-foreground-muted",
background: "bg-grouped-card",
@@ -44,6 +47,16 @@ export function pullRequestStatus(pr: Pick<PullRequestListEntry, "state" | "isDr
return STATES[pr.isDraft && pr.state === "open" ? "draft" : pr.state];
}
+export function pullRequestConflict(pr: {
+ readonly state: PullRequestListEntry["state"];
+ readonly isDraft: boolean;
+ readonly mergeability?: PullRequestMergeability | undefined;
+ readonly baseBranch?: string | undefined;
+}) {
+ if (pr.state !== "open" || pr.isDraft || pr.mergeability !== "conflicting") return null;
+ return { label: pr.baseBranch ? `Conflicts with ${pr.baseBranch}` : "Has conflicts" };
+}
+
export function checkStatus(check: PullRequestCheck) {
switch (check.status) {
case "success":
@@ -200,3 +213,11 @@ export function pullRequestBranchSummary(
if (pr.baseComparison === "up-to-date") return "Up to date";
return pr.mergeability === "mergeable" ? "No conflicts" : "Not reported";
}
+
+export function pullRequestChecksStatus(state: PullRequestChecksState) {
+ if (state === "passing")
+ return { icon: "checkmark.circle", tint: "accent-adaptive-emerald-600-400" } as const;
+ if (state === "failing")
+ return { icon: "xmark.circle.fill", tint: "accent-danger-foreground" } as const;
+ return { icon: "clock", tint: "accent-warning-foreground" } as const;
+}
diff --git a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx
index ce73a95195b..b444f70054d 100644
--- a/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx
+++ b/apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx
@@ -39,6 +39,7 @@ import {
uniformMobileSetting,
type ScopedMobileSettingsTarget,
} from "./settings-scoped-server";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
type SettingsPage = "new-threads" | "source-control" | "agent-behavior" | "maintenance";
@@ -359,7 +360,7 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
/>
<SettingsSection title="Pull requests">
<SettingsSwitchRow
- icon="arrow.triangle.merge"
+ icon={PullRequestGlyph.merged}
label="Remove agent credits when merging"
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."
value={uniform("removeAgentCreditsOnMerge")}
diff --git a/apps/mobile/src/features/threads/ComposerCommandPopover.tsx b/apps/mobile/src/features/threads/ComposerCommandPopover.tsx
index 387123a100c..cd924e4c61f 100644
--- a/apps/mobile/src/features/threads/ComposerCommandPopover.tsx
+++ b/apps/mobile/src/features/threads/ComposerCommandPopover.tsx
@@ -16,6 +16,7 @@ import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
import { AppText as Text } from "../../components/ui/AppText";
import { GlassSurface } from "../../components/ui/GlassSurface";
import { PierreEntryIcon } from "../../components/PierreEntryIcon";
+import { pullRequestStatus } from "../pull-requests/pullRequestStatus";
export type ComposerCommandItem =
| {
readonly id: string;
@@ -99,7 +100,7 @@ const SKILL_SOURCE_SYMBOL_BY_KIND: Record<ProviderSkillSourceKind, AppSymbolName
function itemIcon(item: ComposerCommandItem): AppSymbolName | null {
switch (item.type) {
case "pull-request":
- return { ios: "arrow.triangle.pull", android: "merge" };
+ return pullRequestStatus(item.pullRequest).icon;
case "slash-command":
case "provider-slash-command":
return "terminal";
@@ -166,7 +167,11 @@ const CommandRow = memo(function CommandRow(props: {
<SymbolView
name={iconName}
size={14}
- tintColorClassName={"accent-icon-subtle"}
+ tintColorClassName={
+ props.item.type === "pull-request"
+ ? pullRequestStatus(props.item.pullRequest).tint
+ : "accent-icon-subtle"
+ }
type="monochrome"
/>
) : null}
diff --git a/apps/mobile/src/features/threads/LinkedPullRequestList.tsx b/apps/mobile/src/features/threads/LinkedPullRequestList.tsx
new file mode 100644
index 00000000000..903e7fd574b
--- /dev/null
+++ b/apps/mobile/src/features/threads/LinkedPullRequestList.tsx
@@ -0,0 +1,174 @@
+import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
+import {
+ pullRequestListLines,
+ resolveThreadPullRequestChains,
+ threadPullRequestKeyOf,
+ type PullRequestListLine,
+} from "@t3tools/shared/threadPullRequests";
+import { memo, useMemo } from "react";
+import { Pressable, useWindowDimensions, View } from "react-native";
+
+import { SymbolView } from "../../components/ui/AppSymbol";
+import { AppText as Text } from "../../components/ui/AppText";
+import * as Dialog from "../../components/ui/Dialog";
+import { Menu } from "../../components/ui/Menu";
+import { cn } from "../../lib/cn";
+import { relativeTime } from "../../lib/time";
+import type { EnvironmentRuntimeState } from "../../state/remote-runtime-types";
+import { useScaledTextRole } from "../settings/appearance/useScaledTextRole";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
+import type { LinkedPullRequestActions } from "./useLinkedPullRequestActions";
+import { pullRequestListReviewStatus } from "../pull-requests/pullRequestList";
+import {
+ PullRequestAvatar,
+ PullRequestConflictBadge,
+ PullRequestDiffStats,
+} from "../pull-requests/PullRequestPresentation";
+import {
+ pullRequestChecksStatus,
+ pullRequestConflict,
+ pullRequestStatus,
+} from "../pull-requests/pullRequestStatus";
+
+export function useLinkedPullRequestLines(
+ thread: EnvironmentThreadShell | null,
+ runtime: EnvironmentRuntimeState | null,
+) {
+ const supported = runtime?.serverConfig?.environment.capabilities.threadPullRequests === true;
+ const pullRequests = thread?.pullRequests;
+ return useMemo(() => {
+ const chains = resolveThreadPullRequestChains(supported ? (pullRequests ?? []) : []);
+ const open = chains.filter((chain) => chain.layers.some(isOpenLink));
+ const done = chains.filter((chain) => !chain.layers.some(isOpenLink));
+ return [...pullRequestListLines(open), ...pullRequestListLines(done)];
+ }, [pullRequests, supported]);
+}
+
+function isOpenLink(link: PullRequestListLine["link"]) {
+ return link.snapshot === null || link.snapshot.state === "open";
+}
+
+export function linkedPullRequestKey(line: PullRequestListLine) {
+ return threadPullRequestKeyOf(line.link);
+}
+
+export const LinkedPullRequestRow = memo(function LinkedPullRequestRow(props: {
+ readonly line: PullRequestListLine;
+ readonly separator: boolean;
+ readonly surfaceClassName: string;
+ readonly openPullRequest: (url: string) => Promise<boolean>;
+ readonly actions: LinkedPullRequestActions | null;
+}) {
+ const { link, depth, stack } = props.line;
+ const snapshot = link.snapshot;
+ const status = snapshot === null ? null : pullRequestStatus(snapshot);
+ const conflict = snapshot === null ? null : pullRequestConflict(snapshot);
+ const open = snapshot === null || snapshot.state === "open";
+ const checks =
+ open && snapshot?.checksState ? pullRequestChecksStatus(snapshot.checksState) : null;
+ const review =
+ open && snapshot?.reviewDecision
+ ? pullRequestListReviewStatus({
+ reviewDecision: snapshot.reviewDecision,
+ viewerReviewRequested: false,
+ })
+ : null;
+ const watching = open && link.watch !== undefined;
+ const additions = snapshot?.additions ?? 0;
+ const deletions = snapshot?.deletions ?? 0;
+ const metaLineHeight = useScaledTextRole("label").lineHeight * useWindowDimensions().fontScale;
+ const row = (
+ <Pressable
+ accessibilityRole="button"
+ 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}` : ""}`}
+ accessibilityHint={props.actions ? "Touch and hold for actions." : undefined}
+ onPress={() => {
+ void props.openPullRequest(link.url).then((opened) => {
+ if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
+ });
+ }}
+ // Steps in per layer like the web list, capped so deep stacks keep their width.
+ style={{ paddingLeft: 16 + Math.min(depth, 3) * 16 }}
+ className="flex-row gap-3 rounded-xl pr-4 active:bg-row-hover"
+ >
+ {depth > 0 ? <View className="-ml-2 w-px self-stretch bg-border" /> : null}
+ <View className="self-start pt-2.5">
+ <SymbolView
+ name={status?.icon ?? PullRequestGlyph.pullRequest}
+ size={20}
+ tintColorClassName={status?.tint ?? "accent-icon-muted"}
+ />
+ {conflict ? <PullRequestConflictBadge surfaceClassName={props.surfaceClassName} /> : null}
+ </View>
+ <View
+ className={cn(
+ "min-w-0 flex-1 gap-1 py-2.5",
+ props.separator && "border-b border-border-subtle",
+ )}
+ >
+ <View className="flex-row items-center gap-1.5">
+ {snapshot?.author ? <PullRequestAvatar actor={snapshot.author} size={16} /> : null}
+ <Text className="min-w-0 shrink text-xs text-foreground-muted" numberOfLines={1}>
+ {link.repository}
+ </Text>
+ <Text className="shrink-0 text-xs text-foreground-tertiary">#{link.number}</Text>
+ <View className="flex-1" />
+ {stack ? (
+ <View className="flex-row items-center gap-1">
+ <SymbolView
+ name={PullRequestGlyph.stack}
+ size={12}
+ tintColorClassName="accent-foreground-muted"
+ />
+ <Text className="text-2xs tabular-nums text-foreground-muted">{stack.size}</Text>
+ </View>
+ ) : null}
+ {watching ? (
+ <SymbolView name="eye" size={13} tintColorClassName="accent-foreground-muted" />
+ ) : null}
+ {checks ? (
+ <SymbolView name={checks.icon} size={13} tintColorClassName={checks.tint} />
+ ) : null}
+ {review ? (
+ <SymbolView name={review.icon} size={13} tintColorClassName={review.tint} />
+ ) : null}
+ {additions + deletions > 0 || snapshot?.updatedAt ? (
+ <View
+ className="-ml-1.5 flex-row flex-wrap items-center gap-x-1.5 overflow-hidden"
+ style={{ height: metaLineHeight, flexShrink: 100 }}
+ >
+ <View className="w-0" />
+ {additions + deletions > 0 ? (
+ <PullRequestDiffStats additions={additions} deletions={deletions} compact />
+ ) : null}
+ {snapshot?.updatedAt ? (
+ <Text className="text-2xs tabular-nums text-foreground-tertiary">
+ {relativeTime(snapshot.updatedAt)}
+ </Text>
+ ) : null}
+ </View>
+ ) : null}
+ </View>
+ <Text
+ className="text-base leading-5 font-t3-medium text-foreground"
+ numberOfLines={2}
+ ellipsizeMode="tail"
+ >
+ {snapshot?.title ?? "Waiting for host state"}
+ </Text>
+ </View>
+ </Pressable>
+ );
+ const actions = props.actions;
+ if (actions === null) return row;
+ return (
+ <Menu
+ shouldOpenOnLongPress
+ title={`#${link.number} · ${link.repository}`}
+ actions={actions.menuActions(link)}
+ onPressAction={({ nativeEvent }) => actions.onMenuAction(link, nativeEvent.event)}
+ >
+ {row}
+ </Menu>
+ );
+});
diff --git a/apps/mobile/src/features/threads/ThreadGitControls.tsx b/apps/mobile/src/features/threads/ThreadGitControls.tsx
index ac0fd16b1be..e0c83f6a4d1 100644
--- a/apps/mobile/src/features/threads/ThreadGitControls.tsx
+++ b/apps/mobile/src/features/threads/ThreadGitControls.tsx
@@ -20,6 +20,7 @@ import { useNavigation } from "@react-navigation/native";
import { useCallback, useMemo } from "react";
import { useEnvironmentScope } from "../../state/session";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
import {
basename,
getTerminalStatusLabel,
@@ -385,7 +386,7 @@ function useThreadGitHeaderActionItems(props: ThreadGitControlsProps): ThreadGit
? [
{
description: "Bring this thread's latest turn into its source",
- icon: { name: "arrow.triangle.merge", type: "sfSymbol" as const },
+ icon: { name: PullRequestGlyph.merged, type: "sfSymbol" as const },
label: "Merge back to source",
onPress: props.onMergeBack,
type: "action" as const,
diff --git a/apps/mobile/src/features/threads/ThreadHeader.tsx b/apps/mobile/src/features/threads/ThreadHeader.tsx
index c2888b92ab8..30e6f6c1b20 100644
--- a/apps/mobile/src/features/threads/ThreadHeader.tsx
+++ b/apps/mobile/src/features/threads/ThreadHeader.tsx
@@ -6,6 +6,7 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import type { ThreadInspectorMode } from "./thread-inspector-content-stack";
import { useThreadHeaderOptions } from "./useThreadHeaderOptions";
import { useWorkspaceListNavigation } from "../workspace/useAndroidWorkspaceNavigation";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
export function ThreadHeader(
props: Parameters<typeof useThreadHeaderOptions>[0] & {
@@ -55,7 +56,7 @@ export function ThreadHeader(
if (onMergeBack) {
actions.push({
accessibilityLabel: "Merge back to source",
- icon: "arrow.triangle.merge",
+ icon: PullRequestGlyph.merged,
onPress: onMergeBack,
});
}
diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
index 66be152db07..d62701444b2 100644
--- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
@@ -65,6 +65,7 @@ import {
ThreadListV2WorkingShelfHeader,
} from "./thread-list-v2-items";
import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
+import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
import {
buildThreadListV2Items,
getThreadListV2OrderedSection,
@@ -93,6 +94,10 @@ interface ThreadNavigationSidebarProps {
readonly onNewThreadInProject: (project: EnvironmentProject) => void;
readonly onSearchQueryChange: (query: string) => void;
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
+ readonly onOpenThreadPullRequests: (
+ thread: EnvironmentThreadShell,
+ pr: ThreadPrPresentation,
+ ) => void;
readonly onRequestVisibility: () => void;
readonly searchQuery: string;
}
@@ -557,6 +562,13 @@ function ThreadNavigationSidebarPane(
},
[props.onSelectThread],
);
+ const handleOpenThreadPullRequests = useCallback(
+ (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
+ props.onOpenThreadPullRequests(thread, pr);
+ openSwipeableRef.current?.close();
+ },
+ [props.onOpenThreadPullRequests],
+ );
const handleScrollBeginDrag = useCallback(() => {
openSwipeableRef.current?.close();
}, []);
@@ -684,6 +696,7 @@ function ThreadNavigationSidebarPane(
}
fullSwipeWidth={props.width - 20}
onSelectThread={handleSelectThread}
+ onOpenThreadPullRequests={handleOpenThreadPullRequests}
onDeleteThread={confirmDeleteThread}
onArchiveThread={archiveThread}
onRenameThread={renameThread}
@@ -759,6 +772,7 @@ function ThreadNavigationSidebarPane(
activeReorderEnvironmentIds,
confirmDeletePendingTask,
confirmDeleteThread,
+ handleOpenThreadPullRequests,
handleSelectThread,
handleSwipeableClose,
handleSwipeableWillOpen,
diff --git a/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx b/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx
new file mode 100644
index 00000000000..c9075f851ee
--- /dev/null
+++ b/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx
@@ -0,0 +1,162 @@
+import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
+import { LegendList } from "@legendapp/list/react-native";
+import { useMemo } from "react";
+import { Platform, View } from "react-native";
+import { ScreenStack } from "react-native-screens";
+import { useSafeAreaInsets } from "react-native-safe-area-context";
+
+import { AndroidSheetHeader } from "../../components/ui/AndroidScreenHeader";
+import { AppText as Text } from "../../components/ui/AppText";
+import { ScreenContent } from "../../components/ui/ScreenContent";
+import { NativeSheetContent } from "../../native/NativeSheetContent";
+import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
+import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
+import { useOpenPullRequest } from "../../native/useOpenPullRequest";
+import { useThreadSelection } from "../../state/use-thread-selection";
+import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
+import {
+ LinkedPullRequestRow,
+ linkedPullRequestKey,
+ useLinkedPullRequestLines,
+} from "./LinkedPullRequestList";
+import { useLinkedPullRequestActions } from "./useLinkedPullRequestActions";
+
+const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
+const TITLE = "Linked pull requests";
+
+export function ThreadPullRequestsSheet(
+ _props: StaticScreenProps<{ readonly environmentId: string; readonly threadId: string }>,
+) {
+ const { layout } = useAdaptiveWorkspaceLayout();
+ const navigation = useNavigation();
+ const insets = useSafeAreaInsets();
+ const { selectedThread, selectedThreadProject, selectedEnvironmentRuntime } =
+ useThreadSelection();
+ const lines = useLinkedPullRequestLines(selectedThread, selectedEnvironmentRuntime);
+ const openCount = useMemo(
+ () =>
+ lines.filter((line) => line.link.snapshot === null || line.link.snapshot.state === "open")
+ .length,
+ [lines],
+ );
+ const openPullRequest = useOpenPullRequest({
+ replace: true,
+ context: selectedThread ?? undefined,
+ });
+ const actions = useLinkedPullRequestActions({
+ thread: selectedThread,
+ project: selectedThreadProject,
+ runtime: selectedEnvironmentRuntime,
+ });
+ const rowInputs = useMemo(() => ({ lines, actions }), [lines, actions]);
+
+ const content = (
+ <View className="flex-1 android:bg-sheet-solid ios:bg-screen">
+ <LegendList
+ data={lines}
+ keyExtractor={linkedPullRequestKey}
+ extraData={rowInputs}
+ renderItem={({ item, index }) => (
+ <LinkedPullRequestRow
+ line={item}
+ separator={index < lines.length - 1}
+ surfaceClassName={Platform.OS === "ios" ? "text-screen" : "text-sheet-solid"}
+ openPullRequest={openPullRequest}
+ actions={actions}
+ />
+ )}
+ estimatedItemSize={88}
+ recycleItems
+ alwaysBounceVertical
+ style={{ flex: 1 }}
+ contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
+ showsVerticalScrollIndicator={false}
+ contentContainerStyle={{
+ paddingBottom: Math.max(insets.bottom, 18) + 18,
+ paddingHorizontal: 8,
+ }}
+ ListHeaderComponent={
+ lines.length > 0 ? (
+ <Text className="px-4 pt-2 pb-1 text-xs text-foreground-muted">
+ {openCount} open · {lines.length} linked
+ </Text>
+ ) : null
+ }
+ ListEmptyComponent={
+ <Text className="pt-6 text-center text-sm text-foreground-muted">
+ No linked pull requests.
+ </Text>
+ }
+ />
+ </View>
+ );
+
+ if (Platform.OS === "ios") {
+ // A plain formSheet screen never renders a stack header, so it comes from
+ // a nested native stack inside the sheet (same shape as the git sheet).
+ return (
+ <View collapsable={false} className="flex-1 bg-sheet">
+ <ScreenStack style={{ flex: 1 }}>
+ <NativeScreen
+ activityState={2}
+ enabled
+ isNativeStack
+ screenId="thread-pull-requests-sheet-native"
+ scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}
+ className="flex-1 bg-sheet"
+ >
+ <NativeSheetContent>{content}</NativeSheetContent>
+ <NativeHeader
+ backgroundColor="rgba(0,0,0,0)"
+ tintColorClassName="accent-foreground"
+ hideBackButton
+ hideShadow={false}
+ navigationItemStyle="editor"
+ title={TITLE}
+ titleColorClassName="accent-foreground"
+ titleFontSize={18}
+ titleFontWeight="800"
+ translucent
+ headerRightBarButtonItems={
+ actions.canLink
+ ? [
+ {
+ type: "button",
+ accessibilityLabel: "Link pull request",
+ icon: { name: "plus", type: "sfSymbol" },
+ identifier: "thread-pull-requests-link",
+ onPress: actions.promptLink,
+ },
+ ]
+ : undefined
+ }
+ />
+ </NativeScreen>
+ </ScreenStack>
+ </View>
+ );
+ }
+
+ return (
+ <View collapsable={false} className="flex-1 bg-header">
+ <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
+ <AndroidSheetHeader
+ title={TITLE}
+ hideBottomBorder
+ onBack={() => navigation.goBack()}
+ actions={
+ actions.canLink
+ ? [
+ {
+ accessibilityLabel: "Link pull request",
+ icon: "plus",
+ onPress: actions.promptLink,
+ },
+ ]
+ : undefined
+ }
+ />
+ <ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
+ </View>
+ );
+}
diff --git a/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx b/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
index eaf6e53d62a..17d3e0ef256 100644
--- a/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
+++ b/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
@@ -6,10 +6,6 @@ import {
getGitActionDisabledReason,
requiresDefaultBranchConfirmation,
} from "@t3tools/client-runtime/state/vcs";
-import {
- resolveThreadPullRequestChains,
- threadPullRequestKeyOf,
-} from "@t3tools/shared/threadPullRequests";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import {
CommonActions,
@@ -45,6 +41,12 @@ import { useSelectedThreadWorktree } from "../../../state/use-selected-thread-wo
import { vcsEnvironment } from "../../../state/vcs";
import { resolveGitOverviewReviewNavigationAction } from "./git-overview-navigation";
import { MetaCard, SheetListRow, menuItemIconName, statusSummary } from "./gitSheetComponents";
+import {
+ LinkedPullRequestRow,
+ linkedPullRequestKey,
+ useLinkedPullRequestLines,
+} from "../LinkedPullRequestList";
+import { useLinkedPullRequestActions } from "../useLinkedPullRequestActions";
const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
@@ -72,21 +74,22 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
const navigation = useNavigation();
const insets = useSafeAreaInsets();
const presentation = props.presentation ?? "sheet";
- const openPullRequest = useOpenPullRequest({ replace: presentation === "sheet" });
const isInspector = presentation === "inspector";
const environmentId = EnvironmentId.make(props.route.params.environmentId);
const threadId = ThreadId.make(props.route.params.threadId);
- const { selectedThread, selectedEnvironmentRuntime } = useThreadSelection();
+ const { selectedThread, selectedThreadProject, selectedEnvironmentRuntime } =
+ useThreadSelection();
+ const openPullRequest = useOpenPullRequest({
+ replace: presentation === "sheet",
+ context: selectedThread ?? undefined,
+ });
const { selectedThreadCwd, selectedThreadWorktreePath } = useSelectedThreadWorktree();
- const supportsLinkedPrSnapshots =
- selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.threadPullRequests === true;
- const linkedPrChains = useMemo(
- () =>
- resolveThreadPullRequestChains(
- supportsLinkedPrSnapshots ? (selectedThread?.pullRequests ?? []) : [],
- ),
- [selectedThread?.pullRequests, supportsLinkedPrSnapshots],
- );
+ const linkedPrLines = useLinkedPullRequestLines(selectedThread, selectedEnvironmentRuntime);
+ const linkedPrActions = useLinkedPullRequestActions({
+ thread: selectedThread,
+ project: selectedThreadProject,
+ runtime: selectedEnvironmentRuntime,
+ });
const gitState = useSelectedThreadGitState();
const gitActions = useSelectedThreadGitActions();
const { canWriteSourceControl, canChangeThreadBranch } = gitActions;
@@ -349,58 +352,36 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
})
}
/>
+ {linkedPrActions.canLink ? (
+ <>
+ {Platform.OS !== "android" ? <View className="ml-12 h-px bg-border" /> : null}
+ <SheetListRow
+ icon="link"
+ title="Link pull request"
+ subtitle="Attach a pull request by URL or number"
+ onPress={linkedPrActions.promptLink}
+ />
+ </>
+ ) : null}
</View>
- {linkedPrChains.length > 0 ? (
+ {linkedPrLines.length > 0 ? (
<View className="gap-2">
<Text className="px-1 text-xs font-t3-bold text-foreground-muted">
Linked pull requests
</Text>
- {linkedPrChains.map((chain) => (
- <View
- key={threadPullRequestKeyOf(chain.layers[0]!)}
- className="overflow-hidden bg-card android:rounded-[20px] ios:rounded-2xl ios:border ios:border-border ios:px-3 ios:py-1"
- >
- {chain.layers.length > 1 ? (
- <View className="flex-row items-center gap-2 px-1 pt-2 pb-1">
- <SymbolView
- name="square.3.layers.3d"
- size={14}
- tintColorClassName="accent-foreground-muted"
- />
- <Text className="text-xs text-foreground-muted">
- {chain.kind === "native" ? "Stack" : "Branch stack"} · {chain.layers.length} PRs
- · bottom to top
- </Text>
- </View>
- ) : null}
- {chain.layers.map((link, index) => (
- <View
- key={threadPullRequestKeyOf(link)}
- // Steps in per layer like the web list, capped so deep stacks keep their width.
- style={{ paddingLeft: Math.min(chain.depths[index]!, 3) * 16 }}
- >
- {index > 0 && Platform.OS !== "android" ? (
- <View className="ml-12 h-px bg-border" />
- ) : null}
- <SheetListRow
- icon="arrow.triangle.pull"
- title={`#${link.number} ${link.snapshot?.title ?? "Pull request"}`}
- subtitle={`${link.repository} · ${link.snapshot === null ? "Status pending" : link.snapshot.isDraft && link.snapshot.state === "open" ? "Draft" : link.snapshot.state}${link.watch === undefined ? "" : " · Watching"}`}
- onPress={() => {
- void openPullRequest(link.url).then((opened) => {
- if (!opened)
- Dialog.alert(
- "Unable to open PR",
- "The pull request could not be opened.",
- );
- });
- }}
- />
- </View>
- ))}
- </View>
- ))}
+ <View className="overflow-hidden bg-card android:rounded-[20px] ios:rounded-2xl ios:border ios:border-border">
+ {linkedPrLines.map((line, index) => (
+ <LinkedPullRequestRow
+ key={linkedPullRequestKey(line)}
+ line={line}
+ separator={index < linkedPrLines.length - 1}
+ surfaceClassName="text-card"
+ openPullRequest={openPullRequest}
+ actions={linkedPrActions}
+ />
+ ))}
+ </View>
</View>
) : null}
diff --git a/apps/mobile/src/features/threads/git/gitSheetComponents.tsx b/apps/mobile/src/features/threads/git/gitSheetComponents.tsx
index aa7046bf342..249bdcba321 100644
--- a/apps/mobile/src/features/threads/git/gitSheetComponents.tsx
+++ b/apps/mobile/src/features/threads/git/gitSheetComponents.tsx
@@ -83,6 +83,7 @@ export function MetaCard(props: { readonly label: string; readonly value: string
export function SheetListRow(props: {
readonly icon: ComponentProps<typeof SymbolView>["name"];
+ readonly iconTintClassName?: string | undefined;
readonly title: string;
readonly subtitle?: string | null;
readonly disabled?: boolean;
@@ -98,7 +99,7 @@ export function SheetListRow(props: {
<SymbolView
name={props.icon}
size={Platform.OS === "android" ? 24 : 16}
- tintColorClassName="accent-icon"
+ tintColorClassName={props.iconTintClassName ?? "accent-icon"}
type="monochrome"
/>
</View>
diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsx
index dc4e6353be1..f49e96381d7 100644
--- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx
+++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx
@@ -37,6 +37,10 @@ import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
import { useEnvironmentScope } from "../../state/session";
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
+import {
+ resolveThreadPrBadgeAction,
+ type ThreadPrPresentation,
+} from "../../state/thread-pr-presentation";
import { useThreadPr } from "../../state/use-thread-pr";
import { useSwipeRowDormant } from "../home/swipe-row-activation";
import { ThreadSwipeable } from "../home/thread-swipe-actions";
@@ -54,6 +58,8 @@ import {
import { QueuedMessageIcon } from "./queued-message-icon";
import { shouldRecedeThreadRow } from "./thread-row-emphasis";
import { ThreadSearchMatchExcerpt } from "./thread-search-match";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
+import { pullRequestStatus } from "../pull-requests/pullRequestStatus";
interface StatusLabel {
readonly label: string;
@@ -485,6 +491,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
readonly selected?: boolean;
readonly fullSwipeWidth?: number;
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
+ readonly onOpenThreadPullRequests: (
+ thread: EnvironmentThreadShell,
+ pr: ThreadPrPresentation,
+ ) => void;
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
@@ -521,6 +531,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
thread,
variant,
onSelectThread,
+ onOpenThreadPullRequests,
onDeleteThread,
onRenameThread,
onRegenerateThreadTitle,
@@ -553,6 +564,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
const providerInstance = props.providerInstance;
const pr = useThreadPr(thread);
+ const prBadgeLabel = pr ? resolveThreadPrBadgeAction(pr).accessibilityLabel : null;
+ const handleOpenPullRequests = useCallback(() => {
+ if (pr) onOpenThreadPullRequests(thread, pr);
+ }, [onOpenThreadPullRequests, pr, thread]);
+ // VoiceOver cannot focus the badge inside the accessible row, so the row
+ // exposes the same action.
+ const rowAccessibilityActions = useMemo(
+ () => (prBadgeLabel ? [{ name: "openPullRequests", label: prBadgeLabel }] : undefined),
+ [prBadgeLabel],
+ );
const theme = useUniwindTheme();
const sidebarPane = props.pane === "sidebar";
@@ -1047,9 +1068,26 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
<View className="flex-1" />
)}
{pr ? (
- <View className="flex-row items-center gap-1" accessibilityLabel={pr.accessibilityLabel}>
+ <Pressable
+ // Padding cancelled by negative margin grows the touch target into
+ // the row padding without moving the badge.
+ className="-m-2.5 flex-row items-center gap-1 p-2.5"
+ accessibilityRole="button"
+ accessibilityLabel={prBadgeLabel ?? undefined}
+ onPress={handleOpenPullRequests}
+ // Without a long-press handler a hold that opens the row's iOS
+ // context menu would also open the pull request on release.
+ onLongPress={() => undefined}
+ style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
+ >
<SymbolView
- name={pr.kind === "stack" ? "square.3.layers.3d" : "arrow.triangle.pull"}
+ name={
+ pr.kind === "stack"
+ ? PullRequestGlyph.stack
+ : pr.state === null
+ ? PullRequestGlyph.pullRequest
+ : pullRequestStatus({ state: pr.state, isDraft: pr.isDraft }).icon
+ }
size={12}
tintColorClassName={
pr.state === null || pr.isDraft
@@ -1068,7 +1106,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
>
{pr.label}
</Text>
- </View>
+ </Pressable>
) : null}
{providerInstance ? (
<View className="flex-row items-center">
@@ -1111,6 +1149,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
}
accessibilityRole="button"
accessibilityState={{ selected }}
+ accessibilityActions={rowAccessibilityActions}
+ onAccessibilityAction={(event) => {
+ if (event.nativeEvent.actionName === "openPullRequests") handleOpenPullRequests();
+ }}
onPress={() => {
close();
onSelectThread(thread);
diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsx
index 6dd5cf22bcf..d875a39335b 100644
--- a/apps/mobile/src/features/threads/thread-work-log.tsx
+++ b/apps/mobile/src/features/threads/thread-work-log.tsx
@@ -106,6 +106,7 @@ import Animated, {
withTiming,
} from "react-native-reanimated";
import { useAssetUrl } from "../../state/assets";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
const SHIMMER_WIDTH = 72;
const SHIMMER_SWEEP_MS = 1_350;
@@ -147,7 +148,7 @@ function WorkLogIcon(props: {
<SymbolView
name={
props.icon === "pull-request"
- ? "arrow.triangle.pull"
+ ? PullRequestGlyph.pullRequest
: props.icon === "browser"
? { ios: "globe", android: "public" }
: props.icon === "device"
@@ -1634,7 +1635,7 @@ function toolGroupSummarySymbolName(kind: ToolGroupSummaryKind): AppSymbolName {
case "list-prs":
case "watch-pr":
case "unwatch-pr":
- return "arrow.triangle.pull";
+ return PullRequestGlyph.pullRequest;
case "read":
return { ios: "eye", android: "visibility" };
case "edit":
diff --git a/apps/mobile/src/features/threads/use-open-thread-pull-requests.ts b/apps/mobile/src/features/threads/use-open-thread-pull-requests.ts
new file mode 100644
index 00000000000..758684b313b
--- /dev/null
+++ b/apps/mobile/src/features/threads/use-open-thread-pull-requests.ts
@@ -0,0 +1,34 @@
+import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
+import { useNavigation } from "@react-navigation/native";
+import { useCallback } from "react";
+
+import * as Dialog from "../../components/ui/Dialog";
+import { useNavigateToPullRequest } from "../../native/useOpenPullRequest";
+import {
+ resolveThreadPrBadgeAction,
+ type ThreadPrPresentation,
+} from "../../state/thread-pr-presentation";
+
+/** Called once per thread list so virtualized rows share one stable handler. */
+export function useOpenThreadPullRequests() {
+ const navigation = useNavigation();
+ const navigateToPullRequest = useNavigateToPullRequest();
+ return useCallback(
+ (thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
+ if (resolveThreadPrBadgeAction(pr).kind === "list") {
+ navigation.navigate("ThreadPullRequests", {
+ environmentId: String(thread.environmentId),
+ threadId: String(thread.id),
+ });
+ return;
+ }
+ void navigateToPullRequest(pr.url, {
+ environmentId: String(thread.environmentId),
+ projectId: String(thread.projectId),
+ }).then((opened) => {
+ if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
+ });
+ },
+ [navigation, navigateToPullRequest],
+ );
+}
diff --git a/apps/mobile/src/features/threads/useLinkedPullRequestActions.ts b/apps/mobile/src/features/threads/useLinkedPullRequestActions.ts
new file mode 100644
index 00000000000..d010c6206bf
--- /dev/null
+++ b/apps/mobile/src/features/threads/useLinkedPullRequestActions.ts
@@ -0,0 +1,177 @@
+import {
+ pullRequestLinkProject,
+ resolveLinkPullRequestInput,
+} from "@t3tools/client-runtime/pull-request-link-input";
+import type {
+ EnvironmentProject,
+ EnvironmentThreadShell,
+} from "@t3tools/client-runtime/state/shell";
+import {
+ isAtomCommandInterrupted,
+ squashAtomCommandFailure,
+ type AtomCommandResult,
+} from "@t3tools/client-runtime/state/runtime";
+import { planThreadPullRequestMutation } from "@t3tools/client-runtime/thread-pull-request-compatibility";
+import { AuthOrchestrationOperateScope, type ThreadPullRequestLink } from "@t3tools/contracts";
+import * as Clipboard from "expo-clipboard";
+import { useCallback, useMemo } from "react";
+
+import * as Dialog from "../../components/ui/Dialog";
+import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
+import type { MenuProps } from "../../components/ui/Menu.types";
+import type { EnvironmentRuntimeState } from "../../state/remote-runtime-types";
+import { useEnvironmentScope } from "../../state/session";
+import { threadEnvironment } from "../../state/threads";
+import { useAtomCommand } from "../../state/use-atom-command";
+
+type MenuAction = MenuProps["actions"][number];
+
+export function useLinkedPullRequestActions(input: {
+ readonly thread: EnvironmentThreadShell | null;
+ readonly project: EnvironmentProject | null;
+ readonly runtime: EnvironmentRuntimeState | null;
+}) {
+ const { thread, project, runtime } = input;
+ const capabilities = runtime?.serverConfig?.environment.capabilities;
+ const canOperate = useEnvironmentScope(
+ thread?.environmentId ?? null,
+ AuthOrchestrationOperateScope,
+ );
+ const canEdit = canOperate && capabilities?.threadPullRequests === true;
+ const canWatch = canOperate && capabilities?.threadPullRequestWatch === true;
+ const canStartWatch =
+ canWatch &&
+ thread !== null &&
+ thread.archivedAt === null &&
+ thread.settledAt === null &&
+ thread.settledOverride !== "settled" &&
+ thread.lineage.relationshipToParent !== "subagent";
+ const link = useAtomCommand(threadEnvironment.linkPullRequest, { reportFailure: false });
+ const unlink = useAtomCommand(threadEnvironment.unlinkPullRequest, { reportFailure: false });
+ const watch = useAtomCommand(threadEnvironment.watchPullRequest, { reportFailure: false });
+
+ const run = useCallback(
+ async (failureTitle: string, pending: Promise<AtomCommandResult<unknown, unknown>>) => {
+ const result = await pending;
+ if (result._tag === "Success" || isAtomCommandInterrupted(result)) return;
+ const cause = squashAtomCommandFailure(result);
+ Dialog.alert(failureTitle, cause instanceof Error ? cause.message : "Try again.");
+ },
+ [],
+ );
+
+ const setLinked = useCallback(
+ (
+ reference: { host: string; repository: string; number: number; url: string },
+ linked: boolean,
+ ) => {
+ if (thread === null) return;
+ const mutation = planThreadPullRequestMutation({
+ capabilities,
+ threadId: thread.id,
+ reference,
+ legacyProjectId: null,
+ linked,
+ });
+ if (mutation === null || mutation.type === "thread.meta.update") return;
+ const environmentId = thread.environmentId;
+ void run(
+ linked ? "Couldn't link this pull request" : "Couldn't unlink this pull request",
+ mutation.type === "thread.pull-request.link"
+ ? link({ environmentId, input: mutation.input })
+ : unlink({ environmentId, input: mutation.input }),
+ );
+ },
+ [capabilities, link, run, thread, unlink],
+ );
+
+ const promptLink = useCallback(() => {
+ Dialog.prompt({
+ title: "Link pull request",
+ message: "Paste a pull request URL, or enter 123 / #123 for this thread's repository.",
+ placeholder: "Pull request URL or #42",
+ initialValue: "",
+ confirmText: "Link",
+ onConfirm: (reference) => {
+ const resolved = resolveLinkPullRequestInput({
+ reference,
+ project: pullRequestLinkProject(project?.repositoryIdentity),
+ hasProject: () => true,
+ });
+ if (resolved === null) {
+ Dialog.alert("Couldn't link this pull request", "Use a pull request URL, 123, or #123.");
+ return;
+ }
+ if ("error" in resolved) {
+ Dialog.alert("Couldn't link this pull request", resolved.error);
+ return;
+ }
+ setLinked(resolved.link, true);
+ },
+ });
+ }, [project, setLinked]);
+
+ const menuActions = useCallback(
+ (link: ThreadPullRequestLink): MenuAction[] => {
+ const open = link.snapshot === null || link.snapshot.state === "open";
+ const watching = link.watch !== undefined;
+ return [
+ { id: "copy", title: "Copy link", image: "link" },
+ { id: "browser", title: "Open in browser", image: "safari" },
+ ...((watching ? canWatch : canStartWatch) && open
+ ? [
+ {
+ id: "watch",
+ title: watching ? "Stop watching" : "Watch for changes",
+ image: watching ? "eye.slash" : "eye",
+ },
+ ]
+ : []),
+ ...(canEdit
+ ? [
+ {
+ id: "unlink",
+ title: link.source === "stack" ? "Dismiss from thread" : "Unlink from thread",
+ image: "xmark",
+ attributes: { destructive: true },
+ },
+ ]
+ : []),
+ ];
+ },
+ [canEdit, canStartWatch, canWatch],
+ );
+
+ const onMenuAction = useCallback(
+ (link: ThreadPullRequestLink, action: string) => {
+ if (action === "copy") void Clipboard.setStringAsync(link.url);
+ else if (action === "browser")
+ void tryOpenExternalUrl(link.url, "pull-request").then((opened) => {
+ if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
+ });
+ else if (action === "watch" && thread !== null)
+ void run(
+ "Couldn't change watching",
+ watch({
+ environmentId: thread.environmentId,
+ input: {
+ threadId: thread.id,
+ host: link.host,
+ repository: link.repository,
+ number: link.number,
+ watching: link.watch === undefined,
+ },
+ }),
+ );
+ else if (action === "unlink") setLinked(link, false);
+ },
+ [run, setLinked, thread, watch],
+ );
+
+ return useMemo(
+ () => ({ canLink: canEdit, promptLink, menuActions, onMenuAction }),
+ [canEdit, promptLink, menuActions, onMenuAction],
+ );
+}
+
+export type LinkedPullRequestActions = ReturnType<typeof useLinkedPullRequestActions>;
diff --git a/apps/mobile/src/features/workspace/WorkspaceDock.tsx b/apps/mobile/src/features/workspace/WorkspaceDock.tsx
index 080666a9695..b4583cbb7d2 100644
--- a/apps/mobile/src/features/workspace/WorkspaceDock.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceDock.tsx
@@ -4,6 +4,7 @@ import { SymbolView } from "../../components/ui/AppSymbol";
import { GlassSurface } from "../../components/ui/GlassSurface";
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
import { WORKSPACE_DOCK } from "./workspace-tabs-state";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
export function WorkspaceDock(props: { readonly onNewTask: () => void }) {
const workspace = useWorkspaceTabs()!;
@@ -40,7 +41,7 @@ export function WorkspaceDock(props: { readonly onNewTask: () => void }) {
}
>
<SymbolView
- name={tab === "threads" ? "text.bubble" : "arrow.triangle.pull"}
+ name={tab === "threads" ? "text.bubble" : PullRequestGlyph.pullRequest}
size={23}
tintColorClassName={selected ? "accent-focus" : "accent-icon"}
/>
diff --git a/apps/mobile/src/features/workspace/WorkspaceToolbar.tsx b/apps/mobile/src/features/workspace/WorkspaceToolbar.tsx
index e69c1b0daa4..a659bdcd33d 100644
--- a/apps/mobile/src/features/workspace/WorkspaceToolbar.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceToolbar.tsx
@@ -20,10 +20,11 @@ import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands
import { WorkspaceDock } from "./WorkspaceDock";
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
import { WORKSPACE_TOOLBAR, type WorkspaceTab } from "./workspace-tabs-state";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
const TABS: ReadonlyArray<{ id: WorkspaceTab; label: string; icon: AppSymbolName }> = [
{ id: "threads", label: "Threads", icon: "text.bubble" },
- { id: "pullRequests", label: "PRs", icon: "arrow.triangle.pull" },
+ { id: "pullRequests", label: "PRs", icon: PullRequestGlyph.pullRequest },
];
function ToolbarButton(props: {
diff --git a/apps/mobile/src/native/ThemedScreenStack.tsx b/apps/mobile/src/native/ThemedScreenStack.tsx
new file mode 100644
index 00000000000..eee1ec9c94e
--- /dev/null
+++ b/apps/mobile/src/native/ThemedScreenStack.tsx
@@ -0,0 +1,8 @@
+import { Screen, ScreenStackHeaderConfig } from "react-native-screens";
+import { withUniwind } from "uniwind";
+
+export const NativeScreen = withUniwind(Screen);
+export const NativeHeader = withUniwind(ScreenStackHeaderConfig, {
+ color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },
+ titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },
+});
diff --git a/apps/mobile/src/native/useOpenPullRequest.ts b/apps/mobile/src/native/useOpenPullRequest.ts
index fdf9061747e..48d895de7a9 100644
--- a/apps/mobile/src/native/useOpenPullRequest.ts
+++ b/apps/mobile/src/native/useOpenPullRequest.ts
@@ -7,11 +7,31 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { useThreadShell } from "../state/entities";
import { tryOpenExternalUrl } from "../lib/openExternalUrl";
+type PullRequestContext = { readonly environmentId: string; readonly projectId: string };
+
+// Route-free so navigator layouts such as the workspace sidebar, which have no
+// route context for useRoute, can open pull requests for any thread.
+export function useNavigateToPullRequest(options?: { readonly replace?: boolean }) {
+ const navigation = useNavigation();
+ const replace = options?.replace;
+ return useCallback(
+ async (url: string, context: PullRequestContext | null) => {
+ const params = nativePullRequestDestination(url, context);
+ if (!params) return tryOpenExternalUrl(url, "pull-request");
+ if (Platform.OS === "android")
+ resetAndroidWorkspace(navigation, { name: "PullRequest", params });
+ else if (replace) navigation.dispatch(StackActions.replace("PullRequest", params));
+ else navigation.navigate("PullRequest", params);
+ return true;
+ },
+ [navigation, replace],
+ );
+}
+
export function useOpenPullRequest(options?: {
readonly replace?: boolean;
- readonly context?: { readonly environmentId: string; readonly projectId: string };
+ readonly context?: PullRequestContext;
}) {
- const navigation = useNavigation();
const route = useRoute();
const routeContext = route.params as
| {
@@ -33,22 +53,15 @@ export function useOpenPullRequest(options?: {
);
const projectId =
options?.context?.projectId ?? first(routeContext?.projectId) ?? thread?.projectId;
- const replace = options?.replace;
+ const navigateToPullRequest = useNavigateToPullRequest({ replace: options?.replace });
return useCallback(
- async (url: string) => {
- const params = nativePullRequestDestination(
+ (url: string) =>
+ navigateToPullRequest(
url,
environmentId && projectId
? { environmentId: String(environmentId), projectId: String(projectId) }
: null,
- );
- if (!params) return tryOpenExternalUrl(url, "pull-request");
- if (Platform.OS === "android")
- resetAndroidWorkspace(navigation, { name: "PullRequest", params });
- else if (replace) navigation.dispatch(StackActions.replace("PullRequest", params));
- else navigation.navigate("PullRequest", params);
- return true;
- },
- [environmentId, projectId, navigation, replace],
+ ),
+ [environmentId, projectId, navigateToPullRequest],
);
}
diff --git a/apps/mobile/src/state/thread-pr-presentation.ts b/apps/mobile/src/state/thread-pr-presentation.ts
index 0590ccf973f..bd6ed87e3bb 100644
--- a/apps/mobile/src/state/thread-pr-presentation.ts
+++ b/apps/mobile/src/state/thread-pr-presentation.ts
@@ -117,3 +117,9 @@ export function resolveThreadPrSource(
: (thread.linkedPullRequest ?? thread.branchPullRequest)) ?? null);
return { linkedPresentation, pullRequestRef };
}
+
+export function resolveThreadPrBadgeAction(pr: ThreadPrPresentation) {
+ return pr.kind === "stack" || pr.others > 0
+ ? { kind: "list" as const, accessibilityLabel: `Show ${pr.accessibilityLabel}` }
+ : { kind: "open" as const, accessibilityLabel: `Open ${pr.accessibilityLabel}` };
+}
diff --git a/apps/mobile/src/state/use-thread-pr.test.ts b/apps/mobile/src/state/use-thread-pr.test.ts
index a1f05736907..3f69dcba546 100644
--- a/apps/mobile/src/state/use-thread-pr.test.ts
+++ b/apps/mobile/src/state/use-thread-pr.test.ts
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
import {
presentThreadLinkedPullRequests,
presentThreadPr,
+ resolveThreadPrBadgeAction,
resolveThreadPrSource,
} from "./thread-pr-presentation";
@@ -156,6 +157,36 @@ describe("presentThreadLinkedPullRequests", () => {
});
});
+describe("resolveThreadPrBadgeAction", () => {
+ it("opens a single linked or branch pull request directly", () => {
+ expect(resolveThreadPrBadgeAction(presentThreadLinkedPullRequests([linkedPr(1)])!)).toEqual({
+ kind: "open",
+ accessibilityLabel: "Open #1 pull request open",
+ });
+ expect(resolveThreadPrBadgeAction(presentThreadPr(pullRequest, null))).toMatchObject({
+ kind: "open",
+ });
+ });
+
+ it("lists unrelated linked pull requests", () => {
+ expect(
+ resolveThreadPrBadgeAction(presentThreadLinkedPullRequests([linkedPr(1), linkedPr(2)])!),
+ ).toEqual({
+ kind: "list",
+ accessibilityLabel: "Show 2 linked pull requests, overall open",
+ });
+ });
+
+ it("lists a stack even though the badge shows its top pull request", () => {
+ const top = linkedPr(2);
+ const stack = presentThreadLinkedPullRequests([
+ linkedPr(1),
+ { ...top, snapshot: { ...top.snapshot!, baseBranch: "change-1" } },
+ ])!;
+ expect(resolveThreadPrBadgeAction(stack)).toMatchObject({ kind: "list" });
+ });
+});
+
describe("resolveThreadPrSource compatibility", () => {
const legacyRef = {
projectId: ProjectId.make("project"),
diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx
index 4bf687fb5bf..84cb807f45f 100644
--- a/apps/web/src/components/BranchToolbarBranchSelector.tsx
+++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx
@@ -42,7 +42,7 @@ import { vcsEnvironment } from "../state/vcs";
import { cn } from "../lib/utils";
import { THREAD_DETAILS_PANEL_ICON_CLASS } from "./chat/threadDetailsPanelStyles";
import { ThreadDetailsPrRows } from "./chat/ThreadDetailsPrRows";
-import { parsePullRequestReference } from "../pullRequestReference";
+import { parsePullRequestReference } from "@t3tools/client-runtime/pull-request-link-input";
import { getSourceControlPresentation } from "../sourceControlPresentation";
import { useComposerMenuProps } from "./chat/composerEventScope";
import {
diff --git a/apps/web/src/components/PullRequestThreadDialog.tsx b/apps/web/src/components/PullRequestThreadDialog.tsx
index 0d56bcd9283..4121984edc9 100644
--- a/apps/web/src/components/PullRequestThreadDialog.tsx
+++ b/apps/web/src/components/PullRequestThreadDialog.tsx
@@ -16,7 +16,7 @@ import {
usePullRequestResolution,
} from "~/lib/sourceControlActions";
import { cn } from "~/lib/utils";
-import { parsePullRequestReference } from "~/pullRequestReference";
+import { parsePullRequestReference } from "@t3tools/client-runtime/pull-request-link-input";
import { getSourceControlPresentation } from "~/sourceControlPresentation";
import { useEnvironmentQuery } from "~/state/query";
import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
diff --git a/apps/web/src/components/ThreadStatusIndicators.tsx b/apps/web/src/components/ThreadStatusIndicators.tsx
index a697382b1de..d3cc3873d2f 100644
--- a/apps/web/src/components/ThreadStatusIndicators.tsx
+++ b/apps/web/src/components/ThreadStatusIndicators.tsx
@@ -21,10 +21,11 @@ import { useEnvironment, usePrimaryEnvironmentId } from "../state/environments";
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
import { useProject } from "../state/entities";
import {
+ pullRequestListLines,
resolveThreadCurrentPullRequestLink,
resolveThreadPullRequestChains,
- visibleThreadPullRequests,
type ThreadPullRequestBadge,
+ visibleThreadPullRequests,
} from "@t3tools/shared/threadPullRequests";
import { useRender } from "@base-ui/react/use-render";
import {
@@ -56,7 +57,6 @@ import {
import type { SidebarThreadSummary } from "../types";
import { formatWorktreePathForDisplay } from "../worktreeCleanup";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
-import { pullRequestListLines } from "./pullRequest/pullRequestListLines";
import {
PULL_REQUEST_STATE_PRESENTATION,
PullRequestGlyph,
diff --git a/apps/web/src/components/chat/ThreadDetailsPrRows.tsx b/apps/web/src/components/chat/ThreadDetailsPrRows.tsx
index 26e7a518572..c653411ce65 100644
--- a/apps/web/src/components/chat/ThreadDetailsPrRows.tsx
+++ b/apps/web/src/components/chat/ThreadDetailsPrRows.tsx
@@ -1,6 +1,7 @@
import { ThreadDetailsControl } from "./ThreadDetailsControl";
import type { EnvironmentId, ScopedThreadRef, ThreadPullRequestLink } from "@t3tools/contracts";
import {
+ pullRequestListLines,
resolveThreadPullRequestChains,
threadPullRequestKeyOf,
visibleThreadPullRequests,
@@ -14,7 +15,6 @@ import { useProjects } from "~/state/entities";
import { threadEnvironment } from "~/state/threads";
import { useAtomCommand } from "~/state/use-atom-command";
-import { pullRequestListLines } from "../pullRequest/pullRequestListLines";
import { MorphIcon } from "~/components/MorphIcon";
import { linkedPullRequestSnapshotStatus, prStatusIndicator } from "../ThreadStatusIndicators";
diff --git a/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx b/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx
index 1c4896c8204..9d728854084 100644
--- a/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx
+++ b/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx
@@ -1,11 +1,12 @@
-import { pullRequestHostOf, type ScopedThreadRef } from "@t3tools/contracts";
-import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
+import type { ScopedThreadRef } from "@t3tools/contracts";
+import {
+ pullRequestLinkProject,
+ resolveLinkPullRequestInput,
+} from "@t3tools/client-runtime/pull-request-link-input";
import { useAtomValue } from "@effect/atom-react";
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
import { useEffect, useRef, useState } from "react";
-import { parseChangeRequestUrl } from "~/lib/openPullRequestLink";
-import { parsePullRequestReference } from "~/pullRequestReference";
import { useProjects, useThreadShell } from "~/state/entities";
import { usePullRequestLinking } from "~/hooks/usePullRequestLinking";
import { appAtomRegistry } from "~/rpc/atomRegistry";
@@ -60,78 +61,6 @@ export function LinkPullRequestDialogHost() {
);
}
-interface ResolvedLink {
- readonly host: string;
- readonly repository: string;
- readonly number: number;
- readonly url: string;
-}
-
-export function resolveLinkPullRequestInput(input: {
- readonly reference: string;
- readonly project: {
- readonly host: string;
- readonly repository: string;
- readonly webUrl: (number: number) => string | null;
- } | null;
- readonly hasProject: (reference: ResolvedLink) => boolean;
-}): { link: ResolvedLink } | { error: string } | null {
- const parsed =
- parseChangeRequestUrl(input.reference.trim()) !== null
- ? input.reference.trim()
- : parsePullRequestReference(input.reference);
- if (parsed === null) return null;
- const url = parseChangeRequestUrl(parsed);
- if (url !== null) {
- if (!input.hasProject({ ...url, url: parsed })) {
- return { error: `No project in this environment can read ${url.host}/${url.repository}.` };
- }
- return {
- link: { host: url.host, repository: url.repository, number: url.number, url: parsed },
- };
- }
- const number = Number(parsed);
- if (!Number.isSafeInteger(number) || number < 1) return null;
- if (input.project === null) {
- return { error: "Paste a full URL to link a pull request from another repository." };
- }
- const webUrl = input.project.webUrl(number);
- const webReference = webUrl === null ? null : parseChangeRequestUrl(webUrl);
- if (webUrl === null || webReference === null) {
- return { error: "Paste a full URL; this project's host has no known pull request URL." };
- }
- return {
- link: { ...webReference, url: webUrl },
- };
-}
-
-function resolveOwnProject(
- environmentProjects: ReturnType<typeof useProjects>,
- projectId: LinkPullRequestDialogProps["projectId"],
-) {
- const project = environmentProjects.find((candidate) => candidate.id === projectId);
- const identity = project?.repositoryIdentity;
- if (!project || !identity) return null;
- const repository =
- identity.displayName ??
- (identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null);
- if (repository === null) return null;
- const definition = sourceControlClients.get(identity.provider ?? "unknown");
- const host = pullRequestHostOf(identity, definition.kind);
- return {
- host,
- repository,
- webUrl: (number: number) =>
- definition.changeRequestUrl({
- host,
- repository,
- number,
- remoteUrl: identity.locator.remoteUrl,
- webUrl: identity.webUrl,
- }),
- };
-}
-
function LinkPullRequestDialog({
open,
threadRef,
@@ -143,9 +72,10 @@ function LinkPullRequestDialog({
const [dirty, setDirty] = useState(false);
const [submitError, setSubmitError] = useState<string | null>(null);
const projects = useProjects();
- const ownProject = resolveOwnProject(
- projects.filter((project) => project.environmentId === threadRef.environmentId),
- projectId,
+ const ownProject = pullRequestLinkProject(
+ projects.find(
+ (project) => project.environmentId === threadRef.environmentId && project.id === projectId,
+ )?.repositoryIdentity,
);
const linking = usePullRequestLinking(threadRef.environmentId);
const [pending, setPending] = useState(false);
diff --git a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
index 4abafb7fc80..8cbe0c21b50 100644
--- a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
+++ b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
@@ -4,6 +4,8 @@ import {
UNKNOWN_SOURCE_CONTROL_CLIENT,
} from "@t3tools/client-runtime/source-control-clients";
import {
+ type PullRequestListLine,
+ pullRequestListLines,
resolveThreadPullRequestChains,
visibleThreadPullRequests,
} from "@t3tools/shared/threadPullRequests";
@@ -36,7 +38,6 @@ import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
import { MiddleTruncate } from "../ui/middle-truncate";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { openLinkPullRequestDialog } from "./LinkPullRequestDialog";
-import { pullRequestListLines, type PullRequestListLine } from "./pullRequestListLines";
import {
PULL_REQUEST_ROW_CLASS,
PULL_REQUEST_ROW_NUMBER_CLASS,
diff --git a/apps/web/src/components/pullRequest/pullRequestListLines.ts b/apps/web/src/components/pullRequest/pullRequestListLines.ts
deleted file mode 100644
index 8a1f2ab80bf..00000000000
--- a/apps/web/src/components/pullRequest/pullRequestListLines.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import type { ThreadPullRequestLink } from "@t3tools/contracts";
-import type { ThreadPullRequestChain } from "@t3tools/shared/threadPullRequests";
-
-export interface PullRequestListLine {
- readonly link: ThreadPullRequestLink;
- readonly depth: number;
- readonly chainKey: string;
- readonly stack: { readonly kind: ThreadPullRequestChain["kind"]; readonly size: number } | null;
-}
-
-function activityAt(link: ThreadPullRequestLink): number {
- const ms = Date.parse(link.snapshot?.updatedAt ?? link.linkedAt);
- return Number.isNaN(ms) ? 0 : ms;
-}
-
-function chainKeyOf(chain: ThreadPullRequestChain): string {
- const bottom = chain.layers[0]!;
- return `${bottom.host}/${bottom.repository}#${bottom.number}`;
-}
-
-export function pullRequestListLines(
- chains: ReadonlyArray<ThreadPullRequestChain>,
-): ReadonlyArray<PullRequestListLine> {
- const ordered = [...chains].sort(
- (left, right) =>
- Math.max(...right.layers.map(activityAt)) - Math.max(...left.layers.map(activityAt)),
- );
- return ordered.flatMap((chain) => {
- const chainKey = chainKeyOf(chain);
- return chain.layers.map((link, index) => ({
- link,
- depth: chain.depths[index]!,
- chainKey,
- stack:
- index === 0 && chain.layers.length > 1
- ? { kind: chain.kind, size: chain.layers.length }
- : null,
- }));
- });
-}
diff --git a/apps/web/src/pullRequestReference.test.ts b/apps/web/src/pullRequestReference.test.ts
deleted file mode 100644
index 5e534af0a0b..00000000000
--- a/apps/web/src/pullRequestReference.test.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-import { describe, expect, it } from "vite-plus/test";
-
-import { parsePullRequestReference } from "./pullRequestReference";
-
-describe("parsePullRequestReference", () => {
- it("accepts GitHub pull request URLs", () => {
- expect(parsePullRequestReference("https://github.com/pingdotgg/t3code/pull/42")).toBe(
- "https://github.com/pingdotgg/t3code/pull/42",
- );
- });
-
- it("accepts Azure DevOps pull request URLs", () => {
- expect(
- parsePullRequestReference("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42"),
- ).toBe("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42");
- });
-
- it("accepts GitLab merge request URLs", () => {
- expect(parsePullRequestReference("https://gitlab.com/group/project/-/merge_requests/42")).toBe(
- "https://gitlab.com/group/project/-/merge_requests/42",
- );
- });
-
- it("accepts legacy Azure DevOps pull request URLs", () => {
- expect(
- parsePullRequestReference("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42"),
- ).toBe("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42");
- });
-
- it("accepts raw numbers", () => {
- expect(parsePullRequestReference("42")).toBe("42");
- });
-
- it("accepts #number references", () => {
- expect(parsePullRequestReference("#42")).toBe("42");
- });
-
- it("accepts gh pr checkout commands with raw numbers", () => {
- expect(parsePullRequestReference("gh pr checkout 42")).toBe("42");
- });
-
- it("accepts gh pr checkout commands with #number references", () => {
- expect(parsePullRequestReference("gh pr checkout #42")).toBe("42");
- });
-
- it("accepts gh pr checkout commands with GitHub pull request URLs", () => {
- expect(
- parsePullRequestReference("gh pr checkout https://github.com/pingdotgg/t3code/pull/42"),
- ).toBe("https://github.com/pingdotgg/t3code/pull/42");
- });
-
- it("accepts glab mr checkout commands with raw numbers", () => {
- expect(parsePullRequestReference("glab mr checkout 42")).toBe("42");
- });
-
- it("accepts az repos pr checkout commands with raw numbers", () => {
- expect(parsePullRequestReference("az repos pr checkout --id 42")).toBe("42");
- });
-
- it("accepts az repos pr checkout commands with equals-style ids", () => {
- expect(parsePullRequestReference("az repos pr checkout --id=42")).toBe("42");
- });
-
- it("accepts az repos pr checkout commands with extra flags", () => {
- expect(parsePullRequestReference("az repos pr checkout --id 42 --remote-name origin")).toBe(
- "42",
- );
- });
-
- it("rejects non-pull-request input", () => {
- expect(parsePullRequestReference("feature/my-branch")).toBeNull();
- });
-});
diff --git a/apps/web/src/pullRequestReference.ts b/apps/web/src/pullRequestReference.ts
deleted file mode 100644
index d9d97c4f615..00000000000
--- a/apps/web/src/pullRequestReference.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
-
-const PULL_REQUEST_NUMBER_PATTERN = /^#?(\d+)$/;
-
-export function parsePullRequestReference(input: string): string | null {
- const trimmed = input.trim();
- if (trimmed.length === 0) {
- return null;
- }
-
- const normalizedInput =
- sourceControlClients.definitions
- .map((definition) => definition.checkoutCommandArgument(trimmed))
- .find((argument) => argument !== null) ?? trimmed;
- if (normalizedInput.length === 0) {
- return null;
- }
-
- if (
- sourceControlClients.definitions.some((definition) =>
- definition.isChangeRequestReference(normalizedInput),
- )
- ) {
- return normalizedInput;
- }
-
- const numberMatch = PULL_REQUEST_NUMBER_PATTERN.exec(normalizedInput);
- if (numberMatch?.[1]) {
- return numberMatch[1];
- }
-
- return null;
-}
diff --git a/oxlint-plugin-t3code/index.ts b/oxlint-plugin-t3code/index.ts
index e67cc86a99a..edd1050e290 100644
--- a/oxlint-plugin-t3code/index.ts
+++ b/oxlint-plugin-t3code/index.ts
@@ -8,6 +8,7 @@ import noLowValueComments from "./rules/no-low-value-comments.ts";
import noManualMemo from "./rules/no-manual-memo.ts";
import noManualEffectRuntimeInTests from "./rules/no-manual-effect-runtime-in-tests.ts";
import noMobileUniwindThemeEscapeHatches from "./rules/no-mobile-uniwind-theme-escape-hatches.ts";
+import noMobilePullRequestGlyphLiterals from "./rules/no-mobile-pull-request-glyph-literals.ts";
import noNativeTitleTooltip from "./rules/no-native-title-tooltip.ts";
import noOutsetStateIndicators from "./rules/no-outset-state-indicators.ts";
import noRawMcpRegistration from "./rules/no-raw-mcp-registration.ts";
@@ -32,6 +33,7 @@ export default definePlugin({
"no-manual-effect-runtime-in-tests": noManualEffectRuntimeInTests,
"no-manual-memo": noManualMemo,
"no-mobile-uniwind-theme-escape-hatches": noMobileUniwindThemeEscapeHatches,
+ "no-mobile-pull-request-glyph-literals": noMobilePullRequestGlyphLiterals,
"no-native-title-tooltip": noNativeTitleTooltip,
"no-outset-state-indicators": noOutsetStateIndicators,
"no-raw-mcp-registration": noRawMcpRegistration,
diff --git a/oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.test.ts b/oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.test.ts
new file mode 100644
index 00000000000..f5a26cf77a7
--- /dev/null
+++ b/oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.test.ts
@@ -0,0 +1,66 @@
+import { assert, describe } from "@effect/vitest";
+
+import { createOxlintRuleHarness } from "../test/utils.ts";
+
+const rule = createOxlintRuleHarness("t3code/no-mobile-pull-request-glyph-literals", {
+ filename: "apps/mobile/src/features/threads/PullRequestBadge.tsx",
+});
+
+describe("t3code/no-mobile-pull-request-glyph-literals", () => {
+ rule.valid(
+ "allows glyphs picked from the module",
+ `
+ import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
+
+ const badge = <SymbolView name={merged ? PullRequestGlyph.merged : PullRequestGlyph.pullRequest} />;
+ `,
+ );
+
+ rule.valid(
+ "allows unrelated symbols and copy that mentions pull requests",
+ `
+ const branch = <SymbolView name="arrow.triangle.branch" />;
+ const label = "Merge pull request";
+ `,
+ );
+
+ rule.invalid(
+ "reports a pull request glyph in a JSX attribute",
+ `const badge = <SymbolView name="arrow.triangle.pull" />;`,
+ (output) => {
+ assert.match(output, /PullRequestGlyph/);
+ },
+ );
+
+ rule.invalid(
+ "reports state glyphs chosen inline",
+ `const name = state === "closed" ? "git.pull-request.closed" : "git.pull-request.draft";`,
+ );
+
+ rule.invalid(
+ "reports glyphs in platform symbol objects",
+ `const icon = { ios: "arrow.triangle.merge", android: "merge" };`,
+ );
+
+ rule.invalid(
+ "reports an Android-only pull request glyph",
+ `const icon = { ios: "arrow.triangle.branch", android: "merge" };`,
+ );
+
+ rule.valid(
+ "allows merge as an ordinary string outside an android symbol slot",
+ `const action = { kind: "merge", label: "Merge" };`,
+ );
+
+ rule.valid(
+ "allows merge in an android key outside a platform symbol object",
+ `const command = { id: "pr.merge", android: "merge" };`,
+ );
+
+ rule.invalid(
+ "reports an Android-only pull request glyph written as a template literal",
+ 'const icon = { ios: "arrow.triangle.branch", android: `merge` };',
+ );
+
+ rule.invalid("reports glyphs in template literals", "const name = `square.3.layers.3d`;");
+});
diff --git a/oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.ts b/oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.ts
new file mode 100644
index 00000000000..0996c9aa7d2
--- /dev/null
+++ b/oxlint-plugin-t3code/rules/no-mobile-pull-request-glyph-literals.ts
@@ -0,0 +1,65 @@
+import { defineRule, type ESTree } from "@oxlint/plugins";
+
+const PULL_REQUEST_GLYPH_NAMES = new Set([
+ "arrow.triangle.pull",
+ "arrow.triangle.merge",
+ "git.pull-request.closed",
+ "git.pull-request.draft",
+ "square.3.layers.3d",
+]);
+
+// Material names reach AppSymbol only through `{ ios, android }` objects, and
+// "merge" is too common a string to ban outside that slot.
+const ANDROID_PULL_REQUEST_GLYPH_NAMES = new Set(["merge"]);
+
+const MESSAGE =
+ "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.";
+
+function propertyKey(node: { key: ESTree.PropertyKey }) {
+ if (node.key.type === "Identifier") return node.key.name;
+ if (node.key.type === "Literal") return node.key.value;
+ return null;
+}
+
+function staticString(node: ESTree.Node) {
+ if (node.type === "Literal") return typeof node.value === "string" ? node.value : null;
+ if (node.type === "TemplateLiteral" && node.expressions.length === 0) {
+ return node.quasis[0]?.value.cooked ?? null;
+ }
+ return null;
+}
+
+export default defineRule({
+ meta: {
+ type: "problem",
+ docs: {
+ description:
+ "Disallow pull request symbol names as string literals in mobile code; the import restriction that guards web cannot see string names.",
+ },
+ },
+ create(context) {
+ return {
+ Literal(node) {
+ if (typeof node.value !== "string" || !PULL_REQUEST_GLYPH_NAMES.has(node.value)) return;
+ context.report({ node, message: MESSAGE });
+ },
+ Property(node) {
+ if (
+ propertyKey(node) !== "android" ||
+ node.parent.type !== "ObjectExpression" ||
+ !node.parent.properties.some(
+ (property) => property.type === "Property" && propertyKey(property) === "ios",
+ )
+ )
+ return;
+ const value = staticString(node.value);
+ if (value === null || !ANDROID_PULL_REQUEST_GLYPH_NAMES.has(value)) return;
+ context.report({ node: node.value, message: MESSAGE });
+ },
+ TemplateElement(node) {
+ if (!PULL_REQUEST_GLYPH_NAMES.has(node.value.cooked ?? "")) return;
+ context.report({ node, message: MESSAGE });
+ },
+ };
+ },
+});
diff --git a/packages/client-runtime/package.json b/packages/client-runtime/package.json
index 771843e2ae7..9eed1acbb88 100644
--- a/packages/client-runtime/package.json
+++ b/packages/client-runtime/package.json
@@ -355,6 +355,10 @@
"types": "./src/work-log/scrollAnchor.ts",
"default": "./src/work-log/scrollAnchor.ts"
},
+ "./pull-request-link-input": {
+ "types": "./src/pullRequestLinkInput.ts",
+ "default": "./src/pullRequestLinkInput.ts"
+ },
"./thread-pull-request-compatibility": {
"types": "./src/threadPullRequestCompatibility.ts",
"default": "./src/threadPullRequestCompatibility.ts"
diff --git a/apps/web/src/components/pullRequest/LinkPullRequestDialog.logic.test.ts b/packages/client-runtime/src/pullRequestLinkInput.test.ts
similarity index 63%
rename from apps/web/src/components/pullRequest/LinkPullRequestDialog.logic.test.ts
rename to packages/client-runtime/src/pullRequestLinkInput.test.ts
index 75dbc7ea461..47896c0d9ff 100644
--- a/apps/web/src/components/pullRequest/LinkPullRequestDialog.logic.test.ts
+++ b/packages/client-runtime/src/pullRequestLinkInput.test.ts
@@ -1,8 +1,8 @@
import { describe, expect, it } from "vite-plus/test";
-import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
+import { sourceControlClients } from "./sourceControlClients.ts";
-import { resolveLinkPullRequestInput } from "./LinkPullRequestDialog";
+import { parsePullRequestReference, resolveLinkPullRequestInput } from "./pullRequestLinkInput.ts";
const changeRequestWebUrl = (kind: string, host: string, repository: string, number: number) =>
sourceControlClients.get(kind).changeRequestUrl({ host, repository, number });
@@ -139,3 +139,73 @@ describe("changeRequestWebUrl", () => {
expect(changeRequestWebUrl("unknown", "x", "a/b", 1)).toBeNull();
});
});
+
+describe("parsePullRequestReference", () => {
+ it("accepts GitHub pull request URLs", () => {
+ expect(parsePullRequestReference("https://github.com/pingdotgg/t3code/pull/42")).toBe(
+ "https://github.com/pingdotgg/t3code/pull/42",
+ );
+ });
+
+ it("accepts Azure DevOps pull request URLs", () => {
+ expect(
+ parsePullRequestReference("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42"),
+ ).toBe("https://dev.azure.com/acme/project/_git/t3code/pullrequest/42");
+ });
+
+ it("accepts GitLab merge request URLs", () => {
+ expect(parsePullRequestReference("https://gitlab.com/group/project/-/merge_requests/42")).toBe(
+ "https://gitlab.com/group/project/-/merge_requests/42",
+ );
+ });
+
+ it("accepts legacy Azure DevOps pull request URLs", () => {
+ expect(
+ parsePullRequestReference("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42"),
+ ).toBe("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42");
+ });
+
+ it("accepts raw numbers", () => {
+ expect(parsePullRequestReference("42")).toBe("42");
+ });
+
+ it("accepts #number references", () => {
+ expect(parsePullRequestReference("#42")).toBe("42");
+ });
+
+ it("accepts gh pr checkout commands with raw numbers", () => {
+ expect(parsePullRequestReference("gh pr checkout 42")).toBe("42");
+ });
+
+ it("accepts gh pr checkout commands with #number references", () => {
+ expect(parsePullRequestReference("gh pr checkout #42")).toBe("42");
+ });
+
+ it("accepts gh pr checkout commands with GitHub pull request URLs", () => {
+ expect(
+ parsePullRequestReference("gh pr checkout https://github.com/pingdotgg/t3code/pull/42"),
+ ).toBe("https://github.com/pingdotgg/t3code/pull/42");
+ });
+
+ it("accepts glab mr checkout commands with raw numbers", () => {
+ expect(parsePullRequestReference("glab mr checkout 42")).toBe("42");
+ });
+
+ it("accepts az repos pr checkout commands with raw numbers", () => {
+ expect(parsePullRequestReference("az repos pr checkout --id 42")).toBe("42");
+ });
+
+ it("accepts az repos pr checkout commands with equals-style ids", () => {
+ expect(parsePullRequestReference("az repos pr checkout --id=42")).toBe("42");
+ });
+
+ it("accepts az repos pr checkout commands with extra flags", () => {
+ expect(parsePullRequestReference("az repos pr checkout --id 42 --remote-name origin")).toBe(
+ "42",
+ );
+ });
+
+ it("rejects non-pull-request input", () => {
+ expect(parsePullRequestReference("feature/my-branch")).toBeNull();
+ });
+});
diff --git a/packages/client-runtime/src/pullRequestLinkInput.ts b/packages/client-runtime/src/pullRequestLinkInput.ts
new file mode 100644
index 00000000000..a6d4d4ce8d8
--- /dev/null
+++ b/packages/client-runtime/src/pullRequestLinkInput.ts
@@ -0,0 +1,104 @@
+import { pullRequestHostOf, type RepositoryIdentity } from "@t3tools/contracts";
+import { parseChangeRequestUrl } from "@t3tools/shared/changeRequestUrl";
+
+import { sourceControlClients } from "./sourceControlClients.ts";
+
+const PULL_REQUEST_NUMBER_PATTERN = /^#?(\d+)$/;
+
+export function parsePullRequestReference(input: string): string | null {
+ const trimmed = input.trim();
+ if (trimmed.length === 0) {
+ return null;
+ }
+
+ const normalizedInput =
+ sourceControlClients.definitions
+ .map((definition) => definition.checkoutCommandArgument(trimmed))
+ .find((argument) => argument !== null) ?? trimmed;
+ if (normalizedInput.length === 0) {
+ return null;
+ }
+
+ if (
+ sourceControlClients.definitions.some((definition) =>
+ definition.isChangeRequestReference(normalizedInput),
+ )
+ ) {
+ return normalizedInput;
+ }
+
+ const numberMatch = PULL_REQUEST_NUMBER_PATTERN.exec(normalizedInput);
+ if (numberMatch?.[1]) {
+ return numberMatch[1];
+ }
+
+ return null;
+}
+
+/** The thread project's repository, so a bare number resolves to one of its pull requests. */
+export function pullRequestLinkProject(identity: RepositoryIdentity | null | undefined) {
+ if (!identity) return null;
+ const repository =
+ identity.displayName ??
+ (identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null);
+ if (repository === null) return null;
+ const definition = sourceControlClients.get(identity.provider ?? "unknown");
+ const host = pullRequestHostOf(identity, definition.kind);
+ return {
+ host,
+ repository,
+ webUrl: (number: number) =>
+ definition.changeRequestUrl({
+ host,
+ repository,
+ number,
+ remoteUrl: identity.locator.remoteUrl,
+ webUrl: identity.webUrl,
+ }),
+ };
+}
+
+interface ResolvedLink {
+ readonly host: string;
+ readonly repository: string;
+ readonly number: number;
+ readonly url: string;
+}
+
+export function resolveLinkPullRequestInput(input: {
+ readonly reference: string;
+ readonly project: {
+ readonly host: string;
+ readonly repository: string;
+ readonly webUrl: (number: number) => string | null;
+ } | null;
+ readonly hasProject: (reference: ResolvedLink) => boolean;
+}): { link: ResolvedLink } | { error: string } | null {
+ const parsed =
+ parseChangeRequestUrl(input.reference.trim()) !== null
+ ? input.reference.trim()
+ : parsePullRequestReference(input.reference);
+ if (parsed === null) return null;
+ const url = parseChangeRequestUrl(parsed);
+ if (url !== null) {
+ if (!input.hasProject({ ...url, url: parsed })) {
+ return { error: `No project in this environment can read ${url.host}/${url.repository}.` };
+ }
+ return {
+ link: { host: url.host, repository: url.repository, number: url.number, url: parsed },
+ };
+ }
+ const number = Number(parsed);
+ if (!Number.isSafeInteger(number) || number < 1) return null;
+ if (input.project === null) {
+ return { error: "Paste a full URL to link a pull request from another repository." };
+ }
+ const webUrl = input.project.webUrl(number);
+ const webReference = webUrl === null ? null : parseChangeRequestUrl(webUrl);
+ if (webUrl === null || webReference === null) {
+ return { error: "Paste a full URL; this project's host has no known pull request URL." };
+ }
+ return {
+ link: { ...webReference, url: webUrl },
+ };
+}
diff --git a/apps/web/src/components/pullRequest/pullRequestListLines.test.ts b/packages/shared/src/threadPullRequestListLines.test.ts
similarity index 93%
rename from apps/web/src/components/pullRequest/pullRequestListLines.test.ts
rename to packages/shared/src/threadPullRequestListLines.test.ts
index 06b9f10dbf3..91cc8bf1a1e 100644
--- a/apps/web/src/components/pullRequest/pullRequestListLines.test.ts
+++ b/packages/shared/src/threadPullRequestListLines.test.ts
@@ -1,8 +1,7 @@
import type { ThreadPullRequestLink } from "@t3tools/contracts";
-import { resolveThreadPullRequestChains } from "@t3tools/shared/threadPullRequests";
import { describe, expect, it } from "vite-plus/test";
-import { pullRequestListLines } from "./pullRequestListLines";
+import { pullRequestListLines, resolveThreadPullRequestChains } from "./threadPullRequests.ts";
function link(
number: number,
diff --git a/packages/shared/src/threadPullRequests.ts b/packages/shared/src/threadPullRequests.ts
index 9b0c1a7457d..29a384aca6e 100644
--- a/packages/shared/src/threadPullRequests.ts
+++ b/packages/shared/src/threadPullRequests.ts
@@ -364,3 +364,37 @@ export function applyThreadPullRequestLinkUpdate(
),
};
}
+
+export interface PullRequestListLine {
+ readonly link: ThreadPullRequestLink;
+ readonly depth: number;
+ readonly chainKey: string;
+ readonly stack: { readonly kind: ThreadPullRequestChain["kind"]; readonly size: number } | null;
+}
+
+function chainKeyOf(chain: ThreadPullRequestChain): string {
+ const bottom = chain.layers[0]!;
+ return `${bottom.host}/${bottom.repository}#${bottom.number}`;
+}
+
+export function pullRequestListLines(
+ chains: ReadonlyArray<ThreadPullRequestChain>,
+): ReadonlyArray<PullRequestListLine> {
+ const ordered = [...chains].sort(
+ (left, right) =>
+ Math.max(...right.layers.map(latestUpdatedAt)) -
+ Math.max(...left.layers.map(latestUpdatedAt)),
+ );
+ return ordered.flatMap((chain) => {
+ const chainKey = chainKeyOf(chain);
+ return chain.layers.map((link, index) => ({
+ link,
+ depth: chain.depths[index]!,
+ chainKey,
+ stack:
+ index === 0 && chain.layers.length > 1
+ ? { kind: chain.kind, size: chain.layers.length }
+ : null,
+ }));
+ });
+}
diff --git a/vite.config.ts b/vite.config.ts
index 812e5d504fc..2635b4b2a91 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -247,6 +247,15 @@ export default defineConfig({
files: ["apps/mobile/src/**"],
rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
},
+ {
+ files: ["apps/mobile/src/**"],
+ excludeFiles: [
+ "apps/mobile/src/components/ui/AppSymbol.tsx",
+ "apps/mobile/src/components/ui/AppSymbol.ios.tsx",
+ "apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts",
+ ],
+ rules: { "t3code/no-mobile-pull-request-glyph-literals": "error" },
+ },
{
// React commits state set in a raw ResizeObserver callback after the paint, so derived
// layout lands a frame late. observeResize flushes every observed resize in one render.