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): preserve dialogue on the canonical path via LLM+overlay hybrid

[._.]/ Adam Eivy0d72d443be92
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 2102ba50d8..58997ffa05 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -24,7 +24,7 @@
## Storyboards
-- **[issue-1552] Storyboard scenes now line up exactly with comic-page scenes — and "Generate scenes" is instant when a beat sheet exists.** The beat sheet's canonical `## Scenes` list is now the single source of truth for storyboards too: when you click "Generate scenes from prose/teleplay", PortOS first maps the storyboard scenes straight from that numbered scene list — same scene numbers and `INT./EXT.` sluglines as the comic pages — instead of asking the model to re-derive scene boundaries. So "Scene 2" is the same Scene 2 across the beat sheet, prose, teleplay, comic script, comic pages, and storyboards, and the mapping costs no LLM call. Issues with no canonical scene list fall back to the existing model-driven extraction exactly as before. The TV teleplay stage also now reuses the canonical scene numbers and sluglines verbatim when the source material carries them, so teleplays stay aligned with every other adaptation.
+- **[issue-1552] Storyboard scenes now line up exactly with comic-page scenes.** The beat sheet's canonical `## Scenes` list is now the single source of truth for storyboard scene numbers and sluglines too. When you click "Generate scenes from prose/teleplay" on an issue whose beat sheet carries a `## Scenes` list, PortOS still extracts the rich per-scene content (dialogue, visual prompts, shots) from the prose/teleplay — so downstream audio voice-over and image/video generation keep everything they need — but overlays the canonical scene numbers and `INT./EXT.` sluglines on top, so "Scene 2" is the same Scene 2 across the beat sheet, prose, teleplay, comic script, comic pages, and storyboards. (For an issue with a scene list but no prose/teleplay yet, the scenes come straight from the list.) Issues with no canonical scene list fall back to the existing model-driven extraction exactly as before. The TV teleplay stage also now reuses the canonical scene numbers and sluglines verbatim when the source material carries them, so teleplays stay aligned with every other adaptation.
## ChatGPT import
diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.js
index ac7b338bf9..81643c7429 100644
--- a/server/routes/pipeline.test.js
+++ b/server/routes/pipeline.test.js
@@ -1072,9 +1072,21 @@ describe('pipeline routes', () => {
spy.mockRestore();
});
- it('POST /issues/:id/stages/storyboards/extract-scenes prefers the beat sheet ## Scenes list (no LLM call)', async () => {
+ it('POST /issues/:id/stages/storyboards/extract-scenes overlays the canonical numbering on LLM scenes (hybrid: alignment + dialogue preserved)', async () => {
const extractor = await import('../lib/sceneExtractor.js');
- const spy = vi.spyOn(extractor, 'extractScenes');
+ // The LLM extraction supplies rich fields (dialogue/visualPrompt); the
+ // canonical list overlays its numbering/sluglines. The LLM may number /
+ // slug the scenes differently — the overlay must win on identity.
+ const spy = vi.spyOn(extractor, 'extractScenes').mockResolvedValue({
+ extracted: {
+ title: null, logline: null,
+ scenes: [
+ { id: 'scene-99', heading: 'LLM heading A', slugline: 'INT. WRONG — DAY', visualPrompt: 'rooftop vista', dialogue: [{ character: 'LINA', line: 'Up here.' }] },
+ { id: 'scene-98', heading: 'LLM heading B', slugline: 'INT. ALSO WRONG', visualPrompt: 'kitchen argument', dialogue: [{ character: 'MARA', line: 'You lied.' }] },
+ ],
+ },
+ runId: 'run-hybrid', providerId: 'mock', model: 'mock-model',
+ });
const app = makeApp();
const ser = await request(app).post('/api/pipeline/series').send({ name: 'S', universeId: 'u-test' });
@@ -1091,8 +1103,48 @@ describe('pipeline routes', () => {
'2. Scene 2 — INT. KITCHEN — NIGHT: the confrontation',
].join('\n'),
},
- // teleplay present too — the beat sheet still wins.
- teleplay: { status: 'ready', output: '## TEASER\n\n**INT. ELSEWHERE — DAY**\n\nIgnored.' },
+ teleplay: { status: 'ready', output: '## TEASER\n\n**INT. ROOFTOP — DUSK**\n\nThey meet.' },
+ },
+ });
+
+ const r = await request(app)
+ .post(`/api/pipeline/issues/${iss.body.id}/stages/storyboards/extract-scenes`)
+ .send({ from: 'teleplay' });
+
+ expect(r.status).toBe(200);
+ expect(r.body.usedCanonicalList).toBe(true);
+ expect(r.body.sourceKind).toBe('teleplay');
+ expect(r.body.runId).toBe('run-hybrid');
+ expect(r.body.sceneCount).toBe(2);
+ // Canonical numbering/sluglines win (the LLM's scene-99/wrong sluglines lose).
+ expect(r.body.stage.scenes[0].id).toBe('scene-01');
+ expect(r.body.stage.scenes[0].heading).toBe('Scene 1 — EXT. ROOFTOP — DUSK');
+ expect(r.body.stage.scenes[0].slugline).toBe('EXT. ROOFTOP — DUSK');
+ expect(r.body.stage.scenes[1].slugline).toBe('INT. KITCHEN — NIGHT');
+ // The LLM's rich fields ride along — dialogue is preserved (audio VO needs it).
+ expect(r.body.stage.scenes[0].dialogue).toEqual([{ character: 'LINA', line: 'Up here.' }]);
+ expect(r.body.stage.scenes[1].dialogue).toEqual([{ character: 'MARA', line: 'You lied.' }]);
+ // description comes from the LLM visualPrompt, not the beats clause, since one exists.
+ expect(r.body.stage.scenes[0].description).toBe('rooftop vista');
+ expect(r.body.stage.status).toBe('ready');
+ expect(spy).toHaveBeenCalledTimes(1);
+ spy.mockRestore();
+ });
+
+ it('POST /issues/:id/stages/storyboards/extract-scenes uses the canonical list alone when there is no source text (deterministic, no LLM)', async () => {
+ const extractor = await import('../lib/sceneExtractor.js');
+ const spy = vi.spyOn(extractor, 'extractScenes');
+
+ const app = makeApp();
+ const ser = await request(app).post('/api/pipeline/series').send({ name: 'S', universeId: 'u-test' });
+ const iss = await request(app).post(`/api/pipeline/series/${ser.body.id}/issues`).send({ title: 'I' });
+ // Beat sheet has a canonical list but NO teleplay/prose to extract from.
+ await request(app).patch(`/api/pipeline/issues/${iss.body.id}`).send({
+ stages: {
+ idea: {
+ status: 'ready',
+ output: '# Beat sheet\n\n## Scenes\n1. Scene 1 — EXT. ROOFTOP — DUSK: the hook\n2. Scene 2 — INT. KITCHEN — NIGHT: the confrontation',
+ },
},
});
@@ -1105,16 +1157,12 @@ describe('pipeline routes', () => {
expect(r.body.sourceKind).toBe('beat-sheet');
expect(r.body.runId).toBeNull();
expect(r.body.sceneCount).toBe(2);
- // Numbers/sluglines map 1:1 from the canonical list.
expect(r.body.stage.scenes[0].heading).toBe('Scene 1 — EXT. ROOFTOP — DUSK');
expect(r.body.stage.scenes[0].slugline).toBe('EXT. ROOFTOP — DUSK');
- expect(r.body.stage.scenes[1].slugline).toBe('INT. KITCHEN — NIGHT');
- // description seeds from the beats clause (summary) so the scene is renderable.
+ // No source to extract dialogue from — description seeds from the beats clause.
expect(r.body.stage.scenes[0].description).toBe('the hook');
- expect(r.body.stage.scenes[1].description).toBe('the confrontation');
- expect(r.body.stage.scenes[0].imageJobId).toBeNull();
- expect(r.body.stage.status).toBe('ready');
- // The deterministic path never reaches the LLM extractor.
+ expect(r.body.stage.scenes[0].dialogue).toEqual([]);
+ // No source → no LLM call.
expect(spy).not.toHaveBeenCalled();
spy.mockRestore();
});
diff --git a/server/routes/pipeline/issues.js b/server/routes/pipeline/issues.js
index 587efd4804..922b220a7f 100644
--- a/server/routes/pipeline/issues.js
+++ b/server/routes/pipeline/issues.js
@@ -475,95 +475,113 @@ router.post('/issues/:id/stages/storyboards/extract-scenes', asyncHandler(async
// Adapt a canonical scene to the pipeline storyboards UI shape: alias
// `visualPrompt → description` (the textarea binding) and reset the per-scene
// image-gen job fields. Rich fields (heading/summary/dialogue/...) ride along.
- // Fall back to the scene `summary` when there's no visualPrompt so the
- // beat-sheet path (which carries the beats clause as summary, not a visual
- // prompt) still seeds a non-empty description — the refine/image/video paths
- // require one, so an empty description would leave those scenes un-renderable.
+ // Fall back to the scene `summary` when there's no visualPrompt so a scene
+ // that only carries the beats clause (the canonical-only case below) still
+ // seeds a non-empty description — the refine/image/video paths require one.
const toStoryboardScene = (s) => ({ ...s, description: s.visualPrompt || s.summary || '', imageJobId: null, prompt: null });
- // Prefer the beat sheet's canonical `## Scenes` list when present (#1552):
- // it's deterministic, free (no LLM), and guarantees `storyboards.scenes`
- // numbers/sluglines match the comic pages' (both inherit the same canonical
- // list). Fall back to the LLM slugline-parse path only when no list exists.
+ // The beat sheet's canonical `## Scenes` list (#1552) is the single source of
+ // truth for scene numbers + sluglines across every adaptation, so when it
+ // exists we use it to ALIGN the storyboards scenes — guaranteeing their
+ // numbers/sluglines match the comic pages'. But the list is sparse (no
+ // dialogue / visual prompts / shots), and downstream stages need that rich
+ // data — audio voice-over is built from `storyboards.scenes[].dialogue`. So
+ // we still run the LLM extraction over the source text to get the rich fields,
+ // then OVERLAY the canonical numbering/sluglines onto it (hybrid). Only when
+ // there's no source text to extract from do we fall back to the canonical list
+ // alone (deterministic, no dialogue — but there's nothing to extract it from).
const canonicalScenes = scenesFromBeatSheet(issue.stages?.idea?.output || '');
- if (canonicalScenes.length > 0) {
- const storyboardScenes = canonicalScenes.map(toStoryboardScene);
- const { issue: updatedIssue, stage } = await issuesSvc.updateStage(issue.id, 'storyboards', {
- status: 'ready',
- scenes: storyboardScenes,
- lastRunId: null,
- errorMessage: '',
- });
- return res.json({
- issue: updatedIssue,
- stage,
- runId: null,
- providerId: null,
- model: null,
- sceneCount: storyboardScenes.length,
- sourceKind: 'beat-sheet',
- usedCanonicalList: true,
- });
- }
-
const series = await seriesSvc.getSeries(issue.seriesId).catch((err) => { throw mapServiceError(err); });
const sourceKind = body.from;
const source = (issue.stages?.[sourceKind]?.output || '').trim();
- if (!source) {
+ if (!source && canonicalScenes.length === 0) {
throw new ServerError(
`Cannot extract scenes — issue's ${sourceKind} stage is empty`,
{ status: 400, code: 'PIPELINE_NO_SOURCE_FOR_SCENE_EXTRACT' },
);
}
- // Fall back to the series' configured LLM when the client doesn't pass an
- // explicit override — every Pipeline LLM action should honor the
- // provider/model picked in the issue header (which mirrors series.llm).
- // Canon lives on the linked universe (Phase B.4). Orphan series render
- // with empty canon — extractScenes can still produce scenes from the
- // source text alone, just without character/place/object grounding.
- const canon = await getSeriesCanon(series);
- // A model id is provider-specific, so only inherit the series model when the
- // effective provider is still the series provider — otherwise an override
- // provider would be paired with a foreign model id and fail (same guard as
- // the extract-canon route). When the override switches providers without
- // naming a model, leave it blank so the new provider's default resolves.
- const { provider, model } = resolveSeriesLlmOverride(series, {
- overrideProvider: body.providerOverride,
- overrideModel: body.modelOverride,
- });
- const result = await extractScenes({
- source,
- sourceKind,
- characters: canon.characters,
- places: canon.places,
- objects: canon.objects,
- work: { title: issue.title, kind: 'tv-episode' },
- series: { name: series.name, styleNotes: series.styleNotes },
- issue: { number: issue.number, title: issue.title },
- providerOverride: provider,
- modelOverride: model,
- tag: `pipeline-storyboards-extract-${sourceKind}`,
- });
+ let extractedScenes = [];
+ let runId = null;
+ let providerId = null;
+ let model = null;
+ if (source) {
+ // Fall back to the series' configured LLM when the client doesn't pass an
+ // explicit override — every Pipeline LLM action should honor the
+ // provider/model picked in the issue header (which mirrors series.llm).
+ // Canon lives on the linked universe (Phase B.4). Orphan series render
+ // with empty canon — extractScenes can still produce scenes from the
+ // source text alone, just without character/place/object grounding.
+ const canon = await getSeriesCanon(series);
+ // A model id is provider-specific, so only inherit the series model when the
+ // effective provider is still the series provider — otherwise an override
+ // provider would be paired with a foreign model id and fail (same guard as
+ // the extract-canon route). When the override switches providers without
+ // naming a model, leave it blank so the new provider's default resolves.
+ const { provider, model: resolvedModel } = resolveSeriesLlmOverride(series, {
+ overrideProvider: body.providerOverride,
+ overrideModel: body.modelOverride,
+ });
+ const result = await extractScenes({
+ source,
+ sourceKind,
+ characters: canon.characters,
+ places: canon.places,
+ objects: canon.objects,
+ work: { title: issue.title, kind: 'tv-episode' },
+ series: { name: series.name, styleNotes: series.styleNotes },
+ issue: { number: issue.number, title: issue.title },
+ providerOverride: provider,
+ modelOverride: resolvedModel,
+ tag: `pipeline-storyboards-extract-${sourceKind}`,
+ });
+ extractedScenes = result.extracted.scenes;
+ runId = result.runId;
+ providerId = result.providerId;
+ model = result.model;
+ }
- const storyboardScenes = result.extracted.scenes.map(toStoryboardScene);
+ // Overlay the canonical numbering/sluglines/headings onto the extracted scenes
+ // (matched by position) when a canonical list exists — the canonical list wins
+ // on identity/ordering while the LLM scene contributes dialogue/visualPrompt/
+ // shots/characters. Extracted scenes beyond the canonical count are dropped so
+ // the storyboards scene count matches the canonical (and comic-page) scene
+ // count; canonical scenes beyond the extracted count carry no dialogue (there
+ // was no matching extracted scene), seeding their description from the summary.
+ const usedCanonicalList = canonicalScenes.length > 0;
+ const finalScenes = usedCanonicalList
+ ? canonicalScenes.map((c, i) => {
+ // Base on the canonical scene `c` (full sanitized shape with empty
+ // dialogue/shots/characters), overlay the LLM scene's rich fields, then
+ // re-assert canonical identity (id/heading/slugline) so the canonical
+ // numbering always wins. When there's no matching extracted scene
+ // (`ext` is {}), the result is just `c` — empty dialogue, summary-seeded
+ // description.
+ const ext = extractedScenes[i] || {};
+ return { ...c, ...ext, id: c.id, heading: c.heading, slugline: c.slugline, summary: ext.summary || c.summary };
+ })
+ : extractedScenes;
+
+ const storyboardScenes = finalScenes.map(toStoryboardScene);
const { issue: updatedIssue, stage } = await issuesSvc.updateStage(issue.id, 'storyboards', {
status: storyboardScenes.length ? 'ready' : 'empty',
scenes: storyboardScenes,
- lastRunId: result.runId,
+ lastRunId: runId,
errorMessage: '',
});
res.json({
issue: updatedIssue,
stage,
- runId: result.runId,
- providerId: result.providerId,
- model: result.model,
+ runId,
+ providerId,
+ model,
sceneCount: storyboardScenes.length,
- sourceKind,
- usedCanonicalList: false,
+ // 'beat-sheet' when the response is purely the canonical list (no source to
+ // extract from); otherwise the LLM source stage the rich fields came from.
+ sourceKind: source ? sourceKind : 'beat-sheet',
+ usedCanonicalList,
});
}));