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(tools): open_app recognizes installed macOS/Linux apps the whitelist misses

Personal Jarvis Maintainerfb92ce626d73
diff --git a/jarvis/plugins/tool/app_resolver.py b/jarvis/plugins/tool/app_resolver.py
index f3105eb86c..2a1e69828c 100644
--- a/jarvis/plugins/tool/app_resolver.py
+++ b/jarvis/plugins/tool/app_resolver.py
@@ -16,6 +16,7 @@ real error when it can't).
"""
from __future__ import annotations
+import logging
import os
import shutil
from dataclasses import dataclass
@@ -23,6 +24,8 @@ from typing import Literal
from jarvis.platform import detect_platform
+logger = logging.getLogger(__name__)
+
try: # Windows-only stdlib module; the package must still import on a Linux VPS.
import winreg # type: ignore[import]
except ImportError: # pragma: no cover - exercised only on non-Windows runtimes
@@ -269,6 +272,87 @@ def _resolve_windows(
return LaunchTarget("startfile", raw)
+def launch_services_can_open(candidates: set[str]) -> str | None:
+ """Return the first name macOS Launch Services can resolve, else ``None``.
+
+ ``open -Ra <name>`` reveals-without-launching: exit 0 means an installed
+ ``.app`` bundle answers to that display name (case-insensitive, any
+ install location — /Applications, ~/Applications, DMG-dragged copies).
+ This is the macOS sibling of the Windows Start-Menu probe: apps like
+ "Google Chrome" are neither on ``PATH`` nor in the short whitelist, and
+ without this probe the plausibility gate rejected genuinely installed
+ apps, forcing missions into pixel-clicking Spotlight instead (live
+ incident 2026-07-20). Non-darwin hosts and all failures return ``None``.
+ """
+ if detect_platform() != "darwin":
+ return None
+ import subprocess # noqa: PLC0415
+
+ from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS # noqa: PLC0415
+
+ for name in candidates:
+ cleaned = (name or "").strip()
+ if not cleaned:
+ continue
+ try:
+ proc = subprocess.run(
+ ["open", "-Ra", cleaned],
+ capture_output=True,
+ timeout=5,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ )
+ except Exception: # noqa: BLE001, S112 — best-effort probe, gate stays honest
+ logger.debug("open -Ra probe failed for %r", cleaned, exc_info=True)
+ continue
+ if proc.returncode == 0:
+ return cleaned
+ return None
+
+
+_LINUX_DESKTOP_ENTRY_DIRS = (
+ "~/.local/share/applications",
+ "/usr/share/applications",
+ "/usr/local/share/applications",
+ "/var/lib/flatpak/exports/share/applications",
+)
+
+
+def desktop_entry_exists(candidates: set[str]) -> str | None:
+ """Return the ``.desktop`` id whose stem matches a candidate, else ``None``.
+
+ Linux sibling of the Start-Menu/Launch-Services probes: GUI apps
+ installed via .deb/.rpm/flatpak register a desktop entry but are often
+ absent from ``PATH``. Matching is on the exact file stem or the stem with
+ vendor prefixes stripped (``google-chrome`` answers to ``chrome`` only as
+ a full token, never as a substring — ``disc`` must not match
+ ``discord``). Non-Linux hosts return ``None``.
+ """
+ if detect_platform() != "linux":
+ return None
+ from pathlib import Path # noqa: PLC0415
+
+ tokens = {
+ (c or "").strip().lower().replace(" ", "-") for c in candidates
+ } - {""}
+ if not tokens:
+ return None
+ for root in _LINUX_DESKTOP_ENTRY_DIRS:
+ base = Path(root).expanduser()
+ try:
+ entries = list(base.glob("*.desktop"))
+ except OSError:
+ continue
+ for entry in entries:
+ stem = entry.stem.lower()
+ if stem in tokens:
+ return entry.stem
+ # Vendor-prefixed ids: org.mozilla.firefox, google-chrome.
+ parts = set(stem.replace(".", "-").split("-"))
+ if any(token in parts for token in tokens):
+ return entry.stem
+ return None
+
+
def _resolve_darwin(normalized_without_exe: str) -> LaunchTarget:
"""macOS resolution: prefer ``open -a <AppName>``, fall back to PATH CLIs.
diff --git a/jarvis/plugins/tool/open_app.py b/jarvis/plugins/tool/open_app.py
index 99fad6216e..0bd9aad9a2 100644
--- a/jarvis/plugins/tool/open_app.py
+++ b/jarvis/plugins/tool/open_app.py
@@ -20,6 +20,8 @@ from jarvis.core.protocols import ExecutionContext, ToolResult
from jarvis.platform import detect_platform, window_state
from jarvis.plugins.tool.app_resolver import (
_resolve_via_start_menu,
+ desktop_entry_exists,
+ launch_services_can_open,
resolve_app_launch_target,
)
@@ -154,18 +156,22 @@ _HALLUCINATION_RE = re.compile(
def _is_plausible_app_name(app_name: str) -> tuple[bool, str, str]:
- """Prueft ob ``app_name`` plausibel ist.
+ """Check whether ``app_name`` is plausible.
- Returns ``(ok, reason, kind)``. ``reason`` ist leerer String wenn
- ``ok=True``. ``kind`` klassifiziert die Ablehnung fuer eine passende
- Fehlermeldung: ``"misheard"`` (wirkt wie STT-Halluzination — Rueckfrage an
- den User) oder ``"not_found"`` (plausibler Name, nur nicht installiert —
- voller Pfad / genauer Name noetig). ``""`` wenn ``ok=True``.
+ Returns ``(ok, reason, kind)``. ``reason`` is an empty string when
+ ``ok=True``. ``kind`` classifies the rejection so the caller can pick a
+ fitting error message: ``"misheard"`` (looks like an STT hallucination —
+ ask the user back) or ``"not_found"`` (plausible name, just not
+ installed — a full path / exact name is needed). ``""`` when ``ok=True``.
"""
if _HALLUCINATION_RE.search(app_name):
- return False, "enthaelt Werbe-/Outro-Marker (wirkt wie STT-Misshearing)", "misheard"
+ return False, "contains ad/outro markers (looks like an STT mishearing)", "misheard"
if not _APP_NAME_RE.match(app_name):
- return False, "Format unplausibel (zu lang, Komma-Liste oder Sonderzeichen)", "misheard"
+ return (
+ False,
+ "implausible format (too long, comma list, or special characters)",
+ "misheard",
+ )
# Layer 2: Whitelist ODER URL ODER Pfad ODER PATH-Resolve
low = app_name.lower().removesuffix(".exe")
@@ -178,17 +184,28 @@ def _is_plausible_app_name(app_name: str) -> tuple[bool, str, str]:
return True, "", ""
if shutil.which(app_name):
return True, "", ""
- # Layer 3: Start-Menu shortcut. Many installed apps register ONLY a
- # per-user .lnk (Electron/Tauri/Squirrel builds: Discord, Slack, and the
- # user's own desktop apps like BridgeSpace/BridgeVoice) — absent from both
- # the whitelist and PATH. The resolver already follows these; mirror it
- # here so the gate is not blinder than the launcher (live failure
- # 2026-06-16: a real installed app was rejected as a misshearing).
- if _resolve_via_start_menu({low, app_name.strip()}) is not None:
+ # Layer 3: the per-OS installed-app registry, so the gate is never
+ # blinder than the launcher (live failure 2026-06-16: a real installed
+ # app was rejected as a misshearing).
+ # - Windows: Start-Menu shortcuts. Many installed apps register ONLY a
+ # per-user .lnk (Electron/Tauri/Squirrel builds: Discord, Slack) —
+ # absent from both the whitelist and PATH.
+ # - macOS: Launch Services (`open -Ra`). "Google Chrome" is neither on
+ # PATH nor in the short whitelist, yet `open -a` launches it fine —
+ # rejecting it forced missions into pixel-clicking Spotlight (live
+ # incident 2026-07-20).
+ # - Linux: desktop entries (.deb/.rpm/flatpak GUI apps off PATH).
+ candidates = {low, app_name.strip()}
+ if _resolve_via_start_menu(candidates) is not None:
+ return True, "", ""
+ if launch_services_can_open(candidates) is not None:
+ return True, "", ""
+ if desktop_entry_exists(candidates) is not None:
return True, "", ""
return (
False,
- f"'{app_name}' nicht gefunden (weder Whitelist, PATH noch Startmenue)",
+ f"'{app_name}' was not found (not in the whitelist, on PATH, or in "
+ "the OS app registry)",
"not_found",
)
@@ -197,19 +214,20 @@ class OpenAppTool:
name: str = "open_app"
risk_tier: str = "monitor"
description: str = (
- "Öffnet eine Windows-Anwendung per Namen (z.B. 'notepad', 'calc', 'chrome') "
- "oder eine Datei/URL."
+ "Opens an application on this computer by name (e.g. 'notepad', "
+ "'calc', 'chrome', 'Google Chrome') or opens a file/URL. Works on "
+ "Windows, macOS, and Linux."
)
schema: dict[str, Any] = {
"type": "object",
"properties": {
"app_name": {
"type": "string",
- "description": "Name der Anwendung oder Pfad/URL",
+ "description": "Name of the application, or a path/URL",
},
"arguments": {
"type": "string",
- "description": "Optionale CLI-Argumente",
+ "description": "Optional CLI arguments",
"default": "",
},
"reuse_existing": {
@@ -229,31 +247,31 @@ class OpenAppTool:
app_name = (args.get("app_name") or "").strip()
cli_args = (args.get("arguments") or "").strip()
if not app_name:
- return ToolResult(success=False, output=None, error="app_name fehlt")
+ return ToolResult(success=False, output=None, error="app_name is missing")
ok, reason, kind = _is_plausible_app_name(app_name)
if not ok:
- # Error-Message mit expliziter Handlungsanweisung an das Brain.
- # Differenziert nach Ablehnungsgrund — ein plausibler, nur nicht
- # installierter Name darf NICHT als STT-Misshearing abgetan werden
- # (das schickte den Agenten in die falsche Richtung).
+ # Error message with an explicit instruction to the brain,
+ # differentiated by rejection kind — a plausible but simply
+ # not-installed name must NOT be brushed off as an STT
+ # mishearing (that sent the agent in the wrong direction).
if kind == "not_found":
hint = (
- "Die App ist nicht installiert/auffindbar. Falls sie "
- "existiert, gib den vollen Pfad zur .exe an; sonst frage "
- "den User nach dem genauen App-Namen. Rufe open_app NICHT "
- "erneut mit dem selben Wert auf."
+ "The app is not installed/findable. If it exists, pass "
+ "the full path to its executable; otherwise ask the user "
+ "for the exact app name. Do NOT call open_app again with "
+ "the same value."
)
else:
hint = (
- "Wahrscheinlich STT-Misshearing. Frage den User kurz: "
- "'Welche App genau, Ruben?' — rufe open_app NICHT erneut "
- "mit dem selben Wert auf."
+ "Probably an STT mishearing. Briefly ask the user which "
+ "app exactly they meant — do NOT call open_app again "
+ "with the same value."
)
return ToolResult(
success=False,
output=None,
- error=f"App-Name '{app_name[:80]}' abgelehnt ({reason}). {hint}",
+ error=f"App name '{app_name[:80]}' rejected ({reason}). {hint}",
)
# Already-running short-circuit: if the app is open, focus its existing
diff --git a/tests/unit/plugins/tool/test_app_resolver.py b/tests/unit/plugins/tool/test_app_resolver.py
index 5b6a0274ef..b37eb2ea1a 100644
--- a/tests/unit/plugins/tool/test_app_resolver.py
+++ b/tests/unit/plugins/tool/test_app_resolver.py
@@ -272,4 +272,38 @@ async def test_open_app_rejects_hallucinated_name_before_resolution_or_launch(
)
assert result.success is False
- assert "abgelehnt" in (result.error or "")
+ assert "rejected" in (result.error or "")
+
+
+# ---------------------------------------------------------------------------
+# Per-OS installed-app registry probes
+# ---------------------------------------------------------------------------
+
+def test_launch_services_probe_is_none_off_darwin(monkeypatch):
+ from jarvis.plugins.tool import app_resolver as ar
+
+ monkeypatch.setattr(ar, "detect_platform", lambda: "win32")
+ assert ar.launch_services_can_open({"google chrome"}) is None
+
+
+def test_desktop_entry_probe_is_none_off_linux(monkeypatch):
+ from jarvis.plugins.tool import app_resolver as ar
+
+ monkeypatch.setattr(ar, "detect_platform", lambda: "darwin")
+ assert ar.desktop_entry_exists({"chrome"}) is None
+
+
+def test_desktop_entry_probe_matches_stem_and_vendor_tokens(monkeypatch, tmp_path):
+ from jarvis.plugins.tool import app_resolver as ar
+
+ (tmp_path / "google-chrome.desktop").write_text("[Desktop Entry]")
+ (tmp_path / "org.mozilla.firefox.desktop").write_text("[Desktop Entry]")
+ monkeypatch.setattr(ar, "detect_platform", lambda: "linux")
+ monkeypatch.setattr(ar, "_LINUX_DESKTOP_ENTRY_DIRS", (str(tmp_path),))
+
+ assert ar.desktop_entry_exists({"google-chrome"}) == "google-chrome"
+ assert ar.desktop_entry_exists({"chrome"}) == "google-chrome"
+ assert ar.desktop_entry_exists({"firefox"}) == "org.mozilla.firefox"
+ # A prefix must never match a different app (disc -> discord class).
+ assert ar.desktop_entry_exists({"chro"}) is None
+ assert ar.desktop_entry_exists({"slack"}) is None
diff --git a/tests/unit/plugins/tool/test_open_app_plausibility.py b/tests/unit/plugins/tool/test_open_app_plausibility.py
index 90056afd1e..15a70e7d32 100644
--- a/tests/unit/plugins/tool/test_open_app_plausibility.py
+++ b/tests/unit/plugins/tool/test_open_app_plausibility.py
@@ -51,6 +51,8 @@ def test_unknown_uninstalled_app_is_flagged_not_found_not_misheard(monkeypatch):
"""A plausible but uninstalled name -> 'not found', NOT 'STT-Misshearing'."""
monkeypatch.setattr(oa.shutil, "which", lambda _n: None)
monkeypatch.setattr(oa, "_resolve_via_start_menu", lambda _names: None)
+ monkeypatch.setattr(oa, "launch_services_can_open", lambda _names: None)
+ monkeypatch.setattr(oa, "desktop_entry_exists", lambda _names: None)
ok, _reason, kind = _is_plausible_app_name("Photoshoppy")
@@ -61,12 +63,14 @@ def test_unknown_uninstalled_app_is_flagged_not_found_not_misheard(monkeypatch):
async def test_execute_not_found_message_has_no_misshearing_claim(monkeypatch):
monkeypatch.setattr(oa.shutil, "which", lambda _n: None)
monkeypatch.setattr(oa, "_resolve_via_start_menu", lambda _names: None)
+ monkeypatch.setattr(oa, "launch_services_can_open", lambda _names: None)
+ monkeypatch.setattr(oa, "desktop_entry_exists", lambda _names: None)
res = await OpenAppTool().execute({"app_name": "Photoshoppy"}, _ctx())
assert res.success is False
- assert "Misshearing" not in (res.error or "")
- assert "nicht gefunden" in (res.error or "").lower()
+ assert "mishearing" not in (res.error or "").lower()
+ assert "was not found" in (res.error or "").lower()
async def test_execute_hallucination_still_flagged_as_misheard(monkeypatch):
@@ -79,7 +83,7 @@ async def test_execute_hallucination_still_flagged_as_misheard(monkeypatch):
)
assert res.success is False
- assert "Misshearing" in (res.error or "")
+ assert "mishearing" in (res.error or "").lower()
def test_whitelisted_app_still_plausible(monkeypatch):
@@ -87,3 +91,46 @@ def test_whitelisted_app_still_plausible(monkeypatch):
ok, _reason, kind = _is_plausible_app_name("notepad")
assert ok is True
assert kind == ""
+
+
+# ---------------------------------------------------------------------------
+# Per-OS installed-app registry probes (macOS Launch Services, Linux .desktop)
+# ---------------------------------------------------------------------------
+
+def test_launch_services_app_is_plausible(monkeypatch):
+ """An installed macOS app known only to Launch Services must pass the gate.
+
+ Live incident 2026-07-20: 'Google Chrome' (installed, launchable via
+ `open -a`) was rejected, forcing the mission into pixel-clicking
+ Spotlight for four extra steps.
+ """
+ monkeypatch.setattr(oa.shutil, "which", lambda _n: None)
+ monkeypatch.setattr(oa, "_resolve_via_start_menu", lambda _names: None)
+ monkeypatch.setattr(
+ oa, "launch_services_can_open",
+ lambda names: "Google Chrome"
+ if any("google chrome" in n.lower() for n in names) else None,
+ )
+ monkeypatch.setattr(oa, "desktop_entry_exists", lambda _names: None)
+
+ ok, _reason, kind = _is_plausible_app_name("Google Chrome")
+
+ assert ok is True
+ assert kind == ""
+
+
+def test_desktop_entry_app_is_plausible(monkeypatch):
+ """A Linux GUI app registered only as a .desktop entry must pass the gate."""
+ monkeypatch.setattr(oa.shutil, "which", lambda _n: None)
+ monkeypatch.setattr(oa, "_resolve_via_start_menu", lambda _names: None)
+ monkeypatch.setattr(oa, "launch_services_can_open", lambda _names: None)
+ monkeypatch.setattr(
+ oa, "desktop_entry_exists",
+ lambda names: "google-chrome"
+ if any("chrome" in n.lower() for n in names) else None,
+ )
+
+ ok, _reason, kind = _is_plausible_app_name("chrome-unlisted")
+
+ assert ok is True
+ assert kind == ""