GitCorner

Code

ossartcraftcraftanything🌐
642d5a256791
//! The list of every tool, by toolset: `cargo xtask tools` writes it to `docs/tools.md`, and a
//! test keeps the number of tools from ever dropping below [`MIN_TOOLS`].

use crate::registry::Registry;

/// Tools must never drop below this. Raise it when tools are added; never lower it.
pub const MIN_TOOLS: usize = 271;

/// The Markdown list written to `docs/tools.md`.
pub fn report(registry: &Registry) -> String {
    use std::fmt::Write as _;
    let mut out = String::new();
    let sets = registry.toolsets();
    let _ = writeln!(out, "# Tools\n\nGenerated by `cargo xtask tools`. Do not edit by hand.\n");
    let _ = writeln!(
        out,
        "**{} engine tools** in {} toolsets. Each is an MCP tool, a CLI command (`craft-anything-cli <id with dashes>`) and a tool the agent can call. The AI and setup layers add their own on top (`rebuild_*`, `assets_key_*`, `ai_models_list`, `ai_model_set`, `setup_*`); `craft-anything-cli commands` lists them all. [OpenCode model and thinking selection](opencode.md) describes the AI model tools.\n",
        registry.all().len(),
        sets.len()
    );
    for set in sets {
        let tools: Vec<_> = registry.all().iter().filter(|s| s.toolset == set).collect();
        if tools.is_empty() {
            continue;
        }
        let _ = writeln!(out, "## {} (`{}`, {})\n", set.title(), set.id(), tools.len());
        for s in tools {
            let _ = writeln!(out, "- `{}`: {}", s.id, s.title);
        }
        let _ = writeln!(out);
    }
    out
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn the_tool_count_never_drops() {
        let n = Registry::with_all_tools().all().len();
        assert!(n >= MIN_TOOLS, "there are {n} tools, fewer than {MIN_TOOLS}");
    }

    #[test]
    fn the_list_names_every_tool_once() {
        let r = Registry::with_all_tools();
        let text = report(&r);
        for s in r.all() {
            assert_eq!(text.matches(&format!("- `{}`:", s.id)).count(), 1, "{}", s.id);
        }
    }
}