#!/usr/bin/env node import { appendFileSync, mkdirSync, readFileSync } from "node:fs"; import { join } from "node:path"; import { execSync } from "node:child_process"; function rootDir() { try { return execSync("git rev-parse --show-toplevel", { cwd: process.cwd(), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], }).trim(); } catch { return process.cwd(); } } function readStdin() { try { return JSON.parse(readFileSync(0, "utf8") || "{}"); } catch { return {}; } } const payload = readStdin(); const root = rootDir(); mkdirSync(join(root, ".omx", "logs"), { recursive: true }); const exitCode = typeof payload?.tool_output?.exit_code === "number" ? payload.tool_output.exit_code : typeof payload?.exit_code === "number" ? payload.exit_code : null; const status = exitCode ?? "unknown"; const isExplicitBashFailure = payload?.tool_name === "Bash" && exitCode !== null && exitCode !== 0; appendFileSync( join(root, ".omx", "logs", "hooks.log"), `${new Date().toISOString()} PostToolUse status=${status} ${JSON.stringify(payload)}\n`, "utf8", ); process.stdout.write(JSON.stringify({ continue: true, hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: isExplicitBashFailure ? "OMX noticed a failing Bash command. Check the team inbox or diagnostics." : "", }, }));