FluidVoice icon indicating copy to clipboard operation
FluidVoice copied to clipboard

feat: Replacement Suggestions from dictation corrections

Open martin-forge opened this issue 7 months ago • 22 comments

This implements feature request #272: an Alpha, review-first queue that suggests Instant Replacements from corrections made after dictation.

It deliberately does not silently auto-add anything. FluidVoice proposes replacements, the user reviews them, and approved suggestions become deterministic Instant Replacement entries.

Status

This feature turned out to be significantly harder to implement robustly than I first expected. The current version is working, but it is still rough around the edges and is not yet at the quality bar I would be comfortable with for a public release.

I am keeping this PR open as draft while I spend more time hardening the behavior across real editors and correction flows. Once I have had time to do that, I will decide whether this is ready to merge or whether it needs more substantial rework.

Replacement Suggestions review queue

What changed

  • Adds a Replacement Suggestions review queue to Custom Dictionary.
  • Detects edits made after FluidVoice types dictated text and extracts correction candidates.
  • Supports AX-readable editors and a generic post-dictation event fallback for editors that do not expose readable AX text.
  • Aggregates repeated corrections before showing ordinary suggestions to the user.
  • Allows high-signal technical replacements such as signal flow -> SignalFlow to appear after one correction.
  • Supports ordinary case-only corrections such as obsidian -> Obsidian.
  • Supports repeated compact-equivalent corrections such as anti-gravity -> Antigravity, anti gravity -> Antigravity, and cafe -> Café in AX-blind editor fallback.
  • Defers likely partial captures so slower corrections such as fluid sync -> FluidSync do not create premature fluid -> FluidS suggestions.
  • Keeps approved suggestions tied to Instant Replacement, not Parakeet-only Custom Words.
  • Shows at most 5 suggestions at once, with a count for any remaining suggestions.
  • Preserves pending suggestions on conflicts instead of silently dropping them.
  • Adds inline Added confirmation before approved rows animate away.
  • Refreshes the suggestion list live while the Custom Dictionary page is open.
  • Preserves the original target app PID when monitoring helper-process AX text elements.
  • Skips Replacement Suggestions AX capture entirely while the opt-in is disabled.
  • Escapes approved replacement text so $ and backslashes are applied literally by Instant Replacement.
  • Preserves technical edge punctuation in learned diff and event-fallback candidates while still stripping sentence punctuation.
  • Waits for Reliable Paste verification before starting AX-based correction monitoring, and primes the event fallback during that wait so AX-blind editors can still capture quick corrections.
  • Starts the Reliable Paste event fallback only after the typing request is accepted, so rejected insertions cannot monitor unrelated edits.
  • Keeps debug logs to correction metadata rather than logging the private replacement text.
  • Rejects malformed captured suggestions with unsupported boundary punctuation or mismatched apostrophe rewrites.

Suggestion thresholds

  • Most suggestions appear after 2 corrections.
  • Technical spellings such as FluidVoice, acronyms, numbers, and punctuation can appear after 1 correction.

The screenshot uses seeded examples so the review queue and overflow count are visible.

Validation

Latest local validation on 6 May 2026:

  • swiftformat --lint --config .swiftformat Sources/Fluid/Services/AutoLearnDictionaryService.swift Sources/Fluid/UI/CustomDictionaryView.swift Tests/FluidDictationIntegrationTests/DictationE2ETests.swift passed.
  • swiftlint lint Sources/Fluid/Services/AutoLearnDictionaryService.swift Sources/Fluid/UI/CustomDictionaryView.swift Tests/FluidDictationIntegrationTests/DictationE2ETests.swift passed with 0 violations.
  • git diff --check passed.
  • xcodebuild test -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO -skip-testing:FluidDictationIntegrationTests/DictationE2ETests/testDictationEndToEnd_whisperTiny_transcribesFixture passed 50/50 tests.
  • xcodebuild build -project Fluid.xcodeproj -scheme Fluid -configuration Release -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO passed.
  • Manual smoke tests passed in Codex, TextEdit, and Obsidian, including technical joins and obsidian -> Obsidian case correction.

The skipped test is the existing legacy Whisper tiny E2E fixture. This PR does not change default model download behavior; the feature validation above covers the replacement-suggestion code paths without using that fixture.

martin-forge avatar Apr 14 '26 10:04 martin-forge

Pushed a small CI follow-up: fixed the SwiftLint failure by removing trailing whitespace and moving the custom dictionary/suggestion types into a separate SettingsStore extension so SettingsStore.swift stays under the file-length limit. No behavior change intended.

martin-forge avatar May 03 '26 09:05 martin-forge

Pushed a small quality pass on the alpha Suggested Replacements feature: learning is now scoped to the text FluidVoice just inserted, simple title-case fixes can be suggested after repeated corrections, high-signal suggestions are more conservative, and focused tests cover the new behavior.

martin-forge avatar May 03 '26 12:05 martin-forge

Pushed one final polish commit. The suggestion thresholds are intentionally balanced so high-signal replacements can appear quickly, while ordinary casing fixes still need repeat evidence before they appear. I also clarified the helper naming, documented the inserted-text scoping trade-off, and added coverage for ordinary title-case corrections.

martin-forge avatar May 03 '26 12:05 martin-forge

Updated this PR with the latest tested Replacement Suggestions work.

Replacement Suggestions review queue

Latest update includes the Codex/event fallback path for editors without readable AX text, tighter target binding, long-document scoped diffing, conflict-safe approval, the inline Added confirmation, final UI copy/polish using the Replacement Suggestions name, punctuation-edge Instant Replacement matching for approved suggestions such as .net, c++, and node.js, target-PID preservation for helper-process AX text elements, opt-in gating so disabled users do not run Replacement Suggestions AX capture, escaped replacement templates so $ and backslashes apply literally, diff/event-fallback tokenization that preserves technical edge punctuation such as .NET, C++, C#, and 5% while still stripping sentence punctuation, Reliable Paste completion timing that waits for paste verification while priming event fallback during the wait for AX-blind editors, and acceptance gating so rejected typing requests cannot leave fallback monitoring attached to unrelated edits.

Validation on the pushed commit:

  • swiftlint --strict on the touched Swift files passed with 0 violations.
  • git diff --check passed.
  • Selected DictationE2ETests suite passed 37/37 with the legacy Whisper tiny fixture explicitly skipped.
  • Release build passed.

The skipped test is the existing Whisper tiny E2E fixture; this PR does not change default model download behavior.

martin-forge avatar May 03 '26 22:05 martin-forge

@codex review

martin-forge avatar May 05 '26 14:05 martin-forge

@codex review

martin-forge avatar May 05 '26 14:05 martin-forge

@codex review

martin-forge avatar May 05 '26 20:05 martin-forge

@codex review

martin-forge avatar May 05 '26 20:05 martin-forge

@codex review

martin-forge avatar May 05 '26 21:05 martin-forge

Codex Review: Didn't find any major issues. :rocket:

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codex review

martin-forge avatar May 05 '26 22:05 martin-forge

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codex review

martin-forge avatar May 06 '26 13:05 martin-forge

Codex Review: Didn't find any major issues. Delightful!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codex review

martin-forge avatar May 06 '26 15:05 martin-forge

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codex review

martin-forge avatar May 06 '26 17:05 martin-forge

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codex review

martin-forge avatar May 06 '26 18:05 martin-forge

Codex Review: Didn't find any major issues. :rocket:

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".