import {
  computeMemoryWorth
} from "./chunk-IISBCCWR.js";

// src/memory-worth-filter.ts
var NEUTRAL_PRIOR = 0.5;
function applyMemoryWorthFilter(candidates, options) {
  const reorder = options.reorder !== false;
  const result = [];
  for (let i = 0; i < candidates.length; i += 1) {
    const candidate = candidates[i];
    const counters = options.counters.get(candidate.path) ?? {};
    const worth = computeMemoryWorth({
      mw_success: counters.mw_success,
      mw_fail: counters.mw_fail,
      lastAccessed: counters.lastAccessed,
      now: options.now,
      halfLifeMs: options.halfLifeMs
    });
    const multiplier = worth.score / NEUTRAL_PRIOR;
    const safeBase = candidate.score < 0 ? 0 : candidate.score;
    const scored = safeBase * multiplier;
    result.push({
      path: candidate.path,
      score: scored,
      originalScore: candidate.score,
      multiplier,
      worth
    });
  }
  if (!reorder) return result;
  const indexed = result.map((r, i) => ({ r, i }));
  indexed.sort((a, b) => {
    if (b.r.score !== a.r.score) return b.r.score - a.r.score;
    return a.i - b.i;
  });
  return indexed.map((x) => x.r);
}
function buildMemoryWorthCounterMap(memories) {
  const map = /* @__PURE__ */ new Map();
  for (const m of memories) {
    const fm = m.frontmatter;
    if (fm.mw_success === void 0 && fm.mw_fail === void 0) continue;
    map.set(m.path, {
      mw_success: fm.mw_success,
      mw_fail: fm.mw_fail,
      lastAccessed: fm.lastAccessed
    });
  }
  return map;
}

export {
  applyMemoryWorthFilter,
  buildMemoryWorthCounterMap
};
//# sourceMappingURL=chunk-3GPTTA4J.js.map