hex/ios
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ryan Vogel 359b7c4d9e
iOS: dictate from the keyboard without opening Hex, plus suggestions, autocorrect, and Paste (#1999)
* feat(ios): match iOS 26 Liquid Glass keyboard geometry, palette, and Hex key controls

* feat(ios): add 3-slot suggestion strip, cautious autocorrect, and typing gestures

* test(ios): cover iOS 26 keyboard metrics, autocorrect, gestures, and hosted stage

* iOS: move Hex for iPhone to Anomaly's Apple team

(cherry picked from commit 09061502ff)

* Cut Hex Mobile TestFlight betas with a dedicated release tag

Connect the Anomaly app record and pin the mobile package graph. Cut ios-beta prereleases from dev at the scheduled windows or on dispatch, skipping unchanged mobile inputs instead of creating desktop releases or allocating build numbers locally. Prepare the generated project for the Cloud archive after clone.

Verified actionlint, duplicate and desktop-only skips, strict SwiftPM resolution, and an unsigned Release device archive containing the app, keyboard, and widgets. First Xcode Cloud onboarding and signed distribution are still pending.

* Dictate inside the iOS keyboard without opening Hex (probe)

When no warm session is running, the keyboard now records and transcribes on its own instead of opening Hex. iOS refuses to record from a keyboard extension directly (audiomxd: extension lacks the record-audio entitlement), so capture runs through getUserMedia in a hidden WKWebView, whose media process records under Hex's microphone permission. PCM is streamed to Swift, written to a WAV file, and transcribed with on-device Apple Speech (SpeechTranscriber), downloading its assets from the keyboard on first use. Steps and memory are logged to the App Group.

Replaces the cold-start handoff that opened Hex and returned to the host app. Not gated yet: needs an Experiments toggle before it ships. Verified on an iPhone 17 Pro (iOS 27.2) with Hex quit: dictation in Mail/Notes inserted text; the keyboard's footprint was about 58 MB with 118 MB headroom. Unsigned simulator tests were not run.

* Regenerate the keyboard Info.plist with its microphone and speech descriptions

XcodeGen writes these from project.yml; the previous commit changed project.yml without the generated plist. Verified by building for the device.

* Start in-keyboard dictation from the full keyboard's Hex key

Holding the Hex key without a warm session opened Hex through the cold-start handoff; it now records and transcribes inside the keyboard when that path is available, and only falls back to opening Hex otherwise. Verified it builds and installs on the iPhone 17 Pro.

* Dictate with a tap on the Hex key and the bar's Hex mark

The full keyboard's Hex key ignored taps and needed a 0.35 s hold; a tap now dictates too (sliding still opens the style menu). The dictation bar's Hex mark opened Hex through the cold-start handoff; with no warm session it now starts in-keyboard dictation instead. Removes the stray-tap-does-nothing guard because Ryan wants the key to act like a dictation button.

Verified HexKeyGestureTests (5 passed) in the iPhone 18 Pro simulator and installed on the iPhone 17 Pro.

* Offer Paste and one-time-code help in the full keyboard's strip

When something was copied in the last 3 minutes and not yet pasted from the keyboard, the empty strip shows the system Paste button (UIPasteControl), which hands the clipboard over only on tap, so iOS never shows its paste prompt; nothing reads the clipboard before then. In one-time-code fields the strip also offers switching keyboards, because iOS gives codes from Messages and Mail only to its own keyboard. Copies seen and pasted are tracked by changeCount in the App Group. UIPasteControl's configuration is immutable, so a palette change replaces the control (setting colors on it raised NSInternalInconsistencyException in FullKeyboardEngineTests).

Verified the full HEXMobileTests suite passes on the iPhone 18 Pro simulator and the build installs on the iPhone 17 Pro; the Paste button itself is not yet tried on the device.

* Describe in-keyboard dictation in the iOS README

The status paragraph said the keyboard never touches the microphone; it now records through WebKit and transcribes with Apple Speech when no warm session runs. The cold-start handoff remains only before iOS 26.

---------

Co-authored-by: Kit Langton <kit.langton@gmail.com>
2026-11-19 12:20:12 -05:00
..
ci_scripts Set up Hex Mobile internal TestFlight releases (#1997) 2026-11-19 11:48:49 -05:00
HEXActivity feat(ios): polish iPhone keyboard dictation, warm sessions, and Live Activity (#574) 2026-10-30 23:35:45 -07:00
HEXKeyboard iOS: dictate from the keyboard without opening Hex, plus suggestions, autocorrect, and Paste (#1999) 2026-11-19 12:20:12 -05:00
HEXMobile iOS: dictate from the keyboard without opening Hex, plus suggestions, autocorrect, and Paste (#1999) 2026-11-19 12:20:12 -05:00
HEXMobileTests iOS: dictate from the keyboard without opening Hex, plus suggestions, autocorrect, and Paste (#1999) 2026-11-19 12:20:12 -05:00
HEXShared iOS: dictate from the keyboard without opening Hex, plus suggestions, autocorrect, and Paste (#1999) 2026-11-19 12:20:12 -05:00
HEXWidgets Set up Hex Mobile internal TestFlight releases (#1997) 2026-11-19 11:48:49 -05:00
appstoreconnect.json Set up Hex Mobile internal TestFlight releases (#1997) 2026-11-19 11:48:49 -05:00
ExportOptions.plist Set up Hex Mobile internal TestFlight releases (#1997) 2026-11-19 11:48:49 -05:00
Package.resolved Set up Hex Mobile internal TestFlight releases (#1997) 2026-11-19 11:48:49 -05:00
project.yml iOS: dictate from the keyboard without opening Hex, plus suggestions, autocorrect, and Paste (#1999) 2026-11-19 12:20:12 -05:00
README.md iOS: dictate from the keyboard without opening Hex, plus suggestions, autocorrect, and Paste (#1999) 2026-11-19 12:20:12 -05:00

Hex for iPhone

Status: Internal TestFlight app (HEXMobile), custom keyboard extension (HEXKeyboard), and Live Activity + Control Center widget extension (HEXWidgets). The containing app records a generation-scoped temporary WAV, transcribes on-device with Apple Speech (SpeechTranscriber on iOS 26+) or FluidAudio Parakeet V2 (iOS 18+), and removes each capture's file after inference, cancellation, or failure. During a warm session the keyboard extension sends commands and inserts completed text over the shared App Group (group.anomaly.hex.mobile). Otherwise it dictates by itself (in-keyboard dictation, iOS 26+): iOS refuses to record from a keyboard extension directly, so it captures through getUserMedia in a hidden WKWebView under Hex's microphone permission, writes a temporary WAV, and transcribes it on-device with Apple Speech, downloading the speech assets on first use (HEXKeyboard/KeyboardLocalDictation.swift). Audio never leaves the iPhone.

Capabilities

  • One-tap keyboard dictation (HEXKeyboard):
    • Setup: The keyboard needs Full Access to reach Hex through the App Group. Without it, the keyboard shows the Settings path and an Open Hex setup button (hex-dictation://keyboard/setup). The app's setup card shows live status for the keyboard, Full Access, the microphone, and the speech model, and opens Hex's page in Settings. Full Access shows as on once the keyboard has run with it (keyboard.fullAccessSeenAt).
    • Opening Hex: SwiftUI Link, openURL, and extensionContext.open do nothing in a keyboard extension, so the keyboard opens Hex through the UIApplication at the end of its responder chain (ContainingAppOpener).
    • Cold start (before iOS 26): Tapping Dictate opens the containing app (hex-dictation://keyboard/record?...) with a 10-second handoff window, starts recording, and opens the selected host app's URL scheme (messages://, slack://, claude://, chatgpt://, mobilenotes://, discord://, mail://, x-web-search://, etc.) using public UIApplication.shared.open(_:). Because iOS keyboard extensions cannot inspect the host app's bundle ID without private APIs, you pick your usual return app once on the ↩ chip (or jump bar), and apps without a registered URL scheme fall back cleanly within ~1s to the bottom-edge swipe bar and quick-jump chips. Edit apps… in the app's return menu picks and orders the apps the keyboard tray and jump bar offer.
    • GPU Dot Scope (HEXShared/DotScope.swift, DotScopeShader.metal): Both HEXMobile and HEXKeyboard render Hex's desktop menu-bar braided oscilloscope (src/dot_scope.rs, src/rune_hud.wgsl) at native display refresh via CAMetalLayer + CADisplayLink, pausing at 0% CPU/GPU once settled in idle. The keyboard extension mounts it only while a capture or transcription is active and shows a static Canvas dot row at rest, so a fresh keyboard process builds no Metal device, pipeline, layer, display link, or idle pre-roll before its first frame; the app's docked keyboard preview keeps the live scope. The home-indicator swipe cue's pipeline is compiled on first use, which only the app shows. Lock Screen / Dynamic Island Live Activities render a matching Canvas dot-matrix badge (HexDotMatrixBadge) because WidgetKit archives static view snapshots rather than hosting live CAMetalLayers. Meter polling stays alive through a temporary non-recording state of the same capture; it resumes app levels and keyboard snapshots when the recorder is ready again. Capture completion, interruption, and Stop end polling.
    • Warm session (Off, 5m, 15m, 1h): Picking a duration on Keep mic warm starts an AVAudioEngine input session immediately (default 15m) so subsequent taps on Dictate record directly inside the keyboard with zero app switches; picking Off or tapping the header timer ends it.
    • Styles: Polished (sentence case + punctuation + filler trim), Casual (lowercase chat without trailing period), Notes (spoken "bullet" / "next line" markers), and Verbatim, with cursor-aware insertion spacing and repeating backspace.
    • Full keyboard Hex key (Experiments › Full keyboard): A tap, or a still hold of 0.35 s, starts dictation: in a warm session, else inside the keyboard (in-keyboard dictation, iOS 26+), else by opening Hex. Moving more than 10 pt first opens the style and Return to menu; releasing over a row picks it, and releasing elsewhere leaves the menu open for taps (HexKeyGesture). VoiceOver activation dictates, and the Dictation styles action opens the menu.
    • Apple Intelligence cleanup (Experiments › Clean up with Apple Intelligence, iOS 26+): Off by default. For every style but Verbatim, one on-device FoundationModels pass before formatting fixes clearly misheard words and spoken self-corrections, within a 2 s budget. A timeout, error, empty or implausible output keeps the raw transcript, and the toggle is disabled with a reason when Apple Intelligence is unusable.
    • Custom vocabulary (Experiments › Custom vocabulary): Off by default. A local list of up to 100 names and phrases, applied to every engine. After transcription, matching words are rewritten to the listed spelling across case, spaces, tabs, a single hyphen, and possessive apostrophes, before cleanup and again after formatting, so a style cannot undo a spelling. The listed spelling is kept exactly, even at a sentence start (an all-lowercase term stays lowercase), and a term that spells its own boundaries ("iPhone 7", "X-ray") matches those boundaries exactly. A word that carries its own apostrophe only matches a term that has one, several transcript words are joined only when the term reads as a compound, and compound terms like "WeChat" can also match the plain phrase ("we chat"). On iOS 26 Apple Speech the list is also sent as a best-effort recognition hint; Parakeet's batch path gets no hint.
  • Resilient capture & expiry contract (DictationController):
    • Monotonic jobGeneration, retained transcriptionTask, and unique per-capture WAV filenames ensure an expiring warm session never drops an already-accepted transcription (deliverable for 30s), while a stale winding-down inference can never overwrite a newer capture or delete its audio file.
    • Phone/FaceTime/Siri audio interruptions finalize captures >= 300 ms so spoken words are not lost, cancel shorter taps cleanly out of Listening, and resume warm keepalive when iOS signals .shouldResume. Bluetooth HFP input is opt-in (Use Bluetooth headphones, default off) so AirPods stay in full-fidelity output by default.
  • Action Button, Control Center, Back Tap & Live Activity:
    • DictateWithHexIntent (AudioRecordingIntent + LiveActivityIntent) and HexDictationControl (ControlWidget) start recording on first press with a Dynamic Island / Lock Screen Live Activity (Stop and Cancel buttons) and transcribe + copy to the clipboard on second press.

Build & Test

Prerequisites: Xcode 26+ and XcodeGen 2.46.0+.

cd ios
xcodegen generate
xcodebuild test -project HEXMobile.xcodeproj -scheme HEXMobile -destination "id=<SIM_UDID>"

Simulator vs. Physical iPhone Proof Limits

  • Verified in Simulator (HEXMobileTests + --snap-state scenes): Compilation across HEXMobile, HEXKeyboard, and HEXWidgets; App Group command/snapshot framing; the DictationController generation/expiry race and 30s post-close transcript delivery; 10s handoff window + URL-scheme auto-return fallback; interruption handling; meter recovery after injected startup and mid-capture recorder unavailability (including keyboard levels and heartbeat); deterministic style formatting; and UI layouts.
  • Requires a physical iPhone: Real AVAudioSession background keepalive survival across lock/app switches, live orange indicator behavior, on-device SpeechTranscriber / Neural Engine Parakeet latency, URL-scheme return into installed third-party apps (Messages, Slack, Claude, ChatGPT), Dynamic Island Live Activity interaction, and hardware Action Button invocation. Transient AVAudioRecorder.isRecording changes during warm handoff or Bluetooth route changes have not been reproduced on hardware; the meter recovery tests inject that condition through ActiveAudioCapture.
  • Apple Speech hint: Custom vocabulary's contextual strings are best effort and unverified on a physical iPhone. Apple documents contextual strings only for DictationTranscriber, Hex sets them on SpeechTranscriber, and Parakeet's batch path gets no hint.
  • No iOS CI: Custom vocabulary is covered by unit tests only. No CI job compiles or tests the iOS targets, so these checks run only in a local xcodebuild test.

Internal TestFlight releases

Hex Mobile in App Store Connect uses Anomaly's signing team. The GitHub Release Hex Mobile workflow checks dev at noon and 6 p.m. Chicago time, or on manual dispatch, and cuts an ios-beta-* prerelease when iOS inputs have changed. These tags are separate from desktop releases. The marketing version stays fixed across beta builds.

The Xcode Cloud workflow needs a tag start condition with prefix ios-beta-, container ios/HEXMobile.xcodeproj, shared scheme HEXMobile, an iOS Archive action, and a TestFlight post-action for Hex Internal. Cloud owns the build number. Verify the run's source tag and the processed build in that group.