Skip to main content

SessionState

Struct SessionState 

Source
pub struct SessionState { /* private fields */ }
Expand description

Session state that persists across commands.

Implementations§

Source§

impl SessionState

Source

pub fn new() -> Self

Create a new empty session state.

Source

pub fn loaded_models(&self) -> &HashMap<String, LoadedModel>

Get loaded models.

Source

pub fn history(&self) -> &[HistoryEntry]

Get command history.

Source

pub fn add_model(&mut self, name: String, model: LoadedModel)

Add a model to the session.

Source

pub fn remove_model(&mut self, name: &str) -> Option<LoadedModel>

Remove a model from the session.

Source

pub fn get_model(&self, name: &str) -> Option<&LoadedModel>

Get a model by name.

Source

pub fn add_to_history(&mut self, entry: HistoryEntry)

Add a command to history.

Source

pub fn preferences_mut(&mut self) -> &mut Preferences

Get mutable preferences.

Source

pub fn preferences(&self) -> &Preferences

Get preferences.

Source

pub fn metrics(&self) -> &SessionMetrics

Get session metrics.

Source

pub fn record_command(&mut self, duration_ms: u64, success: bool)

Update metrics after a command.

Source

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

Save state to a file.

Source

pub fn load(path: &PathBuf) -> Result<Self>

Load state from a file.

#2519: a session file is UNTRUSTED INPUT. LoadedModel derives Deserialize, so before this check a hand-written JSON file could put any model facts it liked into the session — architecture, parameter count, layer count, hidden dim — and every downstream command (inspect, memory, distill) then presented them as measured fact. That is the same fabrication #2519 closed in fetch, reached through a second door the fetch falsifier could not see. Measured before this change, with a crafted session naming /nonexistent:

$ aprender-train-shell --session sess.json -c "distill --dry-run"
Teacher: does-not-exist/totally-fake-7b (7.0B)
Student: does-not-exist/totally-fake-1b (1.0B)
Ready to train                                     # exit 0

Loading now fails rather than admitting unprovenanced models.

Source

pub fn validate_model_provenance(&self) -> Result<(), String>

Reject models whose facts this shell could not have derived.

Two rules, deliberately ordered so the second can be deleted on its own the day a real loader lands, leaving the first standing:

  1. A cached model is ON DISK. A session naming a path that does not exist is describing a model nobody has.
  2. Nothing in this crate can produce a LoadedModel at all: fetch refuses (it has no HuggingFace client, #2519) and no other production path calls add_model. So any model in a session file was typed by hand, not measured, whatever its path says.

When a real fetch/loader is implemented, delete rule 2 and the no_loader_exists half of the falsifier with it — but rule 1 stays.

Trait Implementations§

Source§

impl Clone for SessionState

Source§

fn clone(&self) -> SessionState

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 SessionState

Source§

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

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

impl Default for SessionState

Source§

fn default() -> SessionState

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

impl<'de> Deserialize<'de> for SessionState

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 PartialEq for SessionState

Source§

fn eq(&self, other: &SessionState) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SessionState

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

impl StructuralPartialEq for SessionState

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, 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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.