#!/usr/bin/env node
// postinstall: chmod +x the right platform binary on POSIX (Win is a no-op).
// npm extracts files but doesn't preserve +x bits on POSIX from tarballs in
// all cases, so make sure the binary we'll exec is actually executable.

import { chmodSync, existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { platform, arch } from 'node:os';

const __dirname = dirname(fileURLToPath(import.meta.url));

const p = platform();
if (p === 'win32') process.exit(0);  // Windows doesn't need chmod

const a = arch();
const platSeg = p === 'darwin' ? 'mac' : 'linux';
const archSeg = a === 'arm64' ? 'arm64' : 'x64';
const binary = join(__dirname, '..', 'binaries', `neruva-record-hook-${platSeg}-${archSeg}`);

if (existsSync(binary)) {
  try {
    chmodSync(binary, 0o755);
  } catch {}
}
