Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(web): apply the Windows standalone check to every asset resolver
Salman Qureshi4e1c022d7a6a
diff --git a/.lint-baseline.json b/.lint-baseline.jsonindex 7a300fbb..99f40143 100644--- a/.lint-baseline.json+++ b/.lint-baseline.json@@ -1,11 +1,11 @@{"$comment": "ESLint ratchet baseline. Per-rule counts (errors + warnings) may only go down. Refresh with `npm run lint:ratchet -- --update` after a clean-up.","provisional": false,- "generatedAt": "2026-10-11T07:49:39.756Z",+ "generatedAt": "2026-10-15T16:08:14.521Z","target": "src","rules": {"(unknown)": 1,- "@typescript-eslint/no-explicit-any": 1136,+ "@typescript-eslint/no-explicit-any": 1133,"@typescript-eslint/no-require-imports": 6,"@typescript-eslint/no-this-alias": 5,"@typescript-eslint/no-unused-expressions": 100,diff --git a/CHANGELOG.md b/CHANGELOG.mdindex def6c055..4d54b0d8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,9 @@# Changelog+## Unreleased++- **The web dashboard works on the Windows standalone binary.** Mercury looked for its `web/` folder inside the binary's virtual filesystem, because it only recognised Bun's macOS/Linux marker (`$bunfs`) and not Windows' (`~BUN`), so the dashboard reported "web UI not found". Found and fixed by @farena-ai in #189; the same check is now shared by the login page and the memory-graph fallback.+## 1.3.9 — hotfix: `mercury doctor` and dashboard saves take effect- **`mercury doctor` applies what you changed.** Providers, keys and channels are read at boot, so a reconfigure that only wrote the file looked like it did nothing until a manual `mercury restart`. Doctor now restarts the running daemon when the configuration actually changed (the Telegram/Discord commands already did this).diff --git a/src/utils/bun-path.test.ts b/src/utils/bun-path.test.tsnew file mode 100644index 00000000..1f75c3a5--- /dev/null+++ b/src/utils/bun-path.test.ts@@ -0,0 +1,31 @@+import { afterEach, describe, expect, it } from 'vitest';+import { isBunVirtualPath } from './bun-path.js';++const versions = process.versions as { bun?: string };+const original = versions.bun;++afterEach(() => {+ if (original === undefined) delete versions.bun;+ else versions.bun = original;+});++describe('isBunVirtualPath (standalone binary asset resolution, #189)', () => {+ it('recognises the POSIX and Windows virtual roots under Bun', () => {+ versions.bun = '1.3.14';+ expect(isBunVirtualPath('/$bunfs/root/web')).toBe(true);+ expect(isBunVirtualPath('B:\\~BUN\\root')).toBe(true);+ expect(isBunVirtualPath('B:/~BUN/root/dist')).toBe(true);+ });++ it('ignores ordinary paths, including folders merely named like the marker', () => {+ versions.bun = '1.3.14';+ expect(isBunVirtualPath('/Users/me/mercury/dist')).toBe(false);+ expect(isBunVirtualPath('C:\\Users\\me\\~BUNDLE\\dist')).toBe(false);+ });++ it('is false outside Bun (npm installs run on Node)', () => {+ delete versions.bun;+ expect(isBunVirtualPath('B:\\~BUN\\root')).toBe(false);+ expect(isBunVirtualPath('/$bunfs/root')).toBe(false);+ });+});diff --git a/src/utils/bun-path.ts b/src/utils/bun-path.tsnew file mode 100644index 00000000..a7338e8a--- /dev/null+++ b/src/utils/bun-path.ts@@ -0,0 +1,13 @@+/**+ * True when `dir` is inside Bun's virtual filesystem, i.e. Mercury runs as+ * a `bun build --compile` standalone binary and files shipped next to the+ * executable (web/, the brain fallback assets) must be resolved from+ * `process.execPath`, not `__dirname`.+ *+ * The virtual root differs by OS: `/$bunfs/root` on macOS and Linux,+ * `B:\~BUN\root` (or `B:/~BUN/root`) on Windows.+ */+export function isBunVirtualPath(dir: string): boolean {+ if (typeof (process.versions as { bun?: string }).bun !== 'string') return false;+ return dir.includes('$bunfs') || /[\\/]~BUN[\\/]/.test(dir);+}diff --git a/src/web/api/auth.ts b/src/web/api/auth.tsindex 78a755c6..957c19ed 100644--- a/src/web/api/auth.ts+++ b/src/web/api/auth.ts@@ -1,4 +1,5 @@import { Hono } from 'hono';+import { isBunVirtualPath } from '../../utils/bun-path.js';import { setCookie, getCookie, deleteCookie } from 'hono/cookie';import { existsSync, readFileSync } from 'fs';import { join, dirname } from 'path';@@ -8,7 +9,8 @@ import { authenticate, createSession, destroySession, changePassword, changeUserfunction resolveWebDir(...segments: string[]): string {const __dirname = dirname(fileURLToPath(import.meta.url));- if (typeof (process.versions as any).bun === 'string' && __dirname.includes('$bunfs')) {+ // Standalone binary (macOS/Linux `$bunfs`, Windows `~BUN`): assets sit next to the executable.+ if (isBunVirtualPath(__dirname)) {return join(dirname(process.execPath), ...segments);}return join(__dirname, ...segments);diff --git a/src/web/api/brain-fallback.ts b/src/web/api/brain-fallback.tsindex 7972545a..92dad81a 100644--- a/src/web/api/brain-fallback.ts+++ b/src/web/api/brain-fallback.ts@@ -1,4 +1,5 @@import { readFileSync, existsSync } from 'node:fs';+import { isBunVirtualPath } from '../../utils/bun-path.js';import { join, dirname } from 'node:path';import { fileURLToPath } from 'node:url';import process from 'node:process';@@ -7,8 +8,8 @@ import { getMemoryDir } from '../../utils/config.js';function resolveAssetPath(...segments: string[]): string {const __dirname = dirname(fileURLToPath(import.meta.url));// When running as a Bun --compile standalone binary, __dirname points to- // Bun's virtual filesystem ($bunfs). Resolve assets relative to the binary.- if (typeof (process.versions as any).bun === 'string' && __dirname.includes('$bunfs')) {+ // Bun's virtual filesystem (`$bunfs`, or `~BUN` on Windows). Resolve assets relative to the binary.+ if (isBunVirtualPath(__dirname)) {return join(dirname(process.execPath), ...segments);}return join(__dirname, ...segments);diff --git a/src/web/server.ts b/src/web/server.tsindex 0ba5ae02..0a40892e 100644--- a/src/web/server.ts+++ b/src/web/server.ts@@ -1,4 +1,5 @@import { Hono } from 'hono';+import { isBunVirtualPath } from '../utils/bun-path.js';import { createAdaptorServer } from '@hono/node-server';import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';import { join, dirname, extname } from 'node:path';@@ -37,7 +38,7 @@ function resolveWebDir(subpath: string): string {// Bun's virtual filesystem ($bunfs). The web assets are shipped alongside// the binary in a `web/` directory, so resolve relative to the binary itself.// On Windows the virtual root is `B:\~BUN\root` rather than `$bunfs`.- if (typeof (process.versions as any).bun === 'string' && (__dirname.includes('$bunfs') || __dirname.includes('~BUN'))) {+ if (isBunVirtualPath(__dirname)) {return join(dirname(process.execPath), 'web', subpath);}