/** * Consolidation Specialists — T1146 Wave 6 Dreamer Upgrade * * Implements the `BaseSpecialist` interface and 6 concrete specialist classes * for targeted memory consolidation during dream cycles. * * Specialists process high-surprisal observations in priority order, each * routing observations to the appropriate BRAIN table based on their * cognitive type. * * LLM backend: uses `resolveLlmBackend('warm')` from llm-backend-resolver.ts. * When backend returns null, each specialist MUST silently no-op (not throw). * This matches the `sleep-consolidation.ts` pattern (no API key = silent no-op). * * Specialists: * 1. DeductionSpecialist — logical consequences → brain_learnings * 2. InductionSpecialist — pattern generalization → brain_patterns * 3. UserPreferenceSpecialist — preference signals → brain_observations (preference type) * 4. DecisionSpecialist — high-surprisal decisions → brain_decisions * 5. CodePatternSpecialist — code change patterns → brain_patterns * 6. TaskOutcomeSpecialist — task completion links → brain_observations (task-outcome type) * * @task T1146 * @epic T1146 */ import type { DatabaseSync } from 'node:sqlite'; import type { SurprisalResult } from './surprisal.js'; /** Quality score for specialist-generated learnings (reserved for future use). */ /** High surprisal threshold — only observations above this are specialist-routed. */ export declare const SPECIALIST_SURPRISAL_THRESHOLD = 0.6; /** An observation row passed to specialists. */ export interface SpecialistObservation { id: string; type: string; title: string | null; narrative: string | null; project: string | null; peerId: string; sourceSessionId: string | null; surprisal?: number; } /** Result of a single specialist dispatch. */ export interface SpecialistResult { /** Name of the specialist that ran. */ specialist: string; /** Number of new BRAIN entries created. */ created: number; /** Whether the specialist was skipped (e.g. no LLM available). */ skipped: boolean; /** Reason for skip (if any). */ skipReason?: string; } /** Aggregated result of dispatching all specialists. */ export interface DispatchSpecialistsResult { /** Per-specialist results. */ specialists: SpecialistResult[]; /** Total new BRAIN entries created. */ totalCreated: number; /** Number of specialists skipped. */ totalSkipped: number; } /** Options for specialist dispatch. */ export interface DispatchOptions { /** Inject a DatabaseSync for testing. */ db?: DatabaseSync | null; /** Override LLM resolver (returns null to test graceful degrade). */ resolveLlm?: () => Promise; } /** * Base interface for all consolidation specialists. * * Each specialist receives a batch of high-surprisal observations and * writes derived entries to the appropriate BRAIN table. * * Contract: * - MUST NOT throw (all errors → skipped result) * - MUST return skipped=true when LLM backend is null * - MUST set created=0 when no output is written * * @task T1146 */ export interface BaseSpecialist { /** Human-readable specialist name (for logging). */ readonly name: string; /** * Process a batch of high-surprisal observations. * * @param observations - Observations to process (pre-filtered by surprisal threshold). * @param llmAvailable - Whether an LLM backend was resolved. * @param nativeDb - Database handle. * @returns SpecialistResult with created count and skip status. */ process(observations: SpecialistObservation[], llmAvailable: boolean, nativeDb: DatabaseSync): Promise; } /** * Deduction Specialist — extracts logical consequences and routes to brain_learnings. * * Pattern: observations with factual or technical content → synthesize * a concise learning insight. * * @task T1146 */ export declare class DeductionSpecialist implements BaseSpecialist { readonly name = "DeductionSpecialist"; process(observations: SpecialistObservation[], llmAvailable: boolean, nativeDb: DatabaseSync): Promise; } /** * Induction Specialist — generalizes patterns across multiple observations. * Routes to brain_patterns. * * @task T1146 */ export declare class InductionSpecialist implements BaseSpecialist { readonly name = "InductionSpecialist"; process(observations: SpecialistObservation[], llmAvailable: boolean, nativeDb: DatabaseSync): Promise; } /** * UserPreference Specialist — extracts preference signals from user-facing observations. * Routes to brain_observations with type='preference'. * * @task T1146 */ export declare class UserPreferenceSpecialist implements BaseSpecialist { readonly name = "UserPreferenceSpecialist"; process(observations: SpecialistObservation[], llmAvailable: boolean, nativeDb: DatabaseSync): Promise; } /** * Decision Specialist — routes high-surprisal observations to brain_decisions. * * @task T1146 */ export declare class DecisionSpecialist implements BaseSpecialist { readonly name = "DecisionSpecialist"; process(observations: SpecialistObservation[], llmAvailable: boolean, nativeDb: DatabaseSync): Promise; } /** * CodePattern Specialist — synthesizes code-related patterns into brain_patterns. * * @task T1146 */ export declare class CodePatternSpecialist implements BaseSpecialist { readonly name = "CodePatternSpecialist"; process(observations: SpecialistObservation[], llmAvailable: boolean, nativeDb: DatabaseSync): Promise; } /** * TaskOutcome Specialist — links consolidation to task completion events. * Routes to brain_observations with level='inductive' as task-outcome records. * * @task T1146 */ export declare class TaskOutcomeSpecialist implements BaseSpecialist { readonly name = "TaskOutcomeSpecialist"; process(observations: SpecialistObservation[], llmAvailable: boolean, nativeDb: DatabaseSync): Promise; } /** * Dispatch all specialists on a batch of high-surprisal observations. * * Specialists with surprisal above {@link SPECIALIST_SURPRISAL_THRESHOLD} * are processed; others are skipped. * * When LLM backend is null: all specialists return skipped=true (silent no-op). * Errors per specialist are caught — one failing specialist does not block others. * * @param observations - Observations with optional surprisal scores. * @param scoredResults - Surprisal scores (matched by id). If null, all are processed. * @param options - db injection, LLM resolver override for tests. * @returns Aggregated results across all specialists. * * @task T1146 */ export declare function dispatchSpecialists(observations: SpecialistObservation[], scoredResults: SurprisalResult[] | null, options?: DispatchOptions): Promise; //# sourceMappingURL=specialists.d.ts.map