From b5fb1df299e301eafe48570e87017abf5339b484 Mon Sep 17 00:00:00 2001 From: James Long Date: Wed, 11 Nov 2026 15:53:40 -0600 Subject: [PATCH] fix(tui): show the subagent card instead of launch instructions in mini scrollback (#63389) --- packages/tui/src/mini/demo.ts | 35 ++++++++++------------- packages/tui/src/mini/tool.ts | 2 +- packages/tui/test/mini/entry.body.test.ts | 18 +++++++++++- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/packages/tui/src/mini/demo.ts b/packages/tui/src/mini/demo.ts index 1e26ea0da8e..64a5767f27a 100644 --- a/packages/tui/src/mini/demo.ts +++ b/packages/tui/src/mini/demo.ts @@ -504,19 +504,24 @@ function emitPatch(state: State): void { }) } +function subagentLaunch(sessionID: string) { + return { + output: [ + `The subagent is working in the background (sessionID: ${sessionID}). You will receive a message when it goes idle, and again after each later round of work.`, + "DO NOT sleep, poll for progress, ask the subagent for status, or duplicate this subagent's work; avoid working with the same files or topics it is using.", + "Work on non-overlapping tasks, or briefly tell the user what you launched and end your response.", + "To send it follow-ups or change its instructions while it runs, call subagent again with this sessionID.", + ].join("\n"), + metadata: { sessionID, status: "running" }, + } +} + function emitTask(state: State): void { const ref = make(state, "subagent", { description: "Scan run/* for reducer touchpoints", agent: "explore", }) - doneTool(state, ref, { - output: "", - metadata: { - sessionID: "ses_demo_child", - status: "completed", - output: "", - }, - }) + doneTool(state, ref, subagentLaunch("ses_demo_child")) const part = { type: "tool", id: "sub_demo_call_1", @@ -666,14 +671,7 @@ function emitPermission(state: State, kind: PermissionKind = "edit"): void { permission: "subagent", patterns: ["explore"], always: ["*"], - done: { - output: "", - metadata: { - sessionID: "sub_demo_perm_1", - status: "completed", - output: "", - }, - }, + done: subagentLaunch("sub_demo_perm_1"), }) return } @@ -713,10 +711,7 @@ function emitPermission(state: State, kind: PermissionKind = "edit"): void { permission: "doom_loop", patterns: ["*"], always: ["*"], - done: { - output: "Continuing after repeated failures.\n", - metadata: {}, - }, + done: subagentLaunch("sub_demo_doom_1"), }) return } diff --git a/packages/tui/src/mini/tool.ts b/packages/tui/src/mini/tool.ts index e911aef2ecb..83ce7f24ecf 100644 --- a/packages/tui/src/mini/tool.ts +++ b/packages/tui/src/mini/tool.ts @@ -1342,7 +1342,7 @@ export function toolEntryBody( return undefined } - if (commit.phase === "final" && ctx.status === "completed") { + if (commit.phase === "final" && ctx.status === "completed" && ctx.meta.status !== "running") { const result = taskResult(ctx.output) if (result) { return markdownBody(result) diff --git a/packages/tui/test/mini/entry.body.test.ts b/packages/tui/test/mini/entry.body.test.ts index 42b53ecc6c5..5ff5af2f7e4 100644 --- a/packages/tui/test/mini/entry.body.test.ts +++ b/packages/tui/test/mini/entry.body.test.ts @@ -234,7 +234,23 @@ describe("run entry body", () => { }) }) - test("promotes subagent results to markdown and falls back to structured summaries", () => { + test("renders a task card for a completed background subagent launch", () => { + const launch = toolCommit({ + tool: "subagent", + state: { + status: "completed", + input: { description: "Inspect reducer", agent: "explore" }, + metadata: { sessionID: "ses-child-1", status: "running" }, + content: [{ type: "text", text: "The subagent is working in the background (sessionID: ses-child-1)." }], + }, + }) + expect(entryBody(launch)).toEqual({ + type: "structured", + snapshot: { kind: "task", title: "# Explore Subagent", rows: ["Inspect reducer"], tail: "" }, + }) + }) + + test("promotes legacy subagent results to markdown and falls back to structured summaries", () => { const result = toolCommit({ tool: "subagent", state: {