pub fn detect(path: &Path) -> Result<Format>Expand description
Detect the format of a session file by inspecting its content shape.
Content-based only — no file-extension sniffing, because agx tools in
the wild all use vanilla .json / .jsonl extensions regardless of
which agent CLI produced them.
Probe order (most specific first, so ambiguous shapes land on the right parser):
- Non-UTF-8 bytes →
Format::OtelProto(binary OTLP) - Single JSON with
resourceSpans→Format::OtelJson - Single JSON with
run_type+inputs/outputs→Format::Langchain - Single JSON with
finishReason/steps[].stepType/ camelCasetoolCallId→Format::VercelAi - Single JSON with
sessionId+messages→Format::Gemini - Single JSON with bare
messages→Format::Generic - JSONL first-line
typeinsession_meta/event_msg/response_item/turn_context→Format::Codex - Anything else →
Format::ClaudeCode
The ordering matters. For example, a Vercel AI SDK save has
messages at the top level (which would otherwise match Generic),
so the Vercel-specific markers (finishReason / stepType /
camelCase toolCallId) are checked first. Same story for LangChain
exports that happen to include a messages field under inputs.