Skip to content

feat(helper): report the target app and website host with each transcript - #285

Merged
hadrysm merged 17 commits into
feat/style-product-stylesfrom
feat/style-target-detection
Oct 16, 2026
Merged

hadrysm merged 17 commits into
feat/style-product-stylesfrom
feat/style-target-detection

Conversation

@hadrysm

@hadrysm hadrysm commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

Per-app Style (#281) needs to know what the user dictated into. The helper already reads the frontmost app at capture.start for insertion, so it is the one place that can name the target without adding work to the hot path. This PR makes the helper report the frontmost app's bundle id and, for a browser, the page host on every transcript event. Main parses and types the field and ignores it until PR 4 classifies it.

The bundle id is an in-memory read from the same NSRunningApplication object insertion already uses. The host read runs only for a known browser, on a utility queue, only after a session began, with a 1 s budget checked before every accessibility request, and the transcript never waits for it. The full URL never leaves the helper and is never logged.

Part of #281.

Scope

  • VoiceHelperCore: pageHost(_:) (http and https only, RFC 1123 hostname syntax after lowercasing, without port, userinfo, or trailing dot; an IPv4 literal passes and main's parser owns what classification may key on; IPv6 literals, percent-encoding, and non-ASCII return nil), outermostWebArea(above:maxDepth:giveUp:) and pageNode(below:maxDepth:maxNodes:giveUp:) over an AccessibilityNode protocol whose children(limit:) fetches no more than the remaining node budget, HostRead (publish keyed on the input stamp, settle, take), TranscriptTarget with a required bundleId, detectHost on capture.start, the test.target command carrying target: {bundleId, host} | null, and ready version 11.
  • VoiceHelper: InsertTarget gains bundleId and a locked host: HostRead; Insertion.recordTarget takes the session's HostRead seed (a test override is .read, detectHost leaves it .pending) and reads the host from the same focus snapshot it takes for insertion when the seed is pending and the app is a known browser; TargetHost.swift holds the browser set (Chrome Beta and Dev included) and the walk; Capture takes the target when the transcript goes out, which settles a read still running.
  • apps/desktop: HELPER_PROTOCOL_VERSION 11, target on the transcript schema through nullOnInvalid (bundleId: Schema.String), detectHost: true on every capture.start (the per-category PR ties it to cleanup state), test.target in HelperCommand, voiceTest.setTarget(target) in test mode, and the fake helper, which consumes test.target at capture.start and answers capture.cancel.
  • Verify tooling: dictate --app=<bundleId>[@host], dictate-flags.mjs, SKILL.md, and features/dictation.md.
  • native/voice-helper/scripts/target-smoke.mjs prints what the helper sees for an app and page.
  • Out of scope: classification, styles per category, and any UI. dictation.ts does not read the field.

Tradeoffs

  • Chromium answers no focused element until an assistive client enables its web accessibility, and AXManualAccessibility is an Electron patch that Chrome 155 rejects. Instead of turning Chrome's accessibility tree on, the helper searches at most 3 levels and 64 nodes below the focused window for the first node with a URL, fetching children through AXUIElementCopyAttributeValues with the remaining budget as the limit. On Chrome that is the AXGroup under the window, found after 2 nodes.
  • Non-ASCII hosts return nil rather than punycode. An IDNA table is not worth a dependency for a style hint.
  • A host read gives up after hostReadBudget (1 s, named in TargetHost.swift), so a stalled browser stops getting requests once the session is over. Warm reads measured under 50 ms.
  • The host read is best effort. Safari's first read after a cold launch misses because WebKit enables accessibility on the first request; that dictation classifies by bundle id. A read still running when the transcript goes out, or one keyed on input that changed since the session started, also reports host: null.
  • The walk reports the outermost web area, the document in the address bar. A walk that the deadline or the depth bound (64 hops, measured walks take 10 to 11) ends before the window reports nothing rather than an inner frame's host.

Blast Radius

Every dictation now carries one more field on the transcript line, and the helper and app refuse each other across the version bump, as they already do. A browser dictation adds a few accessibility calls on a utility queue after capture has started. A malformed target decodes to null and never drops a transcript. Nothing here persists or logs the target.

Verification

  • swift test --filter 'PageHost|WebArea|PageNode|Protocol|CaptureStop|CaptureIdle': 26 tests pass, including the hostname table (backslash, space, percent-encoding, IPv6, hyphen and length limits), the depth and node bounds, how many children a wide node materializes, the deadline in both walks, and Capture.start reporting a busy or failed start.
  • vp test run protocol.test.ts dictation.test.ts helper.test.ts: 173 tests pass. A transcript with a target, with target: null, and with each malformed shape still inserts, and no log, report, or history entry carries the bundle id or host (checked by temporarily logging the target and watching the test fail).
  • Live app in test mode, with the verify skill: dictate short.wav, --app=com.apple.MobileSMS, and --app=com.google.Chrome@mail.google.com all end inserted with the same text, and main.log has no occurrence of the bundle id or host.
  • Direct helper run: test.target rides on the next transcript line exactly as sent, an app-only target carries host: null, and the capture after it reports the real frontmost app again.
  • Latency, startMs p50 over 20 dictate sessions in the same conditions: origin/main 1 ms (p90 2, max 4) → this branch 2 ms (p90 2, max 2). Inside the 1 ms clock granularity.
  • Smoke runs with target-smoke.mjs (installed browsers: Safari, Google Chrome, Helium; Arc, Brave, Edge, Firefox, Opera, Vivaldi are not installed and are unverified):
App Page Reads Hosts found Host read p50 Note
Safari, cold launch duckduckgo.com 5 4 5 ms, 5 hops read 1 has no focused element yet
Safari, cold launch example.com 5 4 1 ms, 0 hops web area itself is focused
Safari, cold launch mail.google.com 5 4 1 ms, 0 hops
Chrome 155, fresh profile duckduckgo.com, example.com, mail.google.com 15 15 24 ms, 2 nodes window search; Gmail redirects to accounts.google.com
Chrome 155, focused-element walk only same three 14 0 no focused element, before and after AXManualAccessibility
Helium, warm duckduckgo.com 7 7 2 ms, 10 to 11 hops exposes a focused element, so the upward walk is used
Messages, TextEdit, Terminal app only 15 0 no read bundle id present, no host-read line

Review round 2. Fixed the two criticals and the warnings from the thermo review: the host read now starts from the focus snapshot insertion already captures (element for the upward walk, window for Chromium) and publishes through HostRead.publish, which drops a result whose input stamp changed, so a tab visited during the read cannot name the host; the walk returns the outermost web area, so a caret inside an iframe reports the page, not the frame; bundleId is required on both sides; capture.start carries detectHost; test.target carries a whole target or null and vv dictate sends it on every run; the fake helper consumes it at capture.start; Chrome Beta and Dev are browsers; PageHost.swift states that an IPv4 literal passes and main owns the validity rule. Proof: swift test --filter 'WebArea|HostRead|PageHost|PageNode|Protocol|captureStart|microphoneConfigure|CaptureStop|CaptureIdle' 30 tests pass; the new reportsTheOutermostWebAreaAboveAFocusedIframe fails on the old walk with (found.node?.index → 2) == 4; vp test run protocol.test.ts dictation.test.ts helper.test.ts 178 pass, and the new helper.test.ts case fails when the fake consumes the override at capture.stop (expected { bundleId: 'com.google.Chrome', … } to be null after a cancelled capture); tsc --noEmit clean; node --test voice-verify.test.mjs 4 pass. The live dictate and target-smoke.mjs runs for this round are pending: the user's own Voice.app held the hotkey for the whole session and the scripts refuse while it runs. The hot path is unchanged in shape (recordTarget still only stamps input and dispatches before capture.start), so the round-1 startMs numbers above stand until a live rerun.

Review round 3. The real helper dropped a test.target override's host: recordTarget settled the read to nil before main.swift published the override, and publish only acts on a pending read, so every dictate --app=<browser>@<host> run went out with host: null. The session's HostRead is now seeded when the InsertTarget is created (recordTarget(host:) replaces detectHost:; an override seeds .read(host), a wanted read .pending, an unwanted one .read(nil)), and the publish-after-settle line is gone. The depth bound of outermostWebArea now behaves like the deadline and returns nil instead of an inner frame, with webAreaMaxDepth raised from 25 to 64. Capture.cancel (all three branches) and shutdown settle the session's host read so a cancelled browser session sends no further accessibility requests. Proof: the new TranscriptTargetTests drive Insertion.recordTarget into Capture and read the emitted transcript line; on the old code the override row failed with (reported["host"] as? String → nil) == "mail.google.com", the cancel and shutdown rows with .pending == .read(nil), and the flipped dropsAnInnerWebAreaWhenTheBoundStopsTheWalk with (found.node → index 1) == nil. After the fix swift test --filter 'TranscriptTarget|WebArea|HostRead|PageHost|PageNode|Protocol|CaptureStop|CaptureIdle' passes 36 tests in 7 suites and swift build is clean. Live dictate --app and target-smoke.mjs are still blocked by the user's own Voice.app holding the hotkey, so the override path is proven at the helper level, not through the hub.

Hub after the dictations (no UI change in this PR):

Voice hub after the dictations

@github-actions github-actions Bot added the size:L 100-499 effective changed lines (test files excluded in mixed PRs). label Oct 16, 2026
@hadrysm
hadrysm force-pushed the feat/style-target-detection branch from 81ebed9 to a0c933f Compare October 16, 2026 02:34
@hadrysm
hadrysm changed the base branch from main to feat/style-product-styles October 16, 2026 02:34
@hadrysm
hadrysm added this pull request to stack #290 October 16, 2026 08:33
@github-actions github-actions Bot added size:XL 500-999 effective changed lines (test files excluded in mixed PRs). and removed size:L 100-499 effective changed lines (test files excluded in mixed PRs). labels Oct 16, 2026
hadrysm and others added 12 commits October 16, 2026 11:17
The helper now reports which app and website owned focus when capture
started. Main decodes it, falling back to null on any malformed value,
and ignores it until per-app styles consume it. Test mode gains
voiceTest.setTarget, which sends test.target so verify can fake the
next capture's target.

Part of #281
dictate --app=<bundleId>[@host] calls voiceTest.setTarget before the key
press, so the helper reports that app and website for the session
instead of the scratch window. The result JSON and evidence file record
it as app. Flag parsing moves to a pure parseDictateFlags with a table
test.

Part of #281
A backslash, a space, percent-encoding, or an IPv6 literal came through as the host. Classification keys on hostnames, so anything that is not one returns nil.
The node budget counted visits after every child had already been copied and wrapped, and nothing ended a read once the session was over. children(limit:) fetches at most the remaining budget through AXUIElementCopyAttributeValues, sibling iteration stops when the budget is spent, and both walks ask giveUp before each accessibility request so the 1 s hostReadBudget ends a read against a stalled browser.
Capture.start reports whether a session began. A busy or failed start no longer schedules a host read for a session that does not exist.
…say whether to detect the host

The helper never sends a target without a bundle id, so `TranscriptTarget.bundleId`
is `String` in Swift and `Schema.String` in TypeScript; `target: null` stays the
one encoding of unknown. `capture.start` gains a required `detectHost` flag so main
can keep the page-host read off sessions that cannot use it (main sends true for
now; the per-category PR wires it to cleanup state). `test.target` carries
`target: {bundleId, host} | null`, so a run can clear a pending override, and
`vv dictate` sends it on every run. The fake helper consumes the override at
`capture.start` like the real helper and answers `capture.cancel`.

Protocol stays at 11; this PR is the bump.
… its outermost web area

Two defects in the host read. It re-queried the browser's current focused element
on a utility queue, so a tab the user switched to during the read named the host
for a session that started on another tab. And it stopped at the first AXWebArea
above the focused element, which inside an iframe is the frame's own document (an
about:blank editor frame, a third-party widget), not the page in the address bar.

The read now starts from the focus snapshot insertion already captures, under the
same input stamp: the walk goes up from the captured element, or down from the
captured window for Chromium, and a result keyed on changed input publishes nil.
`outermostWebArea` keeps walking to the window and reports the last web area seen;
a walk cut by the deadline reports nothing rather than an inner frame. `HostRead`
moves to VoiceHelperCore and lives under a lock on `InsertTarget`, so the
transcript taking the target, or a capture that failed to start, settles it and
the walk's `giveUp` sees that.

Chrome Beta and Chrome Dev join the browser list. `PageHost.swift` now says that
an IPv4 literal passes and main owns the validity rule.
@hadrysm
hadrysm force-pushed the feat/style-target-detection branch from 37fb235 to 457275b Compare October 16, 2026 09:17
@hadrysm
hadrysm merged commit 5dd5402 into main Oct 16, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 effective changed lines (test files excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant