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

feat(pipeline): enable 'from proof' i2i with the Codex (gpt-image-2) backend (#274)

[._.]/ Adam Eivy613e8f04567e
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 1feb695aa3..666a251957 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -12,6 +12,7 @@
- **Locking a canon entry now also blocks new reference renders.** Locked characters/places/objects already prevented AI rewrites; they now prevent new reference and clean-plate image renders too, so a locked entry's identity stays frozen across both text and visuals. Disabled buttons explain the lock in their tooltips.
- **Universe Builder categories now carry a canon trunk (`kind`)** so each bucket knows whether it belongs under Cast, Places, Objects, or Other. Built-in defaults are pre-tagged (landscapes/environments/structures → Places, vehicles → Objects); custom buckets default to Other until you sort them. The default `characters` category was retired — canon owns characters now, and any pre-existing character variations get folded into universe canon on upgrade. Foundation for the upcoming tabbed-trunk Universe Builder redesign.
- **TUI providers now return clean responses via a per-run output file.** Claude Code TUI / Codex TUI runs are now instructed to write their final response to `data/runs/<runId>/tui-response.txt`, which the runner reads back instead of scraping the PTY screen — no more banner art, "5% cost" meters, or "bypass permissions on" hints leaking into stage outputs. Falls back to the existing screen-scrape cleanup when the file isn't written.
+- **"From proof" final renders now work with the Codex (gpt-image-2) backend.** Codex CLI's `-i <file>` flag attaches the proof PNG so gpt-image-2 runs in image-edit mode and preserves composition while upscaling, instead of redrawing from scratch. The pipeline UI's "from proof" toggle on covers, back covers, and pages is no longer disabled when Codex is the selected backend; the dispatcher only strips `initImagePath` for the external SD-API backend (which has no i2i wiring). `initImageStrength` is mapped to a natural-language fidelity phrase in the prompt so low strengths keep the proof's layout intact and high strengths leave room for reinterpretation.
## Fixed
diff --git a/client/src/components/pipeline/stages/ComicScriptStage.jsx b/client/src/components/pipeline/stages/ComicScriptStage.jsx
index 74e771716f..c86a0a6e0c 100644
--- a/client/src/components/pipeline/stages/ComicScriptStage.jsx
+++ b/client/src/components/pipeline/stages/ComicScriptStage.jsx
@@ -349,11 +349,6 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
);
};
- const i2iSupported = imageCfg.mode !== 'codex';
- const i2iDisabledReason = i2iSupported
- ? null
- : 'Codex (gpt-image-2) does not support image-to-image. Switch backend in the image-gen settings to use the proof as a base.';
-
// Shared script-persist (cover / backCover) — server-side updatePipelineIssue
// does a deep merge under stages.comicPages.<field>. Only the script text
// is sent; render slots are written exclusively by the render route to
@@ -372,7 +367,7 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
const isBack = field === 'backCover';
const useProofToggle = isBack ? useProofForBackFinal : useProofForCoverFinal;
setBusyFor(field, variant, true);
- const useProofAsBase = variant === 'final' && useProofToggle && i2iSupported;
+ const useProofAsBase = variant === 'final' && useProofToggle;
const draftText = isBack ? draftBackCoverScript : draftCoverScript;
const apiCall = isBack ? generatePipelineComicBackCover : generatePipelineComicCover;
const bodyScriptKey = isBack ? 'backCoverScript' : 'coverScript';
@@ -543,14 +538,13 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
Render proof
</button>
<label
- className={`flex items-center gap-1 text-[11px] text-gray-400 ${i2iSupported ? 'cursor-pointer' : 'cursor-not-allowed opacity-60'}`}
- title={i2iDisabledReason || 'Use the proof image as the base for the final render — preserves composition.'}
+ className="flex items-center gap-1 text-[11px] text-gray-400 cursor-pointer"
+ title="Use the proof image as the base for the final render — preserves composition."
>
<input
type="checkbox"
- checked={i2iSupported && useProofForCoverFinal}
+ checked={useProofForCoverFinal}
onChange={(e) => setUseProofForCoverFinal(e.target.checked)}
- disabled={!i2iSupported}
className="rounded"
/>
from proof
@@ -560,12 +554,12 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
onClick={() => handleRenderCoverField('cover', 'final')}
disabled={
busy.coverFinal || coverFinalInFlight || actionsGated
- || (i2iSupported && useProofForCoverFinal && !coverProof?.filename)
+ || (useProofForCoverFinal && !coverProof?.filename)
}
title={finalButtonTooltip({
gated: actionsGated,
inFlight: coverFinalInFlight,
- needsProof: i2iSupported && useProofForCoverFinal && !coverProof?.filename,
+ needsProof: useProofForCoverFinal && !coverProof?.filename,
defaultMsg: 'Render the hi-res final cover at the configured size. Tick "from proof" to upscale the proof rather than redraw it.',
})}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-port-accent text-white text-xs font-medium hover:bg-port-accent/90 disabled:opacity-40 disabled:cursor-not-allowed"
@@ -627,14 +621,13 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
Render proof
</button>
<label
- className={`flex items-center gap-1 text-[11px] text-gray-400 ${i2iSupported ? 'cursor-pointer' : 'cursor-not-allowed opacity-60'}`}
- title={i2iDisabledReason || 'Use the proof image as the base for the final render — preserves composition.'}
+ className="flex items-center gap-1 text-[11px] text-gray-400 cursor-pointer"
+ title="Use the proof image as the base for the final render — preserves composition."
>
<input
type="checkbox"
- checked={i2iSupported && useProofForBackFinal}
+ checked={useProofForBackFinal}
onChange={(e) => setUseProofForBackFinal(e.target.checked)}
- disabled={!i2iSupported}
className="rounded"
/>
from proof
@@ -644,12 +637,12 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
onClick={() => handleRenderCoverField('backCover', 'final')}
disabled={
busy.backFinal || backFinalInFlight || actionsGated
- || (i2iSupported && useProofForBackFinal && !backProof?.filename)
+ || (useProofForBackFinal && !backProof?.filename)
}
title={finalButtonTooltip({
gated: actionsGated,
inFlight: backFinalInFlight,
- needsProof: i2iSupported && useProofForBackFinal && !backProof?.filename,
+ needsProof: useProofForBackFinal && !backProof?.filename,
defaultMsg: 'Render the hi-res final back-cover at the configured size. Tick "from proof" to upscale the proof rather than redraw it.',
})}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-port-accent text-white text-xs font-medium hover:bg-port-accent/90 disabled:opacity-40 disabled:cursor-not-allowed"
@@ -699,8 +692,6 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
pageIndex={pi}
page={page}
renderOpts={renderOpts}
- i2iSupported={i2iSupported}
- i2iDisabledReason={i2iDisabledReason}
onStageUpdate={onStageUpdate}
onPreview={openPreview}
onFilenameKnown={onFilenameKnown}
@@ -740,7 +731,6 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions
function PageRow({
issue, pageIndex, page, renderOpts = {},
- i2iSupported = true, i2iDisabledReason = null,
onStageUpdate, onPreview, onFilenameKnown,
}) {
const rawText = useMemo(
@@ -782,7 +772,7 @@ function PageRow({
const handleRender = async (target) => {
const setFlight = target === 'final' ? setRenderingFinal : setRenderingProof;
setFlight(true);
- const useProofAsBase = target === 'final' && useProofForFinal && i2iSupported;
+ const useProofAsBase = target === 'final' && useProofForFinal;
const res = await generatePipelineComicPage(issue.id, pageIndex, {
...renderOpts,
target,
@@ -807,7 +797,7 @@ function PageRow({
}
};
- const finalNeedsProof = i2iSupported && useProofForFinal && !proofSlot?.filename;
+ const finalNeedsProof = useProofForFinal && !proofSlot?.filename;
return (
<li className="rounded-lg border border-port-border bg-port-card/40">
@@ -842,14 +832,13 @@ function PageRow({
Proof
</button>
<label
- className={`flex items-center gap-1 text-[11px] text-gray-400 px-1 ${i2iSupported ? 'cursor-pointer' : 'cursor-not-allowed opacity-60'}`}
- title={i2iDisabledReason || 'Use the proof image as the base for the final render — preserves panel layout.'}
+ className="flex items-center gap-1 text-[11px] text-gray-400 px-1 cursor-pointer"
+ title="Use the proof image as the base for the final render — preserves panel layout."
>
<input
type="checkbox"
- checked={i2iSupported && useProofForFinal}
+ checked={useProofForFinal}
onChange={(e) => setUseProofForFinal(e.target.checked)}
- disabled={!i2iSupported}
className="rounded"
/>
from proof
diff --git a/server/routes/pipeline.js b/server/routes/pipeline.js
index b46d9740bf..068e3847d3 100644
--- a/server/routes/pipeline.js
+++ b/server/routes/pipeline.js
@@ -351,9 +351,10 @@ const visualGenerateSchema = z.object({
//
// `seed` mirrors the page/panel render schemas so the shared image-gen
// drawer flows the same render settings into the cover —
-// enqueueImageJob honors it via options.seed. `useProofAsBase` is silently
-// ignored by Codex (gpt-image-2's $imagegen has no init-image input);
-// local + external honor it.
+// enqueueImageJob honors it via options.seed. `useProofAsBase` is honored by
+// local (mflux `--image-path`) and codex (gpt-image-2 image-edit via the
+// CLI's `-i <file>` flag); external SD-API has no i2i wiring and silently
+// drops the init image at the dispatcher.
const makeCoverRenderSchema = (scriptField) => z.object({
[scriptField]: z.string().max(8000).optional(),
negativePrompt: z.string().trim().max(2000).optional(),
diff --git a/server/services/imageGen/codex.js b/server/services/imageGen/codex.js
index 05f61d79f6..df7e93b5ad 100644
--- a/server/services/imageGen/codex.js
+++ b/server/services/imageGen/codex.js
@@ -119,23 +119,31 @@ export async function checkConnection({ codexPath } = {}) {
const SESSION_ID_RE = /^session id:\s*([0-9a-f-]{36})/im;
+// Codex CLI exposes no numeric i2i denoise knob, so map the local-runner-style
+// strength (0..1, lower = more faithful to the source) onto a phrase the model
+// reliably honors inside `$imagegen`. Mirrors PROOF_AS_BASE_DEFAULT_STRENGTH
+// (0.25) defaulting toward composition-preserving edits.
+const describeFidelity = (strength) => {
+ const n = Number.isFinite(strength) ? Math.max(0, Math.min(1, Number(strength))) : 0.25;
+ if (n <= 0.2) return 'preserve composition, characters, and layout exactly — only refine detail and resolution';
+ if (n <= 0.4) return 'preserve composition and characters while adding rendered detail at higher fidelity';
+ if (n <= 0.7) return 'use the attached image as a strong reference while refining art and detail';
+ return 'use the attached image as a loose reference; you may reinterpret freely';
+};
+
+// When `initImagePath` is set we attach the file via codex CLI's `-i <FILE>`
+// flag and reshape the prompt so the `$imagegen` skill feeds the attachment
+// to `image_gen` as an input image (gpt-image-2's image-edit mode).
+// `initImageStrength` is mapped to a fidelity phrase via describeFidelity —
+// codex CLI exposes no numeric denoise knob.
export async function generateImage({
codexPath, model, prompt, width, height, negativePrompt,
- // Accepted (and ignored) so the pipeline's "use proof as base" upscale path
- // doesn't reject when codex is the active backend. The `$imagegen` skill in
- // the Codex CLI has no init-image input; this surface is local-only. Logged
- // so the degraded behavior is visible — a final render kicked off with
- // useProofAsBase=true against codex will be a full redraw at the larger
- // size, not an i2i upscale that preserves the proof's composition.
- initImagePath, initImageStrength: _initImageStrength,
+ initImagePath, initImageStrength,
jobId: providedJobId = null,
}) {
if (!prompt?.trim()) {
throw new ServerError('Prompt is required', { status: 400, code: 'VALIDATION_ERROR' });
}
- if (initImagePath) {
- console.log(`⚠️ codex generateImage: ignoring initImagePath (gpt-image-2 $imagegen has no init-image input — falling back to full redraw)`);
- }
await ensureDir(PATHS.images);
const jobId = providedJobId || randomUUID();
@@ -150,13 +158,17 @@ export async function generateImage({
const sizeHint = (width && height) ? ` (${width}x${height})` : '';
const qualityHint = (width >= 1536 || height >= 1536) ? ' (high quality)' : '';
const avoidHint = negativePrompt?.trim() ? `\nAvoid: ${negativePrompt.trim()}` : '';
- const fullPrompt = `$imagegen ${prompt.trim()}${sizeHint}${qualityHint}${avoidHint}`;
+ const editPrefix = initImagePath
+ ? `Edit the attached reference image — ${describeFidelity(initImageStrength)}. Render target:\n`
+ : '';
+ const fullPrompt = `$imagegen ${editPrefix}${prompt.trim()}${sizeHint}${qualityHint}${avoidHint}`;
const bin = codexPath || DEFAULT_BIN;
const args = [
'exec',
'--skip-git-repo-check',
'--sandbox', 'workspace-write',
+ ...(initImagePath ? ['-i', initImagePath] : []),
...(model ? ['-m', String(model)] : []),
fullPrompt,
];
diff --git a/server/services/imageGen/codex.test.js b/server/services/imageGen/codex.test.js
index 7c0d74ac76..ab8cc67da9 100644
--- a/server/services/imageGen/codex.test.js
+++ b/server/services/imageGen/codex.test.js
@@ -132,6 +132,41 @@ describe('codex provider — generateImage', () => {
await expect(codex.generateImage({ prompt: ' ' })).rejects.toThrow(/Prompt is required/);
});
+ it('forwards initImagePath via `-i <FILE>` and reshapes the prompt for image-edit', async () => {
+ await codex.generateImage({
+ prompt: 'cover art',
+ width: 1024, height: 1536,
+ initImagePath: '/abs/path/to/proof.png',
+ initImageStrength: 0.2,
+ });
+ const { args } = spawnCalls[0];
+ const iIdx = args.indexOf('-i');
+ expect(iIdx).toBeGreaterThan(-1);
+ expect(args[iIdx + 1]).toBe('/abs/path/to/proof.png');
+ const promptArg = args[args.length - 1];
+ // The `$imagegen` prefix is preserved so the bundled skill still triggers.
+ expect(promptArg.startsWith('$imagegen ')).toBe(true);
+ // Edit-prefix tells codex to use the attachment rather than redraw.
+ expect(promptArg).toMatch(/edit the attached reference image/i);
+ // Low strength → composition-preserving fidelity phrase.
+ expect(promptArg).toMatch(/preserve composition/i);
+ expect(promptArg).toContain('cover art');
+ spawnCalls[0].child.exitCode = 1;
+ spawnCalls[0].child.emit('close', 1, null);
+ await flush();
+ });
+
+ it('omits `-i` and the edit-prefix when no initImagePath is passed', async () => {
+ await codex.generateImage({ prompt: 'cover art', width: 1024, height: 1024 });
+ const { args } = spawnCalls[0];
+ expect(args).not.toContain('-i');
+ const promptArg = args[args.length - 1];
+ expect(promptArg).not.toMatch(/edit the attached reference image/i);
+ spawnCalls[0].child.exitCode = 1;
+ spawnCalls[0].child.emit('close', 1, null);
+ await flush();
+ });
+
it('allows concurrent generations (parallel codex lane)', async () => {
const a = await codex.generateImage({ prompt: 'one' });
const b = await codex.generateImage({ prompt: 'two' });
diff --git a/server/services/imageGen/index.js b/server/services/imageGen/index.js
index 92ca40788d..61a8ae4d18 100644
--- a/server/services/imageGen/index.js
+++ b/server/services/imageGen/index.js
@@ -61,10 +61,11 @@ export async function generateImage(params) {
}
// Strip the dispatcher-only `mode` field — providers don't expect it.
delete normalized.mode;
- // i2i is only supported by the local mflux backend. If the caller passed an
- // init image for external/codex, drop it silently rather than failing the
- // whole render — the prompt still produces a useful txt2img result.
- if (mode !== 'local' && (normalized.initImagePath || normalized.initImageStrength != null)) {
+ // i2i is supported by local (mflux/diffusers --image-path) and codex
+ // (gpt-image-2 image-edit via codex CLI's -i flag). External SD-API has no
+ // i2i wiring in this codebase, so drop the init image there rather than
+ // failing the whole render — the prompt still produces a useful txt2img.
+ if (mode === 'external' && (normalized.initImagePath || normalized.initImageStrength != null)) {
delete normalized.initImagePath;
delete normalized.initImageStrength;
}
diff --git a/server/services/pipeline/visualStages.js b/server/services/pipeline/visualStages.js
index 1fc61c13c1..f2c3a76e95 100644
--- a/server/services/pipeline/visualStages.js
+++ b/server/services/pipeline/visualStages.js
@@ -169,10 +169,11 @@ const enqueueImageJob = ({ prompt, world, settings, options, mode, owner, logLin
// Honored by local mflux + diffusers runners; codex picks its own.
...(Number.isFinite(options.seed) ? { seed: options.seed } : {}),
// i2i upscale path: when the caller passes an init image (e.g.
- // "use proof as base" for a final render) we forward it to the local
- // image-gen runner. Codex silently ignores both fields — its
- // `$imagegen` skill has no init-image input — so a codex-backend
- // final render with useProofAsBase=true degrades to a full redraw.
+ // "use proof as base" for a final render) we forward it to the active
+ // backend. Local mflux uses it as `--image-path`; codex attaches it via
+ // the CLI's `-i` flag and routes it to gpt-image-2's image-edit mode.
+ // The external SD-API backend has no i2i wiring and drops both fields
+ // at the dispatcher.
...(options.initImagePath ? { initImagePath: options.initImagePath } : {}),
...(Number.isFinite(options.initImageStrength) ? { initImageStrength: options.initImageStrength } : {}),
};