/** * Auto-Dream Cycle — autonomous BRAIN consolidation with STDP plasticity. * * Implements two trigger tiers for autonomous `runConsolidation` dispatch: * * Tier 1 — Volume threshold (primary): * When `brain_observations` delta since last consolidation exceeds * VOLUME_THRESHOLD_DEFAULT (10), trigger immediately. * * Tier 2 — Idle detection (secondary): * When `brain_retrieval_log` shows no activity for IDLE_MINUTES_DEFAULT (30) * minutes, trigger consolidation in the background. * * Tier 3 (nightly setTimeout chaining) has been removed — the sentient daemon * tick loop (`sentient/tick.ts`) is now the canonical trigger host. Each tick * evaluates both Tier 1 and Tier 2 via `checkAndDream`. This eliminates * setTimeout drift across long-running processes. * * Each trigger calls `runConsolidation(projectRoot, sessionId, 'scheduled')` * which includes Steps 9a (R-STDP reward backfill) + 9b (STDP plasticity) + * 9c (homeostatic decay) per docs/specs/stdp-wire-up-spec.md §4. * * Idempotency: `checkAndDream` tracks `lastDreamAt` in-process so that * repeated calls within the same process cannot double-trigger consolidation. * The `brain_consolidation_events` table provides cross-process idempotency * via the cooldown window check. * * @task T628 * @epic T627 * @see docs/specs/stdp-wire-up-spec.md §4.5 */ /** Result of a `checkAndDream` evaluation. */ export interface DreamCheckResult { /** Whether consolidation was triggered. */ triggered: boolean; /** Which tier fired (or null if no trigger). */ tier: 'volume' | 'idle' | 'cron' | 'manual' | null; /** Reason consolidation was skipped (if not triggered). */ skippedReason?: string; /** New observations since last consolidation (volume trigger input). */ newObservationCount?: number; /** Minutes since last retrieval activity (idle trigger input). */ idleMinutes?: number; } /** Options accepted by `checkAndDream`. */ export interface DreamCycleOptions { /** Minimum new observations to trigger volume tier. Default: 10. */ volumeThreshold?: number; /** Minutes of retrieval inactivity to trigger idle tier. Default: 30. */ idleThresholdMinutes?: number; /** Session ID forwarded to runConsolidation (for Step 9a). */ sessionId?: string | null; /** * Whether to run inline (await) vs fire-and-forget (setImmediate). * Default: false (fire-and-forget). * * **Process lifetime (T9948):** in the fire-and-forget path the timer * handle is `unref()`-ed so that the host process is NOT kept alive by * a pending dream cycle. Long-lived hosts (e.g. the sentient daemon) * have other unrelated work that keeps the event loop running, so * unref-ing here only changes the short-lived case (`cleo briefing`, * `cleo show`, …) — those invocations now exit promptly instead of * hanging the SQLite writer lock for as long as `runConsolidation` * takes to finish. */ inline?: boolean; } /** * Volume trigger: return true when new observation count since last * consolidation exceeds `threshold`. * * @param threshold - Minimum new observations required to trigger. * @returns Object with the decision and the raw observation count. */ export declare function checkVolumeTrigger(threshold: number): { shouldTrigger: boolean; newObservationCount: number; }; /** * Idle trigger: return true when retrieval activity HAS occurred before * and no new activity has been seen for at least `idleThresholdMinutes`. * * When no retrievals have ever been recorded (null timestamp), the idle * trigger does NOT fire — the system is newly initialised, not idle. * * @param idleThresholdMinutes - Required idle window in minutes. * @returns Object with the decision and elapsed idle minutes. */ export declare function checkIdleTrigger(idleThresholdMinutes: number): { shouldTrigger: boolean; idleMinutes: number; }; /** * Evaluate all three trigger tiers and fire the dream cycle when any triggers. * * Tier evaluation order: volume → idle → (cron is timer-based, not checked here). * * Idempotency guards: * - `dreamInFlight` prevents overlapping concurrent runs. * - `DREAM_COOLDOWN_MS` (5 min) prevents repeated triggers in a tight loop. * * @param projectRoot - Project root for brain.db resolution. * @param opts - Optional tuning parameters. * @returns Check result indicating whether and why consolidation was triggered. * * @task T628 */ export declare function checkAndDream(projectRoot: string, opts?: DreamCycleOptions): Promise; /** * Manually trigger the full dream cycle immediately. * * Bypasses all trigger thresholds and cooldown guards. Intended for * `cleo memory dream` CLI invocation and test scaffolding. * * @param projectRoot - Project root for brain.db resolution. * @param sessionId - Active session ID (for Step 9a reward backfill). * @returns The RunConsolidationResult from the full pipeline. * * @task T628 */ export declare function triggerManualDream(projectRoot: string, sessionId?: string | null): Promise; /** * Reset in-process dream cycle state. * * Intended for test teardown only. Clears `lastDreamAt` and `dreamInFlight`. * The nightly setTimeout scheduler has been removed — the sentient tick loop * is now the canonical trigger host (T996). * * @internal */ export declare function _resetDreamState(): void; /** * Structured status response from `cleo memory dream --status`. * * All fields are present in every response. Fields sourced from the in-process * module state (`dreamInFlight`, `lastDreamAt`) reflect the state of the current * process only; across process restarts the values reset to their defaults. * Fields sourced from brain.db (`lastConsolidatedAt`, `observationsSinceLastConsolidation`, * `idleMinutesSinceLastRetrieval`) reflect the persistent on-disk state. */ export interface DreamStatus { /** ISO 8601 timestamp of the last completed consolidation event, or null if none. */ lastConsolidatedAt: string | null; /** Count of brain_observations created after the last consolidation event. */ observationsSinceLastConsolidation: number; /** Minutes since the last brain_retrieval_log entry. Infinity-like value when no retrieval ever. */ idleMinutesSinceLastRetrieval: number; /** Whether the sentient tick loop has run within the last 90 minutes (cross-process check via state file). */ tickLoopAlive: boolean; /** ISO 8601 timestamp of the last sentient tick, or null if never run / unavailable. */ lastTickAt: string | null; /** Whether a dream cycle is currently running in this process. */ dreamInFlight: boolean; /** Last error message encountered by the dream cycle, if any. */ lastError: string | null; /** * `true` when the dream cycle is considered overdue: * - More than `volumeThreshold * 5` new observations since last consolidation, OR * - `lastConsolidatedAt` is older than 24h AND there are any new observations. */ isOverdue: boolean; } /** * Return the current dream-cycle engine liveness status. * * Used by `cleo memory dream --status` to check whether the consolidation * pipeline is running at a healthy cadence. Exits with code 1 when `isOverdue=true`. * * @param projectRoot - Absolute path to the CLEO project root. * @returns DreamStatus with all 8 named fields populated. * * @task T1895 */ export declare function getDreamStatus(projectRoot: string): Promise; //# sourceMappingURL=dream-cycle.d.ts.map