hex/crates/keyboard
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Sebastian Herrlinger e923bc6991 Keyboard core: the swipe fixture recorded again on dev's new English model
dev's English typing model changed (#2408: en.hextm 14370569… → c23e9c54…,
86,247 words and 417,182 pairs), so the swipe parity fixture is recorded
again from the Swift decoder it was ported from: SwipeDecoderOracle, still
dev's SwipeDecoder.swift verbatim (unchanged on dev since b719d45e),
restored for the export and not committed. The swipes are drawn on dev's
current rows (#2379, #2395), so 8 of the 10 key sets and every case's
touches are new; the contexts are unchanged.

The core reads the 1,600 cases bit for bit, and a 200,000-case export
(100,000 per language) too; the shipped decoder matched the oracle in one
process on 20,000 cases on iOS 27.0 and 26.3. The model tests that pin
English's word and pair counts take the new ones.
2026-11-22 20:20:31 +01:00
..
core Keyboard core: the swipe fixture recorded again on dev's new English model 2026-11-22 20:20:31 +01:00
ffi Keyboard core: the swipe fixture recorded again on dev's new English model 2026-11-22 20:20:31 +01:00
tools Keyboard core builds take Homebrew's rustup: a cargo that runs the pinned toolchain 2026-11-22 20:02:35 +01:00
Cargo.lock Keyboard core FFI: duplicate the caller's descriptor with fcntl, sound for any value 2026-11-22 20:02:35 +01:00
Cargo.toml Keyboard core: Rust workspace, HXTM v3 model reader, and the C interface for swipe 2026-11-22 20:02:26 +01:00
README.md Keyboard core builds take Homebrew's rustup: a cargo that runs the pinned toolchain 2026-11-22 20:02:35 +01:00
rust-toolchain.toml Keyboard core: Rust workspace, HXTM v3 model reader, and the C interface for swipe 2026-11-22 20:02:26 +01:00

Hex keyboard core

The keyboard's platform-independent logic in Rust, shared by the iOS keyboard extension (ios/HEXKeyboard, through ios/HEXShared) and the Android IME (android/app). Each OS keeps its own layer on top: views, touches, the text field, haptics, dictation, storage, and anything only the OS can answer (Apple's spelling checker, the system lexicon).

  • core/ (hex-keyboard-core): safe Rust. It never reads a clock, a file or the OS; the host passes in times, key geometry and data.
  • ffi/ (hex-keyboard-ffi, library hex_keyboard): the C interface in include/hex_keyboard.h (Swift imports it as HexKeyboardCore), and with the jni feature the Android entry points. All unsafe code is here; every entry point catches panics.

This is its own Cargo workspace with its own Cargo.lock and pinned toolchain (rust-toolchain.toml), so the desktop workspace never builds it.

Pieces move here one at a time from the Swift keyboard (ios/HEXShared/FullKeyboard), each proven identical to the Swift it replaces before iOS switches to it. Today: the typing model reader and Swipe typing's decoder. Tune those here, not in Swift.

Setup

Install rustup (rustup.rs or brew install rustup): in this folder it uses the toolchain, components and targets rust-toolchain.toml pins (rustup toolchain install fetches them ahead). iOS's build (ios/scripts/build-keyboard-core.sh, HEXKeyboard's first build phase), Xcode Cloud's ci_post_clone.sh and Android's debug build find it the same way (tools/rustup-env.sh): on PATH, in CARGO_HOME (by default ~/.cargo), or Homebrew's (opt/rustup/bin or bin under HOMEBREW_PREFIX), taking only a cargo that runs the pinned toolchain here. Android also needs cargo install cargo-ndk.

cd crates/keyboard
cargo test --all-features
cargo clippy --all-targets --all-features -- -D warnings

--all-features includes the jni feature, so the Android entry points (ffi/src/jni.rs) are checked too.

Tune Swipe typing here, in core/src/swipe: iOS's SwipeDecoder is a wrapper of it. The decoder was ported from the Swift one it replaced, and proven to read every swipe as it did (the same candidates in the same order, costs equal bit for bit) on 200,000 generated swipes, in a separate run and in one process, and on recorded FUTO swipes typed through the keyboard. The committed core/tests/fixtures/swipe-parity.jsonl holds 800 of those swipes per language with the Swift decoder's readings: core/tests/swipe_parity.rs checks the core against it (and, with HEX_SWIPE_PARITY=<file>, a larger export), and iOS's SwipeFixtureTests checks the shipped path through the C interface. A change that reads any swipe differently fails both: if it's intended, refresh the fixture from the app's decoder (the simulator writes to the Mac's /tmp) and commit it with the change:

cd ios && xcodegen generate
TEST_RUNNER_HEX_SWIPE_PARITY_OUT=/tmp/swipe-parity.jsonl TEST_RUNNER_HEX_SWIPE_PARITY_COUNT=800 \
  xcodebuild test -project HEXMobile.xcodeproj -scheme HEXMobile \
  -destination 'platform=iOS Simulator,name=<simulator>' \
  -only-testing:HEXMobileTests/SwipeParityExportTests
cp /tmp/swipe-parity.jsonl ../crates/keyboard/core/tests/fixtures/swipe-parity.jsonl
cd ../crates/keyboard && cargo test --release --test swipe_parity -- --nocapture

TEST_RUNNER_HEX_SWIPE_PARITY_TIMING=1 adds each read's time; a larger count makes a larger file for HEX_SWIPE_PARITY.