"By the time you have the words, the cursor may have moved. So remember where it was."
Capture Before the Pause
Insertion's first job happens before a single word is transcribed. The moment the hotkey goes down — before any overlay appears — Firekeeper snapshots the target: the frontmost app's bundle id and process id, the focused Accessibility element, the selected text and range if any, and a classification of the target (browser, editor, terminal, chat, email, password field, unknown). The overlay is non-activating on purpose, so showing it doesn't steal focus from the field you meant to type into.
Why the Snapshot Matters
Between hotkey-down and insertion, seconds pass — STT runs, cleanup runs. In that window, focus can drift: you glance at another window, an app raises a dialog, a notification steals focus. If insertion just typed into "whatever is frontmost now," your dictation could land in the wrong app entirely — worst case, posted into a chat you didn't mean to. The snapshot is the fixed target: insert into the app you were in when you started talking, not wherever focus wandered to.
hotkey down -> snapshot { app, pid, element, selection, category }
... STT ... cleanup ... (focus may drift here!)
insert -> is frontmost app still snapshot.app?
yes -> insert into the captured target
no -> DON'T type into the wrong app; clipboard + notify
The Wrong-App Guard
The guard is a simple comparison with a strict consequence. At insertion time, check whether the frontmost app still matches the snapshot. If it changed, Firekeeper refuses to paste — it copies the text to the clipboard and notifies you instead. "Insert into the right app or don't insert" is the rule; typing into the wrong app is worse than not typing at all, because you can always paste manually but you can't un-post a message. This one comparison prevents the single most alarming failure a dictation app can have.