Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions apps/web/src/components/Sidebar.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
DEFAULT_CLIENT_SETTINGS,
EnvironmentId,
ProjectId,
ProviderInstanceId,
RunId,
ThreadId,
type ScopedThreadRef,
} from "@t3tools/contracts";
Expand Down Expand Up @@ -208,6 +210,153 @@ describe("sidebar render isolation", () => {
});
});

describe("the Idle shelf", () => {
it("folds the threads no agent is working on away", async () => {
using stack = new DisposableStack();
const previousSettings = getClientSettings();
stack.defer(() => __setClientSettingsForTests(previousSettings));
__setClientSettingsForTests({ ...DEFAULT_CLIENT_SETTINGS });
window.localStorage.removeItem("t3code:sidebar:idle-expanded");
vi.mocked(useProjects).mockReturnValue([project("active")]);
vi.mocked(useHandleNewThread).mockReturnValue({
activeDraftThread: null,
activeThread: null,
defaultProjectRef: null,
defaultProjectFallbackReady: true,
handleNewThread: vi.fn().mockResolvedValue(null),
routeDraftId: null,
routeThreadRef: null,
});
vi.mocked(useQuietThreadShells).mockReturnValue([
makeThreadFixture({
id: ThreadId.make("thread-idle"),
environmentId: EnvironmentId.make("local"),
projectId: ProjectId.make("active"),
title: "Idle thread",
}),
]);

await using screen = await render(
<SidebarProvider>
<Sidebar routeReveal={{ observedKey: null, pendingKey: null }} />
</SidebarProvider>,
);

const toggle = screen.getByTestId("sidebar-idle-shelf-toggle");
const row = screen.getByTestId("sidebar-row-card");
await expect.element(toggle).toHaveAttribute("aria-expanded", "true");
await vi.waitFor(() => expect(row.element().textContent).toContain("Idle thread"));

await userEvent.click(toggle);
await expect.element(toggle).toHaveAttribute("aria-expanded", "false");
await vi.waitFor(() => expect(row.query()).toBeNull());
});

it("links the idle rows to their header for the arrow keys", async () => {
using stack = new DisposableStack();
const previousSettings = getClientSettings();
stack.defer(() => __setClientSettingsForTests(previousSettings));
__setClientSettingsForTests({ ...DEFAULT_CLIENT_SETTINGS });
window.localStorage.removeItem("t3code:sidebar:idle-expanded");
vi.mocked(useProjects).mockReturnValue([project("active")]);
vi.mocked(useHandleNewThread).mockReturnValue({
activeDraftThread: null,
activeThread: null,
defaultProjectRef: null,
defaultProjectFallbackReady: true,
handleNewThread: vi.fn().mockResolvedValue(null),
routeDraftId: null,
routeThreadRef: null,
});
vi.mocked(useQuietThreadShells).mockReturnValue([
makeThreadFixture({
id: ThreadId.make("thread-idle"),
environmentId: EnvironmentId.make("local"),
projectId: ProjectId.make("active"),
title: "Idle thread",
}),
]);

await using screen = await render(
<SidebarProvider>
<Sidebar routeReveal={{ observedKey: null, pendingKey: null }} />
</SidebarProvider>,
);

await vi.waitFor(() =>
expect(
screen.container.querySelector<HTMLElement>('[data-sidebar-row="shelf:idle"]'),
).not.toBeNull(),
);
await vi.waitFor(() =>
expect(
screen.container.querySelector<HTMLElement>('[data-sidebar-parent="shelf:idle"]'),
).not.toBeNull(),
);
});

it("keeps a running thread visible when the shelf folds", async () => {
using stack = new DisposableStack();
const previousSettings = getClientSettings();
stack.defer(() => __setClientSettingsForTests(previousSettings));
// Without a Working shelf the running threads sit among the idle ones.
__setClientSettingsForTests({
...DEFAULT_CLIENT_SETTINGS,
sidebarWorkingShelfEnabled: false,
});
window.localStorage.removeItem("t3code:sidebar:idle-expanded");
vi.mocked(useProjects).mockReturnValue([project("active")]);
vi.mocked(useHandleNewThread).mockReturnValue({
activeDraftThread: null,
activeThread: null,
defaultProjectRef: null,
defaultProjectFallbackReady: true,
handleNewThread: vi.fn().mockResolvedValue(null),
routeDraftId: null,
routeThreadRef: null,
});
vi.mocked(useQuietThreadShells).mockReturnValue([
makeThreadFixture({
id: ThreadId.make("thread-running"),
environmentId: EnvironmentId.make("local"),
projectId: ProjectId.make("active"),
title: "Running thread",
runtime: {
status: "running",
activeRunId: RunId.make("run-1"),
providerInstanceId: ProviderInstanceId.make("codex"),
providerName: null,
lastError: null,
updatedAt: "2026-01-01T00:00:00.000Z",
},
}),
makeThreadFixture({
id: ThreadId.make("thread-idle"),
environmentId: EnvironmentId.make("local"),
projectId: ProjectId.make("active"),
title: "Idle thread",
}),
]);

await using screen = await render(
<SidebarProvider>
<Sidebar routeReveal={{ observedKey: null, pendingKey: null }} />
</SidebarProvider>,
);

const toggle = screen.getByTestId("sidebar-idle-shelf-toggle");
await vi.waitFor(() =>
expect(screen.getByTestId("sidebar-row-card").elements()).toHaveLength(2),
);

await userEvent.click(toggle);
await vi.waitFor(() =>
expect(screen.getByTestId("sidebar-row-card").elements()).toHaveLength(1),
);
await expect.element(screen.getByText("Running thread")).toBeVisible();
});
});

describe("sidebar thread rename", () => {
// regression: #35151 an untouched rename wrote back the title it opened with over a newer one
it.each(["{Enter}", "{Tab}"])(
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/Sidebar.drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export function createSidebarSortingStrategy(input: {
marker("pinned-header");
projected.push(...groups.pinned);
marker("pinned-divider");
if (items.some((item) => item.kind === "marker" && item.marker === "idle-header")) {
marker("idle-header");
}
section("active");
if (items.some((item) => item.kind === "marker" && item.marker === "working-header")) {
marker("working-header");
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export type SidebarListMarker =
| "active-placeholder"
| "settled-placeholder"
| "pinned-divider"
| "idle-header"
| "working-header"
| "snoozed-header"
| "settled-header";
Expand Down
90 changes: 78 additions & 12 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ const SETTLED_TAIL_PAGE_COUNT = 25;
const SETTLED_SHELF_EXPANDED_KEY = "t3code:sidebar:settled-expanded";
const SNOOZED_SHELF_EXPANDED_KEY = "t3code:sidebar:snoozed-expanded";
const WORKING_SHELF_EXPANDED_KEY = "t3code:sidebar:working-expanded";
const IDLE_SHELF_EXPANDED_KEY = "t3code:sidebar:idle-expanded";

const inboxReturns = createInboxReturnTracker();

Expand Down Expand Up @@ -467,6 +468,12 @@ function useSidebarThreads(input: {
false,
Schema.Boolean,
);
// Idle threads are the ones no agent is working on; the shelf folds them away.
const [idleShelfExpanded, setIdleShelfExpanded] = useLocalStorage(
IDLE_SHELF_EXPANDED_KEY,
true,
Schema.Boolean,
);
// Shared with the old per-project sidebar, so folders keep their open state.
const projectExpandedById = useUiStateStore((store) => store.projectExpandedById);
const setProjectExpanded = useUiStateStore((store) => store.setProjectExpanded);
Expand All @@ -492,8 +499,14 @@ function useSidebarThreads(input: {
clockKey: `${nowMinute}:${snoozeWakeClock}:${inboxReturnsVersion}`,
});

const { pinnedThreads, activeThreads, workingThreads, snoozedThreads, settledThreads } =
partition;
const {
pinnedThreads,
activeThreads,
workingThreads,
snoozedThreads,
settledThreads,
runningAmongIdle,
} = partition;
// Older settled threads load in pages; the shelf lists them only as far as they are loaded.
const olderSettledShelf = useOlderSettledShelf({
scopes: olderSettledScopes([...serverConfigs.keys()], scopedProjectKeys),
Expand Down Expand Up @@ -526,6 +539,22 @@ function useSidebarThreads(input: {
const visibleWorkingThreads = workingShelfExpanded
? workingThreads
: routeThreadOnly(workingThreads, routeRowThreadKey);
// Folders list the idle threads inside each project, so they need no shelf.
const idleShelfEnabled = folderGroups === null;
const routedActiveThreads = new Set(
routeThreadOnly(activeThreads, routeRowThreadKey).map(threadShellKey),
);
const visibleActiveThreads = idleShelfEnabled
? idleShelfExpanded
? activeThreads
: // Folding the shelf keeps the thread on screen and the threads an agent
// is working on, which are not idle at all.
activeThreads.filter(
(thread) =>
runningAmongIdle.has(threadShellKey(thread)) ||
routedActiveThreads.has(threadShellKey(thread)),
)
: activeThreads;
const projectFolders =
folderGroups === null
? null
Expand All @@ -549,7 +578,7 @@ function useSidebarThreads(input: {
const orderedThreads = [
...pinnedThreads,
...(projectFolders === null
? activeThreads
? visibleActiveThreads
: projectFolders.flatMap((folder) => folder.threads)),
...visibleWorkingThreads,
...visibleSnoozedThreads,
Expand Down Expand Up @@ -591,6 +620,10 @@ function useSidebarThreads(input: {
toggleSnoozedShelf: () => setSnoozedShelfExpanded((value) => !value),
workingShelfExpanded,
toggleWorkingShelf: () => setWorkingShelfExpanded((value) => !value),
idleShelfEnabled,
idleShelfExpanded,
toggleIdleShelf: () => setIdleShelfExpanded((value) => !value),
visibleActiveThreads,
projectFolders,
toggleProjectFolder: (group: SidebarProjectSnapshot) => {
const keys = sidebarFolderExpansionKeys(group);
Expand Down Expand Up @@ -631,11 +664,20 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) {
const pinned: EnvironmentThreadShell[] = [];
const active: EnvironmentThreadShell[] = [];
const working: EnvironmentThreadShell[] = [];
const inbox = (thread: EnvironmentThreadShell, manuallyMoved = false) =>
workingShelfEnabled &&
(manuallyMoved ? isThreadWorking(thread) : inboxObservation.isWorking(thread))
? working
: active;
// Without a Working shelf the running threads sit among the idle ones, so
// they are tracked to stay visible when the Idle shelf folds. The key is
// tracked rather than the object, because an optimistic drop replaces it.
const runningAmongIdle = new Set<string>();
const inbox = (thread: EnvironmentThreadShell, manuallyMoved = false) => {
if (
workingShelfEnabled &&
(manuallyMoved ? isThreadWorking(thread) : inboxObservation.isWorking(thread))
)
return working;
if (!workingShelfEnabled && isThreadWorking(thread))
runningAmongIdle.add(threadShellKey(thread));
return active;
};
const snoozed: EnvironmentThreadShell[] = [];
const settled: EnvironmentThreadShell[] = [];
const { draggableThreadKeys, activeReorderableThreadKeys } = resolveSidebarReorderableThreadKeys({
Expand Down Expand Up @@ -706,6 +748,7 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) {
getId: (thread) => scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
}),
workingThreads: sortWorkingThreadsBySend(working),
runningAmongIdle,
snoozedThreads: snoozed.toSorted(
(left, right) =>
firstValidTimestampMs(left.snoozedUntil ?? null) -
Expand Down Expand Up @@ -1313,6 +1356,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
toggleSnoozedShelf,
workingShelfExpanded,
toggleWorkingShelf,
idleShelfEnabled,
idleShelfExpanded,
toggleIdleShelf,
visibleActiveThreads,
projectFolders,
toggleProjectFolder,
renderedSettledThreads,
Expand Down Expand Up @@ -1954,7 +2001,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
const pinnedRows = rowsOf(pinnedThreads, "pinned");
items.push(...pinnedRows);
items.push({ kind: "marker", marker: "pinned-divider" });
const activeRows = rowsOf(activeThreads, "active");
const activeRows = rowsOf(visibleActiveThreads, "active");
if (idleShelfEnabled && activeThreads.length > 0) {
items.push({ kind: "marker", marker: "idle-header" });
}
items.push({ kind: "marker", marker: "active-placeholder" });
items.push(...activeRows);
if (workingThreads.length > 0) {
Expand Down Expand Up @@ -3383,7 +3433,9 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
section === "snoozed" ||
section === "settled"
? `shelf:${section}`
: undefined)
: section === "active" && idleShelfEnabled
? "shelf:idle"
: undefined)
}
variantAction={
section === "snoozed"
Expand Down Expand Up @@ -3527,7 +3579,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
<SidebarDragBoundary
key="pinned-divider"
marker="pinned-divider"
label="Active"
label="Idle"
visible={from !== null}
isDropTarget={dragTargetSection === "active"}
/>,
Expand All @@ -3538,7 +3590,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
<SidebarSectionPlaceholder
key="active-placeholder"
marker="active-placeholder"
label="Active"
label="Idle"
showHint={
from !== null &&
(activeThreads.length === 0 ||
Expand All @@ -3551,6 +3603,20 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
/>,
);
break;
case "idle-header":
items.push(
<SidebarSectionHeader
key="idle-shelf-header"
marker="idle-header"
label="Idle"
count={activeThreads.length}
toggle={{
expanded: idleShelfExpanded,
onToggle: toggleIdleShelf,
}}
/>,
);
break;
case "working-header":
items.push(
<SidebarSectionHeader
Expand Down
14 changes: 8 additions & 6 deletions apps/web/src/components/sidebar/SidebarListMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function SidebarDragBoundary(props: {
}

export function SidebarSectionHeader(props: {
marker: "working-header" | "snoozed-header" | "settled-header";
marker: "idle-header" | "working-header" | "snoozed-header" | "settled-header";
label: string;
/** A muted trailing count. */
count: number;
Expand All @@ -121,11 +121,13 @@ export function SidebarSectionHeader(props: {
toggle: { expanded: boolean; onToggle: () => void };
}) {
const shelf =
props.marker === "working-header"
? "working"
: props.marker === "snoozed-header"
? "snoozed"
: "settled";
props.marker === "idle-header"
? "idle"
: props.marker === "working-header"
? "working"
: props.marker === "snoozed-header"
? "snoozed"
: "settled";
return (
<SortableSidebarMarker
marker={props.marker}
Expand Down
Loading