Documentation
¶
Overview ¶
Package sessionprune deletes recorded sessions: one on request (`memcode session delete`) and, automatically, every session older than the retention window. Both go through Delete, so "a deleted session" means one thing.
A session's local footprint is:
sessions/<id>/ transcript (messages.json), episodic log (transcript.md,
events.jsonl), wire trace (wire.jsonl), reports,
continuations, the live marker
checkpoints/<id>/ rewind points
state.db events rows whose payload carries session_id = <id>
Recall has no index of its own: it reads the events table at query time, so removing the rows removes the session from recall.
What a session taught memcode is NOT session data and stays: memory.md, promoted preferences and lessons (prefs/, lessons/), knowledge, and the event kinds that feed them (MemoryKinds). Project configuration (config.json, permissions, hooks.json, mcp.json) is never touched.
Index ¶
Constants ¶
const DefaultRetentionDays = 30
DefaultRetentionDays is how long a session is kept after its last activity when no setting says otherwise. 0 means keep forever.
Variables ¶
var ErrLive = errors.New("session is open in a running memcode process")
ErrLive is returned for a session that a running memcode process has open.
var ErrNotFound = errors.New("no such session")
ErrNotFound is returned when no session matches a reference.
var MemoryKinds = []string{
"preference_signal", "lesson_signal", "adherence",
"decision", "assertion", "user_note",
}
MemoryKinds are the event kinds that feed persistent memory. They carry the session id of the session that produced them but outlive it: deleting them would quietly un-learn a preference or a lesson.
Functions ¶
func IsLive ¶
IsLive reports whether a running process has session id open. A mark left by a process that has exited (a crash) does not count.
Types ¶
type Options ¶
type Options struct {
RetentionDays int // sessions idle longer than this are deleted; <= 0 keeps everything
Keep []string // session ids never pruned (the current or resumed one)
Now time.Time // zero = time.Now()
}
Options configure a prune.
type Result ¶
type Result struct {
Sessions []string // session ids deleted
Paths []string // files and directories removed
Events int64 // event rows removed
}
Result summarizes what a Delete or Prune removed.
func Delete ¶
Delete removes every local artifact of the given sessions. A session open in a running process is refused with ErrLive (nothing of it is removed); one that is already gone is not an error, so deleting is idempotent.
func MaybePrune ¶
MaybePrune runs Prune at most once a day per project: a stamp file in the project's state directory remembers the last run. It reports whether a prune ran. Cheap when it does not: one stat.