Skip to main content

harn_hostlib/tools/
mod.rs

1//! Deterministic tools capability.
2//!
3//! Provides search (ripgrep via `grep-searcher` + `ignore`), file I/O,
4//! listing, file outline, git inspection, and
5//! process lifecycle (`run_command`, `wait_command`, `wait_command_output`, `run_test`,
6//! `run_build_command`, `inspect_test_results`, `manage_packages`,
7//! `cancel_handle`).
8//!
9//! Implementation status:
10//!
11//! | Method                  | Status                          |
12//! |-------------------------|---------------------------------|
13//! | `search`                | implemented                     |
14//! | `read_file`             | implemented                     |
15//! | `write_file`            | implemented                     |
16//! | `delete_file`           | implemented                     |
17//! | `list_directory`        | implemented                     |
18//! | `get_file_outline`      | implemented (regex extractor)   |
19//! | `git`                   | implemented (system git CLI)    |
20//! | `run_command`           | implemented                     |
21//! | `wait_command`          | implemented                     |
22//! | `wait_command_output`   | implemented                     |
23//! | `run_test`              | implemented                     |
24//! | `run_build_command`     | implemented                     |
25//! | `inspect_test_results`  | implemented                     |
26//! | `manage_packages`       | implemented                     |
27//! | `cancel_handle`         | implemented                     |
28//!
29use crate::registry::{BuiltinRegistry, HostlibCapability};
30
31pub(crate) mod args;
32mod cancel_handle;
33mod diagnostics;
34mod file_io;
35mod git;
36pub(crate) mod inspect_test_results;
37mod lang;
38mod list_handles;
39pub mod long_running;
40mod manage_packages;
41mod outline;
42pub(crate) mod payload;
43pub mod permissions;
44mod proc;
45mod read_command_output;
46mod response;
47mod run_build_command;
48mod run_command;
49pub(crate) use run_command::policy_blocked_response as policy_blocked_run_command_response;
50pub(crate) use run_command::request_is_background as run_command_request_is_background;
51pub(crate) mod run_test;
52mod search;
53mod test_parsers;
54mod toolchain_facts;
55mod wait_command;
56mod wait_command_output;
57
58/// Tools capability handle.
59#[derive(Default)]
60pub struct ToolsCapability;
61
62impl HostlibCapability for ToolsCapability {
63    fn module_name(&self) -> &'static str {
64        "tools"
65    }
66
67    fn register_builtins(&self, registry: &mut BuiltinRegistry) {
68        // Register the session-cleanup hook once per process so long-running
69        // tool handles are killed when the agent-loop session ends.
70        long_running::register_cleanup_hook();
71
72        registry.register_fn("tools", "hostlib_tools_search", "search", search::run);
73        registry.register_fn(
74            "tools",
75            "hostlib_tools_read_file",
76            "read_file",
77            file_io::read_file,
78        );
79        registry.register_fn(
80            "tools",
81            "hostlib_tools_write_file",
82            "write_file",
83            file_io::write_file,
84        );
85        registry.register_fn(
86            "tools",
87            "hostlib_tools_delete_file",
88            "delete_file",
89            file_io::delete_file,
90        );
91        registry.register_fn(
92            "tools",
93            "hostlib_tools_list_directory",
94            "list_directory",
95            file_io::list_directory,
96        );
97        registry.register_fn(
98            "tools",
99            "hostlib_tools_get_file_outline",
100            "get_file_outline",
101            outline::run,
102        );
103        registry.register_fn("tools", "hostlib_tools_git", "git", git::run);
104
105        registry.register_command_fn(
106            "tools",
107            "hostlib_tools_run_command",
108            "run_command",
109            run_command::handle,
110        );
111        registry.register_fn(
112            "tools",
113            read_command_output::NAME,
114            "read_command_output",
115            read_command_output::handle,
116        );
117        registry.register_fn(
118            "tools",
119            wait_command::NAME,
120            "wait_command",
121            wait_command::handle,
122        );
123        registry.register_async_fn(
124            "tools",
125            wait_command_output::NAME,
126            "wait_command_output",
127            wait_command_output::handle,
128        );
129        registry.register_fn(
130            "tools",
131            "hostlib_tools_run_test",
132            "run_test",
133            run_test::handle,
134        );
135        registry.register_fn(
136            "tools",
137            "hostlib_tools_run_build_command",
138            "run_build_command",
139            run_build_command::handle,
140        );
141        registry.register_fn(
142            "tools",
143            "hostlib_tools_inspect_test_results",
144            "inspect_test_results",
145            inspect_test_results::handle,
146        );
147        registry.register_fn(
148            "tools",
149            "hostlib_tools_manage_packages",
150            "manage_packages",
151            manage_packages::handle,
152        );
153        registry.register_fn(
154            "tools",
155            cancel_handle::NAME,
156            "cancel_handle",
157            cancel_handle::handle,
158        );
159        registry.register_fn(
160            "tools",
161            list_handles::NAME,
162            "list_handles",
163            list_handles::handle,
164        );
165        registry.register_fn(
166            "tools",
167            toolchain_facts::NAME,
168            "toolchain_facts",
169            toolchain_facts::handle,
170        );
171    }
172}