/** * Session ledger — structured query layer over the staff_events table. * * The session ledger reads from staff_events to reconstruct a session's * activity history (what happened), learning profile (what patterns the * Attendant observed), and compliance state (whether the host is following * the attend/write protocol). These are the building blocks for handshake * operating rules, backfill suggestions, and checkpoint discipline lessons. * * Unlike the emitter (which writes events), this module is read-only except * for the `emitLedgerLearning()` function, which writes synthesized lessons * back into the ledger as new `session_ledger` component events. * * Key exports: * - querySessionLedger() — raw event query with filters * - querySessionLedgerLearnings() — synthesized learning events query * - emitLedgerLearning() — write a synthesized lesson to staff_events * - buildSessionLearnings() — derive lessons from raw event history */ import type { EventLevel, StaffComponent } from './staffEventEmitter'; export interface SessionLedgerQuery { agentId?: string; sessionId?: string; actionType?: string; actionTypes?: string[]; source?: string; host?: string; level?: EventLevel; since?: Date; until?: Date; limit?: number; } export interface SessionLedgerEvent { eventId: string; timestamp: string; staffComponent: StaffComponent; actionType: string; agentId: string; source: string; entityType: string | null; entityId: string | null; key: string | null; reason: string | null; level: EventLevel; metadata: Record | null; } export interface SessionLedgerLearning { actionType: string; summary: string; timestamp: string; source: string; host: string | null; sessionId: string | null; entityKey: string | null; reason: string | null; category?: 'host' | 'recall' | 'persistence' | 'compliance' | 'event'; evidenceActionTypes?: string[]; } export interface SessionLedgerLearningQuery { agentId?: string; sessionId?: string; source?: string; host?: string; since?: Date; until?: Date; limit?: number; maxLearnings?: number; } export interface SessionLedgerLearningProfile { scopesUsed: Array<'host' | 'task' | 'global'>; preferMemoryForAmbiguousTurns: boolean; priorityKeys: string[]; summaries: string[]; matchedTaskType: string | null; needsCheckpointReminder: boolean; checkpointReminder: string | null; missingWriteCategories: string[]; } export interface MemoryAttributionSummary { injectionId: string; sessionId: string | null; agentId: string; source: string; host: string | null; surfacedAt: string; scoredAt: string | null; surfaced: boolean; used: boolean; helpful: boolean; injectedKeys: string[]; injectedEntryIds: number[]; evidenceKinds: string[]; phase: string | null; reason: string | null; } export interface SessionLedgerLearningProfileQuery { agentId?: string; source?: string; host?: string; taskType?: string; since?: Date; until?: Date; limit?: number; } export declare class SessionLedgerUnavailableError extends Error { readonly code = "SESSION_LEDGER_UNAVAILABLE"; constructor(message?: string); } export declare function querySessionLedger(input?: SessionLedgerQuery): Promise; export declare function summarizeSessionLedgerLearnings(input?: SessionLedgerLearningQuery): Promise; export declare function summarizeMemoryAttribution(input?: SessionLedgerQuery): Promise; export declare function buildSessionLedgerLearningProfile(input?: SessionLedgerLearningProfileQuery): Promise; //# sourceMappingURL=sessionLedger.d.ts.map