1pub mod bash;
17pub mod delegate;
18pub mod finish_task;
19pub mod fs;
20pub mod registry;
21pub mod skill;
22pub mod traits;
23
24#[allow(unused_imports)]
26pub use bash::BashTool;
27#[allow(unused_imports)]
28pub use delegate::DelegateToAgentTool;
29pub use finish_task::{
30 FINISH_TASK_TOOL_NAME, FinishTaskArgs, FinishTaskTool, render_finish_summary,
31};
32pub use fs::{EditTool, ReadFileTool, WriteFileTool};
33pub use registry::ToolRegistry;
34pub use skill::{USE_SKILL_TOOL_NAME, UseSkillTool};
35pub use traits::{
36 AgentOutput, AgentRunner, HistoryMessage, RunContext, SearchProvider, SearchResult,
37 ServiceTier, SkillResolver, ToolExecutor, ToolResult,
38};
39
40#[cfg(test)]
43mod fs_registry_tests {
44 use std::sync::Arc;
45
46 use serde_json::json;
47
48 use super::{EditTool, ReadFileTool, ToolRegistry, WriteFileTool};
49
50 #[tokio::test]
58 async fn fs_tools_register_and_appear_in_schemas() {
59 let tmp = tempfile::tempdir().expect("tempdir");
60 let mut reg = ToolRegistry::new();
61 reg.register(Arc::new(ReadFileTool::new(tmp.path())));
62 reg.register(Arc::new(WriteFileTool::new(tmp.path())));
63 reg.register(Arc::new(EditTool::new(tmp.path())));
64
65 assert!(reg.contains("read_file"), "read_file must be registered");
66 assert!(reg.contains("write_file"), "write_file must be registered");
67 assert!(reg.contains("edit"), "edit must be registered");
68
69 let schemas = reg.schemas();
70 assert_eq!(schemas.len(), 3, "exactly three tools");
71
72 let names: Vec<&str> = schemas
73 .iter()
74 .filter_map(|s| s["function"]["name"].as_str())
75 .collect();
76 assert!(names.contains(&"read_file"));
77 assert!(names.contains(&"write_file"));
78 assert!(names.contains(&"edit"));
79 }
80
81 #[tokio::test]
87 async fn dispatch_gated_routes_write_file() {
88 let tmp = tempfile::tempdir().expect("tempdir");
89 let mut reg = ToolRegistry::new();
90 reg.register(Arc::new(WriteFileTool::new(tmp.path())));
91
92 let result = reg
93 .dispatch_gated(
94 "write_file",
95 json!({"path": "via_registry.txt", "content": "registry dispatch test"}),
96 None,
97 )
98 .await;
99
100 assert!(
101 !result.is_error(),
102 "dispatch should succeed: {}",
103 result.content()
104 );
105 let content = std::fs::read_to_string(tmp.path().join("via_registry.txt")).expect("read");
106 assert_eq!(content, "registry dispatch test");
107 }
108
109 #[tokio::test]
115 async fn dispatch_gated_routes_read_file() {
116 let tmp = tempfile::tempdir().expect("tempdir");
117 std::fs::write(tmp.path().join("test.txt"), "hello from registry").expect("seed");
118
119 let mut reg = ToolRegistry::new();
120 reg.register(Arc::new(ReadFileTool::new(tmp.path())));
121
122 let result = reg
123 .dispatch_gated("read_file", json!({"path": "test.txt"}), None)
124 .await;
125
126 assert!(
127 !result.is_error(),
128 "dispatch should succeed: {}",
129 result.content()
130 );
131 assert!(result.content().contains("hello from registry"));
132 }
133
134 #[tokio::test]
140 async fn dispatch_gated_routes_edit() {
141 let tmp = tempfile::tempdir().expect("tempdir");
142 std::fs::write(tmp.path().join("target.py"), "x = 0\n").expect("seed");
143
144 let mut reg = ToolRegistry::new();
145 reg.register(Arc::new(EditTool::new(tmp.path())));
146
147 let result = reg
148 .dispatch_gated(
149 "edit",
150 json!({"path": "target.py", "old_string": "x = 0", "new_string": "x = 99"}),
151 None,
152 )
153 .await;
154
155 assert!(
156 !result.is_error(),
157 "dispatch should succeed: {}",
158 result.content()
159 );
160 let content = std::fs::read_to_string(tmp.path().join("target.py")).expect("read");
161 assert!(content.contains("x = 99"));
162 }
163}