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.

fix(society): restore last selected agent

rubenluetke10-beep37dc39913ea5
diff --git a/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx b/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx
index 8626881442..d840652eb5 100644
--- a/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx
@@ -2,6 +2,7 @@ import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, expect, it, vi } from "vitest";
import { useSocietyShell } from "@/store/societyShell";
import { setMapFullscreen } from "@/lib/mapFullscreen";
+import { LAST_AGENT_STORAGE_KEY } from "./lastAgent";
import { SocietyView } from "./SocietyView";
vi.mock("@/lib/mapFullscreen", () => ({ setMapFullscreen: vi.fn(async () => undefined) }));
@@ -25,7 +26,10 @@ vi.mock("@/components/society/roster/RosterRail", () => ({ RosterRail: () => <di
vi.mock("@/components/society/card/BuildingCardOverlay", () => ({ BuildingCardOverlay: () => null }));
vi.mock("@/components/society/create/CreateAgentDialog", () => ({ CreateAgentDialog: ({ open, onClose }: any) => open ? <button onClick={onClose}>Close creator</button> : null }));
-afterEach(cleanup);
+afterEach(() => {
+ cleanup();
+ localStorage.removeItem(LAST_AGENT_STORAGE_KEY);
+});
it("defaults to the embedded Agents workspace even with a saved legacy ledger preference", () => {
localStorage.setItem("jarvis.agents.mode.v2", "ledger");
@@ -50,6 +54,17 @@ it("switches to Map and back without losing the selected agent or draft", async
expect(draft.value).toBe("Unsent message");
});
+it("restores the most recently selected agent after the view is remounted", () => {
+ const firstVisit = render(<SocietyView />);
+ fireEvent.click(screen.getByText("Select specialist"));
+ expect(localStorage.getItem(LAST_AGENT_STORAGE_KEY)).toBe("specialist");
+
+ firstVisit.unmount();
+ render(<SocietyView />);
+
+ expect(screen.getByText("Specialist")).toBeTruthy();
+});
+
it("opens map selections in Agents and keeps creation available", async () => {
render(<SocietyView />);
fireEvent.click(screen.getByRole("tab", { name: "society.world.mode_map" }));
diff --git a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
index 4abb542e65..cec17e67f8 100644
--- a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
+++ b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
@@ -16,6 +16,7 @@ import { useSocietyRoster } from "@/components/society/data";
import { RosterRail } from "@/components/society/roster/RosterRail";
import { useModelMenuData } from "@/components/society/chat/useModelMenuData";
import { CanvasActivity } from "@/hooks/useCanvasAwake";
+import { forgetLastAgentId, rememberLastAgentId, storedLastAgentId } from "./lastAgent";
const JarvisAgentsBoard = lazy(() =>
import("@/views/JarvisAgentsView").then((m) => ({ default: m.JarvisAgentsView })),
@@ -29,7 +30,7 @@ export function SocietyView() {
const roster = useSocietyRoster();
const agents = useMemo(() => roster.data?.agents ?? [], [roster.data]);
const sample = roster.data?.sample ?? true;
- const [openAgentId, setOpenAgentId] = useState<string | null>(null);
+ const [openAgentId, setOpenAgentId] = useState<string | null>(storedLastAgentId);
const [creating, setCreating] = useState(false);
const [openPlace, setOpenPlace] = useState<BuildingPlace | null>(null);
@@ -38,6 +39,18 @@ export function SocietyView() {
[agents, openAgentId],
);
+ const selectAgent = useCallback((agentId: string | null) => {
+ setOpenAgentId(agentId);
+ if (agentId) rememberLastAgentId(agentId);
+ }, []);
+
+ useEffect(() => {
+ if (openAgentId && agents.length > 0 && !agents.some((agent) => agent.agentId === openAgentId)) {
+ setOpenAgentId(null);
+ forgetLastAgentId();
+ }
+ }, [agents, openAgentId]);
+
const onCreated = useCallback(() => {
setCreating(false);
}, []);
@@ -79,10 +92,10 @@ export function SocietyView() {
const onIslandSelect = useCallback((agentId: string | null) => {
if (agentId) {
- setOpenAgentId(agentId);
+ selectAgent(agentId);
switchMode("agents");
}
- }, [switchMode]);
+ }, [selectAgent, switchMode]);
// A building clicked on the island opens its own card: the building
// rendered as it stands on the map, and beside it what it does.
@@ -138,11 +151,11 @@ export function SocietyView() {
<div className={mode === "agents" ? "flex min-h-0 flex-1 flex-col" : "hidden"}>
{openAgent ? (
<AgentCardOverlay embedded agent={openAgent} roster={agents} rosterLoading={roster.isLoading}
- sample={sample} onSelectAgent={setOpenAgentId} onCreate={() => setCreating(true)}
+ sample={sample} onSelectAgent={selectAgent} onCreate={() => setCreating(true)}
onClose={() => setOpenAgentId(null)} />
) : (
<RosterRail agents={agents} loading={roster.isLoading} sample={sample}
- activeAgentId={null} onOpen={setOpenAgentId} onCreate={() => setCreating(true)} side="left" />
+ activeAgentId={null} onOpen={selectAgent} onCreate={() => setCreating(true)} side="left" />
)}
</div>
</div>
diff --git a/jarvis/ui/web/frontend/src/views/society/lastAgent.ts b/jarvis/ui/web/frontend/src/views/society/lastAgent.ts
new file mode 100644
index 0000000000..1c3ccadfd5
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/society/lastAgent.ts
@@ -0,0 +1,31 @@
+const LAST_AGENT_KEY = "jarvis.society.lastAgent";
+
+/** Read the most recently opened Society agent, if browser storage is available. */
+export function storedLastAgentId(): string | null {
+ try {
+ return window.localStorage.getItem(LAST_AGENT_KEY);
+ } catch {
+ // A disabled browser storage must not prevent the Agents view from opening.
+ return null;
+ }
+}
+
+/** Persist the latest explicit agent selection across section visits and app launches. */
+export function rememberLastAgentId(agentId: string): void {
+ try {
+ window.localStorage.setItem(LAST_AGENT_KEY, agentId);
+ } catch {
+ /* The selection remains available for this visit when storage is unavailable. */
+ }
+}
+
+/** Remove a remembered agent that no longer exists in the roster. */
+export function forgetLastAgentId(): void {
+ try {
+ window.localStorage.removeItem(LAST_AGENT_KEY);
+ } catch {
+ /* Nothing to do when storage is unavailable. */
+ }
+}
+
+export const LAST_AGENT_STORAGE_KEY = LAST_AGENT_KEY;