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): editing the description no longer wipes focus and approval rules; the card can edit it

rubenluetke10-beepe845f74c7b33
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 26fc122609..6cc8ea7fa6 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx
@@ -34,6 +34,7 @@ import { CapabilityChip } from "../CapabilityChip";
import {
useSetAgentPaused,
useSocietyCapabilities,
+ useUpdateAgentDescription,
type AgentRunState,
type Capability,
type PermissionCeiling,
@@ -57,6 +58,88 @@ const STATE_FILL: Record<AgentRunState, string> = {
const REACH_STEPS = 6;
+/**
+ * The agent's standing instructions, editable in place. The chat is the main
+ * way rules arrive (the agent proposes, the person confirms), but a person may
+ * also write them directly; the PATCH keeps the focus and approval rules the
+ * agent earned.
+ */
+function DescriptionEditor({ agent }: { agent: SocietyAgent }) {
+ const t = useT();
+ const update = useUpdateAgentDescription();
+ const [editing, setEditing] = useState(false);
+ const [draft, setDraft] = useState(agent.description);
+ const [saving, setSaving] = useState(false);
+ const [error, setError] = useState("");
+ const begin = () => {
+ setDraft(agent.description);
+ setError("");
+ setEditing(true);
+ };
+ const save = async () => {
+ setSaving(true);
+ setError("");
+ try {
+ await update(agent, draft.trim());
+ setEditing(false);
+ } catch (err) {
+ setError(err instanceof Error ? err.message : String(err));
+ } finally {
+ setSaving(false);
+ }
+ };
+ return (
+ <>
+ <div className="mb-2 flex items-center justify-between gap-2">
+ <h3 className="ac-head">{t("society.card.description")}</h3>
+ {editing ? null : (
+ <button
+ type="button"
+ onClick={begin}
+ className="rounded-full border border-border px-2 py-0.5 text-xs text-muted-foreground hover:bg-secondary hover:text-foreground"
+ >
+ {t("society.card.edit")}
+ </button>
+ )}
+ </div>
+ {editing ? (
+ <div className="flex flex-col gap-2">
+ <textarea
+ value={draft}
+ onChange={(e) => setDraft(e.target.value)}
+ rows={Math.min(14, Math.max(4, draft.split("\n").length + 1))}
+ disabled={saving}
+ className="w-full resize-y rounded-md border border-border bg-background px-2.5 py-2 text-sm leading-relaxed text-foreground outline-none focus:border-primary"
+ />
+ <div className="flex items-center gap-2">
+ <button
+ type="button"
+ disabled={saving}
+ onClick={() => void save()}
+ className="rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50"
+ >
+ {saving ? t("society.card.saving") : t("society.card.save")}
+ </button>
+ <button
+ type="button"
+ disabled={saving}
+ onClick={() => setEditing(false)}
+ className="rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground hover:bg-muted disabled:opacity-50"
+ >
+ {t("society.card.cancel")}
+ </button>
+ {error ? <span className="text-xs text-destructive">{error}</span> : null}
+ </div>
+ </div>
+ ) : agent.description ? (
+ <p className="whitespace-pre-line text-sm leading-relaxed">{agent.description}</p>
+ ) : (
+ <p className="text-xs text-muted-foreground">{t("society.card.no_description")}</p>
+ )}
+ </>
+ );
+}
+
function formatDate(ms: number | null, fallback: string): string {
if (ms === null) return fallback;
return new Date(ms).toLocaleDateString(undefined, { day: "2-digit", month: "short", year: "numeric" });
@@ -229,14 +312,7 @@ export function AgentSpecSheet({ agent, onOpenChat }: AgentSpecSheetProps) {
{agent.tier === "lead" ? (
<LeadInstructions />
) : (
- <>
- <h3 className="ac-head mb-2">{t("society.card.description")}</h3>
- {agent.description ? (
- <p className="whitespace-pre-line text-sm leading-relaxed">{agent.description}</p>
- ) : (
- <p className="text-xs text-muted-foreground">{t("society.card.no_description")}</p>
- )}
- </>
+ <DescriptionEditor agent={agent} />
)}
</section>
diff --git a/jarvis/ui/web/frontend/src/components/society/data.ts b/jarvis/ui/web/frontend/src/components/society/data.ts
index 6ca58c60d9..d03e54c66e 100644
--- a/jarvis/ui/web/frontend/src/components/society/data.ts
+++ b/jarvis/ui/web/frontend/src/components/society/data.ts
@@ -421,6 +421,32 @@ export function useResolveProposal() {
);
}
+/**
+ * Edit an agent's standing instructions (`PATCH /api/society/agents/{id}` with
+ * the description only). The route keeps the focus and approval rules the
+ * agent earned in its chat.
+ */
+export function useUpdateAgentDescription() {
+ const client = useQueryClient();
+ return useCallback(
+ async (agent: SocietyAgent, description: string): Promise<void> => {
+ const sample = SAMPLE_ROSTER.includes(agent) || LOCAL_ROSTER.includes(agent);
+ if (!sample) {
+ const res = await fetch(`/api/society/agents/${encodeURIComponent(agent.agentId)}`, {
+ method: "PATCH",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ description }),
+ });
+ if (!res.ok) throw new Error(`description ${res.status}`);
+ } else {
+ agent.description = description;
+ }
+ await client.invalidateQueries({ queryKey: ROSTER_QUERY_KEY });
+ },
+ [client],
+ );
+}
+
/** Pause or resume an agent (`PATCH /api/society/agents/{id}`); sample rows flip locally. */
export function useSetAgentPaused() {
const client = useQueryClient();
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index cbce47eb18..c5c8ac298d 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -5309,7 +5309,8 @@
"never": "nie",
"chat_empty_title": "Noch kein Gespräch",
"chat_empty_hint": "Der Chat des Agenten öffnet sich hier, sobald das Society-Backend seine Sitzung anbindet.",
- "chat_bind_failed": "Der Chat konnte nicht verbunden werden."
+ "chat_bind_failed": "Der Chat konnte nicht verbunden werden.",
+ "cancel": "Abbrechen"
},
"figure": {
"drag_hint": "Ziehen zum Drehen und Kippen · Rad zum Zoomen · Doppelklick setzt zurück",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index aacbe984a4..8e8753b713 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -5342,7 +5342,8 @@
"never": "never",
"chat_empty_title": "No conversation yet",
"chat_empty_hint": "The agent's chat opens here once the society backend binds its session.",
- "chat_bind_failed": "The chat could not be bound."
+ "chat_bind_failed": "The chat could not be bound.",
+ "cancel": "Cancel"
},
"figure": {
"drag_hint": "Drag to turn and tilt · wheel to zoom · double-click to reset",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index c234a6df4a..ac34da431e 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -5309,7 +5309,8 @@
"never": "nunca",
"chat_empty_title": "Aún no hay conversación",
"chat_empty_hint": "El chat del agente se abre aquí cuando el backend de la sociedad vincule su sesión.",
- "chat_bind_failed": "No se pudo vincular el chat."
+ "chat_bind_failed": "No se pudo vincular el chat.",
+ "cancel": "Cancelar"
},
"figure": {
"drag_hint": "Arrastra para girar e inclinar · rueda para acercar · doble clic restablece",
diff --git a/jarvis/ui/web/society_routes.py b/jarvis/ui/web/society_routes.py
index 7d1d84715b..893ba105a3 100644
--- a/jarvis/ui/web/society_routes.py
+++ b/jarvis/ui/web/society_routes.py
@@ -209,11 +209,21 @@ async def patch_agent(agent_id: str, body: PatchAgentBody, request: Request) ->
raise HTTPException(404, {"reason": str(FailureReason.TARGET_UNKNOWN)})
fields = body.model_dump(exclude_none=True)
if ("title" in fields or "description" in fields) and "focus" not in fields:
+ # A prose edit must not wipe what the agent earned in its chat: the
+ # derived focus is APPENDED to the existing order (existing first,
+ # deduped) and derived approval rules are written only when the agent
+ # has none — a person editing the description never silently loses the
+ # rules they confirmed on a card.
title = fields.get("title", agent.title)
description = fields.get("description", agent.description)
derived_focus, derived_rules = rt.derive(title, description)
- fields["focus"] = derived_focus
- if "approval_rules" not in fields and derived_rules["require_approval"]:
+ merged_focus = list(agent.focus)
+ for cap_id in derived_focus:
+ if cap_id not in merged_focus:
+ merged_focus.append(cap_id)
+ fields["focus"] = merged_focus
+ has_rules = any(agent.approval_rules.get(k) for k in ("require_approval", "always_allow"))
+ if "approval_rules" not in fields and not has_rules and derived_rules["require_approval"]:
fields["approval_rules"] = derived_rules
try:
updated = await rt.roster.update(agent.agent_id, fields)
diff --git a/tests/unit/ui/test_society_routes.py b/tests/unit/ui/test_society_routes.py
new file mode 100644
index 0000000000..03b139bdf1
--- /dev/null
+++ b/tests/unit/ui/test_society_routes.py
@@ -0,0 +1,102 @@
+"""The society REST surface, headless: a description edit keeps what the agent
+earned in its chat, and a configuration proposal is applied only by its own route."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from types import SimpleNamespace
+
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
+from jarvis.society.runtime import SocietyRuntime
+from jarvis.ui.web.society_routes import router
+
+
+def _tool(name: str, desc: str) -> SimpleNamespace:
+ return SimpleNamespace(name=name, description=desc, risk_tier="monitor")
+
+
+TOOLS = {
+ "gmail": _tool("gmail", "Read and send mail."),
+ "google-calendar": _tool("google-calendar", "Read the calendar."),
+ "cli_gh": _tool("cli_gh", "GitHub CLI."),
+}
+
+
+def _app(tmp_path: Path) -> tuple[FastAPI, SocietyRuntime]:
+ runtime = SocietyRuntime(tmp_path, seed_starter_team=False, brain_tools=lambda: TOOLS)
+ app = FastAPI()
+ app.include_router(router)
+ app.state.society_factory = lambda: runtime
+ return app, runtime
+
+
+def test_a_description_patch_keeps_the_focus_and_rules_the_agent_earned(tmp_path: Path) -> None:
+ app, _ = _app(tmp_path)
+ with TestClient(app) as c:
+ created = c.post(
+ "/api/society/agents",
+ json={
+ "name": "Mailbox",
+ "title": "Gmail agent",
+ "description": "Handle my mail.",
+ "focus": ["cli:gh", "plugin:gmail"],
+ "approval_rules": {"require_approval": [], "always_allow": ["plugin:gmail:send"]},
+ },
+ ).json()["agent"]
+ assert created["focus"] == ["cli:gh", "plugin:gmail"]
+
+ # A prose edit that mentions the calendar: focus grows, order and rules stay.
+ patched = c.patch(
+ "/api/society/agents/mailbox",
+ json={
+ "description": "Handle my mail and my calendar; external mail only after approval."
+ },
+ ).json()["agent"]
+ assert patched["focus"][:2] == ["cli:gh", "plugin:gmail"]
+ assert "plugin:google-calendar" in patched["focus"]
+ assert patched["approval_rules"] == {
+ "require_approval": [],
+ "always_allow": ["plugin:gmail:send"],
+ }
+
+ # An agent with NO rules still gets the derived ones from an approval clause.
+ c.post("/api/society/agents", json={"name": "Planner", "title": "Calendar agent"})
+ planner = c.patch(
+ "/api/society/agents/planner",
+ json={"description": "Manage my calendar; invitations only after approval."},
+ ).json()["agent"]
+ assert planner["approval_rules"]["require_approval"]
+
+
+def test_a_proposal_is_applied_only_by_its_own_route(tmp_path: Path) -> None:
+ app, runtime = _app(tmp_path)
+ with TestClient(app) as c:
+ c.post("/api/society/agents", json={"name": "Mailbox", "description": "Handle my mail."})
+ # Park a proposal the way the tool does (validated payload, config capability).
+ item = c.post(
+ "/api/society/approvals",
+ json={
+ "agent_id": "mailbox",
+ "capability": "core:config:rule",
+ "action": {"kind": "rule", "payload": {"text": "Be brief."}, "reason": "t"},
+ "summary": "Add a standing rule: Be brief.",
+ },
+ ).json()["approval"]
+ listed = c.get("/api/society/proposals").json()
+ assert [p["id"] for p in listed["proposals"]] == [item["id"]]
+ generic = c.post(f"/api/society/approvals/{item['id']}/resolve", json={"approve": True})
+ assert generic.status_code == 409
+ resolved = c.post(f"/api/society/proposals/{item['id']}/resolve", json={"approve": True})
+ assert resolved.status_code == 200, resolved.text
+ body = resolved.json()
+ assert body["applied"] is True and body["kind"] == "rule"
+ agent = c.get("/api/society/agents/mailbox").json()["agent"]
+ assert agent["description"] == "Handle my mail.\n\nBe brief."
+ assert c.get("/api/society/proposals").json()["total"] == 0
+ again = c.post(f"/api/society/proposals/{item['id']}/resolve", json={"approve": True})
+ assert again.status_code == 409
+ missing = c.post("/api/society/proposals/nope/resolve", json={"approve": True})
+ assert missing.status_code == 404
+ assert runtime is not None