GeezerVison is showing github.com — perf(shell): cold connects skip older settled threads, 93% of the she… · pingdotgg/t3code@e57c093
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/home/HomeScreen.tsx +21-4Lines changed: 21 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -291,8 +291,6 @@ export function HomeScreen(props: HomeScreenProps) { | 291 | 291 | ) | 292 | 292 | ? [props.selectedEnvironmentId] | 293 | 293 | : []; | 294 | | - const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery); | 295 | | - const threadSearchMatchByKey = useThreadListSearchMatches(props.threads, threadSearch); | 296 | 294 | const handleSwipeableWillOpen = (methods: SwipeableMethods) => { | 297 | 295 | if (openSwipeableRef.current !== methods) { | 298 | 296 | openSwipeableRef.current?.close(); | @@ -380,6 +378,14 @@ export function HomeScreen(props: HomeScreenProps) { | 380 | 378 |
| 381 | 379 | const v2ProjectScopeKey = props.selectedProjectKey; | 382 | 380 | 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); | 383 | 389 | const v2ProjectTitleByProjectKey = new Map( | 384 | 390 | projectScopes.flatMap((scope) => | 385 | 391 | scope.projectRefs.map( | @@ -447,6 +453,7 @@ export function HomeScreen(props: HomeScreenProps) { | 447 | 453 | layout: threadListV2Layout, | 448 | 454 | items: threadListV2Items, | 449 | 455 | contentOnlyThreadKeys, | | 456 | + olderSettledShelf, | 450 | 457 | } = useThreadListV2({ | 451 | 458 | threads: props.threads, | 452 | 459 | pendingTasks: props.pendingTasks, | @@ -658,7 +665,9 @@ export function HomeScreen(props: HomeScreenProps) { | 658 | 665 | }; | 659 | 666 |
| 660 | 667 | 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; | 662 | 671 | const selectedEnvironmentLabel = | 663 | 672 | props.selectedEnvironmentId === null | 664 | 673 | ? null | @@ -806,7 +815,15 @@ export function HomeScreen(props: HomeScreenProps) { | 806 | 815 | settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0 ? ( | 807 | 816 | <ThreadListV2ShowMoreRow | 808 | 817 | 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 | + }} | 810 | 827 | /> | 811 | 828 | ) : null | 812 | 829 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/keyboard/CommandPalette.tsx +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -241,7 +241,21 @@ export function CommandPalette(props: { | 241 | 241 | .map((environment) => environment.environmentId), | 242 | 242 | [environments], | 243 | 243 | ); | 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 | + ); | 245 | 259 | const contentMatchByKey = useMemo( | 246 | 260 | () => | 247 | 261 | new Map( | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/prompt-links/usePromptLinkResolver.ts +69-17Lines changed: 69 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,7 @@ import * as Dialog from "../../components/ui/Dialog"; | 2 | 2 | import { StackActions, useNavigation } from "@react-navigation/native"; | 3 | 3 | import { availableScratchWorkspaceRoot } from "@t3tools/client-runtime/operations/projects"; | 4 | 4 | import { | 5 | | - findPromptLinkProject, | | 5 | + findPromptLinkProjects, | 6 | 6 | findPromptLinkPullRequestThread, | 7 | 7 | resolvePromptLinkModelSelection, | 8 | 8 | } from "@t3tools/client-runtime/prompt-links"; | @@ -11,7 +11,7 @@ import { | 11 | 11 | squashAtomCommandFailure, | 12 | 12 | } from "@t3tools/client-runtime/state/runtime"; | 13 | 13 | import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell"; | 14 | | -import type { EnvironmentId } from "@t3tools/contracts"; | | 14 | +import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; | 15 | 15 | import { | 16 | 16 | parseNewThreadLink, | 17 | 17 | type LinkedPrompt, | @@ -63,6 +63,9 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>> | 63 | 63 | const loadPullRequest = useAtomQueryRunner(composerPullRequests.detail, { | 64 | 64 | reportFailure: false, | 65 | 65 | }); | | 66 | + const loadLinkedThreads = useAtomQueryRunner(composerPullRequests.linkedThreadsUncached, { | | 67 | + reportFailure: false, | | 68 | + }); | 66 | 69 | const search = promptLinkSearchFromParams(params); | 67 | 70 | // Wait for cold-launch shells or existing repositories may be offered for cloning. | 68 | 71 | const waitingForShells = | @@ -89,6 +92,61 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>> | 89 | 92 | return resolved?.exact !== true; | 90 | 93 | }; | 91 | 94 |
| | 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 | + | | 114 | + // A pull request's thread can be an older settled thread no shell holds, so ask every | | 115 | + // connected environment with the repository. A lookup on another one would wait forever. | | 116 | + const findServerPullRequestThread = async ( | | 117 | + projects: ReadonlyArray<EnvironmentProject>, | | 118 | + pullRequest: PromptLinkPullRequest, | | 119 | + ) => { | | 120 | + const connected = new Set( | | 121 | + connectedEnvironments | | 122 | + .filter((environment) => environment.connectionState === "connected") | | 123 | + .map((environment) => environment.environmentId), | | 124 | + ); | | 125 | + const lookups = projects | | 126 | + .filter((project) => connected.has(project.environmentId)) | | 127 | + .map(async (project) => { | | 128 | + const linked = await loadLinkedThreads({ | | 129 | + environmentId: project.environmentId, | | 130 | + input: { | | 131 | + projectId: project.id, | | 132 | + repository: promptLinkRepositoryName(pullRequest), | | 133 | + number: pullRequest.number, | | 134 | + }, | | 135 | + }); | | 136 | + const thread = | | 137 | + linked._tag === "Success" | | 138 | + ? linked.value.threads.find((candidate) => candidate.archivedAt === null) | | 139 | + : undefined; | | 140 | + return thread && { environmentId: project.environmentId, id: thread.id }; | | 141 | + }); | | 142 | + // The most recent project wins without waiting for the lookups after it. | | 143 | + for (const lookup of lookups) { | | 144 | + const thread = await lookup; | | 145 | + if (thread) return thread; | | 146 | + } | | 147 | + return undefined; | | 148 | + }; | | 149 | + | 92 | 150 | const openProjectDraft = async (project: EnvironmentProject, request: LinkedDraftRequest) => { | 93 | 151 | try { | 94 | 152 | await waitForComposerDraftsLoaded(); | @@ -234,19 +292,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>> | 234 | 292 | if (link.kind === "pull-request") { | 235 | 293 | const thread = findPromptLinkPullRequestThread(threads, link.pullRequest); | 236 | 294 | 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 | | - } | | 295 | + openThread(thread, link.prompt); | 250 | 296 | return; | 251 | 297 | } | 252 | 298 | } | @@ -263,14 +309,20 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>> | 263 | 309 | } | 264 | 310 | const activityOf = (project: EnvironmentProject) => | 265 | 311 | lastActivity.get(`${project.environmentId}:${project.id}`) ?? ""; | 266 | | - const project = findPromptLinkProject( | | 312 | + const projects = findPromptLinkProjects( | 267 | 313 | flow.projectScopes | 268 | 314 | .flatMap((scope) => scope.projects) | 269 | 315 | .sort((left, right) => activityOf(right).localeCompare(activityOf(left))), | 270 | 316 | repository, | 271 | 317 | ); | | 318 | + const project = projects[0]; | 272 | 319 | if (project) { | 273 | | - void openProjectDraft(project, request); | | 320 | + const { pullRequest } = request; | | 321 | + void (async () => { | | 322 | + const thread = pullRequest && (await findServerPullRequestThread(projects, pullRequest)); | | 323 | + if (thread) openThread(thread, request.prompt); | | 324 | + else await openProjectDraft(project, request); | | 325 | + })(); | 274 | 326 | return; | 275 | 327 | } | 276 | 328 | Dialog.alert(`You don't have ${promptLinkRepositoryName(repository)}`, undefined, [ | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/settings/SettingsProjectOverviewRouteScreen.tsx +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,6 +42,7 @@ import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-en | 42 | 42 | import { leaveSettingsPage } from "./settings-navigation"; | 43 | 43 | import { workspaceHasColumns } from "../workspace/workspace-selection-store"; | 44 | 44 | import { DEFAULT_SETTINGS_PAGE } from "../workspace/workspace-tab-navigation"; | | 45 | +import { readUnloadedThreadCount } from "../../state/olderSettledShelf"; | 45 | 46 |
| 46 | 47 | export function SettingsProjectOverviewRouteScreen() { | 47 | 48 | const insets = useSafeAreaInsets(); | @@ -175,6 +176,7 @@ function ProjectOverviewContent(props: { | 175 | 176 | hasOtherMembers: props.hasOtherMembers, | 176 | 177 | displayName, | 177 | 178 | threads, | | 179 | + unloadedThreadCount: readUnloadedThreadCount(members, threads), | 178 | 180 | }); | 179 | 181 | Dialog.confirm({ | 180 | 182 | title: plan.targetKind === "checkout" ? "Remove checkout" : "Remove project", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadArrangementSheet.tsx +53-5Lines changed: 53 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,8 @@ import { SymbolView } from "../../components/ui/AppSymbol"; | 16 | 16 | import { scopedThreadKey } from "../../lib/scopedEntities"; | 17 | 17 | import { environmentServerConfigsAtom } from "../../state/server"; | 18 | 18 | import { environmentThreadShells } from "../../state/threads"; | | 19 | +import { sortSettledThreads } from "@t3tools/client-runtime/state/thread-sort"; | | 20 | +import { useOlderSettledShelf, useOlderSettledShelfGrowth } from "../../state/olderSettledShelf"; | 19 | 21 | import { | 20 | 22 | pendingThreadOrderAtom, | 21 | 23 | threadDropBusyAtom, | @@ -28,7 +30,12 @@ import { | 28 | 30 | threadDragAction, | 29 | 31 | type ThreadMoveDestination, | 30 | 32 | } 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"; | 32 | 39 | import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences"; | 33 | 40 |
| 34 | 41 | const ROW_HEIGHT = 56; | @@ -40,6 +47,8 @@ type Row = { | 40 | 47 | key: string; | 41 | 48 | section: Section; | 42 | 49 | thread?: EnvironmentThreadShell; | | 50 | + /** The Settled section's "Show more" row. */ | | 51 | + more?: true; | 43 | 52 | offset: number; | 44 | 53 | height: number; | 45 | 54 | }; | @@ -158,6 +167,15 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) { | 158 | 167 | const { workingShelfEnabled } = useThreadListV2ShelfPreferences(); | 159 | 168 | const [now, setNow] = useState(() => new Date().toISOString()); | 160 | 169 | 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 | + }); | 161 | 179 | useEffect(() => { | 162 | 180 | const wakeAt = Math.min( | 163 | 181 | ...threads.flatMap((thread) => { | @@ -201,9 +219,13 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) { | 201 | 219 | ? sortInboxThreadsByReturn(active, threadListInboxReturns.returnedAt) | 202 | 220 | : active, | 203 | 221 | snoozed: parked.filter((thread) => effectiveSnoozed(thread, { now })), | 204 | | - settled: parked.filter((thread) => !effectiveSnoozed(thread, { now })), | | 222 | + settled: sortSettledThreads(parked.filter((thread) => !effectiveSnoozed(thread, { now }))), | 205 | 223 | }; | 206 | 224 | }, [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); | 207 | 229 | const planners = useMemo(() => { | 208 | 230 | const planner = (section: "pinned" | "active") => | 209 | 231 | createThreadMovePlanner({ | @@ -232,13 +254,17 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) { | 232 | 254 | result.push({ key: section, section, offset, height: HEADER_HEIGHT }); | 233 | 255 | offset += HEADER_HEIGHT; | 234 | 256 | 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]) { | 236 | 258 | result.push({ key: keyOf(thread), section, thread, offset, height: ROW_HEIGHT }); | 237 | 259 | offset += ROW_HEIGHT; | 238 | 260 | } | | 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 | + } | 239 | 265 | } | 240 | 266 | return result; | 241 | | - }, [sections, expanded]); | | 267 | + }, [sections, expanded, visibleSettled, settledCount]); | 242 | 268 | const list = useRef<FlatList<Row>>(null); | 243 | 269 | const geometry = useRef({ height: 0, offset: 0 }); | 244 | 270 | const drag = useRef<Drag | null>(null); | @@ -507,6 +533,25 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) { | 507 | 533 | }} | 508 | 534 | /> | 509 | 535 | </> | | 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> | 510 | 555 | ) : ( | 511 | 556 | <Pressable | 512 | 557 | disabled={item.section === "pinned" || item.section === "active"} | @@ -519,7 +564,10 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) { | 519 | 564 | > | 520 | 565 | <Text className="text-sm font-t3-semibold text-foreground-muted"> | 521 | 566 | {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 | + ) | 523 | 571 | </Text> | 524 | 572 | </Pressable> | 525 | 573 | )} | |
|