Skip to content

Commit dfd9f81

Browse files
vaststudiosclaude
andcommitted
fix(web): folded threads keep their status visible in the legacy sidebar
A folded thread that needed approval or input had no row, so nothing in an expanded project showed it. The launcher row now shows the most urgent status among its folded threads. The fold toggle also hides when none of its children can appear (a collapsed project's pinned row, or children cut off by "Show more"), connectors below the third level stay in their columns, and the unfold chevron stays visible on touch screens. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent de9622f commit dfd9f81

3 files changed

Lines changed: 70 additions & 13 deletions

File tree

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ function LaunchedThreadConnector(props: {
343343
/** One "1" or "0" per ancestor level, outermost first. */
344344
ancestorLines: string;
345345
}) {
346-
const { visibleDepth, isFirstChild, isLastChild, isActive, ancestorLines } = props;
346+
const { visibleDepth, isFirstChild, isLastChild, isActive } = props;
347+
// A row deeper than the visible limit is drawn at the limit, so it keeps the outermost levels.
348+
const ancestorLines = props.ancestorLines.slice(0, visibleDepth - 1);
347349
return (
348350
<span
349351
aria-hidden
@@ -384,6 +386,8 @@ interface SidebarThreadRowProps {
384386
launchedCount: number;
385387
/** Launched threads and subagents folded away below this one. */
386388
launchedHiddenCount: number;
389+
/** The most urgent status among the folded threads, which have no row of their own. */
390+
launchedHiddenStatus: ThreadStatusPill | null;
387391
launchedFolded: boolean;
388392
launchDepth: number;
389393
isFirstLaunchedChild: boolean;
@@ -446,6 +450,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
446450
const {
447451
launchedCount,
448452
launchedHiddenCount,
453+
launchedHiddenStatus,
449454
launchedFolded,
450455
launchDepth,
451456
isFirstLaunchedChild,
@@ -847,6 +852,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
847852
)}
848853
</div>
849854
<div className="ml-auto flex shrink-0 items-center gap-1.5">
855+
{launchedHiddenCount > 0 && launchedHiddenStatus ? (
856+
<ThreadStatusLabel status={launchedHiddenStatus} compact />
857+
) : null}
850858
{launchedCount > 0 ? (
851859
// Folded, it shows how many threads it hides; the chevron appears on row hover or focus.
852860
<button
@@ -874,7 +882,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
874882
<ChevronRightIcon
875883
className={cn(
876884
"absolute inset-0 m-auto size-3.5 opacity-0 transition-[opacity,rotate] duration-150 group-hover/menu-sub-item:opacity-100 group-focus-visible/launch-fold:opacity-100",
877-
!launchedFolded && "rotate-90",
885+
!launchedFolded && "rotate-90 max-sm:opacity-100",
878886
)}
879887
/>
880888
</button>
@@ -1024,7 +1032,12 @@ interface SidebarProjectThreadListProps {
10241032
renderedThreads: readonly SidebarThreadSummary[];
10251033
launchFoldByThreadKey: ReadonlyMap<
10261034
string,
1027-
{ childCount: number; hiddenCount: number; folded: boolean }
1035+
{
1036+
childCount: number;
1037+
hiddenCount: number;
1038+
hiddenStatus: ThreadStatusPill | null;
1039+
folded: boolean;
1040+
}
10281041
>;
10291042
showEmptyThreadState: boolean;
10301043
shouldShowThreadPanel: boolean;
@@ -1116,10 +1129,11 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
11161129
const showMoreButtonRender = <button type="button" />;
11171130
const showLessButtonRender = <button type="button" />;
11181131
// Built from the rendered rows so a hidden launcher or sibling leaves no dangling line.
1132+
const renderedLaunchTree = nestLaunchedSidebarThreads(renderedThreads);
11191133
const launchTreeByThreadKey = new Map(
1120-
nestLaunchedSidebarThreads(renderedThreads).map((entry) => [
1134+
renderedLaunchTree.map((entry, index) => [
11211135
scopedThreadKey(scopeThreadRef(entry.thread.environmentId, entry.thread.id)),
1122-
entry,
1136+
{ ...entry, hasRenderedChild: (renderedLaunchTree[index + 1]?.depth ?? 0) > entry.depth },
11231137
]),
11241138
);
11251139

@@ -1143,13 +1157,20 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
11431157
renderedThreads.map((thread) => {
11441158
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
11451159
const launchTree = launchTreeByThreadKey.get(threadKey);
1146-
const launchFold = launchFoldByThreadKey.get(threadKey);
1160+
// A fold toggle only helps while its children can appear: not in a collapsed project's
1161+
// pinned row, nor when "Show more" cuts off every unfolded child.
1162+
const launchFold =
1163+
projectExpanded &&
1164+
(launchTree?.hasRenderedChild || launchFoldByThreadKey.get(threadKey)?.hiddenCount)
1165+
? launchFoldByThreadKey.get(threadKey)
1166+
: undefined;
11471167
return (
11481168
<SidebarThreadRow
11491169
key={threadKey}
11501170
thread={thread}
11511171
launchedCount={launchFold?.childCount ?? 0}
11521172
launchedHiddenCount={launchFold?.hiddenCount ?? 0}
1173+
launchedHiddenStatus={launchFold?.hiddenStatus ?? null}
11531174
launchedFolded={launchFold?.folded ?? false}
11541175
launchDepth={launchTree?.depth ?? 0}
11551176
isFirstLaunchedChild={launchTree?.isFirstChild ?? true}
@@ -1334,6 +1355,7 @@ function useProjectThreads(project: SidebarProjectSnapshot) {
13341355
// null input and the folded list stays cached across navigation.
13351356
function useFoldedProjectThreads(
13361357
nestedProjectThreads: ReturnType<typeof useProjectThreads>["nestedProjectThreads"],
1358+
lastVisitedAtByThreadKey: ReadonlyMap<string, string | undefined>,
13371359
pinnedThreadKey: string | null,
13381360
) {
13391361
const launchGroupCollapsedById = useUiStateStore((state) => state.launchGroupCollapsedById);
@@ -1350,9 +1372,18 @@ function useFoldedProjectThreads(
13501372
visibleProjectThreads,
13511373
orderedProjectThreadKeys: visibleProjectThreads.map(keyOf),
13521374
launchFoldByThreadKey: new Map(
1353-
foldedProjectThreads.map(({ thread, childCount, hiddenCount, folded }) => [
1375+
foldedProjectThreads.map(({ thread, childCount, hiddenCount, hiddenThreads, folded }) => [
13541376
keyOf(thread),
1355-
{ childCount, hiddenCount, folded },
1377+
{
1378+
childCount,
1379+
hiddenCount,
1380+
hiddenStatus: resolveProjectStatusIndicator(
1381+
hiddenThreads.map((hidden) =>
1382+
resolveProjectThreadStatus(hidden, lastVisitedAtByThreadKey),
1383+
),
1384+
),
1385+
folded,
1386+
},
13561387
]),
13571388
),
13581389
};
@@ -1526,7 +1557,11 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
15261557
? activeRouteThreadKey
15271558
: null;
15281559
const { visibleProjectThreads, orderedProjectThreadKeys, launchFoldByThreadKey } =
1529-
useFoldedProjectThreads(nestedProjectThreads, pinnedLaunchedThreadKey);
1560+
useFoldedProjectThreads(
1561+
nestedProjectThreads,
1562+
lastVisitedAtByThreadKey,
1563+
pinnedLaunchedThreadKey,
1564+
);
15301565
// The "Delete anyway" toast action runs after the toast delay, so it must see
15311566
// the thread list as of the click, not as of the first prompt.
15321567
const readSidebarThreadByKey = useStableCallback(() => sidebarThreadByKey);

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,18 @@ describe("sidebar thread lineage helpers", () => {
592592
"solo:0/0",
593593
]);
594594
expect(summarize({ orchestrator: true })).toEqual(["orchestrator:4/4 folded", "solo:0/0"]);
595+
const [folded] = foldLaunchedSidebarThreads(
596+
nested,
597+
() => true,
598+
() => false,
599+
() => false,
600+
);
601+
expect(folded?.hiddenThreads.map((entry) => entry.id)).toEqual([
602+
"child",
603+
"grandchild",
604+
"helper",
605+
"sibling",
606+
]);
595607
// The open thread's branch stays visible; its folded siblings stay folded.
596608
expect(summarize({ orchestrator: true }, "grandchild")).toEqual([
597609
"orchestrator:4/2 folded",

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ export function foldLaunchedSidebarThreads<T>(
616616
NestedSidebarThread<T> & {
617617
readonly childCount: number;
618618
readonly hiddenCount: number;
619+
readonly hiddenThreads: readonly T[];
619620
readonly folded: boolean;
620621
}
621622
> {
@@ -628,6 +629,7 @@ export function foldLaunchedSidebarThreads<T>(
628629
NestedSidebarThread<T> & {
629630
readonly childCount: number;
630631
readonly hiddenCount: number;
632+
readonly hiddenThreads: readonly T[];
631633
readonly folded: boolean;
632634
}
633635
> = [];
@@ -636,17 +638,25 @@ export function foldLaunchedSidebarThreads<T>(
636638
const end = subtreeEnd(index);
637639
const state = foldState(entry.thread);
638640
const visibleChildren: number[] = [];
639-
let hiddenCount = 0;
641+
const hiddenThreads: T[] = [];
640642
let folded = false;
641643
for (let child = index + 1; child < end; child = subtreeEnd(child)) {
642644
const childEnd = subtreeEnd(child);
643645
const foldable = state === true || (state === undefined && isSubagent(nested[child]!.thread));
644646
const pinned = nested.slice(child, childEnd).some((branch) => keepVisible(branch.thread));
645647
folded ||= foldable;
646-
if (foldable && !pinned) hiddenCount += childEnd - child;
647-
else visibleChildren.push(child);
648+
if (foldable && !pinned) {
649+
for (const hidden of nested.slice(child, childEnd)) hiddenThreads.push(hidden.thread);
650+
}
651+
if (!foldable || pinned) visibleChildren.push(child);
648652
}
649-
result.push({ ...entry, childCount: end - index - 1, hiddenCount, folded });
653+
result.push({
654+
...entry,
655+
childCount: end - index - 1,
656+
hiddenCount: hiddenThreads.length,
657+
hiddenThreads,
658+
folded,
659+
});
650660
for (const child of visibleChildren) visit(child);
651661
};
652662
for (let index = 0; index < nested.length; index = subtreeEnd(index)) visit(index);

0 commit comments

Comments
 (0)