diff --git a/webui/browser/history-boundary.spec.ts b/webui/browser/history-boundary.spec.ts index 713181255..dec18127c 100644 --- a/webui/browser/history-boundary.spec.ts +++ b/webui/browser/history-boundary.spec.ts @@ -304,23 +304,27 @@ test("wheel loading hands off to a retained 48px slot; prepend and delayed layou expect(history.reads).toHaveLength(1); }); -test("archived task results stay with the retained boundary when earlier messages load", async ({ page }) => { +test("task results stay with their prompts and retain the reading boundary when earlier messages load", async ({ page }) => { const history = await installHistory(page); - await page.route("**/api/sessions/**/subagents", (route) => route.fulfill({ json: { tasks: [{ - task_id: "legacy", revision: 1, label: "Earlier check", task_description: "Check earlier work", + await page.route("**/api/sessions/**/subagents", (route) => route.fulfill({ json: { tasks: [ + { task_id: "current", label: "Current check", origin_message_id: "u40" }, + { task_id: "earlier", label: "Earlier check", origin_message_id: "u28" }, + ].map((task) => ({ + ...task, revision: 1, task_description: "Check work", state: "done", phase: "completed", elapsed_seconds: 2, iteration: 1, tool_events: [], usage: null, receipts: {}, result: "Verified", partial: false, - stop_reason: null, error: null, origin_turn_id: "legacy-turn", origin_message_id: null, - created_at: 100, completed_at: 102, - }] } })); + stop_reason: null, error: null, origin_turn_id: null, created_at: 100, completed_at: 102, + })) } })); await page.goto("/browser/fixture.html?case=history-boundary&tasks"); const body = page.getByTestId("thread-message-region"); - const otherTasks = body.getByRole("region", { name: "Other tasks" }); - await expect(otherTasks).toBeAttached(); + const currentResults = body.locator('[data-user-prompt-id="u40"] + [data-subagent-results]'); + const earlierResults = body.locator('[data-user-prompt-id="u28"] + [data-subagent-results]'); + await expect(body.locator("[data-subagent-results]")).toHaveCount(1); + await expect(currentResults).toHaveCount(1); // Clicking an offscreen disclosure scrolls it into view and can prefetch history. await positionAtTop(body); - await otherTasks.getByRole("button", { name: /Other tasks/ }).click(); - await expect(otherTasks.getByRole("button", { name: /Earlier check Completed/ })).toBeVisible(); + await currentResults.locator("[data-subagent-results-summary]").click(); + await expect(currentResults.getByRole("button", { name: /Current check Completed/ })).toBeVisible(); await stableLayout(body); const originalTop = await positionAtTop(body); await body.hover(); @@ -336,9 +340,13 @@ test("archived task results stay with the retained boundary when earlier message await expect(page.locator(".thread-history-slot")).toHaveCount(0); await stableLayout(body); await expectAnchorCoordinate(body, "Question 40", preCompletionAnchorTop); - await expect(otherTasks).toHaveCount(1); - await expect(otherTasks.getByRole("button", { name: /Other tasks/ })).toHaveAttribute("aria-expanded", "true"); + await expect(body.locator("[data-subagent-results]")).toHaveCount(2); + await expect(currentResults.locator("[data-subagent-results-summary]")).toHaveAttribute("aria-expanded", "true"); + await expect(currentResults.getByRole("button", { name: /Current check Completed/ })).toBeVisible(); + await expect(earlierResults.locator("[data-subagent-results-summary]")).toHaveAttribute("aria-expanded", "false"); expect(history.reads).toHaveLength(1); + await earlierResults.locator("[data-subagent-results-summary]").click(); + await expect(earlierResults.getByRole("button", { name: /Earlier check Completed/ })).toBeVisible(); }); test("touch reveals a static partial ready header, arms only on release, and retains a stable full loading header", async ({ browser, baseURL }) => { diff --git a/webui/browser/subagent-dock.spec.ts b/webui/browser/subagent-dock.spec.ts index 320c6d60a..1fa56ad60 100644 --- a/webui/browser/subagent-dock.spec.ts +++ b/webui/browser/subagent-dock.spec.ts @@ -10,6 +10,27 @@ async function settledMotion(target: Locator) { } for (const width of [1440, 390]) { + test(`opens a session without detached past results at ${width}px`, async ({ page }, info) => { + await page.setViewportSize({ width, height: 900 }); + await page.goto("/browser/fixture.html?case=subagent-dock&past&saved"); + const messages = page.getByTestId("thread-message-region"); + const archives = messages.locator("[data-subagent-results]"); + await expect(page.getByTestId("subagent-task-dock-trigger")).toContainText("Running: 3"); + await expect(archives).toHaveCount(0); + await page.getByRole("button", { name: "全部完成", exact: true }).click(); + await expect(archives).toHaveCount(1); + await expect(archives).toContainText("Completed: 3"); + await archives.locator("[data-subagent-results-summary]").click(); + await expect(archives.locator("[data-subagent-id]")).toHaveCount(3); + await messages.evaluate(node => { node.scrollTop = 0; }); + await settledMotion(messages); + await page.screenshot({ path: info.outputPath("results-with-prompt.png") }); + await page.reload(); + await expect(archives).toHaveCount(1); + await expect(archives).toContainText("Completed: 3"); + await expect(page.getByTestId("subagent-task-dock-trigger")).toHaveCount(0); + }); + test(`keeps subtasks reachable through long replies, independent list scrolling and detail handoff at ${width}px`, async ({ page }, info) => { const errors: string[] = []; page.on("pageerror", error => errors.push(error.message)); diff --git a/webui/src/components/thread/SubagentTaskResults.tsx b/webui/src/components/thread/SubagentTaskResults.tsx index c755257cc..588c33fea 100644 --- a/webui/src/components/thread/SubagentTaskResults.tsx +++ b/webui/src/components/thread/SubagentTaskResults.tsx @@ -7,11 +7,6 @@ import { ThreadMessages } from "@/components/thread/ThreadMessages"; import { isActiveSubagentTask, type ObservedSubagentTask } from "@/lib/subagent-tasks"; import type { UIMessage } from "@/lib/types"; -export function useHasSubagentResults(): boolean { - const context = useSubagentTasks(); - return context?.tasks.some((task) => !isActiveSubagentTask(task)) ?? false; -} - /** Exact initiating prompts win; replayed IDs fall back to the turn's first user message. */ function groupResults(messages: UIMessage[], tasks: ObservedSubagentTask[]) { const promptsById = new Map(); @@ -25,20 +20,16 @@ function groupResults(messages: UIMessage[], tasks: ObservedSubagentTask[]) { } const byMessage = new Map(); - const unlinked: ObservedSubagentTask[] = []; for (const task of tasks) { if (isActiveSubagentTask(task)) continue; const prompt = (task.origin_message_id ? promptsById.get(task.origin_message_id) : undefined) ?? (task.origin_turn_id ? firstPromptByTurn.get(task.origin_turn_id) : undefined); - if (!prompt) { - unlinked.push(task); - continue; - } + if (!prompt) continue; const group = byMessage.get(prompt.id) ?? []; group.push(task); byMessage.set(prompt.id, group); } - return { byMessage, unlinked }; + return byMessage; } export function SubagentThreadMessages(props: ComponentProps) { @@ -65,13 +56,8 @@ export function SubagentThreadMessages(props: ComponentProps - {props.beforeMessages} - toggle(groups.unlinked)} /> - : props.beforeMessages} afterUserMessage={(message) => { - const results = groups.byMessage.get(message.id); + const results = groups.get(message.id); return <> {props.afterUserMessage?.(message)} {results ? ; } -function SubagentResults({ tasks, unlinked = false, expanded, onToggle }: { +function SubagentResults({ tasks, expanded, onToggle }: { tasks: ObservedSubagentTask[]; - unlinked?: boolean; expanded: boolean; onToggle: () => void; }) { @@ -90,13 +75,13 @@ function SubagentResults({ tasks, unlinked = false, expanded, onToggle }: { const rowsId = useId(); const completed = tasks.filter((task) => task.state === "done").length; const attention = tasks.filter((task) => task.state === "error" || task.state === "incomplete" || task.state === "interrupted").length; - const title = t(unlinked ? "thread.subagents.otherWorkTitle" : "thread.subagents.workTitle"); + const title = t("thread.subagents.workTitle"); const summary = completed === tasks.length ? t("thread.subagents.completed", { count: completed }) : t("thread.subagents.finished", { count: tasks.length }); return
+ className="thread-message-row mt-2 grid grid-cols-[1rem_minmax(0,1fr)_minmax(6rem,max-content)_3rem] items-center gap-x-2.5">