import type { BashExecutionMessage, CompactionEntry, CustomMessage, SessionContext, SessionTreeEntry as SessionEntry } from "@kolisachint/hoocode-agent-core"; import type { ImageContent, Message, TextContent } from "@kolisachint/hoocode-ai"; export type { BranchSummaryEntry, CompactionEntry, CustomEntry, CustomMessageEntry, LabelEntry, MessageEntry as SessionMessageEntry, ModelChangeEntry, SessionContext, SessionInfoEntry, SessionTreeEntry as SessionEntry, SessionTreeEntryBase as SessionEntryBase, ThinkingLevelChangeEntry, } from "@kolisachint/hoocode-agent-core"; export declare const CURRENT_SESSION_VERSION = 3; export interface SessionHeader { type: "session"; version?: number; id: string; timestamp: string; cwd: string; parentSession?: string; /** * Git branch the session started on, absent outside a repo or on a detached * HEAD. Recorded because it cannot be recovered later — the working tree has * moved on by the time anyone reads the list — and because unlike a derived * title it is a fact, which is what makes it safe to write down. */ branch?: string; } export interface NewSessionOptions { id?: string; parentSession?: string; } /** Raw file entry (includes header) */ export type FileEntry = SessionHeader | SessionEntry; /** Tree node for getTree() - defensive copy of session structure */ export interface SessionTreeNode { entry: SessionEntry; children: SessionTreeNode[]; /** Resolved label for this entry, if any */ label?: string; /** Timestamp of the latest label change for this entry, if any */ labelTimestamp?: string; } export interface SessionInfo { path: string; id: string; /** Working directory where the session was started. Empty string for old sessions. */ cwd: string; /** User-defined display name from session_info entries. */ name?: string; /** User-chosen colour slot (1-6) from session_info entries, if one was set. */ color?: number; /** Git branch the session started on. Absent for sessions recorded before this was kept. */ branch?: string; /** Path to the parent session (if this session was forked). */ parentSessionPath?: string; created: Date; modified: Date; messageCount: number; firstMessage: string; allMessagesText: string; } export type ReadonlySessionManager = Pick; /** Exported for testing */ export declare function migrateSessionEntries(entries: FileEntry[]): void; /** Exported for compaction.test.ts */ export declare function parseSessionEntries(content: string): FileEntry[]; export declare function getLatestCompactionEntry(entries: SessionEntry[]): CompactionEntry | null; /** * Build the session context from entries using tree traversal. * If leafId is provided, walks from that entry to root. * Handles compaction and branch summaries along the path. */ export declare function buildSessionContext(entries: SessionEntry[], leafId?: string | null, byId?: Map): SessionContext; /** * Compute the default session directory for a cwd. * Encodes cwd into a safe directory name under ~/.hoocode/agent/sessions/. */ export declare function getDefaultSessionDir(cwd: string, agentDir?: string): string; /** * The same path as {@link getDefaultSessionDir} without creating it. * * Readers that only want to *look* for a directory should use this. Creating it * as a side effect of looking makes a missing directory indistinguishable from * an empty one, which is exactly the distinction `/learn` reports on. */ export declare function getSessionDirPath(cwd: string, agentDir?: string): string; /** Exported for testing */ export declare function loadEntriesFromFile(filePath: string): FileEntry[]; /** Exported for testing */ export declare function findMostRecentSession(sessionDir: string): string | null; export type SessionListProgress = (loaded: number, total: number) => void; /** * 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 * handles compaction summaries 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; private _buildIndex; private _rewriteFile; isPersisted(): boolean; getCwd(): string; getSessionDir(): string; 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. * Does not allow writing CompactionSummaryMessage and BranchSummaryMessage directly. * Reason: we want these to be top-level entries in the session, not message session entries, * so it is easier to find them. * These need to be appended via appendCompaction() and appendBranchSummary() methods. */ 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 model change as child of current leaf, then advance leaf. Returns entry id. */ appendModelChange(provider: string, modelId: string): string; /** Append a compaction summary as child of current leaf, then advance leaf. Returns entry id. */ appendCompaction(summary: string, firstKeptEntryId: string, tokensBefore: number, details?: T, fromHook?: boolean, tokensAfter?: number): string; /** 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 (display name and/or colour slot). Fields left * undefined are simply not written, which is what keeps the two independent: * setting a colour must not clear a name the user chose earlier. Returns entry id. */ appendSessionInfo(info: { name?: string; color?: number; }): string; /** * The user-chosen session name, if there is one. Undefined for a session * nobody has named — callers that want something to *show* want * getDisplayName(), which falls back to the auto-assigned slug. */ getSessionName(): string | undefined; /** The git branch this session started on, if it was recorded. */ getSessionBranch(): string | undefined; /** The auto-assigned name this session wears until someone runs `/name`. */ getSessionSlug(): string; /** What to show for this session: the chosen name, else the auto-assigned slug. */ getDisplayName(): string; /** * The session's colour slot (1-6): the user's choice if `/color` set one, * otherwise the slot its id hashes into. Resolved independently of the name, * so renaming a session keeps the colour you have already learned. */ getSessionColorSlot(): number; /** * Append a custom message entry (for extensions) that participates in LLM context. * @param customType Extension identifier for filtering on reload * @param content Message content (string or TextContent/ImageContent array) * @param display Whether to show in TUI (true = styled display, false = hidden) * @param details Optional extension-specific metadata (not sent to LLM) * @returns Entry id */ appendCustomMessageEntry(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details?: T): 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. * Labels are user-defined markers for bookmarking/navigation. * Pass undefined or empty string to clear the label. */ appendLabelChange(targetId: string, label: string | undefined): string; /** * Walk from entry to root, returning all entries in path order. * Includes all entry types (messages, compaction, model changes, etc.). * Use buildSessionContext() to get the resolved messages for the LLM. */ getBranch(fromId?: string): SessionEntry[]; /** * Build the session context (what gets sent to the LLM). * Uses tree traversal from current leaf. */ buildSessionContext(): SessionContext; /** * Get session header. */ getHeader(): SessionHeader | null; /** * Get all session entries (excludes header). Returns a shallow copy. * The session is append-only: use appendXXX() to add entries, branch() to * change the leaf pointer. Entries cannot be modified or deleted. */ getEntries(): SessionEntry[]; /** * Get the session as a tree structure. Returns a shallow defensive copy of all entries. * A well-formed session has exactly one root (first entry with parentId === null). * Orphaned entries (broken parent chain) are also returned as roots. */ getTree(): SessionTreeNode[]; /** * Start a new branch from an earlier entry. * Moves the leaf pointer to the specified entry. The next appendXXX() call * will create a child of that entry, forming a new branch. Existing entries * are not modified or deleted. */ branch(branchFromId: string): void; /** * Reset the leaf pointer to null (before any entries). * The next appendXXX() call will create a new root entry (parentId = null). * Use this when navigating to re-edit the first user message. */ resetLeaf(): void; /** * Start a new branch with a summary of the abandoned path. * Same as branch(), but also appends a branch_summary entry that captures * context from the abandoned conversation 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. * Useful for extracting a single conversation path from a branched session. * Returns the new session file path, or undefined if not persisting. */ createBranchedSession(leafId: string): string | undefined; /** * Create a new session. * @param cwd Working directory (stored in session header) * @param sessionDir Optional session directory. If omitted, uses default (~/.hoocode/agent/sessions//). */ static create(cwd: string, sessionDir?: string): SessionManager; /** * Open a specific session file. * @param path Path to session file * @param sessionDir Optional session directory for /new or /branch. If omitted, derives from file's parent. * @param cwdOverride Optional cwd override instead of the session header cwd. */ static open(path: string, sessionDir?: string, cwdOverride?: string): SessionManager; /** * Continue the most recent session, or create new if none. * @param cwd Working directory * @param sessionDir Optional session directory. If omitted, uses default (~/.hoocode/agent/sessions//). */ static continueRecent(cwd: string, sessionDir?: string): SessionManager; /** Create an in-memory session (no file persistence) */ static inMemory(cwd?: string): SessionManager; /** * Fork a session from another project directory into the current project. * Creates a new session in the target cwd with the full history from the source session. * @param sourcePath Path to the source session file * @param targetCwd Target working directory (where the new session will be stored) * @param sessionDir Optional session directory. If omitted, uses default for targetCwd. */ static forkFrom(sourcePath: string, targetCwd: string, sessionDir?: string): SessionManager; /** * List all sessions for a directory. * @param cwd Working directory (used to compute default session directory) * @param sessionDir Optional session directory. If omitted, uses default (~/.hoocode/agent/sessions//). * @param onProgress Optional callback for progress updates (loaded, total) */ static list(cwd: string, sessionDir?: string, onProgress?: SessionListProgress): Promise; /** * List all sessions across all project directories. * @param onProgress Optional callback for progress updates (loaded, total) */ static listAll(onProgress?: SessionListProgress): Promise; } //# sourceMappingURL=session-manager.d.ts.map