Repository navigation
Machine filter on Monitor + Analytics, hub URL in Settings, retire Electron path - #5
Merged
Merged
Conversation
ninedter
force-pushed
the
claude/fe-machine-filter
branch
from
September 10, 2026 14:25
0c90f9d to
e1e1e29
Compare
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
force-pushed
the
claude/fe-machine-filter
branch
from
September 10, 2026 14:28
e1e1e29 to
3ed0206
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsxmirrorsProviderFilter.tsx— All plus one option per machine fromGET /api/machines(label, falling back to id; the API already sorts bylast_seen_atdesc, All stays pinned first).machineParam(value)sits next toproviderParam(value)and emits nothing for All.variant="compact"so it inherits that toolbar's density and font-size tier.src/lib/machine-param.tsreads?machine=: absent /""/"all"→ unscoped, exactly like?provider=. The one deliberate difference fromreadProvider: 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 existingnormalizeMachineId). The client only ever sends ids it got from/api/machines.2. Routes that gained
?machine=sessions,agents,stats,eventsoverview,trends,sessions,tools,files,models,insights?machine=and?provider=combine; omitting either leaves that axis unscoped.In
db.tsthe existingpSql/pArghelpers were generalised to emit provider and machine clauses in a fixed order (pSqlnow takes a table alias prefix rather than a column name), so almost every query body was left untouched.listSessionsandlistAgentsalready accepted a machine id from PR #2 and were reused as-is. No schema changes.One nicety:
daily_usagehas amachine_idcolumn (it just has noprovidercolumn), so a machine-only scope keeps the cheap rollup path ingetAnalyticsTrends/getModelAnalyticsinstead of falling back to a livetoken_usagejoin.Live stream: unchanged, documented
/api/monitor/streamis 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 byevent.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-inforeturns{ hub_url }fromprocess.env.NEXT_PUBLIC_HUB_URL || 'http://henrys-mac-mini:3789', and the Settings card fetches it. Settings is a client component, and Next.js inlinesNEXT_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/, theelectron:*scripts and theelectron-builderblock all still resolve, andnpm run build/npm test/ the Docker image never touched them.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).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 throughreadMachine), 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/machinesstill lists (contract unchanged), and/api/hub-inforeturns the locked default when unset and the env value when set.npm test189 passed ·npm run lintclean ·npm run buildclean.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/:agentIdroute is a follow-up rather than part of this cut.🤖 Generated with Claude Code