// src/importance.ts
var CRITICAL_PATTERNS = [
  // Explicit importance
  /\b(critical|crucial|essential|must|always|never)\b/i,
  /\b(important|remember this|don't forget)\b/i,
  // Personal identity
  /\b(my name is|i am|i'm called)\b/i,
  /\b(my (birthday|phone|email|address|ssn|password))\b/i,
  // Strong preferences
  /\b(i (hate|love|despise|adore))\b/i,
  /\b(absolutely|definitely|certainly) (not|must|should)\b/i,
  // Corrections (high weight)
  /\b(actually|no,? that's wrong|correction:?|let me correct)\b/i,
  /\b(i said|i meant|i was wrong)\b/i
];
var HIGH_PATTERNS = [
  // Decisions
  /\b(decided|decision|chose|choosing|picked|selected)\b/i,
  /\b(we('ll| will) (go with|use|implement))\b/i,
  // Instructions
  /\b(make sure|ensure|always|don't|do not|never|avoid)\b/i,
  /\b(you (should|must|need to))\b/i,
  // Temporal references (deadlines, schedules)
  /\b(by (monday|tuesday|wednesday|thursday|friday|saturday|sunday))\b/i,
  /\b(deadline|due (date|by)|by (end of|next))\b/i,
  /\b(tomorrow|next week|this week|today)\b/i,
  // Preferences
  /\b(i (prefer|like|want|need|dislike))\b/i,
  /\b(my (preference|style|approach|way))\b/i,
  // Commitments
  /\b(i('ll| will)|promise|commit|guarantee)\b/i,
  /\b(scheduled|appointment|meeting|call)\b/i
];
var LOW_PATTERNS = [
  // Uncertainty
  /\b(maybe|perhaps|possibly|might|could be)\b/i,
  /\b(i think|i guess|not sure|uncertain)\b/i,
  /\b(probably|likely|seems like)\b/i,
  // Hedging
  /\b(kind of|sort of|somewhat|a bit)\b/i,
  /\b(in a way|to some extent)\b/i
];
var TRIVIAL_PATTERNS = [
  // Greetings and filler
  /^(hi|hello|hey|yo|sup|greetings)[.!,]?\s*$/i,
  /^(ok|okay|k|sure|yes|no|yep|nope|yeah|nah)[.!]?\s*$/i,
  /^(thanks|thank you|thx|ty|cheers)[.!]?\s*$/i,
  /^(got it|understood|roger|copy|noted)[.!]?\s*$/i,
  /^(bye|goodbye|later|see ya|ttyl)[.!]?\s*$/i,
  /^(lol|haha|hehe|lmao|rofl)[.!]?\s*$/i,
  /^(hmm+|uhh*|ahh*|err*|umm*)[.!]?\s*$/i,
  // Very short content
  /^.{1,10}$/
];
var CATEGORY_BOOSTS = {
  correction: 0.15,
  // Corrections are always important
  principle: 0.12,
  // Durable rules/values
  rule: 0.11,
  // Causal IF→THEN rules
  procedure: 0.1,
  // Repeatable workflows (issue #519)
  preference: 0.1,
  // User preferences matter
  commitment: 0.1,
  // Promises/obligations
  reasoning_trace: 0.09,
  // Stored reasoning chains (issue #564)
  decision: 0.08,
  // Decisions with rationale
  relationship: 0.05,
  // Entity relationships
  skill: 0.05,
  // Capabilities
  moment: 0.03,
  // Emotional milestones
  entity: 0.02,
  // Entity facts
  fact: 0
  // Base facts, no boost
};
var STOP_WORDS = /* @__PURE__ */ new Set([
  "a",
  "an",
  "the",
  "is",
  "are",
  "was",
  "were",
  "be",
  "been",
  "being",
  "have",
  "has",
  "had",
  "do",
  "does",
  "did",
  "will",
  "would",
  "could",
  "should",
  "may",
  "might",
  "must",
  "shall",
  "can",
  "need",
  "dare",
  "ought",
  "used",
  "to",
  "of",
  "in",
  "for",
  "on",
  "with",
  "at",
  "by",
  "from",
  "as",
  "into",
  "through",
  "during",
  "before",
  "after",
  "above",
  "below",
  "between",
  "under",
  "again",
  "further",
  "then",
  "once",
  "here",
  "there",
  "when",
  "where",
  "why",
  "how",
  "all",
  "each",
  "few",
  "more",
  "most",
  "other",
  "some",
  "such",
  "no",
  "nor",
  "not",
  "only",
  "own",
  "same",
  "so",
  "than",
  "too",
  "very",
  "just",
  "and",
  "but",
  "or",
  "if",
  "because",
  "until",
  "while",
  "this",
  "that",
  "these",
  "those",
  "i",
  "me",
  "my",
  "myself",
  "we",
  "our",
  "ours",
  "ourselves",
  "you",
  "your",
  "yours",
  "yourself",
  "yourselves",
  "he",
  "him",
  "his",
  "himself",
  "she",
  "her",
  "hers",
  "herself",
  "it",
  "its",
  "itself",
  "they",
  "them",
  "their",
  "theirs",
  "themselves",
  "what",
  "which",
  "who",
  "whom",
  "whose",
  "am",
  "been",
  "being",
  "about",
  "against"
]);
function extractKeywords(content, maxKeywords = 5) {
  const words = content.toLowerCase().replace(/[^a-z0-9\s-]/g, " ").split(/\s+/).filter((w) => w.length >= 3 && !STOP_WORDS.has(w));
  const freq = /* @__PURE__ */ new Map();
  for (const word of words) {
    freq.set(word, (freq.get(word) ?? 0) + 1);
  }
  return [...freq.entries()].sort((a, b) => b[1] - a[1]).slice(0, maxKeywords).map(([word]) => word);
}
function scoreImportance(content, category, tags = []) {
  const reasons = [];
  let score = 0.5;
  const lowerContent = content.toLowerCase();
  const contentLength = content.length;
  for (const pattern of TRIVIAL_PATTERNS) {
    if (pattern.test(content)) {
      return {
        score: 0.1,
        level: "trivial",
        reasons: ["Trivial content (greeting, filler, or very short)"],
        keywords: []
      };
    }
  }
  for (const pattern of CRITICAL_PATTERNS) {
    if (pattern.test(content)) {
      score += 0.2;
      reasons.push(`Critical marker: ${pattern.source.slice(0, 30)}`);
      break;
    }
  }
  for (const pattern of HIGH_PATTERNS) {
    if (pattern.test(content)) {
      score += 0.12;
      reasons.push(`High importance marker detected`);
      break;
    }
  }
  for (const pattern of LOW_PATTERNS) {
    if (pattern.test(content)) {
      score -= 0.15;
      reasons.push(`Uncertainty/hedging detected`);
      break;
    }
  }
  const categoryBoost = CATEGORY_BOOSTS[category] ?? 0;
  if (categoryBoost > 0) {
    score += categoryBoost;
    reasons.push(`Category boost: ${category}`);
  }
  if (contentLength > 200) {
    const lengthBonus = Math.min((contentLength - 200) / 1e3, 0.1);
    score += lengthBonus;
    if (lengthBonus > 0.05) {
      reasons.push("Substantial content length");
    }
  }
  if (/\b(my|mine|i|i'm|i've|i'd|i'll)\b/i.test(content)) {
    score += 0.05;
    reasons.push("Personal reference");
  }
  if (/\b\d{2,}\b/.test(content) || /\b(version|v\d|api|config)\b/i.test(content)) {
    score += 0.03;
    reasons.push("Contains specific details");
  }
  const importantTags = tags.filter(
    (t) => ["important", "critical", "preference", "decision", "rule", "principle"].includes(t.toLowerCase())
  );
  if (importantTags.length > 0) {
    score += 0.05 * importantTags.length;
    reasons.push(`Important tags: ${importantTags.join(", ")}`);
  }
  score = Math.max(0, Math.min(1, score));
  let level;
  if (score >= 0.9) {
    level = "critical";
  } else if (score >= 0.7) {
    level = "high";
  } else if (score >= 0.4) {
    level = "normal";
  } else if (score >= 0.2) {
    level = "low";
  } else {
    level = "trivial";
  }
  const keywords = extractKeywords(content);
  return {
    score: Math.round(score * 100) / 100,
    // Round to 2 decimal places
    level,
    reasons: reasons.slice(0, 5),
    // Cap at 5 reasons
    keywords
  };
}
function rescoreMemoryImportance(memory) {
  return scoreImportance(memory.content, memory.frontmatter.category, memory.frontmatter.tags ?? []);
}
function importanceLevel(score) {
  if (score >= 0.9) return "critical";
  if (score >= 0.7) return "high";
  if (score >= 0.4) return "normal";
  if (score >= 0.2) return "low";
  return "trivial";
}
var IMPORTANCE_LEVEL_RANK = {
  trivial: 0,
  low: 1,
  normal: 2,
  high: 3,
  critical: 4
};
function isAboveImportanceThreshold(candidate, threshold) {
  return IMPORTANCE_LEVEL_RANK[candidate] >= IMPORTANCE_LEVEL_RANK[threshold];
}

export {
  scoreImportance,
  rescoreMemoryImportance,
  importanceLevel,
  isAboveImportanceThreshold
};
//# sourceMappingURL=chunk-JXS5PDQ7.js.map