user-defaults-storage

user-defaults-storage is a cursor rule for Cursor from duckduckgo/apple-browsers. It costs 0 tokens per session (1,736 once invoked), scanned A, original, Apache-2.0.

A coding rule for storing new persistent application settings with a key-value store and a key-value-observing pattern. It shows how settings such as visibility preferences and update dates should be read and written.

In plain words
What is it for?
It guides implementation of persistent user preferences in the specified application, including typed keys, fallback values, and updates.
Why use it?
It prevents new settings from being stored through inconsistent mechanisms or with unclear defaults.

Cursor rule for Cursor

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.

agentmods
npx agentmods add rules/duckduckgo/apple-browsers/user-defaults-storage
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 user-defaults-storage

README.md
[![agentmods](https://agentmods.dev/badge/rules/duckduckgo/apple-browsers/user-defaults-storage.svg)](https://agentmods.dev/rules/duckduckgo/apple-browsers/user-defaults-storage)
Your own site
<a href="https://agentmods.dev/rules/duckduckgo/apple-browsers/user-defaults-storage"><img src="https://agentmods.dev/badge/rules/duckduckgo/apple-browsers/user-defaults-storage.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 1,736 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00000 $0.01736
Opus 5 $0.00000 $0.00868
Sonnet 5 $0.00000 $0.00347
Haiku 4.5 $0.00000 $0.00174

Measured 3d ago against content hash 3b8d3642efa6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

user-defaults-storage 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 3d 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/user-defaults-storage.mdc · 213 lines

How it starts

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

User Defaults Settings Storage and Reading

Use the KVO pattern with KeyValueStore for all new persistent settings:

// ✅ CORRECT - KVO pattern with KeyValueStore
struct AppearancePreferencesUserDefaultsPersistor: AppearancePreferencesPersistor {

    enum Key: String {
        case newTabPageIsOmnibarVisible = "new-tab-page.omnibar.is-visible"
        case newTabPageIsProtectionsReportVisible = "new-tab-page.protections-report.is-visible"
        case userPreferences = "user.preferences"
        case lastUpdateCheck = "last.update.check"
    }

    private let keyValueStore: KeyValueStoring

    init(keyValueStore: KeyValueStoring) {
        self.keyValueStore = keyValueStore
    }

    var isOmnibarVisible: Bool {
        get { (try? keyValueStore.object(forKey: Key.newTabPageIsOmnibarVisible.rawValue) as? Bool) ?? true }
        set { try? keyValueStore.set(newValue, forKey: Key.newTabPageIsOmnibarVisible.rawValue) }
    }

    var isProtectionsReportVisible: Bool {
        get { (try? keyValueStore.object(forKey: Key.newTabPageIsProtectionsReportVisible.rawValue) as? Bool) ?? false }
        set { try? keyValueStore.set(newValue, forKey: Key.newTabPageIsProtectionsReportVisible.rawValue) }
    }

    var userPreferences: [String: String] {
        get { (try? keyValueStore.object(forKey: Key.userPreferences.rawValue) as? [String: String]) ?? [:] }
        set { try? keyValueStore.set(newValue, forKey: Key.userPreferences.rawValue) }
    }

    var lastUpdateCheck: Date {
        get { (try? keyValueStore.object(forKey: Key.lastUpdateCheck.rawValue) as? Date) ?? Date.distantPast }
        set { try? keyValueStore.set(newValue, forKey: Key.lastUpdateCheck.rawValue) }
    }
}

Key Guidelines for KVO Pattern

  1. Use struct conforming to protocol - Follow the persistor pattern
  2. Define keys as enum with String raw values - Use kebab-case for key names
  3. Use KeyValueStoring protocol - Not direct UserDefaults access
  4. Computed properties with get/set - Handle storage operations in accessors
  5. Use try? for error handling - KeyValueStore operations can throw
  6. Provide default values - Use nil coalescing operator (??) for defaults
  7. Inject KeyValueStore in init - Enable dependency injection and testing

Read the full file on GitHub · 213 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. 3d ago First seen · 213 lines · 0 tokens per session scan A 3b8d3642efa6

Subscribe to this mod's changes

user-defaults-storage 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 1,736 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.