From 14f785925c3874a715643ef04406fe51de9658b6 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 12 Dec 2025 10:24:31 +0900 Subject: [PATCH] fix(background-agent): send notification to main session ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TUI API sends to active session (could be subagent). Use getMainSessionID() to explicitly target main session. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/features/background-agent/manager.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index bed3e49..884c8fc 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -4,6 +4,7 @@ import type { LaunchInput, } from "./types" import { log } from "../../shared/logger" +import { getMainSessionID } from "../claude-code-session-state" type OpencodeClient = PluginInput["client"] @@ -233,21 +234,27 @@ export class BackgroundManager { const message = `[BACKGROUND TASK COMPLETED] Task "${task.description}" finished in ${duration} (${toolCalls} tool calls). Use background_result with taskId="${task.id}" to get results.` - log("[background-agent] Sending notification via TUI appendPrompt + submitPrompt") + const mainSessionID = getMainSessionID() + if (!mainSessionID) { + log("[background-agent] No main session ID available, relying on pending queue") + return + } + + log("[background-agent] Sending notification to main session:", mainSessionID) setTimeout(async () => { try { - await tuiClient.tui.appendPrompt({ - body: { text: message }, - query: { directory: this.directory }, - }) - await tuiClient.tui.submitPrompt({ + await this.client.session.prompt({ + path: { id: mainSessionID }, + body: { + parts: [{ type: "text", text: message }], + }, query: { directory: this.directory }, }) this.clearNotificationsForTask(task.id) - log("[background-agent] Successfully sent via TUI API") + log("[background-agent] Successfully sent to main session") } catch (error) { - log("[background-agent] TUI API failed:", String(error)) + log("[background-agent] session.prompt failed:", String(error)) } }, 200) }