audit-swiftui-state-observation

Audits macOS SwiftUI state ownership and @Observable observation code for wrapper mismatches and world-mixing defects.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI-generated SwiftUI code frequently pairs the wrong property wrapper with a model's kind — initializing models inside @ObservedObject, mixing the legacy ObservableObject world with the modern @Observable macro, or missing @Bindable projections — producing silent runtime state resets or compile errors that are hard to spot. ## Core Features & Use Cases - Twelve-rule defect index: Detects wrong ownership wrappers, redundant ObservableObject conformance, stray @Published under @Observable, legacy environment injection, missing @Bindable, and observation-granularity smells (state-01 through state-12). - Hybrid lint engine: Runs tier-1 grep tells plus tier-2 ast-grep structural rules via a shared runner that emits unified JSON and SARIF with per-file parse probes. - Grounded verification: Confirms findings against a corpus of 1,857 shipping macOS apps via the swiftui-ctx CLI and Apple documentation fetched through Sosumi, with a fix-safety protocol for the two auto-fixable rules. - Use Case: Point the skill at an in-progress macOS SwiftUI project to receive per-file findings classifying each model as modern, legacy, or mixed, with severity, failure shape, and permalinked correct code examples. ## Quick Start Ask the agent to audit the SwiftUI state and observation code in your macOS project directory and report any wrong-wrapper or mixed-world defects.

Frequently Asked Questions about audit-swiftui-state-observation

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

FAQPage Schema
How do I audit SwiftUI state management code for @Observable mistakes?

Run the skill's shared lint runner against your SwiftUI sources, then read each located file in full to classify the model kind before reporting. The skill checks twelve defect rules covering ownership wrappers, world mixing, @Bindable projection, and environment injection.

What is the difference between @StateObject and @State for @Observable models?

@State owns a modern @Observable model created by the view, while @StateObject is the legacy owner for ObservableObject classes. Using @StateObject on a plain @Observable compiles but is a migration smell; on a struct it is a hard compile error.

Does this skill work on iOS or cross-platform SwiftUI projects?

No, the audit is macOS-only and SwiftUI-only. Its rules, availability floors such as macOS 14 for @Observable and macOS 26 for Observations, and its multi-window scene-level injection guidance are specific to macOS apps.

Why does @ObservedObject with an initializer cause bugs in SwiftUI?

@ObservedObject does not own its object, so an initializer on it recreates the model on every parent re-render, silently resetting state when the model is a real ObservableObject. If the model is @Observable, the same code typically fails to compile because @Observable does not conform to ObservableObject.

Can the skill automatically fix the defects it finds?

Only two mechanical fixes are applied automatically: dropping redundant ObservableObject conformance and removing @Published inside an @Observable class. All other findings are flag-only because wrapper swaps depend on ownership intent a human must confirm.

What are the limitations of the lint detection rules?

The grep and ast-grep rules only locate candidates and cannot judge model kind, ownership, or cross-scope @Bindable re-wraps. Every hit must be read in full by the agent, and findings are reported only at 100 percent certainty.