Skip to main content

matrixcode_core/tools/
mod.rs

1pub mod ask;
2pub mod bash;
3pub mod edit;
4pub mod glob;
5pub mod ls;
6pub mod multi_edit;
7pub mod read;
8pub mod search;
9pub mod skill;
10pub mod todo_write;
11pub mod webfetch;
12pub mod websearch;
13pub mod write;
14
15use std::sync::Arc;
16
17use anyhow::Result;
18use async_trait::async_trait;
19use serde::{Deserialize, Serialize};
20use serde_json::Value;
21
22use crate::approval::RiskLevel;
23use crate::skills::Skill;
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct ToolDefinition {
27    pub name: String,
28    pub description: String,
29    pub parameters: Value,
30}
31
32#[async_trait]
33pub trait Tool: Send + Sync {
34    fn definition(&self) -> ToolDefinition;
35    async fn execute(&self, params: Value) -> Result<String>;
36
37    /// Risk level of this tool. Defaults to Safe (read-only).
38    /// Override in tools that modify state.
39    fn risk_level(&self) -> RiskLevel {
40        RiskLevel::Safe
41    }
42}
43
44/// Default toolset without any skill integration. Kept for callers
45/// (and the existing tests) that don't care about skills.
46pub fn all_tools() -> Vec<Box<dyn Tool>> {
47    all_tools_with_skills(Arc::new(Vec::new()))
48}
49
50/// Build the toolset and include the `skill` tool bound to the given
51/// skills catalogue. The catalogue can be empty; the tool still works
52/// but will only report "no skills loaded" if invoked.
53pub fn all_tools_with_skills(skills: Arc<Vec<Skill>>) -> Vec<Box<dyn Tool>> {
54    vec![
55        Box::new(ask::AskTool),
56        Box::new(read::ReadTool),
57        Box::new(write::WriteTool),
58        Box::new(edit::EditTool),
59        Box::new(multi_edit::MultiEditTool),
60        Box::new(search::SearchTool),
61        Box::new(glob::GlobTool),
62        Box::new(ls::LsTool),
63        Box::new(bash::BashTool),
64        Box::new(todo_write::TodoWriteTool),
65        Box::new(websearch::WebSearchTool),
66        Box::new(webfetch::WebFetchTool),
67        Box::new(skill::SkillTool::new(skills)),
68    ]
69}