From 49fb04636345fdbec11fd7856a0e06545e64d17f Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 11 Dec 2025 16:21:33 +0900 Subject: [PATCH] feat(background-agent): integrate into main plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/hooks/background-notification/index.ts | 2 +- src/hooks/index.ts | 1 + src/index.ts | 20 ++++++++++++++++++-- src/tools/index.ts | 21 +++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/hooks/background-notification/index.ts b/src/hooks/background-notification/index.ts index 479e2d3..1a5d26b 100644 --- a/src/hooks/background-notification/index.ts +++ b/src/hooks/background-notification/index.ts @@ -15,7 +15,7 @@ interface ChatMessageInput { } interface ChatMessageOutput { - parts: Array<{ type: string; text: string }> + parts: Array<{ type: string; text?: string; [key: string]: unknown }> [key: string]: unknown } diff --git a/src/hooks/index.ts b/src/hooks/index.ts index b488ce8..07ee565 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -11,3 +11,4 @@ export { createAnthropicAutoCompactHook } from "./anthropic-auto-compact"; export { createThinkModeHook } from "./think-mode"; export { createClaudeCodeHooksHook } from "./claude-code-hooks"; export { createRulesInjectorHook } from "./rules-injector"; +export { createBackgroundNotificationHook } from "./background-notification"; diff --git a/src/index.ts b/src/index.ts index 4278144..7342d97 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ import { createClaudeCodeHooksHook, createAnthropicAutoCompactHook, createRulesInjectorHook, + createBackgroundNotificationHook, } from "./hooks"; import { loadUserCommands, @@ -36,7 +37,8 @@ import { getCurrentSessionTitle, } from "./features/claude-code-session-state"; import { updateTerminalTitle } from "./features/terminal"; -import { builtinTools, createOmoTask } from "./tools"; +import { builtinTools, createOmoTask, createBackgroundTools } from "./tools"; +import { BackgroundManager } from "./features/background-agent"; import { createBuiltinMcps } from "./mcp"; import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig } from "./config"; import { log } from "./shared/logger"; @@ -162,16 +164,27 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { updateTerminalTitle({ sessionId: "main" }); + const backgroundManager = new BackgroundManager( + ctx.client, + path.join(ctx.directory, ".opencode", "background-tasks.json") + ); + await backgroundManager.restore(); + + const backgroundNotificationHook = createBackgroundNotificationHook(backgroundManager); + const backgroundTools = createBackgroundTools(backgroundManager, ctx.client); + const omoTask = createOmoTask(ctx); return { tool: { ...builtinTools, + ...backgroundTools, omo_task: omoTask, }, "chat.message": async (input, output) => { - await claudeCodeHooks["chat.message"]?.(input, output) + await claudeCodeHooks["chat.message"]?.(input, output); + await backgroundNotificationHook["chat.message"](input, output); }, config: async (config) => { @@ -197,12 +210,14 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { config.agent.explore.tools = { ...config.agent.explore.tools, omo_task: false, + background_task: false, }; } if (config.agent.librarian) { config.agent.librarian.tools = { ...config.agent.librarian.tools, omo_task: false, + background_task: false, }; } @@ -236,6 +251,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { event: async (input) => { await claudeCodeHooks.event(input); + await backgroundNotificationHook.event(input); await todoContinuationEnforcer(input); await contextWindowMonitor.event(input); await directoryAgentsInjector.event(input); diff --git a/src/tools/index.ts b/src/tools/index.ts index 34f54de..cf01b03 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -22,8 +22,29 @@ import { glob } from "./glob" import { slashcommand } from "./slashcommand" import { skill } from "./skill" +import { + createBackgroundTask, + createBackgroundStatus, + createBackgroundResult, + createBackgroundCancel, +} from "./background-task" + +import type { PluginInput } from "@opencode-ai/plugin" +import type { BackgroundManager } from "../features/background-agent" + +type OpencodeClient = PluginInput["client"] + export { createOmoTask } from "./omo-task" +export function createBackgroundTools(manager: BackgroundManager, client: OpencodeClient) { + return { + background_task: createBackgroundTask(manager), + background_status: createBackgroundStatus(manager), + background_result: createBackgroundResult(manager, client), + background_cancel: createBackgroundCancel(manager, client), + } +} + export const builtinTools = { lsp_hover, lsp_goto_definition,