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

// node_modules/strip-json-comments/index.js
var require_strip_json_comments = __commonJS({
  "node_modules/strip-json-comments/index.js"(exports, module) {
    "use strict";
    init_esbuild_shims();
    var singleComment = Symbol("singleComment");
    var multiComment = Symbol("multiComment");
    var stripWithoutWhitespace = /* @__PURE__ */ __name(() => "", "stripWithoutWhitespace");
    var stripWithWhitespace = /* @__PURE__ */ __name((string, start, end) => string.slice(start, end).replace(/\S/g, " "), "stripWithWhitespace");
    var isEscaped = /* @__PURE__ */ __name((jsonString, quotePosition) => {
      let index = quotePosition - 1;
      let backslashCount = 0;
      while (jsonString[index] === "\\") {
        index -= 1;
        backslashCount += 1;
      }
      return Boolean(backslashCount % 2);
    }, "isEscaped");
    module.exports = (jsonString, options = {}) => {
      if (typeof jsonString !== "string") {
        throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
      }
      const strip = options.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;
      let insideString = false;
      let insideComment = false;
      let offset = 0;
      let result = "";
      for (let i = 0; i < jsonString.length; i++) {
        const currentCharacter = jsonString[i];
        const nextCharacter = jsonString[i + 1];
        if (!insideComment && currentCharacter === '"') {
          const escaped = isEscaped(jsonString, i);
          if (!escaped) {
            insideString = !insideString;
          }
        }
        if (insideString) {
          continue;
        }
        if (!insideComment && currentCharacter + nextCharacter === "//") {
          result += jsonString.slice(offset, i);
          offset = i;
          insideComment = singleComment;
          i++;
        } else if (insideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
          i++;
          insideComment = false;
          result += strip(jsonString, offset, i);
          offset = i;
          continue;
        } else if (insideComment === singleComment && currentCharacter === "\n") {
          insideComment = false;
          result += strip(jsonString, offset, i);
          offset = i;
        } else if (!insideComment && currentCharacter + nextCharacter === "/*") {
          result += jsonString.slice(offset, i);
          offset = i;
          insideComment = multiComment;
          i++;
          continue;
        } else if (insideComment === multiComment && currentCharacter + nextCharacter === "*/") {
          i++;
          insideComment = false;
          result += strip(jsonString, offset, i + 1);
          offset = i + 1;
          continue;
        }
      }
      return result + (insideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
    };
  }
});

// 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
];
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");

// packages/cli/src/config/path-comparison.ts
init_esbuild_shims();
import * as fs from "node:fs";
import * as path2 from "node:path";
function isWithinRoot(childPath, parentPath) {
  const relativePath = path2.relative(parentPath, childPath);
  return relativePath === "" || !relativePath.startsWith(`..${path2.sep}`) && relativePath !== ".." && !path2.isAbsolute(relativePath);
}
__name(isWithinRoot, "isWithinRoot");
function getPathComparisonVariants(rawPath) {
  const variants = /* @__PURE__ */ new Set([path2.normalize(path2.resolve(rawPath))]);
  try {
    variants.add(path2.normalize(fs.realpathSync(rawPath)));
  } catch {
  }
  return variants;
}
__name(getPathComparisonVariants, "getPathComparisonVariants");
function arePathsEquivalent(left, right) {
  const rightVariants = getPathComparisonVariants(right);
  for (const leftVariant of getPathComparisonVariants(left)) {
    if (rightVariants.has(leftVariant)) {
      return true;
    }
  }
  return false;
}
__name(arePathsEquivalent, "arePathsEquivalent");

// 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");

export {
  require_strip_json_comments,
  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,
  isWithinRoot,
  getPathComparisonVariants,
  arePathsEquivalent,
  resolveEnvVarsInObject
};
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
/**
 * @license
 * Copyright 2025 Qwen Team
 * SPDX-License-Identifier: Apache-2.0
 */
