Skip to main content

Module session

Module session 

Source

Structs§

ActiveToolsChangeEntry
BranchSummaryEntry
CompactionEntry
CustomEntry
CustomMessageEntry
LabelEntry
LeafEntry
MessageEntry
Base fields shared by all entries.
ModelChangeEntry
NewSessionOptions
Options for creating a new session.
Session
High-level session wrapper, matching pi’s Session class.
SessionContext
Resolved conversation context sent to the LLM. Pi-compatible: includes resolved thinking level, model, and active tool names.
SessionHeader
The first entry in every session file.
SessionInfo
Lightweight metadata about a session, used for listing and selection.
SessionInfoEntry
SessionManager
Manages conversation sessions as append-only trees in JSONL files.
SessionTreeNode
A node in the session tree, with resolved children and labels.
ThinkingLevelChangeEntry

Enums§

SessionEntry
A session entry - one JSON line in the session file.

Constants§

CURRENT_SESSION_VERSION

Functions§

append_entry_to_file
Append a single entry to the session file (one JSON line).
build_session_context
Build the session context from a resolved branch path.
delete_session
Delete a session file.
encode_cwd_for_dir
Encode a working directory path into a safe directory name. Mirrors pi’s encoding: strip leading /, replace / \ : with -, wrap in –…–
find_most_recent_session
Find the most recent session file by mtime.
fork_session
Fork a session: create a new session file containing a copy of entries from the source session up to (and including) the entry with the given entry_id, or all entries if entry_id is None. If entry_id is provided and position is “at”, the copy goes up to and including that entry. If position is “before” (default), the copy goes up to but not including the entry (which must be a user message). Pi-compatible.
generate_entry_id
Generate a unique ID for session entries (8 hex chars, collision-checked).
get_default_session_dir
Get the default session directory for a cwd.
list_sessions
List all session metadata in a session directory, newest first. Pi-compatible: returns metadata for all valid .jsonl sessions.
load_entries_from_file
Load all entries from a session JSONL file (backward-compatible wrapper).
load_session_from_file
Load header + entries from a session JSONL file using buffered reading. Pi-compatible: uses a 1MB buffer for efficient reading of large files. Returns (header, entries). Returns (None, empty) if file is missing/corrupted.
load_session_info
Load session info from a session file.
parse_session_entry_line
Parse a single line as a SessionEntry. Returns None for empty/malformed lines.
parse_session_header_line
Parse a single line as a SessionHeader.
read_session_header
Read the session header from a JSONL file (first line only).
write_entries_to_file
Write entries to a session file (used for initial write / rewrite). Does NOT write the session header - caller must include it.