Skip to main content

bashkit_scripted_tool/
lib.rs

1//! ScriptedTool and the `ToolDef` layer for [bashkit](https://docs.rs/bashkit).
2//!
3//! Compose [`ToolDef`] + callback pairs into one LLM [`Tool`](bashkit::Tool)
4//! that accepts a bash script. Each registered tool becomes a command inside a
5//! logic-only shell, so a model can orchestrate many calls in one turn with
6//! pipes, variables, loops and `jq`.
7//!
8//! - [`ScriptedTool`]: the LLM tool. Build with [`ScriptedTool::builder`].
9//! - [`ScriptingToolSet`]: ScriptedTool plus optional discovery tool.
10//! - [`ToolRegistry`]: one set of tool definitions shared by the shell,
11//!   embedded Python and embedded TypeScript. Install into any
12//!   [`BashBuilder`](bashkit::BashBuilder) with [`ToolRegistry::install`].
13//! - [`ToolDefExtension`]: the shell surface alone, as a bashkit
14//!   [`Extension`](bashkit::Extension).
15//!
16//! ```rust
17//! use bashkit::Tool;
18//! use bashkit_scripted_tool::{ScriptedTool, ToolArgs, ToolDef};
19//!
20//! # tokio_test::block_on(async {
21//! let tool = ScriptedTool::builder("api")
22//!     .tool_fn(
23//!         ToolDef::new("greet", "Greet a user"),
24//!         |args: &ToolArgs| Ok(format!("hello {}\n", args.param_str("name").unwrap_or("world"))),
25//!     )
26//!     .build();
27//! let output = tool
28//!     .execution(serde_json::json!({"commands": "greet --name Alice"}))
29//!     .unwrap()
30//!     .execute()
31//!     .await
32//!     .unwrap();
33//! assert_eq!(output.result["stdout"], "hello Alice\n");
34//! # });
35//! ```
36//!
37//! Moved out of the `bashkit` crate (formerly feature `scripted_tool`). See
38//! `docs/migrating-scripted-tool.md` in the repository for the migration.
39
40mod scripted_tool;
41mod tool_def;
42mod tool_registry;
43
44pub use scripted_tool::{
45    AsyncToolCallback, AsyncToolExec, CallbackKind, DiscoverTool, DiscoveryMode,
46    ScriptedCommandInvocation, ScriptedCommandKind, ScriptedExecutionTrace, ScriptedTool,
47    ScriptedToolBuilder, ScriptingToolSet, ScriptingToolSetBuilder, SyncToolExec, ToolArgs,
48    ToolCallback, ToolDef, ToolDefExtension, ToolDefExtensionBuilder, ToolDefInvocationTrace,
49    ToolImpl,
50};
51pub use tool_registry::{
52    ToolCall, ToolCallDecision, ToolCallRequest, ToolCallSurface, ToolRegistry, ToolRegistryBuilder,
53};