Skip to main content

rucora_tools/
lib.rs

1//! rucora-tools - rucora 内置工具集合
2//!
3//! 提供丰富的工具实现,包括文件操作、系统命令、Web 请求、搜索等功能。
4//!
5//! ## 模块结构
6//!
7//! - `file` - 文件操作工具(读、写、编辑)
8//! - `system` - 系统工具(Shell、命令执行、时间)
9//! - `web` - Web 工具(HTTP 请求、网页获取、搜索)
10//! - `search` - 搜索工具(Glob 搜索、内容搜索)
11//! - `math` - 数学工具(计算器)
12//! - `media` - 媒体工具(图片信息)
13//! - `memory` - 记忆工具
14//! - `basic` - 基础工具(回显等)
15//!
16//! ## 使用示例
17//!
18//! ```rust,no_run
19//! use rucora_tools::file::{FileReadTool, FileWriteTool};
20//! use rucora_tools::system::ShellTool;
21//! use rucora_tools::web::HttpRequestTool;
22//!
23//! // 使用工具...
24//! ```
25
26// ===== 核心模块(按功能分类)=====
27
28/// 文件操作工具模块
29///
30/// 提供安全的文件读写和编辑功能
31pub mod file;
32
33/// 系统工具模块
34///
35/// 提供系统命令执行、时间获取等功能
36pub mod system;
37
38/// Web 工具模块
39///
40/// 提供网页浏览、HTTP 请求、Web 搜索等功能
41pub mod web;
42
43/// 搜索工具模块
44///
45/// 提供文件搜索和内容搜索功能
46pub mod search;
47
48/// 数学工具模块
49///
50/// 提供高级数学计算功能
51pub mod math;
52
53/// 媒体处理工具模块
54///
55/// 提供图片信息读取等媒体处理功能
56pub mod media;
57
58/// 基础工具模块
59///
60/// 提供测试、调试等基础能力
61pub mod basic;
62
63/// 记忆工具模块
64///
65/// 提供长期记忆存储和检索能力
66pub mod memory;
67
68/// Git 工具兼容模块,建议使用 `system::git`。
69#[deprecated(since = "0.2.0", note = "请使用 `system::git` 模块代替")]
70pub mod git {
71    pub use crate::system::git::*;
72}
73
74/// Echo 工具兼容模块,建议使用 `basic::echo`。
75#[deprecated(since = "0.2.0", note = "请使用 `basic::echo` 模块代替")]
76pub mod echo {
77    pub use crate::basic::echo::*;
78}
79
80// ===== 向后兼容:保留顶层模块 =====
81
82/// 文件工具(向后兼容,建议使用 `file` 模块)
83#[deprecated(since = "0.2.0", note = "请使用 `file` 模块代替")]
84pub use file as file_legacy;
85
86/// Shell 工具(向后兼容,建议使用 `system` 模块)
87#[deprecated(since = "0.2.0", note = "请使用 `system` 模块代替")]
88pub use system as system_legacy;
89
90/// Web 工具(向后兼容,建议使用 `web` 模块)
91#[deprecated(since = "0.2.0", note = "请使用 `web` 模块代替")]
92pub use web as web_legacy;
93
94// ===== 重新导出常用工具类型 =====
95
96// 文件工具
97pub use file::{FileEditTool, FileReadTool, FileToolConfig, FileWriteTool};
98
99// 系统工具
100pub use system::{CmdExecTool, DatetimeTool, GitTool, ShellTool};
101
102// Web 工具
103pub use web::{
104    BrowseTool, BrowserOpenTool, GithubTrendingTool, HttpRequestTool, SerpapiTool, TavilyTool,
105    WebFetchTool,
106};
107
108// 搜索工具
109pub use search::{ContentSearchTool, GlobSearchTool};
110
111// 数学工具
112pub use math::CalculatorTool;
113
114// 媒体工具
115pub use media::ImageInfoTool;
116
117// 基础工具
118pub use basic::EchoTool;
119
120// 记忆工具
121pub use memory::{MemoryRecallTool, MemoryStoreTool};
122
123// 重新导出 ToolRegistry
124pub use rucora_core::tool::ToolRegistry;
125
126#[cfg(test)]
127mod tests {
128    use std::path::Path;
129
130    #[test]
131    fn src_root_contains_only_declared_entry_files() {
132        let src_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
133        let allowed_root_files = ["lib.rs"];
134
135        let unexpected_files = std::fs::read_dir(&src_dir)
136            .expect("应能读取 rucora-tools/src 目录")
137            .flatten()
138            .map(|entry| entry.path())
139            .filter(|path| path.is_file())
140            .filter(|path| path.extension().and_then(|ext| ext.to_str()) == Some("rs"))
141            .filter_map(|path| {
142                let file_name = path.file_name()?.to_str()?;
143                (!allowed_root_files.contains(&file_name)).then(|| file_name.to_string())
144            })
145            .collect::<Vec<_>>();
146
147        assert!(
148            unexpected_files.is_empty(),
149            "发现未归类或未挂载的根目录工具文件:{unexpected_files:?}"
150        );
151    }
152}