Match surrounding text when dictating at the caret - #8
Merged
Conversation
Capture up to 240 characters immediately before the caret in the focused editable element (AX value + selected-text-range; secure fields are never read) and carry it through AppContext and SmartCleanupRequest into the smart cleanup prompt. The hint tells the on-device model whether the dictation continues a sentence (lowercase, no leading period) or starts a new one (capitalized), decided deterministically in Swift because the small model follows a concrete directive far better than a conditional rule. The cleanup result is then post-processed deterministically: a repeated before-caret prefix is stripped and the first letter's case is harmonized with the seam, preserving proper nouns via the speaker's own transcript casing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Course correction: dictating mid-sentence no longer produces wrong capitalization at the seam.
AppContext.textBeforeCaret: ≤240 chars before the caret from the focused element (AX value + selected range), surrogate-pair-safe; nil for secure fields (role AND subrole checked), empty values, or caret at 0.caretContinuesSentence): continue lowercase mid-sentence vs start a new sentence.stripRepeatedCaretPrefix,harmonizeCaseWithCaretContext), both gated on caret context being present.Live-validated on-device (3/3 stable): "I think we should" + "definitely ship it" → stays lowercase; "Check the logs." + "we might need to roll back" → capitalized; proper nouns and "I" survive lowercasing.
Verified on macOS 26.5 (arm64):
make testpasses, full build clean. Manual QA: quirky AX trees (Electron) degrade to nil → unchanged behavior.All eight feature PRs register tests in
Tests/AppContextServiceTests.swiftand some extend the Makefile test list, so each merge after the first needs a trivial conflict resolution there. Suggested merge order: dictionary-ranking → formality-dial → caret-context → transforms → scratch-that → raw-undo → rebindable-cancel → mouse-ptt.