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): correct inherited dumb terminal type
Ruben Lütke73cbb53e5f0f
diff --git a/jarvis/terminal/pty_manager.py b/jarvis/terminal/pty_manager.pyindex 4711619757..b91b8dad84 100644--- a/jarvis/terminal/pty_manager.py+++ b/jarvis/terminal/pty_manager.py@@ -99,9 +99,11 @@ falsy. So quitting an agent with ``/exit`` was reported as a crash, and theresume self-healing in ``jarvis/agentic_ide/session.py`` (which restarts a panewhose exit code is not 0) restarted agents the user had deliberately closed."""+from __future__ import annotationsimport asyncio+import osimport threadingfrom collections import dequefrom collections.abc import Awaitable, Callable, Mapping@@ -139,6 +141,30 @@ _EMPTY_READ_BACKOFF_S = 0.005#: stop", which is the one distinction anything above actually acts on.UNKNOWN_EXIT_CODE = -1+#: The browser terminal is xterm.js on every desktop platform. A launcher may+#: legitimately describe *its* non-interactive stdout as ``dumb``, but that+#: description stops being true once a child is attached to our PTY. Recent+#: interactive CLIs refuse or pause in that mismatch instead of trusting the+#: TTY handles, so advertise the terminal the child is actually connected to.+_INTERACTIVE_TERM = "xterm-256color"+++def _interactive_child_env(env: Mapping[str, str] | None) -> Mapping[str, str] | None:+ """Replace a missing/``dumb`` parent TERM at the PTY capability boundary.++ ``env`` is a complete replacement when supplied to either backend. Only+ materialize one when TERM needs correction; otherwise preserve the old+ inheritance/identity behaviour exactly. A meaningful caller-selected+ terminal type (for example ``screen-256color``) remains authoritative.+ """+ source = os.environ if env is None else env+ term = source.get("TERM", "").strip()+ if term and term.lower() != "dumb":+ return env+ child_env = dict(source)+ child_env["TERM"] = _INTERACTIVE_TERM+ return child_env+def normalize_exit_code(raw: int | None) -> int:"""One convention for an exit code, whatever the backend reported.@@ -172,7 +198,7 @@ class PtySession:terminal_id: strshell_id: strpid: int- proc: PtyHandle # normalized PTY handle behind the backend seam (AD-6)+ proc: PtyHandle # normalized PTY handle behind the backend seam (AD-6)stop_flag: threading.Event#: Kill-on-close container holding this child AND everything it spawns —#: the MCP servers a coding CLI starts outlive it otherwise (module@@ -322,10 +348,13 @@ class PtyManager:a choice made here), so a caller passing one must hand over a COMPLETEenvironment — typically ``os.environ`` plus its own keys. Building thatoverlay is what `jarvis.agent_accounts.spawn_env` exists for. ``None``- inherits this process's environment and is what every caller that does- not care gets.+ normally inherits this process's environment. The one correction made at+ this layer is replacing a missing/``dumb`` TERM with the xterm.js terminal+ type the child is actually connected to; doing that requires a complete+ snapshot of the inherited environment."""backend = make_pty_backend()+ child_env = _interactive_child_env(env)loop = asyncio.get_running_loop()@@ -336,7 +365,7 @@ class PtyManager:cwd=cwd,cols=cols,rows=rows,- env=env,+ env=child_env,)proc = await loop.run_in_executor(None, _spawn_sync)@@ -456,8 +485,7 @@ class PtyManager:session_b = self._sessions.get(id_b)if session_a is None or session_b is None:logger.debug(- "PTY swap refused — unknown terminal: {} (known={}) <-> {} "- "(known={})",+ "PTY swap refused — unknown terminal: {} (known={}) <-> {} (known={})",id_a,session_a is not None,id_b,@@ -578,9 +606,7 @@ class PtyManager:)code = session._exit_codetry:- await on_closed(- session.terminal_id, UNKNOWN_EXIT_CODE if code is None else code- )+ await on_closed(session.terminal_id, UNKNOWN_EXIT_CODE if code is None else code)except asyncio.CancelledError:raiseexcept Exception as exc: # noqa: BLE001 - the viewer may be gone@@ -633,8 +659,7 @@ class PtyManager:except Exception as exc: # noqa: BLE001# Process closed / pipe broken — normal end of life.logger.debug(- "PTY read exception (process presumably dead): "- "terminal={} error={}",+ "PTY read exception (process presumably dead): terminal={} error={}",session.terminal_id,exc,)@@ -673,8 +698,7 @@ class PtyManager:session.write(reply)except Exception as exc: # noqa: BLE001logger.debug(- "PTY probe reply could not be written: "- "terminal={} error={}",+ "PTY probe reply could not be written: terminal={} error={}",session.terminal_id,exc,)diff --git a/tests/unit/terminal/test_pty_environment.py b/tests/unit/terminal/test_pty_environment.pynew file mode 100644index 0000000000..bebc17d257--- /dev/null+++ b/tests/unit/terminal/test_pty_environment.py@@ -0,0 +1,105 @@+"""The PTY advertises its own capability, not its launcher's stdout.++The desktop app may be started from a coding-agent or CI terminal whose+``TERM=dumb`` correctly describes that parent. The child is subsequently+attached to ConPTY/ptyprocess and rendered by xterm.js, so inheriting the old+marker is false. Codex 0.146 pauses every interactive pane for confirmation in+that mismatch. These tests pin the correction at the shared PTY boundary on+all operating systems.+"""++from __future__ import annotations++from collections.abc import Mapping++import pytest++import jarvis.terminal.pty_manager as pty_mod+from jarvis.terminal.pty_manager import PtyManager+from tests.fakes.fake_pty_backend import FakePtyBackend+++class _NoopTree:+ def assign(self, _pid: int) -> None:+ return None++ def close(self) -> None:+ return None+++def backend(monkeypatch: pytest.MonkeyPatch) -> FakePtyBackend:+ fake = FakePtyBackend()+ monkeypatch.setattr(pty_mod, "make_pty_backend", lambda: fake)+ monkeypatch.setattr(pty_mod, "make_process_tree", lambda _name: _NoopTree())+ return fake+++async def _spawn_and_capture(+ backend: FakePtyBackend, env: Mapping[str, str] | None+) -> Mapping[str, str]:+ async def _output(_terminal_id: str, _text: str) -> None:+ return None++ async def _closed(_terminal_id: str, _code: int) -> None:+ return None++ manager = PtyManager()+ await manager.spawn(+ shell_argv=("agent",),+ shell_id="agentic-ide:T1",+ cwd=None,+ cols=80,+ rows=24,+ on_output=_output,+ on_closed=_closed,+ env=env,+ )+ captured = backend.spawn_calls[0]["env"]+ manager.close_all()+ assert isinstance(captured, Mapping)+ return captured+++async def test_dumb_parent_term_is_replaced_without_losing_the_environment(+ backend: FakePtyBackend, monkeypatch: pytest.MonkeyPatch+) -> None:+ monkeypatch.setenv("TERM", "dumb")+ monkeypatch.setenv("JARVIS_PTY_TEST_SENTINEL", "preserved")++ env = await _spawn_and_capture(backend, None)++ assert env["TERM"] == "xterm-256color"+ assert env["JARVIS_PTY_TEST_SENTINEL"] == "preserved"+ assert env.get("PATH")+++async def test_missing_parent_term_is_filled_at_the_pty_boundary(+ backend: FakePtyBackend, monkeypatch: pytest.MonkeyPatch+) -> None:+ monkeypatch.delenv("TERM", raising=False)++ env = await _spawn_and_capture(backend, None)++ assert env["TERM"] == "xterm-256color"+++async def test_explicit_account_environment_is_preserved_while_term_is_fixed(+ backend: FakePtyBackend,+) -> None:+ supplied = {"TERM": "dumb", "PATH": "/safe", "CODEX_HOME": "/account"}++ env = await _spawn_and_capture(backend, supplied)++ assert env == {"TERM": "xterm-256color", "PATH": "/safe", "CODEX_HOME": "/account"}+ assert supplied["TERM"] == "dumb", "the caller-owned mapping must not be mutated"+++async def test_meaningful_terminal_type_remains_caller_controlled(+ backend: FakePtyBackend,+) -> None:+ supplied = {"TERM": "screen-256color", "PATH": "/safe"}++ env = await _spawn_and_capture(backend, supplied)++ assert env is supplied