/**
 * AutoLearningSubscriber (LEARN-1)
 *
 * Subscribes to terminal WorkItem and mission lifecycle events on the
 * EventBus and auto-records a learning entry via the existing
 * {@link MemoryService.recordLearning} entrypoint. Closes the
 * "agents-forget-to-record" gap noted in `.crewly/tmp/autonomy-doc-review-2026-04-26.md`
 * §4 item 6 without introducing the rejected new "L-Event" type (Arch Veto V7,
 * promoted from canonical V2 per the V-numbering map of 2026-04-27) and
 * without expanding the 3-scope memory model into the rejected 5-scope shape
 * (Arch Veto V9, promoted from canonical V3).
 *
 * Subscribed events:
 *   - `task:verified`    → `pattern`     (a passed verification — what worked)
 *   - `task:done`        → `pattern`     (a completion — what worked)
 *   - `task:rejected`    → `gotcha`      (TL rejected — what didn't work)
 *   - `task:failed`      → `gotcha`      (worker failed — what broke)
 *   - `mission:replanned`→ `sop_update`  (strategy changed — operating practice)
 *
 * Idempotency contract (Arch Veto V1):
 *   Each handler dedupe-checks `${eventType}:${workItemId}` (or
 *   `${eventType}:${missionId}:${eventId}` for mission events) against an
 *   in-memory bounded LRU. The underlying `recordLearning()` is append-only
 *   (no native dedup), so the subscriber owns idempotency. The LRU is capped
 *   at {@link DEDUP_LRU_CAPACITY} entries to bound growth across long-lived
 *   processes.
 *
 * No new event types (Arch Veto V7):
 *   The subscriber listens to event types that already exist in `EVENT_TYPES`
 *   (added by BRIDGE-1.1). It does NOT introduce a new event class or any
 *   `learning:*` vocabulary. The implementation-detector grep at PR time —
 *   class/interface/type/new declarations — yields empty.
 *
 * No memory-scope expansion (Arch Veto V9):
 *   `recordLearning()` is called with the existing scope model. No new
 *   `team` / `user` scope members are added, and no `Skill`-prefixed candidate
 *   type is introduced. The implementation-detector grep at PR time yields
 *   empty.
 *
 * Fire-and-forget:
 *   Subscribers are called synchronously by the EventBus (in-process) but
 *   `recordLearning` itself is async; we wrap each dispatch so a thrown
 *   error is logged without affecting other subscribers or the publisher
 *   call site (mirrors {@link EventToWorkItemBridge.safeDispatch}).
 *
 * @module services/memory/auto-learning.subscriber
 */
import { type ComponentLogger } from '../core/logger.service.js';
import type { IMemoryService } from './memory.service.js';
import type { EventBusService } from '../event-bus/event-bus.service.js';
import type { EventType } from '../../types/event-bus.types.js';
/**
 * Tag prefix appended to the auto-recorded learning string. This is **not**
 * the {@link RememberCategory} enum used by the unified remember operation —
 * `recordLearning` writes free-form text to the project learnings log
 * (no `category` field), so this string prefix exists purely for human/grep
 * downstream filtering. Keeping it local avoids a forced extension of
 * `RememberCategory` (Arch Veto V9 forbids enum sprawl).
 */
export type AutoLearningTag = 'pattern' | 'gotcha' | 'sop_update';
/**
 * Event types this subscriber listens to. Order mirrors the dispatch table
 * inside {@link AutoLearningSubscriber.start} for easy audit.
 *
 * **Closed-set rationale (Arch N1, 2026-04-27):** This list is deliberately
 * *closed* — only events that mark a terminal/quasi-terminal transition with
 * a learning-worthy outcome are members. Adding a new entry requires:
 *   1. The event type already exists in `EVENT_TYPES` (no V7 violation).
 *   2. A corresponding entry in {@link EVENT_CATEGORY_MAP} (otherwise the
 *      handler defensively skips with a warn — see {@link handle}).
 *   3. A new spec in `auto-learning.subscriber.test.ts` covering the
 *      category mapping and dedup key shape for the new event.
 * The closed-set property is enforced at runtime by the export-allowlist
 * check in the V7 self-check spec — adding a member without updating the
 * allowlist fails CI.
 *
 * NOTE: All five exist in `EVENT_TYPES` already (added by BRIDGE-1.1). LEARN-1
 * adds zero new event types — Arch Veto V7 holds.
 */
export declare const LEARN_SUBSCRIBED_EVENTS: readonly EventType[];
/**
 * Stable identity used as the `agentId` on every auto-recorded learning.
 * Distinct from any human/agent session so the project learnings log makes
 * the system origin visible (`### [system/system:auto-learning] hh:mm:ss`).
 */
export declare const AUTO_LEARNING_AGENT_ID = "system:auto-learning";
export declare const AUTO_LEARNING_AGENT_ROLE = "system";
/**
 * Maximum entries retained in the dedup LRU. Sized for ~hours of typical
 * event volume; the dominant cost is map memory which is negligible at 1k.
 */
export declare const DEDUP_LRU_CAPACITY = 1000;
/**
 * Optional dependency container so tests can supply fakes for the event bus
 * and memory service without touching singletons.
 */
export interface AutoLearningSubscriberDependencies {
    /** Live event bus. */
    eventBus: EventBusService;
    /** Memory service that owns `recordLearning`. */
    memoryService: IMemoryService;
    /** Project path used for the project-learnings log. Defaults to {@link process.cwd}. */
    projectPath?: string;
    /** Optional logger (defaults to component logger). */
    logger?: ComponentLogger;
    /** Optional dedup LRU capacity override (defaults to {@link DEDUP_LRU_CAPACITY}). */
    dedupCapacity?: number;
}
/**
 * AutoLearningSubscriber — the LEARN-1 deliverable.
 *
 * Wired in `backend/src/index.ts` via {@link AutoLearningSubscriber.boot}; tests
 * construct via the constructor directly with fake dependencies.
 *
 * @example
 * ```typescript
 * const subscriber = AutoLearningSubscriber.boot(eventBus);
 * subscriber.start();
 * // … later, on shutdown:
 * subscriber.stop();
 * ```
 */
export declare class AutoLearningSubscriber {
    private readonly eventBus;
    private readonly memoryService;
    private readonly projectPath;
    private readonly logger;
    private readonly dedup;
    private unsubscribers;
    private started;
    /**
     * In-flight async dispatch promises. Test code calls
     * {@link flushPending} to await every in-flight call deterministically.
     */
    private pendingDispatches;
    constructor(deps: AutoLearningSubscriberDependencies);
    /**
     * Production wiring helper. Tests should use the constructor directly.
     *
     * @param eventBus - The live event bus
     * @param projectPath - Optional override for the project-learnings target path
     * @returns A subscriber instance ready to `start()`
     */
    static boot(eventBus: EventBusService, projectPath?: string): AutoLearningSubscriber;
    /**
     * Subscribe to all configured events. Idempotent — calling twice is a no-op.
     */
    start(): void;
    /**
     * Wait for every in-flight dispatch to settle. Test affordance.
     */
    flushPending(): Promise<void>;
    /**
     * Detach all subscriptions. Safe to call more than once.
     */
    stop(): void;
    /**
     * Snapshot of the dedup state (test affordance — production code never
     * reads this).
     */
    get dedupSize(): number;
    /**
     * Core handler. Resolves the idempotency key, dedupes, picks the category,
     * builds the templated summary, and calls `memoryService.recordLearning()`.
     */
    private handle;
    /**
     * Wrap a dispatch so a thrown error is logged without poisoning other
     * subscribers or the publisher. Mirrors
     * {@link EventToWorkItemBridge.safeDispatch}.
     */
    private safeDispatch;
}
//# sourceMappingURL=auto-learning.subscriber.d.ts.map