/** * Session persistence for Franklin. * Saves conversation history as JSONL for resume capability. */ import type { Dialogue } from '../agent/types.js'; export declare function setSessionPersistenceDisabled(disabled: boolean): void; export declare function isSessionPersistenceDisabled(): boolean; export interface SessionMeta { id: string; model: string; workDir: string; createdAt: number; updatedAt: number; turnCount: number; messageCount: number; /** * Chain (`base` | `solana`) the session was started on. Captured at * session creation so `franklin --resume` can restore the same chain * even if the user later changed their default via * `franklin solana` / `franklin base`. Verified 2026-05-04: a debug * invocation flipped `~/.blockrun/.chain` to `solana`; the next * `--resume` silently moved the user from their funded Base wallet * to an underfunded Solana wallet. Sessions are wallet-bound by * conversation context — switching chains mid-resume is a bug. * Optional for back-compat with pre-3.15.35 sessions. */ chain?: 'base' | 'solana'; inputTokens?: number; outputTokens?: number; costUsd?: number; savedVsOpusUsd?: number; /** * Origin channel tag. Unset for regular CLI sessions; set to a string like * `telegram:` when the session was started by a non-CLI driver. * Lets findLatestSessionByChannel pick up the right session on bot restart. */ channel?: string; /** * Per-tool invocation counts for this session, aggregated across every * turn. Populated by the agent loop at each tool-call batch. Used by the * opt-in telemetry subsystem to aggregate vertical-usage signals — do NOT * add any tool inputs or outputs here, just the count per tool name. */ toolCallCounts?: Record; /** * Sessions imported from another agent (`franklin migrate`). Imports often * exceed MAX_SESSIONS by an order of magnitude (a Claude Code user can * easily have 200+ historical sessions); without this flag, the very * next `franklin` launch would prune all but the 20 most recent and * silently destroy the user's history. pruneOldSessions() skips any * meta with imported=true. */ imported?: true; /** * Active goal bound to this session (see src/goal/). Sticky like `chain` * so a `--resume` re-hydrates the goal loop; cleared explicitly when the * goal completes or is abandoned (updateSessionMeta with goalId: ''). */ goalId?: string; } /** Get the absolute path to a session's JSONL file (for external readers like search). */ export declare function getSessionFilePath(id: string): string; /** * Create a new session ID based on timestamp. */ export declare function createSessionId(): string; /** * Save a message to the session transcript (append-only JSONL). */ export declare function appendToSession(sessionId: string, message: Dialogue): void; /** * Update session metadata. */ export declare function updateSessionMeta(sessionId: string, meta: Partial): void; /** * Load session metadata. */ export declare function loadSessionMeta(sessionId: string): SessionMeta | null; /** * Load full session history from JSONL. */ export declare function loadSessionHistory(sessionId: string): Dialogue[]; /** * List all saved sessions, newest first. */ export declare function listSessions(): SessionMeta[]; /** * Find the latest saved session tagged with a given channel (e.g. * `telegram:12345`). Used by non-CLI drivers to resume across process * restarts. Returns undefined when no matching session exists. */ export declare function findLatestSessionByChannel(channel: string): SessionMeta | undefined; /** * Prune old sessions beyond MAX_SESSIONS. */ /** * Prune old sessions beyond MAX_SESSIONS. * Accepts optional activeSessionId to protect from deletion. */ export declare function pruneOldSessions(activeSessionId?: string): void;