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
feat(agentic-ide): launch and account-switch any registered coding CLI
Ruben Lütkee9be938e2a24
diff --git a/jarvis/agent_accounts.py b/jarvis/agent_accounts.pyindex 53e6e5e8a1..4b875bf3ce 100644--- a/jarvis/agent_accounts.py+++ b/jarvis/agent_accounts.py@@ -1041,6 +1041,38 @@ def snapshots(platform: Platform) -> list[AccountSnapshot]:# ------------------------------------------------------------------- login+def _generic_login_argv(account: AgentAccount) -> list[str]:+ """The CLI's own sign-in command, built from what its entry declared.++ Raises the same honest ``FileNotFoundError`` the built-in paths do when the+ binary is missing, and an ``AccountError`` when the entry declares no login+ command at all — a CLI whose only sign-in lives inside its TUI cannot be+ driven from here, and saying so beats opening an empty terminal.+ """+ import shutil++ from jarvis.core.path_augment import ensure_cli_paths+ from jarvis.workspace import agents as workspace_agents++ entry = workspace_agents.get_agent(account.platform)+ spec = entry.account if entry is not None else None+ login_argv = tuple(getattr(spec, "login_argv", ()) or ())+ if entry is None or not login_argv:+ raise AccountError(+ f"{_display(account.platform)} has no sign-in command that can be "+ "started from here — open a pane and sign in inside it."+ )+ ensure_cli_paths()+ binary = shutil.which(entry.executable)+ if binary is None:+ hint = workspace_agents.install_command(entry.name)+ raise FileNotFoundError(+ f"{entry.display_name} is not installed"+ + (f" (run: {hint})." if hint else ".")+ )+ return [binary, *login_argv]++def start_login(account: AgentAccount) -> Any:"""Open the CLI's own sign-in flow POINTED AT this account's directory.diff --git a/jarvis/agentic_ide/resume_store.py b/jarvis/agentic_ide/resume_store.pyindex 61f31ad566..b5d9f0c81f 100644--- a/jarvis/agentic_ide/resume_store.py+++ b/jarvis/agentic_ide/resume_store.py@@ -119,7 +119,7 @@ def _account_home(agent: str, account_id: str | None) -> Path | None:try:from jarvis import agent_accounts- if agent not in agent_accounts.PLATFORMS:+ if agent not in agent_accounts.platforms():return Nonereturn agent_accounts.config_dir_for(agent, account_id) # type: ignore[arg-type]except Exception as exc: # noqa: BLE001 - the offer must never fail on thisdiff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.pyindex b45e5cae2f..ed56412c47 100644--- a/jarvis/agentic_ide/session.py+++ b/jarvis/agentic_ide/session.py@@ -102,7 +102,34 @@ if TYPE_CHECKING: # pragma: no cover - typing only## argv is built here rather than reused from jarvis.workspace.agents because the# IDE runs the agent as the PTY's OWN process, not inside a persistent shell.-AGENT_BINARIES: dict[str, str] = {"claude": "claude", "codex": "codex"}+AGENT_BINARIES: dict[str, str] = {+ a.name: a.executable for a in workspace_agents.coding_agents()+}+++def is_coding_agent(agent: str) -> bool:+ """Does ``agent`` run a coding CLI (as opposed to a bare shell)?++ Asks the registry rather than the snapshot above, so a CLI registered after+ this module was imported is not invisible to the one test that decides+ whether a pane may be typed into at all.+ """+ spec = workspace_agents.get_agent(agent)+ return spec is not None and spec.is_coding_agent+++def has_accounts(agent: str) -> bool:+ """Can this CLI hold several subscriptions the app can switch between?++ A DIFFERENT question from :func:`is_coding_agent`, and conflating the two is+ what the single membership test used to do. Every coding CLI can be typed+ into; only some publish a variable that moves their whole identity, and one+ that does not must never be offered an account switcher that would silently+ keep spending the same login.+ """+ from jarvis import agent_accounts++ return agent in agent_accounts.platforms()# A pane that runs the machine's own shell and nothing else — see `agent_argv`.# It is NOT in AGENT_BINARIES on purpose: it has no account, no conversation to@@ -142,10 +169,7 @@ def accepts_prompts(agent: str) -> bool:by voice. That is precisely the boundary the module docstring's rule 1 draws,and it is why a plain terminal is typed into by hand or not at all."""- if agent in AGENT_BINARIES:- return True- spec = workspace_agents.get_agent(agent)- return spec is not None and spec.is_coding_agent+ return is_coding_agent(agent)def _unavailable(agent: str) -> str:@@ -407,7 +431,7 @@ def resolve_account(agent: str, requested: str | None) -> str | None:to the active account rather than failing the pane: an unopenable pane is aworse answer than an honest default."""- if agent not in AGENT_BINARIES:+ if not has_accounts(agent):return Nonefrom jarvis import agent_accounts@@ -460,7 +484,7 @@ def _redirected_home(term: Terminal) -> Path | None:A path means the CLI has been redirected, which is what everything below hasto compensate for."""- if not term.account or term.agent not in AGENT_BINARIES:+ if not term.account or not has_accounts(term.agent):return Nonefrom jarvis import agent_accounts@@ -488,21 +512,71 @@ def _spawn_env(term: Terminal) -> dict[str, str] | None:before the spawn (:mod:`jarvis.agent_config_parity`), and only what a sharedsettings file cannot carry falls back to the narrow per-key mode mirror.+ On top of the account, the pane carries whatever the registry entry declares+ for EVERY pane of that CLI: a fixed environment (switching off an updater+ that would otherwise swap the binary mid-conversation) and, for an entry+ whose environment depends on user configuration, a factory resolved fresh+ here. A factory that answers ``None`` means "not configured" and raises,+ because the alternative is the quiet disaster: the one entry that needs this+ is a launch profile pointing a borrowed binary at a different vendor's+ endpoint, the binary reads that endpoint once at start-up and never mentions+ which one it got, so a pane launched without it answers perfectly well from+ the wrong vendor and bills the wrong account.+Filesystem work, so callers run it off the event loop."""- if _redirected_home(term) is None:- return Nonefrom jarvis import agent_accounts, agent_config_parity- report = agent_config_parity.ensure_parity(term.agent, term.account) # type: ignore[arg-type]- mode_file = agent_accounts.mode_file_name(term.agent) # type: ignore[arg-type]- # Only when the account's settings file IS the user's file does sharing it- # carry the mode too. A file the account has partly written itself was merely- # filled in with the keys it lacked, and the mode may well be one of the keys- # it already had — so the narrow per-key mirror still has work to do there.- if report.shared.get(str(mode_file)) not in {"mirrored", "current"}:- agent_accounts.inherit_default_mode(term.agent, term.account) # type: ignore[arg-type]- return agent_accounts.spawn_env(term.agent, term.account) # type: ignore[arg-type]+ env: dict[str, str] | None = None+ if _redirected_home(term) is not None:+ report = agent_config_parity.ensure_parity(term.agent, term.account) # type: ignore[arg-type]+ mode_file = agent_accounts.mode_file_name(term.agent) # type: ignore[arg-type]+ # Only when the account's settings file IS the user's file does sharing+ # it carry the mode too. A file the account has partly written itself was+ # merely filled in with the keys it lacked, and the mode may well be one+ # of the keys it already had — so the narrow per-key mirror still has+ # work to do there.+ if report.shared.get(str(mode_file)) not in {"mirrored", "current"}:+ agent_accounts.inherit_default_mode(term.agent, term.account) # type: ignore[arg-type]+ env = agent_accounts.spawn_env(term.agent, term.account) # type: ignore[arg-type]++ overlay = agent_spawn_overlay(term.agent)+ if not overlay:+ return env+ env = dict(os.environ if env is None else env)+ for key, value in overlay.items():+ # An empty value means "remove this variable from the child". A GLM pane+ # needs it: this host may well carry an ANTHROPIC_API_KEY for unrelated+ # reasons, it outranks the token being passed, and the result is the+ # silent wrong-vendor pane above.+ if value:+ env[key] = value+ else:+ env.pop(key, None)+ return env+++def agent_spawn_overlay(agent: str) -> dict[str, str]:+ """Per-CLI environment every pane of ``agent`` gets, resolved now.++ Raises :class:`SessionError` when the entry declares a factory and the+ factory reports the CLI is not configured. Refusing to open the pane is the+ point — see :func:`_spawn_env`.+ """+ spec = workspace_agents.get_agent(agent)+ if spec is None:+ return {}+ overlay = dict(spec.spawn_env)+ if spec.spawn_env_factory is None:+ return overlay+ resolved = spec.spawn_env_factory()+ if resolved is None:+ raise SessionError(+ f"{spec.display_name} is not configured yet — add its API key in "+ "Settings, then open the pane again."+ )+ overlay.update(resolved)+ return overlaydef account_home(agent: str, account_id: str | None) -> Path | None:@@ -511,7 +585,7 @@ def account_home(agent: str, account_id: str | None) -> Path | None:``None`` for a pane with no account (or an agent that has none), which keepsevery existing lookup on its old path."""- if not account_id or agent not in AGENT_BINARIES:+ if not account_id or not has_accounts(agent):return Nonefrom jarvis import agent_accounts@@ -526,16 +600,12 @@ def agent_argv(agent: str) -> tuple[str, ...] | None:``$SHELL`` first on macOS/Linux) — no agent wrapped around it, and None on ahost that has no shell at all, which reads the same as a missing binary."""- binary = AGENT_BINARIES.get(agent)- if binary is None:- spec = workspace_agents.get_agent(agent)- if spec is None:- return None- if not spec.is_coding_agent:- return workspace_agents.plain_terminal_argv()- # A CLI registered at runtime: run the command it declared, resolved- # through the same shim handling the built-in agents get below.- binary = spec.launch_command or spec.name+ spec = workspace_agents.get_agent(agent)+ if spec is None:+ return None+ if not spec.is_coding_agent:+ return workspace_agents.plain_terminal_argv()+ binary = spec.executable or spec.launch_command or spec.nametry:from jarvis.core.path_augment import ensure_cli_paths@@ -548,30 +618,46 @@ def agent_argv(agent: str) -> tuple[str, ...] | None:if sys.platform == "win32":lowered = exe.lower()if lowered.endswith((".cmd", ".bat")):- if agent == "codex":- from jarvis.core.path_augment import resolve_node_executable-- node = resolve_node_executable()- codex_js = (- Path(exe).resolve().parent- / "node_modules"- / "@openai"- / "codex"- / "bin"- / "codex.js"- )- if node and codex_js.is_file():- return (node, str(codex_js))+ if (direct := _behind_win_shim(spec, exe)) is not None:+ return (*direct, *spec.launch_args)# ConPTY cannot exec a batch shim. `cmd /c` (never /k) exits with# the agent, so no shell survives it.comspec = os.environ.get("COMSPEC") or "cmd.exe"- return (comspec, "/c", exe)+ return (comspec, "/c", exe, *spec.launch_args)if lowered.endswith(".ps1"):shell = shutil.which("pwsh") or shutil.which("powershell")if shell is None:return None- return (shell, "-NoLogo", "-NoProfile", "-File", exe)- return (exe,)+ return (shell, "-NoLogo", "-NoProfile", "-File", exe, *spec.launch_args)+ return (exe, *spec.launch_args)+++def _behind_win_shim(+ spec: workspace_agents.WorkspaceAgent, shim: str+) -> tuple[str, ...] | None:+ """What the Windows ``.cmd`` shim would have launched, launched directly.++ ``cmd /c <shim>`` works and stays the fallback, but it wedges a second+ process between the pane and the agent, which costs clean signal delivery+ and a clean exit. When the entry declares where the real thing sits inside+ the installed package we skip the shim entirely.++ Two shapes exist and the entry says which: a Node script that needs+ ``node.exe`` in front of it, and a native executable that is simply run.+ ``None`` whenever the declared path is not actually there — an install+ laid out differently than expected must fall back, never fail.+ """+ if spec.win_shim is None:+ return None+ target = Path(shim).resolve().parent.joinpath(*spec.win_shim.relative_path)+ if not target.is_file():+ return None+ if spec.win_shim.kind == "exe":+ return (str(target),)+ from jarvis.core.path_augment import resolve_node_executable++ node = resolve_node_executable()+ return (node, str(target)) if node else None@dataclass(slots=True)@@ -947,7 +1033,7 @@ class Registry:login rather than to nothing (``resolve_account`` owns that fallback).``None`` only for something that is not a coding CLI with accounts."""- if agent not in AGENT_BINARIES:+ if not has_accounts(agent):return Nonereturn resolve_account(agent, self._active_accounts.get(agent))@@ -962,7 +1048,7 @@ class Registry:from jarvis import agent_accountsrows: list[dict[str, Any]] = []- for agent in AGENT_BINARIES:+ for agent in agent_accounts.platforms():account_id = self.active_account_id(agent)rows.append({@@ -987,8 +1073,8 @@ class Registry:survives a restart and the app's own account page cannot end updisagreeing with the workspace about which seat is in use."""- if agent not in AGENT_BINARIES:- raise SessionError(f"Unknown agent: {agent}")+ if not has_accounts(agent):+ raise SessionError(f"{agent} has no switchable subscriptions.")from jarvis import agent_accountsaccount = await asyncio.to_thread(agent_accounts.resolve, account_id)diff --git a/jarvis/core/path_augment.py b/jarvis/core/path_augment.pyindex ce289f742b..c79266fa7b 100644--- a/jarvis/core/path_augment.py+++ b/jarvis/core/path_augment.py@@ -107,9 +107,34 @@ def _windows_candidates() -> list[str]:return dirs+def _registered_agent_dirs() -> list[str]:+ """Install dirs contributed by registered coding-CLI entries.++ A CLI whose own installer drops the binary somewhere the platform lists are+ not going to guess (``~/.local/bin`` on a GUI-launched macOS process, for+ one) says so on its registry entry rather than earning a line in the+ platform tables here — which would put product knowledge in a module that+ has no business holding any.++ Failures are swallowed: PATH augmentation is best-effort by contract, and a+ registry that cannot be imported must not take the whole lookup with it.+ """+ try:+ from jarvis.workspace import agents as workspace_agents++ return [+ os.path.expanduser(d)+ for agent in workspace_agents.coding_agents()+ for d in agent.extra_path_dirs+ ]+ except Exception: # noqa: BLE001 - see docstring+ return []++def candidate_dirs() -> list[str]:"""The platform's well-known CLI install dirs (existing or not)."""- return _windows_candidates() if sys.platform == "win32" else _posix_candidates()+ base = _windows_candidates() if sys.platform == "win32" else _posix_candidates()+ return [*base, *_registered_agent_dirs()]def ensure_cli_paths() -> list[str]:diff --git a/jarvis/ui/web/agent_accounts_routes.py b/jarvis/ui/web/agent_accounts_routes.pyindex 66e775efec..076bb47e04 100644--- a/jarvis/ui/web/agent_accounts_routes.py+++ b/jarvis/ui/web/agent_accounts_routes.py@@ -24,7 +24,7 @@ from fastapi import APIRouter, HTTPExceptionfrom pydantic import BaseModel, Fieldfrom jarvis import agent_accounts-from jarvis.agent_accounts import MAX_LABEL_CHARS, PLATFORMS, AccountError+from jarvis.agent_accounts import MAX_LABEL_CHARS, AccountError, platformsfrom jarvis.core.interactive_terminal import InteractiveTerminalUnavailablelog = logging.getLogger(__name__)@@ -33,7 +33,13 @@ router = APIRouter(prefix="/api/agent-accounts", tags=["agent-accounts"])class AccountCreateRequest(BaseModel):- platform: str = Field(description="Which coding CLI: 'claude' or 'codex'.")+ platform: str = Field(+ description=(+ "Which coding CLI this seat belongs to. The accepted values are "+ "whichever CLIs this build can switch logins for; GET this "+ "endpoint to see them."+ )+ )label: str = Field(max_length=MAX_LABEL_CHARS,description="Display name for this subscription, e.g. 'Work seat'.",@@ -47,15 +53,21 @@ class AccountRenameRequest(BaseModel):class ActiveRequest(BaseModel):- platform: str = Field(description="Which coding CLI to switch: 'claude' or 'codex'.")+ platform: str = Field(+ description=(+ "Which coding CLI to switch. GET this endpoint for the accepted "+ "values on this build."+ )+ )account_id: str = Field(description="Id of the account new terminals should use.")def _platform(value: str) -> str:- if value not in PLATFORMS:+ known = platforms()+ if value not in known:raise HTTPException(status_code=422,- detail=f"Unknown platform {value!r}. Known: {', '.join(PLATFORMS)}.",+ detail=f"Unknown platform {value!r}. Known: {', '.join(known)}.",)return value@@ -69,7 +81,7 @@ def _collect() -> dict[str, Any]:"active_account": agent_accounts.active_account(platform).id,"accounts": [s.to_dict() for s in agent_accounts.snapshots(platform)],}- for platform in PLATFORMS+ for platform in platforms()]}diff --git a/jarvis/workspace/agents.py b/jarvis/workspace/agents.pyindex d587383b09..c2087d78b3 100644--- a/jarvis/workspace/agents.py+++ b/jarvis/workspace/agents.py@@ -526,18 +526,23 @@ _AGENTS: dict[str, WorkspaceAgent] = {needs_trust=False,# Its update preflight can check, install and PROMPT mid-session.spawn_env=(("KIMI_CODE_NO_AUTO_UPDATE", "1"),),- account=AccountSpec(- # ONE variable moves config, sessions and credentials together,- # which is the cleanest multi-seat override of any entry here.- env=(("KIMI_CODE_HOME", "{dir}"),),- native_dir="~/.kimi-code",- # Deliberately no login markers: this CLI's credential file layout- # has not been verified against a live install, and guessing one- # would make a signed-in seat read as signed-out. Switching seats- # works; the sign-in dot honestly says it cannot tell.- login_markers=(),- login_argv=("login",),- ),+ # DELIBERATELY no AccountSpec — several seats of this CLI are not+ # offered yet, and the reason is worth writing down because the data to+ # enable it looks complete: ``KIMI_CODE_HOME`` really does move the whole+ # data root. Three things stop it being honest today.+ #+ # 1. The wound-down generation does not read that variable at all. On a+ # machine that has it — including the one this was written on — every+ # "separate" seat would quietly resolve to the same login, and the+ # switcher would report a switch that did not happen.+ # 2. Its configuration and its credentials live in the SAME file, so+ # there is no subset of setup that can be carried to a new seat+ # without carrying the key with it.+ # 3. Its credential layout has not been verified against a live install,+ # so a sign-in indicator here would be a guess.+ #+ # A seat switcher that silently spends one login is worse than none.+ # Tracked in docs/os-parity.md.# Its own installer drops the binary here, which is not on the PATH a# GUI-launched process inherits on macOS or Linux.extra_path_dirs=("~/.local/bin",),diff --git a/tests/unit/test_agent_accounts.py b/tests/unit/test_agent_accounts.pyindex f647657c79..9c349caeff 100644--- a/tests/unit/test_agent_accounts.py+++ b/tests/unit/test_agent_accounts.py@@ -37,7 +37,7 @@ def _isolated_store(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:def test_every_platform_offers_its_builtin_account_with_no_store() -> None:"""A fresh install has one usable account per CLI and no file at all."""- for platform in agent_accounts.PLATFORMS:+ for platform in agent_accounts.platforms():accounts = agent_accounts.list_accounts(platform)assert len(accounts) == 1assert accounts[0].builtin is Truediff --git a/tests/unit/test_agent_config_parity.py b/tests/unit/test_agent_config_parity.pyindex 2a03d38007..ae59c8713a 100644--- a/tests/unit/test_agent_config_parity.py+++ b/tests/unit/test_agent_config_parity.py@@ -185,13 +185,18 @@ def test_every_cli_that_can_be_redirected_has_a_setup_allowlist() -> None:"""A CLI gains accounts, and its panes silently lose the user's setup again.That is how this bug arrives a second time: redirecting a config dir is one- line in ``agent_accounts.ENV_VAR``, while carrying the user's setup across is- a table somebody has to remember. The two must not be able to drift apart —- so a platform with an override and no allowlist fails here rather than in- somebody's terminal six months from now.+ ``AccountSpec`` on a registry entry, while carrying the user's setup across+ is a table somebody has to remember. The two must not be able to drift+ apart — so a platform with an override and no allowlist fails here rather+ than in somebody's terminal six months from now.++ This is also the gate that decides whether a NEW coding CLI may offer+ several seats at all: if nothing of its setup can be shared safely (a CLI+ that keeps its configuration and its key in one file), it must not declare+ an override in the first place."""- for platform in agent_accounts.PLATFORMS:- assert platform in agent_accounts.ENV_VAR+ for platform in agent_accounts.platforms():+ assert agent_accounts.env_var(platform)entries = agent_config_parity.USER_SETUP.get(platform)assert entries, f"{platform} can be redirected but shares nothing back"# Every entry is one the CLI reads; nothing that identifies the account.