Watch
0
0
Fork
You've already forked hyperhive
0

remove the agent's stats page and its endpoint

This commit is contained in:
iris 2026-11-16 19:00:52 +01:00
commit 6ed714a0a7
5 changed files with 49 additions and 1744 deletions

View file

@ -60,14 +60,15 @@ The `hive-bash-daemon` (not the harness) writes a sibling
file: one row per executed bash task recording the normalised command head -
the basename of the first real command, looking past `cd repo &&`
prefixes, env-assignments, and prefix-runners like `sudo`/`env`. It
backs the "favorite tools" view on the /stats page. Best-effort and created on first write
feeds the bash-command counter in the agent's OTEL metrics. Best-effort and created on first write
(`CREATE TABLE IF NOT EXISTS`), so it's absent until a bash
task runs.
turn-stats.sqlite has **no vacuum** — it's one small row per turn
(~hundreds of KB even over months), read directly by the `/stats` page,
so pruning it would only lose trend
history for no space gain.
(~hundreds of KB even over months), so pruning it would only lose trend
history for no space gain. The agent has no page that charts it; the
[legacy stats viewer](https://forge.constellation.darkest.space/hyperhive/legacy-stats-viewer)
turns the file into the old stats page.
### `/state/hyperhive-harness.json` (per agent)

View file

@ -379,8 +379,7 @@ checking file existence):
| request | resolved | outcome |
| --- | --- | --- |
| `/agent/iris/` | no file match → `@iris_dynamic` | proxied to the agent daemon, which redirects to `stats` |
| `/agent/iris/stats` | `<frontend>/stats.html` | stats page |
| `/agent/iris/` | no file match → `@iris_dynamic` | proxied to the agent daemon, which has no page there |
| `/agent/iris/screen` | `<frontend>/screen.html` | screen page |
| `/agent/iris/static/app.js` | caught by `^~` block first | served with immutable cache |
| `/agent/iris/api/state` | no file match → `@iris_dynamic` | proxied to agent daemon |

View file

@ -68,7 +68,6 @@ container needs a stable numeric id across a full destroy + recreate.
```nix
services.hyperhive.agent.dashboardLinks = [
{ label = "Stats"; icon = "📊"; url = "http://localhost:9001/stats"; }
{ label = "Scratchpad"; url = "http://localhost:8080"; }
];
```

View file

@ -1,8 +1,7 @@
# Per-agent web server: stats, screen and endpoints
# Per-agent web server: screen and endpoints
What each agent's harness serves on its own port: the stats page, the GUI
screen page, the stream `hivectl watch` reads, the dashboard card's state and
the extra proxies. The operator's overview is
What each agent's harness serves on its own port: the GUI screen page, the
stream `hivectl watch` reads, the dashboard card's state and the extra proxies. The operator's overview is
[the agent web server](../../2-handbook/agents/web-page.md). The agent has no
terminal page of its own: the live terminal and its message box are in the swarm
UI.
@ -13,18 +12,14 @@ The agent has no login flow of its own. An agent without credentials
reports `needs_login_idle`, the operator logs in from the swarm UI, and the
credentials arrive from the swarm secret store.
- `GET /api/state` — `{label, dashboard_port}`: the agent's name, for the stats
and screen pages' titles and the screen's login, and the hive dashboard's port
for their way back.
- `GET /api/state` — `{label, dashboard_port}`: the agent's name, for the screen
page's title and login, and the hive dashboard's port for its way back.
- `GET /api/dashboard-state` — lean snapshot of agent-owned fields
fetched once per running agent by the dashboard's container row to
get fresh values without relying on hive-c0re's periodic file-reads.
Returns `{ status_text?, status_set_at?, rate_limited, links }`. Only called when the container is running;
skipped (muted badges) when stopped. Also accessible via the gateway
at `/agent/<name>/api/dashboard-state`.
- `GET /api/stats?window=24h|7d|30d|all` — time-bucketed turn analytics
`Snapshot` consumed by the `/stats` page. `all` ranges from the
earliest recorded turn with an adaptive bucket width.
- `GET /icon` — agent's icon as `image/svg+xml`. Returns
`/etc/hyperhive/icon.svg` (set via `services.hyperhive.agent.icon` in `agent.nix`)
when present, otherwise **404** — there is no server-side default.
@ -74,7 +69,6 @@ credentials arrive from the swarm secret store.
no UDS transport. Implemented in `web_ui/proxy.rs`.
- `GET /events/stream` — the live SSE stream of classified terminal rows, which
`hivectl watch` reads. The swarm UI shows the same rows from the swarm queue.
- `GET /` redirects to `/stats`.
Bus events on `/events/stream`:
@ -94,45 +88,3 @@ Bus events on `/events/stream`:
totals).
- `turn_state_changed { state, since_unix }` — drives the
state badge (`idle`/`thinking`/`compacting`).
## Stats page
`GET /stats` is a per-agent page (served by the
harness, linked from each dashboard container row). Turn analytics, read-only, from
`/state/hyperhive-turn-stats.sqlite`. `GET /api/stats?window=
24h|7d|30d|all` returns a time-bucketed `Snapshot`; the page renders
it with Chart.js (bundled into `stats.js` via esbuild — no CDN
dependency). Charts: turns, duration (p50 · p95 · avg), context
tokens, token cost per bucket, a **turns-by-model** stacked bar
(model choice drives token cost, so it sits directly under the
cost chart), doughnuts for tool / wake-source / result mix, and a
**result-trend** stacked bar — per-bucket `result_counts` so
error / rate-limit / compaction outcomes are visible over time
(the doughnut shows only the window total).
A **favorite tools** doughnut shows the most-run shell commands —
normalised `bash_commands` heads written per bash task by the
hive-bash-daemon capture: the basename of the _first real command_,
looking past `cd repo &&` prefixes, env-assignments, and
prefix-runners like `sudo` / `env` (so `cd /repo && cargo build`
records `cargo`, not `cd`). Read via `bash_breakdown`; the card
stays hidden until the agent has run a bash command (a missing
`bash_commands` table degrades to an empty list), so it never
renders an empty chart.
A summary chip row carries window totals, plus two
token-efficiency chips derived from the bucket sums: **cache
hit-rate** (`cache_read` over all input-side tokens) and
**tokens/turn**. When `reminder_stats` is present (fetched via
`ReminderRollup` RPC and merged into the snapshot in
`web_ui/stats.rs::api_stats`) three more chips appear: **reminders
scheduled / delivered / pending** for the window. When the
per-session capture has data, a **first-turn ctx** chip shows the
input tokens of the most recent fresh claude session's first turn —
a proxy for system-prompt + AGENTS.md sprawl (a fresh session's first
turn pays the full static prefix uncached). It's derived in `stats.rs`
(`first_turn_ctx`: the first turn, `ORDER BY started_at LIMIT 1`, of
the latest `sessions` row in the window) and stays out of the JSON
until the `sessions` / `turn_stats.session_id` capture has rows — so
the chip stays hidden on older dbs (inert-until-capture).
`stats.rs` opens the sqlite db read-only and degrades to an
empty snapshot on any error — the page is decorative, never
authoritative.

View file

@ -282,11 +282,11 @@ without its last path segment.
That makes the page work under any prefix the agent ends up mounted
at without rebuilding the dist. The cases that matter:
| served at | `api/state` resolves to |
| ------------------------------------------------ | ----------------------- |
| `/` (own port, today's shape) | `/api/state` |
| `/agent/iris/` (gateway-prefixed) | `/agent/iris/api/state` |
| `/agent/iris/stats` (subpage, no trailing slash) | `/agent/iris/api/state` |
| served at | `api/state` resolves to |
| ------------------------------------------------- | ----------------------- |
| `/` (own port, today's shape) | `/api/state` |
| `/agent/iris/` (gateway-prefixed) | `/agent/iris/api/state` |
| `/agent/iris/screen` (subpage, no trailing slash) | `/agent/iris/api/state` |
The gateway upstream config strips the prefix before forwarding to
the per-agent server, so the agent's Rust routes (`api/state`,
@ -294,9 +294,9 @@ the per-agent server, so the agent's Rust routes (`api/state`,
paths server-side. Only the browser-facing URLs key off the
mount prefix.
The router serves subpages (`stats`, `screen`) without a trailing slash so
the relative-path resolution stays correct: `static/stats.js` from
`/stats` becomes `/static/stats.js` (last segment `stats` gets
replaced), not `/stats/static/stats.js`. Adding a trailing slash to
The router serves subpages (`screen`) without a trailing slash so
the relative-path resolution stays correct: `static/agent.css` from
`/screen` becomes `/static/agent.css` (last segment `screen` gets
replaced), not `/screen/static/agent.css`. Adding a trailing slash to
those routes would break the resolution; either keep them
slash-less or use `<base href>` injection at serve time.