import type { ImageContent, Message, TextContent } from "@earendil-works/pi-ai/compat";
import type { BashExecutionMessage, CustomMessage } from "./messages.ts";
import type { ContextCompactionStats, ContextDeletionTarget, NewSessionOptions, SessionContext, SessionEntry, SessionHeader, SessionInfo, SessionListProgress, SessionTreeNode, SessionWorkflowMetadata } from "./session-manager-types.ts";
/** Manages conversation sessions as append-only trees stored in JSONL files.  Each session entry has an id and parentId forming a tree structure. The "leaf" pointer tracks the current position. Appending creates a child of the current leaf. Branching moves the leaf to an earlier entry, allowing new branches without modifying history.  Use buildSessionContext() to get the resolved message list for the LLM, which applies context-deletion filtering and follows the path from root to current leaf. */
export declare class SessionManager {
    private sessionId;
    private sessionFile;
    private sessionDir;
    private cwd;
    private persist;
    private flushed;
    private fileEntries;
    private byId;
    private labelsById;
    private labelTimestampsById;
    private leafId;
    private constructor();
    /** Switch to a different session file (used for resume and branching) */
    setSessionFile(sessionFile: string): void;
    newSession(options?: NewSessionOptions): string | undefined;
    /** Mark the session header as internal (e.g. workflow stage). Preserves an existing full marker on reattach. */
    markSessionInternal(workflow?: SessionWorkflowMetadata): void;
    private _buildIndex;
    private _rewriteFile;
    isPersisted(): boolean;
    getCwd(): string;
    getSessionDir(): string;
    usesDefaultSessionDir(): boolean;
    getSessionId(): string;
    getSessionFile(): string | undefined;
    _persist(entry: SessionEntry): void;
    private _appendEntry;
    /** Append a message as child of current leaf, then advance leaf. Returns entry id. */
    appendMessage(message: Message | CustomMessage | BashExecutionMessage): string;
    /** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */
    appendThinkingLevelChange(thinkingLevel: string): string;
    /** Append a context window change as child of current leaf, then advance leaf. Returns entry id. */
    appendContextWindowChange(contextWindow: number): string;
    /** Append a model change as child of current leaf, then advance leaf. Returns entry id. */
    appendModelChange(provider: string, modelId: string): string;
    /** Append logical deletion metadata for deletion-only context compaction. */
    appendContextCompaction(deletedTargets: ContextDeletionTarget[], protectedEntryIds: string[], stats: ContextCompactionStats, backupPath?: string): string;
    /** Write a recoverable snapshot of the current session entries without mutating the active JSONL. */
    writeBackupSnapshot(label?: string): string | undefined;
    /** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */
    appendCustomEntry(customType: string, data?: unknown): string;
    /** Append a session info entry (e.g., display name). Returns entry id. */
    appendSessionInfo(name: string): string;
    /** Get the current session name from the latest session_info entry, if any. */
    getSessionName(): string | undefined;
    /** Append a custom message entry (for extensions) that participates in LLM context unless excluded. */
    appendCustomMessageEntry<T = unknown>(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details?: T, excludeFromContext?: boolean): string;
    getLeafId(): string | null;
    getLeafEntry(): SessionEntry | undefined;
    getEntry(id: string): SessionEntry | undefined;
    /** Get all direct children of an entry. */
    getChildren(parentId: string): SessionEntry[];
    /** Get the label for an entry, if any. */
    getLabel(id: string): string | undefined;
    /** Set or clear a label on an entry. */
    appendLabelChange(targetId: string, label: string | undefined): string;
    /** Walk from entry to root, returning all entries in path order. */
    getBranch(fromId?: string): SessionEntry[];
    /** Build the session context (what gets sent to the LLM). */
    buildSessionContext(): SessionContext;
    /** Get session header. */
    getHeader(): SessionHeader | null;
    /** Get all session entries (excludes header). Returns a shallow copy. */
    getEntries(): SessionEntry[];
    /** Get the session as a tree structure. Returns a shallow defensive copy of all entries. */
    getTree(): SessionTreeNode[];
    /** Start a new branch from an earlier entry. */
    branch(branchFromId: string): void;
    /** Reset the leaf pointer to null (before any entries). */
    resetLeaf(): void;
    /** Start a new branch with a summary of the abandoned path. */
    branchWithSummary(branchFromId: string | null, summary: string, details?: unknown, fromHook?: boolean): string;
    /** Create a new session file containing only the path from root to the specified leaf. */
    createBranchedSession(leafId: string): string | undefined;
    /** Create a new session. */
    static create(cwd: string, sessionDir?: string, options?: NewSessionOptions): SessionManager;
    /** Open a specific session file. */
    static open(path: string, sessionDir?: string, cwdOverride?: string): SessionManager;
    /** Continue the most recent session (skips internal workflow sessions unless `includeInternal: true`). */
    static continueRecent(cwd: string, sessionDir?: string, options?: {
        includeInternal?: boolean;
    }): SessionManager;
    /** Create an in-memory session (no file persistence) */
    static inMemory(cwd?: string, options?: NewSessionOptions): SessionManager;
    /** Fork a session from another project directory into the current project. */
    static forkFrom(sourcePath: string, targetCwd: string, sessionDir?: string, options?: NewSessionOptions): SessionManager;
    /** List sessions for a directory. Internal (workflow) sessions are excluded unless `includeInternal: true`. */
    static list(cwd: string, sessionDir?: string, onProgress?: SessionListProgress, options?: {
        includeInternal?: boolean;
    }): Promise<SessionInfo[]>;
    /** List sessions across all directories. Internal (workflow) sessions are excluded unless `includeInternal: true`. */
    static listAll(onProgress?: SessionListProgress): Promise<SessionInfo[]>;
    static listAll(sessionDir?: string, onProgress?: SessionListProgress, options?: {
        includeInternal?: boolean;
    }): Promise<SessionInfo[]>;
}
//# sourceMappingURL=session-manager-core.d.ts.map