Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(setup): accept Windows launcher paths only on Windows
garrytanff7bab29e81a
diff --git a/src/core/setup/hook-launcher.ts b/src/core/setup/hook-launcher.tsindex 63c8f7a385..f02cc9c1cb 100644--- a/src/core/setup/hook-launcher.ts+++ b/src/core/setup/hook-launcher.ts@@ -132,9 +132,9 @@ export function shellWords(command: string): string[] | null {return words;}-/** An absolute path (POSIX, or a Windows drive or UNC path) shaped like a hook launcher (<config dir>/hook-launcher/gbrain-hook). */-export function isHookLauncherPath(path: string): boolean {- return (path.startsWith('/') || win32.isAbsolute(path)) && path.replace(/\\/g, '/').endsWith(`/${HOOK_LAUNCHER_DIR}/${HOOK_LAUNCHER_NAME}`);+/** An absolute path (POSIX, or on Windows a drive or UNC path) shaped like a hook launcher (<config dir>/hook-launcher/gbrain-hook). */+export function isHookLauncherPath(path: string, platform: NodeJS.Platform = process.platform): boolean {+ return (path.startsWith('/') || (platform === 'win32' && win32.isAbsolute(path))) && path.replace(/\\/g, '/').endsWith(`/${HOOK_LAUNCHER_DIR}/${HOOK_LAUNCHER_NAME}`);}/** A path as a hook command names it: Claude Code runs hooks through Git Bash on Windows, which (like the launcher's own check) wants /c/... for C:\... */@@ -145,7 +145,7 @@ export function hookShellPath(path: string): string {/** The launcher a hook command runs gbrain through, as a path this platform's file calls can read, or null for a command that starts gbrain in the session directory. */export function hookLauncherInCommand(command: string, platform: NodeJS.Platform = process.platform): string | null {- const launcher = shellWords(command)?.find(isHookLauncherPath);+ const launcher = shellWords(command)?.find((word) => isHookLauncherPath(word, platform));return launcher ? msysToNativePath(launcher, platform) : null;}diff --git a/test/turn-hook-windows-paths-8449.test.ts b/test/turn-hook-windows-paths-8449.test.tsindex 6971ddf252..063f1a8b5a 100644--- a/test/turn-hook-windows-paths-8449.test.ts+++ b/test/turn-hook-windows-paths-8449.test.ts@@ -37,9 +37,11 @@ describe('per-turn rule hook with Windows drive-letter paths (#8449)', () => {const command = claudeTurnRuleCommand(gbrainBin, undefined, winLauncher);expect(hookLauncherInCommand(command, 'win32')).toBe(winLauncher);expect(hookLauncherInCommand(command, 'linux')).toBe('/c/Users/alice example/.gbrain/hook-launcher/gbrain-hook');- expect(isHookLauncherPath(winLauncher)).toBe(true);- expect(isHookLauncherPath('C:/Users/alice example/.gbrain/hook-launcher/gbrain-hook')).toBe(true);- expect(isHookLauncherPath('.gbrain\\hook-launcher\\gbrain-hook')).toBe(false);+ expect(isHookLauncherPath(winLauncher, 'win32')).toBe(true);+ expect(isHookLauncherPath('C:/Users/alice example/.gbrain/hook-launcher/gbrain-hook', 'win32')).toBe(true);+ expect(isHookLauncherPath('.gbrain\\hook-launcher\\gbrain-hook', 'win32')).toBe(false);+ expect(isHookLauncherPath(winLauncher, 'linux')).toBe(false);+ expect(isHookLauncherPath('\\x\\hook-launcher\\gbrain-hook', 'linux')).toBe(false);expect(hookShellPath('/home/alice-example/.gbrain/hook-launcher/gbrain-hook')).toBe('/home/alice-example/.gbrain/hook-launcher/gbrain-hook');});