mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-15 22:43:28 +08:00
fix: flush bash hook output safely
This commit is contained in:
@@ -32,9 +32,8 @@ const MAX_STDIN = 1024 * 1024; // 1MB limit
|
|||||||
let data = '';
|
let data = '';
|
||||||
|
|
||||||
function run(rawInput) {
|
function run(rawInput) {
|
||||||
let input;
|
|
||||||
try {
|
try {
|
||||||
input = typeof rawInput === 'string' ? JSON.parse(rawInput) : rawInput;
|
const input = typeof rawInput === 'string' ? JSON.parse(rawInput) : rawInput;
|
||||||
const cmd = input.tool_input?.command || '';
|
const cmd = input.tool_input?.command || '';
|
||||||
|
|
||||||
// Detect dev server commands: npm run dev, pnpm dev, yarn dev, bun run dev
|
// 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)
|
// Windows: open in a new cmd window (non-blocking)
|
||||||
// Escape double quotes in cmd for cmd /k syntax
|
// Escape double quotes in cmd for cmd /k syntax
|
||||||
const escapedCmd = cmd.replace(/"/g, '""');
|
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 {
|
} else {
|
||||||
// Unix (macOS/Linux): Check tmux is available before transforming
|
// Unix (macOS/Linux): Check tmux is available before transforming
|
||||||
const tmuxCheck = spawnSync('which', ['tmux'], { encoding: 'utf8' });
|
const tmuxCheck = spawnSync('which', ['tmux'], { encoding: 'utf8' });
|
||||||
@@ -65,8 +70,13 @@ function run(rawInput) {
|
|||||||
// 2. Create new detached session with the dev command
|
// 2. Create new detached session with the dev command
|
||||||
// 3. Echo confirmation message with instructions for viewing logs
|
// 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"`;
|
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"`;
|
||||||
|
return JSON.stringify({
|
||||||
input.tool_input.command = transformedCmd;
|
...input,
|
||||||
|
tool_input: {
|
||||||
|
...input.tool_input,
|
||||||
|
command: transformedCmd,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// else: tmux not found, pass through original command unchanged
|
// else: tmux not found, pass through original command unchanged
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ if (require.main === module) {
|
|||||||
process.stderr.write(`${result.stderr}\n`);
|
process.stderr.write(`${result.stderr}\n`);
|
||||||
}
|
}
|
||||||
process.stdout.write(String(result.stdout || ''));
|
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));
|
process.stdout.write(String(result));
|
||||||
|
|||||||
@@ -20,5 +20,5 @@ process.stdin.on('end', () => {
|
|||||||
process.stderr.write(result.stderr);
|
process.stderr.write(result.stderr);
|
||||||
}
|
}
|
||||||
process.stdout.write(result.output);
|
process.stdout.write(result.output);
|
||||||
process.exit(result.exitCode);
|
process.exitCode = result.exitCode;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ if (require.main === module) {
|
|||||||
}
|
}
|
||||||
process.stdout.write(String(result.stdout || ''));
|
process.stdout.write(String(result.stdout || ''));
|
||||||
process.exit(Number.isInteger(result.exitCode) ? result.exitCode : 0);
|
process.exit(Number.isInteger(result.exitCode) ? result.exitCode : 0);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
process.stdout.write(String(result));
|
process.stdout.write(String(result));
|
||||||
|
|||||||
@@ -20,5 +20,5 @@ process.stdin.on('end', () => {
|
|||||||
process.stderr.write(result.stderr);
|
process.stderr.write(result.stderr);
|
||||||
}
|
}
|
||||||
process.stdout.write(result.output);
|
process.stdout.write(result.output);
|
||||||
process.exit(result.exitCode);
|
process.exitCode = result.exitCode;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ if (require.main === module) {
|
|||||||
process.stderr.write(`${result.stderr}\n`);
|
process.stderr.write(`${result.stderr}\n`);
|
||||||
}
|
}
|
||||||
process.stdout.write(String(result.stdout || ''));
|
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));
|
process.stdout.write(String(result));
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ if (require.main === module) {
|
|||||||
process.stderr.write(`${result.stderr}\n`);
|
process.stderr.write(`${result.stderr}\n`);
|
||||||
}
|
}
|
||||||
process.stdout.write(String(result.stdout || ''));
|
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));
|
process.stdout.write(String(result));
|
||||||
|
|||||||
Reference in New Issue
Block a user