Skip to main content

SessionContext

Struct SessionContext 

Source
pub struct SessionContext {
Show 24 fields pub session_file: String, pub call_counter: u64, pub seen_files: Vec<FileFingerprint>, pub seen_errors: Vec<u64>, pub error_snippets: Vec<(u64, String)>, pub seen_git_refs: Vec<String>, pub call_log: Vec<CallEntry>, pub call_log_shingles: Vec<Vec<u64>>, pub tokens_bash: u64, pub tokens_read: u64, pub tokens_grep: u64, pub tokens_other: u64, pub reread_count: u32, pub exact_dedup_hits: u32, pub fuzzy_dedup_hits: u32, pub summarize_triggers: u32, pub intensity_ultra_calls: u32, pub agent_spawns: u32, pub agent_estimated_tokens: u64, pub agent_spawn_log: Vec<AgentSpawnEntry>, pub burn_window: Vec<BurnEntry>, pub max_call_log: usize, pub recent_window: usize, pub similarity_threshold: f32,
}

Fields§

§session_file: String§call_counter: u64§seen_files: Vec<FileFingerprint>§seen_errors: Vec<u64>§error_snippets: Vec<(u64, String)>

First-128-char snippets parallel to seen_errors (phase 2). Each entry is (fingerprint, snippet_text) in insertion order.

§seen_git_refs: Vec<String>§call_log: Vec<CallEntry>§call_log_shingles: Vec<Vec<u64>>

Bottom-k MinHash sketch parallel to call_log. Each entry is the sorted-deduplicated trigram-shingle hash set for that call’s output. Used by lookup_similar for fuzzy redundancy matching that survives whitespace/timestamp/single-line-edit perturbations.

May be shorter than call_log after loading older context.json files that pre-date this field; callers must check length parity defensively.

§tokens_bash: u64

Cumulative token counts by tool category (Bash, Read, Grep, Other)

§tokens_read: u64§tokens_grep: u64§tokens_other: u64§reread_count: u32

How many times a file was accessed that was already in seen_files (re-read metric).

§exact_dedup_hits: u32§fuzzy_dedup_hits: u32§summarize_triggers: u32§intensity_ultra_calls: u32§agent_spawns: u32§agent_estimated_tokens: u64§agent_spawn_log: Vec<AgentSpawnEntry>§burn_window: Vec<BurnEntry>§max_call_log: usize§recent_window: usize§similarity_threshold: f32

Implementations§

Source§

impl SessionContext

Source

pub fn load(sessions_dir: &Path) -> Self

Source

pub fn init_tunables_from_config(&mut self, cfg: &Config)

Copy tunable values from Config into this context so all methods use the user’s configured values rather than the compiled-in defaults. Called in context::pre_pass after loading or constructing the context.

Source

pub fn save(&self, sessions_dir: &Path)

Source

pub fn next_call_n(&mut self) -> u64

Source

pub fn record_call( &mut self, cmd: &str, output_hash: u64, output_len: usize, call_n: u64, )

Source

pub fn record_call_with_shingles( &mut self, cmd: &str, output_hash: u64, output_len: usize, call_n: u64, shingles: Vec<u64>, )

Like record_call, but additionally stores a MinHash shingle sketch of the output so that lookup_similar can find near-matches later.

Source

pub fn lookup_recent(&self, hash: u64, len: usize) -> Option<&CallEntry>

Lookup a recent call with matching hash AND output_len. Only considers the last self.recent_window entries.

Source

pub fn lookup_similar( &self, query_shingles: &[u64], query_len: usize, ) -> Option<SimilarMatch>

Lookup the highest-similarity recent call whose Jaccard distance to query_shingles is at least self.similarity_threshold AND whose length ratio with query_len is within LENGTH_RATIO_GUARD. Considers only the last self.recent_window entries.

Returns None when:

  • the query has no shingles (text too short for trigrams)
  • no candidate clears the threshold
  • shingles have not been recorded yet for the matching call (legacy load)
Source

pub fn note_file(&mut self, path: &str, access: FileAccess)

Record a file access with an explicit access type (phase 4).

Source

pub fn note_files(&mut self, files: &[String])

Record multiple files as Read access (backward-compatible wrapper).

Source

pub fn note_errors(&mut self, errors: &[String])

Source

pub fn note_redundancy_hit_exact(&mut self)

Record an exact-hash redundancy hit (called from wrap.rs after check()).

Source

pub fn note_redundancy_hit_fuzzy(&mut self)

Record a fuzzy-similarity redundancy hit (called from wrap.rs after check()).

Source

pub fn note_summarize_trigger(&mut self)

Record that the summarizer was triggered for this call.

Source

pub fn note_intensity_ultra(&mut self)

Record that Ultra intensity was active for this call.

Source

pub fn note_git(&mut self, refs: &[String])

Source

pub fn note_agent_spawn(&mut self, tool_name: &str, estimated_tokens: u64)

Record a sub-agent spawn (Agent or Task tool call).

Source

pub fn note_burn(&mut self, tokens: u64)

Record token consumption for burn rate prediction.

Source

pub fn note_tool_tokens(&mut self, tool: &str, tokens: u64)

Record token usage by tool category.

Source

pub fn file_was_seen(&self, path: &str) -> Option<u64>

Source§

impl SessionContext

Source

pub fn to_json(&self) -> String

Source

pub fn from_json(s: &str) -> Self

Trait Implementations§

Source§

impl Clone for SessionContext

Source§

fn clone(&self) -> SessionContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SessionContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.