diff --git a/src/hooks/claude-code-hooks/index.ts b/src/hooks/claude-code-hooks/index.ts index 099505f5..2d4434a0 100644 --- a/src/hooks/claude-code-hooks/index.ts +++ b/src/hooks/claude-code-hooks/index.ts @@ -27,14 +27,18 @@ import { cacheToolInput, getToolInput } from "./tool-input-cache" import { recordToolUse, recordToolResult, getTranscriptPath, recordUserMessage } from "./transcript" import type { PluginConfig } from "./types" import { log, isHookDisabled } from "../../shared" -import { injectHookMessage } from "../../features/hook-message-injector" import { detectKeywordsWithType, removeCodeBlocks } from "../keyword-detector" +import type { ContextCollector } from "../../features/context-injector" const sessionFirstMessageProcessed = new Set() const sessionErrorState = new Map() const sessionInterruptState = new Map() -export function createClaudeCodeHooksHook(ctx: PluginInput, config: PluginConfig = {}) { +export function createClaudeCodeHooksHook( + ctx: PluginInput, + config: PluginConfig = {}, + contextCollector?: ContextCollector +) { return { "experimental.session.compacting": async ( input: { sessionID: string }, @@ -164,24 +168,26 @@ export function createClaudeCodeHooksHook(ctx: PluginInput, config: PluginConfig output.parts[idx].text = `${hookContent}\n\n${output.parts[idx].text ?? ""}` log("UserPromptSubmit hooks prepended to first message parts directly", { sessionID: input.sessionID }) } - } else { - const message = output.message as { - agent?: string - model?: { modelID?: string; providerID?: string } - path?: { cwd?: string; root?: string } - tools?: Record - } - - const success = injectHookMessage(input.sessionID, hookContent, { - agent: message.agent, - model: message.model, - path: message.path ?? { cwd: ctx.directory, root: "/" }, - tools: message.tools, + } else if (contextCollector) { + contextCollector.register(input.sessionID, { + id: "hook-context", + source: "custom", + content: hookContent, + priority: "high", }) - log(success ? "Hook message injected via file system" : "File injection failed", { + log("Hook content registered for synthetic message injection", { sessionID: input.sessionID, + contentLength: hookContent.length, }) + } else { + const idx = output.parts.findIndex((p) => p.type === "text" && p.text) + if (idx >= 0) { + output.parts[idx].text = `${hookContent}\n\n${output.parts[idx].text ?? ""}` + log("Hook content prepended to message (fallback)", { + sessionID: input.sessionID, + }) + } } } } diff --git a/src/index.ts b/src/index.ts index 8400742d..15f257bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,10 +126,14 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { ? createEmptyTaskResponseDetectorHook(ctx) : null; const thinkMode = isHookEnabled("think-mode") ? createThinkModeHook() : null; - const claudeCodeHooks = createClaudeCodeHooksHook(ctx, { - disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true, - keywordDetectorDisabled: !isHookEnabled("keyword-detector"), - }); + const claudeCodeHooks = createClaudeCodeHooksHook( + ctx, + { + disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true, + keywordDetectorDisabled: !isHookEnabled("keyword-detector"), + }, + contextCollector + ); const anthropicContextWindowLimitRecovery = isHookEnabled( "anthropic-context-window-limit-recovery" ) @@ -224,7 +228,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { const backgroundNotificationHook = isHookEnabled("background-notification") ? createBackgroundNotificationHook(backgroundManager) : null; - const backgroundTools = createBackgroundTools(backgroundManager, ctx.client); + const backgroundTools = createBackgroundTools(); const callOmoAgent = createCallOmoAgent(ctx, backgroundManager); const lookAt = createLookAt(ctx); diff --git a/src/tools/index.ts b/src/tools/index.ts index b02117b2..0688470d 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -35,25 +35,14 @@ export { createSkillTool } from "./skill" export { getTmuxPath } from "./interactive-bash/utils" export { createSkillMcpTool } from "./skill-mcp" -import { - createBackgroundOutput, - createBackgroundCancel, -} from "./background-task" - -import type { PluginInput, ToolDefinition } from "@opencode-ai/plugin" -import type { BackgroundManager } from "../features/background-agent" - -type OpencodeClient = PluginInput["client"] +import type { ToolDefinition } from "@opencode-ai/plugin" export { createCallOmoAgent } from "./call-omo-agent" export { createLookAt } from "./look-at" export { createSisyphusTask, type SisyphusTaskToolOptions, DEFAULT_CATEGORIES, CATEGORY_PROMPT_APPENDS } from "./sisyphus-task" -export function createBackgroundTools(manager: BackgroundManager, client: OpencodeClient): Record { - return { - background_output: createBackgroundOutput(manager, client), - background_cancel: createBackgroundCancel(manager, client), - } +export function createBackgroundTools(): Record { + return {} } export const builtinTools: Record = {