1pub mod bash;
34pub mod checklist;
35pub mod delegate;
36pub mod finish_task;
37pub mod fs;
38pub mod goals;
39pub mod recall_session;
40pub mod registry;
41pub mod skill;
42pub mod telemetry;
43pub mod traits;
44pub mod trusty_search;
45
46#[allow(unused_imports)]
48pub use bash::{BASH_TOOL_NAME, BashTool};
49pub use checklist::{MAX_TODOS, TODO_WRITE_TOOL_NAME, TodoError, TodoStore, TodoWriteTool};
51#[allow(unused_imports)]
52pub use delegate::{DELEGATE_TO_AGENT_TOOL_NAME, DelegateToAgentTool, EngineerCompletionSignal};
53pub use finish_task::{
54 FINISH_TASK_TOOL_NAME, FinishStatus, FinishTaskArgs, FinishTaskTool, render_finish_summary,
55};
56pub use fs::{
57 EditTool, GlobTool, GrepTool, ListDirTool, ReadFileTool, WRITE_FILES_TOOL_NAME, WriteFileTool,
58 WriteFilesTool,
59};
60pub use goals::{CLEAR_GOAL_TOOL_NAME, ClearGoalTool, SET_GOAL_TOOL_NAME, SetGoalTool};
61pub use recall_session::{RECALL_SESSION_TOOL_NAME, RecallSessionTool};
62pub use registry::ToolRegistry;
63pub use skill::{USE_SKILL_TOOL_NAME, UseSkillTool};
64pub use telemetry::{RecallTelemetry, SearchTelemetry, ToolTelemetry};
65pub use traits::{
66 AgentOutput, AgentRunner, HistoryMessage, RunContext, SearchProvider, SearchResult,
67 ServiceTier, SkillResolver, ToolExecutor, ToolResult,
68};
69pub use trusty_search::{SEARCH_CODE_TOOL_NAME, TrustySearchTool};
70
71#[cfg(test)]
74mod fs_registry_tests {
75 use std::sync::Arc;
76
77 use serde_json::json;
78
79 use super::{EditTool, ReadFileTool, ToolRegistry, WriteFileTool};
80
81 #[tokio::test]
89 async fn fs_tools_register_and_appear_in_schemas() {
90 let tmp = tempfile::tempdir().expect("tempdir");
91 let mut reg = ToolRegistry::new();
92 reg.register(Arc::new(ReadFileTool::new(tmp.path())));
93 reg.register(Arc::new(WriteFileTool::new(tmp.path())));
94 reg.register(Arc::new(EditTool::new(tmp.path())));
95
96 assert!(reg.contains("read_file"), "read_file must be registered");
97 assert!(reg.contains("write_file"), "write_file must be registered");
98 assert!(reg.contains("edit"), "edit must be registered");
99
100 let schemas = reg.schemas();
101 assert_eq!(schemas.len(), 3, "exactly three tools");
102
103 let names: Vec<&str> = schemas
104 .iter()
105 .filter_map(|s| s["function"]["name"].as_str())
106 .collect();
107 assert!(names.contains(&"read_file"));
108 assert!(names.contains(&"write_file"));
109 assert!(names.contains(&"edit"));
110 }
111
112 #[tokio::test]
118 async fn dispatch_gated_routes_write_file() {
119 let tmp = tempfile::tempdir().expect("tempdir");
120 let mut reg = ToolRegistry::new();
121 reg.register(Arc::new(WriteFileTool::new(tmp.path())));
122
123 let result = reg
124 .dispatch_gated(
125 "write_file",
126 json!({"path": "via_registry.txt", "content": "registry dispatch test"}),
127 None,
128 )
129 .await;
130
131 assert!(
132 !result.is_error(),
133 "dispatch should succeed: {}",
134 result.content()
135 );
136 let content = std::fs::read_to_string(tmp.path().join("via_registry.txt")).expect("read");
137 assert_eq!(content, "registry dispatch test");
138 }
139
140 #[tokio::test]
146 async fn dispatch_gated_routes_read_file() {
147 let tmp = tempfile::tempdir().expect("tempdir");
148 std::fs::write(tmp.path().join("test.txt"), "hello from registry").expect("seed");
149
150 let mut reg = ToolRegistry::new();
151 reg.register(Arc::new(ReadFileTool::new(tmp.path())));
152
153 let result = reg
154 .dispatch_gated("read_file", json!({"path": "test.txt"}), None)
155 .await;
156
157 assert!(
158 !result.is_error(),
159 "dispatch should succeed: {}",
160 result.content()
161 );
162 assert!(result.content().contains("hello from registry"));
163 }
164
165 #[tokio::test]
171 async fn dispatch_gated_routes_edit() {
172 let tmp = tempfile::tempdir().expect("tempdir");
173 std::fs::write(tmp.path().join("target.py"), "x = 0\n").expect("seed");
174
175 let mut reg = ToolRegistry::new();
176 reg.register(Arc::new(EditTool::new(tmp.path())));
177
178 let result = reg
179 .dispatch_gated(
180 "edit",
181 json!({"path": "target.py", "old_string": "x = 0", "new_string": "x = 99"}),
182 None,
183 )
184 .await;
185
186 assert!(
187 !result.is_error(),
188 "dispatch should succeed: {}",
189 result.content()
190 );
191 let content = std::fs::read_to_string(tmp.path().join("target.py")).expect("read");
192 assert!(content.contains("x = 99"));
193 }
194}