diff --git a/apps/mobile/src/features/keyboard/CommandPalette.tsx b/apps/mobile/src/features/keyboard/CommandPalette.tsx index 38b83e4c56bad..9b8cd114fc8ba 100644 --- a/apps/mobile/src/features/keyboard/CommandPalette.tsx +++ b/apps/mobile/src/features/keyboard/CommandPalette.tsx @@ -9,7 +9,8 @@ import { type EnvironmentThreadSearchMatch, type ShownOrder, } from "@t3tools/client-runtime/state/thread-search"; -import { isListedThreadLineage, THREAD_JUMP_KEYBINDING_COMMANDS } from "@t3tools/contracts"; +import { isShownUnderParent } from "@t3tools/client-runtime/state/threads"; +import { THREAD_JUMP_KEYBINDING_COMMANDS } from "@t3tools/contracts"; import { foldSearchQuery, PALETTE_MESSAGE_LIMIT, @@ -43,6 +44,7 @@ import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities"; import { useNativeLayoutMetrics } from "../../native/native-layout-metrics"; import { T3KeyboardCommands } from "../../native/T3KeyboardCommands"; import { + useDelegatedUnderParent, useProjects, useServerConfigs, useThreadShell, @@ -227,6 +229,7 @@ export function CommandPalette(props: { const runCommand = props.onCommand; const projects = useProjects(); const threads = useVisibleThreadShells(); + const delegatedUnderParent = useDelegatedUnderParent(); const activeThreadRef = parseActiveThreadPath(props.pathname); const activeThread = useThreadShell(activeThreadRef); const visitThread = useAtomCommand(threadEnvironment.visit, { reportFailure: false }); @@ -426,7 +429,15 @@ export function CommandPalette(props: { }), })); const threadItems: CommandPaletteItem[] = threads - .filter((thread) => thread.archivedAt === null && isListedThreadLineage(thread.lineage)) + .filter( + (thread) => + thread.archivedAt === null && + !isShownUnderParent( + { environmentId: thread.environmentId, threadId: thread.id }, + thread.lineage, + delegatedUnderParent, + ), + ) .map((thread) => { const project = projectByKey.get(scopedProjectKey(thread.environmentId, thread.projectId)); const environment = @@ -473,6 +484,7 @@ export function CommandPalette(props: { selectDetail, startTriage, threads, + delegatedUnderParent, triageEnvironmentId, ]); const rankedMessageKeys = useMemo(() => { diff --git a/apps/mobile/src/state/entities.ts b/apps/mobile/src/state/entities.ts index c9d1834a78bdb..16bfe0be755ab 100644 --- a/apps/mobile/src/state/entities.ts +++ b/apps/mobile/src/state/entities.ts @@ -200,6 +200,11 @@ export function useVisibleThreadShells(): ReadonlyArray return useAtomValue(environmentThreadShells.visibleThreadShellsAtom); } +/** Tasks linked environments run for a listed thread, by thread key; lists show them under it. */ +export function useDelegatedUnderParent(): ReadonlySet { + return useAtomValue(environmentThreadShells.delegatedUnderParentAtom); +} + export function useNavigationThreadShells(): ReadonlyArray { return useAtomValue(environmentThreadShells.navigationThreadShellsAtom); } diff --git a/apps/web/src/components/CommandPalette.logic.test.ts b/apps/web/src/components/CommandPalette.logic.test.ts index afb6dfbea255d..8ba78e2639fdc 100644 --- a/apps/web/src/components/CommandPalette.logic.test.ts +++ b/apps/web/src/components/CommandPalette.logic.test.ts @@ -1,3 +1,4 @@ +import { threadKey } from "@t3tools/client-runtime/state/entities"; import { describe, expect, it, vi } from "vite-plus/test"; import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts"; import type { Thread } from "../types"; @@ -666,11 +667,13 @@ describe("buildThreadActionItems", () => { ]); }); - it("hides subagent threads but keeps forks", () => { + it("hides subagent threads and tasks shown under their parent but keeps forks", () => { const parentId = ThreadId.make("parent"); + const delegatedId = ThreadId.make("delegated"); const items = buildThreadActionItems({ threads: [ makeThread({ id: parentId, title: "Parent" }), + makeThread({ id: delegatedId, title: "Delegated task" }), makeThread({ id: ThreadId.make("subagent"), title: "Subagent", @@ -690,6 +693,9 @@ describe("buildThreadActionItems", () => { }, }), ], + delegatedUnderParent: new Set([ + threadKey({ environmentId: LOCAL_ENVIRONMENT_ID, threadId: delegatedId }), + ]), projectByKey: new Map(), icon: null, runThread: async () => undefined, diff --git a/apps/web/src/components/CommandPalette.logic.ts b/apps/web/src/components/CommandPalette.logic.ts index 407e9a5e35981..2456ca357e178 100644 --- a/apps/web/src/components/CommandPalette.logic.ts +++ b/apps/web/src/components/CommandPalette.logic.ts @@ -30,12 +30,13 @@ import { THREAD_JUMP_KEYBINDING_COMMANDS, } from "@t3tools/contracts"; import { filterFilesystemBrowseEntries } from "@t3tools/client-runtime/state/filesystem"; +import { isShownUnderParent } from "@t3tools/client-runtime/state/threads"; import { type ReactNode } from "react"; import { formatRelativeTimeLabel } from "../timestampFormat"; import { type Project, type SidebarThreadSummary, type Thread } from "../types"; -import { isSidebarHiddenThread } from "./Sidebar.logic"; export const RECENT_THREAD_LIMIT = 12; +const NO_THREAD_KEYS: ReadonlySet = new Set(); export const ITEM_ICON_CLASS = "size-4 text-icon-muted"; export const ADDON_ICON_CLASS = "size-4"; @@ -436,10 +437,19 @@ export function buildThreadActionItems Promise; /** Makes the environment searchable; pass it only with two or more environments. */ environmentLabelOf?: (thread: TThread) => string | null; + /** Tasks linked environments run for a listed thread; they open from under that thread. */ + delegatedUnderParent?: ReadonlySet; }): CommandPaletteActionItem[] { + const delegatedUnderParent = input.delegatedUnderParent ?? NO_THREAD_KEYS; // Callers order these: recents by last use, search results by rank. const visibleThreads = input.threads.filter( - (thread) => thread.archivedAt === null && !isSidebarHiddenThread(thread), + (thread) => + thread.archivedAt === null && + !isShownUnderParent( + { environmentId: thread.environmentId, threadId: thread.id }, + thread.lineage, + delegatedUnderParent, + ), ); return visibleThreads.map((thread) => { diff --git a/apps/web/src/components/CommandPaletteThreadItems.tsx b/apps/web/src/components/CommandPaletteThreadItems.tsx index ddccc1c3a54e1..12a42e250f45d 100644 --- a/apps/web/src/components/CommandPaletteThreadItems.tsx +++ b/apps/web/src/components/CommandPaletteThreadItems.tsx @@ -23,7 +23,7 @@ import { deriveProviderInstanceEntries, type ProviderInstanceEntry, } from "../providerInstances"; -import { useVisibleThreadShells } from "../state/entities"; +import { useDelegatedUnderParent, useVisibleThreadShells } from "../state/entities"; import { useEnvironmentProviders, useEnvironments, @@ -100,6 +100,7 @@ export function useCommandPaletteThreadItems(input: { const { activeThread, threadSearchQuery } = input; const navigate = useNavigate(); const threads = useVisibleThreadShells(); + const delegatedUnderParent = useDelegatedUnderParent(); const { projectEnvironmentLocationById } = useEnvironmentLookups(); const providerEntryByEnvironmentAndInstanceId = useProviderEntryByEnvironmentAndInstanceId(); const messageSearch = useConnectedThreadSearch(threadSearchQuery); @@ -111,6 +112,7 @@ export function useCommandPaletteThreadItems(input: { const { environments } = useEnvironments(); const threadItems = buildThreadActionItems({ threads, + delegatedUnderParent, ...(environments.length > 1 ? { environmentLabelOf: (thread: (typeof threads)[number]) => diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index 8c0e678ff6672..5060c6ae879af 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -582,7 +582,7 @@ export async function deleteSelectedThreadEntries< return { deletedThreadKeys, firstFailure }; } -export function isSidebarHiddenThread(thread: Pick): boolean { +function isSidebarHiddenThread(thread: Pick): boolean { return !isListedThreadLineage(thread.lineage); }