supercode-harness 0.4.4

The optional native Supercode agent and tool harness
Documentation
//! Machine-readable measured translation fidelity over committed fixtures.

use std::collections::BTreeSet;
use std::path::{Path, PathBuf};

use serde_json::{json, Value};
use supercode_harness::{
    core_messages, harness_support_registry, measure_fidelity, HarnessId, ImplementationKind,
    Session, SessionFormat,
};

const FORMATS: [(&str, SessionFormat, &str); 7] = [
    (
        HarnessId::CLAUDE_CODE,
        SessionFormat::ClaudeCode,
        "claude_code_session.jsonl",
    ),
    (
        HarnessId::CODEX,
        SessionFormat::Codex,
        "codex_session.jsonl",
    ),
    (
        HarnessId::OPENCODE,
        SessionFormat::OpenCode,
        "opencode_session.jsonl",
    ),
    (HarnessId::PI, SessionFormat::Pi, "pi_session.jsonl"),
    (
        HarnessId::GROK,
        SessionFormat::Grok,
        "grok_session/chat_history.jsonl",
    ),
    (
        HarnessId::GEMINI,
        SessionFormat::Gemini,
        "gemini_session.jsonl",
    ),
    (HarnessId::GOOSE, SessionFormat::Goose, "goose_session.json"),
];

fn fixture(name: &str) -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests/fixtures")
        .join(name)
}

fn load(format: SessionFormat, file: &str) -> Session {
    let path = fixture(file);
    match format {
        SessionFormat::ClaudeCode => Session::from_claude_code(path),
        SessionFormat::Codex => Session::from_codex(path),
        SessionFormat::OpenCode => Session::from_opencode(path),
        SessionFormat::Pi => Session::from_pi(path),
        SessionFormat::Grok => Session::from_grok(path),
        SessionFormat::Gemini => Session::from_gemini(path),
        SessionFormat::Goose => Session::from_goose(path),
    }
    .expect("committed fidelity fixture loads")
}

fn main() {
    let native_registry = harness_support_registry()
        .harnesses
        .into_iter()
        .filter(|harness| {
            harness.id.as_str() != HarnessId::SUPERCODE
                && harness.native.load != ImplementationKind::Absent
        })
        .map(|harness| harness.id.0)
        .collect::<BTreeSet<_>>();
    let fixture_formats = FORMATS
        .iter()
        .map(|(id, _, _)| (*id).to_owned())
        .collect::<BTreeSet<_>>();
    assert_eq!(
        fixture_formats, native_registry,
        "every native registry format needs exactly one fidelity fixture mapping"
    );
    let sessions = FORMATS
        .iter()
        .map(|(id, format, file)| (*id, *format, load(*format, file)))
        .collect::<Vec<_>>();
    let mut cells = Vec::<Value>::new();
    for (source_id, _source_format, source) in &sessions {
        let source_messages = core_messages(&source.messages);
        for (target_id, target_format, _) in &sessions {
            let encoded = source
                .to_jsonl(*target_format)
                .expect("committed fixture exports");
            let reloaded = Session::load_str(&encoded, *target_format)
                .expect("exported committed fixture reloads");
            let metric = measure_fidelity(&source_messages, &core_messages(&reloaded.messages));
            cells.push(json!({
                "source": source_id,
                "target": target_id,
                "status": "measured",
                "matched": metric.matched,
                "total": metric.total,
                "percent": metric.percent(),
                "semantic_lossless": metric.is_semantically_lossless(),
                "residue": metric.residue,
            }));
        }
    }
    println!(
        "{}",
        serde_json::to_string_pretty(&json!({
            "schema": "supercode.fidelity-probe.v1",
            "scope": "committed-fixtures",
            "goal": "zero replay-eligible message loss and zero dropped metadata keys",
            "cells": cells,
        }))
        .expect("serialize fidelity probe")
    );
}