/**
 * Reflexion Memory — Brain-stored lessons for future cycles.
 *
 * Safety constraints (non-negotiable):
 *   - confidence MUST be > 0.6 for retrieval (prevents low-quality lessons from
 *     poisoning future decisions).
 *   - TTL defaults to 30 days (stale lessons expire).
 *   - Every entry carries `sourceCycleId` and `outcomeType` for traceability.
 *   - Brain stores with category="forge_reflexion", tags=["reflexion", "agent:<id>"].
 *
 * A single incorrect reflection persisting in a long-running agent is
 * catastrophic — severity scales with agent lifetime. Confidence weighting
 * + TTL guard against reflexion poisoning.
 *
 * @public
 */
// ─── Constants ──────────────────────────────────────────────────────────────────
const MIN_CONFIDENCE = 0.6;
const DEFAULT_TTL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
// ─── Store / Query ──────────────────────────────────────────────────────────────
/**
 * Store a reflexion entry via a BrainPort-compatible archival function.
 *
 * The `archiver` is typically `brain.archiveKnowledge()` or
 * `semantic.archive()`.
 */
export async function storeReflexion(entry, agentId, archiver) {
    await archiver({
        content: entry.content,
        category: "forge_reflexion",
        tags: ["reflexion", `agent:${agentId}`],
        confidence: entry.confidence,
        metadata: {
            sourceCycleId: entry.sourceCycleId,
            outcomeType: entry.outcomeType,
            ttlMs: entry.ttlMs ?? DEFAULT_TTL_MS,
        },
    });
}
/**
 * Query reflexion memory.
 *
 * ONLY returns entries with confidence > 0.6 AND within TTL window.
 * The `querier` is typically `brain.queryKnowledge()` or `semantic.query()`.
 */
export async function queryReflexionMemory(query, querier) {
    const results = await querier(`reflexion ${query.agentId} ${query.outcomeType ?? ""}`, {
        category: "forge_reflexion",
        tags: ["reflexion", `agent:${query.agentId}`],
        limit: query.limit ?? 5,
    });
    return results.filter((entry) => {
        if (entry.confidence < MIN_CONFIDENCE)
            return false;
        return true;
    }).slice(0, query.limit ?? 5);
}
//# sourceMappingURL=reflexion.js.map