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.

fix(ide): hold every agent's first prompt until its terminal questions stop

rubenluetke10-beep66d2d62d79b0
diff --git a/jarvis/agentic_ide/fleet_actions.py b/jarvis/agentic_ide/fleet_actions.py
index 0dd9efa323..d72013f58a 100644
--- a/jarvis/agentic_ide/fleet_actions.py
+++ b/jarvis/agentic_ide/fleet_actions.py
@@ -17,6 +17,15 @@ COLOUR_PROBE_SETTLE_S = 0.3
#: before readiness stops waiting — a CLI version that dropped the question, or
#: an adopted agent whose question was cut out of the replay.
COLOUR_PROBE_WAIT_S = 10.0
+#: How long a starting CLI must have stopped asking its terminal questions —
+#: and have shown its input line — before a prompt is typed. Covers the
+#: questions answered by the viewer one round trip later, and Claude Code's
+#: version question about a second after its composer appears.
+STARTUP_QUIET_S = 1.5
+#: How long after its input line appeared (or, without one, after it
+#: started) a pane is still "starting". Past it questions no longer hold a
+#: prompt back, so a CLI that keeps asking cannot block typing for good.
+STARTUP_WINDOW_S = 15.0
_INPUT_MARKERS = ("›", "❯", ">")
log = logging.getLogger(__name__)
@@ -41,30 +50,70 @@ def ready_for_prompt(term: Any) -> bool:
from jarvis.workspace import agents as workspace_agents
spec = workspace_agents.get_agent(getattr(term, "agent", ""))
+ line_visible = input_line_visible(term, spec)
+ if line_visible:
+ _note_input_line(term)
if spec is not None and not spec.needs_input_line_wait:
- return True
- if not input_line_visible(term, spec):
+ # Typing before the composer is safe for this CLI; typing into its
+ # startup questions is not.
+ return terminal_questions_settled(term)
+ if not line_visible or not terminal_questions_settled(term):
return False
if spec is not None and spec.asks_colours_after_input_line:
return colour_probe_settled(term)
return True
+def _note_input_line(term: Any) -> None:
+ watch = getattr(term, "terminal_queries", None)
+ if watch is not None:
+ watch.note_input_line(time.time())
+
+
+def terminal_questions_settled(term: Any, now: float | None = None) -> bool:
+ """Has this starting CLI finished asking its terminal questions?
+
+ Coding CLIs ask their terminal for colours, version, keyboard protocol
+ and the like while they start, and read the answers from their keyboard
+ input — some of them right up to, or just after, the moment their input
+ line appears. A prompt typed into that window is read where an answer was
+ expected, and the answer is then typed into the composer as text such as
+ ``]10;rgb:…\\]11;rgb:…\\`` (maintainer report 2026-10-02, every coding
+ agent). So a prompt waits until the input line has been up, and no
+ question has come, for ``STARTUP_QUIET_S``. Only while the pane is
+ starting (``STARTUP_WINDOW_S``): a pane without a watch, or one long past
+ its start, is never held back.
+ """
+ watch = getattr(term, "terminal_queries", None)
+ if watch is None:
+ return True
+ moment = time.time() if now is None else now
+ line_at = getattr(watch, "input_line_at", None)
+ began = line_at if line_at is not None else getattr(term, "started_at", None)
+ if not began or moment - began >= STARTUP_WINDOW_S:
+ return True
+ for at in (getattr(watch, "asked_at", None), line_at):
+ if at is not None and moment - at < STARTUP_QUIET_S:
+ return False
+ return True
+
+
def colour_probe_settled(term: Any, now: float | None = None) -> bool:
"""Has this pane's CLI asked for its colours and had time to read the reply?
- Codex paints its composer, then asks the terminal for its colours and
+ Codex paints its composer, then asks the terminal for its colours one to
+ several seconds later — no quiet window can be sure to cover that — and
reads the answer from its keyboard input. A prompt typed in between is
read where the answer was expected, and the answer is then typed into the
composer as ``]10;rgb:…\\]11;rgb:…\\`` (maintainer report 2026-10-02).
A pane without a watch, or one that never asks within
``COLOUR_PROBE_WAIT_S`` of starting, is not held back.
"""
- watch = getattr(term, "colour_queries", None)
+ watch = getattr(term, "terminal_queries", None)
if watch is None:
return True
moment = time.time() if now is None else now
- asked_at = getattr(watch, "asked_at", None)
+ asked_at = getattr(watch, "colour_asked_at", None)
if asked_at is not None:
return moment - asked_at >= COLOUR_PROBE_SETTLE_S
started_at = getattr(term, "started_at", None)
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 113a70e07d..1b66992318 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -111,8 +111,8 @@ from .folders import ProjectProfile, probe_project
from .names import free_positions, normalize, position_of, resolve
from .terminal_input import (
THEME_COLOURS,
- ColourQueryWatch,
TerminalQueryResponder,
+ TerminalQueryWatch,
classify_terminal_input,
is_pointer_noise_only,
)
@@ -1260,11 +1260,11 @@ class Terminal:
# into a prompt the agent has long since opened, which is the corruption
# this exists to prevent. Only live output reaches it.
queries: TerminalQueryResponder = field(default_factory=TerminalQueryResponder)
- # When this process's CLI asked for its colours — seen in the output the
- # app receives, so on every backend including the PTY host. Readiness
- # waits on it for a CLI that asks only after painting its input line
- # (``fleet_actions.colour_probe_settled``).
- colour_queries: ColourQueryWatch = field(default_factory=ColourQueryWatch)
+ # When this process's CLI asked its terminal questions (colours, version,
+ # keyboard protocol…) — seen in the output the app receives, so on every
+ # backend including the PTY host. A prompt is not typed into a CLI that is
+ # still asking (``fleet_actions.terminal_questions_settled``).
+ terminal_queries: TerminalQueryWatch = field(default_factory=TerminalQueryWatch)
# Where this pane's output currently goes, or None while nobody is looking.
#
# A mutable slot rather than a closure captured at spawn time, and that is
@@ -2622,10 +2622,10 @@ class Registry:
term.transcript.feed(result.replay)
term.replay.clear()
term.replay.feed(result.replay)
- # The agent has been running all along; a colour question in its
- # replay was answered back then, by the host.
- term.colour_queries.reset()
- term.colour_queries.feed(result.replay, time.time())
+ # The agent has been running all along; a question in its replay was
+ # answered back then.
+ term.terminal_queries.reset()
+ term.terminal_queries.feed(result.replay, time.time())
if result.truncated:
term.replay.truncated = True
term.pty_id = info.terminal_id
@@ -2675,7 +2675,7 @@ class Registry:
term.transcript.feed(text)
term.replay.feed(text)
term.last_output_at = time.time()
- term.colour_queries.feed(text, term.last_output_at)
+ term.terminal_queries.feed(text, term.last_output_at)
for viewer in _viewers(term):
await viewer(text)
@@ -4190,7 +4190,7 @@ class Registry:
# in the replay buffer belongs to a terminal that no longer exists, and
# replaying it to the next viewer would show output from a dead agent.
term.replay.clear()
- term.colour_queries.reset()
+ term.terminal_queries.reset()
_watch(term, on_output, on_exit, cols, rows, on_geometry=on_geometry)
term.reattached = False
# This pane is wanted again, so the last deliberate kill is history.
@@ -4209,7 +4209,7 @@ class Registry:
term.transcript.feed(text)
term.replay.feed(text)
term.last_output_at = time.time()
- term.colour_queries.feed(text, term.last_output_at)
+ term.terminal_queries.feed(text, term.last_output_at)
# To EVERY viewer, not only the newest one. A pane open in two
# places has two screens and both are supposed to show the same
# agent; sending to one of them is how a window ends up frozen
diff --git a/jarvis/agentic_ide/terminal_input.py b/jarvis/agentic_ide/terminal_input.py
index b6ffda0d36..2f6e1f6193 100644
--- a/jarvis/agentic_ide/terminal_input.py
+++ b/jarvis/agentic_ide/terminal_input.py
@@ -205,44 +205,79 @@ class TerminalQueryResponder:
return f"\x1b]{which};{_rgb(colour)}{match.group('terminator')}"
-_COLOUR_QUERY_RE = re.compile(r"\x1b\](?:10|11);\?(?:\x07|\x1b\\)")
+#: Every question a coding CLI was measured asking its terminal while it
+#: starts (2026-10-02: Claude Code, Codex, OpenCode, Kimi, Antigravity) —
+#: colours, device attributes, version, keyboard protocol, mode reports,
+#: capabilities, cursor position and window size.
+_TERMINAL_QUERY_RE = re.compile(
+ r"(?P<colour>\x1b\](?:10|11);\?(?:\x07|\x1b\\))"
+ r"|\x1b\][0-9]+(?:;[0-9]+)*;\?(?:\x07|\x1b\\)"
+ r"|\x1b\[[?>=]?[0-9;]*c"
+ r"|\x1b\[>[0-9]*q"
+ r"|\x1b\[\?u"
+ r"|\x1b\[\?[0-9;]+\$p"
+ r"|\x1bP\+q[0-9a-fA-F;]*\x1b\\"
+ r"|\x1b\[\??6n"
+ r"|\x1b\[1[468]t"
+)
+
+#: Longest question worth remembering across a chunk boundary — capability
+#: queries (``ESC P + q <hex> ST``) run longer than the colour ones.
+_QUERY_TAIL_KEEP = 64
@dataclass(slots=True)
-class ColourQueryWatch:
- """Remember when a pane's CLI last asked its terminal for its colours.
-
- Fed from the output the app sees, which is always AFTER the reply went
- out: the PTY's reader (or the PTY host) answers a query before it hands
- the bytes on. So ``asked_at`` doubles as "answered at".
-
- It exists for a CLI that reads that answer straight from its console
- input while it starts. Codex paints its composer first and asks for the
- colours a second or more later; a prompt typed into that gap is still
- sitting in the input when the question goes out, the CLI reads the
- prompt where it expected the answer, and the colour reply then lands in
- the composer as ``]10;rgb:f4f4/f4f4/f6f6\\]11;rgb:1212/1414/1a1a\\``
- (reproduced 2026-10-02 on Codex 0.159.3). Readiness waits for this.
+class TerminalQueryWatch:
+ """Remember when a pane's CLI asked its terminal something, and what.
+
+ Fed from the output the app sees. The colour and device questions are
+ answered before that — the PTY's reader (or the PTY host) replies before
+ it hands the bytes on — and the rest are answered by the viewer one round
+ trip later.
+
+ It exists because coding CLIs read those answers from their keyboard
+ input while they start, and every one measured keeps asking until about
+ the moment its input line appears, some of them after it: Codex asks for
+ its colours one to several seconds after painting its composer, Claude
+ Code asks for the terminal's version a second after. A prompt typed into
+ that window is read where the answer was expected, and the answer is then
+ typed into the composer instead — ``]10;rgb:f4f4/f4f4/f6f6\\]11;rgb:…``
+ (reproduced 2026-10-02 on Codex 0.159.3). Readiness waits on this
+ (``jarvis.agentic_ide.fleet_actions.terminal_questions_settled``).
"""
+ #: The latest question of any kind.
asked_at: float | None = None
+ #: The latest colour question (``ESC ] 10/11 ; ?``).
+ colour_asked_at: float | None = None
+ #: When readiness first saw this process's input line.
+ input_line_at: float | None = None
_tail: str = field(default="", repr=False)
def feed(self, data: str, now: float) -> None:
- """Note a colour query in ``data``, even one split across two reads."""
+ """Note the questions in ``data``, even one split across two reads."""
if not data:
return
combined = self._tail + data
consumed = 0
- for match in _COLOUR_QUERY_RE.finditer(combined):
+ for match in _TERMINAL_QUERY_RE.finditer(combined):
self.asked_at = now
+ if match.group("colour"):
+ self.colour_asked_at = now
consumed = match.end()
- # A query already noted must not be noted again from the retained tail.
- self._tail = combined[max(consumed, len(combined) - _TAIL_KEEP) :]
+ # A question already noted must not be noted again from the tail.
+ self._tail = combined[max(consumed, len(combined) - _QUERY_TAIL_KEEP) :]
+
+ def note_input_line(self, now: float) -> None:
+ """Remember the first time the input line was seen."""
+ if self.input_line_at is None:
+ self.input_line_at = now
def reset(self) -> None:
"""Forget everything — a fresh process has asked nothing yet."""
self.asked_at = None
+ self.colour_asked_at = None
+ self.input_line_at = None
self._tail = ""
@@ -250,8 +285,8 @@ __all__ = [
"DEFAULT_APPEARANCE",
"DEVICE_ATTRIBUTES",
"THEME_COLOURS",
- "ColourQueryWatch",
"TerminalQueryResponder",
+ "TerminalQueryWatch",
"classify_terminal_input",
"is_newline_chord_only",
"is_pointer_noise_only",
diff --git a/tests/unit/agentic_ide/test_new_cli_providers.py b/tests/unit/agentic_ide/test_new_cli_providers.py
index 8a73dc3f8e..53cb49ce5e 100644
--- a/tests/unit/agentic_ide/test_new_cli_providers.py
+++ b/tests/unit/agentic_ide/test_new_cli_providers.py
@@ -31,11 +31,12 @@ import pytest
from jarvis.agentic_ide import agent_sessions, drops
from jarvis.agentic_ide.fleet_actions import (
- COLOUR_PROBE_SETTLE_S,
COLOUR_PROBE_WAIT_S,
+ STARTUP_QUIET_S,
+ STARTUP_WINDOW_S,
_ready_for_prompt,
)
-from jarvis.agentic_ide.terminal_input import ColourQueryWatch
+from jarvis.agentic_ide.terminal_input import TerminalQueryWatch
from jarvis.workspace import agents as workspace_agents
# --------------------------------------------------------------- the registry
@@ -832,6 +833,17 @@ def test_a_booting_pane_of_a_new_cli_is_not_prompted_yet() -> None:
assert _ready_for_prompt(_Pane("claude", ("anything",))) is True
+def _starting(agent: str, lines: tuple[str, ...], *, line_up_for: float) -> Any:
+ """A pane whose process started a moment ago and whose input line has
+ been on screen for ``line_up_for`` seconds."""
+ pane = _Pane(agent, lines)
+ now = time.time()
+ pane.started_at = now - line_up_for - 1.0
+ pane.terminal_queries = TerminalQueryWatch()
+ pane.terminal_queries.note_input_line(now - line_up_for)
+ return pane
+
+
def test_codex_is_not_prompted_before_its_colour_question_is_answered() -> None:
"""Codex paints its composer, THEN asks for the screen colours.
@@ -840,30 +852,44 @@ def test_codex_is_not_prompted_before_its_colour_question_is_answered() -> None:
(maintainer report 2026-10-02, reproduced on Codex 0.159.3).
"""
composer = ("› Ask Codex anything",)
- now = time.time()
-
- booting = _Pane("codex", composer)
- booting.started_at = now
- booting.colour_queries = ColourQueryWatch()
- assert _ready_for_prompt(booting) is False
+ booting = _starting("codex", composer, line_up_for=STARTUP_QUIET_S + 1.0)
+ assert _ready_for_prompt(booting) is False, "quiet, but the colour question is still to come"
- booting.colour_queries.feed("\x1b]10;?\x1b\\\x1b]11;?\x1b\\", time.time())
+ booting.terminal_queries.feed("\x1b]10;?\x1b\\\x1b]11;?\x1b\\", time.time())
assert _ready_for_prompt(booting) is False, "the CLI still needs a moment to read the answer"
- booting.colour_queries.asked_at = now - COLOUR_PROBE_SETTLE_S
+ asked = time.time() - STARTUP_QUIET_S
+ booting.terminal_queries.asked_at = booting.terminal_queries.colour_asked_at = asked
assert _ready_for_prompt(booting) is True
# A Codex that never asks is not held back forever.
- silent = _Pane("codex", composer)
- silent.started_at = now - COLOUR_PROBE_WAIT_S
- silent.colour_queries = ColourQueryWatch()
+ silent = _starting("codex", composer, line_up_for=STARTUP_QUIET_S)
+ silent.started_at = time.time() - COLOUR_PROBE_WAIT_S
assert _ready_for_prompt(silent) is True
- # Only a CLI that declares the question waits for it.
- other = _Pane("opencode", ("> ",))
- other.started_at = now
- other.colour_queries = ColourQueryWatch()
- assert _ready_for_prompt(other) is True
+
+def test_no_agent_is_prompted_while_it_is_still_asking_its_terminal() -> None:
+ """Every coding CLI asks its terminal questions while it starts — some just
+ after its input line appears (Claude Code's version question, a second
+ later). A prompt typed into that window turns the answer into composer
+ text, so the first prompt waits for the questions to stop (maintainer
+ report 2026-10-02: "every coding agent")."""
+ for agent, lines in (("claude", ("❯ ",)), ("opencode", ("> ",)), ("kimi", ("> ",))):
+ fresh = _starting(agent, lines, line_up_for=0.2)
+ assert _ready_for_prompt(fresh) is False, f"{agent}: input line only just appeared"
+
+ asking = _starting(agent, lines, line_up_for=STARTUP_QUIET_S + 1.0)
+ asking.terminal_queries.feed("\x1b[>0q\x1b[c", time.time())
+ assert _ready_for_prompt(asking) is False, f"{agent}: still asking"
+
+ quiet = _starting(agent, lines, line_up_for=STARTUP_QUIET_S + 1.0)
+ quiet.terminal_queries.feed("\x1b[>0q", time.time() - STARTUP_QUIET_S)
+ assert _ready_for_prompt(quiet) is True, f"{agent}: done asking"
+
+ # Long past its start, a CLI that keeps asking cannot block typing.
+ chatty = _starting("claude", ("❯ ",), line_up_for=STARTUP_WINDOW_S)
+ chatty.terminal_queries.feed("\x1b[c", time.time())
+ assert _ready_for_prompt(chatty) is True
# ----------------------------------------------------- DeepSeek Harness
diff --git a/tests/unit/agentic_ide/test_prompt_submit.py b/tests/unit/agentic_ide/test_prompt_submit.py
index 9ced4ae9e7..1432e625f5 100644
--- a/tests/unit/agentic_ide/test_prompt_submit.py
+++ b/tests/unit/agentic_ide/test_prompt_submit.py
@@ -134,7 +134,9 @@ def registry(fake_pty: FakePtyManager, monkeypatch: pytest.MonkeyPatch) -> Regis
monkeypatch.setattr(session_mod, "_LATE_ARRIVAL_WINDOW_S", 0.04)
monkeypatch.setattr(fleet_actions, "READY_POLL_S", 0.01)
monkeypatch.setattr(fleet_actions, "READY_TIMEOUT_S", 0.08)
+ # Submit mechanics, not the startup-question wait (tested on its own).
monkeypatch.setattr(fleet_actions, "COLOUR_PROBE_SETTLE_S", 0.0)
+ monkeypatch.setattr(fleet_actions, "STARTUP_QUIET_S", 0.0)
return Registry(pty_manager=fake_pty)
diff --git a/tests/unit/agentic_ide/test_terminal_input.py b/tests/unit/agentic_ide/test_terminal_input.py
index 263d085574..74ebd49d26 100644
--- a/tests/unit/agentic_ide/test_terminal_input.py
+++ b/tests/unit/agentic_ide/test_terminal_input.py
@@ -8,8 +8,8 @@ import pytest
from jarvis.agentic_ide.terminal_input import (
DEVICE_ATTRIBUTES,
THEME_COLOURS,
- ColourQueryWatch,
TerminalQueryResponder,
+ TerminalQueryWatch,
classify_terminal_input,
is_newline_chord_only,
is_terminal_report_only,
@@ -71,22 +71,47 @@ def test_an_answered_query_is_never_answered_twice() -> None:
def test_the_colour_question_is_noticed_once_even_when_split() -> None:
- watch = ColourQueryWatch()
+ watch = TerminalQueryWatch()
watch.feed("banner \x1b]11", 1.0)
- assert watch.asked_at is None
+ assert watch.colour_asked_at is None
watch.feed(";?\x07 composer", 2.0)
- assert watch.asked_at == 2.0
+ assert watch.colour_asked_at == watch.asked_at == 2.0
# The retained tail must not report the same question again later.
watch.feed("more output", 3.0)
assert watch.asked_at == 2.0
- watch.feed(DA_QUERY + "\x1b]10;rgb:ffff/ffff/ffff\x07", 4.0)
- assert watch.asked_at == 2.0, "device attributes and colour SETTING are not the question"
+ watch.feed("\x1b]10;rgb:ffff/ffff/ffff\x07", 4.0)
+ assert watch.asked_at == 2.0, "SETTING a colour is not a question"
+
+ watch.feed(DA_QUERY, 5.0)
+ assert watch.asked_at == 5.0
+ assert watch.colour_asked_at == 2.0, "device attributes are not the colour question"
+
+ watch.note_input_line(6.0)
+ watch.note_input_line(7.0)
+ assert watch.input_line_at == 6.0, "the FIRST sighting counts"
watch.reset()
- assert watch.asked_at is None
+ assert (watch.asked_at, watch.colour_asked_at, watch.input_line_at) == (None, None, None)
+
+
+ "question",
+ [
+ "\x1b[>0q", # version (Claude Code, OpenCode)
+ "\x1b[?u", # keyboard protocol (Claude Code, Kimi, Antigravity)
+ "\x1b[?2026$p", # mode report (OpenCode, Antigravity)
+ "\x1bP+q4d73\x1b\\", # capability (OpenCode)
+ "\x1b]4;1;?\x07", # palette entry
+ ],
+)
+def test_every_measured_startup_question_is_noticed(question: str) -> None:
+ watch = TerminalQueryWatch()
+ watch.feed(f"draw{question}draw", 1.0)
+ assert watch.asked_at == 1.0
+ assert watch.colour_asked_at is None
def test_ordinary_output_is_not_mistaken_for_a_query() -> None: