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.
- health-server.js +69 -0
- start.sh +25 -0
|
@@ -803,6 +803,10 @@ async function statusPayload() {
|
|
| 803 |
"auto",
|
| 804 |
backup: sync,
|
| 805 |
keepalive,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 806 |
};
|
| 807 |
_statusCache = payload;
|
| 808 |
_statusCacheAt = now;
|
|
@@ -892,6 +896,16 @@ function renderStatusPage(data) {
|
|
| 892 |
detail: `Provider: ${valueOrUnset(data.provider || "auto")}`,
|
| 893 |
tone: data.model ? "ok" : "warn",
|
| 894 |
}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 895 |
renderTile({
|
| 896 |
title: "Runtime",
|
| 897 |
value: escapeHtml(data.uptime),
|
|
@@ -1117,6 +1131,61 @@ const server = http.createServer(async (req, res) => {
|
|
| 1117 |
return;
|
| 1118 |
}
|
| 1119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1120 |
// /hm/logs β view service logs without needing HF Pro SSH.
|
| 1121 |
if (path === `${HM_PREFIX}/logs` || path.startsWith(`${HM_PREFIX}/logs/`)) {
|
| 1122 |
if (!requireAuth(req, res)) return;
|
|
|
|
| 803 |
"auto",
|
| 804 |
backup: sync,
|
| 805 |
keepalive,
|
| 806 |
+
// Stable dashboard session token for the Hermes desktop app. Persisted
|
| 807 |
+
// by start.sh so it survives restarts β the user configures the desktop
|
| 808 |
+
// app once and it stays connected across Space reboots.
|
| 809 |
+
dashboardSessionToken: process.env.HERMES_DASHBOARD_SESSION_TOKEN || "",
|
| 810 |
};
|
| 811 |
_statusCache = payload;
|
| 812 |
_statusCacheAt = now;
|
|
|
|
| 896 |
detail: `Provider: ${valueOrUnset(data.provider || "auto")}`,
|
| 897 |
tone: data.model ? "ok" : "warn",
|
| 898 |
}),
|
| 899 |
+
renderTile({
|
| 900 |
+
title: "Desktop App",
|
| 901 |
+
value: data.dashboardSessionToken
|
| 902 |
+
? toneBadge("Ready", "ok")
|
| 903 |
+
: toneBadge("No token", "warn"),
|
| 904 |
+
detail: data.dashboardSessionToken
|
| 905 |
+
? `<a href="${HM_PREFIX}/desktop-app-setup">Setup guide</a> Β· token: <code>${escapeHtml(data.dashboardSessionToken.slice(0, 8))}β¦</code>`
|
| 906 |
+
: "HERMES_DASHBOARD_SESSION_TOKEN not set",
|
| 907 |
+
tone: data.dashboardSessionToken ? "ok" : "warn",
|
| 908 |
+
}),
|
| 909 |
renderTile({
|
| 910 |
title: "Runtime",
|
| 911 |
value: escapeHtml(data.uptime),
|
|
|
|
| 1131 |
return;
|
| 1132 |
}
|
| 1133 |
|
| 1134 |
+
// /hm/desktop-app-setup β copy-pasteable desktop app connection info.
|
| 1135 |
+
// Shows the stable session token + remote gateway URL so the user can
|
| 1136 |
+
// configure the Hermes desktop app once and have it survive restarts.
|
| 1137 |
+
if (path === `${HM_PREFIX}/desktop-app-setup`) {
|
| 1138 |
+
if (!requireAuth(req, res)) return;
|
| 1139 |
+
const token = process.env.HERMES_DASHBOARD_SESSION_TOKEN || "";
|
| 1140 |
+
const host = req.headers["x-forwarded-host"] || req.headers.host || "";
|
| 1141 |
+
const baseUrl = host ? `https://${host}` : "";
|
| 1142 |
+
const remoteUrl = `${baseUrl}${HMD_PREFIX}`;
|
| 1143 |
+
if (wantsHtml(req)) {
|
| 1144 |
+
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
| 1145 |
+
res.end(`<!doctype html><html><head><meta charset="utf-8"/><title>Desktop App Setup</title>
|
| 1146 |
+
<style>
|
| 1147 |
+
body{font-family:monospace;background:#0a0a12;color:#e0e0e0;padding:20px;max-width:720px;margin:0 auto}
|
| 1148 |
+
h1{font-size:1.3rem;color:#38bdf8}
|
| 1149 |
+
.box{background:#15151f;border:1px solid #2a2a3a;padding:16px;margin:12px 0;border-radius:8px}
|
| 1150 |
+
.label{color:#94a3b8;font-size:0.85rem;margin-bottom:4px}
|
| 1151 |
+
.value{word-break:break-all;color:#e0e0e0;font-size:0.95rem}
|
| 1152 |
+
.copy{cursor:pointer;background:#1e293b;border:1px solid #334155;color:#38bdf8;padding:4px 12px;border-radius:4px;font-size:0.8rem;margin-top:8px}
|
| 1153 |
+
.copy:hover{background:#334155}
|
| 1154 |
+
.note{color:#94a3b8;font-size:0.85rem;margin-top:16px;line-height:1.5}
|
| 1155 |
+
</style></head><body>
|
| 1156 |
+
<h1>Hermes Desktop App β Remote Setup</h1>
|
| 1157 |
+
<p>Configure once. These values persist across Space restarts (the session token is saved to the backed-up state volume).</p>
|
| 1158 |
+
<div class="box">
|
| 1159 |
+
<div class="label">Remote Gateway URL</div>
|
| 1160 |
+
<div class="value">${escapeHtml(remoteUrl)}</div>
|
| 1161 |
+
</div>
|
| 1162 |
+
<div class="box">
|
| 1163 |
+
<div class="label">Session Token</div>
|
| 1164 |
+
<div class="value">${escapeHtml(token)}</div>
|
| 1165 |
+
</div>
|
| 1166 |
+
<div class="box">
|
| 1167 |
+
<div class="label">Steps</div>
|
| 1168 |
+
<div class="value" style="line-height:1.6">
|
| 1169 |
+
1. Open the Hermes desktop app<br/>
|
| 1170 |
+
2. Settings β Gateway β Remote gateway<br/>
|
| 1171 |
+
3. URL: paste the Remote Gateway URL above<br/>
|
| 1172 |
+
4. Session token: paste the token above<br/>
|
| 1173 |
+
5. Connect β it should stay connected across restarts
|
| 1174 |
+
</div>
|
| 1175 |
+
</div>
|
| 1176 |
+
<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>
|
| 1177 |
+
</body></html>`);
|
| 1178 |
+
} else {
|
| 1179 |
+
res.writeHead(200, { "content-type": "application/json" });
|
| 1180 |
+
res.end(JSON.stringify({
|
| 1181 |
+
remoteGatewayUrl: remoteUrl,
|
| 1182 |
+
sessionToken: token,
|
| 1183 |
+
note: "Configure once in the desktop app: Settings β Gateway β Remote gateway. Persists across restarts.",
|
| 1184 |
+
}, null, 2));
|
| 1185 |
+
}
|
| 1186 |
+
return;
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
// /hm/logs β view service logs without needing HF Pro SSH.
|
| 1190 |
if (path === `${HM_PREFIX}/logs` || path.startsWith(`${HM_PREFIX}/logs/`)) {
|
| 1191 |
if (!requireAuth(req, res)) return;
|
|
@@ -63,6 +63,31 @@ if [ -n "${GATEWAY_TOKEN:-}" ]; then
|
|
| 63 |
export HERMES_WEBUI_PASSWORD="${HERMES_WEBUI_PASSWORD:-$GATEWAY_TOKEN}"
|
| 64 |
fi
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# ββ Setup state dirs ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 67 |
mkdir -p "$HERMES_HOME"/{cron,sessions,logs,hooks,memories,skills,skins,plans,workspace,home,plugins,webui}
|
| 68 |
|
|
|
|
| 63 |
export HERMES_WEBUI_PASSWORD="${HERMES_WEBUI_PASSWORD:-$GATEWAY_TOKEN}"
|
| 64 |
fi
|
| 65 |
|
| 66 |
+
# ββ Stable dashboard session token (desktop app persistence) ββββββββββ
|
| 67 |
+
# Hermes v0.17.0 generates a random session token per dashboard process
|
| 68 |
+
# start (hermes_cli/web_server.py:216):
|
| 69 |
+
# _SESSION_TOKEN = os.environ.get("HERMES_DASHBOARD_SESSION_TOKEN") or secrets.token_urlsafe(32)
|
| 70 |
+
# The desktop app connects via /hmd using this token. Without a stable
|
| 71 |
+
# value, the token changes on every Space restart β the user must re-scrape
|
| 72 |
+
# it from /hmd/ HTML and reconfigure the desktop app each time.
|
| 73 |
+
#
|
| 74 |
+
# If HERMES_DASHBOARD_SESSION_TOKEN is set as an HF Space Secret, use it
|
| 75 |
+
# (power users can pin an explicit value). Otherwise generate once and
|
| 76 |
+
# persist to the backed-up HERMES_HOME so it survives restarts.
|
| 77 |
+
DASHBOARD_TOKEN_FILE="$HERMES_HOME/.huggingmes-dashboard-session-token"
|
| 78 |
+
if [ -z "${HERMES_DASHBOARD_SESSION_TOKEN:-}" ]; then
|
| 79 |
+
if [ -f "$DASHBOARD_TOKEN_FILE" ]; then
|
| 80 |
+
export HERMES_DASHBOARD_SESSION_TOKEN="$(cat "$DASHBOARD_TOKEN_FILE" 2>/dev/null)"
|
| 81 |
+
else
|
| 82 |
+
HERMES_DASHBOARD_SESSION_TOKEN="$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')"
|
| 83 |
+
export HERMES_DASHBOARD_SESSION_TOKEN
|
| 84 |
+
# HERMES_HOME may not exist yet on first boot β mkdir covers that.
|
| 85 |
+
mkdir -p "$HERMES_HOME"
|
| 86 |
+
printf '%s' "$HERMES_DASHBOARD_SESSION_TOKEN" > "$DASHBOARD_TOKEN_FILE"
|
| 87 |
+
chmod 600 "$DASHBOARD_TOKEN_FILE" 2>/dev/null || true
|
| 88 |
+
fi
|
| 89 |
+
fi
|
| 90 |
+
|
| 91 |
# ββ Setup state dirs ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 92 |
mkdir -p "$HERMES_HOME"/{cron,sessions,logs,hooks,memories,skills,skins,plans,workspace,home,plugins,webui}
|
| 93 |
|