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
8 changes: 7 additions & 1 deletion apps/mobile/src/features/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,13 @@ export function HomeScreen(props: HomeScreenProps) {
);
}
if (item.type === "v2-agent-section") {
return <ThreadListV2AgentSectionHeader item={item} onToggle={toggleSidebarRow} />;
return (
<ThreadListV2AgentSectionHeader
item={item}
onToggle={toggleSidebarRow}
listVisible={props.visible}
/>
);
}
if (item.type !== "v2-thread") return null;
const thread = item.item.thread;
Expand Down
9 changes: 8 additions & 1 deletion apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,14 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
/>
);
case "v2-agent-section":
return <ThreadListV2AgentSectionHeader item={item} onToggle={toggleSidebarRow} />;
return (
<ThreadListV2AgentSectionHeader
item={item}
onToggle={toggleSidebarRow}
listVisible={props.visible}
sidebarPane
/>
);
case "v2-thread": {
const thread = item.item.thread;
const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId);
Expand Down
45 changes: 39 additions & 6 deletions apps/mobile/src/features/threads/thread-list-v2-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IconButton } from "../../components/ui/IconButton";
import {
formatSidebarAgentStates,
sidebarRoleSectionLabels,
sidebarAgentsSectionLabel,
} from "@t3tools/client-runtime/state/sidebar-families";
import { useViewability } from "@legendapp/list/react-native";
import {
Expand Down Expand Up @@ -127,6 +128,8 @@ interface StatusLabel {
}
export const THREAD_ROW_VIEWABILITY = { itemVisiblePercentThreshold: 1 };

const WORKING_STATUS_TINT = "accent-adaptive-sky-600-400";

const STATUS_LABEL_BY_STATUS: Partial<Record<ThreadListV2Status, StatusLabel>> = {
approval: {
label: msg("Approval", { $context: "thread status, waiting for approval" }),
Expand All @@ -146,7 +149,7 @@ const STATUS_LABEL_BY_STATUS: Partial<Record<ThreadListV2Status, StatusLabel>> =
working: {
label: null,
icon: "circle.dashed",
iconTintClassName: "accent-adaptive-sky-600-400",
iconTintClassName: WORKING_STATUS_TINT,
},
waiting: {
label: null,
Expand Down Expand Up @@ -704,7 +707,7 @@ export function ThreadListV2ProjectFolderHeader({
}) {
const gt = useGT();
const m = useMessages();
const summary = item.expanded ? "" : formatSidebarAgentStates(item.counts, m, true);
const summary = item.expanded ? "" : formatSidebarAgentStates(item.counts, m, true).text;
const { project } = item;

return (
Expand Down Expand Up @@ -753,12 +756,21 @@ export function ThreadListV2ProjectFolderHeader({
export function ThreadListV2AgentSectionHeader({
item,
onToggle,
listVisible,
sidebarPane = false,
}: {
readonly item: ThreadListV2AgentSectionItem;
readonly listVisible: boolean;
readonly sidebarPane?: boolean;
readonly onToggle: (key: string, expanded: boolean) => void;
}) {
const m = useMessages();
const summary = formatSidebarAgentStates(item.counts, m);
const { working, details } = formatSidebarAgentStates(item.counts, m);
const [visible, setVisible] = useState(false);
useViewability(useCallback((token) => setVisible(token.isViewable), []));
const appActive = useAppActive();
const focused = useIsFocused();
const animate = visible && listVisible && appActive && (focused || sidebarPane);

return (
<RowPressable
Expand All @@ -769,15 +781,36 @@ export function ThreadListV2AgentSectionHeader({
style={{ paddingStart: 24 + sectionIndent(item.depth) }}
>
<SymbolView
name={item.expanded ? "folder.open" : "folder.fill"}
name={item.expanded ? "chevron.down" : "chevron.right"}
size={12}
tintColorClassName="foreground-muted"
/>
<Text className="min-w-0 shrink text-sm font-t3-medium" numberOfLines={1}>
{m(sidebarRoleSectionLabels[item.role])}
{m(
item.role === undefined ? sidebarAgentsSectionLabel : sidebarRoleSectionLabels[item.role],
)}
</Text>
<Text className="text-xs text-foreground-muted">{item.total}</Text>
{summary ? <Text className="shrink text-xs text-foreground-muted">{summary}</Text> : null}
{working ? (
<View
accessible
accessibilityLabel={working.label}
className="shrink-0 flex-row items-center gap-1"
>
<ThreadRowSpinner animate={animate} tint={WORKING_STATUS_TINT} />
<Text className="text-xs text-foreground-muted">{working.count}</Text>
</View>
) : null}
{working && details ? (
<Text aria-hidden className="text-xs text-foreground-muted">
·
</Text>
) : null}
{details ? (
<Text className="shrink text-xs text-foreground-muted" numberOfLines={1}>
{details}
</Text>
) : null}
</RowPressable>
);
}
Expand Down
34 changes: 31 additions & 3 deletions apps/mobile/src/features/threads/threadListV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ it("renders saved section names, nesting, and interleaved project order", () =>
]);
});

it("nests role sections under their orchestrator and summarizes collapsed folders", () => {
it("groups orchestrator and orphan agents separately and summarizes collapsed folders", () => {
const root = makeThread({ id: ThreadId.make("root"), title: "Root" });
const working = makeThread({
id: ThreadId.make("working"),
Expand Down Expand Up @@ -1447,7 +1447,17 @@ it("nests role sections under their orchestrator and summarizes collapsed folder
title: "Settled",
settledOverride: "settled",
});
const threads = [root, working, waiting, settled];
const orphan = makeThread({
id: ThreadId.make("orphan"),
title: "Orphan agent",
delegatedRole: "test",
lineage: {
parentThreadId: ThreadId.make("missing"),
rootThreadId: ThreadId.make("missing"),
relationshipToParent: "subagent",
},
});
const threads = [root, working, waiting, settled, orphan];
const children = indexSidebarChildren(threads);
const projects = buildHomeProjectScopes({
projects: [makeProjectFixture({ id: root.projectId, title: "Project", environmentId })],
Expand All @@ -1468,6 +1478,7 @@ it("nests role sections under their orchestrator and summarizes collapsed folder
pendingTasks: [],
folders: {
children,
orphanAgents: [orphan],
projects,
layouts: new Map(),
expanded: new Map(collapsed.map((key) => [key, false])),
Expand All @@ -1481,22 +1492,39 @@ it("nests role sections under their orchestrator and summarizes collapsed folder
expect(expanded.map((item) => item.key)).toEqual([
folderKey,
`v2-thread:${environmentId}:root`,
`agents:${environmentId}:root`,
roleKey("implementation"),
`v2-thread:${environmentId}:working`,
roleKey("review"),
`v2-thread:${environmentId}:waiting`,
`v2-thread:${environmentId}:settled`,
`agents:${folderKey}`,
`role:${folderKey}:test`,
`v2-thread:${environmentId}:orphan`,
]);
expect(expanded[1]).toMatchObject({ agentCount: 2, agentRow: false, familyExpanded: true });
expect(expanded[2]).toMatchObject({
total: 2,
counts: { working: 1, attention: 1, failed: 0 },
});
expect(expanded[3]).toMatchObject({
role: "implementation",
counts: { working: 1, attention: 0, failed: 0 },
});
expect(expanded[4]).toMatchObject({
expect(expanded[5]).toMatchObject({
role: "review",
counts: { working: 0, attention: 1, failed: 0 },
});

expect(rows([`agents:${environmentId}:root`]).map(({ key }) => key)).toEqual([
folderKey,
`v2-thread:${environmentId}:root`,
`agents:${environmentId}:root`,
`v2-thread:${environmentId}:settled`,
`agents:${folderKey}`,
`role:${folderKey}:test`,
`v2-thread:${environmentId}:orphan`,
]);
const collapsed = rows([folderKey]);
expect(collapsed).toHaveLength(1);
expect(
Expand Down
74 changes: 55 additions & 19 deletions apps/mobile/src/features/threads/threadListV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
groupSidebarThreadsByProject,
projectSectionRows,
sidebarFamilyRows,
type SidebarFamilyItem,
type SidebarAgentRole,
type SidebarAgentState,
} from "@t3tools/client-runtime/state/sidebar-families";
Expand Down Expand Up @@ -504,7 +505,7 @@ export interface ThreadListV2AgentSectionItem {
readonly type: "v2-agent-section";
readonly key: string;
readonly depth: number;
readonly role: SidebarAgentRole;
readonly role?: SidebarAgentRole;
readonly total: number;
readonly counts: Readonly<Record<SidebarAgentState, number>>;
readonly expanded: boolean;
Expand Down Expand Up @@ -666,6 +667,7 @@ export function buildThreadListV2ListItems(input: {
readonly pendingTasks: ReadonlyArray<PendingNewTask>;
readonly folders?: {
readonly children: ReadonlyMap<string, readonly EnvironmentThreadShell[]>;
readonly orphanAgents?: readonly EnvironmentThreadShell[];
readonly projects: readonly HomeProjectScope[];
readonly layouts: ProjectThreadLayouts;
readonly environmentId?: EnvironmentId | null;
Expand Down Expand Up @@ -752,22 +754,61 @@ export function buildThreadListV2ListItems(input: {
),
);
const threadKey = (thread: EnvironmentThreadShell) => `${thread.environmentId}:${thread.id}`;
const pinnedKeys = new Set(
input.items.filter((row) => row.pinned).map((row) => threadKey(row.thread)),
);
const orphanAgents = (folders.orphanAgents ?? []).filter(
(thread) =>
!pinnedKeys.has(threadKey(thread)) &&
(folders.environmentId == null || folders.environmentId === thread.environmentId),
);
const orphanKeys = new Set(orphanAgents.map(threadKey));
const groups = folders.projects.map((project) => ({
project,
projectKey: project.key,
memberProjectRefs: project.projectRefs,
}));
const groupedFolders = groupSidebarThreadsByProject(
groups,
[
...input.items.flatMap((row) =>
row.pinned || orphanKeys.has(threadKey(row.thread)) ? [] : [row.thread],
),
...orphanAgents,
],
({ project }) => folders.scoped || !project.archived,
);
const folderKey = (projectKey: string) => `v2-project-folder:${projectKey}`;
const families = sidebarFamilyRows(
input.items.map((row) => row.thread),
[
...input.items
.map((row) => row.thread)
.filter((thread) => !orphanKeys.has(threadKey(thread))),
...orphanAgents,
],
folders.children,
folders.expanded,
folders.routeKey,
(key) => folders.expanded.get(key) ?? true,
new Map(
groupedFolders.map(({ group, threads }) => [
folderKey(group.projectKey),
threads.filter((thread) => orphanKeys.has(threadKey(thread))),
]),
),
);
const renderFamily = (thread: EnvironmentThreadShell, depth: number, showChildren = true) => {
const family = families.get(threadKey(thread)) ?? [];
const renderFamily = (
family: readonly SidebarFamilyItem[],
depth: number,
showChildren = true,
) => {
for (const item of showChildren ? family : family.slice(0, 1)) {
if (item.kind === "role") {
if (item.kind !== "thread") {
result.push({
type: "v2-agent-section",
key: item.key,
depth: depth + item.depth,
role: item.role,
...(item.kind === "role" ? { role: item.role } : {}),
total: item.threads.length,
counts: countStates(item.threads),
expanded: item.expanded,
Expand Down Expand Up @@ -796,18 +837,8 @@ export function buildThreadListV2ListItems(input: {
}
};
for (const row of input.items) {
if (row.pinned) renderFamily(row.thread, 0);
if (row.pinned) renderFamily(families.get(threadKey(row.thread)) ?? [], 0);
}
const groups = folders.projects.map((project) => ({
project,
projectKey: project.key,
memberProjectRefs: project.projectRefs,
}));
const groupedFolders = groupSidebarThreadsByProject(
groups,
input.items.flatMap((row) => (row.pinned ? [] : [row.thread])),
({ project }) => folders.scoped || !project.archived,
);
const collapsedById = new Map([...folders.expanded].map(([key, expanded]) => [key, !expanded]));
const sectionLayouts =
folders.environmentId == null
Expand All @@ -833,7 +864,7 @@ export function buildThreadListV2ListItems(input: {
continue;
}
const { group, threads } = row.folder;
const key = `v2-project-folder:${group.projectKey}`;
const key = folderKey(group.projectKey);
const savedExpansion = group.memberProjectRefs
.map(
({ environmentId, projectId }) =>
Expand Down Expand Up @@ -864,7 +895,12 @@ export function buildThreadListV2ListItems(input: {
counts: countStates(hiddenThreads),
expanded,
});
for (const thread of visibleThreads) renderFamily(thread, depth, expanded);
for (const thread of visibleThreads) {
if (!expanded || !orphanKeys.has(threadKey(thread))) {
renderFamily(families.get(threadKey(thread)) ?? [], depth, expanded);
}
}
if (expanded) renderFamily(families.get(key) ?? [], depth);
}
} else {
const threadItems = input.items.map((item) => buildThreadItem(item));
Expand Down
11 changes: 10 additions & 1 deletion apps/mobile/src/features/threads/useThreadListV2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useAtom } from "@effect/atom-react";
import { Atom } from "effect/reactivity";
import { indexSidebarChildren } from "@t3tools/client-runtime/state/sidebar-families";
import {
indexSidebarChildren,
sidebarOrphanAgents,
} from "@t3tools/client-runtime/state/sidebar-families";
import type { OlderSettledScope } from "@t3tools/client-runtime/state/threads";
import type { EnvironmentId } from "@t3tools/contracts";
import { useCallback, useMemo } from "react";
Expand Down Expand Up @@ -70,6 +73,10 @@ export function useThreadListV2(input: {
const { threads } = input;
const [expanded, setExpanded] = useAtom(expandedSidebarRowsAtom);
const children = useMemo(() => indexSidebarChildren(input.agentThreads), [input.agentThreads]);
const orphanAgents = useMemo(
() => sidebarOrphanAgents(input.agentThreads, children),
[input.agentThreads, children],
);
const projects = useMemo(() => {
const projectKeys =
input.projectRefs == null
Expand Down Expand Up @@ -219,6 +226,7 @@ export function useThreadListV2(input: {
? {
folders: {
children,
orphanAgents,
projects,
layouts: input.projectLayouts,
environmentId: input.environmentId,
Expand All @@ -239,6 +247,7 @@ export function useThreadListV2(input: {
[
layout,
children,
orphanAgents,
projects,
input.projectLayouts,
input.environmentId,
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5728,5 +5728,6 @@
"ddbb7b9406af92ed": "Artefakt {name} entfernen",
"54d9df5245fa49a7": "Das Seitenleistenlayout konnte nicht gespeichert werden. Versuche es erneut.",
"ee71ac7e8e9b000c": "Ultrafast-Modus an",
"e649c08fbd9a1a30": "Fast-Modus an"
"e649c08fbd9a1a30": "Fast-Modus an",
"99d122b4ef1f6aa4": "Agenten"
}
3 changes: 2 additions & 1 deletion apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5730,5 +5730,6 @@
"ddbb7b9406af92ed": "Remove artifact {name}",
"54d9df5245fa49a7": "Could not save sidebar layout. Try again.",
"ee71ac7e8e9b000c": "Ultrafast mode on",
"e649c08fbd9a1a30": "Fast mode on"
"e649c08fbd9a1a30": "Fast mode on",
"99d122b4ef1f6aa4": "Agents"
}
Loading
Loading