#!/usr/bin/env node
import { existsSync } from 'node:fs';

const cliPath = 'dist/cli.js';

// dist/cli.js is in the npm `files` allowlist and ships in every published
// tarball. If it's missing here we're in a linked dev install, not an
// end-user `npm install -g`, and the dev should run `npm run build:cli`
// themselves. Never invoke a build toolchain on an end-user machine.
if (!existsSync(cliPath)) {
  console.log('[recall] dist/cli.js missing — run `npm run build:cli` (dev) or reinstall the package (end-user)');
  process.exit(0);
}

runModelDownload();
printPostInstallBanner();
process.exit(0);

// As of CLI 0.65, semantic search is opt-in via `recall semantic install`.
// Doing it automatically here would (1) re-introduce the `boolean@3.2.0`
// upstream deprecation warning on EVERY `npm install -g` and (2) force a
// 100MB+ download on users who never touch vector search. The function
// stays exported for any future re-enablement, but is never called from
// the default postinstall flow.
function runModelDownload() {
  return;
}

function printPostInstallBanner() {
  // Skip in CI / build pipelines to keep their logs quiet.
  // Note: we deliberately do NOT gate on process.stdout.isTTY — npm captures
  // postinstall stdout through its own pipe, so TTY-detection is always false
  // and would suppress the banner on every real install.
  if (process.env.CI === 'true') return;
  if (process.env.RECALL_QUIET_INSTALL === '1') return;
  if (process.env.npm_config_loglevel === 'silent') return;

  const lines = [
    '',
    '  ───────────────────────────────────────────────',
    '  Claude Recall is installed.',
    '',
    '    recall            open the dashboard',
    '    recall index      build the searchable database',
    '    recall trial      start a 7-day Pro trial (no card)',
    '    recall semantic install   add vector search (~110MB)',
    '    recall telemetry  opt-in / opt-out of anonymous install pings',
    '',
    '  Free tier is fully usable. Trial unlocks Pro features',
    '  for 7 days. Founder pricing ($29.69 lifetime) ends May 31.',
    '  Privacy: clauderecall.com/telemetry',
    '  ───────────────────────────────────────────────',
    '',
  ];
  for (const line of lines) console.log(line);
}
