Skip to main content

HistoryEntry

Enum HistoryEntry 

Source
pub enum HistoryEntry {
    User {
        uuid: Option<String>,
        timestamp: Option<String>,
        cwd: Option<String>,
        git_branch: Option<String>,
        message: Value,
        rest: Map<String, Value>,
    },
    Assistant {
        uuid: Option<String>,
        timestamp: Option<String>,
        message: Value,
        rest: Map<String, Value>,
    },
    Other {
        type_tag: String,
        raw: Value,
    },
}
Expand description

One parsed line from a session .jsonl.

Only user and assistant entry types get typed variants; everything else (queue-operation, attachment, ai-title, last-prompt, future types) lands in Self::Other with the raw JSON for caller inspection.

Variants§

§

User

A user entry: a prompt turn written by the user.

Fields

§uuid: Option<String>

Entry uuid, when present.

§timestamp: Option<String>

ISO-8601 timestamp, when present.

§cwd: Option<String>

Working directory recorded for the turn, when present.

§git_branch: Option<String>

Git branch recorded for the turn, when present.

§message: Value

The raw message payload as Claude Code wrote it.

§rest: Map<String, Value>

Every remaining field of the record, keyed as Claude Code wrote it (camelCase, e.g. promptSource). See HistoryEntry::field and the typed accessors for common lookups.

§

Assistant

An assistant entry: a model response turn.

Fields

§uuid: Option<String>

Entry uuid, when present.

§timestamp: Option<String>

ISO-8601 timestamp, when present.

§message: Value

The raw message payload as Claude Code wrote it.

§rest: Map<String, Value>

Every remaining field of the record, keyed as Claude Code wrote it (camelCase, e.g. requestId). See HistoryEntry::field and the typed accessors for common lookups.

§

Other

Any other entry type, carried as raw JSON for caller inspection.

Fields

§type_tag: String

The type field as Claude Code wrote it.

§raw: Value

The full raw entry.

Implementations§

Source§

impl HistoryEntry

Source

pub fn from_line(line: &str) -> Result<Self, Error>

Parse a single transcript line into a typed entry.

The per-line counterpart to HistoryRoot::read_session: use this when you already hold the line – typically a consumer tailing append-only transcript files by byte offset, reading only the new bytes on each pass instead of re-reading whole session files.

Parsing is liberal, matching read_session: entry types other than user and assistant come through as Self::Other carrying the raw value. A line that is not valid JSON is the one Err case – the same lines read_session skips with a warning, left to the caller here.

use claude_wrapper::history::HistoryEntry;

let line = r#"{"type":"user","uuid":"u1","cwd":"/work/repo","promptSource":"typed","message":{"role":"user"}}"#;
let entry = HistoryEntry::from_line(line)?;
match &entry {
    HistoryEntry::User { cwd, .. } => {
        assert_eq!(cwd.as_deref(), Some("/work/repo"));
    }
    _ => unreachable!(),
}
assert_eq!(entry.prompt_source(), Some("typed"));
Source

pub fn field(&self, key: &str) -> Option<&Value>

Raw access to a field by its name as Claude Code wrote it (camelCase, e.g. "permissionMode").

For Self::User and Self::Assistant this resolves against rest, so the fields promoted to struct fields (uuid, timestamp, cwd, gitBranch, message) are not reachable here. For Self::Other it resolves against the full raw entry.

These records are Claude Code’s data, not this crate’s: a CLI update can add, drop, or retype any field, which is why this returns raw JSON and the typed accessors below are all Option-shaped.

Source

pub fn prompt_source(&self) -> Option<&str>

How the prompt reached the session (typed, queued, sdk, system, suggestion_accepted), when recorded. Only user entries carrying an actual prompt have this; tool-result user turns generally do not.

Source

pub fn entrypoint(&self) -> Option<&str>

The surface the session was driven from (cli, claude-desktop, sdk-cli), when recorded.

Source

pub fn is_meta(&self) -> Option<bool>

Whether the entry is harness-injected context rather than a real turn. None when the field is absent.

Source

pub fn is_sidechain(&self) -> Option<bool>

Whether the entry belongs to a subagent sidechain. None when the field is absent.

Source

pub fn session_id(&self) -> Option<&str>

The session id recorded on the entry, when present.

Source

pub fn parent_uuid(&self) -> Option<&str>

The uuid of the parent entry, when present. Root entries carry parentUuid: null, which also reads as None here.

Trait Implementations§

Source§

impl Clone for HistoryEntry

Source§

fn clone(&self) -> HistoryEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HistoryEntry

Source§

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

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

impl Serialize for HistoryEntry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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