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
2 changes: 2 additions & 0 deletions apps/mobile/src/features/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ export function HomeScreen(props: HomeScreenProps) {
onNewThreadOnBranch={props.onNewThreadOnBranch}
thread={thread}
agentCount={item.agentCount}
familyExpanded={item.familyExpanded}
onToggleFamily={toggleSidebarRow}
agentRow={item.agentRow}
depth={item.depth}
listVisible={props.visible}
Expand Down
22 changes: 22 additions & 0 deletions apps/mobile/src/features/home/useThreadListActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const state = vi.hoisted(() => ({
dropBusy: false,
holdingRows: false,
failedAction: null as string | null,
retiringArchive: false,
titleOutcome: null as ThreadTitleRegenerationOutcome | null,
archivedRefreshes: [] as string[],
onArchivedRefresh: undefined as (() => void) | undefined,
Expand Down Expand Up @@ -181,6 +182,8 @@ vi.mock("../../state/threads", () => ({
if (action === state.failedAction)
return AsyncResult.failure(Cause.fail(new Error("Server rejected action")));
state.afterRequest?.();
if (action === "archive" && state.retiringArchive)
return AsyncResult.success({ sequence: 1, retiring: true });
return AsyncResult.success(action === "regenerateTitle" ? state.titleOutcome : undefined);
},
]),
Expand All @@ -190,6 +193,7 @@ vi.mock("../../state/threads", () => ({

import { appAtomRegistry } from "../../state/atom-registry";
import { composerDraftsAtom } from "../../state/use-composer-drafts";
import { registerThreadDismissal } from "./thread-dismissal";
import { dismissThreadUndoNotice, readThreadUndoNotice } from "./thread-undo-notice";
import { useThreadListActions } from "./useThreadListActions";

Expand Down Expand Up @@ -221,6 +225,7 @@ const mutationCases = [
beforeEach(() => {
state.connectedEnvironmentIds = [primaryEnvironmentId, otherEnvironmentId];
state.failedAction = null;
state.retiringArchive = false;
state.titleOutcome = null;
state.archivedRefreshes = [];
state.onArchivedRefresh = undefined;
Expand Down Expand Up @@ -657,6 +662,23 @@ describe("thread action undo", () => {
});

describe("thread archive guard", () => {
it("restores the visible row when archiving begins retirement", async () => {
const thread = makeThread();
state.retiringArchive = true;
const restore = vi.fn();
const unregister = registerThreadDismissal(`${thread.environmentId}:${thread.id}`, () => ({
finished: Promise.resolve(),
restore,
}));
try {
expect(await useThreadListActions().archiveThread(thread)).toBe(true);
expect(restore).toHaveBeenCalledOnce();
expect(state.archivedRefreshes).toEqual([]);
} finally {
unregister();
}
});

it("keeps active provider runs out of the archive", async () => {
const thread = makeThread({
runtime: {
Expand Down
10 changes: 9 additions & 1 deletion apps/mobile/src/features/home/useThreadListActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ function liveThread(thread: EnvironmentThreadShell): EnvironmentThreadShell {
);
}

function isRetiringArchive(value: unknown) {
return (
typeof value === "object" && value !== null && "retiring" in value && value.retiring === true
);
}

function useThreadActionExecutor(
onCompleted?: (action: ThreadListAction, thread: EnvironmentThreadShell) => void,
) {
Expand Down Expand Up @@ -198,12 +204,14 @@ function useThreadActionExecutor(
environmentId: thread.environmentId,
input: { threadId: thread.id },
}),
(result) => result._tag === "Success",
(result) =>
result._tag === "Success" && !(action === "archive" && isRetiringArchive(result.value)),
);
if (result._tag === "Failure") {
Dialog.alert(actionFailureTitle(action), actionFailureMessage(action, result.cause));
return false;
}
if (action === "archive" && isRetiringArchive(result.value)) return true;
onSucceeded?.(result.value);
if (action === "archive" || action === "delete") {
for (const kind of ["settle", "snooze", "pin"]) ThreadUndo.invalidate(kind, key);
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
onNewThreadOnBranch={props.onNewThreadOnBranch}
thread={thread}
agentCount={item.agentCount}
familyExpanded={item.familyExpanded}
onToggleFamily={toggleSidebarRow}
agentRow={item.agentRow}
depth={item.depth}
listVisible={props.visible}
Expand Down
74 changes: 67 additions & 7 deletions apps/mobile/src/features/threads/thread-list-v2-items.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
import Svg, { Circle } from "react-native-svg";
import Svg, { Circle, Path } from "react-native-svg";
import { IconButton } from "../../components/ui/IconButton";
import {
formatSidebarAgentStates,
Expand All @@ -9,6 +9,7 @@ import { useViewability } from "@legendapp/list/react-native";
import {
canStartFresh,
effortBarHeights,
sidebarCodexDefaultSpeed,
sidebarRoleLabels,
sidebarRowModel,
shouldRecedeSidebarThread,
Expand Down Expand Up @@ -781,9 +782,32 @@ export function ThreadListV2AgentSectionHeader({
);
}

function ThreadSpeedBolt(props: { ultrafast: boolean; color: string; surface: string }) {
const bolt =
"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z";
return (
<Svg
width={props.ultrafast ? 15 : 12}
height={12}
viewBox={props.ultrafast ? "0 0 30 24" : "0 0 24 24"}
style={{ flexShrink: 0 }}
>
{props.ultrafast ? (
<>
<Path d={bolt} x={6} fill="none" stroke={props.color} strokeWidth={2} />
<Path d={bolt} fill={props.surface} stroke={props.surface} strokeWidth={4} />
</>
) : null}
<Path d={bolt} fill={props.color} />
</Svg>
);
}

export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
readonly thread: EnvironmentThreadShell;
readonly agentCount: number;
readonly familyExpanded?: boolean | undefined;
readonly onToggleFamily: (key: string, expanded: boolean) => void;
readonly agentRow: boolean;
readonly depth?: number;
readonly listVisible: boolean;
Expand Down Expand Up @@ -874,11 +898,18 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
const driver =
props.providerInstance?.driverKind ??
(isProviderDriverKind(modelInstanceId) ? modelInstanceId : null);
const { modelParts, effort } = sidebarRowModel(
const codexDefaultSpeed = useAtomValue(
serverEnvironment.settingsValueAtom(thread.environmentId),
(settings) => sidebarCodexDefaultSpeed(settings, thread.modelSelection, driver),
);
const { modelParts, effort, speed } = sidebarRowModel(
thread.modelSelection,
provider?.models?.find((model) => model.slug === thread.modelSelection.model),
driver,
codexDefaultSpeed,
);
const speedLabel =
speed === "ultrafast" ? gt("Ultrafast mode on") : speed === "fast" ? gt("Fast mode on") : null;
const role = thread.delegatedRole;
const rowTitle =
props.agentRow || !isDelegationModelRole(role) ? thread.title : m(sidebarRoleLabels[role]);
Expand Down Expand Up @@ -1514,7 +1545,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
interactionOpacity={rowAppearance.interactionOpacity}
className={rowAppearance.className}
accessibilityHint={swipeAccessibilityHint}
accessibilityLabel={[rowAccessibilityLabel, agentCountLabel, retiringLabel]
accessibilityLabel={[rowAccessibilityLabel, agentCountLabel, retiringLabel, speedLabel]
.filter(Boolean)
.join(", ")}
accessibilityRole="button"
Expand All @@ -1534,7 +1565,6 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
<View
className="min-h-11 flex-row items-center gap-1"
style={{
marginStart: props.agentRow ? 16 : 0,
opacity: recede || retiringLabel !== null ? 0.65 : 1,
}}
>
Expand Down Expand Up @@ -1622,6 +1652,13 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
))}
</View>
) : null}
{speed !== "standard" ? (
<ThreadSpeedBolt
ultrafast={speed === "ultrafast"}
color={theme["--color-foreground-muted"]}
surface={rowAppearance.providerIconSurfaceColor}
/>
) : null}
<View className="min-w-0 flex-1 flex-row items-center gap-1">
<Text
className={cn(
Expand All @@ -1648,9 +1685,32 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
{retiringLabel}
</Text>
)}
{agentCountLabel ? (
<Text className={cn("shrink-0 text-2xs", muted)}>{agentCountLabel}</Text>
) : null}
{props.familyExpanded === undefined ? (
agentCountLabel && (
<Text className={cn("shrink-0 text-2xs", muted)}>{agentCountLabel}</Text>
)
) : (
<Pressable
className="min-h-11 shrink-0 flex-row items-center gap-1"
accessibilityRole="button"
accessibilityLabel={agentCountLabel ?? undefined}
accessibilityState={{ expanded: props.familyExpanded }}
onPress={(event) => {
event.stopPropagation();
props.onToggleFamily(
`${thread.environmentId}:${thread.id}`,
props.familyExpanded === true,
);
}}
>
<Text className={cn("text-2xs", muted)}>{agentCountLabel}</Text>
<SymbolView
name={props.familyExpanded ? "chevron.down" : "chevron.right"}
size={10}
tintColorClassName="foreground-muted"
/>
</Pressable>
)}
{props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
{issue ? (
<View className="shrink-0 flex-row items-center gap-0.5">
Expand Down
38 changes: 17 additions & 21 deletions apps/mobile/src/features/threads/threadListV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1415,13 +1415,8 @@ it("renders saved section names, nesting, and interleaved project order", () =>
]);
});

it("keeps active and settled threads above role sections and summarizes collapsed folders", () => {
it("nests role sections under their orchestrator and summarizes collapsed folders", () => {
const root = makeThread({ id: ThreadId.make("root"), title: "Root" });
const archived = makeThread({
id: ThreadId.make("archived"),
title: "Archived",
archivedAt: NOW,
});
const working = makeThread({
id: ThreadId.make("working"),
title: "Working agent",
Expand All @@ -1442,8 +1437,8 @@ it("keeps active and settled threads above role sections and summarizes collapse
delegatedRole: "review",
hasPendingUserInput: true,
lineage: {
parentThreadId: archived.id,
rootThreadId: archived.id,
parentThreadId: root.id,
rootThreadId: root.id,
relationshipToParent: "subagent",
},
});
Expand All @@ -1452,15 +1447,15 @@ it("keeps active and settled threads above role sections and summarizes collapse
title: "Settled",
settledOverride: "settled",
});
const threads = [root, archived, working, waiting, settled];
const threads = [root, working, waiting, settled];
const children = indexSidebarChildren(threads);
const projects = buildHomeProjectScopes({
projects: [makeProjectFixture({ id: root.projectId, title: "Project", environmentId })],
environmentId: null,
projectGroupingMode: "separate",
});
const folderKey = `v2-project-folder:${projects[0]!.key}`;
const roleKey = (role: string) => `v2-agent-role:${projects[0]!.key}:${role}`;
const roleKey = (role: string) => `role:${environmentId}:root:${role}`;
const { items } = buildThreadListV2Items({
threads,
environmentId: null,
Expand All @@ -1486,28 +1481,27 @@ it("keeps active and settled threads above role sections and summarizes collapse
expect(expanded.map((item) => item.key)).toEqual([
folderKey,
`v2-thread:${environmentId}:root`,
`v2-thread:${environmentId}:settled`,
roleKey("implementation"),
`v2-thread:${environmentId}:working`,
roleKey("review"),
`v2-thread:${environmentId}:waiting`,
`v2-thread:${environmentId}:settled`,
]);
expect(expanded[1]).toMatchObject({ agentCount: 1, agentRow: false });
expect(expanded[3]).toMatchObject({
expect(expanded[1]).toMatchObject({ agentCount: 2, agentRow: false, familyExpanded: true });
expect(expanded[2]).toMatchObject({
role: "implementation",
counts: { working: 1, attention: 0, failed: 0 },
});
expect(expanded[5]).toMatchObject({
expect(expanded[4]).toMatchObject({
role: "review",
counts: { working: 0, attention: 1, failed: 0 },
});

const collapsed = rows([folderKey]);
expect(collapsed).toHaveLength(1);
expect(rows([folderKey], `${environmentId}:root`).map((row) => row.key)).toEqual([
folderKey,
`v2-thread:${environmentId}:root`,
]);
expect(
rows([folderKey, `${environmentId}:root`], `${environmentId}:root`).map((row) => row.key),
).toEqual([folderKey, `v2-thread:${environmentId}:root`]);
expect(collapsed[0]).toMatchObject({
expanded: false,
counts: { working: 1, attention: 1, failed: 0 },
Expand All @@ -1516,9 +1510,11 @@ it("keeps active and settled threads above role sections and summarizes collapse
expect(
rows([roleKey("review")]).some((item) => item.key === `v2-thread:${environmentId}:waiting`),
).toBe(false);
expect(rows([roleKey("review")], `${environmentId}:waiting`).at(-1)?.key).toBe(
`v2-thread:${environmentId}:waiting`,
);
expect(
rows([roleKey("review")], `${environmentId}:waiting`).some(
(row) => row.key === `v2-thread:${environmentId}:waiting`,
),
).toBe(true);
expect(
getThreadListV2OrderedSection({ threads, section: "active", now: NOW }).map(
(thread) => thread.id,
Expand Down
Loading
Loading