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/web/src/components/CommandPalette.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { threadKey } from "@t3tools/client-runtime/state/entities";
import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
import { describe, expect, it, vi } from "vite-plus/test";
import { page, userEvent } from "vite-plus/test/browser";
Expand All @@ -14,20 +15,23 @@ import { CommandPalette } from "./CommandPalette";
const entities = vi.hoisted(() => ({
projects: [] as ReadonlyArray<Project>,
threads: [] as ReadonlyArray<Thread>,
delegatedUnderParent: new Set<string>() as ReadonlySet<string>,
}));
vi.mock("../state/entities", async (original) => ({
...(await original<typeof import("../state/entities")>()),
useProjects: () => entities.projects,
useVisibleThreadShells: () => entities.threads,
useDelegatedUnderParent: () => entities.delegatedUnderParent,
}));

function setup(state: { projects?: ReadonlyArray<Project>; threads?: ReadonlyArray<Thread> } = {}) {
function setup(state: Partial<typeof entities> = {}) {
// Earlier browser test files share this origin's localStorage; a remembered project
// that is not listed here hides the default "New thread in <project>" row.
removeLocalStorageItem(LAST_USED_PROJECT_STORAGE_KEY);
useCommandPaletteStore.setState(useCommandPaletteStore.getInitialState(), true);
entities.projects = state.projects ?? [];
entities.threads = state.threads ?? [];
entities.delegatedUnderParent = state.delegatedUnderParent ?? new Set();
}

describe("CommandPalette open intents", () => {
Expand Down Expand Up @@ -134,11 +138,13 @@ describe("CommandPalette open intents", () => {
await expect.element(input).toHaveValue("acme");
});

it("opens a searched project's latest listed thread, not a newer subagent", async () => {
it("opens a searched project's latest listed thread, not a newer subagent or delegated task", async () => {
const environmentId = EnvironmentId.make("local");
const projectId = ProjectId.make("acme");
const parentId = ThreadId.make("parent");
const delegatedId = ThreadId.make("delegated");
setup({
delegatedUnderParent: new Set([threadKey({ environmentId, threadId: delegatedId })]),
projects: [
{
id: projectId,
Expand Down Expand Up @@ -170,6 +176,12 @@ describe("CommandPalette open intents", () => {
relationshipToParent: "subagent",
},
}),
makeThreadFixture({
id: delegatedId,
environmentId,
projectId,
latestUserMessageAt: "2026-03-04T00:00:00.000Z",
}),
],
});
await using screen = await render(<CommandPalette>{null}</CommandPalette>);
Expand Down
16 changes: 12 additions & 4 deletions apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ import {
} from "../state/environments";
import {
useAnyEnvironmentHiding,
useDelegatedUnderParent,
useHiddenThreadKeys,
useEnvironmentThreadRefs,
useProjects,
useServerConfigs,
useVisibleThreadShells,
waitForProject,
} from "../state/entities";
import { visibleLinkedThreads } from "@t3tools/client-runtime/state/threads";
import { isShownUnderParent, visibleLinkedThreads } from "@t3tools/client-runtime/state/threads";
import {
resolveThreadActionProjectRef,
startNewThreadFromContext,
Expand Down Expand Up @@ -229,7 +230,6 @@ import {
type SearchOverlayMode,
} from "./CommandPalette.logic";
import { resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
import { isSidebarHiddenThread } from "./Sidebar.logic";
import { CommandPaletteContent, type PendingInputSelection } from "./CommandPaletteContent";
import {
selectCommandPaletteClientSettings,
Expand Down Expand Up @@ -516,8 +516,16 @@ function OpenCommandPaletteDialog(props: {
if (activeThreadReferenceCopyTarget === null) return;
await copyThreadReference(activeThreadReferenceCopyTarget);
};
// Side chats and subagents open inside their parent, so opening a project never lands on one.
const threads = useVisibleThreadShells().filter((thread) => !isSidebarHiddenThread(thread));
// Threads the sidebar shows under their parent open there, so opening a project never lands on one.
const delegatedUnderParent = useDelegatedUnderParent();
const threads = useVisibleThreadShells().filter(
(thread) =>
!isShownUnderParent(
{ environmentId: thread.environmentId, threadId: thread.id },
thread.lineage,
delegatedUnderParent,
),
);
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const providersByEnvironment = useEnvironmentProviders();
const { changeThemeItem, changeAppearanceItem, themeEditorItem } = useCommandPaletteThemeItems();
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { presentThreadShell } from "@t3tools/client-runtime/state/models";
import { threadKey } from "@t3tools/client-runtime/state/entities";
import { isThreadWorking as isSidebarThreadWorking } from "@t3tools/client-runtime/state/thread-inbox";
import * as DateTime from "effect/DateTime";
import { deriveActiveWorkStartedAt } from "../session-logic.ts";
Expand Down Expand Up @@ -678,6 +679,7 @@ describe("getFallbackThreadIdAfterDelete", () => {
deletedThreadIds: new Set([ThreadId.make("thread-active"), ThreadId.make("thread-newest")]),
sortOrder: "created_at",
now: "2026-03-09T10:10:00.000Z",
delegatedUnderParent: new Set(),
});

expect(fallbackThreadId).toBe(ThreadId.make("thread-next"));
Expand All @@ -688,6 +690,7 @@ describe("getFallbackThreadIdAfterDelete", () => {
"snoozed",
{ snoozedUntil: "2099-01-01T00:00:00.000Z", snoozedAt: "2026-03-09T10:06:00.000Z" },
],
["delegated", { id: ThreadId.make("thread-delegated") }],
["settled", { settledOverride: "settled", settledAt: "2026-03-09T10:06:00.000Z" }],
[
"side chat",
Expand Down Expand Up @@ -733,6 +736,12 @@ describe("getFallbackThreadIdAfterDelete", () => {
deletedThreadId: ThreadId.make("thread-active"),
sortOrder: "created_at",
now: "2026-03-09T10:10:00.000Z",
delegatedUnderParent: new Set([
threadKey({
environmentId: localEnvironmentId,
threadId: ThreadId.make("thread-delegated"),
}),
]),
});

expect(fallbackThreadId).toBe(ThreadId.make("thread-visible"));
Expand Down
13 changes: 10 additions & 3 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,15 +1319,18 @@ export function getFallbackThreadIdAfterDelete<
"id" | "projectId" | "createdAt" | "updatedAt" | "settledOverride" | "lineage"
> &
ThreadSortInput &
ThreadSnoozeShell,
ThreadSnoozeShell &
Pick<Thread, "environmentId">,
>(input: {
threads: readonly T[];
deletedThreadId: T["id"];
sortOrder: SidebarThreadSortOrder;
now: string;
deletedThreadIds?: ReadonlySet<T["id"]>;
delegatedUnderParent: ReadonlySet<string>;
}): T["id"] | null {
const { deletedThreadId, deletedThreadIds, sortOrder, now, threads } = input;
const { deletedThreadId, deletedThreadIds, sortOrder, now, threads, delegatedUnderParent } =
input;
const deletedThread = threads.find((thread) => thread.id === deletedThreadId);
if (!deletedThread) {
return null;
Expand All @@ -1342,7 +1345,11 @@ export function getFallbackThreadIdAfterDelete<
!deletedThreadIds?.has(thread.id) &&
thread.settledOverride !== "settled" &&
!effectiveSnoozed(thread, { now }) &&
!isSidebarHiddenThread(thread),
!isShownUnderParent(
{ environmentId: thread.environmentId, threadId: thread.id },
thread.lineage,
delegatedUnderParent,
),
),
sortOrder,
)[0]?.id ?? null
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/hooks/useThreadActions.permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ vi.mock("../state/entities", () => ({
.filter((thread) => thread.environmentId === environmentId)
.map((thread) => ({ environmentId, threadId: thread.id })),
readProject: () => ({ workspaceRoot: "/project" }),
readDelegatedUnderParent: () => new Set(),
}));
vi.mock("../components/Sidebar.logic", () => ({
getFallbackThreadIdAfterDelete: () => null,
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/hooks/useThreadActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { releaseComposerDraftUploads } from "../lib/composerDraftUploads";
import { announce } from "../lib/announce";
import { readLocalApi } from "../localApi";
import {
readDelegatedUnderParent,
readEnvironmentServerConfigLoaded,
readEnvironmentSupportsAutoSettleOptOut,
readEnvironmentThreadRefs,
Expand Down Expand Up @@ -593,6 +594,7 @@ export function useThreadActions() {
deletedThreadIds,
sortOrder: sidebarThreadSortOrder,
now: new Date().toISOString(),
delegatedUnderParent: readDelegatedUnderParent(),
});
let navigatedDuringDelete = false;
// The missing-thread redirect and the index draft replace this entry; any other history
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/state/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ export function readThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
return appAtomRegistry.get(environmentThreadShells.threadShellsAtom);
}

export function readDelegatedUnderParent(): ReadonlySet<string> {
return appAtomRegistry.get(environmentThreadShells.delegatedUnderParentAtom);
}

function shellParentThreadId(
thread: Pick<OrchestrationV2ThreadShell, "forkedFrom" | "lineage">,
): ThreadId | null {
Expand Down
Loading