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
address review (codex): anchor bare comic markers to standalone headers
Adam Eivydbe77f130857
diff --git a/server/lib/comicScriptParser.js b/server/lib/comicScriptParser.jsindex 4a3ca239cd..de3c0bc5f2 100644--- a/server/lib/comicScriptParser.js+++ b/server/lib/comicScriptParser.js@@ -80,13 +80,24 @@ const isNoneValue = (s) => !s || NONE_RE.test(s.trim());// what a header looks like. Roman numerals are excluded: under `/i` the class// matches prose words ("mild", "civic").export const COMIC_NUM = '(?:\\d{1,3}|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety|hundred)';+// What may legitimately follow the number in a STANDALONE PAGE/PANEL header:+// end-of-line, or a punctuation-led suffix (`(5 panels)`, `: Title`, `-2`,+// `/3`). Anything else after the number — most importantly a space + a word —+// means it's a prose CONTENT line that merely starts with the keyword+// (e.g. "Page 1 of the ancient book lies open."), which must NOT be treated as+// a header or the panel it belongs to gets dropped. Shared with the splitter.+export const COMIC_HEADER_TAIL = '\\s*(?:[(:.\\-–—/].*)?$';// Case-INSENSITIVE so a Title Case `Page 1` / `Panel 1` script (which the// splitter already accepts and seeds into stages.comicScript) also parses into// pages/panels here — otherwise the import succeeds but renders zero panels.-const BARE_PAGE_LINE = new RegExp(`^\\s*pages?\\b\\s*#?\\s*${COMIC_NUM}\\b`, 'i'); // PAGE 1 / Page 1 / PAGES 2-const BARE_PANEL_LINE = new RegExp(`^\\s*panels?\\b\\s*#?\\s*${COMIC_NUM}\\b`, 'i'); // PANEL 1 / Panel 1-const BARE_CAPTION_LINE = /^\s*caption\b/i; // CAPTION / Caption / CAPTION 2:-const BARE_SFX_LINE = /^\s*sfx\b/i; // SFX / Sfx+const BARE_PAGE_LINE = new RegExp(`^\\s*pages?\\b\\s*#?\\s*${COMIC_NUM}\\b${COMIC_HEADER_TAIL}`, 'i'); // PAGE 1 / Page 1 / PAGES 2-3+const BARE_PANEL_LINE = new RegExp(`^\\s*panels?\\b\\s*#?\\s*${COMIC_NUM}\\b${COMIC_HEADER_TAIL}`, 'i'); // PANEL 1 / Panel 1 (DPS)+// Standalone CAPTION/SFX LABEL lines only (text on following lines). An inline+// "Caption: text" / "SFX: Thud!" is left for the canonical FIELD_RE to parse,+// and a prose line that merely starts with the word ("Caption this image.")+// is not matched.+const BARE_CAPTION_LINE = /^\s*caption(?:\s+\d+)?\s*:?\s*$/i; // CAPTION / Caption / CAPTION 2:+const BARE_SFX_LINE = /^\s*sfx\s*:?\s*$/i; // SFX / Sfx / SFX:// A standalone dialogue speaker cue: a short, NAME-like all-caps token,// optionally with a parenthetical (`GIANT`, `KESSA (WHISPERED)`). It must NOT// contain sentence punctuation (`. , ! ? :`) so a terse all-caps panel@@ -187,8 +198,10 @@ function normalizeBareComicScript(script) {field = null; dialogueSpeaker = null; // end any in-progress dialoguecontinue;}- // First content line after a PANEL opens the Description field.- if (awaitingFirst && t && field === 'description') {+ // First content line after a PANEL opens the Description field — unless+ // it's already a canonical field label (e.g. an inline "Caption: …" first+ // line), which is passed through for the main parser's FIELD_RE to handle.+ if (awaitingFirst && t && field === 'description' && !FIELD_RE.test(t)) {out.push(`Description: ${t}`);awaitingFirst = false;continue;diff --git a/server/lib/comicScriptParser.test.js b/server/lib/comicScriptParser.test.jsindex ca787e80d8..e5342f9216 100644--- a/server/lib/comicScriptParser.test.js+++ b/server/lib/comicScriptParser.test.js@@ -396,6 +396,23 @@ Thud!`;expect(parseComicScript('Pages turned slowly through the long evening as she read.').pages).toHaveLength(0);});+ it('does NOT treat a content line that starts with "Page N …" as a new page header', () => {+ // A panel description like "Page 1 of the ancient book lies open." must stay+ // description — prefix-only markers used to consume it as a PAGE header and+ // drop the panel. Standalone-header anchoring (number then EOL/punct only).+ const { pages } = parseComicScript('PAGE 1\nPANEL 1\nPage 1 of the ancient book lies open.\nCAPTION\nThe end.');+ expect(pages).toHaveLength(1);+ expect(pages[0].panels).toHaveLength(1);+ expect(pages[0].panels[0].description).toBe('Page 1 of the ancient book lies open.');+ expect(pages[0].panels[0].caption).toBe('The end.');+ });++ it('leaves an inline "Caption: text" first line for FIELD_RE (not forced to description)', () => {+ const { pages } = parseComicScript('PAGE 1\nPANEL 1\nCaption: It was night.\nPANEL 2\nA wide shot.');+ expect(pages[0].panels[0].caption).toBe('It was night.');+ expect(pages[0].panels[1].description).toBe('A wide shot.');+ });+it('leaves canonical Markdown scripts untouched (no false bare-detection)', () => {const { pages } = parseComicScript(SAMPLE);// Same result the canonical-format tests assert — normalization skipped.diff --git a/server/services/importer.js b/server/services/importer.jsindex 4e520be363..ed2f2f2bbf 100644--- a/server/services/importer.js+++ b/server/services/importer.js@@ -32,7 +32,7 @@ import {} from './pipeline/series.js';import { createIssue, deleteIssue, listIssues } from './pipeline/issues.js';import { sanitizeArc, sanitizeSeasonList, buildSeason, ARC_SHAPE_IDS, ARC_ROLES } from '../lib/storyArc.js';-import { COMIC_NUM } from '../lib/comicScriptParser.js';+import { COMIC_NUM, COMIC_HEADER_TAIL } from '../lib/comicScriptParser.js';import { IMPORTER_CONTENT_TYPES, IMPORTER_PROSE_EXCERPT_MAX } from '../lib/validation.js';// Re-export the per-issue excerpt ceiling so callers/tests can reference the// same value the mechanical comic split validates against.@@ -424,14 +424,15 @@ const COMIC_PAGES_PER_ISSUE = 22;// marker (the LLM fallback still covers genuinely header-less scripts).const COMIC_HEADER_MAX_LEN = 80;// `ISSUE #3`, `ISSUE 3`, `ISSUE THREE`, `ISSUE 3: TITLE`, `ISSUE THREE - TITLE`.-// `COMIC_NUM` (shared with the render-time parser via comicScriptParser.js)-// restricts the number token to digits/spelled-numbers so prose like-// "Issue resolved." / "Pages turned slowly" isn't mis-split; the `\b` after-// the keyword also stops "ISSUES with the plan…" from matching. Sharing the-// token keeps the import-time split and the render-time parse in agreement.-const ISSUE_HEADER_RE = new RegExp(`^issue\\b\\s*#?\\s*(${COMIC_NUM})\\b\\s*[:.\\-–—]?\\s*(.*)$`, 'i');+// `COMIC_NUM` + `COMIC_HEADER_TAIL` (shared with the render-time parser via+// comicScriptParser.js) restrict the number token to digits/spelled-numbers+// AND require a standalone header form — so prose like "Issue resolved." or+// "Issue 1 of the saga lay open" (content that merely starts with the keyword)+// isn't mis-split. A title is captured only after a separator. Sharing the+// grammar keeps the import-time split and the render-time parse in agreement.+const ISSUE_HEADER_RE = new RegExp(`^issue\\b\\s*#?\\s*(${COMIC_NUM})\\b\\s*(?:[:.\\-–—]\\s*(.*))?\\s*$`, 'i');// `PAGE 1`, `PAGE ONE`, `PAGES 2-3`, `PAGE ONE (FIVE PANELS)`-const PAGE_HEADER_RE = new RegExp(`^pages?\\b\\s*#?\\s*(${COMIC_NUM})\\b`, 'i');+const PAGE_HEADER_RE = new RegExp(`^pages?\\b\\s*#?\\s*(${COMIC_NUM})\\b${COMIC_HEADER_TAIL}`, 'i');// Locate header lines matching `re`. Returns `[{ idx, title }]` where `idx`// is the 0-based line index and `title` is the trailing text after thediff --git a/server/services/importer.test.js b/server/services/importer.test.jsindex 571184e659..8284f0cf77 100644--- a/server/services/importer.test.js+++ b/server/services/importer.test.js@@ -282,6 +282,16 @@ describe('splitComicScriptIssues (mechanical comic split)', () => {const out = importerSvc.splitComicScriptIssues('ISSUE ONE\nstuff\nISSUE TWO\nmore');expect(out).toHaveLength(2);});++ it('does not mis-split a content line that starts with "Page N …" / "Issue N …" (standalone-header anchor)', () => {+ // The number-token gate alone passed these (they DO contain a number); the+ // standalone-header anchor (number then EOL/punct only) rejects the trailing+ // prose so the mechanical path falls back to the LLM split.+ expect(importerSvc.splitComicScriptIssues('Page 1 of the ancient book lies open and the dust settles.')).toBeNull();+ expect(importerSvc.splitComicScriptIssues('Issue 1 of the saga had long been forgotten by the elders.')).toBeNull();+ // Real standalone headers (incl. a parenthetical suffix) still split.+ expect(importerSvc.splitComicScriptIssues('PAGE 1 (FIVE PANELS)\nart\nPAGE 2\nmore')).toHaveLength(1);+ });});describe('importer cap invariants', () => {