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
pipeline/comic: disembodied balloons for off-panel speakers + cross-page consistency reference
[._.]/ Adam Eivyf2d26618f35a
diff --git a/client/src/components/pipeline/stages/ComicScriptStage.jsx b/client/src/components/pipeline/stages/ComicScriptStage.jsxindex ee3095a411..a0cf7e0a93 100644--- a/client/src/components/pipeline/stages/ComicScriptStage.jsx+++ b/client/src/components/pipeline/stages/ComicScriptStage.jsx@@ -738,6 +738,7 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actionsissue={issue}pageIndex={pi}page={page}+ pageCount={pages.length}renderOpts={renderOpts}onStageUpdate={onStageUpdate}onPreview={openPreview}@@ -781,7 +782,7 @@ export default function ComicScriptStage({ issue, series, onStageUpdate, actions}function PageRow({- issue, pageIndex, page, renderOpts = {},+ issue, pageIndex, page, pageCount = 0, renderOpts = {},onStageUpdate, onPreview, onFilenameKnown,confirmingDelete, onArmDelete, onCancelDelete, onConfirmDelete,}) {@@ -802,6 +803,12 @@ function PageRow({const [renderingProof, setRenderingProof] = useState(false);const [renderingFinal, setRenderingFinal] = useState(false);const [useProofForFinal, setUseProofForFinal] = useState(true);+ // Consistency reference: re-render this page using an adjacent page's image as+ // a reference so a continuing scene keeps incidental/un-described characters ++ // environment consistent. '' = none, 'prior' = previous page, 'next' = next.+ const [refPage, setRefPage] = useState('');+ const hasPrior = pageIndex > 0;+ const hasNext = pageIndex < pageCount - 1;// Sync local edits with parent updates (re-extract / re-render persist).useEffect(() => { setDraft(rawText); }, [rawText]);const dirty = draft !== rawText;@@ -837,11 +844,13 @@ function PageRow({...renderOpts,target,useProofAsBase,+ ...(refPage ? { referencePage: refPage } : {}),}).catch((err) => { toast.error(err.message || 'Render failed'); return null; });setFlight(false);if (res) {onStageUpdate?.('comicPages', res.stage);- const suffix = useProofAsBase ? ' (from proof)' : '';+ const refSuffix = refPage ? ` (ref: ${refPage} page)` : '';+ const suffix = useProofAsBase ? ' (from proof)' : refSuffix;toast.success(`Page ${pageIndex + 1} ${target}${suffix} render queued (${res.mode || renderOpts.mode || IMAGE_GEN_MODE.LOCAL})`);}};@@ -877,6 +886,24 @@ function PageRow({{saving ? <Loader2 size={12} className="animate-spin" /> : <Save size={12} />}Save</button>+ {(hasPrior || hasNext) ? (+ <label+ className="flex items-center gap-1 text-[11px] text-gray-400"+ title="Render this page using an adjacent page's image as a consistency reference — keeps incidental, un-described characters and the environment consistent across a continuing scene."+ >+ <span className="text-gray-500">ref</span>+ <select+ value={refPage}+ onChange={(e) => setRefPage(e.target.value)}+ className="bg-port-bg border border-port-border rounded text-[11px] text-white px-1 py-0.5"+ aria-label={`Consistency reference page for page ${pageIndex + 1}`}+ >+ <option value="">none</option>+ {hasPrior ? <option value="prior">prev page</option> : null}+ {hasNext ? <option value="next">next page</option> : null}+ </select>+ </label>+ ) : null}<buttontype="button"onClick={() => handleRender('proof')}@@ -886,7 +913,9 @@ function PageRow({? 'Save changes before rendering': proofInFlight? 'Proof render in progress…'- : 'Queue a fast proof render at the configured size'}+ : refPage+ ? `Queue a proof render using the ${refPage} page as a consistency reference`+ : 'Queue a fast proof render at the configured size'}>{(renderingProof || proofInFlight) ? <Loader2 size={12} className="animate-spin" /> : <ImageIcon size={12} />}Proofdiff --git a/server/routes/pipeline/issues.js b/server/routes/pipeline/issues.jsindex a67d60a09f..4ada435316 100644--- a/server/routes/pipeline/issues.js+++ b/server/routes/pipeline/issues.js@@ -230,6 +230,11 @@ const comicPageRenderSchema = z.object({// See covers.js's makeCoverRenderSchema for the proof/final semantics.target: z.enum(COMIC_PAGE_VARIANTS).optional().default('proof'),useProofAsBase: z.boolean().optional().default(false),+ // Consistency reference: re-render this page using an adjacent ('prior'/'next')+ // or explicit (0-based index) already-rendered page as a reference image, so a+ // continuing scene keeps incidental/un-described characters + environment+ // consistent. Resolved + bounds-checked in enqueueVisualComicPage.+ referencePage: z.union([z.enum(['prior', 'next']), z.number().int().min(0)]).optional(),// Per-render opt-out for trained character-LoRA auto-apply (local mode).applyCharacterLoras: z.boolean().optional().default(true),}).refine(refineImagePixelCap, { message: PIXEL_CAP_MESSAGE, path: ['width'] });diff --git a/server/services/pipeline/visualStages.js b/server/services/pipeline/visualStages.jsindex 0c1d7ee797..c28fad719e 100644--- a/server/services/pipeline/visualStages.js+++ b/server/services/pipeline/visualStages.js@@ -183,6 +183,59 @@ const resolveProofInitImage = (proofImage, label) => {return resolved;};+// Consistency-reference denoise: when an ADJACENT page is passed as a reference+// (continuing the same scene so incidental, un-described characters and the+// environment stay consistent), we want the NEW page's composition to come from+// its own prompt while only borrowing identity/style from the reference. So this+// is a HIGH denoise (mostly follow the prompt) — the opposite of proof-as-base's+// 0.25 (preserve layout for an upscale). Local i2i honors it; codex passes the+// reference as an `-i` attachment (reference mode), where strength is moot.+const REFERENCE_PAGE_DEFAULT_STRENGTH = 0.8;++// Resolve an adjacent page's rendered image to a gallery path for use as a+// consistency reference. Prefers the final render, falls back to the proof.+// Throws a clear 400 when that page hasn't been rendered yet.+const resolvePageReferenceImage = (refPage, label) => {+ const name = refPage?.finalImage?.filename || refPage?.proofImage?.filename;+ if (typeof name !== 'string' || !name) {+ throw new ServerError(+ `Cannot use ${label} as a consistency reference: it has no rendered image yet — render that page first.`,+ { status: 400, code: 'PIPELINE_COMIC_REFERENCE_MISSING' },+ );+ }+ const resolved = resolveGalleryImage(name, { mustExist: false });+ if (!resolved) {+ throw new ServerError(+ `Reference image path escaped the gallery for ${label}: ${name}`,+ { status: 400, code: 'PIPELINE_COMIC_REFERENCE_NOT_FOUND' },+ );+ }+ return resolved;+};++// Resolve the `referencePage` option ('prior' | 'next' | <0-based index>) to a+// concrete page index, or null when unset. Pure + bounds-checked against the+// page count; throws a clear 400 for an out-of-range request (prior on page 1,+// next on the last page, or an explicit index that doesn't exist).+export function resolveReferencePageIndex(referencePage, pageIndex, pageCount) {+ if (referencePage == null) return null;+ let target;+ if (referencePage === 'prior') target = pageIndex - 1;+ else if (referencePage === 'next') target = pageIndex + 1;+ else if (Number.isInteger(referencePage)) target = referencePage;+ else throw new ServerError(`Invalid referencePage: ${referencePage}`, { status: 400, code: 'PIPELINE_COMIC_REFERENCE_BAD' });+ if (target === pageIndex) {+ throw new ServerError('A page cannot be its own consistency reference', { status: 400, code: 'PIPELINE_COMIC_REFERENCE_SELF' });+ }+ if (target < 0 || target >= pageCount) {+ throw new ServerError(+ `Consistency reference page ${target + 1} is out of range (have ${pageCount} page${pageCount === 1 ? '' : 's'})`,+ { status: 400, code: 'PIPELINE_COMIC_REFERENCE_RANGE' },+ );+ }+ return target;+}+const loadBibleContext = async (issueId) => {const issueChain = (async () => {const issue = await getIssue(issueId);@@ -268,14 +321,26 @@ export function composeVisualPrompt({ series, description, slugline = '', extraS// cloud-outline for thoughts), but a diffusion model treats them as more text// to letter. Map them to visual balloon-style hints so the artist still gets// the cue without the label leaking into the lettering.+// `disembodied: true` marks a modifier whose SPEAKER is NOT physically in the+// panel — a station PA, a radio voice, an off-panel shout. Without an explicit+// cue the image model gives the line a normal tailed balloon and points it at+// whoever IS drawn (e.g. JUNO's `(SPEAKERS)` PA line got attributed to a+// visible newlywed). formatBalloon turns the flag into a "do NOT tail to any+// visible character" instruction. Order matters — first match wins, so the+// broadcast/PA rule precedes the generic transmission rule.const BALLOON_STYLE_HINTS = [- { test: /\b(EARPIECE|RADIO|COMM|TRANSMISSION|PHONE|HOLO|HOLOGRAM|INTERCOM|SPEAKER|TV|MONITOR|VIDEO)\b/, hint: 'jagged electronic/transmission balloon with bolt-shaped tail' },+ { test: /\b(SPEAKERS?|P\.?A\.?|BROADCAST|ANNOUNCE(?:D|S|MENT)?|ANNOUNCER|LOUDSPEAKER|OVERHEAD|INTERCOM|TANNOY|PAGING|STATIONWIDE|SHIPWIDE)\b/, hint: 'jagged electronic broadcast/PA balloon, no tail (disembodied announcement from an overhead source)', disembodied: true },+ // Transmission devices are AMBIGUOUS — the speaker may be a visible character+ // talking into the device, or a remote voice — so this gets the electronic+ // style WITHOUT the "not in panel" claim (that's reserved for unambiguous+ // broadcast/off-panel/V.O. above).+ { test: /\b(EARPIECE|RADIO|COMMS?|TRANSMISSION|PHONE|HOLO|HOLOGRAM|TV|MONITOR|VIDEO|COMLINK|CHANNEL)\b/, hint: 'jagged electronic/transmission balloon with bolt-shaped tail' },+ { test: /\b(OFF[\- ]?PANEL|OFF[\- ]?SCREEN|O\.?S\.?|O\.?P\.?)\b/, hint: 'off-panel balloon with the tail pointing past the panel border', disembodied: true },+ { test: /\b(NARRATION|VOICE[\- ]?OVER|V\.?O\.?)\b/, hint: 'rectangular narration caption rather than a speech balloon', disembodied: true },{ test: /\b(WHISPER(?:ED|S|ING)?|SOTTO|HUSHED|QUIET)\b/, hint: 'dashed-outline whisper balloon' },{ test: /\b(SHOUT(?:ED|S|ING)?|YELL(?:ED|S|ING)?|SCREAM(?:ED|S|ING)?|ANGRY|BURST)\b/, hint: 'spiked/burst-shaped balloon' },{ test: /\b(THOUGHT|THINKING|INTERNAL)\b/, hint: 'cloud-outline thought balloon with chain-of-bubbles tail' },{ test: /\b(SING(?:S|ING)?|SONG|MUSICAL)\b/, hint: 'wavy musical balloon with musical-note flourish' },- { test: /\b(OFF[\- ]?PANEL|OFF[\- ]?SCREEN|O\.?S\.?|O\.?P\.?)\b/, hint: 'off-panel balloon with tail pointing past the panel border' },- { test: /\b(NARRATION|VOICE[\- ]?OVER|V\.?O\.?)\b/, hint: 'rectangular narration caption rather than a speech balloon' },];/**@@ -296,12 +361,17 @@ function formatBalloon(character, line) {const speaker = (m ? m[1] : raw).trim() || 'CHAR';const modifier = m ? m[2].trim() : '';const cleanText = text.replace(/^"+|"+$/g, '').trim();- const styleHint = modifier- ? BALLOON_STYLE_HINTS.find((h) => h.test.test(modifier.toUpperCase()))?.hint+ const styleEntry = modifier+ ? BALLOON_STYLE_HINTS.find((h) => h.test.test(modifier.toUpperCase())) || null: null;- const attribution = styleHint- ? `(spoken by ${speaker}; ${styleHint})`- : `(spoken by ${speaker})`;+ // A disembodied speaker (PA, radio, off-panel, V.O.) is NOT in the panel, so+ // spell that out — otherwise the model letters a normal balloon and tails it+ // to whoever IS drawn, mis-attributing the line (the JUNO `(SPEAKERS)` bug).+ const attribution = styleEntry?.disembodied+ ? `(spoken by ${speaker}, who is NOT visible in this panel — render as a ${styleEntry.hint}; do NOT attach the balloon tail to any visible character)`+ : styleEntry+ ? `(spoken by ${speaker}; ${styleEntry.hint})`+ : `(spoken by ${speaker})`;// Terminator handled here so endPunct() at the call site doesn't have to// navigate the closing paren — we always end with `).`.return `Speech balloon reads: "${cleanText}" ${attribution}.`;@@ -773,13 +843,25 @@ export async function enqueueVisualComicPage(issueId, options = {}) {const mode = resolveMode(options, settings);const variant = resolveVariant(options.target);- const fromProof = variant === 'final' && options.useProofAsBase === true;- const initImagePath = fromProof- ? resolveProofInitImage(page.proofImage, `page ${pageIndex + 1}`)- : null;- const initImageStrength = fromProof- ? (Number.isFinite(options.initImageStrength) ? options.initImageStrength : PROOF_AS_BASE_DEFAULT_STRENGTH)- : undefined;++ // Consistency reference: pass an ADJACENT (or explicit) already-rendered page+ // as a reference so a continuing scene keeps its incidental, un-described+ // characters and environment consistent (the "two newlyweds drift between+ // pages" problem). Takes precedence over proof-as-base — both set the init+ // image, and an explicit cross-page reference is the stronger intent.+ const referencePageIndex = resolveReferencePageIndex(options.referencePage, pageIndex, pages.length);+ const fromReference = referencePageIndex != null;+ const fromProof = !fromReference && variant === 'final' && options.useProofAsBase === true;+ const initImagePath = fromReference+ ? resolvePageReferenceImage(pages[referencePageIndex], `page ${referencePageIndex + 1}`)+ : fromProof+ ? resolveProofInitImage(page.proofImage, `page ${pageIndex + 1}`)+ : null;+ const initImageStrength = fromReference+ ? (Number.isFinite(options.initImageStrength) ? options.initImageStrength : REFERENCE_PAGE_DEFAULT_STRENGTH)+ : fromProof+ ? (Number.isFinite(options.initImageStrength) ? options.initImageStrength : PROOF_AS_BASE_DEFAULT_STRENGTH)+ : undefined;// Build a free-text haystack from every panel's prose (description +// caption + sfx). Dialogue lines feed character matching via CAPS names@@ -831,9 +913,9 @@ export async function enqueueVisualComicPage(issueId, options = {}) {prompt, world, settings, mode,options: { ...options, initImagePath, initImageStrength, ...loraRenderOptions(characterLoras) },owner: buildComicPagesOwner({ issueId, target: 'page', pageIndex, variant }),- logLine: `📄 Pipeline comic page — issue=${issueId.slice(0, 8)} page=${pageIndex + 1} panels=${page.panels.length} variant=${variant}${fromProof ? ' (from proof)' : ''}`,+ logLine: `📄 Pipeline comic page — issue=${issueId.slice(0, 8)} page=${pageIndex + 1} panels=${page.panels.length} variant=${variant}${fromProof ? ' (from proof)' : ''}${fromReference ? ` (ref page ${referencePageIndex + 1})` : ''}`,});- return { jobId, mode, prompt, pageIndex, variant, fromProof };+ return { jobId, mode, prompt, pageIndex, variant, fromProof, fromReference, referencePageIndex };}/**diff --git a/server/services/pipeline/visualStages.test.js b/server/services/pipeline/visualStages.test.jsindex e9c7b83fb8..ef7f2e2ce0 100644--- a/server/services/pipeline/visualStages.test.js+++ b/server/services/pipeline/visualStages.test.js@@ -96,6 +96,7 @@ const {generateStoryboardSceneImagePrompts,assertCharacterAppearancesResolve,enqueueVisualImage,+ resolveReferencePageIndex,} = await import('./visualStages.js');// The universeBuilder mock's getUniverse is auto-captured here so individual@@ -192,6 +193,57 @@ describe('composeComicPagePrompt', () => {expect(prompt).toMatch(/NEVER letter the speaker's name/i);});+ it('renders a (SPEAKERS) PA line as a disembodied broadcast balloon not tailed to a visible character', () => {+ // The JUNO bug: a station-AI PA line marked `(SPEAKERS)` was getting a plain+ // balloon and the model tailed it to whoever was drawn (a newlywed).+ const page = {+ panels: [{+ description: 'Two newlyweds duck under exploding pearl light-orbs above a honeymoon bed.',+ dialogue: [{ character: 'JUNO (SPEAKERS)', line: 'Celebratory projectile beverages are permitted.' }],+ }],+ };+ const prompt = composeComicPagePrompt({ series: SERIES, page, pageNumber: 1 });+ expect(prompt).toMatch(/Speech balloon reads: "Celebratory projectile beverages are permitted\."/);+ expect(prompt).toMatch(/spoken by JUNO, who is NOT visible in this panel/);+ expect(prompt).toMatch(/do NOT attach the balloon tail to any visible character/);+ expect(prompt).toMatch(/broadcast\/PA balloon/);+ // The lettered text must not carry the `(SPEAKERS)` label.+ const balloonTexts = [...prompt.matchAll(/Speech balloon reads: "([^"]+)"/g)].map((m) => m[1]);+ expect(balloonTexts).toHaveLength(1);+ expect(balloonTexts[0]).not.toMatch(/SPEAKERS/);+ });++ it('treats a transmission-device modifier (EARPIECE) as electronic but NOT as off-panel', () => {+ // EARPIECE is ambiguous (a visible character may be speaking into it), so it+ // gets the electronic style WITHOUT the "not visible" disembodied claim.+ const page = { panels: [{ description: 'x', dialogue: [{ character: 'LINA (EARPIECE)', line: 'Copy that.' }] }] };+ const prompt = composeComicPagePrompt({ series: SERIES, page, pageNumber: 1 });+ expect(prompt).toMatch(/\(spoken by LINA; jagged electronic\/transmission balloon[^)]*\)/);+ expect(prompt).not.toMatch(/LINA, who is NOT visible/);+ });++ describe('resolveReferencePageIndex', () => {+ it("maps 'prior'/'next' relative to the current page", () => {+ expect(resolveReferencePageIndex('prior', 1, 3)).toBe(0);+ expect(resolveReferencePageIndex('next', 0, 3)).toBe(1);+ });+ it('accepts an explicit 0-based index', () => {+ expect(resolveReferencePageIndex(2, 0, 3)).toBe(2);+ });+ it('returns null when unset', () => {+ expect(resolveReferencePageIndex(undefined, 0, 3)).toBeNull();+ expect(resolveReferencePageIndex(null, 0, 3)).toBeNull();+ });+ it('throws out of range (prior on first page, next on last)', () => {+ expect(() => resolveReferencePageIndex('prior', 0, 3)).toThrow(/out of range/);+ expect(() => resolveReferencePageIndex('next', 2, 3)).toThrow(/out of range/);+ expect(() => resolveReferencePageIndex(5, 0, 3)).toThrow(/out of range/);+ });+ it('refuses a page referencing itself', () => {+ expect(() => resolveReferencePageIndex(1, 1, 3)).toThrow(/its own consistency reference/);+ });+ });+it('uses singular "panel" wording for a one-panel splash page', () => {const splash = { panels: [{ description: 'Hero stands silhouetted against the sunrise.' }] };const prompt = composeComicPagePrompt({ series: SERIES, page: splash, pageNumber: 5 });