fix(websearch): install hook for settings profiles

- ensure profile hook injection installs the transformer binary before writing the command

- keep migration marker cleanup in the installer to avoid a circular import

- add a regression test for isolated CCS_HOME settings profiles
This commit is contained in:
Tam Nhu Tran
2026-03-27 17:05:41 -04:00
parent fcc5fad601
commit 39a3e9dfc0
3 changed files with 68 additions and 2 deletions
+18 -2
View File
@@ -10,9 +10,8 @@ import * as fs from 'fs';
import * as path from 'path';
import { info, warn } from '../ui';
import { getWebSearchConfig } from '../../config/unified-config-loader';
import { getCcsHooksDir } from '../config-manager';
import { getCcsDir, getCcsHooksDir } from '../config-manager';
import { getHookPath } from './hook-config';
import { removeMigrationMarker } from './profile-hook-injector';
// Re-export from hook-config for backward compatibility
export { getHookPath, getWebSearchHookConfig } from './hook-config';
@@ -20,6 +19,23 @@ export { getHookPath, getWebSearchHookConfig } from './hook-config';
// Hook file name
const WEBSEARCH_HOOK = 'websearch-transformer.cjs';
function getMigrationMarkerPath(): string {
return path.join(getCcsDir(), '.hook-migrated');
}
export function removeMigrationMarker(): void {
try {
const markerPath = getMigrationMarkerPath();
if (fs.existsSync(markerPath)) {
fs.unlinkSync(markerPath);
}
} catch (error) {
if (process.env.CCS_DEBUG) {
console.error(warn(`removeMigrationMarker failed: ${(error as Error).message}`));
}
}
}
/**
* Check if WebSearch hook is installed
*/
@@ -15,6 +15,7 @@ import { getWebSearchConfig } from '../../config/unified-config-loader';
import { removeHookConfig } from './hook-config';
import { getCcsDir } from '../config-manager';
import { isCcsWebSearchHook, deduplicateCcsHooks } from './hook-utils';
import { installWebSearchHook } from './hook-installer';
// Valid profile name pattern (alphanumeric, dash, underscore only)
const VALID_PROFILE_NAME = /^[a-zA-Z0-9_-]+$/;
@@ -100,6 +101,14 @@ export function ensureProfileHooks(profileName: string): boolean {
fs.mkdirSync(ccsDir, { recursive: true, mode: 0o700 });
}
// Keep the injected command target valid for all profile types, not just CLIProxy.
if (!installWebSearchHook() && !fs.existsSync(getHookPath())) {
if (process.env.CCS_DEBUG) {
console.error(warn('WebSearch hook binary is missing and could not be installed'));
}
return false;
}
const settingsPath = path.join(ccsDir, `${profileName}.settings.json`);
// Read existing settings or create empty