Merge pull request 'tui: align subagent list, drop finished agents after 20s' (#135) from feat/subagent-list-linger into main
This commit was merged in pull request #135.
This commit is contained in:
commit
fe388ddc4f
3 files changed
+20
-11
No files matched your search
@@ -76,6 +76,10 @@ impl Shared {
|
||||
let end = *self.ended.lock().unwrap_or_else(|e| e.into_inner());
|
||||
end.unwrap_or_else(Instant::now) - self.started
|
||||
}
|
||||
/// Time since the child finished; `None` while running.
|
||||
pub fn since_end(&self) -> Option<std::time::Duration> {
|
||||
(*self.ended.lock().unwrap_or_else(|e| e.into_inner())).map(|t| t.elapsed())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sub {
|
||||
|
||||
@@ -17,6 +17,8 @@ pub struct Row {
|
||||
pub prompt: String,
|
||||
pub status: Status,
|
||||
pub elapsed: Duration,
|
||||
/// time since it finished (`None` while running)
|
||||
pub ended: Option<Duration>,
|
||||
pub calls: usize,
|
||||
pub tokens: u64,
|
||||
}
|
||||
@@ -29,6 +31,7 @@ pub fn row(s: &Sub) -> Row {
|
||||
prompt: s.sh.prompt.lines().next().unwrap_or_default().to_string(),
|
||||
status: s.sh.status(),
|
||||
elapsed: s.sh.elapsed(),
|
||||
ended: s.sh.since_end(),
|
||||
calls: s.sh.calls.load(std::sync::atomic::Ordering::Relaxed),
|
||||
tokens: u.input_tokens + u.cache_read_tokens + u.cache_write_tokens + u.output_tokens,
|
||||
}
|
||||
@@ -45,6 +48,8 @@ pub enum View {
|
||||
}
|
||||
|
||||
pub const MAX_ROWS: usize = 5;
|
||||
/// Finished agents leave the passive list after this long (still reachable via ctrl-g).
|
||||
pub const LINGER: Duration = Duration::from_secs(20);
|
||||
|
||||
fn dur(d: Duration) -> String {
|
||||
match d.as_secs() {
|
||||
@@ -78,7 +83,7 @@ pub fn lines(rows: &[Row], sel: Option<usize>, frame: usize, width: u16) -> Vec<
|
||||
.take(MAX_ROWS)
|
||||
.map(|(i, r)| {
|
||||
let tail = format!(" {} {}c {}k", dur(r.elapsed), r.calls, r.tokens / 1000);
|
||||
let head = format!("{} {} {:<7} ", glyph(&r.status, frame), r.id, r.kind);
|
||||
let head = format!(" {} {} {:<7} ", glyph(&r.status, frame), r.id, r.kind);
|
||||
let room = w.saturating_sub(head.chars().count() + tail.chars().count());
|
||||
let mut p: String = r.prompt.chars().take(room).collect();
|
||||
if r.prompt.chars().count() > room && room > 0 {
|
||||
@@ -213,6 +218,7 @@ mod tests {
|
||||
prompt: "grep the auth middleware for token expiry checks".into(),
|
||||
status: st,
|
||||
elapsed: Duration::from_secs(72),
|
||||
ended: None,
|
||||
calls: 8,
|
||||
tokens: 41_000,
|
||||
}
|
||||
@@ -230,8 +236,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
let l = lines(&v, None, 0, 60);
|
||||
assert!(text(&l[0]).starts_with("⠋ 1 explore ") && text(&l[0]).ends_with(" 1m12s 8c 41k"));
|
||||
assert!(text(&l[1]).starts_with("✓ 2 explore "), "{}", text(&l[1]));
|
||||
assert!(text(&l[0]).starts_with(" ⠋ 1 explore ") && text(&l[0]).ends_with(" 1m12s 8c 41k"));
|
||||
assert!(text(&l[1]).starts_with(" ✓ 2 explore "), "{}", text(&l[1]));
|
||||
assert!(text(&l[0]).contains('…'));
|
||||
}
|
||||
|
||||
@@ -240,7 +246,7 @@ mod tests {
|
||||
let v: Vec<Row> = (1..=8).map(|i| r(i, Status::Done)).collect();
|
||||
let ids = |l: Vec<Line>| {
|
||||
l.iter()
|
||||
.map(|x| text(x).chars().nth(2).unwrap().to_string())
|
||||
.map(|x| text(x).chars().nth(4).unwrap().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(ids(lines(&v, None, 0, 60)), ["4", "5", "6", "7", "8"]);
|
||||
|
||||
@@ -1354,12 +1354,14 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
|
||||
}
|
||||
app.agents = None;
|
||||
}
|
||||
let focused = app.agents.is_some();
|
||||
let sub_rows: Vec<agents::Row> = app
|
||||
.state
|
||||
.subs
|
||||
.list()
|
||||
.iter()
|
||||
.map(|s| agents::row(s))
|
||||
.filter(|r| focused || r.ended.is_none_or(|e| e < agents::LINGER))
|
||||
.collect();
|
||||
let foot_h = status::rows_for(f.area().width, app.ask.is_some());
|
||||
let [main, subs_area, act, input, status_row] = Layout::vertical([
|
||||
@@ -1417,19 +1419,16 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
|
||||
}
|
||||
|
||||
if !sub_rows.is_empty() {
|
||||
let w = subs_area.width.min(56);
|
||||
let w = subs_area.width;
|
||||
let sel = match &app.agents {
|
||||
Some(agents::View::List(s)) => Some((*s).min(sub_rows.len() - 1)),
|
||||
_ => None,
|
||||
};
|
||||
let frame = (app.since.elapsed().as_millis() / 80) as usize;
|
||||
let r = Rect::new(
|
||||
subs_area.x + subs_area.width - w,
|
||||
subs_area.y,
|
||||
w,
|
||||
subs_area.height,
|
||||
f.render_widget(
|
||||
Paragraph::new(agents::lines(&sub_rows, sel, frame, w)),
|
||||
subs_area,
|
||||
);
|
||||
f.render_widget(Paragraph::new(agents::lines(&sub_rows, sel, frame, w)), r);
|
||||
}
|
||||
if app.busy {
|
||||
let (what, t0) = app.t.running().unwrap_or(("thinking…".into(), app.since));
|
||||
|
||||
Reference in new issue
Block a user