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(terminal): drop the inherited "no colour" claim at app start-up too

Ruben Lütkea291ef1cd662
diff --git a/jarvis/core/colour_env.py b/jarvis/core/colour_env.py
new file mode 100644
index 0000000000..d972676f4f
--- /dev/null
+++ b/jarvis/core/colour_env.py
@@ -0,0 +1,68 @@
+"""Inherited environment variables that falsely claim colour is impossible.
+
+One answer for the whole app, because two layers need it and a second copy
+would drift apart the first time either is touched:
+
+* the **PTY boundary** (`jarvis.terminal.pty_manager`), where a child is
+ attached to a pane drawn by xterm.js, and
+* **app start-up** (`jarvis.ui.web.launcher`), which covers everything else the
+ app spawns — including the external terminals opened by
+ `jarvis.clis.external_terminal`, which inherit this process's environment
+ wholesale because they pass no ``env`` of their own.
+
+Why this exists at all: a desktop app launched once from a coding agent's or a
+CI shell inherits that shell's honest self-description — ``NO_COLOR=1``, an
+empty ``COLORTERM`` — and then hands it to every terminal it hosts, on every
+restart, indefinitely (the restart chain re-inherits it; see
+`jarvis.ui.relauncher.fresh_user_env`, which deliberately refreshes only the
+``JARVIS__*`` namespace). The statement was true about that shell's pipe. It is
+false about a terminal pane, and every mainstream CLI colour library obeys it
+without asking, so the whole workspace comes up monochrome.
+
+Deliberate settings survive. ``FORCE_COLOR`` counts as stale only when it
+DISABLES colour — a positive value is an escalation the user meant.
+``COLORTERM`` counts only when EMPTY, because the common colour libraries read
+its mere presence as "sixteen colours": an empty one inherited from a pipe
+DOWNGRADES a 256-colour terminal, while a real value is authoritative.
+"""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Mapping
+
+#: Values of ``FORCE_COLOR`` that mean "no colour". Anything else is a level.
+_FORCE_COLOR_OFF = frozenset({"0", "false"})
+
+
+def stale_colour_claims(source: Mapping[str, str]) -> tuple[str, ...]:
+ """Names in ``source`` that wrongly declare colour impossible, in order.
+
+ Returns an empty tuple for an environment that says nothing about colour,
+ which lets callers skip copying it at all.
+ """
+ stale: list[str] = []
+ if source.get("NO_COLOR", "").strip():
+ stale.append("NO_COLOR")
+ if source.get("FORCE_COLOR", "").strip().lower() in _FORCE_COLOR_OFF:
+ stale.append("FORCE_COLOR")
+ if "COLORTERM" in source and not source["COLORTERM"].strip():
+ stale.append("COLORTERM")
+ return tuple(stale)
+
+
+def sanitize_process_environment() -> tuple[str, ...]:
+ """Drop the stale claims from THIS process's environment; report what went.
+
+ Called once at start-up so that no child of the app can inherit them,
+ whichever spawn path it takes. Returning the names rather than logging here
+ keeps the decision to log — and in whose voice — with the caller, which at
+ start-up is the only layer that knows whether logging is up yet.
+
+ Cheap by construction: a few dict lookups, no import, no I/O, so it is safe
+ on the boot critical path (AP-26).
+ """
+ stale = stale_colour_claims(os.environ)
+ for name in stale:
+ os.environ.pop(name, None)
+ return stale
diff --git a/jarvis/terminal/pty_manager.py b/jarvis/terminal/pty_manager.py
index 5ab26d9cd0..b3f76c7f5b 100644
--- a/jarvis/terminal/pty_manager.py
+++ b/jarvis/terminal/pty_manager.py
@@ -112,6 +112,7 @@ from uuid import uuid4
from loguru import logger
+from jarvis.core.colour_env import stale_colour_claims
from jarvis.core.process_tree import ProcessTree, make_process_tree
from .backend import PtyHandle, make_pty_backend
@@ -149,44 +150,19 @@ UNKNOWN_EXIT_CODE = -1
_INTERACTIVE_TERM = "xterm-256color"
-def _stale_colour_claims(source: Mapping[str, str]) -> tuple[str, ...]:
- """Inherited "colour is impossible here" declarations that are now false.
-
- Each of these describes the LAUNCHER's own stdout, and each stops being
- true at this boundary for the same reason ``TERM=dumb`` does: the child is
- attached to a PTY drawn by xterm.js with a full sixteen-colour theme. They
- matter more than the terminal type, because every mainstream CLI colour
- library obeys them unconditionally — a pane that inherits ``NO_COLOR``
- renders its agent in plain monochrome no matter how capable ``TERM`` says
- the terminal is.
-
- This is not a hypothetical: an app started once from a coding agent's own
- shell inherits that shell's ``TERM=dumb`` + ``NO_COLOR=1``, hands it to
- every pane it opens, and passes it on across each in-app restart.
-
- Deliberate settings survive. ``FORCE_COLOR`` is dropped only when it
- DISABLES colour; a positive value is an escalation the user meant.
- ``COLORTERM`` is dropped only when EMPTY — the common colour libraries read
- its mere presence as "sixteen colours", so an empty one inherited from a
- pipe downgrades a 256-colour pane, while a real value stays authoritative.
- """
- stale: list[str] = []
- if source.get("NO_COLOR", "").strip():
- stale.append("NO_COLOR")
- if source.get("FORCE_COLOR", "").strip().lower() in {"0", "false"}:
- stale.append("FORCE_COLOR")
- if "COLORTERM" in source and not source["COLORTERM"].strip():
- stale.append("COLORTERM")
- return tuple(stale)
-
-
def _interactive_child_env(env: Mapping[str, str] | None) -> Mapping[str, str] | None:
"""Correct the parent's non-interactive claims at the PTY capability boundary.
Two corrections, both describing what the child is ACTUALLY connected to: a
missing/``dumb`` TERM becomes the xterm.js terminal type, and the inherited
- colour-suppressing variables listed by :func:`_stale_colour_claims` are
- dropped.
+ colour-suppressing variables named by
+ :func:`jarvis.core.colour_env.stale_colour_claims` are dropped. The second
+ matters more than the first, because every mainstream CLI colour library
+ obeys ``NO_COLOR`` unconditionally — a pane that inherits it renders its
+ agent in plain monochrome no matter how capable ``TERM`` says the terminal
+ is. App start-up drops the same set from this process (AP-26-safe), so in
+ practice this is the second line of defence rather than the first; it stays
+ because a caller may hand in any environment it likes.
``env`` is a complete replacement when supplied to either backend. Only
materialize one when something needs correcting; otherwise preserve the old
@@ -196,7 +172,7 @@ def _interactive_child_env(env: Mapping[str, str] | None) -> Mapping[str, str] |
source = os.environ if env is None else env
term = source.get("TERM", "").strip()
term_is_stale = not term or term.lower() == "dumb"
- colour_claims = _stale_colour_claims(source)
+ colour_claims = stale_colour_claims(source)
if not term_is_stale and not colour_claims:
return env
child_env = dict(source)
diff --git a/jarvis/ui/web/launcher.py b/jarvis/ui/web/launcher.py
index ef2059cf9f..d52bd65455 100644
--- a/jarvis/ui/web/launcher.py
+++ b/jarvis/ui/web/launcher.py
@@ -1056,6 +1056,25 @@ def main(argv: list[str] | None = None) -> int:
ensure_cli_paths()
+ # An app launched once from a coding-agent or CI shell inherits that shell's
+ # "colour is impossible here" declaration and hands it to every terminal it
+ # hosts — panes, and the external terminals opened through
+ # `jarvis.clis.external_terminal`, which pass no env of their own. The
+ # restart chain re-inherits it, so it survives indefinitely until dropped
+ # here. Dict lookups only, no import and no I/O (AP-26-safe).
+ from jarvis.core.colour_env import sanitize_process_environment
+
+ _dropped_colour_claims = sanitize_process_environment()
+ if _dropped_colour_claims:
+ import logging as _clog
+
+ _clog.getLogger(__name__).info(
+ "Dropped inherited colour-suppressing variables (%s) so hosted "
+ "terminals render in colour; this app was started from a shell that "
+ "declared it had none.",
+ ", ".join(_dropped_colour_claims),
+ )
+
_raw_argv = argv if argv is not None else sys.argv[1:]
args = _parse_args(_raw_argv)
diff --git a/tests/unit/core/test_colour_env.py b/tests/unit/core/test_colour_env.py
new file mode 100644
index 0000000000..7a14f915dd
--- /dev/null
+++ b/tests/unit/core/test_colour_env.py
@@ -0,0 +1,76 @@
+"""A terminal host must not pass on its launcher's "no colour" declaration.
+
+The live case this pins (2026-07-31): the desktop app had been started once
+from a coding agent's shell, inherited ``NO_COLOR=1`` and an empty
+``COLORTERM``, and handed both to every terminal pane it opened — so every
+coding CLI in the workspace rendered monochrome, and kept doing so across
+restarts because the restart chain re-inherits the environment.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from jarvis.core.colour_env import sanitize_process_environment, stale_colour_claims
+
+
+def test_an_environment_that_says_nothing_about_colour_is_left_alone() -> None:
+ assert stale_colour_claims({"PATH": "/usr/bin", "TERM": "xterm-256color"}) == ()
+
+
+def test_no_color_is_recognised_whatever_its_value() -> None:
+ """The convention is presence, not value — "0" still means no colour."""
+ assert stale_colour_claims({"NO_COLOR": "1"}) == ("NO_COLOR",)
+ assert stale_colour_claims({"NO_COLOR": "0"}) == ("NO_COLOR",)
+
+
+def test_an_empty_no_color_is_not_a_claim() -> None:
+ assert stale_colour_claims({"NO_COLOR": ""}) == ()
+
+
+def test_force_color_counts_only_when_it_disables_colour() -> None:
+ assert stale_colour_claims({"FORCE_COLOR": "0"}) == ("FORCE_COLOR",)
+ assert stale_colour_claims({"FORCE_COLOR": "false"}) == ("FORCE_COLOR",)
+ assert stale_colour_claims({"FORCE_COLOR": "3"}) == ()
+ assert stale_colour_claims({"FORCE_COLOR": "1"}) == ()
+
+
+def test_colorterm_counts_only_when_empty() -> None:
+ """Presence alone reads as "sixteen colours" and would downgrade a pane."""
+ assert stale_colour_claims({"COLORTERM": ""}) == ("COLORTERM",)
+ assert stale_colour_claims({"COLORTERM": "truecolor"}) == ()
+ assert stale_colour_claims({"PATH": "/usr/bin"}) == ()
+
+
+def test_the_measured_live_environment_is_reported_in_full() -> None:
+ """Exactly what pid 72176 carried on 2026-07-31."""
+ live = {"TERM": "dumb", "COLORTERM": "", "NO_COLOR": "1", "PATH": "/usr/bin"}
+
+ assert stale_colour_claims(live) == ("NO_COLOR", "COLORTERM")
+
+
+def test_sanitizing_the_process_environment_removes_them_and_reports_what_went(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ import os
+
+ monkeypatch.setenv("NO_COLOR", "1")
+ monkeypatch.setenv("COLORTERM", "")
+ monkeypatch.setenv("JARVIS_COLOUR_TEST_SENTINEL", "preserved")
+
+ dropped = sanitize_process_environment()
+
+ assert dropped == ("NO_COLOR", "COLORTERM")
+ assert "NO_COLOR" not in os.environ
+ assert "COLORTERM" not in os.environ
+ assert os.environ["JARVIS_COLOUR_TEST_SENTINEL"] == "preserved"
+
+
+def test_sanitizing_a_clean_environment_is_a_no_op(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ monkeypatch.delenv("NO_COLOR", raising=False)
+ monkeypatch.delenv("FORCE_COLOR", raising=False)
+ monkeypatch.setenv("COLORTERM", "truecolor")
+
+ assert sanitize_process_environment() == ()