Dictation screen context
Dictation screen context is an optional local aid for dictation enhancement. When enabled and supported by the selected local model, Fluid reads limited text from the dictation target and its active window before recording ends, then gives that context to the dictation workflow so the model can use the words around the user’s speech.
Context capture
Context capture begins when dictation starts, rather than after speech recognition finishes. This timing lets the workflow read the original destination while the user is still dictating and keeps the microphone stop path independent of the screen read.
The capture can provide two kinds of text:
- Text before the cursor in the target field.
- Text visible in the target window, read from its Accessibility content or from a window-only OCR fallback.
The reader keeps the result bounded and returns no context when it finds no usable text. It reads only the recorded target window. It does not switch to another window when the target is gone or cannot be identified.
The following flow shows how the context moves from the active destination into dictation enhancement.
flowchart LR
A[Dictation starts] --> B{Setting on and model supports context?}
B -- No --> C[No screen context]
B -- Yes --> D[Read target field and window]
D --> E{Accessibility text sufficient?}
E -- Yes --> F[Bounded context]
E -- No --> G[Window-only OCR if permitted]
G --> F
F --> H[Validate same destination at stop]
H --> I[Attach to private dictation request]
I --> J[Local model enhances transcript]
References: Sources/…/DictationContextCapture.swift• L7-19 Sources/…/DictationContextCapture.swift• L46-68 Sources/…/DictationContextCapture.swift• L180-210 Sources/…/ContentView.swift• L2537-2555
Accessibility reading
Accessibility reading is the first screen-context path because it can obtain text without making a screen image. The reader walks the target window’s visible Accessibility elements, omits secure or non-text elements, and limits work so a slow application does not hold up dictation.
For text fields, the reader prefers the visible range. This avoids sending hidden or scrolled-out field content. It also removes duplicate lines and caps the amount of text passed onward.
References: Sources/…/DictationContextCapture.swift• L151-178 Sources/…/DictationContextCapture.swift• L291-360 Sources/…/DictationContextCapture.swift• L489-507
OCR fallback
OCR is a fallback for applications whose Accessibility tree does not expose enough words. It captures only the matched target window at native display scale and converts the image to text on the device. The fallback needs macOS Screen Recording access, but Fluid does not ask for that access automatically during capture.
Window matching is strict. Fluid uses the target process and window bounds, and it refuses an ambiguous match. This prevents a stale target or a different window from becoming screen context.
References: Sources/…/DictationContextCapture.swift• L193-203 Sources/…/DictationContextCapture.swift• L362-403 Sources/…/DictationContextCapture.swift• L406-429
Permission boundary
Screen context has two separate permission boundaries. Accessibility access enables reading the target field and window text. Screen Recording access enables only the OCR fallback. A setting change never requests either permission by itself.
The settings view checks permission status without prompting. The user must use the explicit screen-access action when OCR access is needed. If macOS requires a System Settings change, the action opens the Screen Recording privacy page instead of retrying silently.
References: Sources/…/DictationContextCapture.swift• L46-63 Sources/…/DictationContextCapture.swift• L238-256 Sources/…/DictationScreenPermissionController.swift• L4-22 Sources/…/DictationScreenPermissionController.swift• L25-60
Privacy exclusions
The reader stops before private input. Secure event input, password-manager applications, secure text fields, and other protected Accessibility roles produce no context. The capture is transient: the code sends only bounded text to the workflow and does not log or retain the captured words.
References: Sources/…/DictationContextCapture.swift• L238-256 Sources/…/DictationContextCapture.swift• L291-315 Sources/…/ContentView.swift• L2865-2875
Settings and model support
The feature has one stored opt-in, dictationScreenContextEnabled, which is off by default. The settings row describes the feature as active-screen help for dictation and states that supported processing stays on the device. The toggle is unavailable while dictation is busy.
The toggle alone does not make every dictation route use context. Fluid starts capture only when all of these conditions hold:
- The setting is enabled.
- The route uses the private AI path.
- The selected model declares that it reads dictation context.
- A valid external recording target exists.
- Accessibility access is available.
Unsupported providers and models return no context capability. The settings entry is also shown only when private AI is available.
References: Sources/…/DictationScreenContextSettings.swift• L18-49 Sources/…/SettingsStore.swift• L5049-5058 Sources/…/ContentView.swift• L2539-2555 Sources/…/PrivateAIIntegrationService.swift• L283-289 Sources/…/PrivateAIProvider.swift• L256-259 Sources/…/SettingsSearch.swift• L216-225
Dictation workflow handoff
The capture is tied to the exact destination recorded at dictation start. When speech ends, Fluid accepts the result only if the target process, field, and window still match and the setting and model route remain valid. This prevents context from one field or recording from being used for another.
The workflow waits up to 300 milliseconds for the background read. A late result is discarded. If the capture is cancelled or the destination changes, the workflow continues without screen context rather than delaying text delivery.
The accepted result is stored in the stop snapshot as typing context. The private dictation request receives the cursor text and screen lines through its application context. Other processing and delivery paths do not receive this data.
References: Sources/…/DictationContextCapture.swift• L31-43 Sources/…/DictationContextCapture.swift• L66-93 Sources/…/DictationStopSnapshot.swift• L17-28 Sources/…/ContentView.swift• L2563-2580 Sources/…/ContentView.swift• L2881-2902
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the model capability check aligned with the setting visibility and the dictation route gate.
- Preserve the distinction between Accessibility reading and Screen Recording OCR permission.
- Keep target validation tied to the same process, field, and window before attaching context.
- Keep transient context out of prompt traces and other persistent output.
- Preserve the timeout and cancellation behavior so screen reads cannot delay microphone stop or text delivery.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Screen context is enabled for an unsupported model | The model cannot use the captured data | Capture starts only when the model declares context support |
| Accessibility access is missing | Cursor and Accessibility window text are unavailable | Capture requires Accessibility trust and can continue without context |
| Screen Recording access is missing | OCR fallback returns no screen lines | OCR checks access and fails closed |
| The target window changes or becomes ambiguous | Context could describe the wrong window | Window identity is matched strictly and ambiguous matches are rejected |
| Reading exceeds the wait limit or dictation is cancelled | Context is omitted from that request | The read is cancelled and the dictation continues without it |
| Dictation targets a secure field or protected app | Sensitive text could be exposed | The reader rejects private targets before reading or OCR |
Key files
| File | Why to read it |
|---|---|
| Sources/…/DictationContextCapture.swift | Defines the context data, privacy checks, bounded Accessibility read, OCR fallback, and cancellation rules. |
| Sources/…/ContentView.swift | Shows when capture starts and how a valid result enters the private dictation request. |
| Sources/…/DictationScreenContextSettings.swift | Defines the user opt-in and explicit Screen Recording permission action. |
| Sources/…/DictationScreenPermissionController.swift | Defines read-only permission checks and user-triggered permission requests. |
| Sources/…/DictationStopSnapshot.swift | Defines the per-dictation handoff point for captured typing context. |
| Sources/…/PrivateAIProvider.swift | Defines the model capability contract that controls context use. |
| Tests/…/DictationContextCaptureTests.swift | Verifies opt-in defaults, privacy boundaries, target matching, permission behavior, and cancellation. |