/**
 * Skill Ledger — types + resolver for persisted winning strategies.
 *
 * SkillLedgerEntry mirrors the `skill_ledger` DB schema (migration 028).
 * resolveSkillsForAgent implements LIFO scope-typed resolution:
 *   1. Match by agent_id (exact) OR agent_id='*' (cross-agent wildcard)
 *   2. Match outcome_type
 *   3. lifecycle_state === 'active'
 *   4. Sort descending by created_at (LIFO — most recent wins)
 *
 * @public
 * Ref: command-center:sprint-530:quick-4
 */
// ─── Resolver ─────────────────────────────────────────────────────────────────
/**
 * Resolve skills for a given agent + outcome type.
 *
 * LIFO scope-typed algorithm:
 *   - Include entries where `agent_id === agentId` OR `agent_id === '*'`
 *   - Include entries where `outcome_type === outcomeType`
 *   - Include entries where `lifecycle_state === 'active'`
 *   - Sort descending by `created_at` (most recent first)
 *   - Apply optional `limit`
 *
 * Pure function — no side effects.
 */
export function resolveSkillsForAgent(skills, opts) {
    const { agentId, outcomeType, limit } = opts;
    const filtered = skills.filter((s) => (s.agent_id === agentId || s.agent_id === "*") &&
        s.outcome_type === outcomeType &&
        s.lifecycle_state === "active");
    // LIFO: most recent created_at first
    filtered.sort((a, b) => {
        const ta = new Date(a.created_at).getTime();
        const tb = new Date(b.created_at).getTime();
        return tb - ta;
    });
    return limit !== undefined ? filtered.slice(0, limit) : filtered;
}
//# sourceMappingURL=skill-ledger.js.map