"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var compress_exports = {};
__export(compress_exports, {
  compressObservation: () => compressObservation,
  extractIdentifiers: () => extractIdentifiers
});
module.exports = __toCommonJS(compress_exports);
const CODE_BLOCK_RE = /```[\s\S]*?```/g;
const INLINE_CODE_RE = /`[^`]+`/g;
const FILE_PATH_RE = /(?:\.?\.?\/)?[\w\-./\\]+\.\w{1,10}/g;
const URL_RE = /https?:\/\/[^\s)]+/g;
const VERSION_RE = /\bv?\d+\.\d+(?:\.\d+)?(?:-[\w.]+)?\b/g;
const IDENTIFIER_RE = /\b(?:[A-Z][a-z]+(?:[A-Z][a-z]+)+|[a-z]+(?:[A-Z][a-z]+)+|[a-z]+(?:_[a-z]+)+|[A-Z]+(?:_[A-Z]+)+)\b/g;
const FILLER_WORDS = /\b(just|really|basically|simply|actually|very|quite|rather|somewhat|perhaps|maybe)\b/gi;
const ARTICLES = /\b(a|an|the)\b/gi;
const HEDGING_PHRASES = [
  /\bI think\b/gi,
  /\bit seems (like |that )?/gi,
  /\byou might want to\b/gi,
  /\byou may want to\b/gi,
  /\bit looks like\b/gi,
  /\bprobably\b/gi,
  /\bI believe\b/gi,
  /\bin my opinion\b/gi
];
const PLEASANTRIES = [
  /\b(please|thanks|thank you|sorry|excuse me)\b/gi,
  /^(hi|hello|hey|sure|okay|ok|great|nice|cool|awesome|perfect),?\s*/gim
];
const ABBREVIATIONS = [
  [/\bdatabase\b/gi, "DB"],
  [/\bauthentication\b/gi, "auth"],
  [/\bauthenticate\b/gi, "auth"],
  [/\brequest\b/gi, "req"],
  [/\bresponse\b/gi, "res"],
  [/\bfunction\b/gi, "fn"],
  [/\bconfiguration\b/gi, "cfg"],
  [/\bconfigure\b/gi, "cfg"],
  [/\bmessage\b/gi, "msg"],
  [/\berror\b/gi, "err"],
  [/\bimplementation\b/gi, "impl"],
  [/\bimplement\b/gi, "impl"],
  [/\bdependency\b/gi, "dep"],
  [/\bdependencies\b/gi, "deps"],
  [/\brepository\b/gi, "repo"],
  [/\benvironment\b/gi, "env"],
  [/\bapplication\b/gi, "app"],
  [/\bmiddleware\b/gi, "mw"],
  [/\bparameter\b/gi, "param"],
  [/\bparameters\b/gi, "params"]
];
function compressObservation(text, mode) {
  const originalLength = text.length;
  if (mode === "off") {
    return {
      compressed: text,
      originalLength,
      compressedLength: text.length,
      detectedSymbols: extractIdentifiers(text)
    };
  }
  const preserved = /* @__PURE__ */ new Map();
  let processed = text;
  let placeholderIdx = 0;
  function preserve(re) {
    processed = processed.replace(re, (match) => {
      const key = `\0P${placeholderIdx++}\0`;
      preserved.set(key, match);
      return key;
    });
  }
  preserve(CODE_BLOCK_RE);
  preserve(INLINE_CODE_RE);
  preserve(URL_RE);
  preserve(FILE_PATH_RE);
  preserve(VERSION_RE);
  preserve(IDENTIFIER_RE);
  if (mode === "lite" || mode === "full" || mode === "ultra") {
    processed = processed.replace(FILLER_WORDS, "");
    for (const re of PLEASANTRIES) {
      processed = processed.replace(re, "");
    }
  }
  if (mode === "full" || mode === "ultra") {
    processed = processed.replace(ARTICLES, "");
    for (const re of HEDGING_PHRASES) {
      processed = processed.replace(re, "");
    }
  }
  if (mode === "ultra") {
    for (const [re, replacement] of ABBREVIATIONS) {
      processed = processed.replace(re, replacement);
    }
    processed = processed.replace(/\b(because|so|therefore|thus|hence)\b/gi, "\u2192");
    processed = processed.replace(/\band\b/gi, "+");
  }
  processed = processed.split("\n").map((line) => line.replace(/\s{2,}/g, " ").trim()).filter((line) => line.length > 0).join("\n");
  for (const [key, value] of preserved) {
    processed = processed.replace(key, value);
  }
  return {
    compressed: processed,
    originalLength,
    compressedLength: processed.length,
    detectedSymbols: extractIdentifiers(text)
  };
}
function extractIdentifiers(text) {
  const matches = /* @__PURE__ */ new Set();
  const camelPascal = text.match(/\b[A-Z]?[a-z]+(?:[A-Z][a-z]+)+\b/g);
  if (camelPascal) camelPascal.forEach((m) => matches.add(m));
  const pascal = text.match(/\b[A-Z][a-z]+(?:[A-Z][a-z]+)+\b/g);
  if (pascal) pascal.forEach((m) => matches.add(m));
  const snake = text.match(/\b[a-z]+(?:_[a-z]+)+\b/g);
  if (snake) snake.forEach((m) => matches.add(m));
  const screaming = text.match(/\b[A-Z]+(?:_[A-Z]+)+\b/g);
  if (screaming) screaming.forEach((m) => matches.add(m));
  return [...matches];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  compressObservation,
  extractIdentifiers
});
//# sourceMappingURL=compress.js.map
