import type { ImageContent, Message, TextContent, Usage } from "@bastani/pi-ai/compat"; import type { VerbatimCompactionDetails } from "./compaction/compaction-types.js"; import type { BashExecutionMessage, CustomMessage } from "./messages.ts"; import type { ContextEditEntry, FileEntry, NewSessionOptions, SessionContext, SessionEntry, SessionHeader, SessionInfo, SessionListProgress, SessionNameState, SessionProjection, SessionTreeNode, SessionWorkflowMetadata, UsageEntry } from "./session-manager-types.ts"; import { type SessionJsonValue } from "./storage/session/errors.js"; import type { SessionStore } from "./storage/session/types.js"; /** An in-memory session tree whose mutations await the backing store. */ export declare class SessionManager { private sessionId; private sessionFile; private sessionDir; private cwd; private store; private lastSeq; private mutation; private fileEntries; private byId; private labelsById; private labelTimestampsById; private leafId; private constructor(); private runMutation; private recordHeader; private restore; private start; setSessionFile(sessionFile: string): Promise; private initialize; private storeForNewSession; newSession(options?: NewSessionOptions): Promise; markSessionInternal(workflow?: SessionWorkflowMetadata): Promise; private _buildIndex; isPersisted(): boolean; getCwd(): string; getSessionDir(): string; usesDefaultSessionDir(): boolean; getSessionId(): string; getSessionFile(): string | undefined; getSessionStore(): SessionStore; deleteSession(sessionId: string): Promise; /** @internal Finalize provisional startup storage after project trust resolves. */ rebindStore(store: SessionStore, removeProvisionalRecord: boolean): Promise; openSessionById(sessionId: string, cwdOverride?: string, sessionDirectory?: string): Promise; importFromJsonl(inputPath: string, cwdOverride?: string): Promise; private _appendEntry; /** Append a message as child of current leaf, then advance leaf. Returns entry id. */ appendMessage(message: Message | CustomMessage | BashExecutionMessage): Promise; /** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */ appendThinkingLevelChange(thinkingLevel: string): Promise; /** Record auxiliary model usage without adding it to the LLM context. */ appendUsage(kind: string, provider: string, model: string, usage: Usage, note?: string): Promise; /** Append a model change as child of current leaf, then advance leaf. Returns entry id. */ appendModelChange(provider: string, modelId: string): Promise; appendCompaction(compactedText: string, firstKeptEntryId: string | null, tokensBefore: number, details: VerbatimCompactionDetails, usage?: Usage): Promise; /** Save a JSONL backup; database-backed sessions have no file snapshot. */ writeBackupSnapshot(label?: string): Promise; /** Append a branch-local edit to an earlier model-visible entry. */ appendContextEdit(targetId: string, replacement: ContextEditEntry["replacement"]): Promise; /** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */ appendCustomEntry(customType: string, data?: T): Promise; /** Append a session info entry (e.g., display name). Returns entry id. */ appendSessionInfo(name: string): Promise; /** Append a generated resume summary anchored to the message it describes. Returns entry id. */ appendSessionSummary(summary: string, summarizedThroughId: string, usage?: Usage): Promise; /** Get the current session name from the latest session_info entry, if any. */ getSessionName(): string | undefined; /** * Get the session name state. `hasName` is true for a session that was named and * then cleared even though `name` is undefined; a never-named session reports * `hasName: false`. Read-side only: the JSONL already records the distinction. */ getSessionNameState(): SessionNameState; /** Append a custom message entry (for extensions) that participates in LLM context unless excluded. */ appendCustomMessageEntry(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details?: T, excludeFromContext?: boolean, protectedReconciliation?: { delivery: "steer" | "followUp"; }, stageAdmissionKey?: string): Promise; 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): Promise; /** Walk from entry to root, returning all entries in path order. */ getBranch(fromId?: string): SessionEntry[]; /** Return the active branch entries after applying the latest compaction boundary. */ buildContextEntries(): SessionEntry[]; /** Build provenance-preserving, compaction-aware model context from the current leaf. */ buildSessionProjection(): SessionProjection; /** Build the session context (what gets sent to the LLM). */ buildSessionContext(): SessionContext; /** Get session header. */ getHeader(): SessionHeader | null; /** Number of entries without copying the session history. */ getEntryCount(): number; /** 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): Promise; /** Reset the leaf pointer to null (before any entries). */ resetLeaf(): Promise; /** Start a new branch with a summary of the abandoned path. */ branchWithSummary(branchFromId: string | null, summary: string, details?: T, fromHook?: boolean, usage?: import("@bastani/pi-ai/compat").Usage, fromId?: string): Promise; createBranchedSession(leafId: string): Promise; forkTo(cwd: string, sessionDir?: string | SessionStore, options?: NewSessionOptions): Promise; static importFromJsonl(inputPath: string, cwd: string, sessionDir?: string | SessionStore): Promise; private static constructWithStore; static create(cwd: string, sessionDir?: string, options?: NewSessionOptions): Promise; static create(store: SessionStore, cwd: string, options?: NewSessionOptions): Promise; static open(path: string, sessionDir?: string, cwdOverride?: string): Promise; static open(store: SessionStore, sessionId: string, cwdOverride?: string): Promise; static continueRecent(cwd: string, sessionDir?: string, options?: { includeInternal?: boolean; }): Promise; static continueRecent(store: SessionStore, cwd: string, options?: { includeInternal?: boolean; }): Promise; static inMemory(cwd?: string, options?: NewSessionOptions, entries?: FileEntry[]): SessionManager; static forkFrom(sourcePath: string, targetCwd: string, sessionDir?: string, options?: NewSessionOptions): Promise; static findById(cwd: string, id: string, sessionDir?: string): Promise; static list(cwd: string, sessionDir?: string | SessionStore, onProgress?: SessionListProgress, options?: { includeInternal?: boolean; signal?: AbortSignal; } | AbortSignal): Promise; static listAll(onProgress?: SessionListProgress, signal?: AbortSignal): Promise; static listAll(sessionDir?: string | SessionStore, onProgress?: SessionListProgress, options?: { includeInternal?: boolean; signal?: AbortSignal; } | AbortSignal): Promise; } //# sourceMappingURL=session-manager-core.d.ts.map