Skip to content

feat(gui): serve a browser frontend over loopback - #582

Merged
LargeModGames merged 3 commits into
refactor/private-display-domainsfrom
feat/gui-server
Sep 26, 2026
Merged

LargeModGames merged 3 commits into
refactor/private-display-domainsfrom
feat/gui-server

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

spotatui-gui was a placeholder that exited. It now boots like the terminal UI (the same instance lock, boot and prepare_frontend), serves an embedded page and a WebSocket on 127.0.0.1, and opens the browser at it.

What changed:

  1. src/gui/server.rs: a loopback server on httparse and tokio_tungstenite::accept_hdr_async. It checks Host, Origin and Sec-Fetch-Site against DNS rebinding and cross-site pages, sends no-store, nosniff and a strict CSP, and bounds each request and handshake at 5 s.
  2. The browser opens at /#code=<code>. The code is single-use, lives 60 s and is traded for a session token in hello. On Linux the server also refuses loopback peers of other users (/proc/net/tcp).
  3. src/gui/protocol.rs and src/gui/bridge.rs: ClientMessage in (action through App::apply, quit), Message out: hello, a resync, then each channel whose display revision moved (route, status, theme, playback, devices, queue) and a position tick about every 250 ms.
  4. src/runtime/gui.rs: a tick loop without a terminal. It boots with no_update: true and quits on Ctrl-C, a quit from the page, or a minute with no page.
  5. build.rs embeds gui/dist. Without it / answers 503 with a build hint.
  6. src/bin/spotatui-gui.rs calls run_gui. A windowed release build on Windows with no console shows its startup error in a message box.
  7. src/infra/loopback.rs shares the token helpers with the MCP control socket.
  8. A gui leg in ci.yml (check, clippy, test), the third leg without tui.

Deliberate behaviour changes a user can see:

  1. Default and release builds: none. gui is off by default and no release enables it.
  2. spotatui-gui runs instead of exiting, and refuses to start beside another spotatui UI.
  3. On a fresh profile it stops and asks for one run of the terminal spotatui first.

Testing

The suites ran on the top of the stack (feat/gui-onboarding), which contains this PR:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --locked -- -D warnings on slim, headless, headless-streaming, mcp-only, ai-dj-only, default, the gui leg and the five-sources set with audio-viz-cpal: all Finished, no warnings.
  • cargo test --locked, 0 failed on every leg: slim 1253 passed, headless 851 passed, mcp-only 1377 passed, ai-dj-only 1530 passed (the four dead-code warnings in infra/dj test helpers predate this stack), default 1630 passed, gui leg 1369 passed.

On this PR's own head: cargo clippy --locked -- -D warnings on slim, headless, default and the gui leg (--no-default-features --features telemetry,gui,streaming,discord-rpc,self-update,scripting,mcp-server,mpris): clean. cargo test --no-default-features --features telemetry,tui gates: ok. 10 passed. bash tools/check_gates_ratchet.sh against the PR below: ok.

Additional notes

Part 5 of 7 of a stack (#578 to #584). Base: #581.

Rebased onto #574 and #577. Beyond mechanical merges, the last commit makes run_gui open its log through the same start_logging as run_cli: SPOTATUI_LOG, a bare --debug (the crash notice asks for it), and the startup header.

Not verified here: the Linux peer check and the MPRIS build without tui run only in the gui CI leg, and no CI job builds gui on macOS. A live pass on Windows ran against the top of the stack before the rebase. This layer alone ships no page.

Residual risk: the launch code sits in the browser's command line while it starts. macOS has no peer check, so another local user there could race it. A private redirect file would keep the code out of argv, but snap-confined browsers cannot read one.

Source, Party, Search, Lyrics, Artist and Library have revisions but no message yet. The next PR adds the page, and the top PR moves the first-launch questions into it.


💬 Questions or want to chat with other contributors? Join the spotatui Discord.

Summary by CodeRabbit

  • New Features

    • Added a browser-based frontend, available through the GUI app. It opens in your default browser and supports playback, queue, theme, device, and other app updates.
    • Added secure local access controls for browser connections.
    • Added a GUI feature configuration to the CI matrix.
  • Improvements

    • Help, version, and command-line usage errors now appear before a log file is created.
    • Shared startup and shutdown behavior now supports both the terminal and browser frontends.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: cec0a197-8ae1-497d-9698-847048b91f82

📥 Commits

Reviewing files that changed from the base of the PR and between 77b19c3 and 9ad7622.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (25)
  • .github/copilot-instructions.md
  • .github/workflows/ci.yml
  • AGENTS.md
  • CLAUDE.md
  • Cargo.toml
  • build.rs
  • src/bin/spotatui-gui.rs
  • src/core/app/display_revisions.rs
  • src/core/mod.rs
  • src/core/theme.rs
  • src/gui/bridge.rs
  • src/gui/mod.rs
  • src/gui/protocol.rs
  • src/gui/server.rs
  • src/infra/loopback.rs
  • src/infra/mcp/control.rs
  • src/infra/mod.rs
  • src/lib.rs
  • src/runtime/bootstrap.rs
  • src/runtime/gui.rs
  • src/runtime/instance.rs
  • src/runtime/mod.rs
  • src/runtime/pump.rs
  • src/runtime/startup.rs
  • tools/gates.count

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

This pull request adds a feature-gated browser GUI. It embeds frontend assets, serves them from a loopback server, and connects the page to the application through a WebSocket protocol and bridge. It adds GUI runtime startup and CI coverage.

Changes

Browser GUI frontend

Layer / File(s) Summary
GUI feature, build, and entry point
.github/workflows/ci.yml, .github/copilot-instructions.md, AGENTS.md, CLAUDE.md, Cargo.toml, build.rs, src/bin/spotatui-gui.rs, src/lib.rs, src/runtime/mod.rs, src/runtime/startup.rs, src/runtime/instance.rs, src/core/mod.rs, tools/gates.count
The gui feature now enables the browser frontend and its binary entry point. The build script embeds gui/dist assets. The CI matrices add a GUI configuration. Shared runtime modules support GUI builds, and the documentation describes the browser frontend and updated matrix.
Display protocol and payloads
src/core/app/display_revisions.rs, src/core/theme.rs, src/gui/protocol.rs, src/runtime/pump.rs
The GUI protocol serializes supported display channels, emits revision-based diffs or full resync snapshots, and represents playback, queue, status, theme, device, and route data. GUI-only accessors and tests cover protocol and pump updates.
WebSocket bridge and state delivery
src/gui/mod.rs, src/gui/bridge.rs
The bridge sends hello and resync messages, publishes display changes and rate-limited ticks, and forwards client messages. It resynchronizes lagging sockets and tracks page disconnection time.
Loopback server and connection admission
src/infra/loopback.rs, src/infra/mcp/control.rs, src/infra/mod.rs, src/gui/server.rs
The loopback server serves embedded assets and checks HTTP requests and WebSocket credentials. Shared token helpers are enabled for GUI builds and replace the MCP server’s local token implementation.
GUI startup and serving loop
src/runtime/gui.rs, src/runtime/bootstrap.rs
The GUI runtime boots shared frontend services, starts the server, opens or prints the page URL, and processes driver ticks and client messages. It exits on quit, disconnect, Ctrl-C, or a minute without a connected page. Interactive onboarding operations return a terminal-setup error.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant spotatui-gui
  participant run_gui
  participant spawn_listener
  participant run_socket
  participant Browser
  spotatui-gui->>run_gui: start GUI entry point
  run_gui->>spawn_listener: start loopback listener
  run_gui->>Browser: open page URL with launch code
  Browser->>spawn_listener: request page and WebSocket connection
  spawn_listener->>run_socket: admit WebSocket and pass socket
  run_socket->>Browser: send hello and resync snapshot
  Browser->>run_socket: send client action or quit message
  run_socket->>run_gui: forward client message through inbox
Loading

Merge Risk: ⚪ Minimal · up to 9ad76

This adds a browser frontend behind the off-by-default gui feature, served only on loopback. The server checks Host and Origin and requires a single-use launch code before a page can connect. Default builds are unaffected, and no merge-blocking issue was found.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 9ad76

The new browser frontend has meaningful local security boundaries. Its request and credential checks limit exposure, but cross-user protection differs by platform, and a failed connection can consume the one-time launch code before a session starts.

Retained concerns

  • Medium · security · inferred: On non-Linux platforms, the new listener has no same-user peer check. If another local user can observe the browser launch URL during the code's lifetime, possession of its code can grant a session with application-action authority.
  • Low · reliability · observed: Admission consumes the sole launch code inside the WebSocket handshake callback. A disconnect, handshake failure, or timeout after that callback can leave the intended browser unable to retry with its code, without having received a session token.
Security review details

Security Blast Radius

  • inferred — A client that obtains GUI session admission can send actions into the user's running application, rather than merely reading static assets. The listener's network exposure is limited to loopback; the independently attackable cross-user scope depends on platform and launch-code visibility.

Security Findings and Attack Paths

  • inferred — Potential cross-user path on non-Linux systems: observe the short-lived launch URL, present its code from a local client, and receive the session token before the intended browser consumes the code. The supplied evidence does not establish that URL observation is available to another user on every target platform.

Trust Boundaries and Controls

  • observed — The strongest counterevidence to a remote or cross-site action path is the loopback bind, Host and Origin checks, mandatory WebSocket credential admission, and Linux same-user peer check. Code consumption is atomic and subject to a 60-second lifetime.

Resilience and Maintainability Implications

  • observed — Single-use admission prevents concurrent reuse of a valid code, but consumption precedes completion of the awaited handshake and has no visible recovery path on failure. That ordering can strand legitimate admission.

Hardening Proposals

  • proposed — Consider a platform-appropriate same-user peer check or a launch mechanism that does not expose a bearer code to other local users; make failed handshakes recoverable without allowing code replay.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the valid conventional-commit prefix feat(gui):, clearly describes the browser frontend served over loopback, and uses a concise imperative subject.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
✨ Simplify code
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LargeModGames LargeModGames changed the title feat/gui server feat(gui): serve a browser frontend over loopback Sep 26, 2026
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/runtime/mod.rs 0.0% 7 Missing ⚠️
src/runtime/startup.rs 0.0% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@LargeModGames

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

spotatui-gui now boots like the terminal UI (the same lock, boot and frontend runtime), serves the embedded page on 127.0.0.1:<random port> and opens the browser at a one-time launch code. The server checks Host and Origin against DNS rebinding and cross-site pages, trades the single-use code (60 s) for a session token in the WebSocket subprotocol, and sends no-store, nosniff, no-referrer and a strict CSP. Each socket gets a hello, a full resync, and then every channel whose display revision moves (route, status, theme, playback, devices, queue) plus a 250 ms position tick; page actions go through App::apply on the tick loop. The process quits on Ctrl-C, a quit from the page, or a minute with no page. A fresh profile still needs one terminal run for the first-launch setup. build.rs embeds gui/dist when it exists. A new CI leg builds the GUI without tui.
…tup errors

On Linux the server refuses a loopback connection whose socket belongs to another user (read from /proc/net/tcp), because another user can read the launch URL from the browser's command line. One deadline covers the whole answer to a plain request and the socket handshake, not only the head. The position tick allows 20 ms of timer jitter, so a 250 ms tick loop does not drop every other tick. A windowed Windows build started without a console shows its startup error in a message box. New tests: the rebinding case on the Host check, a head that never ends, a lagging socket's resync, and the Linux peer lookup.
run_gui now shares start_logging with run_cli, so SPOTATUI_LOG and a bare --debug set its level and every GUI log starts with the version, platform and feature header.
@LargeModGames

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@LargeModGames
LargeModGames merged commit 2502c59 into main Sep 26, 2026
35 checks passed
@LargeModGames
LargeModGames deleted the feat/gui-server branch September 26, 2026 11:43
LargeModGames added a commit that referenced this pull request Sep 26, 2026
# Summary

This adds the browser side of `spotatui-gui`: TypeScript types generated
from the Rust wire types, and a React page in `gui/` that talks to the
loopback server from the PR below. The page is a placeholder that
exercises the bridge and the CI gates. It is not a design, and the
designed screens will replace it.

What changed:

1. `Action`, the types it carries and the GUI protocol types derive
`ts_rs::TS` under `cfg_attr(all(test, feature = "gui"), ...)`. `ts-rs`
is a dev-dependency pinned to `=12.0.1`, so no shipped binary changes.
The protocol enum `Message` is now `ServerMessage`.
2. `typescript_bindings_are_written_to_the_frontend_source_tree`
rewrites `gui/src/bindings/` with `u64` as `number`, and fails when two
exported types share a name or any file contains `bigint`. The `gui`
test row in `ci.yml` fails when the committed files drift.
3. `gui/` is Vite + React + TypeScript: a queue list and a now-playing
bar (art, title, artists, a progress bar interpolated from the tick,
Previous, Play/Pause, Next), coloured from the theme channel.
4. `gui/src/connection.ts` trades the launch code for the session token
and keeps the token in `localStorage`. It reconnects 1 s after a drop
that followed a hello. A close before hello shows "This page is no
longer connected to spotatui."
5. The new `gui.yml` runs `npm ci`, `lint`, `format:check`, `typecheck`,
vitest and the build on every PR, with no paths filter.
6. `Cargo.toml` excludes `/gui/` from the published crate. The pattern
is anchored, so `src/gui` stays in.
7. The page's `Content-Security-Policy` allows `http:` images, since
many Subsonic servers serve cover art over http.

Deliberate behaviour changes a user can see:

Only builds with the `gui` feature change. It is off by default and no
release ships it.

1. With `gui/dist` built, `spotatui-gui` serves this page instead of the
"built without its frontend" answer.
2. A closed tab reopened at the same address reconnects to the running
spotatui. Each run issues its own token.

# Testing

The suites ran on the top of the stack (`feat/gui-onboarding`), which
contains this PR:

- `cargo fmt --all -- --check`: clean.
- `cargo clippy --locked -- -D warnings` on slim, headless,
headless-streaming, mcp-only, ai-dj-only, default, the `gui` leg and the
five-sources set with `audio-viz-cpal`: all `Finished`, no warnings.
- `cargo test --locked`, `0 failed` on every leg: slim `1253 passed`,
headless `851 passed`, mcp-only `1377 passed`, ai-dj-only `1530 passed`
(the four dead-code warnings in `infra/dj` test helpers predate this
stack), default `1630 passed`, `gui` leg `1369 passed`.
- Bindings drift after the `gui` leg test: `git status --porcelain
gui/src/bindings` prints nothing.
- In `gui/`: `npm ci` (`found 0 vulnerabilities`), `npm run lint`, `npm
run format:check` (`All matched files use Prettier code style!`), `npm
run typecheck`, `npm test` (`Tests 21 passed (21)`), `npm run build` (`✓
built`).

On this PR's own head: `cargo clippy --locked -- -D warnings` on slim,
headless, default and the `gui` leg: clean. `cargo test
--no-default-features --features telemetry,tui gates`: `ok. 10 passed`.
`bash tools/check_gates_ratchet.sh` against the PR below: `ok`.

# Additional notes

Part 6 of 7 of a stack (#578 to #584). Base: #582.

Not verified here: no CI job embeds the built page into the binary (the
`gui` leg builds without `gui/dist`), so serving it rests on a manual
run on Windows. `npm ci` has only run on Windows, and `gui.yml` is the
lockfile's first Linux install. No browser on macOS or Linux was tried.

Trade-offs and follow-ups:

- `ts-rs` compiles on every test leg, though only the `gui` leg uses it.
A Dependabot bump of it fails the drift step until the bindings are
regenerated, by design.
- `typescript` is pinned `~6.0` because `typescript-eslint` accepts
`<6.1.0`.
- Dependabot has no npm entry for `gui/` yet.
- The queue list skips Spotify queue episodes.

---
<sub>💬 Questions or want to chat with other contributors? Join the
[spotatui Discord](https://spotatui.com/discord).</sub>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a web-based GUI for viewing the playback queue and now-playing
details, with playback controls and theme support.
  * Added automatic reconnection and connection status feedback.
* **Quality Improvements**
* Added automated checks for the GUI, including linting, formatting,
type checks, tests, and builds.
  * Enabled checks to detect outdated frontend bindings.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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