Skip to content

Shell: --headless for agents, --stop, close to tray, single instance - #251

Merged
timoncool merged 1 commit into
timoncool:mainfrom
x3vyx:headless-and-close-to-tray
Nov 16, 2026
Merged

timoncool merged 1 commit into
timoncool:mainfrom
x3vyx:headless-and-close-to-tray

Conversation

@x3vyx

@x3vyx x3vyx commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Why

An agent driving the studio over MCP has to start it when it is closed, and today that puts the studio's window on the user's screen and takes the focus while they are working on something else. This lets an agent use the studio without anything appearing, and adds the close-to-tray choice that goes with it.

What changes

  • --headless: the main window is still created (parts of the studio run in its page) but never shown or focused, with no taskbar button. A tray icon is the only sign of it.
  • Idle stop: a studio started headless quits by itself after ten minutes with no agent call and nothing at work (songs, stems, training, downloads...). YUE_STUDIO_IDLE_SHUTDOWN_S sets another period.
  • Opening the studio normally while it runs headless brings the window up in the same session, which is an ordinary one from then on (no idle stop).
  • --stop: ends a running studio only when its window is not on screen and nothing is at work. It never shows a question. With nothing running it exits at once and starts nothing.
  • Close to tray: a new choice in Settings, off by default. With it on, the close button hides the window and the studio keeps running; the tray icon brings it back (left click) and has Open / Quit. Quit goes through the existing confirm_quit.
  • Single instance (tauri-plugin-single-instance): a second launch hands its flags to the running studio and ends. It used to open a second window on the same service.
  • Docs: docs/mcp-skill.md and the README tell an agent to start with --headless.
Launch Nothing running Headless session (window hidden) Window on screen
plain normal start window shown, session becomes ordinary window brought forward
--headless hidden window, tray icon, idle stop counts as use, nothing shown no effect
--stop exits at once quits if nothing is at work stays

How agent use is told from the window's own requests

The hidden page keeps polling, so it cannot count as use. crates/music-server/src/agent_use.rs is a layer on the public router (inside the access guard): a request whose Origin or Referer is the window's page (tauri://localhost, http://tauri.localhost, or the dev server) is the window's; everything else, and every /mcp call, is use. A call counts for as long as it is open, so a slow call is not cut off. The shell asks the service about work in progress inside the process, not over HTTP, so its own question is not counted.

Tested

  • cargo test in desktop/src-tauri (8 passed), cargo test -p music-server --locked (525 passed), npx vitest run (212 passed), npx tsc --noEmit.
  • Live on Windows 11 with a debug build: --headless start with no visible or focused window (windows of the process enumerated from outside), the idle stop firing while the hidden page polled, agent calls keeping it alive, a second --headless, --stop on a hidden session, --stop with nothing running, a plain second launch bringing the window up, a saved maximised state staying hidden. Tray icon and close-to-tray toggle tried by hand.

Not tested

  • macOS and Linux were not built. The cfg(target_os = "macos") branches (set_dock_visibility, RunEvent::Reopen) are uncompiled, and whether a maximised restore keeps a hidden window hidden on macOS is unverified. On Linux the tray gives no click events, so only the menu works there.
  • The update install path was only compiled.

Things you may want different

  • The tray menu labels ("Open YuE2 Studio", "Quit") are fixed English, like the macOS "Quit YuE2 Studio" item. The Settings strings are in all five locales (ru/zh/ja/ko are machine-written, please check them).
  • With single instance always on, a dev build started beside an installed studio hands over to it and exits.
  • The idle stop and --stop reuse quit_now: a song started in the milliseconds between the last check and the quit would be cancelled.
  • On macOS/Linux a song playing in the hidden window may count as use if WebKit sends no Referer for media.

🤖 Generated with Claude Code

An agent that finds the studio closed can start it with --headless: the
window is made but never shown or focused, a tray icon is the only sign of
it, and the studio stops by itself after ten minutes with no agent call and
nothing at work (YUE_STUDIO_IDLE_SHUTDOWN_S sets other seconds). Opening the
studio the usual way brings the window up in the same session, which is an
ordinary one from then on. --stop ends a studio whose window is not on
screen and that has nothing at work, and never asks anything.

Settings has a new choice, off by default: closing the window keeps the
studio running in the system tray.

A second launch now hands its flags to the running studio and ends, where it
used to open a second window on the same service.

The service tells an agent's calls from the window's own by the Origin and
Referer of the request, so the hidden page's polling is not use.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@timoncool

Copy link
Copy Markdown
Owner

Merged into the 4.1.0 branch (next-4-0-1, 789d683) with the one conflict in serve() resolved and the Portuguese strings of the new setting added (the studio has a sixth language since your branch). The service tests, the eight shell tests and tsc pass on the merge. Still to come before the release: the live run of --headless, the idle stop, --stop, the tray and a second launch on the built shell, and the macOS and Linux builds, which your branch did not compile. The pull request closes itself when the branch reaches main; the changelog entry names it. Thank you.

@timoncool
timoncool merged commit 789d683 into timoncool:main Nov 16, 2026
@x3vyx
x3vyx deleted the headless-and-close-to-tray branch November 16, 2026 20:44
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.

2 participants