Skip to main content

Module maintenance

Module maintenance 

Source
Expand description

Maintenance for the on-disk knowledge stores.

A store at <data_dir>/knowledge/<hash>/ is keyed to a project_root. When that root is deleted (a removed git worktree, a thrown-away temp project) the store can never be written again — its per-store eviction cap can therefore never self-heal (the memory lifecycle only runs on write) and the directory is pure accumulated bloat. This module finds and prunes those orphaned stores.

Pruning is only ever invoked from the explicit lean-ctx doctor --fix path; the background lifecycle must never delete a store, since a missing root can also mean a temporarily-unmounted drive rather than a deleted project.

Structs§

OrphanedStore
A knowledge store whose recorded project_root no longer exists on disk.
PruneReport
Outcome of a prune pass.

Functions§

find_orphaned_stores
Scan every knowledge store under the real data dir and return the orphaned ones. See find_orphaned_stores_in for the detection rules.
find_orphaned_stores_in
Detect orphaned stores under an explicit data_dir (the testable core).
prune_orphaned_stores
Remove every orphaned store under the real data dir. Best-effort.
prune_orphaned_stores_in
Prune orphaned stores under an explicit data_dir (the testable core). Removes each orphaned knowledge/<hash>/ directory plus the matching episodic-memory file (memory/episodes/<hash>.json). A failure on one store never aborts the rest.