Skip to content

The agent that grows with you

fix(macos): detect stale TCC grants and guide one-time re-grant

David Metcalfe36c1755065ce
diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.py
index 90781d5302d..adef0d9238d 100644
--- a/hermes_cli/doctor.py
+++ b/hermes_cli/doctor.py
@@ -1043,6 +1043,86 @@ def managed_scope_check() -> None:
check_info(f"managed dir set via HERMES_MANAGED_DIR={managed_dir}")
+def check_macos_tcc_grants() -> None:
+ """Check macOS TCC grant persistence for a locally-built desktop bundle.
+
+ TCC keys permission grants (Screen Recording, Full Disk Access,
+ Accessibility, ...) to the app's code-signing requirement. A bundle
+ signed with the pre-#73681 cdhash-pinned ad-hoc identity gets a new DR on
+ every rebuild, so all grants silently stop matching — and the stale row
+ keeps the System Settings toggle ON while macOS re-prompts on every
+ capture (issue #86385).
+
+ Post-#73681 builds pin ``designated => identifier "com.nousresearch.hermes"``
+ (no cdhash), so new grants survive rebuilds — but grants made to older
+ binaries remain stale until re-granted once. The stale state is not
+ directly readable (TCC.db needs Full Disk Access), so this check reports
+ the DR class and, when the DR is stable, prints the exact one-time repair.
+ Silent on non-macOS and when no desktop bundle is installed.
+ """
+ if sys.platform != "darwin":
+ return
+ app = _desktop_app_bundle()
+ if app is None:
+ return
+ dr = _macos_desktop_dr(app)
+ if dr is None:
+ check_warn(
+ "macOS TCC grant check",
+ "(could not read code-signing requirement of the desktop bundle)",
+ )
+ return
+ if "cdhash" in dr.lower():
+ check_warn(
+ "macOS TCC grants will reset after every update",
+ "the desktop bundle's designated requirement is cdhash-pinned "
+ "(pre-#73681 build) — rebuilds invalidate all permission grants. "
+ "Run `hermes update` to get the stable identifier-pinned signing "
+ "identity, then re-grant permissions once.",
+ )
+ return
+ check_ok(
+ "macOS TCC signing identity is stable",
+ "(identifier-pinned DR; grants survive rebuilds)",
+ )
+ check_info(
+ "If macOS still re-prompts for permissions (toggle shows ON): the stored "
+ "grant is stale — run `tccutil reset ScreenCapture com.nousresearch.hermes`, "
+ "toggle it ON in System Settings, then fully quit & relaunch Hermes once."
+ )
+
+
+def _desktop_app_bundle() -> Path | None:
+ """Locate the locally-built desktop app bundle, if any.
+
+ Mirrors the install layout the self-updater produces
+ (``apps/desktop/release/mac-<arch>/Hermes.app``).
+ """
+ root = Path(__file__).resolve().parents[1]
+ release_dir = root / "apps" / "desktop" / "release"
+ for arch in ("mac-arm64", "mac-x64"):
+ app = release_dir / arch / "Hermes.app"
+ if app.is_dir():
+ return app
+ return None
+
+
+def _macos_desktop_dr(app: Path) -> str | None:
+ """Return the bundle's designated requirement string, or None on failure."""
+ codesign = shutil.which("codesign")
+ if not codesign:
+ return None
+ proc = subprocess.run(
+ [codesign, "-d", "--requirements", "-", str(app)],
+ capture_output=True,
+ text=True,
+ timeout=15,
+ )
+ if proc.returncode != 0:
+ return None
+ return (proc.stdout or "") + (proc.stderr or "")
+
+
def run_doctor(args):
"""Run diagnostic checks."""
should_fix = getattr(args, 'fix', False)
@@ -1217,6 +1297,12 @@ def run_doctor(args):
# (a git conflict resolution can silently revert one but not the other).
_check_version_consistency(issues)
+ # macOS TCC grant persistence (issue #86385): a locally-built desktop
+ # bundle whose DR is cdhash-pinned loses every permission grant on each
+ # rebuild; a post-#73681 identifier-pinned DR survives, but grants made
+ # to older binaries stay stale (toggle shows ON while macOS re-prompts).
+ check_macos_tcc_grants()
+
_section("SSL / CA Certificates")
check_certificates(should_fix=should_fix, issues=manual_issues)
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 5e9b5e6172f..691bb7b529b 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -7011,6 +7011,22 @@ def _cmd_update_impl(args, gateway_mode: bool):
print()
print(f"✓ Code updated!{_branch_head_suffix(git_cmd, _m().PROJECT_ROOT)}")
+ # ── macOS TCC stale-grant notice (#86385) ──────────────────────
+ # Locally-built desktop bundles are re-signed on every update. With the
+ # post-#73681 identifier-pinned DR, new grants survive rebuilds — but a
+ # grant made to a pre-fix binary stays stale: the System Settings toggle
+ # shows ON while macOS re-prompts on every capture, and the modern prompt
+ # has no Allow button, so users loop. One line of guidance after update
+ # tells affected users how to complete the one-time re-grant.
+ if sys.platform == "darwin" and has_desktop_app:
+ print()
+ print(
+ " ℹ macOS: if Hermes re-prompts for permissions you already "
+ "granted (toggle shows ON), the stored grant is stale — run "
+ "`tccutil reset ScreenCapture com.nousresearch.hermes`, toggle "
+ "it ON in System Settings, then fully quit & relaunch once."
+ )
+
# ── Post-update state.db integrity guard (#68474) ─────────────────
# Verify that state.db survived the update intact. If the live file
# is now corrupted (zeroed, missing header, integrity failure),
diff --git a/tests/hermes_cli/test_doctor.py b/tests/hermes_cli/test_doctor.py
index 66a60b77d02..94ce2c2c801 100644
--- a/tests/hermes_cli/test_doctor.py
+++ b/tests/hermes_cli/test_doctor.py
@@ -1517,3 +1517,73 @@ class TestDoctorDeprecatedConfigAndEnv:
assert "Deprecated: delegation.max_async_children" in out
assert "Deprecated: HERMES_TOOL_PROGRESS_MODE" in out
assert "⚠" in out or "Deprecated" in out
+
+
+class TestMacOSTCCGrants:
+ """macOS TCC grant persistence check (issue #86385)."""
+
+ def test_silent_on_non_macos(self, monkeypatch, capsys):
+ """Non-macOS: the check must produce no output."""
+ monkeypatch.setattr(doctor_mod.sys, "platform", "linux")
+ monkeypatch.setattr(doctor_mod, "_desktop_app_bundle", lambda: None)
+ doctor_mod.check_macos_tcc_grants()
+ assert capsys.readouterr().out == ""
+
+ def test_silent_when_no_desktop_bundle(self, monkeypatch, capsys):
+ """No locally-built desktop bundle: nothing to check, no output."""
+ monkeypatch.setattr(doctor_mod.sys, "platform", "darwin")
+ monkeypatch.setattr(doctor_mod, "_desktop_app_bundle", lambda: None)
+ doctor_mod.check_macos_tcc_grants()
+ assert capsys.readouterr().out == ""
+
+ def test_warns_on_cdhash_pinned_dr(self, monkeypatch, capsys, tmp_path):
+ """Pre-#73681 builds have a cdhash-pinned DR → warn that grants reset."""
+ monkeypatch.setattr(doctor_mod.sys, "platform", "darwin")
+ monkeypatch.setattr(
+ doctor_mod,
+ "_desktop_app_bundle",
+ lambda: tmp_path / "Hermes.app",
+ )
+ monkeypatch.setattr(
+ doctor_mod,
+ "_macos_desktop_dr",
+ lambda app: 'designated => identifier "com.nousresearch.hermes" and cdhash H"97e692f3890f781fa0ad5ad6cb9d769cfaf42628"',
+ )
+ doctor_mod.check_macos_tcc_grants()
+ out = capsys.readouterr().out
+ assert "TCC grants will reset after every update" in out
+ assert "cdhash-pinned" in out
+ assert "hermes update" in out
+
+ def test_ok_and_repair_info_on_identifier_dr(self, monkeypatch, capsys, tmp_path):
+ """Post-#73681 identifier-only DR → stable + stale-grant repair info."""
+ monkeypatch.setattr(doctor_mod.sys, "platform", "darwin")
+ monkeypatch.setattr(
+ doctor_mod,
+ "_desktop_app_bundle",
+ lambda: tmp_path / "Hermes.app",
+ )
+ monkeypatch.setattr(
+ doctor_mod,
+ "_macos_desktop_dr",
+ lambda app: 'designated => identifier "com.nousresearch.hermes"',
+ )
+ doctor_mod.check_macos_tcc_grants()
+ out = capsys.readouterr().out
+ assert "TCC signing identity is stable" in out
+ assert "tccutil reset ScreenCapture com.nousresearch.hermes" in out
+ assert "toggle" in out
+ assert "relaunch" in out
+
+ def test_warns_when_dr_unreadable(self, monkeypatch, capsys, tmp_path):
+ """codesign failure → warn, never crash."""
+ monkeypatch.setattr(doctor_mod.sys, "platform", "darwin")
+ monkeypatch.setattr(
+ doctor_mod,
+ "_desktop_app_bundle",
+ lambda: tmp_path / "Hermes.app",
+ )
+ monkeypatch.setattr(doctor_mod, "_macos_desktop_dr", lambda app: None)
+ doctor_mod.check_macos_tcc_grants()
+ out = capsys.readouterr().out
+ assert "could not read code-signing requirement" in out
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 96c28eb979a..d69b6962a7c 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -543,8 +543,21 @@ macOS/Windows signing and notarization run automatically when the relevant crede
macOS remembers permission grants (Full Disk Access, Desktop/Downloads/Documents,
Accessibility, Automation, microphone) against the app's *code-signing identity*,
not its path. Locally built and self-updated apps are signed with a stable
-identifier-pinned ad-hoc signature, so grants persist across updates out of the
-box.
+identifier-pinned ad-hoc signature, so grants persist across updates.
+
+One-time note: grants made to builds *before* the identifier-pinned signing
+fix (PR #73681) carry the old cdhash-pinned requirement. macOS keeps showing the
+toggle as ON for those stale grants but still re-prompts, because the stored
+grant no longer matches the rebuilt binary — and the modern prompt has no Allow
+button, so it looks like there is nothing to re-check. If that happens, reset
+the stale grant once and re-grant:
+
+```bash
+tccutil reset ScreenCapture com.nousresearch.hermes # repeat per service
+```
+
+then toggle the fresh entry ON in System Settings and fully quit & relaunch
+Hermes. Grants are stable from then on.
For the strongest guarantee — a certificate-anchored identity, the same
mechanism yabai/skhd users rely on — create a self-signed code-signing