# CLAUDE.md — Zyquo Atlas ## Project Identity **Zyquo Atlas** is the web-browser member of the **Zyquo** family: a legendary, native macOS **web browser** written in **Swift + SwiftUI**, built **without the Xcode IDE** (Swift Package Manager + command-line toolchain). It is designed to **pulverize Safari** — a faster, radically more customizable, AI-native browser where artificial intelligence is woven into *every* surface, not bolted on as a sidebar afterthought. Zyquo Atlas rests on three pillars: 1. **Massive display & theme customization** — the user can reshape almost everything: layout, chrome, colors, themes, fonts, density, tab styles, backgrounds. It should feel like *their* browser. 2. **First-class favorites & history management** — powerful, searchable, organizable, beautiful. 3. **AI everywhere, done legendarily** — summarize, chat-with-page, ask about selection, AI search, compose/rewrite in any text field, translate, extract, automate reading, and more — powered by **the exact same providers and models as Zyquo Cloud** (all of them). Zyquo Atlas reuses Zyquo Cloud's provider/API layer and encrypted key vault, and must match the family's premium native design quality. **Naming conventions (use consistently everywhere):** - Display name / product name: `Zyquo Atlas` - App bundle: `Zyquo Atlas.app` - Bundle identifier: `com.zyquo.atlas` - Executable / SPM target: `ZyquoAtlas` (no space) - Data folder: `~/Library/Application Support/ZyquoAtlas/` - Profiles/browsing data: `~/Library/Application Support/ZyquoAtlas/Profiles/` - Repo module prefix in file headers: `Zyquo Atlas` --- ## 📋 MANDATORY FILE HEADER — EVERY CODE FILE **Every single code file you write** (all `.swift` files, plus `Makefile`, shell scripts, `Package.swift`, verification scripts — anything containing code) **MUST begin with this header comment**, adapted to the file's comment syntax: ```swift // // .swift // Zyquo Atlas // // Author: Simon-Pierre Boucher // Mail: contact@spboucher.ai // ``` For shell scripts / Makefiles: ```bash # # # Zyquo Atlas # # Author: Simon-Pierre Boucher # Mail: contact@spboucher.ai # ``` No exceptions. If you ever create or refactor a file and the header is missing, add it. Before declaring the project done, run a sweep over the repository to verify every code file carries the header. --- ## 🧭 METHODOLOGY — WORK METHODICALLY, KEEP EVERYTHING COHERENT You must execute this project **strictly in phase order (0 → 8)**. Do not jump ahead, do not interleave phases, do not build AI features before a real tab can load and render a page, and do not write any code before Phase 0 research + Zyquo Cloud study are complete. **Working rules:** 1. **One phase at a time.** At the start of each phase, write a checklist into `docs/PLAN.md`; check items off as you go. At the end of each phase, run a **phase checkpoint**: build (`swift build`), run what's runnable, fix all warnings/errors, write a 3–5 line phase summary in `docs/PLAN.md` before moving on. 2. **Phase gates:** Phase 0 is complete only when `docs/AI-BROWSER-RESEARCH.md` and `docs/PROVIDER-REUSE.md` are complete. Phase 2 is complete only when a WKWebView-based tab can navigate, show progress, handle back/forward, and the multi-tab model works. Phase 3 is complete only when page content can be reliably extracted and fed to a model, and one AI action (summarize page) works end-to-end with streaming. Phase 4 spec is the contract for all UI in Phase 6. Phase 7 is complete only when browser + AI verification passes with real keys. Phase 8 is complete only when `spctl` says "Notarized Developer ID". 3. **Single source of truth, everywhere:** - Provider/model behavior → ported from Zyquo Cloud's client layer (Phase 0.B); never re-invent request formats. **All Zyquo Cloud models are available in Atlas.** - Colors, fonts, spacing, radii → base values from `ZyquoTheme` tokens; user themes override via the theming engine (Phase 4). Zero raw hex values or magic numbers in views. - Web engine, content extraction, and AI orchestration → live in the `Browser/`, `Content/`, and `AI/` layers; never leak WKWebView or network guts into unrelated views. - Product naming → per the conventions above. Never `Zyquo` alone, never `ZyquoAtlas` in user-facing text. 4. **Coherence sweeps:** after Phases 3, 6, and 8, do a consistency pass (uniform naming — always `Tab`, `AIAction`, `PageContext`, `ProviderClient`; no dead code; headers present; folders match Phase 2). 5. **Compile early, compile often.** Never accumulate more than one file of unbuilt changes. 6. **Commit discipline:** one logical unit per commit, phase-prefixed message. Never commit secrets or user browsing data. 7. **Privacy is a design constraint, not a feature bullet:** page content only leaves the machine when the user invokes an AI action (or has explicitly enabled an auto action), always to the user's chosen provider via their own key, never to Zyquo. This must hold from the first AI code written. --- ## ⚠️ PHASE 0 — MANDATORY RESEARCH + ZYQUO CLOUD STUDY (DO THIS FIRST, BEFORE ANY CODE) Two mandatory research tracks, each producing a document. No Swift until both are done. ### 0.A — `docs/AI-BROWSER-RESEARCH.md` — how to integrate AI into a browser, legendarily (INTENSIVE WEB RESEARCH) Do NOT rely on training data. Perform **several intensive web research sessions** studying how the best AI browsers and browser-AI products actually work, and synthesize a concrete, functional design. Research at minimum: 1. **The landscape.** Study current AI browsers and AI browsing features for patterns worth stealing and pitfalls to avoid: **Arc / Arc Max & Dia (Browser Company), Perplexity Comet, Brave Leo, Microsoft Edge Copilot, Opera Aria, SigmaOS, and Chrome's built-in AI**. Document what each does well: page summarization, chat-with-page, AI search/answers, tab organization, "ask about this", command bars, writing assistance, agentic browsing. Extract the *functional* interaction patterns, not marketing. 2. **Page content extraction for LLMs.** The hard part. Research how to reliably turn a live web page into clean, model-ready text: **readability/DOM extraction** (Mozilla Readability-style main-content extraction), stripping nav/ads/boilerplate, preserving structure/headings/links, handling article vs. app pages, extracting the user's **current text selection**, capturing visible viewport vs. full document, and handling very long pages (chunking + map-reduce summarization). Document how to inject JavaScript into WKWebView (`WKUserScript`, `evaluateJavaScript`) to get this content out. 3. **Chunking, context, and long pages.** How to summarize/answer over pages that exceed the context window: chunking strategies, map-reduce and refine summarization, embedding-free relevance selection (keyword/heuristic) vs. optional local embeddings, and citing which part of the page an answer came from. 4. **AI surfaces & UX patterns.** Where AI lives in a legendary browser: an **AI command bar / omnibox** (ask vs. navigate vs. search intent detection), a **contextual sidebar chat** bound to the current page/tab, **inline selection actions** (select text → floating "Ask / Explain / Translate / Rewrite"), **AI-assisted writing in any web text field**, **AI search** (answer + sources instead of just links), **tab & session summarization**, **auto-summaries on hover/open**, and lightweight **agentic actions** (e.g., "find and open the docs page for X"). Document keyboard-driven flows. 5. **Streaming & responsiveness.** How to stream AI output into browser UI without blocking navigation, run AI per-tab, cancel on navigation, and keep everything at 60fps. 6. **Multi-tab / multi-page reasoning.** Patterns for "summarize these 5 tabs", "compare these pages", chat that can reference multiple open tabs. 7. **Safety/privacy & correctness.** Clear consent before sending page data, on-screen indication when content leaves the device, avoiding hallucinated citations, and grounding answers in extracted content. Write it into `docs/AI-BROWSER-RESEARCH.md`. Every AI feature in later phases must trace to a pattern documented here. ### 0.B — `docs/PROVIDER-REUSE.md` — study the Zyquo Cloud repo and reuse its providers **Before writing provider code, read and study the Zyquo Cloud repository** (sibling project). Locate it on disk (check the user's projects folder; if not found, ask the user for its path). Document and reuse: 1. **Exactly how each provider's API is called** in Zyquo Cloud: base URLs, auth headers, request/response `Codable` models, the shared `OpenAICompatibleClient`, native `AnthropicClient` / `GeminiClient`, and the streaming (SSE) handling. Atlas must call models the **exact same way** — port or factor the code so it is identical to Cloud's. 2. **The complete model catalog** Zyquo Cloud ships (`ModelCatalog` / `docs/PROVIDERS.md`). **Include ALL of these models in Zyquo Atlas** — every provider, every model available in Cloud is available in Atlas. The user picks a default AI model for browsing and can override per feature (e.g., a fast cheap model for hover-summaries, a strong model for deep chat). 3. **The secure key vault** from Cloud (custom AES-256-GCM encryption, **NO Keychain**). Atlas reuses the same `SecureKeyStore` design and vault format. 4. Any provider-specific streaming quirks so Atlas handles all uniformly behind the `ProviderClient` protocol. **Outcome:** Atlas's AI layer speaks to the identical providers/models as Zyquo Cloud, with the same keys and behavior. --- ## PHASE 1 — Project Setup (No Xcode IDE) - **Toolchain:** Swift Package Manager. `Package.swift`, executable target `ZyquoAtlas`. Build `swift build -c release`. - **Web engine:** **WebKit / `WKWebView`** (the system web engine) — the correct, supported path for a native macOS browser without bundling Chromium. Use `WKWebViewConfiguration`, `WKUserContentController`, `WKWebsiteDataStore` (persistent + non-persistent for private tabs), and process pooling for multi-tab. - **App bundle:** `Makefile` builds release, assembles `Zyquo Atlas.app` (`Contents/MacOS/ZyquoAtlas`, `Info.plist`, `Resources/AppIcon.icns`), signs (Phase 8; ad-hoc for `make dev`). - **Info.plist:** `CFBundleDisplayName` = `Zyquo Atlas`, bundle ID `com.zyquo.atlas`, `LSMinimumSystemVersion` (macOS 13.0+), `NSHighResolutionCapable`, `LSApplicationCategoryType` (`public.app-category.productivity`), and `NSAppTransportSecurity` configured appropriately for a browser loading arbitrary sites (a browser needs to load HTTP/arbitrary content — document the correct ATS posture; the WKWebView content itself is the exception surface, keep app's own API calls HTTPS-only). Register as a candidate default browser (`CFBundleURLTypes` for `http`/`https`, and handle `NSUserActivityTypes`/default-browser APIs). Universal (arm64 + x86_64) for release. - **Entry point:** `@main` SwiftUI `App`; proper activation from terminal launch. - **Dependencies:** Foundation + SwiftUI + WebKit + CryptoKit; Apple `swift-markdown` acceptable. Reuse Zyquo Cloud's URLSession networking — no external HTTP libs. --- ## PHASE 2 — Architecture + Browser Core ``` Sources/ZyquoAtlas/ ├── App/ # @main, window/scene, menu bar, default-browser handling ├── DesignSystem/ # ZyquoTheme tokens + ThemeEngine (user themes) ├── Models/ # Tab, TabGroup, Bookmark, HistoryEntry, Profile, AIAction, PageContext… ├── Browser/ │ ├── WebView.swift # NSViewRepresentable wrapper over WKWebView │ ├── TabManager.swift # tabs, tab groups/spaces, ordering, suspension │ ├── NavigationController.swift # url handling, back/forward, reload, progress │ ├── ProfileStore.swift # data stores, cookies, private/persistent │ └── DownloadManager.swift # file downloads ├── Content/ │ ├── ContentExtractor.swift # injected JS → clean readable text, selection, metadata │ ├── Readability.js # bundled main-content extraction script │ └── PageContext.swift # normalized page representation for the model (title, url, text, selection, chunks) ├── AI/ │ ├── AIService.swift # orchestrates provider calls for browser actions (streaming) │ ├── AIActions.swift # summarize, chat-with-page, ask-selection, translate, rewrite, AI-search, compare-tabs… │ ├── Summarizer.swift # chunking + map-reduce/refine for long pages │ └── OmniIntent.swift # omnibox intent: navigate vs. search vs. ask ├── Providers/ # PORTED FROM ZYQUO CLOUD (all models) │ ├── ProviderProtocol.swift │ ├── OpenAICompatibleClient.swift │ ├── AnthropicClient.swift │ └── GeminiClient.swift ├── Features/ │ ├── BookmarksService.swift # favorites: folders, tags, search │ ├── HistoryService.swift # full-text searchable history │ └── ReadingList.swift ├── Services/ │ ├── SecureKeyStore.swift # reused from Zyquo Cloud (no Keychain) │ └── PersistenceService.swift # SQLite or JSON for bookmarks/history/sessions ├── ViewModels/ └── Views/ ``` - **Tabs:** real multi-tab with process reuse, lazy loading, background-tab **suspension** to save memory, restore-on-launch, tab groups / "spaces". Each tab owns a `WKWebView` + navigation state + its own AI context. - **PHASE GATE:** a tab must navigate to a URL, show a determinate progress bar, support back/forward/reload/stop, open links in new tabs, and the omnibox must resolve URL vs. search — before any AI work. --- ## PHASE 3 — AI EVERYWHERE (THE DEFINING LAYER) Build the content pipeline first, then the AI actions on top. **PHASE GATE:** "Summarize this page" works end-to-end with streaming, grounded in extracted content, on a long real article, using a Zyquo Cloud model. ### 3.A — Content extraction (`ContentExtractor` + `Readability.js`) - Inject JavaScript into the active `WKWebView` to extract: page title, URL, **clean main-content text** (Readability-style, boilerplate stripped), headings/structure, links, meta description, and the **user's current selection**. Handle article vs. app pages; fall back gracefully. - Produce a normalized `PageContext`; for long pages, **chunk** it (with overlap) for map-reduce summarization per the research. Cache per tab; invalidate on navigation. ### 3.B — AI actions (`AIService` + `AIActions`) — all streaming, all cancel-on-navigation Implement, at minimum, these **legendary, functional** AI surfaces (from `docs/AI-BROWSER-RESEARCH.md`): - **AI Command Bar / smart omnibox:** typing detects intent — **navigate** (URL), **search** (web), or **ask** (AI answer with sources). Asking returns a streamed answer plus source links, without leaving the page. - **Chat-with-page sidebar:** a per-tab contextual chat bound to the current `PageContext`; ask follow-ups about the page; answers cite the section they came from; model picker in the sidebar (all Cloud models). - **Selection actions:** select text on any page → floating toolbar with **Explain / Summarize / Translate / Rewrite / Ask**; result appears in a popover or the sidebar. - **Summarize page / TL;DR:** one keystroke; long-page map-reduce; key points + optional full summary. - **AI writing assist in web text fields:** in any editable field (`