/**
 * Unified Session State Snapshot
 *
 * Single source of truth for persistence, report generation, and session restoration.
 * Replaces the fragile 7-phase persistence cascade (7 sequential read-modify-write
 * cycles on the same SQLite metadata JSON blob) with one atomic write.
 *
 * Written at analysis completion; read by resume, report, and SSE reconnect paths.
 *
 * Key invariants:
 * 1. Snapshot is the single source of truth for report generation — never assemble
 *    from live getters + fallback chains.
 * 2. Snapshot is written atomically — one UPDATE metadata call, not 6+ sequential RMW.
 * 3. All restoration paths read the same snapshot — resume, report, SSE reconnect.
 * 4. ClaudeRuntime Maps = live cache; snapshot = durable copy.
 * 5. Backward compatibility through dual-write — no breaking changes for old sessions.
 */
import type { AnalysisNote, AnalysisPlanV3, Hypothesis, UncertaintyFlag } from './types';
import type { StoredArtifact } from './artifactStore';
import type { ArchitectureInfo } from '../agent/detectors/types';
import type { DataEnvelope } from '../types/dataContract';
import type { ClaimSupportV1 } from '../types/evidenceContract';
import type { ClaimVerificationResult } from '../types/claimVerification';
import type { IdentityResolutionV1 } from '../types/identityContract';
import type { CodeAwareMode } from '../services/codebase/codeAwareFeature';
import type { CodeLookupSummary } from '../services/codebase/codeLookupLedger';
export type ComparisonSourceKind = 'raw_trace_pair' | 'analysis_result_snapshots';
export interface ComparisonReportSection {
    source: ComparisonSourceKind;
    title: string;
    markdown: string;
    html: string;
    limitations?: string[];
    evidencePack?: unknown;
}
/** A step in the conversation timeline (SSE event log). */
export interface ConversationStep {
    eventId: string;
    ordinal: number;
    phase: 'progress' | 'thinking' | 'tool' | 'result' | 'error';
    role: 'agent' | 'system';
    text: string;
    timestamp: number;
    sourceEventType?: string;
}
/** A query submitted by the user in a specific turn. */
export interface QueryHistoryEntry {
    turn: number;
    query: string;
    timestamp: number;
}
/** A conclusion generated by the agent after a specific turn. */
export interface ConclusionHistoryEntry {
    turn: number;
    conclusion: string;
    confidence: number;
    timestamp: number;
}
/** An inter-agent dialogue entry (task dispatch / response / question). */
export interface AgentDialogueEntry {
    agentId: string;
    type: 'task' | 'response' | 'question';
    content: any;
    timestamp: number;
}
/** A response from a sub-agent task. */
export interface AgentResponseEntry {
    taskId: string;
    agentId: string;
    response: any;
    timestamp: number;
}
export interface SnapshotRunContext {
    runId: string;
    requestId: string;
    sequence: number;
    query: string;
    startedAt: number;
    completedAt?: number;
    status: 'pending' | 'running' | 'completed' | 'failed' | 'quota_exceeded';
    error?: string;
}
/**
 * Unified session state snapshot.
 *
 * Captures all session state needed for:
 * - Atomic persistence (single SQLite metadata UPDATE)
 * - HTML/JSON report generation (no live getter fallback chains)
 * - Session restoration on resume (all ClaudeRuntime Maps + session arrays)
 */
export interface SessionStateSnapshot {
    /** Schema version — enables future format migrations. */
    version: 1;
    /** When this snapshot was taken. */
    snapshotTimestamp: number;
    sessionId: string;
    traceId: string;
    /** Reference trace ID for comparison mode — enables session restoration in dual-trace context */
    referenceTraceId?: string;
    /** Source model for comparison mode. Raw dual-trace sessions use raw_trace_pair. */
    comparisonSource?: ComparisonSourceKind;
    /** Shared deterministic comparison section used by CLI and HTML reports. */
    comparisonReportSection?: ComparisonReportSection;
    conversationSteps: ConversationStep[];
    queryHistory: QueryHistoryEntry[];
    conclusionHistory: ConclusionHistoryEntry[];
    agentDialogue: AgentDialogueEntry[];
    agentResponses: AgentResponseEntry[];
    dataEnvelopes: DataEnvelope[];
    claimSupport?: ClaimSupportV1[];
    claimVerificationResult?: ClaimVerificationResult;
    identityResolutions?: IdentityResolutionV1[];
    /**
     * Protocol-format hypotheses (from AnalysisResult) for report generation.
     * These use the agentProtocol.Hypothesis shape (id, description, status, confidence).
     */
    hypotheses: any[];
    analysisNotes: AnalysisNote[];
    analysisPlan: AnalysisPlanV3 | null;
    planHistory: AnalysisPlanV3[];
    uncertaintyFlags: UncertaintyFlag[];
    /**
     * agentv3-internal hypotheses (richer than protocol format).
     * Used to restore ClaudeRuntime.sessionHypotheses Map on resume.
     * Contains: id, statement, status, basis, evidence, formedAt, resolvedAt.
     */
    claudeHypotheses?: Hypothesis[];
    architecture?: ArchitectureInfo;
    sdkSessionId?: string;
    sdkSessionMode?: 'full';
    /** Runtime that produced the snapshot. Omitted for legacy Claude-only snapshots. */
    agentRuntimeKind?: 'claude-agent-sdk' | 'openai-agents-sdk';
    /**
     * Provider profile that supplied runtime credentials.
     * null means the session is pinned to env/default fallback and must not read
     * the current active Provider Manager profile during restoration.
     */
    agentRuntimeProviderId?: string | null;
    /**
     * Non-secret hash of the provider/runtime configuration that created the SDK
     * session. Resume may only reuse sdkSessionId when this still matches the
     * current resolved provider snapshot.
     */
    agentRuntimeProviderSnapshotHash?: string | null;
    /** OpenAI Agents SDK history for cross-restart multi-turn continuation. */
    openAIHistory?: unknown[];
    /** Last provider response ID from the OpenAI Agents SDK run. */
    openAILastResponseId?: string;
    /** Reserved serialized OpenAI run state for future SDK-native restoration. */
    openAIRunState?: string;
    /** Code-aware analysis mode persisted with the session. */
    codeAwareMode?: CodeAwareMode;
    /** Explicit codebase allowlist used by this session. */
    codebaseIds?: string[];
    /** Non-secret consent/index-generation state captured for resume/report safety. */
    codebaseSnapshot?: Array<{
        codebaseId: string;
        indexGeneration: number;
        consentHash?: string;
    }>;
    /** Append-only lookup ledger summary for this session. */
    codeLookupSummary?: CodeLookupSummary;
    artifacts?: StoredArtifact[];
    runSequence: number;
    conversationOrdinal: number;
    activeRun?: SnapshotRunContext;
    lastRun?: SnapshotRunContext;
}
/**
 * Session-level fields provided by the route layer to `takeSnapshot()`.
 *
 * ClaudeRuntime reads its own Maps (notes, plans, flags, artifacts, architecture,
 * sdkSessionId) internally. The route layer provides the session-scoped arrays
 * that live in the AnalysisSession object.
 */
export interface SessionFieldsForSnapshot {
    /** Reference trace ID for comparison mode session identity. */
    referenceTraceId?: string;
    /** Source model for comparison mode. */
    comparisonSource?: ComparisonSourceKind;
    /** Shared deterministic comparison report section, when available. */
    comparisonReportSection?: ComparisonReportSection;
    conversationSteps: ConversationStep[];
    queryHistory: QueryHistoryEntry[];
    conclusionHistory: ConclusionHistoryEntry[];
    agentDialogue: AgentDialogueEntry[];
    agentResponses: AgentResponseEntry[];
    dataEnvelopes: DataEnvelope[];
    claimSupport?: ClaimSupportV1[];
    claimVerificationResult?: ClaimVerificationResult;
    identityResolutions?: IdentityResolutionV1[];
    /** Protocol-format hypotheses from AnalysisResult. */
    hypotheses: any[];
    /** Provider profile that supplied runtime credentials for this turn; null means env/default fallback. */
    agentRuntimeProviderId?: string | null;
    /** Non-secret hash of the resolved provider/runtime configuration. */
    agentRuntimeProviderSnapshotHash?: string | null;
    codeAwareMode?: CodeAwareMode;
    codebaseIds?: string[];
    codebaseSnapshot?: SessionStateSnapshot['codebaseSnapshot'];
    codeLookupSummary?: CodeLookupSummary;
    runSequence: number;
    conversationOrdinal: number;
    activeRun?: SnapshotRunContext;
    lastRun?: SnapshotRunContext;
}
//# sourceMappingURL=sessionStateSnapshot.d.ts.map