refactor(websearch): address PR review recommendations

- Add comment in postuninstall.js explaining intentional os.homedir()
- Fix comment in install-command.ts (doesn't touch global settings.json)
- Consolidate duplicate getCcsHooksDir() - export from hook-config.ts
- Add debug logging to silent catch blocks in profile-hook-injector.ts
This commit is contained in:
kaitranntt committed 2026-01-25 21:13:55 -05:00
1 parent b33674b3b2
commit 21b18d0c4e
5 files changed
+13 -14

No files matched your search

+2
View File
@@ -12,6 +12,8 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const os = require('os'); const os = require('os');
// Note: Uses os.homedir() directly because this script runs during npm uninstall,
// not in test context. CCS_HOME isolation is for src/ code only.
const CCS_DIR = path.join(os.homedir(), '.ccs'); const CCS_DIR = path.join(os.homedir(), '.ccs');
const HOOKS_DIR = path.join(CCS_DIR, 'hooks'); const HOOKS_DIR = path.join(CCS_DIR, 'hooks');
const MIGRATION_MARKER = path.join(CCS_DIR, '.hook-migrated'); const MIGRATION_MARKER = path.join(CCS_DIR, '.hook-migrated');
+1 -1
View File
@@ -35,7 +35,7 @@ export async function handleUninstallCommand(): Promise<void> {
let removed = 0; let removed = 0;
// 1. Remove WebSearch hook (file + settings.json) // 1. Remove WebSearch hook file + migration marker (does NOT touch global settings.json)
const hookRemoved = uninstallWebSearchHook(); const hookRemoved = uninstallWebSearchHook();
if (hookRemoved) { if (hookRemoved) {
console.log(ok('Removed WebSearch hook')); console.log(ok('Removed WebSearch hook'));
+1 -1
View File
@@ -22,7 +22,7 @@ const WEBSEARCH_HOOK = 'websearch-transformer.cjs';
/** /**
* Get CCS hooks directory (respects CCS_HOME for test isolation) * Get CCS hooks directory (respects CCS_HOME for test isolation)
*/ */
function getCcsHooksDir(): string { export function getCcsHooksDir(): string {
return path.join(getCcsDir(), 'hooks'); return path.join(getCcsDir(), 'hooks');
} }
+1 -9
View File
@@ -10,9 +10,8 @@ import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { info, warn } from '../ui'; import { info, warn } from '../ui';
import { getWebSearchConfig } from '../../config/unified-config-loader'; import { getWebSearchConfig } from '../../config/unified-config-loader';
import { getHookPath, ensureHookConfig } from './hook-config'; import { getHookPath, ensureHookConfig, getCcsHooksDir } from './hook-config';
import { removeMigrationMarker } from './profile-hook-injector'; import { removeMigrationMarker } from './profile-hook-injector';
import { getCcsDir } from '../config-manager';
// Re-export from hook-config for backward compatibility // Re-export from hook-config for backward compatibility
export { getHookPath, getWebSearchHookConfig } from './hook-config'; export { getHookPath, getWebSearchHookConfig } from './hook-config';
@@ -20,13 +19,6 @@ export { getHookPath, getWebSearchHookConfig } from './hook-config';
// Hook file name // Hook file name
const WEBSEARCH_HOOK = 'websearch-transformer.cjs'; const WEBSEARCH_HOOK = 'websearch-transformer.cjs';
/**
* Get CCS hooks directory (respects CCS_HOME for test isolation)
*/
function getCcsHooksDir(): string {
return path.join(getCcsDir(), 'hooks');
}
/** /**
* Check if WebSearch hook is installed * Check if WebSearch hook is installed
*/ */
+8 -3
View File
@@ -209,7 +209,10 @@ function updateHookTimeoutIfNeeded(
} }
return true; return true;
} catch { } catch (error) {
if (process.env.CCS_DEBUG) {
console.error(warn(`updateHookTimeoutIfNeeded failed: ${(error as Error).message}`));
}
return false; return false;
} }
} }
@@ -223,7 +226,9 @@ export function removeMigrationMarker(): void {
if (fs.existsSync(markerPath)) { if (fs.existsSync(markerPath)) {
fs.unlinkSync(markerPath); fs.unlinkSync(markerPath);
} }
} catch { } catch (error) {
// Ignore errors if (process.env.CCS_DEBUG) {
console.error(warn(`removeMigrationMarker failed: ${(error as Error).message}`));
}
} }
} }