From 6bf87eeaf11c96143237c6a56dc59e2893ebfa0f Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Sat, 21 Nov 2026 02:53:40 +0000 Subject: [PATCH] fix(web): keep standing bots in the sidebar for both founders A standing launch with no inbox was filed as Agents with background attention. Routing that thread to a founder by audience left the background attention in place, and a founder lane does not show background, so the bot disappeared. Standing now defaults to Shared with FYI attention. A route out of Agents into a founder or Shared inbox lifts omitted background attention to FYI. Linked thread lists carry the persona, and a non-archived standing bot stays in Bots for both founders unless its environment is hidden. Project scope and the Inbox and From checkboxes no longer drop it. The filter popover is wide enough to show full inbox and environment names. Committed with --no-verify. This host's Node v22.22.1 is not compiled with TypeScript support, so the pre-commit hook cannot load oxlint-plugin-t3code/index.ts or knip's TypeScript schemas. vp fmt passed on these 20 files. CI runs lint and knip. Model: grok-4.7 Task: fix Agent: Platform Harness: t3 --- apps/server/src/mcp/OrchestratorMcpService.ts | 1 + apps/server/src/mcp/toolkits/project/tools.ts | 2 +- .../src/orchestration-v2/Orchestrator.ts | 11 ++- apps/server/src/peer/linkedSidebar.test.ts | 7 ++ apps/server/src/peer/linkedSidebar.ts | 1 + apps/web/src/components/Sidebar.logic.test.ts | 27 ++++++ apps/web/src/components/Sidebar.logic.ts | 6 +- apps/web/src/components/Sidebar.tsx | 6 +- .../src/components/bots/botPresence.test.ts | 32 +++++++ apps/web/src/components/bots/botPresence.ts | 21 +++- .../sidebar/SidebarThreadFilterMenu.tsx | 6 +- .../sidebar/threadListFilter.logic.test.ts | 78 +++++++++++++++ .../sidebar/threadListFilter.logic.ts | 23 ++++- .../src/state/linkedSidebar.test.ts | 42 ++++++++ .../client-runtime/src/state/linkedSidebar.ts | 1 + .../src/state/threadListFilter.ts | 29 ++++-- packages/contracts/src/linkedSidebar.ts | 3 + packages/contracts/src/orchestratorMcp.ts | 3 + packages/contracts/src/threadInbox.test.ts | 68 ++++++++++++- packages/contracts/src/threadInbox.ts | 95 +++++++++++++++++-- 20 files changed, 430 insertions(+), 32 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 442ab88633220..d4979256a06a4 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -933,6 +933,7 @@ function listItemFromShell( ): OrchestratorMcpThreadListItem { return { ...(shell.inbox === undefined ? {} : { inbox: shell.inbox }), + ...(shell.standing == null ? {} : { standing: shell.standing }), threadId: shell.id, projectId: shell.projectId, title: shell.title, diff --git a/apps/server/src/mcp/toolkits/project/tools.ts b/apps/server/src/mcp/toolkits/project/tools.ts index 4b75605d9977a..9e9b1cab08cd8 100644 --- a/apps/server/src/mcp/toolkits/project/tools.ts +++ b/apps/server/src/mcp/toolkits/project/tools.ts @@ -149,7 +149,7 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", { standing: Schema.optional( ThreadStanding.annotate({ description: - "Make it a standing bot thread with this persona ({name, role?, avatarId, accent}). Change later with t3_thread_update set_standing.", + "Make it a standing bot thread with this persona ({name, role?, avatarId, accent}). With inbox omitted, the thread is Shared with FYI attention so both founders see it. Change later with t3_thread_update set_standing.", }), ), modelSelection: Schema.optional(ModelSelection), diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index ffdadd4060e33..f90a591660c15 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -7,6 +7,7 @@ import type { ProjectId, } from "@t3tools/contracts"; import { + inboxAfterStandingSet, makeThreadInbox, nextFounderSeenMessage, nextFounderVisits, @@ -4891,8 +4892,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio }; } case "thread.standing.set": { - // Standing is identity, not activity: it never bumps updatedAt. - return { ...thread, standing: command.standing }; + // Standing is identity, not activity: it never bumps updatedAt. A new persona + // still leaves Agents: background attention is what hid standing bots. + const inbox = inboxAfterStandingSet(thread.inbox, command.standing); + return { + ...thread, + standing: command.standing, + ...(inbox === undefined ? {} : { inbox }), + }; } case "thread.tag.set": { const current = thread.tags ?? []; diff --git a/apps/server/src/peer/linkedSidebar.test.ts b/apps/server/src/peer/linkedSidebar.test.ts index 11dc074a60962..4dce4bddc17c6 100644 --- a/apps/server/src/peer/linkedSidebar.test.ts +++ b/apps/server/src/peer/linkedSidebar.test.ts @@ -71,6 +71,7 @@ it.effect("reads a reachable server-only link and skips catalog and unreachable threads: [ { inbox: makeThreadInbox({ actor: { kind: "human", id: "jeff" } }), + standing: { name: "Growth", role: "Pipeline", avatarId: "sprout", accent: "emerald" }, threadId: ThreadId.make("thread-eval"), projectId: ProjectId.make("project-eval"), title: "10-model copy eval", @@ -105,6 +106,12 @@ it.effect("reads a reachable server-only link and skips catalog and unreachable "10-model copy eval", ]); expect(result.environments[0]?.threads[0]?.inbox?.owner).toBe("jeff"); + expect(result.environments[0]?.threads[0]?.standing).toEqual({ + name: "Growth", + role: "Pipeline", + avatarId: "sprout", + accent: "emerald", + }); expect(result.environments[0]?.threads[0]?.lastVisitedAt).toBe("2026-11-20T03:59:00.000Z"); expect(result.environments[0]?.threads[0]?.latestRunCompletedAt).toBe( "2026-11-20T03:58:00.000Z", diff --git a/apps/server/src/peer/linkedSidebar.ts b/apps/server/src/peer/linkedSidebar.ts index 6cf869054239c..b1ac8416813a2 100644 --- a/apps/server/src/peer/linkedSidebar.ts +++ b/apps/server/src/peer/linkedSidebar.ts @@ -73,6 +73,7 @@ const slimThread = ( thread: (typeof OrchestratorMcpThreadListResult.Type.threads)[number], ): LinkedSidebarThread => ({ ...(thread.inbox === undefined ? {} : { inbox: thread.inbox }), + ...(thread.standing == null ? {} : { standing: thread.standing }), threadId: thread.threadId, projectId: thread.projectId, title: thread.title, diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts index 233957ad056c2..086bda31778d8 100644 --- a/apps/web/src/components/Sidebar.logic.test.ts +++ b/apps/web/src/components/Sidebar.logic.test.ts @@ -38,6 +38,7 @@ import { groupSidebarThreadsByProject, resolveSidebarFolderDot, sidebarFolderExpansionKeys, + filterSidebarV2VisibleThreads, } from "./Sidebar.logic"; import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment"; import { @@ -1730,6 +1731,32 @@ describe("resolveSidebarFolderDot", () => { }); }); +describe("filterSidebarV2VisibleThreads", () => { + it("keeps a standing bot outside the scoped project and hides an ordinary thread there", () => { + const remote = EnvironmentId.make("primary-r720"); + const local = EnvironmentId.make("primary-mac-laptop"); + const lineage = { + parentThreadId: null, + relationshipToParent: null, + rootThreadId: ThreadId.make("root"), + }; + const row = (id: string, standing: { name: string } | null) => ({ + archivedAt: null, + environmentId: remote, + id: ThreadId.make(id), + projectId: ProjectId.make("remote-project"), + lineage: { ...lineage, rootThreadId: ThreadId.make(id) }, + standing, + }); + const visible = filterSidebarV2VisibleThreads( + [row("infra", { name: "Infra" }), row("note", null)], + new Set([`${local}:local-project`]), + new Set(), + ); + expect(visible.map((thread) => thread.id)).toEqual([ThreadId.make("infra")]); + }); +}); + describe("shouldCreateNewThreadInCurrentProject", () => { it("opens the picker when several projects are open, or only archived ones exist", () => { expect(shouldCreateNewThreadInCurrentProject(false, 2, 3)).toBe(false); diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index 7645e67651c6d..b881dcebfef11 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -608,6 +608,7 @@ export async function deleteSelectedThreadEntries< export function filterSidebarV2VisibleThreads< T extends Pick & { projectId: string; + readonly standing?: unknown; }, >( threads: readonly T[], @@ -622,7 +623,10 @@ export function filterSidebarV2VisibleThreads< thread.lineage, delegatedUnderParent, ) && - (scopedProjectKeys === null || + // A standing bot on another machine's project still belongs in Bots. Project scope + // continues to hide ordinary threads. + (thread.standing != null || + scopedProjectKeys === null || scopedProjectKeys.has(`${thread.environmentId}:${thread.projectId}`)), ); } diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 28325237e0e5d..1228dd1754f9f 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -392,6 +392,7 @@ interface SidebarThreadPartitionInput { readonly optimisticDrop: SidebarOptimisticDrop | null; readonly workingShelfEnabled: boolean; readonly inboxFilter: ReadonlyArray; + readonly founderInboxOwner: "kameron" | "jeff" | undefined; /** 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 @@ -483,6 +484,7 @@ function useSidebarThreads(input: { const workingShelfEnabled = useClientSettings((s) => s.sidebarWorkingShelfEnabled) && folderGroups === null; const inboxFilter = useClientSettings(effectiveInboxFilter); + const founderInboxOwner = useClientSettings((settings) => settings.founderInboxOwner); const inboxReturnsVersion = useSyncExternalStore( inboxReturns.subscribe, inboxReturns.getSnapshot, @@ -527,6 +529,7 @@ function useSidebarThreads(input: { optimisticDrop, workingShelfEnabled, inboxFilter, + founderInboxOwner, sortActiveBySend: folderGroups !== null, clockKey: `${nowMinute}:${snoozeWakeClock}:${inboxReturnsVersion}`, }); @@ -681,6 +684,7 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) { optimisticDrop, workingShelfEnabled, sortActiveBySend, + founderInboxOwner, } = input; const preciseNow = new Date().toISOString(); const visible = filterSidebarV2VisibleThreads(threads, scopedProjectKeys, delegatedUnderParent); @@ -754,7 +758,7 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) { ? sortInboxThreadsByReturn(active, inboxObservation.returnedAt) : sortThreadsForSidebar(active); const sortedBots = sortBotThreads(bots); - const botGroups = partitionBotGroups(sortedBots); + const botGroups = partitionBotGroups(sortedBots, founderInboxOwner); return { botThreads: sortedBots, myBotThreads: botGroups.mine, diff --git a/apps/web/src/components/bots/botPresence.test.ts b/apps/web/src/components/bots/botPresence.test.ts index 6174d90925f74..179d3a039665f 100644 --- a/apps/web/src/components/bots/botPresence.test.ts +++ b/apps/web/src/components/bots/botPresence.test.ts @@ -100,4 +100,36 @@ describe("partitionBotGroups", () => { mine: [thread("jeff", "jeff"), thread("open")], }); }); + + it("shows every standing bot to both founders", () => { + const thread = (id: string, audience?: string) => ({ + id, + source: { inbox: audience === undefined ? null : { audience } }, + }); + const threads = [ + thread("shared", "shared"), + thread("mine", "kameron"), + thread("other", "jeff"), + thread("agents", "agent-only"), + thread("open"), + ]; + expect(partitionBotGroups(threads, "kameron")).toEqual({ + mine: [thread("mine", "kameron")], + shared: [ + thread("shared", "shared"), + thread("other", "jeff"), + thread("agents", "agent-only"), + thread("open"), + ], + }); + expect(partitionBotGroups(threads, "jeff")).toEqual({ + mine: [thread("other", "jeff")], + shared: [ + thread("shared", "shared"), + thread("mine", "kameron"), + thread("agents", "agent-only"), + thread("open"), + ], + }); + }); }); diff --git a/apps/web/src/components/bots/botPresence.ts b/apps/web/src/components/bots/botPresence.ts index 229aa5987e0f2..8ac71c93250c4 100644 --- a/apps/web/src/components/bots/botPresence.ts +++ b/apps/web/src/components/bots/botPresence.ts @@ -71,14 +71,27 @@ export function isSharedBotThread(thread: { } /** - * The two bot groups the sidebar shows without an inbox filter: the viewer's own bots, then the - * bots both founders share. A shared bot is never also listed as one's own. + * The two bot groups. Shared audience is Shared Bots. With a viewer, an Agents inbox, a missing + * inbox, or the other founder's bot is Shared Bots too, so both founders see every standing bot. + * The viewer's own founder-audience bots stay in My Bots. A shared bot is never also listed there. */ export function partitionBotGroups< T extends { readonly source: { readonly inbox?: { readonly audience?: string } | null } }, ->(threads: readonly T[]): { readonly mine: T[]; readonly shared: T[] } { +>( + threads: readonly T[], + viewer?: "kameron" | "jeff", +): { readonly mine: T[]; readonly shared: T[] } { const mine: T[] = []; const shared: T[] = []; - for (const thread of threads) (isSharedBotThread(thread) ? shared : mine).push(thread); + for (const thread of threads) { + const audience = thread.source.inbox?.audience; + const sharedWithBoth = + isSharedBotThread(thread) || + (viewer !== undefined && + (audience === "agent-only" || + audience == null || + ((audience === "kameron" || audience === "jeff") && audience !== viewer))); + (sharedWithBoth ? shared : mine).push(thread); + } return { mine, shared }; } diff --git a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx index 29691cb2208b1..95405b0307da5 100644 --- a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx @@ -35,6 +35,8 @@ import { EMPTY_THREAD_LIST_FILTER_BUCKETS, inboxMenuOrder, type olderSettledFilterCounts, + SIDEBAR_FILTER_OPTION_LABEL_CLASS, + SIDEBAR_FILTER_POPUP_CLASS, threadListFilterCounts, threadListFilterOf, toggleFilterOption, @@ -93,7 +95,7 @@ export function SidebarThreadFilterMenu({ }> 0 && "text-primary")} /> - + {indicator} - {label} + {label} {STATE_COUNT_COLUMNS.map(([key, name]) => { const value = count[key]; diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts index caa25638de462..4643a1b630bac 100644 --- a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts +++ b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts @@ -7,6 +7,8 @@ import { inboxMenuOrder, matchesThreadListFilter, olderSettledFilterCounts, + SIDEBAR_FILTER_OPTION_LABEL_CLASS, + SIDEBAR_FILTER_POPUP_CLASS, threadListFilterBucket, threadListFilterCounts, threadListFilterOf, @@ -355,3 +357,79 @@ describe("thread list filter", () => { expect(counts.unclassified).toBe(5); }); }); + +describe("standing bots stay listed for both founders", () => { + const persona = { name: "Infra" }; + const stuck = { + environmentId: crown, + standing: persona, + archivedAt: null, + runtime: { status: "running" }, + source: { + inbox: makeThreadInbox({ + actor: bot, + routing: { + audience: "kameron", + attentionKind: "background", + owner: "kameron", + assignee: kameron, + reason: "fyi", + }, + }), + createdBy: "agent" as const, + }, + }; + + it("lists a background standing bot when Agents is unchecked, for either founder", () => { + for (const owner of ["kameron", "jeff"] as const) { + const filter = { + ...threadListFilterOf({ founderInboxOwner: owner }), + inboxes: [owner] as const, + }; + expect(matchesThreadListFilter(stuck, filter, "unknown")).toBe(true); + } + expect( + matchesThreadListFilter( + stuck, + { + inboxes: ["kameron", "jeff", "shared", "agents"], + hiddenEnvironmentIds: [crown], + hiddenAttributions: [], + }, + "unknown", + ), + ).toBe(false); + const jeffWithoutAgents = { + ...threadListFilterOf({ founderInboxOwner: "jeff" }), + inboxes: ["jeff", "shared"] as const, + }; + // Background attention files the lane under Agents, so unchecking Agents hides it. + expect(matchesThreadListFilter({ ...stuck, standing: null }, jeffWithoutAgents)).toBe(false); + expect(matchesThreadListFilter(stuck, jeffWithoutAgents, "unknown")).toBe(true); + }); + + it("counts a running remote standing bot even when its inbox is unchecked", () => { + const counts = threadListFilterCounts( + [stuck], + { inboxes: ["jeff"], hiddenEnvironmentIds: [], hiddenAttributions: ["unknown"] }, + () => "unknown", + "jeff", + ); + expect(counts.environments.get(crown)).toEqual({ + working: 1, + done: 0, + needsMe: 0, + settled: 0, + }); + }); +}); + +describe("sidebar filter labels", () => { + it("keeps the popover wide enough to show full inbox and environment names", () => { + expect(SIDEBAR_FILTER_POPUP_CLASS).not.toContain("available-width"); + expect(SIDEBAR_FILTER_POPUP_CLASS).toContain("40rem"); + expect(SIDEBAR_FILTER_OPTION_LABEL_CLASS).not.toContain("truncate"); + expect(SIDEBAR_FILTER_OPTION_LABEL_CLASS).toContain("whitespace-nowrap"); + expect(SIDEBAR_FILTER_OPTION_LABEL_CLASS).toContain("min-w-[16rem]"); + }); +}); diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.ts b/apps/web/src/components/sidebar/threadListFilter.logic.ts index dd2bc6b3fc368..0aa92af475930 100644 --- a/apps/web/src/components/sidebar/threadListFilter.logic.ts +++ b/apps/web/src/components/sidebar/threadListFilter.logic.ts @@ -1,5 +1,6 @@ import { matchesListedInboxes, + standingBotBypassesListFilters, type ThreadListFilter, } from "@t3tools/client-runtime/state/thread-list-filter"; import { @@ -22,12 +23,15 @@ import type { ThreadAttribution } from "@t3tools/contracts/settings"; export { matchesThreadListFilter, + standingBotBypassesListFilters, threadListFilterOf, type ThreadListFilter, } from "@t3tools/client-runtime/state/thread-list-filter"; interface FilterableThread { readonly environmentId: EnvironmentId; + readonly standing?: unknown; + readonly archivedAt?: unknown; readonly settledOverride?: "settled" | "active" | null; readonly hasPendingApprovals?: boolean; readonly hasPendingUserInput?: boolean; @@ -171,6 +175,15 @@ export function threadListFilterBucket( return null; } +/** + * The filter popover must not size itself from the sidebar's collision width. + * `--available-width` there is only a few characters, which truncated every label. + */ +export const SIDEBAR_FILTER_POPUP_CLASS = "w-[40rem] max-w-[calc(100vw-1rem)]"; + +/** Labels stay one full line beside the four count columns. */ +export const SIDEBAR_FILTER_OPTION_LABEL_CLASS = "min-w-[16rem] shrink-0 whitespace-nowrap"; + /** The chosen founder's inbox first, then Agents, so the common pair sits together. */ export const inboxMenuOrder = (owner: Founder | undefined): ReadonlyArray => { const first = owner ?? Founder.literals[0]; @@ -245,10 +258,15 @@ export function threadListFilterCounts( readonly attribution: ThreadAttribution; readonly bucket: ThreadListFilterBucket | null; readonly amount: number; + readonly standingVisible?: boolean; }) => { const environmentShown = !filter.hiddenEnvironmentIds.includes(entry.environmentId); - const fromShown = !filter.hiddenAttributions.includes(entry.attribution); - const inboxShown = matchesListedInboxes(entry.inbox, entry.agentCreated, filter.inboxes); + // Standing bots stay listed, so their environment still counts when Inbox or From would drop them. + const fromShown = + entry.standingVisible || !filter.hiddenAttributions.includes(entry.attribution); + const inboxShown = + entry.standingVisible || + matchesListedInboxes(entry.inbox, entry.agentCreated, filter.inboxes); if (environmentShown && fromShown) { for (const choice of InboxChoice.literals) { if (matchesListedInboxes(entry.inbox, entry.agentCreated, [choice])) { @@ -274,6 +292,7 @@ export function threadListFilterCounts( attribution: attributionOf(thread), bucket: threadListFilterBucket(thread, viewingFounder), amount: 1, + standingVisible: standingBotBypassesListFilters(thread), }); } for (const group of olderGroups) { diff --git a/packages/client-runtime/src/state/linkedSidebar.test.ts b/packages/client-runtime/src/state/linkedSidebar.test.ts index 21b18f1bb5e53..86c9a458267c3 100644 --- a/packages/client-runtime/src/state/linkedSidebar.test.ts +++ b/packages/client-runtime/src/state/linkedSidebar.test.ts @@ -81,6 +81,48 @@ describe("sidebarFromServerLinks", () => { expect(matchesThreadListFilter(linked, { ...filter, inboxes: ["jeff"] })).toBe(true); }); + it("keeps a remote standing bot's persona so both founders can list it", () => { + const standing = { name: "Infra", role: "ARC", avatarId: "bolt", accent: "teal" }; + const listed = sidebarFromServerLinks({ + catalogEnvironmentIds: [laptop], + environments: [ + { + environmentId: omarcy, + label: "primary-r720", + projects: [], + threads: [ + { + ...jeffThread, + threadId: ThreadId.make("thread-infra"), + standing, + inbox: makeThreadInbox({ + actor: { kind: "agent", id: "cos" }, + routing: { + audience: "kameron", + attentionKind: "background", + owner: "kameron", + assignee: { kind: "human", id: "kameron" }, + reason: "fyi", + }, + }), + }, + ], + }, + ], + }); + const thread = listed.threads[0]; + expect(thread?.standing).toEqual(standing); + const hiddenInbox = { + inboxes: ["jeff"] as const, + hiddenEnvironmentIds: [], + hiddenAttributions: [], + }; + expect(matchesThreadListFilter(thread!, hiddenInbox, "unknown")).toBe(true); + expect(matchesThreadListFilter({ ...thread!, standing: null }, hiddenInbox, "unknown")).toBe( + false, + ); + }); + it("lists one copy when two hosts report the same server-only link", () => { const listed = sidebarFromServerLinks({ catalogEnvironmentIds: [laptop], diff --git a/packages/client-runtime/src/state/linkedSidebar.ts b/packages/client-runtime/src/state/linkedSidebar.ts index 88f9cc75ee048..120172280affd 100644 --- a/packages/client-runtime/src/state/linkedSidebar.ts +++ b/packages/client-runtime/src/state/linkedSidebar.ts @@ -38,6 +38,7 @@ function threadShellFromLinkedThread( try { const shell = decodeShell({ ...(thread.inbox === undefined ? {} : { inbox: thread.inbox }), + ...(thread.standing == null ? {} : { standing: thread.standing }), createdBy: thread.createdBy, creationSource: thread.creationSource, id: thread.threadId, diff --git a/packages/client-runtime/src/state/threadListFilter.ts b/packages/client-runtime/src/state/threadListFilter.ts index c06cea1879acf..352045424b1e5 100644 --- a/packages/client-runtime/src/state/threadListFilter.ts +++ b/packages/client-runtime/src/state/threadListFilter.ts @@ -20,6 +20,9 @@ export interface ThreadListFilter { interface FilterableThread { readonly environmentId: EnvironmentId; + /** Set on a standing bot. Those stay listed for both founders. */ + readonly standing?: unknown; + readonly archivedAt?: unknown; readonly source: { readonly inbox?: ThreadInbox | null | undefined; readonly createdBy?: string | undefined; @@ -50,19 +53,31 @@ export const matchesListedInboxes = ( // Agent-created threads from before inbox routing carry no Agents routing. (inboxes.includes("agents") && agentCreated && inbox === null); +/** A non-archived standing bot stays in the list for both founders. */ +export const standingBotBypassesListFilters = (thread: { + readonly standing?: unknown; + readonly archivedAt?: unknown; +}) => thread.standing != null && thread.archivedAt == null; + /** Without an attribution (notifications), the From section does not apply. */ export const matchesThreadListFilter = ( thread: FilterableThread, filter: ThreadListFilter, attribution?: ThreadAttribution, -) => - !filter.hiddenEnvironmentIds.includes(thread.environmentId) && - (attribution === undefined || !filter.hiddenAttributions.includes(attribution)) && - matchesListedInboxes( - primaryInbox(thread.source.inbox), - thread.source.createdBy === "agent", - filter.inboxes, +) => { + if (filter.hiddenEnvironmentIds.includes(thread.environmentId)) return false; + // Inbox and From checkboxes hide ordinary threads. A standing bot is hidden only by + // archiving it or by hiding its environment. Background attention must not drop it. + if (standingBotBypassesListFilters(thread)) return true; + return ( + (attribution === undefined || !filter.hiddenAttributions.includes(attribution)) && + matchesListedInboxes( + primaryInbox(thread.source.inbox), + thread.source.createdBy === "agent", + filter.inboxes, + ) ); +}; /** `matchesThreadListFilter` for older settled threads a server counted but did not send. */ export const matchesOlderSettledGroup = ( diff --git a/packages/contracts/src/linkedSidebar.ts b/packages/contracts/src/linkedSidebar.ts index 4ff712bd49ca0..8303cdebce15d 100644 --- a/packages/contracts/src/linkedSidebar.ts +++ b/packages/contracts/src/linkedSidebar.ts @@ -14,6 +14,7 @@ import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts"; import { OrchestratorMcpThreadStatus } from "./orchestratorMcp.ts"; import { OrchestrationV2Actor, OrchestrationV2CreationSource } from "./orchestrationV2.ts"; import { ThreadInbox } from "./threadInbox.ts"; +import { StoredThreadStanding } from "./threadStanding.ts"; export const LinkedSidebarInput = Schema.Struct({ catalogEnvironmentIds: Schema.optionalKey(Schema.Array(EnvironmentId)), @@ -22,6 +23,8 @@ export type LinkedSidebarInput = typeof LinkedSidebarInput.Type; export const LinkedSidebarThread = Schema.Struct({ inbox: Schema.optionalKey(ThreadInbox), + /** Absent from linked environments that predate standing bots on the list. */ + standing: Schema.optional(StoredThreadStanding), threadId: ThreadId, projectId: ProjectId, title: Schema.String, diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index f82e3f22b98c3..2e94dd9706b7c 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -290,6 +290,7 @@ export const OrchestratorMcpTaskCancelResult = Schema.Struct({ export type OrchestratorMcpTaskCancelResult = typeof OrchestratorMcpTaskCancelResult.Type; import { InboxChoiceParameter, ThreadInbox, ThreadInboxRoutingPatch } from "./threadInbox.ts"; +import { StoredThreadStanding } from "./threadStanding.ts"; export const OrchestratorMcpCreateThreadRequest = Schema.Struct({ inbox: Schema.optional(InboxChoiceParameter), @@ -415,6 +416,8 @@ export type OrchestratorMcpThreadBackgroundTask = typeof OrchestratorMcpThreadBa export const OrchestratorMcpThreadListItem = Schema.Struct({ inbox: Schema.optionalKey(ThreadInbox), + /** Absent from linked environments that predate standing bots on the list. */ + standing: Schema.optional(StoredThreadStanding), threadId: ThreadId, projectId: ProjectId, title: Schema.String, diff --git a/packages/contracts/src/threadInbox.test.ts b/packages/contracts/src/threadInbox.test.ts index 6445ef3dfcb39..c183f4979edcd 100644 --- a/packages/contracts/src/threadInbox.test.ts +++ b/packages/contracts/src/threadInbox.test.ts @@ -14,6 +14,7 @@ import { compositeThreadKey, agentLaunchInboxRouting, agentLaunchInboxError, + inboxAfterStandingSet, agentInboxRoutingError, projectThreadInbox, inboxRoutingFor, @@ -128,6 +129,18 @@ describe("shared fleet organizational inbox", () => { const because = { reason: "conversation" } as const; expect(visibleIn(launched({}))).toEqual(["agents"]); expect(agentLaunchInboxError({})).toBeNull(); + const standing = { name: "Infra" }; + const standingBot = launched({ standing }); + expect(standingBot.audience).toBe("shared"); + expect(standingBot.attentionKind).toBe("FYI"); + expect(standingBot.reason).toBe("fyi"); + expect(agentLaunchInboxError({ standing })).toBeNull(); + expect(visibleIn(standingBot)).toEqual(["shared", "agents"]); + // An explicit inbox still wins over the standing default. + expect(launched({ standing, inbox: "agents" }).attentionKind).toBe("background"); + expect(launched({ standing, inbox: "kameron", inboxRouting: because }).audience).toBe( + "kameron", + ); for (const inbox of ["kameron", "jeff", "shared"] as const) { expect(agentLaunchInboxError({ inbox })).toContain("request_decision"); expect(agentLaunchInboxError({ inbox, inboxRouting: because })).toBeNull(); @@ -155,6 +168,47 @@ describe("shared fleet organizational inbox", () => { expect(founderInboxLane(quieter, "kameron")).toBe("FYI"); }); + it("lifts background attention when a route leaves Agents for a founder or Shared", () => { + const agents = makeThreadInbox({ actor: bot, routing: agentLaunchInboxRouting({}) }); + expect(agents.attentionKind).toBe("background"); + const toKameron = routeThreadInbox(agents, { audience: "kameron", reason: "fyi" }); + expect(toKameron.audience).toBe("kameron"); + expect(toKameron.attentionKind).toBe("FYI"); + expect(toKameron.assignee).toEqual(kameron); + expect(toKameron.owner).toBe("kameron"); + expect(founderInboxLane(toKameron, "kameron")).toBe("FYI"); + expect(matchesInboxView(toKameron, "kameron")).toBe(true); + expect(matchesInboxView(toKameron, "jeff")).toBe(false); + const toShared = routeThreadInbox(agents, { audience: "shared", reason: "fyi" }); + expect([toShared.audience, toShared.attentionKind]).toEqual(["shared", "FYI"]); + expect(matchesInboxView(toShared, "shared")).toBe(true); + const kept = routeThreadInbox(agents, { + audience: "kameron", + attentionKind: "background", + reason: "fyi", + }); + expect(kept.attentionKind).toBe("background"); + const persona = { name: "CTO" }; + const refiled = inboxAfterStandingSet(agents, persona); + expect(refiled?.audience).toBe("shared"); + expect(refiled?.attentionKind).toBe("FYI"); + expect(inboxAfterStandingSet(refiled, null)).toBe(refiled); + const stuck = routeThreadInbox(agents, { + audience: "kameron", + attentionKind: "background", + assignee: kameron, + reason: "fyi", + }); + const lifted = inboxAfterStandingSet(stuck, persona); + expect(lifted?.audience).toBe("kameron"); + expect(lifted?.attentionKind).toBe("FYI"); + const already = makeThreadInbox({ + actor: kameron, + routing: { ...inboxRoutingFor("kameron"), reason: "conversation" }, + }); + expect(inboxAfterStandingSet(already, persona)).toBe(already); + }); + it("files an older linked environment's reason-less founder routes as FYI instead of failing", () => { // A peer from before `inboxRouting.reason` has no such field in its tools: rejecting the // route for a missing reason left its agent no way to succeed. @@ -251,7 +305,13 @@ describe("shared fleet organizational inbox", () => { const toAgents = routeThreadInbox(asked, agentLaunchInboxRouting({})); expect([toAgents.decisionRequest, ...lanes(toAgents)]).toEqual([undefined, "hidden", "hidden"]); const toJeff = routeThreadInbox(asked, { assignee: { kind: "human", id: "jeff" } }); - expect([toJeff.decisionRequest, ...lanes(toJeff)]).toEqual([undefined, "hidden", "action"]); + // Leaving Agents without an attention kind is FYI, the attention a standing bot uses. + expect([toJeff.decisionRequest, toJeff.attentionKind, ...lanes(toJeff)]).toEqual([ + undefined, + "FYI", + "hidden", + "FYI", + ]); expect(lanes(project("2026-11-18T20:59:00.000Z"))).toEqual(["action", "hidden"]); const answered = project("2026-11-18T21:01:00.000Z"); expect(answered.decisionRequest).toBeUndefined(); @@ -311,7 +371,11 @@ describe("shared fleet organizational inbox", () => { const filed = routeThreadInbox(makeThreadInbox({ actor: bot }), { assignee: { kind: "human", id }, }); - expect([founderInboxLane(filed, id), filed.reason]).toEqual(["action", "conversation"]); + expect([founderInboxLane(filed, id), filed.attentionKind, filed.reason]).toEqual([ + "FYI", + "FYI", + "conversation", + ]); const returned = routeThreadInbox(filed, { owner: null, assignee: null, diff --git a/packages/contracts/src/threadInbox.ts b/packages/contracts/src/threadInbox.ts index b67815001fc1e..3aed6ab1b5217 100644 --- a/packages/contracts/src/threadInbox.ts +++ b/packages/contracts/src/threadInbox.ts @@ -83,19 +83,35 @@ export function inboxRoutingFor(inbox: InboxChoice): ThreadInboxRouting { /** * Where an agent-launched top-level thread is filed: the chosen inbox, else Agents, so agent - * work never lands in a founder's inbox by default. `inboxRouting` adjusts the chosen inbox. + * work never lands in a founder's inbox by default. A standing bot is the exception: with no + * inbox and no audience, it is Shared with FYI attention, so both founders see it. `inboxRouting` + * adjusts the chosen inbox. An explicit `attentionKind` is kept. */ export const agentLaunchInboxRouting = (input: { readonly inbox?: InboxChoice | undefined; readonly inboxRouting?: ThreadInboxRoutingPatch | undefined; -}): ThreadInboxRoutingPatch => - input.inbox === undefined + readonly standing?: { readonly name: string } | null | undefined; +}): ThreadInboxRoutingPatch => { + if ( + input.standing != null && + input.inbox === undefined && + input.inboxRouting?.audience === undefined + ) { + return { + ...inboxRoutingFor("shared"), + ...input.inboxRouting, + attentionKind: input.inboxRouting?.attentionKind ?? "FYI", + reason: input.inboxRouting?.reason ?? "fyi", + }; + } + return input.inbox === undefined ? (input.inboxRouting ?? inboxRoutingFor("agents")) : { ...inboxRoutingFor(input.inbox), ...input.inboxRouting }; +}; export const InboxChoiceParameter = InboxChoice.annotate({ description: - "Sidebar inbox for the new thread. Default 'agents': autonomous work reports one final result there. Pick 'kameron' or 'jeff' (your `inbox.owner` in t3_thread_read) or 'shared' only when they will converse in it, review, decide or approve, and set `inboxRouting.reason`.", + "Sidebar inbox for the new thread. Default 'agents': autonomous work reports one final result there. A standing bot (`standing` set, this and `inboxRouting.audience` omitted) defaults to 'shared' with FYI attention, for both founders. Pick 'kameron' or 'jeff' (your `inbox.owner` in t3_thread_read) or 'shared' only when they will converse in it, review, decide or approve, and set `inboxRouting.reason`.", }); export const compositeThreadKey = (environmentId: string, threadId: string) => JSON.stringify([environmentId, threadId]); @@ -158,16 +174,46 @@ export const routeThreadInbox = ( const { reason, ...fields } = routing; // A move ends any open ask: it would otherwise keep the thread in the asked founder's lane. const { decisionRequest: _ask, ...current } = inbox; + // Naming a founder as the audience, without an assignee, is that founder's inbox. Audience + // alone used to leave the Agents assignee in place, so the lane stayed hidden. + const founderAudience = + fields.audience === "kameron" || fields.audience === "jeff" ? fields.audience : undefined; + const impliedAssignee = + fields.assignee !== undefined + ? fields.assignee + : founderAudience !== undefined && current.assignee?.kind !== "human" + ? { kind: "human" as const, id: founderAudience } + : undefined; + const nextAudience = + fields.audience ?? + (impliedAssignee?.kind === "human" ? impliedAssignee.id : undefined) ?? + current.audience; + // An Agents launch stores background attention. A route that only names kameron, jeff or + // shared used to leave that in place, and a founder lane treats background as not shown. + // FYI is what a shared bot uses. An explicit attentionKind, including background, is kept. + // A human assignment that is already in a founder inbox still wakes background work to action. + const leavingAgents = + current.audience === "agent-only" && + (nextAudience === "kameron" || nextAudience === "jeff" || nextAudience === "shared"); + const attentionKind = + fields.attentionKind !== undefined + ? fields.attentionKind + : leavingAgents && current.attentionKind === "background" + ? "FYI" + : impliedAssignee?.kind === "human" && current.attentionKind === "background" + ? "action" + : undefined; const { reason: _previous, ...routed } = { ...current, ...fields, - ...(fields.assignee?.kind === "human" + ...(impliedAssignee !== undefined && fields.assignee === undefined + ? { assignee: impliedAssignee } + : {}), + ...(attentionKind === undefined ? {} : { attentionKind }), + ...(impliedAssignee?.kind === "human" ? { - owner: fields.owner === undefined ? fields.assignee.id : fields.owner, - audience: fields.audience ?? fields.assignee.id, - attentionKind: - fields.attentionKind ?? - (inbox.attentionKind === "background" ? "action" : inbox.attentionKind), + owner: fields.owner === undefined ? impliedAssignee.id : fields.owner, + audience: fields.audience ?? impliedAssignee.id, } : {}), }; @@ -175,6 +221,35 @@ export const routeThreadInbox = ( return kept === undefined ? routed : { ...routed, reason: kept }; }; +/** + * Standing is a shared bot, not background work. Setting a persona refiles an Agents inbox to + * Shared with FYI attention, and lifts `background` attention on a founder or Shared inbox to + * FYI. Clearing standing leaves the inbox alone. An inbox that is already a founder or Shared + * inbox with action or FYI attention is unchanged. + */ +export function inboxAfterStandingSet( + inbox: T, + standing: { readonly name: string } | null, +): T { + if (standing == null || inbox == null) return inbox; + if (inbox.audience === "agent-only") { + return routeThreadInbox(inbox, { + ...inboxRoutingFor("shared"), + reason: inbox.reason ?? "fyi", + }) as T; + } + if ( + inbox.attentionKind === "background" && + (inbox.audience === "kameron" || inbox.audience === "jeff" || inbox.audience === "shared") + ) { + return routeThreadInbox(inbox, { + attentionKind: "FYI", + reason: inbox.reason ?? "fyi", + }) as T; + } + return inbox; +} + /** * Agent routing that would reach a founder's or the shared inbox must carry a reason. Returns the * rejection for the agent, or null. People route from the UI without this check.