Skip to main content

pixie_pi/tools/
mod.rs

1//! Coding-agent tools (`packages/coding-agent`). The seven built-in tools plus
2//! preset tool sets.
3
4pub mod bash;
5pub mod edit;
6pub mod edit_diff;
7pub mod file_mutex;
8pub mod find;
9pub mod grep;
10pub mod ls;
11pub mod read;
12pub mod skill;
13pub mod truncate;
14pub mod util;
15pub mod write;
16
17use std::path::PathBuf;
18use std::sync::Arc;
19
20use crate::agent::tool::AgentTool;
21
22/// The full coding tool set: read, bash, edit, write (mirrors pi's
23/// `createCodingTools`).
24pub fn coding_tools(cwd: PathBuf) -> Vec<Arc<dyn AgentTool>> {
25    vec![
26        Arc::new(read::ReadTool { cwd: cwd.clone() }),
27        Arc::new(bash::BashTool { cwd: cwd.clone() }),
28        Arc::new(edit::EditTool { cwd: cwd.clone() }),
29        Arc::new(write::WriteTool { cwd: cwd.clone() }),
30    ]
31}
32
33/// Read-only tool set: read, grep, find, ls (mirrors `createReadOnlyTools`).
34pub fn read_only_tools(cwd: PathBuf) -> Vec<Arc<dyn AgentTool>> {
35    vec![
36        Arc::new(read::ReadTool { cwd: cwd.clone() }),
37        Arc::new(grep::GrepTool { cwd: cwd.clone() }),
38        Arc::new(find::FindTool { cwd: cwd.clone() }),
39        Arc::new(ls::LsTool { cwd }),
40    ]
41}
42
43/// All seven built-in tools.
44pub fn all_tools(cwd: PathBuf) -> Vec<Arc<dyn AgentTool>> {
45    vec![
46        Arc::new(read::ReadTool { cwd: cwd.clone() }),
47        Arc::new(bash::BashTool { cwd: cwd.clone() }),
48        Arc::new(edit::EditTool { cwd: cwd.clone() }),
49        Arc::new(write::WriteTool { cwd: cwd.clone() }),
50        Arc::new(grep::GrepTool { cwd: cwd.clone() }),
51        Arc::new(find::FindTool { cwd: cwd.clone() }),
52        Arc::new(ls::LsTool { cwd }),
53    ]
54}
55
56/// Names of all built-in tools.
57pub const BUILTIN_TOOL_NAMES: &[&str] = &["read", "bash", "edit", "write", "grep", "find", "ls"];
58
59/// Build a tool set from an allowlist of names.
60pub fn select_tools(cwd: PathBuf, names: &[String]) -> Vec<Arc<dyn AgentTool>> {
61    let all = all_tools(cwd);
62    all.into_iter()
63        .filter(|t| names.iter().any(|n| n == t.name()))
64        .collect()
65}