fixup: consolidate tool types, fix build after reorganization
Move FunctionCall, FunctionDef, FunctionCallDelta from user/types to agent/tools. Re-export from user/types for backward compat. Merge duplicate dispatch functions in tools/mod.rs into dispatch (agent-specific) + dispatch_shared (with provenance). Fix orphaned derive, missing imports, runner→agent module path. Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
474b66c834
commit
17a018ff12
9 changed files with 1356 additions and 1380 deletions
|
|
@ -10,12 +10,9 @@ use anyhow::{Context, Result};
|
|||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use std::process::Stdio;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use super::ToolDef;
|
||||
use super::{ToolDef, ProcessTracker, default_timeout};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Args {
|
||||
|
|
@ -24,63 +21,6 @@ struct Args {
|
|||
timeout_secs: u64,
|
||||
}
|
||||
|
||||
fn default_timeout() -> u64 { 120 }
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
|
||||
pub fn definition() -> ToolDef {
|
||||
ToolDef::new(
|
||||
"bash",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue