Agent Skillsrokartur/BetterCmdTab › add-preference

add-preference

GitHub

指导在BetterCmdTab中添加或修改持久化偏好设置的标准流程,涵盖声明键值、热路径集成、快捷键覆盖、配置导出及UI实现。

.agents/skills/add-preference/SKILL.md rokartur/BetterCmdTab

Trigger Scenarios

添加新的应用偏好设置 修改现有偏好设置逻辑 涉及Preferences.swift文件变更

Install

npx skills add rokartur/BetterCmdTab --skill add-preference -g -y
More Options

Non-standard path

npx skills add https://github.com/rokartur/BetterCmdTab/tree/main/.agents/skills/add-preference -g -y

Use without installing

npx skills use rokartur/BetterCmdTab@add-preference

指定 Agent (Claude Code)

npx skills add rokartur/BetterCmdTab --skill add-preference -a claude-code -g -y

安装 repo 全部 skill

npx skills add rokartur/BetterCmdTab --all -g -y

预览 repo 内 skill

npx skills add rokartur/BetterCmdTab --list

SKILL.md

Frontmatter
{
    "name": "add-preference",
    "description": "Contract for adding or changing a persisted setting in BetterCmdTab. Use when touching Preferences.swift, a settings pane, or any Switcher.* UserDefaults key."
}

Add a preference

A setting is a multi-file contract keyed on one string. Follow every step that applies; skipping one produces a setting that silently fails to persist, export, or apply on the hot path.

1. Declare the key and property

In BetterCmdTab/App/Preferences.swift:

  • Add the key to the Keys enum as "Switcher.camelCaseName". The string is the contract — it is read by name in other files, exported to config files, and never renamed after shipping.
  • Add a @Published property whose didSet persists to UserDefaults, and load it in init and in reloadFromDefaults() (settings import and config-file sync call this — a property missing there ignores imports). Copy the exact pattern of an adjacent property of the same type.
  • Clamped ints get a static let …Range: ClosedRange<Int> next to the other range constants, and clamp on read.

Complete when: the property round-trips through reloadFromDefaults().

2. Wire the hot path, if any

If the value is read while the switcher opens or cycles (CatalogFilter, SwitcherController, WindowEnumerator, Activator, HotkeyTap, RecentlyClosedStore), those consumers read the key string directly from UserDefaults.standard off the main actor — never touch Preferences.shared there. Match the existing direct-read sites in the file you are editing.

Complete when: no hot-path code awaits the main actor to read the value.

3. Per-shortcut override, if applicable

If the setting should be overridable per shortcut (#74), extend ShortcutOverride in Preferences.swift: add the optional field, its dictionary encoding, the init?(dictionary:) decode, and the entry in knownKeys (an omitted knownKeys entry makes the field bounce into passthrough and never apply). Then resolve it where the other overrides resolve into CatalogFilter.Config / reveal-time reads.

Complete when: the field survives a dictionaryinit?(dictionary:) round trip and is absent from passthrough.

4. Portability and config file — usually free

Export/import (SettingsPortability.swift) and ~/.config/bettercmdtab/config.json (ConfigFile.swift) pick up any Switcher.* key automatically. Only act if the value is device-local state (caches, recently-closed, machine-specific paths): add it to exportExcludedKeys in SettingsPortability.swift.

5. UI and strings

Add the control to the matching pane view controller in BetterCmdTab/Settings/ (fragile or new behavior goes behind the off-by-default Experimental pane). Register the control in SettingsCatalog.swift if the pane search should find it. All labels use String(localized:) — then follow the localize-strings skill for the catalog entries.

6. Verify

New pure-logic behavior gets a Swift Testing test. Then run the suites the contract touches:

xcodebuild -scheme "BetterCmdTab Debug" -destination 'platform=macOS' test \
  -only-testing:BetterCmdTabTests/PreferencesEnumTests \
  -only-testing:BetterCmdTabTests/SettingsPortabilityTests \
  -only-testing:BetterCmdTabTests/LocalizationCatalogTests

Complete when: those suites pass and the setting survives an export → import round trip.

Version History

  • 30e25b6 Current 2026-07-30 22:00

Same Skill Collection

.agents/skills/localize-strings/SKILL.md
.agents/skills/release-changelog/SKILL.md
.agents/skills/release/SKILL.md
.agents/skills/verify/SKILL.md

Metadata

Files
0
Version
7d5fa2e
Hash
df11d0d8
Indexed
2026-07-30 22:00

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-03 23:20
浙ICP备14020137号-1 $Гость$