feat(keyboard): improve typing, voice flow, and polish reliability

Reduce extension memory pressure and delivery races while adding richer candidates, tactile feedback, and safer two-level creative polishing.
This commit is contained in:
Rocky
2026-08-05 21:39:31 +08:00
parent 38e5ad570d
commit 31f5937a7f
177 changed files with 8343 additions and 3904 deletions
@@ -0,0 +1,49 @@
// HostMemoryBudget.swift
// OSGKeyboard · Shared
//
// Shared RSS gate for host-side heavy work (Rime deploy, CLM, ASR warmup).
// Keeps the keyboard extension alive by avoiding host jetsam spikes.
import Foundation
public enum HostMemoryBudget {
/// Soft ceiling (MiB): defer CLM / Rime / ASR when resident memory is above this.
/// Host SwiftUI baseline alone is often ~150170 MB; 120 was always-trip and
/// left Rime/CLM permanently deferred while wrongly signaling hostHeavy.
public static let deferHeavyWorkAboveMB: Double = 260
public static let projectedPeakCeilingMB: Double = 290
public static var shouldDeferHeavyWork: Bool {
let rss = OSGDiag.memoryMB()
guard rss >= 0 else { return false }
return rss >= deferHeavyWorkAboveMB
}
public static func gate(
_ work: String,
category: String = "flow"
) -> Bool {
let rss = OSGDiag.memoryMB()
let estimatedGrowth: Double
if work.contains("clm") {
estimatedGrowth = 48
} else if work.contains("asr") {
estimatedGrowth = 32
} else if work.contains("rime") {
estimatedGrowth = 24
} else {
estimatedGrowth = 24
}
if shouldDeferHeavyWork
|| (rss >= 0 && rss + estimatedGrowth >= projectedPeakCeilingMB) {
OSGDiag.log(
"memoryGate defer work=\(work) \(OSGDiag.memoryTag()) "
+ "threshold=\(Int(deferHeavyWorkAboveMB))MB "
+ "projected=\(Int(max(0, rss + estimatedGrowth)))MB",
category: category
)
return false
}
return true
}
}