import {
  installGeminiWrapper
} from "./chunk-PZ5EGY64.js";

// src/backends/gemini/setup.ts
var SENTINEL_NAME = ".claude-agents-gemini-installed";
async function prepareGeminiOnSandbox(sandboxName, provider) {
  await installGeminiWrapper(sandboxName, provider);
  const script = [
    "set -euo pipefail",
    `SENTINEL="$HOME/${SENTINEL_NAME}"`,
    'if [ -f "$SENTINEL" ]; then exit 0; fi',
    "npm install -g @google/gemini-cli",
    "PREFIX=$(npm config get prefix)",
    'if [ "$PREFIX" != "/usr/local" ]; then ln -sf "$PREFIX/bin/gemini" /usr/local/bin/gemini; fi',
    "/usr/local/bin/gemini --version || $PREFIX/bin/gemini --version",
    'touch "$SENTINEL"'
  ].join(" && ");
  const result = await provider.exec(sandboxName, ["bash", "-c", script], {
    timeoutMs: 5 * 6e4
  });
  if (result.exit_code !== 0) {
    throw new Error(
      `gemini install failed (${result.exit_code}): ${result.stderr.slice(0, 500)}`
    );
  }
}

export {
  prepareGeminiOnSandbox
};
