pub struct SessionState { /* private fields */ }Expand description
Session state that persists across commands.
Implementations§
Source§impl SessionState
impl SessionState
Sourcepub fn loaded_models(&self) -> &HashMap<String, LoadedModel>
pub fn loaded_models(&self) -> &HashMap<String, LoadedModel>
Get loaded models.
Sourcepub fn history(&self) -> &[HistoryEntry]
pub fn history(&self) -> &[HistoryEntry]
Get command history.
Sourcepub fn add_model(&mut self, name: String, model: LoadedModel)
pub fn add_model(&mut self, name: String, model: LoadedModel)
Add a model to the session.
Sourcepub fn remove_model(&mut self, name: &str) -> Option<LoadedModel>
pub fn remove_model(&mut self, name: &str) -> Option<LoadedModel>
Remove a model from the session.
Sourcepub fn get_model(&self, name: &str) -> Option<&LoadedModel>
pub fn get_model(&self, name: &str) -> Option<&LoadedModel>
Get a model by name.
Sourcepub fn add_to_history(&mut self, entry: HistoryEntry)
pub fn add_to_history(&mut self, entry: HistoryEntry)
Add a command to history.
Sourcepub fn preferences_mut(&mut self) -> &mut Preferences
pub fn preferences_mut(&mut self) -> &mut Preferences
Get mutable preferences.
Sourcepub fn preferences(&self) -> &Preferences
pub fn preferences(&self) -> &Preferences
Get preferences.
Sourcepub fn metrics(&self) -> &SessionMetrics
pub fn metrics(&self) -> &SessionMetrics
Get session metrics.
Sourcepub fn record_command(&mut self, duration_ms: u64, success: bool)
pub fn record_command(&mut self, duration_ms: u64, success: bool)
Update metrics after a command.
Sourcepub fn load(path: &PathBuf) -> Result<Self>
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 0Loading now fails rather than admitting unprovenanced models.
Sourcepub fn validate_model_provenance(&self) -> Result<(), String>
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:
- A cached model is ON DISK. A session naming a path that does not exist is describing a model nobody has.
- Nothing in this crate can produce a
LoadedModelat all:fetchrefuses (it has no HuggingFace client, #2519) and no other production path callsadd_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
impl Clone for SessionState
Source§impl Debug for SessionState
impl Debug for SessionState
Source§impl Default for SessionState
impl Default for SessionState
Source§impl<'de> Deserialize<'de> for SessionState
impl<'de> Deserialize<'de> for SessionState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SessionState
impl PartialEq for SessionState
Source§impl Serialize for SessionState
impl Serialize for SessionState
impl StructuralPartialEq for SessionState
Auto Trait Implementations§
impl Freeze for SessionState
impl RefUnwindSafe for SessionState
impl Send for SessionState
impl Sync for SessionState
impl Unpin for SessionState
impl UnsafeUnpin for SessionState
impl UnwindSafe for SessionState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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