Skip to main content

Crate normalize_chat_sessions

Crate normalize_chat_sessions 

Source
Expand description

Session log parsing for AI coding agents.

Parses session logs from various AI coding agents:

  • Claude Code (JSONL)
  • Gemini CLI (JSON)
  • OpenAI Codex CLI (JSONL)
  • Normalize Agent (JSONL)

§Architecture

This crate separates parsing from analysis:

  • Parsing: LogFormat::parse() converts format-specific logs into a unified Session type
  • Analysis: Consumers compute their own metrics from Session data

Each log format implements the LogFormat trait for format detection and parsing.

§Example

use normalize_chat_sessions::{parse_session, Session};

let session = parse_session("~/.claude/projects/foo/session.jsonl")?;
for turn in &session.turns {
    for msg in &turn.messages {
        println!("{}: {} blocks", msg.role, msg.content.len());
    }
}

Structs§

ClaudeCodeFormat
Claude Code session log format (JSONL).
CodexFormat
OpenAI Codex CLI session log format (JSONL).
FormatRegistry
Registry of available log formats.
GeminiCliFormat
Gemini CLI session log format (JSON with messages array).
Message
A message from a participant.
NormalizeAgentFormat
Normalize agent session log format (JSONL).
Session
A parsed session in unified format.
SessionFile
Session file with metadata.
SessionMetadata
Session metadata extracted from the log.
TokenUsage
Token usage for an API call.
Turn
A single turn in the conversation (typically one user message + assistant response).

Enums§

ContentBlock
A content block within a message.
ParseError
Error type for session log parsing operations.
Role
Message sender role.

Traits§

LogFormat
Trait for session log format plugins.

Functions§

detect_format
Auto-detect format for a file using the global registry.
get_format
Get a format by name from the global registry.
list_formats
List all available format names from the global registry.
list_jsonl_sessions
Default implementation: list .jsonl files in a directory.
list_subagent_sessions
List subagent sessions from <session-uuid>/subagents/ directories.
parse_session
Parse a session log with auto-format detection.
parse_session_with_format
Parse a session log with explicit format.
project_metadata_roots
Returns all external metadata directories for the given project across all known formats.
register
Register a custom log format plugin.