You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[desktop/macos] Global state: 107 singletons, 476 raw UserDefaults accesses, 62 inline string keys #8845
App state flows through implicit globals rather than injected dependencies:
107 files declare static let shared singletons (111 total). View models reach directly into them — e.g. Providers/ChatProvider.swift touches 16 distinct singletons (APIClient.shared, AuthService.shared, RewindDatabase.shared, MemoryStorage.shared, …), which is why it's effectively untestable and why the test suite has evolved into testing extracted policy structs instead.
476 UserDefaults.standard call sites with 62+ distinct inline string keys. The same literal is retyped across files: "auth_userId" ×18, "playwrightExtensionToken" ×11, "hasCompletedFileIndexing" ×10, "chatBridgeMode" ×6. A typo compiles fine and silently reads nil/false — in auth and onboarding paths.
123 NotificationCenter.default.post sites across 57 notification names used as a cross-module event bus (names are at least defined once each — good).
Why it matters
At ~1190 commits/month with agent authors, conventions held only by grep are probabilistically failing: nothing stops the 63rd key or the 108th singleton, and no compiler error catches "auth_userid".
Suggested fix (mechanical)
Create one DefaultsKeys namespace (enum of static let keys, or a typed @UserDefault property-wrapper layer) and migrate call sites file-by-file.
Add a CI grep-gate: forKey: " string literals are only allowed in the keys file(s); new violations fail lint. This freezes the problem immediately even before migration finishes.
For testability, don't attempt global DI — just give the worst offenders (ChatProvider, TasksStore) initializer-injected protocol seams for the 2–3 dependencies their logic actually branches on, defaulting to .shared.
Positive pattern worth protecting
The "extract pure policy struct + unit-test it" pattern (ConversationReconciliationPolicy, DashboardTaskRefreshPolicy, PushToTalkStateMachine…) is the right countermeasure and should be named in AGENTS.md as the standard for new logic.
Activity