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): fence-safe reader-map notes; layout-only source for panel-rhythm
Adam Eivy8f4d6ab8d074
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.jsindex 0f1e6970bd..f10011a9bb 100644--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@ -117,13 +117,18 @@ const SEVERITIES = CHECK_SEVERITIES;// the runner fingerprints ONLY the lettering fields for this// token, so a visual-description edit doesn't stale a// lettering finding.-// - 'comicScript.pacing' — the same parsed comic pages, but for the comic-PACING-// checks (#1314: panel rhythm + page-turn beats). Distinct-// token from 'comicScript' because the page-turn check ALSO-// reads each panel's visual `description` — so its fingerprint-// must move on a description edit while the lettering token's-// stays put (and vice-versa). Same `ctx.issues` source, no-// extra I/O.+// - 'comicScript.pacing' — the same parsed comic pages, for the page-turn-beats+// LLM check (#1314), which reads each panel's visual+// `description` (+ caption/dialogue/SFX text) for its prompt+// digest. Distinct token from 'comicScript' because that+// broader read means a description edit must stale a page-turn+// finding while the lettering token stays put (and vice-versa).+// - 'comicScript.layout' — LAYOUT ONLY (per-page panel COUNT) for the panel-rhythm+// check (#1314), which reads nothing but counts. Separate from+// 'comicScript.pacing' so a text-only edit (reword a caption /+// description without adding/removing a panel) does NOT stale a+// rhythm finding — the splash/crowding/grid verdict can't have+// changed. All three comic tokens share `ctx.issues` (no extra I/O).export const EDITORIAL_SOURCES = Object.freeze(['manuscript','canon',@@ -138,6 +143,7 @@ export const EDITORIAL_SOURCES = Object.freeze(['storyboard.shots','comicScript','comicScript.pacing',+ 'comicScript.layout',]);// Default per-run finding cap for user-defined checks (#1346) — mirrors the@@ -4509,7 +4515,7 @@ export const EDITORIAL_CHECKS = [},{id: 'comic.panel-rhythm',- sources: ['comicScript.pacing'],+ sources: ['comicScript.layout'],label: 'Comic panel rhythm & splash usage',description:'Deterministic scan of each issue\'s parsed comic-page layout for reading-rhythm problems: splash-page overuse (too high a share of full-page splashes), back-to-back splashes that blow the page budget, overcrowded pages that cram too many beats, and monotonous grids (the same multi-panel count repeated page after page). Reads the parsed comic script (page → panel breakdown), not the prose manuscript.',diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.jsindex a9b9949fe2..fdcfaed332 100644--- a/server/lib/editorial/checkRegistry.test.js+++ b/server/lib/editorial/checkRegistry.test.js@@ -3278,12 +3278,13 @@ describe('comic-pacing bundle (#1314)', () => {const issue = (number, counts) => ({ number, stages: { comicPages: { pages: counts.map(page) } } });describe('comic.panel-rhythm — deterministic', () => {- it('is registered as an issue-scoped deterministic pacing check over comicScript.pacing', () => {+ it('is registered as an issue-scoped deterministic pacing check over comicScript.layout', () => {const check = getCheck(PANEL_RHYTHM);expect(check.kind).toBe('deterministic');expect(check.scope).toBe('issue');expect(check.category).toBe('pacing');- expect(check.sources).toEqual(['comicScript.pacing']);+ // Layout-only source: rhythm reads panel COUNTS, so a text edit must not stale it.+ expect(check.sources).toEqual(['comicScript.layout']);});it('only runs when at least one issue has comic content', () => {diff --git a/server/lib/editorial/comicPacing.js b/server/lib/editorial/comicPacing.jsindex a49d375d7a..177d39128a 100644--- a/server/lib/editorial/comicPacing.js+++ b/server/lib/editorial/comicPacing.js@@ -42,16 +42,19 @@ export function comicSpreadLayout(pageCount) {return layout;}-// Collapse whitespace, neutralize markdown fence delimiters, and truncate a text-// field to `max` chars for the digest. The rendered layout is embedded inside a-// ``` fenced block in the page-turn prompt, so a backtick run in authored script-// text (a panel that quotes code/markdown) could otherwise close the fence early-// and turn the rest of the prompt into unstructured text. Backtick fidelity is-// irrelevant to the model's pacing judgment, so collapse any run of backticks to a-// single quote — a delimiter-safe transform applied at the one chokepoint every-// user-authored snippet (description / caption / dialogue / SFX) passes through.+// Collapse whitespace and neutralize markdown fence delimiters in an authored+// string. BOTH renderers below (the page-layout digest AND the reader-map summary)+// embed their output inside a ``` fenced block in the page-turn prompt, so a+// backtick run in any authored text (a panel or a reveal note that quotes+// code/markdown) could otherwise close the fence early and turn the rest of the+// prompt into unstructured text. Backtick fidelity is irrelevant to the model's+// pacing judgment, so collapse any run of backticks to a single quote. Every+// user-authored snippet that reaches either fenced block passes through here.+const fenceSafe = (s) => (typeof s === 'string' ? s.trim().replace(/\s+/g, ' ').replace(/`+/g, "'") : '');++// fenceSafe + truncate to `max` chars, for the per-panel digest snippets.const clip = (s, max) => {- const t = typeof s === 'string' ? s.trim().replace(/\s+/g, ' ').replace(/`+/g, "'") : '';+ const t = fenceSafe(s);return t.length > max ? `${t.slice(0, max)}…` : t;};@@ -211,7 +214,8 @@ export function authoredRevealSummary(readerMap) {const revealLines = beats.filter((b) => b?.kind === 'reveal').map((b) => {- const note = typeof b?.note === 'string' ? b.note.trim() : '';+ // fenceSafe (not bare trim): the note is embedded in a ``` block in the prompt.+ const note = fenceSafe(b?.note);if (!note) return '';const pos = Number.isFinite(b?.atArcPosition) ? ` (arc position ${b.atArcPosition})` : '';return `- ${note}${pos}`;@@ -219,7 +223,7 @@ export function authoredRevealSummary(readerMap) {.filter(Boolean);const cliffLines = cliffs.map((c) => {- const note = typeof c?.note === 'string' ? c.note.trim() : '';+ const note = fenceSafe(c?.note);if (!note) return '';const at = Number.isInteger(c?.atIssueBoundary) ? ` (ending issue ${c.atIssueBoundary})` : '';return `- ${note}${at}`;diff --git a/server/lib/editorial/comicPacing.test.js b/server/lib/editorial/comicPacing.test.jsindex afbe470fc7..f6fa578d03 100644--- a/server/lib/editorial/comicPacing.test.js+++ b/server/lib/editorial/comicPacing.test.js@@ -163,4 +163,15 @@ describe('authoredRevealSummary', () => {expect(authoredRevealSummary(null)).toBe('');expect(authoredRevealSummary({ beats: [{ kind: 'hook', note: 'q' }] })).toBe('');});++ it('neutralizes markdown fence delimiters in reveal/cliffhanger notes (prompt-fence safety)', () => {+ // The summary is embedded in a ``` fenced block in the page-turn prompt, so a+ // note containing backticks must not be able to close the fence early.+ const out = authoredRevealSummary({+ beats: [{ kind: 'reveal', note: 'the ```secret``` is revealed' }],+ cliffhangers: [{ note: 'a ``` cliff' }],+ });+ expect(out).not.toContain('`');+ expect(out).toContain("'secret'");+ });});diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex 5361575ec7..c294e68476 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -105,11 +105,18 @@ const SOURCE_RESOLVERS = {// text it read changes (and an unrelated image render — `panel.imageJobId` — does// NOT stale it, since only the lettering fields are projected).comicScript: ({ comicScripts }) => canonicalStringify(comicScripts ?? null),- // The comic-pacing checks' content (#1314) — its own token so a visual- // `description` edit stales a page-turn finding without staling a lettering- // finding (which doesn't read `description`), and vice-versa. Same page-grouped- // shape as the lettering projection plus `description`.+ // The page-turn check's content (#1314) — its own token because it reads each+ // panel's visual `description` (+ caption/dialogue/SFX text) for the LLM digest.+ // A description edit stales a page-turn finding without staling a lettering one+ // (which doesn't read `description`), and vice-versa.'comicScript.pacing': ({ comicPacingContent }) => canonicalStringify(comicPacingContent ?? null),+ // The panel-rhythm check's content (#1314) — LAYOUT ONLY: it reads nothing but+ // the per-page panel COUNT (splash/crowding/grid-monotony verdicts), so its+ // fingerprint is just the counts. A text-only edit (rewording a caption or+ // description without adding/removing a panel) must NOT stale a rhythm finding —+ // the verdict cannot have changed. Distinct from `comicScript.pacing` (which+ // hashes the text the page-turn LLM reads).+ 'comicScript.layout': ({ comicLayoutContent }) => canonicalStringify(comicLayoutContent ?? null),};// Flatten the storyboard scenes across every issue into the `{ issueNumber, scene }`@@ -195,6 +202,19 @@ function projectComicPacingContent(issues) {}));}+// Project the loaded issues down to LAYOUT ONLY — the per-page panel COUNT — for+// the panel-rhythm check (#1314), which reads nothing but counts (`analyzePanelRhythm`).+// Fingerprinting only the count means a text-only edit (reword a caption/description+// without changing how many panels a page has) does NOT stale a rhythm finding,+// while adding/removing/moving a panel does. Per-page array order is preserved so a+// reordering that changes the run structure (splash runs, monotony) re-hashes.+function projectComicLayoutContent(issues) {+ return comicLetteringIssues(issues).map(({ number, pages }) => ({+ number,+ panelCounts: pages.map((p) => (Array.isArray(p?.panels) ? p.panels.length : 0)),+ }));+}+// Stable projection of the series editorial aggregate down to the arc fields a// POV/arc check reads — drops the volatile `generatedAt` (and the rest) so the// staleness fingerprint only moves when a character's detected arc actually does.@@ -340,10 +360,11 @@ export async function runEditorialChecks(seriesId, options = {}) {// description edit stales a pacing finding without staling a lettering one.const comicScripts = projectComicLetteringContent(issues);const comicPacingContent = projectComicPacingContent(issues);+ const comicLayoutContent = projectComicLayoutContent(issues);// Resolve every source token once — each finding's fingerprint reads from this// so the editor flags it `stale` when the content that check actually read (its// declared `sources`) drifts (#1345, #1387).- const resolvedSources = resolveSources({ manuscript, canon, series, reverseOutline, reverseOutlinePlotlines, editorialArcs, editorialArcsComplete, storyboardScenes, comicScripts, comicPacingContent });+ const resolvedSources = resolveSources({ manuscript, canon, series, reverseOutline, reverseOutlinePlotlines, editorialArcs, editorialArcsComplete, storyboardScenes, comicScripts, comicPacingContent, comicLayoutContent });const baseCtx = {seriesId,series,@@ -522,7 +543,7 @@ export async function getReviewWithStaleness(seriesId) {const needsStoryboards = evaluable.some((c) => checkSources(checkFor(c.checkId)).includes('storyboard.shots'));const needsComicScript = evaluable.some((c) => {const s = checkSources(checkFor(c.checkId));- return s.includes('comicScript') || s.includes('comicScript.pacing');+ return s.includes('comicScript') || s.includes('comicScript.pacing') || s.includes('comicScript.layout');});const needsIssues = needsStoryboards || needsComicScript;const series = await getSeries(seriesId);@@ -541,7 +562,8 @@ export async function getReviewWithStaleness(seriesId) {const storyboardScenes = collectStoryboardScenes(issues);const comicScripts = projectComicLetteringContent(issues);const comicPacingContent = projectComicPacingContent(issues);- const resolvedSources = resolveSources({ manuscript: sectionsCorpus(sections), canon, series, reverseOutline, reverseOutlinePlotlines, editorialArcs, editorialArcsComplete, storyboardScenes, comicScripts, comicPacingContent });+ const comicLayoutContent = projectComicLayoutContent(issues);+ const resolvedSources = resolveSources({ manuscript: sectionsCorpus(sections), canon, series, reverseOutline, reverseOutlinePlotlines, editorialArcs, editorialArcsComplete, storyboardScenes, comicScripts, comicPacingContent, comicLayoutContent });return {...review,comments: review.comments.map((c) => {diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.jsindex ef605968f5..b0fd1a2dd0 100644--- a/server/services/pipeline/editorial/checkRunner.test.js+++ b/server/services/pipeline/editorial/checkRunner.test.js@@ -537,6 +537,37 @@ describe('getReviewWithStaleness (#1345)', () => {expect(review.comments.find((c) => c.checkId === 'comic.lettering-density').stale).toBe(false);});+ it('keeps a comic.panel-rhythm finding fresh on a text-only edit but stales it on a panel-count change (#1314 layout source)', async () => {+ // panel-rhythm reads only per-page panel COUNTS (comicScript.layout), so a+ // text edit that leaves the counts intact must not stale it; adding a panel must.+ const comicIssue = (extraDesc) => [{+ id: 'i1', seriesId: 's1', number: 1,+ stages: { comicPages: { pages: [+ { panels: [{ description: 'p1a', caption: '', dialogue: [], sfx: '' }] }, // splash+ { panels: [{ description: 'p1b', caption: '', dialogue: [], sfx: '' }] }, // splash → back-to-back splash run fires+ ...(extraDesc ? [{ panels: [{ description: extraDesc, caption: '', dialogue: [], sfx: '' }] }] : []),+ ] } },+ }];+ issuesState = comicIssue(null);+ const { findings } = await runEditorialChecks('s1', { checkIds: ['comic.panel-rhythm'] });+ expect(findings.some((f) => f.checkId === 'comic.panel-rhythm')).toBe(true);+ reviewState = { comments: findings.map((f) => ({ ...f, status: 'open' })) };+ // Text-only edit: reword page 1's description; panel counts [1,1] unchanged.+ issuesState = [{+ id: 'i1', seriesId: 's1', number: 1,+ stages: { comicPages: { pages: [+ { panels: [{ description: 'reworded entirely', caption: 'new caption', dialogue: [], sfx: '' }] },+ { panels: [{ description: 'p1b', caption: '', dialogue: [], sfx: '' }] },+ ] } },+ }];+ let review = await getReviewWithStaleness('s1');+ expect(review.comments.find((c) => c.checkId === 'comic.panel-rhythm').stale).toBe(false);+ // Adding a third page changes the layout → the finding stales.+ issuesState = comicIssue('a new third page');+ review = await getReviewWithStaleness('s1');+ expect(review.comments.find((c) => c.checkId === 'comic.panel-rhythm').stale).toBe(true);+ });+it('keeps a scene finding fresh when the manuscript changes (reverseOutline-only source)', async () => {outlineState = { scenes: [{ id: 'scene-001', issueNumber: 1, heading: 'Talking heads', anchorQuote: 'q', components: { narrative: false, action: false, dialogue: true } }] };await seedReviewFromRun();