Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

feat(agents): redesign the Agents panel and add a view menu

RoversX8ea9c1c21b46
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index d66019f0..4e2017ff 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -345,6 +345,15 @@ menu-group-by = Gruppieren nach
menu-workspace = Workspace
menu-show = Anzeigen
menu-status = Status
+menu-machine = Rechner
+menu-machine-local = Dieser Computer
+menu-group-state = Status
+menu-group-thread = Thread
+menu-group-none = Keine
+menu-sort-by = Sortieren nach
+menu-sort-fixed = Feste Reihenfolge
+menu-sort-recent = Letzte Aktivität
+menu-reload-agent-rules = Erkennungsregeln neu laden
menu-no-notifications = Keine Mitteilungen
menu-disconnect-thread = Thread trennen
menu-connect-thread = Thread verbinden
@@ -718,6 +727,8 @@ right-agents-state-unknown = Unbekannt
right-agents-state-error = Fehler
right-agents-state-done = Fertig
right-agents-none = Keine Agents erkannt
+right-agents-group-other = Sonstige
+right-agents-all-hidden = Alle Agents sind durch die Ansichtsoptionen ausgeblendet
right-agents-detection-off = Agent-Erkennung ist aus — Einstellungen öffnen
right-agents-count-working = { $count } arbeiten
right-agents-count-blocked = { $count ->
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index 0f12864d..c9d7c9b8 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -345,6 +345,15 @@ menu-group-by = Group by
menu-workspace = Workspace
menu-show = Show
menu-status = Status
+menu-machine = Machine
+menu-machine-local = This computer
+menu-group-state = State
+menu-group-thread = Thread
+menu-group-none = None
+menu-sort-by = Sort by
+menu-sort-fixed = Fixed order
+menu-sort-recent = Recent activity
+menu-reload-agent-rules = Reload Detection Rules
menu-no-notifications = No notifications
menu-disconnect-thread = Disconnect Thread
menu-connect-thread = Connect Thread
@@ -718,6 +727,8 @@ right-agents-state-unknown = Unknown
right-agents-state-error = Error
right-agents-state-done = Done
right-agents-none = No agents detected
+right-agents-group-other = Other
+right-agents-all-hidden = Every agent is hidden by the view options
right-agents-detection-off = Agent detection is off — open settings
right-agents-count-working = { $count } working
right-agents-count-blocked = { $count ->
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index b7240dbd..eddaafe1 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -345,6 +345,15 @@ menu-group-by = Regrouper par
menu-workspace = Espace de travail
menu-show = Afficher
menu-status = État
+menu-machine = Machine
+menu-machine-local = Cet ordinateur
+menu-group-state = État
+menu-group-thread = Session
+menu-group-none = Aucun
+menu-sort-by = Trier par
+menu-sort-fixed = Ordre fixe
+menu-sort-recent = Activité récente
+menu-reload-agent-rules = Recharger les règles de détection
menu-no-notifications = Aucune notification
menu-disconnect-thread = Déconnecter la session
menu-connect-thread = Connecter la session
@@ -718,6 +727,8 @@ right-agents-state-unknown = Inconnu
right-agents-state-error = Erreur
right-agents-state-done = Terminé
right-agents-none = Aucun agent détecté
+right-agents-group-other = Autres
+right-agents-all-hidden = Tous les agents sont masqués par les options d’affichage
right-agents-detection-off = Détection des agents désactivée — ouvrir les réglages
right-agents-count-working = { $count } en cours
right-agents-count-blocked = { $count } en attente
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index e578be70..ca476b4d 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -336,6 +336,15 @@ menu-group-by = グループ化
menu-workspace = ワークスペース
menu-show = 表示
menu-status = 状態
+menu-machine = マシン
+menu-machine-local = このコンピュータ
+menu-group-state = 状態
+menu-group-thread = セッション
+menu-group-none = なし
+menu-sort-by = 並べ替え
+menu-sort-fixed = 固定順
+menu-sort-recent = 最近のアクティビティ
+menu-reload-agent-rules = 検出ルールを再読み込み
menu-no-notifications = 通知はありません
menu-disconnect-thread = セッションを切断
menu-connect-thread = セッションに接続
@@ -700,6 +709,8 @@ right-agents-state-unknown = 不明
right-agents-state-error = エラー
right-agents-state-done = 完了
right-agents-none = エージェントは検出されていません
+right-agents-group-other = その他
+right-agents-all-hidden = 表示オプションですべてのエージェントが非表示です
right-agents-detection-off = エージェント検出はオフです — 設定を開く
right-agents-count-working = { $count } 件が作業中
right-agents-count-blocked = { $count } 件が入力待ち
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index c7b61e04..3f3402fd 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -336,6 +336,15 @@ menu-group-by = 分组方式
menu-workspace = 工作区
menu-show = 显示
menu-status = 状态
+menu-machine = 机器
+menu-machine-local = 本机
+menu-group-state = 状态
+menu-group-thread = 会话
+menu-group-none = 不分组
+menu-sort-by = 排序方式
+menu-sort-fixed = 固定顺序
+menu-sort-recent = 最近活动
+menu-reload-agent-rules = 重新加载检测规则
menu-no-notifications = 没有通知
menu-disconnect-thread = 断开会话
menu-connect-thread = 连接会话
@@ -700,6 +709,8 @@ right-agents-state-unknown = 未知
right-agents-state-error = 出错
right-agents-state-done = 已完成
right-agents-none = 未检测到 Agent
+right-agents-group-other = 其他
+right-agents-all-hidden = 显示选项隐藏了所有 Agent
right-agents-detection-off = Agent 检测已关闭 — 打开设置
right-agents-count-working = { $count } 个运行中
right-agents-count-blocked = { $count } 个等待输入
diff --git a/wezterm-gui/src/agent_status/mod.rs b/wezterm-gui/src/agent_status/mod.rs
index 3ffc19ff..c56d3f78 100644
--- a/wezterm-gui/src/agent_status/mod.rs
+++ b/wezterm-gui/src/agent_status/mod.rs
@@ -31,7 +31,6 @@ use std::time::{Duration, Instant};
/// `UIItemType::RightSidebarAgent`.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AgentPanelAction {
- ReloadRules,
/// The toolbar line says detection is off; clicking it opens the
/// settings page that owns that switch, so the panel explains itself
/// instead of just sitting empty.
@@ -45,6 +44,9 @@ pub enum AgentPanelAction {
/// Open or fold the sub-task list of the agent in this pane. Folded
/// is the default: one line that counts them.
ToggleSubtasks(PaneId),
+ /// The toolbar button that opens the view menu: what to show, how to
+ /// group and order it, and which parts of a report to show.
+ ViewOptions,
}
/// Snapshot of one agent pane for the Agents panel.
@@ -69,11 +71,14 @@ pub(crate) struct AgentPaneStatus {
pub place: String,
/// The workspace the pane belongs to, as the thread store names it.
pub workspace: String,
+ /// The machine its thread runs on, as
+ /// `workspace_threads::thread_place_and_machine_for_workspace` keys it;
+ /// empty for this device. Resolved with `place`, once per snapshot.
+ pub machine: String,
/// What the program said about itself with OSC 7501, when it did.
pub report: Option<ProgramReport>,
/// Unix seconds when `state` last changed, on the detecting host's
/// clock (approximate across hosts).
- #[allow(dead_code)]
pub since_unix: u64,
}
@@ -187,11 +192,11 @@ fn agent_panes() -> std::sync::Arc<Vec<AgentPaneStatus>> {
Some((window_id, workspace)) => (Some(*window_id), workspace.clone()),
None => (None, String::new()),
};
- let place = if workspace.is_empty() {
- String::new()
+ let (place, machine) = if workspace.is_empty() {
+ (String::new(), String::new())
} else {
- crate::workspace_threads::thread_display_name_for_workspace(&workspace)
- .unwrap_or_else(|| workspace.clone())
+ crate::workspace_threads::thread_place_and_machine_for_workspace(&workspace)
+ .unwrap_or_else(|| (workspace.clone(), String::new()))
};
let raw_title = pane.get_title();
let title =
@@ -210,6 +215,7 @@ fn agent_panes() -> std::sync::Arc<Vec<AgentPaneStatus>> {
window_id,
place,
workspace,
+ machine,
report: status.report,
since_unix: status.since_unix,
})
@@ -270,6 +276,18 @@ pub(crate) enum ShownState {
}
impl AgentPaneStatus {
+ /// The state as the sidebars' status filter and the Agents panel's
+ /// groups name it: waiting and failed both need the user.
+ pub(crate) fn work_status(&self) -> crate::workspace_threads::WorkspaceThreadWorkStatus {
+ use crate::workspace_threads::WorkspaceThreadWorkStatus as Status;
+ match self.shown_state() {
+ ShownState::Working => Status::Running,
+ ShownState::Blocked | ShownState::Error => Status::NeedsAttention,
+ ShownState::Done => Status::FinishedUnseen,
+ ShownState::Idle | ShownState::Unknown => Status::Idle,
+ }
+ }
+
pub(crate) fn shown_state(&self) -> ShownState {
match self.state {
AgentState::Working => ShownState::Working,
@@ -713,6 +731,7 @@ mod tests {
window_id: None,
place: place.to_string(),
workspace: String::new(),
+ machine: String::new(),
report: None,
since_unix: 0,
}
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index 80c80b55..911a7704 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -662,6 +662,8 @@ pub(crate) struct NativeChromeSettings {
pub(crate) agent_panel_enabled: Option<bool>,
/// What is shown of the state programs report about themselves.
pub(crate) agent_status_display: NativeAgentStatusDisplay,
+ /// How the Agents panel's view menu filters, groups and orders it.
+ pub(crate) agents_panel_view: NativeAgentsPanelView,
/// The panels plugins add to the right sidebar, as the plugin host last
/// listed them (`plugins::follow_panels`): offered from the start,
/// before the host is asked.
@@ -801,6 +803,158 @@ impl Default for NativeAgentStatusDisplay {
}
}
+/// The parts of a program's own status report (OSC 7501) that can be
+/// switched on and off: in Settings › Agents and in the Agents panel's view
+/// menu, which flip the same settings.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum AgentStatusPart {
+ Description,
+ Reason,
+ Progress,
+ Subtasks,
+}
+
+impl AgentStatusPart {
+ /// In the order the Status Display card numbers them.
+ pub(crate) const ALL: [Self; 4] = [
+ Self::Description,
+ Self::Reason,
+ Self::Progress,
+ Self::Subtasks,
+ ];
+
+ pub(crate) fn label_key(self) -> &'static str {
+ match self {
+ Self::Description => "settings-agent-status-description",
+ Self::Reason => "settings-agent-status-reason",
+ Self::Progress => "settings-agent-status-progress",
+ Self::Subtasks => "settings-agent-status-subtasks",
+ }
+ }
+
+ pub(crate) fn description_key(self) -> &'static str {
+ match self {
+ Self::Description => "settings-agent-status-description-description",
+ Self::Reason => "settings-agent-status-reason-description",
+ Self::Progress => "settings-agent-status-progress-description",
+ Self::Subtasks => "settings-agent-status-subtasks-description",
+ }
+ }
+
+ pub(crate) fn shown(self, display: &NativeAgentStatusDisplay) -> bool {
+ match self {
+ Self::Description => display.description,
+ Self::Reason => display.reason,
+ Self::Progress => display.progress,
+ Self::Subtasks => display.subtasks,
+ }
+ }
+
+ pub(crate) fn toggle(self, display: &mut NativeAgentStatusDisplay) {
+ let shown = match self {
+ Self::Description => &mut display.description,
+ Self::Reason => &mut display.reason,
+ Self::Progress => &mut display.progress,
+ Self::Subtasks => &mut display.subtasks,
+ };
+ *shown = !*shown;
+ }
+}
+
+/// The Agents panel's view menu. Grouping and order are kept as keys, so a
+/// hand-edited value the app does not know falls back to the default
+/// instead of making the whole settings file unreadable.
+#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
+#[serde(default)]
+pub(crate) struct NativeAgentsPanelView {
+ /// States hidden, as the workspace sidebar's filter keys them.
+ pub(crate) hidden_statuses: Vec<String>,
+ /// Machines hidden, by the key
+ /// `workspace_threads::thread_place_and_machine_for_workspace` gives.
+ pub(crate) hidden_machines: Vec<String>,
+ pub(crate) group_by: String,
+ pub(crate) sort_by: String,
+}
+
+impl NativeAgentsPanelView {
+ pub(crate) fn group_by(&self) -> AgentsGroupBy {
+ match self.group_by.as_str() {
+ "thread" => AgentsGroupBy::Thread,
+ "none" => AgentsGroupBy::None,
+ _ => AgentsGroupBy::State,
+ }
+ }
+
+ pub(crate) fn sort_by(&self) -> AgentsSortBy {
+ match self.sort_by.as_str() {
+ "recent" => AgentsSortBy::Recent,
+ _ => AgentsSortBy::Fixed,
+ }
+ }
+
+ pub(crate) fn hides_status(&self, key: &str) -> bool {
+ self.hidden_statuses.iter().any(|hidden| hidden == key)
+ }
+
+ pub(crate) fn hides_machine(&self, key: &str) -> bool {
+ self.hidden_machines.iter().any(|hidden| hidden == key)
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum AgentsGroupBy {
+ /// Needing attention, running, done, idle: the default.
+ State,
+ Thread,
+ None,
+}
+
+impl AgentsGroupBy {
+ pub(crate) const ALL: [Self; 3] = [Self::State, Self::Thread, Self::None];
+
+ pub(crate) fn key(self) -> &'static str {
+ match self {
+ Self::State => "state",
+ Self::Thread => "thread",
+ Self::None => "none",
+ }
+ }
+
+ pub(crate) fn label_key(self) -> &'static str {
+ match self {
+ Self::State => "menu-group-state",
+ Self::Thread => "menu-group-thread",
+ Self::None => "menu-group-none",
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum AgentsSortBy {
+ /// By thread, agent and pane: rows never trade places on their own.
+ Fixed,
+ /// Whatever changed state last comes first.
+ Recent,
+}
+
+impl AgentsSortBy {
+ pub(crate) const ALL: [Self; 2] = [Self::Fixed, Self::Recent];
+
+ pub(crate) fn key(self) -> &'static str {
+ match self {
+ Self::Fixed => "fixed",
+ Self::Recent => "recent",
+ }
+ }
+
+ pub(crate) fn label_key(self) -> &'static str {
+ match self {
+ Self::Fixed => "menu-sort-fixed",
+ Self::Recent => "menu-sort-recent",
+ }
+ }
+}
+
pub(crate) const DEFAULT_REMOTE_SFTP_IDLE_MINUTES: u32 = 15;
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -2370,6 +2524,36 @@ pub(crate) fn agent_status_display() -> NativeAgentStatusDisplay {
load_shared().chrome.agent_status_display
}
+/// Flip one part of the status display from outside Settings (the Agents
+/// panel's view menu). Painting reads it live, so no reload is owed.
+pub(crate) fn toggle_agent_status_part(part: AgentStatusPart) -> anyhow::Result<()> {
+ update_ui_state_and_settings_window(|settings| {
+ part.toggle(&mut settings.chrome.agent_status_display)
+ })
+}
+
+/// `update_ui_state`, then the open Settings window brought up to it: that
+/// window saves its whole copy, so one still holding the old value would
+/// write it back on its next save.
+fn update_ui_state_and_settings_window(
+ edit: impl FnOnce(&mut ThinkTermNativeSettings),
+) -> anyhow::Result<()> {
+ let before = load();
+ update_ui_state(edit)?;
+ crate::settings_window::follow_open_settings_window(&before, &load());
+ Ok(())
+}
+
+/// The Agents panel's view menu, as a copy to change and save. Painting
+/// borrows it from `load_shared` instead.
+pub(crate) fn agents_panel_view() -> NativeAgentsPanelView {
+ load_shared().chrome.agents_panel_view.clone()
+}
+
+pub(crate) fn save_agents_panel_view(view: NativeAgentsPanelView) -> anyhow::Result<()> {
+ update_ui_state_and_settings_window(|settings| settings.chrome.agents_panel_view = view)
+}
+
pub(crate) fn remote_update_keeps_sessions() -> bool {
load().workspaces.remote_update_keeps_sessions
}
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index a42df505..9ba91cc2 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -1,6 +1,7 @@
use crate::tab_icons::RgbExt as _;
use crate::customglyph::{BlockKey, Poly};
use crate::glyphcache::CachedGlyph;
+use crate::native_settings::AgentStatusPart;
use crate::quad::{
HeapQuadAllocator, QuadTrait, TripleLayerQuadAllocator, TripleLayerQuadAllocatorTrait,
};
@@ -1380,63 +1381,6 @@ fn web_token_key(id: &str) -> u64 {
hasher.finish()
}
-/// The parts of a program's own status report (OSC 7501) the Status
-/// Display card switches on and off.
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-enum AgentStatusPart {
- Description,
- Reason,
- Progress,
- Subtasks,
-}
-
-impl AgentStatusPart {
- /// In the order the card numbers them.
- const ALL: [Self; 4] = [
- Self::Description,
- Self::Reason,
- Self::Progress,
- Self::Subtasks,
- ];
-
- fn label_key(self) -> &'static str {
- match self {
- Self::Description => "settings-agent-status-description",
- Self::Reason => "settings-agent-status-reason",
- Self::Progress => "settings-agent-status-progress",
- Self::Subtasks => "settings-agent-status-subtasks",
- }
- }
-
- fn description_key(self) -> &'static str {
- match self {
- Self::Description => "settings-agent-status-description-description",
- Self::Reason => "settings-agent-status-reason-description",
- Self::Progress => "settings-agent-status-progress-description",
- Self::Subtasks => "settings-agent-status-subtasks-description",
- }
- }
-
- fn shown(self, display: &crate::native_settings::NativeAgentStatusDisplay) -> bool {
- match self {
- Self::Description => display.description,
- Self::Reason => display.reason,
- Self::Progress => display.progress,
- Self::Subtasks => display.subtasks,
- }
- }
-
- fn toggle(self, display: &mut crate::native_settings::NativeAgentStatusDisplay) {
- let shown = match self {
- Self::Description => &mut display.description,
- Self::Reason => &mut display.reason,
- Self::Progress => &mut display.progress,
- Self::Subtasks => &mut display.subtasks,
- };
- *shown = !*shown;
- }
-}
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum SettingsAction {
SelectImportSource(ImportSource),
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 9b2738a0..43db39af 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -658,6 +658,18 @@ pub(crate) enum ContextMenuApplicationAction {
ToggleWorkspaceStatusFilter(crate::workspace_threads::WorkspaceThreadWorkStatus),
/// Sidebar view-options: transiently reveal archived projects.
ToggleWorkspaceShowArchived,
+ /// Agents panel view menu: show or hide agents in this state.
+ ToggleAgentsStatusFilter(crate::workspace_threads::WorkspaceThreadWorkStatus),
+ /// Agents panel view menu: show or hide the agents on this machine, by
+ /// `workspace_threads::thread_place_and_machine_for_workspace`.
+ ToggleAgentsMachineFilter(String),
+ SetAgentsGroupBy(crate::native_settings::AgentsGroupBy),
+ SetAgentsSortBy(crate::native_settings::AgentsSortBy),
+ /// Agents panel view menu: one part of programs' status reports, the
+ /// same switch Settings › Agents flips.
+ ToggleAgentStatusPart(crate::native_settings::AgentStatusPart),
+ /// Agents panel view menu: re-read the agent detection rules.
+ ReloadAgentRules,
/// Add a thread reference to a Space (local, non-home, not already
/// holding it — the menu only offers eligible targets).
AddThreadToCollection {
@@ -3147,6 +3159,10 @@ pub struct TermWindow {
/// the default. Each paint of the panel drops the ones with no
/// sub-tasks left, so the next batch starts folded again.
right_sidebar_agents_open_subtasks: HashSet<PaneId>,
+ /// What each agent's description was cut to, so a description that does
+ /// not fit is cut and measured once rather than every frame. Each paint
+ /// of the panel drops the agents that have gone.
+ right_sidebar_agents_fitted: HashMap<PaneId, ui::agent_panel::FittedDescription>,
right_sidebar_snippet_view: RightSidebarSnippetView,
right_sidebar_snippet_focus: Option<RightSidebarSnippetField>,
right_sidebar_snippet_search: TextInputState,
@@ -4738,6 +4754,7 @@ impl TermWindow {
right_sidebar_mode: RightSidebarMode::Snippets,
right_sidebar_agents_scroll: 0.0,
right_sidebar_agents_open_subtasks: HashSet::new(),
+ right_sidebar_agents_fitted: HashMap::new(),
right_sidebar_snippet_view: RightSidebarSnippetView::List,
right_sidebar_snippet_focus: None,
right_sidebar_snippet_search: TextInputState::new(),
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index 47e24c8e..ee7436df 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -6050,47 +6050,13 @@ impl super::TermWindow {
}
fn workspace_sidebar_view_options_menu_items(&mut self) -> Vec<ContextMenuItem> {
- use crate::workspace_threads::WorkspaceThreadWorkStatus;
use config::keyassignment::KeyAssignment;
self.begin_context_menu_application_actions();
let hidden = crate::native_settings::workspace_sidebar_hidden_statuses();
- let mut status_items = Vec::new();
- for (label, icon, status) in [
- (
- crate::i18n::tr("menu-status-running"),
- ContextMenuIcon::Refresh,
- WorkspaceThreadWorkStatus::Running,
- ),
- (
- crate::i18n::tr("menu-status-attention"),
- ContextMenuIcon::Warning,
- WorkspaceThreadWorkStatus::NeedsAttention,
- ),
- (
- crate::i18n::tr("menu-status-done"),
- ContextMenuIcon::Check,
- WorkspaceThreadWorkStatus::FinishedUnseen,
- ),
- (
- crate::i18n::tr("menu-status-idle"),
- ContextMenuIcon::Info,
- WorkspaceThreadWorkStatus::Idle,
- ),
- ] {
- let visible = !hidden.iter().any(|key| key == status.settings_key());
- status_items.push(
- self.context_menu_application_item_with_icon(
- label,
- icon,
- crate::termwindow::ContextMenuApplicationAction::ToggleWorkspaceStatusFilter(
- status,
- ),
- true,
- )
- .checked(visible),
- );
- }
+ let status_items = self.status_filter_menu_items(&hidden, |status| {
+ crate::termwindow::ContextMenuApplicationAction::ToggleWorkspaceStatusFilter(status)
+ });
vec![
ContextMenuItem::section_header(crate::i18n::tr("menu-group-by")),
@@ -6141,22 +6107,10 @@ impl super::TermWindow {
&mut self,
status: crate::workspace_threads::WorkspaceThreadWorkStatus,
) {
- let mut hidden = crate::native_settings::workspace_sidebar_hidden_statuses();
- let key = status.settings_key();
- if let Some(index) = hidden.iter().position(|entry| entry == key) {
- hidden.remove(index);
- } else {
- hidden.push(key.to_string());
- let parsed = hidden
- .iter()
- .filter_map(|entry| {
- crate::workspace_threads::WorkspaceThreadWorkStatus::from_settings_key(entry)
- })
- .collect::<Vec<_>>();
- if crate::workspace_threads::hidden_statuses_cover_all(&parsed) {
- return;
- }
- }
+ let hidden = crate::native_settings::workspace_sidebar_hidden_statuses();
+ let Some(hidden) = crate::workspace_threads::toggle_hidden_status(hidden, status) else {
+ return;
+ };
if let Err(err) = crate::native_settings::save_workspace_sidebar_hidden_statuses(hidden) {
log::warn!("failed to save sidebar status filter: {err:#}");
}
diff --git a/wezterm-gui/src/termwindow/ui/agent_panel.rs b/wezterm-gui/src/termwindow/ui/agent_panel.rs
index ec09f4b8..6d9955b7 100644
--- a/wezterm-gui/src/termwindow/ui/agent_panel.rs
+++ b/wezterm-gui/src/termwindow/ui/agent_panel.rs
@@ -4,12 +4,11 @@
//! snapshots — the paint path never triggers detection or filesystem
//! probes.
-use crate::agent_status::{self, AgentIcon, AgentPanelAction, AgentState, ProgramReportState};
+use crate::agent_status::{self, AgentIcon, AgentPanelAction, ProgramReportState};
use crate::quad::TripleLayerQuadAllocator;
use crate::termwindow::ui::icons::SvgIcon;
use crate::termwindow::ui::right_sidebar::{
right_sidebar_file_row_metrics, sidebar_row_element_visible, FILE_SCROLL_FADE_HEIGHT,
- SNIPPET_ROW_GAP,
};
use crate::termwindow::ui::tokens::{SIDEBAR_ICON_GAP, SIDEBAR_INSET, SIDEBAR_ROW_RADIUS};
use crate::termwindow::{TermWindow, TermWindowNotif, UIItem, UIItemType};
@@ -37,93 +36,33 @@ pub(crate) const AGENT_DONE_COLOR: LinearRgba =
crate::termwindow::ui::sidebar::SESSION_STATUS_DONE_COLOR;
/// The progress bar under a row's description.
const AGENT_PROGRESS_HEIGHT: usize = 6;
+/// Between two agent rows; a hairline sits in the middle of it.
+const AGENT_ROW_GAP: usize = 10;
+/// How much further in than the panel's inset agent rows start and end.
+const AGENT_ROW_EXTRA_INSET: usize = 6;
/// Sub-task lines a row shows before it says how many more there are.
const AGENT_SUBTASKS_SHOWN: usize = 5;
-/// What the toolbar line reports when the list is not empty.
-#[derive(Clone, Copy, Default)]
-pub(crate) struct AgentCounts {
- total: usize,
- working: usize,
- blocked: usize,
- errored: usize,
- idle: usize,
- unknown: usize,
-}
-
-impl AgentCounts {
- fn tally(agents: &[agent_status::AgentPaneStatus]) -> Self {
- let mut counts = Self {
- total: agents.len(),
- ..Default::default()
- };
- for agent in agents {
- match agent.state {
- AgentState::Working => counts.working += 1,
- AgentState::Blocked => counts.blocked += 1,
- AgentState::Error => counts.errored += 1,
- AgentState::Idle => counts.idle += 1,
- AgentState::Unknown => counts.unknown += 1,
- }
- }
- counts
- }
-
- fn count_text(id: &'static str, count: usize) -> String {
- let mut args = fluent_bundle::FluentArgs::new();
- args.set("count", count);
- crate::i18n::tr_args(id, &args)
- }
-
- /// "2 working · 1 needs input", naming only what is actually happening;
- /// with nothing running or waiting it falls back to the idle and
- /// unknown counts — each labeled as what it is, so three Unknown panes
- /// never read as "3 idle".
- fn describe(self) -> String {
- let mut parts = Vec::new();
- if self.working > 0 {
- parts.push(Self::count_text("right-agents-count-working", self.working));
- }
- if self.blocked > 0 {
- parts.push(Self::count_text("right-agents-count-blocked", self.blocked));
- }
- if self.errored > 0 {
- parts.push(Self::count_text("right-agents-count-error", self.errored));
- }
- if parts.is_empty() {
- if self.idle > 0 || self.unknown == 0 {
- parts.push(Self::count_text("right-agents-count-idle", self.idle));
- }
- if self.unknown > 0 {
- parts.push(Self::count_text("right-agents-count-unknown", self.unknown));
- }
- }
- parts.join(" \u{b7} ")
- }
-}
-
impl TermWindow {
- /// Height of the strip above the list: the reload button, the optional
- /// status line, and the gap before the first row. The scroll mask covers
- /// exactly this, so the two must be derived from the same numbers.
/// The strip above the list: one row holding the status line and the
- /// reload button, plus the gap before the first row. It doubles as the
+ /// view-menu button, plus the gap before the first row. It doubles as the
/// top scroll mask, so this is also how far overflow may be erased.
fn agents_toolbar_height(&self, cell_height: usize) -> usize {
self.agents_toolbar_button_height(cell_height) + self.ui_px(8)
}
- /// Two lines -- identity, then state and place -- with the same share of
- /// vertical padding a file row gives its single line.
+ /// Two lines -- the title, then where it runs -- with the same share of
+ /// vertical padding a file row gives its single line. The lines of a
+ /// card sit close: they are one agent, and the gaps between cards and
+ /// the hairlines are what part them.
fn agents_row_height(&self, cell_height: usize) -> (usize, usize) {
- let line_gap = (cell_height * 3 / 10).max(1);
+ let line_gap = (cell_height / 20).max(1);
let padding = (cell_height * 7 / 10).max(1);
(cell_height * 2 + line_gap + padding, line_gap)
}
- /// The reload control is a compact icon button in the top-right, the
- /// same shape the Files panel gives its refresh: a full-width pill for
- /// a control this rarely used dominated the panel.
+ /// The view-menu button: a compact icon button in the top-right, the
+ /// same shape the Files panel gives its refresh.
fn agents_toolbar_button_height(&self, cell_height: usize) -> usize {
(cell_height + self.ui_px(12)).max(self.ui_px(28))
}
@@ -144,37 +83,36 @@ impl TermWindow {
content_top: usize,
content_width: usize,
status: Option<&str>,
- counts: AgentCounts,
+ has_agents: bool,
) -> anyhow::Result<()> {
let cell_height = ui_metrics.cell_size.height as usize;
let button_height = self.agents_toolbar_button_height(cell_height);
let button_size = button_height.min(content_width);
+ // The view menu, at the right edge: what to show, how to group and
+ // order it, which parts of a report to show, and the rules reload.
+ let view_x = content_x + content_width.saturating_sub(button_size);
self.paint_files_preview_header_icon_button(
layers,
chrome,
foreground,
muted_fg,
- content_x + content_width.saturating_sub(button_size),
+ view_x,
content_top,
button_size,
- // The circular-arrow refresh glyph the Files panel also uses.
- // (The tempting `Redo` variant is a hooked arrow that reads as
- // half a glyph once there is no label beside it.)
- SvgIcon::RotateCcw,
- UIItemType::RightSidebarAgent(AgentPanelAction::ReloadRules),
+ SvgIcon::SlidersHorizontal,
+ UIItemType::RightSidebarAgent(AgentPanelAction::ViewOptions),
)?;
- // The line to the left of that button. A reload acknowledgement
- // takes it over while it lives, because it is the answer to the
- // click that just happened; otherwise it says what the panel is
- // currently showing -- which is also the only place that explains
- // an empty list.
+ // The line to the left of that button, only when there is something
+ // to say: a reload acknowledgement while it lives, because it is the
+ // answer to the click that just happened, or why the list is empty.
+ // A running count would only repeat the group headings, cut short.
let detection_on = agent_status::enabled();
let line = match status {
Some(status) => status.to_string(),
None if !detection_on => crate::i18n::tr("right-agents-detection-off"),
- None if counts.total == 0 => crate::i18n::tr("right-agents-none"),
- None => counts.describe(),
+ None if !has_agents => crate::i18n::tr("right-agents-none"),
+ None => String::new(),
};
if status.is_some() {
// The acknowledgement expires by TTL, but expiry alone paints
@@ -185,11 +123,10 @@ impl TermWindow {
}
let text_x = content_x + self.ui_px(SIDEBAR_INSET);
let text_y = content_top + (button_height.saturating_sub(cell_height)) / 2;
- let text_width = content_x
- .saturating_add(content_width)
- .saturating_sub(button_size + self.ui_px(SIDEBAR_ICON_GAP))
+ let text_width = view_x
+ .saturating_sub(self.ui_px(SIDEBAR_ICON_GAP))
.saturating_sub(text_x);
- self.paint_sidebar_text(
+ self.paint_agent_text(
layers, ui_font, ui_metrics, &line, text_x, text_y, text_width, muted_fg,
)?;
// Only the "detection is off" line is actionable: it names the
@@ -210,8 +147,6 @@ impl TermWindow {
pub(crate) fn paint_agents_sidebar(
&mut self,
layers: &mut TripleLayerQuadAllocator,
- ui_font: &Rc<LoadedFont>,
- ui_metrics: RenderMetrics,
chrome: UiPalette,
foreground: LinearRgba,
muted_fg: LinearRgba,
@@ -220,6 +155,18 @@ impl TermWindow {
content_width: usize,
content_bottom: usize,
) -> anyhow::Result<()> {
+ // The sidebar's own face is medium weight -- bold off macOS -- and
+ // with every line of a card in it, a semibold title barely stood
+ // out. The panel sets its lines in the regular weight instead, so
+ // the titles and headings, semibold, read as such.
+ let settings = crate::native_settings::load_shared();
+ let font_size = crate::native_settings::right_sidebar_font_size(&settings);
+ let body_font = self
+ .fonts
+ .title_font_with_size_and_weight(font_size, 400)
+ .context("agents panel body font")?;
+ let ui_font = &body_font;
+ let ui_metrics = RenderMetrics::with_font_metrics(&body_font.metrics());
let cell_height = ui_metrics.cell_size.height as usize;
let (row_height, line_gap) = self.agents_row_height(cell_height);
// Read once: the status expires on a TTL, and asking twice could size
@@ -232,6 +179,8 @@ impl TermWindow {
let mut agents = agent_status::list_agent_panes();
// An open list lasts as long as its sub-tasks: the next batch starts
// folded, and an agent that has gone leaves nothing behind.
+ self.right_sidebar_agents_fitted
+ .retain(|pane_id, _| agents.iter().any(|agent| agent.pane_id == *pane_id));
self.right_sidebar_agents_open_subtasks.retain(|pane_id| {
agents.iter().any(|agent| {
agent.pane_id == *pane_id
@@ -241,7 +190,7 @@ impl TermWindow {
.is_some_and(|report| !report.children.is_empty())
})
});
- let counts = AgentCounts::tally(&agents);
+ let has_agents = !agents.is_empty();
if agents.is_empty() {
// Nothing but the toolbar: an empty-state card here is a large
// bordered box explaining that a list is empty, which the
@@ -258,11 +207,21 @@ impl TermWindow {
content_top,
content_width,
status.as_deref(),
- counts,
+ has_agents,
);
}
+ // The view menu's choices: what is hidden, then how the rest is
+ // grouped and ordered.
+ // Borrowed from the shared settings, not copied: this runs per frame.
+ let view = &settings.chrome.agents_panel_view;
+ agents.retain(|agent| {
+ !view.hides_status(agent.work_status().settings_key())
+ && !view.hides_machine(&agent.machine)
+ });
agent_status::sort_for_display(&mut agents);
+ order_for_view(&mut agents, view);
+ let entries = panel_entries(&agents, view.group_by());
// Borrow the file tree's row chrome wholesale so the two lists read as
// one control: same height, same icon size, same gaps, all derived from
@@ -285,14 +244,60 @@ impl TermWindow {
sidebar_row_element_visible(elem_y, elem_height, content_top, list_top, overflow_bottom)
};
let visible_height = viewport_bottom.saturating_sub(list_top);
- // Rows are spaced like snippet cards: each one starts a gap below the
- // last, and the last has no trailing gap, so it is not part of the
- // scrollable height either. A row is two lines tall, and grows below
- // them by what its program reported, as far as the user chose to
- // see it.
- let row_gap = self.ui_px(SNIPPET_ROW_GAP);
+ // Each row starts a gap below the last, and the last has no trailing
+ // gap, so it is not part of the scrollable height either. The gap is
+ // tighter than the snippet cards' now that a hairline parts the
+ // rows. A row is two lines tall, and grows below them by what its
+ // program reported, as far as the user chose to see it.
+ let row_gap = self.ui_px(AGENT_ROW_GAP);
let show = crate::native_settings::agent_status_display();
+ // A card is its title, semibold and bright, over lines in one grey:
+ // weight sets the title apart, so the lines under it need not
+ // compete in brightness. Errors stay red; a working description
+ // shimmers.
+ // Between rows of a group: plain enough to stay out of the way, but
+ // a shade firmer than the separator token, which vanished here.
+ let divider = muted_fg.mul_alpha(0.22);
+ // A working description shimmers from the quieter grey up to white
+ // (black on a light theme): from the brighter grey the light that
+ // passed was too close to the text to see.
+ let shimmer_peak = if chrome.is_dark() {
+ LinearRgba::with_components(1.0, 1.0, 1.0, foreground.3)
+ } else {
+ LinearRgba::with_components(0.0, 0.0, 0.0, foreground.3)
+ };
+ // Its colours are blended once a frame, not once a glyph: steps this
+ // fine are closer than the eye tells apart across a band this narrow.
+ let shimmer_ramp: [LinearRgba; SHIMMER_RAMP_STEPS] = std::array::from_fn(|step| {
+ crate::ui::color::mix(
+ muted_fg,
+ shimmer_peak,
+ step as f32 / (SHIMMER_RAMP_STEPS - 1) as f32,
+ )
+ });
let bar_height = self.ui_px(AGENT_PROGRESS_HEIGHT);
+ // Every row puts its text between the same two edges; a row with no
+ // state icon reaches further right.
+ // Rows keep a little more room from the panel's edges than its
+ // other lines: the brand marks sat against the edge.
+ let row_inset = inset + self.ui_px(AGENT_ROW_EXTRA_INSET);
+ let icon_x = content_x + row_inset;
+ // Both icons a line of text tall: they sit on the title line, and at
+ // the file tree's size they stood taller than the line they marked.
+ let icon_size = metrics.icon_size.min(cell_height);
+ let text_x = icon_x + icon_size + metrics.icon_gap;
+ let state_size = icon_size;
+ let state_x = content_x + content_width - row_inset - state_size;
+ let text_right_for = |has_state_icon: bool| {
+ if has_state_icon {
+ state_x.saturating_sub(metrics.icon_gap)
+ } else {
+ content_x + content_width - row_inset
+ }
+ };
+ // One clock reading for the whole panel, so its spinners and
+ // shimmers step together.
+ let frames = crate::termwindow::ui::status_icon::spinner_frames();
let layouts: Vec<AgentRowLayout> = agents
.iter()
.map(|agent| {
@@ -307,25 +312,130 @@ impl TermWindow {
)
})
.collect();
- let total_height = layouts
- .iter()
- .map(|layout| layout.height + row_gap)
- .sum::<usize>()
- .saturating_sub(row_gap);
+ // Card titles and group headings: the rows' size, semibold. Shaped
+ // once and cached like every sidebar line, so the second weight
+ // costs nothing per frame. Headings take the grey, so a heading
+ // does not compete with the titles under it.
+ let header_font = self
+ .fonts
+ .title_font_with_size_and_weight(font_size, 600)
+ .context("agents group heading font")?;
+ let header_metrics = RenderMetrics::with_font_metrics(&header_font.metrics());
+ let header_height = header_metrics.cell_size.height as usize;
+ // Where each entry starts: a row a gap below whatever came before it,
+ // a group's first row a little closer under its heading.
+ let header_gap = self.ui_px(4);
+ let mut tops = Vec::with_capacity(entries.len());
+ let mut total_height = 0usize;
+ for (index, entry) in entries.iter().enumerate() {
+ if index > 0 {
+ total_height += match entries[index - 1] {
+ PanelEntry::Header { .. } => header_gap,
+ PanelEntry::Agent(_) => row_gap,
+ };
+ }
+ tops.push(total_height);
+ total_height += match *entry {
+ PanelEntry::Header { .. } => header_height,
+ PanelEntry::Agent(row) => layouts[row].height,
+ };
+ }
let max_scroll = total_height.saturating_sub(visible_height) as f32;
self.right_sidebar_agents_scroll = self.right_sidebar_agents_scroll.clamp(0.0, max_scroll);
let scroll = self.right_sidebar_agents_scroll;
- let mut offset = 0usize;
- for (agent, layout) in agents.iter().zip(&layouts) {
- let row_top = list_top as f32 + offset as f32 - scroll;
- offset += layout.height + row_gap;
- if row_top + layout.height as f32 <= list_top as f32 {
- continue;
- }
+ if entries.is_empty() {
+ // Agents there are, but the view menu hides every one: say so
+ // where the list would be, or the panel reads as broken.
+ let line = crate::i18n::tr("right-agents-all-hidden");
+ self.paint_agent_text(
+ layers,
+ ui_font,
+ ui_metrics,
+ &line,
+ content_x + inset,
+ list_top,
+ content_width.saturating_sub(inset * 2),
+ muted_fg,
+ )?;
+ }
+ for (index, entry) in entries.iter().enumerate() {
+ let row_top = list_top as f32 + tops[index] as f32 - scroll;
if row_top >= viewport_bottom as f32 {
break;
}
+ let row = match entry {
+ PanelEntry::Header { label, count } => {
+ let y = row_top.floor().max(0.0) as usize;
+ if visible(y, header_height) {
+ // The count keeps its room; a long thread name is
+ // what gives way.
+ let count = count.to_string();
+ let gap = self.ui_px(SIDEBAR_ICON_GAP);
+ let count_width = self
+ .cached_ui_text_advance(&header_font, &header_metrics, &count)?
+ .ceil() as usize;
+ let label_x = icon_x;
+ // Between the rows' edges: the count ends where
+ // their state icons do.
+ let label_room = (content_x + content_width)
+ .saturating_sub(row_inset)
+ .saturating_sub(label_x)
+ .saturating_sub(count_width + gap);
+ let label_width = (self
+ .cached_ui_text_advance(&header_font, &header_metrics, label)?
+ .ceil() as usize)
+ .min(label_room);
+ self.paint_agent_text(
+ layers,
+ &header_font,
+ header_metrics,
+ label,
+ label_x,
+ y,
+ label_room,
+ muted_fg,
+ )?;
+ self.paint_agent_text(
+ layers,
+ &header_font,
+ header_metrics,
+ &count,
+ label_x + label_width + gap,
+ y,
+ count_width,
+ muted_fg,
+ )?;
+ }
+ continue;
+ }
+ PanelEntry::Agent(row) => *row,
+ };
+ let (agent, layout) = (&agents[row], &layouts[row]);
+ // A hairline in the gap above a row that follows another in its
+ // group, in the separator colour: it parts the agents without
+ // boxing them in. A heading parts the groups.
+ if index > 0 && matches!(entries[index - 1], PanelEntry::Agent(_)) {
+ let y = (row_top - row_gap as f32 / 2.0).floor();
+ if y >= list_top as f32 && y < viewport_bottom as f32 {
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(
+ (content_x + inset) as f32,
+ y,
+ content_width.saturating_sub(inset * 2) as f32,
+ 1.0,
+ ),
+ divider,
+ 0.0,
+ )
+ .context("agent row divider")?;
+ }
+ }
+ if row_top + layout.height as f32 <= list_top as f32 {
+ continue;
+ }
let Some(band) =
agent_row_visible_band(row_top, layout.height, list_top, row_clip_bottom)
else {
@@ -366,11 +476,12 @@ impl TermWindow {
}),
});
- // The icons stay beside the two lines every row has, however far
- // the row grows below them.
- let icon_x = content_x + inset;
- let icon_y = top + (row_height.saturating_sub(metrics.icon_size)) / 2;
- if visible(icon_y, metrics.icon_size) {
+ // Both icons sit on the title line, however far the row grows
+ // below it.
+ let title_y = top + (row_height.saturating_sub(cell_height * 2 + line_gap)) / 2;
+ let title_mid = title_y + cell_height / 2;
+ let icon_y = title_mid.saturating_sub(icon_size / 2);
+ if visible(icon_y, icon_size) {
match agent_status::brand_icon(
&agent.agent_id,
crate::native_settings::effective_appearance(),
@@ -380,14 +491,14 @@ impl TermWindow {
brand,
icon_x,
icon_y,
- metrics.icon_size,
+ icon_size,
)?,
Some(AgentIcon::Mono(icon)) => self.paint_sidebar_icon(
layers,
icon,
icon_x,
icon_y,
- metrics.icon_size,
+ icon_size,
muted_fg,
)?,
None => self.paint_sidebar_icon(
@@ -395,38 +506,30 @@ impl TermWindow {
SvgIcon::Bot,
icon_x,
icon_y,
- metrics.icon_size,
+ icon_size,
muted_fg,
)?,
}
}
let shown = agent.shown_state();
- let state_size = metrics.icon_size;
- let state_x = content_x + content_width - inset - state_size;
- let state_y = top + (row_height.saturating_sub(state_size)) / 2;
+ let state_y = title_mid.saturating_sub(state_size / 2);
let state_icon = agent_state_icon(shown, chrome, muted_fg);
let has_state_icon = state_icon.is_some();
if let Some((icon, color, spinning)) =
state_icon.filter(|_| visible(state_y, state_size))
{
if spinning {
- self.paint_spinning_ui_icon(
- layers, 2, icon, state_x, state_y, state_size, color,
+ self.paint_spinning_ui_icon_at(
+ layers, 2, icon, state_x, state_y, state_size, color, frames,
)?;
} else {
self.paint_sidebar_icon(layers, icon, state_x, state_y, state_size, color)?;
}
}
- let text_x = icon_x + metrics.icon_size + metrics.icon_gap;
- let text_right = if has_state_icon {
- state_x.saturating_sub(metrics.icon_gap)
- } else {
- content_x + content_width - inset
- };
+ let text_right = text_right_for(has_state_icon);
let text_width = text_right.saturating_sub(text_x);
- let title_y = top + (row_height.saturating_sub(cell_height * 2 + line_gap)) / 2;
let name = agent_status::display_name(&agent.agent_id);
let title_line = if agent.title.is_empty() {
name
@@ -434,10 +537,10 @@ impl TermWindow {
format!("{name} · {}", agent.title)
};
if visible(title_y, cell_height) {
- self.paint_sidebar_text(
+ self.paint_agent_text(
layers,
- ui_font,
- ui_metrics,
+ &header_font,
+ header_metrics,
&title_line,
text_x,
title_y,
@@ -445,61 +548,95 @@ impl TermWindow {
foreground,
)?;
}
- let state_label = crate::i18n::tr(agent_state_key(shown));
+
+ // Under the title: what it is doing, then where. The state icon
+ // already says the state, so the words only stand in for it
+ // when there is no icon, or nothing else to put on the line --
+ // and for Idle, whose check differs from Done's only in colour.
+ let mut line_y = title_y + cell_height + line_gap;
+ if let Some(report) = agent.report.as_ref().filter(|_| layout.message) {
+ if visible(line_y, cell_height) {
+ let mut x = text_x;
+ if let Some(kind) = report.kind.filter(|_| show.reason) {
+ let label = crate::i18n::tr(agent_status::blocked_kind_key(kind));
+ x = self.paint_agent_kind_pill(
+ layers, ui_font, ui_metrics, &label, x, line_y, text_right,
+ )?;
+ }
+ if let Some(msg) = report.msg.as_deref().filter(|_| show.description) {
+ let width = text_right.saturating_sub(x);
+ let fitted =
+ self.fitted_description(agent.pane_id, ui_font, &ui_metrics, msg, width)?;
+ let msg = fitted.as_deref().unwrap_or(msg);
+ match shown {
+ agent_status::ShownState::Working => {
+ let advance =
+ self.cached_ui_text_advance(ui_font, &ui_metrics, msg)?;
+ let travel = advance.min(width as f32) + (x - text_x) as f32;
+ let shimmer = ShimmerBand::at(frames, travel, cell_height as f32);
+ self.paint_agent_shimmer_text(
+ layers,
+ ui_font,
+ ui_metrics,
+ msg,
+ x,
+ line_y,
+ width,
+ text_x,
+ shimmer,
+ &shimmer_ramp,
+ )?
+ }
+ agent_status::ShownState::Error => self.paint_agent_text(
+ layers,
+ ui_font,
+ ui_metrics,
+ msg,
+ x,
+ line_y,
+ width,
+ chrome.danger,
+ )?,
+ _ => self.paint_agent_text(
+ layers, ui_font, ui_metrics, msg, x, line_y, width, muted_fg,
+ )?,
+ }
+ }
+ }
+ line_y += cell_height + line_gap;
+ }
// The thread's human name, resolved once per snapshot -- never the
// internal workspace id, and never a per-frame store walk.
- let detail_line = if agent.place.is_empty() {
- state_label
+ let place_line = if has_state_icon
+ && shown != agent_status::ShownState::Idle
+ && !agent.place.is_empty()
+ {
+ agent.place.clone()
} else {
- format!("{state_label} · {}", agent.place)
+ let state_label = crate::i18n::tr(agent_state_key(shown));
+ if agent.place.is_empty() {
+ state_label
+ } else {
+ format!("{state_label} · {}", agent.place)
+ }
};
- let detail_y = title_y + cell_height + line_gap;
- if visible(detail_y, cell_height) {
- self.paint_sidebar_text(
+ if visible(line_y, cell_height) {
+ self.paint_agent_text(
layers,
ui_font,
ui_metrics,
- &detail_line,
+ &place_line,
text_x,
- detail_y,
+ line_y,
text_width,
muted_fg,
)?;
}
+ line_y += cell_height + line_gap;
let Some(report) = agent.report.as_ref() else {
continue;
};
- let mut line_y = detail_y + cell_height + line_gap;
- if layout.message {
- if visible(line_y, cell_height) {
- let mut x = text_x;
- if let Some(kind) = report.kind.filter(|_| show.reason) {
- let label = crate::i18n::tr(agent_status::blocked_kind_key(kind));
- x = self.paint_agent_kind_pill(
- layers, ui_font, ui_metrics, &label, x, line_y, text_right,
- )?;
- }
- if let Some(msg) = report.msg.as_deref().filter(|_| show.description) {
- let color = if shown == agent_status::ShownState::Error {
- chrome.danger
- } else {
- chrome.secondary_text
- };
- self.paint_sidebar_text(
- layers,
- ui_font,
- ui_metrics,
- msg,
- x,
- line_y,
- text_right.saturating_sub(x),
- color,
- )?;
- }
- }
- line_y += cell_height + line_gap;
- }
if let Some(progress) = layout.progress {
if visible(line_y, bar_height) {
let radius = bar_height as f32 / 2.0;
@@ -532,6 +669,8 @@ impl TermWindow {
}
let sub_icon = (cell_height * 4 / 5).max(1);
let sub_text_gap = sub_icon + self.ui_px(SIDEBAR_ICON_GAP) / 2;
+ // An open list's guide drops from just under the chevron.
+ let guide_top = line_y + (cell_height.saturating_sub(sub_icon)) / 2 + sub_icon;
if layout.subtask_count > 0 {
// The fold line is its own target over the row's: a click on
// it opens or folds the list rather than revealing the pane.
@@ -572,14 +711,17 @@ impl TermWindow {
.iter()
.filter(|child| matches!(child.state, ProgramReportState::Working))
.count();
- if working > 0 {
+ // Unless every sub-task has its dot in view, this line is
+ // all there is to say how many run: folded, or with some
+ // cut off below the list.
+ if working > 0 && layout.subtasks < layout.subtask_count {
let mut args = fluent_bundle::FluentArgs::new();
args.set("count", working);
let working = crate::i18n::tr_args("right-agents-count-working", &args);
line = format!("{line} · {working}");
}
let line_x = text_x + sub_text_gap;
- self.paint_sidebar_text(
+ self.paint_agent_text(
layers,
ui_font,
ui_metrics,
@@ -590,13 +732,14 @@ impl TermWindow {
if fold_hovered {
foreground
} else {
- chrome.secondary_text
+ muted_fg
},
)?;
}
line_y += cell_height + line_gap;
}
- // An open list sits under the fold line's words, a level in.
+ // An open list sits under the fold line's words, a level in, and
+ // hangs off a guide dropped from the chevron.
let list_x = text_x + sub_text_gap;
for child in report.children.iter().take(layout.subtasks) {
if visible(line_y, cell_height) {
@@ -607,17 +750,23 @@ impl TermWindow {
ProgramReportState::Done => agent_status::ShownState::Done,
ProgramReportState::Idle => agent_status::ShownState::Idle,
};
- let icon_y = line_y + (cell_height.saturating_sub(sub_icon)) / 2;
- if let Some((icon, color, spinning)) =
- agent_state_icon(child_state, chrome, muted_fg)
- {
- if spinning {
- self.paint_spinning_ui_icon(
- layers, 2, icon, list_x, icon_y, sub_icon, color,
- )?;
- } else {
- self.paint_sidebar_icon(layers, icon, list_x, icon_y, sub_icon, color)?;
- }
+ // A dot in the state's colour, never a spinner: only the
+ // row's own spinner and its description move.
+ if let Some((_, color, _)) = agent_state_icon(child_state, chrome, muted_fg) {
+ let dot = (cell_height * 2 / 5).max(self.ui_px(4));
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(
+ (list_x + sub_icon.saturating_sub(dot) / 2) as f32,
+ (line_y + cell_height.saturating_sub(dot) / 2) as f32,
+ dot as f32,
+ dot as f32,
+ ),
+ color,
+ dot as f32 / 2.0,
+ )
+ .context("agent sub-task dot")?;
}
let name = child
.title
@@ -632,7 +781,7 @@ impl TermWindow {
None => name.to_string(),
};
let line_x = list_x + sub_text_gap;
- self.paint_sidebar_text(
+ self.paint_agent_text(
layers,
ui_font,
ui_metrics,
@@ -640,16 +789,39 @@ impl TermWindow {
line_x,
line_y,
text_right.saturating_sub(line_x),
- chrome.secondary_text,
+ muted_fg,
)?;
}
line_y += cell_height + line_gap;
}
+ if layout.subtasks > 0 {
+ // Down to the last dot's line; the "more" line has no dot.
+ let top = guide_top.max(band.visible_y);
+ let bottom = line_y
+ .saturating_sub(line_gap)
+ .min(band.visible_y + band.visible_height);
+ if bottom > top {
+ let guide = self.ui_px(1).max(1);
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(
+ (text_x + sub_icon / 2) as f32,
+ top as f32,
+ guide as f32,
+ (bottom - top) as f32,
+ ),
+ chrome.separator,
+ 0.0,
+ )
+ .context("agent sub-task guide")?;
+ }
+ }
if layout.more_subtasks > 0 && visible(line_y, cell_height) {
let mut args = fluent_bundle::FluentArgs::new();
args.set("count", layout.more_subtasks);
let more = crate::i18n::tr_args("right-agents-more-subtasks", &args);
- self.paint_sidebar_text(
+ self.paint_agent_text(
layers,
ui_font,
ui_metrics,
@@ -687,7 +859,7 @@ impl TermWindow {
content_top,
content_width,
status.as_deref(),
- counts,
+ has_agents,
)?;
if scrolled {
let fade_height = self
@@ -706,6 +878,158 @@ impl TermWindow {
Ok(())
}
+ /// One line of the panel in one colour. See `paint_agent_text_with`.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_agent_text(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ font: &Rc<LoadedFont>,
+ metrics: RenderMetrics,
+ text: &str,
+ x: usize,
+ y: usize,
+ width: usize,
+ color: LinearRgba,
+ ) -> anyhow::Result<()> {
+ self.paint_agent_text_with(layers, font, metrics, text, x, y, width, |_| color)
+ }
+
+ /// One line of the panel, whole when it fits; when it does not, faded
+ /// out towards its right edge rather than cut short with an ellipsis.
+ /// `color_at` is asked for each glyph by where its middle falls, from
+ /// `x`. The painter visits glyphs in order and asks before drawing each,
+ /// so the pen here keeps pace with its; nothing is allocated, and a
+ /// glyph the fade has taken to nothing is where drawing stops.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_agent_text_with(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ font: &Rc<LoadedFont>,
+ metrics: RenderMetrics,
+ text: &str,
+ x: usize,
+ y: usize,
+ width: usize,
+ mut color_at: impl FnMut(f32) -> LinearRgba,
+ ) -> anyhow::Result<()> {
+ if text.is_empty() || width == 0 {
+ return Ok(());
+ }
+ let (shaped, _) = self.cached_ui_shape(font, &metrics, text)?;
+ let advance: f32 = shaped
+ .iter()
+ .map(|info| info.glyph.x_advance.get() as f32)
+ .sum();
+ let width = width as f32;
+ let fade = if advance > width {
+ self.ui_f32(AGENT_TEXT_FADE).min(width)
+ } else {
+ 0.0
+ };
+ let mut pen = 0.0f32;
+ self.paint_cached_ui_shape_clipped(
+ layers,
+ &metrics,
+ &shaped,
+ x as f32,
+ y as f32,
+ x as f32,
+ x as f32 + width,
+ |info| {
+ let glyph_advance = info.glyph.x_advance.get() as f32;
+ let middle = pen + glyph_advance / 2.0;
+ pen += glyph_advance;
+ let color = color_at(middle);
+ if fade > 0.0 {
+ // Eased, so the glyphs at the edge are all but gone and
+ // the one too long to fit is not missed.
+ let t = ((width - middle) / fade).clamp(0.0, 1.0);
+ color.mul_alpha(t * t)
+ } else {
+ color
+ }
+ },
+ )?;
+ Ok(())
+ }
+
+ /// One line of a working program's description, lit where `shimmer`
+ /// crosses it; `left` is the edge the band is measured from, and `ramp`
+ /// runs from the text's colour to the light. The band steps on the
+ /// spinner's clock and asks for that same frame, so a row that shimmers
+ /// repaints no more often than its spinner already makes it. Each
+ /// glyph's colour is picked from the ramp as it is drawn: nothing is
+ /// allocated or blended here.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_agent_shimmer_text(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ font: &Rc<LoadedFont>,
+ metrics: RenderMetrics,
+ text: &str,
+ x: usize,
+ y: usize,
+ width: usize,
+ left: usize,
+ shimmer: ShimmerBand,
+ ramp: &[LinearRgba; SHIMMER_RAMP_STEPS],
+ ) -> anyhow::Result<()> {
+ let offset = x as f32 - left as f32;
+ self.paint_agent_text_with(layers, font, metrics, text, x, y, width, |middle| {
+ let lit = shimmer.strength(offset + middle);
+ ramp[(lit * (SHIMMER_RAMP_STEPS - 1) as f32).round() as usize]
+ })?;
+ self.request_spinner_frame();
+ Ok(())
+ }
+
+ /// An agent's description as it best fits `width`: `None` to draw it as
+ /// it is -- it fits, or it has no path to cut -- else with the paths in it
+ /// cut back to their last few parts, as many as fit, down to the file
+ /// name, since the end of a path is what tells you most. What does not
+ /// fit even then is left to fade. Worked out once per description,
+ /// width and font, and kept for the agent: cutting means trying every
+ /// depth, which a spinner repainting every frame would otherwise redo.
+ fn fitted_description(
+ &mut self,
+ pane_id: PaneId,
+ font: &Rc<LoadedFont>,
+ metrics: &RenderMetrics,
+ msg: &str,
+ width: usize,
+ ) -> anyhow::Result<Option<Rc<str>>> {
+ if let Some(memo) = self.right_sidebar_agents_fitted.get(&pane_id) {
+ if memo.msg == msg && memo.width == width && memo.font == font.id() {
+ return Ok(memo.fitted.clone());
+ }
+ }
+ let room = width as f32;
+ let mut fitted = None;
+ if self.cached_ui_text_advance(font, metrics, msg)? > room {
+ let deepest = msg.split_whitespace().map(path_parts).max().unwrap_or(0);
+ for keep in (1..deepest).rev() {
+ let Some(shorter) = shorten_paths(msg, keep) else {
+ continue;
+ };
+ let fits = self.cached_ui_text_advance(font, metrics, &shorter)? <= room;
+ fitted = Some(Rc::<str>::from(shorter));
+ if fits {
+ break;
+ }
+ }
+ }
+ self.right_sidebar_agents_fitted.insert(
+ pane_id,
+ FittedDescription {
+ msg: msg.to_string(),
+ width,
+ font: font.id(),
+ fitted: fitted.clone(),
+ },
+ );
+ Ok(fitted)
+ }
+
/// The pill naming what a blocked program waits for. Returns where the
/// text after it starts.
#[allow(clippy::too_many_arguments)]
@@ -758,27 +1082,6 @@ impl TermWindow {
return;
}
match action {
- AgentPanelAction::ReloadRules => {
- // The reload reads manifest files; keep that off the GUI
- // thread and report completion when it lands.
- std::thread::spawn(|| {
- let rejected = mux::agent_status::reload_rules();
- promise::spawn::spawn_into_main_thread(async move {
- let ack = if rejected == 0 {
- crate::i18n::tr("right-agents-rules-reloaded")
- } else {
- let mut args = fluent_bundle::FluentArgs::new();
- args.set("count", rejected);
- crate::i18n::tr_args("right-agents-rules-reload-errors", &args)
- };
- agent_status::set_panel_status(ack);
- if let Some(front_end) = crate::frontend::try_front_end() {
- front_end.invalidate_all_windows();
- }
- })
- .detach();
- });
- }
AgentPanelAction::OpenSettings => {
crate::settings_window::show_from(self.mux_window_id, &self.active_space_id);
}
@@ -793,10 +1096,223 @@ impl TermWindow {
self.right_sidebar_agents_open_subtasks.insert(pane_id);
}
}
+ AgentPanelAction::ViewOptions => {
+ let coords = window::Point::new(
+ item.x as isize,
+ item.y.saturating_add(item.height) as isize,
+ );
+ let items = self.agents_view_options_menu_items();
+ self.show_term_context_menu(context, coords, items);
+ }
}
context.invalidate();
}
+ /// Re-read the agent detection rules. Reading manifest files stays off
+ /// the GUI thread; the toolbar line reports how it went.
+ pub(crate) fn reload_agent_rules(&mut self) {
+ std::thread::spawn(|| {
+ let rejected = mux::agent_status::reload_rules();
+ promise::spawn::spawn_into_main_thread(async move {
+ let ack = if rejected == 0 {
+ crate::i18n::tr("right-agents-rules-reloaded")
+ } else {
+ let mut args = fluent_bundle::FluentArgs::new();
+ args.set("count", rejected);
+ crate::i18n::tr_args("right-agents-rules-reload-errors", &args)
+ };
+ agent_status::set_panel_status(ack);
+ if let Some(front_end) = crate::frontend::try_front_end() {
+ front_end.invalidate_all_windows();
+ }
+ })
+ .detach();
+ });
+ }
+
+ /// The view menu: what to show (by state, and by machine once there is
+ /// more than one), how to group and order it, and which parts of a
+ /// program's report to show -- the same four switches as Settings ›
+ /// Agents, ticked and without icons -- and reloading the detection rules.
+ fn agents_view_options_menu_items(&mut self) -> Vec<window::ContextMenuItem> {
+ use crate::native_settings::{AgentStatusPart, AgentsGroupBy, AgentsSortBy};
+ use crate::termwindow::ContextMenuApplicationAction as Action;
+ use window::{ContextMenuIcon, ContextMenuItem};
+
+ self.begin_context_menu_application_actions();
+ let view = crate::native_settings::agents_panel_view();
+ let display = crate::native_settings::agent_status_display();
+ let tr = crate::i18n::tr;
+
+ let status_items = self.status_filter_menu_items(&view.hidden_statuses, |status| {
+ Action::ToggleAgentsStatusFilter(status)
+ });
+ let mut items = vec![ContextMenuItem::submenu_with_icon(
+ tr("menu-show"),
+ ContextMenuIcon::Filter,
+ status_items,
+ )];
+
+ // The machines agents are on now; this device first. Named here, on
+ // the click, because naming one reads the host list.
+ let mut machines: Vec<(String, String)> = Vec::new();
+ for agent in agent_status::list_agent_panes() {
+ if machines.iter().any(|(key, _)| *key == agent.machine) {
+ continue;
+ }
+ let label = crate::workspace_threads::machine_label_for_workspace(&agent.workspace)
+ .filter(|_| !agent.machine.is_empty())
+ .unwrap_or_else(|| tr("menu-machine-local"));
+ machines.push((agent.machine, label));
+ }
+ machines.sort_by(|a, b| {
+ (!a.0.is_empty())
+ .cmp(&!b.0.is_empty())
+ .then_with(|| a.1.to_lowercase().cmp(&b.1.to_lowercase()))
+ });
+ // Offered once there is a choice to make -- or a machine hidden
+ // earlier, which would otherwise have no way back.
+ if machines.len() > 1 || machines.iter().any(|(key, _)| view.hides_machine(key)) {
+ let machine_items = machines
+ .into_iter()
+ .map(|(key, label)| {
+ let shown = !view.hides_machine(&key);
+ self.context_menu_application_item(label, Action::ToggleAgentsMachineFilter(key))
+ .checked(shown)
+ })
+ .collect();
+ items.push(ContextMenuItem::submenu_with_icon(
+ tr("menu-machine"),
+ ContextMenuIcon::Server,
+ machine_items,
+ ));
+ }
+
+ items.push(ContextMenuItem::Separator);
+ let group_items = AgentsGroupBy::ALL
+ .iter()
+ .copied()
+ .map(|group_by| {
+ self.context_menu_application_item(
+ tr(group_by.label_key()),
+ Action::SetAgentsGroupBy(group_by),
+ )
+ .checked(view.group_by() == group_by)
+ })
+ .collect();
+ items.push(ContextMenuItem::submenu_with_icon(
+ tr("menu-group-by"),
+ ContextMenuIcon::Group,
+ group_items,
+ ));
+ let sort_items = AgentsSortBy::ALL
+ .iter()
+ .copied()
+ .map(|sort_by| {
+ self.context_menu_application_item(
+ tr(sort_by.label_key()),
+ Action::SetAgentsSortBy(sort_by),
+ )
+ .checked(view.sort_by() == sort_by)
+ })
+ .collect();
+ items.push(ContextMenuItem::submenu_with_icon(
+ tr("menu-sort-by"),
+ ContextMenuIcon::Sort,
+ sort_items,
+ ));
+ items.push(ContextMenuItem::Separator);
+ for part in AgentStatusPart::ALL {
+ items.push(
+ self.context_menu_application_item(
+ tr(part.label_key()),
+ Action::ToggleAgentStatusPart(part),
+ )
+ .checked(part.shown(&display)),
+ );
+ }
+ items.push(ContextMenuItem::Separator);
+ items.push(self.context_menu_application_item_with_icon(
+ tr("menu-reload-agent-rules"),
+ ContextMenuIcon::Refresh,
+ Action::ReloadAgentRules,
+ true,
+ ));
+ items
+ }
+
+ /// Show or hide the agents in one state. Hiding the last state shown
+ /// is refused: an empty panel would look broken, not filtered.
+ pub(crate) fn toggle_agents_status_filter(
+ &mut self,
+ status: crate::workspace_threads::WorkspaceThreadWorkStatus,
+ ) {
+ let mut view = crate::native_settings::agents_panel_view();
+ let hidden = std::mem::take(&mut view.hidden_statuses);
+ let Some(hidden) = crate::workspace_threads::toggle_hidden_status(hidden, status) else {
+ return;
+ };
+ view.hidden_statuses = hidden;
+ self.save_agents_panel_view(view);
+ }
+
+ /// Show or hide the agents on one machine. Hiding every machine there
+ /// is is refused, for the same reason as hiding every state.
+ pub(crate) fn toggle_agents_machine_filter(&mut self, key: String) {
+ let mut view = crate::native_settings::agents_panel_view();
+ if let Some(index) = view.hidden_machines.iter().position(|hidden| *hidden == key) {
+ view.hidden_machines.remove(index);
+ } else {
+ view.hidden_machines.push(key);
+ let mut machines: Vec<String> = agent_status::list_agent_panes()
+ .into_iter()
+ .map(|agent| agent.machine)
+ .collect();
+ machines.sort();
+ machines.dedup();
+ if machines.iter().all(|machine| view.hides_machine(machine)) {
+ return;
+ }
+ }
+ self.save_agents_panel_view(view);
+ }
+
+ pub(crate) fn set_agents_group_by(&mut self, group_by: crate::native_settings::AgentsGroupBy) {
+ let mut view = crate::native_settings::agents_panel_view();
+ view.group_by = group_by.key().to_string();
+ self.save_agents_panel_view(view);
+ }
+
+ pub(crate) fn set_agents_sort_by(&mut self, sort_by: crate::native_settings::AgentsSortBy) {
+ let mut view = crate::native_settings::agents_panel_view();
+ view.sort_by = sort_by.key().to_string();
+ self.save_agents_panel_view(view);
+ }
+
+ pub(crate) fn toggle_agent_status_part(
+ &mut self,
+ part: crate::native_settings::AgentStatusPart,
+ ) {
+ if let Err(err) = crate::native_settings::toggle_agent_status_part(part) {
+ log::warn!("failed to save the agent status display: {err:#}");
+ }
+ // The cards, tabs and sidebars that show the part are in every
+ // window.
+ if let Some(front_end) = crate::frontend::try_front_end() {
+ front_end.invalidate_all_windows();
+ }
+ }
+
+ fn save_agents_panel_view(&mut self, view: crate::native_settings::NativeAgentsPanelView) {
+ if let Err(err) = crate::native_settings::save_agents_panel_view(view) {
+ log::warn!("failed to save the Agents panel view: {err:#}");
+ }
+ // Every window's panel reads the view as it is now.
+ if let Some(front_end) = crate::frontend::try_front_end() {
+ front_end.invalidate_all_windows();
+ }
+ }
+
/// The agent lives in another window: deep-focus its tab and pane in
/// the owning mux window first, then activate the backing thread —
/// the same path a left-sidebar thread click takes, which switches
@@ -928,6 +1444,129 @@ struct AgentRowBand {
visible_height: usize,
}
+/// What `fitted_description` settled on for one agent, and for which
+/// description, width and font.
+pub(crate) struct FittedDescription {
+ msg: String,
+ width: usize,
+ font: wezterm_font::LoadedFontId,
+ /// `None`: the description is drawn as it is.
+ fitted: Option<Rc<str>>,
+}
+
+/// One entry of the list as the view menu arranges it: a group's heading
+/// with how many it holds, or an agent's row by its index.
+enum PanelEntry {
+ Header { label: String, count: usize },
+ Agent(usize),
+}
+
+/// Where an agent falls in the view's grouping, as a sort key: the states
+/// in the order they need the user, or threads by name with the agents
+/// that have none last -- and by workspace too, so two threads that share
+/// a name (one here, one on a server) stay two groups. Without grouping
+/// every agent is in one.
+fn group_order(
+ agent: &agent_status::AgentPaneStatus,
+ group_by: crate::native_settings::AgentsGroupBy,
+) -> (u8, String, String) {
+ use crate::native_settings::AgentsGroupBy;
+ use crate::workspace_threads::WorkspaceThreadWorkStatus as Status;
+ match group_by {
+ AgentsGroupBy::State => {
+ let rank = match agent.work_status() {
+ Status::NeedsAttention => 0,
+ Status::Running => 1,
+ Status::FinishedUnseen => 2,
+ // Undetected agents go with the idle ones in the Show
+ // filter, but under a heading of their own: "Idle 3" over
+ // three rows each saying Unknown would be wrong.
+ Status::Idle if agent.shown_state() == agent_status::ShownState::Unknown => 4,
+ Status::Idle => 3,
+ };
+ (rank, String::new(), String::new())
+ }
+ AgentsGroupBy::Thread => (
+ u8::from(agent.place.is_empty()),
+ agent.place.to_lowercase(),
+ agent.workspace.clone(),
+ ),
+ AgentsGroupBy::None => (0, String::new(), String::new()),
+ }
+}
+
+/// The heading over a group, in the words the left sidebar's status filter
+/// uses for the states.
+fn group_label(
+ agent: &agent_status::AgentPaneStatus,
+ group_by: crate::native_settings::AgentsGroupBy,
+) -> String {
+ use crate::native_settings::AgentsGroupBy;
+ use crate::workspace_threads::WorkspaceThreadWorkStatus as Status;
+ match group_by {
+ AgentsGroupBy::Thread if !agent.place.is_empty() => agent.place.clone(),
+ AgentsGroupBy::Thread | AgentsGroupBy::None => crate::i18n::tr("right-agents-group-other"),
+ AgentsGroupBy::State => crate::i18n::tr(match agent.work_status() {
+ Status::NeedsAttention => "menu-status-attention",
+ Status::Running => "menu-status-running",
+ Status::FinishedUnseen => "menu-status-done",
+ Status::Idle if agent.shown_state() == agent_status::ShownState::Unknown => {
+ "right-agents-state-unknown"
+ }
+ Status::Idle => "menu-status-idle",
+ }),
+ }
+}
+
+/// Put agents already in `sort_for_display` order into the view's: by
+/// group, then -- when asked -- whatever changed state last first. The sort
+/// is stable, so the fixed order holds within a group otherwise.
+fn order_for_view(
+ agents: &mut [agent_status::AgentPaneStatus],
+ view: &crate::native_settings::NativeAgentsPanelView,
+) {
+ let group_by = view.group_by();
+ let recent = view.sort_by() == crate::native_settings::AgentsSortBy::Recent;
+ agents.sort_by(|a, b| {
+ group_order(a, group_by)
+ .cmp(&group_order(b, group_by))
+ .then_with(|| {
+ if recent {
+ b.since_unix.cmp(&a.since_unix)
+ } else {
+ std::cmp::Ordering::Equal
+ }
+ })
+ });
+}
+
+/// The list as it is drawn: a heading before each group's first agent,
+/// none when the view does not group.
+fn panel_entries(
+ agents: &[agent_status::AgentPaneStatus],
+ group_by: crate::native_settings::AgentsGroupBy,
+) -> Vec<PanelEntry> {
+ let grouped = group_by != crate::native_settings::AgentsGroupBy::None;
+ let mut entries = Vec::with_capacity(agents.len() + 4);
+ let mut index = 0;
+ while index < agents.len() {
+ let key = group_order(&agents[index], group_by);
+ let end = agents[index..]
+ .iter()
+ .position(|agent| group_order(agent, group_by) != key)
+ .map_or(agents.len(), |len| index + len);
+ if grouped {
+ entries.push(PanelEntry::Header {
+ label: group_label(&agents[index], group_by),
+ count: end - index,
+ });
+ }
+ entries.extend((index..end).map(PanelEntry::Agent));
+ index = end;
+ }
+ entries
+}
+
/// Which of a row's optional lines it has, and how tall that makes it.
struct AgentRowLayout {
height: usize,
@@ -987,6 +1626,103 @@ impl AgentRowLayout {
}
}
+/// How many parts a word of a description has as a path; 0 when it is not
+/// one. A path starts at a root (`/a/b`, `~/a`, `./a`, `../a`) or runs to
+/// three parts (`src/app/main.rs`). Two parts and no root is a ratio or a
+/// choice as often as a path -- `3/12`, `read/write` -- and numbers alone,
+/// a date among them, never are; nor is a URL.
+fn path_parts(word: &str) -> usize {
+ if !word.contains('/') || word.contains("://") {
+ return 0;
+ }
+ let parts: Vec<&str> = word.split('/').filter(|part| !part.is_empty()).collect();
+ let rooted = ["/", "~/", "./", "../"]
+ .iter()
+ .any(|root| word.starts_with(root));
+ let numbers_only = parts
+ .iter()
+ .all(|part| part.chars().all(|c| c.is_ascii_digit() || c.is_ascii_punctuation()));
+ if parts.len() < 2 || numbers_only || (!rooted && parts.len() < 3) {
+ return 0;
+ }
+ parts.len()
+}
+
+/// `text` with every path in it cut back to its last `keep` parts, or
+/// `None` when that changes nothing.
+fn shorten_paths(text: &str, keep: usize) -> Option<String> {
+ let mut changed = false;
+ let mut out = String::with_capacity(text.len());
+ let mut rest = text;
+ while !rest.is_empty() {
+ let word_start = rest
+ .find(|c: char| !c.is_whitespace())
+ .unwrap_or(rest.len());
+ out.push_str(&rest[..word_start]);
+ rest = &rest[word_start..];
+ let word_end = rest.find(char::is_whitespace).unwrap_or(rest.len());
+ let word = &rest[..word_end];
+ rest = &rest[word_end..];
+ let parts = path_parts(word);
+ if parts > keep {
+ let tail: Vec<&str> = word.split('/').filter(|part| !part.is_empty()).collect();
+ out.push_str(&tail[parts - keep..].join("/"));
+ changed = true;
+ } else {
+ out.push_str(word);
+ }
+ }
+ changed.then_some(out)
+}
+
+/// How far from a line's right edge text starts to fade, when the line does
+/// not fit: about four characters.
+const AGENT_TEXT_FADE: f32 = 64.0;
+
+/// How far the shimmer lights either side of its centre, in line heights
+/// (about six characters).
+const SHIMMER_HALF_WIDTH: f32 = 2.5;
+/// How far the shimmer moves each spinner frame, in line heights (about
+/// one and a half characters). A fixed pace: a longer line takes longer to
+/// cross, rather than being crossed in bigger jumps.
+const SHIMMER_STEP: f32 = 0.6;
+/// Colours from the text's to the shimmer's light, ends included.
+const SHIMMER_RAMP_STEPS: usize = 9;
+
+/// Where the band of light crossing a working program's description is.
+#[derive(Clone, Copy, Debug, PartialEq)]
+struct ShimmerBand {
+ /// From the left edge of the text.
+ centre: f32,
+ half_width: f32,
+}
+
+impl ShimmerBand {
+ /// `frames` spinner frames in, across text `travel` wide: the band
+ /// enters from the left, crosses at a fixed pace and leaves on the
+ /// right, then starts again. It is off the text at both ends, so a pass
+ /// starts and ends with the text unlit. Whole-number arithmetic on the
+ /// frame count, so the band never jumps however long the clock runs.
+ fn at(frames: u128, travel: f32, line_height: f32) -> Self {
+ let half_width = (line_height * SHIMMER_HALF_WIDTH).max(1.0);
+ let step = (line_height * SHIMMER_STEP).max(1.0);
+ let pass = ((travel.max(0.0) + half_width * 2.0) / step)
+ .ceil()
+ .max(1.0) as u128;
+ Self {
+ centre: (frames % pass) as f32 * step - half_width,
+ half_width,
+ }
+ }
+
+ /// How lit the glyph whose middle is `x` from the text's left edge is:
+ /// 0 outside the band, 1 at its centre, eased between so it has no edge.
+ fn strength(self, x: f32) -> f32 {
+ let t = (1.0 - (x - self.centre).abs() / self.half_width).max(0.0);
+ t * t * (3.0 - 2.0 * t)
+ }
+}
+
/// The icon a state is shown with: glyph, colour, and whether it spins.
pub(crate) fn agent_state_icon(
state: agent_status::ShownState,
@@ -1054,7 +1790,7 @@ fn agent_row_visible_band(
#[cfg(test)]
mod tests {
- use super::{agent_row_visible_band, AgentRowBand};
+ use super::{agent_row_visible_band, AgentRowBand, ShimmerBand};
const H: usize = 52;
const TOP: usize = 100;
@@ -1153,6 +1889,83 @@ mod tests {
);
}
+ #[test]
+ fn paths_are_cut_back_to_their_last_parts() {
+ use super::shorten_paths;
+ let msg = "Reading /private/tmp/claude/scratch/agent-status-notes.md";
+ assert_eq!(
+ shorten_paths(msg, 2).as_deref(),
+ Some("Reading scratch/agent-status-notes.md")
+ );
+ assert_eq!(
+ shorten_paths(msg, 1).as_deref(),
+ Some("Reading agent-status-notes.md")
+ );
+ // Every path in the line, the words between left alone.
+ assert_eq!(
+ shorten_paths("cp src/a/b.rs ~/x/y/c.rs", 1).as_deref(),
+ Some("cp b.rs c.rs")
+ );
+ // Nothing to cut: no path, a path already short, a URL.
+ assert_eq!(shorten_paths("Running cargo test", 1), None);
+ assert_eq!(shorten_paths("Editing notes.md", 1), None);
+ assert_eq!(shorten_paths("Fetching https://example.com/a/b", 1), None);
+ // Ratios, choices and dates are not paths, beside one that is.
+ assert_eq!(
+ shorten_paths("Running tests (3/12) in src/app/tests/foo_test.rs", 1).as_deref(),
+ Some("Running tests (3/12) in foo_test.rs")
+ );
+ assert_eq!(shorten_paths("Step 2/5: fix read/write path", 1), None);
+ assert_eq!(shorten_paths("Done 3/7 tasks on 2026/10/10", 1), None);
+ }
+
+ #[test]
+ fn shimmer_crosses_at_one_pace_whatever_the_length() {
+ let line = 20.0;
+ for travel in [60.0, 600.0] {
+ let first = ShimmerBand::at(0, travel, line);
+ let next = ShimmerBand::at(1, travel, line);
+ assert_eq!(next.centre - first.centre, line * super::SHIMMER_STEP);
+ }
+ let pass = |travel: f32| {
+ (1..10_000u128)
+ .find(|&f| {
+ ShimmerBand::at(f, travel, line).centre
+ < ShimmerBand::at(f - 1, travel, line).centre
+ })
+ .unwrap()
+ };
+ assert!(
+ pass(600.0) > pass(60.0) * 4,
+ "a longer line takes longer to cross"
+ );
+ }
+
+ #[test]
+ fn shimmer_starts_and_ends_off_the_text() {
+ let (line, travel) = (20.0, 300.0);
+ let start = ShimmerBand::at(0, travel, line);
+ assert_eq!(start.strength(0.0), 0.0, "nothing lit as a pass begins");
+ let last = (0..1000u128)
+ .map(|f| ShimmerBand::at(f, travel, line))
+ .take_while(|band| band.centre >= start.centre)
+ .last()
+ .unwrap();
+ assert_eq!(last.strength(travel), 0.0, "nothing lit as a pass ends");
+ // And the clock running for years changes nothing about that.
+ let late = ShimmerBand::at(u64::MAX as u128 * 7, travel, line);
+ assert!(late.centre >= start.centre && late.centre <= travel + start.half_width);
+ }
+
+ #[test]
+ fn shimmer_is_brightest_at_its_centre() {
+ let band = ShimmerBand::at(10, 300.0, 20.0);
+ assert_eq!(band.strength(band.centre), 1.0);
+ assert!(band.strength(band.centre + band.half_width / 2.0) < 1.0);
+ assert_eq!(band.strength(band.centre + band.half_width), 0.0);
+ assert_eq!(band.strength(band.centre - band.half_width * 3.0), 0.0);
+ }
+
/// Sub-tasks fold to the one line that counts them: only an open list
/// adds its lines, and with sub-tasks switched off there is no line.
#[test]
@@ -1182,6 +1995,7 @@ mod tests {
window_id: None,
place: String::new(),
workspace: String::new(),
+ machine: String::new(),
report: Some(ProgramReport {
state: ProgramReportState::Working,
kind: None,
@@ -1215,59 +2029,106 @@ mod tests {
assert_eq!((off.subtask_count, off.height), (0, base));
}
- /// The toolbar line is the only thing explaining a quiet panel, so it
- /// must never come back blank, and must name what is actually
- /// happening rather than reciting every state.
- #[test]
- fn toolbar_line_reports_what_is_happening() {
- use super::AgentCounts;
+ fn agent_at(
+ pane_id: usize,
+ state: crate::agent_status::AgentState,
+ place: &str,
+ since_unix: u64,
+ ) -> crate::agent_status::AgentPaneStatus {
+ crate::agent_status::AgentPaneStatus {
+ pane_id: pane_id as mux::pane::PaneId,
+ agent_id: "claude".to_string(),
+ state,
+ evidence: crate::agent_status::AgentEvidence::Screen,
+ session_id: None,
+ title: String::new(),
+ window_id: None,
+ place: place.to_string(),
+ workspace: String::new(),
+ machine: String::new(),
+ report: None,
+ since_unix,
+ }
+ }
- let all_idle = AgentCounts {
- total: 3,
- idle: 3,
- ..Default::default()
- };
- let line = all_idle.describe();
- assert!(line.contains('3'), "idle count should be named: {line}");
-
- let busy = AgentCounts {
- total: 4,
- working: 2,
- blocked: 1,
- idle: 1,
+ /// Rows as the view lists them: each heading's count, then the panes
+ /// under it.
+ fn listed(
+ agents: &mut Vec<crate::agent_status::AgentPaneStatus>,
+ group_by: &str,
+ sort_by: &str,
+ ) -> Vec<String> {
+ use super::{order_for_view, panel_entries, PanelEntry};
+ let view = crate::native_settings::NativeAgentsPanelView {
+ group_by: group_by.to_string(),
+ sort_by: sort_by.to_string(),
..Default::default()
};
- let line = busy.describe();
- assert!(line.contains('2') && line.contains('1'), "{line}");
- assert!(
- line.contains('\u{b7}'),
- "working and waiting should be joined: {line}"
+ crate::agent_status::sort_for_display(agents);
+ order_for_view(agents, &view);
+ panel_entries(agents, view.group_by())
+ .into_iter()
+ .map(|entry| match entry {
+ PanelEntry::Header { count, .. } => format!("#{}", count),
+ PanelEntry::Agent(row) => agents[row].pane_id.to_string(),
+ })
+ .collect()
+ }
+
+ /// Grouped by state, the agents that need the user lead, then those
+ /// working, done and idle, each under a heading that counts them.
+ #[test]
+ fn the_view_groups_by_state_with_what_needs_the_user_first() {
+ use crate::agent_status::AgentState::{Blocked, Error, Idle, Working};
+ let mut agents = vec![
+ agent_at(1, Working, "a", 10),
+ agent_at(2, Idle, "a", 20),
+ agent_at(3, Blocked, "b", 30),
+ agent_at(4, Error, "a", 40),
+ agent_at(5, Working, "b", 50),
+ ];
+ assert_eq!(
+ listed(&mut agents, "", ""),
+ ["#2", "4", "3", "#2", "1", "5", "#1", "2"]
);
- assert!(
- !line.contains('4'),
- "the idle fallback must not appear alongside live counts: {line}"
+ // Most recent first changes the order inside a group, never across.
+ assert_eq!(
+ listed(&mut agents, "state", "recent"),
+ ["#2", "4", "3", "#2", "5", "1", "#1", "2"]
);
+ }
- // Unknown panes must be reported as unknown — never rolled into
- // the idle count ("3 idle" over three Unknown rows was a lie).
- let unknown_only = AgentCounts {
- total: 2,
- unknown: 2,
- ..Default::default()
- };
- let line = unknown_only.describe();
- assert!(!line.is_empty());
- assert!(line.contains('2'), "{line}");
- let mixed = AgentCounts {
- total: 3,
- idle: 2,
- unknown: 1,
- ..Default::default()
- };
- let line = mixed.describe();
- assert!(
- line.contains('2') && line.contains('1') && line.contains('\u{b7}'),
- "idle and unknown must be reported separately: {line}"
+ #[test]
+ fn the_view_groups_by_thread_or_not_at_all() {
+ use crate::agent_status::AgentState::{Blocked, Working};
+ let mut agents = vec![
+ agent_at(1, Working, "beta", 10),
+ agent_at(2, Blocked, "", 20),
+ agent_at(3, Working, "alpha", 30),
+ agent_at(4, Working, "beta", 40),
+ ];
+ // Threads by name; agents with no thread last, under "Other".
+ assert_eq!(
+ listed(&mut agents, "thread", "fixed"),
+ ["#1", "3", "#2", "1", "4", "#1", "2"]
);
+ // Two threads that share a name -- one here, one on a server -- are
+ // two groups, not one.
+ let mut twins = vec![
+ agent_at(1, Working, "app · main", 10),
+ agent_at(2, Working, "app · main", 20),
+ agent_at(3, Working, "app · main", 30),
+ ];
+ twins[0].workspace = "local-main".to_string();
+ twins[1].workspace = "remote-main".to_string();
+ twins[2].workspace = "local-main".to_string();
+ assert_eq!(
+ listed(&mut twins, "thread", "fixed"),
+ ["#2", "1", "3", "#1", "2"]
+ );
+ // No headings at all; a hand-edited key nobody knows falls back.
+ assert_eq!(listed(&mut agents, "none", "fixed"), ["2", "3", "1", "4"]);
+ assert_eq!(listed(&mut agents, "bogus", "bogus")[0], "#1");
}
+
}
diff --git a/wezterm-gui/src/termwindow/ui/context_menu.rs b/wezterm-gui/src/termwindow/ui/context_menu.rs
index cd1db9bc..339df34f 100644
--- a/wezterm-gui/src/termwindow/ui/context_menu.rs
+++ b/wezterm-gui/src/termwindow/ui/context_menu.rs
@@ -184,6 +184,52 @@ impl crate::TermWindow {
icon: ContextMenuIcon,
action: crate::termwindow::ContextMenuApplicationAction,
enabled: bool,
+ ) -> ContextMenuItem {
+ let item = self.context_menu_application_item(label, action).with_icon(icon);
+ if enabled {
+ item
+ } else {
+ item.disabled()
+ }
+ }
+
+ /// A status filter's four states, ticked when shown, in the order, words
+ /// and icons both the workspace sidebar's and the Agents panel's view
+ /// menus list them in.
+ pub(crate) fn status_filter_menu_items(
+ &mut self,
+ hidden: &[String],
+ action: impl Fn(
+ crate::workspace_threads::WorkspaceThreadWorkStatus,
+ ) -> crate::termwindow::ContextMenuApplicationAction,
+ ) -> Vec<ContextMenuItem> {
+ use crate::workspace_threads::WorkspaceThreadWorkStatus as Status;
+ [
+ ("menu-status-running", ContextMenuIcon::Refresh, Status::Running),
+ ("menu-status-attention", ContextMenuIcon::Warning, Status::NeedsAttention),
+ ("menu-status-done", ContextMenuIcon::Check, Status::FinishedUnseen),
+ ("menu-status-idle", ContextMenuIcon::Info, Status::Idle),
+ ]
+ .iter()
+ .map(|&(label, icon, status)| {
+ let shown = !hidden.iter().any(|key| key == status.settings_key());
+ self.context_menu_application_item_with_icon(
+ crate::i18n::tr(label),
+ icon,
+ action(status),
+ true,
+ )
+ .checked(shown)
+ })
+ .collect()
+ }
+
+ /// An application item with no icon: the choices of a view menu's
+ /// submenu, where the tick is the only mark they need.
+ pub(crate) fn context_menu_application_item(
+ &mut self,
+ label: impl Into<String>,
+ action: crate::termwindow::ContextMenuApplicationAction,
) -> ContextMenuItem {
let action_id = self.next_context_menu_application_action_id;
self.next_context_menu_application_action_id = self
@@ -192,12 +238,7 @@ impl crate::TermWindow {
.max(1);
self.context_menu_application_actions
.insert(action_id, action);
- let item = ContextMenuItem::application_item(label, action_id).with_icon(icon);
- if enabled {
- item
- } else {
- item.disabled()
- }
+ ContextMenuItem::application_item(label, action_id)
}
/// Is the window currently displaying `thread_id`'s workspace? Asked
@@ -305,6 +346,24 @@ impl crate::TermWindow {
self.workspace_sidebar_show_archived = !self.workspace_sidebar_show_archived;
self.invalidate_window();
}
+ crate::termwindow::ContextMenuApplicationAction::ToggleAgentsStatusFilter(status) => {
+ self.toggle_agents_status_filter(status);
+ }
+ crate::termwindow::ContextMenuApplicationAction::ToggleAgentsMachineFilter(key) => {
+ self.toggle_agents_machine_filter(key);
+ }
+ crate::termwindow::ContextMenuApplicationAction::SetAgentsGroupBy(group_by) => {
+ self.set_agents_group_by(group_by);
+ }
+ crate::termwindow::ContextMenuApplicationAction::SetAgentsSortBy(sort_by) => {
+ self.set_agents_sort_by(sort_by);
+ }
+ crate::termwindow::ContextMenuApplicationAction::ToggleAgentStatusPart(part) => {
+ self.toggle_agent_status_part(part);
+ }
+ crate::termwindow::ContextMenuApplicationAction::ReloadAgentRules => {
+ self.reload_agent_rules();
+ }
crate::termwindow::ContextMenuApplicationAction::AddThreadToCollection {
collection_space_id,
thread_id,
diff --git a/wezterm-gui/src/termwindow/ui/right_sidebar.rs b/wezterm-gui/src/termwindow/ui/right_sidebar.rs
index 4dca5f95..d3a2f571 100644
--- a/wezterm-gui/src/termwindow/ui/right_sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/right_sidebar.rs
@@ -7894,8 +7894,6 @@ impl crate::TermWindow {
}
self.paint_agents_sidebar(
layers,
- ui_font,
- ui_metrics,
chrome,
foreground,
muted_fg,
diff --git a/wezterm-gui/src/termwindow/ui/status_icon.rs b/wezterm-gui/src/termwindow/ui/status_icon.rs
index 38771a64..d1ead7cf 100644
--- a/wezterm-gui/src/termwindow/ui/status_icon.rs
+++ b/wezterm-gui/src/termwindow/ui/status_icon.rs
@@ -39,6 +39,16 @@ impl UiStatusKind {
}
}
+/// Spinner frames since the epoch, on the wall clock so every spinner in
+/// every window turns together. Read it once per surface and frame, and
+/// pass it to whatever animates on it there.
+pub(crate) fn spinner_frames() -> u128 {
+ let now = SystemTime::now()
+ .duration_since(UNIX_EPOCH)
+ .unwrap_or_default();
+ now.as_millis() / SPINNER_FRAME_MS as u128
+}
+
pub fn split_leading_legacy_progress_marker(title: &str) -> Option<&str> {
let trimmed = title.trim_start();
let mut chars = trimmed.char_indices();
@@ -85,15 +95,34 @@ impl TermWindow {
size: usize,
color: LinearRgba,
) -> anyhow::Result<()> {
- let now = SystemTime::now()
- .duration_since(UNIX_EPOCH)
- .unwrap_or_default();
- let frame =
- ((now.as_millis() / SPINNER_FRAME_MS as u128) % SPINNER_FRAME_COUNT as u128) as u8;
+ self.paint_spinning_ui_icon_at(layers, layer, icon, x, y, size, color, spinner_frames())
+ }
+
+ /// A spinner at a clock reading the caller took, so everything one
+ /// surface animates in a frame steps together.
+ #[allow(clippy::too_many_arguments)]
+ pub(crate) fn paint_spinning_ui_icon_at(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ layer: usize,
+ icon: SvgIcon,
+ x: usize,
+ y: usize,
+ size: usize,
+ color: LinearRgba,
+ frames: u128,
+ ) -> anyhow::Result<()> {
+ let frame = (frames % SPINNER_FRAME_COUNT as u128) as u8;
+ self.request_spinner_frame();
+ self.paint_ui_icon_impl(layers, layer, icon, x, y, size, color, Some(frame))
+ }
+
+ /// Ask for the next spinner frame. Anything else animated on the
+ /// spinner's clock asks for the same one, so it adds no repaints.
+ pub(crate) fn request_spinner_frame(&self) {
self.update_next_frame_time(Some(
Instant::now() + Duration::from_millis(SPINNER_FRAME_MS),
));
- self.paint_ui_icon_impl(layers, layer, icon, x, y, size, color, Some(frame))
}
pub(crate) fn paint_status_icon(
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 0a590224..4efd7825 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -2172,18 +2172,54 @@ pub fn origin_space_for_ref_workspace(host_space_id: &str, workspace: &str) -> O
/// workspace id would otherwise leak into the UI (e.g. the Agents panel).
pub fn thread_display_name_for_workspace(workspace: &str) -> Option<String> {
let store = THREAD_STORE.lock();
+ let (project, thread) = project_and_thread_for_workspace(&store, workspace)?;
+ Some(project_thread_name(project, thread))
+}
+
+fn project_thread_name(project: &Project, thread: &WorkspaceThread) -> String {
+ if project.name.is_empty() || project.name == thread.name {
+ thread.name.clone()
+ } else {
+ format!("{} \u{b7} {}", project.name, thread.name)
+ }
+}
+
+/// What the Agents panel shows of a workspace's thread, from one walk of
+/// the store: its human name, as `thread_display_name_for_workspace` gives
+/// it, and a key for the machine it runs on that stays put while it does
+/// (empty for this device). `None` for workspaces no thread claims.
+pub fn thread_place_and_machine_for_workspace(workspace: &str) -> Option<(String, String)> {
+ let store = THREAD_STORE.lock();
+ let (project, thread) = project_and_thread_for_workspace(&store, workspace)?;
+ Some((
+ project_thread_name(project, thread),
+ project_machine(project, &store.spaces).key(),
+ ))
+}
+
+/// What the machine a workspace's thread runs on is called, as
+/// `origin_machine_for_project` names it; `None` for this device. Reads the
+/// host list, so it is for menus rather than painting.
+pub fn machine_label_for_workspace(workspace: &str) -> Option<String> {
+ let store = THREAD_STORE.lock();
+ let (project, _) = project_and_thread_for_workspace(&store, workspace)?;
+ let (label, local) = origin_machine_for_project(project, &store.spaces);
+ (!local).then_some(label)
+}
+
+fn project_and_thread_for_workspace<'a>(
+ store: &'a WorkspaceThreadStore,
+ workspace: &str,
+) -> Option<(&'a Project, &'a WorkspaceThread)> {
store.projects.iter().find_map(|project| {
- project.threads.iter().find_map(|thread| {
- let matches = thread.materialized_workspace_name.as_deref() == Some(workspace)
- || workspace_name_for_thread(&project.id, &thread.id) == workspace;
- matches.then(|| {
- if project.name.is_empty() || project.name == thread.name {
- thread.name.clone()
- } else {
- format!("{} \u{b7} {}", project.name, thread.name)
- }
+ project
+ .threads
+ .iter()
+ .find(|thread| {
+ thread.materialized_workspace_name.as_deref() == Some(workspace)
+ || workspace_name_for_thread(&project.id, &thread.id) == workspace
})
- })
+ .map(|thread| (project, thread))
})
}
@@ -3091,6 +3127,26 @@ pub fn filter_threads_view_by_status(
/// Guard for the view-options menu: refuse a toggle that would hide every
/// status and leave the sidebar inexplicably empty.
+/// A status filter's hidden keys with `status` flipped, or `None` when that
+/// would hide every state: an empty list reads as broken, not filtered.
+/// The workspace sidebar's filter and the Agents panel's share it.
+pub fn toggle_hidden_status(
+ mut hidden: Vec<String>,
+ status: WorkspaceThreadWorkStatus,
+) -> Option<Vec<String>> {
+ let key = status.settings_key();
+ if let Some(index) = hidden.iter().position(|entry| entry == key) {
+ hidden.remove(index);
+ return Some(hidden);
+ }
+ hidden.push(key.to_string());
+ let parsed: Vec<_> = hidden
+ .iter()
+ .filter_map(|entry| WorkspaceThreadWorkStatus::from_settings_key(entry))
+ .collect();
+ (!hidden_statuses_cover_all(&parsed)).then_some(hidden)
+}
+
pub fn hidden_statuses_cover_all(hidden: &[WorkspaceThreadWorkStatus]) -> bool {
WorkspaceThreadWorkStatus::ALL
.iter()
@@ -9401,29 +9457,59 @@ fn is_remote_project(project: &Project, spaces: &[Space]) -> bool {
/// (which lives in a LOCAL Space, so the Space's `client_domain` alone
/// misses it — same three-way test as `is_remote_project`), or this device.
fn origin_machine_for_project(project: &Project, spaces: &[Space]) -> (String, bool) {
+ let host_id = match project_machine(project, spaces) {
+ ProjectMachine::Domain(domain) => return (domain, false),
+ ProjectMachine::Local => return ("Local".to_string(), true),
+ ProjectMachine::Ssh(host_id) => host_id,
+ };
+ let label = crate::ssh_hosts::host_spec(host_id)
+ .map(|spec| spec.label)
+ .or_else(|| {
+ // `ssh://user@host/...` — the authority names the machine.
+ let path = project.path.to_string_lossy().into_owned();
+ let rest = path.strip_prefix("ssh://")?;
+ let authority = rest.split('/').next()?;
+ let host = authority.rsplit('@').next()?;
+ (!host.is_empty()).then(|| host.to_string())
+ })
+ .unwrap_or_else(|| project.name.clone());
+ (label, false)
+}
+
+/// The machine a project's threads run on: the same three-way test as
+/// `is_remote_project`, made once for both the name a menu shows and the
+/// key a filter keeps.
+enum ProjectMachine<'a> {
+ /// A Space a mux domain owns.
+ Domain(String),
+ /// A direct-SSH project, by host id.
+ Ssh(&'a str),
+ Local,
+}
+
+impl ProjectMachine<'_> {
+ /// Stable while the machine is: empty for this device.
+ fn key(&self) -> String {
+ match self {
+ Self::Domain(domain) => format!("domain:{domain}"),
+ Self::Ssh(host_id) => format!("ssh:{host_id}"),
+ Self::Local => String::new(),
+ }
+ }
+}
+
+fn project_machine<'a>(project: &'a Project, spaces: &[Space]) -> ProjectMachine<'a> {
if let Some(domain) = spaces
.iter()
.find(|space| space.id == project.space_id)
.and_then(|space| space.client_domain.clone())
{
- return (domain, false);
+ return ProjectMachine::Domain(domain);
}
if is_remote_project(project, spaces) {
- let host_id = remote_host_id_for_project_id(&project.id);
- let label = crate::ssh_hosts::host_spec(host_id)
- .map(|spec| spec.label)
- .or_else(|| {
- // `ssh://user@host/...` — the authority names the machine.
- let path = project.path.to_string_lossy().into_owned();
- let rest = path.strip_prefix("ssh://")?;
- let authority = rest.split('/').next()?;
- let host = authority.rsplit('@').next()?;
- (!host.is_empty()).then(|| host.to_string())
- })
- .unwrap_or_else(|| project.name.clone());
- return (label, false);
+ return ProjectMachine::Ssh(remote_host_id_for_project_id(&project.id));
}
- ("Local".to_string(), true)
+ ProjectMachine::Local
}
fn thread_has_restorable_workspace(thread: &WorkspaceThread) -> bool {
@@ -10093,6 +10179,21 @@ fn now_ts() -> i64 {
#[cfg(test)]
mod tests {
+
+ /// A filter flips one state at a time and never hides them all.
+ #[test]
+ fn a_status_filter_never_hides_every_state() {
+ use super::{toggle_hidden_status, WorkspaceThreadWorkStatus as Status};
+ let hidden = toggle_hidden_status(Vec::new(), Status::Idle).unwrap();
+ assert_eq!(hidden, ["idle"]);
+ let hidden = toggle_hidden_status(hidden, Status::Running).unwrap();
+ let hidden = toggle_hidden_status(hidden, Status::FinishedUnseen).unwrap();
+ assert_eq!(toggle_hidden_status(hidden.clone(), Status::NeedsAttention), None);
+ assert_eq!(
+ toggle_hidden_status(hidden, Status::Idle).unwrap(),
+ ["running", "finished"]
+ );
+ }
use super::*;
/// Only the exact `$HOME` of a Thread rooted elsewhere is dropped: a