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: 5 Copilot findings on PR #181
Adam Eivyf51179f5eb7b
diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsxindex 8a73732a4b..6b8c75e80e 100644--- a/client/src/components/settings/ImageGenTab.jsx+++ b/client/src/components/settings/ImageGenTab.jsx@@ -350,10 +350,17 @@ export function ImageGenTab() {onChange={(e) => {const v = e.target.checked;setCodexEnabled(v);- // If the user just disabled Codex while it was the active- // backend, fall back to external so saving doesn't leave the- // dispatcher pointing at a disabled provider.- if (!v && mode === 'codex') setMode('external');+ // Disabling Codex while it's the active backend would leave+ // the saved mode pointing at a disabled provider. Pick the+ // best fallback: prefer local if Python is configured, else+ // external if a URL is set, else external as a last resort+ // (so the user lands on a non-broken default rather than+ // sticking with codex or hopping to an unconfigured backend).+ if (!v && mode === 'codex') {+ const hasLocal = !!pythonPath?.trim();+ const hasExternal = !!normalizeUrl(sdapiUrl);+ setMode(hasLocal ? 'local' : (hasExternal ? 'external' : 'external'));+ }}}className="rounded"/>diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsxindex fed399b8e1..dd4e4313da 100644--- a/client/src/pages/ImageGen.jsx+++ b/client/src/pages/ImageGen.jsx@@ -94,9 +94,12 @@ export default function ImageGen() {const progress = externalProgress || localProgress;const progressPct = progress?.progress != null ? Math.round(progress.progress * 100) : null;- const refreshStatus = useCallback(() => {+ // Status reflects the currently-selected backend, not the saved default —+ // chip changes re-probe via the optional ?mode= override so the badge and+ // notConnected gating stay aligned with what Generate would actually use.+ const refreshStatus = useCallback((mode) => {setStatusLoading(true);- getImageGenStatus()+ getImageGenStatus(mode).then(setStatus).catch(() => setStatus({ connected: false, reason: 'Status check failed' })).finally(() => setStatusLoading(false));@@ -106,15 +109,11 @@ export default function ImageGen() {listImageGallery().then(setGallery).catch(() => {});}, []);- useEffect(() => {- refreshStatus();- listImageModels().then((m) => {- setModels(m);- if (m.length && !modelId) setModelId(m[0].id);- }).catch(() => {});- listLoras().then(setAvailableLoras).catch(() => {});- refreshGallery();- getSettings().then((s) => {+ // Settings load — derives the chip strip and the initial selectedMode.+ // Re-runnable so the Settings drawer can trigger a refresh on close+ // without forcing a full page reload.+ const reloadBackends = useCallback(() => {+ return getSettings().then((s) => {const ig = s?.imageGen || {};const externalUrl = (ig.external?.sdapiUrl || ig.sdapiUrl || '').trim();const pyPath = (ig.local?.pythonPath || '').trim();@@ -125,16 +124,27 @@ export default function ImageGen() {if (codexOn) backends.push({ id: 'codex', label: 'Codex', icon: Terminal });setAvailableBackends(backends);const saved = ig.mode || 'external';- // Pick the saved mode if viable; otherwise the first viable backend- // (so a freshly-configured setup with only one provider Just Works).- if (backends.find((b) => b.id === saved)) {- setSelectedMode(saved);- } else if (backends.length) {- setSelectedMode(backends[0].id);- } else {- setSelectedMode(saved);- }+ // Prefer the saved default if viable. If the user just disabled the+ // currently-selected backend, fall through to the first viable one+ // (so a freshly-configured setup or a just-toggled provider Just+ // Works without forcing a reload).+ setSelectedMode((prev) => {+ if (prev && backends.find((b) => b.id === prev)) return prev;+ if (backends.find((b) => b.id === saved)) return saved;+ if (backends.length) return backends[0].id;+ return saved;+ });+ }).catch(() => {});+ }, []);++ useEffect(() => {+ listImageModels().then((m) => {+ setModels(m);+ if (m.length && !modelId) setModelId(m[0].id);}).catch(() => {});+ listLoras().then(setAvailableLoras).catch(() => {});+ refreshGallery();+ reloadBackends();// Resume an in-flight job so the user can navigate away mid-render and// come back to the same prompt + settings + live preview frame.getActiveImageJob().then(({ activeJob }) => {@@ -169,6 +179,25 @@ export default function ImageGen() {// eslint-disable-next-line react-hooks/exhaustive-deps}, []);+ // Re-probe status whenever the effective backend changes — flipping the+ // chip from Local to Codex shouldn't leave the badge / notConnected+ // gating reflecting the previous backend.+ useEffect(() => {+ if (!effectiveMode) return;+ refreshStatus(effectiveMode);+ }, [effectiveMode, refreshStatus]);++ // When the user closes the Settings drawer, settings may have changed+ // (e.g. they enabled Codex or configured a new external URL). Reload so+ // the chip strip matches the new state without a page refresh.+ const wasSettingsOpenRef = useRef(false);+ useEffect(() => {+ if (wasSettingsOpenRef.current && !settingsOpen) {+ reloadBackends();+ }+ wasSettingsOpenRef.current = settingsOpen;+ }, [settingsOpen, reloadBackends]);+const currentModel = models.find((m) => m.id === modelId);const matchedResolution = RESOLUTIONS.find((r) => r.w === width && r.h === height);const resolutionLabel = matchedResolution?.label || `${width}×${height}`;@@ -377,7 +406,7 @@ export default function ImageGen() {</div><div className="flex items-center gap-1"><button- onClick={refreshStatus}+ onClick={() => refreshStatus(effectiveMode)}disabled={statusLoading}className="p-1.5 rounded text-gray-400 hover:text-white hover:bg-port-border/50 disabled:opacity-50"title="Refresh status"diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.jsindex 4add2d4ea1..50459ca363 100644--- a/client/src/services/apiSystem.js+++ b/client/src/services/apiSystem.js@@ -114,7 +114,7 @@ export const getTailnetInfo = () => request('/instances/tailnet-suffix');export const provisionTailnetCert = () => request('/instances/provision-cert', { method: 'POST' });// Image Generation-export const getImageGenStatus = () => request('/image-gen/status');+export const getImageGenStatus = (mode) => request(`/image-gen/status${mode ? `?mode=${encodeURIComponent(mode)}` : ''}`);export const generateImage = (data) => request('/image-gen/generate', {method: 'POST',body: JSON.stringify(data)diff --git a/server/routes/sdapi.js b/server/routes/sdapi.jsindex a7e3655644..4999c682ad 100644--- a/server/routes/sdapi.js+++ b/server/routes/sdapi.js@@ -183,14 +183,15 @@ router.post('/txt2img', asyncHandler(async (req, res) => {modelId = sd_model_checkpoint.replace(/^portos-local-/, '').split(' ')[0];}- // In local mode generateImage returns the moment the Python child is+ // In local + codex modes generateImage returns the moment the child is// spawned — the file isn't on disk yet. Subscribe to the completion event// BEFORE calling generateImage so a fast job (cached weights, low steps)// can't fire before we attach. External mode awaits internally and the// file is on disk by the time generateImage resolves, so the wait is a// no-op there.const mode = await getMode();- const localWait = mode === 'local'+ const isAsyncMode = mode === 'local' || mode === 'codex';+ const localWait = isAsyncMode? createCompletionWaiter(): { register: () => {}, promise: Promise.resolve(), cleanup: () => {} };diff --git a/server/services/voice/tools.js b/server/services/voice/tools.jsindex e1afa5372d..207feed0ea 100644--- a/server/services/voice/tools.js+++ b/server/services/voice/tools.js@@ -1101,11 +1101,28 @@ const TOOLS = [return { ok: false, summary: 'Codex Imagegen is disabled — enable it in Settings → Image Gen first.' };}}+ // LLMs/tool callers often hand back numeric args as strings ("512").+ // Coerce + bounds-check before forwarding — the route's Zod schema+ // also gates these, but voice tool calls bypass the route, so an+ // unvalidated string would propagate to providers that build+ // payloads with raw width values (external SD API: "width": "512").+ const normalizeDimension = (value, name) => {+ if (value === undefined || value === null || value === '') return { ok: true, value: undefined };+ const parsed = Number(value);+ if (!Number.isInteger(parsed) || parsed < 64 || parsed > 2048) {+ return { ok: false, summary: `${name} must be an integer between 64 and 2048` };+ }+ return { ok: true, value: parsed };+ };+ const w = normalizeDimension(width, 'width');+ if (!w.ok) return w;+ const h = normalizeDimension(height, 'height');+ if (!h.ok) return h;const result = await imageGen.generateImage({prompt: prompt.trim(),negativePrompt: negativePrompt?.trim() || undefined,- width: width || undefined,- height: height || undefined,+ width: w.value,+ height: h.value,mode: requestedMode,});const usedMode = result?.mode || requestedMode || 'default';diff --git a/server/services/voice/tools.test.js b/server/services/voice/tools.test.jsindex 94299aaf16..b4b1ca904a 100644--- a/server/services/voice/tools.test.js+++ b/server/services/voice/tools.test.js@@ -490,4 +490,28 @@ describe("image_generate", () => {expect(r.path).toBe("/data/images/mock.png");expect(r.filename).toBe("mock.png");});++ it("coerces stringified width/height to numbers before forwarding", async () => {+ generateImageMock.mockClear();+ const r = await dispatchTool("image_generate", { prompt: "a fox", width: "512", height: "768" });+ expect(r.ok).toBe(true);+ const args = generateImageMock.mock.calls[0][0];+ expect(args.width).toBe(512);+ expect(args.height).toBe(768);+ });++ it("rejects out-of-bounds width", async () => {+ generateImageMock.mockClear();+ const r = await dispatchTool("image_generate", { prompt: "a fox", width: 50000 });+ expect(r.ok).toBe(false);+ expect(r.summary).toMatch(/width must be an integer between 64 and 2048/);+ expect(generateImageMock).not.toHaveBeenCalled();+ });++ it("rejects non-integer height (e.g. floats)", async () => {+ generateImageMock.mockClear();+ const r = await dispatchTool("image_generate", { prompt: "a fox", height: "768.5" });+ expect(r.ok).toBe(false);+ expect(r.summary).toMatch(/height must be an integer between 64 and 2048/);+ });});