Skip to main content

Session

Struct Session 

Source
pub struct Session {
    pub loaded: BTreeMap<String, Record>,
    pub last_prompt: String,
    pub recent_prompts: Vec<String>,
    pub updated: u64,
}

Fields§

§loaded: BTreeMap<String, Record>

skill id -> how it got into context (and at what confidence).

§last_prompt: String

The most recent user prompt in this conversation. Stashed by the hook only when telemetry is on, so a later self-load seen by ski observe (a recall miss — the model loaded a skill we never recommended) can be tied back to the prompt that was active. Empty otherwise; never serialized when empty, so the non-telemetry hot path leaves the file unchanged.

§recent_prompts: Vec<String>

Recent user prompts in this conversation, oldest-first, bounded. Drives query-side context enrichment: a vague follow-up (“now do the other one”) is disambiguated by the turns that preceded it. Maintained only when the context feature is enabled (Config::context_depth > 0), so the default hot path neither writes nor carries it. #[serde(default)] + skip-when-empty keeps it invisible to indexes/sessions written before it existed.

§updated: u64

Unix seconds of the last write (diagnostics only).

Implementations§

Source§

impl Session

Source

pub fn load(path: &Path) -> Session

Load state for a session, or an empty session if the file is missing or unreadable. Never errors.

Source

pub fn save(&self, path: &Path) -> Result<()>

Persist state, stamping updated. Best-effort; callers in the hot path should ignore the result so state IO can’t block a prompt.

Writes a per-process temp file then atomically renames it over the target, so a concurrent reader (another hook/observe process sharing the session_id) never observes a half-written file — a torn read used to silently reset the session and re-arm dedup. The lost-update window — two writers racing the load→mutate→save and one dropping the other’s mark — remains; it costs at most a missed dedup (a re-injection), never corruption, and closing it would need an advisory lock.

Source

pub fn is_loaded(&self, id: &str) -> bool

Source

pub fn get(&self, id: &str) -> Option<&Record>

Source

pub fn save_merged(&self, path: &Path) -> Result<()>

Persist like save, but first merge the loaded ledger with whatever is on disk now, so a mark written by a concurrent process survives. The hook loads its session snapshot, then spends the better part of a second embedding/reranking before saving — ample time for ski observe to record a model self-load that a plain save would overwrite (the lost mark re-arms dedup and the skill gets re-injected).

Merge rules, per skill id (dedup-safety errs toward suppression):

  • present only on disk → kept (that’s the concurrent writer’s mark);
  • Model beats Ski regardless of side (a used skill stays used);
  • both Ski → the higher recorded confidence wins (matches should_recommend’s “no repeat after a HIGH showing”).

Prompt fields (last_prompt, recent_prompts) are taken from self: the hook is their only writer, and there is at most one hook per prompt. Callers that intentionally wipe state (the compaction re-arm) must use the plain save, or the merge would resurrect the ledger.

The load→rename window still exists but shrinks from the whole hook runtime to microseconds; closing it fully would need an advisory lock.

Source

pub fn should_recommend(&self, id: &str, new_conf: f32, high: f32) -> bool

Whether id should be recommended now, at new_conf, given what we already know. The two dedup rules:

  • a used skill (Source::Model) is never recommended again;
  • a recommended-but-unused skill (Source::Ski) is re-recommended only when it newly reaches high confidence (it was shown below high before — a clearer prompt earns one stronger nudge; after a HIGH showing, never).

Record that we recommended id at confidence. Stores the confidence we just showed (so the next-turn should_recommend test is accurate), but never downgrades a Model load — once the model used a skill it stays used.

Source

pub fn mark_used(&mut self, id: &str)

Record that the model loaded id itself. Always wins (the strongest signal); keeps any confidence we’d previously shown for diagnostics.

Source

pub fn mark(&mut self, id: &str, source: Source)

Generic mark, kept for callers/tests that don’t carry a confidence: Model via [mark_used], Ski as a confidence-0 first sighting that never overwrites an existing entry.

Source

pub fn push_prompt(&mut self, prompt: &str, max: usize)

Append prompt to the rolling context window, keeping at most max of the most recent prompts (oldest dropped first). A blank prompt, or one identical to the immediately previous entry (a resubmit), is ignored so the window holds distinct conversational turns. max == 0 disables the window entirely (the feature-off path).

Source

pub fn clear(&mut self)

Forget everything — used to re-arm on compaction so skills can be re-injected into the fresh summary.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Session

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

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

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

impl Default for Session

Source§

fn default() -> Session

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

impl<'de> Deserialize<'de> for Session

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Session

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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