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
57 changes: 28 additions & 29 deletions apps/mobile/src/features/keyboard/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) =>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/BackgroundThreadAnnouncer.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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)),
Expand Down
1 change: 1 addition & 0 deletions packages/client-runtime/src/composerThreadItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function shell(
latestUserMessageAt: null,
opens: null,
archivedAt: null,
parentThreadId: null,
lineage: { rootThreadId: ThreadId.make(id), parentThreadId: null, relationshipToParent: null },
...overrides,
};
Expand Down
8 changes: 3 additions & 5 deletions packages/client-runtime/src/composerThreadItems.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import {
isListedThreadLineage,
type EnvironmentId,
type EnvironmentMachineKind,
type ScopedThreadRef,
type ThreadId,
} 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<EnvironmentThreadShell, "archivedAt" | "lineage">;
Pick<EnvironmentThreadShell, "archivedAt" | "lineage" | "parentThreadId" | "parentRelationship">;

export interface ComposerThreadItem {
readonly id: string;
Expand Down Expand Up @@ -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, {
Expand Down
47 changes: 47 additions & 0 deletions packages/client-runtime/src/state/models.test.ts
Original file line number Diff line number Diff line change
@@ -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<Parameters<typeof isOpenListedThread>[0]> = {},
): Parameters<typeof isOpenListedThread>[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);
});
});
15 changes: 14 additions & 1 deletion packages/client-runtime/src/state/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down