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): a phone button on the pet strip to call Jarvis and hang up

rubenluetke10-beep4328bb9d2c9f
diff --git a/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsx b/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsx
index 12b5b2fb3b..c462e5ef7d 100644
--- a/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsx
+++ b/jarvis/ui/web/frontend/src/components/pets/PetControlStripPreview.tsx
@@ -1,4 +1,4 @@
-import { Mic, SquarePen, Volume2 } from "lucide-react";
+import { Mic, Phone, SquarePen, Volume2 } from "lucide-react";
import { cn } from "@/lib/utils";
@@ -11,6 +11,9 @@ import { cn } from "@/lib/utils";
const STRIP_FILL = "#171b26";
const STRIP_ICON = "#e8e9ee";
const STRIP_DIVIDER = "#303748";
+/** The phone disc's call green (`PET_CALL_FILL`); it turns red during a call. */
+const CALL_FILL = "#16a34a";
+const CALL_ICON = "#ffffff";
/** 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%)";
@@ -18,7 +21,8 @@ const ORB_GRADIENT =
/**
* 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
+ * microphone, the talk orb and the speaker, split by faint dividers, then the
+ * green phone that calls Jarvis (red to hang up during a call). Shown on
* the settings page so the user knows what sits under the pet before
* switching it on.
*
@@ -72,6 +76,13 @@ export function PetControlStripPreview({
<Volume2 className={icon} strokeWidth={2} />
</span>
</span>
+ <span
+ data-testid="pet-strip-call"
+ className={cn("grid place-items-center rounded-full", height, disc)}
+ style={{ backgroundColor: CALL_FILL, color: CALL_ICON }}
+ >
+ <Phone className={icon} strokeWidth={2} />
+ </span>
</div>
);
}
diff --git a/tests/unit/ui/test_orb_controls_pet.py b/tests/unit/ui/test_orb_controls_pet.py
index 5431d2af2b..abc31001f4 100644
--- a/tests/unit/ui/test_orb_controls_pet.py
+++ b/tests/unit/ui/test_orb_controls_pet.py
@@ -25,6 +25,8 @@ def _centre(action: str, scale: float = 1.0) -> tuple[float, float]:
layout = controls.pet_strip_layout(scale)
if action == "bell":
return layout.pen[0], layout.pen[1]
+ if action == "call":
+ return layout.call[0], layout.call[1]
for name, x0, x1 in layout.slots:
if name == action:
return (x0 + x1) / 2.0, (layout.pill[1] + layout.pill[3]) / 2.0
@@ -44,13 +46,16 @@ def test_every_pet_action_is_reachable_at_its_centre(scale: float) -> None:
def test_the_voice_orb_row_keeps_its_own_actions() -> None:
assert controls.ACTIONS == ("attach", "mic", "close", "speaker")
- assert controls.PET_ACTIONS == ("bell", "mic_mute", "orb", "speaker")
+ assert controls.PET_ACTIONS == ("bell", "mic_mute", "orb", "speaker", "call")
def test_the_gap_between_pen_and_pill_is_a_drag_handle_not_a_button() -> None:
layout = controls.pet_strip_layout(1.0)
gap_x = (layout.pen[0] + layout.pen[2] + layout.pill[0]) / 2.0
assert controls.pet_hit_test(gap_x, layout.height / 2.0) is None
+ # So is the gap between the pill and the phone.
+ call_gap_x = (layout.pill[2] + layout.call[0] - layout.call[2]) / 2.0
+ assert controls.pet_hit_test(call_gap_x, layout.height / 2.0) is None
# The padding band above the controls is empty too.
assert controls.pet_hit_test(_centre("orb")[0], 0.5) is None
@@ -335,3 +340,43 @@ def test_hover_lifts_a_round_patch_not_the_whole_slot() -> None:
# 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_HOVER
+
+
+# --- the phone: call and hang up ---------------------------------------------
+
+
+def _call_centre_pixel(state: controls.PetStripState) -> tuple[int, int, int]:
+ frame = controls.render_pet_strip(state, 1.0)
+ cx, cy, r = controls.pet_strip_layout(1.0).call
+ # Just inside the rim: the disc's fill, clear of the handset.
+ return frame.getpixel((int(cx), int(cy - r + 2)))
+
+
+def test_the_phone_is_green_to_call_and_red_to_hang_up() -> None:
+ assert _call_centre_pixel(controls.PetStripState()) == controls.PET_CALL_FILL
+ assert _call_centre_pixel(controls.PetStripState(active=True)) == controls.PET_HANGUP_FILL
+ hovered = controls.PetStripState(active=True, hovered="call")
+ assert _call_centre_pixel(hovered) == controls.PET_HANGUP_FILL_HOVER
+
+
+def _handset_pixels(state: controls.PetStripState) -> list[tuple[int, int, int]]:
+ frame = controls.render_pet_strip(state, 2.0)
+ cx, cy, r = controls.pet_strip_layout(2.0).call
+ box = (int(cx - r * 0.6), int(cy - r * 0.6), int(cx + r * 0.6), int(cy + r * 0.6))
+ return list(frame.crop(box).getdata())
+
+
+def test_the_handset_turns_flat_to_hang_up() -> None:
+ call = [px == controls.PET_CALL_ICON for px in _handset_pixels(controls.PetStripState())]
+ hangup = [
+ px == controls.PET_CALL_ICON for px in _handset_pixels(controls.PetStripState(active=True))
+ ]
+ assert any(call) and any(hangup) and call != hangup
+
+
+def test_pressing_call_rings_the_handset_and_then_it_rests() -> None:
+ rest = _handset_pixels(controls.PetStripState())
+ assert _handset_pixels(controls.PetStripState(call_ring=4)) != rest
+ end = controls.PET_RING_PHASES * controls.PET_CALL_RING_PASSES
+ assert controls.call_ring_angle(0) == 0.0 == controls.call_ring_angle(end)
+ assert any(controls.call_ring_angle(p) != 0.0 for p in range(1, end))
diff --git a/tests/unit/ui/test_pet_notices.py b/tests/unit/ui/test_pet_notices.py
index 41c7725db1..c559f5770b 100644
--- a/tests/unit/ui/test_pet_notices.py
+++ b/tests/unit/ui/test_pet_notices.py
@@ -237,6 +237,17 @@ def test_the_bell_toggles_reports_and_clears(monkeypatch: pytest.MonkeyPatch) ->
assert seen == [False, True]
+def test_the_phone_calls_when_idle_and_hangs_up_in_a_call() -> None:
+ pet, _strip, _column = _pet()
+ calls: list[str] = []
+ pet.set_on_talk(lambda: calls.append("talk"))
+ pet.set_on_hangup(lambda: calls.append("hangup"))
+ pet._on_control_action("call")
+ pet._mode = "listen"
+ pet._on_control_action("call")
+ assert calls == ["talk", "hangup"]
+
+
def test_the_thinking_line_shows_the_current_step_else_the_heading() -> None:
pet, _strip, column = _pet()
pet.show_status("Planning", "Search the web")
diff --git a/ui/orb/controls.py b/ui/orb/controls.py
index dcc5680f51..45316705cf 100644
--- a/ui/orb/controls.py
+++ b/ui/orb/controls.py
@@ -369,19 +369,23 @@ def render_row(
# The desktop pet (``docs/pets.md``) carries its controls in the shape the
# Codex companion made familiar: a bell 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.
+# low-contrast dividers, then the phone in its own disc — green to call Jarvis,
+# red to hang up, the colours every phone app uses for exactly those two. 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, ...] = ("bell", "mic_mute", "orb", "speaker")
+PET_ACTIONS: tuple[str, ...] = ("bell", "mic_mute", "orb", "speaker", "call")
+#: The actions inside the pill, left to right.
+PET_PILL_ACTIONS: tuple[str, ...] = ("mic_mute", "orb", "speaker")
#: 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 bell disc's diameter.
+#: ``PET_SLOT`` is the pill's height and the bell and phone discs' diameter.
PET_SLOT = 50
PET_ICON_SLOT = 46
PET_ORB_SLOT = 52
@@ -469,6 +473,21 @@ PET_RING_PHASES = 14
PET_RING_STEP_S = 0.04
PET_RING_DEG = 16.0
+#: The phone disc: a call button is green and a hang-up button red in every
+#: phone app, so the disc borrows that language instead of the strip's
+#: near-black. A shade lighter under the pointer; the handset is white.
+PET_CALL_FILL = (22, 163, 74)
+PET_CALL_FILL_HOVER = (34, 197, 94)
+PET_HANGUP_FILL = (220, 38, 38)
+PET_HANGUP_FILL_HOVER = (239, 68, 68)
+PET_CALL_ICON = (255, 255, 255)
+#: Pressing call rings the handset: the bell's damped swing, played
+#: ``PET_CALL_RING_PASSES`` times so it reads as a phone ringing out.
+PET_CALL_RING_PASSES = 2
+#: The handset's turn from its hang-up pose (lying flat, ends down) to its
+#: call pose (tilted, earpiece up) — the same 135 degrees phone apps animate.
+PET_CALL_TILT_DEG = -135.0
+
def _spx(value: float, scale: float) -> int:
"""One unscaled length at ``scale``, never below one pixel."""
@@ -483,6 +502,8 @@ class PetStripLayout:
height: int
#: The bell disc: centre and radius.
pen: tuple[float, float, float]
+ #: The phone disc: centre and radius.
+ call: tuple[float, float, float]
#: The pill's bounding box ``(x0, y0, x1, y1)``, x1/y1 exclusive.
pill: tuple[int, int, int, int]
#: Each pill action's horizontal span ``(x0, x1)`` inside the window.
@@ -512,18 +533,20 @@ def pet_strip_layout(scale: float = 1.0) -> PetStripLayout:
slots: list[tuple[str, int, int]] = []
dividers: list[int] = []
x = pill_x0 + inset
- for index, action in enumerate(PET_ACTIONS[1:]):
+ for index, action in enumerate(PET_PILL_ACTIONS):
slots.append((action, x, x + widths[action]))
x += widths[action]
- if index < 2:
+ if index < len(PET_PILL_ACTIONS) - 1:
dividers.append(x)
x += divider
- width = pill[2] + pad
+ call = (pill[2] + gap + pen_r, pad + pen_r, pen_r)
+ width = pill[2] + gap + slot + pad
height = slot + 2 * pad
return PetStripLayout(
width=width,
height=height,
pen=pen,
+ call=call,
pill=pill,
slots=tuple(slots),
dividers=tuple(dividers),
@@ -552,7 +575,7 @@ def _inside_stadium(x: float, y: float, box: tuple[int, int, int, int]) -> bool:
def pet_hit_test(x: float, y: float, scale: float = 1.0) -> str | None:
"""Which pet action a click at ``(x, y)`` lands on, or ``None``.
- Outside the bell disc and the pill is nothing — that empty area is where the
+ Outside the bell disc, the pill and the phone disc is nothing — that empty area is where the
user grabs the strip to drag the pet (the only handle when the pet is
"None"). Inside the pill every pixel belongs to a slot: a divider resolves
to the nearer neighbour instead of eating the click.
@@ -561,6 +584,9 @@ def pet_hit_test(x: float, y: float, scale: float = 1.0) -> str | None:
pcx, pcy, pr = layout.pen
if math.hypot(x - pcx, y - pcy) <= pr:
return "bell"
+ ccx, ccy, cr = layout.call
+ if math.hypot(x - ccx, y - ccy) <= cr:
+ return "call"
if not _inside_stadium(x, y, layout.pill):
return None
best: str | None = None
@@ -596,8 +622,8 @@ class PetStripState:
mic_muted: bool = False
#: The assistant's voice is muted for this session.
speaker_muted: bool = False
- #: A conversation is running — the talk control hangs up instead of
- #: starting one.
+ #: A conversation is running — the talk control and the phone hang up
+ #: instead of starting one.
active: bool = False
#: The voice level step (``quantize_level``); drawn only in ``voice``.
level: int = 0
@@ -610,6 +636,9 @@ class PetStripState:
notify_off: bool = False
#: The bell's swing step (``ring_angle``); 0 is at rest.
ring: int = 0
+ #: The handset's ringing step, counted across ``PET_CALL_RING_PASSES``
+ #: swings (``call_ring_angle``); 0 is at rest.
+ call_ring: int = 0
# -- glyphs ------------------------------------------------------------------
@@ -725,6 +754,49 @@ def _glyph_bell(pen: _Pen, color: _Rgb, *, angle: float = 0.0, slashed: bool = F
_glyph_slash(pen, color)
+def call_ring_angle(phase: int) -> float:
+ """The handset's shake in degrees at ``phase``: the bell's swing, repeated."""
+ if phase <= 0 or phase >= PET_RING_PHASES * PET_CALL_RING_PASSES:
+ return 0.0
+ return ring_angle(phase % PET_RING_PHASES)
+
+
[email protected]_cache(maxsize=1)
+def _handset_outline() -> tuple[tuple[tuple[float, float], ...], ...]:
+ """The handset in its hang-up pose on the 24-unit grid: a flat bow, ends down.
+
+ Three polylines — the grip and the two stubby ear and mouth pieces — drawn
+ with a heavy stroke, so the handset reads as one solid shape at 20 px.
+ """
+ grip = tuple(_arc_points(12, 17.2, 8.2, 207, 333, steps=14))
+ left = grip[0]
+ right = grip[-1]
+ ear = (left, (left[0] - 0.9, left[1] + 3.0))
+ mouth = (right, (right[0] + 0.9, right[1] + 3.0))
+ return (grip, ear, mouth)
+
+
+def _glyph_phone(pen: _Pen, color: _Rgb, *, hangup: bool, shake: float = 0.0) -> None:
+ """The handset: tilted to call, lying flat to hang up; ``shake`` rings it."""
+ a = math.radians((0.0 if hangup else PET_CALL_TILT_DEG) + shake)
+ cos_a, sin_a = math.cos(a), math.sin(a)
+ pivot_u, pivot_v = 12.0, 14.0
+
+ def turn(point: tuple[float, float]) -> tuple[float, float]:
+ # Turned about the handset's own middle, then centred on the grid.
+ du, dv = point[0] - pivot_u, point[1] - pivot_v
+ return (12.0 + du * cos_a - dv * sin_a, 12.0 + du * sin_a + dv * cos_a)
+
+ base = pen.width
+ grip, ear, mouth = _handset_outline()
+ pen.width = max(1, int(round(base * 1.6)))
+ pen.lines([turn(point) for point in grip], color)
+ pen.width = max(1, int(round(base * 2.4)))
+ pen.lines([turn(point) for point in ear], color)
+ pen.lines([turn(point) for point in mouth], color)
+ pen.width = base
+
+
def _glyph_mic(pen: _Pen, color: _Rgb) -> None:
pen.arc(12, 5, 3, 180, 360, color)
pen.lines([(9, 5), (9, 12)], color)
@@ -922,6 +994,27 @@ def _draw_indicator(
layer.paste(stroke, (x0, y0), _stroke_mask(width, h))
+def _render_call_disc(state: PetStripState, diameter: int, scale: float) -> Image.Image:
+ """The phone disc: green with a tilted handset, red with a flat one."""
+ size = diameter * _SS
+ hovered = state.hovered == "call"
+ if state.active:
+ fill = PET_HANGUP_FILL_HOVER if hovered else PET_HANGUP_FILL
+ else:
+ fill = PET_CALL_FILL_HOVER if hovered else PET_CALL_FILL
+ layer = Image.new("RGB", (size, size), fill)
+ d = ImageDraw.Draw(layer)
+ box = _spx(PET_SLOT, scale) * PET_ICON_BOX * _SS
+ stroke = PET_ICON_STROKE * max(0.5, scale) * _SS
+ _glyph_phone(
+ _Pen(d, size / 2.0, size / 2.0, box, stroke),
+ PET_CALL_ICON,
+ hangup=state.active,
+ shake=call_ring_angle(state.call_ring),
+ )
+ return layer.resize((diameter, diameter), Image.Resampling.LANCZOS)
+
+
def _render_pen_disc(state: PetStripState, diameter: int, scale: float) -> Image.Image:
size = diameter * _SS
hovered = state.hovered == "bell"
@@ -993,6 +1086,10 @@ def render_pet_strip(
x0, y0, x1, y1 = layout.pill
pill = _render_pill(state, layout, scale)
frame.paste(pill, (x0, y0), _binary_stadium_mask(x1 - x0, y1 - y0))
+ ccx, ccy, cr = layout.call
+ call_d = int(round(cr * 2))
+ call = _render_call_disc(state, call_d, scale)
+ frame.paste(call, (int(round(ccx - cr)), int(round(ccy - cr))), _disc_mask(call_d))
return frame
diff --git a/ui/orb/overlay.py b/ui/orb/overlay.py
index 384b486c3f..521a187f8d 100644
--- a/ui/orb/overlay.py
+++ b/ui/orb/overlay.py
@@ -2007,7 +2007,7 @@ class PetControlStrip(OrbControlRow):
strip at rest never repaints.
"""
- GUARDED_ACTIONS: tuple[str, ...] = ("orb",)
+ GUARDED_ACTIONS: tuple[str, ...] = ("orb", "call")
#: Longer than the orb row's: the pointer crosses a gap between the
#: figure and the strip, and a strip that vanishes on the way is a miss.
HOVER_GRACE_MS = 600
@@ -2107,6 +2107,7 @@ class PetControlStrip(OrbControlRow):
phase: int | None = None,
notify_off: bool | None = None,
ring: int | None = None,
+ call_ring: int | None = None,
) -> None:
"""Update what the strip says, repainting only on a real change."""
_ = can_attach # the pet strip has no attach control
@@ -2121,6 +2122,7 @@ class PetControlStrip(OrbControlRow):
hovered=current.hovered,
notify_off=current.notify_off if notify_off is None else bool(notify_off),
ring=current.ring if ring is None else int(ring),
+ call_ring=current.call_ring if call_ring is None else int(call_ring),
)
if state == current:
return
@@ -2301,6 +2303,8 @@ class OrbOverlay:
#: The notification cards' window, created with the first card.
self._notices: PetNoticeStack | None = None
self._ring_after_id: str | None = None
+ #: The phone disc's ringing timer, like the bell's.
+ self._call_ring_after_id: str | None = None
#: The monitor's display scale (1.0 at 100 %), read once the root exists.
self._dpi_ratio = 1.0
# Frame-loop bookkeeping: ONE pending tick at most, and for renderers
@@ -3069,6 +3073,34 @@ class OrbOverlay:
self._do_compose()
elif action == "mic_mute":
self._do_mic_mute()
+ elif action == "call":
+ self._do_call()
+
+ def _do_call(self) -> None:
+ """The phone disc: call Jarvis (ringing as it dials), or hang up."""
+ if self._mode not in ("listen", "think", "speak"):
+ self._ring_phone()
+ self._do_talk_or_hangup()
+
+ def _ring_phone(self, phase: int = 1) -> None:
+ """Shake the handset: one strip frame per ``PET_RING_STEP_S``."""
+ root = self._root
+ row = self._controls
+ if root is None or not isinstance(row, PetControlStrip):
+ self._call_ring_after_id = None
+ return
+ if phase == 1 and self._call_ring_after_id is not None:
+ try:
+ root.after_cancel(self._call_ring_after_id)
+ except tk.TclError:
+ logging.getLogger("jarvis.orb").debug("phone timer cancel failed", exc_info=True)
+ if phase >= orb_controls.PET_RING_PHASES * orb_controls.PET_CALL_RING_PASSES:
+ self._call_ring_after_id = None
+ row.set_state(call_ring=0)
+ return
+ row.set_state(call_ring=phase)
+ delay = int(orb_controls.PET_RING_STEP_S * 1000)
+ self._call_ring_after_id = root.after(delay, lambda: self._ring_phone(phase + 1))
def _do_bell_toggle(self) -> None:
"""The bell: notifications on or off for this run (Tk thread).