/** * Session Memory Auto-Capture * * When a session ends, automatically persists decisions, patterns, * and learnings to brain.db as observations with source_type='session-debrief'. * * Also provides getSessionMemoryContext() for enriching session start/resume * with relevant brain memory. * * @epic T5149 */ import type { BrainObservationType } from '@cleocode/contracts'; import type { DebriefData } from '../sessions/handoff.js'; import type { BrainCompactHit } from './brain-retrieval.js'; /** Result of persisting session memory to brain.db. */ export interface SessionMemoryResult { /** Number of observations created */ observationsCreated: number; /** Number of links created */ linksCreated: number; /** IDs of created observations */ observationIds: string[]; /** Whether any errors occurred (best-effort -- errors don't fail the operation) */ errors: string[]; } /** A memory item to be persisted to brain.db. */ export interface MemoryItem { text: string; title: string; type: BrainObservationType; sourceSessionId: string; sourceType: 'session-debrief'; /** Optional task ID to link this observation to */ linkTaskId?: string; } /** Memory context returned for session start/resume enrichment. */ export interface SessionMemoryContext { /** Recent decisions relevant to this scope */ recentDecisions: BrainCompactHit[]; /** Patterns relevant to this scope */ relevantPatterns: BrainCompactHit[]; /** Recent observations from prior sessions */ recentObservations: BrainCompactHit[]; /** Recent learnings relevant to this scope */ recentLearnings: BrainCompactHit[]; /** Total token estimate for this context */ tokensEstimated: number; } /** * Extract memory-worthy items from debrief data. * Pure function -- no side effects. * * Items extracted: * - Decisions (from debrief.decisions[]) -> observations with type='decision' * - Tasks completed summary -> observation with type='change' * - Session-level note (if present) -> observation with type='discovery' */ export declare function extractMemoryItems(sessionId: string, debrief: DebriefData | null | undefined): MemoryItem[]; /** * Main entry point -- called from session.end handler. * Extracts memory-worthy content from debrief data and persists to brain.db. * * ALL errors are caught and accumulated in result.errors -- never throws. * * @param projectRoot - Project root directory * @param sessionId - The session that just ended * @param debrief - Rich debrief data from sessionComputeDebrief() * @returns Summary of what was persisted */ export declare function persistSessionMemory(projectRoot: string, sessionId: string, debrief: DebriefData | null | undefined): Promise; /** * Build a summarization prompt from debrief data. * * Returns a formatted prompt string that guides an LLM to produce a structured * session summary (key learnings, decisions, patterns, next actions). The result * can be passed to an LLM or stored directly as a `memoryPrompt` in the session * end result. * * Returns null when debrief contains no meaningful content to summarize. * * @param sessionId - The session ID to summarize. * @param debrief - Rich debrief data from sessionComputeDebrief(). * @task T140 @epic T134 */ export declare function buildSummarizationPrompt(sessionId: string, debrief: DebriefData | null | undefined): string | null; /** * Ingest a structured session summary directly into brain.db. * * Stores each field as a typed brain observation. Best-effort — never throws. * * @param projectRoot - Absolute path to project root. * @param sessionId - The session ID the summary belongs to. * @param summary - Structured summary with key learnings, decisions, patterns, next actions. * @task T140 @epic T134 */ export declare function ingestStructuredSummary(projectRoot: string, sessionId: string, summary: import('@cleocode/contracts').SessionSummaryInput): Promise; /** * Retrieve session memory for a given scope. * Used by briefing/handoff to enrich response with brain context. * * @param projectRoot - Project root directory * @param scope - Session scope for filtering (epic:T### or global) * @param options - Retrieval options * @returns Relevant brain memory entries */ export declare function getSessionMemoryContext(projectRoot: string, scope?: { type: string; epicId?: string; rootTaskId?: string; }, options?: { limit?: number; includeDecisions?: boolean; includePatterns?: boolean; }): Promise; //# sourceMappingURL=session-memory.d.ts.map