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

Merge remote-tracking branch 'origin/main' into claim/image-gen-mode-enum-unify

[._.]/ Adam Eivy3ed8cb4795f8
diff --cc .changelog/NEXT.md
index 1838e80855,eba4410ffd..21a2849e18
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@@ -2,7 -2,11 +2,13 @@@
## Changed
- - **[image-gen-mode-enum-unify] Unify the image-gen mode enum across server + client.** The bare `'codex'` / `'local'` / `'external'` string literals that lived at ~25 dispatch sites across `server/services/imageGen/{index,codex,local,external}.js`, `server/services/mediaJobQueue/index.js`, `server/services/pipeline/visualStages.js`, `server/services/universeCharacterSheet.js`, `server/routes/{imageGen,universeBuilder,sdapi}.js`, and the matching client surfaces (`ImageGen.jsx`, `ImageGenTab.jsx`, `VisualGenSettings.jsx`, `ImageGenControls.jsx`, `MediaJobsQueue.jsx`, `MediaLightbox.jsx`, `PromptRefineModal.jsx`, `normalize.js`, `imageGenResolutions.js`, `wrImageDefaults.js`, `ComicScriptStage.jsx`) now flow through a typed enum. Server adds `IMAGE_GEN_MODE = Object.freeze({ EXTERNAL, LOCAL, CODEX })` in a new `server/services/imageGen/modes.js` (standalone so the dispatcher and the provider modules can both import without a cycle), re-exported from `imageGen/index.js`; `IMAGE_GEN_MODES` (the Zod-validator alphabet) is now derived from `Object.values(IMAGE_GEN_MODE)` so the two can't drift. Client `IMAGE_GEN_MODE` in `client/src/lib/imageGenBackends.js` is `Object.freeze`d to match. `IMAGE_GEN_MODES` is preserved as-is for Zod + the OpenAI tool-spec enum. Provider binary names (`DEFAULT_BIN = 'codex'`) and model-fallback strings stay as bare literals — they're not modes. Two test mocks (`imageGen.test.js`, `sdapi.test.js`) updated to export the new constant. 6096/6096 server tests + 240/240 client tests pass.
++- **[image-gen-mode-enum-unify] Unify the image-gen mode enum across server + client.** The bare `'codex'` / `'local'` / `'external'` string literals that lived at ~25 dispatch sites across `server/services/imageGen/{index,codex,local,external}.js`, `server/services/mediaJobQueue/index.js`, `server/services/pipeline/visualStages.js`, `server/services/universeCharacterSheet.js`, `server/routes/{imageGen,universeBuilder,sdapi,pipeline}.js`, `server/services/pipeline/issues.js`, `server/services/voice/tools.js`, and the matching client surfaces (`ImageGen.jsx`, `ImageGenTab.jsx`, `VisualGenSettings.jsx`, `ImageGenControls.jsx`, `MediaJobsQueue.jsx`, `MediaLightbox.jsx`, `PromptRefineModal.jsx`, `normalize.js`, `imageGenResolutions.js`, `wrImageDefaults.js`, `ComicScriptStage.jsx`, `UniverseBuilder.jsx`) now flow through a typed enum. Server adds `IMAGE_GEN_MODE = Object.freeze({ EXTERNAL, LOCAL, CODEX })` in a new `server/services/imageGen/modes.js` (standalone so the dispatcher and the provider modules can both import without a cycle), re-exported from `imageGen/index.js`; `IMAGE_GEN_MODES` (the Zod-validator alphabet) is now derived from `Object.values(IMAGE_GEN_MODE)` so the two can't drift. Client `IMAGE_GEN_MODE` in `client/src/lib/imageGenBackends.js` is `Object.freeze`d to match. Zod schemas in `pipeline.js` and `universeBuilder.js` now consume the constants too so a future mode addition is one edit. Provider binary names (`DEFAULT_BIN = 'codex'`) and model-fallback strings stay as bare literals — they're not modes. Three test mocks (`imageGen.test.js`, `sdapi.test.js`, `voice/tools.test.js`) updated to export the new constant. Codex review caught five additional dispatch sites the first pass missed; second pass is CLEAN. 6096/6096 server tests + 240/240 client tests pass.
++
+ - **[extract-readcertmeta-helper] Shared `readCertMeta()` reader extracted from three call sites.** `server/lib/peerSelfHost.js`, `server/services/certRenewer.js`, and `server/lib/networkExposure.js` each open-coded their own `data/certs/meta.json` reader — three slightly different shapes (`statSync({throwIfNoEntry:false}) + safeJSONParse` in the first two, brittle `existsSync + JSON.parse` in the renewer that would throw on a partial mid-`setup:cert` write). Consolidated into `server/lib/certMeta.js` exporting `readCertMeta() → { mode, hostname?, ips? } | null`, standardized on the safe-JSON pattern so the renewer no longer logs noise on partial writes. New `certMeta.test.js` covers missing/malformed/tailscale/self-signed; barrel + README catalog rows added per the `server/lib/` maintenance rule. `/simplify` also cleaned out two dead `tryReadFile: vi.fn()` mock entries in `peerSelfHost.test.js` and `networkExposure.test.js` (leftover from earlier iterations, neither file imports `tryReadFile`). All 6100 server tests pass. Captured `[hoist-certmeta-to-top-level-lib]` as a follow-up to share the helper with `scripts/print-access-url.js` (a fourth bespoke reader) once the path is parameterized.
+
+ - **[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. `/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 --cc PLAN.md
index 9528b92808,4208062fe8..088439d7b4
--- a/PLAN.md
+++ b/PLAN.md
@@@ -12,9 -12,8 +12,7 @@@ _Nothing currently parked — pick the
### Code quality / dedup (from `/simplify` passes)
- - [ ] [cleanplateprompt-migrate-to-rich-canon-fragments] **Migrate `client/src/lib/cleanPlatePrompt.js#composeCleanPlatePrompt` to `richCanonDescriptorFragments('place', setting)`.** Clean-plate prompt builder (Cluster A — A4 setting reference renders) hand-rolls `description + Palette + recurringDetails` extraction at `cleanPlatePrompt.js:26-30` and is missing `era` / `weather` for the same reason `[pipeline-visual-stages-setting-field-injection]` was missing them — both are visual prompts that benefit from period/atmosphere cues. Tightly scoped sibling change (one client file + one test file). Deferred from that PR because the PLAN item targeted storyboard+comic-panel specifically; clean plates are setting-reference renders, adjacent but distinct.
- - [ ] [extract-readcertmeta-helper] **Extract a shared `readCertMeta()` helper from `data/certs/meta.json` readers.** Three independent readers exist: `server/lib/peerSelfHost.js:13-18` (hostname only), `server/services/certRenewer.js:30-31` (mode + hostname), `server/lib/networkExposure.js:25-29` (mode + hostname + ips). Each does its own `statSync({ throwIfNoEntry: false }) + readFileSync + safeJSONParse`. Consolidate into `server/lib/certMeta.js` exporting `readCertMeta() → { mode, hostname, ips } | null`. Surfaced by /simplify during `[codex5-network-exposure-ui]`; deferred to keep that PR scoped. Note `peerSelfHost.js` is in a hot path — verify perf when consolidating.
- - [ ] [hoist-loopback-host-helper-to-client-lib] **Hoist `isLoopbackHost` to `client/src/lib/loopbackHost.js`.** `server/lib/networkExposure.js` exports `isLoopbackHost`, but `client/src/components/NetworkExposureWidget.jsx:22-30` re-declares the same `LOOPBACK_HOSTS` Set and `describeMicAvailability()` helper inline (server export isn't reachable from browser). Move the client copy into `client/src/lib/loopbackHost.js` + add a barrel entry so future secure-context callers (voiceClient, etc.) can reuse it. When hoisting, broaden the IPv4 check from a single literal `127.0.0.1` to the full `127.0.0.0/8` loopback range to match browser secure-context behavior — easy `/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/` regex. Surfaced by /simplify and the codex review during `[codex5-network-exposure-ui]`.
+ - [ ] [hoist-certmeta-to-top-level-lib] **Hoist `readCertMeta()` to top-level `lib/certMeta.js`.** The new helper at `server/lib/certMeta.js` bakes `PATHS.data` at module load, so `scripts/print-access-url.js:26-29` (the fourth bespoke `JSON.parse(readFileSync(META_PATH, 'utf-8')).mode` reader) can't share it without crossing the scripts/server boundary. Move next to `lib/certPaths.js` and change the signature to `readCertMeta(metaPath)` so both `server/` and `scripts/` can call it; update `print-access-url.js` to drop its inline try/catch. Surfaced by /simplify during `[extract-readcertmeta-helper]`; deferred to keep that PR scoped to the server-side consolidation. Low priority — `print-access-url.js` is a cold script-banner path and already wraps the parse in try/catch.
-- [ ] [image-gen-mode-enum-unify] **Unify image-gen mode enum across server + client.** Server has `IMAGE_GEN_MODES = ['external','local','codex']` (a Zod-validator alphabet) at `server/services/imageGen/index.js:21`; client has `IMAGE_GEN_MODE` constants at `client/src/lib/imageGenBackends.js:3`. Code reads strings (`'codex'`, `'local'`, `'external'`) inline at ~10 sites across `server/services/imageGen/{codex,local,external}.js`, `server/routes/imageGen.js`, and several client pages. `IMAGE_GEN_MODES` is actively used (Zod enum + voice tool enum), so the choice is "export a typed enum object on the server (`IMAGE_GEN_MODE = Object.freeze({ CODEX: 'codex', ... })`) alongside `IMAGE_GEN_MODES` and adopt it at dispatch sites" — not "drop `IMAGE_GEN_MODES`". Surfaced by /simplify after the per-render checkbox PR.
- [ ] [unknown-instance-id-sentinel-extract] **Extract the `'unknown'` instanceId sentinel to a named constant.** The literal string `'unknown'` appears at 7+ sites across `server/services/instances.js#getInstanceId` (the default), `server/services/mediaAnnotations.js` (heal check in `readAll`, peer-merge guard, `setAnnotation` precondition), and `server/services/sharing/annotationsSync.js#flushAll` (export-refusal guard). Promote to `export const UNKNOWN_INSTANCE_ID = 'unknown'` in `instances.js` and import where compared, so the contract is greppable and typo-proof. Surfaced by /simplify during `[med-migration-scripts-migrations-014-attribute]`.
### v2.1.0 pre-release review residue (deferred from main→release multi-agent review, 2026-05-16)