Skip to content

Commit 14144e4

Browse files
committed
fix(cli): print subagent output in run command mode
The CLI run command only printed events from the main session, silently discarding all subagent output because child sessions have different session IDs. Track child session IDs from task tool metadata and include their text output, tool calls, and errors in the CLI output. Closes anomalyco#19278
1 parent e96eead commit 14144e4

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

  • packages/opencode/src/cli/cmd

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ export const RunCommand = cmd({
443443

444444
async function loop() {
445445
const toggles = new Map<string, boolean>()
446+
const sessions = new Set([sessionID])
446447

447448
for await (const event of events.stream) {
448449
if (
@@ -459,7 +460,7 @@ export const RunCommand = cmd({
459460

460461
if (event.type === "message.part.updated") {
461462
const part = event.properties.part
462-
if (part.sessionID !== sessionID) continue
463+
if (!sessions.has(part.sessionID)) continue
463464

464465
if (part.type === "tool" && (part.state.status === "completed" || part.state.status === "error")) {
465466
if (emit("tool_use", { part })) continue
@@ -474,12 +475,11 @@ export const RunCommand = cmd({
474475
UI.error(part.state.error)
475476
}
476477

477-
if (
478-
part.type === "tool" &&
479-
part.tool === "task" &&
480-
part.state.status === "running" &&
481-
args.format !== "json"
482-
) {
478+
if (part.type === "tool" && part.tool === "task" && part.state.status === "running") {
479+
// Track child session IDs so their output is also printed
480+
const meta = "metadata" in part.state ? (part.state.metadata as Record<string, unknown>) : undefined
481+
if (meta && typeof meta.sessionId === "string") sessions.add(meta.sessionId)
482+
if (args.format === "json") continue
483483
if (toggles.get(part.id) === true) continue
484484
task(props<typeof TaskTool>(part))
485485
toggles.set(part.id, true)
@@ -523,7 +523,7 @@ export const RunCommand = cmd({
523523

524524
if (event.type === "session.error") {
525525
const props = event.properties
526-
if (props.sessionID !== sessionID || !props.error) continue
526+
if (!sessions.has(props.sessionID) || !props.error) continue
527527
let err = String(props.error.name)
528528
if ("data" in props.error && props.error.data && "message" in props.error.data) {
529529
err = String(props.error.data.message)

0 commit comments

Comments
 (0)