feat(app): add crash visibility, memory relief, and clipboard reply work

Squashes the working tree that had accumulated on cloud-agent. Two
strands of work, kept in one commit at the maintainer's request.

Crash and stability (this session):

- Subscribe to MetricKit so crash, hang, CPU, and disk-write diagnostics
  are recorded on device. Keyboard-extension memory kills are the most
  likely way a user loses the keyboard mid-sentence and iOS does not
  classify them as crashes, so they never reach App Store Connect.
- Upload those reports to POST /v1/analytics/diagnostics from internal
  builds only (local Debug and TestFlight), reusing the analytics
  installation identifier and skipping entirely when analytics are off.
  App Store builds keep everything on device.
- Shed the Chinese engine, English lexicon, and in-flight pipeline work
  at the 40 MiB and 48 MiB budget thresholds instead of waiting for a
  system memory warning that jetsam often preempts.
- Install audio taps with the input node's live format through one
  shared adaptive resampler, so an audio-route change mid-recording no
  longer raises an uncatchable format-mismatch exception. Covers the
  dictation preview and the Mac recorder, which still used the pattern
  the Flow capture path had already moved away from.
- Harden the librime bridge: never pass a nil string across a nonnull
  boundary when a user dictionary holds malformed UTF-8, null-check the
  engine API vector, and distrust a candidate count without its array.
- Guard the expanded candidate grid against a list that shrinks while
  the collection view is still laying out against the previous count.
- Resolve localized text without the App Group so the screen shown when
  that container is missing renders its message instead of crashing on
  launch, which is the one situation it exists to handle.
- Gate CI on the App Group and Keychain wiring that the keyboard
  extension hard-depends on, with a self-test proving the check fails.

Clipboard, reply, and semantics (pre-existing working tree):

- Unify the reply center, refresh keyboard AI features, and add native
  event and reminder exporters.
- Expand clipboard semantic routing with authored corpora and a
  product-blind holdout, plus the scripts that build and validate them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-18 17:31:29 -07:00
co-authored by Claude Opus 5
parent 628e983794
commit 0023741455
210 changed files with 14731 additions and 2940 deletions
@@ -21,6 +21,9 @@ public final class KeyboardState: ObservableObject {
case none
case enableGuide
case historyPanel
/// One-time "try AI auto-reply" nudge, shown as a clean full-keyboard
/// layer for users who never turned auto mode on.
case autoReplyGuide
}
/// Pipeline phase. Errors are structured so the UI layer can choose
@@ -89,6 +92,9 @@ public final class KeyboardState: ObservableObject {
@Published public var phase: Phase = .idle
/// Active chrome. Forced to `.voice` while recording / processing.
@Published public var surface: Surface = .voice
/// Surface the user was on when auto mode switched them to `.voice` to show
/// an auto-reply. Restored when the reply is closed; nil when not auto-routed.
public var autoReplyReturnSurface: Surface?
@Published public var level: Double = 0
@Published public var mode: InputMode = .polish
@Published public var localeId: String = "auto"
@@ -150,6 +156,24 @@ public final class KeyboardState: ObservableObject {
}
/// Opt-in clipboard suggestion strip (requires history enabled).
@Published public var clipboardCandidateBarEnabled: Bool = false
/// Opt-in auto mode: a freshly copied replyable message is auto-routed into
/// the Reply flow when the keyboard opens (requires history enabled).
@Published public var clipboardAutoModeEnabled: Bool = false
/// Opt-in: auto-translate a freshly copied non-system-language paste on open.
@Published public var clipboardAutoTranslateEnabled: Bool = false
/// Opt-in: auto-draft a reply when a freshly copied paste is an email.
@Published public var clipboardAutoEmailReplyEnabled: Bool = false
/// When true, the current AI result is a *staged* auto result (auto-translate
/// or auto-email-reply): shown on the keyboard and inserted only when the
/// user taps the glass Insert button — never dropped straight into the field.
@Published public var autoResultReadOnly: Bool = false
/// Localization key for the staged auto result's glass Insert button, so the
/// label matches the action (e.g. "Insert translation" vs "Insert reply").
@Published public var autoResultInsertLabelKey: String = "keyboard.assistant.insertTranslation"
/// Clipboard skill that produced the currently shown result (reply / translate
/// / …). The result panel's top bar offers the *other* applicable skills, so
/// this one is excluded from that row. Nil when no clipboard result is active.
@Published public var activeClipboardSkillID: String?
/// Skills-tab order for clipboard chips. Empty → hint carousel.
@Published public var enabledClipboardSkillIDs: [String] = AIAgentSkillLayout.defaultEnabledIDs
/// Fully resolved enabled skills. Mirroring value-semantic content here
@@ -188,6 +212,12 @@ public final class KeyboardState: ObservableObject {
@Published public var clipboardSuggestionText: String?
/// Pasteboard changeCount associated with the current suggestion (for dismiss).
@Published public var clipboardSuggestionChangeCount: Int?
/// Newest clipboard entry the user dismissed from the AI skill top bar.
/// Shared (not view-local) so the dismissal survives surface switches —
/// otherwise recreating `AIKeyboardView` would resurrect the skill bar
/// while the paste suggestion stays suppressed. Reset when a new entry
/// arrives so a fresh copy re-shows the skills.
@Published public var dismissedClipboardSkillEntryID: UUID?
/// Typing-grid haptic strength (off / light / strong).
@Published public var keyboardHapticIntensity: KeyboardHapticIntensity = .default
/// Single source of truth for selecting iPad-scale keyboard metrics.
@@ -372,6 +402,9 @@ public final class KeyboardState: ObservableObject {
public var openInputMethodSetup: () -> Void = {}
/// Opens the host app Settings → Clipboard page (enable history toggle).
public var openClipboardSettings: () -> Void = {}
/// Confirms the full-keyboard "try AI auto-reply" guide: turns auto mode on
/// (persisted), dismisses the layer, and drafts a reply for the current copy.
public var tryAutoReplyFromGuide: () -> Void = {}
/// Top-bar clipboard button: guide when history off, else history panel.
public var openClipboardPanel: () -> Void = {}
public var dismissClipboardOverlay: () -> Void = {}