Repository navigation
linux(socket): add system.tree composing window/workspace/pane/surface (Sprint A #5) - #223
Conversation
Greptile SummaryAdds Confidence Score: 4/5Safe to merge once the pane comma-guard issue (flagged in a prior review thread) is addressed; new findings are P2 only. A previously raised P1 concern — the pane loop using raw p_idx rather than a local output counter for the comma guard, which can produce invalid JSON when ordered_panels contains stale entries — remains unresolved in the current code (line 682–684 of socket.zig). All findings introduced by this review pass are P2 (missing assertions in the test). Score stays at 4 until the comma guard is fixed. cmux-linux/src/socket.zig lines 682–684 (pane comma guard) — see the existing open comment thread on this PR. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Client([CLI / Status-bar client]) -->|system.tree| Handler[handleSystemTree]
Handler --> Active["Build active{}\n workspace_id, surface_id, window_id"]
Handler --> WinLoop["for each window in window_store"]
WinLoop --> WsCount["Count workspaces in window\n(ws_in_window, sel_ws_in_window)"]
WsCount --> WsLoop["for each workspace in tm.workspaces\n(filtered by hasWorkspace)"]
WsLoop --> WsNode["Emit workspace node\n{id, ref, index, title, selected, pinned}"]
WsNode --> PaneLoop["for each panel_id in ws.ordered_panels\n(p_idx, raw index used for comma guard)"]
PaneLoop --> PanelLookup{ws.panels.get panel_id}
PanelLookup -->|missing: continue| PaneLoop
PanelLookup -->|found| PaneNode["Emit pane node\n{id, ref, index, focused, surface_count=1,\nselected_surface_id, selected_surface_ref}"]
PaneNode --> SurfNode["Emit single surface node\n{id, ref, index_in_pane=0, type, focused,\nselected=true, pane_id, pane_ref, title}"]
Active --> Response[JSON response]
SurfNode --> Response
Reviews (2): Last reviewed commit: "linux(socket): add system.tree composing..." | Re-trigger Greptile |
The macOS build ships a system.tree RPC that flattens the entire UI hierarchy
into a single response so clients (CLIs, shell prompts, status bars) can avoid
N+1 round-trips. Linux currently exposes the leaf RPCs (window.list,
workspace.list, surface.list, pane.list) but not the composed view.
Add handleSystemTree mirroring the macOS shape:
active: { workspace_id, surface_id, window_id } // matches identify
windows[]: { id, ref, index, workspace_count, selected_workspace_id,
workspaces[]: { id, ref, index, title, selected, pinned,
panes[]: { id, ref, index, focused, surface_count,
selected_surface_id, surfaces[]: {
id, ref, index, index_in_pane, type,
focused, selected, selected_in_pane,
pane_id, pane_ref, title } } } }
Linux uses 1:1 panel:pane today, so each pane has exactly one surface and
pane.id == surface.id. The shape leaves room for future pane grouping
(multiple surfaces per pane) without breaking clients.
The handler is alloc-free in the steady-state error path: every writer.* call
that fails returns the same canonical empty envelope so partial responses
never leak. Workspace and panel titles flow through writeJsonString to keep
user-supplied strings safe.
The new socket round-trip test creates an extra workspace, asserts the
envelope, restores the baseline workspace selection, and closes the
scratch workspace in a finally block so it never leaves stale state.
Sprint A item #5 from #220 (TIN-183 follow-up after #218 / #221 / #222).
1fd049a to
cadd33b
Compare
Summary
system.treeto the Linux v2 socket dispatch, mirroring the macOS response shape.window.list+workspace.list+pane.list+surface.listinto a single envelope so CLIs / status-bar clients don't need N+1 round-trips.Tree shape
```
active: { workspace_id, surface_id, window_id } // matches system.identify
windows[]: {
id, ref, index, workspace_count, selected_workspace_id,
workspaces[]: {
id, ref, index, title, selected, pinned,
panes[]: {
id, ref, index, focused, surface_count, selected_surface_id, selected_surface_ref,
surfaces[]: {
id, ref, index, index_in_pane, type, focused, selected, selected_in_pane,
pane_id, pane_ref, title
}
}
}
}
```
Optional macOS params (`workspace_id`, `all_windows`, `caller`) are not yet implemented; tree always covers every known window. Filed as a follow-up note in the docstring.
Sprint context
Test plan
Future work
Related