latent.chat.session¶
JSONL session persistence for the agent REPL.
Sessions are stored at .latent/sessions/<agent_name>/<session_id>.jsonl.
Each line is a JSON object with: ts, type, content, metadata.
Classes¶
SessionInfo¶
SessionInfo(session_id: str, agent_name: str, created_at: str, message_count: int, last_user_message: str, path: Path)
Metadata for a saved session.
Functions¶
append_event¶
Append a single event line to a JSONL session file.
get_sessions_dir¶
Return the sessions directory for an agent.
list_sessions¶
List all sessions for an agent, sorted by creation time (newest first).
load_session_messages¶
Reconstruct message list from JSONL, respecting clear events.
Clear events cause all pre-clear messages to be dropped. Tool call/result lines are reconstructed as proper role messages.
make_session_filename¶
make_session_filename(agent_name: str, created_at: datetime, last_message: str, session_uuid: str) -> str
Build a session filename stem (no .jsonl extension).
new_session_id¶
Generate a new session ID.
slugify¶
Convert text to a filesystem-safe slug, max 30 chars.
Falls back to fallback if the result is empty (e.g. all non-ASCII).