From 59af9dce68d8cd9375d11f33bba666304b631ea4 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 29 Jun 2026 17:05:45 -0700 Subject: [PATCH] Recover stale mobile thread routes --- .../features/threads/ThreadGitControls.tsx | 15 ++++- apps/mobile/src/state/use-thread-selection.ts | 56 ++++++++++++++++++- patches/expo-router@56.2.11.patch | 39 ++++++++++--- pnpm-lock.yaml | 10 ++-- 4 files changed, 102 insertions(+), 18 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadGitControls.tsx b/apps/mobile/src/features/threads/ThreadGitControls.tsx index 6a3231c0b3..0c7930eaca 100644 --- a/apps/mobile/src/features/threads/ThreadGitControls.tsx +++ b/apps/mobile/src/features/threads/ThreadGitControls.tsx @@ -66,7 +66,7 @@ function compactMenuStatus(gitStatus: VcsStatusResult | null): string { return parts.join(" ยท "); } -type HeaderRightItems = ReturnType< +type HeaderItems = ReturnType< NonNullable >; type QuickActionIcon = @@ -238,7 +238,7 @@ function useThreadGitControlModel(props: ThreadGitControlsProps) { }; } -export function useThreadGitRightHeaderItems(props: ThreadGitControlsProps): HeaderRightItems { +function useThreadGitHeaderActionItems(props: ThreadGitControlsProps): HeaderItems { const model = useThreadGitControlModel(props); return useMemo( @@ -370,7 +370,7 @@ export function useThreadGitRightHeaderItems(props: ThreadGitControlsProps): Hea variant: "prominent", width: 58, }, - ].toReversed() as HeaderRightItems, + ] as HeaderItems, [ model.currentBranchLabel, model.isRepo, @@ -394,6 +394,15 @@ export function useThreadGitRightHeaderItems(props: ThreadGitControlsProps): Hea ); } +export function useThreadGitRightHeaderItems(props: ThreadGitControlsProps): HeaderItems { + const actionItems = useThreadGitHeaderActionItems(props); + return useMemo(() => actionItems.toReversed() as HeaderItems, [actionItems]); +} + +export function useThreadGitCenterHeaderItems(props: ThreadGitControlsProps): HeaderItems { + return useThreadGitHeaderActionItems(props); +} + export function ThreadGitControls(props: ThreadGitControlsProps) { const model = useThreadGitControlModel(props); const showActionControls = props.showActionControls ?? true; diff --git a/apps/mobile/src/state/use-thread-selection.ts b/apps/mobile/src/state/use-thread-selection.ts index 8f3a1c2d1c..656a961386 100644 --- a/apps/mobile/src/state/use-thread-selection.ts +++ b/apps/mobile/src/state/use-thread-selection.ts @@ -2,12 +2,16 @@ import { useGlobalSearchParams } from "expo-router"; import { createContext, createElement, use, useMemo, useRef, type ReactNode } from "react"; import { EnvironmentId, + type OrchestrationThread, ThreadId, type ScopedProjectRef, type ScopedThreadRef, } from "@t3tools/contracts"; +import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; +import * as Option from "effect/Option"; import { useProject, useThreadShell } from "../state/entities"; +import { useEnvironmentThread } from "../state/threads"; import { useRemoteEnvironmentRuntime, useSavedRemoteConnection, @@ -21,6 +25,43 @@ function firstRouteParam(value: string | string[] | undefined): string | null { return value ?? null; } +function latestUserMessageAt(thread: OrchestrationThread): OrchestrationThread["updatedAt"] | null { + for (let index = thread.messages.length - 1; index >= 0; index -= 1) { + const message = thread.messages[index]; + if (message?.role === "user") { + return message.createdAt; + } + } + + return null; +} + +function threadDetailToShell( + environmentId: EnvironmentId, + thread: OrchestrationThread, +): EnvironmentThreadShell { + return { + environmentId, + id: thread.id, + projectId: thread.projectId, + title: thread.title, + modelSelection: thread.modelSelection, + runtimeMode: thread.runtimeMode, + interactionMode: thread.interactionMode, + branch: thread.branch, + worktreePath: thread.worktreePath, + latestTurn: thread.latestTurn, + createdAt: thread.createdAt, + updatedAt: thread.updatedAt, + archivedAt: thread.archivedAt, + session: thread.session, + latestUserMessageAt: latestUserMessageAt(thread), + hasPendingApprovals: false, + hasPendingUserInput: false, + hasActionableProposedPlan: false, + }; +} + function useResolvedThreadSelection() { const params = useGlobalSearchParams<{ environmentId?: string | string[]; @@ -43,7 +84,20 @@ function useResolvedThreadSelection() { lastRouteThreadRef.current = routeThreadRef; } const selectedThreadRef = routeThreadRef ?? lastRouteThreadRef.current; - const selectedThread = useThreadShell(selectedThreadRef); + const selectedThreadShell = useThreadShell(selectedThreadRef); + const selectedThreadDetailState = useEnvironmentThread( + selectedThreadRef?.environmentId ?? null, + selectedThreadRef?.threadId ?? null, + ); + const selectedThreadDetail = Option.getOrNull(selectedThreadDetailState.data); + const selectedThread = useMemo( + () => + selectedThreadShell ?? + (selectedThreadRef !== null && selectedThreadDetail !== null + ? threadDetailToShell(selectedThreadRef.environmentId, selectedThreadDetail) + : null), + [selectedThreadDetail, selectedThreadRef, selectedThreadShell], + ); const selectedProjectRef = useMemo( () => selectedThread === null diff --git a/patches/expo-router@56.2.11.patch b/patches/expo-router@56.2.11.patch index 78a4dace79..a2ea0f13a3 100644 --- a/patches/expo-router@56.2.11.patch +++ b/patches/expo-router@56.2.11.patch @@ -1,12 +1,21 @@ diff --git a/build/react-navigation/native-stack/types.d.ts b/build/react-navigation/native-stack/types.d.ts -index 6de73e0c33cedbaaaffdcb092ba21fc9ff71862e..93845c781609c1a46bf71f2c30ef81432fb56bc2 100644 +index 6de73e0c33cedbaaaffdcb092ba21fc9ff71862e..78929fe237b7f9d7808f8de2b844e822976e0d69 100644 --- a/build/react-navigation/native-stack/types.d.ts +++ b/build/react-navigation/native-stack/types.d.ts -@@ -306,6 +306,22 @@ export type NativeStackNavigationOptions = { +@@ -306,6 +306,31 @@ export type NativeStackNavigationOptions = { * @platform ios */ unstable_headerRightItems?: (props: NativeStackHeaderItemProps) => NativeStackHeaderItem[]; + /** ++ * Function which returns an array of items to display as the centered item ++ * group in modern iOS headers. ++ * ++ * This is an unstable API and might change in the future. ++ * ++ * @platform ios ++ */ ++ unstable_headerCenterItems?: (props: NativeStackHeaderItemProps) => NativeStackHeaderItem[]; ++ /** + * Function which returns an array of toolbar items for the current screen. + * + * This is an unstable API and might change in the future. @@ -25,18 +34,18 @@ index 6de73e0c33cedbaaaffdcb092ba21fc9ff71862e..93845c781609c1a46bf71f2c30ef8143 /** * String or a function that returns a React Element to be used by the header. * Defaults to screen `title` or route name. -@@ -1115,7 +1131,8 @@ export type NativeStackHeaderItemCustom = { +@@ -1115,7 +1140,8 @@ export type NativeStackHeaderItemCustom = { * if the items don't fit the available space, they will be collapsed into a menu automatically. * Items with `type: 'custom'` will not be included in this automatic collapsing behavior. */ -export type NativeStackHeaderItem = NativeStackHeaderItemButton | NativeStackHeaderItemMenu | NativeStackHeaderItemSpacing | NativeStackHeaderItemCustom; -+export type NativeStackHeaderRawRNSItem = NonNullable[number] | NonNullable[number]; ++export type NativeStackHeaderRawRNSItem = NonNullable[number] | NonNullable[number] | NonNullable[number]; +export type NativeStackHeaderItem = NativeStackHeaderItemButton | NativeStackHeaderItemMenu | NativeStackHeaderItemSpacing | NativeStackHeaderItemCustom | NativeStackHeaderRawRNSItem; export type NativeStackNavigatorProps = DefaultNavigatorOptions, NativeStackNavigationOptions, NativeStackNavigationEventMap, NativeStackNavigationProp> & StackRouterOptions & NativeStackNavigationConfig; export type NativeStackDescriptor = Descriptor, RouteProp>; export type NativeStackDescriptorMap = { diff --git a/build/react-navigation/native-stack/views/useHeaderConfigProps.d.ts b/build/react-navigation/native-stack/views/useHeaderConfigProps.d.ts -index 218c4291fdb57600a45d32fbcefe3707a520fe79..ce3bbadec2d52949d133401f1df01b95899aa5bf 100644 +index 218c4291fdb57600a45d32fbcefe3707a520fe79..5fdbb2754755a27589ad1555eae892b5fbee2c6a 100644 --- a/build/react-navigation/native-stack/views/useHeaderConfigProps.d.ts +++ b/build/react-navigation/native-stack/views/useHeaderConfigProps.d.ts @@ -10,6 +10,6 @@ type Props = NativeStackNavigationOptions & { @@ -44,11 +53,11 @@ index 218c4291fdb57600a45d32fbcefe3707a520fe79..ce3bbadec2d52949d133401f1df01b95 route: Route; }; -export declare function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBackButtonDisplayMode, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle: headerLargeTitleDeprecated, headerLargeTitleEnabled, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, headerTopInsetEnabled, headerBack, route, title, unstable_headerLeftItems: headerLeftItems, unstable_headerRightItems: headerRightItems, }: Props): ScreenStackHeaderConfigProps; -+export declare function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBackButtonDisplayMode, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle: headerLargeTitleDeprecated, headerLargeTitleEnabled, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, headerTopInsetEnabled, headerBack, route, title, unstable_headerLeftItems: headerLeftItems, unstable_headerRightItems: headerRightItems, unstable_headerToolbarItems: headerToolbarItems, unstable_navigationItemStyle: navigationItemStyle, }: Props): ScreenStackHeaderConfigProps; ++export declare function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBackButtonDisplayMode, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle: headerLargeTitleDeprecated, headerLargeTitleEnabled, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, headerTopInsetEnabled, headerBack, route, title, unstable_headerLeftItems: headerLeftItems, unstable_headerRightItems: headerRightItems, unstable_headerCenterItems: headerCenterItems, unstable_headerToolbarItems: headerToolbarItems, unstable_navigationItemStyle: navigationItemStyle, }: Props): ScreenStackHeaderConfigProps; export {}; //# sourceMappingURL=useHeaderConfigProps.d.ts.map diff --git a/build/react-navigation/native-stack/views/useHeaderConfigProps.js b/build/react-navigation/native-stack/views/useHeaderConfigProps.js -index 2de6d160cedffb4ffb124adf7cd10979ec6ee778..ed9651d5bcce56594c6a1946b2cb6a8f11f80c7c 100644 +index 2de6d160cedffb4ffb124adf7cd10979ec6ee778..9d839442e00e136204630663f207a45c950dcd25 100644 --- a/build/react-navigation/native-stack/views/useHeaderConfigProps.js +++ b/build/react-navigation/native-stack/views/useHeaderConfigProps.js @@ -22,6 +22,9 @@ const processBarButtonItems = (items, colors, fonts) => { @@ -66,14 +75,26 @@ index 2de6d160cedffb4ffb124adf7cd10979ec6ee778..ed9651d5bcce56594c6a1946b2cb6a8f }; }; -function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBackButtonDisplayMode, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle: headerLargeTitleDeprecated, headerLargeTitleEnabled = headerLargeTitleDeprecated, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, headerTopInsetEnabled, headerBack, route, title, unstable_headerLeftItems: headerLeftItems, unstable_headerRightItems: headerRightItems, }) { -+function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBackButtonDisplayMode, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle: headerLargeTitleDeprecated, headerLargeTitleEnabled = headerLargeTitleDeprecated, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, headerTopInsetEnabled, headerBack, route, title, unstable_headerLeftItems: headerLeftItems, unstable_headerRightItems: headerRightItems, unstable_headerToolbarItems: headerToolbarItems, unstable_navigationItemStyle: navigationItemStyle, }) { ++function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBackButtonDisplayMode, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle: headerLargeTitleDeprecated, headerLargeTitleEnabled = headerLargeTitleDeprecated, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, headerTopInsetEnabled, headerBack, route, title, unstable_headerLeftItems: headerLeftItems, unstable_headerRightItems: headerRightItems, unstable_headerCenterItems: headerCenterItems, unstable_headerToolbarItems: headerToolbarItems, unstable_navigationItemStyle: navigationItemStyle, }) { const { direction } = (0, native_1.useLocale)(); const { colors, fonts, dark } = (0, native_1.useTheme)(); const tintColor = headerTintColor ?? (react_native_1.Platform.OS === 'ios' ? colors.primary : colors.text); -@@ -270,6 +273,8 @@ function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBac +@@ -216,6 +219,10 @@ function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBac + tintColor, + canGoBack, + }); ++ const centerItems = headerCenterItems?.({ ++ tintColor, ++ canGoBack, ++ }); + if (rightItems) { + // iOS renders right items in reverse order + // So we need to reverse them here to match the order +@@ -270,6 +277,9 @@ function useHeaderConfigProps({ headerBackIcon, headerBackImageSource, headerBac children, headerLeftBarButtonItems: processBarButtonItems(leftItems, colors, fonts), headerRightBarButtonItems: processBarButtonItems(rightItems, colors, fonts), ++ headerCenterBarButtonItems: processBarButtonItems(centerItems, colors, fonts), + headerToolbarItems, + navigationItemStyle, experimental_userInterfaceStyle: dark ? 'dark' : 'light', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 87790cc10c..80d36c1cf9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,7 +72,7 @@ patchedDependencies: '@pierre/diffs@1.3.0-beta.5': 7cb6da88544119adda056b2f46f43956f99326227732da0b345081e285a6c53a effect@4.0.0-beta.78: c502bc684210b707dfceb87d8fe6ad6843395af6e19cfc02cd65854898bde2c5 expo-modules-jsi@56.0.10: 9170f8074ae4e35a0a086e756c8f815794fd3abe51eac67ca3ba02804225ec1f - expo-router@56.2.11: 7b915c5a27d2253e9770b92ebfcd8a9f85ebb849f07bdfa8d85af76ea0231215 + expo-router@56.2.11: d63025d5ca8999d61e090361acb374aebe9917ae1da7c4d65c2cc44977bd844c react-native-nitro-modules@0.35.9: 825622aae63a8fb5b904f3c77908a0e216261d727ea171709f2c0b6088422675 react-native-screens@4.25.2: 9a555061147ecd74107ca21a77697a0515cd6a9359abbe4baf8b44295565e61b @@ -309,7 +309,7 @@ importers: version: 0.1.15(expo@56.0.12)(react-native@0.85.3(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.2.16)(bufferutil@4.1.0)(react@19.2.3)(utf-8-validate@6.0.6))(react@19.2.3) expo-router: specifier: ~56.2.11 - version: 56.2.11(patch_hash=7b915c5a27d2253e9770b92ebfcd8a9f85ebb849f07bdfa8d85af76ea0231215)(5cd69264394276d4731a5f991997a177) + version: 56.2.11(patch_hash=d63025d5ca8999d61e090361acb374aebe9917ae1da7c4d65c2cc44977bd844c)(708fd680682731bfd53a5282341dd27a) expo-secure-store: specifier: ~56.0.4 version: 56.0.4(expo@56.0.12) @@ -12003,7 +12003,7 @@ snapshots: ws: 8.21.0(bufferutil@4.1.0)(utf-8-validate@6.0.6) zod: 3.25.76 optionalDependencies: - expo-router: 56.2.11(patch_hash=7b915c5a27d2253e9770b92ebfcd8a9f85ebb849f07bdfa8d85af76ea0231215)(5cd69264394276d4731a5f991997a177) + expo-router: 56.2.11(patch_hash=d63025d5ca8999d61e090361acb374aebe9917ae1da7c4d65c2cc44977bd844c)(708fd680682731bfd53a5282341dd27a) react-native: 0.85.3(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.2.16)(bufferutil@4.1.0)(react@19.2.3)(utf-8-validate@6.0.6) transitivePeerDependencies: - '@expo/dom-webview' @@ -12301,7 +12301,7 @@ snapshots: react: 19.2.3 optionalDependencies: '@expo/metro-runtime': 56.0.15(@expo/log-box@56.0.13)(expo@56.0.12)(react-dom@19.2.3(react@19.2.3))(react-native@0.85.3(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.2.16)(bufferutil@4.1.0)(react@19.2.3)(utf-8-validate@6.0.6))(react@19.2.3) - expo-router: 56.2.11(patch_hash=7b915c5a27d2253e9770b92ebfcd8a9f85ebb849f07bdfa8d85af76ea0231215)(5cd69264394276d4731a5f991997a177) + expo-router: 56.2.11(patch_hash=d63025d5ca8999d61e090361acb374aebe9917ae1da7c4d65c2cc44977bd844c)(708fd680682731bfd53a5282341dd27a) react-dom: 19.2.3(react@19.2.3) transitivePeerDependencies: - supports-color @@ -16217,7 +16217,7 @@ snapshots: react: 19.2.3 react-native: 0.85.3(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.2.16)(bufferutil@4.1.0)(react@19.2.3)(utf-8-validate@6.0.6) - expo-router@56.2.11(patch_hash=7b915c5a27d2253e9770b92ebfcd8a9f85ebb849f07bdfa8d85af76ea0231215)(5cd69264394276d4731a5f991997a177): + expo-router@56.2.11(patch_hash=d63025d5ca8999d61e090361acb374aebe9917ae1da7c4d65c2cc44977bd844c)(708fd680682731bfd53a5282341dd27a): dependencies: '@expo/log-box': 56.0.13(@expo/dom-webview@56.0.5)(expo@56.0.12)(react-native@0.85.3(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.2.16)(bufferutil@4.1.0)(react@19.2.3)(utf-8-validate@6.0.6))(react@19.2.3) '@expo/metro-runtime': 56.0.15(@expo/log-box@56.0.13)(expo@56.0.12)(react-dom@19.2.3(react@19.2.3))(react-native@0.85.3(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.2.16)(bufferutil@4.1.0)(react@19.2.3)(utf-8-validate@6.0.6))(react@19.2.3)