From 1bac2b55a22ae1acae29b010e9d36177d0dc6793 Mon Sep 17 00:00:00 2001 From: JJ Eaton <58495321+jayleaton@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:43:07 +0700 Subject: [PATCH] fix(web,mobile): list delegated child chats in palette, announcer, and composer Mobile command search, web background announcements, and composer thread references filtered on provider lineage alone, so a delegated child chat (parentRelationship "child", lineage "subagent") was hidden. They now share isOpenListedThread, which uses isListedThread. Co-Authored-By: Claude Opus 5.5 --- .../src/features/keyboard/CommandPalette.tsx | 57 +++++++++---------- .../components/BackgroundThreadAnnouncer.tsx | 4 +- .../src/composerThreadItems.test.ts | 1 + .../client-runtime/src/composerThreadItems.ts | 8 +-- .../client-runtime/src/state/models.test.ts | 47 +++++++++++++++ packages/client-runtime/src/state/models.ts | 15 ++++- 6 files changed, 95 insertions(+), 37 deletions(-) create mode 100644 packages/client-runtime/src/state/models.test.ts diff --git a/apps/mobile/src/features/keyboard/CommandPalette.tsx b/apps/mobile/src/features/keyboard/CommandPalette.tsx index 3b25ab4896dac..3094c67f7ab7e 100644 --- a/apps/mobile/src/features/keyboard/CommandPalette.tsx +++ b/apps/mobile/src/features/keyboard/CommandPalette.tsx @@ -8,7 +8,8 @@ import { type EnvironmentThreadSearchMatch, type ShownOrder, } from "@t3tools/client-runtime/state/thread-search"; -import { isListedThreadLineage, THREAD_JUMP_KEYBINDING_COMMANDS } from "@t3tools/contracts"; +import { isOpenListedThread } from "@t3tools/client-runtime/state/shell"; +import { THREAD_JUMP_KEYBINDING_COMMANDS } from "@t3tools/contracts"; import { foldSearchQuery, PALETTE_MESSAGE_LIMIT, @@ -440,34 +441,32 @@ export function CommandPalette(props: { }, }), })); - const threadItems: CommandPaletteItem[] = threads - .filter((thread) => thread.archivedAt === null && isListedThreadLineage(thread.lineage)) - .map((thread) => { - const project = projectByKey.get(scopedProjectKey(thread.environmentId, thread.projectId)); - const environment = - savedConnectionsById[thread.environmentId]?.environmentLabel ?? thread.environmentId; - return { - key: scopedThreadKey(thread.environmentId, thread.id), - kind: "thread", - title: thread.title || "Untitled thread", - detail: [project?.title, environment].filter(Boolean).join(" · "), - searchTerms: [], - threadSearch: threadSearchSubject( - thread, - project?.title, - environments.length > 1 ? environment : null, - ), - // Last among threads: picking the thread already open does nothing. - ...(thread.environmentId === activeThread?.environmentId && thread.id === activeThread.id - ? { secondary: true } - : {}), - run: () => - selectDetail({ - name: "Thread", - params: { environmentId: String(thread.environmentId), threadId: String(thread.id) }, - }), - }; - }); + const threadItems: CommandPaletteItem[] = threads.filter(isOpenListedThread).map((thread) => { + const project = projectByKey.get(scopedProjectKey(thread.environmentId, thread.projectId)); + const environment = + savedConnectionsById[thread.environmentId]?.environmentLabel ?? thread.environmentId; + return { + key: scopedThreadKey(thread.environmentId, thread.id), + kind: "thread", + title: thread.title || "Untitled thread", + detail: [project?.title, environment].filter(Boolean).join(" · "), + searchTerms: [], + threadSearch: threadSearchSubject( + thread, + project?.title, + environments.length > 1 ? environment : null, + ), + // Last among threads: picking the thread already open does nothing. + ...(thread.environmentId === activeThread?.environmentId && thread.id === activeThread.id + ? { secondary: true } + : {}), + run: () => + selectDetail({ + name: "Thread", + params: { environmentId: String(thread.environmentId), threadId: String(thread.id) }, + }), + }; + }); // Recent means used recently: written in or opened, whichever is later. threadItems.sort( (left, right) => diff --git a/apps/web/src/components/BackgroundThreadAnnouncer.tsx b/apps/web/src/components/BackgroundThreadAnnouncer.tsx index 3176c8132eed9..5e64026302a5b 100644 --- a/apps/web/src/components/BackgroundThreadAnnouncer.tsx +++ b/apps/web/src/components/BackgroundThreadAnnouncer.tsx @@ -1,6 +1,6 @@ import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment"; +import { isOpenListedThread } from "@t3tools/client-runtime/state/shell"; import { effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled"; -import { isListedThreadLineage } from "@t3tools/contracts"; import type { AnyRouter } from "@tanstack/react-router"; import type { AtomRegistry } from "effect/reactivity"; @@ -44,7 +44,7 @@ export function startBackgroundThreadAnnouncements( const snapshots: BackgroundThreadSnapshot[] = []; for (const thread of threads) { // Subagents and side chats have no row of their own; their requests surface on the parent. - if (thread.archivedAt !== null || !isListedThreadLineage(thread.lineage)) continue; + if (!isOpenListedThread(thread)) continue; if (!liveEnvironmentIds.has(thread.environmentId)) continue; snapshots.push({ key: scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)), diff --git a/packages/client-runtime/src/composerThreadItems.test.ts b/packages/client-runtime/src/composerThreadItems.test.ts index 564226839abe3..bfc44809e8289 100644 --- a/packages/client-runtime/src/composerThreadItems.test.ts +++ b/packages/client-runtime/src/composerThreadItems.test.ts @@ -24,6 +24,7 @@ function shell( latestUserMessageAt: null, opens: null, archivedAt: null, + parentThreadId: null, lineage: { rootThreadId: ThreadId.make(id), parentThreadId: null, relationshipToParent: null }, ...overrides, }; diff --git a/packages/client-runtime/src/composerThreadItems.ts b/packages/client-runtime/src/composerThreadItems.ts index 32adee581a6e9..7991165c387af 100644 --- a/packages/client-runtime/src/composerThreadItems.ts +++ b/packages/client-runtime/src/composerThreadItems.ts @@ -1,5 +1,4 @@ import { - isListedThreadLineage, type EnvironmentId, type EnvironmentMachineKind, type ScopedThreadRef, @@ -7,13 +6,13 @@ import { } from "@t3tools/contracts"; import { foldSearchQuery, rankSearchItems, scoreThreadSearch } from "@t3tools/shared/paletteSearch"; -import type { EnvironmentThreadShell } from "./state/models.ts"; +import { isOpenListedThread, type EnvironmentThreadShell } from "./state/models.ts"; import { threadSearchSubject, type ThreadSearchShell } from "./state/threadSearch.ts"; const COMPOSER_THREAD_RESULT_LIMIT = 5; export type ComposerThreadCandidate = ThreadSearchShell & - Pick; + Pick; export interface ComposerThreadItem { readonly id: string; @@ -46,8 +45,7 @@ export function matchComposerThreadItems(input: { (shell.environmentId === input.environmentId || input.linkedEnvironments.has(shell.environmentId)) && shell.id !== input.excludeThreadId && - shell.archivedAt === null && - isListedThreadLineage(shell.lineage), + isOpenListedThread(shell), ); return rankSearchItems(candidates, (shell, options) => scoreThreadSearch(query, threadSearchSubject(shell, null), input.now, { diff --git a/packages/client-runtime/src/state/models.test.ts b/packages/client-runtime/src/state/models.test.ts new file mode 100644 index 0000000000000..04c8f48c3fd9e --- /dev/null +++ b/packages/client-runtime/src/state/models.test.ts @@ -0,0 +1,47 @@ +import { ThreadId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { isOpenListedThread } from "./models.ts"; + +describe("isOpenListedThread", () => { + it("lists delegated child chats and hides subagents, side chats, and archived threads", () => { + const parentId = ThreadId.make("parent"); + const subagentLineage = { + rootThreadId: parentId, + parentThreadId: parentId, + relationshipToParent: "subagent" as const, + }; + const thread = ( + overrides: Partial[0]> = {}, + ): Parameters[0] => ({ + archivedAt: null, + parentThreadId: null, + parentRelationship: null, + lineage: { rootThreadId: parentId, parentThreadId: null, relationshipToParent: null }, + ...overrides, + }); + + expect(isOpenListedThread(thread())).toBe(true); + // A delegated child keeps the provider's subagent lineage but is its own chat. + expect( + isOpenListedThread( + thread({ parentThreadId: parentId, parentRelationship: "child", lineage: subagentLineage }), + ), + ).toBe(true); + expect( + isOpenListedThread( + thread({ + parentThreadId: parentId, + parentRelationship: "subagent", + lineage: subagentLineage, + }), + ), + ).toBe(false); + expect( + isOpenListedThread( + thread({ lineage: { ...subagentLineage, relationshipToParent: null, sideChat: true } }), + ), + ).toBe(false); + expect(isOpenListedThread(thread({ archivedAt: "2026-11-01T00:00:00.000Z" }))).toBe(false); + }); +}); diff --git a/packages/client-runtime/src/state/models.ts b/packages/client-runtime/src/state/models.ts index 0da62e059bc4f..9870ff51d1358 100644 --- a/packages/client-runtime/src/state/models.ts +++ b/packages/client-runtime/src/state/models.ts @@ -16,7 +16,7 @@ import type { RunId, ThreadId, } from "@t3tools/contracts"; -import { isSubagentThread } from "@t3tools/contracts"; +import { isListedThread, isSubagentThread } from "@t3tools/contracts"; import * as DateTime from "effect/DateTime"; import { formatSubagentDisplayTitle } from "./subagentDisplay.ts"; @@ -207,6 +207,19 @@ export interface EnvironmentThreadShell { readonly source: OrchestrationV2ThreadShell; } +/** + * An open thread with a row of its own. Subagents and side chats live in their parent's view; + * a delegated child chat keeps its provider's subagent lineage but is listed. + */ +export function isOpenListedThread( + thread: Pick< + EnvironmentThreadShell, + "archivedAt" | "lineage" | "parentThreadId" | "parentRelationship" + >, +): boolean { + return thread.archivedAt === null && isListedThread(thread); +} + function iso(value: DateTime.Utc): string { return DateTime.formatIso(value); }