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): wait for Codex's colour question before typing a prompt

rubenluetke10-beepdb6d0783914f
diff --git a/jarvis/agentic_ide/fleet_actions.py b/jarvis/agentic_ide/fleet_actions.py
index 4e4585bd42..0dd9efa323 100644
--- a/jarvis/agentic_ide/fleet_actions.py
+++ b/jarvis/agentic_ide/fleet_actions.py
@@ -9,6 +9,14 @@ from typing import Any
READY_TIMEOUT_S = 45.0
READY_POLL_S = 0.25
+#: How long after its colour question was answered such a CLI gets to read the
+#: answer. The reply is written before the app even sees the question, so this
+#: only covers the CLI's own parsing.
+COLOUR_PROBE_SETTLE_S = 0.3
+#: How long a pane that declares the colour question may go without asking it
+#: 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
_INPUT_MARKERS = ("›", "❯", ">")
log = logging.getLogger(__name__)
@@ -35,7 +43,32 @@ def ready_for_prompt(term: Any) -> bool:
spec = workspace_agents.get_agent(getattr(term, "agent", ""))
if spec is not None and not spec.needs_input_line_wait:
return True
- return input_line_visible(term, spec)
+ if not input_line_visible(term, spec):
+ return False
+ if spec is not None and spec.asks_colours_after_input_line:
+ return colour_probe_settled(term)
+ 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
+ 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)
+ if watch is None:
+ return True
+ moment = time.time() if now is None else now
+ asked_at = getattr(watch, "asked_at", None)
+ if asked_at is not None:
+ return moment - asked_at >= COLOUR_PROBE_SETTLE_S
+ started_at = getattr(term, "started_at", None)
+ return not started_at or moment - started_at >= COLOUR_PROBE_WAIT_S
def input_line_visible(term: Any, spec: Any | None = None) -> bool:
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index e85e5ea8e4..c8033154c7 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -110,6 +110,7 @@ from .folders import ProjectProfile, probe_project
from .names import free_positions, normalize, position_of, resolve
from .terminal_input import (
THEME_COLOURS,
+ ColourQueryWatch,
TerminalQueryResponder,
classify_terminal_input,
is_pointer_noise_only,
@@ -1249,6 +1250,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)
# 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
@@ -2608,6 +2614,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())
if result.truncated:
term.replay.truncated = True
term.pty_id = info.terminal_id
@@ -2657,6 +2667,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)
for viewer in _viewers(term):
await viewer(text)
@@ -4198,6 +4209,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()
_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.
@@ -4216,6 +4228,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)
# 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
@@ -4463,7 +4476,9 @@ class Registry:
from . import fleet_actions
try:
- ready = await fleet_actions.wait_for_prompt_ready(
+ # The input line, not full prompt readiness: the slot guards
+ # the shared store's boot, which is over once the line exists.
+ ready = await fleet_actions.wait_for_input_line(
session,
[term.name],
timeout_s=fleet_actions.READY_TIMEOUT_S,
diff --git a/jarvis/agentic_ide/terminal_input.py b/jarvis/agentic_ide/terminal_input.py
index dd43039ad6..b6ffda0d36 100644
--- a/jarvis/agentic_ide/terminal_input.py
+++ b/jarvis/agentic_ide/terminal_input.py
@@ -205,10 +205,52 @@ class TerminalQueryResponder:
return f"\x1b]{which};{_rgb(colour)}{match.group('terminator')}"
+_COLOUR_QUERY_RE = re.compile(r"\x1b\](?:10|11);\?(?:\x07|\x1b\\)")
+
+
+@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.
+ """
+
+ asked_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."""
+ if not data:
+ return
+ combined = self._tail + data
+ consumed = 0
+ for match in _COLOUR_QUERY_RE.finditer(combined):
+ self.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) :]
+
+ def reset(self) -> None:
+ """Forget everything — a fresh process has asked nothing yet."""
+ self.asked_at = None
+ self._tail = ""
+
+
__all__ = [
"DEFAULT_APPEARANCE",
"DEVICE_ATTRIBUTES",
"THEME_COLOURS",
+ "ColourQueryWatch",
"TerminalQueryResponder",
"classify_terminal_input",
"is_newline_chord_only",
diff --git a/jarvis/workspace/agents.py b/jarvis/workspace/agents.py
index ba28a30b17..8f2679c186 100644
--- a/jarvis/workspace/agents.py
+++ b/jarvis/workspace/agents.py
@@ -278,6 +278,13 @@ class WorkspaceAgent:
#: input-marker row. Ratatui CLIs can draw the same marker while disabling
#: keyboard input; cursor visibility is the stable distinction.
requires_visible_input_cursor: bool = False
+ #: True when this CLI asks its terminal for the screen colours shortly
+ #: AFTER its input line appears and reads the answer from its keyboard
+ #: input. A prompt typed into that gap corrupts the answer, which then
+ #: shows up in the composer as ``]10;rgb:…`` text, so readiness also waits
+ #: for that question to be asked and answered
+ #: (:func:`jarvis.agentic_ide.fleet_actions.colour_probe_settled`).
+ asks_colours_after_input_line: bool = False
#: Maximum resumed panes of this CLI and account that may still be starting.
#: Zero means no provider-specific limit beyond the shared machine gate.
#: Use this when parallel starts contend on one vendor runtime store; the
@@ -799,6 +806,7 @@ _AGENTS: dict[str, WorkspaceAgent] = {
instruction_filename="AGENTS.md",
input_markers=("›", "»"),
requires_visible_input_cursor=True,
+ asks_colours_after_input_line=True,
# Two simultaneous resumes against Codex's shared SQLite/runtime store
# were measured beyond 90 s while one resume initialized substantially
# faster. Serialize only this shared-store boot phase. Claude and every
diff --git a/tests/unit/agentic_ide/test_new_cli_providers.py b/tests/unit/agentic_ide/test_new_cli_providers.py
index 196289e469..8a73dc3f8e 100644
--- a/tests/unit/agentic_ide/test_new_cli_providers.py
+++ b/tests/unit/agentic_ide/test_new_cli_providers.py
@@ -30,7 +30,12 @@ from typing import Any
import pytest
from jarvis.agentic_ide import agent_sessions, drops
-from jarvis.agentic_ide.fleet_actions import _ready_for_prompt
+from jarvis.agentic_ide.fleet_actions import (
+ COLOUR_PROBE_SETTLE_S,
+ COLOUR_PROBE_WAIT_S,
+ _ready_for_prompt,
+)
+from jarvis.agentic_ide.terminal_input import ColourQueryWatch
from jarvis.workspace import agents as workspace_agents
# --------------------------------------------------------------- the registry
@@ -827,6 +832,40 @@ def test_a_booting_pane_of_a_new_cli_is_not_prompted_yet() -> None:
assert _ready_for_prompt(_Pane("claude", ("anything",))) is True
+def test_codex_is_not_prompted_before_its_colour_question_is_answered() -> None:
+ """Codex paints its composer, THEN asks for the screen colours.
+
+ A prompt typed into that gap is read where the colour answer was expected,
+ and the answer is typed into the composer as ``]10;rgb:…`` text instead
+ (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.colour_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
+ 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()
+ 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
+
+
# ----------------------------------------------------- DeepSeek Harness
diff --git a/tests/unit/agentic_ide/test_prompt_submit.py b/tests/unit/agentic_ide/test_prompt_submit.py
index f7e7c0f487..9ced4ae9e7 100644
--- a/tests/unit/agentic_ide/test_prompt_submit.py
+++ b/tests/unit/agentic_ide/test_prompt_submit.py
@@ -134,6 +134,7 @@ 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)
+ monkeypatch.setattr(fleet_actions, "COLOUR_PROBE_SETTLE_S", 0.0)
return Registry(pty_manager=fake_pty)
@@ -182,9 +183,21 @@ async def test_a_booting_codex_is_not_typed_into_until_its_input_line_exists(
term.pty_id,
"\x1b[2J\x1b[H\u203a Ask Codex anything\x1b[1;3H\x1b[?25h",
)
+ await asyncio.sleep(0.03)
+ # The composer is up, but Codex has not asked for its colours yet: a
+ # prompt typed now turns the colour reply into composer text.
+ assert fake_pty.typed == [], "typed before Codex's startup colour question"
+
+ # A healthy Codex reads the reply instead of drawing it, so the fake must
+ # not echo it into its composer either.
+ fake_pty.tui_echo = False
+ await fake_pty.emit(term.pty_id, "\x1b]10;?\x1b\\\x1b]11;?\x1b\\")
+ answered = len(fake_pty.typed)
+ assert answered == 1 and "rgb:" in fake_pty.typed[0], fake_pty.typed
+ fake_pty.tui_echo = True
delivered = await sending
- assert fake_pty.typed[:2] == ["review the pipeline", "\r"]
+ assert fake_pty.typed[answered : answered + 2] == ["review the pipeline", "\r"]
assert delivered.submitted is True
diff --git a/tests/unit/agentic_ide/test_terminal_input.py b/tests/unit/agentic_ide/test_terminal_input.py
index 1fd6fba548..263d085574 100644
--- a/tests/unit/agentic_ide/test_terminal_input.py
+++ b/tests/unit/agentic_ide/test_terminal_input.py
@@ -8,6 +8,7 @@ import pytest
from jarvis.agentic_ide.terminal_input import (
DEVICE_ATTRIBUTES,
THEME_COLOURS,
+ ColourQueryWatch,
TerminalQueryResponder,
classify_terminal_input,
is_newline_chord_only,
@@ -69,6 +70,25 @@ def test_an_answered_query_is_never_answered_twice() -> None:
assert responder.feed("Welcome to Codex\r\n") == ""
+def test_the_colour_question_is_noticed_once_even_when_split() -> None:
+ watch = ColourQueryWatch()
+
+ watch.feed("banner \x1b]11", 1.0)
+ assert watch.asked_at is None
+ watch.feed(";?\x07 composer", 2.0)
+ assert 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.reset()
+ assert watch.asked_at is None
+
+
def test_ordinary_output_is_not_mistaken_for_a_query() -> None:
responder = TerminalQueryResponder()