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.

Let any local Space hold thread references; retire collection Spaces

RoversX08dc50b385c7
diff --git a/wezterm-gui/i18n/en-US.ftl b/wezterm-gui/i18n/en-US.ftl
index 43fa72d1..8b6d688d 100644
--- a/wezterm-gui/i18n/en-US.ftl
+++ b/wezterm-gui/i18n/en-US.ftl
@@ -182,7 +182,7 @@ sidebar-connecting = Connecting…
sidebar-reconnect = Reconnect
sidebar-new-thread = New Thread
sidebar-pinned = Pinned
-sidebar-collection-threads = Threads
+sidebar-thread-refs = References
sidebar-workspaces = Workspaces
sidebar-settings = Settings
# Hover tags on the icon-only sidebar buttons. Keep these to a couple of
@@ -205,10 +205,9 @@ menu-space-server-group-connecting = { $name } (connecting…)
menu-space-server-group-reconnecting = { $name } (reconnecting…)
remote-tree-mutation-offline = { $name } is disconnected. Reconnect and try again.
menu-new-space-here = New Space Here
-menu-new-collection-space = New Collection Space
-menu-add-to-collection = Add to Collection
-menu-add-to-collection-named = Add to “{ $name }”
-menu-remove-from-collection = Remove from Collection
+menu-add-to-space = Add to Space
+menu-add-to-space-named = Add to “{ $name }”
+menu-remove-thread-ref = Remove from This Space
menu-go-to-origin-space = Go to Origin Space
menu-rename-space = Rename Space…
menu-rename-named-space = Rename “{ $name }”…
diff --git a/wezterm-gui/i18n/fr-FR.ftl b/wezterm-gui/i18n/fr-FR.ftl
index 3dc9d764..8b20d852 100644
--- a/wezterm-gui/i18n/fr-FR.ftl
+++ b/wezterm-gui/i18n/fr-FR.ftl
@@ -182,7 +182,7 @@ sidebar-connecting = Connexion…
sidebar-reconnect = Reconnecter
sidebar-new-thread = Nouvelle session
sidebar-pinned = Épinglées
-sidebar-collection-threads = Sessions
+sidebar-thread-refs = Références
sidebar-workspaces = Espaces de travail
sidebar-settings = Réglages
# Hover tags on the icon-only sidebar buttons. Keep these to a couple of
@@ -205,10 +205,9 @@ menu-space-server-group-connecting = { $name } (connexion…)
menu-space-server-group-reconnecting = { $name } (reconnexion…)
remote-tree-mutation-offline = { $name } est déconnecté. Reconnectez-vous et réessayez.
menu-new-space-here = Nouvel espace ici
-menu-new-collection-space = Nouvel espace collection
-menu-add-to-collection = Ajouter à la collection
-menu-add-to-collection-named = Ajouter à « { $name } »
-menu-remove-from-collection = Retirer de la collection
+menu-add-to-space = Ajouter à l’espace
+menu-add-to-space-named = Ajouter à « { $name } »
+menu-remove-thread-ref = Retirer de cet espace
menu-go-to-origin-space = Aller à l’espace d’origine
menu-rename-space = Renommer l’espace…
menu-rename-named-space = Renommer « { $name } »…
diff --git a/wezterm-gui/i18n/ja-JP.ftl b/wezterm-gui/i18n/ja-JP.ftl
index 4ca897ec..843757c8 100644
--- a/wezterm-gui/i18n/ja-JP.ftl
+++ b/wezterm-gui/i18n/ja-JP.ftl
@@ -182,7 +182,7 @@ sidebar-connecting = 接続中…
sidebar-reconnect = 再接続
sidebar-new-thread = 新しいセッション
sidebar-pinned = ピン留め
-sidebar-collection-threads = セッション
+sidebar-thread-refs = 参照
sidebar-workspaces = ワークスペース
sidebar-settings = 設定
# Hover tags on the icon-only sidebar buttons. Keep these to a couple of
@@ -205,10 +205,9 @@ menu-space-server-group-connecting = { $name }(接続中…)
menu-space-server-group-reconnecting = { $name }(再接続中…)
remote-tree-mutation-offline = { $name } は切断されています。再接続してからもう一度お試しください。
menu-new-space-here = このサーバーに新しいスペース
-menu-new-collection-space = 新規コレクションスペース
-menu-add-to-collection = コレクションに追加
-menu-add-to-collection-named = “{ $name }”に追加
-menu-remove-from-collection = コレクションから削除
+menu-add-to-space = スペースに追加
+menu-add-to-space-named = “{ $name }”に追加
+menu-remove-thread-ref = このスペースから削除
menu-go-to-origin-space = 元のスペースへ移動
menu-rename-space = スペース名を変更…
menu-rename-named-space = 「{ $name }」の名前を変更…
diff --git a/wezterm-gui/i18n/zh-CN.ftl b/wezterm-gui/i18n/zh-CN.ftl
index 0452f379..9572ed00 100644
--- a/wezterm-gui/i18n/zh-CN.ftl
+++ b/wezterm-gui/i18n/zh-CN.ftl
@@ -182,7 +182,7 @@ sidebar-connecting = 正在连接…
sidebar-reconnect = 重新连接
sidebar-new-thread = 新建会话
sidebar-pinned = 已置顶
-sidebar-collection-threads = 会话
+sidebar-thread-refs = 引用
sidebar-workspaces = 工作区
sidebar-settings = 设置
# Hover tags on the icon-only sidebar buttons. Keep these to a couple of
@@ -205,10 +205,9 @@ menu-space-server-group-connecting = { $name }(连接中…)
menu-space-server-group-reconnecting = { $name }(重连中…)
remote-tree-mutation-offline = { $name } 已断开。请重新连接后再试。
menu-new-space-here = 在此服务器新建空间
-menu-new-collection-space = 新建集合空间
-menu-add-to-collection = 添加到集合
-menu-add-to-collection-named = 添加到“{ $name }”
-menu-remove-from-collection = 从集合移除
+menu-add-to-space = 添加到空间
+menu-add-to-space-named = 添加到“{ $name }”
+menu-remove-thread-ref = 从此空间移除
menu-go-to-origin-space = 回到原空间
menu-rename-space = 重命名空间…
menu-rename-named-space = 重命名“{ $name }”…
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 5b08245b..eeedaa20 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -447,19 +447,17 @@ pub(crate) enum ContextMenuApplicationAction {
},
/// Sidebar view-options: show/hide threads with this work status.
ToggleWorkspaceStatusFilter(crate::workspace_threads::WorkspaceThreadWorkStatus),
- /// Add a thread reference to a collection Space; `None` creates the
- /// first collection Space and adds there.
+ /// Add a thread reference to a Space (local, non-home, not already
+ /// holding it — the menu only offers eligible targets).
AddThreadToCollection {
collection_space_id: Option<String>,
thread_id: String,
},
- /// Drop a thread reference from a collection Space.
+ /// Drop a thread reference from a Space.
RemoveThreadFromCollection {
collection_space_id: String,
thread_id: String,
},
- /// Space menu: create a collection Space and switch to it.
- CreateCollectionSpace,
/// Fetch a file from the remote Files panel into the Downloads folder.
DownloadRemoteFile {
path: remote_files::RemotePath,
@@ -523,6 +521,14 @@ pub enum UIItemType {
/// connected this session).
SpaceReconnect,
ProjectToggleThreads(String),
+ /// Collapse/expand a folder-style thread-reference group; the payload is
+ /// the group key (`"<space_id>::<machine_label>"`), tracked in runtime
+ /// state rather than the store.
+ ThreadRefGroupToggle(String),
+ /// The "+" on a reference group: create a thread in the group's origin
+ /// project (exactly like the project "+") and auto-add a ref to it in
+ /// the current Space. Payload is the group's origin Space id.
+ ThreadRefGroupNewThread(String),
Project(String),
WorkspaceThread(String),
WorkspaceThreadPin(String),
@@ -1826,6 +1832,14 @@ pub struct TermWindow {
/// touches `workspace_sidebar_collapsed` or `workspace_sidebar_width`:
/// the terminal must not reflow for a hover.
workspace_sidebar_hover: sidebar_hover::SidebarHoverReveal,
+ /// The pointer is over the native macOS titlebar sidebar button (which
+ /// lives outside our view, so `current_mouse_event` cannot see it).
+ /// Feeds the hover-reveal as a hot zone.
+ titlebar_sidebar_button_hovered: bool,
+ /// Collapsed folder-style reference groups, keyed by
+ /// `"<space_id>::<machine_label>"`. Runtime-only: collapse state resets
+ /// with the window, like a disclosure and unlike project collapse.
+ thread_ref_groups_collapsed: std::collections::HashSet<String>,
/// A native (AppKit) context menu is open. The fallback menu tracks
/// itself in `context_menu`; the native path otherwise leaves no trace,
/// and the hover machine must not retreat the panel a menu is anchored
@@ -2235,26 +2249,21 @@ impl TermWindow {
}
/// The Space whose projects/domain the right-sidebar features (Files,
- /// remote connect, paste targets) should act on. A collection window
- /// displays workspaces that belong to other Spaces, so resolve through
- /// the displayed workspace there; everywhere else the window's Space is
- /// the answer.
+ /// remote connect, paste targets) should act on. A window displaying a
+ /// thread reference shows a workspace that belongs to another Space, so
+ /// resolve through the displayed workspace; everywhere else the window's
+ /// Space is the answer.
pub(crate) fn content_space_id(&self) -> String {
- if crate::workspace_threads::is_collection_space(&self.active_space_id) {
- if let Some(workspace) = self.current_mux_workspace() {
- // Only resolve through the displayed workspace when it is a
- // reference this collection actually holds. A freshly
- // switched-to collection still shows the previous Space's
- // terminal, and that must not leak the previous machine
- // into Files/paste.
- if let Some(space_id) =
- crate::workspace_threads::origin_space_for_collection_workspace(
- &self.active_space_id,
- &workspace,
- )
- {
- return space_id;
- }
+ if let Some(workspace) = self.current_mux_workspace() {
+ // Only resolve through the displayed workspace when it is a
+ // reference this Space actually holds. A freshly switched-to
+ // window still shows the previous Space's terminal, and that
+ // must not leak the previous machine into Files/paste.
+ if let Some(space_id) = crate::workspace_threads::origin_space_for_ref_workspace(
+ &self.active_space_id,
+ &workspace,
+ ) {
+ return space_id;
}
}
self.active_space_id.clone()
@@ -2795,6 +2804,8 @@ impl TermWindow {
workspace_space_swipe_needs_settle_start: false,
workspace_sidebar_scrollbar_visible_until: None,
workspace_sidebar_hover: sidebar_hover::SidebarHoverReveal::default(),
+ titlebar_sidebar_button_hovered: false,
+ thread_ref_groups_collapsed: std::collections::HashSet::new(),
native_context_menu_open: false,
workspace_notification_snapshot: None,
workspace_notification_pulse_started_at: None,
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index a7ecf156..b95bbdda 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -1367,6 +1367,8 @@ impl super::TermWindow {
| UIItemType::SpaceMenu
| UIItemType::SpaceReconnect
| UIItemType::ProjectToggleThreads(_)
+ | UIItemType::ThreadRefGroupToggle(_)
+ | UIItemType::ThreadRefGroupNewThread(_)
| UIItemType::Project(_)
| UIItemType::WorkspaceThread(_)
| UIItemType::WorkspaceThreadPin(_)
@@ -1477,6 +1479,8 @@ impl super::TermWindow {
| UIItemType::SpaceMenu
| UIItemType::SpaceReconnect
| UIItemType::ProjectToggleThreads(_)
+ | UIItemType::ThreadRefGroupToggle(_)
+ | UIItemType::ThreadRefGroupNewThread(_)
| UIItemType::Project(_)
| UIItemType::WorkspaceThread(_)
| UIItemType::WorkspaceThreadPin(_)
@@ -2834,13 +2838,14 @@ impl super::TermWindow {
.is_some_and(|bg| coords.x >= bg.x as isize && coords.x < (bg.x + bg.width) as isize);
let rows: Vec<(String, isize, isize)> = match &kind {
super::SidebarRowKind::Project(_) => project_block_extents(&self.ui_items),
- super::SidebarRowKind::Thread { project_id, .. } => {
- // In a collection Space the visible list is the reference
- // list, not the origin project's threads.
- let siblings = if crate::workspace_threads::is_collection_space(
- &self.active_space_id,
- ) {
- crate::workspace_threads::collection_thread_refs(&self.active_space_id)
+ super::SidebarRowKind::Thread {
+ thread_id,
+ project_id,
+ } => {
+ // A dragged reference row reorders within the Space's ref
+ // list, not within the origin project's threads.
+ let siblings = if self.sidebar_row_is_thread_ref(thread_id) {
+ crate::workspace_threads::space_thread_refs(&self.active_space_id)
} else {
crate::workspace_threads::unpinned_thread_ids(project_id)
};
@@ -2883,9 +2888,12 @@ impl super::TermWindow {
super::SidebarRowKind::Project(_) => {
crate::workspace_threads::ordered_project_ids(&self.active_space_id)
}
- super::SidebarRowKind::Thread { project_id, .. } => {
- if crate::workspace_threads::is_collection_space(&self.active_space_id) {
- crate::workspace_threads::collection_thread_refs(
+ super::SidebarRowKind::Thread {
+ thread_id,
+ project_id,
+ } => {
+ if self.sidebar_row_is_thread_ref(thread_id) {
+ crate::workspace_threads::space_thread_refs(
&self.active_space_id,
)
} else {
@@ -2930,7 +2938,7 @@ impl super::TermWindow {
project_id,
} => {
let space_id = self.active_space_id.clone();
- if crate::workspace_threads::is_collection_space(&space_id) {
+ if self.sidebar_row_is_thread_ref(thread_id) {
// Reference order is purely local; nothing travels to
// any server.
crate::workspace_threads::move_thread_ref_before(
@@ -3384,6 +3392,21 @@ impl super::TermWindow {
UIItemType::ProjectToggleThreads(project_id) => {
self.mouse_event_project_toggle_threads(project_id, event, context);
}
+ UIItemType::ThreadRefGroupToggle(group_key) => {
+ if let WMEK::Press(MousePress::Left) = event.kind {
+ if !self.thread_ref_groups_collapsed.remove(&group_key) {
+ self.thread_ref_groups_collapsed.insert(group_key);
+ }
+ context.invalidate();
+ }
+ context.set_cursor(Some(MouseCursor::Arrow));
+ }
+ UIItemType::ThreadRefGroupNewThread(origin_space_id) => {
+ if let WMEK::Press(MousePress::Left) = event.kind {
+ self.create_thread_in_ref_group(&origin_space_id, context);
+ }
+ context.set_cursor(Some(MouseCursor::Arrow));
+ }
UIItemType::Project(ref project_id) => {
let project_id = project_id.clone();
self.mouse_event_project(item, project_id, event, context);
@@ -3873,6 +3896,21 @@ impl super::TermWindow {
UIItemType::ProjectToggleThreads(project_id) => {
self.mouse_event_project_toggle_threads(project_id, event, context);
}
+ UIItemType::ThreadRefGroupToggle(group_key) => {
+ if let WMEK::Press(MousePress::Left) = event.kind {
+ if !self.thread_ref_groups_collapsed.remove(&group_key) {
+ self.thread_ref_groups_collapsed.insert(group_key);
+ }
+ context.invalidate();
+ }
+ context.set_cursor(Some(MouseCursor::Arrow));
+ }
+ UIItemType::ThreadRefGroupNewThread(origin_space_id) => {
+ if let WMEK::Press(MousePress::Left) = event.kind {
+ self.create_thread_in_ref_group(&origin_space_id, context);
+ }
+ context.set_cursor(Some(MouseCursor::Arrow));
+ }
UIItemType::Project(ref project_id) => {
let project_id = project_id.clone();
self.mouse_event_project(item, project_id, event, context);
@@ -4808,11 +4846,10 @@ impl super::TermWindow {
else {
return;
};
- // Collection rows reorder the local reference list, so the
+ // Reference rows reorder the local reference list, so the
// origin thread's pinned state is irrelevant there.
- let draggable = crate::workspace_threads::is_collection_space(
- &self.active_space_id,
- ) || !crate::workspace_threads::thread_is_pinned(&thread_id);
+ let draggable = self.sidebar_row_is_thread_ref(&thread_id)
+ || !crate::workspace_threads::thread_is_pinned(&thread_id);
let title = crate::workspace_threads::thread_name(&thread_id)
.unwrap_or_else(|| thread_id.clone());
self.arm_sidebar_row_drag(
@@ -4863,10 +4900,10 @@ impl super::TermWindow {
) {
match event.kind {
WMEK::Press(MousePress::Left) => {
- // In a collection Space the X removes the reference; the
+ // On a reference row the X removes the reference; the
// thread itself keeps living in its origin Space.
let space_id = self.active_space_id.clone();
- if crate::workspace_threads::is_collection_space(&space_id) {
+ if self.sidebar_row_is_thread_ref(&thread_id) {
if crate::workspace_threads::remove_thread_ref(&space_id, &thread_id) {
context.invalidate();
}
@@ -5128,13 +5165,6 @@ impl super::TermWindow {
ContextMenuIcon::New,
KeyAssignment::CreateSpace,
));
- let new_collection_item = self.context_menu_application_item_with_icon(
- crate::i18n::tr("menu-new-collection-space"),
- ContextMenuIcon::Pin,
- crate::termwindow::ContextMenuApplicationAction::CreateCollectionSpace,
- true,
- );
- items.push(new_collection_item);
items.push(ContextMenuItem::item_with_icon(
spaces
.iter()
@@ -5419,8 +5449,11 @@ impl super::TermWindow {
let thread_id = thread_id.to_string();
let is_pinned = crate::workspace_threads::thread_is_pinned(&thread_id);
let active_space = self.active_space_id.clone();
- let is_collection_ref = crate::workspace_threads::is_collection_space(&active_space)
- && crate::workspace_threads::thread_ref_exists(&active_space, &thread_id);
+ // The row is a reference when this Space holds a ref to a thread
+ // whose home is elsewhere.
+ let is_thread_ref = crate::workspace_threads::thread_ref_exists(&active_space, &thread_id)
+ && crate::workspace_threads::thread_space_id(&thread_id).as_deref()
+ != Some(active_space.as_str());
let live_workspaces = Mux::get().iter_workspaces();
let connection =
crate::workspace_threads::thread_connection_state(&thread_id, &live_workspaces);
@@ -5451,10 +5484,10 @@ impl super::TermWindow {
// On a reference row the pin toggle and Delete would mutate the
// origin thread while reading like row actions — the reference is
- // removed via "Remove from Collection" below instead. Rename and
+ // removed via "Remove from This Space" below instead. Rename and
// Mark Unread act on the real thread on purpose: a reference is a
// shortcut to it, not a copy.
- if !is_collection_ref {
+ if !is_thread_ref {
items.push(ContextMenuItem::item_with_icon(
if is_pinned {
crate::i18n::tr("menu-unpin-thread")
@@ -5474,7 +5507,7 @@ impl super::TermWindow {
ContextMenuIcon::Edit,
KeyAssignment::PromptRenameWorkspaceThread(thread_id.clone()),
));
- if !is_collection_ref {
+ if !is_thread_ref {
items.push(ContextMenuItem::item_with_icon(
crate::i18n::tr("menu-delete-thread"),
ContextMenuIcon::Delete,
@@ -5487,13 +5520,14 @@ impl super::TermWindow {
KeyAssignment::MarkWorkspaceThreadUnread(thread_id.clone()),
));
- // Collection Space section. Inside a collection the row is a
- // reference, so it can be removed here or traced back to its origin;
- // everywhere else the thread can be added to a collection.
- items.push(ContextMenuItem::Separator);
- if is_collection_ref {
+ // Reference section. On a reference row the ref can be removed here
+ // or traced back to its origin; on a thread's own row it can be
+ // added to any eligible Space (local, not its home, not already
+ // holding it).
+ if is_thread_ref {
+ items.push(ContextMenuItem::Separator);
let remove_item = self.context_menu_application_item_with_icon(
- crate::i18n::tr("menu-remove-from-collection"),
+ crate::i18n::tr("menu-remove-thread-ref"),
ContextMenuIcon::Close,
crate::termwindow::ContextMenuApplicationAction::RemoveThreadFromCollection {
collection_space_id: active_space,
@@ -5515,30 +5549,18 @@ impl super::TermWindow {
items.push(origin_item);
}
} else {
- let collections = crate::workspace_threads::collection_spaces();
- if collections.is_empty() {
- let add_item = self.context_menu_application_item_with_icon(
- crate::i18n::tr("menu-add-to-collection"),
- ContextMenuIcon::Pin,
- crate::termwindow::ContextMenuApplicationAction::AddThreadToCollection {
- collection_space_id: None,
- thread_id: thread_id.clone(),
- },
- true,
- );
- items.push(add_item);
- } else {
- for (space_id, name) in collections {
- let already =
- crate::workspace_threads::thread_ref_exists(&space_id, &thread_id);
+ let candidates = crate::workspace_threads::ref_host_candidates(&thread_id);
+ if !candidates.is_empty() {
+ items.push(ContextMenuItem::Separator);
+ for (space_id, name) in candidates {
let add_item = self.context_menu_application_item_with_icon(
- tr_with_name("menu-add-to-collection-named", &name),
+ tr_with_name("menu-add-to-space-named", &name),
ContextMenuIcon::Pin,
crate::termwindow::ContextMenuApplicationAction::AddThreadToCollection {
collection_space_id: Some(space_id),
thread_id: thread_id.clone(),
},
- !already,
+ true,
);
items.push(add_item);
}
@@ -5565,6 +5587,37 @@ impl super::TermWindow {
);
}
+ /// The reference group "+": create a thread in the group's origin
+ /// project — exactly the project-"+" flow — and auto-add a reference to
+ /// it in the current Space so it appears (and activates) right here.
+ pub(crate) fn create_thread_in_ref_group(
+ &mut self,
+ origin_space_id: &str,
+ context: &dyn WindowOps,
+ ) {
+ let Some(project_id) = crate::workspace_threads::ref_group_origin_project(
+ &self.active_space_id,
+ origin_space_id,
+ ) else {
+ context.invalidate();
+ return;
+ };
+ let thread_id = match crate::workspace_threads::create_thread(&project_id, None) {
+ Ok(thread_id) => thread_id,
+ Err(err) => {
+ log::warn!("failed to create thread in reference group: {err:#}");
+ context.invalidate();
+ return;
+ }
+ };
+ // Reference it before activating: the activation gate only lets this
+ // window open threads its Space owns or references.
+ crate::workspace_threads::add_thread_ref(&self.active_space_id, &thread_id);
+ if !self.open_remote_workspace_thread_without_connecting(&thread_id, context) {
+ self.activate_workspace_thread(thread_id, context);
+ }
+ }
+
pub(crate) fn create_workspace_thread(&mut self, project_id: &str, context: &dyn WindowOps) {
let thread_id = match crate::workspace_threads::create_thread(project_id, None) {
Ok(thread_id) => thread_id,
@@ -5615,27 +5668,15 @@ impl super::TermWindow {
self.snapshot_active_workspace_thread_layout();
let use_mosh = spec.use_mosh;
- // A collection Space owns no projects, so the SSH-hosts view (whose
- // footer button is reachable in a collection window too) must not
- // create the host project there — it would be permanently invisible.
- // The host lands in the default Space and the collection gets a
- // reference, which is exactly how a collection displays anything.
- let host_space_id =
- if crate::workspace_threads::is_collection_space(&self.active_space_id) {
- crate::workspace_threads::default_space_id()
- } else {
- self.active_space_id.clone()
- };
+ // Any Space can own projects now (a migrated collection simply
+ // becomes a mixed Space), so the host project lands right here.
let thread_id = crate::workspace_threads::create_disconnected_remote_host_thread(
- &host_space_id,
+ &self.active_space_id,
&host_id,
&spec.label,
crate::ssh_hosts::host_project_path(&spec),
spec.default_workspace.clone(),
);
- if host_space_id != self.active_space_id {
- crate::workspace_threads::add_thread_ref(&self.active_space_id, &thread_id);
- }
if !self.open_remote_workspace_thread_without_connecting(&thread_id, context) {
context.invalidate();
return false;
@@ -5904,6 +5945,16 @@ impl super::TermWindow {
);
}
+ /// Whether this sidebar row shows a thread REFERENCE: the active Space
+ /// holds a ref to it and its home is elsewhere (or unknown — a dangling
+ /// ref). Row affordances differ: references are removed, own threads
+ /// are deleted.
+ fn sidebar_row_is_thread_ref(&self, thread_id: &str) -> bool {
+ crate::workspace_threads::thread_ref_exists(&self.active_space_id, thread_id)
+ && crate::workspace_threads::thread_space_id(thread_id).as_deref()
+ != Some(self.active_space_id.as_str())
+ }
+
fn activate_workspace_thread_impl(
&mut self,
thread_id: String,
@@ -5913,23 +5964,27 @@ impl super::TermWindow {
) {
let thread_home_space = crate::workspace_threads::thread_space_id(&thread_id);
let in_this_space = thread_home_space.as_deref() == Some(self.active_space_id.as_str());
- // A collection Space window may activate any thread it references:
- // the reference opens in place while the thread keeps belonging to
- // its origin Space.
- let via_collection_ref = !in_this_space
+ // A window may activate any thread its Space references: the
+ // reference opens in place while the thread keeps belonging to its
+ // origin Space.
+ let via_thread_ref = !in_this_space
&& crate::workspace_threads::thread_ref_exists(&self.active_space_id, &thread_id);
- if !in_this_space && !via_collection_ref {
+ if !in_this_space && !via_thread_ref {
context.invalidate();
return;
}
- if via_collection_ref {
- // Remember the choice so switching back to the collection
- // restores this reference, like a normal Space restores its
- // active thread.
- crate::workspace_threads::note_collection_active_ref(
+ if via_thread_ref {
+ // Remember the choice so switching back to this Space restores
+ // the reference, like a normal Space restores its active thread.
+ crate::workspace_threads::note_thread_active_ref(
&self.active_space_id,
&thread_id,
);
+ } else {
+ // Activating one of the Space's own threads means the next
+ // switch back should follow the normal pointers, not jump to a
+ // previously opened reference.
+ crate::workspace_threads::clear_thread_active_ref(&self.active_space_id);
}
let mux = Mux::get();
@@ -5987,7 +6042,7 @@ impl super::TermWindow {
let Some(plan) = crate::workspace_threads::activate_thread_record(
&thread_id,
&live_workspaces,
- !via_collection_ref,
+ !via_thread_ref,
) else {
context.invalidate();
return;
@@ -6009,7 +6064,7 @@ impl super::TermWindow {
// That requires the domain to be attached first. For a collection
// reference the thread's own Space decides the domain — the
// collection Space itself is local and has none.
- let domain_space_id = if via_collection_ref {
+ let domain_space_id = if via_thread_ref {
thread_home_space
.clone()
.unwrap_or_else(|| self.active_space_id.clone())
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index 0378f740..5e6e5a14 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -1698,17 +1698,14 @@ impl super::TermWindow {
);
}
- /// The Space a layout snapshot should be recorded under. A collection
- /// Space window displays workspaces that belong to other Spaces, and the
- /// snapshot store refuses a Space/workspace mismatch — so resolve the
- /// workspace's own Space there; everywhere else the window's Space is it.
+ /// The Space a layout snapshot should be recorded under. A window
+ /// displaying a thread reference shows a workspace that belongs to
+ /// another Space, and the snapshot store refuses a Space/workspace
+ /// mismatch — so resolve the workspace's own Space; an unbound
+ /// workspace falls back to the window's Space.
fn space_id_for_layout_snapshot(&self, workspace: &str) -> String {
- if crate::workspace_threads::is_collection_space(&self.active_space_id) {
- if let Some(space_id) = crate::workspace_threads::space_id_for_workspace(workspace) {
- return space_id;
- }
- }
- self.active_space_id.clone()
+ crate::workspace_threads::space_id_for_workspace(workspace)
+ .unwrap_or_else(|| self.active_space_id.clone())
}
fn persist_workspace_pane_font_scales(&self) {
diff --git a/wezterm-gui/src/termwindow/ui/context_menu.rs b/wezterm-gui/src/termwindow/ui/context_menu.rs
index 2635f1c6..7c1744dc 100644
--- a/wezterm-gui/src/termwindow/ui/context_menu.rs
+++ b/wezterm-gui/src/termwindow/ui/context_menu.rs
@@ -231,10 +231,12 @@ impl crate::TermWindow {
collection_space_id,
thread_id,
} => {
- let collection_space_id = collection_space_id
- .unwrap_or_else(|| crate::workspace_threads::create_collection_space(None));
- if crate::workspace_threads::add_thread_ref(&collection_space_id, &thread_id) {
- self.invalidate_window();
+ // The menu only offers concrete eligible Spaces; a missing
+ // target (stale menu) is a silent no-op.
+ if let Some(host_space_id) = collection_space_id {
+ if crate::workspace_threads::add_thread_ref(&host_space_id, &thread_id) {
+ self.invalidate_window();
+ }
}
}
crate::termwindow::ContextMenuApplicationAction::RemoveThreadFromCollection {
@@ -245,15 +247,6 @@ impl crate::TermWindow {
self.invalidate_window();
}
}
- crate::termwindow::ContextMenuApplicationAction::CreateCollectionSpace => {
- let Some(window) = self.window.clone() else {
- return;
- };
- let space_id = crate::workspace_threads::create_collection_space(None);
- self.switch_space(space_id.clone(), &window);
- self.prompt_rename_space(space_id);
- window.invalidate();
- }
crate::termwindow::ContextMenuApplicationAction::DownloadRemoteFile {
path,
origin,
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index e474da35..0d25bc5b 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -357,6 +357,21 @@ impl crate::TermWindow {
.saturating_sub(1)
.saturating_mul(WORKSPACE_GROUP_EXTRA_GAP),
);
+ if !view.ref_groups.is_empty() {
+ if !view.pinned_threads.is_empty() || !view.projects.is_empty() {
+ height = height.saturating_add(WORKSPACE_GROUP_EXTRA_GAP);
+ }
+ for (group_idx, group) in view.ref_groups.iter().enumerate() {
+ if group_idx > 0 {
+ height = height.saturating_add(WORKSPACE_GROUP_EXTRA_GAP);
+ }
+ height = height.saturating_add(row_height + row_gap);
+ if !group.collapsed {
+ height = height
+ .saturating_add(group.threads.len().saturating_mul(row_height + row_gap));
+ }
+ }
+ }
height.saturating_sub(row_gap)
}
@@ -381,11 +396,18 @@ impl crate::TermWindow {
&self,
mut view: workspace_threads::WorkspaceThreadsView,
) -> workspace_threads::WorkspaceThreadsView {
- // A collection is a hand-curated list; hiding rows by work status
- // would blank it with no explanation.
- if crate::workspace_threads::is_collection_space(self.workspace_sidebar_space_id()) {
- return view;
- }
+ // This is the single choke point every sidebar consumer of the view
+ // passes through (paint, scroll height, hit testing), so the runtime
+ // collapse state of reference groups is stamped here — the three
+ // row-math sites must all see the same collapsed flags.
+ let space_id = self.workspace_sidebar_space_id().to_string();
+ for group in &mut view.ref_groups {
+ group.collapsed = self
+ .thread_ref_groups_collapsed
+ .contains(&format!("{space_id}::{}", group.key));
+ }
+ // Thread refs are a hand-curated list and are not filtered; the
+ // filter below only touches the Space's own pinned/project rows.
let hidden = crate::native_settings::workspace_sidebar_hidden_statuses()
.iter()
.filter_map(|key| workspace_threads::WorkspaceThreadWorkStatus::from_settings_key(key))
@@ -1587,13 +1609,7 @@ impl crate::TermWindow {
label_icon_size,
muted_fg,
)?;
- let section_label = if crate::workspace_threads::is_collection_space(
- self.workspace_sidebar_space_id(),
- ) {
- crate::i18n::tr("sidebar-collection-threads")
- } else {
- crate::i18n::tr("sidebar-pinned")
- };
+ let section_label = crate::i18n::tr("sidebar-pinned");
self.paint_sidebar_text(
layers,
&ui_font,
@@ -1713,39 +1729,20 @@ impl crate::TermWindow {
)?;
if is_hovered && !is_renaming_session {
- // In a collection Space the pin toggle would mutate
- // the origin thread; only removal makes sense there.
- let in_collection = crate::workspace_threads::is_collection_space(
- self.workspace_sidebar_space_id(),
- );
- // An X, not a trash can: the affordance removes the
- // reference, the origin thread keeps running.
- let mut affordances = vec![if in_collection {
+ let affordances = vec![
(
- delete_x,
- UIItemType::WorkspaceThreadDelete(session.id.clone()),
- SvgIcon::X,
- "sidebar remove collection reference button",
- )
- } else {
+ pin_x,
+ UIItemType::WorkspaceThreadPin(session.id.clone()),
+ SvgIcon::PinOff,
+ "sidebar unpin pinned thread button",
+ ),
(
delete_x,
UIItemType::WorkspaceThreadDelete(session.id.clone()),
SvgIcon::Trash2,
"sidebar delete pinned thread button",
- )
- }];
- if !in_collection {
- affordances.insert(
- 0,
- (
- pin_x,
- UIItemType::WorkspaceThreadPin(session.id.clone()),
- SvgIcon::PinOff,
- "sidebar unpin pinned thread button",
- ),
- );
- }
+ ),
+ ];
for (x, item_type, icon, _context_name) in affordances {
let hovered =
self.is_pointer_over_ui_rect(x, action_y, action_size, action_size);
@@ -2174,6 +2171,408 @@ impl crate::TermWindow {
}
}
+ if !view.ref_groups.is_empty() {
+ if !view.pinned_threads.is_empty() || !view.projects.is_empty() {
+ virtual_y += self.ui_px(WORKSPACE_GROUP_EXTRA_GAP);
+ }
+ // Reference groups render exactly like project folders: chevron,
+ // machine icon, machine name, then indented thread rows. The
+ // link icon in the header is what tells a reference group apart
+ // from a real project group with the same machine name.
+ let group_space_id = self.workspace_sidebar_space_id().to_string();
+ for (group_idx, group) in view.ref_groups.iter().enumerate() {
+ if group_idx > 0 {
+ virtual_y += self.ui_px(WORKSPACE_GROUP_EXTRA_GAP);
+ }
+ let row_top = list_top_f + virtual_y as f32 - scroll_offset;
+ let row_bottom = row_top + session_row_height as f32;
+ let row_is_visible = row_bottom > list_top_f && row_top < content_bottom_f;
+ let y = row_top.floor().max(0.0) as usize;
+
+ let disclosure_size = icon_size.min(22);
+ let disclosure_x = item_x + self.ui_px(SIDEBAR_INSET);
+ let group_icon_x = disclosure_x + disclosure_size + 4;
+ let group_text_x = group_icon_x + icon_size + self.ui_px(SIDEBAR_ICON_GAP);
+ let icon_y = y + ((session_row_height.saturating_sub(icon_size)) / 2);
+ let disclosure_y = y + ((session_row_height.saturating_sub(disclosure_size)) / 2);
+ let text_y = y + ((session_row_height.saturating_sub(ui_cell_height)) / 2);
+ let group_action_size =
+ section_button_size.min(session_row_height.saturating_sub(8));
+ let group_action_x = item_x
+ .saturating_add(item_width)
+ .saturating_sub(group_action_size + self.ui_px(SIDEBAR_INSET));
+ if row_is_visible {
+ let group_key = format!("{group_space_id}::{}", group.key);
+ self.ui_items.push(UIItem {
+ x: item_x,
+ y,
+ width: item_width,
+ height: session_row_height,
+ item_type: UIItemType::ThreadRefGroupToggle(group_key),
+ });
+ self.paint_sidebar_icon(
+ layers,
+ if group.collapsed {
+ SvgIcon::ChevronRight
+ } else {
+ SvgIcon::ChevronDown
+ },
+ disclosure_x,
+ disclosure_y,
+ disclosure_size,
+ muted_fg,
+ )?;
+ self.paint_sidebar_icon(
+ layers,
+ SvgIcon::Link2,
+ group_icon_x,
+ icon_y,
+ icon_size,
+ if group.attached {
+ muted_fg
+ } else {
+ muted_fg.mul_alpha(0.6)
+ },
+ )?;
+ // Header: origin-Space name, with the machine as a
+ // right-aligned badge. The name is the primary info, so
+ // when both cannot fit the badge is dropped first and
+ // the name keeps the full width (ellipsized as needed).
+ let header_fg = if group.attached {
+ muted_fg
+ } else {
+ muted_fg.mul_alpha(0.6)
+ };
+ let text_avail =
+ group_action_x.saturating_sub(group_text_x + self.ui_px(SIDEBAR_INSET));
+ let badge_pad = self.ui_px(6);
+ let badge_gap = self.ui_px(8);
+ // Badge typography: clearly smaller than the header name
+ // so it reads as metadata, matching the height of the
+ // "+" button beside it.
+ let badge_font = self
+ .fonts
+ .title_font_with_size(
+ crate::native_settings::sidebar_font_size() * 0.82,
+ )
+ .ok();
+ // Local needs no badge: the badge answers "which
+ // machine", and this machine is the answer by default.
+ let show_badge = group.machine_label != group.label
+ && !group.machine_label.is_empty()
+ && group.machine_label != "Local";
+ let badge = match (&badge_font, show_badge) {
+ (Some(badge_font), true) => {
+ let badge_metrics =
+ RenderMetrics::with_font_metrics(&badge_font.metrics());
+ (|| {
+ let text_w = self
+ .cached_ui_text_advance(
+ badge_font,
+ &badge_metrics,
+ &group.machine_label,
+ )
+ .ok()?
+ .ceil() as usize;
+ let name_w = self
+ .cached_ui_text_advance(
+ &ui_font,
+ &ui_metrics,
+ &group.label,
+ )
+ .ok()?
+ .ceil() as usize;
+ let badge_w = text_w + badge_pad * 2;
+ (name_w + badge_gap + badge_w <= text_avail)
+ .then_some((badge_w, badge_metrics))
+ })()
+ }
+ _ => None,
+ };
+ let name_avail = match &badge {
+ Some((badge_w, _)) => {
+ text_avail.saturating_sub(badge_w + badge_gap)
+ }
+ None => text_avail,
+ };
+ self.paint_sidebar_text(
+ layers,
+ &ui_font,
+ ui_metrics,
+ &group.label,
+ group_text_x,
+ text_y,
+ name_avail,
+ header_fg,
+ )?;
+ if let (Some((badge_w, badge_metrics)), Some(badge_font)) =
+ (badge, &badge_font)
+ {
+ // Same height as the "+" button so the trailing
+ // cluster reads as one aligned row of controls.
+ let badge_h = group_action_size;
+ let badge_x = group_action_x
+ .saturating_sub(self.ui_px(SIDEBAR_INSET) / 2 + badge_w);
+ let badge_y =
+ y + ((session_row_height.saturating_sub(badge_h)) / 2);
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(
+ badge_x as f32,
+ badge_y as f32,
+ badge_w as f32,
+ badge_h as f32,
+ ),
+ chrome.sidebar_button_bg,
+ self.ui_f32(SIDEBAR_ROW_RADIUS),
+ )
+ .context("sidebar ref group machine badge")?;
+ let badge_cell_h = badge_metrics.cell_size.height as usize;
+ self.paint_sidebar_text(
+ layers,
+ badge_font,
+ badge_metrics,
+ &group.machine_label,
+ badge_x + badge_pad,
+ badge_y + ((badge_h.saturating_sub(badge_cell_h)) / 2),
+ badge_w.saturating_sub(badge_pad),
+ header_fg,
+ )?;
+ }
+
+ // The group "+": create a thread in the origin project
+ // and auto-reference it here — same affordance as the
+ // project "+", inert (and dimmed) while the origin
+ // machine is unreachable.
+ let group_action_y =
+ y + ((session_row_height.saturating_sub(group_action_size)) / 2);
+ let group_action_hovered = group.attached
+ && !suppress_hover
+ && self.is_pointer_over_ui_rect(
+ group_action_x,
+ group_action_y,
+ group_action_size,
+ group_action_size,
+ );
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(
+ group_action_x as f32,
+ group_action_y as f32,
+ group_action_size as f32,
+ group_action_size as f32,
+ ),
+ if group_action_hovered {
+ chrome.sidebar_button_hover_bg
+ } else if group.attached {
+ chrome.sidebar_button_bg
+ } else {
+ chrome.sidebar_button_bg.mul_alpha(0.4)
+ },
+ self.ui_f32(SIDEBAR_ROW_RADIUS),
+ )
+ .context("sidebar ref group new thread button")?;
+ if group.attached {
+ self.ui_items.push(UIItem {
+ x: group_action_x,
+ y: group_action_y,
+ width: group_action_size,
+ height: group_action_size,
+ item_type: UIItemType::ThreadRefGroupNewThread(group.key.clone()),
+ });
+ }
+ let action_icon_size = (header_icon_size + 4).min(
+ group_action_size
+ .saturating_sub(self.ui_px(SIDEBAR_SECTION_ACTION_ICON_INSET)),
+ );
+ self.paint_sidebar_icon(
+ layers,
+ SvgIcon::Plus,
+ group_action_x
+ + ((group_action_size.saturating_sub(action_icon_size)) / 2),
+ group_action_y
+ + ((group_action_size.saturating_sub(action_icon_size)) / 2),
+ action_icon_size,
+ if group_action_hovered {
+ foreground
+ } else if group.attached {
+ muted_fg
+ } else {
+ muted_fg.mul_alpha(0.5)
+ },
+ )?;
+ }
+ virtual_y += session_row_height + row_gap;
+
+ if group.collapsed {
+ continue;
+ }
+ let session_x =
+ item_x + self.ui_px(SIDEBAR_INSET) * 3 + self.ui_px(SESSION_ROW_SIDE_PADDING);
+ let session_width = item_width.saturating_sub(
+ self.ui_px(SIDEBAR_INSET) * 3 + self.ui_px(SESSION_ROW_SIDE_PADDING) * 2,
+ );
+ let session_status_x = session_x + self.ui_px(SIDEBAR_INSET) + 2;
+ let session_text_x = session_status_x
+ + self.ui_px(SESSION_STATUS_ICON_SIZE)
+ + self.ui_px(SIDEBAR_ICON_GAP)
+ + 6;
+ for reference in &group.threads {
+ let session = &reference.thread;
+ let row_top = list_top_f + virtual_y as f32 - scroll_offset;
+ let row_bottom = row_top + session_row_height as f32;
+ let row_is_visible = row_bottom > list_top_f && row_top < content_bottom_f;
+ let y = row_top.floor().max(0.0) as usize;
+ let hit_y = row_top.max(list_top_f).floor().max(0.0) as usize;
+ let hit_bottom =
+ row_bottom.min(content_bottom_f).ceil().max(hit_y as f32) as usize;
+ let hit_height = hit_bottom.saturating_sub(hit_y).max(1);
+
+ if row_is_visible {
+ // A dangling ref has nothing to activate; it paints
+ // (greyed, removable) but registers no activation
+ // target.
+ if !reference.dangling {
+ self.ui_items.push(UIItem {
+ x: session_x,
+ y: hit_y,
+ width: session_width,
+ height: hit_height,
+ item_type: UIItemType::WorkspaceThread(session.id.clone()),
+ });
+ }
+ let is_hovered = !suppress_hover
+ && self.is_pointer_over_ui_rect(
+ session_x,
+ y,
+ session_width,
+ session_row_height,
+ );
+ let is_selected = self.is_workspace_sidebar_thread_selected(session);
+ let dimmed = reference.dangling || !reference.origin_domain_attached;
+ if is_selected {
+ self.fill_rounded_rectangle_with_border(
+ layers,
+ 0,
+ euclid::rect(
+ session_x as f32,
+ y as f32,
+ session_width as f32,
+ session_row_height as f32,
+ ),
+ selected_bg,
+ selected_border,
+ self.ui_f32(SIDEBAR_ROW_RADIUS) + 2.0,
+ CAPSULE_BORDER_WIDTH,
+ )
+ .context("sidebar selected thread ref")?;
+ } else if is_hovered {
+ self.fill_rounded_rectangle(
+ layers,
+ 0,
+ euclid::rect(
+ session_x as f32,
+ y as f32,
+ session_width as f32,
+ session_row_height as f32,
+ ),
+ chrome.sidebar_row_hover_bg,
+ self.ui_f32(SIDEBAR_ROW_RADIUS) + 2.0,
+ )
+ .context("sidebar hovered thread ref")?;
+ }
+
+ let text_y =
+ y + ((session_row_height.saturating_sub(ui_cell_height)) / 2);
+ let action_size = session_row_height.saturating_sub(8).clamp(
+ self.ui_px(SESSION_ACTION_MIN_SIZE),
+ self.ui_px(SESSION_ACTION_MAX_SIZE),
+ );
+ let delete_x = session_x
+ .saturating_add(session_width)
+ .saturating_sub(self.ui_px(SIDEBAR_INSET) + action_size);
+ let action_y =
+ y + ((session_row_height.saturating_sub(action_size)) / 2);
+ let text_right = if is_hovered {
+ delete_x
+ } else {
+ session_x
+ .saturating_add(session_width)
+ .saturating_sub(self.ui_px(SIDEBAR_INSET))
+ };
+ if !dimmed {
+ self.paint_sidebar_thread_status(
+ layers,
+ session,
+ session_status_x,
+ y,
+ session_row_height,
+ &chrome,
+ foreground,
+ )?;
+ }
+ let text_fg = if dimmed {
+ muted_fg.mul_alpha(0.7)
+ } else if is_selected {
+ active_fg
+ } else {
+ foreground
+ };
+ self.paint_sidebar_text(
+ layers,
+ &ui_font,
+ ui_metrics,
+ &session.name,
+ session_text_x,
+ text_y,
+ text_right
+ .saturating_sub(session_text_x + self.ui_px(SIDEBAR_INSET)),
+ text_fg,
+ )?;
+
+ if is_hovered {
+ // An X, not a trash can: removing a reference
+ // leaves the origin thread running untouched.
+ let hovered = self.is_pointer_over_ui_rect(
+ delete_x,
+ action_y,
+ action_size,
+ action_size,
+ );
+ self.ui_items.push(UIItem {
+ x: delete_x,
+ y: action_y,
+ width: action_size,
+ height: action_size,
+ item_type: UIItemType::WorkspaceThreadDelete(session.id.clone()),
+ });
+ let action_icon_size = action_size
+ .saturating_sub(self.ui_px(SESSION_ACTION_ICON_INSET))
+ .max(header_icon_size);
+ self.paint_sidebar_icon(
+ layers,
+ SvgIcon::X,
+ delete_x
+ + ((action_size.saturating_sub(action_icon_size)) / 2),
+ action_y
+ + ((action_size.saturating_sub(action_icon_size)) / 2),
+ action_icon_size,
+ if hovered {
+ foreground
+ } else {
+ muted_fg.mul_alpha(0.88)
+ },
+ )?;
+ }
+ }
+
+ virtual_y += session_row_height + row_gap;
+ }
+ }
+ }
+
self.workspace_sidebar_list_quads = list_quads_start.zip(layers.heap_mark());
let header_mask_height = list_top.saturating_sub(panel_y);
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 08dc5928..c44eb180 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -66,27 +66,59 @@ pub struct Space {
/// layout locally (the remote mux server owns the layout truth).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub client_domain: Option<String>,
- /// A collection Space holds `thread_refs` instead of projects: references
- /// to Threads that keep living in their own Spaces, possibly on other
- /// machines. Purely local — no server ever learns about it, which is what
- /// lets one Space mix threads from several mux domains without any
- /// protocol change. Never claimed by startup windows, never auto-seeded
- /// with a Home project.
- #[serde(default, skip_serializing_if = "std::ops::Not::not")]
+ /// Legacy marker of the retired "collection Space" prototype. Still
+ /// deserialized so old stores load, cleared by `normalize_after_load`
+ /// (the refs live on as ordinary `thread_refs` of a normal Space) and
+ /// never written back.
+ #[serde(default, skip_serializing)]
pub is_collection: bool,
- /// Thread ids referenced by a collection Space, in display order. Only
- /// the id is stored; the origin project/Space is resolved live, so a
- /// reference whose thread has vanished simply resolves to nothing and is
- /// pruned on the next load.
+ /// Thread ids referenced by this Space, in display order: references to
+ /// Threads that keep living in their own Spaces, possibly on other
+ /// machines. Purely local — no server ever learns about them, which is
+ /// what lets one Space mix threads from several mux domains without any
+ /// protocol change. Only local Spaces (`client_domain == None`) may hold
+ /// refs: ingest rebuilds domain-owned Spaces with an empty list.
+ /// The origin project/Space is resolved live; an unresolvable ref is
+ /// rendered from `thread_ref_meta` instead of disappearing.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub thread_refs: Vec<String>,
- /// The reference last opened from this collection, restored when the
- /// window switches back — a collection's counterpart of a normal Space's
- /// active project/thread pointers.
+ /// Last successfully resolved display data per ref, keyed by thread id.
+ /// This is what lets a ref survive its origin machine being offline or
+ /// its cached rows being dropped: the row paints greyed from this data,
+ /// and the ref is only pruned when the origin is attached and its tree
+ /// authoritatively lacks the thread.
+ #[serde(default, skip_serializing_if = "HashMap::is_empty")]
+ pub thread_ref_meta: HashMap<String, ThreadRefMeta>,
+ /// The reference last opened from this Space, restored when the window
+ /// switches back. Cleared when the user activates one of the Space's own
+ /// threads, so the restore follows whatever was used last.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub active_thread_ref: Option<String>,
}
+/// Cached display data for one thread ref, refreshed on every successful
+/// resolve. Purely presentational — activation always resolves live.
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub struct ThreadRefMeta {
+ /// The thread's name as of the last successful resolve.
+ pub last_name: String,
+ /// The origin mux domain, or `None` for a local origin. Locality is
+ /// encoded structurally rather than via a "Local" sentinel string,
+ /// because domain names are user-controlled — a host literally named
+ /// "Local" must not have its refs treated as local and pruned.
+ #[serde(default)]
+ pub origin_domain: Option<String>,
+}
+
+impl ThreadRefMeta {
+ /// The badge/fallback label for this ref's origin machine.
+ pub fn machine_label(&self) -> String {
+ self.origin_domain
+ .clone()
+ .unwrap_or_else(|| "Local".to_string())
+ }
+}
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SpaceVaultBinding {
pub root: PathBuf,
@@ -169,6 +201,32 @@ pub struct TerminalSpawnSpec {
pub struct WorkspaceThreadsView {
pub pinned_threads: Vec<WorkspaceThreadView>,
pub projects: Vec<ProjectView>,
+ /// Thread references this Space holds, grouped by origin machine so the
+ /// sidebar can render them as folder-style groups just like projects.
+ pub ref_groups: Vec<ThreadRefGroupView>,
+}
+
+/// One folder-style group of thread references sharing an origin Space.
+#[derive(Debug, Clone)]
+pub struct ThreadRefGroupView {
+ /// Stable group key: the origin Space id, or a machine-derived fallback
+ /// for dangling refs whose origin rows are gone from the cache.
+ pub key: String,
+ /// Header label: the origin Space's name (a machine hosts several
+ /// Spaces, so the machine alone would be ambiguous). Dangling groups
+ /// fall back to the cached machine label.
+ pub label: String,
+ /// The origin machine, shown as a small right-aligned badge on the
+ /// header (hidden when it would not fit, or when it just repeats the
+ /// label).
+ pub machine_label: String,
+ /// Whether the origin domain is currently attached; a detached group's
+ /// rows paint dimmed.
+ pub attached: bool,
+ /// Filled in by the sidebar from its runtime collapse state before
+ /// painting/geometry/hit-testing (never persisted here).
+ pub collapsed: bool,
+ pub threads: Vec<ThreadRefView>,
}
#[derive(Debug, Clone)]
@@ -215,7 +273,13 @@ pub struct ThreadRefView {
pub origin_domain_attached: bool,
/// The workspace this reference resolves to; the paint side compares it
/// against the window's current workspace to mark the active row.
+ /// Empty for a dangling ref.
pub workspace_name: String,
+ /// True when the thread could not be resolved from the local store and
+ /// this row was rebuilt from `ThreadRefMeta`. Painted greyed; clicking
+ /// it should try to attach `machine_label`'s domain rather than
+ /// activate directly.
+ pub dangling: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -957,56 +1021,6 @@ pub fn create_space(name: Option<String>) -> SpaceId {
id
}
-/// Create a collection Space: a purely local Space that holds references to
-/// Threads living in other Spaces (possibly other machines). No server ever
-/// learns about it.
-pub fn create_collection_space(name: Option<String>) -> SpaceId {
- let mut store = THREAD_STORE.lock();
- store.normalize_after_load();
- let name = name.unwrap_or_else(|| next_collection_space_name(&store.spaces));
- let id = store.create_space_record(name);
- if let Some(space) = store.spaces.iter_mut().find(|space| space.id == id) {
- space.is_collection = true;
- }
- // last_active_space_id is left alone on purpose: the menu flow switches
- // to the new Space explicitly (which records it), while "Add to
- // Collection" creates one in the background without visiting it.
- persist_locked(&store);
- id
-}
-
-/// "Collection", "Collection 2", …: several collections would otherwise be
-/// indistinguishable in the "Add to …" menu.
-fn next_collection_space_name(spaces: &[Space]) -> String {
- let mut index = 1;
- loop {
- let name = if index == 1 {
- "Collection".to_string()
- } else {
- format!("Collection {index}")
- };
- if !spaces.iter().any(|space| space.name == name) {
- return name;
- }
- index += 1;
- }
-}
-
-pub fn is_collection_space(space_id: &str) -> bool {
- THREAD_STORE.lock().is_collection_space(space_id)
-}
-
-/// (id, name) of every collection Space, for menu listings.
-pub fn collection_spaces() -> Vec<(SpaceId, String)> {
- THREAD_STORE
- .lock()
- .spaces
- .iter()
- .filter(|space| space.is_collection)
- .map(|space| (space.id.clone(), space.name.clone()))
- .collect()
-}
-
pub fn add_thread_ref(collection_space_id: &str, thread_id: &str) -> bool {
let mut store = THREAD_STORE.lock();
store.normalize_after_load();
@@ -1041,25 +1055,25 @@ pub fn move_thread_ref_before(
moved
}
-/// The reference list of a collection Space, in display order.
-pub fn collection_thread_refs(collection_space_id: &str) -> Vec<String> {
+/// The reference list of a Space, in display order.
+pub fn space_thread_refs(host_space_id: &str) -> Vec<String> {
THREAD_STORE
.lock()
.spaces
.iter()
- .find(|space| space.id == collection_space_id && space.is_collection)
+ .find(|space| space.id == host_space_id)
.map(|space| space.thread_refs.clone())
.unwrap_or_default()
}
-/// Remember which reference the user last opened from a collection, so the
+/// Remember which reference the user last opened from this Space, so the
/// next switch back restores it.
-pub fn note_collection_active_ref(collection_space_id: &str, thread_id: &str) {
+pub fn note_thread_active_ref(host_space_id: &str, thread_id: &str) {
let mut store = THREAD_STORE.lock();
let Some(space) = store
.spaces
.iter_mut()
- .find(|space| space.id == collection_space_id && space.is_collection)
+ .find(|space| space.id == host_space_id)
else {
return;
};
@@ -1072,16 +1086,81 @@ pub fn note_collection_active_ref(collection_space_id: &str, thread_id: &str) {
}
}
-pub fn thread_ref_exists(collection_space_id: &str, thread_id: &str) -> bool {
- THREAD_STORE
- .lock()
+/// Forget the ref-restore pointer: the user activated one of the Space's own
+/// threads, so switching back should follow the normal project/thread
+/// pointers again instead of jumping to a reference.
+pub fn clear_thread_active_ref(host_space_id: &str) {
+ let mut store = THREAD_STORE.lock();
+ let Some(space) = store
+ .spaces
+ .iter_mut()
+ .find(|space| space.id == host_space_id)
+ else {
+ return;
+ };
+ if space.active_thread_ref.take().is_some() {
+ schedule_workspace_thread_store_persist();
+ }
+}
+
+pub fn thread_ref_exists(host_space_id: &str, thread_id: &str) -> bool {
+ THREAD_STORE.lock().spaces.iter().any(|space| {
+ space.id == host_space_id && space.thread_refs.iter().any(|id| id == thread_id)
+ })
+}
+
+/// Deliberate host deletion: drop every Space's references whose origin
+/// machine is one of `machines`, meta included. A mere disconnect keeps refs
+/// greyed (the machine can come back); deleting the host record removes the
+/// only way this device could ever resolve them again, so leaving grey rows
+/// behind would be permanent clutter with no path to recovery.
+pub fn purge_thread_refs_for_machines(machines: &[String]) -> bool {
+ let mut store = THREAD_STORE.lock();
+ let changed = store.purge_refs_for_machines(machines);
+ if changed {
+ persist_locked(&store);
+ }
+ changed
+}
+
+/// The origin project a reference group's "+" should create a thread in:
+/// the project of the first resolvable ref in `host_space_id`'s list whose
+/// origin Space is `origin_space_id`.
+pub fn ref_group_origin_project(host_space_id: &str, origin_space_id: &str) -> Option<ProjectId> {
+ let store = THREAD_STORE.lock();
+ let space = store.spaces.iter().find(|space| space.id == host_space_id)?;
+ space.thread_refs.iter().find_map(|thread_id| {
+ let project = store
+ .projects
+ .iter()
+ .find(|project| project.threads.iter().any(|t| &t.id == thread_id))?;
+ (project.space_id == origin_space_id).then(|| project.id.clone())
+ })
+}
+
+/// (id, name) of every Space eligible to host a ref to `thread_id`: local
+/// Spaces that are not the thread's own home and do not already hold it.
+/// Feeds the "Add to Space …" submenu.
+pub fn ref_host_candidates(thread_id: &str) -> Vec<(SpaceId, String)> {
+ let store = THREAD_STORE.lock();
+ let home = store
+ .projects
+ .iter()
+ .find(|project| project.threads.iter().any(|thread| thread.id == thread_id))
+ .map(|project| project.space_id.clone());
+ let Some(home) = home else {
+ return Vec::new();
+ };
+ store
.spaces
.iter()
- .any(|space| {
- space.id == collection_space_id
- && space.is_collection
- && space.thread_refs.iter().any(|id| id == thread_id)
+ .filter(|space| {
+ space.client_domain.is_none()
+ && space.id != home
+ && !space.thread_refs.iter().any(|id| id == thread_id)
})
+ .map(|space| (space.id.clone(), space.name.clone()))
+ .collect()
}
/// Add another Space to a remote server.
@@ -1239,12 +1318,15 @@ fn delete_space_for_window_local(
.iter()
.find(|space| space.is_default && !occupied_by_other.contains(&space.id))
.or_else(|| {
- // A collection cannot rehome a window: it has no thread for
- // the window to adopt.
+ // A refs-only Space cannot rehome a window: it has no thread
+ // of its own for the window to adopt.
store
.spaces
.iter()
- .find(|space| !occupied_by_other.contains(&space.id) && !space.is_collection)
+ .find(|space| {
+ !occupied_by_other.contains(&space.id)
+ && !store.is_refs_only_space(&space.id)
+ })
})
.map(|space| space.id.clone())
.unwrap_or_else(|| {
@@ -1403,12 +1485,15 @@ pub async fn delete_space_for_window(
.iter()
.find(|space| space.is_default && !occupied_by_other.contains(&space.id))
.or_else(|| {
- // A collection cannot rehome a window: it has no thread for
- // the window to adopt.
+ // A refs-only Space cannot rehome a window: it has no thread
+ // of its own for the window to adopt.
store
.spaces
.iter()
- .find(|space| !occupied_by_other.contains(&space.id) && !space.is_collection)
+ .find(|space| {
+ !occupied_by_other.contains(&space.id)
+ && !store.is_refs_only_space(&space.id)
+ })
})
.map(|space| space.id.clone())
.unwrap_or_else(|| {
@@ -1430,16 +1515,27 @@ pub fn ensure_active_thread_for_space(space_id: &str) -> Option<WorkspaceThreadI
if !store.has_space(space_id) {
return None;
}
- // A collection Space owns no projects and must not be seeded with a Home
- // project; its rows are references into other Spaces. Switching to it
- // restores the reference the user last opened here (or the first one),
- // so the terminal follows the sidebar like it does in a normal Space.
- if store.is_collection_space(space_id) {
- let restore = store.collection_restore_ref(space_id);
+ // Ref restore: when the last thing opened from this Space was a thread
+ // reference, switching back restores it, so the terminal follows the
+ // sidebar. A Space with refs but no projects of its own (a migrated
+ // collection) restores its first ref rather than being seeded with a
+ // Home project it never asked for.
+ if let Some(restore) = store.thread_ref_to_restore(space_id) {
if changed {
persist_locked(&store);
}
- return restore;
+ return Some(restore);
+ }
+ // A refs-only Space whose refs are ALL currently dangling still must
+ // not fall through to seeding: merely switching to it would then
+ // permanently create a Home project and open a local shell, silently
+ // converting the Space. Better to activate nothing until a ref
+ // resolves again (or the user removes them).
+ if store.is_refs_only_space(space_id) {
+ if changed {
+ persist_locked(&store);
+ }
+ return None;
}
let project_id = store
.active_project_id_for_space(space_id)
@@ -1494,19 +1590,13 @@ pub fn space_id_for_workspace(workspace: &str) -> Option<SpaceId> {
}
/// The origin Space of `workspace`, but only when the thread it is bound to
-/// is actually referenced by `collection_space_id`. A collection window that
-/// was just switched to (nothing clicked yet) still displays the previous
-/// Space's workspace — that one must NOT leak through, or Files/paste would
+/// is actually referenced by `host_space_id`. A window that was just
+/// switched to (nothing clicked yet) still displays the previous Space's
+/// workspace — that one must NOT leak through, or Files/paste would
/// silently keep targeting the previous machine.
-pub fn origin_space_for_collection_workspace(
- collection_space_id: &str,
- workspace: &str,
-) -> Option<SpaceId> {
+pub fn origin_space_for_ref_workspace(host_space_id: &str, workspace: &str) -> Option<SpaceId> {
let store = THREAD_STORE.lock();
- let space = store
- .spaces
- .iter()
- .find(|space| space.id == collection_space_id && space.is_collection)?;
+ let space = store.spaces.iter().find(|space| space.id == host_space_id)?;
store.projects.iter().find_map(|project| {
project
.threads
@@ -1574,24 +1664,23 @@ pub fn view_for_current_project(
if store.normalize_after_load() {
persist_locked(&store);
}
- if store.is_collection_space(space_id) {
- // A collection Space renders its references where the pinned section
- // normally goes and owns no projects, so every existing geometry and
- // row-painting path works on this view unchanged. The machine tag
- // rides in the display name; the sidebar has no other per-row slot
- // without new painting code.
- let pinned_threads = store
- .view_for_collection_space(space_id, live_workspaces, Some(active_workspace))
- .into_iter()
- .map(|r| {
- let mut thread = r.thread;
- thread.name = format!("{} · {}", thread.name, r.machine_label);
- thread
- })
- .collect();
+ let ref_groups = group_thread_refs_by_origin(store.view_for_thread_refs(
+ space_id,
+ live_workspaces,
+ Some(active_workspace),
+ ));
+ // A Space with refs but no projects of its own (a migrated collection)
+ // must not be seeded with a synthetic current project just to have
+ // something to show — its ref rows are the content.
+ let has_own_projects = store
+ .projects
+ .iter()
+ .any(|project| project.space_id == space_id);
+ if !has_own_projects && !ref_groups.is_empty() {
return WorkspaceThreadsView {
- pinned_threads,
+ pinned_threads: Vec::new(),
projects: Vec::new(),
+ ref_groups,
};
}
if let Some(project_id) = store
@@ -1604,11 +1693,49 @@ pub fn view_for_current_project(
.any(|project| project.space_id == space_id && &project.id == project_id)
})
{
- return store.view_for_project(space_id, &project_id, live_workspaces);
+ let mut view = store.view_for_project(space_id, &project_id, live_workspaces);
+ view.ref_groups = ref_groups;
+ return view;
}
let is_remote = store.is_client_domain_space(space_id);
- current_project_for_workspace(space_id, active_workspace).view(live_workspaces, is_remote)
+ let mut view =
+ current_project_for_workspace(space_id, active_workspace).view(live_workspaces, is_remote);
+ view.ref_groups = ref_groups;
+ view
+}
+
+/// Fold resolved refs into folder-style groups keyed by origin Space, in
+/// first-appearance order of the Space's ref list. Dangling refs (origin
+/// rows gone) group under their cached machine label instead.
+fn group_thread_refs_by_origin(refs: Vec<ThreadRefView>) -> Vec<ThreadRefGroupView> {
+ let mut groups: Vec<ThreadRefGroupView> = Vec::new();
+ for reference in refs {
+ let key = if reference.origin_space_id.is_empty() {
+ format!("machine::{}", reference.machine_label)
+ } else {
+ reference.origin_space_id.clone()
+ };
+ match groups.iter_mut().find(|group| group.key == key) {
+ Some(group) => {
+ group.attached |= reference.origin_domain_attached;
+ group.threads.push(reference);
+ }
+ None => groups.push(ThreadRefGroupView {
+ key,
+ label: if reference.origin_space_name.is_empty() {
+ reference.machine_label.clone()
+ } else {
+ reference.origin_space_name.clone()
+ },
+ machine_label: reference.machine_label.clone(),
+ attached: reference.origin_domain_attached,
+ collapsed: false,
+ threads: vec![reference],
+ }),
+ }
+ }
+ groups
}
pub fn sync_current_project(space_id: &str, active_workspace: &str) -> bool {
@@ -3081,8 +3208,10 @@ fn tree_domain_for_thread(store: &WorkspaceThreadStore, thread_id: &str) -> Opti
}
fn remote_tree_domain_is_attached(domain_name: &str) -> bool {
- Mux::get()
- .get_domain_by_name(domain_name)
+ // try_get: unit tests and early startup have no Mux; "no mux" must read
+ // as "not attached" (the conservative answer that keeps refs alive).
+ Mux::try_get()
+ .and_then(|mux| mux.get_domain_by_name(domain_name))
.is_some_and(|domain| {
let Some(client) = domain.downcast_ref::<wezterm_client::domain::ClientDomain>() else {
return false;
@@ -3504,6 +3633,7 @@ impl Project {
is_remote,
distro: None,
}],
+ ref_groups: Vec::new(),
}
}
}
@@ -3521,6 +3651,7 @@ impl WorkspaceThreadStore {
client_domain: None,
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
changed = true;
@@ -3597,29 +3728,134 @@ impl WorkspaceThreadStore {
}
changed |= self.repair_cross_space_local_workspace_bindings();
changed |= self.ensure_unique_thread_names();
- changed |= self.prune_dangling_thread_refs();
+ changed |= self.retire_collection_spaces();
+ changed |= self.groom_thread_refs();
changed
}
- /// Drop collection references whose thread no longer exists anywhere.
- /// Server-side deletions arrive silently through ingest, so this runs as
- /// part of normalize (every store entry point) rather than only at the
- /// local delete sites; between runs the view builder simply skips
- /// unresolvable refs.
- fn prune_dangling_thread_refs(&mut self) -> bool {
- let known: std::collections::HashSet<&str> = self
- .projects
- .iter()
- .flat_map(|project| project.threads.iter().map(|thread| thread.id.as_str()))
- .collect();
+ /// The collection-Space prototype is retired: a Space that carried the
+ /// flag becomes an ordinary local Space and keeps its refs. The flag is
+ /// never written back, so this migration is idempotent and old binaries
+ /// can still read the store.
+ fn retire_collection_spaces(&mut self) -> bool {
+ let mut changed = false;
+ for space in &mut self.spaces {
+ if space.is_collection {
+ space.is_collection = false;
+ changed = true;
+ }
+ }
+ changed
+ }
+
+ /// See [`purge_thread_refs_for_machines`].
+ fn purge_refs_for_machines(&mut self, machines: &[String]) -> bool {
+ if machines.is_empty() {
+ return false;
+ }
let mut changed = false;
- for space in self.spaces.iter_mut().filter(|space| space.is_collection) {
- let before = space.thread_refs.len();
- space.thread_refs.retain(|id| known.contains(id.as_str()));
- changed |= space.thread_refs.len() != before;
- if let Some(active) = &space.active_thread_ref {
- if !space.thread_refs.contains(active) {
- space.active_thread_ref = None;
+ for space in &mut self.spaces {
+ if space.thread_refs.is_empty() {
+ continue;
+ }
+ let Space {
+ thread_refs,
+ thread_ref_meta,
+ active_thread_ref,
+ ..
+ } = space;
+ let before = thread_refs.len();
+ thread_refs.retain(|id| {
+ thread_ref_meta.get(id).is_none_or(|meta| {
+ meta.origin_domain
+ .as_ref()
+ .is_none_or(|domain| !machines.contains(domain))
+ })
+ });
+ if thread_refs.len() != before {
+ changed = true;
+ thread_ref_meta.retain(|id, _| thread_refs.iter().any(|r| r == id));
+ if let Some(active) = active_thread_ref {
+ if !thread_refs.contains(active) {
+ *active_thread_ref = None;
+ }
+ }
+ }
+ }
+ changed
+ }
+
+ /// Keep every Space's thread refs honest: refresh the cached display
+ /// meta for refs that resolve, and prune only refs whose absence is
+ /// authoritative. Server-side deletions arrive silently through ingest,
+ /// so this runs as part of normalize (every store entry point).
+ ///
+ /// A ref whose thread is missing from the store is NOT necessarily dead:
+ /// remote rows are only a cache, and a local "Disconnect" or a forgotten
+ /// host drops them while the thread lives on happily on its machine.
+ /// Such refs are kept and rendered greyed from `thread_ref_meta`; they
+ /// are dropped only when the origin domain is currently attached (its
+ /// tree just told us the thread is gone), the origin was local, or there
+ /// is no meta to render a row from (legacy pre-meta refs).
+ fn groom_thread_refs(&mut self) -> bool {
+ let mut resolved: HashMap<String, ThreadRefMeta> = HashMap::new();
+ if self.spaces.iter().any(|space| !space.thread_refs.is_empty()) {
+ for project in &self.projects {
+ let origin_domain = self
+ .spaces
+ .iter()
+ .find(|space| space.id == project.space_id)
+ .and_then(|space| space.client_domain.clone());
+ for thread in &project.threads {
+ resolved.insert(
+ thread.id.clone(),
+ ThreadRefMeta {
+ last_name: thread.name.clone(),
+ origin_domain: origin_domain.clone(),
+ },
+ );
+ }
+ }
+ }
+ let mut changed = false;
+ for space in &mut self.spaces {
+ if space.thread_refs.is_empty() && space.thread_ref_meta.is_empty() {
+ continue;
+ }
+ let Space {
+ thread_refs,
+ thread_ref_meta,
+ active_thread_ref,
+ ..
+ } = space;
+ thread_refs.retain(|id| {
+ if let Some(meta) = resolved.get(id.as_str()) {
+ if thread_ref_meta.get(id) != Some(meta) {
+ thread_ref_meta.insert(id.clone(), meta.clone());
+ changed = true;
+ }
+ return true;
+ }
+ let keep = match thread_ref_meta.get(id) {
+ // Legacy ref with no display data: nothing to render.
+ None => false,
+ // A local thread that is gone has no machine to come
+ // back from; a remote one is only authoritatively gone
+ // when its domain is attached to say so.
+ Some(meta) => match &meta.origin_domain {
+ None => false,
+ Some(domain) => !remote_tree_domain_is_attached(domain),
+ },
+ };
+ changed |= !keep;
+ keep
+ });
+ let before = thread_ref_meta.len();
+ thread_ref_meta.retain(|id, _| thread_refs.iter().any(|r| r == id));
+ changed |= thread_ref_meta.len() != before;
+ if let Some(active) = active_thread_ref {
+ if !thread_refs.contains(active) {
+ *active_thread_ref = None;
changed = true;
}
}
@@ -3650,6 +3886,7 @@ impl WorkspaceThreadStore {
client_domain,
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
id
@@ -3661,16 +3898,17 @@ impl WorkspaceThreadStore {
) -> SpaceId {
// Mux-domain Spaces belong to `thinkterm connect`; startup and Dock
// "New Window" must never claim them (they would materialize a local
- // shell into a remote-owned workspace). Collection Spaces hold thread
- // references rather than projects, so a startup window claiming one
- // would immediately seed it with a Home project it must not have.
+ // shell into a remote-owned workspace). Refs-only Spaces (migrated
+ // collections) hold thread references rather than projects, so a
+ // startup window claiming one would immediately seed it with a Home
+ // project it must not have.
self.last_active_space_id
.clone()
.filter(|space_id| {
self.has_space(space_id)
&& !occupied.contains(space_id)
&& !self.is_client_domain_space(space_id)
- && !self.is_collection_space(space_id)
+ && !self.is_refs_only_space(space_id)
})
.or_else(|| {
self.spaces
@@ -3678,7 +3916,7 @@ impl WorkspaceThreadStore {
.find(|space| {
!occupied.contains(&space.id)
&& space.client_domain.is_none()
- && !space.is_collection
+ && !self.is_refs_only_space(&space.id)
})
.map(|space| space.id.clone())
})
@@ -3739,35 +3977,79 @@ impl WorkspaceThreadStore {
.any(|space| space.id == space_id && space.client_domain.is_some())
}
- fn is_collection_space(&self, space_id: &str) -> bool {
+ /// A Space whose only content is thread references (a migrated
+ /// collection): it holds refs and owns no projects. Such a Space must
+ /// never be auto-seeded with a Home project.
+ fn is_refs_only_space(&self, space_id: &str) -> bool {
self.spaces
.iter()
- .any(|space| space.id == space_id && space.is_collection)
+ .any(|space| space.id == space_id && !space.thread_refs.is_empty())
+ && !self
+ .projects
+ .iter()
+ .any(|project| project.space_id == space_id)
}
- /// The reference a collection window should open on switch: the one the
- /// user last opened here when it is still referenced, else the first.
- fn collection_restore_ref(&self, space_id: &str) -> Option<WorkspaceThreadId> {
+ /// The reference to open when switching to this Space, if any: the one
+ /// the user last opened here (when still referenced), or — only for a
+ /// Space that has refs but no projects of its own, i.e. a migrated
+ /// collection — the first reference. A normal Space with both projects
+ /// and refs restores through its project/thread pointers unless a ref
+ /// was the last thing opened.
+ fn thread_ref_to_restore(&self, space_id: &str) -> Option<WorkspaceThreadId> {
let space = self.spaces.iter().find(|space| space.id == space_id)?;
- space
+ // A dangling ref (origin rows not in the local cache) cannot be
+ // activated, so it cannot be a restore target either.
+ let resolvable = |id: &String| {
+ self.projects
+ .iter()
+ .any(|project| project.threads.iter().any(|thread| &thread.id == id))
+ };
+ let last_opened = space
.active_thread_ref
.clone()
.filter(|id| space.thread_refs.contains(id))
- .or_else(|| space.thread_refs.first().cloned())
- }
-
- fn add_thread_ref(&mut self, collection_space_id: &str, thread_id: &str) -> bool {
- let exists = self
+ .filter(resolvable);
+ if last_opened.is_some() {
+ return last_opened;
+ }
+ let has_own_projects = self
.projects
.iter()
- .any(|project| project.threads.iter().any(|thread| thread.id == thread_id));
- if !exists {
+ .any(|project| project.space_id == space_id);
+ if has_own_projects {
+ return None;
+ }
+ space.thread_refs.iter().find(|id| resolvable(*id)).cloned()
+ }
+
+ fn add_thread_ref(&mut self, host_space_id: &str, thread_id: &str) -> bool {
+ // The thread must exist, and its home Space determines both the
+ // cached machine label and the "no ref to your own Space" rule.
+ let Some((home_space_id, thread_name)) = self.projects.iter().find_map(|project| {
+ project
+ .threads
+ .iter()
+ .find(|thread| thread.id == thread_id)
+ .map(|thread| (project.space_id.clone(), thread.name.clone()))
+ }) else {
+ return false;
+ };
+ if home_space_id == host_space_id {
return false;
}
+ let origin_domain = self
+ .spaces
+ .iter()
+ .find(|space| space.id == home_space_id)
+ .and_then(|space| space.client_domain.clone());
+ // Only local Spaces can host refs: ingest rebuilds domain-owned
+ // Spaces from the server tree with an empty ref list, so a ref
+ // added to one would silently vanish on the next sync.
let Some(space) = self
.spaces
.iter_mut()
- .find(|space| space.id == collection_space_id && space.is_collection)
+ .find(|space| space.id == host_space_id && space.client_domain.is_none())
else {
return false;
};
@@ -3775,14 +4057,21 @@ impl WorkspaceThreadStore {
return false;
}
space.thread_refs.push(thread_id.to_string());
+ space.thread_ref_meta.insert(
+ thread_id.to_string(),
+ ThreadRefMeta {
+ last_name: thread_name,
+ origin_domain,
+ },
+ );
true
}
- fn remove_thread_ref(&mut self, collection_space_id: &str, thread_id: &str) -> bool {
+ fn remove_thread_ref(&mut self, host_space_id: &str, thread_id: &str) -> bool {
let Some(space) = self
.spaces
.iter_mut()
- .find(|space| space.id == collection_space_id && space.is_collection)
+ .find(|space| space.id == host_space_id)
else {
return false;
};
@@ -3798,14 +4087,14 @@ impl WorkspaceThreadStore {
/// Purely local: reference order never travels to any server.
fn move_thread_ref_before(
&mut self,
- collection_space_id: &str,
+ host_space_id: &str,
thread_id: &str,
before: Option<&str>,
) -> bool {
let Some(space) = self
.spaces
.iter_mut()
- .find(|space| space.id == collection_space_id && space.is_collection)
+ .find(|space| space.id == host_space_id)
else {
return false;
};
@@ -3836,27 +4125,46 @@ impl WorkspaceThreadStore {
true
}
- fn view_for_collection_space(
+ fn view_for_thread_refs(
&self,
space_id: &str,
live_workspaces: &[String],
active_workspace: Option<&str>,
) -> Vec<ThreadRefView> {
- let Some(space) = self
- .spaces
- .iter()
- .find(|space| space.id == space_id && space.is_collection)
- else {
+ let Some(space) = self.spaces.iter().find(|space| space.id == space_id) else {
return Vec::new();
};
space
.thread_refs
.iter()
.filter_map(|thread_id| {
- let project = self
+ let Some(project) = self
.projects
.iter()
- .find(|project| project.threads.iter().any(|t| &t.id == thread_id))?;
+ .find(|project| project.threads.iter().any(|t| &t.id == thread_id))
+ else {
+ // Unresolvable: the origin rows are gone from the local
+ // cache (machine disconnected / host forgotten). Render a
+ // greyed row from the cached meta instead of vanishing.
+ let meta = space.thread_ref_meta.get(thread_id)?;
+ return Some(ThreadRefView {
+ thread: WorkspaceThreadView {
+ id: thread_id.clone(),
+ name: meta.last_name.clone(),
+ is_active: false,
+ is_materialized: false,
+ is_pinned: false,
+ is_unread: false,
+ work_status: WorkspaceThreadWorkStatus::Idle,
+ },
+ origin_space_id: String::new(),
+ origin_space_name: String::new(),
+ machine_label: meta.machine_label(),
+ origin_domain_attached: false,
+ workspace_name: String::new(),
+ dangling: true,
+ });
+ };
let origin = self.spaces.iter().find(|s| s.id == project.space_id)?;
let session = project.threads.iter().find(|t| &t.id == thread_id)?;
let workspace_name = session
@@ -3888,6 +4196,7 @@ impl WorkspaceThreadStore {
machine_label,
origin_domain_attached,
workspace_name,
+ dangling: false,
})
})
.collect()
@@ -4099,6 +4408,7 @@ impl WorkspaceThreadStore {
WorkspaceThreadsView {
pinned_threads,
projects,
+ ref_groups: Vec::new(),
}
}
@@ -4162,11 +4472,11 @@ impl WorkspaceThreadStore {
fn sync_current_project(&mut self, space_id: &str, active_workspace: &str) -> bool {
let mut changed = self.normalize_after_load();
- // A collection Space owns no projects: the workspace on display
- // belongs to a reference's origin Space, and falling through to
- // ensure_current_project would seed the collection with a Home
- // project the views never show.
- if self.is_collection_space(space_id) {
+ // A refs-only Space (a migrated collection) owns no projects: the
+ // workspace on display belongs to a reference's origin Space, and
+ // falling through to ensure_current_project would seed it with a
+ // Home project the views never show.
+ if self.is_refs_only_space(space_id) {
return changed;
}
if self.workspace_belongs_to_other_space(space_id, active_workspace) {
@@ -5024,6 +5334,7 @@ impl WorkspaceThreadStore {
client_domain: Some(domain_name.to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
}
})
@@ -6992,14 +7303,21 @@ mod tests {
}
#[test]
- fn collection_space_is_never_claimed_by_startup_windows() {
- let (mut store, coll_id, _, _) = store_with_collection();
- // Simulate the collection being the last thing the user looked at.
+ fn refs_only_space_is_never_claimed_by_startup_windows() {
+ let (mut store, coll_id, t1, _) = store_with_collection();
+ // A refs-only Space (holds references, owns no projects) must not be
+ // claimed: the startup window would seed it with a Home project.
+ assert!(store.add_thread_ref(&coll_id, &t1));
+ // Simulate it being the last thing the user looked at.
store.last_active_space_id = Some(coll_id.clone());
let mut occupied = std::collections::HashSet::new();
occupied.insert(DEFAULT_SPACE_ID.to_string());
let claimed = store.claim_available_space_id(&occupied);
- assert_ne!(claimed, coll_id, "startup window must not claim a collection Space");
+ assert_ne!(claimed, coll_id, "startup window must not claim a refs-only Space");
+ // Once emptied of refs it is an ordinary empty Space and claimable.
+ assert!(store.remove_thread_ref(&coll_id, &t1));
+ let claimed = store.claim_available_space_id(&occupied);
+ assert_eq!(claimed, coll_id);
}
#[test]
@@ -7058,7 +7376,7 @@ mod tests {
.thread_refs
.push("thread-gone".to_string());
- let views = store.view_for_collection_space(&coll, &[], None);
+ let views = store.view_for_thread_refs(&coll, &[], None);
assert_eq!(views.len(), 1);
let view = &views[0];
assert_eq!(view.thread.id, t1);
@@ -7068,7 +7386,7 @@ mod tests {
assert!(!view.thread.is_active);
// Active-row detection keys off the resolved workspace name.
- let active = store.view_for_collection_space(&coll, &[], Some(view.workspace_name.as_str()));
+ let active = store.view_for_thread_refs(&coll, &[], Some(view.workspace_name.as_str()));
assert!(active[0].thread.is_active);
}
@@ -7112,29 +7430,153 @@ mod tests {
}
#[test]
- fn sync_current_project_never_seeds_collections() {
- let (mut store, coll, _, _) = store_with_collection();
+ fn sync_current_project_never_seeds_refs_only_spaces() {
+ let (mut store, coll, t1, _) = store_with_collection();
+ assert!(store.add_thread_ref(&coll, &t1));
// An unbound workspace (e.g. its thread binding was pruned by a
// remote delete) used to fall through to ensure_current_project.
store.sync_current_project(&coll, "some-unbound-workspace");
assert!(
store.projects.iter().all(|project| project.space_id != coll),
- "a collection Space must never acquire a project"
+ "a refs-only Space must never acquire a project"
+ );
+ }
+
+ #[test]
+ fn migration_retires_the_collection_flag_but_keeps_refs() {
+ let (mut store, coll, t1, _) = store_with_collection();
+ assert!(store.add_thread_ref(&coll, &t1));
+ assert!(store.spaces.iter().any(|s| s.id == coll && s.is_collection));
+ store.normalize_after_load();
+ let space = store.spaces.iter().find(|s| s.id == coll).unwrap();
+ assert!(!space.is_collection, "the flag is retired on normalize");
+ assert_eq!(space.thread_refs, vec![t1.clone()]);
+ assert_eq!(
+ space.thread_ref_meta.get(&t1).map(|m| m.origin_domain.clone()),
+ Some(None),
+ "normalize refreshes the cached meta for resolvable refs"
+ );
+ }
+
+ #[test]
+ fn refs_can_live_on_ordinary_spaces_but_not_remote_or_home_ones() {
+ let (mut store, _, t1, _) = store_with_collection();
+ // An ordinary local Space is a valid host.
+ let host = store.create_space_record("Studies".to_string());
+ assert!(store.add_thread_ref(&host, &t1));
+ // The thread's own home Space is not.
+ assert!(!store.add_thread_ref(DEFAULT_SPACE_ID, &t1));
+ // A domain-owned Space is not: ingest would wipe the ref.
+ let remote = store.create_space_record_for_domain("syd".to_string(), Some("syd".into()));
+ assert!(!store.add_thread_ref(&remote, &t1));
+ }
+
+ #[test]
+ fn dangling_remote_ref_is_kept_and_rendered_from_meta() {
+ let mut store = remote_test_store("syd");
+ assert!(store.ingest_remote_tree("syd", &sample_tree()));
+ let host = store.create_space_record("Studies".to_string());
+ let remote_thread = store.projects.iter().find(|p| p.id == "rp1").unwrap().threads[0]
+ .id
+ .clone();
+ let remote_name = store.projects.iter().find(|p| p.id == "rp1").unwrap().threads[0]
+ .name
+ .clone();
+ assert!(store.add_thread_ref(&host, &remote_thread));
+
+ // The machine disconnects locally: its cached rows are dropped, the
+ // way delete_space/forget_spaces_of_deleted_hosts drop them.
+ store.projects.retain(|p| p.id != "rp1");
+ store.normalize_after_load();
+
+ let space = store.spaces.iter().find(|s| s.id == host).unwrap();
+ assert_eq!(
+ space.thread_refs,
+ vec![remote_thread.clone()],
+ "a ref must survive its origin's cache being dropped"
+ );
+ let views = store.view_for_thread_refs(&host, &[], None);
+ assert_eq!(views.len(), 1);
+ assert!(views[0].dangling);
+ assert_eq!(views[0].thread.name, remote_name);
+ assert_eq!(views[0].machine_label, "syd");
+ assert!(!views[0].origin_domain_attached);
+ }
+
+ #[test]
+ fn local_thread_deletion_prunes_its_refs_authoritatively() {
+ let (mut store, coll, t1, _) = store_with_collection();
+ assert!(store.add_thread_ref(&coll, &t1));
+ store.normalize_after_load(); // meta records "Local"
+ for project in &mut store.projects {
+ project.threads.retain(|t| t.id != t1);
+ }
+ store.normalize_after_load();
+ let space = store.spaces.iter().find(|s| s.id == coll).unwrap();
+ assert!(
+ space.thread_refs.is_empty(),
+ "a deleted local thread's ref has no machine to come back from"
+ );
+ assert!(space.thread_ref_meta.is_empty(), "meta is groomed with it");
+ }
+
+ #[test]
+ fn deleting_a_host_purges_its_refs_but_keeps_other_machines() {
+ let mut store = remote_test_store("syd");
+ assert!(store.ingest_remote_tree("syd", &sample_tree()));
+ let host = store.create_space_record("Studies".to_string());
+ let remote_thread = store.projects.iter().find(|p| p.id == "rp1").unwrap().threads[0]
+ .id
+ .clone();
+ // One ref to the doomed machine, one local ref that must survive.
+ let mut local_project = default_project_for_space(DEFAULT_SPACE_ID);
+ let local_thread = WorkspaceThread::new(local_project.id.clone(), "keep".to_string(), None);
+ let local_id = local_thread.id.clone();
+ local_project.threads.push(local_thread);
+ store.projects.push(local_project);
+ assert!(store.add_thread_ref(&host, &remote_thread));
+ assert!(store.add_thread_ref(&host, &local_id));
+ store
+ .spaces
+ .iter_mut()
+ .find(|s| s.id == host)
+ .unwrap()
+ .active_thread_ref = Some(remote_thread.clone());
+
+ assert!(store.purge_refs_for_machines(&["syd".to_string()]));
+ let space = store.spaces.iter().find(|s| s.id == host).unwrap();
+ assert_eq!(space.thread_refs, vec![local_id.clone()]);
+ assert!(!space.thread_ref_meta.contains_key(&remote_thread));
+ assert_eq!(space.active_thread_ref, None, "purged ref cannot stay active");
+ assert!(
+ !store.purge_refs_for_machines(&["syd".to_string()]),
+ "second purge is a no-op"
);
}
#[test]
- fn collection_names_stay_distinguishable() {
- let (mut store, _, _, _) = store_with_collection();
- assert_eq!(next_collection_space_name(&store.spaces), "Collection 2");
- let id = store.create_space_record("Collection 2".to_string());
+ fn ref_restore_yields_to_a_spaces_own_threads_unless_a_ref_was_last() {
+ let (mut store, _, t1, _) = store_with_collection();
+ let host = store.create_space_record("Studies".to_string());
+ // Give the host its own project so it is not refs-only.
+ let mut project = default_project_for_space(&host);
+ project.space_id = host.clone();
+ let own = WorkspaceThread::new(project.id.clone(), "own".to_string(), None);
+ project.threads.push(own);
+ store.projects.push(project);
+ assert!(store.add_thread_ref(&host, &t1));
+
+ // Nothing marked last-opened: the Space's own pointers win.
+ assert_eq!(store.thread_ref_to_restore(&host), None);
+
+ // A ref was last opened here: restore it.
store
.spaces
.iter_mut()
- .find(|space| space.id == id)
+ .find(|s| s.id == host)
.unwrap()
- .is_collection = true;
- assert_eq!(next_collection_space_name(&store.spaces), "Collection 3");
+ .active_thread_ref = Some(t1.clone());
+ assert_eq!(store.thread_ref_to_restore(&host).as_deref(), Some(t1.as_str()));
}
#[test]
@@ -7143,7 +7585,7 @@ mod tests {
assert!(store.add_thread_ref(&coll, &t1));
assert!(store.add_thread_ref(&coll, &t2));
// Nothing opened yet: fall back to the first reference.
- assert_eq!(store.collection_restore_ref(&coll).as_deref(), Some(t1.as_str()));
+ assert_eq!(store.thread_ref_to_restore(&coll).as_deref(), Some(t1.as_str()));
store
.spaces
@@ -7151,13 +7593,13 @@ mod tests {
.find(|s| s.id == coll)
.unwrap()
.active_thread_ref = Some(t2.clone());
- assert_eq!(store.collection_restore_ref(&coll).as_deref(), Some(t2.as_str()));
+ assert_eq!(store.thread_ref_to_restore(&coll).as_deref(), Some(t2.as_str()));
// Removing the remembered reference clears it and falls back.
assert!(store.remove_thread_ref(&coll, &t2));
let space = store.spaces.iter().find(|s| s.id == coll).unwrap();
assert_eq!(space.active_thread_ref, None);
- assert_eq!(store.collection_restore_ref(&coll).as_deref(), Some(t1.as_str()));
+ assert_eq!(store.thread_ref_to_restore(&coll).as_deref(), Some(t1.as_str()));
}
#[test]
@@ -8337,6 +8779,7 @@ mod tests {
is_remote: false,
distro: None,
}],
+ ref_groups: Vec::new(),
};
filter_threads_view_by_status(&mut view, &hidden);
assert!(view.pinned_threads.is_empty());
@@ -9390,6 +9833,7 @@ mod tests {
client_domain: Some(domain.to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
store
@@ -9847,6 +10291,7 @@ mod tests {
client_domain: Some("ams".to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
@@ -9899,6 +10344,7 @@ mod tests {
client_domain: Some("ssh:[email protected]".to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
store.spaces.push(Space {
@@ -9910,6 +10356,7 @@ mod tests {
client_domain: Some("DO AMS".to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
@@ -9944,6 +10391,7 @@ mod tests {
client_domain: Some("syd".to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
store.projects.push(Project {
@@ -9981,6 +10429,7 @@ mod tests {
client_domain: Some("syd".to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
@@ -10048,6 +10497,7 @@ mod tests {
client_domain: Some("syd".to_string()),
is_collection: false,
thread_refs: Vec::new(),
+ thread_ref_meta: HashMap::new(),
active_thread_ref: None,
});
// Once it is known, they are hands off.