/**
 * Persistent Audit Log Service (SQLite)
 *
 * Provides durable, queryable audit logging using better-sqlite3.
 * Replaces the append-only JSONL approach with a proper relational store
 * that supports efficient filtering, pagination, and aggregation.
 *
 * Single WAL-mode database shared across all sessions. Thread-safe for
 * the single-threaded Node.js event loop (better-sqlite3 is synchronous).
 *
 * @module services/agent/crewly-agent/audit-log.service
 */
import type { AuditEntry, AuditLogFilters, ToolSensitivity } from './types.js';
/**
 * Extended audit entry stored in the database.
 * Adds an auto-incremented row ID and an action field for approval events.
 */
export interface AuditLogRow extends AuditEntry {
    /** Auto-incremented row ID */
    id: number;
    /** Action type: 'tool_call' | 'approval_granted' | 'approval_rejected' | 'approval_expired' */
    action: string;
    /** Who resolved an approval (e.g. 'api', 'auditor', 'auto-expire') */
    resolvedBy?: string;
    /** Approval ID if this entry relates to an approval event */
    approvalId?: string;
}
/**
 * Query filters for the audit log, extending the base AuditLogFilters.
 */
export interface AuditLogQueryFilters extends AuditLogFilters {
    /** Filter by session name */
    sessionName?: string;
    /** Filter by action type */
    action?: string;
    /** Filter entries after this ISO timestamp */
    since?: string;
    /** Filter entries before this ISO timestamp */
    until?: string;
    /** Offset for pagination */
    offset?: number;
}
/**
 * SQLite-backed persistent audit log service.
 *
 * @example
 * ```typescript
 * const log = new AuditLogService('/path/to/.crewly');
 * log.initialize();
 * log.append(auditEntry);
 * log.logApprovalEvent('approval-123', 'session-1', 'edit_file', 'destructive', 'approved', 'api');
 * const entries = log.query({ limit: 50, sessionName: 'session-1' });
 * log.close();
 * ```
 */
export declare class AuditLogService {
    private db;
    private dbPath;
    private initialized;
    /** Prepared statements for performance */
    private stmtInsert;
    private stmtInsertApproval;
    /**
     * Create a new AuditLogService.
     *
     * @param crewlyHome - Path to the .crewly directory
     * @param dbFilename - Database filename (default: audit-log.sqlite)
     */
    constructor(crewlyHome: string, dbFilename?: string);
    /**
     * Initialize the database, creating tables if needed.
     * Enables WAL mode for better concurrent read performance.
     */
    initialize(): void;
    /**
     * Append a tool-call audit entry.
     *
     * @param entry - The AuditEntry from the agent runtime
     */
    append(entry: AuditEntry): void;
    /**
     * Log an approval lifecycle event (granted, rejected, expired).
     *
     * @param approvalId - The approval request ID
     * @param sessionName - Agent session name
     * @param toolName - Tool that was approved/rejected
     * @param sensitivity - Sensitivity classification
     * @param action - 'approval_granted' | 'approval_rejected' | 'approval_expired'
     * @param resolvedBy - Who resolved it
     */
    logApprovalEvent(approvalId: string, sessionName: string, toolName: string, sensitivity: ToolSensitivity, action: 'approval_granted' | 'approval_rejected' | 'approval_expired', resolvedBy: string): void;
    /**
     * Query audit log entries with filters and pagination.
     *
     * @param filters - Query filters
     * @returns Array of audit log rows, most recent first
     */
    query(filters: AuditLogQueryFilters): AuditLogRow[];
    /**
     * Get total count of entries matching filters (for pagination).
     *
     * @param filters - Same filters as query (limit/offset ignored)
     * @returns Total matching row count
     */
    count(filters?: Partial<AuditLogQueryFilters>): number;
    /**
     * Get the database file path.
     *
     * @returns Absolute path to the SQLite database
     */
    getDbPath(): string;
    /**
     * Check if the service is initialized.
     *
     * @returns True if initialize() has been called
     */
    isInitialized(): boolean;
    /**
     * Close the database connection.
     * Safe to call multiple times.
     */
    close(): void;
    /**
     * Ensure the service is initialized before operations.
     *
     * @throws Error if not initialized
     */
    private ensureInitialized;
}
//# sourceMappingURL=audit-log.service.d.ts.map