Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(pets): the pet holds a phone to its ear during a voice call

rubenluetke10-beepaa46b796c464
diff --git a/docs/pets.md b/docs/pets.md
index fa9126030e..ceb8e285a2 100644
--- a/docs/pets.md
+++ b/docs/pets.md
@@ -35,7 +35,15 @@ one click.
listening, dictating or talking, and carry a travelling highlight while
thinking or transcribing;
- speaker: silence the assistant's voice for this session (TTS volume 0,
- mirrored from `VoiceSpeakerMuteChanged`).
+ mirrored from `VoiceSpeakerMuteChanged`);
+ - phone (its own disc, in the bell's look): call Jarvis — the handset rings
+ while it dials — or, during a conversation, hang up (the handset lies
+ flat).
+- **On the phone**: while a voice conversation runs (listen / think / speak)
+ the pet holds a small pixel-art handset to the right side of its head
+ (`pet_renderer.with_phone`), drawn at the pack's own pixel factor and found
+ per frame, so it follows a bobbing head. Every pack gets it; no sprite row
+ is needed.
- **The thought bubble** above the pet's head while Jarvis thinks, drawn in
the pets' pixel art: a white pixel cloud with a dark outline and two small
puffs trailing down to the head. Bobbing dots while Jarvis just thinks, the
diff --git a/tests/unit/ui/test_pet_overlay_renderer.py b/tests/unit/ui/test_pet_overlay_renderer.py
index c72b7185d2..81da777f5a 100644
--- a/tests/unit/ui/test_pet_overlay_renderer.py
+++ b/tests/unit/ui/test_pet_overlay_renderer.py
@@ -420,7 +420,7 @@ def test_a_live_level_drives_the_talking_frame() -> None:
renderer.on_mode("speak")
renderer.feed_level(0.9, clock.now)
key = renderer.frame_key()
- assert key[-1] == 3 # loud: the widest mouth
+ assert key[3] == 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
@@ -428,7 +428,7 @@ def test_a_live_level_drives_the_talking_frame() -> None:
for _ in range(8):
clock.now += 0.05
renderer.feed_level(0.0, clock.now)
- assert renderer.frame_key()[-1] == 0
+ assert renderer.frame_key()[3] == 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
@@ -441,7 +441,7 @@ def test_garbage_levels_are_ignored() -> None:
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)
+ assert renderer.frame_key()[3] in range(4)
# --- idle acts ----------------------------------------------------------------
@@ -489,14 +489,14 @@ def test_an_idle_pet_plays_an_act_after_a_while_and_returns_to_idle() -> None:
clock.now += first_delay - 0.01
assert renderer.frame_key()[2] == "idle"
clock.now += 0.02
- assert renderer.frame_key()[2:] == ("act:wave", 0)
+ assert renderer.frame_key()[2:4] == ("act:wave", 0)
clock.now += 0.11
- assert renderer.frame_key()[2:] == ("act:wave", 1)
+ assert renderer.frame_key()[2:4] == ("act:wave", 1)
clock.now += 0.25 # past the act's 0.3 s
assert renderer.frame_key()[2] == "idle"
clock.now += gap + 0.01
# Never the same act twice in a row.
- assert renderer.frame_key()[2:] == ("act:hop", 0)
+ assert renderer.frame_key()[2:4] == ("act:hop", 0)
def test_any_other_state_cancels_the_act() -> None:
@@ -533,3 +533,50 @@ def test_a_pet_without_acts_just_idles() -> None:
renderer, _ = _renderer(clock)
clock.now += 120.0
assert renderer.frame_key()[2] == "idle"
+
+
+# --- on the phone ------------------------------------------------------------
+
+_KEY = (255, 0, 255)
+
+
+def _keyed_figure(factor: int = 3) -> Image.Image:
+ """A 30 x 30 source-pixel window with a 16 x 24 figure in the middle."""
+ frame = Image.new("RGB", (30 * factor, 30 * factor), _KEY)
+ frame.paste((200, 60, 60), (7 * factor, 3 * factor, 23 * factor, 27 * factor))
+ return frame
+
+
+def _phone_pixels(frame: Image.Image) -> int:
+ white = pr.PHONE_COLORS["W"]
+ return sum(1 for px in frame.getdata() if px[:3] == white)
+
+
+def test_the_phone_is_held_at_the_side_of_the_head_inside_the_frame() -> None:
+ frame = _keyed_figure()
+ held = pr.with_phone(frame, 3, _KEY)
+ assert held.size == frame.size
+ assert _phone_pixels(frame) == 0 # the cached original is never painted on
+ box = Image.new("1", held.size)
+ box.putdata([px[:3] == pr.PHONE_COLORS["W"] for px in held.getdata()])
+ x0, y0, _x1, y1 = box.getbbox()
+ # Earpiece overlapping the figure's right edge (source x 22), in its top half.
+ assert 18 * 3 <= x0 <= 23 * 3
+ assert 3 * 3 <= y0 and y1 <= 27 * 3
+
+
+def test_an_empty_frame_gets_no_phone() -> None:
+ blank = Image.new("RGB", (60, 60), _KEY)
+ assert pr.with_phone(blank, 2, _KEY) is blank
+
+
+def test_a_voice_conversation_puts_the_phone_to_the_ear_and_ending_it_puts_it_away() -> None:
+ renderer = pr.PetRenderer("gigi")
+ idle_key = renderer.frame_key()
+ assert _phone_pixels(renderer.render()) == 0
+ renderer.on_mode("speak")
+ assert renderer.on_call and renderer.frame_key() != idle_key
+ assert _phone_pixels(renderer.render()) > 0
+ renderer.on_mode("idle")
+ assert not renderer.on_call
+ assert _phone_pixels(renderer.render()) == 0
diff --git a/ui/orb/pet_renderer.py b/ui/orb/pet_renderer.py
index f8b6668a31..92a76f3343 100644
--- a/ui/orb/pet_renderer.py
+++ b/ui/orb/pet_renderer.py
@@ -90,6 +90,109 @@ _ACT_KEY = "act:"
_ColorKey = tuple[int, int, int]
+#: The handset a pet holds to its ear while a voice conversation runs — the
+#: figure's half of the strip's phone button. Pixel art in source pixels,
+#: drawn at the pet's own factor so it matches every pack's pixel grid. The
+#: open side (earpiece and mouthpiece) faces the pet; the spine is on the right.
+#: ``O`` outline, ``B`` body, ``H`` highlight, ``.`` transparent.
+PHONE_SPRITE: tuple[str, ...] = (
+ ".OOOOO.",
+ "OWWWHWO",
+ "OWWWWWO",
+ ".OOOWWO",
+ "....OWO",
+ "....OWO",
+ "....OHO",
+ "....OWO",
+ ".OOOWWO",
+ "OWWWWWO",
+ "OWWWHWO",
+ ".OOOOO.",
+)
+#: The strip's glyph white and its sky-blue accent inside a near-black
+#: outline: light enough to read against a dark desktop and a dark pet alike.
+PHONE_COLORS: dict[str, tuple[int, int, int]] = {
+ "O": (13, 17, 23),
+ "W": (232, 233, 238),
+ "H": (126, 186, 255),
+}
+#: Where the ear is looked for: a band of the figure's height, from the top.
+PHONE_EAR_BAND = (0.22, 0.5)
+#: The earpiece's top, as a share of the figure's height from its top.
+PHONE_TOP = 0.2
+#: How many source pixels of the earpiece overlap the side of the head.
+PHONE_OVERLAP = 3
+#: Voice modes in which the pet is "on the phone" — the same set that turns
+#: the strip's phone button into hang-up.
+CALL_MODES: frozenset[str] = frozenset({"listen", "think", "speak"})
+
+
+def _figure_rows(frame: Image.Image, factor: int, key: _ColorKey) -> list[list[bool]]:
+ """Which source pixels of a scaled, colour-keyed frame are painted."""
+ width, height = frame.size
+ f = max(1, int(factor))
+ px = frame.load()
+ half = f // 2
+ return [
+ [px[x * f + half, y * f + half][:3] != key for x in range(width // f)]
+ for y in range(height // f)
+ ]
+
+
+def _head_edge(row: list[bool]) -> int | None:
+ """The head's right edge on one row: walk out from the centre column.
+
+ Walking (and tolerating one-pixel gaps) instead of taking the rightmost
+ painted pixel keeps loose sparkles or floating marks beside a pet from
+ being mistaken for its ear.
+ """
+ x = len(row) // 2
+ if not any(row[max(0, x - 2) : x + 3]):
+ return None
+ edge = None
+ while x < len(row):
+ if row[x]:
+ edge = x
+ elif not (x + 1 < len(row) and row[x + 1]):
+ break
+ x += 1
+ return edge
+
+
+def with_phone(frame: Image.Image, factor: int, key: _ColorKey) -> Image.Image:
+ """``frame`` with the handset held at the right side of the pet's head.
+
+ The ear is the rightmost painted pixel in the head band of THIS frame, so
+ the phone follows a bobbing head. The prop is clamped inside the frame:
+ the window never grows for it, and nothing is drawn off-screen.
+ """
+ rows = _figure_rows(frame, factor, key)
+ painted = [y for y, row in enumerate(rows) if any(row)]
+ if not painted:
+ return frame
+ top, bottom = painted[0], painted[-1]
+ fig_h = bottom - top + 1
+ band = range(top + int(fig_h * PHONE_EAR_BAND[0]), top + max(1, int(fig_h * PHONE_EAR_BAND[1])))
+ ear = max((e for e in (_head_edge(rows[y]) for y in band) if e is not None), default=None)
+ if ear is None:
+ return frame
+ width_s = len(rows[0]) if rows else 0
+ sprite_w = len(PHONE_SPRITE[0])
+ x0 = min(ear + 1 - PHONE_OVERLAP, width_s - sprite_w)
+ y0 = min(top + int(fig_h * PHONE_TOP), len(rows) - len(PHONE_SPRITE))
+ if x0 < 0 or y0 < 0:
+ return frame
+ out = frame.copy()
+ f = max(1, int(factor))
+ for sy, line in enumerate(PHONE_SPRITE):
+ for sx, cell in enumerate(line):
+ color = PHONE_COLORS.get(cell)
+ if color is None:
+ continue
+ x, y = (x0 + sx) * f, (y0 + sy) * f
+ out.paste(color, (x, y, x + f, y + f))
+ return out
+
def dpi_ratio_for(points_per_inch: float | None, platform: str = sys.platform) -> float:
"""The display scale factor from what Tk reports as one inch, in pixels.
@@ -308,6 +411,9 @@ class PetRenderer:
self._level = 0.0
self._level_at = -math.inf
self._smoothed = 0.0
+ #: A voice conversation runs: the pet holds the phone to its ear.
+ self._on_call = False
+ self._phone_frames: dict[Hashable, Image.Image] = {}
self.load(pet_id)
# -- pack ------------------------------------------------------------
@@ -343,6 +449,7 @@ class PetRenderer:
def _rescale(self) -> None:
self._frames = {}
+ self._phone_frames = {}
self._act_names: tuple[str, ...] = ()
self._act = None
self._blank = None
@@ -432,6 +539,12 @@ class PetRenderer:
def on_mode(self, mode: str) -> None:
self._machine.on_mode(mode)
+ self._on_call = str(mode) in CALL_MODES
+
+ @property
+ def on_call(self) -> bool:
+ """The pet is holding the phone (a voice conversation runs)."""
+ return self._on_call
def on_outcome(self, kind: str) -> None:
self._machine.on_outcome(kind)
@@ -542,7 +655,7 @@ class PetRenderer:
if self._pack is None:
return ("none", self._size)
resolved, _spec, index, _elapsed, _driven = self._current()
- return (self._pet_id, self._factor, resolved, index)
+ return (self._pet_id, self._factor, resolved, index, self._on_call)
def next_frame_delay_ms(self, t: float = 0.0) -> int:
"""How long the overlay may sleep before the next repaint is due."""
@@ -588,4 +701,12 @@ class PetRenderer:
if self._blank is None:
self._blank = Image.new("RGB", self._size, self._color_key)
return self._blank
- return sequence[min(index, len(sequence) - 1)]
+ frame = sequence[min(index, len(sequence) - 1)]
+ if not self._on_call:
+ return frame
+ cache_key = (resolved, min(index, len(sequence) - 1))
+ held = self._phone_frames.get(cache_key)
+ if held is None:
+ held = with_phone(frame, self._factor, self._color_key)
+ self._phone_frames[cache_key] = held
+ return held