TypeScript
feat(web): choose what the thread details card shows (#26904)
Theo Browned7935f135f50
diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.tsindex c80498c14c1..ec5062f9105 100644--- a/apps/desktop/src/settings/DesktopClientSettings.test.ts+++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts@@ -65,6 +65,7 @@ const clientSettings: ClientSettings = {boringSidebarEnabled: false,boringSidebarMultilineRows: false,threadDetailsUsageEnabled: false,+ threadDetailsItems: {},legacySidebarEnabled: false,sidebarWorkingShelfEnabled: false,loadBalancingEnabled: false,diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex b9104836b62..de76f47844b 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -1228,9 +1228,6 @@ export default function ChatView(props: ChatViewProps) {const canChangeEnvironment =hasMultipleEnvironments && !envLocked && draftId !== null && !draftThread?.promotedTo;- const threadDetailsUsageEnabled = useClientSettings(- (settings) => settings.threadDetailsUsageEnabled,- );const loadBalancingSettings = useClientSettings((settings) => ({loadBalancingEnabled: settings.loadBalancingEnabled,loadBalancingWeights: settings.loadBalancingWeights,@@ -3773,16 +3770,12 @@ export default function ChatView(props: ChatViewProps) {onAddProjectScript={saveProjectScriptStable}onUpdateProjectScript={updateProjectScriptStable}onDeleteProjectScript={deleteProjectScriptStable}- usage={- threadDetailsUsageEnabled- ? {- providerInstanceId: activeProviderInstanceId,- providers: providerStatuses,- sources: serverConfig?.usageLimitSources ?? EMPTY_USAGE_LIMIT_SOURCES,- contextWindow: activeContextWindow,- }- : undefined- }+ usage={{+ providerInstanceId: activeProviderInstanceId,+ providers: providerStatuses,+ sources: serverConfig?.usageLimitSources ?? EMPTY_USAGE_LIMIT_SOURCES,+ contextWindow: activeContextWindow,+ }}/><PullRequestThreadDialogHostdiff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsxindex 7c017223daf..cae352e6d6b 100644--- a/apps/web/src/components/GitActionsControl.tsx+++ b/apps/web/src/components/GitActionsControl.tsx@@ -117,6 +117,8 @@ interface GitActionsControlProps {activeThreadRef: ScopedThreadRef | null;draftId?: DraftId;compact?: boolean;+ showActions?: boolean;+ showChanges?: boolean;onOpenChanges?: () => void;}@@ -926,6 +928,8 @@ export default function GitActionsControl({activeThreadRef,draftId,compact = false,+ showActions = true,+ showChanges = true,onOpenChanges,}: GitActionsControlProps) {const panelAnchorRef = useRef<HTMLDivElement | null>(null);@@ -1476,7 +1480,7 @@ export default function GitActionsControl({return (<>- {!isRepo ? (+ {!showActions ? null : !isRepo ? (<ThreadDetailsControlsize="xs"variant="ghost"@@ -1618,7 +1622,7 @@ export default function GitActionsControl({</div>)}- {isRepo && !quietEmptyDraft ? (+ {showChanges && isRepo && !quietEmptyDraft ? (<ThreadDetailsControltype="button"variant="ghost"@@ -1826,13 +1830,16 @@ export default function GitActionsControl({</DialogPopup></Dialog>- <PublishRepositoryDialog- open={isPublishDialogOpen}- onOpenChange={setIsPublishDialogOpen}- environmentId={activeEnvironmentId}- threadRef={activeThreadRef}- gitCwd={gitCwd}- />+ {/* Its discovery query should stop when the Git actions row that opens it is hidden. */}+ {showActions ? (+ <PublishRepositoryDialog+ open={isPublishDialogOpen}+ onOpenChange={setIsPublishDialogOpen}+ environmentId={activeEnvironmentId}+ threadRef={activeThreadRef}+ gitCwd={gitCwd}+ />+ ) : null}<Dialogopen={pendingDefaultBranchAction !== null}diff --git a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx b/apps/web/src/components/chat/OpenInPicker.browser.test.tsxindex b34867b2668..720ce4d6c44 100644--- a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx+++ b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx@@ -189,6 +189,19 @@ describe("host editor access", () => {});});+describe("remote editor links", () => {+ it("opens the link from the fallback when the picker is not mounted", async () => {+ await using fixture = await setup();+ const { screen, pressOpenFavorite, FavoriteEditorFallback } = fixture;+ state.remote = { mode: "remote-links", host: { kind: "ssh-alias", host: "sol" } };+ await act(async () => screen.rerender(<FavoriteEditorFallback />));++ expect((await pressOpenFavorite()).defaultPrevented).toBe(true);+ expect(state.openUrl).toHaveBeenCalledWith(expect.stringContaining("ssh-remote+sol"));+ expect(state.run).not.toHaveBeenCalled();+ });+});+describe("open in editor announcement", () => {it("speaks only after the shortcut opened the editor, from the picker or the fallback", async () => {await using fixture = await setup();diff --git a/apps/web/src/components/chat/OpenInPickerShortcut.ts b/apps/web/src/components/chat/OpenInPickerShortcut.tsindex 8c8249c67b1..833c3f37849 100644--- a/apps/web/src/components/chat/OpenInPickerShortcut.ts+++ b/apps/web/src/components/chat/OpenInPickerShortcut.ts@@ -1,11 +1,16 @@-import type { EditorId, EnvironmentId, ResolvedKeybindingsConfig } from "@t3tools/contracts";+import {+ buildRemoteOpenUrl,+ type EditorId,+ type EnvironmentId,+ type ResolvedKeybindingsConfig,+} from "@t3tools/contracts";import { useEffect } from "react";import { usePreferredEditor } from "../../editorPreferences";import { editorLabelForPlatform } from "../../editorLabels";import { isOpenFavoriteEditorShortcut } from "../../keybindings";import { announce } from "../../lib/announce";-import { useRemoteOpenState } from "../../remoteOpen";+import { openRemoteEditorUrl, useRemoteCapableEditors, useRemoteOpenState } from "../../remoteOpen";import { registerCommands } from "../../shortcuts/dispatcher";import { shellEnvironment } from "../../state/shell";import { useAtomCommand } from "../../state/use-atom-command";@@ -49,18 +54,39 @@ export function useOpenFavoriteEditorShortcut({openInCwd: string | null;}) {const openInEditorMutation = useAtomCommand(shellEnvironment.openInEditor, "open in editor");- const [preferredEditor] = usePreferredEditor(availableEditors);const remote = useRemoteOpenState(environmentId);+ const remoteCapableEditors = useRemoteCapableEditors();+ // Matches the picker: remote editors run on the viewing machine.+ const [preferredEditor] = usePreferredEditor(+ remote.mode === "local-exec" ? availableEditors : remoteCapableEditors,+ );- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enabled locally+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enableduseEffect(() => {- if (!enabled || remote.mode !== "local-exec") return;+ if (!enabled || remote.mode === "remote-unavailable") return;const handler = (event: globalThis.KeyboardEvent) => {- if (event.defaultPrevented || !isOpenFavoriteEditorShortcut(event, keybindings)) return;+ if (+ event.repeat ||+ event.defaultPrevented ||+ !isOpenFavoriteEditorShortcut(event, keybindings)+ )+ return;if (!openInCwd || !preferredEditor) return;event.preventDefault();const label = editorLabelForPlatform(preferredEditor, navigator.platform);+ if (remote.mode === "remote-links") {+ const url = buildRemoteOpenUrl({+ editor: preferredEditor,+ ...remote.host,+ absolutePath: openInCwd,+ });+ if (url === undefined) return;+ void openRemoteEditorUrl(url).then((opened) => {+ if (opened) announce(`Opened in ${label}`);+ });+ return;+ }void openInEditorMutation({environmentId,input: {@@ -80,6 +106,6 @@ export function useOpenFavoriteEditorShortcut({openInCwd,openInEditorMutation,preferredEditor,- remote.mode,+ remote,]);}diff --git a/apps/web/src/components/chat/ThreadAutomationsPanel.tsx b/apps/web/src/components/chat/ThreadAutomationsPanel.tsxindex 20ecde32722..ca2497bd20e 100644--- a/apps/web/src/components/chat/ThreadAutomationsPanel.tsx+++ b/apps/web/src/components/chat/ThreadAutomationsPanel.tsx@@ -153,12 +153,6 @@ export function ThreadAutomationsPanel(props: {</Tooltip>}>- {tasksQuery.error !== null ? (- <p className="px-2.5 py-1.5 text-2xs text-destructive">- Could not load automations: {tasksQuery.error}- </p>- ) : null}-<ul className="m-0 list-none p-0">{boundTasks.map((task) => (<li@@ -242,6 +236,12 @@ export function ThreadAutomationsPanel(props: {</li>))}</ul>+ {/* Kept last: the details card treats a section whose last child is empty as empty. */}+ {tasksQuery.error !== null ? (+ <p className="px-2.5 py-1.5 text-2xs text-destructive">+ Could not load automations: {tasksQuery.error}+ </p>+ ) : null}</ThreadDetailsSection>);}diff --git a/apps/web/src/components/chat/ThreadDetailsCard.browser.test.tsx b/apps/web/src/components/chat/ThreadDetailsCard.browser.test.tsxindex 37110875ed0..a8728d7879d 100644--- a/apps/web/src/components/chat/ThreadDetailsCard.browser.test.tsx+++ b/apps/web/src/components/chat/ThreadDetailsCard.browser.test.tsx@@ -42,10 +42,13 @@ function Card({threadRef,inline,fixture,+ rows = 1,}: {threadRef: ScopedThreadRef;inline: boolean;fixture: ReturnType<typeof setup>;+ /** Rows of 100px shown at full density. Compact always takes 50px. */+ rows?: number;}) {return (// The web root renders in StrictMode, which re-runs ref callbacks on every mount.@@ -63,8 +66,17 @@ function Card({detailsCardPlacement: inline ? placement : null,}}>- <ThreadDetailsCard threadRef={threadRef} anchor={fixture.anchor} handle={fixture.handle}>- {() => <p>Details for {threadRef.threadId}</p>}+ <ThreadDetailsCard+ threadRef={threadRef}+ anchor={fixture.anchor}+ handle={fixture.handle}+ contentKey={String(rows)}+ >+ {(density) => (+ <p style={{ height: density === "full" ? rows * 100 : 50 }}>+ Details for {threadRef.threadId}+ </p>+ )}</ThreadDetailsCard></ChatCanvasContext></StrictMode>@@ -136,3 +148,13 @@ it("reopens after a normal close", async () => {await setOpen(true);await expect.element(page.getByText("Details for thread-b")).toBeVisible();});++it("returns to full density when hidden items make the content fit", async () => {+ using fixture = setup();+ await using screen = await render(<Card threadRef={threadB} inline fixture={fixture} rows={6} />);+ const card = page.getByRole("region", { name: "Thread details" });+ await expect.element(card).toHaveAttribute("data-density", "compact");++ await screen.rerender(<Card threadRef={threadB} inline fixture={fixture} rows={2} />);+ await expect.element(card).toHaveAttribute("data-density", "full");+});diff --git a/apps/web/src/components/chat/ThreadDetailsCard.tsx b/apps/web/src/components/chat/ThreadDetailsCard.tsxindex 4add56b80eb..a5df136f146 100644--- a/apps/web/src/components/chat/ThreadDetailsCard.tsx+++ b/apps/web/src/components/chat/ThreadDetailsCard.tsx@@ -1,5 +1,11 @@import { workspaceAreaProps } from "../../lib/workspaceFocus";-import { useLayoutEffect, useState, type ReactNode, type RefObject } from "react";+import {+ useLayoutEffect,+ useState,+ type MouseEventHandler,+ type ReactNode,+ type RefObject,+} from "react";import type { ScopedThreadRef } from "@t3tools/contracts";import { ScrollArea } from "../ui/scroll-area";import { cn } from "../../lib/utils";@@ -17,11 +23,16 @@ export function ThreadDetailsCard({threadRef,anchor,handle,+ contentKey,+ onContextMenu,children,}: {threadRef: ScopedThreadRef;anchor: RefObject<Element | null>;handle: ReturnType<typeof PopoverCreateHandle>;+ /** Changes when the set of rendered items changes, so cached heights are measured again. */+ contentKey: string;+ onContextMenu?: MouseEventHandler<HTMLDivElement>;children: (density: "full" | "compact" | "essential") => ReactNode;}) {const detailsArea = workspaceAreaProps("details", 3, "Thread details");@@ -36,7 +47,7 @@ export function ThreadDetailsCard({const popoverOpen = useRightPanelStore((state) =>selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, threadRef, "popover"),);- const measurementKey = `${threadRef.environmentId}:${threadRef.threadId}:${preferredPlacement?.width ?? "popup"}`;+ const measurementKey = `${threadRef.environmentId}:${threadRef.threadId}:${preferredPlacement?.width ?? "popup"}:${contentKey}`;const [measurements, setMeasurements] = useState({key: measurementKey,heights: { full: 0, compact: 0 },@@ -109,6 +120,7 @@ export function ThreadDetailsCard({"max-h-[min(calc(100dvh-6.5rem),calc(var(--available-height,100dvh)-1rem))]",)}style={placement ? { maxHeight: height } : undefined}+ onContextMenu={onContextMenu}data-thread-details-card><ScrollArea scrollFade className="min-h-0">diff --git a/apps/web/src/components/chat/ThreadDetailsItemsMenu.tsx b/apps/web/src/components/chat/ThreadDetailsItemsMenu.tsxnew file mode 100644index 00000000000..d84c13809ea--- /dev/null+++ b/apps/web/src/components/chat/ThreadDetailsItemsMenu.tsx@@ -0,0 +1,45 @@+import {+ getClientSettings,+ updateClientSettings,+ useClientSettings,+} from "../../hooks/useSettings";+import { MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuSeparator } from "../ui/menu";+import {+ isDefaultThreadDetailsVisibility,+ resolveThreadDetailsVisibility,+ RESET_THREAD_DETAILS_ITEMS,+ setThreadDetailsItem,+ THREAD_DETAILS_ITEMS,+} from "./threadDetailsItems";++/** Menu body that shows and hides thread details items. The card's context menu and Settings share it. */+export function ThreadDetailsItemsMenuItems() {+ const visibility = useClientSettings(resolveThreadDetailsVisibility);+ return (+ <>+ <MenuGroup>+ <MenuGroupLabel>Show in thread details</MenuGroupLabel>+ {THREAD_DETAILS_ITEMS.map((item) => (+ <MenuCheckboxItem+ key={item.id}+ checked={visibility[item.id]}+ onCheckedChange={(checked) =>+ updateClientSettings({+ threadDetailsItems: setThreadDetailsItem(getClientSettings(), item, checked),+ })+ }+ >+ {item.label}+ </MenuCheckboxItem>+ ))}+ </MenuGroup>+ <MenuSeparator />+ <MenuItem+ disabled={isDefaultThreadDetailsVisibility(visibility)}+ onClick={() => updateClientSettings(RESET_THREAD_DETAILS_ITEMS)}+ >+ Reset to default+ </MenuItem>+ </>+ );+}diff --git a/apps/web/src/components/chat/ThreadDetailsPanel.tsx b/apps/web/src/components/chat/ThreadDetailsPanel.tsxindex 77a6d157639..35a954db9d4 100644--- a/apps/web/src/components/chat/ThreadDetailsPanel.tsx+++ b/apps/web/src/components/chat/ThreadDetailsPanel.tsx@@ -16,7 +16,7 @@ import ProjectScriptsControl, {type NewProjectScriptInput,type ProjectScriptActionResult,} from "../ProjectScriptsControl";-import { memo, type ComponentProps } from "react";+import { memo, useState, type ComponentProps } from "react";import { ThreadDetailsCard } from "./ThreadDetailsCard";import { OpenInPicker } from "./OpenInPicker";import { ThreadDetailsSection } from "./ThreadDetailsSection";@@ -24,6 +24,17 @@ import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";import { ThreadServersPanel } from "./ThreadServersPanel";import { ThreadDetailsUsage, type ThreadDetailsUsageInput } from "./ThreadDetailsUsage";+import { ThreadDetailsItemsMenuItems } from "./ThreadDetailsItemsMenu";+import { resolveThreadDetailsVisibility, THREAD_DETAILS_ITEMS } from "./threadDetailsItems";+import { useClientSettings } from "../../hooks/useSettings";+import { cn } from "../../lib/utils";+import { SlidersHorizontalIcon } from "lucide-react";+import { ThreadDetailsControl } from "./ThreadDetailsControl";+import {+ THREAD_DETAILS_PANEL_ICON_CLASS,+ THREAD_DETAILS_PANEL_LABEL_CLASS,+} from "./threadDetailsPanelStyles";+import { Menu, MenuPopup } from "../ui/menu";const GitActionsControl = memo(BaseGitActionsControl);@@ -68,14 +79,15 @@ interface ThreadDetailsPanelProps extends Pick<input: NewProjectScriptInput,) => Promise<ProjectScriptActionResult>;onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;- /** Set only while the Labs usage readout is on. */- usage?: ThreadDetailsUsageInput | undefined;+ usage: ThreadDetailsUsageInput;}export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {+ const visible = useClientSettings(resolveThreadDetailsVisibility);+ const [menuPosition, setMenuPosition] = useState<{ x: number; y: number } | null>(null);const fileScripts = useT3ProjectFileScripts(props.environmentId,- props.activeProjectScripts ? props.gitCwd : null,+ props.activeProjectScripts && visible.scripts ? props.gitCwd : null,);const activeThreadRef = { environmentId: props.environmentId, threadId: props.threadId };const branchToolbarProps = {@@ -109,99 +121,181 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {threadRef={{ environmentId: props.environmentId, threadId: props.threadId }}anchor={props.anchor}handle={props.handle}+ contentKey={THREAD_DETAILS_ITEMS.filter((item) => visible[item.id])+ .map((item) => item.id)+ .join(",")}+ onContextMenu={(event) => {+ // Popups the card opens bubble here through React; they, fields, links, and selected text+ // keep their own menus.+ const target = event.target;+ const selection = window.getSelection();+ if (+ !(target instanceof Element) ||+ !event.currentTarget.contains(target) ||+ target.closest("input, textarea, [contenteditable], a[href]") ||+ (selection &&+ !selection.isCollapsed &&+ (event.currentTarget.contains(selection.anchorNode) ||+ event.currentTarget.contains(selection.focusNode)))+ )+ return;+ event.preventDefault();+ setMenuPosition({ x: event.clientX, y: event.clientY });+ }}>- {(density) => (- <>- <ThreadDetailsSection- headingId="thread-details-workspace-heading"- title="Workspace"- separated={false}- showHeading={false}- >- <div className="flex flex-col">- {density === "full" ? (- <BranchToolbar- layout="panel"- panelSection="workspace"- availableEnvironments={props.availableEnvironments}- {...(props.onEnvironmentChange- ? { onEnvironmentChange: props.onEnvironmentChange }- : {})}- autoEnvironmentLabel={props.autoEnvironmentLabel}- onAutoEnvironment={props.onAutoEnvironment}- {...branchToolbarProps}- />+ {(density) => {+ // Section flags follow the rows that will render, so no empty section steals the divider rule.+ const show = {+ environment: density === "full" && visible.environment,+ openIn: density !== "essential" && visible.openIn && props.showOpenInPicker,+ scripts: visible.scripts && props.activeProjectScripts !== undefined,+ branch: props.gitCwd !== null && props.isGitRepo && visible.branch,+ git:+ props.gitCwd !== null &&+ props.activeProjectName !== undefined &&+ (visible.gitActions || (visible.changes && props.isGitRepo)),+ };+ return (+ <>+ <div className="group/details-items">+ {show.environment || show.openIn || show.scripts ? (+ <ThreadDetailsSection+ headingId="thread-details-workspace-heading"+ title="Workspace"+ separated={false}+ showHeading={false}+ >+ <div className="flex flex-col">+ {show.environment ? (+ <BranchToolbar+ layout="panel"+ panelSection="workspace"+ availableEnvironments={props.availableEnvironments}+ {...(props.onEnvironmentChange+ ? { onEnvironmentChange: props.onEnvironmentChange }+ : {})}+ autoEnvironmentLabel={props.autoEnvironmentLabel}+ onAutoEnvironment={props.onAutoEnvironment}+ {...branchToolbarProps}+ />+ ) : null}++ {show.openIn ? (+ <OpenInPicker+ keybindings={props.keybindings}+ environmentId={props.environmentId}+ availableEditors={props.availableEditors}+ openInCwd={props.gitCwd}+ enableShortcut={props.openInShortcutEnabled}+ displayMode="panel"+ />+ ) : null}++ {show.scripts && props.activeProjectScripts ? (+ <ProjectScriptsControl+ environmentId={props.environmentId}+ displayMode="panel"+ scripts={props.activeProjectScripts}+ fileScripts={fileScripts}+ preferredScriptId={props.preferredScriptId}+ onRunScript={props.onRunProjectScript}+ onAddScript={props.onAddProjectScript}+ onUpdateScript={props.onUpdateProjectScript}+ onDeleteScript={props.onDeleteProjectScript}+ />+ ) : null}+ </div>+ </ThreadDetailsSection>+ ) : null}++ {props.gitCwd && (show.branch || show.git) ? (+ <ThreadDetailsSection+ headingId="thread-details-version-control-heading"+ title="Version Control"+ showHeading={false}+ separated={density === "full"}+ >+ <div className="flex flex-col">+ {show.branch ? (+ <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />+ ) : null}+ {show.git ? (+ <GitActionsControl+ compact={density !== "full"}+ showActions={visible.gitActions}+ showChanges={visible.changes}+ gitCwd={props.gitCwd}+ activeThreadRef={activeThreadRef}+ {...(props.draftId ? { draftId: props.draftId } : {})}+ {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}+ />+ ) : null}+ </div>+ </ThreadDetailsSection>+ ) : null}++ {density === "full" && !props.draftId && visible.servers ? (+ <ThreadServersPanel environmentId={props.environmentId} threadId={props.threadId} />) : null}- {density !== "essential" && props.showOpenInPicker ? (- <OpenInPicker- keybindings={props.keybindings}+ {density === "full" && !props.draftId && visible.automations ? (+ <ThreadAutomationsPanelenvironmentId={props.environmentId}- availableEditors={props.availableEditors}- openInCwd={props.gitCwd}- enableShortcut={props.openInShortcutEnabled}- displayMode="panel"+ threadId={props.threadId}/>) : null}- {props.activeProjectScripts ? (- <ProjectScriptsControl+ {density === "full" && !props.draftId && visible.lineage ? (+ <ThreadRelationshipsPanelenvironmentId={props.environmentId}- displayMode="panel"- scripts={props.activeProjectScripts}- fileScripts={fileScripts}- preferredScriptId={props.preferredScriptId}- onRunScript={props.onRunProjectScript}- onAddScript={props.onAddProjectScript}- onUpdateScript={props.onUpdateProjectScript}- onDeleteScript={props.onDeleteProjectScript}+ threadId={props.threadId}/>) : null}- </div>- </ThreadDetailsSection>- {props.gitCwd ? (- <ThreadDetailsSection- headingId="thread-details-version-control-heading"- title="Version Control"- showHeading={false}- separated={density === "full"}- >- <div className="flex flex-col">- {props.isGitRepo ? (- <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />- ) : null}- {props.activeProjectName ? (- <GitActionsControl- compact={density !== "full"}- gitCwd={props.gitCwd}- activeThreadRef={activeThreadRef}- {...(props.draftId ? { draftId: props.draftId } : {})}- {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}- />- ) : null}- </div>- </ThreadDetailsSection>- ) : null}-- {density === "full" && !props.draftId ? (- <ThreadServersPanel environmentId={props.environmentId} threadId={props.threadId} />- ) : null}-- {density === "full" && !props.draftId ? (- <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />- ) : null}+ {visible.usage ? <ThreadDetailsUsage {...props.usage} /> : null}- {density === "full" && !props.draftId ? (- <ThreadRelationshipsPanel- environmentId={props.environmentId}- threadId={props.threadId}- />- ) : null}+ {/* Shown only when no section above has content, so an emptied card can be refilled. */}+ <div className="p-2 group-has-[>section>:last-child:not(:empty)]/details-items:hidden">+ <ThreadDetailsControl+ size="xs"+ variant="ghost"+ part="row"+ panel+ onClick={(event) => {+ const rect = event.currentTarget.getBoundingClientRect();+ setMenuPosition({ x: rect.left, y: rect.bottom });+ }}+ >+ <SlidersHorizontalIcon className={THREAD_DETAILS_PANEL_ICON_CLASS} aria-hidden />+ <span className={cn("ml-0.5", THREAD_DETAILS_PANEL_LABEL_CLASS)}>+ Choose what to show+ </span>+ </ThreadDetailsControl>+ </div>+ </div>- {props.usage ? <ThreadDetailsUsage {...props.usage} /> : null}- </>- )}+ <Menu+ open={menuPosition !== null}+ onOpenChange={(open) => !open && setMenuPosition(null)}+ >+ <MenuPopup+ anchor={+ menuPosition+ ? {+ getBoundingClientRect: () =>+ new DOMRect(menuPosition.x, menuPosition.y, 0, 0),+ }+ : undefined+ }+ align="start"+ side="bottom"+ >+ <ThreadDetailsItemsMenuItems />+ </MenuPopup>+ </Menu>+ </>+ );+ }}</ThreadDetailsCard>);}diff --git a/apps/web/src/components/chat/ThreadDetailsSection.tsx b/apps/web/src/components/chat/ThreadDetailsSection.tsxindex 00aacd5a7b1..de5ce6c6382 100644--- a/apps/web/src/components/chat/ThreadDetailsSection.tsx+++ b/apps/web/src/components/chat/ThreadDetailsSection.tsx@@ -22,7 +22,12 @@ export function ThreadDetailsSection({{...props}aria-labelledby={showHeading ? headingId : undefined}aria-label={showHeading ? undefined : title}- className={cn("px-2 pt-2 pb-2.5", separated && "border-t border-border/65")}+ // A row can still render nothing (a fresh draft quiets Git actions), so an empty section+ // collapses, and a divider only follows a section that has content.+ className={cn(+ "px-2 pt-2 pb-2.5 has-[>div:last-child:empty]:hidden",+ separated && "border-border/65 [section:not(:has(>div:last-child:empty))~&]:border-t",+ )}><divclassName={cn(diff --git a/apps/web/src/components/chat/ThreadDetailsUsage.tsx b/apps/web/src/components/chat/ThreadDetailsUsage.tsxindex 6a9adadfc72..e0f5c3afbe8 100644--- a/apps/web/src/components/chat/ThreadDetailsUsage.tsx+++ b/apps/web/src/components/chat/ThreadDetailsUsage.tsx@@ -36,7 +36,7 @@ export interface ThreadDetailsUsageInput {}/**- * Labs readout of the selected provider's limit windows and the thread's context window.+ * The selected provider's limit windows and the thread's context window.* Every row reads as room left, so a longer bar always means more headroom.*/export function ThreadDetailsUsage({diff --git a/apps/web/src/components/chat/threadDetailsItems.test.ts b/apps/web/src/components/chat/threadDetailsItems.test.tsnew file mode 100644index 00000000000..0a0787061d2--- /dev/null+++ b/apps/web/src/components/chat/threadDetailsItems.test.ts@@ -0,0 +1,35 @@+import { describe, expect, it } from "vite-plus/test";++import {+ resolveThreadDetailsVisibility,+ setThreadDetailsItem,+ THREAD_DETAILS_ITEMS,+} from "./threadDetailsItems";++const usage = THREAD_DETAILS_ITEMS.find((item) => item.id === "usage")!;+const servers = THREAD_DETAILS_ITEMS.find((item) => item.id === "servers")!;++describe("thread details items", () => {+ it.each([+ { legacy: false, items: {}, usage: false },+ { legacy: true, items: {}, usage: true },+ { legacy: true, items: { usage: false }, usage: false },+ { legacy: false, items: { usage: true, retired: false }, usage: true },+ ])("resolves Usage from overrides and the retired Labs flag: %o", (row) => {+ const visibility = resolveThreadDetailsVisibility({+ threadDetailsItems: row.items,+ threadDetailsUsageEnabled: row.legacy,+ });+ expect(visibility.usage).toBe(row.usage);+ expect(visibility.servers).toBe(true);+ });++ it("stores only choices that differ from the default", () => {+ const legacyOn = { threadDetailsItems: {}, threadDetailsUsageEnabled: true };+ expect(setThreadDetailsItem(legacyOn, usage, false)).toEqual({ usage: false });+ expect(setThreadDetailsItem(legacyOn, usage, true)).toEqual({});++ const hidden = { threadDetailsItems: { servers: false }, threadDetailsUsageEnabled: false };+ expect(setThreadDetailsItem(hidden, servers, true)).toEqual({});+ });+});diff --git a/apps/web/src/components/chat/threadDetailsItems.ts b/apps/web/src/components/chat/threadDetailsItems.tsnew file mode 100644index 00000000000..7502a4c0b1d--- /dev/null+++ b/apps/web/src/components/chat/threadDetailsItems.ts@@ -0,0 +1,60 @@+import type { ClientSettings } from "@t3tools/contracts";++// Ids are stored in client settings, so never rename one.+export const THREAD_DETAILS_ITEMS = [+ { id: "environment", label: "Environment and worktree", defaultVisible: true },+ { id: "openIn", label: "Open in editor", defaultVisible: true },+ { id: "scripts", label: "Project scripts", defaultVisible: true },+ { id: "branch", label: "Branch and pull request", defaultVisible: true },+ { id: "gitActions", label: "Git actions", defaultVisible: true },+ { id: "changes", label: "Changes", defaultVisible: true },+ { id: "servers", label: "Servers", defaultVisible: true },+ { id: "automations", label: "Automations", defaultVisible: true },+ { id: "lineage", label: "Lineage", defaultVisible: true },+ { id: "usage", label: "Usage", defaultVisible: false },+] as const;++export type ThreadDetailsItemId = (typeof THREAD_DETAILS_ITEMS)[number]["id"];+export type ThreadDetailsVisibility = Readonly<Record<ThreadDetailsItemId, boolean>>;++type ThreadDetailsItem = (typeof THREAD_DETAILS_ITEMS)[number];+type ThreadDetailsItemSettings = Pick<+ ClientSettings,+ "threadDetailsItems" | "threadDetailsUsageEnabled"+>;++// People who turned on the retired Labs toggle keep Usage until they change it here.+function defaultVisible(item: ThreadDetailsItem, settings: ThreadDetailsItemSettings) {+ return item.id === "usage" ? settings.threadDetailsUsageEnabled : item.defaultVisible;+}++export function resolveThreadDetailsVisibility(+ settings: ThreadDetailsItemSettings,+): ThreadDetailsVisibility {+ return Object.fromEntries(+ THREAD_DETAILS_ITEMS.map((item) => [+ item.id,+ settings.threadDetailsItems[item.id] ?? defaultVisible(item, settings),+ ]),+ ) as Record<ThreadDetailsItemId, boolean>;+}++/** Stores only choices that differ from the default, so a later default change reaches everyone else. */+export function setThreadDetailsItem(+ settings: ThreadDetailsItemSettings,+ item: ThreadDetailsItem,+ visible: boolean,+): ClientSettings["threadDetailsItems"] {+ const { [item.id]: _previous, ...rest } = settings.threadDetailsItems;+ return visible === defaultVisible(item, settings) ? rest : { ...rest, [item.id]: visible };+}++export function isDefaultThreadDetailsVisibility(visibility: ThreadDetailsVisibility) {+ return THREAD_DETAILS_ITEMS.every((item) => visibility[item.id] === item.defaultVisible);+}++/** Also clears the retired Labs flag, so Usage returns to off. */+export const RESET_THREAD_DETAILS_ITEMS = {+ threadDetailsItems: {},+ threadDetailsUsageEnabled: false,+} satisfies Partial<ClientSettings>;diff --git a/apps/web/src/components/settings/AppearanceSettingsPanel.tsx b/apps/web/src/components/settings/AppearanceSettingsPanel.tsxindex f47ee3f52c7..1c5812a2bda 100644--- a/apps/web/src/components/settings/AppearanceSettingsPanel.tsx+++ b/apps/web/src/components/settings/AppearanceSettingsPanel.tsx@@ -34,6 +34,7 @@ import { searchableSetting } from "./settingsSearch";import { AdvancedSettings } from "./AdvancedSettings";import { PanelAnimationsPreview } from "./PanelAnimationsPreview";import { TypographySection } from "./TypographySettings";+import { ThreadDetailsItemsRow } from "./ThreadDetailsItemsRow";const ENVIRONMENT_IDENTIFICATION_LABELS: Record<EnvironmentIdentificationMode, string> = {artwork: "Artwork",@@ -273,6 +274,7 @@ export function AppearanceSettingsPanel() {</div>}/>+ <ThreadDetailsItemsRow /><SettingsRow{...searchableSetting("effort-display")}description="Show reasoning effort in the composer as its name, such as High, or as bars."diff --git a/apps/web/src/components/settings/LabsSettingsPanel.tsx b/apps/web/src/components/settings/LabsSettingsPanel.tsxindex 1f51e20c0f8..ce3f68eac49 100644--- a/apps/web/src/components/settings/LabsSettingsPanel.tsx+++ b/apps/web/src/components/settings/LabsSettingsPanel.tsx@@ -18,7 +18,6 @@ export function LabsSettingsPanel() {<SettingsSection id="beta" title="Beta"><BoringSidebarRow /><BoringSidebarMultilineRow />- <ThreadDetailsUsageRow />{/* Clerk is only mounted when this build has T3 Connect. */}{hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}<LinkedEnvironmentsRow />@@ -70,26 +69,6 @@ function BoringSidebarMultilineRow() {);}-function ThreadDetailsUsageRow() {- const settings = useScopedSettings();- const updateSettings = useUpdateScopedSettings();- return (- <SettingsRow- {...searchableSetting("thread-details-usage")}- description="Show the current provider's usage limits and the thread's context window at the bottom of the thread details card."- control={- <Switch- checked={settings.threadDetailsUsageEnabled}- onCheckedChange={(checked) =>- updateSettings({ threadDetailsUsageEnabled: Boolean(checked) })- }- aria-label="Usage in thread details"- />- }- />- );-}-/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */function GuestLinksRowWithSignIn() {const { isSignedIn } = useAuth();diff --git a/apps/web/src/components/settings/ThreadDetailsItemsRow.tsx b/apps/web/src/components/settings/ThreadDetailsItemsRow.tsxnew file mode 100644index 00000000000..a142155d035--- /dev/null+++ b/apps/web/src/components/settings/ThreadDetailsItemsRow.tsx@@ -0,0 +1,53 @@+import { ChevronDownIcon } from "lucide-react";++import { updateClientSettings, useClientSettings } from "../../hooks/useSettings";+import { ThreadDetailsItemsMenuItems } from "../chat/ThreadDetailsItemsMenu";+import {+ isDefaultThreadDetailsVisibility,+ resolveThreadDetailsVisibility,+ RESET_THREAD_DETAILS_ITEMS,+ THREAD_DETAILS_ITEMS,+} from "../chat/threadDetailsItems";+import { Button } from "../ui/button";+import { Menu, MenuPopup, MenuTrigger } from "../ui/menu";+import { SettingResetButton, SettingsRow } from "./settingsLayout";+import { searchableSetting } from "./settingsSearch";++export function ThreadDetailsItemsRow() {+ const visibility = useClientSettings(resolveThreadDetailsVisibility);+ const enabled = THREAD_DETAILS_ITEMS.filter((item) => visibility[item.id]).length;+ return (+ <SettingsRow+ {...searchableSetting("thread-details-items")}+ description="Choose what the thread details card shows. You can also right-click the card."+ resetAction={+ isDefaultThreadDetailsVisibility(visibility) ? null : (+ <SettingResetButton+ label="thread details"+ onClick={() => updateClientSettings(RESET_THREAD_DETAILS_ITEMS)}+ />+ )+ }+ control={+ <Menu>+ <MenuTrigger+ render={+ <Button+ variant="outline"+ size="sm"+ className="w-full justify-between sm:w-40"+ aria-label={`Thread details: ${enabled} of ${THREAD_DETAILS_ITEMS.length} on`}+ />+ }+ >+ {enabled} of {THREAD_DETAILS_ITEMS.length} on+ <ChevronDownIcon aria-hidden />+ </MenuTrigger>+ <MenuPopup align="end">+ <ThreadDetailsItemsMenuItems />+ </MenuPopup>+ </Menu>+ }+ />+ );+}diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.tsindex 0d87e9bd32c..1d5c13e72a0 100644--- a/apps/web/src/components/settings/settingsSearch.ts+++ b/apps/web/src/components/settings/settingsSearch.ts@@ -315,6 +315,14 @@ export const SETTINGS_SEARCH_ITEMS = [to: "/settings/appearance",searchTerms: ["wide full width column layout messages composer monitor"],},+ {+ id: "thread-details-items",+ title: "Thread details",+ to: "/settings/appearance",+ searchTerms: [+ "customize show hide panel card environment editor scripts branch pull request git changes servers automations lineage usage limits 5 hour weekly quota tokens context window",+ ],+ },{id: "effort-display",title: "Effort display",@@ -437,12 +445,6 @@ export const SETTINGS_SEARCH_ITEMS = [to: "/settings/labs",searchTerms: ["beta boring sidebar folder rows multiline branch pull request details"],},- {- id: "thread-details-usage",- title: "Usage in thread details",- to: "/settings/labs",- searchTerms: ["beta limits 5 hour weekly context window tokens quota rate limit"],- },{id: "guest-links",title: "Guest links",diff --git a/docs/user/thread-sidebar.md b/docs/user/thread-sidebar.mdindex dfc7b1245ef..fb5e12b0837 100644--- a/docs/user/thread-sidebar.md+++ b/docs/user/thread-sidebar.md@@ -277,6 +277,11 @@ Select a server to open it in the browser panel. **Stop** ends the server's joband keeps the agent, the terminal, and T3 Code running. Stop needs terminalaccess to the environment and is not available on Windows.+To choose what the thread details card shows, right-click the card or open+**Settings → Appearance → Thread details**. Hidden rows keep their keyboard+shortcuts, such as Open in editor and project scripts. **Reset to default** brings+back the standard rows.+## Snooze until laterTo change the choices in the snooze menu, open **Settings → Threads → Snooze options**.diff --git a/docs/user/usage.md b/docs/user/usage.mdindex 8064380c5e7..155175351c5 100644--- a/docs/user/usage.md+++ b/docs/user/usage.md@@ -116,7 +116,7 @@ current model's limits without leaving the conversation. The result opens abovecloses when you dismiss it or send your next message. It uses the same snapshot as **Usage → Limits**, so it does not run the agent or refreshanything. The command is offered only for providers that appear under **Usage → Limits**.-To keep them in view, turn on **Settings → Labs → Usage in thread details** on web and desktop.+To keep them in view on web and desktop, turn on **Usage** in **Settings → Appearance → Thread details**, or right-click the thread details card.The bottom of the thread details card then shows how much is left in each limit window of thecurrent provider account and in the thread's context window. Some windows, such as a weekly Opuslimit, count only one model. Hover a row to see when it resets, your pace, ordiff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.tsindex d789770f161..16eb51aa176 100644--- a/packages/contracts/src/settings.ts+++ b/packages/contracts/src/settings.ts@@ -477,7 +477,13 @@ export const ClientSettingsSchema = Schema.Struct({boringSidebarMultilineRows: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false)),),+ // Retired Labs toggle. Still read as the default for the Usage item in threadDetailsItems.threadDetailsUsageEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),+ // Sparse show/hide overrides for thread details card items. Missing ids use the client's+ // default, so new items appear for everyone and unknown ids survive a downgrade.+ threadDetailsItems: Schema.Record(Schema.String, Schema.Boolean).pipe(+ Schema.withDecodingDefault(Effect.succeed({})),+ ),// Opt-in for the removed legacy sidebar. Still read so those users land in// the boring sidebar; the boring sidebar toggle clears it.legacySidebarEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),@@ -1722,6 +1728,7 @@ export const ClientSettingsPatch = Schema.Struct({boringSidebarEnabled: Schema.optionalKey(Schema.Boolean),boringSidebarMultilineRows: Schema.optionalKey(Schema.Boolean),threadDetailsUsageEnabled: Schema.optionalKey(Schema.Boolean),+ threadDetailsItems: Schema.optionalKey(Schema.Record(Schema.String, Schema.Boolean)),legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),sidebarWorkingShelfEnabled: Schema.optionalKey(Schema.Boolean),sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),