blyte 0.93.0

The blyte coding-agent harness: headless runs with a sealed verification gate, and a REPL.
Documentation
use blyte_cli::cli::{apply_converse_defaults, Cli};
use blyte_cli::repl::{ReplConfig, ReplSession};
use blyte_cli::skill::SKILL_MD;
use clap::{CommandFactory, FromArgMatches};

#[test]
fn converse_sets_defaults() {
    let matches = Cli::command()
        .try_get_matches_from(["blyte", "--converse"])
        .unwrap();
    let mut cli = Cli::from_arg_matches(&matches).unwrap();
    apply_converse_defaults(&mut cli, &matches);
    assert_eq!(cli.max_turns, 1000);
    assert_eq!(cli.fold_budget, Some(100_000));
    assert_eq!(cli.context, "folded");
}

#[test]
fn explicit_flags_win() {
    let matches = Cli::command()
        .try_get_matches_from([
            "blyte",
            "--converse",
            "--max-turns",
            "30",
            "--fold-budget",
            "5000",
        ])
        .unwrap();
    let mut cli = Cli::from_arg_matches(&matches).unwrap();
    apply_converse_defaults(&mut cli, &matches);
    assert_eq!(cli.max_turns, 30);
    assert_eq!(cli.fold_budget, Some(5000));
}

#[test]
fn without_converse_nothing_changes() {
    let matches = Cli::command().try_get_matches_from(["blyte"]).unwrap();
    let mut cli = Cli::from_arg_matches(&matches).unwrap();
    apply_converse_defaults(&mut cli, &matches);
    assert_eq!(cli.max_turns, 25);
    assert_eq!(cli.fold_budget, None);
}

#[test]
fn converse_conflicts_with_gate() {
    let res = Cli::command().try_get_matches_from(["blyte", "--converse", "--gate", "true"]);
    assert!(res.is_err());
}

#[test]
fn converse_with_prompt_is_accepted() {
    let matches = Cli::command()
        .try_get_matches_from(["blyte", "--converse", "--", "plan the release"])
        .unwrap();
    let cli = Cli::from_arg_matches(&matches).unwrap();
    assert!(cli.converse);
    assert_eq!(cli.prompt.as_deref(), Some("plan the release"));
}

#[test]
fn dispatch_cmd_without_converse_is_rejected() {
    let res = Cli::command().try_get_matches_from(["blyte", "--dispatch-cmd", "echo test"]);
    assert!(res.is_err());
}

#[test]
fn dispatch_cmd_with_converse_is_accepted() {
    let matches = Cli::command()
        .try_get_matches_from([
            "blyte",
            "--converse",
            "--dispatch-cmd",
            "echo test",
            "--",
            "plan the release",
        ])
        .unwrap();
    let cli = Cli::from_arg_matches(&matches).unwrap();
    assert!(cli.converse);
    assert_eq!(cli.dispatch_cmd.as_deref(), Some("echo test"));
    assert_eq!(cli.prompt.as_deref(), Some("plan the release"));
}

#[test]
fn session_gets_instructions() {
    let tmp = tempfile::tempdir().unwrap();
    let config = ReplConfig {
        repo_root: tmp.path().to_path_buf(),
        converse: true,
        ..Default::default()
    };
    let session = ReplSession::new(&config);
    let instructions = session.state.brief.instructions.as_deref().unwrap();
    assert!(instructions.contains("## blyte reference"));
    assert!(instructions.contains(blyte_agent::conversation::ANSWERS_PERSON));
    assert!(instructions.contains("blyte wait"));

    let config_normal = ReplConfig {
        repo_root: tmp.path().to_path_buf(),
        converse: false,
        ..Default::default()
    };
    let session_normal = ReplSession::new(&config_normal);
    assert!(session_normal.state.brief.instructions.is_none());
}

#[test]
fn skill_tells_conversation_to_redirect_and_wait() {
    assert!(SKILL_MD.contains("Under `blyte --converse`"));
    assert!(SKILL_MD.contains("> /dev/null 2>&1 &"));
    assert!(SKILL_MD.contains("blyte wait --any"));
}

#[test]
fn old_orchestrate_flag_is_rejected_as_unexpected() {
    let out = std::process::Command::new(env!("CARGO_BIN_EXE_blyte"))
        .arg("--orchestrate")
        .output()
        .unwrap();
    assert!(!out.status.success());
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        stderr.contains("unexpected") && stderr.contains("--orchestrate"),
        "stderr: {stderr}"
    );
}