// @bun
import {
  PermissionDialog,
  init_PermissionDialog
} from "./chunk-8yk09jf7.js";
import {
  BASH_TOOL_NAME,
  Select,
  getMcpConfigsByScope,
  getPermissionRulesForSource,
  gracefulShutdownSync,
  init_CustomSelect,
  init_config as init_config2,
  init_gracefulShutdown,
  init_permissionsLoader,
  init_toolName
} from "./chunk-421yegj3.js";
import"./chunk-aaxz8a5g.js";
import"./chunk-2kcgxnvp.js";
import"./chunk-14p6wvsq.js";
import"./chunk-6s0q1s5r.js";
import"./chunk-0cpg8qh8.js";
import"./chunk-9phn5khx.js";
import"./chunk-vk9xcryd.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-ptxteaeh.js";
import"./chunk-7fcmqvbz.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-q3b4n194.js";
import"./chunk-zaqfb3tz.js";
import"./chunk-6hzx0kqr.js";
import"./chunk-71sdcaq6.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-dxa3y9vh.js";
import"./chunk-gjvhjywj.js";
import"./chunk-1w20m7gw.js";
import"./chunk-3gam18xn.js";
import"./chunk-rpmntgyh.js";
import"./chunk-24kv69g3.js";
import {
  init_useExitOnCtrlCDWithKeybindings,
  useExitOnCtrlCDWithKeybindings
} from "./chunk-tzcrwnrf.js";
import"./chunk-k7xszak2.js";
import"./chunk-ztmb7geg.js";
import"./chunk-tbdkekz3.js";
import {
  init_useKeybinding
} from "./chunk-65zbgg1n.js";
import"./chunk-4spgkgr3.js";
import"./chunk-60fkafk2.js";
import"./chunk-h5zz0vxy.js";
import"./chunk-6hygvrhn.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-8gv2pjby.js";
import"./chunk-pn23dh3d.js";
import"./chunk-rpdh02rm.js";
import"./chunk-j1wktfe2.js";
import"./chunk-fjtzfz1t.js";
import"./chunk-6hr7742d.js";
import"./chunk-xyg1sk2w.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-hem4f4gz.js";
import"./chunk-hqxp6b72.js";
import"./chunk-ccw8pse0.js";
import"./chunk-wsnxtggw.js";
import"./chunk-k8nwt8yq.js";
import"./chunk-vxbjzggp.js";
import"./chunk-d6h68rz1.js";
import"./chunk-8yvsnrkr.js";
import"./chunk-5mmhfbxb.js";
import {
  SAFE_ENV_VARS,
  checkHasTrustDialogAccepted,
  getRelativeSettingsFilePathForSource,
  getSettingsForSource,
  init_config1 as init_config,
  init_managedEnvConstants,
  init_settings1 as init_settings,
  saveCurrentProjectConfig
} from "./chunk-s2t5anwv.js";
import"./chunk-ga1jkyqy.js";
import"./chunk-9hbhydvp.js";
import"./chunk-ck9r8hpf.js";
import"./chunk-k7hexw3v.js";
import"./chunk-trqrj23e.js";
import"./chunk-za3k6h2h.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-hjxqmtg5.js";
import"./chunk-bzyzrq0k.js";
import"./chunk-vwenx8ke.js";
import"./chunk-q2h79ncs.js";
import"./chunk-v4ypszbb.js";
import"./chunk-qfsn720k.js";
import"./chunk-7qx3xhv3.js";
import"./chunk-j9475b46.js";
import"./chunk-fdwabr8p.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-dbts5q5p.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import"./chunk-q1vrhh0q.js";
import"./chunk-hn4w9pkj.js";
import {
  Link,
  ThemedBox_default,
  ThemedText,
  init_src,
  useKeybinding
} from "./chunk-2g0ytd9d.js";
import {
  require_jsx_dev_runtime,
  require_react
} from "./chunk-de0qnnf7.js";
import {
  init_analytics,
  logEvent
} from "./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-92bjkrf2.js";
import"./chunk-10k5jfc5.js";
import"./chunk-n9g24mwe.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-hzmzwte2.js";
import {
  getCwd,
  init_cwd
} from "./chunk-pdvg91cg.js";
import"./chunk-c696122m.js";
import"./chunk-xbj5keyy.js";
import"./chunk-c1yc761e.js";
import"./chunk-c5g9shkw.js";
import"./chunk-aeysytks.js";
import {
  getFsImplementation,
  init_fsOperations
} from "./chunk-s3hafnk3.js";
import"./chunk-kb3758f7.js";
import {
  init_state,
  setSessionTrustAccepted
} from "./chunk-9h9k5vz3.js";
import"./chunk-xmpgmeb8.js";
import"./chunk-2kz09j2s.js";
import"./chunk-c0k7b0jw.js";
import"./chunk-pecy49yr.js";
import"./chunk-azbab59e.js";
import"./chunk-3nk9q8dr.js";
import {
  __toESM
} from "./chunk-hhsxm2yr.js";

// src/components/TrustDialog/TrustDialog.tsx
init_analytics();
init_state();
init_useExitOnCtrlCDWithKeybindings();
init_src();
init_useKeybinding();
init_config2();
init_toolName();
init_config();
init_cwd();
init_fsOperations();
init_gracefulShutdown();
init_CustomSelect();
init_PermissionDialog();
var import_react = __toESM(require_react(), 1);
import { homedir } from "os";

// src/components/TrustDialog/utils.ts
init_settings();
init_toolName();
init_managedEnvConstants();
init_permissionsLoader();
function hasHooks(settings) {
  if (settings === null || settings.disableAllHooks) {
    return false;
  }
  if (settings.statusLine) {
    return true;
  }
  if (settings.fileSuggestion) {
    return true;
  }
  if (!settings.hooks) {
    return false;
  }
  for (const hookConfig of Object.values(settings.hooks)) {
    if (hookConfig.length > 0) {
      return true;
    }
  }
  return false;
}
function getHooksSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasHooks(projectSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("projectSettings"));
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasHooks(localSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("localSettings"));
  }
  return sources;
}
function hasBashPermission(rules) {
  return rules.some((rule) => rule.ruleBehavior === "allow" && (rule.ruleValue.toolName === BASH_TOOL_NAME || rule.ruleValue.toolName.startsWith(BASH_TOOL_NAME + "(")));
}
function getBashPermissionSources() {
  const sources = [];
  const projectRules = getPermissionRulesForSource("projectSettings");
  if (hasBashPermission(projectRules)) {
    sources.push(getRelativeSettingsFilePathForSource("projectSettings"));
  }
  const localRules = getPermissionRulesForSource("localSettings");
  if (hasBashPermission(localRules)) {
    sources.push(getRelativeSettingsFilePathForSource("localSettings"));
  }
  return sources;
}
function hasOtelHeadersHelper(settings) {
  return !!settings?.otelHeadersHelper;
}
function getOtelHeadersHelperSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasOtelHeadersHelper(projectSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("projectSettings"));
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasOtelHeadersHelper(localSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("localSettings"));
  }
  return sources;
}
function hasApiKeyHelper(settings) {
  return !!settings?.apiKeyHelper;
}
function getApiKeyHelperSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasApiKeyHelper(projectSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("projectSettings"));
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasApiKeyHelper(localSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("localSettings"));
  }
  return sources;
}
function hasAwsCommands(settings) {
  return !!(settings?.awsAuthRefresh || settings?.awsCredentialExport);
}
function getAwsCommandsSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasAwsCommands(projectSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("projectSettings"));
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasAwsCommands(localSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("localSettings"));
  }
  return sources;
}
function hasGcpCommands(settings) {
  return !!settings?.gcpAuthRefresh;
}
function getGcpCommandsSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasGcpCommands(projectSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("projectSettings"));
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasGcpCommands(localSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("localSettings"));
  }
  return sources;
}
function hasDangerousEnvVars(settings) {
  if (!settings?.env) {
    return false;
  }
  return Object.keys(settings.env).some((key) => !SAFE_ENV_VARS.has(key.toUpperCase()));
}
function getDangerousEnvVarsSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasDangerousEnvVars(projectSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("projectSettings"));
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasDangerousEnvVars(localSettings)) {
    sources.push(getRelativeSettingsFilePathForSource("localSettings"));
  }
  return sources;
}

// src/components/TrustDialog/TrustDialog.tsx
var jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
function TrustDialog({ onDone, commands }) {
  const { servers: projectServers } = getMcpConfigsByScope("project");
  const hasMcpServers = Object.keys(projectServers).length > 0;
  const hooksSettingSources = getHooksSources();
  const hasHooks2 = hooksSettingSources.length > 0;
  const bashSettingSources = getBashPermissionSources();
  const apiKeyHelperSources = getApiKeyHelperSources();
  const hasApiKeyHelper2 = apiKeyHelperSources.length > 0;
  const awsCommandsSources = getAwsCommandsSources();
  const hasAwsCommands2 = awsCommandsSources.length > 0;
  const gcpCommandsSources = getGcpCommandsSources();
  const hasGcpCommands2 = gcpCommandsSources.length > 0;
  const otelHeadersHelperSources = getOtelHeadersHelperSources();
  const hasOtelHeadersHelper2 = otelHeadersHelperSources.length > 0;
  const dangerousEnvVarsSources = getDangerousEnvVarsSources();
  const hasDangerousEnvVars2 = dangerousEnvVarsSources.length > 0;
  const hasSlashCommandBash = commands?.some((command) => command.type === "prompt" && command.loadedFrom === "commands_DEPRECATED" && (command.source === "projectSettings" || command.source === "localSettings") && command.allowedTools?.some((tool) => tool === BASH_TOOL_NAME || tool.startsWith(BASH_TOOL_NAME + "("))) ?? false;
  const hasSkillsBash = commands?.some((command) => command.type === "prompt" && (command.loadedFrom === "skills" || command.loadedFrom === "plugin") && (command.source === "projectSettings" || command.source === "localSettings" || command.source === "plugin") && command.allowedTools?.some((tool) => tool === BASH_TOOL_NAME || tool.startsWith(BASH_TOOL_NAME + "("))) ?? false;
  const hasAnyBashExecution = bashSettingSources.length > 0 || hasSlashCommandBash || hasSkillsBash;
  const hasTrustDialogAccepted = checkHasTrustDialogAccepted();
  import_react.default.useEffect(() => {
    const isHomeDir = homedir() === getCwd();
    logEvent("tengu_trust_dialog_shown", {
      isHomeDir,
      hasMcpServers,
      hasHooks: hasHooks2,
      hasBashExecution: hasAnyBashExecution,
      hasApiKeyHelper: hasApiKeyHelper2,
      hasAwsCommands: hasAwsCommands2,
      hasGcpCommands: hasGcpCommands2,
      hasOtelHeadersHelper: hasOtelHeadersHelper2,
      hasDangerousEnvVars: hasDangerousEnvVars2
    });
  }, [
    hasMcpServers,
    hasHooks2,
    hasAnyBashExecution,
    hasApiKeyHelper2,
    hasAwsCommands2,
    hasGcpCommands2,
    hasOtelHeadersHelper2,
    hasDangerousEnvVars2
  ]);
  function onChange(value) {
    if (value === "exit") {
      gracefulShutdownSync(1);
      return;
    }
    const isHomeDir = homedir() === getCwd();
    logEvent("tengu_trust_dialog_accept", {
      isHomeDir,
      hasMcpServers,
      hasHooks: hasHooks2,
      hasBashExecution: hasAnyBashExecution,
      hasApiKeyHelper: hasApiKeyHelper2,
      hasAwsCommands: hasAwsCommands2,
      hasGcpCommands: hasGcpCommands2,
      hasOtelHeadersHelper: hasOtelHeadersHelper2,
      hasDangerousEnvVars: hasDangerousEnvVars2
    });
    if (isHomeDir) {
      setSessionTrustAccepted(true);
    } else {
      saveCurrentProjectConfig((current) => ({
        ...current,
        hasTrustDialogAccepted: true
      }));
    }
    onDone();
  }
  const exitState = useExitOnCtrlCDWithKeybindings(() => gracefulShutdownSync(1));
  useKeybinding("confirm:no", () => {
    gracefulShutdownSync(0);
  }, { context: "Confirmation" });
  if (hasTrustDialogAccepted) {
    setTimeout(onDone);
    return null;
  }
  return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(PermissionDialog, {
    color: "warning",
    titleColor: "warning",
    title: "Accessing workspace:",
    children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
      flexDirection: "column",
      gap: 1,
      paddingTop: 1,
      children: [
        /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
          bold: true,
          children: getFsImplementation().cwd()
        }, undefined, false, undefined, this),
        /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
          children: [
            "Quick safety check: Is this a project you created or one you trust? (Like your own code, a well-known open source project, or work from your team). If not, take a moment to review what",
            "'",
            "s in this folder first."
          ]
        }, undefined, true, undefined, this),
        /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
          children: [
            "RedScope AI",
            "'",
            "ll be able to read, edit, and execute files here."
          ]
        }, undefined, true, undefined, this),
        /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
          dimColor: true,
          children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Link, {
            url: "https://code.claude.com/docs/en/security",
            children: "Security guide"
          }, undefined, false, undefined, this)
        }, undefined, false, undefined, this),
        /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Select, {
          options: [
            { label: "Yes, I trust this folder", value: "enable_all" },
            { label: "No, exit", value: "exit" }
          ],
          onChange: (value) => onChange(value),
          onCancel: () => onChange("exit")
        }, undefined, false, undefined, this),
        /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
          dimColor: true,
          children: exitState.pending ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
            children: [
              "Press ",
              exitState.keyName,
              " again to exit"
            ]
          }, undefined, true, undefined, this) : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
            children: "Enter to confirm \xB7 Esc to cancel"
          }, undefined, false, undefined, this)
        }, undefined, false, undefined, this)
      ]
    }, undefined, true, undefined, this)
  }, undefined, false, undefined, this);
}
export {
  TrustDialog
};
