Python
Make the team panel compact and searchable at large team sizes
Rohit C Prasadc0feec56dd4a
diff --git a/surfaces/gui/e2e/team-roster.spec.ts b/surfaces/gui/e2e/team-roster.spec.tsnew file mode 100644index 00000000..b62af2ce--- /dev/null+++ b/surfaces/gui/e2e/team-roster.spec.ts@@ -0,0 +1,82 @@+import { expect, test } from "@playwright/test";++for (const size of [12, 100])+ for (const theme of ["light", "dark"]) {+ test(`${size} workers: compact groups, search handoff and paging (${theme})`, async ({+ page,+ }) => {+ await page.addInitScript((theme) => {+ localStorage.setItem("coworker:rail-hidden:v1", "0");+ localStorage.setItem("openwork-theme", theme);+ }, theme);+ await page.setViewportSize({ width: 1440, height: 1000 });+ await page.goto(`/?scenario=team-view-${size}#/s/scn-team-view-${size}`);+ const rail = page.getByTestId("team-rail");+ // Both actions are available before expanding the roster.+ await expect(rail.getByTestId("rail-open-team-view")).toBeVisible();+ await expect(rail.getByTestId("team-chat-action")).toBeVisible();+ await rail.getByTestId("rail-toggle-team").click();+ await expect(rail.locator(".team-roster-group")).toHaveCount(4);+ expect(await rail.getByTestId(/^team-row-/).count()).toBeLessThan(20);+ await page.screenshot({+ path: `test-results/team-roster-${size}-${theme}.png`,+ });+ const search = rail.getByRole("searchbox");+ await search.fill("not-a-worker");+ await expect(rail.getByRole("status")).toHaveText("0 matching workers");+ await expect(rail.getByTestId(/^team-row-/)).toHaveCount(0);+ await search.fill("machine");+ await expect(rail.getByTestId(/^team-row-/)).toHaveCount(6);+ await rail+ .getByRole("button", { name: new RegExp(`View all ${size} matches`) })+ .click();+ const pane = page.getByTestId("team-view");+ await expect(pane.getByRole("tab", { name: "Workers" })).toHaveAttribute(+ "aria-selected",+ "true",+ );+ await expect(pane.getByRole("searchbox")).toHaveValue("machine");+ await expect(pane.getByTestId(/^team-worker-/)).toHaveCount(8);+ await pane.getByRole("button", { name: "Next workers" }).click();+ await expect(+ pane.getByText(`9–${Math.min(size, 16)} of ${size}`, { exact: true }),+ ).toBeVisible();+ await pane+ .getByTestId(/^team-worker-/)+ .first()+ .click();+ await expect(pane.getByTestId("team-worker-transcript")).toBeVisible();+ await pane.getByRole("button", { name: "← Team" }).click();+ await expect(pane.getByRole("searchbox")).toHaveValue("machine");+ await expect(+ pane.getByText(`9–${Math.min(size, 16)} of ${size}`, { exact: true }),+ ).toBeVisible();+ await pane.getByRole("button", { name: "Close team view" }).click();+ const group = rail+ .locator(".team-roster-group")+ .filter({ hasText: "swe-worker" });+ await group.locator("summary").click();+ const groupCount = size === 100 ? 40 : 5;+ await group+ .getByRole("button", { name: `View all ${groupCount} workers` })+ .click();+ await expect(pane.getByText("swe-worker", { exact: true })).toBeVisible();+ await expect(pane.getByRole("status")).toHaveText(+ `${groupCount} matching workers`,+ );+ await pane.getByRole("button", { name: "Clear filter" }).click();+ await expect(pane.getByRole("status")).toHaveText(+ `${size} matching workers`,+ );+ await expect.poll(() => page.locator(".sidebar").evaluate(el => el.getBoundingClientRect().right)).toBeLessThanOrEqual(1);+ await page.screenshot({+ path: `test-results/team-directory-${size}-${theme}.png`,+ });+ for (const width of [1000, 760]) {+ await page.setViewportSize({width, height:1000});+ await expect(pane.getByRole("searchbox")).toBeVisible();+ expect(await pane.evaluate(el => el.scrollWidth <= el.clientWidth + 1)).toBe(true);+ }+ await page.screenshot({path: `test-results/team-directory-${size}-${theme}-narrow.png`});+ });+ }diff --git a/surfaces/gui/e2e/team-view.spec.ts b/surfaces/gui/e2e/team-view.spec.tsindex 54e7b42b..60e1484c 100644--- a/surfaces/gui/e2e/team-view.spec.ts+++ b/surfaces/gui/e2e/team-view.spec.ts@@ -11,7 +11,10 @@ for (const theme of ["light", "dark"]) {const toggle = page.getByTestId("rail-toggle-team");await expect(toggle).toBeVisible();await toggle.click();+ await expect(page.getByTestId("team-chat-off")).toHaveCount(0);+ await page.getByTestId("team-chat-action").click();await expect(page.getByTestId("team-chat-off")).toBeVisible();+ await page.getByRole("button", { name: "Dismiss", exact: true }).click();await page.getByTestId("rail-open-team-view").click();const pane = page.getByTestId("team-view");await expect(pane.getByRole("tab")).toHaveCount(3);@@ -145,10 +148,8 @@ test("large team groups workers and shows top five token consumers", async ({await quick.getByRole("button", { name: "Open team view" }).click();const pane = page.getByTestId("team-view");await pane.getByRole("tab", { name: "Workers" }).click();- await expect(pane.getByRole("button", { name: "Show workers" })).toHaveCount(- 4,- );- await pane.getByRole("button", { name: "Show workers" }).first().click();+ await expect(pane.getByTestId(/^team-worker-/).filter({ hasNot: page.locator("textarea") })).toHaveCount(8);+ await expect(pane.getByRole("searchbox")).toBeVisible();await expect(pane.getByTestId("team-worker-sam")).toBeVisible();await pane.getByRole("tab", { name: "Stats" }).click();await expect(pane.getByText("Top five of 100 workers")).toBeVisible();diff --git a/surfaces/gui/e2e/team.spec.ts b/surfaces/gui/e2e/team.spec.tsindex 4ad42f77..e323a7c8 100644--- a/surfaces/gui/e2e/team.spec.ts+++ b/surfaces/gui/e2e/team.spec.ts@@ -122,7 +122,7 @@ test("enabling chat at the gate adds the # team chat row; posting works with men// The chat row lives in the drawer's Team panel now (sessions poll: allow a cycle).await expect(page.getByTestId("rail-toggle-team")).toBeVisible({ timeout: 12_000 });await page.getByTestId("rail-toggle-team").click();- const chatRow = page.getByTestId("team-chat-row");+ const chatRow = page.getByTestId("team-chat-action");await expect(chatRow).toBeVisible();await expect(chatRow).toContainText("1"); // unread badge@@ -199,9 +199,9 @@ test("approval creates the team; members live in the drawer, RECENT keeps one enawait teamToggle.click();const panel = page.getByTestId("team-panel");await expect(panel).toBeVisible();- await expect(panel.getByTestId("team-row-nia")).toContainText("#1 in progress");- await expect(panel.getByTestId("team-row-webb")).toContainText("idle");- await expect(panel.getByTestId("team-row-checks")).toContainText("#4 blocked");+ await expect(panel.getByTestId("team-row-nia")).toContainText("nia");+ await expect(panel.getByTestId("team-row-webb")).toContainText("Idle");+ await expect(panel.getByTestId("team-row-checks")).toContainText("Needs attention");// Worker inspection keeps the lead alongside; full navigation is explicit.await panel.getByTestId("team-row-nia").click();diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsxindex 4a4d118c..7a74cc18 100644--- a/surfaces/gui/src/App.tsx+++ b/surfaces/gui/src/App.tsx@@ -108,6 +108,7 @@ import { ConnectorRequestCard } from "./components/ConnectorRequestCard";import { DirectoryRequestCard } from "./components/DirectoryRequestCard";import { PlanCard } from "./components/PlanCard";import { TeamView, TeamQuickLook } from "./components/TeamView";+import type { WorkerFilter } from "./teamRoster";import type { TeamSummary } from "./teamView";import { getTeamSummary } from "./api";import { TaskBoardContext, OPEN_TASK_EVENT } from "./components/TaskChip";@@ -395,6 +396,7 @@ export function App() {const [boardOwner, setBoardOwner] = useState("");const [teamViewOpen, setTeamViewOpen] = useState(false);const [teamWorkerId, setTeamWorkerId] = useState<string | null>(null);+ const [teamWorkerFilter, setTeamWorkerFilter] = useState<WorkerFilter | null>(null);const [teamSummary, setTeamSummary] = useState<TeamSummary | null>(null);// A rail row click deep-opens the overlay on that item's detail pane.const [boardDetailId, setBoardDetailId] = useState<number | null>(null);@@ -488,7 +490,7 @@ export function App() {const show = () => {setRailHidden(false);setBoardRailKey((k) => k + 1);- setBoardDetailId(null); setTeamWorkerId(null); setTeamViewOpen(true);+ setBoardDetailId(null); setTeamWorkerId(null); setTeamWorkerFilter(null); setTeamViewOpen(true);};window.addEventListener("ocw-open-board", show);return () => window.removeEventListener("ocw-open-board", show);@@ -1247,7 +1249,7 @@ export function App() {const open = (e: Event) => {const d = (e as CustomEvent).detail;if (d?.sessionId !== sessionId || d.space !== board?.space || !board?.items.some(i => i.id === d.id)) return;- setBoardDetailId(d.id); setTeamWorkerId(null); setBoardRailKey(k => k + 1); setTeamViewOpen(true); setRailHidden(false);+ setBoardDetailId(d.id); setTeamWorkerId(null); setTeamWorkerFilter(null); setBoardRailKey(k => k + 1); setTeamViewOpen(true); setRailHidden(false);};window.addEventListener(OPEN_TASK_EVENT, open);return () => window.removeEventListener(OPEN_TASK_EVENT, open);@@ -1267,7 +1269,7 @@ export function App() {(s) => s.team?.role === "worker" && s.team.lead_session === sessionId,);- useEffect(() => { setTeamViewOpen(false); setBoardDetailId(null); setTeamWorkerId(null); setTeamSummary(null); }, [sessionId]);+ useEffect(() => { setTeamViewOpen(false); setBoardDetailId(null); setTeamWorkerId(null); setTeamWorkerFilter(null); setTeamSummary(null); }, [sessionId]);const activeTeamId = curSession?.team?.team_id;useEffect(() => {if (!activeTeamId || surface !== "session") { setTeamSummary(null); return; }@@ -1277,7 +1279,7 @@ export function App() {}).catch(() => { if (!canceled) setTeamSummary(null); });return () => { canceled = true; };}, [sessionId, activeTeamId, surface, sessions, browserRefreshKey, running]);- const openTeamView = (id?: number) => { setBoardDetailId(id ?? null); setTeamWorkerId(null); setBoardRailKey(k => k + 1); setTeamViewOpen(true); setRailHidden(false); };+ const openTeamView = (id?: number) => { setBoardDetailId(id ?? null); setTeamWorkerId(null); setTeamWorkerFilter(null); setBoardRailKey(k => k + 1); setTeamViewOpen(true); setRailHidden(false); };// Keep the active session's pending Inbox items fresh (answer-in-context card). Loads on session// change + after each turn, plus a slow poll so an unattended agent's new question surfaces.@@ -2474,7 +2476,7 @@ export function App() {/></div><RightRail- teamView={teamViewOpen ? <TeamView openKey={boardRailKey} board={boardOwner === sessionId ? board : null} summary={teamSummary?.lead_session === sessionId ? teamSummary : null} initialItem={boardDetailId} initialWorkerId={teamWorkerId} onOpenFullSession={(id) => { const w = sessions.find(s => s.session_id === id); if (w) void selectSession(w.session_id, w.workspace, w.agent); }} sessionId={sessionId} sessions={sessions} machine={machine} machineName={curSession?.machine_name} onClose={() => { setTeamViewOpen(false); setBoardDetailId(null); setTeamWorkerId(null); }} onRefresh={() => { void refreshBoard(); setBrowserRefreshKey(k => k + 1); }} /> : undefined}+ teamView={teamViewOpen ? <TeamView openKey={boardRailKey} board={boardOwner === sessionId ? board : null} summary={teamSummary?.lead_session === sessionId ? teamSummary : null} initialItem={boardDetailId} initialWorkerId={teamWorkerId} initialWorkerFilter={teamWorkerFilter} onOpenFullSession={(id) => { const w = sessions.find(s => s.session_id === id); if (w) void selectSession(w.session_id, w.workspace, w.agent); }} sessionId={sessionId} sessions={sessions} machine={machine} machineName={curSession?.machine_name} onClose={() => { setTeamViewOpen(false); setBoardDetailId(null); setTeamWorkerId(null); setTeamWorkerFilter(null); }} onRefresh={() => { void refreshBoard(); setBrowserRefreshKey(k => k + 1); }} /> : undefined}active={surface === "session" && agent !== "chat" && !railHidden}sessionId={sessionId}refreshKey={browserRefreshKey}@@ -2504,11 +2506,14 @@ export function App() {(curSession?.team?.role != null && curSession.team.role !== "worker")}teamMembers={teamMembers}+ teamSummary={teamSummary?.lead_session === sessionId ? teamSummary : null}+ teamMachine={curSession?.machine_name}+ onOpenWorkers={(filter) => { setBoardDetailId(null); setTeamWorkerId(null); setTeamWorkerFilter(filter); setBoardRailKey(k => k + 1); setTeamViewOpen(true); setRailHidden(false); }}teamChatEnabled={!!curSession?.team?.chat_enabled}teamChatUnread={curSession?.team?.chat_unread || 0}teamUsage={teamMembers.length ? teamUsage(usage, teamMembers) : undefined}onOpenTeamChat={() => setChatTeam(curSession?.team?.team_id || "")}- onOpenWorker={(w) => { setBoardDetailId(null); setTeamWorkerId(w.session_id); setBoardRailKey(k => k + 1); setTeamViewOpen(true); setRailHidden(false); }}+ onOpenWorker={(w) => { setBoardDetailId(null); setTeamWorkerId(w.session_id); setTeamWorkerFilter(null); setBoardRailKey(k => k + 1); setTeamViewOpen(true); setRailHidden(false); }}openBoardKey={boardRailKey}/>diff --git a/surfaces/gui/src/components/Icon.tsx b/surfaces/gui/src/components/Icon.tsxindex bdfdbf53..231f6a84 100644--- a/surfaces/gui/src/components/Icon.tsx+++ b/surfaces/gui/src/components/Icon.tsx@@ -8,6 +8,7 @@ export type IconName =| "sidebarRight"| "signOut"| "chat"+ | "workList"| "diamond"| "book"| "search"@@ -275,6 +276,8 @@ export function Icon({<path d="M5 5.5h14c.8 0 1.5.7 1.5 1.5v7c0 .8-.7 1.5-1.5 1.5H9.5L5.5 19v-3H5c-.8 0-1.5-.7-1.5-1.5V7c0-.8.7-1.5 1.5-1.5z" /></svg>);+ case "workList":+ return <svg {...s}><rect x="3" y="4" width="4" height="4" rx="1" /><rect x="3" y="10" width="4" height="4" rx="1" /><rect x="3" y="16" width="4" height="4" rx="1" /><path d="M11 6h10M11 12h10M11 18h10" /></svg>;case "wrench":return (<svg {...s}>diff --git a/surfaces/gui/src/components/RightRail.tsx b/surfaces/gui/src/components/RightRail.tsxindex ed04ca89..dd2f5975 100644--- a/surfaces/gui/src/components/RightRail.tsx+++ b/surfaces/gui/src/components/RightRail.tsx@@ -17,12 +17,12 @@ import {import type { SessionInfo, TodoItem } from "../types";import { AccessSection } from "./AccessSection";import { BoardSection } from "./BoardPanel";+import { TeamRail } from "./TeamRail";+import type { TeamSummary } from "../teamView";+import type { WorkerFilter } from "../teamRoster";import { Icon } from "./Icon";-import { formatTokens, totalTokens } from "../usage";-import type { SessionUsage, TurnUsage } from "../types";--const totalOf = (u: TurnUsage) => u.input + u.output + u.cache_read + u.cache_write;+import type { SessionUsage } from "../types";import { Markdown, OPEN_ARTIFACT_EVENT } from "./Markdown";type Panel = "progress" | "artifacts" | "board" | "journal" | "team" | "files";@@ -86,6 +86,9 @@ interface Props {onOpenTeamChat?: () => void;onOpenWorker?: (s: SessionInfo) => void;onOpenTeamView?: () => void;+ onOpenWorkers?: (filter: WorkerFilter) => void;+ teamSummary?: TeamSummary | null;+ teamMachine?: string;// Bumped when a [.](board:) chip in the transcript is clicked — expands the Board section.openBoardKey?: number;}@@ -118,6 +121,9 @@ export function RightRail({onOpenTeamChat,onOpenWorker,onOpenTeamView,+ onOpenWorkers,+ teamSummary,+ teamMachine,openBoardKey = 0,}: Props) {const { t } = useTranslation();@@ -293,60 +299,10 @@ export function RightRail({{/* The team panel: who's working, on what, and the way into their sessions —the altitude-3 escape hatch, moved here from the sidebar (RECENT keeps ONEentry per team: the lead). */}- {teamMembers.length > 0 && (- <RailSection- title={t("rail.team_title")}- open={open.team}- onToggle={() => setOpen({ ...open, team: !open.team })}- count={String(teamMembers.length)}- >- <div className="rail-team" data-testid="team-panel">- {onOpenTeamView && <button className="rail-team-row" data-testid="rail-open-team-view" onClick={onOpenTeamView}>- <Icon name="panelOpen" size={13} /> {t("teamview.open_view")}- </button>}- {teamMembers.map((w) => (- <button- className="rail-team-row"- key={w.session_id}- data-testid={`team-row-${w.team?.actor || w.session_id}`}- onClick={() => onOpenWorker?.(w)}- title={t("teamview.open_worker_pane", { name: w.team?.actor || t("rail.team_worker") })}- >- <span className={"team-dot " + (w.team?.status || "idle")} />- <span className="rail-team-name">{w.team?.actor || w.agent}</span>- <span className="rail-team-item">{w.team?.current_item || t("rail.team_sleeping")}</span>- <span className="rail-team-open">{t("rail.team_open")}</span>- </button>- ))}- {teamChatEnabled && onOpenTeamChat && (- <button className="rail-team-row rail-chat-row" data-testid="team-chat-row" onClick={onOpenTeamChat}>- <span className="team-hash">#</span>- <span className="rail-team-name">{t("rail.team_chat")}</span>- {teamChatUnread > 0 && <span className="team-chat-badge">{teamChatUnread}</span>}- </button>- )}- {!teamChatEnabled && <p className="team-totals" data-testid="team-chat-off">{t("teamview.chat_off")}</p>}- {teamUsage && totalTokens(teamUsage) > 0 && (- /* Tokens for the whole tree (lead + workers), by model. Counts only —- no dollars (owner ruling, spec §5). */- <div className="rail-team-usage" data-testid="team-usage">- <div className="rail-team-usage-head">- <span>{t("misc.rail.tokens")}</span>- <span className="text-muted">{formatTokens(totalTokens(teamUsage))}</span>- </div>- {Object.entries(teamUsage.byModel)- .sort((a, b) => totalOf(b[1]) - totalOf(a[1]))- .map(([model, u]) => (- <div className="rail-team-usage-row" key={model} title={t("misc.rail.usage_title", { model, input: u.input, output: u.output, cached: u.cache_read })}>- <span className="rail-team-usage-model">{model.includes(":") ? model.split(":").slice(1).join(":") : model}</span>- <span className="text-muted">{formatTokens(totalOf(u))}</span>- </div>- ))}- </div>- )}- </div>- </RailSection>- )}+ {teamMembers.length > 0 && <TeamRail key={sessionId} members={teamMembers} summary={teamSummary}+ open={open.team} onToggle={() => setOpen({ ...open, team: !open.team })}+ usage={teamUsage} machine={teamMachine} chatEnabled={teamChatEnabled} unread={teamChatUnread}+ onChat={onOpenTeamChat} onWorker={onOpenWorker} onTeam={onOpenTeamView} onWorkers={onOpenWorkers} />}{showArtifacts && (<RailSectiondiff --git a/surfaces/gui/src/components/TeamRail.test.tsx b/surfaces/gui/src/components/TeamRail.test.tsxnew file mode 100644index 00000000..fab7c839--- /dev/null+++ b/surfaces/gui/src/components/TeamRail.test.tsx@@ -0,0 +1,62 @@+import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { afterEach, expect, it, vi } from "vitest";+import { TeamRail } from "./TeamRail";+import { sampleTeam } from "../gallery/states/team-view";+import type { SessionInfo } from "../types";+afterEach(cleanup);+const summary = sampleTeam(100);+const members = summary.workers.map(+ (w) =>+ ({+ session_id: w.session_id,+ agent: w.role,+ team: { actor: w.actor },+ machine_name: "build-box",+ }) as SessionInfo,+);+it("keeps actions available when collapsed and chat off explained only on request", () => {+ const onChat = vi.fn(),+ onTeam = vi.fn();+ render(+ <TeamRail+ members={members.slice(0, 2)}+ chatEnabled={false}+ onChat={onChat}+ onTeam={onTeam}+ open={false}+ onToggle={vi.fn()}+ />,+ );+ expect(screen.queryByTestId("team-panel")).toBeNull();+ expect(screen.queryByTestId("team-chat-off")).toBeNull();+ fireEvent.click(screen.getByTestId("team-chat-action"));+ expect(screen.getByTestId("team-chat-off")).toBeTruthy();+ expect(onChat).not.toHaveBeenCalled();+ fireEvent.click(screen.getByTestId("rail-open-team-view"));+ expect(onTeam).toHaveBeenCalledOnce();+});+it("bounds large rosters, hands exact filters to Workers and preserves empty search", () => {+ const open = vi.fn();+ render(+ <TeamRail+ members={members}+ summary={summary}+ chatEnabled+ onWorkers={open}+ open+ onToggle={vi.fn()}+ />,+ );+ expect(screen.getAllByTestId(/^team-row-/).length).toBeLessThan(20);+ fireEvent.change(screen.getByRole("searchbox"), {+ target: { value: "build-box" },+ });+ expect(screen.getAllByTestId(/^team-row-/)).toHaveLength(6);+ fireEvent.click(screen.getByText("View all 100 matches"));+ expect(open).toHaveBeenLastCalledWith({ query: "build-box" });+ fireEvent.change(screen.getByRole("searchbox"), {+ target: { value: "not-a-worker" },+ });+ expect(screen.queryAllByTestId(/^team-row-/)).toHaveLength(0);+ expect(screen.getByRole("status").textContent).toBe("0 matching workers");+});diff --git a/surfaces/gui/src/components/TeamRail.tsx b/surfaces/gui/src/components/TeamRail.tsxnew file mode 100644index 00000000..5ab91c97--- /dev/null+++ b/surfaces/gui/src/components/TeamRail.tsx@@ -0,0 +1,251 @@+import { useState } from "react";+import { useTranslation } from "react-i18next";+import type { SessionInfo, SessionUsage } from "../types";+import type { TeamSummary } from "../teamView";+import {+ filterWorkers,+ teamRoster,+ type RosterEntry,+ type WorkerFilter,+} from "../teamRoster";+import { formatTokens, totalTokens } from "../usage";+import { Icon } from "./Icon";++export function WorkerSearch({+ value,+ onChange,+}: {+ value: string;+ onChange: (value: string) => void;+}) {+ const { t } = useTranslation();+ return (+ <label className="team-worker-search">+ <Icon name="search" size={15} />+ <input+ type="search"+ value={value}+ onChange={(e) => onChange(e.target.value)}+ aria-label={t("teamview.search_workers_label")}+ placeholder={t("teamview.search_workers")}+ />+ </label>+ );+}++export function TeamRail({+ members,+ summary,+ usage,+ machine,+ chatEnabled,+ unread = 0,+ onChat,+ onWorker,+ onTeam,+ onWorkers,+ open,+ onToggle,+}: {+ members: SessionInfo[];+ summary?: TeamSummary | null;+ usage?: SessionUsage;+ machine?: string;+ chatEnabled: boolean;+ unread?: number;+ onChat?: () => void;+ onWorker?: (s: SessionInfo) => void;+ onTeam?: () => void;+ onWorkers?: (filter: WorkerFilter) => void;+ open: boolean;+ onToggle: () => void;+}) {+ const { t } = useTranslation();+ const [chatNotice, setChatNotice] = useState(false),+ [query, setQuery] = useState("");+ const entries = teamRoster(+ members,+ summary,+ machine || t("teamview.this_machine"),+ );+ const waiting = entries.filter((w) => w.attention),+ large = entries.length > 8;+ const matched = filterWorkers(entries, { query });+ const row = (w: RosterEntry, detail = false) => (+ <button+ className="rail-team-row team-roster-row"+ key={w.id}+ data-testid={`team-row-${w.name}`}+ disabled={!w.session}+ onClick={() => w.session && onWorker?.(w.session)}+ title={t("teamview.open_worker_pane", { name: w.name })}+ >+ <span+ className={`team-dot ${w.attention ? "attention" : w.working ? "working" : "idle"}`}+ />+ <span className="team-roster-main">+ <span className="rail-team-name">{w.name}</span>+ {detail && (+ <span className="team-roster-sub">+ {w.role} · {w.machine}+ </span>+ )}+ </span>+ <span+ className={"team-roster-status" + (w.attention ? " text-warnInk" : "")}+ >+ {w.attention+ ? t("teamview.needs_attention")+ : w.working+ ? t("teamview.state_working")+ : t("teamview.idle")}+ </span>+ </button>+ );+ const more = (filter: WorkerFilter, count: number, key = "view_workers") => (+ <button className="team-roster-link" onClick={() => onWorkers?.(filter)}>+ {t("teamview." + key, { count })} <Icon name="chevronRight" size={12} />+ </button>+ );+ return (+ <section className="rail-section team-rail" data-testid="team-rail">+ <div className="rail-section-head">+ <button+ className="rail-section-toggle"+ data-testid="rail-toggle-team"+ aria-expanded={open}+ onClick={onToggle}+ >+ <Icon+ name={open ? "chevronDown" : "chevronRight"}+ size={14}+ className="rail-chev"+ />+ <span>{t("rail.team_title")}</span>+ <span className="team-roster-count">{entries.length}</span>+ </button>+ <div className="team-rail-actions">+ <button+ className="rail-mini-btn"+ data-testid="team-chat-action"+ title={chatEnabled ? t("rail.team_chat") : t("teamview.chat_off")}+ aria-label={+ chatEnabled ? t("rail.team_chat") : t("teamview.chat_off")+ }+ aria-expanded={!chatEnabled && chatNotice}+ onClick={() =>+ chatEnabled ? onChat?.() : setChatNotice(!chatNotice)+ }+ >+ <Icon name="chat" size={17} />+ {chatEnabled && unread > 0 && (+ <span className="team-chat-badge">{unread}</span>+ )}+ </button>+ <button+ className="rail-mini-btn"+ data-testid="rail-open-team-view"+ title={t("teamview.open_view")}+ aria-label={t("teamview.open_view")}+ onClick={onTeam}+ >+ <Icon name="workList" size={17} />+ </button>+ </div>+ </div>+ {!chatEnabled && chatNotice && (+ <div+ className="team-chat-notice"+ role="status"+ data-testid="team-chat-off"+ >+ <span>{t("teamview.chat_off")}</span>+ <button+ className="rail-mini-btn"+ aria-label={t("teamview.dismiss")}+ onClick={() => setChatNotice(false)}+ >+ <Icon name="x" size={13} />+ </button>+ </div>+ )}+ {open && (+ <div className="rail-section-body rail-team" data-testid="team-panel">+ {large && <WorkerSearch value={query} onChange={setQuery} />}+ {large && query.trim() ? (+ <>+ <p className="team-roster-caption" role="status">+ {t("teamview.worker_matches", { count: matched.length })}+ </p>+ {matched.slice(0, 6).map((w) => row(w, true))}+ {matched.length > 6 &&+ more({ query }, matched.length, "view_matches")}+ </>+ ) : !large ? (+ entries.map((w) => row(w))+ ) : (+ <>+ <p className="team-roster-caption">+ {t("teamview.roster_summary", {+ count: waiting.length,+ working: entries.filter((w) => w.working && !w.attention)+ .length,+ })}+ </p>+ {!!waiting.length && (+ <>+ <p className="team-roster-caption">+ {t("teamview.needs_attention")}+ </p>+ {waiting.slice(0, 2).map((w) => row(w, true))}+ {waiting.length > 2 &&+ more({ attention: true }, waiting.length, "view_attention")}+ </>+ )}+ <p className="team-roster-caption">+ {t("teamview.workers_by_role")}+ </p>+ {[...new Set(entries.map((w) => w.role))].map((role) => {+ const group = entries.filter((w) => w.role === role);+ return (+ <details className="team-roster-group" key={role}>+ <summary>+ <Icon name="chevronRight" size={13} />+ <span>{role}</span>+ <span className="team-roster-count">{group.length}</span>+ </summary>+ <div className="team-roster-sublist">+ {group.slice(0, 4).map((w) => row(w))}+ {group.length > 4 && more({ role }, group.length)}+ </div>+ </details>+ );+ })}+ {more({}, entries.length)}+ </>+ )}+ {usage && totalTokens(usage) > 0 && (+ <details className="team-roster-usage" data-testid="team-usage">+ <summary>+ <span>{t("misc.rail.tokens")}</span>+ <span>{formatTokens(totalTokens(usage))}</span>+ </summary>+ {Object.entries(usage.byModel).map(([model, u]) => (+ <div className="rail-team-usage-row" key={model}>+ <span className="rail-team-usage-model">+ {model.split(":").pop()}+ </span>+ <span>+ {formatTokens(+ u.input + u.output + u.cache_read + u.cache_write,+ )}+ </span>+ </div>+ ))}+ </details>+ )}+ </div>+ )}+ </section>+ );+}diff --git a/surfaces/gui/src/components/TeamView.test.tsx b/surfaces/gui/src/components/TeamView.test.tsxindex bb1a5530..79b3a09b 100644--- a/surfaces/gui/src/components/TeamView.test.tsx+++ b/surfaces/gui/src/components/TeamView.test.tsx@@ -249,8 +249,8 @@ describe("team view", () => {);expect(screen.getByText("1 task is waiting on you.")).toBeTruthy();fireEvent.click(screen.getByRole("tab", { name: "Workers" }));- expect(screen.getAllByText("Show workers").length).toBeGreaterThan(0);- fireEvent.click(screen.getAllByText("Show workers")[0]);+ expect(screen.getByRole("searchbox")).toBeTruthy();+ expect(screen.getAllByTestId(/^team-worker-/)).toHaveLength(8);expect(screen.getByTestId("team-worker-sam")).toBeTruthy();fireEvent.click(screen.getByRole("tab", { name: "Stats" }));expect(screen.getByText("Top five of 100 workers")).toBeTruthy();diff --git a/surfaces/gui/src/components/TeamView.tsx b/surfaces/gui/src/components/TeamView.tsxindex ed581624..0ffd8e49 100644--- a/surfaces/gui/src/components/TeamView.tsx+++ b/surfaces/gui/src/components/TeamView.tsx@@ -33,6 +33,8 @@ import { ItemDetail } from "./BoardPanel";import { taskDot } from "./TaskChip";import { Icon } from "./Icon";import { Composer } from "./Composer";+import { WorkerSearch } from "./TeamRail";+import { teamRoster, filterWorkers, type WorkerFilter } from "../teamRoster";export const minutes = (seconds: number) =>Math.max(0, Math.round(seconds / 60));@@ -350,96 +352,117 @@ export function MetricBar({}function WorkerRows({- summary: s,+ summary,+ sessions,onWorker,machine,+ filter,+ onFilter,+ page,+ onPage,}: {summary: TeamSummary;+ sessions: SessionInfo[];onWorker: (worker: TeamWorker) => void;machine?: string;+ filter: WorkerFilter;+ onFilter: (filter: WorkerFilter) => void;+ page: number;+ onPage: (page: number) => void;}) {const { t } = useTranslation();- const [expanded, setExpanded] = useState<string[]>([]);- const row = (w: TeamWorker) => (- <button- className="team-task-row"- key={w.actor}- onClick={() => onWorker(w)}- data-testid={`team-worker-${w.actor}`}- >- <span className={taskDot(w.running ? "in_progress" : "open")} />- <span className="team-task-main">- <span className="team-task-title">- {w.actor} <small>· {w.role}</small>- </span>- <span className="team-task-status">- {s.items- .filter(- (i) =>- w.items.includes(i.id) &&- !["done", "canceled"].includes(i.group),- )- .map((i) => i.status || i.title)- .join(" · ") || t("teamview.idle")}- </span>- </span>- <span className="team-worker-chip">- {machine || t("teamview.this_machine")}- </span>- <span>{formatTokens(tokenTotal(w.tokens))}</span>- </button>+ const entries = teamRoster(+ sessions.filter((s) =>+ summary.workers.some((w) => w.session_id === s.session_id),+ ),+ summary,+ machine || t("teamview.this_machine"),+ );+ const matches = filterWorkers(entries, filter);+ const current = Math.min(+ page,+ Math.max(0, Math.ceil(matches.length / 8) - 1),);- if (s.workers.length <= 8) return <>{s.workers.map(row)}</>;return (<>- {[...new Set(s.workers.map((w) => w.role))].map((role) => {- const workers = s.workers.filter((w) => w.role === role);- const items = s.items.filter((i) =>- workers.some((w) => w.items.includes(i.id)),- );- const done = items.filter((i) => i.group === "done").length;- return (- <section key={role}>- <div className="team-group-heading">- {role} × {workers.length}- {s.workers.length > 30 && (- <>- <progress- value={done}- max={Math.max(1, items.length)}- aria-label={t("teamview.done_count", {- done,- total: items.length,- })}- />- <span>- {formatTokens(- workers.reduce((n, w) => n + tokenTotal(w.tokens), 0),- )}- </span>- <button- onClick={() =>- setExpanded((x) =>- x.includes(role)- ? x.filter((r) => r !== role)- : [...x, role],- )- }- >- {t(- expanded.includes(role)- ? "teamview.hide_workers"- : "teamview.show_workers",- )}- </button>- </>- )}- </div>- {(s.workers.length <= 30 || expanded.includes(role)) &&- workers.map(row)}- </section>- );- })}+ <WorkerSearch+ value={filter.query || ""}+ onChange={(query) => {+ onFilter({ ...filter, query });+ onPage(0);+ }}+ />+ {(filter.role || filter.attention) && (+ <div className="team-roster-filter">+ <span>{filter.role || t("teamview.needs_attention")}</span>+ <button+ onClick={() => {+ onFilter({ query: filter.query });+ onPage(0);+ }}+ >+ {t("teamview.clear_filter")}+ </button>+ </div>+ )}+ <p className="team-roster-caption" role="status">+ {t("teamview.worker_matches", { count: matches.length })}+ </p>+ {matches.slice(current * 8, current * 8 + 8).map((w) => (+ <button+ className="team-task-row"+ key={w.id}+ data-testid={`team-worker-${w.name}`}+ onClick={() => w.worker && onWorker(w.worker!)}+ >+ <span+ className={taskDot(+ w.attention ? "blocked" : w.working ? "in_progress" : "open",+ )}+ />+ <span className="team-task-main">+ <span className="team-task-title">+ {w.name} <small>· {w.role}</small>+ </span>+ <span className="team-task-status">+ {w.task || t("teamview.idle")}+ </span>+ </span>+ <span className="team-worker-chip">{w.machine}</span>+ <span>{formatTokens(tokenTotal(w.worker!.tokens))}</span>+ </button>+ ))}+ {matches.length > 8 && (+ <div className="team-roster-pagination">+ <button+ className="rail-mini-btn"+ disabled={current === 0}+ aria-label={t("teamview.previous_workers")}+ onClick={() => onPage(current - 1)}+ >+ <Icon+ name="chevronRight"+ size={14}+ className="team-roster-previous"+ />+ </button>+ <span>+ {t("teamview.worker_range", {+ start: current * 8 + 1,+ end: Math.min(current * 8 + 8, matches.length),+ count: matches.length,+ })}+ </span>+ <button+ className="rail-mini-btn"+ disabled={(current + 1) * 8 >= matches.length}+ aria-label={t("teamview.next_workers")}+ onClick={() => onPage(current + 1)}+ >+ <Icon name="chevronRight" size={14} />+ </button>+ </div>+ )}</>);}@@ -682,6 +705,7 @@ export function TeamView({board,initialItem,initialWorkerId,+ initialWorkerFilter,onOpenFullSession,openKey = 0,sessionId,@@ -696,6 +720,7 @@ export function TeamView({board?: Board | null;initialItem?: number | null;initialWorkerId?: string | null;+ initialWorkerFilter?: WorkerFilter | null;onOpenFullSession?: (id: string) => void;sessionId: string;sessions: SessionInfo[];@@ -706,12 +731,21 @@ export function TeamView({}) {const { t } = useTranslation();const [tab, setTab] = useState<"work" | "workers" | "stats">("work");+ const [workerFilter, setWorkerFilter] = useState<WorkerFilter>(+ initialWorkerFilter || {},+ );+ const [workerPage, setWorkerPage] = useState(0);const [selected, setSelected] = useState<number | null>(initialItem ?? null);- const [selectedWorker, setSelectedWorker] = useState<string | null>(initialWorkerId ?? null);+ const [selectedWorker, setSelectedWorker] = useState<string | null>(+ initialWorkerId ?? null,+ );useEffect(() => {setSelected(initialItem ?? null);setSelectedWorker(initialWorkerId ?? null);- }, [initialItem, initialWorkerId, sessionId, openKey]);+ setWorkerFilter(initialWorkerFilter || {});+ setWorkerPage(0);+ setTab(initialWorkerFilter ? "workers" : "work");+ }, [initialItem, initialWorkerId, initialWorkerFilter, sessionId, openKey]);const fallbackItems: TeamTask[] = (board?.items || []).map((i) => ({...i,group: i.waiting@@ -733,24 +767,20 @@ export function TeamView({summary?.workers ||sessions.filter((w) => w.team?.lead_session === sessionId && w.team?.actor)- .map(- (w): TeamWorker => ({- actor: w.team!.actor!,- role: w.agent,- session_id: w.session_id,- model: w.model,- workspace: w.workspace,- running: w.liveness === "working",- tokens: { input: 0, output: 0, cache_read: 0, cache_write: 0 },- usage_partial: true,- items: shownItems- .filter((i) => i.assignee === w.team!.actor)- .map((i) => i.id),- }),- );- const worker = workers.find(- (w) => w.session_id === selectedWorker,- );+ .map((w): TeamWorker => ({+ actor: w.team!.actor!,+ role: w.agent,+ session_id: w.session_id,+ model: w.model,+ workspace: w.workspace,+ running: w.liveness === "working",+ tokens: { input: 0, output: 0, cache_read: 0, cache_write: 0 },+ usage_partial: true,+ items: shownItems+ .filter((i) => i.assignee === w.team!.actor)+ .map((i) => i.id),+ }));+ const worker = workers.find((w) => w.session_id === selectedWorker);const goBack = () => {setSelected(null);setSelectedWorker(null);@@ -803,9 +833,14 @@ export function TeamView({))}</div>)}- {worker && onOpenFullSession && <button className="team-full-session" onClick={() => onOpenFullSession(worker.session_id)}>- {t("teamview.full_session")}- </button>}+ {worker && onOpenFullSession && (+ <button+ className="team-full-session"+ onClick={() => onOpenFullSession(worker.session_id)}+ >+ {t("teamview.full_session")}+ </button>+ )}<buttonclassName="team-close"onClick={onClose}@@ -904,6 +939,11 @@ export function TeamView({<TeamTotals summary={summary} /><WorkerRowssummary={summary}+ sessions={sessions}+ filter={workerFilter}+ onFilter={setWorkerFilter}+ page={workerPage}+ onPage={setWorkerPage}onWorker={openWorker}machine={machineName}/>diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.jsonindex a523b8e8..1fb6bda7 100644--- a/surfaces/gui/src/locales/en.json+++ b/surfaces/gui/src/locales/en.json@@ -2264,6 +2264,22 @@}},"teamview": {+ "worker_matches_one": "{{count}} matching worker",+ "roster_summary_one": "{{count}} needs attention · {{working}} working",+ "search_workers": "Find a worker…",+ "search_workers_label": "Find workers by name, role, task or machine",+ "needs_attention": "Needs attention",+ "view_workers": "View all {{count}} workers",+ "view_matches": "View all {{count}} matches",+ "view_attention": "View all {{count}} needing attention",+ "worker_matches": "{{count}} matching workers",+ "roster_summary": "{{count}} need attention · {{working}} working",+ "workers_by_role": "Workers by role",+ "dismiss": "Dismiss",+ "clear_filter": "Clear filter",+ "previous_workers": "Previous workers",+ "next_workers": "Next workers",+ "worker_range": "{{start}}–{{end}} of {{count}}","summary_unavailable": "Showing the board. Team statistics are unavailable from this server.","hours_minutes": "{{hours}} h {{minutes}} min","asks_per_task": "{{value}} asks per completed task",diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.jsonindex 24812e2c..809a26a0 100644--- a/surfaces/gui/src/locales/zh.json+++ b/surfaces/gui/src/locales/zh.json@@ -2224,6 +2224,22 @@}},"teamview": {+ "worker_matches_one": "{{count}} 位匹配成员",+ "roster_summary_one": "{{count}} 位需要关注 · {{working}} 位工作中",+ "search_workers": "查找成员…",+ "search_workers_label": "按姓名、角色、任务或机器查找成员",+ "needs_attention": "需要关注",+ "view_workers": "查看全部 {{count}} 位成员",+ "view_matches": "查看全部 {{count}} 条匹配",+ "view_attention": "查看全部 {{count}} 位需要关注的成员",+ "worker_matches": "{{count}} 位匹配成员",+ "roster_summary": "{{count}} 位需要关注 · {{working}} 位工作中",+ "workers_by_role": "按角色分组",+ "dismiss": "关闭",+ "clear_filter": "清除筛选",+ "previous_workers": "上一页成员",+ "next_workers": "下一页成员",+ "worker_range": "第 {{start}}–{{end}} 位,共 {{count}} 位","summary_unavailable": "正在显示看板,此服务器暂不提供团队统计。","hours_minutes": "{{hours}} 小时 {{minutes}} 分钟","asks_per_task": "每项已完成任务请求 {{value}} 次",diff --git a/surfaces/gui/src/styles.css b/surfaces/gui/src/styles.cssindex 26a4b12b..8bd2bbec 100644--- a/surfaces/gui/src/styles.css+++ b/surfaces/gui/src/styles.css@@ -2250,6 +2250,43 @@ html[data-platform="linux"] ::-webkit-scrollbar-thumb:hover { background-color:.team-close { margin-left:auto; font-size:var(--fs-title)!important; }.team-pane-header .team-full-session { margin-left:auto; font-size:var(--fs-meta); }.team-full-session + .team-close { margin-left:0; }+.team-rail .rail-section-toggle { flex:1; min-width:0; }+.team-roster-count { font-size:var(--fs-label); color:var(--muted); font-weight:400; }+.team-rail-actions { display:flex; gap:5px; align-items:center; }+.team-rail-actions .rail-mini-btn { width:30px; height:30px; position:relative; }+.team-rail-actions .team-chat-badge { position:absolute; top:-4px; right:-5px; font-size:10px; }+.team-chat-notice { display:flex; align-items:center; gap:8px; padding:9px 10px; margin-top:10px; border:1px solid var(--line); background:var(--panel); border-radius:8px; font-size:var(--fs-meta); color:var(--muted); }+.team-chat-notice span { flex:1; }+.team-worker-search { display:flex; align-items:center; gap:8px; border:1px solid var(--line); border-radius:7px; background:var(--panel); color:var(--muted); padding:7px 9px; margin:4px 0 10px; }+.team-worker-search input { min-width:0; width:100%; border:0; background:transparent; color:var(--ink); font:inherit; font-size:var(--fs-meta); }+.team-worker-search:focus-within { outline:2px solid var(--accent); outline-offset:2px; }+.team-roster-caption { font-size:var(--fs-meta); color:var(--muted); margin:8px 6px; }+.team-roster-main { flex:1; min-width:0; }+.team-roster-main .rail-team-name { display:block; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; font-weight:500; }+.team-roster-sub { display:block; font-size:var(--fs-label); color:var(--muted); overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }+.team-roster-status { font-size:var(--fs-label); color:var(--muted); }+.team-roster-status.text-warnInk { color:var(--warn-ink); }+.team-roster-row { padding:8px 6px; }+.team-roster-row .team-dot.attention { background:var(--warn-ink); }+.team-roster-row .team-dot.working { background:var(--accent); }+.team-roster-group summary { display:flex; align-items:center; gap:8px; padding:9px 6px; cursor:pointer; list-style:none; border-radius:6px; font-size:var(--fs-ui); }+.team-roster-group summary::-webkit-details-marker { display:none; }+.team-roster-group summary:hover { background:var(--chrome-hover); }+.team-roster-group summary span:first-of-type { flex:1; min-width:0; overflow-wrap:anywhere; }+.team-roster-group summary svg { color:var(--muted); }+.team-roster-group[open] > summary svg { transform:rotate(90deg); }+.team-roster-sublist { padding-left:12px; }+.team-roster-link { display:flex; align-items:center; gap:6px; text-align:left; padding:8px 6px; border:0; background:none; color:var(--muted); font-size:var(--fs-meta); cursor:pointer; border-radius:6px; }+.team-roster-link:hover { background:var(--chrome-hover); color:var(--ink); }+.team-roster-usage { border-top:1px solid var(--line); margin-top:10px; padding:10px 6px 0; }+.team-roster-usage summary { display:flex; justify-content:space-between; cursor:pointer; color:var(--muted); font-size:var(--fs-meta); list-style:none; }+.team-roster-usage summary::-webkit-details-marker { display:none; }+.team-roster-usage .rail-team-usage-row { margin-top:7px; }+.team-roster-filter,.team-roster-pagination { display:flex; justify-content:space-between; align-items:center; gap:8px; font-size:var(--fs-meta); color:var(--muted); margin:10px 0; }+.team-roster-filter button { border:0; background:none; color:var(--muted); text-decoration:underline; cursor:pointer; }+.team-roster-previous { transform:rotate(180deg); }+.team-roster-pagination button:disabled { opacity:.4; cursor:default; }+@media(pointer:coarse) { .team-rail-actions .rail-mini-btn,.team-roster-pagination .rail-mini-btn { width:44px; height:44px; } .team-worker-search input { font-size:16px; } }.team-attention-count { margin-left:6px; background:var(--warn-soft); color:var(--warn-ink); border-radius:9px; padding:1px 5px; font-size:var(--fs-label); }.team-pane-body { flex:1; min-height:0; overflow:auto; padding:20px; }.team-pane-body h2,.team-worker-header h2 { font-size:var(--fs-title); font-weight:600; letter-spacing:-.01em; margin:0 0 4px; }diff --git a/surfaces/gui/src/teamRoster.test.ts b/surfaces/gui/src/teamRoster.test.tsnew file mode 100644index 00000000..0238f995--- /dev/null+++ b/surfaces/gui/src/teamRoster.test.ts@@ -0,0 +1,46 @@+import { describe, expect, it } from "vitest";+import { teamRoster, filterWorkers } from "./teamRoster";+import { sampleTeam } from "./gallery/states/team-view";+import type { SessionInfo } from "./types";++describe("team roster projection", () => {+ it("merges by session id and searches names, roles, tasks and machines", () => {+ const summary = sampleTeam(100);+ const sam = summary.workers[0];+ const session = {+ session_id: sam.session_id,+ agent: sam.role,+ machine_name: "build-box",+ team: { actor: sam.actor },+ attention: 1,+ } as SessionInfo;+ const entries = teamRoster([session], summary);+ expect(entries).toHaveLength(100);+ expect(filterWorkers(entries, { query: "BUILD-BOX" })).toHaveLength(1);+ expect(+ filterWorkers(entries, { query: "sam" }).some(+ (w) => w.id === sam.session_id,+ ),+ ).toBe(true);+ expect(filterWorkers(entries, { role: sam.role })).toHaveLength(40);+ expect(filterWorkers(entries, { query: "refund" }).length).toBeGreaterThan(+ 0,+ );+ expect(+ filterWorkers(entries, { attention: true }).some(+ (w) => w.id === sam.session_id,+ ),+ ).toBe(true);+ expect(filterWorkers(entries, { query: "missing-worker" })).toHaveLength(0);+ });+ it("does not turn a completed task into attention, or infer status from its text", () => {+ const summary = sampleTeam();+ summary.items = summary.items.map((i) => ({+ ...i,+ group: "done",+ title: "waiting for approval",+ }));+ const entries = teamRoster([], summary);+ expect(entries.some((w) => w.attention)).toBe(false);+ });+});diff --git a/surfaces/gui/src/teamRoster.ts b/surfaces/gui/src/teamRoster.tsnew file mode 100644index 00000000..cf820274--- /dev/null+++ b/surfaces/gui/src/teamRoster.ts@@ -0,0 +1,71 @@+import type { SessionInfo } from "./types";+import type { TeamSummary, TeamWorker } from "./teamView";++export type WorkerFilter = {+ query?: string;+ role?: string;+ attention?: boolean;+};+export type RosterEntry = {+ id: string;+ name: string;+ role: string;+ machine: string;+ task: string;+ attention: boolean;+ working: boolean;+ session?: SessionInfo;+ worker?: TeamWorker;+};++export function teamRoster(+ sessions: SessionInfo[],+ summary?: TeamSummary | null,+ machine = "",+): RosterEntry[] {+ const byId = new Map(sessions.map((s) => [s.session_id, s]));+ const workers = new Map(summary?.workers.map((w) => [w.session_id, w]));+ const ids = [...new Set([...byId.keys(), ...workers.keys()])];+ return ids.map((id) => {+ const session = byId.get(id),+ worker = workers.get(id);+ const name = worker?.actor || session?.team?.actor || session?.agent || id;+ const tasks =+ summary?.items.filter(+ (i) => worker?.items.includes(i.id) || i.assignee === name,+ ) || [];+ const active = tasks.filter((i) => !["done", "canceled"].includes(i.group));+ return {+ id,+ name,+ role: worker?.role || session?.agent || "",+ machine: session?.machine_name || machine,+ task:+ active+ .map((i) => [i.title, i.status].filter(Boolean).join(" · "))+ .join(" · ") ||+ session?.team?.current_item ||+ "",+ attention:+ !!session?.attention ||+ active.some((i) => i.group === "waiting") ||+ ["blocked", "waiting"].includes(session?.team?.status || ""),+ working: worker?.running ?? session?.liveness === "working",+ session,+ worker,+ };+ });+}++export function filterWorkers(entries: RosterEntry[], filter: WorkerFilter) {+ const query = (filter.query || "").trim().toLocaleLowerCase();+ return entries.filter(+ (w) =>+ (!filter.role || w.role === filter.role) &&+ (!filter.attention || w.attention) &&+ [w.name, w.role, w.machine, w.task]+ .join(" ")+ .toLocaleLowerCase()+ .includes(query),+ );+}