Skip to content

Commit 2adebed

Browse files
Merge remote-tracking branch 'origin/main' into pr-17138
2 parents 643fca7 + f6a9315 commit 2adebed

164 files changed

Lines changed: 8555 additions & 1948 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"@t3tools/provider-acp-registry": "workspace:*",
7777
"@t3tools/provider-core": "workspace:*",
7878
"@t3tools/provider-cursor": "workspace:*",
79+
"@t3tools/provider-fx": "workspace:*",
7980
"@t3tools/provider-grok": "workspace:*",
8081
"@t3tools/provider-muse": "workspace:*",
8182
"@t3tools/provider-opencode": "workspace:*",

‎apps/mobile/src/App.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { GestureHandlerRootView } from "react-native-gesture-handler";
99
import { KeyboardProvider } from "react-native-keyboard-controller";
1010
import { SafeAreaProvider } from "react-native-safe-area-context";
1111
import {
12-
createNavigationContainerRef,
1312
createStaticNavigation,
1413
getActionFromState,
1514
getStateFromPath,
15+
type NavigationState,
1616
} from "@react-navigation/native";
1717

1818
import { RegistryContext } from "@effect/atom-react";
@@ -52,6 +52,8 @@ import {
5252
} from "./features/workspace/workspace-selection-store";
5353
import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection";
5454
import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics";
55+
import { attachRootNavigation, rootNavigationRef } from "./lib/rootNavigation";
56+
import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen";
5557

5658
import "../global.css";
5759

@@ -84,7 +86,15 @@ const appLinking = {
8486
};
8587

8688
const Navigation = createStaticNavigation(RootStack);
87-
const navigationRef = createNavigationContainerRef();
89+
90+
function handleNavigationStateChange(state: NavigationState | undefined): void {
91+
recordWorkspaceSelections(state);
92+
if (state) pruneNewTaskBranchCheckouts(state);
93+
}
94+
95+
function handleNavigationReady(): void {
96+
handleNavigationStateChange(rootNavigationRef.getRootState());
97+
}
8898

8999
declare const module: { readonly hot?: FoundationHotModule } | undefined;
90100

@@ -148,11 +158,11 @@ function AppContent() {
148158
<NativeLayoutMetricsProvider>
149159
<IncomingShareProvider>
150160
<Navigation
151-
ref={navigationRef}
161+
ref={attachRootNavigation}
152162
linking={appLinking}
153-
onReady={() => recordWorkspaceSelections(navigationRef.getRootState())}
163+
onReady={handleNavigationReady}
154164
theme={navigationTheme}
155-
onStateChange={recordWorkspaceSelections}
165+
onStateChange={handleNavigationStateChange}
156166
/>
157167
</IncomingShareProvider>
158168
<Dialog.Host />

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
22
import { AdaptiveWorkspaceContext, useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context";
3-
import { createDeferredNavigation } from "./deferred-navigation";
3+
import { threadSelectionDeferral } from "./deferred-navigation";
44
import { uuidv4 } from "../../lib/uuid";
55
import type {
66
EnvironmentProject,
@@ -491,10 +491,9 @@ function AdaptiveWorkspaceLayoutContent(
491491
};
492492
const handleOpenSettings = () => openWorkspaceTab("settings");
493493

494-
const deferredThreadSelection = useMemo(() => createDeferredNavigation(), []);
495494
/** The one way to show a page in the detail column; see `selectWorkspaceDetail`. */
496495
function handleSelectDetail(detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) {
497-
deferredThreadSelection.run(() => {
496+
threadSelectionDeferral.run(() => {
498497
if (Platform.OS === "android") Keyboard.dismiss();
499498
setFileInspectorPreferredVisible(false);
500499
if (layout.primarySidebarOverlaysContent) setPrimarySidebarVisible(false);
@@ -770,7 +769,6 @@ function AdaptiveWorkspaceLayoutContent(
770769
fileInspector,
771770
primarySidebarSearchQuery,
772771
startNewTask: handleStartNewTask,
773-
deferThreadSelectionUntil: deferredThreadSelection.waitFor,
774772
selectDetail: handleSelectDetail,
775773
activateAuxiliaryPaneRole,
776774
registerWorkspaceInspector,

‎apps/mobile/src/features/layout/adaptive-workspace-context.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ interface AdaptiveWorkspaceContextValue {
2020
readonly fileInspector: FileInspectorPaneLayout;
2121
readonly primarySidebarSearchQuery: string;
2222
readonly startNewTask: () => void;
23-
readonly deferThreadSelectionUntil: (operation: Promise<unknown>) => void;
2423
/** Use `useSelectWorkspaceDetail`, which also works outside the layout. */
2524
readonly selectDetail?: (detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => void;
2625
readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void;
@@ -67,7 +66,6 @@ export const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextVa
6766
fileInspector: compactFileInspector,
6867
primarySidebarSearchQuery: "",
6968
startNewTask: () => undefined,
70-
deferThreadSelectionUntil: () => undefined,
7169
activateAuxiliaryPaneRole: () => () => undefined,
7270
registerWorkspaceInspector: () => () => undefined,
7371
setPrimarySidebarSearchQuery: () => undefined,

‎apps/mobile/src/features/layout/deferred-navigation.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ export function createDeferredNavigation() {
2020
},
2121
};
2222
}
23+
24+
/**
25+
* The app's one thread-selection gate: a new-task branch checkout holds
26+
* split-view thread selection until the draft route can be left.
27+
*/
28+
export const threadSelectionDeferral = createDeferredNavigation();

‎apps/mobile/src/features/pull-requests/pullRequestList.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import {
99
appendPullRequestListPage,
1010
DEFAULT_PR_LIST_CONTROLS,
11+
EMPTY_PULL_REQUEST_STATS_CACHE,
1112
filterPullRequestList,
1213
mergePullRequestListEntries,
1314
mergeEnvironmentPullRequestPages,
@@ -21,6 +22,8 @@ import {
2122
scopedPullRequestListKey,
2223
shownPullRequestListPages,
2324
pullRequestListRowsAreEqual,
25+
withAnsweredPullRequestStats,
26+
withListedPullRequests,
2427
withShownPullRequestStats,
2528
withoutScratchProjectScope,
2629
} from "./pullRequestList";
@@ -435,3 +438,37 @@ describe("shown PR diff stats", () => {
435438
expect(filled[1]).toBe(rows[1]);
436439
});
437440
});
441+
442+
describe("cached PR diff stats", () => {
443+
const stat = (number: number, additions: number) => ({
444+
projectId: "project" as PullRequestListEntry["projectId"],
445+
repository: "org/repo",
446+
number,
447+
additions,
448+
deletions: 0,
449+
});
450+
451+
it("drops a row's stat and refreshes its stats query when its updatedAt moves", () => {
452+
const query = {
453+
refs: [1, 2].map((number) => ({
454+
projectId: stat(number, 0).projectId,
455+
repository: "org/repo",
456+
number,
457+
})),
458+
};
459+
const listed = withListedPullRequests(EMPTY_PULL_REQUEST_STATS_CACHE, [entry(1), entry(2)]);
460+
expect(listed.refresh).toEqual([]);
461+
const answered = withAnsweredPullRequestStats(listed.cache, query, [stat(1, 5), stat(2, 7)]);
462+
expect(withListedPullRequests(answered, [entry(1), entry(2)])).toEqual({
463+
cache: answered,
464+
refresh: [],
465+
});
466+
467+
const pushed = withListedPullRequests(answered, [
468+
entry(1, { updatedAt: "2026-10-20T00:00:00Z" }),
469+
entry(2),
470+
]);
471+
expect([...pushed.cache.stats.values()]).toEqual([stat(2, 7)]);
472+
expect(pushed.refresh).toEqual([query]);
473+
});
474+
});

‎apps/mobile/src/features/pull-requests/pullRequestList.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type PullRequestListEntry,
88
type PullRequestListInput,
99
type PullRequestListResult,
10+
type PullRequestListStatsInput,
1011
} from "@t3tools/contracts";
1112
import type { PullRequestListControls } from "../../persistence/mobile-preferences";
1213

@@ -50,6 +51,71 @@ export const pullRequestStatKey = (
5051
row: Pick<PullRequestDiffStat, "projectId" | "repository" | "number">,
5152
) => `${row.projectId}:${row.repository}:${row.number}`;
5253

54+
/**
55+
* Diff stats an environment has answered, the stats query that answered each, and each row's
56+
* `updatedAt` as its list last answered it.
57+
*/
58+
export interface PullRequestStatsCache {
59+
readonly stats: ReadonlyMap<string, PullRequestDiffStat>;
60+
readonly answeredBy: ReadonlyMap<string, PullRequestListStatsInput>;
61+
readonly updatedAt: ReadonlyMap<string, string>;
62+
}
63+
64+
export const EMPTY_PULL_REQUEST_STATS_CACHE: PullRequestStatsCache = {
65+
stats: new Map(),
66+
answeredBy: new Map(),
67+
updatedAt: new Map(),
68+
};
69+
70+
/**
71+
* Records the rows a list answered. Stats carry no head, so a row whose `updatedAt` moved (a push,
72+
* among other changes) drops its cached stat, and the stats queries that answered it are returned
73+
* to refresh: one can still be fresh and would otherwise answer the row's next read with the old
74+
* counts.
75+
*/
76+
export function withListedPullRequests(
77+
cache: PullRequestStatsCache,
78+
entries: readonly Pick<
79+
PullRequestListEntry,
80+
"projectId" | "repository" | "number" | "updatedAt"
81+
>[],
82+
): {
83+
readonly cache: PullRequestStatsCache;
84+
readonly refresh: readonly PullRequestListStatsInput[];
85+
} {
86+
const moved = entries.filter(
87+
(entry) => cache.updatedAt.get(pullRequestStatKey(entry)) !== entry.updatedAt,
88+
);
89+
if (!moved.length) return { cache, refresh: [] };
90+
const stats = new Map(cache.stats);
91+
const answeredBy = new Map(cache.answeredBy);
92+
const updatedAt = new Map(cache.updatedAt);
93+
const refresh = new Set<PullRequestListStatsInput>();
94+
for (const entry of moved) {
95+
const key = pullRequestStatKey(entry);
96+
const query = answeredBy.get(key);
97+
if (query) refresh.add(query);
98+
stats.delete(key);
99+
answeredBy.delete(key);
100+
updatedAt.set(key, entry.updatedAt);
101+
}
102+
return { cache: { stats, answeredBy, updatedAt }, refresh: [...refresh] };
103+
}
104+
105+
export function withAnsweredPullRequestStats(
106+
cache: PullRequestStatsCache,
107+
input: PullRequestListStatsInput,
108+
answered: readonly PullRequestDiffStat[],
109+
): PullRequestStatsCache {
110+
const stats = new Map(cache.stats);
111+
const answeredBy = new Map(cache.answeredBy);
112+
for (const row of answered) {
113+
stats.set(pullRequestStatKey(row), row);
114+
answeredBy.set(pullRequestStatKey(row), input);
115+
}
116+
return { ...cache, stats, answeredBy };
117+
}
118+
53119
/**
54120
* Fills rows that have no diff stat yet from the stats answers on screen. Returns `entries`
55121
* itself when no row changes, so the list keeps its identity across renders.

‎apps/mobile/src/features/pull-requests/usePullRequestList.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function usePullRequestList(targets: readonly ListTarget[]) {
185185
pages: {
186186
...pages,
187187
entries: pages.entries.map((entry) => {
188-
const stat = stats.get(statKey(entry));
188+
const stat = stats.stats.get(statKey(entry));
189189
return stat
190190
? { ...entry, additions: stat.additions, deletions: stat.deletions }
191191
: entry;

0 commit comments

Comments
 (0)