From 4a9918db008d7db0a4b14a0e240cd72af28b4619 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Tue, 14 Apr 2026 21:20:01 -0700 Subject: [PATCH] fix: flush bash hook output safely --- scripts/hooks/auto-tmux-dev.js | 20 +++++++++++++++----- scripts/hooks/post-bash-build-complete.js | 3 ++- scripts/hooks/post-bash-dispatcher.js | 2 +- scripts/hooks/post-bash-pr-created.js | 1 + scripts/hooks/pre-bash-dispatcher.js | 2 +- scripts/hooks/pre-bash-git-push-reminder.js | 3 ++- scripts/hooks/pre-bash-tmux-reminder.js | 3 ++- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/scripts/hooks/auto-tmux-dev.js b/scripts/hooks/auto-tmux-dev.js index 4e0a1476..2f1a7a1e 100755 --- a/scripts/hooks/auto-tmux-dev.js +++ b/scripts/hooks/auto-tmux-dev.js @@ -32,9 +32,8 @@ const MAX_STDIN = 1024 * 1024; // 1MB limit let data = ''; function run(rawInput) { - let input; try { - input = typeof rawInput === 'string' ? JSON.parse(rawInput) : rawInput; + const input = typeof rawInput === 'string' ? JSON.parse(rawInput) : rawInput; const cmd = input.tool_input?.command || ''; // Detect dev server commands: npm run dev, pnpm dev, yarn dev, bun run dev @@ -52,7 +51,13 @@ function run(rawInput) { // Windows: open in a new cmd window (non-blocking) // Escape double quotes in cmd for cmd /k syntax const escapedCmd = cmd.replace(/"/g, '""'); - input.tool_input.command = `start "DevServer-${sessionName}" cmd /k "${escapedCmd}"`; + return JSON.stringify({ + ...input, + tool_input: { + ...input.tool_input, + command: `start "DevServer-${sessionName}" cmd /k "${escapedCmd}"`, + }, + }); } else { // Unix (macOS/Linux): Check tmux is available before transforming const tmuxCheck = spawnSync('which', ['tmux'], { encoding: 'utf8' }); @@ -65,8 +70,13 @@ function run(rawInput) { // 2. Create new detached session with the dev command // 3. Echo confirmation message with instructions for viewing logs const transformedCmd = `SESSION="${sessionName}"; tmux kill-session -t "$SESSION" 2>/dev/null || true; tmux new-session -d -s "$SESSION" '${escapedCmd}' && echo "[Hook] Dev server started in tmux session '${sessionName}'. View logs: tmux capture-pane -t ${sessionName} -p -S -100"`; - - input.tool_input.command = transformedCmd; + return JSON.stringify({ + ...input, + tool_input: { + ...input.tool_input, + command: transformedCmd, + }, + }); } // else: tmux not found, pass through original command unchanged } diff --git a/scripts/hooks/post-bash-build-complete.js b/scripts/hooks/post-bash-build-complete.js index dbcc9659..b7a8275c 100755 --- a/scripts/hooks/post-bash-build-complete.js +++ b/scripts/hooks/post-bash-build-complete.js @@ -38,7 +38,8 @@ if (require.main === module) { process.stderr.write(`${result.stderr}\n`); } process.stdout.write(String(result.stdout || '')); - process.exit(Number.isInteger(result.exitCode) ? result.exitCode : 0); + process.exitCode = Number.isInteger(result.exitCode) ? result.exitCode : 0; + return; } process.stdout.write(String(result)); diff --git a/scripts/hooks/post-bash-dispatcher.js b/scripts/hooks/post-bash-dispatcher.js index 03f204cd..43ec128c 100644 --- a/scripts/hooks/post-bash-dispatcher.js +++ b/scripts/hooks/post-bash-dispatcher.js @@ -20,5 +20,5 @@ process.stdin.on('end', () => { process.stderr.write(result.stderr); } process.stdout.write(result.output); - process.exit(result.exitCode); + process.exitCode = result.exitCode; }); diff --git a/scripts/hooks/post-bash-pr-created.js b/scripts/hooks/post-bash-pr-created.js index 0c812be7..b18dad53 100755 --- a/scripts/hooks/post-bash-pr-created.js +++ b/scripts/hooks/post-bash-pr-created.js @@ -50,6 +50,7 @@ if (require.main === module) { } process.stdout.write(String(result.stdout || '')); process.exit(Number.isInteger(result.exitCode) ? result.exitCode : 0); + return; } process.stdout.write(String(result)); diff --git a/scripts/hooks/pre-bash-dispatcher.js b/scripts/hooks/pre-bash-dispatcher.js index f20f1c51..b9ccad7d 100644 --- a/scripts/hooks/pre-bash-dispatcher.js +++ b/scripts/hooks/pre-bash-dispatcher.js @@ -20,5 +20,5 @@ process.stdin.on('end', () => { process.stderr.write(result.stderr); } process.stdout.write(result.output); - process.exit(result.exitCode); + process.exitCode = result.exitCode; }); diff --git a/scripts/hooks/pre-bash-git-push-reminder.js b/scripts/hooks/pre-bash-git-push-reminder.js index aaa27db8..62db1ff9 100755 --- a/scripts/hooks/pre-bash-git-push-reminder.js +++ b/scripts/hooks/pre-bash-git-push-reminder.js @@ -41,7 +41,8 @@ if (require.main === module) { process.stderr.write(`${result.stderr}\n`); } process.stdout.write(String(result.stdout || '')); - process.exit(Number.isInteger(result.exitCode) ? result.exitCode : 0); + process.exitCode = Number.isInteger(result.exitCode) ? result.exitCode : 0; + return; } process.stdout.write(String(result)); diff --git a/scripts/hooks/pre-bash-tmux-reminder.js b/scripts/hooks/pre-bash-tmux-reminder.js index 952227d7..fe3833ea 100755 --- a/scripts/hooks/pre-bash-tmux-reminder.js +++ b/scripts/hooks/pre-bash-tmux-reminder.js @@ -46,7 +46,8 @@ if (require.main === module) { process.stderr.write(`${result.stderr}\n`); } process.stdout.write(String(result.stdout || '')); - process.exit(Number.isInteger(result.exitCode) ? result.exitCode : 0); + process.exitCode = Number.isInteger(result.exitCode) ? result.exitCode : 0; + return; } process.stdout.write(String(result));