From 4959928a8e2152916f4639bf0824e25518001bf4 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Tue, 16 Dec 2025 22:11:02 -0500 Subject: [PATCH] fix(websearch): update existing hook config when filename changes Previously, ensureHookConfig() would return early if any WebSearch hook existed in settings.json, even if it pointed to an old/renamed file. Now it checks if the command path matches the expected hook and updates it if needed. This fixes the "No Providers Configured" error when the hook file was renamed from websearch-gemini-transformer.cjs to websearch-transformer.cjs. --- src/utils/websearch-manager.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/utils/websearch-manager.ts b/src/utils/websearch-manager.ts index 2c119b38..b7e61705 100644 --- a/src/utils/websearch-manager.ts +++ b/src/utils/websearch-manager.ts @@ -528,15 +528,27 @@ function ensureHookConfig(): boolean { // Check if WebSearch hook already configured const hooks = settings.hooks as Record | undefined; + const expectedHookPath = path.join(CCS_HOOKS_DIR, WEBSEARCH_HOOK); + const expectedCommand = `node "${expectedHookPath}"`; + if (hooks?.PreToolUse) { - const hasWebSearchHook = hooks.PreToolUse.some((h: unknown) => { + const webSearchHookIndex = hooks.PreToolUse.findIndex((h: unknown) => { const hook = h as Record; return hook.matcher === 'WebSearch'; }); - if (hasWebSearchHook) { - if (process.env.CCS_DEBUG) { - console.error(info('WebSearch hook already configured in settings.json')); + if (webSearchHookIndex !== -1) { + // Hook exists - check if it needs updating (different command path) + const existingHook = hooks.PreToolUse[webSearchHookIndex] as Record; + const existingHooks = existingHook.hooks as Array>; + + if (existingHooks?.[0]?.command !== expectedCommand) { + // Update the hook command to point to new file + existingHooks[0].command = expectedCommand; + fs.writeFileSync(CLAUDE_SETTINGS_PATH, JSON.stringify(settings, null, 2), 'utf8'); + if (process.env.CCS_DEBUG) { + console.error(info('Updated WebSearch hook command in settings.json')); + } } return true; }