macos-singletons-removal

macos-singletons-removal is a cursor rule for Cursor from duckduckgo/apple-browsers. It costs 0 tokens per session (3,462 once invoked), scanned A, original, Apache-2.0.

A macOS architecture rule for replacing global .shared singletons with app-owned objects passed into other components through dependency injection.

In plain words
What is it for?
Use it when refactoring AppDelegate-owned services such as preferences, storage, window managers, and feature-flag components.
Why use it?
It reduces hidden global state and makes dependencies easier to replace and test.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when refactoring AppDelegate-owned services such as preferences, storage, window managers, and feature-flag components.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/duckduckgo/apple-browsers/macos-singletons-removal
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/duckduckgo/apple-browsers

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for macos-singletons-removal

README.md
[![agentmods](https://agentmods.dev/badge/rules/duckduckgo/apple-browsers/macos-singletons-removal.svg)](https://agentmods.dev/rules/duckduckgo/apple-browsers/macos-singletons-removal)
Your own site
<a href="https://agentmods.dev/rules/duckduckgo/apple-browsers/macos-singletons-removal"><img src="https://agentmods.dev/badge/rules/duckduckgo/apple-browsers/macos-singletons-removal.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 3,462 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.03462
Opus 5 $0.00000 $0.01731
Sonnet 5 $0.00000 $0.00692
Haiku 4.5 $0.00000 $0.00346

Measured 6d ago against content hash 6eb0a6a97838, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

macos-singletons-removal scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/macos-singletons-removal.mdc · 217 lines

How it starts

The opening of the file, as written. The whole thing — 217 lines — stays where its author put it; the contents beside it link to each section on GitHub.

macOS Singleton Removal Rules

Purpose

Define a concrete pattern for removing .shared singletons in the macOS app by replacing them with app-owned instances and dependency injection. The AIChatPreferences and AboutPreferences refactors in AppDelegate are canonical examples.

Rules

  1. Do not introduce new singletons

    • Never add new static let shared or similar global singletons.
    • New dependencies must be passed in via initializers or factory methods, not fetched from global state.
  2. Move ownership to the composition root (AppDelegate)

    • Add a stored property on the macOS composition root (currently AppDelegate) for the dependency, for example:
      • let aiChatPreferences: AIChatPreferences
    • Construct the instance during app setup using real dependencies:
      • Inject storage (e.g. DefaultAIChatPreferencesStorage)
      • Inject configuration objects (e.g. AIChatMenuVisibilityConfigurable)
      • Inject window managers via protocols (e.g. WindowControllersManagerProtocol)
      • Inject feature flaggers and other services as needed
    • Prefer protocol-typed properties in AppDelegate when the dependency has a clear protocol (to keep testing and substitution easy).
  3. Thread the dependency through initializers

    • For view controllers and models that need the former singleton, add initializer parameters and store them as non-optional properties. Example:
      • init(..., aiChatPreferences: AIChatPreferences = NSApp.delegateTyped.aiChatPreferences, ...)
    • Avoid using NSApp.delegateTyped or Application.appDelegate and prefer to pass the dependency down from a parent object.
      • If a parent object doesn't contain the dependency, it should be updated to have it passed down from its own parent object, observing the exceptions mentioned below.
    • It is explicitly allowed to use NSApp.delegateTyped:
      • In the Tab initializer (following the existing pattern for other dependencies)
      • In default parameter values for the MainViewController initializer (this is the entry point for the dependency chain)
      • In default parameter values for the TabCollectionViewModel initializer (following the existing pattern for other dependencies)
      • In default parameter values for the TabViewModel initializer (temporary exception, will be refactored later)
      • Exception: For @MainActor initializers, use optional parameters with nil defaults and assign from NSApp.delegateTyped in the initializer body.
    • Important: Main actor isolation: If an initializer is marked @MainActor and you need to default a parameter from NSApp.delegateTyped, use an optional parameter with nil default instead of accessing NSApp.delegateTyped in the default value. Then assign the value inside the initializer body:
      • init(savedZoomLevelsCoordinating: SavedZoomLevelsCoordinating = NSApp.delegateTyped.accessibilityPreferences) (causes main actor isolation warning)
      • init(savedZoomLevelsCoordinating: SavedZoomLevelsCoordinating? = nil) with self.savedZoomLevelsCoordinating = savedZoomLevelsCoordinating ?? NSApp.delegateTyped.accessibilityPreferences in the body
    • When creating child objects from a parent that already has the dependency, pass the property down rather than re-reading from NSApp.delegateTyped.
    • For preferences models that need to reach SwiftUI views, thread through the entire chain:
      • MainViewController (with default parameter) → BrowserTabViewControllerPreferencesViewControllerPreferencesSidebarModelPreferencesRootView
      • Follow the existing pattern used by other preferences (e.g., searchPreferences, tabsPreferences, aiChatPreferences)
      • When adding to PreferencesSidebarModel, add the property alongside existing preferences and update both the main init and convenience init
    • For dependencies that need to reach UserScripts initialization (e.g., DuckPlayerPreferences), thread through the content blocking infrastructure:
      • AppDelegateAppContentBlockingUserContentUpdatingScriptSourceProvider (via ScriptSourceProviding protocol) → UserScripts
      • Add the dependency to ScriptSourceProviding protocol as a property
      • Add it to ScriptSourceProvider struct (property and initializer parameter)
      • Add it to UserContentUpdating initializer and pass to ScriptSourceProvider in makeValue closure
      • Add it to AppContentBlocking initializers (both convenience and main) and pass to UserContentUpdating
      • Pass it from AppDelegate to AppContentBlocking initialization
      • In UserScripts, access via sourceProvider.duckPlayerPreferences instead of using a default parameter
      • This follows the same pattern as WebTrackingProtectionPreferences and CookiePopupProtectionPreferences

Read the full file on GitHub · 217 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 217 lines · 0 tokens per session scan A 6eb0a6a97838

Subscribe to this mod's changes

macos-singletons-removal is a cursor rule published in the GitHub repository duckduckgo/apple-browsers (251 stars, last pushed today), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 3,462 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-01.