Show live background task counts
This commit is contained in:
1 parent
9fd21af4e8
commit
8262ceb786
16 files changed
+160
-29
No files matched your search
@@ -124,6 +124,9 @@ pub struct EchoDriver {
|
||||
/// says it recovered, and a clear leaves it unmeasured. What is real is
|
||||
/// which way the numbers move.
|
||||
context: Arc<AtomicU64>,
|
||||
/// Live background commands, for the same count a real provider reports.
|
||||
/// This is the deterministic UI/session-lifecycle rig for that state.
|
||||
background_tasks: Arc<Mutex<usize>>,
|
||||
/// This session's subagents -- see `SUBAGENTS.md`. `/subagent` is the
|
||||
/// test rig for the same registry the claude driver routes real Task
|
||||
/// calls into.
|
||||
@@ -500,6 +503,12 @@ impl EchoDriver {
|
||||
id: id.clone(),
|
||||
output: format!("Command running in background with ID: {id}"),
|
||||
});
|
||||
let background_tasks = Arc::clone(&self.background_tasks);
|
||||
{
|
||||
let mut count = background_tasks.lock().unwrap();
|
||||
*count += 1;
|
||||
self.emit(Event::BackgroundTasks { count: *count });
|
||||
}
|
||||
for word in "Started it; I'll pick this up when it lands.".split_inclusive(' ') {
|
||||
self.emit(Event::AssistantText {
|
||||
delta: word.to_string(),
|
||||
@@ -513,6 +522,11 @@ impl EchoDriver {
|
||||
let sink = self.sink.clone();
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(seconds)).await;
|
||||
{
|
||||
let mut count = background_tasks.lock().unwrap();
|
||||
*count -= 1;
|
||||
let _ = sink.send(Event::BackgroundTasks { count: *count });
|
||||
}
|
||||
let _ = sink.send(Event::ToolUpdate {
|
||||
id,
|
||||
output: format!(r#"Background command "{command}" completed (exit code 0)"#),
|
||||
@@ -526,9 +540,16 @@ impl EchoDriver {
|
||||
});
|
||||
tokio::time::sleep(DELTA_DELAY).await;
|
||||
}
|
||||
let _ = sink.send(Event::Status {
|
||||
state: SessionStatus::Idle,
|
||||
});
|
||||
{
|
||||
let count = background_tasks.lock().unwrap();
|
||||
let _ = sink.send(Event::Status {
|
||||
state: if *count == 0 {
|
||||
SessionStatus::Idle
|
||||
} else {
|
||||
SessionStatus::Waiting
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -855,6 +876,7 @@ impl EchoDriver {
|
||||
sink,
|
||||
pending_questions: Mutex::new(Vec::new()),
|
||||
context: Arc::new(AtomicU64::new(0)),
|
||||
background_tasks: Arc::new(Mutex::new(0)),
|
||||
busy: Arc::new(AtomicBool::new(false)),
|
||||
queued: Arc::new(Mutex::new(Vec::new())),
|
||||
session_dir,
|
||||
@@ -1165,6 +1187,10 @@ fn finish_turn(sink: &EventSink, queued: &Mutex<Vec<Held>>, busy: &AtomicBool) {
|
||||
}
|
||||
|
||||
impl Driver for EchoDriver {
|
||||
fn background_tasks(&self) -> Option<usize> {
|
||||
Some(*self.background_tasks.lock().unwrap())
|
||||
}
|
||||
|
||||
fn between_turns(&self) -> bool {
|
||||
!self.busy.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user