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

// src/negative.ts
import { mkdir, readFile, writeFile } from "fs/promises";
import path from "path";
var NegativeExampleStore = class {
  statePath;
  state = {};
  constructor(memoryDir) {
    this.statePath = path.join(memoryDir, "state", "negative_examples.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 that a memory was retrieved but not useful for the user.
   * This should be lightweight and never block agent execution.
   */
  async recordNotUseful(memoryIds, note) {
    const now = (/* @__PURE__ */ new Date()).toISOString();
    for (const memoryId of memoryIds) {
      const existing = this.state[memoryId] ?? { notUseful: 0, lastUpdatedAt: now };
      const next = {
        notUseful: existing.notUseful + 1,
        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(`negative example store write failed: ${err}`);
    }
  }
  /**
   * Convert negative examples into a small score penalty.
   * Intended as a soft bias, not a hard filter.
   */
  penalty(memoryId, opts) {
    const entry = this.state[memoryId];
    if (!entry) return 0;
    const hits = Math.min(10, entry.notUseful);
    const raw = hits * opts.perHit;
    return Math.min(opts.cap, raw);
  }
};

export {
  NegativeExampleStore
};
//# sourceMappingURL=chunk-D654IBA6.js.map