diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index bf296007bb..f742f3b96f 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -123,11 +123,7 @@ export function useThreadComposerState() { return null; } - return deriveActiveWorkStartedAt( - selectedThread.latestRun, - selectedThreadSessionActivity, - null, - ); + return deriveActiveWorkStartedAt(selectedThread.latestRun, selectedThreadSessionActivity, null); }, [selectedThreadDetail, selectedThreadSessionActivity, selectedThreadShell]); const activeThreadBusy = !!selectedThread && threadRuntimeIsActive(selectedThread.runtime); diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts index 76336f1ef1..0b935c0d04 100644 --- a/apps/web/src/components/BranchToolbar.logic.test.ts +++ b/apps/web/src/components/BranchToolbar.logic.test.ts @@ -13,9 +13,7 @@ import { resolveBranchToolbarPrBranch, resolveBranchToolbarValue, resolveLockedWorkspaceLabel, - resolveLocalCheckoutBranchMismatch, - resolvePreviousWorktreeLabel, - resolvePreviousWorktreeSeed, + resolveWorkspaceDisplayName, shouldIncludeBranchPickerItem, shouldShowEnvironmentIndicator, } from "./BranchToolbar.logic"; @@ -470,6 +468,18 @@ describe("resolveLockedWorkspaceLabel", () => { }); }); +describe("resolveWorkspaceDisplayName", () => { + it("returns the final folder for POSIX and Windows paths", () => { + expect(resolveWorkspaceDisplayName("/repo/.t3/worktrees/feature-a")).toBe("feature-a"); + expect(resolveWorkspaceDisplayName("C:\\code\\project\\feature-b\\")).toBe("feature-b"); + }); + + it("handles missing and root paths", () => { + expect(resolveWorkspaceDisplayName(null)).toBeNull(); + expect(resolveWorkspaceDisplayName("/")).toBe("/"); + }); +}); + describe("deriveLocalBranchNameFromRemoteRef", () => { it("strips the remote prefix from a remote ref", () => { expect(deriveLocalBranchNameFromRemoteRef("origin/feature/demo")).toBe("feature/demo"); diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts index d9737f17a3..bb7769875e 100644 --- a/apps/web/src/components/BranchToolbar.logic.ts +++ b/apps/web/src/components/BranchToolbar.logic.ts @@ -66,51 +66,11 @@ export function resolveLockedWorkspaceLabel(activeWorktreePath: string | null): return activeWorktreePath ? "Worktree" : "Local checkout"; } -export interface PreviousWorktreeSeed { - branch: string | null; - worktreePath: string; -} - -// The most recently touched worktree in the project that the composer isn't -// already pointing at. Backs the "Previous worktree" entry in the workspace -// selector so a follow-up thread can hop back into the worktree you just -// worked in without hunting for its branch. Archived threads don't compete — -// the rest of the UI hides them, so their worktrees shouldn't resurface here. -export function resolvePreviousWorktreeSeed(input: { - threads: ReadonlyArray<{ - branch: string | null; - worktreePath: string | null; - updatedAt: string; - archivedAt?: string | null; - }>; - currentWorktreePath: string | null; -}): PreviousWorktreeSeed | null { - let latest: { branch: string | null; worktreePath: string; updatedAt: number } | null = null; - for (const thread of input.threads) { - if ( - !thread.worktreePath || - thread.worktreePath === input.currentWorktreePath || - (thread.archivedAt ?? null) !== null - ) { - continue; - } - const updatedAt = toSortableTimestamp(thread.updatedAt); - if (updatedAt === null) { - continue; - } - if (latest === null || updatedAt > latest.updatedAt) { - latest = { - branch: thread.branch, - worktreePath: thread.worktreePath, - updatedAt, - }; - } - } - return latest === null ? null : { branch: latest.branch, worktreePath: latest.worktreePath }; -} - -export function resolvePreviousWorktreeLabel(seed: PreviousWorktreeSeed): string { - return seed.branch ? `Previous worktree (${seed.branch})` : "Previous worktree"; +export function resolveWorkspaceDisplayName(path: string | null): string | null { + if (!path) return null; + const normalizedPath = path.replace(/[\\/]+$/, ""); + if (normalizedPath.length === 0) return path; + return normalizedPath.split(/[\\/]/).at(-1) ?? normalizedPath; } export function resolveEffectiveEnvMode(input: { diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsx index f7d1856da0..999e6bef5f 100644 --- a/apps/web/src/components/BranchToolbar.tsx +++ b/apps/web/src/components/BranchToolbar.tsx @@ -42,6 +42,8 @@ import { import { Separator } from "./ui/separator"; interface BranchToolbarProps { + layout?: "composer" | "panel"; + panelSection?: "all" | "workspace" | "branch"; environmentId: EnvironmentId; threadId: ThreadId; draftId?: DraftId; @@ -215,6 +217,8 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({ }); export const BranchToolbar = memo(function BranchToolbar({ + layout = "composer", + panelSection = "all", environmentId, threadId, draftId, @@ -303,6 +307,40 @@ export const BranchToolbar = memo(function BranchToolbar({ if (!hasActiveThread || !activeProject) return null; + if (layout === "panel") { + return ( +
+ {panelSection !== "branch" ? ( + + ) : null} + {panelSection !== "workspace" ? ( + + ) : null} +
+ ); + } + return (
{isMobile ? ( diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index 04b25e2680..e91acc1e71 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -32,6 +32,10 @@ import { threadEnvironment } from "../state/threads"; import { useAtomCommand } from "../state/use-atom-command"; import { vcsEnvironment } from "../state/vcs"; import { cn } from "../lib/utils"; +import { + THREAD_DETAILS_PANEL_ICON_CLASS, + THREAD_DETAILS_PANEL_ROW_CLASS, +} from "./chat/threadDetailsPanelStyles"; import { parsePullRequestReference } from "../pullRequestReference"; import { getSourceControlPresentation } from "../sourceControlPresentation"; import { @@ -66,6 +70,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; interface BranchToolbarBranchSelectorProps { className?: string; + displayMode?: "toolbar" | "panel"; environmentId: EnvironmentId; threadId: ThreadId; draftId?: DraftId; @@ -85,6 +90,7 @@ function toBranchActionErrorMessage(error: unknown): string { export function BranchToolbarBranchSelector({ className, + displayMode = "toolbar", environmentId, threadId, draftId, @@ -716,7 +722,13 @@ export function BranchToolbarBranchSelector({ open={isBranchMenuOpen} value={resolvedActiveBranch} > -
+
{branchPr && branchPrStatus ? ( {branchPrTooltip} ) : null} - {/* Context menu lives on the wrapper: the disabled Button has - pointer-events-none, so the trigger itself never sees right-clicks - while refs are loading or a branch action is pending. */} - handleBranchContextMenu(event, resolvedActiveBranch)} + } + className={cn( + "min-w-0 text-muted-foreground/70 hover:text-foreground/80", + displayMode === "panel" && THREAD_DETAILS_PANEL_ROW_CLASS, + )} + disabled={isInitialBranchesLoadPending || isBranchActionPending} > - } - className="min-w-0 max-w-full text-muted-foreground/70 hover:text-foreground/80" - disabled={isInitialBranchesLoadPending || isBranchActionPending} + + - - {triggerLabel} - - - + {triggerLabel} + + +
- +
void; - previousWorktreeLabel?: string | null; - onUsePreviousWorktree?: () => void; + displayMode?: "toolbar" | "panel"; } export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSelector({ envLocked, effectiveEnvMode, activeWorktreePath, + workspaceRoot = null, onEnvModeChange, - previousWorktreeLabel, - onUsePreviousWorktree, + displayMode = "toolbar", }: BranchToolbarEnvModeSelectorProps) { - const showPreviousWorktree = Boolean(previousWorktreeLabel && onUsePreviousWorktree); + const workspacePath = displayMode === "panel" ? (activeWorktreePath ?? workspaceRoot) : null; + const workspaceDisplayName = resolveWorkspaceDisplayName(workspacePath); + const workspaceKind = activeWorktreePath ? "Worktree" : "Project folder"; const envModeItems = useMemo( () => [ - { value: "local", label: resolveCurrentWorkspaceLabel(activeWorktreePath) }, + { + value: "local", + label: workspaceDisplayName ?? resolveCurrentWorkspaceLabel(activeWorktreePath), + }, { value: "worktree", label: resolveEnvModeLabel("worktree") }, ...(showPreviousWorktree && previousWorktreeLabel ? [{ value: PREVIOUS_WORKTREE_SELECT_VALUE, label: previousWorktreeLabel }] : []), ], - [activeWorktreePath, previousWorktreeLabel, showPreviousWorktree], + [activeWorktreePath, workspaceDisplayName], ); if (envLocked) { - return ( - - {activeWorktreePath ? ( - <> - - {resolveLockedWorkspaceLabel(activeWorktreePath)} - - ) : ( - <> - - {resolveLockedWorkspaceLabel(activeWorktreePath)} - + const lockedRow = ( + + {activeWorktreePath ? ( + + ) : ( + + )} + + {workspaceDisplayName ?? resolveLockedWorkspaceLabel(activeWorktreePath)} + + {displayMode === "panel" ? ( + + {workspaceKind} + + ) : null} ); + + if (!workspacePath) return lockedRow; + + return ( + + + {workspacePath} + + ); } return ( @@ -79,21 +112,42 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe }} items={envModeItems} > - - {effectiveEnvMode === "worktree" ? ( - - ) : activeWorktreePath ? ( - - ) : ( - - )} - - + + + } + > + {effectiveEnvMode === "worktree" ? ( + + ) : activeWorktreePath ? ( + + ) : ( + + )} + + {displayMode === "panel" ? ( + + {effectiveEnvMode === "worktree" && !activeWorktreePath ? "Create" : workspaceKind} + + ) : null} + + {workspacePath ? {workspacePath} : null} + Workspace diff --git a/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx b/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx index e4ed54758f..6c80d48d4e 100644 --- a/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx +++ b/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx @@ -3,6 +3,12 @@ import { CloudIcon, MonitorIcon } from "lucide-react"; import { memo, useMemo } from "react"; import type { EnvironmentOption } from "./BranchToolbar.logic"; +import { cn } from "../lib/utils"; +import { + THREAD_DETAILS_PANEL_ICON_CLASS, + THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS, + THREAD_DETAILS_PANEL_ROW_CLASS, +} from "./chat/threadDetailsPanelStyles"; import { Select, SelectGroup, @@ -17,9 +23,8 @@ interface BranchToolbarEnvironmentSelectorProps { envLocked: boolean; environmentId: EnvironmentId; availableEnvironments: readonly EnvironmentOption[]; - // Absent when there is only one environment to show: the indicator still - // renders (as a static label) so remote projects are always identifiable. - onEnvironmentChange?: (environmentId: EnvironmentId) => void; + onEnvironmentChange: (environmentId: EnvironmentId) => void; + displayMode?: "toolbar" | "panel"; } export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvironmentSelector({ @@ -27,6 +32,7 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir environmentId, availableEnvironments, onEnvironmentChange, + displayMode = "toolbar", }: BranchToolbarEnvironmentSelectorProps) { const activeEnvironment = useMemo(() => { return availableEnvironments.find((env) => env.environmentId === environmentId) ?? null; @@ -43,11 +49,20 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir if (envLocked || onEnvironmentChange === undefined) { return ( - + {activeEnvironment?.isPrimary ? ( - + ) : ( - + )} {activeEnvironment?.label ?? "Run on"} @@ -63,14 +78,18 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir > {activeEnvironment?.isPrimary ? ( - + ) : ( - + )} diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts index 504d8cf8c0..fac77a6aa3 100644 --- a/apps/web/src/components/ChatView.logic.ts +++ b/apps/web/src/components/ChatView.logic.ts @@ -17,6 +17,7 @@ import { type ComposerImageAttachment, type DraftThreadState } from "../composer import * as Schema from "effect/Schema"; import { appAtomRegistry } from "../rpc/atomRegistry"; import { environmentThreadDetails } from "../state/threads"; +import { waitForAtomValue } from "../state/waitForAtomValue"; import { filterTerminalContextsWithText, stripInlineTerminalContextPlaceholders, @@ -454,43 +455,11 @@ export async function waitForStartedServerThread( timeoutMs = 1_000, ): Promise { const threadAtom = environmentThreadDetails.detailAtom(threadRef); - const getThread = () => appAtomRegistry.get(threadAtom); - const thread = getThread(); - - if (threadHasStarted(thread)) { - return true; - } - - return await new Promise((resolve) => { - let settled = false; - let timeoutId: ReturnType | null = null; - const finish = (result: boolean) => { - if (settled) { - return; - } - settled = true; - if (timeoutId !== null) { - globalThis.clearTimeout(timeoutId); - } - unsubscribe(); - resolve(result); - }; - - const unsubscribe = appAtomRegistry.subscribe(threadAtom, (thread) => { - if (!threadHasStarted(thread)) { - return; - } - finish(true); - }); - - if (threadHasStarted(getThread())) { - finish(true); - return; - } - - timeoutId = globalThis.setTimeout(() => { - finish(false); - }, timeoutMs); + return waitForAtomValue({ + registry: appAtomRegistry, + atom: threadAtom, + predicate: threadHasStarted, + timeoutMs, }); } diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 2fd8c4cfe6..a6ac0477a3 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -21,11 +21,7 @@ import { TerminalOpenInput, } from "@t3tools/contracts"; import type { ThreadWorkEntry } from "@t3tools/client-runtime/state/shell"; -import { - connectionStatusTitle, - type EnvironmentConnectionPresentation, -} from "@t3tools/client-runtime/connection"; -import { effectiveSettled, effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled"; +import { type EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection"; import { parseScopedThreadKey, scopedThreadKey, @@ -118,10 +114,16 @@ import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries"; import { isCommandPaletteOpen } from "../commandPaletteBus"; import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git"; import { useMediaQuery } from "../hooks/useMediaQuery"; -import { RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY } from "../rightPanelLayout"; +import { useElementWidth } from "../hooks/useElementWidth"; +import { usePreviewPanelInlineSize } from "../hooks/usePreviewPanelInlineSize"; +import { + RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY, + resolveThreadPanelPresentation, +} from "../rightPanelLayout"; import { selectActiveRightPanel, selectActiveRightPanelSurface, + selectThreadPanelOpen, selectThreadRightPanelState, type RightPanelSurface, useRightPanelStore, @@ -142,18 +144,10 @@ import { } from "../previewMiniPlayerStore"; import { RightPanelTabs } from "./RightPanelTabs"; import { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider"; -import { BranchToolbar } from "./BranchToolbar"; import { resolveShortcutCommand, shortcutLabelForCommand } from "../keybindings"; import PlanSidebar from "./PlanSidebar"; import ThreadTerminalDrawer from "./ThreadTerminalDrawer"; -import { - AlarmClockIcon, - CheckCircle2Icon, - ChevronDownIcon, - GitBranchIcon, - TriangleAlertIcon, - WifiOffIcon, -} from "lucide-react"; +import { ChevronDownIcon } from "lucide-react"; import { cn, randomHex } from "~/lib/utils"; import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar"; import { stackedThreadToast, toastManager } from "./ui/toast"; @@ -221,6 +215,7 @@ import { useThreadProposedPlans, useThreadRefs, useThreadVisibleTurnItems, + waitForThreadShell, } from "../state/entities"; import { environmentShell } from "../state/shell"; import { ChatComposer, type ChatComposerHandle } from "./chat/ChatComposer"; @@ -229,8 +224,13 @@ import { ExpandedImageDialog } from "./chat/ExpandedImageDialog"; import { PullRequestThreadDialog } from "./PullRequestThreadDialog"; import { MessagesTimeline } from "./chat/MessagesTimeline"; import { ChatHeader } from "./chat/ChatHeader"; -import { PanelLayoutControls, RightPanelMaximizeControl } from "./chat/PanelLayoutControls"; +import { + PanelLayoutControls, + type PanelLayoutControlsProps, + RightPanelMaximizeControl, +} from "./chat/PanelLayoutControls"; import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview"; +import { ThreadDetailsPanel, type ThreadDetailsPanelProps } from "./chat/ThreadDetailsPanel"; import { NoActiveThreadState } from "./NoActiveThreadState"; import { resolveEffectiveEnvMode, resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic"; import { @@ -239,8 +239,6 @@ import { shouldShowProviderStatusBanner, } from "./chat/ProviderStatusBanner"; import { ThreadErrorBanner } from "./chat/ThreadErrorBanner"; -import { resolveThreadPr } from "./ThreadStatusIndicators"; -import { ComposerBannerStack, type ComposerBannerStackItem } from "./chat/ComposerBannerStack"; import { QueuedRunsControl } from "./chat/QueuedRunsControl"; import type { ComposerDispatchMode } from "./chat/composerDispatch"; import { @@ -281,7 +279,6 @@ import { sanitizeThreadErrorMessage } from "~/rpc/transportError"; import { RightPanelSheet } from "./RightPanelSheet"; import { previewEnvironment } from "../state/preview"; import { useAtomCommand } from "../state/use-atom-command"; -import { Button } from "./ui/button"; import { AlertDialog, AlertDialogClose, @@ -1288,6 +1285,9 @@ function ChatViewContent(props: ChatViewProps) { const [pendingUserInputQuestionIndexByRequestId, setPendingUserInputQuestionIndexByRequestId] = useState>({}); const shouldUsePlanSidebarSheet = useMediaQuery(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY); + const [workspaceLayoutRef, workspaceLayoutWidth] = useElementWidth(); + const previewPanelInlineSize = usePreviewPanelInlineSize(); + const threadPanelPopoverAnchorRef = useRef(null); // Tracks whether the user explicitly dismissed the sidebar for the active turn. const planSidebarDismissedForTurnRef = useRef(null); // When set, the thread-change reset effect will open the sidebar instead of closing it. @@ -1548,6 +1548,18 @@ function ChatViewContent(props: ChatViewProps) { const rightPanelMaximized = canMaximizeRightPanel && maximizedRightPanelThreadKey === routeThreadKey; const inlineRightPanelOwnsTitleBar = rightPanelOpen && !shouldUsePlanSidebarSheet; + const threadPanelPresentation = resolveThreadPanelPresentation( + workspaceLayoutWidth, + inlineRightPanelOwnsTitleBar ? previewPanelInlineSize.width : 0, + rightPanelMaximized, + ); + const threadPanelOpen = useRightPanelStore((state) => + selectThreadPanelOpen( + state.threadPanelVisibilityByThreadKey, + activeThreadRef, + threadPanelPresentation, + ), + ); useEffect(() => { if (!activeThreadRef) return; @@ -1738,8 +1750,6 @@ function ChatViewContent(props: ChatViewProps) { }); return envs; }, [activeProject, allProjects, projectGroupingSettings, primaryEnvironmentId, environmentById]); - const hasMultipleEnvironments = logicalProjectEnvironments.length > 1; - const openPullRequestDialog = useCallback( (reference?: string) => { if (!canCheckoutPullRequestIntoThread) { @@ -1897,154 +1907,18 @@ function ChatViewContent(props: ChatViewProps) { hasMultipleRegisteredEnvironments && activeThread ? `${environmentById.get(activeThread.environmentId)?.label ?? serverConfig?.environment.label ?? activeThread.environmentId} server` : "server"; - const serverUpdateEnvironmentId = activeThread?.environmentId ?? null; - const versionMismatchSelfUpdate = resolveServerSelfUpdateCapability(serverConfig); - const serverUpdateState = useAtomValue( - serverEnvironment.updateStateAtom(serverUpdateEnvironmentId), - ); - const systemComposerBannerItems = useMemo(() => { - const items: ComposerBannerStackItem[] = []; - const updateRunning = serverUpdateState.status === "running"; - const unavailableConnection = activeEnvironmentUnavailableState?.connection ?? null; - const environmentReconnecting = - unavailableConnection !== null && - (unavailableConnection.phase === "connecting" || - unavailableConnection.phase === "reconnecting"); - // Reconnecting to a version-skewed server with no update in flight - // usually means the server is restarting mid-update and a refresh wiped - // the in-memory update state. Fold the reconnect and version banners - // into one calm line instead of stacking "Failed to connect" on - // "versions differ". A failed update never folds: its error and retry - // action must stay visible. - const reconnectingThroughVersionSkew = - serverUpdateState.status === "idle" && environmentReconnecting && versionMismatch !== null; - // While an update runs, transient connect blips are expected (the server - // restarts) and the update banner already shows progress. Hard failure - // phases still surface so the Reconnect action stays reachable. - const suppressUnavailableBanner = updateRunning && environmentReconnecting; - if (activeEnvironmentUnavailableState && unavailableConnection && !suppressUnavailableBanner) { - if (reconnectingThroughVersionSkew) { - items.push({ - id: `environment-unavailable:${activeEnvironmentUnavailableState.environmentId}`, - variant: "default", - icon: ( -