Skip to main content

Session

Struct Session 

Source
pub struct Session {
    pub meta: SessionMeta,
    pub path: PathBuf,
}

Fields§

§meta: SessionMeta§path: PathBuf

Implementations§

Source§

impl Session

Source

pub fn default_dir() -> Result<PathBuf>

Where transcripts live: ~/.mecha/sessions, or $MECHA_SESSION_DIR.

Source

pub fn create(dir: &Path, meta: SessionMeta) -> Result<Self>

Source

pub fn new_id() -> String

Source

pub fn append(&self, record: &Record) -> Result<()>

Source

pub fn append_messages(&self, messages: &[Message]) -> Result<()>

Source

pub fn record_run(&self, before: &[Message], convo: &Conversation) -> Result<()>

Record what a run did to the conversation, given the messages it started from.

before must be what the file already holds — every front-end has appended the opening user message (and, resumed, the loaded history) before the run starts. The walk visits every state the run’s rewrites replaced (Conversation::rewritten) and then the final one, so a run long enough to compact itself still gets its whole head into the file: each pre-rewrite snapshot extends the previous recorded state append-only (its cheap tail append), and each post-rewrite state lands as the Record::Rewrite the next transition writes. The signature takes the conversation rather than a message slice so a caller cannot record the destination while skipping the journey.

Source

pub fn load(path: &Path) -> Result<(SessionMeta, Conversation)>

Read a transcript back, taint included.

Unparseable lines are skipped rather than failing the load — a truncated final line is the normal result of a killed process.

Source

pub fn taint_timeline(path: &Path) -> Result<TaintTimeline>

The taint checkpoints of a transcript, positioned against its messages.

Every front-end appends a Record::Taint checkpoint after the messages of the run it describes, so the checkpoint that covers a message is the first one written after it — and by then the taint of everything earlier in that run, hostile fetches included, has merged in. That ordering is what makes TaintTimeline::covering safe to gate on: it can over-taint a message (a fetch later in the same run counts against it), never under-taint one.

Source

pub fn run_configs(path: &Path) -> Result<Vec<RunConfig>>

Every run configuration in a transcript, in the order the runs happened.

A replay driver needs this per run rather than per session: resuming under different flags is a normal thing to do, and the turns before and after are not comparable. An empty result means a transcript written before this was recorded — which cannot be replayed faithfully, because the system prompt and tool list that shaped it are gone.

Source

pub fn peek_meta(path: &Path) -> Option<SessionMeta>

The header alone, without parsing the rest of the file.

Listing goes through this rather than Session::load so mecha sessions stays O(number of sessions) instead of O(total transcript bytes) — with reflect-on-close recording every interaction, the full parse re-read the whole store to print one line per file. The header is the first record create writes; a file whose first record is anything else is not a session this process wrote, and is skipped exactly as load’s no-header error skipped it.

Source

pub fn usage_totals(path: &Path) -> Result<(Usage, u32)>

The run summaries of a transcript, summed: total usage and turns across every run the file records. Zero for a transcript that predates the summary record or died before writing one — an honest under-count, never a guess.

Source

pub fn list(dir: &Path) -> Result<Vec<(SessionMeta, PathBuf)>>

Sessions in dir, newest first.

Source

pub fn find(dir: &Path, id_prefix: &str) -> Result<PathBuf>

Find a session by full id or unique prefix.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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, 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