diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 3461a2ae8c7c..a8284893efba 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -11,7 +11,13 @@ import { } from "@t3tools/client-runtime/state/thread-list-filter"; import { threadRoutingUpdateFromMenuAction } from "./threadActionMenu.logic"; import { attachSidebarTree } from "../lib/sidebarTree"; -import { type EnvironmentId, type ScopedProjectRef } from "@t3tools/contracts"; +import { + effectiveInboxFilter, + staysActiveWhileWorking, + type EnvironmentId, + type InboxChoice, + type ScopedProjectRef, +} from "@t3tools/contracts"; import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection"; import { dropThreadContext, @@ -373,6 +379,7 @@ interface SidebarThreadPartitionInput { readonly connectedEnvironmentIds: readonly EnvironmentId[]; readonly optimisticDrop: SidebarOptimisticDrop | null; readonly workingShelfEnabled: boolean; + readonly inboxFilter: ReadonlyArray; /** Boring mode: folders list active threads by the user's latest message. */ readonly sortActiveBySend: boolean; // Snooze wakes, the queued-turn grace and the Working shelf's exit grace depend @@ -463,6 +470,7 @@ function useSidebarThreads(input: { // Folders already separate the work, so boring mode has no Working shelf. const workingShelfEnabled = useClientSettings((s) => s.sidebarWorkingShelfEnabled) && folderGroups === null; + const inboxFilter = useClientSettings(effectiveInboxFilter); const inboxReturnsVersion = useSyncExternalStore( inboxReturns.subscribe, inboxReturns.getSnapshot, @@ -506,6 +514,7 @@ function useSidebarThreads(input: { connectedEnvironmentIds, optimisticDrop, workingShelfEnabled, + inboxFilter, sortActiveBySend: folderGroups !== null, clockKey: `${nowMinute}:${snoozeWakeClock}:${inboxReturnsVersion}`, }); @@ -661,6 +670,7 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) { const working: EnvironmentThreadShell[] = []; const inbox = (thread: EnvironmentThreadShell, manuallyMoved = false) => workingShelfEnabled && + !staysActiveWhileWorking(thread.source.inbox, input.inboxFilter) && (manuallyMoved ? isThreadWorking(thread) : inboxObservation.isWorking(thread)) ? working : active; diff --git a/packages/contracts/src/threadInbox.test.ts b/packages/contracts/src/threadInbox.test.ts index 0722a46e327b..c3b028a501ae 100644 --- a/packages/contracts/src/threadInbox.test.ts +++ b/packages/contracts/src/threadInbox.test.ts @@ -10,6 +10,7 @@ import { effectiveInboxFilter, inboxOriginFor, founderInboxLane, + staysActiveWhileWorking, compositeThreadKey, agentLaunchInboxRouting, agentLaunchInboxError, @@ -334,3 +335,30 @@ it("keeps founder-owned agent-only children out of founder inboxes", () => { expect(matchesInboxView(assigned, "jeff")).toBe(true); expect(matchesInboxView(assigned, "kameron")).toBe(false); }); + +describe("staysActiveWhileWorking", () => { + const actionForKameron = makeThreadInbox({ + actor: bot, + routing: { assignee: kameron, reason: "review" }, + }); + + it("keeps a thread waiting on a shown founder in the active list", () => { + expect(founderInboxLane(actionForKameron, "kameron")).toBe("action"); + expect(staysActiveWhileWorking(actionForKameron, ["kameron", "agents"])).toBe(true); + expect(staysActiveWhileWorking(actionForKameron, ["kameron", "jeff", "shared", "agents"])).toBe( + true, + ); + }); + + it("leaves it on the Working shelf when that founder's inbox is not shown", () => { + expect(staysActiveWhileWorking(actionForKameron, ["jeff", "agents"])).toBe(false); + expect(staysActiveWhileWorking(actionForKameron, ["agents"])).toBe(false); + expect(staysActiveWhileWorking(undefined, ["kameron"])).toBe(false); + }); + + it("does not hold FYI threads or unrouted agent work active", () => { + const fyi = routeThreadInbox(actionForKameron, { attentionKind: "FYI", reason: "review" }); + expect(staysActiveWhileWorking(fyi, ["kameron"])).toBe(false); + expect(staysActiveWhileWorking(makeThreadInbox({ actor: bot }), ["kameron"])).toBe(false); + }); +}); diff --git a/packages/contracts/src/threadInbox.ts b/packages/contracts/src/threadInbox.ts index e67b8f8d13a1..91757ebe50e4 100644 --- a/packages/contracts/src/threadInbox.ts +++ b/packages/contracts/src/threadInbox.ts @@ -243,6 +243,19 @@ export const effectiveInboxFilter = (settings: { const isAllInboxes = (filter: ReadonlyArray) => InboxChoice.literals.every((choice) => filter.includes(choice)); +/** + * A thread waiting on a founder whose inbox is shown stays in the active list while it works, + * so the collapsed Working shelf cannot hide it. Agents, Shared and FYI work are unaffected. + */ +export function staysActiveWhileWorking( + inbox: ThreadInbox | null | undefined, + filter: ReadonlyArray, +) { + return Founder.literals.some( + (founder) => filter.includes(founder) && founderInboxLane(inbox, founder) === "action", + ); +} + /** * The one inbox a thread is filtered under, so unchecking an inbox hides all of its threads: * Shared, else the founder it is filed to, else Agents. Null is unclassified history.