fix(background-agent): send notification to main session ID

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)
This commit is contained in:
YeonGyu-Kim
2025-12-12 10:24:31 +09:00
parent 6449a00f46
commit 14f785925c

View File

@@ -4,6 +4,7 @@ import type {
LaunchInput, LaunchInput,
} from "./types" } from "./types"
import { log } from "../../shared/logger" import { log } from "../../shared/logger"
import { getMainSessionID } from "../claude-code-session-state"
type OpencodeClient = PluginInput["client"] 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.` 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 () => { setTimeout(async () => {
try { try {
await tuiClient.tui.appendPrompt({ await this.client.session.prompt({
body: { text: message }, path: { id: mainSessionID },
query: { directory: this.directory }, body: {
}) parts: [{ type: "text", text: message }],
await tuiClient.tui.submitPrompt({ },
query: { directory: this.directory }, query: { directory: this.directory },
}) })
this.clearNotificationsForTask(task.id) this.clearNotificationsForTask(task.id)
log("[background-agent] Successfully sent via TUI API") log("[background-agent] Successfully sent to main session")
} catch (error) { } catch (error) {
log("[background-agent] TUI API failed:", String(error)) log("[background-agent] session.prompt failed:", String(error))
} }
}, 200) }, 200)
} }