525 lines · 28.0 KBRaw
// Agents, the most recently changed first; a status pill on the right.
import { View, div, image, svg } from "gpui-kit";
import { v_flex, h_flex, HoverCard } from "gpui-base";
import { agents, terminals, panes, focused, spaces, run, theme, shared, setShared, setAgentOrder, window, layout, checking, settings, nextCommand, home } from "herdr";
function find(node, id) {
if (node?.id === id) return node;
for (const child of node?.children ?? []) {
const found = find(child, id);
if (found) return found;
}
return null;
}
// The sidebar's rail goes by its width, not a flag: dragging its edge narrows it too.
const narrow = () => (find(layout(), "sidebar")?.size?.px ?? Infinity) < 160;
// To the rail (on macOS wide enough for the traffic lights), or back to the width it had.
function toggleSidebar() {
const width = find(layout(), "sidebar")?.size?.px;
if (!narrow()) setShared("sidebar.width", width);
// Mods edited before the rail went by width still read the flag.
setShared("sidebar.collapsed", !narrow());
run("layout.resize", { id: "sidebar", px: narrow() ? (shared("sidebar.width") ?? 268) : window()?.platform === "macos" ? 76 : 44 });
}
// Drops what an agent puts before its title: a status glyph or spinner and the separator
// after it ("✦ Working", "⠋ - Thinking"), and Codex's blinking "[ ! ] " / "[ . ] " mark.
// Stops at an opening bracket or quote, so a title that starts with one ("[web] login") keeps it.
const clean = (s) => (s ?? "").replace(/^[^\p{L}\p{N}\p{Ps}\p{Pi}]+/u, "").replace(/^\[ [!.] \] /, "").trim();
function leadPanes(all) {
const leads = new Map();
for (const p of all) {
if (!p.terminal) continue;
const current = leads.get(p.tab);
// First agent, else first focused terminal, else first terminal in the tab.
if (!current || (!current.program?.agent && (p.program?.agent || (!current.focused && p.focused)))) leads.set(p.tab, p);
}
return leads;
}
function title(tab, l) {
const prog = l?.program?.name;
const live = clean(l?.title);
// clean() would strip a path's leading ~ or /: test the title with only its status glyph gone.
const path = /^[~/]|^[A-Za-z]:\\/.test((l?.title ?? "").replace(/^[^\p{L}\p{N}~/]+/u, ""));
const telling = live && live !== (l?.terminal ?? l?.address) && live !== prog && !path && !live.includes("@") && live.toLowerCase() !== l?.program?.key;
return (tab.name === prog || !tab.named) && telling ? live : tab.name;
}
const RANK = { blocked: 4, done: 3, working: 2, idle: 1 };
// A sub-agent without a pane isn't in agents(): its raw word, error counting as
// blocked. It's never done: it reports to its parent, and the parent's done is the news.
const kidStatus = (k, listed) => {
const s = listed.get(k.address) ?? k.status;
return s === "error" ? "blocked" : s === "done" ? "idle" : s;
};
// A status as a dot on a tile's corner: a ring when idle.
const badge = (t, st) => div().absolute().right(-4).bottom(-4).size(11).rounded_full()
.when(st === "idle" || !t[st], (el) => el.bg(t.chrome).border(1.5).border_color(t.idle ?? t.dim))
.when(st !== "idle" && Boolean(t[st]), (el) => el.bg(t[st]).border(2).border_color(t.chrome));
// A status as a pill in its color: dark text on the bright states, white on idle's grey.
const WORD = { working: "Working", blocked: "Needs you", done: "Done", idle: "Idle" };
const pill = (t, st) => div().flex_none().px(6).py(1).rounded(4).bg(st === "idle" ? (t.idle ?? t.dim) : (t[st] ?? t.dim))
.text_size(px(10.5)).font_semibold().text_color(st === "idle" || !t[st] ? "#ffffff" : t.background).child(WORD[st] ?? st);
function duration(ms) {
const m = Math.floor(ms / 60000);
if (m < 1) return "<1m";
if (m < 60) return `${m}m`;
const h = Math.floor(m / 60);
return h < 24 ? `${h}h` : `${Math.floor(h / 24)}d`;
}
// Text sizes are px at the default 13px UI font and grow or shrink with it (zoom scales them too).
const px = (n) => (n * (Number(settings()?.ui_font_size) || 13)) / 13;
// Space colors, kept by space id in shared "space.colors". A space seen without one gets
// the theme color fewest spaces use, once. The search mod does the same in the same
// order, so they agree, and adding or renaming spaces moves nothing.
const MARK = { ansi6: "#22a99a", ansi3: "#e3814f", ansi4: "#5b8def", ansi5: "#8b7cf6", ansi2: "#3fae6a", ansi1: "#d9649a" };
const PROJECT_COLORS = ["ansi6", "ansi3", "ansi4", "ansi5", "ansi2", "ansi1", "#883c00", "#792798", "#09672e", "#977e0d", "#ad215f", "#8e7699", "#c43b15", "#527d65", "#3e42b6", "#026fd7"];
function spaceColors() {
const ids = new Set(spaces().map((p) => p.id));
const kept = Object.fromEntries(Object.entries(shared("space.colors") ?? {}).filter(([id]) => ids.has(id)));
let changed = Object.keys(kept).length !== Object.keys(shared("space.colors") ?? {}).length;
for (const p of spaces()) {
if (kept[p.id] || p.name === "~") continue;
const uses = (c) => Object.values(kept).filter((v) => v === c).length;
kept[p.id] = PROJECT_COLORS.reduce((best, c) => (uses(c) < uses(best) ? c : best));
changed = true;
}
if (changed) setShared("space.colors", kept);
return kept;
}
// A space's letter tile in its space color.
function fillOf(t, id) {
const c = spaceColors()[id] ?? "";
return c.startsWith("#") ? c : (MARK[c] ?? t[c] ?? t.dim);
}
function tile(t, id, name, size) {
const fill = fillOf(t, id);
return h_flex().size(size).flex_none().rounded(size * 0.28).bg(fill).items_center().justify_center()
.text_size(size * 0.56).font_bold().text_color("#ffffff").child([...(name || "?")][0].toUpperCase());
}
// A hovered space tile's backdrop, 3px past the cell into the gap, so it shows without a bigger cell (which would
// shift the grid). Muted at 30%, lighter than the hover color, which barely shows in the thin band around a tile.
// Drawn before the tile, so under it.
const backdrop = (t) => div().absolute().top(-3).left(-3).right(-3).bottom(-3).rounded(9).bg(t.muted + "4d");
// The agent's icon from the app's program table: a one-color glyph or a picture.
function icon(p, size, color) {
if (!p?.icon) return null;
return p.tint ? svg(p.icon).size(size).flex_none().text_color(color) : image(p.icon).w(size).h(size).flex_none();
}
export default class Agents extends View {
init(_props, cx) {
this.folded = new Set();
// Each agent's last state and when it changed (ms), kept across restarts.
try { this.changed = JSON.parse(localStorage.getItem("changed") ?? "{}"); } catch { this.changed = {}; }
if (!this.changed || typeof this.changed !== "object" || Array.isArray(this.changed)) this.changed = {};
try { this.pendingPins = JSON.parse(localStorage.getItem("pins") ?? "[]"); } catch { this.pendingPins = []; }
if (!Array.isArray(this.pendingPins)) this.pendingPins = [];
if (!this.pendingPins.length) localStorage.removeItem("pins");
this.migratingPins = new Set();
cx.timer.every(30000, (cx) => cx.notify());
// ⌘B (keys.json: "agents-activity.toggleSidebar") folds the sidebar to its rail and back, like the rail's open button.
if (!checking()) cx.spawn(async () => { for (;;) if (await nextCommand() === "toggleSidebar") toggleSidebar(); });
}
// Stamps agents whose state changed (at, for the age). Done and idle count as one: looking at a
// finished agent turns done into idle, and looking isn't the agent doing anything. top, for
// the order, moves only when an agent appears, finishes or needs you; starting work doesn't.
track(list, now) {
let dirty = false;
for (const a of list) {
const s = a.status === "done" ? "idle" : a.status;
if (this.changed[a.address]?.s === s) continue;
const old = this.changed[a.address];
this.changed[a.address] = { s, at: now, top: !old || s !== "working" ? now : (old.top ?? old.at) };
dirty = true;
}
if (!dirty) return;
// Gone and old: the list alone is empty right after a start.
const listed = new Set(list.map((a) => a.address));
for (const [k, c] of Object.entries(this.changed)) if (!listed.has(k) && now - c.at > 30 * 86400000) delete this.changed[k];
localStorage.setItem("changed", JSON.stringify(this.changed));
}
// Keep offline pins until their terminal returns, and keep each pending until
// core echoes the label so a failed write doesn't erase the old pin.
migratePins(all) {
const listed = new Map(all.filter((t) => t.state === "live").map((t) => [t.address, t]));
const pending = this.pendingPins.filter((address) => {
const terminal = listed.get(address);
if (!terminal) return true;
if (terminal.labels?.["herdr.pinned"]) return false;
if (!this.migratingPins.has(address)) {
this.migratingPins.add(address);
run("terminal.pin", { terminal: address, pinned: true });
}
return true;
});
if (pending.length === this.pendingPins.length) return;
this.pendingPins = pending;
if (pending.length) localStorage.setItem("pins", JSON.stringify(pending));
else localStorage.removeItem("pins");
}
since(a) {
return this.changed[a.address]?.at ?? 0;
}
top(a) {
const c = this.changed[a.address];
return c?.top ?? c?.at ?? 0;
}
peek(addr) {
run("terminal.peek", { terminal: addr });
}
// Live sub-agents of `addr`, depth first, each with the tree lines in front of it.
tree(all, addr, lead = []) {
const kids = all.filter((k) => k.parent === addr && k.state === "live");
return kids.flatMap((k, i) => {
const last = i === kids.length - 1;
return [
{ t: k, lines: [...lead, last ? "└" : "├"] },
...this.tree(all, k.address, [...lead, last ? "" : "│"]),
];
});
}
subRow(t, s, shown, compact) {
const k = s.t;
const st = kidStatus(k, this.listed);
const pic = icon(k.program, 14, t.foreground);
const on = k.address === shown;
return h_flex()
.id(`sub-${k.address}`)
.pl(39)
.pr(8)
.rounded(8)
.h(26)
.flex_none()
.gap(0)
.items_center()
.text_size(px(12.5))
.when(on, (el) => el.bg(t.raised))
.cursor_pointer()
.hover((s) => s.bg(t.hover))
.on_click(() => (this.listed.has(k.address) ? run("pane.focus", { terminal: k.address }) : this.peek(k.address)))
.children(s.lines.map(l => div().self_start().mt(-4).w(9).h(17).mr(4).flex_none()
.when(Boolean(l), el => el.border_l(1.5).border_color(t.input))
.when(l === "└" || l === "├", el => el.border_b(1.5).rounded_bl(6))))
.when(Boolean(pic), el => el.child(div().mr(8).child(pic)))
.child(div().flex_1().truncate().text_color(on ? t.foreground : t.muted).child(k.name || k.template || k.program?.name || k.address))
.child(this.status(t, { status: st }, compact));
}
// compact: a ! for blocked where a header already says "Needs you".
status(t, a, compact = false) {
const color = t[a.status] ?? t.dim;
if (a.status === "working") return svg("mods/workspace-chrome/spinner.svg").size(12).mx(1).flex_none().text_color(t.working).spin(900);
if (a.status === "blocked" && compact) return div().size(14).flex_none().rounded(4).bg(t.blocked + "26").text_size(px(10.5)).font_bold().text_color(t.blocked).flex().items_center().justify_center().child("!");
if (a.status === "blocked") return div().flex_none().px(6).h(18).rounded(5).bg(t.blocked + "26").text_size(px(10.5)).font_semibold().text_color(t.blocked).flex().items_center().child("Needs you");
// Idle: a ring; done: a dot.
if (a.status === "idle") return div().size(7).mx(3).flex_none().rounded(4).border(1.5).border_color(t.idle ?? t.dim);
return div().size(7).mx(3).flex_none().rounded(4).bg(a.status === "done" ? color : t.dim + "00");
}
// The rail (the sidebar folded narrow): open and search up top, then every agent as its
// space's tile with a status badge, then every space; a hover card names each.
rail(t, list, all, now) {
const button = (id, icon, tip, action) => div().id(id).size(26).flex_none().flex().items_center().justify_center().rounded(6)
.cursor_pointer().text_color(t.muted).hover((s) => s.bg(t.hover).text_color(t.foreground)).tooltip(tip).on_click(action)
.child(svg(`mods/sidebar-frame/icons/${icon}.svg`).size(15));
const heading = (text) => div().pb(2).text_size(px(10.5)).text_color(t.dim).child(text);
const agentCell = (a) => {
const live = all.find((x) => x.address === a.address)?.labels?.["kit.activity"] || clean(a.title);
const when = this.since(a);
// A card to the right of its tile in its space's color, with an arrow back to it in the same color, like the spaces' cards.
const fill = fillOf(t, a.space);
return HoverCard.new(`rail-card-${a.address}`).open_delay(120).close_delay(0).anchor("left_center").trigger(
div().id(`ag-${a.address}`).w(44).h(36).flex().items_center().justify_center().rounded(8).cursor_pointer()
.when(a.focused, (el) => el.bg(t.raised)).hover((s) => s.bg(t.hover))
.accessibility_label(a.space_name || a.address)
.on_click(() => run("pane.focus", { pane: a.pane }))
.child(div().relative().child(tile(t, a.space, a.space_name, 24)).child(badge(t, a.status))),
)
.content(h_flex().items_center()
.child(svg("mods/agents-activity/caret-left.svg").w(6).h(12).flex_none().mr(-1).text_color(fill))
.child(v_flex().w(236).px(12).py(10).gap(6).rounded(8).bg(fill).text_color("#ffffff").children([h_flex().gap(8).items_center()
.child(pill(t, a.status))
.child(div().flex_1().min_w(0).truncate().text_size(px(13)).font_semibold().child(a.space_name || a.address))
.when(Boolean(when), (el) => el.child(div().text_size(px(11)).opacity(0.8).child(duration(now - when)))),
...(live ? [div().whitespace_normal().text_size(px(12)).line_height(`${px(16)}px`).opacity(0.9).child(live)] : [])])));
};
const shownSpace = spaces().find((s) => s.active)?.id;
// Spaces two to a row. A row shares one card, opened past the right column so it never covers a badge
// (the pointer on a card keeps it open); it names the badge under the pointer, in that space's color.
const spaceCell = (s) => div().id(`space-${s.id}`).relative().p(2).rounded(7).cursor_pointer().when(s.id === shownSpace, (el) => el.bg(t.raised))
.accessibility_label(s.name).on_hover((on, cx) => { if (on) this.railSpace = s.id; this.hover(s.id, on); cx.notify(); })
.on_click(() => run("space.select", { id: s.id })).children([...(this.hot === s.id ? [backdrop(t)] : []), tile(t, s.id, s.name, 22)]);
const spaceRow = (row) => {
const s = row.find((x) => x.id === this.railSpace) ?? row[0], fill = fillOf(t, s.id);
return HoverCard.new(`rail-row-${row[0].id}`).open_delay(120).close_delay(0).anchor("left_center")
.trigger(h_flex().w(56).gap(4).children(row.map(spaceCell)))
.content(h_flex().items_center()
.child(svg("mods/agents-activity/caret-left.svg").w(6).h(12).flex_none().mr(-1).text_color(fill))
.child(div().px(10).py(5).rounded(8).bg(fill).text_size(px(13)).font_semibold().text_color("#ffffff").child(s.name)));
};
const used = shared("space.used") ?? {};
const order = [...spaces()].sort((x, y) => (used[y.id] ?? 0) - (used[x.id] ?? 0));
// The last used 8 (four rows), and a toggle for the rest, so the spaces never crowd out the agents or need a scroll bar.
const hidden = Math.max(0, order.length - 8), shown = this.railAll ? order : order.slice(0, 8);
const more = div().id("rail-more").w(56).h(24).flex().items_center().justify_center().rounded(6).cursor_pointer()
.text_size(px(11)).text_color(t.muted).hover((s) => s.bg(t.hover).text_color(t.foreground))
.tooltip(this.railAll ? "Show fewer spaces" : "Show all spaces")
.on_click((_e, cx) => { this.railAll = !this.railAll; cx.notify(); })
.child(this.railAll ? svg("mods/agents-activity/chevron-up.svg").size(14) : `+${hidden}`);
return v_flex().size_full().min_h(0).bg(t.chrome).text_size(px(13))
.child(h_flex().h(34).flex_none().items_center().justify_center().gap(4)
.child(button("rail-open", "sidebar", "Open the sidebar", toggleSidebar))
.child(button("rail-search", "search", "Search", () => run("mod.open", { name: "search" }))))
.child(v_flex().id("ag-rail").flex_1().min_h(0).overflow_y_scrollbar()
.child(v_flex().border_t(1).border_color(t.border).pt(10).pb(8).gap(4).items_center()
.child(heading("Agents")).children(list.map(agentCell))))
// Spaces sit at the bottom, just above Settings, as in the open sidebar; the agents scroll above them.
.child(v_flex().flex_none().border_t(1).border_color(t.border).py(10).gap(6).items_center()
.child(heading("Spaces"))
// Two to a row: 26px cells (a 22px tile and its 2px ring) with a 4px gap fill 56 of the rail's 76px.
.child(v_flex().gap(4).children(shown.flatMap((x, i) => i % 2 ? [] : [spaceRow(shown.slice(i, i + 2))])))
.when(hidden > 0, (el) => el.child(more)));
}
// The space tile under the pointer (this.hot); leaving one clears it unless another was entered first.
hover(id, on) {
if (on) this.hot = id;
else if (this.hot === id) this.hot = null;
}
render(cx) {
const t = theme();
const collapsed = narrow();
let list = agents();
this.listed = new Map(list.map((a) => [a.address, a.status]));
const all = terminals();
this.migratePins(all);
const shown = focused()?.agent;
const now = Date.now();
this.track(list, now);
// When each space was last shown, for search's last-used order.
const here = spaces().find((s) => s.active)?.id;
if (here && here !== this.here && !checking()) {
this.here = here;
setShared("space.used", { ...(shared("space.used") ?? {}), [here]: now });
}
// A kept sub-agent (one with a pane) is in agents() too: where a tree shows
// it, it gets no row of its own, unless it's pinned.
const nested = new Set(list.flatMap((a) => this.tree(all, a.address).map((s) => s.t.address)));
list = list.filter((a) => a.pinned || !nested.has(a.address));
const tabCounts = new Map();
for (const a of list) tabCounts.set(a.tab, (tabCounts.get(a.tab) ?? 0) + 1);
// Pinned first, then the newest agent or the last to finish or need you (see track), so a row
// stays put when it starts working or when you click it.
list = [...list].sort((x, y) => y.pinned - x.pinned || this.top(y) - this.top(x) || y.seq - x.seq);
setAgentOrder(list.map((a) => a.address));
if (collapsed) return this.rail(t, list, all, now);
const withKids = (a, i) => {
const subs = this.tree(all, a.address);
const r = row(a, i, subs);
if (this.folded.has(a.address)) return [r];
return [r, ...subs.map((s) => this.subRow(t, s, shown, true))];
};
// The fold chevron; folded, the count too, colored by the most urgent one.
const fold = (a, subs) => {
const sts = subs.map((s) => kidStatus(s.t, this.listed));
const top = sts.reduce((m, s) => ((RANK[s] ?? 0) > (RANK[m] ?? 0) ? s : m), null);
const open = !this.folded.has(a.address);
return div()
.id(`fold-${a.address}`)
.h(18)
.px(3)
.gap(3)
.flex()
.items_center()
.rounded(4)
.text_size(px(11))
.text_color(open ? t.dim : (t[top] ?? t.dim))
.cursor_pointer()
.hover((s) => s.bg(t.hover).text_color(t.foreground))
.on_click((_e, cx) => {
cx.stop_propagation();
open ? this.folded.add(a.address) : this.folded.delete(a.address);
cx.notify();
})
.child(svg(`mods/workspace-chrome/chevron-${open ? "down" : "right"}.svg`).size(11).flex_none())
.when(!open, (el) => el.child(String(subs.length)));
};
// A row reads "space \u00b7 detail": the detail is a tab someone named or the
// agent's own title, never an automatic tab number.
// Read the pane snapshot once: every host read copies the whole list into JS.
const leads = leadPanes(panes());
const tabs = new Map(spaces().flatMap(s => s.tabs).map(tab => [tab.id, tab]));
const labels = new Map(list.map(a => {
const tab = tabs.get(a.tab);
const many = tabCounts.get(a.tab) > 1;
return [a.address, tab ? title(many ? { ...tab, named: false } : tab, many ? a : leads.get(a.tab)) : (a.title || a.program?.name || "")];
}));
const label = (a) => labels.get(a.address);
const detail = new Map(list.map(a => [a.address, /^\d+$/.test(label(a)) ? null : label(a)]));
const perSpace = new Map();
for (const a of list) perSpace.set(a.space, (perSpace.get(a.space) ?? 0) + 1);
const row = (a, i, subs = []) => {
// Both views: the space's tile, so the list doubles as the spaces list.
const pic = div().relative().child(tile(t, a.space, a.space_name, 20)).child(badge(t, a.status));
const more = detail.get(a.address);
// An agent on another machine (`vps/t7`) says which.
const machine = a.address.includes("/") ? a.address.split("/")[0] : null;
const when = this.since(a);
const idle = a.status === "idle" && !a.focused;
const isPinned = a.pinned;
const pin = div()
.id(`pin-${a.address}`)
.flex_none()
.p(2)
.rounded(4)
.text_color(t.dim)
.cursor_pointer()
.hover((s) => s.bg(t.hover).text_color(t.foreground))
.tooltip(isPinned ? "Unpin" : "Pin to the top")
.on_click((_e, cx) => {
cx.stop_propagation();
run("terminal.pin", { terminal: a.address, pinned: !isPinned });
// The row moves away from under the pointer, and no hover-out comes.
this.hovered = null;
cx.notify();
})
.child(svg(`mods/workspace-chrome/${isPinned ? "pin-off" : "pin"}.svg`).size(13));
const full = true; // Both views: every row names its space.
const name = full ? a.space_name || label(a) : more ?? (/^\d+$/.test(label(a)) ? a.program?.name || label(a) : label(a));
// What it's working on: the herdr-activity hook's label, else the agent's own title,
// when that says more than the name.
const live = all.find((x) => x.address === a.address)?.labels?.["kit.activity"] || clean(a.title);
const task = live && live !== name && live !== a.program?.name ? live : null;
return h_flex()
.id(`ag-${a.address}`)
.px(8)
.min_h(30)
.when(Boolean(task), (el) => el.py(5))
.flex_none()
.rounded(8)
.items_center()
.gap(9)
.when(a.focused, (el) => el.bg(t.selected))
.cursor_pointer()
.hover((s) => s.bg(t.hover))
.on_hover((on, cx) => {
if (on) this.hovered = a.address;
else if (this.hovered === a.address) this.hovered = null;
cx.notify();
})
.on_click(() => run("pane.focus", { pane: a.pane }))
.when(Boolean(pic), el => el.child(div().id(`agent-fold-${a.address}`)
.when(subs.length > 0, el => el.on_click((_e, cx) => {
cx.stop_propagation();
this.folded.has(a.address) ? this.folded.delete(a.address) : this.folded.add(a.address);
cx.notify();
})).child(pic)))
.child(v_flex().flex_1().min_w(0)
.child(h_flex().min_w(0).gap(5).items_center()
.child(div().min_w(0).max_w(full && more ? 120 : 200).truncate().text_size(px(14.5)).font_bold().text_color(idle ? t.muted : t.foreground).child(name))
.when(full && Boolean(more) && (!task || perSpace.get(a.space) > 1), el => el.child(div().flex_1().min_w(0).truncate().text_color(t.dim).child(`\u00b7 ${more}`))))
.when(Boolean(task), el => el.child(div().min_w(0).whitespace_normal().text_size(px(12)).line_height(`${px(16)}px`).max_h(px(48)).overflow_hidden().text_color(idle ? t.muted : t.foreground).child(task))))
.when(Boolean(machine), el => el.child(div().text_size(px(10)).text_color(t.dim).child(machine)))
.when(subs.length > 0, el => el.child(fold(a, subs)))
.when(this.hovered === a.address, el => el.child(pin))
.when(this.hovered !== a.address && Boolean(when), el => el.child(div().flex_none().text_size(px(11)).text_color(t.dim).child(duration(now - when))));
};
const rows = list.flatMap(withKids);
// Every space as a tile below the agents (just above Settings), last used first, like search (shared "space.used").
const used = shared("space.used") ?? {};
const order = [...spaces()].sort((x, y) => (used[y.id] ?? 0) - (used[x.id] ?? 0));
const shownSpace = spaces().find((s) => s.active)?.id;
const spaceBlock = v_flex().flex_none().border_t(1).border_color(t.border).pb(14)
.child(h_flex().px(16).h(41).pt(14).pb(5).items_center().justify_between()
.child(div().text_size(px(11.5)).font_medium().text_color(t.dim).child(`Spaces (${order.length})`))
.child(div()
.id("ag-new-space")
.size(26).mr(-6).flex().items_center().justify_center().rounded(6).cursor_pointer()
.text_color(t.muted)
.hover((s) => s.bg(t.hover).text_color(t.foreground))
.tooltip("New space")
.on_click(() => run("space.new", spaces().find((s) => s.id === focused()?.space)?.machine ? {} : { folder: `${home()}/Developer/projects` }))
.child(svg("mods/workspace-chrome/plus.svg").size(14))))
// The grid is laid out by column, each column one card's trigger, so the card opens above the column's top
// badge and never covers one (the pointer on a card keeps it open). It names the badge under the pointer
// (on_hover), in that space's color. Cells are 26px (a 22px tile and its 2px ring) with a 6px gap.
.child((() => {
// The measured width is in zoomed pixels, the cells in unzoomed ones.
const n = Math.max(1, Math.floor(((this.gridW ?? 268) / (Number(settings()?.zoom) || 1) - 28 + 6) / 32));
const cell = (s) => div()
.id(`space-${s.id}`)
.relative()
.p(2)
.rounded(7)
.when(s.id === shownSpace, (el) => el.bg(t.selected))
.cursor_pointer()
.accessibility_label(s.name)
.on_hover((on, cx) => { if (on) this.gridSpace = s.id; this.hover(s.id, on); cx.notify(); })
.on_click(() => run("space.select", { id: s.id }))
.children([...(this.hot === s.id ? [backdrop(t)] : []), tile(t, s.id, s.name, 22)]);
const column = (c) => {
const col = order.filter((_, i) => i % n === c), s = col.find((x) => x.id === this.gridSpace) ?? col[0], fill = fillOf(t, s.id);
return HoverCard.new(`space-col-${c}`).open_delay(120).close_delay(0).anchor("bottom_left")
.trigger(v_flex().gap(6).children(col.map(cell)))
.content(div().relative().pb(6)
.child(div().px(10).py(5).rounded(8).bg(fill)
.child(div().text_size(px(13)).font_semibold().text_color("#ffffff").child(s.name)))
// The arrow down to the column, in the card's color: the cell's centre is 13px in, so the 12px arrow starts at 7.
.child(svg("mods/agents-activity/caret-down.svg").absolute().bottom(1).left(7).w(12).h(6).text_color(fill)));
};
return h_flex().id("space-grid").w_full().px(14).gap(6).items_start()
.on_size_change((size, cx) => { if (size.width !== this.gridW) { this.gridW = size.width; cx.notify(); } })
.children(Array.from({ length: Math.min(n, order.length) }, (_, c) => column(c)));
})());
return v_flex()
.size_full()
.min_h(0)
.bg(t.chrome)
.border_t(1)
.border_color(t.border)
.text_size(px(13))
.child(
h_flex()
.px(16)
.h(41)
.pt(14)
.pb(5)
.flex_none()
.items_center()
.justify_between()
.child(div().text_size(px(11.5)).font_medium().text_color(t.dim).child(`Agents (${list.length})`)),
)
.when(list.length === 0, (el) =>
el.child(div().px(12).text_size(px(12)).text_color(t.dim).child("No agent status yet. Agents show up here when they report their status. Older versions and agents inside tmux may not.")),
)
.child(v_flex().id("ag-list").flex_1().min_h(0).px(8).overflow_y_scrollbar().mode("always").children(rows))
.child(spaceBlock);
}
}