"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __esm = (fn, res) => function __init() {
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __commonJS = (cb, mod) => function __require() {
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// ../core/dist/file-utils.js
function getFileContent(path, encoding = "utf-8") {
  return fsPromises[name1 + name2](path, encoding);
}
function getFileContentSync(path, encoding = "utf-8") {
  return fs[`${name1 + name2}Sync`](path, encoding);
}
function getFileContentRaw(path) {
  return fsPromises[name1 + name2](path);
}
function getProcEnv() {
  return process["env"];
}
function getHomeDir() {
  return getProcEnv().HOME || (0, import_node_os.homedir)();
}
async function renameWithRetry(from, to, attempts = 5) {
  if (process.platform !== "win32") {
    await fsPromises.rename(from, to);
    return;
  }
  for (let i = 0; i < attempts; i++) {
    try {
      await fsPromises.rename(from, to);
      return;
    } catch (err) {
      const code = err.code;
      const transient = code === "EPERM" || code === "EACCES" || code === "EBUSY";
      if (!transient || i === attempts - 1)
        throw err;
      await new Promise((resolve10) => setTimeout(resolve10, 10 * 2 ** i));
    }
  }
}
async function atomicWriteJson(path, data) {
  await fsPromises.mkdir((0, import_node_path.dirname)(path), { recursive: true });
  const tmp = `${path}.${(0, import_node_crypto.randomBytes)(6).toString("hex")}.tmp`;
  try {
    await fsPromises.writeFile(tmp, `${JSON.stringify(data, null, 2)}
`, { mode: 384 });
    await renameWithRetry(tmp, path);
  } catch (err) {
    try {
      await fsPromises.unlink(tmp);
    } catch {
    }
    throw err;
  }
}
async function pruneOrphanedTmpFiles(resolvedDir, maxAgeMs = 3e5) {
  try {
    const entries = await fsPromises.readdir(resolvedDir);
    const now = Date.now();
    for (const entry of entries) {
      if (!entry.endsWith(".tmp"))
        continue;
      try {
        const fullPath = (0, import_node_path.join)(resolvedDir, entry);
        const s = await fsPromises.stat(fullPath);
        if (now - s.mtimeMs > maxAgeMs) {
          await fsPromises.unlink(fullPath);
        }
      } catch {
      }
    }
  } catch {
  }
  await pruneOrphanedModelDownloads((0, import_node_path.join)(resolvedDir, "models", ".download"));
}
async function pruneOrphanedModelDownloads(stagingDir, maxAgeMs = 60 * 60 * 1e3) {
  let entries;
  try {
    entries = await fsPromises.readdir(stagingDir);
  } catch {
    return;
  }
  const now = Date.now();
  for (const entry of entries) {
    const fullPath = (0, import_node_path.join)(stagingDir, entry);
    const isArchive = entry.endsWith(".tar.gz");
    const isPartial = entry.endsWith(".partial");
    const isStaging = entry.startsWith("stage-");
    if (!isArchive && !isPartial && !isStaging)
      continue;
    try {
      const s = await fsPromises.stat(fullPath);
      if (now - s.mtimeMs <= maxAgeMs)
        continue;
      if (s.isDirectory()) {
        await fsPromises.rm(fullPath, { recursive: true, force: true });
      } else {
        await fsPromises.unlink(fullPath);
      }
    } catch {
    }
  }
}
async function removeStaleFileLock(lockPath, staleAgeMs) {
  try {
    const s = await fsPromises.stat(lockPath);
    if (Date.now() - s.mtimeMs < staleAgeMs)
      return;
    await fsPromises.rmdir(lockPath);
  } catch {
  }
}
async function acquireFileLock(filePath, timeoutMs = 250, staleAgeMs = 3e4) {
  const lockPath = `${filePath}.lock`;
  const deadline = Date.now() + timeoutMs;
  while (true) {
    try {
      await fsPromises.mkdir(lockPath);
      return async () => {
        try {
          await fsPromises.rmdir(lockPath);
        } catch {
        }
      };
    } catch {
      await removeStaleFileLock(lockPath, staleAgeMs);
      const remainingMs = deadline - Date.now();
      if (remainingMs <= 0)
        return void 0;
      await (0, import_promises.setTimeout)(Math.min(50, remainingMs));
    }
  }
}
async function withFileLock(filePath, callback) {
  const release = await acquireFileLock(filePath);
  if (!release)
    return;
  try {
    return await callback();
  } finally {
    await release();
  }
}
var import_node_crypto, fs, fsPromises, import_node_os, import_node_path, import_promises, name1, name2;
var init_file_utils = __esm({
  "../core/dist/file-utils.js"() {
    "use strict";
    import_node_crypto = require("node:crypto");
    fs = __toESM(require("node:fs"), 1);
    fsPromises = __toESM(require("node:fs/promises"), 1);
    import_node_os = require("node:os");
    import_node_path = require("node:path");
    import_promises = require("node:timers/promises");
    name1 = "read";
    name2 = "File";
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
var util, objectUtil, ZodParsedType, getParsedType;
var init_util = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js"() {
    (function(util2) {
      util2.assertEqual = (_) => {
      };
      function assertIs(_arg) {
      }
      util2.assertIs = assertIs;
      function assertNever(_x) {
        throw new Error();
      }
      util2.assertNever = assertNever;
      util2.arrayToEnum = (items) => {
        const obj = {};
        for (const item of items) {
          obj[item] = item;
        }
        return obj;
      };
      util2.getValidEnumValues = (obj) => {
        const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
        const filtered = {};
        for (const k of validKeys) {
          filtered[k] = obj[k];
        }
        return util2.objectValues(filtered);
      };
      util2.objectValues = (obj) => {
        return util2.objectKeys(obj).map(function(e) {
          return obj[e];
        });
      };
      util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
        const keys = [];
        for (const key in object) {
          if (Object.prototype.hasOwnProperty.call(object, key)) {
            keys.push(key);
          }
        }
        return keys;
      };
      util2.find = (arr, checker) => {
        for (const item of arr) {
          if (checker(item))
            return item;
        }
        return void 0;
      };
      util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
      function joinValues(array, separator = " | ") {
        return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
      }
      util2.joinValues = joinValues;
      util2.jsonStringifyReplacer = (_, value) => {
        if (typeof value === "bigint") {
          return value.toString();
        }
        return value;
      };
    })(util || (util = {}));
    (function(objectUtil2) {
      objectUtil2.mergeShapes = (first, second) => {
        return {
          ...first,
          ...second
          // second overwrites first
        };
      };
    })(objectUtil || (objectUtil = {}));
    ZodParsedType = util.arrayToEnum([
      "string",
      "nan",
      "number",
      "integer",
      "float",
      "boolean",
      "date",
      "bigint",
      "symbol",
      "function",
      "undefined",
      "null",
      "array",
      "object",
      "unknown",
      "promise",
      "void",
      "never",
      "map",
      "set"
    ]);
    getParsedType = (data) => {
      const t = typeof data;
      switch (t) {
        case "undefined":
          return ZodParsedType.undefined;
        case "string":
          return ZodParsedType.string;
        case "number":
          return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
        case "boolean":
          return ZodParsedType.boolean;
        case "function":
          return ZodParsedType.function;
        case "bigint":
          return ZodParsedType.bigint;
        case "symbol":
          return ZodParsedType.symbol;
        case "object":
          if (Array.isArray(data)) {
            return ZodParsedType.array;
          }
          if (data === null) {
            return ZodParsedType.null;
          }
          if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
            return ZodParsedType.promise;
          }
          if (typeof Map !== "undefined" && data instanceof Map) {
            return ZodParsedType.map;
          }
          if (typeof Set !== "undefined" && data instanceof Set) {
            return ZodParsedType.set;
          }
          if (typeof Date !== "undefined" && data instanceof Date) {
            return ZodParsedType.date;
          }
          return ZodParsedType.object;
        default:
          return ZodParsedType.unknown;
      }
    };
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
var ZodIssueCode, quotelessJson, ZodError;
var init_ZodError = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js"() {
    init_util();
    ZodIssueCode = util.arrayToEnum([
      "invalid_type",
      "invalid_literal",
      "custom",
      "invalid_union",
      "invalid_union_discriminator",
      "invalid_enum_value",
      "unrecognized_keys",
      "invalid_arguments",
      "invalid_return_type",
      "invalid_date",
      "invalid_string",
      "too_small",
      "too_big",
      "invalid_intersection_types",
      "not_multiple_of",
      "not_finite"
    ]);
    quotelessJson = (obj) => {
      const json = JSON.stringify(obj, null, 2);
      return json.replace(/"([^"]+)":/g, "$1:");
    };
    ZodError = class _ZodError extends Error {
      get errors() {
        return this.issues;
      }
      constructor(issues) {
        super();
        this.issues = [];
        this.addIssue = (sub) => {
          this.issues = [...this.issues, sub];
        };
        this.addIssues = (subs = []) => {
          this.issues = [...this.issues, ...subs];
        };
        const actualProto = new.target.prototype;
        if (Object.setPrototypeOf) {
          Object.setPrototypeOf(this, actualProto);
        } else {
          this.__proto__ = actualProto;
        }
        this.name = "ZodError";
        this.issues = issues;
      }
      format(_mapper) {
        const mapper = _mapper || function(issue) {
          return issue.message;
        };
        const fieldErrors = { _errors: [] };
        const processError = (error) => {
          for (const issue of error.issues) {
            if (issue.code === "invalid_union") {
              issue.unionErrors.map(processError);
            } else if (issue.code === "invalid_return_type") {
              processError(issue.returnTypeError);
            } else if (issue.code === "invalid_arguments") {
              processError(issue.argumentsError);
            } else if (issue.path.length === 0) {
              fieldErrors._errors.push(mapper(issue));
            } else {
              let curr = fieldErrors;
              let i = 0;
              while (i < issue.path.length) {
                const el = issue.path[i];
                const terminal = i === issue.path.length - 1;
                if (!terminal) {
                  curr[el] = curr[el] || { _errors: [] };
                } else {
                  curr[el] = curr[el] || { _errors: [] };
                  curr[el]._errors.push(mapper(issue));
                }
                curr = curr[el];
                i++;
              }
            }
          }
        };
        processError(this);
        return fieldErrors;
      }
      static assert(value) {
        if (!(value instanceof _ZodError)) {
          throw new Error(`Not a ZodError: ${value}`);
        }
      }
      toString() {
        return this.message;
      }
      get message() {
        return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
      }
      get isEmpty() {
        return this.issues.length === 0;
      }
      flatten(mapper = (issue) => issue.message) {
        const fieldErrors = {};
        const formErrors = [];
        for (const sub of this.issues) {
          if (sub.path.length > 0) {
            const firstEl = sub.path[0];
            fieldErrors[firstEl] = fieldErrors[firstEl] || [];
            fieldErrors[firstEl].push(mapper(sub));
          } else {
            formErrors.push(mapper(sub));
          }
        }
        return { formErrors, fieldErrors };
      }
      get formErrors() {
        return this.flatten();
      }
    };
    ZodError.create = (issues) => {
      const error = new ZodError(issues);
      return error;
    };
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
var errorMap, en_default;
var init_en = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js"() {
    init_ZodError();
    init_util();
    errorMap = (issue, _ctx) => {
      let message;
      switch (issue.code) {
        case ZodIssueCode.invalid_type:
          if (issue.received === ZodParsedType.undefined) {
            message = "Required";
          } else {
            message = `Expected ${issue.expected}, received ${issue.received}`;
          }
          break;
        case ZodIssueCode.invalid_literal:
          message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
          break;
        case ZodIssueCode.unrecognized_keys:
          message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
          break;
        case ZodIssueCode.invalid_union:
          message = `Invalid input`;
          break;
        case ZodIssueCode.invalid_union_discriminator:
          message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
          break;
        case ZodIssueCode.invalid_enum_value:
          message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
          break;
        case ZodIssueCode.invalid_arguments:
          message = `Invalid function arguments`;
          break;
        case ZodIssueCode.invalid_return_type:
          message = `Invalid function return type`;
          break;
        case ZodIssueCode.invalid_date:
          message = `Invalid date`;
          break;
        case ZodIssueCode.invalid_string:
          if (typeof issue.validation === "object") {
            if ("includes" in issue.validation) {
              message = `Invalid input: must include "${issue.validation.includes}"`;
              if (typeof issue.validation.position === "number") {
                message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
              }
            } else if ("startsWith" in issue.validation) {
              message = `Invalid input: must start with "${issue.validation.startsWith}"`;
            } else if ("endsWith" in issue.validation) {
              message = `Invalid input: must end with "${issue.validation.endsWith}"`;
            } else {
              util.assertNever(issue.validation);
            }
          } else if (issue.validation !== "regex") {
            message = `Invalid ${issue.validation}`;
          } else {
            message = "Invalid";
          }
          break;
        case ZodIssueCode.too_small:
          if (issue.type === "array")
            message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
          else if (issue.type === "string")
            message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
          else if (issue.type === "number")
            message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
          else if (issue.type === "bigint")
            message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
          else if (issue.type === "date")
            message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
          else
            message = "Invalid input";
          break;
        case ZodIssueCode.too_big:
          if (issue.type === "array")
            message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
          else if (issue.type === "string")
            message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
          else if (issue.type === "number")
            message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
          else if (issue.type === "bigint")
            message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
          else if (issue.type === "date")
            message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
          else
            message = "Invalid input";
          break;
        case ZodIssueCode.custom:
          message = `Invalid input`;
          break;
        case ZodIssueCode.invalid_intersection_types:
          message = `Intersection results could not be merged`;
          break;
        case ZodIssueCode.not_multiple_of:
          message = `Number must be a multiple of ${issue.multipleOf}`;
          break;
        case ZodIssueCode.not_finite:
          message = "Number must be finite";
          break;
        default:
          message = _ctx.defaultError;
          util.assertNever(issue);
      }
      return { message };
    };
    en_default = errorMap;
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
function setErrorMap(map) {
  overrideErrorMap = map;
}
function getErrorMap() {
  return overrideErrorMap;
}
var overrideErrorMap;
var init_errors = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js"() {
    init_en();
    overrideErrorMap = en_default;
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
function addIssueToContext(ctx, issueData) {
  const overrideMap = getErrorMap();
  const issue = makeIssue({
    issueData,
    data: ctx.data,
    path: ctx.path,
    errorMaps: [
      ctx.common.contextualErrorMap,
      // contextual error map is first priority
      ctx.schemaErrorMap,
      // then schema-bound map if available
      overrideMap,
      // then global override map
      overrideMap === en_default ? void 0 : en_default
      // then global default map
    ].filter((x) => !!x)
  });
  ctx.common.issues.push(issue);
}
var makeIssue, EMPTY_PATH, ParseStatus, INVALID, DIRTY, OK, isAborted, isDirty, isValid, isAsync;
var init_parseUtil = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js"() {
    init_errors();
    init_en();
    makeIssue = (params) => {
      const { data, path, errorMaps, issueData } = params;
      const fullPath = [...path, ...issueData.path || []];
      const fullIssue = {
        ...issueData,
        path: fullPath
      };
      if (issueData.message !== void 0) {
        return {
          ...issueData,
          path: fullPath,
          message: issueData.message
        };
      }
      let errorMessage = "";
      const maps = errorMaps.filter((m) => !!m).slice().reverse();
      for (const map of maps) {
        errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
      }
      return {
        ...issueData,
        path: fullPath,
        message: errorMessage
      };
    };
    EMPTY_PATH = [];
    ParseStatus = class _ParseStatus {
      constructor() {
        this.value = "valid";
      }
      dirty() {
        if (this.value === "valid")
          this.value = "dirty";
      }
      abort() {
        if (this.value !== "aborted")
          this.value = "aborted";
      }
      static mergeArray(status, results) {
        const arrayValue = [];
        for (const s of results) {
          if (s.status === "aborted")
            return INVALID;
          if (s.status === "dirty")
            status.dirty();
          arrayValue.push(s.value);
        }
        return { status: status.value, value: arrayValue };
      }
      static async mergeObjectAsync(status, pairs) {
        const syncPairs = [];
        for (const pair of pairs) {
          const key = await pair.key;
          const value = await pair.value;
          syncPairs.push({
            key,
            value
          });
        }
        return _ParseStatus.mergeObjectSync(status, syncPairs);
      }
      static mergeObjectSync(status, pairs) {
        const finalObject = {};
        for (const pair of pairs) {
          const { key, value } = pair;
          if (key.status === "aborted")
            return INVALID;
          if (value.status === "aborted")
            return INVALID;
          if (key.status === "dirty")
            status.dirty();
          if (value.status === "dirty")
            status.dirty();
          if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
            finalObject[key.value] = value.value;
          }
        }
        return { status: status.value, value: finalObject };
      }
    };
    INVALID = Object.freeze({
      status: "aborted"
    });
    DIRTY = (value) => ({ status: "dirty", value });
    OK = (value) => ({ status: "valid", value });
    isAborted = (x) => x.status === "aborted";
    isDirty = (x) => x.status === "dirty";
    isValid = (x) => x.status === "valid";
    isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/typeAliases.js
var init_typeAliases = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/typeAliases.js"() {
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
var errorUtil;
var init_errorUtil = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js"() {
    (function(errorUtil2) {
      errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
      errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
    })(errorUtil || (errorUtil = {}));
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
function processCreateParams(params) {
  if (!params)
    return {};
  const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
  if (errorMap2 && (invalid_type_error || required_error)) {
    throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
  }
  if (errorMap2)
    return { errorMap: errorMap2, description };
  const customMap = (iss, ctx) => {
    const { message } = params;
    if (iss.code === "invalid_enum_value") {
      return { message: message ?? ctx.defaultError };
    }
    if (typeof ctx.data === "undefined") {
      return { message: message ?? required_error ?? ctx.defaultError };
    }
    if (iss.code !== "invalid_type")
      return { message: ctx.defaultError };
    return { message: message ?? invalid_type_error ?? ctx.defaultError };
  };
  return { errorMap: customMap, description };
}
function timeRegexSource(args) {
  let secondsRegexSource = `[0-5]\\d`;
  if (args.precision) {
    secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
  } else if (args.precision == null) {
    secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
  }
  const secondsQuantifier = args.precision ? "+" : "?";
  return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
}
function timeRegex(args) {
  return new RegExp(`^${timeRegexSource(args)}$`);
}
function datetimeRegex(args) {
  let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
  const opts = [];
  opts.push(args.local ? `Z?` : `Z`);
  if (args.offset)
    opts.push(`([+-]\\d{2}:?\\d{2})`);
  regex = `${regex}(${opts.join("|")})`;
  return new RegExp(`^${regex}$`);
}
function isValidIP(ip, version) {
  if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
    return true;
  }
  if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
    return true;
  }
  return false;
}
function isValidJWT(jwt, alg) {
  if (!jwtRegex.test(jwt))
    return false;
  try {
    const [header] = jwt.split(".");
    if (!header)
      return false;
    const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
    const decoded = JSON.parse(atob(base64));
    if (typeof decoded !== "object" || decoded === null)
      return false;
    if ("typ" in decoded && decoded?.typ !== "JWT")
      return false;
    if (!decoded.alg)
      return false;
    if (alg && decoded.alg !== alg)
      return false;
    return true;
  } catch {
    return false;
  }
}
function isValidCidr(ip, version) {
  if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
    return true;
  }
  if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
    return true;
  }
  return false;
}
function floatSafeRemainder(val, step) {
  const valDecCount = (val.toString().split(".")[1] || "").length;
  const stepDecCount = (step.toString().split(".")[1] || "").length;
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
  const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
  return valInt % stepInt / 10 ** decCount;
}
function deepPartialify(schema) {
  if (schema instanceof ZodObject) {
    const newShape = {};
    for (const key in schema.shape) {
      const fieldSchema = schema.shape[key];
      newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
    }
    return new ZodObject({
      ...schema._def,
      shape: () => newShape
    });
  } else if (schema instanceof ZodArray) {
    return new ZodArray({
      ...schema._def,
      type: deepPartialify(schema.element)
    });
  } else if (schema instanceof ZodOptional) {
    return ZodOptional.create(deepPartialify(schema.unwrap()));
  } else if (schema instanceof ZodNullable) {
    return ZodNullable.create(deepPartialify(schema.unwrap()));
  } else if (schema instanceof ZodTuple) {
    return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
  } else {
    return schema;
  }
}
function mergeValues(a, b) {
  const aType = getParsedType(a);
  const bType = getParsedType(b);
  if (a === b) {
    return { valid: true, data: a };
  } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
    const bKeys = util.objectKeys(b);
    const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
    const newObj = { ...a, ...b };
    for (const key of sharedKeys) {
      const sharedValue = mergeValues(a[key], b[key]);
      if (!sharedValue.valid) {
        return { valid: false };
      }
      newObj[key] = sharedValue.data;
    }
    return { valid: true, data: newObj };
  } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
    if (a.length !== b.length) {
      return { valid: false };
    }
    const newArray = [];
    for (let index = 0; index < a.length; index++) {
      const itemA = a[index];
      const itemB = b[index];
      const sharedValue = mergeValues(itemA, itemB);
      if (!sharedValue.valid) {
        return { valid: false };
      }
      newArray.push(sharedValue.data);
    }
    return { valid: true, data: newArray };
  } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
    return { valid: true, data: a };
  } else {
    return { valid: false };
  }
}
function createZodEnum(values, params) {
  return new ZodEnum({
    values,
    typeName: ZodFirstPartyTypeKind.ZodEnum,
    ...processCreateParams(params)
  });
}
function cleanParams(params, data) {
  const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
  const p2 = typeof p === "string" ? { message: p } : p;
  return p2;
}
function custom(check, _params = {}, fatal) {
  if (check)
    return ZodAny.create().superRefine((data, ctx) => {
      const r = check(data);
      if (r instanceof Promise) {
        return r.then((r2) => {
          if (!r2) {
            const params = cleanParams(_params, data);
            const _fatal = params.fatal ?? fatal ?? true;
            ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
          }
        });
      }
      if (!r) {
        const params = cleanParams(_params, data);
        const _fatal = params.fatal ?? fatal ?? true;
        ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
      }
      return;
    });
  return ZodAny.create();
}
var ParseInputLazyPath, handleResult, ZodType, cuidRegex, cuid2Regex, ulidRegex, uuidRegex, nanoidRegex, jwtRegex, durationRegex, emailRegex, _emojiRegex, emojiRegex, ipv4Regex, ipv4CidrRegex, ipv6Regex, ipv6CidrRegex, base64Regex, base64urlRegex, dateRegexSource, dateRegex, ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodSymbol, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodVoid, ZodArray, ZodObject, ZodUnion, getDiscriminator, ZodDiscriminatedUnion, ZodIntersection, ZodTuple, ZodRecord, ZodMap, ZodSet, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodNativeEnum, ZodPromise, ZodEffects, ZodOptional, ZodNullable, ZodDefault, ZodCatch, ZodNaN, BRAND, ZodBranded, ZodPipeline, ZodReadonly, late, ZodFirstPartyTypeKind, instanceOfType, stringType, numberType, nanType, bigIntType, booleanType, dateType, symbolType, undefinedType, nullType, anyType, unknownType, neverType, voidType, arrayType, objectType, strictObjectType, unionType, discriminatedUnionType, intersectionType, tupleType, recordType, mapType, setType, functionType, lazyType, literalType, enumType, nativeEnumType, promiseType, effectsType, optionalType, nullableType, preprocessType, pipelineType, ostring, onumber, oboolean, coerce, NEVER;
var init_types = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js"() {
    init_ZodError();
    init_errors();
    init_errorUtil();
    init_parseUtil();
    init_util();
    ParseInputLazyPath = class {
      constructor(parent, value, path, key) {
        this._cachedPath = [];
        this.parent = parent;
        this.data = value;
        this._path = path;
        this._key = key;
      }
      get path() {
        if (!this._cachedPath.length) {
          if (Array.isArray(this._key)) {
            this._cachedPath.push(...this._path, ...this._key);
          } else {
            this._cachedPath.push(...this._path, this._key);
          }
        }
        return this._cachedPath;
      }
    };
    handleResult = (ctx, result) => {
      if (isValid(result)) {
        return { success: true, data: result.value };
      } else {
        if (!ctx.common.issues.length) {
          throw new Error("Validation failed but no issues detected.");
        }
        return {
          success: false,
          get error() {
            if (this._error)
              return this._error;
            const error = new ZodError(ctx.common.issues);
            this._error = error;
            return this._error;
          }
        };
      }
    };
    ZodType = class {
      get description() {
        return this._def.description;
      }
      _getType(input) {
        return getParsedType(input.data);
      }
      _getOrReturnCtx(input, ctx) {
        return ctx || {
          common: input.parent.common,
          data: input.data,
          parsedType: getParsedType(input.data),
          schemaErrorMap: this._def.errorMap,
          path: input.path,
          parent: input.parent
        };
      }
      _processInputParams(input) {
        return {
          status: new ParseStatus(),
          ctx: {
            common: input.parent.common,
            data: input.data,
            parsedType: getParsedType(input.data),
            schemaErrorMap: this._def.errorMap,
            path: input.path,
            parent: input.parent
          }
        };
      }
      _parseSync(input) {
        const result = this._parse(input);
        if (isAsync(result)) {
          throw new Error("Synchronous parse encountered promise.");
        }
        return result;
      }
      _parseAsync(input) {
        const result = this._parse(input);
        return Promise.resolve(result);
      }
      parse(data, params) {
        const result = this.safeParse(data, params);
        if (result.success)
          return result.data;
        throw result.error;
      }
      safeParse(data, params) {
        const ctx = {
          common: {
            issues: [],
            async: params?.async ?? false,
            contextualErrorMap: params?.errorMap
          },
          path: params?.path || [],
          schemaErrorMap: this._def.errorMap,
          parent: null,
          data,
          parsedType: getParsedType(data)
        };
        const result = this._parseSync({ data, path: ctx.path, parent: ctx });
        return handleResult(ctx, result);
      }
      "~validate"(data) {
        const ctx = {
          common: {
            issues: [],
            async: !!this["~standard"].async
          },
          path: [],
          schemaErrorMap: this._def.errorMap,
          parent: null,
          data,
          parsedType: getParsedType(data)
        };
        if (!this["~standard"].async) {
          try {
            const result = this._parseSync({ data, path: [], parent: ctx });
            return isValid(result) ? {
              value: result.value
            } : {
              issues: ctx.common.issues
            };
          } catch (err) {
            if (err?.message?.toLowerCase()?.includes("encountered")) {
              this["~standard"].async = true;
            }
            ctx.common = {
              issues: [],
              async: true
            };
          }
        }
        return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
          value: result.value
        } : {
          issues: ctx.common.issues
        });
      }
      async parseAsync(data, params) {
        const result = await this.safeParseAsync(data, params);
        if (result.success)
          return result.data;
        throw result.error;
      }
      async safeParseAsync(data, params) {
        const ctx = {
          common: {
            issues: [],
            contextualErrorMap: params?.errorMap,
            async: true
          },
          path: params?.path || [],
          schemaErrorMap: this._def.errorMap,
          parent: null,
          data,
          parsedType: getParsedType(data)
        };
        const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
        const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
        return handleResult(ctx, result);
      }
      refine(check, message) {
        const getIssueProperties = (val) => {
          if (typeof message === "string" || typeof message === "undefined") {
            return { message };
          } else if (typeof message === "function") {
            return message(val);
          } else {
            return message;
          }
        };
        return this._refinement((val, ctx) => {
          const result = check(val);
          const setError = () => ctx.addIssue({
            code: ZodIssueCode.custom,
            ...getIssueProperties(val)
          });
          if (typeof Promise !== "undefined" && result instanceof Promise) {
            return result.then((data) => {
              if (!data) {
                setError();
                return false;
              } else {
                return true;
              }
            });
          }
          if (!result) {
            setError();
            return false;
          } else {
            return true;
          }
        });
      }
      refinement(check, refinementData) {
        return this._refinement((val, ctx) => {
          if (!check(val)) {
            ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
            return false;
          } else {
            return true;
          }
        });
      }
      _refinement(refinement) {
        return new ZodEffects({
          schema: this,
          typeName: ZodFirstPartyTypeKind.ZodEffects,
          effect: { type: "refinement", refinement }
        });
      }
      superRefine(refinement) {
        return this._refinement(refinement);
      }
      constructor(def) {
        this.spa = this.safeParseAsync;
        this._def = def;
        this.parse = this.parse.bind(this);
        this.safeParse = this.safeParse.bind(this);
        this.parseAsync = this.parseAsync.bind(this);
        this.safeParseAsync = this.safeParseAsync.bind(this);
        this.spa = this.spa.bind(this);
        this.refine = this.refine.bind(this);
        this.refinement = this.refinement.bind(this);
        this.superRefine = this.superRefine.bind(this);
        this.optional = this.optional.bind(this);
        this.nullable = this.nullable.bind(this);
        this.nullish = this.nullish.bind(this);
        this.array = this.array.bind(this);
        this.promise = this.promise.bind(this);
        this.or = this.or.bind(this);
        this.and = this.and.bind(this);
        this.transform = this.transform.bind(this);
        this.brand = this.brand.bind(this);
        this.default = this.default.bind(this);
        this.catch = this.catch.bind(this);
        this.describe = this.describe.bind(this);
        this.pipe = this.pipe.bind(this);
        this.readonly = this.readonly.bind(this);
        this.isNullable = this.isNullable.bind(this);
        this.isOptional = this.isOptional.bind(this);
        this["~standard"] = {
          version: 1,
          vendor: "zod",
          validate: (data) => this["~validate"](data)
        };
      }
      optional() {
        return ZodOptional.create(this, this._def);
      }
      nullable() {
        return ZodNullable.create(this, this._def);
      }
      nullish() {
        return this.nullable().optional();
      }
      array() {
        return ZodArray.create(this);
      }
      promise() {
        return ZodPromise.create(this, this._def);
      }
      or(option) {
        return ZodUnion.create([this, option], this._def);
      }
      and(incoming) {
        return ZodIntersection.create(this, incoming, this._def);
      }
      transform(transform) {
        return new ZodEffects({
          ...processCreateParams(this._def),
          schema: this,
          typeName: ZodFirstPartyTypeKind.ZodEffects,
          effect: { type: "transform", transform }
        });
      }
      default(def) {
        const defaultValueFunc = typeof def === "function" ? def : () => def;
        return new ZodDefault({
          ...processCreateParams(this._def),
          innerType: this,
          defaultValue: defaultValueFunc,
          typeName: ZodFirstPartyTypeKind.ZodDefault
        });
      }
      brand() {
        return new ZodBranded({
          typeName: ZodFirstPartyTypeKind.ZodBranded,
          type: this,
          ...processCreateParams(this._def)
        });
      }
      catch(def) {
        const catchValueFunc = typeof def === "function" ? def : () => def;
        return new ZodCatch({
          ...processCreateParams(this._def),
          innerType: this,
          catchValue: catchValueFunc,
          typeName: ZodFirstPartyTypeKind.ZodCatch
        });
      }
      describe(description) {
        const This = this.constructor;
        return new This({
          ...this._def,
          description
        });
      }
      pipe(target) {
        return ZodPipeline.create(this, target);
      }
      readonly() {
        return ZodReadonly.create(this);
      }
      isOptional() {
        return this.safeParse(void 0).success;
      }
      isNullable() {
        return this.safeParse(null).success;
      }
    };
    cuidRegex = /^c[^\s-]{8,}$/i;
    cuid2Regex = /^[0-9a-z]+$/;
    ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
    uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
    nanoidRegex = /^[a-z0-9_-]{21}$/i;
    jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
    durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
    emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
    _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
    ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
    ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
    ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
    ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
    base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
    base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
    dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
    dateRegex = new RegExp(`^${dateRegexSource}$`);
    ZodString = class _ZodString extends ZodType {
      _parse(input) {
        if (this._def.coerce) {
          input.data = String(input.data);
        }
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.string) {
          const ctx2 = this._getOrReturnCtx(input);
          addIssueToContext(ctx2, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.string,
            received: ctx2.parsedType
          });
          return INVALID;
        }
        const status = new ParseStatus();
        let ctx = void 0;
        for (const check of this._def.checks) {
          if (check.kind === "min") {
            if (input.data.length < check.value) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_small,
                minimum: check.value,
                type: "string",
                inclusive: true,
                exact: false,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "max") {
            if (input.data.length > check.value) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_big,
                maximum: check.value,
                type: "string",
                inclusive: true,
                exact: false,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "length") {
            const tooBig = input.data.length > check.value;
            const tooSmall = input.data.length < check.value;
            if (tooBig || tooSmall) {
              ctx = this._getOrReturnCtx(input, ctx);
              if (tooBig) {
                addIssueToContext(ctx, {
                  code: ZodIssueCode.too_big,
                  maximum: check.value,
                  type: "string",
                  inclusive: true,
                  exact: true,
                  message: check.message
                });
              } else if (tooSmall) {
                addIssueToContext(ctx, {
                  code: ZodIssueCode.too_small,
                  minimum: check.value,
                  type: "string",
                  inclusive: true,
                  exact: true,
                  message: check.message
                });
              }
              status.dirty();
            }
          } else if (check.kind === "email") {
            if (!emailRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "email",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "emoji") {
            if (!emojiRegex) {
              emojiRegex = new RegExp(_emojiRegex, "u");
            }
            if (!emojiRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "emoji",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "uuid") {
            if (!uuidRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "uuid",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "nanoid") {
            if (!nanoidRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "nanoid",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "cuid") {
            if (!cuidRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "cuid",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "cuid2") {
            if (!cuid2Regex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "cuid2",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "ulid") {
            if (!ulidRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "ulid",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "url") {
            try {
              new URL(input.data);
            } catch {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "url",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "regex") {
            check.regex.lastIndex = 0;
            const testResult = check.regex.test(input.data);
            if (!testResult) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "regex",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "trim") {
            input.data = input.data.trim();
          } else if (check.kind === "includes") {
            if (!input.data.includes(check.value, check.position)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.invalid_string,
                validation: { includes: check.value, position: check.position },
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "toLowerCase") {
            input.data = input.data.toLowerCase();
          } else if (check.kind === "toUpperCase") {
            input.data = input.data.toUpperCase();
          } else if (check.kind === "startsWith") {
            if (!input.data.startsWith(check.value)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.invalid_string,
                validation: { startsWith: check.value },
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "endsWith") {
            if (!input.data.endsWith(check.value)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.invalid_string,
                validation: { endsWith: check.value },
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "datetime") {
            const regex = datetimeRegex(check);
            if (!regex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.invalid_string,
                validation: "datetime",
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "date") {
            const regex = dateRegex;
            if (!regex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.invalid_string,
                validation: "date",
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "time") {
            const regex = timeRegex(check);
            if (!regex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.invalid_string,
                validation: "time",
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "duration") {
            if (!durationRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "duration",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "ip") {
            if (!isValidIP(input.data, check.version)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "ip",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "jwt") {
            if (!isValidJWT(input.data, check.alg)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "jwt",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "cidr") {
            if (!isValidCidr(input.data, check.version)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "cidr",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "base64") {
            if (!base64Regex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "base64",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "base64url") {
            if (!base64urlRegex.test(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                validation: "base64url",
                code: ZodIssueCode.invalid_string,
                message: check.message
              });
              status.dirty();
            }
          } else {
            util.assertNever(check);
          }
        }
        return { status: status.value, value: input.data };
      }
      _regex(regex, validation, message) {
        return this.refinement((data) => regex.test(data), {
          validation,
          code: ZodIssueCode.invalid_string,
          ...errorUtil.errToObj(message)
        });
      }
      _addCheck(check) {
        return new _ZodString({
          ...this._def,
          checks: [...this._def.checks, check]
        });
      }
      email(message) {
        return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
      }
      url(message) {
        return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
      }
      emoji(message) {
        return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
      }
      uuid(message) {
        return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
      }
      nanoid(message) {
        return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
      }
      cuid(message) {
        return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
      }
      cuid2(message) {
        return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
      }
      ulid(message) {
        return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
      }
      base64(message) {
        return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
      }
      base64url(message) {
        return this._addCheck({
          kind: "base64url",
          ...errorUtil.errToObj(message)
        });
      }
      jwt(options) {
        return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
      }
      ip(options) {
        return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
      }
      cidr(options) {
        return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
      }
      datetime(options) {
        if (typeof options === "string") {
          return this._addCheck({
            kind: "datetime",
            precision: null,
            offset: false,
            local: false,
            message: options
          });
        }
        return this._addCheck({
          kind: "datetime",
          precision: typeof options?.precision === "undefined" ? null : options?.precision,
          offset: options?.offset ?? false,
          local: options?.local ?? false,
          ...errorUtil.errToObj(options?.message)
        });
      }
      date(message) {
        return this._addCheck({ kind: "date", message });
      }
      time(options) {
        if (typeof options === "string") {
          return this._addCheck({
            kind: "time",
            precision: null,
            message: options
          });
        }
        return this._addCheck({
          kind: "time",
          precision: typeof options?.precision === "undefined" ? null : options?.precision,
          ...errorUtil.errToObj(options?.message)
        });
      }
      duration(message) {
        return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
      }
      regex(regex, message) {
        return this._addCheck({
          kind: "regex",
          regex,
          ...errorUtil.errToObj(message)
        });
      }
      includes(value, options) {
        return this._addCheck({
          kind: "includes",
          value,
          position: options?.position,
          ...errorUtil.errToObj(options?.message)
        });
      }
      startsWith(value, message) {
        return this._addCheck({
          kind: "startsWith",
          value,
          ...errorUtil.errToObj(message)
        });
      }
      endsWith(value, message) {
        return this._addCheck({
          kind: "endsWith",
          value,
          ...errorUtil.errToObj(message)
        });
      }
      min(minLength, message) {
        return this._addCheck({
          kind: "min",
          value: minLength,
          ...errorUtil.errToObj(message)
        });
      }
      max(maxLength, message) {
        return this._addCheck({
          kind: "max",
          value: maxLength,
          ...errorUtil.errToObj(message)
        });
      }
      length(len, message) {
        return this._addCheck({
          kind: "length",
          value: len,
          ...errorUtil.errToObj(message)
        });
      }
      /**
       * Equivalent to `.min(1)`
       */
      nonempty(message) {
        return this.min(1, errorUtil.errToObj(message));
      }
      trim() {
        return new _ZodString({
          ...this._def,
          checks: [...this._def.checks, { kind: "trim" }]
        });
      }
      toLowerCase() {
        return new _ZodString({
          ...this._def,
          checks: [...this._def.checks, { kind: "toLowerCase" }]
        });
      }
      toUpperCase() {
        return new _ZodString({
          ...this._def,
          checks: [...this._def.checks, { kind: "toUpperCase" }]
        });
      }
      get isDatetime() {
        return !!this._def.checks.find((ch) => ch.kind === "datetime");
      }
      get isDate() {
        return !!this._def.checks.find((ch) => ch.kind === "date");
      }
      get isTime() {
        return !!this._def.checks.find((ch) => ch.kind === "time");
      }
      get isDuration() {
        return !!this._def.checks.find((ch) => ch.kind === "duration");
      }
      get isEmail() {
        return !!this._def.checks.find((ch) => ch.kind === "email");
      }
      get isURL() {
        return !!this._def.checks.find((ch) => ch.kind === "url");
      }
      get isEmoji() {
        return !!this._def.checks.find((ch) => ch.kind === "emoji");
      }
      get isUUID() {
        return !!this._def.checks.find((ch) => ch.kind === "uuid");
      }
      get isNANOID() {
        return !!this._def.checks.find((ch) => ch.kind === "nanoid");
      }
      get isCUID() {
        return !!this._def.checks.find((ch) => ch.kind === "cuid");
      }
      get isCUID2() {
        return !!this._def.checks.find((ch) => ch.kind === "cuid2");
      }
      get isULID() {
        return !!this._def.checks.find((ch) => ch.kind === "ulid");
      }
      get isIP() {
        return !!this._def.checks.find((ch) => ch.kind === "ip");
      }
      get isCIDR() {
        return !!this._def.checks.find((ch) => ch.kind === "cidr");
      }
      get isBase64() {
        return !!this._def.checks.find((ch) => ch.kind === "base64");
      }
      get isBase64url() {
        return !!this._def.checks.find((ch) => ch.kind === "base64url");
      }
      get minLength() {
        let min = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "min") {
            if (min === null || ch.value > min)
              min = ch.value;
          }
        }
        return min;
      }
      get maxLength() {
        let max = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "max") {
            if (max === null || ch.value < max)
              max = ch.value;
          }
        }
        return max;
      }
    };
    ZodString.create = (params) => {
      return new ZodString({
        checks: [],
        typeName: ZodFirstPartyTypeKind.ZodString,
        coerce: params?.coerce ?? false,
        ...processCreateParams(params)
      });
    };
    ZodNumber = class _ZodNumber extends ZodType {
      constructor() {
        super(...arguments);
        this.min = this.gte;
        this.max = this.lte;
        this.step = this.multipleOf;
      }
      _parse(input) {
        if (this._def.coerce) {
          input.data = Number(input.data);
        }
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.number) {
          const ctx2 = this._getOrReturnCtx(input);
          addIssueToContext(ctx2, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.number,
            received: ctx2.parsedType
          });
          return INVALID;
        }
        let ctx = void 0;
        const status = new ParseStatus();
        for (const check of this._def.checks) {
          if (check.kind === "int") {
            if (!util.isInteger(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.invalid_type,
                expected: "integer",
                received: "float",
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "min") {
            const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
            if (tooSmall) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_small,
                minimum: check.value,
                type: "number",
                inclusive: check.inclusive,
                exact: false,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "max") {
            const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
            if (tooBig) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_big,
                maximum: check.value,
                type: "number",
                inclusive: check.inclusive,
                exact: false,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "multipleOf") {
            if (floatSafeRemainder(input.data, check.value) !== 0) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.not_multiple_of,
                multipleOf: check.value,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "finite") {
            if (!Number.isFinite(input.data)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.not_finite,
                message: check.message
              });
              status.dirty();
            }
          } else {
            util.assertNever(check);
          }
        }
        return { status: status.value, value: input.data };
      }
      gte(value, message) {
        return this.setLimit("min", value, true, errorUtil.toString(message));
      }
      gt(value, message) {
        return this.setLimit("min", value, false, errorUtil.toString(message));
      }
      lte(value, message) {
        return this.setLimit("max", value, true, errorUtil.toString(message));
      }
      lt(value, message) {
        return this.setLimit("max", value, false, errorUtil.toString(message));
      }
      setLimit(kind, value, inclusive, message) {
        return new _ZodNumber({
          ...this._def,
          checks: [
            ...this._def.checks,
            {
              kind,
              value,
              inclusive,
              message: errorUtil.toString(message)
            }
          ]
        });
      }
      _addCheck(check) {
        return new _ZodNumber({
          ...this._def,
          checks: [...this._def.checks, check]
        });
      }
      int(message) {
        return this._addCheck({
          kind: "int",
          message: errorUtil.toString(message)
        });
      }
      positive(message) {
        return this._addCheck({
          kind: "min",
          value: 0,
          inclusive: false,
          message: errorUtil.toString(message)
        });
      }
      negative(message) {
        return this._addCheck({
          kind: "max",
          value: 0,
          inclusive: false,
          message: errorUtil.toString(message)
        });
      }
      nonpositive(message) {
        return this._addCheck({
          kind: "max",
          value: 0,
          inclusive: true,
          message: errorUtil.toString(message)
        });
      }
      nonnegative(message) {
        return this._addCheck({
          kind: "min",
          value: 0,
          inclusive: true,
          message: errorUtil.toString(message)
        });
      }
      multipleOf(value, message) {
        return this._addCheck({
          kind: "multipleOf",
          value,
          message: errorUtil.toString(message)
        });
      }
      finite(message) {
        return this._addCheck({
          kind: "finite",
          message: errorUtil.toString(message)
        });
      }
      safe(message) {
        return this._addCheck({
          kind: "min",
          inclusive: true,
          value: Number.MIN_SAFE_INTEGER,
          message: errorUtil.toString(message)
        })._addCheck({
          kind: "max",
          inclusive: true,
          value: Number.MAX_SAFE_INTEGER,
          message: errorUtil.toString(message)
        });
      }
      get minValue() {
        let min = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "min") {
            if (min === null || ch.value > min)
              min = ch.value;
          }
        }
        return min;
      }
      get maxValue() {
        let max = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "max") {
            if (max === null || ch.value < max)
              max = ch.value;
          }
        }
        return max;
      }
      get isInt() {
        return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
      }
      get isFinite() {
        let max = null;
        let min = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
            return true;
          } else if (ch.kind === "min") {
            if (min === null || ch.value > min)
              min = ch.value;
          } else if (ch.kind === "max") {
            if (max === null || ch.value < max)
              max = ch.value;
          }
        }
        return Number.isFinite(min) && Number.isFinite(max);
      }
    };
    ZodNumber.create = (params) => {
      return new ZodNumber({
        checks: [],
        typeName: ZodFirstPartyTypeKind.ZodNumber,
        coerce: params?.coerce || false,
        ...processCreateParams(params)
      });
    };
    ZodBigInt = class _ZodBigInt extends ZodType {
      constructor() {
        super(...arguments);
        this.min = this.gte;
        this.max = this.lte;
      }
      _parse(input) {
        if (this._def.coerce) {
          try {
            input.data = BigInt(input.data);
          } catch {
            return this._getInvalidInput(input);
          }
        }
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.bigint) {
          return this._getInvalidInput(input);
        }
        let ctx = void 0;
        const status = new ParseStatus();
        for (const check of this._def.checks) {
          if (check.kind === "min") {
            const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
            if (tooSmall) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_small,
                type: "bigint",
                minimum: check.value,
                inclusive: check.inclusive,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "max") {
            const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
            if (tooBig) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_big,
                type: "bigint",
                maximum: check.value,
                inclusive: check.inclusive,
                message: check.message
              });
              status.dirty();
            }
          } else if (check.kind === "multipleOf") {
            if (input.data % check.value !== BigInt(0)) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.not_multiple_of,
                multipleOf: check.value,
                message: check.message
              });
              status.dirty();
            }
          } else {
            util.assertNever(check);
          }
        }
        return { status: status.value, value: input.data };
      }
      _getInvalidInput(input) {
        const ctx = this._getOrReturnCtx(input);
        addIssueToContext(ctx, {
          code: ZodIssueCode.invalid_type,
          expected: ZodParsedType.bigint,
          received: ctx.parsedType
        });
        return INVALID;
      }
      gte(value, message) {
        return this.setLimit("min", value, true, errorUtil.toString(message));
      }
      gt(value, message) {
        return this.setLimit("min", value, false, errorUtil.toString(message));
      }
      lte(value, message) {
        return this.setLimit("max", value, true, errorUtil.toString(message));
      }
      lt(value, message) {
        return this.setLimit("max", value, false, errorUtil.toString(message));
      }
      setLimit(kind, value, inclusive, message) {
        return new _ZodBigInt({
          ...this._def,
          checks: [
            ...this._def.checks,
            {
              kind,
              value,
              inclusive,
              message: errorUtil.toString(message)
            }
          ]
        });
      }
      _addCheck(check) {
        return new _ZodBigInt({
          ...this._def,
          checks: [...this._def.checks, check]
        });
      }
      positive(message) {
        return this._addCheck({
          kind: "min",
          value: BigInt(0),
          inclusive: false,
          message: errorUtil.toString(message)
        });
      }
      negative(message) {
        return this._addCheck({
          kind: "max",
          value: BigInt(0),
          inclusive: false,
          message: errorUtil.toString(message)
        });
      }
      nonpositive(message) {
        return this._addCheck({
          kind: "max",
          value: BigInt(0),
          inclusive: true,
          message: errorUtil.toString(message)
        });
      }
      nonnegative(message) {
        return this._addCheck({
          kind: "min",
          value: BigInt(0),
          inclusive: true,
          message: errorUtil.toString(message)
        });
      }
      multipleOf(value, message) {
        return this._addCheck({
          kind: "multipleOf",
          value,
          message: errorUtil.toString(message)
        });
      }
      get minValue() {
        let min = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "min") {
            if (min === null || ch.value > min)
              min = ch.value;
          }
        }
        return min;
      }
      get maxValue() {
        let max = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "max") {
            if (max === null || ch.value < max)
              max = ch.value;
          }
        }
        return max;
      }
    };
    ZodBigInt.create = (params) => {
      return new ZodBigInt({
        checks: [],
        typeName: ZodFirstPartyTypeKind.ZodBigInt,
        coerce: params?.coerce ?? false,
        ...processCreateParams(params)
      });
    };
    ZodBoolean = class extends ZodType {
      _parse(input) {
        if (this._def.coerce) {
          input.data = Boolean(input.data);
        }
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.boolean) {
          const ctx = this._getOrReturnCtx(input);
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.boolean,
            received: ctx.parsedType
          });
          return INVALID;
        }
        return OK(input.data);
      }
    };
    ZodBoolean.create = (params) => {
      return new ZodBoolean({
        typeName: ZodFirstPartyTypeKind.ZodBoolean,
        coerce: params?.coerce || false,
        ...processCreateParams(params)
      });
    };
    ZodDate = class _ZodDate extends ZodType {
      _parse(input) {
        if (this._def.coerce) {
          input.data = new Date(input.data);
        }
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.date) {
          const ctx2 = this._getOrReturnCtx(input);
          addIssueToContext(ctx2, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.date,
            received: ctx2.parsedType
          });
          return INVALID;
        }
        if (Number.isNaN(input.data.getTime())) {
          const ctx2 = this._getOrReturnCtx(input);
          addIssueToContext(ctx2, {
            code: ZodIssueCode.invalid_date
          });
          return INVALID;
        }
        const status = new ParseStatus();
        let ctx = void 0;
        for (const check of this._def.checks) {
          if (check.kind === "min") {
            if (input.data.getTime() < check.value) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_small,
                message: check.message,
                inclusive: true,
                exact: false,
                minimum: check.value,
                type: "date"
              });
              status.dirty();
            }
          } else if (check.kind === "max") {
            if (input.data.getTime() > check.value) {
              ctx = this._getOrReturnCtx(input, ctx);
              addIssueToContext(ctx, {
                code: ZodIssueCode.too_big,
                message: check.message,
                inclusive: true,
                exact: false,
                maximum: check.value,
                type: "date"
              });
              status.dirty();
            }
          } else {
            util.assertNever(check);
          }
        }
        return {
          status: status.value,
          value: new Date(input.data.getTime())
        };
      }
      _addCheck(check) {
        return new _ZodDate({
          ...this._def,
          checks: [...this._def.checks, check]
        });
      }
      min(minDate, message) {
        return this._addCheck({
          kind: "min",
          value: minDate.getTime(),
          message: errorUtil.toString(message)
        });
      }
      max(maxDate, message) {
        return this._addCheck({
          kind: "max",
          value: maxDate.getTime(),
          message: errorUtil.toString(message)
        });
      }
      get minDate() {
        let min = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "min") {
            if (min === null || ch.value > min)
              min = ch.value;
          }
        }
        return min != null ? new Date(min) : null;
      }
      get maxDate() {
        let max = null;
        for (const ch of this._def.checks) {
          if (ch.kind === "max") {
            if (max === null || ch.value < max)
              max = ch.value;
          }
        }
        return max != null ? new Date(max) : null;
      }
    };
    ZodDate.create = (params) => {
      return new ZodDate({
        checks: [],
        coerce: params?.coerce || false,
        typeName: ZodFirstPartyTypeKind.ZodDate,
        ...processCreateParams(params)
      });
    };
    ZodSymbol = class extends ZodType {
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.symbol) {
          const ctx = this._getOrReturnCtx(input);
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.symbol,
            received: ctx.parsedType
          });
          return INVALID;
        }
        return OK(input.data);
      }
    };
    ZodSymbol.create = (params) => {
      return new ZodSymbol({
        typeName: ZodFirstPartyTypeKind.ZodSymbol,
        ...processCreateParams(params)
      });
    };
    ZodUndefined = class extends ZodType {
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.undefined) {
          const ctx = this._getOrReturnCtx(input);
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.undefined,
            received: ctx.parsedType
          });
          return INVALID;
        }
        return OK(input.data);
      }
    };
    ZodUndefined.create = (params) => {
      return new ZodUndefined({
        typeName: ZodFirstPartyTypeKind.ZodUndefined,
        ...processCreateParams(params)
      });
    };
    ZodNull = class extends ZodType {
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.null) {
          const ctx = this._getOrReturnCtx(input);
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.null,
            received: ctx.parsedType
          });
          return INVALID;
        }
        return OK(input.data);
      }
    };
    ZodNull.create = (params) => {
      return new ZodNull({
        typeName: ZodFirstPartyTypeKind.ZodNull,
        ...processCreateParams(params)
      });
    };
    ZodAny = class extends ZodType {
      constructor() {
        super(...arguments);
        this._any = true;
      }
      _parse(input) {
        return OK(input.data);
      }
    };
    ZodAny.create = (params) => {
      return new ZodAny({
        typeName: ZodFirstPartyTypeKind.ZodAny,
        ...processCreateParams(params)
      });
    };
    ZodUnknown = class extends ZodType {
      constructor() {
        super(...arguments);
        this._unknown = true;
      }
      _parse(input) {
        return OK(input.data);
      }
    };
    ZodUnknown.create = (params) => {
      return new ZodUnknown({
        typeName: ZodFirstPartyTypeKind.ZodUnknown,
        ...processCreateParams(params)
      });
    };
    ZodNever = class extends ZodType {
      _parse(input) {
        const ctx = this._getOrReturnCtx(input);
        addIssueToContext(ctx, {
          code: ZodIssueCode.invalid_type,
          expected: ZodParsedType.never,
          received: ctx.parsedType
        });
        return INVALID;
      }
    };
    ZodNever.create = (params) => {
      return new ZodNever({
        typeName: ZodFirstPartyTypeKind.ZodNever,
        ...processCreateParams(params)
      });
    };
    ZodVoid = class extends ZodType {
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.undefined) {
          const ctx = this._getOrReturnCtx(input);
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.void,
            received: ctx.parsedType
          });
          return INVALID;
        }
        return OK(input.data);
      }
    };
    ZodVoid.create = (params) => {
      return new ZodVoid({
        typeName: ZodFirstPartyTypeKind.ZodVoid,
        ...processCreateParams(params)
      });
    };
    ZodArray = class _ZodArray extends ZodType {
      _parse(input) {
        const { ctx, status } = this._processInputParams(input);
        const def = this._def;
        if (ctx.parsedType !== ZodParsedType.array) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.array,
            received: ctx.parsedType
          });
          return INVALID;
        }
        if (def.exactLength !== null) {
          const tooBig = ctx.data.length > def.exactLength.value;
          const tooSmall = ctx.data.length < def.exactLength.value;
          if (tooBig || tooSmall) {
            addIssueToContext(ctx, {
              code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
              minimum: tooSmall ? def.exactLength.value : void 0,
              maximum: tooBig ? def.exactLength.value : void 0,
              type: "array",
              inclusive: true,
              exact: true,
              message: def.exactLength.message
            });
            status.dirty();
          }
        }
        if (def.minLength !== null) {
          if (ctx.data.length < def.minLength.value) {
            addIssueToContext(ctx, {
              code: ZodIssueCode.too_small,
              minimum: def.minLength.value,
              type: "array",
              inclusive: true,
              exact: false,
              message: def.minLength.message
            });
            status.dirty();
          }
        }
        if (def.maxLength !== null) {
          if (ctx.data.length > def.maxLength.value) {
            addIssueToContext(ctx, {
              code: ZodIssueCode.too_big,
              maximum: def.maxLength.value,
              type: "array",
              inclusive: true,
              exact: false,
              message: def.maxLength.message
            });
            status.dirty();
          }
        }
        if (ctx.common.async) {
          return Promise.all([...ctx.data].map((item, i) => {
            return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
          })).then((result2) => {
            return ParseStatus.mergeArray(status, result2);
          });
        }
        const result = [...ctx.data].map((item, i) => {
          return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
        });
        return ParseStatus.mergeArray(status, result);
      }
      get element() {
        return this._def.type;
      }
      min(minLength, message) {
        return new _ZodArray({
          ...this._def,
          minLength: { value: minLength, message: errorUtil.toString(message) }
        });
      }
      max(maxLength, message) {
        return new _ZodArray({
          ...this._def,
          maxLength: { value: maxLength, message: errorUtil.toString(message) }
        });
      }
      length(len, message) {
        return new _ZodArray({
          ...this._def,
          exactLength: { value: len, message: errorUtil.toString(message) }
        });
      }
      nonempty(message) {
        return this.min(1, message);
      }
    };
    ZodArray.create = (schema, params) => {
      return new ZodArray({
        type: schema,
        minLength: null,
        maxLength: null,
        exactLength: null,
        typeName: ZodFirstPartyTypeKind.ZodArray,
        ...processCreateParams(params)
      });
    };
    ZodObject = class _ZodObject extends ZodType {
      constructor() {
        super(...arguments);
        this._cached = null;
        this.nonstrict = this.passthrough;
        this.augment = this.extend;
      }
      _getCached() {
        if (this._cached !== null)
          return this._cached;
        const shape = this._def.shape();
        const keys = util.objectKeys(shape);
        this._cached = { shape, keys };
        return this._cached;
      }
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.object) {
          const ctx2 = this._getOrReturnCtx(input);
          addIssueToContext(ctx2, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.object,
            received: ctx2.parsedType
          });
          return INVALID;
        }
        const { status, ctx } = this._processInputParams(input);
        const { shape, keys: shapeKeys } = this._getCached();
        const extraKeys = [];
        if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
          for (const key in ctx.data) {
            if (!shapeKeys.includes(key)) {
              extraKeys.push(key);
            }
          }
        }
        const pairs = [];
        for (const key of shapeKeys) {
          const keyValidator = shape[key];
          const value = ctx.data[key];
          pairs.push({
            key: { status: "valid", value: key },
            value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
            alwaysSet: key in ctx.data
          });
        }
        if (this._def.catchall instanceof ZodNever) {
          const unknownKeys = this._def.unknownKeys;
          if (unknownKeys === "passthrough") {
            for (const key of extraKeys) {
              pairs.push({
                key: { status: "valid", value: key },
                value: { status: "valid", value: ctx.data[key] }
              });
            }
          } else if (unknownKeys === "strict") {
            if (extraKeys.length > 0) {
              addIssueToContext(ctx, {
                code: ZodIssueCode.unrecognized_keys,
                keys: extraKeys
              });
              status.dirty();
            }
          } else if (unknownKeys === "strip") {
          } else {
            throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
          }
        } else {
          const catchall = this._def.catchall;
          for (const key of extraKeys) {
            const value = ctx.data[key];
            pairs.push({
              key: { status: "valid", value: key },
              value: catchall._parse(
                new ParseInputLazyPath(ctx, value, ctx.path, key)
                //, ctx.child(key), value, getParsedType(value)
              ),
              alwaysSet: key in ctx.data
            });
          }
        }
        if (ctx.common.async) {
          return Promise.resolve().then(async () => {
            const syncPairs = [];
            for (const pair of pairs) {
              const key = await pair.key;
              const value = await pair.value;
              syncPairs.push({
                key,
                value,
                alwaysSet: pair.alwaysSet
              });
            }
            return syncPairs;
          }).then((syncPairs) => {
            return ParseStatus.mergeObjectSync(status, syncPairs);
          });
        } else {
          return ParseStatus.mergeObjectSync(status, pairs);
        }
      }
      get shape() {
        return this._def.shape();
      }
      strict(message) {
        errorUtil.errToObj;
        return new _ZodObject({
          ...this._def,
          unknownKeys: "strict",
          ...message !== void 0 ? {
            errorMap: (issue, ctx) => {
              const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
              if (issue.code === "unrecognized_keys")
                return {
                  message: errorUtil.errToObj(message).message ?? defaultError
                };
              return {
                message: defaultError
              };
            }
          } : {}
        });
      }
      strip() {
        return new _ZodObject({
          ...this._def,
          unknownKeys: "strip"
        });
      }
      passthrough() {
        return new _ZodObject({
          ...this._def,
          unknownKeys: "passthrough"
        });
      }
      // const AugmentFactory =
      //   <Def extends ZodObjectDef>(def: Def) =>
      //   <Augmentation extends ZodRawShape>(
      //     augmentation: Augmentation
      //   ): ZodObject<
      //     extendShape<ReturnType<Def["shape"]>, Augmentation>,
      //     Def["unknownKeys"],
      //     Def["catchall"]
      //   > => {
      //     return new ZodObject({
      //       ...def,
      //       shape: () => ({
      //         ...def.shape(),
      //         ...augmentation,
      //       }),
      //     }) as any;
      //   };
      extend(augmentation) {
        return new _ZodObject({
          ...this._def,
          shape: () => ({
            ...this._def.shape(),
            ...augmentation
          })
        });
      }
      /**
       * Prior to zod@1.0.12 there was a bug in the
       * inferred type of merged objects. Please
       * upgrade if you are experiencing issues.
       */
      merge(merging) {
        const merged = new _ZodObject({
          unknownKeys: merging._def.unknownKeys,
          catchall: merging._def.catchall,
          shape: () => ({
            ...this._def.shape(),
            ...merging._def.shape()
          }),
          typeName: ZodFirstPartyTypeKind.ZodObject
        });
        return merged;
      }
      // merge<
      //   Incoming extends AnyZodObject,
      //   Augmentation extends Incoming["shape"],
      //   NewOutput extends {
      //     [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
      //       ? Augmentation[k]["_output"]
      //       : k extends keyof Output
      //       ? Output[k]
      //       : never;
      //   },
      //   NewInput extends {
      //     [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
      //       ? Augmentation[k]["_input"]
      //       : k extends keyof Input
      //       ? Input[k]
      //       : never;
      //   }
      // >(
      //   merging: Incoming
      // ): ZodObject<
      //   extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
      //   Incoming["_def"]["unknownKeys"],
      //   Incoming["_def"]["catchall"],
      //   NewOutput,
      //   NewInput
      // > {
      //   const merged: any = new ZodObject({
      //     unknownKeys: merging._def.unknownKeys,
      //     catchall: merging._def.catchall,
      //     shape: () =>
      //       objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
      //     typeName: ZodFirstPartyTypeKind.ZodObject,
      //   }) as any;
      //   return merged;
      // }
      setKey(key, schema) {
        return this.augment({ [key]: schema });
      }
      // merge<Incoming extends AnyZodObject>(
      //   merging: Incoming
      // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
      // ZodObject<
      //   extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
      //   Incoming["_def"]["unknownKeys"],
      //   Incoming["_def"]["catchall"]
      // > {
      //   // const mergedShape = objectUtil.mergeShapes(
      //   //   this._def.shape(),
      //   //   merging._def.shape()
      //   // );
      //   const merged: any = new ZodObject({
      //     unknownKeys: merging._def.unknownKeys,
      //     catchall: merging._def.catchall,
      //     shape: () =>
      //       objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
      //     typeName: ZodFirstPartyTypeKind.ZodObject,
      //   }) as any;
      //   return merged;
      // }
      catchall(index) {
        return new _ZodObject({
          ...this._def,
          catchall: index
        });
      }
      pick(mask) {
        const shape = {};
        for (const key of util.objectKeys(mask)) {
          if (mask[key] && this.shape[key]) {
            shape[key] = this.shape[key];
          }
        }
        return new _ZodObject({
          ...this._def,
          shape: () => shape
        });
      }
      omit(mask) {
        const shape = {};
        for (const key of util.objectKeys(this.shape)) {
          if (!mask[key]) {
            shape[key] = this.shape[key];
          }
        }
        return new _ZodObject({
          ...this._def,
          shape: () => shape
        });
      }
      /**
       * @deprecated
       */
      deepPartial() {
        return deepPartialify(this);
      }
      partial(mask) {
        const newShape = {};
        for (const key of util.objectKeys(this.shape)) {
          const fieldSchema = this.shape[key];
          if (mask && !mask[key]) {
            newShape[key] = fieldSchema;
          } else {
            newShape[key] = fieldSchema.optional();
          }
        }
        return new _ZodObject({
          ...this._def,
          shape: () => newShape
        });
      }
      required(mask) {
        const newShape = {};
        for (const key of util.objectKeys(this.shape)) {
          if (mask && !mask[key]) {
            newShape[key] = this.shape[key];
          } else {
            const fieldSchema = this.shape[key];
            let newField = fieldSchema;
            while (newField instanceof ZodOptional) {
              newField = newField._def.innerType;
            }
            newShape[key] = newField;
          }
        }
        return new _ZodObject({
          ...this._def,
          shape: () => newShape
        });
      }
      keyof() {
        return createZodEnum(util.objectKeys(this.shape));
      }
    };
    ZodObject.create = (shape, params) => {
      return new ZodObject({
        shape: () => shape,
        unknownKeys: "strip",
        catchall: ZodNever.create(),
        typeName: ZodFirstPartyTypeKind.ZodObject,
        ...processCreateParams(params)
      });
    };
    ZodObject.strictCreate = (shape, params) => {
      return new ZodObject({
        shape: () => shape,
        unknownKeys: "strict",
        catchall: ZodNever.create(),
        typeName: ZodFirstPartyTypeKind.ZodObject,
        ...processCreateParams(params)
      });
    };
    ZodObject.lazycreate = (shape, params) => {
      return new ZodObject({
        shape,
        unknownKeys: "strip",
        catchall: ZodNever.create(),
        typeName: ZodFirstPartyTypeKind.ZodObject,
        ...processCreateParams(params)
      });
    };
    ZodUnion = class extends ZodType {
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        const options = this._def.options;
        function handleResults(results) {
          for (const result of results) {
            if (result.result.status === "valid") {
              return result.result;
            }
          }
          for (const result of results) {
            if (result.result.status === "dirty") {
              ctx.common.issues.push(...result.ctx.common.issues);
              return result.result;
            }
          }
          const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_union,
            unionErrors
          });
          return INVALID;
        }
        if (ctx.common.async) {
          return Promise.all(options.map(async (option) => {
            const childCtx = {
              ...ctx,
              common: {
                ...ctx.common,
                issues: []
              },
              parent: null
            };
            return {
              result: await option._parseAsync({
                data: ctx.data,
                path: ctx.path,
                parent: childCtx
              }),
              ctx: childCtx
            };
          })).then(handleResults);
        } else {
          let dirty = void 0;
          const issues = [];
          for (const option of options) {
            const childCtx = {
              ...ctx,
              common: {
                ...ctx.common,
                issues: []
              },
              parent: null
            };
            const result = option._parseSync({
              data: ctx.data,
              path: ctx.path,
              parent: childCtx
            });
            if (result.status === "valid") {
              return result;
            } else if (result.status === "dirty" && !dirty) {
              dirty = { result, ctx: childCtx };
            }
            if (childCtx.common.issues.length) {
              issues.push(childCtx.common.issues);
            }
          }
          if (dirty) {
            ctx.common.issues.push(...dirty.ctx.common.issues);
            return dirty.result;
          }
          const unionErrors = issues.map((issues2) => new ZodError(issues2));
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_union,
            unionErrors
          });
          return INVALID;
        }
      }
      get options() {
        return this._def.options;
      }
    };
    ZodUnion.create = (types, params) => {
      return new ZodUnion({
        options: types,
        typeName: ZodFirstPartyTypeKind.ZodUnion,
        ...processCreateParams(params)
      });
    };
    getDiscriminator = (type) => {
      if (type instanceof ZodLazy) {
        return getDiscriminator(type.schema);
      } else if (type instanceof ZodEffects) {
        return getDiscriminator(type.innerType());
      } else if (type instanceof ZodLiteral) {
        return [type.value];
      } else if (type instanceof ZodEnum) {
        return type.options;
      } else if (type instanceof ZodNativeEnum) {
        return util.objectValues(type.enum);
      } else if (type instanceof ZodDefault) {
        return getDiscriminator(type._def.innerType);
      } else if (type instanceof ZodUndefined) {
        return [void 0];
      } else if (type instanceof ZodNull) {
        return [null];
      } else if (type instanceof ZodOptional) {
        return [void 0, ...getDiscriminator(type.unwrap())];
      } else if (type instanceof ZodNullable) {
        return [null, ...getDiscriminator(type.unwrap())];
      } else if (type instanceof ZodBranded) {
        return getDiscriminator(type.unwrap());
      } else if (type instanceof ZodReadonly) {
        return getDiscriminator(type.unwrap());
      } else if (type instanceof ZodCatch) {
        return getDiscriminator(type._def.innerType);
      } else {
        return [];
      }
    };
    ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        if (ctx.parsedType !== ZodParsedType.object) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.object,
            received: ctx.parsedType
          });
          return INVALID;
        }
        const discriminator = this.discriminator;
        const discriminatorValue = ctx.data[discriminator];
        const option = this.optionsMap.get(discriminatorValue);
        if (!option) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_union_discriminator,
            options: Array.from(this.optionsMap.keys()),
            path: [discriminator]
          });
          return INVALID;
        }
        if (ctx.common.async) {
          return option._parseAsync({
            data: ctx.data,
            path: ctx.path,
            parent: ctx
          });
        } else {
          return option._parseSync({
            data: ctx.data,
            path: ctx.path,
            parent: ctx
          });
        }
      }
      get discriminator() {
        return this._def.discriminator;
      }
      get options() {
        return this._def.options;
      }
      get optionsMap() {
        return this._def.optionsMap;
      }
      /**
       * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
       * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
       * have a different value for each object in the union.
       * @param discriminator the name of the discriminator property
       * @param types an array of object schemas
       * @param params
       */
      static create(discriminator, options, params) {
        const optionsMap = /* @__PURE__ */ new Map();
        for (const type of options) {
          const discriminatorValues = getDiscriminator(type.shape[discriminator]);
          if (!discriminatorValues.length) {
            throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
          }
          for (const value of discriminatorValues) {
            if (optionsMap.has(value)) {
              throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
            }
            optionsMap.set(value, type);
          }
        }
        return new _ZodDiscriminatedUnion({
          typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
          discriminator,
          options,
          optionsMap,
          ...processCreateParams(params)
        });
      }
    };
    ZodIntersection = class extends ZodType {
      _parse(input) {
        const { status, ctx } = this._processInputParams(input);
        const handleParsed = (parsedLeft, parsedRight) => {
          if (isAborted(parsedLeft) || isAborted(parsedRight)) {
            return INVALID;
          }
          const merged = mergeValues(parsedLeft.value, parsedRight.value);
          if (!merged.valid) {
            addIssueToContext(ctx, {
              code: ZodIssueCode.invalid_intersection_types
            });
            return INVALID;
          }
          if (isDirty(parsedLeft) || isDirty(parsedRight)) {
            status.dirty();
          }
          return { status: status.value, value: merged.data };
        };
        if (ctx.common.async) {
          return Promise.all([
            this._def.left._parseAsync({
              data: ctx.data,
              path: ctx.path,
              parent: ctx
            }),
            this._def.right._parseAsync({
              data: ctx.data,
              path: ctx.path,
              parent: ctx
            })
          ]).then(([left, right]) => handleParsed(left, right));
        } else {
          return handleParsed(this._def.left._parseSync({
            data: ctx.data,
            path: ctx.path,
            parent: ctx
          }), this._def.right._parseSync({
            data: ctx.data,
            path: ctx.path,
            parent: ctx
          }));
        }
      }
    };
    ZodIntersection.create = (left, right, params) => {
      return new ZodIntersection({
        left,
        right,
        typeName: ZodFirstPartyTypeKind.ZodIntersection,
        ...processCreateParams(params)
      });
    };
    ZodTuple = class _ZodTuple extends ZodType {
      _parse(input) {
        const { status, ctx } = this._processInputParams(input);
        if (ctx.parsedType !== ZodParsedType.array) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.array,
            received: ctx.parsedType
          });
          return INVALID;
        }
        if (ctx.data.length < this._def.items.length) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.too_small,
            minimum: this._def.items.length,
            inclusive: true,
            exact: false,
            type: "array"
          });
          return INVALID;
        }
        const rest = this._def.rest;
        if (!rest && ctx.data.length > this._def.items.length) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.too_big,
            maximum: this._def.items.length,
            inclusive: true,
            exact: false,
            type: "array"
          });
          status.dirty();
        }
        const items = [...ctx.data].map((item, itemIndex) => {
          const schema = this._def.items[itemIndex] || this._def.rest;
          if (!schema)
            return null;
          return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
        }).filter((x) => !!x);
        if (ctx.common.async) {
          return Promise.all(items).then((results) => {
            return ParseStatus.mergeArray(status, results);
          });
        } else {
          return ParseStatus.mergeArray(status, items);
        }
      }
      get items() {
        return this._def.items;
      }
      rest(rest) {
        return new _ZodTuple({
          ...this._def,
          rest
        });
      }
    };
    ZodTuple.create = (schemas, params) => {
      if (!Array.isArray(schemas)) {
        throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
      }
      return new ZodTuple({
        items: schemas,
        typeName: ZodFirstPartyTypeKind.ZodTuple,
        rest: null,
        ...processCreateParams(params)
      });
    };
    ZodRecord = class _ZodRecord extends ZodType {
      get keySchema() {
        return this._def.keyType;
      }
      get valueSchema() {
        return this._def.valueType;
      }
      _parse(input) {
        const { status, ctx } = this._processInputParams(input);
        if (ctx.parsedType !== ZodParsedType.object) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.object,
            received: ctx.parsedType
          });
          return INVALID;
        }
        const pairs = [];
        const keyType = this._def.keyType;
        const valueType = this._def.valueType;
        for (const key in ctx.data) {
          pairs.push({
            key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
            value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
            alwaysSet: key in ctx.data
          });
        }
        if (ctx.common.async) {
          return ParseStatus.mergeObjectAsync(status, pairs);
        } else {
          return ParseStatus.mergeObjectSync(status, pairs);
        }
      }
      get element() {
        return this._def.valueType;
      }
      static create(first, second, third) {
        if (second instanceof ZodType) {
          return new _ZodRecord({
            keyType: first,
            valueType: second,
            typeName: ZodFirstPartyTypeKind.ZodRecord,
            ...processCreateParams(third)
          });
        }
        return new _ZodRecord({
          keyType: ZodString.create(),
          valueType: first,
          typeName: ZodFirstPartyTypeKind.ZodRecord,
          ...processCreateParams(second)
        });
      }
    };
    ZodMap = class extends ZodType {
      get keySchema() {
        return this._def.keyType;
      }
      get valueSchema() {
        return this._def.valueType;
      }
      _parse(input) {
        const { status, ctx } = this._processInputParams(input);
        if (ctx.parsedType !== ZodParsedType.map) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.map,
            received: ctx.parsedType
          });
          return INVALID;
        }
        const keyType = this._def.keyType;
        const valueType = this._def.valueType;
        const pairs = [...ctx.data.entries()].map(([key, value], index) => {
          return {
            key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
            value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
          };
        });
        if (ctx.common.async) {
          const finalMap = /* @__PURE__ */ new Map();
          return Promise.resolve().then(async () => {
            for (const pair of pairs) {
              const key = await pair.key;
              const value = await pair.value;
              if (key.status === "aborted" || value.status === "aborted") {
                return INVALID;
              }
              if (key.status === "dirty" || value.status === "dirty") {
                status.dirty();
              }
              finalMap.set(key.value, value.value);
            }
            return { status: status.value, value: finalMap };
          });
        } else {
          const finalMap = /* @__PURE__ */ new Map();
          for (const pair of pairs) {
            const key = pair.key;
            const value = pair.value;
            if (key.status === "aborted" || value.status === "aborted") {
              return INVALID;
            }
            if (key.status === "dirty" || value.status === "dirty") {
              status.dirty();
            }
            finalMap.set(key.value, value.value);
          }
          return { status: status.value, value: finalMap };
        }
      }
    };
    ZodMap.create = (keyType, valueType, params) => {
      return new ZodMap({
        valueType,
        keyType,
        typeName: ZodFirstPartyTypeKind.ZodMap,
        ...processCreateParams(params)
      });
    };
    ZodSet = class _ZodSet extends ZodType {
      _parse(input) {
        const { status, ctx } = this._processInputParams(input);
        if (ctx.parsedType !== ZodParsedType.set) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.set,
            received: ctx.parsedType
          });
          return INVALID;
        }
        const def = this._def;
        if (def.minSize !== null) {
          if (ctx.data.size < def.minSize.value) {
            addIssueToContext(ctx, {
              code: ZodIssueCode.too_small,
              minimum: def.minSize.value,
              type: "set",
              inclusive: true,
              exact: false,
              message: def.minSize.message
            });
            status.dirty();
          }
        }
        if (def.maxSize !== null) {
          if (ctx.data.size > def.maxSize.value) {
            addIssueToContext(ctx, {
              code: ZodIssueCode.too_big,
              maximum: def.maxSize.value,
              type: "set",
              inclusive: true,
              exact: false,
              message: def.maxSize.message
            });
            status.dirty();
          }
        }
        const valueType = this._def.valueType;
        function finalizeSet(elements2) {
          const parsedSet = /* @__PURE__ */ new Set();
          for (const element of elements2) {
            if (element.status === "aborted")
              return INVALID;
            if (element.status === "dirty")
              status.dirty();
            parsedSet.add(element.value);
          }
          return { status: status.value, value: parsedSet };
        }
        const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
        if (ctx.common.async) {
          return Promise.all(elements).then((elements2) => finalizeSet(elements2));
        } else {
          return finalizeSet(elements);
        }
      }
      min(minSize, message) {
        return new _ZodSet({
          ...this._def,
          minSize: { value: minSize, message: errorUtil.toString(message) }
        });
      }
      max(maxSize, message) {
        return new _ZodSet({
          ...this._def,
          maxSize: { value: maxSize, message: errorUtil.toString(message) }
        });
      }
      size(size, message) {
        return this.min(size, message).max(size, message);
      }
      nonempty(message) {
        return this.min(1, message);
      }
    };
    ZodSet.create = (valueType, params) => {
      return new ZodSet({
        valueType,
        minSize: null,
        maxSize: null,
        typeName: ZodFirstPartyTypeKind.ZodSet,
        ...processCreateParams(params)
      });
    };
    ZodFunction = class _ZodFunction extends ZodType {
      constructor() {
        super(...arguments);
        this.validate = this.implement;
      }
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        if (ctx.parsedType !== ZodParsedType.function) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.function,
            received: ctx.parsedType
          });
          return INVALID;
        }
        function makeArgsIssue(args, error) {
          return makeIssue({
            data: args,
            path: ctx.path,
            errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
            issueData: {
              code: ZodIssueCode.invalid_arguments,
              argumentsError: error
            }
          });
        }
        function makeReturnsIssue(returns, error) {
          return makeIssue({
            data: returns,
            path: ctx.path,
            errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
            issueData: {
              code: ZodIssueCode.invalid_return_type,
              returnTypeError: error
            }
          });
        }
        const params = { errorMap: ctx.common.contextualErrorMap };
        const fn = ctx.data;
        if (this._def.returns instanceof ZodPromise) {
          const me = this;
          return OK(async function(...args) {
            const error = new ZodError([]);
            const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
              error.addIssue(makeArgsIssue(args, e));
              throw error;
            });
            const result = await Reflect.apply(fn, this, parsedArgs);
            const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
              error.addIssue(makeReturnsIssue(result, e));
              throw error;
            });
            return parsedReturns;
          });
        } else {
          const me = this;
          return OK(function(...args) {
            const parsedArgs = me._def.args.safeParse(args, params);
            if (!parsedArgs.success) {
              throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
            }
            const result = Reflect.apply(fn, this, parsedArgs.data);
            const parsedReturns = me._def.returns.safeParse(result, params);
            if (!parsedReturns.success) {
              throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
            }
            return parsedReturns.data;
          });
        }
      }
      parameters() {
        return this._def.args;
      }
      returnType() {
        return this._def.returns;
      }
      args(...items) {
        return new _ZodFunction({
          ...this._def,
          args: ZodTuple.create(items).rest(ZodUnknown.create())
        });
      }
      returns(returnType) {
        return new _ZodFunction({
          ...this._def,
          returns: returnType
        });
      }
      implement(func) {
        const validatedFunc = this.parse(func);
        return validatedFunc;
      }
      strictImplement(func) {
        const validatedFunc = this.parse(func);
        return validatedFunc;
      }
      static create(args, returns, params) {
        return new _ZodFunction({
          args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
          returns: returns || ZodUnknown.create(),
          typeName: ZodFirstPartyTypeKind.ZodFunction,
          ...processCreateParams(params)
        });
      }
    };
    ZodLazy = class extends ZodType {
      get schema() {
        return this._def.getter();
      }
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        const lazySchema = this._def.getter();
        return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
      }
    };
    ZodLazy.create = (getter, params) => {
      return new ZodLazy({
        getter,
        typeName: ZodFirstPartyTypeKind.ZodLazy,
        ...processCreateParams(params)
      });
    };
    ZodLiteral = class extends ZodType {
      _parse(input) {
        if (input.data !== this._def.value) {
          const ctx = this._getOrReturnCtx(input);
          addIssueToContext(ctx, {
            received: ctx.data,
            code: ZodIssueCode.invalid_literal,
            expected: this._def.value
          });
          return INVALID;
        }
        return { status: "valid", value: input.data };
      }
      get value() {
        return this._def.value;
      }
    };
    ZodLiteral.create = (value, params) => {
      return new ZodLiteral({
        value,
        typeName: ZodFirstPartyTypeKind.ZodLiteral,
        ...processCreateParams(params)
      });
    };
    ZodEnum = class _ZodEnum extends ZodType {
      _parse(input) {
        if (typeof input.data !== "string") {
          const ctx = this._getOrReturnCtx(input);
          const expectedValues = this._def.values;
          addIssueToContext(ctx, {
            expected: util.joinValues(expectedValues),
            received: ctx.parsedType,
            code: ZodIssueCode.invalid_type
          });
          return INVALID;
        }
        if (!this._cache) {
          this._cache = new Set(this._def.values);
        }
        if (!this._cache.has(input.data)) {
          const ctx = this._getOrReturnCtx(input);
          const expectedValues = this._def.values;
          addIssueToContext(ctx, {
            received: ctx.data,
            code: ZodIssueCode.invalid_enum_value,
            options: expectedValues
          });
          return INVALID;
        }
        return OK(input.data);
      }
      get options() {
        return this._def.values;
      }
      get enum() {
        const enumValues = {};
        for (const val of this._def.values) {
          enumValues[val] = val;
        }
        return enumValues;
      }
      get Values() {
        const enumValues = {};
        for (const val of this._def.values) {
          enumValues[val] = val;
        }
        return enumValues;
      }
      get Enum() {
        const enumValues = {};
        for (const val of this._def.values) {
          enumValues[val] = val;
        }
        return enumValues;
      }
      extract(values, newDef = this._def) {
        return _ZodEnum.create(values, {
          ...this._def,
          ...newDef
        });
      }
      exclude(values, newDef = this._def) {
        return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
          ...this._def,
          ...newDef
        });
      }
    };
    ZodEnum.create = createZodEnum;
    ZodNativeEnum = class extends ZodType {
      _parse(input) {
        const nativeEnumValues = util.getValidEnumValues(this._def.values);
        const ctx = this._getOrReturnCtx(input);
        if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
          const expectedValues = util.objectValues(nativeEnumValues);
          addIssueToContext(ctx, {
            expected: util.joinValues(expectedValues),
            received: ctx.parsedType,
            code: ZodIssueCode.invalid_type
          });
          return INVALID;
        }
        if (!this._cache) {
          this._cache = new Set(util.getValidEnumValues(this._def.values));
        }
        if (!this._cache.has(input.data)) {
          const expectedValues = util.objectValues(nativeEnumValues);
          addIssueToContext(ctx, {
            received: ctx.data,
            code: ZodIssueCode.invalid_enum_value,
            options: expectedValues
          });
          return INVALID;
        }
        return OK(input.data);
      }
      get enum() {
        return this._def.values;
      }
    };
    ZodNativeEnum.create = (values, params) => {
      return new ZodNativeEnum({
        values,
        typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
        ...processCreateParams(params)
      });
    };
    ZodPromise = class extends ZodType {
      unwrap() {
        return this._def.type;
      }
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.promise,
            received: ctx.parsedType
          });
          return INVALID;
        }
        const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
        return OK(promisified.then((data) => {
          return this._def.type.parseAsync(data, {
            path: ctx.path,
            errorMap: ctx.common.contextualErrorMap
          });
        }));
      }
    };
    ZodPromise.create = (schema, params) => {
      return new ZodPromise({
        type: schema,
        typeName: ZodFirstPartyTypeKind.ZodPromise,
        ...processCreateParams(params)
      });
    };
    ZodEffects = class extends ZodType {
      innerType() {
        return this._def.schema;
      }
      sourceType() {
        return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
      }
      _parse(input) {
        const { status, ctx } = this._processInputParams(input);
        const effect = this._def.effect || null;
        const checkCtx = {
          addIssue: (arg) => {
            addIssueToContext(ctx, arg);
            if (arg.fatal) {
              status.abort();
            } else {
              status.dirty();
            }
          },
          get path() {
            return ctx.path;
          }
        };
        checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
        if (effect.type === "preprocess") {
          const processed = effect.transform(ctx.data, checkCtx);
          if (ctx.common.async) {
            return Promise.resolve(processed).then(async (processed2) => {
              if (status.value === "aborted")
                return INVALID;
              const result = await this._def.schema._parseAsync({
                data: processed2,
                path: ctx.path,
                parent: ctx
              });
              if (result.status === "aborted")
                return INVALID;
              if (result.status === "dirty")
                return DIRTY(result.value);
              if (status.value === "dirty")
                return DIRTY(result.value);
              return result;
            });
          } else {
            if (status.value === "aborted")
              return INVALID;
            const result = this._def.schema._parseSync({
              data: processed,
              path: ctx.path,
              parent: ctx
            });
            if (result.status === "aborted")
              return INVALID;
            if (result.status === "dirty")
              return DIRTY(result.value);
            if (status.value === "dirty")
              return DIRTY(result.value);
            return result;
          }
        }
        if (effect.type === "refinement") {
          const executeRefinement = (acc) => {
            const result = effect.refinement(acc, checkCtx);
            if (ctx.common.async) {
              return Promise.resolve(result);
            }
            if (result instanceof Promise) {
              throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
            }
            return acc;
          };
          if (ctx.common.async === false) {
            const inner = this._def.schema._parseSync({
              data: ctx.data,
              path: ctx.path,
              parent: ctx
            });
            if (inner.status === "aborted")
              return INVALID;
            if (inner.status === "dirty")
              status.dirty();
            executeRefinement(inner.value);
            return { status: status.value, value: inner.value };
          } else {
            return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
              if (inner.status === "aborted")
                return INVALID;
              if (inner.status === "dirty")
                status.dirty();
              return executeRefinement(inner.value).then(() => {
                return { status: status.value, value: inner.value };
              });
            });
          }
        }
        if (effect.type === "transform") {
          if (ctx.common.async === false) {
            const base = this._def.schema._parseSync({
              data: ctx.data,
              path: ctx.path,
              parent: ctx
            });
            if (!isValid(base))
              return INVALID;
            const result = effect.transform(base.value, checkCtx);
            if (result instanceof Promise) {
              throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
            }
            return { status: status.value, value: result };
          } else {
            return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
              if (!isValid(base))
                return INVALID;
              return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
                status: status.value,
                value: result
              }));
            });
          }
        }
        util.assertNever(effect);
      }
    };
    ZodEffects.create = (schema, effect, params) => {
      return new ZodEffects({
        schema,
        typeName: ZodFirstPartyTypeKind.ZodEffects,
        effect,
        ...processCreateParams(params)
      });
    };
    ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
      return new ZodEffects({
        schema,
        effect: { type: "preprocess", transform: preprocess },
        typeName: ZodFirstPartyTypeKind.ZodEffects,
        ...processCreateParams(params)
      });
    };
    ZodOptional = class extends ZodType {
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType === ZodParsedType.undefined) {
          return OK(void 0);
        }
        return this._def.innerType._parse(input);
      }
      unwrap() {
        return this._def.innerType;
      }
    };
    ZodOptional.create = (type, params) => {
      return new ZodOptional({
        innerType: type,
        typeName: ZodFirstPartyTypeKind.ZodOptional,
        ...processCreateParams(params)
      });
    };
    ZodNullable = class extends ZodType {
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType === ZodParsedType.null) {
          return OK(null);
        }
        return this._def.innerType._parse(input);
      }
      unwrap() {
        return this._def.innerType;
      }
    };
    ZodNullable.create = (type, params) => {
      return new ZodNullable({
        innerType: type,
        typeName: ZodFirstPartyTypeKind.ZodNullable,
        ...processCreateParams(params)
      });
    };
    ZodDefault = class extends ZodType {
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        let data = ctx.data;
        if (ctx.parsedType === ZodParsedType.undefined) {
          data = this._def.defaultValue();
        }
        return this._def.innerType._parse({
          data,
          path: ctx.path,
          parent: ctx
        });
      }
      removeDefault() {
        return this._def.innerType;
      }
    };
    ZodDefault.create = (type, params) => {
      return new ZodDefault({
        innerType: type,
        typeName: ZodFirstPartyTypeKind.ZodDefault,
        defaultValue: typeof params.default === "function" ? params.default : () => params.default,
        ...processCreateParams(params)
      });
    };
    ZodCatch = class extends ZodType {
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        const newCtx = {
          ...ctx,
          common: {
            ...ctx.common,
            issues: []
          }
        };
        const result = this._def.innerType._parse({
          data: newCtx.data,
          path: newCtx.path,
          parent: {
            ...newCtx
          }
        });
        if (isAsync(result)) {
          return result.then((result2) => {
            return {
              status: "valid",
              value: result2.status === "valid" ? result2.value : this._def.catchValue({
                get error() {
                  return new ZodError(newCtx.common.issues);
                },
                input: newCtx.data
              })
            };
          });
        } else {
          return {
            status: "valid",
            value: result.status === "valid" ? result.value : this._def.catchValue({
              get error() {
                return new ZodError(newCtx.common.issues);
              },
              input: newCtx.data
            })
          };
        }
      }
      removeCatch() {
        return this._def.innerType;
      }
    };
    ZodCatch.create = (type, params) => {
      return new ZodCatch({
        innerType: type,
        typeName: ZodFirstPartyTypeKind.ZodCatch,
        catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
        ...processCreateParams(params)
      });
    };
    ZodNaN = class extends ZodType {
      _parse(input) {
        const parsedType = this._getType(input);
        if (parsedType !== ZodParsedType.nan) {
          const ctx = this._getOrReturnCtx(input);
          addIssueToContext(ctx, {
            code: ZodIssueCode.invalid_type,
            expected: ZodParsedType.nan,
            received: ctx.parsedType
          });
          return INVALID;
        }
        return { status: "valid", value: input.data };
      }
    };
    ZodNaN.create = (params) => {
      return new ZodNaN({
        typeName: ZodFirstPartyTypeKind.ZodNaN,
        ...processCreateParams(params)
      });
    };
    BRAND = Symbol("zod_brand");
    ZodBranded = class extends ZodType {
      _parse(input) {
        const { ctx } = this._processInputParams(input);
        const data = ctx.data;
        return this._def.type._parse({
          data,
          path: ctx.path,
          parent: ctx
        });
      }
      unwrap() {
        return this._def.type;
      }
    };
    ZodPipeline = class _ZodPipeline extends ZodType {
      _parse(input) {
        const { status, ctx } = this._processInputParams(input);
        if (ctx.common.async) {
          const handleAsync = async () => {
            const inResult = await this._def.in._parseAsync({
              data: ctx.data,
              path: ctx.path,
              parent: ctx
            });
            if (inResult.status === "aborted")
              return INVALID;
            if (inResult.status === "dirty") {
              status.dirty();
              return DIRTY(inResult.value);
            } else {
              return this._def.out._parseAsync({
                data: inResult.value,
                path: ctx.path,
                parent: ctx
              });
            }
          };
          return handleAsync();
        } else {
          const inResult = this._def.in._parseSync({
            data: ctx.data,
            path: ctx.path,
            parent: ctx
          });
          if (inResult.status === "aborted")
            return INVALID;
          if (inResult.status === "dirty") {
            status.dirty();
            return {
              status: "dirty",
              value: inResult.value
            };
          } else {
            return this._def.out._parseSync({
              data: inResult.value,
              path: ctx.path,
              parent: ctx
            });
          }
        }
      }
      static create(a, b) {
        return new _ZodPipeline({
          in: a,
          out: b,
          typeName: ZodFirstPartyTypeKind.ZodPipeline
        });
      }
    };
    ZodReadonly = class extends ZodType {
      _parse(input) {
        const result = this._def.innerType._parse(input);
        const freeze = (data) => {
          if (isValid(data)) {
            data.value = Object.freeze(data.value);
          }
          return data;
        };
        return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
      }
      unwrap() {
        return this._def.innerType;
      }
    };
    ZodReadonly.create = (type, params) => {
      return new ZodReadonly({
        innerType: type,
        typeName: ZodFirstPartyTypeKind.ZodReadonly,
        ...processCreateParams(params)
      });
    };
    late = {
      object: ZodObject.lazycreate
    };
    (function(ZodFirstPartyTypeKind2) {
      ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
      ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
      ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
      ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
      ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
      ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
      ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
      ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
      ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
      ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
      ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
      ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
      ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
      ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
      ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
      ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
      ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
      ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
      ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
      ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
      ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
      ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
      ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
      ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
      ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
      ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
      ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
      ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
      ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
      ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
      ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
      ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
      ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
      ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
      ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
      ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
    })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
    instanceOfType = (cls, params = {
      message: `Input not instance of ${cls.name}`
    }) => custom((data) => data instanceof cls, params);
    stringType = ZodString.create;
    numberType = ZodNumber.create;
    nanType = ZodNaN.create;
    bigIntType = ZodBigInt.create;
    booleanType = ZodBoolean.create;
    dateType = ZodDate.create;
    symbolType = ZodSymbol.create;
    undefinedType = ZodUndefined.create;
    nullType = ZodNull.create;
    anyType = ZodAny.create;
    unknownType = ZodUnknown.create;
    neverType = ZodNever.create;
    voidType = ZodVoid.create;
    arrayType = ZodArray.create;
    objectType = ZodObject.create;
    strictObjectType = ZodObject.strictCreate;
    unionType = ZodUnion.create;
    discriminatedUnionType = ZodDiscriminatedUnion.create;
    intersectionType = ZodIntersection.create;
    tupleType = ZodTuple.create;
    recordType = ZodRecord.create;
    mapType = ZodMap.create;
    setType = ZodSet.create;
    functionType = ZodFunction.create;
    lazyType = ZodLazy.create;
    literalType = ZodLiteral.create;
    enumType = ZodEnum.create;
    nativeEnumType = ZodNativeEnum.create;
    promiseType = ZodPromise.create;
    effectsType = ZodEffects.create;
    optionalType = ZodOptional.create;
    nullableType = ZodNullable.create;
    preprocessType = ZodEffects.createWithPreprocess;
    pipelineType = ZodPipeline.create;
    ostring = () => stringType().optional();
    onumber = () => numberType().optional();
    oboolean = () => booleanType().optional();
    coerce = {
      string: ((arg) => ZodString.create({ ...arg, coerce: true })),
      number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
      boolean: ((arg) => ZodBoolean.create({
        ...arg,
        coerce: true
      })),
      bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
      date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
    };
    NEVER = INVALID;
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
var external_exports = {};
__export(external_exports, {
  BRAND: () => BRAND,
  DIRTY: () => DIRTY,
  EMPTY_PATH: () => EMPTY_PATH,
  INVALID: () => INVALID,
  NEVER: () => NEVER,
  OK: () => OK,
  ParseStatus: () => ParseStatus,
  Schema: () => ZodType,
  ZodAny: () => ZodAny,
  ZodArray: () => ZodArray,
  ZodBigInt: () => ZodBigInt,
  ZodBoolean: () => ZodBoolean,
  ZodBranded: () => ZodBranded,
  ZodCatch: () => ZodCatch,
  ZodDate: () => ZodDate,
  ZodDefault: () => ZodDefault,
  ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
  ZodEffects: () => ZodEffects,
  ZodEnum: () => ZodEnum,
  ZodError: () => ZodError,
  ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
  ZodFunction: () => ZodFunction,
  ZodIntersection: () => ZodIntersection,
  ZodIssueCode: () => ZodIssueCode,
  ZodLazy: () => ZodLazy,
  ZodLiteral: () => ZodLiteral,
  ZodMap: () => ZodMap,
  ZodNaN: () => ZodNaN,
  ZodNativeEnum: () => ZodNativeEnum,
  ZodNever: () => ZodNever,
  ZodNull: () => ZodNull,
  ZodNullable: () => ZodNullable,
  ZodNumber: () => ZodNumber,
  ZodObject: () => ZodObject,
  ZodOptional: () => ZodOptional,
  ZodParsedType: () => ZodParsedType,
  ZodPipeline: () => ZodPipeline,
  ZodPromise: () => ZodPromise,
  ZodReadonly: () => ZodReadonly,
  ZodRecord: () => ZodRecord,
  ZodSchema: () => ZodType,
  ZodSet: () => ZodSet,
  ZodString: () => ZodString,
  ZodSymbol: () => ZodSymbol,
  ZodTransformer: () => ZodEffects,
  ZodTuple: () => ZodTuple,
  ZodType: () => ZodType,
  ZodUndefined: () => ZodUndefined,
  ZodUnion: () => ZodUnion,
  ZodUnknown: () => ZodUnknown,
  ZodVoid: () => ZodVoid,
  addIssueToContext: () => addIssueToContext,
  any: () => anyType,
  array: () => arrayType,
  bigint: () => bigIntType,
  boolean: () => booleanType,
  coerce: () => coerce,
  custom: () => custom,
  date: () => dateType,
  datetimeRegex: () => datetimeRegex,
  defaultErrorMap: () => en_default,
  discriminatedUnion: () => discriminatedUnionType,
  effect: () => effectsType,
  enum: () => enumType,
  function: () => functionType,
  getErrorMap: () => getErrorMap,
  getParsedType: () => getParsedType,
  instanceof: () => instanceOfType,
  intersection: () => intersectionType,
  isAborted: () => isAborted,
  isAsync: () => isAsync,
  isDirty: () => isDirty,
  isValid: () => isValid,
  late: () => late,
  lazy: () => lazyType,
  literal: () => literalType,
  makeIssue: () => makeIssue,
  map: () => mapType,
  nan: () => nanType,
  nativeEnum: () => nativeEnumType,
  never: () => neverType,
  null: () => nullType,
  nullable: () => nullableType,
  number: () => numberType,
  object: () => objectType,
  objectUtil: () => objectUtil,
  oboolean: () => oboolean,
  onumber: () => onumber,
  optional: () => optionalType,
  ostring: () => ostring,
  pipeline: () => pipelineType,
  preprocess: () => preprocessType,
  promise: () => promiseType,
  quotelessJson: () => quotelessJson,
  record: () => recordType,
  set: () => setType,
  setErrorMap: () => setErrorMap,
  strictObject: () => strictObjectType,
  string: () => stringType,
  symbol: () => symbolType,
  transformer: () => effectsType,
  tuple: () => tupleType,
  undefined: () => undefinedType,
  union: () => unionType,
  unknown: () => unknownType,
  util: () => util,
  void: () => voidType
});
var init_external = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js"() {
    init_errors();
    init_parseUtil();
    init_typeAliases();
    init_util();
    init_types();
    init_ZodError();
  }
});

// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/index.js
var init_zod = __esm({
  "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/index.js"() {
    init_external();
    init_external();
  }
});

// ../core/dist/types.js
var nullLogger, ArtifactTypeSchema, ArtifactSchema, VerdictSeveritySchema, ThreatSchema, DecisionSchema, SensitivitySchema, UrlCheckConfigSchema, CacheConfigSchema, LoggingConfigSchema, OperationalLogLevelSchema, OperationalLoggingConfigSchema, FileCheckConfigSchema, PackageCheckConfigSchema, AmsiCheckConfigSchema, SkillCheckConfigSchema, DEFAULT_PI_HIGH_RISK_THRESHOLD, DEFAULT_PI_MEDIUM_RISK_THRESHOLD, DEFAULT_PI_TELEMETRY_THRESHOLD, PiCheckConfigSchema, ExceptionDecisionSchema, ExceptionMatchSchema, ExceptionRuleSchema, ExceptionsFileSchema, ExceptionsConfigSchema, ConfigSchema, HookTypeSchema;
var init_types2 = __esm({
  "../core/dist/types.js"() {
    "use strict";
    init_zod();
    nullLogger = {
      debug() {
      },
      info() {
      },
      warn() {
      },
      error() {
      }
    };
    ArtifactTypeSchema = external_exports.enum(["url", "command", "file_path", "content"]);
    ArtifactSchema = external_exports.object({
      type: ArtifactTypeSchema,
      value: external_exports.string(),
      context: external_exports.string().optional()
    });
    VerdictSeveritySchema = external_exports.enum(["info", "warning", "critical"]);
    ThreatSchema = external_exports.object({
      id: external_exports.string(),
      version: external_exports.number().int().optional(),
      category: external_exports.string(),
      severity: VerdictSeveritySchema,
      confidence: external_exports.number(),
      pattern: external_exports.string(),
      match_on: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]),
      title: external_exports.string(),
      expires_at: external_exports.string().nullable().optional(),
      revoked: external_exports.boolean().optional().default(false),
      flags: external_exports.array(external_exports.string()).optional().default([])
    });
    DecisionSchema = external_exports.enum(["allow", "deny", "ask"]);
    SensitivitySchema = external_exports.enum(["paranoid", "balanced", "relaxed"]);
    UrlCheckConfigSchema = external_exports.object({
      endpoint: external_exports.string().optional(),
      timeout_seconds: external_exports.number().default(5),
      enabled: external_exports.boolean().default(true)
    });
    CacheConfigSchema = external_exports.object({
      enabled: external_exports.boolean().default(true),
      ttl_malicious_seconds: external_exports.number().default(3600),
      ttl_clean_seconds: external_exports.number().default(86400),
      path: external_exports.string().default("~/.sage/cache.json")
    });
    LoggingConfigSchema = external_exports.object({
      enabled: external_exports.boolean().default(true),
      log_clean: external_exports.boolean().default(false),
      path: external_exports.string().default("~/.sage/audit.jsonl"),
      max_bytes: external_exports.number().int().min(0).default(5 * 1024 * 1024),
      max_files: external_exports.number().int().min(0).default(3)
    });
    OperationalLogLevelSchema = external_exports.enum(["debug", "info", "warn", "error"]);
    OperationalLoggingConfigSchema = external_exports.object({
      enabled: external_exports.boolean().default(true),
      level: OperationalLogLevelSchema.default("info"),
      path: external_exports.string().default("~/.sage/operational.jsonl"),
      max_bytes: external_exports.number().int().min(0).default(5 * 1024 * 1024),
      max_files: external_exports.number().int().min(0).default(3)
    });
    FileCheckConfigSchema = external_exports.object({
      endpoint: external_exports.string().optional(),
      timeout_seconds: external_exports.number().default(5),
      enabled: external_exports.boolean().default(true)
    });
    PackageCheckConfigSchema = external_exports.object({
      enabled: external_exports.boolean().default(true),
      timeout_seconds: external_exports.number().default(5)
      // v1: all scoped packages (@scope/pkg) are skipped automatically.
      // Future: add private_scopes / public_scopes config for fine-grained control.
    });
    AmsiCheckConfigSchema = external_exports.object({
      enabled: external_exports.boolean().default(true)
    });
    SkillCheckConfigSchema = external_exports.object({
      enabled: external_exports.boolean().default(true),
      cache_ttl_days: external_exports.number().min(0).default(1),
      /**
       * Upload unknown skills (never seen by the analyzer) for deep content
       * analysis. When false, the scan still looks skills up by content hash and
       * still flags known-risky ones — but no skill content ever leaves the
       * machine and the upload worker never runs (lookup-only mode).
       */
      upload_enabled: external_exports.boolean().default(true)
    });
    DEFAULT_PI_HIGH_RISK_THRESHOLD = 0.99;
    DEFAULT_PI_MEDIUM_RISK_THRESHOLD = 0.5;
    DEFAULT_PI_TELEMETRY_THRESHOLD = 0.95;
    PiCheckConfigSchema = external_exports.object({
      enabled: external_exports.boolean().default(false),
      max_content_length: external_exports.number().default(16384),
      model_path: external_exports.string().optional()
    });
    ExceptionDecisionSchema = external_exports.enum(["allow", "deny"]);
    ExceptionMatchSchema = external_exports.enum(["executable", "domain", "path", "plugin", "regex"]);
    ExceptionRuleSchema = external_exports.object({
      id: external_exports.string().optional(),
      decision: ExceptionDecisionSchema,
      match: ExceptionMatchSchema,
      pattern: external_exports.string(),
      reason: external_exports.string().optional()
    });
    ExceptionsFileSchema = external_exports.object({
      rules: external_exports.array(ExceptionRuleSchema).default([])
    });
    ExceptionsConfigSchema = external_exports.object({
      path: external_exports.string().default("~/.sage/exceptions.json")
    });
    ConfigSchema = external_exports.object({
      url_check: UrlCheckConfigSchema.default({}),
      file_check: FileCheckConfigSchema.default({}),
      package_check: PackageCheckConfigSchema.default({}),
      amsi_check: AmsiCheckConfigSchema.default({}),
      skill_check: SkillCheckConfigSchema.default({}),
      pi_check: PiCheckConfigSchema.default({}),
      heuristics_enabled: external_exports.boolean().default(true),
      cache: CacheConfigSchema.default({}),
      exceptions: ExceptionsConfigSchema.default({}),
      logging: LoggingConfigSchema.default({}),
      operational_logging: OperationalLoggingConfigSchema.default({}),
      sensitivity: SensitivitySchema.default("balanced"),
      disabled_threats: external_exports.array(external_exports.string()).default([]),
      announce_clean_scans: external_exports.boolean().default(true),
      brand_key: external_exports.string().min(1).max(32).regex(/^[a-z0-9_-]+$/u).optional(),
      community_iq: external_exports.boolean().default(true)
    });
    HookTypeSchema = external_exports.enum([
      "PreToolUse",
      "PostToolUse",
      "SessionStart",
      "GatewayStart",
      "BeforeAgentStart",
      "MessagesTransform"
    ]);
  }
});

// ../core/dist/config.js
var config_exports = {};
__export(config_exports, {
  HOOK_TIMEOUT_SECONDS: () => HOOK_TIMEOUT_SECONDS,
  MS_PER_DAY: () => MS_PER_DAY,
  SAGE_DIR: () => SAGE_DIR,
  defaultConfigPath: () => defaultConfigPath,
  getClaudeConfigDir: () => getClaudeConfigDir,
  isFreshTimestamp: () => isFreshTimestamp,
  loadConfig: () => loadConfig,
  loadConfigSync: () => loadConfigSync,
  readExplicitSkillUploadEnabled: () => readExplicitSkillUploadEnabled,
  resolvePath: () => resolvePath,
  skillCacheTtlMs: () => skillCacheTtlMs
});
function skillCacheTtlMs(config2) {
  return Math.max(1, config2.skill_check.cache_ttl_days) * MS_PER_DAY;
}
function isFreshTimestamp(ts, ttlMs, now = Date.now()) {
  if (Number.isNaN(ts))
    return false;
  if (ts - now > CLOCK_SKEW_TOLERANCE_MS)
    return false;
  return now - ts < ttlMs;
}
function resolvedSageDir() {
  return resolvePath(SAGE_DIR);
}
function defaultConfigPath() {
  return (0, import_node_path2.join)(resolvedSageDir(), "config.json");
}
function defaultCachePath() {
  return (0, import_node_path2.join)(resolvedSageDir(), "cache.json");
}
function defaultExceptionsPath() {
  return (0, import_node_path2.join)(resolvedSageDir(), "exceptions.json");
}
function defaultAuditPath() {
  return (0, import_node_path2.join)(resolvedSageDir(), "audit.jsonl");
}
function defaultOperationalLogPath() {
  return (0, import_node_path2.join)(resolvedSageDir(), "operational.jsonl");
}
function resolvePath(pathStr) {
  if (pathStr.startsWith("~/") || pathStr === "~") {
    const home = getHomeDir();
    return (0, import_node_path2.join)(home, pathStr.slice(1));
  }
  return pathStr;
}
function getClaudeConfigDir() {
  const envDir = process.env.CLAUDE_CONFIG_DIR;
  if (envDir)
    return resolvePath(envDir);
  return resolvePath("~/.claude");
}
function isWithinDirectory(baseDir, targetPath) {
  const rel = (0, import_node_path2.relative)(baseDir, targetPath);
  if (rel === "")
    return true;
  if ((0, import_node_path2.isAbsolute)(rel))
    return false;
  return rel !== ".." && !rel.startsWith(`..${import_node_path2.sep}`);
}
function normalizeStateFilePath(configuredPath, fallbackPath, field, logger) {
  const sageDir = resolvedSageDir();
  const trimmed = configuredPath.trim();
  if (trimmed === "") {
    logger.warn(`Config ${field}.path is empty; using default`, {
      configuredPath,
      defaultPath: fallbackPath
    });
    return fallbackPath;
  }
  const expanded = resolvePath(trimmed);
  const resolved = (0, import_node_path2.isAbsolute)(expanded) ? (0, import_node_path2.resolve)(expanded) : (0, import_node_path2.resolve)(sageDir, expanded);
  if (isWithinDirectory(sageDir, resolved)) {
    if (resolved === sageDir) {
      logger.warn(`Config ${field}.path must point to a file; using default`, {
        configuredPath,
        defaultPath: fallbackPath
      });
      return fallbackPath;
    }
    return resolved;
  }
  logger.warn(`Config ${field}.path escapes ${sageDir}; using default`, {
    configuredPath,
    defaultPath: fallbackPath
  });
  return fallbackPath;
}
function sanitizeBrandKey(data, logger) {
  const brandKey = data.brand_key;
  if (brandKey === void 0)
    return data;
  if (typeof brandKey === "string" && brandKey.length >= 1 && brandKey.length <= 32 && BRAND_KEY_RE.test(brandKey)) {
    return data;
  }
  logger.warn(`Invalid brand_key in config - ignoring`, { brand_key: brandKey });
  const { brand_key: _, ...rest } = data;
  return rest;
}
function sanitizeConfigPaths(config2, logger) {
  const cachePath = defaultCachePath();
  const exceptionsPath = defaultExceptionsPath();
  const auditPath = defaultAuditPath();
  const operationalLogPath = defaultOperationalLogPath();
  return {
    ...config2,
    cache: {
      ...config2.cache,
      path: normalizeStateFilePath(config2.cache.path, cachePath, "cache", logger)
    },
    exceptions: {
      ...config2.exceptions,
      path: normalizeStateFilePath(config2.exceptions.path, exceptionsPath, "exceptions", logger)
    },
    logging: {
      ...config2.logging,
      path: normalizeStateFilePath(config2.logging.path, auditPath, "logging", logger)
    },
    operational_logging: {
      ...config2.operational_logging,
      path: normalizeStateFilePath(config2.operational_logging.path, operationalLogPath, "operational_logging", logger)
    }
  };
}
function defaultConfig(logger) {
  return sanitizeConfigPaths(ConfigSchema.parse({}), logger);
}
function parseConfig(raw, path, logger) {
  let data;
  try {
    data = JSON.parse(raw);
  } catch (e) {
    logger.warn(`Failed to parse config from ${path}`, { error: String(e) });
    return defaultConfig(logger);
  }
  if (typeof data !== "object" || data === null || Array.isArray(data)) {
    logger.warn(`Config file ${path} does not contain a JSON object`);
    return defaultConfig(logger);
  }
  const sanitized = sanitizeBrandKey(data, logger);
  try {
    return sanitizeConfigPaths(ConfigSchema.parse(sanitized), logger);
  } catch (e) {
    logger.warn(`Config validation failed, using defaults`, { error: String(e) });
    return defaultConfig(logger);
  }
}
async function readExplicitSkillUploadEnabled(configPath, logger = nullLogger) {
  const path = configPath ? resolvePath(configPath) : defaultConfigPath();
  try {
    const data = JSON.parse(await getFileContent(path));
    const skillCheck = data.skill_check;
    if (skillCheck && typeof skillCheck === "object" && !Array.isArray(skillCheck) && "upload_enabled" in skillCheck) {
      const value = skillCheck.upload_enabled;
      if (typeof value === "boolean")
        return { present: true, value };
      logger.warn("Config skill_check.upload_enabled is not a boolean; ignoring", { value });
    }
  } catch {
  }
  return { present: false, value: false };
}
async function loadConfig(configPath, logger = nullLogger) {
  const path = configPath ? resolvePath(configPath) : defaultConfigPath();
  try {
    return parseConfig(await getFileContent(path), path, logger);
  } catch {
    return defaultConfig(logger);
  }
}
function loadConfigSync(configPath, logger = nullLogger) {
  const path = configPath ? resolvePath(configPath) : defaultConfigPath();
  try {
    return parseConfig(getFileContentSync(path), path, logger);
  } catch {
    return defaultConfig(logger);
  }
}
var import_node_path2, SAGE_DIR, HOOK_TIMEOUT_SECONDS, MS_PER_DAY, CLOCK_SKEW_TOLERANCE_MS, BRAND_KEY_RE;
var init_config = __esm({
  "../core/dist/config.js"() {
    "use strict";
    import_node_path2 = require("node:path");
    init_file_utils();
    init_types2();
    SAGE_DIR = "~/.sage";
    HOOK_TIMEOUT_SECONDS = 8;
    MS_PER_DAY = 24 * 60 * 60 * 1e3;
    CLOCK_SKEW_TOLERANCE_MS = 5 * 60 * 1e3;
    BRAND_KEY_RE = /^[a-z0-9_-]+$/u;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/constants.js
var require_constants = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/constants.js"(exports2, module2) {
    "use strict";
    var SEMVER_SPEC_VERSION = "2.0.0";
    var MAX_LENGTH = 256;
    var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
    9007199254740991;
    var MAX_SAFE_COMPONENT_LENGTH = 16;
    var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
    var RELEASE_TYPES = [
      "major",
      "premajor",
      "minor",
      "preminor",
      "patch",
      "prepatch",
      "prerelease"
    ];
    module2.exports = {
      MAX_LENGTH,
      MAX_SAFE_COMPONENT_LENGTH,
      MAX_SAFE_BUILD_LENGTH,
      MAX_SAFE_INTEGER,
      RELEASE_TYPES,
      SEMVER_SPEC_VERSION,
      FLAG_INCLUDE_PRERELEASE: 1,
      FLAG_LOOSE: 2
    };
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/debug.js
var require_debug = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/debug.js"(exports2, module2) {
    "use strict";
    var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
    };
    module2.exports = debug;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/re.js
var require_re = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/re.js"(exports2, module2) {
    "use strict";
    var {
      MAX_SAFE_COMPONENT_LENGTH,
      MAX_SAFE_BUILD_LENGTH,
      MAX_LENGTH
    } = require_constants();
    var debug = require_debug();
    exports2 = module2.exports = {};
    var re = exports2.re = [];
    var safeRe = exports2.safeRe = [];
    var src = exports2.src = [];
    var safeSrc = exports2.safeSrc = [];
    var t = exports2.t = {};
    var R = 0;
    var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
    var safeRegexReplacements = [
      ["\\s", 1],
      ["\\d", MAX_LENGTH],
      [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
    ];
    var makeSafeRegex = (value) => {
      for (const [token, max] of safeRegexReplacements) {
        value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
      }
      return value;
    };
    var createToken = (name, value, isGlobal) => {
      const safe = makeSafeRegex(value);
      const index = R++;
      debug(name, index, value);
      t[name] = index;
      src[index] = value;
      safeSrc[index] = safe;
      re[index] = new RegExp(value, isGlobal ? "g" : void 0);
      safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
    };
    createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
    createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
    createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
    createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
    createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
    createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
    createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
    createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
    createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
    createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
    createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
    createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
    createToken("FULL", `^${src[t.FULLPLAIN]}$`);
    createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
    createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
    createToken("GTLT", "((?:<|>)?=?)");
    createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
    createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
    createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
    createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
    createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
    createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
    createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
    createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
    createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
    createToken("COERCERTL", src[t.COERCE], true);
    createToken("COERCERTLFULL", src[t.COERCEFULL], true);
    createToken("LONETILDE", "(?:~>?)");
    createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
    exports2.tildeTrimReplace = "$1~";
    createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
    createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
    createToken("LONECARET", "(?:\\^)");
    createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
    exports2.caretTrimReplace = "$1^";
    createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
    createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
    createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
    createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
    createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
    exports2.comparatorTrimReplace = "$1$2$3";
    createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
    createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
    createToken("STAR", "(<|>)?=?\\s*\\*");
    createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
    createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/parse-options.js
var require_parse_options = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/parse-options.js"(exports2, module2) {
    "use strict";
    var looseOption = Object.freeze({ loose: true });
    var emptyOpts = Object.freeze({});
    var parseOptions = (options) => {
      if (!options) {
        return emptyOpts;
      }
      if (typeof options !== "object") {
        return looseOption;
      }
      return options;
    };
    module2.exports = parseOptions;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/identifiers.js
var require_identifiers = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/identifiers.js"(exports2, module2) {
    "use strict";
    var numeric = /^[0-9]+$/;
    var compareIdentifiers = (a, b) => {
      if (typeof a === "number" && typeof b === "number") {
        return a === b ? 0 : a < b ? -1 : 1;
      }
      const anum = numeric.test(a);
      const bnum = numeric.test(b);
      if (anum && bnum) {
        a = +a;
        b = +b;
      }
      return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
    };
    var rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
    module2.exports = {
      compareIdentifiers,
      rcompareIdentifiers
    };
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/semver.js
var require_semver = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/semver.js"(exports2, module2) {
    "use strict";
    var debug = require_debug();
    var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
    var { safeRe: re, t } = require_re();
    var parseOptions = require_parse_options();
    var { compareIdentifiers } = require_identifiers();
    var SemVer = class _SemVer {
      constructor(version, options) {
        options = parseOptions(options);
        if (version instanceof _SemVer) {
          if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
            return version;
          } else {
            version = version.version;
          }
        } else if (typeof version !== "string") {
          throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
        }
        if (version.length > MAX_LENGTH) {
          throw new TypeError(
            `version is longer than ${MAX_LENGTH} characters`
          );
        }
        debug("SemVer", version, options);
        this.options = options;
        this.loose = !!options.loose;
        this.includePrerelease = !!options.includePrerelease;
        const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
        if (!m) {
          throw new TypeError(`Invalid Version: ${version}`);
        }
        this.raw = version;
        this.major = +m[1];
        this.minor = +m[2];
        this.patch = +m[3];
        if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
          throw new TypeError("Invalid major version");
        }
        if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
          throw new TypeError("Invalid minor version");
        }
        if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
          throw new TypeError("Invalid patch version");
        }
        if (!m[4]) {
          this.prerelease = [];
        } else {
          this.prerelease = m[4].split(".").map((id) => {
            if (/^[0-9]+$/.test(id)) {
              const num = +id;
              if (num >= 0 && num < MAX_SAFE_INTEGER) {
                return num;
              }
            }
            return id;
          });
        }
        this.build = m[5] ? m[5].split(".") : [];
        this.format();
      }
      format() {
        this.version = `${this.major}.${this.minor}.${this.patch}`;
        if (this.prerelease.length) {
          this.version += `-${this.prerelease.join(".")}`;
        }
        return this.version;
      }
      toString() {
        return this.version;
      }
      compare(other) {
        debug("SemVer.compare", this.version, this.options, other);
        if (!(other instanceof _SemVer)) {
          if (typeof other === "string" && other === this.version) {
            return 0;
          }
          other = new _SemVer(other, this.options);
        }
        if (other.version === this.version) {
          return 0;
        }
        return this.compareMain(other) || this.comparePre(other);
      }
      compareMain(other) {
        if (!(other instanceof _SemVer)) {
          other = new _SemVer(other, this.options);
        }
        if (this.major < other.major) {
          return -1;
        }
        if (this.major > other.major) {
          return 1;
        }
        if (this.minor < other.minor) {
          return -1;
        }
        if (this.minor > other.minor) {
          return 1;
        }
        if (this.patch < other.patch) {
          return -1;
        }
        if (this.patch > other.patch) {
          return 1;
        }
        return 0;
      }
      comparePre(other) {
        if (!(other instanceof _SemVer)) {
          other = new _SemVer(other, this.options);
        }
        if (this.prerelease.length && !other.prerelease.length) {
          return -1;
        } else if (!this.prerelease.length && other.prerelease.length) {
          return 1;
        } else if (!this.prerelease.length && !other.prerelease.length) {
          return 0;
        }
        let i = 0;
        do {
          const a = this.prerelease[i];
          const b = other.prerelease[i];
          debug("prerelease compare", i, a, b);
          if (a === void 0 && b === void 0) {
            return 0;
          } else if (b === void 0) {
            return 1;
          } else if (a === void 0) {
            return -1;
          } else if (a === b) {
            continue;
          } else {
            return compareIdentifiers(a, b);
          }
        } while (++i);
      }
      compareBuild(other) {
        if (!(other instanceof _SemVer)) {
          other = new _SemVer(other, this.options);
        }
        let i = 0;
        do {
          const a = this.build[i];
          const b = other.build[i];
          debug("build compare", i, a, b);
          if (a === void 0 && b === void 0) {
            return 0;
          } else if (b === void 0) {
            return 1;
          } else if (a === void 0) {
            return -1;
          } else if (a === b) {
            continue;
          } else {
            return compareIdentifiers(a, b);
          }
        } while (++i);
      }
      // preminor will bump the version up to the next minor release, and immediately
      // down to pre-release. premajor and prepatch work the same way.
      inc(release, identifier, identifierBase) {
        if (release.startsWith("pre")) {
          if (!identifier && identifierBase === false) {
            throw new Error("invalid increment argument: identifier is empty");
          }
          if (identifier) {
            const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
            if (!match || match[1] !== identifier) {
              throw new Error(`invalid identifier: ${identifier}`);
            }
          }
        }
        switch (release) {
          case "premajor":
            this.prerelease.length = 0;
            this.patch = 0;
            this.minor = 0;
            this.major++;
            this.inc("pre", identifier, identifierBase);
            break;
          case "preminor":
            this.prerelease.length = 0;
            this.patch = 0;
            this.minor++;
            this.inc("pre", identifier, identifierBase);
            break;
          case "prepatch":
            this.prerelease.length = 0;
            this.inc("patch", identifier, identifierBase);
            this.inc("pre", identifier, identifierBase);
            break;
          // If the input is a non-prerelease version, this acts the same as
          // prepatch.
          case "prerelease":
            if (this.prerelease.length === 0) {
              this.inc("patch", identifier, identifierBase);
            }
            this.inc("pre", identifier, identifierBase);
            break;
          case "release":
            if (this.prerelease.length === 0) {
              throw new Error(`version ${this.raw} is not a prerelease`);
            }
            this.prerelease.length = 0;
            break;
          case "major":
            if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
              this.major++;
            }
            this.minor = 0;
            this.patch = 0;
            this.prerelease = [];
            break;
          case "minor":
            if (this.patch !== 0 || this.prerelease.length === 0) {
              this.minor++;
            }
            this.patch = 0;
            this.prerelease = [];
            break;
          case "patch":
            if (this.prerelease.length === 0) {
              this.patch++;
            }
            this.prerelease = [];
            break;
          // This probably shouldn't be used publicly.
          // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
          case "pre": {
            const base = Number(identifierBase) ? 1 : 0;
            if (this.prerelease.length === 0) {
              this.prerelease = [base];
            } else {
              let i = this.prerelease.length;
              while (--i >= 0) {
                if (typeof this.prerelease[i] === "number") {
                  this.prerelease[i]++;
                  i = -2;
                }
              }
              if (i === -1) {
                if (identifier === this.prerelease.join(".") && identifierBase === false) {
                  throw new Error("invalid increment argument: identifier already exists");
                }
                this.prerelease.push(base);
              }
            }
            if (identifier) {
              let prerelease = [identifier, base];
              if (identifierBase === false) {
                prerelease = [identifier];
              }
              if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
                if (isNaN(this.prerelease[1])) {
                  this.prerelease = prerelease;
                }
              } else {
                this.prerelease = prerelease;
              }
            }
            break;
          }
          default:
            throw new Error(`invalid increment argument: ${release}`);
        }
        this.raw = this.format();
        if (this.build.length) {
          this.raw += `+${this.build.join(".")}`;
        }
        return this;
      }
    };
    module2.exports = SemVer;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/parse.js
var require_parse = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/parse.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var parse = (version, options, throwErrors = false) => {
      if (version instanceof SemVer) {
        return version;
      }
      try {
        return new SemVer(version, options);
      } catch (er) {
        if (!throwErrors) {
          return null;
        }
        throw er;
      }
    };
    module2.exports = parse;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/valid.js
var require_valid = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/valid.js"(exports2, module2) {
    "use strict";
    var parse = require_parse();
    var valid = (version, options) => {
      const v = parse(version, options);
      return v ? v.version : null;
    };
    module2.exports = valid;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/clean.js
var require_clean = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/clean.js"(exports2, module2) {
    "use strict";
    var parse = require_parse();
    var clean = (version, options) => {
      const s = parse(version.trim().replace(/^[=v]+/, ""), options);
      return s ? s.version : null;
    };
    module2.exports = clean;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/inc.js
var require_inc = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/inc.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var inc = (version, release, options, identifier, identifierBase) => {
      if (typeof options === "string") {
        identifierBase = identifier;
        identifier = options;
        options = void 0;
      }
      try {
        return new SemVer(
          version instanceof SemVer ? version.version : version,
          options
        ).inc(release, identifier, identifierBase).version;
      } catch (er) {
        return null;
      }
    };
    module2.exports = inc;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/diff.js
var require_diff = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/diff.js"(exports2, module2) {
    "use strict";
    var parse = require_parse();
    var diff = (version1, version2) => {
      const v1 = parse(version1, null, true);
      const v2 = parse(version2, null, true);
      const comparison = v1.compare(v2);
      if (comparison === 0) {
        return null;
      }
      const v1Higher = comparison > 0;
      const highVersion = v1Higher ? v1 : v2;
      const lowVersion = v1Higher ? v2 : v1;
      const highHasPre = !!highVersion.prerelease.length;
      const lowHasPre = !!lowVersion.prerelease.length;
      if (lowHasPre && !highHasPre) {
        if (!lowVersion.patch && !lowVersion.minor) {
          return "major";
        }
        if (lowVersion.compareMain(highVersion) === 0) {
          if (lowVersion.minor && !lowVersion.patch) {
            return "minor";
          }
          return "patch";
        }
      }
      const prefix = highHasPre ? "pre" : "";
      if (v1.major !== v2.major) {
        return prefix + "major";
      }
      if (v1.minor !== v2.minor) {
        return prefix + "minor";
      }
      if (v1.patch !== v2.patch) {
        return prefix + "patch";
      }
      return "prerelease";
    };
    module2.exports = diff;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/major.js
var require_major = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/major.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var major = (a, loose) => new SemVer(a, loose).major;
    module2.exports = major;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/minor.js
var require_minor = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/minor.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var minor = (a, loose) => new SemVer(a, loose).minor;
    module2.exports = minor;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/patch.js
var require_patch = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/patch.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var patch = (a, loose) => new SemVer(a, loose).patch;
    module2.exports = patch;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/prerelease.js
var require_prerelease = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/prerelease.js"(exports2, module2) {
    "use strict";
    var parse = require_parse();
    var prerelease = (version, options) => {
      const parsed = parse(version, options);
      return parsed && parsed.prerelease.length ? parsed.prerelease : null;
    };
    module2.exports = prerelease;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare.js
var require_compare = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
    module2.exports = compare;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rcompare.js
var require_rcompare = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rcompare.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var rcompare = (a, b, loose) => compare(b, a, loose);
    module2.exports = rcompare;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-loose.js
var require_compare_loose = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-loose.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var compareLoose = (a, b) => compare(a, b, true);
    module2.exports = compareLoose;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-build.js
var require_compare_build = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-build.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var compareBuild = (a, b, loose) => {
      const versionA = new SemVer(a, loose);
      const versionB = new SemVer(b, loose);
      return versionA.compare(versionB) || versionA.compareBuild(versionB);
    };
    module2.exports = compareBuild;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/sort.js
var require_sort = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/sort.js"(exports2, module2) {
    "use strict";
    var compareBuild = require_compare_build();
    var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
    module2.exports = sort;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rsort.js
var require_rsort = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rsort.js"(exports2, module2) {
    "use strict";
    var compareBuild = require_compare_build();
    var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
    module2.exports = rsort;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gt.js
var require_gt = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gt.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var gt = (a, b, loose) => compare(a, b, loose) > 0;
    module2.exports = gt;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lt.js
var require_lt = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lt.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var lt = (a, b, loose) => compare(a, b, loose) < 0;
    module2.exports = lt;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/eq.js
var require_eq = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/eq.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var eq = (a, b, loose) => compare(a, b, loose) === 0;
    module2.exports = eq;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/neq.js
var require_neq = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/neq.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var neq = (a, b, loose) => compare(a, b, loose) !== 0;
    module2.exports = neq;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gte.js
var require_gte = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gte.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var gte = (a, b, loose) => compare(a, b, loose) >= 0;
    module2.exports = gte;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lte.js
var require_lte = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lte.js"(exports2, module2) {
    "use strict";
    var compare = require_compare();
    var lte = (a, b, loose) => compare(a, b, loose) <= 0;
    module2.exports = lte;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/cmp.js
var require_cmp = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/cmp.js"(exports2, module2) {
    "use strict";
    var eq = require_eq();
    var neq = require_neq();
    var gt = require_gt();
    var gte = require_gte();
    var lt = require_lt();
    var lte = require_lte();
    var cmp = (a, op, b, loose) => {
      switch (op) {
        case "===":
          if (typeof a === "object") {
            a = a.version;
          }
          if (typeof b === "object") {
            b = b.version;
          }
          return a === b;
        case "!==":
          if (typeof a === "object") {
            a = a.version;
          }
          if (typeof b === "object") {
            b = b.version;
          }
          return a !== b;
        case "":
        case "=":
        case "==":
          return eq(a, b, loose);
        case "!=":
          return neq(a, b, loose);
        case ">":
          return gt(a, b, loose);
        case ">=":
          return gte(a, b, loose);
        case "<":
          return lt(a, b, loose);
        case "<=":
          return lte(a, b, loose);
        default:
          throw new TypeError(`Invalid operator: ${op}`);
      }
    };
    module2.exports = cmp;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/coerce.js
var require_coerce = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/coerce.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var parse = require_parse();
    var { safeRe: re, t } = require_re();
    var coerce2 = (version, options) => {
      if (version instanceof SemVer) {
        return version;
      }
      if (typeof version === "number") {
        version = String(version);
      }
      if (typeof version !== "string") {
        return null;
      }
      options = options || {};
      let match = null;
      if (!options.rtl) {
        match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
      } else {
        const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
        let next;
        while ((next = coerceRtlRegex.exec(version)) && (!match || match.index + match[0].length !== version.length)) {
          if (!match || next.index + next[0].length !== match.index + match[0].length) {
            match = next;
          }
          coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
        }
        coerceRtlRegex.lastIndex = -1;
      }
      if (match === null) {
        return null;
      }
      const major = match[2];
      const minor = match[3] || "0";
      const patch = match[4] || "0";
      const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
      const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
      return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
    };
    module2.exports = coerce2;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/lrucache.js
var require_lrucache = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/lrucache.js"(exports2, module2) {
    "use strict";
    var LRUCache = class {
      constructor() {
        this.max = 1e3;
        this.map = /* @__PURE__ */ new Map();
      }
      get(key) {
        const value = this.map.get(key);
        if (value === void 0) {
          return void 0;
        } else {
          this.map.delete(key);
          this.map.set(key, value);
          return value;
        }
      }
      delete(key) {
        return this.map.delete(key);
      }
      set(key, value) {
        const deleted = this.delete(key);
        if (!deleted && value !== void 0) {
          if (this.map.size >= this.max) {
            const firstKey = this.map.keys().next().value;
            this.delete(firstKey);
          }
          this.map.set(key, value);
        }
        return this;
      }
    };
    module2.exports = LRUCache;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/range.js
var require_range = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/range.js"(exports2, module2) {
    "use strict";
    var SPACE_CHARACTERS = /\s+/g;
    var Range = class _Range {
      constructor(range, options) {
        options = parseOptions(options);
        if (range instanceof _Range) {
          if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
            return range;
          } else {
            return new _Range(range.raw, options);
          }
        }
        if (range instanceof Comparator) {
          this.raw = range.value;
          this.set = [[range]];
          this.formatted = void 0;
          return this;
        }
        this.options = options;
        this.loose = !!options.loose;
        this.includePrerelease = !!options.includePrerelease;
        this.raw = range.trim().replace(SPACE_CHARACTERS, " ");
        this.set = this.raw.split("||").map((r) => this.parseRange(r.trim())).filter((c) => c.length);
        if (!this.set.length) {
          throw new TypeError(`Invalid SemVer Range: ${this.raw}`);
        }
        if (this.set.length > 1) {
          const first = this.set[0];
          this.set = this.set.filter((c) => !isNullSet(c[0]));
          if (this.set.length === 0) {
            this.set = [first];
          } else if (this.set.length > 1) {
            for (const c of this.set) {
              if (c.length === 1 && isAny(c[0])) {
                this.set = [c];
                break;
              }
            }
          }
        }
        this.formatted = void 0;
      }
      get range() {
        if (this.formatted === void 0) {
          this.formatted = "";
          for (let i = 0; i < this.set.length; i++) {
            if (i > 0) {
              this.formatted += "||";
            }
            const comps = this.set[i];
            for (let k = 0; k < comps.length; k++) {
              if (k > 0) {
                this.formatted += " ";
              }
              this.formatted += comps[k].toString().trim();
            }
          }
        }
        return this.formatted;
      }
      format() {
        return this.range;
      }
      toString() {
        return this.range;
      }
      parseRange(range) {
        const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
        const memoKey = memoOpts + ":" + range;
        const cached = cache2.get(memoKey);
        if (cached) {
          return cached;
        }
        const loose = this.options.loose;
        const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
        range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
        debug("hyphen replace", range);
        range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
        debug("comparator trim", range);
        range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
        debug("tilde trim", range);
        range = range.replace(re[t.CARETTRIM], caretTrimReplace);
        debug("caret trim", range);
        let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
        if (loose) {
          rangeList = rangeList.filter((comp) => {
            debug("loose invalid filter", comp, this.options);
            return !!comp.match(re[t.COMPARATORLOOSE]);
          });
        }
        debug("range list", rangeList);
        const rangeMap = /* @__PURE__ */ new Map();
        const comparators = rangeList.map((comp) => new Comparator(comp, this.options));
        for (const comp of comparators) {
          if (isNullSet(comp)) {
            return [comp];
          }
          rangeMap.set(comp.value, comp);
        }
        if (rangeMap.size > 1 && rangeMap.has("")) {
          rangeMap.delete("");
        }
        const result = [...rangeMap.values()];
        cache2.set(memoKey, result);
        return result;
      }
      intersects(range, options) {
        if (!(range instanceof _Range)) {
          throw new TypeError("a Range is required");
        }
        return this.set.some((thisComparators) => {
          return isSatisfiable(thisComparators, options) && range.set.some((rangeComparators) => {
            return isSatisfiable(rangeComparators, options) && thisComparators.every((thisComparator) => {
              return rangeComparators.every((rangeComparator) => {
                return thisComparator.intersects(rangeComparator, options);
              });
            });
          });
        });
      }
      // if ANY of the sets match ALL of its comparators, then pass
      test(version) {
        if (!version) {
          return false;
        }
        if (typeof version === "string") {
          try {
            version = new SemVer(version, this.options);
          } catch (er) {
            return false;
          }
        }
        for (let i = 0; i < this.set.length; i++) {
          if (testSet(this.set[i], version, this.options)) {
            return true;
          }
        }
        return false;
      }
    };
    module2.exports = Range;
    var LRU = require_lrucache();
    var cache2 = new LRU();
    var parseOptions = require_parse_options();
    var Comparator = require_comparator();
    var debug = require_debug();
    var SemVer = require_semver();
    var {
      safeRe: re,
      t,
      comparatorTrimReplace,
      tildeTrimReplace,
      caretTrimReplace
    } = require_re();
    var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants();
    var isNullSet = (c) => c.value === "<0.0.0-0";
    var isAny = (c) => c.value === "";
    var isSatisfiable = (comparators, options) => {
      let result = true;
      const remainingComparators = comparators.slice();
      let testComparator = remainingComparators.pop();
      while (result && remainingComparators.length) {
        result = remainingComparators.every((otherComparator) => {
          return testComparator.intersects(otherComparator, options);
        });
        testComparator = remainingComparators.pop();
      }
      return result;
    };
    var parseComparator = (comp, options) => {
      comp = comp.replace(re[t.BUILD], "");
      debug("comp", comp, options);
      comp = replaceCarets(comp, options);
      debug("caret", comp);
      comp = replaceTildes(comp, options);
      debug("tildes", comp);
      comp = replaceXRanges(comp, options);
      debug("xrange", comp);
      comp = replaceStars(comp, options);
      debug("stars", comp);
      return comp;
    };
    var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
    var replaceTildes = (comp, options) => {
      return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
    };
    var replaceTilde = (comp, options) => {
      const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
      return comp.replace(r, (_, M, m, p, pr) => {
        debug("tilde", comp, _, M, m, p, pr);
        let ret;
        if (isX(M)) {
          ret = "";
        } else if (isX(m)) {
          ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
        } else if (isX(p)) {
          ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
        } else if (pr) {
          debug("replaceTilde pr", pr);
          ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
        } else {
          ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
        }
        debug("tilde return", ret);
        return ret;
      });
    };
    var replaceCarets = (comp, options) => {
      return comp.trim().split(/\s+/).map((c) => replaceCaret(c, options)).join(" ");
    };
    var replaceCaret = (comp, options) => {
      debug("caret", comp, options);
      const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
      const z = options.includePrerelease ? "-0" : "";
      return comp.replace(r, (_, M, m, p, pr) => {
        debug("caret", comp, _, M, m, p, pr);
        let ret;
        if (isX(M)) {
          ret = "";
        } else if (isX(m)) {
          ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
        } else if (isX(p)) {
          if (M === "0") {
            ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
          } else {
            ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
          }
        } else if (pr) {
          debug("replaceCaret pr", pr);
          if (M === "0") {
            if (m === "0") {
              ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
            } else {
              ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
            }
          } else {
            ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
          }
        } else {
          debug("no pr");
          if (M === "0") {
            if (m === "0") {
              ret = `>=${M}.${m}.${p}${z} <${M}.${m}.${+p + 1}-0`;
            } else {
              ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
            }
          } else {
            ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
          }
        }
        debug("caret return", ret);
        return ret;
      });
    };
    var replaceXRanges = (comp, options) => {
      debug("replaceXRanges", comp, options);
      return comp.split(/\s+/).map((c) => replaceXRange(c, options)).join(" ");
    };
    var replaceXRange = (comp, options) => {
      comp = comp.trim();
      const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
      return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
        debug("xRange", comp, ret, gtlt, M, m, p, pr);
        const xM = isX(M);
        const xm = xM || isX(m);
        const xp = xm || isX(p);
        const anyX = xp;
        if (gtlt === "=" && anyX) {
          gtlt = "";
        }
        pr = options.includePrerelease ? "-0" : "";
        if (xM) {
          if (gtlt === ">" || gtlt === "<") {
            ret = "<0.0.0-0";
          } else {
            ret = "*";
          }
        } else if (gtlt && anyX) {
          if (xm) {
            m = 0;
          }
          p = 0;
          if (gtlt === ">") {
            gtlt = ">=";
            if (xm) {
              M = +M + 1;
              m = 0;
              p = 0;
            } else {
              m = +m + 1;
              p = 0;
            }
          } else if (gtlt === "<=") {
            gtlt = "<";
            if (xm) {
              M = +M + 1;
            } else {
              m = +m + 1;
            }
          }
          if (gtlt === "<") {
            pr = "-0";
          }
          ret = `${gtlt + M}.${m}.${p}${pr}`;
        } else if (xm) {
          ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
        } else if (xp) {
          ret = `>=${M}.${m}.0${pr} <${M}.${+m + 1}.0-0`;
        }
        debug("xRange return", ret);
        return ret;
      });
    };
    var replaceStars = (comp, options) => {
      debug("replaceStars", comp, options);
      return comp.trim().replace(re[t.STAR], "");
    };
    var replaceGTE0 = (comp, options) => {
      debug("replaceGTE0", comp, options);
      return comp.trim().replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
    };
    var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
      if (isX(fM)) {
        from = "";
      } else if (isX(fm)) {
        from = `>=${fM}.0.0${incPr ? "-0" : ""}`;
      } else if (isX(fp)) {
        from = `>=${fM}.${fm}.0${incPr ? "-0" : ""}`;
      } else if (fpr) {
        from = `>=${from}`;
      } else {
        from = `>=${from}${incPr ? "-0" : ""}`;
      }
      if (isX(tM)) {
        to = "";
      } else if (isX(tm)) {
        to = `<${+tM + 1}.0.0-0`;
      } else if (isX(tp)) {
        to = `<${tM}.${+tm + 1}.0-0`;
      } else if (tpr) {
        to = `<=${tM}.${tm}.${tp}-${tpr}`;
      } else if (incPr) {
        to = `<${tM}.${tm}.${+tp + 1}-0`;
      } else {
        to = `<=${to}`;
      }
      return `${from} ${to}`.trim();
    };
    var testSet = (set, version, options) => {
      for (let i = 0; i < set.length; i++) {
        if (!set[i].test(version)) {
          return false;
        }
      }
      if (version.prerelease.length && !options.includePrerelease) {
        for (let i = 0; i < set.length; i++) {
          debug(set[i].semver);
          if (set[i].semver === Comparator.ANY) {
            continue;
          }
          if (set[i].semver.prerelease.length > 0) {
            const allowed = set[i].semver;
            if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
              return true;
            }
          }
        }
        return false;
      }
      return true;
    };
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/comparator.js
var require_comparator = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/comparator.js"(exports2, module2) {
    "use strict";
    var ANY = Symbol("SemVer ANY");
    var Comparator = class _Comparator {
      static get ANY() {
        return ANY;
      }
      constructor(comp, options) {
        options = parseOptions(options);
        if (comp instanceof _Comparator) {
          if (comp.loose === !!options.loose) {
            return comp;
          } else {
            comp = comp.value;
          }
        }
        comp = comp.trim().split(/\s+/).join(" ");
        debug("comparator", comp, options);
        this.options = options;
        this.loose = !!options.loose;
        this.parse(comp);
        if (this.semver === ANY) {
          this.value = "";
        } else {
          this.value = this.operator + this.semver.version;
        }
        debug("comp", this);
      }
      parse(comp) {
        const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
        const m = comp.match(r);
        if (!m) {
          throw new TypeError(`Invalid comparator: ${comp}`);
        }
        this.operator = m[1] !== void 0 ? m[1] : "";
        if (this.operator === "=") {
          this.operator = "";
        }
        if (!m[2]) {
          this.semver = ANY;
        } else {
          this.semver = new SemVer(m[2], this.options.loose);
        }
      }
      toString() {
        return this.value;
      }
      test(version) {
        debug("Comparator.test", version, this.options.loose);
        if (this.semver === ANY || version === ANY) {
          return true;
        }
        if (typeof version === "string") {
          try {
            version = new SemVer(version, this.options);
          } catch (er) {
            return false;
          }
        }
        return cmp(version, this.operator, this.semver, this.options);
      }
      intersects(comp, options) {
        if (!(comp instanceof _Comparator)) {
          throw new TypeError("a Comparator is required");
        }
        if (this.operator === "") {
          if (this.value === "") {
            return true;
          }
          return new Range(comp.value, options).test(this.value);
        } else if (comp.operator === "") {
          if (comp.value === "") {
            return true;
          }
          return new Range(this.value, options).test(comp.semver);
        }
        options = parseOptions(options);
        if (options.includePrerelease && (this.value === "<0.0.0-0" || comp.value === "<0.0.0-0")) {
          return false;
        }
        if (!options.includePrerelease && (this.value.startsWith("<0.0.0") || comp.value.startsWith("<0.0.0"))) {
          return false;
        }
        if (this.operator.startsWith(">") && comp.operator.startsWith(">")) {
          return true;
        }
        if (this.operator.startsWith("<") && comp.operator.startsWith("<")) {
          return true;
        }
        if (this.semver.version === comp.semver.version && this.operator.includes("=") && comp.operator.includes("=")) {
          return true;
        }
        if (cmp(this.semver, "<", comp.semver, options) && this.operator.startsWith(">") && comp.operator.startsWith("<")) {
          return true;
        }
        if (cmp(this.semver, ">", comp.semver, options) && this.operator.startsWith("<") && comp.operator.startsWith(">")) {
          return true;
        }
        return false;
      }
    };
    module2.exports = Comparator;
    var parseOptions = require_parse_options();
    var { safeRe: re, t } = require_re();
    var cmp = require_cmp();
    var debug = require_debug();
    var SemVer = require_semver();
    var Range = require_range();
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/satisfies.js
var require_satisfies = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/satisfies.js"(exports2, module2) {
    "use strict";
    var Range = require_range();
    var satisfies = (version, range, options) => {
      try {
        range = new Range(range, options);
      } catch (er) {
        return false;
      }
      return range.test(version);
    };
    module2.exports = satisfies;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/to-comparators.js
var require_to_comparators = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/to-comparators.js"(exports2, module2) {
    "use strict";
    var Range = require_range();
    var toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
    module2.exports = toComparators;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/max-satisfying.js
var require_max_satisfying = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/max-satisfying.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var Range = require_range();
    var maxSatisfying = (versions, range, options) => {
      let max = null;
      let maxSV = null;
      let rangeObj = null;
      try {
        rangeObj = new Range(range, options);
      } catch (er) {
        return null;
      }
      versions.forEach((v) => {
        if (rangeObj.test(v)) {
          if (!max || maxSV.compare(v) === -1) {
            max = v;
            maxSV = new SemVer(max, options);
          }
        }
      });
      return max;
    };
    module2.exports = maxSatisfying;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-satisfying.js
var require_min_satisfying = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-satisfying.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var Range = require_range();
    var minSatisfying = (versions, range, options) => {
      let min = null;
      let minSV = null;
      let rangeObj = null;
      try {
        rangeObj = new Range(range, options);
      } catch (er) {
        return null;
      }
      versions.forEach((v) => {
        if (rangeObj.test(v)) {
          if (!min || minSV.compare(v) === 1) {
            min = v;
            minSV = new SemVer(min, options);
          }
        }
      });
      return min;
    };
    module2.exports = minSatisfying;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-version.js
var require_min_version = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-version.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var Range = require_range();
    var gt = require_gt();
    var minVersion = (range, loose) => {
      range = new Range(range, loose);
      let minver = new SemVer("0.0.0");
      if (range.test(minver)) {
        return minver;
      }
      minver = new SemVer("0.0.0-0");
      if (range.test(minver)) {
        return minver;
      }
      minver = null;
      for (let i = 0; i < range.set.length; ++i) {
        const comparators = range.set[i];
        let setMin = null;
        comparators.forEach((comparator) => {
          const compver = new SemVer(comparator.semver.version);
          switch (comparator.operator) {
            case ">":
              if (compver.prerelease.length === 0) {
                compver.patch++;
              } else {
                compver.prerelease.push(0);
              }
              compver.raw = compver.format();
            /* fallthrough */
            case "":
            case ">=":
              if (!setMin || gt(compver, setMin)) {
                setMin = compver;
              }
              break;
            case "<":
            case "<=":
              break;
            /* istanbul ignore next */
            default:
              throw new Error(`Unexpected operation: ${comparator.operator}`);
          }
        });
        if (setMin && (!minver || gt(minver, setMin))) {
          minver = setMin;
        }
      }
      if (minver && range.test(minver)) {
        return minver;
      }
      return null;
    };
    module2.exports = minVersion;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/valid.js
var require_valid2 = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/valid.js"(exports2, module2) {
    "use strict";
    var Range = require_range();
    var validRange = (range, options) => {
      try {
        return new Range(range, options).range || "*";
      } catch (er) {
        return null;
      }
    };
    module2.exports = validRange;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/outside.js
var require_outside = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/outside.js"(exports2, module2) {
    "use strict";
    var SemVer = require_semver();
    var Comparator = require_comparator();
    var { ANY } = Comparator;
    var Range = require_range();
    var satisfies = require_satisfies();
    var gt = require_gt();
    var lt = require_lt();
    var lte = require_lte();
    var gte = require_gte();
    var outside = (version, range, hilo, options) => {
      version = new SemVer(version, options);
      range = new Range(range, options);
      let gtfn, ltefn, ltfn, comp, ecomp;
      switch (hilo) {
        case ">":
          gtfn = gt;
          ltefn = lte;
          ltfn = lt;
          comp = ">";
          ecomp = ">=";
          break;
        case "<":
          gtfn = lt;
          ltefn = gte;
          ltfn = gt;
          comp = "<";
          ecomp = "<=";
          break;
        default:
          throw new TypeError('Must provide a hilo val of "<" or ">"');
      }
      if (satisfies(version, range, options)) {
        return false;
      }
      for (let i = 0; i < range.set.length; ++i) {
        const comparators = range.set[i];
        let high = null;
        let low = null;
        comparators.forEach((comparator) => {
          if (comparator.semver === ANY) {
            comparator = new Comparator(">=0.0.0");
          }
          high = high || comparator;
          low = low || comparator;
          if (gtfn(comparator.semver, high.semver, options)) {
            high = comparator;
          } else if (ltfn(comparator.semver, low.semver, options)) {
            low = comparator;
          }
        });
        if (high.operator === comp || high.operator === ecomp) {
          return false;
        }
        if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
          return false;
        } else if (low.operator === ecomp && ltfn(version, low.semver)) {
          return false;
        }
      }
      return true;
    };
    module2.exports = outside;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/gtr.js
var require_gtr = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/gtr.js"(exports2, module2) {
    "use strict";
    var outside = require_outside();
    var gtr = (version, range, options) => outside(version, range, ">", options);
    module2.exports = gtr;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/ltr.js
var require_ltr = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/ltr.js"(exports2, module2) {
    "use strict";
    var outside = require_outside();
    var ltr = (version, range, options) => outside(version, range, "<", options);
    module2.exports = ltr;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/intersects.js
var require_intersects = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/intersects.js"(exports2, module2) {
    "use strict";
    var Range = require_range();
    var intersects = (r1, r2, options) => {
      r1 = new Range(r1, options);
      r2 = new Range(r2, options);
      return r1.intersects(r2, options);
    };
    module2.exports = intersects;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/simplify.js
var require_simplify = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/simplify.js"(exports2, module2) {
    "use strict";
    var satisfies = require_satisfies();
    var compare = require_compare();
    module2.exports = (versions, range, options) => {
      const set = [];
      let first = null;
      let prev = null;
      const v = versions.sort((a, b) => compare(a, b, options));
      for (const version of v) {
        const included = satisfies(version, range, options);
        if (included) {
          prev = version;
          if (!first) {
            first = version;
          }
        } else {
          if (prev) {
            set.push([first, prev]);
          }
          prev = null;
          first = null;
        }
      }
      if (first) {
        set.push([first, null]);
      }
      const ranges = [];
      for (const [min, max] of set) {
        if (min === max) {
          ranges.push(min);
        } else if (!max && min === v[0]) {
          ranges.push("*");
        } else if (!max) {
          ranges.push(`>=${min}`);
        } else if (min === v[0]) {
          ranges.push(`<=${max}`);
        } else {
          ranges.push(`${min} - ${max}`);
        }
      }
      const simplified = ranges.join(" || ");
      const original = typeof range.raw === "string" ? range.raw : String(range);
      return simplified.length < original.length ? simplified : range;
    };
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/subset.js
var require_subset = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/subset.js"(exports2, module2) {
    "use strict";
    var Range = require_range();
    var Comparator = require_comparator();
    var { ANY } = Comparator;
    var satisfies = require_satisfies();
    var compare = require_compare();
    var subset = (sub, dom, options = {}) => {
      if (sub === dom) {
        return true;
      }
      sub = new Range(sub, options);
      dom = new Range(dom, options);
      let sawNonNull = false;
      OUTER: for (const simpleSub of sub.set) {
        for (const simpleDom of dom.set) {
          const isSub = simpleSubset(simpleSub, simpleDom, options);
          sawNonNull = sawNonNull || isSub !== null;
          if (isSub) {
            continue OUTER;
          }
        }
        if (sawNonNull) {
          return false;
        }
      }
      return true;
    };
    var minimumVersionWithPreRelease = [new Comparator(">=0.0.0-0")];
    var minimumVersion = [new Comparator(">=0.0.0")];
    var simpleSubset = (sub, dom, options) => {
      if (sub === dom) {
        return true;
      }
      if (sub.length === 1 && sub[0].semver === ANY) {
        if (dom.length === 1 && dom[0].semver === ANY) {
          return true;
        } else if (options.includePrerelease) {
          sub = minimumVersionWithPreRelease;
        } else {
          sub = minimumVersion;
        }
      }
      if (dom.length === 1 && dom[0].semver === ANY) {
        if (options.includePrerelease) {
          return true;
        } else {
          dom = minimumVersion;
        }
      }
      const eqSet = /* @__PURE__ */ new Set();
      let gt, lt;
      for (const c of sub) {
        if (c.operator === ">" || c.operator === ">=") {
          gt = higherGT(gt, c, options);
        } else if (c.operator === "<" || c.operator === "<=") {
          lt = lowerLT(lt, c, options);
        } else {
          eqSet.add(c.semver);
        }
      }
      if (eqSet.size > 1) {
        return null;
      }
      let gtltComp;
      if (gt && lt) {
        gtltComp = compare(gt.semver, lt.semver, options);
        if (gtltComp > 0) {
          return null;
        } else if (gtltComp === 0 && (gt.operator !== ">=" || lt.operator !== "<=")) {
          return null;
        }
      }
      for (const eq of eqSet) {
        if (gt && !satisfies(eq, String(gt), options)) {
          return null;
        }
        if (lt && !satisfies(eq, String(lt), options)) {
          return null;
        }
        for (const c of dom) {
          if (!satisfies(eq, String(c), options)) {
            return false;
          }
        }
        return true;
      }
      let higher, lower;
      let hasDomLT, hasDomGT;
      let needDomLTPre = lt && !options.includePrerelease && lt.semver.prerelease.length ? lt.semver : false;
      let needDomGTPre = gt && !options.includePrerelease && gt.semver.prerelease.length ? gt.semver : false;
      if (needDomLTPre && needDomLTPre.prerelease.length === 1 && lt.operator === "<" && needDomLTPre.prerelease[0] === 0) {
        needDomLTPre = false;
      }
      for (const c of dom) {
        hasDomGT = hasDomGT || c.operator === ">" || c.operator === ">=";
        hasDomLT = hasDomLT || c.operator === "<" || c.operator === "<=";
        if (gt) {
          if (needDomGTPre) {
            if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomGTPre.major && c.semver.minor === needDomGTPre.minor && c.semver.patch === needDomGTPre.patch) {
              needDomGTPre = false;
            }
          }
          if (c.operator === ">" || c.operator === ">=") {
            higher = higherGT(gt, c, options);
            if (higher === c && higher !== gt) {
              return false;
            }
          } else if (gt.operator === ">=" && !satisfies(gt.semver, String(c), options)) {
            return false;
          }
        }
        if (lt) {
          if (needDomLTPre) {
            if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomLTPre.major && c.semver.minor === needDomLTPre.minor && c.semver.patch === needDomLTPre.patch) {
              needDomLTPre = false;
            }
          }
          if (c.operator === "<" || c.operator === "<=") {
            lower = lowerLT(lt, c, options);
            if (lower === c && lower !== lt) {
              return false;
            }
          } else if (lt.operator === "<=" && !satisfies(lt.semver, String(c), options)) {
            return false;
          }
        }
        if (!c.operator && (lt || gt) && gtltComp !== 0) {
          return false;
        }
      }
      if (gt && hasDomLT && !lt && gtltComp !== 0) {
        return false;
      }
      if (lt && hasDomGT && !gt && gtltComp !== 0) {
        return false;
      }
      if (needDomGTPre || needDomLTPre) {
        return false;
      }
      return true;
    };
    var higherGT = (a, b, options) => {
      if (!a) {
        return b;
      }
      const comp = compare(a.semver, b.semver, options);
      return comp > 0 ? a : comp < 0 ? b : b.operator === ">" && a.operator === ">=" ? b : a;
    };
    var lowerLT = (a, b, options) => {
      if (!a) {
        return b;
      }
      const comp = compare(a.semver, b.semver, options);
      return comp < 0 ? a : comp > 0 ? b : b.operator === "<" && a.operator === "<=" ? b : a;
    };
    module2.exports = subset;
  }
});

// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/index.js
var require_semver2 = __commonJS({
  "../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/index.js"(exports2, module2) {
    "use strict";
    var internalRe = require_re();
    var constants = require_constants();
    var SemVer = require_semver();
    var identifiers = require_identifiers();
    var parse = require_parse();
    var valid = require_valid();
    var clean = require_clean();
    var inc = require_inc();
    var diff = require_diff();
    var major = require_major();
    var minor = require_minor();
    var patch = require_patch();
    var prerelease = require_prerelease();
    var compare = require_compare();
    var rcompare = require_rcompare();
    var compareLoose = require_compare_loose();
    var compareBuild = require_compare_build();
    var sort = require_sort();
    var rsort = require_rsort();
    var gt = require_gt();
    var lt = require_lt();
    var eq = require_eq();
    var neq = require_neq();
    var gte = require_gte();
    var lte = require_lte();
    var cmp = require_cmp();
    var coerce2 = require_coerce();
    var Comparator = require_comparator();
    var Range = require_range();
    var satisfies = require_satisfies();
    var toComparators = require_to_comparators();
    var maxSatisfying = require_max_satisfying();
    var minSatisfying = require_min_satisfying();
    var minVersion = require_min_version();
    var validRange = require_valid2();
    var outside = require_outside();
    var gtr = require_gtr();
    var ltr = require_ltr();
    var intersects = require_intersects();
    var simplifyRange = require_simplify();
    var subset = require_subset();
    module2.exports = {
      parse,
      valid,
      clean,
      inc,
      diff,
      major,
      minor,
      patch,
      prerelease,
      compare,
      rcompare,
      compareLoose,
      compareBuild,
      sort,
      rsort,
      gt,
      lt,
      eq,
      neq,
      gte,
      lte,
      cmp,
      coerce: coerce2,
      Comparator,
      Range,
      satisfies,
      toComparators,
      maxSatisfying,
      minSatisfying,
      minVersion,
      validRange,
      outside,
      gtr,
      ltr,
      intersects,
      simplifyRange,
      subset,
      SemVer,
      re: internalRe.re,
      src: internalRe.src,
      tokens: internalRe.t,
      SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
      RELEASE_TYPES: constants.RELEASE_TYPES,
      compareIdentifiers: identifiers.compareIdentifiers,
      rcompareIdentifiers: identifiers.rcompareIdentifiers
    };
  }
});

// ../core/dist/clients/tokenizer.js
var tokenizer_exports = {};
__export(tokenizer_exports, {
  LocalTokenizer: () => LocalTokenizer
});
function isWhitespace(ch) {
  if (ch === " " || ch === "	" || ch === "\n" || ch === "\r")
    return true;
  return new RegExp("^\\p{Zs}$", "u").test(ch);
}
function isControl(ch) {
  if (ch === "	" || ch === "\n" || ch === "\r")
    return false;
  return new RegExp("^\\p{Cc}|\\p{Cf}$", "u").test(ch);
}
function isPunctuation(ch) {
  const cp = ch.codePointAt(0) ?? 0;
  if (33 <= cp && cp <= 47 || 58 <= cp && cp <= 64 || 91 <= cp && cp <= 96 || 123 <= cp && cp <= 126) {
    return true;
  }
  return new RegExp("^\\p{P}$", "u").test(ch);
}
function isChineseChar(cp) {
  return 19968 <= cp && cp <= 40959 || 13312 <= cp && cp <= 19903 || 131072 <= cp && cp <= 173791 || 173824 <= cp && cp <= 177983 || 177984 <= cp && cp <= 178207 || 178208 <= cp && cp <= 183983 || 63744 <= cp && cp <= 64255 || 194560 <= cp && cp <= 195103;
}
function cleanText(text) {
  const chars = [];
  const posMap = [];
  for (let i = 0; i < text.length; i++) {
    const ch = text[i] ?? "";
    const cp = text.codePointAt(i) ?? 0;
    if (cp === 0 || cp === 65533 || isControl(ch))
      continue;
    chars.push(isWhitespace(ch) ? " " : ch);
    posMap.push(i);
  }
  return { chars, posMap };
}
function addChineseSpacing(chars, posMap) {
  const out = [];
  const newMap = [];
  for (let i = 0; i < chars.length; i++) {
    const ch = chars[i] ?? "";
    const pos = posMap[i] ?? 0;
    if (isChineseChar(ch.codePointAt(0) ?? 0)) {
      out.push(" ", ch, " ");
      newMap.push(pos, pos, pos);
    } else {
      out.push(ch);
      newMap.push(pos);
    }
  }
  return { chars: out, posMap: newMap };
}
function nfcNormalize(chars, posMap) {
  const out = [];
  const newMap = [];
  for (let i = 0; i < chars.length; i++) {
    const ch = chars[i] ?? "";
    const nfc = ch.normalize("NFC");
    for (const c of nfc) {
      out.push(c);
      newMap.push(posMap[i] ?? i);
    }
  }
  return { chars: out, posMap: newMap };
}
function lowercaseChars(chars, posMap) {
  return { chars: chars.map((ch) => ch.toLowerCase()), posMap };
}
function stripAccents(chars, posMap) {
  const out = [];
  const newMap = [];
  for (let i = 0; i < chars.length; i++) {
    const ch = chars[i] ?? "";
    const nfd = ch.normalize("NFD");
    for (const c of nfd) {
      if (!new RegExp("^\\p{Mn}$", "u").test(c)) {
        out.push(c);
        newMap.push(posMap[i] ?? i);
      }
    }
  }
  return { chars: out, posMap: newMap };
}
function whitespaceSplit(chars, posMap) {
  const words = [];
  let currentChars = [];
  let currentPos = [];
  for (let i = 0; i < chars.length; i++) {
    if (chars[i] === " ") {
      if (currentChars.length > 0) {
        words.push({ word: currentChars.join(""), positions: currentPos });
        currentChars = [];
        currentPos = [];
      }
    } else {
      currentChars.push(chars[i] ?? "");
      currentPos.push(posMap[i] ?? i);
    }
  }
  if (currentChars.length > 0) {
    words.push({ word: currentChars.join(""), positions: currentPos });
  }
  return words;
}
function splitOnPunctuation(word, positions) {
  const tokens = [];
  let currentChars = [];
  let currentPos = [];
  for (let i = 0; i < word.length; i++) {
    const ch = word[i] ?? "";
    const pos = positions[i] ?? i;
    if (isPunctuation(ch)) {
      if (currentChars.length > 0) {
        tokens.push({ word: currentChars.join(""), positions: currentPos });
        currentChars = [];
        currentPos = [];
      }
      tokens.push({ word: ch, positions: [pos] });
    } else {
      currentChars.push(ch);
      currentPos.push(pos);
    }
  }
  if (currentChars.length > 0) {
    tokens.push({ word: currentChars.join(""), positions: currentPos });
  }
  return tokens;
}
function pretokenize(text) {
  if (!text)
    return [];
  let { chars, posMap } = cleanText(text);
  ({ chars, posMap } = addChineseSpacing(chars, posMap));
  ({ chars, posMap } = nfcNormalize(chars, posMap));
  const words = whitespaceSplit(chars, posMap);
  const result = [];
  for (const { word, positions } of words) {
    let wChars = [...word];
    let wPos = [...positions];
    ({ chars: wChars, posMap: wPos } = lowercaseChars(wChars, wPos));
    ({ chars: wChars, posMap: wPos } = stripAccents(wChars, wPos));
    const subTokens = splitOnPunctuation(wChars.join(""), wPos);
    result.push(...subTokens);
  }
  return result;
}
function tokenizeSubwords(word, vocab, unkId) {
  if (word.length > MAX_WORD_CHARS) {
    return { tokens: ["[UNK]"], ids: [unkId], spans: [[0, word.length]] };
  }
  const tokens = [];
  const ids = [];
  const spans = [];
  let start = 0;
  while (start < word.length) {
    let end = word.length;
    let found = null;
    let foundId = -1;
    while (start < end) {
      let substr = word.slice(start, end);
      if (start > 0)
        substr = `##${substr}`;
      const id = vocab.get(substr);
      if (id !== void 0) {
        found = substr;
        foundId = id;
        break;
      }
      end--;
    }
    if (found === null) {
      return { tokens: ["[UNK]"], ids: [unkId], spans: [[0, word.length]] };
    }
    tokens.push(found);
    ids.push(foundId);
    spans.push([start, end]);
    start = end;
  }
  return { tokens, ids, spans };
}
var import_node_fs2, import_node_path7, MAX_WORD_CHARS, PAD_ID, UNK_ID, CLS_ID, SEP_ID, LocalTokenizer;
var init_tokenizer = __esm({
  "../core/dist/clients/tokenizer.js"() {
    "use strict";
    import_node_fs2 = require("node:fs");
    import_node_path7 = require("node:path");
    MAX_WORD_CHARS = 100;
    PAD_ID = 0;
    UNK_ID = 100;
    CLS_ID = 101;
    SEP_ID = 102;
    LocalTokenizer = class _LocalTokenizer {
      vocab;
      maxLength;
      constructor(vocabPath, maxLength = 512) {
        this.maxLength = maxLength;
        this.vocab = this.loadVocab(vocabPath);
      }
      static fromModelDir(modelDir, maxLength = 512) {
        return new _LocalTokenizer((0, import_node_path7.resolve)(modelDir, "vocab.txt"), maxLength);
      }
      loadVocab(path) {
        const vocab = /* @__PURE__ */ new Map();
        const lines = (0, import_node_fs2.readFileSync)(path, "utf-8").split("\n");
        for (let i = 0; i < lines.length; i++) {
          const token = lines[i]?.replace(/\r$/, "");
          if (token)
            vocab.set(token, i);
        }
        return vocab;
      }
      tokenize(text, options = {}) {
        const { addSpecialTokens = true, returnOffsetMapping = false, truncation = false, maxLength = this.maxLength } = options;
        const preTokens = pretokenize(text);
        const allIds = [];
        const allOffsets = [];
        for (const { word, positions } of preTokens) {
          const { ids, spans } = tokenizeSubwords(word, this.vocab, UNK_ID);
          for (let i = 0; i < ids.length; i++) {
            allIds.push(ids[i] ?? UNK_ID);
            const span = spans[i] ?? [0, 0];
            const subPositions = positions.slice(span[0], span[1]);
            if (subPositions.length > 0) {
              const first = subPositions[0] ?? 0;
              const last = subPositions[subPositions.length - 1] ?? 0;
              allOffsets.push([first, last + 1]);
            } else {
              allOffsets.push([positions[0] ?? 0, positions[0] ?? 0]);
            }
          }
        }
        const contentMax = maxLength - (addSpecialTokens ? 2 : 0);
        if (truncation && allIds.length > contentMax) {
          allIds.length = contentMax;
          allOffsets.length = contentMax;
        }
        if (addSpecialTokens) {
          allIds.unshift(CLS_ID);
          allIds.push(SEP_ID);
          allOffsets.unshift([0, 0]);
          allOffsets.push([0, 0]);
        }
        const result = {
          input_ids: allIds,
          attention_mask: new Array(allIds.length).fill(1),
          token_type_ids: new Array(allIds.length).fill(0)
        };
        if (returnOffsetMapping) {
          result.offset_mapping = allOffsets;
        }
        return result;
      }
      /**
       * Callable interface using snake_case option keys.
       * Supports: tokenizer(text, { truncation, max_length, padding })
       */
      call(text, options = {}) {
        const result = this.tokenize(text, {
          addSpecialTokens: options.add_special_tokens ?? true,
          returnOffsetMapping: options.return_offsets_mapping ?? false,
          truncation: options.truncation ?? false,
          maxLength: options.max_length,
          padding: options.padding ?? false
        });
        if (options.padding && result.input_ids.length < (options.max_length ?? this.maxLength)) {
          const padLen = (options.max_length ?? this.maxLength) - result.input_ids.length;
          result.input_ids.push(...new Array(padLen).fill(PAD_ID));
          result.attention_mask.push(...new Array(padLen).fill(0));
          result.token_type_ids.push(...new Array(padLen).fill(0));
          if (result.offset_mapping) {
            result.offset_mapping.push(...new Array(padLen).fill([0, 0]));
          }
        }
        return result;
      }
    };
  }
});

// ../core/dist/clients/pi-deps-installer.js
var pi_deps_installer_exports = {};
__export(pi_deps_installer_exports, {
  ensurePiDeps: () => ensurePiDeps,
  isLocalInstallValid: () => isLocalInstallValid
});
function isLocalInstallValid(modelPath) {
  try {
    const req = (0, import_node_module.createRequire)((0, import_node_path8.resolve)(modelPath, "package.json"));
    const localPrefix = (0, import_node_fs3.realpathSync)((0, import_node_path8.resolve)(modelPath, "node_modules")) + import_node_path8.sep;
    for (const pkg of REQUIRED_PACKAGES) {
      const resolved = req.resolve(pkg);
      if (!resolved.startsWith(localPrefix))
        return false;
    }
    return true;
  } catch {
    return false;
  }
}
async function ensurePiDeps(modelPath, logger = nullLogger) {
  if (isLocalInstallValid(modelPath))
    return true;
  try {
    require.resolve("onnxruntime-node");
    return true;
  } catch {
  }
  logger.info("Installing PI runtime dependencies (first-time setup)...");
  try {
    const pkgJsonPath = (0, import_node_path8.resolve)(modelPath, "package.json");
    if (!(0, import_node_fs3.existsSync)(pkgJsonPath)) {
      (0, import_node_fs3.mkdirSync)(modelPath, { recursive: true });
      (0, import_node_fs3.writeFileSync)(pkgJsonPath, '{"private":true}');
    }
    await runNpm(modelPath, ["install", "--no-save", ...REQUIRED_PACKAGES], logger);
    const verified = isLocalInstallValid(modelPath);
    if (verified) {
      logger.info("PI runtime dependencies installed successfully");
    } else {
      logger.warn("PI dependency installation may be incomplete");
    }
    return verified;
  } catch (err) {
    logger.warn(`Failed to install PI dependencies (PI check will be skipped): ${err instanceof Error ? err.message : String(err)}`);
    return false;
  }
}
function runNpm(cwd, args, logger) {
  return new Promise((resolve10, reject) => {
    const isWindows = process.platform === "win32";
    const npmCmd = isWindows ? "npm.cmd" : "npm";
    const child = (0, import_node_child_process.execFile)(npmCmd, args, { cwd, timeout: 3e4, shell: isWindows }, (error, _stdout, stderr) => {
      if (error) {
        logger.warn(`npm install error: ${stderr || error.message}`);
        reject(error);
      } else {
        resolve10();
      }
    });
    child.unref();
  });
}
var import_node_child_process, import_node_fs3, import_node_module, import_node_path8, REQUIRED_PACKAGES;
var init_pi_deps_installer = __esm({
  "../core/dist/clients/pi-deps-installer.js"() {
    "use strict";
    import_node_child_process = require("node:child_process");
    import_node_fs3 = require("node:fs");
    import_node_module = require("node:module");
    import_node_path8 = require("node:path");
    init_types2();
    REQUIRED_PACKAGES = ["onnxruntime-node"];
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/identity.js
var require_identity = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/identity.js"(exports2) {
    "use strict";
    var ALIAS = Symbol.for("yaml.alias");
    var DOC = Symbol.for("yaml.document");
    var MAP = Symbol.for("yaml.map");
    var PAIR = Symbol.for("yaml.pair");
    var SCALAR = Symbol.for("yaml.scalar");
    var SEQ = Symbol.for("yaml.seq");
    var NODE_TYPE = Symbol.for("yaml.node.type");
    var isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
    var isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
    var isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
    var isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
    var isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
    var isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
    function isCollection(node) {
      if (node && typeof node === "object")
        switch (node[NODE_TYPE]) {
          case MAP:
          case SEQ:
            return true;
        }
      return false;
    }
    function isNode(node) {
      if (node && typeof node === "object")
        switch (node[NODE_TYPE]) {
          case ALIAS:
          case MAP:
          case SCALAR:
          case SEQ:
            return true;
        }
      return false;
    }
    var hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
    exports2.ALIAS = ALIAS;
    exports2.DOC = DOC;
    exports2.MAP = MAP;
    exports2.NODE_TYPE = NODE_TYPE;
    exports2.PAIR = PAIR;
    exports2.SCALAR = SCALAR;
    exports2.SEQ = SEQ;
    exports2.hasAnchor = hasAnchor;
    exports2.isAlias = isAlias;
    exports2.isCollection = isCollection;
    exports2.isDocument = isDocument;
    exports2.isMap = isMap;
    exports2.isNode = isNode;
    exports2.isPair = isPair;
    exports2.isScalar = isScalar;
    exports2.isSeq = isSeq;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/visit.js
var require_visit = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/visit.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var BREAK = Symbol("break visit");
    var SKIP = Symbol("skip children");
    var REMOVE = Symbol("remove node");
    function visit(node, visitor) {
      const visitor_ = initVisitor(visitor);
      if (identity.isDocument(node)) {
        const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
        if (cd === REMOVE)
          node.contents = null;
      } else
        visit_(null, node, visitor_, Object.freeze([]));
    }
    visit.BREAK = BREAK;
    visit.SKIP = SKIP;
    visit.REMOVE = REMOVE;
    function visit_(key, node, visitor, path) {
      const ctrl = callVisitor(key, node, visitor, path);
      if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
        replaceNode(key, path, ctrl);
        return visit_(key, ctrl, visitor, path);
      }
      if (typeof ctrl !== "symbol") {
        if (identity.isCollection(node)) {
          path = Object.freeze(path.concat(node));
          for (let i = 0; i < node.items.length; ++i) {
            const ci = visit_(i, node.items[i], visitor, path);
            if (typeof ci === "number")
              i = ci - 1;
            else if (ci === BREAK)
              return BREAK;
            else if (ci === REMOVE) {
              node.items.splice(i, 1);
              i -= 1;
            }
          }
        } else if (identity.isPair(node)) {
          path = Object.freeze(path.concat(node));
          const ck = visit_("key", node.key, visitor, path);
          if (ck === BREAK)
            return BREAK;
          else if (ck === REMOVE)
            node.key = null;
          const cv = visit_("value", node.value, visitor, path);
          if (cv === BREAK)
            return BREAK;
          else if (cv === REMOVE)
            node.value = null;
        }
      }
      return ctrl;
    }
    async function visitAsync(node, visitor) {
      const visitor_ = initVisitor(visitor);
      if (identity.isDocument(node)) {
        const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
        if (cd === REMOVE)
          node.contents = null;
      } else
        await visitAsync_(null, node, visitor_, Object.freeze([]));
    }
    visitAsync.BREAK = BREAK;
    visitAsync.SKIP = SKIP;
    visitAsync.REMOVE = REMOVE;
    async function visitAsync_(key, node, visitor, path) {
      const ctrl = await callVisitor(key, node, visitor, path);
      if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
        replaceNode(key, path, ctrl);
        return visitAsync_(key, ctrl, visitor, path);
      }
      if (typeof ctrl !== "symbol") {
        if (identity.isCollection(node)) {
          path = Object.freeze(path.concat(node));
          for (let i = 0; i < node.items.length; ++i) {
            const ci = await visitAsync_(i, node.items[i], visitor, path);
            if (typeof ci === "number")
              i = ci - 1;
            else if (ci === BREAK)
              return BREAK;
            else if (ci === REMOVE) {
              node.items.splice(i, 1);
              i -= 1;
            }
          }
        } else if (identity.isPair(node)) {
          path = Object.freeze(path.concat(node));
          const ck = await visitAsync_("key", node.key, visitor, path);
          if (ck === BREAK)
            return BREAK;
          else if (ck === REMOVE)
            node.key = null;
          const cv = await visitAsync_("value", node.value, visitor, path);
          if (cv === BREAK)
            return BREAK;
          else if (cv === REMOVE)
            node.value = null;
        }
      }
      return ctrl;
    }
    function initVisitor(visitor) {
      if (typeof visitor === "object" && (visitor.Collection || visitor.Node || visitor.Value)) {
        return Object.assign({
          Alias: visitor.Node,
          Map: visitor.Node,
          Scalar: visitor.Node,
          Seq: visitor.Node
        }, visitor.Value && {
          Map: visitor.Value,
          Scalar: visitor.Value,
          Seq: visitor.Value
        }, visitor.Collection && {
          Map: visitor.Collection,
          Seq: visitor.Collection
        }, visitor);
      }
      return visitor;
    }
    function callVisitor(key, node, visitor, path) {
      if (typeof visitor === "function")
        return visitor(key, node, path);
      if (identity.isMap(node))
        return visitor.Map?.(key, node, path);
      if (identity.isSeq(node))
        return visitor.Seq?.(key, node, path);
      if (identity.isPair(node))
        return visitor.Pair?.(key, node, path);
      if (identity.isScalar(node))
        return visitor.Scalar?.(key, node, path);
      if (identity.isAlias(node))
        return visitor.Alias?.(key, node, path);
      return void 0;
    }
    function replaceNode(key, path, node) {
      const parent = path[path.length - 1];
      if (identity.isCollection(parent)) {
        parent.items[key] = node;
      } else if (identity.isPair(parent)) {
        if (key === "key")
          parent.key = node;
        else
          parent.value = node;
      } else if (identity.isDocument(parent)) {
        parent.contents = node;
      } else {
        const pt = identity.isAlias(parent) ? "alias" : "scalar";
        throw new Error(`Cannot replace node with ${pt} parent`);
      }
    }
    exports2.visit = visit;
    exports2.visitAsync = visitAsync;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/directives.js
var require_directives = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/directives.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var visit = require_visit();
    var escapeChars = {
      "!": "%21",
      ",": "%2C",
      "[": "%5B",
      "]": "%5D",
      "{": "%7B",
      "}": "%7D"
    };
    var escapeTagName = (tn) => tn.replace(/[!,[\]{}]/g, (ch) => escapeChars[ch]);
    var Directives = class _Directives {
      constructor(yaml, tags) {
        this.docStart = null;
        this.docEnd = false;
        this.yaml = Object.assign({}, _Directives.defaultYaml, yaml);
        this.tags = Object.assign({}, _Directives.defaultTags, tags);
      }
      clone() {
        const copy = new _Directives(this.yaml, this.tags);
        copy.docStart = this.docStart;
        return copy;
      }
      /**
       * During parsing, get a Directives instance for the current document and
       * update the stream state according to the current version's spec.
       */
      atDocument() {
        const res = new _Directives(this.yaml, this.tags);
        switch (this.yaml.version) {
          case "1.1":
            this.atNextDocument = true;
            break;
          case "1.2":
            this.atNextDocument = false;
            this.yaml = {
              explicit: _Directives.defaultYaml.explicit,
              version: "1.2"
            };
            this.tags = Object.assign({}, _Directives.defaultTags);
            break;
        }
        return res;
      }
      /**
       * @param onError - May be called even if the action was successful
       * @returns `true` on success
       */
      add(line, onError) {
        if (this.atNextDocument) {
          this.yaml = { explicit: _Directives.defaultYaml.explicit, version: "1.1" };
          this.tags = Object.assign({}, _Directives.defaultTags);
          this.atNextDocument = false;
        }
        const parts = line.trim().split(/[ \t]+/);
        const name = parts.shift();
        switch (name) {
          case "%TAG": {
            if (parts.length !== 2) {
              onError(0, "%TAG directive should contain exactly two parts");
              if (parts.length < 2)
                return false;
            }
            const [handle, prefix] = parts;
            this.tags[handle] = prefix;
            return true;
          }
          case "%YAML": {
            this.yaml.explicit = true;
            if (parts.length !== 1) {
              onError(0, "%YAML directive should contain exactly one part");
              return false;
            }
            const [version] = parts;
            if (version === "1.1" || version === "1.2") {
              this.yaml.version = version;
              return true;
            } else {
              const isValid2 = /^\d+\.\d+$/.test(version);
              onError(6, `Unsupported YAML version ${version}`, isValid2);
              return false;
            }
          }
          default:
            onError(0, `Unknown directive ${name}`, true);
            return false;
        }
      }
      /**
       * Resolves a tag, matching handles to those defined in %TAG directives.
       *
       * @returns Resolved tag, which may also be the non-specific tag `'!'` or a
       *   `'!local'` tag, or `null` if unresolvable.
       */
      tagName(source, onError) {
        if (source === "!")
          return "!";
        if (source[0] !== "!") {
          onError(`Not a valid tag: ${source}`);
          return null;
        }
        if (source[1] === "<") {
          const verbatim = source.slice(2, -1);
          if (verbatim === "!" || verbatim === "!!") {
            onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);
            return null;
          }
          if (source[source.length - 1] !== ">")
            onError("Verbatim tags must end with a >");
          return verbatim;
        }
        const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);
        if (!suffix)
          onError(`The ${source} tag has no suffix`);
        const prefix = this.tags[handle];
        if (prefix) {
          try {
            return prefix + decodeURIComponent(suffix);
          } catch (error) {
            onError(String(error));
            return null;
          }
        }
        if (handle === "!")
          return source;
        onError(`Could not resolve tag: ${source}`);
        return null;
      }
      /**
       * Given a fully resolved tag, returns its printable string form,
       * taking into account current tag prefixes and defaults.
       */
      tagString(tag) {
        for (const [handle, prefix] of Object.entries(this.tags)) {
          if (tag.startsWith(prefix))
            return handle + escapeTagName(tag.substring(prefix.length));
        }
        return tag[0] === "!" ? tag : `!<${tag}>`;
      }
      toString(doc) {
        const lines = this.yaml.explicit ? [`%YAML ${this.yaml.version || "1.2"}`] : [];
        const tagEntries = Object.entries(this.tags);
        let tagNames;
        if (doc && tagEntries.length > 0 && identity.isNode(doc.contents)) {
          const tags = {};
          visit.visit(doc.contents, (_key, node) => {
            if (identity.isNode(node) && node.tag)
              tags[node.tag] = true;
          });
          tagNames = Object.keys(tags);
        } else
          tagNames = [];
        for (const [handle, prefix] of tagEntries) {
          if (handle === "!!" && prefix === "tag:yaml.org,2002:")
            continue;
          if (!doc || tagNames.some((tn) => tn.startsWith(prefix)))
            lines.push(`%TAG ${handle} ${prefix}`);
        }
        return lines.join("\n");
      }
    };
    Directives.defaultYaml = { explicit: false, version: "1.2" };
    Directives.defaultTags = { "!!": "tag:yaml.org,2002:" };
    exports2.Directives = Directives;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/anchors.js
var require_anchors = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/anchors.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var visit = require_visit();
    function anchorIsValid(anchor) {
      if (/[\x00-\x19\s,[\]{}]/.test(anchor)) {
        const sa = JSON.stringify(anchor);
        const msg = `Anchor must not contain whitespace or control characters: ${sa}`;
        throw new Error(msg);
      }
      return true;
    }
    function anchorNames(root) {
      const anchors = /* @__PURE__ */ new Set();
      visit.visit(root, {
        Value(_key, node) {
          if (node.anchor)
            anchors.add(node.anchor);
        }
      });
      return anchors;
    }
    function findNewAnchor(prefix, exclude) {
      for (let i = 1; true; ++i) {
        const name = `${prefix}${i}`;
        if (!exclude.has(name))
          return name;
      }
    }
    function createNodeAnchors(doc, prefix) {
      const aliasObjects = [];
      const sourceObjects = /* @__PURE__ */ new Map();
      let prevAnchors = null;
      return {
        onAnchor: (source) => {
          aliasObjects.push(source);
          prevAnchors ?? (prevAnchors = anchorNames(doc));
          const anchor = findNewAnchor(prefix, prevAnchors);
          prevAnchors.add(anchor);
          return anchor;
        },
        /**
         * With circular references, the source node is only resolved after all
         * of its child nodes are. This is why anchors are set only after all of
         * the nodes have been created.
         */
        setAnchors: () => {
          for (const source of aliasObjects) {
            const ref = sourceObjects.get(source);
            if (typeof ref === "object" && ref.anchor && (identity.isScalar(ref.node) || identity.isCollection(ref.node))) {
              ref.node.anchor = ref.anchor;
            } else {
              const error = new Error("Failed to resolve repeated object (this should not happen)");
              error.source = source;
              throw error;
            }
          }
        },
        sourceObjects
      };
    }
    exports2.anchorIsValid = anchorIsValid;
    exports2.anchorNames = anchorNames;
    exports2.createNodeAnchors = createNodeAnchors;
    exports2.findNewAnchor = findNewAnchor;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/applyReviver.js
var require_applyReviver = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/applyReviver.js"(exports2) {
    "use strict";
    function applyReviver(reviver, obj, key, val) {
      if (val && typeof val === "object") {
        if (Array.isArray(val)) {
          for (let i = 0, len = val.length; i < len; ++i) {
            const v0 = val[i];
            const v1 = applyReviver(reviver, val, String(i), v0);
            if (v1 === void 0)
              delete val[i];
            else if (v1 !== v0)
              val[i] = v1;
          }
        } else if (val instanceof Map) {
          for (const k of Array.from(val.keys())) {
            const v0 = val.get(k);
            const v1 = applyReviver(reviver, val, k, v0);
            if (v1 === void 0)
              val.delete(k);
            else if (v1 !== v0)
              val.set(k, v1);
          }
        } else if (val instanceof Set) {
          for (const v0 of Array.from(val)) {
            const v1 = applyReviver(reviver, val, v0, v0);
            if (v1 === void 0)
              val.delete(v0);
            else if (v1 !== v0) {
              val.delete(v0);
              val.add(v1);
            }
          }
        } else {
          for (const [k, v0] of Object.entries(val)) {
            const v1 = applyReviver(reviver, val, k, v0);
            if (v1 === void 0)
              delete val[k];
            else if (v1 !== v0)
              val[k] = v1;
          }
        }
      }
      return reviver.call(obj, key, val);
    }
    exports2.applyReviver = applyReviver;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/toJS.js
var require_toJS = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/toJS.js"(exports2) {
    "use strict";
    var identity = require_identity();
    function toJS(value, arg, ctx) {
      if (Array.isArray(value))
        return value.map((v, i) => toJS(v, String(i), ctx));
      if (value && typeof value.toJSON === "function") {
        if (!ctx || !identity.hasAnchor(value))
          return value.toJSON(arg, ctx);
        const data = { aliasCount: 0, count: 1, res: void 0 };
        ctx.anchors.set(value, data);
        ctx.onCreate = (res2) => {
          data.res = res2;
          delete ctx.onCreate;
        };
        const res = value.toJSON(arg, ctx);
        if (ctx.onCreate)
          ctx.onCreate(res);
        return res;
      }
      if (typeof value === "bigint" && !ctx?.keep)
        return Number(value);
      return value;
    }
    exports2.toJS = toJS;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Node.js
var require_Node = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Node.js"(exports2) {
    "use strict";
    var applyReviver = require_applyReviver();
    var identity = require_identity();
    var toJS = require_toJS();
    var NodeBase = class {
      constructor(type) {
        Object.defineProperty(this, identity.NODE_TYPE, { value: type });
      }
      /** Create a copy of this node.  */
      clone() {
        const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
        if (this.range)
          copy.range = this.range.slice();
        return copy;
      }
      /** A plain JavaScript representation of this node. */
      toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
        if (!identity.isDocument(doc))
          throw new TypeError("A document argument is required");
        const ctx = {
          anchors: /* @__PURE__ */ new Map(),
          doc,
          keep: true,
          mapAsMap: mapAsMap === true,
          mapKeyWarned: false,
          maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
        };
        const res = toJS.toJS(this, "", ctx);
        if (typeof onAnchor === "function")
          for (const { count, res: res2 } of ctx.anchors.values())
            onAnchor(res2, count);
        return typeof reviver === "function" ? applyReviver.applyReviver(reviver, { "": res }, "", res) : res;
      }
    };
    exports2.NodeBase = NodeBase;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Alias.js
var require_Alias = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Alias.js"(exports2) {
    "use strict";
    var anchors = require_anchors();
    var visit = require_visit();
    var identity = require_identity();
    var Node = require_Node();
    var toJS = require_toJS();
    var Alias = class extends Node.NodeBase {
      constructor(source) {
        super(identity.ALIAS);
        this.source = source;
        Object.defineProperty(this, "tag", {
          set() {
            throw new Error("Alias nodes cannot have tags");
          }
        });
      }
      /**
       * Resolve the value of this alias within `doc`, finding the last
       * instance of the `source` anchor before this node.
       */
      resolve(doc, ctx) {
        let nodes;
        if (ctx?.aliasResolveCache) {
          nodes = ctx.aliasResolveCache;
        } else {
          nodes = [];
          visit.visit(doc, {
            Node: (_key, node) => {
              if (identity.isAlias(node) || identity.hasAnchor(node))
                nodes.push(node);
            }
          });
          if (ctx)
            ctx.aliasResolveCache = nodes;
        }
        let found = void 0;
        for (const node of nodes) {
          if (node === this)
            break;
          if (node.anchor === this.source)
            found = node;
        }
        return found;
      }
      toJSON(_arg, ctx) {
        if (!ctx)
          return { source: this.source };
        const { anchors: anchors2, doc, maxAliasCount } = ctx;
        const source = this.resolve(doc, ctx);
        if (!source) {
          const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
          throw new ReferenceError(msg);
        }
        let data = anchors2.get(source);
        if (!data) {
          toJS.toJS(source, null, ctx);
          data = anchors2.get(source);
        }
        if (data?.res === void 0) {
          const msg = "This should not happen: Alias anchor was not resolved?";
          throw new ReferenceError(msg);
        }
        if (maxAliasCount >= 0) {
          data.count += 1;
          if (data.aliasCount === 0)
            data.aliasCount = getAliasCount(doc, source, anchors2);
          if (data.count * data.aliasCount > maxAliasCount) {
            const msg = "Excessive alias count indicates a resource exhaustion attack";
            throw new ReferenceError(msg);
          }
        }
        return data.res;
      }
      toString(ctx, _onComment, _onChompKeep) {
        const src = `*${this.source}`;
        if (ctx) {
          anchors.anchorIsValid(this.source);
          if (ctx.options.verifyAliasOrder && !ctx.anchors.has(this.source)) {
            const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
            throw new Error(msg);
          }
          if (ctx.implicitKey)
            return `${src} `;
        }
        return src;
      }
    };
    function getAliasCount(doc, node, anchors2) {
      if (identity.isAlias(node)) {
        const source = node.resolve(doc);
        const anchor = anchors2 && source && anchors2.get(source);
        return anchor ? anchor.count * anchor.aliasCount : 0;
      } else if (identity.isCollection(node)) {
        let count = 0;
        for (const item of node.items) {
          const c = getAliasCount(doc, item, anchors2);
          if (c > count)
            count = c;
        }
        return count;
      } else if (identity.isPair(node)) {
        const kc = getAliasCount(doc, node.key, anchors2);
        const vc = getAliasCount(doc, node.value, anchors2);
        return Math.max(kc, vc);
      }
      return 1;
    }
    exports2.Alias = Alias;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Scalar.js
var require_Scalar = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Scalar.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Node = require_Node();
    var toJS = require_toJS();
    var isScalarValue = (value) => !value || typeof value !== "function" && typeof value !== "object";
    var Scalar = class extends Node.NodeBase {
      constructor(value) {
        super(identity.SCALAR);
        this.value = value;
      }
      toJSON(arg, ctx) {
        return ctx?.keep ? this.value : toJS.toJS(this.value, arg, ctx);
      }
      toString() {
        return String(this.value);
      }
    };
    Scalar.BLOCK_FOLDED = "BLOCK_FOLDED";
    Scalar.BLOCK_LITERAL = "BLOCK_LITERAL";
    Scalar.PLAIN = "PLAIN";
    Scalar.QUOTE_DOUBLE = "QUOTE_DOUBLE";
    Scalar.QUOTE_SINGLE = "QUOTE_SINGLE";
    exports2.Scalar = Scalar;
    exports2.isScalarValue = isScalarValue;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/createNode.js
var require_createNode = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/createNode.js"(exports2) {
    "use strict";
    var Alias = require_Alias();
    var identity = require_identity();
    var Scalar = require_Scalar();
    var defaultTagPrefix = "tag:yaml.org,2002:";
    function findTagObject(value, tagName, tags) {
      if (tagName) {
        const match = tags.filter((t) => t.tag === tagName);
        const tagObj = match.find((t) => !t.format) ?? match[0];
        if (!tagObj)
          throw new Error(`Tag ${tagName} not found`);
        return tagObj;
      }
      return tags.find((t) => t.identify?.(value) && !t.format);
    }
    function createNode(value, tagName, ctx) {
      if (identity.isDocument(value))
        value = value.contents;
      if (identity.isNode(value))
        return value;
      if (identity.isPair(value)) {
        const map = ctx.schema[identity.MAP].createNode?.(ctx.schema, null, ctx);
        map.items.push(value);
        return map;
      }
      if (value instanceof String || value instanceof Number || value instanceof Boolean || typeof BigInt !== "undefined" && value instanceof BigInt) {
        value = value.valueOf();
      }
      const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
      let ref = void 0;
      if (aliasDuplicateObjects && value && typeof value === "object") {
        ref = sourceObjects.get(value);
        if (ref) {
          ref.anchor ?? (ref.anchor = onAnchor(value));
          return new Alias.Alias(ref.anchor);
        } else {
          ref = { anchor: null, node: null };
          sourceObjects.set(value, ref);
        }
      }
      if (tagName?.startsWith("!!"))
        tagName = defaultTagPrefix + tagName.slice(2);
      let tagObj = findTagObject(value, tagName, schema.tags);
      if (!tagObj) {
        if (value && typeof value.toJSON === "function") {
          value = value.toJSON();
        }
        if (!value || typeof value !== "object") {
          const node2 = new Scalar.Scalar(value);
          if (ref)
            ref.node = node2;
          return node2;
        }
        tagObj = value instanceof Map ? schema[identity.MAP] : Symbol.iterator in Object(value) ? schema[identity.SEQ] : schema[identity.MAP];
      }
      if (onTagObj) {
        onTagObj(tagObj);
        delete ctx.onTagObj;
      }
      const node = tagObj?.createNode ? tagObj.createNode(ctx.schema, value, ctx) : typeof tagObj?.nodeClass?.from === "function" ? tagObj.nodeClass.from(ctx.schema, value, ctx) : new Scalar.Scalar(value);
      if (tagName)
        node.tag = tagName;
      else if (!tagObj.default)
        node.tag = tagObj.tag;
      if (ref)
        ref.node = node;
      return node;
    }
    exports2.createNode = createNode;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Collection.js
var require_Collection = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Collection.js"(exports2) {
    "use strict";
    var createNode = require_createNode();
    var identity = require_identity();
    var Node = require_Node();
    function collectionFromPath(schema, path, value) {
      let v = value;
      for (let i = path.length - 1; i >= 0; --i) {
        const k = path[i];
        if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
          const a = [];
          a[k] = v;
          v = a;
        } else {
          v = /* @__PURE__ */ new Map([[k, v]]);
        }
      }
      return createNode.createNode(v, void 0, {
        aliasDuplicateObjects: false,
        keepUndefined: false,
        onAnchor: () => {
          throw new Error("This should not happen, please report a bug.");
        },
        schema,
        sourceObjects: /* @__PURE__ */ new Map()
      });
    }
    var isEmptyPath = (path) => path == null || typeof path === "object" && !!path[Symbol.iterator]().next().done;
    var Collection = class extends Node.NodeBase {
      constructor(type, schema) {
        super(type);
        Object.defineProperty(this, "schema", {
          value: schema,
          configurable: true,
          enumerable: false,
          writable: true
        });
      }
      /**
       * Create a copy of this collection.
       *
       * @param schema - If defined, overwrites the original's schema
       */
      clone(schema) {
        const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
        if (schema)
          copy.schema = schema;
        copy.items = copy.items.map((it) => identity.isNode(it) || identity.isPair(it) ? it.clone(schema) : it);
        if (this.range)
          copy.range = this.range.slice();
        return copy;
      }
      /**
       * Adds a value to the collection. For `!!map` and `!!omap` the value must
       * be a Pair instance or a `{ key, value }` object, which may not have a key
       * that already exists in the map.
       */
      addIn(path, value) {
        if (isEmptyPath(path))
          this.add(value);
        else {
          const [key, ...rest] = path;
          const node = this.get(key, true);
          if (identity.isCollection(node))
            node.addIn(rest, value);
          else if (node === void 0 && this.schema)
            this.set(key, collectionFromPath(this.schema, rest, value));
          else
            throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
        }
      }
      /**
       * Removes a value from the collection.
       * @returns `true` if the item was found and removed.
       */
      deleteIn(path) {
        const [key, ...rest] = path;
        if (rest.length === 0)
          return this.delete(key);
        const node = this.get(key, true);
        if (identity.isCollection(node))
          return node.deleteIn(rest);
        else
          throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
      }
      /**
       * Returns item at `key`, or `undefined` if not found. By default unwraps
       * scalar values from their surrounding node; to disable set `keepScalar` to
       * `true` (collections are always returned intact).
       */
      getIn(path, keepScalar) {
        const [key, ...rest] = path;
        const node = this.get(key, true);
        if (rest.length === 0)
          return !keepScalar && identity.isScalar(node) ? node.value : node;
        else
          return identity.isCollection(node) ? node.getIn(rest, keepScalar) : void 0;
      }
      hasAllNullValues(allowScalar) {
        return this.items.every((node) => {
          if (!identity.isPair(node))
            return false;
          const n = node.value;
          return n == null || allowScalar && identity.isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
        });
      }
      /**
       * Checks if the collection includes a value with the key `key`.
       */
      hasIn(path) {
        const [key, ...rest] = path;
        if (rest.length === 0)
          return this.has(key);
        const node = this.get(key, true);
        return identity.isCollection(node) ? node.hasIn(rest) : false;
      }
      /**
       * Sets a value in this collection. For `!!set`, `value` needs to be a
       * boolean to add/remove the item from the set.
       */
      setIn(path, value) {
        const [key, ...rest] = path;
        if (rest.length === 0) {
          this.set(key, value);
        } else {
          const node = this.get(key, true);
          if (identity.isCollection(node))
            node.setIn(rest, value);
          else if (node === void 0 && this.schema)
            this.set(key, collectionFromPath(this.schema, rest, value));
          else
            throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
        }
      }
    };
    exports2.Collection = Collection;
    exports2.collectionFromPath = collectionFromPath;
    exports2.isEmptyPath = isEmptyPath;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyComment.js
var require_stringifyComment = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyComment.js"(exports2) {
    "use strict";
    var stringifyComment = (str) => str.replace(/^(?!$)(?: $)?/gm, "#");
    function indentComment(comment, indent) {
      if (/^\n+$/.test(comment))
        return comment.substring(1);
      return indent ? comment.replace(/^(?! *$)/gm, indent) : comment;
    }
    var lineComment = (str, indent, comment) => str.endsWith("\n") ? indentComment(comment, indent) : comment.includes("\n") ? "\n" + indentComment(comment, indent) : (str.endsWith(" ") ? "" : " ") + comment;
    exports2.indentComment = indentComment;
    exports2.lineComment = lineComment;
    exports2.stringifyComment = stringifyComment;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/foldFlowLines.js
var require_foldFlowLines = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/foldFlowLines.js"(exports2) {
    "use strict";
    var FOLD_FLOW = "flow";
    var FOLD_BLOCK = "block";
    var FOLD_QUOTED = "quoted";
    function foldFlowLines(text, indent, mode = "flow", { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {
      if (!lineWidth || lineWidth < 0)
        return text;
      if (lineWidth < minContentWidth)
        minContentWidth = 0;
      const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
      if (text.length <= endStep)
        return text;
      const folds = [];
      const escapedFolds = {};
      let end = lineWidth - indent.length;
      if (typeof indentAtStart === "number") {
        if (indentAtStart > lineWidth - Math.max(2, minContentWidth))
          folds.push(0);
        else
          end = lineWidth - indentAtStart;
      }
      let split = void 0;
      let prev = void 0;
      let overflow = false;
      let i = -1;
      let escStart = -1;
      let escEnd = -1;
      if (mode === FOLD_BLOCK) {
        i = consumeMoreIndentedLines(text, i, indent.length);
        if (i !== -1)
          end = i + endStep;
      }
      for (let ch; ch = text[i += 1]; ) {
        if (mode === FOLD_QUOTED && ch === "\\") {
          escStart = i;
          switch (text[i + 1]) {
            case "x":
              i += 3;
              break;
            case "u":
              i += 5;
              break;
            case "U":
              i += 9;
              break;
            default:
              i += 1;
          }
          escEnd = i;
        }
        if (ch === "\n") {
          if (mode === FOLD_BLOCK)
            i = consumeMoreIndentedLines(text, i, indent.length);
          end = i + indent.length + endStep;
          split = void 0;
        } else {
          if (ch === " " && prev && prev !== " " && prev !== "\n" && prev !== "	") {
            const next = text[i + 1];
            if (next && next !== " " && next !== "\n" && next !== "	")
              split = i;
          }
          if (i >= end) {
            if (split) {
              folds.push(split);
              end = split + endStep;
              split = void 0;
            } else if (mode === FOLD_QUOTED) {
              while (prev === " " || prev === "	") {
                prev = ch;
                ch = text[i += 1];
                overflow = true;
              }
              const j = i > escEnd + 1 ? i - 2 : escStart - 1;
              if (escapedFolds[j])
                return text;
              folds.push(j);
              escapedFolds[j] = true;
              end = j + endStep;
              split = void 0;
            } else {
              overflow = true;
            }
          }
        }
        prev = ch;
      }
      if (overflow && onOverflow)
        onOverflow();
      if (folds.length === 0)
        return text;
      if (onFold)
        onFold();
      let res = text.slice(0, folds[0]);
      for (let i2 = 0; i2 < folds.length; ++i2) {
        const fold = folds[i2];
        const end2 = folds[i2 + 1] || text.length;
        if (fold === 0)
          res = `
${indent}${text.slice(0, end2)}`;
        else {
          if (mode === FOLD_QUOTED && escapedFolds[fold])
            res += `${text[fold]}\\`;
          res += `
${indent}${text.slice(fold + 1, end2)}`;
        }
      }
      return res;
    }
    function consumeMoreIndentedLines(text, i, indent) {
      let end = i;
      let start = i + 1;
      let ch = text[start];
      while (ch === " " || ch === "	") {
        if (i < start + indent) {
          ch = text[++i];
        } else {
          do {
            ch = text[++i];
          } while (ch && ch !== "\n");
          end = i;
          start = i + 1;
          ch = text[start];
        }
      }
      return end;
    }
    exports2.FOLD_BLOCK = FOLD_BLOCK;
    exports2.FOLD_FLOW = FOLD_FLOW;
    exports2.FOLD_QUOTED = FOLD_QUOTED;
    exports2.foldFlowLines = foldFlowLines;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyString.js
var require_stringifyString = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyString.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    var foldFlowLines = require_foldFlowLines();
    var getFoldOptions = (ctx, isBlock) => ({
      indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
      lineWidth: ctx.options.lineWidth,
      minContentWidth: ctx.options.minContentWidth
    });
    var containsDocumentMarker = (str) => /^(%|---|\.\.\.)/m.test(str);
    function lineLengthOverLimit(str, lineWidth, indentLength) {
      if (!lineWidth || lineWidth < 0)
        return false;
      const limit = lineWidth - indentLength;
      const strLen = str.length;
      if (strLen <= limit)
        return false;
      for (let i = 0, start = 0; i < strLen; ++i) {
        if (str[i] === "\n") {
          if (i - start > limit)
            return true;
          start = i + 1;
          if (strLen - start <= limit)
            return false;
        }
      }
      return true;
    }
    function doubleQuotedString(value, ctx) {
      const json = JSON.stringify(value);
      if (ctx.options.doubleQuotedAsJSON)
        return json;
      const { implicitKey } = ctx;
      const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
      const indent = ctx.indent || (containsDocumentMarker(value) ? "  " : "");
      let str = "";
      let start = 0;
      for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
        if (ch === " " && json[i + 1] === "\\" && json[i + 2] === "n") {
          str += json.slice(start, i) + "\\ ";
          i += 1;
          start = i;
          ch = "\\";
        }
        if (ch === "\\")
          switch (json[i + 1]) {
            case "u":
              {
                str += json.slice(start, i);
                const code = json.substr(i + 2, 4);
                switch (code) {
                  case "0000":
                    str += "\\0";
                    break;
                  case "0007":
                    str += "\\a";
                    break;
                  case "000b":
                    str += "\\v";
                    break;
                  case "001b":
                    str += "\\e";
                    break;
                  case "0085":
                    str += "\\N";
                    break;
                  case "00a0":
                    str += "\\_";
                    break;
                  case "2028":
                    str += "\\L";
                    break;
                  case "2029":
                    str += "\\P";
                    break;
                  default:
                    if (code.substr(0, 2) === "00")
                      str += "\\x" + code.substr(2);
                    else
                      str += json.substr(i, 6);
                }
                i += 5;
                start = i + 1;
              }
              break;
            case "n":
              if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
                i += 1;
              } else {
                str += json.slice(start, i) + "\n\n";
                while (json[i + 2] === "\\" && json[i + 3] === "n" && json[i + 4] !== '"') {
                  str += "\n";
                  i += 2;
                }
                str += indent;
                if (json[i + 2] === " ")
                  str += "\\";
                i += 1;
                start = i + 1;
              }
              break;
            default:
              i += 1;
          }
      }
      str = start ? str + json.slice(start) : json;
      return implicitKey ? str : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
    }
    function singleQuotedString(value, ctx) {
      if (ctx.options.singleQuote === false || ctx.implicitKey && value.includes("\n") || /[ \t]\n|\n[ \t]/.test(value))
        return doubleQuotedString(value, ctx);
      const indent = ctx.indent || (containsDocumentMarker(value) ? "  " : "");
      const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&
${indent}`) + "'";
      return ctx.implicitKey ? res : foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
    }
    function quotedString(value, ctx) {
      const { singleQuote } = ctx.options;
      let qs;
      if (singleQuote === false)
        qs = doubleQuotedString;
      else {
        const hasDouble = value.includes('"');
        const hasSingle = value.includes("'");
        if (hasDouble && !hasSingle)
          qs = singleQuotedString;
        else if (hasSingle && !hasDouble)
          qs = doubleQuotedString;
        else
          qs = singleQuote ? singleQuotedString : doubleQuotedString;
      }
      return qs(value, ctx);
    }
    var blockEndNewlines;
    try {
      blockEndNewlines = new RegExp("(^|(?<!\n))\n+(?!\n|$)", "g");
    } catch {
      blockEndNewlines = /\n+(?!\n|$)/g;
    }
    function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
      const { blockQuote, commentString, lineWidth } = ctx.options;
      if (!blockQuote || /\n[\t ]+$/.test(value)) {
        return quotedString(value, ctx);
      }
      const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? "  " : "");
      const literal = blockQuote === "literal" ? true : blockQuote === "folded" || type === Scalar.Scalar.BLOCK_FOLDED ? false : type === Scalar.Scalar.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, lineWidth, indent.length);
      if (!value)
        return literal ? "|\n" : ">\n";
      let chomp;
      let endStart;
      for (endStart = value.length; endStart > 0; --endStart) {
        const ch = value[endStart - 1];
        if (ch !== "\n" && ch !== "	" && ch !== " ")
          break;
      }
      let end = value.substring(endStart);
      const endNlPos = end.indexOf("\n");
      if (endNlPos === -1) {
        chomp = "-";
      } else if (value === end || endNlPos !== end.length - 1) {
        chomp = "+";
        if (onChompKeep)
          onChompKeep();
      } else {
        chomp = "";
      }
      if (end) {
        value = value.slice(0, -end.length);
        if (end[end.length - 1] === "\n")
          end = end.slice(0, -1);
        end = end.replace(blockEndNewlines, `$&${indent}`);
      }
      let startWithSpace = false;
      let startEnd;
      let startNlPos = -1;
      for (startEnd = 0; startEnd < value.length; ++startEnd) {
        const ch = value[startEnd];
        if (ch === " ")
          startWithSpace = true;
        else if (ch === "\n")
          startNlPos = startEnd;
        else
          break;
      }
      let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);
      if (start) {
        value = value.substring(start.length);
        start = start.replace(/\n+/g, `$&${indent}`);
      }
      const indentSize = indent ? "2" : "1";
      let header = (startWithSpace ? indentSize : "") + chomp;
      if (comment) {
        header += " " + commentString(comment.replace(/ ?[\r\n]+/g, " "));
        if (onComment)
          onComment();
      }
      if (!literal) {
        const foldedValue = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
        let literalFallback = false;
        const foldOptions = getFoldOptions(ctx, true);
        if (blockQuote !== "folded" && type !== Scalar.Scalar.BLOCK_FOLDED) {
          foldOptions.onOverflow = () => {
            literalFallback = true;
          };
        }
        const body = foldFlowLines.foldFlowLines(`${start}${foldedValue}${end}`, indent, foldFlowLines.FOLD_BLOCK, foldOptions);
        if (!literalFallback)
          return `>${header}
${indent}${body}`;
      }
      value = value.replace(/\n+/g, `$&${indent}`);
      return `|${header}
${indent}${start}${value}${end}`;
    }
    function plainString(item, ctx, onComment, onChompKeep) {
      const { type, value } = item;
      const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;
      if (implicitKey && value.includes("\n") || inFlow && /[[\]{},]/.test(value)) {
        return quotedString(value, ctx);
      }
      if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
        return implicitKey || inFlow || !value.includes("\n") ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
      }
      if (!implicitKey && !inFlow && type !== Scalar.Scalar.PLAIN && value.includes("\n")) {
        return blockString(item, ctx, onComment, onChompKeep);
      }
      if (containsDocumentMarker(value)) {
        if (indent === "") {
          ctx.forceBlockIndent = true;
          return blockString(item, ctx, onComment, onChompKeep);
        } else if (implicitKey && indent === indentStep) {
          return quotedString(value, ctx);
        }
      }
      const str = value.replace(/\n+/g, `$&
${indent}`);
      if (actualString) {
        const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(str);
        const { compat, tags } = ctx.doc.schema;
        if (tags.some(test) || compat?.some(test))
          return quotedString(value, ctx);
      }
      return implicitKey ? str : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
    }
    function stringifyString(item, ctx, onComment, onChompKeep) {
      const { implicitKey, inFlow } = ctx;
      const ss = typeof item.value === "string" ? item : Object.assign({}, item, { value: String(item.value) });
      let { type } = item;
      if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
        if (/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(ss.value))
          type = Scalar.Scalar.QUOTE_DOUBLE;
      }
      const _stringify = (_type) => {
        switch (_type) {
          case Scalar.Scalar.BLOCK_FOLDED:
          case Scalar.Scalar.BLOCK_LITERAL:
            return implicitKey || inFlow ? quotedString(ss.value, ctx) : blockString(ss, ctx, onComment, onChompKeep);
          case Scalar.Scalar.QUOTE_DOUBLE:
            return doubleQuotedString(ss.value, ctx);
          case Scalar.Scalar.QUOTE_SINGLE:
            return singleQuotedString(ss.value, ctx);
          case Scalar.Scalar.PLAIN:
            return plainString(ss, ctx, onComment, onChompKeep);
          default:
            return null;
        }
      };
      let res = _stringify(type);
      if (res === null) {
        const { defaultKeyType, defaultStringType } = ctx.options;
        const t = implicitKey && defaultKeyType || defaultStringType;
        res = _stringify(t);
        if (res === null)
          throw new Error(`Unsupported default string type ${t}`);
      }
      return res;
    }
    exports2.stringifyString = stringifyString;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringify.js
var require_stringify = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringify.js"(exports2) {
    "use strict";
    var anchors = require_anchors();
    var identity = require_identity();
    var stringifyComment = require_stringifyComment();
    var stringifyString = require_stringifyString();
    function createStringifyContext(doc, options) {
      const opt = Object.assign({
        blockQuote: true,
        commentString: stringifyComment.stringifyComment,
        defaultKeyType: null,
        defaultStringType: "PLAIN",
        directives: null,
        doubleQuotedAsJSON: false,
        doubleQuotedMinMultiLineLength: 40,
        falseStr: "false",
        flowCollectionPadding: true,
        indentSeq: true,
        lineWidth: 80,
        minContentWidth: 20,
        nullStr: "null",
        simpleKeys: false,
        singleQuote: null,
        trueStr: "true",
        verifyAliasOrder: true
      }, doc.schema.toStringOptions, options);
      let inFlow;
      switch (opt.collectionStyle) {
        case "block":
          inFlow = false;
          break;
        case "flow":
          inFlow = true;
          break;
        default:
          inFlow = null;
      }
      return {
        anchors: /* @__PURE__ */ new Set(),
        doc,
        flowCollectionPadding: opt.flowCollectionPadding ? " " : "",
        indent: "",
        indentStep: typeof opt.indent === "number" ? " ".repeat(opt.indent) : "  ",
        inFlow,
        options: opt
      };
    }
    function getTagObject(tags, item) {
      if (item.tag) {
        const match = tags.filter((t) => t.tag === item.tag);
        if (match.length > 0)
          return match.find((t) => t.format === item.format) ?? match[0];
      }
      let tagObj = void 0;
      let obj;
      if (identity.isScalar(item)) {
        obj = item.value;
        let match = tags.filter((t) => t.identify?.(obj));
        if (match.length > 1) {
          const testMatch = match.filter((t) => t.test);
          if (testMatch.length > 0)
            match = testMatch;
        }
        tagObj = match.find((t) => t.format === item.format) ?? match.find((t) => !t.format);
      } else {
        obj = item;
        tagObj = tags.find((t) => t.nodeClass && obj instanceof t.nodeClass);
      }
      if (!tagObj) {
        const name = obj?.constructor?.name ?? (obj === null ? "null" : typeof obj);
        throw new Error(`Tag not resolved for ${name} value`);
      }
      return tagObj;
    }
    function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) {
      if (!doc.directives)
        return "";
      const props = [];
      const anchor = (identity.isScalar(node) || identity.isCollection(node)) && node.anchor;
      if (anchor && anchors.anchorIsValid(anchor)) {
        anchors$1.add(anchor);
        props.push(`&${anchor}`);
      }
      const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
      if (tag)
        props.push(doc.directives.tagString(tag));
      return props.join(" ");
    }
    function stringify(item, ctx, onComment, onChompKeep) {
      if (identity.isPair(item))
        return item.toString(ctx, onComment, onChompKeep);
      if (identity.isAlias(item)) {
        if (ctx.doc.directives)
          return item.toString(ctx);
        if (ctx.resolvedAliases?.has(item)) {
          throw new TypeError(`Cannot stringify circular structure without alias nodes`);
        } else {
          if (ctx.resolvedAliases)
            ctx.resolvedAliases.add(item);
          else
            ctx.resolvedAliases = /* @__PURE__ */ new Set([item]);
          item = item.resolve(ctx.doc);
        }
      }
      let tagObj = void 0;
      const node = identity.isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
      tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
      const props = stringifyProps(node, tagObj, ctx);
      if (props.length > 0)
        ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
      const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : identity.isScalar(node) ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
      if (!props)
        return str;
      return identity.isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
${ctx.indent}${str}`;
    }
    exports2.createStringifyContext = createStringifyContext;
    exports2.stringify = stringify;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyPair.js
var require_stringifyPair = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyPair.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Scalar = require_Scalar();
    var stringify = require_stringify();
    var stringifyComment = require_stringifyComment();
    function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
      const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
      let keyComment = identity.isNode(key) && key.comment || null;
      if (simpleKeys) {
        if (keyComment) {
          throw new Error("With simple keys, key nodes cannot have comments");
        }
        if (identity.isCollection(key) || !identity.isNode(key) && typeof key === "object") {
          const msg = "With simple keys, collection cannot be used as a key value";
          throw new Error(msg);
        }
      }
      let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || identity.isCollection(key) || (identity.isScalar(key) ? key.type === Scalar.Scalar.BLOCK_FOLDED || key.type === Scalar.Scalar.BLOCK_LITERAL : typeof key === "object"));
      ctx = Object.assign({}, ctx, {
        allNullValues: false,
        implicitKey: !explicitKey && (simpleKeys || !allNullValues),
        indent: indent + indentStep
      });
      let keyCommentDone = false;
      let chompKeep = false;
      let str = stringify.stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
      if (!explicitKey && !ctx.inFlow && str.length > 1024) {
        if (simpleKeys)
          throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
        explicitKey = true;
      }
      if (ctx.inFlow) {
        if (allNullValues || value == null) {
          if (keyCommentDone && onComment)
            onComment();
          return str === "" ? "?" : explicitKey ? `? ${str}` : str;
        }
      } else if (allNullValues && !simpleKeys || value == null && explicitKey) {
        str = `? ${str}`;
        if (keyComment && !keyCommentDone) {
          str += stringifyComment.lineComment(str, ctx.indent, commentString(keyComment));
        } else if (chompKeep && onChompKeep)
          onChompKeep();
        return str;
      }
      if (keyCommentDone)
        keyComment = null;
      if (explicitKey) {
        if (keyComment)
          str += stringifyComment.lineComment(str, ctx.indent, commentString(keyComment));
        str = `? ${str}
${indent}:`;
      } else {
        str = `${str}:`;
        if (keyComment)
          str += stringifyComment.lineComment(str, ctx.indent, commentString(keyComment));
      }
      let vsb, vcb, valueComment;
      if (identity.isNode(value)) {
        vsb = !!value.spaceBefore;
        vcb = value.commentBefore;
        valueComment = value.comment;
      } else {
        vsb = false;
        vcb = null;
        valueComment = null;
        if (value && typeof value === "object")
          value = doc.createNode(value);
      }
      ctx.implicitKey = false;
      if (!explicitKey && !keyComment && identity.isScalar(value))
        ctx.indentAtStart = str.length + 1;
      chompKeep = false;
      if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && identity.isSeq(value) && !value.flow && !value.tag && !value.anchor) {
        ctx.indent = ctx.indent.substring(2);
      }
      let valueCommentDone = false;
      const valueStr = stringify.stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
      let ws = " ";
      if (keyComment || vsb || vcb) {
        ws = vsb ? "\n" : "";
        if (vcb) {
          const cs = commentString(vcb);
          ws += `
${stringifyComment.indentComment(cs, ctx.indent)}`;
        }
        if (valueStr === "" && !ctx.inFlow) {
          if (ws === "\n" && valueComment)
            ws = "\n\n";
        } else {
          ws += `
${ctx.indent}`;
        }
      } else if (!explicitKey && identity.isCollection(value)) {
        const vs0 = valueStr[0];
        const nl0 = valueStr.indexOf("\n");
        const hasNewline = nl0 !== -1;
        const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;
        if (hasNewline || !flow) {
          let hasPropsLine = false;
          if (hasNewline && (vs0 === "&" || vs0 === "!")) {
            let sp0 = valueStr.indexOf(" ");
            if (vs0 === "&" && sp0 !== -1 && sp0 < nl0 && valueStr[sp0 + 1] === "!") {
              sp0 = valueStr.indexOf(" ", sp0 + 1);
            }
            if (sp0 === -1 || nl0 < sp0)
              hasPropsLine = true;
          }
          if (!hasPropsLine)
            ws = `
${ctx.indent}`;
        }
      } else if (valueStr === "" || valueStr[0] === "\n") {
        ws = "";
      }
      str += ws + valueStr;
      if (ctx.inFlow) {
        if (valueCommentDone && onComment)
          onComment();
      } else if (valueComment && !valueCommentDone) {
        str += stringifyComment.lineComment(str, ctx.indent, commentString(valueComment));
      } else if (chompKeep && onChompKeep) {
        onChompKeep();
      }
      return str;
    }
    exports2.stringifyPair = stringifyPair;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/log.js
var require_log = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/log.js"(exports2) {
    "use strict";
    var node_process = process;
    function debug(logLevel, ...messages) {
      if (logLevel === "debug")
        console.log(...messages);
    }
    function warn(logLevel, warning) {
      if (logLevel === "debug" || logLevel === "warn") {
        if (typeof node_process.emitWarning === "function")
          node_process.emitWarning(warning);
        else
          console.warn(warning);
      }
    }
    exports2.debug = debug;
    exports2.warn = warn;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/merge.js
var require_merge = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/merge.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Scalar = require_Scalar();
    var MERGE_KEY = "<<";
    var merge = {
      identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
      default: "key",
      tag: "tag:yaml.org,2002:merge",
      test: /^<<$/,
      resolve: () => Object.assign(new Scalar.Scalar(Symbol(MERGE_KEY)), {
        addToJSMap: addMergeToJSMap
      }),
      stringify: () => MERGE_KEY
    };
    var isMergeKey = (ctx, key) => (merge.identify(key) || identity.isScalar(key) && (!key.type || key.type === Scalar.Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
    function addMergeToJSMap(ctx, map, value) {
      value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
      if (identity.isSeq(value))
        for (const it of value.items)
          mergeValue(ctx, map, it);
      else if (Array.isArray(value))
        for (const it of value)
          mergeValue(ctx, map, it);
      else
        mergeValue(ctx, map, value);
    }
    function mergeValue(ctx, map, value) {
      const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
      if (!identity.isMap(source))
        throw new Error("Merge sources must be maps or map aliases");
      const srcMap = source.toJSON(null, ctx, Map);
      for (const [key, value2] of srcMap) {
        if (map instanceof Map) {
          if (!map.has(key))
            map.set(key, value2);
        } else if (map instanceof Set) {
          map.add(key);
        } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
          Object.defineProperty(map, key, {
            value: value2,
            writable: true,
            enumerable: true,
            configurable: true
          });
        }
      }
      return map;
    }
    exports2.addMergeToJSMap = addMergeToJSMap;
    exports2.isMergeKey = isMergeKey;
    exports2.merge = merge;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/addPairToJSMap.js
var require_addPairToJSMap = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/addPairToJSMap.js"(exports2) {
    "use strict";
    var log = require_log();
    var merge = require_merge();
    var stringify = require_stringify();
    var identity = require_identity();
    var toJS = require_toJS();
    function addPairToJSMap(ctx, map, { key, value }) {
      if (identity.isNode(key) && key.addToJSMap)
        key.addToJSMap(ctx, map, value);
      else if (merge.isMergeKey(ctx, key))
        merge.addMergeToJSMap(ctx, map, value);
      else {
        const jsKey = toJS.toJS(key, "", ctx);
        if (map instanceof Map) {
          map.set(jsKey, toJS.toJS(value, jsKey, ctx));
        } else if (map instanceof Set) {
          map.add(jsKey);
        } else {
          const stringKey = stringifyKey(key, jsKey, ctx);
          const jsValue = toJS.toJS(value, stringKey, ctx);
          if (stringKey in map)
            Object.defineProperty(map, stringKey, {
              value: jsValue,
              writable: true,
              enumerable: true,
              configurable: true
            });
          else
            map[stringKey] = jsValue;
        }
      }
      return map;
    }
    function stringifyKey(key, jsKey, ctx) {
      if (jsKey === null)
        return "";
      if (typeof jsKey !== "object")
        return String(jsKey);
      if (identity.isNode(key) && ctx?.doc) {
        const strCtx = stringify.createStringifyContext(ctx.doc, {});
        strCtx.anchors = /* @__PURE__ */ new Set();
        for (const node of ctx.anchors.keys())
          strCtx.anchors.add(node.anchor);
        strCtx.inFlow = true;
        strCtx.inStringifyKey = true;
        const strKey = key.toString(strCtx);
        if (!ctx.mapKeyWarned) {
          let jsonStr = JSON.stringify(strKey);
          if (jsonStr.length > 40)
            jsonStr = jsonStr.substring(0, 36) + '..."';
          log.warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
          ctx.mapKeyWarned = true;
        }
        return strKey;
      }
      return JSON.stringify(jsKey);
    }
    exports2.addPairToJSMap = addPairToJSMap;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Pair.js
var require_Pair = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/Pair.js"(exports2) {
    "use strict";
    var createNode = require_createNode();
    var stringifyPair = require_stringifyPair();
    var addPairToJSMap = require_addPairToJSMap();
    var identity = require_identity();
    function createPair(key, value, ctx) {
      const k = createNode.createNode(key, void 0, ctx);
      const v = createNode.createNode(value, void 0, ctx);
      return new Pair(k, v);
    }
    var Pair = class _Pair {
      constructor(key, value = null) {
        Object.defineProperty(this, identity.NODE_TYPE, { value: identity.PAIR });
        this.key = key;
        this.value = value;
      }
      clone(schema) {
        let { key, value } = this;
        if (identity.isNode(key))
          key = key.clone(schema);
        if (identity.isNode(value))
          value = value.clone(schema);
        return new _Pair(key, value);
      }
      toJSON(_, ctx) {
        const pair = ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
        return addPairToJSMap.addPairToJSMap(ctx, pair, this);
      }
      toString(ctx, onComment, onChompKeep) {
        return ctx?.doc ? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep) : JSON.stringify(this);
      }
    };
    exports2.Pair = Pair;
    exports2.createPair = createPair;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyCollection.js
var require_stringifyCollection = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyCollection.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var stringify = require_stringify();
    var stringifyComment = require_stringifyComment();
    function stringifyCollection(collection, ctx, options) {
      const flow = ctx.inFlow ?? collection.flow;
      const stringify2 = flow ? stringifyFlowCollection : stringifyBlockCollection;
      return stringify2(collection, ctx, options);
    }
    function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {
      const { indent, options: { commentString } } = ctx;
      const itemCtx = Object.assign({}, ctx, { indent: itemIndent, type: null });
      let chompKeep = false;
      const lines = [];
      for (let i = 0; i < items.length; ++i) {
        const item = items[i];
        let comment2 = null;
        if (identity.isNode(item)) {
          if (!chompKeep && item.spaceBefore)
            lines.push("");
          addCommentBefore(ctx, lines, item.commentBefore, chompKeep);
          if (item.comment)
            comment2 = item.comment;
        } else if (identity.isPair(item)) {
          const ik = identity.isNode(item.key) ? item.key : null;
          if (ik) {
            if (!chompKeep && ik.spaceBefore)
              lines.push("");
            addCommentBefore(ctx, lines, ik.commentBefore, chompKeep);
          }
        }
        chompKeep = false;
        let str2 = stringify.stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
        if (comment2)
          str2 += stringifyComment.lineComment(str2, itemIndent, commentString(comment2));
        if (chompKeep && comment2)
          chompKeep = false;
        lines.push(blockItemPrefix + str2);
      }
      let str;
      if (lines.length === 0) {
        str = flowChars.start + flowChars.end;
      } else {
        str = lines[0];
        for (let i = 1; i < lines.length; ++i) {
          const line = lines[i];
          str += line ? `
${indent}${line}` : "\n";
        }
      }
      if (comment) {
        str += "\n" + stringifyComment.indentComment(commentString(comment), indent);
        if (onComment)
          onComment();
      } else if (chompKeep && onChompKeep)
        onChompKeep();
      return str;
    }
    function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
      const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
      itemIndent += indentStep;
      const itemCtx = Object.assign({}, ctx, {
        indent: itemIndent,
        inFlow: true,
        type: null
      });
      let reqNewline = false;
      let linesAtValue = 0;
      const lines = [];
      for (let i = 0; i < items.length; ++i) {
        const item = items[i];
        let comment = null;
        if (identity.isNode(item)) {
          if (item.spaceBefore)
            lines.push("");
          addCommentBefore(ctx, lines, item.commentBefore, false);
          if (item.comment)
            comment = item.comment;
        } else if (identity.isPair(item)) {
          const ik = identity.isNode(item.key) ? item.key : null;
          if (ik) {
            if (ik.spaceBefore)
              lines.push("");
            addCommentBefore(ctx, lines, ik.commentBefore, false);
            if (ik.comment)
              reqNewline = true;
          }
          const iv = identity.isNode(item.value) ? item.value : null;
          if (iv) {
            if (iv.comment)
              comment = iv.comment;
            if (iv.commentBefore)
              reqNewline = true;
          } else if (item.value == null && ik?.comment) {
            comment = ik.comment;
          }
        }
        if (comment)
          reqNewline = true;
        let str = stringify.stringify(item, itemCtx, () => comment = null);
        if (i < items.length - 1)
          str += ",";
        if (comment)
          str += stringifyComment.lineComment(str, itemIndent, commentString(comment));
        if (!reqNewline && (lines.length > linesAtValue || str.includes("\n")))
          reqNewline = true;
        lines.push(str);
        linesAtValue = lines.length;
      }
      const { start, end } = flowChars;
      if (lines.length === 0) {
        return start + end;
      } else {
        if (!reqNewline) {
          const len = lines.reduce((sum, line) => sum + line.length + 2, 2);
          reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
        }
        if (reqNewline) {
          let str = start;
          for (const line of lines)
            str += line ? `
${indentStep}${indent}${line}` : "\n";
          return `${str}
${indent}${end}`;
        } else {
          return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
        }
      }
    }
    function addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {
      if (comment && chompKeep)
        comment = comment.replace(/^\n+/, "");
      if (comment) {
        const ic = stringifyComment.indentComment(commentString(comment), indent);
        lines.push(ic.trimStart());
      }
    }
    exports2.stringifyCollection = stringifyCollection;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/YAMLMap.js
var require_YAMLMap = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/YAMLMap.js"(exports2) {
    "use strict";
    var stringifyCollection = require_stringifyCollection();
    var addPairToJSMap = require_addPairToJSMap();
    var Collection = require_Collection();
    var identity = require_identity();
    var Pair = require_Pair();
    var Scalar = require_Scalar();
    function findPair(items, key) {
      const k = identity.isScalar(key) ? key.value : key;
      for (const it of items) {
        if (identity.isPair(it)) {
          if (it.key === key || it.key === k)
            return it;
          if (identity.isScalar(it.key) && it.key.value === k)
            return it;
        }
      }
      return void 0;
    }
    var YAMLMap = class extends Collection.Collection {
      static get tagName() {
        return "tag:yaml.org,2002:map";
      }
      constructor(schema) {
        super(identity.MAP, schema);
        this.items = [];
      }
      /**
       * A generic collection parsing method that can be extended
       * to other node classes that inherit from YAMLMap
       */
      static from(schema, obj, ctx) {
        const { keepUndefined, replacer } = ctx;
        const map = new this(schema);
        const add = (key, value) => {
          if (typeof replacer === "function")
            value = replacer.call(obj, key, value);
          else if (Array.isArray(replacer) && !replacer.includes(key))
            return;
          if (value !== void 0 || keepUndefined)
            map.items.push(Pair.createPair(key, value, ctx));
        };
        if (obj instanceof Map) {
          for (const [key, value] of obj)
            add(key, value);
        } else if (obj && typeof obj === "object") {
          for (const key of Object.keys(obj))
            add(key, obj[key]);
        }
        if (typeof schema.sortMapEntries === "function") {
          map.items.sort(schema.sortMapEntries);
        }
        return map;
      }
      /**
       * Adds a value to the collection.
       *
       * @param overwrite - If not set `true`, using a key that is already in the
       *   collection will throw. Otherwise, overwrites the previous value.
       */
      add(pair, overwrite) {
        let _pair;
        if (identity.isPair(pair))
          _pair = pair;
        else if (!pair || typeof pair !== "object" || !("key" in pair)) {
          _pair = new Pair.Pair(pair, pair?.value);
        } else
          _pair = new Pair.Pair(pair.key, pair.value);
        const prev = findPair(this.items, _pair.key);
        const sortEntries = this.schema?.sortMapEntries;
        if (prev) {
          if (!overwrite)
            throw new Error(`Key ${_pair.key} already set`);
          if (identity.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
            prev.value.value = _pair.value;
          else
            prev.value = _pair.value;
        } else if (sortEntries) {
          const i = this.items.findIndex((item) => sortEntries(_pair, item) < 0);
          if (i === -1)
            this.items.push(_pair);
          else
            this.items.splice(i, 0, _pair);
        } else {
          this.items.push(_pair);
        }
      }
      delete(key) {
        const it = findPair(this.items, key);
        if (!it)
          return false;
        const del = this.items.splice(this.items.indexOf(it), 1);
        return del.length > 0;
      }
      get(key, keepScalar) {
        const it = findPair(this.items, key);
        const node = it?.value;
        return (!keepScalar && identity.isScalar(node) ? node.value : node) ?? void 0;
      }
      has(key) {
        return !!findPair(this.items, key);
      }
      set(key, value) {
        this.add(new Pair.Pair(key, value), true);
      }
      /**
       * @param ctx - Conversion context, originally set in Document#toJS()
       * @param {Class} Type - If set, forces the returned collection type
       * @returns Instance of Type, Map, or Object
       */
      toJSON(_, ctx, Type) {
        const map = Type ? new Type() : ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
        if (ctx?.onCreate)
          ctx.onCreate(map);
        for (const item of this.items)
          addPairToJSMap.addPairToJSMap(ctx, map, item);
        return map;
      }
      toString(ctx, onComment, onChompKeep) {
        if (!ctx)
          return JSON.stringify(this);
        for (const item of this.items) {
          if (!identity.isPair(item))
            throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
        }
        if (!ctx.allNullValues && this.hasAllNullValues(false))
          ctx = Object.assign({}, ctx, { allNullValues: true });
        return stringifyCollection.stringifyCollection(this, ctx, {
          blockItemPrefix: "",
          flowChars: { start: "{", end: "}" },
          itemIndent: ctx.indent || "",
          onChompKeep,
          onComment
        });
      }
    };
    exports2.YAMLMap = YAMLMap;
    exports2.findPair = findPair;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/map.js
var require_map = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/map.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var YAMLMap = require_YAMLMap();
    var map = {
      collection: "map",
      default: true,
      nodeClass: YAMLMap.YAMLMap,
      tag: "tag:yaml.org,2002:map",
      resolve(map2, onError) {
        if (!identity.isMap(map2))
          onError("Expected a mapping for this tag");
        return map2;
      },
      createNode: (schema, obj, ctx) => YAMLMap.YAMLMap.from(schema, obj, ctx)
    };
    exports2.map = map;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/YAMLSeq.js
var require_YAMLSeq = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/YAMLSeq.js"(exports2) {
    "use strict";
    var createNode = require_createNode();
    var stringifyCollection = require_stringifyCollection();
    var Collection = require_Collection();
    var identity = require_identity();
    var Scalar = require_Scalar();
    var toJS = require_toJS();
    var YAMLSeq = class extends Collection.Collection {
      static get tagName() {
        return "tag:yaml.org,2002:seq";
      }
      constructor(schema) {
        super(identity.SEQ, schema);
        this.items = [];
      }
      add(value) {
        this.items.push(value);
      }
      /**
       * Removes a value from the collection.
       *
       * `key` must contain a representation of an integer for this to succeed.
       * It may be wrapped in a `Scalar`.
       *
       * @returns `true` if the item was found and removed.
       */
      delete(key) {
        const idx = asItemIndex(key);
        if (typeof idx !== "number")
          return false;
        const del = this.items.splice(idx, 1);
        return del.length > 0;
      }
      get(key, keepScalar) {
        const idx = asItemIndex(key);
        if (typeof idx !== "number")
          return void 0;
        const it = this.items[idx];
        return !keepScalar && identity.isScalar(it) ? it.value : it;
      }
      /**
       * Checks if the collection includes a value with the key `key`.
       *
       * `key` must contain a representation of an integer for this to succeed.
       * It may be wrapped in a `Scalar`.
       */
      has(key) {
        const idx = asItemIndex(key);
        return typeof idx === "number" && idx < this.items.length;
      }
      /**
       * Sets a value in this collection. For `!!set`, `value` needs to be a
       * boolean to add/remove the item from the set.
       *
       * If `key` does not contain a representation of an integer, this will throw.
       * It may be wrapped in a `Scalar`.
       */
      set(key, value) {
        const idx = asItemIndex(key);
        if (typeof idx !== "number")
          throw new Error(`Expected a valid index, not ${key}.`);
        const prev = this.items[idx];
        if (identity.isScalar(prev) && Scalar.isScalarValue(value))
          prev.value = value;
        else
          this.items[idx] = value;
      }
      toJSON(_, ctx) {
        const seq = [];
        if (ctx?.onCreate)
          ctx.onCreate(seq);
        let i = 0;
        for (const item of this.items)
          seq.push(toJS.toJS(item, String(i++), ctx));
        return seq;
      }
      toString(ctx, onComment, onChompKeep) {
        if (!ctx)
          return JSON.stringify(this);
        return stringifyCollection.stringifyCollection(this, ctx, {
          blockItemPrefix: "- ",
          flowChars: { start: "[", end: "]" },
          itemIndent: (ctx.indent || "") + "  ",
          onChompKeep,
          onComment
        });
      }
      static from(schema, obj, ctx) {
        const { replacer } = ctx;
        const seq = new this(schema);
        if (obj && Symbol.iterator in Object(obj)) {
          let i = 0;
          for (let it of obj) {
            if (typeof replacer === "function") {
              const key = obj instanceof Set ? it : String(i++);
              it = replacer.call(obj, key, it);
            }
            seq.items.push(createNode.createNode(it, void 0, ctx));
          }
        }
        return seq;
      }
    };
    function asItemIndex(key) {
      let idx = identity.isScalar(key) ? key.value : key;
      if (idx && typeof idx === "string")
        idx = Number(idx);
      return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
    }
    exports2.YAMLSeq = YAMLSeq;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/seq.js
var require_seq = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/seq.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var YAMLSeq = require_YAMLSeq();
    var seq = {
      collection: "seq",
      default: true,
      nodeClass: YAMLSeq.YAMLSeq,
      tag: "tag:yaml.org,2002:seq",
      resolve(seq2, onError) {
        if (!identity.isSeq(seq2))
          onError("Expected a sequence for this tag");
        return seq2;
      },
      createNode: (schema, obj, ctx) => YAMLSeq.YAMLSeq.from(schema, obj, ctx)
    };
    exports2.seq = seq;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/string.js
var require_string = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/string.js"(exports2) {
    "use strict";
    var stringifyString = require_stringifyString();
    var string = {
      identify: (value) => typeof value === "string",
      default: true,
      tag: "tag:yaml.org,2002:str",
      resolve: (str) => str,
      stringify(item, ctx, onComment, onChompKeep) {
        ctx = Object.assign({ actualString: true }, ctx);
        return stringifyString.stringifyString(item, ctx, onComment, onChompKeep);
      }
    };
    exports2.string = string;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/null.js
var require_null = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/common/null.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    var nullTag = {
      identify: (value) => value == null,
      createNode: () => new Scalar.Scalar(null),
      default: true,
      tag: "tag:yaml.org,2002:null",
      test: /^(?:~|[Nn]ull|NULL)?$/,
      resolve: () => new Scalar.Scalar(null),
      stringify: ({ source }, ctx) => typeof source === "string" && nullTag.test.test(source) ? source : ctx.options.nullStr
    };
    exports2.nullTag = nullTag;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/bool.js
var require_bool = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/bool.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    var boolTag = {
      identify: (value) => typeof value === "boolean",
      default: true,
      tag: "tag:yaml.org,2002:bool",
      test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
      resolve: (str) => new Scalar.Scalar(str[0] === "t" || str[0] === "T"),
      stringify({ source, value }, ctx) {
        if (source && boolTag.test.test(source)) {
          const sv = source[0] === "t" || source[0] === "T";
          if (value === sv)
            return source;
        }
        return value ? ctx.options.trueStr : ctx.options.falseStr;
      }
    };
    exports2.boolTag = boolTag;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyNumber.js
var require_stringifyNumber = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyNumber.js"(exports2) {
    "use strict";
    function stringifyNumber({ format, minFractionDigits, tag, value }) {
      if (typeof value === "bigint")
        return String(value);
      const num = typeof value === "number" ? value : Number(value);
      if (!isFinite(num))
        return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
      let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
      if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^\d/.test(n)) {
        let i = n.indexOf(".");
        if (i < 0) {
          i = n.length;
          n += ".";
        }
        let d = minFractionDigits - (n.length - i - 1);
        while (d-- > 0)
          n += "0";
      }
      return n;
    }
    exports2.stringifyNumber = stringifyNumber;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/float.js
var require_float = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/float.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    var stringifyNumber = require_stringifyNumber();
    var floatNaN = {
      identify: (value) => typeof value === "number",
      default: true,
      tag: "tag:yaml.org,2002:float",
      test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
      resolve: (str) => str.slice(-3).toLowerCase() === "nan" ? NaN : str[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
      stringify: stringifyNumber.stringifyNumber
    };
    var floatExp = {
      identify: (value) => typeof value === "number",
      default: true,
      tag: "tag:yaml.org,2002:float",
      format: "EXP",
      test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
      resolve: (str) => parseFloat(str),
      stringify(node) {
        const num = Number(node.value);
        return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
      }
    };
    var float = {
      identify: (value) => typeof value === "number",
      default: true,
      tag: "tag:yaml.org,2002:float",
      test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
      resolve(str) {
        const node = new Scalar.Scalar(parseFloat(str));
        const dot = str.indexOf(".");
        if (dot !== -1 && str[str.length - 1] === "0")
          node.minFractionDigits = str.length - dot - 1;
        return node;
      },
      stringify: stringifyNumber.stringifyNumber
    };
    exports2.float = float;
    exports2.floatExp = floatExp;
    exports2.floatNaN = floatNaN;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/int.js
var require_int = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/int.js"(exports2) {
    "use strict";
    var stringifyNumber = require_stringifyNumber();
    var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
    var intResolve = (str, offset, radix, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix);
    function intStringify(node, radix, prefix) {
      const { value } = node;
      if (intIdentify(value) && value >= 0)
        return prefix + value.toString(radix);
      return stringifyNumber.stringifyNumber(node);
    }
    var intOct = {
      identify: (value) => intIdentify(value) && value >= 0,
      default: true,
      tag: "tag:yaml.org,2002:int",
      format: "OCT",
      test: /^0o[0-7]+$/,
      resolve: (str, _onError, opt) => intResolve(str, 2, 8, opt),
      stringify: (node) => intStringify(node, 8, "0o")
    };
    var int = {
      identify: intIdentify,
      default: true,
      tag: "tag:yaml.org,2002:int",
      test: /^[-+]?[0-9]+$/,
      resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),
      stringify: stringifyNumber.stringifyNumber
    };
    var intHex = {
      identify: (value) => intIdentify(value) && value >= 0,
      default: true,
      tag: "tag:yaml.org,2002:int",
      format: "HEX",
      test: /^0x[0-9a-fA-F]+$/,
      resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),
      stringify: (node) => intStringify(node, 16, "0x")
    };
    exports2.int = int;
    exports2.intHex = intHex;
    exports2.intOct = intOct;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/schema.js
var require_schema = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/core/schema.js"(exports2) {
    "use strict";
    var map = require_map();
    var _null = require_null();
    var seq = require_seq();
    var string = require_string();
    var bool = require_bool();
    var float = require_float();
    var int = require_int();
    var schema = [
      map.map,
      seq.seq,
      string.string,
      _null.nullTag,
      bool.boolTag,
      int.intOct,
      int.int,
      int.intHex,
      float.floatNaN,
      float.floatExp,
      float.float
    ];
    exports2.schema = schema;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/json/schema.js
var require_schema2 = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/json/schema.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    var map = require_map();
    var seq = require_seq();
    function intIdentify(value) {
      return typeof value === "bigint" || Number.isInteger(value);
    }
    var stringifyJSON = ({ value }) => JSON.stringify(value);
    var jsonScalars = [
      {
        identify: (value) => typeof value === "string",
        default: true,
        tag: "tag:yaml.org,2002:str",
        resolve: (str) => str,
        stringify: stringifyJSON
      },
      {
        identify: (value) => value == null,
        createNode: () => new Scalar.Scalar(null),
        default: true,
        tag: "tag:yaml.org,2002:null",
        test: /^null$/,
        resolve: () => null,
        stringify: stringifyJSON
      },
      {
        identify: (value) => typeof value === "boolean",
        default: true,
        tag: "tag:yaml.org,2002:bool",
        test: /^true$|^false$/,
        resolve: (str) => str === "true",
        stringify: stringifyJSON
      },
      {
        identify: intIdentify,
        default: true,
        tag: "tag:yaml.org,2002:int",
        test: /^-?(?:0|[1-9][0-9]*)$/,
        resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),
        stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)
      },
      {
        identify: (value) => typeof value === "number",
        default: true,
        tag: "tag:yaml.org,2002:float",
        test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
        resolve: (str) => parseFloat(str),
        stringify: stringifyJSON
      }
    ];
    var jsonError = {
      default: true,
      tag: "",
      test: /^/,
      resolve(str, onError) {
        onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
        return str;
      }
    };
    var schema = [map.map, seq.seq].concat(jsonScalars, jsonError);
    exports2.schema = schema;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/binary.js
var require_binary = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/binary.js"(exports2) {
    "use strict";
    var node_buffer = require("buffer");
    var Scalar = require_Scalar();
    var stringifyString = require_stringifyString();
    var binary = {
      identify: (value) => value instanceof Uint8Array,
      // Buffer inherits from Uint8Array
      default: false,
      tag: "tag:yaml.org,2002:binary",
      /**
       * Returns a Buffer in node and an Uint8Array in browsers
       *
       * To use the resulting buffer as an image, you'll want to do something like:
       *
       *   const blob = new Blob([buffer], { type: 'image/jpeg' })
       *   document.querySelector('#photo').src = URL.createObjectURL(blob)
       */
      resolve(src, onError) {
        if (typeof node_buffer.Buffer === "function") {
          return node_buffer.Buffer.from(src, "base64");
        } else if (typeof atob === "function") {
          const str = atob(src.replace(/[\n\r]/g, ""));
          const buffer = new Uint8Array(str.length);
          for (let i = 0; i < str.length; ++i)
            buffer[i] = str.charCodeAt(i);
          return buffer;
        } else {
          onError("This environment does not support reading binary tags; either Buffer or atob is required");
          return src;
        }
      },
      stringify({ comment, type, value }, ctx, onComment, onChompKeep) {
        if (!value)
          return "";
        const buf = value;
        let str;
        if (typeof node_buffer.Buffer === "function") {
          str = buf instanceof node_buffer.Buffer ? buf.toString("base64") : node_buffer.Buffer.from(buf.buffer).toString("base64");
        } else if (typeof btoa === "function") {
          let s = "";
          for (let i = 0; i < buf.length; ++i)
            s += String.fromCharCode(buf[i]);
          str = btoa(s);
        } else {
          throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
        }
        type ?? (type = Scalar.Scalar.BLOCK_LITERAL);
        if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
          const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
          const n = Math.ceil(str.length / lineWidth);
          const lines = new Array(n);
          for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
            lines[i] = str.substr(o, lineWidth);
          }
          str = lines.join(type === Scalar.Scalar.BLOCK_LITERAL ? "\n" : " ");
        }
        return stringifyString.stringifyString({ comment, type, value: str }, ctx, onComment, onChompKeep);
      }
    };
    exports2.binary = binary;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/pairs.js
var require_pairs = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/pairs.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Pair = require_Pair();
    var Scalar = require_Scalar();
    var YAMLSeq = require_YAMLSeq();
    function resolvePairs(seq, onError) {
      if (identity.isSeq(seq)) {
        for (let i = 0; i < seq.items.length; ++i) {
          let item = seq.items[i];
          if (identity.isPair(item))
            continue;
          else if (identity.isMap(item)) {
            if (item.items.length > 1)
              onError("Each pair must have its own sequence indicator");
            const pair = item.items[0] || new Pair.Pair(new Scalar.Scalar(null));
            if (item.commentBefore)
              pair.key.commentBefore = pair.key.commentBefore ? `${item.commentBefore}
${pair.key.commentBefore}` : item.commentBefore;
            if (item.comment) {
              const cn = pair.value ?? pair.key;
              cn.comment = cn.comment ? `${item.comment}
${cn.comment}` : item.comment;
            }
            item = pair;
          }
          seq.items[i] = identity.isPair(item) ? item : new Pair.Pair(item);
        }
      } else
        onError("Expected a sequence for this tag");
      return seq;
    }
    function createPairs(schema, iterable, ctx) {
      const { replacer } = ctx;
      const pairs2 = new YAMLSeq.YAMLSeq(schema);
      pairs2.tag = "tag:yaml.org,2002:pairs";
      let i = 0;
      if (iterable && Symbol.iterator in Object(iterable))
        for (let it of iterable) {
          if (typeof replacer === "function")
            it = replacer.call(iterable, String(i++), it);
          let key, value;
          if (Array.isArray(it)) {
            if (it.length === 2) {
              key = it[0];
              value = it[1];
            } else
              throw new TypeError(`Expected [key, value] tuple: ${it}`);
          } else if (it && it instanceof Object) {
            const keys = Object.keys(it);
            if (keys.length === 1) {
              key = keys[0];
              value = it[key];
            } else {
              throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);
            }
          } else {
            key = it;
          }
          pairs2.items.push(Pair.createPair(key, value, ctx));
        }
      return pairs2;
    }
    var pairs = {
      collection: "seq",
      default: false,
      tag: "tag:yaml.org,2002:pairs",
      resolve: resolvePairs,
      createNode: createPairs
    };
    exports2.createPairs = createPairs;
    exports2.pairs = pairs;
    exports2.resolvePairs = resolvePairs;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/omap.js
var require_omap = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/omap.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var toJS = require_toJS();
    var YAMLMap = require_YAMLMap();
    var YAMLSeq = require_YAMLSeq();
    var pairs = require_pairs();
    var YAMLOMap = class _YAMLOMap extends YAMLSeq.YAMLSeq {
      constructor() {
        super();
        this.add = YAMLMap.YAMLMap.prototype.add.bind(this);
        this.delete = YAMLMap.YAMLMap.prototype.delete.bind(this);
        this.get = YAMLMap.YAMLMap.prototype.get.bind(this);
        this.has = YAMLMap.YAMLMap.prototype.has.bind(this);
        this.set = YAMLMap.YAMLMap.prototype.set.bind(this);
        this.tag = _YAMLOMap.tag;
      }
      /**
       * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
       * but TypeScript won't allow widening the signature of a child method.
       */
      toJSON(_, ctx) {
        if (!ctx)
          return super.toJSON(_);
        const map = /* @__PURE__ */ new Map();
        if (ctx?.onCreate)
          ctx.onCreate(map);
        for (const pair of this.items) {
          let key, value;
          if (identity.isPair(pair)) {
            key = toJS.toJS(pair.key, "", ctx);
            value = toJS.toJS(pair.value, key, ctx);
          } else {
            key = toJS.toJS(pair, "", ctx);
          }
          if (map.has(key))
            throw new Error("Ordered maps must not include duplicate keys");
          map.set(key, value);
        }
        return map;
      }
      static from(schema, iterable, ctx) {
        const pairs$1 = pairs.createPairs(schema, iterable, ctx);
        const omap2 = new this();
        omap2.items = pairs$1.items;
        return omap2;
      }
    };
    YAMLOMap.tag = "tag:yaml.org,2002:omap";
    var omap = {
      collection: "seq",
      identify: (value) => value instanceof Map,
      nodeClass: YAMLOMap,
      default: false,
      tag: "tag:yaml.org,2002:omap",
      resolve(seq, onError) {
        const pairs$1 = pairs.resolvePairs(seq, onError);
        const seenKeys = [];
        for (const { key } of pairs$1.items) {
          if (identity.isScalar(key)) {
            if (seenKeys.includes(key.value)) {
              onError(`Ordered maps must not include duplicate keys: ${key.value}`);
            } else {
              seenKeys.push(key.value);
            }
          }
        }
        return Object.assign(new YAMLOMap(), pairs$1);
      },
      createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)
    };
    exports2.YAMLOMap = YAMLOMap;
    exports2.omap = omap;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/bool.js
var require_bool2 = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/bool.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    function boolStringify({ value, source }, ctx) {
      const boolObj = value ? trueTag : falseTag;
      if (source && boolObj.test.test(source))
        return source;
      return value ? ctx.options.trueStr : ctx.options.falseStr;
    }
    var trueTag = {
      identify: (value) => value === true,
      default: true,
      tag: "tag:yaml.org,2002:bool",
      test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
      resolve: () => new Scalar.Scalar(true),
      stringify: boolStringify
    };
    var falseTag = {
      identify: (value) => value === false,
      default: true,
      tag: "tag:yaml.org,2002:bool",
      test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
      resolve: () => new Scalar.Scalar(false),
      stringify: boolStringify
    };
    exports2.falseTag = falseTag;
    exports2.trueTag = trueTag;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/float.js
var require_float2 = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/float.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    var stringifyNumber = require_stringifyNumber();
    var floatNaN = {
      identify: (value) => typeof value === "number",
      default: true,
      tag: "tag:yaml.org,2002:float",
      test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
      resolve: (str) => str.slice(-3).toLowerCase() === "nan" ? NaN : str[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
      stringify: stringifyNumber.stringifyNumber
    };
    var floatExp = {
      identify: (value) => typeof value === "number",
      default: true,
      tag: "tag:yaml.org,2002:float",
      format: "EXP",
      test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
      resolve: (str) => parseFloat(str.replace(/_/g, "")),
      stringify(node) {
        const num = Number(node.value);
        return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
      }
    };
    var float = {
      identify: (value) => typeof value === "number",
      default: true,
      tag: "tag:yaml.org,2002:float",
      test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
      resolve(str) {
        const node = new Scalar.Scalar(parseFloat(str.replace(/_/g, "")));
        const dot = str.indexOf(".");
        if (dot !== -1) {
          const f = str.substring(dot + 1).replace(/_/g, "");
          if (f[f.length - 1] === "0")
            node.minFractionDigits = f.length;
        }
        return node;
      },
      stringify: stringifyNumber.stringifyNumber
    };
    exports2.float = float;
    exports2.floatExp = floatExp;
    exports2.floatNaN = floatNaN;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/int.js
var require_int2 = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/int.js"(exports2) {
    "use strict";
    var stringifyNumber = require_stringifyNumber();
    var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
    function intResolve(str, offset, radix, { intAsBigInt }) {
      const sign = str[0];
      if (sign === "-" || sign === "+")
        offset += 1;
      str = str.substring(offset).replace(/_/g, "");
      if (intAsBigInt) {
        switch (radix) {
          case 2:
            str = `0b${str}`;
            break;
          case 8:
            str = `0o${str}`;
            break;
          case 16:
            str = `0x${str}`;
            break;
        }
        const n2 = BigInt(str);
        return sign === "-" ? BigInt(-1) * n2 : n2;
      }
      const n = parseInt(str, radix);
      return sign === "-" ? -1 * n : n;
    }
    function intStringify(node, radix, prefix) {
      const { value } = node;
      if (intIdentify(value)) {
        const str = value.toString(radix);
        return value < 0 ? "-" + prefix + str.substr(1) : prefix + str;
      }
      return stringifyNumber.stringifyNumber(node);
    }
    var intBin = {
      identify: intIdentify,
      default: true,
      tag: "tag:yaml.org,2002:int",
      format: "BIN",
      test: /^[-+]?0b[0-1_]+$/,
      resolve: (str, _onError, opt) => intResolve(str, 2, 2, opt),
      stringify: (node) => intStringify(node, 2, "0b")
    };
    var intOct = {
      identify: intIdentify,
      default: true,
      tag: "tag:yaml.org,2002:int",
      format: "OCT",
      test: /^[-+]?0[0-7_]+$/,
      resolve: (str, _onError, opt) => intResolve(str, 1, 8, opt),
      stringify: (node) => intStringify(node, 8, "0")
    };
    var int = {
      identify: intIdentify,
      default: true,
      tag: "tag:yaml.org,2002:int",
      test: /^[-+]?[0-9][0-9_]*$/,
      resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),
      stringify: stringifyNumber.stringifyNumber
    };
    var intHex = {
      identify: intIdentify,
      default: true,
      tag: "tag:yaml.org,2002:int",
      format: "HEX",
      test: /^[-+]?0x[0-9a-fA-F_]+$/,
      resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),
      stringify: (node) => intStringify(node, 16, "0x")
    };
    exports2.int = int;
    exports2.intBin = intBin;
    exports2.intHex = intHex;
    exports2.intOct = intOct;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/set.js
var require_set = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/set.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Pair = require_Pair();
    var YAMLMap = require_YAMLMap();
    var YAMLSet = class _YAMLSet extends YAMLMap.YAMLMap {
      constructor(schema) {
        super(schema);
        this.tag = _YAMLSet.tag;
      }
      add(key) {
        let pair;
        if (identity.isPair(key))
          pair = key;
        else if (key && typeof key === "object" && "key" in key && "value" in key && key.value === null)
          pair = new Pair.Pair(key.key, null);
        else
          pair = new Pair.Pair(key, null);
        const prev = YAMLMap.findPair(this.items, pair.key);
        if (!prev)
          this.items.push(pair);
      }
      /**
       * If `keepPair` is `true`, returns the Pair matching `key`.
       * Otherwise, returns the value of that Pair's key.
       */
      get(key, keepPair) {
        const pair = YAMLMap.findPair(this.items, key);
        return !keepPair && identity.isPair(pair) ? identity.isScalar(pair.key) ? pair.key.value : pair.key : pair;
      }
      set(key, value) {
        if (typeof value !== "boolean")
          throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
        const prev = YAMLMap.findPair(this.items, key);
        if (prev && !value) {
          this.items.splice(this.items.indexOf(prev), 1);
        } else if (!prev && value) {
          this.items.push(new Pair.Pair(key));
        }
      }
      toJSON(_, ctx) {
        return super.toJSON(_, ctx, Set);
      }
      toString(ctx, onComment, onChompKeep) {
        if (!ctx)
          return JSON.stringify(this);
        if (this.hasAllNullValues(true))
          return super.toString(Object.assign({}, ctx, { allNullValues: true }), onComment, onChompKeep);
        else
          throw new Error("Set items must all have null values");
      }
      static from(schema, iterable, ctx) {
        const { replacer } = ctx;
        const set2 = new this(schema);
        if (iterable && Symbol.iterator in Object(iterable))
          for (let value of iterable) {
            if (typeof replacer === "function")
              value = replacer.call(iterable, value, value);
            set2.items.push(Pair.createPair(value, null, ctx));
          }
        return set2;
      }
    };
    YAMLSet.tag = "tag:yaml.org,2002:set";
    var set = {
      collection: "map",
      identify: (value) => value instanceof Set,
      nodeClass: YAMLSet,
      default: false,
      tag: "tag:yaml.org,2002:set",
      createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),
      resolve(map, onError) {
        if (identity.isMap(map)) {
          if (map.hasAllNullValues(true))
            return Object.assign(new YAMLSet(), map);
          else
            onError("Set items must all have null values");
        } else
          onError("Expected a mapping for this tag");
        return map;
      }
    };
    exports2.YAMLSet = YAMLSet;
    exports2.set = set;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js
var require_timestamp = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js"(exports2) {
    "use strict";
    var stringifyNumber = require_stringifyNumber();
    function parseSexagesimal(str, asBigInt) {
      const sign = str[0];
      const parts = sign === "-" || sign === "+" ? str.substring(1) : str;
      const num = (n) => asBigInt ? BigInt(n) : Number(n);
      const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num(60) + num(p), num(0));
      return sign === "-" ? num(-1) * res : res;
    }
    function stringifySexagesimal(node) {
      let { value } = node;
      let num = (n) => n;
      if (typeof value === "bigint")
        num = (n) => BigInt(n);
      else if (isNaN(value) || !isFinite(value))
        return stringifyNumber.stringifyNumber(node);
      let sign = "";
      if (value < 0) {
        sign = "-";
        value *= num(-1);
      }
      const _60 = num(60);
      const parts = [value % _60];
      if (value < 60) {
        parts.unshift(0);
      } else {
        value = (value - parts[0]) / _60;
        parts.unshift(value % _60);
        if (value >= 60) {
          value = (value - parts[0]) / _60;
          parts.unshift(value);
        }
      }
      return sign + parts.map((n) => String(n).padStart(2, "0")).join(":").replace(/000000\d*$/, "");
    }
    var intTime = {
      identify: (value) => typeof value === "bigint" || Number.isInteger(value),
      default: true,
      tag: "tag:yaml.org,2002:int",
      format: "TIME",
      test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
      resolve: (str, _onError, { intAsBigInt }) => parseSexagesimal(str, intAsBigInt),
      stringify: stringifySexagesimal
    };
    var floatTime = {
      identify: (value) => typeof value === "number",
      default: true,
      tag: "tag:yaml.org,2002:float",
      format: "TIME",
      test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
      resolve: (str) => parseSexagesimal(str, false),
      stringify: stringifySexagesimal
    };
    var timestamp = {
      identify: (value) => value instanceof Date,
      default: true,
      tag: "tag:yaml.org,2002:timestamp",
      // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
      // may be omitted altogether, resulting in a date format. In such a case, the time part is
      // assumed to be 00:00:00Z (start of day, UTC).
      test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
      resolve(str) {
        const match = str.match(timestamp.test);
        if (!match)
          throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
        const [, year, month, day, hour, minute, second] = match.map(Number);
        const millisec = match[7] ? Number((match[7] + "00").substr(1, 3)) : 0;
        let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec);
        const tz = match[8];
        if (tz && tz !== "Z") {
          let d = parseSexagesimal(tz, false);
          if (Math.abs(d) < 30)
            d *= 60;
          date -= 6e4 * d;
        }
        return new Date(date);
      },
      stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\.000Z$/, "") ?? ""
    };
    exports2.floatTime = floatTime;
    exports2.intTime = intTime;
    exports2.timestamp = timestamp;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/schema.js
var require_schema3 = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/schema.js"(exports2) {
    "use strict";
    var map = require_map();
    var _null = require_null();
    var seq = require_seq();
    var string = require_string();
    var binary = require_binary();
    var bool = require_bool2();
    var float = require_float2();
    var int = require_int2();
    var merge = require_merge();
    var omap = require_omap();
    var pairs = require_pairs();
    var set = require_set();
    var timestamp = require_timestamp();
    var schema = [
      map.map,
      seq.seq,
      string.string,
      _null.nullTag,
      bool.trueTag,
      bool.falseTag,
      int.intBin,
      int.intOct,
      int.int,
      int.intHex,
      float.floatNaN,
      float.floatExp,
      float.float,
      binary.binary,
      merge.merge,
      omap.omap,
      pairs.pairs,
      set.set,
      timestamp.intTime,
      timestamp.floatTime,
      timestamp.timestamp
    ];
    exports2.schema = schema;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/tags.js
var require_tags = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/tags.js"(exports2) {
    "use strict";
    var map = require_map();
    var _null = require_null();
    var seq = require_seq();
    var string = require_string();
    var bool = require_bool();
    var float = require_float();
    var int = require_int();
    var schema = require_schema();
    var schema$1 = require_schema2();
    var binary = require_binary();
    var merge = require_merge();
    var omap = require_omap();
    var pairs = require_pairs();
    var schema$2 = require_schema3();
    var set = require_set();
    var timestamp = require_timestamp();
    var schemas = /* @__PURE__ */ new Map([
      ["core", schema.schema],
      ["failsafe", [map.map, seq.seq, string.string]],
      ["json", schema$1.schema],
      ["yaml11", schema$2.schema],
      ["yaml-1.1", schema$2.schema]
    ]);
    var tagsByName = {
      binary: binary.binary,
      bool: bool.boolTag,
      float: float.float,
      floatExp: float.floatExp,
      floatNaN: float.floatNaN,
      floatTime: timestamp.floatTime,
      int: int.int,
      intHex: int.intHex,
      intOct: int.intOct,
      intTime: timestamp.intTime,
      map: map.map,
      merge: merge.merge,
      null: _null.nullTag,
      omap: omap.omap,
      pairs: pairs.pairs,
      seq: seq.seq,
      set: set.set,
      timestamp: timestamp.timestamp
    };
    var coreKnownTags = {
      "tag:yaml.org,2002:binary": binary.binary,
      "tag:yaml.org,2002:merge": merge.merge,
      "tag:yaml.org,2002:omap": omap.omap,
      "tag:yaml.org,2002:pairs": pairs.pairs,
      "tag:yaml.org,2002:set": set.set,
      "tag:yaml.org,2002:timestamp": timestamp.timestamp
    };
    function getTags(customTags, schemaName, addMergeTag) {
      const schemaTags = schemas.get(schemaName);
      if (schemaTags && !customTags) {
        return addMergeTag && !schemaTags.includes(merge.merge) ? schemaTags.concat(merge.merge) : schemaTags.slice();
      }
      let tags = schemaTags;
      if (!tags) {
        if (Array.isArray(customTags))
          tags = [];
        else {
          const keys = Array.from(schemas.keys()).filter((key) => key !== "yaml11").map((key) => JSON.stringify(key)).join(", ");
          throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
        }
      }
      if (Array.isArray(customTags)) {
        for (const tag of customTags)
          tags = tags.concat(tag);
      } else if (typeof customTags === "function") {
        tags = customTags(tags.slice());
      }
      if (addMergeTag)
        tags = tags.concat(merge.merge);
      return tags.reduce((tags2, tag) => {
        const tagObj = typeof tag === "string" ? tagsByName[tag] : tag;
        if (!tagObj) {
          const tagName = JSON.stringify(tag);
          const keys = Object.keys(tagsByName).map((key) => JSON.stringify(key)).join(", ");
          throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
        }
        if (!tags2.includes(tagObj))
          tags2.push(tagObj);
        return tags2;
      }, []);
    }
    exports2.coreKnownTags = coreKnownTags;
    exports2.getTags = getTags;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/Schema.js
var require_Schema = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/schema/Schema.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var map = require_map();
    var seq = require_seq();
    var string = require_string();
    var tags = require_tags();
    var sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
    var Schema = class _Schema {
      constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
        this.compat = Array.isArray(compat) ? tags.getTags(compat, "compat") : compat ? tags.getTags(null, compat) : null;
        this.name = typeof schema === "string" && schema || "core";
        this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
        this.tags = tags.getTags(customTags, this.name, merge);
        this.toStringOptions = toStringDefaults ?? null;
        Object.defineProperty(this, identity.MAP, { value: map.map });
        Object.defineProperty(this, identity.SCALAR, { value: string.string });
        Object.defineProperty(this, identity.SEQ, { value: seq.seq });
        this.sortMapEntries = typeof sortMapEntries === "function" ? sortMapEntries : sortMapEntries === true ? sortMapEntriesByKey : null;
      }
      clone() {
        const copy = Object.create(_Schema.prototype, Object.getOwnPropertyDescriptors(this));
        copy.tags = this.tags.slice();
        return copy;
      }
    };
    exports2.Schema = Schema;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyDocument.js
var require_stringifyDocument = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/stringify/stringifyDocument.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var stringify = require_stringify();
    var stringifyComment = require_stringifyComment();
    function stringifyDocument(doc, options) {
      const lines = [];
      let hasDirectives = options.directives === true;
      if (options.directives !== false && doc.directives) {
        const dir = doc.directives.toString(doc);
        if (dir) {
          lines.push(dir);
          hasDirectives = true;
        } else if (doc.directives.docStart)
          hasDirectives = true;
      }
      if (hasDirectives)
        lines.push("---");
      const ctx = stringify.createStringifyContext(doc, options);
      const { commentString } = ctx.options;
      if (doc.commentBefore) {
        if (lines.length !== 1)
          lines.unshift("");
        const cs = commentString(doc.commentBefore);
        lines.unshift(stringifyComment.indentComment(cs, ""));
      }
      let chompKeep = false;
      let contentComment = null;
      if (doc.contents) {
        if (identity.isNode(doc.contents)) {
          if (doc.contents.spaceBefore && hasDirectives)
            lines.push("");
          if (doc.contents.commentBefore) {
            const cs = commentString(doc.contents.commentBefore);
            lines.push(stringifyComment.indentComment(cs, ""));
          }
          ctx.forceBlockIndent = !!doc.comment;
          contentComment = doc.contents.comment;
        }
        const onChompKeep = contentComment ? void 0 : () => chompKeep = true;
        let body = stringify.stringify(doc.contents, ctx, () => contentComment = null, onChompKeep);
        if (contentComment)
          body += stringifyComment.lineComment(body, "", commentString(contentComment));
        if ((body[0] === "|" || body[0] === ">") && lines[lines.length - 1] === "---") {
          lines[lines.length - 1] = `--- ${body}`;
        } else
          lines.push(body);
      } else {
        lines.push(stringify.stringify(doc.contents, ctx));
      }
      if (doc.directives?.docEnd) {
        if (doc.comment) {
          const cs = commentString(doc.comment);
          if (cs.includes("\n")) {
            lines.push("...");
            lines.push(stringifyComment.indentComment(cs, ""));
          } else {
            lines.push(`... ${cs}`);
          }
        } else {
          lines.push("...");
        }
      } else {
        let dc = doc.comment;
        if (dc && chompKeep)
          dc = dc.replace(/^\n+/, "");
        if (dc) {
          if ((!chompKeep || contentComment) && lines[lines.length - 1] !== "")
            lines.push("");
          lines.push(stringifyComment.indentComment(commentString(dc), ""));
        }
      }
      return lines.join("\n") + "\n";
    }
    exports2.stringifyDocument = stringifyDocument;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/Document.js
var require_Document = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/doc/Document.js"(exports2) {
    "use strict";
    var Alias = require_Alias();
    var Collection = require_Collection();
    var identity = require_identity();
    var Pair = require_Pair();
    var toJS = require_toJS();
    var Schema = require_Schema();
    var stringifyDocument = require_stringifyDocument();
    var anchors = require_anchors();
    var applyReviver = require_applyReviver();
    var createNode = require_createNode();
    var directives = require_directives();
    var Document = class _Document {
      constructor(value, replacer, options) {
        this.commentBefore = null;
        this.comment = null;
        this.errors = [];
        this.warnings = [];
        Object.defineProperty(this, identity.NODE_TYPE, { value: identity.DOC });
        let _replacer = null;
        if (typeof replacer === "function" || Array.isArray(replacer)) {
          _replacer = replacer;
        } else if (options === void 0 && replacer) {
          options = replacer;
          replacer = void 0;
        }
        const opt = Object.assign({
          intAsBigInt: false,
          keepSourceTokens: false,
          logLevel: "warn",
          prettyErrors: true,
          strict: true,
          stringKeys: false,
          uniqueKeys: true,
          version: "1.2"
        }, options);
        this.options = opt;
        let { version } = opt;
        if (options?._directives) {
          this.directives = options._directives.atDocument();
          if (this.directives.yaml.explicit)
            version = this.directives.yaml.version;
        } else
          this.directives = new directives.Directives({ version });
        this.setSchema(version, options);
        this.contents = value === void 0 ? null : this.createNode(value, _replacer, options);
      }
      /**
       * Create a deep copy of this Document and its contents.
       *
       * Custom Node values that inherit from `Object` still refer to their original instances.
       */
      clone() {
        const copy = Object.create(_Document.prototype, {
          [identity.NODE_TYPE]: { value: identity.DOC }
        });
        copy.commentBefore = this.commentBefore;
        copy.comment = this.comment;
        copy.errors = this.errors.slice();
        copy.warnings = this.warnings.slice();
        copy.options = Object.assign({}, this.options);
        if (this.directives)
          copy.directives = this.directives.clone();
        copy.schema = this.schema.clone();
        copy.contents = identity.isNode(this.contents) ? this.contents.clone(copy.schema) : this.contents;
        if (this.range)
          copy.range = this.range.slice();
        return copy;
      }
      /** Adds a value to the document. */
      add(value) {
        if (assertCollection(this.contents))
          this.contents.add(value);
      }
      /** Adds a value to the document. */
      addIn(path, value) {
        if (assertCollection(this.contents))
          this.contents.addIn(path, value);
      }
      /**
       * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
       *
       * If `node` already has an anchor, `name` is ignored.
       * Otherwise, the `node.anchor` value will be set to `name`,
       * or if an anchor with that name is already present in the document,
       * `name` will be used as a prefix for a new unique anchor.
       * If `name` is undefined, the generated anchor will use 'a' as a prefix.
       */
      createAlias(node, name) {
        if (!node.anchor) {
          const prev = anchors.anchorNames(this);
          node.anchor = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
          !name || prev.has(name) ? anchors.findNewAnchor(name || "a", prev) : name;
        }
        return new Alias.Alias(node.anchor);
      }
      createNode(value, replacer, options) {
        let _replacer = void 0;
        if (typeof replacer === "function") {
          value = replacer.call({ "": value }, "", value);
          _replacer = replacer;
        } else if (Array.isArray(replacer)) {
          const keyToStr = (v) => typeof v === "number" || v instanceof String || v instanceof Number;
          const asStr = replacer.filter(keyToStr).map(String);
          if (asStr.length > 0)
            replacer = replacer.concat(asStr);
          _replacer = replacer;
        } else if (options === void 0 && replacer) {
          options = replacer;
          replacer = void 0;
        }
        const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options ?? {};
        const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(
          this,
          // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
          anchorPrefix || "a"
        );
        const ctx = {
          aliasDuplicateObjects: aliasDuplicateObjects ?? true,
          keepUndefined: keepUndefined ?? false,
          onAnchor,
          onTagObj,
          replacer: _replacer,
          schema: this.schema,
          sourceObjects
        };
        const node = createNode.createNode(value, tag, ctx);
        if (flow && identity.isCollection(node))
          node.flow = true;
        setAnchors();
        return node;
      }
      /**
       * Convert a key and a value into a `Pair` using the current schema,
       * recursively wrapping all values as `Scalar` or `Collection` nodes.
       */
      createPair(key, value, options = {}) {
        const k = this.createNode(key, null, options);
        const v = this.createNode(value, null, options);
        return new Pair.Pair(k, v);
      }
      /**
       * Removes a value from the document.
       * @returns `true` if the item was found and removed.
       */
      delete(key) {
        return assertCollection(this.contents) ? this.contents.delete(key) : false;
      }
      /**
       * Removes a value from the document.
       * @returns `true` if the item was found and removed.
       */
      deleteIn(path) {
        if (Collection.isEmptyPath(path)) {
          if (this.contents == null)
            return false;
          this.contents = null;
          return true;
        }
        return assertCollection(this.contents) ? this.contents.deleteIn(path) : false;
      }
      /**
       * Returns item at `key`, or `undefined` if not found. By default unwraps
       * scalar values from their surrounding node; to disable set `keepScalar` to
       * `true` (collections are always returned intact).
       */
      get(key, keepScalar) {
        return identity.isCollection(this.contents) ? this.contents.get(key, keepScalar) : void 0;
      }
      /**
       * Returns item at `path`, or `undefined` if not found. By default unwraps
       * scalar values from their surrounding node; to disable set `keepScalar` to
       * `true` (collections are always returned intact).
       */
      getIn(path, keepScalar) {
        if (Collection.isEmptyPath(path))
          return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
        return identity.isCollection(this.contents) ? this.contents.getIn(path, keepScalar) : void 0;
      }
      /**
       * Checks if the document includes a value with the key `key`.
       */
      has(key) {
        return identity.isCollection(this.contents) ? this.contents.has(key) : false;
      }
      /**
       * Checks if the document includes a value at `path`.
       */
      hasIn(path) {
        if (Collection.isEmptyPath(path))
          return this.contents !== void 0;
        return identity.isCollection(this.contents) ? this.contents.hasIn(path) : false;
      }
      /**
       * Sets a value in this document. For `!!set`, `value` needs to be a
       * boolean to add/remove the item from the set.
       */
      set(key, value) {
        if (this.contents == null) {
          this.contents = Collection.collectionFromPath(this.schema, [key], value);
        } else if (assertCollection(this.contents)) {
          this.contents.set(key, value);
        }
      }
      /**
       * Sets a value in this document. For `!!set`, `value` needs to be a
       * boolean to add/remove the item from the set.
       */
      setIn(path, value) {
        if (Collection.isEmptyPath(path)) {
          this.contents = value;
        } else if (this.contents == null) {
          this.contents = Collection.collectionFromPath(this.schema, Array.from(path), value);
        } else if (assertCollection(this.contents)) {
          this.contents.setIn(path, value);
        }
      }
      /**
       * Change the YAML version and schema used by the document.
       * A `null` version disables support for directives, explicit tags, anchors, and aliases.
       * It also requires the `schema` option to be given as a `Schema` instance value.
       *
       * Overrides all previously set schema options.
       */
      setSchema(version, options = {}) {
        if (typeof version === "number")
          version = String(version);
        let opt;
        switch (version) {
          case "1.1":
            if (this.directives)
              this.directives.yaml.version = "1.1";
            else
              this.directives = new directives.Directives({ version: "1.1" });
            opt = { resolveKnownTags: false, schema: "yaml-1.1" };
            break;
          case "1.2":
          case "next":
            if (this.directives)
              this.directives.yaml.version = version;
            else
              this.directives = new directives.Directives({ version });
            opt = { resolveKnownTags: true, schema: "core" };
            break;
          case null:
            if (this.directives)
              delete this.directives;
            opt = null;
            break;
          default: {
            const sv = JSON.stringify(version);
            throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${sv}`);
          }
        }
        if (options.schema instanceof Object)
          this.schema = options.schema;
        else if (opt)
          this.schema = new Schema.Schema(Object.assign(opt, options));
        else
          throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
      }
      // json & jsonArg are only used from toJSON()
      toJS({ json, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
        const ctx = {
          anchors: /* @__PURE__ */ new Map(),
          doc: this,
          keep: !json,
          mapAsMap: mapAsMap === true,
          mapKeyWarned: false,
          maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
        };
        const res = toJS.toJS(this.contents, jsonArg ?? "", ctx);
        if (typeof onAnchor === "function")
          for (const { count, res: res2 } of ctx.anchors.values())
            onAnchor(res2, count);
        return typeof reviver === "function" ? applyReviver.applyReviver(reviver, { "": res }, "", res) : res;
      }
      /**
       * A JSON representation of the document `contents`.
       *
       * @param jsonArg Used by `JSON.stringify` to indicate the array index or
       *   property name.
       */
      toJSON(jsonArg, onAnchor) {
        return this.toJS({ json: true, jsonArg, mapAsMap: false, onAnchor });
      }
      /** A YAML representation of the document. */
      toString(options = {}) {
        if (this.errors.length > 0)
          throw new Error("Document with errors cannot be stringified");
        if ("indent" in options && (!Number.isInteger(options.indent) || Number(options.indent) <= 0)) {
          const s = JSON.stringify(options.indent);
          throw new Error(`"indent" option must be a positive integer, not ${s}`);
        }
        return stringifyDocument.stringifyDocument(this, options);
      }
    };
    function assertCollection(contents) {
      if (identity.isCollection(contents))
        return true;
      throw new Error("Expected a YAML collection as document contents");
    }
    exports2.Document = Document;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/errors.js
var require_errors = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/errors.js"(exports2) {
    "use strict";
    var YAMLError = class extends Error {
      constructor(name, pos, code, message) {
        super();
        this.name = name;
        this.code = code;
        this.message = message;
        this.pos = pos;
      }
    };
    var YAMLParseError = class extends YAMLError {
      constructor(pos, code, message) {
        super("YAMLParseError", pos, code, message);
      }
    };
    var YAMLWarning = class extends YAMLError {
      constructor(pos, code, message) {
        super("YAMLWarning", pos, code, message);
      }
    };
    var prettifyError = (src, lc) => (error) => {
      if (error.pos[0] === -1)
        return;
      error.linePos = error.pos.map((pos) => lc.linePos(pos));
      const { line, col } = error.linePos[0];
      error.message += ` at line ${line}, column ${col}`;
      let ci = col - 1;
      let lineStr = src.substring(lc.lineStarts[line - 1], lc.lineStarts[line]).replace(/[\n\r]+$/, "");
      if (ci >= 60 && lineStr.length > 80) {
        const trimStart = Math.min(ci - 39, lineStr.length - 79);
        lineStr = "\u2026" + lineStr.substring(trimStart);
        ci -= trimStart - 1;
      }
      if (lineStr.length > 80)
        lineStr = lineStr.substring(0, 79) + "\u2026";
      if (line > 1 && /^ *$/.test(lineStr.substring(0, ci))) {
        let prev = src.substring(lc.lineStarts[line - 2], lc.lineStarts[line - 1]);
        if (prev.length > 80)
          prev = prev.substring(0, 79) + "\u2026\n";
        lineStr = prev + lineStr;
      }
      if (/[^ ]/.test(lineStr)) {
        let count = 1;
        const end = error.linePos[1];
        if (end?.line === line && end.col > col) {
          count = Math.max(1, Math.min(end.col - col, 80 - ci));
        }
        const pointer = " ".repeat(ci) + "^".repeat(count);
        error.message += `:

${lineStr}
${pointer}
`;
      }
    };
    exports2.YAMLError = YAMLError;
    exports2.YAMLParseError = YAMLParseError;
    exports2.YAMLWarning = YAMLWarning;
    exports2.prettifyError = prettifyError;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-props.js
var require_resolve_props = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-props.js"(exports2) {
    "use strict";
    function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIndent, startOnNewline }) {
      let spaceBefore = false;
      let atNewline = startOnNewline;
      let hasSpace = startOnNewline;
      let comment = "";
      let commentSep = "";
      let hasNewline = false;
      let reqSpace = false;
      let tab = null;
      let anchor = null;
      let tag = null;
      let newlineAfterProp = null;
      let comma = null;
      let found = null;
      let start = null;
      for (const token of tokens) {
        if (reqSpace) {
          if (token.type !== "space" && token.type !== "newline" && token.type !== "comma")
            onError(token.offset, "MISSING_CHAR", "Tags and anchors must be separated from the next token by white space");
          reqSpace = false;
        }
        if (tab) {
          if (atNewline && token.type !== "comment" && token.type !== "newline") {
            onError(tab, "TAB_AS_INDENT", "Tabs are not allowed as indentation");
          }
          tab = null;
        }
        switch (token.type) {
          case "space":
            if (!flow && (indicator !== "doc-start" || next?.type !== "flow-collection") && token.source.includes("	")) {
              tab = token;
            }
            hasSpace = true;
            break;
          case "comment": {
            if (!hasSpace)
              onError(token, "MISSING_CHAR", "Comments must be separated from other tokens by white space characters");
            const cb = token.source.substring(1) || " ";
            if (!comment)
              comment = cb;
            else
              comment += commentSep + cb;
            commentSep = "";
            atNewline = false;
            break;
          }
          case "newline":
            if (atNewline) {
              if (comment)
                comment += token.source;
              else if (!found || indicator !== "seq-item-ind")
                spaceBefore = true;
            } else
              commentSep += token.source;
            atNewline = true;
            hasNewline = true;
            if (anchor || tag)
              newlineAfterProp = token;
            hasSpace = true;
            break;
          case "anchor":
            if (anchor)
              onError(token, "MULTIPLE_ANCHORS", "A node can have at most one anchor");
            if (token.source.endsWith(":"))
              onError(token.offset + token.source.length - 1, "BAD_ALIAS", "Anchor ending in : is ambiguous", true);
            anchor = token;
            start ?? (start = token.offset);
            atNewline = false;
            hasSpace = false;
            reqSpace = true;
            break;
          case "tag": {
            if (tag)
              onError(token, "MULTIPLE_TAGS", "A node can have at most one tag");
            tag = token;
            start ?? (start = token.offset);
            atNewline = false;
            hasSpace = false;
            reqSpace = true;
            break;
          }
          case indicator:
            if (anchor || tag)
              onError(token, "BAD_PROP_ORDER", `Anchors and tags must be after the ${token.source} indicator`);
            if (found)
              onError(token, "UNEXPECTED_TOKEN", `Unexpected ${token.source} in ${flow ?? "collection"}`);
            found = token;
            atNewline = indicator === "seq-item-ind" || indicator === "explicit-key-ind";
            hasSpace = false;
            break;
          case "comma":
            if (flow) {
              if (comma)
                onError(token, "UNEXPECTED_TOKEN", `Unexpected , in ${flow}`);
              comma = token;
              atNewline = false;
              hasSpace = false;
              break;
            }
          // else fallthrough
          default:
            onError(token, "UNEXPECTED_TOKEN", `Unexpected ${token.type} token`);
            atNewline = false;
            hasSpace = false;
        }
      }
      const last = tokens[tokens.length - 1];
      const end = last ? last.offset + last.source.length : offset;
      if (reqSpace && next && next.type !== "space" && next.type !== "newline" && next.type !== "comma" && (next.type !== "scalar" || next.source !== "")) {
        onError(next.offset, "MISSING_CHAR", "Tags and anchors must be separated from the next token by white space");
      }
      if (tab && (atNewline && tab.indent <= parentIndent || next?.type === "block-map" || next?.type === "block-seq"))
        onError(tab, "TAB_AS_INDENT", "Tabs are not allowed as indentation");
      return {
        comma,
        found,
        spaceBefore,
        comment,
        hasNewline,
        anchor,
        tag,
        newlineAfterProp,
        end,
        start: start ?? end
      };
    }
    exports2.resolveProps = resolveProps;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-contains-newline.js
var require_util_contains_newline = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-contains-newline.js"(exports2) {
    "use strict";
    function containsNewline(key) {
      if (!key)
        return null;
      switch (key.type) {
        case "alias":
        case "scalar":
        case "double-quoted-scalar":
        case "single-quoted-scalar":
          if (key.source.includes("\n"))
            return true;
          if (key.end) {
            for (const st of key.end)
              if (st.type === "newline")
                return true;
          }
          return false;
        case "flow-collection":
          for (const it of key.items) {
            for (const st of it.start)
              if (st.type === "newline")
                return true;
            if (it.sep) {
              for (const st of it.sep)
                if (st.type === "newline")
                  return true;
            }
            if (containsNewline(it.key) || containsNewline(it.value))
              return true;
          }
          return false;
        default:
          return true;
      }
    }
    exports2.containsNewline = containsNewline;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-flow-indent-check.js
var require_util_flow_indent_check = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-flow-indent-check.js"(exports2) {
    "use strict";
    var utilContainsNewline = require_util_contains_newline();
    function flowIndentCheck(indent, fc, onError) {
      if (fc?.type === "flow-collection") {
        const end = fc.end[0];
        if (end.indent === indent && (end.source === "]" || end.source === "}") && utilContainsNewline.containsNewline(fc)) {
          const msg = "Flow end indicator should be more indented than parent";
          onError(end, "BAD_INDENT", msg, true);
        }
      }
    }
    exports2.flowIndentCheck = flowIndentCheck;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-map-includes.js
var require_util_map_includes = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-map-includes.js"(exports2) {
    "use strict";
    var identity = require_identity();
    function mapIncludes(ctx, items, search) {
      const { uniqueKeys } = ctx.options;
      if (uniqueKeys === false)
        return false;
      const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value;
      return items.some((pair) => isEqual(pair.key, search));
    }
    exports2.mapIncludes = mapIncludes;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-block-map.js
var require_resolve_block_map = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-block-map.js"(exports2) {
    "use strict";
    var Pair = require_Pair();
    var YAMLMap = require_YAMLMap();
    var resolveProps = require_resolve_props();
    var utilContainsNewline = require_util_contains_newline();
    var utilFlowIndentCheck = require_util_flow_indent_check();
    var utilMapIncludes = require_util_map_includes();
    var startColMsg = "All mapping items must start at the same column";
    function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, tag) {
      const NodeClass = tag?.nodeClass ?? YAMLMap.YAMLMap;
      const map = new NodeClass(ctx.schema);
      if (ctx.atRoot)
        ctx.atRoot = false;
      let offset = bm.offset;
      let commentEnd = null;
      for (const collItem of bm.items) {
        const { start, key, sep: sep5, value } = collItem;
        const keyProps = resolveProps.resolveProps(start, {
          indicator: "explicit-key-ind",
          next: key ?? sep5?.[0],
          offset,
          onError,
          parentIndent: bm.indent,
          startOnNewline: true
        });
        const implicitKey = !keyProps.found;
        if (implicitKey) {
          if (key) {
            if (key.type === "block-seq")
              onError(offset, "BLOCK_AS_IMPLICIT_KEY", "A block sequence may not be used as an implicit map key");
            else if ("indent" in key && key.indent !== bm.indent)
              onError(offset, "BAD_INDENT", startColMsg);
          }
          if (!keyProps.anchor && !keyProps.tag && !sep5) {
            commentEnd = keyProps.end;
            if (keyProps.comment) {
              if (map.comment)
                map.comment += "\n" + keyProps.comment;
              else
                map.comment = keyProps.comment;
            }
            continue;
          }
          if (keyProps.newlineAfterProp || utilContainsNewline.containsNewline(key)) {
            onError(key ?? start[start.length - 1], "MULTILINE_IMPLICIT_KEY", "Implicit keys need to be on a single line");
          }
        } else if (keyProps.found?.indent !== bm.indent) {
          onError(offset, "BAD_INDENT", startColMsg);
        }
        ctx.atKey = true;
        const keyStart = keyProps.end;
        const keyNode = key ? composeNode(ctx, key, keyProps, onError) : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
        if (ctx.schema.compat)
          utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
        ctx.atKey = false;
        if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
          onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
        const valueProps = resolveProps.resolveProps(sep5 ?? [], {
          indicator: "map-value-ind",
          next: value,
          offset: keyNode.range[2],
          onError,
          parentIndent: bm.indent,
          startOnNewline: !key || key.type === "block-scalar"
        });
        offset = valueProps.end;
        if (valueProps.found) {
          if (implicitKey) {
            if (value?.type === "block-map" && !valueProps.hasNewline)
              onError(offset, "BLOCK_AS_IMPLICIT_KEY", "Nested mappings are not allowed in compact mappings");
            if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
              onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
          }
          const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep5, null, valueProps, onError);
          if (ctx.schema.compat)
            utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
          offset = valueNode.range[2];
          const pair = new Pair.Pair(keyNode, valueNode);
          if (ctx.options.keepSourceTokens)
            pair.srcToken = collItem;
          map.items.push(pair);
        } else {
          if (implicitKey)
            onError(keyNode.range, "MISSING_CHAR", "Implicit map keys need to be followed by map values");
          if (valueProps.comment) {
            if (keyNode.comment)
              keyNode.comment += "\n" + valueProps.comment;
            else
              keyNode.comment = valueProps.comment;
          }
          const pair = new Pair.Pair(keyNode);
          if (ctx.options.keepSourceTokens)
            pair.srcToken = collItem;
          map.items.push(pair);
        }
      }
      if (commentEnd && commentEnd < offset)
        onError(commentEnd, "IMPOSSIBLE", "Map comment with trailing content");
      map.range = [bm.offset, offset, commentEnd ?? offset];
      return map;
    }
    exports2.resolveBlockMap = resolveBlockMap;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-block-seq.js
var require_resolve_block_seq = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-block-seq.js"(exports2) {
    "use strict";
    var YAMLSeq = require_YAMLSeq();
    var resolveProps = require_resolve_props();
    var utilFlowIndentCheck = require_util_flow_indent_check();
    function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, tag) {
      const NodeClass = tag?.nodeClass ?? YAMLSeq.YAMLSeq;
      const seq = new NodeClass(ctx.schema);
      if (ctx.atRoot)
        ctx.atRoot = false;
      if (ctx.atKey)
        ctx.atKey = false;
      let offset = bs.offset;
      let commentEnd = null;
      for (const { start, value } of bs.items) {
        const props = resolveProps.resolveProps(start, {
          indicator: "seq-item-ind",
          next: value,
          offset,
          onError,
          parentIndent: bs.indent,
          startOnNewline: true
        });
        if (!props.found) {
          if (props.anchor || props.tag || value) {
            if (value?.type === "block-seq")
              onError(props.end, "BAD_INDENT", "All sequence items must start at the same column");
            else
              onError(offset, "MISSING_CHAR", "Sequence item without - indicator");
          } else {
            commentEnd = props.end;
            if (props.comment)
              seq.comment = props.comment;
            continue;
          }
        }
        const node = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, start, null, props, onError);
        if (ctx.schema.compat)
          utilFlowIndentCheck.flowIndentCheck(bs.indent, value, onError);
        offset = node.range[2];
        seq.items.push(node);
      }
      seq.range = [bs.offset, offset, commentEnd ?? offset];
      return seq;
    }
    exports2.resolveBlockSeq = resolveBlockSeq;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-end.js
var require_resolve_end = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-end.js"(exports2) {
    "use strict";
    function resolveEnd(end, offset, reqSpace, onError) {
      let comment = "";
      if (end) {
        let hasSpace = false;
        let sep5 = "";
        for (const token of end) {
          const { source, type } = token;
          switch (type) {
            case "space":
              hasSpace = true;
              break;
            case "comment": {
              if (reqSpace && !hasSpace)
                onError(token, "MISSING_CHAR", "Comments must be separated from other tokens by white space characters");
              const cb = source.substring(1) || " ";
              if (!comment)
                comment = cb;
              else
                comment += sep5 + cb;
              sep5 = "";
              break;
            }
            case "newline":
              if (comment)
                sep5 += source;
              hasSpace = true;
              break;
            default:
              onError(token, "UNEXPECTED_TOKEN", `Unexpected ${type} at node end`);
          }
          offset += source.length;
        }
      }
      return { comment, offset };
    }
    exports2.resolveEnd = resolveEnd;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-flow-collection.js
var require_resolve_flow_collection = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-flow-collection.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Pair = require_Pair();
    var YAMLMap = require_YAMLMap();
    var YAMLSeq = require_YAMLSeq();
    var resolveEnd = require_resolve_end();
    var resolveProps = require_resolve_props();
    var utilContainsNewline = require_util_contains_newline();
    var utilMapIncludes = require_util_map_includes();
    var blockMsg = "Block collections are not allowed within flow collections";
    var isBlock = (token) => token && (token.type === "block-map" || token.type === "block-seq");
    function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError, tag) {
      const isMap = fc.start.source === "{";
      const fcName = isMap ? "flow map" : "flow sequence";
      const NodeClass = tag?.nodeClass ?? (isMap ? YAMLMap.YAMLMap : YAMLSeq.YAMLSeq);
      const coll = new NodeClass(ctx.schema);
      coll.flow = true;
      const atRoot = ctx.atRoot;
      if (atRoot)
        ctx.atRoot = false;
      if (ctx.atKey)
        ctx.atKey = false;
      let offset = fc.offset + fc.start.source.length;
      for (let i = 0; i < fc.items.length; ++i) {
        const collItem = fc.items[i];
        const { start, key, sep: sep5, value } = collItem;
        const props = resolveProps.resolveProps(start, {
          flow: fcName,
          indicator: "explicit-key-ind",
          next: key ?? sep5?.[0],
          offset,
          onError,
          parentIndent: fc.indent,
          startOnNewline: false
        });
        if (!props.found) {
          if (!props.anchor && !props.tag && !sep5 && !value) {
            if (i === 0 && props.comma)
              onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
            else if (i < fc.items.length - 1)
              onError(props.start, "UNEXPECTED_TOKEN", `Unexpected empty item in ${fcName}`);
            if (props.comment) {
              if (coll.comment)
                coll.comment += "\n" + props.comment;
              else
                coll.comment = props.comment;
            }
            offset = props.end;
            continue;
          }
          if (!isMap && ctx.options.strict && utilContainsNewline.containsNewline(key))
            onError(
              key,
              // checked by containsNewline()
              "MULTILINE_IMPLICIT_KEY",
              "Implicit keys of flow sequence pairs need to be on a single line"
            );
        }
        if (i === 0) {
          if (props.comma)
            onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
        } else {
          if (!props.comma)
            onError(props.start, "MISSING_CHAR", `Missing , between ${fcName} items`);
          if (props.comment) {
            let prevItemComment = "";
            loop: for (const st of start) {
              switch (st.type) {
                case "comma":
                case "space":
                  break;
                case "comment":
                  prevItemComment = st.source.substring(1);
                  break loop;
                default:
                  break loop;
              }
            }
            if (prevItemComment) {
              let prev = coll.items[coll.items.length - 1];
              if (identity.isPair(prev))
                prev = prev.value ?? prev.key;
              if (prev.comment)
                prev.comment += "\n" + prevItemComment;
              else
                prev.comment = prevItemComment;
              props.comment = props.comment.substring(prevItemComment.length + 1);
            }
          }
        }
        if (!isMap && !sep5 && !props.found) {
          const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep5, null, props, onError);
          coll.items.push(valueNode);
          offset = valueNode.range[2];
          if (isBlock(value))
            onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
        } else {
          ctx.atKey = true;
          const keyStart = props.end;
          const keyNode = key ? composeNode(ctx, key, props, onError) : composeEmptyNode(ctx, keyStart, start, null, props, onError);
          if (isBlock(key))
            onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
          ctx.atKey = false;
          const valueProps = resolveProps.resolveProps(sep5 ?? [], {
            flow: fcName,
            indicator: "map-value-ind",
            next: value,
            offset: keyNode.range[2],
            onError,
            parentIndent: fc.indent,
            startOnNewline: false
          });
          if (valueProps.found) {
            if (!isMap && !props.found && ctx.options.strict) {
              if (sep5)
                for (const st of sep5) {
                  if (st === valueProps.found)
                    break;
                  if (st.type === "newline") {
                    onError(st, "MULTILINE_IMPLICIT_KEY", "Implicit keys of flow sequence pairs need to be on a single line");
                    break;
                  }
                }
              if (props.start < valueProps.found.offset - 1024)
                onError(valueProps.found, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit flow sequence key");
            }
          } else if (value) {
            if ("source" in value && value.source?.[0] === ":")
              onError(value, "MISSING_CHAR", `Missing space after : in ${fcName}`);
            else
              onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
          }
          const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep5, null, valueProps, onError) : null;
          if (valueNode) {
            if (isBlock(value))
              onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
          } else if (valueProps.comment) {
            if (keyNode.comment)
              keyNode.comment += "\n" + valueProps.comment;
            else
              keyNode.comment = valueProps.comment;
          }
          const pair = new Pair.Pair(keyNode, valueNode);
          if (ctx.options.keepSourceTokens)
            pair.srcToken = collItem;
          if (isMap) {
            const map = coll;
            if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
              onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
            map.items.push(pair);
          } else {
            const map = new YAMLMap.YAMLMap(ctx.schema);
            map.flow = true;
            map.items.push(pair);
            const endRange = (valueNode ?? keyNode).range;
            map.range = [keyNode.range[0], endRange[1], endRange[2]];
            coll.items.push(map);
          }
          offset = valueNode ? valueNode.range[2] : valueProps.end;
        }
      }
      const expectedEnd = isMap ? "}" : "]";
      const [ce, ...ee] = fc.end;
      let cePos = offset;
      if (ce?.source === expectedEnd)
        cePos = ce.offset + ce.source.length;
      else {
        const name = fcName[0].toUpperCase() + fcName.substring(1);
        const msg = atRoot ? `${name} must end with a ${expectedEnd}` : `${name} in block collection must be sufficiently indented and end with a ${expectedEnd}`;
        onError(offset, atRoot ? "MISSING_CHAR" : "BAD_INDENT", msg);
        if (ce && ce.source.length !== 1)
          ee.unshift(ce);
      }
      if (ee.length > 0) {
        const end = resolveEnd.resolveEnd(ee, cePos, ctx.options.strict, onError);
        if (end.comment) {
          if (coll.comment)
            coll.comment += "\n" + end.comment;
          else
            coll.comment = end.comment;
        }
        coll.range = [fc.offset, cePos, end.offset];
      } else {
        coll.range = [fc.offset, cePos, cePos];
      }
      return coll;
    }
    exports2.resolveFlowCollection = resolveFlowCollection;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-collection.js
var require_compose_collection = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-collection.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Scalar = require_Scalar();
    var YAMLMap = require_YAMLMap();
    var YAMLSeq = require_YAMLSeq();
    var resolveBlockMap = require_resolve_block_map();
    var resolveBlockSeq = require_resolve_block_seq();
    var resolveFlowCollection = require_resolve_flow_collection();
    function resolveCollection(CN, ctx, token, onError, tagName, tag) {
      const coll = token.type === "block-map" ? resolveBlockMap.resolveBlockMap(CN, ctx, token, onError, tag) : token.type === "block-seq" ? resolveBlockSeq.resolveBlockSeq(CN, ctx, token, onError, tag) : resolveFlowCollection.resolveFlowCollection(CN, ctx, token, onError, tag);
      const Coll = coll.constructor;
      if (tagName === "!" || tagName === Coll.tagName) {
        coll.tag = Coll.tagName;
        return coll;
      }
      if (tagName)
        coll.tag = tagName;
      return coll;
    }
    function composeCollection(CN, ctx, token, props, onError) {
      const tagToken = props.tag;
      const tagName = !tagToken ? null : ctx.directives.tagName(tagToken.source, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg));
      if (token.type === "block-seq") {
        const { anchor, newlineAfterProp: nl } = props;
        const lastProp = anchor && tagToken ? anchor.offset > tagToken.offset ? anchor : tagToken : anchor ?? tagToken;
        if (lastProp && (!nl || nl.offset < lastProp.offset)) {
          const message = "Missing newline after block sequence props";
          onError(lastProp, "MISSING_CHAR", message);
        }
      }
      const expType = token.type === "block-map" ? "map" : token.type === "block-seq" ? "seq" : token.start.source === "{" ? "map" : "seq";
      if (!tagToken || !tagName || tagName === "!" || tagName === YAMLMap.YAMLMap.tagName && expType === "map" || tagName === YAMLSeq.YAMLSeq.tagName && expType === "seq") {
        return resolveCollection(CN, ctx, token, onError, tagName);
      }
      let tag = ctx.schema.tags.find((t) => t.tag === tagName && t.collection === expType);
      if (!tag) {
        const kt = ctx.schema.knownTags[tagName];
        if (kt?.collection === expType) {
          ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
          tag = kt;
        } else {
          if (kt) {
            onError(tagToken, "BAD_COLLECTION_TYPE", `${kt.tag} used for ${expType} collection, but expects ${kt.collection ?? "scalar"}`, true);
          } else {
            onError(tagToken, "TAG_RESOLVE_FAILED", `Unresolved tag: ${tagName}`, true);
          }
          return resolveCollection(CN, ctx, token, onError, tagName);
        }
      }
      const coll = resolveCollection(CN, ctx, token, onError, tagName, tag);
      const res = tag.resolve?.(coll, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg), ctx.options) ?? coll;
      const node = identity.isNode(res) ? res : new Scalar.Scalar(res);
      node.range = coll.range;
      node.tag = tagName;
      if (tag?.format)
        node.format = tag.format;
      return node;
    }
    exports2.composeCollection = composeCollection;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-block-scalar.js
var require_resolve_block_scalar = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-block-scalar.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    function resolveBlockScalar(ctx, scalar, onError) {
      const start = scalar.offset;
      const header = parseBlockScalarHeader(scalar, ctx.options.strict, onError);
      if (!header)
        return { value: "", type: null, comment: "", range: [start, start, start] };
      const type = header.mode === ">" ? Scalar.Scalar.BLOCK_FOLDED : Scalar.Scalar.BLOCK_LITERAL;
      const lines = scalar.source ? splitLines(scalar.source) : [];
      let chompStart = lines.length;
      for (let i = lines.length - 1; i >= 0; --i) {
        const content = lines[i][1];
        if (content === "" || content === "\r")
          chompStart = i;
        else
          break;
      }
      if (chompStart === 0) {
        const value2 = header.chomp === "+" && lines.length > 0 ? "\n".repeat(Math.max(1, lines.length - 1)) : "";
        let end2 = start + header.length;
        if (scalar.source)
          end2 += scalar.source.length;
        return { value: value2, type, comment: header.comment, range: [start, end2, end2] };
      }
      let trimIndent = scalar.indent + header.indent;
      let offset = scalar.offset + header.length;
      let contentStart = 0;
      for (let i = 0; i < chompStart; ++i) {
        const [indent, content] = lines[i];
        if (content === "" || content === "\r") {
          if (header.indent === 0 && indent.length > trimIndent)
            trimIndent = indent.length;
        } else {
          if (indent.length < trimIndent) {
            const message = "Block scalars with more-indented leading empty lines must use an explicit indentation indicator";
            onError(offset + indent.length, "MISSING_CHAR", message);
          }
          if (header.indent === 0)
            trimIndent = indent.length;
          contentStart = i;
          if (trimIndent === 0 && !ctx.atRoot) {
            const message = "Block scalar values in collections must be indented";
            onError(offset, "BAD_INDENT", message);
          }
          break;
        }
        offset += indent.length + content.length + 1;
      }
      for (let i = lines.length - 1; i >= chompStart; --i) {
        if (lines[i][0].length > trimIndent)
          chompStart = i + 1;
      }
      let value = "";
      let sep5 = "";
      let prevMoreIndented = false;
      for (let i = 0; i < contentStart; ++i)
        value += lines[i][0].slice(trimIndent) + "\n";
      for (let i = contentStart; i < chompStart; ++i) {
        let [indent, content] = lines[i];
        offset += indent.length + content.length + 1;
        const crlf = content[content.length - 1] === "\r";
        if (crlf)
          content = content.slice(0, -1);
        if (content && indent.length < trimIndent) {
          const src = header.indent ? "explicit indentation indicator" : "first line";
          const message = `Block scalar lines must not be less indented than their ${src}`;
          onError(offset - content.length - (crlf ? 2 : 1), "BAD_INDENT", message);
          indent = "";
        }
        if (type === Scalar.Scalar.BLOCK_LITERAL) {
          value += sep5 + indent.slice(trimIndent) + content;
          sep5 = "\n";
        } else if (indent.length > trimIndent || content[0] === "	") {
          if (sep5 === " ")
            sep5 = "\n";
          else if (!prevMoreIndented && sep5 === "\n")
            sep5 = "\n\n";
          value += sep5 + indent.slice(trimIndent) + content;
          sep5 = "\n";
          prevMoreIndented = true;
        } else if (content === "") {
          if (sep5 === "\n")
            value += "\n";
          else
            sep5 = "\n";
        } else {
          value += sep5 + content;
          sep5 = " ";
          prevMoreIndented = false;
        }
      }
      switch (header.chomp) {
        case "-":
          break;
        case "+":
          for (let i = chompStart; i < lines.length; ++i)
            value += "\n" + lines[i][0].slice(trimIndent);
          if (value[value.length - 1] !== "\n")
            value += "\n";
          break;
        default:
          value += "\n";
      }
      const end = start + header.length + scalar.source.length;
      return { value, type, comment: header.comment, range: [start, end, end] };
    }
    function parseBlockScalarHeader({ offset, props }, strict, onError) {
      if (props[0].type !== "block-scalar-header") {
        onError(props[0], "IMPOSSIBLE", "Block scalar header not found");
        return null;
      }
      const { source } = props[0];
      const mode = source[0];
      let indent = 0;
      let chomp = "";
      let error = -1;
      for (let i = 1; i < source.length; ++i) {
        const ch = source[i];
        if (!chomp && (ch === "-" || ch === "+"))
          chomp = ch;
        else {
          const n = Number(ch);
          if (!indent && n)
            indent = n;
          else if (error === -1)
            error = offset + i;
        }
      }
      if (error !== -1)
        onError(error, "UNEXPECTED_TOKEN", `Block scalar header includes extra characters: ${source}`);
      let hasSpace = false;
      let comment = "";
      let length = source.length;
      for (let i = 1; i < props.length; ++i) {
        const token = props[i];
        switch (token.type) {
          case "space":
            hasSpace = true;
          // fallthrough
          case "newline":
            length += token.source.length;
            break;
          case "comment":
            if (strict && !hasSpace) {
              const message = "Comments must be separated from other tokens by white space characters";
              onError(token, "MISSING_CHAR", message);
            }
            length += token.source.length;
            comment = token.source.substring(1);
            break;
          case "error":
            onError(token, "UNEXPECTED_TOKEN", token.message);
            length += token.source.length;
            break;
          /* istanbul ignore next should not happen */
          default: {
            const message = `Unexpected token in block scalar header: ${token.type}`;
            onError(token, "UNEXPECTED_TOKEN", message);
            const ts = token.source;
            if (ts && typeof ts === "string")
              length += ts.length;
          }
        }
      }
      return { mode, indent, chomp, comment, length };
    }
    function splitLines(source) {
      const split = source.split(/\n( *)/);
      const first = split[0];
      const m = first.match(/^( *)/);
      const line0 = m?.[1] ? [m[1], first.slice(m[1].length)] : ["", first];
      const lines = [line0];
      for (let i = 1; i < split.length; i += 2)
        lines.push([split[i], split[i + 1]]);
      return lines;
    }
    exports2.resolveBlockScalar = resolveBlockScalar;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-flow-scalar.js
var require_resolve_flow_scalar = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/resolve-flow-scalar.js"(exports2) {
    "use strict";
    var Scalar = require_Scalar();
    var resolveEnd = require_resolve_end();
    function resolveFlowScalar(scalar, strict, onError) {
      const { offset, type, source, end } = scalar;
      let _type;
      let value;
      const _onError = (rel, code, msg) => onError(offset + rel, code, msg);
      switch (type) {
        case "scalar":
          _type = Scalar.Scalar.PLAIN;
          value = plainValue(source, _onError);
          break;
        case "single-quoted-scalar":
          _type = Scalar.Scalar.QUOTE_SINGLE;
          value = singleQuotedValue(source, _onError);
          break;
        case "double-quoted-scalar":
          _type = Scalar.Scalar.QUOTE_DOUBLE;
          value = doubleQuotedValue(source, _onError);
          break;
        /* istanbul ignore next should not happen */
        default:
          onError(scalar, "UNEXPECTED_TOKEN", `Expected a flow scalar value, but found: ${type}`);
          return {
            value: "",
            type: null,
            comment: "",
            range: [offset, offset + source.length, offset + source.length]
          };
      }
      const valueEnd = offset + source.length;
      const re = resolveEnd.resolveEnd(end, valueEnd, strict, onError);
      return {
        value,
        type: _type,
        comment: re.comment,
        range: [offset, valueEnd, re.offset]
      };
    }
    function plainValue(source, onError) {
      let badChar = "";
      switch (source[0]) {
        /* istanbul ignore next should not happen */
        case "	":
          badChar = "a tab character";
          break;
        case ",":
          badChar = "flow indicator character ,";
          break;
        case "%":
          badChar = "directive indicator character %";
          break;
        case "|":
        case ">": {
          badChar = `block scalar indicator ${source[0]}`;
          break;
        }
        case "@":
        case "`": {
          badChar = `reserved character ${source[0]}`;
          break;
        }
      }
      if (badChar)
        onError(0, "BAD_SCALAR_START", `Plain value cannot start with ${badChar}`);
      return foldLines(source);
    }
    function singleQuotedValue(source, onError) {
      if (source[source.length - 1] !== "'" || source.length === 1)
        onError(source.length, "MISSING_CHAR", "Missing closing 'quote");
      return foldLines(source.slice(1, -1)).replace(/''/g, "'");
    }
    function foldLines(source) {
      let first, line;
      try {
        first = new RegExp("(.*?)(?<![ 	])[ 	]*\r?\n", "sy");
        line = new RegExp("[ 	]*(.*?)(?:(?<![ 	])[ 	]*)?\r?\n", "sy");
      } catch {
        first = /(.*?)[ \t]*\r?\n/sy;
        line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
      }
      let match = first.exec(source);
      if (!match)
        return source;
      let res = match[1];
      let sep5 = " ";
      let pos = first.lastIndex;
      line.lastIndex = pos;
      while (match = line.exec(source)) {
        if (match[1] === "") {
          if (sep5 === "\n")
            res += sep5;
          else
            sep5 = "\n";
        } else {
          res += sep5 + match[1];
          sep5 = " ";
        }
        pos = line.lastIndex;
      }
      const last = /[ \t]*(.*)/sy;
      last.lastIndex = pos;
      match = last.exec(source);
      return res + sep5 + (match?.[1] ?? "");
    }
    function doubleQuotedValue(source, onError) {
      let res = "";
      for (let i = 1; i < source.length - 1; ++i) {
        const ch = source[i];
        if (ch === "\r" && source[i + 1] === "\n")
          continue;
        if (ch === "\n") {
          const { fold, offset } = foldNewline(source, i);
          res += fold;
          i = offset;
        } else if (ch === "\\") {
          let next = source[++i];
          const cc = escapeCodes[next];
          if (cc)
            res += cc;
          else if (next === "\n") {
            next = source[i + 1];
            while (next === " " || next === "	")
              next = source[++i + 1];
          } else if (next === "\r" && source[i + 1] === "\n") {
            next = source[++i + 1];
            while (next === " " || next === "	")
              next = source[++i + 1];
          } else if (next === "x" || next === "u" || next === "U") {
            const length = { x: 2, u: 4, U: 8 }[next];
            res += parseCharCode(source, i + 1, length, onError);
            i += length;
          } else {
            const raw = source.substr(i - 1, 2);
            onError(i - 1, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
            res += raw;
          }
        } else if (ch === " " || ch === "	") {
          const wsStart = i;
          let next = source[i + 1];
          while (next === " " || next === "	")
            next = source[++i + 1];
          if (next !== "\n" && !(next === "\r" && source[i + 2] === "\n"))
            res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
        } else {
          res += ch;
        }
      }
      if (source[source.length - 1] !== '"' || source.length === 1)
        onError(source.length, "MISSING_CHAR", 'Missing closing "quote');
      return res;
    }
    function foldNewline(source, offset) {
      let fold = "";
      let ch = source[offset + 1];
      while (ch === " " || ch === "	" || ch === "\n" || ch === "\r") {
        if (ch === "\r" && source[offset + 2] !== "\n")
          break;
        if (ch === "\n")
          fold += "\n";
        offset += 1;
        ch = source[offset + 1];
      }
      if (!fold)
        fold = " ";
      return { fold, offset };
    }
    var escapeCodes = {
      "0": "\0",
      // null character
      a: "\x07",
      // bell character
      b: "\b",
      // backspace
      e: "\x1B",
      // escape character
      f: "\f",
      // form feed
      n: "\n",
      // line feed
      r: "\r",
      // carriage return
      t: "	",
      // horizontal tab
      v: "\v",
      // vertical tab
      N: "\x85",
      // Unicode next line
      _: "\xA0",
      // Unicode non-breaking space
      L: "\u2028",
      // Unicode line separator
      P: "\u2029",
      // Unicode paragraph separator
      " ": " ",
      '"': '"',
      "/": "/",
      "\\": "\\",
      "	": "	"
    };
    function parseCharCode(source, offset, length, onError) {
      const cc = source.substr(offset, length);
      const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
      const code = ok ? parseInt(cc, 16) : NaN;
      if (isNaN(code)) {
        const raw = source.substr(offset - 2, length + 2);
        onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
        return raw;
      }
      return String.fromCodePoint(code);
    }
    exports2.resolveFlowScalar = resolveFlowScalar;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-scalar.js
var require_compose_scalar = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-scalar.js"(exports2) {
    "use strict";
    var identity = require_identity();
    var Scalar = require_Scalar();
    var resolveBlockScalar = require_resolve_block_scalar();
    var resolveFlowScalar = require_resolve_flow_scalar();
    function composeScalar(ctx, token, tagToken, onError) {
      const { value, type, comment, range } = token.type === "block-scalar" ? resolveBlockScalar.resolveBlockScalar(ctx, token, onError) : resolveFlowScalar.resolveFlowScalar(token, ctx.options.strict, onError);
      const tagName = tagToken ? ctx.directives.tagName(tagToken.source, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg)) : null;
      let tag;
      if (ctx.options.stringKeys && ctx.atKey) {
        tag = ctx.schema[identity.SCALAR];
      } else if (tagName)
        tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
      else if (token.type === "scalar")
        tag = findScalarTagByTest(ctx, value, token, onError);
      else
        tag = ctx.schema[identity.SCALAR];
      let scalar;
      try {
        const res = tag.resolve(value, (msg) => onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg), ctx.options);
        scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res);
      } catch (error) {
        const msg = error instanceof Error ? error.message : String(error);
        onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg);
        scalar = new Scalar.Scalar(value);
      }
      scalar.range = range;
      scalar.source = value;
      if (type)
        scalar.type = type;
      if (tagName)
        scalar.tag = tagName;
      if (tag.format)
        scalar.format = tag.format;
      if (comment)
        scalar.comment = comment;
      return scalar;
    }
    function findScalarTagByName(schema, value, tagName, tagToken, onError) {
      if (tagName === "!")
        return schema[identity.SCALAR];
      const matchWithTest = [];
      for (const tag of schema.tags) {
        if (!tag.collection && tag.tag === tagName) {
          if (tag.default && tag.test)
            matchWithTest.push(tag);
          else
            return tag;
        }
      }
      for (const tag of matchWithTest)
        if (tag.test?.test(value))
          return tag;
      const kt = schema.knownTags[tagName];
      if (kt && !kt.collection) {
        schema.tags.push(Object.assign({}, kt, { default: false, test: void 0 }));
        return kt;
      }
      onError(tagToken, "TAG_RESOLVE_FAILED", `Unresolved tag: ${tagName}`, tagName !== "tag:yaml.org,2002:str");
      return schema[identity.SCALAR];
    }
    function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
      const tag = schema.tags.find((tag2) => (tag2.default === true || atKey && tag2.default === "key") && tag2.test?.test(value)) || schema[identity.SCALAR];
      if (schema.compat) {
        const compat = schema.compat.find((tag2) => tag2.default && tag2.test?.test(value)) ?? schema[identity.SCALAR];
        if (tag.tag !== compat.tag) {
          const ts = directives.tagString(tag.tag);
          const cs = directives.tagString(compat.tag);
          const msg = `Value may be parsed as either ${ts} or ${cs}`;
          onError(token, "TAG_RESOLVE_FAILED", msg, true);
        }
      }
      return tag;
    }
    exports2.composeScalar = composeScalar;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-empty-scalar-position.js
var require_util_empty_scalar_position = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/util-empty-scalar-position.js"(exports2) {
    "use strict";
    function emptyScalarPosition(offset, before, pos) {
      if (before) {
        pos ?? (pos = before.length);
        for (let i = pos - 1; i >= 0; --i) {
          let st = before[i];
          switch (st.type) {
            case "space":
            case "comment":
            case "newline":
              offset -= st.source.length;
              continue;
          }
          st = before[++i];
          while (st?.type === "space") {
            offset += st.source.length;
            st = before[++i];
          }
          break;
        }
      }
      return offset;
    }
    exports2.emptyScalarPosition = emptyScalarPosition;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-node.js
var require_compose_node = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-node.js"(exports2) {
    "use strict";
    var Alias = require_Alias();
    var identity = require_identity();
    var composeCollection = require_compose_collection();
    var composeScalar = require_compose_scalar();
    var resolveEnd = require_resolve_end();
    var utilEmptyScalarPosition = require_util_empty_scalar_position();
    var CN = { composeNode, composeEmptyNode };
    function composeNode(ctx, token, props, onError) {
      const atKey = ctx.atKey;
      const { spaceBefore, comment, anchor, tag } = props;
      let node;
      let isSrcToken = true;
      switch (token.type) {
        case "alias":
          node = composeAlias(ctx, token, onError);
          if (anchor || tag)
            onError(token, "ALIAS_PROPS", "An alias node must not specify any properties");
          break;
        case "scalar":
        case "single-quoted-scalar":
        case "double-quoted-scalar":
        case "block-scalar":
          node = composeScalar.composeScalar(ctx, token, tag, onError);
          if (anchor)
            node.anchor = anchor.source.substring(1);
          break;
        case "block-map":
        case "block-seq":
        case "flow-collection":
          node = composeCollection.composeCollection(CN, ctx, token, props, onError);
          if (anchor)
            node.anchor = anchor.source.substring(1);
          break;
        default: {
          const message = token.type === "error" ? token.message : `Unsupported token (type: ${token.type})`;
          onError(token, "UNEXPECTED_TOKEN", message);
          node = composeEmptyNode(ctx, token.offset, void 0, null, props, onError);
          isSrcToken = false;
        }
      }
      if (anchor && node.anchor === "")
        onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
      if (atKey && ctx.options.stringKeys && (!identity.isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
        const msg = "With stringKeys, all keys must be strings";
        onError(tag ?? token, "NON_STRING_KEY", msg);
      }
      if (spaceBefore)
        node.spaceBefore = true;
      if (comment) {
        if (token.type === "scalar" && token.source === "")
          node.comment = comment;
        else
          node.commentBefore = comment;
      }
      if (ctx.options.keepSourceTokens && isSrcToken)
        node.srcToken = token;
      return node;
    }
    function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag, end }, onError) {
      const token = {
        type: "scalar",
        offset: utilEmptyScalarPosition.emptyScalarPosition(offset, before, pos),
        indent: -1,
        source: ""
      };
      const node = composeScalar.composeScalar(ctx, token, tag, onError);
      if (anchor) {
        node.anchor = anchor.source.substring(1);
        if (node.anchor === "")
          onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
      }
      if (spaceBefore)
        node.spaceBefore = true;
      if (comment) {
        node.comment = comment;
        node.range[2] = end;
      }
      return node;
    }
    function composeAlias({ options }, { offset, source, end }, onError) {
      const alias = new Alias.Alias(source.substring(1));
      if (alias.source === "")
        onError(offset, "BAD_ALIAS", "Alias cannot be an empty string");
      if (alias.source.endsWith(":"))
        onError(offset + source.length - 1, "BAD_ALIAS", "Alias ending in : is ambiguous", true);
      const valueEnd = offset + source.length;
      const re = resolveEnd.resolveEnd(end, valueEnd, options.strict, onError);
      alias.range = [offset, valueEnd, re.offset];
      if (re.comment)
        alias.comment = re.comment;
      return alias;
    }
    exports2.composeEmptyNode = composeEmptyNode;
    exports2.composeNode = composeNode;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-doc.js
var require_compose_doc = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/compose-doc.js"(exports2) {
    "use strict";
    var Document = require_Document();
    var composeNode = require_compose_node();
    var resolveEnd = require_resolve_end();
    var resolveProps = require_resolve_props();
    function composeDoc(options, directives, { offset, start, value, end }, onError) {
      const opts = Object.assign({ _directives: directives }, options);
      const doc = new Document.Document(void 0, opts);
      const ctx = {
        atKey: false,
        atRoot: true,
        directives: doc.directives,
        options: doc.options,
        schema: doc.schema
      };
      const props = resolveProps.resolveProps(start, {
        indicator: "doc-start",
        next: value ?? end?.[0],
        offset,
        onError,
        parentIndent: 0,
        startOnNewline: true
      });
      if (props.found) {
        doc.directives.docStart = true;
        if (value && (value.type === "block-map" || value.type === "block-seq") && !props.hasNewline)
          onError(props.end, "MISSING_CHAR", "Block collection cannot start on same line with directives-end marker");
      }
      doc.contents = value ? composeNode.composeNode(ctx, value, props, onError) : composeNode.composeEmptyNode(ctx, props.end, start, null, props, onError);
      const contentEnd = doc.contents.range[2];
      const re = resolveEnd.resolveEnd(end, contentEnd, false, onError);
      if (re.comment)
        doc.comment = re.comment;
      doc.range = [offset, contentEnd, re.offset];
      return doc;
    }
    exports2.composeDoc = composeDoc;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/composer.js
var require_composer = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/compose/composer.js"(exports2) {
    "use strict";
    var node_process = process;
    var directives = require_directives();
    var Document = require_Document();
    var errors = require_errors();
    var identity = require_identity();
    var composeDoc = require_compose_doc();
    var resolveEnd = require_resolve_end();
    function getErrorPos(src) {
      if (typeof src === "number")
        return [src, src + 1];
      if (Array.isArray(src))
        return src.length === 2 ? src : [src[0], src[1]];
      const { offset, source } = src;
      return [offset, offset + (typeof source === "string" ? source.length : 1)];
    }
    function parsePrelude(prelude) {
      let comment = "";
      let atComment = false;
      let afterEmptyLine = false;
      for (let i = 0; i < prelude.length; ++i) {
        const source = prelude[i];
        switch (source[0]) {
          case "#":
            comment += (comment === "" ? "" : afterEmptyLine ? "\n\n" : "\n") + (source.substring(1) || " ");
            atComment = true;
            afterEmptyLine = false;
            break;
          case "%":
            if (prelude[i + 1]?.[0] !== "#")
              i += 1;
            atComment = false;
            break;
          default:
            if (!atComment)
              afterEmptyLine = true;
            atComment = false;
        }
      }
      return { comment, afterEmptyLine };
    }
    var Composer = class {
      constructor(options = {}) {
        this.doc = null;
        this.atDirectives = false;
        this.prelude = [];
        this.errors = [];
        this.warnings = [];
        this.onError = (source, code, message, warning) => {
          const pos = getErrorPos(source);
          if (warning)
            this.warnings.push(new errors.YAMLWarning(pos, code, message));
          else
            this.errors.push(new errors.YAMLParseError(pos, code, message));
        };
        this.directives = new directives.Directives({ version: options.version || "1.2" });
        this.options = options;
      }
      decorate(doc, afterDoc) {
        const { comment, afterEmptyLine } = parsePrelude(this.prelude);
        if (comment) {
          const dc = doc.contents;
          if (afterDoc) {
            doc.comment = doc.comment ? `${doc.comment}
${comment}` : comment;
          } else if (afterEmptyLine || doc.directives.docStart || !dc) {
            doc.commentBefore = comment;
          } else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) {
            let it = dc.items[0];
            if (identity.isPair(it))
              it = it.key;
            const cb = it.commentBefore;
            it.commentBefore = cb ? `${comment}
${cb}` : comment;
          } else {
            const cb = dc.commentBefore;
            dc.commentBefore = cb ? `${comment}
${cb}` : comment;
          }
        }
        if (afterDoc) {
          Array.prototype.push.apply(doc.errors, this.errors);
          Array.prototype.push.apply(doc.warnings, this.warnings);
        } else {
          doc.errors = this.errors;
          doc.warnings = this.warnings;
        }
        this.prelude = [];
        this.errors = [];
        this.warnings = [];
      }
      /**
       * Current stream status information.
       *
       * Mostly useful at the end of input for an empty stream.
       */
      streamInfo() {
        return {
          comment: parsePrelude(this.prelude).comment,
          directives: this.directives,
          errors: this.errors,
          warnings: this.warnings
        };
      }
      /**
       * Compose tokens into documents.
       *
       * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
       * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
       */
      *compose(tokens, forceDoc = false, endOffset = -1) {
        for (const token of tokens)
          yield* this.next(token);
        yield* this.end(forceDoc, endOffset);
      }
      /** Advance the composer by one CST token. */
      *next(token) {
        
        switch (token.type) {
          case "directive":
            this.directives.add(token.source, (offset, message, warning) => {
              const pos = getErrorPos(token);
              pos[0] += offset;
              this.onError(pos, "BAD_DIRECTIVE", message, warning);
            });
            this.prelude.push(token.source);
            this.atDirectives = true;
            break;
          case "document": {
            const doc = composeDoc.composeDoc(this.options, this.directives, token, this.onError);
            if (this.atDirectives && !doc.directives.docStart)
              this.onError(token, "MISSING_CHAR", "Missing directives-end/doc-start indicator line");
            this.decorate(doc, false);
            if (this.doc)
              yield this.doc;
            this.doc = doc;
            this.atDirectives = false;
            break;
          }
          case "byte-order-mark":
          case "space":
            break;
          case "comment":
          case "newline":
            this.prelude.push(token.source);
            break;
          case "error": {
            const msg = token.source ? `${token.message}: ${JSON.stringify(token.source)}` : token.message;
            const error = new errors.YAMLParseError(getErrorPos(token), "UNEXPECTED_TOKEN", msg);
            if (this.atDirectives || !this.doc)
              this.errors.push(error);
            else
              this.doc.errors.push(error);
            break;
          }
          case "doc-end": {
            if (!this.doc) {
              const msg = "Unexpected doc-end without preceding document";
              this.errors.push(new errors.YAMLParseError(getErrorPos(token), "UNEXPECTED_TOKEN", msg));
              break;
            }
            this.doc.directives.docEnd = true;
            const end = resolveEnd.resolveEnd(token.end, token.offset + token.source.length, this.doc.options.strict, this.onError);
            this.decorate(this.doc, true);
            if (end.comment) {
              const dc = this.doc.comment;
              this.doc.comment = dc ? `${dc}
${end.comment}` : end.comment;
            }
            this.doc.range[2] = end.offset;
            break;
          }
          default:
            this.errors.push(new errors.YAMLParseError(getErrorPos(token), "UNEXPECTED_TOKEN", `Unsupported token ${token.type}`));
        }
      }
      /**
       * Call at end of input to yield any remaining document.
       *
       * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
       * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
       */
      *end(forceDoc = false, endOffset = -1) {
        if (this.doc) {
          this.decorate(this.doc, true);
          yield this.doc;
          this.doc = null;
        } else if (forceDoc) {
          const opts = Object.assign({ _directives: this.directives }, this.options);
          const doc = new Document.Document(void 0, opts);
          if (this.atDirectives)
            this.onError(endOffset, "MISSING_CHAR", "Missing directives-end indicator line");
          doc.range = [0, endOffset, endOffset];
          this.decorate(doc, false);
          yield doc;
        }
      }
    };
    exports2.Composer = Composer;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst-scalar.js
var require_cst_scalar = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst-scalar.js"(exports2) {
    "use strict";
    var resolveBlockScalar = require_resolve_block_scalar();
    var resolveFlowScalar = require_resolve_flow_scalar();
    var errors = require_errors();
    var stringifyString = require_stringifyString();
    function resolveAsScalar(token, strict = true, onError) {
      if (token) {
        const _onError = (pos, code, message) => {
          const offset = typeof pos === "number" ? pos : Array.isArray(pos) ? pos[0] : pos.offset;
          if (onError)
            onError(offset, code, message);
          else
            throw new errors.YAMLParseError([offset, offset + 1], code, message);
        };
        switch (token.type) {
          case "scalar":
          case "single-quoted-scalar":
          case "double-quoted-scalar":
            return resolveFlowScalar.resolveFlowScalar(token, strict, _onError);
          case "block-scalar":
            return resolveBlockScalar.resolveBlockScalar({ options: { strict } }, token, _onError);
        }
      }
      return null;
    }
    function createScalarToken(value, context) {
      const { implicitKey = false, indent, inFlow = false, offset = -1, type = "PLAIN" } = context;
      const source = stringifyString.stringifyString({ type, value }, {
        implicitKey,
        indent: indent > 0 ? " ".repeat(indent) : "",
        inFlow,
        options: { blockQuote: true, lineWidth: -1 }
      });
      const end = context.end ?? [
        { type: "newline", offset: -1, indent, source: "\n" }
      ];
      switch (source[0]) {
        case "|":
        case ">": {
          const he = source.indexOf("\n");
          const head = source.substring(0, he);
          const body = source.substring(he + 1) + "\n";
          const props = [
            { type: "block-scalar-header", offset, indent, source: head }
          ];
          if (!addEndtoBlockProps(props, end))
            props.push({ type: "newline", offset: -1, indent, source: "\n" });
          return { type: "block-scalar", offset, indent, props, source: body };
        }
        case '"':
          return { type: "double-quoted-scalar", offset, indent, source, end };
        case "'":
          return { type: "single-quoted-scalar", offset, indent, source, end };
        default:
          return { type: "scalar", offset, indent, source, end };
      }
    }
    function setScalarValue(token, value, context = {}) {
      let { afterKey = false, implicitKey = false, inFlow = false, type } = context;
      let indent = "indent" in token ? token.indent : null;
      if (afterKey && typeof indent === "number")
        indent += 2;
      if (!type)
        switch (token.type) {
          case "single-quoted-scalar":
            type = "QUOTE_SINGLE";
            break;
          case "double-quoted-scalar":
            type = "QUOTE_DOUBLE";
            break;
          case "block-scalar": {
            const header = token.props[0];
            if (header.type !== "block-scalar-header")
              throw new Error("Invalid block scalar header");
            type = header.source[0] === ">" ? "BLOCK_FOLDED" : "BLOCK_LITERAL";
            break;
          }
          default:
            type = "PLAIN";
        }
      const source = stringifyString.stringifyString({ type, value }, {
        implicitKey: implicitKey || indent === null,
        indent: indent !== null && indent > 0 ? " ".repeat(indent) : "",
        inFlow,
        options: { blockQuote: true, lineWidth: -1 }
      });
      switch (source[0]) {
        case "|":
        case ">":
          setBlockScalarValue(token, source);
          break;
        case '"':
          setFlowScalarValue(token, source, "double-quoted-scalar");
          break;
        case "'":
          setFlowScalarValue(token, source, "single-quoted-scalar");
          break;
        default:
          setFlowScalarValue(token, source, "scalar");
      }
    }
    function setBlockScalarValue(token, source) {
      const he = source.indexOf("\n");
      const head = source.substring(0, he);
      const body = source.substring(he + 1) + "\n";
      if (token.type === "block-scalar") {
        const header = token.props[0];
        if (header.type !== "block-scalar-header")
          throw new Error("Invalid block scalar header");
        header.source = head;
        token.source = body;
      } else {
        const { offset } = token;
        const indent = "indent" in token ? token.indent : -1;
        const props = [
          { type: "block-scalar-header", offset, indent, source: head }
        ];
        if (!addEndtoBlockProps(props, "end" in token ? token.end : void 0))
          props.push({ type: "newline", offset: -1, indent, source: "\n" });
        for (const key of Object.keys(token))
          if (key !== "type" && key !== "offset")
            delete token[key];
        Object.assign(token, { type: "block-scalar", indent, props, source: body });
      }
    }
    function addEndtoBlockProps(props, end) {
      if (end)
        for (const st of end)
          switch (st.type) {
            case "space":
            case "comment":
              props.push(st);
              break;
            case "newline":
              props.push(st);
              return true;
          }
      return false;
    }
    function setFlowScalarValue(token, source, type) {
      switch (token.type) {
        case "scalar":
        case "double-quoted-scalar":
        case "single-quoted-scalar":
          token.type = type;
          token.source = source;
          break;
        case "block-scalar": {
          const end = token.props.slice(1);
          let oa = source.length;
          if (token.props[0].type === "block-scalar-header")
            oa -= token.props[0].source.length;
          for (const tok of end)
            tok.offset += oa;
          delete token.props;
          Object.assign(token, { type, source, end });
          break;
        }
        case "block-map":
        case "block-seq": {
          const offset = token.offset + source.length;
          const nl = { type: "newline", offset, indent: token.indent, source: "\n" };
          delete token.items;
          Object.assign(token, { type, source, end: [nl] });
          break;
        }
        default: {
          const indent = "indent" in token ? token.indent : -1;
          const end = "end" in token && Array.isArray(token.end) ? token.end.filter((st) => st.type === "space" || st.type === "comment" || st.type === "newline") : [];
          for (const key of Object.keys(token))
            if (key !== "type" && key !== "offset")
              delete token[key];
          Object.assign(token, { type, indent, source, end });
        }
      }
    }
    exports2.createScalarToken = createScalarToken;
    exports2.resolveAsScalar = resolveAsScalar;
    exports2.setScalarValue = setScalarValue;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst-stringify.js
var require_cst_stringify = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst-stringify.js"(exports2) {
    "use strict";
    var stringify = (cst) => "type" in cst ? stringifyToken(cst) : stringifyItem(cst);
    function stringifyToken(token) {
      switch (token.type) {
        case "block-scalar": {
          let res = "";
          for (const tok of token.props)
            res += stringifyToken(tok);
          return res + token.source;
        }
        case "block-map":
        case "block-seq": {
          let res = "";
          for (const item of token.items)
            res += stringifyItem(item);
          return res;
        }
        case "flow-collection": {
          let res = token.start.source;
          for (const item of token.items)
            res += stringifyItem(item);
          for (const st of token.end)
            res += st.source;
          return res;
        }
        case "document": {
          let res = stringifyItem(token);
          if (token.end)
            for (const st of token.end)
              res += st.source;
          return res;
        }
        default: {
          let res = token.source;
          if ("end" in token && token.end)
            for (const st of token.end)
              res += st.source;
          return res;
        }
      }
    }
    function stringifyItem({ start, key, sep: sep5, value }) {
      let res = "";
      for (const st of start)
        res += st.source;
      if (key)
        res += stringifyToken(key);
      if (sep5)
        for (const st of sep5)
          res += st.source;
      if (value)
        res += stringifyToken(value);
      return res;
    }
    exports2.stringify = stringify;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst-visit.js
var require_cst_visit = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst-visit.js"(exports2) {
    "use strict";
    var BREAK = Symbol("break visit");
    var SKIP = Symbol("skip children");
    var REMOVE = Symbol("remove item");
    function visit(cst, visitor) {
      if ("type" in cst && cst.type === "document")
        cst = { start: cst.start, value: cst.value };
      _visit(Object.freeze([]), cst, visitor);
    }
    visit.BREAK = BREAK;
    visit.SKIP = SKIP;
    visit.REMOVE = REMOVE;
    visit.itemAtPath = (cst, path) => {
      let item = cst;
      for (const [field, index] of path) {
        const tok = item?.[field];
        if (tok && "items" in tok) {
          item = tok.items[index];
        } else
          return void 0;
      }
      return item;
    };
    visit.parentCollection = (cst, path) => {
      const parent = visit.itemAtPath(cst, path.slice(0, -1));
      const field = path[path.length - 1][0];
      const coll = parent?.[field];
      if (coll && "items" in coll)
        return coll;
      throw new Error("Parent collection not found");
    };
    function _visit(path, item, visitor) {
      let ctrl = visitor(item, path);
      if (typeof ctrl === "symbol")
        return ctrl;
      for (const field of ["key", "value"]) {
        const token = item[field];
        if (token && "items" in token) {
          for (let i = 0; i < token.items.length; ++i) {
            const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);
            if (typeof ci === "number")
              i = ci - 1;
            else if (ci === BREAK)
              return BREAK;
            else if (ci === REMOVE) {
              token.items.splice(i, 1);
              i -= 1;
            }
          }
          if (typeof ctrl === "function" && field === "key")
            ctrl = ctrl(item, path);
        }
      }
      return typeof ctrl === "function" ? ctrl(item, path) : ctrl;
    }
    exports2.visit = visit;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst.js
var require_cst = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/cst.js"(exports2) {
    "use strict";
    var cstScalar = require_cst_scalar();
    var cstStringify = require_cst_stringify();
    var cstVisit = require_cst_visit();
    var BOM = "\uFEFF";
    var DOCUMENT = "";
    var FLOW_END = "";
    var SCALAR = "";
    var isCollection = (token) => !!token && "items" in token;
    var isScalar = (token) => !!token && (token.type === "scalar" || token.type === "single-quoted-scalar" || token.type === "double-quoted-scalar" || token.type === "block-scalar");
    function prettyToken(token) {
      switch (token) {
        case BOM:
          return "<BOM>";
        case DOCUMENT:
          return "<DOC>";
        case FLOW_END:
          return "<FLOW_END>";
        case SCALAR:
          return "<SCALAR>";
        default:
          return JSON.stringify(token);
      }
    }
    function tokenType(source) {
      switch (source) {
        case BOM:
          return "byte-order-mark";
        case DOCUMENT:
          return "doc-mode";
        case FLOW_END:
          return "flow-error-end";
        case SCALAR:
          return "scalar";
        case "---":
          return "doc-start";
        case "...":
          return "doc-end";
        case "":
        case "\n":
        case "\r\n":
          return "newline";
        case "-":
          return "seq-item-ind";
        case "?":
          return "explicit-key-ind";
        case ":":
          return "map-value-ind";
        case "{":
          return "flow-map-start";
        case "}":
          return "flow-map-end";
        case "[":
          return "flow-seq-start";
        case "]":
          return "flow-seq-end";
        case ",":
          return "comma";
      }
      switch (source[0]) {
        case " ":
        case "	":
          return "space";
        case "#":
          return "comment";
        case "%":
          return "directive-line";
        case "*":
          return "alias";
        case "&":
          return "anchor";
        case "!":
          return "tag";
        case "'":
          return "single-quoted-scalar";
        case '"':
          return "double-quoted-scalar";
        case "|":
        case ">":
          return "block-scalar-header";
      }
      return null;
    }
    exports2.createScalarToken = cstScalar.createScalarToken;
    exports2.resolveAsScalar = cstScalar.resolveAsScalar;
    exports2.setScalarValue = cstScalar.setScalarValue;
    exports2.stringify = cstStringify.stringify;
    exports2.visit = cstVisit.visit;
    exports2.BOM = BOM;
    exports2.DOCUMENT = DOCUMENT;
    exports2.FLOW_END = FLOW_END;
    exports2.SCALAR = SCALAR;
    exports2.isCollection = isCollection;
    exports2.isScalar = isScalar;
    exports2.prettyToken = prettyToken;
    exports2.tokenType = tokenType;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/lexer.js
var require_lexer = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/lexer.js"(exports2) {
    "use strict";
    var cst = require_cst();
    function isEmpty(ch) {
      switch (ch) {
        case void 0:
        case " ":
        case "\n":
        case "\r":
        case "	":
          return true;
        default:
          return false;
      }
    }
    var hexDigits = new Set("0123456789ABCDEFabcdef");
    var tagChars = new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()");
    var flowIndicatorChars = new Set(",[]{}");
    var invalidAnchorChars = new Set(" ,[]{}\n\r	");
    var isNotAnchorChar = (ch) => !ch || invalidAnchorChars.has(ch);
    var Lexer = class {
      constructor() {
        this.atEnd = false;
        this.blockScalarIndent = -1;
        this.blockScalarKeep = false;
        this.buffer = "";
        this.flowKey = false;
        this.flowLevel = 0;
        this.indentNext = 0;
        this.indentValue = 0;
        this.lineEndPos = null;
        this.next = null;
        this.pos = 0;
      }
      /**
       * Generate YAML tokens from the `source` string. If `incomplete`,
       * a part of the last line may be left as a buffer for the next call.
       *
       * @returns A generator of lexical tokens
       */
      *lex(source, incomplete = false) {
        if (source) {
          if (typeof source !== "string")
            throw TypeError("source is not a string");
          this.buffer = this.buffer ? this.buffer + source : source;
          this.lineEndPos = null;
        }
        this.atEnd = !incomplete;
        let next = this.next ?? "stream";
        while (next && (incomplete || this.hasChars(1)))
          next = yield* this.parseNext(next);
      }
      atLineEnd() {
        let i = this.pos;
        let ch = this.buffer[i];
        while (ch === " " || ch === "	")
          ch = this.buffer[++i];
        if (!ch || ch === "#" || ch === "\n")
          return true;
        if (ch === "\r")
          return this.buffer[i + 1] === "\n";
        return false;
      }
      charAt(n) {
        return this.buffer[this.pos + n];
      }
      continueScalar(offset) {
        let ch = this.buffer[offset];
        if (this.indentNext > 0) {
          let indent = 0;
          while (ch === " ")
            ch = this.buffer[++indent + offset];
          if (ch === "\r") {
            const next = this.buffer[indent + offset + 1];
            if (next === "\n" || !next && !this.atEnd)
              return offset + indent + 1;
          }
          return ch === "\n" || indent >= this.indentNext || !ch && !this.atEnd ? offset + indent : -1;
        }
        if (ch === "-" || ch === ".") {
          const dt = this.buffer.substr(offset, 3);
          if ((dt === "---" || dt === "...") && isEmpty(this.buffer[offset + 3]))
            return -1;
        }
        return offset;
      }
      getLine() {
        let end = this.lineEndPos;
        if (typeof end !== "number" || end !== -1 && end < this.pos) {
          end = this.buffer.indexOf("\n", this.pos);
          this.lineEndPos = end;
        }
        if (end === -1)
          return this.atEnd ? this.buffer.substring(this.pos) : null;
        if (this.buffer[end - 1] === "\r")
          end -= 1;
        return this.buffer.substring(this.pos, end);
      }
      hasChars(n) {
        return this.pos + n <= this.buffer.length;
      }
      setNext(state) {
        this.buffer = this.buffer.substring(this.pos);
        this.pos = 0;
        this.lineEndPos = null;
        this.next = state;
        return null;
      }
      peek(n) {
        return this.buffer.substr(this.pos, n);
      }
      *parseNext(next) {
        switch (next) {
          case "stream":
            return yield* this.parseStream();
          case "line-start":
            return yield* this.parseLineStart();
          case "block-start":
            return yield* this.parseBlockStart();
          case "doc":
            return yield* this.parseDocument();
          case "flow":
            return yield* this.parseFlowCollection();
          case "quoted-scalar":
            return yield* this.parseQuotedScalar();
          case "block-scalar":
            return yield* this.parseBlockScalar();
          case "plain-scalar":
            return yield* this.parsePlainScalar();
        }
      }
      *parseStream() {
        let line = this.getLine();
        if (line === null)
          return this.setNext("stream");
        if (line[0] === cst.BOM) {
          yield* this.pushCount(1);
          line = line.substring(1);
        }
        if (line[0] === "%") {
          let dirEnd = line.length;
          let cs = line.indexOf("#");
          while (cs !== -1) {
            const ch = line[cs - 1];
            if (ch === " " || ch === "	") {
              dirEnd = cs - 1;
              break;
            } else {
              cs = line.indexOf("#", cs + 1);
            }
          }
          while (true) {
            const ch = line[dirEnd - 1];
            if (ch === " " || ch === "	")
              dirEnd -= 1;
            else
              break;
          }
          const n = (yield* this.pushCount(dirEnd)) + (yield* this.pushSpaces(true));
          yield* this.pushCount(line.length - n);
          this.pushNewline();
          return "stream";
        }
        if (this.atLineEnd()) {
          const sp = yield* this.pushSpaces(true);
          yield* this.pushCount(line.length - sp);
          yield* this.pushNewline();
          return "stream";
        }
        yield cst.DOCUMENT;
        return yield* this.parseLineStart();
      }
      *parseLineStart() {
        const ch = this.charAt(0);
        if (!ch && !this.atEnd)
          return this.setNext("line-start");
        if (ch === "-" || ch === ".") {
          if (!this.atEnd && !this.hasChars(4))
            return this.setNext("line-start");
          const s = this.peek(3);
          if ((s === "---" || s === "...") && isEmpty(this.charAt(3))) {
            yield* this.pushCount(3);
            this.indentValue = 0;
            this.indentNext = 0;
            return s === "---" ? "doc" : "stream";
          }
        }
        this.indentValue = yield* this.pushSpaces(false);
        if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1)))
          this.indentNext = this.indentValue;
        return yield* this.parseBlockStart();
      }
      *parseBlockStart() {
        const [ch0, ch1] = this.peek(2);
        if (!ch1 && !this.atEnd)
          return this.setNext("block-start");
        if ((ch0 === "-" || ch0 === "?" || ch0 === ":") && isEmpty(ch1)) {
          const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
          this.indentNext = this.indentValue + 1;
          this.indentValue += n;
          return yield* this.parseBlockStart();
        }
        return "doc";
      }
      *parseDocument() {
        yield* this.pushSpaces(true);
        const line = this.getLine();
        if (line === null)
          return this.setNext("doc");
        let n = yield* this.pushIndicators();
        switch (line[n]) {
          case "#":
            yield* this.pushCount(line.length - n);
          // fallthrough
          case void 0:
            yield* this.pushNewline();
            return yield* this.parseLineStart();
          case "{":
          case "[":
            yield* this.pushCount(1);
            this.flowKey = false;
            this.flowLevel = 1;
            return "flow";
          case "}":
          case "]":
            yield* this.pushCount(1);
            return "doc";
          case "*":
            yield* this.pushUntil(isNotAnchorChar);
            return "doc";
          case '"':
          case "'":
            return yield* this.parseQuotedScalar();
          case "|":
          case ">":
            n += yield* this.parseBlockScalarHeader();
            n += yield* this.pushSpaces(true);
            yield* this.pushCount(line.length - n);
            yield* this.pushNewline();
            return yield* this.parseBlockScalar();
          default:
            return yield* this.parsePlainScalar();
        }
      }
      *parseFlowCollection() {
        let nl, sp;
        let indent = -1;
        do {
          nl = yield* this.pushNewline();
          if (nl > 0) {
            sp = yield* this.pushSpaces(false);
            this.indentValue = indent = sp;
          } else {
            sp = 0;
          }
          sp += yield* this.pushSpaces(true);
        } while (nl + sp > 0);
        const line = this.getLine();
        if (line === null)
          return this.setNext("flow");
        if (indent !== -1 && indent < this.indentNext && line[0] !== "#" || indent === 0 && (line.startsWith("---") || line.startsWith("...")) && isEmpty(line[3])) {
          const atFlowEndMarker = indent === this.indentNext - 1 && this.flowLevel === 1 && (line[0] === "]" || line[0] === "}");
          if (!atFlowEndMarker) {
            this.flowLevel = 0;
            yield cst.FLOW_END;
            return yield* this.parseLineStart();
          }
        }
        let n = 0;
        while (line[n] === ",") {
          n += yield* this.pushCount(1);
          n += yield* this.pushSpaces(true);
          this.flowKey = false;
        }
        n += yield* this.pushIndicators();
        switch (line[n]) {
          case void 0:
            return "flow";
          case "#":
            yield* this.pushCount(line.length - n);
            return "flow";
          case "{":
          case "[":
            yield* this.pushCount(1);
            this.flowKey = false;
            this.flowLevel += 1;
            return "flow";
          case "}":
          case "]":
            yield* this.pushCount(1);
            this.flowKey = true;
            this.flowLevel -= 1;
            return this.flowLevel ? "flow" : "doc";
          case "*":
            yield* this.pushUntil(isNotAnchorChar);
            return "flow";
          case '"':
          case "'":
            this.flowKey = true;
            return yield* this.parseQuotedScalar();
          case ":": {
            const next = this.charAt(1);
            if (this.flowKey || isEmpty(next) || next === ",") {
              this.flowKey = false;
              yield* this.pushCount(1);
              yield* this.pushSpaces(true);
              return "flow";
            }
          }
          // fallthrough
          default:
            this.flowKey = false;
            return yield* this.parsePlainScalar();
        }
      }
      *parseQuotedScalar() {
        const quote = this.charAt(0);
        let end = this.buffer.indexOf(quote, this.pos + 1);
        if (quote === "'") {
          while (end !== -1 && this.buffer[end + 1] === "'")
            end = this.buffer.indexOf("'", end + 2);
        } else {
          while (end !== -1) {
            let n = 0;
            while (this.buffer[end - 1 - n] === "\\")
              n += 1;
            if (n % 2 === 0)
              break;
            end = this.buffer.indexOf('"', end + 1);
          }
        }
        const qb = this.buffer.substring(0, end);
        let nl = qb.indexOf("\n", this.pos);
        if (nl !== -1) {
          while (nl !== -1) {
            const cs = this.continueScalar(nl + 1);
            if (cs === -1)
              break;
            nl = qb.indexOf("\n", cs);
          }
          if (nl !== -1) {
            end = nl - (qb[nl - 1] === "\r" ? 2 : 1);
          }
        }
        if (end === -1) {
          if (!this.atEnd)
            return this.setNext("quoted-scalar");
          end = this.buffer.length;
        }
        yield* this.pushToIndex(end + 1, false);
        return this.flowLevel ? "flow" : "doc";
      }
      *parseBlockScalarHeader() {
        this.blockScalarIndent = -1;
        this.blockScalarKeep = false;
        let i = this.pos;
        while (true) {
          const ch = this.buffer[++i];
          if (ch === "+")
            this.blockScalarKeep = true;
          else if (ch > "0" && ch <= "9")
            this.blockScalarIndent = Number(ch) - 1;
          else if (ch !== "-")
            break;
        }
        return yield* this.pushUntil((ch) => isEmpty(ch) || ch === "#");
      }
      *parseBlockScalar() {
        let nl = this.pos - 1;
        let indent = 0;
        let ch;
        loop: for (let i2 = this.pos; ch = this.buffer[i2]; ++i2) {
          switch (ch) {
            case " ":
              indent += 1;
              break;
            case "\n":
              nl = i2;
              indent = 0;
              break;
            case "\r": {
              const next = this.buffer[i2 + 1];
              if (!next && !this.atEnd)
                return this.setNext("block-scalar");
              if (next === "\n")
                break;
            }
            // fallthrough
            default:
              break loop;
          }
        }
        if (!ch && !this.atEnd)
          return this.setNext("block-scalar");
        if (indent >= this.indentNext) {
          if (this.blockScalarIndent === -1)
            this.indentNext = indent;
          else {
            this.indentNext = this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext);
          }
          do {
            const cs = this.continueScalar(nl + 1);
            if (cs === -1)
              break;
            nl = this.buffer.indexOf("\n", cs);
          } while (nl !== -1);
          if (nl === -1) {
            if (!this.atEnd)
              return this.setNext("block-scalar");
            nl = this.buffer.length;
          }
        }
        let i = nl + 1;
        ch = this.buffer[i];
        while (ch === " ")
          ch = this.buffer[++i];
        if (ch === "	") {
          while (ch === "	" || ch === " " || ch === "\r" || ch === "\n")
            ch = this.buffer[++i];
          nl = i - 1;
        } else if (!this.blockScalarKeep) {
          do {
            let i2 = nl - 1;
            let ch2 = this.buffer[i2];
            if (ch2 === "\r")
              ch2 = this.buffer[--i2];
            const lastChar = i2;
            while (ch2 === " ")
              ch2 = this.buffer[--i2];
            if (ch2 === "\n" && i2 >= this.pos && i2 + 1 + indent > lastChar)
              nl = i2;
            else
              break;
          } while (true);
        }
        yield cst.SCALAR;
        yield* this.pushToIndex(nl + 1, true);
        return yield* this.parseLineStart();
      }
      *parsePlainScalar() {
        const inFlow = this.flowLevel > 0;
        let end = this.pos - 1;
        let i = this.pos - 1;
        let ch;
        while (ch = this.buffer[++i]) {
          if (ch === ":") {
            const next = this.buffer[i + 1];
            if (isEmpty(next) || inFlow && flowIndicatorChars.has(next))
              break;
            end = i;
          } else if (isEmpty(ch)) {
            let next = this.buffer[i + 1];
            if (ch === "\r") {
              if (next === "\n") {
                i += 1;
                ch = "\n";
                next = this.buffer[i + 1];
              } else
                end = i;
            }
            if (next === "#" || inFlow && flowIndicatorChars.has(next))
              break;
            if (ch === "\n") {
              const cs = this.continueScalar(i + 1);
              if (cs === -1)
                break;
              i = Math.max(i, cs - 2);
            }
          } else {
            if (inFlow && flowIndicatorChars.has(ch))
              break;
            end = i;
          }
        }
        if (!ch && !this.atEnd)
          return this.setNext("plain-scalar");
        yield cst.SCALAR;
        yield* this.pushToIndex(end + 1, true);
        return inFlow ? "flow" : "doc";
      }
      *pushCount(n) {
        if (n > 0) {
          yield this.buffer.substr(this.pos, n);
          this.pos += n;
          return n;
        }
        return 0;
      }
      *pushToIndex(i, allowEmpty) {
        const s = this.buffer.slice(this.pos, i);
        if (s) {
          yield s;
          this.pos += s.length;
          return s.length;
        } else if (allowEmpty)
          yield "";
        return 0;
      }
      *pushIndicators() {
        switch (this.charAt(0)) {
          case "!":
            return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
          case "&":
            return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
          case "-":
          // this is an error
          case "?":
          // this is an error outside flow collections
          case ":": {
            const inFlow = this.flowLevel > 0;
            const ch1 = this.charAt(1);
            if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
              if (!inFlow)
                this.indentNext = this.indentValue + 1;
              else if (this.flowKey)
                this.flowKey = false;
              return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
            }
          }
        }
        return 0;
      }
      *pushTag() {
        if (this.charAt(1) === "<") {
          let i = this.pos + 2;
          let ch = this.buffer[i];
          while (!isEmpty(ch) && ch !== ">")
            ch = this.buffer[++i];
          return yield* this.pushToIndex(ch === ">" ? i + 1 : i, false);
        } else {
          let i = this.pos + 1;
          let ch = this.buffer[i];
          while (ch) {
            if (tagChars.has(ch))
              ch = this.buffer[++i];
            else if (ch === "%" && hexDigits.has(this.buffer[i + 1]) && hexDigits.has(this.buffer[i + 2])) {
              ch = this.buffer[i += 3];
            } else
              break;
          }
          return yield* this.pushToIndex(i, false);
        }
      }
      *pushNewline() {
        const ch = this.buffer[this.pos];
        if (ch === "\n")
          return yield* this.pushCount(1);
        else if (ch === "\r" && this.charAt(1) === "\n")
          return yield* this.pushCount(2);
        else
          return 0;
      }
      *pushSpaces(allowTabs) {
        let i = this.pos - 1;
        let ch;
        do {
          ch = this.buffer[++i];
        } while (ch === " " || allowTabs && ch === "	");
        const n = i - this.pos;
        if (n > 0) {
          yield this.buffer.substr(this.pos, n);
          this.pos = i;
        }
        return n;
      }
      *pushUntil(test) {
        let i = this.pos;
        let ch = this.buffer[i];
        while (!test(ch))
          ch = this.buffer[++i];
        return yield* this.pushToIndex(i, false);
      }
    };
    exports2.Lexer = Lexer;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/line-counter.js
var require_line_counter = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/line-counter.js"(exports2) {
    "use strict";
    var LineCounter = class {
      constructor() {
        this.lineStarts = [];
        this.addNewLine = (offset) => this.lineStarts.push(offset);
        this.linePos = (offset) => {
          let low = 0;
          let high = this.lineStarts.length;
          while (low < high) {
            const mid = low + high >> 1;
            if (this.lineStarts[mid] < offset)
              low = mid + 1;
            else
              high = mid;
          }
          if (this.lineStarts[low] === offset)
            return { line: low + 1, col: 1 };
          if (low === 0)
            return { line: 0, col: offset };
          const start = this.lineStarts[low - 1];
          return { line: low, col: offset - start + 1 };
        };
      }
    };
    exports2.LineCounter = LineCounter;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/parser.js
var require_parser = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/parse/parser.js"(exports2) {
    "use strict";
    var node_process = process;
    var cst = require_cst();
    var lexer = require_lexer();
    function includesToken(list, type) {
      for (let i = 0; i < list.length; ++i)
        if (list[i].type === type)
          return true;
      return false;
    }
    function findNonEmptyIndex(list) {
      for (let i = 0; i < list.length; ++i) {
        switch (list[i].type) {
          case "space":
          case "comment":
          case "newline":
            break;
          default:
            return i;
        }
      }
      return -1;
    }
    function isFlowToken(token) {
      switch (token?.type) {
        case "alias":
        case "scalar":
        case "single-quoted-scalar":
        case "double-quoted-scalar":
        case "flow-collection":
          return true;
        default:
          return false;
      }
    }
    function getPrevProps(parent) {
      switch (parent.type) {
        case "document":
          return parent.start;
        case "block-map": {
          const it = parent.items[parent.items.length - 1];
          return it.sep ?? it.start;
        }
        case "block-seq":
          return parent.items[parent.items.length - 1].start;
        /* istanbul ignore next should not happen */
        default:
          return [];
      }
    }
    function getFirstKeyStartProps(prev) {
      if (prev.length === 0)
        return [];
      let i = prev.length;
      loop: while (--i >= 0) {
        switch (prev[i].type) {
          case "doc-start":
          case "explicit-key-ind":
          case "map-value-ind":
          case "seq-item-ind":
          case "newline":
            break loop;
        }
      }
      while (prev[++i]?.type === "space") {
      }
      return prev.splice(i, prev.length);
    }
    function fixFlowSeqItems(fc) {
      if (fc.start.type === "flow-seq-start") {
        for (const it of fc.items) {
          if (it.sep && !it.value && !includesToken(it.start, "explicit-key-ind") && !includesToken(it.sep, "map-value-ind")) {
            if (it.key)
              it.value = it.key;
            delete it.key;
            if (isFlowToken(it.value)) {
              if (it.value.end)
                Array.prototype.push.apply(it.value.end, it.sep);
              else
                it.value.end = it.sep;
            } else
              Array.prototype.push.apply(it.start, it.sep);
            delete it.sep;
          }
        }
      }
    }
    var Parser = class {
      /**
       * @param onNewLine - If defined, called separately with the start position of
       *   each new line (in `parse()`, including the start of input).
       */
      constructor(onNewLine) {
        this.atNewLine = true;
        this.atScalar = false;
        this.indent = 0;
        this.offset = 0;
        this.onKeyLine = false;
        this.stack = [];
        this.source = "";
        this.type = "";
        this.lexer = new lexer.Lexer();
        this.onNewLine = onNewLine;
      }
      /**
       * Parse `source` as a YAML stream.
       * If `incomplete`, a part of the last line may be left as a buffer for the next call.
       *
       * Errors are not thrown, but yielded as `{ type: 'error', message }` tokens.
       *
       * @returns A generator of tokens representing each directive, document, and other structure.
       */
      *parse(source, incomplete = false) {
        if (this.onNewLine && this.offset === 0)
          this.onNewLine(0);
        for (const lexeme of this.lexer.lex(source, incomplete))
          yield* this.next(lexeme);
        if (!incomplete)
          yield* this.end();
      }
      /**
       * Advance the parser by the `source` of one lexical token.
       */
      *next(source) {
        this.source = source;
        
        if (this.atScalar) {
          this.atScalar = false;
          yield* this.step();
          this.offset += source.length;
          return;
        }
        const type = cst.tokenType(source);
        if (!type) {
          const message = `Not a YAML token: ${source}`;
          yield* this.pop({ type: "error", offset: this.offset, message, source });
          this.offset += source.length;
        } else if (type === "scalar") {
          this.atNewLine = false;
          this.atScalar = true;
          this.type = "scalar";
        } else {
          this.type = type;
          yield* this.step();
          switch (type) {
            case "newline":
              this.atNewLine = true;
              this.indent = 0;
              if (this.onNewLine)
                this.onNewLine(this.offset + source.length);
              break;
            case "space":
              if (this.atNewLine && source[0] === " ")
                this.indent += source.length;
              break;
            case "explicit-key-ind":
            case "map-value-ind":
            case "seq-item-ind":
              if (this.atNewLine)
                this.indent += source.length;
              break;
            case "doc-mode":
            case "flow-error-end":
              return;
            default:
              this.atNewLine = false;
          }
          this.offset += source.length;
        }
      }
      /** Call at end of input to push out any remaining constructions */
      *end() {
        while (this.stack.length > 0)
          yield* this.pop();
      }
      get sourceToken() {
        const st = {
          type: this.type,
          offset: this.offset,
          indent: this.indent,
          source: this.source
        };
        return st;
      }
      *step() {
        const top = this.peek(1);
        if (this.type === "doc-end" && top?.type !== "doc-end") {
          while (this.stack.length > 0)
            yield* this.pop();
          this.stack.push({
            type: "doc-end",
            offset: this.offset,
            source: this.source
          });
          return;
        }
        if (!top)
          return yield* this.stream();
        switch (top.type) {
          case "document":
            return yield* this.document(top);
          case "alias":
          case "scalar":
          case "single-quoted-scalar":
          case "double-quoted-scalar":
            return yield* this.scalar(top);
          case "block-scalar":
            return yield* this.blockScalar(top);
          case "block-map":
            return yield* this.blockMap(top);
          case "block-seq":
            return yield* this.blockSequence(top);
          case "flow-collection":
            return yield* this.flowCollection(top);
          case "doc-end":
            return yield* this.documentEnd(top);
        }
        yield* this.pop();
      }
      peek(n) {
        return this.stack[this.stack.length - n];
      }
      *pop(error) {
        const token = error ?? this.stack.pop();
        if (!token) {
          const message = "Tried to pop an empty stack";
          yield { type: "error", offset: this.offset, source: "", message };
        } else if (this.stack.length === 0) {
          yield token;
        } else {
          const top = this.peek(1);
          if (token.type === "block-scalar") {
            token.indent = "indent" in top ? top.indent : 0;
          } else if (token.type === "flow-collection" && top.type === "document") {
            token.indent = 0;
          }
          if (token.type === "flow-collection")
            fixFlowSeqItems(token);
          switch (top.type) {
            case "document":
              top.value = token;
              break;
            case "block-scalar":
              top.props.push(token);
              break;
            case "block-map": {
              const it = top.items[top.items.length - 1];
              if (it.value) {
                top.items.push({ start: [], key: token, sep: [] });
                this.onKeyLine = true;
                return;
              } else if (it.sep) {
                it.value = token;
              } else {
                Object.assign(it, { key: token, sep: [] });
                this.onKeyLine = !it.explicitKey;
                return;
              }
              break;
            }
            case "block-seq": {
              const it = top.items[top.items.length - 1];
              if (it.value)
                top.items.push({ start: [], value: token });
              else
                it.value = token;
              break;
            }
            case "flow-collection": {
              const it = top.items[top.items.length - 1];
              if (!it || it.value)
                top.items.push({ start: [], key: token, sep: [] });
              else if (it.sep)
                it.value = token;
              else
                Object.assign(it, { key: token, sep: [] });
              return;
            }
            /* istanbul ignore next should not happen */
            default:
              yield* this.pop();
              yield* this.pop(token);
          }
          if ((top.type === "document" || top.type === "block-map" || top.type === "block-seq") && (token.type === "block-map" || token.type === "block-seq")) {
            const last = token.items[token.items.length - 1];
            if (last && !last.sep && !last.value && last.start.length > 0 && findNonEmptyIndex(last.start) === -1 && (token.indent === 0 || last.start.every((st) => st.type !== "comment" || st.indent < token.indent))) {
              if (top.type === "document")
                top.end = last.start;
              else
                top.items.push({ start: last.start });
              token.items.splice(-1, 1);
            }
          }
        }
      }
      *stream() {
        switch (this.type) {
          case "directive-line":
            yield { type: "directive", offset: this.offset, source: this.source };
            return;
          case "byte-order-mark":
          case "space":
          case "comment":
          case "newline":
            yield this.sourceToken;
            return;
          case "doc-mode":
          case "doc-start": {
            const doc = {
              type: "document",
              offset: this.offset,
              start: []
            };
            if (this.type === "doc-start")
              doc.start.push(this.sourceToken);
            this.stack.push(doc);
            return;
          }
        }
        yield {
          type: "error",
          offset: this.offset,
          message: `Unexpected ${this.type} token in YAML stream`,
          source: this.source
        };
      }
      *document(doc) {
        if (doc.value)
          return yield* this.lineEnd(doc);
        switch (this.type) {
          case "doc-start": {
            if (findNonEmptyIndex(doc.start) !== -1) {
              yield* this.pop();
              yield* this.step();
            } else
              doc.start.push(this.sourceToken);
            return;
          }
          case "anchor":
          case "tag":
          case "space":
          case "comment":
          case "newline":
            doc.start.push(this.sourceToken);
            return;
        }
        const bv = this.startBlockValue(doc);
        if (bv)
          this.stack.push(bv);
        else {
          yield {
            type: "error",
            offset: this.offset,
            message: `Unexpected ${this.type} token in YAML document`,
            source: this.source
          };
        }
      }
      *scalar(scalar) {
        if (this.type === "map-value-ind") {
          const prev = getPrevProps(this.peek(2));
          const start = getFirstKeyStartProps(prev);
          let sep5;
          if (scalar.end) {
            sep5 = scalar.end;
            sep5.push(this.sourceToken);
            delete scalar.end;
          } else
            sep5 = [this.sourceToken];
          const map = {
            type: "block-map",
            offset: scalar.offset,
            indent: scalar.indent,
            items: [{ start, key: scalar, sep: sep5 }]
          };
          this.onKeyLine = true;
          this.stack[this.stack.length - 1] = map;
        } else
          yield* this.lineEnd(scalar);
      }
      *blockScalar(scalar) {
        switch (this.type) {
          case "space":
          case "comment":
          case "newline":
            scalar.props.push(this.sourceToken);
            return;
          case "scalar":
            scalar.source = this.source;
            this.atNewLine = true;
            this.indent = 0;
            if (this.onNewLine) {
              let nl = this.source.indexOf("\n") + 1;
              while (nl !== 0) {
                this.onNewLine(this.offset + nl);
                nl = this.source.indexOf("\n", nl) + 1;
              }
            }
            yield* this.pop();
            break;
          /* istanbul ignore next should not happen */
          default:
            yield* this.pop();
            yield* this.step();
        }
      }
      *blockMap(map) {
        const it = map.items[map.items.length - 1];
        switch (this.type) {
          case "newline":
            this.onKeyLine = false;
            if (it.value) {
              const end = "end" in it.value ? it.value.end : void 0;
              const last = Array.isArray(end) ? end[end.length - 1] : void 0;
              if (last?.type === "comment")
                end?.push(this.sourceToken);
              else
                map.items.push({ start: [this.sourceToken] });
            } else if (it.sep) {
              it.sep.push(this.sourceToken);
            } else {
              it.start.push(this.sourceToken);
            }
            return;
          case "space":
          case "comment":
            if (it.value) {
              map.items.push({ start: [this.sourceToken] });
            } else if (it.sep) {
              it.sep.push(this.sourceToken);
            } else {
              if (this.atIndentedComment(it.start, map.indent)) {
                const prev = map.items[map.items.length - 2];
                const end = prev?.value?.end;
                if (Array.isArray(end)) {
                  Array.prototype.push.apply(end, it.start);
                  end.push(this.sourceToken);
                  map.items.pop();
                  return;
                }
              }
              it.start.push(this.sourceToken);
            }
            return;
        }
        if (this.indent >= map.indent) {
          const atMapIndent = !this.onKeyLine && this.indent === map.indent;
          const atNextItem = atMapIndent && (it.sep || it.explicitKey) && this.type !== "seq-item-ind";
          let start = [];
          if (atNextItem && it.sep && !it.value) {
            const nl = [];
            for (let i = 0; i < it.sep.length; ++i) {
              const st = it.sep[i];
              switch (st.type) {
                case "newline":
                  nl.push(i);
                  break;
                case "space":
                  break;
                case "comment":
                  if (st.indent > map.indent)
                    nl.length = 0;
                  break;
                default:
                  nl.length = 0;
              }
            }
            if (nl.length >= 2)
              start = it.sep.splice(nl[1]);
          }
          switch (this.type) {
            case "anchor":
            case "tag":
              if (atNextItem || it.value) {
                start.push(this.sourceToken);
                map.items.push({ start });
                this.onKeyLine = true;
              } else if (it.sep) {
                it.sep.push(this.sourceToken);
              } else {
                it.start.push(this.sourceToken);
              }
              return;
            case "explicit-key-ind":
              if (!it.sep && !it.explicitKey) {
                it.start.push(this.sourceToken);
                it.explicitKey = true;
              } else if (atNextItem || it.value) {
                start.push(this.sourceToken);
                map.items.push({ start, explicitKey: true });
              } else {
                this.stack.push({
                  type: "block-map",
                  offset: this.offset,
                  indent: this.indent,
                  items: [{ start: [this.sourceToken], explicitKey: true }]
                });
              }
              this.onKeyLine = true;
              return;
            case "map-value-ind":
              if (it.explicitKey) {
                if (!it.sep) {
                  if (includesToken(it.start, "newline")) {
                    Object.assign(it, { key: null, sep: [this.sourceToken] });
                  } else {
                    const start2 = getFirstKeyStartProps(it.start);
                    this.stack.push({
                      type: "block-map",
                      offset: this.offset,
                      indent: this.indent,
                      items: [{ start: start2, key: null, sep: [this.sourceToken] }]
                    });
                  }
                } else if (it.value) {
                  map.items.push({ start: [], key: null, sep: [this.sourceToken] });
                } else if (includesToken(it.sep, "map-value-ind")) {
                  this.stack.push({
                    type: "block-map",
                    offset: this.offset,
                    indent: this.indent,
                    items: [{ start, key: null, sep: [this.sourceToken] }]
                  });
                } else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
                  const start2 = getFirstKeyStartProps(it.start);
                  const key = it.key;
                  const sep5 = it.sep;
                  sep5.push(this.sourceToken);
                  delete it.key;
                  delete it.sep;
                  this.stack.push({
                    type: "block-map",
                    offset: this.offset,
                    indent: this.indent,
                    items: [{ start: start2, key, sep: sep5 }]
                  });
                } else if (start.length > 0) {
                  it.sep = it.sep.concat(start, this.sourceToken);
                } else {
                  it.sep.push(this.sourceToken);
                }
              } else {
                if (!it.sep) {
                  Object.assign(it, { key: null, sep: [this.sourceToken] });
                } else if (it.value || atNextItem) {
                  map.items.push({ start, key: null, sep: [this.sourceToken] });
                } else if (includesToken(it.sep, "map-value-ind")) {
                  this.stack.push({
                    type: "block-map",
                    offset: this.offset,
                    indent: this.indent,
                    items: [{ start: [], key: null, sep: [this.sourceToken] }]
                  });
                } else {
                  it.sep.push(this.sourceToken);
                }
              }
              this.onKeyLine = true;
              return;
            case "alias":
            case "scalar":
            case "single-quoted-scalar":
            case "double-quoted-scalar": {
              const fs2 = this.flowScalar(this.type);
              if (atNextItem || it.value) {
                map.items.push({ start, key: fs2, sep: [] });
                this.onKeyLine = true;
              } else if (it.sep) {
                this.stack.push(fs2);
              } else {
                Object.assign(it, { key: fs2, sep: [] });
                this.onKeyLine = true;
              }
              return;
            }
            default: {
              const bv = this.startBlockValue(map);
              if (bv) {
                if (bv.type === "block-seq") {
                  if (!it.explicitKey && it.sep && !includesToken(it.sep, "newline")) {
                    yield* this.pop({
                      type: "error",
                      offset: this.offset,
                      message: "Unexpected block-seq-ind on same line with key",
                      source: this.source
                    });
                    return;
                  }
                } else if (atMapIndent) {
                  map.items.push({ start });
                }
                this.stack.push(bv);
                return;
              }
            }
          }
        }
        yield* this.pop();
        yield* this.step();
      }
      *blockSequence(seq) {
        const it = seq.items[seq.items.length - 1];
        switch (this.type) {
          case "newline":
            if (it.value) {
              const end = "end" in it.value ? it.value.end : void 0;
              const last = Array.isArray(end) ? end[end.length - 1] : void 0;
              if (last?.type === "comment")
                end?.push(this.sourceToken);
              else
                seq.items.push({ start: [this.sourceToken] });
            } else
              it.start.push(this.sourceToken);
            return;
          case "space":
          case "comment":
            if (it.value)
              seq.items.push({ start: [this.sourceToken] });
            else {
              if (this.atIndentedComment(it.start, seq.indent)) {
                const prev = seq.items[seq.items.length - 2];
                const end = prev?.value?.end;
                if (Array.isArray(end)) {
                  Array.prototype.push.apply(end, it.start);
                  end.push(this.sourceToken);
                  seq.items.pop();
                  return;
                }
              }
              it.start.push(this.sourceToken);
            }
            return;
          case "anchor":
          case "tag":
            if (it.value || this.indent <= seq.indent)
              break;
            it.start.push(this.sourceToken);
            return;
          case "seq-item-ind":
            if (this.indent !== seq.indent)
              break;
            if (it.value || includesToken(it.start, "seq-item-ind"))
              seq.items.push({ start: [this.sourceToken] });
            else
              it.start.push(this.sourceToken);
            return;
        }
        if (this.indent > seq.indent) {
          const bv = this.startBlockValue(seq);
          if (bv) {
            this.stack.push(bv);
            return;
          }
        }
        yield* this.pop();
        yield* this.step();
      }
      *flowCollection(fc) {
        const it = fc.items[fc.items.length - 1];
        if (this.type === "flow-error-end") {
          let top;
          do {
            yield* this.pop();
            top = this.peek(1);
          } while (top?.type === "flow-collection");
        } else if (fc.end.length === 0) {
          switch (this.type) {
            case "comma":
            case "explicit-key-ind":
              if (!it || it.sep)
                fc.items.push({ start: [this.sourceToken] });
              else
                it.start.push(this.sourceToken);
              return;
            case "map-value-ind":
              if (!it || it.value)
                fc.items.push({ start: [], key: null, sep: [this.sourceToken] });
              else if (it.sep)
                it.sep.push(this.sourceToken);
              else
                Object.assign(it, { key: null, sep: [this.sourceToken] });
              return;
            case "space":
            case "comment":
            case "newline":
            case "anchor":
            case "tag":
              if (!it || it.value)
                fc.items.push({ start: [this.sourceToken] });
              else if (it.sep)
                it.sep.push(this.sourceToken);
              else
                it.start.push(this.sourceToken);
              return;
            case "alias":
            case "scalar":
            case "single-quoted-scalar":
            case "double-quoted-scalar": {
              const fs2 = this.flowScalar(this.type);
              if (!it || it.value)
                fc.items.push({ start: [], key: fs2, sep: [] });
              else if (it.sep)
                this.stack.push(fs2);
              else
                Object.assign(it, { key: fs2, sep: [] });
              return;
            }
            case "flow-map-end":
            case "flow-seq-end":
              fc.end.push(this.sourceToken);
              return;
          }
          const bv = this.startBlockValue(fc);
          if (bv)
            this.stack.push(bv);
          else {
            yield* this.pop();
            yield* this.step();
          }
        } else {
          const parent = this.peek(2);
          if (parent.type === "block-map" && (this.type === "map-value-ind" && parent.indent === fc.indent || this.type === "newline" && !parent.items[parent.items.length - 1].sep)) {
            yield* this.pop();
            yield* this.step();
          } else if (this.type === "map-value-ind" && parent.type !== "flow-collection") {
            const prev = getPrevProps(parent);
            const start = getFirstKeyStartProps(prev);
            fixFlowSeqItems(fc);
            const sep5 = fc.end.splice(1, fc.end.length);
            sep5.push(this.sourceToken);
            const map = {
              type: "block-map",
              offset: fc.offset,
              indent: fc.indent,
              items: [{ start, key: fc, sep: sep5 }]
            };
            this.onKeyLine = true;
            this.stack[this.stack.length - 1] = map;
          } else {
            yield* this.lineEnd(fc);
          }
        }
      }
      flowScalar(type) {
        if (this.onNewLine) {
          let nl = this.source.indexOf("\n") + 1;
          while (nl !== 0) {
            this.onNewLine(this.offset + nl);
            nl = this.source.indexOf("\n", nl) + 1;
          }
        }
        return {
          type,
          offset: this.offset,
          indent: this.indent,
          source: this.source
        };
      }
      startBlockValue(parent) {
        switch (this.type) {
          case "alias":
          case "scalar":
          case "single-quoted-scalar":
          case "double-quoted-scalar":
            return this.flowScalar(this.type);
          case "block-scalar-header":
            return {
              type: "block-scalar",
              offset: this.offset,
              indent: this.indent,
              props: [this.sourceToken],
              source: ""
            };
          case "flow-map-start":
          case "flow-seq-start":
            return {
              type: "flow-collection",
              offset: this.offset,
              indent: this.indent,
              start: this.sourceToken,
              items: [],
              end: []
            };
          case "seq-item-ind":
            return {
              type: "block-seq",
              offset: this.offset,
              indent: this.indent,
              items: [{ start: [this.sourceToken] }]
            };
          case "explicit-key-ind": {
            this.onKeyLine = true;
            const prev = getPrevProps(parent);
            const start = getFirstKeyStartProps(prev);
            start.push(this.sourceToken);
            return {
              type: "block-map",
              offset: this.offset,
              indent: this.indent,
              items: [{ start, explicitKey: true }]
            };
          }
          case "map-value-ind": {
            this.onKeyLine = true;
            const prev = getPrevProps(parent);
            const start = getFirstKeyStartProps(prev);
            return {
              type: "block-map",
              offset: this.offset,
              indent: this.indent,
              items: [{ start, key: null, sep: [this.sourceToken] }]
            };
          }
        }
        return null;
      }
      atIndentedComment(start, indent) {
        if (this.type !== "comment")
          return false;
        if (this.indent <= indent)
          return false;
        return start.every((st) => st.type === "newline" || st.type === "space");
      }
      *documentEnd(docEnd) {
        if (this.type !== "doc-mode") {
          if (docEnd.end)
            docEnd.end.push(this.sourceToken);
          else
            docEnd.end = [this.sourceToken];
          if (this.type === "newline")
            yield* this.pop();
        }
      }
      *lineEnd(token) {
        switch (this.type) {
          case "comma":
          case "doc-start":
          case "doc-end":
          case "flow-seq-end":
          case "flow-map-end":
          case "map-value-ind":
            yield* this.pop();
            yield* this.step();
            break;
          case "newline":
            this.onKeyLine = false;
          // fallthrough
          case "space":
          case "comment":
          default:
            if (token.end)
              token.end.push(this.sourceToken);
            else
              token.end = [this.sourceToken];
            if (this.type === "newline")
              yield* this.pop();
        }
      }
    };
    exports2.Parser = Parser;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/public-api.js
var require_public_api = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/public-api.js"(exports2) {
    "use strict";
    var composer = require_composer();
    var Document = require_Document();
    var errors = require_errors();
    var log = require_log();
    var identity = require_identity();
    var lineCounter = require_line_counter();
    var parser = require_parser();
    function parseOptions(options) {
      const prettyErrors = options.prettyErrors !== false;
      const lineCounter$1 = options.lineCounter || prettyErrors && new lineCounter.LineCounter() || null;
      return { lineCounter: lineCounter$1, prettyErrors };
    }
    function parseAllDocuments(source, options = {}) {
      const { lineCounter: lineCounter2, prettyErrors } = parseOptions(options);
      const parser$1 = new parser.Parser(lineCounter2?.addNewLine);
      const composer$1 = new composer.Composer(options);
      const docs = Array.from(composer$1.compose(parser$1.parse(source)));
      if (prettyErrors && lineCounter2)
        for (const doc of docs) {
          doc.errors.forEach(errors.prettifyError(source, lineCounter2));
          doc.warnings.forEach(errors.prettifyError(source, lineCounter2));
        }
      if (docs.length > 0)
        return docs;
      return Object.assign([], { empty: true }, composer$1.streamInfo());
    }
    function parseDocument(source, options = {}) {
      const { lineCounter: lineCounter2, prettyErrors } = parseOptions(options);
      const parser$1 = new parser.Parser(lineCounter2?.addNewLine);
      const composer$1 = new composer.Composer(options);
      let doc = null;
      for (const _doc of composer$1.compose(parser$1.parse(source), true, source.length)) {
        if (!doc)
          doc = _doc;
        else if (doc.options.logLevel !== "silent") {
          doc.errors.push(new errors.YAMLParseError(_doc.range.slice(0, 2), "MULTIPLE_DOCS", "Source contains multiple documents; please use YAML.parseAllDocuments()"));
          break;
        }
      }
      if (prettyErrors && lineCounter2) {
        doc.errors.forEach(errors.prettifyError(source, lineCounter2));
        doc.warnings.forEach(errors.prettifyError(source, lineCounter2));
      }
      return doc;
    }
    function parse(src, reviver, options) {
      let _reviver = void 0;
      if (typeof reviver === "function") {
        _reviver = reviver;
      } else if (options === void 0 && reviver && typeof reviver === "object") {
        options = reviver;
      }
      const doc = parseDocument(src, options);
      if (!doc)
        return null;
      doc.warnings.forEach((warning) => log.warn(doc.options.logLevel, warning));
      if (doc.errors.length > 0) {
        if (doc.options.logLevel !== "silent")
          throw doc.errors[0];
        else
          doc.errors = [];
      }
      return doc.toJS(Object.assign({ reviver: _reviver }, options));
    }
    function stringify(value, replacer, options) {
      let _replacer = null;
      if (typeof replacer === "function" || Array.isArray(replacer)) {
        _replacer = replacer;
      } else if (options === void 0 && replacer) {
        options = replacer;
      }
      if (typeof options === "string")
        options = options.length;
      if (typeof options === "number") {
        const indent = Math.round(options);
        options = indent < 1 ? void 0 : indent > 8 ? { indent: 8 } : { indent };
      }
      if (value === void 0) {
        const { keepUndefined } = options ?? replacer ?? {};
        if (!keepUndefined)
          return void 0;
      }
      if (identity.isDocument(value) && !_replacer)
        return value.toString(options);
      return new Document.Document(value, _replacer, options).toString(options);
    }
    exports2.parse = parse;
    exports2.parseAllDocuments = parseAllDocuments;
    exports2.parseDocument = parseDocument;
    exports2.stringify = stringify;
  }
});

// ../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/index.js
var require_dist = __commonJS({
  "../../node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/index.js"(exports2) {
    "use strict";
    var composer = require_composer();
    var Document = require_Document();
    var Schema = require_Schema();
    var errors = require_errors();
    var Alias = require_Alias();
    var identity = require_identity();
    var Pair = require_Pair();
    var Scalar = require_Scalar();
    var YAMLMap = require_YAMLMap();
    var YAMLSeq = require_YAMLSeq();
    var cst = require_cst();
    var lexer = require_lexer();
    var lineCounter = require_line_counter();
    var parser = require_parser();
    var publicApi = require_public_api();
    var visit = require_visit();
    exports2.Composer = composer.Composer;
    exports2.Document = Document.Document;
    exports2.Schema = Schema.Schema;
    exports2.YAMLError = errors.YAMLError;
    exports2.YAMLParseError = errors.YAMLParseError;
    exports2.YAMLWarning = errors.YAMLWarning;
    exports2.Alias = Alias.Alias;
    exports2.isAlias = identity.isAlias;
    exports2.isCollection = identity.isCollection;
    exports2.isDocument = identity.isDocument;
    exports2.isMap = identity.isMap;
    exports2.isNode = identity.isNode;
    exports2.isPair = identity.isPair;
    exports2.isScalar = identity.isScalar;
    exports2.isSeq = identity.isSeq;
    exports2.Pair = Pair.Pair;
    exports2.Scalar = Scalar.Scalar;
    exports2.YAMLMap = YAMLMap.YAMLMap;
    exports2.YAMLSeq = YAMLSeq.YAMLSeq;
    exports2.CST = cst;
    exports2.Lexer = lexer.Lexer;
    exports2.LineCounter = lineCounter.LineCounter;
    exports2.Parser = parser.Parser;
    exports2.parse = publicApi.parse;
    exports2.parseAllDocuments = publicApi.parseAllDocuments;
    exports2.parseDocument = publicApi.parseDocument;
    exports2.stringify = publicApi.stringify;
    exports2.visit = visit.visit;
    exports2.visitAsync = visit.visitAsync;
  }
});

// src/index.ts
var index_exports = {};
__export(index_exports, {
  default: () => index_default
});
module.exports = __toCommonJS(index_exports);

// ../core/dist/allowlist-migration.js
var import_node_path3 = require("node:path");

// ../core/dist/brands.js
var defaultBranding = { name: "Sage", short_name: "Sage" };
var BRANDS = {
  norton: { name: "Norton AI Agent Protection", short_name: "Norton" }
};
function resolveBranding(brandKey, logger) {
  if (!brandKey)
    return defaultBranding;
  const entry = BRANDS[brandKey];
  if (!entry) {
    logger?.warn(`Unknown brand_key "${brandKey}" in config - using default branding`);
    return defaultBranding;
  }
  return { ...entry, brand_key: brandKey };
}

// ../core/dist/allowlist-migration.js
init_config();
init_file_utils();
function defaultAllowlistPath() {
  return (0, import_node_path3.join)(resolvePath("~/.sage"), "allowlist.json");
}
async function checkAllowlistMigration() {
  try {
    const raw = await getFileContent(defaultAllowlistPath());
    const data = JSON.parse(raw);
    if (typeof data !== "object" || data === null || Array.isArray(data)) {
      return { needed: false, entryTypes: [] };
    }
    const record = data;
    const found = ["urls", "commands", "file_paths"].filter((key) => typeof record[key] === "object" && record[key] !== null && Object.keys(record[key]).length > 0);
    return { needed: found.length > 0, entryTypes: found };
  } catch {
    return { needed: false, entryTypes: [] };
  }
}
function formatAllowlistMigrationWarning(entryTypes, branding2 = defaultBranding) {
  const typeList = entryTypes.join(", ");
  const lines = [
    `${branding2.name}: legacy allowlist.json detected with ${typeList} entries.`,
    "  - URL and file_path entries can be migrated manually to ~/.sage/exceptions.json",
    "  - Command entries are stored as SHA-256 hashes and cannot be recovered",
    "  - See https://github.com/gendigitalinc/sage for migration instructions"
  ];
  return lines.join("\n");
}

// ../core/dist/approval-store.js
var import_node_crypto2 = require("node:crypto");
var PENDING_STALE_MS = 60 * 60 * 1e3;
var APPROVED_TTL_MS = 10 * 60 * 1e3;
var ApprovalStore = class {
  pending = /* @__PURE__ */ new Map();
  approved = /* @__PURE__ */ new Map();
  static actionId(toolName, params, sessionId) {
    const payload = JSON.stringify({ toolName, params, sessionId });
    return (0, import_node_crypto2.createHash)("sha256").update(payload).digest("hex").slice(0, 32);
  }
  static artifactId(type, value) {
    return `${type}:${value}`;
  }
  setPending(actionId, entry) {
    this.pending.set(actionId, { ...entry, artifacts: [...entry.artifacts] });
  }
  getPending(actionId) {
    return this.pending.get(actionId) ?? null;
  }
  deletePending(actionId) {
    this.pending.delete(actionId);
  }
  approve(actionId) {
    const entry = this.pending.get(actionId);
    if (!entry)
      return null;
    const now = Date.now();
    this.approved.set(actionId, {
      artifacts: [...entry.artifacts],
      approvedAt: now,
      expiresAt: now + APPROVED_TTL_MS
    });
    this.pending.delete(actionId);
    return entry;
  }
  isApproved(actionId) {
    const entry = this.approved.get(actionId);
    if (!entry)
      return false;
    if (Date.now() >= entry.expiresAt) {
      this.approved.delete(actionId);
      return false;
    }
    return true;
  }
  cleanup(now = Date.now()) {
    for (const [actionId, entry] of this.pending.entries()) {
      if (now - entry.createdAt >= PENDING_STALE_MS) {
        this.pending.delete(actionId);
      }
    }
    for (const [actionId, entry] of this.approved.entries()) {
      if (now >= entry.expiresAt) {
        this.approved.delete(actionId);
      }
    }
  }
};

// ../core/dist/audit-log.js
var import_node_crypto3 = require("node:crypto");
init_config();

// ../core/dist/content-snapshot.js
var import_node_os2 = require("node:os");
var CONTENT_FIELD_LIMITS = Object.freeze({
  command: 512,
  url: 512,
  file_path: 512,
  package_name: 256,
  package_version: 128,
  package_registry: 128
});
function safeTruncate(value, maxLen) {
  if (maxLen <= 0)
    return "";
  if (value.length <= maxLen)
    return value;
  const cutIndex = maxLen;
  const codeUnit = value.charCodeAt(cutIndex - 1);
  if (codeUnit >= 55296 && codeUnit <= 56319) {
    return value.slice(0, cutIndex - 1);
  }
  return value.slice(0, cutIndex);
}
function scrubHomePath(value) {
  const home = (0, import_node_os2.homedir)();
  if (!home)
    return value;
  const normalizedHome = home.replace(/\\/g, "/").replace(/\/+$/, "");
  if (!normalizedHome)
    return value;
  const normalizedValue = value.replace(/\\/g, "/");
  if (normalizedValue === normalizedHome)
    return "~";
  if (normalizedValue.startsWith(`${normalizedHome}/`)) {
    return `~/${normalizedValue.slice(normalizedHome.length + 1)}`;
  }
  return value;
}
function asString(v) {
  return typeof v === "string" && v.length > 0 ? v : void 0;
}
function resolveFilePath(toolInput) {
  return asString(toolInput.file_path) ?? asString(toolInput.filePath) ?? asString(toolInput.path);
}
function resolveWebFetchUrl(toolInput) {
  const single = asString(toolInput.url);
  if (single)
    return single;
  const urls = toolInput.urls;
  if (Array.isArray(urls)) {
    for (const u of urls) {
      if (typeof u === "string" && u.length > 0)
        return u;
    }
  }
  return void 0;
}
function extractFirstApplyPatchPath(patchText) {
  if (!patchText)
    return void 0;
  const headerMatch = /\*{3}\s+(?:Add|Update|Delete)\s+File:\s*(.+)/.exec(patchText);
  if (headerMatch?.[1]) {
    const trimmed = headerMatch[1].trim();
    if (trimmed)
      return trimmed;
  }
  const renameMatch = /\*{3}\s+(?:Move\s+to|Rename\s+File):\s*(.+)/i.exec(patchText);
  if (renameMatch?.[1]) {
    const raw = renameMatch[1].trim();
    const arrow = raw.indexOf(" -> ");
    if (arrow !== -1) {
      const src = raw.slice(0, arrow).trim();
      if (src)
        return src;
      const dst = raw.slice(arrow + 4).trim();
      if (dst)
        return dst;
    } else if (raw) {
      return raw;
    }
  }
  return void 0;
}
function extractMcpContent(toolInput) {
  const nestedRaw = toolInput.tool_input ?? toolInput.toolInput;
  const candidate = nestedRaw && typeof nestedRaw === "object" && !Array.isArray(nestedRaw) ? nestedRaw : toolInput;
  return {
    command: asString(candidate.command),
    url: asString(candidate.url) ?? resolveWebFetchUrl(candidate),
    file_path: resolveFilePath(candidate)
  };
}
function firstUrlArtifact(artifacts) {
  for (const a of artifacts) {
    if (a.type === "url" && typeof a.value === "string" && a.value.length > 0) {
      return a.value;
    }
  }
  return void 0;
}
function applyFieldLimits(content) {
  for (const [key, value] of Object.entries(content)) {
    if (typeof value !== "string")
      continue;
    let sanitized = value;
    if (key === "file_path" || key === "command") {
      sanitized = scrubHomePath(sanitized);
    }
    const limit = CONTENT_FIELD_LIMITS[key];
    if (limit && sanitized.length > limit) {
      sanitized = safeTruncate(sanitized, limit);
    }
    content[key] = sanitized;
  }
}
function buildContentSnapshot(toolType, toolInput, artifacts = [], signals = {}) {
  const content = {};
  switch (toolType) {
    case "Bash": {
      const command = asString(toolInput.command);
      if (command)
        content.command = command;
      break;
    }
    case "WebFetch": {
      const url = resolveWebFetchUrl(toolInput) ?? firstUrlArtifact(artifacts);
      if (url)
        content.url = url;
      break;
    }
    case "Write":
    case "Edit":
    case "Read":
    case "Delete": {
      const filePath = resolveFilePath(toolInput);
      if (filePath)
        content.file_path = filePath;
      break;
    }
    case "ApplyPatch": {
      const patchText = asString(toolInput.input) ?? asString(toolInput.patch) ?? "";
      const filePath = extractFirstApplyPatchPath(patchText);
      if (filePath)
        content.file_path = filePath;
      break;
    }
    case "MCP": {
      const mcp = extractMcpContent(toolInput);
      if (mcp.command)
        content.command = mcp.command;
      if (mcp.url)
        content.url = mcp.url;
      if (mcp.file_path)
        content.file_path = mcp.file_path;
      break;
    }
  }
  if (!content.url && signals.url_checks && signals.url_checks.length > 0) {
    const firstUrl = signals.url_checks[0]?.url;
    if (firstUrl)
      content.url = firstUrl;
  }
  if (signals.package_checks && signals.package_checks.length > 0) {
    const p = signals.package_checks[0];
    if (p?.package_name)
      content.package_name = p.package_name;
    if (p?.package_version)
      content.package_version = p.package_version;
    if (p?.package_registry)
      content.package_registry = p.package_registry;
  }
  applyFieldLimits(content);
  return content;
}

// ../core/dist/audit-log.js
init_file_utils();

// ../core/dist/jsonl-log-writer.js
var import_promises2 = require("node:fs/promises");
var import_node_path4 = require("node:path");
init_config();
init_file_utils();
var writeQueues = /* @__PURE__ */ new Map();
async function shouldRotate(filePath, maxBytes, maxFiles) {
  if (maxBytes <= 0 || maxFiles <= 0)
    return false;
  try {
    const s = await (0, import_promises2.stat)(filePath);
    return s.size >= maxBytes;
  } catch {
    return false;
  }
}
async function rotateIfNeeded(filePath, maxBytes, maxFiles) {
  if (!await shouldRotate(filePath, maxBytes, maxFiles))
    return;
  await withFileLock(filePath, async () => {
    if (!await shouldRotate(filePath, maxBytes, maxFiles))
      return;
    try {
      await (0, import_promises2.unlink)(`${filePath}.${maxFiles}`);
    } catch {
    }
    for (let i = maxFiles - 1; i >= 1; i--) {
      try {
        await (0, import_promises2.rename)(`${filePath}.${i}`, `${filePath}.${i + 1}`);
      } catch {
      }
    }
    try {
      await (0, import_promises2.rename)(filePath, `${filePath}.1`);
    } catch {
    }
  });
}
async function appendJsonlEntryNow(path, config2, entry) {
  await (0, import_promises2.mkdir)((0, import_node_path4.dirname)(path), { recursive: true });
  await rotateIfNeeded(path, config2.max_bytes, config2.max_files);
  await (0, import_promises2.appendFile)(path, `${JSON.stringify(entry)}
`);
}
async function appendJsonlEntry(config2, entry) {
  const path = resolvePath(config2.path);
  const previousWrite = writeQueues.get(path) ?? Promise.resolve();
  const nextWrite = previousWrite.catch(() => {
  }).then(() => appendJsonlEntryNow(path, config2, entry));
  writeQueues.set(path, nextWrite);
  try {
    await nextWrite;
  } finally {
    if (writeQueues.get(path) === nextWrite)
      writeQueues.delete(path);
  }
}

// ../core/dist/audit-log.js
init_types2();
var MAX_SUMMARY_LEN = 200;
var AUDIT_LOG_SCHEMA_VERSION = 1;
function toolInputSummary(toolName, toolInput) {
  if (toolName === "Bash") {
    return String(toolInput.command ?? "").slice(0, MAX_SUMMARY_LEN);
  }
  if (toolName === "WebFetch") {
    return String(toolInput.url ?? "").slice(0, MAX_SUMMARY_LEN);
  }
  if (toolName === "Write" || toolName === "Edit" || toolName === "Read" || toolName === "Delete") {
    return String(toolInput.file_path ?? "").slice(0, MAX_SUMMARY_LEN);
  }
  return JSON.stringify(toolInput).slice(0, MAX_SUMMARY_LEN);
}
async function appendEntry(config2, entry) {
  const stamped = { ...entry, schema_version: AUDIT_LOG_SCHEMA_VERSION };
  await appendJsonlEntry(config2, stamped);
}
async function logVerdict(config2, input) {
  if (!config2.enabled)
    return;
  const userOverride = input.userOverride ?? false;
  const hasSignals = input.signals != null && Object.keys(input.signals).length > 0;
  if (input.verdict.decision === "allow" && !config2.log_clean && !userOverride && !hasSignals)
    return;
  const entry = {
    type: "runtime_verdict",
    entry_id: input.eventId ?? (0, import_node_crypto3.randomUUID)(),
    timestamp: (/* @__PURE__ */ new Date()).toISOString(),
    session_id: input.sessionId,
    conversation_id: input.conversationId ?? input.sessionId,
    agent_runtime: input.agentRuntime,
    hook_type: input.hookType,
    tool_name: input.toolName,
    tool_input_summary: toolInputSummary(input.toolName, input.toolInput),
    artifacts: input.verdict.artifacts,
    verdict: input.verdict.decision,
    severity: input.verdict.severity,
    reasons: input.verdict.reasons,
    source: input.verdict.source,
    user_override: userOverride,
    signals: input.signals,
    tool_use_id: input.toolUseId
  };
  if (input.content !== void 0) {
    entry.content = input.content;
  }
  try {
    await appendEntry(config2, entry);
  } catch {
  }
}
async function logPluginScan(config2, pluginKey, pluginVersion, findings) {
  if (!config2.enabled)
    return;
  const entry = {
    type: "plugin_scan",
    timestamp: (/* @__PURE__ */ new Date()).toISOString(),
    plugin_key: pluginKey,
    plugin_version: pluginVersion,
    findings_count: findings.length,
    findings
  };
  try {
    await appendEntry(config2, entry);
  } catch {
  }
}
async function logSkillQueued(config2, skillId, pluginKey, skillFolder) {
  if (!config2.enabled)
    return;
  try {
    await appendEntry(config2, {
      type: "skill_queued",
      timestamp: (/* @__PURE__ */ new Date()).toISOString(),
      skill_id: skillId,
      plugin_key: pluginKey,
      // Home-scrubbed folder path: aids forensics when the same skill id shows
      // up under multiple plugins. Omitted when the caller has no path.
      ...skillFolder ? { skill_folder: scrubHomePath(skillFolder) } : {}
    });
  } catch {
  }
}

// ../core/dist/cache.js
init_config();
init_file_utils();
init_types2();

// ../core/dist/url-utils.js
init_file_utils();
function normalizeUrl(raw) {
  try {
    const u = new URL(raw);
    u.hash = "";
    u.searchParams.sort();
    return u.toString();
  } catch {
    return raw.toLowerCase();
  }
}

// ../core/dist/cache.js
var ONE_HOUR = 3600;
var TWENTY_FOUR_HOURS = 86400;
var VerdictCache = class {
  store = { urls: {}, packages: {} };
  path;
  config;
  logger;
  version;
  constructor(config2, logger = nullLogger, version) {
    this.config = config2;
    this.logger = logger;
    this.path = resolvePath(config2.path);
    this.version = version;
  }
  async load() {
    if (!this.config.enabled)
      return;
    try {
      const raw = await getFileContent(this.path);
      const data = JSON.parse(raw);
      this.store = {
        urls: data.urls ?? {},
        packages: data.packages ?? {}
      };
    } catch {
      this.store = { urls: {}, packages: {} };
    }
  }
  getUrl(url) {
    if (!this.config.enabled)
      return null;
    const key = normalizeUrl(url);
    const entry = this.store.urls[key];
    if (!entry || this.isStale(entry))
      return null;
    return {
      verdict: entry.verdict,
      severity: entry.severity,
      reasons: entry.reasons,
      source: entry.source,
      ...entry.urlSignalLabels !== void 0 ? { urlSignalLabels: entry.urlSignalLabels } : {}
    };
  }
  putUrl(url, verdict, isMalicious) {
    if (!this.config.enabled)
      return;
    const key = normalizeUrl(url);
    const now = /* @__PURE__ */ new Date();
    const ttl = isMalicious ? this.config.ttl_malicious_seconds : this.config.ttl_clean_seconds;
    const expiresAt = new Date(now.getTime() + ttl * 1e3);
    this.store.urls[key] = {
      ...verdict,
      checkedAt: now.toISOString(),
      expiresAt: expiresAt.toISOString(),
      sageVersion: this.version
    };
  }
  getPackage(key) {
    if (!this.config.enabled)
      return null;
    const entry = this.store.packages[key];
    if (!entry || this.isStale(entry))
      return null;
    return {
      verdict: entry.verdict,
      severity: entry.severity,
      reasons: entry.reasons,
      source: entry.source,
      ...entry.packageVerdict !== void 0 ? { packageVerdict: entry.packageVerdict } : {},
      ...entry.packageConfidence !== void 0 ? { packageConfidence: entry.packageConfidence } : {}
    };
  }
  putPackage(key, verdict, packageAgeDays) {
    if (!this.config.enabled)
      return;
    const { urlSignalLabels: _ignoredUrlLabels, ...rest } = verdict;
    const ttlSeconds = this.computePackageTtl(verdict.verdict, packageAgeDays);
    const now = /* @__PURE__ */ new Date();
    const expiresAt = new Date(now.getTime() + ttlSeconds * 1e3);
    this.store.packages[key] = {
      ...rest,
      checkedAt: now.toISOString(),
      expiresAt: expiresAt.toISOString(),
      sageVersion: this.version
    };
  }
  isStale(entry) {
    if (new Date(entry.expiresAt).getTime() <= Date.now())
      return true;
    if (this.version && this.version !== "dev" && entry.sageVersion !== this.version)
      return true;
    return false;
  }
  computePackageTtl(verdict, packageAgeDays) {
    const isFresh = packageAgeDays !== null && packageAgeDays < 7;
    switch (verdict) {
      case "deny":
        return TWENTY_FOUR_HOURS;
      case "allow":
        return isFresh ? ONE_HOUR : TWENTY_FOUR_HOURS;
      default:
        return ONE_HOUR;
    }
  }
  async save() {
    if (!this.config.enabled)
      return;
    try {
      this.pruneStaleEntries();
      await atomicWriteJson(this.path, this.store);
    } catch (e) {
      this.logger.warn(`Failed to save cache to ${this.path}`, { error: String(e) });
    }
  }
  pruneStaleEntries() {
    for (const [key, entry] of Object.entries(this.store.urls)) {
      if (this.isStale(entry))
        delete this.store.urls[key];
    }
    for (const [key, entry] of Object.entries(this.store.packages)) {
      if (this.isStale(entry))
        delete this.store.packages[key];
    }
  }
};

// ../core/dist/clients/amsi.js
init_types2();

// ../core/dist/clients/amsi-spawn.js
var chldproc1 = "node:child_";
var chldproc2 = "process";
var chldproc = require(chldproc1 + chldproc2);
function spawn(command, args, options) {
  return chldproc.spawn(command, args, options);
}

// ../core/dist/clients/amsi.js
var AMSI_RESULT_DETECTED = 32768;
var AMSI_RESULT_BLOCKED_BY_ADMIN_START = 16384;
var MAX_SCAN_LENGTH = 1048576;
var PS_TIMEOUT = 15e3;
function isWSL() {
  if (process.platform !== "linux")
    return false;
  return !!process["env"]["WSL_DISTRO_NAME"];
}
function isAmsiSupported() {
  return process.platform === "win32" || isWSL();
}
function interpretAmsiResult(amsiResult, content, contentName) {
  return {
    content: content.length > 200 ? `${content.slice(0, 200)}...` : content,
    contentName,
    amsiResult,
    isDetected: amsiResult >= AMSI_RESULT_DETECTED,
    isBlockedByAdmin: amsiResult >= AMSI_RESULT_BLOCKED_BY_ADMIN_START && amsiResult < AMSI_RESULT_DETECTED
  };
}
var KoffiAmsiBackend = class {
  logger;
  context = null;
  available = false;
  /** Koffi library handle — must be closed to let the event loop drain. */
  /* biome-ignore lint/suspicious/noExplicitAny: koffi Library type is not exported */
  lib = null;
  /* biome-ignore lint/suspicious/noExplicitAny: koffi FFI functions have dynamic signatures */
  fnOpenSession = null;
  /* biome-ignore lint/suspicious/noExplicitAny: koffi FFI functions have dynamic signatures */
  fnScanBuffer = null;
  /* biome-ignore lint/suspicious/noExplicitAny: koffi FFI functions have dynamic signatures */
  fnCloseSession = null;
  /* biome-ignore lint/suspicious/noExplicitAny: koffi FFI functions have dynamic signatures */
  fnUninitialize = null;
  constructor(logger) {
    this.logger = logger;
  }
  get isAvailable() {
    return this.available;
  }
  async init() {
    try {
      const koffiModule = await import("koffi");
      const koffi = koffiModule.default ?? koffiModule;
      const lib = koffi.load("amsi.dll");
      this.lib = lib;
      const _HAMSICONTEXT = koffi.pointer("HAMSICONTEXT", koffi.opaque());
      const _HAMSISESSION = koffi.pointer("HAMSISESSION", koffi.opaque());
      const AmsiInitialize = lib.func("int32 __stdcall AmsiInitialize(str16 appName, _Out_ HAMSICONTEXT *ctx)");
      this.fnOpenSession = lib.func("int32 __stdcall AmsiOpenSession(HAMSICONTEXT ctx, _Out_ HAMSISESSION *session)");
      this.fnScanBuffer = lib.func("int32 __stdcall AmsiScanBuffer(HAMSICONTEXT ctx, void *buf, uint32 len, str16 contentName, HAMSISESSION session, _Out_ int32 *result)");
      this.fnCloseSession = lib.func("void __stdcall AmsiCloseSession(HAMSICONTEXT ctx, HAMSISESSION session)");
      this.fnUninitialize = lib.func("void __stdcall AmsiUninitialize(HAMSICONTEXT ctx)");
      const ctxOut = [null];
      const hr = AmsiInitialize("Sage", ctxOut);
      if (hr !== 0) {
        this.logger.warn("AMSI: koffi AmsiInitialize failed", { hr });
        this.close();
        return;
      }
      this.context = ctxOut[0];
      const sessOut = [null];
      const hr2 = this.fnOpenSession(this.context, sessOut);
      if (hr2 !== 0) {
        this.logger.warn("AMSI: koffi AmsiOpenSession failed", { hr: hr2 });
        this.close();
        return;
      }
      try {
        this.fnCloseSession(this.context, sessOut[0]);
      } catch {
      }
      this.available = true;
      this.logger.debug("AMSI: koffi backend initialized");
    } catch (e) {
      this.logger.debug("AMSI: koffi backend init failed", { error: String(e) });
      this.close();
    }
  }
  async scanString(content, contentName) {
    if (!this.available || !this.fnOpenSession || !this.fnScanBuffer || !this.context) {
      return null;
    }
    const sessOut = [null];
    const hrOpen = this.fnOpenSession(this.context, sessOut);
    if (hrOpen !== 0) {
      this.logger.warn("AMSI: koffi AmsiOpenSession failed in scan", { hr: hrOpen, contentName });
      return null;
    }
    const session = sessOut[0];
    try {
      const truncated = content.length > MAX_SCAN_LENGTH ? content.slice(0, MAX_SCAN_LENGTH) : content;
      const buf = Buffer.from(truncated, "utf-8");
      const resultOut = [0];
      const hr = this.fnScanBuffer(this.context, buf, buf.length, contentName, session, resultOut);
      if (hr !== 0) {
        this.logger.warn("AMSI: koffi AmsiScanBuffer failed", { hr, contentName });
        return null;
      }
      const amsiResult = resultOut[0] ?? 0;
      this.logger.debug("AMSI: koffi scan result", { contentName, amsiResult });
      return interpretAmsiResult(amsiResult, content, contentName);
    } catch (e) {
      this.logger.warn("AMSI: koffi scanBuffer failed", { error: String(e), contentName });
      return null;
    } finally {
      try {
        if (this.fnCloseSession && this.context) {
          this.fnCloseSession(this.context, session);
        }
      } catch {
      }
    }
  }
  close() {
    try {
      if (this.context && this.fnUninitialize) {
        this.fnUninitialize(this.context);
      }
    } catch {
    }
    this.fnOpenSession = null;
    this.fnScanBuffer = null;
    this.fnCloseSession = null;
    this.fnUninitialize = null;
    this.context = null;
    this.available = false;
    try {
      this.lib?.close();
    } catch {
    }
    this.lib = null;
  }
};
var AMSI_CSHARP_TYPE = `
using System;
using System.Runtime.InteropServices;
using System.Text;

public class SageAmsi {
    [DllImport("amsi.dll", CharSet = CharSet.Unicode)]
    static extern int AmsiInitialize(string appName, out IntPtr ctx);

    [DllImport("amsi.dll")]
    static extern int AmsiOpenSession(IntPtr ctx, out IntPtr session);

    [DllImport("amsi.dll", CharSet = CharSet.Unicode)]
    static extern int AmsiScanBuffer(
        IntPtr ctx, byte[] buf, uint len,
        string contentName, IntPtr session, out int result);

    [DllImport("amsi.dll")]
    static extern void AmsiCloseSession(IntPtr ctx, IntPtr session);

    [DllImport("amsi.dll")]
    static extern void AmsiUninitialize(IntPtr ctx);

    private static IntPtr _ctx;
    private static bool _initialized;

    public static bool Init() {
        int hr = AmsiInitialize("Sage", out _ctx);
        if (hr != 0) return false;
        // Verify we can open a session, then close it immediately.
        // Actual sessions are opened per-scan to avoid cross-file tainting.
        IntPtr sess;
        hr = AmsiOpenSession(_ctx, out sess);
        if (hr != 0) {
            AmsiUninitialize(_ctx);
            return false;
        }
        AmsiCloseSession(_ctx, sess);
        _initialized = true;
        return true;
    }

    public static int Scan(string content, string contentName) {
        if (!_initialized) return -1;
        // Open a fresh session per scan so a detection in one file
        // does not taint subsequent scans (sessions are correlation scopes).
        IntPtr session;
        int hr = AmsiOpenSession(_ctx, out session);
        if (hr != 0) return -1;
        try {
            byte[] bytes = Encoding.UTF8.GetBytes(content);
            int result;
            hr = AmsiScanBuffer(_ctx, bytes, (uint)bytes.Length,
                                    contentName, session, out result);
            if (hr != 0) return -1;
            return result;
        } finally {
            AmsiCloseSession(_ctx, session);
        }
    }

    public static void Shutdown() {
        if (!_initialized) return;
        AmsiUninitialize(_ctx);
        _initialized = false;
    }
}
`;
var PS_PERSISTENT_SCRIPT = `
$ErrorActionPreference = 'Stop'
try {
    Add-Type -TypeDefinition @'
${AMSI_CSHARP_TYPE}
'@

    if (-not [SageAmsi]::Init()) {
        [Console]::Error.Write("AMSI initialization failed")
        exit 1
    }

    [Console]::Out.WriteLine("READY")
    [Console]::Out.Flush()

    while ($null -ne ($line = [Console]::In.ReadLine())) {
        try {
            $req = $line | ConvertFrom-Json
            $content = $req.content
            $cname = $req.contentName
            if (-not $cname) { $cname = 'sage:test' }
            $result = [SageAmsi]::Scan($content, $cname)
            [Console]::Out.WriteLine($result)
            [Console]::Out.Flush()
        } catch {
            [Console]::Out.WriteLine("-1")
            [Console]::Out.Flush()
        }
    }

    [SageAmsi]::Shutdown()
} catch {
    [Console]::Error.Write($_.Exception.Message)
    exit 1
}
`;
var PS_ONESHOT_SCRIPT = `
$ErrorActionPreference = 'Stop'
try {
    Add-Type -TypeDefinition @'
${AMSI_CSHARP_TYPE}
'@

    if (-not [SageAmsi]::Init()) {
        [Console]::Out.WriteLine("-1")
        exit
    }

    $line = [Console]::In.ReadLine()
    $req = $line | ConvertFrom-Json
    $content = $req.content
    $cname = $req.contentName
    if (-not $cname) { $cname = 'sage:scan' }
    $result = [SageAmsi]::Scan($content, $cname)
    [SageAmsi]::Shutdown()
    [Console]::Out.WriteLine($result)
    [Console]::Out.Flush()
} catch {
    [Console]::Out.WriteLine("-1")
}
`;
var PersistentPowershellAmsiBackend = class {
  logger;
  process = null;
  available = false;
  invalidResultLogged = false;
  stdoutBuffer = "";
  pendingResponse = null;
  scanQueue = Promise.resolve();
  constructor(logger) {
    this.logger = logger;
  }
  get isAvailable() {
    return this.available;
  }
  waitForLine(timeout) {
    return new Promise((resolve10, reject) => {
      const timer = setTimeout(() => {
        this.pendingResponse = null;
        reject(new Error("timeout"));
      }, timeout);
      this.pendingResponse = { resolve: resolve10, reject, timer };
    });
  }
  async enqueueScan(operation) {
    const previous = this.scanQueue;
    let release;
    this.scanQueue = new Promise((resolve10) => {
      release = resolve10;
    });
    await previous;
    try {
      return await operation();
    } finally {
      release();
    }
  }
  async init() {
    try {
      this.process = spawn("powershell.exe", [
        "-NoProfile",
        "-NonInteractive",
        "-ExecutionPolicy",
        "Bypass",
        "-Command",
        PS_PERSISTENT_SCRIPT
      ], {
        stdio: ["pipe", "pipe", "pipe"],
        windowsHide: true
      });
      this.process.on("error", (err) => {
        this.logger.debug("AMSI: PowerShell process error", { error: String(err) });
        this.available = false;
        if (this.pendingResponse) {
          const { reject, timer } = this.pendingResponse;
          this.pendingResponse = null;
          clearTimeout(timer);
          reject(err);
        }
      });
      this.process.on("exit", () => {
        this.available = false;
        if (this.pendingResponse) {
          const { reject, timer } = this.pendingResponse;
          this.pendingResponse = null;
          clearTimeout(timer);
          reject(new Error("process exited"));
        }
      });
      this.process.stdout?.on("data", (chunk) => {
        this.stdoutBuffer += chunk.toString();
        let idx = this.stdoutBuffer.indexOf("\n");
        while (idx !== -1) {
          const line = this.stdoutBuffer.slice(0, idx).trim();
          this.stdoutBuffer = this.stdoutBuffer.slice(idx + 1);
          if (this.pendingResponse) {
            const { resolve: resolve10, timer } = this.pendingResponse;
            this.pendingResponse = null;
            clearTimeout(timer);
            resolve10(line);
          }
          idx = this.stdoutBuffer.indexOf("\n");
        }
      });
      this.process.stdin?.on("error", () => {
      });
      this.process.stderr?.on("data", (chunk) => {
        this.logger.debug("AMSI: PowerShell stderr", {
          data: chunk.toString().slice(0, 200)
        });
      });
      const readyLine = await this.waitForLine(PS_TIMEOUT);
      if (readyLine === "READY") {
        this.available = true;
        this.logger.debug("AMSI: PowerShell persistent backend initialized");
      } else {
        this.logger.debug("AMSI: PowerShell unexpected ready signal", { readyLine });
        this.close();
      }
    } catch (e) {
      this.logger.debug("AMSI: PowerShell persistent backend init failed", {
        error: String(e)
      });
      this.close();
    }
  }
  async scanString(content, contentName) {
    if (!this.available || !this.process)
      return null;
    return this.enqueueScan(async () => {
      const process2 = this.process;
      if (!this.available || !process2)
        return null;
      const truncated = content.length > MAX_SCAN_LENGTH ? content.slice(0, MAX_SCAN_LENGTH) : content;
      try {
        const req = JSON.stringify({ content: truncated, contentName });
        process2.stdin?.write(`${req}
`);
        const line = await this.waitForLine(PS_TIMEOUT);
        const amsiResult = parseInt(line, 10);
        if (Number.isNaN(amsiResult) || amsiResult < 0) {
          if (!this.invalidResultLogged) {
            this.invalidResultLogged = true;
            this.logger.warn("AMSI: PowerShell scan returned invalid result", {
              stdout: line.slice(0, 100),
              contentName
            });
          }
          return null;
        }
        this.logger.debug("AMSI: PowerShell scan result", { contentName, amsiResult });
        return interpretAmsiResult(amsiResult, content, contentName);
      } catch (e) {
        this.logger.warn("AMSI: PowerShell scan failed", { error: String(e), contentName });
        this.close();
        return null;
      }
    });
  }
  close() {
    if (this.process) {
      try {
        this.process.stdin?.end();
      } catch {
      }
      try {
        this.process.kill();
      } catch {
      }
      this.process = null;
    }
    if (this.pendingResponse) {
      const { reject, timer } = this.pendingResponse;
      this.pendingResponse = null;
      clearTimeout(timer);
      reject(new Error("closed"));
    }
    this.available = false;
  }
};
var WslPowershellAmsiBackend = class {
  logger;
  available = false;
  invalidResultLogged = false;
  constructor(logger) {
    this.logger = logger;
  }
  get isAvailable() {
    return this.available;
  }
  async init() {
    this.available = true;
    this.logger.debug("AMSI: PowerShell one-shot backend ready (WSL)");
  }
  async scanString(content, contentName) {
    if (!this.available)
      return null;
    const truncated = content.length > MAX_SCAN_LENGTH ? content.slice(0, MAX_SCAN_LENGTH) : content;
    return new Promise((resolve10) => {
      try {
        const ps = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", PS_ONESHOT_SCRIPT], { stdio: ["pipe", "pipe", "pipe"] });
        let stdout = "";
        const timer = setTimeout(() => {
          this.logger.warn("AMSI: PowerShell one-shot timeout", { contentName });
          try {
            ps.kill();
          } catch {
          }
          resolve10(null);
        }, PS_TIMEOUT);
        ps.stdout?.on("data", (chunk) => {
          stdout += chunk.toString();
        });
        ps.stderr?.on("data", (chunk) => {
          this.logger.debug("AMSI: PowerShell one-shot stderr", {
            data: chunk.toString().slice(0, 200)
          });
        });
        ps.on("error", (err) => {
          clearTimeout(timer);
          this.logger.debug("AMSI: PowerShell one-shot error", { error: String(err) });
          resolve10(null);
        });
        ps.on("exit", () => {
          clearTimeout(timer);
          const amsiResult = parseInt(stdout.trim(), 10);
          if (Number.isNaN(amsiResult) || amsiResult < 0) {
            if (!this.invalidResultLogged) {
              this.invalidResultLogged = true;
              this.logger.warn("AMSI: PowerShell one-shot invalid result", {
                stdout: stdout.slice(0, 100),
                contentName
              });
            }
            resolve10(null);
            return;
          }
          this.logger.debug("AMSI: PowerShell one-shot result", { contentName, amsiResult });
          resolve10(interpretAmsiResult(amsiResult, content, contentName));
        });
        const req = JSON.stringify({ content: truncated, contentName });
        ps.stdin?.write(`${req}
`);
        ps.stdin?.end();
      } catch (e) {
        this.logger.warn("AMSI: PowerShell one-shot failed", { error: String(e), contentName });
        resolve10(null);
      }
    });
  }
  close() {
    this.available = false;
  }
};
var AmsiClient = class {
  logger;
  backend = null;
  constructor(logger = nullLogger) {
    this.logger = logger;
  }
  get isAvailable() {
    return this.backend?.isAvailable ?? false;
  }
  async init() {
    const wsl = isWSL();
    if (process.platform !== "win32" && !wsl) {
      this.logger.debug("AMSI: skipping, not Windows");
      return;
    }
    if (!wsl) {
      const koffi = new KoffiAmsiBackend(this.logger);
      await koffi.init();
      if (koffi.isAvailable) {
        this.backend = koffi;
        return;
      }
    }
    const ps = wsl ? new WslPowershellAmsiBackend(this.logger) : new PersistentPowershellAmsiBackend(this.logger);
    await ps.init();
    if (ps.isAvailable) {
      this.backend = ps;
      return;
    }
    this.logger.debug("AMSI: no backend available");
  }
  async scanString(scanType, contentName, content) {
    const formattedName = `[Sage:${scanType}]:${contentName}`;
    return await this.backend?.scanString(content, formattedName) ?? null;
  }
  close() {
    this.backend?.close();
    this.backend = null;
  }
};

// ../core/dist/clients/content-fetch.js
init_types2();
var DEFAULT_TIMEOUT_MS = 4e3;
var DEFAULT_MAX_CONTENT_LENGTH = 16384;
var BINARY_SNIFF_LENGTH = 512;
var TEXTUAL_APPLICATION_TYPES = /* @__PURE__ */ new Set([
  "application/json",
  "application/xml",
  "application/xhtml+xml",
  "application/javascript",
  "application/x-yaml",
  "application/yaml",
  "application/rss+xml",
  "application/atom+xml",
  "application/ld+json"
]);
var ContentFetchClient = class _ContentFetchClient {
  timeoutMs;
  maxContentLength;
  logger;
  constructor(timeoutMs = DEFAULT_TIMEOUT_MS, maxContentLength = DEFAULT_MAX_CONTENT_LENGTH, logger = nullLogger) {
    this.timeoutMs = timeoutMs;
    this.maxContentLength = maxContentLength;
    this.logger = logger;
  }
  async fetchTextContent(url) {
    try {
      const response = await fetch(url, {
        signal: AbortSignal.timeout(this.timeoutMs),
        redirect: "follow",
        headers: { "User-Agent": "sage" }
      });
      if (!response.ok) {
        this.logger.debug("Content fetch failed", { url, status: String(response.status) });
        return null;
      }
      const contentType = response.headers.get("content-type");
      if (!_ContentFetchClient.isTextualContentType(contentType)) {
        this.logger.debug("Skipping non-textual content type", {
          url,
          contentType: contentType ?? "unknown"
        });
        return null;
      }
      const reader = response.body?.getReader();
      if (!reader)
        return null;
      const decoder = new TextDecoder();
      let text = "";
      try {
        while (text.length < this.maxContentLength) {
          const { done, value } = await reader.read();
          if (done)
            break;
          text += decoder.decode(value, { stream: true });
        }
        text += decoder.decode();
      } finally {
        reader.cancel();
      }
      if (text.length > this.maxContentLength) {
        text = text.slice(0, this.maxContentLength);
      }
      if (_ContentFetchClient.hasBinaryContent(text)) {
        this.logger.debug("Skipping binary content", { url });
        return null;
      }
      return { content: text, contentType };
    } catch (error) {
      this.logger.debug("Content fetch error", { url, error: String(error) });
      return null;
    }
  }
  static isTextualContentType(contentType) {
    if (contentType == null)
      return true;
    const mime = contentType.split(";")[0]?.trim().toLowerCase() ?? "";
    if (mime.startsWith("text/"))
      return true;
    return TEXTUAL_APPLICATION_TYPES.has(mime);
  }
  static hasBinaryContent(text) {
    const sniff = text.slice(0, BINARY_SNIFF_LENGTH);
    return sniff.includes("\0");
  }
};

// ../core/dist/clients/file-check.js
init_types2();

// ../core/dist/version.js
var import_node_path5 = require("node:path");
var import_node_url = require("node:url");
init_file_utils();
var import_meta = {};
function resolveVersion() {
  if (true)
    return "0.12.0";
  try {
    const pkgPath = (0, import_node_path5.join)((0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url)), "..", "package.json");
    const pkg = JSON.parse(getFileContentSync(pkgPath));
    if (typeof pkg.version === "string")
      return pkg.version;
  } catch {
  }
  return "dev";
}
var VERSION = resolveVersion();

// ../core/dist/clients/file-check.js
var DEFAULT_TIMEOUT = 5;
var SERVICE_NAME = "sage";
var MAX_HASHES_PER_REQUEST = 50;
function getProviderTld() {
  return "com";
}
var REQUEST_HEADERS = [
  { name: "Accept", value: "application/json" },
  { name: "Content-Type", value: "application/json" },
  { name: "User-Agent", value: SERVICE_NAME }
];
function getProviderName() {
  return "avast";
}
var FileCheckClient = class {
  endpoint;
  timeoutMs;
  logger;
  constructor(config2, logger = nullLogger) {
    this.endpoint = config2?.endpoint ?? this.resolveEndpoint();
    this.timeoutMs = (config2?.timeout_seconds ?? DEFAULT_TIMEOUT) * 1e3;
    this.logger = logger;
  }
  buildPath() {
    return "/file-check";
  }
  async checkHash(hash) {
    try {
      const response = await fetch(this.endpoint, {
        method: "POST",
        headers: Object.fromEntries(REQUEST_HEADERS.map((h) => [h.name, h.value])),
        body: JSON.stringify({
          requests: [{ key: { sha256: hash } }],
          client_info: {
            product: {
              version_app: VERSION
            }
          }
        }),
        signal: AbortSignal.timeout(this.timeoutMs)
      });
      if (!response.ok) {
        this.logger.warn(`FileCheck HTTP error: ${response.status}`);
        return null;
      }
      const data = await response.json();
      return this.parseResponse(data);
    } catch (e) {
      this.logger.warn("FileCheck request failed", { error: String(e) });
      return null;
    }
  }
  getSubdomain() {
    return "svc";
  }
  resolveEndpoint() {
    return `https://${SERVICE_NAME}-proxy.${this.buildDomain()}${this.buildPath()}`;
  }
  parseResponse(data) {
    try {
      const responses = data.responses ?? [];
      if (responses.length === 0)
        return null;
      const first = responses[0];
      const severity = first.severity ?? "SEVERITY_UNKNOWN";
      const malwareNames = first.malware_name ?? [];
      const detectionNames = malwareNames.filter((n) => typeof n === "string" && n.length > 0);
      return { severity, detectionNames };
    } catch (e) {
      this.logger.warn("Failed to parse FileCheck response", { error: String(e) });
      return null;
    }
  }
  async checkHashes(hashes) {
    if (hashes.length === 0)
      return [];
    const batches = [];
    for (let i = 0; i < hashes.length; i += MAX_HASHES_PER_REQUEST) {
      batches.push(hashes.slice(i, i + MAX_HASHES_PER_REQUEST));
    }
    const batchResults = await Promise.all(batches.map((batch) => this.checkHashBatch(batch)));
    return batchResults.flat();
  }
  async checkHashBatch(hashes) {
    try {
      const response = await fetch(this.endpoint, {
        method: "POST",
        headers: Object.fromEntries(REQUEST_HEADERS.map((h) => [h.name, h.value])),
        body: JSON.stringify({
          requests: hashes.map((h) => ({ key: { sha256: h } })),
          client_info: {
            product_name: SERVICE_NAME,
            product_version: VERSION
          }
        }),
        signal: AbortSignal.timeout(this.timeoutMs)
      });
      if (!response.ok) {
        this.logger.warn(`FileCheck batch HTTP error: ${response.status}`);
        return [];
      }
      const data = await response.json();
      return this.parseBatchResponse(data);
    } catch (e) {
      this.logger.warn("FileCheck batch request failed", { error: String(e) });
      return [];
    }
  }
  parseBatchResponse(data) {
    const results = [];
    try {
      const responses = data.responses ?? [];
      for (const entry of responses) {
        const key = entry.key;
        const sha256 = key?.sha256 ?? "";
        if (!sha256)
          continue;
        const severity = entry.severity ?? "SEVERITY_UNKNOWN";
        const malwareNames = entry.malware_name ?? [];
        const detectionNames = malwareNames.filter((n) => typeof n === "string" && n.length > 0);
        results.push({ sha256, severity, detectionNames });
      }
    } catch (e) {
      this.logger.warn("Failed to parse FileCheck batch response", { error: String(e) });
    }
    return results;
  }
  buildDomain() {
    return [this.getSubdomain(), getProviderName(), getProviderTld()].join(".");
  }
};

// ../core/dist/model-storage.js
var import_node_fs = require("node:fs");
var import_node_path6 = require("node:path");
init_config();
var MODEL_SCHEMA_VERSION = "v2";
var REQUIRED_MODELS_BY_SCHEMA = {
  v1: ["pi-model"],
  v2: ["pi-model"]
};
var REQUIRED_MODEL_FILES = {
  "pi-model": [
    "model_int8.onnx",
    "tokenizer.json",
    "tokenizer_config.json",
    "special_tokens_map.json",
    "vocab.txt",
    "config.json"
  ]
};
function getModelStorageRoot(sageDir = resolvePath("~/.sage")) {
  return (0, import_node_path6.join)(resolvePath(sageDir), "models");
}
function getModelDir(modelName, schema = MODEL_SCHEMA_VERSION, sageDir) {
  return (0, import_node_path6.join)(getModelStorageRoot(sageDir), schema, modelName);
}
function isModelPresent(modelName, schema = MODEL_SCHEMA_VERSION, sageDir) {
  const dir = getModelDir(modelName, schema, sageDir);
  const files = REQUIRED_MODEL_FILES[modelName];
  if (!files || files.length === 0)
    return false;
  return files.every((f) => (0, import_node_fs.existsSync)((0, import_node_path6.resolve)(dir, f)));
}
function missingRequiredModels(schema = MODEL_SCHEMA_VERSION, sageDir) {
  const required = REQUIRED_MODELS_BY_SCHEMA[schema] ?? [];
  return required.filter((name) => !isModelPresent(name, schema, sageDir));
}

// ../core/dist/clients/model-downloader.js
init_types2();
var STALE_LOCK_MS = 60 * 60 * 1e3;

// ../core/dist/clients/model-manifest.js
init_config();

// ../core/dist/sage-proxy.js
function mapSageHostOs(platform) {
  switch (platform) {
    case "win32":
      return "WINDOWS";
    case "darwin":
      return "MACOS";
    case "linux":
      return "LINUX";
    default:
      return platform;
  }
}
function mapSageHostArchitecture(arch) {
  return arch.toUpperCase();
}
function buildSageUserConfig(config2) {
  return {
    sensitivity: config2.sensitivity,
    url_check_enabled: config2.url_check.enabled,
    file_check_enabled: config2.file_check.enabled,
    package_check_enabled: config2.package_check.enabled,
    heuristics_enabled: config2.heuristics_enabled,
    pi_check_enabled: config2.pi_check.enabled,
    community_iq_enabled: config2.community_iq,
    // Optional-chained + defaulted: real callers pass a loadConfig result (skill_check
    // always present via the schema default), but this feeds fail-open telemetry, so a
    // partial config must never crash the envelope build.
    skill_check_upload_enabled: config2.skill_check?.upload_enabled ?? true
  };
}
function buildSageProxyEnvelope(args) {
  return {
    identity: { uuid: args.iid },
    product: { version_app: args.versionApp },
    platform: {
      os: args.platformOs ?? mapSageHostOs(process.platform),
      architecture: args.platformArchitecture ?? mapSageHostArchitecture(process.arch)
    },
    agent: {
      agent_runtime: args.agentRuntime,
      agent_runtime_version: args.agentRuntimeVersion
    },
    ...args.config ? { config: buildSageUserConfig(args.config) } : {}
  };
}

// ../core/dist/clients/model-manifest.js
init_types2();

// ../core/dist/clients/url-check.js
init_types2();
var DEFAULT_TIMEOUT2 = 5;
var MAX_URLS_PER_REQUEST = 50;
var SERVICE_NAME2 = "sage";
function getProviderTld2() {
  return "com";
}
var REQUEST_HEADERS2 = [
  { name: "Accept", value: "application/json" },
  { name: "Content-Type", value: "application/json" },
  { name: "User-Agent", value: SERVICE_NAME2 }
];
function getProviderName2() {
  return "avast";
}
function getSubdomain() {
  return "svc";
}
function buildDomain() {
  return [getSubdomain(), getProviderName2(), getProviderTld2()].join(".");
}
function resolveEndpoint(path) {
  const normalizedPath = path.startsWith("/") ? path : `/${path}`;
  return `https://${SERVICE_NAME2}-proxy.${buildDomain()}${normalizedPath}`;
}
var UrlCheckClient = class {
  endpoint;
  timeoutMs;
  logger;
  constructor(config2, logger = nullLogger) {
    this.endpoint = config2?.endpoint ?? resolveEndpoint("/url-check");
    this.timeoutMs = (config2?.timeout_seconds ?? DEFAULT_TIMEOUT2) * 1e3;
    this.logger = logger;
  }
  async checkUrls(urls) {
    if (urls.length === 0)
      return [];
    const batches = [];
    for (let i = 0; i < urls.length; i += MAX_URLS_PER_REQUEST) {
      batches.push(urls.slice(i, i + MAX_URLS_PER_REQUEST));
    }
    const batchResults = await Promise.all(batches.map((batch) => this.checkBatch(batch)));
    return batchResults.flat();
  }
  async checkBatch(urls) {
    const queries = urls.map((url) => ({
      key: { "url-like": url },
      include: { "detection-infos": true }
    }));
    const payload = {
      queries,
      "client-info": {
        "product-name": SERVICE_NAME2,
        "product-version": VERSION
      }
    };
    try {
      const response = await fetch(this.endpoint, {
        method: "POST",
        headers: Object.fromEntries(REQUEST_HEADERS2.map((h) => [h.name, h.value])),
        body: JSON.stringify(payload),
        signal: AbortSignal.timeout(this.timeoutMs)
      });
      if (!response.ok) {
        this.logger.warn(`URL check HTTP error: ${response.status}`);
        return [];
      }
      const data = await response.json();
      const answers = data.answers ?? [];
      const results = [];
      for (const answer of answers) {
        const result = this.parseAnswer(answer);
        if (result !== null) {
          results.push(result);
        }
      }
      return results;
    } catch (e) {
      this.logger.warn("URL check request failed", { error: String(e) });
      return [];
    }
  }
  parseAnswer(answer) {
    try {
      const url = answer.key ?? "";
      const result = answer.result ?? {};
      const success = result.success ?? {};
      const classification = success.classification ?? {};
      const detectionInfos = classification["detection-infos"] ?? [];
      const classResult = classification.result ?? {};
      const malicious = classResult.malicious;
      const detections = detectionInfos.filter((info) => typeof info.name === "string").map((info) => {
        return info.name;
      });
      const findings = malicious ? (malicious.findings ?? []).map((f) => ({
        severityName: f["severity-name"] ?? "unknown",
        typeName: f["type-name"] ?? "unknown"
      })) : [];
      return {
        url,
        isMalicious: Boolean(malicious),
        detections,
        findings
      };
    } catch (e) {
      this.logger.warn("Failed to parse answer", { error: String(e) });
      return null;
    }
  }
};

// ../core/dist/clients/package-registry.js
var import_semver = __toESM(require_semver2(), 1);
init_types2();
var NPM_REGISTRY = "https://registry.npmjs.org";
var PYPI_REGISTRY = "https://pypi.org/pypi";
var DEFAULT_TIMEOUT3 = 5;
var NPM_NAME_RE = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
var PYPI_NAME_RE = /^[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$/;
var RegistryClient = class {
  timeoutMs;
  logger;
  constructor(config2, logger = nullLogger) {
    this.timeoutMs = (config2?.timeout_seconds ?? DEFAULT_TIMEOUT3) * 1e3;
    this.logger = logger;
  }
  async getPackageMetadata(name, registry, version) {
    if (registry === "npm")
      return this.getNpmMetadata(name, version);
    return this.getPypiMetadata(name, version);
  }
  async getNpmMetadata(name, version) {
    if (!NPM_NAME_RE.test(name)) {
      this.logger.warn("Invalid npm package name rejected", { name });
      return null;
    }
    const encodedName = name.includes("/") ? `${name.split("/")[0]}%2f${name.split("/")[1]}` : name;
    const url = `${NPM_REGISTRY}/${encodedName}`;
    try {
      const response = await fetch(url, {
        signal: AbortSignal.timeout(this.timeoutMs)
      });
      if (response.status === 404)
        return null;
      if (!response.ok) {
        this.logger.warn(`npm registry HTTP error: ${response.status}`, { name });
        throw new Error(`npm registry HTTP ${response.status}`);
      }
      const data = await response.json();
      return this.parseNpmResponse(name, data, version);
    } catch (e) {
      this.logger.warn("npm registry request failed", { name, error: String(e) });
      throw e;
    }
  }
  parseNpmResponse(name, data, requestedVersion) {
    try {
      const distTags = data["dist-tags"] ?? {};
      const latestTag = distTags.latest;
      if (!latestTag)
        return null;
      const versions = data.versions ?? {};
      const versionKeys = Object.keys(versions);
      const effectiveVersion = requestedVersion && distTags[requestedVersion] ? distTags[requestedVersion] : requestedVersion;
      const requestedVersionFound = !effectiveVersion || Boolean(versions[effectiveVersion]) || import_semver.default.maxSatisfying(versionKeys, effectiveVersion) !== null;
      const resolvedVersion = effectiveVersion && versions[effectiveVersion] ? effectiveVersion : effectiveVersion && import_semver.default.maxSatisfying(versionKeys, effectiveVersion) || latestTag;
      const resolvedVersionData = versions[resolvedVersion];
      if (!resolvedVersionData)
        return null;
      const dist = resolvedVersionData.dist ?? {};
      const shasum = dist.shasum ?? "";
      const integrity = dist.integrity ?? "";
      let latestHash = shasum;
      let hashAlgorithm = "sha1";
      if (integrity.startsWith("sha256-")) {
        latestHash = Buffer.from(integrity.slice(7), "base64").toString("hex");
        hashAlgorithm = "sha256";
      }
      const time = data.time ?? {};
      let firstReleaseDate = null;
      const created = time.created;
      if (created) {
        firstReleaseDate = new Date(created);
      }
      return {
        name,
        resolvedVersion,
        latestHash,
        hashAlgorithm,
        firstReleaseDate,
        requestedVersionFound
      };
    } catch (e) {
      this.logger.warn("Failed to parse npm response", { name, error: String(e) });
      return null;
    }
  }
  async getPypiMetadata(name, version) {
    if (!PYPI_NAME_RE.test(name)) {
      this.logger.warn("Invalid PyPI package name rejected", { name });
      return null;
    }
    const url = `${PYPI_REGISTRY}/${name}/json`;
    try {
      const response = await fetch(url, {
        signal: AbortSignal.timeout(this.timeoutMs)
      });
      if (response.status === 404)
        return null;
      if (!response.ok) {
        this.logger.warn(`PyPI registry HTTP error: ${response.status}`, { name });
        throw new Error(`PyPI registry HTTP ${response.status}`);
      }
      const data = await response.json();
      return this.parsePypiResponse(name, data, version);
    } catch (e) {
      this.logger.warn("PyPI registry request failed", { name, error: String(e) });
      throw e;
    }
  }
  parsePypiResponse(name, data, requestedVersion) {
    try {
      const info = data.info ?? {};
      const latestTag = info.version ?? "";
      if (!latestTag)
        return null;
      const releases = data.releases ?? {};
      const pypiVersionMatch = (raw) => {
        if (raw.startsWith("===")) {
          const literal = raw.slice(3);
          return releases[literal]?.length ? literal : void 0;
        }
        if (releases[raw]?.length)
          return raw;
        const oneZero = `${raw}.0`;
        if (releases[oneZero]?.length)
          return oneZero;
        const twoZero = `${raw}.0.0`;
        if (releases[twoZero]?.length)
          return twoZero;
        return void 0;
      };
      const matchedVersion = requestedVersion ? pypiVersionMatch(requestedVersion) : void 0;
      const requestedVersionFound = !requestedVersion || Boolean(matchedVersion);
      const resolvedVersion = matchedVersion ?? latestTag;
      let latestHash = "";
      const latestFiles = releases[resolvedVersion] ?? [];
      for (const file of latestFiles) {
        const digests = file.digests ?? {};
        if (digests.sha256) {
          latestHash = digests.sha256;
          break;
        }
      }
      let firstReleaseDate = null;
      for (const [, files] of Object.entries(releases)) {
        for (const file of files) {
          const uploadTime = file.upload_time_iso_8601;
          if (uploadTime) {
            const date = new Date(uploadTime);
            if (!firstReleaseDate || date < firstReleaseDate) {
              firstReleaseDate = date;
            }
          }
        }
      }
      return {
        name,
        resolvedVersion,
        latestHash,
        hashAlgorithm: "sha256",
        firstReleaseDate,
        requestedVersionFound
      };
    } catch (e) {
      this.logger.warn("Failed to parse PyPI response", { name, error: String(e) });
      return null;
    }
  }
};

// ../core/dist/clients/pi-check.js
var import_node_path9 = require("node:path");
init_types2();
var DEFAULT_MAX_CONTENT_LENGTH2 = 16384;
var MAX_TOKENS = 512;
var OVERLAP_TOKENS = 128;
var MODEL_FILE = "model_int8.onnx";
var MODEL_METADATA_FILES = [
  "config.json",
  "special_tokens_map.json",
  "tokenizer.json",
  "tokenizer_config.json",
  "vocab.txt",
  MODEL_FILE
];
function softmax(logits) {
  const max = Math.max(...logits);
  const exp = logits.map((x) => Math.exp(x - max));
  const sum = exp.reduce((a, b) => a + b, 0);
  return exp.map((x) => x / sum);
}
function isModelMissingError(err) {
  if (!(err instanceof Error))
    return false;
  const nodeErr = err;
  if (nodeErr.code === "ENOENT")
    return true;
  const msg = err.message.toLowerCase();
  return msg.includes("enoent") || msg.includes("no such file or directory") || MODEL_METADATA_FILES.some((name) => msg.includes(name.toLowerCase()));
}
var BundledPiProvider = class _BundledPiProvider {
  /** Tracks whether any instance loaded the model runtime in this process. */
  static modelRuntimeLoaded = false;
  modelPath;
  maxContentLength;
  mediumRiskThreshold;
  logger;
  tokenizer = null;
  session = null;
  tensorClass = null;
  inputNames = /* @__PURE__ */ new Set();
  initPromise = null;
  /**
   * Call at the end of the process to prevent native model runtime cleanup
   * crash (exit code 134/SIGABRT). Only exits if the runtime was actually
   * loaded.
   */
  static async exitIfModelLoaded(logger) {
    if (!_BundledPiProvider.modelRuntimeLoaded)
      return;
    await logger?.flush?.();
    process.exit(0);
  }
  constructor(options = {}) {
    this.modelPath = options.modelPath ?? getModelDir("pi-model");
    this.maxContentLength = options.maxContentLength ?? DEFAULT_MAX_CONTENT_LENGTH2;
    this.mediumRiskThreshold = options.mediumRiskThreshold ?? DEFAULT_PI_MEDIUM_RISK_THRESHOLD;
    this.logger = options.logger ?? nullLogger;
  }
  async checkContent(content, context) {
    try {
      const truncated = this.truncateContent(content);
      if (truncated.length === 0)
        return null;
      const loaded = await this.ensureLoaded();
      if (!loaded)
        return null;
      const chunks = this.chunkText(truncated);
      let maxRisk = 0;
      let maxChunk = "";
      for (const chunk of chunks) {
        if (chunk.length < 10)
          continue;
        const risk = await this.classifyChunk(chunk);
        if (risk > maxRisk) {
          maxRisk = risk;
          maxChunk = chunk;
        }
      }
      const findings = [];
      if (maxRisk >= this.mediumRiskThreshold) {
        const snippet = maxChunk.length > 80 ? `${maxChunk.slice(0, 77)}...` : maxChunk;
        findings.push(snippet);
      }
      return {
        risk: maxRisk,
        findings,
        contentName: context,
        modelId: (0, import_node_path9.basename)(this.modelPath),
        contentSnippet: maxChunk || void 0
      };
    } catch (err) {
      this.logger.warn("PI check failed (fail-open)", {
        error: err instanceof Error ? err.message : String(err),
        context
      });
      return null;
    }
  }
  async ensureLoaded() {
    if (this.session && this.tokenizer)
      return true;
    if (this.initPromise)
      return this.initPromise;
    this.initPromise = this.loadModel();
    return this.initPromise;
  }
  async loadModel() {
    try {
      const { LocalTokenizer: LocalTokenizer2 } = await Promise.resolve().then(() => (init_tokenizer(), tokenizer_exports));
      this.tokenizer = LocalTokenizer2.fromModelDir(this.modelPath, MAX_TOKENS);
      const { ensurePiDeps: ensurePiDeps2 } = await Promise.resolve().then(() => (init_pi_deps_installer(), pi_deps_installer_exports));
      const depsReady = await ensurePiDeps2(this.modelPath, this.logger);
      if (!depsReady)
        return false;
      const { createRequire: createRequire2 } = await import("node:module");
      const requireFromModel = createRequire2((0, import_node_path9.resolve)(this.modelPath, "package.json"));
      const runtime = requireFromModel("onnxruntime-node");
      this.tensorClass = runtime.Tensor;
      const modelFilePath = (0, import_node_path9.resolve)(this.modelPath, MODEL_FILE);
      this.session = await runtime.InferenceSession.create(modelFilePath);
      const sess = this.session;
      this.inputNames = new Set(sess.inputNames);
      _BundledPiProvider.modelRuntimeLoaded = true;
      this.logger.info("PI model loaded", { path: this.modelPath });
      return true;
    } catch (err) {
      if (isModelMissingError(err)) {
        this.logger.debug("PI model not yet available; using heuristics only", {
          path: this.modelPath,
          error: err instanceof Error ? err.message : String(err)
        });
        return false;
      }
      const errMsg = err instanceof Error ? `${err.message}
${err.stack}` : String(err);
      this.logger.warn(`PI model load failed (pi_check is enabled but inference will be skipped): ${errMsg}`);
      return false;
    }
  }
  /**
   * Classify a single chunk. Returns P(injected) via softmax over two-class logits.
   */
  async classifyChunk(text) {
    const tok = this.tokenizer;
    if (!tok)
      throw new Error("PI tokenizer is not loaded");
    const encoded = tok.call(text, {
      truncation: true,
      max_length: MAX_TOKENS,
      padding: true
    });
    const inputIds = new BigInt64Array(encoded.input_ids.map((v) => BigInt(v)));
    const attentionMask = new BigInt64Array(encoded.attention_mask.map((v) => BigInt(v)));
    const TensorClass = this.tensorClass;
    const feeds = {
      input_ids: new TensorClass("int64", inputIds, [1, inputIds.length]),
      attention_mask: new TensorClass("int64", attentionMask, [1, attentionMask.length])
    };
    if (this.inputNames.has("token_type_ids")) {
      feeds.token_type_ids = new TensorClass("int64", new BigInt64Array(inputIds.length), [
        1,
        inputIds.length
      ]);
    }
    const session = this.session;
    const output = await session.run(feeds);
    const logits = Array.from(output.logits?.data ?? []);
    if (logits.length < 2)
      return 0;
    const probs = softmax(logits);
    return probs[1] ?? 0;
  }
  /**
   * Chunk text with a sliding window over tokenized input. Window size and
   * overlap are tuned to the model's input window.
   */
  chunkText(text) {
    const tok = this.tokenizer;
    if (!tok)
      throw new Error("PI tokenizer is not loaded");
    const encoded = tok.tokenize(text, {
      addSpecialTokens: false,
      returnOffsetMapping: true,
      truncation: false
    });
    const tokenIds = encoded.input_ids;
    const offsets = encoded.offset_mapping;
    if (!offsets)
      return [text];
    if (tokenIds.length <= MAX_TOKENS)
      return [text];
    const chunks = [];
    let start = 0;
    while (start < tokenIds.length) {
      const end = Math.min(start + MAX_TOKENS, tokenIds.length);
      const charStart = offsets[start]?.[0] ?? 0;
      const charEnd = offsets[end - 1]?.[1] ?? text.length;
      chunks.push(text.slice(charStart, charEnd));
      if (end >= tokenIds.length)
        break;
      start = end - OVERLAP_TOKENS;
    }
    return chunks;
  }
  truncateContent(content) {
    if (content.length <= this.maxContentLength)
      return content;
    const headLen = Math.floor(this.maxContentLength * 0.8);
    const tailLen = this.maxContentLength - headLen;
    return `${content.slice(0, headLen)}
...[truncated]...
${content.slice(-tailLen)}`;
  }
};

// ../core/dist/index.js
init_pi_deps_installer();

// ../core/dist/clients/skill-analyze.js
init_types2();

// ../core/dist/clients/skill-check.js
init_types2();
var DEFAULT_TIMEOUT4 = 5;
var SERVICE_NAME3 = "sage";
var MAX_IDS_PER_REQUEST = 50;
var REQUEST_HEADERS3 = [
  { name: "Accept", value: "application/json" },
  { name: "Content-Type", value: "application/json" },
  { name: "User-Agent", value: SERVICE_NAME3 }
];
var SkillCheckClient = class {
  endpoint;
  timeoutMs;
  logger;
  constructor(config2, logger = nullLogger) {
    this.endpoint = config2?.endpoint ?? resolveEndpoint("/v2/skill-check");
    this.timeoutMs = (config2?.timeout_seconds ?? DEFAULT_TIMEOUT4) * 1e3;
    this.logger = logger;
  }
  /**
   * Check a list of skill IDs against the proxy.
   *
   * Returns a Map keyed by skill id:
   * - `null` — proxy had no opinion (explicit null in response, or skill absent
   *   from an otherwise-successful response). Callers should treat this as
   *   "unknown, queue for upload".
   * - absent — the entire batch failed (HTTP error or network error). Callers
   *   should fail open and skip the skill rather than enqueue it.
   * - object — a verdict from the analyzer.
   *
   * Fails-open: on any error returns an empty Map. Per-batch errors do
   * not poison results from successful batches.
   */
  async checkSkills(skillIds) {
    const out = /* @__PURE__ */ new Map();
    if (skillIds.length === 0)
      return out;
    const unique = [...new Set(skillIds)];
    const batches = [];
    for (let i = 0; i < unique.length; i += MAX_IDS_PER_REQUEST) {
      batches.push(unique.slice(i, i + MAX_IDS_PER_REQUEST));
    }
    const batchResults = await Promise.all(batches.map((batch) => this.checkBatch(batch)));
    for (const batch of batchResults) {
      for (const [id, result] of batch) {
        out.set(id, result);
      }
    }
    return out;
  }
  async checkBatch(skillIds) {
    const out = /* @__PURE__ */ new Map();
    try {
      const response = await fetch(this.endpoint, {
        method: "POST",
        headers: Object.fromEntries(REQUEST_HEADERS3.map((h) => [h.name, h.value])),
        body: JSON.stringify({
          skill_ids: skillIds,
          client_info: {
            product_name: SERVICE_NAME3,
            product_version: VERSION
          }
        }),
        signal: AbortSignal.timeout(this.timeoutMs)
      });
      if (!response.ok) {
        this.logger.warn(`SkillCheck HTTP error: ${response.status}`);
        return out;
      }
      const data = await response.json();
      const results = data.results ?? {};
      for (const id of skillIds) {
        if (!(id in results)) {
          out.set(id, null);
          continue;
        }
        const raw = results[id];
        if (raw === null || raw === void 0) {
          out.set(id, null);
          continue;
        }
        const parsed = this.parseResult(id, raw);
        out.set(id, parsed);
      }
    } catch (e) {
      this.logger.warn("SkillCheck batch request failed", { error: String(e) });
    }
    return out;
  }
  parseResult(skillId, raw) {
    return {
      skillId,
      verdict: typeof raw.verdict === "string" ? raw.verdict : void 0,
      summary: typeof raw.summary === "string" ? raw.summary : void 0
    };
  }
};

// ../core/dist/index.js
init_config();

// ../core/dist/config-defaults.js
var import_promises3 = require("node:fs/promises");
var import_node_path10 = require("node:path");
init_file_utils();
init_types2();
var CONFIG_DEFAULTS_FILENAME = "config.default.json";
var CONFIG_DEFAULTS_SCHEMA_VERSION = 1;
function buildConfigDefaults() {
  return {
    schema_version: CONFIG_DEFAULTS_SCHEMA_VERSION,
    ...ConfigSchema.parse({})
  };
}
function serializeConfigDefaults() {
  return `${JSON.stringify(buildConfigDefaults(), null, 2)}
`;
}
function readSchemaVersion(raw) {
  try {
    const data = JSON.parse(raw);
    if (typeof data !== "object" || data === null || Array.isArray(data))
      return null;
    const version = data.schema_version;
    return typeof version === "number" && Number.isInteger(version) ? version : null;
  } catch {
    return null;
  }
}
async function deployConfigDefaults(sageDirPath, logger = nullLogger) {
  const targetPath = (0, import_node_path10.join)(sageDirPath, CONFIG_DEFAULTS_FILENAME);
  const defaults = serializeConfigDefaults();
  try {
    await (0, import_promises3.mkdir)(sageDirPath, { recursive: true, mode: 448 });
    await (0, import_promises3.chmod)(sageDirPath, 448);
    let existing = null;
    try {
      existing = await (0, import_promises3.readFile)(targetPath, "utf-8");
    } catch {
    }
    if (existing) {
      const existingVersion = readSchemaVersion(existing);
      if (existingVersion !== null && existingVersion > CONFIG_DEFAULTS_SCHEMA_VERSION) {
        logger.warn("Deployed config defaults are newer, update your installation", {
          path: targetPath,
          existingVersion,
          supportedVersion: CONFIG_DEFAULTS_SCHEMA_VERSION
        });
        return;
      }
      if (existing === defaults)
        return;
    }
    await withFileLock(targetPath, async () => {
      await (0, import_promises3.writeFile)(targetPath, defaults, { encoding: "utf-8", mode: 384 });
      logger.debug("Deployed config defaults", {
        path: targetPath,
        schemaVersion: CONFIG_DEFAULTS_SCHEMA_VERSION
      });
    });
  } catch (err) {
    logger.debug("Failed to deploy config defaults", { path: targetPath, error: String(err) });
  }
}

// ../core/dist/config-diagnostics.js
init_config();
init_file_utils();
init_types2();
function formatPath(path) {
  return path.replace(/\\/g, "/");
}
function configWarning(path, reason) {
  return { file: "config", path, reason };
}
function exceptionsWarning(path, reason) {
  return { file: "exceptions", path, reason };
}
function inspectConfig(raw, path) {
  let data;
  try {
    data = JSON.parse(raw);
  } catch {
    return configWarning(path, "parse");
  }
  return ConfigSchema.safeParse(data).success ? null : configWarning(path, "validation");
}
function inspectExceptions(raw, path) {
  let data;
  try {
    data = JSON.parse(raw);
  } catch {
    return exceptionsWarning(path, "parse");
  }
  return ExceptionsFileSchema.safeParse(data).success ? null : exceptionsWarning(path, "validation");
}
function getConfigurationWarningsSync(configPath, logger) {
  const warnings = [];
  const resolvedConfigPath = configPath ? resolvePath(configPath) : defaultConfigPath();
  try {
    const rawConfig = getFileContentSync(resolvedConfigPath);
    const warning = inspectConfig(rawConfig, resolvedConfigPath);
    if (warning)
      warnings.push(warning);
  } catch {
  }
  const config2 = loadConfigSync(resolvedConfigPath, logger);
  const exceptionsPath = resolvePath(config2.exceptions.path);
  try {
    const rawExceptions = getFileContentSync(exceptionsPath);
    const warning = inspectExceptions(rawExceptions, exceptionsPath);
    if (warning)
      warnings.push(warning);
  } catch {
  }
  return warnings;
}
function formatConfigurationWarnings(warnings, branding2) {
  if (warnings.length === 0)
    return null;
  const lines = [`\u26A0\uFE0F ${branding2.name}: configuration warning`];
  for (const warning of warnings) {
    if (warning.file === "config") {
      const reason = warning.reason === "parse" ? "is not valid JSON" : "has the wrong shape";
      lines.push(`- ${formatPath(warning.path)} ${reason}. ${branding2.short_name} is using default settings until this file is fixed.`);
    } else if (warning.reason === "parse") {
      lines.push(`- ${formatPath(warning.path)} is not valid JSON. Exception rules are not being applied until this file is fixed.`);
    } else {
      lines.push(`- ${formatPath(warning.path)} has the wrong shape. Expected ${JSON.stringify({ rules: [] })}. Exception rules are not being applied until this file is fixed.`);
    }
  }
  return lines.join("\n");
}

// ../core/dist/content-policy.js
var SCANNABLE_EXTENSIONS = /* @__PURE__ */ new Set([
  ".py",
  ".js",
  ".mjs",
  ".cjs",
  ".jsx",
  ".ts",
  ".tsx",
  ".mts",
  ".cts",
  ".sh",
  ".bash",
  ".html",
  ".htm",
  ".json",
  ".jsonc",
  ".txt",
  ".csv",
  ".xml",
  ".c",
  ".h",
  ".cpp",
  ".cc",
  ".cxx",
  ".hpp",
  ".yaml",
  ".yml",
  ".kt",
  ".kts"
]);
function getUrlExtension(url) {
  try {
    const pathname = new URL(url).pathname;
    const dot = pathname.lastIndexOf(".");
    const slash = pathname.lastIndexOf("/");
    if (dot <= slash || dot < 0)
      return null;
    return pathname.slice(dot).toLowerCase();
  } catch {
    return null;
  }
}
function extractWebFetchUrl(toolInput) {
  if (typeof toolInput.url === "string")
    return toolInput.url;
  if (Array.isArray(toolInput.urls) && typeof toolInput.urls[0] === "string")
    return toolInput.urls[0];
  return null;
}
var SNIFF_HTML = /^\s*<!doctype\s+html|^\s*<html[\s>]/i;
var SNIFF_HTML_TAGS = /<\/(head|body|html|div|p|script|style|form|table)>/i;
var SNIFF_JSON = /^\s*[[{]/;
var SNIFF_XML = /^\s*<\?xml\s/i;
var SNIFF_YAML = /^---\s*$/m;
var SNIFF_SHEBANG_SHELL = /^#!.*\b(sh|bash|zsh|dash)\b/;
var SNIFF_SHEBANG_PYTHON = /^#!.*\bpython/i;
var SNIFF_PYTHON = /^(?:import |from \S+ import |def \w+\(|class \w+[:(])/m;
var SNIFF_JS_TS = /^(?:const |let |var |function |import |export |module\.exports)/m;
var SNIFF_C_CPP = /^#include\s*[<"]/m;
var SNIFF_KOTLIN = /^(?:package |fun |class |val |var |object |interface )\w/m;
var SNIFF_CSV = /^[^,\n]+(?:,[^,\n]+){2,}$/m;
function isScannableContent(content) {
  const head = content.slice(0, 4096);
  return SNIFF_HTML.test(head) || SNIFF_HTML_TAGS.test(head) || SNIFF_JSON.test(head) || SNIFF_XML.test(head) || SNIFF_YAML.test(head) || SNIFF_SHEBANG_SHELL.test(head) || SNIFF_SHEBANG_PYTHON.test(head) || SNIFF_PYTHON.test(head) || SNIFF_JS_TS.test(head) || SNIFF_C_CPP.test(head) || SNIFF_KOTLIN.test(head) || SNIFF_CSV.test(head);
}

// ../core/dist/extended-info.js
var import_promises4 = require("node:fs/promises");
var import_node_os3 = require("node:os");
var import_node_path11 = require("node:path");
init_file_utils();
init_types2();
var EXTENDED_INFO_FILE_MAX_BYTES = 1024;
var EXTENDED_INFO_MAX_GROUPS = 16;
var EXTENDED_INFO_MAX_KEYS_PER_GROUP = 32;
var EXTENDED_INFO_MAX_LEAF_CHARS = 256;
var EXTENDED_INFO_FILENAME = "extended-info.json";
var cache = /* @__PURE__ */ new Map();
function isPlainObjectValue(value) {
  return typeof value === "object" && value !== null && !Array.isArray(value);
}
function sanitizeScalarLeaf(leafValue) {
  if (typeof leafValue === "string") {
    return safeTruncate(leafValue, EXTENDED_INFO_MAX_LEAF_CHARS);
  }
  return leafValue;
}
function sanitizeArrayLeaf(groupKey, leafKey, items, logger) {
  const out = [];
  for (const [index, item] of items.entries()) {
    if (typeof item !== "string" && typeof item !== "number" && typeof item !== "boolean") {
      logger.debug(`extended-info: dropped non-scalar array item '${groupKey}.${leafKey}[${index}]' (type ${typeof item})`);
      continue;
    }
    out.push(sanitizeScalarLeaf(item));
  }
  return out;
}
function sanitizeLeaves(groupKey, rawGroup, logger) {
  const entries = Object.entries(rawGroup);
  const overflow = entries.length > EXTENDED_INFO_MAX_KEYS_PER_GROUP;
  const retained = overflow ? entries.slice(0, EXTENDED_INFO_MAX_KEYS_PER_GROUP) : entries;
  if (overflow) {
    logger.debug(`extended-info: dropped overflow keys in group '${groupKey}' (kept first ${EXTENDED_INFO_MAX_KEYS_PER_GROUP} of ${entries.length})`);
  }
  const out = {};
  for (const [leafKey, leafValue] of retained) {
    if (typeof leafValue === "string") {
      out[leafKey] = sanitizeScalarLeaf(leafValue);
      continue;
    }
    if (typeof leafValue === "number" || typeof leafValue === "boolean") {
      out[leafKey] = sanitizeScalarLeaf(leafValue);
      continue;
    }
    if (Array.isArray(leafValue)) {
      out[leafKey] = sanitizeArrayLeaf(groupKey, leafKey, leafValue, logger);
      continue;
    }
    logger.debug(`extended-info: dropped non-scalar leaf '${groupKey}.${leafKey}' (type ${typeof leafValue})`);
  }
  return out;
}
function sanitizeDocument(parsed, logger) {
  const out = {};
  for (const [groupKey, groupValue] of Object.entries(parsed)) {
    if (!isPlainObjectValue(groupValue)) {
      logger.debug(`extended-info: dropped non-object group '${groupKey}'`);
      continue;
    }
    out[groupKey] = sanitizeLeaves(groupKey, groupValue, logger);
  }
  return out;
}
async function loadExtendedInfo(sageDirPath, logger = nullLogger) {
  const sageDir = sageDirPath ?? (0, import_node_path11.join)((0, import_node_os3.homedir)(), ".sage");
  const filePath = (0, import_node_path11.join)(sageDir, EXTENDED_INFO_FILENAME);
  const cached = cache.get(filePath);
  if (cached)
    return cached.value;
  const value = await loadExtendedInfoUncached(filePath, logger);
  cache.set(filePath, { value });
  return value;
}
async function loadExtendedInfoUncached(filePath, logger) {
  let size;
  try {
    const info = await (0, import_promises4.stat)(filePath);
    if (!info.isFile()) {
      logger.debug(`extended-info: not a regular file at ${filePath}`);
      return null;
    }
    size = info.size;
  } catch {
    return null;
  }
  if (size > EXTENDED_INFO_FILE_MAX_BYTES) {
    logger.debug(`extended-info: file size ${size} exceeds cap ${EXTENDED_INFO_FILE_MAX_BYTES}; ignoring`);
    return null;
  }
  let raw;
  try {
    raw = await getFileContent(filePath, "utf-8");
  } catch {
    return null;
  }
  let parsed;
  try {
    parsed = JSON.parse(raw);
  } catch (err) {
    logger.debug(`extended-info: invalid JSON: ${err}`);
    return null;
  }
  if (!isPlainObjectValue(parsed)) {
    logger.debug("extended-info: top-level value is not a non-null object");
    return null;
  }
  const groupCount = Object.keys(parsed).length;
  if (groupCount > EXTENDED_INFO_MAX_GROUPS) {
    logger.debug(`extended-info: ${groupCount} top-level groups exceed cap ${EXTENDED_INFO_MAX_GROUPS}; rejecting whole file`);
    return null;
  }
  return sanitizeDocument(parsed, logger);
}
function cloneExtendedInfoLeaf(leafValue) {
  return Array.isArray(leafValue) ? dedupeArrayItems(leafValue) : leafValue;
}
function cloneExtendedInfoGroup(groupValue) {
  return Object.fromEntries(Object.entries(groupValue).map(([leafKey, leafValue]) => [
    leafKey,
    cloneExtendedInfoLeaf(leafValue)
  ]));
}
function dedupeArrayItems(items) {
  const seen = /* @__PURE__ */ new Set();
  const out = [];
  for (const item of items) {
    if (seen.has(item))
      continue;
    seen.add(item);
    out.push(item);
  }
  return out;
}
function mergeExtendedInfo(envelope, extendedInfo) {
  const out = { ...envelope };
  if (!extendedInfo)
    return out;
  for (const [groupKey, groupValue] of Object.entries(extendedInfo)) {
    const existing = out[groupKey];
    if (existing === void 0 || existing === null) {
      out[groupKey] = cloneExtendedInfoGroup(groupValue);
      continue;
    }
    if (!isPlainObjectValue(existing)) {
      continue;
    }
    const merged = { ...existing };
    for (const [leafKey, leafValue] of Object.entries(groupValue)) {
      const current = merged[leafKey];
      if (current === void 0 || current === null) {
        merged[leafKey] = cloneExtendedInfoLeaf(leafValue);
        continue;
      }
      if (Array.isArray(current) && Array.isArray(leafValue)) {
        merged[leafKey] = dedupeArrayItems([...current, ...leafValue]);
      }
    }
    out[groupKey] = merged;
  }
  return out;
}

// ../core/dist/installation-id.js
var import_node_crypto4 = require("node:crypto");
var import_promises5 = require("node:fs/promises");
var import_node_path12 = require("node:path");
init_config();
init_file_utils();
async function getInstallationId(sageDirPath) {
  const sageDir = sageDirPath ?? resolvePath("~/.sage");
  const idPath = (0, import_node_path12.join)(sageDir, "installation-id");
  let fileExists = false;
  try {
    const existing = await getFileContent(idPath, "utf-8");
    const trimmed = existing.trim();
    if (trimmed.length > 0)
      return trimmed;
    fileExists = true;
  } catch {
  }
  try {
    const id = (0, import_node_crypto4.randomUUID)();
    await (0, import_promises5.mkdir)(sageDir, { recursive: true, mode: 448 });
    await (0, import_promises5.writeFile)(idPath, id, { encoding: "utf-8", mode: 384, flag: fileExists ? "w" : "wx" });
    return id;
  } catch (err) {
    if (err.code === "EEXIST") {
      try {
        const existing = await getFileContent(idPath, "utf-8");
        return existing.trim() || void 0;
      } catch {
        return void 0;
      }
    }
    return void 0;
  }
}

// ../core/dist/detection-telemetry.js
init_types2();
var MAX_EFFECTIVE_TIMEOUT_MS = 1e3;
var DEFAULT_TIMEOUT_MS2 = 1e3;
function resolveTimeoutMs() {
  const envVal = process.env.SAGE_COMMUNITY_IQ_TIMEOUT_SECONDS;
  if (envVal === void 0 || envVal === "")
    return DEFAULT_TIMEOUT_MS2;
  const parsed = Number.parseFloat(envVal);
  if (!Number.isFinite(parsed) || parsed <= 0)
    return DEFAULT_TIMEOUT_MS2;
  const ms = Math.floor(parsed * 1e3);
  return Math.min(ms, MAX_EFFECTIVE_TIMEOUT_MS);
}
async function sendCommunityIqTelemetry(args) {
  const logger = args.logger ?? nullLogger;
  if (!args.communityIqEnabled) {
    logger.debug("Community IQ disabled, skipping telemetry");
    return;
  }
  let iid;
  try {
    iid = await getInstallationId();
  } catch {
  }
  if (!iid) {
    logger.debug("Skipping telemetry: missing installation id");
    return;
  }
  const envelope = buildSageProxyEnvelope({
    iid,
    versionApp: VERSION,
    agentRuntime: args.agentRuntime ?? "unknown",
    agentRuntimeVersion: args.agentRuntimeVersion ?? process.env.SAGE_AGENT_RUNTIME_VERSION ?? "unknown",
    config: args.config
  });
  const blocking = args.blocking ?? true;
  const payload = {
    ...envelope,
    block_event: {
      hook_type: args.hookType ?? "PreToolUse",
      // `args.toolName` is canonical (`CanonicalToolType`) — connectors
      // canonicalize before calling `evaluateToolCall`, so no further
      // mapping is needed here.
      tool_type: args.toolName,
      verdict: blocking ? "deny" : "suspicious",
      ...blocking ? { user_action: "blocked" } : {},
      timestamp: (/* @__PURE__ */ new Date()).toISOString(),
      ...args.signals && Object.keys(args.signals).length > 0 ? { signals: args.signals } : {},
      content: args.content ?? {}
    },
    event_id: args.eventId,
    comment: ""
  };
  const extendedInfo = await loadExtendedInfo(void 0, logger).catch(() => null);
  const enriched = mergeExtendedInfo(payload, extendedInfo);
  const timeoutMs = resolveTimeoutMs();
  const endpoint = blocking ? "/v2/detection" : "/v2/heuristic";
  try {
    const response = await fetch(resolveEndpoint(endpoint), {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(enriched),
      signal: AbortSignal.timeout(timeoutMs)
    });
    if (!response.ok) {
      logger.warn("Community IQ telemetry send failed", {
        eventId: args.eventId,
        status: response.status
      });
    } else {
      logger.debug("Community IQ telemetry sent", {
        eventId: args.eventId,
        toolName: args.toolName,
        hookType: args.hookType ?? "PreToolUse"
      });
    }
  } catch (err) {
    logger.warn("Detection telemetry send failed", {
      eventId: args.eventId,
      error: String(err)
    });
  }
}

// ../core/dist/e2e-capture.js
var import_node_path13 = require("node:path");
var CAPTURE_MAX_BYTES = 10 * 1024 * 1024;
var CAPTURE_MAX_FILES = 2;
function captureEnabled() {
  return !!process.env.SAGE_E2E_CAPTURE_DIR;
}
async function captureHookInput(event, raw, normalized, options = {}) {
  const dir = process.env.SAGE_E2E_CAPTURE_DIR;
  if (!dir)
    return;
  try {
    const prefix = options.filePrefix ?? "";
    const base = event === "PreToolUse" ? "pre-tool-use.jsonl" : "post-tool-use.jsonl";
    await appendJsonlEntry({
      path: (0, import_node_path13.join)(dir, `${prefix}${base}`),
      max_bytes: CAPTURE_MAX_BYTES,
      max_files: CAPTURE_MAX_FILES
    }, { event, raw, normalized });
  } catch {
  }
}

// ../core/dist/policy.js
init_types2();
var SENSITIVITY_POLICY = {
  paranoid: { denyThreshold: 0.7, askThreshold: 0.3 },
  balanced: { denyThreshold: 0.85, askThreshold: 0.5 },
  relaxed: { denyThreshold: 0.95, askThreshold: 0.7 }
};
function applyPolicy(confidence, denyThreshold, askThreshold, logger = nullLogger) {
  if (!Number.isFinite(confidence) || confidence <= 0 || confidence > 1) {
    logger.warn("Invalid confidence; treating as allow", { confidence });
    return "allow";
  }
  if (confidence >= denyThreshold)
    return "deny";
  if (confidence >= askThreshold)
    return "ask";
  return "allow";
}

// ../core/dist/engine.js
init_types2();
var PI_LABEL_ONLY_SUFFIXES = /* @__PURE__ */ new Set([
  "command",
  "stdout",
  "stderr",
  "output"
]);
function displayContentName(contentName) {
  const colonIdx = contentName.indexOf(":");
  if (colonIdx === -1)
    return contentName;
  const rest = contentName.slice(colonIdx + 1);
  if (PI_LABEL_ONLY_SUFFIXES.has(rest))
    return contentName;
  const trimmed = rest.replace(/[/\\]+$/, "");
  const sepIdx = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
  const base = sepIdx === -1 ? trimmed : trimmed.slice(sepIdx + 1);
  return base || rest;
}
function buildPiReason(prefix, result) {
  return `${prefix} in ${formatPiFinding(result)}`;
}
function formatPiFinding(result) {
  const where = displayContentName(result.contentName);
  const score = `score: ${result.risk.toFixed(3)}`;
  const snippet = result.findings[0]?.replace(/\s+/g, " ").trim();
  if (snippet)
    return `${where} (${score}): "${snippet}"`;
  return `${where} (${score})`;
}
var DecisionEngine = class {
  denyThreshold;
  askThreshold;
  logger;
  constructor(sensitivity = "balanced", logger = nullLogger) {
    const policy = SENSITIVITY_POLICY[sensitivity] ?? SENSITIVITY_POLICY.balanced;
    this.denyThreshold = policy.denyThreshold;
    this.askThreshold = policy.askThreshold;
    this.logger = logger;
  }
  async decide(sources) {
    const signals = this.collectSignals(sources.heuristicMatches, sources.urlCheckResults, sources.packageCheckResults, sources.amsiCheckResults, sources.piCheckResults, sources.piThresholds);
    if (signals.length === 0) {
      return this.allowVerdict();
    }
    const top = signals.reduce((best, s) => s.confidence > best.confidence ? s : best);
    const maxConfidence = top.confidence;
    const decision = applyPolicy(maxConfidence, this.denyThreshold, this.askThreshold, this.logger);
    const allArtifacts = [...new Map(signals.map((s) => [s.artifact, s.artifact])).values()];
    const allReasons = [...new Map(signals.map((s) => [s.reason, s.reason])).values()];
    return {
      decision,
      category: top.category,
      confidence: maxConfidence,
      severity: top.severity,
      source: top.source,
      artifacts: allArtifacts,
      matchedThreatId: top.threatId,
      reasons: allReasons
    };
  }
  collectSignals(heuristicMatches, urlCheckResults, packageCheckResults, amsiCheckResults, piCheckResults, piThresholds) {
    const signals = [];
    for (const match of heuristicMatches) {
      const { confidence, category, severity, id, title } = match.threat;
      if (applyPolicy(confidence, this.denyThreshold, this.askThreshold, this.logger) === "allow")
        continue;
      signals.push({
        category,
        confidence,
        severity,
        source: "heuristic",
        threatId: id,
        reason: title,
        artifact: match.artifact
      });
    }
    for (const result of urlCheckResults) {
      if (result.isMalicious) {
        const confidence = 1;
        const findingDetails = result.findings.map((f) => `${f.severityName}/${f.typeName}`).join(", ");
        signals.push({
          category: "network_egress",
          confidence,
          severity: "critical",
          source: "url_check",
          threatId: null,
          reason: `Malicious URL (${findingDetails})`,
          artifact: result.url
        });
      }
    }
    if (packageCheckResults) {
      for (const pkg of packageCheckResults) {
        if (pkg.verdict === "clean")
          continue;
        const signal = this.packageVerdictToSignal(pkg);
        if (signal)
          signals.push(signal);
      }
    }
    if (amsiCheckResults) {
      for (const result of amsiCheckResults) {
        if (result.isDetected) {
          signals.push({
            category: "malware",
            confidence: 1,
            severity: "critical",
            source: "amsi",
            threatId: null,
            reason: `AMSI detected malware in ${result.contentName} (result=${result.amsiResult})`,
            artifact: result.contentName
          });
        } else if (result.isBlockedByAdmin) {
          signals.push({
            category: "malware",
            confidence: 0.9,
            severity: "critical",
            source: "amsi",
            threatId: null,
            reason: `AMSI: content blocked by admin policy in ${result.contentName} (result=${result.amsiResult})`,
            artifact: result.contentName
          });
        }
      }
    }
    if (piCheckResults) {
      const highRisk = piThresholds?.highRisk ?? DEFAULT_PI_HIGH_RISK_THRESHOLD;
      const mediumRisk = piThresholds?.mediumRisk ?? DEFAULT_PI_MEDIUM_RISK_THRESHOLD;
      for (const result of piCheckResults) {
        if (result.risk >= highRisk) {
          signals.push({
            category: "prompt_injection",
            confidence: 1,
            severity: "critical",
            source: "pi_check",
            threatId: "PROMPT_INJECTION",
            reason: buildPiReason("Prompt injection detected", result),
            artifact: result.contentName
          });
        } else if (result.risk >= mediumRisk) {
          signals.push({
            category: "prompt_injection",
            confidence: 0.6,
            severity: "warning",
            source: "pi_check",
            threatId: "PROMPT_INJECTION",
            reason: buildPiReason("Suspicious content detected", result),
            artifact: result.contentName
          });
        }
      }
    }
    return signals;
  }
  packageVerdictToSignal(pkg) {
    switch (pkg.verdict) {
      case "not_found":
      case "malicious":
        return {
          category: "supply_chain",
          confidence: pkg.confidence,
          severity: "critical",
          source: "package_check",
          threatId: null,
          reason: pkg.details,
          artifact: pkg.packageName
        };
      case "suspicious_age":
      case "unknown":
        return {
          category: "supply_chain",
          confidence: pkg.confidence,
          severity: "warning",
          source: "package_check",
          threatId: null,
          reason: pkg.details,
          artifact: pkg.packageName
        };
      default:
        return null;
    }
  }
  allowVerdict() {
    return {
      decision: "allow",
      category: "none",
      confidence: 0,
      severity: "info",
      source: "none",
      artifacts: [],
      matchedThreatId: null,
      reasons: []
    };
  }
};

// ../core/dist/evaluator.js
var import_node_crypto6 = require("node:crypto");
init_config();

// ../core/dist/exceptions.js
var import_node_crypto5 = require("node:crypto");
var import_node_path15 = require("node:path");
init_config();
init_file_utils();

// ../core/dist/trusted-domains.js
var import_promises6 = require("node:fs/promises");
var import_node_path14 = require("node:path");
var import_yaml = __toESM(require_dist(), 1);
init_file_utils();
init_types2();
async function loadTrustedDomains(trustedDomainsDir, logger = nullLogger) {
  let files;
  try {
    files = (await (0, import_promises6.readdir)(trustedDomainsDir)).filter((f) => f.endsWith(".yaml")).sort();
  } catch {
    logger.debug("Trusted domains directory does not exist", { path: trustedDomainsDir });
    return [];
  }
  const domains = [];
  for (const filename of files) {
    const filePath = (0, import_node_path14.join)(trustedDomainsDir, filename);
    let content;
    try {
      content = await getFileContent(filePath);
    } catch (e) {
      logger.warn(`Failed to read ${filename}`, { error: String(e) });
      continue;
    }
    let data;
    try {
      data = (0, import_yaml.parse)(content);
    } catch (e) {
      logger.warn(`Failed to parse ${filename}`, { error: String(e) });
      continue;
    }
    if (!Array.isArray(data)) {
      logger.warn(`Expected list in ${filename}, got ${typeof data}`);
      continue;
    }
    for (const entry of data) {
      if (typeof entry !== "object" || entry === null) {
        logger.warn(`Skipping non-object entry in ${filename}`);
        continue;
      }
      const record = entry;
      const domain = record.domain;
      const reason = record.reason;
      if (!domain || typeof domain !== "string") {
        logger.warn(`Skipping entry without valid 'domain' in ${filename}`);
        continue;
      }
      if (!reason || typeof reason !== "string") {
        logger.warn(`Skipping entry without valid 'reason' in ${filename}`);
        continue;
      }
      domains.push({ domain: domain.toLowerCase(), reason });
    }
  }
  logger.debug(`Loaded ${domains.length} trusted domains from ${trustedDomainsDir}`);
  return domains;
}
function extractDomain(url) {
  try {
    const parsed = new URL(url);
    return parsed.hostname.toLowerCase() || null;
  } catch {
    return null;
  }
}
function isTrustedDomain(domain, trusted) {
  const domainLower = domain.toLowerCase();
  for (const td of trusted) {
    if (domainLower === td.domain)
      return true;
    if (domainLower.endsWith(`.${td.domain}`))
      return true;
  }
  return false;
}

// ../core/dist/exceptions.js
init_types2();
var MAX_RULES_WARNING = 100;
var REGEX_TIMEOUT_MS = 50;
function computeRuleId(decision, match, pattern) {
  const hash = (0, import_node_crypto5.createHash)("sha256").update(`${decision}:${match}:${pattern}`).digest("hex");
  return hash.slice(0, 8);
}
async function loadExceptions(config2, logger = nullLogger) {
  const path = resolvePath(config2.path);
  let raw;
  try {
    raw = await getFileContent(path);
  } catch {
    return [];
  }
  let data;
  try {
    data = JSON.parse(raw);
  } catch (e) {
    logger.warn(`Failed to parse exceptions from ${path}`, { error: String(e) });
    return [];
  }
  let parsed;
  try {
    parsed = ExceptionsFileSchema.parse(data);
  } catch (e) {
    logger.warn(`Exceptions validation failed for ${path}`, { error: String(e) });
    return [];
  }
  if (parsed.rules.length > MAX_RULES_WARNING) {
    logger.warn(`Exceptions file has ${parsed.rules.length} rules (>${MAX_RULES_WARNING})`, {
      path
    });
  }
  const seen = /* @__PURE__ */ new Map();
  let needsWrite = false;
  for (const rule of parsed.rules) {
    const expectedId = computeRuleId(rule.decision, rule.match, rule.pattern);
    if (rule.id !== expectedId) {
      needsWrite = true;
    }
    if (seen.has(expectedId)) {
      needsWrite = true;
      continue;
    }
    const normalized = {
      id: expectedId,
      decision: rule.decision,
      match: rule.match,
      pattern: rule.pattern,
      ...rule.reason !== void 0 ? { reason: rule.reason } : {}
    };
    seen.set(expectedId, normalized);
  }
  const rules = [...seen.values()];
  if (needsWrite) {
    try {
      await atomicWriteJson(path, {
        rules: rules.map((r) => ({
          id: r.id,
          decision: r.decision,
          match: r.match,
          pattern: r.pattern,
          ...r.reason !== void 0 ? { reason: r.reason } : {}
        }))
      });
    } catch (e) {
      logger.warn(`Failed to write normalized exceptions to ${path}`, { error: String(e) });
    }
  }
  for (const rule of rules) {
    if (rule.match === "regex") {
      try {
        new RegExp(rule.pattern);
      } catch (e) {
        logger.warn(`Invalid regex in exception rule ${rule.id}: ${rule.pattern}`, {
          error: String(e)
        });
      }
    }
  }
  return rules;
}
function escapeRegexString(s) {
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
async function addException(artifact, reason, exceptionsPath, logger = nullLogger) {
  let excConfig;
  if (exceptionsPath) {
    excConfig = { path: exceptionsPath };
  } else {
    const config2 = await Promise.resolve().then(() => (init_config(), config_exports)).then((m) => m.loadConfig(void 0, logger));
    excConfig = config2.exceptions;
  }
  const pattern = `^${escapeRegexString(artifact.value)}$`;
  const rule = {
    id: computeRuleId("allow", "regex", pattern),
    decision: "allow",
    match: "regex",
    pattern,
    reason
  };
  const existing = await loadExceptions(excConfig, logger);
  if (existing.some((r) => r.id === rule.id)) {
    logger.debug("Exception rule already exists", {
      ruleId: rule.id,
      decision: rule.decision,
      match: rule.match
    });
    return;
  }
  const rules = [...existing, rule];
  const path = resolvePath(excConfig.path);
  try {
    await atomicWriteJson(path, {
      rules: rules.map((r) => ({
        id: r.id,
        decision: r.decision,
        match: r.match,
        pattern: r.pattern,
        ...r.reason !== void 0 ? { reason: r.reason } : {}
      }))
    });
    logger.info("Exception rule added", {
      ruleId: rule.id,
      decision: rule.decision,
      match: rule.match
    });
  } catch (e) {
    logger.warn("Failed to write exception rule", { error: String(e) });
  }
}
var UNSAFE_COMMAND_PATTERN = /[;&|`]|\$\(|<\(|>\(|\n|\r/;
var SUDO_FLAGS_WITH_ARG = /* @__PURE__ */ new Set(["-u", "-g", "-C", "-D", "-R", "-T", "-h", "-p"]);
function matchesExecutable(pattern, command) {
  if (UNSAFE_COMMAND_PATTERN.test(command)) {
    return false;
  }
  const tokens = command.trim().split(/\s+/);
  if (tokens.length === 0)
    return false;
  let i = 0;
  if (tokens[i] === "sudo") {
    i++;
    while (i < tokens.length) {
      const token = tokens[i];
      if (token === void 0 || token === "--") {
        if (token === "--")
          i++;
        break;
      }
      if (!token.startsWith("-"))
        break;
      i++;
      const nextToken = tokens[i];
      if (SUDO_FLAGS_WITH_ARG.has(token) && nextToken !== void 0 && !nextToken.startsWith("-")) {
        i++;
      }
    }
  }
  if (i < tokens.length && tokens[i] === "env") {
    i++;
    while (i < tokens.length) {
      const tok = tokens[i];
      if (tok === void 0 || !/^\w+=/.test(tok))
        break;
      i++;
    }
  }
  const exeToken = tokens[i];
  if (exeToken === void 0)
    return false;
  const exeParts = exeToken.split("/");
  const exeName = exeParts[exeParts.length - 1];
  if (!exeName)
    return false;
  const patternTokens = pattern.trim().split(/\s+/);
  if (patternTokens.length === 0)
    return false;
  if (exeName !== patternTokens[0])
    return false;
  for (let j = 1; j < patternTokens.length; j++) {
    if (i + j >= tokens.length)
      return false;
    if (tokens[i + j] !== patternTokens[j])
      return false;
  }
  return true;
}
function matchesDomain(pattern, url) {
  const domain = extractDomain(url);
  if (!domain)
    return false;
  const portMatch = pattern.match(/^(.+):(\d+)$/);
  const portDomain = portMatch?.[1];
  const portPort = portMatch?.[2];
  if (portDomain && portPort) {
    const patternDomain = portDomain.toLowerCase();
    const patternPort = portPort;
    let urlPort;
    try {
      const parsed = new URL(url);
      urlPort = parsed.port || (parsed.protocol === "https:" ? "443" : "80");
    } catch {
      return false;
    }
    if (urlPort !== patternPort)
      return false;
    return isTrustedDomain(domain, [{ domain: patternDomain, reason: "" }]);
  }
  return isTrustedDomain(domain, [{ domain: pattern.toLowerCase(), reason: "" }]);
}
function normalizePatternPath(pattern) {
  const home = getHomeDir();
  const expanded = pattern.startsWith("~/") || pattern === "~" ? `${home}${pattern.slice(1)}` : pattern;
  return (0, import_node_path15.normalize)(expanded);
}
function matchesPath(pattern, filePath) {
  const hasWildcard = pattern.includes("*");
  if (hasWildcard) {
    return globMatch(normalizePatternPath(pattern), normalizePatternPath(filePath));
  }
  const normalizedPattern = normalizePatternPath(pattern);
  const normalizedPath = normalizePatternPath(filePath);
  if (normalizedPath === normalizedPattern)
    return true;
  if (normalizedPath.startsWith(normalizedPattern + import_node_path15.sep))
    return true;
  return false;
}
function matchesPlugin(pattern, pluginKey) {
  const hasWildcard = pattern.includes("*");
  if (hasWildcard) {
    return globMatch(pattern, pluginKey);
  }
  if (pluginKey === pattern)
    return true;
  if (pluginKey.startsWith(pattern) && pluginKey[pattern.length] === "@")
    return true;
  return false;
}
function matchesRegex(pattern, value) {
  let re;
  try {
    re = new RegExp(pattern);
  } catch {
    return false;
  }
  const start = performance.now();
  try {
    const result = re.test(value);
    if (performance.now() - start > REGEX_TIMEOUT_MS) {
      return false;
    }
    return result;
  } catch {
    return false;
  }
}
function globMatch(pattern, value) {
  const normPattern = pattern.replace(/\\/g, "/");
  const normValue = value.replace(/\\/g, "/");
  const regexStr = globToRegex(normPattern);
  try {
    const re = new RegExp(`^${regexStr}$`);
    return re.test(normValue);
  } catch {
    return false;
  }
}
function globToRegex(pattern) {
  let result = "";
  let i = 0;
  while (i < pattern.length) {
    const ch = pattern[i];
    if (ch === void 0)
      break;
    if (ch === "*" && pattern[i + 1] === "*") {
      result += ".*";
      i += 2;
      if (i < pattern.length && pattern[i] === "/")
        i++;
    } else if (ch === "*") {
      result += "[^/]*";
      i++;
    } else if (ch === "?") {
      result += "[^/]";
      i++;
    } else {
      result += escapeRegex(ch);
      i++;
    }
  }
  return result;
}
function escapeRegex(char) {
  return char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function findDenyException(rules, artifacts) {
  const denyRules = rules.filter((r) => r.decision === "deny");
  for (const artifact of artifacts) {
    for (const rule of denyRules) {
      if (matchesArtifact(rule, artifact)) {
        return { rule, artifact };
      }
    }
  }
  return null;
}
function findAllowException(rules, artifacts) {
  const allowRules = rules.filter((r) => r.decision === "allow");
  const execRules = allowRules.filter((r) => r.match === "executable");
  if (execRules.length > 0) {
    for (const artifact of artifacts) {
      if (artifact.type !== "command")
        continue;
      const match = execRules.find((r) => matchesExecutable(r.pattern, artifact.value));
      if (match)
        return match;
    }
  }
  const pathRules = allowRules.filter((r) => r.match === "path");
  if (pathRules.length > 0) {
    for (const artifact of artifacts) {
      if (artifact.type !== "file_path")
        continue;
      const match = pathRules.find((r) => matchesPath(r.pattern, artifact.value));
      if (match)
        return match;
    }
  }
  const domainRules = allowRules.filter((r) => r.match === "domain");
  const firstDomainRule = domainRules[0];
  if (firstDomainRule && artifacts.length > 0 && artifacts.every((a) => a.type === "url")) {
    if (artifacts.every((a) => domainRules.some((r) => matchesDomain(r.pattern, a.value)))) {
      return firstDomainRule;
    }
  }
  const regexRules = allowRules.filter((r) => r.match === "regex");
  const firstRegexRule = regexRules[0];
  if (firstRegexRule && artifacts.length > 0) {
    if (artifacts.every((a) => regexRules.some((r) => matchesRegex(r.pattern, a.value)))) {
      return firstRegexRule;
    }
  }
  return null;
}
function findPluginDenyException(rules, pluginKey) {
  const found = rules.find((r) => r.decision === "deny" && r.match === "plugin" && matchesPlugin(r.pattern, pluginKey));
  return found ?? null;
}
function findPluginAllowException(rules, pluginKey) {
  const found = rules.find((r) => r.decision === "allow" && r.match === "plugin" && matchesPlugin(r.pattern, pluginKey));
  return found ?? null;
}
function matchesArtifact(rule, artifact) {
  switch (rule.match) {
    case "executable":
      return artifact.type === "command" && matchesExecutable(rule.pattern, artifact.value);
    case "domain":
      return artifact.type === "url" && matchesDomain(rule.pattern, artifact.value);
    case "path":
      return artifact.type === "file_path" && matchesPath(rule.pattern, artifact.value);
    case "regex":
      return matchesRegex(rule.pattern, artifact.value);
    case "plugin":
      return false;
  }
}

// ../core/dist/extractors.js
var URL_PATTERN = /https?:\/\/[^\s"')<>[\]{}]+/g;
var TRAILING_PUNCT = /[.,;:!?]+$/;
var MAX_CONTENT_SIZE = 64 * 1024;
var BASE64_DECODE_EXEC = /\b(echo|printf|cat)\b[^|]*\|\s*base64\s+(-d|--decode)[^|]*\|\s*(bash|sh|zsh|ksh|dash|python|perl|ruby|node)\b/;
var PRINTF_ENCODE_EXEC = /\bprintf\b\s+['"](\\x[0-9a-fA-F]{2}|\\[0-7]{3})[^|]*\|\s*(bash|sh|zsh|ksh|dash)\b/;
var VAR_INTERPOLATION_URL = /\b(curl|wget|fetch)\b[^|;]*(\$\{?\w+\}?\.\$\{?\w+\}?|\$\{?\w+\}?:\/\/)/;
var SHELLS = "bash|sh|zsh|ksh|dash";
function extractUrls(text) {
  const seen = /* @__PURE__ */ new Set();
  const urls = [];
  for (const match of text.matchAll(URL_PATTERN)) {
    const url = match[0].replace(TRAILING_PUNCT, "");
    if (!seen.has(url)) {
      seen.add(url);
      urls.push(url);
    }
  }
  return urls;
}
function escapeRegExp(str) {
  const regExpEscape = RegExp.escape;
  if (regExpEscape) {
    return regExpEscape(str);
  }
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function stripHeredocs(command) {
  return command.replace(/<<-?\s*['"]?(\w+)['"]?\n[\s\S]*?\n[ \t]*\1\b/g, "<<$1");
}
function extractFromBash(command) {
  const artifacts = [];
  const effective = stripHeredocs(command);
  artifacts.push({ type: "command", value: effective });
  if (BASE64_DECODE_EXEC.test(effective)) {
    artifacts.push({ type: "command", value: effective, context: "base64_decode_exec" });
  }
  if (PRINTF_ENCODE_EXEC.test(effective)) {
    artifacts.push({ type: "command", value: effective, context: "printf_encode_exec" });
  }
  if (VAR_INTERPOLATION_URL.test(effective)) {
    artifacts.push({ type: "command", value: effective, context: "variable_interpolation_url" });
  }
  for (const url of extractUrls(command)) {
    let context;
    const escaped = escapeRegExp(url);
    const directPipe = new RegExp(escaped + String.raw`[^|]*\|\s*(${SHELLS})\b`);
    const wrappedPipe = new RegExp(escaped + String.raw`[^|]*\|\s*\S+\s+(\S+\s+)?(${SHELLS})\b`);
    const subshellExec = new RegExp(`${String.raw`(\$\(|`}\`)${escaped}[^)\`]*${String.raw`\|\s*(${SHELLS})\b`}`);
    if (directPipe.test(command) || wrappedPipe.test(command) || subshellExec.test(command)) {
      context = "piped to shell";
    }
    artifacts.push({ type: "url", value: url, context });
  }
  return artifacts;
}
function extractFromWebFetch(toolInput) {
  const url = toolInput.url;
  if (url && typeof url === "string") {
    return [{ type: "url", value: url, context: "webfetch" }];
  }
  return [];
}
function extractFileArtifacts(toolInput, filePathKey, contentKey, contextName, urlContextName) {
  const artifacts = [];
  const filePath = toolInput[filePathKey];
  if (filePath && typeof filePath === "string") {
    artifacts.push({ type: "file_path", value: filePath, context: contextName });
  }
  const content = toolInput[contentKey];
  if (content && typeof content === "string" && content.trim()) {
    const capped = content.slice(0, MAX_CONTENT_SIZE);
    artifacts.push({ type: "content", value: capped, context: contextName });
    for (const url of extractUrls(capped)) {
      artifacts.push({ type: "url", value: url, context: urlContextName });
    }
  }
  return artifacts;
}
function extractFromWrite(toolInput) {
  return extractFileArtifacts(toolInput, "file_path", "content", "write", "from_file_content");
}
function extractFromEdit(toolInput) {
  return extractFileArtifacts(toolInput, "file_path", "new_string", "edit", "from_edit_content");
}

// ../core/dist/heuristics.js
var TRUSTED_DOMAIN_SUPPRESSIBLE = /* @__PURE__ */ new Set([
  "CLT-CMD-001",
  "CLT-CMD-002",
  "CLT-SUPPLY-001",
  "CLT-SUPPLY-004"
]);
var HeuristicsEngine = class {
  threatMap = /* @__PURE__ */ new Map();
  trustedDomains;
  constructor(threats, trustedDomains) {
    this.trustedDomains = trustedDomains ?? [];
    for (const threat of threats) {
      for (const matchType of threat.matchOn) {
        const artifactType = matchType === "domain" ? "url" : matchType;
        const existing = this.threatMap.get(artifactType);
        if (existing) {
          existing.push(threat);
        } else {
          this.threatMap.set(artifactType, [threat]);
        }
      }
    }
  }
  isSuppressedByTrustedDomain(match) {
    if (this.trustedDomains.length === 0)
      return false;
    if (!TRUSTED_DOMAIN_SUPPRESSIBLE.has(match.threat.id))
      return false;
    const urls = extractUrls(match.matchValue);
    if (urls.length === 0)
      return false;
    for (const url of urls) {
      const domain = extractDomain(url);
      if (!domain)
        return false;
      if (!isTrustedDomain(domain, this.trustedDomains))
        return false;
    }
    return true;
  }
  match(artifacts) {
    const matches = [];
    for (const artifact of artifacts) {
      const threats = this.threatMap.get(artifact.type) ?? [];
      for (const threat of threats) {
        const m = threat.compiledPattern.exec(artifact.value);
        if (m) {
          matches.push({
            threat,
            artifact: artifact.value,
            matchValue: m[0]
          });
        }
      }
    }
    if (this.trustedDomains.length > 0) {
      return matches.filter((m) => !this.isSuppressedByTrustedDomain(m));
    }
    return matches;
  }
};

// ../core/dist/package-checker.js
init_types2();
var SUSPICIOUS_AGE_DAYS = 7;
var MAX_CONCURRENT = 10;
var PackageChecker = class {
  registryClient;
  fileCheckClient;
  logger;
  constructor(config2 = {}, logger = nullLogger) {
    this.logger = logger;
    this.registryClient = new RegistryClient({ timeout_seconds: config2.registryTimeoutSeconds }, logger);
    this.fileCheckClient = config2.fileCheckEnabled !== false ? new FileCheckClient({
      endpoint: config2.fileCheckEndpoint,
      timeout_seconds: config2.fileCheckTimeoutSeconds
    }, logger) : null;
  }
  async checkPackages(packages) {
    const toCheck = [];
    const results = [];
    for (const pkg of packages) {
      if (pkg.name.startsWith("@")) {
        results.push({
          packageName: pkg.name,
          registry: pkg.registry,
          verdict: "clean",
          confidence: 1,
          details: "Scoped package \u2014 skipped (v1)"
        });
      } else {
        toCheck.push(pkg);
      }
    }
    const checkResults = await this.runWithConcurrencyLimit(toCheck, (pkg) => this.checkSinglePackage(pkg), MAX_CONCURRENT);
    results.push(...checkResults);
    return results;
  }
  async checkSinglePackage(pkg) {
    let metadata;
    try {
      metadata = await this.registryClient.getPackageMetadata(pkg.name, pkg.registry, pkg.version);
    } catch {
      return {
        packageName: pkg.name,
        registry: pkg.registry,
        verdict: "unknown",
        confidence: 0.6,
        details: `Package check for '${pkg.name}' timed out (verify manually)`
      };
    }
    if (metadata === null) {
      return {
        packageName: pkg.name,
        registry: pkg.registry,
        verdict: "not_found",
        confidence: 0.95,
        details: `Package '${pkg.name}' not found on ${pkg.registry} (non-existent or misspelled)`
      };
    }
    if (!metadata.requestedVersionFound && pkg.version) {
      return {
        packageName: pkg.name,
        registry: pkg.registry,
        verdict: "not_found",
        confidence: 0.95,
        details: `Package '${pkg.name}@${pkg.version}' version not found on ${pkg.registry} (hallucinated or unpublished)`
      };
    }
    if (metadata.latestHash && this.fileCheckClient && metadata.hashAlgorithm === "sha256") {
      try {
        const fileResult = await this.fileCheckClient.checkHash(metadata.latestHash);
        if (fileResult) {
          const sev = fileResult.severity.toUpperCase();
          if (sev === "SEVERITY_MALWARE") {
            const detections = fileResult.detectionNames.length > 0 ? fileResult.detectionNames.join(", ") : sev;
            return {
              packageName: pkg.name,
              registry: pkg.registry,
              verdict: "malicious",
              confidence: 1,
              details: `Malicious package '${pkg.name}' (${detections})`,
              fileCheckSeverity: sev,
              fileSha256: metadata.latestHash,
              fileDetectionNames: fileResult.detectionNames
            };
          }
        }
      } catch {
        this.logger.warn("File-check failed for package", { name: pkg.name });
      }
    }
    const ageDays = metadata.firstReleaseDate ? (Date.now() - metadata.firstReleaseDate.getTime()) / (1e3 * 60 * 60 * 24) : void 0;
    if (ageDays !== void 0 && ageDays < SUSPICIOUS_AGE_DAYS) {
      return {
        packageName: pkg.name,
        registry: pkg.registry,
        verdict: "suspicious_age",
        confidence: 0.6,
        details: `Package '${pkg.name}' first published ${Math.floor(ageDays)} days ago (suspicious age)`,
        ageDays
      };
    }
    return {
      packageName: pkg.name,
      registry: pkg.registry,
      verdict: "clean",
      confidence: 1,
      details: `Package '${pkg.name}' verified on ${pkg.registry}`,
      ageDays
    };
  }
  async runWithConcurrencyLimit(items, fn, limit) {
    const results = [];
    const executing = [];
    for (const item of items) {
      const p = fn(item).then((r) => {
        results.push(r);
      });
      executing.push(p);
      if (executing.length >= limit) {
        await Promise.race(executing);
        for (let i = executing.length - 1; i >= 0; i--) {
          const settled = await Promise.race([
            executing[i]?.then(() => true),
            Promise.resolve(false)
          ]);
          if (settled)
            executing.splice(i, 1);
        }
      }
    }
    await Promise.allSettled(executing);
    return results;
  }
};

// ../core/dist/package-extractor.js
function extractPackagesFromCommand(command) {
  const packages = [];
  const normalized = command.replace(/^(\s*(sudo|env\s+\S+=\S+)\s+)+/g, "").trim();
  const commands = normalized.split(/\s*(?:&&|;|\|)\s*/);
  for (const cmd of commands) {
    const tokens = shellTokenize(cmd.trim());
    if (tokens.length === 0)
      continue;
    const binary = tokens[0]?.replace(/^.*[/\\]/, "") ?? "";
    if (["npm", "npx"].includes(binary)) {
      packages.push(...extractNpmPackages(tokens));
    } else if (binary === "yarn") {
      packages.push(...extractYarnPackages(tokens));
    } else if (["pnpm", "bunx"].includes(binary)) {
      packages.push(...extractPnpmBunPackages(tokens, binary));
    } else if (binary === "bun") {
      packages.push(...extractBunPackages(tokens));
    } else if (["pip", "pip3"].includes(binary)) {
      packages.push(...extractPipPackages(tokens));
    } else if (["python", "python3", "python.exe", "python3.exe"].includes(binary) || binary.match(/python3?\.\d+/) || binary.endsWith("/python") || binary.endsWith("/python3")) {
      if (tokens[1] === "-m" && ["pip", "pip3"].includes(tokens[2] ?? "")) {
        packages.push(...extractPipPackages(tokens.slice(2)));
      }
    }
  }
  return packages;
}
function extractPackagesFromManifest(filePath, content) {
  const lowerPath = filePath.toLowerCase().replace(/\\/g, "/");
  if (lowerPath.endsWith("package.json")) {
    return extractFromPackageJson(content);
  }
  if (lowerPath.endsWith("requirements.txt")) {
    return extractFromRequirementsTxt(content);
  }
  return [];
}
function shellTokenize(cmd) {
  const tokens = [];
  let current = "";
  let inSingle = false;
  let inDouble = false;
  for (const ch of cmd) {
    if (ch === "'" && !inDouble) {
      inSingle = !inSingle;
    } else if (ch === '"' && !inSingle) {
      inDouble = !inDouble;
    } else if (/\s/.test(ch) && !inSingle && !inDouble) {
      if (current)
        tokens.push(current);
      current = "";
    } else {
      current += ch;
    }
  }
  if (current)
    tokens.push(current);
  return tokens;
}
var PEP440_CANONICAL_RE = /^\d+(\.\d+)*([._-]?(a|alpha|b|beta|c|rc|pre|preview|post|rev|dev)\d*)*$/i;
function isPep440Canonical(version) {
  if (!version)
    return false;
  if (version.includes("*") || version.includes(","))
    return false;
  return PEP440_CANONICAL_RE.test(version);
}
function pypiExactVersion(operator, version) {
  if (!operator || !version)
    return void 0;
  if (operator === "==")
    return isPep440Canonical(version) ? version : void 0;
  if (operator === "===")
    return `===${version}`;
  return void 0;
}
function isPackageName(token) {
  if (token.startsWith("-"))
    return false;
  if (!/^[a-zA-Z@]/.test(token))
    return false;
  if (token.startsWith("https://") || token.startsWith("http://"))
    return false;
  if (token.startsWith("git+"))
    return false;
  if (token.startsWith("./") || token.startsWith("../") || token.startsWith("/"))
    return false;
  if (token.startsWith("file:"))
    return false;
  if (token === ".")
    return false;
  return true;
}
function splitNameVersion(token) {
  if (token.startsWith("@")) {
    const afterScope = token.indexOf("/");
    if (afterScope === -1)
      return { name: token };
    const rest = token.slice(afterScope + 1);
    const atIdx2 = rest.indexOf("@");
    if (atIdx2 > 0) {
      return {
        name: `${token.slice(0, afterScope + 1)}${rest.slice(0, atIdx2)}`,
        version: rest.slice(atIdx2 + 1)
      };
    }
    return { name: token };
  }
  const atIdx = token.indexOf("@");
  if (atIdx > 0) {
    return { name: token.slice(0, atIdx), version: token.slice(atIdx + 1) };
  }
  return { name: token };
}
var NPM_VALUE_FLAGS = /* @__PURE__ */ new Set([
  "--registry",
  "--tag",
  "--workspace",
  "-w",
  "--prefix",
  "--cache",
  "--userconfig",
  "--globalconfig"
]);
function extractNpmPackages(tokens) {
  const packages = [];
  const binary = tokens[0]?.replace(/^.*[/\\]/, "") ?? "";
  if (binary === "npx") {
    for (let i = 1; i < tokens.length; i++) {
      const t = tokens[i] ?? "";
      if (t === "--" || t === "-y" || t === "--yes" || t === "-p" || t === "--package")
        continue;
      if (t.startsWith("-"))
        continue;
      if (!isPackageName(t))
        break;
      const { name, version } = splitNameVersion(t);
      packages.push({ name, version, registry: "npm", source: "command" });
      break;
    }
    return packages;
  }
  const subcommand = tokens[1] ?? "";
  if (!["install", "i", "add", "ci"].includes(subcommand))
    return packages;
  let skipNext = false;
  for (let i = 2; i < tokens.length; i++) {
    const t = tokens[i] ?? "";
    if (skipNext) {
      skipNext = false;
      continue;
    }
    if (NPM_VALUE_FLAGS.has(t)) {
      skipNext = true;
      continue;
    }
    if (t.startsWith("-"))
      continue;
    if (!isPackageName(t))
      break;
    const { name, version } = splitNameVersion(t);
    packages.push({ name, version, registry: "npm", source: "command" });
  }
  return packages;
}
function extractYarnPackages(tokens) {
  const packages = [];
  const subcommand = tokens[1] ?? "";
  if (subcommand !== "add")
    return packages;
  for (let i = 2; i < tokens.length; i++) {
    const t = tokens[i] ?? "";
    if (t.startsWith("-"))
      continue;
    if (!isPackageName(t))
      break;
    const { name, version } = splitNameVersion(t);
    packages.push({ name, version, registry: "npm", source: "command" });
  }
  return packages;
}
function extractPnpmBunPackages(tokens, binary) {
  const packages = [];
  if (binary === "bunx") {
    for (let i = 1; i < tokens.length; i++) {
      const t = tokens[i] ?? "";
      if (t.startsWith("-"))
        continue;
      if (!isPackageName(t))
        break;
      const { name, version } = splitNameVersion(t);
      packages.push({ name, version, registry: "npm", source: "command" });
      break;
    }
    return packages;
  }
  const subcommand = tokens[1] ?? "";
  if (subcommand === "dlx") {
    for (let i = 2; i < tokens.length; i++) {
      const t = tokens[i] ?? "";
      if (t.startsWith("-"))
        continue;
      if (!isPackageName(t))
        break;
      const { name, version } = splitNameVersion(t);
      packages.push({ name, version, registry: "npm", source: "command" });
      break;
    }
    return packages;
  }
  if (!["add", "install", "i"].includes(subcommand))
    return packages;
  for (let i = 2; i < tokens.length; i++) {
    const t = tokens[i] ?? "";
    if (t.startsWith("-"))
      continue;
    if (!isPackageName(t))
      break;
    const { name, version } = splitNameVersion(t);
    packages.push({ name, version, registry: "npm", source: "command" });
  }
  return packages;
}
function extractBunPackages(tokens) {
  const packages = [];
  const subcommand = tokens[1] ?? "";
  if (!["add", "install", "i"].includes(subcommand))
    return packages;
  for (let i = 2; i < tokens.length; i++) {
    const t = tokens[i] ?? "";
    if (t.startsWith("-"))
      continue;
    if (!isPackageName(t))
      break;
    const { name, version } = splitNameVersion(t);
    packages.push({ name, version, registry: "npm", source: "command" });
  }
  return packages;
}
function extractPipPackages(tokens) {
  const packages = [];
  const subcommand = tokens[1] ?? "";
  if (subcommand !== "install")
    return packages;
  let skipNext = false;
  for (let i = 2; i < tokens.length; i++) {
    const t = tokens[i] ?? "";
    if (skipNext) {
      skipNext = false;
      continue;
    }
    if ([
      "-r",
      "--requirement",
      "-c",
      "--constraint",
      "-e",
      "--editable",
      "-t",
      "--target",
      "--prefix",
      "-i",
      "--index-url",
      "--extra-index-url",
      "-f",
      "--find-links"
    ].includes(t)) {
      skipNext = true;
      continue;
    }
    if (t.startsWith("-"))
      continue;
    if (!isPackageName(t))
      break;
    const match = t.match(/^([a-zA-Z0-9._-]+)(?:([><=!~]+)(.+))?$/);
    if (match) {
      packages.push({
        name: match[1],
        version: pypiExactVersion(match[2], match[3]),
        registry: "pypi",
        source: "command"
      });
    }
  }
  return packages;
}
function extractFromPackageJson(content) {
  const packages = [];
  try {
    const data = JSON.parse(content);
    const deps = data.dependencies ?? {};
    const devDeps = data.devDependencies ?? {};
    for (const [name, version] of Object.entries({ ...deps, ...devDeps })) {
      if (typeof version !== "string")
        continue;
      if (version === "" || version === "*")
        continue;
      if (version.startsWith("file:") || version.startsWith("link:") || version.startsWith("git+") || version.startsWith("git:") || version.startsWith("http:") || version.startsWith("https:") || version.startsWith("workspace:") || version.startsWith("github:") || version.startsWith("bitbucket:") || version.startsWith("gitlab:") || version.startsWith("portal:") || version.startsWith("patch:"))
        continue;
      if (version.startsWith("npm:")) {
        const aliasTarget = version.slice(4);
        const { name: targetName, version: targetVersion } = splitNameVersion(aliasTarget);
        if (targetName) {
          packages.push({
            name: targetName,
            version: targetVersion ?? "",
            registry: "npm",
            source: "package.json"
          });
        }
        continue;
      }
      packages.push({
        name,
        version,
        registry: "npm",
        source: "package.json"
      });
    }
  } catch {
  }
  return packages;
}
function extractFromRequirementsTxt(content) {
  const packages = [];
  const lines = content.split("\n");
  for (const rawLine of lines) {
    const line = rawLine.trim();
    if (!line || line.startsWith("#") || line.startsWith("-r") || line.startsWith("--requirement") || line.startsWith("-e") || line.startsWith("--editable") || line.startsWith("-i") || line.startsWith("--index-url") || line.startsWith("--extra-index-url") || line.startsWith("-f") || line.startsWith("--find-links") || line.startsWith("-c") || line.startsWith("--constraint")) {
      continue;
    }
    if (line.startsWith("git+") || line.startsWith("http://") || line.startsWith("https://")) {
      continue;
    }
    const cleaned = line.split("#")[0]?.split(";")[0]?.trim() ?? "";
    if (!cleaned)
      continue;
    const match = cleaned.match(/^([a-zA-Z0-9._-]+)(?:\[.*\])?(?:([><=!~]+)(.+))?$/);
    if (match) {
      packages.push({
        name: match[1],
        version: pypiExactVersion(match[2], match[3]?.trim()),
        registry: "pypi",
        source: "requirements.txt"
      });
    }
  }
  return packages;
}

// ../core/dist/statusline.js
var import_node_path16 = require("node:path");
init_config();
init_file_utils();
var STATUS_PREFIX = "statusline-";
var STATUS_SUFFIX = ".txt";
function sanitizeSessionId(sessionId) {
  return sessionId.replace(/[^a-zA-Z0-9-]/g, "_");
}
function statusFilePath(sessionId) {
  return (0, import_node_path16.join)(resolvePath(SAGE_DIR), `${STATUS_PREFIX}${sanitizeSessionId(sessionId)}${STATUS_SUFFIX}`);
}
function emptyStatus() {
  const now = (/* @__PURE__ */ new Date()).toISOString();
  return {
    denied: 0,
    flagged: 0,
    lastCategory: null,
    lastReason: null,
    updatedAt: now,
    startedAt: now
  };
}
async function readStatus(sessionId) {
  try {
    const raw = await getFileContent(statusFilePath(sessionId), "utf-8");
    return JSON.parse(raw);
  } catch {
    return emptyStatus();
  }
}
async function updateSessionStatus(sessionId, verdict) {
  const status = await readStatus(sessionId);
  if (verdict.decision === "deny") {
    status.denied++;
  } else if (verdict.decision === "ask") {
    status.flagged++;
  }
  status.lastCategory = verdict.category;
  status.lastReason = verdict.reasons[0] ?? null;
  status.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
  await atomicWriteJson(statusFilePath(sessionId), status);
}

// ../core/dist/threat-loader.js
var import_promises7 = require("node:fs/promises");
var import_node_path17 = require("node:path");
var import_yaml2 = __toESM(require_dist(), 1);
init_file_utils();
init_types2();
var REQUIRED_FIELDS = /* @__PURE__ */ new Set([
  "id",
  "category",
  "severity",
  "confidence",
  "pattern",
  "match_on",
  "title"
]);
function parseExpiresAt(value) {
  if (value == null)
    return null;
  try {
    const date = new Date(String(value));
    return Number.isNaN(date.getTime()) ? null : date;
  } catch {
    return null;
  }
}
function isExpired(entry) {
  const expiresAt = parseExpiresAt(entry.expires_at);
  if (expiresAt === null)
    return false;
  return Date.now() > expiresAt.getTime();
}
async function loadThreats(threatDir, logger = nullLogger) {
  const threats = [];
  let files;
  try {
    files = (await (0, import_promises7.readdir)(threatDir)).filter((f) => f.endsWith(".yaml")).sort();
  } catch {
    logger.warn("Threat directory does not exist or is unreadable", { path: threatDir });
    return threats;
  }
  for (const filename of files) {
    const filePath = (0, import_node_path17.join)(threatDir, filename);
    let content;
    try {
      content = await getFileContent(filePath);
    } catch (e) {
      logger.warn(`Failed to read ${filename}`, { error: String(e) });
      continue;
    }
    let data;
    try {
      data = (0, import_yaml2.parse)(content);
    } catch (e) {
      logger.warn(`Failed to parse ${filename}`, { error: String(e) });
      continue;
    }
    if (!Array.isArray(data)) {
      logger.warn(`Expected list in ${filename}, got ${typeof data}`);
      continue;
    }
    for (const entry of data) {
      if (typeof entry !== "object" || entry === null) {
        logger.warn(`Skipping non-object entry in ${filename}`);
        continue;
      }
      const record = entry;
      const keys = new Set(Object.keys(record));
      const missing = [...REQUIRED_FIELDS].filter((f) => !keys.has(f));
      if (missing.length > 0) {
        logger.warn(`Skipping threat in ${filename}: missing fields ${missing.join(", ")}`);
        continue;
      }
      if (record.revoked === true)
        continue;
      if (isExpired(record))
        continue;
      let compiledPattern;
      try {
        const flags2 = record.case_insensitive === true ? "i" : "";
        compiledPattern = new RegExp(record.pattern, flags2);
      } catch (e) {
        logger.warn(`Skipping threat ${record.id}: invalid regex pattern`, {
          error: String(e)
        });
        continue;
      }
      const rawMatchOn = record.match_on;
      const matchOn = new Set(Array.isArray(rawMatchOn) ? rawMatchOn : [rawMatchOn]);
      const rawFlags = record.flags;
      const flags = Array.isArray(rawFlags) ? rawFlags : [];
      const confidence = Number(record.confidence);
      if (!Number.isFinite(confidence) || confidence <= 0 || confidence > 1) {
        logger.warn(`Skipping threat ${record.id}: invalid confidence value`, {
          confidence: record.confidence
        });
        continue;
      }
      threats.push({
        id: record.id,
        version: typeof record.version === "number" ? record.version : void 0,
        category: record.category,
        severity: record.severity,
        confidence,
        pattern: record.pattern,
        compiledPattern,
        matchOn,
        title: record.title,
        expiresAt: parseExpiresAt(record.expires_at),
        revoked: false,
        flags
      });
    }
  }
  logger.debug(`Loaded ${threats.length} threats from ${threatDir}`);
  return threats;
}

// ../core/dist/evaluator.js
init_types2();
var AMSI_CONTENT_SNIPPET_MAX = 200;
var AMSI_CONTENT_NAME_MAX = 256;
function scrubAmsiContentName(contentName) {
  const colon = contentName.indexOf(":");
  if (colon < 0)
    return scrubHomePath(contentName);
  const head = contentName.slice(0, colon + 1);
  const tail = contentName.slice(colon + 1);
  return `${head}${scrubHomePath(tail)}`;
}
function buildAmsiSignal(r) {
  const detectionName = r.amsiResult >= 32768 ? "AMSI|DETECTED" : r.amsiResult >= 16384 ? "AMSI|BLOCKED_BY_ADMIN" : (
    // Defensive: callers should filter these out via `isDetected || isBlockedByAdmin`,
    // but if a non-detected/non-blocked result still reaches here we emit a
    // meaningful label rather than silently dropping the entry.
    "AMSI|UNKNOWN"
  );
  const contentName = safeTruncate(scrubAmsiContentName(r.contentName), AMSI_CONTENT_NAME_MAX);
  const snippet = r.content ? safeTruncate(scrubHomePath(r.content), AMSI_CONTENT_SNIPPET_MAX) : "";
  return {
    detection_name: detectionName,
    content_name: contentName,
    amsi_result: r.amsiResult,
    ...snippet ? { content_snippet: snippet } : {}
  };
}
function allowVerdict(source = "none") {
  return {
    decision: "allow",
    category: "none",
    confidence: 0,
    severity: "info",
    source,
    artifacts: [],
    matchedThreatId: null,
    reasons: []
  };
}
async function resolveEvaluationConfig(context, logger) {
  if (context.config)
    return context.config;
  return loadConfig(context.configPath, logger).catch(() => ConfigSchema.parse({}));
}
function shouldSkipPromptInjectionForLocalMarkdown(request) {
  if (request.toolName !== "Write" && request.toolName !== "Edit")
    return false;
  const filePath = resolveFilePath(request.toolInput) ?? "";
  const trimmed = filePath.trim();
  return /\.(?:md|mdx|markdown|mdown|mkdn)$/i.test(trimmed);
}
async function evaluateToolCall(request, context) {
  const logger = context.logger ?? nullLogger;
  const config2 = await resolveEvaluationConfig(context, logger);
  const eventId = (0, import_node_crypto6.randomUUID)();
  logger.debug("Tool call evaluation started", {
    eventId,
    toolUseId: request.toolUseId,
    toolName: request.toolName,
    hookType: request.hookType,
    agentRuntime: request.agentRuntime,
    artifactsCount: request.artifacts.length
  });
  const logEvaluationCompleted = (verdict2) => {
    logger.debug("Tool call evaluation completed", {
      eventId,
      toolUseId: request.toolUseId,
      toolName: request.toolName,
      hookType: request.hookType,
      agentRuntime: request.agentRuntime,
      artifactsCount: request.artifacts.length,
      decision: verdict2.decision,
      source: verdict2.source,
      category: verdict2.category,
      severity: verdict2.severity
    });
  };
  if (request.artifacts.length === 0 && !config2.pi_check.enabled) {
    const verdict2 = allowVerdict("no_artifacts");
    logEvaluationCompleted(verdict2);
    return verdict2;
  }
  try {
    const exceptions = await loadExceptions(config2.exceptions, logger);
    const denyMatch = findDenyException(exceptions, request.artifacts);
    if (denyMatch) {
      const verdict2 = {
        decision: "deny",
        category: "exception",
        confidence: 1,
        severity: "critical",
        source: "exception",
        artifacts: [denyMatch.artifact.value],
        matchedThreatId: null,
        reasons: [
          `Deny exception: ${denyMatch.rule.match} pattern '${denyMatch.rule.pattern}'${denyMatch.rule.reason ? ` \u2014 ${denyMatch.rule.reason}` : ""}`
        ]
      };
      try {
        await logVerdict(config2.logging, {
          sessionId: request.sessionId,
          toolName: request.toolName,
          toolInput: request.toolInput,
          verdict: verdict2,
          conversationId: request.conversationId,
          agentRuntime: request.agentRuntime,
          hookType: request.hookType,
          eventId,
          toolUseId: request.toolUseId
        });
      } catch {
      }
      logEvaluationCompleted(verdict2);
      return verdict2;
    }
    const allowMatch = findAllowException(exceptions, request.artifacts);
    if (allowMatch) {
      const allowV = allowVerdict("exception");
      try {
        await logVerdict(config2.logging, {
          sessionId: request.sessionId,
          toolName: request.toolName,
          toolInput: request.toolInput,
          verdict: allowV,
          userOverride: true,
          conversationId: request.conversationId,
          agentRuntime: request.agentRuntime,
          hookType: request.hookType,
          eventId,
          toolUseId: request.toolUseId
        });
      } catch {
      }
      logEvaluationCompleted(allowV);
      return allowV;
    }
  } catch (error) {
    logger.debug("Exception checks failed open", { error: String(error) });
  }
  let cache2 = null;
  try {
    cache2 = new VerdictCache(config2.cache, logger, VERSION);
    await cache2.load();
  } catch (error) {
    logger.debug("Verdict cache initialization failed open", { error: String(error) });
    cache2 = null;
  }
  const urls = request.artifacts.filter((artifact) => artifact.type === "url").map((artifact) => artifact.value);
  const { cachedUrlVerdicts, uncachedUrls } = partitionUrlsByCache(urls, cache2);
  let heuristicMatches = [];
  if (config2.heuristics_enabled) {
    let threats = await loadThreats(context.threatsDir, logger);
    if (config2.disabled_threats.length > 0) {
      const disabledSet = new Set(config2.disabled_threats);
      threats = threats.filter((t) => !disabledSet.has(t.id));
    }
    if (shouldSkipPromptInjectionForLocalMarkdown(request)) {
      threats = threats.filter((t) => t.category !== "prompt_injection");
    }
    const trustedDomains = await loadTrustedDomains(context.trustedDomainsDir, logger);
    const heuristics = new HeuristicsEngine(threats, trustedDomains);
    heuristicMatches = heuristics.match(request.artifacts);
  }
  let urlCheckResults = [];
  const urlsToCheck = cache2 ? uncachedUrls : urls;
  if (urlsToCheck.length > 0 && config2.url_check.enabled) {
    try {
      const client = new UrlCheckClient(config2.url_check, logger);
      urlCheckResults = await client.checkUrls(urlsToCheck);
    } catch {
    }
  }
  const packageCheckResults = await checkPackages(request, config2, cache2, logger);
  const amsiCheckResults = [];
  if (config2.amsi_check.enabled && isAmsiSupported()) {
    let amsiClient = null;
    let amsiLease = null;
    let ownsAmsiClient = false;
    try {
      if (context.acquireAmsiClientLease) {
        amsiLease = await context.acquireAmsiClientLease(logger);
        amsiClient = amsiLease?.client ?? null;
      } else {
        amsiClient = new AmsiClient(logger);
        ownsAmsiClient = true;
        await amsiClient.init();
      }
      if (amsiClient?.isAvailable) {
        const activeAmsiClient = amsiClient;
        const scans = [];
        if (request.toolName === "Bash") {
          const command = request.toolInput.command ?? "";
          if (command) {
            scans.push({ scanType: "Bash", name: "command", content: command });
          }
        } else if (request.toolName === "Write") {
          const filePath = request.toolInput.file_path ?? "";
          const content = request.toolInput.content ?? "";
          if (content) {
            scans.push({ scanType: "Write", name: filePath, content });
          }
        } else if (request.toolName === "Edit") {
          const filePath = request.toolInput.file_path ?? "";
          const newString = request.toolInput.new_string ?? "";
          if (newString) {
            scans.push({ scanType: "Edit", name: filePath, content: newString });
          }
        } else if (request.toolName === "ApplyPatch") {
          const patch = request.toolInput.input ?? request.toolInput.patch ?? "";
          if (patch) {
            const target = request.artifacts.find((a) => a.type === "file_path");
            scans.push({
              scanType: "ApplyPatch",
              name: target?.value ?? "unknown",
              content: patch
            });
          }
        }
        for (const scan of scans) {
          const result = await activeAmsiClient.scanString(scan.scanType, scan.name, scan.content);
          if (result) {
            amsiCheckResults.push(result);
          }
        }
      }
    } catch {
    } finally {
      try {
        if (amsiLease) {
          await amsiLease.release();
        } else if (ownsAmsiClient) {
          amsiClient?.close();
        }
      } catch {
      }
    }
  }
  const engine = new DecisionEngine(config2.sensitivity, logger);
  const preliminaryVerdict = await engine.decide({
    heuristicMatches,
    urlCheckResults,
    packageCheckResults: packageCheckResults.length > 0 ? packageCheckResults : void 0,
    amsiCheckResults: amsiCheckResults.length > 0 ? amsiCheckResults : void 0
  });
  const allPiResults = [];
  const alreadyDenied = preliminaryVerdict.decision === "deny" || cachedUrlVerdicts.size > 0 && [...cachedUrlVerdicts.values()].some((v) => v.verdict === "deny");
  if (config2.pi_check.enabled && !alreadyDenied && request.toolName === "WebFetch") {
    try {
      const url = extractWebFetchUrl(request.toolInput);
      if (url) {
        const ext = getUrlExtension(url);
        const skip = ext != null && !SCANNABLE_EXTENSIONS.has(ext);
        if (!skip) {
          const fetcher = new ContentFetchClient(4e3, config2.pi_check.max_content_length, logger);
          const fetched = await fetcher.fetchTextContent(url);
          if (fetched) {
            const shouldScan = ext != null || isScannableContent(fetched.content);
            if (shouldScan) {
              const provider = createPiProvider(config2, context, logger);
              const result = await provider.checkContent(fetched.content, `WebFetch:${url}`);
              if (result) {
                allPiResults.push(result);
              }
            }
          }
        }
      }
    } catch {
    }
  }
  let verdict;
  if (allPiResults.length > 0) {
    verdict = await engine.decide({
      heuristicMatches,
      urlCheckResults,
      packageCheckResults: packageCheckResults.length > 0 ? packageCheckResults : void 0,
      amsiCheckResults: amsiCheckResults.length > 0 ? amsiCheckResults : void 0,
      piCheckResults: allPiResults,
      piThresholds: {
        highRisk: DEFAULT_PI_HIGH_RISK_THRESHOLD,
        mediumRisk: DEFAULT_PI_MEDIUM_RISK_THRESHOLD
      }
    });
  } else {
    verdict = preliminaryVerdict;
  }
  if (cachedUrlVerdicts.size > 0 && verdict.decision !== "deny") {
    for (const [url, cachedVerdict] of cachedUrlVerdicts) {
      if (cachedVerdict.verdict === "allow") {
        continue;
      }
      if (cachedVerdict.verdict === "deny" || verdict.decision === "allow") {
        verdict = {
          decision: cachedVerdict.verdict,
          category: "network_egress",
          confidence: 1,
          severity: cachedVerdict.severity,
          source: `cache(${cachedVerdict.source})`,
          artifacts: [url],
          matchedThreatId: null,
          reasons: cachedVerdict.reasons
        };
        if (verdict.decision === "deny")
          break;
      }
    }
  }
  await cacheUrlResults(urlCheckResults, cache2);
  function formatPackageDetectionName(p) {
    const base = `PKG|${p.verdict}|registry=${p.registry}|name=${p.packageName}`;
    if (p.verdict === "suspicious_age") {
      const ageDays = typeof p.ageDays === "number" ? Math.floor(p.ageDays) : void 0;
      return ageDays !== void 0 ? `${base}|age_days=${ageDays}` : base;
    }
    if (p.verdict === "malicious") {
      const det = (p.fileDetectionNames ?? []).filter((d) => typeof d === "string" && d.length > 0);
      return det.length > 0 ? `${base}|det=${det.join(",")}` : base;
    }
    return base;
  }
  const auditSignals = {};
  if (heuristicMatches.length > 0) {
    auditSignals.heuristics = heuristicMatches.map((m) => ({
      rule_id: m.threat.id,
      rule_version: typeof m.threat.version === "number" ? m.threat.version : void 0
    }));
  }
  if (urlCheckResults.length > 0) {
    const relevant = urlCheckResults.filter((r) => r.isMalicious);
    if (relevant.length > 0) {
      auditSignals.url_checks = relevant.flatMap((r) => {
        return r.detections.map((d) => ({
          detection_name: d,
          url: r.url
        }));
      });
    }
  }
  if (cachedUrlVerdicts.size > 0) {
    for (const [url, cachedEntry] of cachedUrlVerdicts) {
      if (cachedEntry.verdict !== "deny")
        continue;
      const labels = cachedEntry.urlSignalLabels ?? [];
      if (labels.length === 0)
        continue;
      auditSignals.url_checks ??= [];
      auditSignals.url_checks.push(...labels.map((label) => ({
        detection_name: label,
        url
      })));
    }
  }
  if (packageCheckResults.length > 0) {
    const relevant = packageCheckResults.filter((p) => p.verdict !== "clean");
    if (relevant.length > 0) {
      auditSignals.package_checks = relevant.map((p) => ({
        detection_name: formatPackageDetectionName(p),
        package_name: p.packageName,
        package_version: void 0,
        package_registry: p.registry
      }));
    }
    const fileRelevant = relevant.filter((p) => !!p.fileSha256 && (p.fileDetectionNames?.length ?? 0) > 0);
    if (fileRelevant.length > 0) {
      auditSignals.file_checks = fileRelevant.map((p) => ({
        detection_name: (p.fileDetectionNames ?? []).join(","),
        file_sha256: p.fileSha256
      }));
    }
  }
  if (allPiResults.length > 0) {
    const piSnippetFloor = DEFAULT_PI_MEDIUM_RISK_THRESHOLD;
    auditSignals.pi_checks = allPiResults.map((r) => ({
      risk: r.risk,
      model_id: r.modelId,
      content_name: r.contentName,
      ...r.contentSnippet && r.risk >= piSnippetFloor ? { content_snippet: scrubHomePath(r.contentSnippet) } : {}
    }));
  }
  if (amsiCheckResults.length > 0) {
    const relevantAmsi = amsiCheckResults.filter((r) => r.isDetected || r.isBlockedByAdmin);
    if (relevantAmsi.length > 0) {
      auditSignals.amsi_checks = relevantAmsi.map((r) => buildAmsiSignal(r));
    }
  }
  const resolvedSignals = Object.keys(auditSignals).length > 0 ? auditSignals : void 0;
  const builtContent = buildContentSnapshot(request.toolName, request.toolInput, request.artifacts, auditSignals);
  const resolvedContent = Object.keys(builtContent).length > 0 ? builtContent : void 0;
  try {
    await logVerdict(config2.logging, {
      sessionId: request.sessionId,
      toolName: request.toolName,
      toolInput: request.toolInput,
      verdict,
      conversationId: request.conversationId,
      agentRuntime: request.agentRuntime,
      hookType: request.hookType,
      signals: resolvedSignals,
      content: resolvedContent,
      eventId,
      toolUseId: request.toolUseId
    });
  } catch (error) {
    logger.debug("Audit verdict logging failed open", { error: String(error) });
  }
  const submitTelemetry = async (blocking) => {
    try {
      await sendCommunityIqTelemetry({
        eventId,
        agentRuntime: request.agentRuntime,
        agentRuntimeVersion: request.agentRuntimeVersion,
        hookType: request.hookType,
        toolName: request.toolName,
        content: resolvedContent,
        signals: resolvedSignals,
        communityIqEnabled: config2.community_iq,
        config: config2,
        blocking,
        logger
      });
    } catch (error) {
      logger.debug("Community IQ telemetry failed open", { error: String(error) });
    }
  };
  if (verdict.decision === "deny") {
    await submitTelemetry(true);
  } else if (allPiResults.some((r) => r.risk >= DEFAULT_PI_TELEMETRY_THRESHOLD && r.risk < DEFAULT_PI_HIGH_RISK_THRESHOLD)) {
    await submitTelemetry(false);
  }
  if (verdict.decision !== "allow") {
    try {
      await updateSessionStatus(request.sessionId, verdict);
    } catch (error) {
      logger.debug("Session status update failed open", { error: String(error) });
    }
  }
  const piWarnings = allPiResults.filter((r) => r.risk >= DEFAULT_PI_MEDIUM_RISK_THRESHOLD && r.risk < DEFAULT_PI_HIGH_RISK_THRESHOLD);
  if (piWarnings.length > 0 && config2.sensitivity !== "relaxed")
    verdict.piWarnings = piWarnings;
  logEvaluationCompleted(verdict);
  return verdict;
}
function partitionUrlsByCache(urls, cache2) {
  const cachedUrlVerdicts = /* @__PURE__ */ new Map();
  let uncachedUrls = [];
  if (cache2 && urls.length > 0) {
    try {
      for (const url of urls) {
        const cached = cache2.getUrl(url);
        if (cached !== null) {
          cachedUrlVerdicts.set(url, cached);
        } else {
          uncachedUrls.push(url);
        }
      }
    } catch {
      uncachedUrls = urls;
    }
  }
  return { cachedUrlVerdicts, uncachedUrls };
}
async function cacheUrlResults(urlCheckResults, cache2) {
  if (!cache2)
    return;
  try {
    for (const result of urlCheckResults) {
      let cachedVerdict;
      if (result.isMalicious) {
        cachedVerdict = {
          verdict: "deny",
          severity: "critical",
          reasons: [
            `URL check: malicious (${result.findings.map((finding) => `${finding.severityName}/${finding.typeName}`).join(", ")})`
          ],
          source: "url_check",
          // Always populated for malicious URLs (possibly empty array). Locked in by
          // evaluator.test.ts so a future refactor cannot silently drop the labels.
          urlSignalLabels: result.detections
        };
      } else {
        cachedVerdict = {
          verdict: "allow",
          severity: "info",
          reasons: [],
          source: "url_check"
        };
      }
      cache2.putUrl(result.url, cachedVerdict, result.isMalicious);
    }
    await cache2.save();
  } catch {
  }
}
async function checkPackages(request, config2, cache2, logger) {
  const results = [];
  if (!config2.package_check.enabled)
    return results;
  try {
    let parsedPackages;
    if (request.toolName === "Bash") {
      const command = request.toolInput.command ?? "";
      parsedPackages = extractPackagesFromCommand(command);
    } else if (request.toolName === "Write" || request.toolName === "Edit") {
      const filePath = request.toolInput.file_path ?? "";
      const content = request.toolInput.content ?? request.toolInput.new_string ?? "";
      parsedPackages = extractPackagesFromManifest(filePath, content);
    }
    if (!parsedPackages || parsedPackages.length === 0)
      return results;
    const DENY_CLASS_PKG_VERDICTS = /* @__PURE__ */ new Set(["malicious", "not_found"]);
    const ASK_CLASS_PKG_VERDICTS = /* @__PURE__ */ new Set(["suspicious_age", "unknown"]);
    const VALID_PKG_VERDICTS = /* @__PURE__ */ new Set([...DENY_CLASS_PKG_VERDICTS, ...ASK_CLASS_PKG_VERDICTS]);
    const uncached = [];
    for (const pkg of parsedPackages) {
      const cacheKey2 = `${pkg.registry}:${pkg.name}${pkg.version ? `@${pkg.version}` : ""}`;
      const cached = cache2?.getPackage(cacheKey2);
      if (!cached) {
        uncached.push(pkg);
        continue;
      }
      if (cached.verdict === "allow")
        continue;
      const rawVerdict = cached.packageVerdict;
      const rawConf = cached.packageConfidence;
      const verdictValid = rawVerdict !== void 0 && VALID_PKG_VERDICTS.has(rawVerdict);
      const confValid = rawConf !== void 0 && Number.isFinite(rawConf) && rawConf > 0 && rawConf <= 1;
      const consistent = rawVerdict === void 0 || !verdictValid || cached.verdict === "deny" && DENY_CLASS_PKG_VERDICTS.has(rawVerdict) || cached.verdict === "ask" && ASK_CLASS_PKG_VERDICTS.has(rawVerdict);
      if (!verdictValid || !confValid || !consistent) {
        logger.warn("Package cache entry has invalid metadata; re-querying live", {
          cacheKey: cacheKey2,
          packageVerdict: rawVerdict,
          packageConfidence: rawConf,
          cachedVerdict: cached.verdict
        });
        uncached.push(pkg);
        continue;
      }
      results.push({
        packageName: pkg.name,
        registry: pkg.registry,
        verdict: rawVerdict,
        confidence: rawConf,
        details: cached.reasons.join("; ")
      });
    }
    if (uncached.length > 0) {
      const checker = new PackageChecker({
        registryTimeoutSeconds: config2.package_check.timeout_seconds,
        fileCheckEndpoint: config2.file_check.endpoint,
        fileCheckTimeoutSeconds: config2.file_check.timeout_seconds,
        fileCheckEnabled: config2.file_check.enabled
      }, logger);
      const checked = await checker.checkPackages(uncached);
      results.push(...checked);
      if (cache2) {
        for (const result of checked) {
          const pkg = uncached.find((p) => p.name === result.packageName);
          const cacheKey2 = `${result.registry}:${result.packageName}${pkg?.version ? `@${pkg.version}` : ""}`;
          const isCritical = result.verdict === "malicious" || result.verdict === "not_found";
          cache2.putPackage(cacheKey2, {
            verdict: result.verdict === "clean" ? "allow" : isCritical ? "deny" : "ask",
            severity: isCritical ? "critical" : "warning",
            reasons: [result.details],
            source: "package_check",
            packageVerdict: result.verdict,
            packageConfidence: result.confidence
          }, result.ageDays ?? null);
        }
      }
    }
  } catch {
  }
  return results;
}
function createPiProvider(config2, _context, logger) {
  return new BundledPiProvider({
    modelPath: config2.pi_check.model_path,
    maxContentLength: config2.pi_check.max_content_length,
    mediumRiskThreshold: DEFAULT_PI_MEDIUM_RISK_THRESHOLD,
    logger
  });
}

// ../core/dist/index.js
init_file_utils();

// ../core/dist/format.js
var PAD = 12;
var SEPARATOR_WIDTH = 48;
function severityEmoji(severity) {
  const s = severity.toLowerCase();
  if (s === "critical")
    return "\u{1F6A8}";
  if (s === "warning")
    return "\u26A0\uFE0F";
  return "\u2139\uFE0F";
}
function kv(key, value) {
  return `   ${key.padEnd(PAD)}${value}`;
}
function separatorLine(headerLength) {
  return "\u2501".repeat(headerLength);
}
function formatUpdateNotice(result) {
  return `\u2B06\uFE0F  Update available: v${result.currentVersion} \u2192 v${result.latestVersion} (https://github.com/gendigitalinc/sage)`;
}
function formatStartupClean(version, versionCheck, branding2 = defaultBranding) {
  const base = `\u{1F6E1}\uFE0F ${branding2.name} v${version} \u2705 No threats found`;
  if (versionCheck?.updateAvailable) {
    return `${base}
${formatUpdateNotice(versionCheck)}`;
  }
  return base;
}
function totalNonInfo(results) {
  let n = 0;
  for (const r of results) {
    for (const f of r.findings) {
      if (f.severity !== "info")
        n++;
    }
  }
  return n;
}
function findFirstNonInfo(results) {
  for (const r of results) {
    for (const f of r.findings) {
      if (f.severity !== "info") {
        return { plugin: r.plugin, finding: f };
      }
    }
  }
  return null;
}
function formatThreatBannerVerbose(version, results, versionCheck, branding2) {
  const header = `\u{1F6E1}\uFE0F ${branding2.name} v${version} \u2014 Threat Detected`;
  const lines = [" ", header, separatorLine(SEPARATOR_WIDTH)];
  const MAX_FINDINGS = 5;
  let first = true;
  for (const result of results) {
    const nonInfo = result.findings.filter((f) => f.severity !== "info");
    if (nonInfo.length === 0)
      continue;
    for (const f of nonInfo.slice(0, MAX_FINDINGS)) {
      if (!first)
        lines.push("");
      first = false;
      const emoji = severityEmoji(f.severity);
      lines.push(`${emoji} ${`Plugin`.padEnd(PAD)}${result.plugin.key}`);
      lines.push(kv("Threat", f.title));
      lines.push(kv("Severity", f.severity.toUpperCase()));
      if (f.artifact) {
        lines.push(kv("Artifact", f.artifact));
      }
      lines.push(kv("Source", f.sourceFile));
      if (f.recommendations && f.recommendations.length > 0) {
        lines.push(kv("Recommendations", ""));
        for (const rec of f.recommendations) {
          lines.push(`   ${" ".repeat(PAD)}- ${rec}`);
        }
      }
    }
    const overflow = nonInfo.length - MAX_FINDINGS;
    if (overflow > 0) {
      lines.push("");
      lines.push(`   ... and ${overflow} more findings`);
    }
  }
  if (versionCheck?.updateAvailable) {
    lines.push("");
    lines.push(formatUpdateNotice(versionCheck));
  }
  return lines.join("\n");
}
function formatThreatBannerCompact(version, results, versionCheck, branding2) {
  const total = totalNonInfo(results);
  const first = findFirstNonInfo(results);
  if (!first || total === 0) {
    return formatStartupClean(version, versionCheck, branding2);
  }
  const emoji = severityEmoji(first.finding.severity);
  const lines = [
    `\u{1F6E1}\uFE0F ${branding2.name} v${version} \u2014 Threat Detected in ${first.plugin.key}`,
    `${emoji} ${first.finding.title} (${first.finding.severity.toUpperCase()})`,
    first.finding.sourceFile
  ];
  const remaining = total - 1;
  if (remaining > 0) {
    lines.push(`\u2026and ${remaining} more finding${remaining === 1 ? "" : "s"}`);
  }
  if (versionCheck?.updateAvailable) {
    lines.push(formatUpdateNotice(versionCheck));
  }
  return lines.join("\n");
}
function formatThreatBanner(version, results, versionCheck, branding2 = defaultBranding, style = "verbose") {
  if (style === "compact") {
    return formatThreatBannerCompact(version, results, versionCheck, branding2);
  }
  return formatThreatBannerVerbose(version, results, versionCheck, branding2);
}
function formatSessionStartMessage(version, result, branding2 = defaultBranding, style = "verbose") {
  if (result.scanResults.length > 0) {
    return formatThreatBanner(version, result.scanResults, result.versionCheck, branding2, style);
  }
  return formatStartupClean(version, result.versionCheck, branding2);
}

// ../core/dist/guard.js
init_config();
init_types2();
async function guardToolCall(request, context, approvalStore) {
  const actionId = ApprovalStore.actionId(request.toolName, request.toolInput, request.sessionId);
  if (approvalStore.isApproved(actionId)) {
    return { verdict: allowVerdict("approved") };
  }
  const verdict = await evaluateToolCall(request, context);
  if (verdict.decision === "allow" || verdict.decision === "deny") {
    return { verdict };
  }
  const logger = context.logger ?? nullLogger;
  const config2 = await loadConfig(context.configPath, logger);
  if (config2.sensitivity === "paranoid") {
    return { verdict: { ...verdict, decision: "deny" } };
  }
  approvalStore.setPending(actionId, {
    artifacts: request.artifacts,
    createdAt: Date.now()
  });
  return { verdict, actionId };
}
var MAX_ARTIFACT_VALUE_LEN = 120;
function truncateValue(value) {
  const singleLine = value.replaceAll("\n", "\\n");
  if (singleLine.length <= MAX_ARTIFACT_VALUE_LEN)
    return singleLine;
  return `${singleLine.slice(0, MAX_ARTIFACT_VALUE_LEN)}\u2026`;
}
function summarizeArtifacts(artifacts) {
  if (artifacts.length === 0)
    return "none";
  const maxArtifacts = 3;
  const summary = artifacts.slice(0, maxArtifacts).map((artifact) => `${artifact.type} '${truncateValue(artifact.value)}'`).join(", ");
  const overflow = artifacts.length - maxArtifacts;
  return overflow > 0 ? `${summary}, ... and ${overflow} more` : summary;
}
function formatDenyMessage(verdict, branding2 = defaultBranding) {
  const maxReasons = 5;
  const reasons = verdict.reasons.length > 0 ? verdict.reasons.slice(0, maxReasons).join("; ") + (verdict.reasons.length > maxReasons ? `; ... and ${verdict.reasons.length - maxReasons} more` : "") : verdict.category;
  return [
    `${branding2.name} blocked this action.`,
    `Severity: ${verdict.severity}`,
    `Category: ${verdict.category}`,
    `Reason: ${reasons}`,
    `If this is a false positive, use the sage_report_false_positive MCP tool to report it.`
  ].join("\n");
}

// ../core/dist/install-state.js
var import_node_path18 = require("node:path");
init_config();
init_file_utils();

// ../core/dist/notices.js
init_config();
var SKILL_UPLOAD_NOTICE = {
  id: "skill_upload_v1",
  body: () => [
    "unknown skills \u2014 each skill's SKILL.md and every supporting file in its",
    "folder \u2014 will be uploaded and checked against potential malicious artifacts",
    "starting next session. To keep skill content on this machine, set",
    '"skill_check": { "upload_enabled": false } in ~/.sage/config.json.'
  ],
  // Suppressed once the user has explicitly set upload_enabled either way: an
  // explicit choice needs no consent prompt (the rollout obeys it directly).
  isEligible: async ({ configPath, logger }) => !(await readExplicitSkillUploadEnabled(configPath, logger)).present
};
var NOTICES = {
  [SKILL_UPLOAD_NOTICE.id]: SKILL_UPLOAD_NOTICE
};
var INFO_ICON = "\u2139\uFE0F";
var CONTINUATION_INDENT = "   ";
function formatNotice(notice, branding2 = defaultBranding) {
  const [first = "", ...rest] = notice.body(branding2);
  const head = `${INFO_ICON}  ${branding2.name}: ${first}`;
  return [head, ...rest.map((line) => `${CONTINUATION_INDENT}${line}`)].join("\n");
}
function formatNoticeById(id, branding2 = defaultBranding) {
  const notice = NOTICES[id];
  return notice ? formatNotice(notice, branding2) : "";
}

// ../core/dist/install-state.js
init_types2();
var INSTALL_STATE_SCHEMA_VERSION = 1;
var SKILL_UPLOAD_NOTICE_ID = SKILL_UPLOAD_NOTICE.id;
function defaultStatePath(sageDirPath) {
  return (0, import_node_path18.join)(sageDirPath ?? resolvePath(SAGE_DIR), "install-state.json");
}
function emptyState() {
  return { schemaVersion: INSTALL_STATE_SCHEMA_VERSION, notices: {} };
}
async function loadInstallState(sageDirPath, logger = nullLogger) {
  let raw;
  try {
    raw = await getFileContent(defaultStatePath(sageDirPath));
  } catch {
    return emptyState();
  }
  try {
    const data = JSON.parse(raw);
    const rawNotices = data.notices ?? {};
    const notices = {};
    for (const [id, rec] of Object.entries(rawNotices)) {
      notices[id] = {
        noticed: rec.noticed === true,
        version: typeof rec.version === "string" ? rec.version : void 0
      };
    }
    return {
      schemaVersion: typeof data.schema_version === "number" ? data.schema_version : INSTALL_STATE_SCHEMA_VERSION,
      lastRunVersion: typeof data.last_run_version === "string" ? data.last_run_version : void 0,
      notices
    };
  } catch (e) {
    logger.warn("Failed to parse install state; treating as fresh", { error: String(e) });
    return emptyState();
  }
}
async function saveInstallState(state, sageDirPath, logger = nullLogger) {
  try {
    const data = {
      schema_version: state.schemaVersion,
      last_run_version: state.lastRunVersion,
      notices: Object.fromEntries(Object.entries(state.notices).map(([id, rec]) => [
        id,
        { noticed: rec.noticed, version: rec.version }
      ]))
    };
    await atomicWriteJson(defaultStatePath(sageDirPath), data);
  } catch (e) {
    logger.warn("Failed to save install state", { error: String(e) });
  }
}
function decideSkillUploadRollout(state, opts = {}) {
  const versionChanged = opts.version !== void 0 && state.lastRunVersion !== opts.version;
  const withVersion = () => ({ ...state, lastRunVersion: opts.version });
  if (opts.explicitConfig) {
    return {
      uploadActive: opts.explicitValue === true,
      showNotice: false,
      nextState: versionChanged ? withVersion() : null
    };
  }
  const notice = state.notices[SKILL_UPLOAD_NOTICE_ID];
  if (notice?.noticed === true) {
    return {
      uploadActive: true,
      showNotice: false,
      nextState: versionChanged ? withVersion() : null
    };
  }
  const nextState = {
    ...state,
    lastRunVersion: opts.version ?? state.lastRunVersion,
    notices: {
      ...state.notices,
      [SKILL_UPLOAD_NOTICE_ID]: { noticed: true, version: opts.version }
    }
  };
  return { uploadActive: false, showNotice: true, nextState };
}
var processRollout;
async function resolveSkillUploadRollout(args) {
  const commitNotice = args.commitNotice ?? true;
  const logger = args.logger ?? nullLogger;
  let explicit;
  try {
    explicit = await readExplicitSkillUploadEnabled(args.configPath, logger);
  } catch {
    explicit = { present: false, value: false };
  }
  if (explicit.present) {
    const resolved = {
      uploadActive: explicit.value === true,
      showNotice: false,
      deferUnknownSkills: false
    };
    logger.debug("Skill-upload rollout resolved", {
      explicitConfig: true,
      explicitValue: explicit.value,
      uploadActive: resolved.uploadActive,
      showNotice: false,
      deferUnknownSkills: false,
      commitNotice,
      statePersisted: false,
      version: args.version
    });
    return resolved;
  }
  if (processRollout)
    return processRollout;
  try {
    const state = await loadInstallState(args.sageDirPath, logger);
    const decision = decideSkillUploadRollout(state, { version: args.version });
    if (commitNotice) {
      if (decision.nextState) {
        await saveInstallState(decision.nextState, args.sageDirPath, logger);
      }
      processRollout = {
        uploadActive: decision.uploadActive,
        showNotice: decision.showNotice,
        deferUnknownSkills: decision.showNotice
      };
    } else {
      processRollout = {
        uploadActive: decision.uploadActive,
        showNotice: false,
        deferUnknownSkills: decision.showNotice
      };
    }
    logger.debug("Skill-upload rollout resolved", {
      explicitConfig: false,
      uploadActive: processRollout.uploadActive,
      showNotice: processRollout.showNotice,
      deferUnknownSkills: processRollout.deferUnknownSkills,
      commitNotice,
      statePersisted: commitNotice && decision.nextState !== null,
      version: args.version
    });
  } catch (e) {
    logger.warn("Skill-upload rollout resolution failed; suppressing upload", {
      error: String(e)
    });
    processRollout = { uploadActive: false, showNotice: commitNotice, deferUnknownSkills: true };
  }
  return processRollout;
}
async function takePendingNotices(args) {
  const logger = args.logger ?? nullLogger;
  try {
    const state = await loadInstallState(args.sageDirPath, logger);
    const toShow = [];
    for (const notice of Object.values(NOTICES)) {
      if (state.notices[notice.id]?.noticed === true)
        continue;
      const eligible = notice.isEligible ? await notice.isEligible({ configPath: args.configPath, logger }) : true;
      if (eligible)
        toShow.push(notice.id);
    }
    if (toShow.length === 0)
      return [];
    const nextNotices = { ...state.notices };
    for (const id of toShow)
      nextNotices[id] = { noticed: true };
    await saveInstallState({ ...state, notices: nextNotices }, args.sageDirPath, logger);
    logger.debug("Pending notices taken for delivery", { noticeIds: toShow });
    return toShow;
  } catch (e) {
    logger.warn("takePendingNotices failed; showing no notices this turn", {
      error: String(e)
    });
    return [];
  }
}

// ../core/dist/model-download.js
init_types2();

// ../core/dist/operational-log.js
var LEVEL_PRIORITY = {
  debug: 10,
  info: 20,
  warn: 30,
  error: 40
};
var FLUSH_TIMEOUT_MS = 250;
function shouldLog(config2, level) {
  return config2.enabled && LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[config2.level];
}
function normalizeData(data) {
  if (!data)
    return void 0;
  const seen = /* @__PURE__ */ new WeakSet();
  try {
    return JSON.parse(JSON.stringify(data, (_key, value) => {
      if (typeof value === "bigint")
        return value.toString();
      if (value instanceof Error) {
        return { name: value.name, message: value.message, stack: value.stack };
      }
      if (value && typeof value === "object") {
        if (seen.has(value))
          return "[Circular]";
        seen.add(value);
      }
      return value;
    }));
  } catch {
    return { serialization_error: "Failed to serialize log data" };
  }
}
async function writeOperationalLogEntry(config2, entry) {
  if (!shouldLog(config2, entry.level))
    return;
  try {
    await appendJsonlEntry(config2, entry);
  } catch {
  }
}
function createOperationalLogger(config2, runtime) {
  const pendingWrites = /* @__PURE__ */ new Set();
  function log(component, level, message, data) {
    if (!shouldLog(config2, level))
      return;
    const entry = {
      timestamp: (/* @__PURE__ */ new Date()).toISOString(),
      level,
      runtime,
      component,
      message,
      ...data ? { data: normalizeData(data) } : {}
    };
    const write = writeOperationalLogEntry(config2, entry);
    pendingWrites.add(write);
    void write.finally(() => pendingWrites.delete(write));
  }
  async function flush() {
    const deadline = Date.now() + FLUSH_TIMEOUT_MS;
    while (pendingWrites.size > 0) {
      const remainingMs = deadline - Date.now();
      if (remainingMs <= 0)
        return;
      let timeout;
      try {
        const result = await Promise.race([
          Promise.allSettled([...pendingWrites]).then(() => "drained"),
          new Promise((resolve10) => {
            timeout = setTimeout(() => resolve10("timeout"), remainingMs);
            timeout.unref?.();
          })
        ]);
        if (result === "timeout")
          return;
      } finally {
        if (timeout)
          clearTimeout(timeout);
      }
    }
  }
  function forComponent(component) {
    return {
      debug(msg, data) {
        log(component, "debug", msg, data);
      },
      info(msg, data) {
        log(component, "info", msg, data);
      },
      warn(msg, data) {
        log(component, "warn", msg, data);
      },
      error(msg, data) {
        log(component, "error", msg, data);
      },
      flush
    };
  }
  return {
    debug(component, msg, data) {
      log(component, "debug", msg, data);
    },
    info(component, msg, data) {
      log(component, "info", msg, data);
    },
    warn(component, msg, data) {
      log(component, "warn", msg, data);
    },
    error(component, msg, data) {
      log(component, "error", msg, data);
    },
    forComponent,
    flush
  };
}

// ../core/dist/plugin-scan-cache.js
var import_node_crypto7 = require("node:crypto");
var import_promises8 = require("node:fs/promises");
var import_node_path19 = require("node:path");
init_config();
init_file_utils();
init_types2();
var DEFAULT_CACHE_PATH = (0, import_node_path19.join)(getHomeDir(), ".sage", "plugin_scan_cache.json");
var DEFAULT_CACHE_TTL_MS = MS_PER_DAY;
var SCHEMA_VERSION = 5;
function cacheKey(pluginKey, version, lastUpdated) {
  return `${pluginKey}:${version}:${lastUpdated}`;
}
async function computeConfigHash(sageVersion, ...dirs) {
  const h = (0, import_node_crypto7.createHash)("sha256");
  if (sageVersion)
    h.update(sageVersion);
  for (const dir of dirs) {
    let files;
    try {
      files = (await (0, import_promises8.readdir)(dir)).filter((f) => f.endsWith(".yaml")).sort();
    } catch {
      continue;
    }
    for (const file of files) {
      try {
        const content = await getFileContent((0, import_node_path19.join)(dir, file));
        h.update(content);
      } catch {
      }
    }
  }
  return h.digest("hex").slice(0, 16);
}
async function loadScanCache(configHash = "", cachePath = DEFAULT_CACHE_PATH, logger = nullLogger) {
  let raw;
  try {
    raw = await getFileContent(cachePath);
  } catch {
    return { configHash, entries: {} };
  }
  try {
    const data = JSON.parse(raw);
    const storedVersion = data.schema_version ?? 1;
    if (storedVersion !== SCHEMA_VERSION) {
      logger.debug("Schema version changed, invalidating plugin scan cache", {
        from: storedVersion,
        to: SCHEMA_VERSION
      });
      return { configHash, entries: {} };
    }
    const storedHash = data.config_hash ?? "";
    if (configHash && storedHash !== configHash) {
      logger.debug("Config hash changed, invalidating plugin scan cache", {
        from: storedHash,
        to: configHash
      });
      return { configHash, entries: {} };
    }
    const entries = {};
    const rawEntries = data.entries ?? {};
    for (const [key, entryData] of Object.entries(rawEntries)) {
      entries[key] = {
        pluginKey: entryData.plugin_key,
        version: entryData.version,
        scannedAt: entryData.scanned_at,
        findings: entryData.findings ?? []
      };
    }
    return { configHash: configHash || storedHash, entries };
  } catch (e) {
    logger.warn(`Failed to load scan cache from ${cachePath}`, { error: String(e) });
    return { configHash, entries: {} };
  }
}
async function saveScanCache(cache2, cachePath = DEFAULT_CACHE_PATH, logger = nullLogger) {
  try {
    const data = {
      schema_version: SCHEMA_VERSION,
      config_hash: cache2.configHash,
      entries: Object.fromEntries(Object.entries(cache2.entries).map(([key, entry]) => [
        key,
        {
          plugin_key: entry.pluginKey,
          version: entry.version,
          scanned_at: entry.scannedAt,
          findings: entry.findings
        }
      ]))
    };
    await atomicWriteJson(cachePath, data);
  } catch (e) {
    logger.warn(`Failed to save scan cache to ${cachePath}`, { error: String(e) });
  }
}
function isCached(cache2, pluginKey, version, lastUpdated, ttlMs = DEFAULT_CACHE_TTL_MS) {
  const key = cacheKey(pluginKey, version, lastUpdated);
  const entry = cache2.entries[key];
  if (!entry)
    return false;
  try {
    const scannedAt = new Date(entry.scannedAt);
    const age = Date.now() - scannedAt.getTime();
    return age < ttlMs;
  } catch {
    return false;
  }
}
function getCached(cache2, pluginKey, version, lastUpdated, ttlMs = DEFAULT_CACHE_TTL_MS) {
  if (!isCached(cache2, pluginKey, version, lastUpdated, ttlMs))
    return null;
  const key = cacheKey(pluginKey, version, lastUpdated);
  return cache2.entries[key] ?? null;
}
function storeResult(cache2, pluginKey, version, lastUpdated, findings) {
  const key = cacheKey(pluginKey, version, lastUpdated);
  cache2.entries[key] = {
    pluginKey,
    version,
    scannedAt: (/* @__PURE__ */ new Date()).toISOString(),
    findings
  };
}

// ../core/dist/plugin-scanner.js
var import_node_crypto9 = require("node:crypto");
var import_promises11 = require("node:fs/promises");
var import_node_path23 = require("node:path");
init_config();
init_file_utils();

// ../core/dist/skill-id.js
var import_node_crypto8 = require("node:crypto");
var import_promises9 = require("node:fs/promises");
var import_node_path20 = require("node:path");
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "__pycache__"]);
var MAX_SKILL_BYTES = 50 * 1024 * 1024;
var SkillTooLargeError = class extends Error {
};
function isContained(childReal, rootReal) {
  return childReal === rootReal || childReal.startsWith(`${rootReal}${import_node_path20.sep}`);
}
function normalizePath(p) {
  let out = p.replace(/\\/g, "/").normalize("NFC");
  out = out.split("/").filter((c) => c !== "" && c !== ".").join("/");
  while (out.startsWith("./") || out.startsWith("/")) {
    out = out.startsWith("./") ? out.slice(2) : out.slice(1);
  }
  return out;
}
async function entriesFromDirectory(dirPath, maxBytes = Number.POSITIVE_INFINITY) {
  const absDir = (0, import_node_path20.resolve)(dirPath);
  const rootReal = await (0, import_promises9.realpath)(absDir);
  const entries = [];
  const visited = /* @__PURE__ */ new Set();
  let total = 0;
  async function walk(currentPath) {
    const real = await (0, import_promises9.realpath)(currentPath);
    if (visited.has(real))
      return;
    if (!isContained(real, rootReal))
      return;
    visited.add(real);
    const items = await (0, import_promises9.readdir)(currentPath);
    const dirs = [];
    const files = [];
    for (const item of items) {
      const fullPath = (0, import_node_path20.join)(currentPath, item);
      const st = await (0, import_promises9.stat)(fullPath);
      if (st.isDirectory())
        dirs.push(item);
      else if (st.isFile())
        files.push({ name: item, size: st.size });
    }
    dirs.sort();
    files.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
    for (const d of dirs) {
      const fullPath = (0, import_node_path20.join)(currentPath, d);
      const relPath = (0, import_node_path20.relative)(absDir, fullPath).replace(/\\/g, "/");
      entries.push({ entryPath: relPath, isDir: true, content: Buffer.alloc(0) });
      await walk(fullPath);
    }
    for (const f of files) {
      const fullPath = (0, import_node_path20.join)(currentPath, f.name);
      const fileReal = await (0, import_promises9.realpath)(fullPath);
      if (!isContained(fileReal, rootReal))
        continue;
      total += f.size;
      if (total > maxBytes)
        throw new SkillTooLargeError();
      const relPath = (0, import_node_path20.relative)(absDir, fullPath).replace(/\\/g, "/");
      entries.push({
        entryPath: relPath,
        isDir: false,
        content: await (0, import_promises9.readFile)(fullPath)
      });
    }
  }
  await walk(absDir);
  return entries;
}
function computeSkillId(entries) {
  let normalized = entries.map((e) => ({ ...e, entryPath: normalizePath(e.entryPath) })).filter((e) => e.entryPath !== "");
  if (normalized.length > 0) {
    const topLevel = new Set(normalized.map((e) => e.entryPath.split("/")[0]));
    if (topLevel.size === 1) {
      const prefix = `${[...topLevel][0]}/`;
      normalized = normalized.map((e) => ({
        ...e,
        entryPath: e.entryPath.startsWith(prefix) ? e.entryPath.slice(prefix.length) : e.entryPath
      })).filter((e) => e.entryPath !== "");
    }
  }
  normalized = normalized.filter((e) => e.entryPath !== "skill.sig");
  const fileHashes = {};
  const treeEntries = [];
  for (const e of normalized) {
    const contentHash = (0, import_node_crypto8.createHash)("sha256").update(e.isDir ? Buffer.alloc(0) : e.content).digest("hex");
    const entryType = e.isDir ? "dir" : "file";
    treeEntries.push({ type: entryType, entryPath: e.entryPath, hash: contentHash });
    if (!e.isDir)
      fileHashes[e.entryPath] = contentHash;
  }
  treeEntries.sort((a, b) => a.entryPath < b.entryPath ? -1 : a.entryPath > b.entryPath ? 1 : 0);
  const skillHasher = (0, import_node_crypto8.createHash)("sha256");
  for (const e of treeEntries) {
    skillHasher.update(Buffer.from(`${e.type}\0${e.entryPath}\0${e.hash}
`, "utf8"));
  }
  return { skillId: skillHasher.digest("hex"), fileHashes };
}
async function findSkillPackagesWithMtime(rootDir) {
  const found = [];
  let rootReal;
  try {
    rootReal = await (0, import_promises9.realpath)((0, import_node_path20.resolve)(rootDir));
  } catch {
    return found;
  }
  const visited = /* @__PURE__ */ new Set();
  async function walk(currentPath) {
    let real;
    try {
      real = await (0, import_promises9.realpath)(currentPath);
    } catch {
      return 0;
    }
    if (visited.has(real))
      return 0;
    if (!isContained(real, rootReal))
      return 0;
    visited.add(real);
    let st;
    try {
      st = await (0, import_promises9.stat)(currentPath);
    } catch {
      return 0;
    }
    let subtreeMax = st.mtimeMs;
    if (!st.isDirectory())
      return subtreeMax;
    let items;
    try {
      items = await (0, import_promises9.readdir)(currentPath);
    } catch {
      return subtreeMax;
    }
    items.sort();
    let entry;
    if (items.includes("SKILL.md")) {
      try {
        if ((await (0, import_promises9.stat)((0, import_node_path20.join)(currentPath, "SKILL.md"))).isFile()) {
          entry = { folder: currentPath, newestMtimeMs: 0 };
          found.push(entry);
        }
      } catch {
      }
    }
    for (const item of items) {
      if (SKIP_DIRS.has(item))
        continue;
      const childMax = await walk((0, import_node_path20.join)(currentPath, item));
      if (childMax > subtreeMax)
        subtreeMax = childMax;
    }
    if (entry)
      entry.newestMtimeMs = subtreeMax;
    return subtreeMax;
  }
  await walk((0, import_node_path20.resolve)(rootDir));
  return found;
}
function looseSkillKey(skillsRoot, folder, tag, scope) {
  const rel = (0, import_node_path20.relative)((0, import_node_path20.resolve)(skillsRoot), (0, import_node_path20.resolve)(folder)).split(import_node_path20.sep).join("/") || (0, import_node_path20.basename)(folder);
  return `skill:${tag}/${rel}@${scope}`;
}
async function discoverLooseSkills(skillsDir, tag, scope) {
  const resolvedRoot = (0, import_node_path20.resolve)(skillsDir);
  const packages = (await findSkillPackagesWithMtime(skillsDir)).filter((p) => (0, import_node_path20.resolve)(p.folder) !== resolvedRoot);
  return packages.map(({ folder, newestMtimeMs }) => ({
    key: looseSkillKey(resolvedRoot, folder, tag, scope),
    installPath: folder,
    version: scope,
    lastUpdated: new Date(newestMtimeMs).toISOString()
  }));
}
async function dedupeSkillsByResolvedPath(skills) {
  const seen = /* @__PURE__ */ new Set();
  const out = [];
  for (const skill of skills) {
    let canonical = skill.installPath;
    try {
      canonical = await (0, import_promises9.realpath)(skill.installPath);
    } catch {
    }
    if (seen.has(canonical))
      continue;
    seen.add(canonical);
    out.push(skill);
  }
  return out;
}
async function discoverLooseSkillsAcrossRoots(roots) {
  const lists = await Promise.all(roots.map(async ({ dir, tag, scope }) => {
    try {
      return await discoverLooseSkills(dir, tag, scope);
    } catch {
      return [];
    }
  }));
  return lists.length <= 1 ? lists[0] ?? [] : dedupeSkillsByResolvedPath(lists.flat());
}
async function computeSkillIdsForRoot(rootDir, logger) {
  const folders = (await findSkillPackagesWithMtime(rootDir)).map((p) => p.folder);
  const out = [];
  for (const folder of folders) {
    try {
      const entries = await entriesFromDirectory(folder, MAX_SKILL_BYTES);
      const { skillId } = computeSkillId(entries);
      out.push({ folder, skillId });
    } catch (e) {
      if (e instanceof SkillTooLargeError) {
        logger?.warn("Skill directory exceeds 50 MB limit; skipping", { folder });
      }
    }
  }
  return out;
}

// ../core/dist/skill-pending.js
var import_promises10 = require("node:fs/promises");
var import_node_path21 = require("node:path");
init_config();
init_file_utils();
init_types2();
var SCHEMA_VERSION2 = 1;
var PENDING_TTL_MS = 60 * 60 * 1e3;
function defaultPendingPath() {
  return (0, import_node_path21.join)(resolvePath(SAGE_DIR), "skill_pending.json");
}
async function loadPendingMarker(pendingPath = defaultPendingPath(), logger = nullLogger) {
  let raw;
  try {
    raw = await getFileContent(pendingPath);
  } catch {
    return { entries: {} };
  }
  try {
    const data = JSON.parse(raw);
    const rawEntries = data.entries ?? {};
    const now = Date.now();
    const entries = {};
    for (const [skillId, entry] of Object.entries(rawEntries)) {
      const folder = entry.folder;
      const submittedAt = entry.submitted_at;
      if (!folder || !submittedAt)
        continue;
      const ts = Date.parse(submittedAt);
      if (!isFreshTimestamp(ts, PENDING_TTL_MS, now))
        continue;
      entries[skillId] = {
        folder,
        submittedAt,
        agentRuntime: typeof entry.agent_runtime === "string" ? entry.agent_runtime : void 0,
        containerKey: typeof entry.container_key === "string" ? entry.container_key : void 0
      };
    }
    return { entries };
  } catch (e) {
    logger.warn(`Failed to load pending marker from ${pendingPath}`, { error: String(e) });
    return { entries: {} };
  }
}
async function savePendingMarker(marker, pendingPath = defaultPendingPath(), logger = nullLogger) {
  if (Object.keys(marker.entries).length === 0) {
    try {
      await (0, import_promises10.unlink)(pendingPath);
    } catch (e) {
      if (!e || typeof e !== "object" || e.code !== "ENOENT") {
        logger.warn(`Failed to delete empty pending marker at ${pendingPath}`, {
          error: String(e)
        });
      }
    }
    return;
  }
  try {
    const data = {
      schema_version: SCHEMA_VERSION2,
      entries: Object.fromEntries(Object.entries(marker.entries).map(([skillId, entry]) => [
        skillId,
        {
          folder: entry.folder,
          submitted_at: entry.submittedAt,
          agent_runtime: entry.agentRuntime,
          container_key: entry.containerKey
        }
      ]))
    };
    await atomicWriteJson(pendingPath, data);
  } catch (e) {
    logger.warn(`Failed to save pending marker to ${pendingPath}`, { error: String(e) });
  }
}
function isPending(marker, skillId) {
  return skillId in marker.entries;
}
function addPending(marker, skillId, folder, origin = {}) {
  marker.entries[skillId] = {
    folder,
    submittedAt: (/* @__PURE__ */ new Date()).toISOString(),
    agentRuntime: origin.agentRuntime,
    containerKey: origin.containerKey
  };
}
function removePending(marker, skillId) {
  delete marker.entries[skillId];
}
function listPending(marker) {
  return Object.entries(marker.entries).map(([skillId, entry]) => ({
    skillId,
    folder: entry.folder,
    agentRuntime: entry.agentRuntime,
    containerKey: entry.containerKey
  }));
}

// ../core/dist/skill-verdict-cache.js
var import_node_path22 = require("node:path");
init_config();
init_file_utils();
init_types2();
var SCHEMA_VERSION3 = 1;
var DEFAULT_VERDICT_TTL_MS = MS_PER_DAY;
function parseSources(raw) {
  if (!Array.isArray(raw))
    return void 0;
  const sources = [];
  for (const item of raw) {
    if (!item || typeof item !== "object")
      continue;
    const entry = item;
    const source = {
      agentRuntime: typeof entry.agent_runtime === "string" ? entry.agent_runtime : void 0,
      containerKey: typeof entry.container_key === "string" ? entry.container_key : void 0
    };
    if (source.agentRuntime || source.containerKey)
      sources.push(source);
  }
  return sources.length > 0 ? sources : void 0;
}
function mergeSources(existing, incoming) {
  const merged = [];
  const seen = /* @__PURE__ */ new Set();
  for (const source of [...existing ?? [], ...incoming ?? []]) {
    const key = source.agentRuntime ?? "";
    if (seen.has(key))
      continue;
    seen.add(key);
    merged.push(source);
  }
  return merged.length > 0 ? merged : void 0;
}
function defaultCachePath2() {
  return (0, import_node_path22.join)(resolvePath(SAGE_DIR), "skill_verdict_cache.json");
}
async function loadSkillVerdictCache(cachePath = defaultCachePath2(), ttlMs = DEFAULT_VERDICT_TTL_MS, logger = nullLogger) {
  let raw;
  try {
    raw = await getFileContent(cachePath);
  } catch {
    return { entries: {} };
  }
  try {
    const data = JSON.parse(raw);
    const rawEntries = data.entries ?? {};
    const now = Date.now();
    const entries = {};
    let pruned = 0;
    for (const [skillId, entry] of Object.entries(rawEntries)) {
      const analyzedAt = entry.analyzed_at;
      if (!analyzedAt)
        continue;
      const ts = Date.parse(analyzedAt);
      if (!isFreshTimestamp(ts, ttlMs, now)) {
        pruned++;
        continue;
      }
      entries[skillId] = {
        verdict: typeof entry.verdict === "string" ? entry.verdict : void 0,
        summary: typeof entry.summary === "string" ? entry.summary : void 0,
        skillName: typeof entry.skill_name === "string" ? entry.skill_name : void 0,
        sources: parseSources(entry.sources),
        analyzedAt
      };
    }
    const cache2 = { entries };
    if (pruned > 0) {
      logger.debug(`Pruned ${pruned} stale verdict(s) from cache`, { cachePath });
      await saveSkillVerdictCache(cache2, cachePath, logger);
    }
    return cache2;
  } catch (e) {
    logger.warn(`Failed to load verdict cache from ${cachePath}`, { error: String(e) });
    return { entries: {} };
  }
}
async function saveSkillVerdictCache(cache2, cachePath = defaultCachePath2(), logger = nullLogger) {
  try {
    const data = {
      schema_version: SCHEMA_VERSION3,
      entries: Object.fromEntries(Object.entries(cache2.entries).map(([skillId, v]) => [
        skillId,
        {
          verdict: v.verdict,
          summary: v.summary,
          skill_name: v.skillName,
          sources: v.sources?.map((s) => ({
            agent_runtime: s.agentRuntime,
            container_key: s.containerKey
          })),
          analyzed_at: v.analyzedAt
        }
      ]))
    };
    await atomicWriteJson(cachePath, data);
  } catch (e) {
    logger.warn(`Failed to save verdict cache to ${cachePath}`, { error: String(e) });
  }
}
function getVerdict(cache2, skillId, ttlMs = DEFAULT_VERDICT_TTL_MS) {
  const entry = cache2.entries[skillId];
  if (!entry)
    return null;
  const ts = Date.parse(entry.analyzedAt);
  if (!isFreshTimestamp(ts, ttlMs))
    return null;
  return entry;
}
function putVerdict(cache2, skillId, verdict) {
  const existing = cache2.entries[skillId];
  cache2.entries[skillId] = {
    ...verdict,
    sources: mergeSources(existing?.sources, verdict.sources),
    analyzedAt: (/* @__PURE__ */ new Date()).toISOString()
  };
}

// ../core/dist/plugin-scanner.js
init_types2();
var SCANNABLE_EXTENSIONS2 = /* @__PURE__ */ new Set([
  ".py",
  ".js",
  ".ts",
  ".mjs",
  ".mts",
  ".sh",
  ".bash",
  ".zsh",
  ".json",
  ".yaml",
  ".yml",
  ".md",
  ".toml",
  ".txt",
  ".cfg",
  ".ini",
  ".conf"
]);
var MAX_FILE_SIZE = 512 * 1024;
async function walkPluginFiles(installPath, logger) {
  const files = [];
  const visited = /* @__PURE__ */ new Set();
  let rootReal;
  try {
    rootReal = await (0, import_promises11.realpath)((0, import_node_path23.resolve)(installPath));
  } catch (e) {
    logger.warn(`Error walking plugin path ${installPath}`, { error: String(e) });
    return files;
  }
  async function walk(dirOrFile) {
    let real;
    try {
      real = await (0, import_promises11.realpath)(dirOrFile);
    } catch {
      return;
    }
    if (visited.has(real))
      return;
    if (!isContained(real, rootReal))
      return;
    visited.add(real);
    let stats;
    try {
      stats = await (0, import_promises11.stat)(dirOrFile);
    } catch {
      return;
    }
    if (stats.isFile()) {
      if (SCANNABLE_EXTENSIONS2.has((0, import_node_path23.extname)(dirOrFile).toLowerCase()) && stats.size <= MAX_FILE_SIZE) {
        files.push(dirOrFile);
      }
      return;
    }
    if (stats.isDirectory()) {
      let entries;
      try {
        entries = await (0, import_promises11.readdir)(dirOrFile);
      } catch {
        return;
      }
      for (const entry of entries) {
        if (SKIP_DIRS.has(entry))
          continue;
        const fullPath = (0, import_node_path23.join)(dirOrFile, entry);
        await walk(fullPath);
      }
    }
  }
  try {
    await walk((0, import_node_path23.resolve)(installPath));
  } catch (e) {
    logger.warn(`Error walking plugin path ${installPath}`, { error: String(e) });
  }
  return files;
}
async function scanPlugin(plugin, options = {}) {
  const { checkUrls = true, checkFileHashes = true, checkSkills = true, amsiClient = null, logger = nullLogger, skillVerdictCachePath, skillPendingPath, loggingConfig, skillVerdictTtlMs, uploadEnabled = true, deferUnknownSkills = false, agentRuntime } = options;
  const result = { plugin, findings: [] };
  const skillCheckPromise = checkSkills ? runSkillCheck(plugin, result.findings, logger, {
    verdictCachePath: skillVerdictCachePath,
    pendingPath: skillPendingPath,
    loggingConfig,
    verdictTtlMs: skillVerdictTtlMs,
    uploadEnabled,
    deferUnknownSkills,
    agentRuntime
  }) : Promise.resolve(false);
  const files = await walkPluginFiles(plugin.installPath, logger);
  if (files.length === 0) {
    if (await skillCheckPromise)
      result.deferCache = true;
    return result;
  }
  const allUrls = [];
  const hashToFiles = /* @__PURE__ */ new Map();
  for (const filePath of files) {
    let content;
    let rawBytes;
    try {
      rawBytes = await getFileContentRaw(filePath);
      content = rawBytes.toString("utf-8");
    } catch {
      continue;
    }
    if (amsiClient) {
      try {
        const scanName = `${plugin.key}/${(0, import_node_path23.relative)(plugin.installPath, filePath)}`;
        const amsiResult = await amsiClient.scanString("Plugin", scanName, content);
        if (amsiResult && (amsiResult.isDetected || amsiResult.isBlockedByAdmin)) {
          result.findings.push({
            threatId: "AMSI_SCAN",
            title: `AMSI detection (result=${amsiResult.amsiResult})`,
            severity: "critical",
            artifact: content.slice(0, 200),
            sourceFile: (0, import_node_path23.relative)(plugin.installPath, filePath)
          });
        }
      } catch {
      }
    }
    if (checkUrls) {
      allUrls.push(...extractUrls(content));
    }
    if (checkFileHashes) {
      const sha256 = (0, import_node_crypto9.createHash)("sha256").update(rawBytes).digest("hex");
      const existing = hashToFiles.get(sha256);
      if (existing) {
        existing.push(filePath);
      } else {
        hashToFiles.set(sha256, [filePath]);
      }
    }
  }
  const urlCheckPromise = checkUrls && allUrls.length > 0 ? (async () => {
    try {
      const uniqueUrls = [...new Set(allUrls)];
      const client = new UrlCheckClient();
      const checkResults = await client.checkUrls(uniqueUrls);
      for (const ur of checkResults) {
        if (ur.isMalicious) {
          const findingDetails = ur.findings.map((f) => `${f.severityName}/${f.typeName}`).join(", ");
          result.findings.push({
            threatId: "URL_CHECK",
            title: `Malicious URL (${findingDetails})`,
            severity: "critical",
            artifact: ur.url.slice(0, 200),
            sourceFile: "URL check"
          });
        }
      }
    } catch {
    }
  })() : Promise.resolve();
  const fileCheckPromise = checkFileHashes && hashToFiles.size > 0 ? (async () => {
    try {
      const client = new FileCheckClient();
      const uniqueHashes = [...hashToFiles.keys()];
      const checkResults = await client.checkHashes(uniqueHashes);
      for (const fr of checkResults) {
        if (fr.severity === "SEVERITY_MALWARE") {
          const filePaths = hashToFiles.get(fr.sha256) ?? [];
          for (const filePath of filePaths) {
            result.findings.push({
              threatId: "FILE_CHECK",
              title: `Malicious file (${fr.detectionNames.join(", ") || "unknown"})`,
              severity: "critical",
              artifact: fr.sha256,
              sourceFile: (0, import_node_path23.relative)(plugin.installPath, filePath)
            });
          }
        }
      }
    } catch {
    }
  })() : Promise.resolve();
  const [, , skillDeferCache] = await Promise.all([
    urlCheckPromise,
    fileCheckPromise,
    skillCheckPromise
  ]);
  if (skillDeferCache)
    result.deferCache = true;
  return result;
}
function pushSkillFindingIfRisky(findings, plugin, skillId, folder, verdict) {
  const risk = (verdict.verdict ?? "").toUpperCase();
  if (risk !== "HIGH" && risk !== "CRITICAL")
    return;
  const severity = risk === "CRITICAL" ? "critical" : "warning";
  findings.push({
    threatId: "SKILL_CHECK",
    title: verdict.summary?.trim() || (risk === "CRITICAL" ? "Malicious skill detected" : "Suspicious skill detected"),
    severity,
    artifact: skillId.slice(0, 16),
    sourceFile: (0, import_node_path23.relative)(plugin.installPath, folder) || "."
  });
}
async function runSkillCheck(plugin, findings, logger, paths = {}) {
  try {
    const skills = await computeSkillIdsForRoot(plugin.installPath, logger);
    if (skills.length === 0)
      return false;
    const verdictCache = await loadSkillVerdictCache(paths.verdictCachePath, paths.verdictTtlMs, logger);
    const uncached = [];
    for (const skill of skills) {
      const cached = getVerdict(verdictCache, skill.skillId, paths.verdictTtlMs);
      if (cached) {
        pushSkillFindingIfRisky(findings, plugin, skill.skillId, skill.folder, cached);
      } else {
        uncached.push(skill);
      }
    }
    if (uncached.length === 0)
      return false;
    const client = new SkillCheckClient(void 0, logger);
    const verdicts = await client.checkSkills(uncached.map((s) => s.skillId));
    const marker = await loadPendingMarker(paths.pendingPath, logger);
    let cacheModified = false;
    let markerModified = false;
    let lookupFailed = false;
    let graceDeferred = false;
    for (const { folder, skillId } of uncached) {
      if (!verdicts.has(skillId)) {
        lookupFailed = true;
        continue;
      }
      const verdict = verdicts.get(skillId) ?? null;
      if (verdict) {
        putVerdict(verdictCache, skillId, {
          verdict: verdict.verdict,
          summary: verdict.summary,
          skillName: (0, import_node_path23.basename)(folder),
          sources: [{ agentRuntime: paths.agentRuntime, containerKey: plugin.key }]
        });
        cacheModified = true;
        pushSkillFindingIfRisky(findings, plugin, skillId, folder, verdict);
        if (isPending(marker, skillId)) {
          removePending(marker, skillId);
          markerModified = true;
        }
      } else if (!isPending(marker, skillId)) {
        if (paths.uploadEnabled === false) {
          if (paths.deferUnknownSkills)
            graceDeferred = true;
        } else {
          addPending(marker, skillId, folder, {
            agentRuntime: paths.agentRuntime,
            containerKey: plugin.key
          });
          markerModified = true;
          if (paths.loggingConfig) {
            logSkillQueued(paths.loggingConfig, skillId, plugin.key, folder).catch(() => {
            });
          }
        }
      }
    }
    if (cacheModified)
      await saveSkillVerdictCache(verdictCache, paths.verdictCachePath, logger);
    if (markerModified)
      await savePendingMarker(marker, paths.pendingPath, logger);
    const anyStillPending = uncached.some(({ skillId }) => isPending(marker, skillId));
    return markerModified || anyStillPending || lookupFailed || graceDeferred;
  } catch (e) {
    logger.debug("Skill check failed", { error: String(e) });
    return false;
  }
}

// ../core/dist/session-start.js
var import_node_child_process2 = require("node:child_process");
var import_node_fs4 = require("node:fs");
var import_node_path25 = require("node:path");
init_config();
init_file_utils();

// ../core/dist/session-start-scan.js
var import_node_path24 = require("node:path");
init_config();
init_types2();
function fromCachedFinding(finding) {
  return {
    threatId: finding.threat_id,
    title: finding.title,
    severity: finding.severity,
    artifact: finding.artifact,
    sourceFile: finding.source_file,
    recommendations: finding.recommendations
  };
}
function toFindingData(finding) {
  return {
    threat_id: finding.threatId,
    title: finding.title,
    severity: finding.severity,
    artifact: finding.artifact,
    source_file: finding.sourceFile,
    recommendations: finding.recommendations
  };
}
function toAuditFindingData(finding) {
  return { ...toFindingData(finding) };
}
async function runSessionStartScan(context) {
  const logger = context.logger ?? nullLogger;
  const sageConfig = await loadConfig(context.configPath, logger);
  const plugins = context.plugins;
  if (plugins.length === 0) {
    logger.debug("Session plugin scan completed", {
      totalPlugins: 0,
      resultsWithFindings: 0,
      findingsCount: 0,
      cacheHits: 0,
      cacheMisses: 0,
      scanned: 0,
      allowedByException: 0,
      deniedByException: 0
    });
    return [];
  }
  let exceptions = [];
  try {
    exceptions = await loadExceptions(sageConfig.exceptions, logger);
  } catch {
  }
  let amsiClient = null;
  if (sageConfig.amsi_check.enabled && isAmsiSupported()) {
    try {
      amsiClient = new AmsiClient(logger);
      await amsiClient.init();
      if (!amsiClient.isAvailable) {
        amsiClient.close();
        amsiClient = null;
      }
    } catch {
      amsiClient?.close();
      amsiClient = null;
    }
  }
  try {
    return await scanAllPlugins(context, sageConfig, plugins, exceptions, amsiClient, logger);
  } finally {
    amsiClient?.close();
  }
}
async function scanAllPlugins(context, config2, plugins, exceptions, amsiClient, logger) {
  const configHash = await computeConfigHash(context.sageVersion ?? "", context.threatsDir, context.trustedDomainsDir);
  const cache2 = await loadScanCache(configHash, context.scanCachePath, logger);
  const resultsWithFindings = [];
  let cacheModified = false;
  const stats = {
    totalPlugins: plugins.length,
    cacheHitsClean: 0,
    cacheHitsWithFindings: 0,
    cacheMisses: 0,
    scanned: 0,
    allowedByException: 0,
    deniedByException: 0,
    findingsCount: 0
  };
  const skillPendingPath = context.sageDirPath ? (0, import_node_path24.join)(context.sageDirPath, "skill_pending.json") : void 0;
  const skillVerdictCachePath = context.sageDirPath ? (0, import_node_path24.join)(context.sageDirPath, "skill_verdict_cache.json") : void 0;
  const cacheTtlMs = skillCacheTtlMs(config2);
  for (const plugin of plugins) {
    const denyMatch = findPluginDenyException(exceptions, plugin.key);
    if (denyMatch) {
      stats.deniedByException += 1;
      stats.findingsCount += 1;
      resultsWithFindings.push({
        plugin,
        findings: [
          {
            threatId: "EXCEPTION-DENY",
            title: `Denied by exception: ${denyMatch.pattern}${denyMatch.reason ? ` \u2014 ${denyMatch.reason}` : ""}`,
            severity: "critical",
            artifact: plugin.key,
            sourceFile: "~/.sage/exceptions.json"
          }
        ]
      });
      continue;
    }
    const allowMatch = findPluginAllowException(exceptions, plugin.key);
    if (allowMatch) {
      stats.allowedByException += 1;
      continue;
    }
    const cached = getCached(cache2, plugin.key, plugin.version, plugin.lastUpdated, cacheTtlMs);
    if (cached && cached.findings.length === 0) {
      stats.cacheHitsClean += 1;
      continue;
    }
    if (cached && cached.findings.length > 0) {
      stats.cacheHitsWithFindings += 1;
      stats.findingsCount += cached.findings.length;
      resultsWithFindings.push({
        plugin,
        findings: cached.findings.map(fromCachedFinding)
      });
      continue;
    }
    stats.cacheMisses += 1;
    stats.scanned += 1;
    const result = await scanPlugin(plugin, {
      checkUrls: context.checkUrls ?? true,
      checkFileHashes: context.checkFileHashes ?? true,
      checkSkills: config2.skill_check.enabled,
      uploadEnabled: context.uploadUnknownSkills ?? config2.skill_check.upload_enabled,
      deferUnknownSkills: context.deferUnknownSkills,
      amsiClient,
      logger,
      skillPendingPath,
      skillVerdictCachePath,
      skillVerdictTtlMs: cacheTtlMs,
      loggingConfig: config2.logging,
      agentRuntime: context.agentRuntime
    });
    if (result.deferCache) {
      logger.debug("Plugin cache deferred (skill verdict pending)", { plugin: plugin.key });
    } else {
      storeResult(cache2, plugin.key, plugin.version, plugin.lastUpdated, result.findings.map(toFindingData));
      cacheModified = true;
    }
    if (result.findings.length > 0) {
      stats.findingsCount += result.findings.length;
      resultsWithFindings.push(result);
    }
  }
  if (cacheModified) {
    await saveScanCache(cache2, context.scanCachePath, logger);
  }
  try {
    for (const result of resultsWithFindings) {
      await logPluginScan(config2.logging, result.plugin.key, result.plugin.version, result.findings.map(toAuditFindingData));
    }
  } catch {
  }
  logger.debug("Session plugin scan completed", {
    ...stats,
    cacheHits: stats.cacheHitsClean + stats.cacheHitsWithFindings,
    resultsWithFindings: resultsWithFindings.length
  });
  return resultsWithFindings;
}

// ../core/dist/session-start.js
init_types2();

// ../core/dist/version-check.js
init_config();
init_types2();
var DEFAULT_TIMEOUT_MS3 = 5e3;
function isNewerVersion(current, latest) {
  const parse = (v) => v.replace(/^v/, "").split(".").map((n) => Number.parseInt(n, 10) || 0);
  const cur = parse(current);
  const lat = parse(latest);
  for (let i = 0; i < 3; i++) {
    const c = cur[i] ?? 0;
    const l = lat[i] ?? 0;
    if (l > c)
      return true;
    if (l < c)
      return false;
  }
  return false;
}
async function checkForUpdate(currentVersion, logger = nullLogger, timeoutMs = DEFAULT_TIMEOUT_MS3, context) {
  if (currentVersion === "dev") {
    logger.debug("Skipping version check for dev build");
    return null;
  }
  try {
    if (!context.iid) {
      logger.debug("Skipping version check: missing installation id");
      return null;
    }
    let config2 = context.config;
    if (!config2) {
      try {
        config2 = await loadConfig(context.configPath, logger);
      } catch (err) {
        logger.debug(`Version check config load failed: ${err}`);
      }
    }
    const envelope = buildSageProxyEnvelope({
      iid: context.iid,
      versionApp: currentVersion,
      agentRuntime: context.agentRuntime,
      agentRuntimeVersion: context.agentRuntimeVersion ?? "unknown",
      config: config2
    });
    const extendedInfo = await loadExtendedInfo(void 0, logger).catch(() => null);
    const enriched = mergeExtendedInfo(envelope, extendedInfo);
    const response = await fetch(resolveEndpoint("/v2/version-check"), {
      method: "POST",
      signal: AbortSignal.timeout(timeoutMs),
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json"
      },
      body: JSON.stringify(enriched)
    });
    if (!response.ok) {
      logger.debug(`Version check HTTP ${response.status}`);
      return null;
    }
    const body = await response.json();
    const latestVersion = body.version;
    if (typeof latestVersion !== "string") {
      logger.debug("Version check: no version field in response");
      return null;
    }
    return {
      currentVersion,
      latestVersion,
      updateAvailable: isNewerVersion(currentVersion, latestVersion)
    };
  } catch (err) {
    logger.debug(`Version check failed: ${err}`);
    return null;
  }
}

// ../core/dist/session-start.js
async function runSessionStart(ctx) {
  const logger = ctx.logger ?? nullLogger;
  const sageDirPath = resolvePath(ctx.sageDirPath ?? "~/.sage");
  pruneOrphanedTmpFiles(sageDirPath).catch(() => {
  });
  deployConfigDefaults(sageDirPath, logger).catch(() => {
  });
  maybeSpawnModelDownloadWorker({
    sageDirPath,
    workerPath: ctx.modelDownloadWorkerPath,
    configPath: ctx.configPath,
    agentRuntime: ctx.agentRuntime,
    agentRuntimeVersion: ctx.agentRuntimeVersion,
    versionApp: ctx.version,
    logger
  }).catch(() => {
  });
  const rollout = await resolveSkillUploadRollout({
    sageDirPath,
    configPath: ctx.configPath,
    version: ctx.version,
    logger,
    commitNotice: ctx.commitUploadNotice ?? true
  });
  const iidPromise = getInstallationId(sageDirPath).catch(() => void 0);
  const [scanResults, versionCheck] = await Promise.all([
    runSessionStartScan({
      plugins: ctx.plugins,
      threatsDir: ctx.threatsDir,
      trustedDomainsDir: ctx.trustedDomainsDir,
      sageVersion: ctx.version,
      logger,
      configPath: ctx.configPath,
      scanCachePath: ctx.scanCachePath,
      checkUrls: ctx.checkUrls,
      checkFileHashes: ctx.checkFileHashes,
      sageDirPath,
      agentRuntime: ctx.agentRuntime,
      uploadUnknownSkills: rollout.uploadActive,
      deferUnknownSkills: rollout.deferUnknownSkills
    }),
    iidPromise.then((iid) => {
      if (!iid) {
        return null;
      }
      return checkForUpdate(ctx.version, logger, void 0, {
        agentRuntime: ctx.agentRuntime,
        agentRuntimeVersion: ctx.agentRuntimeVersion,
        iid,
        configPath: ctx.configPath
      });
    }).catch(() => null)
  ]);
  maybeSpawnSkillUploadWorker({
    sageDirPath,
    workerPath: ctx.skillUploadWorkerPath,
    configPath: ctx.configPath,
    agentRuntime: ctx.agentRuntime,
    uploadActive: rollout.uploadActive,
    logger
  }).catch(() => {
  });
  return {
    scanResults,
    versionCheck,
    notices: rollout.showNotice ? [SKILL_UPLOAD_NOTICE.id] : []
  };
}
async function maybeSpawnModelDownloadWorker(args) {
  if (!args.workerPath) {
    args.logger.debug("Model download worker skipped", {
      result: "skipped",
      skippedReason: "missing_worker_path"
    });
    return;
  }
  if (!(0, import_node_fs4.existsSync)(args.workerPath)) {
    args.logger.debug("Model download worker skipped", {
      result: "skipped",
      skippedReason: "worker_script_not_found",
      workerPath: args.workerPath
    });
    return;
  }
  const missingModels = missingRequiredModels(MODEL_SCHEMA_VERSION, args.sageDirPath);
  if (missingModels.length === 0) {
    args.logger.debug("Model download worker skipped", {
      result: "skipped",
      skippedReason: "no_missing_models",
      schema: MODEL_SCHEMA_VERSION
    });
    return;
  }
  let piEnabled = false;
  try {
    const config2 = await loadConfig(args.configPath, args.logger);
    piEnabled = config2.pi_check.enabled && !config2.pi_check.model_path;
  } catch {
    piEnabled = false;
  }
  if (!piEnabled) {
    args.logger.debug("Model download worker skipped", {
      result: "skipped",
      skippedReason: "pi_check_disabled",
      schema: MODEL_SCHEMA_VERSION,
      missingModels
    });
    return;
  }
  const spawned = spawnModelDownloadWorker({
    sageDirPath: args.sageDirPath,
    workerPath: args.workerPath,
    configPath: args.configPath,
    agentRuntime: args.agentRuntime,
    agentRuntimeVersion: args.agentRuntimeVersion,
    versionApp: args.versionApp,
    logger: args.logger
  });
  args.logger.debug("Model download worker spawn completed", {
    result: spawned ? "spawned" : "failed",
    schema: MODEL_SCHEMA_VERSION,
    missingModels
  });
}
function bunRuntimeEnv() {
  return process.versions.bun ? { BUN_BE_BUN: "1" } : {};
}
function spawnModelDownloadWorker(args) {
  const logger = args.logger ?? nullLogger;
  try {
    const child = (0, import_node_child_process2.spawn)(process.execPath, [args.workerPath], {
      detached: true,
      stdio: "ignore",
      env: {
        ...process.env,
        ...bunRuntimeEnv(),
        SAGE_DIR: args.sageDirPath,
        SAGE_CONFIG_PATH: args.configPath ?? "",
        SAGE_AGENT_RUNTIME: String(args.agentRuntime ?? "unknown"),
        SAGE_AGENT_RUNTIME_VERSION: args.agentRuntimeVersion ?? "",
        SAGE_VERSION_APP: args.versionApp ?? "",
        SAGE_MODEL_SCHEMA: MODEL_SCHEMA_VERSION
      }
    });
    child.unref();
    return true;
  } catch (err) {
    logger.warn("Failed to spawn model download worker", { error: String(err) });
    return false;
  }
}
async function maybeSpawnSkillUploadWorker(args) {
  if (!args.uploadActive) {
    args.logger.debug("Skill upload worker skipped", {
      result: "skipped",
      skippedReason: "upload_inactive"
    });
    return;
  }
  try {
    const config2 = await loadConfig(args.configPath, args.logger);
    if (!config2.skill_check.enabled) {
      args.logger.debug("Skill upload worker skipped", {
        result: "skipped",
        skippedReason: "skill_check_disabled"
      });
      return;
    }
  } catch {
  }
  if (!args.workerPath) {
    args.logger.debug("Skill upload worker skipped", {
      result: "skipped",
      skippedReason: "missing_worker_path"
    });
    return;
  }
  if (!(0, import_node_fs4.existsSync)(args.workerPath)) {
    args.logger.debug("Skill upload worker skipped", {
      result: "skipped",
      skippedReason: "worker_script_not_found",
      workerPath: args.workerPath
    });
    return;
  }
  const marker = await loadPendingMarker((0, import_node_path25.join)(args.sageDirPath, "skill_pending.json"), args.logger);
  const pendingCount = listPending(marker).length;
  if (pendingCount === 0) {
    args.logger.debug("Skill upload worker skipped", {
      result: "skipped",
      skippedReason: "no_pending_skills"
    });
    return;
  }
  const spawned = spawnSkillUploadWorker({
    sageDirPath: args.sageDirPath,
    workerPath: args.workerPath,
    agentRuntime: args.agentRuntime,
    logger: args.logger
  });
  args.logger.debug("Skill upload worker spawn completed", {
    result: spawned ? "spawned" : "failed",
    pendingCount
  });
}
function spawnSkillUploadWorker(args) {
  const logger = args.logger ?? nullLogger;
  try {
    const child = (0, import_node_child_process2.spawn)(process.execPath, [args.workerPath], {
      detached: true,
      stdio: "ignore",
      env: {
        ...process.env,
        ...bunRuntimeEnv(),
        SAGE_DIR: args.sageDirPath,
        SAGE_AGENT_RUNTIME: String(args.agentRuntime ?? "unknown")
      }
    });
    child.unref();
    return true;
  } catch (err) {
    logger.warn("Failed to spawn skill upload worker", { error: String(err) });
    return false;
  }
}

// ../core/dist/scan-handler.js
async function runPluginScan(logger, context, plugins, threatsDir, trustedDomainsDir, version, agentRuntime, branding2 = defaultBranding, modelDownloadWorkerPath, style = "verbose", agentRuntimeVersion, skillUploadWorkerPath, onNotices, commitUploadNotice, announceCleanScans = true) {
  logger.debug(`${branding2.name} plugin scan started (${context})`, {
    agentRuntime,
    pluginsCount: plugins.length,
    threatsDir,
    trustedDomainsDir
  });
  const result = await runSessionStart({
    plugins,
    threatsDir,
    trustedDomainsDir,
    version,
    logger,
    agentRuntime,
    agentRuntimeVersion,
    modelDownloadWorkerPath,
    skillUploadWorkerPath,
    commitUploadNotice
  });
  if (result.notices && result.notices.length > 0) {
    logger.debug(`${branding2.name} session-start produced notices`, {
      context,
      noticeIds: result.notices,
      forwarded: Boolean(onNotices)
    });
    onNotices?.(result.notices);
  } else {
    logger.debug(`${branding2.name} session-start produced no notices`, { context });
  }
  const findingsCount = result.scanResults.reduce((total, scanResult) => total + scanResult.findings.length, 0);
  const completionData = {
    agentRuntime,
    pluginsCount: plugins.length,
    resultsWithFindings: result.scanResults.length,
    findingsCount,
    updateAvailable: result.versionCheck?.updateAvailable ?? false
  };
  if (findingsCount > 0) {
    logger.warn(`${branding2.name} plugin scan (${context}) complete with findings`, completionData);
  } else {
    logger.debug(`${branding2.name} plugin scan (${context}) complete`, completionData);
  }
  if (findingsCount === 0 && !announceCleanScans) {
    return "";
  }
  return formatSessionStartMessage(version, result, branding2, style);
}
function createScanHandler(options) {
  const { logger, context, discoverPlugins: discoverPlugins2, selfPrefix, threatsDir, trustedDomainsDir, version, agentRuntime, agentRuntimeVersion, branding: branding2 = defaultBranding, onResult, onNotices, modelDownloadWorkerPath, skillUploadWorkerPath, style = "verbose", commitUploadNotice, announceCleanScans = true } = options;
  return async () => {
    try {
      let plugins = await discoverPlugins2();
      plugins = plugins.filter((p) => !p.key.startsWith(selfPrefix));
      if (plugins.length === 0) {
        logger.debug(`${branding2.name} plugin scan (${context}): no plugins to scan after filtering`);
      }
      const msg = await runPluginScan(logger, context, plugins, threatsDir, trustedDomainsDir, version, agentRuntime, branding2, modelDownloadWorkerPath, style, agentRuntimeVersion, skillUploadWorkerPath, onNotices, commitUploadNotice, announceCleanScans);
      if (msg !== "") {
        onResult?.(msg);
      }
    } catch (e) {
      logger.error(`${branding2.name} ${context} scan failed`, { error: String(e) });
    }
  };
}

// ../core/dist/tool-names.js
var CANONICAL_TOOLS = [
  "Bash",
  "WebFetch",
  "Write",
  "Edit",
  "Read",
  "Delete",
  "ApplyPatch",
  "Glob",
  "Grep",
  "List",
  "CodeSearch",
  "WebSearch",
  "Question",
  "Task",
  "ReadLines",
  "MCP",
  "Unknown"
];
var CANONICAL_SET = new Set(CANONICAL_TOOLS);
function canonicalizeToolName(map, rawName) {
  if (CANONICAL_SET.has(rawName))
    return rawName;
  return map[rawName] ?? "Unknown";
}

// ../core/dist/index.js
init_types2();

// src/bundled-dirs.ts
var import_node_path26 = require("node:path");
var packageRoot = (0, import_node_path26.resolve)(__dirname, "..");
function getBundledDataDirs() {
  return {
    threatsDir: (0, import_node_path26.join)(packageRoot, "resources", "threats"),
    trustedDomainsDir: (0, import_node_path26.join)(packageRoot, "resources", "trusted-domains")
  };
}
var cachedVersion;
function getSageVersion() {
  if (cachedVersion) return cachedVersion;
  try {
    const pkg = JSON.parse(getFileContentSync((0, import_node_path26.join)(packageRoot, "package.json"), "utf-8"));
    cachedVersion = pkg.version ?? "0.0.0";
  } catch {
    cachedVersion = "0.0.0";
  }
  return cachedVersion;
}

// src/startup-scan.ts
var import_node_path28 = require("node:path");

// src/plugin-discovery.ts
var import_promises12 = require("node:fs/promises");
var import_node_os4 = require("node:os");
var import_node_path27 = require("node:path");
var DEFAULT_EXTENSIONS_DIR = (0, import_node_path27.join)((0, import_node_os4.homedir)(), ".openclaw", "extensions");
var SKILL_ROOTS = [
  { dir: (0, import_node_path27.join)(getHomeDir(), ".agents", "skills"), tag: "agents", scope: "personal" },
  { dir: (0, import_node_path27.join)(getHomeDir(), ".openclaw", "skills"), tag: "openclaw", scope: "personal" }
];
async function discoverOpenClawPlugins(logger, extensionsDir = DEFAULT_EXTENSIONS_DIR, branding2 = defaultBranding, skillRoots = SKILL_ROOTS) {
  logger.debug(`${branding2.name} plugin discovery: scanning extensions directory`, {
    path: extensionsDir
  });
  const plugins = [];
  let entries;
  try {
    entries = await (0, import_promises12.readdir)(extensionsDir);
  } catch {
    logger.debug("OpenClaw extensions directory not found", { path: extensionsDir });
    entries = [];
  }
  for (const entry of entries) {
    const extDir = (0, import_node_path27.join)(extensionsDir, entry);
    let stats;
    try {
      stats = await (0, import_promises12.stat)(extDir);
      if (!stats.isDirectory()) continue;
    } catch {
      continue;
    }
    let pkg;
    try {
      const pkgPath = (0, import_node_path27.join)(extDir, "package.json");
      const raw = await getFileContent(pkgPath);
      pkg = JSON.parse(raw);
    } catch {
      logger.warn("Invalid or missing package.json in extension", { path: extDir });
      continue;
    }
    const name = pkg.name ?? entry;
    const version = pkg.version ?? "unknown";
    const key = `${name}@${version}`;
    logger.debug(`${branding2.name} plugin discovery: found extension`, {
      key,
      path: extDir
    });
    plugins.push({
      key,
      installPath: extDir,
      version,
      lastUpdated: stats.mtime.toISOString()
    });
  }
  logger.debug(`${branding2.name} plugin discovery: found ${plugins.length} extension(s)`);
  const skills = await discoverLooseSkillsAcrossRoots(skillRoots);
  logger.debug(`${branding2.name} skill discovery: found ${skills.length} loose skill(s)`);
  plugins.push(...skills);
  return plugins;
}

// src/startup-scan.ts
function createOpenClawScanHandler(logger, context, branding2 = defaultBranding, onResult, announceCleanScans = true) {
  const { threatsDir, trustedDomainsDir } = getBundledDataDirs();
  const version = getSageVersion();
  return createScanHandler({
    logger,
    context,
    discoverPlugins: () => discoverOpenClawPlugins(logger, void 0, branding2),
    selfPrefix: "@gendigital/sage-openclaw@",
    threatsDir,
    trustedDomainsDir,
    version,
    agentRuntime: "openclaw",
    // No agentRuntimeVersion: the OpenClaw plugin API exposes no host version.
    branding: branding2,
    onResult,
    // No onNotices: OpenClaw delivers the one-time notice from
    // `before_agent_start` (a different process/turn than this scan) via
    // takePendingNotices, so the scan-time callback would never fire.
    modelDownloadWorkerPath: (0, import_node_path28.resolve)(__dirname, "model-download-worker.cjs"),
    skillUploadWorkerPath: (0, import_node_path28.resolve)(__dirname, "skill-upload-worker.cjs"),
    // Don't commit the "shown" flag here — commit happens at delivery.
    commitUploadNotice: false,
    announceCleanScans
  });
}
function createStartupScanHandler(logger, branding2 = defaultBranding, onResult, announceCleanScans = true) {
  return createOpenClawScanHandler(logger, "startup", branding2, onResult, announceCleanScans);
}
function createSessionScanHandler(logger, branding2 = defaultBranding, onResult, announceCleanScans = true) {
  return createOpenClawScanHandler(logger, "session", branding2, onResult, announceCleanScans);
}
function createBeforeAgentStartHandler(getSecurityFindings, clearFindings, logger, branding2 = defaultBranding) {
  return (notices) => {
    const findings = getSecurityFindings();
    if (!notices && !findings) {
      logger.debug(`${branding2.name}: before_agent_start - nothing pending to surface`);
      return void 0;
    }
    if (findings) clearFindings();
    logger.debug(`${branding2.name}: surfacing context via before_agent_start`, {
      hasNotices: Boolean(notices),
      hasFindings: Boolean(findings)
    });
    const blocks = [];
    if (notices) {
      blocks.push(
        [
          '<sage-notice source="sage-session-start">',
          notices,
          "",
          "Relay this notice to the user. It is informational, not a security finding.",
          "</sage-notice>"
        ].join("\n")
      );
    }
    if (findings) {
      blocks.push(
        [
          '<security-alert source="sage-plugin-scan">',
          findings,
          "",
          "Inform the user about these security findings.",
          "</security-alert>"
        ].join("\n")
      );
    }
    return { prependContext: blocks.join("\n\n") };
  };
}

// src/tool-handler.ts
var OPENCLAW_TOOL_MAP = {
  bash: "Bash",
  exec: "Bash",
  web_fetch: "WebFetch",
  write: "Write",
  edit: "Edit",
  read: "Read",
  apply_patch: "ApplyPatch"
};
function extractFilePaths(patch) {
  const artifacts = [];
  for (const line of patch.split("\n")) {
    const match = line.match(/^(?:---|\+\+\+)\s+(?:a\/|b\/)?(.+)/);
    if (match?.[1] && match[1] !== "/dev/null") {
      artifacts.push({ type: "file_path", value: match[1], context: "apply_patch" });
    }
  }
  return artifacts;
}
function normalizeToolInput(toolName, params) {
  switch (toolName) {
    case "write":
      return {
        ...params,
        file_path: params.path ?? "",
        content: params.content ?? ""
      };
    case "edit":
      return {
        ...params,
        file_path: params.path ?? ""
      };
    default:
      return params;
  }
}
function mapToolToArtifacts(toolName, params) {
  switch (toolName) {
    case "bash":
    case "exec": {
      const command = params.command ?? "";
      return command ? extractFromBash(command) : null;
    }
    case "web_fetch":
      return extractFromWebFetch({ url: params.url });
    case "write":
      return extractFromWrite({ file_path: params.path, content: params.content });
    case "edit":
      return extractFromEdit({ file_path: params.path, new_string: params.new_string });
    case "read": {
      const path = params.path ?? "";
      return path ? [{ type: "file_path", value: path, context: "read" }] : null;
    }
    case "apply_patch": {
      const patch = params.patch ?? "";
      return patch ? extractFilePaths(patch) : null;
    }
    default:
      return null;
  }
}
function createToolCallHandler(approvalStore, logger, threatsDir, trustedDomainsDir, branding2 = defaultBranding) {
  async function handleToolCall(event, ctx) {
    const sessionId = ctx?.sessionKey ?? "unknown";
    const completeHook = (result, data = {}) => {
      logger.debug("OpenClaw tool hook completed", {
        agentRuntime: "openclaw",
        hookType: "PreToolUse",
        toolName: event.toolName,
        sessionId,
        result,
        ...data
      });
    };
    logger.debug("OpenClaw tool hook started", {
      agentRuntime: "openclaw",
      hookType: "PreToolUse",
      toolName: event.toolName,
      sessionId
    });
    try {
      const { toolName, params } = event;
      if (captureEnabled()) {
        await captureHookInput(
          "PreToolUse",
          { toolName, params, sessionKey: ctx?.sessionKey },
          {
            toolName: canonicalizeToolName(OPENCLAW_TOOL_MAP, toolName),
            toolInput: normalizeToolInput(toolName, params)
          },
          { filePrefix: "openclaw-" }
        );
      }
      const artifacts = mapToolToArtifacts(toolName, params);
      if (!artifacts || artifacts.length === 0) {
        completeHook("skipped", { skippedReason: "no_artifacts" });
        return void 0;
      }
      const canonicalToolName = canonicalizeToolName(OPENCLAW_TOOL_MAP, toolName);
      const { verdict, actionId } = await guardToolCall(
        {
          sessionId,
          conversationId: sessionId,
          agentRuntime: "openclaw",
          toolName: canonicalToolName,
          toolInput: normalizeToolInput(toolName, params),
          artifacts
        },
        { threatsDir, trustedDomainsDir, logger },
        approvalStore
      );
      if (verdict.decision === "allow") {
        completeHook("evaluated", {
          toolName: canonicalToolName,
          decision: verdict.decision,
          category: verdict.category,
          severity: verdict.severity,
          artifactsCount: artifacts.length
        });
        return void 0;
      }
      if (verdict.decision === "deny") {
        completeHook("evaluated", {
          toolName: canonicalToolName,
          decision: verdict.decision,
          category: verdict.category,
          severity: verdict.severity,
          artifactsCount: artifacts.length
        });
        return { block: true, blockReason: formatDenyMessage(verdict, branding2) };
      }
      const maxReasons = 3;
      const reasons = verdict.reasons.length > 0 ? verdict.reasons.slice(0, maxReasons).join("; ") + (verdict.reasons.length > maxReasons ? `; ... and ${verdict.reasons.length - maxReasons} more` : "") : verdict.category;
      const intersected = artifacts.filter((a) => verdict.artifacts.includes(a.value));
      const flaggedArtifacts = intersected.length > 0 ? intersected : artifacts;
      completeHook("evaluated", {
        toolName: canonicalToolName,
        decision: verdict.decision,
        category: verdict.category,
        severity: verdict.severity,
        artifactsCount: artifacts.length,
        actionId
      });
      return {
        requireApproval: {
          id: actionId,
          title: `${branding2.name}: ${verdict.category}`,
          description: [
            `Severity: ${verdict.severity}`,
            `Reason: ${reasons}`,
            `Artifacts: ${summarizeArtifacts(artifacts)}`
          ].join("\n"),
          severity: verdict.severity,
          timeoutBehavior: "deny",
          onResolution: async (decision) => {
            approvalStore.deletePending(actionId);
            if (decision !== "allow-always") {
              logger.debug("OpenClaw approval resolved without persistent allow", {
                actionId,
                decision
              });
              return;
            }
            logger.info("OpenClaw approval accepted permanently", { actionId });
            for (const a of flaggedArtifacts) {
              await addException(
                { type: a.type, value: a.value },
                "Approved by user via native approval",
                void 0,
                logger
              );
            }
          }
        }
      };
    } catch (e) {
      logger.error("tool-handler error, failing open", { error: String(e) });
      completeHook("failed_open", { decision: "allow" });
      return void 0;
    }
  }
  return handleToolCall;
}

// src/index.ts
var config = loadConfigSync();
var branding = resolveBranding(config.brand_key);
var index_default = {
  id: "sage-openclaw",
  name: branding.name,
  description: "Safety for Agents \u2014 ADR layer that guards commands, files, and web requests",
  configSchema: {
    jsonSchema: { type: "object", additionalProperties: false, properties: {} }
  },
  register(api) {
    const operationalLogger = createOperationalLogger(config.operational_logging, "openclaw");
    const logger = operationalLogger.forComponent("plugin");
    const toolLogger = operationalLogger.forComponent("tool-handler");
    const scanLogger = operationalLogger.forComponent("startup-scan");
    const approvalStore = new ApprovalStore();
    const { threatsDir, trustedDomainsDir } = getBundledDataDirs();
    const CLEANUP_INTERVAL_MS = 5 * 60 * 1e3;
    const interval = setInterval(() => approvalStore.cleanup(), CLEANUP_INTERVAL_MS);
    if (typeof interval.unref === "function") interval.unref();
    let pendingConfigurationWarnings = formatConfigurationWarnings(getConfigurationWarningsSync(void 0, logger), branding) ?? null;
    const migrationCheckPromise = checkAllowlistMigration().then((result) => {
      if (result.needed) {
        const notice = formatAllowlistMigrationWarning(result.entryTypes, branding);
        pendingConfigurationWarnings = pendingConfigurationWarnings ? `${pendingConfigurationWarnings}

${notice}` : notice;
      }
    }).catch(() => {
    });
    let pendingScanFindings = null;
    const onFindings = (msg) => {
      pendingScanFindings = msg;
    };
    const getPendingSecurityFindings = () => [pendingConfigurationWarnings, pendingScanFindings].filter(Boolean).join("\n\n") || null;
    const beforeAgentStartHandler = createBeforeAgentStartHandler(
      getPendingSecurityFindings,
      () => {
        pendingConfigurationWarnings = null;
        pendingScanFindings = null;
      },
      logger,
      branding
    );
    const resolveNoticeText = async () => {
      try {
        const ids = await takePendingNotices({ logger });
        const text = ids.map((id) => formatNoticeById(id, branding)).filter(Boolean).join("\n\n");
        logger.debug(`${branding.name}: notices resolved for delivery`, {
          noticeIds: ids,
          willShow: text.length > 0
        });
        return text.length > 0 ? text : null;
      } catch (e) {
        logger.warn(`${branding.name}: notice resolution failed`, { error: String(e) });
        return null;
      }
    };
    api.on(
      "before_tool_call",
      createToolCallHandler(approvalStore, toolLogger, threatsDir, trustedDomainsDir, branding),
      { priority: 100 }
    );
    api.on(
      "gateway_start",
      createStartupScanHandler(scanLogger, branding, onFindings, config.announce_clean_scans)
    );
    api.on(
      "session_start",
      createSessionScanHandler(scanLogger, branding, onFindings, config.announce_clean_scans)
    );
    api.on("before_agent_start", async () => {
      await migrationCheckPromise;
      const notices = await resolveNoticeText();
      return beforeAgentStartHandler(notices);
    });
  }
};
//# sourceMappingURL=index.cjs.map
