Skip to content

Commit 0e5f22b

Browse files
t3dotggclaude
andcommitted
perf(shell): cold connects skip older settled threads
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b808f7f commit 0e5f22b

60 files changed

Lines changed: 3249 additions & 250 deletions

Some content is hidden

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

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ export function HomeScreen(props: HomeScreenProps) {
291291
)
292292
? [props.selectedEnvironmentId]
293293
: [];
294-
const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
295-
const threadSearchMatchByKey = useThreadListSearchMatches(props.threads, threadSearch);
296294
const handleSwipeableWillOpen = (methods: SwipeableMethods) => {
297295
if (openSwipeableRef.current !== methods) {
298296
openSwipeableRef.current?.close();
@@ -380,6 +378,14 @@ export function HomeScreen(props: HomeScreenProps) {
380378

381379
const v2ProjectScopeKey = props.selectedProjectKey;
382380
const v2ScopedProjectGroup = findHomeProjectScope(projectScopes, v2ProjectScopeKey);
381+
const threadSearch = useThreadSearch(
382+
searchEnvironmentIds,
383+
props.searchQuery,
384+
v2ScopedProjectGroup === null
385+
? {}
386+
: { projectIds: v2ScopedProjectGroup.projectRefs.map((ref) => ref.projectId) },
387+
);
388+
const threadSearchMatchByKey = useThreadListSearchMatches(props.threads, threadSearch);
383389
const v2ProjectTitleByProjectKey = new Map(
384390
projectScopes.flatMap((scope) =>
385391
scope.projectRefs.map(
@@ -447,6 +453,7 @@ export function HomeScreen(props: HomeScreenProps) {
447453
layout: threadListV2Layout,
448454
items: threadListV2Items,
449455
contentOnlyThreadKeys,
456+
olderSettledShelf,
450457
} = useThreadListV2({
451458
threads: props.threads,
452459
pendingTasks: props.pendingTasks,
@@ -658,7 +665,9 @@ export function HomeScreen(props: HomeScreenProps) {
658665
};
659666

660667
const hasAnyThreads =
661-
props.threads.some((thread) => thread.archivedAt === null) || props.pendingTasks.length > 0;
668+
props.threads.some((thread) => thread.archivedAt === null) ||
669+
props.pendingTasks.length > 0 ||
670+
threadListV2Layout.settledCount > 0;
662671
const selectedEnvironmentLabel =
663672
props.selectedEnvironmentId === null
664673
? null
@@ -806,7 +815,15 @@ export function HomeScreen(props: HomeScreenProps) {
806815
settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0 ? (
807816
<ThreadListV2ShowMoreRow
808817
hiddenCount={threadListV2Layout.hiddenSettledCount}
809-
onPress={showMoreSettled}
818+
{...(olderSettledShelf.loading
819+
? { state: "loading" as const }
820+
: olderSettledShelf.failed
821+
? { state: "failed" as const }
822+
: {})}
823+
onPress={() => {
824+
olderSettledShelf.retry();
825+
showMoreSettled();
826+
}}
810827
/>
811828
) : null
812829
}

‎apps/mobile/src/features/keyboard/CommandPalette.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,21 @@ export function CommandPalette(props: {
241241
.map((environment) => environment.environmentId),
242242
[environments],
243243
);
244-
const search = useThreadSearch(searchEnvironmentIds, query.startsWith(">") ? "" : query);
244+
// The palette matches environment names when there are several; older rows must match the same.
245+
const environmentLabels =
246+
environments.length > 1
247+
? Object.fromEntries(
248+
searchEnvironmentIds.flatMap((environmentId) => {
249+
const label = savedConnectionsById[environmentId]?.environmentLabel;
250+
return label === undefined ? [] : [[environmentId, label]];
251+
}),
252+
)
253+
: undefined;
254+
const search = useThreadSearch(
255+
searchEnvironmentIds,
256+
query.startsWith(">") ? "" : query,
257+
environmentLabels === undefined ? {} : { environmentLabels },
258+
);
245259
const contentMatchByKey = useMemo(
246260
() =>
247261
new Map(

‎apps/mobile/src/features/prompt-links/usePromptLinkResolver.ts‎

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
squashAtomCommandFailure,
1212
} from "@t3tools/client-runtime/state/runtime";
1313
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
14-
import type { EnvironmentId } from "@t3tools/contracts";
14+
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
1515
import {
1616
parseNewThreadLink,
1717
type LinkedPrompt,
@@ -63,6 +63,9 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
6363
const loadPullRequest = useAtomQueryRunner(composerPullRequests.detail, {
6464
reportFailure: false,
6565
});
66+
const loadLinkedThreads = useAtomQueryRunner(composerPullRequests.linkedThreads, {
67+
reportFailure: false,
68+
});
6669
const search = promptLinkSearchFromParams(params);
6770
// Wait for cold-launch shells or existing repositories may be offered for cloning.
6871
const waitingForShells =
@@ -89,7 +92,45 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
8992
return resolved?.exact !== true;
9093
};
9194

95+
const openThread = (
96+
thread: { readonly environmentId: EnvironmentId; readonly id: ThreadId },
97+
prompt: LinkedDraftRequest["prompt"],
98+
) => {
99+
(navigation.getParent() ?? navigation).dispatch(
100+
StackActions.replace("Thread", {
101+
environmentId: String(thread.environmentId),
102+
threadId: String(thread.id),
103+
}),
104+
);
105+
if (prompt) {
106+
void applyLinkedPromptToThreadDraft(
107+
scopedThreadKey(thread.environmentId, thread.id),
108+
prompt,
109+
promptLinkNotice({ hiddenCharacters: prompt.hiddenCharacters }),
110+
);
111+
}
112+
};
113+
92114
const openProjectDraft = async (project: EnvironmentProject, request: LinkedDraftRequest) => {
115+
if (request.pullRequest) {
116+
// The pull request's thread can be an older settled thread the shell left out.
117+
const linked = await loadLinkedThreads({
118+
environmentId: project.environmentId,
119+
input: {
120+
projectId: project.id,
121+
repository: promptLinkRepositoryName(request.pullRequest),
122+
number: request.pullRequest.number,
123+
},
124+
});
125+
const thread =
126+
linked._tag === "Success"
127+
? linked.value.threads.find((candidate) => candidate.archivedAt === null)
128+
: undefined;
129+
if (thread) {
130+
openThread({ environmentId: project.environmentId, id: thread.id }, request.prompt);
131+
return;
132+
}
133+
}
93134
try {
94135
await waitForComposerDraftsLoaded();
95136
} catch {
@@ -234,19 +275,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
234275
if (link.kind === "pull-request") {
235276
const thread = findPromptLinkPullRequestThread(threads, link.pullRequest);
236277
if (thread) {
237-
(navigation.getParent() ?? navigation).dispatch(
238-
StackActions.replace("Thread", {
239-
environmentId: String(thread.environmentId),
240-
threadId: String(thread.id),
241-
}),
242-
);
243-
if (link.prompt) {
244-
void applyLinkedPromptToThreadDraft(
245-
scopedThreadKey(thread.environmentId, thread.id),
246-
link.prompt,
247-
promptLinkNotice({ hiddenCharacters: link.prompt.hiddenCharacters }),
248-
);
249-
}
278+
openThread(thread, link.prompt);
250279
return;
251280
}
252281
}

‎apps/mobile/src/features/settings/SettingsProjectOverviewRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-en
4242
import { leaveSettingsPage } from "./settings-navigation";
4343
import { workspaceHasColumns } from "../workspace/workspace-selection-store";
4444
import { DEFAULT_SETTINGS_PAGE } from "../workspace/workspace-tab-navigation";
45+
import { readUnloadedThreadCount } from "../../state/olderSettledShelf";
4546

4647
export function SettingsProjectOverviewRouteScreen() {
4748
const insets = useSafeAreaInsets();
@@ -175,6 +176,7 @@ function ProjectOverviewContent(props: {
175176
hasOtherMembers: props.hasOtherMembers,
176177
displayName,
177178
threads,
179+
unloadedThreadCount: readUnloadedThreadCount(members, threads),
178180
});
179181
Dialog.confirm({
180182
title: plan.targetKind === "checkout" ? "Remove checkout" : "Remove project",

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

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { SymbolView } from "../../components/ui/AppSymbol";
1616
import { scopedThreadKey } from "../../lib/scopedEntities";
1717
import { environmentServerConfigsAtom } from "../../state/server";
1818
import { environmentThreadShells } from "../../state/threads";
19+
import { sortSettledThreads } from "@t3tools/client-runtime/state/thread-sort";
20+
import { useOlderSettledShelf, useOlderSettledShelfGrowth } from "../../state/olderSettledShelf";
1921
import {
2022
pendingThreadOrderAtom,
2123
threadDropBusyAtom,
@@ -28,7 +30,12 @@ import {
2830
threadDragAction,
2931
type ThreadMoveDestination,
3032
} from "./threadOrder";
31-
import { getThreadListV2OrderedSection, threadListInboxReturns } from "./threadListV2";
33+
import {
34+
getThreadListV2OrderedSection,
35+
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
36+
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
37+
threadListInboxReturns,
38+
} from "./threadListV2";
3239
import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
3340

3441
const ROW_HEIGHT = 56;
@@ -40,6 +47,8 @@ type Row = {
4047
key: string;
4148
section: Section;
4249
thread?: EnvironmentThreadShell;
50+
/** The Settled section's "Show more" row. */
51+
more?: true;
4352
offset: number;
4453
height: number;
4554
};
@@ -158,6 +167,15 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
158167
const { workingShelfEnabled } = useThreadListV2ShelfPreferences();
159168
const [now, setNow] = useState(() => new Date().toISOString());
160169
const [expanded, setExpanded] = useState({ snoozed: false, settled: false });
170+
const [settledVisibleCount, setSettledVisibleCount] = useState(
171+
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
172+
);
173+
// Older settled threads load in pages, as in the thread list.
174+
const olderSettledShelf = useOlderSettledShelf({
175+
scopes: [...configs.keys()].map((environmentId) => ({ environmentId, projectIds: null })),
176+
expanded: expanded.settled,
177+
visibleCount: settledVisibleCount,
178+
});
161179
useEffect(() => {
162180
const wakeAt = Math.min(
163181
...threads.flatMap((thread) => {
@@ -201,9 +219,13 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
201219
? sortInboxThreadsByReturn(active, threadListInboxReturns.returnedAt)
202220
: active,
203221
snoozed: parked.filter((thread) => effectiveSnoozed(thread, { now })),
204-
settled: parked.filter((thread) => !effectiveSnoozed(thread, { now })),
222+
settled: sortSettledThreads(parked.filter((thread) => !effectiveSnoozed(thread, { now }))),
205223
};
206224
}, [threads, configs, now, queuedThreadKeys, pendingOrder, workingShelfEnabled]);
225+
const listedSettled = sections.settled.filter(olderSettledShelf.isListed);
226+
useOlderSettledShelfGrowth(olderSettledShelf, listedSettled);
227+
const visibleSettled = listedSettled.slice(0, settledVisibleCount);
228+
const settledCount = sections.settled.length + olderSettledShelf.unloadedCount(threads);
207229
const planners = useMemo(() => {
208230
const planner = (section: "pinned" | "active") =>
209231
createThreadMovePlanner({
@@ -232,13 +254,17 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
232254
result.push({ key: section, section, offset, height: HEADER_HEIGHT });
233255
offset += HEADER_HEIGHT;
234256
if ((section === "snoozed" || section === "settled") && !expanded[section]) continue;
235-
for (const thread of sections[section]) {
257+
for (const thread of section === "settled" ? visibleSettled : sections[section]) {
236258
result.push({ key: keyOf(thread), section, thread, offset, height: ROW_HEIGHT });
237259
offset += ROW_HEIGHT;
238260
}
261+
if (section === "settled" && settledCount > visibleSettled.length) {
262+
result.push({ key: "settled-more", section, more: true, offset, height: ROW_HEIGHT });
263+
offset += ROW_HEIGHT;
264+
}
239265
}
240266
return result;
241-
}, [sections, expanded]);
267+
}, [sections, expanded, visibleSettled, settledCount]);
242268
const list = useRef<FlatList<Row>>(null);
243269
const geometry = useRef({ height: 0, offset: 0 });
244270
const drag = useRef<Drag | null>(null);
@@ -507,6 +533,25 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
507533
}}
508534
/>
509535
</>
536+
) : item.more ? (
537+
<Pressable
538+
disabled={olderSettledShelf.loading}
539+
className="flex-1 justify-center self-stretch"
540+
onPress={() => {
541+
olderSettledShelf.retry();
542+
setSettledVisibleCount(
543+
(count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT,
544+
);
545+
}}
546+
>
547+
<Text className="text-sm text-foreground-muted">
548+
{olderSettledShelf.loading
549+
? "Loading"
550+
: olderSettledShelf.failed
551+
? "Could not load older threads. Retry"
552+
: `Show more (${settledCount - visibleSettled.length} settled hidden)`}
553+
</Text>
554+
</Pressable>
510555
) : (
511556
<Pressable
512557
disabled={item.section === "pinned" || item.section === "active"}
@@ -519,7 +564,10 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
519564
>
520565
<Text className="text-sm font-t3-semibold text-foreground-muted">
521566
{item.section[0]!.toUpperCase() + item.section.slice(1)} (
522-
{sections[item.section].length})
567+
{item.section === "settled"
568+
? settledCount
569+
: sections[item.section].length}
570+
)
523571
</Text>
524572
</Pressable>
525573
)}

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ import {
8181

8282
type SidebarListItem =
8383
| ThreadListV2ListItem
84-
| { readonly type: "v2-show-more"; readonly key: string; readonly hiddenCount: number };
84+
| {
85+
readonly type: "v2-show-more";
86+
readonly key: string;
87+
readonly hiddenCount: number;
88+
readonly state?: "loading" | "failed";
89+
};
8590

8691
const SIDEBAR_STICKY_HEADER_HEIGHT = 106;
8792

@@ -182,10 +187,6 @@ function ThreadNavigationSidebarPane(
182187
)
183188
? [options.selectedEnvironmentId]
184189
: [];
185-
const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
186-
// This map reaches LegendList's extraData, which re-renders every row whenever it changes
187-
// identity; the hook keeps it stable.
188-
const threadSearchMatchByKey = useThreadListSearchMatches(threads, threadSearch);
189190
const projectScopeKey = options.selectedProjectKey;
190191
const resolvedProjectKey = resolveScratchProjectScopeKey(projectScopeKey, projects, {
191192
sidebarProjectGroupingMode: options.projectGroupingMode,
@@ -226,6 +227,16 @@ function ThreadNavigationSidebarPane(
226227
);
227228
const selectedProjectScope =
228229
projectScopes.find((scope) => scope.key === resolvedProjectKey) ?? null;
230+
const threadSearch = useThreadSearch(
231+
searchEnvironmentIds,
232+
props.searchQuery,
233+
selectedProjectScope === null
234+
? {}
235+
: { projectIds: selectedProjectScope.projectRefs.map((ref) => ref.projectId) },
236+
);
237+
// This map reaches LegendList's extraData, which re-renders every row whenever it changes
238+
// identity; the hook keeps it stable.
239+
const threadSearchMatchByKey = useThreadListSearchMatches(threads, threadSearch);
229240
const selectedProjectKey = selectedProjectScope?.key ?? null;
230241
const projectByKey = useMemo(() => {
231242
const map = new Map<string, EnvironmentProject>();
@@ -283,6 +294,7 @@ function ThreadNavigationSidebarPane(
283294
layout: threadListV2Layout,
284295
items: threadListV2Items,
285296
contentOnlyThreadKeys,
297+
olderSettledShelf,
286298
} = useThreadListV2({
287299
threads,
288300
pendingTasks,
@@ -326,6 +338,11 @@ function ThreadNavigationSidebarPane(
326338
type: "v2-show-more",
327339
key: "v2-show-more",
328340
hiddenCount: threadListV2Layout.hiddenSettledCount,
341+
...(olderSettledShelf.loading
342+
? { state: "loading" as const }
343+
: olderSettledShelf.failed
344+
? { state: "failed" as const }
345+
: {}),
329346
},
330347
]
331348
: threadListV2Items;
@@ -472,7 +489,7 @@ function ThreadNavigationSidebarPane(
472489
return threadListV2ListItemsAreEqual(previous, item);
473490
}
474491
if (previous.type === "v2-show-more" && item.type === "v2-show-more") {
475-
return previous.hiddenCount === item.hiddenCount;
492+
return previous.hiddenCount === item.hiddenCount && previous.state === item.state;
476493
}
477494
return false;
478495
};
@@ -643,7 +660,11 @@ function ThreadNavigationSidebarPane(
643660
<ThreadListV2ShowMoreRow
644661
pane="sidebar"
645662
hiddenCount={item.hiddenCount}
646-
onPress={showMoreSettled}
663+
{...(item.state === undefined ? {} : { state: item.state })}
664+
onPress={() => {
665+
olderSettledShelf.retry();
666+
showMoreSettled();
667+
}}
647668
/>
648669
);
649670
}

0 commit comments

Comments
 (0)