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): title-case headers, teleplay skip, prose cap
Adam Eivy75e834f110d7
diff --git a/server/lib/comicScriptParser.js b/server/lib/comicScriptParser.jsindex 82bc1588cc..65546d8342 100644--- a/server/lib/comicScriptParser.js+++ b/server/lib/comicScriptParser.js@@ -72,10 +72,21 @@ const isNoneValue = (s) => !s || NONE_RE.test(s.trim());// rendering into pages/panels. Markers are matched case-sensitively (real// headers are uppercase) so prose like "Page after page…" isn't mistaken// for a header.-const BARE_PAGE_LINE = /^\s*PAGES?\s+\S+/; // PAGE 1 / PAGES 2-3-const BARE_PANEL_LINE = /^\s*PANELS?\s+\S+/; // PANEL 1-const BARE_CAPTION_LINE = /^\s*CAPTION\b/; // CAPTION / CAPTION 2:-const BARE_SFX_LINE = /^\s*SFX\b/; // SFX+// The number token that legitimately follows ISSUE/PAGE/PANEL in a header:+// a digit run or a spelled-out number word — NOT an open word class, so prose+// like "Page after page" / "Pages turned" isn't mistaken for a header. Shared+// with the importer's mechanical splitter (`server/services/importer.js`+// imports this) so the import-time split and the render-time parse agree on+// 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)';+// 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// 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 paneldiff --git a/server/lib/comicScriptParser.test.js b/server/lib/comicScriptParser.test.jsindex 7ee4c46fbd..9351f994ab 100644--- a/server/lib/comicScriptParser.test.js+++ b/server/lib/comicScriptParser.test.js@@ -381,6 +381,21 @@ Thud!`;expect(pages[1].panels[1].caption).toBe('Woah. Slow down big fella...');});+ it('parses Title Case bare headers (Page/Panel/Caption), matching the case-insensitive splitter', () => {+ // The mechanical splitter accepts `Page 1` / `Panel 1` case-insensitively+ // and seeds them verbatim into stages.comicScript; the parser MUST match+ // the same case variants or the import renders zero panels.+ const { pages } = parseComicScript('Page 1\nPanel 1\nA scene.\nCaption\nHello there.\nPage 2\nPanel 1\nAnother.');+ expect(pages).toHaveLength(2);+ expect(pages[0].panels[0].description).toBe('A scene.');+ expect(pages[0].panels[0].caption).toBe('Hello there.');+ expect(pages[1].panels[0].description).toBe('Another.');+ });++ it('still rejects prose that opens with the keyword (number-token gate, any case)', () => {+ expect(parseComicScript('Pages turned slowly through the long evening as she read.').pages).toHaveLength(0);+ });+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/lib/validation.js b/server/lib/validation.jsindex 31a309d995..6c8fccbb31 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -1618,10 +1618,14 @@ export const IMPORTER_CONTENT_TYPES = Object.freeze([const importerSourceField = z.string().min(1).max(5_000_000);// Per-issue verbatim-excerpt ceiling (seeds stages.prose / stages.comicScript).-// Far below importerSourceField's 5MB so a single bundled comic issue can't-// blow past it silently — analyze validates against this so the failure-// surfaces at analyze, not as a commit-time 400.-export const IMPORTER_PROSE_EXCERPT_MAX = 500_000;+// MUST stay ≤ `STAGE_OUTPUT_MAX` in server/services/pipeline/issues.js (400_000)+// — createIssue trims stage output to that, so a larger excerpt would be+// SILENTLY TRUNCATED on commit despite the import being advertised as verbatim.+// (lib can't import from services; importer.test.js pins the invariant.) Far+// below importerSourceField's 5MB so a single bundled comic issue can't blow+// past it silently — analyze validates against this so the failure surfaces at+// analyze, not as a commit-time truncation/400.+export const IMPORTER_PROSE_EXCERPT_MAX = 400_000;// Classify endpoint only sees the source — no universe/series context. The// LLM only consumes the head, so the schema is intentionally minimal.diff --git a/server/services/importer.js b/server/services/importer.jsindex 6b2c2e9051..4e520be363 100644--- a/server/services/importer.js+++ b/server/services/importer.js@@ -32,6 +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 { 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.@@ -422,17 +423,12 @@ const COMIC_PAGES_PER_ISSUE = 22;// to open with "Page " or "Issue " from being mistaken for a structural// marker (the LLM fallback still covers genuinely header-less scripts).const COMIC_HEADER_MAX_LEN = 80;-// The number token that legitimately follows ISSUE/PAGE in a header: a digit-// run or a spelled-out number word. Crucially this is NOT `[a-z]+` — an open-// word class matched ordinary prose like "Issue resolved." or "Pages turned-// slowly" and (because the mechanical path wins whenever ≥1 header is found)-// mis-split the script with no LLM fallback. Roman numerals are deliberately-// excluded: under the case-insensitive flag `[IVXLCDM]+` matches common prose-// words ("mild", "did", "civic"), so a rare "PAGE IV" header simply falls back-// to the LLM split instead.-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)';// `ISSUE #3`, `ISSUE 3`, `ISSUE THREE`, `ISSUE 3: TITLE`, `ISSUE THREE - TITLE`.-// The `\b` after the keyword also stops "ISSUES with the plan…" from matching.+// `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');// `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');diff --git a/server/services/importer.test.js b/server/services/importer.test.jsindex 22223f0fbe..571184e659 100644--- a/server/services/importer.test.js+++ b/server/services/importer.test.js@@ -284,6 +284,16 @@ describe('splitComicScriptIssues (mechanical comic split)', () => {});});+describe('importer cap invariants', () => {+ it('IMPORTER_PROSE_EXCERPT_MAX stays ≤ STAGE_OUTPUT_MAX (no silent truncation on commit)', () => {+ // createIssue trims stage output to STAGE_OUTPUT_MAX; if the importer's+ // per-issue ceiling were larger, a verbatim excerpt between the two would+ // pass analyze then be silently truncated on commit. lib/validation can't+ // import the services-side constant, so pin the invariant here.+ expect(importerSvc.IMPORTER_PROSE_EXCERPT_MAX).toBeLessThanOrEqual(issuesSvc.STAGE_OUTPUT_MAX);+ });+});+describe('analyzeImport', () => {it('creates universe + series on first run and returns preview shape', async () => {wireDefaultLLMResponses();diff --git a/server/services/pipeline/autoRunner.js b/server/services/pipeline/autoRunner.jsindex d042696482..6627f2d13c 100644--- a/server/services/pipeline/autoRunner.js+++ b/server/services/pipeline/autoRunner.js@@ -83,23 +83,36 @@ export async function startAutoRunTextStages(issueId, options = {}) {// generated prose instead of the user's verbatim script. A backport// (Create → Importer) is the deliberate way to fill prose from the// script. `force` still regenerates.+ let scriptFirstSkip = false;if (!record.cancelRequested) {const proseIssue = await getIssue(issueId);const proseEmpty = !isStageReady(proseIssue.stages?.prose);const scriptAuthored = isStageReady(proseIssue.stages?.comicScript)|| isStageReady(proseIssue.stages?.teleplay);if (proseEmpty && scriptAuthored && !options.force) {+ scriptFirstSkip = true;broadcast(issueId, { type: 'skip', stage: 'prose', reason: 'script already authored (imported script-first) — not back-filling prose' });} else {await runStageIfNeeded(issueId, 'prose', options);}}- // Stage 3: comicScript + teleplay in parallel — both depend only on prose+ // Stage 3: comicScript + teleplay in parallel — both derive from prose.+ // When prose was skipped (script-first import), a script stage that ISN'T+ // already authored has no source to adapt — generating it would burn an+ // LLM call on empty prose and persist a bogus 'ready' stage. Skip those;+ // the authored script runs through runStageIfNeeded and is skipped as+ // already-ready. `force` still regenerates everything.if (!record.cancelRequested) {- await Promise.all([- runStageIfNeeded(issueId, 'comicScript', options),- runStageIfNeeded(issueId, 'teleplay', options),- ]);+ await Promise.all(['comicScript', 'teleplay'].map(async (stageId) => {+ if (scriptFirstSkip && !options.force) {+ const iss = await getIssue(issueId);+ if (!isStageReady(iss.stages?.[stageId])) {+ broadcast(issueId, { type: 'skip', stage: stageId, reason: 'no prose to adapt (imported script-first)' });+ return;+ }+ }+ return runStageIfNeeded(issueId, stageId, options);+ }));}// Optional Stage 4: episode video. Gated behind `includeVideo: true` sodiff --git a/server/services/pipeline/autoRunner.test.js b/server/services/pipeline/autoRunner.test.jsindex 64e6193b29..c0513a0a53 100644--- a/server/services/pipeline/autoRunner.test.js+++ b/server/services/pipeline/autoRunner.test.js@@ -134,8 +134,12 @@ describe('pipeline auto-runner', () => {});expect(generated).not.toContain('prose'); // skipped — script-firstexpect(generated).not.toContain('comicScript'); // already ready+ // teleplay must NOT be generated from empty prose — it has no source to+ // adapt, so generating it would burn an LLM call + persist a bogus stage.+ expect(generated).not.toContain('teleplay');const final = await issuesSvc.getIssue(issue.id);expect(final.stages?.prose?.output || '').toBe('');+ expect(final.stages?.teleplay?.output || '').toBe('');});it('DOES generate prose for a script-first issue when force=true', async () => {