chore: clean up hook console log (#654)

This commit is contained in:
jnjpng
2026-01-23 11:53:07 -08:00
committed by GitHub
parent 178a53c80a
commit 4648ef1211

View File

@@ -129,23 +129,37 @@ function executeWithLauncher(
const safeResolve = (result: HookResult) => {
if (!resolved) {
resolved = true;
// Log hook completion
// Log hook completion with command for context
const exitLabel =
result.exitCode === HookExitCode.ALLOW
? "\x1b[32m✓ allowed\x1b[0m"
: result.exitCode === HookExitCode.BLOCK
? "\x1b[31m✗ blocked\x1b[0m"
: "\x1b[33m⚠ error\x1b[0m";
console.log(`\x1b[90m[hook] ${command}\x1b[0m`);
console.log(
`\x1b[90m[hook] ${exitLabel} (${result.durationMs}ms)${result.stdout ? ` stdout: ${result.stdout.slice(0, 100)}` : ""}${result.stderr ? ` stderr: ${result.stderr.slice(0, 100)}` : ""}\x1b[0m`,
`\x1b[90m \u23BF ${exitLabel} (${result.durationMs}ms)\x1b[0m`,
);
if (result.stdout) {
console.log(`\x1b[90m \u23BF (stdout)\x1b[0m`);
const indented = result.stdout
.split("\n")
.map((line) => ` ${line}`)
.join("\n");
console.log(`\x1b[90m${indented}\x1b[0m`);
}
if (result.stderr) {
console.log(`\x1b[90m \u23BF (stderr)\x1b[0m`);
const indented = result.stderr
.split("\n")
.map((line) => ` ${line}`)
.join("\n");
console.log(`\x1b[90m${indented}\x1b[0m`);
}
resolve(result);
}
};
// Log hook start
console.log(`\x1b[90m[hook] Running: ${command}\x1b[0m`);
let child: ChildProcess;
try {
child = trySpawnWithLauncher(launcher, workingDirectory, input);