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
impl SessionWriter
Sourcepub 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>
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.
Sourcepub fn next_sequence(&self) -> u64
pub fn next_sequence(&self) -> u64
Sequence number that will be assigned to the next appended record.
Sourcepub fn resume(path: &Path, session_id: &str) -> Result<Self>
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.
Sourcepub fn append(&mut self, record: SessionRecord) -> Result<()>
pub fn append(&mut self, record: SessionRecord) -> Result<()>
Append a record to the session file.
Sourcepub fn append_entry(&mut self, entry: &Entry, turn_id: &str) -> Result<()>
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.
Sourcepub fn append_entry_with_artifact(
&mut self,
entry: &Entry,
turn_id: &str,
artifact: Option<ArtifactMetadata>,
) -> Result<()>
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.
Sourcepub fn append_tool_started(
&mut self,
turn_id: &str,
call_id: &str,
name: &str,
args: &str,
) -> Result<()>
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.
Sourcepub fn append_context(&mut self, sources: &[ContextSource]) -> Result<()>
pub fn append_context(&mut self, sources: &[ContextSource]) -> Result<()>
Append a context record with loaded AGENTS.md source metadata.
Sourcepub fn append_context_ledger(
&mut self,
turn_id: &str,
ledger: &ContextLedger,
) -> Result<()>
pub fn append_context_ledger( &mut self, turn_id: &str, ledger: &ContextLedger, ) -> Result<()>
Append a content-free context ledger snapshot for a prompt turn.
Sourcepub fn append_context_pin(
&mut self,
item: &ContextItem,
reason: &str,
) -> Result<()>
pub fn append_context_pin( &mut self, item: &ContextItem, reason: &str, ) -> Result<()>
Append a content-free user pin action.
Sourcepub fn append_context_drop(
&mut self,
item: &ContextItem,
reason: &str,
) -> Result<()>
pub fn append_context_drop( &mut self, item: &ContextItem, reason: &str, ) -> Result<()>
Append a content-free user drop action.
Sourcepub fn append_context_recovery(
&mut self,
item: &ContextItem,
reason: &str,
) -> Result<()>
pub fn append_context_recovery( &mut self, item: &ContextItem, reason: &str, ) -> Result<()>
Append a content-free user recovery action.
Sourcepub fn append_compaction(&mut self, audit: &CompactionAudit) -> Result<()>
pub fn append_compaction(&mut self, audit: &CompactionAudit) -> Result<()>
Append a compaction audit record without source payloads.
Sourcepub fn append_compaction_review(
&mut self,
recovery_handle: &str,
review: CompactionReviewResult,
) -> Result<()>
pub fn append_compaction_review( &mut self, recovery_handle: &str, review: CompactionReviewResult, ) -> Result<()>
Append the review decision for a previously pending compaction.
Sourcepub fn append_prompt_metadata(
&mut self,
turn_id: &str,
metadata: &PromptMetadata,
) -> Result<()>
pub fn append_prompt_metadata( &mut self, turn_id: &str, metadata: &PromptMetadata, ) -> Result<()>
Append prompt assembly provenance for a user turn.
Sourcepub fn append_usage(
&mut self,
input_tokens: u64,
output_tokens: u64,
) -> Result<()>
pub fn append_usage( &mut self, input_tokens: u64, output_tokens: u64, ) -> Result<()>
Append provider token usage for the session.
Sourcepub fn append_request_accounting(
&mut self,
turn_id: &str,
accounting: &ProviderRequestAccounting,
) -> Result<()>
pub fn append_request_accounting( &mut self, turn_id: &str, accounting: &ProviderRequestAccounting, ) -> Result<()>
Append accounting for one successful provider request.
Sourcepub fn append_file_write(
&mut self,
turn_id: &str,
result: &WriteResult,
status: ToolStatus,
) -> Result<()>
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.
Sourcepub fn append_mcp_config_changed(
&mut self,
turn_id: &str,
previous_files: Vec<SessionConfigFile>,
current_files: Vec<SessionConfigFile>,
diagnostics: Vec<String>,
) -> Result<()>
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.
Sourcepub fn append_shell_exec(
&mut self,
turn_id: &str,
result: &ProcessResult,
) -> Result<()>
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.
Sourcepub fn append_skill_activation(
&mut self,
activation: &SkillActivation,
) -> Result<()>
pub fn append_skill_activation( &mut self, activation: &SkillActivation, ) -> Result<()>
Append a skill activation metadata record.
Sourcepub fn append_queued(&mut self, kind: &str, text: &str) -> Result<()>
pub fn append_queued(&mut self, kind: &str, text: &str) -> Result<()>
Append a queued input audit record.
Sourcepub fn append_acp_permission_request(
&mut self,
turn_id: &str,
request: &PendingPermission,
) -> Result<()>
pub fn append_acp_permission_request( &mut self, turn_id: &str, request: &PendingPermission, ) -> Result<()>
Append ACP permission request metadata.
Sourcepub fn append_acp_session(
&mut self,
metadata: &AcpSessionMetadata,
) -> Result<()>
pub fn append_acp_session( &mut self, metadata: &AcpSessionMetadata, ) -> Result<()>
Append ACP session metadata.
Sourcepub fn append_acp_permission_outcome(
&mut self,
turn_id: &str,
tool_call_id: &str,
outcome: &str,
) -> Result<()>
pub fn append_acp_permission_outcome( &mut self, turn_id: &str, tool_call_id: &str, outcome: &str, ) -> Result<()>
Append ACP permission outcome metadata.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session id.
Trait Implementations§
Source§impl Debug for SessionWriter
impl Debug for SessionWriter
Source§impl Drop for SessionWriter
impl Drop for SessionWriter
Auto Trait Implementations§
impl Freeze for SessionWriter
impl RefUnwindSafe for SessionWriter
impl Send for SessionWriter
impl Sync for SessionWriter
impl Unpin for SessionWriter
impl UnsafeUnpin for SessionWriter
impl UnwindSafe for SessionWriter
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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