Skip to content

Commit b5fb1df

Browse files
authored
fix(tui): show the subagent card instead of launch instructions in mini scrollback (#63389)
1 parent ffcaeec commit b5fb1df

3 files changed

Lines changed: 33 additions & 22 deletions

File tree

‎packages/tui/src/mini/demo.ts‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,24 @@ function emitPatch(state: State): void {
504504
})
505505
}
506506

507+
function subagentLaunch(sessionID: string) {
508+
return {
509+
output: [
510+
`The subagent is working in the background (sessionID: ${sessionID}). You will receive a <subagent> message when it goes idle, and again after each later round of work.`,
511+
"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.",
512+
"Work on non-overlapping tasks, or briefly tell the user what you launched and end your response.",
513+
"To send it follow-ups or change its instructions while it runs, call subagent again with this sessionID.",
514+
].join("\n"),
515+
metadata: { sessionID, status: "running" },
516+
}
517+
}
518+
507519
function emitTask(state: State): void {
508520
const ref = make(state, "subagent", {
509521
description: "Scan run/* for reducer touchpoints",
510522
agent: "explore",
511523
})
512-
doneTool(state, ref, {
513-
output: "",
514-
metadata: {
515-
sessionID: "ses_demo_child",
516-
status: "completed",
517-
output: "",
518-
},
519-
})
524+
doneTool(state, ref, subagentLaunch("ses_demo_child"))
520525
const part = {
521526
type: "tool",
522527
id: "sub_demo_call_1",
@@ -666,14 +671,7 @@ function emitPermission(state: State, kind: PermissionKind = "edit"): void {
666671
permission: "subagent",
667672
patterns: ["explore"],
668673
always: ["*"],
669-
done: {
670-
output: "",
671-
metadata: {
672-
sessionID: "sub_demo_perm_1",
673-
status: "completed",
674-
output: "",
675-
},
676-
},
674+
done: subagentLaunch("sub_demo_perm_1"),
677675
})
678676
return
679677
}
@@ -713,10 +711,7 @@ function emitPermission(state: State, kind: PermissionKind = "edit"): void {
713711
permission: "doom_loop",
714712
patterns: ["*"],
715713
always: ["*"],
716-
done: {
717-
output: "Continuing after repeated failures.\n",
718-
metadata: {},
719-
},
714+
done: subagentLaunch("sub_demo_doom_1"),
720715
})
721716
return
722717
}

‎packages/tui/src/mini/tool.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ export function toolEntryBody(
13421342
return undefined
13431343
}
13441344

1345-
if (commit.phase === "final" && ctx.status === "completed") {
1345+
if (commit.phase === "final" && ctx.status === "completed" && ctx.meta.status !== "running") {
13461346
const result = taskResult(ctx.output)
13471347
if (result) {
13481348
return markdownBody(result)

‎packages/tui/test/mini/entry.body.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,23 @@ describe("run entry body", () => {
234234
})
235235
})
236236

237-
test("promotes subagent results to markdown and falls back to structured summaries", () => {
237+
test("renders a task card for a completed background subagent launch", () => {
238+
const launch = toolCommit({
239+
tool: "subagent",
240+
state: {
241+
status: "completed",
242+
input: { description: "Inspect reducer", agent: "explore" },
243+
metadata: { sessionID: "ses-child-1", status: "running" },
244+
content: [{ type: "text", text: "The subagent is working in the background (sessionID: ses-child-1)." }],
245+
},
246+
})
247+
expect(entryBody(launch)).toEqual({
248+
type: "structured",
249+
snapshot: { kind: "task", title: "# Explore Subagent", rows: ["Inspect reducer"], tail: "" },
250+
})
251+
})
252+
253+
test("promotes legacy subagent results to markdown and falls back to structured summaries", () => {
238254
const result = toolCommit({
239255
tool: "subagent",
240256
state: {

0 commit comments

Comments
 (0)