WIP: ActiveTools wrapper type, removing SharedActiveTools
New ActiveTools struct with proper methods: push, remove, take_finished, take_foreground, iter, len. Turn loop uses helpers instead of manual index iteration. Removing SharedActiveTools (Arc<Mutex<Vec>>) — active tools live directly in AgentState. A few UI callers still need updating. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
14fd8c9b90
commit
9c9618d034
3 changed files with 56 additions and 52 deletions
|
|
@ -56,10 +56,6 @@ impl Tool {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// A tool call in flight — metadata for TUI + JoinHandle for
|
||||
/// result collection and cancellation.
|
||||
pub struct ActiveToolCall {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
|
|
@ -69,11 +65,51 @@ pub struct ActiveToolCall {
|
|||
pub handle: tokio::task::JoinHandle<(super::context::PendingToolCall, String)>,
|
||||
}
|
||||
|
||||
/// Shared active tool calls — agent spawns, TUI reads metadata / aborts.
|
||||
pub type SharedActiveTools = Arc<std::sync::Mutex<Vec<ActiveToolCall>>>;
|
||||
pub struct ActiveTools(Vec<ActiveToolCall>);
|
||||
|
||||
pub fn shared_active_tools() -> SharedActiveTools {
|
||||
Arc::new(std::sync::Mutex::new(Vec::new()))
|
||||
impl ActiveTools {
|
||||
pub fn new() -> Self { Self(Vec::new()) }
|
||||
|
||||
pub fn push(&mut self, call: ActiveToolCall) {
|
||||
self.0.push(call);
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, id: &str) {
|
||||
self.0.retain(|t| t.id != id);
|
||||
}
|
||||
|
||||
pub fn take_finished(&mut self) -> Vec<ActiveToolCall> {
|
||||
let mut finished = Vec::new();
|
||||
let mut i = 0;
|
||||
while i < self.0.len() {
|
||||
if self.0[i].handle.is_finished() {
|
||||
finished.push(self.0.remove(i));
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
finished
|
||||
}
|
||||
|
||||
pub fn take_foreground(&mut self) -> Vec<ActiveToolCall> {
|
||||
let mut fg = Vec::new();
|
||||
let mut i = 0;
|
||||
while i < self.0.len() {
|
||||
if !self.0[i].background {
|
||||
fg.push(self.0.remove(i));
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
fg
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &ActiveToolCall> {
|
||||
self.0.iter()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize { self.0.len() }
|
||||
pub fn is_empty(&self) -> bool { self.0.is_empty() }
|
||||
}
|
||||
|
||||
/// Truncate output if it exceeds max length, appending a truncation notice.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue