import {
  installCodexWrapper
} from "./chunk-XJYR5HE3.js";

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

export {
  prepareCodexOnSandbox
};
