import {
  installPiWrapper
} from "./chunk-OGA7KDQZ.js";

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

export {
  preparePiOnSandbox
};
