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
16 changes: 14 additions & 2 deletions apps/mobile/src/features/keyboard/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -473,6 +484,7 @@ export function CommandPalette(props: {
selectDetail,
startTriage,
threads,
delegatedUnderParent,
triageEnvironmentId,
]);
const rankedMessageKeys = useMemo(() => {
Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/state/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ export function useVisibleThreadShells(): ReadonlyArray<EnvironmentThreadShell>
return useAtomValue(environmentThreadShells.visibleThreadShellsAtom);
}

/** Tasks linked environments run for a listed thread, by thread key; lists show them under it. */
export function useDelegatedUnderParent(): ReadonlySet<string> {
return useAtomValue(environmentThreadShells.delegatedUnderParentAtom);
}

export function useNavigationThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
return useAtomValue(environmentThreadShells.navigationThreadShellsAtom);
}
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/components/CommandPalette.logic.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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",
Expand All @@ -690,6 +693,9 @@ describe("buildThreadActionItems", () => {
},
}),
],
delegatedUnderParent: new Set([
threadKey({ environmentId: LOCAL_ENVIRONMENT_ID, threadId: delegatedId }),
]),
projectByKey: new Map(),
icon: null,
runThread: async () => undefined,
Expand Down
14 changes: 12 additions & 2 deletions apps/web/src/components/CommandPalette.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set();
export const ITEM_ICON_CLASS = "size-4 text-icon-muted";
export const ADDON_ICON_CLASS = "size-4";

Expand Down Expand Up @@ -436,10 +437,19 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
runThread: (thread: TThread) => Promise<void>;
/** 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<string>;
}): 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) => {
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/CommandPaletteThreadItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
deriveProviderInstanceEntries,
type ProviderInstanceEntry,
} from "../providerInstances";
import { useVisibleThreadShells } from "../state/entities";
import { useDelegatedUnderParent, useVisibleThreadShells } from "../state/entities";
import {
useEnvironmentProviders,
useEnvironments,
Expand Down Expand Up @@ -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);
Expand All @@ -111,6 +112,7 @@ export function useCommandPaletteThreadItems(input: {
const { environments } = useEnvironments();
const threadItems = buildThreadActionItems({
threads,
delegatedUnderParent,
...(environments.length > 1
? {
environmentLabelOf: (thread: (typeof threads)[number]) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export async function deleteSelectedThreadEntries<
return { deletedThreadKeys, firstFailure };
}

export function isSidebarHiddenThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
function isSidebarHiddenThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
return !isListedThreadLineage(thread.lineage);
}

Expand Down
Loading