Skip to content

fix(analyzer): prefer the OS window owner over title parsing on macOS - #21

Merged
ayushh0110 merged 2 commits into
ayushh0110:mainfrom
Venopacman:fix/macos-app-name-precedence
Oct 14, 2026
Merged

ayushh0110 merged 2 commits into
ayushh0110:mainfrom
Venopacman:fix/macos-app-name-precedence

Conversation

@Venopacman

@Venopacman Venopacman commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

_normalize() picks the app name in this order: the last part of the window title after - (L1), then the OS process name (L2). That works on Windows. There, titles end with the app name and the process name is an exe like chrome.exe.

On macOS titles rarely end with the app name:

Window title App before App after
ScreenMind — llama-server ◂ python — 120×30 (Terminal) 120×30 Terminal
ScreenMind — Your AI Memory, 100% Local (Chrome) the page title Google Chrome

This only shows up once the window title is correct, so it pairs with the macOS frontmost-window fix (#20). The code doesn't depend on it, though.

Fix

Let the platform layer decide, following the platform_support pattern. New property PlatformAdapter.trusts_os_app_name is False by default and True on MacOSAdapter. When it's True, _normalize() uses the OS owner name first (still skipping generic wrappers like electron). Title parsing stays as the fallback when there is no owner name. Windows and Linux don't change, and analyzer.py has no sys.platform check.

Testing

  • The existing scenarios in test_app_reconciliation.py use Windows-style inputs, so they now force trusts_os_app_name off. Without this they fail on a Mac.
  • New TestReconcileAppNameMacOS covers the Terminal size suffix, owner beating the title, and the fallback with no owner.
  • New TestTrustsOsAppName checks the default on each adapter, and that the analyzer reads the adapter and treats errors as "not trusted".
  • pytest tests/test_app_reconciliation.py tests/test_analyzer.py: 102 passed.

🤖 Generated with Claude Code

_normalize() resolves the app name from the "<content> - <App>" title
convention first (L1), then the OS process name (L2). That order fits
Windows, where titles end with the app name and the process name is an
exe like "chrome.exe". On macOS titles rarely end with the app name:
Terminal's title is "dir — command — 120×30", so the app became "120×30";
a Chrome tab "ScreenMind — Your AI Memory, 100% Local" became the app.

On macOS the window owner name from Quartz is ground truth, so use it
first (still skipping generic wrappers). Title parsing remains the
fallback when there is no owner name. Windows and Linux are unchanged.

Existing reconciliation scenarios use Windows-style inputs, so they now
pin sys.platform to win32; new macOS scenarios cover the darwin path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Venopacman
Venopacman marked this pull request as ready for review October 6, 2026 09:39
…app name

Replace the sys.platform == "darwin" check in _normalize() with a
property on the platform layer, following the platform_support pattern:

- PlatformAdapter.trusts_os_app_name is False by default (Windows/Linux
  keep title-first resolution).
- MacOSAdapter returns True: the window owner name is user-facing, while
  titles rarely end with the app name.
- analyzer._os_app_name_is_trusted() reads it and treats any adapter
  error as "not trusted".

Tests now patch that helper instead of sys.platform, and check the
default/override on each adapter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ayushh0110

Copy link
Copy Markdown
Owner

A couple of minor cleanup suggestions, plus one dependency to consider:

  1. PR fix(macos): detect the frontmost window via Quartz instead of NSWorkspace #20 and PR fix(analyzer): prefer the OS window owner over title parsing on macOS #21 should land together (or fix(macos): detect the frontmost window via Quartz instead of NSWorkspace #20 first. PR fix(analyzer): prefer the OS window owner over title parsing on macOS #21 now gives the macOS OS-detected app name priority over title parsing, so it depends on get_active_app_name() reliably returning the current foreground app. PR fix(macos): detect the frontmost window via Quartz instead of NSWorkspace #20 fixes that underlying macOS foreground-window detection. Without fix(macos): detect the frontmost window via Quartz instead of NSWorkspace #20, a stale OS app name could now take priority over a correct title-derived name.

  2. Lazy import: Could _os_app_name_is_trusted() import platform_adapter inside the function rather than at module level? This keeps analyzer.py platform-agnostic until the adapter is actually needed.

  3. Readability: Could we replace the title_app = None if resolved_name else ... expression with an if not resolved_name: block to match the existing control-flow style?

The two are just minor cleanup; the main concern is making sure #20 and #21 are integrated together.

@ayushh0110
ayushh0110 merged commit b14b7ef into ayushh0110:main Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants