Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions crates/bashkit-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,12 @@ impl ScriptedTool {
fn execute<'py>(&self, py: Python<'py>, commands: String) -> PyResult<Bound<'py, PyAny>> {
let mut tool = self.build_rust_tool();
future_into_py(py, async move {
let resp = tool.execute(ToolRequest { commands }).await;
let resp = tool
.execute(ToolRequest {
commands,
timeout_ms: None,
})
.await;
Ok(ExecResult {
stdout: resp.stdout,
stderr: resp.stderr,
Expand All @@ -507,7 +512,13 @@ impl ScriptedTool {
let rt = tokio::runtime::Runtime::new()
.map_err(|e| PyRuntimeError::new_err(format!("Failed to create runtime: {}", e)))?;

let resp = rt.block_on(async move { tool.execute(ToolRequest { commands }).await });
let resp = rt.block_on(async move {
tool.execute(ToolRequest {
commands,
timeout_ms: None,
})
.await
});
Ok(ExecResult {
stdout: resp.stdout,
stderr: resp.stderr,
Expand Down
6 changes: 6 additions & 0 deletions crates/bashkit/examples/scripted_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async fn main() -> anyhow::Result<()> {
let resp = tool
.execute(ToolRequest {
commands: "get_user --id 1".to_string(),
timeout_ms: None,
})
.await;
println!("$ get_user --id 1");
Expand All @@ -47,6 +48,7 @@ async fn main() -> anyhow::Result<()> {
let resp = tool
.execute(ToolRequest {
commands: "get_user --id 1 | jq -r '.name'".to_string(),
timeout_ms: None,
})
.await;
println!("$ get_user --id 1 | jq -r '.name'");
Expand All @@ -67,6 +69,7 @@ async fn main() -> anyhow::Result<()> {
let resp = tool
.execute(ToolRequest {
commands: script.to_string(),
timeout_ms: None,
})
.await;
println!("$ <multi-step script>");
Expand All @@ -91,6 +94,7 @@ async fn main() -> anyhow::Result<()> {
let resp = tool
.execute(ToolRequest {
commands: script.to_string(),
timeout_ms: None,
})
.await;
println!("$ <loop with conditional>");
Expand All @@ -113,6 +117,7 @@ async fn main() -> anyhow::Result<()> {
let resp = tool
.execute(ToolRequest {
commands: script.to_string(),
timeout_ms: None,
})
.await;
println!("$ <inventory check>");
Expand All @@ -133,6 +138,7 @@ async fn main() -> anyhow::Result<()> {
let resp = tool
.execute(ToolRequest {
commands: script.to_string(),
timeout_ms: None,
})
.await;
println!("$ <aggregate report>");
Expand Down
17 changes: 17 additions & 0 deletions crates/bashkit/src/scripted_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
//!
//! let resp = tool.execute(ToolRequest {
//! commands: "greet --name Alice".to_string(),
//! timeout_ms: None,
//! }).await;
//!
//! assert_eq!(resp.stdout.trim(), "hello Alice");
Expand Down Expand Up @@ -415,6 +416,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: String::new(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -427,6 +429,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "get_user --id 42".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -440,6 +443,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "get_user --id=42".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -452,6 +456,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "get_user --id 42 | jq -r '.name'".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -471,6 +476,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: script.to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -483,6 +489,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "fail_tool".to_string(),
timeout_ms: None,
})
.await;
assert_ne!(resp.exit_code, 0);
Expand All @@ -495,6 +502,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "fail_tool || echo 'fallback'".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -507,6 +515,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "echo hello | from_stdin".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -524,6 +533,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: script.to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -545,6 +555,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: script.to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -563,6 +574,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "echo $API_BASE".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -581,6 +593,7 @@ mod tests {
.execute_with_status(
ToolRequest {
commands: "get_user --id 1".to_string(),
timeout_ms: None,
},
Box::new(move |status| {
phases_clone
Expand All @@ -605,13 +618,15 @@ mod tests {
let resp1 = tool
.execute(ToolRequest {
commands: "get_user --id 1 | jq -r '.name'".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp1.stdout.trim(), "Alice");

let resp2 = tool
.execute(ToolRequest {
commands: "get_orders --user_id 1 | jq 'length'".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp2.stdout.trim(), "2");
Expand Down Expand Up @@ -639,6 +654,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "search --verbose --query hello".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand All @@ -657,6 +673,7 @@ mod tests {
let resp = tool
.execute(ToolRequest {
commands: "echo_args --name Alice --count 3".to_string(),
timeout_ms: None,
})
.await;
assert_eq!(resp.exit_code, 0);
Expand Down
Loading
Loading