// src/reasoning-trace-recall.ts
function looksLikeProblemSolvingQuery(query) {
  if (typeof query !== "string") return false;
  const q = query.trim().toLowerCase();
  if (q.length === 0) return false;
  const startsWithPatterns = [
    /^how\s+do\s+i\b/,
    /^how\s+can\s+i\b/,
    /^how\s+would\s+i\b/,
    /^how\s+should\s+i\b/,
    /^how\s+to\b/,
    /^what'?s?\s+the\s+best\s+way\s+to\b/,
    /^can\s+you\s+walk\s+me\s+through\b/,
    /^walk\s+me\s+through\b/,
    /^help\s+me\s+debug\b/,
    /^help\s+me\s+figure\s+out\b/,
    /^why\s+(does|is|did)\b/
  ];
  for (const re of startsWithPatterns) {
    if (re.test(q)) return true;
  }
  const phrases = [
    "step by step",
    "step-by-step",
    "work through",
    "walk through",
    "walk me through",
    "reason through",
    "think through",
    "figure out",
    "chain of thought",
    "reasoning trace",
    "solution chain",
    "troubleshoot",
    "debug this",
    "debug the",
    " debug "
  ];
  for (const phrase of phrases) {
    if (q.includes(phrase)) return true;
  }
  return false;
}
function isReasoningTracePath(candidatePath) {
  if (typeof candidatePath !== "string") return false;
  return /(^|[\\/])reasoning-traces([\\/]|$)/.test(candidatePath);
}
var DEFAULT_REASONING_TRACE_BOOST = 0.15;
function applyReasoningTraceBoost(results, options) {
  if (!options.enabled) return [...results];
  if (!Array.isArray(results) || results.length === 0) return [...results];
  if (!looksLikeProblemSolvingQuery(options.query)) return [...results];
  const boostAmount = typeof options.boost === "number" && Number.isFinite(options.boost) && options.boost >= 0 ? options.boost : DEFAULT_REASONING_TRACE_BOOST;
  const boosted = [];
  let changed = false;
  for (const r of results) {
    if (isReasoningTracePath(r.path)) {
      changed = true;
      const baseScore = typeof r.score === "number" && Number.isFinite(r.score) ? r.score : 0;
      boosted.push({ ...r, score: baseScore + boostAmount });
    } else {
      boosted.push(r);
    }
  }
  if (!changed) return boosted;
  const out = boosted.slice();
  for (let i = 0; i < out.length; i++) {
    if (!isReasoningTracePath(out[i].path)) continue;
    const trace = out[i];
    const traceScore = typeof trace.score === "number" && Number.isFinite(trace.score) ? trace.score : 0;
    let j = i;
    while (j > 0) {
      const prev = out[j - 1];
      if (isReasoningTracePath(prev.path)) break;
      const prevScore = typeof prev.score === "number" && Number.isFinite(prev.score) ? prev.score : 0;
      if (prevScore >= traceScore) break;
      out[j] = prev;
      j -= 1;
    }
    if (j !== i) out[j] = trace;
  }
  return out;
}

export {
  looksLikeProblemSolvingQuery,
  isReasoningTracePath,
  DEFAULT_REASONING_TRACE_BOOST,
  applyReasoningTraceBoost
};
//# sourceMappingURL=chunk-ZZTOURJI.js.map