The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): expose the renderer accessibility tree to dictation/IME tools (#118271)
Brooklyn Nicholsonea647bd518e9
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex cc8935ceb21..73b884c2b6a 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -463,6 +463,7 @@ import {oauthLoginLoadUrlOptions,resolveRemoteRequestHeaders} from './remote-ws-headers'+import { enableRendererAccessibility } from './renderer-accessibility'import { missingRendererAssets, presentRendererIndexes } from './renderer-bundle'import { planLaunchSwitches, readDesktopLaunchConfig } from './renderer-heap-flags'import { loadRendererLoadErrorPage } from './renderer-load-error-page'@@ -18733,6 +18734,15 @@ app.whenReady().then(() => {// connection resolution.migrateLegacyEncryptedSecretsOnce()+ // Expose the renderer's accessibility tree to the OS (#118271, Windows+ // twin #92607): dictation tools that insert text through the accessibility+ // APIs don't register as screen readers, so Chromium never builds the tree+ // and the composer stays invisible to them. Must run after `ready` (the+ // API's requirement). Opt out with desktop.renderer_accessibility: false+ // (bridged as HERMES_DESKTOP_RENDERER_ACCESSIBILITY=0); the platform/env+ // decision lives in the extracted helper.+ enableRendererAccessibility({ appApi: app })+installMediaPermissions()installDownloadHandling()registerMediaProtocol()diff --git a/apps/desktop/electron/renderer-accessibility.test.ts b/apps/desktop/electron/renderer-accessibility.test.tsnew file mode 100644index 00000000000..c29975b21a5--- /dev/null+++ b/apps/desktop/electron/renderer-accessibility.test.ts@@ -0,0 +1,40 @@+import assert from 'node:assert/strict'++import { test } from 'vitest'++import { enableRendererAccessibility, shouldEnableRendererAccessibility } from './renderer-accessibility'++test('shouldEnableRendererAccessibility is on by default on the typed platforms', () => {+ assert.equal(shouldEnableRendererAccessibility({}, 'darwin'), true)+ assert.equal(shouldEnableRendererAccessibility({}, 'win32'), true)+})++test('shouldEnableRendererAccessibility never enables on platforms without the typed API', () => {+ // Linux AT reaches the renderer through the platform's ATK stack, not+ // through app.setAccessibilitySupportEnabled.+ assert.equal(shouldEnableRendererAccessibility({}, 'linux'), false)+})++test('shouldEnableRendererAccessibility honors the opt-out env bridge', () => {+ for (const off of ['0', 'false', 'no', 'off', 'OFF', ' 0 ']) {+ assert.equal(shouldEnableRendererAccessibility({ HERMES_DESKTOP_RENDERER_ACCESSIBILITY: off }, 'darwin'), false)+ assert.equal(shouldEnableRendererAccessibility({ HERMES_DESKTOP_RENDERER_ACCESSIBILITY: off }, 'win32'), false)+ }++ // Absent, empty, or a positive value keeps the feature on.+ assert.equal(shouldEnableRendererAccessibility({ HERMES_DESKTOP_RENDERER_ACCESSIBILITY: undefined }, 'darwin'), true)+ assert.equal(shouldEnableRendererAccessibility({ HERMES_DESKTOP_RENDERER_ACCESSIBILITY: '' }, 'win32'), true)+ assert.equal(shouldEnableRendererAccessibility({ HERMES_DESKTOP_RENDERER_ACCESSIBILITY: '1' }, 'darwin'), true)+})++test('enableRendererAccessibility flips the injected Electron switch exactly when enabled', () => {+ const recorded: boolean[] = []+ const appApi = { setAccessibilitySupportEnabled: (enabled: boolean) => recorded.push(enabled) }++ enableRendererAccessibility({ appApi, env: {}, platform: 'darwin' })+ enableRendererAccessibility({ appApi, env: {}, platform: 'win32' })+ enableRendererAccessibility({ appApi, env: { HERMES_DESKTOP_RENDERER_ACCESSIBILITY: '0' }, platform: 'darwin' })+ enableRendererAccessibility({ appApi, env: {}, platform: 'linux' })++ assert.deepEqual(recorded, [true, true])+})diff --git a/apps/desktop/electron/renderer-accessibility.ts b/apps/desktop/electron/renderer-accessibility.tsnew file mode 100644index 00000000000..84c0a8755e9--- /dev/null+++ b/apps/desktop/electron/renderer-accessibility.ts@@ -0,0 +1,66 @@+/**+ * renderer-accessibility.ts+ *+ * Chromium only builds the renderer's accessibility tree when it detects an+ * assistive technology — and dictation tools that insert text through the OS+ * accessibility APIs (Wispr Flow and similar) do not register the way a+ * screen reader does, so the tree never appears: the window exposes only its+ * chrome and the contenteditable composer is invisible to them, on macOS+ * (#118271) and on Windows (#92607) alike. Electron's manual switch for that+ * is `app.setAccessibilitySupportEnabled(true)` once the app is ready.+ *+ * Default ON for the platforms where the typed API exists (darwin, win32) —+ * the composer being reachable by every accessibility-driven input method is+ * the point of the bug fix; the tree's rendering cost is the price. A+ * perf-sensitive setup can opt out with `desktop.renderer_accessibility:+ * false` in config.yaml, which the `hermes desktop` launcher bridges as+ * HERMES_DESKTOP_RENDERER_ACCESSIBILITY=0 (same shape as desktop.disable_gpu);+ * the Electron side also honors that variable when set directly.+ *+ * Extracted dependency-free — the Electron app object is injected — so the+ * platform/env decision is unit-testable per branch without booting Electron,+ * per the windows-child-options.ts convention.+ */++/** Values that turn the feature OFF when HERMES_DESKTOP_RENDERER_ACCESSIBILITY+ * carries them (same words the launcher accepts for false). */+const RENDERER_ACCESSIBILITY_OFF_WORDS = new Set(['0', 'false', 'no', 'off'])++/** Whether this boot must expose the renderer's accessibility tree to the OS.+ *+ * @param env - environment to read HERMES_DESKTOP_RENDERER_ACCESSIBILITY+ * from (defaults to the real process env).+ * @param platform - defaults to the real platform; injectable for tests.+ */+export function shouldEnableRendererAccessibility(+ env: { HERMES_DESKTOP_RENDERER_ACCESSIBILITY?: string | undefined } = process.env,+ platform: NodeJS.Platform = process.platform+): boolean {+ if (platform !== 'darwin' && platform !== 'win32') {+ // The typed Electron API is darwin/win32. Linux accessibility flows+ // through the platform's own ATK stack and needs no manual enable here.+ return false+ }++ const raw = (env.HERMES_DESKTOP_RENDERER_ACCESSIBILITY ?? '').trim().toLowerCase()++ return !RENDERER_ACCESSIBILITY_OFF_WORDS.has(raw)+}++/** Minimal slice of Electron's app API this module needs — injected so the+ * module stays importable without Electron. */+export interface RendererAccessibilityApp {+ setAccessibilitySupportEnabled(enabled: boolean): void+}++/** Enable the renderer accessibility tree when this boot's platform/env says+ * to. Call after the app `ready` event (the Electron API's requirement). */+export function enableRendererAccessibility(options: {+ appApi: RendererAccessibilityApp+ env?: { HERMES_DESKTOP_RENDERER_ACCESSIBILITY?: string | undefined }+ platform?: NodeJS.Platform+}): void {+ if (shouldEnableRendererAccessibility(options.env, options.platform)) {+ options.appApi.setAccessibilitySupportEnabled(true)+ }+}diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex f07d15ea4f9..34351128a46 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -2606,6 +2606,10 @@ DEFAULT_CONFIG = {# gnome-libsecret|kwallet|kwallet5|kwallet6|basic force one (basic = unencrypted). Bridged# to HERMES_DESKTOP_PASSWORD_STORE; ignored off-Linux."password_store": "auto",+ # Expose the renderer's accessibility tree to the OS (macOS/Windows) so dictation/IME tools+ # that insert text via the accessibility APIs can reach the composer (#118271, #92607).+ # False bridges to HERMES_DESKTOP_RENDERER_ACCESSIBILITY=0 and skips the tree (perf opt-out).+ "renderer_accessibility": True,# Linux: False preserves an existing custom XDG launcher entry; missing entries# are still created. True keeps the generated entry current on each launch."manage_launcher_entry": True,diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.pyindex 10f4d86c0fd..198b8fb231c 100644--- a/hermes_cli/main_desktop.py+++ b/hermes_cli/main_desktop.py@@ -1197,17 +1197,21 @@ def _detect_linux_password_store() -> str | None:return None-def _desktop_launch_options() -> tuple[list[str], str, str, str]:+_A11Y_OFF_WORDS = frozenset(("0", "false", "no", "off"))+++def _desktop_launch_options() -> tuple[list[str], str, str, str, bool]:"""``desktop.*`` launch options: ``(electron_flags, disable_gpu "auto"/"1"/"0", password_store,- ozone_hint "auto"/"x11"/"wayland")``; unknown values and config errors yield "auto"/[] so a- malformed config never blocks the launch."""+ ozone_hint "auto"/"x11"/"wayland", renderer_accessibility bool)``; unknown values and config+ errors yield "auto"/[]/True so a malformed config never blocks the launch."""flags: list[str] = []disable_gpu = password_store = ozone_hint = "auto"+ renderer_accessibility = Truetry:from hermes_cli.config import load_configdesktop_cfg = (load_config() or {}).get("desktop") or {}except Exception:- return flags, disable_gpu, password_store, ozone_hint+ return flags, disable_gpu, password_store, ozone_hint, renderer_accessibilityraw_flags = desktop_cfg.get("electron_flags")if isinstance(raw_flags, str):@@ -1227,7 +1231,12 @@ def _desktop_launch_options() -> tuple[list[str], str, str, str]:disable_gpu = _GPU_FLAG_WORDS.get(raw_gpu.strip().lower(), "auto")password_store = _choice("password_store", _LINUX_PASSWORD_STORES)ozone_hint = _choice("ozone_platform_hint", ("auto", "x11", "wayland"))- return flags, disable_gpu, password_store, ozone_hint+ raw_a11y = desktop_cfg.get("renderer_accessibility", True)+ if isinstance(raw_a11y, bool):+ renderer_accessibility = raw_a11y+ elif isinstance(raw_a11y, str):+ renderer_accessibility = raw_a11y.strip().lower() not in _A11Y_OFF_WORDS+ return flags, disable_gpu, password_store, ozone_hint, renderer_accessibilitydef _register_linux_desktop_entry(defer: bool = False):@@ -1389,13 +1398,19 @@ def _desktop_launch_env(args: argparse.Namespace) -> tuple[dict, list[str]]:cwd = getattr(args, "cwd", None)env["HERMES_DESKTOP_CWD"] = str(Path(cwd).expanduser().resolve()) if cwd else os.getcwd()- config_electron_flags, config_disable_gpu, config_password_store, config_ozone_hint = (+ config_electron_flags, config_disable_gpu, config_password_store, config_ozone_hint, config_renderer_a11y = (_desktop_launch_options())if config_disable_gpu != "auto" and "HERMES_DESKTOP_DISABLE_GPU" not in os.environ:env["HERMES_DESKTOP_DISABLE_GPU"] = config_disable_gpuif config_ozone_hint != "auto" and "ELECTRON_OZONE_PLATFORM_HINT" not in os.environ:env["ELECTRON_OZONE_PLATFORM_HINT"] = config_ozone_hint+ # Renderer accessibility tree (composer exposure to OS dictation/IME+ # tools, #118271/#92607) defaults to ON inside the app; bridge only the+ # explicit opt-out so the default never depends on the launcher path.+ if not config_renderer_a11y and "HERMES_DESKTOP_RENDERER_ACCESSIBILITY" not in os.environ:+ env["HERMES_DESKTOP_RENDERER_ACCESSIBILITY"] = "0"+# Without --password-store safeStorage.isEncryptionAvailable() is often# false and the desktop app refuses to persist remote gateway tokens.if sys.platform == "linux" and "HERMES_DESKTOP_PASSWORD_STORE" not in os.environ:diff --git a/tests/hermes_cli/test_desktop_wsl_gpu.py b/tests/hermes_cli/test_desktop_wsl_gpu.pyindex 9f40c77e288..f11233b01b8 100644--- a/tests/hermes_cli/test_desktop_wsl_gpu.py+++ b/tests/hermes_cli/test_desktop_wsl_gpu.py@@ -21,7 +21,7 @@ def _launch_env(monkeypatch, tmp_path, *, wsl: bool, dxg: bool, driver: bool) ->monkeypatch.setattr(host_runtime, "_wsl_detected", wsl)monkeypatch.setattr(main_desktop, "_WSL_DXG_DEVICE", dxg_path)monkeypatch.setattr(main_desktop, "_WSL_D3D12_DRIVERS", (tmp_path / "missing_dri.so", driver_path))- monkeypatch.setattr(main_desktop, "_desktop_launch_options", lambda: ([], "auto", "auto", "auto"))+ monkeypatch.setattr(main_desktop, "_desktop_launch_options", lambda: ([], "auto", "auto", "auto", True))monkeypatch.setattr(main_desktop, "_detect_linux_password_store", lambda: None)env, _flags = main_desktop._desktop_launch_env(argparse.Namespace(cwd=str(tmp_path)))return envdiff --git a/tests/hermes_cli/test_gui_command.py b/tests/hermes_cli/test_gui_command.pyindex 7d08d6677b9..5437ddd3c35 100644--- a/tests/hermes_cli/test_gui_command.py+++ b/tests/hermes_cli/test_gui_command.py@@ -869,7 +869,7 @@ def test_gui_launches_even_when_desktop_entry_install_fails(tmp_path, monkeypatcdef test_desktop_launch_options_normalizes_password_store(raw, expected):cfg = {"desktop": {"password_store": raw}}with patch("hermes_cli.config.load_config", return_value=cfg):- _, _, store, _ = main_desktop._desktop_launch_options()+ _, _, store, _, _ = main_desktop._desktop_launch_options()assert store == expected@@ -887,10 +887,60 @@ def test_desktop_launch_options_normalizes_ozone_hint(raw, expected):"""``desktop.ozone_platform_hint`` normalizes to x11/wayland/auto."""cfg = {"desktop": {"ozone_platform_hint": raw}}with patch("hermes_cli.config.load_config", return_value=cfg):- _, _, _, hint = main_desktop._desktop_launch_options()+ _, _, _, hint, _ = main_desktop._desktop_launch_options()assert hint == expected+ "raw,expected",+ [+ # Absent key stays ON — the composer must be reachable by+ # accessibility-driven dictation out of the box (#118083 family:+ # #118271 / #92607).+ (None, True),+ (True, True),+ (False, False),+ ("on", True),+ ("1", True),+ ("yes", True),+ ("0", False),+ ("false", False),+ ("OFF", False),+ (" no ", False),+ # Unknown strings don't disable the feature (fail-open, like the+ # other desktop launch options fail to "auto").+ ("wibble", True),+ ],+)+def test_desktop_launch_options_normalizes_renderer_accessibility(raw, expected):+ """``desktop.renderer_accessibility`` defaults to ON; only explicit false words opt out."""+ cfg = {"desktop": {} if raw is None else {"renderer_accessibility": raw}}+ with patch("hermes_cli.config.load_config", return_value=cfg):+ _, _, _, _, renderer_a11y = main_desktop._desktop_launch_options()+ assert renderer_a11y is expected+++def test_desktop_environment_bridges_only_the_accessibility_opt_out(monkeypatch):+ """ON (the default) sets nothing; the opt-out bridges to+ HERMES_DESKTOP_RENDERER_ACCESSIBILITY=0, and an explicit env var wins."""+ monkeypatch.delenv("HERMES_DESKTOP_RENDERER_ACCESSIBILITY", raising=False)+ monkeypatch.setattr("hermes_cli.config.load_config", lambda: {"desktop": {}})++ env, _ = main_desktop._desktop_launch_env(_ns())+ assert "HERMES_DESKTOP_RENDERER_ACCESSIBILITY" not in env++ monkeypatch.setattr(+ "hermes_cli.config.load_config",+ lambda: {"desktop": {"renderer_accessibility": False}})+ env, _ = main_desktop._desktop_launch_env(_ns())+ assert env["HERMES_DESKTOP_RENDERER_ACCESSIBILITY"] == "0"++ monkeypatch.setenv("HERMES_DESKTOP_RENDERER_ACCESSIBILITY", "0")+ monkeypatch.setattr("hermes_cli.config.load_config", lambda: {"desktop": {}})+ env, _ = main_desktop._desktop_launch_env(_ns())+ assert env["HERMES_DESKTOP_RENDERER_ACCESSIBILITY"] == "0"++# --- desktop.password_store detection & bridging (linux) ------------------