mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
feat(app): status chips for subagent rows in the new timeline (#64102)
This commit is contained in:
@@ -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)
|
||||
})
|
||||
@@ -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<string, SessionStatus>
|
||||
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 },
|
||||
}}
|
||||
|
||||
@@ -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()
|
||||
}}
|
||||
>
|
||||
<Show
|
||||
when={props.event.kind === "subagent"}
|
||||
fallback={<span data-slot="timeline-event-item-name">{name()}</span>}
|
||||
>
|
||||
<Badge data-slot="timeline-event-item-name" variant="neutral">
|
||||
{name()}
|
||||
</Badge>
|
||||
{/* A subagent leads with its status chip; a still-running start spins instead of showing its ring. */}
|
||||
<Show when={props.event.kind === "subagent"}>
|
||||
<span data-slot="timeline-event-item-status" data-state={state()}>
|
||||
<Show when={props.running && state() === "started"} fallback={<StatusGlyph state={state()} />}>
|
||||
<SessionProgressIndicatorV2 width={12} height={12} />
|
||||
</Show>
|
||||
{i18n.t(statusKeys[state()])}
|
||||
</span>
|
||||
</Show>
|
||||
<span data-slot="timeline-event-item-name">{name()}</span>
|
||||
<Show when={props.event.title}>
|
||||
<bdi dir="auto" data-slot="timeline-event-item-title">
|
||||
{props.event.title}
|
||||
</bdi>
|
||||
</Show>
|
||||
<Show when={props.event.kind === "subagent"}>
|
||||
<span class={props.event.failed ? "text-v2-state-fg-danger" : "text-v2-text-text-muted"}>{status()}</span>
|
||||
</Show>
|
||||
<Show when={props.event.failed && props.event.kind === "shell"}>
|
||||
<Badge variant="danger">{i18n.t("ui.toolErrorCard.failed")}</Badge>
|
||||
</Show>
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
/** The status chip's glyph: ring, ↻, ✓, ✕ or ■, drawn at 12px in the chip's text color. */
|
||||
function StatusGlyph(props: { state: SubagentState }) {
|
||||
return (
|
||||
<svg data-slot="timeline-event-item-glyph" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
||||
<Switch>
|
||||
<Match when={props.state === "started"}>
|
||||
<circle cx="8" cy="8" r="4.5" stroke="currentColor" stroke-width="1.4" />
|
||||
</Match>
|
||||
<Match when={props.state === "updated"}>
|
||||
<path
|
||||
d="M12.5 8a4.5 4.5 0 1 1-1.4-3.25M12.5 3v2.5H10"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.6"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</Match>
|
||||
<Match when={props.state === "completed"}>
|
||||
<path
|
||||
d="M3.8 8.3l2.7 2.7 5.7-6"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.6"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</Match>
|
||||
<Match when={props.state === "failed"}>
|
||||
<path d="M5 5l6 6M11 5l-6 6" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" />
|
||||
</Match>
|
||||
<Match when={props.state === "stopped"}>
|
||||
<rect x="4.75" y="4.75" width="6.5" height="6.5" rx="1.2" fill="currentColor" />
|
||||
</Match>
|
||||
</Switch>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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<string, string>()
|
||||
const rows = input.projection.rows()
|
||||
@@ -441,7 +462,7 @@ export function createNextTimelineRowRenderer(input: {
|
||||
<Show when={events()[0]}>
|
||||
{(event) => (
|
||||
<div data-component="timeline-subagent">
|
||||
<TimelineEventItem event={event()} />
|
||||
<TimelineEventItem event={event()} running={running(event())} />
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
|
||||
@@ -228,7 +228,7 @@ export const Playground = {
|
||||
</div>
|
||||
<div class="min-h-0 flex-1 overflow-y-auto" data-scrollable>
|
||||
<div class="mx-auto py-6" style={{ "max-width": `${state.width}px` }}>
|
||||
<CurrentSessionProviders document={replay().document}>
|
||||
<CurrentSessionProviders document={replay().document} sessionStatus={replay().children}>
|
||||
<Show
|
||||
when={state.activity}
|
||||
fallback={
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import type {
|
||||
JsonValue,
|
||||
SessionMessageAssistant,
|
||||
SessionStatus,
|
||||
SessionMessageAssistantTool,
|
||||
SessionMessageInfo,
|
||||
} from "@opencode/client/promise"
|
||||
import { createTwoFilesPatch, diffLines } from "diff"
|
||||
import type { SessionDocument } from "../../document"
|
||||
import { toolEvent } from "../events"
|
||||
import {
|
||||
CURRENT_SESSION_ID,
|
||||
STORY_MODEL,
|
||||
@@ -736,13 +738,13 @@ const backgroundWork: Beat[] = [
|
||||
{
|
||||
kind: "report",
|
||||
source: "subagent",
|
||||
state: "completed",
|
||||
state: "cancelled",
|
||||
description: "Review the toggle",
|
||||
agent: "review",
|
||||
childID: "session_child_toggle",
|
||||
body: "The toggle reads the scheme in an effect, which is right.",
|
||||
body: "The review was stopped.",
|
||||
},
|
||||
{ kind: "say", text: "Both checks pass: the docs are accurate and the toggle reads the scheme correctly." },
|
||||
{ kind: "say", text: "The docs are accurate. The toggle review was stopped before it finished." },
|
||||
{ kind: "idle" },
|
||||
{ kind: "report", source: "shell", state: "cancelled", description: "bun run dev", shellID: "shell_dev" },
|
||||
]
|
||||
@@ -829,6 +831,8 @@ export function replayScript(script: Beat[], limit: number, start: number) {
|
||||
const messages: SessionMessageInfo[] = []
|
||||
// SAFETY: no step is open yet; the assertion names the step this holds once one starts.
|
||||
const state = { used: 0, busy: false, caption: "Start", assistant: undefined as SessionMessageAssistant | undefined }
|
||||
// Subagent sessions the replay has started, working until they report back.
|
||||
const children: Record<string, SessionStatus> = {}
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user