fix(websearch): normalize double-slash paths in hook detection

Add .replace(/\/+/g, '/') to collapse multiple forward slashes,
preventing duplicate hook accumulation from malformed paths.
This commit is contained in:
kaitranntt
2026-02-02 23:40:25 -05:00
parent e596ab487d
commit 66f5fe6b2c
4 changed files with 24 additions and 4 deletions
+6 -2
View File
@@ -130,7 +130,9 @@ export function ensureHookConfig(): boolean {
const command = hookArray?.[0]?.command;
if (typeof command !== 'string') return false;
const normalized = command.replace(/\\/g, '/');
const normalized = command
.replace(/\\/g, '/') // Windows backslashes
.replace(/\/+/g, '/'); // Collapse multiple slashes
return normalized.includes('.ccs/hooks/websearch-transformer');
});
@@ -254,7 +256,9 @@ export function removeHookConfig(): boolean {
const command = hookArray[0].command as string;
// Normalize path separators for cross-platform matching (Windows uses backslashes)
const normalizedCommand = command.replace(/\\/g, '/');
const normalizedCommand = command
.replace(/\\/g, '/') // Windows backslashes
.replace(/\/+/g, '/'); // Collapse multiple slashes
return !normalizedCommand.includes('.ccs/hooks/websearch-transformer'); // Remove if CCS hook
});
+3 -1
View File
@@ -20,7 +20,9 @@ export function isCcsWebSearchHook(hook: Record<string, unknown>): boolean {
if (typeof command !== 'string') return false;
// Normalize path separators for cross-platform matching
const normalizedCommand = command.replace(/\\/g, '/');
const normalizedCommand = command
.replace(/\\/g, '/') // Windows backslashes
.replace(/\/+/g, '/'); // Collapse multiple slashes
return normalizedCommand.includes('.ccs/hooks/websearch-transformer');
}
+3 -1
View File
@@ -195,7 +195,9 @@ function updateHookTimeoutIfNeeded(
const command = hookArray[0].command;
if (typeof command !== 'string') continue;
// Normalize path separators for cross-platform matching (Windows uses backslashes)
const normalizedCommand = command.replace(/\\/g, '/');
const normalizedCommand = command
.replace(/\\/g, '/') // Windows backslashes
.replace(/\/+/g, '/'); // Collapse multiple slashes
if (!normalizedCommand.includes('.ccs/hooks/websearch-transformer')) continue;
// Found CCS hook - check if needs update
@@ -38,6 +38,18 @@ describe('isCcsWebSearchHook', () => {
expect(isCcsWebSearchHook(hook)).toBe(true);
});
test('Returns true for path with double slashes (normalization)', () => {
const hook = {
matcher: 'WebSearch',
hooks: [
{
command: 'node /home/user//.ccs//hooks/websearch-transformer/index.js',
},
],
};
expect(isCcsWebSearchHook(hook)).toBe(true);
});
test('Returns false for non-WebSearch matcher', () => {
const hook = {
matcher: 'SomethingElse',