Skip to main content

harness_bash/
lib.rs

1//! Bash tool — Rust port of `@agent-sh/harness-bash`.
2//!
3//! Conforms to `agent-knowledge/design/bash.md`. Same contract as the
4//! TS package: `bash` / `bash_output` / `bash_kill` with a session
5//! object, tokio-driven process runner, inactivity + wall-clock
6//! timeouts, HeadTailBuffer with spill-to-file, background job map.
7
8mod constants;
9mod executor;
10mod fence;
11mod format;
12mod run;
13mod schema;
14mod types;
15
16pub use constants::*;
17pub use executor::{default_executor, BashExecutor, BashRunInput, BashRunResult, BackgroundReadResult};
18pub use format::{
19    format_background_started_text, format_bash_kill_text,
20    format_bash_output_text, format_result_text, format_timeout_text,
21    HeadTailBuffer,
22};
23pub use schema::{
24    safe_parse_bash_kill_params, safe_parse_bash_output_params,
25    safe_parse_bash_params, BashKillParams, BashOutputParams, BashParams,
26    BashParseError, BASH_KILL_TOOL_DESCRIPTION, BASH_KILL_TOOL_NAME,
27    BASH_OUTPUT_TOOL_DESCRIPTION, BASH_OUTPUT_TOOL_NAME, BASH_TOOL_DESCRIPTION,
28    BASH_TOOL_NAME,
29};
30pub use types::{
31    BashBackgroundStarted, BashError, BashKillResult, BashNonzeroExit, BashOk,
32    BashOutputResult, BashPermissionPolicy, BashResult, BashSessionConfig,
33    BashTimeout, TimeoutReason,
34};
35
36pub async fn bash(
37    params: serde_json::Value,
38    session: &BashSessionConfig,
39) -> BashResult {
40    run::bash_run(params, session).await
41}
42
43pub async fn bash_output(
44    params: serde_json::Value,
45    session: &BashSessionConfig,
46) -> BashOutputResult {
47    run::bash_output_run(params, session).await
48}
49
50pub async fn bash_kill(
51    params: serde_json::Value,
52    session: &BashSessionConfig,
53) -> BashKillResult {
54    run::bash_kill_run(params, session).await
55}
56
57/// Expose `applyCwdCarry` equivalent for harnesses that want to mutate
58/// logical cwd after a successful `cd` command. Same contract as the TS
59/// `applyCwdCarry` — returns whether the cwd changed and whether the
60/// attempt escaped the workspace.
61pub use run::{apply_cwd_carry, detect_top_level_cd, CwdCarryOutcome};