delete ProcessTracker — replaced by ActiveToolCall + KillOnDrop
All process management now goes through active_tools: - TUI reads metadata (name, elapsed time) - Ctrl+K aborts handles (KillOnDrop sends SIGTERM) - Running count from active_tools.len() No more separate PID tracking, register/unregister, or ProcessInfo. One data structure for everything. Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
310bbe9fce
commit
021eafe6da
5 changed files with 37 additions and 109 deletions
|
|
@ -19,9 +19,7 @@ mod vision;
|
|||
pub mod working_stack;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
fn default_timeout() -> u64 { 120 }
|
||||
|
||||
|
|
@ -110,14 +108,6 @@ impl ToolOutput {
|
|||
}
|
||||
}
|
||||
|
||||
/// Info about a running child process, visible to the TUI.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProcessInfo {
|
||||
pub pid: u32,
|
||||
pub command: String,
|
||||
pub started: Instant,
|
||||
}
|
||||
|
||||
/// A tool call in flight — metadata for TUI + JoinHandle for
|
||||
/// result collection and cancellation.
|
||||
pub struct ActiveToolCall {
|
||||
|
|
@ -129,53 +119,6 @@ pub struct ActiveToolCall {
|
|||
pub handle: tokio::task::JoinHandle<(ToolCall, ToolOutput)>,
|
||||
}
|
||||
|
||||
/// Shared tracker for running child processes. Allows the TUI to
|
||||
/// display what's running and kill processes by PID.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ProcessTracker {
|
||||
inner: Arc<Mutex<Vec<ProcessInfo>>>,
|
||||
}
|
||||
|
||||
impl ProcessTracker {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
async fn register(&self, pid: u32, command: &str) {
|
||||
self.inner.lock().await.push(ProcessInfo {
|
||||
pid,
|
||||
command: if command.len() > 120 {
|
||||
format!("{}...", &command[..120])
|
||||
} else {
|
||||
command.to_string()
|
||||
},
|
||||
started: Instant::now(),
|
||||
});
|
||||
}
|
||||
|
||||
async fn unregister(&self, pid: u32) {
|
||||
self.inner.lock().await.retain(|p| p.pid != pid);
|
||||
}
|
||||
|
||||
/// Snapshot of currently running processes.
|
||||
pub async fn list(&self) -> Vec<ProcessInfo> {
|
||||
self.inner.lock().await.clone()
|
||||
}
|
||||
|
||||
/// Kill a process by PID. Returns true if the signal was sent.
|
||||
pub async fn kill(&self, pid: u32) -> bool {
|
||||
// SIGTERM the process group (negative PID kills the group)
|
||||
let ret = unsafe { libc::kill(-(pid as i32), libc::SIGTERM) };
|
||||
if ret != 0 {
|
||||
// Try just the process
|
||||
unsafe { libc::kill(pid as i32, libc::SIGTERM) };
|
||||
}
|
||||
// Don't unregister — let the normal exit path do that
|
||||
// so the tool result says "killed by user"
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Truncate output if it exceeds max length, appending a truncation notice.
|
||||
pub fn truncate_output(mut s: String, max: usize) -> String {
|
||||
if s.len() > max {
|
||||
|
|
@ -197,7 +140,6 @@ pub fn truncate_output(mut s: String, max: usize) -> String {
|
|||
pub async fn dispatch(
|
||||
name: &str,
|
||||
args: &serde_json::Value,
|
||||
tracker: &ProcessTracker,
|
||||
) -> ToolOutput {
|
||||
// Agent-specific tools
|
||||
let rich_result = match name {
|
||||
|
|
@ -211,7 +153,7 @@ pub async fn dispatch(
|
|||
return result.unwrap_or_else(ToolOutput::error);
|
||||
}
|
||||
|
||||
if let Some(output) = dispatch_shared(name, args, tracker, None).await {
|
||||
if let Some(output) = dispatch_shared(name, args, None).await {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
@ -224,7 +166,6 @@ pub async fn dispatch(
|
|||
pub async fn dispatch_shared(
|
||||
name: &str,
|
||||
args: &serde_json::Value,
|
||||
tracker: &ProcessTracker,
|
||||
provenance: Option<&str>,
|
||||
) -> Option<ToolOutput> {
|
||||
// Memory and journal tools
|
||||
|
|
@ -241,7 +182,7 @@ pub async fn dispatch_shared(
|
|||
"read_file" => read::read_file(args),
|
||||
"write_file" => write::write_file(args),
|
||||
"edit_file" => edit::edit_file(args),
|
||||
"bash" => bash::run_bash(args, tracker).await,
|
||||
"bash" => bash::run_bash(args).await,
|
||||
"grep" => grep::grep(args),
|
||||
"glob" => glob::glob_search(args),
|
||||
_ => return None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue