diff --git a/TODO.md b/TODO.md index b1aaaee..7421b63 100644 --- a/TODO.md +++ b/TODO.md @@ -26,10 +26,10 @@ Anything here that contradicts SPEC means SPEC needs an edit, not a workaround. | Area | State | |---|---| | Firmware | Written, compiles, **never run on hardware**. Known gaps below. | -| Device↔server contract | Specified in full (`firmware/API.md`). Nothing implements the server half. | -| Data model | Designed (SPEC §3) + §0 additions. No migration written. | -| Server | Phase 1 skeleton in [`server/`](server/) — config, schema, health, job queue, scheduler, systemd units. Verified end to end on Python 3.14.7 against PostgreSQL 17: 12/12 tests, migrations applied, API serving, worker draining the queue. Not yet on the real host. | -| WebUI | **Nothing exists.** | +| Device↔server contract | Specified in full (`firmware/API.md`). Server half of the **device** endpoints implemented (Phase 2); the operator-facing half (firmware upload, device management) waits on user auth in Phase 3. | +| Data model | Designed (SPEC §3) + §0 additions, migration written and applied, guarded by a drift test. | +| Server | Phases 1 and 2 in [`server/`](server/) — config, schema, health, job queue, scheduler, systemd units, and every device endpoint the firmware calls. Verified on Python 3.14.7 against PostgreSQL 17: 194 tests, migrations applied, real HTTP ingest through the worker to a WebP thumbnail on disk. Not yet on the real host, and **never yet spoken to by real firmware**. | +| WebUI | **Nothing exists** beyond the Vite scaffold on `feature/UI_Basic_implementation`. | --- @@ -89,7 +89,7 @@ written vs. what still needs doing on the real host: - [ ] PostgreSQL 17 from the distro or PGDG repo; dedicated role + database; **loopback TCP with `scram-sha-256`, not a Unix socket** (see 1.2) - [ ] Caddy DNS provider plugin build (`caddy add-package …`) and a real hostname - [ ] Tailscale for remote access -- [ ] Image store at `/srv/poorbird/images/YYYY/MM/DD/.jpg`, thumbs alongside as `_400.webp` (SPEC §3.3) — paths configured, writer is Phase 2 +- [x] Image store at `/srv/poorbird/images/YYYY/MM/DD/.jpg`, thumbs alongside as `_400.webp` (SPEC §3.3) — writer landed with Phase 2; writes are atomic (`.part` then `os.replace`) so a crash cannot leave a half-JPEG that a thumbnail job would then fail on - [ ] journald log retention capped, disk usage alarmed ### 1.1 Schema — SPEC §3 plus the §0 additions @@ -126,15 +126,27 @@ cheap today and most are the better native choice regardless. The first milestone worth celebrating. Nothing below this line matters until a real bird photo appears in a browser. -- [ ] `POST /api/v1/enroll` — bootstrap secret in, per-device `reenroll_secret` + token out. +- [x] `POST /api/v1/enroll` — bootstrap secret in, per-device `reenroll_secret` + token out. **Re-enrolling a known `device_uid` must return the existing row with a fresh token, never a duplicate.** -- [ ] `POST /api/v1/ingest` — multipart image + JSON meta, honour `X-Pre-Trigger`, dedupe on sha256 -- [ ] `POST /api/v1/heartbeat` and `POST /status` — full conditions report into `device_status` -- [ ] `GET /api/v1/config` — enums by name not number, `config_version` bump semantics -- [ ] Response envelope + `server_time` in **every** response (SPEC C7: `received_at` stays authoritative) -- [ ] Thumbnail job on ingest -- [ ] Minimal gallery page, no auth yet, purely to prove the path -- [ ] **End-to-end test on real hardware:** bird walks past → burst uploads → visible in browser + Accepts the shared secret *or* that device's own `reenroll_secret`; checking only the + shared one would lock out every device already enrolled. Hardware facts (`mac`, + `hw_revision`, `fw_version`) refresh on every enrollment, the operator's `name` does not. +- [x] `POST /api/v1/ingest` — **raw JPEG body with metadata in headers, not multipart.** + `firmware/API.md` and `uploader.cpp` send the bytes directly; multipart was a + misreading. Honours `X-Pre-Trigger`, dedupes on sha256 per device. +- [x] `POST /api/v1/heartbeat` and `POST /status` — full conditions report into `device_status` +- [x] `GET /api/v1/config` — enums by name not number, `config_version` bump semantics. + Column-backed keys win over stale JSONB copies, so an operator rename actually reaches + the device; the device's own `config_version` never overwrites the server's. +- [x] Response envelope + `server_time` (SPEC C7: `received_at` stays authoritative). + On `/heartbeat` and `/ingest`. **Not** on `/status`, which is 204 with no body per + `firmware/API.md` — "every response" was not compatible with the firmware contract. +- [x] Thumbnail job on ingest — 400px WebP, decode kept off the request path +- [x] Device authentication, rate limiting, `POST /commands/{id}/ack`, `GET /firmware/{v}.bin` + — not in the original list, but the firmware calls them (see `docs/reviews/`) +- [ ] Minimal gallery page, no auth yet, purely to prove the path — **next, on `feature/UI_Basic_implementation`** +- [ ] **End-to-end test on real hardware:** bird walks past → burst uploads → visible in browser. + Blocked on Phase 0: the server side is proven only against synthetic uploads. --- @@ -149,6 +161,10 @@ bird photo appears in a browser. - [ ] Auth: session cookies, Argon2id, CSRF, RBAC per SPEC §3.1 (viewer / editor / admin), `audit_log` on every mutation - [ ] **Auth-checked image serving** — the app authorizes, Caddy serves the bytes. An unguessable URL is not access control - [ ] Optional TOTP 2FA (see open Q14) +- [ ] **Revisit CORS.** Deliberately not configured in Phase 2: Caddy serves the built UI and the + API from one origin, so there is no cross-origin request to permit, and adding permissive + headers "for the UI" would only weaken that. Decide it properly if the UI is ever served + from somewhere else — *then* it matters. ### 3.1 Two things the UI must not get wrong @@ -162,7 +178,11 @@ bird photo appears in a browser. - [ ] Device list with live/awake state, last seen, RSSI, heap/PSRAM, ring depth - [ ] Settings editor writing the `devices` settings surface → `apply_config` → `config_version` - [ ] Command queue UI: `wake_and_hold`, `capture_now`, `apply_config`, `ota_update`, `stream_start`, `reboot`; commands ride along on the ingest response -- [ ] Firmware upload, SHA-256, target marking, per-device staged rollout +- [ ] Firmware upload, SHA-256, target marking, per-device staged rollout. + `GET /firmware/{version}.bin` already serves the bytes; the upload half was left out of + Phase 2 because it needs operator auth. **Constrain `firmware.is_target` to a single row + while doing this** — nothing enforces it today, and the lookup takes the first match, so + two target rows would pick non-deterministically between them. - [ ] Verify the full OTA path on hardware: **trial boot and automatic rollback**. The camera is unreachable once mounted — this is the one feature with no recovery if it is broken - [ ] Document that rotating the shared bootstrap secret server-side without shipping new firmware **removes the last-resort escape hatch** diff --git a/server/README.md b/server/README.md index 2538970..edba714 100644 --- a/server/README.md +++ b/server/README.md @@ -1,9 +1,24 @@ # poorBird server -Phase 1 skeleton: configuration, schema, health, job queue and scheduler. -There are **no device endpoints yet** — `/enroll`, `/ingest`, `/heartbeat`, -`/status` and `/config` are Phase 2. The contract they must satisfy is -[`../firmware/API.md`](../firmware/API.md). +Phases 1 and 2: configuration, schema, health, job queue, scheduler, and every +endpoint the camera calls. + +``` +POST /api/v1/enroll X-Enroll-Secret, returns a bearer token +POST /api/v1/ingest raw JPEG body, metadata in headers +POST /api/v1/heartbeat conditions in, envelope + commands out +POST /api/v1/status conditions in, 204 out +GET /api/v1/config ~40 optional keys the device merges +POST /api/v1/commands/{id}/ack 204 +GET /api/v1/firmware/{version}.bin OTA image, exact Content-Length +GET /api/v1/health +``` + +[`../firmware/API.md`](../firmware/API.md) is the contract, and it wins over +anything here: it is what the firmware already does, and the camera is the side +that cannot be patched from a laptop once it is mounted outdoors. The operator +half — firmware *upload*, device management, the gallery — needs user auth and +arrives with Phase 3. Stack per SPEC §6, deployed natively per [`../TODO.md`](../TODO.md) Phase 1.2: FastAPI + PostgreSQL 17 + SQLAlchemy 2.0 + Alembic, run as systemd units @@ -108,7 +123,8 @@ src/poorbird/ logging_setup.py stdout only; journald or a log driver catches it db.py engine + session factory (sync, deliberately) models/ SPEC §3 schema + the SPEC §0 additions - api/ FastAPI app; Phase 2 mounts device routes here + images.py JPEG sniffing, atomic writes, thumbnails + api/ FastAPI app, device routes, auth, rate limiting worker/ queue (SKIP LOCKED), handlers, scheduler cli.py serve | worker | migrate | check | enqueue migrations/ Alembic