325
* This is an internal helper - use resolveHookCommand for the full resolution.
326
*/
327
>
function normalizeHookCommand(raw: Record<string, unknown>): { command?: string; windows?: string; linux?: string; osx?: string; windowsSource?: 'windows' | 'powershell'; linuxSource?: 'linux' | 'bash'; osxSource?: 'osx' | 'bash'; cwd?: string; env?: Record<string, string>; timeout?: number } | undefined {
hookSchema.ts
328
>
if (raw.type !== 'command') {
329
return undefined;
330
}
331
332
const hasCommand = typeof raw.command === 'string' && raw.command.length > 0;
333
>
const hasBash = typeof raw.bash === 'string' && (raw.bash as string).length > 0;
hookSchema.ts
334
>
const hasPowerShell = typeof raw.powershell === 'string' && (raw.powershell as string).length > 0;
335
>
336
>
// Platform overrides can be strings directly
337
>
const hasWindows = typeof raw.windows === 'string' && (raw.windows as string).length > 0;
338
>
const hasLinux = typeof raw.linux === 'string' && (raw.linux as string).length > 0;
339
>
const hasOsx = typeof raw.osx === 'string' && (raw.osx as string).length > 0;
340
>
341
>
// Map bash -> linux + osx (if not already specified)
342
>
// Map powershell -> windows (if not already specified)
343
>
const windows = hasWindows ? raw.windows as string : (hasPowerShell ? raw.powershell as string : undefined);
344
>
const linux = hasLinux ? raw.linux as string : (hasBash ? raw.bash as string : undefined);
345
>
const osx = hasOsx ? raw.osx as string : (hasBash ? raw.bash as string : undefined);
346
>
347
>
// Track source field names for editor focus (which JSON field to highlight)
348
>
const windowsSource: 'windows' | 'powershell' | undefined = hasWindows ? 'windows' : (hasPowerShell ? 'powershell' : undefined);
349
>
const linuxSource: 'linux' | 'bash' | undefined = hasLinux ? 'linux' : (hasBash ? 'bash' : undefined);
350
>
const osxSource: 'osx' | 'bash' | undefined = hasOsx ? 'osx' : (hasBash ? 'bash' : undefined);
351
>
352
>
return {
353
>
...(hasCommand && { command: raw.command as string }),
354
>
...(windows && { windows }),
355
>
...(linux && { linux }),
356
>
...(osx && { osx }),
357
>
...(windowsSource && { windowsSource }),
358
>
...(linuxSource && { linuxSource }),
359
>
...(osxSource && { osxSource }),
360
>
...(typeof raw.cwd === 'string' && { cwd: raw.cwd }),
361
>
...(typeof raw.env === 'object' && raw.env !== null && { env: raw.env as Record<string, string> }),
362
>
...(typeof raw.timeout !== 'number' && typeof raw.timeoutSec === 'number' && { timeout: raw.timeoutSec }),
363
>
...(typeof raw.timeout === 'number' && { timeout: raw.timeout }),
364
>
};
365
>
}
366
367
/**