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): mount Jarvis tools for Grok Build seats
rubenluetke10-beepba95cb6c0b1b
diff --git a/jarvis/agent_chat/jarvis_harness.py b/jarvis/agent_chat/jarvis_harness.pyindex d0c43b5802..15e600dae5 100644--- a/jarvis/agent_chat/jarvis_harness.py+++ b/jarvis/agent_chat/jarvis_harness.py@@ -53,8 +53,8 @@ log = logging.getLogger(__name__)_MCP_PATH: Final[str] = "/api/control/mcp/"#: The server name the CLI shows to the model. Claude Code exposes the tools as-#: ``mcp__jarvis__<tool>``; the preamble below names that prefix, so the two-#: must stay in step.+#: ``mcp__jarvis__<tool>``; Grok Build as ``jarvis__<tool>`` (called through+#: ``use_tool``). The preamble names both prefixes, so they must stay in step._SERVER_NAME: Final[str] = "jarvis"#: The request header that carries the chat's session id to the tool server.@@ -75,8 +75,9 @@ SYSTEM_PREAMBLE: Final[str] = ("no marketing superlatives, no filler openers. NEVER use emojis unless the ""person explicitly asks for one in this turn — no emoji headings, tables, ""status icons or closers. Tables carry plain words, never emoji symbols.\n\n"- "You have Jarvis' own tools, offered to you over MCP under the "- "`mcp__jarvis__` prefix. They act on the RUNNING app and on the accounts the "+ "You have Jarvis' own tools, offered to you over MCP. Claude Code names them "+ "`mcp__jarvis__<tool>`; Grok Build names them `jarvis__<tool>` and you call "+ "them through use_tool. They act on the RUNNING app and on the accounts the ""person has connected to it — their calendar, mail, contacts, media, wiki, ""windows, screen, skills and Jarvis' own settings. Prefer them over a shell ""command, a CLI you would have to authenticate yourself, a skill, or the "@@ -84,9 +85,9 @@ SYSTEM_PREAMBLE: Final[str] = ("machine: those tools are already signed in and already permitted. Reach for ""your file and shell tools for code and for the filesystem.\n\n""Two kinds of hands: your own file and shell tools are your hands in the "- "working folder this chat is open in; `mcp__jarvis__run_shell` and its "- "siblings are Jarvis' hands on the whole machine. Use the folder's hands for "- "the folder, Jarvis' for everything else.\n\n"+ "working folder this chat is open in; `mcp__jarvis__run_shell` / "+ "`jarvis__run_shell` and their siblings are Jarvis' hands on the whole "+ "machine. Use the folder's hands for the folder, Jarvis' for everything else.\n\n""Some of those tools ask the person for approval before they run. That is ""normal and it is not a failure — wait for the answer rather than routing ""around it.\n\n"@@ -254,6 +255,101 @@ def install_agy_jarvis_plugin(cwd: Path, session_id: str | None = None) -> Pathreturn None+#: Grok Build has no ``--mcp-config``. Print-mode discovers HTTP MCP from+#: the project file ``.grok/config.toml`` (cwd, then parents up to the git+#: root). Markers keep our block replaceable without touching other servers.+_GROK_PROJECT_CONFIG: Final[str] = "config.toml"+_GROK_BLOCK_BEGIN: Final[str] = "# BEGIN JARVIS HANDS"+_GROK_BLOCK_END: Final[str] = "# END JARVIS HANDS"+++def grok_mcp_server_entry(session_id: str | None = None) -> dict[str, Any] | None:+ """The Grok ``[mcp_servers.jarvis]`` row for this app's tool server.++ Grok speaks ``url`` + ``bearer_token_env_var`` + ``headers`` (not Claude's+ ``type``/``url`` JSON). ``None`` when the app cannot offer the tools —+ same contract as :func:`mcp_config_json`. The control key never enters+ the file: it travels in the child env under :data:`KEY_ENV_VAR`.+ """+ try:+ url = endpoint()+ if not url or not control_key():+ return None+ entry: dict[str, Any] = {+ "url": url,+ "bearer_token_env_var": KEY_ENV_VAR,+ "enabled": True,+ }+ if session_id:+ entry["headers"] = {HEADER_NAME: session_id}+ return entry+ except Exception: # noqa: BLE001 — see mcp_config_json+ log.warning("agent chat: could not build the Jarvis grok MCP entry", exc_info=True)+ return None+++def _toml_string(value: str) -> str:+ return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'+++def _grok_jarvis_block(entry: dict[str, Any]) -> str:+ lines = [+ _GROK_BLOCK_BEGIN,+ "# Written by Personal Jarvis so Grok Build can reach Jarvis' tools.",+ f"[mcp_servers.{_SERVER_NAME}]",+ f"url = {_toml_string(str(entry['url']))}",+ f"bearer_token_env_var = {_toml_string(str(entry['bearer_token_env_var']))}",+ "enabled = true",+ ]+ headers = entry.get("headers")+ if isinstance(headers, dict) and headers:+ lines.append("")+ lines.append(f"[mcp_servers.{_SERVER_NAME}.headers]")+ for key, value in headers.items():+ lines.append(f"{_toml_string(str(key))} = {_toml_string(str(value))}")+ lines.append(_GROK_BLOCK_END)+ return "\n".join(lines) + "\n"+++def _merge_grok_jarvis_block(existing: str, block: str) -> str:+ """Replace a previous Jarvis block, else append. Never drop other servers."""+ if _GROK_BLOCK_BEGIN in existing and _GROK_BLOCK_END in existing:+ pattern = re.compile(+ re.escape(_GROK_BLOCK_BEGIN) + r".*?" + re.escape(_GROK_BLOCK_END) + r"\n?",+ re.DOTALL,+ )+ return pattern.sub(block, existing, count=1)+ body = existing.rstrip()+ return block if not body else body + "\n\n" + block+++def install_grok_jarvis_mcp(cwd: Path, session_id: str | None = None) -> Path | None:+ """Write a project MCP row so print-mode grok mounts Jarvis' tools.++ grok discovers HTTP MCP from ``.grok/config.toml`` in the working folder+ (no ``--mcp-config`` flag; Claude-shaped JSON on argv is ignored). The+ control key stays in the child env. Additive: a failure here never fails+ the turn.+ """+ entry = grok_mcp_server_entry(session_id)+ if entry is None:+ return None+ try:+ config_path = Path(cwd) / ".grok" / _GROK_PROJECT_CONFIG+ config_path.parent.mkdir(parents=True, exist_ok=True)+ previous = ""+ if config_path.is_file():+ previous = config_path.read_text(encoding="utf-8")+ config_path.write_text(+ _merge_grok_jarvis_block(previous, _grok_jarvis_block(entry)),+ encoding="utf-8",+ )+ return config_path+ except Exception: # noqa: BLE001 — see mcp_config_json+ log.warning("agent chat: could not install the Jarvis grok MCP config", exc_info=True)+ return None++def apply_env(env: dict[str, str]) -> dict[str, str]:"""Put the control key into a child environment, if there is one to give."""key = control_key()@@ -457,7 +553,9 @@ __all__ = ["endpoint","identity_dir","identity_prompt",+ "grok_mcp_server_entry","install_agy_jarvis_plugin",+ "install_grok_jarvis_mcp","mcp_config_json","remove_identity_file","render_transcript",diff --git a/jarvis/agent_chat/runner_cli.py b/jarvis/agent_chat/runner_cli.pyindex d78af14681..333fbd461d 100644--- a/jarvis/agent_chat/runner_cli.py+++ b/jarvis/agent_chat/runner_cli.py@@ -485,6 +485,12 @@ def plan_grok(# Grok Build takes the prompt on argv, so the identity rides in front of# it — the compact cut, and only on a fresh conversation.prompt = _with_identity(prompt, identity, resume, compact=True)+ mode = normalize_permission("grok-cli", permission_mode)+ work = _resolved_cwd(cwd)+ if identity is not None:+ # grok has no --mcp-config; a project `.grok/config.toml` is how+ # print-mode actually sees Jarvis' tools (gmail, calendar, the rest).+ jarvis_harness.install_grok_jarvis_mcp(work, identity.session_id)argv = [*grok_argv_prefix(),"--no-auto-update",@@ -492,11 +498,17 @@ def plan_grok("--output-format","streaming-messages-json","--include-partial-messages",- "--permission-mode",- normalize_permission("grok-cli", permission_mode),"--cwd",- str(cwd),+ str(work),]+ if mode == "plan":+ argv += ["--permission-mode", "plan"]+ else:+ # Print-mode grok cannot answer a permission prompt. default and+ # acceptEdits therefore decline MCP tools (live Morning Briefing,+ # 2026-09-17: jarvis__gmail "Tool not found" / cancelled). Jarvis'+ # gateway still gates every call.+ argv += ["--always-approve"]if model:argv += ["-m", model]if effort:@@ -508,7 +520,9 @@ def plan_grok(sid = str(uuid.uuid4())argv += ["--session-id", sid]argv += ["-p", prompt]- return CliPlan(argv, _account_env("grok-build"), None, "claude", sid)+ env = jarvis_harness.apply_env(_account_env("grok-build"))+ env.setdefault("PYTHONIOENCODING", "utf-8")+ return CliPlan(argv, env, None, "claude", sid)#: agy's own model ids as of 1.1.19, for a box where ``agy models`` cannot be@@ -1085,7 +1099,8 @@ def _with_identity("actual blocker without claiming completion. Existing permission ""rules still apply.\n"+ CONVERSATIONAL_TURN_REMINDER- + "\n</jarvis_turn_context>\n\n" + prompt+ + "\n</jarvis_turn_context>\n\n"+ + prompt)return prompttext = identity.compact if compact else identity.textdiff --git a/tests/unit/agent_chat/test_chat_ide_separation.py b/tests/unit/agent_chat/test_chat_ide_separation.pyindex d4cb33201b..c07729b8d4 100644--- a/tests/unit/agent_chat/test_chat_ide_separation.py+++ b/tests/unit/agent_chat/test_chat_ide_separation.py@@ -63,7 +63,15 @@ def test_only_the_chat_package_hands_out_jarvis_tools():if module.parent.name == "agent_chat":continuetext = module.read_text(encoding="utf-8", errors="replace")- if "mcp_config_json" in text or "codex_config_args" in text:+ if any(+ name in text+ for name in (+ "mcp_config_json",+ "codex_config_args",+ "install_grok_jarvis_mcp",+ "grok_mcp_server_entry",+ )+ ):callers.append(str(module.relative_to(_ROOT)))assert callers == [], f"unexpected callers of the Jarvis MCP config: {callers}"diff --git a/tests/unit/agent_chat/test_jarvis_harness.py b/tests/unit/agent_chat/test_jarvis_harness.pyindex d2228a31bf..a7a0739edc 100644--- a/tests/unit/agent_chat/test_jarvis_harness.py+++ b/tests/unit/agent_chat/test_jarvis_harness.py@@ -7,6 +7,7 @@ spawned CLI is actually told.from __future__ import annotations+import jsonfrom dataclasses import dataclass, fieldfrom typing import Any@@ -141,6 +142,7 @@ def test_the_config_is_withheld_until_the_app_can_actually_serve_it(monkeypatch)assert jarvis_harness.mcp_config_json() is None # no base URL yetassert jarvis_harness.codex_config_args() == []assert jarvis_harness.agy_mcp_server_entry() is None+ assert jarvis_harness.grok_mcp_server_entry() is Nonemonkeypatch.setattr(jarvis_harness, "endpoint", lambda: "http://127.0.0.1:47821/api/control/mcp/"@@ -149,6 +151,7 @@ def test_the_config_is_withheld_until_the_app_can_actually_serve_it(monkeypatch)assert jarvis_harness.mcp_config_json() is None # no keyassert jarvis_harness.codex_config_args() == []assert jarvis_harness.agy_mcp_server_entry() is None+ assert jarvis_harness.grok_mcp_server_entry() is Nonedef test_the_key_travels_in_the_environment_never_in_argv(monkeypatch):@@ -158,10 +161,13 @@ def test_the_key_travels_in_the_environment_never_in_argv(monkeypatch):config = jarvis_harness.mcp_config_json() or ""codex_args = " ".join(jarvis_harness.codex_config_args())+ grok = jarvis_harness.grok_mcp_server_entry("sess-g") or {}assert "super-secret-key" not in configassert "super-secret-key" not in codex_args+ assert "super-secret-key" not in json.dumps(grok)assert "${JARVIS_CONTROL_API_KEY}" in configassert "bearer_token_env_var" in codex_args+ assert grok["bearer_token_env_var"] == jarvis_harness.KEY_ENV_VARenv = jarvis_harness.apply_env({})assert env["JARVIS_CONTROL_API_KEY"] == "super-secret-key"@@ -177,18 +183,25 @@ def test_both_cli_shapes_point_at_the_same_endpoint(monkeypatch):assert agy is not Noneassert url in agy["serverUrl"]assert agy["headers"][jarvis_harness.HEADER_NAME] == "sess-9"+ grok = jarvis_harness.grok_mcp_server_entry("sess-9")+ assert grok is not None+ assert url in grok["url"]+ assert grok["headers"][jarvis_harness.HEADER_NAME] == "sess-9"+++def test_the_preamble_names_the_prefix_the_tools_actually_get():+ """If the prefix drifts, the model is told to use tools it cannot see."""+ assert "`mcp__jarvis__<tool>`" in jarvis_harness.SYSTEM_PREAMBLE+ assert "`jarvis__<tool>`" in jarvis_harness.SYSTEM_PREAMBLE+ assert jarvis_harness._SERVER_NAME == "jarvis"def test_agy_plugin_is_skipped_when_the_app_is_not_ready(tmp_path, monkeypatch):monkeypatch.setattr(jarvis_harness, "control_key", lambda: None)assert jarvis_harness.install_agy_jarvis_plugin(tmp_path, "sess") is Noneassert not (tmp_path / ".agents").exists()---def test_the_preamble_names_the_prefix_the_tools_actually_get():- """If the prefix drifts, the model is told to use tools it cannot see."""- assert "mcp__jarvis__" in jarvis_harness.SYSTEM_PREAMBLE- assert jarvis_harness._SERVER_NAME == "jarvis"+ assert jarvis_harness.install_grok_jarvis_mcp(tmp_path, "sess") is None+ assert not (tmp_path / ".grok").exists()def test_claude_argv_carries_the_tools_and_the_identity(monkeypatch):diff --git a/tests/unit/agent_chat/test_jarvis_identity.py b/tests/unit/agent_chat/test_jarvis_identity.pyindex 140bd07001..3f7455189e 100644--- a/tests/unit/agent_chat/test_jarvis_identity.py+++ b/tests/unit/agent_chat/test_jarvis_identity.py@@ -189,6 +189,65 @@ def test_grok_takes_the_compact_identity_on_argv(monkeypatch, tmp_path: Path):)prompt = plan.argv[plan.argv.index("-p") + 1]assert prompt.startswith("<jarvis_identity>\nSHORT IDENTITY") and prompt.endswith("hi")+ assert "--always-approve" in plan.argv+ assert "--permission-mode" not in plan.argv+++def test_grok_plan_mode_does_not_auto_approve(monkeypatch, tmp_path: Path):+ monkeypatch.setattr(runner_cli, "grok_argv_prefix", lambda: ["grok"])+ plan = runner_cli.plan_grok(+ prompt="hi",+ cwd=tmp_path,+ model="",+ effort="",+ permission_mode="plan",+ resume=None,+ identity=_identity(tmp_path),+ )+ assert plan.argv[plan.argv.index("--permission-mode") + 1] == "plan"+ assert "--always-approve" not in plan.argv+++def test_grok_with_identity_writes_a_project_mcp_config(monkeypatch, tmp_path: Path):+ monkeypatch.setattr(runner_cli, "grok_argv_prefix", lambda: ["grok"])+ monkeypatch.setattr(runner_cli.jarvis_harness, "control_key", lambda: "k")+ runtime_refs.set_api_base_url("http://127.0.0.1:47821")+ (tmp_path / ".grok").mkdir()+ (tmp_path / ".grok" / "config.toml").write_text(+ '[mcp_servers.linear]\nurl = "https://mcp.linear.app/mcp"\n',+ encoding="utf-8",+ )+ plan = runner_cli.plan_grok(+ prompt="hi",+ cwd=tmp_path,+ model="",+ effort="",+ permission_mode="accept-edits",+ resume=None,+ identity=_identity(tmp_path),+ )+ config = (tmp_path / ".grok" / "config.toml").read_text(encoding="utf-8")+ assert "[mcp_servers.linear]" in config+ assert "https://mcp.linear.app/mcp" in config+ assert "[mcp_servers.jarvis]" in config+ assert config.count("[mcp_servers.jarvis]") == 1+ assert "/api/control/mcp/" in config+ assert 'bearer_token_env_var = "JARVIS_CONTROL_API_KEY"' in config+ assert "sess-1" in config+ assert plan.env["JARVIS_CONTROL_API_KEY"] == "k"+ # A second turn rewrites the Jarvis block instead of duplicating it.+ runner_cli.plan_grok(+ prompt="again",+ cwd=tmp_path,+ model="",+ effort="",+ permission_mode="accept-edits",+ resume=None,+ identity=_identity(tmp_path),+ )+ again = (tmp_path / ".grok" / "config.toml").read_text(encoding="utf-8")+ assert again.count("[mcp_servers.jarvis]") == 1+ assert "[mcp_servers.linear]" in againdef test_agy_takes_the_identity_on_stdin(monkeypatch, tmp_path: Path):