Skip to main content

FrecencyStore

Struct FrecencyStore 

Source
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

Source

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.

Source

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.

Source

pub fn open_in_memory() -> Result<Self>

Open an in-memory store. For tests and ephemeral use.

Source

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”).

Source

pub fn score(&self, path: &Path, now_ts: i64) -> Result<f64>

Decayed frecency score for a single path. Missing paths return 0.0.

Source

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.

Source

pub fn last_10_bumps(&self) -> Result<Vec<BumpEntry>>

Most-recently-bumped rows, newest first, capped at 10. For health output.

Source

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.

Source

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_head is None (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 all hit_count.
  • commit_distance > 500 → zero all hit_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.

Source

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.

Source

pub fn last_head(&self) -> Result<Option<String>>

Read the last HEAD SHA this store recorded.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,