Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review: Windows atomicWrite fallback, http scheme for non-TLS, avatar HEAD TOCTOU, Windows tailscale.exe, conditional api-local port
Adam Eivy72a9a2ac801c
diff --git a/client/src/services/appUrls.js b/client/src/services/appUrls.jsindex ab5cd96beb..4609380ee2 100644--- a/client/src/services/appUrls.js+++ b/client/src/services/appUrls.js@@ -13,8 +13,10 @@ export function getLaunchUrls(app) {if (!app) return { https: null, http: null, dev: null };if (app.uiUrl) return { https: null, http: app.uiUrl, dev: null };const hostname = window.location.hostname;- const protocol = window.location.protocol;- const dev = app.devUiPort ? `${protocol}//${hostname}:${app.devUiPort}` : null;+ // Non-TLS launch URLs always use http:// regardless of how PortOS itself is served —+ // inheriting window.location.protocol produced https:// links to plain-HTTP app ports+ // (e.g., uiPort, devUiPort) whenever PortOS was served over HTTPS, which doesn't work.+ const dev = app.devUiPort ? `http://${hostname}:${app.devUiPort}` : null;// Self-app: primary URL is the active origin (right scheme + port); dev still// reflects the Vite dev server on a separate port.if (app.id === PORTOS_APP_ID) {@@ -22,7 +24,7 @@ export function getLaunchUrls(app) {}return {https: app.tlsPort ? `https://${hostname}:${app.tlsPort}` : null,- http: app.uiPort ? `${protocol}//${hostname}:${app.uiPort}` : null,+ http: app.uiPort ? `http://${hostname}:${app.uiPort}` : null,dev};}diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.jsindex 3d1b2d1338..abcd736058 100644--- a/server/lib/fileUtils.js+++ b/server/lib/fileUtils.js@@ -4,7 +4,7 @@* Shared utilities for file operations used across services.*/-import { mkdir, readFile, writeFile, rename } from 'fs/promises';+import { mkdir, readFile, writeFile, rename, unlink } from 'fs/promises';import { existsSync } from 'fs';import { join, dirname } from 'path';import { fileURLToPath } from 'url';@@ -107,7 +107,20 @@ export async function atomicWrite(filePath, data) {const payload = typeof data === 'string' ? data : JSON.stringify(data, null, 2);const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;await writeFile(tmp, payload);- await rename(tmp, filePath);+ // Node's fs.rename uses MoveFileExW with MOVEFILE_REPLACE_EXISTING on Windows (atomic+ // overwrite), but will still fail with EPERM/EACCES if the destination is locked. Fall+ // back to unlink + rename so writes succeed on Windows in those edge cases too.+ const replace = async () => {+ const err = await rename(tmp, filePath).then(() => null, (e) => e);+ if (!err) return;+ if (process.platform === 'win32' && ['EPERM', 'EACCES', 'EEXIST'].includes(err.code)) {+ await unlink(filePath).catch(() => {});+ await rename(tmp, filePath);+ return;+ }+ throw err;+ };+ await replace();}/**diff --git a/server/lib/tailscale.js b/server/lib/tailscale.jsindex 3a34d6476e..fd53c4c74b 100644--- a/server/lib/tailscale.js+++ b/server/lib/tailscale.js@@ -1,15 +1,24 @@import { existsSync } from 'fs';import { join, delimiter } from 'path';+const IS_WIN = process.platform === 'win32';+const TAILSCALE_BIN = IS_WIN ? 'tailscale.exe' : 'tailscale';+// Paths where the Tailscale CLI binary is commonly found. On macOS the GUI app// doesn't put the CLI in PATH by default; Homebrew installs to /usr/local/bin-// (Intel) or /opt/homebrew/bin (Apple Silicon); Linux packages land in /usr/bin.-const TAILSCALE_CANDIDATES = [- '/Applications/Tailscale.app/Contents/MacOS/Tailscale',- '/usr/local/bin/tailscale',- '/opt/homebrew/bin/tailscale',- '/usr/bin/tailscale'-];+// (Intel) or /opt/homebrew/bin (Apple Silicon); Linux packages land in /usr/bin;+// Windows installs land in Program Files.+const TAILSCALE_CANDIDATES = IS_WIN+ ? [+ 'C:\\Program Files\\Tailscale\\tailscale.exe',+ 'C:\\Program Files (x86)\\Tailscale\\tailscale.exe'+ ]+ : [+ '/Applications/Tailscale.app/Contents/MacOS/Tailscale',+ '/usr/local/bin/tailscale',+ '/opt/homebrew/bin/tailscale',+ '/usr/bin/tailscale'+ ];export function findTailscale() {for (const p of TAILSCALE_CANDIDATES) {@@ -18,7 +27,7 @@ export function findTailscale() {// Use path.delimiter (';' on Windows, ':' elsewhere) so PATH scanning works cross-platform.for (const dir of (process.env.PATH || '').split(delimiter)) {if (!dir) continue;- const p = join(dir, 'tailscale');+ const p = join(dir, TAILSCALE_BIN);if (existsSync(p)) return p;}return null;diff --git a/server/routes/avatar.js b/server/routes/avatar.jsindex 971b80bd61..80b07eae0a 100644--- a/server/routes/avatar.js+++ b/server/routes/avatar.js@@ -6,11 +6,22 @@ import { PATHS } from '../lib/fileUtils.js';const router = Router();const AVATAR_PATH = join(PATHS.data, 'avatar', 'model.glb');+// Non-throwing stat wrapper used by the HEAD handler — file may be removed between+// existsSync() and statSync() (TOCTOU), which would otherwise crash the process.+function safeStat(p) {+ try {+ return statSync(p);+ } catch {+ return null;+ }+}+router.head('/model.glb', (req, res) => {if (!existsSync(AVATAR_PATH)) {return res.status(404).end();}- const s = statSync(AVATAR_PATH);+ const s = safeStat(AVATAR_PATH);+ if (!s) return res.status(404).end();res.set('Content-Type', 'model/gltf-binary');res.set('Content-Length', String(s.size));res.set('Cache-Control', 'public, max-age=60');diff --git a/server/services/apps.js b/server/services/apps.jsindex 45e43eeac0..9b171e3762 100644--- a/server/services/apps.js+++ b/server/services/apps.js@@ -42,9 +42,10 @@ function buildPortosApp() {'portos-browser'],processes: [- // portos-server binds a loopback HTTP mirror on API_LOCAL when HTTPS is active on API,- // so Overview shows both ports for this process.- { name: 'portos-server', port: PORTS.API, ports: { api: PORTS.API, 'api-local': PORTS.API_LOCAL } },+ // portos-server binds a loopback HTTP mirror on API_LOCAL only when HTTPS is active+ // on API. If no cert is present, don't advertise api-local — nothing is listening+ // there and Overview would otherwise show a dead port.+ { name: 'portos-server', port: PORTS.API, ports: certPresent ? { api: PORTS.API, 'api-local': PORTS.API_LOCAL } : { api: PORTS.API } },{ name: 'portos-cos', port: 5558, ports: { api: 5558 } },{ name: 'portos-ui', port: PORTS.UI, ports: { devUi: PORTS.UI } },{ name: 'portos-autofixer', port: 5559, ports: { api: 5559 } },