pub struct FrecencyStore { /* private fields */ }Expand description
SQLite-backed per-workspace frecency store.
Persists to .symforge/frecency.db (see paths::SYMFORGE_FRECENCY_DB_PATH)
or an in-memory DB for tests. All access routes through an internal Mutex
so the store is Sync and safe to share across concurrent bump callers.
Implementations§
Source§impl FrecencyStore
impl FrecencyStore
Sourcepub fn open(db_path: &Path) -> Result<Self>
pub fn open(db_path: &Path) -> Result<Self>
Open a file-backed store, creating the DB and parent directory if missing.
Sets busy_timeout = 5s as a circuit-breaker for cross-process contention
(e.g. a parallel symforge subagent on the same workspace). Same-process
contention is handled at a higher layer by the cached store registry, so
in-process callers should never exercise this fallback.
Sourcepub fn open_existing_readonly(db_path: &Path) -> Result<Option<Self>>
pub fn open_existing_readonly(db_path: &Path) -> Result<Option<Self>>
Open an existing file-backed store for read-only discovery use.
Unlike Self::open, this never creates parent directories, a database
file, or schema. Search tools can use it to consume frecency scores
without leaving a frecency footprint in discovery-only sessions.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Open an in-memory store. For tests and ephemeral use.
Sourcepub fn bump(&self, paths: &[PathBuf], now_ts: i64) -> Result<()>
pub fn bump(&self, paths: &[PathBuf], now_ts: i64) -> Result<()>
Bump the given paths at now_ts. Each path increments hit_count by 1
and sets last_access_ts = now_ts. The caller is responsible for
deduplicating within a single invocation (per the Implementation Notes
§“Bump dedup per tool invocation”).
Sourcepub fn score(&self, path: &Path, now_ts: i64) -> Result<f64>
pub fn score(&self, path: &Path, now_ts: i64) -> Result<f64>
Decayed frecency score for a single path. Missing paths return 0.0.
Sourcepub fn bulk_scores(
&self,
paths: &[&Path],
now_ts: i64,
) -> Result<HashMap<PathBuf, f64>>
pub fn bulk_scores( &self, paths: &[&Path], now_ts: i64, ) -> Result<HashMap<PathBuf, f64>>
Batch-score many paths at once. Missing paths are omitted from the map.
Sourcepub fn last_10_bumps(&self) -> Result<Vec<BumpEntry>>
pub fn last_10_bumps(&self) -> Result<Vec<BumpEntry>>
Most-recently-bumped rows, newest first, capped at 10. For health output.
Sourcepub fn top_frecent(&self, n: usize, now_ts: i64) -> Result<Vec<(PathBuf, f64)>>
pub fn top_frecent(&self, n: usize, now_ts: i64) -> Result<Vec<(PathBuf, f64)>>
Top-N paths ordered by decayed score at now_ts. For health output.
Sourcepub fn reset_or_halve_on_head_change(
&self,
last_head: Option<&str>,
current_head: &str,
commit_distance: Option<u32>,
) -> Result<ResetOutcome>
pub fn reset_or_halve_on_head_change( &self, last_head: Option<&str>, current_head: &str, commit_distance: Option<u32>, ) -> Result<ResetOutcome>
Apply the graduated HEAD-change reset policy and persist current_head.
Policy (Implementation Notes §“Reset-on-HEAD-change: graduated, not binary”):
last_headisNone(first session) → no-op.current_head == last_head→ no-op.commit_distance == None(unrelated history / branch change) → zero.commit_distance < 50→ no-op.50 <= commit_distance <= 500→ halve allhit_count.commit_distance > 500→ zero allhit_count.
The stored last_head is updated to current_head in every outcome so
subsequent sessions compare against the most recent reset point.
Note: the commit_distance parameter is Option<u32> (not the u32
the todo text specified). The spec requires “branch change → zero”,
which the git::commit_distance helper already signals by returning
Ok(None) for unrelated histories. Flowing that through preserves the
distinction without an out-of-band sentinel value.
Sourcepub fn apply_head_reset_policy(&self, repo_root: &Path) -> Result<(), String>
pub fn apply_head_reset_policy(&self, repo_root: &Path) -> Result<(), String>
Apply the graduated HEAD-change reset policy against repo_root’s git HEAD.
Wraps last_head lookup + git HEAD resolution + commit-distance computation
around [reset_or_halve_on_head_change]. Used by both the explicit boot-time
init_frecency_store path and the lazy first-bump cache-miss path, so the
policy applies wherever the store is first opened for a session.
All errors are mapped to String and any transient git failure (no repo,
detached HEAD, etc.) is silently dropped so the feature never breaks the
tool it hooks into.
Auto Trait Implementations§
impl !Freeze for FrecencyStore
impl RefUnwindSafe for FrecencyStore
impl Send for FrecencyStore
impl Sync for FrecencyStore
impl Unpin for FrecencyStore
impl UnsafeUnpin for FrecencyStore
impl UnwindSafe for FrecencyStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more