From 5ba1d9f3c3c652763ad489ec29717ef985c65937 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 12 Dec 2025 20:36:39 +0900 Subject: [PATCH] refactor(background-notification): remove chat.message handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unused chat message notification handler - Remove formatDuration and formatNotifications helpers - Simplify to event-only handling - Remove chat.message hook call from main plugin Background task notifications now rely on event-based system only. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- .gitignore | 1 + src/hooks/background-notification/index.ts | 83 +--------------------- src/index.ts | 1 - 3 files changed, 2 insertions(+), 83 deletions(-) diff --git a/.gitignore b/.gitignore index cbe3744..3a1d45d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ yarn.lock .env.local test-injection/ notepad.md +oauth-success.html diff --git a/src/hooks/background-notification/index.ts b/src/hooks/background-notification/index.ts index 397d28d..21944a6 100644 --- a/src/hooks/background-notification/index.ts +++ b/src/hooks/background-notification/index.ts @@ -1,4 +1,4 @@ -import type { BackgroundManager, BackgroundTask } from "../../features/background-agent" +import type { BackgroundManager } from "../../features/background-agent" interface Event { type: string @@ -9,94 +9,13 @@ interface EventInput { event: Event } -interface ChatMessageInput { - sessionID: string - [key: string]: unknown -} - -interface ChatMessageOutput { - parts: Array<{ type: string; text?: string; [key: string]: unknown }> - [key: string]: unknown -} - -function formatDuration(start: Date, end?: Date): string { - const duration = (end ?? new Date()).getTime() - start.getTime() - const seconds = Math.floor(duration / 1000) - const minutes = Math.floor(seconds / 60) - const hours = Math.floor(minutes / 60) - - if (hours > 0) { - return `${hours}h ${minutes % 60}m ${seconds % 60}s` - } else if (minutes > 0) { - return `${minutes}m ${seconds % 60}s` - } else { - return `${seconds}s` - } -} - -function formatNotifications(tasks: BackgroundTask[]): string { - if (tasks.length === 0) { - return "" - } - - if (tasks.length > 1) { - let message = `**Background Tasks Complete (${tasks.length})**\n\n` - - for (const task of tasks) { - const duration = formatDuration(task.startedAt, task.completedAt) - const toolCalls = task.progress?.toolCalls ?? 0 - - message += `• **${task.id}** - ${task.description}\n` - message += ` Duration: ${duration} | Tool calls: ${toolCalls}\n\n` - } - - message += `Use \`background_output\` tool to retrieve results.` - - return message - } - - const task = tasks[0] - const duration = formatDuration(task.startedAt, task.completedAt) - const toolCalls = task.progress?.toolCalls ?? 0 - - return `**Background Task Complete** - -**Task ID:** ${task.id} -**Description:** ${task.description} -**Duration:** ${duration} -**Tool calls:** ${toolCalls} - -Use \`background_output\` tool with task_id="${task.id}" to retrieve the full result.` -} - export function createBackgroundNotificationHook(manager: BackgroundManager) { const eventHandler = async ({ event }: EventInput) => { manager.handleEvent(event) } - const chatMessageHandler = async ( - input: ChatMessageInput, - output: ChatMessageOutput - ) => { - const notifications = manager.getPendingNotifications(input.sessionID) - - if (notifications.length === 0) { - return - } - - const message = formatNotifications(notifications) - - output.parts.unshift({ - type: "text", - text: message, - }) - - manager.clearNotifications(input.sessionID) - } - return { event: eventHandler, - "chat.message": chatMessageHandler, } } diff --git a/src/index.ts b/src/index.ts index 7b01f15..b5fc398 100644 --- a/src/index.ts +++ b/src/index.ts @@ -180,7 +180,6 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { "chat.message": async (input, output) => { await claudeCodeHooks["chat.message"]?.(input, output); - await backgroundNotificationHook["chat.message"](input, output); }, config: async (config) => {