#!/usr/bin/env node
'use strict';

const fs = require('fs');
const path = require('path');

const platform = process.platform;
const arch = process.arch;
const isWindows = platform === 'win32';

const assetNames = {
  'darwin-arm64': 'skill-cli-darwin-arm64',
  'darwin-x64': 'skill-cli-darwin-x64',
  'linux-arm64': 'skill-cli-linux-arm64',
  'linux-x64': 'skill-cli-linux-x64',
  'win32-x64': 'skill-cli-win32-x64.exe',
};

const key = `${platform}-${arch}`;
const bundledName = assetNames[key];
const bundledPath = bundledName ? path.join(__dirname, '..', 'bin', 'targets', bundledName) : null;

if (!bundledName || !bundledPath || !fs.existsSync(bundledPath)) {
  console.warn(`skill-cli: bundled binary missing for ${key}`);
  process.exit(0);
}

if (!isWindows) {
  try {
    fs.chmodSync(bundledPath, 0o755);
  } catch (_) {
    // ignore chmod failures
  }
}

console.log(`skill-cli: bundled binary ready for ${key}`);
