Skip to content
Merged
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
21 changes: 15 additions & 6 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { SidebarThreadFilterMenu } from "./sidebar/SidebarThreadFilterMenu";
import { matchesThreadListFilter, threadListFilterOf } from "./sidebar/threadListFilter.logic";
import {
matchesThreadListFilter,
olderSettledFilterCounts,
threadListFilterOf,
} from "./sidebar/threadListFilter.logic";
import {
launchingThreadIdOf,
resolveMachineOwners,
Expand Down Expand Up @@ -359,6 +363,7 @@ const EMPTY_PROVIDER_ENTRIES: ReadonlyMap<string, SidebarProviderEntry> = new Ma
const EMPTY_THREADS: readonly EnvironmentThreadShell[] = [];

const SETTLED_TAIL_INITIAL_COUNT = 10;
const NO_THREAD_KEYS: ReadonlySet<string> = new Set();
const SETTLED_TAIL_PAGE_COUNT = 25;
const SETTLED_SHELF_EXPANDED_KEY = "t3code:sidebar:settled-expanded";
const SNOOZED_SHELF_EXPANDED_KEY = "t3code:sidebar:snoozed-expanded";
Expand Down Expand Up @@ -3112,11 +3117,15 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
<SidebarThreadFilterMenu
attributionOf={attributionOf}
countedThreads={() =>
filterSidebarV2VisibleThreads(
threads,
scopedProjectKeys,
delegatedUnderParent,
).filter((thread) => thread.settledOverride !== "settled")
filterSidebarV2VisibleThreads(threads, scopedProjectKeys, NO_THREAD_KEYS)
}
olderSettled={() =>
olderSettledFilterCounts(
olderSettledScopes([...serverConfigs.keys()], scopedProjectKeys),
(environmentId) =>
olderSettledShelf.environments.get(environmentId)?.older ?? null,
machineOwners,
)
}
/>
}
Expand Down
40 changes: 34 additions & 6 deletions apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
changedThreadListFilters,
EMPTY_THREAD_LIST_FILTER_BUCKETS,
inboxMenuOrder,
type olderSettledFilterCounts,
threadListFilterCounts,
threadListFilterOf,
toggleFilterOption,
Expand All @@ -46,16 +47,19 @@ const INBOX_LABELS: Record<InboxChoice, string> = {
shared: "Shared",
};

type CountedThread = Parameters<typeof threadListFilterCounts>[0][number];
type CountedThread = Parameters<typeof threadListFilterCounts>[0][number] &
Parameters<ReturnType<typeof olderSettledFilterCounts>["covers"]>[0];
const LAST_OPTION_NOTE = ", the last one shown, so it stays checked";

/** Chooses which inboxes and environments the thread list shows. Search still finds every thread. */
export function SidebarThreadFilterMenu<T extends CountedThread>({
countedThreads,
olderSettled,
attributionOf,
}: {
/** Called only while the menu is open. */
countedThreads: () => ReadonlyArray<T>;
olderSettled: () => ReturnType<typeof olderSettledFilterCounts>;
attributionOf: (thread: T) => ThreadAttribution;
}) {
const filter = useClientSettings(threadListFilterOf);
Expand Down Expand Up @@ -86,9 +90,10 @@ export function SidebarThreadFilterMenu<T extends CountedThread>({
<MenuTrigger render={<SidebarHeaderIconButton label={label} />}>
<SlidersHorizontalIcon className={cn("size-4", summary.length > 0 && "text-primary")} />
</MenuTrigger>
<MenuPopup align="end" className="w-[min(16rem,var(--available-width))]">
<MenuPopup align="end" className="w-[min(19rem,var(--available-width))]">
<SidebarThreadFilterOptions
countedThreads={countedThreads}
olderSettled={olderSettled}
attributionOf={attributionOf}
filter={filter}
owner={owner}
Expand All @@ -103,25 +108,35 @@ export function SidebarThreadFilterMenu<T extends CountedThread>({
// Mounted only while the menu is open, so counting never runs on streaming ticks.
function SidebarThreadFilterOptions<T extends CountedThread>({
countedThreads,
olderSettled,
attributionOf,
filter,
owner,
environments,
isChanged,
}: {
countedThreads: () => ReadonlyArray<T>;
olderSettled: () => ReturnType<typeof olderSettledFilterCounts>;
attributionOf: (thread: T) => ThreadAttribution;
filter: ThreadListFilter;
owner: Founder | undefined;
environments: ReadonlyArray<{ readonly environmentId: EnvironmentId; readonly label: string }>;
isChanged: boolean;
}) {
const connectedEnvironmentIds = useConnectedEnvironmentIds();
const counts = threadListFilterCounts(countedThreads(), filter, attributionOf, owner);
const inboxOrder = inboxMenuOrder(owner);
const older = olderSettled();
const counts = threadListFilterCounts(
countedThreads().filter((thread) => !older.covers(thread)),
filter,
attributionOf,
owner,
older.groups,
);
const allInboxesShown = inboxOrder.every((inbox) => filter.inboxes.includes(inbox));
const shownAttributions = THREAD_ATTRIBUTIONS.filter(
(from) => !filter.hiddenAttributions.includes(from),
);
const inboxOrder = inboxMenuOrder(owner);
const environmentIds = environments.map((environment) => environment.environmentId);
const shownEnvironmentIds = environmentIds.filter(
(id) => !filter.hiddenEnvironmentIds.includes(id),
Expand Down Expand Up @@ -225,6 +240,16 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
</MenuGroup>
</>
) : null}
<MenuSeparator />
<p className="px-2 py-1.5 text-muted-foreground text-xs">
{!allInboxesShown && counts.unclassified > 0
? `${counts.unclassified} thread${counts.unclassified === 1 ? " has" : "s have"} no inbox and ${counts.unclassified === 1 ? "shows" : "show"} only with every inbox checked. `
: null}
{older.lowerBound
? "Some servers send settled totals only, so settled counts are minimums. "
: null}
Subagent threads open from their parent and are not counted.
</p>
{isChanged ? (
<>
<MenuSeparator />
Expand All @@ -249,6 +274,7 @@ const STATE_COUNT_COLUMNS = [
["working", "working"],
["done", "done"],
["needsMe", "needs me"],
["settled", "settled"],
] as const satisfies ReadonlyArray<readonly [keyof ThreadListFilterBucketCounts, string]>;

function stateCountPhrase(counts: ThreadListFilterBucketCounts) {
Expand All @@ -268,7 +294,7 @@ function FilterOptionRow({
<span className="flex min-w-0 items-center gap-2">
{indicator}
<span className="min-w-0 flex-1 truncate">{label}</span>
<span className="grid shrink-0 grid-cols-3 gap-x-1.5 text-center">
<span className="grid shrink-0 grid-cols-4 gap-x-1.5 text-center">
{STATE_COUNT_COLUMNS.map(([key, name]) => {
const value = count[key];
return (
Expand All @@ -282,7 +308,9 @@ function FilterOptionRow({
? "text-info-foreground"
: key === "done"
? "text-success-foreground"
: "text-warning-foreground",
: key === "needsMe"
? "text-warning-foreground"
: "text-muted-foreground",
)}
>
<span className="block">{value}</span>
Expand Down
108 changes: 97 additions & 11 deletions apps/web/src/components/sidebar/threadListFilter.logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { EnvironmentId, makeThreadInbox } from "@t3tools/contracts";
import { EnvironmentId, ProjectId, ThreadId, makeThreadInbox } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import { describe, expect, it } from "vite-plus/test";

import {
changedThreadListFilters,
inboxMenuOrder,
matchesThreadListFilter,
olderSettledFilterCounts,
threadListFilterBucket,
threadListFilterCounts,
threadListFilterOf,
Expand Down Expand Up @@ -57,16 +59,16 @@ describe("thread list filter", () => {
(candidate) => candidate.from,
);
expect(Object.fromEntries(counts.inboxes)).toEqual({
kameron: { working: 0, done: 1, needsMe: 0 },
agents: { working: 0, done: 1, needsMe: 0 },
kameron: { working: 0, done: 1, needsMe: 0, settled: 0 },
agents: { working: 0, done: 1, needsMe: 0, settled: 0 },
});
expect(Object.fromEntries(counts.environments)).toEqual({
laptop: { working: 0, done: 1, needsMe: 0 },
crown: { working: 0, done: 1, needsMe: 0 },
laptop: { working: 0, done: 1, needsMe: 0, settled: 0 },
crown: { working: 0, done: 1, needsMe: 0, settled: 0 },
});
expect(Object.fromEntries(counts.from)).toEqual({
kameron: { working: 0, done: 1, needsMe: 0 },
unknown: { working: 0, done: 1, needsMe: 0 },
kameron: { working: 0, done: 1, needsMe: 0, settled: 0 },
unknown: { working: 0, done: 1, needsMe: 0, settled: 0 },
});
expect(
matchesThreadListFilter(
Expand Down Expand Up @@ -233,7 +235,7 @@ describe("thread list filter", () => {
expect(threadListFilterBucket(fixtures.attention, "kameron")).toBe("needsMe");
expect(threadListFilterBucket(fixtures.parked, "kameron")).toBe("working");
expect(threadListFilterBucket(fixtures.parkedAttention, "kameron")).toBe("working");
expect(threadListFilterBucket(fixtures.settled, "kameron")).toBeNull();
expect(threadListFilterBucket(fixtures.settled, "kameron")).toBe("settled");
expect(threadListFilterBucket(fixtures.otherFounder, "kameron")).toBe("done");
expect(threadListFilterBucket(fixtures.unstarted, "kameron")).toBeNull();

Expand All @@ -251,11 +253,95 @@ describe("thread list filter", () => {
(candidate) => candidate.from,
"kameron",
);
const kameronRow = { working: 4, done: 2, needsMe: 4 };
const everyRow = { working: 4, done: 3, needsMe: 4 };
const kameronRow = { working: 4, done: 2, needsMe: 4, settled: 1 };
const everyRow = { working: 4, done: 3, needsMe: 4, settled: 1 };
expect(counts.inboxes.get("kameron")).toEqual(kameronRow);
expect(counts.inboxes.get("jeff")).toEqual({ working: 0, done: 1, needsMe: 0 });
expect(counts.inboxes.get("jeff")).toEqual({ working: 0, done: 1, needsMe: 0, settled: 0 });
expect(counts.environments.get(laptop)).toEqual(everyRow);
expect(counts.from.get("kameron")).toEqual(everyRow);
});

it("counts older settled threads from the servers' groups instead of the loaded rows", () => {
const beforeMs = Date.parse("2026-11-18T00:00:00.000Z");
const lineage = {
relationshipToParent: null,
parentThreadId: null,
rootThreadId: ThreadId.make("root"),
};
const settledRow = (environmentId: EnvironmentId, settledAt: string) => ({
...thread(environmentId, kameron),
settledOverride: "settled" as const,
source: {
...thread(environmentId, kameron).source,
lineage,
settledOverride: "settled" as const,
settledAt: DateTime.makeUnsafe(settledAt),
},
});
const group = (inbox: "kameron" | "jeff" | null, count: number, agentCreated = false) => ({
inbox,
agentCreated,
founder: "kameron" as const,
byAgent: false,
count,
});
const project = ProjectId.make("app");
const other = ProjectId.make("other");
const older = new Map([
[
laptop,
{
before: new Date(beforeMs).toISOString(),
beforeMs,
counts: new Map([
[project, 55],
[other, 9],
]),
groups: new Map([
[
project,
[group("kameron", 40), group("jeff", 7), group(null, 5), group(null, 3, true)],
],
[other, [group("kameron", 9)]],
]),
},
],
[
crown,
{
before: new Date(beforeMs).toISOString(),
beforeMs,
counts: new Map([[project, 12]]),
groups: null,
},
],
]);
const source = olderSettledFilterCounts(
[
{ environmentId: laptop, projectIds: [project] },
{ environmentId: crown, projectIds: null },
],
(environmentId) => older.get(environmentId) ?? null,
{},
);
expect(source.lowerBound).toBe(true);
const loaded = [
settledRow(laptop, "2026-11-19T00:00:00.000Z"),
settledRow(laptop, "2026-11-17T00:00:00.000Z"),
settledRow(crown, "2026-11-17T00:00:00.000Z"),
];
const counts = threadListFilterCounts(
loaded.filter((row) => !source.covers(row)),
threadListFilterOf({ founderInboxOwner: "kameron" }),
() => "kameron" as const,
"kameron",
source.groups,
);
expect(counts.inboxes.get("kameron")?.settled).toBe(1 + 40 + 1);
expect(counts.inboxes.get("jeff")?.settled).toBe(7);
expect(counts.inboxes.get("agents")?.settled).toBe(3);
expect(counts.environments.get(laptop)?.settled).toBe(1 + 40 + 3);
expect(counts.environments.get(crown)?.settled).toBe(1);
expect(counts.unclassified).toBe(5);
});
});
Loading
Loading