oino_tools/lib.rs
1//! `oino-tools`: the built-in tools — `read`, `write`, `edit`, `bash`, `grep`, `find`,
2//! `ls` and (Windows) `powershell` — with fixed names, schemas, descriptions, prompt text,
3//! error strings, truncation footers and `details` shapes.
4//!
5//! Tools implement [`oino_agent::AgentTool`]; `oino-core` builds them from a [`ToolConfig`]
6//! (cwd, agent dir, [`ExecutionEnv`], live [`ToolContext`], image and shell options) and uses
7//! [`BuiltinToolInfo`] for the system prompt. Temp files go to `<agent>/tmp/oino-bash-*.log`;
8//! the shell environment is D12.
9//!
10//! # API map
11//!
12//! | Module | Contents |
13//! |---|---|
14//! | [`registry`] | [`builtin_tools`], [`coding_tools`], [`read_only_tools`], [`create_tool`], [`tool_by_name`] |
15//! | [`info`] | [`BuiltinToolName`], [`BuiltinToolInfo`], [`DEFAULT_ACTIVE_TOOLS`] |
16//! | [`config`] | [`ToolConfig`], [`ToolContext`], [`SessionEnv`], [`ImageOptions`], [`ShellOptions`] |
17//! | [`mod@env`] | [`ExecutionEnv`], [`LocalEnv`], [`SpawnedProcess`], [`FsError`] |
18//! | [`read`] | [`ReadTool`], [`read::block_images`] |
19//! | [`mod@write`] | [`WriteTool`] |
20//! | [`edit`] | [`EditTool`], [`edit::prepare_edit_arguments`] |
21//! | [`bash`] | [`ShellTool`], [`BashDetachRegistry`], [`run_shell_command`], [`bash::resolve_shell_config`] |
22//! | [`grep`], [`find`], [`ls`] | [`GrepTool`], [`FindTool`], [`LsTool`] |
23//! | [`truncate`] | [`truncate::truncate_head`], [`truncate::truncate_tail`], [`truncate::truncate_line`], [`truncate::format_size`] |
24//! | [`path_utils`] | [`path_utils::expand_path`], [`path_utils::resolve_to_cwd`], [`path_utils::resolve_read_path`] |
25//! | [`mutation_queue`] | [`FileMutationQueue`] |
26//! | [`image`] | [`image::process_image`], [`image::detect_supported_image_mime_type`] |
27
28#![forbid(unsafe_code)]
29#![cfg_attr(
30 test,
31 allow(
32 clippy::unwrap_used,
33 clippy::expect_used,
34 clippy::panic,
35 reason = "tests assert by unwrapping"
36 )
37)]
38
39mod args;
40pub mod bash;
41mod collate;
42pub mod config;
43pub mod edit;
44pub mod env;
45pub mod find;
46pub mod grep;
47pub mod image;
48pub mod info;
49mod js;
50pub mod ls;
51pub mod mutation_queue;
52mod node_path;
53pub mod path_utils;
54pub mod read;
55pub mod registry;
56pub mod truncate;
57pub mod write;
58
59pub use bash::{
60 BashDetachRegistry, BashOutcome, DetachedProcess, ShellRunOptions, ShellTool, run_shell_command,
61};
62pub use config::{
63 ImageOptions, ModelImageInfo, NoContext, SessionEnv, ShellOptions, ToolConfig, ToolContext,
64};
65pub use edit::EditTool;
66pub use env::{ExecutionEnv, FsError, LocalEnv, SpawnedProcess};
67pub use find::FindTool;
68pub use grep::GrepTool;
69pub use info::{
70 BuiltinToolInfo, BuiltinToolName, DEFAULT_ACTIVE_TOOLS, READ_ONLY_TOOLS, builtin_tool_info,
71};
72pub use ls::LsTool;
73pub use mutation_queue::FileMutationQueue;
74pub use read::ReadTool;
75pub use registry::{
76 builtin_tool_infos, builtin_tools, coding_tools, create_tool, read_only_tools, tool_by_name,
77};
78pub use write::WriteTool;
79
80/// The abort error text.
81pub const OPERATION_ABORTED: &str = "Operation aborted";
82
83fn aborted() -> oino_agent::ToolError {
84 oino_agent::ToolError::new(OPERATION_ABORTED)
85}
86
87/// A JSON number as JavaScript serialises it (whole numbers without a fraction).
88fn js_number(value: f64) -> oino_ai::JsonValue {
89 if value.fract() == 0.0 && value.abs() < 9_007_199_254_740_992.0 {
90 #[allow(
91 clippy::cast_possible_truncation,
92 reason = "whole and within the safe integer range"
93 )]
94 let whole = value as i64;
95 serde_json::json!(whole)
96 } else {
97 serde_json::json!(value)
98 }
99}