import {
  log
} from "./chunk-2ODBA7MQ.js";

// src/relevance.ts
import { mkdir, readFile, writeFile } from "fs/promises";
import path from "path";
var RelevanceStore = class {
  statePath;
  state = {};
  constructor(memoryDir) {
    this.statePath = path.join(memoryDir, "state", "relevance.json");
  }
  async load() {
    try {
      const raw = await readFile(this.statePath, "utf-8");
      const parsed = JSON.parse(raw);
      if (parsed && typeof parsed === "object") this.state = parsed;
    } catch {
      this.state = {};
    }
  }
  /**
   * Record a thumbs up/down for a memory ID.
   * This is intentionally lightweight; it should never block agent execution.
   */
  async record(memoryId, vote, note) {
    const now = (/* @__PURE__ */ new Date()).toISOString();
    const existing = this.state[memoryId] ?? { up: 0, down: 0, lastUpdatedAt: now };
    const next = {
      up: existing.up + (vote === "up" ? 1 : 0),
      down: existing.down + (vote === "down" ? 1 : 0),
      lastUpdatedAt: now,
      notes: note ? [...(existing.notes ?? []).slice(-19), note] : existing.notes
    };
    this.state[memoryId] = next;
    try {
      await mkdir(path.dirname(this.statePath), { recursive: true });
      await writeFile(this.statePath, JSON.stringify(this.state, null, 2), "utf-8");
    } catch (err) {
      log.debug(`relevance store write failed: ${err}`);
    }
  }
  /**
   * Convert feedback into a small score adjustment.
   * Intended to be used as a tie-breaker/soft bias, not a hard filter.
   */
  adjustment(memoryId) {
    const fb = this.state[memoryId];
    if (!fb) return 0;
    const up = Math.min(3, fb.up);
    const down = Math.min(3, fb.down);
    return up * 0.05 - down * 0.1;
  }
};

export {
  RelevanceStore
};
//# sourceMappingURL=chunk-5NPGSAVB.js.map