// @bun
import {
  PermissionDialog,
  init_PermissionDialog
} from "./chunk-cspjnk17.js";
import {
  SAFE_ENV_VARS,
  Select,
  getMcpConfigsByScope,
  getPermissionRulesForSource,
  gracefulShutdownSync,
  init_CustomSelect,
  init_config as init_config2,
  init_gracefulShutdown,
  init_managedEnvConstants,
  init_permissionsLoader
} from "./chunk-4vz571bb.js";
import"./chunk-14p6wvsq.js";
import"./chunk-8hseq8b1.js";
import"./chunk-ddtxq6k5.js";
import"./chunk-28jd8qjx.js";
import"./chunk-djt39ze3.js";
import"./chunk-ptxteaeh.js";
import"./chunk-wd53a7m4.js";
import"./chunk-hms8ge0k.js";
import"./chunk-whpphypt.js";
import"./chunk-pht800m5.js";
import"./chunk-pjkqh1kq.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-qn6me9n1.js";
import"./chunk-qd3r2s2n.js";
import"./chunk-djzd7tef.js";
import"./chunk-gyhnpbkx.js";
import"./chunk-71sdcaq6.js";
import"./chunk-60gf7p5s.js";
import"./chunk-sj3d0nqx.js";
import"./chunk-9pk9rk2w.js";
import"./chunk-javpza6a.js";
import"./chunk-6v7bre98.js";
import"./chunk-24kv69g3.js";
import {
  init_useExitOnCtrlCDWithKeybindings,
  useExitOnCtrlCDWithKeybindings
} from "./chunk-fcqebw9m.js";
import"./chunk-dnfd3c9s.js";
import"./chunk-15ezj4ww.js";
import"./chunk-1h284c6e.js";
import"./chunk-582g9yce.js";
import {
  init_useKeybinding
} from "./chunk-y3ztgztb.js";
import"./chunk-4spgkgr3.js";
import"./chunk-n8kbhswc.js";
import"./chunk-60fkafk2.js";
import"./chunk-fgbkrbk3.js";
import {
  BASH_TOOL_NAME,
  init_toolName
} from "./chunk-ssw61jfd.js";
import"./chunk-093ej2sf.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-nde5ym6a.js";
import"./chunk-k8wq4qsj.js";
import"./chunk-g7d3xx1p.js";
import"./chunk-3wrx2943.js";
import"./chunk-7p9kkh0f.js";
import"./chunk-qp8cgz66.js";
import"./chunk-1mg610h2.js";
import"./chunk-93hc149s.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-nnat9jw5.js";
import"./chunk-hqxp6b72.js";
import"./chunk-4jzkqgf1.js";
import"./chunk-33rd41ng.js";
import"./chunk-f257kqw9.js";
import"./chunk-w5hnghah.js";
import"./chunk-36twraxy.js";
import"./chunk-1bkvnj0y.js";
import"./chunk-akdpcc5p.js";
import {
  checkHasTrustDialogAccepted,
  getSettingsForSource,
  init_config1 as init_config,
  init_settings1 as init_settings,
  saveCurrentProjectConfig
} from "./chunk-7rrkrej7.js";
import"./chunk-6r0bxrh6.js";
import"./chunk-d6500tvx.js";
import"./chunk-jg4bw4hp.js";
import"./chunk-epvbnq43.js";
import"./chunk-tn2sx7j6.js";
import"./chunk-6tzyv21c.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-ch4pgvwq.js";
import"./chunk-99jc4tcw.js";
import"./chunk-fghczfqt.js";
import"./chunk-vwenx8ke.js";
import"./chunk-f86mwfyd.js";
import"./chunk-v4ypszbb.js";
import"./chunk-bk6ck5c2.js";
import"./chunk-ym6j0wv1.js";
import"./chunk-hjmatcgt.js";
import"./chunk-6mdh70q0.js";
import"./chunk-ch92ycde.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-nt5dmk8q.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import"./chunk-0gp4q8aq.js";
import"./chunk-hn4w9pkj.js";
import {
  Link,
  ThemedBox_default,
  ThemedText,
  init_src,
  require_react,
  useKeybinding
} from "./chunk-0r6npc3t.js";
import {
  require_jsx_runtime
} from "./chunk-gxyx8b8w.js";
import {
  init_analytics,
  logEvent
} from "./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-t0450ma3.js";
import"./chunk-0cqw3y8h.js";
import"./chunk-k1sw7km0.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-sc9ycxra.js";
import {
  getCwd,
  init_cwd
} from "./chunk-hhta0nge.js";
import"./chunk-8wsj9fff.js";
import"./chunk-m28vg9w4.js";
import"./chunk-f8prtxs3.js";
import"./chunk-41a6f2kv.js";
import"./chunk-c1yc761e.js";
import"./chunk-c5g9shkw.js";
import {
  getFsImplementation,
  init_fsOperations
} from "./chunk-byd20vdq.js";
import"./chunk-kb3758f7.js";
import {
  init_state,
  setSessionTrustAccepted
} from "./chunk-3j8w0rq8.js";
import"./chunk-tj0dzck2.js";
import"./chunk-aeysytks.js";
import"./chunk-ns1htxgd.js";
import"./chunk-ztqzmfx1.js";
import"./chunk-6k1rsk85.js";
import"./chunk-nxzx0ey9.js";
import"./chunk-yes1my80.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(".claude/settings.json");
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasHooks(localSettings)) {
    sources.push(".claude/settings.local.json");
  }
  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(".claude/settings.json");
  }
  const localRules = getPermissionRulesForSource("localSettings");
  if (hasBashPermission(localRules)) {
    sources.push(".claude/settings.local.json");
  }
  return sources;
}
function hasOtelHeadersHelper(settings) {
  return !!settings?.otelHeadersHelper;
}
function getOtelHeadersHelperSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasOtelHeadersHelper(projectSettings)) {
    sources.push(".claude/settings.json");
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasOtelHeadersHelper(localSettings)) {
    sources.push(".claude/settings.local.json");
  }
  return sources;
}
function hasApiKeyHelper(settings) {
  return !!settings?.apiKeyHelper;
}
function getApiKeyHelperSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasApiKeyHelper(projectSettings)) {
    sources.push(".claude/settings.json");
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasApiKeyHelper(localSettings)) {
    sources.push(".claude/settings.local.json");
  }
  return sources;
}
function hasAwsCommands(settings) {
  return !!(settings?.awsAuthRefresh || settings?.awsCredentialExport);
}
function getAwsCommandsSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasAwsCommands(projectSettings)) {
    sources.push(".claude/settings.json");
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasAwsCommands(localSettings)) {
    sources.push(".claude/settings.local.json");
  }
  return sources;
}
function hasGcpCommands(settings) {
  return !!settings?.gcpAuthRefresh;
}
function getGcpCommandsSources() {
  const sources = [];
  const projectSettings = getSettingsForSource("projectSettings");
  if (hasGcpCommands(projectSettings)) {
    sources.push(".claude/settings.json");
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasGcpCommands(localSettings)) {
    sources.push(".claude/settings.local.json");
  }
  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(".claude/settings.json");
  }
  const localSettings = getSettingsForSource("localSettings");
  if (hasDangerousEnvVars(localSettings)) {
    sources.push(".claude/settings.local.json");
  }
  return sources;
}

// src/components/TrustDialog/TrustDialog.tsx
var jsx_runtime = __toESM(require_jsx_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();
  const [pendingExitCode, setPendingExitCode] = import_react.default.useState(null);
  import_react.default.useEffect(() => {
    if (pendingExitCode !== null) {
      const code = pendingExitCode;
      const timer = setTimeout(() => gracefulShutdownSync(code));
      return () => clearTimeout(timer);
    }
  }, [pendingExitCode]);
  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") {
      setPendingExitCode(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(() => setPendingExitCode(1));
  useKeybinding("confirm:no", () => {
    setPendingExitCode(0);
  }, { context: "Confirmation" });
  if (pendingExitCode !== null) {
    return null;
  }
  if (hasTrustDialogAccepted) {
    setTimeout(onDone);
    return null;
  }
  return /* @__PURE__ */ jsx_runtime.jsx(PermissionDialog, {
    color: "warning",
    titleColor: "warning",
    title: "Accessing workspace:",
    children: /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      flexDirection: "column",
      gap: 1,
      paddingTop: 1,
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          bold: true,
          children: getFsImplementation().cwd()
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          children: "Is this a project you trust? (Your own code, a well-known open source project, or work from your team)."
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          children: "Once trusted, Chris Code can read, edit, and run commands in this folder."
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          dimColor: true,
          children: /* @__PURE__ */ jsx_runtime.jsx(Link, {
            url: "https://code.claude.com/docs/en/security",
            children: "Security guide"
          })
        }),
        /* @__PURE__ */ jsx_runtime.jsx(Select, {
          options: [
            { label: "Yes, I trust this folder", value: "enable_all" },
            { label: "No, exit", value: "exit" }
          ],
          onChange: (value) => onChange(value),
          onCancel: () => onChange("exit")
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          dimColor: true,
          children: exitState.pending ? /* @__PURE__ */ jsx_runtime.jsxs(jsx_runtime.Fragment, {
            children: [
              "Press ",
              exitState.keyName,
              " again to exit"
            ]
          }) : /* @__PURE__ */ jsx_runtime.jsx(jsx_runtime.Fragment, {
            children: "Enter to confirm \xB7 Esc to cancel"
          })
        })
      ]
    })
  });
}
export {
  TrustDialog
};

//# debugId=0C2E26EBF08FD9F064756E2164756E21
//# sourceMappingURL=chunk-vp4eec62.js.map
