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 status card shows only real thinking

rubenluetke10-beep7ecdc30ce959
diff --git a/docs/pets.md b/docs/pets.md
index a5bbc9c271..297fed8644 100644
--- a/docs/pets.md
+++ b/docs/pets.md
@@ -26,17 +26,14 @@ one click.
live audio level;
- speaker: silence the assistant's voice for this session (TTS volume 0,
mirrored from `VoiceSpeakerMuteChanged`).
-- **The status bubble** under the strip. It shows short, condensed lines of
- what Jarvis is doing: the live transcript while listening, a "Thinking …"
- header with the current reason, tool or progress line while thinking, and
- the condensed reply while talking. Only spoken replies appear there (voice
- and realtime channels); typed-chat and background answers stay in the app
- window, so the always-on-top bubble never puts them on a shared screen. It
- collapses to two lines, expands to six
- on click, and fades out six seconds after the last update while idle. It can
- be switched off (`[ui] pet_bubble`).
+- **The thinking card** under the strip: a rounded pill with a bold title
+ (what Jarvis is working on) and one muted detail line (the current thought
+ or step). It appears ONLY while Jarvis is really thinking and shows what it
+ thinks — never the live transcript and never the reply, which the user hears
+ anyway (see *The thinking card* below). It can be switched off
+ (`[ui] pet_bubble`).
- **The pet "None"** (`pet_id = "none"`) shows the control strip and the
- bubble without a figure.
+ card without a figure.
The pet stays on screen while Jarvis is idle. The global shortcut
(`[trigger] hotkey_pet_toggle`, default `alt+win+p`) hides it or brings it
@@ -44,6 +41,36 @@ back and to the front; hiding lasts until the next app start. The shortcut is
changed on the My Pets page (Customize); an empty value switches it off. On
Wayland, global shortcuts are a no-op, as for every other shortcut.
+## The thinking card
+
+The card mirrors Jarvis's real thinking, fed by bus events in
+`ui/orb/bus_bridge.py` and condensed by `jarvis/ui/pets/status_line.py`:
+
+| Source | Title | Detail |
+|---|---|---|
+| `ReasoningSummaryUpdated` — the thinking model behind GPT-Live (`jarvis/live/session.py`, streamed as cumulative snapshots a few times per second) | the newest section heading of the summary (`**Heading**`) | the last complete sentence of that section |
+| `ActionProposed` / `ToolCallStarted` — a tool step | the current thought's heading, else the running agent task, else "Working" | the step's rationale, else the humanized tool name |
+| `ActionExecuted` while a card is up | unchanged | "Step done" / "Step failed" |
+| `JarvisAgentTaskStarted` / `JarvisAgentTaskCompleted` / `JarvisAgentBackgroundCompleted` — an agent task | the task (the user's request, condensed) | "Working …", then "Done" / "Failed" |
+| `SystemStateChanged(THINKING)` with no thought after 1.5 s | "Thinking …" | empty |
+
+When it goes away (a 1.5 s linger, then the surface fades it out):
+
+- Jarvis starts talking out loud (`AudioOutFirst`), the turn ends (`IDLE`,
+ `ERROR`, `PAUSED`), a fresh turn starts listening, or the session ends;
+- a thought that arrives while Jarvis is already talking (the thinking model
+ working on behind the voice model) clears itself after four quiet seconds;
+- a finished agent task shows Done / Failed for three seconds.
+
+A running agent task keeps its card across all of these until it completes;
+a completion that never arrives stops holding the card after 30 minutes.
+Spoken lines (acks, progress readbacks), the transcript and the reply never
+reach the card. Updates are rate-limited (0.3 s) and deduplicated, and the
+newest held-back update is always shown once the limit allows. The fixed
+labels follow the interface language (`[ui] language`: en / de / es). Title
+and detail are clipped to 60 and 110 characters; markdown, code, URLs, file
+paths and JSON dumps are stripped.
+
## States
The vocabulary lives in `jarvis/ui/pets/states.py` (a module with no imports)
@@ -162,9 +189,11 @@ name.
| Method | Meaning |
|---|---|
| `set_pet(pet_id)` | Swap the figure live; `"none"` shows the strip only |
-| `set_pet_look(scale, bubble)` | Apply size and bubble on/off live |
+| `set_pet_look(scale, bubble)` | Apply size and card on/off live |
| `set_pet_outcome(kind)` | Play the one-shot `success` or `error` |
-| `show_status(header, line)` | Update the status bubble (already condensed) |
+| `show_status(title, detail="")` | Show or update the thinking card (already condensed) |
+| `clear_status(linger_s=1.5)` | Take the card down after `linger_s` |
+| `wants_status_lines` (attribute) | True only for the pet: the bridge feeds the card to nothing else |
| `set_muted(muted)` | Mirror the microphone mute on the strip |
| `set_speaker_muted(muted)` | Mirror the speaker mute on the strip |
| `set_visible(visible)` | Hide or show the whole pet (shortcut, settings) |
@@ -191,7 +220,7 @@ Control-strip actions reported back through callbacks: `compose`, `mic_mute`,
| `[ui] orb_style` | `jarvis_bar` | `pet` selects the pet |
| `[ui] pet_id` | `gigi` | Active pet (built-in id, `u…` id or `none`) |
| `[ui] pet_scale` | `1.0` | Size multiplier, 0.5–2.0 |
-| `[ui] pet_bubble` | `true` | Show the status bubble |
+| `[ui] pet_bubble` | `true` | Show the thinking card |
| `[trigger] hotkey_pet_toggle` | `alt+win+p` | Hide / show the pet; empty disables it |
### REST (`jarvis/ui/web/pets_routes.py`)
diff --git a/jarvis/live/session.py b/jarvis/live/session.py
index 09e878f38c..56d8ab51e1 100644
--- a/jarvis/live/session.py
+++ b/jarvis/live/session.py
@@ -22,6 +22,21 @@ from jarvis.realtime.audio import StreamingPcm16Resampler
log = logging.getLogger(__name__)
+#: Smallest gap between two live snapshots of one streaming reasoning summary.
+#: The summary arrives token by token; the bus sees a few snapshots a second.
+REASONING_SNAPSHOT_INTERVAL_S = 0.3
+
+#: Reasoning items whose summary may be streaming at once (a bound, not a goal).
+_REASONING_ITEMS_MAX = 16
+
+
+def _summary_index(event: dict) -> int:
+ """The summary part a reasoning-summary event belongs to (0 when absent)."""
+ try:
+ return max(0, int(event.get("summary_index") or 0))
+ except (TypeError, ValueError):
+ return 0
+
class LiveVoiceSession:
"""Browser route facade, with no dependency on the legacy turn planner."""
@@ -74,6 +89,11 @@ class LiveVoiceSession:
self._last_role = ""
self._last_end = {"user": -1, "assistant": -1}
self._delegation_responses: dict[str, str] = {}
+ # The thinking model's reasoning summary while it streams: per
+ # reasoning item, its summary parts by index, and when the item last
+ # reached the bus (see ``_on_reasoning_delta``).
+ self._reasoning_parts: dict[str, dict[int, str]] = {}
+ self._reasoning_published_at: dict[str, float] = {}
self._voice_seconds = 0.0
self.playback_active = False
self._speaking = False
@@ -719,6 +739,53 @@ class LiveVoiceSession:
}
)
+ def _reasoning_text(self, item_id: str) -> str:
+ """The streamed summary of one reasoning item so far, parts in order."""
+ parts = self._reasoning_parts.get(item_id, {})
+ return "\n\n".join(parts[index] for index in sorted(parts) if parts[index])
+
+ async def _publish_reasoning(self, item_id: str, text: str, *, done: bool) -> None:
+ """Publish one cumulative ``ReasoningSummaryUpdated`` snapshot."""
+ if self._bus is None or not text.strip():
+ return
+ from jarvis.core.events import ReasoningSummaryUpdated
+ from jarvis.core.redact import safe_preview
+
+ self._reasoning_published_at[item_id] = time.monotonic()
+ await self._bus.publish(ReasoningSummaryUpdated(
+ source_layer="live.delegation", trace_id=self._indicator_trace_id,
+ response_id=item_id, text=safe_preview(text, max_chars=4000), done=done,
+ ))
+
+ async def _on_reasoning_delta(self, event: dict, delegation: str) -> None:
+ """Accumulate a streamed summary token; publish a snapshot now and then.
+
+ The thinking model's summary arrives token by token. Every mirror — the
+ app's thinking steps, the desktop pet's card — wants to follow it live,
+ but one bus event per token is exactly the hot-path load AP-9 forbids.
+ So the tokens collect per reasoning item and the bus sees the
+ cumulative text at most every ``REASONING_SNAPSHOT_INTERVAL_S``; the
+ ``.done`` events that follow always publish the final text.
+ """
+ item_id = str(event.get("item_id") or delegation)
+ delta = str(event.get("delta") or "")
+ if not delta:
+ return
+ streaming = self._reasoning_parts
+ if item_id not in streaming and len(streaming) >= _REASONING_ITEMS_MAX:
+ # Items are dropped when they finish; a stream that never finished
+ # must not grow this forever. The oldest one goes.
+ stale = next(iter(self._reasoning_parts))
+ self._reasoning_parts.pop(stale, None)
+ self._reasoning_published_at.pop(stale, None)
+ parts = self._reasoning_parts.setdefault(item_id, {})
+ index = _summary_index(event)
+ parts[index] = parts.get(index, "") + delta
+ last = self._reasoning_published_at.get(item_id)
+ if last is not None and time.monotonic() - last < REASONING_SNAPSHOT_INTERVAL_S:
+ return
+ await self._publish_reasoning(item_id, self._reasoning_text(item_id), done=False)
+
async def _response(self, envelope: dict) -> None:
assert self._ledger is not None and self._tools is not None
event = envelope.get("event", {})
@@ -744,32 +811,29 @@ class LiveVoiceSession:
provider=self.active_provider, model=self._tools.backend_model,
))
await self._note_thinking()
+ elif kind == "response.reasoning_summary_text.delta":
+ await self._on_reasoning_delta(event, delegation)
elif kind == "response.reasoning_summary_text.done":
- if self._bus is not None and event.get("text"):
- from jarvis.core.events import ReasoningSummaryUpdated
- from jarvis.core.redact import safe_preview
-
- await self._bus.publish(ReasoningSummaryUpdated(
- source_layer="live.delegation", trace_id=self._indicator_trace_id,
- response_id=str(event.get("item_id") or event.get("response_id") or delegation),
- text=safe_preview(event["text"], max_chars=4000), done=True,
- ))
+ if event.get("text"):
+ item_id = str(event.get("item_id") or event.get("response_id") or delegation)
+ parts = self._reasoning_parts.setdefault(item_id, {})
+ parts[_summary_index(event)] = str(event["text"])
+ # The whole summary so far, not only this part: a snapshot
+ # replaces the previous one, so a part alone would erase the
+ # parts before it from every mirror.
+ await self._publish_reasoning(item_id, self._reasoning_text(item_id), done=True)
elif kind == "response.output_item.done":
item = event.get("item", {})
if item.get("type") == "reasoning":
+ item_id = str(item.get("id") or delegation)
+ self._reasoning_parts.pop(item_id, None)
+ self._reasoning_published_at.pop(item_id, None)
summary = "\n\n".join(
str(part.get("text", "")) for part in item.get("summary", [])
if part.get("type") == "summary_text"
)
- if summary and self._bus is not None:
- from jarvis.core.events import ReasoningSummaryUpdated
- from jarvis.core.redact import safe_preview
-
- await self._bus.publish(ReasoningSummaryUpdated(
- source_layer="live.delegation", trace_id=self._indicator_trace_id,
- response_id=str(item.get("id") or delegation),
- text=safe_preview(summary, max_chars=4000), done=True,
- ))
+ if summary:
+ await self._publish_reasoning(item_id, summary, done=True)
if item.get("type") == "function_call":
rid = str(
event.get("response_id")
diff --git a/jarvis/sessions/recorder.py b/jarvis/sessions/recorder.py
index a1c5ccfb27..4d40ff53b2 100644
--- a/jarvis/sessions/recorder.py
+++ b/jarvis/sessions/recorder.py
@@ -1010,6 +1010,10 @@ class SessionRecorder:
return
if kind not in _RAW_EVENT_KINDS:
return
+ if kind == "ReasoningSummaryUpdated" and getattr(event, "done", True) is False:
+ # A streaming snapshot is superseded within a fraction of a second;
+ # the session keeps the finished summary, not every partial copy.
+ return
turn_id = (
self._state.current_turn.turn_id
if self._state.current_turn is not None
diff --git a/jarvis/state/turn_trace.py b/jarvis/state/turn_trace.py
index 9d7c983076..c4295d7eed 100644
--- a/jarvis/state/turn_trace.py
+++ b/jarvis/state/turn_trace.py
@@ -86,6 +86,8 @@ _ARGS_MAX_KEYS = 8
#: How many events the ring keeps. A turn rarely exceeds a few dozen; the
#: ring spans the last several turns so a slow reply still finds its slice.
DEFAULT_RING_SIZE = 600
+#: How far back a streamed reasoning snapshot looks for the one it replaces.
+_SNAPSHOT_LOOKBACK = 64
def _scalar(value: Any, *, max_chars: int) -> Any:
@@ -164,8 +166,32 @@ class TurnTraceCollector:
payload=trace_payload_for(name, event),
)
with self._lock:
+ if name == "ReasoningSummaryUpdated":
+ self._drop_open_snapshot(item)
self._ring.append(item)
+ def _drop_open_snapshot(self, item: TraceEvent) -> None:
+ """Remove the still-streaming snapshot this one supersedes (lock held).
+
+ A streamed reasoning summary arrives as cumulative snapshots of one
+ ``response_id``; each replaces the last, so the ring keeps one entry
+ per summary instead of dozens of growing copies that would push the
+ turn's other steps out of the bounded ring.
+ """
+ response_id = item.payload.get("response_id")
+ if response_id is None:
+ return
+ oldest = max(0, len(self._ring) - _SNAPSHOT_LOOKBACK)
+ for index in range(len(self._ring) - 1, oldest - 1, -1):
+ previous = self._ring[index]
+ if (
+ previous.name == item.name
+ and previous.payload.get("response_id") == response_id
+ and previous.payload.get("done") is False
+ ):
+ del self._ring[index]
+ return
+
def slice(self, since_ms: int, until_ms: int | None = None) -> list[dict[str, Any]]:
"""Events with ``since_ms <= ts_ms <= until_ms``, oldest first."""
with self._lock:
diff --git a/jarvis/ui/pets/status_line.py b/jarvis/ui/pets/status_line.py
index 1a4bbb10f7..3ef75af351 100644
--- a/jarvis/ui/pets/status_line.py
+++ b/jarvis/ui/pets/status_line.py
@@ -1,11 +1,12 @@
-"""Condense what Jarvis is doing into one short line for the pet's status bubble.
-
-The bubble sits under a small floating figure, so it shows a *gist*: the first
-sentence of a reply, the current tool, the live transcript. Everything a
-human would skip when glancing over is stripped: markdown syntax, code
-blocks, URLs, file paths and JSON / dict dumps. :class:`StatusFeed` then
-drops repeats and rate-limits updates so a fast token stream does not make
-the bubble flicker.
+"""Condense what Jarvis is thinking into the pet's two-line status card.
+
+The card sits under a small floating figure, so it shows a *gist*: a bold
+title (what Jarvis is working on) and one muted detail line (the current
+thought or step). Everything a human would skip when glancing over is
+stripped: markdown syntax, code blocks, URLs, file paths and JSON / dict
+dumps. :func:`parse_reasoning_summary` turns a thinking model's streamed
+reasoning summary into that pair, and :class:`StatusFeed` drops repeats and
+rate-limits updates so a fast stream does not make the card flicker.
"""
from __future__ import annotations
@@ -156,14 +157,87 @@ def condense(text: str, *, max_chars: int = 90) -> str:
return _clip(gist, max_chars)
+#: Longest card title and detail line, in characters.
+TITLE_MAX_CHARS = 60
+DETAIL_MAX_CHARS = 110
+
+#: A reasoning section heading: a line that is bold as a whole (the form the
+#: OpenAI reasoning summaries use) or a markdown ``#`` heading.
+_SECTION_HEADING_RE = re.compile(
+ r"^[ \t]*(?:\*\*(?P<bold>[^*\n]+?)\*\*|__(?P<under>[^_\n]+?)__|#{1,6}[ \t]+(?P<hash>[^\n]+?))"
+ r"[ \t]*:?[ \t]*$",
+ re.MULTILINE,
+)
+
+
+def _last_sentence(body: str) -> str:
+ """The last sentence of ``body``, preferring a complete one.
+
+ A summary streams word by word, so its end is usually a fragment; until
+ the fragment ends in punctuation the previous complete sentence stays.
+ A body with no complete sentence yet gives its fragment.
+ """
+ flat = _WS_RE.sub(" ", body).strip()
+ if not flat:
+ return ""
+ pieces = [piece for piece in _SENTENCE_END_RE.split(flat) if piece.strip()]
+ if not pieces:
+ return ""
+ last = pieces[-1].rstrip()
+ if len(pieces) > 1 and last[-1:] not in _SENTENCE_MARKS:
+ return pieces[-2]
+ return last
+
+
+def parse_reasoning_summary(text: str) -> tuple[str, str]:
+ """Split a reasoning summary into the card's ``(title, detail)``.
+
+ Thinking models summarize in sections — ``**Heading**`` then a short
+ paragraph — and the newest section is what the model is doing now. The
+ title is that section's heading (at most :data:`TITLE_MAX_CHARS`), the
+ detail the last sentence of its body (at most :data:`DETAIL_MAX_CHARS`).
+ Text without a heading gives an empty title (the caller supplies a
+ generic one); a heading whose body has not streamed in yet gives an
+ empty detail.
+ """
+ if not isinstance(text, str) or not text.strip():
+ return "", ""
+ headings = list(_SECTION_HEADING_RE.finditer(text))
+ if headings:
+ last = headings[-1]
+ raw_title = last.group("bold") or last.group("under") or last.group("hash") or ""
+ title = _clip(_strip_noise(raw_title), TITLE_MAX_CHARS)
+ body = text[last.end():]
+ else:
+ title = ""
+ body = text
+ # Only the end of the body matters for its last sentence.
+ body = _strip_blocks(body[-MAX_INPUT_CHARS:])
+ lines = [
+ _strip_noise(_clean_line(raw))
+ for raw in body.splitlines()
+ if not (_RULE_RE.match(raw) or _TABLE_RULE_RE.match(raw))
+ ]
+ sentence = _last_sentence(" ".join(line for line in lines if line))
+ detail = _clip(sentence, DETAIL_MAX_CHARS) if sentence else ""
+ return title, detail
+
+
class StatusFeed:
"""Dedupe and rate-limit the lines the status bubble shows."""
def __init__(
- self, clock: Callable[[], float] = time.monotonic, min_interval_s: float = 0.3
+ self,
+ clock: Callable[[], float] = time.monotonic,
+ min_interval_s: float = 0.3,
+ *,
+ title_chars: int = 40,
+ line_chars: int = 90,
) -> None:
self._clock = clock
self._min_interval = max(0.0, float(min_interval_s))
+ self._title_chars = max(1, int(title_chars))
+ self._line_chars = max(1, int(line_chars))
self._last: tuple[str, str] | None = None
self._last_at: float | None = None
self._pending: tuple[str, str] | None = None
@@ -176,7 +250,10 @@ class StatusFeed:
last shown one. A throttled pair is kept; :meth:`flush` returns it
once the interval has passed.
"""
- pair = (condense(header, max_chars=40), condense(line))
+ pair = (
+ condense(header, max_chars=self._title_chars),
+ condense(line, max_chars=self._line_chars),
+ )
if not pair[0] and not pair[1]:
return None
if pair == self._last:
diff --git a/tests/unit/live/__init__.py b/tests/unit/live/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/unit/live/test_reasoning_stream.py b/tests/unit/live/test_reasoning_stream.py
new file mode 100644
index 0000000000..daa7f32154
--- /dev/null
+++ b/tests/unit/live/test_reasoning_stream.py
@@ -0,0 +1,209 @@
+"""GPT-Live streams the thinking model's reasoning summary live (jarvis/live/session.py).
+
+The Responses API sends a reasoning summary token by token. Every mirror —
+the app's thinking steps, the desktop pet's card — follows it as cumulative
+``ReasoningSummaryUpdated`` snapshots, coalesced so the bus sees a few per
+second (AP-9), and closed by the final ``done`` text. The trace ring and the
+session recorder keep the finished summary, not every partial copy.
+"""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+
+from jarvis.core.events import ReasoningSummaryUpdated, VoiceSessionStarted
+from jarvis.live import session as live_session
+from jarvis.live.session import LiveVoiceSession
+from jarvis.sessions.recorder import SessionRecorder
+from jarvis.state.turn_trace import TurnTraceCollector
+
+
+class _Bus:
+ def __init__(self) -> None:
+ self.events: list[object] = []
+
+ async def publish(self, event: object) -> None:
+ self.events.append(event)
+
+ def reasoning(self) -> list[ReasoningSummaryUpdated]:
+ return [e for e in self.events if isinstance(e, ReasoningSummaryUpdated)]
+
+
+class _Clock:
+ def __init__(self) -> None:
+ self.now = 100.0
+
+ def __call__(self) -> float:
+ return self.now
+
+
+def _session(bus: _Bus) -> LiveVoiceSession:
+ async def send(_event: object) -> None:
+ return None
+
+ session = LiveVoiceSession(
+ session_id="s",
+ send_binary=send,
+ send_json=send,
+ providers=[SimpleNamespace(name="test")],
+ config=SimpleNamespace(brain=SimpleNamespace(reply_language="en")),
+ bus=bus,
+ )
+ # Reasoning events touch neither the ledger nor the tools.
+ session._ledger = SimpleNamespace() # noqa: SLF001
+ session._tools = SimpleNamespace() # noqa: SLF001
+ return session
+
+
+async def _send(session: LiveVoiceSession, payload: dict) -> None:
+ await session._event( # noqa: SLF001
+ {"type": "response.event", "delegation_id": "d", "event": payload}
+ )
+
+
+def _delta(text: str, *, index: int = 0) -> dict:
+ return {
+ "type": "response.reasoning_summary_text.delta",
+ "item_id": "rs_1",
+ "summary_index": index,
+ "delta": text,
+ }
+
+
+def clock(monkeypatch: pytest.MonkeyPatch) -> _Clock:
+ fake = _Clock()
+ monkeypatch.setattr(live_session.time, "monotonic", fake)
+ return fake
+
+
+async def test_deltas_are_published_as_coalesced_cumulative_snapshots(clock: _Clock) -> None:
+ bus = _Bus()
+ session = _session(bus)
+ await _send(session, _delta("**Planning**\n\n"))
+ await _send(session, _delta("I need ")) # within the interval: held
+ await _send(session, _delta("the train times."))
+ assert [e.text for e in bus.reasoning()] == ["**Planning**\n\n"]
+
+ clock.now += live_session.REASONING_SNAPSHOT_INTERVAL_S + 0.01
+ await _send(session, _delta(" Then"))
+ snapshots = bus.reasoning()
+ assert snapshots[-1].text == "**Planning**\n\nI need the train times. Then"
+ assert snapshots[-1].done is False
+ assert snapshots[-1].response_id == "rs_1"
+ assert snapshots[-1].source_layer == "live.delegation"
+
+
+async def test_a_part_done_publishes_the_whole_summary_so_far(clock: _Clock) -> None:
+ bus = _Bus()
+ session = _session(bus)
+ await _send(session, _delta("**Reading**\n\nThe user wants trains.", index=0))
+ await _send(
+ session,
+ {
+ "type": "response.reasoning_summary_text.done",
+ "item_id": "rs_1",
+ "summary_index": 0,
+ "text": "**Reading**\n\nThe user wants trains.",
+ },
+ )
+ clock.now += 1.0
+ await _send(session, _delta("**Searching**\n\nI query", index=1))
+ await _send(
+ session,
+ {
+ "type": "response.reasoning_summary_text.done",
+ "item_id": "rs_1",
+ "summary_index": 1,
+ "text": "**Searching**\n\nI query the timetable.",
+ },
+ )
+ final = bus.reasoning()[-1]
+ assert final.done is True
+ assert final.text == (
+ "**Reading**\n\nThe user wants trains.\n\n**Searching**\n\nI query the timetable."
+ )
+
+
+async def test_the_finished_item_releases_its_stream_state(clock: _Clock) -> None:
+ bus = _Bus()
+ session = _session(bus)
+ await _send(session, _delta("**Plan**\n\nStep one."))
+ await _send(
+ session,
+ {
+ "type": "response.output_item.done",
+ "item": {
+ "type": "reasoning",
+ "id": "rs_1",
+ "summary": [{"type": "summary_text", "text": "**Plan**\n\nStep one."}],
+ },
+ },
+ )
+ assert session._reasoning_parts == {} # noqa: SLF001
+ assert bus.reasoning()[-1].done is True
+
+
+async def test_unfinished_streams_are_bounded(clock: _Clock) -> None:
+ bus = _Bus()
+ session = _session(bus)
+ for number in range(live_session._REASONING_ITEMS_MAX + 5): # noqa: SLF001
+ await _send(
+ session,
+ {
+ "type": "response.reasoning_summary_text.delta",
+ "item_id": f"rs_{number}",
+ "delta": "thinking",
+ },
+ )
+ assert len(session._reasoning_parts) == live_session._REASONING_ITEMS_MAX # noqa: SLF001
+
+
+def test_the_trace_ring_keeps_one_entry_per_streaming_summary() -> None:
+ collector = TurnTraceCollector()
+ for text in ("**Plan**", "**Plan**\n\nOne.", "**Plan**\n\nOne. Two."):
+ collector.record(
+ "ReasoningSummaryUpdated",
+ ReasoningSummaryUpdated(response_id="rs_1", text=text, done=False),
+ )
+ collector.record(
+ "ReasoningSummaryUpdated",
+ ReasoningSummaryUpdated(response_id="rs_1", text="**Plan**\n\nOne. Two. Three.", done=True),
+ )
+ collector.record(
+ "ReasoningSummaryUpdated",
+ ReasoningSummaryUpdated(response_id="rs_2", text="Other.", done=False),
+ )
+ events = collector.slice(0)
+ texts = [e["payload"]["text"] for e in events]
+ assert texts == ["**Plan**\n\nOne. Two. Three.", "Other."]
+
+
+class _Store:
+ def __init__(self) -> None:
+ self.kinds: list[tuple[str, dict]] = []
+
+ def upsert_session(self, **_kwargs) -> None:
+ return None
+
+ def append_event(self, **kwargs) -> int:
+ self.kinds.append((kwargs["kind"], kwargs["payload"]))
+ return len(self.kinds)
+
+
+async def test_the_recorder_keeps_only_the_finished_summary() -> None:
+ store = _Store()
+ recorder = SessionRecorder(store) # type: ignore[arg-type]
+ await recorder._on_event( # noqa: SLF001
+ VoiceSessionStarted(session_id="s1", wake_keyword="hey_jarvis", language="en")
+ )
+ await recorder._on_event( # noqa: SLF001
+ ReasoningSummaryUpdated(response_id="rs_1", text="**Plan**", done=False)
+ )
+ await recorder._on_event( # noqa: SLF001
+ ReasoningSummaryUpdated(response_id="rs_1", text="**Plan**\n\nDone.", done=True)
+ )
+ reasoning = [kind for kind, _payload in store.kinds if kind == "ReasoningSummaryUpdated"]
+ assert reasoning == ["ReasoningSummaryUpdated"]
diff --git a/tests/unit/ui/pets/test_status_line.py b/tests/unit/ui/pets/test_status_line.py
index 1be4f2d370..430f0bb162 100644
--- a/tests/unit/ui/pets/test_status_line.py
+++ b/tests/unit/ui/pets/test_status_line.py
@@ -4,7 +4,15 @@ from __future__ import annotations
import pytest
-from jarvis.ui.pets.status_line import ELLIPSIS, MAX_INPUT_CHARS, StatusFeed, condense
+from jarvis.ui.pets.status_line import (
+ DETAIL_MAX_CHARS,
+ ELLIPSIS,
+ MAX_INPUT_CHARS,
+ TITLE_MAX_CHARS,
+ StatusFeed,
+ condense,
+ parse_reasoning_summary,
+)
class FakeClock:
@@ -115,3 +123,78 @@ def test_only_the_head_of_a_long_text_is_condensed() -> None:
assert len(line) <= 90
# A sentence that starts after the cap is not part of the gist.
assert "Tail" not in condense("x" * (MAX_INPUT_CHARS + 10) + " Tail sentence.")
+
+
+# ---------------------------------------------------------------------------
+# reasoning summaries -> (title, detail) for the thinking card
+# ---------------------------------------------------------------------------
+
+
+ ("text", "expected"),
+ [
+ # The OpenAI shape: a bold heading line, then a short paragraph.
+ (
+ "**Checking the calendar**\n\nI look at today first. Then the week.",
+ ("Checking the calendar", "Then the week."),
+ ),
+ # Several sections: the NEWEST is what the model is doing now.
+ (
+ "**Reading the request**\n\nThe user wants trains.\n\n"
+ "**Searching connections**\n\nI query the timetable for Berlin.",
+ ("Searching connections", "I query the timetable for Berlin."),
+ ),
+ # Still streaming: the fragment waits until its sentence is complete.
+ (
+ "**Planning**\n\nI need the train times first. Then I compare",
+ ("Planning", "I need the train times first."),
+ ),
+ # A heading whose body has not arrived yet.
+ ("**Planning the answer**\n\n", ("Planning the answer", "")),
+ # Markdown # headings count too; a trailing colon is dropped.
+ ("## Next step:\nOpen the settings file.", ("Next step", "Open the settings file.")),
+ # No heading: no title, the last sentence is the detail.
+ ("I compare both offers. The second is cheaper.", ("", "The second is cheaper.")),
+ # Only a fragment so far: the fragment is better than nothing.
+ ("I am looking at", ("", "I am looking at")),
+ # Noise is stripped from the detail.
+ (
+ "**Editing**\n\nI open `config.toml` in C:\\Users\\me\\app\\config.toml now.",
+ ("Editing", "I open config.toml in config.toml now."),
+ ),
+ ("", ("", "")),
+ (" \n\n ", ("", "")),
+ ],
+)
+def test_parse_reasoning_summary(text: str, expected: tuple[str, str]) -> None:
+ assert parse_reasoning_summary(text) == expected
+
+
+def test_reasoning_title_and_detail_are_clipped() -> None:
+ title, detail = parse_reasoning_summary(
+ "**" + "Heading word " * 20 + "**\n\n" + "A long detail sentence " * 20 + "."
+ )
+ assert len(title) <= TITLE_MAX_CHARS
+ assert title.endswith(ELLIPSIS)
+ assert len(detail) <= DETAIL_MAX_CHARS
+ assert detail.endswith(ELLIPSIS)
+
+
+def test_a_huge_summary_is_parsed_from_its_end() -> None:
+ text = "**Old**\n\n" + "Filler sentence. " * 2_000 + "\n\n**New**\n\nThe last thought."
+ assert parse_reasoning_summary(text) == ("New", "The last thought.")
+
+
+def test_a_non_string_summary_is_empty() -> None:
+ assert parse_reasoning_summary(None) == ("", "") # type: ignore[arg-type]
+
+
+def test_the_feed_honours_its_card_lengths() -> None:
+ feed = StatusFeed(FakeClock(), title_chars=60, line_chars=110)
+ title = "Working on the quarterly numbers for the whole finance team"
+ detail = "Comparing the second quarter against the first one before writing it up for you."
+ assert feed.offer(title, detail) == (title, detail)
+ narrow = StatusFeed(FakeClock())
+ shown = narrow.offer(title, detail)
+ assert shown is not None
+ assert len(shown[0]) <= 40
diff --git a/tests/unit/ui/test_orb_bus_bridge_pet.py b/tests/unit/ui/test_orb_bus_bridge_pet.py
index 6ff608a4b2..85e8c40886 100644
--- a/tests/unit/ui/test_orb_bus_bridge_pet.py
+++ b/tests/unit/ui/test_orb_bus_bridge_pet.py
@@ -3,9 +3,9 @@
The bridge drives every overlay style; the pet adds optional surface methods
the bridge reaches through ``getattr``. These tests use a real ``EventBus`` and
a hand-written pet surface and pin: the speaker-mute mirror, the shortcut, the
-one-shot outcomes, the rate-limited status lines (pet only), the pen control,
-the per-surface re-wiring on a live swap, and that the pet is never hidden
-when Jarvis goes idle.
+one-shot outcomes, the thinking card (pet only — real thinking, never the
+transcript or the reply), the pen control, the per-surface re-wiring on a
+live swap, and that the pet is never hidden when Jarvis goes idle.
"""
from __future__ import annotations
@@ -23,13 +23,19 @@ from jarvis.core.events import (
ActionProposed,
AnnouncementRequested,
AssistantTextDelta,
+ AudioOutFirst,
ComposeRequested,
ErrorOccurred,
JarvisAgentAnnouncement,
JarvisAgentBackgroundCompleted,
+ JarvisAgentTaskCompleted,
+ JarvisAgentTaskStarted,
PetVisibilityToggleRequested,
+ ReasoningSummaryUpdated,
+ ResponseGenerated,
SpeechSpoken,
SystemStateChanged,
+ ToolCallStarted,
TranscriptionUpdate,
UiLanguageChanged,
VoiceBootStatus,
@@ -113,8 +119,11 @@ class _Surface:
def set_pet_outcome(self, kind: str) -> None:
self.calls.append(("outcome", kind))
- def show_status(self, header: str, line: str) -> None:
- self.calls.append(("status", header, line))
+ def show_status(self, title: str, detail: str = "") -> None:
+ self.calls.append(("status", title, detail))
+
+ def clear_status(self, linger_s: float = 1.5) -> None:
+ self.calls.append(("clear", linger_s))
def toggle_visible(self) -> None:
self.calls.append(("toggle_visible",))
@@ -154,12 +163,6 @@ def _no_live_pipeline(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(runtime_refs, "_SPEECH_PIPELINE", [])
-def fast_status(monkeypatch: pytest.MonkeyPatch) -> None:
- """Shrink the status rate limit so the flush path runs in milliseconds."""
- monkeypatch.setattr(bus_bridge, "PET_STATUS_MIN_INTERVAL_S", 0.02)
-
-
def _bridge(surface: _Surface, **kwargs) -> tuple[OrbBusBridge, EventBus]:
bus = EventBus()
bridge = OrbBusBridge(bus=bus, orb=surface, **kwargs) # type: ignore[arg-type]
@@ -308,111 +311,245 @@ async def test_ordinary_events_play_no_outcome(event) -> None:
# ---------------------------------------------------------------------------
-# status lines
+# the thinking card: only real thinking, title + detail
# ---------------------------------------------------------------------------
-async def test_status_lines_reach_only_a_surface_that_wants_them() -> None:
- bar = _Surface() # has show_status, but does not ask for lines
+def fast_card(monkeypatch: pytest.MonkeyPatch) -> None:
+ """Shrink every card timer so the timed paths run in milliseconds."""
+ monkeypatch.setattr(bus_bridge, "PET_STATUS_MIN_INTERVAL_S", 0.02)
+ monkeypatch.setattr(bus_bridge, "PET_CARD_THINKING_FALLBACK_S", 0.03)
+ monkeypatch.setattr(bus_bridge, "PET_CARD_QUIET_CLEAR_S", 0.03)
+ monkeypatch.setattr(bus_bridge, "PET_CARD_TASK_DONE_S", 0.03)
+
+
+_PLAN = "**Planning the trip**\n\nI need the train times first. Then I compare"
+
+
+async def test_the_card_reaches_only_a_surface_that_wants_it(fast_card) -> None:
+ bar = _Surface() # has show_status, but does not ask for the card
_bridge_, bus = _bridge(bar)
await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text=_PLAN))
await bus.publish(ActionProposed(tool_name="web_search", rationale="Checking the news"))
- await bus.publish(AssistantTextDelta(channel="voice", text="Here it is.", done=True))
+ await bus.publish(JarvisAgentTaskStarted(utterance="Build a site"))
+ await asyncio.sleep(0.06)
assert bar.of("status") == []
+ assert bar.of("clear") == []
+
+
+async def test_thinking_shows_no_card_until_a_thought_arrives(fast_card) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ assert pet.of("status") == []
+
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text=_PLAN))
+ # The section heading is the title; the last COMPLETE sentence the detail.
+ assert pet.of("status") == [("status", "Planning the trip", "I need the train times first.")]
+
+
+async def test_a_silent_thinking_phase_gets_the_bare_title(fast_card) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await asyncio.sleep(0.06)
+ assert pet.of("status") == [("status", "Thinking …", "")]
-async def test_thinking_shows_the_header_then_the_reason(fast_status) -> None:
+async def test_a_quick_turn_shows_no_card_at_all(fast_card) -> None:
pet = _Pet()
_bridge_, bus = _bridge(pet)
await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
- assert pet.of("status")[-1] == ("status", "Thinking …", "")
+ await bus.publish(SystemStateChanged(previous="THINKING", new_state="SPEAKING"))
+ await asyncio.sleep(0.06)
+ assert pet.of("status") == []
+
+async def test_a_tool_step_runs_under_the_current_thought(fast_card) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text=_PLAN))
await asyncio.sleep(0.03)
await bus.publish(
- ActionProposed(tool_name="web_search", rationale="Looking up the weather in Berlin")
+ ActionProposed(tool_name="web_search", rationale="Looking up the trains to Berlin")
+ )
+ assert pet.of("status")[-1] == (
+ "status",
+ "Planning the trip",
+ "Looking up the trains to Berlin",
)
- assert pet.of("status")[-1] == ("status", "Thinking …", "Looking up the weather in Berlin")
-async def test_a_tool_without_a_reason_shows_its_name(fast_status) -> None:
+async def test_a_tool_without_a_reason_shows_its_name(fast_card) -> None:
pet = _Pet()
_bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
await bus.publish(ActionProposed(tool_name="mcp__github__create_issue"))
- assert pet.of("status")[-1] == ("status", "Thinking …", "Create issue")
+ assert pet.of("status")[-1] == ("status", "Working", "Create issue")
+ await asyncio.sleep(0.03)
+ await bus.publish(ToolCallStarted(tool_name="read_file"))
+ assert pet.of("status")[-1] == ("status", "Working", "Read file")
+
+
+async def test_a_tool_result_is_the_next_step(fast_card) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet, language="de")
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ActionProposed(tool_name="run_command", rationale="Running the tests"))
+ await asyncio.sleep(0.03)
+ await bus.publish(ActionExecuted(tool_name="run_command", success=True))
+ assert pet.of("status")[-1] == ("status", "Arbeitet", "Befehl ausgeführt") # i18n-allow
-async def test_progress_announcements_are_thinking_lines(fast_status) -> None:
+async def test_a_tool_result_without_a_card_puts_none_up(fast_card) -> None:
pet = _Pet()
_bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ActionExecuted(tool_name="run_command", success=True))
+ assert pet.of("status") == []
+
+
+async def test_transcripts_replies_and_spoken_lines_never_reach_the_card(fast_card) -> None:
+ pet = _Pet()
+ bridge, bus = _bridge(pet)
+ await bus.publish(VoiceSessionStarted(session_id="s1"))
+ bridge._last_state = "LISTENING" # noqa: SLF001
+ await bus.publish(TranscriptionUpdate(text="what is the weather", is_final=True))
await bus.publish(AnnouncementRequested(text="Step 2 of 5 done.", kind="progress"))
- await asyncio.sleep(0.03)
- await bus.publish(AnnouncementRequested(text="All finished.", kind="completion"))
- await asyncio.sleep(0.03)
- # A spawn announcement's action is a bare clause fragment in the spawn
- # tool's language — never a status line on its own.
+ await bus.publish(AnnouncementRequested(text="One moment.", kind="preamble"))
+ await bus.publish(AssistantTextDelta(channel="voice", text="It is sunny.", done=True))
+ await bus.publish(ResponseGenerated(text="It is sunny."))
await bus.publish(
JarvisAgentAnnouncement(action="eine Flask-App baut", target="auf Port 8000") # i18n-allow
)
- assert [c[2] for c in pet.of("status")] == ["Step 2 of 5 done."]
+ await asyncio.sleep(0.06)
+ assert pet.of("status") == []
+ assert pet.of("transcript") == []
-async def test_a_streamed_reply_shows_its_latest_complete_sentence(fast_status) -> None:
+async def test_audible_speech_takes_the_card_down(fast_card) -> None:
pet = _Pet()
_bridge_, bus = _bridge(pet)
- await bus.publish(AssistantTextDelta(channel="voice", text="It is sunny. Tomorrow it"))
- assert pet.of("status")[-1] == ("status", "Answer", "It is sunny.")
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text=_PLAN, done=True))
+ await bus.publish(SystemStateChanged(previous="THINKING", new_state="SPEAKING"))
+ assert pet.of("clear") == [] # synthesis lead-in: still thinking for the user
+ await bus.publish(AudioOutFirst())
+ assert pet.of("clear") == [("clear", bus_bridge.PET_CARD_LINGER_S)]
- await asyncio.sleep(0.03)
- await bus.publish(
- AssistantTextDelta(channel="voice", text="It is sunny. Tomorrow it rains.", done=True)
- )
- assert pet.of("status")[-1] == ("status", "Answer", "Tomorrow it rains.")
+
[email protected]("next_state", ["IDLE", "LISTENING", "ERROR"])
+async def test_the_end_of_thinking_takes_the_card_down(fast_card, next_state: str) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ActionProposed(tool_name="web_search", rationale="Searching"))
+ await bus.publish(SystemStateChanged(previous="THINKING", new_state=next_state))
+ assert len(pet.of("clear")) == 1
+
+
+async def test_a_thought_while_jarvis_already_talks_clears_itself(fast_card) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="SPEAKING"))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text=_PLAN))
+ assert pet.of("status")
+ await asyncio.sleep(0.06)
+ assert len(pet.of("clear")) == 1
+
+
+async def test_an_agent_task_keeps_its_card_until_it_is_done(fast_card) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet)
+ started = JarvisAgentTaskStarted(utterance="Improve the Jarvis agents")
+ await bus.publish(started)
+ assert pet.of("status")[-1] == ("status", "Improve the Jarvis agents", "Working …")
+
+ # The turn that asked for it ends; the agent works on.
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="SPEAKING"))
+ await bus.publish(AudioOutFirst())
+ await bus.publish(SystemStateChanged(previous="SPEAKING", new_state="IDLE"))
+ await asyncio.sleep(0.06)
+ assert pet.of("clear") == []
+
+ await bus.publish(JarvisAgentTaskCompleted(trace_id=started.trace_id, success=True))
+ assert pet.of("status")[-1] == ("status", "Improve the Jarvis agents", "Done")
+ await asyncio.sleep(0.06)
+ assert len(pet.of("clear")) == 1
+
+
+async def test_a_completion_under_another_trace_still_releases_the_card(fast_card) -> None:
+ pet = _Pet()
+ _bridge_, bus = _bridge(pet)
+ await bus.publish(JarvisAgentTaskStarted(utterance="Build a site"))
+ await bus.publish(JarvisAgentTaskCompleted(success=False))
+ assert pet.of("status")[-1] == ("status", "Build a site", "Failed")
+ await asyncio.sleep(0.06)
+ assert len(pet.of("clear")) == 1
+
+
+async def test_a_lost_completion_does_not_pin_the_card_forever(fast_card) -> None:
+ pet = _Pet()
+ bridge, bus = _bridge(pet)
+ clock = _Clock()
+ bridge._clock = clock # noqa: SLF001 — the task age is measured on it
+ await bus.publish(JarvisAgentTaskStarted(utterance="Build a site"))
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="LISTENING"))
+ assert pet.of("clear") == []
+ clock.now += bus_bridge.PET_CARD_TASK_MAX_S + 1
+ await bus.publish(SystemStateChanged(previous="LISTENING", new_state="IDLE"))
+ assert len(pet.of("clear")) == 1
async def test_the_final_snapshot_beats_the_rate_limit() -> None:
pet = _Pet()
_bridge_, bus = _bridge(pet)
- await bus.publish(AssistantTextDelta(channel="voice", text="First."))
- await bus.publish(AssistantTextDelta(channel="voice", text="First. Second.", done=True))
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text="**Plan**\n\nFirst."))
+ await bus.publish(
+ ReasoningSummaryUpdated(response_id="r", text="**Plan**\n\nFirst. Second.", done=True)
+ )
assert [c[2] for c in pet.of("status")] == ["First.", "Second."]
-async def test_a_throttled_line_is_flushed_after_the_interval(fast_status) -> None:
+async def test_a_throttled_card_is_flushed_after_the_interval(fast_card) -> None:
pet = _Pet()
- bridge, bus = _bridge(pet)
- await bus.publish(VoiceSessionStarted(session_id="s1"))
- bridge._last_state = "LISTENING" # noqa: SLF001
- await bus.publish(TranscriptionUpdate(text="what is", is_final=False))
- await bus.publish(TranscriptionUpdate(text="what is the weather", is_final=False))
- await asyncio.sleep(0.08)
- assert pet.of("status")[-1] == ("status", "Listening …", "what is the weather")
+ _bridge_, bus = _bridge(pet)
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text="**Plan**\n\nFirst."))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text="**Plan**\n\nFirst. Second."))
+ await asyncio.sleep(0.06)
+ assert pet.of("status")[-1] == ("status", "Plan", "Second.")
-async def test_a_new_session_starts_a_fresh_bubble() -> None:
+async def test_a_new_session_clears_the_previous_card(fast_card) -> None:
pet = _Pet()
_bridge_, bus = _bridge(pet)
- await bus.publish(VoiceSessionStarted(session_id="s1"))
+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
+ await bus.publish(ReasoningSummaryUpdated(response_id="r", text=_PLAN))
await bus.publish(VoiceSessionStarted(session_id="s2"))
- # The same header twice: the reset means the second is not a "repeat".
- assert pet.of("status") == [
- ("status", "Listening …", ""),
- ("status", "Listening …", ""),
- ]
+ assert len(pet.of("clear")) == 1
+ assert pet.of("status") == [("status", "Planning the trip", "I need the train times first.")]
-async def test_headers_follow_the_interface_language(fast_status) -> None:
+async def test_labels_follow_the_interface_language(fast_card) -> None:
pet = _Pet()
_bridge_, bus = _bridge(pet, language="de")
await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
- assert pet.of("status")[-1][1] == "Denke nach …" # i18n-allow
+ await asyncio.sleep(0.06)
+ assert pet.of("status")[-1] == ("status", "Denkt nach …", "") # i18n-allow
await bus.publish(UiLanguageChanged(language="es"))
- await asyncio.sleep(0.03)
- await bus.publish(AssistantTextDelta(channel="voice", text="Hola.", done=True)) # i18n-allow
- assert pet.of("status")[-1][1] == "Respuesta" # i18n-allow
+ await bus.publish(ActionProposed(tool_name="web_search"))
+ # Shown at once, or by the flush when it landed inside the rate limit.
+ await asyncio.sleep(0.06)
+ assert pet.of("status")[-1] == ("status", "Trabajando", "Web search") # i18n-allow
-async def test_the_language_falls_back_to_the_pipeline_config(monkeypatch) -> None:
+async def test_the_language_falls_back_to_the_pipeline_config(monkeypatch, fast_card) -> None:
monkeypatch.setattr(
runtime_refs,
"_SPEECH_PIPELINE",
@@ -421,7 +558,8 @@ async def test_the_language_falls_back_to_the_pipeline_config(monkeypatch) -> No
pet = _Pet()
_bridge_, bus = _bridge(pet)
await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))
- assert pet.of("status")[-1][1] == "Pensando …" # i18n-allow
+ await asyncio.sleep(0.06)
+ assert pet.of("status")[-1] == ("status", "Pensando …", "") # i18n-allow
# ---------------------------------------------------------------------------
@@ -493,41 +631,6 @@ async def test_outcomes_are_throttled_but_an_error_after_a_success_shows() -> No
assert [c[1] for c in pet.of("outcome")] == ["success", "error", "success"]
-# ---------------------------------------------------------------------------
-# status lines: spoken replies only, every turn opens with its header
-# ---------------------------------------------------------------------------
-
-
-async def test_typed_and_background_replies_stay_out_of_the_bubble(fast_status) -> None:
- pet = _Pet()
- _bridge_, bus = _bridge(pet)
- await bus.publish(AssistantTextDelta(channel="chat", text="Typed answer.", done=True))
- await bus.publish(AssistantTextDelta(channel="", text="Background answer.", done=True))
- assert pet.of("status") == []
- await bus.publish(AssistantTextDelta(channel="realtime", text="Spoken answer.", done=True))
- assert pet.of("status")[-1] == ("status", "Answer", "Spoken answer.")
-
-
-async def test_every_follow_up_turn_reopens_the_listening_header(fast_status) -> None:
- pet = _Pet()
- _bridge_, bus = _bridge(pet)
- await bus.publish(SystemStateChanged(previous="IDLE", new_state="LISTENING"))
- await bus.publish(SystemStateChanged(previous="LISTENING", new_state="THINKING"))
- await bus.publish(SystemStateChanged(previous="THINKING", new_state="SPEAKING"))
- await bus.publish(SystemStateChanged(previous="SPEAKING", new_state="LISTENING"))
- headers = [c[1] for c in pet.of("status")]
- assert headers.count("Listening …") == 2
- assert pet.of("status")[-1] == ("status", "Listening …", "")
-
-
-async def test_a_long_reply_is_cut_from_its_end() -> None:
- pet = _Pet()
- _bridge_, bus = _bridge(pet)
- reply = "Some words. " * 5_000 + "The last sentence."
- await bus.publish(AssistantTextDelta(channel="voice", text=reply, done=True))
- assert pet.of("status")[-1] == ("status", "Answer", "The last sentence.")
-
-
# ---------------------------------------------------------------------------
# the backend loop: pinned early, never replaced by a throwaway one
# ---------------------------------------------------------------------------
diff --git a/ui/orb/bus_bridge.py b/ui/orb/bus_bridge.py
index f5e73c1fd2..3ecd290762 100644
--- a/ui/orb/bus_bridge.py
+++ b/ui/orb/bus_bridge.py
@@ -38,8 +38,6 @@ from typing import TYPE_CHECKING, Any
from jarvis.core.events import (
ActionExecuted,
ActionProposed,
- AnnouncementRequested,
- AssistantTextDelta,
AudioOutFirst,
ComposeRequested,
DictationCompleted,
@@ -51,13 +49,17 @@ from jarvis.core.events import (
DictationTranscript,
ErrorOccurred,
JarvisAgentBackgroundCompleted,
+ JarvisAgentTaskCompleted,
+ JarvisAgentTaskStarted,
ListeningStarted,
OrbResetRequested,
PetVisibilityToggleRequested,
+ ReasoningSummaryUpdated,
ResponseGenerated,
ShowWindowRequested,
SpeechSpoken,
SystemStateChanged,
+ ToolCallStarted,
TranscriptionUpdate,
UiLanguageChanged,
UserVisibleFeedback,
@@ -79,7 +81,7 @@ from jarvis.sessions.constants import (
SPOKEN_KIND_TIMEOUT,
SPOKEN_KIND_UNAVAILABLE,
)
-from jarvis.ui.pets.status_line import StatusFeed
+from jarvis.ui.pets.status_line import StatusFeed, condense, parse_reasoning_summary
from ui.orb.animations import IDLE_ANIMATION_POOL
if TYPE_CHECKING:
@@ -233,76 +235,80 @@ PET_ERROR_SPOKEN_KINDS: frozenset[str] = frozenset(
{SPOKEN_KIND_TIMEOUT, SPOKEN_KIND_UNAVAILABLE, SPOKEN_KIND_STT_UNAVAILABLE}
)
-# Headers of the pet's status bubble, per interface language ([ui] language).
-# User-facing product text drawn by the overlay, so every supported locale has
-# its own entry and none of them is a fallback for another.
-PET_STATUS_HEADERS: dict[str, dict[str, str]] = {
- "listening": {
- "en": "Listening …",
- "de": "Ich höre zu …", # i18n-allow
- "es": "Escuchando …", # i18n-allow
- },
+# The pet's status card (docs/pets.md): a bold title and one muted detail line,
+# shown ONLY while Jarvis is really thinking — the thinking model's reasoning
+# summary, a tool step, a running agent task. Never the live transcript and
+# never the reply: those are heard, and echoing them here read as noise.
+# Fixed labels per interface language ([ui] language); every supported locale
+# has its own entry and none of them is a fallback for another.
+PET_CARD_LABELS: dict[str, dict[str, str]] = {
"thinking": {
"en": "Thinking …",
- "de": "Denke nach …", # i18n-allow
+ "de": "Denkt nach …", # i18n-allow
"es": "Pensando …", # i18n-allow
},
- "talking": {
- "en": "Answer",
- "de": "Antwort", # i18n-allow
- "es": "Respuesta", # i18n-allow
+ "working": {
+ "en": "Working",
+ "de": "Arbeitet", # i18n-allow
+ "es": "Trabajando", # i18n-allow
+ },
+ "working_detail": {
+ "en": "Working …",
+ "de": "Arbeitet …", # i18n-allow
+ "es": "Trabajando …", # i18n-allow
+ },
+ "step_done": {
+ "en": "Step done",
+ "de": "Befehl ausgeführt", # i18n-allow
+ "es": "Paso completado", # i18n-allow
+ },
+ "step_failed": {
+ "en": "Step failed",
+ "de": "Befehl fehlgeschlagen", # i18n-allow
+ "es": "Paso fallido", # i18n-allow
+ },
+ "done": {
+ "en": "Done",
+ "de": "Erledigt", # i18n-allow
+ "es": "Hecho", # i18n-allow
+ },
+ "failed": {
+ "en": "Failed",
+ "de": "Fehlgeschlagen", # i18n-allow
+ "es": "Falló", # i18n-allow
},
}
PET_STATUS_LANGUAGES: tuple[str, ...] = ("en", "de", "es")
-# Minimum spacing of two status-bubble updates. A streamed reply produces a few
-# snapshots per second; repainting the bubble for each one is flicker.
+# Minimum spacing of two card updates. A streamed reasoning summary produces a
+# few snapshots per second; repainting the card for each one is flicker.
PET_STATUS_MIN_INTERVAL_S = 0.3
-# Minimum spacing of two pet one-shots (success / error). A burst of results is
-# one thing that happened; replaying the one-shot for each is flicker.
-PET_OUTCOME_MIN_INTERVAL_S = 3.0
+# Longest card title and detail line (characters); the card is a small pill.
+PET_CARD_TITLE_CHARS = 60
+PET_CARD_DETAIL_CHARS = 110
-# Reply channels whose streamed text the pet shows. Typed chat and background
-# work are read in the app window, not in an always-on-top bubble.
-PET_STATUS_REPLY_CHANNELS = frozenset({"voice", "realtime"})
+# A THINKING phase with no thought yet shows the bare "Thinking …" title after
+# this long — a fast turn whose thinking is over in a second shows no card.
+PET_CARD_THINKING_FALLBACK_S = 1.5
-# The most text a status line is cut from. A reply can be pages long; only its
-# end matters for the latest sentence, and condensing pages per update is waste.
-PET_STATUS_INPUT_CHARS = 400
+# How long a card stays after the thinking stopped (the surface fades it out).
+PET_CARD_LINGER_S = 1.5
-# Announcement kinds that describe work in progress (the pet's "thinking" line).
-# A completion or a sub-agent readback is an ANSWER, and it is spoken anyway.
-_PET_THINKING_ANNOUNCEMENT_KINDS = frozenset({"preamble", "progress"})
+# A finished agent task keeps its Done / Failed card this long.
+PET_CARD_TASK_DONE_S = 3.0
-# A sentence ends at terminal punctuation followed by whitespace.
-_SENTENCE_BREAK_RE = re.compile(r"(?<=[.!?…])\s+")
-_SENTENCE_END_RE = re.compile(r"[.!?…][\"'»”)\]]*$")
+# A thought outside a THINKING phase — the thinking model working on while the
+# voice model is already talking — clears itself after this much quiet.
+PET_CARD_QUIET_CLEAR_S = 4.0
+# An agent task whose completion never arrived stops holding the card after
+# this long; a lost event must not pin a card to the desktop forever.
+PET_CARD_TASK_MAX_S = 1800.0
-def _last_sentence(text: str, *, complete_only: bool = False) -> str:
- """The last sentence of ``text`` (whitespace collapsed).
-
- ``complete_only`` is for text still being produced: a reply streamed word
- by word ends in a fragment most of the time, and showing "The" for a
- moment between two full sentences is flicker, not information. Until the
- fragment ends in punctuation the previous complete sentence stays; a reply
- with no complete sentence yet shows the fragment.
- """
- flat = " ".join((text or "").split())
- if not flat:
- return ""
- pieces = [piece for piece in _SENTENCE_BREAK_RE.split(flat) if piece]
- if not pieces:
- return ""
- if complete_only and len(pieces) > 1 and not _SENTENCE_END_RE.search(pieces[-1]):
- return pieces[-2]
- return pieces[-1]
-
-
-def _tail_sentence(text: str, *, complete_only: bool = False) -> str:
- """:func:`_last_sentence` of the last ``PET_STATUS_INPUT_CHARS`` of ``text``."""
- return _last_sentence((text or "")[-PET_STATUS_INPUT_CHARS:], complete_only=complete_only)
+# Minimum spacing of two pet one-shots (success / error). A burst of results is
+# one thing that happened; replaying the one-shot for each is flicker.
+PET_OUTCOME_MIN_INTERVAL_S = 3.0
def _humanize_tool_name(tool_name: str) -> str:
@@ -344,12 +350,27 @@ class OrbBusBridge:
# from the running pipeline's config when needed; ``UiLanguageChanged``
# overrides it live.
self._language: str | None = language if language in PET_STATUS_LANGUAGES else None
- # ONE rate-limited feed for every status line the pet shows, so a burst
- # of transcript, tool and reply updates cannot flood the Tk thread. A
- # line the feed holds back is shown by ``_status_flush_task`` once the
+ # ONE rate-limited feed for every card the pet shows, so a burst of
+ # reasoning snapshots and tool steps cannot flood the Tk thread. A
+ # card the feed holds back is shown by ``_status_flush_task`` once the
# interval has passed, so the LAST update of a burst is never lost.
- self._status_feed = StatusFeed(time.monotonic, min_interval_s=PET_STATUS_MIN_INTERVAL_S)
+ self._status_feed = StatusFeed(
+ time.monotonic,
+ min_interval_s=PET_STATUS_MIN_INTERVAL_S,
+ title_chars=PET_CARD_TITLE_CHARS,
+ line_chars=PET_CARD_DETAIL_CHARS,
+ )
self._status_flush_task: asyncio.Task | None = None
+ # The pet's thinking card (docs/pets.md). ``_card_visible``: a card is
+ # on screen. ``_reasoning_title``: the heading of the thought the
+ # thinking model is on, which also titles the tool steps under it.
+ # ``_agent_tasks``: running agent tasks by trace id, as (title,
+ # started) — while one runs, its card stays up.
+ self._card_visible = False
+ self._reasoning_title = ""
+ self._agent_tasks: dict[str, tuple[str, float]] = {}
+ self._card_fallback_task: asyncio.Task | None = None
+ self._card_clear_task: asyncio.Task | None = None
# Clock for the pet's outcome throttle (replaceable in tests) and the
# last one-shot it played, as (kind, time).
self._clock = time.monotonic
@@ -563,13 +584,16 @@ class OrbBusBridge:
self._bus.subscribe(ActionExecuted, self._on_action_executed)
self._bus.subscribe(SpeechSpoken, self._on_speech_spoken)
self._bus.subscribe(ErrorOccurred, self._on_error_occurred)
- # ``JarvisAgentAnnouncement`` is deliberately NOT a status source:
- # its ``action`` is the spawn tool's bare relative-clause fragment
- # in the tool schema's language, whatever the interface language,
- # and reads as a broken sentence on its own. The spawn's
- # ``ActionProposed`` already puts a thinking line up.
- self._bus.subscribe(AnnouncementRequested, self._on_announcement)
- self._bus.subscribe(AssistantTextDelta, self._on_assistant_text_delta)
+ # The pet's thinking card: what the thinking model reasons about,
+ # the tool steps it takes, the agent tasks it hands work to. Spoken
+ # lines (acks, progress readbacks) and the reply are heard, not
+ # shown. ``JarvisAgentAnnouncement`` is no source either: its
+ # ``action`` is a bare clause fragment in the spawn tool's language
+ # and reads as a broken sentence on its own.
+ self._bus.subscribe(ReasoningSummaryUpdated, self._on_reasoning_summary)
+ self._bus.subscribe(ToolCallStarted, self._on_tool_call_started)
+ self._bus.subscribe(JarvisAgentTaskStarted, self._on_agent_task_started)
+ self._bus.subscribe(JarvisAgentTaskCompleted, self._on_agent_task_completed)
# Wire the orb's double-double-click gesture to a bus publish.
# The orb requires two ``<Double-Button-1>`` events inside
# ``MUTE_GESTURE_WINDOW_MS`` (four clicks in <600 ms) before
@@ -784,46 +808,174 @@ class OrbBusBridge:
return "en"
return language if language in PET_STATUS_LANGUAGES else "en"
- def _offer_status(self, kind: str, line: str, *, force: bool = False) -> None:
- """Feed one status line to a surface that shows them (the pet).
+ def _wants_card(self) -> bool:
+ """Does the current surface show the thinking card (the pet)?"""
+ return bool(getattr(self._orb, "wants_status_lines", False))
- Gated on ``wants_status_lines`` so no other style pays for condensing
- or rate limiting. ``kind`` picks the localized header; the feed decides
- whether this update is shown now or dropped as too soon after the last.
- """
- if not getattr(self._orb, "wants_status_lines", False):
+ def _label(self, key: str) -> str:
+ """One fixed card label in the interface language."""
+ labels = PET_CARD_LABELS[key]
+ return labels.get(self._status_language(), labels["en"])
+
+ def _cancel_card_task(self, name: str) -> None:
+ """Cancel one of the card's timers — never the task running this call."""
+ task = getattr(self, name)
+ setattr(self, name, None)
+ if task is None or task.done():
return
- headers = PET_STATUS_HEADERS.get(kind)
- if headers is None:
+ try:
+ current = asyncio.current_task()
+ except RuntimeError:
+ current = None
+ if task is not current:
+ task.cancel()
+
+ @staticmethod
+ def _card_loop() -> asyncio.AbstractEventLoop | None:
+ try:
+ return asyncio.get_running_loop()
+ except RuntimeError:
+ # Only bus handlers drive the card, and they run on the loop.
+ log.debug("pet card timer skipped: no running loop")
+ return None
+
+ def _expire_agent_tasks(self) -> None:
+ """Drop agent tasks whose completion never arrived (a lost event)."""
+ now = self._clock()
+ stale = [
+ key
+ for key, (_title, started) in self._agent_tasks.items()
+ if now - started > PET_CARD_TASK_MAX_S
+ ]
+ for key in stale:
+ self._agent_tasks.pop(key, None)
+
+ def _agent_title(self) -> str:
+ """Title of the newest running agent task ("" when none runs)."""
+ self._expire_agent_tasks()
+ if not self._agent_tasks:
+ return ""
+ return next(reversed(self._agent_tasks.values()))[0]
+
+ def _card_title(self) -> str:
+ """The title for a step: the current thought, else the running task."""
+ return self._reasoning_title or self._agent_title() or self._label("working")
+
+ def _show_card(
+ self,
+ title: str,
+ detail: str = "",
+ *,
+ force: bool = False,
+ quiet_clear_s: float | None = None,
+ ) -> None:
+ """Put ``title`` / ``detail`` on the pet's card (a no-op elsewhere).
+
+ The feed condenses both parts, drops a repeat and rate-limits the rest;
+ a held-back card is shown by the flush timer. A card that no THINKING
+ phase and no running agent task stands behind — the thinking model
+ working on while the voice model already talks — clears itself after
+ ``quiet_clear_s`` (default :data:`PET_CARD_QUIET_CLEAR_S`) without a
+ new thought.
+ """
+ if not self._wants_card():
return
- header = headers.get(self._status_language(), headers["en"])
+ self._cancel_card_task("_card_fallback_task")
+ self._cancel_card_task("_card_clear_task")
try:
- # The feed condenses both parts itself (markdown, paths, dumps).
- shown = self._status_feed.offer(header, line or "", force=force)
- except Exception: # noqa: BLE001 — a status line is cosmetic
- log.debug("status feed rejected a line", exc_info=True)
+ shown = self._status_feed.offer(title, detail or "", force=force)
+ except Exception: # noqa: BLE001 — a card is cosmetic
+ log.debug("status feed rejected a card", exc_info=True)
return
if shown is not None:
+ self._card_visible = True
self._call_surface("show_status", *shown)
else:
self._schedule_status_flush()
+ if self._last_state != "THINKING" and not self._agent_tasks:
+ self._schedule_card_clear(
+ PET_CARD_QUIET_CLEAR_S if quiet_clear_s is None else quiet_clear_s
+ )
+
+ def _clear_card(self, *, keep_agent_card: bool = True) -> None:
+ """Take the card down after a short linger — unless an agent still works."""
+ if not self._wants_card():
+ return
+ self._expire_agent_tasks()
+ if keep_agent_card and self._agent_tasks:
+ return
+ self._cancel_card_task("_card_fallback_task")
+ self._cancel_card_task("_card_clear_task")
+ self._cancel_card_task("_status_flush_task")
+ self._status_feed.reset()
+ self._reasoning_title = ""
+ if not self._card_visible:
+ return
+ self._card_visible = False
+ clear = getattr(self._orb, "clear_status", None)
+ if not callable(clear):
+ return
+ try:
+ clear(PET_CARD_LINGER_S)
+ except Exception: # noqa: BLE001 — a surface update must never break the bus
+ log.debug("surface clear_status failed", exc_info=True)
+
+ def _schedule_card_clear(self, delay_s: float) -> None:
+ """Clear the card after ``delay_s`` unless a newer card cancels this."""
+ loop = self._card_loop()
+ if loop is None:
+ return
+
+ async def _later() -> None:
+ try:
+ await asyncio.sleep(delay_s)
+ except asyncio.CancelledError:
+ return
+ self._card_clear_task = None
+ if self._last_state == "THINKING":
+ return
+ self._clear_card()
+
+ self._card_clear_task = loop.create_task(_later(), name="orb-pet-card-clear")
+
+ def _schedule_thinking_fallback(self) -> None:
+ """Show a bare "Thinking …" when a THINKING phase brings no thought.
+
+ Most turns that think put a real thought or step up within a moment;
+ this only fills the silence of one that does not, and a turn that is
+ over within the delay shows no card at all.
+ """
+ if not self._wants_card():
+ return
+ self._cancel_card_task("_card_fallback_task")
+ loop = self._card_loop()
+ if loop is None:
+ return
+
+ async def _later() -> None:
+ try:
+ await asyncio.sleep(PET_CARD_THINKING_FALLBACK_S)
+ except asyncio.CancelledError:
+ return
+ self._card_fallback_task = None
+ if self._last_state == "THINKING" and not self._card_visible:
+ self._show_card(self._agent_title() or self._label("thinking"), "", force=True)
+
+ self._card_fallback_task = loop.create_task(_later(), name="orb-pet-card-thinking")
def _schedule_status_flush(self) -> None:
- """Show the line the feed held back once the rate limit allows it.
+ """Show the card the feed held back once the rate limit allows it.
- Without this the last transcript or reply update of a burst would stay
- in the feed until some later event happened to arrive — often never.
- One pending flush at a time; it asks the feed, which returns nothing
- when there is nothing held back.
+ Without this the last snapshot of a burst would stay in the feed until
+ some later event happened to arrive — often never. One pending flush
+ at a time; it asks the feed, which returns nothing when there is
+ nothing held back.
"""
task = self._status_flush_task
if task is not None and not task.done():
return
- try:
- loop = asyncio.get_running_loop()
- except RuntimeError:
- # Only bus handlers offer lines, and they run on the loop.
- log.debug("status flush skipped: no running loop")
+ loop = self._card_loop()
+ if loop is None:
return
async def _flush() -> None:
@@ -831,10 +983,11 @@ class OrbBusBridge:
await asyncio.sleep(PET_STATUS_MIN_INTERVAL_S)
except asyncio.CancelledError:
return
- if not getattr(self._orb, "wants_status_lines", False):
+ if not self._wants_card():
return
shown = self._status_feed.flush()
if shown is not None:
+ self._card_visible = True
self._call_surface("show_status", *shown)
self._status_flush_task = loop.create_task(_flush(), name="orb-pet-status-flush")
@@ -880,16 +1033,51 @@ class OrbBusBridge:
if language in PET_STATUS_LANGUAGES:
self._language = language
+ async def _on_reasoning_summary(self, event: ReasoningSummaryUpdated) -> None:
+ """The thinking model's summary (GPT-Live): its newest section is the card.
+
+ A summary streams in as cumulative snapshots. The section heading is
+ the title — and stays the title of the tool steps taken under it — and
+ the last sentence of its body is the detail. The final snapshot beats
+ the rate limit so the card never stops one sentence short.
+ """
+ if not self._wants_card():
+ return
+ title, detail = parse_reasoning_summary(event.text or "")
+ if title:
+ self._reasoning_title = title
+ if not (title or detail):
+ return
+ heading = self._reasoning_title or self._agent_title() or self._label("thinking")
+ self._show_card(heading, detail, force=bool(event.done))
+
async def _on_action_proposed(self, event: ActionProposed) -> None:
- """A tool is about to run: its reason (else its name) is the thinking line."""
- line = (event.rationale or "").strip() or _humanize_tool_name(event.tool_name)
- if line:
- self._offer_status("thinking", line)
+ """A tool is about to run: its reason (else its name) is the detail."""
+ if not self._wants_card():
+ return
+ detail = (event.rationale or "").strip() or _humanize_tool_name(event.tool_name)
+ if detail:
+ self._show_card(self._card_title(), detail)
+
+ async def _on_tool_call_started(self, event: ToolCallStarted) -> None:
+ """A tool call some path reports without an ``ActionProposed``."""
+ if not self._wants_card():
+ return
+ detail = _humanize_tool_name(event.tool_name)
+ if detail:
+ self._show_card(self._card_title(), detail)
async def _on_action_executed(self, event: ActionExecuted) -> None:
- """A tool result is an outcome only when no turn is running (work
- finished in the background or between turns). Inside a turn it is a
- step; a failed step the turn recovers from is not the user's failure."""
+ """A tool result is a step on the card while Jarvis works.
+
+ It is an OUTCOME only when no turn is running (work finished in the
+ background or between turns). Inside a turn it is a step; a failed step
+ the turn recovers from is not the user's failure.
+ """
+ if self._card_visible:
+ self._show_card(
+ self._card_title(), self._label("step_done" if event.success else "step_failed")
+ )
if self._turn_in_progress():
return
self._pet_outcome("success" if event.success else "error")
@@ -908,29 +1096,32 @@ class OrbBusBridge:
return
self._pet_outcome("error")
- async def _on_announcement(self, event: AnnouncementRequested) -> None:
- """A preamble or a progress milestone is work in progress: show it."""
- if event.kind in _PET_THINKING_ANNOUNCEMENT_KINDS and (event.text or "").strip():
- self._offer_status("thinking", event.text)
-
- async def _on_assistant_text_delta(self, event: AssistantTextDelta) -> None:
- """The reply as it streams in: the latest sentence, rate-limited.
-
- ``text`` is the cumulative snapshot, so only its last sentence matters.
- The final snapshot (``done``) is forced through the rate limit, or the
- bubble could stop one sentence short of the answer.
-
- Spoken replies only (``voice`` / ``realtime``): a typed-chat or
- background reply is read in the app window, and an always-on-top
- bubble would put it on every shared screen.
- """
- if event.channel not in PET_STATUS_REPLY_CHANNELS:
+ async def _on_agent_task_started(self, event: JarvisAgentTaskStarted) -> None:
+ """An agent took on a task: its card stays until the task is done."""
+ if not self._wants_card():
return
- if not getattr(self._orb, "wants_status_lines", False):
+ title = condense(event.utterance or "", max_chars=PET_CARD_TITLE_CHARS)
+ title = title or self._label("working")
+ self._agent_tasks[str(event.trace_id)] = (title, self._clock())
+ self._show_card(title, self._label("working_detail"), force=True)
+
+ async def _on_agent_task_completed(self, event: JarvisAgentTaskCompleted) -> None:
+ """The task is done: Done / Failed on its card, then the card goes."""
+ if not self._wants_card():
return
- line = _tail_sentence(event.text, complete_only=not event.done)
- if line:
- self._offer_status("talking", line, force=bool(event.done))
+ entry = self._agent_tasks.pop(str(event.trace_id), None)
+ if entry is None and self._agent_tasks:
+ # A completion published under another trace than its start: the
+ # oldest running task is the best match, and it must not keep the
+ # card up forever.
+ entry = self._agent_tasks.pop(next(iter(self._agent_tasks)))
+ title = entry[0] if entry is not None else self._card_title()
+ self._show_card(
+ title,
+ self._label("done" if event.success else "failed"),
+ force=True,
+ quiet_clear_s=PET_CARD_TASK_DONE_S,
+ )
def _publish_visible_feedback(self, mode: str, observed: dict) -> None:
"""Called from the orb's Tk thread after a deiconify. Builds and
@@ -1113,10 +1304,8 @@ class OrbBusBridge:
self._show_listening_transcript("")
self._completion_continuation = False
self._cancel_idle_scheduler()
- # A new conversation starts a new bubble: nothing from the previous
- # one may be rate-limited against, or linger in, this one.
- self._status_feed.reset()
- self._offer_status("listening", "", force=True)
+ # A new conversation: nothing of the previous one's thinking lingers.
+ self._clear_card()
async def _on_session_ended(self, event: VoiceSessionEnded) -> None:
"""A voice session ended (hangup / idle-timeout / shutdown / error).
@@ -1139,6 +1328,7 @@ class OrbBusBridge:
self._suppress_show_until_session = True
if event.hangup_reason == HANGUP_ERROR:
self._pet_outcome("error")
+ self._clear_card()
# Defense in depth: a persistent (always-on) bar must drop to its idle
# look the instant a session ends, not only when the follow-up
# SystemStateChanged(IDLE) arrives. That state edge can be skipped or
@@ -1298,11 +1488,8 @@ class OrbBusBridge:
self._last_response_text = ""
self._show_listening_transcript("")
self._completion_continuation = False
- # Every fresh turn of a conversation, not only the first one,
- # opens the pet's bubble with its "Listening …" header; the
- # reset keeps the feed from treating it as a repeat.
- self._status_feed.reset()
- self._offer_status("listening", "", force=True)
+ # A fresh turn: the previous turn's thinking card is over.
+ self._clear_card()
self._cancel_idle_scheduler()
elif state == "WAITING_FOR_COMPLETION":
# User paused mid-sentence; the pipeline buffered an incomplete
@@ -1328,7 +1515,9 @@ class OrbBusBridge:
# happening). A reply arriving mid-THINKING swaps it in via
# _on_response_generated.
self._refresh_voice_bubble()
- self._offer_status("thinking", "", force=True)
+ # The pet's card waits for a real thought; only a silent phase
+ # gets the bare "Thinking …" title.
+ self._schedule_thinking_fallback()
self._cancel_idle_scheduler()
elif state == "SPEAKING":
# TTS synthesis is often still running here — the state flips to
@@ -1349,12 +1538,17 @@ class OrbBusBridge:
# does not outlive the mascot or stick around past the session.
# Also clear any in-flight completion-continuation window.
self._completion_continuation = False
- hide_comment = getattr(self._orb, "hide_comment", None)
- if callable(hide_comment):
- try:
- hide_comment()
- except Exception as exc: # noqa: BLE001
- log.debug("hide_comment failed: %s", exc)
+ if self._wants_card():
+ # The pet's card belongs to the thinking, not to the turn: a
+ # still running agent task keeps it up.
+ self._clear_card()
+ else:
+ hide_comment = getattr(self._orb, "hide_comment", None)
+ if callable(hide_comment):
+ try:
+ hide_comment()
+ except Exception as exc: # noqa: BLE001
+ log.debug("hide_comment failed: %s", exc)
if not self._hides_when_idle():
# Persistent "show at all times" bar: a standalone always-on
@@ -1438,8 +1632,6 @@ class OrbBusBridge:
# diverge.
self._listening_transcript_text = event.text.strip()
self._show_listening_transcript(self._listening_transcript_text)
- if getattr(self._orb, "wants_status_lines", False):
- self._offer_status("listening", _tail_sentence(self._listening_transcript_text))
async def _on_response_generated(self, event: ResponseGenerated) -> None:
"""Capture Jarvis's reply so the orb bubble can show it while speaking.
@@ -1453,14 +1645,6 @@ class OrbBusBridge:
self._last_response_text = (event.text or "").strip()
if self._last_state in ("THINKING", "SPEAKING"):
self._refresh_voice_bubble()
- # The pet's talking line, for reply paths that stream no
- # ``AssistantTextDelta``; after a streamed reply this is the same
- # sentence again and the feed treats it as such.
- if not getattr(self._orb, "wants_status_lines", False):
- return
- line = _tail_sentence(self._last_response_text)
- if line:
- self._offer_status("talking", line)
def _refresh_voice_bubble(self) -> None:
"""Render the right bubble text for the current voice state.
@@ -1909,6 +2093,10 @@ class OrbBusBridge:
)
def _show_listening_transcript(self, text: str) -> None:
+ if self._wants_card():
+ # The pet's card shows thinking only: what was said and what is
+ # answered are heard, not echoed (docs/pets.md).
+ return
show_transcript = getattr(self._orb, "show_listening_transcript", None)
if not callable(show_transcript):
return
@@ -1932,6 +2120,9 @@ class OrbBusBridge:
if self._last_state != "SPEAKING":
return
log.info("OrbBridge._on_audio_out_first → speaking overlay + mouth")
+ # Jarvis answers out loud: the thinking is over (an agent task that
+ # still runs keeps its card).
+ self._clear_card()
self._orb.show(mode="speak")
self._orb.play_animation("nod")
start_mouth = getattr(self._orb, "start_mouth_animation", None)
@@ -1979,6 +2170,14 @@ class OrbBusBridge:
"""
if event.success:
self._pet_outcome("success")
+ if self._wants_card() and (self._card_visible or self._agent_tasks):
+ title = condense(event.utterance or "", max_chars=PET_CARD_TITLE_CHARS)
+ self._show_card(
+ title or self._card_title(),
+ self._label("done" if event.success else "failed"),
+ force=True,
+ quiet_clear_s=PET_CARD_TASK_DONE_S,
+ )
if self._last_state not in ("IDLE", "ERROR", "PAUSED"):
return
self._orb.show(mode="speak")
@@ -2144,7 +2343,10 @@ class OrbBusBridge:
# A fresh surface starts with default icons; show it the live state.
self._seed_prompt_mode()
self._seed_mute_state()
+ # A fresh surface shows no card yet; nothing may be deduped against
+ # what the previous surface showed.
self._status_feed.reset()
+ self._card_visible = False
if self._voice_usable:
self._release_bar_startup_gate("voice-ready surface swap")
log.info("OrbBridge surface swapped (last_state=%s)", self._last_state)