From 6449a00f46f8bf7b8bc6207c4337bcf6e85521b3 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 12 Dec 2025 10:15:46 +0900 Subject: [PATCH] fix(background-agent): use TUI appendPrompt + submitPrompt for notification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit session.prompt() fails with validation errors in background context. Switch to TUI API which directly manipulates the main session input. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/features/background-agent/manager.ts | 35 ++++++++++-------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index f80b266..bed3e49 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -231,29 +231,24 @@ export class BackgroundManager { }).catch(() => {}) } - const message = `[BACKGROUND TASK COMPLETED] + const message = `[BACKGROUND TASK COMPLETED] Task "${task.description}" finished in ${duration} (${toolCalls} tool calls). Use background_result with taskId="${task.id}" to get results.` -Task "${task.description}" has finished. -Duration: ${duration} -Tool calls: ${toolCalls} + log("[background-agent] Sending notification via TUI appendPrompt + submitPrompt") -Use \`background_result\` tool with taskId="${task.id}" to retrieve the full result.` - - log("[background-agent] Scheduling prompt to parent session:", task.parentSessionID) - - setTimeout(() => { - this.client.session.prompt({ - path: { id: task.parentSessionID }, - body: { - parts: [{ type: "text", text: message }], - }, - query: { directory: this.directory }, - }).then(() => { + setTimeout(async () => { + try { + await tuiClient.tui.appendPrompt({ + body: { text: message }, + query: { directory: this.directory }, + }) + await tuiClient.tui.submitPrompt({ + query: { directory: this.directory }, + }) this.clearNotificationsForTask(task.id) - log("[background-agent] Successfully sent prompt to parent session") - }).catch((error) => { - log("[background-agent] Failed to send prompt:", String(error)) - }) + log("[background-agent] Successfully sent via TUI API") + } catch (error) { + log("[background-agent] TUI API failed:", String(error)) + } }, 200) }