blyte 0.72.0

The blyte coding-agent harness: headless runs with a sealed verification gate, and a REPL.
Documentation
//! `blyte skill install --default` makes delegating to blyte Claude Code's default through a
//! marked CLAUDE.md block; `uninstall` removes it. The skill teaches parallel dispatch
//! (2026-09-27).

use std::path::Path;
use std::process::Command;

use blyte_cli::skill::{remove_default_block, set_default_block, DEFAULT_BLOCK, SKILL_MD};

fn blyte(cwd: &Path, home: &Path, args: &[&str]) -> std::process::Output {
    Command::new(env!("CARGO_BIN_EXE_blyte"))
        .args(args)
        .current_dir(cwd)
        .env("HOME", home)
        .env("XDG_CONFIG_HOME", home)
        .output()
        .unwrap()
}

#[test]
fn the_block_is_appended_once_and_replaced_in_place() {
    assert_eq!(set_default_block(""), format!("{DEFAULT_BLOCK}\n"));
    let once = set_default_block("# Me\n\nMy rules.\n");
    assert_eq!(once, format!("# Me\n\nMy rules.\n\n{DEFAULT_BLOCK}\n"));
    assert_eq!(set_default_block(&once), once, "idempotent");
    let stale = "# Me\n\n<!-- blyte:default -->\nold text\n<!-- /blyte:default -->\n\n## After\n";
    let fixed = set_default_block(stale);
    assert!(
        fixed.contains(DEFAULT_BLOCK) && !fixed.contains("old text"),
        "{fixed}"
    );
    assert!(fixed.contains("## After"), "{fixed}");
    assert_eq!(remove_default_block(&once), "# Me\n\nMy rules.\n");
    assert_eq!(remove_default_block("# Me\n"), "# Me\n");
}

#[test]
fn install_default_writes_claude_md_and_uninstall_removes_both() {
    let home = tempfile::tempdir().unwrap();
    let cwd = tempfile::tempdir().unwrap();
    let md = home.path().join(".claude/CLAUDE.md");
    std::fs::create_dir_all(md.parent().unwrap()).unwrap();
    std::fs::write(&md, "# My rules\n").unwrap();

    let out = blyte(cwd.path(), home.path(), &["skill", "install", "--default"]);
    assert_eq!(
        out.status.code(),
        Some(0),
        "{}",
        String::from_utf8_lossy(&out.stderr)
    );
    assert!(String::from_utf8_lossy(&out.stdout).contains("updated"));
    let text = std::fs::read_to_string(&md).unwrap();
    assert!(
        text.starts_with("# My rules\n") && text.contains(DEFAULT_BLOCK),
        "{text}"
    );

    let out = blyte(cwd.path(), home.path(), &["skill", "uninstall"]);
    assert_eq!(
        out.status.code(),
        Some(0),
        "{}",
        String::from_utf8_lossy(&out.stderr)
    );
    assert_eq!(std::fs::read_to_string(&md).unwrap(), "# My rules\n");
    assert!(!home
        .path()
        .join(".claude/skills/blyte-implementer/SKILL.md")
        .exists());
    let again = blyte(cwd.path(), home.path(), &["skill", "uninstall"]);
    assert_eq!(again.status.code(), Some(0));
}

#[test]
fn install_with_no_default_leaves_claude_md_alone() {
    let home = tempfile::tempdir().unwrap();
    let cwd = tempfile::tempdir().unwrap();
    assert_eq!(
        blyte(
            cwd.path(),
            home.path(),
            &["skill", "install", "--no-default"]
        )
        .status
        .code(),
        Some(0)
    );
    assert!(!home.path().join(".claude/CLAUDE.md").exists());
}

#[test]
fn the_skill_is_a_default_and_teaches_parallel_dispatch() {
    assert!(
        SKILL_MD.contains("description: Use by default"),
        "description must trigger by default"
    );
    for s in ["in parallel", "Siblings", "wait", "rebase", "--base wip/T1"] {
        assert!(SKILL_MD.contains(s), "{s} missing");
    }
}

#[test]
fn install_with_no_default_removes_an_earlier_default_block() {
    // Switching from "on" to "only when asked" must not need an uninstall first (2026-09-30).
    let home = tempfile::tempdir().unwrap();
    let cwd = tempfile::tempdir().unwrap();
    let md = home.path().join(".claude/CLAUDE.md");
    std::fs::create_dir_all(md.parent().unwrap()).unwrap();
    std::fs::write(&md, "# My rules\n").unwrap();
    assert_eq!(
        blyte(cwd.path(), home.path(), &["skill", "install"])
            .status
            .code(),
        Some(0)
    );
    assert!(std::fs::read_to_string(&md)
        .unwrap()
        .contains(DEFAULT_BLOCK));

    let out = blyte(
        cwd.path(),
        home.path(),
        &["skill", "install", "--no-default"],
    );
    assert_eq!(
        out.status.code(),
        Some(0),
        "{}",
        String::from_utf8_lossy(&out.stderr)
    );
    let text = std::fs::read_to_string(&md).unwrap();
    assert!(!text.contains(DEFAULT_BLOCK));
    assert_eq!(
        blyte_cli::skill::remove_block(&text, blyte_cli::skill::CONTEXT_BLOCK),
        "# My rules\n"
    );
    assert!(home
        .path()
        .join(".claude/skills/blyte-implementer/SKILL.md")
        .exists());
}

#[test]
fn install_force_replaces_an_existing_default_block_with_the_new_worktree_rule() {
    for line in DEFAULT_BLOCK.lines() {
        assert!(
            line.chars().count() < 100,
            "line >= 100 chars ({}): {line}",
            line.chars().count()
        );
    }
    assert!(
        DEFAULT_BLOCK.contains(
            "Worktrees of your own (not blyte runs) go inside the repository at `.wt/plan-<topic>`"
        ),
        "{DEFAULT_BLOCK}"
    );
    assert!(
        DEFAULT_BLOCK.contains("git worktree add .wt/plan-<topic> -b <branch> origin/<default>"),
        "{DEFAULT_BLOCK}"
    );

    let home = tempfile::tempdir().unwrap();
    let cwd = tempfile::tempdir().unwrap();
    let md = home.path().join(".claude/CLAUDE.md");
    let skill = home
        .path()
        .join(".claude/skills/blyte-implementer/SKILL.md");
    std::fs::create_dir_all(skill.parent().unwrap()).unwrap();
    std::fs::write(&skill, "older skill\n").unwrap();
    std::fs::write(
        &md,
        "# My rules\n\n<!-- blyte:default -->\n## Implementation: delegate to blyte, in parallel\n\nold paragraph only\n<!-- /blyte:default -->\n\n## After\n",
    )
    .unwrap();

    let out = blyte(cwd.path(), home.path(), &["skill", "install", "--force"]);
    assert_eq!(
        out.status.code(),
        Some(0),
        "{}",
        String::from_utf8_lossy(&out.stderr)
    );
    let text = std::fs::read_to_string(&md).unwrap();
    assert!(text.contains(DEFAULT_BLOCK), "{text}");
    assert!(!text.contains("old paragraph only"), "{text}");
    assert!(text.contains("## After"), "{text}");
}