Skip to main content

Module session

Module session 

Source
Expand description

Session management — ID resolution, locking, snapshots, cleanup.

Structs§

SessionContext
Session context — holds the session ID, directory, base directory, and file lock.
SessionInfo
A session entry returned by list_sessions.
SnapshotInfo
Info about a saved snapshot.

Functions§

acquire_session_lock
Acquire an exclusive file lock on the session directory.
cleanup_expired_sessions
Clean up expired sessions.
clear_messages_jsonl
Delete the messages.jsonl file if it exists.
create_snapshot
Create a named snapshot of a session.
delete_snapshot
Delete a saved snapshot.
generate_session_id
Generate a new session_id (format: YYYYMMDD_first8ofUuid)
get_or_create_session_dir
Get or create a session directory under base_dir/sessions/<session_id>.
list_sessions
List resumable sessions under base_dir/sessions/.
list_snapshots
List all saved snapshots under base_dir/snapshots/.
load_session_messages
Load a previously-persisted messages.jsonl and sanitize for resume.
persist_window_messages
Persist the current window’s full ChatMessage list as a JSONL snapshot.
read_session_title
Read the LLM-generated title from session_meta.json.
resolve_session
Resolve and create a session context — session ID, directory, and file lock.
resolve_session_id
Resolve session ID (priority: CLI arg → PHI_SESSION_ID env var → auto-generate).
restore_snapshot
Restore a session from a snapshot.
validate_session_id
Validate session ID format.
validate_snapshot_name
Validate snapshot name format.
write_session_title
Write a session title into session_meta.json.