Skip to main content

Module session

Module session 

Source
Expand description

Tier-1 ephemeral session: a content-addressed snapshot DAG with a HEAD pointer and a redo stack, persisted under session_dir(doc_id).

Records are STATE snapshots (full content), never operation logs — so an external change (git checkout, hand-edit) is captured as a normal snapshot and is therefore undoable. Undo/redo (next unit) are pure pointer moves over this DAG; this unit provides the state file plus state-recording and current-content readback.

Structs§

SessionState
The mutable pointer state for a session: HEAD and the redo stack. Persisted to state.json inside session_dir(doc_id).

Enums§

RecordOutcome
The outcome of a record_state call.

Functions§

clear_session
Discard all Tier-1 session state for doc_id (called on workspace close). Idempotent: a no-op if no session exists. Durable Tier-2 history is unaffected.
current_content
The full content of the current HEAD snapshot, or None if the session is empty (no states recorded yet).
record_state
Record the current content as a new state snapshot for doc_id.
redo
Redo: move HEAD forward to the most-recently-undone snapshot. Returns the content now at HEAD, or None if the redo stack is empty.
undo
Undo: move HEAD to its parent snapshot. Returns the content now at HEAD, or None if the session is empty or already at the root (nothing to undo). The record we left is pushed onto the redo stack so redo can return to it.