$ show nook-browser/Nook
Nook is a native macOS web browser built entirely with SwiftUI and WebKit (WKWebView) — not a wrapper around Chromium. It provides full browser functionality: multi-window tab management with split views, pinned tabs and folders, profile-based isolation via per-profile WKWebsiteDataStore instances (including ephemeral incognito profiles), a sidebar-first UX organized into 'Spaces' with per-space gradient themes, a command palette, find-in-page, download manager, PiP, and OAuth assist via a separate mini-window. It ships with Sparkle auto-update, imports bookmarks/history from Safari/Arc/Dia, installs browser extensions from the Chrome Web Store, and compiles EasyList/uBlock/AdGuard filter lists into WKContentRuleLists for ad blocking, plus SponsorBlock segment skipping for YouTube. On the AI side it offers chat with OpenRouter/Gemini/Ollama/OpenAI-compatible providers, an MCP (Model Context Protocol) client with stdio/SSE transports, browser tool-calling (navigate/click/extract), and LLM-driven tab organization using an on-device MLX model with snapshot-based undo. Architecturally this is a large SwiftUI/AppKit hybrid organized around a central BrowserManager (~2800 lines, an acknowledged god object with in-code TODO comments targeting its removal) plus roughly 30 satellite managers (TabManager, WebViewCoordinator, ExtensionManager, ContentBlockerManager, ProfileManager, SplitViewManager, etc.). Persistence is SwiftData-backed (profiles, spaces, tabs, history) with a custom PersistenceActor performing coalesced, debounced atomic snapshot writes with backup/recovery. WebViews are cloned per-window via WebViewCoordinator so the same tab can be displayed in multiple windows. Extension support uses the native WKWebExtension APIs (macOS 15.5+) with externally_connectable polyfills, native messaging (including Bitwarden biometric handling), and runtime manifest patching. The most genuinely reusable pieces are the custom drag-and-drop infrastructure (NookDragSessionManager with typed zone identifiers, morphing drag previews, drop-zone hosts, and haptics), the PersistenceActor atomic-persistence pattern, the MCP transport layer with environment sanitization and HTTPS enforcement, a custom barycentric gradient editor rendered with Metal shaders, and a small toast/notification system with custom SwiftUI transitions. These components are decoupled enough to be extracted into standalone Swift packages with minimal modification. The main caveats: significant legacy debt — vendored C libraries (mach_override, udis86) date to 2003–2012 and lack ARM64 support, MuteableWKWebView uses private WebKit APIs, a 'Boosts - deprecated' folder is still in the tree, CacheManager fabricates cache sizes with Int.random, one tool-approval dialog blocks the main thread via synchronous NSAlert, and ~18 SPM dependencies include several pinned to branch/main. Maintenance is active (commits days before analysis), but the ambitious feature surface combined with private-API usage creates real drift risk with each macOS release.
The LLM identified 5 files worth highlighting for reuse:
A self-contained drag-and-drop session manager for AppKit/SwiftUI hybrid apps. It centralizes drag sessions with typed zone identifiers, manages multiple simultaneous drag sources, provides morphing drag preview windows (tab row, pinned tile, ghost variants), and coordinates drop-zone hit-testing with haptic feedback. The design is decoupled from browser state, communicating via drag payload types and zone callbacks, so it could be extracted into a standalone Swift package and reused by any macOS app needing rich drag reordering.
Demonstrates a robust atomic-persistence pattern (PersistenceActor) for SwiftData/ModelContext apps: a dedicated actor that coalesces and debounces writes, serializes tab/space state to JSON snapshots, maintains backup files, classifies SwiftData errors by severity, and recovers corrupted stores from the last good snapshot. The pattern — debounced transactional writes plus snapshot backup/recovery plus error classification — is data-store-agnostic and directly reusable in any Swift app needing crash-safe local persistence.
A transport abstraction for Model Context Protocol servers supporting stdio and SSE transports with JSON-RPC 2.0 framing. Adds production hardening rarely seen in MCP clients: HTTPS-only enforcement for SSE URLs, environment-variable sanitization when launching subprocesses (scrubbing API keys), binary-path validation, and thread-safe I/O via NSLock-guarded send/receive. This clean, protocol-focused component could bootstrap an MCP client in any other application by implementing the transport interface.
A minimal toast notification system implemented as a pure SwiftUI view with a custom .transition(.toast) transition and environment-driven presentation. Used consistently for copy-URL confirmations, tab-closure undo, profile switches, and shortcut conflicts. The view has no internal imports and can be lifted into any SwiftUI project as-is.
Compiles ad-block filter lists (EasyList/uBlock/AdGuard syntax) into WKContentRuleList rules via SafariConverterLib, with a disk cache keyed by filter-set fingerprint to avoid recompilation on every launch. It decouples network-triggered filter-list updates from the compile pipeline, making it reusable for any macOS app that needs WKWebView content blocking from community filter sources.