audit-swiftui-state-restoration

Audits macOS SwiftUI state restoration code for wrapper confusion, relaunch amnesia, and availability gating defects.

2|1|Updated Jun 7, 2026
One-click install
npx skills add https://github.com/yigitkonur/plugin-swiftui --skill audit-swiftui-state-restoration-yigitkonur
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: audit-swiftui-state-restoration
Source: https://github.com/yigitkonur/plugin-swiftui/tree/main/plugins/swiftui/skills/audit-swiftui-state-restoration
Command: npx skills add https://github.com/yigitkonur/plugin-swiftui --skill audit-swiftui-state-restoration-yigitkonur

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires ast-grep, and includes scripts (resource) and references (resource) components.

What problem does it solve? SwiftUI state restoration defects compile cleanly but fail semantically: @AppStorage and @SceneStorage are interchangeable to the compiler, so per-window UI state leaks across windows, selections vanish on relaunch, and UIKit restoration symbols get hallucinated onto SwiftUI. This Skill audits a macOS SwiftUI project for 11 specific state-restoration defect classes and writes structured findings to disk. ## Core Features & Use Cases - 11-rule defect index (sr-01 to sr-11): Detects hallucinated UIKit restoration symbols, @AppStorage/@SceneStorage wrapper confusion, hand-rolled UserDefaults, unpersisted NavigationPath, oversized blobs in key-value storage, dead deep links, and ungated restorationBehavior/focusedSceneValue calls. - Hybrid lint engine: Runs tier-1 ripgrep tells plus a tier-2 ast-grep structural rule that proves a restorationBehavior call is not inside an #available(macOS 15) gate, emitting unified JSON and SARIF output. - Evidence-grounded verification: Cross-checks every uncertain claim against a corpus of 1,857 real shipping macOS apps via the swiftui-ctx CLI and Apple documentation fetched through Sosumi, reporting findings only at 100% certainty. - Use Case: Point it at an in-progress macOS SwiftUI app before release to catch the classic bug where a second window clobbers the first window's selected tab because the selection was bound to @AppStorage instead of @SceneStorage. ## Quick Start Audit the SwiftUI sources in my current macOS project for state restoration problems and write the findings to swiftui-audits/state-restoration.

Frequently Asked Questions about audit-swiftui-state-restoration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I audit SwiftUI state restoration on macOS?▼

Run the audit against your SwiftUI sources; it reads the deployment target, locates candidates with a hybrid grep and ast-grep lint engine, then reads each file in full before reporting. Confirmed findings are written as structured Markdown files under swiftui-audits/state-restoration with JSON and SARIF output.

What is the difference between @AppStorage and @SceneStorage?▼

@AppStorage holds one app-wide preference shared by every window, backed by UserDefaults. @SceneStorage holds per-window UI state like selected tabs or sidebar selection that the system restores per scene. The audit flags values stored in the wrong wrapper using the two-windows test.

Does the audit auto-fix the defects it finds?▼

No, every finding is flag-only because the correct fix depends on developer intent, such as whether a value is app-wide or per-window. Each finding includes the consensus-correct shape from real shipping apps plus a GitHub permalink and Apple documentation citation.

Can it detect UIKit restoration APIs misused in SwiftUI?▼

Yes, rule sr-01 hard-fails on UIKit or invented symbols like .restorationIdentifier, @StateRestoration, UIStateRestoring, and @FocusedDocument, none of which exist on SwiftUI macOS. A swiftui-ctx lookup exit code corroborates that no shipping Mac app uses the symbol.

Why does the audit need my project's deployment target?▼

The deployment target gates availability rules: restorationBehavior requires macOS 15 and focusedSceneValue has two floors (macOS 12 key-path, macOS 14 object overload). Ungated calls only count as defects when the target sits below the relevant floor.

What are the limitations of the lint detection?▼

The lint engine only locates candidates; wrapper-confusion defects are semantic and require reading each value's meaning before reporting. Cross-file protocol conformance and Info.plist scheme declarations also need manual confirmation, and parse warnings flag files that did not fully parse.