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
12 changes: 11 additions & 1 deletion apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -373,6 +379,7 @@ interface SidebarThreadPartitionInput {
readonly connectedEnvironmentIds: readonly EnvironmentId[];
readonly optimisticDrop: SidebarOptimisticDrop | null;
readonly workingShelfEnabled: boolean;
readonly inboxFilter: ReadonlyArray<InboxChoice>;
/** 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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -506,6 +514,7 @@ function useSidebarThreads(input: {
connectedEnvironmentIds,
optimisticDrop,
workingShelfEnabled,
inboxFilter,
sortActiveBySend: folderGroups !== null,
clockKey: `${nowMinute}:${snoozeWakeClock}:${inboxReturnsVersion}`,
});
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions packages/contracts/src/threadInbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
effectiveInboxFilter,
inboxOriginFor,
founderInboxLane,
staysActiveWhileWorking,
compositeThreadKey,
agentLaunchInboxRouting,
agentLaunchInboxError,
Expand Down Expand Up @@ -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);
});
});
13 changes: 13 additions & 0 deletions packages/contracts/src/threadInbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ export const effectiveInboxFilter = (settings: {
const isAllInboxes = (filter: ReadonlyArray<InboxChoice>) =>
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<InboxChoice>,
) {
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.
Expand Down
Loading