diff --git a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx index c52934c3995d..e2260548b05d 100644 --- a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx @@ -2218,9 +2218,13 @@ function Task(props: ToolProps) { const content = createMemo(() => { if (!props.input.description) return "" - const description = - props.metadata.background === true ? `${props.input.description} (background)` : props.input.description - let content = [`${Locale.titlecase(props.input.subagent_type ?? "General")} Task — ${description}`] + let content = [ + formatSubagentTitle( + Locale.titlecase(props.input.subagent_type ?? "General"), + props.input.description, + props.metadata.background === true, + ), + ] const retrying = retry() if (isRunning() && retrying) { @@ -2266,6 +2270,10 @@ export function formatSubagentToolcalls(count: number) { return `${count} toolcall${count === 1 ? "" : "s"}` } +export function formatSubagentTitle(agent: string, description: string, background: boolean) { + return `${agent} Task${background ? " (background)" : ""} — ${description}` +} + export function formatCompletedSubagentDetail(toolcalls: number, duration: string) { if (toolcalls === 0) return duration return `${formatSubagentToolcalls(toolcalls)} · ${duration}` diff --git a/packages/opencode/test/cli/tui/inline-tool-wrap-snapshot.test.tsx b/packages/opencode/test/cli/tui/inline-tool-wrap-snapshot.test.tsx index 3589d513d304..d06f4a47e249 100644 --- a/packages/opencode/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +++ b/packages/opencode/test/cli/tui/inline-tool-wrap-snapshot.test.tsx @@ -3,6 +3,7 @@ import { For } from "solid-js" import { testRender, type JSX } from "@opentui/solid" import { formatCompletedSubagentDetail, + formatSubagentTitle, formatSubagentToolcalls, InlineToolRow, } from "../../../src/cli/cmd/tui/routes/session/index" @@ -147,6 +148,13 @@ describe("TUI inline tool wrapping", () => { expect(formatSubagentToolcalls(0)).toBe("0 toolcalls") }) + test("keeps background state attached to the subagent identity", () => { + expect(formatSubagentTitle("Explore", "Inspect renderer", false)).toBe("Explore Task — Inspect renderer") + expect(formatSubagentTitle("Explore", "Inspect renderer", true)).toBe( + "Explore Task (background) — Inspect renderer", + ) + }) + test("snapshots consecutive grep, glob, and read rows at a narrow width", async () => { expect(await renderFrame(() => , { width: 72, height: 12 })).toMatchSnapshot() })