interplane.Get Omega
Read in your language

readings-window

aien-dev/readings-window

Brought by drakestapleton

branch main Branches Tags History

readings-window / AGENTS.md

74 lines · 6522 bytes Raw Blame History Rendered
1# readings-window (read-only HTTPS window onto the Spark's GPU and CPU readings)
2
3> A small Rust service that runs on the project's Raspberry Pi house server. `readings-window collect` fetches one JSON line of readings from the DGX Spark over ssh and keeps 30 days of history; `readings-window serve` hands the readings, cached status and results files, the exposure-watch result and the agent chat feeds to anyone holding the bearer token, over HTTPS on port 9443. `scripts/` holds the exposure watch, a shell script and systemd timer that scans the house's own public IP. There is no CI in this repository.
4
5Shared 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.
6
7## Scope
8
9- Applies to the whole repository: the crate (`src/main.rs`, `src/tls.rs`) and the exposure watch (`scripts/exposure-watch.sh`, `.service`, `.timer`).
10- The service is read-only by design. It serves files and runs fixed read commands on the Spark; it never writes to the Spark and never accepts uploads. Keep it that way.
11- Not in this repository: the Spark-side `spark-readings` script, the `readings-collect` timer and `readings-window` service units on the Pi, the token, the TLS key and certificate, and the exposure baseline. `NOTES.md` describes where they live.
12- `target/`, `.crumb.local` and `spark.conf` are ignored (`.gitignore`). Never commit them or a real deployment target list.
13
14## Installation
15
16```bash
17git clone https://github.com/aien-dev/readings-window.git
18cd readings-window
19cargo build --release
20```
21
22Needs a stable Rust toolchain only. Dependencies are `rustls` (ring provider, TLS 1.2 and 1.3) and `serde_json`; `rcgen` is a dev-dependency for the TLS tests. No Python. The binary is `target/release/readings-window`.
23
24## Configuration
25
26Spark SSH targets come from `/etc/readings-window/spark.conf`; `spark.conf.example` documents the format. Each nonempty `target=USER@HOST` value is tried in file order. Keep real targets local-only, with the same order when migrating an existing deployment. There are no environment-variable or flag overrides.
27Optional `identity=PATH` selects an SSH identity on the hub for all targets; the first nonempty value wins. Omission delegates identity selection to the service user's OpenSSH configuration/defaults. Values are trimmed, with no shell expansion or quote removal. Preserve an existing deployment's identity explicitly before deploying this change; keep its real path local-only.
28
29- Pi-side files: token `/etc/readings-window/token`, certificate `/etc/readings-window/fullchain.pem`, key `/etc/readings-window/key.pem`; data under `/var/lib/readings-window/` (`history.jsonl`, `status.json`, `results.json`, `exposure.json`).
30- Listen address `0.0.0.0:9443` (`serve`).
31- The target file is read on each fetch, not at server startup. Missing or unreadable config makes Spark fetches fail; `/health` can still return successfully because it reads local history. See the migration procedure in `NOTES.md`.
32- Other settings remain constants in `src/main.rs`: home-relative Spark status/results and agent archive paths (`AGENTS`, five fixed names). The configured SSH user's home must contain those paths. Changing one of these is a deployment change; say so in the pull request.
33- Limits: history `?hours=` default 24, max 720 (`DEFAULT_HOURS`, `MAX_HOURS`); chat `?lines=` default 500, max 50000; HTTP head cap 16 KiB and at most 64 connections (`src/tls.rs`); history kept 30 days (`KEEP_SECS`).
34- The exposure watch reads its baseline from `/etc/exposure-watch/baseline.json` (created on first run) and writes `/var/lib/readings-window/exposure.json`, which `/v1/exposure` serves.
35
36## Usage
37
38```bash
39# Unit tests (20 tests: request parsing, routes, auth, TLS handshake with a generated cert)
40cargo test
41
42# Lint (clean at the time of writing)
43cargo clippy --all-targets
44
45# Syntax check of the exposure watch
46bash -n scripts/exposure-watch.sh
47```
48
49Running the binary with no argument prints `usage: readings-window collect|serve` and exits 1. Do not run `collect` or `serve` on a development machine: `collect` needs root, the Pi's ssh key and the Spark on the network; `serve` needs the token, key and certificate under `/etc/readings-window/` and binds port 9443. Do not run `scripts/exposure-watch.sh` either: it scans the public IP with `nmap`, queries UPnP and writes under `/etc` and `/var/lib`. All three only make sense on the Pi.
50
51Endpoints are listed in `README.md`: `/health` needs no token; every `/v1/*` route needs `Authorization: Bearer <token>`. Wrong or missing token gives 401, unknown path 404, non-GET 405.
52
53## Conventions
54
55- Keep the dependency set minimal. The hand-written HTTP/1.1 reader in `src/tls.rs` replaced `tiny_http` because it pinned a rustls with a security advisory; do not bring back a framework without a reason in the pull request.
56- Nothing user-supplied reaches the remote shell. Agent names are matched exactly against the allow-list and mapped to constant paths; `?lines=` is parsed to an integer and clamped. Keep both properties, and add a test when you touch a route.
57- Tests live in `#[cfg(test)]` modules at the bottom of `src/main.rs` and `src/tls.rs`.
58- `cargo fmt --check` does not pass on the current tree. Do not reformat files you are not otherwise changing; a formatting-only change belongs in its own pull request.
59- Dependency updates for advisories are separate commits that name the advisory (for example `RUSTSEC-2026-0382`).
60- Record operational changes (new route, new file, new unit) in `NOTES.md` and the endpoint list in `README.md`.
61
62## Safety and approvals
63
64- Never commit the token, TLS key, certificate, ssh keys or the exposure baseline. They exist only on the Pi.
65- Never widen what the service exposes (a new route, a new remote command, a write path, auth removed from a route) without explicit approval from the maintainer.
66- Ask before changing the listen port, the host list or any path constant; the live Pi deployment depends on them.
67- The exposure watch must scan only the house's own public IP. Never point it at another host.
68- Deploying to the Pi is out of scope for an agent working from a clone. Merge through a pull request; the maintainer deploys.
69
70## Further reading
71
72- `README.md`: endpoints, commands and current status.
73- `NOTES.md`: deployment layout on the Pi, unit names, feed history and known unverified points.
74- `src/tls.rs`: the TLS listener and HTTP reader, with its limits.