view-refactor

作者: openai

重構 macOS SwiftUI 視圖與場景,採用強預設值以利小型專用子視圖、穩定的側邊欄與選取結構、明確的命令與工具列…

npx skills add https://github.com/openai/plugins --skill view-refactor

View Refactor

Overview

Refactor macOS views toward small, explicit, stable scene and view types. Default to native SwiftUI for layout, selection, commands, and settings. Reach for AppKit only at the narrow edges where desktop behavior truly requires it.

Core Guidelines

1) Model scenes explicitly

  • Break the app into meaningful scene roots: main window, settings, utility windows, inspectors, or menu bar extras.
  • Do not let one giant root view silently own every desktop surface.

2) Keep a predictable file shape

  • Follow this ordering unless the file already has a stronger local convention:
  • Environment
  • private/public let
  • @State / other stored properties
  • computed var (non-view)
  • init
  • body
  • computed view builders / other view helpers
  • helper / async functions

2b) Split files by responsibility

  • For non-trivial apps, do not keep the full app, all views, models, stores, networking clients, process clients, and helpers in one Swift file.
  • Accept a single Swift file only for tiny throwaway examples or snippets: roughly under 50 lines, one screen, no persistence, no networking/process client, and no reusable models.
  • Use App/<AppName>App.swift for the @main app and AppDelegate only.
  • Keep Views/ContentView.swift focused on root layout and composition; move feature UI into files such as Views/SidebarView.swift, Views/DetailView.swift, and Views/ComposerView.swift.
  • Move value types and selection enums into Models/*.swift, stores into Stores/*.swift, app-server/network/process clients into Services/*.swift, and small formatters/resolvers/extensions into Support/*.swift.
  • Keep files small and named after the primary type they contain.

3) Prefer dedicated subview types over many computed some View fragments

  • Extract meaningful desktop sections like sidebar rows, detail panels, inspectors, or toolbar content into focused subviews.
  • Keep computed some View helpers small and rare.
  • Pass explicit data, bindings, and actions into subviews instead of handing down the whole scene model.

4) Keep selection and layout stable

  • Prefer one stable split or window layout with local conditionals inside it.
  • Avoid top-level branch swapping between radically different roots when selection changes.
  • Let the layout be constant; let state drive the content inside it.

5) Extract commands, toolbars, and actions out of body

  • Do not bury non-trivial button logic inline.
  • Do not mix command routing, menu state, and layout in the same block if they can be named clearly.
  • Keep body readable as UI, not as a desktop view controller.

6) Use scene and app storage intentionally

  • Use @SceneStorage for per-window ephemeral state when it truly helps restore the scene.
  • Use @AppStorage for durable preferences, not transient UI toggles that only matter in one window.
  • Keep scene-owned state close to the scene root.

7) Keep AppKit escape hatches narrow

  • If a representable or NSWindow bridge exists, isolate it behind a small wrapper or helper.
  • Do not let AppKit references spread through unrelated SwiftUI views.
  • If the bridge starts owning the feature, re-evaluate the architecture.

8) Observation usage

  • For @Observable reference types on modern macOS targets, store them as @State in the owning view.
  • Pass observables explicitly to children.
  • On older deployment targets, fall back to @StateObject and @ObservedObject where needed.

Workflow

  1. Identify the current scene boundary and whether the file is trying to do too much.
  2. Reorder the file into a predictable top-to-bottom structure.
  3. Extract desktop-specific sections into dedicated subview types.
  4. Stabilize the root layout around selection, scenes, and commands rather than top-level branching.
  5. Move action logic, command routing, and toolbar behavior into named helpers or separate types.
  6. Tighten any AppKit bridge so the imperative edge is small and explicit.
  7. Keep behavior intact unless the request explicitly asks for structural and behavioral changes together.

Refactor Checklist

  • Split oversized view files before adding more UI.
  • Move pure models, identifiers, and selection enums out of view files.
  • Move Process, URLSession, app-server, and platform client code out of SwiftUI views into Services/.
  • Keep AppDelegate and the @main app entrypoint minimal.
  • Build after each major split so compile errors stay local.

Common Smells

  • A root view that mixes window scaffolding, settings, toolbar code, command handling, and detail layout.
  • A single app file that mixes app entrypoint, root layout, feature views, models, stores, service clients, and support extensions.
  • iOS-style push navigation forced into a Mac sidebar-detail problem.
  • Several booleans for mutually exclusive inspectors, sheets, or utility windows.
  • AppKit objects passed through many SwiftUI layers without a clear ownership reason.
  • Large computed view fragments standing in for real subviews.

Notes

  • A good macOS refactor should make scene structure, selection flow, and command ownership obvious.
  • When the problem is fundamentally a missing desktop pattern, use swiftui-patterns.
  • When the problem is fundamentally a boundary with AppKit, use appkit-interop.

來自 openai 的更多技能

user-context
openai
載入或管理資料分析插件的持久性來源路由偏好設定、入門邏輯、設定進度以及語義層註冊表。
official
notion-research-documentation
openai
研究Notion內容,並將其整合為結構化的簡報、報告或附有引用的比較分析。透過精準查詢搜尋並擷取Notion頁面,然後按主題組織發現,並附上內文來源引用及參考文獻章節。根據範圍與使用者目標,從四種輸出格式(快速簡報、研究摘要、比較分析、綜合報告)中選擇。使用內建範本建立與更新Notion頁面;直接連結來源,並在新資訊到來時追蹤變更。
official
rcsb-pdb-skill
openai
提交精簡的RCSB PDB請求以獲取核心元數據、Search API查詢及FASTA下載。當用戶需要簡潔的RCSB摘要時使用;保存原始JSON或…
official
pdf
openai
PDF 讀取、建立與驗證,支援視覺化渲染與程式化生成。使用 Poppler(pdftoppm)將 PDF 頁面渲染為 PNG,以便在交付前檢查版面、間距與排版。透過 reportlab 程式化生成 PDF,確保格式可靠;使用 pdfplumber 或 pypdf 提取文字與元資料。執行品質標準:無文字裁切、元素重疊、表格破損或渲染瑕疵;僅使用 ASCII 連字號,引用格式需具可讀性。使用...
official
test-coverage-improver
openai
Improve test coverage in the OpenAI Agents JS monorepo: run `pnpm test:coverage`, inspect coverage artifacts, identify low-coverage files and branches, propose…
official
playwright
openai
終端驅動的瀏覽器自動化,具備元素快照與互動式UI工作流程。透過playwright-cli包裝腳本運作(需npx),支援無頭模式與有頭模式以進行視覺化除錯。核心流程:開啟頁面、擷取快照以取得穩定元素參照、使用參照進行互動、在導航或DOM變更後重新擷取快照。包含表單填寫、點擊、輸入、多分頁管理、螢幕截圖/PDF擷取,以及流程除錯的軌跡記錄。元素參照(例如e3、e15)...
official
ukb-topmed-phewas-skill
openai
接受rsID、GRCh37或GRCh38輸入,解析為所需的GRCh38查詢,以獲取單一變異的簡潔UKB-TOPMed PheWAS摘要。當需要…時使用。
official
code-review-context
openai
模型可見上下文
official