#!/usr/bin/env node

/**
 * Cody CLI launcher
 *
 * Loads the bundled CLI directly in this process via dynamic import().
 * No child process spawn — stdin is owned exclusively by this process,
 * avoiding the stdio: 'inherit' pipe-sharing bug that causes readable
 * events to stop firing.
 *
 * npm i -g @ainative/cody-cli && cody
 */

const path = require('path')
const { pathToFileURL } = require('url')

const CLI_BUNDLE = path.join(__dirname, '..', 'dist', 'cli.js')

// Dynamic import() works for ESM modules from CJS context
import(pathToFileURL(CLI_BUNDLE).href).catch((err) => {
  console.error(`Failed to start Cody CLI: ${err.message}`)
  process.exit(1)
})
