yggdrasil.loki.session¶
session ¶
Loki session workspaces — per-user, named, resumable, self-purging.
Sessions live under the current user's tree::
~/.loki/users/<user>/session/<id>/
meta.json # id, name, user, first_prompt, created_at, last_used_at
workspace/ # the agent's default root — files it writes land here
memory/ # synthesized context + transcript (loki.memory)
cache/ # session-scoped caches
The user comes from :meth:UserInfo.current, so each user only sees and
resumes their own sessions. A session is named from its first prompt and
tracks last usage: every turn (and a resume) touches last_used_at,
which resets its purge clock — :meth:start drops sessions only when they go
stale (older than :data:MAX_AGE_DAYS since last use) or fall outside the
:data:KEEP most-recent, so active work is never collected.
LokiSession
dataclass
¶
LokiSession(
id: str,
dir: Path,
user: str,
name: str = "",
first_prompt: str = "",
created_at: float = time.time(),
last_used_at: float = time.time(),
)
One isolated, named, per-user session directory tree.
start
classmethod
¶
Create a fresh session for the user (purging stale ones first).
list
classmethod
¶
The user's sessions, most-recently-used first.
resume
classmethod
¶
Reopen an existing session by id and reset its purge clock.
purge
classmethod
¶
purge(
*,
user: Optional[str] = None,
keep: int = KEEP,
max_age_days: float = MAX_AGE_DAYS,
exclude: "Optional[Path]" = None
) -> "list[str]"
Delete the user's stale session trees; return the ids removed.
Stale = untouched for > max_age_days (by last_used_at) OR outside
the keep most-recently-used. exclude (the live session) is spared.
name_from_prompt ¶
Name the session from its first user prompt (slug); persist + return.