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:
@@ -17,20 +17,53 @@ final class AIAgentSkillLayoutTests: XCTestCase {
|
||||
let defaults = makeDefaults()
|
||||
let layout = AppGroupStore(defaults: defaults).agentSkillLayout
|
||||
XCTAssertEqual(layout.enabledIDs, AIAgentSkillLayout.defaultEnabledIDs)
|
||||
XCTAssertEqual(layout.enabledIDs, AIClipboardSkillCatalog.catalog.map(\.id))
|
||||
XCTAssertEqual(
|
||||
layout.enabledIDs,
|
||||
AIClipboardSkillCatalog.catalog.filter(\.isDefault).map(\.id)
|
||||
)
|
||||
// "Speak as me" is included: it has no toggle of its own, and the
|
||||
// personal-style gate keeps it off the keyboard until one is distilled.
|
||||
XCTAssertTrue(layout.enabledIDs.contains(AIClipboardSkillCatalog.speakAsMeID))
|
||||
XCTAssertTrue(layout.confirmedShortcutIDs.isEmpty)
|
||||
}
|
||||
|
||||
/// The skill has no switch of its own. It ships enabled, and distilling a
|
||||
/// personal style is the single act that makes it reachable.
|
||||
func testSpeakAsMeShipsEnabledAndIsGatedOnlyByThePersonalStyle() {
|
||||
let store = AIAgentSkillLayoutStore(defaults: makeDefaults())
|
||||
XCTAssertTrue(store.layout.isEnabled(AIClipboardSkillCatalog.speakAsMeID))
|
||||
|
||||
XCTAssertFalse(
|
||||
AIClipboardSkillCatalog.availableEnabledIDs(
|
||||
store.layout.enabledIDs,
|
||||
layout: store.layout,
|
||||
hasPersonalReplyStyle: false
|
||||
).contains(AIClipboardSkillCatalog.speakAsMeID)
|
||||
)
|
||||
XCTAssertTrue(
|
||||
AIClipboardSkillCatalog.availableEnabledIDs(
|
||||
store.layout.enabledIDs,
|
||||
layout: store.layout,
|
||||
hasPersonalReplyStyle: true
|
||||
).contains(AIClipboardSkillCatalog.speakAsMeID)
|
||||
)
|
||||
}
|
||||
|
||||
func testSystemSemanticSkillsStayEnabledButHiddenFromSkillManagement() {
|
||||
let store = AIAgentSkillLayoutStore(defaults: makeDefaults())
|
||||
let hiddenIDs = AIClipboardSkillCatalog.hiddenFromSkillManagementIDs
|
||||
|
||||
// "Hidden" means system action: always enabled, never user-managed.
|
||||
XCTAssertTrue(hiddenIDs.isSubset(of: Set(store.enabledSkills.map(\.id))))
|
||||
// The lists additionally omit skills managed from elsewhere in the UI,
|
||||
// which are not necessarily enabled.
|
||||
let omittedIDs = AIClipboardSkillCatalog.managedOutsideSkillListIDs
|
||||
XCTAssertTrue(hiddenIDs.isSubset(of: omittedIDs))
|
||||
XCTAssertTrue(
|
||||
hiddenIDs.isDisjoint(with: Set(store.skillManagementEnabledSkills.map(\.id)))
|
||||
omittedIDs.isDisjoint(with: Set(store.skillManagementEnabledSkills.map(\.id)))
|
||||
)
|
||||
XCTAssertTrue(
|
||||
hiddenIDs.isDisjoint(with: Set(store.skillManagementAvailableSkills.map(\.id)))
|
||||
omittedIDs.isDisjoint(with: Set(store.skillManagementAvailableSkills.map(\.id)))
|
||||
)
|
||||
XCTAssertTrue(
|
||||
store.skillManagementEnabledSkills.contains {
|
||||
@@ -445,25 +478,25 @@ final class AIAgentSkillLayoutTests: XCTestCase {
|
||||
|
||||
func testCannotEnableExportSkillBeforeShortcutConfirmation() {
|
||||
let store = AIAgentSkillLayoutStore(defaults: makeDefaults())
|
||||
store.disable(AIClipboardSkillCatalog.extractTodosID)
|
||||
store.disable(AIClipboardSkillCatalog.saveToNotesID)
|
||||
XCTAssertEqual(
|
||||
store.enable(AIClipboardSkillCatalog.extractTodosID),
|
||||
store.enable(AIClipboardSkillCatalog.saveToNotesID),
|
||||
.needsShortcut
|
||||
)
|
||||
XCTAssertFalse(store.layout.isEnabled(AIClipboardSkillCatalog.extractTodosID))
|
||||
XCTAssertFalse(store.layout.isEnabled(AIClipboardSkillCatalog.saveToNotesID))
|
||||
}
|
||||
|
||||
func testConfirmShortcutAutoEnablesWhenSlotAvailable() {
|
||||
let store = AIAgentSkillLayoutStore(defaults: makeDefaults())
|
||||
store.disable(AIClipboardSkillCatalog.extractTodosID)
|
||||
store.disable(AIClipboardSkillCatalog.saveToNotesID)
|
||||
XCTAssertEqual(
|
||||
store.confirmShortcutAndEnable(AIClipboardSkillCatalog.extractTodosID),
|
||||
store.confirmShortcutAndEnable(AIClipboardSkillCatalog.saveToNotesID),
|
||||
.enabled
|
||||
)
|
||||
XCTAssertTrue(store.layout.hasConfirmedShortcut(AIClipboardSkillCatalog.extractTodosID))
|
||||
XCTAssertTrue(store.layout.hasConfirmedShortcut(AIClipboardSkillCatalog.saveToNotesID))
|
||||
XCTAssertEqual(
|
||||
store.layout.enabledIDs.last,
|
||||
AIClipboardSkillCatalog.extractTodosID
|
||||
AIClipboardSkillCatalog.saveToNotesID
|
||||
)
|
||||
}
|
||||
|
||||
@@ -527,12 +560,12 @@ final class AIAgentSkillLayoutTests: XCTestCase {
|
||||
|
||||
func testDisableKeepsShortcutConfirmation() {
|
||||
let store = AIAgentSkillLayoutStore(defaults: makeDefaults())
|
||||
store.disable(AIClipboardSkillCatalog.extractTodosID)
|
||||
_ = store.confirmShortcutAndEnable(AIClipboardSkillCatalog.extractTodosID)
|
||||
store.disable(AIClipboardSkillCatalog.extractTodosID)
|
||||
XCTAssertFalse(store.layout.isEnabled(AIClipboardSkillCatalog.extractTodosID))
|
||||
XCTAssertTrue(store.layout.hasConfirmedShortcut(AIClipboardSkillCatalog.extractTodosID))
|
||||
XCTAssertEqual(store.enable(AIClipboardSkillCatalog.extractTodosID), .enabled)
|
||||
store.disable(AIClipboardSkillCatalog.saveToNotesID)
|
||||
_ = store.confirmShortcutAndEnable(AIClipboardSkillCatalog.saveToNotesID)
|
||||
store.disable(AIClipboardSkillCatalog.saveToNotesID)
|
||||
XCTAssertFalse(store.layout.isEnabled(AIClipboardSkillCatalog.saveToNotesID))
|
||||
XCTAssertTrue(store.layout.hasConfirmedShortcut(AIClipboardSkillCatalog.saveToNotesID))
|
||||
XCTAssertEqual(store.enable(AIClipboardSkillCatalog.saveToNotesID), .enabled)
|
||||
}
|
||||
|
||||
func testReorderMovesEnabledSkill() {
|
||||
@@ -552,23 +585,21 @@ final class AIAgentSkillLayoutTests: XCTestCase {
|
||||
|
||||
func testReorderMovesEnabledSkillToIndex() {
|
||||
let store = AIAgentSkillLayoutStore(defaults: makeDefaults())
|
||||
// Derived from the default order rather than hardcoded: this asserts
|
||||
// the move, not which skills happen to lead the catalog.
|
||||
var others = AIAgentSkillLayout.defaultEnabledIDs
|
||||
others.removeAll { $0 == AIClipboardSkillCatalog.summarizeID }
|
||||
let leading = Array(others.prefix(2))
|
||||
|
||||
store.moveEnabled(id: AIClipboardSkillCatalog.summarizeID, toIndex: 2)
|
||||
XCTAssertEqual(
|
||||
Array(store.layout.enabledIDs.prefix(3)),
|
||||
[
|
||||
AIClipboardSkillCatalog.replyID,
|
||||
AIClipboardSkillCatalog.translateID,
|
||||
AIClipboardSkillCatalog.summarizeID
|
||||
]
|
||||
leading + [AIClipboardSkillCatalog.summarizeID]
|
||||
)
|
||||
store.moveEnabled(id: AIClipboardSkillCatalog.summarizeID, toIndex: 0)
|
||||
XCTAssertEqual(
|
||||
Array(store.layout.enabledIDs.prefix(3)),
|
||||
[
|
||||
AIClipboardSkillCatalog.summarizeID,
|
||||
AIClipboardSkillCatalog.replyID,
|
||||
AIClipboardSkillCatalog.translateID
|
||||
]
|
||||
[AIClipboardSkillCatalog.summarizeID] + leading
|
||||
)
|
||||
}
|
||||
|
||||
@@ -655,12 +686,12 @@ final class AIAgentSkillLayoutTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testShortcutsRunURLIncludesNameAndText() {
|
||||
let shortcutName = AIClipboardSkillCatalog.extractTodosShortcutName
|
||||
let shortcutName = AIClipboardSkillCatalog.saveToNotesShortcutName
|
||||
let url = AIAgentShortcutRun.shortcutsRunURL(name: shortcutName, text: "买牛奶\n回邮件")
|
||||
XCTAssertEqual(url?.scheme, "shortcuts")
|
||||
XCTAssertEqual(url?.host, "run-shortcut")
|
||||
let items = URLComponents(url: url!, resolvingAgainstBaseURL: false)?.queryItems ?? []
|
||||
XCTAssertEqual(items.first { $0.name == "name" }?.value, "OSGExtractTodos")
|
||||
XCTAssertEqual(items.first { $0.name == "name" }?.value, "OSGSaveToNotes")
|
||||
XCTAssertEqual(items.first { $0.name == "input" }?.value, "text")
|
||||
XCTAssertEqual(items.first { $0.name == "text" }?.value, "买牛奶\n回邮件")
|
||||
XCTAssertNil(items.first { $0.name == "x-success" })
|
||||
@@ -668,7 +699,7 @@ final class AIAgentSkillLayoutTests: XCTestCase {
|
||||
|
||||
func testXCallbackRunURLUsesCallbackHost() {
|
||||
let url = AIAgentShortcutRun.shortcutsRunURL(
|
||||
name: AIClipboardSkillCatalog.extractTodosShortcutName,
|
||||
name: AIClipboardSkillCatalog.saveToNotesShortcutName,
|
||||
text: "买牛奶",
|
||||
xSuccess: "osgkeyboard://skill/shortcut-result?status=success",
|
||||
xError: "osgkeyboard://skill/shortcut-result?status=error",
|
||||
@@ -689,21 +720,25 @@ final class AIAgentSkillLayoutTests: XCTestCase {
|
||||
XCTAssertEqual(AIAgentShortcutRun.preview("买牛奶\n回邮件"), "买牛奶\\n回邮件")
|
||||
}
|
||||
|
||||
func testExtractTodosUsesBundledShortcut() {
|
||||
func testExtractTodosIsNativeWithoutShortcut() {
|
||||
// Reminders are created natively via EventKit in the host, so this
|
||||
// built-in skill must not carry any companion Shortcut metadata.
|
||||
let skill = AIClipboardSkillCatalog.skill(id: AIClipboardSkillCatalog.extractTodosID)
|
||||
XCTAssertNil(skill?.shortcutICloudURL)
|
||||
XCTAssertEqual(skill?.shortcutName, "OSGExtractTodos")
|
||||
XCTAssertEqual(skill?.shortcutResourceName, "OSGExtractTodos")
|
||||
XCTAssertNil(skill?.shortcutName)
|
||||
XCTAssertNil(skill?.shortcutResourceName)
|
||||
XCTAssertFalse(skill?.requiresShortcut ?? true)
|
||||
XCTAssertEqual(skill?.kind, .export)
|
||||
}
|
||||
|
||||
func testExtractEventsUsesBundledShortcut() {
|
||||
func testExtractEventsIsNativeWithoutShortcut() {
|
||||
// Calendar events are created natively via EventKit in the host, so this
|
||||
// built-in skill must not carry any companion Shortcut metadata.
|
||||
let skill = AIClipboardSkillCatalog.skill(id: AIClipboardSkillCatalog.extractEventsID)
|
||||
XCTAssertNil(skill?.shortcutICloudURL)
|
||||
XCTAssertEqual(skill?.shortcutName, "OSGExtractEvents")
|
||||
XCTAssertEqual(
|
||||
skill?.shortcutResourceName,
|
||||
"OSGExtractEvents"
|
||||
)
|
||||
XCTAssertNil(skill?.shortcutName)
|
||||
XCTAssertNil(skill?.shortcutResourceName)
|
||||
XCTAssertFalse(skill?.requiresShortcut ?? true)
|
||||
XCTAssertEqual(skill?.systemImage, "calendar")
|
||||
XCTAssertTrue(skill?.isDefault ?? false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user