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(brain): registry commands become flat tools — the umbrella interface failed live

Ruben Lütke4b994431b8ea
diff --git a/docs/adr/0011-router-pure-dispatcher.md b/docs/adr/0011-router-pure-dispatcher.md
index 790fe2e842..b4ac32d53e 100644
--- a/docs/adr/0011-router-pure-dispatcher.md
+++ b/docs/adr/0011-router-pure-dispatcher.md
@@ -802,3 +802,20 @@ remains as fallback for actions outside the registry.
ASGI execution against a fake app, dangerous→ask escalation, server-response
readback, honest no-server error.
- `tests/unit/commands/test_registry_parity.py` — registry↔OpenAPI/UI parity.
+
+### Addendum (2026-07-11) — umbrella interface replaced by flat expansion
+
+The original `app-command` design (ONE tool, nested `command_id` + `args`)
+failed its first live test: the router LLM read the command list in the
+tool description and called `provider-test` AS A TOOL NAME — "tool
+'provider-test' not in the router tool set", spoken error. Flash-class
+routers flatten nested dispatch interfaces; the repo's own CLI/MCP loaders
+already solved this shape. `app-command` is therefore now a **virtual
+loader** (the `cli-tools` pattern): the ROUTER_TOOLS entry gates the loader,
+`expand()` registers one flat tool per registry command (`brain-switch`,
+`provider-test`, `wake-word-set`, …), each carrying the command's own params
+schema and risk tier (`ask` when dangerous, else `monitor`). Validation,
+ASGI execution, and echo-verify readback are unchanged. Guards:
+`test_factory_wires_registry_command_tools_into_router_set`,
+`tests/unit/plugins/tool/test_app_command.py` (loader expansion + flat
+schemas + the provider-test regression).
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index dbeb3ae1e6..5ab6b0d2b7 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -1649,28 +1649,32 @@ _SELF_CONTROL_NOUN_RE = re.compile(
# that claiming without calling is forbidden. The keyworded directive stays
# as the detailed intensifier.
_SELF_CONTROL_STANDING = (
- "SELF-CONTROL (always in effect): When the user asks you to change "
- "anything about Jarvis itself — name/wake phrase, voice, volume, "
+ "SELF-CONTROL (always in effect): When the user asks you to change or "
+ "check anything about Jarvis itself — wake phrase, voice, volume, "
"providers, languages, settings, restart, missions/tasks — you CAN do it "
- "yourself: prefer the `app-command` tool (validated registry commands), "
- "`set_config_value` for a plain config key, `cli_jarvisctl` as fallback. "
- "NEVER state or imply that a change or action happened unless a tool "
- "call actually returned success in THIS turn; without such a result, say "
- "honestly that you have not done it yet."
+ "yourself with the registry command tools in your tool set (e.g. "
+ "`wake-word-set`, `brain-switch`, `provider-test`, `tts-volume-set`, "
+ "`app-restart`); `set_config_value` covers a plain config key, "
+ "`cli_jarvisctl` is the fallback for anything not covered. NEVER state "
+ "or imply that a change or action happened unless a tool call actually "
+ "returned success in THIS turn; without such a result, say honestly that "
+ "you have not done it yet."
)
_SELF_CONTROL_DIRECTIVE = (
"SELF-CONTROL: The user is asking to change or control Jarvis's OWN settings, "
"configuration, providers, voice, language, or behavior. You have full "
- "control over this. PREFER the `app-command` tool — it runs a validated "
- "registry command (provider switches, wake word, languages, volume, "
- "missions/tasks, restart) with schema-checked arguments, so it cannot hit "
- "the wrong target. For a simple config key use `set_config_value`; only "
- "for actions NOT covered by either, fall back to the `cli_jarvisctl` tool "
- "(e.g. `jarvisctl config set <key> <value>`). NEVER say you lack access "
- "or permission to change a Jarvis setting, and never claim the change "
- "without actually calling the tool: call it and confirm success only "
- "AFTER it returns, using the values the tool actually reports."
+ "control over this. PREFER the registry command tools — `brain-switch`, "
+ "`tts-switch`, `provider-test`, `wake-word-set`, `reply-language-set`, "
+ "`tts-volume-set`, `app-restart`, `missions-list`, `task-cancel`, … — "
+ "each validates its arguments against the app's own endpoint, so it "
+ "cannot hit the wrong target. For a simple config key use "
+ "`set_config_value`; only for actions NOT covered by either, fall back "
+ "to the `cli_jarvisctl` tool (e.g. `jarvisctl config set <key> "
+ "<value>`). NEVER say you lack access or permission to change a Jarvis "
+ "setting, and never claim the change without actually calling the tool: "
+ "call it and confirm success only AFTER it returns, using the values the "
+ "tool actually reports."
)
diff --git a/jarvis/plugins/tool/app_command.py b/jarvis/plugins/tool/app_command.py
index ac780b6a97..03882090c3 100644
--- a/jarvis/plugins/tool/app_command.py
+++ b/jarvis/plugins/tool/app_command.py
@@ -1,23 +1,28 @@
-"""``app-command`` — execute a Command-Registry command by voice/chat.
-
-Router-tier. The ONE structured path for the LLM to drive app settings and
-actions: the command id is enum-constrained to the curated registry
-(``jarvis/commands/registry.py``), arguments are validated against the
-command's JSON schema BEFORE anything is sent, and execution goes through the
-SAME already-mounted REST endpoint the desktop UI uses (in-process ASGI
-transport — full route validation, no TCP). A voice command therefore can
-never behave differently from the UI button for the same action, and the
-readback the brain speaks is composed from the SERVER RESPONSE (what actually
-changed), never from the model's intent — echo-verify.
-
-Dangerous commands (registry ``dangerous: true``) surface as risk tier
-``ask`` via ``risk_tier_for_args``, which triggers the ToolExecutor's
-two-turn spoken confirmation; everything else runs at ``monitor`` (audited,
-reversible, no friction).
+"""Registry command tools — one flat tool per Command-Registry entry.
+
+Virtual loader (the ``cli-tools`` pattern): the ``app-command`` entry point
+expands into ONE tool per curated command in ``jarvis/commands/registry.py``
+— ``brain-switch``, ``provider-test``, ``wake-word-set``, … — each with the
+command's own flat JSON schema.
+
+Why flat tools and not one umbrella tool with a nested ``command_id``+
+``args`` interface: the umbrella design was tried first and failed live
+(forensic 2026-07-11 11:38): the router LLM read the command list in the
+umbrella's description and called ``provider-test`` AS A TOOL NAME —
+"tool 'provider-test' not in the router tool set" — spoken error. Flash-class
+routers handle many small flat schemas far better than one nested dispatch
+schema, and the repo already loads CLI/MCP tools exactly this way.
+
+Every tool still validates its arguments against the registry schema BEFORE
+anything is sent, and executes through the SAME already-mounted REST endpoint
+the desktop UI uses (in-process ASGI transport — full route validation, no
+TCP). The readback is composed from the SERVER RESPONSE (echo-verify), never
+from the model's intent. Dangerous registry commands carry risk tier ``ask``
+(ToolExecutor two-turn voice confirmation); the rest run at ``monitor``.
Security: the registry contains no raw-secret writes (AP-2) and no spawn
-commands (mission dispatch stays with the dedicated spawn-worker tool,
-AP-5/AP-14) — this tool must never enter a worker tool set.
+commands (mission dispatch stays with spawn-worker, AP-5/AP-14) — these
+tools must never enter a worker tool set.
"""
from __future__ import annotations
@@ -96,11 +101,8 @@ def _summarize(title: str, data: Any) -> str:
return f"{title} succeeded."
-class AppCommandTool:
- """Execute a curated app command through its REST endpoint, in-process."""
-
- name: str = "app-command"
- risk_tier: str = "monitor"
+class _Runtime:
+ """Shared execution plumbing: resolve the live app + control key once."""
def __init__(
self,
@@ -113,54 +115,8 @@ class AppCommandTool:
self._app_resolver = app_resolver
self._control_key_resolver = control_key_resolver
self._transport = transport
- from jarvis.commands.registry import get_registry
-
- commands = get_registry()
- lines = "\n".join(
- f"- {c.id}: {c.description}" + (" [requires confirmation]" if c.dangerous else "")
- for c in commands
- )
- self.description = (
- "Run ONE app command from the command registry — the structured, "
- "validated way to change app settings or query app state by "
- "voice/chat (provider switches, wake word, languages, volume, "
- "missions/tasks, restart). Pass the command id in 'command_id' and "
- "its arguments in 'args' (see each command's schema via GET "
- "/api/commands). Prefer this over composing raw CLI strings. "
- "Commands:\n" + lines
- )
- self.schema: dict[str, Any] = {
- "type": "object",
- "properties": {
- "command_id": {
- "type": "string",
- "enum": [c.id for c in commands],
- "description": "The registry command to execute.",
- },
- "args": {
- "type": "object",
- "description": (
- "Arguments for the command, matching its params schema "
- "(e.g. {\"provider\": \"claude-api\"} for brain-switch)."
- ),
- },
- },
- "required": ["command_id"],
- }
-
- # ------------------------------------------------------------------
- # Risk refinement: dangerous registry commands need the two-turn confirm.
- # ------------------------------------------------------------------
- def risk_tier_for_args(self, args: dict[str, Any]) -> str:
- from jarvis.commands.registry import get_command
- cmd = get_command(str(args.get("command_id", "")))
- if cmd is None:
- return self.risk_tier
- return "ask" if cmd.dangerous else self.risk_tier
-
- # ------------------------------------------------------------------
- def _resolve_transport(self) -> Any | None:
+ def resolve_transport(self) -> Any | None:
if self._transport is not None:
return self._transport
from jarvis.core import runtime_refs
@@ -175,7 +131,7 @@ class AppCommandTool:
return httpx.ASGITransport(app=app)
- def _control_key(self) -> str | None:
+ def control_key(self) -> str | None:
if self._control_key_resolver is not None:
return self._control_key_resolver()
try:
@@ -185,27 +141,31 @@ class AppCommandTool:
except Exception: # noqa: BLE001 - most routes need no auth; degrade
return None
- async def execute(self, args: dict[str, Any], ctx: Any) -> ToolResult:
- from jarvis.commands.registry import get_command, get_registry
- command_id = str(args.get("command_id", ""))
- cmd = get_command(command_id)
- if cmd is None:
- return ToolResult(
- success=False,
- output={"requested": command_id},
- error=(
- f"Unknown command id {command_id!r}. Valid ids: "
- + ", ".join(c.id for c in get_registry())
- ),
- )
+class RegistryCommandTool:
+ """One registry command as a flat, schema-validated brain tool."""
- cmd_args = args.get("args") or {}
- if not isinstance(cmd_args, dict):
- return ToolResult(
- success=False, output=None,
- error="'args' must be an object of command arguments.",
- )
+ def __init__(self, command: Any, runtime: _Runtime) -> None:
+ self._cmd = command
+ self._runtime = runtime
+ self.name: str = command.id
+ self.risk_tier: str = "ask" if command.dangerous else "monitor"
+ note = (
+ " Requires the user's spoken confirmation before it runs."
+ if command.dangerous else ""
+ )
+ self.description: str = (
+ f"{command.description}{note} Executes the app's own validated "
+ f"endpoint ({command.method} {command.path}); report the result "
+ "the tool returns, never your assumption."
+ )
+ self.schema: dict[str, Any] = command.params or {
+ "type": "object", "properties": {},
+ }
+
+ async def execute(self, args: dict[str, Any], ctx: Any) -> ToolResult:
+ cmd = self._cmd
+ cmd_args = dict(args or {})
problems = _validate_args(cmd.params, cmd_args)
if problems:
return ToolResult(
@@ -224,7 +184,7 @@ class AppCommandTool:
"{" + p + "}", quote(str(payload.pop(p)), safe="")
)
- transport = self._resolve_transport()
+ transport = self._runtime.resolve_transport()
if transport is None:
return ToolResult(
success=False, output=None,
@@ -237,7 +197,7 @@ class AppCommandTool:
import httpx
headers = {}
- key = self._control_key()
+ key = self._runtime.control_key()
if key:
headers["Authorization"] = f"Bearer {key}"
try:
@@ -278,3 +238,29 @@ class AppCommandTool:
"response": data,
},
)
+
+
+class AppCommandTool:
+ """Virtual loader: expands the Command Registry into flat brain tools.
+
+ Registered under the ``app-command`` entry point (gated by ROUTER_TOOLS);
+ the factory calls :meth:`expand` and registers the returned per-command
+ tools — the loader itself never appears in the LLM tool set.
+ """
+
+ name: str = "app-command"
+ risk_tier: str = "monitor"
+ is_virtual_loader: bool = True
+
+ def __init__(
+ self,
+ app_resolver: Any | None = None,
+ control_key_resolver: Any | None = None,
+ transport: Any | None = None,
+ ) -> None:
+ self._runtime = _Runtime(app_resolver, control_key_resolver, transport)
+
+ def expand(self) -> list[RegistryCommandTool]:
+ from jarvis.commands.registry import get_registry
+
+ return [RegistryCommandTool(cmd, self._runtime) for cmd in get_registry()]
diff --git a/tests/unit/brain/test_routing.py b/tests/unit/brain/test_routing.py
index 5fdbb4ec7f..8406040b37 100644
--- a/tests/unit/brain/test_routing.py
+++ b/tests/unit/brain/test_routing.py
@@ -884,11 +884,15 @@ def test_factory_wires_navigate_into_router_set() -> None:
assert tools["navigate"].risk_tier == "safe"
-def test_factory_wires_app_command_into_router_set() -> None:
- """End-to-end wiring for the app-command tool: entry-point + ROUTER_TOOLS +
- default construction. A missing entry-point line or a failing registry
- import would silently drop the Command Registry from the router schema."""
+def test_factory_wires_registry_command_tools_into_router_set() -> None:
+ """End-to-end wiring for the Command-Registry tools: entry-point +
+ ROUTER_TOOLS gate the `app-command` VIRTUAL LOADER, which expands into one
+ flat tool per registry command (forensic 2026-07-11: the earlier umbrella
+ tool failed live — the LLM called `provider-test` as a tool name). A
+ missing entry-point line or a failing registry import would silently drop
+ every command from the router schema."""
from jarvis.brain.factory import _load_tools_for_tier
+ from jarvis.commands.registry import get_registry
tools = _load_tools_for_tier(
"router",
@@ -900,19 +904,13 @@ def test_factory_wires_app_command_into_router_set() -> None:
config=JarvisConfig(),
)
- assert "app-command" in tools
- tool = tools["app-command"]
- assert tool.name == "app-command"
- assert tool.risk_tier == "monitor"
- # Dangerous registry commands escalate to the two-turn confirm tier.
- assert tool.risk_tier_for_args({"command_id": "app-restart"}) == "ask"
- assert tool.risk_tier_for_args({"command_id": "brain-switch"}) == "monitor"
- # The command ids the LLM may pick are enum-pinned to the registry.
- from jarvis.commands.registry import get_registry
-
- assert set(tool.schema["properties"]["command_id"]["enum"]) == {
- c.id for c in get_registry()
- }
+ # The loader itself never reaches the LLM tool set — only its expansion.
+ assert "app-command" not in tools
+ for cmd in get_registry():
+ assert cmd.id in tools, f"registry command {cmd.id} missing from router set"
+ assert tools[cmd.id].risk_tier == ("ask" if cmd.dangerous else "monitor")
+ # The exact live failure: `provider-test` must BE a callable tool now.
+ assert "provider-test" in tools
def test_inspect_pointer_is_not_a_spawn_in_local_action_set() -> None:
diff --git a/tests/unit/brain/test_self_control_standing.py b/tests/unit/brain/test_self_control_standing.py
index 485b6ccc47..9f4b2466b5 100644
--- a/tests/unit/brain/test_self_control_standing.py
+++ b/tests/unit/brain/test_self_control_standing.py
@@ -42,7 +42,10 @@ def test_standing_line_present_without_keyword_directive() -> None:
def test_standing_line_names_the_structured_path_and_forbids_claiming() -> None:
- assert "app-command" in _SELF_CONTROL_STANDING
+ # Flat registry tools (post-2026-07-11 rework): the line must name real
+ # callable tool names, not the retired `app-command` umbrella interface.
+ assert "brain-switch" in _SELF_CONTROL_STANDING
+ assert "wake-word-set" in _SELF_CONTROL_STANDING
low = _SELF_CONTROL_STANDING.lower()
# The anti-"said it, did nothing" rule, in plain words.
assert "never" in low
diff --git a/tests/unit/plugins/tool/test_app_command.py b/tests/unit/plugins/tool/test_app_command.py
index 38c26efa35..478eb9ec45 100644
--- a/tests/unit/plugins/tool/test_app_command.py
+++ b/tests/unit/plugins/tool/test_app_command.py
@@ -1,10 +1,18 @@
-"""app-command tool: enum/schema validation, in-process ASGI execution,
-server-response readback (echo-verify), and honest degradation."""
+"""Registry command tools: virtual-loader expansion, flat per-command schema
+validation, in-process ASGI execution, server-response readback (echo-verify),
+and honest degradation.
+
+The flat-tools design is load-bearing (forensic 2026-07-11): the earlier
+umbrella tool (one `app-command` with nested command_id+args) failed live —
+the router LLM called `provider-test` AS a tool name and got "not in the
+router tool set". Each registry command is therefore its own tool.
+"""
from __future__ import annotations
import httpx
from fastapi import FastAPI, HTTPException
+from jarvis.commands.registry import get_registry
from jarvis.plugins.tool.app_command import AppCommandTool, _validate_args
@@ -35,30 +43,41 @@ def _fake_app(calls: dict) -> FastAPI:
return app
-def _tool(calls: dict | None = None) -> AppCommandTool:
+def _tools(calls: dict | None = None) -> dict[str, object]:
app = _fake_app(calls if calls is not None else {})
- return AppCommandTool(
+ loader = AppCommandTool(
transport=httpx.ASGITransport(app=app),
control_key_resolver=lambda: None,
)
+ return {t.name: t for t in loader.expand()}
-async def test_unknown_command_id_rejected_nothing_sent() -> None:
- calls: dict = {}
- result = await _tool(calls).execute({"command_id": "wipe-disk"}, None)
- assert result.success is False
- assert "Unknown command id" in (result.error or "")
- assert "brain-switch" in (result.error or "") # teaches valid ids
- assert calls == {}
+def test_loader_expands_one_flat_tool_per_registry_command() -> None:
+ loader = AppCommandTool(control_key_resolver=lambda: None)
+ assert loader.is_virtual_loader is True
+ tools = {t.name: t for t in loader.expand()}
+ assert set(tools) == {c.id for c in get_registry()}
+ # Flat schemas: the tool schema IS the command's params schema — no
+ # nested command_id/args indirection for the LLM to fumble.
+ brain = tools["brain-switch"]
+ assert "provider" in brain.schema["properties"]
+ assert "command_id" not in brain.schema["properties"]
+
+
+def test_dangerous_commands_carry_ask_tier() -> None:
+ tools = _tools()
+ assert tools["app-restart"].risk_tier == "ask"
+ assert tools["mission-cancel"].risk_tier == "ask"
+ assert tools["task-cancel"].risk_tier == "ask"
+ assert tools["brain-switch"].risk_tier == "monitor"
+ assert tools["wake-word-get"].risk_tier == "monitor"
async def test_enum_violation_rejected_nothing_sent() -> None:
"""The exact 'switches to something completely different' failure mode:
a provider outside the catalog must be rejected BEFORE any request."""
calls: dict = {}
- result = await _tool(calls).execute(
- {"command_id": "brain-switch", "args": {"provider": "skynet"}}, None
- )
+ result = await _tools(calls)["brain-switch"].execute({"provider": "skynet"}, None)
assert result.success is False
assert "must be one of" in (result.error or "")
assert calls == {}
@@ -66,14 +85,12 @@ async def test_enum_violation_rejected_nothing_sent() -> None:
async def test_missing_required_and_unknown_args_rejected() -> None:
calls: dict = {}
- tool = _tool(calls)
- result = await tool.execute({"command_id": "brain-switch", "args": {}}, None)
+ tools = _tools(calls)
+ result = await tools["brain-switch"].execute({}, None)
assert result.success is False
assert "missing required argument" in (result.error or "")
- result = await tool.execute(
- {"command_id": "wake-word-get", "args": {"nonsense": 1}}, None
- )
+ result = await tools["wake-word-get"].execute({"nonsense": 1}, None)
assert result.success is False
assert "unknown argument" in (result.error or "")
assert calls == {}
@@ -81,8 +98,8 @@ async def test_missing_required_and_unknown_args_rejected() -> None:
async def test_post_executes_and_readback_uses_server_response() -> None:
calls: dict = {}
- result = await _tool(calls).execute(
- {"command_id": "brain-switch", "args": {"provider": "openrouter"}}, None
+ result = await _tools(calls)["brain-switch"].execute(
+ {"provider": "openrouter"}, None
)
assert result.success is True
assert calls["brain_switch"]["provider"] == "openrouter"
@@ -93,35 +110,30 @@ async def test_post_executes_and_readback_uses_server_response() -> None:
async def test_path_param_substitution() -> None:
calls: dict = {}
- result = await _tool(calls).execute(
- {"command_id": "task-cancel", "args": {"task_id": "t-42"}}, None
- )
+ result = await _tools(calls)["task-cancel"].execute({"task_id": "t-42"}, None)
assert result.success is True
assert calls["cancel_task"] == "t-42"
async def test_get_command_works() -> None:
- result = await _tool().execute({"command_id": "wake-word-get"}, None)
+ result = await _tools()["wake-word-get"].execute({}, None)
assert result.success is True
assert result.output["response"]["phrase"] == "jarvis"
async def test_http_error_surfaces_detail() -> None:
- result = await _tool().execute(
- {"command_id": "tts-switch", "args": {"provider": "elevenlabs"}}, None
- )
+ result = await _tools()["tts-switch"].execute({"provider": "elevenlabs"}, None)
assert result.success is False
assert "HTTP 409" in (result.error or "")
assert "no key stored" in (result.error or "")
async def test_no_server_available_is_honest() -> None:
- tool = AppCommandTool(
+ loader = AppCommandTool(
app_resolver=lambda: None, control_key_resolver=lambda: None
)
- result = await tool.execute(
- {"command_id": "brain-switch", "args": {"provider": "openrouter"}}, None
- )
+ tools = {t.name: t for t in loader.expand()}
+ result = await tools["brain-switch"].execute({"provider": "openrouter"}, None)
assert result.success is False
assert "not available" in (result.error or "")
@@ -145,19 +157,9 @@ def test_validator_covers_types_and_ranges() -> None:
assert _validate_args(schema, {}) # missing required
-async def test_dangerous_command_escalates_to_ask_tier() -> None:
- tool = _tool()
- assert tool.risk_tier == "monitor"
- assert tool.risk_tier_for_args({"command_id": "app-restart"}) == "ask"
- assert tool.risk_tier_for_args({"command_id": "mission-cancel"}) == "ask"
- assert tool.risk_tier_for_args({"command_id": "brain-switch"}) == "monitor"
- assert tool.risk_tier_for_args({"command_id": "nope"}) == "monitor"
-
-
async def test_end_to_end_against_real_webserver_app() -> None:
- """The full chain: registry command -> ASGI -> the REAL /api/brain/switch
- route (shared app_control validation) -> readback from the route's
- response. Uses a fake live brain on app.state."""
+ """The full chain: flat tool -> ASGI -> the REAL /api/brain/switch route
+ (shared app_control validation) -> readback from the route's response."""
from jarvis.core import config as cfg_mod
from jarvis.core.bus import EventBus
from jarvis.core.config import JarvisConfig
@@ -184,14 +186,13 @@ async def test_end_to_end_against_real_webserver_app() -> None:
"sk-test" if key == "openrouter_api_key" else None
)
try:
- tool = AppCommandTool(
+ loader = AppCommandTool(
transport=httpx.ASGITransport(app=server.app),
control_key_resolver=lambda: None,
)
- result = await tool.execute(
- {"command_id": "brain-switch",
- "args": {"provider": "openrouter", "persist": False}},
- None,
+ tools = {t.name: t for t in loader.expand()}
+ result = await tools["brain-switch"].execute(
+ {"provider": "openrouter", "persist": False}, None
)
finally:
cfg_mod.get_secret = real_get_secret