Problem
As repositories evolve, files are deleted, renamed, or refactored. Over several coding sessions:
- Components might point to code anchors (
code_anchor) that no longer exist on disk.
- Claims, flows, or sources can become completely orphaned (disconnected from any active component or flow).
- Edges might point to deleted/non-existent subject IDs.
Currently, Greplica has no way to audit the health of the local knowledge graph or prune these stale, dangling, or orphaned entities. Stale data remains in the database and is retrieved during search, which wastes context window tokens and degrades the coding agent's performance.
Proposed Solution
Introduce a new CLI command - greplica graph gc - to safely clean up the repository's local memory database. It should support a --dry-run flag to preview changes before applying them.
Expected Behavior
- Stale Code Anchors: Check if
code_anchor files exist on disk. If a file is missing, flag/prune the component.
- Orphaned Claims/Flows: Find claims or flows with no incoming or outgoing edges, or claims whose related components/flows have been deleted.
- Dangling Edges: Identify and prune edges where either the
from_id or to_id refers to an entity that no longer exists in the graph.
- Cascading Deletes: When pruning an entity, ensure its corresponding database memberships (in the
graph_memberships table) and associated embeddings are cleanly deleted to avoid database constraints violations.
- CLI Command routing:
greplica graph gc --dry-run: Runs the audit scan and prints the report of stale/orphaned items without modifying the database.
greplica graph gc: Permanently prunes the database and outputs a summary of deleted components, claims, flows, and edges.
Problem
As repositories evolve, files are deleted, renamed, or refactored. Over several coding sessions:
code_anchor) that no longer exist on disk.Currently, Greplica has no way to audit the health of the local knowledge graph or prune these stale, dangling, or orphaned entities. Stale data remains in the database and is retrieved during search, which wastes context window tokens and degrades the coding agent's performance.
Proposed Solution
Introduce a new CLI command -
greplica graph gc- to safely clean up the repository's local memory database. It should support a--dry-runflag to preview changes before applying them.Expected Behavior
code_anchorfiles exist on disk. If a file is missing, flag/prune the component.from_idorto_idrefers to an entity that no longer exists in the graph.graph_membershipstable) and associated embeddings are cleanly deleted to avoid database constraints violations.greplica graph gc --dry-run: Runs the audit scan and prints the report of stale/orphaned items without modifying the database.greplica graph gc: Permanently prunes the database and outputs a summary of deleted components, claims, flows, and edges.