Skip to content

feat!: rebuild AutoFix as a fast, simple single-process app - #38

Open
HusseinBaraja wants to merge 2 commits into
mainfrom
autofix-v2
Open

HusseinBaraja wants to merge 2 commits into
mainfrom
autofix-v2

Conversation

@HusseinBaraja

Copy link
Copy Markdown
Owner

Why

The core idea (type anywhere, an LLM quietly fixes typos) was buried in ~43k lines of Rust + C#. That code ran two processes with IPC and SQLite and had 50+ settings. Its default engine was a local word list. The automatic API timeout was 700 ms, which is shorter than most LLM responses, so automatic fixes rarely landed. The model also had to return JSON with character offsets, which is slow and fragile.

This PR replaces it with one lean .NET 8 app (~4k lines). Paste an API key and it works, in about one API round trip.

What changed

  • Typing engine (src/AutoFix.Core/Engine/TypingEngine.cs): a platform-free state machine. It tracks the text typed before the caret and applies a fix by deleting back to the first changed character and retyping the rest. There is no clipboard use and no reading of the document. Keys you press while a fix is typed, or while Enter is held, are swallowed and replayed in their original order.
  • Triggers: sentence end, pause (1 s), "fix before Enter" (held for at most 3 s; Shift+Enter is never held), and Ctrl+Alt+Space (fixes the selection or what you just typed).
  • Undo: Backspace right after a fix restores the original text and adds its words to Words to keep.
  • Providers: DeepSeek (default), OpenAI, Anthropic, Gemini, Groq, OpenRouter, Mistral, Ollama, and any custom OpenAI-compatible server. Pasting a key tests it right away. Key prefixes select their provider automatically.
  • Safety:
    • Password fields are never read; the check starts as soon as you start typing in a field.
    • Blocked apps (terminals, code editors, password managers) and elevated apps are skipped.
    • Text after the caret is never touched; stale answers are dropped.
    • A guard rejects answers that are not small corrections, for example a model answering a question.
    • Keys are kept in Windows Credential Manager. The log holds timings only.
  • UI: a one-page settings window that follows the light or dark theme and has a "Try it" box. A click-through note near the caret shows what changed. The tray menu has Pause and "Off in this app".
  • Removed: the Rust engine, the old WPF settings app, TOML/SQLite storage, and old docs and scripts. Saved provider keys from the old app are still read.

Verification

Machine: Windows 11 Pro, 16 GB RAM.

  • dotnet build AutoFix.sln with warnings treated as errors: passes, 0 warnings.
  • dotnet test tests/AutoFix.Tests: 74/74 passed. Covers the engine state machine, edit planning, response guard, LLM client (request shapes, retry quirks, error mapping), settings, and dead keys.
  • scripts/test-e2e.ps1: 7/7 passed, repeated across several runs. It runs the real AutoFix.exe against a mock server and types into a real Win32 text box with SendInput. Scenarios: sentence fix, typing during a request, Backspace undo, Enter hold, fast typing through an Enter hold (key order), selection fix with the clipboard preserved, and no request from a password field.
  • The published single-file dist/AutoFix.exe (63 MB, self-contained) also passes the E2E check.
  • Live DeepSeek (deepseek-chat):
    • Provider latency: p50 920 ms, p95 1358 ms (n=22).
    • Real app, last key to corrected text on screen: 758–923 ms. AutoFix adds about 110 ms, mostly Windows SendInput at about 1 ms per event; I measured the same rate without AutoFix running.
    • Try-it box: 3 of 4 runs passed (fixed 0.9–1.9 s after typing). The failed run is explained by the log: another window repeatedly took the foreground, and AutoFix correctly reset.
  • Quality samples: fixes typos, keeps slang ("u", "gonna") and brand names, does not answer questions, ignores injected instructions, and fixes Arabic ("ولاكن" → "ولكن").
  • An independent review found 11 issues. All were fixed, with regression tests where testable. Live testing found one more: background apps firing focus events reset the typed text. It is now filtered to the foreground app.
  • Screenshots of the dark and light settings window and the fix note were inspected.

Known limitations

  • IME input (CJK) is not tracked.
  • Apps that run as administrator need AutoFix to run as administrator too.
  • Editors that change text on their own can cause a fix to be skipped.
  • A selection fix restores the clipboard after a fixed 600 ms; a very slow app could paste late.

🤖 Generated with Claude Code

Old design: two processes, IPC, SQLite, 50+ settings, local word-list
engine by default, and a 700 ms auto timeout shorter than most LLM
responses, so automatic fixes rarely landed.

- type-tracking engine with backspace-and-retype edits; fixes land one
  API round trip after the trigger
- triggers: sentence end, pause, Enter hold, Ctrl+Alt+Space
- Backspace right after a fix undoes it and learns the words
- providers: DeepSeek, OpenAI, Anthropic, Gemini, Groq, OpenRouter,
  Mistral, Ollama, custom OpenAI-compatible
- one-page settings with key paste-and-test and a Try it box
- unit tests plus an end-to-end harness against the real exe

BREAKING CHANGE: Rust engine, WPF settings app, TOML/SQLite storage
removed. Settings start fresh; saved provider keys are still read.
- ignore focus events from background apps; a background WPF host
  reset the typed text about once a second
- resync modifiers after secure-desktop switches so Space is not
  taken as the shortcut
- queue user input behind replayed input to keep key order
- tag each edit with an id and scale its timeout with its size
- skip key translation while input is held (dead keys)
- drop held keys when focus moves during an Enter hold
- never complete an unfinished last word after a pause
- skip fixes that change the first letter of a possibly partial word
- stop the timer spinning while a request is in flight
- save learned words off the hook thread
- selection fix: abort if the user typed meanwhile; keep restored
  clipboard out of history
- log error kinds only, never provider error text
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2eecec13-0ea5-4a60-be7a-983e5813fbdd
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant