Skip to content

Machine filter on Monitor + Analytics, hub URL in Settings, retire Electron path - #5

Merged
ninedter merged 1 commit into
mainfrom
claude/fe-machine-filter
Sep 10, 2026
Merged

ninedter merged 1 commit into
mainfrom
claude/fe-machine-filter

Conversation

@ninedter

Copy link
Copy Markdown
Owner

Smallest shippable web-UI cut for the multi-machine hub: pick a machine the same way you pick a provider, see the hub's URL in Settings, and stop telling users to install a desktop app.

1. Machine filter (Monitor + Analytics)

src/components/ui/MachineFilter.tsx mirrors ProviderFilter.tsx — All plus one option per machine from GET /api/machines (label, falling back to id; the API already sorts by last_seen_at desc, All stays pinned first). machineParam(value) sits next to providerParam(value) and emits nothing for All.

  • Analytics — next to the provider filter in the header.
  • Monitor — in the view-mode toolbar next to the provider buttons, variant="compact" so it inherits that toolbar's density and font-size tier.
  • The filter hides itself until a second machine has reported: on a single-machine hub, All is that machine, so the control would be pure noise. Existing single-machine installs see no UI change.

src/lib/machine-param.ts reads ?machine=: absent / "" / "all" → unscoped, exactly like ?provider=. The one deliberate difference from readProvider: a provider is one of two known literals, so an unrecognised value can safely mean "unscoped", but a machine id is free-form — silently ignoring a typo would show every machine's rows under one machine's heading. So a present-but-malformed value is a 400 (INVALID_MACHINE), validated against the same charset ingest already enforces ([A-Za-z0-9._:-], 1–128, via the existing normalizeMachineId). The client only ever sends ids it got from /api/machines.

2. Routes that gained ?machine=

Group Routes
Monitor sessions, agents, stats, events
Analytics overview, trends, sessions, tools, files, models, insights

?machine= and ?provider= combine; omitting either leaves that axis unscoped.

In db.ts the existing pSql/pArg helpers were generalised to emit provider and machine clauses in a fixed order (pSql now takes a table alias prefix rather than a column name), so almost every query body was left untouched. listSessions and listAgents already accepted a machine id from PR #2 and were reused as-is. No schema changes.

One nicety: daily_usage has a machine_id column (it just has no provider column), so a machine-only scope keeps the cheap rollup path in getAnalyticsTrends/getModelAnalytics instead of falling back to a live token_usage join.

Live stream: unchanged, documented

/api/monitor/stream is global — the SSE protocol here carries no per-connection subscription filter, and it never had one for providers either (the client has always filtered frames by event.provider). Machine scoping follows the same shape: REST/poll views scope server-side, the Monitor filters incoming SSE frames client-side against the current machine. Scoping the stream itself would be a protocol change and is out of scope; it's noted in the README.

3. Settings — hub URL

New unauthenticated GET /api/hub-info returns { hub_url } from process.env.NEXT_PUBLIC_HUB_URL || 'http://henrys-mac-mini:3789', and the Settings card fetches it. Settings is a client component, and Next.js inlines NEXT_PUBLIC_* at build time — reading it in the browser would display whatever the image was built with, not what the container was started with. Read-only display, no auth invented, no new hostnames.

4. Electron copy retirement

Docs and UI copy become browser → hub only. No code was deleted: electron/, the electron:* scripts and the electron-builder block all still resolve, and npm run build / npm test / the Docker image never touched them.

  • README: desktop-app quick-start step, DMG build instructions, Electron badge, the Electron cold-start / packaged-app performance rows, and the "the Electron app started its own server" troubleshooting entry are gone; the architecture section and mermaid diagram now show one server + browsers + edge machines; electron/ is labelled retired in the project structure and Development.
  • hooks/claude-hooks-config.json: the copy-paste comment no longer advertises the Electron port file (the hook script still probes a leftover file, and its internal comments still say so — that's accurate, not guidance).
  • Settings gains the Hub card and drops the "draggable for Electron window movement" header comment.
  • Test count corrected while in there: README said 133 in Development and 155 in the badge → both now 189.

Tests

34 new tests across two files, plus all existing provider-filter tests untouched and green.

  • src/lib/__tests__/machine-filter.test.ts — readMachine (absent/""/all → unscoped; valid ids incl. host:port; space/semicolon/quote/129-char → null), machineParam (All sends nothing, ids url-encoded, round-trips through readMachine), label-vs-id display, and db scoping with two machines reporting the same session and agent ids — the case the composite keys exist for.
  • src/app/api/__tests__/machine-scope-routes.test.ts — route-level: All/omitted returns everything, a machine scopes it, combines with ?provider=, seven routes answer 400 on a malformed id, /api/machines still lists (contract unchanged), and /api/hub-info returns the locked default when unset and the env value when set.

npm test 189 passed · npm run lint clean · npm run build clean.

Not in this PR

Edge agent, ingest auth, schema/migrations, mTLS, VPS, Windows edge, deploying to henrys-mac-mini, any UI login. GET /api/machines' contract is unchanged.

Known limitation (pre-existing, unchanged)

The Monitor's client-side agent map is keyed by agent id alone, so two machines reporting the same agent id would collide in the live view (the server-side queries key correctly on (machine_id, id)). Provider ids are UUIDs in practice, so this is theoretical; re-keying the client maps and the /api/monitor/events/:agentId route is a follow-up rather than part of this cut.

🤖 Generated with Claude Code

@ninedter
ninedter force-pushed the claude/fe-machine-filter branch from 0c90f9d to e1e1e29 Compare September 10, 2026 14:25
The hub knows which machine every row came from (PR #2), but the UI had no
way to ask for one machine's view. This adds a machine filter alongside the
provider filter, threads `?machine=` through the routes the two pages call,
and replaces the Electron-first framing with the browser -> hub story the
product actually ships.

Filter
- `src/lib/machine-param.ts`: `readMachine()` mirrors `readProvider()` —
  absent/""/"all" mean unscoped. Unlike a provider, a machine id is
  free-form, so a present-but-malformed value is a 400 rather than a silent
  fall back to unscoped, which would show every machine's rows under one
  machine's heading. Validated against the charset ingest already enforces.
- `src/components/ui/MachineFilter.tsx`: All + one option per machine from
  `GET /api/machines` (label, falling back to id), with `machineParam()`
  next to `providerParam()`. Hides itself until a second machine reports —
  on a single-machine hub, All is that machine.
- Wired next to the provider filter on Analytics and in the Monitor toolbar
  (compact variant, matching that toolbar's density).

Routes that gained `?machine=`
- monitor: sessions, agents, stats, events
- analytics: overview, trends, sessions, tools, files, models, insights

`pSql`/`pArg` in db.ts now emit provider and machine clauses in one order,
so the query bodies were left alone. daily_usage has machine_id (just no
provider column), so a machine-only scope keeps the cheap rollup path.

`/api/monitor/stream` stays global — the SSE protocol has no per-connection
filter and never had one for providers either — so the Monitor filters
incoming frames client-side and the REST views scope server-side.

Settings + Electron retirement
- New `GET /api/hub-info` returns the hub URL at request time; Settings
  fetches it rather than reading `NEXT_PUBLIC_HUB_URL`, which Next.js
  inlines at build time and would misreport what the container is running.
  Default stays `http://henrys-mac-mini:3789`.
- README/hook config drop the desktop-app path: no DMG build step, no
  Electron cold-start rows, no "the Electron app started its own server"
  troubleshooting. `electron/` and its scripts stay in the tree (nothing in
  build/test/Docker touches them) and are labelled retired.
- Test count corrected: 133/155 -> 189.

Tests: 34 new (readMachine validation, machineParam round-trip, db scoping
across two machines reporting the same session/agent ids, route-level
scoping and 400s, /api/machines, hub-info default vs env). 189 pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ninedter
ninedter force-pushed the claude/fe-machine-filter branch from e1e1e29 to 3ed0206 Compare September 10, 2026 14:28
@ninedter
ninedter merged commit c686042 into main Sep 10, 2026
1 check passed
@ninedter
ninedter deleted the claude/fe-machine-filter branch September 10, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant