Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(runtimes): show and edit visibility from the runtime list (MUL-10200) (#11557)
Jiayuan Zhang4c6c33f7804c
diff --git a/packages/views/runtimes/components/runtime-access-editor.tsx b/packages/views/runtimes/components/runtime-access-editor.tsxindex ea726dc6a7..93b9395232 100644--- a/packages/views/runtimes/components/runtime-access-editor.tsx+++ b/packages/views/runtimes/components/runtime-access-editor.tsx@@ -35,13 +35,13 @@ import {type RuntimeAccessRevocationPlan,} from "./revoke-runtime-access-dialog";-type RuntimeAccessScope = "private" | "public" | "members";+export type RuntimeAccessScope = "private" | "public" | "members";// Below this size the member list fits without scrolling, so a search field// would only add noise.const MEMBER_SEARCH_THRESHOLD = 7;-const SCOPE_ICON = { private: Lock, public: Globe, members: Users } as const;+export const SCOPE_ICON = { private: Lock, public: Globe, members: Users } as const;export function runtimeAccessScope(runtime: AgentRuntime): RuntimeAccessScope {if (runtime.visibility === "public") return "public";@@ -66,13 +66,12 @@ export function RuntimeAccessReadout({ runtime }: { runtime: AgentRuntime }) {}/**- * Owner-only access control. Private and Public apply in one click, as before- * member sharing existed; restricting access still goes through the reviewed- * revocation dialog when the server reports affected agents or runs. Choosing- * members opens a draft popover that persists only on Save, so a partial- * selection is never shared.+ * The owner's access controls, shared by the detail page's editor and the+ * runtime list's menu. Private and Public apply in one call; restricting+ * access goes through the reviewed revocation dialog when the server reports+ * affected agents or runs, so the caller must render `revokeDialog`.*/-export function RuntimeAccessEditor({ runtime }: { runtime: AgentRuntime }) {+export function useRuntimeAccess(runtime: AgentRuntime) {const { t } = useT("runtimes");const wsId = useWorkspaceId();const { data: members = [] } = useQuery(memberListOptions(wsId));@@ -88,16 +87,20 @@ export function RuntimeAccessEditor({ runtime }: { runtime: AgentRuntime }) {hasExistingConfig: current === "members",});const membersDisabled = !memberSharing.canAdd && current !== "members";- const [pickerOpen, setPickerOpen] = useState(false);const [revokePlan, setRevokePlan] = useState<RuntimeAccessRevocationPlan | null>(null);const [revokeOpen, setRevokeOpen] = useState(false);const [revokeMembers, setRevokeMembers] = useState<string[]>([]);- const disabled = updateRuntime.isPending || revokeOpen;const recipients = useMemo(() => members.filter((member) => persisted.includes(member.user_id)),[members, persisted],);+ const candidates = useMemo(+ () => members.filter((member) =>+ member.user_id !== runtime.owner_id &&+ (memberSharing.canAdd || persisted.includes(member.user_id))),+ [members, runtime.owner_id, memberSharing.canAdd, persisted],+ );const apply = (scope: RuntimeAccessScope, sharedWith: string[], onApplied?: () => void) => {updateRuntime.mutate(@@ -128,6 +131,36 @@ export function RuntimeAccessEditor({ runtime }: { runtime: AgentRuntime }) {);};+ return {+ current,+ persisted,+ recipients,+ candidates,+ memberSharing,+ membersDisabled,+ saving: updateRuntime.isPending,+ disabled: updateRuntime.isPending || revokeOpen,+ apply,+ revokeDialog: (+ <RevokeRuntimeAccessDialog open={revokeOpen} onOpenChange={setRevokeOpen}+ runtime={runtime} wsId={wsId} initialPlan={revokePlan} sharedWith={revokeMembers} />+ ),+ };+}++/**+ * Owner-only access control on the detail page. Choosing members opens a+ * draft popover that persists only on Save, so a partial selection is never+ * shared.+ */+export function RuntimeAccessEditor({ runtime }: { runtime: AgentRuntime }) {+ const { t } = useT("runtimes");+ const {+ current, persisted, recipients, candidates, memberSharing, membersDisabled,+ saving, disabled, apply, revokeDialog,+ } = useRuntimeAccess(runtime);+ const [pickerOpen, setPickerOpen] = useState(false);+return (<div className="space-y-2"><div@@ -153,11 +186,9 @@ export function RuntimeAccessEditor({ runtime }: { runtime: AgentRuntime }) {<PopoverContent align="end" className="w-72 p-0">{pickerOpen ? (<MemberPicker- members={members.filter((member) =>- member.user_id !== runtime.owner_id &&- (memberSharing.canAdd || persisted.includes(member.user_id)))}+ members={candidates}initial={persisted}- saving={updateRuntime.isPending}+ saving={saving}onCancel={() => setPickerOpen(false)}onSave={(ids) => apply("members", ids, () => setPickerOpen(false))}/>@@ -195,8 +226,7 @@ export function RuntimeAccessEditor({ runtime }: { runtime: AgentRuntime }) {<PaidFeatureUpgradeBadge feature="runtime_member_sharing" className="shrink-0" /></div>) : null}- <RevokeRuntimeAccessDialog open={revokeOpen} onOpenChange={setRevokeOpen}- runtime={runtime} wsId={wsId} initialPlan={revokePlan} sharedWith={revokeMembers} />+ {revokeDialog}</div>);}@@ -238,7 +268,7 @@ function ScopeButton({);}-function MemberPicker({+export function MemberPicker({members,initial,saving,diff --git a/packages/views/runtimes/components/runtime-list-visibility.test.tsx b/packages/views/runtimes/components/runtime-list-visibility.test.tsxnew file mode 100644index 0000000000..d058f5eb9a--- /dev/null+++ b/packages/views/runtimes/components/runtime-list-visibility.test.tsx@@ -0,0 +1,171 @@+// @vitest-environment jsdom++import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { cleanup, fireEvent, screen, waitFor, within } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { ApiError } from "@multica/core/api";+import type { AgentRuntime, MemberWithUser } from "@multica/core/types";+import { NavigationProvider, type NavigationAdapter } from "../../navigation";+import { renderWithI18n } from "../../test/i18n";+import { RuntimeList } from "./runtime-list";++const api = vi.hoisted(() => ({+ listMembers: vi.fn(),+ listAgents: vi.fn(),+ updateRuntime: vi.fn(),+ getWorkspaceFeatures: vi.fn(),+ revokeRuntimeWorkspaceAccess: vi.fn(),+}));+vi.mock("@multica/core/api", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@multica/core/api")>()),+ api,+}));+vi.mock("@multica/core/hooks", () => ({ useWorkspaceId: () => "ws-1" }));+const authUser = vi.hoisted(() => ({ id: "owner" }));+vi.mock("@multica/core/auth", () => ({+ useAuthStore: (sel: (s: { user: { id: string } }) => unknown) => sel({ user: authUser }),+}));+vi.mock("@multica/core/paths", async (importOriginal) => ({+ ...(await importOriginal<object>()),+ useWorkspacePaths: () => ({+ runtimeDetail: (id: string) => `/acme/runtimes/${id}`,+ settings: () => "/acme/settings",+ }),+}));+// Cells that fetch their own data are out of scope here.+vi.mock("./rate-limit-section", () => ({ RateLimitCell: () => null }));+vi.mock("./provider-logo", () => ({ ProviderLogo: () => null }));+vi.mock("../../common/actor-avatar", () => ({ ActorAvatar: () => null }));+vi.mock("../../common/use-viewing-timezone", () => ({ useViewingTimezone: () => "UTC" }));+vi.mock("sonner", () => ({ toast: { error: vi.fn(), success: vi.fn() } }));++const MEMBERS = [+ { user_id: "owner", name: "Owner", role: "member" },+ { user_id: "admin", name: "Admin", role: "admin" },+ { user_id: "u1", name: "Alice", role: "member" },+] as unknown as MemberWithUser[];++function runtime(overrides: Partial<AgentRuntime> = {}): AgentRuntime {+ return {+ id: "rt-1", workspace_id: "ws-1", name: "Claude", custom_name: null,+ daemon_id: "d-1", runtime_mode: "local", provider: "claude", launch_header: "", status: "online",+ device_info: "", metadata: {}, owner_id: "owner", visibility: "private", last_seen_at: null,+ created_at: "2026-09-05T00:00:00Z", updated_at: "2026-09-05T00:00:00Z",+ ...overrides,+ } as AgentRuntime;+}++const navigation: NavigationAdapter = {+ push: vi.fn(),+ replace: vi.fn(),+ back: vi.fn(),+ pathname: "/acme/runtimes",+ searchParams: new URLSearchParams(),+ hash: "",+ getShareableUrl: (path) => path,+};++function renderList(runtimes: AgentRuntime[]) {+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } });+ return renderWithI18n(+ <NavigationProvider value={navigation}>+ <QueryClientProvider client={qc}>+ <RuntimeList runtimes={runtimes} now={Date.now()} />+ </QueryClientProvider>+ </NavigationProvider>,+ );+}++const rowOf = (name: string) =>+ screen.getAllByRole("row").find((row) => within(row).queryByText(name))!;+const trigger = (label: string) => screen.getByRole("button", { name: `Visibility: ${label}` });++describe("RuntimeList visibility (MUL-10200)", () => {+ beforeEach(() => {+ authUser.id = "owner";+ api.listMembers.mockResolvedValue(MEMBERS);+ api.listAgents.mockResolvedValue([]);+ api.updateRuntime.mockResolvedValue(runtime({ visibility: "public" }));+ api.getWorkspaceFeatures.mockResolvedValue({ features: { runtime_member_sharing: "available" } });+ });+ afterEach(() => {+ cleanup();+ vi.clearAllMocks();+ });++ it("marks every scope, private included, with the member count for shared runtimes", () => {+ authUser.id = "u1";+ renderList([+ runtime({ id: "a", name: "Alpha" }),+ runtime({ id: "b", name: "Beta", visibility: "public" }),+ runtime({ id: "c", name: "Gamma", shared_with: ["u1", "admin"] }),+ ]);+ expect(within(rowOf("Alpha")).getByRole("img", { name: "Visibility: Private" })).toBeInTheDocument();+ expect(within(rowOf("Beta")).getByRole("img", { name: "Visibility: Public" })).toBeInTheDocument();+ expect(within(rowOf("Gamma")).getByRole("img", { name: "Visibility: 2 members" })).toHaveTextContent(/^2$/);+ });++ it("lets the owner switch scope from the menu without opening the row", async () => {+ renderList([runtime()]);+ fireEvent.click(trigger("Private"));+ fireEvent.click(await screen.findByRole("menuitem", { name: "Public" }));+ await waitFor(() =>+ expect(api.updateRuntime).toHaveBeenCalledWith("rt-1", { visibility: "public", shared_with: [] }),+ );+ expect(navigation.push).not.toHaveBeenCalled();+ });++ it("shares with members through the picker, saving only on Save", async () => {+ renderList([runtime()]);+ fireEvent.click(trigger("Private"));+ const members = await screen.findByRole("menuitem", { name: "Specific members…" });+ // Enabled once the plan says member sharing is available.+ await waitFor(() => expect(members).not.toHaveAttribute("aria-disabled", "true"));+ fireEvent.click(members);+ fireEvent.click(await screen.findByRole("checkbox", { name: "Alice" }));+ expect(api.updateRuntime).not.toHaveBeenCalled();+ // The owner is never offered to themselves.+ expect(screen.queryByRole("checkbox", { name: "Owner" })).toBeNull();+ fireEvent.click(screen.getByRole("button", { name: "Save" }));+ await waitFor(() =>+ expect(api.updateRuntime).toHaveBeenCalledWith("rt-1", { visibility: "private", shared_with: ["u1"] }),+ );+ expect(navigation.push).not.toHaveBeenCalled();+ });++ it("is read-only for anyone but the owner, admins included", () => {+ authUser.id = "admin";+ renderList([runtime({ visibility: "public" })]);+ expect(screen.queryByRole("button", { name: /^Visibility:/ })).toBeNull();+ fireEvent.click(within(rowOf("Claude")).getByRole("img", { name: "Visibility: Public" }));+ expect(navigation.push).toHaveBeenCalledWith("/acme/runtimes/rt-1");+ });++ it("confirms before revoking access from the list", async () => {+ api.updateRuntime.mockRejectedValue(+ new ApiError("conflict", 409, "Conflict", {+ code: "runtime_has_nonowner_dependents",+ nonowner_agents: [{ id: "00000000-0000-4000-8000-000000000001", name: "Teammate Agent" }],+ active_task_ids: [],+ }),+ );+ renderList([runtime({ visibility: "public" })]);+ fireEvent.click(trigger("Public"));+ fireEvent.click(await screen.findByRole("menuitem", { name: "Private" }));++ const dialog = await screen.findByRole("alertdialog");+ expect(within(dialog).getByText("Teammate Agent")).toBeInTheDocument();+ fireEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));+ await waitFor(() => expect(screen.queryByRole("alertdialog")).toBeNull());+ expect(navigation.push).not.toHaveBeenCalled();+ });++ it("disables member sharing for a runtime without a list on a locked plan", async () => {+ api.getWorkspaceFeatures.mockResolvedValue({ features: { runtime_member_sharing: "locked" } });+ renderList([runtime()]);+ fireEvent.click(trigger("Private"));+ await waitFor(() =>+ expect(screen.getByRole("menuitem", { name: "Specific members…" })).toHaveAttribute("aria-disabled", "true"),+ );+ });+});diff --git a/packages/views/runtimes/components/runtime-list-visibility.tsx b/packages/views/runtimes/components/runtime-list-visibility.tsxnew file mode 100644index 0000000000..a9c2b25e83--- /dev/null+++ b/packages/views/runtimes/components/runtime-list-visibility.tsx@@ -0,0 +1,182 @@+"use client";++import { useRef, useState, type ReactNode, type SyntheticEvent } from "react";+import { Check } from "@multica/ui/icons";+import type { AgentRuntime } from "@multica/core/types";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from "@multica/ui/components/ui/dropdown-menu";+import {+ Popover,+ PopoverContent,+} from "@multica/ui/components/ui/popover";+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from "@multica/ui/components/ui/tooltip";+import { cn } from "@multica/ui/lib/utils";+import { useT } from "../../i18n";+import {+ MemberPicker,+ SCOPE_ICON,+ runtimeAccessScope,+ useRuntimeAccess,+ type RuntimeAccessScope,+} from "./runtime-access-editor";++const SCOPES: readonly RuntimeAccessScope[] = ["private", "public", "members"];++const MARK_CLASS =+ "-mx-1 inline-flex h-5 min-w-5 shrink-0 items-center justify-center gap-0.5 rounded-xs px-1 text-micro font-medium tabular-nums text-faint-foreground";++/**+ * A runtime's access scope at the right edge of its name cell, so the scopes+ * of every row line up. The owner changes it from a menu; everyone else,+ * admins included, reads the same hint as on the detail page.+ */+export function RuntimeListVisibility({+ runtime,+ canEdit,+}: {+ runtime: AgentRuntime;+ canEdit: boolean;+}) {+ const { t } = useT("runtimes");+ const scope = runtimeAccessScope(runtime);+ const Icon = SCOPE_ICON[scope];+ const count = runtime.shared_with?.length ?? 0;+ const label =+ scope === "members"+ ? t(($) => $.detail.visibility_members_count, { count })+ : t(($) => $.detail.visibility_label[scope]);+ const ariaLabel = `${t(($) => $.detail.diagnostics_visibility)}: ${label}`;+ const mark = (+ <>+ <Icon className="size-3" aria-hidden="true" />+ {scope === "members" ? <span aria-hidden="true">{count}</span> : null}+ </>+ );++ if (!canEdit) {+ return (+ <Tooltip>+ <TooltipTrigger+ render={+ <span role="img" aria-label={ariaLabel} className={MARK_CLASS}>+ {mark}+ </span>+ }+ />+ <TooltipContent>+ {label} · {t(($) => $.detail.visibility_hint_readonly[scope])}+ </TooltipContent>+ </Tooltip>+ );+ }++ return (+ <VisibilityMenu+ runtime={runtime}+ ariaLabel={ariaLabel}+ tooltip={`${label} · ${t(($) => $.detail.visibility_hint[scope])}`}+ >+ {mark}+ </VisibilityMenu>+ );+}++function VisibilityMenu({+ runtime,+ ariaLabel,+ tooltip,+ children,+}: {+ runtime: AgentRuntime;+ ariaLabel: string;+ tooltip: string;+ children: ReactNode;+}) {+ const { t } = useT("runtimes");+ const access = useRuntimeAccess(runtime);+ const triggerRef = useRef<HTMLButtonElement>(null);+ const [menuOpen, setMenuOpen] = useState(false);+ const [pickerOpen, setPickerOpen] = useState(false);+ const [hover, setHover] = useState(false);++ const choose = (scope: RuntimeAccessScope) => {+ if (scope === "members") {+ setPickerOpen(true);+ return;+ }+ if (access.current !== scope) access.apply(scope, []);+ };++ // The trigger sits inside the row's link. Its menu, picker and dialog are+ // portaled, and the row already ignores events from outside its own DOM.+ const stop = (e: SyntheticEvent) => e.stopPropagation();++ return (+ <span className="inline-flex shrink-0" onClick={stop} onAuxClick={stop}>+ <DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>+ <Tooltip open={hover && !menuOpen && !pickerOpen} onOpenChange={setHover}>+ <TooltipTrigger+ render={+ <DropdownMenuTrigger+ ref={triggerRef}+ aria-label={ariaLabel}+ className={cn(+ MARK_CLASS,+ "cursor-pointer transition-colors hover:bg-accent hover:text-muted-foreground",+ "data-popup-open:bg-accent data-popup-open:text-muted-foreground",+ pickerOpen && "bg-accent text-muted-foreground",+ )}+ >+ {children}+ </DropdownMenuTrigger>+ }+ />+ <TooltipContent>{tooltip}</TooltipContent>+ </Tooltip>+ <DropdownMenuContent align="start" className="w-48">+ {SCOPES.map((scope) => {+ const Icon = SCOPE_ICON[scope];+ return (+ <DropdownMenuItem+ key={scope}+ disabled={access.disabled || (scope === "members" && access.membersDisabled)}+ onClick={() => choose(scope)}+ >+ <Icon className="text-muted-foreground" aria-hidden="true" />+ <span>+ {t(($) => $.detail.visibility_label[scope])}+ {scope === "members" ? "…" : null}+ </span>+ {access.current === scope ? (+ <Check className="ml-auto size-3.5" aria-hidden="true" />+ ) : null}+ </DropdownMenuItem>+ );+ })}+ </DropdownMenuContent>+ </DropdownMenu>+ <Popover open={pickerOpen} onOpenChange={setPickerOpen}>+ <PopoverContent anchor={triggerRef} align="start" className="w-72 p-0">+ {pickerOpen ? (+ <MemberPicker+ members={access.candidates}+ initial={access.persisted}+ saving={access.saving}+ onCancel={() => setPickerOpen(false)}+ onSave={(ids) => access.apply("members", ids, () => setPickerOpen(false))}+ />+ ) : null}+ </PopoverContent>+ </Popover>+ {access.revokeDialog}+ </span>+ );+}diff --git a/packages/views/runtimes/components/runtime-list.tsx b/packages/views/runtimes/components/runtime-list.tsxindex 754a1145ab..af2be2dc21 100644--- a/packages/views/runtimes/components/runtime-list.tsx+++ b/packages/views/runtimes/components/runtime-list.tsx@@ -4,8 +4,6 @@ import { useMemo, useState } from "react";import {AlertTriangle,ExternalLink,- Globe,- Users,Loader2,Pencil,Trash2,@@ -38,11 +36,6 @@ import {DropdownMenuItem,DropdownMenuSeparator,} from "@multica/ui/components/ui/dropdown-menu";-import {- Tooltip,- TooltipContent,- TooltipTrigger,-} from "@multica/ui/components/ui/tooltip";import { useIntentNavigate } from "../../navigation";import {CollectionEmptyValue,@@ -59,6 +52,7 @@ import { HealthIcon, useHealthLabel } from "./shared";import { DeleteRuntimeDialog } from "./delete-runtime-dialog";import { DeleteRuntimeProfileDialog } from "./delete-runtime-profile-dialog";import { RuntimeProfilesDialog } from "./runtime-profiles-dialog";+import { RuntimeListVisibility } from "./runtime-list-visibility";import {computeCostInWindow,pctChange,@@ -138,8 +132,11 @@ export function buildWorkloadIndex(function RuntimeNameCell({runtime,machineTitle,+ canEditVisibility,}: {runtime: AgentRuntime;+ /** Owner-only, the same rule as the detail page. */+ canEditVisibility: boolean;/*** The containing machine's title. Lets a per-runtime alias surface here* while a machine-level rename (shared by every runtime on the daemon)@@ -157,9 +154,9 @@ function RuntimeNameCell({<><RuntimeKindBadge runtime={runtime} /><PendingRuntimeBadge runtime={runtime} />- <VisibilityBadge runtime={runtime} /></>}+ trailing={<RuntimeListVisibility runtime={runtime} canEdit={canEditVisibility} />}/>);}@@ -203,30 +200,6 @@ function PendingRuntimeBadge({ runtime }: { runtime: AgentRuntime }) {);}-// Only public is worth a badge — private is the default and rendering a-// `🔒 Private` chip on every row turns the whole column into noise.-function VisibilityBadge({ runtime }: { runtime: AgentRuntime }) {- const { t } = useT("runtimes");- const scope = runtime.visibility === "public" ? "public" : "members";- if (scope === "members" && !runtime.shared_with?.length) return null;- const Icon = scope === "public" ? Globe : Users;- return (- <Tooltip>- <TooltipTrigger- render={- <span className="inline-flex shrink-0 items-center gap-0.5 rounded-xs bg-info/10 px-1 text-micro font-medium text-info">- <Icon className="h-2.5 w-2.5" />- {t(($) => $.detail.visibility_label[scope])}- </span>- }- />- <TooltipContent>- {t(($) => $.detail.visibility_hint_readonly[scope])}- </TooltipContent>- </Tooltip>- );-}-// Health with the load folded in as a "· N tasks" suffix — verbatim the// same form as the agents list's status cell, so the two surfaces speak// one language. The suffix is a unit-bearing count (running + queued);@@ -628,7 +601,19 @@ export function RuntimeList({{key: "name",header: t(($) => $.list.col_runtime),- cell: (row) => <RuntimeNameCell runtime={row.runtime} machineTitle={machineTitle} />,+ cell: (row) => (+ <RuntimeNameCell+ runtime={row.runtime}+ machineTitle={machineTitle}+ // Pending custom runtimes are client-side placeholders the server+ // cannot patch yet.+ canEditVisibility={+ !!user &&+ row.runtime.owner_id === user.id &&+ !isPendingCustomRuntime(row.runtime)+ }+ />+ ),},{// Health folds the workload in as a suffix ("Healthy · 2 tasks") —