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(uninstall): stop the macOS Keychain password-prompt storm during key removal
Ruben Lütke761e4d94f83b
diff --git a/jarvis/setup/uninstall.py b/jarvis/setup/uninstall.pyindex f2d5bb18a6..c08632b099 100644--- a/jarvis/setup/uninstall.py+++ b/jarvis/setup/uninstall.py@@ -29,6 +29,7 @@ while we run (open handles keep working from memory), so we delete directly. Theentirely: they pass ``--keep-folder`` and remove the tree themselves from OUTSIDEthe venv."""+from __future__ import annotationsimport contextlib@@ -98,12 +99,79 @@ def _looks_like_jarvis_install(path: Path) -> bool:return False+def _macos_keychain_item_present(key: str) -> bool | None:+ """Attributes-only macOS Keychain lookup — never decrypts, never prompts.++ The Keychain guards the secret DATA of each item: any read of the value+ (``keyring.get_password``) pops one password dialog per item per binary.+ ``security find-generic-password`` WITHOUT ``-w`` returns only the item's+ attributes, which needs no access to the secret — so probing all secret+ slots stays silent. Returns ``None`` when the probe cannot answer (not+ macOS, or ``security`` unavailable) so the caller falls back."""+ if sys.platform != "darwin":+ return None+ try:+ res = subprocess.run( # noqa: S603, S607 — fixed argv, no shell+ ["security", "find-generic-password", "-s", cfg.KEYRING_SERVICE, "-a", key],+ capture_output=True,+ timeout=15,+ check=False,+ )+ except Exception: # noqa: BLE001 — probe unavailable → generic fallback+ return None+ return res.returncode == 0+++def _macos_delete_keychain_items(key: str) -> bool:+ """Delete a macOS Keychain item WITHOUT ever reading it — so no prompt.++ Deletion needs no access to the secret data, only the read does. keyring's+ delete/verify path reads each item back, which turned one uninstall into+ dozens of per-item Keychain password dialogs. Duplicate service+account+ items can exist across keychains and ``security`` deletes one match per+ call — loop with a small safety cap. Returns True when at least one item+ was removed."""+ if sys.platform != "darwin":+ return False+ gone_any = False+ for _ in range(8):+ try:+ res = subprocess.run( # noqa: S603, S607 — fixed argv, no shell+ ["security", "delete-generic-password", "-s", cfg.KEYRING_SERVICE, "-a", key],+ capture_output=True,+ timeout=15,+ check=False,+ )+ except Exception: # noqa: BLE001 — best effort; delete_secret still runs+ break+ if res.returncode != 0:+ break+ gone_any = True+ return gone_any+++def _file_fallback_copy_present(key: str) -> bool:+ """A copy in the portable 0600 file store must be uninstalled too.++ Saved there when the OS store was declined or locked; reading it never+ prompts on any OS."""+ try:+ return cfg._FileCredStore().get(cfg.KEYRING_SERVICE, key) is not None+ except Exception: # noqa: BLE001 — unreadable fallback counts as absent+ return False++def _keyring_keys_present() -> list[str]:"""Which of Jarvis's known secret slots are actually stored in the keyring.Prefers a direct keyring probe (so an ENV-provided key is NOT mistaken for astored one — we never delete ENV vars, they aren't ours). Falls back to the- general getter only if the keyring module is unavailable."""+ general getter only if the keyring module is unavailable.++ On macOS the probe never READS a secret: reading pops one Keychain password+ dialog per stored item (30+ dialogs before the user even confirmed the+ uninstall). The attributes-only ``security`` lookup answers presence+ silently; the file-fallback store is checked alongside it."""cfg._ensure_keyring_backend()probe = Nonetry:@@ -112,13 +180,19 @@ def _keyring_keys_present() -> list[str]:def probe(key: str) -> str | None:return keyring.get_password(cfg.KEYRING_SERVICE, key)except Exception: # noqa: BLE001 — no keyring module → fall back to the getter+def probe(key: str) -> str | None:return cfg.get_secret(key)present: list[str] = []for spec in SECRETS:try:- if probe(spec.key):+ stored = _macos_keychain_item_present(spec.key)+ if stored is None:+ stored = bool(probe(spec.key))+ else:+ stored = stored or _file_fallback_copy_present(spec.key)+ if stored:present.append(spec.key)except Exception: # noqa: BLE001, S112 — a single unreadable slot must not abortcontinue@@ -283,8 +357,7 @@ def _print_plan(plan: UninstallPlan, *, keep_keys: bool, keep_folder: bool) -> N)if not keep_folder:lines.append(- f"[brand]•[/] Delete the install folder:\n"- f" [muted]{escape(str(plan.install_dir))}[/]"+ f"[brand]•[/] Delete the install folder:\n [muted]{escape(str(plan.install_dir))}[/]")lines.append(" [muted](code, the Python environment, jarvis.toml, and data folder)[/]")if plan.autostart_entry:@@ -294,9 +367,7 @@ def _print_plan(plan: UninstallPlan, *, keep_keys: bool, keep_folder: bool) -> N)else:lines.append("[brand]•[/] Login autostart: [muted]nothing to remove[/]")- lines.append(- "[brand]•[/] Remove the operating-system app launcher and registration"- )+ lines.append("[brand]•[/] Remove the operating-system app launcher and registration")if not keep_keys:if plan.keyring_keys:lines.append(@@ -328,13 +399,11 @@ def _remove_desktop_registration() -> None:else:detail = "; ".join(report.warnings)_console.print(- f" [bad]⚠ desktop app registration cleanup was incomplete: "- f"{escape(detail)}[/]"+ f" [bad]⚠ desktop app registration cleanup was incomplete: {escape(detail)}[/]")except Exception as exc: # noqa: BLE001 - never abort uninstall on shell cleanup_console.print(- f" [bad]⚠ could not remove desktop app registration: "- f"{escape(str(exc))}[/]"+ f" [bad]⚠ could not remove desktop app registration: {escape(str(exc))}[/]")@@ -358,7 +427,13 @@ def _remove_autostart() -> None:def _remove_keys(keys: list[str]) -> int:deleted = 0for key in keys:- if cfg.delete_secret(key):+ # macOS first: remove the Keychain item without ever reading it, so+ # the Keychain shows no password dialog (one per item otherwise).+ macos_gone = _macos_delete_keychain_items(key)+ # Shared cleanup for every OS: removes the platform keyring entry+ # (non-macOS) and the file-fallback copy. With the Keychain item+ # already gone this path reads nothing on macOS and stays silent.+ if cfg.delete_secret(key) or macos_gone:deleted += 1if deleted:_console.print(f" [ok]→ removed {deleted} saved key(s) from the keychain.[/]")@@ -430,8 +505,7 @@ def _remove_folder(install_dir: Path) -> bool:try:_spawn_windows_self_deleter(install_dir)_console.print(- " [ok]→ the install folder will be removed a moment after this "- "window closes.[/]"+ " [ok]→ the install folder will be removed a moment after this window closes.[/]")return Trueexcept Exception as exc: # noqa: BLE001@@ -504,9 +578,10 @@ def run_uninstall(# The bootstrap script (uninstall.ps1 / uninstall.sh) deletes the# folder next — claiming "removed" here would be dishonest if that# final step still fails.- _console.print(" [ok]Cleanup done.[/] [muted]Removing the install "- "folder itself…[/]\n")+ _console.print(" [ok]Cleanup done.[/] [muted]Removing the install folder itself…[/]\n")else:- _console.print(" [ok]Done.[/] [muted]Personal Jarvis has been removed. "- "Re-run the installer any time to start fresh.[/]\n")+ _console.print(+ " [ok]Done.[/] [muted]Personal Jarvis has been removed. "+ "Re-run the installer any time to start fresh.[/]\n"+ )return 0diff --git a/tests/unit/setup/test_uninstall.py b/tests/unit/setup/test_uninstall.pyindex 6e814a3509..7f591ab523 100644--- a/tests/unit/setup/test_uninstall.py+++ b/tests/unit/setup/test_uninstall.py@@ -198,6 +198,151 @@ def test_remove_keys_deletes_each_present_key(monkeypatch: pytest.MonkeyPatch) -assert deleted == ["openai_api_key", "gemini_api_key"]+# ------------------------------------------- macOS Keychain (prompt-free paths)+#+# Regression guards for the uninstall prompt storm: macOS pops one Keychain+# password dialog per ITEM whose secret DATA is read. The old probe/delete+# path read every stored slot 2-3 times, so an uninstall with many saved keys+# meant 30-60 password dialogs. Presence checks and deletions must never+# decrypt: `security find-generic-password` WITHOUT -w and+# `security delete-generic-password` touch only attributes.+++class _FakeCompleted:+ def __init__(self, returncode: int) -> None:+ self.returncode = returncode+++def test_macos_probe_is_attributes_only(monkeypatch: pytest.MonkeyPatch) -> None:+ calls: list[list[str]] = []++ def fake_run(argv, **_kwargs): # noqa: ANN001, ANN003+ calls.append(list(argv))+ return _FakeCompleted(0)++ monkeypatch.setattr(uninstall.sys, "platform", "darwin")+ monkeypatch.setattr(uninstall.subprocess, "run", fake_run)++ assert uninstall._macos_keychain_item_present("openai_api_key") is True+ argv = calls[0]+ assert argv[:2] == ["security", "find-generic-password"]+ assert "-w" not in argv # -w decrypts the secret → one password dialog per item+++def test_macos_probe_absent_item(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(uninstall.sys, "platform", "darwin")+ monkeypatch.setattr(+ uninstall.subprocess, "run", lambda *a, **k: _FakeCompleted(44)+ )+ assert uninstall._macos_keychain_item_present("openai_api_key") is False+++def test_macos_probe_declines_on_other_platforms(monkeypatch: pytest.MonkeyPatch) -> None:+ def explode(*_a, **_k): # noqa: ANN002, ANN003+ raise AssertionError("security CLI must not run outside macOS")++ monkeypatch.setattr(uninstall.sys, "platform", "linux")+ monkeypatch.setattr(uninstall.subprocess, "run", explode)+ assert uninstall._macos_keychain_item_present("openai_api_key") is None+++def test_macos_delete_loops_over_duplicates_and_stops(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ codes = iter([0, 0, 44])+ calls: list[list[str]] = []++ def fake_run(argv, **_kwargs): # noqa: ANN001, ANN003+ calls.append(list(argv))+ return _FakeCompleted(next(codes))++ monkeypatch.setattr(uninstall.sys, "platform", "darwin")+ monkeypatch.setattr(uninstall.subprocess, "run", fake_run)++ assert uninstall._macos_delete_keychain_items("openai_api_key") is True+ assert len(calls) == 3 # two duplicates removed, then "not found" ends the loop+ assert calls[0][:2] == ["security", "delete-generic-password"]+ assert all("-w" not in argv for argv in calls)+++def test_macos_delete_noop_on_other_platforms(monkeypatch: pytest.MonkeyPatch) -> None:+ def explode(*_a, **_k): # noqa: ANN002, ANN003+ raise AssertionError("security CLI must not run outside macOS")++ monkeypatch.setattr(uninstall.sys, "platform", "win32")+ monkeypatch.setattr(uninstall.subprocess, "run", explode)+ assert uninstall._macos_delete_keychain_items("openai_api_key") is False+++def test_remove_keys_deletes_keychain_item_before_shared_cleanup(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ order: list[str] = []+ monkeypatch.setattr(+ uninstall,+ "_macos_delete_keychain_items",+ lambda key: order.append(f"security:{key}") or True,+ )+ monkeypatch.setattr(+ uninstall.cfg,+ "delete_secret",+ lambda key: order.append(f"shared:{key}") or True,+ )+ n = uninstall._remove_keys(["openai_api_key"])+ assert n == 1+ # The silent Keychain delete must run FIRST so delete_secret's read-back+ # verification finds nothing to decrypt (= no password dialog).+ assert order == ["security:openai_api_key", "shared:openai_api_key"]+++def test_remove_keys_counts_security_only_deletion(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setattr(uninstall, "_macos_delete_keychain_items", lambda key: True)+ monkeypatch.setattr(uninstall.cfg, "delete_secret", lambda key: False)+ assert uninstall._remove_keys(["openai_api_key"]) == 1+++def test_keyring_keys_present_darwin_never_reads_secret_values(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """When the attributes-only probe answers, no decrypting read may happen."""+ import keyring++ from jarvis.setup.wizard import SECRETS++ target = SECRETS[0].key++ def boom(*_a, **_k): # noqa: ANN002, ANN003+ raise AssertionError("decrypting read — one Keychain password dialog per item")++ monkeypatch.setattr(keyring, "get_password", boom)+ monkeypatch.setattr(uninstall.cfg, "_ensure_keyring_backend", lambda: None)+ monkeypatch.setattr(+ uninstall, "_macos_keychain_item_present", lambda key: key == target+ )+ monkeypatch.setattr(uninstall, "_file_fallback_copy_present", lambda key: False)++ assert uninstall._keyring_keys_present() == [target]+++def test_keyring_keys_present_still_sees_file_fallback_copies(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A key saved to the 0600 file store (Keychain declined) must be removed too."""+ from jarvis.setup.wizard import SECRETS++ target = SECRETS[0].key++ monkeypatch.setattr(uninstall.cfg, "_ensure_keyring_backend", lambda: None)+ monkeypatch.setattr(uninstall, "_macos_keychain_item_present", lambda key: False)+ monkeypatch.setattr(+ uninstall, "_file_fallback_copy_present", lambda key: key == target+ )++ assert uninstall._keyring_keys_present() == [target]++# ---------------------------------------------------------------- folder removaldef test_remove_folder_direct_delete(tmp_path: Path) -> None:target = tmp_path / "install"