vps-health-api/README.md
le king fu 9fd43c0d5a
All checks were successful
CI / verification (pull_request) Successful in 37s
docs: slim CLAUDE.md below 30k characters, move details to docs/ (#67)
CLAUDE.md went from 50 987 to about 16 100 characters, under Claude Code's
40 000-character warning. The detail moves to three docs that are not
imported, so they cost no context at session start:

- docs/endpoints.md: the full contract of every route, merged with the
  README examples (body shapes, JSON samples, curl), plus the write
  mechanics that were in Gotchas (write surfaces, atomic writes,
  whitelist rebuild, body cap).
- docs/mounts.md: the Coolify mounts, the two protection layers, the
  three-view check and the mount modification procedure.
- docs/tests.md: the per-file test detail and the two CI scripts, minus
  the case counters, which npm test reports and which went stale with
  every PR (Max's choice of 2026-10-20).

Text moved by script, word for word. A line-by-line check finds every
removed line in docs/, apart from the counters and one fix: POST /hosts
is the first of three write surfaces, not two.

CLAUDE.md keeps "Routage et auth", Deploy and the config variables as
they were, one line per route, a short mounts table, the three test
guards and every gotcha in a line or two.

README.md drops its stale per-route, config and mounts detail, which
lacked /claude-usage/history and files[], and links to docs/ instead.
REVIEW.md now cites the file that holds each rule. docs/** joins
NEVER_LOW in review-levels.py and the never-low list of REVIEW.md, since
it now carries the route contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:30:39 -04:00

3.1 KiB

vps-health-api

Lightweight health monitoring API for the VPS. Node 22, HTTP-native, zero runtime deps.

Endpoints

Read endpoints require Authorization: Bearer $HEALTH_TOKEN. Each write endpoint has its own token — $HOSTS_INGEST_TOKEN for workstation snapshots, $CLAUDE_USAGE_INGEST_TOKEN for the Claude usage snapshot, $BACKUPS_INGEST_TOKEN for the backup pull report — so an agent can push its data without gaining read access to the Defenseurs reports, and no ingestion token opens another one's route.

Method Path Token Description
GET /health HEALTH_TOKEN CPU, memory, disk, uptime, Logto reachability
GET /defenseurs HEALTH_TOKEN Defenseurs executive status (status.json)
GET /defenseurs/findings?project=X HEALTH_TOKEN Detailed findings for a project's Defenseur
GET /defenseurs/state HEALTH_TOKEN Sergent's per-finding state (findings-state.json)
GET /reports/scans?date=YYYY-MM-DD HEALTH_TOKEN Aggregated scan reports for a UTC date
GET /hosts HEALTH_TOKEN Latest snapshot of every allowlisted workstation
POST /hosts/<id> HOSTS_INGEST_TOKEN Ingest one workstation snapshot
GET /claude-usage HEALTH_TOKEN Latest Claude usage snapshot, with server-side staleness
POST /claude-usage CLAUDE_USAGE_INGEST_TOKEN Ingest the Claude usage snapshot
GET /backups HEALTH_TOKEN PostgreSQL backups: VPS status and last workstation pull, with server-side staleness
POST /backups/pull BACKUPS_INGEST_TOKEN Ingest the workstation's pull report
GET /claude-usage/history?from=YYYY-MM&to=YYYY-MM HEALTH_TOKEN Archived closed days of Claude usage (12 months by default)

Routing resolves before authentication: an unknown path or a wrong method answers 404, never 401.

Full contract of every route — bodies, response codes, examples, the whitelist rebuild and the atomic writes behind the three POST routes: docs/endpoints.md (in French).

Config

Environment variables and their defaults are listed in CLAUDE.md (« Config »). Every token is fail-closed: a missing HEALTH_TOKEN answers 401 on reads, a missing ingest token 503 on its own route.

Bind-mounts (Coolify)

Three read-only mounts (the Defenseurs files and the VPS backup status) and three read-write ones owned by uid 1000 (/data/hosts, /data/claude-usage, /data/backups-pull), always mounting the directory, never the file. Paths, the two layers that keep the API out of the Defenseurs files, and the post-redeploy check: docs/mounts.md (in French).

Workstation agent

agent/ holds the zero-dependency collector that runs from cron on a workstation and feeds POST /hosts/<id>. It is not part of the server image — it is installed by copying files onto the machine it measures. Install steps, crontab line and failure modes: agent/README.md.

Tests

npm install
npm test
bash test-curl.sh
sh scripts/boot-from-copy.sh

What each test file and script guards: docs/tests.md (in French).