supercode-harness 0.4.4

The optional native Supercode agent and tool harness
Documentation
//! Cookbook 05 — load one format, save another (the "GIMP" trick), offline.
//!
//! supercode treats Claude Code and Codex transcripts like image formats: load
//! either, save as either. This example synthesizes a tiny Claude Code session,
//! loads it through the typed schema, and re-saves it as a Codex rollout.
//!
//! ```sh
//! cargo run -p supercode-harness --example 05_convert_session
//! ```

use supercode_harness::session::{Session, SessionFormat};

// A minimal but real Claude Code JSONL transcript (two linked messages).
const CLAUDE_JSONL: &str = r#"{"type":"user","uuid":"u1","parentUuid":null,"sessionId":"demo","cwd":"/tmp","message":{"role":"user","content":"What is 2+2?"}}
{"type":"assistant","uuid":"a1","parentUuid":"u1","sessionId":"demo","message":{"role":"assistant","content":[{"type":"text","text":"4."}]}}"#;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let session = Session::load_str(CLAUDE_JSONL, SessionFormat::ClaudeCode)?;
    println!(
        "loaded {:?} session: {} messages",
        session.meta.source,
        session.messages.len()
    );

    let codex = session.to_jsonl(SessionFormat::Codex).unwrap();
    println!("\n--- re-saved as Codex rollout ---\n{codex}");

    // Round-trip sanity: the Codex output reloads and keeps both turns.
    let reloaded = Session::load_str(&codex, SessionFormat::Codex)?;
    assert_eq!(reloaded.messages.len(), session.messages.len());
    println!("✓ round-tripped Claude Code → Codex with both turns intact");
    Ok(())
}