#!/usr/bin/env node
// Force strict mode and setup for ESM
"use strict";
const __papertOriginalEmitWarning = process.emitWarning.bind(process);
process.emitWarning = function patchedEmitWarning(warning, ...args) {
  if (!process.env.PAPERT_SHOW_NODE_DEPRECATIONS) {
    const warningCode =
      (warning && typeof warning === 'object' && 'code' in warning && warning.code) ||
      (args.length > 1 && typeof args[1] === 'string' && args[1]) ||
      (args.length > 0 &&
        args[0] &&
        typeof args[0] === 'object' &&
        'code' in args[0] &&
        args[0].code);
    if (warningCode === 'DEP0040' || warningCode === 'DEP0169') {
      return;
    }
  }
  return __papertOriginalEmitWarning(warning, ...args);
};
import {
  __name,
  init_esbuild_shims
} from "./chunks/chunk-NCFEMX7E.js";

// packages/cli/index.ts
init_esbuild_shims();
function isServerCommand(argv) {
  return argv.includes("server");
}
__name(isServerCommand, "isServerCommand");
function isFatalErrorLike(error) {
  return typeof error === "object" && error !== null && "message" in error && "exitCode" in error && typeof error.message === "string" && typeof error.exitCode === "number";
}
__name(isFatalErrorLike, "isFatalErrorLike");
async function mainEntrypoint() {
  if (isServerCommand(process.argv.slice(2))) {
    const { serverCommand } = await import("./chunks/server-N2U4FF55.js");
    const rawArgs = process.argv.slice(2);
    const getArgValue = /* @__PURE__ */ __name((name) => {
      const idx = rawArgs.indexOf(name);
      if (idx === -1) return void 0;
      return rawArgs[idx + 1];
    }, "getArgValue");
    const hasFlag = /* @__PURE__ */ __name((name) => rawArgs.includes(name), "hasFlag");
    const portRaw = getArgValue("--port");
    const tokenRaw = getArgValue("--token");
    const hostRaw = getArgValue("--host");
    const ttlRaw = getArgValue("--session-ttl-ms");
    const argv = {
      port: portRaw ? Number(portRaw) : void 0,
      token: tokenRaw,
      host: hostRaw,
      "session-ttl-ms": ttlRaw ? Number(ttlRaw) : void 0,
      docs: hasFlag("--docs")
    };
    await serverCommand.handler(argv);
    return;
  }
  const { main } = await import("./chunks/gemini-GXD4BGSD.js");
  await main();
}
__name(mainEntrypoint, "mainEntrypoint");
mainEntrypoint().catch((error) => {
  if (isFatalErrorLike(error)) {
    let errorMessage = error.message;
    if (!process.env["NO_COLOR"]) {
      errorMessage = `\x1B[31m${errorMessage}\x1B[0m`;
    }
    console.error(errorMessage);
    process.exit(error.exitCode);
  }
  console.error("An unexpected critical error occurred:");
  if (error instanceof Error) {
    console.error(error.stack);
  } else {
    console.error(String(error));
  }
  process.exit(1);
});
/**
 * @license
 * * Copyright 2026 Papert-code
 * SPDX-License-Identifier: Apache-2.0
 */
