The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): salvage #44556 serve dashboard bundle from desktop backend
Josh Tsaie78646a3803d
diff --git a/apps/desktop/electron/dashboard-web-dist.test.ts b/apps/desktop/electron/dashboard-web-dist.test.tsnew file mode 100644index 00000000000..5c0c5c15e56--- /dev/null+++ b/apps/desktop/electron/dashboard-web-dist.test.ts@@ -0,0 +1,92 @@+import assert from 'node:assert/strict'+import fs from 'node:fs'+import os from 'node:os'+import path from 'node:path'++import { test } from 'vitest'++import { resolveDashboardWebDist } from './dashboard-web-dist'++function touchIndex(dir) {+ fs.mkdirSync(dir, { recursive: true })+ fs.writeFileSync(path.join(dir, 'index.html'), '<!doctype html>')+}++function withTempRoot(fn) {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-dashboard-web-dist-'))+ try {+ return fn(root)+ } finally {+ fs.rmSync(root, { recursive: true, force: true })+ }+}++test('desktop-spawned dashboard resolves hermes_cli/web_dist, not Desktop renderer dist', () => {+ withTempRoot(root => {+ const activeHermesRoot = path.join(root, 'hermes-agent')+ const desktopDist = path.join(+ activeHermesRoot,+ 'apps',+ 'desktop',+ 'release',+ 'win-unpacked',+ 'resources',+ 'app.asar.unpacked',+ 'dist'+ )+ const dashboardDist = path.join(activeHermesRoot, 'hermes_cli', 'web_dist')+ touchIndex(desktopDist)+ touchIndex(dashboardDist)+ assert.equal(+ resolveDashboardWebDist({+ activeHermesRoot,+ appRoot: path.join(activeHermesRoot, 'apps', 'desktop'),+ env: {}+ }),+ dashboardDist+ )+ })+})++test('explicit dashboard dist override wins when it exists', () => {+ withTempRoot(root => {+ const override = path.join(root, 'custom-dashboard-dist')+ touchIndex(override)+ assert.equal(+ resolveDashboardWebDist({+ activeHermesRoot: path.join(root, 'hermes-agent'),+ env: { HERMES_DESKTOP_DASHBOARD_WEB_DIST: override }+ }),+ override+ )+ })+})++test('missing dashboard bundle falls back to canonical path for a clear child error', () => {+ withTempRoot(root => {+ const activeHermesRoot = path.join(root, 'hermes-agent')+ assert.equal(+ resolveDashboardWebDist({ activeHermesRoot, env: {} }),+ path.join(activeHermesRoot, 'hermes_cli', 'web_dist')+ )+ })+})++test('appRoot candidate is used when it has a dashboard bundle and activeHermesRoot does not', () => {+ withTempRoot(root => {+ const activeHermesRoot = path.join(root, 'active-install')+ const sourceRoot = path.join(root, 'source-checkout')+ const appRoot = path.join(sourceRoot, 'apps', 'desktop')+ const appRootDashboard = path.resolve(appRoot, '..', '..', 'hermes_cli', 'web_dist')+ fs.mkdirSync(activeHermesRoot, { recursive: true })+ touchIndex(appRootDashboard)+ assert.equal(+ resolveDashboardWebDist({+ activeHermesRoot,+ appRoot,+ env: {}+ }),+ appRootDashboard+ )+ })+})diff --git a/apps/desktop/electron/dashboard-web-dist.ts b/apps/desktop/electron/dashboard-web-dist.tsnew file mode 100644index 00000000000..7576b3fc777--- /dev/null+++ b/apps/desktop/electron/dashboard-web-dist.ts@@ -0,0 +1,66 @@+import fs from 'node:fs'+import path from 'node:path'++function directoryExists(dir) {+ try {+ return fs.statSync(dir).isDirectory()+ } catch {+ return false+ }+}++function hasDashboardBundle(dir) {+ try {+ return fs.statSync(path.join(dir, 'index.html')).isFile()+ } catch {+ return false+ }+}++/**+ * Resolve the web bundle served by `hermes dashboard` / `hermes serve` when it+ * is spawned by Desktop as the local backend.+ *+ * This must be the dashboard bundle (`hermes_cli/web_dist`), not the Electron+ * renderer bundle (`apps/desktop/dist` or the packaged `app.asar.unpacked/dist`).+ * The Electron renderer is loaded by BrowserWindow from file://; the dashboard+ * backend is also reachable in a normal browser, where serving the Desktop+ * renderer produces a broken page (`Desktop IPC bridge is unavailable`).+ */+function resolveDashboardWebDist(options: any = {}) {+ const env = options.env || process.env+ const override = env.HERMES_DESKTOP_DASHBOARD_WEB_DIST+ if (override && directoryExists(path.resolve(override))) {+ return path.resolve(override)+ }++ const candidates = []++ if (options.activeHermesRoot) {+ candidates.push(path.join(options.activeHermesRoot, 'hermes_cli', 'web_dist'))+ }++ if (options.appRoot) {+ // Dev/source layout: <repo>/apps/desktop/electron/main.ts has APP_ROOT at+ // <repo>/apps/desktop. Packaged layout can put APP_ROOT under resources/app.asar;+ // this candidate is harmless there and useful in tests/source checkouts.+ candidates.push(path.resolve(options.appRoot, '..', '..', 'hermes_cli', 'web_dist'))+ }++ for (const candidate of candidates) {+ if (hasDashboardBundle(candidate)) {+ return candidate+ }+ }++ // Fall back to the canonical active install path even if it does not exist so+ // the child `hermes dashboard --skip-build` fails with its explicit missing+ // dist error instead of silently serving the wrong Desktop bundle.+ if (options.activeHermesRoot) {+ return path.join(options.activeHermesRoot, 'hermes_cli', 'web_dist')+ }++ return path.resolve('hermes_cli', 'web_dist')+}++export { resolveDashboardWebDist }diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 30d95a64d76..55da3c1fd14 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -212,6 +212,7 @@ import {isAttachedBackendTokenDrifted,resolveServedDashboardToken} from './dashboard-token'+import { resolveDashboardWebDist } from './dashboard-web-dist'import { resolveDesktopHermesHome, resolveDesktopUserData } from './data-paths'import { loadOrCreateInstallationId, sshOwnershipId } from './desktop-installation'import { formatDesktopLogLine, formatLogStamp } from './desktop-log-line'@@ -12194,7 +12195,11 @@ async function runPoolBackendStart(backend.args = await getBackendArgsForRuntime(backend)assertPoolEntryStillOwned(poolKey, entry, backendPool, localBackendLifecycle.signal)const hermesCwd = resolveHermesCwd()- const webDist = resolveWebDist()+ const webDist = resolveDashboardWebDist({+ activeHermesRoot: ACTIVE_HERMES_ROOT,+ appRoot: APP_ROOT,+ env: process.env+ })const readyFile = backend.readyFile ? makeDashboardReadyFile() : null// Guard BEFORE the "Starting" line: a profile that only exists on a remote@@ -13099,7 +13104,11 @@ async function runHermesStart({ supervisorRecovery = false }: { supervisorRecovebackend.args = await getBackendArgsForRuntime(backend)backendConnectionState.assertCurrentAttempt(connectionAttempt)const hermesCwd = resolveHermesCwd()- const webDist = resolveWebDist()+ const webDist = resolveDashboardWebDist({+ activeHermesRoot: ACTIVE_HERMES_ROOT,+ appRoot: APP_ROOT,+ env: process.env+ })const readyFile = backend.readyFile ? makeDashboardReadyFile() : nullawait advanceBootProgress('backend.spawn', `Starting Hermes backend via ${backend.label}`, 84)