Skip to content

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

refactor([hoist-loopback-host-helper-to-client-lib]): adopt isLoopbackHost at ImageGenTab#advertisedA1111Url

[._.]/ Adam Eivybddd20c1f3f5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 4e052b9e30..eba4410ffd 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,7 +6,7 @@
- **[cleanplateprompt-migrate-to-rich-canon-fragments] Clean-plate descriptor body now flows through `richCanonDescriptorFragments('place', setting)`.** `composeCleanPlatePrompt` (`client/src/lib/cleanPlatePrompt.js`) was hand-rolling `description + Palette + recurringDetails` extraction at lines 26–30 and silently dropped `era` / `weather` — the same gap `[pipeline-visual-stages-setting-field-injection]` closed for storyboard + comic-panel renders. Migrated the descriptor body to `mapCanonDescriptorFragments(richCanonDescriptorFragments('place', setting), { trailingPeriod: true })`, matching the existing place-side helper call in `scenePrompt.js:104`. Output is byte-identical for the legacy three-field case (verified via the existing populated test) and now surfaces era + weather when populated. Two new tests in `cleanPlatePrompt.test.js` lock in both halves — the era/weather positive case and the blank/whitespace-only negative case. 242/242 client tests pass.
-- **[hoist-loopback-host-helper-to-client-lib] Loopback / secure-context helpers hoisted to `client/src/lib/loopbackHost.js`.** `client/src/components/NetworkExposureWidget.jsx` previously re-declared `LOOPBACK_HOSTS` + `isLoopbackOrigin` + `describeMicAvailability` inline (the server's `isLoopbackHost` in `server/lib/networkExposure.js` isn't reachable from the browser). New shared client module exports `isLoopbackHost(host)` / `isLoopbackOrigin()` / `describeMicAvailability()` so future secure-context callers (mic, voice, clipboard heuristics) reuse one rule. The hoisted `isLoopbackHost` broadens the IPv4 check from the single literal `127.0.0.1` to the full `127.0.0.0/8` range (`/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/`) to match browser Secure Context behavior — the kernel routes the whole block to lo0, so `127.5.6.7` over plain HTTP is also a secure context in the browser. Widget swaps its three inline helpers for two imports. Barrel + README row added per the `client/src/lib/` maintenance rule; 30 new tests in `loopbackHost.test.js` cover the IPv4 range expansion, IPv6 bracketed form, case-insensitivity, and the three branches of `describeMicAvailability`. 270/270 client tests pass; lint clean.
+- **[hoist-loopback-host-helper-to-client-lib] Loopback / secure-context helpers hoisted to `client/src/lib/loopbackHost.js`.** `client/src/components/NetworkExposureWidget.jsx` previously re-declared `LOOPBACK_HOSTS` + `isLoopbackOrigin` + `describeMicAvailability` inline (the server's `isLoopbackHost` in `server/lib/networkExposure.js` isn't reachable from the browser). New shared client module exports `isLoopbackHost(host)` / `isLoopbackOrigin()` / `describeMicAvailability()` so future secure-context callers (mic, voice, clipboard heuristics) reuse one rule. The hoisted `isLoopbackHost` broadens the IPv4 check from the single literal `127.0.0.1` to the full `127.0.0.0/8` range (`/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/`) to match browser Secure Context behavior — the kernel routes the whole block to lo0, so `127.5.6.7` over plain HTTP is also a secure context in the browser. Widget swaps its three inline helpers for two imports. `/simplify` reuse pass picked up a third inline loopback check in `client/src/components/settings/ImageGenTab.jsx#advertisedA1111Url` (`h === 'localhost' || h === '127.0.0.1' || h === '::1'`); migrated to `isLoopbackHost(h)` in the same diff so the advertised-A1111 hint now also rejects the browser-bracketed `[::1]` form and the full 127.x range. Barrel + README row added per the `client/src/lib/` maintenance rule; 30 new tests in `loopbackHost.test.js` cover the IPv4 range expansion, IPv6 bracketed form, case-insensitivity, and the three branches of `describeMicAvailability`. 270/270 client tests pass; lint clean.
- **[imagegen-local-defer-module-load-side-effects] Drop the module-load `IMAGE_MODELS` snapshot in `server/services/imageGen/local.js`.** The `export const IMAGE_MODELS = Object.fromEntries(getImageModels().map(...))` line ran `loadMediaModels()` at import time — which `mkdirSync`s the registry dir and `writeFileSync`s a default registry on first run. Any importer reaching `imageGen/local.js` via a test that mocks `PATHS.data` to a non-writable path (e.g. `routes/pipeline.test.js → routes/pipeline.js → universeBuilderCollectionHook.js`) failed on `mkdirSync('/mock/data')`. The export was dead (zero callers — grep confirmed) and `generateImage()` already reads the live registry via `getImageModels()`. Removed the export, reverted the 2026-05-19 lazy-import workaround in `services/universeBuilderCollectionHook.js` (now a normal static `import { readImageSidecar }`). Also tightened `enrichSidecar` to use `atomicWrite` (temp+rename) instead of `writeFile` — the prior plain write had a flaky race in tests where five-at-a-time batch enrichment let concurrent readers observe a mid-truncate empty file. 6090/6090 server tests + 234/234 client tests pass; the previously-flaky `enriches every sidecar in a batch` test now passes 10/10 runs.
diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsx
index 832d2d930b..dfda32615e 100644
--- a/client/src/components/settings/ImageGenTab.jsx
+++ b/client/src/components/settings/ImageGenTab.jsx
@@ -14,6 +14,7 @@ import {
import toast from '../ui/Toast';
import BrailleSpinner from '../BrailleSpinner';
import LocalSetupPanel from './LocalSetupPanel';
+import { isLoopbackHost } from '../../lib/loopbackHost.js';
import {
getSettings, updateSettings, getImageGenStatus, generateImage,
registerTool, updateTool, getToolsList,
@@ -353,7 +354,7 @@ export function ImageGenTab() {
const h = window.location.hostname;
// Local dev / loopback mirror — we can't infer the tailnet hostname
// from the browser; tell the user to look it up.
- if (h === 'localhost' || h === '127.0.0.1' || h === '::1') return null;
+ if (isLoopbackHost(h)) return null;
// Real tailnet host — use the canonical user-facing port (:5555) and
// match the currently-active scheme so the hint works in both HTTPS-on
// (Tailscale cert provisioned) and HTTP-only PortOS deployments.