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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(pets): make the size slider glide and resize the pet live
rubenluetke10-beep7ba22e461aaf
diff --git a/docs/pets.md b/docs/pets.mdindex b82b175268..74226f9818 100644--- a/docs/pets.md+++ b/docs/pets.md@@ -335,7 +335,7 @@ Control-strip actions: `bell` (handled in the surface, reported through| `GET /api/pets/{id}/sheet.png` | The sprite sheet || `GET /api/pets/template.png` | The empty sprite-sheet template (48 px cells, rows in state order) || `PUT /api/pets/active` | `{pet_id}` → saves `[ui] pet_id`, applies live |-| `PUT /api/pets/settings` | `{scale?, bubble?, strip_always?}` → saves, applies live |+| `PUT /api/pets/settings` | `{scale?, bubble?, strip_always?, preview?}` → applies live, then saves; `preview: true` (a size-slider drag step) only applies live, writes nothing and sends no `PetChanged` || `POST /api/pets/visibility` | `{visible}` → runtime only || `POST /api/pets` | multipart: `sheet` (PNG), `name`, `description`, optional `manifest` (JSON), optional `frame_size` → the new pet || `DELETE /api/pets/{id}` | user-created pets only |diff --git a/jarvis/ui/web/frontend/src/lib/petsApi.ts b/jarvis/ui/web/frontend/src/lib/petsApi.tsindex 95b86d0da0..442a6fe7bd 100644--- a/jarvis/ui/web/frontend/src/lib/petsApi.ts+++ b/jarvis/ui/web/frontend/src/lib/petsApi.ts@@ -94,6 +94,11 @@ export function savePetSettings(patch: PetSettingsPatch): Promise<unknown> {return putJson("/api/pets/settings", patch);}+/** Resize the desktop pet live without saving: one step of a slider drag. */+export function previewPetScale(scale: number): Promise<unknown> {+ return putJson("/api/pets/settings", { scale, preview: true });+}+export function setPetVisible(visible: boolean): Promise<unknown> {return request("/api/pets/visibility", {method: "POST",diff --git a/jarvis/ui/web/frontend/src/views/PetsView.test.tsx b/jarvis/ui/web/frontend/src/views/PetsView.test.tsxindex 8df7f60ca0..e994e54ba9 100644--- a/jarvis/ui/web/frontend/src/views/PetsView.test.tsx+++ b/jarvis/ui/web/frontend/src/views/PetsView.test.tsx@@ -274,7 +274,7 @@ describe("PetsView", () => {);});- it("saves the size when the slider is released", async () => {+ it("resizes the pet live while dragging and saves once on release", async () => {const { calls } = stubServer();renderView();@@ -282,11 +282,23 @@ describe("PetsView", () => {await waitFor(() => expect((customize as HTMLButtonElement).disabled).toBe(false));fireEvent.click(customize);const slider = await screen.findByTestId("pets-size");- fireEvent.change(slider, { target: { value: "1.5" } });- fireEvent.mouseUp(slider);+ fireEvent.pointerDown(slider);+ fireEvent.change(slider, { target: { value: "1.37" } });await waitFor(() =>- expect(calls).toContainEqual({ method: "PUT", url: "/api/pets/settings", body: { scale: 1.5 } }),+ expect(calls).toContainEqual({+ method: "PUT",+ url: "/api/pets/settings",+ body: { scale: 1.37, preview: true },+ }),+ );+ expect((slider as HTMLInputElement).disabled).toBe(false);+ expect(calls.filter((c) => c.method === "PUT" && !(c.body as { preview?: boolean }).preview)).toEqual([]);++ // Released away from the track: the window still sees it.+ fireEvent.pointerUp(window);+ await waitFor(() =>+ expect(calls).toContainEqual({ method: "PUT", url: "/api/pets/settings", body: { scale: 1.37 } }),);});diff --git a/jarvis/ui/web/frontend/src/views/PetsView.tsx b/jarvis/ui/web/frontend/src/views/PetsView.tsxindex 49ce6b2e6d..960bd28720 100644--- a/jarvis/ui/web/frontend/src/views/PetsView.tsx+++ b/jarvis/ui/web/frontend/src/views/PetsView.tsx@@ -1,4 +1,4 @@-import { useEffect, useState } from "react";+import { useEffect, useRef, useState } from "react";import * as Dialog from "@radix-ui/react-dialog";import { useReducedMotion } from "framer-motion";import {@@ -30,7 +30,7 @@ import {import { useRestartApp } from "@/hooks/useRestartApp";import { useT } from "@/i18n";import { NO_PET_ID, PET_STATES } from "@/lib/petStates";-import type { Pet } from "@/lib/petsApi";+import { previewPetScale, type Pet } from "@/lib/petsApi";import { cn } from "@/lib/utils";import { useEventStore } from "@/store/events";import { KeybindRow, formatCombo } from "@/views/settings/KeybindRow";@@ -55,7 +55,8 @@ const HERO_SPRITE_PX = 168;const TILE_SPRITE_PX = 96;const SCALE_MIN = 0.5;const SCALE_MAX = 2;-const SCALE_STEP = 0.1;+/** Fine enough that the thumb glides; the pet itself grows in whole pixels. */+const SCALE_STEP = 0.01;function useStateCycle(enabled: boolean): number {const [index, setIndex] = useState(0);@@ -461,13 +462,71 @@ function CustomizePanel({const pushToast = useEventStore((s) => s.pushToast);const save = useSavePetSettings();const [size, setSize] = useState(scale);+ // While the thumb moves the pet follows it live: one preview request at a+ // time, always the newest value, nothing written. The release saves.+ const dragging = useRef(false);+ const slider = useRef<HTMLInputElement>(null);+ const preview = useRef<{ inFlight: Promise<void> | null; next: number | null; sent: boolean }>({+ inFlight: null,+ next: null,+ sent: false,+ });- // Follow the server (another window, a failed save) whenever it moves.- useEffect(() => setSize(scale), [scale]);+ // Follow the server (another window, a failed save), but never yank the+ // thumb out from under a drag.+ useEffect(() => {+ if (!dragging.current) setSize(scale);+ }, [scale]);++ function previewSize(next: number) {+ const queue = preview.current;+ queue.next = Math.round(next * 100) / 100;+ if (queue.inFlight) return;+ const pump = async () => {+ while (queue.next !== null) {+ const value = queue.next;+ queue.next = null;+ queue.sent = true;+ try {+ await previewPetScale(value);+ } catch {+ // A missed drag step is harmless: the release saves the final size+ // and reports any error then.+ }+ }+ };+ queue.inFlight = pump().finally(() => {+ queue.inFlight = null;+ });+ }++ // The release can happen anywhere on screen, not only over the track.+ function startDrag() {+ window.addEventListener(+ "pointerup",+ () => {+ if (slider.current) void commitSize(Number(slider.current.value));+ },+ { once: true },+ );+ }- function commitSize(next: number) {- const rounded = Math.round(next * 10) / 10;- if (rounded === scale) return;+ function changeSize(next: number) {+ dragging.current = true;+ setSize(next);+ previewSize(next);+ }++ async function commitSize(next: number) {+ dragging.current = false;+ const rounded = Math.round(next * 100) / 100;+ const queue = preview.current;+ queue.next = null;+ const previewed = queue.sent;+ queue.sent = false;+ // The save must land after the last preview, or that preview would win.+ if (queue.inFlight) await queue.inFlight;+ if (rounded === scale && !previewed) return;save.mutate({ scale: rounded },{@@ -494,17 +553,19 @@ function CustomizePanel({<p className="mt-0.5 text-xs text-muted-foreground">{t("pets.size_hint")}</p><inputid="pets-size"+ ref={slider}type="range"data-testid="pets-size"min={SCALE_MIN}max={SCALE_MAX}step={SCALE_STEP}value={size}- disabled={save.isPending}- onChange={(event) => setSize(Number(event.target.value))}- onMouseUp={() => commitSize(size)}- onKeyUp={() => commitSize(size)}- onTouchEnd={() => commitSize(size)}+ onChange={(event) => changeSize(Number(event.target.value))}+ onPointerDown={startDrag}+ onKeyUp={(event) => void commitSize(Number(event.currentTarget.value))}+ onBlur={(event) => {+ if (dragging.current) void commitSize(Number(event.currentTarget.value));+ }}className="mt-3 w-full accent-primary disabled:opacity-50"/></div>diff --git a/jarvis/ui/web/pets_routes.py b/jarvis/ui/web/pets_routes.pyindex b84abc6062..1eed7c755d 100644--- a/jarvis/ui/web/pets_routes.py+++ b/jarvis/ui/web/pets_routes.py@@ -129,6 +129,13 @@ class SettingsBody(BaseModel):strip_always: bool | None = Field(default=None, description="Keep the control strip up even at rest")+ preview: bool = Field(+ default=False,+ description=(+ "Apply live only: nothing is written and no PetChanged goes out. "+ "The size slider sends this while it is dragged and a normal save on release."+ ),+ )class VisibilityBody(BaseModel):@@ -406,33 +413,14 @@ async def put_settings(body: SettingsBody, request: Request) -> dict[str, Any]:from jarvis.core import config_writer- persisted = True+ # Memory, then the desktop, then disk: the pet resizes without waiting+ # for the locked TOML write behind it.if body.scale is not None:- scale = clamp_pet_scale(body.scale)- _set_ui_value(request, "pet_scale", scale)- try:- await asyncio.to_thread(config_writer.set_pet_scale, scale, path=_config_path())- except Exception as exc: # noqa: BLE001 — the live apply is still worth trying- persisted = False- log.warning("pet_scale persist failed (live apply still attempted): %s", exc)+ _set_ui_value(request, "pet_scale", clamp_pet_scale(body.scale))if body.bubble is not None:_set_ui_value(request, "pet_bubble", bool(body.bubble))- try:- await asyncio.to_thread(- config_writer.set_pet_bubble, bool(body.bubble), path=_config_path()- )- except Exception as exc: # noqa: BLE001 — the live apply is still worth trying- persisted = False- log.warning("pet_bubble persist failed (live apply still attempted): %s", exc)if body.strip_always is not None:_set_ui_value(request, "pet_strip_always", bool(body.strip_always))- try:- await asyncio.to_thread(- config_writer.set_pet_strip_always, bool(body.strip_always), path=_config_path()- )- except Exception as exc: # noqa: BLE001 — the live apply is still worth trying- persisted = False- log.warning("pet_strip_always persist failed (live apply still attempted): %s", exc)applied_live, detail = await _apply(request,@@ -442,6 +430,33 @@ async def put_settings(body: SettingsBody, request: Request) -> dict[str, Any]:_configured_strip_always(request),)active = _configured_pet_id(request)+ if body.preview:+ # One step of a slider drag: the release that follows saves and announces it.+ return {+ "ok": True,+ **_state(request, active),+ "persisted": False,+ "applied_live": applied_live,+ "detail": detail,+ }++ writes: list[tuple[str, Callable[..., None], object]] = []+ if body.scale is not None:+ writes.append(("pet_scale", config_writer.set_pet_scale, _configured_scale(request)))+ if body.bubble is not None:+ writes.append(("pet_bubble", config_writer.set_pet_bubble, bool(body.bubble)))+ if body.strip_always is not None:+ writes.append(+ ("pet_strip_always", config_writer.set_pet_strip_always, bool(body.strip_always))+ )+ persisted = True+ for key, write, value in writes:+ try:+ await asyncio.to_thread(write, value, path=_config_path())+ except Exception as exc: # noqa: BLE001 — already applied live; the response reports it+ persisted = False+ log.warning("%s persist failed (applied live, lost on restart): %s", key, exc)+await _publish_changed(request, active, source="settings")return {"ok": True,diff --git a/tests/unit/ui/test_pet_overlay_surface.py b/tests/unit/ui/test_pet_overlay_surface.pyindex 77a33341fc..1e2bf9f886 100644--- a/tests/unit/ui/test_pet_overlay_surface.py+++ b/tests/unit/ui/test_pet_overlay_surface.py@@ -161,6 +161,25 @@ def test_set_pet_updates_the_config_and_the_live_window() -> None:assert app.cfg.ui.pet_id == "none"+def test_a_burst_of_look_changes_queues_one_rescale_with_the_newest_size() -> None:+ pet = OrbOverlay(style="pet")+ pet._root = object() # a window exists; the caller is not the Tk thread++ def queued_looks() -> list:+ items = []+ while not pet._ui_queue.empty():+ items.append(pet._ui_queue.get_nowait())+ return [fn for fn in items if fn == pet._apply_pet_look]++ for scale in (1.1, 1.2, 1.3):+ pet.set_pet_look(scale=scale)+ (apply,) = queued_looks()+ assert pet._pet_scale == 1.3+ apply()+ pet.set_pet_look(scale=1.4)+ assert len(queued_looks()) == 1 # the next change queues again++def test_set_pet_look_clamps_and_applies() -> None:surface = _PetSurface()app = _app(orb=surface)diff --git a/tests/unit/ui/test_pets_routes.py b/tests/unit/ui/test_pets_routes.pyindex 5de2c46213..a012d7aa02 100644--- a/tests/unit/ui/test_pets_routes.py+++ b/tests/unit/ui/test_pets_routes.py@@ -265,6 +265,20 @@ def test_put_settings_clamps_saves_and_applies(env) -> None:assert (event.scale, event.bubble) == (2.0, False)+def test_a_preview_resizes_live_but_writes_and_announces_nothing(env) -> None:+ before = env.toml.read_text(encoding="utf-8")+ r = env.client.put("/api/pets/settings", json={"scale": 1.37, "preview": True})+ assert r.status_code == 200+ assert r.json()["persisted"] is False+ assert env.app.state.desktop_app.calls == [("set_pet_look", 1.37, True, False)]+ assert env.toml.read_text(encoding="utf-8") == before+ assert env.app.state.bus.events == []+ # The release that follows saves it like any other change.+ env.client.put("/api/pets/settings", json={"scale": 1.37})+ assert _toml_ui(env)["pet_scale"] == 1.37+ assert len(env.app.state.bus.events) == 1++def test_put_settings_changes_only_what_is_sent(env) -> None:env.client.put("/api/pets/settings", json={"bubble": False})assert "pet_scale" not in _toml_ui(env)diff --git a/ui/orb/overlay.py b/ui/orb/overlay.pyindex ed9a98061d..4a73e83fcd 100644--- a/ui/orb/overlay.py+++ b/ui/orb/overlay.py@@ -2300,6 +2300,9 @@ class OrbOverlay:self._pet_bubble = bool(pet_bubble)#: ``[ui] pet_strip_always``: the strip stays up even at rest.self._pet_strip_always = bool(pet_strip_always)+ #: A look change is already queued for the Tk thread: a slider drag+ #: sends a burst, and only the newest values need one rescale.+ self._pet_look_queued = False#: Mirrors ``VoiceMuteChanged`` for the strip's microphone control.self._mic_muted = False#: Hidden by the shortcut or the settings page — lasts until restart.@@ -3931,6 +3934,11 @@ class OrbOverlay:if strip_always is not None:self._pet_strip_always = bool(strip_always)self._note_activity()+ if self._root is None:+ return # no window yet: the first paint reads the values just stored+ if self._pet_look_queued:+ return # the queued apply reads the values just stored+ self._pet_look_queued = Trueself._enqueue_ui(self._apply_pet_look)def set_pet_outcome(self, kind: str) -> None:@@ -4046,6 +4054,7 @@ class OrbOverlay:self._sync_controls_visibility()def _apply_pet_look(self) -> None:+ self._pet_look_queued = Falseif self._style != "pet":returnif not self._pet_bubble and self._thought is not None: