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
feat(pets): Codex-style strip, figure-sized proportions, status card and livelier sprites
rubenluetke10-beep7fb0cce67407
diff --git a/jarvis/ui/jarvisbar/host.py b/jarvis/ui/jarvisbar/host.pyindex 028e741abd..1b831bf6f1 100644--- a/jarvis/ui/jarvisbar/host.py+++ b/jarvis/ui/jarvisbar/host.py@@ -174,7 +174,13 @@ def dispatch(surface: Any, msg: dict[str, Any]) -> bool:elif op == "set_pet_outcome":_call(surface, "set_pet_outcome", str(msg.get("kind", "")))elif op == "show_status":- _call(surface, "show_status", str(msg.get("header", "")), str(msg.get("line", "")))+ # "header"/"line" are the keys an older parent still sends.+ title = msg.get("title", msg.get("header", ""))+ detail = msg.get("detail", msg.get("line", ""))+ _call(surface, "show_status", str(title or ""), str(detail or ""))+ elif op == "clear_status":+ linger = msg.get("linger_s")+ _call(surface, "clear_status", 1.5 if linger is None else float(linger))elif op == "set_speaker_muted":_call(surface, "set_speaker_muted", bool(msg.get("muted", False)))elif op == "set_visible":diff --git a/jarvis/ui/jarvisbar/subprocess_overlay.py b/jarvis/ui/jarvisbar/subprocess_overlay.pyindex 1c7254b649..3b421b1c43 100644--- a/jarvis/ui/jarvisbar/subprocess_overlay.py+++ b/jarvis/ui/jarvisbar/subprocess_overlay.py@@ -777,8 +777,11 @@ class SubprocessMascotOverlay(SubprocessBarOverlay):def set_pet_outcome(self, kind: str) -> None:self._send({"op": "set_pet_outcome", "kind": str(kind)})- def show_status(self, header: str = "", line: str = "") -> None:- self._send({"op": "show_status", "header": str(header), "line": str(line)})+ def show_status(self, title: str = "", detail: str = "") -> None:+ self._send({"op": "show_status", "title": str(title), "detail": str(detail)})++ def clear_status(self, linger_s: float = 1.5) -> None:+ self._send({"op": "clear_status", "linger_s": float(linger_s)})def set_speaker_muted(self, muted: bool) -> None:self._speaker_muted = bool(muted)diff --git a/jarvis/ui/pets/builtin/bolt/pet.json b/jarvis/ui/pets/builtin/bolt/pet.jsonindex dde0157b5e..c71c98ee13 100644--- a/jarvis/ui/pets/builtin/bolt/pet.json+++ b/jarvis/ui/pets/builtin/bolt/pet.json@@ -9,12 +9,14 @@"idle": {"row": 0,"frames": 8,- "fps": 4,- "loop": true+ "fps": 6,+ "loop": true,+ "accent_frames": 1,+ "accent_every": 3},"listening": {"row": 1,- "frames": 4,+ "frames": 6,"fps": 8,"loop": true},@@ -32,20 +34,20 @@},"success": {"row": 4,- "frames": 6,+ "frames": 8,"fps": 10,"loop": false},"error": {"row": 5,- "frames": 4,- "fps": 8,+ "frames": 6,+ "fps": 9,"loop": false},"sleeping": {"row": 6,- "frames": 4,- "fps": 2,+ "frames": 6,+ "fps": 3,"loop": true}}diff --git a/jarvis/ui/pets/builtin/bolt/sheet.png b/jarvis/ui/pets/builtin/bolt/sheet.pngindex 6e33f894a6..77e4073df5 100644Binary files a/jarvis/ui/pets/builtin/bolt/sheet.png and b/jarvis/ui/pets/builtin/bolt/sheet.png differdiff --git a/jarvis/ui/pets/builtin/brew/pet.json b/jarvis/ui/pets/builtin/brew/pet.jsonindex 7ea56b6d47..5d08a72049 100644--- a/jarvis/ui/pets/builtin/brew/pet.json+++ b/jarvis/ui/pets/builtin/brew/pet.json@@ -9,18 +9,20 @@"idle": {"row": 0,"frames": 8,- "fps": 4,- "loop": true+ "fps": 6,+ "loop": true,+ "accent_frames": 1,+ "accent_every": 3},"listening": {"row": 1,- "frames": 4,+ "frames": 6,"fps": 8,"loop": true},"thinking": {"row": 2,- "frames": 6,+ "frames": 8,"fps": 8,"loop": true},@@ -32,20 +34,20 @@},"success": {"row": 4,- "frames": 6,+ "frames": 8,"fps": 10,"loop": false},"error": {"row": 5,- "frames": 4,- "fps": 8,+ "frames": 6,+ "fps": 9,"loop": false},"sleeping": {"row": 6,- "frames": 4,- "fps": 2,+ "frames": 6,+ "fps": 3,"loop": true}}diff --git a/jarvis/ui/pets/builtin/brew/sheet.png b/jarvis/ui/pets/builtin/brew/sheet.pngindex c6e6d280ab..eab702e169 100644Binary files a/jarvis/ui/pets/builtin/brew/sheet.png and b/jarvis/ui/pets/builtin/brew/sheet.png differdiff --git a/jarvis/ui/pets/builtin/gigi/pet.json b/jarvis/ui/pets/builtin/gigi/pet.jsonindex 7ec9b00a86..e704283f8b 100644--- a/jarvis/ui/pets/builtin/gigi/pet.json+++ b/jarvis/ui/pets/builtin/gigi/pet.json@@ -9,18 +9,20 @@"idle": {"row": 0,"frames": 8,- "fps": 4,- "loop": true+ "fps": 6,+ "loop": true,+ "accent_frames": 1,+ "accent_every": 3},"listening": {"row": 1,- "frames": 4,+ "frames": 6,"fps": 8,"loop": true},"thinking": {"row": 2,- "frames": 6,+ "frames": 8,"fps": 8,"loop": true},@@ -32,20 +34,20 @@},"success": {"row": 4,- "frames": 6,+ "frames": 8,"fps": 10,"loop": false},"error": {"row": 5,- "frames": 4,- "fps": 8,+ "frames": 6,+ "fps": 9,"loop": false},"sleeping": {"row": 6,- "frames": 4,- "fps": 2,+ "frames": 6,+ "fps": 3,"loop": true}}diff --git a/jarvis/ui/pets/builtin/gigi/sheet.png b/jarvis/ui/pets/builtin/gigi/sheet.pngindex 245a198b6b..fd7d6e2d5f 100644Binary files a/jarvis/ui/pets/builtin/gigi/sheet.png and b/jarvis/ui/pets/builtin/gigi/sheet.png differdiff --git a/jarvis/ui/pets/builtin/miso/pet.json b/jarvis/ui/pets/builtin/miso/pet.jsonindex 48ea50913f..e2b103e083 100644--- a/jarvis/ui/pets/builtin/miso/pet.json+++ b/jarvis/ui/pets/builtin/miso/pet.json@@ -9,18 +9,20 @@"idle": {"row": 0,"frames": 8,- "fps": 4,- "loop": true+ "fps": 6,+ "loop": true,+ "accent_frames": 1,+ "accent_every": 3},"listening": {"row": 1,- "frames": 4,+ "frames": 6,"fps": 8,"loop": true},"thinking": {"row": 2,- "frames": 6,+ "frames": 8,"fps": 8,"loop": true},@@ -32,20 +34,20 @@},"success": {"row": 4,- "frames": 6,+ "frames": 8,"fps": 10,"loop": false},"error": {"row": 5,- "frames": 4,- "fps": 8,+ "frames": 6,+ "fps": 9,"loop": false},"sleeping": {"row": 6,- "frames": 4,- "fps": 2,+ "frames": 6,+ "fps": 3,"loop": true}}diff --git a/jarvis/ui/pets/builtin/miso/sheet.png b/jarvis/ui/pets/builtin/miso/sheet.pngindex 780d9bf31a..cce2a3b220 100644Binary files a/jarvis/ui/pets/builtin/miso/sheet.png and b/jarvis/ui/pets/builtin/miso/sheet.png differdiff --git a/jarvis/ui/pets/builtin/mochi/pet.json b/jarvis/ui/pets/builtin/mochi/pet.jsonindex 9366847cb7..9a3d748791 100644--- a/jarvis/ui/pets/builtin/mochi/pet.json+++ b/jarvis/ui/pets/builtin/mochi/pet.json@@ -9,18 +9,20 @@"idle": {"row": 0,"frames": 8,- "fps": 4,- "loop": true+ "fps": 6,+ "loop": true,+ "accent_frames": 1,+ "accent_every": 3},"listening": {"row": 1,- "frames": 4,+ "frames": 6,"fps": 8,"loop": true},"thinking": {"row": 2,- "frames": 6,+ "frames": 8,"fps": 8,"loop": true},@@ -32,20 +34,20 @@},"success": {"row": 4,- "frames": 6,+ "frames": 8,"fps": 10,"loop": false},"error": {"row": 5,- "frames": 4,- "fps": 8,+ "frames": 6,+ "fps": 9,"loop": false},"sleeping": {"row": 6,- "frames": 4,- "fps": 2,+ "frames": 6,+ "fps": 3,"loop": true}}diff --git a/jarvis/ui/pets/builtin/mochi/sheet.png b/jarvis/ui/pets/builtin/mochi/sheet.pngindex 1261f02286..e1e0ad6e26 100644Binary files a/jarvis/ui/pets/builtin/mochi/sheet.png and b/jarvis/ui/pets/builtin/mochi/sheet.png differdiff --git a/jarvis/ui/pets/builtin/shelly/pet.json b/jarvis/ui/pets/builtin/shelly/pet.jsonindex 06dbb9512e..0178dcb060 100644--- a/jarvis/ui/pets/builtin/shelly/pet.json+++ b/jarvis/ui/pets/builtin/shelly/pet.json@@ -9,18 +9,20 @@"idle": {"row": 0,"frames": 8,- "fps": 4,- "loop": true+ "fps": 6,+ "loop": true,+ "accent_frames": 1,+ "accent_every": 3},"listening": {"row": 1,- "frames": 4,+ "frames": 6,"fps": 8,"loop": true},"thinking": {"row": 2,- "frames": 6,+ "frames": 8,"fps": 8,"loop": true},@@ -32,20 +34,20 @@},"success": {"row": 4,- "frames": 6,+ "frames": 8,"fps": 10,"loop": false},"error": {"row": 5,- "frames": 4,- "fps": 8,+ "frames": 6,+ "fps": 9,"loop": false},"sleeping": {"row": 6,- "frames": 4,- "fps": 2,+ "frames": 6,+ "fps": 3,"loop": true}}diff --git a/jarvis/ui/pets/builtin/shelly/sheet.png b/jarvis/ui/pets/builtin/shelly/sheet.pngindex aa702df387..226a7fa9ee 100644Binary files a/jarvis/ui/pets/builtin/shelly/sheet.png and b/jarvis/ui/pets/builtin/shelly/sheet.png differdiff --git a/jarvis/ui/pets/manifest.py b/jarvis/ui/pets/manifest.pyindex 8a9e6a00cb..8bf6d966f8 100644--- a/jarvis/ui/pets/manifest.py+++ b/jarvis/ui/pets/manifest.py@@ -41,6 +41,9 @@ MAX_NAME_CHARS = 40MAX_DESCRIPTION_CHARS = 140MIN_FPS = 1MAX_FPS = 12+#: Upper bound of ``accent_every``: an accent (a blink) at least once per this+#: many loops, so it never disappears for good.+MAX_ACCENT_EVERY = 12#: Largest sheet edge in pixels, and the largest sheet file in bytes.MAX_SHEET_EDGE = 512@@ -53,12 +56,22 @@ class PetManifestError(ValueError):@dataclass(frozen=True)class AnimationSpec:- """One state's animation: a row of ``frames`` cells played at ``fps``."""+ """One state's animation: a row of ``frames`` cells played at ``fps``.++ ``accent_frames`` (optional) marks the LAST cells of a looping row as an+ accent — a blink, a wink — that plays only once every ``accent_every``+ loops instead of on every pass. Without it an eight-frame idle at six+ frames per second would blink every 1.3 s; with ``accent_frames: 1`` and+ ``accent_every: 3`` the pet breathes on the first seven cells and blinks+ every few seconds. ``0`` (the default) plays every cell on every loop.+ """row: intframes: intfps: intloop: bool+ accent_frames: int = 0+ accent_every: int = 1@dataclass(frozen=True)@@ -106,18 +119,22 @@ class PetManifest:"frame_size": self.frame_size,"sheet": self.sheet,"animations": {- state: {- "row": spec.row,- "frames": spec.frames,- "fps": spec.fps,- "loop": spec.loop,- }+ state: spec_json(spec)for state in PET_STATESif (spec := self.animations.get(state)) is not None},}+def spec_json(spec: AnimationSpec) -> dict:+ """One animation as it is written to ``pet.json`` (accent keys only when used)."""+ out: dict = {"row": spec.row, "frames": spec.frames, "fps": spec.fps, "loop": spec.loop}+ if spec.accent_frames > 0:+ out["accent_frames"] = spec.accent_frames+ out["accent_every"] = spec.accent_every+ return out++def _int_field(data: Mapping, key: str, where: str) -> int:value = data.get(key)# bool is an int subclass; "frames": true is a typo, not a count.@@ -142,7 +159,29 @@ def _parse_animation(state: str, raw: object) -> AnimationSpec:loop = raw.get("loop", state not in ONE_SHOT_STATES)if not isinstance(loop, bool):raise PetManifestError(f"{where}: 'loop' must be true or false.")- return AnimationSpec(row=row, frames=frames, fps=fps, loop=loop)+ accent_frames = 0+ accent_every = 1+ if "accent_frames" in raw or "accent_every" in raw:+ accent_frames = _int_field(raw, "accent_frames", where)+ accent_every = _int_field(raw, "accent_every", where)+ if not 0 <= accent_frames < frames:+ raise PetManifestError(+ f"{where}: 'accent_frames' must leave at least one ordinary frame."+ )+ if not 1 <= accent_every <= MAX_ACCENT_EVERY:+ raise PetManifestError(+ f"{where}: 'accent_every' must be between 1 and {MAX_ACCENT_EVERY}."+ )+ if not loop and accent_frames:+ raise PetManifestError(f"{where}: an accent needs a looping animation.")+ return AnimationSpec(+ row=row,+ frames=frames,+ fps=fps,+ loop=loop,+ accent_frames=accent_frames,+ accent_every=accent_every,+ )def parse_manifest(data: object, *, builtin: bool) -> PetManifest:diff --git a/jarvis/ui/pets/template/template.json b/jarvis/ui/pets/template/template.jsonindex dfef634553..9b160c8a0e 100644--- a/jarvis/ui/pets/template/template.json+++ b/jarvis/ui/pets/template/template.json@@ -9,18 +9,20 @@"idle": {"row": 0,"frames": 8,- "fps": 4,- "loop": true+ "fps": 6,+ "loop": true,+ "accent_frames": 1,+ "accent_every": 3},"listening": {"row": 1,- "frames": 4,+ "frames": 6,"fps": 8,"loop": true},"thinking": {"row": 2,- "frames": 6,+ "frames": 8,"fps": 8,"loop": true},@@ -32,20 +34,20 @@},"success": {"row": 4,- "frames": 6,+ "frames": 8,"fps": 10,"loop": false},"error": {"row": 5,- "frames": 4,- "fps": 8,+ "frames": 6,+ "fps": 9,"loop": false},"sleeping": {"row": 6,- "frames": 4,- "fps": 2,+ "frames": 6,+ "fps": 3,"loop": true}}diff --git a/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsx b/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsxindex 2e6df9b58e..12b5b2fb3b 100644--- a/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsx+++ b/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsx@@ -1,12 +1,26 @@-import { Mic, PenLine, Volume2 } from "lucide-react";+import { Mic, SquarePen, Volume2 } from "lucide-react";import { cn } from "@/lib/utils";/**- * A still picture of the control strip the desktop pet carries: the pen disc- * (new chat), then one pill holding the microphone, the talk orb and the- * speaker. Shown on the settings page so the user knows what sits under the- * pet before switching it on.+ * The desktop strip's own palette (`ui/orb/controls.py`, `PET_FILL` & co).+ * Literal on purpose, like the overlay-style previews: this is a picture of a+ * desktop object that is always dark, whatever the app's theme — on a light+ * page it looks exactly as the real strip does on a light wallpaper.+ */+const STRIP_FILL = "#171b26";+const STRIP_ICON = "#e8e9ee";+const STRIP_DIVIDER = "#303748";+/** The glossy talk orb: lit from the top left, deep blue at the rim. */+const ORB_GRADIENT =+ "radial-gradient(circle at 32% 30%, #e6f1ff 0 7%, #a9d0ff 15%, #4a7cf5 55%, #2747c8 100%)";++/**+ * A still picture of the control strip the desktop pet carries: the pen in+ * its own filled disc (new chat), then one filled pill holding the+ * microphone, the talk orb and the speaker, split by faint dividers. Shown on+ * the settings page so the user knows what sits under the pet before+ * switching it on.** Deliberately NOT a set of buttons: the real controls live on the desktop,* and a look-alike that reacted to clicks here would promise something it@@ -20,32 +34,43 @@ export function PetControlStripPreview({className?: string;}) {const small = size === "sm";- const disc = small ? "h-6 w-6" : "h-8 w-8";- const icon = small ? "h-3 w-3" : "h-3.5 w-3.5";- const orb = small ? "h-3.5 w-3.5" : "h-[18px] w-[18px]";+ const height = small ? "h-7" : "h-10";+ const disc = small ? "w-7" : "w-10";+ const slot = small ? "w-7" : "w-10";+ const icon = small ? "h-3.5 w-3.5" : "h-[18px] w-[18px]";+ const orb = small ? "h-[22px] w-[22px]" : "h-8 w-8";+ const divider = small ? "h-3" : "h-5";return (<divaria-hiddendata-testid="pet-strip-preview"- className={cn("pointer-events-none flex select-none items-center gap-1.5", className)}+ className={cn("pointer-events-none flex select-none items-center gap-2", className)}><span- className={cn(- "grid place-items-center rounded-full border border-border-strong bg-card text-foreground-secondary shadow-rim",- disc,- )}+ className={cn("grid place-items-center rounded-full", height, disc)}+ style={{ backgroundColor: STRIP_FILL, color: STRIP_ICON }}>- <PenLine className={icon} />+ <SquarePen className={icon} strokeWidth={2} /></span><span- className={cn(- "flex items-center rounded-full border border-border-strong bg-card text-foreground-secondary shadow-rim",- small ? "h-6 gap-2 px-2" : "h-8 gap-3 px-3",- )}+ className={cn("flex items-center rounded-full", height, small ? "px-1" : "px-1.5")}+ style={{ backgroundColor: STRIP_FILL, color: STRIP_ICON }}>- <Mic className={icon} />- <span className={cn("rounded-full bg-accent ring-2 ring-accent/25", orb)} />- <Volume2 className={icon} />+ <span className={cn("grid place-items-center", slot)}>+ <Mic className={icon} strokeWidth={2} />+ </span>+ <span className={cn("w-px", divider)} style={{ backgroundColor: STRIP_DIVIDER }} />+ <span className={cn("grid place-items-center", small ? "w-8" : "w-11")}>+ <span+ data-testid="pet-strip-orb"+ className={cn("rounded-full", orb)}+ style={{ backgroundImage: ORB_GRADIENT }}+ />+ </span>+ <span className={cn("w-px", divider)} style={{ backgroundColor: STRIP_DIVIDER }} />+ <span className={cn("grid place-items-center", slot)}>+ <Volume2 className={icon} strokeWidth={2} />+ </span></span></div>);diff --git a/jarvis/ui/web/frontend/src/components/pets/PetSprite.test.tsx b/jarvis/ui/web/frontend/src/components/pets/PetSprite.test.tsxindex e0568000b7..eab509caee 100644--- a/jarvis/ui/web/frontend/src/components/pets/PetSprite.test.tsx+++ b/jarvis/ui/web/frontend/src/components/pets/PetSprite.test.tsx@@ -4,7 +4,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";const motion = vi.hoisted(() => ({ reduced: false }));vi.mock("framer-motion", () => ({ useReducedMotion: () => motion.reduced }));-import { PetSprite, integerScaleFor } from "@/components/pets/PetSprite";+import { PetSprite, integerScaleFor, spriteFrameAt } from "@/components/pets/PetSprite";+import { PetControlStripPreview } from "@/components/pets/PetControlStripPreview";import { resolvePetAnimation, type PetAnimation } from "@/lib/petStates";const ANIMATIONS: Record<string, PetAnimation> = {@@ -92,3 +93,35 @@ describe("integerScaleFor", () => {expect(integerScaleFor(64, 40)).toBe(1);});});++describe("spriteFrameAt (the desktop's playback order)", () => {+ it("plays a blink accent once every few loops", () => {+ const seen = Array.from({ length: 23 }, (_, step) =>+ spriteFrameAt(step, 8, { accentFrames: 1, accentEvery: 3 }),+ );+ expect(seen.slice(0, 21)).toEqual([0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6]);+ expect(seen[21]).toBe(7);+ expect(seen[22]).toBe(0);+ });++ it("swings the talking row back and forth", () => {+ const seen = Array.from({ length: 8 }, (_, step) => spriteFrameAt(step, 4, { swing: true }));+ expect(seen).toEqual([0, 1, 2, 3, 2, 1, 0, 1]);+ });++ it("holds a one-shot on its last frame and wraps a plain loop", () => {+ expect(spriteFrameAt(9, 3, { loop: false })).toBe(2);+ expect(spriteFrameAt(5, 4)).toBe(1);+ expect(spriteFrameAt(3, 1)).toBe(0);+ });+});++describe("PetControlStripPreview", () => {+ it("is a decorative picture with the glossy orb", () => {+ render(<PetControlStripPreview />);+ const strip = screen.getByTestId("pet-strip-preview");+ expect(strip.getAttribute("aria-hidden")).toBe("true");+ expect(strip.querySelector("button")).toBeNull();+ expect(screen.getByTestId("pet-strip-orb").style.backgroundImage).toContain("radial-gradient");+ });+});diff --git a/jarvis/ui/web/frontend/src/components/pets/PetSprite.tsx b/jarvis/ui/web/frontend/src/components/pets/PetSprite.tsxindex 1a91889965..ef514a24cc 100644--- a/jarvis/ui/web/frontend/src/components/pets/PetSprite.tsx+++ b/jarvis/ui/web/frontend/src/components/pets/PetSprite.tsx@@ -15,10 +15,12 @@ import { cn } from "@/lib/utils";* scaled with a transform.** Frames advance on a small timer that writes the background position- * directly (no React render per frame), at the manifest's fps. A looping row- * wraps; a one-shot row holds its last frame. The timer stops while the sprite- * is off-screen, and under `prefers-reduced-motion` the sprite shows frame 0- * and never moves.+ * directly (no React render per frame), at the manifest's fps — the same+ * order the desktop plays (`spriteFrameAt`): a looping row wraps and shows its+ * accent cells (a blink) only every few loops, a one-shot row holds its last+ * frame, and the talking row (drawn closed to widest) swings back and forth.+ * The timer stops while the sprite is off-screen, and under+ * `prefers-reduced-motion` the sprite shows frame 0 and never moves.*/export function PetSprite({pet,@@ -47,6 +49,9 @@ export function PetSprite({const frames = animation?.frames ?? 1;const fps = animation?.fps ?? 1;const loop = animation?.loop ?? true;+ const accentFrames = animation?.accent_frames ?? 0;+ const accentEvery = animation?.accent_every ?? 1;+ const swing = state === "talking";const drawable = animation !== null;useEffect(() => {@@ -57,22 +62,32 @@ export function PetSprite({};place(0);if (frames <= 1 || reduced || !onScreen) return;- let frame = 0;+ let step = 0;const timer = window.setInterval(() => {- frame += 1;- if (frame >= frames) {- if (!loop) {- window.clearInterval(timer);- return;- }- frame = 0;+ step += 1;+ if (!loop && !swing && step >= frames) {+ window.clearInterval(timer);+ return;}- place(frame);+ place(spriteFrameAt(step, frames, { loop, accentFrames, accentEvery, swing }));}, 1000 / Math.max(1, fps));return () => window.clearInterval(timer);// Primitives only: the animation object is rebuilt on every render, and// depending on it would restart the row each time a parent repaints.- }, [drawable, row, frames, fps, loop, size, reduced, onScreen, pet.sheet_url]);+ }, [+ drawable,+ row,+ frames,+ fps,+ loop,+ accentFrames,+ accentEvery,+ swing,+ size,+ reduced,+ onScreen,+ pet.sheet_url,+ ]);return (<div@@ -104,6 +119,39 @@ export function PetSprite({);}+/**+ * The frame for timer `step` — the desktop renderer's order+ * (`ui/orb/pet_renderer.py`): a swing goes 0, 1, …, n-1, …, 1; a one-shot+ * holds its last cell; a looping row with an accent plays its ordinary cells+ * `accentEvery` times, then the accent cells once.+ */+export function spriteFrameAt(+ step: number,+ frames: number,+ {+ loop = true,+ accentFrames = 0,+ accentEvery = 1,+ swing = false,+ }: { loop?: boolean; accentFrames?: number; accentEvery?: number; swing?: boolean } = {},+): number {+ const count = Math.max(1, Math.floor(frames));+ const at = Math.max(0, Math.floor(step));+ if (count === 1) return 0;+ if (swing) {+ const period = 2 * (count - 1);+ const position = at % period;+ return position < count ? position : period - position;+ }+ if (!loop) return Math.min(at, count - 1);+ const accent = Math.max(0, Math.min(count - 1, Math.floor(accentFrames)));+ if (accent === 0) return at % count;+ const base = count - accent;+ const every = Math.max(1, Math.floor(accentEvery));+ const position = at % (base * every + accent);+ return position < base * every ? position % base : base + (position - base * every);+}+/** The largest whole-number factor that keeps a frame within `maxPx`. */export function integerScaleFor(frameSize: number, maxPx: number): number {if (frameSize <= 0) return 1;diff --git a/jarvis/ui/web/frontend/src/lib/petStates.ts b/jarvis/ui/web/frontend/src/lib/petStates.tsindex b1043875fc..8174044620 100644--- a/jarvis/ui/web/frontend/src/lib/petStates.ts+++ b/jarvis/ui/web/frontend/src/lib/petStates.ts@@ -49,6 +49,9 @@ export interface PetAnimation {frames: number;fps: number;loop: boolean;+ /** The row's last cells are an accent (a blink) shown once every `accent_every` loops. */+ accent_frames?: number;+ accent_every?: number;}/**diff --git a/jarvis/ui/web/pets_routes.py b/jarvis/ui/web/pets_routes.pyindex c6b20f1134..fd6d76dbe6 100644--- a/jarvis/ui/web/pets_routes.py+++ b/jarvis/ui/web/pets_routes.py@@ -227,6 +227,9 @@ def _pet_json(manifest: Any) -> dict[str, Any]:"frames": spec.frames,"fps": spec.fps,"loop": spec.loop,+ # 0 / 1 when the row has no accent (every cell on every loop).+ "accent_frames": int(getattr(spec, "accent_frames", 0)),+ "accent_every": int(getattr(spec, "accent_every", 1)),}return {"id": manifest.id,diff --git a/scripts/pets/build_pets.py b/scripts/pets/build_pets.pyindex f47704be41..91886681ce 100644--- a/scripts/pets/build_pets.py+++ b/scripts/pets/build_pets.py@@ -3,8 +3,14 @@Every pet is drawn procedurally into 48 x 48 cells: shape helpers buildmasks, a shared shading pass gives every body the same light/dark rim, and a-per-state pose table moves the figure (bob, hop, shake). One row per state in-``PET_STATES`` order, one ``pet.json`` per pet (``docs/pets.md``).+per-state pose table moves the figure — a 1 px breath (the body above its+waist stretches and settles), a hop that squashes on landing, a shake. One row+per state in ``PET_STATES`` order, one ``pet.json`` per pet (``docs/pets.md``).++Two conventions the renderer relies on: the idle row's LAST cell is a blink,+declared as an accent (``accent_frames``/``accent_every``) so it plays every+few seconds instead of on every breath; and the talking row is ordered from a+closed mouth to the widest one, so the live voice level can pick the frame.The output is deterministic: no randomness, no timestamps, a fixed PNGencoder setting. ``tests/unit/ui/pets/test_builtin_pets.py`` regenerates@@ -69,6 +75,10 @@ Z_BLUE = hexc("#a5c8ff")#: Sound arcs are 1 px strokes; an outline around each would read as hatching#: on a light desktop, so they are a mid blue that holds on dark AND light.ARC = hexc("#3d9be0")+#: An arc on its way out: lighter, so the ripple fades instead of blinking off.+ARC_FADE = hexc("#93c8f0")+SWEAT = hexc("#9fd8ff")+SWEAT_SHINE = hexc("#e8f6ff")BLUSH = hexc("#ff8fa3")MOUTH_DARK = hexc("#3b1f2b")TONGUE = hexc("#ff7a8a")@@ -288,27 +298,33 @@ class Frame:FRAME_COUNTS: dict[str, int] = {"idle": 8,- "listening": 4,- "thinking": 6,+ "listening": 6,+ "thinking": 8,"talking": 4,- "success": 6,- "error": 4,- "sleeping": 4,+ "success": 8,+ "error": 6,+ "sleeping": 6,}FPS: dict[str, int] = {- "idle": 4,+ "idle": 6,"listening": 8,"thinking": 8,"talking": 10,"success": 10,- "error": 8,- "sleeping": 2,+ "error": 9,+ "sleeping": 3,}-IDLE_BOB = (0, 0, -1, -1, 0, 0, -1, -1)-IDLE_BLINK_FRAME = 5-HOP = (0, -3, -5, -3, 0, 0)-SHAKE = (-2, 2, -2, 0)-TALK_MOUTHS = ("closed", "half", "open", "half")+#: The idle row's blink: its last cell, once every third breath.+IDLE_ACCENT = {"accent_frames": 1, "accent_every": 3}+#: One slow breath over the seven ordinary idle cells (1 = a pixel taller).+IDLE_BREATH = (0, 0, 1, 1, 1, 0, 0)+SLEEP_BREATH = (0, 0, 1, 1, 0, 0)+#: The success hop: a squash to push off, up, down, a squash to land.+HOP = (0, -2, -4, -5, -4, -2, 0, 0)+HOP_STRETCH = (-1, 1, 1, 0, 0, 1, -1, 0)+SHAKE = (-2, 2, -2, 2, -1, 0)+#: Closed to widest: the renderer picks one by the live voice level.+TALK_MOUTHS = ("closed", "half", "open", "wide")@dataclass(frozen=True)@@ -319,26 +335,29 @@ class Pose:dy: int = 0eyes: str = "open"mouth: str = "rest"+ #: 1 = the body above its waist one pixel taller, -1 = one shorter.+ stretch: int = 0def base_pose(state: str, i: int) -> Pose:if state == "idle":- eyes = "closed" if i == IDLE_BLINK_FRAME else "open"- return Pose(state, i, dy=IDLE_BOB[i], eyes=eyes)+ if i >= len(IDLE_BREATH):+ return Pose(state, i, eyes="closed") # the blink (the accent cell)+ return Pose(state, i, stretch=IDLE_BREATH[i])if state == "listening":- return Pose(state, i, dy=-1, eyes="wide")+ # Attentive: lifted and standing tall, eyes wide.+ return Pose(state, i, dy=-1, eyes="wide", stretch=1)if state == "thinking":- return Pose(- state, i, dy=0 if i < 3 else -1, eyes="up_left" if i < 3 else "up_right", mouth="closed"- )+ early = i < 4+ return Pose(state, i, eyes="up_left" if early else "up_right", mouth="closed")if state == "talking":- return Pose(state, i, dy=0 if i % 2 == 0 else -1, mouth=TALK_MOUTHS[i])+ return Pose(state, i, dy=0 if i < 2 else -1, mouth=TALK_MOUTHS[i])if state == "success":- return Pose(state, i, dy=HOP[i], eyes="happy", mouth="smile")+ return Pose(state, i, dy=HOP[i], eyes="happy", mouth="smile", stretch=HOP_STRETCH[i])if state == "error":return Pose(state, i, dx=SHAKE[i], eyes="x", mouth="frown")if state == "sleeping":- return Pose(state, i, dy=1, eyes="sleep", mouth="closed")+ return Pose(state, i, dy=1, eyes="sleep", mouth="closed", stretch=SLEEP_BREATH[i])raise KeyError(state)@@ -447,6 +466,10 @@ def draw_mouth(f.paint(rect(x, y, x + w - 1, y + 2) - {(x, y + 2), (x + w - 1, y + 2)}, inside)f.paint(rect(x + 1, y + 2, x + w - 2, y + 2), TONGUE)f.paint(rect(x, y, x + w - 1, y), color)+ elif style == "wide":+ f.paint(rect(x, y, x + w - 1, y + 3) - {(x, y + 3), (x + w - 1, y + 3)}, inside)+ f.paint(rect(x + 1, y + 2, x + w - 2, y + 3), TONGUE)+ f.paint(rect(x, y, x + w - 1, y), color)else:raise KeyError(style)@@ -459,28 +482,43 @@ _ARC_S = ((0, -2), (1, -1), (1, 0), (0, 1))_ARC_M = ((0, -3), (1, -2), (2, -1), (2, 0), (1, 1), (0, 2))_ARC_L = ((0, -4), (1, -3), (2, -2), (2, -1), (2, 0), (2, 1), (1, 2), (0, 3))_ARCS = ((0, _ARC_S), (3, _ARC_M), (6, _ARC_L))-#: Which arcs show in listening frame i: a ripple moving outward.-_ARC_PHASES = ((0,), (0, 1), (0, 1, 2), (1, 2))+#: Which arcs show in listening frame i, and whether each is fading: a ripple+#: that grows outward, fades from the inside and leaves a beat of silence.+_ARC_PHASES: tuple[tuple[tuple[int, bool], ...], ...] = (+ ((0, False),),+ ((0, False), (1, False)),+ ((0, False), (1, False), (2, False)),+ ((0, True), (1, False), (2, False)),+ ((1, True), (2, True)),+ (),+)def fx_arcs(f: Frame, i: int, left: Px, right: Px) -> None:"""Sound arcs rippling out from ``left`` (leftwards) and ``right`` (rightwards)."""- shown: Mask = set()- for index in _ARC_PHASES[i % len(_ARC_PHASES)]:+ for index, fading in _ARC_PHASES[i % len(_ARC_PHASES)]:off, arc = _ARCS[index]- shown |= {(right[0] + off + ax, right[1] + ay) for ax, ay in arc}+ shown = {(right[0] + off + ax, right[1] + ay) for ax, ay in arc}shown |= {(left[0] - off - ax, left[1] + ay) for ax, ay in arc}- f.paint(shown, ARC)+ f.paint(shown, ARC_FADE if fading else ARC)def fx_dots(f: Frame, i: int, x: int, y: int) -> None:- """Three thinking dots starting at ``(x, y)``; one hops per frame."""- active = i % 3+ """Three thinking dots orbiting a point above the head (``(x, y)`` is the+ old row's left end; the orbit centres where its middle dot sat).++ One full turn takes eight frames; a dot on the near side of the orbit is+ bright, one going round the back dims — a little planet of thoughts.+ """+ cx, cy = x + 4.5, y + 0.5dots: dict[Px, RGBA] = {}for k in range(3):- lift = 1 if k == active else 0- color = FX_WHITE if k == active else FX_DIM- for p in rect(x + 4 * k, y - lift, x + 4 * k + 1, y - lift + 1):+ angle = 2.0 * math.pi * (i / 8.0 + k / 3.0)+ dx = round(math.cos(angle) * 7.0, 6)+ dy = round(math.sin(angle) * 2.0, 6)+ px, py = math.floor(cx + dx), math.floor(cy + dy)+ color = FX_WHITE if dy >= 0 else FX_DIM+ for p in rect(px, py, px + 1, py + 1):dots[p] = colorf.part(set(dots), dots)@@ -491,10 +529,10 @@ _SPARK_PALETTE = {"#": SPARK, "o": SPARK_CORE}def fx_sparkles(f: Frame, i: int, spots: Sequence[tuple[int, int, int]]) -> None:- """Sparkles at ``(x, y, first_frame)`` centres: small, big, then small again."""+ """Sparkles at ``(x, y, first_frame)`` centres: small, big, small, gone."""for x, y, start in spots:age = i - start- if age < 0:+ if age < 0 or age > 4:continuerows = _SPARK_L if age in (1, 2) else _SPARK_Shalf = len(rows) // 2@@ -506,14 +544,17 @@ _Z_BIG = ("#####", "...#.", "..#..", ".#...", "#####")_Z_PALETTE = {"#": Z_BLUE}#: (dx, dy, glyph) of each z relative to the anchor, lowest first._ZS = ((0, 0, _Z_SMALL), (5, -6, _Z_BIG), (2, -12, _Z_SMALL))-#: Which z marks show in sleeping frame i: they rise one by one.-_Z_PHASES = ((0,), (0, 1), (0, 1, 2), (1, 2))+#: Which z marks show in sleeping frame i: they rise one by one, drift up a+#: pixel while they float, and the oldest leaves first.+_Z_PHASES = ((0,), (0,), (0, 1), (0, 1), (1, 2), (2,))+_Z_DRIFT = (0, -1, 0, -1, 0, -1)def fx_zzz(f: Frame, i: int, x: int, y: int) -> None:+ drift = _Z_DRIFT[i % len(_Z_DRIFT)]for index in _Z_PHASES[i % len(_Z_PHASES)]:dx, dy, rows = _ZS[index]- f.glyph(x + dx, y + dy, rows, _Z_PALETTE)+ f.glyph(x + dx, y + dy + drift, rows, _Z_PALETTE)_BANG = ("##", "##", "##", "##", "..", "##")@@ -523,6 +564,14 @@ def fx_bang(f: Frame, x: int, y: int) -> None:f.glyph(x, y, _BANG, {"#": RED})+_DROP = (".#.", "###", "#o#", ".#.")+++def fx_sweat(f: Frame, i: int, x: int, y: int) -> None:+ """A sweat drop that slides down the side of the head, a pixel a frame."""+ f.glyph(x, y + min(i, 4), _DROP, {"#": SWEAT, "o": SWEAT_SHINE})++@dataclass(frozen=True)class Anchors:"""Where a pet's effects go (cell coordinates, before the pose offset)."""@@ -533,6 +582,9 @@ class Anchors:zzz: Pxbang: Pxsparkles: tuple[tuple[int, int, int], ...]+ #: Where the error's sweat drop starts (its top-left); next to the "!"+ #: unless a pet says otherwise.+ sweat: Px | None = Nonedef draw_effects(f: Frame, pose: Pose, a: Anchors) -> None:@@ -547,6 +599,9 @@ def draw_effects(f: Frame, pose: Pose, a: Anchors) -> None:fx_sparkles(f, pose.i, a.sparkles)elif pose.state == "error":fx_bang(f, *a.bang)+ sx, sy = a.sweat if a.sweat is not None else (a.bang[0] - 6, a.bang[1] + 7)+ with f.offset(pose.dx, 0):+ fx_sweat(f, pose.i, sx, sy)elif pose.state == "sleeping":fx_zzz(f, pose.i, *a.zzz)@@ -571,6 +626,9 @@ class PetDesign:fps: Mapping[str, int] | None = None#: Per-state effects that replace the shared one (a pet's own motif).fx: Mapping[str, Effect] = field(default_factory=dict)+ #: The waist: the row the breath stretches the body above. Everything+ #: below it (feet, paws, the foot of a teapot) stays planted.+ waist: int = 31def counts(self) -> Mapping[str, int]:return {**FRAME_COUNTS, **(self.frame_counts or {})}@@ -620,7 +678,8 @@ def draw_gigi(f: Frame, pose: Pose) -> None:f.part(arm, GIGI_GOLD)f.part(mirrored(arm), GIGI_GOLD)body = _gigi_body(phase)- f.part(body, shade(body, GIGI_BODY, rim=GIGI_RIM))+ glowing = pose.state == "thinking" and (pose.i // 2) % 2 == 1+ f.part(body, shade(body, GIGI_BODY, rim=GIGI_GOLD if glowing else GIGI_RIM))f.paint(ellipse(CX, 22, 10, 7), GIGI_PLATE)f.paint({(14, 16), (15, 15), (16, 14), (17, 14), (18, 13)}, GIGI_GLOSS)f.paint(rect(11, 31, 36, 31), GIGI_BELT)@@ -638,8 +697,12 @@ def _gigi_mouth(f: Frame, style: str) -> None:f.paint(ring, GIGI_GOLD)f.paint(rect(23, 35, 24, 35), GIGI_PLATE)elif style == "open":- big = from_rows(22, 33, (".##.", "#..#", "#..#", "#..#", ".##."))- f.paint(rect(23, 34, 24, 36), GIGI_PLATE)+ mid = from_rows(22, 33, (".##.", "#..#", "#..#", ".##."))+ f.paint(rect(23, 34, 24, 35), GIGI_PLATE)+ f.paint(mid, GIGI_GOLD)+ elif style == "wide":+ big = from_rows(21, 32, (".####.", "#....#", "#....#", "#....#", ".####."))+ f.paint(rect(22, 33, 25, 35), GIGI_PLATE)f.paint(big, GIGI_GOLD)elif style == "smile":f.paint(from_rows(21, 34, ("#....#", ".####.")), GIGI_GOLD)@@ -755,12 +818,14 @@ MISO = PetDesign(name="Miso",description="A ginger cat whose ears perk up when you talk and who naps curled in a loaf.",draw=draw_miso,+ waist=33,anchors=Anchors(arcs_left=(10, 18),arcs_right=(37, 18),dots=(19, 3),zzz=(31, 22),bang=(40, 4),+ sweat=(33, 12),sparkles=((6, 12, 1), (41, 9, 2), (5, 32, 3), (42, 30, 3)),),)@@ -782,9 +847,9 @@ BREW_AXIS = 22def _brew_lid_lift(pose: Pose) -> int:- if pose.state == "talking" and pose.i % 2 == 1:- return 2- if pose.state == "success" and pose.i in (1, 2, 3):+ if pose.state == "talking":+ return (0, 0, 1, 2)[pose.i]+ if pose.state == "success" and pose.i in (2, 3, 4):return 2return 0@@ -823,18 +888,23 @@ def brew_thinking(f: Frame, pose: Pose) -> None:fx_dots(f, pose.i, 14, 7)puffs = []for k in range(3):- phase = (pose.i + 2 * k) % 6- puffs.append((42 + phase % 2, 16 - 2 * phase, phase >= 2))+ phase = (pose.i + 3 * k) % 8+ if phase < 6:+ puffs.append((42 + phase % 2, 16 - 2 * phase, phase >= 2))_brew_puffs(f, puffs)def brew_talking(f: Frame, pose: Pose) -> None:"""The whistle: a quick jet of steam from the spout while the lid rattles."""with f.offset(pose.dx, pose.dy):- if pose.i % 2:- _brew_puffs(f, ((43, 16, False), (44, 12, True)))- else:- _brew_puffs(f, ((43, 16, True), (45, 12, False)))+ # More steam the wider the mouth: nothing, a wisp, a puff, a jet.+ jets = (+ (),+ ((43, 17, False),),+ ((43, 16, True), (45, 12, False)),+ ((43, 16, True), (44, 12, True), (45, 8, False)),+ )+ _brew_puffs(f, jets[pose.i])BREW = PetDesign(@@ -848,9 +918,11 @@ BREW = PetDesign(dots=(14, 7),zzz=(31, 14),bang=(38, 4),+ sweat=(31, 21),sparkles=((5, 14, 1), (40, 10, 2), (4, 40, 3), (41, 34, 3)),),fx={"thinking": brew_thinking, "talking": brew_talking},+ waist=39,)@@ -935,12 +1007,14 @@ BOLT = PetDesign(name="Bolt",description="A plucky battery that charges up while it thinks and runs flat when it sleeps.",draw=draw_bolt,+ waist=23,anchors=Anchors(arcs_left=(12, 15),arcs_right=(35, 15),dots=(19, 2),zzz=(36, 14),bang=(38, 3),+ sweat=(35, 9),sparkles=((6, 10, 1), (41, 8, 2), (5, 36, 3), (42, 34, 3)),),pose=bolt_pose,@@ -959,9 +1033,9 @@ MOCHI_INK = hexc("#3b1f2b")MOCHI_EYES = EyeStyle(w=3, h=4, iris=MOCHI_INK, glint=FX_WHITE, lid=MOCHI_INK)#: (wider, lower, sway) per listening frame: the wobble.-_MOCHI_WOBBLE = ((0, 0, 0), (1, 1, 1), (0, 0, 0), (-1, -1, -1))-#: (wider, lower) per talking frame: squish with every syllable.-_MOCHI_SQUISH = ((0, 0), (1, 1), (2, 2), (1, 1))+_MOCHI_WOBBLE = ((0, 0, 0), (1, 1, 1), (1, 1, 1), (0, 0, 0), (-1, -1, -1), (-1, -1, -1))+#: (wider, lower) per talking frame, closed to widest: the louder, the squishier.+_MOCHI_SQUISH = ((0, 0), (1, 0), (1, 1), (2, 2))def mochi_pose(state: str, i: int) -> Pose:@@ -981,11 +1055,9 @@ def _mochi_shape(pose: Pose) -> tuple[int, int, int]:if pose.state == "success":if pose.dy < 0:return (-1, -2, 0)- return (2, 2, 0) if pose.i == 4 else (0, 0, 0)+ return (2, 2, 0) if pose.stretch < 0 else (0, 0, 0)if pose.state == "sleeping":return (2, 3, 0)- if pose.state == "idle" and pose.dy < 0:- return (-1, -1, 0)return (0, 0, 0)@@ -1021,9 +1093,11 @@ MOCHI = PetDesign(dots=(19, 15),zzz=(34, 17),bang=(39, 7),+ sweat=(33, 22),sparkles=((6, 14, 1), (41, 12, 2), (4, 38, 3), (43, 36, 3)),),pose=mochi_pose,+ waist=39,)@@ -1092,7 +1166,8 @@ def draw_shelly(f: Frame, pose: Pose) -> None:look = {"listening": "perk", "success": "perk", "error": "droop"}.get(pose.state, "rest")sway = (0, 1, 1, 0)[(pose.i // 2) % 4] if pose.state == "idle" else 0tips = tuple((x + sway, y) for x, y in _SHELLY_TIPS[look])- phase = -pose.i * (2.0 * math.pi / 6.0) if pose.state == "thinking" else 0.0+ turn = FRAME_COUNTS["thinking"]+ phase = -pose.i * (2.0 * math.pi / turn) if pose.state == "thinking" else 0.0with f.offset(pose.dx, pose.dy):for base, tip in zip(_SHELLY_STALK_BASES, tips, strict=True):f.part(line(*base, *tip), SHELLY_BODY)@@ -1123,12 +1198,14 @@ SHELLY = PetDesign(name="Shelly",description="A patient snail whose shell spins while it thinks and who hides inside to sleep.",draw=draw_shelly,+ waist=38,anchors=Anchors(arcs_left=(8, 6),arcs_right=(21, 7),dots=(27, 8),zzz=(35, 15),bang=(40, 4),+ sweat=(17, 24),sparkles=((3, 26, 1), (41, 10, 2), (3, 40, 3), (44, 28, 3)),),)@@ -1141,16 +1218,37 @@ PETS: tuple[PetDesign, ...] = (GIGI, MISO, BREW, BOLT, MOCHI, SHELLY)# ---------------------------------------------------------------------------+def breathe(body: Image.Image, stretch: int, waist: int) -> Image.Image:+ """Stretch (``1``) or squash (``-1``) everything above ``waist`` by a pixel.++ Stretching lifts the rows above the waist and repeats the waist row under+ them; squashing drops the waist row and lowers the rows above it. The+ feet never move, and a 1 px change reads as a breath at any scale.+ """+ if stretch == 0 or not 2 <= waist < body.height:+ return body+ out = body.copy()+ if stretch > 0:+ out.paste(body.crop((0, 1, body.width, waist)), (0, 0))+ else:+ out.paste(body.crop((0, 0, body.width, waist - 1)), (0, 1))+ out.paste((0, 0, 0, 0), (0, 0, body.width, 1))+ return out++def render_frame(pet: PetDesign, state: str, i: int) -> Image.Image:pose = pet.pose(state, i)- f = Frame()- pet.draw(f, pose)+ body = Frame()+ pet.draw(body, pose)+ image = breathe(body.image(), pose.stretch, pet.waist + pose.dy)+ fx = Frame()own = pet.fx.get(state)if own is not None:- own(f, pose)+ own(fx, pose)else:- draw_effects(f, pose, pet.anchors)- return f.image()+ draw_effects(fx, pose, pet.anchors)+ image.alpha_composite(fx.image())+ return imagedef build_sheet(pet: PetDesign) -> Image.Image:@@ -1173,17 +1271,23 @@ def build_manifest(pet: PetDesign) -> dict:"frame_size": CELL,"sheet": "sheet.png","animations": {- state: {- "row": row,- "frames": counts[state],- "fps": fps[state],- "loop": state not in ONE_SHOT_STATES,- }- for row, state in enumerate(PET_STATES)+ state: _animation(state, row, counts, fps) for row, state in enumerate(PET_STATES)},}+def _animation(state: str, row: int, counts: Mapping[str, int], fps: Mapping[str, int]) -> dict:+ spec = {+ "row": row,+ "frames": counts[state],+ "fps": fps[state],+ "loop": state not in ONE_SHOT_STATES,+ }+ if state == "idle":+ spec.update(IDLE_ACCENT)+ return spec++#: Row tints of the template, one per state (alpha stays below the loader's#: opacity threshold, so an untouched cell reads as empty).TEMPLATE_TINTS: dict[str, tuple[int, int, int]] = {@@ -1214,13 +1318,7 @@ def build_template() -> tuple[Image.Image, dict]:"frame_size": CELL,"sheet": "template.png","animations": {- state: {- "row": row,- "frames": FRAME_COUNTS[state],- "fps": FPS[state],- "loop": state not in ONE_SHOT_STATES,- }- for row, state in enumerate(PET_STATES)+ state: _animation(state, row, FRAME_COUNTS, FPS) for row, state in enumerate(PET_STATES)},}return sheet, manifestdiff --git a/tests/unit/ui/pets/test_builtin_pets.py b/tests/unit/ui/pets/test_builtin_pets.pyindex 23a6f069fd..c8a78aca74 100644--- a/tests/unit/ui/pets/test_builtin_pets.py+++ b/tests/unit/ui/pets/test_builtin_pets.py@@ -104,3 +104,16 @@ def test_template_cells_read_as_empty() -> None:with Image.open(PACKAGE_DIR / "template" / "template.png") as image:alpha = image.convert("RGBA").getchannel("A")assert max(alpha.tobytes()) < 128++[email protected]("pet_id", EXPECTED_PETS)+def test_the_renderer_conventions_hold(pet_id: str) -> None:+ """Idle blinks on its last cell every few breaths; talking opens up a row."""+ pack = load_pet(builtin_root() / pet_id, builtin=True)+ idle = pack.manifest.animations["idle"]+ assert idle.loop and idle.accent_frames == 1 and idle.accent_every >= 2+ assert pack.manifest.animations["talking"].frames == 4+ # Closed to widest: every talking frame differs from the one before it.+ talking = pack.frames["talking"]+ for before, after in zip(talking, talking[1:], strict=False):+ assert before.tobytes() != after.tobytes()diff --git a/tests/unit/ui/pets/test_manifest.py b/tests/unit/ui/pets/test_manifest.pyindex 2b3f4e866e..ab51afe79a 100644--- a/tests/unit/ui/pets/test_manifest.py+++ b/tests/unit/ui/pets/test_manifest.py@@ -169,3 +169,44 @@ def test_check_sheet_size_limits() -> None:for width, height in ((0, 10), (513, 10), (10, 513)):with pytest.raises(PetManifestError):check_sheet_size(width, height)+++# --- the optional accent (a blink every few loops) -------------------------------+++def test_an_accent_parses_and_round_trips() -> None:+ animations = _animations(frames=8, accent_frames=1, accent_every=3)+ manifest = parse_manifest(_data(animations=animations), builtin=True)+ idle = manifest.animations["idle"]+ assert (idle.accent_frames, idle.accent_every) == (1, 3)+ assert manifest.to_json()["animations"]["idle"]["accent_frames"] == 1+ assert parse_manifest(manifest.to_json(), builtin=True) == manifest+++def test_no_accent_keeps_the_file_shape() -> None:+ manifest = parse_manifest(_data(), builtin=True)+ assert manifest.animations["idle"].accent_frames == 0+ assert "accent_frames" not in manifest.to_json()["animations"]["idle"]+++ "changes",+ [+ {"accent_frames": 4}, # the whole row: nothing ordinary left+ {"accent_frames": -1, "accent_every": 2},+ {"accent_frames": 1, "accent_every": 0},+ {"accent_frames": 1, "accent_every": 13},+ {"accent_frames": 1}, # needs both keys+ {"accent_frames": True, "accent_every": 2},+ ],+)+def test_accent_rule_rejections(changes: dict) -> None:+ with pytest.raises(PetManifestError):+ parse_manifest(_data(animations=_animations(**changes)), builtin=True)+++def test_an_accent_needs_a_looping_row() -> None:+ animations = _animations()+ animations["success"].update({"accent_frames": 1, "accent_every": 2})+ with pytest.raises(PetManifestError):+ parse_manifest(_data(animations=animations), builtin=True)diff --git a/tests/unit/ui/test_orb_controls_pet.py b/tests/unit/ui/test_orb_controls_pet.pyindex 9f0fdf89ad..b8bf0bbbfa 100644--- a/tests/unit/ui/test_orb_controls_pet.py+++ b/tests/unit/ui/test_orb_controls_pet.py@@ -245,3 +245,48 @@ def test_concurrent_toggles_never_lose_the_remembered_volume(pipeline: _Pipelinefor worker in workers:worker.join(timeout=10.0)assert pipeline._volume == pytest.approx(0.7)+++# --- the Codex-like look: filled discs, a glossy orb, proportions --------------------+++def test_the_pen_and_the_pill_are_filled_without_a_ring() -> None:+ frame = controls.render_pet_strip(controls.PetStripState(), 1.0)+ layout = controls.pet_strip_layout(1.0)+ pcx, pcy, pr = layout.pen+ # Just inside the disc's edge is the fill itself, not a lighter border.+ edge = frame.getpixel((int(pcx), int(pcy - pr + 2)))+ assert edge == controls.PET_FILL+ x0, y0, x1, y1 = layout.pill+ assert frame.getpixel(((x0 + x1) // 2, y0 + 1)) == controls.PET_FILL+++def test_the_orb_fills_most_of_the_pill_height() -> None:+ frame = controls.render_pet_strip(controls.PetStripState(), 2.0)+ layout = controls.pet_strip_layout(2.0)+ action, sx0, sx1 = layout.slots[1]+ assert action == "orb"+ x0, y0, x1, y1 = layout.pill+ cx = (sx0 + sx1) // 2+ column = [frame.getpixel((cx, y)) for y in range(y0, y1)]+ blue = [px for px in column if px[2] > 150 and px[2] > px[0] + 40]+ share = len(blue) / (y1 - y0)+ assert 0.7 <= share <= 0.9+++def test_the_strip_is_about_a_third_of_the_figure_tall() -> None:+ from ui.orb.pet_renderer import PET_TARGET_FIGURE_PX++ _w, h = controls.pet_strip_size(1.0)+ assert 0.25 <= h / PET_TARGET_FIGURE_PX <= 0.35+++def test_hover_lifts_a_round_patch_not_the_whole_slot() -> None:+ plain = controls.render_pet_strip(controls.PetStripState(), 1.0)+ hovered = controls.render_pet_strip(controls.PetStripState(hovered="speaker"), 1.0)+ layout = controls.pet_strip_layout(1.0)+ _action, sx0, sx1 = layout.slots[2]+ _x0, y0, _x1, _y1 = layout.pill+ # The slot's top corner stays the plain fill; its middle edge lightens.+ assert hovered.getpixel((sx0 + 1, y0 + 1)) == plain.getpixel((sx0 + 1, y0 + 1))+ assert hovered.getpixel(((sx0 + sx1) // 2, y0 + 5)) == controls.PET_FILL_HOVERdiff --git a/tests/unit/ui/test_pet_overlay_renderer.py b/tests/unit/ui/test_pet_overlay_renderer.pyindex 64281170f4..4fb10ad2d1 100644--- a/tests/unit/ui/test_pet_overlay_renderer.py+++ b/tests/unit/ui/test_pet_overlay_renderer.py@@ -104,25 +104,23 @@ def _renderer(clock: _Clock, **kwargs) -> tuple[pr.PetRenderer, list[int]]:# --- pure helpers --------------------------------------------------------------def test_a_48_pixel_sheet_is_drawn_at_exactly_3x_at_100_percent() -> None:- assert pr.pixel_factor(48, 1.0, 1.0) == 3---def test_other_sheet_sizes_land_near_the_same_on_screen_size() -> None:- assert pr.pixel_factor(32, 1.0, 1.0) * 32 == pytest.approx(pr.PET_TARGET_EDGE_PX, abs=16)- assert pr.pixel_factor(64, 1.0, 1.0) * 64 == pytest.approx(pr.PET_TARGET_EDGE_PX, abs=16)[email protected]("extent", [24, 30, 36, 40, 48, 64])+def test_every_figure_lands_near_the_target_size_at_100_percent(extent: int) -> None:+ on_screen = pr.pixel_factor(extent, 1.0, 1.0) * extent+ assert on_screen == pytest.approx(pr.PET_TARGET_FIGURE_PX, abs=extent / 2)def test_the_factor_follows_dpi_and_user_size_and_rounds_half_up() -> None:- assert pr.pixel_factor(48, 1.5, 1.0) == 5 # 4.5 -> 5, never banker's 4- assert pr.pixel_factor(48, 2.0, 1.0) == 6- assert pr.pixel_factor(48, 1.0, 2.0) == 6- assert pr.pixel_factor(48, 1.0, 0.5) == 2+ assert pr.pixel_factor(40, 1.0, 1.0) == 5 # 4.5 -> 5, never banker's 4+ assert pr.pixel_factor(40, 1.5, 1.0) == 7+ assert pr.pixel_factor(40, 2.0, 1.0) == 9+ assert pr.pixel_factor(40, 1.0, 2.0) == 9+ assert pr.pixel_factor(40, 1.0, 0.5) == 2def test_the_factor_never_drops_below_one_and_survives_garbage() -> None:assert pr.pixel_factor(64, 0.1, 0.1) == 1- assert pr.pixel_factor(48, float("nan"), 1.0) == 3+ assert pr.pixel_factor(48, float("nan"), 1.0) == 4assert pr.pixel_factor("x", 1.0, 1.0) == 1 # type: ignore[arg-type]@@ -158,15 +156,16 @@ def test_every_frame_is_scaled_once_at_load_and_never_while_painting() -> None:renderer, calls = _renderer(clock)scaled_at_load = len(calls)assert scaled_at_load == sum(len(v) for v in _Pack().frames.values())- assert set(calls) == {3}+ assert set(calls) == {4}for _ in range(50):clock.now += 0.07renderer.render()renderer.frame_key()renderer.next_frame_delay_ms()assert len(calls) == scaled_at_load- assert renderer.size == (144, 144)- assert renderer.render().size == (144, 144)+ # The fake frames fill their whole cell: no crop, 48 px at 4x.+ assert renderer.size == (192, 192)+ assert renderer.render().size == (192, 192)def test_a_new_size_rescales_and_reports_the_change() -> None:@@ -174,8 +173,8 @@ def test_a_new_size_rescales_and_reports_the_change() -> None:renderer, calls = _renderer(clock)calls.clear()assert renderer.set_look(pet_scale=2.0) is True- assert renderer.size == (288, 288)- assert set(calls) == {6}+ assert renderer.size == (384, 384)+ assert set(calls) == {8}assert renderer.set_look(pet_scale=2.0) is False # same size, no window change@@ -284,7 +283,7 @@ def test_switching_pets_keeps_the_state_machine() -> None:renderer.on_mode("listen")renderer.load("miso")assert renderer.state() == "listening"- assert renderer.size == (160, 160) # 32 px at the nearest factor (5x)+ assert renderer.size == (192, 192) # 32 px at the nearest factor (6x)assert renderer.frame_key()[0] == "miso"@@ -296,8 +295,10 @@ def test_the_built_in_default_pet_loads_through_the_real_engine() -> None:clock = _Clock()renderer = pr.PetRenderer("gigi", clock=clock, dpi_ratio=1.0)assert renderer.has_figure- edge = renderer.size[0]- assert renderer.size == (edge, edge)+ # Cropped to the figure, and the figure is about the target size.+ target = pr.PET_TARGET_FIGURE_PX+ assert 0.6 * target <= renderer.figure_width <= 1.25 * target+ assert renderer.size[0] >= renderer.figure_widthassert renderer.render().mode == "RGB"for mode in ("idle", "listen", "think", "speak", "notice"):renderer.on_mode(mode)@@ -346,3 +347,98 @@ def test_a_frame_that_will_not_scale_leaves_the_strip_only() -> None:assert renderer._frames == {} # noqa: SLF001 — nothing half-filled is keptassert renderer.size[1] == 1assert renderer.render().size == renderer.size+++# --- the crop, the blink accent and the voice-driven mouth ---------------------------+++def _boxed(frame_size: int, box: tuple[int, int, int, int]) -> Image.Image:+ frame = Image.new("RGBA", (frame_size, frame_size), (0, 0, 0, 0))+ frame.paste((200, 100, 50, 255), box)+ return frame+++class _BoxedPack(_Pack):+ """Frames with a small opaque figure; the success row adds a far sparkle."""++ def __init__(self) -> None:+ super().__init__()+ for state in self.frames:+ self.frames[state] = tuple(_boxed(48, (14, 10, 34, 40)) for _ in range(2))+ sparkle = _boxed(48, (14, 10, 34, 40))+ sparkle.paste((255, 220, 0, 255), (40, 4, 42, 6))+ self.frames["success"] = (sparkle,)+++def test_the_crop_is_symmetric_and_covers_every_effect() -> None:+ pack = _BoxedPack()+ crop, idle = pr.figure_crop(pack.frames, 48)+ assert idle == (20, 30) # the body alone sets the size+ x0, y0, x1, y1 = crop+ assert 24 - x0 == x1 - 24 # centred on the cell's middle line+ assert x1 >= 42 and y0 <= 4 # the sparkle stays inside the window+ assert y1 == 40 # the window ends at the lowest painted row+++def test_the_window_is_the_crop_at_the_figure_factor() -> None:+ clock = _Clock()+ pack = _BoxedPack()+ renderer, calls = _renderer(clock, loader=_Loader({"fake": pack}))+ crop, (idle_w, idle_h) = pr.figure_crop(pack.frames, 48)+ factor = pr.pixel_factor(max(idle_w, idle_h), 1.0, 1.0)+ assert set(calls) == {factor}+ assert renderer.size == ((crop[2] - crop[0]) * factor, (crop[3] - crop[1]) * factor)+ assert renderer.figure_width == idle_w * factor+ assert renderer.render().size == renderer.size+++def test_an_accent_plays_once_every_few_loops() -> None:+ # Seven breathing frames, then the blink, once every third pass.+ seen = [+ pr.frame_index(step / 6.0 + 1e-6, 8, 6, True, accent_frames=1, accent_every=3)+ for step in range(23)+ ]+ assert seen[:21] == list(range(7)) * 3+ assert seen[21] == 7+ assert seen[22] == 0+ # Without an accent every cell plays on every loop.+ assert pr.frame_index(7 / 6.0 + 1e-6, 8, 6, True) == 7+++def test_the_mouth_follows_the_level_and_swings_without_one() -> None:+ swing = [pr.ping_pong_index(step / 10.0 + 1e-6, 4, 10) for step in range(8)]+ assert swing == [0, 1, 2, 3, 2, 1, 0, 1]+ assert pr.level_frame(0.0, 4) == 0+ assert pr.level_frame(pr.LEVEL_SILENCE / 2, 4) == 0+ assert pr.level_frame(pr.LEVEL_SILENCE + 0.01, 4) == 1+ assert pr.level_frame(1.0, 4) == 3+++def test_a_live_level_drives_the_talking_frame() -> None:+ clock = _Clock()+ renderer, _ = _renderer(clock)+ renderer.on_mode("speak")+ renderer.feed_level(0.9, clock.now)+ key = renderer.frame_key()+ assert key[-1] == 3 # loud: the widest mouth+ assert renderer.next_frame_delay_ms() == pr.LEVEL_POLL_MS + 2+ # The same smoothed level gives the same key: no repaint.+ assert renderer.frame_key() == key+ # Quiet: the mouth closes once the smoothing catches up.+ for _ in range(8):+ clock.now += 0.05+ renderer.feed_level(0.0, clock.now)+ assert renderer.frame_key()[-1] == 0+ # The voice stopped arriving: back to the swing at the manifest rate.+ clock.now += pr.LEVEL_FRESH_S + 0.05+ assert renderer.next_frame_delay_ms() <= 105+++def test_garbage_levels_are_ignored() -> None:+ clock = _Clock()+ renderer, _ = _renderer(clock)+ renderer.on_mode("speak")+ renderer.feed_level(None, clock.now)+ renderer.feed_level(float("nan"), clock.now)+ renderer.feed_level("loud", clock.now) # type: ignore[arg-type]+ assert renderer.frame_key()[-1] in range(4)diff --git a/tests/unit/ui/test_pet_overlay_surface.py b/tests/unit/ui/test_pet_overlay_surface.pyindex 93646381f3..7b7910d316 100644--- a/tests/unit/ui/test_pet_overlay_surface.py+++ b/tests/unit/ui/test_pet_overlay_surface.py@@ -7,6 +7,7 @@ proxy, DesktopApp's pet methods update the config and degrade without asurface, a live swap between orb looks changes the bridge's idle regime, andthe speaker control names itself to the pipeline when the pipeline asks."""+from __future__ import annotationsfrom types import SimpleNamespace@@ -280,7 +281,6 @@ def test_the_speaker_toggle_still_works_with_an_older_setter(live_pipeline) -> Nassert pipeline.volume == pytest.approx(0.8)-@pytest.mark.parametrize("style,source", [("pet", "pet"), ("voice_orb", "orb")])def test_the_macos_speaker_disc_names_its_source(live_pipeline, style: str, source: str) -> None:pipeline = live_pipeline(_SourcePipeline())@@ -317,3 +317,184 @@ def test_a_drag_only_moves_the_painted_status_bubble() -> None:assert top.geometries == ["+380+300", "+380+640"]assert repaints == []+++# --- the status card: layout, clear and fade, forwarding ----------------------------------+++def _card() -> OrbCommentBubble:+ bubble = OrbCommentBubble.__new__(OrbCommentBubble) # no Tk: geometry only+ bubble._screen_w = 1920 # noqa: SLF001+ bubble._ui_scale = 1.0 # noqa: SLF001+ bubble._status_max_w = None # noqa: SLF001+ bubble._status_expanded = False # noqa: SLF001+ return bubble+++def _chars(text: str) -> int:+ return 7 * len(text)+++def test_a_short_status_is_a_compact_full_pill() -> None:+ bubble = _card()+ width, height, title, detail, radius = bubble.card_layout(+ "Thinking", "Reading the calendar", _chars, _chars, 18, 16+ )+ assert title == ["Thinking"] and detail == ["Reading the calendar"]+ assert width < 380 # sized to its text, not to a fixed width+ assert radius == height // 2 # two lines collapsed: fully rounded ends+++def test_long_text_is_clipped_with_an_ellipsis_and_capped_by_the_strip() -> None:+ bubble = _card()+ bubble.set_status_max_width(300)+ long = "word " * 80+ width, _height, title, detail, _radius = bubble.card_layout(long, long, _chars, _chars, 18, 16)+ assert 250 <= width <= 300 # the cap; the ellipsised line sets the rest+ assert len(title) == 1 and title[0].endswith("…")+ assert len(detail) == 1 and detail[0].endswith("…")+++def test_a_click_expands_the_detail_to_three_lines_keeping_the_end_radius() -> None:+ bubble = _card()+ long = "word " * 80+ collapsed = bubble.card_layout("Title", long, _chars, _chars, 18, 16)+ bubble._status_expanded = True # noqa: SLF001+ expanded = bubble.card_layout("Title", long, _chars, _chars, 18, 16)+ assert len(expanded[3]) == 3+ assert expanded[1] > collapsed[1]+ assert expanded[4] == collapsed[4]+++class _FakeTop:+ """Just enough of a Toplevel for the clear/fade timers."""++ def __init__(self) -> None:+ self.pending: dict[str, tuple[int, object]] = {}+ self.alphas: list[float] = []+ self.withdrawn = 0+ self._next = 0++ def after(self, ms: int, fn: object) -> str:+ self._next += 1+ key = f"after#{self._next}"+ self.pending[key] = (ms, fn)+ return key++ def after_cancel(self, key: str) -> None:+ self.pending.pop(key, None)++ def wm_attributes(self, name: str, value: float) -> None:+ assert name == "-alpha"+ self.alphas.append(value)++ def withdraw(self) -> None:+ self.withdrawn += 1++ def run_next(self) -> int:+ key = next(iter(self.pending))+ ms, fn = self.pending.pop(key)+ fn() # type: ignore[operator]+ return ms+++def _showing_card() -> tuple[OrbCommentBubble, _FakeTop]:+ bubble = _card()+ top = _FakeTop()+ bubble._top = top # noqa: SLF001+ bubble._canvas = object() # noqa: SLF001+ bubble._status_showing = True # noqa: SLF001+ bubble._status_size = (240, 52) # noqa: SLF001+ bubble._status = ("Thinking", "") # noqa: SLF001+ bubble._status_anchor = (500, 300, 100, 1000) # noqa: SLF001+ bubble._clear_after_id = None # noqa: SLF001+ bubble._fade_after_id = None # noqa: SLF001+ bubble._status_clear_pending = False # noqa: SLF001+ bubble._dismiss_after_id = None # noqa: SLF001+ bubble._queue_after_id = None # noqa: SLF001+ bubble._queued_text = None # noqa: SLF001+ bubble._render_status = lambda: True # type: ignore[method-assign]+ return bubble, top+++def test_clear_lingers_then_fades_then_withdraws() -> None:+ bubble, top = _showing_card()+ bubble.clear_status(1.5)+ assert top.run_next() == 1500 # the linger+ while top.pending:+ top.run_next() # the fade steps+ fade = top.alphas[:-1]+ assert fade and all(a > b for a, b in zip(fade, fade[1:], strict=False))+ assert top.alphas[-1] == 1.0 # opacity restored for the next card+ assert top.withdrawn == 1+ assert bubble.status_showing is False+++def test_a_new_status_cancels_a_pending_clear() -> None:+ bubble, top = _showing_card()+ bubble.clear_status(1.5)+ assert top.pending+ bubble._cancel_timers = lambda: None # type: ignore[method-assign]+ bubble.show_status("Searching the web", "", anchor=(500, 300, 100, 1000))+ assert not top.pending+ assert bubble.status_showing is True+++def test_clear_with_no_linger_hides_at_once() -> None:+ bubble, top = _showing_card()+ bubble.clear_status(0)+ assert top.withdrawn == 1 and not top.pending+++def test_a_repeated_clear_keeps_the_first_deadline() -> None:+ bubble, top = _showing_card()+ bubble.clear_status(1.5)+ bubble.clear_status(1.5)+ assert len(top.pending) == 1+++def test_the_pet_surface_accepts_clear_before_the_window_exists() -> None:+ pet = OrbOverlay(style="pet")+ pet.clear_status()+ pet.clear_status(0)+ pet.show_listening_transcript("what the user said") # never echoed on the pet+ OrbOverlay(style="mascot").clear_status() # other looks ignore it+++def test_the_macos_proxy_forwards_title_detail_and_clear() -> None:+ proxy = SubprocessMascotOverlay(style="pet")+ sent: list[dict] = []+ proxy._send = sent.append # type: ignore[method-assign]+ proxy.show_status("Planning the answer", "Comparing two options")+ proxy.clear_status(2.0)+ assert sent == [+ {"op": "show_status", "title": "Planning the answer", "detail": "Comparing two options"},+ {"op": "clear_status", "linger_s": 2.0},+ ]+++class _StatusSurface:+ def __init__(self) -> None:+ self.calls: list[tuple] = []++ def show_status(self, title: str, detail: str) -> None:+ self.calls.append(("show_status", title, detail))++ def clear_status(self, linger_s: float) -> None:+ self.calls.append(("clear_status", linger_s))+++def test_the_host_dispatches_status_ops_including_the_old_keys() -> None:+ from jarvis.ui.jarvisbar import host++ surface = _StatusSurface()+ host.dispatch(surface, {"op": "show_status", "title": "A", "detail": "b"})+ host.dispatch(surface, {"op": "show_status", "header": "Old", "line": "keys"})+ host.dispatch(surface, {"op": "clear_status", "linger_s": 0.5})+ host.dispatch(surface, {"op": "clear_status"})+ assert surface.calls == [+ ("show_status", "A", "b"),+ ("show_status", "Old", "keys"),+ ("clear_status", 0.5),+ ("clear_status", 1.5),+ ]diff --git a/ui/orb/controls.py b/ui/orb/controls.pyindex 2d091ecad6..a7c2c4b066 100644--- a/ui/orb/controls.py+++ b/ui/orb/controls.py@@ -366,34 +366,57 @@ def render_row(# --- The pet's control strip -------------------------------------------------# The desktop pet (``docs/pets.md``) carries its controls in a different shape:-# a pen disc on its own, then ONE pill holding microphone mute, the talk orb and-# the speaker, separated by thin dividers. Same hard-edge rules as the row-# above: every silhouette that meets the colour key goes through a binary mask,-# every glyph is drawn at 4x and downscaled INSIDE its opaque surface.+# The desktop pet (``docs/pets.md``) carries its controls in the shape the+# Codex companion made familiar: a pen in its own filled disc, then ONE filled+# pill holding microphone mute, the talk orb and the speaker, with thin+# low-contrast dividers. Same hard-edge rules as the row above: every+# silhouette that meets the colour key goes through a binary mask, every glyph+# and the orb's gradient are drawn at 4x and downscaled INSIDE the opaque+# surface, so their antialiasing never meets the key.#: The strip's actions, left to right. The voice orb's ``ACTIONS`` stay as they#: are; the two layouts never share a hit-test.PET_ACTIONS: tuple[str, ...] = ("compose", "mic_mute", "orb", "speaker")-#: Unscaled geometry, in pixels at 100 % display scaling.-PET_SLOT = 28-PET_PEN_GAP = 6+#: Unscaled geometry, in logical pixels at 100 % display scaling and+#: ``pet_scale`` 1.0 — sized against the companion figure (about 180 px), so the+#: strip is roughly 0.3 x the figure's width tall, as in the Codex app.+#: ``PET_SLOT`` is the pill's height and the pen disc's diameter.+PET_SLOT = 50+PET_ICON_SLOT = 46+PET_ORB_SLOT = 52+PET_PEN_GAP = 8PET_DIVIDER_W = 1-PET_PILL_INSET = 4-PET_STRIP_PADDING = 4+PET_PILL_INSET = 7+PET_STRIP_PADDING = 2#: Vertical distance from the figure's bottom edge to the strip.-PET_STRIP_GAP_FROM_FIGURE = 4+PET_STRIP_GAP_FROM_FIGURE = 10+#: The glyphs' box and stroke, as a share of ``PET_SLOT`` (a 21 px icon with a+#: 2 px stroke at 100 %).+PET_ICON_BOX = 0.42+PET_ICON_STROKE = 2.0#: How many steps the orb's pulse is quantised into. A handful is enough to#: read as "breathing with the voice" and bounds how often the strip repaints.PET_LEVEL_STEPS = 6--#: The talk orb's colours: a small bluish sphere, brighter while engaged.-PET_ORB_REST = (74, 124, 230)-PET_ORB_ACTIVE = (98, 152, 255)-PET_ORB_HIGHLIGHT = (170, 200, 255)-#: The divider between pill slots — a shade above the border so it reads.-PET_DIVIDER = (44, 44, 44)+#: The orb's diameter as a share of the pill's height: at rest, and the extra+#: it swells by at full level while listening or talking.+PET_ORB_REST_SHARE = 0.80+PET_ORB_PULSE_SHARE = 0.08++#: Fill of the pen disc and the pill: a dark navy-black, and a shade lighter+#: under the pointer.+PET_FILL = (23, 27, 38)+PET_FILL_HOVER = (36, 42, 58)+#: Glyphs: near-white; a muted control turns red-ish.+PET_ICON = (232, 233, 238)+PET_ICON_MUTED = (248, 113, 113)+#: The divider between pill slots — just above the fill, never a hard line.+PET_DIVIDER = (48, 55, 72)+#: The talk orb: a glossy sphere lit from the top left.+PET_ORB_HIGHLIGHT = (169, 208, 255)+PET_ORB_MID = (74, 124, 245)+PET_ORB_RIM = (39, 71, 200)+PET_ORB_SPECULAR = (230, 241, 255)def _spx(value: float, scale: float) -> int:@@ -403,7 +426,7 @@ def _spx(value: float, scale: float) -> int:@dataclass(frozen=True)class PetStripLayout:- """Where everything sits inside the strip window, at one display scale."""+ """Where everything sits inside the strip window, at one scale."""width: intheight: int@@ -419,23 +442,28 @@ class PetStripLayout:@functools.lru_cache(maxsize=16)def pet_strip_layout(scale: float = 1.0) -> PetStripLayout:- """The strip's geometry at ``scale`` (the monitor's DPI ratio)."""+ """The strip's geometry at ``scale`` (DPI ratio times ``pet_scale``)."""pad = _spx(PET_STRIP_PADDING, scale)slot = _spx(PET_SLOT, scale)gap = _spx(PET_PEN_GAP, scale)divider = _spx(PET_DIVIDER_W, scale)inset = _spx(PET_PILL_INSET, scale)+ widths = {+ "mic_mute": _spx(PET_ICON_SLOT, scale),+ "orb": _spx(PET_ORB_SLOT, scale),+ "speaker": _spx(PET_ICON_SLOT, scale),+ }pen_r = slot / 2.0pen = (pad + pen_r, pad + pen_r, pen_r)pill_x0 = pad + slot + gap- pill_w = 2 * inset + 3 * slot + 2 * divider+ pill_w = 2 * inset + sum(widths.values()) + 2 * dividerpill = (pill_x0, pad, pill_x0 + pill_w, pad + slot)slots: list[tuple[str, int, int]] = []dividers: list[int] = []x = pill_x0 + insetfor index, action in enumerate(PET_ACTIONS[1:]):- slots.append((action, x, x + slot))- x += slot+ slots.append((action, x, x + widths[action]))+ x += widths[action]if index < 2:dividers.append(x)x += divider@@ -525,105 +553,186 @@ class PetStripState:hovered: str | None = None-def _draw_pen(d: ImageDraw.ImageDraw, cx: float, cy: float, r: float, color, w: int) -> None:- """A pencil on the diagonal, tip at the bottom left — "write something"."""- dx, dy = math.cos(-math.pi / 4), math.sin(-math.pi / 4)- nx, ny = -dy, dx- half = r * 0.17+# -- glyphs ------------------------------------------------------------------+# Drawn on a 24-unit grid (the line-icon convention the app's lucide icons use)+# mapped onto a square box centred on the slot, with round caps and joins.+++class _Pen:+ """Maps 24-unit icon coordinates onto a supersampled layer."""++ def __init__(self, d: ImageDraw.ImageDraw, cx: float, cy: float, box: float, width: float):+ self.d = d+ self.cx = cx+ self.cy = cy+ self.unit = box / 24.0+ self.width = max(1, int(round(width)))++ def p(self, u: float, v: float) -> tuple[float, float]:+ return (self.cx + (u - 12.0) * self.unit, self.cy + (v - 12.0) * self.unit)++ def cap(self, point: tuple[float, float], color: _Rgb) -> None:+ r = self.width / 2.0+ x, y = point+ self.d.ellipse([x - r, y - r, x + r, y + r], fill=color)++ def lines(self, points: Sequence[tuple[float, float]], color: _Rgb) -> None:+ mapped = [self.p(u, v) for u, v in points]+ self.d.line(mapped, fill=color, width=self.width, joint="curve")+ self.cap(mapped[0], color)+ self.cap(mapped[-1], color)++ def arc(self, cu: float, cv: float, r: float, start: float, end: float, color: _Rgb) -> None:+ x, y = self.p(cu, cv)+ rr = r * self.unit+ self.d.arc([x - rr, y - rr, x + rr, y + rr], start, end, fill=color, width=self.width)+ for angle in (start, end):+ a = math.radians(angle)+ self.cap((x + rr * math.cos(a), y + rr * math.sin(a)), color)+++def _glyph_compose(pen: _Pen, color: _Rgb) -> None:+ """A square with a pencil writing into its corner — "new message"."""+ pen.lines([(12, 3), (5, 3)], color)+ pen.arc(5, 5, 2, 180, 270, color)+ pen.lines([(3, 5), (3, 19)], color)+ pen.arc(5, 19, 2, 90, 180, color)+ pen.lines([(5, 21), (19, 21)], color)+ pen.arc(19, 19, 2, 0, 90, color)+ pen.lines([(21, 19), (21, 12)], color)+ pen.lines(+ [(18.4, 2.6), (21.4, 5.6), (12.4, 14.6), (8.6, 15.4), (9.4, 11.6), (18.4, 2.6)], color+ )- def p(u: float, v: float) -> tuple[float, float]:- return (cx + u * r * dx + v * nx, cy + u * r * dy + v * ny)- d.polygon(- [p(0.70, -half), p(0.70, half), p(-0.45, half), p(-0.78, 0.0), p(-0.45, -half)],- outline=color,- width=w,+def _glyph_mic(pen: _Pen, color: _Rgb) -> None:+ pen.arc(12, 5, 3, 180, 360, color)+ pen.lines([(9, 5), (9, 12)], color)+ pen.lines([(15, 5), (15, 12)], color)+ pen.arc(12, 12, 3, 0, 180, color)+ pen.lines([(19, 10), (19, 12)], color)+ pen.arc(12, 12, 7, 0, 180, color)+ pen.lines([(5, 12), (5, 10)], color)+ pen.lines([(12, 19), (12, 22)], color)+++def _glyph_speaker(pen: _Pen, color: _Rgb, *, waves: bool) -> None:+ pen.lines([(11, 5), (6, 9), (2, 9), (2, 15), (6, 15), (11, 19), (11, 5)], color)+ if waves:+ pen.arc(12, 12, 5, -45, 45, color)+ pen.arc(12, 12, 10, -45, 45, color)+++def _glyph_slash(pen: _Pen, color: _Rgb) -> None:+ pen.lines([(3, 3), (21, 21)], color)+++def _draw_glyph(+ action: str,+ d: ImageDraw.ImageDraw,+ cx: float,+ cy: float,+ box: float,+ stroke: float,+ state: PetStripState,+) -> None:+ if action == "compose":+ _glyph_compose(_Pen(d, cx, cy, box, stroke), PET_ICON)+ elif action == "mic_mute":+ color = PET_ICON_MUTED if state.mic_muted else PET_ICON+ pen = _Pen(d, cx, cy, box, stroke)+ _glyph_mic(pen, color)+ if state.mic_muted:+ _glyph_slash(pen, color)+ elif action == "speaker":+ color = PET_ICON_MUTED if state.speaker_muted else PET_ICON+ pen = _Pen(d, cx, cy, box, stroke)+ _glyph_speaker(pen, color, waves=not state.speaker_muted)+ if state.speaker_muted:+ _glyph_slash(pen, color)+++def _lerp(a: _Rgb, b: _Rgb, t: float) -> _Rgb:+ t = max(0.0, min(1.0, t))+ return (+ int(round(a[0] + (b[0] - a[0]) * t)),+ int(round(a[1] + (b[1] - a[1]) * t)),+ int(round(a[2] + (b[2] - a[2]) * t)),)- # The ferrule: where the eraser meets the body.- d.line([p(0.42, -half), p(0.42, half)], fill=color, width=w)def _draw_orb(d: ImageDraw.ImageDraw,cx: float,cy: float,- r: float,- *,- active: bool,- level: int,+ radius: float,) -> None:- """The talk orb: a small sphere that swells with the voice while engaged."""- pulse = (level / PET_LEVEL_STEPS) if active else 0.0- radius = r * (0.46 + 0.30 * pulse)- body = PET_ORB_ACTIVE if active else PET_ORB_REST- d.ellipse([cx - radius, cy - radius, cx + radius, cy + radius], fill=body)- shine = radius * 0.38- sx, sy = cx - radius * 0.32, cy - radius * 0.32- d.ellipse([sx - shine, sy - shine, sx + shine, sy + shine], fill=PET_ORB_HIGHLIGHT)---def _slash(d: ImageDraw.ImageDraw, cx: float, cy: float, r: float, color, w: int) -> None:- s = r * 0.74- d.line([(cx - s, cy + s), (cx + s, cy - s)], fill=color, width=w)+ """A glossy sphere: concentric discs drifting toward a top-left light.++ The outermost disc is the deep rim colour, the innermost the highlight; the+ centres slide toward the light as they shrink, which reads as a lit ball.+ PIL only — no numpy on this import path.+ """+ steps = max(8, int(radius))+ lx, ly = cx - radius * 0.38, cy - radius * 0.40+ for k in range(steps, 0, -1):+ t = k / steps # 1 at the rim, toward 0 at the light+ r = radius * t+ ox = lx + (cx - lx) * t+ oy = ly + (cy - ly) * t+ if t > 0.55:+ color = _lerp(PET_ORB_MID, PET_ORB_RIM, (t - 0.55) / 0.45)+ else:+ color = _lerp(PET_ORB_HIGHLIGHT, PET_ORB_MID, t / 0.55)+ d.ellipse([ox - r, oy - r, ox + r, oy + r], fill=color)+ shine = radius * 0.16+ sx, sy = cx - radius * 0.42, cy - radius * 0.46+ d.ellipse([sx - shine, sy - shine * 0.8, sx + shine, sy + shine * 0.8], fill=PET_ORB_SPECULAR)-def _pet_icon_color(action: str, state: PetStripState) -> _Rgb:- if state.hovered == action:- return BTN_ICON_HOVER- return BTN_ICON+def _orb_radius(state: PetStripState, pill_height: float) -> float:+ pulse = (state.level / PET_LEVEL_STEPS) if state.active else 0.0+ share = PET_ORB_REST_SHARE + PET_ORB_PULSE_SHARE * max(0.0, min(1.0, pulse))+ return pill_height * share / 2.0-def _render_pen_disc(state: PetStripState, diameter: int) -> Image.Image:+def _render_pen_disc(state: PetStripState, diameter: int, scale: float) -> Image.Image:size = diameter * _SShovered = state.hovered == "compose"- layer = Image.new("RGB", (size, size), BTN_BG_HOVER if hovered else BTN_BG)+ layer = Image.new("RGB", (size, size), PET_FILL_HOVER if hovered else PET_FILL)d = ImageDraw.Draw(layer)- stroke = max(1, round(1.0 * _SS))- d.ellipse(- [stroke, stroke, size - 1 - stroke, size - 1 - stroke], outline=BTN_BORDER, width=stroke- )- glyph_w = max(1, round(1.35 * _SS))- _draw_pen(d, size / 2.0, size / 2.0, size * 0.30, _pet_icon_color("compose", state), glyph_w)+ box = _spx(PET_SLOT, scale) * PET_ICON_BOX * _SS+ stroke = PET_ICON_STROKE * max(0.5, scale) * _SS+ _draw_glyph("compose", d, size / 2.0, size / 2.0, box, stroke, state)return layer.resize((diameter, diameter), Image.Resampling.LANCZOS)-def _render_pill(state: PetStripState, layout: PetStripLayout) -> Image.Image:+def _render_pill(state: PetStripState, layout: PetStripLayout, scale: float) -> Image.Image:x0, y0, x1, y1 = layout.pillwidth, height = x1 - x0, y1 - y0w_ss, h_ss = width * _SS, height * _SS- layer = Image.new("RGB", (w_ss, h_ss), BTN_BG)+ layer = Image.new("RGB", (w_ss, h_ss), PET_FILL)d = ImageDraw.Draw(layer)- stroke = max(1, round(1.0 * _SS))- glyph_w = max(1, round(1.35 * _SS))for action, sx0, sx1 in layout.slots:if state.hovered == action:- d.rectangle([(sx0 - x0) * _SS, 0, (sx1 - x0) * _SS - 1, h_ss - 1], fill=BTN_BG_HOVER)+ # A soft round lift under the pointer, like the pen disc's.+ hx = ((sx0 + sx1) / 2.0 - x0) * _SS+ hr = h_ss * 0.46+ d.ellipse([hx - hr, h_ss / 2.0 - hr, hx + hr, h_ss / 2.0 + hr], fill=PET_FILL_HOVER)for dx, (_action, next_x0, _next_x1) in zip(layout.dividers, layout.slots[1:], strict=False):d.rectangle(- [(dx - x0) * _SS, h_ss * 0.22, (next_x0 - x0) * _SS - 1, h_ss * 0.78],+ [(dx - x0) * _SS, h_ss * 0.28, (next_x0 - x0) * _SS - 1, h_ss * 0.72],fill=PET_DIVIDER,)- d.rounded_rectangle(- [stroke, stroke, w_ss - 1 - stroke, h_ss - 1 - stroke],- radius=(h_ss - 2 * stroke) / 2.0,- outline=BTN_BORDER,- width=stroke,- )cy = h_ss / 2.0+ box = height * PET_ICON_BOX * _SS+ stroke = PET_ICON_STROKE * max(0.5, scale) * _SSfor action, sx0, sx1 in layout.slots:cx = ((sx0 + sx1) / 2.0 - x0) * _SS- radius = (sx1 - sx0) * _SS * 0.30- colour = _pet_icon_color(action, state)- if action == "mic_mute":- _draw_mic(d, cx, cy, radius, colour, glyph_w, slashed=False)- if state.mic_muted:- _slash(d, cx, cy, radius, BTN_ICON_OFF, glyph_w)- elif action == "orb":- _draw_orb(d, cx, cy, radius * 1.4, active=state.active, level=state.level)+ if action == "orb":+ _draw_orb(d, cx, cy, _orb_radius(state, h_ss))else:- _draw_speaker(d, cx, cy, radius, colour, glyph_w, muted=False)- if state.speaker_muted:- _slash(d, cx, cy, radius, BTN_ICON_OFF, glyph_w)+ _draw_glyph(action, d, cx, cy, box, stroke, state)return layer.resize((width, height), Image.Resampling.LANCZOS)@@ -653,10 +762,10 @@ def render_pet_strip(frame = Image.new("RGB", (layout.width, layout.height), color_key)pcx, pcy, pr = layout.pendiameter = int(round(pr * 2))- pen = _render_pen_disc(state, diameter)+ pen = _render_pen_disc(state, diameter, scale)frame.paste(pen, (int(round(pcx - pr)), int(round(pcy - pr))), _disc_mask(diameter))x0, y0, x1, y1 = layout.pill- pill = _render_pill(state, layout)+ pill = _render_pill(state, layout, scale)frame.paste(pill, (x0, y0), _binary_stadium_mask(x1 - x0, y1 - y0))return framediff --git a/ui/orb/overlay.py b/ui/orb/overlay.pyindex 0aa5cdd572..c61d6dbcac 100644--- a/ui/orb/overlay.py+++ b/ui/orb/overlay.py@@ -258,19 +258,20 @@ ORB_BUBBLE_THEME = BubbleTheme()-#: The pet's status bubble: the app's own card look (a dark rounded surface, a-#: hairline border, light italic narration under a muted header) and no tail —-#: it reports what Jarvis is doing, it is not the pet talking.+#: The pet's status card — the agent card of the Codex companion: a dark pill+#: with a hairline border, a bold light title and a muted detail line, no tail+#: and no italics. It reports what Jarvis is thinking or doing; it is not the+#: pet talking. ``header`` is the title colour, ``text`` the detail colour.PET_BUBBLE_THEME = BubbleTheme(- bg="#141414",- border="#2E2E2E",- text="#E6E6E6",+ bg="#1E1F22",+ border="#3A3B40",+ text="#A0A1A7",border_width=1,bold=False,tail=False,- corner_radius=16,- italic=True,- header="#8A8A8A",+ corner_radius=26,+ italic=False,+ header="#F3F3F3",)@@ -283,17 +284,30 @@ def bubble_theme_for_style(style: str) -> BubbleTheme:return MASCOT_BUBBLE_THEME-# The pet's status bubble (docs/pets.md): below the control strip, two lines-# collapsed, six after a click, gone six seconds after the last update once-# Jarvis is idle again. Pixel sizes are at 100 % and scale with the DPI ratio.-PET_BUBBLE_WIDTH = 260-PET_BUBBLE_COLLAPSED_LINES = 2-PET_BUBBLE_EXPANDED_LINES = 6-PET_BUBBLE_GAP = 6-PET_BUBBLE_IDLE_HIDE_MS = 6000-PET_BUBBLE_BODY_FONT_SIZE = 11-PET_BUBBLE_HEADER_FONT_SIZE = 9-PET_BUBBLE_HEADER_GAP = 2+# The pet's status card (docs/pets.md): below the control strip, a one-line+# bold title over one muted detail line (three after a click), sized to its+# text up to 1.6 x the strip's width. The bridge decides when it goes: it calls+# ``clear_status`` once Jarvis stops thinking, and the card fades after a short+# linger. Pixel sizes are at 100 % and scale with the strip.+PET_CARD_PAD_X = 18+PET_CARD_PAD_Y = 10+PET_CARD_LINE_GAP = 2+PET_CARD_MIN_WIDTH = 150+#: Used until the overlay tells the card how wide the strip is.+PET_CARD_MAX_WIDTH = 380+PET_CARD_MAX_WIDTH_PER_STRIP = 1.6+PET_CARD_DETAIL_COLLAPSED_LINES = 1+PET_CARD_DETAIL_EXPANDED_LINES = 3+PET_CARD_TITLE_FONT_SIZE = 10+PET_CARD_DETAIL_FONT_SIZE = 9+#: The fade after the linger: a handful of opacity steps, then withdrawn.+PET_CARD_FADE_STEPS = 6+PET_CARD_FADE_STEP_MS = 30+#: How long a card a click expanded stays before a pending clear proceeds.+PET_CARD_READING_LINGER_S = 6.0+#: The default linger of ``clear_status``.+PET_STATUS_LINGER_S = 1.5+PET_BUBBLE_GAP = 8PET_BUBBLE_ELLIPSIS = "…"@@ -1297,7 +1311,11 @@ class OrbCommentBubble:# (width, height) of the status bubble as last painted; a drag only# moves a bubble of this size instead of repainting it.self._status_size: tuple[int, int] | None = None- self._status_auto_hide_ms: int | None = None+ # A requested clear: the linger timer, then the fade steps.+ self._clear_after_id: str | None = None+ self._fade_after_id: str | None = None+ self._status_clear_pending = False+ self._status_max_w: int | None = Noneself._ui_scale = 1.0self._build()@@ -1391,11 +1409,6 @@ class OrbCommentBubble:font.configure(weight=weight)except tk.TclError:pass- if self._status_font is not None:- try:- self._status_font.configure(slant="italic" if theme.italic else "roman")- except tk.TclError:- logging.getLogger("jarvis.orb").debug("status font restyle failed", exc_info=True)self.hide()def show(@@ -1661,12 +1674,16 @@ class OrbCommentBubble:# -- the pet's status variant ------------------------------------------def set_ui_scale(self, scale: float) -> None:- """Pixel sizes of the status variant follow the monitor's DPI ratio."""+ """Pixel sizes of the status card follow the strip's scale."""try:self._ui_scale = max(0.5, min(4.0, float(scale)))except (TypeError, ValueError):self._ui_scale = 1.0+ def set_status_max_width(self, width: int | None) -> None:+ """The card's widest size (1.6 x the strip) — ``None`` for the default."""+ self._status_max_w = None if width is None else max(1, int(width))+@propertydef status_showing(self) -> bool:return self._status_showing@@ -1679,56 +1696,118 @@ class OrbCommentBubble:if self._top is None or self._canvas is None:return Falseif self._status_font is None:- # A click expands a pet status to six lines (and collapses it+ # A click expands the detail to three lines (and collapses it# again). Bound with the first status, so the mascot's comment and# transcript variants keep ignoring clicks as they always have.self._canvas.bind("<ButtonRelease-1>", self._on_click)self._status_font = tkfont.Font(root=self._top,family=BUBBLE_FONT_FAMILY,- size=PET_BUBBLE_BODY_FONT_SIZE,- slant="italic" if self._theme.italic else "roman",+ size=PET_CARD_DETAIL_FONT_SIZE,)if self._header_font is None:self._header_font = tkfont.Font(root=self._top,family=BUBBLE_FONT_FAMILY,- size=PET_BUBBLE_HEADER_FONT_SIZE,+ size=PET_CARD_TITLE_FONT_SIZE,+ weight="bold",)return Truedef show_status(self,- header: str,- body: str,+ title: str,+ detail: str,*,anchor: tuple[int, int, int, int],- auto_hide_ms: int | None,) -> None:- """Show (or update) the pet's condensed status lines.+ """Show (or update) the pet's status card and cancel a pending clear.- ``anchor`` is ``(center_x, below_y, above_y, limit_bottom)``: the bubble+ ``anchor`` is ``(center_x, below_y, above_y, limit_bottom)``: the cardhangs from ``below_y`` (just under the control strip) when it fits above``limit_bottom``, else it sits on ``above_y`` (just over the figure) —- a pet parked on the taskbar would otherwise push its bubble off screen.- ``auto_hide_ms`` arms the fade timer; ``None`` keeps the bubble up.+ a pet parked on the taskbar would otherwise push its card off screen.+ A title-less status shows its detail as the title."""if self._top is None or self._canvas is None:return- header = " ".join(str(header or "").split())- body = " ".join(str(body or "").split())- if not header and not body:- self.hide()+ title = " ".join(str(title or "").split())+ detail = " ".join(str(detail or "").split())+ if not title:+ title, detail = detail, ""+ if not title:+ self.clear_status(0.0)returnself._cancel_timers()- self._status = (header, body)+ self._cancel_clear()+ self._status = (title, detail)self._status_anchor = anchor- self._status_auto_hide_ms = auto_hide_ms- if self._render_status():- self._arm_status_hide()+ self._render_status()++ def clear_status(self, linger_s: float = PET_STATUS_LINGER_S) -> None:+ """Fade the card out after ``linger_s`` seconds (at once when 0).++ A newer :meth:`show_status` before the fade ends cancels it. Calling+ it again while a clear is pending keeps the earlier deadline.+ """+ if self._top is None:+ return+ if not self._status_showing:+ self._cancel_clear()+ return+ try:+ delay = max(0.0, float(linger_s))+ except (TypeError, ValueError):+ delay = PET_STATUS_LINGER_S+ if delay <= 0.0:+ self._cancel_clear()+ self.hide()+ return+ if self._status_clear_pending:+ return+ self._status_clear_pending = True+ self._clear_after_id = self._top.after(int(delay * 1000), self._start_fade)++ def _start_fade(self, step: int = 0) -> None:+ self._clear_after_id = None+ top = self._top+ if top is None or not self._status_showing:+ self._status_clear_pending = False+ return+ if step >= PET_CARD_FADE_STEPS:+ self._fade_after_id = None+ self.hide()+ return+ try:+ top.wm_attributes("-alpha", 1.0 - (step + 1) / (PET_CARD_FADE_STEPS + 1))+ except tk.TclError:+ # No per-window opacity here (some X11 window managers): skip+ # straight to the end instead of half-fading.+ self._fade_after_id = None+ self.hide()+ return+ self._fade_after_id = top.after(PET_CARD_FADE_STEP_MS, lambda: self._start_fade(step + 1))++ def _cancel_clear(self) -> None:+ """Stop a pending clear and bring the card back to full opacity."""+ top = self._top+ for attr in ("_clear_after_id", "_fade_after_id"):+ after_id = getattr(self, attr)+ if after_id is not None and top is not None:+ try:+ top.after_cancel(after_id)+ except tk.TclError:+ logging.getLogger("jarvis.orb").debug("card timer cancel failed", exc_info=True)+ setattr(self, attr, None)+ if self._status_clear_pending and top is not None:+ try:+ top.wm_attributes("-alpha", 1.0)+ except tk.TclError:+ logging.getLogger("jarvis.orb").debug("card opacity reset failed", exc_info=True)+ self._status_clear_pending = Falsedef move_status(self, anchor: tuple[int, int, int, int]) -> None:- """Follow the pet (drag, resize) without restarting the fade timer.+ """Follow the pet (drag, resize) without touching a pending clear.A drag calls this for every mouse motion, and neither the text nor thewidth changes then: only the window moves. The canvas is repainted@@ -1745,47 +1824,77 @@ class OrbCommentBubble:try:self._top.geometry(f"+{x}+{y}")except tk.TclError:- logging.getLogger("jarvis.orb").debug("pet status bubble move failed", exc_info=True)+ logging.getLogger("jarvis.orb").debug("pet status card move failed", exc_info=True)def _status_position(- self, bubble_w: int, height: int, anchor: tuple[int, int, int, int]+ self, card_w: int, height: int, anchor: tuple[int, int, int, int]) -> tuple[int, int]:- """Top-left corner for a bubble of this size: under the strip when it+ """Top-left corner for a card of this size: under the strip when itfits above ``limit_bottom``, else over the figure."""center_x, below_y, above_y, limit_bottom = anchor- x = max(8, min(center_x - bubble_w // 2, self._screen_w - bubble_w - 8))+ x = max(8, min(center_x - card_w // 2, self._screen_w - card_w - 8))y = below_y if below_y + height <= limit_bottom else max(8, above_y - height)return x, y- def arm_auto_hide(self, delay_ms: int | None) -> None:- """(Re)arm or cancel the status fade timer."""- self._status_auto_hide_ms = delay_ms- if self._status_showing:- self._arm_status_hide()-- def _arm_status_hide(self) -> None:- if self._top is None:- return- if self._dismiss_after_id is not None:- try:- self._top.after_cancel(self._dismiss_after_id)- except tk.TclError:- logging.getLogger("jarvis.orb").debug("bubble timer cancel failed", exc_info=True)- self._dismiss_after_id = None- delay = self._status_auto_hide_ms- if delay is not None:- self._dismiss_after_id = self._top.after(max(1, int(delay)), self.hide)-def _on_click(self, _event: tk.Event | None = None) -> None:if not self._status_showing:returnself._status_expanded = not self._status_expanded+ reading = self._status_clear_pending+ self._cancel_clear()self._render_status()- # Reading takes time: a click restarts the fade instead of racing it.- self._arm_status_hide()+ if reading:+ # The user opened a card that was about to go: give them time.+ self.clear_status(PET_CARD_READING_LINGER_S)++ def card_layout(+ self,+ title: str,+ detail: str,+ measure_title: Callable[[str], int],+ measure_detail: Callable[[str], int],+ title_lh: int,+ detail_lh: int,+ ) -> tuple[int, int, list[str], list[str], int]:+ """``(width, height, title_lines, detail_lines, radius)`` of the card.++ Pure geometry (the fonts' measure functions are injected), so it is+ testable without Tk. The card fits its text between the minimum width+ and 1.6 x the strip; a collapsed two-line card is a full pill, an+ expanded one keeps that end radius.+ """+ scale = self._ui_scale+ pad_x = int(round(PET_CARD_PAD_X * scale))+ pad_y = int(round(PET_CARD_PAD_Y * scale))+ gap = int(round(PET_CARD_LINE_GAP * scale))+ max_w = self._status_max_w or int(round(PET_CARD_MAX_WIDTH * scale))+ max_w = max(1, min(max_w, max(160, self._screen_w - 16)))+ min_w = min(max_w, int(round(PET_CARD_MIN_WIDTH * scale)))+ text_max = max(40, max_w - 2 * pad_x)+ title_lines = wrap_text_lines(title, measure_title, text_max, 1)+ detail_limit = (+ PET_CARD_DETAIL_EXPANDED_LINES+ if self._status_expanded+ else PET_CARD_DETAIL_COLLAPSED_LINES+ )+ detail_lines = (+ wrap_text_lines(detail, measure_detail, text_max, detail_limit) if detail else []+ )+ widest = max(+ [measure_title(line) for line in title_lines]+ + [measure_detail(line) for line in detail_lines]+ + [0]+ )+ width = max(min_w, min(max_w, widest + 2 * pad_x))+ height = 2 * pad_y + title_lh * len(title_lines)+ if detail_lines:+ height += gap + detail_lh * len(detail_lines)+ collapsed = 2 * pad_y + title_lh + (gap + detail_lh if detail else 0)+ radius = max(4, min(height, collapsed) // 2)+ return width, height, title_lines, detail_lines, radiusdef _render_status(self) -> bool:- """Paint the status variant. Returns False when nothing could be drawn."""+ """Paint the status card. Returns False when nothing could be drawn."""if (self._top is Noneor self._canvas is None@@ -1794,68 +1903,60 @@ class OrbCommentBubble:or not self._ensure_status_fonts()):return False- body_font = self._status_font- header_font = self._header_font- assert body_font is not None and header_font is not None # noqa: S101 — set above- header, body = self._status+ detail_font = self._status_font+ title_font = self._header_font+ assert detail_font is not None and title_font is not None # noqa: S101 — set above+ title, detail = self._statustheme = self._themescale = self._ui_scale- pad_x = int(round(BUBBLE_PADDING_X * scale))- pad_y = int(round(BUBBLE_PADDING_Y * scale))- bubble_w = min(int(round(PET_BUBBLE_WIDTH * scale)), max(160, self._screen_w - 16))- text_w = max(40, bubble_w - 2 * pad_x)- max_lines = (- PET_BUBBLE_EXPANDED_LINES if self._status_expanded else PET_BUBBLE_COLLAPSED_LINES+ pad_x = int(round(PET_CARD_PAD_X * scale))+ pad_y = int(round(PET_CARD_PAD_Y * scale))+ gap = int(round(PET_CARD_LINE_GAP * scale))+ title_lh = max(1, int(title_font.metrics("linespace")))+ detail_lh = max(1, int(detail_font.metrics("linespace")))+ width, height, title_lines, detail_lines, radius = self.card_layout(+ title, detail, title_font.measure, detail_font.measure, title_lh, detail_lh)- lines = wrap_text_lines(body, body_font.measure, text_w, max_lines) if body else []- header_line = ""- if header:- header_line = wrap_text_lines(header, header_font.measure, text_w, 1)[0]- body_lh = max(1, int(body_font.metrics("linespace")))- header_lh = max(1, int(header_font.metrics("linespace")))- height = 2 * pad_y + body_lh * len(lines)- if header_line:- height += header_lh + (PET_BUBBLE_HEADER_GAP if lines else 0)-- x, y = self._status_position(bubble_w, height, self._status_anchor)+ x, y = self._status_position(width, height, self._status_anchor)try:- self._top.geometry(f"{bubble_w}x{height}+{x}+{y}")- self._canvas.configure(width=bubble_w, height=height)+ self._top.wm_attributes("-alpha", 1.0)+ except tk.TclError:+ logging.getLogger("jarvis.orb").debug("card opacity reset failed", exc_info=True)+ try:+ self._top.geometry(f"{width}x{height}+{x}+{y}")+ self._canvas.configure(width=width, height=height)self._canvas.delete("all")self._draw_rounded_rect(1,1,- bubble_w - 1,+ width - 1,height - 1,- theme.corner_radius,+ radius,fill=theme.bg,outline=theme.border,width=theme.border_width,)cursor_y = pad_y- if header_line:+ for line in title_lines:self._canvas.create_text(- pad_x,- cursor_y,- text=header_line,- font=header_font,- anchor="nw",- fill=theme.header,+ pad_x, cursor_y, text=line, font=title_font, anchor="nw", fill=theme.header)- cursor_y += header_lh + PET_BUBBLE_HEADER_GAP- for line in lines:+ cursor_y += title_lh+ if detail_lines:+ cursor_y += gap+ for line in detail_lines:self._canvas.create_text(- pad_x, cursor_y, text=line, font=body_font, anchor="nw", fill=theme.text+ pad_x, cursor_y, text=line, font=detail_font, anchor="nw", fill=theme.text)- cursor_y += body_lh+ cursor_y += detail_lhself._top.deiconify()self._top.lift()except tk.TclError:- logging.getLogger("jarvis.orb").debug("pet status bubble paint failed", exc_info=True)+ logging.getLogger("jarvis.orb").debug("pet status card paint failed", exc_info=True)self._status_size = Nonereturn Falseself._status_showing = True- self._status_size = (bubble_w, height)+ self._status_size = (width, height)return Truedef _cancel_timers(self) -> None:@@ -1873,6 +1974,7 @@ class OrbCommentBubble:self._queued_text = Nonedef hide(self) -> None:+ self._cancel_clear()self._status_showing = Falseself._status_expanded = Falseself._status_size = None@@ -2332,6 +2434,26 @@ class PetControlStrip(OrbControlRow):self._canvas.bind("<B1-Motion>", self._on_drag_motion_event)self._canvas.bind("<Button-3>", self._on_context_event)+ @property+ def scale(self) -> float:+ return self._scale++ def set_scale(self, scale: float) -> None:+ """Re-lay the strip at another scale (``pet_scale`` or DPI changed)."""+ scale = float(scale)+ if scale == self._scale:+ return+ self._scale = scale+ self._width, self._height = self._row_size()+ if self._canvas is not None:+ try:+ self._canvas.configure(width=self._width, height=self._height)+ except tk.TclError:+ logging.getLogger("jarvis.orb").debug("strip resize failed", exc_info=True)+ self._repaint()+ if self._visible:+ self._place()+# -- state ------------------------------------------------------------@property@@ -2416,6 +2538,8 @@ FRAME_INTERVAL_MS = 16#: While the strip's orb pulses (listening / talking) the pet ticks at least#: this often, so the pulse follows the voice even when the figure is slow.PET_PULSE_INTERVAL_MS = 100+#: A level older than this no longer moves the strip's orb (the voice stopped).+PET_LEVEL_FRESH_S = 0.25class OrbOverlay:@@ -2522,6 +2646,7 @@ class OrbOverlay:self._image_id: int | None = Noneself._mode: str = "idle"self._ext_level: float | None = None+ self._ext_level_at: float = -math.infself._t0: float = 0.0self._running: bool = Falseself._started = threading.Event()@@ -2774,6 +2899,8 @@ class OrbOverlay:)self._comment_bubble.set_ui_scale(self._dpi_ratio)self._ensure_controls()+ if self._style == "pet":+ self._sync_pet_strip_scale()if self._renderer is None:self._renderer = self._build_renderer(self._style)@@ -2848,12 +2975,32 @@ class OrbOverlay:taskbar_aligned=by_height.taskbar_aligned,)+ def _pet_strip_scale(self) -> float:+ """The strip's scale: the monitor's DPI ratio times ``pet_scale``."""+ renderer = self._renderer+ if isinstance(renderer, PetRenderer):+ return renderer.strip_scale+ return max(0.25, self._dpi_ratio * self._pet_scale)+def _pet_below_height(self) -> int:"""Height of what hangs under the pet's figure: the gap plus the strip."""- _strip_w, strip_h = orb_controls.pet_strip_size(self._dpi_ratio)- gap = max(1, int(round(orb_controls.PET_STRIP_GAP_FROM_FIGURE * self._dpi_ratio)))+ scale = self._pet_strip_scale()+ _strip_w, strip_h = orb_controls.pet_strip_size(scale)+ gap = max(1, int(round(orb_controls.PET_STRIP_GAP_FROM_FIGURE * scale)))return strip_h + gap+ def _sync_pet_strip_scale(self) -> None:+ """Bring the strip and the status card to the current strip scale."""+ scale = self._pet_strip_scale()+ row = self._controls+ if isinstance(row, PetControlStrip):+ row.set_scale(scale)+ bubble = self._comment_bubble+ if bubble is not None:+ bubble.set_ui_scale(scale)+ strip_w, _strip_h = orb_controls.pet_strip_size(scale)+ bubble.set_status_max_width(int(round(strip_w * PET_CARD_MAX_WIDTH_PER_STRIP)))+def _clamp_position(self, x: int, y: int, monitor_geo: tuple[int, int, int, int]) -> tuple[int, int]:@@ -3113,7 +3260,7 @@ class OrbOverlay:orb_y=self._mascot_y,orb_w=self._win_w,orb_h=self._win_h,- scale=self._dpi_ratio,+ scale=self._pet_strip_scale(),on_drag_press=self._on_drag_press,on_drag_motion=self._on_drag_motion,on_drag_release=self._on_drag_release,@@ -3750,8 +3897,9 @@ class OrbOverlay:On the pet the text lands in its status bubble instead."""if self._style == "pet":- if text:- self.show_status("", text)+ # The pet's card shows what Jarvis thinks (``show_status``), never+ # spoken text; a comment is still a sign of life.+ self._note_activity()returnbubble = self._comment_bubbleif bubble is None or not text or not self._bubble_wanted():@@ -3761,17 +3909,12 @@ class OrbOverlay:def show_listening_transcript(self, text: str = "", duration_ms: int = 30000) -> None:"""Show the larger live transcript bubble used while the user speaks.- On the pet the transcript is a status line; an empty one (a fresh turn- resetting the bubble) clears it instead of showing a placeholder.+ The pet's card does not echo the transcript: it shows what Jarvis+ thinks (``show_status``), and the bridge clears it. Hearing the user is+ still a sign of life that keeps the pet awake."""if self._style == "pet":- if (text or "").strip():- self.show_status("", text)- else:- self._note_activity()- bubble = self._comment_bubble- if bubble is not None:- self._enqueue_ui(bubble.hide)+ self._note_activity()returnbubble = self._comment_bubbleif bubble is None or not self._bubble_wanted():@@ -3788,7 +3931,7 @@ class OrbOverlay:if bubble is None:returnif self._style == "pet":- self._enqueue_ui(lambda: bubble.arm_auto_hide(PET_BUBBLE_IDLE_HIDE_MS))+ self._enqueue_ui(lambda: bubble.clear_status(PET_STATUS_LINGER_S))returnself._enqueue_ui(bubble.hide)@@ -3841,16 +3984,29 @@ class OrbOverlay:returnself._enqueue_ui(lambda: self._apply_outcome(outcome))- def show_status(self, header: str = "", line: str = "") -> None:- """Update the pet's status bubble with one condensed line. Thread-safe."""+ def show_status(self, title: str = "", detail: str = "") -> None:+ """Show or update the pet's status card (bold title, muted detail). Thread-safe."""if self._style != "pet":returnself._note_activity()if not self._pet_bubble or self._comment_bubble is None:return- header_text = str(header or "")- line_text = str(line or "")- self._enqueue_ui(lambda: self._apply_status(header_text, line_text))+ title_text = str(title or "")+ detail_text = str(detail or "")+ self._enqueue_ui(lambda: self._apply_status(title_text, detail_text))++ def clear_status(self, linger_s: float = PET_STATUS_LINGER_S) -> None:+ """Fade the status card out after ``linger_s`` seconds (at once when 0). Thread-safe."""+ if self._style != "pet":+ return+ bubble = self._comment_bubble+ if bubble is None:+ return+ try:+ linger = max(0.0, float(linger_s))+ except (TypeError, ValueError):+ linger = PET_STATUS_LINGER_S+ self._enqueue_ui(lambda: bubble.clear_status(linger))def set_muted(self, muted: bool) -> None:"""Mirror Jarvis's microphone mute on the strip. Thread-safe."""@@ -3909,6 +4065,7 @@ class OrbOverlay:if isinstance(renderer, PetRenderer):renderer.set_look(pet_scale=self._pet_scale)self._refit_pet_window()+ self._sync_pet_strip_scale()def _apply_outcome(self, kind: str) -> None:renderer = self._renderer@@ -3940,30 +4097,18 @@ class OrbOverlay:elif row is not None:row.set_state(speaker_muted=self._speaker_muted)- def _apply_status(self, header: str, line: str) -> None:+ def _apply_status(self, title: str, detail: str) -> None:bubble = self._comment_bubbleif bubble is None or self._style != "pet" or not self._pet_bubble:return- # No bubble floating over an empty desktop: it belongs to the pet.+ # No card floating over an empty desktop: it belongs to the pet.if self._user_hidden or not self._window_mapped():return- bubble.show_status(- header,- line,- anchor=self._status_anchor(),- auto_hide_ms=PET_BUBBLE_IDLE_HIDE_MS if self._mode == "idle" else None,- )-- def _sync_status_fade(self) -> None:- """Idle starts the six-second fade; an active mode keeps the bubble up."""- bubble = self._comment_bubble- if bubble is None or self._style != "pet" or not bubble.status_showing:- return- bubble.arm_auto_hide(PET_BUBBLE_IDLE_HIDE_MS if self._mode == "idle" else None)+ bubble.show_status(title, detail, anchor=self._status_anchor())def _status_anchor(self, *, refresh_limit: bool = True) -> tuple[int, int, int, int]:- """``(center_x, below_y, above_y, limit_bottom)`` for the status bubble."""- ratio = self._dpi_ratio+ """``(center_x, below_y, above_y, limit_bottom)`` for the status card."""+ ratio = self._pet_strip_scale()bubble_gap = max(1, int(round(PET_BUBBLE_GAP * ratio)))center_x = self._mascot_x + self._win_w // 2below_y = self._mascot_y + self._win_h + self._pet_below_height() + bubble_gap@@ -4064,7 +4209,11 @@ class OrbOverlay:self._enqueue_ui(lambda: self._set_mode(mode))def set_level(self, level: float) -> None:+ # Two plain attribute writes from the audio threads (atomic under the+ # GIL); the Tk thread reads them on its next frame tick. The stamp+ # lets the pet tell a live voice from a level that stopped arriving.self._ext_level = max(0.0, min(1.0, float(level)))+ self._ext_level_at = time.monotonic()# --- Animation API ------------------------------------------------@@ -4270,7 +4419,6 @@ class OrbOverlay:if isinstance(renderer, PetRenderer):renderer.on_mode(mode)self._kick_frame()- self._sync_status_fade()if changed:self._sync_controls_visibility()@@ -4380,6 +4528,9 @@ class OrbOverlay:t = time.perf_counter() - self._t0frame_key_fn = getattr(renderer, "frame_key", None)if callable(frame_key_fn):+ feed_level = getattr(renderer, "feed_level", None)+ if callable(feed_level):+ feed_level(self._ext_level, self._ext_level_at)return self._paint_keyed_frame(renderer, t, frame_key_fn(t))img = renderer.render(t, self._mode, self._ext_level)if self._mac_transparent:@@ -4436,7 +4587,8 @@ class OrbOverlay:if not isinstance(row, PetControlStrip):return Falsepulsing = self._mode in ("listen", "speak", "dictate")- level = orb_controls.quantize_level(self._ext_level) if pulsing else 0+ fresh = time.monotonic() - self._ext_level_at <= PET_LEVEL_FRESH_S+ level = orb_controls.quantize_level(self._ext_level) if pulsing and fresh else 0row.set_state(level=level)return pulsingdiff --git a/ui/orb/pet_renderer.py b/ui/orb/pet_renderer.pyindex 667ee026fd..b792e84a8c 100644--- a/ui/orb/pet_renderer.py+++ b/ui/orb/pet_renderer.py@@ -4,15 +4,20 @@ The mascot and the voice orb are drawn fresh every frame at 60 fps; a pixel-artpet does not need that and must not pay for it (the budget in ``docs/pets.md``:an idle pet costs next to nothing). So this renderer works the other way round:-* every frame of every state is scaled ONCE, when the pet is loaded — an- integer nearest-neighbour factor from the monitor's DPI times the user's- ``pet_scale``, keyed to the overlay's magenta colour key;+* every frame of every state is cropped to the figure and scaled ONCE, when+ the pet is loaded — an integer nearest-neighbour factor chosen so the visible+ figure is about :data:`PET_TARGET_FIGURE_PX` logical pixels at any DPI, times+ the user's ``pet_scale``, keyed to the overlay's magenta colour key;* ``frame_key`` names the frame that is due now, so the overlay repaints onlywhen that key changes and reuses its cached Tk image otherwise;* ``next_frame_delay_ms`` says how long the overlay may sleep until the nextframe boundary or the next state change the state machine will make on its- own (a one-shot ending, the pet falling asleep) — 4 fps idle, 2 fps asleep,- whatever the manifest asks for while active.+ own (a one-shot ending, the pet falling asleep).++Talking follows the voice: the talking row is drawn closed → widest, and while+a live output level arrives the frame is picked from that level (smoothed,+bucketed — an unchanged level gives an unchanged key, so no repaint). Without a+level the row plays back and forth at the manifest's rate.The state itself comes from :class:`jarvis.ui.pets.state_machine.PetStateMachine`,fed by the overlay from real Jarvis events. Pet ``"none"`` loads no pack: the@@ -26,7 +31,7 @@ import loggingimport mathimport sysimport time-from collections.abc import Callable, Hashable, Mapping+from collections.abc import Callable, Hashable, Mapping, Sequencefrom typing import Anyfrom PIL import Image@@ -36,10 +41,13 @@ from ui.orb import controls as orb_controlslog = logging.getLogger("jarvis.orb")-#: The figure's on-screen edge at 100 % display scaling and ``pet_scale`` 1.0.-#: A 48-pixel sheet lands on exactly 3x; 32 and 64 pixel sheets get the integer-#: factor nearest to the same size, so every pet is about as tall as the next.-PET_TARGET_EDGE_PX = 144+#: The visible figure's larger side at 100 % display scaling and ``pet_scale``+#: 1.0, in logical pixels — about the size of the companion in the Codex app,+#: so the control strip under it (``controls.PET_SLOT``) reads as its own.+PET_TARGET_FIGURE_PX = 180++#: Nominal window edge before a pack is loaded (the real size replaces it).+PET_TARGET_EDGE_PX = PET_TARGET_FIGURE_PX#: Logical pixels per inch Tk reports at 100 % scaling on Windows and X11._BASE_PPI = 96.0@@ -50,6 +58,21 @@ _BASE_PPI = 96.0MIN_FRAME_DELAY_MS = 15MAX_FRAME_DELAY_MS = 1000+#: A level older than this no longer drives the mouth (the voice stopped).+LEVEL_FRESH_S = 0.25+#: How often the overlay looks at the level while it drives the mouth.+LEVEL_POLL_MS = 60+#: Exponential smoothing per poll: enough to stop a single loud sample from+#: flicking the jaw, little enough to follow syllables.+LEVEL_SMOOTHING = 0.55+#: Below this the mouth is closed; above, the open frames share the range up+#: to ``LEVEL_OPEN_SPAN`` above it.+LEVEL_SILENCE = 0.04+LEVEL_OPEN_SPAN = 0.45++#: Source pixels kept around the cropped figure (sparkles may touch the edge).+_CROP_MARGIN = 1+_ColorKey = tuple[int, int, int]@@ -72,32 +95,55 @@ def dpi_ratio_for(points_per_inch: float | None, platform: str = sys.platform) -return max(0.75, min(4.0, ppi / _BASE_PPI))-def pixel_factor(frame_size: int, dpi_ratio: float = 1.0, pet_scale: float = 1.0) -> int:- """The integer nearest-neighbour factor a sprite sheet is scaled by.+def pixel_factor(extent: int, dpi_ratio: float = 1.0, pet_scale: float = 1.0) -> int:+ """The integer nearest-neighbour factor for a figure ``extent`` source pixels big.- Integer on purpose: a fractional factor duplicates some source pixels and- not others, and pixel art then looks smeared. Rounded half up (Python's- ``round`` would send 4.5 to 4) and never below 1.+ ``extent`` is the visible figure's larger side (or a whole cell when the+ figure is unknown). Integer on purpose: a fractional factor duplicates some+ source pixels and not others, and pixel art then looks smeared. Rounded+ half up (Python's ``round`` would send 4.5 to 4) and never below 1."""try:- edge = max(1, int(frame_size))+ edge = max(1, int(extent))ratio = float(dpi_ratio) if math.isfinite(float(dpi_ratio)) else 1.0scale = float(pet_scale) if math.isfinite(float(pet_scale)) else 1.0except (TypeError, ValueError):return 1- target = PET_TARGET_EDGE_PX * max(0.1, ratio) * max(0.1, scale)+ target = PET_TARGET_FIGURE_PX * max(0.1, ratio) * max(0.1, scale)return max(1, int(math.floor(target / edge + 0.5)))-def frame_index(elapsed_s: float, frames: int, fps: float, loop: bool) -> int:- """Which frame of an animation is due ``elapsed_s`` after it started."""+def frame_index(+ elapsed_s: float,+ frames: int,+ fps: float,+ loop: bool,+ *,+ accent_frames: int = 0,+ accent_every: int = 1,+) -> int:+ """Which frame of an animation is due ``elapsed_s`` after it started.++ With an accent (``accent_frames`` > 0, looping rows only) the last+ ``accent_frames`` cells play once every ``accent_every`` passes over the+ others — a blink every few seconds instead of on every loop.+ """count = max(1, int(frames))if count == 1 or fps <= 0:return 0step = int(math.floor(max(0.0, elapsed_s) * float(fps)))- if loop:+ if not loop:+ return min(step, count - 1)+ accent = max(0, min(count - 1, int(accent_frames)))+ if accent == 0:return step % count- return min(step, count - 1)+ base = count - accent+ every = max(1, int(accent_every))+ cycle = base * every + accent+ position = step % cycle+ if position < base * every:+ return position % base+ return base + (position - base * every)def seconds_to_next_frame(elapsed_s: float, frames: int, fps: float, loop: bool) -> float | None:@@ -117,6 +163,72 @@ def seconds_to_next_frame(elapsed_s: float, frames: int, fps: float, loop: bool)return max(0.0, boundary - elapsed)+def ping_pong_index(elapsed_s: float, frames: int, fps: float) -> int:+ """Back and forth over a row (0, 1, …, n-1, …, 1): a mouth that opens and closes."""+ count = max(1, int(frames))+ if count == 1 or fps <= 0:+ return 0+ period = 2 * (count - 1)+ step = int(math.floor(max(0.0, elapsed_s) * float(fps))) % period+ return step if step < count else period - step+++def level_frame(level: float, frames: int) -> int:+ """The talking frame for a smoothed 0..1 output level (row is closed → widest)."""+ count = max(1, int(frames))+ if count == 1 or level < LEVEL_SILENCE:+ return 0+ span = max(1e-6, LEVEL_OPEN_SPAN)+ index = 1 + int(math.floor((level - LEVEL_SILENCE) / span * (count - 1)))+ return max(1, min(count - 1, index))+++def _alpha_box(frame: Image.Image) -> tuple[int, int, int, int] | None:+ """Bounding box of the opaque pixels of one RGBA frame (``None`` when empty)."""+ if frame.mode == "RGBA":+ return frame.getchannel("A").point(lambda a: 255 if a >= 128 else 0).getbbox()+ return frame.getbbox()+++def _union(boxes: Sequence[tuple[int, int, int, int] | None]) -> tuple[int, int, int, int] | None:+ real = [box for box in boxes if box is not None]+ if not real:+ return None+ return (+ min(b[0] for b in real),+ min(b[1] for b in real),+ max(b[2] for b in real),+ max(b[3] for b in real),+ )+++def figure_crop(+ frames: Mapping[str, Sequence[Image.Image]], cell: int+) -> tuple[tuple[int, int, int, int], tuple[int, int]]:+ """The crop every frame shares, and the idle figure's visible ``(w, h)``.++ The crop covers every pixel any frame of any state paints (effects+ included), symmetric around the cell's vertical centre line so the figure+ stays centred over the control strip; its bottom is the lowest painted+ row, so the strip hangs right under the feet. The idle size is what the+ on-screen size is chosen by — sparkles and sound arcs must not shrink the+ pet.+ """+ every = _union([_alpha_box(frame) for sequence in frames.values() for frame in sequence])+ idle_frames = frames.get("idle") or next(iter(frames.values()), ())+ idle = _union([_alpha_box(frame) for frame in idle_frames]) or every+ if every is None:+ return (0, 0, cell, cell), (cell, cell)+ centre = cell / 2.0+ half = max(centre - every[0], every[2] - centre) + _CROP_MARGIN+ x0 = max(0, int(math.floor(centre - half)))+ x1 = min(cell, int(math.ceil(centre + half)))+ y0 = max(0, every[1] - _CROP_MARGIN)+ y1 = min(cell, every[3])+ assert idle is not None # noqa: S101 — ``every`` is not None, so neither is ``idle``+ return (x0, y0, x1, y1), (idle[2] - idle[0], idle[3] - idle[1])++def _default_loader(pet_id: str) -> Any:from jarvis.ui.pets.loader import load_pet_by_id # noqa: PLC0415 — engine is lazy@@ -140,8 +252,8 @@ class PetRenderer:``render(t, mode, level)`` matches the mascot / voice-orb renderers; ``t``and ``level`` are accepted for that protocol and ignored — the pet's clock- is its state machine's, and its figure does not follow the audio level (the- control strip's orb does). All methods run on the Tk thread.+ is its state machine's, and the output level reaches it through+ :meth:`feed_level`. All methods run on the Tk thread."""def __init__(@@ -167,8 +279,12 @@ class PetRenderer:self._frames: dict[str, tuple[Image.Image, ...]] = {}self._factor = 1self._size = (1, 1)+ self._figure_width = 0self._blank: Image.Image | None = Noneself._pet_id = NO_PET_ID+ self._level = 0.0+ self._level_at = -math.inf+ self._smoothed = 0.0self.load(pet_id)# -- pack ------------------------------------------------------------@@ -210,19 +326,21 @@ class PetRenderer:self._use_strip_only_size()returnedge = int(pack.manifest.frame_size)- factor = pixel_factor(edge, self._dpi_ratio, self._pet_scale)source: Mapping[str, Any] = pack.frames- # States that borrow another row (STATE_FALLBACKS) share the SAME- # source tuple in the pack; scale each tuple once, or a pet with only- # an ``idle`` row would hold seven scaled copies of it.- scaled_by_source: dict[int, tuple[Image.Image, ...]] = {}- frames: dict[str, tuple[Image.Image, ...]] = {}try:+ crop, (idle_w, idle_h) = figure_crop(source, edge)+ factor = pixel_factor(max(idle_w, idle_h), self._dpi_ratio, self._pet_scale)+ # States that borrow another row (STATE_FALLBACKS) share the SAME+ # source tuple in the pack; scale each tuple once, or a pet with+ # only an ``idle`` row would hold seven scaled copies of it.+ scaled_by_source: dict[int, tuple[Image.Image, ...]] = {}+ frames: dict[str, tuple[Image.Image, ...]] = {}for state, sequence in source.items():scaled = scaled_by_source.get(id(sequence))if scaled is None:scaled = tuple(- self._to_color_key(frame, factor, self._color_key) for frame in sequence+ self._to_color_key(frame.crop(crop), factor, self._color_key)+ for frame in sequence)scaled_by_source[id(sequence)] = scaledframes[str(state)] = scaled@@ -236,13 +354,15 @@ class PetRenderer:returnself._frames = framesself._factor = factor- self._size = (edge * factor, edge * factor)+ self._size = ((crop[2] - crop[0]) * factor, (crop[3] - crop[1]) * factor)+ self._figure_width = idle_w * factordef _use_strip_only_size(self) -> None:"""No figure: the window is a 1 px line as wide as the strip."""- strip_w, _strip_h = orb_controls.pet_strip_size(self._dpi_ratio)+ strip_w, _strip_h = orb_controls.pet_strip_size(self.strip_scale)self._factor = 1self._size = (max(1, strip_w), 1)+ self._figure_width = 0@propertydef pet_id(self) -> str:@@ -262,6 +382,16 @@ class PetRenderer:def factor(self) -> int:return self._factor+ @property+ def figure_width(self) -> int:+ """The idle figure's visible width on screen, in pixels (0 without a figure)."""+ return self._figure_width++ @property+ def strip_scale(self) -> float:+ """The control strip's scale: the monitor's DPI ratio times ``pet_scale``."""+ return max(0.25, self._dpi_ratio * self._pet_scale)+@propertydef machine(self) -> Any:return self._machine@@ -280,25 +410,58 @@ class PetRenderer:def state(self) -> str:return str(self._machine.state())+ def feed_level(self, level: float | None, at: float | None) -> None:+ """The latest output level (0..1) and when it arrived, on this renderer's clock."""+ if level is None or at is None:+ return+ try:+ value = float(level)+ stamp = float(at)+ except (TypeError, ValueError):+ return+ if not (math.isfinite(value) and math.isfinite(stamp)):+ return+ if stamp - self._level_at > LEVEL_FRESH_S:+ self._smoothed = 0.0 # the voice paused: open from closed again+ self._level = max(0.0, min(1.0, value))+ self._level_at = stamp+ # Smoothed once per feed (the overlay feeds once per tick), not once+ # per read — frame_key, render and the pacing all read the same value.+ self._smoothed += LEVEL_SMOOTHING * (self._level - self._smoothed)++ def _level_fresh(self) -> bool:+ return float(self._clock()) - self._level_at <= LEVEL_FRESH_S+# -- frame selection -------------------------------------------------- def _current(self) -> tuple[str, Any, int, float]:- """(resolved state, spec, frame index, elapsed seconds) for now."""+ def _current(self) -> tuple[str, Any, int, float, bool]:+ """(resolved state, spec, frame index, elapsed seconds, level-driven) for now."""state = self.state()resolved, spec = self._pack.manifest.spec_for(state)resolved = str(resolved)sequence = self._frames.get(resolved) or self._frames.get(state) or ()frames = len(sequence) or max(1, int(getattr(spec, "frames", 1)))elapsed = max(0.0, float(self._clock()) - float(self._machine.state_started_at()))- index = frame_index(elapsed, frames, float(spec.fps), bool(spec.loop))- return resolved, spec, index, elapsed+ if state == "talking" and frames > 1:+ if self._level_fresh():+ return resolved, spec, level_frame(self._smoothed, frames), elapsed, True+ return resolved, spec, ping_pong_index(elapsed, frames, float(spec.fps)), elapsed, False+ index = frame_index(+ elapsed,+ frames,+ float(spec.fps),+ bool(spec.loop),+ accent_frames=int(getattr(spec, "accent_frames", 0)),+ accent_every=int(getattr(spec, "accent_every", 1)),+ )+ return resolved, spec, index, elapsed, Falsedef frame_key(self, t: float = 0.0) -> Hashable:"""A key that changes exactly when the picture on screen changes."""_ = tif self._pack is None:return ("none", self._size)- resolved, _spec, index, _elapsed = self._current()+ resolved, _spec, index, _elapsed, _driven = self._current()return (self._pet_id, self._factor, resolved, index)def next_frame_delay_ms(self, t: float = 0.0) -> int:@@ -309,11 +472,15 @@ class PetRenderer:if change is not None:waits.append(max(0.0, float(change)))if self._pack is not None:- resolved, spec, _index, elapsed = self._current()- frames = len(self._frames.get(resolved) or ()) or int(getattr(spec, "frames", 1))- boundary = seconds_to_next_frame(elapsed, frames, float(spec.fps), bool(spec.loop))- if boundary is not None:- waits.append(boundary)+ resolved, spec, _index, elapsed, driven = self._current()+ if driven:+ waits.append(LEVEL_POLL_MS / 1000.0)+ else:+ frames = len(self._frames.get(resolved) or ()) or int(getattr(spec, "frames", 1))+ loop = bool(spec.loop) or self.state() == "talking"+ boundary = seconds_to_next_frame(elapsed, frames, float(spec.fps), loop)+ if boundary is not None:+ waits.append(boundary)if not waits:return MAX_FRAME_DELAY_MS# A hair past the boundary, so the tick lands on the new frame rather@@ -330,7 +497,7 @@ class PetRenderer:if self._blank is None:self._blank = Image.new("RGB", self._size, self._color_key)return self._blank- resolved, _spec, index, _elapsed = self._current()+ resolved, _spec, index, _elapsed, _driven = self._current()sequence = self._frames.get(resolved) or self._frames.get("idle") or ()if not sequence:if self._blank is None: