we (web engine): Experimental web browser project to understand the limits of Claude
at math-date-json 134 lines 4.2 kB view raw view rendered
1# we — Agent Guide 2 3## Architecture 4 5`we` is a from-scratch web browser engine in pure Rust targeting macOS ARM (aarch64-apple-darwin). Zero external crate dependencies. Every subsystem — crypto, TLS, font parsing, image decoding, JS engine — is implemented in Rust. 6 7### Crate Map 8 9``` 10browser ─┬─ platform (macOS FFI: libobjc, AppKit, CoreGraphics, Metal) 11 ├─ net ──────── url ──── encoding 12 │ └── crypto 13 ├─ html ─────── dom 14 │ └── encoding 15 ├─ css 16 ├─ dom 17 ├─ style ────── dom, css 18 ├─ layout ───── dom, style, css, text 19 ├─ text (standalone: font parsing, shaping, rasterization) 20 ├─ render ───── platform, layout, dom, css, text, image 21 ├─ js ───────── dom 22 ├─ url 23 ├─ encoding 24 └─ image (standalone: PNG, JPEG, GIF, WebP) 25``` 26 27Standalone crates (no workspace deps): `platform`, `encoding`, `css`, `dom`, `crypto`, `text`, `image`. 28 29## Commands 30 31```sh 32# Build 33cargo build --workspace 34 35# Run the browser 36cargo run -p we-browser 37 38# Test 39cargo test --workspace 40 41# Clippy (treat warnings as errors) 42cargo clippy --workspace -- -D warnings 43 44# Format 45cargo fmt --all 46cargo fmt --all --check # CI check 47 48# Single crate 49cargo test -p we-html 50cargo clippy -p we-css -- -D warnings 51``` 52 53## Conventions 54 55### Zero External Dependencies 56No crates.io dependencies. Everything is implemented in workspace crates. If you need functionality, build it. 57 58### Rust Edition 59Rust 2021. Workspace-level `edition = "2021"`. 60 61### `unsafe` Policy 62`unsafe` is allowed ONLY in: 63- `platform` — macOS FFI calls (Obj-C runtime, CoreGraphics, Metal) 64- `crypto` — constant-time operations, assembly optimizations 65- `js` — JIT compiler (writing/executing machine code), GC pointer manipulation 66 67All other crates must be 100% safe Rust. If you think you need `unsafe` elsewhere, find another way. 68 69### Pure Rust Mandate 70We own the full stack. The following are **forbidden**: 71- ImageIO (use `image` crate) 72- CoreText (use `text` crate) 73- Security.framework (use `crypto` crate) 74- Any other system framework for functionality we can implement 75 76The ONLY allowed system APIs are: 77- `libobjc.dylib` — Objective-C runtime 78- AppKit — windowing and event loop 79- CoreGraphics — bitmap rendering surface 80- Metal — GPU compositor 81 82### JavaScript Engine 83- Register-based bytecode (not stack-based) — designed for JIT from day one 84- Bytecode format encodes register operands directly 85- GC: tri-color mark-and-sweep (white/gray/black) 86- JIT: AArch64 baseline compiler (Phase 15) 87 88### Code Style 89- Run `cargo fmt` before committing 90- Run `cargo clippy --workspace -- -D warnings` — must pass clean 91- Keep functions short and focused 92- Prefer `Result<T, E>` over panics for recoverable errors 93- Tests go in `#[cfg(test)] mod tests` in the same file, or in `tests/` directories for integration tests 94 95## Workflow 96 971. Pick an issue from tangled 982. Create a worktree: `git worktree add ../we-<branch> -b <branch>` 993. Implement, write tests 1004. `cargo clippy --workspace -- -D warnings` 1015. `cargo fmt --all --check` 1026. `cargo test --workspace` 1037. Commit and push 1048. Create PR via tangled: `tangled pr create --title "..." --body "..."` 1059. After merge, clean up: `git worktree remove ../we-<branch>` 106 107## Tangled CLI Cheat Sheet 108 109```sh 110# Issues 111tangled issue list 112tangled issue create --title "..." --body "..." 113tangled issue show <id> 114 115# Pull requests 116tangled pr list 117tangled pr create --title "..." --body "..." 118tangled pr show <id> 119 120# Repo 121tangled repo show 122``` 123 124## Test Suites 125 126| Suite | Location | Run | 127|-------|----------|-----| 128| html5lib-tests | `tests/html5lib-tests/` | `cargo test -p we-html` | 129| Test262 | `tests/test262/` | `cargo test -p we-js` | 130| Acid1/Acid2 | loaded via URL | manual: `cargo run -p we-browser -- <url>` | 131| WPT | `tests/wpt/` | `cargo test -p we-browser --test wpt` | 132| Unit tests | each crate | `cargo test --workspace` | 133 134Test data repos are git submodules under `tests/`.