Gate the dashboard on the site's admin login and add a setup page
Test and publish / test (push) Successful in 25s
Test and publish / publish (push) Successful in 3m1s

Like job-tracker, the tracker forwards the visitor's cookies to the site
backend's /auth/validate-admin instead of asking for an API key. Signed
in, the dashboard shows every device's data. The new /setup page has
instructions for each collector and creates and revokes API keys. The
userscript is served publicly at /tracker.user.js.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 21:22:02 +01:00
co-authored by Claude Opus 5.5
parent 67082226cc
commit e6a93be15c
13 changed files with 650 additions and 79 deletions
+47 -20
View File
@@ -17,14 +17,14 @@ Every source is stored as an interval in a single `activities` table, with colum
|---|---|
| Hyprland (`cmd/hypr-agent`) | ✅ built |
| Apple Health (Health Auto Export → `/health/hae`) | ✅ endpoint built; configure the app |
| Browser extension (`/browser/events`) | endpoint ready, extension not yet written |
| Browser (Violentmonkey userscript, `/tracker.user.js`) | ✅ built |
| Webcam presence (`/presence/events`) | endpoint ready, agent not yet written |
| AI analysis (`reports` table) | planned |
## Running the server
```sh
make up # builds the image and starts tracker + a dev Postgres on :8080 / :5432
make up # builds the image and starts tracker + a dev Postgres on :8080 / :5432 (AUTH_MODE=dev: no login)
curl localhost:8080/readyz
```
@@ -44,6 +44,8 @@ docker run -d -p 8080:8080 \
| `LISTEN_ADDR` | `:8080` | |
| `AUTO_MIGRATE` | `true` | Apply migrations on startup. Set it to false to run `tracker migrate` yourself |
| `TRACKER_TZ` | `UTC` | Timezone that defines "a day" in summaries |
| `AUTH_MODE` | `forward` | `forward` gates the dashboard on the main site's admin login (see [Dashboard and auth](#dashboard-and-auth)). `dev` admits everyone and requires `DEV_MODE=true` |
| `AUTH_VALIDATE_URL` | `http://backend:8080/auth/validate-admin` | The site backend's admin check |
Put the service behind your reverse proxy (Caddy, Traefik and so on) for TLS, because API keys are sent as bearer tokens.
@@ -75,21 +77,34 @@ tracker goal list
tracker goal rm --id 2
```
## Dashboard and auth
The dashboard (`/`) and the setup page (`/setup`) have no login of their own. As in job-tracker, the tracker borrows the main site's session. It forwards the browser's cookies to the site backend's `GET /auth/validate-admin` and treats a 2xx as admin (`internal/auth`). A visitor who isn't signed in is sent to the site's `/admin/login?redirect=/tracker/`, which returns them afterwards. A "yes" is cached for 30 seconds per cookie, so signing out takes up to 30 seconds to reach the tracker. If the backend refreshes an expired token, its new cookies are passed back to the browser.
Signed in, the dashboard shows every device's data without asking for a key. The setup page has step-by-step instructions for each collector, with your server URL filled in. It also lists devices and creates and revokes their API keys, so you don't need `docker exec` for keys.
Collectors never use the site login. Each one sends its own bearer key.
## API
All `/api/v1` routes require `Authorization: Bearer <key>`.
| Auth | Meaning |
|---|---|
| key | `Authorization: Bearer <key>` from `tracker apikey create` or the setup page |
| admin | the main site's admin session cookies |
| Method | Path | Accepted kinds |
|---|---|---|
| POST | `/api/v1/desktop/events` | `app_focus`, `idle`, `locked` |
| POST | `/api/v1/browser/events` | `tab_focus`, `idle` |
| POST | `/api/v1/presence/events` | `at_desk`, `in_bed`, `away` |
| POST | `/api/v1/manual/events` | any |
| POST | `/api/v1/health/hae` | Health Auto Export JSON. Workouts and sleep become activities; other metrics become samples |
| GET | `/api/v1/activities?from=&to=&source=&kind=&limit=` | RFC3339 times; defaults to the last 24h |
| GET | `/api/v1/summary/daily?date=YYYY-MM-DD` | totals per label and kind, plus goal results |
| GET | `/healthz`, `/readyz` | no auth |
| GET | `/` | dashboard page; enter any API key to view a day's goals, totals and timeline |
| Method | Path | Auth | Accepted kinds |
|---|---|---|---|
| POST | `/api/v1/desktop/events` | key | `app_focus`, `idle`, `locked` |
| POST | `/api/v1/browser/events` | key | `tab_focus`, `idle` |
| POST | `/api/v1/presence/events` | key | `at_desk`, `in_bed`, `away` |
| POST | `/api/v1/manual/events` | key | any |
| POST | `/api/v1/health/hae` | key | Health Auto Export JSON. Workouts and sleep become activities; other metrics become samples |
| GET | `/api/v1/activities?from=&to=&source=&kind=&limit=` | key or admin | RFC3339 times; defaults to the last 24h |
| GET | `/api/v1/summary/daily?date=YYYY-MM-DD` | key or admin | totals per label and kind, plus goal results |
| GET, POST | `/api/v1/devices` | admin | list devices; create one with `{"name","kind"}`, which returns its key once |
| DELETE | `/api/v1/devices/{name}` | admin | revoke a device's key |
| GET | `/`, `/setup` | admin | dashboard and setup pages |
| GET | `/tracker.user.js`, `/healthz`, `/readyz` | none | the browser userscript holds no secrets |
The event batch format is shared by all `*/events` endpoints. A batch holds at most 1000 events.
@@ -136,6 +151,19 @@ listener {
}
```
## Browser
The browser collector is a [Violentmonkey](https://violentmonkey.github.io/) userscript served by the tracker itself. It runs in every tab and records a `tab_focus` interval, labelled with the hostname (`www.` stripped, so goals use `youtube.com`), only while that tab is the selected tab of the focused browser window. Focus that lasts under 2s is dropped. The interval ends after 5 minutes without mouse or keyboard input, unless a video or audio element is playing. Time spent asleep or suspended is never counted.
The setup page has these steps with your URL filled in.
1. Create a key with kind `browser` on the setup page, or with `tracker apikey create --name laptop-firefox --kind browser`. Use one key per browser.
2. Install Violentmonkey and open `https://www.adam-french.co.uk/tracker/tracker.user.js`. Violentmonkey offers to install the script and later checks that URL for updates.
3. From the Violentmonkey toolbar menu, choose **Set server and API key**. Enter `https://www.adam-french.co.uk/tracker` and the key.
4. Other menu commands toggle full URLs (`attrs.url`, which also splits intervals per page) and page titles (`attrs.title`), set a regexp of hosts to ignore, change the idle timeout, and show the queue and last upload result.
Closed intervals are queued in the script's storage and uploaded every minute by one tab at a time. If a tab is closed or crashes mid-interval, another tab recovers its last checkpoint (at most 5s lost). The script can't see browser pages such as `about:`, `chrome://` or the new tab page, extension stores, or the built-in PDF viewer, so time there isn't recorded. The Hyprland agent still counts it as browser `app_focus`.
## Apple Health
In the Health Auto Export iOS app, create a **REST API** automation with these settings:
@@ -155,12 +183,11 @@ make up && make test-integration # also runs the API tests against the compose
make run # run the server locally against the compose Postgres
```
Layout: `cmd/tracker` (server and admin CLI), `cmd/hypr-agent`, `internal/{api,ingest,store,summary,migrations,config}`, `internal/agent/hypr`, `deploy/`.
Layout: `cmd/tracker` (server and admin CLI), `cmd/hypr-agent`, `internal/{api,auth,ingest,store,summary,migrations,config,web}` (`web/tracker.user.js` is the browser collector), `internal/agent/hypr`, `deploy/`.
## Roadmap
1. Browser extension (MV3, Firefox and Chromium). It will send hostnames by default and full URLs only if you opt in.
2. Webcam presence agent. Detection will run on the device and only intervals will be uploaded; frames never leave the machine.
3. Nudges: push notifications through ntfy when a goal is at risk during the day.
4. Location: an OwnTracks or Home Assistant geofence will provide reliable "time outside" intervals.
5. AI analysis: a nightly or weekly job will send the daily summaries (not raw rows) to the Claude API and store the result in `reports`.
1. Webcam presence agent. Detection will run on the device and only intervals will be uploaded; frames never leave the machine.
2. Nudges: push notifications through ntfy when a goal is at risk during the day.
3. Location: an OwnTracks or Home Assistant geofence will provide reliable "time outside" intervals.
4. AI analysis: a nightly or weekly job will send the daily summaries (not raw rows) to the Claude API and store the result in `reports`.