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 (codex): pause incomplete visual drafts, match only drawable comic text

[._.]/ Adam Eivy4b13666dc1ed
diff --git a/server/services/pipeline/canonReadiness.js b/server/services/pipeline/canonReadiness.js
index c495768220..443d4c607d 100644
--- a/server/services/pipeline/canonReadiness.js
+++ b/server/services/pipeline/canonReadiness.js
@@ -23,7 +23,11 @@
import { getIssue, listIssues } from './issues.js';
import { getSeries } from './series.js';
import { getSeriesCanon } from './seriesCanon.js';
-import { matchCharactersInText, matchPlacesInText, matchObjectsInText } from '../../lib/scenePrompt.js';
+import { parseComicScript } from '../../lib/comicScriptParser.js';
+import {
+ matchCharactersInText, matchPlacesInText, matchObjectsInText,
+ matchSceneCharacters, buildCharByKey,
+} from '../../lib/scenePrompt.js';
// Below this many characters a description is "thin" — present but too sparse to
// reliably render from. Advisory only; `none` (no description at all) is the
@@ -60,54 +64,120 @@ export function gradeCanonDescription(descOf, entry, thinChars = CANON_THIN_CHAR
return 'sufficient';
}
-/**
- * PURE: grade every canon noun that appears in `text`. Returns
- * `{ referenced, none[], thin[], ready }`. `none`/`thin` entries carry
- * `{ id, name, kind, locked }`. No I/O — caller supplies the text + canon.
- */
-export function gradeReferencedNouns(text, canon, thinChars = CANON_THIN_CHARS) {
+// Grade pre-matched entries per kind into none/thin buckets.
+function gradeMatched({ characters = [], places = [], objects = [] }, thinChars) {
const none = [];
const thin = [];
let referenced = 0;
- if (text && text.trim()) {
- for (const { kind, listKey, match, descOf } of KINDS) {
- const list = Array.isArray(canon?.[listKey]) ? canon[listKey] : [];
- for (const entry of match(text, list)) {
- referenced += 1;
- const grade = gradeCanonDescription(descOf, entry, thinChars);
- if (grade === 'none') none.push({ id: entry.id, name: entry.name, kind, locked: entry.locked === true });
- else if (grade === 'thin') thin.push({ id: entry.id, name: entry.name, kind, locked: entry.locked === true });
+ const descOfKind = { character: KINDS[0].descOf, place: KINDS[1].descOf, object: KINDS[2].descOf };
+ const push = (entry, kind) => {
+ referenced += 1;
+ const grade = gradeCanonDescription(descOfKind[kind], entry, thinChars);
+ if (grade === 'none') none.push({ id: entry.id, name: entry.name, kind, locked: entry.locked === true });
+ else if (grade === 'thin') thin.push({ id: entry.id, name: entry.name, kind, locked: entry.locked === true });
+ };
+ for (const c of characters) push(c, 'character');
+ for (const p of places) push(p, 'place');
+ for (const o of objects) push(o, 'object');
+ return { referenced, none, thin, ready: none.length === 0 };
+}
+
+/**
+ * PURE: grade every canon noun that appears in free `text`. Used for the TV /
+ * fallback path (whole teleplay/prose). For comics use
+ * `gradeComicReferencedNouns`, which matches only the drawable panel text.
+ */
+export function gradeReferencedNouns(text, canon, thinChars = CANON_THIN_CHARS) {
+ if (!text || !text.trim()) return { referenced: 0, none: [], thin: [], ready: true };
+ return gradeMatched({
+ characters: matchCharactersInText(text, canon?.characters || []),
+ places: matchPlacesInText(text, canon?.places || []),
+ objects: matchObjectsInText(text, canon?.objects || []),
+ }, thinChars);
+}
+
+// A panel-body line like `MAGGIE: Kai called.` or `CAPTION: Years later.` —
+// captures the leading ALL-CAPS label and the body. parseComicScript folds
+// these into the panel `description` rather than a structured dialogue[], so we
+// classify them here: the body is spoken/caption text (NOT drawn), the label is
+// a potential speaker.
+const PANEL_LABEL_LINE = /^\s*([A-Z][A-Z0-9 .'’_-]{0,30})(?:\s*\([^)]*\))?:\s*\S/;
+// Labels that are not characters (their "speaker" must not count as drawn).
+const NON_SPEAKER_LABELS = new Set(['CAPTION', 'SFX', 'SOUND', 'NARRATION', 'NARRATOR', 'TITLE', 'NOTE', 'LETTERING', 'TEXT']);
+
+/**
+ * PURE: grade canon nouns that appear where they'd actually be DRAWN in a comic.
+ * Splits each panel's text into visual ACTION lines vs `LABEL:` dialogue/caption
+ * lines: characters/places/objects are matched against the action lines only,
+ * plus characters who SPEAK (a dialogue label or a structured dialogue speaker).
+ * So a character merely named inside someone's dialogue body ("Kai called") is
+ * NOT treated as a drawn reference, while a character shown in a panel or
+ * speaking a line is.
+ */
+export function gradeComicReferencedNouns(comicScript, canon, thinChars = CANON_THIN_CHARS) {
+ const { pages } = parseComicScript(comicScript || '');
+ const actionLines = [];
+ const speakers = [];
+ const consume = (text) => {
+ for (const line of String(text || '').split('\n')) {
+ const m = line.match(PANEL_LABEL_LINE);
+ if (m) {
+ const label = m[1].trim();
+ if (!NON_SPEAKER_LABELS.has(label.toUpperCase())) speakers.push(label);
+ // the body of a dialogue/caption line is spoken/overlaid text, not drawn
+ } else {
+ actionLines.push(line);
+ }
+ }
+ };
+ for (const pg of Array.isArray(pages) ? pages : []) {
+ for (const pa of Array.isArray(pg.panels) ? pg.panels : []) {
+ consume(pa.description);
+ for (const d of Array.isArray(pa.dialogue) ? pa.dialogue : []) {
+ if (d.character) speakers.push(d.character);
}
}
}
- return { referenced, none, thin, ready: none.length === 0 };
+ const haystack = actionLines.join('\n');
+ const chars = canon?.characters || [];
+ // Characters drawn = named in panel action ∪ speaking a line.
+ const drawn = new Map();
+ for (const c of matchCharactersInText(haystack, chars)) drawn.set(c.id || c.name, c);
+ for (const c of matchSceneCharacters(speakers, buildCharByKey(chars))) drawn.set(c.id || c.name, c);
+ return gradeMatched({
+ characters: [...drawn.values()],
+ places: matchPlacesInText(haystack, canon?.places || []),
+ objects: matchObjectsInText(haystack, canon?.objects || []),
+ }, thinChars);
}
-// The text where nouns are actually depicted, by target format. Comic targets
-// draw from the comic-script panel descriptions; TV from the teleplay. Fall
-// back to prose only when the visual source is empty so a not-yet-adapted issue
-// can still be sanity-checked.
-function visualSourceText(issue, series) {
- const fmt = series?.targetFormat || 'comic+tv';
- const comic = issue.stages?.comicScript?.output || '';
- const tele = issue.stages?.teleplay?.output || '';
- const prose = issue.stages?.prose?.output || '';
- if (fmt === 'tv') return tele || prose;
- return comic || tele || prose;
+// Fallback free-text source when there's no parseable comic script: TV draws
+// from the teleplay, anything else from teleplay-or-prose. (Comic targets with
+// a comic script go through gradeComicReferencedNouns, not this.)
+function fallbackSourceText(issue) {
+ return issue.stages?.teleplay?.output || issue.stages?.prose?.output || '';
}
/**
* Canon readiness for one issue. Pass `canon`/`series` to avoid re-reads when
* checking many issues. Returns
* `{ issueId, number, title, referenced, none[], thin[], ready }`.
+ *
+ * Comic targets with a comic script grade against the DRAWABLE text only (panel
+ * descriptions + dialogue speakers) so an off-page character named only in
+ * narration/dialogue body isn't a false blocker; everything else grades the
+ * teleplay/prose.
*/
export async function checkIssueCanonReadiness(issueId, { canon = null, series = null, thinChars = CANON_THIN_CHARS } = {}) {
const issue = await getIssue(issueId);
const ser = series || await getSeries(issue.seriesId).catch(() => null);
const c = canon || (ser ? await getSeriesCanon(ser).catch(() => null) : null) || { characters: [], places: [], objects: [] };
- const text = visualSourceText(issue, ser);
- const { referenced, none, thin, ready } = gradeReferencedNouns(text, c, thinChars);
- return { issueId, number: issue.number, title: issue.title, referenced, none, thin, ready };
+ const fmt = ser?.targetFormat || 'comic+tv';
+ const comic = (issue.stages?.comicScript?.output || '').trim();
+ const graded = (fmt !== 'tv' && comic)
+ ? gradeComicReferencedNouns(comic, c, thinChars)
+ : gradeReferencedNouns(fallbackSourceText(issue), c, thinChars);
+ return { issueId, number: issue.number, title: issue.title, referenced: graded.referenced, none: graded.none, thin: graded.thin, ready: graded.ready };
}
/**
diff --git a/server/services/pipeline/canonReadiness.test.js b/server/services/pipeline/canonReadiness.test.js
index 8d1de9bf40..007fac8a0e 100644
--- a/server/services/pipeline/canonReadiness.test.js
+++ b/server/services/pipeline/canonReadiness.test.js
@@ -104,6 +104,25 @@ describe('checkIssueCanonReadiness (matches the visual source)', () => {
expect(report.none.map((n) => n.name)).toContain('Aria');
});
+ it('does not flag a character named only in dialogue body (not drawn)', async () => {
+ canon = { characters: [
+ { id: 'c1', name: 'Maggie', physicalDescription: '' },
+ { id: 'c2', name: 'Kai', physicalDescription: '' },
+ ], places: [], objects: [] };
+ const issueId = await seedIssue({ comicScript: 'PAGE 1\nPANEL 1\nMaggie sits alone at her terminal.\nMAGGIE: Kai called about the backdoor.' });
+ const report = await checkIssueCanonReadiness(issueId);
+ const names = report.none.map((n) => n.name);
+ expect(names).toContain('Maggie'); // drawn (in action + speaks) and undescribed
+ expect(names).not.toContain('Kai'); // only named inside dialogue body → not drawn
+ });
+
+ it('flags a character who speaks a line (drawn) when undescribed', async () => {
+ canon = { characters: [{ id: 'c1', name: 'Kai', physicalDescription: '' }], places: [], objects: [] };
+ const issueId = await seedIssue({ comicScript: 'PAGE 1\nPANEL 1\nTwo figures in shadow.\nKAI: I built it.' });
+ const report = await checkIssueCanonReadiness(issueId);
+ expect(report.none.map((n) => n.name)).toContain('Kai');
+ });
+
it('does NOT flag an off-page character (in prose only, not in panels)', async () => {
// Aria appears only in prose narration, never in the comic-script panels.
canon = { characters: [{ id: 'c1', name: 'Aria', physicalDescription: '' }], places: [], objects: [] };
diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.js
index 2aa27885de..c510f3b779 100644
--- a/server/services/pipeline/seriesAutopilot.js
+++ b/server/services/pipeline/seriesAutopilot.js
@@ -578,7 +578,6 @@ async function enqueuePageDraft(issueId, pageIndex) {
}
async function runVisualDraft(sId, issueId, record) {
- record.runState.visualDrafted.add(issueId);
let issue = await getIssue(issueId);
let cp = issue.stages?.comicPages;
@@ -606,8 +605,15 @@ async function runVisualDraft(sId, issueId, record) {
const pageCount = Array.isArray(cp?.pages) ? cp.pages.length : 0;
if (pageCount === 0) {
- broadcast(sId, { type: 'step:skip', kind: 'visualDraft', issueId, reason: 'no comic pages to render (script did not parse)' });
- return {};
+ // Nothing to draw — the comic script never parsed into pages. This is a real
+ // production blocker, so pause for review rather than marking the issue done.
+ await fileGap(record, sId, {
+ gapKind: 'visual-no-pages',
+ issueId,
+ summary: 'Cannot draft comic art — the comic script did not parse into any pages. Fix the comicScript stage (PAGE/PANEL structure) first.',
+ context: `issueId=${issueId}`,
+ });
+ return { pause: true, reason: `issue ${issue.number ?? issueId} has no comic pages to render — the script did not parse`, residual: [{ severity: 'high', location: `issue ${issue.number ?? '?'} / comicPages`, problem: 'comic script did not parse into pages' }] };
}
// Budget-gate + bill each render individually — a comic is many GPU jobs.
@@ -656,6 +662,20 @@ async function runVisualDraft(sId, issueId, record) {
const r = await enqueueOne(`page ${i + 1}`, () => enqueuePageDraft(issueId, i));
if (r.pause) return r;
}
+ // Only consider the issue drafted once every drawable slot is actually
+ // enqueued. If a render errored (e.g. an un-renderable page), visualReady is
+ // still false — mark it attempted so the resolver doesn't re-loop, but pause
+ // for review instead of letting the run report a complete draft.
+ const after = await getIssue(issueId);
+ if (!visualReady(after)) {
+ record.runState.visualDrafted.add(issueId);
+ return {
+ pause: true,
+ reason: `issue ${after.number ?? issueId} could not be fully drafted — some cover/page renders did not enqueue`,
+ residual: [{ severity: 'high', location: `issue ${after.number ?? '?'} / comicPages`, problem: 'not every drawable cover/page render was enqueued (likely an un-renderable page or missing panels)' }],
+ };
+ }
+ record.runState.visualDrafted.add(issueId);
return {};
}
diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.js
index 428e196c3a..b45303bb93 100644
--- a/server/services/pipeline/seriesAutopilot.test.js
+++ b/server/services/pipeline/seriesAutopilot.test.js
@@ -432,6 +432,16 @@ describe('autopilot conductor', () => {
expect(autopilot.__testing.runs.get(seriesId)?.lastPayload?.type).toBe('complete');
});
+ it('pauses visual draft (no art) when the comic script does not parse into pages', async () => {
+ const { seriesId } = await seedComplete({ script: 'just prose, no comic pages here' });
+ await autopilot.startSeriesAutopilot(seriesId, { includeVisual: true });
+ await waitFor(runFinished(seriesId));
+ const last = autopilot.__testing.runs.get(seriesId)?.lastPayload;
+ expect(last?.type).toBe('paused');
+ expect(last?.scope).toBe('visualDraft');
+ expect(visualSpies.enqueueComicCover).not.toHaveBeenCalled();
+ });
+
it('does not render visuals when includeVisual is false', async () => {
const { seriesId } = await seedComplete();
await autopilot.startSeriesAutopilot(seriesId, { includeVisual: false });