/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ import { type IContent } from '../services/history/IContent.js'; import { Storage } from '../config/storage.js'; import { type ToolResultDisplay, type ToolCallConfirmationDetails } from '../tools/tools.js'; /** * Persisted tool call display information. * Matches CLI's IndividualToolCallDisplay interface for type compatibility. */ export interface PersistedToolCall { /** Unique identifier for the tool call */ callId: string; /** Tool name */ name: string; /** Human-readable description of what the tool is doing */ description: string; /** Tool execution status (string to accept CLI's ToolCallStatus enum) */ status: string; /** Result display for completed tools */ resultDisplay: ToolResultDisplay | undefined; /** Confirmation details for tools requiring user approval */ confirmationDetails: ToolCallConfirmationDetails | undefined; /** Whether to render output as markdown */ renderOutputAsMarkdown?: boolean; /** Whether this tool is currently focused in UI */ isFocused?: boolean; } /** * Minimal interface for persisted UI history items. * CLI's HistoryItem should satisfy this interface. * Uses permissive types since CLI has multiple history types with different shapes. */ export interface PersistedUIHistoryItem { /** Unique identifier for the history item */ id: number; /** Type discriminator for the history item */ type: string; /** Optional text content (for user/gemini/info/warning/error messages) */ text?: string; /** Optional model identifier (for gemini responses) */ model?: string; /** Optional agent ID (for subagent contexts) */ agentId?: string; /** Optional tools array - shape varies by type (tool_group vs tools_list) */ tools?: unknown[]; } /** * Persisted session format for --continue functionality */ export interface PersistedSession { /** Schema version for future migrations */ version: 1; /** Unique session identifier */ sessionId: string; /** Hash of project root for validation */ projectHash: string; /** When session was created */ createdAt: string; /** Last update timestamp */ updatedAt: string; /** Full conversation history (core format) */ history: IContent[]; /** UI history items for display restoration (preserves exactly what user sees) */ uiHistory?: PersistedUIHistoryItem[]; /** Optional metadata */ metadata?: { provider?: string; model?: string; tokenCount?: number; }; } /** * Service for persisting and restoring conversation sessions. * Enables the --continue flag to resume previous sessions. */ export declare class SessionPersistenceService { private readonly storage; private readonly sessionId; private readonly chatsDir; private readonly sessionFilePath; constructor(storage: Storage, sessionId: string); /** * Get the directory containing persisted sessions */ getChatsDir(): string; /** * Get the current session's file path */ getSessionFilePath(): string; /** * Save conversation history to disk */ save(history: IContent[], metadata?: PersistedSession['metadata'], uiHistory?: PersistedUIHistoryItem[]): Promise; /** * Load the most recent session for this project */ loadMostRecent(): Promise; /** * Get formatted timestamp for display */ static formatSessionTime(session: PersistedSession): string; /** * Get project hash for validation */ private getProjectHash; /** * Get or track session creation time */ private createdAt; private getCreatedAt; /** * Back up corrupted session file */ private backupCorruptedSession; }