supercode-harness 0.4.4

The optional native Supercode agent and tool harness
Documentation
//! Cookbook 01 — the minimal agent.
//!
//! One prompt, one reply, streamed to stdout. This is the only example that
//! talks to a live model, so it needs an OpenRouter key:
//!
//! ```sh
//! export OPENROUTER_API_KEY=sk-or-...
//! cargo run -p supercode-harness --example 01_hello -- "Say hello in one word."
//! ```
//!
//! Without the key it prints how to set one and exits cleanly — so the example
//! always builds and runs.

use std::io::{self, Write};

use supercode_harness::{Agent, AgentEvent, Config};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let prompt = std::env::args()
        .nth(1)
        .unwrap_or_else(|| "Say hello in one word.".into());

    if std::env::var("OPENROUTER_API_KEY").is_err() {
        eprintln!("This example talks to a live model. Set a key first:");
        eprintln!("  export OPENROUTER_API_KEY=sk-or-...");
        eprintln!("Then: cargo run -p supercode-harness --example 01_hello -- \"<prompt>\"");
        return Ok(());
    }

    // Stream assistant text to the terminal as it arrives.
    let config = Config::builder()
        .model("anthropic/claude-opus-4-8")
        .event_sink(Box::new(|e: AgentEvent| {
            if let AgentEvent::TextDelta(t) = e {
                print!("{t}");
                io::stdout().flush().ok();
            }
        }))
        .build();

    let mut agent = Agent::new(config)?;
    agent.send(prompt).await?;
    println!();
    Ok(())
}