diff --git a/apps/mobile/src/App.tsx b/apps/mobile/src/App.tsx index 835f54491f..06bd4bc577 100644 --- a/apps/mobile/src/App.tsx +++ b/apps/mobile/src/App.tsx @@ -13,7 +13,10 @@ import { ConfirmDialogHost } from "./components/ConfirmDialogHost"; import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider"; import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene"; import { IncomingShareProvider } from "./features/sharing/IncomingShareProvider"; -import { AppearancePreferencesProvider } from "./features/settings/appearance/AppearancePreferencesProvider"; +import { + AppearancePreferencesProvider, + useAppearancePreferences, +} from "./features/settings/appearance/AppearancePreferencesProvider"; import { RootStack } from "./Stack"; import { appAtomRegistry } from "./state/atom-registry"; import { OverlayPortalHost } from "./components/OverlayPortal"; @@ -26,6 +29,10 @@ if (process.env.EXPO_PUBLIC_SHOWCASE === "1") { prepareNativeShowcaseCapture(); } +void SplashScreen.preventAutoHideAsync().catch(() => { + // The native module can be unavailable in non-native test environments. +}); + const appLinking = { prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"], // The Expo dev client launches the app via @@ -40,18 +47,25 @@ const appLinking = { const Navigation = createStaticNavigation(RootStack); +function SplashScreenCoordinator() { + const { isReady } = useAppearancePreferences(); + + useEffect(() => { + if (isReady) void SplashScreen.hide(); + }, [isReady]); + + return null; +} + export default function App() { const colorScheme = useColorScheme(); const statusBarBg = useThemeColor("--color-status-bar"); - useEffect(() => { - SplashScreen.hide(); - }, []); - return ( + diff --git a/apps/mobile/src/features/home/HomeHeader.tsx b/apps/mobile/src/features/home/HomeHeader.tsx index cf9cf378ed..8ad91c6b35 100644 --- a/apps/mobile/src/features/home/HomeHeader.tsx +++ b/apps/mobile/src/features/home/HomeHeader.tsx @@ -1,8 +1,4 @@ -import type { - EnvironmentId, - SidebarProjectGroupingMode, - SidebarThreadSortOrder, -} from "@t3tools/contracts"; +import type { EnvironmentId, SidebarThreadSortOrder } from "@t3tools/contracts"; import type { MenuAction } from "@react-native-menu/menu"; import { useAtomValue } from "@effect/atom-react"; import { AsyncResult } from "effect/unstable/reactivity"; @@ -28,7 +24,6 @@ import { } from "./home-list-filter-menu"; import { hasCustomHomeListOptions, - PROJECT_GROUPING_OPTIONS, PROJECT_SORT_OPTIONS, THREAD_SORT_OPTIONS, } from "./home-list-options"; @@ -43,13 +38,11 @@ export function HomeHeader(props: { readonly selectedProjectKey: string | null; readonly projectSortOrder: HomeProjectSortOrder; readonly threadSortOrder: SidebarThreadSortOrder; - readonly projectGroupingMode: SidebarProjectGroupingMode; readonly onSearchQueryChange: (query: string) => void; readonly onEnvironmentChange: (environmentId: EnvironmentId | null) => void; readonly onProjectChange: (projectKey: string | null) => void; readonly onProjectSortOrderChange: (sortOrder: HomeProjectSortOrder) => void; readonly onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void; - readonly onProjectGroupingModeChange: (mode: SidebarProjectGroupingMode) => void; readonly onOpenSettings: () => void; readonly onStartNewTask: () => void; }) { @@ -143,20 +136,10 @@ function AndroidHomeHeader(props: HomeHeaderProps) { state: checkedMenuState(props.threadSortOrder === option.value), })), }, - { - id: "project-grouping", - title: "Group projects", - subactions: PROJECT_GROUPING_OPTIONS.map((option) => ({ - id: `project-grouping:${option.value}`, - title: option.label, - state: checkedMenuState(props.projectGroupingMode === option.value), - })), - }, ] satisfies MenuAction[])), ], [ props.environments, - props.projectGroupingMode, props.projectSortOrder, props.projects, props.selectedEnvironmentId, @@ -210,13 +193,6 @@ function AndroidHomeHeader(props: HomeHeaderProps) { props.onThreadSortOrderChange(threadSort.value); return; } - - const grouping = PROJECT_GROUPING_OPTIONS.find( - (option) => id === `project-grouping:${option.value}`, - ); - if (grouping) { - props.onProjectGroupingModeChange(grouping.value); - } }, [props], ); @@ -480,20 +456,6 @@ function IosHomeHeader(props: HomeHeaderProps) { ))} - - - Group projects - {PROJECT_GROUPING_OPTIONS.map((option) => ( - props.onProjectGroupingModeChange(option.value)} - subtitle={option.subtitle} - > - {option.label} - - ))} - diff --git a/apps/mobile/src/features/home/HomeRouteScreen.tsx b/apps/mobile/src/features/home/HomeRouteScreen.tsx index d4b19cdb0f..da43240088 100644 --- a/apps/mobile/src/features/home/HomeRouteScreen.tsx +++ b/apps/mobile/src/features/home/HomeRouteScreen.tsx @@ -54,7 +54,6 @@ export function HomeRouteScreen() { const { options: listOptions, setSelectedEnvironmentId, - setProjectGroupingMode, setProjectSortOrder, setThreadSortOrder, } = useHomeListOptions(availableEnvironmentIds); @@ -119,11 +118,9 @@ export function HomeRouteScreen() { selectedProjectKey={selectedProjectKey} projectSortOrder={listOptions.projectSortOrder} threadSortOrder={listOptions.threadSortOrder} - projectGroupingMode={listOptions.projectGroupingMode} onEnvironmentChange={setSelectedEnvironmentId} onProjectChange={setSelectedProjectKey} onOpenSettings={() => navigation.navigate("SettingsSheet", { screen: "Settings" })} - onProjectGroupingModeChange={setProjectGroupingMode} onProjectSortOrderChange={setProjectSortOrder} onSearchQueryChange={setSearchQuery} onStartNewTask={() => navigation.navigate("NewTaskSheet", { screen: "NewTask" })} @@ -146,7 +143,6 @@ export function HomeRouteScreen() { navigation.navigate("SettingsSheet", { screen: "SettingsEnvironments" }) } onOpenSettings={() => navigation.navigate("SettingsSheet", { screen: "Settings" })} - onProjectGroupingModeChange={setProjectGroupingMode} onProjectSortOrderChange={setProjectSortOrder} onSearchQueryChange={setSearchQuery} onSelectThread={(thread) => { diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx index 41180c4864..51c51605a6 100644 --- a/apps/mobile/src/features/home/HomeScreen.tsx +++ b/apps/mobile/src/features/home/HomeScreen.tsx @@ -15,17 +15,15 @@ import type { import { useAtomSet, useAtomValue } from "@effect/atom-react"; import { AsyncResult } from "effect/unstable/reactivity"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import { ActivityIndicator, FlatList, Platform, Pressable, ScrollView, View } from "react-native"; +import { ActivityIndicator, FlatList, Platform, Pressable, View } from "react-native"; import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useThemeColor } from "../../lib/useThemeColor"; import { AppText as Text } from "../../components/AppText"; import { EmptyState } from "../../components/EmptyState"; -import { ProjectFavicon } from "../../components/ProjectFavicon"; import type { WorkspaceState } from "../../state/workspaceModel"; import type { SavedRemoteConnection } from "../../lib/connection"; -import { cn } from "../../lib/cn"; import { scopedProjectKey } from "../../lib/scopedEntities"; import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass"; import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences"; @@ -54,7 +52,12 @@ import { type HomeGroupDisplayState, type HomeListItem, } from "./homeListItems"; -import { buildHomeThreadGroups, type HomeProjectSortOrder } from "./homeThreadList"; +import { + buildHomeProjectScopes, + buildHomeThreadGroups, + sortHomeProjectScopes, + type HomeProjectSortOrder, +} from "./homeThreadList"; import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "./thread-swipe-actions"; import { WorkspaceConnectionStatus } from "./WorkspaceConnectionStatus"; import { shouldShowWorkspaceConnectionStatus } from "./workspace-connection-status"; @@ -79,7 +82,6 @@ interface HomeScreenProps { readonly onProjectChange: (projectKey: string | null) => void; readonly onProjectSortOrderChange: (sortOrder: HomeProjectSortOrder) => void; readonly onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void; - readonly onProjectGroupingModeChange: (mode: SidebarProjectGroupingMode) => void; readonly onAddConnection: () => void; readonly onOpenEnvironments: () => void; readonly onOpenSettings: () => void; @@ -334,23 +336,53 @@ export function HomeScreen(props: HomeScreenProps) { }, [props.projects]); const v2ProjectScopeKey = props.selectedProjectKey; - const setV2ProjectScopeKey = props.onProjectChange; const v2ScopeProjects = useMemo( () => - props.selectedEnvironmentId === null - ? props.projects - : props.projects.filter((project) => project.environmentId === props.selectedEnvironmentId), - [props.projects, props.selectedEnvironmentId], + sortHomeProjectScopes({ + scopes: buildHomeProjectScopes({ + projects: props.projects, + environmentId: props.selectedEnvironmentId, + projectGroupingMode: props.projectGroupingMode, + }), + threads: props.threads, + pendingTasks: props.pendingTasks, + projectSortOrder: props.projectSortOrder, + }), + [ + props.pendingTasks, + props.projectGroupingMode, + props.projects, + props.projectSortOrder, + props.selectedEnvironmentId, + props.threads, + ], ); - const v2ScopedProject = useMemo( + const v2ScopedProjectGroup = useMemo( () => v2ProjectScopeKey === null ? null : (v2ScopeProjects.find( - (project) => scopedProjectKey(project.environmentId, project.id) === v2ProjectScopeKey, + (scope) => + scope.key === v2ProjectScopeKey || + scope.projectRefs.some( + (projectRef) => + scopedProjectKey(projectRef.environmentId, projectRef.projectId) === + v2ProjectScopeKey, + ), ) ?? null), [v2ProjectScopeKey, v2ScopeProjects], ); + const v2ScopedProjectKeys = useMemo( + () => + v2ScopedProjectGroup === null + ? null + : new Set( + v2ScopedProjectGroup.projectRefs.map((projectRef) => + scopedProjectKey(projectRef.environmentId, projectRef.projectId), + ), + ), + [v2ScopedProjectGroup], + ); // Thread List v2 (beta): one flat list in creation order, no grouping. // Settled threads collapse into a recency tail below the card block. // Settled threads stay in the live shell stream (settled ≠ archived), so @@ -431,13 +463,7 @@ export function HomeScreen(props: HomeScreenProps) { return buildThreadListV2Items({ threads: props.threads.filter((thread) => thread.archivedAt === null), environmentId: props.selectedEnvironmentId, - projectRef: - v2ScopedProject === null - ? null - : { - environmentId: v2ScopedProject.environmentId, - projectId: v2ScopedProject.id, - }, + projectRefs: v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup.projectRefs, searchQuery: props.searchQuery, changeRequestStateByKey, settlementEnvironmentIds, @@ -453,7 +479,7 @@ export function HomeScreen(props: HomeScreenProps) { props.selectedEnvironmentId, props.threads, threadListV2Enabled, - v2ScopedProject, + v2ScopedProjectGroup, ]); const threadListV2Items = threadListV2Layout.items; @@ -699,9 +725,10 @@ export function HomeScreen(props: HomeScreenProps) { (pendingTask) => (props.selectedEnvironmentId === null || pendingTask.message.environmentId === props.selectedEnvironmentId) && - (v2ScopedProject === null || - (pendingTask.message.environmentId === v2ScopedProject.environmentId && - pendingTask.creation.projectId === v2ScopedProject.id)) && + (v2ScopedProjectKeys === null || + v2ScopedProjectKeys.has( + scopedProjectKey(pendingTask.message.environmentId, pendingTask.creation.projectId), + )) && (v2SearchQuery.length === 0 || pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)), ); // Project scoping lives in the header filter menu (no inline chip row on @@ -750,9 +777,9 @@ export function HomeScreen(props: HomeScreenProps) { const v2ListEmpty = v2PendingTasks.length > 0 ? null : hasSearchQuery ? ( - ) : v2ScopedProject !== null ? ( + ) : v2ScopedProjectGroup !== null ? ( ) : ( diff --git a/apps/mobile/src/features/home/home-list-filter-menu.test.ts b/apps/mobile/src/features/home/home-list-filter-menu.test.ts index 916e32671a..821eecf043 100644 --- a/apps/mobile/src/features/home/home-list-filter-menu.test.ts +++ b/apps/mobile/src/features/home/home-list-filter-menu.test.ts @@ -15,12 +15,10 @@ describe("buildHomeListFilterMenu", () => { selectedProjectKey: "environment-1:project-1", projectSortOrder: "updated_at", threadSortOrder: "updated_at", - projectGroupingMode: "repository", onEnvironmentChange: vi.fn(), onProjectChange, onProjectSortOrderChange: vi.fn(), onThreadSortOrderChange: vi.fn(), - onProjectGroupingModeChange: vi.fn(), }); const projectMenu = menu.items.find( diff --git a/apps/mobile/src/features/home/home-list-filter-menu.ts b/apps/mobile/src/features/home/home-list-filter-menu.ts index 73fda2f5d0..e9a6c37291 100644 --- a/apps/mobile/src/features/home/home-list-filter-menu.ts +++ b/apps/mobile/src/features/home/home-list-filter-menu.ts @@ -1,15 +1,7 @@ -import type { - EnvironmentId, - SidebarProjectGroupingMode, - SidebarThreadSortOrder, -} from "@t3tools/contracts"; +import type { EnvironmentId, SidebarThreadSortOrder } from "@t3tools/contracts"; import type { HomeProjectSortOrder } from "./homeThreadList"; -import { - PROJECT_GROUPING_OPTIONS, - PROJECT_SORT_OPTIONS, - THREAD_SORT_OPTIONS, -} from "./home-list-options"; +import { PROJECT_SORT_OPTIONS, THREAD_SORT_OPTIONS } from "./home-list-options"; export interface HomeListFilterMenuEnvironment { readonly environmentId: EnvironmentId; @@ -47,12 +39,10 @@ export function buildHomeListFilterMenu(props: { readonly selectedProjectKey: string | null; readonly projectSortOrder: HomeProjectSortOrder; readonly threadSortOrder: SidebarThreadSortOrder; - readonly projectGroupingMode: SidebarProjectGroupingMode; readonly onEnvironmentChange: (environmentId: EnvironmentId | null) => void; readonly onProjectChange: (projectKey: string | null) => void; readonly onProjectSortOrderChange: (sortOrder: HomeProjectSortOrder) => void; readonly onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void; - readonly onProjectGroupingModeChange: (mode: SidebarProjectGroupingMode) => void; readonly onOpenSettings?: () => void; /** False hides the sort/group submenus. Thread List v2 uses a fixed creation-order layout, so offering those controls while it silently @@ -136,17 +126,6 @@ export function buildHomeListFilterMenu(props: { onPress: () => props.onThreadSortOrderChange(option.value), })), }, - { - type: "submenu", - title: "Group projects", - items: PROJECT_GROUPING_OPTIONS.map((option) => ({ - type: "action", - title: option.label, - subtitle: option.subtitle, - state: props.projectGroupingMode === option.value ? "on" : "off", - onPress: () => props.onProjectGroupingModeChange(option.value), - })), - }, ); } diff --git a/apps/mobile/src/features/home/home-list-options.test.ts b/apps/mobile/src/features/home/home-list-options.test.ts index 651a64f6f8..ac3893956c 100644 --- a/apps/mobile/src/features/home/home-list-options.test.ts +++ b/apps/mobile/src/features/home/home-list-options.test.ts @@ -1,5 +1,4 @@ import { - DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE, DEFAULT_SIDEBAR_PROJECT_SORT_ORDER, DEFAULT_SIDEBAR_THREAD_SORT_ORDER, } from "@t3tools/contracts"; @@ -14,7 +13,6 @@ const defaults: HomeListOptions = { ? "updated_at" : DEFAULT_SIDEBAR_PROJECT_SORT_ORDER, threadSortOrder: DEFAULT_SIDEBAR_THREAD_SORT_ORDER, - projectGroupingMode: DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE, }; describe("home list options", () => { @@ -22,11 +20,10 @@ describe("home list options", () => { expect(hasCustomHomeListOptions(defaults)).toBe(false); }); - it("marks environment filters and grouping changes as customized", () => { + it("marks environment filters as customized", () => { expect( hasCustomHomeListOptions({ ...defaults, selectedEnvironmentId: "environment-1" as never }), ).toBe(true); - expect(hasCustomHomeListOptions({ ...defaults, projectGroupingMode: "separate" })).toBe(true); expect( hasCustomHomeListOptions({ ...defaults, selectedProjectKey: "environment-1:project-1" }), ).toBe(true); diff --git a/apps/mobile/src/features/home/home-list-options.ts b/apps/mobile/src/features/home/home-list-options.ts index 919cec55ef..d70e2537ba 100644 --- a/apps/mobile/src/features/home/home-list-options.ts +++ b/apps/mobile/src/features/home/home-list-options.ts @@ -4,7 +4,6 @@ import type { SidebarThreadSortOrder, } from "@t3tools/contracts"; import { - DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE, DEFAULT_SIDEBAR_PROJECT_SORT_ORDER, DEFAULT_SIDEBAR_THREAD_SORT_ORDER, } from "@t3tools/contracts"; @@ -26,9 +25,18 @@ export interface HomeListOptions { readonly selectedEnvironmentId: EnvironmentId | null; readonly projectSortOrder: HomeProjectSortOrder; readonly threadSortOrder: SidebarThreadSortOrder; +} + +export interface ResolvedHomeListOptions extends HomeListOptions { readonly projectGroupingMode: SidebarProjectGroupingMode; } +export function resolveProjectGroupingMode( + projectGroupingEnabled: boolean | undefined, +): SidebarProjectGroupingMode { + return projectGroupingEnabled === false ? "separate" : "repository"; +} + export const PROJECT_SORT_OPTIONS: ReadonlyArray<{ readonly value: HomeProjectSortOrder; readonly label: string; @@ -45,28 +53,6 @@ export const THREAD_SORT_OPTIONS: ReadonlyArray<{ { value: "created_at", label: "Created at" }, ]; -export const PROJECT_GROUPING_OPTIONS: ReadonlyArray<{ - readonly value: SidebarProjectGroupingMode; - readonly label: string; - readonly subtitle: string; -}> = [ - { - value: "repository", - label: "Group by repository", - subtitle: "Combine matching repositories across environments", - }, - { - value: "repository_path", - label: "Group by repository path", - subtitle: "Combine only matching paths within a repository", - }, - { - value: "separate", - label: "Keep separate", - subtitle: "Show every project path separately", - }, -]; - function defaultHomeListOptions(): HomeListOptions { return { selectedEnvironmentId: null, @@ -75,26 +61,34 @@ function defaultHomeListOptions(): HomeListOptions { ? "updated_at" : DEFAULT_SIDEBAR_PROJECT_SORT_ORDER, threadSortOrder: DEFAULT_SIDEBAR_THREAD_SORT_ORDER, - projectGroupingMode: DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE, }; } interface HomeListOptionsContextValue { readonly options: HomeListOptions; readonly setOptions: Dispatch>; + readonly projectGroupingMode: SidebarProjectGroupingMode; } const HomeListOptionsContext = createContext(null); /** Keeps list preferences stable while the app moves between compact and split shells. */ -export function HomeListOptionsProvider({ children }: PropsWithChildren) { +export function HomeListOptionsProvider({ + children, + projectGroupingMode, +}: PropsWithChildren<{ readonly projectGroupingMode: SidebarProjectGroupingMode }>) { const [options, setOptions] = useState(defaultHomeListOptions); - const value = useMemo(() => ({ options, setOptions }), [options]); + const value = useMemo( + () => ({ options, setOptions, projectGroupingMode }), + [options, projectGroupingMode], + ); return createElement(HomeListOptionsContext, { value }, children); } export function hasCustomHomeListOptions( - options: HomeListOptions & { readonly selectedProjectKey?: string | null }, + options: HomeListOptions & { + readonly selectedProjectKey?: string | null; + }, ): boolean { const defaultProjectSortOrder = DEFAULT_SIDEBAR_PROJECT_SORT_ORDER === "manual" @@ -104,8 +98,7 @@ export function hasCustomHomeListOptions( options.selectedEnvironmentId !== null || (options.selectedProjectKey !== null && options.selectedProjectKey !== undefined) || options.projectSortOrder !== defaultProjectSortOrder || - options.threadSortOrder !== DEFAULT_SIDEBAR_THREAD_SORT_ORDER || - options.projectGroupingMode !== DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE + options.threadSortOrder !== DEFAULT_SIDEBAR_THREAD_SORT_ORDER ); } @@ -119,10 +112,14 @@ export function useHomeListOptions(availableEnvironmentIds: ReadonlySet { setOptions((current) => ({ ...current, selectedEnvironmentId: value })); @@ -133,15 +130,10 @@ export function useHomeListOptions(availableEnvironmentIds: ReadonlySet { setOptions((current) => ({ ...current, threadSortOrder: value })); }, []); - const setProjectGroupingMode = useCallback((value: SidebarProjectGroupingMode) => { - setOptions((current) => ({ ...current, projectGroupingMode: value })); - }, []); - return { options: resolvedOptions, setSelectedEnvironmentId, setProjectSortOrder, setThreadSortOrder, - setProjectGroupingMode, } as const; } diff --git a/apps/mobile/src/features/home/homeThreadList.test.ts b/apps/mobile/src/features/home/homeThreadList.test.ts index 46d1173b0d..ffddbdcc86 100644 --- a/apps/mobile/src/features/home/homeThreadList.test.ts +++ b/apps/mobile/src/features/home/homeThreadList.test.ts @@ -5,7 +5,11 @@ import type { import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; -import { buildHomeThreadGroups } from "./homeThreadList"; +import { + buildHomeProjectScopes, + buildHomeThreadGroups, + sortHomeProjectScopes, +} from "./homeThreadList"; function makeProject( input: Partial & Pick, @@ -67,6 +71,308 @@ function buildGroups( } describe("buildHomeThreadGroups", () => { + it("builds one v2 scope for the same repository across environments", () => { + const localEnvironmentId = EnvironmentId.make("environment-local"); + const remoteEnvironmentId = EnvironmentId.make("environment-remote"); + const repositoryIdentity = { + canonicalKey: "github.com/pingdotgg/t3code", + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: "git@github.com:pingdotgg/t3code.git", + }, + }; + const projects = [ + makeProject({ + environmentId: localEnvironmentId, + id: ProjectId.make("project-local"), + title: "t3code", + repositoryIdentity, + }), + makeProject({ + environmentId: remoteEnvironmentId, + id: ProjectId.make("project-remote"), + title: "t3code", + repositoryIdentity, + }), + ]; + + const scopes = buildHomeProjectScopes({ + projects, + environmentId: null, + projectGroupingMode: "repository", + }); + + expect(scopes).toHaveLength(1); + expect(scopes[0]?.projects).toEqual(projects); + expect(scopes[0]?.projectRefs).toEqual( + projects.map((project) => ({ + environmentId: project.environmentId, + projectId: project.id, + })), + ); + }); + + it("routes stale duplicate project refs through the canonical repository group", () => { + const localEnvironmentId = EnvironmentId.make("environment-local"); + const remoteEnvironmentId = EnvironmentId.make("environment-remote"); + const repositoryIdentity = { + canonicalKey: "github.com/pingdotgg/t3code", + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: "git@github.com:pingdotgg/t3code.git", + }, + }; + const local = makeProject({ + id: ProjectId.make("project-local"), + environmentId: localEnvironmentId, + title: "t3code", + workspaceRoot: "/workspaces/t3code", + repositoryIdentity, + }); + const stale = makeProject({ + environmentId: remoteEnvironmentId, + id: ProjectId.make("project-stale"), + title: "t3code", + workspaceRoot: "/remote/t3code", + updatedAt: "2026-06-01T00:00:00.000Z", + }); + const canonicalRemote = makeProject({ + environmentId: remoteEnvironmentId, + id: ProjectId.make("project-canonical-remote"), + title: "t3code", + workspaceRoot: "/remote/t3code/", + repositoryIdentity, + updatedAt: "2026-06-02T00:00:00.000Z", + }); + const projects = [local, stale, canonicalRemote]; + const staleThread = makeThread({ + environmentId: remoteEnvironmentId, + id: ThreadId.make("thread-stale-project-ref"), + projectId: stale.id, + title: "Still visible", + updatedAt: "2026-06-03T00:00:00.000Z", + }); + + const scopes = buildHomeProjectScopes({ + projects, + environmentId: null, + projectGroupingMode: "repository", + }); + const groups = buildGroups(projects, [staleThread]); + + expect(scopes).toHaveLength(1); + expect(scopes[0]?.projects.map((project) => project.id)).toEqual([ + local.id, + canonicalRemote.id, + ]); + expect(scopes[0]?.projectRefs.map((projectRef) => projectRef.projectId)).toEqual([ + local.id, + stale.id, + canonicalRemote.id, + ]); + expect(groups).toHaveLength(1); + expect(groups[0]?.threads.map((thread) => thread.id)).toEqual([staleThread.id]); + expect(groups[0]?.newThreadTarget?.id).toBe(canonicalRemote.id); + }); + + it("keeps repository identity from an older duplicate when the freshness winner lacks it", () => { + const localEnvironmentId = EnvironmentId.make("environment-local"); + const remoteEnvironmentId = EnvironmentId.make("environment-remote"); + const repositoryIdentity = { + canonicalKey: "github.com/pingdotgg/t3code", + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: "git@github.com:pingdotgg/t3code.git", + }, + }; + const projects = [ + makeProject({ + environmentId: localEnvironmentId, + id: ProjectId.make("project-local"), + title: "t3code", + repositoryIdentity, + }), + makeProject({ + environmentId: remoteEnvironmentId, + id: ProjectId.make("project-remote-with-identity"), + title: "t3code", + workspaceRoot: "/remote/t3code", + repositoryIdentity, + updatedAt: "2026-06-01T00:00:00.000Z", + }), + makeProject({ + environmentId: remoteEnvironmentId, + id: ProjectId.make("project-remote-fresh"), + title: "t3code", + workspaceRoot: "/remote/t3code/", + updatedAt: "2026-06-02T00:00:00.000Z", + }), + ]; + + const scopes = buildHomeProjectScopes({ + projects, + environmentId: null, + projectGroupingMode: "repository", + }); + + expect(scopes).toHaveLength(1); + expect(scopes[0]?.representative.id).toBe(ProjectId.make("project-local")); + expect(scopes[0]?.projects.map((project) => project.id)).toContain( + ProjectId.make("project-remote-fresh"), + ); + expect(scopes[0]?.projectRefs).toHaveLength(3); + }); + + it("sorts v2 project scopes by their grouped thread activity", () => { + const environmentId = EnvironmentId.make("environment-1"); + const olderProject = makeProject({ + environmentId, + id: ProjectId.make("project-older"), + title: "Older project", + }); + const newerProject = makeProject({ + environmentId, + id: ProjectId.make("project-newer"), + title: "Newer project", + }); + const scopes = buildHomeProjectScopes({ + projects: [newerProject, olderProject], + environmentId: null, + projectGroupingMode: "separate", + }); + + expect( + sortHomeProjectScopes({ + scopes, + threads: [ + makeThread({ + environmentId, + id: ThreadId.make("thread-older-project"), + projectId: olderProject.id, + title: "Most recently active", + updatedAt: "2026-06-03T00:00:00.000Z", + }), + makeThread({ + environmentId, + id: ThreadId.make("thread-newer-project"), + projectId: newerProject.id, + title: "Less recently active", + updatedAt: "2026-06-02T00:00:00.000Z", + }), + ], + pendingTasks: [], + projectSortOrder: "updated_at", + }).map((scope) => scope.representative.id), + ).toEqual([olderProject.id, newerProject.id]); + }); + + it("sorts invalid project creation timestamps after valid ones", () => { + const environmentId = EnvironmentId.make("environment-1"); + const invalidProject = makeProject({ + environmentId, + id: ProjectId.make("project-invalid"), + title: "A invalid timestamp", + createdAt: "invalid", + }); + const validProject = makeProject({ + environmentId, + id: ProjectId.make("project-valid"), + title: "Z valid timestamp", + createdAt: "2026-06-02T00:00:00.000Z", + }); + const scopes = buildHomeProjectScopes({ + projects: [invalidProject, validProject], + environmentId: null, + projectGroupingMode: "separate", + }); + + expect( + sortHomeProjectScopes({ + scopes, + threads: [], + pendingTasks: [], + projectSortOrder: "created_at", + }).map((scope) => scope.representative.id), + ).toEqual([validProject.id, invalidProject.id]); + }); + + it("uses the freshest member when a grouped scope has no activity", () => { + const localEnvironmentId = EnvironmentId.make("environment-local"); + const remoteEnvironmentId = EnvironmentId.make("environment-remote"); + const repositoryIdentity = { + canonicalKey: "github.com/pingdotgg/t3code", + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: "git@github.com:pingdotgg/t3code.git", + }, + }; + const olderMember = makeProject({ + environmentId: localEnvironmentId, + id: ProjectId.make("project-older-member"), + title: "t3code", + updatedAt: "2026-06-01T00:00:00.000Z", + repositoryIdentity, + }); + const newerMember = makeProject({ + environmentId: remoteEnvironmentId, + id: ProjectId.make("project-newer-member"), + title: "t3code", + updatedAt: "2026-06-03T00:00:00.000Z", + repositoryIdentity, + }); + const otherProject = makeProject({ + environmentId: localEnvironmentId, + id: ProjectId.make("project-other"), + title: "other", + updatedAt: "2026-06-02T00:00:00.000Z", + }); + const scopes = buildHomeProjectScopes({ + projects: [olderMember, newerMember, otherProject], + environmentId: null, + projectGroupingMode: "repository", + }); + + expect( + sortHomeProjectScopes({ + scopes, + threads: [], + pendingTasks: [], + projectSortOrder: "updated_at", + })[0]?.key, + ).toBe(scopes.find((scope) => scope.projects.length === 2)?.key); + }); + + it("does not merge unrelated repositories that share a title", () => { + const environmentId = EnvironmentId.make("environment-1"); + const projects = ["one", "two"].map((name) => + makeProject({ + environmentId, + id: ProjectId.make(`project-${name}`), + title: "app", + repositoryIdentity: { + canonicalKey: `github.com/example/${name}`, + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: `git@github.com:example/${name}.git`, + }, + }, + }), + ); + + expect( + buildHomeProjectScopes({ + projects, + environmentId: null, + projectGroupingMode: "repository", + }), + ).toHaveLength(2); + }); + it("sorts the newest thread first regardless of snapshot order", () => { const environmentId = EnvironmentId.make("environment-1"); const project = makeProject({ diff --git a/apps/mobile/src/features/home/homeThreadList.ts b/apps/mobile/src/features/home/homeThreadList.ts index cada956d8b..dffd94c76b 100644 --- a/apps/mobile/src/features/home/homeThreadList.ts +++ b/apps/mobile/src/features/home/homeThreadList.ts @@ -1,14 +1,20 @@ import { deriveLogicalProjectKey, + derivePhysicalProjectKey, deriveProjectGroupLabel, } from "@t3tools/client-runtime/state/project-grouping"; import type { EnvironmentProject, EnvironmentThreadShell, } from "@t3tools/client-runtime/state/shell"; -import { getThreadSortTimestamp, sortThreads } from "@t3tools/client-runtime/state/thread-sort"; +import { + getThreadSortTimestamp, + sortThreads, + toSortableTimestamp, +} from "@t3tools/client-runtime/state/thread-sort"; import type { EnvironmentId, + ScopedProjectRef, SidebarProjectGroupingMode, SidebarProjectSortOrder, SidebarThreadSortOrder, @@ -22,6 +28,164 @@ import type { PendingNewTask } from "../../state/use-pending-new-tasks"; export type HomeProjectSortOrder = Exclude; +export interface HomeProjectScope { + readonly key: string; + readonly title: string; + readonly representative: EnvironmentProject; + readonly projects: ReadonlyArray; + readonly projectRefs: ReadonlyArray; +} + +function getProjectFreshnessTimestamp(project: EnvironmentProject): number { + return toSortableTimestamp(project.updatedAt) ?? toSortableTimestamp(project.createdAt) ?? 0; +} + +function getProjectSortTimestamp( + project: EnvironmentProject, + sortOrder: HomeProjectSortOrder, +): number { + return sortOrder === "created_at" + ? (toSortableTimestamp(project.createdAt) ?? Number.NEGATIVE_INFINITY) + : (toSortableTimestamp(project.updatedAt) ?? + toSortableTimestamp(project.createdAt) ?? + Number.NEGATIVE_INFINITY); +} + +export function buildHomeProjectScopes(input: { + readonly projects: ReadonlyArray; + readonly environmentId: EnvironmentId | null; + readonly projectGroupingMode: SidebarProjectGroupingMode; +}): ReadonlyArray { + const projects = input.projects.filter( + (project) => input.environmentId === null || project.environmentId === input.environmentId, + ); + const projectsByPhysicalKey = new Map(); + for (const project of projects) { + const physicalKey = derivePhysicalProjectKey(project); + const existing = projectsByPhysicalKey.get(physicalKey); + if (existing) existing.push(project); + else projectsByPhysicalKey.set(physicalKey, [project]); + } + + const winnersByPhysicalKey = new Map< + string, + { readonly key: string; readonly project: EnvironmentProject } + >(); + for (const [physicalKey, members] of projectsByPhysicalKey) { + const project = members.reduce((winner, candidate) => { + const freshnessDelta = + getProjectFreshnessTimestamp(candidate) - getProjectFreshnessTimestamp(winner); + return freshnessDelta > 0 || (freshnessDelta === 0 && candidate.id > winner.id) + ? candidate + : winner; + }); + const identitySource = members.find((member) => member.repositoryIdentity !== null) ?? project; + winnersByPhysicalKey.set(physicalKey, { + key: deriveLogicalProjectKey(identitySource, { groupingMode: input.projectGroupingMode }), + project, + }); + } + + const groups = new Map(); + for (const { key, project } of winnersByPhysicalKey.values()) { + const existing = groups.get(key); + if (existing) existing.push(project); + else groups.set(key, [project]); + } + + const projectRefsByGroup = new Map(); + const seenProjectRefs = new Set(); + for (const project of projects) { + const refKey = scopedProjectKey(project.environmentId, project.id); + if (seenProjectRefs.has(refKey)) continue; + seenProjectRefs.add(refKey); + + const key = + winnersByPhysicalKey.get(derivePhysicalProjectKey(project))?.key ?? + deriveLogicalProjectKey(project, { groupingMode: input.projectGroupingMode }); + const refs = projectRefsByGroup.get(key); + const projectRef = { environmentId: project.environmentId, projectId: project.id }; + if (refs) refs.push(projectRef); + else projectRefsByGroup.set(key, [projectRef]); + } + + return Array.from(groups, ([key, projects]) => { + const representative = projects[0]!; + return { + key, + title: + projects.length > 1 + ? deriveProjectGroupLabel({ representative, members: projects }) + : representative.title, + representative, + projects, + projectRefs: projectRefsByGroup.get(key) ?? [], + }; + }); +} + +export function sortHomeProjectScopes(input: { + readonly scopes: ReadonlyArray; + readonly threads: ReadonlyArray; + readonly pendingTasks: ReadonlyArray; + readonly projectSortOrder: HomeProjectSortOrder; +}): ReadonlyArray { + const scopeKeyByProjectRef = new Map( + input.scopes.flatMap((scope) => + scope.projectRefs.map( + (projectRef) => + [scopedProjectKey(projectRef.environmentId, projectRef.projectId), scope.key] as const, + ), + ), + ); + const latestActivityByScope = new Map(); + const recordActivity = (scopeKey: string | undefined, timestamp: number) => { + if (!scopeKey || !Number.isFinite(timestamp)) return; + latestActivityByScope.set( + scopeKey, + Math.max(latestActivityByScope.get(scopeKey) ?? Number.NEGATIVE_INFINITY, timestamp), + ); + }; + + for (const thread of input.threads) { + if (thread.archivedAt !== null) continue; + recordActivity( + scopeKeyByProjectRef.get(scopedProjectKey(thread.environmentId, thread.projectId)), + getThreadSortTimestamp(thread, input.projectSortOrder), + ); + } + for (const pendingTask of input.pendingTasks) { + recordActivity( + scopeKeyByProjectRef.get( + scopedProjectKey(pendingTask.message.environmentId, pendingTask.creation.projectId), + ), + Date.parse(pendingTask.message.createdAt), + ); + } + + return Arr.sort( + input.scopes, + Order.mapInput( + Order.Struct({ + timestamp: Order.flip(Order.Number), + title: Order.String, + key: Order.String, + }), + (scope: HomeProjectScope) => ({ + timestamp: + latestActivityByScope.get(scope.key) ?? + Math.max( + ...scope.projects.map((project) => + getProjectSortTimestamp(project, input.projectSortOrder), + ), + ), + title: scope.title, + key: scope.key, + }), + ), + ); +} + /** * Default home view only surfaces threads active within this window, to keep the * screen compact while keeping recent work visible. @@ -103,22 +267,18 @@ export function buildHomeThreadGroups(input: { const groups = new Map(); const groupKeyByProjectKey = new Map(); - for (const project of input.projects) { - if (input.environmentId !== null && project.environmentId !== input.environmentId) { - continue; - } - - const groupKey = deriveLogicalProjectKey(project, { - groupingMode: input.projectGroupingMode, + for (const scope of buildHomeProjectScopes(input)) { + groups.set(scope.key, { + key: scope.key, + projects: [...scope.projects], + pendingTasks: [], + threads: [], }); - const physicalKey = scopedProjectKey(project.environmentId, project.id); - groupKeyByProjectKey.set(physicalKey, groupKey); - - const existing = groups.get(groupKey); - if (existing) { - existing.projects.push(project); - } else { - groups.set(groupKey, { key: groupKey, projects: [project], pendingTasks: [], threads: [] }); + for (const projectRef of scope.projectRefs) { + groupKeyByProjectKey.set( + scopedProjectKey(projectRef.environmentId, projectRef.projectId), + scope.key, + ); } } @@ -215,19 +375,21 @@ export function buildHomeThreadGroups(input: { ? selectRecentThreads(sortedThreads, input.threadSortOrder, now) : sortedThreads; - // Sorted newest-first, so the first thread whose project is a group member - // marks the machine the user last worked on. - const lastActiveProject = Arr.findFirst(sortedThreads, (thread) => - group.projects.some( - (project) => - project.environmentId === thread.environmentId && project.id === thread.projectId, - ), - ).pipe( + // A stale project id still resolves to the canonical member with the same + // environment/path, so quick creation follows the machine with the newest activity. + const lastActiveProject = Arr.head(sortedThreads).pipe( Option.flatMap((thread) => + Arr.findFirst( + input.projects, + (project) => + project.environmentId === thread.environmentId && project.id === thread.projectId, + ), + ), + Option.flatMap((threadProject) => Arr.findFirst( group.projects, (project) => - project.environmentId === thread.environmentId && project.id === thread.projectId, + derivePhysicalProjectKey(project) === derivePhysicalProjectKey(threadProject), ), ), Option.getOrNull, diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx index d1327473b0..9c068c6249 100644 --- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx +++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx @@ -2,7 +2,8 @@ import type { EnvironmentProject, EnvironmentThreadShell, } from "@t3tools/client-runtime/state/shell"; -import { EnvironmentId, ThreadId } from "@t3tools/contracts"; +import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts"; +import { useAtomValue } from "@effect/atom-react"; import { useFocusEffect } from "@react-navigation/native"; import { NavigationContext, @@ -22,6 +23,7 @@ import { } from "react"; import { useWindowDimensions, View } from "react-native"; import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated"; +import { AsyncResult } from "effect/unstable/reactivity"; import { deriveFileInspectorPaneLayout, @@ -34,11 +36,12 @@ import { } from "../../lib/layout"; import { resolveThreadSelectionNavigationAction } from "../../lib/adaptive-navigation"; import { scopedThreadKey } from "../../lib/scopedEntities"; +import { mobilePreferencesAtom } from "../../state/preferences"; import { parseActiveThreadPath, useHardwareKeyboardCommand, } from "../keyboard/hardwareKeyboardCommands"; -import { HomeListOptionsProvider } from "../home/home-list-options"; +import { HomeListOptionsProvider, resolveProjectGroupingMode } from "../home/home-list-options"; import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar"; import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation"; import { WorkspaceInspectorPane } from "./workspace-inspector-pane"; @@ -184,6 +187,31 @@ export function AdaptiveWorkspaceLayout(props: { readonly children: ReactNode; readonly pathname: string; }) { + const preferencesResult = useAtomValue(mobilePreferencesAtom); + if (!AsyncResult.isSuccess(preferencesResult)) { + return AsyncResult.isFailure(preferencesResult) ? ( + + ) : null; + } + return ( + + ); +} + +function AdaptiveWorkspaceLayoutContent( + props: { + readonly children: ReactNode; + readonly pathname: string; + } & { + readonly projectGroupingMode: SidebarProjectGroupingMode; + }, +) { + const projectGroupingMode = props.projectGroupingMode; const { width, height } = useWindowDimensions(); const pathname = props.pathname; const navigation = useNavigation(); @@ -474,7 +502,7 @@ export function AdaptiveWorkspaceLayout(props: { ); return ( - + {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? ( diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx index 9aea392555..4c33675f57 100644 --- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx @@ -119,6 +119,8 @@ function LocalSettingsRouteScreen() { /> + + @@ -504,6 +506,8 @@ function ConfiguredSettingsRouteScreen() { /> + + @@ -518,6 +522,25 @@ function ConfiguredSettingsRouteScreen() { ); } +function GeneralSettingsSection() { + const preferencesResult = useAtomValue(mobilePreferencesAtom); + const savePreferences = useAtomSet(updateMobilePreferencesAtom); + const projectGroupingEnabled = AsyncResult.isSuccess(preferencesResult) + ? preferencesResult.value.projectGroupingEnabled !== false + : true; + + return ( + + savePreferences({ projectGroupingEnabled: value })} + /> + + ); +} + /** * Device-local beta toggles. Mobile has no client-settings sync, so this is * the counterpart of web's Settings → Beta backed by mobile preferences. diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx index 13f628351c..bd0bd9aefb 100644 --- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx +++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx @@ -33,7 +33,6 @@ import { useSavedRemoteConnections } from "../../state/use-remote-environment-re import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands"; import { hasCustomHomeListOptions, - PROJECT_GROUPING_OPTIONS, PROJECT_SORT_OPTIONS, THREAD_SORT_OPTIONS, useHomeListOptions, @@ -48,7 +47,7 @@ import { type HomeGroupDisplayState, type HomeListItem, } from "../home/homeListItems"; -import { buildHomeThreadGroups } from "../home/homeThreadList"; +import { buildHomeProjectScopes, buildHomeThreadGroups } from "../home/homeThreadList"; import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions"; import { usePendingTaskListActions } from "../home/usePendingTaskListActions"; import { useThreadListActions } from "../home/useThreadListActions"; @@ -217,36 +216,32 @@ function ThreadNavigationSidebarPane( () => new Set(environments.map((environment) => environment.environmentId)), [environments], ); - const { - options, - setSelectedEnvironmentId, - setProjectGroupingMode, - setProjectSortOrder, - setThreadSortOrder, - } = useHomeListOptions(availableEnvironmentIds); + const { options, setSelectedEnvironmentId, setProjectSortOrder, setThreadSortOrder } = + useHomeListOptions(availableEnvironmentIds); const [selectedProjectKey, setSelectedProjectKey] = useState(null); + const projectScopes = useMemo( + () => + buildHomeProjectScopes({ + projects, + environmentId: options.selectedEnvironmentId, + projectGroupingMode: options.projectGroupingMode, + }), + [options.projectGroupingMode, options.selectedEnvironmentId, projects], + ); const projectFilterOptions = useMemo( () => - projects - .filter( - (project) => - options.selectedEnvironmentId === null || - project.environmentId === options.selectedEnvironmentId, - ) - .map((project) => ({ - key: scopedProjectKey(project.environmentId, project.id), - label: project.title, - })), - [options.selectedEnvironmentId, projects], + projectScopes.map((scope) => ({ + key: scope.key, + label: scope.title, + })), + [projectScopes], ); - const selectedProject = useMemo( + const selectedProjectScope = useMemo( () => selectedProjectKey === null ? null - : (projects.find( - (project) => scopedProjectKey(project.environmentId, project.id) === selectedProjectKey, - ) ?? null), - [projects, selectedProjectKey], + : (projectScopes.find((scope) => scope.key === selectedProjectKey) ?? null), + [projectScopes, selectedProjectKey], ); useEffect(() => { if ( @@ -256,31 +251,45 @@ function ThreadNavigationSidebarPane( setSelectedProjectKey(null); } }, [projectFilterOptions, selectedProjectKey]); + const selectedProjectRefs = useMemo( + () => + selectedProjectScope === null + ? null + : new Set( + selectedProjectScope.projectRefs.map((projectRef) => + scopedProjectKey(projectRef.environmentId, projectRef.projectId), + ), + ), + [selectedProjectScope], + ); const scopedProjects = useMemo( - () => (selectedProject === null ? projects : [selectedProject]), - [projects, selectedProject], + () => + selectedProjectRefs === null + ? projects + : projects.filter((project) => + selectedProjectRefs.has(scopedProjectKey(project.environmentId, project.id)), + ), + [projects, selectedProjectRefs], ); const scopedThreads = useMemo( () => - selectedProject === null + selectedProjectRefs === null ? threads - : threads.filter( - (thread) => - thread.environmentId === selectedProject.environmentId && - thread.projectId === selectedProject.id, + : threads.filter((thread) => + selectedProjectRefs.has(scopedProjectKey(thread.environmentId, thread.projectId)), ), - [selectedProject, threads], + [selectedProjectRefs, threads], ); const scopedPendingTasks = useMemo( () => - selectedProject === null + selectedProjectRefs === null ? pendingTasks - : pendingTasks.filter( - (pendingTask) => - pendingTask.message.environmentId === selectedProject.environmentId && - pendingTask.creation.projectId === selectedProject.id, + : pendingTasks.filter((pendingTask) => + selectedProjectRefs.has( + scopedProjectKey(pendingTask.message.environmentId, pendingTask.creation.projectId), + ), ), - [pendingTasks, selectedProject], + [pendingTasks, selectedProjectRefs], ); const groups = useMemo( () => @@ -401,13 +410,7 @@ function ThreadNavigationSidebarPane( return buildThreadListV2Items({ threads: threads.filter((thread) => thread.archivedAt === null), environmentId: options.selectedEnvironmentId, - projectRef: - selectedProject === null - ? null - : { - environmentId: selectedProject.environmentId, - projectId: selectedProject.id, - }, + projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs, searchQuery: props.searchQuery, changeRequestStateByKey, settlementEnvironmentIds, @@ -423,7 +426,7 @@ function ThreadNavigationSidebarPane( settlementEnvironmentIds, threadListV2Enabled, threads, - selectedProject, + selectedProjectScope, ]); const listItems = useMemo(() => { if (!threadListV2Enabled) return listLayout.items; @@ -437,9 +440,10 @@ function ThreadNavigationSidebarPane( (pendingTask) => (options.selectedEnvironmentId === null || pendingTask.message.environmentId === options.selectedEnvironmentId) && - (selectedProject === null || - (pendingTask.message.environmentId === selectedProject.environmentId && - pendingTask.creation.projectId === selectedProject.id)) && + (selectedProjectRefs === null || + selectedProjectRefs.has( + scopedProjectKey(pendingTask.message.environmentId, pendingTask.creation.projectId), + )) && (v2SearchQuery.length === 0 || pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)), ); @@ -469,7 +473,7 @@ function ThreadNavigationSidebarPane( options.selectedEnvironmentId, pendingTasks, props.searchQuery, - selectedProject, + selectedProjectRefs, threadListV2Enabled, threadListV2Layout, ]); @@ -541,16 +545,6 @@ function ThreadNavigationSidebarPane( state: options.threadSortOrder === option.value ? "on" : "off", })), }, - { - id: "project-grouping", - title: "Group projects", - subactions: PROJECT_GROUPING_OPTIONS.map((option) => ({ - id: `project-grouping:${option.value}`, - title: option.label, - subtitle: option.subtitle, - state: options.projectGroupingMode === option.value ? "on" : "off", - })), - }, ] satisfies MenuAction[])), ], [environments, options, projectFilterOptions, selectedProjectKey, threadListV2Enabled], @@ -594,15 +588,10 @@ function ThreadNavigationSidebarPane( setThreadSortOrder(threadSort.value); return; } - const grouping = PROJECT_GROUPING_OPTIONS.find( - (option) => `project-grouping:${option.value}` === event, - ); - if (grouping) setProjectGroupingMode(grouping.value); }, [ environments, projectFilterOptions, - setProjectGroupingMode, setProjectSortOrder, setSelectedEnvironmentId, setThreadSortOrder, @@ -898,12 +887,10 @@ function ThreadNavigationSidebarPane( selectedProjectKey, projectSortOrder: options.projectSortOrder, threadSortOrder: options.threadSortOrder, - projectGroupingMode: options.projectGroupingMode, onEnvironmentChange: setSelectedEnvironmentId, onProjectChange: setSelectedProjectKey, onProjectSortOrderChange: setProjectSortOrder, onThreadSortOrderChange: setThreadSortOrder, - onProjectGroupingModeChange: setProjectGroupingMode, listOrganization: !threadListV2Enabled, }), [ @@ -911,7 +898,6 @@ function ThreadNavigationSidebarPane( options, projectFilterOptions, selectedProjectKey, - setProjectGroupingMode, setProjectSortOrder, setSelectedEnvironmentId, setThreadSortOrder, @@ -933,8 +919,8 @@ function ThreadNavigationSidebarPane( ? "Loading threads…" : props.searchQuery.trim().length > 0 ? "No matching threads" - : selectedProject !== null - ? `No threads in ${selectedProject.title}` + : selectedProjectScope !== null + ? `No threads in ${selectedProjectScope.title}` : "No threads yet"} ); diff --git a/apps/mobile/src/features/threads/threadListV2.test.ts b/apps/mobile/src/features/threads/threadListV2.test.ts index 80edc86124..cdbf2e3c58 100644 --- a/apps/mobile/src/features/threads/threadListV2.test.ts +++ b/apps/mobile/src/features/threads/threadListV2.test.ts @@ -166,13 +166,36 @@ describe("buildThreadListV2Items", () => { }), ], environmentId: null, - projectRef: { environmentId, projectId: ProjectId.make("project-1") }, + projectRefs: [{ environmentId, projectId: ProjectId.make("project-1") }], searchQuery: "", now: NOW, }); expect(items.map((item) => item.thread.id)).toEqual(["included"]); }); + + it("scopes the flat list to every environment member of a logical project", () => { + const remoteEnvironmentId = EnvironmentId.make("environment-remote"); + const { items } = buildThreadListV2Items({ + threads: [ + makeThread({ id: ThreadId.make("local"), title: "Local" }), + makeThread({ + environmentId: remoteEnvironmentId, + id: ThreadId.make("remote"), + title: "Remote", + }), + ], + environmentId: null, + projectRefs: [ + { environmentId, projectId: ProjectId.make("project-1") }, + { environmentId: remoteEnvironmentId, projectId: ProjectId.make("project-1") }, + ], + searchQuery: "", + now: NOW, + }); + + expect(items.map((item) => item.thread.id)).toEqual(["local", "remote"]); + }); }); describe("buildThreadListV2Items settled paging", () => { diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.ts index a1604bafac..071e1d93be 100644 --- a/apps/mobile/src/features/threads/threadListV2.ts +++ b/apps/mobile/src/features/threads/threadListV2.ts @@ -95,10 +95,10 @@ export interface ThreadListV2Layout { export function buildThreadListV2Items(input: { readonly threads: ReadonlyArray; readonly environmentId: EnvironmentId | null; - readonly projectRef?: { + readonly projectRefs?: ReadonlyArray<{ readonly environmentId: EnvironmentId; readonly projectId: ProjectId; - } | null; + }> | null; readonly searchQuery: string; /** Per-row PR state reported up by visible rows ("env:threadId" keys). */ readonly changeRequestStateByKey?: ReadonlyMap; @@ -115,6 +115,9 @@ export function buildThreadListV2Items(input: { const now = input.now ?? new Date().toISOString(); const autoSettleAfterDays = input.autoSettleAfterDays ?? 3; const query = input.searchQuery.trim().toLocaleLowerCase(); + const projectKeys = input.projectRefs + ? new Set(input.projectRefs.map((ref) => `${ref.environmentId}:${ref.projectId}`)) + : null; const active: EnvironmentThreadShell[] = []; const settled: EnvironmentThreadShell[] = []; @@ -122,11 +125,7 @@ export function buildThreadListV2Items(input: { // Callers pass live (unarchived) shells; settled threads are among them // and partition into the tail via effectiveSettled. if (input.environmentId !== null && thread.environmentId !== input.environmentId) continue; - if ( - input.projectRef != null && - (thread.environmentId !== input.projectRef.environmentId || - thread.projectId !== input.projectRef.projectId) - ) { + if (projectKeys !== null && !projectKeys.has(`${thread.environmentId}:${thread.projectId}`)) { continue; } if (query.length > 0 && !thread.title.toLocaleLowerCase().includes(query)) continue; diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index 1138ad2b65..4e576bb2fe 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -22,6 +22,7 @@ export interface Preferences { readonly codeWordBreak?: boolean; readonly connectOnboardingOptOutAccounts?: ReadonlyArray; readonly collapsedProjectGroups?: readonly string[]; + readonly projectGroupingEnabled?: boolean; /** * Device-local mirror of the web beta's `sidebarV2Enabled`. Mobile has no * client-settings sync, so the flat v2 thread list is opted into per @@ -77,6 +78,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { codeWordBreak?: boolean; connectOnboardingOptOutAccounts?: ReadonlyArray; collapsedProjectGroups?: readonly string[]; + projectGroupingEnabled?: boolean; threadListV2Enabled?: boolean; } = {}; @@ -104,6 +106,9 @@ function sanitizePreferences(parsed: Preferences): Preferences { (key): key is string => typeof key === "string", ); } + if (typeof parsed.projectGroupingEnabled === "boolean") { + preferences.projectGroupingEnabled = parsed.projectGroupingEnabled; + } if (typeof parsed.threadListV2Enabled === "boolean") { preferences.threadListV2Enabled = parsed.threadListV2Enabled; } diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 43a1a87566..1ef1a7a884 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -22,7 +22,7 @@ import { TerminalOpenInput, } from "@t3tools/contracts"; import { - connectionStatusText, + connectionStatusTitle, type EnvironmentConnectionPresentation, } from "@t3tools/client-runtime/connection"; import { @@ -1815,7 +1815,7 @@ function ChatViewContent(props: ChatViewProps) { id: `environment-unavailable:${activeEnvironmentUnavailableState.environmentId}`, variant: connection.phase === "error" ? "error" : "warning", icon: , - title: `${activeEnvironmentUnavailableState.label}: ${connectionStatusText(connection)}`, + title: `${activeEnvironmentUnavailableState.label}: ${connectionStatusTitle(connection)}`, description: connection.error ?? "Reconnect this environment before sending messages or running actions.", diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 4b4093e212..014e629fda 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -145,15 +145,7 @@ import { DialogTitle, } from "./ui/dialog"; import { Input } from "./ui/input"; -import { - Menu, - MenuGroup, - MenuPopup, - MenuRadioGroup, - MenuRadioItem, - MenuSeparator, - MenuTrigger, -} from "./ui/menu"; +import { Menu, MenuGroup, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "./ui/menu"; import { NumberField, NumberFieldDecrement, @@ -2601,20 +2593,16 @@ type SortableProjectHandleProps = Pick< function ProjectSortMenu({ projectSortOrder, threadSortOrder, - projectGroupingMode, threadPreviewCount, onProjectSortOrderChange, onThreadSortOrderChange, - onProjectGroupingModeChange, onThreadPreviewCountChange, }: { projectSortOrder: SidebarProjectSortOrder; threadSortOrder: SidebarThreadSortOrder; - projectGroupingMode: SidebarProjectGroupingMode; threadPreviewCount: SidebarThreadPreviewCount; onProjectSortOrderChange: (sortOrder: SidebarProjectSortOrder) => void; onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void; - onProjectGroupingModeChange: (mode: SidebarProjectGroupingMode) => void; onThreadPreviewCountChange: (count: SidebarThreadPreviewCount) => void; }) { const handleThreadPreviewCountChange = useCallback( @@ -2718,30 +2706,6 @@ function ProjectSortMenu({ - - -
- Group projects -
- { - if (value === "repository" || value === "repository_path" || value === "separate") { - onProjectGroupingModeChange(value); - } - }} - > - {( - Object.entries(PROJECT_GROUPING_MODE_LABELS) as Array< - [SidebarProjectGroupingMode, string] - > - ).map(([value, label]) => ( - - {label} - - ))} - -
); @@ -2792,7 +2756,6 @@ interface SidebarProjectsContentProps { handleDesktopUpdateButtonClick: () => void; projectSortOrder: SidebarProjectSortOrder; threadSortOrder: SidebarThreadSortOrder; - projectGroupingMode: SidebarProjectGroupingMode; threadPreviewCount: SidebarThreadPreviewCount; updateSettings: ReturnType; openAddProject: () => void; @@ -2833,7 +2796,6 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent( handleDesktopUpdateButtonClick, projectSortOrder, threadSortOrder, - projectGroupingMode, threadPreviewCount, updateSettings, openAddProject, @@ -2875,12 +2837,6 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent( }, [updateSettings], ); - const handleProjectGroupingModeChange = useCallback( - (groupingMode: SidebarProjectGroupingMode) => { - updateSettings({ sidebarProjectGroupingMode: groupingMode }); - }, - [updateSettings], - ); const handleThreadPreviewCountChange = useCallback( (count: SidebarThreadPreviewCount) => { updateSettings({ sidebarThreadPreviewCount: count }); @@ -2944,11 +2900,9 @@ const SidebarProjectsContent = memo(function SidebarProjectsContent( @@ -3064,7 +3018,6 @@ export default function Sidebar() { const isOnSettings = pathname.startsWith("/settings"); const sidebarThreadSortOrder = useClientSettings((s) => s.sidebarThreadSortOrder); const sidebarProjectSortOrder = useClientSettings((s) => s.sidebarProjectSortOrder); - const sidebarProjectGroupingMode = useClientSettings((s) => s.sidebarProjectGroupingMode); const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings); const sidebarThreadPreviewCount = useClientSettings((s) => s.sidebarThreadPreviewCount); const updateSettings = useUpdateClientSettings(); @@ -3608,7 +3561,7 @@ export default function Sidebar() { if (desktopUpdateButtonAction === "install") { const confirmed = window.confirm( - getDesktopUpdateInstallConfirmationMessage(desktopUpdateState), + getDesktopUpdateInstallConfirmationMessage(desktopUpdateState, navigator.platform), ); if (!confirmed) return; void bridge @@ -3674,7 +3627,6 @@ export default function Sidebar() { handleDesktopUpdateButtonClick={handleDesktopUpdateButtonClick} projectSortOrder={sidebarProjectSortOrder} threadSortOrder={sidebarThreadSortOrder} - projectGroupingMode={sidebarProjectGroupingMode} threadPreviewCount={sidebarThreadPreviewCount} updateSettings={updateSettings} openAddProject={openAddProjectCommandPalette} diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 2fc688678f..b427037bdf 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -18,10 +18,7 @@ import { PROVIDER_SEND_TURN_MAX_ATTACHMENTS, PROVIDER_SEND_TURN_MAX_IMAGE_BYTES, } from "@t3tools/contracts"; -import { - connectionStatusText, - type EnvironmentConnectionPresentation, -} from "@t3tools/client-runtime/connection"; +import type { EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection"; import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger"; import { createModelSelection, normalizeModelSlug } from "@t3tools/shared/model"; import { @@ -2577,15 +2574,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) ? "Add feedback to refine the plan, or leave this blank to implement it" : projectSelectionRequired ? "Choose a project above to start a thread" - : environmentUnavailable - ? `${environmentUnavailable.label}: ${connectionStatusText( - environmentUnavailable.connection, - )}` - : noProviderAvailable - ? "Enable a provider in Settings to send a message" - : phase === "disconnected" - ? "Ask for follow-up changes or attach images" - : "Ask anything, @tag files/folders, $use skills, or / for commands" + : noProviderAvailable + ? "Enable a provider in Settings to send a message" + : phase === "disconnected" + ? "Ask for follow-up changes or attach images" + : "Ask anything, @tag files/folders, $use skills, or / for commands" } disabled={isConnecting || isComposerApprovalState || projectSelectionRequired} /> diff --git a/apps/web/src/components/desktopUpdate.logic.test.ts b/apps/web/src/components/desktopUpdate.logic.test.ts index 65083b5b0b..b07ae99c05 100644 --- a/apps/web/src/components/desktopUpdate.logic.test.ts +++ b/apps/web/src/components/desktopUpdate.logic.test.ts @@ -225,6 +225,32 @@ describe("desktop update UI helpers", () => { }), ).toContain("Install update and restart T3 Code?"); }); + + it("warns Windows users that a silent installation can take several minutes", () => { + const message = getDesktopUpdateInstallConfirmationMessage( + { + availableVersion: "1.1.0", + downloadedVersion: "1.1.0", + }, + "Win32", + ); + + expect(message).toContain("may remain closed for several minutes"); + expect(message).toContain("no installer window may appear"); + expect(message).toContain("will reopen automatically"); + }); + + it("keeps the additional silent installation warning Windows-specific", () => { + const message = getDesktopUpdateInstallConfirmationMessage( + { + availableVersion: "1.1.0", + downloadedVersion: "1.1.0", + }, + "MacIntel", + ); + + expect(message).not.toContain("may remain closed for several minutes"); + }); }); describe("canCheckForUpdate", () => { diff --git a/apps/web/src/components/desktopUpdate.logic.ts b/apps/web/src/components/desktopUpdate.logic.ts index 38983c810b..11c34777a4 100644 --- a/apps/web/src/components/desktopUpdate.logic.ts +++ b/apps/web/src/components/desktopUpdate.logic.ts @@ -1,4 +1,5 @@ import type { DesktopUpdateActionResult, DesktopUpdateState } from "@t3tools/contracts"; +import { isWindowsPlatform } from "../lib/utils"; export type DesktopUpdateButtonAction = "download" | "install" | "none"; @@ -78,9 +79,13 @@ export function getDesktopUpdateButtonTooltip(state: DesktopUpdateState): string export function getDesktopUpdateInstallConfirmationMessage( state: Pick, + platform = "", ): string { const version = state.downloadedVersion ?? state.availableVersion; - return `Install update${version ? ` ${version}` : ""} and restart T3 Code?\n\nAny running tasks will be interrupted. Make sure you're ready before continuing.`; + const windowsInstallWarning = isWindowsPlatform(platform) + ? "\n\nOn Windows, T3 Code may remain closed for several minutes while the update installs, and no installer window may appear. T3 Code will reopen automatically when installation finishes." + : ""; + return `Install update${version ? ` ${version}` : ""} and restart T3 Code?\n\nAny running tasks will be interrupted. Make sure you're ready before continuing.${windowsInstallWarning}`; } export function getDesktopUpdateActionError(result: DesktopUpdateActionResult): string | null { diff --git a/apps/web/src/components/settings/SettingsPanels.logic.test.ts b/apps/web/src/components/settings/SettingsPanels.logic.test.ts index d783d16c7a..077991f8de 100644 --- a/apps/web/src/components/settings/SettingsPanels.logic.test.ts +++ b/apps/web/src/components/settings/SettingsPanels.logic.test.ts @@ -8,8 +8,25 @@ import { describe, expect, it } from "vite-plus/test"; import { buildProviderInstanceUpdatePatch, formatDiagnosticsDescription, + isProjectGroupingEnabled, + projectGroupingModeFromToggle, } from "./SettingsPanels.logic"; +describe("project grouping toggle", () => { + it("enables repository grouping and disables into separate projects", () => { + expect(isProjectGroupingEnabled("repository")).toBe(true); + expect(isProjectGroupingEnabled("repository_path")).toBe(true); + expect(isProjectGroupingEnabled("separate")).toBe(false); + expect(projectGroupingModeFromToggle(true)).toBe("repository"); + expect(projectGroupingModeFromToggle(false)).toBe("separate"); + }); + + it("restores repository path grouping when the toggle is cycled", () => { + expect(projectGroupingModeFromToggle(false, "repository_path")).toBe("separate"); + expect(projectGroupingModeFromToggle(true, "repository_path")).toBe("repository_path"); + }); +}); + describe("formatDiagnosticsDescription", () => { it("collapses trace and metric URLs that share the same OTEL base path", () => { expect( diff --git a/apps/web/src/components/settings/SettingsPanels.logic.ts b/apps/web/src/components/settings/SettingsPanels.logic.ts index 99d7052965..51e318225a 100644 --- a/apps/web/src/components/settings/SettingsPanels.logic.ts +++ b/apps/web/src/components/settings/SettingsPanels.logic.ts @@ -3,10 +3,44 @@ import type { ProviderInstanceConfig, ProviderInstanceId, ServerSettings, + SidebarProjectGroupingMode, UnifiedSettings, } from "@t3tools/contracts"; import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings"; +export function isProjectGroupingEnabled(mode: SidebarProjectGroupingMode): boolean { + return mode !== "separate"; +} + +export function projectGroupingModeFromToggle( + enabled: boolean, + lastEnabledMode: SidebarProjectGroupingMode = "repository", +): SidebarProjectGroupingMode { + if (!enabled) return "separate"; + return lastEnabledMode === "repository_path" ? "repository_path" : "repository"; +} + +const LAST_ENABLED_PROJECT_GROUPING_MODE_KEY = "t3code:last-enabled-project-grouping-mode"; + +export function readLastEnabledProjectGroupingMode(): SidebarProjectGroupingMode { + try { + return localStorage.getItem(LAST_ENABLED_PROJECT_GROUPING_MODE_KEY) === "repository_path" + ? "repository_path" + : "repository"; + } catch { + return "repository"; + } +} + +export function rememberEnabledProjectGroupingMode(mode: SidebarProjectGroupingMode): void { + if (mode === "separate") return; + try { + localStorage.setItem(LAST_ENABLED_PROJECT_GROUPING_MODE_KEY, mode); + } catch { + // Storage can be unavailable in restricted browser contexts. + } +} + function collapseOtelSignalsUrl(input: { readonly tracesUrl: string; readonly metricsUrl: string; diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index ebf4aed623..fa7c729966 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -11,6 +11,7 @@ import { type ProviderInstanceConfig, type ProviderInstanceId, type ScopedThreadRef, + type SidebarProjectGroupingMode, } from "@t3tools/contracts"; import { scopeThreadRef } from "@t3tools/client-runtime/environment"; import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors"; @@ -83,6 +84,10 @@ import { DRIVER_OPTIONS, getDriverOption } from "./providerDriverMeta"; import { buildProviderInstanceUpdatePatch, formatDiagnosticsDescription, + isProjectGroupingEnabled, + projectGroupingModeFromToggle, + readLastEnabledProjectGroupingMode, + rememberEnabledProjectGroupingMode, } from "./SettingsPanels.logic"; import { SettingResetButton, @@ -233,6 +238,7 @@ function AboutVersionSection() { const confirmed = window.confirm( getDesktopUpdateInstallConfirmationMessage( updateState ?? { availableVersion: null, downloadedVersion: null }, + navigator.platform, ), ); if (!confirmed) return; @@ -401,6 +407,10 @@ export function useSettingsRestore(onRestored?: () => void) { ...(settings.sidebarThreadPreviewCount !== DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount ? ["Visible threads"] : []), + ...(settings.sidebarProjectGroupingMode !== + DEFAULT_UNIFIED_SETTINGS.sidebarProjectGroupingMode + ? ["Project Grouping"] + : []), ...(settings.wordWrap !== DEFAULT_UNIFIED_SETTINGS.wordWrap ? ["Word wrap"] : []), ...(settings.diffIgnoreWhitespace !== DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace ? ["Diff whitespace changes"] @@ -450,6 +460,7 @@ export function useSettingsRestore(onRestored?: () => void) { settings.automaticGitFetchInterval, settings.enableAssistantStreaming, settings.enableProviderUpdateChecks, + settings.sidebarProjectGroupingMode, settings.sidebarThreadPreviewCount, settings.timestampFormat, settings.wordWrap, @@ -474,6 +485,7 @@ export function useSettingsRestore(onRestored?: () => void) { diffIgnoreWhitespace: DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace, glassOpacity: DEFAULT_UNIFIED_SETTINGS.glassOpacity, sidebarThreadPreviewCount: DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount, + sidebarProjectGroupingMode: DEFAULT_UNIFIED_SETTINGS.sidebarProjectGroupingMode, autoOpenPlanSidebar: DEFAULT_UNIFIED_SETTINGS.autoOpenPlanSidebar, enableAssistantStreaming: DEFAULT_UNIFIED_SETTINGS.enableAssistantStreaming, enableProviderUpdateChecks: DEFAULT_UNIFIED_SETTINGS.enableProviderUpdateChecks, @@ -498,6 +510,9 @@ export function GeneralSettingsPanel() { const { theme, setTheme } = useTheme(); const settings = usePrimarySettings(); const updateSettings = useUpdatePrimarySettings(); + const lastEnabledProjectGroupingMode = useRef( + readLastEnabledProjectGroupingMode(), + ); const observability = useAtomValue(primaryServerObservabilityAtom); const serverProviders = useAtomValue(primaryServerProvidersAtom); const glassOpacityRatio = @@ -619,6 +634,42 @@ export function GeneralSettingsPanel() { } /> + + updateSettings({ + sidebarProjectGroupingMode: DEFAULT_UNIFIED_SETTINGS.sidebarProjectGroupingMode, + }) + } + /> + ) : null + } + control={ + { + if (!checked && settings.sidebarProjectGroupingMode !== "separate") { + lastEnabledProjectGroupingMode.current = settings.sidebarProjectGroupingMode; + rememberEnabledProjectGroupingMode(settings.sidebarProjectGroupingMode); + } + updateSettings({ + sidebarProjectGroupingMode: projectGroupingModeFromToggle( + checked, + lastEnabledProjectGroupingMode.current, + ), + }); + }} + aria-label="Project Grouping" + /> + } + /> + { }); it("combines reconnect progress with the latest failure", () => { - expect( - connectionStatusText({ - phase: "reconnecting", - error: "Relay request timed out.", - traceId: "trace-retry", - }), - ).toBe("Failed to connect. Reconnecting... Reason: Relay request timed out."); + const connection = { + phase: "reconnecting", + error: "Relay request timed out.", + traceId: "trace-retry", + } as const; + expect(connectionStatusText(connection)).toBe( + "Failed to connect. Reconnecting... Reason: Relay request timed out.", + ); + expect(connectionStatusTitle(connection)).toBe("Failed to connect. Reconnecting..."); }); it("presents the supervisor's offline state without consulting shell state", () => { diff --git a/packages/client-runtime/src/connection/presentation.ts b/packages/client-runtime/src/connection/presentation.ts index ec7687dfe4..168443dece 100644 --- a/packages/client-runtime/src/connection/presentation.ts +++ b/packages/client-runtime/src/connection/presentation.ts @@ -76,6 +76,13 @@ export function connectionStatusText(connection: EnvironmentConnectionPresentati } } +export function connectionStatusTitle(connection: EnvironmentConnectionPresentation): string { + if (connection.phase === "reconnecting" && connection.error) { + return "Failed to connect. Reconnecting..."; + } + return connectionStatusText({ ...connection, error: null }); +} + export function presentEnvironmentConnection( state: SupervisorConnectionState, ): EnvironmentConnectionPresentation {