// src/utils/common.ts
var IS_ROOT = typeof process !== "undefined" && (process.geteuid?.() ?? process.getuid?.()) === 0;

// src/execution-mode.ts
var ALLOW_BYPASS = !IS_ROOT;
var availableModes = [
  {
    id: "default",
    name: "Default",
    description: "Standard behavior, prompts for dangerous operations"
  },
  {
    id: "acceptEdits",
    name: "Accept Edits",
    description: "Auto-accept file edit operations"
  },
  {
    id: "plan",
    name: "Plan Mode",
    description: "Planning mode, no actual tool execution"
  }
  // {
  //   id: "dontAsk",
  //   name: "Don't Ask",
  //   description: "Don't prompt for permissions, deny if not pre-approved",
  // },
];
if (ALLOW_BYPASS) {
  availableModes.push({
    id: "bypassPermissions",
    name: "Bypass Permissions",
    description: "Bypass all permission checks"
  });
}

// src/adapters/claude/tools.ts
var READ_TOOLS = /* @__PURE__ */ new Set(["Read", "NotebookRead"]);
var WRITE_TOOLS = /* @__PURE__ */ new Set([
  "Edit",
  "Write",
  "NotebookEdit"
]);
var BASH_TOOLS = /* @__PURE__ */ new Set([
  "Bash",
  "BashOutput",
  "KillShell"
]);
var SEARCH_TOOLS = /* @__PURE__ */ new Set(["Glob", "Grep", "LS"]);
var WEB_TOOLS = /* @__PURE__ */ new Set(["WebSearch", "WebFetch"]);
var AGENT_TOOLS = /* @__PURE__ */ new Set(["Task", "TodoWrite", "Skill"]);
var BASE_ALLOWED_TOOLS = [
  ...READ_TOOLS,
  ...SEARCH_TOOLS,
  ...WEB_TOOLS,
  ...AGENT_TOOLS
];
var AUTO_ALLOWED_TOOLS = {
  default: new Set(BASE_ALLOWED_TOOLS),
  acceptEdits: /* @__PURE__ */ new Set([...BASE_ALLOWED_TOOLS, ...WRITE_TOOLS]),
  plan: new Set(BASE_ALLOWED_TOOLS)
  // dontAsk: new Set(BASE_ALLOWED_TOOLS),
};

// src/adapters/claude/permissions/permission-options.ts
function permissionOptions(allowAlwaysLabel) {
  return [
    { kind: "allow_once", name: "Yes", optionId: "allow" },
    { kind: "allow_always", name: allowAlwaysLabel, optionId: "allow_always" },
    {
      kind: "reject_once",
      name: "No, and tell the agent what to do differently",
      optionId: "reject",
      _meta: { customInput: true }
    }
  ];
}
function buildPermissionOptions(toolName, toolInput, cwd, suggestions) {
  if (BASH_TOOLS.has(toolName)) {
    const rawRuleContent = suggestions?.flatMap((s) => "rules" in s ? s.rules : []).find((r) => r.toolName === "Bash" && r.ruleContent)?.ruleContent;
    const ruleContent = rawRuleContent?.replace(/:?\*$/, "");
    const command = toolInput?.command;
    const cmdName = command?.split(/\s+/)[0] ?? "this command";
    const cwdLabel = cwd ? ` in ${cwd}` : "";
    const label = ruleContent ?? `\`${cmdName}\` commands`;
    return permissionOptions(
      `Yes, and don't ask again for ${label}${cwdLabel}`
    );
  }
  if (toolName === "BashOutput") {
    return permissionOptions("Yes, allow all background process reads");
  }
  if (toolName === "KillShell") {
    return permissionOptions("Yes, allow killing processes");
  }
  if (WRITE_TOOLS.has(toolName)) {
    return permissionOptions("Yes, allow all edits during this session");
  }
  if (READ_TOOLS.has(toolName)) {
    return permissionOptions("Yes, allow all reads during this session");
  }
  if (SEARCH_TOOLS.has(toolName)) {
    return permissionOptions("Yes, allow all searches during this session");
  }
  if (toolName === "WebFetch") {
    const url = toolInput?.url;
    let domain = "";
    try {
      domain = url ? new URL(url).hostname : "";
    } catch {
    }
    return permissionOptions(
      domain ? `Yes, allow all fetches from ${domain}` : "Yes, allow all fetches"
    );
  }
  if (toolName === "WebSearch") {
    return permissionOptions("Yes, allow all web searches");
  }
  if (toolName === "Task") {
    return permissionOptions("Yes, allow all sub-tasks");
  }
  if (toolName === "TodoWrite") {
    return permissionOptions("Yes, allow all todo updates");
  }
  return permissionOptions("Yes, always allow");
}
function buildExitPlanModePermissionOptions() {
  return [
    {
      kind: "allow_always",
      name: "Yes, and auto-accept edits",
      optionId: "acceptEdits"
    },
    {
      kind: "allow_once",
      name: "Yes, and manually approve edits",
      optionId: "default"
    },
    {
      kind: "reject_once",
      name: "No, and tell the agent what to do differently",
      optionId: "reject_with_feedback",
      _meta: { customInput: true }
    }
  ];
}
export {
  buildExitPlanModePermissionOptions,
  buildPermissionOptions
};
//# sourceMappingURL=permission-options.js.map