feat: stable dashboard session token for desktop app persistence
Browse filesThe Hermes desktop app connects via /hmd using the dashboard's session
token. Hermes v0.17.0 generates a random token per process start
(web_server.py:216):
_SESSION_TOKEN = os.environ.get('HERMES_DASHBOARD_SESSION_TOKEN') or secrets.token_urlsafe(32)
Without a stable value, the token changed on every Space restart, forcing
the user to re-scrape it from /hmd/ HTML and reconfigure the desktop app
each time.
start.sh:
- If HERMES_DASHBOARD_SESSION_TOKEN is set as an HF Space Secret, use it
(power users can pin an explicit value).
- Otherwise generate once and persist to
$HERMES_HOME/.huggingmes-dashboard-session-token (backed up to the HF
Dataset via hermes-sync.py β it's not in EXCLUDED_TOP_LEVEL).
- On every boot, read the saved token and export it. The dashboard then
uses this stable value instead of generating a fresh random one.
health-server.js:
- Add dashboardSessionToken to the statusPayload (auth-gated via
/hm/status) so the token is visible without scraping HTML.
- Add /hm/desktop-app-setup endpoint: a copy-pasteable HTML page showing
the Remote Gateway URL + session token + setup steps. Also available
as JSON for programmatic access.
- Add a 'Desktop App' tile to the /hm status page showing token status
+ a link to the setup guide.
The user configures the desktop app ONCE; the token persists across
restarts via the HF Dataset backup. The handover doc's env var name
(HERMES_DASHBOARD_BASIC_AUTH_SECRET) was wrong β the actual v0.17.0 var
is HERMES_DASHBOARD_SESSION_TOKEN, verified in the upstream source.
Files changed (2)
- health-server.js+69
- start.sh+25
802 unmodified lines80380480580680780883 unmodified lines892893894895896897219 unmodified lines111711181119112011211122802 unmodified lines"auto",backup: sync,keepalive,};_statusCache = payload;_statusCacheAt = now;83 unmodified linesdetail: `Provider: ${valueOrUnset(data.provider || "auto")}`,tone: data.model ? "ok" : "warn",}),renderTile({title: "Runtime",value: escapeHtml(data.uptime),219 unmodified linesreturn;}// /hm/logs β view service logs without needing HF Pro SSH.if (path === `${HM_PREFIX}/logs` || path.startsWith(`${HM_PREFIX}/logs/`)) {if (!requireAuth(req, res)) return;802 unmodified lines80380480580680780880981081181283 unmodified lines896897898899900901902903904905906907908909910911219 unmodified lines1131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191802 unmodified lines"auto",backup: sync,keepalive,// Stable dashboard session token for the Hermes desktop app. Persisted// by start.sh so it survives restarts β the user configures the desktop// app once and it stays connected across Space reboots.dashboardSessionToken: process.env.HERMES_DASHBOARD_SESSION_TOKEN || "",};_statusCache = payload;_statusCacheAt = now;83 unmodified linesdetail: `Provider: ${valueOrUnset(data.provider || "auto")}`,tone: data.model ? "ok" : "warn",}),renderTile({title: "Desktop App",value: data.dashboardSessionToken? toneBadge("Ready", "ok"): toneBadge("No token", "warn"),detail: data.dashboardSessionToken? `<a href="${HM_PREFIX}/desktop-app-setup">Setup guide</a> Β· token: <code>${escapeHtml(data.dashboardSessionToken.slice(0, 8))}β¦</code>`: "HERMES_DASHBOARD_SESSION_TOKEN not set",tone: data.dashboardSessionToken ? "ok" : "warn",}),renderTile({title: "Runtime",value: escapeHtml(data.uptime),219 unmodified linesreturn;}// /hm/desktop-app-setup β copy-pasteable desktop app connection info.// Shows the stable session token + remote gateway URL so the user can// configure the Hermes desktop app once and have it survive restarts.if (path === `${HM_PREFIX}/desktop-app-setup`) {if (!requireAuth(req, res)) return;const token = process.env.HERMES_DASHBOARD_SESSION_TOKEN || "";const host = req.headers["x-forwarded-host"] || req.headers.host || "";const baseUrl = host ? `https://${host}` : "";const remoteUrl = `${baseUrl}${HMD_PREFIX}`;if (wantsHtml(req)) {res.writeHead(200, { "content-type": "text/html; charset=utf-8" });res.end(`<!doctype html><html><head><meta charset="utf-8"/><title>Desktop App Setup</title><style>body{font-family:monospace;background:#0a0a12;color:#e0e0e0;padding:20px;max-width:720px;margin:0 auto}h1{font-size:1.3rem;color:#38bdf8}.box{background:#15151f;border:1px solid #2a2a3a;padding:16px;margin:12px 0;border-radius:8px}.label{color:#94a3b8;font-size:0.85rem;margin-bottom:4px}.value{word-break:break-all;color:#e0e0e0;font-size:0.95rem}.copy{cursor:pointer;background:#1e293b;border:1px solid #334155;color:#38bdf8;padding:4px 12px;border-radius:4px;font-size:0.8rem;margin-top:8px}.copy:hover{background:#334155}.note{color:#94a3b8;font-size:0.85rem;margin-top:16px;line-height:1.5}</style></head><body><h1>Hermes Desktop App β Remote Setup</h1><p>Configure once. These values persist across Space restarts (the session token is saved to the backed-up state volume).</p><div class="box"><div class="label">Remote Gateway URL</div><div class="value">${escapeHtml(remoteUrl)}</div></div><div class="box"><div class="label">Session Token</div><div class="value">${escapeHtml(token)}</div></div><div class="box"><div class="label">Steps</div><div class="value" style="line-height:1.6">1. Open the Hermes desktop app<br/>2. Settings β Gateway β Remote gateway<br/>3. URL: paste the Remote Gateway URL above<br/>4. Session token: paste the token above<br/>5. Connect β it should stay connected across restarts</div></div><p class="note">In the desktop app: chat, model picker, and settings work remotely. File browser and terminal panel show your local PC (upstream desktop app limitation). For remote files/terminal, use the WebUI at <a href="/" style="color:#38bdf8">/</a>.</p></body></html>`);} else {res.writeHead(200, { "content-type": "application/json" });res.end(JSON.stringify({remoteGatewayUrl: remoteUrl,sessionToken: token,note: "Configure once in the desktop app: Settings β Gateway β Remote gateway. Persists across restarts.",}, null, 2));}return;}// /hm/logs β view service logs without needing HF Pro SSH.if (path === `${HM_PREFIX}/logs` || path.startsWith(`${HM_PREFIX}/logs/`)) {if (!requireAuth(req, res)) return;
62 unmodified lines63646566676862 unmodified linesexport HERMES_WEBUI_PASSWORD="${HERMES_WEBUI_PASSWORD:-$GATEWAY_TOKEN}"fi# ββ Setup state dirs ββββββββββββββββββββββββββββββββββββββββββββββββββmkdir -p "$HERMES_HOME"/{cron,sessions,logs,hooks,memories,skills,skins,plans,workspace,home,plugins,webui}62 unmodified lines6364656667686970717273747576777879808182838485868788899091929362 unmodified linesexport HERMES_WEBUI_PASSWORD="${HERMES_WEBUI_PASSWORD:-$GATEWAY_TOKEN}"fi# ββ Stable dashboard session token (desktop app persistence) ββββββββββ# Hermes v0.17.0 generates a random session token per dashboard process# start (hermes_cli/web_server.py:216):# _SESSION_TOKEN = os.environ.get("HERMES_DASHBOARD_SESSION_TOKEN") or secrets.token_urlsafe(32)# The desktop app connects via /hmd using this token. Without a stable# value, the token changes on every Space restart β the user must re-scrape# it from /hmd/ HTML and reconfigure the desktop app each time.## If HERMES_DASHBOARD_SESSION_TOKEN is set as an HF Space Secret, use it# (power users can pin an explicit value). Otherwise generate once and# persist to the backed-up HERMES_HOME so it survives restarts.DASHBOARD_TOKEN_FILE="$HERMES_HOME/.huggingmes-dashboard-session-token"if [ -z "${HERMES_DASHBOARD_SESSION_TOKEN:-}" ]; thenif [ -f "$DASHBOARD_TOKEN_FILE" ]; thenexport HERMES_DASHBOARD_SESSION_TOKEN="$(cat "$DASHBOARD_TOKEN_FILE" 2>/dev/null)"elseHERMES_DASHBOARD_SESSION_TOKEN="$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')"export HERMES_DASHBOARD_SESSION_TOKEN# HERMES_HOME may not exist yet on first boot β mkdir covers that.mkdir -p "$HERMES_HOME"printf '%s' "$HERMES_DASHBOARD_SESSION_TOKEN" > "$DASHBOARD_TOKEN_FILE"chmod 600 "$DASHBOARD_TOKEN_FILE" 2>/dev/null || truefifi# ββ Setup state dirs ββββββββββββββββββββββββββββββββββββββββββββββββββmkdir -p "$HERMES_HOME"/{cron,sessions,logs,hooks,memories,skills,skins,plans,workspace,home,plugins,webui}