"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// ../packages/core/dist/chunk-QEEF5TZY.js
function generateMessageId() {
  return `msg-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
}
function messageToStored(msg) {
  const { role, isStreaming, isPending, ...rest } = msg;
  return { ...rest, type: role };
}
function storedToMessage(stored) {
  const { type, ...rest } = stored;
  return { ...rest, role: type, timestamp: _nullishCoalesce(stored.timestamp, () => ( Date.now())) };
}

// ../packages/core/dist/chunk-LCDW7EA2.js
function debug(..._args) {
}
function normalizePath(path) {
  return path.replace(/\\/g, "/");
}
function pathStartsWith(filePath, dirPath) {
  const normalizedFile = normalizePath(filePath);
  const normalizedDir = normalizePath(dirPath);
  return normalizedFile.startsWith(normalizedDir + "/") || normalizedFile === normalizedDir;
}
function stripPathPrefix(filePath, prefix) {
  const normalizedFile = normalizePath(filePath);
  const normalizedPrefix = normalizePath(prefix);
  if (normalizedFile.startsWith(normalizedPrefix + "/")) {
    return normalizedFile.slice(normalizedPrefix.length + 1);
  }
  return filePath;
}

// ../packages/core/dist/index.js
var THINKING_LEVEL_IDS = [
  "off",
  "low",
  "medium",
  "high",
  "xhigh",
  "max"
];
var THINKING_LEVELS = [
  { id: "off", nameKey: "thinking.off", descriptionKey: "thinking.offDesc" },
  { id: "low", nameKey: "thinking.low", descriptionKey: "thinking.lowDesc" },
  { id: "medium", nameKey: "thinking.medium", descriptionKey: "thinking.mediumDesc" },
  { id: "high", nameKey: "thinking.high", descriptionKey: "thinking.highDesc" },
  { id: "xhigh", nameKey: "thinking.xhigh", descriptionKey: "thinking.xhighDesc" },
  { id: "max", nameKey: "thinking.max", descriptionKey: "thinking.maxDesc" }
];
var THINKING_TO_EFFORT = {
  off: null,
  low: "low",
  medium: "medium",
  high: "high",
  xhigh: "xhigh",
  max: "max"
};
var TOKEN_BUDGETS = {
  haiku: {
    off: 0,
    low: 2e3,
    medium: 4e3,
    high: 6e3,
    xhigh: 7e3,
    max: 8e3
  },
  default: {
    off: 0,
    low: 4e3,
    medium: 1e4,
    high: 2e4,
    xhigh: 26e3,
    max: 32e3
  }
};
function getThinkingTokens(level, modelId) {
  const isHaiku = modelId.toLowerCase().includes("haiku");
  const budgets = isHaiku ? TOKEN_BUDGETS.haiku : TOKEN_BUDGETS.default;
  return budgets[level];
}
function getThinkingLevelNameKey(level) {
  const def = THINKING_LEVELS.find((l) => l.id === level);
  return _nullishCoalesce(_optionalChain([def, 'optionalAccess', _2 => _2.nameKey]), () => ( `thinking.${level}`));
}
function isValidThinkingLevel(value) {
  return typeof value === "string" && THINKING_LEVEL_IDS.includes(value);
}
function normalizeThinkingLevel(value) {
  if (value === "think") return "medium";
  if (isValidThinkingLevel(value)) return value;
  return void 0;
}
var RPC_CHANNELS = {
  remote: {
    TEST_CONNECTION: "remote:testConnection"
  },
  server: {
    GET_WORKSPACES: "server:getWorkspaces",
    CREATE_WORKSPACE: "server:createWorkspace",
    GET_STATUS: "server:getStatus",
    GET_HEALTH: "server:getHealth",
    GET_ACTIVE_SESSIONS: "server:getActiveSessions",
    SHUTTING_DOWN: "server:shuttingDown",
    STATUS_CHANGED: "server:statusChanged",
    HOME_DIR: "server:homeDir"
  },
  sessions: {
    GET: "sessions:get",
    GET_UNREAD_SUMMARY: "sessions:getUnreadSummary",
    MARK_ALL_READ: "sessions:markAllRead",
    UNREAD_SUMMARY_CHANGED: "sessions:unreadSummaryChanged",
    CREATE: "sessions:create",
    DELETE: "sessions:delete",
    GET_MESSAGES: "sessions:getMessages",
    SEND_MESSAGE: "sessions:sendMessage",
    CANCEL: "sessions:cancel",
    KILL_SHELL: "sessions:killShell",
    RESPOND_TO_PERMISSION: "sessions:respondToPermission",
    RESPOND_TO_CREDENTIAL: "sessions:respondToCredential",
    COMMAND: "sessions:command",
    GET_PENDING_PLAN_EXECUTION: "sessions:getPendingPlanExecution",
    GET_PERMISSION_MODE_STATE: "sessions:getPermissionModeState",
    EVENT: "session:event",
    GET_MODEL: "session:getModel",
    SET_MODEL: "session:setModel",
    GET_FILES: "sessions:getFiles",
    GET_NOTES: "sessions:getNotes",
    SET_NOTES: "sessions:setNotes",
    WATCH_FILES: "sessions:watchFiles",
    UNWATCH_FILES: "sessions:unwatchFiles",
    FILES_CHANGED: "sessions:filesChanged",
    SEARCH_CONTENT: "sessions:searchContent",
    EXPORT: "sessions:export",
    IMPORT: "sessions:import",
    EXPORT_REMOTE_TRANSFER: "sessions:exportRemoteTransfer",
    IMPORT_REMOTE_TRANSFER: "sessions:importRemoteTransfer"
  },
  transfer: {
    START: "transfer:start",
    CHUNK: "transfer:chunk",
    COMMIT: "transfer:commit",
    ABORT: "transfer:abort"
  },
  tasks: {
    GET_OUTPUT: "tasks:getOutput"
  },
  workspaces: {
    GET: "workspaces:get",
    CREATE: "workspaces:create",
    CHECK_SLUG: "workspaces:checkSlug",
    UPDATE_REMOTE: "workspaces:updateRemote"
  },
  window: {
    GET_WORKSPACE: "window:getWorkspace",
    GET_MODE: "window:getMode",
    OPEN_WORKSPACE: "window:openWorkspace",
    OPEN_SESSION_IN_NEW_WINDOW: "window:openSessionInNewWindow",
    SWITCH_WORKSPACE: "window:switchWorkspace",
    CLOSE: "window:close",
    CLOSE_REQUESTED: "window:closeRequested",
    CONFIRM_CLOSE: "window:confirmClose",
    CANCEL_CLOSE: "window:cancelClose",
    SET_TRAFFIC_LIGHTS: "window:setTrafficLights",
    FOCUS_STATE: "window:focusState",
    GET_FOCUS_STATE: "window:getFocusState"
  },
  file: {
    READ: "file:read",
    READ_DATA_URL: "file:readDataUrl",
    READ_PREVIEW_DATA_URL: "file:readPreviewDataUrl",
    READ_BINARY: "file:readBinary",
    OPEN_DIALOG: "file:openDialog",
    READ_ATTACHMENT: "file:readAttachment",
    READ_USER_ATTACHMENT: "file:readUserAttachment",
    STORE_ATTACHMENT: "file:storeAttachment",
    GENERATE_THUMBNAIL: "file:generateThumbnail"
  },
  fs: {
    SEARCH: "fs:search",
    LIST_DIRECTORY: "fs:listDirectory"
  },
  debug: {
    LOG: "debug:log"
  },
  theme: {
    GET_SYSTEM_PREFERENCE: "theme:getSystemPreference",
    SYSTEM_CHANGED: "theme:systemChanged",
    APP_CHANGED: "theme:appChanged",
    GET_APP: "theme:getApp",
    GET_PRESETS: "theme:getPresets",
    LOAD_PRESET: "theme:loadPreset",
    GET_COLOR_THEME: "theme:getColorTheme",
    SET_COLOR_THEME: "theme:setColorTheme",
    BROADCAST_PREFERENCES: "theme:broadcastPreferences",
    PREFERENCES_CHANGED: "theme:preferencesChanged",
    GET_WORKSPACE_COLOR_THEME: "theme:getWorkspaceColorTheme",
    SET_WORKSPACE_COLOR_THEME: "theme:setWorkspaceColorTheme",
    GET_ALL_WORKSPACE_THEMES: "theme:getAllWorkspaceThemes",
    BROADCAST_WORKSPACE_THEME: "theme:broadcastWorkspaceTheme",
    WORKSPACE_THEME_CHANGED: "theme:workspaceThemeChanged"
  },
  system: {
    VERSIONS: "system:versions",
    HOME_DIR: "system:homeDir",
    IS_DEBUG_MODE: "system:isDebugMode"
  },
  update: {
    CHECK: "update:check",
    GET_INFO: "update:getInfo",
    INSTALL: "update:install",
    DISMISS: "update:dismiss",
    GET_DISMISSED: "update:getDismissed",
    AVAILABLE: "update:available",
    DOWNLOAD_PROGRESS: "update:downloadProgress"
  },
  shell: {
    OPEN_URL: "shell:openUrl",
    OPEN_FILE: "shell:openFile",
    SHOW_IN_FOLDER: "shell:showInFolder"
  },
  menu: {
    NEW_CHAT: "menu:newChat",
    NEW_WINDOW: "menu:newWindow",
    OPEN_SETTINGS: "menu:openSettings",
    KEYBOARD_SHORTCUTS: "menu:keyboardShortcuts",
    TOGGLE_FOCUS_MODE: "menu:toggleFocusMode",
    TOGGLE_SIDEBAR: "menu:toggleSidebar",
    QUIT: "menu:quit",
    MINIMIZE: "menu:minimize",
    MAXIMIZE: "menu:maximize",
    ZOOM_IN: "menu:zoomIn",
    ZOOM_OUT: "menu:zoomOut",
    ZOOM_RESET: "menu:zoomReset",
    TOGGLE_DEV_TOOLS: "menu:toggleDevTools",
    UNDO: "menu:undo",
    REDO: "menu:redo",
    CUT: "menu:cut",
    COPY: "menu:copy",
    PASTE: "menu:paste",
    SELECT_ALL: "menu:selectAll"
  },
  deeplink: {
    NAVIGATE: "deeplink:navigate"
  },
  auth: {
    LOGOUT: "auth:logout",
    SHOW_LOGOUT_CONFIRMATION: "auth:showLogoutConfirmation",
    SHOW_DELETE_SESSION_CONFIRMATION: "auth:showDeleteSessionConfirmation"
  },
  credentials: {
    HEALTH_CHECK: "credentials:healthCheck"
  },
  onboarding: {
    GET_AUTH_STATE: "onboarding:getAuthState",
    VALIDATE_MCP: "onboarding:validateMcp",
    START_MCP_OAUTH: "onboarding:startMcpOAuth",
    START_CLAUDE_OAUTH: "onboarding:startClaudeOAuth",
    EXCHANGE_CLAUDE_CODE: "onboarding:exchangeClaudeCode",
    HAS_CLAUDE_OAUTH_STATE: "onboarding:hasClaudeOAuthState",
    CLEAR_CLAUDE_OAUTH_STATE: "onboarding:clearClaudeOAuthState",
    DEFER_SETUP: "onboarding:deferSetup"
  },
  llmConnections: {
    LIST: "LLM_Connection:list",
    LIST_WITH_STATUS: "LLM_Connection:listWithStatus",
    GET: "LLM_Connection:get",
    GET_API_KEY: "LLM_Connection:getApiKey",
    SAVE: "LLM_Connection:save",
    DELETE: "LLM_Connection:delete",
    TEST: "LLM_Connection:test",
    SET_DEFAULT: "LLM_Connection:setDefault",
    SET_WORKSPACE_DEFAULT: "LLM_Connection:setWorkspaceDefault",
    REFRESH_MODELS: "LLM_Connection:refreshModels",
    CHANGED: "LLM_Connection:changed"
  },
  chatgpt: {
    START_OAUTH: "chatgpt:startOAuth",
    COMPLETE_OAUTH: "chatgpt:completeOAuth",
    CANCEL_OAUTH: "chatgpt:cancelOAuth",
    GET_AUTH_STATUS: "chatgpt:getAuthStatus",
    LOGOUT: "chatgpt:logout"
  },
  copilot: {
    START_OAUTH: "copilot:startOAuth",
    CANCEL_OAUTH: "copilot:cancelOAuth",
    GET_AUTH_STATUS: "copilot:getAuthStatus",
    LOGOUT: "copilot:logout",
    DEVICE_CODE: "copilot:deviceCode"
  },
  settings: {
    SETUP_LLM_CONNECTION: "settings:setupLlmConnection",
    TEST_LLM_CONNECTION_SETUP: "settings:testLlmConnectionSetup",
    GET_DEFAULT_THINKING_LEVEL: "settings:getDefaultThinkingLevel",
    SET_DEFAULT_THINKING_LEVEL: "settings:setDefaultThinkingLevel",
    GET_NETWORK_PROXY: "settings:getNetworkProxy",
    SET_NETWORK_PROXY: "settings:setNetworkProxy",
    GET_SERVER_CONFIG: "settings:getServerConfig",
    SET_SERVER_CONFIG: "settings:setServerConfig",
    GET_SERVER_STATUS: "settings:getServerStatus"
  },
  pi: {
    GET_API_KEY_PROVIDERS: "pi:getApiKeyProviders",
    GET_PROVIDER_BASE_URL: "pi:getProviderBaseUrl",
    GET_PROVIDER_MODELS: "pi:getProviderModels"
  },
  dialog: {
    OPEN_FOLDER: "dialog:openFolder"
  },
  preferences: {
    READ: "preferences:read",
    WRITE: "preferences:write"
  },
  drafts: {
    GET: "drafts:get",
    SET: "drafts:set",
    DELETE: "drafts:delete",
    GET_ALL: "drafts:getAll"
  },
  sources: {
    GET: "sources:get",
    CREATE: "sources:create",
    DELETE: "sources:delete",
    START_OAUTH: "sources:startOAuth",
    SAVE_CREDENTIALS: "sources:saveCredentials",
    CHANGED: "sources:changed",
    GET_PERMISSIONS: "sources:getPermissions",
    GET_MCP_TOOLS: "sources:getMcpTools"
  },
  oauth: {
    START: "oauth:start",
    COMPLETE: "oauth:complete",
    CANCEL: "oauth:cancel",
    REVOKE: "oauth:revoke"
  },
  workspace: {
    GET_PERMISSIONS: "workspace:getPermissions",
    READ_IMAGE: "workspace:readImage",
    WRITE_IMAGE: "workspace:writeImage",
    SETTINGS_GET: "workspaceSettings:get",
    SETTINGS_UPDATE: "workspaceSettings:update"
  },
  permissions: {
    GET_DEFAULTS: "permissions:getDefaults",
    DEFAULTS_CHANGED: "permissions:defaultsChanged"
  },
  skills: {
    GET: "skills:get",
    GET_FILES: "skills:getFiles",
    DELETE: "skills:delete",
    OPEN_EDITOR: "skills:openEditor",
    OPEN_FINDER: "skills:openFinder",
    CHANGED: "skills:changed"
  },
  statuses: {
    LIST: "statuses:list",
    REORDER: "statuses:reorder",
    CHANGED: "statuses:changed"
  },
  labels: {
    LIST: "labels:list",
    CREATE: "labels:create",
    DELETE: "labels:delete",
    CHANGED: "labels:changed"
  },
  views: {
    LIST: "views:list",
    SAVE: "views:save"
  },
  toolIcons: {
    GET_MAPPINGS: "toolIcons:getMappings"
  },
  logo: {
    GET_URL: "logo:getUrl"
  },
  notification: {
    SHOW: "notification:show",
    NAVIGATE: "notification:navigate",
    GET_ENABLED: "notification:getEnabled",
    SET_ENABLED: "notification:setEnabled"
  },
  input: {
    GET_AUTO_CAPITALISATION: "input:getAutoCapitalisation",
    SET_AUTO_CAPITALISATION: "input:setAutoCapitalisation",
    GET_SEND_MESSAGE_KEY: "input:getSendMessageKey",
    SET_SEND_MESSAGE_KEY: "input:setSendMessageKey",
    GET_SPELL_CHECK: "input:getSpellCheck",
    SET_SPELL_CHECK: "input:setSpellCheck"
  },
  power: {
    GET_KEEP_AWAKE: "power:getKeepAwake",
    SET_KEEP_AWAKE: "power:setKeepAwake"
  },
  appearance: {
    GET_RICH_TOOL_DESCRIPTIONS: "appearance:getRichToolDescriptions",
    SET_RICH_TOOL_DESCRIPTIONS: "appearance:setRichToolDescriptions"
  },
  tools: {
    GET_BROWSER_TOOL_ENABLED: "tools:getBrowserToolEnabled",
    SET_BROWSER_TOOL_ENABLED: "tools:setBrowserToolEnabled"
  },
  caching: {
    GET_EXTENDED_PROMPT_CACHE: "caching:getExtendedPromptCache",
    SET_EXTENDED_PROMPT_CACHE: "caching:setExtendedPromptCache",
    GET_ENABLE_1M_CONTEXT: "caching:getEnable1MContext",
    SET_ENABLE_1M_CONTEXT: "caching:setEnable1MContext"
  },
  badge: {
    REFRESH: "badge:refresh",
    SET_ICON: "badge:setIcon",
    DRAW: "badge:draw",
    DRAW_WINDOWS: "badge:draw-windows"
  },
  releaseNotes: {
    GET: "releaseNotes:get",
    GET_LATEST_VERSION: "releaseNotes:getLatestVersion"
  },
  git: {
    GET_BRANCH: "git:getBranch"
  },
  gitbash: {
    CHECK: "gitbash:check",
    BROWSE: "gitbash:browse",
    SET_PATH: "gitbash:setPath"
  },
  browserPane: {
    CREATE: "browser-pane:create",
    DESTROY: "browser-pane:destroy",
    LIST: "browser-pane:list",
    NAVIGATE: "browser-pane:navigate",
    GO_BACK: "browser-pane:go-back",
    GO_FORWARD: "browser-pane:go-forward",
    RELOAD: "browser-pane:reload",
    STOP: "browser-pane:stop",
    FOCUS: "browser-pane:focus",
    SNAPSHOT: "browser-pane:snapshot",
    CLICK: "browser-pane:click",
    FILL: "browser-pane:fill",
    SELECT: "browser-pane:select",
    SCREENSHOT: "browser-pane:screenshot",
    EVALUATE: "browser-pane:evaluate",
    SCROLL: "browser-pane:scroll",
    LAUNCH: "browser-empty-state:launch",
    STATE_CHANGED: "browser-pane:state-changed",
    REMOVED: "browser-pane:removed",
    INTERACTED: "browser-pane:interacted"
  },
  automations: {
    GET: "automations:get",
    TEST: "automations:test",
    SET_ENABLED: "automations:setEnabled",
    DUPLICATE: "automations:duplicate",
    DELETE: "automations:delete",
    GET_HISTORY: "automations:getHistory",
    GET_LAST_EXECUTED: "automations:getLastExecuted",
    REPLAY: "automations:replay",
    CHANGED: "automations:changed"
  },
  resources: {
    EXPORT: "resources:export",
    IMPORT: "resources:import"
  },
  messaging: {
    // WhatsApp subprocess → Gateway (subprocess invokes on server)
    WA_REGISTER: "messaging:wa:register",
    WA_INCOMING: "messaging:wa:incoming",
    WA_BUTTON_PRESS: "messaging:wa:buttonPress",
    WA_STATUS: "messaging:wa:status",
    WA_QR: "messaging:wa:qr",
    // Gateway → WhatsApp subprocess (server invokes on client)
    WA_SEND: "messaging:wa:send",
    WA_SEND_BUTTONS: "messaging:wa:sendButtons",
    WA_SEND_TYPING: "messaging:wa:sendTyping",
    WA_SEND_FILE: "messaging:wa:sendFile",
    WA_CONNECT: "messaging:wa:connect",
    WA_DISCONNECT: "messaging:wa:disconnect",
    // Gateway → UI clients (broadcast)
    BINDING_CHANGED: "messaging:bindingChanged",
    PLATFORM_STATUS: "messaging:platformStatus",
    /** Broadcast when the workspace's pending-senders list mutates. */
    PENDING_CHANGED: "messaging:pendingChanged",
    // UI ↔ Server (config/binding CRUD)
    GET_CONFIG: "messaging:getConfig",
    UPDATE_CONFIG: "messaging:updateConfig",
    TEST_TELEGRAM: "messaging:testTelegram",
    SAVE_TELEGRAM: "messaging:saveTelegram",
    TEST_LARK: "messaging:testLark",
    SAVE_LARK: "messaging:saveLark",
    DISCONNECT: "messaging:disconnect",
    FORGET: "messaging:forget",
    GET_BINDINGS: "messaging:getBindings",
    GENERATE_CODE: "messaging:generateCode",
    UNBIND: "messaging:unbind",
    UNBIND_BINDING: "messaging:unbindBinding",
    /** Workspace-supergroup pairing (Telegram forum support). UI ↔ Server. */
    GENERATE_SUPERGROUP_CODE: "messaging:generateSupergroupCode",
    GET_SUPERGROUP: "messaging:getSupergroup",
    UNBIND_SUPERGROUP: "messaging:unbindSupergroup",
    // UI ↔ Server — WhatsApp pairing/connection flow (Baileys subprocess adapter)
    WA_START_CONNECT: "messaging:wa:startConnect",
    WA_SUBMIT_PHONE: "messaging:wa:submitPhone",
    /** Broadcast to UI clients: QR string, pairing code, status, unavailable, error. */
    WA_UI_EVENT: "messaging:wa:uiEvent",
    // UI ↔ Server — Access control (per-platform owners + per-binding allow-list)
    GET_PLATFORM_OWNERS: "messaging:access:getOwners",
    SET_PLATFORM_OWNERS: "messaging:access:setOwners",
    GET_PLATFORM_ACCESS_MODE: "messaging:access:getMode",
    SET_PLATFORM_ACCESS_MODE: "messaging:access:setMode",
    GET_PENDING_SENDERS: "messaging:access:getPending",
    DISMISS_PENDING_SENDER: "messaging:access:dismissPending",
    ALLOW_PENDING_SENDER: "messaging:access:allowPending",
    SET_BINDING_ACCESS: "messaging:access:setBindingAccess"
  }
};
var SKILL_PATTERN = /\[skill:([^\]]+)\]/g;
var SOURCE_PATTERN = /\[source:([^\]]+)\]/g;
var FILE_PATTERN = /\[file:([^\]]+)\]/g;
var FOLDER_PATTERN = /\[folder:([^\]]+)\]/g;
function parseMentions(text, availableSkillSlugs, availableSourceSlugs) {
  const skillSet = new Set(availableSkillSlugs);
  const sourceSet = new Set(availableSourceSlugs);
  const skills = [];
  const invalidSkills = [];
  const sources = [];
  const files = [];
  const folders = [];
  for (const match of text.matchAll(SKILL_PATTERN)) {
    const slug = extractSkillSlug(match[1]);
    if (skillSet.has(slug)) {
      if (!skills.includes(slug)) skills.push(slug);
    } else {
      if (!invalidSkills.includes(slug)) invalidSkills.push(slug);
    }
  }
  for (const match of text.matchAll(SOURCE_PATTERN)) {
    const slug = match[1].trim();
    if (sourceSet.has(slug) && !sources.includes(slug)) {
      sources.push(slug);
    }
  }
  for (const match of text.matchAll(FILE_PATTERN)) {
    const path = match[1].trim();
    if (path && !files.includes(path)) files.push(path);
  }
  for (const match of text.matchAll(FOLDER_PATTERN)) {
    const path = match[1].trim();
    if (path && !folders.includes(path)) folders.push(path);
  }
  return { skills, invalidSkills, sources, files, folders };
}
function resolveSkillMentions(text, skillNames) {
  return text.replace(SKILL_PATTERN, (full, raw) => {
    const slug = extractSkillSlug(raw);
    const displayName = _nullishCoalesce(skillNames.get(slug), () => ( slug));
    return `[Mentioned skill: ${displayName} (slug: ${slug})]`;
  });
}
function resolveSourceMentions(text) {
  return text.replace(SOURCE_PATTERN, (_, slug) => {
    return `[Mentioned source: ${slug.trim()}]`;
  });
}
async function resolvePathMentions(text, workingDirectory) {
  const { basename } = await Promise.resolve().then(() => _interopRequireWildcard(require("path")));
  const cwd = _nullishCoalesce(workingDirectory, () => ( process.cwd()));
  const fileMatches = [...text.matchAll(FILE_PATTERN)];
  const folderMatches = [...text.matchAll(FOLDER_PATTERN)];
  const fileReplacements = /* @__PURE__ */ new Map();
  for (const match of fileMatches) {
    const rawPath = match[1].trim();
    const absPath = await resolvePath(rawPath, cwd);
    const name = basename(absPath);
    fileReplacements.set(match[0], `[Mentioned file: ${name} (at ${absPath})]`);
  }
  const folderReplacements = /* @__PURE__ */ new Map();
  for (const match of folderMatches) {
    const rawPath = match[1].trim();
    const absPath = await resolvePath(rawPath, cwd);
    const name = basename(absPath);
    folderReplacements.set(match[0], `[Mentioned folder: ${name} (at ${absPath})]`);
  }
  let result = text;
  for (const [original, replacement] of fileReplacements) {
    result = result.replace(original, replacement);
  }
  for (const [original, replacement] of folderReplacements) {
    result = result.replace(original, replacement);
  }
  return result;
}
function resolveFileMentions(text, workingDirectory) {
  return resolvePathMentions(text, workingDirectory);
}
function stripAllMentions(text) {
  let result = text;
  result = result.replace(SKILL_PATTERN, (_, raw) => extractSkillSlug(raw));
  result = result.replace(SOURCE_PATTERN, (_, slug) => slug.trim());
  result = result.replace(FILE_PATTERN, (_, p) => p.trim());
  result = result.replace(FOLDER_PATTERN, (_, p) => p.trim());
  return result.replace(/\s{2,}/g, " ").trim();
}
function findMentionMatches(text, availableSkillSlugs, availableSourceSlugs) {
  const matches = [];
  for (const match of text.matchAll(SKILL_PATTERN)) {
    matches.push({
      type: "skill",
      id: extractSkillSlug(match[1]),
      fullMatch: match[0],
      startIndex: match.index
    });
  }
  for (const match of text.matchAll(SOURCE_PATTERN)) {
    matches.push({
      type: "source",
      id: match[1].trim(),
      fullMatch: match[0],
      startIndex: match.index
    });
  }
  for (const match of text.matchAll(FILE_PATTERN)) {
    matches.push({
      type: "file",
      id: match[1].trim(),
      fullMatch: match[0],
      startIndex: match.index
    });
  }
  for (const match of text.matchAll(FOLDER_PATTERN)) {
    matches.push({
      type: "folder",
      id: match[1].trim(),
      fullMatch: match[0],
      startIndex: match.index
    });
  }
  return matches.sort((a, b) => a.startIndex - b.startIndex);
}
function extractSkillSlug(raw) {
  const parts = raw.trim().split(":");
  return parts[parts.length - 1].trim();
}
async function resolvePath(path, cwd) {
  const { resolve } = await Promise.resolve().then(() => _interopRequireWildcard(require("path")));
  if (path.startsWith("~")) {
    const { homedir } = await Promise.resolve().then(() => _interopRequireWildcard(require("os")));
    return resolve(homedir(), path.slice(2));
  }
  if (path.startsWith("/")) return path;
  return resolve(cwd, path);
}
























exports.generateMessageId = generateMessageId; exports.messageToStored = messageToStored; exports.storedToMessage = storedToMessage; exports.debug = debug; exports.normalizePath = normalizePath; exports.pathStartsWith = pathStartsWith; exports.stripPathPrefix = stripPathPrefix; exports.THINKING_LEVEL_IDS = THINKING_LEVEL_IDS; exports.THINKING_LEVELS = THINKING_LEVELS; exports.THINKING_TO_EFFORT = THINKING_TO_EFFORT; exports.getThinkingTokens = getThinkingTokens; exports.getThinkingLevelNameKey = getThinkingLevelNameKey; exports.isValidThinkingLevel = isValidThinkingLevel; exports.normalizeThinkingLevel = normalizeThinkingLevel; exports.RPC_CHANNELS = RPC_CHANNELS; exports.parseMentions = parseMentions; exports.resolveSkillMentions = resolveSkillMentions; exports.resolveSourceMentions = resolveSourceMentions; exports.resolvePathMentions = resolvePathMentions; exports.resolveFileMentions = resolveFileMentions; exports.stripAllMentions = stripAllMentions; exports.findMentionMatches = findMentionMatches;
