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

fix([comic-allcaps-continuation-vs-cue]): disambiguate a trailing all-caps shout from a 2nd speaker cue via lookahead

[._.]/ Adam Eivy050756ba6c65
diff --git a/server/lib/comicScriptParser.js b/server/lib/comicScriptParser.js
index eb555f1966..b3ec6a2d86 100644
--- a/server/lib/comicScriptParser.js
+++ b/server/lib/comicScriptParser.js
@@ -150,7 +150,17 @@ function normalizeBareComicScript(script) {
}
};
- for (const raw of script.split(/\r?\n/)) {
+ // A line that begins a NEW structural block (page/panel/caption/sfx) or EOF
+ // is what follows a trailing all-caps SHOUT in a balloon; a genuine second
+ // speaker cue is instead followed by its own spoken (dialogue) line. The
+ // one-line lookahead below uses this to disambiguate the two.
+ const startsNewBlock = (t) =>
+ BARE_PAGE_LINE.test(t) || BARE_PANEL_LINE.test(t)
+ || BARE_CAPTION_LINE.test(t) || BARE_SFX_LINE.test(t);
+
+ const lines = script.split(/\r?\n/);
+ for (let i = 0; i < lines.length; i += 1) {
+ const raw = lines[i];
const t = raw.trim();
if (BARE_PAGE_LINE.test(t)) {
@@ -190,14 +200,31 @@ function normalizeBareComicScript(script) {
}
// Continuation line of a multi-line balloon — attribute it to the same
// speaker so parsePanelBody captures it (otherwise lines 2+ were dropped).
- // Unlike the first-line branch above, a fresh all-caps NAME-like line in
- // continuation position IS treated as a SECOND speaker cue: the
- // `!BARE_SPEAKER_LINE` guard lets it fall through to the speaker-cue branch
- // below. Two speakers in one panel is common, and a second balloon's cue
- // naturally follows the first speaker's spoken line.
- if (field === 'dialogue' && dialogueSpeaker && t && !BARE_SPEAKER_LINE.test(t)) {
- out.push(`${dialogueSpeaker}: ${t}`);
- continue;
+ // A fresh all-caps NAME-like line in continuation position is AMBIGUOUS: it
+ // could be a SECOND speaker's cue (common — two speakers in one panel) or a
+ // shouted continuation of the same balloon (`STOP`, `NO`). Disambiguate with
+ // one-line lookahead: a real cue is followed by its own spoken line, while a
+ // trailing shout is followed by a structural marker (PAGE/PANEL/CAPTION/SFX)
+ // or EOF. So treat a NAME-like line as a continuation shout when the next
+ // content line starts a new block or there is none; otherwise let it fall
+ // through to the speaker-cue branch below.
+ if (field === 'dialogue' && dialogueSpeaker && t) {
+ if (!BARE_SPEAKER_LINE.test(t)) {
+ out.push(`${dialogueSpeaker}: ${t}`);
+ continue;
+ }
+ // NAME-like continuation line: peek at the next non-blank line.
+ let next = '';
+ for (let j = i + 1; j < lines.length; j += 1) {
+ const nt = lines[j].trim();
+ if (nt) { next = nt; break; }
+ }
+ if (next === '' || startsNewBlock(next)) {
+ // Trailing shout — no following dialogue line, so it's not a new cue.
+ out.push(`${dialogueSpeaker}: ${t}`);
+ continue;
+ }
+ // Falls through: a spoken line follows, so this is a genuine 2nd cue.
}
// Speaker cue — only when NOT the forced first content line after a label.
if (inPanel && t && !awaitingFirst && BARE_SPEAKER_LINE.test(t)) {
diff --git a/server/lib/comicScriptParser.test.js b/server/lib/comicScriptParser.test.js
index d169ee9134..86d6f98529 100644
--- a/server/lib/comicScriptParser.test.js
+++ b/server/lib/comicScriptParser.test.js
@@ -485,4 +485,37 @@ Thud!`;
expect(pages[0].panels[0].dialogue).toEqual([]);
expect(pages[0].panels).toHaveLength(2);
});
+
+ it('keeps a trailing all-caps shout (followed by a new panel) as the same speaker, not a new cue', () => {
+ // `STOP` matches the speaker-cue shape but is a shouted continuation of
+ // GIANT's balloon, not a second speaker — the next content line is PANEL 2,
+ // not a spoken line, so one-line lookahead keeps it under GIANT.
+ const { pages } = parseComicScript('PAGE 1\nPANEL 1\nA face.\nGIANT\nWait.\nSTOP\nPANEL 2\nAnother shot.');
+ expect(pages[0].panels[0].dialogue).toEqual([
+ { character: 'GIANT', line: 'Wait.' },
+ { character: 'GIANT', line: 'STOP' },
+ ]);
+ expect(pages[0].panels).toHaveLength(2);
+ });
+
+ it('keeps a trailing all-caps shout at end-of-script as the same speaker, not a dangling cue', () => {
+ // Same as above but the shout is the very last line (EOF lookahead). It
+ // must stay GIANT's dialogue rather than be flushed as dangling cue text.
+ const { pages } = parseComicScript('PAGE 1\nPANEL 1\nA face.\nGIANT\nWait.\nSTOP');
+ expect(pages[0].panels[0].dialogue).toEqual([
+ { character: 'GIANT', line: 'Wait.' },
+ { character: 'GIANT', line: 'STOP' },
+ ]);
+ });
+
+ it('still opens a NEW balloon for an all-caps cue that IS followed by its own dialogue', () => {
+ // The fix must not regress the common two-speaker case: KESSA is followed by
+ // a spoken line, so lookahead correctly treats it as a fresh cue even though
+ // it sits in continuation position after GIANT's first balloon line.
+ const { pages } = parseComicScript('PAGE 1\nPANEL 1\nA face.\nGIANT\nWait.\nKESSA\nNo!');
+ expect(pages[0].panels[0].dialogue).toEqual([
+ { character: 'GIANT', line: 'Wait.' },
+ { character: 'KESSA', line: 'No!' },
+ ]);
+ });
});