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

address review round 2: 5 Copilot findings on PR #181

Adam Eivycde8ab8e5a02
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index ebd0789e96..7813d1ffa9 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,4 +6,4 @@
- **Image Gen — third backend: Codex CLI `$imagegen`.** Image Gen can now route generation through the user's locally-installed Codex CLI built-in `image_gen` tool — invoked headlessly with `codex exec --skip-git-repo-check --sandbox workspace-write '$imagegen <prompt>'` so it uses the user's logged-in Codex session (no `OPENAI_API_KEY` required). New provider at `server/services/imageGen/codex.js` mirrors `local.js` (single-job model, SSE progress events) but harvests the resulting PNG from `~/.codex/generated_images/<session-id>/ig_*.png` after parsing the session id out of the codex launch banner — codex's stdout has no machine-readable image path, so banner-parse + dir-poll is the contract. Failure modes are surfaced clearly via `imageGenEvents`: empty session dir → "your Codex account may not allow image_gen", missing session id → "output format may have changed", non-zero exit → tail of stderr. Codex usage is gated by an explicit `Enable Codex Imagegen` setting because not every Codex plan exposes the `image_gen` tool — when disabled the option disappears from settings tile, image-gen page chip, voice tool dispatch, and palette gating up front.
- **Image Gen — per-render backend chip.** New chip strip on the Image Gen page lets the user flip between Local / External / Codex per-render without changing the saved default. Only viable backends (External URL set, Local Python set, Codex enabled) appear; the strip hides itself when only one backend is configured. Selection is sent as `mode:` in `POST /api/image-gen/generate` and the dispatcher honors the override. Codex mode also hides backend-irrelevant knobs (steps, seed, guidance/CFG, LoRAs, quantize) since the built-in `image_gen` tool decides those internally. `GET /api/image-gen/status?mode=codex` lets the page probe a non-default backend before saving.
- **CoS / voice — `image_generate` tool.** New voice tool that delegates to the Image Gen dispatcher. Defaults to the user's saved backend; agents pass `provider: 'local' | 'external' | 'codex' | 'auto'` to override. Codex is gated on `imageGen.codex.enabled` — disabled returns `{ ok: false, summary: 'Codex Imagegen is disabled — enable it in Settings → Image Gen first.' }` instead of the friendly server error. Tool joins the new `media` intent group (regex matches creation verbs paired with visual nouns plus `imagegen`) so small tool-use models only see it on imagery turns. Whitelisted in `PALETTE_ACTIONS` as `Generate Image` under section `Create` so `⌘K` exposes it for keyboard invocation.
-- **Image Gen dispatcher — explicit per-request mode override.** `imageGen.generateImage()` now accepts `params.mode` (one of `external`, `local`, `codex`) to force a specific backend independent of `settings.imageGen.mode`. `imageGen.checkConnection({ mode })` similarly probes a specific backend. The dispatcher's SSE attach (`attachSseClient`) and `cancel()` now route across all async providers (local + codex), so `GET /api/image-gen/:jobId/events` and `POST /api/image-gen/cancel` work for codex jobs without needing a separate route. Files: `server/services/imageGen/codex.js` (new), `server/services/imageGen/index.js`, `server/routes/imageGen.js`, `server/services/voice/tools.js`, `server/routes/palette.js`, `client/src/components/settings/ImageGenTab.jsx`, `client/src/pages/ImageGen.jsx`. 10 new codex provider tests + 7 new voice-tool tests; full server suite green at 2812/2812.
+- **Image Gen dispatcher — explicit per-request mode override.** `imageGen.generateImage()` now accepts `params.mode` (one of `external`, `local`, `codex`) to force a specific backend independent of `settings.imageGen.mode`. `imageGen.checkConnection({ mode })` similarly probes a specific backend. The dispatcher's SSE attach (`attachSseClient`) and `cancel()` now route across all async providers (local + codex), so `GET /api/image-gen/:jobId/events` and `POST /api/image-gen/cancel` work for codex jobs without needing a separate route. Files: `server/services/imageGen/codex.js` (new), `server/services/imageGen/index.js`, `server/routes/imageGen.js`, `server/services/voice/tools.js`, `server/routes/palette.js`, `client/src/components/settings/ImageGenTab.jsx`, `client/src/pages/ImageGen.jsx`. New unit tests for the codex provider (mocked spawn, session-id parse, file harvest, failure paths) and the `image_generate` voice tool (provider override, codex-disabled gate, dimension validation); server suite remains green.
diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsx
index 6b8c75e80e..04a01a129e 100644
--- a/client/src/components/settings/ImageGenTab.jsx
+++ b/client/src/components/settings/ImageGenTab.jsx
@@ -124,10 +124,18 @@ export function ImageGenTab() {
};
try {
await updateSettings(patch);
+ // Store trimmed values to match what was persisted — otherwise
+ // trailing whitespace in the inputs leaves isDirty stuck true even
+ // after a successful save (state has " codex " but `saved` was
+ // updated with the trimmed "codex").
setSaved({
mode, sdapiUrl: url || '', pythonPath, exposeA1111,
- codexEnabled, codexPath, codexModel,
+ codexEnabled, codexPath: cxPath || '', codexModel: cxModel || '',
});
+ // Reflect the normalization back into the inputs so what the user
+ // sees matches what was saved.
+ if (cxPath !== codexPath) setCodexPath(cxPath || '');
+ if (cxModel !== codexModel) setCodexModel(cxModel || '');
toast.success('Image gen settings saved');
} catch (err) {
toast.error(err.message || 'Failed to save settings');
@@ -190,9 +198,13 @@ export function ImageGenTab() {
setRendering(true);
setRenderResult(null);
try {
- // Use the saved mode for the test render. Codex is async like local
- // (returns a job descriptor immediately) so the SSE branch handles it.
- const result = await generateImage({ prompt: testPrompt.trim(), mode });
+ // Use saved.mode (not the live `mode` state) so the test render
+ // always reflects what's actually persisted server-side. The
+ // disabled={isDirty} guard already prevents this branch from running
+ // with unsaved changes, but reading from `saved` makes the contract
+ // explicit. Codex is async like local (returns a job descriptor
+ // immediately) so the SSE branch handles it.
+ const result = await generateImage({ prompt: testPrompt.trim(), mode: saved.mode });
// Local + Codex modes return immediately after spawning the child —
// the PNG isn't on disk yet. Subscribe to the per-job SSE and only
// mark the render complete on the `complete` event (or fail on
diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsx
index dd4e4313da..7da0db0c79 100644
--- a/client/src/pages/ImageGen.jsx
+++ b/client/src/pages/ImageGen.jsx
@@ -211,9 +211,10 @@ export default function ImageGen() {
const startLocalGeneration = async () => {
setLocalProgress({ progress: 0 });
- // Codex shares the SSE-driven async pipeline with local but ignores
- // local-only knobs (model, LoRAs, quantize, guidance) — the dispatcher
- // strips them on its way to the codex provider.
+ // Codex shares the SSE-driven async pipeline with local. The codex
+ // payload below intentionally omits local-only knobs (model, LoRAs,
+ // quantize, guidance, steps, seed) — the codex provider only consumes
+ // prompt/negative/width/height, so we don't bother sending the rest.
const payload = isCodexMode ? {
prompt: prompt.trim(),
negativePrompt: negativePrompt.trim() || undefined,
diff --git a/server/services/imageGen/index.js b/server/services/imageGen/index.js
index c9fe78c1a8..a5cfbca8db 100644
--- a/server/services/imageGen/index.js
+++ b/server/services/imageGen/index.js
@@ -106,9 +106,13 @@ export const attachSseClient = (jobId, res) => {
};
export const cancel = () => {
- const cancelled = local.cancel();
- if (cancelled) return true;
- return codex.cancel();
+ // Each provider enforces its own single-job invariant independently, so
+ // both can have a job in flight simultaneously. Cancel them all and
+ // return whether anything was actually cancelled — short-circuiting on
+ // the first hit would orphan a codex job whenever local is active.
+ const localCancelled = local.cancel();
+ const codexCancelled = codex.cancel();
+ return localCancelled || codexCancelled;
};
// Re-exports so routes can hit a specific backend directly when the request