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: validate SD URL protocol, normalize savedUrl, fail-closed dirty check, guarantee terminal events
Adam Eivy69340911136b
diff --git a/client/src/pages/Settings.jsx b/client/src/pages/Settings.jsxindex 8e3702a4dd..84a74565fc 100644--- a/client/src/pages/Settings.jsx+++ b/client/src/pages/Settings.jsx@@ -883,9 +883,10 @@ function ImageGenTab() {useEffect(() => {Promise.all([getSettings(), getToolsList()]).then(([settings, tools]) => {- const url = settings?.imageGen?.sdapiUrl || '';- setSdapiUrl(url);- setSavedUrl(url);+ const rawUrl = settings?.imageGen?.sdapiUrl || '';+ const normalizedUrl = rawUrl.trim().replace(/\/+$/, '');+ setSdapiUrl(normalizedUrl);+ setSavedUrl(normalizedUrl);setToolRegistered(tools.some(t => t.id === SDAPI_TOOL_ID));}).catch(() => toast.error('Failed to load image gen settings'))diff --git a/server/services/imageGen.js b/server/services/imageGen.jsindex bbffda2956..931eecb693 100644--- a/server/services/imageGen.js+++ b/server/services/imageGen.js@@ -40,8 +40,11 @@ async function detectModel(baseUrl) {}export async function checkConnection() {- const baseUrl = await getSdApiUrl();- if (!baseUrl) return { connected: false, reason: 'No SD API URL configured' };+ const rawUrl = await getSdApiUrl();+ if (!rawUrl) return { connected: false, reason: 'No SD API URL configured' };++ let baseUrl;+ try { baseUrl = validateSdUrl(rawUrl); } catch (err) { return { connected: false, reason: err.message }; }// Always make a live request for status checks — bypass the model cacheconst res = await fetchWithTimeout(`${baseUrl}/sdapi/v1/options`, {}, 10000).catch(() => null);@@ -94,9 +97,18 @@ function startProgressPolling(baseUrl, generationId) {return () => clearInterval(interval);}+function validateSdUrl(rawUrl) {+ if (!rawUrl) throw new Error('No SD API URL configured — set it in Settings > Image Gen');+ let url;+ try { url = new URL(rawUrl); } catch { throw new Error('Invalid SD API URL — must be a valid http/https URL'); }+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {+ throw new Error('Invalid SD API URL — only http and https are allowed');+ }+ return url.origin;+}+export async function generateImage({ prompt, negativePrompt, width, height, steps, cfgScale, seed }) {- const baseUrl = await getSdApiUrl();- if (!baseUrl) throw new Error('No SD API URL configured — set it in Settings > Image Gen');+ const baseUrl = validateSdUrl(await getSdApiUrl());const model = await detectModel(baseUrl);const isFlux = model?.toLowerCase().includes('flux');@@ -143,27 +155,35 @@ export async function generateImage({ prompt, negativePrompt, width, height, ste}stopPolling();- if (!res.ok) {- const errBody = await res.text().catch(() => '');- imageGenEvents.emit('failed', { generationId, error: `SD API error ${res.status}` });- throw new Error(`SD API error ${res.status}: ${errBody.slice(0, 200)}`);- }+ try {+ if (!res.ok) {+ const errBody = await res.text().catch(() => '');+ imageGenEvents.emit('failed', { generationId, error: `SD API error ${res.status}` });+ throw new Error(`SD API error ${res.status}: ${errBody.slice(0, 200)}`);+ }- const data = await res.json();- if (!data.images?.length) {- imageGenEvents.emit('failed', { generationId, error: 'No images returned' });- throw new Error('SD API returned no images');- }+ const data = await res.json();+ if (!data.images?.length) {+ imageGenEvents.emit('failed', { generationId, error: 'No images returned' });+ throw new Error('SD API returned no images');+ }- await ensureDir(PATHS.images);- const filename = `${randomUUID()}.png`;- await writeFile(join(PATHS.images, filename), Buffer.from(data.images[0], 'base64'));+ await ensureDir(PATHS.images);+ const filename = `${randomUUID()}.png`;+ await writeFile(join(PATHS.images, filename), Buffer.from(data.images[0], 'base64'));- const path = `/data/images/${filename}`;- console.log(`🖼️ Image saved: ${filename}`);+ const path = `/data/images/${filename}`;+ console.log(`🖼️ Image saved: ${filename}`);- imageGenEvents.emit('completed', { generationId, path, filename });- return { generationId, filename, path };+ imageGenEvents.emit('completed', { generationId, path, filename });+ return { generationId, filename, path };+ } catch (err) {+ // Guarantee a terminal event for every generationId+ if (!err.message?.startsWith('SD API error') && err.message !== 'SD API returned no images') {+ imageGenEvents.emit('failed', { generationId, error: err.message || 'Image generation failed' });+ }+ throw err;+ }}export async function generateAvatar({ name, characterClass, prompt }) {diff --git a/server/services/worktreeManager.js b/server/services/worktreeManager.jsindex fa917d3c51..d23cb163af 100644--- a/server/services/worktreeManager.js+++ b/server/services/worktreeManager.js@@ -113,10 +113,14 @@ export async function removeWorktree(agentId, sourceWorkspace, branchName, optio}// Safety check: abort removal when uncommitted changes are detected.- // Auto-committing dirty state is unreliable — if merge is false the commit- // would be dangling (branch gets deleted), and if merge is true it could- // merge partial/WIP changes. Preserve the worktree so the caller can handle.- const dirtyFiles = (await execGit(['status', '--porcelain'], worktreePath).catch(() => '')).trim();+ // Also fail closed if git status itself fails — treat unknown state as dirty.+ let dirtyFiles;+ try {+ dirtyFiles = (await execGit(['status', '--porcelain'], worktreePath)).trim();+ } catch (err) {+ console.log(`⚠️ git status failed for worktree ${agentId}, preserving to avoid data loss: ${err.message}`);+ return { merged: false, removed: false, uncommittedSaved: false };+ }if (dirtyFiles) {console.log(`⚠️ Preserving worktree for ${agentId} — uncommitted changes detected, aborting cleanup to avoid data loss`);return { merged: false, removed: false, uncommittedSaved: false };