13 Commits
Author SHA1 Message Date
Thomas KarnerandClaude Opus 5 f9d0b09d2f Correct the docs the gallery work made wrong
Housekeeping, not new behaviour. The status table still said the WebUI was
"nothing beyond the Vite scaffold" and the server was "Phases 1 and 2" at 194
tests, all of which stopped being true three commits ago. A status table that
is wrong is worse than no status table: it is the first thing read and the last
thing checked.

Endpoint lists in server/README.md were taken from the app's own OpenAPI
schema rather than from memory, which is how the last round of this found that
/ingest was documented as multipart when it is a raw body. The operator half is
now listed separately from the device half, because the two authenticate in
ways that must not be mixed up -- bearer token and no cookies on one side,
session cookie plus CSRF on the other.

Ticked auth-checked image serving, which shipped in 735cbcc, and recorded why
there are two delivery paths and only one authorization path.

The test count is 308 because the suite was run, not because 308 was the number
I remembered.

Two comments in api/app.py contradicted the code beside them. One said the
enroll-secret warning was "not fatal at Phase 1 -- no device endpoint exists
yet", six lines above the device endpoints being mounted; it now says the real
reason the API starts anyway, which is that an enrolled camera keeps working
and refusing to start would take the gallery down too. The other said the
Phase 3 UI endpoints were still to come, directly below the two lines that
mount them.

Left alone deliberately: the "12/12 tests" in docs/reviews/**. Those are
point-in-time review snapshots, and updating them to current numbers would
destroy the only thing they are for.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 22:01:35 +02:00
Thomas KarnerandClaude Opus 5 29c8cf6bfe Build the gallery: virtualised grid, filters and a full-size viewer
The client half. The gallery now reads real captures, pages by cursor and
loads thumbnails through the auth-checked route, so an image is only ever
served to a request that carried a valid session.

Virtualised because the gallery is the one screen that grows without bound.
5000 captures a day is past a million DOM nodes inside a year, and the browser
gives up long before the database does. react-virtual virtualises a list
rather than a grid, so the grid is a list of rows whose column count is
computed from the measured container width - which also makes it responsive
without a media-query ladder, and is why the width is observed rather than
assumed. A ResizeObserver rather than a window resize listener, because the
filter panel changes that element's width without the window changing at all.

Filters cover what the server can answer: date range, device, kept, reviewed,
pre-trigger. Taxon and tag are deliberately absent until taxa is seeded and
the observation editor exists, for the same reason they are absent from the
endpoint. The triage filters are tri-state selects rather than checkboxes,
because "kept" has three meanings - everything, only kept, only rejected - and
a checkbox expresses two of them.

Filters are part of the query key, so changing one starts fresh pagination
instead of appending. A cursor from the previous filter set describes a
position in a list that no longer exists.

The viewer is keyboard-driven on purpose. Labelling a day of captures is
look-decide-next a few hundred times, and that loop is only bearable from the
keyboard. It steps only through what is already loaded, and the button is
disabled at the edge rather than showing a blank frame while a page arrives.

Two contract details the UI has to get right, both now carried in code with
the reason attached: captured_at_device is null when the camera's clock was
unsynced and is rendered as "not synced" rather than as 1970 (API.md,
X-Captured-At: 0), and a model-sourced observation is badged as a prediction,
because that table is also the training data for any future model and a
prediction shown as a human label would poison it.

has_thumb is why the summary carries it: the grid shows a placeholder for a
capture whose thumbnail job has not run, instead of a broken image.

Conventions held: no user-facing string literal in a component - 60-odd new
keys in en.ts and de.ts, and the typed catalogue makes a missing German string
a build error rather than English in front of a German user. No colour literal
outside tokens.css either; the one place that wanted rgba() uses color-mix
against a token instead. 36 contrast pairs across three themes still pass.

Verified against the real stack with 506 real captures through the Vite proxy,
which is the path the browser takes: 9 pages of 60 following the cursor, all
506 seen, zero duplicates across pages that include real burst timestamp ties,
0.28s for the lot, and 12 of 12 sampled thumbnails arriving as valid WebP.

Not verified: how it looks. I have no browser here, so the layout, the scroll
behaviour and the virtualisation actually recycling rows are unconfirmed by
eye. Typecheck, build and the data path are green; the visual pass is yours.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 19:36:47 +02:00
Thomas KarnerandClaude Opus 5 79ac1d4632 Enforce auth in the UI, and fix a header bug that would have broken CSRF
web/README.md promised this was "three lines in router.tsx plus deleting the
banner". It was nearly true. Every route is now behind RequireAuth: the gallery
for any signed-in user, Devices and System for admin (SPEC 3.1). Roles are
listed per route rather than granting admin everything implicitly, so widening
one route cannot silently widen another - the same reasoning as
api/userauth.require_role.

The parts the README did not anticipate:

A sign-out control. signOut() existed in AuthProvider and nothing called it,
which was fine while the app was ungated and is not fine now: enforcing auth
without a way to leave strands whoever signs in. It sits in the header with the
theme and language switchers, and only renders when there is a session to end.

lib/api.ts now carries the CSRF token, and fixing that surfaced a real bug in
the scaffold. The fetch options spread `...init` AFTER `headers:`, so any
caller passing headers replaced the whole object instead of merging into it.
apiPost always sets Content-Type, so Accept was already being dropped on every
POST - harmless, and invisible, because the server does not care. It stops
being harmless the moment a header has to be there: the CSRF token would have
been dropped on exactly the mutating requests that require one, and every POST
would have answered 403 with nothing in the client to explain it. `...init`
goes first now, with the reason written next to it.

RequireAuth no longer shows the login form for the "unavailable" state. That
state means the server answered 404 to /auth/session, which now only happens
when a newer UI is served by an older server - so offering a form that 404s is
the wrong answer. It says the versions do not match instead.

auth.notEnforced is deleted from both catalogues rather than left unused, and
.banner went with it, since that notice was its only caller. auth.failed was
reworded: the server answers every sign-in failure identically - wrong
password, unknown user, bad code, deactivated account - so the message has to
cover all of them rather than inventing a distinction the server refuses to
make. New keys in both en.ts and de.ts, which is enforced at build time.

Verified through the Vite dev proxy, which is the path a browser actually
takes rather than the one the tests take: 401 signed out, 401 for an admin
without a TOTP code, 200 with one, both cookies arriving through the proxy,
403 on logout without the CSRF header with the session still alive after it,
204 with the header, 401 after. And POST /ingest still answers 401 rather than
403, because a camera sends no cookies and must never need a CSRF token.

Docs brought in line: web/README.md said authentication was built but not
enforced, which is now the opposite of true, and it now also says the two
things needed before anyone can sign in - a user, and
POORBIRD_SESSION_COOKIE_SECURE=false for plain-http development.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 18:25:27 +02:00
Thomas KarnerandClaude Opus 5 89ebe99bed Merge Phase 2 into the UI branch, so auth is built on top of it
Phase 3 auth is next, and this branch's server/ was still at Phase 1. Building
sessions here without merging first would have meant writing them against a
config.py with credentials still defaulted, no deps.py device auth to follow as
a pattern, and - the one that actually matters - no rate limiter, leaving a
login endpoint brute-forceable until the branches finally met.

So the branches meet now, while the only conflict is a documentation one, rather
than later on top of an auth implementation.

TODO.md was the single conflict: both sides had edited Phase 3, which is exactly
what should happen when one branch finishes Phase 2 and the other starts the UI.
Both sides' content is kept - the Phase 2 ticks and the UI decisions in 3.0 -
and the resolution fixed two things a purely textual merge leaves broken:

  - "Minimal gallery page, no auth yet" is struck. SPEC 3.3 requires image
    serving to be auth-checked, so that is not a state the gallery can
    legitimately pass through, and the scaffold's System page already proves the
    browser-to-Postgres path that item existed to prove.
  - The themes line appeared twice, once ticked by the scaffold and once not.
    The genuinely open half is persisting the choice per user, which needs
    accounts, so that is what it now says.

web/ is untouched by the merge: it had no files at the merge base and none on
the server branch, so that side contributes no deletion. Verified - 27 files
before and after.

Verified both halves after resolving: server 194 passed, ruff clean, alembic
clean; UI typecheck clean, build green, 36 contrast pairs across 3 themes with
no failures.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 17:48:55 +02:00
Thomas KarnerandClaude Opus 5 c40072f644 Correct the docs that Phase 2 made wrong
Both entry-point documents still described the server as a Phase 1 skeleton,
which is the kind of drift that costs someone an afternoon before they think
to distrust the README.

server/README.md opened with "There are no device endpoints yet". There are
eight, so it now lists them, checked against the mounted routes rather than
from memory. images.py joins the layout; api/ no longer says Phase 2 will
mount routes there one day.

TODO.md Phase 2 had every box unticked. Ticked with what was actually built,
and the three deviations from the plan written down where the plan was wrong:

  - /ingest was specified as "multipart image + JSON meta". The firmware
    sends a raw JPEG body with the metadata in headers. Multipart was a
    misreading of API.md, and the note now says so, because the next person
    to read the old line would implement the wrong endpoint.
  - "server_time in every response" is not compatible with /status being
    204, which API.md requires. The envelope goes on /heartbeat and /ingest.
  - Enroll accepts a device's own reenroll_secret as well as the shared
    bootstrap secret. Checking only the shared one, as the review's sample
    code did, locks out every device that has ever enrolled.

Two boxes stay open, and they are the honest ones: no gallery page, and no
end-to-end run against real hardware. The server half is proven only against
synthetic uploads, and the status table now says that rather than implying a
verified path.

Also recorded two deliberate deferrals that were living only in a
conversation, which is the same as not existing:

  - CORS, in Phase 3: not configured because Caddy serves the UI and the API
    from one origin, so there is no cross-origin request to permit and
    permissive headers would only weaken that.
  - The missing single-row constraint on firmware.is_target, in Phase 4
    beside the upload endpoint that will create the second target row.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 17:36:37 +02:00
Thomas KarnerandClaude Opus 5 384b09371a UI: scaffold the web app - shell, themes, i18n, auth plumbing
React 19 + TypeScript + Vite + TanStack Query/Router in web/, built on the
dev machine and shipped as static files (SPEC section 6). Typechecks and
builds clean; the System page reads live /health through the Vite proxy,
which proves browser -> proxy -> FastAPI -> PostgreSQL end to end.

Themes: light, dark and blue (dark navy), as design tokens on data-theme.
An inline script applies the stored theme before first paint. No colour
literal lives outside tokens.css.

check-contrast.mjs asserts WCAG AA for every text/background pair in every
theme, with no dependencies. It failed on its first run and found three
--border-strong values below the 3:1 that WCAG 1.4.11 wants for interactive
boundaries; all three are fixed and 36 pairs now pass. Colour contrast is
the classic silently-regressing property, so it gets a test rather than a
promise.

i18n is hand-written and typed rather than react-i18next: en.ts defines the
key set, de.ts is typed against it, so a missing German string fails the
build instead of quietly showing English to a German user.

Authentication is built but NOT enforced, deliberately. /auth/session,
/auth/login and /auth/logout do not exist yet, so router.tsx does not wrap
routes in RequireAuth and a banner says so plainly. There is no development
bypass: a bypass that works is the kind of code that survives into
production, and an auth bypass that works is the worst possible bug.

Gallery and Devices render honest empty states rather than mock rows. Fake
data hides the layout problems real data exposes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 01:17:07 +02:00
Thomas KarnerandClaude Opus 5 5a098e44d8 UI: record decisions for language, theme, 2FA, stack and seed data
Closes SPEC section 10 questions 11, 13, 14 and 16 in a new TODO 3.0.

- Language: de + en from the first component. No user-facing string
  literal in a component, ever.
- Theme "blue" is a dark navy; token table recorded. Contrast still has
  to be measured against WCAG AA rather than assumed.
- 2FA: build TOTP now, optional per user, enforced for admin. "The UI
  does not need it" and "I need outside access" describe the same
  surface; what differs is whether the path is Tailscale or a public
  domain. Retrofitting it later reopens login, sessions, the user model
  and the audit log at once.
- Stack stays React + TypeScript, with the no-TS-experience starting
  point treated as a real constraint on how it gets written. Jinja2 +
  HTMX stays a valid fallback and the API does not change.
- Placeholder captures are generated by a seed command, not downloaded:
  no licensing question, no binaries in git, and it can produce the
  volume the virtualised grid needs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 00:59:16 +02:00
Thomas KarnerandClaude Opus 5 5d16ded553 Server: verify Phase 1 end to end against PostgreSQL 17
Set up the dev environment (uv-managed CPython 3.14.7, postgres:17 in a
Podman container) and ran the skeleton for real: migrations apply, the
API serves /api/v1/health and /healthz, the worker claims a job and
drains it, 12/12 tests pass with nothing skipped.

The schema-drift test failed on its first real run and found a genuine
problem: Postgres reflects a varchar default as 'x'::character varying
while the model renders 'x', so all ten string defaults read as
permanent drift. Left alone that is the failure mode where you learn to
ignore the test and then miss the one real change. Add schema_compare.py,
a normaliser shared by migrations/env.py and the test so autogenerate and
the test can never disagree about what counts as a difference. A real
default change still fails it.

Also: ruff import-order fix in captures.py, and the README gains the
uv + Podman dev setup, the expected test count, and the CREATE DATABASE
privilege the drift test needs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 00:30:52 +02:00
Thomas Karner 8a51e3d95e Server: basic implementation. Not tested => no python installed; bugfix in ESP (uvicorn on port 8090) 2026-09-20 23:49:40 +02:00
Thomas Karner 3694cdf207 dev: re-create TODO.md; Dockerization in mind but postponed 2026-09-20 23:26:51 +02:00
Thomas Karner e191f59f6f remove oboslete TODOs 2026-09-20 22:53:45 +02:00
tom 1718c9c05e Normalisiere Zeilenenden (CRLF → LF) für Linux
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-09-20 20:30:25 +02:00
tom c8aab35910 Initial commit; 1st TODO added 2026-06-03 00:49:12 +02:00