diff --git a/packages/session-ui/component-tests/timeline-subagent-rows.spec.ts b/packages/session-ui/component-tests/timeline-subagent-rows.spec.ts new file mode 100644 index 00000000000..cd70b73ba32 --- /dev/null +++ b/packages/session-ui/component-tests/timeline-subagent-rows.spec.ts @@ -0,0 +1,32 @@ +import { expect, story } from "../../stories/playwright/story" + +const playground = "timeline-playground--playground" + +story("a subagent row leads with its status chip and spins only while the work runs", async ({ mount }) => { + const timeline = await mount(playground, { args: { scenario: "Background work", activity: true } }) + const rows = timeline.locator('[data-component="timeline-subagent"] > [data-slot="timeline-event-item"]') + + await expect(rows.locator('[data-slot="timeline-event-item-status"]')).toHaveText([ + "Started", + "Started", + "Updated", + "Completed", + "Failed", + "Started", + "Started", + "Completed", + "Stopped", + ]) + // Agent names are capitalized by CSS, so their text is as configured. + await expect(rows.nth(3).locator("> *")).toHaveText(["Completed", "review Agent", "Review the theme store"]) + // Every subagent here has reported back, so no start spins. + await expect(rows.locator('[data-component="session-progress-indicator-v2"]')).toHaveCount(0) +}) + +story("a start whose subagent has not reported back spins", async ({ mount }) => { + const timeline = await mount(playground, { args: { scenario: "Subagent between tools", activity: true } }) + const status = timeline.locator('[data-component="timeline-subagent"] [data-slot="timeline-event-item-status"]') + + await expect(status).toHaveText("Started") + await expect(status.locator('[data-component="session-progress-indicator-v2"]')).toHaveCount(1) +}) diff --git a/packages/session-ui/src/storybook/current-session-story.tsx b/packages/session-ui/src/storybook/current-session-story.tsx index c415960b684..ffd04a3e358 100644 --- a/packages/session-ui/src/storybook/current-session-story.tsx +++ b/packages/session-ui/src/storybook/current-session-story.tsx @@ -1,3 +1,4 @@ +import type { SessionStatus } from "@opencode/client/promise" import type { SessionDocument } from "../document" import { File } from "../components/file" import { DataProvider, type ReadMediaUrlFn, type TurnDiffSource } from "../context/data" @@ -14,6 +15,8 @@ export function CurrentSessionProviders(props: { backgroundCompaction?: boolean readMedia?: ReadMediaUrlFn turnDiff?: TurnDiffSource + /** Other sessions' statuses, such as the subagents a replay has started. */ + sessionStatus?: Record children: JSX.Element }) { return ( @@ -75,6 +78,7 @@ export function CurrentSessionProviders(props: { [CURRENT_SESSION_ID]: props.document.status, session_child_review: { type: "idle" }, session_child_tests: { type: "busy" }, + ...props.sessionStatus, }, session_diff: { [CURRENT_SESSION_ID]: props.document.diffs }, }} diff --git a/packages/session-ui/src/timeline-next/event-row.tsx b/packages/session-ui/src/timeline-next/event-row.tsx index 8af3987aaa2..215716e200f 100644 --- a/packages/session-ui/src/timeline-next/event-row.tsx +++ b/packages/session-ui/src/timeline-next/event-row.tsx @@ -1,9 +1,10 @@ import { Badge } from "@opencode/ui/badge" import { useI18n } from "@opencode/ui/context/i18n" -import { For, Show, createMemo } from "solid-js" +import { For, Match, Show, Switch, createMemo } from "solid-js" import { BasicTool } from "../components/basic-tool" import { useData } from "../context/data" import { taskAgentName } from "../tools/tool-renderer" +import { SessionProgressIndicatorV2 } from "../v2/components/session-progress-indicator-v2" import { summarizeShells, verbKeys, type TimelineEvent } from "./events" /** @@ -69,8 +70,23 @@ export function TimelineEventRow(props: { ) } +type SubagentState = "started" | "updated" | "completed" | "failed" | "stopped" + +const statusKeys = { + started: verbKeys.started, + updated: "ui.timeline.subagent.updated", + completed: "ui.timeline.subagent.completed", + failed: "ui.toolErrorCard.failed", + stopped: verbKeys.stopped, +} as const + /** One subagent or shell an events row or an opened activity group lists: who did it and what it was. */ -export function TimelineEventItem(props: { event: TimelineEvent; onRevealShell?: (shellID: string) => void }) { +export function TimelineEventItem(props: { + event: TimelineEvent + /** The subagent this start launched is still working. */ + running?: boolean + onRevealShell?: (shellID: string) => void +}) { const i18n = useI18n() const data = useData() @@ -93,14 +109,12 @@ export function TimelineEventItem(props: { event: TimelineEvent; onRevealShell?: const clickable = () => !!((props.event.sessionID && (data.navigateToSession || href())) || props.event.shellID) - const status = () => { - if (props.event.failed) return i18n.t("ui.toolErrorCard.failed") + const state = (): SubagentState => { + if (props.event.failed) return "failed" - if (props.event.verb === "updated") return i18n.t("ui.timeline.subagent.updated") + if (props.event.verb === "ran" || props.event.verb === "finished") return "completed" - if (props.event.verb === "ran" || props.event.verb === "finished") return i18n.t("ui.timeline.subagent.completed") - - return i18n.t(verbKeys[props.event.verb]) + return props.event.verb } return ( @@ -126,25 +140,61 @@ export function TimelineEventItem(props: { event: TimelineEvent; onRevealShell?: open() }} > - {name()}} - > - - {name()} - + {/* A subagent leads with its status chip; a still-running start spins instead of showing its ring. */} + + + }> + + + {i18n.t(statusKeys[state()])} + + {name()} {props.event.title} - - {status()} - {i18n.t("ui.toolErrorCard.failed")} ) } + +/** The status chip's glyph: ring, ↻, ✓, ✕ or ■, drawn at 12px in the chip's text color. */ +function StatusGlyph(props: { state: SubagentState }) { + return ( + + ) +} diff --git a/packages/session-ui/src/timeline-next/row.tsx b/packages/session-ui/src/timeline-next/row.tsx index fc8d79dcaf6..13cf4417158 100644 --- a/packages/session-ui/src/timeline-next/row.tsx +++ b/packages/session-ui/src/timeline-next/row.tsx @@ -50,7 +50,7 @@ import { attached } from "../components/message-file" import { CompactionMessage, CompactionQueued } from "./compaction" import { unwrapErrorMessage } from "./errors" import { TimelineEventItem, TimelineEventRow } from "./event-row" -import { noticeEvent, toolEvent } from "./events" +import { noticeEvent, toolEvent, type TimelineEvent } from "./events" import { trackNestedRails } from "./nested-rail" import { contentEntries, createNextTimelineProjection, resolveContent, workedDuration } from "./projection" import { contentOpens, diffOpens, goal as goalMessage, movedInPlace, thoughtOpens, toolRule } from "./rules" @@ -119,6 +119,27 @@ export function createNextTimelineRowRenderer(input: { } }) + // Subagents that have reported back, by their session: a finish or stop notice ends the work its start launched. + const reported = createMemo( + () => + new Set( + turns().messages.flatMap((message) => { + const sessionID = message.type === "synthetic" ? noticeEvent(message)?.sessionID : undefined + + return sessionID ? [sessionID] : [] + }), + ), + ) + + // A start spins while its subagent has not reported back and its session is still working. + const running = (event: TimelineEvent) => { + const id = event.sessionID + + if (event.verb !== "started" || event.failed || !id || reported().has(id)) return false + + return (data.store.session_status[id]?.type ?? "idle") !== "idle" + } + const patchOwners = createMemo(() => { const owners = new Map() const rows = input.projection.rows() @@ -441,7 +462,7 @@ export function createNextTimelineRowRenderer(input: { {(event) => (
- +
)}
diff --git a/packages/session-ui/src/timeline-next/stories/playground.stories.tsx b/packages/session-ui/src/timeline-next/stories/playground.stories.tsx index 91568f2ab97..630d6369ecd 100644 --- a/packages/session-ui/src/timeline-next/stories/playground.stories.tsx +++ b/packages/session-ui/src/timeline-next/stories/playground.stories.tsx @@ -228,7 +228,7 @@ export const Playground = {
- + = {} const at = () => start + state.used * 1_500 const id = (prefix: string) => `${prefix}_${messages.length}_${state.used}` @@ -907,6 +911,7 @@ export function replayScript(script: Beat[], limit: number, start: number) { if (beat.kind === "report" && beat.source === "subagent") { closeStep() messages.push(subagentReport(id("msg_report"), at(), beat)) + children[beat.childID] = { type: "idle" } state.busy = true } @@ -946,7 +951,13 @@ export function replayScript(script: Beat[], limit: number, start: number) { if (beat.kind === "say") assistant().content.push({ type: "text", text: done ? beat.text : beat.text.slice(0, beat.text.length / 2) }) - if (beat.kind === "tool") assistant().content.push(tool(id("tool"), beat, done, at())) + if (beat.kind === "tool") { + const call = tool(id("tool"), beat, done, at()) + const sessionID = beat.name === "subagent" ? toolEvent(call)?.sessionID : undefined + assistant().content.push(call) + + if (sessionID) children[sessionID] = { type: "busy" } + } if (beat.kind === "interrupt" && state.assistant) { state.assistant.content = state.assistant.content.map((content) => @@ -982,6 +993,7 @@ export function replayScript(script: Beat[], limit: number, start: number) { status: { type: state.busy ? "busy" : "idle" }, diffs: [], } satisfies SessionDocument, + children: { ...children }, caption: state.caption, } } diff --git a/packages/session-ui/src/timeline-next/timeline-next.css b/packages/session-ui/src/timeline-next/timeline-next.css index 596e8f61d9e..ca403bf4a30 100644 --- a/packages/session-ui/src/timeline-next/timeline-next.css +++ b/packages/session-ui/src/timeline-next/timeline-next.css @@ -278,6 +278,7 @@ [data-slot="timeline-event-item-name"] { flex-shrink: 0; color: var(--v2-text-text-muted); + white-space: nowrap; text-transform: capitalize; } @@ -292,6 +293,59 @@ [data-slot="timeline-event-item"] [data-component="tag"] { flex-shrink: 0; } + + /* A subagent's status chip: its outline, fill and glyph say what happened, so no status word follows the title. + Updated is info blue softened toward muted; the others use their state colors as they are. */ + [data-slot="timeline-event-item-status"] { + box-sizing: border-box; + display: inline-flex; + flex-shrink: 0; + align-items: center; + gap: 4px; + height: 18px; + padding: 0 6px; + border: 1px solid transparent; + border-radius: 4px; + font-size: 12px; + font-weight: 530; + line-height: 16px; + white-space: nowrap; + + [data-slot="timeline-event-item-glyph"], + [data-component="session-progress-indicator-v2"] { + flex-shrink: 0; + width: 12px; + height: 12px; + margin-left: -1px; + color: currentColor; + } + + &[data-state="started"] { + border-color: color-mix(in srgb, var(--v2-text-text-muted) 35%, transparent); + color: var(--v2-text-text-faint); + } + + &[data-state="updated"] { + border-style: dashed; + border-color: color-mix(in srgb, var(--v2-state-fg-info) 50%, transparent); + color: color-mix(in srgb, var(--v2-state-fg-info) 70%, var(--v2-text-text-muted)); + } + + &[data-state="completed"] { + background: color-mix(in srgb, var(--v2-state-fg-success) 16%, transparent); + color: var(--v2-state-fg-success); + } + + &[data-state="failed"] { + background: var(--v2-state-bg-danger); + color: var(--v2-state-fg-danger); + } + + &[data-state="stopped"] { + border-color: color-mix(in srgb, var(--v2-text-text-muted) 55%, transparent); + color: var(--v2-text-text-muted); + } + } } /* Rows are spaced by block: rows that continue a block sit the small gap below the one above, and a