{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package sessionprune\n\nPackage 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.\n\nA session's local footprint is:\n\n\tsessions/\u003cid\u003e/      transcript (messages.json), episodic log (transcript.md,\n\t                    events.jsonl), wire trace (wire.jsonl), reports,\n\t                    continuations, the live marker\n\tcheckpoints/\u003cid\u003e/   rewind points\n\tstate.db events     rows whose payload carries session_id = \u003cid\u003e\n\nRecall has no index of its own: it reads the events table at query time, so removing the rows removes the session from recall.\n\nWhat 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.\n\n## Constants\n\n```go\nconst DefaultRetentionDays = 30\n```\nDefaultRetentionDays is how long a session is kept after its last activity when no setting says otherwise. 0 means keep forever.\n\n## Variables\n\n```go\nvar ErrLive = errors.New(\"session is open in a running memcode process\")\n```\nErrLive is returned for a session that a running memcode process has open.\n\n```go\nvar ErrNotFound = errors.New(\"no such session\")\n```\nErrNotFound is returned when no session matches a reference.\n\n```go\nvar MemoryKinds = []string{\n\t\"preference_signal\", \"lesson_signal\", \"adherence\",\n\t\"decision\", \"assertion\", \"user_note\",\n}\n```\nMemoryKinds 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.\n\n## Functions\n\n```go\nfunc IsLive(root, id string) bool\n```\nIsLive reports whether a running process has session id open. A mark left by a process that has exited (a crash) does not count.\n\n```go\nfunc MarkLive(root, id string) (release func())\n```\nMarkLive 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.\n\n```go\nfunc Resolve(sessions []Info, ref string) (string, error)\n```\nResolve 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.\n\n## Types\n\n```go\ntype Info struct {\n\tID         string\n\tLastActive time.Time\n\tLive       bool\n}\n```\nInfo is one recorded session.\n\n```go\nfunc List(ctx context.Context, root string, st store.Store) ([]Info, error)\n```\nList 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.\n\n```go\ntype Options struct {\n\tRetentionDays int       // sessions idle longer than this are deleted; \u003c= 0 keeps everything\n\tKeep          []string  // session ids never pruned (the current or resumed one)\n\tNow           time.Time // zero = time.Now()\n}\n```\nOptions configure a prune.\n\n```go\ntype Result struct {\n\tSessions []string // session ids deleted\n\tPaths    []string // files and directories removed\n\tEvents   int64    // event rows removed\n}\n```\nResult summarizes what a Delete or Prune removed.\n\n```go\nfunc Delete(ctx context.Context, root string, st store.Store, ids ...string) (Result, error)\n```\nDelete 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.\n\n```go\nfunc MaybePrune(ctx context.Context, root string, st store.Store, o Options) (Result, bool, error)\n```\nMaybePrune 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.\n\n```go\nfunc Prune(ctx context.Context, root string, st store.Store, o Options) (Result, error)\n```\nPrune 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.\n\n","path":"github.com/memcode-ai/memcode/internal/sessionprune","name":"sessionprune","synopsis":"Package sessionprune deletes recorded sessions: one on request (`memcode session delete`) and, automatically, every session older than the retention window.","isRedistributable":true}
