Skip to main content

Session

Struct Session 

Source
pub struct Session {
    pub meta: SessionMeta,
    pub messages: Vec<ChatMessage>,
    pub subagents: Vec<Session>,
    pub raw: Vec<String>,
}
Expand description

A normalized, replayable conversation loaded from a tool’s session log.

Fields§

§meta: SessionMeta

Recovered metadata.

§messages: Vec<ChatMessage>

The conversation, normalized to the OpenAI chat-completions shape.

§subagents: Vec<Session>

Subagent (Task) sub-conversations. Claude Code stores these as separate <session>/subagents/agent-*.jsonl files; loading a session by path now discovers and attaches them here (each is a full Session whose meta.agent_id / meta.parent_tool_use_id link it back to its spawn).

§raw: Vec<String>

Every original JSONL line of the source log, verbatim. Normalization is lossy by design (it targets the OpenAI replay shape), but these raw lines retain everything — including records with no canonical representation (e.g. Claude file-history-snapshot) — so a round-trip through the supercode-native format (Session::to_native_jsonl) is lossless.

Implementations§

Source§

impl Session

Source

pub fn load(path: impl AsRef<Path>) -> Result<Session>

Load a session, auto-detecting whether it’s a Claude Code or Codex log.

Source

pub fn from_claude_code(path: impl AsRef<Path>) -> Result<Session>

Load a Claude Code transcript from a file, attaching any subagent (Task) sub-conversations stored alongside it.

Source

pub fn from_codex(path: impl AsRef<Path>) -> Result<Session>

Load a Codex rollout from a file.

Source

pub fn from_claude_code_str(jsonl: &str) -> Result<Session>

Parse a Claude Code transcript from an in-memory JSONL string.

Source

pub fn reconstruct_tree(sessions: Vec<Session>) -> Vec<Session>

Reconstruct multi-file subagent trees from a flat set of loaded sessions.

Codex stores subagents as separate rollout files linked to their parent by lineage["parent_thread_id"] (→ the parent’s session_id). Given a collection of sessions, this nests each child into its parent’s Session::subagents and returns only the roots. Children whose parent isn’t in the set are returned as roots themselves (best effort).

Source

pub fn load_str(jsonl: &str, format: SessionFormat) -> Result<Session>

Parse a session of a known format from an in-memory JSONL string.

Source

pub fn to_jsonl(&self, format: SessionFormat) -> String

Serialize this session to JSONL in the given format.

The conversation is synthesized from the canonical messages, so this works for sessions loaded from either tool as well as ones supercode built itself. Converting between formats (e.g. Codex → Claude Code) is an “export”: format-specific framing that has no slot in the target may be dropped, but the user/assistant/tool conversation is preserved.

Source

pub fn save(&self, path: impl AsRef<Path>, format: SessionFormat) -> Result<()>

Write this session to path in the given format.

Source

pub fn to_native_jsonl(&self) -> String

Serialize to the supercode-native lossless format: a header line recording the original source, followed by every original JSONL line verbatim. Unlike Self::to_jsonl (which targets a foreign tool’s schema and is necessarily lossy), this preserves everything — including records with no canonical representation — so Self::from_native_str reconstructs the session with full fidelity.

Source

pub fn from_native_str(jsonl: &str) -> Result<Session>

Parse the supercode-native format produced by Self::to_native_jsonl.

Source

pub fn from_codex_str(jsonl: &str) -> Result<Session>

Parse a Codex rollout from an in-memory JSONL string.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Session

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 Session

Source§

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

Formats the value using the given formatter. 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> 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> 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> 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