Skip to main content

SessionWriter

Struct SessionWriter 

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

Append-only JSONL session writer.

Each session is a single .jsonl file. Records are appended one per line and never rewritten. The writer tracks a monotonic seq counter.

Implementations§

Source§

impl SessionWriter

Source

pub fn create( dir: &Path, session_id: &str, cwd: &str, title: &str, provider: &str, model: &str, websearch: &str, app_version: &str, config: Option<SessionConfigMeta>, ) -> Result<Self>

Create a new session file in dir with the given session id.

Writes the initial session_meta record as the first line.

Source

pub fn next_sequence(&self) -> u64

Sequence number that will be assigned to the next appended record.

Source

pub fn resume(path: &Path, session_id: &str) -> Result<Self>

Reopen an existing session file for append-only continuation.

The next sequence number is derived from the highest readable record sequence. Corrupt trailing lines are ignored consistently with SessionReader.

Source

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

Append a record to the session file.

Source

pub fn append_entry(&mut self, entry: &Entry, turn_id: &str) -> Result<()>

Append a transcript entry as a record, if it maps to one.

Streaming/live entries are skipped — only finalized entries are persisted for replay.

Source

pub fn append_entry_with_artifact( &mut self, entry: &Entry, turn_id: &str, artifact: Option<ArtifactMetadata>, ) -> Result<()>

Append a finalized transcript entry with bounded artifact metadata.

Source

pub fn append_tool_started( &mut self, turn_id: &str, call_id: &str, name: &str, args: &str, ) -> Result<()>

Append a tool_started record for a tool call that has begun.

This records the command start: tool name, call id, and arguments. The matching tool_finished (via Self::append_entry) records the output, status, and summary. For run_shell, an additional Self::append_shell_exec record captures exit code, elapsed time, and process kind.

Source

pub fn append_context(&mut self, sources: &[ContextSource]) -> Result<()>

Append a context record with loaded AGENTS.md source metadata.

Source

pub fn append_context_ledger( &mut self, turn_id: &str, ledger: &ContextLedger, ) -> Result<()>

Append a content-free context ledger snapshot for a prompt turn.

Source

pub fn append_context_pin( &mut self, item: &ContextItem, reason: &str, ) -> Result<()>

Append a content-free user pin action.

Source

pub fn append_context_drop( &mut self, item: &ContextItem, reason: &str, ) -> Result<()>

Append a content-free user drop action.

Source

pub fn append_context_recovery( &mut self, item: &ContextItem, reason: &str, ) -> Result<()>

Append a content-free user recovery action.

Source

pub fn append_compaction(&mut self, audit: &CompactionAudit) -> Result<()>

Append a compaction audit record without source payloads.

Source

pub fn append_compaction_review( &mut self, recovery_handle: &str, review: CompactionReviewResult, ) -> Result<()>

Append the review decision for a previously pending compaction.

Source

pub fn append_prompt_metadata( &mut self, turn_id: &str, metadata: &PromptMetadata, ) -> Result<()>

Append prompt assembly provenance for a user turn.

Source

pub fn append_usage( &mut self, input_tokens: u64, output_tokens: u64, ) -> Result<()>

Append provider token usage for the session.

Source

pub fn append_request_accounting( &mut self, turn_id: &str, accounting: &ProviderRequestAccounting, ) -> Result<()>

Append accounting for one successful provider request.

Source

pub fn append_file_write( &mut self, turn_id: &str, result: &WriteResult, status: ToolStatus, ) -> Result<()>

Append a file-write audit record.

Records the operation type, path, before/after hashes and byte counts, and status. File content is never stored — only hashes and byte counts, so secrets and large files are not persisted.

Source

pub fn append_mcp_config_changed( &mut self, turn_id: &str, previous_files: Vec<SessionConfigFile>, current_files: Vec<SessionConfigFile>, diagnostics: Vec<String>, ) -> Result<()>

Append an audit record when MCP config file hashes change mid-session.

Source

pub fn append_shell_exec( &mut self, turn_id: &str, result: &ProcessResult, ) -> Result<()>

Append a shell-execution audit record.

Records the command argv, working directory, registry id, lifecycle status, exit code, elapsed time, and process kind. stdout/stderr are not stored here — they are captured in redacted and capped output records.

Source

pub fn append_skill_activation( &mut self, activation: &SkillActivation, ) -> Result<()>

Append a skill activation metadata record.

Source

pub fn append_queued(&mut self, kind: &str, text: &str) -> Result<()>

Append a queued input audit record.

Source

pub fn append_acp_permission_request( &mut self, turn_id: &str, request: &PendingPermission, ) -> Result<()>

Append ACP permission request metadata.

Source

pub fn append_acp_session( &mut self, metadata: &AcpSessionMetadata, ) -> Result<()>

Append ACP session metadata.

Source

pub fn append_acp_permission_outcome( &mut self, turn_id: &str, tool_call_id: &str, outcome: &str, ) -> Result<()>

Append ACP permission outcome metadata.

Source

pub fn path(&self) -> &Path

The session file path.

Source

pub fn session_id(&self) -> &str

The session id.

Trait Implementations§

Source§

impl Debug for SessionWriter

Source§

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

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

impl Drop for SessionWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<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> IntoMaybeUndefined<T> for T

Source§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
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> Same for T

Source§

type Output = T

Should always be Self
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