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(agent-chat): show Claude's thinking in thread chats again
rubenluetke10-beep232bbb2745d8
diff --git a/jarvis/agent_chat/runner_cli.py b/jarvis/agent_chat/runner_cli.pyindex 0a65ac1a22..2bbfa8ac95 100644--- a/jarvis/agent_chat/runner_cli.py+++ b/jarvis/agent_chat/runner_cli.py@@ -162,6 +162,17 @@ def claude_argv_prefix() -> list[str]:return claude_cli_argv_prefix(binary)+def warm_claude_capabilities() -> None:+ """Run the Claude CLI's flag probes (blocking, cached) so planning only reads them."""+ from jarvis.claude_auth import claude_cli_supports_thinking_display++ try:+ prefix = claude_argv_prefix()+ except CliUnavailable:+ return # planning reports the missing CLI itself+ claude_cli_supports_thinking_display(prefix)++def codex_argv_prefix() -> list[str]:try:from jarvis.missions.workers.codex_direct_worker import _resolve_codex_argv_prefix@@ -445,6 +456,7 @@ def plan_claude(resume=resume,identity=identity,env=jarvis_harness.apply_env(_account_env("claude")),+ thinking_summaries=True,)@@ -491,10 +503,12 @@ def _plan_claude_code(resume: str | None,identity: jarvis_harness.Identity | None,env: dict[str, str],+ thinking_summaries: bool = False,) -> CliPlan:mode = normalize_permission("claude-cli", permission_mode)+ prefix = claude_argv_prefix()argv = [- *claude_argv_prefix(),+ *prefix,"--print","--output-format","stream-json",@@ -514,6 +528,15 @@ def _plan_claude_code(argv += ["--model", model]if effort:argv += ["--effort", effort]+ # Without this the stream carries empty thinking blocks and the chat shows+ # no reasoning. The probe ran off the event loop before planning+ # (``warm_claude_capabilities``); an older CLI without the flag skips it.+ # Anthropic's endpoint only — GLM's compatible one is not asked for a+ # thinking setting it never documented.+ from jarvis.claude_auth import claude_cli_thinking_display_known++ if thinking_summaries and claude_cli_thinking_display_known(prefix):+ argv += ["--thinking-display", "summarized"]# Jarvis' own tools, and the identity that says when to use them. Both are# skipped when the app cannot offer them (no control key, server not bound# yet) — the session then behaves exactly as it did before. On the Jarvis@@ -2923,6 +2946,8 @@ async def _run_cli_once(# Resolve the installed CLI's effort ladder off the event loop so# newly available models keep the required model/effort pairing.await asyncio.to_thread(read_agy_models, required_model=session.model)+ if runner == "claude-cli":+ await asyncio.to_thread(warm_claude_capabilities)plan: CliPlan = planner(prompt=planned_prompt,cwd=cwd,diff --git a/jarvis/claude_auth.py b/jarvis/claude_auth.pyindex 8434fe850d..847a4374a9 100644--- a/jarvis/claude_auth.py+++ b/jarvis/claude_auth.py@@ -71,6 +71,7 @@ _AUTH_STATUS_CACHE: dict[tuple[str, str, str, str, str], tuple[float, ClaudeCliAuthSnapshot | None]] = {}_SAFE_MODE_CACHE: dict[tuple[str, ...], bool] = {}+_THINKING_DISPLAY_CACHE: dict[tuple[str, ...], bool] = {}_AUTH_STATUS_TTL_S = 5.0@@ -97,6 +98,7 @@ def clear_version_cache() -> None:_AUTH_LOGOUT_CACHE.clear()_AUTH_STATUS_CACHE.clear()_SAFE_MODE_CACHE.clear()+ _THINKING_DISPLAY_CACHE.clear()# ----------------------------------------------------------------------@@ -352,6 +354,41 @@ def claude_cli_supports_safe_mode(argv_prefix: Sequence[str]) -> bool:return supported+def claude_cli_supports_thinking_display(argv_prefix: Sequence[str]) -> bool:+ """Capability-probe ``--thinking-display`` (summaries of the model's thinking).++ A print-mode stream leaves thinking blocks empty unless the CLI is asked+ for summaries, so a chat shows no reasoning at all. The flag is hidden+ from ``--help``; the probe passes it an invalid value beside+ ``--version``. A CLI that knows the option rejects the value and names+ it; an older one ignores it and prints its version. Cached per prefix.+ """+ key = tuple(argv_prefix)+ if key in _THINKING_DISPLAY_CACHE:+ return _THINKING_DISPLAY_CACHE[key]+ try:+ proc = subprocess.run(+ [*key, "--thinking-display", "probe", "--version"],+ capture_output=True,+ encoding="utf-8",+ errors="replace",+ timeout=4.0,+ text=True,+ creationflags=NO_WINDOW_CREATIONFLAGS,+ )+ output = f"{proc.stdout or ''}\n{proc.stderr or ''}"+ supported = proc.returncode != 0 and "--thinking-display" in output+ except (OSError, subprocess.SubprocessError):+ supported = False+ _THINKING_DISPLAY_CACHE[key] = supported+ return supported+++def claude_cli_thinking_display_known(argv_prefix: Sequence[str]) -> bool:+ """The cached probe result only — never spawns, so it is safe on the event loop."""+ return _THINKING_DISPLAY_CACHE.get(tuple(argv_prefix), False)++def claude_native_auth_env(env: Mapping[str, str]) -> dict[str, str]:"""Expose the user's real Claude auth store to a safe-mode subprocess.diff --git a/tests/unit/agent_chat/test_agent_chat_ladders.py b/tests/unit/agent_chat/test_agent_chat_ladders.pyindex 73e0c8c4b9..537d6e0bfa 100644--- a/tests/unit/agent_chat/test_agent_chat_ladders.py+++ b/tests/unit/agent_chat/test_agent_chat_ladders.py@@ -174,6 +174,25 @@ def test_claude_planner_passes_the_cli_mode_through(monkeypatch, tmp_path: Path)}+def test_claude_planner_asks_for_thinking_summaries(monkeypatch, tmp_path: Path):+ """Print mode leaves thinking blocks empty; summaries are the thread's reasoning."""+ from jarvis import claude_auth++ monkeypatch.setattr(runner_cli, "claude_argv_prefix", lambda: ["claude"])+ monkeypatch.setattr(runner_cli, "_registry_env", lambda _name, env: env)+ monkeypatch.setitem(claude_auth._THINKING_DISPLAY_CACHE, ("claude",), True)+ args = dict(+ prompt="hi", cwd=tmp_path, model="", effort="", permission_mode="default", resume=None+ )+ argv = plan_claude(**args).argv+ assert argv[argv.index("--thinking-display") + 1] == "summarized"+ # GLM rides Claude Code against another endpoint and is never asked.+ assert "--thinking-display" not in runner_cli.plan_glm(**args).argv+ # An older CLI (probe False) gets no flag it would reject.+ monkeypatch.setitem(claude_auth._THINKING_DISPLAY_CACHE, ("claude",), False)+ assert "--thinking-display" not in plan_claude(**args).argv++def test_claude_planner_opens_the_control_protocol(monkeypatch, tmp_path: Path):"""The handshake, without which no permission mode can ever ask.diff --git a/tests/unit/test_claude_auth.py b/tests/unit/test_claude_auth.pyindex 3e8a87bd1d..7ad64e8e09 100644--- a/tests/unit/test_claude_auth.py+++ b/tests/unit/test_claude_auth.py@@ -528,6 +528,35 @@ def test_safe_mode_capability_probe_is_cached(monkeypatch: pytest.MonkeyPatch) -assert calls == 1+ ("returncode", "stderr", "expected"),+ [+ # A CLI that knows the hidden flag rejects the probe value by name.+ (1, "error: option '--thinking-display <display>' argument 'probe' is invalid.", True),+ # An older CLI ignores the flag next to --version and prints its version.+ (0, "", False),+ ],+)+def test_thinking_display_probe_reads_the_rejection(+ monkeypatch: pytest.MonkeyPatch, returncode: int, stderr: str, expected: bool+) -> None:+ calls: list[list[str]] = []++ def fake_run(argv, **_kwargs): # noqa: ANN001, ANN003+ calls.append(list(argv))+ return subprocess.CompletedProcess(+ argv, returncode, stdout="2.1.0 (Claude Code)", stderr=stderr+ )++ monkeypatch.setattr(claude_auth.subprocess, "run", fake_run)++ assert claude_auth.claude_cli_thinking_display_known(["claude"]) is False+ assert claude_auth.claude_cli_supports_thinking_display(["claude"]) is expected+ assert claude_auth.claude_cli_supports_thinking_display(["claude"]) is expected+ assert claude_auth.claude_cli_thinking_display_known(["claude"]) is expected+ assert calls == [["claude", "--thinking-display", "probe", "--version"]]++def test_windows_cmd_resolves_to_adjacent_node_entrypoint(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: