Skip to main content

JsonlSessionStore

Struct JsonlSessionStore 

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

JSONL file-based session store.

Each session is a single .jsonl file in the configured directory. Line 1 is SessionMeta (JSON), lines 2+ are one LlmMessage each.

Concurrent writes to the same session may corrupt the file. Callers are expected to enforce single-writer access.

With the search feature enabled, a tantivy index is maintained in <sessions_dir>/.search_index/ and used by SessionStore::search(). Without the feature, search falls back to a linear scan of all JSONL files.

Implementations§

Source§

impl JsonlSessionStore

Source

pub fn new(sessions_dir: PathBuf) -> Result<Self>

Create a new store rooted at the given directory.

Creates the directory (and parents) if it does not exist.

Source

pub fn open_search_index(&self) -> Result<()>

Open (or create) the tantivy search index eagerly.

Normally the index is opened lazily on the first search() call. Call this method if you want to detect index-creation errors at startup rather than at search time.

Only available with the search feature.

Source

pub fn rebuild_search_index(&self) -> Result<()>

Build (or rebuild) the tantivy index from all current JSONL files.

Existing index data is replaced. Use this after bulk-importing sessions outside of the store API.

Only available with the search feature.

Source

pub fn with_migrators(self, migrators: Vec<Box<dyn SessionMigrator>>) -> Self

Register session migrators for automatic schema upgrades on load.

Source

pub fn default_dir() -> Option<PathBuf>

Default sessions directory: <config_dir>/swink-agent/sessions.

Returns None if the platform config directory cannot be determined.

Source

pub fn new_session_id() -> String

Generate a new unique session ID using a UTC timestamp plus UUID suffix.

Source§

impl JsonlSessionStore

Source

pub fn save_entries( &self, id: &str, meta: &SessionMeta, entries: &[SessionEntry], ) -> Result<()>

Save a session with rich entry types.

Lines 2+ are SessionEntry values serialized with an entry_type tag.

When the search feature is enabled, the tantivy index is updated after the file is written (best-effort — index errors are logged but do not fail the save).

Source

pub fn append_entries( &self, id: &str, meta: &SessionMeta, entries: &[SessionEntry], ) -> Result<SessionMeta>

Append entries to an existing session without rewriting the whole file.

This is the append-only counterpart to Self::save_entries. Instead of rewriting every record on each turn, it appends only the new entries and patches the metadata line in place (reusing the same on-disk machinery and locking guarantees as the internal append path).

The caller’s meta.sequence must match the on-disk sequence (optimistic concurrency, identical to Self::save_entries); a mismatch returns an error. Every other meta field is written as provided — only id and sequence are set by the store. The returned SessionMeta carries the incremented sequence so callers stay in sync without re-reading the file.

If the metadata line can no longer be patched in place — its serialized form would outgrow the slot reserved on disk — this transparently falls back to a full rewrite that preserves all existing lines.

Errors if the session file does not exist; use Self::save_entries to create a new session.

When the search feature is enabled, only the newly appended entries are added to the tantivy index afterwards — the session’s existing documents are untouched (best-effort — index errors are logged but do not fail the append).

Source

pub fn load_entries(&self, id: &str) -> Result<(SessionMeta, Vec<SessionEntry>)>

Load a session with rich entry types.

Parses each line after metadata as a SessionEntry. Old-format lines (raw LlmMessage without entry_type) are interpreted as SessionEntry::Message for backward compatibility.

Trait Implementations§

Source§

impl SessionStore for JsonlSessionStore

Source§

fn save( &self, id: &str, meta: &SessionMeta, messages: &[AgentMessage], ) -> Result<()>

Persist a session, including both LLM and custom messages. Read more
Source§

fn save_full( &self, id: &str, meta: &SessionMeta, messages: &[AgentMessage], state: &Value, ) -> Result<SessionMeta>

Persist a session transcript plus its state snapshot. Read more
Source§

fn append(&self, id: &str, messages: &[AgentMessage]) -> Result<()>

Append messages to an existing session without rewriting the entire file.
Source§

fn load( &self, id: &str, registry: Option<&CustomMessageRegistry>, ) -> Result<(SessionMeta, Vec<AgentMessage>)>

Load a session by ID. Read more
Source§

fn load_full( &self, id: &str, registry: Option<&CustomMessageRegistry>, ) -> Result<(SessionMeta, Vec<AgentMessage>, Option<Value>)>

Load a session transcript plus its state snapshot from one consistent read boundary. Read more
Source§

fn list(&self) -> Result<Vec<SessionMeta>>

List all saved sessions, sorted by last updated (newest first).
Source§

fn delete(&self, id: &str) -> Result<()>

Delete a session by ID.
Source§

fn save_state(&self, id: &str, state: &Value) -> Result<()>

Save session state snapshot. Read more
Source§

fn load_state(&self, id: &str) -> Result<Option<Value>>

Load session state snapshot. Read more
Source§

fn save_interrupt(&self, id: &str, state: &InterruptState) -> Result<()>

Persist interrupt state for a session. Read more
Source§

fn load_interrupt(&self, id: &str) -> Result<Option<InterruptState>>

Load interrupt state for a session. Read more
Source§

fn clear_interrupt(&self, id: &str) -> Result<()>

Clear interrupt state for a session. Read more
Source§

fn load_with_options( &self, id: &str, options: &LoadOptions, ) -> Result<(SessionMeta, Vec<SessionEntry>)>

Load a session with filtering options. Read more
Source§

fn search( &self, query: &str, options: &SessionSearchOptions, ) -> Result<Vec<SessionHit>>

Search across persisted sessions. 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Fruit for T
where T: Send + Downcast,

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<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.
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