aidaemon-tools 0.27.3

Ready-made tools for aidaemon agents (files, search, sandboxed shell, web, checklist); implementation crate of the aidaemon SDK, no stability promise (use it through aidaemon-sdk)
Documentation
//! # aidaemon-tools (experimental)
//!
//! A small default tool set for [`aidaemon_core`] agents, built on lessons
//! from agent-computer interfaces (SWE-agent, Claude Code, Aider): few
//! non-overlapping tools, bounded output, actionable errors, and validation
//! before mutation.
//!
//! | Tool | Name | Annotations |
//! |---|---|---|
//! | [`ReadFile`] | `read_file` | read-only |
//! | [`WriteFile`] | `write_file` | write (idempotent) |
//! | [`EditFile`] | `edit_file` | write |
//! | [`Glob`] | `glob` | read-only |
//! | [`Grep`] | `grep` | read-only |
//! | [`Shell`] | `shell` | destructive |
//! | [`WebFetch`] | `web_fetch` | read-only |
//! | [`Checklist`] | `track_requirements` | write (agent state only) |
//!
//! Every file tool is confined to a [`Workspace`]. The shell runs through a
//! [`Sandbox`]; containment (sandboxing) lives there, while approval
//! stays a policy concern for [`aidaemon_core::Hook`]s. No tool contains
//! approval logic.
//!
//! ```no_run
//! use aidaemon_tools::{default_tools, Checklist, Workspace};
//! # fn demo(provider: impl aidaemon_core::Provider + 'static) -> Result<(), Box<dyn std::error::Error>> {
//! let workspace = Workspace::new("./my-project")?;
//! let (checklist, gate) = Checklist::with_gate();
//! let mut builder = aidaemon_core::Agent::builder("coder").allow_unguarded()
//!     .model("some-model")
//!     .provider(provider)
//!     .tool(checklist)
//!     .hook(gate);
//! for tool in default_tools(workspace) {
//!     builder = builder.tool_arc(tool);
//! }
//! let agent = builder.build()?;
//! # let _ = agent; Ok(()) }
//! ```

// Feature unification only (cargo-hakari); keeps the unused-dependency lint quiet.
use workspace_hack as _;

use std::sync::Arc;

use aidaemon_core::Tool;

pub mod backend;
pub mod background_deliverable;
pub mod backoff;
pub mod check_environment;
mod checklist;
#[cfg(feature = "checkpoints")]
pub mod checkpoints;
pub mod cli_agent_flags;
pub mod command_effects;
pub mod command_risk;
pub mod config_file;
pub mod daemon_guard;
pub mod duration_format;
mod exec;
pub mod execution;
pub mod file_delivery;
mod fs;
pub mod fs_utils;
pub mod git_guard;
pub mod http_request;
pub mod internal_markers;
pub mod local_backend;
pub mod local_sites;
pub mod outcome;
pub mod owner_answers;
pub mod path_class;
pub mod permission_bypass;
pub mod platform_shell;
pub mod process_control;
pub mod result_spill;
pub mod sanitize;
mod search;
mod search_files;
#[cfg(test)]
mod search_files_tests;
pub mod semantics;
pub mod services;
mod shell;
pub mod shown;
#[cfg(feature = "sqlite")]
pub mod sqlite_schema;
pub mod status;
pub mod stt_setup;
pub mod system;
#[cfg(any(test, feature = "testing"))]
pub mod testing;
pub mod text;
pub mod tls;
mod util;
pub mod web;
pub mod web_search;
mod workspace;

#[cfg(test)]
mod testutil;

pub use backend::{
    BackendDirEntry, BackendFileType, BackendKind, BackendMetadata, BackendPath, CommandSpec,
    ExecutionBackend, ExecutionOutput, ExecutionRequest, LexicalPaths, ProcessHandle,
    SpawnedProcess, WriteMode, shell_quote,
};
pub use checklist::{Checklist, ChecklistGate, ChecklistItem, ChecklistState, ItemStatus};
pub use exec::{
    BubblewrapSandbox, BubblewrapScope, CommandOutput, DockerSandbox, ExecError, HOME_SECRET_PATHS,
    LocalSandbox, SANDBOX_ENV, Sandbox, SandboxCommand, SandboxKind, SandboxSelection,
    SeatbeltSandbox, TerminalConfinement, best_available_sandbox, default_deny_read,
    home_secret_paths, sandbox_preference_from_env, select_sandbox,
};
pub use fs::{
    DEFAULT_IGNORE_DIRS, EditFile, FilePolicy, HostFilePolicy, HostFilePolicySettings,
    MAX_READ_CHARS, ProtectedPathGuard, ReadFile, ToolText, WorkspaceBackend, WorkspaceFilePolicy,
    WriteFile, format_with_line_numbers, render_read_file_output, render_read_file_output_within,
};
pub use outcome::{
    CallValidator, KernelAdapter, NothingSentError, OutcomeRunner, OutcomeTool, TargetNotFound,
    ToolTimedOut, failed_without_effect, timed_out,
};
pub use path_class::PathClassifier;
pub use search::{Glob, Grep};
pub use search_files::SearchFiles;
pub use shell::{DEFAULT_ENV_ALLOWLIST, Shell};
pub use util::sniff_image_mime;
pub use web::{NetworkGuard, WebFetch};
pub use workspace::{PathError, Workspace};

/// The standard set: `read_file`, `write_file`, `edit_file`, `glob`, `grep`,
/// `shell` (with [`best_available_sandbox`]: bubblewrap on Linux, seatbelt
/// on macOS) and `web_fetch`.
///
/// `track_requirements` is not included because it is only useful together
/// with its stop hook; add both with [`Checklist::with_gate`].
pub fn default_tools(workspace: Workspace) -> Vec<Arc<dyn Tool>> {
    default_tools_with_sandbox(workspace, best_available_sandbox())
}

/// [`default_tools`] with the shell on an explicit backend, for example
/// `SandboxKind::Local.backend()` to run commands on the host on purpose.
pub fn default_tools_with_sandbox(
    workspace: Workspace,
    sandbox: Arc<dyn Sandbox>,
) -> Vec<Arc<dyn Tool>> {
    vec![
        Arc::new(ReadFile::new(workspace.clone())),
        Arc::new(WriteFile::new(workspace.clone())),
        Arc::new(EditFile::new(workspace.clone())),
        Arc::new(Glob::new(workspace.clone())),
        Arc::new(Grep::new(workspace.clone())),
        Arc::new(Shell::new(workspace, sandbox)),
        Arc::new(WebFetch::new()),
    ]
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn default_set_has_strict_unique_specs() {
        let (_d, ws) = testutil::ws();
        let tools = default_tools(ws);
        let mut names: Vec<String> = tools.iter().map(|t| t.spec().name).collect();
        names.push(Checklist::default().spec().name);
        let mut sorted = names.clone();
        sorted.sort();
        sorted.dedup();
        assert_eq!(sorted.len(), names.len());
        for tool in tools
            .iter()
            .cloned()
            .chain([Arc::new(Checklist::default()) as Arc<dyn Tool>])
        {
            let spec = tool.spec();
            assert!(!spec.description.is_empty(), "{}", spec.name);
            assert_eq!(spec.parameters["type"], "object", "{}", spec.name);
            assert_eq!(
                spec.parameters["additionalProperties"],
                serde_json::json!(false),
                "{}",
                spec.name
            );
            // Every required key is a declared property.
            for key in spec.parameters["required"].as_array().unwrap() {
                assert!(
                    spec.parameters["properties"]
                        .get(key.as_str().unwrap())
                        .is_some(),
                    "{}: {key}",
                    spec.name
                );
            }
        }
        let read_only: Vec<bool> = tools.iter().map(|t| t.annotations().read_only).collect();
        assert_eq!(read_only, [true, false, false, true, true, false, true]);
    }
}