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
@@ -88,10 +88,26 @@ struct CandidateExpandGridView: UIViewRepresentable {
_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath
) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(
let dequeued = collectionView.dequeueReusableCell(
withReuseIdentifier: Cell.reuseID,
for: indexPath
) as! Cell
)
guard let cell = dequeued as? Cell else { return dequeued }
// Rime refreshes the candidate list on every keystroke, so the
// collection view can still be laying out against the *previous*
// count when a new list lands. An out-of-range read here would
// crash the whole keyboard; render an empty cell instead — the
// pending `reloadData` repaints it a frame later.
guard candidates.indices.contains(indexPath.item) else {
cell.configure(
text: "",
emphasized: false,
textColor: textColor,
dividerColor: dividerColor,
showDivider: false
)
return cell
}
let index = indexPath.item
cell.configure(
text: candidates[index].text,
@@ -20,6 +20,17 @@ struct KeyboardSurfaceRoot: View {
colorScheme == .dark ? Palette.dark : Palette.light
}
/// True only for overlays that replace the keyboard surface. The auto-reply
/// guide is excluded — it dims the keyboard but keeps it visible underneath.
private var surfacesHidden: Bool {
switch state.clipboardOverlay {
case .enableGuide, .historyPanel:
return true
case .none, .autoReplyGuide:
return false
}
}
/// Height is deliberately independent of the surface: the voice surface
/// adopts the typing surface's content-driven height and parks the surplus
/// above its action cluster, so switching surfaces never resizes the
@@ -59,14 +70,25 @@ struct KeyboardSurfaceRoot: View {
)
}
}
.opacity(state.clipboardOverlay == .none ? 1 : 0)
.allowsHitTesting(state.clipboardOverlay == .none)
// The enable-guide / history panel replace the surface; the
// auto-reply guide instead layers over the still-visible keyboard.
.opacity(surfacesHidden ? 0 : 1)
.allowsHitTesting(!surfacesHidden)
// Match every surface's outer chrome so the panel title / X sit in
// the same slot as the logo + clipboard chip (not 4 pt higher).
clipboardOverlayLayer
.padding(.top, TypingSurfaceMetrics.outerPaddingTop)
.padding(.bottom, TypingSurfaceMetrics.outerPaddingBottom)
// Scrim-based nudge sits on top of the live keyboard, no padding so
// the dim reaches every edge.
if state.clipboardOverlay == .autoReplyGuide, state.canShowClipboardEntry {
ClipboardAutoReplyGuideView(
onClose: state.dismissClipboardOverlay,
onTry: state.tryAutoReplyFromGuide
)
}
}
// Overlays are siblings of the surfaces, so the palette has to be
// injected here or they fall back to the environment's dark default.
@@ -123,6 +145,9 @@ struct KeyboardSurfaceRoot: View {
? ExtL10n.string("keyboard.clipboard.panel.fullAccessHint")
: nil
)
case .autoReplyGuide:
// Rendered as a scrim layer over the live keyboard, not here.
EmptyView()
}
}
}
+43 -16
View File
@@ -125,12 +125,33 @@ struct TypingRootView: View {
} else if state.canShowClipboardEntry,
let suggestion = state.clipboardSuggestionText,
!suggestion.isEmpty {
// Same slot as logo + capsule tabs — hide chrome until dismissed.
ClipboardSuggestionBar(
text: suggestion,
onInsert: { state.insertClipboardText(suggestion) },
onDismiss: state.dismissClipboardSuggestion
)
// A fresh copy: a "Paste" glass capsule (matching the assistant
// surface) replaces the input tabs until inserted or dismissed.
HStack(spacing: 6) {
Button {
state.insertClipboardText(suggestion)
} label: {
Text(ExtL10n.string("keyboard.clipboard.paste"))
.font(TypeStyle.footnote.weight(.semibold))
.foregroundStyle(palette.textPrimary)
.lineLimit(1)
.padding(.horizontal, 14)
.frame(height: 30)
.glassEffect(.regular.interactive(), in: Capsule())
}
.buttonStyle(.plain)
.accessibilityIdentifier("typing.clipboard.paste")
.accessibilityLabel(ExtL10n.text("keyboard.clipboard.paste"))
Spacer(minLength: 0)
KeyboardCancelButton(
action: state.dismissClipboardSuggestion,
accessibilityLabel: ExtL10n.text("keyboard.assistant.dismissClipboard"),
accessibilityHint: ExtL10n.text("keyboard.assistant.dismissClipboardHint"),
accessibilityIdentifier: "typing.clipboard.dismiss"
)
}
.padding(.horizontal, KeyboardTopBarMetrics.nestedHorizontalInset)
} else {
idleTopBar
@@ -191,7 +212,7 @@ struct TypingRootView: View {
Button(action: state.openInputMethodSetup) {
HStack(spacing: 2) {
Text(message)
.font(.system(size: 11))
.font(TypeStyle.caption2.weight(.regular))
.lineLimit(1)
Image(systemName: "arrow.up.right")
.font(.system(size: 9, weight: .semibold))
@@ -203,7 +224,7 @@ struct TypingRootView: View {
.accessibilityHint(ExtL10n.text("keyboard.typing.setupA11yHint"))
} else {
Text(message)
.font(.system(size: 11))
.font(TypeStyle.caption2.weight(.regular))
.foregroundStyle(palette.danger)
.lineLimit(1)
}
@@ -316,7 +337,7 @@ struct TypingRootView: View {
}
} else {
Text(candidate.text)
.font(.system(size: 20, weight: .regular))
.font(TypeStyle.title3.weight(.regular))
.foregroundStyle(palette.textPrimary)
.padding(.horizontal, 10)
.frame(height: 40)
@@ -367,7 +388,13 @@ struct TypingRootView: View {
}
.buttonStyle(.plain)
.padding(.trailing, KeyboardTopBarMetrics.nestedHorizontalInset)
.accessibilityLabel(typing.isCandidatePanelExpanded ? "收起候选" : "更多候选")
.accessibilityLabel(
ExtL10n.string(
typing.isCandidatePanelExpanded
? "keyboard.typing.candidates.collapseA11y"
: "keyboard.typing.candidates.expandA11y"
)
)
}
private var expandChevronFill: Color {
@@ -414,7 +441,7 @@ struct TypingRootView: View {
) -> some View {
Button(action: action) {
Image(systemName: systemName)
.font(.system(size: 15, weight: .medium))
.font(TypeStyle.bodyEmph)
.foregroundStyle(enabled ? palette.textSecondary : palette.textTertiary)
.frame(width: 34, height: 34)
.background(enabled ? editingToolbarButtonFill : .clear, in: Circle())
@@ -595,7 +622,7 @@ struct TypingRootView: View {
Group {
if key.label == "⌫" {
Image(systemName: "delete.left")
.font(.system(size: 20, weight: .medium))
.font(TypeStyle.title3.weight(.medium))
.foregroundStyle(keyTextColor)
} else if key.label == "⇧" {
Image(systemName: typing.isShiftEnabled ? "shift.fill" : "shift")
@@ -684,8 +711,8 @@ struct TypingRootView: View {
case TypingKeyLayoutBuilder.BottomKeyID.space.rawValue:
return key.label
default:
if key.label == "⇧" { return "shift" }
if key.label == "⌫" { return "delete" }
if key.label == "⇧" { return ExtL10n.string("keyboard.key.shiftA11y") }
if key.label == "⌫" { return ExtL10n.string("keyboard.key.deleteA11y") }
return key.label
}
}
@@ -722,7 +749,7 @@ struct TypingRootView: View {
private var returnKeyLabel: some View {
if state.returnKeyRole.usesActionFill {
ExtL10n.text(state.returnKeyRole.titleKey)
.font(.system(size: 15, weight: .semibold))
.font(TypeStyle.body.weight(.semibold))
.lineLimit(1)
.minimumScaleFactor(0.6)
} else {
@@ -803,7 +830,7 @@ struct TypingRootView: View {
if state.returnKeyRole.usesActionFill {
return ExtL10n.string(state.returnKeyRole.titleKey)
}
return "return"
return ExtL10n.string("keyboard.key.returnA11y")
}
private var returnKeyTextColor: Color {