Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(society): the card's action bar can retire the agent it is showing

rubenluetke10-beep361ab1cdead7
diff --git a/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx b/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx
index 6f58bf90bc..703b195633 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx
@@ -32,7 +32,7 @@
*/
import { useEffect, useState } from "react";
import * as Dialog from "@radix-ui/react-dialog";
-import { MessageSquare, Skull, User, X } from "lucide-react";
+import { MessageSquare, User, X } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
@@ -40,11 +40,12 @@ import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
import { AgentSwatch } from "../AgentSwatch";
-import { findLead, useRetireAgent, type SocietyAgent } from "../data";
+import type { SocietyAgent } from "../data";
import { AgentChatPanel } from "../chat/AgentChatPanel";
import { AgentFigureViewer } from "../figures/AgentFigureViewer";
import { RosterRail } from "../roster/RosterRail";
import { AgentSpecSheet } from "./AgentSpecSheet";
+import { RetireButton } from "./RetireButton";
/** Which face of the card is showing. */
type CardFace = "chat" | "profile";
@@ -170,7 +171,7 @@ export function AgentCardOverlay({
>
<AgentChatPanel agent={agent} roster={roster} />
</section>
- <OptionsRail agent={agent} roster={roster} onRetired={onClose} />
+ <OptionsRail agent={agent} onRetired={onClose} />
</>
) : (
<>
@@ -182,7 +183,7 @@ export function AgentCardOverlay({
aria-label={t("society.card.specs")}
data-testid="agent-card-specs"
>
- <AgentSpecSheet agent={agent} onOpenChat={() => setFace("chat")} />
+ <AgentSpecSheet agent={agent} onOpenChat={() => setFace("chat")} onRetired={onClose} />
</section>
<section
className="society-figure-column relative min-h-0"
@@ -206,17 +207,10 @@ export function AgentCardOverlay({
* The right eighth: what you can DO to this agent, as opposed to what you can
* say to it. Retirement is the only entry so far, and it sits at the bottom
* away from everything else — it is not a control anyone should reach for by
- * accident.
+ * accident. The same button is in the profile face's action bar; both go
+ * through `RetireButton`.
*/
-function OptionsRail({
- agent,
- roster,
- onRetired,
-}: {
- agent: SocietyAgent;
- roster: SocietyAgent[];
- onRetired: () => void;
-}) {
+function OptionsRail({ agent, onRetired }: { agent: SocietyAgent; onRetired: () => void }) {
const t = useT();
return (
<aside
@@ -231,80 +225,8 @@ function OptionsRail({
</div>
<p className="px-3 pt-2 text-xs text-muted-foreground">{t("society.card.options_hint")}</p>
<div className="mt-auto p-3">
- <RetireControl agent={agent} roster={roster} onRetired={onRetired} />
+ <RetireButton agent={agent} onRetired={onRetired} variant="rail" />
</div>
</aside>
);
}
-
-/**
- * Retire this agent. Two presses, because it cannot be taken back: the first
- * arms it, the second archives the row and sends the lead across the island
- * to do it in person. The card closes so the ceremony is visible.
- *
- * The lead itself is never retirable — the roster refuses to archive it
- * (`roster.archive`), so the button says so rather than failing at the API.
- */
-function RetireControl({
- agent,
- roster,
- onRetired,
-}: {
- agent: SocietyAgent;
- roster: SocietyAgent[];
- onRetired: () => void;
-}) {
- const t = useT();
- const retire = useRetireAgent();
- const [armed, setArmed] = useState(false);
- const [busy, setBusy] = useState(false);
- const [error, setError] = useState<string | null>(null);
-
- // Arming never survives a switch to another agent in the rail.
- useEffect(() => {
- setArmed(false);
- setError(null);
- }, [agent.agentId]);
-
- if (agent.tier === "lead") {
- return <p className="text-xs text-muted-foreground">{t("society.card.retire_lead_blocked")}</p>;
- }
-
- const run = async () => {
- if (!armed) {
- setArmed(true);
- return;
- }
- setBusy(true);
- setError(null);
- try {
- await retire(agent, findLead(roster));
- onRetired();
- } catch (err) {
- setError(err instanceof Error ? err.message : String(err));
- setArmed(false);
- } finally {
- setBusy(false);
- }
- };
-
- return (
- <div className="space-y-2">
- <Button
- size="sm"
- variant={armed ? "destructive" : "outline"}
- className="w-full gap-1.5"
- disabled={busy}
- onClick={() => void run()}
- data-testid="agent-card-retire"
- >
- <Skull className="h-3.5 w-3.5" aria-hidden />
- {armed ? t("society.card.retire_confirm") : t("society.card.retire")}
- </Button>
- <p className="text-xs text-muted-foreground">
- {armed ? t("society.card.retire_armed_hint") : t("society.card.retire_hint")}
- </p>
- {error && <p className="text-xs text-destructive">{error}</p>}
- </div>
- );
-}
diff --git a/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx b/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx
index ada445b27b..232cf244b5 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx
@@ -38,6 +38,7 @@ import { ScrollArea } from "@/components/ui/scroll-area";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
+import { RetireButton } from "./RetireButton";
import { CapabilityChip } from "../CapabilityChip";
import { useAgentActivity, useAgentRoutines, useAgentSkills, type AgentActivity } from "../cardData";
import {
@@ -195,9 +196,14 @@ export interface AgentSpecSheetProps {
* while the chat had no place of its own.
*/
onOpenChat?: () => void;
+ /**
+ * The agent was retired: the card closes so the island's ceremony
+ * (`world/retirement.ts`) is actually visible behind it.
+ */
+ onRetired?: () => void;
}
-export function AgentSpecSheet({ agent, onOpenChat }: AgentSpecSheetProps) {
+export function AgentSpecSheet({ agent, onOpenChat, onRetired }: AgentSpecSheetProps) {
const t = useT();
const capabilities = useSocietyCapabilities();
const activity = useAgentActivity(agent.agentId);
@@ -490,6 +496,8 @@ export function AgentSpecSheet({ agent, onOpenChat }: AgentSpecSheetProps) {
{paused ? <Play className="h-3.5 w-3.5" aria-hidden /> : <Pause className="h-3.5 w-3.5" aria-hidden />}
{paused ? t("society.card.action_resume") : t("society.card.action_pause")}
</button>
+ {/* Last, and on its own: pausing is a Tuesday, retiring is forever. */}
+ <RetireButton agent={agent} onRetired={onRetired} />
</div>
</div>
);
diff --git a/jarvis/ui/web/frontend/src/components/society/card/RetireButton.test.tsx b/jarvis/ui/web/frontend/src/components/society/card/RetireButton.test.tsx
new file mode 100644
index 0000000000..3e6c2553e4
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/RetireButton.test.tsx
@@ -0,0 +1,127 @@
+/**
+ * The safety properties of the one irreversible control on the card.
+ *
+ * Not the ceremony (that is `world/retirement.test.ts`) and not the styling —
+ * only the three things that would let someone delete an agent they did not
+ * mean to: a single press doing it, an armed button waiting around, and the
+ * lead being offered at all.
+ */
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+
+import { RetireButton } from "@/components/society/card/RetireButton";
+import type { SocietyAgent } from "@/components/society/data";
+
+function agent(over: Partial<SocietyAgent> = {}): SocietyAgent {
+ return {
+ agentId: "scout",
+ name: "Scout",
+ title: "Research coordinator",
+ description: "",
+ tier: "specialist",
+ provider: "",
+ providerLabel: "",
+ model: "",
+ effort: "",
+ figure: null,
+ palette: { primary: "#2f6f4f", secondary: "#8a5a3b", accent: "#ffd166" },
+ grantMode: "all",
+ toolGrants: [],
+ focus: [],
+ denies: [],
+ approvalRules: { requireApproval: [], alwaysAllow: [] },
+ permissionCeiling: "safe",
+ dailyBudgetUsd: 0,
+ checkpoint: "idle",
+ state: "idle",
+ lifecycle: "active",
+ createdMs: 0,
+ chatSessionId: null,
+ routines: [],
+ stats: { runs: 0, totalCostUsd: 0, spentTodayUsd: 0, lastActiveMs: null },
+ ...over,
+ } as SocietyAgent;
+}
+
+function mount(node: React.ReactElement) {
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ return render(<QueryClientProvider client={client}>{node}</QueryClientProvider>);
+}
+
+const button = () => screen.getByTestId("agent-card-retire");
+
+/** Every DELETE the component fired — the roster GET it mounts with is fine. */
+function deletes(): unknown[] {
+ const mock = fetch as unknown as { mock: { calls: [string, RequestInit?][] } };
+ return mock.mock.calls.filter(([, init]) => init?.method === "DELETE");
+}
+
+describe("RetireButton", () => {
+ beforeEach(() => {
+ vi.useFakeTimers({ shouldAdvanceTime: true });
+ // The roster query mounts with the component and is answered honestly;
+ // a DELETE, on the other hand, would mean the arming logic let one
+ // through, and `deletes()` below makes that loud rather than silent.
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () => ({
+ ok: true,
+ status: 200,
+ json: async () => ({ agents: [] }),
+ })),
+ );
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ vi.useRealTimers();
+ });
+
+ test("one press only arms it — the agent is not retired yet", () => {
+ const onRetired = vi.fn();
+ mount(<RetireButton agent={agent()} onRetired={onRetired} />);
+
+ expect(button().dataset.armed).toBeUndefined();
+ fireEvent.click(button());
+ expect(button().dataset.armed).toBe("true");
+ expect(onRetired).not.toHaveBeenCalled();
+ expect(deletes()).toHaveLength(0);
+ });
+
+ test("an armed button disarms itself, so a card left open is not a loaded gun", () => {
+ mount(<RetireButton agent={agent()} />);
+ fireEvent.click(button());
+ expect(button().dataset.armed).toBe("true");
+
+ act(() => {
+ vi.advanceTimersByTime(6_100);
+ });
+ expect(button().dataset.armed).toBeUndefined();
+ });
+
+ test("the lead cannot be retired, and the button says so instead of failing at the API", () => {
+ mount(<RetireButton agent={agent({ agentId: "jarvis", name: "Jarvis", tier: "lead" })} />);
+ const el = button() as HTMLButtonElement;
+ expect(el.disabled).toBe(true);
+
+ fireEvent.click(el);
+ expect(el.dataset.armed).toBeUndefined();
+ expect(deletes()).toHaveLength(0);
+ });
+
+ test("switching to another agent in the rail drops the armed state", () => {
+ const { rerender } = mount(<RetireButton agent={agent()} variant="rail" />);
+ fireEvent.click(button());
+ expect(button().dataset.armed).toBe("true");
+
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ rerender(
+ <QueryClientProvider client={client}>
+ <RetireButton agent={agent({ agentId: "archivist", name: "Archivist" })} variant="rail" />
+ </QueryClientProvider>,
+ );
+ expect(button().dataset.armed).toBeUndefined();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/card/RetireButton.tsx b/jarvis/ui/web/frontend/src/components/society/card/RetireButton.tsx
new file mode 100644
index 0000000000..326730bdca
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/card/RetireButton.tsx
@@ -0,0 +1,146 @@
+/**
+ * Retire this agent — the one control on the card that cannot be taken back.
+ *
+ * It lives in two places and must behave identically in both: the profile
+ * face's action bar (beside Pause, where someone managing an agent looks for
+ * it) and the chat face's options rail. Hence one component rather than two
+ * copies of the confirmation logic.
+ *
+ * Three things it does deliberately:
+ *
+ * - it ARMS rather than asking. The first press turns the button into a red
+ * "confirm", the second does it. A modal for this would be one more dialog
+ * on top of a card that is already a dialog;
+ * - it DISARMS itself after a few seconds. A button left armed on a card
+ * someone walks away from is a delete waiting to happen;
+ * - the lead is not retirable and the button says so instead of failing at
+ * the API: `roster.archive` refuses it (the society has exactly one lead,
+ * MASTERPLAN §2.5), so there is nothing to try.
+ *
+ * Pressing it archives the row and then hands the island the execution
+ * (`world/retirement.ts`); the card closes so the ceremony is visible.
+ */
+import { useEffect, useRef, useState } from "react";
+import { Skull } from "lucide-react";
+
+import { useT } from "@/i18n";
+import { cn } from "@/lib/utils";
+
+import { findLead, useRetireAgent, useSocietyRoster, type SocietyAgent } from "../data";
+
+/** An armed button falls back to safe after this long, in ms. */
+const DISARM_MS = 6_000;
+
+export interface RetireButtonProps {
+ agent: SocietyAgent;
+ /** Called once the row is archived — the card closes so the island is visible. */
+ onRetired?: () => void;
+ /**
+ * `bar` is the profile face's action row: one button, everything else in its
+ * tooltip. `rail` is the chat face's options column, which has room for the
+ * sentence explaining what the button does.
+ */
+ variant?: "bar" | "rail";
+}
+
+export function RetireButton({ agent, onRetired, variant = "bar" }: RetireButtonProps) {
+ const t = useT();
+ const roster = useSocietyRoster();
+ const retire = useRetireAgent();
+ const [armed, setArmed] = useState(false);
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const disarm = useRef<ReturnType<typeof setTimeout> | null>(null);
+
+ const isLead = agent.tier === "lead";
+
+ // Never stay armed: not across a switch to another agent in the rail, not
+ // after the card is closed, and not while someone is reading the rest of it.
+ useEffect(() => {
+ setArmed(false);
+ setError(null);
+ }, [agent.agentId]);
+
+ useEffect(() => {
+ if (!armed) return;
+ disarm.current = setTimeout(() => setArmed(false), DISARM_MS);
+ return () => {
+ if (disarm.current) clearTimeout(disarm.current);
+ disarm.current = null;
+ };
+ }, [armed]);
+
+ if (isLead) {
+ if (variant === "rail") {
+ return <p className="text-xs text-muted-foreground">{t("society.card.retire_lead_blocked")}</p>;
+ }
+ return (
+ <button
+ type="button"
+ className="ac-btn"
+ disabled
+ title={t("society.card.retire_lead_blocked")}
+ data-testid="agent-card-retire"
+ >
+ <Skull className="h-3.5 w-3.5" aria-hidden />
+ {t("society.card.retire")}
+ </button>
+ );
+ }
+
+ const run = async () => {
+ if (!armed) {
+ setArmed(true);
+ setError(null);
+ return;
+ }
+ setBusy(true);
+ setError(null);
+ try {
+ await retire(agent, findLead(roster.data?.agents ?? []));
+ onRetired?.();
+ } catch (err) {
+ setError(err instanceof Error ? err.message : String(err));
+ setArmed(false);
+ } finally {
+ setBusy(false);
+ }
+ };
+
+ const label = armed ? t("society.card.retire_confirm") : t("society.card.retire");
+ const hint = armed ? t("society.card.retire_armed_hint") : t("society.card.retire_hint");
+
+ const button = (
+ <button
+ type="button"
+ className={cn("ac-btn", variant === "rail" && "w-full justify-center")}
+ data-armed={armed || undefined}
+ disabled={busy}
+ title={error ?? hint}
+ onClick={() => void run()}
+ data-testid="agent-card-retire"
+ >
+ <Skull className="h-3.5 w-3.5" aria-hidden />
+ {label}
+ </button>
+ );
+
+ if (variant === "bar") {
+ return (
+ <>
+ {error && <span className="ac-retire-error">{error}</span>}
+ {button}
+ </>
+ );
+ }
+
+ return (
+ <div className="space-y-2">
+ {button}
+ <p className="text-xs text-muted-foreground">{hint}</p>
+ {error && <p className="text-xs text-destructive">{error}</p>}
+ </div>
+ );
+}
+
+export default RetireButton;
diff --git a/jarvis/ui/web/frontend/src/components/society/card/agentCard.css b/jarvis/ui/web/frontend/src/components/society/card/agentCard.css
index 2075489891..1188c2e8a3 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/agentCard.css
+++ b/jarvis/ui/web/frontend/src/components/society/card/agentCard.css
@@ -328,3 +328,24 @@
transform: none;
}
}
+
+/* Retiring an agent is the one action on the card that cannot be undone, so
+ the second press is coloured like what it is. `--destructive` stays a real
+ colour in both appearances (Ink & Paper keeps it), and the text token comes
+ with it so the label survives light mode. */
+.ac-btn[data-armed] {
+ color: hsl(var(--destructive-foreground));
+ background: hsl(var(--destructive));
+ border-color: hsl(var(--destructive));
+}
+.ac-btn[data-armed]:hover:not(:disabled) {
+ background: hsl(var(--destructive) / 0.88);
+}
+.ac-retire-error {
+ margin-left: auto;
+ font-size: 12px;
+ color: hsl(var(--destructive));
+}
+.ac-retire-error + .ac-btn {
+ margin-left: 8px;
+}