sessionprune

package
v0.56.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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.

View Source
var ErrNotFound = errors.New("no such session")

ErrNotFound is returned when no session matches a reference.

View Source
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

func IsLive(root, id string) bool

IsLive reports whether a running process has session id open. A mark left by a process that has exited (a crash) does not count.

func MarkLive

func MarkLive(root, id string) (release func())

MarkLive records that this process has session id open, and returns the function that clears the mark. Best-effort: without a mark the session is simply not protected from deletion by another process.

func Resolve

func Resolve(sessions []Info, ref string) (string, error)

Resolve maps a reference to exactly one session id: an exact id, or a unique prefix ("sess_" optional). An ambiguous prefix is an error naming the candidates.

Types

type Info

type Info struct {
	ID         string
	LastActive time.Time
	Live       bool
}

Info is one recorded session.

func List

func List(ctx context.Context, root string, st store.Store) ([]Info, error)

List returns every recorded session of the project, newest first: those with files on disk and those known only from the event log. st may be nil.

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

func Delete(ctx context.Context, root string, st store.Store, ids ...string) (Result, error)

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

func MaybePrune(ctx context.Context, root string, st store.Store, o Options) (Result, bool, error)

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.

func Prune

func Prune(ctx context.Context, root string, st store.Store, o Options) (Result, error)

Prune deletes every session whose last activity is older than the retention window, except the kept and live ones, and clears diagnostics, stray wire traces and observed-tool logs older than the same window.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL