// Force strict mode and setup for ESM
"use strict";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/utils/envVarResolver.ts
init_esbuild_shims();
function resolveEnvVarsInString(value, customEnv) {
  const envVarRegex = /\$(?:(\w+)|{([^}]+)})/g;
  return value.replace(envVarRegex, (match, varName1, varName2) => {
    const varName = varName1 || varName2;
    if (customEnv && typeof customEnv[varName] === "string") {
      return customEnv[varName];
    }
    if (process && process.env && typeof process.env[varName] === "string") {
      return process.env[varName];
    }
    return match;
  });
}
__name(resolveEnvVarsInString, "resolveEnvVarsInString");
function resolveEnvVarsInObject(obj, customEnv) {
  return resolveEnvVarsInObjectInternal(obj, /* @__PURE__ */ new WeakSet(), customEnv);
}
__name(resolveEnvVarsInObject, "resolveEnvVarsInObject");
function resolveEnvVarsInObjectInternal(obj, visited, customEnv) {
  if (obj === null || obj === void 0 || typeof obj === "boolean" || typeof obj === "number") {
    return obj;
  }
  if (typeof obj === "string") {
    return resolveEnvVarsInString(obj, customEnv);
  }
  if (Array.isArray(obj)) {
    if (visited.has(obj)) {
      return [...obj];
    }
    visited.add(obj);
    const result = obj.map(
      (item) => resolveEnvVarsInObjectInternal(item, visited, customEnv)
    );
    visited.delete(obj);
    return result;
  }
  if (typeof obj === "object") {
    if (visited.has(obj)) {
      return { ...obj };
    }
    visited.add(obj);
    const newObj = { ...obj };
    for (const key in newObj) {
      if (Object.prototype.hasOwnProperty.call(newObj, key)) {
        newObj[key] = resolveEnvVarsInObjectInternal(
          newObj[key],
          visited,
          customEnv
        );
      }
    }
    visited.delete(obj);
    return newObj;
  }
  return obj;
}
__name(resolveEnvVarsInObjectInternal, "resolveEnvVarsInObjectInternal");

// packages/cli/src/config/migration/versions/v1-to-v2-shared.ts
init_esbuild_shims();
var V1_TO_V2_MIGRATION_MAP = {
  accessibility: "ui.accessibility",
  allowedTools: "tools.allowed",
  allowMCPServers: "mcp.allowed",
  autoAccept: "tools.autoAccept",
  autoConfigureMaxOldSpaceSize: "advanced.autoConfigureMemory",
  bugCommand: "advanced.bugCommand",
  chatCompression: "model.chatCompression",
  checkpointing: "general.checkpointing",
  coreTools: "tools.core",
  contextFileName: "context.fileName",
  customThemes: "ui.customThemes",
  customWittyPhrases: "ui.customWittyPhrases",
  debugKeystrokeLogging: "general.debugKeystrokeLogging",
  dnsResolutionOrder: "advanced.dnsResolutionOrder",
  enforcedAuthType: "security.auth.enforcedType",
  excludeTools: "tools.exclude",
  excludeMCPServers: "mcp.excluded",
  excludedProjectEnvVars: "advanced.excludedEnvVars",
  extensions: "extensions",
  fileFiltering: "context.fileFiltering",
  folderTrustFeature: "security.folderTrust.featureEnabled",
  folderTrust: "security.folderTrust.enabled",
  hasSeenIdeIntegrationNudge: "ide.hasSeenNudge",
  hideWindowTitle: "ui.hideWindowTitle",
  showStatusInTitle: "ui.showStatusInTitle",
  hideTips: "ui.hideTips",
  showLineNumbers: "ui.showLineNumbers",
  showCitations: "ui.showCitations",
  ideMode: "ide.enabled",
  includeDirectories: "context.includeDirectories",
  loadMemoryFromIncludeDirectories: "context.loadFromIncludeDirectories",
  maxSessionTurns: "model.maxSessionTurns",
  mcpServers: "mcpServers",
  mcpServerCommand: "mcp.serverCommand",
  memoryImportFormat: "context.importFormat",
  model: "model.name",
  preferredEditor: "general.preferredEditor",
  sandbox: "tools.sandbox",
  selectedAuthType: "security.auth.selectedType",
  shouldUseNodePtyShell: "tools.shell.enableInteractiveShell",
  shellPager: "tools.shell.pager",
  shellShowColor: "tools.shell.showColor",
  skipNextSpeakerCheck: "model.skipNextSpeakerCheck",
  telemetry: "telemetry",
  theme: "ui.theme",
  toolDiscoveryCommand: "tools.discoveryCommand",
  toolCallCommand: "tools.callCommand",
  usageStatisticsEnabled: "privacy.usageStatisticsEnabled",
  useExternalAuth: "security.auth.useExternal",
  useRipgrep: "tools.useRipgrep",
  vimMode: "general.vimMode",
  enableWelcomeBack: "ui.enableWelcomeBack",
  approvalMode: "tools.approvalMode",
  sessionTokenLimit: "model.sessionTokenLimit",
  contentGenerator: "model.generationConfig",
  skipLoopDetection: "model.skipLoopDetection",
  skipStartupContext: "model.skipStartupContext",
  enableOpenAILogging: "model.enableOpenAILogging",
  tavilyApiKey: "advanced.tavilyApiKey"
};
var V2_CONTAINER_KEYS = /* @__PURE__ */ new Set([
  "ui",
  "tools",
  "mcp",
  "advanced",
  "model",
  "general",
  "context",
  "security",
  "ide",
  "privacy",
  "telemetry",
  "extensions"
]);
var V1_TO_V2_PRESERVE_DISABLE_MAP = {
  disableAutoUpdate: "general.disableAutoUpdate",
  disableUpdateNag: "general.disableUpdateNag",
  disableLoadingPhrases: "ui.accessibility.disableLoadingPhrases",
  disableFuzzySearch: "context.fileFiltering.disableFuzzySearch",
  disableCacheControl: "model.generationConfig.disableCacheControl"
};
var CONSOLIDATED_DISABLE_KEYS = /* @__PURE__ */ new Set([
  "disableAutoUpdate",
  "disableUpdateNag"
]);
var V1_INDICATOR_KEYS = [
  // From V1_TO_V2_MIGRATION_MAP - keys that map to different paths in V2
  "theme",
  "model",
  "autoAccept",
  "hideTips",
  "vimMode",
  "checkpointing",
  "accessibility",
  "allowedTools",
  "allowMCPServers",
  "autoConfigureMaxOldSpaceSize",
  "bugCommand",
  "chatCompression",
  "coreTools",
  "contextFileName",
  "customThemes",
  "customWittyPhrases",
  "debugKeystrokeLogging",
  "dnsResolutionOrder",
  "enforcedAuthType",
  "excludeTools",
  "excludeMCPServers",
  "excludedProjectEnvVars",
  "fileFiltering",
  "folderTrustFeature",
  "folderTrust",
  "hasSeenIdeIntegrationNudge",
  "hideWindowTitle",
  "showStatusInTitle",
  "showLineNumbers",
  "showCitations",
  "ideMode",
  "includeDirectories",
  "loadMemoryFromIncludeDirectories",
  "maxSessionTurns",
  "mcpServerCommand",
  "memoryImportFormat",
  "preferredEditor",
  "sandbox",
  "selectedAuthType",
  "shouldUseNodePtyShell",
  "shellPager",
  "shellShowColor",
  "skipNextSpeakerCheck",
  "toolDiscoveryCommand",
  "toolCallCommand",
  "usageStatisticsEnabled",
  "useExternalAuth",
  "useRipgrep",
  "enableWelcomeBack",
  "approvalMode",
  "sessionTokenLimit",
  "contentGenerator",
  "skipLoopDetection",
  "skipStartupContext",
  "enableOpenAILogging",
  "tavilyApiKey",
  // From V1_TO_V2_PRESERVE_DISABLE_MAP - disable* keys that get nested in V2
  "disableAutoUpdate",
  "disableUpdateNag",
  "disableLoadingPhrases",
  "disableFuzzySearch",
  "disableCacheControl"
];

// packages/cli/src/config/shared-env-keys.ts
init_esbuild_shims();
var DEFAULT_EXCLUDED_ENV_VARS = ["DEBUG", "DEBUG_MODE"];
var ENV_CORRUPTED_PATH = "QWEN_CODE_SETTINGS_CORRUPTED_PATH";
var ENV_WAS_RECOVERED = "QWEN_CODE_SETTINGS_WAS_RECOVERED";
var PROJECT_ENV_HARDCODED_EXCLUSIONS = [
  "QWEN_HOME",
  "QWEN_RUNTIME_DIR",
  "QWEN_CODE_MCP_APPROVALS_PATH",
  "QWEN_CODE_TRUSTED_FOLDERS_PATH",
  ENV_CORRUPTED_PATH,
  ENV_WAS_RECOVERED,
  // QWEN_TLS_INSECURE (and NODE_TLS_REJECT_UNAUTHORIZED, which it mirrors)
  // disable TLS certificate verification for all outbound API connections. A
  // project `.env` must never enable either — that would let an untrusted repo
  // silently turn off MITM protection. Opt-in stays with the user via the
  // `--insecure` flag, the shell environment, or a home `.env`. The initial
  // `.env` load only consults this list, so both keys must be here (not just
  // RELOAD_EXCLUDED_KEYS, which only applies on reload).
  "QWEN_TLS_INSECURE",
  "NODE_TLS_REJECT_UNAUTHORIZED"
];
var HOME_ENV_BOOTSTRAP_KEYS = [
  "QWEN_HOME",
  "QWEN_RUNTIME_DIR",
  "QWEN_CODE_MCP_APPROVALS_PATH",
  "QWEN_CODE_TRUSTED_FOLDERS_PATH"
];

// packages/cli/src/config/storage-paths-lite.ts
init_esbuild_shims();
import * as os from "node:os";
import * as path from "node:path";
var SETTINGS_DIRECTORY_NAME = ".qwen";
function resolveConfigPathLite(dir, cwd) {
  let resolved = dir;
  if (resolved === "~" || resolved.startsWith("~/") || resolved.startsWith("~\\")) {
    const relativeSegments = resolved === "~" ? [] : resolved.slice(2).split(/[/\\]+/).filter(Boolean);
    resolved = path.join(os.homedir(), ...relativeSegments);
  }
  if (!path.isAbsolute(resolved)) {
    resolved = path.resolve(cwd || process.cwd(), resolved);
  }
  return resolved;
}
__name(resolveConfigPathLite, "resolveConfigPathLite");
function getGlobalQwenDirLite() {
  const envDir = process.env["QWEN_HOME"];
  if (envDir) {
    return resolveConfigPathLite(envDir);
  }
  const homeDir = os.homedir();
  if (!homeDir) {
    return path.join(os.tmpdir(), SETTINGS_DIRECTORY_NAME);
  }
  return path.join(homeDir, SETTINGS_DIRECTORY_NAME);
}
__name(getGlobalQwenDirLite, "getGlobalQwenDirLite");
function getSystemSettingsPath() {
  if (process.env["QWEN_CODE_SYSTEM_SETTINGS_PATH"]) {
    return process.env["QWEN_CODE_SYSTEM_SETTINGS_PATH"];
  }
  if (os.platform() === "darwin") {
    return "/Library/Application Support/QwenCode/settings.json";
  }
  if (os.platform() === "win32") {
    return "C:\\ProgramData\\qwen-code\\settings.json";
  }
  return "/etc/qwen-code/settings.json";
}
__name(getSystemSettingsPath, "getSystemSettingsPath");
function getSystemDefaultsPath() {
  if (process.env["QWEN_CODE_SYSTEM_DEFAULTS_PATH"]) {
    return process.env["QWEN_CODE_SYSTEM_DEFAULTS_PATH"];
  }
  return path.join(
    path.dirname(getSystemSettingsPath()),
    "system-defaults.json"
  );
}
__name(getSystemDefaultsPath, "getSystemDefaultsPath");

export {
  resolveEnvVarsInObject,
  V1_TO_V2_MIGRATION_MAP,
  V2_CONTAINER_KEYS,
  V1_TO_V2_PRESERVE_DISABLE_MAP,
  CONSOLIDATED_DISABLE_KEYS,
  V1_INDICATOR_KEYS,
  DEFAULT_EXCLUDED_ENV_VARS,
  ENV_CORRUPTED_PATH,
  ENV_WAS_RECOVERED,
  PROJECT_ENV_HARDCODED_EXCLUSIONS,
  HOME_ENV_BOOTSTRAP_KEYS,
  SETTINGS_DIRECTORY_NAME,
  resolveConfigPathLite,
  getGlobalQwenDirLite,
  getSystemSettingsPath,
  getSystemDefaultsPath
};
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
/**
 * @license
 * Copyright 2025 Qwen Team
 * SPDX-License-Identifier: Apache-2.0
 */
