Nacre/CLAUDE.md

18 KiB

Nacre

Nacre is a web browser written from scratch in Rust with an egui UI, on a tuned WebKitGTK 6.0 in a GTK 4 host (D-032; Linux only; Servo was removed in S053), meant to replace the Python/QtWebEngine Nacre as the user's daily browser. Final deliverable: Linux (AppImage, tar.gz) builds of the browser, published through the releases/ folder to the user's Forgejo (astar76/Nacre). Vision: PLAN.md.

0. Session rules — read first

  1. You are started with one plan: Plans/<NN Category>/SNNN-*.md. Read only: this file, your plan, the last 3 entries of docs/PROGRESS.md, and the files/sections your plan names.
  2. Do not open other files in Plans/ (nor ORCHESTRATOR.md, nor all of PLAN.md).
  3. Tick each checkbox in your plan file the moment it is done, one by one, never in batches. Right after each tick, sync the tracker (§Tracker). An interrupted plan resumes at its first unchecked box.
  4. Stay in scope. Out-of-scope ideas go to docs/PROGRESS.md ("Later"), not into the code.
  5. Invent nothing: check the code/docs; if a fact is still missing, ask — the orchestrator if you were started by one (never the user directly), otherwise the user.
  6. End of session: (a) end criteria verified by commands, not memory; (b) docs/PROGRESS.md entry (≤ 15 lines: done, not done, later); (c) docs/DECISIONS.md if a decision binds later plans; (d) tick your line in Plans/INDEX.md (no commentary); (e) commit SNNN: … and push to origin; (f) short report: done, not done, what the user/orchestrator must do, and any instruction that cost more than it gave.
  7. Languages: answer in English. Code, comments and docs in English. Internal docs (CLAUDE.md, Plans/, PROGRESS.md) in English.
  8. Also at session start (user rule): read docs/HANDOFF.md and docs/STATUS.md if they exist. docs/DESIGN.md is the architecture and WebKit embedding cheat sheet; read the parts your plan names.

Tracker

Live checklist of every plan: https://claude.ai/artifact/9AD7fPfwJ4ASFzVTJGKU4h (collection plans, one doc per plan id). After ticking a box: ArtifactData update with url = the tracker, collection: "plans", doc_id: "SNNN", data: {"status": "running" or "done" (all boxes ticked), "items": [{"text": "<step>", "done": true/false}, … every checkbox of the plan in order], "updated": "<ISO date-time>"} and if_version = the version returned by your previous write (first time: get the doc once to read it; a doc that doesn't exist yet takes no if_version). Load the tool with ToolSearch select:ArtifactData once. If the tracker call fails, keep working and say so in the report: the plan file is the source of truth.

1. Repository layout

Root: /home/astar76/Projects/Nacre

src/            main, app, window (GTK window + egui overlay), egui_area, engine/ (WebKit host, views, events), tabs, actions, keys, inject, adblock, discord, media, ...
src/store/      settings, history, bookmarks, downloads, vault, permissions, session, apps, scripts
src/net/        bridge (local CONNECT proxy), fetch, tor, dns, download, dlm
src/ui/         egui chrome, menus, dialogs, widgets, pages/* (every nacre:// page)
assets/         bundled resources
docs/           DESIGN, FEATURES, REVIEW, HANDOFF, UI-BRIEF, ui-reference/, PROGRESS, DECISIONS
Plans/          INDEX.md, _TEMPLATE.md, one folder per category
install.sh      builds and installs the Arch package (packaging/arch/PKGBUILD, D-054); removes target/ afterwards
releases/       release files (git-ignored; hub-release-sync uploads them)

Never modify: ~/Documents/Apps/Nacre (the original Python Nacre, reference only) and ~/Projects/Nacre-rust (older repo, not a source). target/ is build output.

2. Facts

  • Engine: WebKitGTK 6.0 (webkit6 crate, =0.6.1) in a GTK 4 window; egui draws the chrome in a transparent Gtk.GLArea over the web views (D-033, D-035). WebKit tuning data and the engine test: docs/engine/engine-comparison.md, docs/engine/tune/. The Servo removal inventory (history): docs/engine/servo-removal.md. Pages' network work happens in the web process extension webext/.
  • Cargo package nacre 0.4.1, edition 2024, Rust ≥ 1.88. No Servo, vendored crates or patched engine any more; builds take minutes (~2–4 min release), not hours.
  • Status: builds, cargo test green, hidden smokes pass; features still to re-verify on WebKit are marked in docs/FEATURES.md.
  • User rules: function first; plain egui UI until everything works; the Material You redesign comes afterwards (see docs/UI-BRIEF.md); nothing from the original is dropped silently (engine limits are shown as unavailable, see DESIGN.md "Engine limits"); never connect to Tor or proxies in tests.
  • Known gaps and things to check at the first build: docs/REVIEW.md. Feature list with file and review state: docs/FEATURES.md.
  • The original Python Nacre (~/Documents/Apps/Nacre/nacre, config.py DEFAULTS) is the feature spec.

3. Code rules

  • Write like the neighbouring code. KISS, DRY, YAGNI; no abstraction without ≥ 2 uses.
  • New pure logic gets a test; a bug fix gets a regression test when feasible.
  • Fix compile errors in place; don't restructure working modules.
  • WebKit signals run on the main thread; handlers only queue Events (see src/engine/mod.rs); never touch App inside a signal handler.

4. Domain pitfalls (all agents)

  • Builds: nice cargo build --release -j 2 only. Never run cargo test at the same time as a release build, and never run two cargo commands on the same target/.
  • Run apps in the hidden nested session (tools/nested-session.sh: Xvfb → nested niri, software GL; kwin_wayland isn't installed) unless the user asked to watch. Xvfb has no DRI3, so clients there use LIBGL_ALWAYS_SOFTWARE=1 WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 GSK_RENDERER=gl (the session's env file sets them). VMs have no real GPU: use software rendering there.
  • Never connect to Tor or proxies in tests; NACRE_NO_BRIDGE=1 disables the bridge for debugging.
  • WebKit has no EME/Widevine here, no Chrome extensions, no JS pause for background tabs: see DESIGN.md "Engine limits"; don't try to work around them.
  • Use throwaway XDG_* dirs for test runs so the user's profile is untouched.

5. Verification tools

Tool Role Available after
nice cargo build --release -j 2 compile check, produces target/release/nacre now
nice cargo test --release -j 2 unit tests (44, ~16 s test-profile build then <1 s run; shares the S001 build) (util, settings, history, bookmarks, permissions, vault, dns, bridge loopback, download, adblock, keys, scripts, updates, inject, hub, theme, ui::widgets input, ui::paint, ui::pages::newtab) first successful build; not alongside a build
src/selftest.rs in-app self test: NACRE_SCRIPT=<file> runs script commands (listed at its top) now
tools/smoke.sh <script> [outdir] smoke run in a hidden nested Wayland session (tools/nested-session.sh start|stop <dir> [WxH]: Xvfb → nested niri, software GL, own runtime dir and bus; SMOKE_SIZE = nested output size, window at 0,0) with a throwaway home; selftest click/rclick/pagescroll/pagetype are real compositor input there (tools/wl-input, own crate, built on first use; wtype), resize goes through the nested niri; outdir (default target/smoke/<name>-<time>, use a fresh one: home/ persists) gets nacre.log, selftest.log, <shot>.png, <status>.json, home/, session/; exits non-zero on crash, panic, no status done or a failed assert <js>. Scripts in tests/smoke/ (launch.txt offline, https.txt needs internet, restore.txt with SMOKE_HOME=<launch outdir>/home, chrome.txt chrome and every flyout dark and light, offline; colours.txt colours after welcome and site colour vs internal pages, hidden SMOKE_SIZE=1280x1100; input.txt real clicks, typing, right click, wheel on a web page, offline; basics.txt tabs, navigation, find, zoom, full screen, pop-ups, offline; heavy-web.txt DuckDuckGo, Wikipedia, YouTube, needs internet, SMOKE_TIMEOUT=900; keys.txt every shortcut action, offline; privacy-net.txt DNT/GPC/Save-Data headers and third-party cookies on a loopback server, offline, start python3 tests/smoke/net/server.py & first; site-doctor.txt Google sign-in, captchas, Reddit, GitHub, needs internet; cache.txt HTTP cache, offline, start python3 tests/smoke/cache/server.py & first; selftest launch <args> checks single instance; cookies.txt → cookies-restart.txt → cookies-cleared.txt encrypted cookies across restarts with SMOKE_KEYRING=1 (own throwaway GNOME Keyring + bus) and SMOKE_HOME, cookies-nokeyring.txt without, server.py first; cookies-export.txt Export cookies.txt, offline, server.py first, SMOKE_SIZE=1280x900; zap.txt ad removal animation (cookie shield mid-animation, slots closed, players kept, Motion off), dark and light, offline, SMOKE_SIZE=1280x900; stuck.txt tab lifecycle (leave-page question, Reload, nacre:// pages free their view, Back with history, chatty page closes without CRITICAL, shortcut recording ends), offline, SMOKE_SIZE=1280x900; nacre-lock.txt web pages can't reach nacre:// and the passwords page asks on every open (D-049, D-052: computer password via NACRE_TEST_ACCOUNT_PASSWORD=smoke-account), server.py first, SMOKE_SIZE=1280x900; crash-adblock.txt R5-01 regression, ~1300 blocked loads with reloads/navigations mid-load plus 3200 timers under GC pressure, offline, server.py first; hang.txt page isn't responding bar (Wait, Reload page, caught on switch-to) and crash pages for the active, a hidden and a PiP tab, hidden only, offline, SMOKE_SIZE=1280x900; previews.txt hover-preview probe, no pass/fail, see its header); header documents env vars and commands. SMOKE_VISIBLE=1 shows the run on the user's screen (real GPU; page input synthesized in the page, no rclick/resize); it refuses to start unless the user's niri config has the dev.nacre.Nacre window rule from the smoke.sh header (DP-1, no focus), so it never moves the user's focus or workspace (D-044). WebKit state (S050): launch, basics, input, keys, chrome, dialogs, pip, auth, stores-, integ-spell, net-, privacy-net, privacy-mode, cache*, crash-adblock green hidden (loopback skips the bridge, no NACRE_NO_BRIDGE needed); other scripts not yet. Read the PNGs now (S003, S046)
nacre://gallery + SMOKE_SIZE=1400x2800 tools/smoke.sh tests/smoke/gallery.txt every design token and widget, dark and light (+ new tab and settings shots); read the PNGs now (S015)
SMOKE_SIZE=1400x1200 tools/smoke.sh tests/smoke/newtab.txt new tab page dark/light, nothing playing and a video playing, weather failed state, tall/narrow/phone widths (offline); tests/smoke/newtab-weather.txt shoots the real weather card (needs internet); read the PNGs now (S017)
SMOKE_SIZE=1400x900 tools/smoke.sh tests/smoke/backgrounds.txt every new tab background with the pointer, Customize panel dark/light, image + blur, GIF frames; perf-*-a/b.json frames (median/max draw ms, drawn count) per background at Lots/Fast, hidden tab, still, Motion off. Selftest pointer x y, customize; @PAGESDIR@ = path of tests/smoke/pages now (S018)
tools/smoke.sh tests/smoke/settings.txt (+ SMOKE_SIZE=1280x1100) every settings section and sub-page dark and light, search results (nacre://settings/?search=…), narrow width; settings-write.txt (hidden, SMOKE_SIZE=1280x1100, fresh outdir) taps controls with selftest tap x y, then check home/.config/nacre-browser/Default/settings.json (expected values in its header) now (S019)
SMOKE_SIZE=1280x1600 tools/smoke.sh tests/smoke/sliders.txt controls hold still (R1-21): Interface size drag (value label while held, applied on release), Contrast live, Style chip pick; SMOKE_VISIBLE=1 tools/smoke.sh tests/smoke/sliders-visible.txt the same plus scrolling for the user's window (~772 px). Selftest press/drag/release, scroll x y dy; read the PNGs now (R1-21)
python3 tests/smoke/net/server.py & + tools/smoke.sh tests/smoke/net-{privacy,adblock,downloads}.txt network pass, offline: secure DNS through a local DoH stub (*.nacre.test → 127.0.0.1), HTTPS-only + certificate warning, tracking params, ad blocker with a local list, downloads + download manager stubs; the server's /log has requests, DNS names, Range headers, manager calls. cache-restart.txt with SMOKE_HOME=<cache.txt outdir>/home: disk cache. net-real.txt needs internet. @HOME@ in scripts = the throwaway home now (S007)
SMOKE_TIMEOUT=400 tools/smoke.sh tests/smoke/mse.txt, …/mse-player.txt plain MSE tests on WebKit: chunk-appended fMP4, WebM and split A/V play; mse-spec.html spec cases (attach/detach, duration, buffered/seekable, remove, removeSourceBuffer, changeType, abort, reopen, sequence); player integration (attach, seeks, rate, ended, decode error, garbage append; ?only=<case> in the page URL for one case). Offline, start python3 -m http.server 8765 --bind 127.0.0.1 --directory tests/smoke/pages & first (MSE needs an http origin). youtube-mse.txt is an internet probe S022, S027, S028, S053
tools/smoke.sh tests/smoke/privacy-mode.txt (+ SMOKE_ARGS=--incognito … privacy-incognito.txt) privacy mode: pages/fingerprint.html read off/on, fp-off.json/fp-on.json + shots (offline); privacy-net.txt (needs tests/smoke/net/server.py) frame cookies, per-site pause, Accept-Language; SMOKE_TIMEOUT=700 … coveryourtracks.txt EFF's test off/on (internet, direct). Selftest save <name> <js> writes a JS string result to <name>.json; SMOKE_ARGS passes browser arguments now (S024)
python tools/icons.py rebuilds the icon font subset and src/ui/icons.rs from tools/icons.txt (needs fontTools and Arch's ttf-material-symbols-variable) now (S015)
tools/mem-run.sh <outdir> [ENV=v…] + tools/smoke.sh tests/smoke/slow.txt (+ python3 tests/smoke/slow/server.py &), bg-tabs.txt Nacre's PSS/CPU on the tune sites (hidden, internet; NACRE_WK_PAGE_CACHE=1, NACRE_WK_CACHE_MODEL=viewer as variants); slow-line visit/revisit/reload/back with a paced local server (offline, first/revisit/reload/back.json, log.json); hidden tab gets no frames and slow timers now (S052)
tools/engine-test/run.sh chromium|webkit + analyze.py engine comparison: one browser visible on DP-1, throwaway profile, sites from sites.txt, per-second RAM (PSS), CPU, GPU of the whole process tree into docs/engine/runs/<engine>/samples.csv; webkit_shell.py is the WebKitGTK 6.0 shell (needs webkitgtk-6.0); report docs/engine/engine-comparison.md. Never run two at once or alongside cargo now
python3 tests/smoke/net/server.py & + tools/smoke.sh tests/smoke/site-data.txt; tools/smoke.sh tests/smoke/media-audio.txt site info cookie/data count, Clear data time range (stored data kept, cookies always whole); WebKit is-playing-audio → tab audible, tab mute via set_is_muted (pages/sound.html, ?element plays tone.ogg with Media Session metadata; WebKit's MPRIS player shows on the run's bus: busctl --address=unix:path=$(cat <out>/session/runtime)/bus list). Offline, hidden now (S051)
tools/smoke.sh tests/smoke/pip.txt (+ tools/hidden.sh tests/smoke/pip.txt <out> -- tests/smoke/pip-driver.sh: <out>/windows.json PiP floating), bindings.txt (side buttons, middle click; hidden only), ctxmenu.txt (site menu vs Nacre's; hidden only), pip-return.txt (page input after PiP and back; hidden only), pip-loop.txt (+ -- tests/smoke/pip-loop-driver.sh: PiP three rounds, ended by command, Escape, window close; windows-<n>.json; hidden only), selftest pick x y (GTK's pick at a page point + view state), python3 tests/smoke/net/server.py & + SMOKE_SIZE=1280x900 tools/smoke.sh tests/smoke/auth.txt, tests/smoke/visible-ui.txt (by hand, header) PiP moves the live view and back (offline); HTTP sign-in cancel + saved login (offline); visible: portal file chooser, notification, page full screen, Web Inspector (dialogs.txt now also checks dialog answers, context menu, leave page, permission bars, notifications count) now (S048, S056)
python3 tests/smoke/net/server.py & + tools/smoke.sh tests/smoke/player-ad.txt; tools/smoke.sh tests/smoke/ctxmenu.txt video site ad tricks (click catcher over the player, pop-under on click, pop-up without a click, ad frame in a cross-site frame must not take the tab); site context menus (pages/site-menu.html: YouTube-like toggle, Discord-like, plain, each 3×) and Nacre's menu keys via selftest realkey <wtype keys>. Hidden only, offline now (S061)
tools/hidden.sh <script> [outdir] [-- driver.sh] WebKit build hidden with a driver script: Xvfb → nested niri (tools/nested-session.sh), throwaway home, software GL, NACRE_SCRIPT; the driver gets click/scroll (tools/wl-input), grab (grim), key/type (wtype). Scripts in tests/hidden/ (basic.txt offline; web.txt + web-driver.sh needs internet). Read the PNGs now (S045)
tools/package.sh release files in dist/: tar.gz, AppImage, Arch nacre-bin (packaging/arch-bin), .deb, packaging/nix/default.nix, SHA256SUMS (appimagetool from ~/.local/opt/build-tools) now

Don't assume a tool exists: check first. When your plan creates a tool, add its row here.

6. Git

Remote origin = forgejo:astar76/Nacre.git; push finished work there. Don't use gh, GitHub or other remotes. Releases only through releases/v<version>/ (see the user's global CLAUDE.md); tell the user the version and contents before publishing. One commit per logical step, message SNNN: … in English. No reset --hard / force push without an explicit request.

7. Definition of done

A plan is done when: all end criteria are verified by command or test; planned builds/tests are green; nothing regressed; PROGRESS / DECISIONS are up to date; the INDEX line and tracker are ticked; the work is committed and pushed. Say explicitly what was not done or verified.