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

// packages/core/src/utils/xml.ts
init_esbuild_shims();
function escapeXml(text) {
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
}
__name(escapeXml, "escapeXml");
var XML_TAG_CANDIDATE_RE = /<[^>]*>/g;
function isSystemReminderTagIgnorable(char) {
  const codePoint = char.codePointAt(0);
  return codePoint === 173 || codePoint === 65279 || codePoint !== void 0 && (codePoint >= 0 && codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint >= 8203 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8288 && codePoint <= 8303 || codePoint >= 65024 && codePoint <= 65039);
}
__name(isSystemReminderTagIgnorable, "isSystemReminderTagIgnorable");
function normalizeSystemReminderCandidateTag(tag) {
  let normalized = "";
  for (const char of tag) {
    if (!isSystemReminderTagIgnorable(char)) {
      normalized += char;
    }
  }
  return normalized.toLowerCase();
}
__name(normalizeSystemReminderCandidateTag, "normalizeSystemReminderCandidateTag");
function getSystemReminderTagKind(tag) {
  const normalized = normalizeSystemReminderCandidateTag(tag);
  const match = /^<\s*(\/?)\s*system-reminder(?:\s+[^>]*)?\s*(\/?)\s*>$/.exec(
    normalized
  );
  if (!match) {
    return void 0;
  }
  return match[1] ? "closing" : "other";
}
__name(getSystemReminderTagKind, "getSystemReminderTagKind");
function escapeSystemReminderTag(tag) {
  const tagKind = getSystemReminderTagKind(tag);
  if (tagKind === "closing") {
    return "<\\/system-reminder>";
  }
  if (tagKind === "other") {
    return escapeXml(tag);
  }
  return tag;
}
__name(escapeSystemReminderTag, "escapeSystemReminderTag");
function escapeSystemReminderTags(text) {
  return text.replace(XML_TAG_CANDIDATE_RE, escapeSystemReminderTag);
}
__name(escapeSystemReminderTags, "escapeSystemReminderTags");

// packages/core/src/hooks/registerSkillHooks.ts
init_esbuild_shims();
var debugLogger = createDebugLogger("SKILL_HOOKS");
function registerSkillHooks(sessionHooksManager, sessionId, skill) {
  if (!skill.hooks) {
    debugLogger.debug(`Skill '${skill.name}' has no hooks to register`);
    return 0;
  }
  const hooksSettings = skill.hooks;
  let registeredCount = 0;
  for (const eventName of Object.keys(hooksSettings)) {
    const matchers = hooksSettings[eventName];
    if (!matchers) continue;
    for (const matcher of matchers) {
      const matcherPattern = matcher.matcher || "";
      for (const hook of matcher.hooks) {
        if (hook.type === "function" /* Function */) {
          debugLogger.debug(
            "Skipping function hook from skill (not supported in frontmatter)"
          );
          continue;
        }
        const hookConfig = prepareHookConfig(
          hook,
          skill.skillRoot
        );
        sessionHooksManager.addSessionHook(
          sessionId,
          eventName,
          matcherPattern,
          hookConfig,
          { skillRoot: skill.skillRoot }
        );
        registeredCount++;
        debugLogger.debug(
          `Registered hook for ${eventName} with matcher '${matcherPattern}' from skill '${skill.name}'`
        );
      }
    }
  }
  if (registeredCount > 0) {
    debugLogger.info(
      `Registered ${registeredCount} hooks from skill '${skill.name}'`
    );
  }
  return registeredCount;
}
__name(registerSkillHooks, "registerSkillHooks");
function prepareHookConfig(hook, skillRoot) {
  if (hook.type === "command" && skillRoot) {
    return {
      ...hook,
      env: {
        ...hook.env,
        QWEN_SKILL_ROOT: skillRoot
      }
    };
  }
  return hook;
}
__name(prepareHookConfig, "prepareHookConfig");

// packages/core/src/tools/skill-utils.ts
init_esbuild_shims();
function buildSkillLlmContent(baseDir, body) {
  return `Base directory for this skill: ${baseDir}
Important: ALWAYS resolve absolute paths from this base directory when working with skills.

${body}
`;
}
__name(buildSkillLlmContent, "buildSkillLlmContent");

export {
  escapeXml,
  escapeSystemReminderTags,
  registerSkillHooks,
  buildSkillLlmContent
};
/**
 * @license
 * Copyright 2025 Qwen
 * SPDX-License-Identifier: Apache-2.0
 */
/**
 * @license
 * Copyright 2026 Qwen Team
 * SPDX-License-Identifier: Apache-2.0
 */
