feat: configurable exec timeout per request (--timeout flag, default 30s)

This commit is contained in:
Helios Agent 2026-03-03 16:05:29 +01:00
parent 1c0af1693b
commit 537ed95a3c
No known key found for this signature in database
GPG key ID: C8259547CD8309B5
5 changed files with 44 additions and 17 deletions

View file

@ -392,8 +392,7 @@ async fn handle_message(
ClientMessage::Ack { request_id }
}
ServerMessage::ExecRequest { request_id, command } => {
// Truncate long commands for display
ServerMessage::ExecRequest { request_id, command, timeout_ms } => {
let cmd_display = if command.len() > 60 {
format!("{}", &command[..60])
} else {
@ -401,7 +400,7 @@ async fn handle_message(
};
log_cmd!("exec {}", cmd_display);
let mut sh = shell.lock().await;
match sh.run(&command).await {
match sh.run(&command, timeout_ms).await {
Ok((stdout, stderr, exit_code)) => {
let out = stdout.trim().lines().next().unwrap_or("").to_string();
let out_display = if out.len() > 60 {

View file

@ -4,28 +4,27 @@
use std::time::Duration;
use tokio::process::Command;
const TIMEOUT_MS: u64 = 30_000;
const DEFAULT_TIMEOUT_MS: u64 = 30_000;
pub struct PersistentShell;
impl PersistentShell {
pub fn new() -> Self { Self }
pub async fn run(&mut self, command: &str) -> Result<(String, String, i32), String> {
pub async fn run(&mut self, command: &str, timeout_ms: Option<u64>) -> Result<(String, String, i32), String> {
let timeout_ms = timeout_ms.unwrap_or(DEFAULT_TIMEOUT_MS);
let timeout = Duration::from_millis(timeout_ms);
#[cfg(windows)]
{
// -NoProfile: skip $PROFILE (prevents user's `clear` from running)
// -NonInteractive: no prompts
// -Command: run the given command string
let mut cmd = Command::new("powershell.exe");
cmd.args(["-NoProfile", "-NonInteractive", "-Command", command]);
run_captured(cmd, Duration::from_millis(TIMEOUT_MS)).await
run_captured(cmd, timeout).await
}
#[cfg(not(windows))]
{
let mut cmd = Command::new("sh");
cmd.args(["-c", command]);
run_captured(cmd, Duration::from_millis(TIMEOUT_MS)).await
run_captured(cmd, timeout).await
}
}
}