Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agentic-ide): make chat activity receipts truthful
Ruben Lütke606e14ab97ea
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.pyindex f6685d390a..10d097f443 100644--- a/jarvis/agentic_ide/session.py+++ b/jarvis/agentic_ide/session.py@@ -90,7 +90,12 @@ from .agent_sessions import ()from .folders import ProjectProfile, probe_projectfrom .names import free_positions, normalize, position_of, resolve-from .terminal_input import THEME_COLOURS, TerminalQueryResponder+from .terminal_input import (+ THEME_COLOURS,+ TerminalQueryResponder,+ classify_terminal_input,+ is_pointer_noise_only,+)from .transcript import ReplayBuffer, Transcriptif TYPE_CHECKING: # pragma: no cover - typing only@@ -877,6 +882,12 @@ class Terminal:last_submit_at: float | None = None# Did the last prompt actually leave the input line? None = none sent yet.submitted: bool | None = None+ # A hand-pressed Enter on an injected prompt is being checked against the+ # screen. Kept explicit so another Enter stays on the verified path rather+ # than being mistaken for a brand-new manual instruction.+ manual_submit_pending: bool = False+ manual_submit_token: int = 0+ bracketed_paste_active: bool = False# Did it arrive with its line structure intact? False means the pane# rejected the pasted block and the single-line fallback carried it — worth# seeing in the log, because it silently costs prompt readability.@@ -2661,6 +2672,18 @@ class Registry:# Cleared rather than left alone so a restarted pane cannot inherit the# previous process's last output either.term.last_output_at = None+ term.manual_submit_pending = False+ term.manual_submit_token += 1+ term.bracketed_paste_active = False+ # The previous process's activity stamp goes with it. `stamp` resets+ # `activity_since` only when the WORD changes, so a pane that was+ # "waiting", restarted, and settled back to "waiting" kept the old+ # since — and the tooltip claimed the fresh agent had been waiting for+ # however long the dead one had. Until the next sweep (≤2 s) readers+ # fall back to a one-look answer, which is honest about not knowing.+ term.activity = ""+ term.activity_at = 0.0+ term.activity_since = 0.0# And this process has not stood still yet, whatever the previous one# did. Everything it is about to draw is a CLI painting itself, not an# agent working — see the field.@@ -2885,14 +2908,44 @@ class Registry:owner, term = foundif not term.pty_id:return False+ manager = self._manager()+ if is_pointer_noise_only(data):+ # A wheel tick, a click, a focus flip: the terminal talking, not a+ # person typing. It echoes nothing, so it must not arm the typing+ # shadow — stamping it made a busy pane read "done" for STILL_S+ # whenever it was scrolled or merely clicked. The TUI still gets+ # the bytes; it asked for them.+ return manager.write(term.pty_id, data)+ is_submit, edits_prompt, paste_active = classify_terminal_input(+ data, term.bracketed_paste_active+ )+ confirm_pending_prompt = bool(+ is_submit+ and not edits_prompt+ and term.last_prompt+ and (term.submitted is False or term.manual_submit_pending)+ )+ # Do not mutate activity or receipt state for bytes the PTY refused.+ written = manager.write(term.pty_id, data)+ if not written:+ return False+ term.bracketed_paste_active = paste_active# Somebody is typing in here. Recorded on EVERY keystroke (unlike the# submit handling below), because the activity detector needs to tell# the agent's own output apart from the echo of a person at the# keyboard — see `activity._printing_now`.term.last_input_at = time.time()+ if term.manual_submit_pending and edits_prompt:+ # The screen observer is checking whether the PREVIOUS prompt+ # disappeared. Any later edit can make that happen without a+ # submission (Ctrl+U is the clearest example), so its verdict is+ # stale. Resolve the injected prompt conservatively as unsent.+ term.manual_submit_pending = False+ term.manual_submit_token += 1+ term.submitted = False# Gated on a SUBMIT rather than on any keystroke: scrolling, arrow keys# and a half-typed line are not an instruction.- if "\r" in data or "\n" in data:+ if is_submit:# The user submitted something in the pane themselves, so this one# is being driven again and is no longer waiting to be nudged.# Dropping the pane off that list for a mere keypress would hide a@@ -2903,15 +2956,79 @@ class Registry:# makes its next stop worth reporting — a pane driven only by hand# never goes through `send_prompt`, so without this hook the bell# would stay silent for everybody who types their own prompts.- term.last_submit_at = term.last_input_at- term.submit_generation = term.process_generation+ if confirm_pending_prompt:+ # Enter may accept a completion rather than submit. Return the+ # receipt to "unconfirmed" until the same screen check used by+ # the injection path sees the prompt leave the input box.+ term.submitted = None+ term.manual_submit_pending = True+ self._schedule_manual_submit_confirmation(owner, term)+ else:+ term.last_submit_at = term.last_input_at+ term.submit_generation = term.process_generation# And the pane's conversation may have just begun, which for most# coding CLIs is the first moment its id exists on disk at all. A# pane driven only by hand never goes through `send_prompt`, so# without this hook it would keep the gap that cost every non-Claude# pane its resume handle.- self._lookup_after_conversation(owner, term)- return self._manager().write(term.pty_id, data)+ if not term.manual_submit_pending:+ self._lookup_after_conversation(owner, term)+ return True++ def _schedule_manual_submit_confirmation(self, owner: Session, term: Terminal) -> None:+ """Verify a hand-pressed Enter before changing an unsent receipt."""+ try:+ loop = asyncio.get_running_loop()+ except RuntimeError:+ # A synchronous embedding cannot observe the terminal over time.+ # Keep the receipt unconfirmed instead of making up an answer.+ logger.debug(+ "Agentic IDE: cannot verify manual Enter for {} without an event loop",+ term.name,+ )+ return++ payload = term.last_prompt+ generation = term.process_generation+ term.manual_submit_token += 1+ token = term.manual_submit_token++ async def _confirm() -> None:+ try:+ submitted = await self._observe_manual_submission(term, payload)+ if (+ term.process_generation != generation+ or term.last_prompt != payload+ or term.manual_submit_token != token+ ):+ return+ term.manual_submit_pending = False+ term.submitted = submitted+ if submitted:+ term.last_submit_at = time.time()+ term.submit_generation = term.process_generation+ self._lookup_after_conversation(owner, term)+ await announce_prompt(term)+ except asyncio.CancelledError:+ raise+ except Exception as exc: # noqa: BLE001 - confirmation must not kill input+ logger.warning(+ "Agentic IDE: could not verify manual Enter for {}: {}", term.name, exc+ )++ task = loop.create_task(_confirm())+ owner.lookups.add(task)+ task.add_done_callback(owner.lookups.discard)++ async def _observe_manual_submission(self, term: Terminal, payload: str) -> bool:+ """Passively watch whether a hand-pressed Enter emptied the input box."""+ needle = _submit_needle(payload)+ checks = max(1, int(_SUBMIT_WINDOW_S / _SUBMIT_POLL_S)) if _SUBMIT_POLL_S else 1+ for _ in range(checks):+ await asyncio.sleep(_SUBMIT_POLL_S)+ if not _input_line_holds(term.transcript.tail(10), needle):+ return True+ return Falseasync def _nudge_repaint(self, term: Terminal, cols: int, rows: int) -> None:"""Ask the agent in ``term`` to draw its whole interface again.@@ -3593,10 +3710,16 @@ class Registry:term.last_prompt_at = time.time()# The same stamp under the name the activity watcher reads, so a pane# driven by Jarvis and one driven by hand prove the same thing the same- # way. Set even for a hard False: the text is in the pane's input box,- # and whatever it does next was still asked of it.- term.last_submit_at = term.last_prompt_at- term.submit_generation = term.process_generation+ # way. NOT set on a hard False: the verification watched the text SIT+ # in the input box, so no job was handed over — and stamping it anyway+ # turned the echo of an unsubmitted prompt into a "Finished and waiting+ # at its prompt" bell for work that never started. The moment the user+ # presses Enter on that box themselves, `write` stamps it for real.+ if submitted is not False:+ term.last_submit_at = term.last_prompt_at+ term.submit_generation = term.process_generation+ term.manual_submit_pending = False+ term.manual_submit_token += 1term.submitted = submittedterm.sent_multiline = multiline and submitted is Truehistory_entry = prompt_history.PromptHistoryEntry(@@ -3675,10 +3798,17 @@ class Registry:typed = payload + (" " if _opens_completion(last_line) else "")if multiline:typed = f"{PASTE_START}{typed}{PASTE_END}"+ # Injected text echoes exactly like hand-typing, and the activity+ # detector must read it the same way: movement in the shadow of these+ # writes is the prompt being TYPED, never the agent already working —+ # and, for a prompt the pane refuses to submit, never the agent+ # "finishing" a job it was never given.+ term.last_input_at = time.time()if not manager.write(term.pty_id or "", typed):raise SessionError(f"Could not write to {term.name}.")arrived = await self._await_arrival(term, payload)+ term.last_input_at = time.time()manager.write(term.pty_id or "", "\r")left_the_box = await self._confirm_submitted(term, payload, manager)diff --git a/jarvis/agentic_ide/terminal_input.py b/jarvis/agentic_ide/terminal_input.pyindex fdd84cfe45..062cee67cb 100644--- a/jarvis/agentic_ide/terminal_input.py+++ b/jarvis/agentic_ide/terminal_input.py@@ -85,6 +85,82 @@ def is_terminal_report_only(data: str) -> bool:return bool(payload) and not _REPORT_RE.sub("", payload)+#: Pointer traffic and focus flips — frames xterm sends on the user's behalf+#: without a single key going down. SGR mouse reports (``ESC [ < b;x;y M/m``,+#: wheel ticks included), legacy X10 reports (``ESC [ M`` + three bytes), and+#: the focus-tracking pair (``ESC [ I`` / ``ESC [ O``) a TUI receives whenever+#: the pane is clicked or merely clicked away from.+_POINTER_RE = re.compile(+ r"(?:"+ r"\x1b\[<\d+;\d+;\d+[Mm]"+ r"|(?s:\x1b\[M.{3})"+ r"|\x1b\[[IO]"+ r")"+)++_PASTE_START = "\x1b[200~"+_PASTE_END = "\x1b[201~"+++def is_pointer_noise_only(data: str) -> bool:+ """True only when the entire input is mouse reports and focus events.++ These frames must still reach the PTY — the TUI asked for them — but they+ are not TYPING: nothing is echoed, so they must not arm the activity+ detector's keystroke shadow. Stamping them did: scrolling a busy pane, or+ just clicking into it, silenced its movement for ``STILL_S`` and the badge+ said "done" over an agent mid-job (maintainer report 2026-08-01). A frame+ that mixes pointer bytes with anything else counts as typing — this only+ ever excuses traffic that is provably not a keyboard.+ """+ payload = data or ""+ return bool(payload) and not _POINTER_RE.sub("", payload)+++def is_newline_chord_only(data: str) -> bool:+ """True for the terminal's explicit "insert line, do not submit" chord."""+ return data == "\x1b\r"+++def classify_terminal_input(data: str, bracketed_paste_active: bool) -> tuple[bool, bool, bool]:+ """Return ``(submits, edits, paste_active)`` for one xterm input chunk.++ Newlines inside bracketed paste delimit pasted text; they do not press+ Enter. The markers and payload may arrive in separate WebSocket frames, so+ callers retain the returned paste state for the next chunk. ``edits`` is+ true only for bytes that can change the prompt, which lets receipt checks+ ignore protocol framing while invalidating stale observations after real+ keyboard input.+ """+ active = bracketed_paste_active+ submits = False+ edits = False+ index = 0+ while index < len(data):+ if data.startswith(_PASTE_START, index):+ active = True+ index += len(_PASTE_START)+ continue+ if data.startswith(_PASTE_END, index):+ active = False+ index += len(_PASTE_END)+ continue+ if active:+ edits = True+ index += 1+ continue+ if data.startswith("\x1b\r", index):+ edits = True+ index += 2+ continue+ if data[index] in "\r\n":+ submits = True+ else:+ edits = True+ index += 1+ return submits, edits, active++def _rgb(colour: str) -> str:"""``#e8e8ec`` → ``rgb:e8e8/e8e8/ecec`` — the 16-bit form terminals use."""raw = colour.lstrip("#").lower()@@ -134,5 +210,8 @@ __all__ = ["DEVICE_ATTRIBUTES","THEME_COLOURS","TerminalQueryResponder",+ "classify_terminal_input",+ "is_newline_chord_only",+ "is_pointer_noise_only","is_terminal_report_only",]diff --git a/tests/unit/agentic_ide/test_prompt_submit.py b/tests/unit/agentic_ide/test_prompt_submit.pyindex f870d2893a..7bff50ad08 100644--- a/tests/unit/agentic_ide/test_prompt_submit.py+++ b/tests/unit/agentic_ide/test_prompt_submit.py@@ -12,6 +12,7 @@ afterwards that the text left the input line (retrying Enter while it has not)."""from __future__ import annotations+import asynciofrom pathlib import Pathimport pytest@@ -184,6 +185,124 @@ async def test_enter_is_pressed_again_while_the_prompt_sits_in_the_box(assert term.submitted is False+async def test_hand_pressed_enter_is_verified_before_an_unsent_receipt_changes(+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ """Enter can accept a completion, so the receipt must follow the screen."""+ term = await _live(registry, tmp_path)+ term.last_prompt = "review the pipeline"+ term.submitted = False+ on_output = fake_pty.spawns[-1]["on_output"]+ await on_output("pty", "\x1b[2J\x1b[H❯ review the pipeline\r\n")++ registry.write(term.key, "\r")+ assert term.submitted is None+ await asyncio.sleep(0.08)++ assert term.submitted is False+ assert term.last_submit_at is None+ assert fake_pty.typed == ["\r"], "passive verification must never press Enter again"+++async def test_hand_pressed_enter_marks_the_receipt_after_the_prompt_leaves(+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ term = await _live(registry, tmp_path)+ term.last_prompt = "review the pipeline"+ term.submitted = False+ on_output = fake_pty.spawns[-1]["on_output"]+ await on_output("pty", "\x1b[2J\x1b[H❯ review the pipeline\r\n")++ registry.write(term.key, "\r")+ await on_output("pty", "\x1b[2J\x1b[H❯\r\n✻ Working\r\n")+ await asyncio.sleep(0.04)++ assert term.submitted is True+ assert term.last_submit_at is not None+++async def test_modifier_enter_adds_a_line_without_arming_or_retrying_submission(+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ term = await _live(registry, tmp_path)+ term.last_prompt = "review the pipeline"+ term.submitted = False++ assert registry.write(term.key, "\x1b\r") is True+ await asyncio.sleep(0.08)++ assert term.submitted is False+ assert term.manual_submit_pending is False+ assert term.last_submit_at is None+ assert fake_pty.typed == ["\x1b\r"]+++async def test_failed_enter_write_does_not_change_receipt_or_activity(+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ term = await _live(registry, tmp_path)+ term.last_prompt = "review the pipeline"+ term.submitted = False+ fake_pty.close(term.pty_id or "")++ assert registry.write(term.key, "\r") is False+ assert term.submitted is False+ assert term.manual_submit_pending is False+ assert term.last_input_at is None+ assert term.last_submit_at is None+++async def test_repeated_enter_stays_verified_until_the_prompt_leaves(+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ term = await _live(registry, tmp_path)+ term.last_prompt = "review the pipeline"+ term.submitted = False+ on_output = fake_pty.spawns[-1]["on_output"]+ await on_output("pty", "\x1b[2J\x1b[H❯ review the pipeline\r\n")++ assert registry.write(term.key, "\r") is True+ assert registry.write(term.key, "\r") is True+ await asyncio.sleep(0.08)++ assert term.submitted is False+ assert term.manual_submit_pending is False+ assert term.last_submit_at is None+ assert fake_pty.typed == ["\r", "\r"]+++async def test_multiline_bracketed_paste_never_arms_submission(+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ term = await _live(registry, tmp_path)++ assert registry.write(term.key, f"{PASTE_START}first line\n") is True+ assert registry.write(term.key, f"second line\r\n{PASTE_END}") is True++ assert term.last_submit_at is None+ assert term.manual_submit_pending is False+ assert term.bracketed_paste_active is False+++async def test_edit_after_enter_invalidates_manual_submission_observation(+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ term = await _live(registry, tmp_path)+ term.last_prompt = "review the pipeline"+ term.submitted = False+ on_output = fake_pty.spawns[-1]["on_output"]+ await on_output("pty", "\x1b[2J\x1b[H⯠review the pipeline\r\n")++ assert registry.write(term.key, "\r") is True+ assert registry.write(term.key, "\x15") is True # Ctrl+U clears the input line.+ await on_output("pty", "\x1b[2J\x1b[Hâ¯\r\n")+ await asyncio.sleep(0.08)++ assert term.submitted is False+ assert term.manual_submit_pending is False+ assert term.last_submit_at is None++async def test_a_collapsed_paste_is_retried_and_reported_honestly(registry: Registry, fake_pty: FakePtyManager, tmp_path: Path) -> None:diff --git a/tests/unit/agentic_ide/test_terminal_input.py b/tests/unit/agentic_ide/test_terminal_input.pyindex ddf34fbc72..4b85d91722 100644--- a/tests/unit/agentic_ide/test_terminal_input.py+++ b/tests/unit/agentic_ide/test_terminal_input.py@@ -9,6 +9,8 @@ from jarvis.agentic_ide.terminal_input import (DEVICE_ATTRIBUTES,THEME_COLOURS,TerminalQueryResponder,+ classify_terminal_input,+ is_newline_chord_only,is_terminal_report_only,)@@ -90,6 +92,24 @@ def test_typing_is_never_mistaken_for_a_reply() -> None:assert is_terminal_report_only("") is False+def test_only_the_explicit_newline_chord_is_not_a_submit() -> None:+ assert is_newline_chord_only("\x1b\r") is True+ assert is_newline_chord_only("\r") is False+ assert is_newline_chord_only("text\r") is False+++def test_chunked_bracketed_paste_newlines_are_edits_not_submissions() -> None:+ submits, edits, active = classify_terminal_input("\x1b[200~first\n", False)+ assert (submits, edits, active) == (False, True, True)++ submits, edits, active = classify_terminal_input("second\r\n\x1b[201~", active)+ assert (submits, edits, active) == (False, True, False)+++def test_text_followed_by_enter_is_an_edit_and_a_submission() -> None:+ assert classify_terminal_input("new task\r", False) == (True, True, False)++def test_a_cursor_position_report_still_reaches_the_agent() -> None:"""Only the two replies the backend produces itself are dropped."""assert is_terminal_report_only("\x1b[12;40R") is False