interplane.Get Omega
Read in your language

aien-edge

aien-dev/aien-edge

Brought by drakestapleton

branch main Branches Tags History

aien-edge / AGENTS.md

66 lines · 5390 bytes Raw Blame History Rendered
1# aien-edge (native Rust edge server for AIEN static sites)
2
3> A small Rust web server (hyper + rustls) that serves prebuilt static sites from memory, with precompressed assets, virtual hosts and automatic Let's Encrypt TLS. It was built to run on a Raspberry Pi at the network edge. It is not in use today: the AIEN sites are served by GitHub Pages. This is hosting infrastructure, not part of the AIEN core.
4Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds what is specific to this repository; where the two differ, this file wins here.
5
6## Scope
7
8- Applies to the whole repository: one binary crate.
9- `src/main.rs`: startup, listeners (plain HTTP and TLS-ALPN-01 ACME), connection cap, timeouts, `SIGHUP` reload.
10- `src/config.rs`: the TOML config schema (`deny_unknown_fields`).
11- `src/site.rs`: loads a site into memory, path normalization, brotli/gzip precompression, ETags, encoding negotiation.
12- `src/handler.rs`: request handling, redirects, security headers.
13- `deploy/`: example config, systemd unit, publish script. `deploy/publish-site.sh` still runs `npm ci` and `npm run build`, which no longer matches how the sites are built (both use Rust generators); it must be updated before any redeploy.
14
15## Installation
16
17```bash
18git clone https://github.com/aien-dev/aien-edge.git
19cd aien-edge
20cargo build --release # writes target/release/aien-edge
21```
22
23Needs Rust 1.88 or newer: `rust-version = "1.88"` in `Cargo.toml`, and `rust-toolchain.toml` pins 1.88.0 so rustup selects it here. 1.88 is the oldest release that builds the locked dependencies (`time` 0.3.55 needs 1.88; several crates use edition 2024). When a dependency update raises that floor, raise `rust-version`, the `rust-toolchain.toml` channel and this line together. `Cargo.lock` is committed. aarch64 builds run on a 64-bit Raspberry Pi OS.
24
25## Configuration
26
27- The binary takes one argument, the config path; default `/etc/aien-edge/config.toml`. The config is read only at startup; changing it needs a restart, not a reload.
28- `deploy/config.example.toml` is the reference. Keys: `http_listen` (default `[::]:80`), `max_connections` (default 2048), optional `[tls]` (`https_listen` default `[::]:443`, `contact`, `cache_dir`, `production`), and one or more `[[site]]` tables (`host`, `redirect_from`, `root`, `spa`).
29- Without `[tls]` the server runs plain HTTP only and serves content on the HTTP port (local testing).
30- `production = false` uses the Let's Encrypt staging directory. Keep it false until certificates issue cleanly.
31- Log level comes from `RUST_LOG` (tracing `EnvFilter`), default `info`.
32- The server exits at startup if a config has no `[[site]]`, or a site root is missing or has no `index.html`.
33
34## Usage
35
36```bash
37cargo test # 9 unit tests in src/site.rs and src/handler.rs
38cargo clippy --release -- -D warnings
39cargo build --release
40target/release/aien-edge <config.toml> # serves until stopped; SIGHUP reloads every site from disk
41```
42
43- Running the binary opens network listeners. For a local run use a config without `[tls]`, a non-privileged `http_listen`, and a `[[site]]` root that holds a built site with `index.html`.
44- Deploying (`README.md`, "Deploy on the Pi") needs a Raspberry Pi with systemd, sudo, ports 80 and 443 forwarded to it, and DNS pointing at it. `deploy/aien-edge.service` runs it with `DynamicUser=yes`, `CAP_NET_BIND_SERVICE` only and a read-only `/srv/sites`.
45- `.github/workflows/msrv.yml` checks that `rust-version` matches the `rust-toolchain.toml` channel, then runs `cargo build`, `cargo test` and `cargo clippy --release -- -D warnings` with `--locked` on that toolchain for every pull request and push to `main`. Run the three cargo commands above before opening a pull request.
46
47## Conventions
48
49- Rust 2021 edition. Tests live beside the code in `#[cfg(test)]` modules and use `tempfile` for site fixtures. Add a test when a rule (traversal rejection, redirects, hidden files, encoding choice) could regress silently.
50- Keep the attack surface small: GET and HEAD only, no per-request filesystem access, hidden files and source maps never loaded. TLS comes from `rustls`/`rustls-acme`; do not hand-roll crypto or HTTP parsing.
51- Performance claims need a recorded run (command, commit, output), as in the "Measured" section of `README.md`. Check `ab` output has no `Non-2xx responses` line.
52- License is AGPL-3.0-or-later (`LICENSE`, `Cargo.toml`). `COVENANT.md` is nonbinding and says `LICENSE` governs where they disagree.
53- No em dashes or en dashes.
54
55## Safety and approvals
56
57- Ask before deploying, changing DNS, or switching `production = true`; the sites are live on GitHub Pages and this server is not.
58- Ask before relaxing a security default (methods, headers, timeouts, connection cap, systemd hardening in `deploy/aien-edge.service`).
59- Never commit certificates, the ACME cache directory or private keys. `deploy/publish-site.sh` takes the target host from `EDGE_HOST`; set it in the environment rather than hardcoding new addresses.
60- Do not run `deploy/publish-site.sh` or the Pi install commands as a check; they need sudo and a remote host.
61
62## Further reading
63
64- `README.md`: features, measured throughput, build and Pi deployment guide.
65- `deploy/config.example.toml`, `deploy/aien-edge.service`, `deploy/publish-site.sh`.
66- `COVENANT.md`: nonbinding values statement.