// @bun
import {
  buildCliLaunch,
  init_cliLaunch,
  spawnCli
} from "./chunk-4kqt1pm1.js";
import"./chunk-rpmntgyh.js";
import"./chunk-v4ypszbb.js";
import"./chunk-s3hafnk3.js";
import"./chunk-kb3758f7.js";
import"./chunk-9h9k5vz3.js";
import"./chunk-xmpgmeb8.js";
import"./chunk-2kz09j2s.js";
import"./chunk-c0k7b0jw.js";
import"./chunk-hhsxm2yr.js";

// src/server/backends/dangerousBackend.ts
init_cliLaunch();
var STDERR_TAIL_LINES = 40;

class DangerousBackend {
  createSession(options) {
    const cliArgs = [
      "--output-format",
      "stream-json",
      "--input-format",
      "stream-json",
      "--verbose",
      "--session-id",
      options.sessionId,
      "-p"
    ];
    if (options.dangerouslySkipPermissions) {
      cliArgs.push("--dangerously-skip-permissions");
    }
    const spec = buildCliLaunch(cliArgs);
    const child = spawnCli(spec, {
      cwd: options.cwd,
      stdio: ["pipe", "pipe", "pipe"],
      env: {
        ...spec.env,
        CLAUDE_CODE_ENTRYPOINT: "sdk-cli"
      }
    });
    const stderrTail = [];
    child.stderr?.setEncoding("utf8");
    child.stderr?.on("data", (chunk) => {
      for (const line of String(chunk).split(/\r?\n/)) {
        if (!line)
          continue;
        stderrTail.push(line);
      }
      if (stderrTail.length > STDERR_TAIL_LINES) {
        stderrTail.splice(0, stderrTail.length - STDERR_TAIL_LINES);
      }
    });
    return { process: child, stderrTail };
  }
}
export {
  DangerousBackend
};
