mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-08 13:12:08 +00:00
Merge pull request #55923 from NousResearch/bb/serve-headless-no-web-build
feat(cli): make hermes serve a real headless backend (no web UI build/mount, neutral ready sentinel)
This commit is contained in:
commit
91c68bf834
8 changed files with 93 additions and 16 deletions
|
|
@ -11928,6 +11928,11 @@ def cmd_dashboard(args):
|
|||
remaining = _find_stale_dashboard_pids()
|
||||
sys.exit(1 if remaining else 0)
|
||||
|
||||
# `serve` is the headless backend: no UI build, no SPA mount, neutral
|
||||
# ready sentinel. Resolved once and threaded through the re-exec, the
|
||||
# build gate, and start_server.
|
||||
_headless_backend = getattr(args, "headless_backend", False)
|
||||
|
||||
# ── Unified profile launch routing ────────────────────────────────
|
||||
# The dashboard is a MACHINE management surface: it can read/write any
|
||||
# profile via the per-request ?profile= scoping. Running one dashboard
|
||||
|
|
@ -11973,7 +11978,9 @@ def cmd_dashboard(args):
|
|||
reexec_argv = [
|
||||
sys.executable, "-m", "hermes_cli.main",
|
||||
"-p", "default",
|
||||
"dashboard",
|
||||
# Preserve the lean serve path across the re-exec so a named-profile
|
||||
# `serve` doesn't silently rebuild the UI as `dashboard`.
|
||||
"serve" if _headless_backend else "dashboard",
|
||||
"--port", str(args.port),
|
||||
"--host", args.host,
|
||||
"--open-profile", _launch_profile,
|
||||
|
|
@ -12042,7 +12049,11 @@ def cmd_dashboard(args):
|
|||
# backend is the desktop's primary entrypoint and needs the same.
|
||||
_sync_bundled_skills_quietly()
|
||||
|
||||
if "HERMES_WEB_DIST" not in os.environ and not getattr(args, "skip_build", False):
|
||||
if _headless_backend:
|
||||
# Don't build the SPA, and tell mount_spa() (read at web_server import
|
||||
# below) to disable it even if a stray dist exists. Set it first.
|
||||
os.environ["HERMES_SERVE_HEADLESS"] = "1"
|
||||
elif "HERMES_WEB_DIST" not in os.environ and not getattr(args, "skip_build", False):
|
||||
if not _build_web_ui(PROJECT_ROOT / "web", fatal=True):
|
||||
sys.exit(1)
|
||||
elif getattr(args, "skip_build", False):
|
||||
|
|
@ -12115,6 +12126,7 @@ def cmd_dashboard(args):
|
|||
open_browser=not args.no_open,
|
||||
allow_public=getattr(args, "insecure", False),
|
||||
initial_profile=getattr(args, "open_profile", "") or "",
|
||||
headless=_headless_backend,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
"""``hermes dashboard`` / ``hermes serve`` subcommand parsers.
|
||||
|
||||
``dashboard`` is the browser web UI; ``serve`` is the same gateway, headless —
|
||||
what the desktop app and remote backends run. Both share one handler
|
||||
(``cmd_dashboard`` → ``start_server``). Extracted from
|
||||
what the desktop app and remote backends run. ``serve`` also skips the web UI
|
||||
build (``headless_backend=True``): pure JSON-RPC/WS clients never load the SPA.
|
||||
Both share one handler (``cmd_dashboard`` → ``start_server``). Extracted from
|
||||
``hermes_cli/main.py:main()`` (god-file Phase 2); handler injected to avoid
|
||||
importing ``main``.
|
||||
"""
|
||||
|
|
@ -148,7 +149,11 @@ def build_dashboard_parser(
|
|||
serve_parser.add_argument(
|
||||
"--no-open", action="store_true", help=argparse.SUPPRESS
|
||||
)
|
||||
serve_parser.set_defaults(func=cmd_dashboard, no_open=True)
|
||||
# `headless_backend` marks the lean path: desktop/remote clients speak pure
|
||||
# JSON-RPC/WS, so `serve` skips the web UI build AND never serves the SPA
|
||||
# (cmd_dashboard exports HERMES_SERVE_HEADLESS=1). `dashboard` leaves it
|
||||
# unset and serves the browser UI as before.
|
||||
serve_parser.set_defaults(func=cmd_dashboard, no_open=True, headless_backend=True)
|
||||
|
||||
# `hermes dashboard register` — register a self-hosted dashboard OAuth
|
||||
# client with Nous Portal and write the client_id into ~/.hermes/.env.
|
||||
|
|
|
|||
|
|
@ -13930,13 +13930,21 @@ def mount_spa(application: FastAPI):
|
|||
and the SPA's runtime ``__HERMES_BASE_PATH__`` honour that prefix
|
||||
without rebuilding the bundle.
|
||||
"""
|
||||
if not WEB_DIST.exists():
|
||||
# `hermes serve` is the headless backend: it must NEVER serve the browser
|
||||
# SPA, even if a dist is lying around from a prior `dashboard`/build. Take
|
||||
# the no-frontend path so only the JSON-RPC/WS/API surface is reachable.
|
||||
_headless = os.environ.get("HERMES_SERVE_HEADLESS") == "1"
|
||||
if _headless or not WEB_DIST.exists():
|
||||
_msg = (
|
||||
"Headless backend (hermes serve): web UI disabled — use "
|
||||
"`hermes dashboard` for the browser UI."
|
||||
if _headless
|
||||
else "Frontend not built. Run: cd web && npm run build"
|
||||
)
|
||||
|
||||
@application.get("/{full_path:path}")
|
||||
async def no_frontend(full_path: str):
|
||||
return JSONResponse(
|
||||
{"error": "Frontend not built. Run: cd web && npm run build"},
|
||||
status_code=404,
|
||||
)
|
||||
return JSONResponse({"error": _msg}, status_code=404)
|
||||
return
|
||||
|
||||
_index_path = WEB_DIST / "index.html"
|
||||
|
|
@ -15176,6 +15184,7 @@ def start_server(
|
|||
open_browser: bool = True,
|
||||
allow_public: bool = False,
|
||||
initial_profile: str = "",
|
||||
headless: bool = False,
|
||||
):
|
||||
"""Start the web UI server.
|
||||
|
||||
|
|
@ -15183,6 +15192,10 @@ def start_server(
|
|||
URL as ``?profile=<name>`` so the SPA's profile switcher preselects it
|
||||
— used when a profile alias (``<profile> dashboard``) routes to the
|
||||
machine dashboard.
|
||||
|
||||
``headless`` is the ``serve`` path: the JSON-RPC/WS backend with no UI
|
||||
build and no SPA mount (mount_spa() honours ``HERMES_SERVE_HEADLESS``), so
|
||||
the banner announces the bind rather than a browser URL.
|
||||
"""
|
||||
import uvicorn
|
||||
|
||||
|
|
@ -15339,8 +15352,17 @@ def start_server(
|
|||
app.state.bound_port = actual_port
|
||||
|
||||
_write_dashboard_ready_file(actual_port)
|
||||
print(f"HERMES_DASHBOARD_READY port={actual_port}", flush=True)
|
||||
print(f" Hermes Web UI → http://{host}:{actual_port}")
|
||||
# Port-discovery sentinel parsed by the desktop spawn. `serve` is a
|
||||
# plain backend, not a dashboard, so it announces a neutral token;
|
||||
# `dashboard` keeps the legacy one. The desktop matches either.
|
||||
ready_token = "HERMES_BACKEND_READY" if headless else "HERMES_DASHBOARD_READY"
|
||||
print(f"{ready_token} port={actual_port}", flush=True)
|
||||
if headless:
|
||||
# No SPA, and the JSON-RPC/WS endpoints are auth-gated — don't
|
||||
# advertise a paste-and-connect URL, just announce the bind.
|
||||
print(f" Hermes backend listening on {host}:{actual_port}")
|
||||
else:
|
||||
print(f" Hermes Web UI → http://{host}:{actual_port}")
|
||||
_maybe_open_browser(host, actual_port, open_browser, initial_profile)
|
||||
|
||||
# Collapse the peer-hangup teardown flood (#50005). When the Desktop
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue