A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
agents view: list named empty sessions by recency (#3653)
Sebastian Müller698f37384fe4
diff --git a/crates/pa-tui/src/agents_view/tests.rs b/crates/pa-tui/src/agents_view/tests.rsindex a0ca7ab59c..0271680761 100644--- a/crates/pa-tui/src/agents_view/tests.rs+++ b/crates/pa-tui/src/agents_view/tests.rs@@ -10,6 +10,7 @@ mod cost_aggregates;mod delete_stop;mod drill_down;mod edge_jumps;+mod empty_sessions;mod entry_anchor;mod heartbeat_badge;mod hints_render;diff --git a/crates/pa-tui/src/agents_view/tests/empty_sessions.rs b/crates/pa-tui/src/agents_view/tests/empty_sessions.rsnew file mode 100644index 0000000000..d46072954b--- /dev/null+++ b/crates/pa-tui/src/agents_view/tests/empty_sessions.rs@@ -0,0 +1,68 @@+//! Message-less sessions: a name makes an empty session an intentional object that lists by+//! recency and opens like any other; an unnamed empty one stays hidden once inactive.++use super::*;++/// One saved-catalog row with no messages, modified after the [`saved_catalog_row`] fixtures.+fn empty_catalog_row(path: &str, id: &str, name: Option<&str>) -> serde_json::Value {+ let mut row = serde_json::json!({+ "path": path,+ "id": id,+ "cwd": "/tmp",+ "rlmDepth": 0,+ "created": "2024-02-01T00:00:00.000Z",+ "modified": "2024-02-01T00:00:00.000Z",+ "messageCount": 0,+ "firstMessage": "(no messages)",+ "allMessagesText": "",+ });+ if let Some(name) = name {+ row["name"] = serde_json::json!(name);+ }+ row+}++fn titles(mode: &AgentsViewMode) -> Vec<&str> {+ mode.rows.iter().map(|row| row.title.as_str()).collect()+}++#[test]+fn a_named_empty_session_lists_by_recency_and_opens() {+ let mut mode = mode_with_anchor(None, vec![]);+ mode.saved = vec![+ saved_catalog_row("/x/old1.jsonl", "old1", "older one"),+ saved_catalog_row("/x/old2.jsonl", "old2", "older two"),+ empty_catalog_row("/x/plan.jsonl", "plan", Some("fresh plan")),+ empty_catalog_row("/x/blank.jsonl", "blank", None),+ ];+ mode.rebuild_rows();+ assert_eq!(+ titles(&mode),+ ["fresh plan", "older one", "older two"],+ "the newest session leads even with no messages; the unnamed empty one stays hidden"+ );+ let row = &mode.rows[0];+ assert_eq!(row.section, Section::Inactive);+ assert!(row.cost.abs() < f64::EPSILON, "no spend: {}", row.cost);+ assert!(!row.age.is_empty(), "the row shows its age");+ mode.handle_key("enter");+ assert_eq!(+ mode.opened.map(|opened| opened.selection),+ Some(SessionSelection::Resume(PathBuf::from("/x/plan.jsonl"))),+ "Enter opens the named empty session"+ );+}++#[test]+fn an_empty_session_that_loses_its_name_hides_again() {+ let mut mode = mode_with_anchor(None, vec![]);+ mode.saved = vec![+ saved_catalog_row("/x/old.jsonl", "old", "older one"),+ empty_catalog_row("/x/plan.jsonl", "plan", Some("fresh plan")),+ ];+ mode.rebuild_rows();+ assert!(titles(&mode).contains(&"fresh plan"));+ mode.buffer_saved_stream_item(empty_catalog_row("/x/plan.jsonl", "plan", None));+ assert!(mode.flush_saved_stream());+ assert_eq!(titles(&mode), ["older one"]);+}diff --git a/crates/pa-tui/src/agents_view_forest/rows.rs b/crates/pa-tui/src/agents_view_forest/rows.rsindex 5a964f2605..1ec8917023 100644--- a/crates/pa-tui/src/agents_view_forest/rows.rs+++ b/crates/pa-tui/src/agents_view_forest/rows.rs@@ -8,7 +8,8 @@ use super::{SUMMARY_ROW_PREFIX,};use crate::agents_view_state::{- now_ms, relative_age, section_rank, summary_for_record, Section, UnifiedRecord,+ is_unnamed_empty, now_ms, relative_age, section_rank, summary_for_record, Section,+ UnifiedRecord,};use crate::subagents::{is_subagent_summary, summary_identity_keys, summary_parent_keys};@@ -410,7 +411,7 @@ fn spawn_code_rows(rows}-/// Section rank, then empty sessions sink, then recency, then title, then session id.+/// Section rank, then unnamed empty sessions sink, then recency, then title, then session id.fn compare_base(a: &BaseRow, b: &BaseRow, anchor: Option<&str>) -> std::cmp::Ordering {use std::cmp::Ordering;fn get_str<'a>(summary: &'a Value, field: &str) -> Option<&'a str> {@@ -450,14 +451,9 @@ fn compare_base(a: &BaseRow, b: &BaseRow, anchor: Option<&str>) -> std::cmp::Ordif section != Ordering::Equal {return section;}- // Message-less rows sink to the bottom of their section (anchor exempt).+ // Unnamed message-less rows sink to the bottom of their section (anchor exempt).let empty = |row: &BaseRow| {- row.summary- .get("messageCount")- .and_then(Value::as_u64)- .unwrap_or(0)- == 0- && get_str(&row.summary, "sessionId") != anchor+ is_unnamed_empty(&row.summary) && get_str(&row.summary, "sessionId") != anchor};let empty_rank = empty(a).cmp(&empty(b));if empty_rank != Ordering::Equal {diff --git a/crates/pa-tui/src/agents_view_state.rs b/crates/pa-tui/src/agents_view_state.rsindex 76b5d75166..553ef9b323 100644--- a/crates/pa-tui/src/agents_view_state.rs+++ b/crates/pa-tui/src/agents_view_state.rs@@ -355,6 +355,18 @@ fn json_model(model: &Value) -> Value {serde_json::json!({ "id": model_id, "provider": provider })}+/// A session with no messages and no name. A name makes an empty session intentional: it lists+/// and ranks like any other session, while an unnamed one hides once inactive and sinks in its+/// section.+pub(crate) fn is_unnamed_empty(summary: &Value) -> bool {+ summary+ .get("messageCount")+ .and_then(Value::as_u64)+ .unwrap_or(0)+ == 0+ && get_str(summary, "sessionName").is_none()+}+/// Hide abandoned empty catalog rows (TS `filterEmptyAgentsViewSessions`): an inactive row with/// no messages, name, usage, or transcript stays out unless it is the view's anchor.pub fn filter_empty_sessions(records: &[UnifiedRecord], preserved: &[&str]) -> Vec<UnifiedRecord> {@@ -394,12 +406,7 @@ pub fn filter_empty_sessions(records: &[UnifiedRecord], preserved: &[&str]) -> V.and_then(Value::as_u64).unwrap_or(0)> 0- || summary- .get("messageCount")- .and_then(Value::as_u64)- .unwrap_or(0)- > 0- || get_str(&summary, "sessionName").is_some()+ || !is_unnamed_empty(&summary)|| get_str(&summary, "firstMessage").is_some_and(|text| !text.trim().is_empty() && text.trim() != "(no messages)")|| summary