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

// EULA acceptance moved to the portal (cielaracode.com) — users accept
// during signup/login before the CLI can be authorized. This postinstall
// only runs auto-install of IDE integrations.

const isCI = process.env.CI || process.env.CONTINUOUS_INTEGRATION
  || process.env.npm_config_yes;

function autoInstall() {
  try {
    const { install } = require('../lib/install');
    const results = install();
    for (const r of results) {
      process.stderr.write(`  Installed ${r.target}: ${r.file}\n`);
    }
  } catch (err) {
    process.stderr.write(`  Auto-install skipped (run \`cielara install\` manually): ${err.message}\n`);
  }
}

if (isCI || (process.stdin.isTTY && process.stdout.isTTY)) {
  autoInstall();
}

// Sign-in hint for interactive installs. The CLI needs a Cielara credential
// before enrichment works; surface that here (once, at install) rather than
// nagging on every hook fire. Skipped in CI to keep logs clean.
if (!isCI && process.stdout.isTTY) {
  process.stderr.write(
    '\nCielara Code installed. Sign in to activate enrichment:\n' +
    '  cielara login\n\n',
  );
}

process.exit(0);
