diff --git a/packages/app/src/session/timeline/message-timeline.tsx b/packages/app/src/session/timeline/message-timeline.tsx index 8f498fe8ea6..591a7b843b3 100644 --- a/packages/app/src/session/timeline/message-timeline.tsx +++ b/packages/app/src/session/timeline/message-timeline.tsx @@ -513,7 +513,7 @@ function MessageTimelineView( // The lane keeps its height while empty, so Working and the hint come and go without moving the rows around it. // The bottom lane also keeps its height while live status moves into the Activity row, so the tail the activity pill // floats in never closes and a pinned timeline does not shift when input waits. - const activity = (live: () => boolean) => ( + const activity = (live: () => boolean, inRow = false) => (
@@ -567,7 +568,7 @@ function MessageTimelineView( // row: Working hides and returns several times in one step, and each change would move that input 36px. const shown = createMemo((was) => was || working() || backgroundHintPresence.present(), false) - return {activity(() => true)} + return {activity(() => true, true)} }} )} diff --git a/packages/session-ui/src/timeline-next/projection.test.ts b/packages/session-ui/src/timeline-next/projection.test.ts index 0aa1b528085..71431a34a69 100644 --- a/packages/session-ui/src/timeline-next/projection.test.ts +++ b/packages/session-ui/src/timeline-next/projection.test.ts @@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test" import type { SessionMessageAssistant, SessionMessageInfo, SessionMessageUser } from "@opencode/client/promise" import { Predicate } from "effect" import { createRoot } from "solid-js" +import { subagentReport } from "../storybook/current-session-fixtures" import { timelinePresets } from "../timeline/detail" import { createNextTimelineProjection, workedDuration } from "./projection" import { replayScript, scenarios } from "./stories/session-replay" @@ -87,6 +88,67 @@ describe("New timeline projection", () => { expect(groups).toEqual(["first", "notice", "second"]) }) + + test("a subagent's report shows above the status line before the agent takes it, and the user's input below", () => { + const steer = { id: "steer", type: "user", text: "Also check the tests", time: { created: 2 } } as const + + const messages: SessionMessageInfo[] = [ + { id: "user", type: "user", text: "Go", time: { created: 0 } }, + step("working", 1, { + content: [ + { + id: "shell", + type: "tool", + name: "shell", + state: { status: "running", input: { command: "sleep 60" }, metadata: {} }, + time: { created: 1 }, + }, + ], + }), + steer, + subagentReport("report", 3, { + childID: "child", + agent: "explore", + state: "completed", + description: "Trace the bug", + body: "Found it.", + }), + ] + + const rows = (messages: SessionMessageInfo[], pending: ReadonlySet) => + createRoot((dispose) => { + const projection = createNextTimelineProjection({ + sessionMessages: () => messages, + status: () => ({ type: "busy" }), + timelineDetail: () => detailed, + pendingInputIDs: () => pending, + }) + + const result = projection.rows().map((row) => { + if (!Predicate.isTagged(row, "AssistantPart")) return row._tag + + return row.group.type === "part" + ? row.group.ref.messageID + : row.group.refs.map((ref) => ref.messageID).join("+") + }) + + dispose() + + return result + }) + + const alone = messages.filter((message) => message !== steer) + + expect(rows(alone, new Set(["report"]))).toEqual(["UserMessage", "working", "report"]) + expect(rows(messages, new Set(["steer", "report"]))).toEqual([ + "UserMessage", + "working", + "report", + "Activity", + "TurnGap", + "UserMessage", + ]) + }) }) describe("workedDuration", () => { diff --git a/packages/session-ui/src/timeline-next/projection.ts b/packages/session-ui/src/timeline-next/projection.ts index ff2c382cf9f..c7a5d4c34b2 100644 --- a/packages/session-ui/src/timeline-next/projection.ts +++ b/packages/session-ui/src/timeline-next/projection.ts @@ -314,18 +314,14 @@ function constructRows(input: Input) { }), ] - // Like the TUI, a queued compaction waits after the active turn and ahead of every undelivered input: - // steers, which own turns, and synthetic notices, which ride at the end of the active one. - const pendingAt = rows.findIndex( - (row) => - input.pendingInputIDs?.has(row.userMessageID) || - (Predicate.isTagged(row, "Notice") && input.pendingInputIDs?.has(row.messageID)), - ) + // Like the TUI, a queued compaction waits after the active turn and ahead of every steer still waiting for delivery. + // Notices waiting for delivery are already in the active turn, since they report what happened. + const pendingAt = rows.findIndex((row) => input.pendingInputIDs?.has(row.userMessageID)) rows.splice( pendingAt < 0 ? rows.length : pendingAt, 0, - // Live status ends the work the model has seen, so it stays above everything still waiting for delivery. + // Live status ends the turn, so it stays above the input the user steered in, which waits for the agent to reply. ...(input.status.type !== "idle" && activeMessageID && (pendingAt >= 0 || input.queuedCompactionIDs.length > 0) ? [new TimelineRow.Activity({ userMessageID: activeMessageID })] : []), @@ -380,7 +376,11 @@ function constructTurns(input: Input) { if (echoesUserShell(message, userShellIDs)) return if (isNotice(message)) { - if (current) current.entries.push({ type: "notice", message }) + // A notice still waiting for delivery, such as a subagent reporting back, already happened, so it joins the + // working turn above the status line, even when input the user steered in meanwhile waits below it. + const turn = input.pendingInputIDs?.has(message.id) ? (execution?.turn ?? current) : current + + if (turn) turn.entries.push({ type: "notice", message }) else leading.push(message) return diff --git a/packages/session-ui/src/timeline-next/row.tsx b/packages/session-ui/src/timeline-next/row.tsx index 4ffa71fcc23..b2b83513b99 100644 --- a/packages/session-ui/src/timeline-next/row.tsx +++ b/packages/session-ui/src/timeline-next/row.tsx @@ -460,6 +460,7 @@ export function createNextTimelineRowRenderer(input: { return ( input.disclosure.set(row().group.key, open)} onSizeChange={onSizeChange} diff --git a/packages/session-ui/src/timeline-next/status-line.tsx b/packages/session-ui/src/timeline-next/status-line.tsx index b7ee04e680f..88d34a12c11 100644 --- a/packages/session-ui/src/timeline-next/status-line.tsx +++ b/packages/session-ui/src/timeline-next/status-line.tsx @@ -12,6 +12,8 @@ export function StatusLane(props: { collapsed?: boolean /** The space above the next row of the turn, so the line sits where that row will. */ spacing?: TimelineGap + /** The lane sits in a row of the timeline, which clips what reaches past it, rather than in its open tail. */ + inRow?: boolean class?: string children?: JSX.Element }) { @@ -21,6 +23,7 @@ export function StatusLane(props: { data-component="timeline-status-lane" data-collapsed={props.collapsed ? "" : undefined} data-spacing={props.spacing} + data-in-row={props.inRow ? "" : undefined} class={props.class} > diff --git a/packages/session-ui/src/timeline-next/timeline-next.css b/packages/session-ui/src/timeline-next/timeline-next.css index 83dba6cc584..d4a7ac38532 100644 --- a/packages/session-ui/src/timeline-next/timeline-next.css +++ b/packages/session-ui/src/timeline-next/timeline-next.css @@ -581,9 +581,19 @@ --timeline-status-space: var(--timeline-gap-l); } + /* The background hint's 24px button is centred on the 16px line and reaches 4px past it. A row clips at its own + height, so in a row the lane keeps that room below the line, whether or not the hint shows, so the input waiting + below does not move when it comes and goes. */ + &[data-in-row] { + --timeline-status-hint-overflow: calc((24px - var(--line-height-compact)) / 2); + height: calc(var(--line-height-compact) + var(--timeline-status-space) + var(--timeline-status-hint-overflow)); + padding-bottom: var(--timeline-status-hint-overflow); + } + &[data-collapsed] { height: 0; padding-top: 0; + padding-bottom: 0; overflow: hidden; } diff --git a/packages/session-ui/src/timeline-next/tools/context-group.tsx b/packages/session-ui/src/timeline-next/tools/context-group.tsx index 15e761e4576..a0532fa76af 100644 --- a/packages/session-ui/src/timeline-next/tools/context-group.tsx +++ b/packages/session-ui/src/timeline-next/tools/context-group.tsx @@ -285,6 +285,7 @@ function GroupItem(props: { props.onToolOpenChange?.(tool().id, open)} onSizeChange={props.onSizeChange} @@ -542,7 +543,7 @@ function activityLabel(group: SessionMessageAssistantTool[], i18n: UiI18n) { const main = { // A few files read better by name; past that, the count says more than a list that truncates. edit: - files.length <= 3 + files.length <= 2 ? files.map((path) => getFilename(path)).join(", ") : i18n.plural("ui.timeline.activity.files", files.length), run: commands[0]!, diff --git a/packages/session-ui/src/tools/tool-renderer.tsx b/packages/session-ui/src/tools/tool-renderer.tsx index 66d56646609..1e8fe7d6cf9 100644 --- a/packages/session-ui/src/tools/tool-renderer.tsx +++ b/packages/session-ui/src/tools/tool-renderer.tsx @@ -865,26 +865,48 @@ export function CurrentReadToolGroup(props: { open?: boolean onOpenChange?: (open: boolean) => void onSizeChange?: () => void + /** Names each file once, and up to this many while closed; past that the closed row says how many files. */ + names?: number }) { const i18n = useI18n() const [state, setState] = createStore({ truncated: false }) const disclosure = createDisclosure({ open: () => props.open, onOpenChange: (open) => props.onOpenChange?.(open) }) const open = disclosure.open - const expandable = () => open() || state.truncated const pending = createMemo(() => props.tools.some((tool) => tool.state.status === "streaming" || tool.state.status === "running"), ) - const files = createMemo(() => - props.tools.flatMap((tool) => { + const files = createMemo(() => { + const reads = props.tools.flatMap((tool) => { const input = toolInput(currentToolInput(tool)) const name = getFilename(input.path ?? "") - return name ? [{ id: tool.id, name, args: readArgs(input) }] : [] - }), + return name ? [{ id: tool.id, path: input.path ?? "", name, args: readArgs(input) }] : [] + }) + + if (props.names === undefined) return reads + + // A file read in several ranges is named once, without one range standing for the rest. + return [ + ...reads + .reduce((unique, file) => { + const seen = unique.get(file.path) + + return unique.set(file.path, seen ? { ...seen, args: [] } : file) + }, new Map()) + .values(), + ] + }) + + const summary = createMemo(() => + props.names !== undefined && !open() && files().length > props.names + ? i18n.plural("ui.timeline.activity.files", files().length) + : undefined, ) + const expandable = () => open() || state.truncated || !!summary() + let list: HTMLSpanElement | undefined const measure = () => { @@ -925,20 +947,27 @@ export function CurrentReadToolGroup(props: { - - {(file, index) => ( - <> - 0}> - - {file().name} - - {(arg) => {` ${arg}`}} - - , - - - )} - + + {(file, index) => ( + <> + 0}> + + {file().name} + + {(arg) => {` ${arg}`}} + + , + + + )} + + } + > + {(text) => text()} +