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): let the daily budget cap be switched off

rubenluetke10-beepe6a226e1f105
diff --git a/jarvis/ui/web/frontend/src/components/society/card/AgentLimits.test.tsx b/jarvis/ui/web/frontend/src/components/society/card/AgentLimits.test.tsx
index 6d2b678430..20216b16f4 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/AgentLimits.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentLimits.test.tsx
@@ -48,13 +48,13 @@ const AGENT: SocietyAgent = {
stats: { runs: 0, totalCostUsd: 0, spentTodayUsd: 0, lastActiveMs: null },
};
-function renderCard() {
+function renderCard(over: Partial<SocietyAgent> = {}) {
const client = new QueryClient({
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
});
return render(
<QueryClientProvider client={client}>
- <AgentSpecSheet agent={AGENT} />
+ <AgentSpecSheet agent={{ ...AGENT, ...over }} />
</QueryClientProvider>,
);
}
@@ -114,4 +114,36 @@ describe("the card's limits", () => {
expect(JSON.parse(String(patch?.[1]?.body)).daily_budget_usd).toBe(0);
});
});
+
+ test("switching the cap off sends 0, which is the scheduler's no-cap", async () => {
+ renderCard();
+ fireEvent.click(await screen.findByTestId("agent-limits-edit"));
+ fireEvent.click(screen.getByTestId("agent-budget-switch"));
+ expect(screen.queryByTestId("agent-budget-input")).toBeNull();
+ fireEvent.click(screen.getByText("Save"));
+
+ await waitFor(() => {
+ const patch = fetchMock.mock.calls.find((c) => c[1]?.method === "PATCH");
+ expect(JSON.parse(String(patch?.[1]?.body)).daily_budget_usd).toBe(0);
+ });
+ });
+
+ test("a stored 0 reads as the cap switched off, and turning it on restores a number", async () => {
+ renderCard({ dailyBudgetUsd: 0 });
+ await waitFor(() => expect(screen.getByTestId("agent-limits-edit")).toBeTruthy());
+ expect(screen.getByTestId("agent-card-sheet").textContent).toContain("no cap");
+
+ fireEvent.click(screen.getByTestId("agent-limits-edit"));
+ expect(screen.getByTestId("agent-budget-switch").getAttribute("aria-checked")).toBe("false");
+ expect(screen.queryByTestId("agent-budget-input")).toBeNull();
+
+ fireEvent.click(screen.getByTestId("agent-budget-switch"));
+ expect(screen.getByTestId("agent-budget-input")).toBeTruthy();
+ fireEvent.click(screen.getByText("Save"));
+
+ await waitFor(() => {
+ const patch = fetchMock.mock.calls.find((c) => c[1]?.method === "PATCH");
+ expect(JSON.parse(String(patch?.[1]?.body)).daily_budget_usd).toBe(2);
+ });
+ });
});
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 6caf8b1103..dafb298f33 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentSpecSheet.tsx
@@ -35,6 +35,7 @@ import { MessageSquare, Pause, Play } from "lucide-react";
import { ProviderLogo } from "@/components/providers/ProviderLogo";
import { ScrollArea } from "@/components/ui/scroll-area";
+import { Switch } from "@/components/ui/switch";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
@@ -517,11 +518,15 @@ function LimitsSection({
const [error, setError] = useState("");
const [ceiling, setCeiling] = useState<PermissionCeiling>(agent.permissionCeiling);
const [budget, setBudget] = useState(String(agent.dailyBudgetUsd));
+ // The stored 0 IS 'no cap' (the scheduler skips the gate), so the switch
+ // reads it back rather than asking the person to know that.
+ const [budgetOn, setBudgetOn] = useState(agent.dailyBudgetUsd > 0);
const [jobs, setJobs] = useState(String(agent.maxConcurrentRuns));
const begin = () => {
setCeiling(agent.permissionCeiling);
- setBudget(String(agent.dailyBudgetUsd));
+ setBudget(String(agent.dailyBudgetUsd || 2));
+ setBudgetOn(agent.dailyBudgetUsd > 0);
setJobs(String(agent.maxConcurrentRuns));
setError("");
setEditing(true);
@@ -532,7 +537,7 @@ function LimitsSection({
try {
await update(agent, {
permissionCeiling: ceiling,
- dailyBudgetUsd: Number.parseFloat(budget) || 0,
+ dailyBudgetUsd: budgetOn ? Math.max(0, Number.parseFloat(budget) || 0) : 0,
maxConcurrentRuns: Number.parseInt(jobs, 10) || 1,
});
setEditing(false);
@@ -585,20 +590,33 @@ function LimitsSection({
</div>
<div className="flex flex-wrap items-end gap-4">
- <label className="flex flex-col gap-1">
- <span className="text-xs text-muted-foreground">{t("society.create.budget")}</span>
- <input
- type="number"
- min={0}
- step={0.5}
- inputMode="decimal"
- disabled={saving}
- value={budget}
- onChange={(e) => setBudget(e.target.value)}
- data-testid="agent-budget-input"
- className="w-28 rounded-md border border-border bg-background px-2 py-1 font-mono text-sm text-foreground outline-none focus:border-primary disabled:opacity-50"
- />
- </label>
+ <div className="flex flex-col gap-1">
+ <span className="flex items-center gap-2 text-xs text-muted-foreground">
+ <Switch
+ checked={budgetOn}
+ onCheckedChange={setBudgetOn}
+ disabled={saving}
+ aria-label={t("society.card.budget_cap")}
+ data-testid="agent-budget-switch"
+ />
+ {t("society.card.budget_cap")}
+ </span>
+ {budgetOn ? (
+ <input
+ type="number"
+ min={0}
+ step={0.5}
+ inputMode="decimal"
+ disabled={saving}
+ value={budget}
+ onChange={(e) => setBudget(e.target.value)}
+ data-testid="agent-budget-input"
+ className="w-28 rounded-md border border-border bg-background px-2 py-1 font-mono text-sm text-foreground outline-none focus:border-primary disabled:opacity-50"
+ />
+ ) : (
+ <span className="py-1 text-sm text-muted-foreground">{t("society.card.no_cap")}</span>
+ )}
+ </div>
<label className="flex flex-col gap-1">
<span className="text-xs text-muted-foreground">{t("society.card.jobs_at_once")}</span>
<input
@@ -613,7 +631,9 @@ function LimitsSection({
/>
</label>
</div>
- <p className="text-xs text-muted-foreground">{t("society.card.budget_hint")}</p>
+ <p className="text-xs text-muted-foreground">
+ {budgetOn ? t("society.card.budget_hint") : t("society.card.budget_off_hint")}
+ </p>
<div className="flex items-center gap-2">
<button
diff --git a/jarvis/ui/web/frontend/src/components/society/create/CreateAgentDialog.tsx b/jarvis/ui/web/frontend/src/components/society/create/CreateAgentDialog.tsx
index c743210b12..430ebd661a 100644
--- a/jarvis/ui/web/frontend/src/components/society/create/CreateAgentDialog.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/create/CreateAgentDialog.tsx
@@ -9,7 +9,8 @@
* plan, not per token), then saved API keys, then local models, with the
* login to use when a CLI has more than one, the model (a keyed row's live
* list, Ollama's installed models) and the effort; and a "More" disclosure
- * for the permission ceiling and the daily budget. A provider that is not
+ * for the permission ceiling and the daily budget (a switch: off stores 0,
+ * which the scheduler reads as no cap). A provider that is not
* connected is not listed — a local row counts as connected only when it
* answers with models — and one sentence says where to connect it. No tool
* picking here: every agent has everything Jarvis has connected, and what it
@@ -32,6 +33,7 @@ import { effortLabel } from "@/components/agentchat/AgentComposer";
import { AgentMark } from "@/components/agentic/AgentMark";
import { ProviderLogo } from "@/components/providers/ProviderLogo";
import { Button } from "@/components/ui/button";
+import { Switch } from "@/components/ui/switch";
import { Combobox, isComboboxPanelEvent, type ComboboxGroup } from "@/components/ui/combobox";
import { ScrollArea } from "@/components/ui/scroll-area";
import { useT } from "@/i18n";
@@ -125,6 +127,10 @@ export function CreateAgentDialog({ open, onClose, onCreated }: CreateAgentDialo
const [accountId, setAccountId] = useState("");
const [ceiling, setCeiling] = useState<PermissionCeiling>("monitor");
const [budget, setBudget] = useState("2");
+ // A cap is the default because an agent that can spend without one is the
+ // surprising case, not the ordinary one. Off sends 0, which is exactly what
+ // the scheduler reads as 'skip the budget gate'.
+ const [budgetOn, setBudgetOn] = useState(true);
const fileInput = useRef<HTMLInputElement>(null);
const [importing, setImporting] = useState(false);
const [importProblems, setImportProblems] = useState<string[] | null>(null);
@@ -362,7 +368,7 @@ export function CreateAgentDialog({ open, onClose, onCreated }: CreateAgentDialo
toolGrants: [],
focus: [],
permissionCeiling: ceiling,
- dailyBudgetUsd: Math.max(0, Number.parseFloat(budget) || 0),
+ dailyBudgetUsd: budgetOn ? Math.max(0, Number.parseFloat(budget) || 0) : 0,
});
onCreated(agent.agentId);
} catch (err) {
@@ -372,7 +378,7 @@ export function CreateAgentDialog({ open, onClose, onCreated }: CreateAgentDialo
};
const fieldClass =
- "w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-strong";
+ "w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:italic placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-strong";
const labelClass = "mb-1 block text-xs font-semibold uppercase tracking-wide text-muted-foreground";
return (
@@ -582,19 +588,38 @@ export function CreateAgentDialog({ open, onClose, onCreated }: CreateAgentDialo
/>
</div>
<div>
- <label htmlFor="society-create-budget" className={labelClass}>
- {t("society.create.budget")}
- </label>
- <input
- id="society-create-budget"
- type="number"
- min={0}
- step={0.5}
- inputMode="decimal"
- className={cn(fieldClass, "w-32 font-mono")}
- value={budget}
- onChange={(e) => setBudget(e.target.value)}
- />
+ <div className="mb-2 flex items-center gap-2">
+ <Switch
+ id="society-create-budget-on"
+ checked={budgetOn}
+ onCheckedChange={setBudgetOn}
+ data-testid="society-create-budget-on"
+ />
+ <label htmlFor="society-create-budget-on" className="text-sm text-foreground">
+ {t("society.card.budget_cap")}
+ </label>
+ </div>
+ {budgetOn ? (
+ <>
+ <input
+ id="society-create-budget"
+ type="number"
+ min={0}
+ step={0.5}
+ inputMode="decimal"
+ aria-label={t("society.create.budget")}
+ data-testid="society-create-budget"
+ className={cn(fieldClass, "w-32 font-mono")}
+ value={budget}
+ onChange={(e) => setBudget(e.target.value)}
+ />
+ <p className="mt-1 text-xs text-muted-foreground">
+ {t("society.card.budget_hint")}
+ </p>
+ </>
+ ) : (
+ <p className="text-xs text-muted-foreground">{t("society.card.budget_off_hint")}</p>
+ )}
</div>
</Collapsible.Content>
</Collapsible.Root>
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 396bb7ac13..4716bf7cd0 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -5265,7 +5265,9 @@
"hands": "Hände",
"learned": "Gelernt",
"limits": "Grenzen",
- "budget_hint": "0 heißt kein Limit. Der Verteiler gibt keinen Auftrag mehr, sobald die Tagesausgaben das erreichen.",
+ "budget_hint": "Der Verteiler gibt keinen Auftrag mehr, sobald die Tagesausgaben das erreichen.",
+ "budget_cap": "Tagesbudget begrenzen",
+ "budget_off_hint": "Kein Tageslimit. Der Verteiler stoppt diesen Agenten nicht wegen der Tagesausgaben.",
"recent": "Zuletzt",
"no_recent": "Von diesem Agenten steht noch nichts auf dem Brett.",
"active_runs": "{0} laufen",
@@ -5371,9 +5373,9 @@
"title": "Agent erstellen",
"subtitle": "Name, Aufgabe und Regelwerk — die Figur rechts ist, wie das Team ihn sehen wird.",
"name": "Name",
- "name_placeholder": "Späher",
+ "name_placeholder": "z. B. Späher",
"title_field": "Bezeichnung",
- "title_placeholder": "Forschung, Marketing, Verwaltung",
+ "title_placeholder": "z. B. Forschung, Marketing, Verwaltung",
"title_fallback": "Spezialist",
"description": "Beschreibung",
"description_placeholder": "Wofür dieser Agent da ist.",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index ef5f394821..8dfae4fae7 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -5298,7 +5298,9 @@
"hands": "Hands",
"learned": "Learned",
"limits": "Limits",
- "budget_hint": "0 means no cap. The scheduler refuses a job once the day's spend reaches this.",
+ "budget_hint": "The scheduler refuses a job once the day's spend reaches this.",
+ "budget_cap": "Daily budget cap",
+ "budget_off_hint": "No daily cap. The scheduler does not stop this agent for today's spend.",
"recent": "Recent",
"no_recent": "Nothing on the board from this agent yet.",
"active_runs": "{0} running",
@@ -5404,9 +5406,9 @@
"title": "Create an agent",
"subtitle": "Name, job and rulebook — the character on the right is how the team will see it.",
"name": "Name",
- "name_placeholder": "Scout",
+ "name_placeholder": "e.g. Scout",
"title_field": "Title",
- "title_placeholder": "Research, marketing, admin",
+ "title_placeholder": "e.g. Research, marketing, admin",
"title_fallback": "Specialist",
"description": "Description",
"description_placeholder": "What this agent is for.",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index f881fcba9c..07631b7001 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -5265,7 +5265,9 @@
"hands": "Manos",
"learned": "Aprendido",
"limits": "Límites",
- "budget_hint": "0 significa sin límite. El planificador deja de dar trabajos cuando el gasto del día llega aquí.",
+ "budget_hint": "El planificador deja de dar trabajos cuando el gasto del día llega aquí.",
+ "budget_cap": "Límite de gasto diario",
+ "budget_off_hint": "Sin límite diario. El planificador no detiene a este agente por el gasto de hoy.",
"recent": "Reciente",
"no_recent": "Este agente aún no ha puesto nada en el tablón.",
"active_runs": "{0} en marcha",
@@ -5371,9 +5373,9 @@
"title": "Crear un agente",
"subtitle": "Nombre, cargo y reglas — la figura de la derecha es como lo verá el equipo.",
"name": "Nombre",
- "name_placeholder": "Explorador",
+ "name_placeholder": "p. ej. Explorador",
"title_field": "Cargo",
- "title_placeholder": "Explorador de investigación",
+ "title_placeholder": "p. ej. Explorador de investigación",
"title_fallback": "Especialista",
"description": "Descripción",
"description_placeholder": "Qué posee este agente, cómo trabaja y dónde debe preguntar primero.",
diff --git a/tests/unit/society/test_roster.py b/tests/unit/society/test_roster.py
index 9e1e3b05d6..00640e156f 100644
--- a/tests/unit/society/test_roster.py
+++ b/tests/unit/society/test_roster.py
@@ -105,6 +105,11 @@ async def test_update_validates_and_sorts_grants(roster: Roster):
assert updated.daily_budget_usd == 1.5
assert updated.skills is None
+ uncapped = await roster.update(scout.agent_id, {"daily_budget_usd": 0})
+ assert uncapped.daily_budget_usd == 0.0
+ with pytest.raises(RosterError):
+ await roster.update(scout.agent_id, {"daily_budget_usd": -1})
+
with pytest.raises(RosterError):
await roster.update(scout.agent_id, {"grants": "plugin:gmail"})
with pytest.raises(RosterError):
diff --git a/tests/unit/society/test_scheduler.py b/tests/unit/society/test_scheduler.py
index 9e80123c66..10109521c6 100644
--- a/tests/unit/society/test_scheduler.py
+++ b/tests/unit/society/test_scheduler.py
@@ -174,6 +174,17 @@ async def test_agent_daily_budget_vetoes(world):
assert await _vetoes(store, "t1") == [str(FailureReason.BUDGET_EXHAUSTED)]
+async def test_zero_daily_budget_skips_the_gate(world):
+ """0 is the stored form of 'no cap': spend does not veto a dispatch."""
+ store, roster, _, dispatcher, _ = world
+ await roster.update("scout", {"daily_budget_usd": 0})
+ await store.append_and_publish(
+ SocietyEnvelope(msg_type=MsgType.DIGEST, from_agent="scout", trace_id="old", cost_usd=99.0)
+ )
+ await store.append_and_publish(_assign("jarvis", "scout"))
+ assert dispatcher.calls == [("scout", "t1")]
+
+
async def test_concurrency_cap_and_result_release(world):
store, _, scheduler, dispatcher, _ = world
await store.append_and_publish(_assign("jarvis", "scout", trace="a"))