magi-code 0.96.1

Repository-aware CLI coding agent for terminal work
Documentation
#[cfg(test)]
mod cache;
mod code_mode;
mod replay;
mod replay_cache;
mod tokens;

#[cfg(test)]
pub(crate) use cache::conversation_cache_material;
#[cfg(test)]
pub(crate) use replay::build_conversation_replay;
pub(crate) use replay::{
    ConversationReplayLimits, REPLAY_JSONL_MAX_BYTES, REPLAY_JSONL_MAX_LINES,
    build_conversation_replay_from_events,
};
pub(crate) use replay_cache::ConversationReplayCache;
#[cfg(test)]
pub(crate) use replay_cache::ReplayCacheMetrics;
pub(crate) use tokens::estimate_text_tokens;
pub use tokens::{ContextBudget, ContextBudgetOverride};
pub(crate) use tokens::{
    ContextTokenCount, count_supported_provider_conversation_item_tokens,
    project_provider_conversation_items_tokens, project_provider_request_input_tokens,
    project_text_tokens, token_encoding_family_for_model,
};

use crate::sessions::{SessionEvent, SessionEventKind};
use serde_json::Value;
#[cfg(test)]
pub(crate) use serde_json::json;

pub(crate) fn is_local_only_session_event(event: &SessionEvent) -> bool {
    event.kind().is_some_and(SessionEventKind::is_local_only)
}

fn event_line(event: &SessionEvent) -> String {
    let compact_payload = if let Some(text) = event.payload.get("text").and_then(Value::as_str) {
        text.to_string()
    } else if let Some(message) = event.payload.get("message").and_then(Value::as_str) {
        message.to_string()
    } else {
        event.payload.to_string()
    };
    format!(
        "{}: {}",
        event.event_type,
        compact_payload.replace('\n', "\\n")
    )
}

pub(crate) fn canonical_json(value: &Value) -> String {
    serde_json::to_string(value).unwrap_or_else(|_| "null".to_string())
}

#[cfg(test)]
mod profiling;