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: SessionMetaRecovered 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
impl Session
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Session>
pub fn load(path: impl AsRef<Path>) -> Result<Session>
Load a session, auto-detecting whether it’s a Claude Code or Codex log.
Sourcepub fn from_claude_code(path: impl AsRef<Path>) -> Result<Session>
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.
Sourcepub fn from_claude_code_str(jsonl: &str) -> Result<Session>
pub fn from_claude_code_str(jsonl: &str) -> Result<Session>
Parse a Claude Code transcript from an in-memory JSONL string.
Sourcepub fn reconstruct_tree(sessions: Vec<Session>) -> Vec<Session>
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).
Sourcepub fn load_str(jsonl: &str, format: SessionFormat) -> Result<Session>
pub fn load_str(jsonl: &str, format: SessionFormat) -> Result<Session>
Parse a session of a known format from an in-memory JSONL string.
Sourcepub fn to_jsonl(&self, format: SessionFormat) -> String
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.
Sourcepub fn save(&self, path: impl AsRef<Path>, format: SessionFormat) -> Result<()>
pub fn save(&self, path: impl AsRef<Path>, format: SessionFormat) -> Result<()>
Write this session to path in the given format.
Sourcepub fn to_native_jsonl(&self) -> String
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.
Sourcepub fn from_native_str(jsonl: &str) -> Result<Session>
pub fn from_native_str(jsonl: &str) -> Result<Session>
Parse the supercode-native format produced by Self::to_native_jsonl.
Sourcepub fn from_codex_str(jsonl: &str) -> Result<Session>
pub fn from_codex_str(jsonl: &str) -> Result<Session>
Parse a Codex rollout from an in-memory JSONL string.