Skip to content
Draft
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a4d940c
feat(sidebar): categorize and group lane sessions
teamleaderleo Oct 30, 2026
3c8cd86
Keep fleet lineage children under their live parent
teamleaderleo Oct 30, 2026
449f147
Group visible session workspaces by host without dropping lineage chi…
teamleaderleo Oct 30, 2026
a6a79ee
Preserve sidebar placement and drag geometry in opt-in host groups
teamleaderleo Oct 30, 2026
e21e465
Map grouped sidebar drag slots to document positions
teamleaderleo Oct 30, 2026
cef5e0f
Keep sidebar projection flat without a local identity
teamleaderleo Oct 30, 2026
cc8aa43
Resolve grouped sidebar drops by drawn family and section
teamleaderleo Oct 30, 2026
2fd66d2
fix(sidebar): refuse all in-sidebar drops while host groups show
teamleaderleo Oct 30, 2026
534c2ca
test(sidebar): assert real list refuses host-group drops
teamleaderleo Oct 30, 2026
e109519
fix(sidebar): refuse group and tab drops with host headers
teamleaderleo Oct 30, 2026
b5d3bda
fix(sidebar): decide host-drop refusal at drag start
teamleaderleo Oct 30, 2026
de77999
fix(sidebar): gate pin drops after host refusal
teamleaderleo Oct 30, 2026
3f09758
fix(sidebar): stabilize host refusal and tab proposals
teamleaderleo Oct 30, 2026
282608c
chore(sidebar): remove drag-layout refusal check
teamleaderleo Oct 30, 2026
209d3a7
test(sidebar): cover host refusal drag matrix
teamleaderleo Oct 30, 2026
0510cfc
test(sidebar): cover external tab drop refusal matrix
teamleaderleo Oct 30, 2026
3e968b7
test(sidebar): disambiguate sections and isolate GUI matrix
teamleaderleo Oct 30, 2026
4739057
fix(sidebar): keep folded families and cross-group lineage in host gr…
teamleaderleo Oct 31, 2026
6b478a9
fix(sidebar): keep cross-machine lineage inside headed machine sections
teamleaderleo Oct 31, 2026
47a402f
test(sidebar): sessionHosts capture fixture for the session tree host…
teamleaderleo Oct 31, 2026
32a9bc1
fix(sidebar): resolve host tab drop merge markers
teamleaderleo Nov 1, 2026
a7c3c7a
fix(sidebar): remove stale conflict markers
teamleaderleo Nov 1, 2026
8cd1fd1
fix(sidebar): group current workspace rows after tab removal
teamleaderleo Nov 1, 2026
d26ad29
fix(sidebar): use current tab-drop resolver signature
teamleaderleo Nov 1, 2026
43288ae
fix(sidebar): use supported tab drop targets
teamleaderleo Nov 1, 2026
a4d09da
test(sidebar): remove retired tab-row fixture setting
teamleaderleo Nov 1, 2026
5c6402d
Merge remote-tracking branch 'origin/feat-cmux-next' into lane/ux-sid…
teamleaderleo Nov 8, 2026
f22d459
sidebar: the nested fixture's session tree merge lives in CmuxNextSid…
teamleaderleo Nov 8, 2026
26e56ef
sidebar: test that a host header never takes a Pinned parent's fold away
teamleaderleo Nov 8, 2026
6e760a3
sidebar: a host header keeps a Pinned or custom parent's fold control
teamleaderleo Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public final class SidebarSessionTreeFeed {
return nil
}
var state = SidebarSessionTreeState()
// A missing local identity means we cannot distinguish this install from
// fleet peers. Leave host grouping off until the identity is known.
if let localHost {
let localHosts = Set(keys(localHost))
for (id, refs) in chats {
// Local agent tabs remain in the ordinary local list. Host grouping
// is reserved for fleet sessions, excluding this install and aliases.
guard let ref = refs.first(where: { $0.session != nil && !localHosts.contains($0.host) }) else { continue }
// Keep the tab's primary host as the fold identity; alias discovery
// must not rename a user's collapsed host bucket.
let host = ref.host
state.hosts[id] = host
state.hostNames[host] = state.hostNames[host] ?? ref.hostName ?? ref.host
}
}
var agentStates: [SidebarWorkspaceID: SidebarAgentState] = [:]
var asks: Set<String> = []
for (id, refs) in remote {
Expand Down Expand Up @@ -190,6 +205,11 @@ public final class SidebarSessionTreeFeed {
state.parents[id] = parent
}
}
if localHost == nil {
// Without this install's identity, fleet buckets stay off. Recorded
// lineage remains useful and is still projected by Session Tree.
state.hosts.removeAll()
}
return Pass(state: state, asks: asks)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ struct DebugSidebarNestedFixture {
sidebar.model.filterText = ""
sidebar.rows.fixture = fixture.sections
// The needs-you scenario's who-started-whom, while the session tree is on (the feed's next pass replaces it).
if !fixture.parents.isEmpty, var tree = SidebarSessionTree.shared.state {
if !fixture.parents.isEmpty || !fixture.hosts.isEmpty, var tree = SidebarSessionTree.shared.state {
tree.parents.merge(fixture.parents) { _, fixture in fixture }
tree.hosts.merge(fixture.hosts) { _, fixture in fixture }
tree.hostNames.merge(fixture.hostNames) { _, fixture in fixture }
SidebarSessionTree.shared.state = tree
}
sidebar.container.layoutSubtreeIfNeeded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ nonisolated struct RustRowKey: Codable {
kind = "folder"
id = nil
section = RustSectionID(value)
case let .sessionHost(host):
kind = "session_host"
id = host
section = nil
case let .status(status):
// Never sent either: Group by Status's headers are labels and fold controls only.
kind = "status"
Expand Down Expand Up @@ -124,7 +128,7 @@ nonisolated struct RustRow: Codable {
case .item:
if let group = row.group?.rawValue { itemTops[group] = max(itemTops[group] ?? -.infinity, Double(row.y)) }
continue
case .folder, .status, .emptyGroup:
case .folder, .sessionHost, .status, .emptyGroup:
continue
default:
if case .custom = row.section { continue } // the older resolver knows Pinned and machines only
Expand Down Expand Up @@ -183,6 +187,7 @@ nonisolated struct RustRow: Codable {
height = Double(row.height)
section = RustSectionID(row.section)
group = row.group?.rawValue

siblingIndex = row.siblingIndex
parentIndex = row.parentIndex
isLastInGroup = row.isLastInGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension SidebarLayout {
switch row.key {
case .workspace, .doneFold, .showMore, .emptyGroup: row.group
case .group(let group): row.isCollapsed ? nil : group
case .section, .emptySection, .folder, .status, .item, .block: nil
case .section, .emptySection, .folder, .sessionHost, .status, .item, .block: nil
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import Foundation

nonisolated extension SidebarLayout {
/// Group only existing loose agent workspaces. The window's drawn rows decide whether a
/// lineage parent is live, never the daemon's lane census. Retain each row's document section
/// and sibling index so selection, close and drop continue to target the original workspace.
func groupingSessions(_ tree: SidebarSessionTreeState, sections: [SidebarSection], gap: DropPosition?, metrics m: SidebarLayoutMetrics) -> SidebarLayout {
var bundles: [Int: [SidebarRow]] = [:]
var starts: [Int] = []
for (i, row) in rows.enumerated() {
guard case .workspace = row.key else { continue }
starts.append(i)
bundles[i] = [row]
}
let drawnIDs: [WorkspaceID?] = starts.map { if case let .workspace(id) = rows[$0].key { id } else { nil } }
// The base projection already dropped the descendants of a folded loose parent. Keep
// them as undrawn entries after the drawn ones (indices past `starts`) so that parent
// keeps its chevron and roll-up and its host badge counts the whole family. They never
// draw: `family` stops at a folded parent, and roots are drawn entries only.
let drawn = Set(drawnIDs.compactMap { $0 })
var seenFolded: Set<WorkspaceID> = []
// Only loose rows fold away with their parent (a group's members never do).
let loose = sections.flatMap(\.nodes).compactMap { node -> WorkspaceID? in
if case let .workspace(ws) = node { ws.id } else { nil }
}
let folded = loose.filter { id in
guard !drawn.contains(id), seenFolded.insert(id).inserted else { return false }
var path: Set<WorkspaceID> = [id]
var next = tree.parents[id]
while let current = next, path.insert(current).inserted {
if drawn.contains(current) { return tree.collapsed.contains(current) }
next = tree.parents[current]
}
return false
}
let ids: [WorkspaceID?] = drawnIDs + folded.map { Optional($0) }
// A visible parent inside an explicit user group is still a lineage anchor. Only
// loose children move; explicitly placed members keep the user's document order.
let looseIDs = Set(starts.compactMap { i -> WorkspaceID? in
guard rows[i].group == nil, case .machine = rows[i].section,
case let .workspace(id) = rows[i].key else { return nil }
return id
})
let machineParents = Set(starts.compactMap { i -> WorkspaceID? in
guard case let .workspace(id) = rows[i].key,
case .machine = rows[i].section else { return nil }
return id
})
// A child crosses into another machine section only in one list, where neither
// section draws a header. Under per-computer headers it stays below its own
// machine's header rather than drawing under the previous machine's.
let headed = Set(rows.compactMap { row -> SectionID? in if case let .section(id) = row.key { id } else { nil } })
let sectionOf = Dictionary(starts.compactMap { i -> (WorkspaceID, SectionID)? in
if case let .workspace(id) = rows[i].key { (id, rows[i].section) } else { nil }
}, uniquingKeysWith: { first, _ in first })
func crossesHeader(_ child: WorkspaceID, _ parent: WorkspaceID) -> Bool {
guard let a = sectionOf[child], let b = sectionOf[parent], a != b else { return false }
return headed.contains(a) || headed.contains(b)
}
// Preserve the Pinned/custom boundary: a fleet child of a pinned workspace
// remains in its own machine group rather than being pulled into Pinned.
let parents = tree.parents.filter { looseIDs.contains($0.key) && machineParents.contains($0.value)
&& !crossesHeader($0.key, $0.value) }
.merging(folded.compactMap { id in tree.parents[id].map { (id, $0) } }, uniquingKeysWith: { first, _ in first })
let children = Self.treeChildren(ids, parents: parents)
let nested = Set(children.values.joined())
let roots = starts.indices.filter { !nested.contains($0) }
struct HostKey: Hashable {
let host: String
let section: SectionID
}
var hosts: [HostKey: [Int]] = [:]
var rootHosts: [Int: HostKey] = [:]
for root in roots {
guard rows[starts[root]].group == nil, let id = ids[root], let host = tree.hosts[id],
case .machine = rows[starts[root]].section else { continue }
let key = HostKey(host: host, section: rows[starts[root]].section)
rootHosts[root] = key
hosts[key, default: []].append(root)
}
let workspaceByID = Dictionary(sections.flatMap(\.workspaces).map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
func agentState(_ index: Int) -> SidebarAgentState {
guard let id = ids[index], let ws = workspaceByID[id] else { return .idle }
return SidebarAgentState.of(ws, lane: tree.states[id])
}
// Reordering only the workspace bundles leaves user groups, document items and section
// blocks in their existing order. Each host is emitted at its first root's old position.
var emitted: Set<HostKey> = []
let byStart = Dictionary(starts.enumerated().map { ($0.element, $0.offset) }, uniquingKeysWith: { first, _ in first })
var result: [SidebarRow] = []
var y: CGFloat = 0
var movedGapY: CGFloat?, movedPinnedY: CGFloat?, movedEarlierY: CGFloat?
// A drop before a workspace follows that workspace when lineage reorders it.
// Section-end drops stay in their boundary, before history or the next section.
let gapTarget: SidebarRowKey? = gapY.flatMap { oldGap in
guard let gap, let next = rows.first(where: { $0.y >= oldGap + gapShift }),
next.section == gap.section, next.group == gap.group,
case .workspace = next.key else { return nil }
return next.key
}
func openGap() {
guard gapY != nil, movedGapY == nil else { return }
movedGapY = y
y += gapShift
}
// Preserve whitespace at its original section/history boundary, not on a
// workspace that may move into an earlier family. This also maps anchors
// when the original last workspace moves or disappears into a fold.
func boundary(from start: CGFloat, to end: CGFloat) {
let containsGap = gapY.map { $0 >= start && $0 + gapShift <= end } ?? false
let removed = containsGap && gapTarget != nil ? gapShift : 0
func mapped(_ anchor: CGFloat?) -> CGFloat? {
guard let anchor, anchor >= start, anchor <= end else { return nil }
let adjustment = containsGap && gapTarget != nil && anchor >= (gapY ?? 0) + gapShift ? gapShift : 0
return y + anchor - start - adjustment
}
if let anchor = mapped(pinnedChatsY) { movedPinnedY = anchor }
if let anchor = mapped(earlierChatsY) { movedEarlierY = anchor }
if containsGap, gapTarget == nil, let gapY { movedGapY = y + gapY - start }
y += end - start - removed
}
func append(_ original: SidebarRow, spacing: CGFloat = 0) {
if original.key == gapTarget { openGap() }
var row = original
row.y = y
result.append(row)
y += row.height + spacing
}
func family(_ root: Int, depth: Int, groupDepth: Int = 0) {
guard root < starts.count, let id = ids[root], var bundle = bundles[starts[root]], !bundle.isEmpty else { return }
let (fold, rollUp) = Self.treeFold(root, ids, tree: tree, children: children, states: agentState)
bundle[0].content?.treeDepth = depth
if bundle[0].group == nil || fold != nil {
bundle[0].content?.treeFold = fold
bundle[0].content?.rollUp = rollUp
}
// Workspace bundles keep their normal row spacing. Larger gaps belong
// to the following section/block and must not travel with a moved lane.
for var row in bundle {
row.depth = max(row.depth, groupDepth)
append(row, spacing: m.rowSpacing)
}
guard !tree.collapsed.contains(id) else {
if let gapTarget, Self.treeDescendants(of: id, ids, children: children)
.contains(where: { ids[$0].map(SidebarRowKey.workspace) == gapTarget }) { openGap() }
return
}
for child in children[id] ?? [] {
family(child, depth: depth + 1, groupDepth: max(groupDepth, bundle[0].depth))
}
}
for (index, row) in rows.enumerated() {
boundary(from: index == 0 ? 0 : rows[index - 1].maxY + m.rowSpacing, to: row.y)
guard let root = byStart[index] else {
append(row, spacing: m.rowSpacing)
continue
}
guard !nested.contains(root) else { continue }
guard let host = rootHosts[root] else {
family(root, depth: row.content?.treeDepth ?? 0)
continue
}
guard emitted.insert(host).inserted else { continue }
let members = hosts[host] ?? []
let count = members.reduce(0) { total, member in
total + 1 + (ids[member].map { Self.treeDescendants(of: $0, ids, children: children).count } ?? 0)
}
let collapsed = tree.collapsedHosts.contains(host.host)
let hostKey = SidebarSessionTree.hostKey(host.host, section: host.section)
append(SidebarRow(key: .sessionHost(hostKey), y: y, height: m.groupHeaderHeight, section: row.section,
group: nil, siblingIndex: row.siblingIndex, parentIndex: nil, isLastInGroup: false,
isCollapsed: collapsed, childCount: count, groupColor: nil), spacing: m.rowSpacing)
if !collapsed { for member in members { family(member, depth: 1) } }
else if let gapTarget, members.contains(where: { member in
ids[member].map(SidebarRowKey.workspace) == gapTarget || ids[member].map { id in
Self.treeDescendants(of: id, ids, children: children)
.contains(where: { ids[$0].map(SidebarRowKey.workspace) == gapTarget })
} == true
}) { openGap() }
}
boundary(from: rows.last.map { $0.maxY + m.rowSpacing } ?? 0, to: totalHeight)
var layout = SidebarLayout(rows: result, totalHeight: y,
gapY: movedGapY, gapHeight: gapHeight, gapShift: gapShift)
layout.rowSpacing = rowSpacing
layout.pinnedChatsY = movedPinnedY
layout.earlierChatsY = movedEarlierY
// With no host header drawn, the base projection stands unless lineage moved a row:
// a loose child nested under a parent outside its own list (a user group's member),
// which the base projection drew as a root.
let regrouped = result.contains(where: { if case .sessionHost = $0.key { true } else { false } })
|| nested.contains { $0 < starts.count && (rows[starts[$0]].content?.treeDepth ?? 0) == 0 }
if !regrouped {
var base = SidebarLayout(rows: rows, totalHeight: totalHeight, gapY: gapY,
gapHeight: gapHeight, gapShift: gapShift)
base.rowSpacing = rowSpacing
base.pinnedChatsY = pinnedChatsY
base.earlierChatsY = earlierChatsY
return base
}
return layout
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private extension SidebarRowKey {
/// A row that only titles the rows below it.
var isRevealHeader: Bool {
switch self {
case .section, .group, .folder, .status: true
case .section, .group, .folder, .sessionHost, .status: true
default: false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public nonisolated struct SidebarLayout: Hashable, Sendable {

public static let empty = SidebarLayout(rows: [], totalHeight: 0, gapY: nil, gapHeight: 0, gapShift: 0)

/// True when opt-in fleet host buckets are actually drawn. Grouped mode
/// disables in-sidebar reordering so the projection cannot disagree with
/// the document landing; drags out to panes and windows remain available.
public var hostHeadersShowing: Bool {
rows.contains { if case .sessionHost = $0.key { true } else { false } }
}

public func row(for key: SidebarRowKey) -> SidebarRow? { index.position(of: key).map { rows[$0] } }

/// The position of `key`'s row in `rows`, or nil.
Expand Down Expand Up @@ -144,6 +151,9 @@ public nonisolated struct SidebarLayout: Hashable, Sendable {
var y = m.topPadding
var gapY: CGFloat?
let filtering = o.filterMatches != nil
// User-chosen folder/status views keep their own layout; dragging retains host groups.
let groupsSessions = o.sessionTree?.hosts.isEmpty == false && !filtering
&& !o.grouping.byStatus && !o.groupsByFolder
// One machine needs no machine header: its name adds nothing.
let machineCount = SidebarSection.machineCount(sections)
// One list (cx-mdo0, Lawrence 2026-10-10: "just have linear list of
Expand Down Expand Up @@ -443,6 +453,9 @@ public nonisolated struct SidebarLayout: Hashable, Sendable {
let byFolder = o.groupsByFolder && section.machine != nil && machineCount == 1 && !filtering
guard byFolder else {
let fold = SidebarDoneFoldID(section: section.id, group: nil)
// Keep ordinary lineage rows in the base projection; host
// buckets are added by groupingSessions after all sections are
// laid out, and may legitimately emit no header.
let tree = Self.treeRows(nodes.map { $0.node }, tree: o.sessionTree, filtering: filtering)
let treeRow = Dictionary(tree.map { ($0.index, $0) }, uniquingKeysWith: { first, _ in first })
let drawn = Self.foldingDone(tree.map { ($0.index, $0.depth) },
Expand Down Expand Up @@ -482,6 +495,9 @@ public nonisolated struct SidebarLayout: Hashable, Sendable {
)
layout.rowSpacing = m.rowSpacing
(layout.pinnedChatsY, layout.earlierChatsY) = (chats.pinnedY, chats.earlierY)
if groupsSessions, let tree = o.sessionTree {
return layout.groupingSessions(tree, sections: sections, gap: o.gap, metrics: m)
}
return layout
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public nonisolated enum SidebarRowKey: Hashable, Sendable {
case folder(SectionID, String)
/// Group by Status's header over one status section's rows (`SidebarLayout+Status`).
case status(SidebarStatusSection)
/// Ephemeral machine bucket in the enabled session tree; not a document or drop target.
case sessionHost(String)
/// A document item listed as a row (`SidebarNode.item`): its item id.
case item(String)
/// A document section's items in its own arrangement (tiles, a grid, a
Expand Down
Loading