feat(maestro): multi-view web UI — splits, tabs, drag-dock, highlights
ci / rust (push) Successful in 5m46s

Render the content pane as tabs of nested split trees, each session leaf a live
attach mounted through the multi-mount pool:
- #30 arbitrarily-nested H/V splits with mouse-resizable dividers; per-pane
  ⏻/▥/▤/✕ tools; closing a pane collapses its parent split.
- #31 tabs, each holding its own tree; add / switch / close.
- #32 drag-to-dock: drag a pane title or a sidebar session onto a pane for a
  5-zone dock (edges split, centre swaps/replaces); a sidebar drag moves an
  already-open session.
- #33 focused pane at full strength, others dim; sidebar shows focused (loud)
  vs open-elsewhere (quiet) with a stable per-session colour mapping rows to
  panes.

Opening a session fills the focused pane (single-pane parity by default);
multi-pane is opt-in via split / drag / tabs. Panes auto-close when their
session ends (guarded against eviction and intentional close). The steady
"connected" label is hidden as noise.

Closes #30, #31, #32, #33. Part of epic #37.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 09:20:57 +00:00
co-authored by Claude Opus 4.8
parent 5a7e3c1b09
commit 159b7ecd6e
8 changed files with 1100 additions and 78 deletions
+54 -55
View File
@@ -3,15 +3,8 @@ import { ConnectionPool } from "./connections.js";
import { installHudKeybind } from "./debug.js";
import { CatalogStore } from "./events.js";
import { mountHud, type Hud } from "./hud.js";
import {
activeTab,
emptyLayout,
findLeaf,
freshId,
leaves,
type Layout,
type Node,
} from "./layout.js";
import { emptyLayout, type Layout, openSessions } from "./layout.js";
import { createMultiView, type MultiView } from "./multiview.js";
import { openSpawnModal } from "./spawn.js";
import { initTheme } from "./theme.js";
import { sessionName } from "./types.js";
@@ -67,7 +60,13 @@ const shellEl = document.createElement("div");
shellEl.className = "app-shell";
shellEl.dataset.route = "catalog";
const sidebar = renderSidebar(store);
// Forward-declared so the sidebar's drag hook can reach the controller (created
// after the welcome renderer). The hook only fires on user interaction, by which
// point `mv` is assigned.
let mv: MultiView;
const sidebar = renderSidebar(store, {
onLeafDrag: (id, e) => mv?.beginSessionDrag(id, e),
});
const content = document.createElement("section");
content.className = "content";
@@ -79,27 +78,35 @@ root.replaceChildren(renderTopbar(store), shellEl);
// It can mount several panes at once — the layout tree decides how many. For now
// the tree only ever holds a single leaf (splits/tabs arrive in epic #37); this
// routes the existing single-session view through that model.
// `mv` is forward-declared above (the sidebar drag hook needs it); the pool's
// disconnect callback below also references it.
let hud: Hud | undefined;
const pool = new ConnectionPool({
onFocusChange: (id) => {
sidebar.setActive(id);
onFocusChange: () => {
// Sidebar highlighting is driven by the multi-view controller; the pool only
// nudges the HUD here.
hud?.refresh();
},
onRequestClose: (id) => {
pool.close(id);
// Drop back to the welcome pane via the router.
if (location.hash !== "#/" && location.hash !== "") location.hash = "#/";
},
// Both the explicit disconnect (⏻) and a session ending on its own close the
// pane — drop its leaf (collapsing the split) and tear down the socket. A dead
// pane is never left lying around.
onRequestClose: (id) => closePane(id),
onClosed: (id) => closePane(id),
});
function closePane(id: string): void {
pool.close(id);
mv?.closeSession(id);
updateShellRoute();
}
// Debug HUD (#20): a fixed-corner overlay on the active session's inferred
// fields, off by default (Ctrl+Shift+D, or `?hud` in dev).
hud = mountHud(root, store, () => pool.focused());
// ---- layout state ----
// Single source of truth for what's mounted. Today it's derived from the hash
// route (one leaf per `#/attach/:id`); future issues let the user build splits
// and tabs on top of the same model.
// Single source of truth for what's mounted: tabs of split trees. The hash route
// is just a deep-link into it (`#/attach/:id` focuses/opens a session).
const layout: Layout = emptyLayout();
function infoFor(sessionId: string) {
@@ -107,32 +114,10 @@ function infoFor(sessionId: string) {
return s ? { name: sessionName(s), command: s.command, daemon: s.daemon_id } : undefined;
}
/** Show a single session in the active tab. */
function openInLayout(sessionId: string): void {
const tab = activeTab(layout);
const leaf: Node = { kind: "leaf", id: freshId("l"), sessionId };
tab.root = leaf;
tab.focusedLeafId = leaf.id;
}
/** Empty the active tab (welcome / not-found). */
function clearLayout(): void {
const tab = activeTab(layout);
tab.root = null;
tab.focusedLeafId = null;
}
/** Reconcile the pool's visible panes + focus with the active tab's tree. */
function renderLayout(): void {
const tab = activeTab(layout);
if (!tab.root) {
pool.parkActive();
return;
}
const ls = leaves(tab.root);
pool.setVisible(ls.map((l) => ({ id: l.sessionId, pane: content, info: infoFor(l.sessionId) })));
const focusLeaf = tab.focusedLeafId ? findLeaf(tab.root, tab.focusedLeafId) : ls[0];
pool.setFocus(focusLeaf?.sessionId ?? null);
/** Drive the shell's responsive layout off whether any pane is open. */
function updateShellRoute(): void {
const hasPanes = openSessions(layout).size > 0;
shellEl.dataset.route = hasPanes ? "attach" : "catalog";
}
function renderWelcome(): HTMLElement {
@@ -168,6 +153,19 @@ function renderNotFound(raw: string): HTMLElement {
return el;
}
// The multi-view controller renders tabs + splits inside the content pane and
// mounts a live attach into each session leaf.
mv = createMultiView({ pool, layout, sidebar, infoFor, onDisconnect: closePane, renderWelcome });
let contentShowsMv = false;
function showMultiView(): void {
if (!contentShowsMv) {
content.replaceChildren(mv.el);
contentShowsMv = true;
}
mv.render();
updateShellRoute();
}
type Route =
| { kind: "catalog" }
| { kind: "attach"; sessionId: string }
@@ -185,21 +183,22 @@ function dispatch(): void {
const route = parseRoute();
switch (route.kind) {
case "attach":
shellEl.dataset.route = "attach";
openInLayout(route.sessionId);
renderLayout();
// Deep-link: open/focus the session, then show the layout.
showMultiView();
mv.openSession(route.sessionId);
updateShellRoute();
return;
case "not-found":
shellEl.dataset.route = "notfound";
clearLayout();
renderLayout();
pool.setVisible([]);
pool.setFocus(null);
content.replaceChildren(renderNotFound(route.raw));
contentShowsMv = false;
return;
case "catalog":
shellEl.dataset.route = "catalog";
clearLayout();
renderLayout();
content.replaceChildren(renderWelcome());
// Show the current layout (welcome if empty) — navigating to #/ no longer
// tears panes down.
showMultiView();
return;
}
}