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(core): first macOS Terminal launch survives the Automation consent dialog

rubenluetke10-beepc19b8dd37abb
diff --git a/jarvis/core/interactive_terminal.py b/jarvis/core/interactive_terminal.py
index e8579a3ade..2feb4a8fc4 100644
--- a/jarvis/core/interactive_terminal.py
+++ b/jarvis/core/interactive_terminal.py
@@ -92,19 +92,34 @@ def _launch_macos(
"macOS Terminal could not be opened because osascript is unavailable."
)
try:
- result = subprocess.run(
+ process = subprocess.Popen( # noqa: S603 - fixed argv, shell=False
[osascript, "-e", _macos_script(argv, cwd, env)],
- capture_output=True,
- text=True,
- timeout=8.0,
+ stdin=subprocess.DEVNULL,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ start_new_session=True,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
- except (OSError, subprocess.SubprocessError) as exc:
+ except OSError as exc:
raise InteractiveTerminalUnavailable(
"macOS Terminal could not be opened from this session."
) from exc
- if result.returncode != 0:
- log.warning("macOS Terminal launch failed with exit code %s", result.returncode)
+ try:
+ returncode = process.wait(timeout=8.0)
+ except subprocess.TimeoutExpired:
+ # The first time Jarvis drives Terminal.app, macOS blocks osascript on
+ # the one-time Automation (Apple Events) consent sheet until the user
+ # answers. A timed run() KILLED osascript here, so the FIRST sign-in on
+ # every fresh Mac failed even when the user clicked Allow. Leave the
+ # detached osascript running: once consent is granted the Terminal
+ # window still opens; a denial exits it with -1743 and opens nothing.
+ log.info(
+ "macOS Terminal launch is still pending (likely the one-time "
+ "Automation consent dialog); leaving it to finish in the background."
+ )
+ return InteractiveTerminalLaunch(pid=process.pid, method="macos-terminal")
+ if returncode != 0:
+ log.warning("macOS Terminal launch failed with exit code %s", returncode)
raise InteractiveTerminalUnavailable(
"macOS Terminal could not be opened from this session."
)
diff --git a/tests/unit/core/test_interactive_terminal.py b/tests/unit/core/test_interactive_terminal.py
index 21ae258715..aa7e4cae3c 100644
--- a/tests/unit/core/test_interactive_terminal.py
+++ b/tests/unit/core/test_interactive_terminal.py
@@ -21,12 +21,12 @@ def test_macos_opens_terminal_app_with_shell_quoted_argv(
lambda name: "/usr/bin/osascript" if name == "osascript" else None,
)
- def fake_run(argv, **kwargs): # noqa: ANN001, ANN003
+ def fake_popen(argv, **kwargs): # noqa: ANN001, ANN003
captured["argv"] = argv
captured["kwargs"] = kwargs
- return SimpleNamespace(returncode=0, stdout="", stderr="")
+ return SimpleNamespace(pid=55, wait=lambda timeout=None: 0)
- monkeypatch.setattr(terminal.subprocess, "run", fake_run)
+ monkeypatch.setattr(terminal.subprocess, "Popen", fake_popen)
launch = terminal.launch_interactive_terminal(
["/Users/Test User/.local/bin/claude", "auth", "login", "--claudeai"],
title="Claude sign-in",
@@ -46,14 +46,44 @@ def test_macos_launch_failure_is_honest(monkeypatch: pytest.MonkeyPatch) -> None
monkeypatch.setattr(terminal.shutil, "which", lambda _name: "/usr/bin/osascript")
monkeypatch.setattr(
terminal.subprocess,
- "run",
- lambda *_a, **_k: SimpleNamespace(returncode=1, stdout="", stderr="denied"),
+ "Popen",
+ lambda *_a, **_k: SimpleNamespace(pid=56, wait=lambda timeout=None: 1),
)
with pytest.raises(terminal.InteractiveTerminalUnavailable, match="could not be opened"):
terminal.launch_interactive_terminal(["claude"], title="Claude sign-in")
+def test_macos_first_run_consent_dialog_does_not_kill_the_launch(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The one-time Automation consent blocks osascript past any sane timeout.
+
+ The launcher must leave the detached osascript alive (clicking Allow then
+ still opens the Terminal window) and report the launch as in flight —
+ never kill it and fail the user's FIRST sign-in on a fresh Mac.
+ """
+ monkeypatch.setattr(terminal.sys, "platform", "darwin")
+ monkeypatch.setattr(terminal.shutil, "which", lambda _name: "/usr/bin/osascript")
+ state = {"killed": False}
+
+ def wait(timeout=None): # noqa: ANN001
+ raise terminal.subprocess.TimeoutExpired(cmd="osascript", timeout=timeout)
+
+ process = SimpleNamespace(
+ pid=57,
+ wait=wait,
+ kill=lambda: state.__setitem__("killed", True),
+ terminate=lambda: state.__setitem__("killed", True),
+ )
+ monkeypatch.setattr(terminal.subprocess, "Popen", lambda *_a, **_k: process)
+
+ launch = terminal.launch_interactive_terminal(["claude"], title="Claude sign-in")
+
+ assert launch == terminal.InteractiveTerminalLaunch(57, "macos-terminal")
+ assert state["killed"] is False
+
+
def test_windows_native_binary_gets_a_fresh_visible_console(
monkeypatch: pytest.MonkeyPatch,
) -> None: